1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code. (Or,
35 let's say almost---see the description of direct update
38 The following diagram shows how redisplay code is invoked. As you
39 can see, Lisp calls redisplay and vice versa. Under window systems
40 like X, some portions of the redisplay code are also called
41 asynchronously during mouse movement or expose events. It is very
42 important that these code parts do NOT use the C library (malloc,
43 free) because many C libraries under Unix are not reentrant. They
44 may also NOT call functions of the Lisp interpreter which could
45 change the interpreter's state. If you don't follow these rules,
46 you will encounter bugs which are very hard to explain.
48 (Direct functions, see below)
49 direct_output_for_insert,
50 direct_forward_char (dispnew.c)
51 +---------------------------------+
54 +--------------+ redisplay +----------------+
55 | Lisp machine |---------------->| Redisplay code |<--+
56 +--------------+ (xdisp.c) +----------------+ |
58 +----------------------------------+ |
59 Don't use this path when called |
62 expose_window (asynchronous) |
64 X expose events -----+
66 What does redisplay do? Obviously, it has to figure out somehow what
67 has been changed since the last time the display has been updated,
68 and to make these changes visible. Preferably it would do that in
69 a moderately intelligent way, i.e. fast.
71 Changes in buffer text can be deduced from window and buffer
72 structures, and from some global variables like `beg_unchanged' and
73 `end_unchanged'. The contents of the display are additionally
74 recorded in a `glyph matrix', a two-dimensional matrix of glyph
75 structures. Each row in such a matrix corresponds to a line on the
76 display, and each glyph in a row corresponds to a column displaying
77 a character, an image, or what else. This matrix is called the
78 `current glyph matrix' or `current matrix' in redisplay
81 For buffer parts that have been changed since the last update, a
82 second glyph matrix is constructed, the so called `desired glyph
83 matrix' or short `desired matrix'. Current and desired matrix are
84 then compared to find a cheap way to update the display, e.g. by
85 reusing part of the display by scrolling lines.
90 You will find a lot of redisplay optimizations when you start
91 looking at the innards of redisplay. The overall goal of all these
92 optimizations is to make redisplay fast because it is done
95 Two optimizations are not found in xdisp.c. These are the direct
96 operations mentioned above. As the name suggests they follow a
97 different principle than the rest of redisplay. Instead of
98 building a desired matrix and then comparing it with the current
99 display, they perform their actions directly on the display and on
102 One direct operation updates the display after one character has
103 been entered. The other one moves the cursor by one position
104 forward or backward. You find these functions under the names
105 `direct_output_for_insert' and `direct_output_forward_char' in
111 Desired matrices are always built per Emacs window. The function
112 `display_line' is the central function to look at if you are
113 interested. It constructs one row in a desired matrix given an
114 iterator structure containing both a buffer position and a
115 description of the environment in which the text is to be
116 displayed. But this is too early, read on.
118 Characters and pixmaps displayed for a range of buffer text depend
119 on various settings of buffers and windows, on overlays and text
120 properties, on display tables, on selective display. The good news
121 is that all this hairy stuff is hidden behind a small set of
122 interface functions taking an iterator structure (struct it)
125 Iteration over things to be displayed is then simple. It is
126 started by initializing an iterator with a call to init_iterator.
127 Calls to get_next_display_element fill the iterator structure with
128 relevant information about the next thing to display. Calls to
129 set_iterator_to_next move the iterator to the next thing.
131 Besides this, an iterator also contains information about the
132 display environment in which glyphs for display elements are to be
133 produced. It has fields for the width and height of the display,
134 the information whether long lines are truncated or continued, a
135 current X and Y position, and lots of other stuff you can better
138 Glyphs in a desired matrix are normally constructed in a loop
139 calling get_next_display_element and then produce_glyphs. The call
140 to produce_glyphs will fill the iterator structure with pixel
141 information about the element being displayed and at the same time
142 produce glyphs for it. If the display element fits on the line
143 being displayed, set_iterator_to_next is called next, otherwise the
144 glyphs produced are discarded.
149 That just couldn't be all, could it? What about terminal types not
150 supporting operations on sub-windows of the screen? To update the
151 display on such a terminal, window-based glyph matrices are not
152 well suited. To be able to reuse part of the display (scrolling
153 lines up and down), we must instead have a view of the whole
154 screen. This is what `frame matrices' are for. They are a trick.
156 Frames on terminals like above have a glyph pool. Windows on such
157 a frame sub-allocate their glyph memory from their frame's glyph
158 pool. The frame itself is given its own glyph matrices. By
159 coincidence---or maybe something else---rows in window glyph
160 matrices are slices of corresponding rows in frame matrices. Thus
161 writing to window matrices implicitly updates a frame matrix which
162 provides us with the view of the whole screen that we originally
163 wanted to have without having to move many bytes around. To be
164 honest, there is a little bit more done, but not much more. If you
165 plan to extend that code, take a look at dispnew.c. The function
166 build_frame_matrix is a good starting point. */
172 #include "keyboard.h"
175 #include "termchar.h"
176 #include "dispextern.h"
178 #include "character.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
203 #ifdef HAVE_WINDOW_SYSTEM
205 #endif /* HAVE_WINDOW_SYSTEM */
207 #ifndef FRAME_X_OUTPUT
208 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
211 #define INFINITY 10000000
213 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
215 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
216 extern int pending_menu_activation
;
219 extern int interrupt_input
;
220 extern int command_loop_level
;
222 extern Lisp_Object do_mouse_tracking
;
224 extern int minibuffer_auto_raise
;
225 extern Lisp_Object Vminibuffer_list
;
227 extern Lisp_Object Qface
;
228 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
230 extern Lisp_Object Voverriding_local_map
;
231 extern Lisp_Object Voverriding_local_map_menu_flag
;
232 extern Lisp_Object Qmenu_item
;
233 extern Lisp_Object Qwhen
;
234 extern Lisp_Object Qhelp_echo
;
236 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
237 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
238 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
239 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
240 Lisp_Object Qinhibit_point_motion_hooks
;
241 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
242 Lisp_Object Qfontified
;
243 Lisp_Object Qgrow_only
;
244 Lisp_Object Qinhibit_eval_during_redisplay
;
245 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
248 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
251 Lisp_Object Qarrow
, Qhand
, Qtext
;
253 Lisp_Object Qrisky_local_variable
;
255 /* Holds the list (error). */
256 Lisp_Object list_of_error
;
258 /* Functions called to fontify regions of text. */
260 Lisp_Object Vfontification_functions
;
261 Lisp_Object Qfontification_functions
;
263 /* Non-nil means automatically select any window when the mouse
264 cursor moves into it. */
265 Lisp_Object Vmouse_autoselect_window
;
267 /* Non-zero means draw tool bar buttons raised when the mouse moves
270 int auto_raise_tool_bar_buttons_p
;
272 /* Non-zero means to reposition window if cursor line is only partially visible. */
274 int make_cursor_line_fully_visible_p
;
276 /* Margin below tool bar in pixels. 0 or nil means no margin.
277 If value is `internal-border-width' or `border-width',
278 the corresponding frame parameter is used. */
280 Lisp_Object Vtool_bar_border
;
282 /* Margin around tool bar buttons in pixels. */
284 Lisp_Object Vtool_bar_button_margin
;
286 /* Thickness of shadow to draw around tool bar buttons. */
288 EMACS_INT tool_bar_button_relief
;
290 /* Non-nil means automatically resize tool-bars so that all tool-bar
291 items are visible, and no blank lines remain.
293 If value is `grow-only', only make tool-bar bigger. */
295 Lisp_Object Vauto_resize_tool_bars
;
297 /* Non-zero means draw block and hollow cursor as wide as the glyph
298 under it. For example, if a block cursor is over a tab, it will be
299 drawn as wide as that tab on the display. */
301 int x_stretch_cursor_p
;
303 /* Non-nil means don't actually do any redisplay. */
305 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
307 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
309 int inhibit_eval_during_redisplay
;
311 /* Names of text properties relevant for redisplay. */
313 Lisp_Object Qdisplay
;
314 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
316 /* Symbols used in text property values. */
318 Lisp_Object Vdisplay_pixels_per_inch
;
319 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
320 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
323 Lisp_Object Qmargin
, Qpointer
;
324 Lisp_Object Qline_height
;
325 extern Lisp_Object Qheight
;
326 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
327 extern Lisp_Object Qscroll_bar
;
328 extern Lisp_Object Qcursor
;
330 /* Non-nil means highlight trailing whitespace. */
332 Lisp_Object Vshow_trailing_whitespace
;
334 /* Non-nil means escape non-break space and hyphens. */
336 Lisp_Object Vnobreak_char_display
;
338 #ifdef HAVE_WINDOW_SYSTEM
339 extern Lisp_Object Voverflow_newline_into_fringe
;
341 /* Test if overflow newline into fringe. Called with iterator IT
342 at or past right window margin, and with IT->current_x set. */
344 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
345 (!NILP (Voverflow_newline_into_fringe) \
346 && FRAME_WINDOW_P (it->f) \
347 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
348 && it->current_x == it->last_visible_x)
350 #endif /* HAVE_WINDOW_SYSTEM */
352 /* Non-nil means show the text cursor in void text areas
353 i.e. in blank areas after eol and eob. This used to be
354 the default in 21.3. */
356 Lisp_Object Vvoid_text_area_pointer
;
358 /* Name of the face used to highlight trailing whitespace. */
360 Lisp_Object Qtrailing_whitespace
;
362 /* Name and number of the face used to highlight escape glyphs. */
364 Lisp_Object Qescape_glyph
;
366 /* Name and number of the face used to highlight non-breaking spaces. */
368 Lisp_Object Qnobreak_space
;
370 /* The symbol `image' which is the car of the lists used to represent
375 /* The image map types. */
376 Lisp_Object QCmap
, QCpointer
;
377 Lisp_Object Qrect
, Qcircle
, Qpoly
;
379 /* Non-zero means print newline to stdout before next mini-buffer
382 int noninteractive_need_newline
;
384 /* Non-zero means print newline to message log before next message. */
386 static int message_log_need_newline
;
388 /* Three markers that message_dolog uses.
389 It could allocate them itself, but that causes trouble
390 in handling memory-full errors. */
391 static Lisp_Object message_dolog_marker1
;
392 static Lisp_Object message_dolog_marker2
;
393 static Lisp_Object message_dolog_marker3
;
395 /* The buffer position of the first character appearing entirely or
396 partially on the line of the selected window which contains the
397 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
398 redisplay optimization in redisplay_internal. */
400 static struct text_pos this_line_start_pos
;
402 /* Number of characters past the end of the line above, including the
403 terminating newline. */
405 static struct text_pos this_line_end_pos
;
407 /* The vertical positions and the height of this line. */
409 static int this_line_vpos
;
410 static int this_line_y
;
411 static int this_line_pixel_height
;
413 /* X position at which this display line starts. Usually zero;
414 negative if first character is partially visible. */
416 static int this_line_start_x
;
418 /* Buffer that this_line_.* variables are referring to. */
420 static struct buffer
*this_line_buffer
;
422 /* Nonzero means truncate lines in all windows less wide than the
425 int truncate_partial_width_windows
;
427 /* A flag to control how to display unibyte 8-bit character. */
429 int unibyte_display_via_language_environment
;
431 /* Nonzero means we have more than one non-mini-buffer-only frame.
432 Not guaranteed to be accurate except while parsing
433 frame-title-format. */
437 Lisp_Object Vglobal_mode_string
;
440 /* List of variables (symbols) which hold markers for overlay arrows.
441 The symbols on this list are examined during redisplay to determine
442 where to display overlay arrows. */
444 Lisp_Object Voverlay_arrow_variable_list
;
446 /* Marker for where to display an arrow on top of the buffer text. */
448 Lisp_Object Voverlay_arrow_position
;
450 /* String to display for the arrow. Only used on terminal frames. */
452 Lisp_Object Voverlay_arrow_string
;
454 /* Values of those variables at last redisplay are stored as
455 properties on `overlay-arrow-position' symbol. However, if
456 Voverlay_arrow_position is a marker, last-arrow-position is its
457 numerical position. */
459 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
461 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
462 properties on a symbol in overlay-arrow-variable-list. */
464 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
466 /* Like mode-line-format, but for the title bar on a visible frame. */
468 Lisp_Object Vframe_title_format
;
470 /* Like mode-line-format, but for the title bar on an iconified frame. */
472 Lisp_Object Vicon_title_format
;
474 /* List of functions to call when a window's size changes. These
475 functions get one arg, a frame on which one or more windows' sizes
478 static Lisp_Object Vwindow_size_change_functions
;
480 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
482 /* Nonzero if an overlay arrow has been displayed in this window. */
484 static int overlay_arrow_seen
;
486 /* Nonzero means highlight the region even in nonselected windows. */
488 int highlight_nonselected_windows
;
490 /* If cursor motion alone moves point off frame, try scrolling this
491 many lines up or down if that will bring it back. */
493 static EMACS_INT scroll_step
;
495 /* Nonzero means scroll just far enough to bring point back on the
496 screen, when appropriate. */
498 static EMACS_INT scroll_conservatively
;
500 /* Recenter the window whenever point gets within this many lines of
501 the top or bottom of the window. This value is translated into a
502 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
503 that there is really a fixed pixel height scroll margin. */
505 EMACS_INT scroll_margin
;
507 /* Number of windows showing the buffer of the selected window (or
508 another buffer with the same base buffer). keyboard.c refers to
513 /* Vector containing glyphs for an ellipsis `...'. */
515 static Lisp_Object default_invis_vector
[3];
517 /* Zero means display the mode-line/header-line/menu-bar in the default face
518 (this slightly odd definition is for compatibility with previous versions
519 of emacs), non-zero means display them using their respective faces.
521 This variable is deprecated. */
523 int mode_line_inverse_video
;
525 /* Prompt to display in front of the mini-buffer contents. */
527 Lisp_Object minibuf_prompt
;
529 /* Width of current mini-buffer prompt. Only set after display_line
530 of the line that contains the prompt. */
532 int minibuf_prompt_width
;
534 /* This is the window where the echo area message was displayed. It
535 is always a mini-buffer window, but it may not be the same window
536 currently active as a mini-buffer. */
538 Lisp_Object echo_area_window
;
540 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
541 pushes the current message and the value of
542 message_enable_multibyte on the stack, the function restore_message
543 pops the stack and displays MESSAGE again. */
545 Lisp_Object Vmessage_stack
;
547 /* Nonzero means multibyte characters were enabled when the echo area
548 message was specified. */
550 int message_enable_multibyte
;
552 /* Nonzero if we should redraw the mode lines on the next redisplay. */
554 int update_mode_lines
;
556 /* Nonzero if window sizes or contents have changed since last
557 redisplay that finished. */
559 int windows_or_buffers_changed
;
561 /* Nonzero means a frame's cursor type has been changed. */
563 int cursor_type_changed
;
565 /* Nonzero after display_mode_line if %l was used and it displayed a
568 int line_number_displayed
;
570 /* Maximum buffer size for which to display line numbers. */
572 Lisp_Object Vline_number_display_limit
;
574 /* Line width to consider when repositioning for line number display. */
576 static EMACS_INT line_number_display_limit_width
;
578 /* Number of lines to keep in the message log buffer. t means
579 infinite. nil means don't log at all. */
581 Lisp_Object Vmessage_log_max
;
583 /* The name of the *Messages* buffer, a string. */
585 static Lisp_Object Vmessages_buffer_name
;
587 /* Current, index 0, and last displayed echo area message. Either
588 buffers from echo_buffers, or nil to indicate no message. */
590 Lisp_Object echo_area_buffer
[2];
592 /* The buffers referenced from echo_area_buffer. */
594 static Lisp_Object echo_buffer
[2];
596 /* A vector saved used in with_area_buffer to reduce consing. */
598 static Lisp_Object Vwith_echo_area_save_vector
;
600 /* Non-zero means display_echo_area should display the last echo area
601 message again. Set by redisplay_preserve_echo_area. */
603 static int display_last_displayed_message_p
;
605 /* Nonzero if echo area is being used by print; zero if being used by
608 int message_buf_print
;
610 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
612 Lisp_Object Qinhibit_menubar_update
;
613 int inhibit_menubar_update
;
615 /* When evaluating expressions from menu bar items (enable conditions,
616 for instance), this is the frame they are being processed for. */
618 Lisp_Object Vmenu_updating_frame
;
620 /* Maximum height for resizing mini-windows. Either a float
621 specifying a fraction of the available height, or an integer
622 specifying a number of lines. */
624 Lisp_Object Vmax_mini_window_height
;
626 /* Non-zero means messages should be displayed with truncated
627 lines instead of being continued. */
629 int message_truncate_lines
;
630 Lisp_Object Qmessage_truncate_lines
;
632 /* Set to 1 in clear_message to make redisplay_internal aware
633 of an emptied echo area. */
635 static int message_cleared_p
;
637 /* How to blink the default frame cursor off. */
638 Lisp_Object Vblink_cursor_alist
;
640 /* A scratch glyph row with contents used for generating truncation
641 glyphs. Also used in direct_output_for_insert. */
643 #define MAX_SCRATCH_GLYPHS 100
644 struct glyph_row scratch_glyph_row
;
645 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
647 /* Ascent and height of the last line processed by move_it_to. */
649 static int last_max_ascent
, last_height
;
651 /* Non-zero if there's a help-echo in the echo area. */
653 int help_echo_showing_p
;
655 /* If >= 0, computed, exact values of mode-line and header-line height
656 to use in the macros CURRENT_MODE_LINE_HEIGHT and
657 CURRENT_HEADER_LINE_HEIGHT. */
659 int current_mode_line_height
, current_header_line_height
;
661 /* The maximum distance to look ahead for text properties. Values
662 that are too small let us call compute_char_face and similar
663 functions too often which is expensive. Values that are too large
664 let us call compute_char_face and alike too often because we
665 might not be interested in text properties that far away. */
667 #define TEXT_PROP_DISTANCE_LIMIT 100
671 /* Variables to turn off display optimizations from Lisp. */
673 int inhibit_try_window_id
, inhibit_try_window_reusing
;
674 int inhibit_try_cursor_movement
;
676 /* Non-zero means print traces of redisplay if compiled with
679 int trace_redisplay_p
;
681 #endif /* GLYPH_DEBUG */
683 #ifdef DEBUG_TRACE_MOVE
684 /* Non-zero means trace with TRACE_MOVE to stderr. */
687 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
689 #define TRACE_MOVE(x) (void) 0
692 /* Non-zero means automatically scroll windows horizontally to make
695 int automatic_hscrolling_p
;
696 Lisp_Object Qauto_hscroll_mode
;
698 /* How close to the margin can point get before the window is scrolled
700 EMACS_INT hscroll_margin
;
702 /* How much to scroll horizontally when point is inside the above margin. */
703 Lisp_Object Vhscroll_step
;
705 /* The variable `resize-mini-windows'. If nil, don't resize
706 mini-windows. If t, always resize them to fit the text they
707 display. If `grow-only', let mini-windows grow only until they
710 Lisp_Object Vresize_mini_windows
;
712 /* Buffer being redisplayed -- for redisplay_window_error. */
714 struct buffer
*displayed_buffer
;
716 /* Space between overline and text. */
718 EMACS_INT overline_margin
;
720 /* Value returned from text property handlers (see below). */
725 HANDLED_RECOMPUTE_PROPS
,
726 HANDLED_OVERLAY_STRING_CONSUMED
,
730 /* A description of text properties that redisplay is interested
735 /* The name of the property. */
738 /* A unique index for the property. */
741 /* A handler function called to set up iterator IT from the property
742 at IT's current position. Value is used to steer handle_stop. */
743 enum prop_handled (*handler
) P_ ((struct it
*it
));
746 static enum prop_handled handle_face_prop
P_ ((struct it
*));
747 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
748 static enum prop_handled handle_display_prop
P_ ((struct it
*));
749 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
750 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
751 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
752 static enum prop_handled handle_auto_composed_prop
P_ ((struct it
*));
754 /* Properties handled by iterators. */
756 static struct props it_props
[] =
758 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
759 /* Handle `face' before `display' because some sub-properties of
760 `display' need to know the face. */
761 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
762 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
763 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
764 {&Qauto_composed
, AUTO_COMPOSED_PROP_IDX
, handle_auto_composed_prop
},
765 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
769 /* Value is the position described by X. If X is a marker, value is
770 the marker_position of X. Otherwise, value is X. */
772 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
774 /* Enumeration returned by some move_it_.* functions internally. */
778 /* Not used. Undefined value. */
781 /* Move ended at the requested buffer position or ZV. */
782 MOVE_POS_MATCH_OR_ZV
,
784 /* Move ended at the requested X pixel position. */
787 /* Move within a line ended at the end of a line that must be
791 /* Move within a line ended at the end of a line that would
792 be displayed truncated. */
795 /* Move within a line ended at a line end. */
799 /* This counter is used to clear the face cache every once in a while
800 in redisplay_internal. It is incremented for each redisplay.
801 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
804 #define CLEAR_FACE_CACHE_COUNT 500
805 static int clear_face_cache_count
;
807 /* Similarly for the image cache. */
809 #ifdef HAVE_WINDOW_SYSTEM
810 #define CLEAR_IMAGE_CACHE_COUNT 101
811 static int clear_image_cache_count
;
814 /* Non-zero while redisplay_internal is in progress. */
818 /* Non-zero means don't free realized faces. Bound while freeing
819 realized faces is dangerous because glyph matrices might still
822 int inhibit_free_realized_faces
;
823 Lisp_Object Qinhibit_free_realized_faces
;
825 /* If a string, XTread_socket generates an event to display that string.
826 (The display is done in read_char.) */
828 Lisp_Object help_echo_string
;
829 Lisp_Object help_echo_window
;
830 Lisp_Object help_echo_object
;
833 /* Temporary variable for XTread_socket. */
835 Lisp_Object previous_help_echo_string
;
837 /* Null glyph slice */
839 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
842 /* Function prototypes. */
844 static void setup_for_ellipsis
P_ ((struct it
*, int));
845 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
846 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
847 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
848 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
849 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
850 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
853 static int invisible_text_between_p
P_ ((struct it
*, int, int));
856 static void pint2str
P_ ((char *, int, int));
857 static void pint2hrstr
P_ ((char *, int, int));
858 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
860 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
861 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
862 static void store_mode_line_noprop_char
P_ ((char));
863 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
864 static void x_consider_frame_title
P_ ((Lisp_Object
));
865 static void handle_stop
P_ ((struct it
*));
866 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
867 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
868 static void ensure_echo_area_buffers
P_ ((void));
869 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
870 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
871 static int with_echo_area_buffer
P_ ((struct window
*, int,
872 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
873 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
874 static void clear_garbaged_frames
P_ ((void));
875 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
876 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
877 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
878 static int display_echo_area
P_ ((struct window
*));
879 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
880 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
881 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
882 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
883 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
885 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
886 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
887 static void insert_left_trunc_glyphs
P_ ((struct it
*));
888 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
890 static void extend_face_to_end_of_line
P_ ((struct it
*));
891 static int append_space_for_newline
P_ ((struct it
*, int));
892 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
893 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
894 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
895 static int trailing_whitespace_p
P_ ((int));
896 static int message_log_check_duplicate
P_ ((int, int, int, int));
897 static void push_it
P_ ((struct it
*));
898 static void pop_it
P_ ((struct it
*));
899 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
900 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
901 static void redisplay_internal
P_ ((int));
902 static int echo_area_display
P_ ((int));
903 static void redisplay_windows
P_ ((Lisp_Object
));
904 static void redisplay_window
P_ ((Lisp_Object
, int));
905 static Lisp_Object
redisplay_window_error ();
906 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
907 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
908 static int update_menu_bar
P_ ((struct frame
*, int, int));
909 static int try_window_reusing_current_matrix
P_ ((struct window
*));
910 static int try_window_id
P_ ((struct window
*));
911 static int display_line
P_ ((struct it
*));
912 static int display_mode_lines
P_ ((struct window
*));
913 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
914 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
915 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
916 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
917 static void display_menu_bar
P_ ((struct window
*));
918 static int display_count_lines
P_ ((int, int, int, int, int *));
919 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
920 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
921 static void compute_line_metrics
P_ ((struct it
*));
922 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
923 static int get_overlay_strings
P_ ((struct it
*, int));
924 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
925 static void next_overlay_string
P_ ((struct it
*));
926 static void reseat
P_ ((struct it
*, struct text_pos
, int));
927 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
928 static void back_to_previous_visible_line_start
P_ ((struct it
*));
929 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
930 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
931 static int next_element_from_ellipsis
P_ ((struct it
*));
932 static int next_element_from_display_vector
P_ ((struct it
*));
933 static int next_element_from_string
P_ ((struct it
*));
934 static int next_element_from_c_string
P_ ((struct it
*));
935 static int next_element_from_buffer
P_ ((struct it
*));
936 static int next_element_from_composition
P_ ((struct it
*));
937 static int next_element_from_image
P_ ((struct it
*));
938 static int next_element_from_stretch
P_ ((struct it
*));
939 static void load_overlay_strings
P_ ((struct it
*, int));
940 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
941 struct display_pos
*));
942 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
943 Lisp_Object
, int, int, int, int));
944 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
946 void move_it_vertically_backward
P_ ((struct it
*, int));
947 static void init_to_row_start
P_ ((struct it
*, struct window
*,
948 struct glyph_row
*));
949 static int init_to_row_end
P_ ((struct it
*, struct window
*,
950 struct glyph_row
*));
951 static void back_to_previous_line_start
P_ ((struct it
*));
952 static int forward_to_next_line_start
P_ ((struct it
*, int *));
953 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
955 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
956 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
957 static int number_of_chars
P_ ((unsigned char *, int));
958 static void compute_stop_pos
P_ ((struct it
*));
959 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
961 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
962 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
963 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
964 Lisp_Object
, Lisp_Object
,
965 struct text_pos
*, int));
966 static int underlying_face_id
P_ ((struct it
*));
967 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
970 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
971 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
973 #ifdef HAVE_WINDOW_SYSTEM
975 static void update_tool_bar
P_ ((struct frame
*, int));
976 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
977 static int redisplay_tool_bar
P_ ((struct frame
*));
978 static void display_tool_bar_line
P_ ((struct it
*, int));
979 static void notice_overwritten_cursor
P_ ((struct window
*,
981 int, int, int, int));
985 #endif /* HAVE_WINDOW_SYSTEM */
988 /***********************************************************************
989 Window display dimensions
990 ***********************************************************************/
992 /* Return the bottom boundary y-position for text lines in window W.
993 This is the first y position at which a line cannot start.
994 It is relative to the top of the window.
996 This is the height of W minus the height of a mode line, if any. */
999 window_text_bottom_y (w
)
1002 int height
= WINDOW_TOTAL_HEIGHT (w
);
1004 if (WINDOW_WANTS_MODELINE_P (w
))
1005 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1009 /* Return the pixel width of display area AREA of window W. AREA < 0
1010 means return the total width of W, not including fringes to
1011 the left and right of the window. */
1014 window_box_width (w
, area
)
1018 int cols
= XFASTINT (w
->total_cols
);
1021 if (!w
->pseudo_window_p
)
1023 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1025 if (area
== TEXT_AREA
)
1027 if (INTEGERP (w
->left_margin_cols
))
1028 cols
-= XFASTINT (w
->left_margin_cols
);
1029 if (INTEGERP (w
->right_margin_cols
))
1030 cols
-= XFASTINT (w
->right_margin_cols
);
1031 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1033 else if (area
== LEFT_MARGIN_AREA
)
1035 cols
= (INTEGERP (w
->left_margin_cols
)
1036 ? XFASTINT (w
->left_margin_cols
) : 0);
1039 else if (area
== RIGHT_MARGIN_AREA
)
1041 cols
= (INTEGERP (w
->right_margin_cols
)
1042 ? XFASTINT (w
->right_margin_cols
) : 0);
1047 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1051 /* Return the pixel height of the display area of window W, not
1052 including mode lines of W, if any. */
1055 window_box_height (w
)
1058 struct frame
*f
= XFRAME (w
->frame
);
1059 int height
= WINDOW_TOTAL_HEIGHT (w
);
1061 xassert (height
>= 0);
1063 /* Note: the code below that determines the mode-line/header-line
1064 height is essentially the same as that contained in the macro
1065 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1066 the appropriate glyph row has its `mode_line_p' flag set,
1067 and if it doesn't, uses estimate_mode_line_height instead. */
1069 if (WINDOW_WANTS_MODELINE_P (w
))
1071 struct glyph_row
*ml_row
1072 = (w
->current_matrix
&& w
->current_matrix
->rows
1073 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1075 if (ml_row
&& ml_row
->mode_line_p
)
1076 height
-= ml_row
->height
;
1078 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1081 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1083 struct glyph_row
*hl_row
1084 = (w
->current_matrix
&& w
->current_matrix
->rows
1085 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1087 if (hl_row
&& hl_row
->mode_line_p
)
1088 height
-= hl_row
->height
;
1090 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1093 /* With a very small font and a mode-line that's taller than
1094 default, we might end up with a negative height. */
1095 return max (0, height
);
1098 /* Return the window-relative coordinate of the left edge of display
1099 area AREA of window W. AREA < 0 means return the left edge of the
1100 whole window, to the right of the left fringe of W. */
1103 window_box_left_offset (w
, area
)
1109 if (w
->pseudo_window_p
)
1112 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1114 if (area
== TEXT_AREA
)
1115 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1116 + window_box_width (w
, LEFT_MARGIN_AREA
));
1117 else if (area
== RIGHT_MARGIN_AREA
)
1118 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1119 + window_box_width (w
, LEFT_MARGIN_AREA
)
1120 + window_box_width (w
, TEXT_AREA
)
1121 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1123 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1124 else if (area
== LEFT_MARGIN_AREA
1125 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1126 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1132 /* Return the window-relative coordinate of the right edge of display
1133 area AREA of window W. AREA < 0 means return the left edge of the
1134 whole window, to the left of the right fringe of W. */
1137 window_box_right_offset (w
, area
)
1141 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1144 /* Return the frame-relative coordinate of the left edge of display
1145 area AREA of window W. AREA < 0 means return the left edge of the
1146 whole window, to the right of the left fringe of W. */
1149 window_box_left (w
, area
)
1153 struct frame
*f
= XFRAME (w
->frame
);
1156 if (w
->pseudo_window_p
)
1157 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1159 x
= (WINDOW_LEFT_EDGE_X (w
)
1160 + window_box_left_offset (w
, area
));
1166 /* Return the frame-relative coordinate of the right edge of display
1167 area AREA of window W. AREA < 0 means return the left edge of the
1168 whole window, to the left of the right fringe of W. */
1171 window_box_right (w
, area
)
1175 return window_box_left (w
, area
) + window_box_width (w
, area
);
1178 /* Get the bounding box of the display area AREA of window W, without
1179 mode lines, in frame-relative coordinates. AREA < 0 means the
1180 whole window, not including the left and right fringes of
1181 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1182 coordinates of the upper-left corner of the box. Return in
1183 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1186 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1189 int *box_x
, *box_y
, *box_width
, *box_height
;
1192 *box_width
= window_box_width (w
, area
);
1194 *box_height
= window_box_height (w
);
1196 *box_x
= window_box_left (w
, area
);
1199 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1200 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1201 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1206 /* Get the bounding box of the display area AREA of window W, without
1207 mode lines. AREA < 0 means the whole window, not including the
1208 left and right fringe of the window. Return in *TOP_LEFT_X
1209 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1210 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1211 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1215 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1216 bottom_right_x
, bottom_right_y
)
1219 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1221 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1223 *bottom_right_x
+= *top_left_x
;
1224 *bottom_right_y
+= *top_left_y
;
1229 /***********************************************************************
1231 ***********************************************************************/
1233 /* Return the bottom y-position of the line the iterator IT is in.
1234 This can modify IT's settings. */
1240 int line_height
= it
->max_ascent
+ it
->max_descent
;
1241 int line_top_y
= it
->current_y
;
1243 if (line_height
== 0)
1246 line_height
= last_height
;
1247 else if (IT_CHARPOS (*it
) < ZV
)
1249 move_it_by_lines (it
, 1, 1);
1250 line_height
= (it
->max_ascent
|| it
->max_descent
1251 ? it
->max_ascent
+ it
->max_descent
1256 struct glyph_row
*row
= it
->glyph_row
;
1258 /* Use the default character height. */
1259 it
->glyph_row
= NULL
;
1260 it
->what
= IT_CHARACTER
;
1263 PRODUCE_GLYPHS (it
);
1264 line_height
= it
->ascent
+ it
->descent
;
1265 it
->glyph_row
= row
;
1269 return line_top_y
+ line_height
;
1273 /* Return 1 if position CHARPOS is visible in window W.
1274 CHARPOS < 0 means return info about WINDOW_END position.
1275 If visible, set *X and *Y to pixel coordinates of top left corner.
1276 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1277 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1280 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1282 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1285 struct text_pos top
;
1287 struct buffer
*old_buffer
= NULL
;
1292 if (XBUFFER (w
->buffer
) != current_buffer
)
1294 old_buffer
= current_buffer
;
1295 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1298 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1300 /* Compute exact mode line heights. */
1301 if (WINDOW_WANTS_MODELINE_P (w
))
1302 current_mode_line_height
1303 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1304 current_buffer
->mode_line_format
);
1306 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1307 current_header_line_height
1308 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1309 current_buffer
->header_line_format
);
1311 start_display (&it
, w
, top
);
1312 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1313 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1315 /* Note that we may overshoot because of invisible text. */
1316 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1318 int top_x
= it
.current_x
;
1319 int top_y
= it
.current_y
;
1320 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1321 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1323 if (top_y
< window_top_y
)
1324 visible_p
= bottom_y
> window_top_y
;
1325 else if (top_y
< it
.last_visible_y
)
1329 if (it
.method
== GET_FROM_BUFFER
)
1331 Lisp_Object window
, prop
;
1333 XSETWINDOW (window
, w
);
1334 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1335 Qinvisible
, window
);
1337 /* If charpos coincides with invisible text covered with an
1338 ellipsis, use the first glyph of the ellipsis to compute
1339 the pixel positions. */
1340 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1342 struct glyph_row
*row
= it
.glyph_row
;
1343 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1344 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1347 for (; glyph
< end
&& glyph
->charpos
< charpos
; glyph
++)
1348 x
+= glyph
->pixel_width
;
1355 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1356 *rtop
= max (0, window_top_y
- top_y
);
1357 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1358 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1359 - max (top_y
, window_top_y
)));
1368 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1369 move_it_by_lines (&it
, 1, 0);
1370 if (charpos
< IT_CHARPOS (it
)
1371 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1374 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1376 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1377 *rtop
= max (0, -it2
.current_y
);
1378 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1379 - it
.last_visible_y
));
1380 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1382 - max (it2
.current_y
,
1383 WINDOW_HEADER_LINE_HEIGHT (w
))));
1389 set_buffer_internal_1 (old_buffer
);
1391 current_header_line_height
= current_mode_line_height
= -1;
1393 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1394 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1397 /* Debugging code. */
1399 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1400 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1402 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1409 /* Return the next character from STR which is MAXLEN bytes long.
1410 Return in *LEN the length of the character. This is like
1411 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1412 we find one, we return a `?', but with the length of the invalid
1416 string_char_and_length (str
, maxlen
, len
)
1417 const unsigned char *str
;
1422 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1423 if (!CHAR_VALID_P (c
, 1))
1424 /* We may not change the length here because other places in Emacs
1425 don't use this function, i.e. they silently accept invalid
1434 /* Given a position POS containing a valid character and byte position
1435 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1437 static struct text_pos
1438 string_pos_nchars_ahead (pos
, string
, nchars
)
1439 struct text_pos pos
;
1443 xassert (STRINGP (string
) && nchars
>= 0);
1445 if (STRING_MULTIBYTE (string
))
1447 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1448 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1453 string_char_and_length (p
, rest
, &len
);
1454 p
+= len
, rest
-= len
;
1455 xassert (rest
>= 0);
1457 BYTEPOS (pos
) += len
;
1461 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1467 /* Value is the text position, i.e. character and byte position,
1468 for character position CHARPOS in STRING. */
1470 static INLINE
struct text_pos
1471 string_pos (charpos
, string
)
1475 struct text_pos pos
;
1476 xassert (STRINGP (string
));
1477 xassert (charpos
>= 0);
1478 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1483 /* Value is a text position, i.e. character and byte position, for
1484 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1485 means recognize multibyte characters. */
1487 static struct text_pos
1488 c_string_pos (charpos
, s
, multibyte_p
)
1493 struct text_pos pos
;
1495 xassert (s
!= NULL
);
1496 xassert (charpos
>= 0);
1500 int rest
= strlen (s
), len
;
1502 SET_TEXT_POS (pos
, 0, 0);
1505 string_char_and_length (s
, rest
, &len
);
1506 s
+= len
, rest
-= len
;
1507 xassert (rest
>= 0);
1509 BYTEPOS (pos
) += len
;
1513 SET_TEXT_POS (pos
, charpos
, charpos
);
1519 /* Value is the number of characters in C string S. MULTIBYTE_P
1520 non-zero means recognize multibyte characters. */
1523 number_of_chars (s
, multibyte_p
)
1531 int rest
= strlen (s
), len
;
1532 unsigned char *p
= (unsigned char *) s
;
1534 for (nchars
= 0; rest
> 0; ++nchars
)
1536 string_char_and_length (p
, rest
, &len
);
1537 rest
-= len
, p
+= len
;
1541 nchars
= strlen (s
);
1547 /* Compute byte position NEWPOS->bytepos corresponding to
1548 NEWPOS->charpos. POS is a known position in string STRING.
1549 NEWPOS->charpos must be >= POS.charpos. */
1552 compute_string_pos (newpos
, pos
, string
)
1553 struct text_pos
*newpos
, pos
;
1556 xassert (STRINGP (string
));
1557 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1559 if (STRING_MULTIBYTE (string
))
1560 *newpos
= string_pos_nchars_ahead (pos
, string
,
1561 CHARPOS (*newpos
) - CHARPOS (pos
));
1563 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1567 Return an estimation of the pixel height of mode or top lines on
1568 frame F. FACE_ID specifies what line's height to estimate. */
1571 estimate_mode_line_height (f
, face_id
)
1573 enum face_id face_id
;
1575 #ifdef HAVE_WINDOW_SYSTEM
1576 if (FRAME_WINDOW_P (f
))
1578 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1580 /* This function is called so early when Emacs starts that the face
1581 cache and mode line face are not yet initialized. */
1582 if (FRAME_FACE_CACHE (f
))
1584 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1588 height
= FONT_HEIGHT (face
->font
);
1589 if (face
->box_line_width
> 0)
1590 height
+= 2 * face
->box_line_width
;
1601 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1602 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1603 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1604 not force the value into range. */
1607 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1609 register int pix_x
, pix_y
;
1611 NativeRectangle
*bounds
;
1615 #ifdef HAVE_WINDOW_SYSTEM
1616 if (FRAME_WINDOW_P (f
))
1618 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1619 even for negative values. */
1621 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1623 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1625 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1626 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1629 STORE_NATIVE_RECT (*bounds
,
1630 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1631 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1632 FRAME_COLUMN_WIDTH (f
) - 1,
1633 FRAME_LINE_HEIGHT (f
) - 1);
1639 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1640 pix_x
= FRAME_TOTAL_COLS (f
);
1644 else if (pix_y
> FRAME_LINES (f
))
1645 pix_y
= FRAME_LINES (f
);
1655 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1656 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1657 can't tell the positions because W's display is not up to date,
1661 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1664 int *frame_x
, *frame_y
;
1666 #ifdef HAVE_WINDOW_SYSTEM
1667 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1671 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1672 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1674 if (display_completed
)
1676 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1677 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1678 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1684 hpos
+= glyph
->pixel_width
;
1688 /* If first glyph is partially visible, its first visible position is still 0. */
1700 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1701 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1712 #ifdef HAVE_WINDOW_SYSTEM
1714 /* Find the glyph under window-relative coordinates X/Y in window W.
1715 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1716 strings. Return in *HPOS and *VPOS the row and column number of
1717 the glyph found. Return in *AREA the glyph area containing X.
1718 Value is a pointer to the glyph found or null if X/Y is not on
1719 text, or we can't tell because W's current matrix is not up to
1726 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1729 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1731 struct glyph
*glyph
, *end
;
1732 struct glyph_row
*row
= NULL
;
1735 /* Find row containing Y. Give up if some row is not enabled. */
1736 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1738 row
= MATRIX_ROW (w
->current_matrix
, i
);
1739 if (!row
->enabled_p
)
1741 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1748 /* Give up if Y is not in the window. */
1749 if (i
== w
->current_matrix
->nrows
)
1752 /* Get the glyph area containing X. */
1753 if (w
->pseudo_window_p
)
1760 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1762 *area
= LEFT_MARGIN_AREA
;
1763 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1765 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1768 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1772 *area
= RIGHT_MARGIN_AREA
;
1773 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1777 /* Find glyph containing X. */
1778 glyph
= row
->glyphs
[*area
];
1779 end
= glyph
+ row
->used
[*area
];
1781 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1783 x
-= glyph
->pixel_width
;
1793 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1796 *hpos
= glyph
- row
->glyphs
[*area
];
1802 Convert frame-relative x/y to coordinates relative to window W.
1803 Takes pseudo-windows into account. */
1806 frame_to_window_pixel_xy (w
, x
, y
)
1810 if (w
->pseudo_window_p
)
1812 /* A pseudo-window is always full-width, and starts at the
1813 left edge of the frame, plus a frame border. */
1814 struct frame
*f
= XFRAME (w
->frame
);
1815 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1816 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1820 *x
-= WINDOW_LEFT_EDGE_X (w
);
1821 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1826 Return in RECTS[] at most N clipping rectangles for glyph string S.
1827 Return the number of stored rectangles. */
1830 get_glyph_string_clip_rects (s
, rects
, n
)
1831 struct glyph_string
*s
;
1832 NativeRectangle
*rects
;
1840 if (s
->row
->full_width_p
)
1842 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1843 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1844 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1846 /* Unless displaying a mode or menu bar line, which are always
1847 fully visible, clip to the visible part of the row. */
1848 if (s
->w
->pseudo_window_p
)
1849 r
.height
= s
->row
->visible_height
;
1851 r
.height
= s
->height
;
1855 /* This is a text line that may be partially visible. */
1856 r
.x
= window_box_left (s
->w
, s
->area
);
1857 r
.width
= window_box_width (s
->w
, s
->area
);
1858 r
.height
= s
->row
->visible_height
;
1862 if (r
.x
< s
->clip_head
->x
)
1864 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1865 r
.width
-= s
->clip_head
->x
- r
.x
;
1868 r
.x
= s
->clip_head
->x
;
1871 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1873 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1874 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1879 /* If S draws overlapping rows, it's sufficient to use the top and
1880 bottom of the window for clipping because this glyph string
1881 intentionally draws over other lines. */
1882 if (s
->for_overlaps
)
1884 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1885 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1887 /* Alas, the above simple strategy does not work for the
1888 environments with anti-aliased text: if the same text is
1889 drawn onto the same place multiple times, it gets thicker.
1890 If the overlap we are processing is for the erased cursor, we
1891 take the intersection with the rectagle of the cursor. */
1892 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1894 XRectangle rc
, r_save
= r
;
1896 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1897 rc
.y
= s
->w
->phys_cursor
.y
;
1898 rc
.width
= s
->w
->phys_cursor_width
;
1899 rc
.height
= s
->w
->phys_cursor_height
;
1901 x_intersect_rectangles (&r_save
, &rc
, &r
);
1906 /* Don't use S->y for clipping because it doesn't take partially
1907 visible lines into account. For example, it can be negative for
1908 partially visible lines at the top of a window. */
1909 if (!s
->row
->full_width_p
1910 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1911 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1913 r
.y
= max (0, s
->row
->y
);
1915 /* If drawing a tool-bar window, draw it over the internal border
1916 at the top of the window. */
1917 if (WINDOWP (s
->f
->tool_bar_window
)
1918 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1919 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1922 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1924 /* If drawing the cursor, don't let glyph draw outside its
1925 advertised boundaries. Cleartype does this under some circumstances. */
1926 if (s
->hl
== DRAW_CURSOR
)
1928 struct glyph
*glyph
= s
->first_glyph
;
1933 r
.width
-= s
->x
- r
.x
;
1936 r
.width
= min (r
.width
, glyph
->pixel_width
);
1938 /* If r.y is below window bottom, ensure that we still see a cursor. */
1939 height
= min (glyph
->ascent
+ glyph
->descent
,
1940 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1941 max_y
= window_text_bottom_y (s
->w
) - height
;
1942 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1943 if (s
->ybase
- glyph
->ascent
> max_y
)
1950 /* Don't draw cursor glyph taller than our actual glyph. */
1951 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1952 if (height
< r
.height
)
1954 max_y
= r
.y
+ r
.height
;
1955 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1956 r
.height
= min (max_y
- r
.y
, height
);
1963 XRectangle r_save
= r
;
1965 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1969 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1970 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1972 #ifdef CONVERT_FROM_XRECT
1973 CONVERT_FROM_XRECT (r
, *rects
);
1981 /* If we are processing overlapping and allowed to return
1982 multiple clipping rectangles, we exclude the row of the glyph
1983 string from the clipping rectangle. This is to avoid drawing
1984 the same text on the environment with anti-aliasing. */
1985 #ifdef CONVERT_FROM_XRECT
1988 XRectangle
*rs
= rects
;
1990 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1992 if (s
->for_overlaps
& OVERLAPS_PRED
)
1995 if (r
.y
+ r
.height
> row_y
)
1998 rs
[i
].height
= row_y
- r
.y
;
2004 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2007 if (r
.y
< row_y
+ s
->row
->visible_height
)
2009 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2011 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2012 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2021 #ifdef CONVERT_FROM_XRECT
2022 for (i
= 0; i
< n
; i
++)
2023 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2030 Return in *NR the clipping rectangle for glyph string S. */
2033 get_glyph_string_clip_rect (s
, nr
)
2034 struct glyph_string
*s
;
2035 NativeRectangle
*nr
;
2037 get_glyph_string_clip_rects (s
, nr
, 1);
2042 Return the position and height of the phys cursor in window W.
2043 Set w->phys_cursor_width to width of phys cursor.
2047 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2049 struct glyph_row
*row
;
2050 struct glyph
*glyph
;
2051 int *xp
, *yp
, *heightp
;
2053 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2054 int x
, y
, wd
, h
, h0
, y0
;
2056 /* Compute the width of the rectangle to draw. If on a stretch
2057 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2058 rectangle as wide as the glyph, but use a canonical character
2060 wd
= glyph
->pixel_width
- 1;
2065 x
= w
->phys_cursor
.x
;
2072 if (glyph
->type
== STRETCH_GLYPH
2073 && !x_stretch_cursor_p
)
2074 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2075 w
->phys_cursor_width
= wd
;
2077 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2079 /* If y is below window bottom, ensure that we still see a cursor. */
2080 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2082 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2083 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2085 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2088 h
= max (h
- (y0
- y
) + 1, h0
);
2093 y0
= window_text_bottom_y (w
) - h0
;
2101 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2102 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2107 * Remember which glyph the mouse is over.
2111 remember_mouse_glyph (f
, gx
, gy
, rect
)
2114 NativeRectangle
*rect
;
2118 struct glyph_row
*r
, *gr
, *end_row
;
2119 enum window_part part
;
2120 enum glyph_row_area area
;
2121 int x
, y
, width
, height
;
2123 /* Try to determine frame pixel position and size of the glyph under
2124 frame pixel coordinates X/Y on frame F. */
2126 if (!f
->glyphs_initialized_p
2127 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2130 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2131 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2135 w
= XWINDOW (window
);
2136 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2137 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2139 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2140 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2142 if (w
->pseudo_window_p
)
2145 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2151 case ON_LEFT_MARGIN
:
2152 area
= LEFT_MARGIN_AREA
;
2155 case ON_RIGHT_MARGIN
:
2156 area
= RIGHT_MARGIN_AREA
;
2159 case ON_HEADER_LINE
:
2161 gr
= (part
== ON_HEADER_LINE
2162 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2163 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2166 goto text_glyph_row_found
;
2173 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2174 if (r
->y
+ r
->height
> y
)
2180 text_glyph_row_found
:
2183 struct glyph
*g
= gr
->glyphs
[area
];
2184 struct glyph
*end
= g
+ gr
->used
[area
];
2186 height
= gr
->height
;
2187 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2188 if (gx
+ g
->pixel_width
> x
)
2193 if (g
->type
== IMAGE_GLYPH
)
2195 /* Don't remember when mouse is over image, as
2196 image may have hot-spots. */
2197 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2200 width
= g
->pixel_width
;
2204 /* Use nominal char spacing at end of line. */
2206 gx
+= (x
/ width
) * width
;
2209 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2210 gx
+= window_box_left_offset (w
, area
);
2214 /* Use nominal line height at end of window. */
2215 gx
= (x
/ width
) * width
;
2217 gy
+= (y
/ height
) * height
;
2221 case ON_LEFT_FRINGE
:
2222 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2223 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2224 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2225 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2228 case ON_RIGHT_FRINGE
:
2229 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2230 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2231 : window_box_right_offset (w
, TEXT_AREA
));
2232 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2236 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2238 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2239 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2240 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2242 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2246 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2247 if (r
->y
+ r
->height
> y
)
2254 height
= gr
->height
;
2257 /* Use nominal line height at end of window. */
2259 gy
+= (y
/ height
) * height
;
2266 /* If there is no glyph under the mouse, then we divide the screen
2267 into a grid of the smallest glyph in the frame, and use that
2270 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2271 round down even for negative values. */
2277 gx
= (gx
/ width
) * width
;
2278 gy
= (gy
/ height
) * height
;
2283 gx
+= WINDOW_LEFT_EDGE_X (w
);
2284 gy
+= WINDOW_TOP_EDGE_Y (w
);
2287 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2289 /* Visible feedback for debugging. */
2292 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2293 f
->output_data
.x
->normal_gc
,
2294 gx
, gy
, width
, height
);
2300 #endif /* HAVE_WINDOW_SYSTEM */
2303 /***********************************************************************
2304 Lisp form evaluation
2305 ***********************************************************************/
2307 /* Error handler for safe_eval and safe_call. */
2310 safe_eval_handler (arg
)
2313 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2318 /* Evaluate SEXPR and return the result, or nil if something went
2319 wrong. Prevent redisplay during the evaluation. */
2321 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2322 Return the result, or nil if something went wrong. Prevent
2323 redisplay during the evaluation. */
2326 safe_call (nargs
, args
)
2332 if (inhibit_eval_during_redisplay
)
2336 int count
= SPECPDL_INDEX ();
2337 struct gcpro gcpro1
;
2340 gcpro1
.nvars
= nargs
;
2341 specbind (Qinhibit_redisplay
, Qt
);
2342 /* Use Qt to ensure debugger does not run,
2343 so there is no possibility of wanting to redisplay. */
2344 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2347 val
= unbind_to (count
, val
);
2354 /* Call function FN with one argument ARG.
2355 Return the result, or nil if something went wrong. */
2358 safe_call1 (fn
, arg
)
2359 Lisp_Object fn
, arg
;
2361 Lisp_Object args
[2];
2364 return safe_call (2, args
);
2367 static Lisp_Object Qeval
;
2370 safe_eval (Lisp_Object sexpr
)
2372 return safe_call1 (Qeval
, sexpr
);
2375 /* Call function FN with one argument ARG.
2376 Return the result, or nil if something went wrong. */
2379 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2381 Lisp_Object args
[3];
2385 return safe_call (3, args
);
2390 /***********************************************************************
2392 ***********************************************************************/
2396 /* Define CHECK_IT to perform sanity checks on iterators.
2397 This is for debugging. It is too slow to do unconditionally. */
2403 if (it
->method
== GET_FROM_STRING
)
2405 xassert (STRINGP (it
->string
));
2406 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2410 xassert (IT_STRING_CHARPOS (*it
) < 0);
2411 if (it
->method
== GET_FROM_BUFFER
)
2413 /* Check that character and byte positions agree. */
2414 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2419 xassert (it
->current
.dpvec_index
>= 0);
2421 xassert (it
->current
.dpvec_index
< 0);
2424 #define CHECK_IT(IT) check_it ((IT))
2428 #define CHECK_IT(IT) (void) 0
2435 /* Check that the window end of window W is what we expect it
2436 to be---the last row in the current matrix displaying text. */
2439 check_window_end (w
)
2442 if (!MINI_WINDOW_P (w
)
2443 && !NILP (w
->window_end_valid
))
2445 struct glyph_row
*row
;
2446 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2447 XFASTINT (w
->window_end_vpos
)),
2449 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2450 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2454 #define CHECK_WINDOW_END(W) check_window_end ((W))
2456 #else /* not GLYPH_DEBUG */
2458 #define CHECK_WINDOW_END(W) (void) 0
2460 #endif /* not GLYPH_DEBUG */
2464 /***********************************************************************
2465 Iterator initialization
2466 ***********************************************************************/
2468 /* Initialize IT for displaying current_buffer in window W, starting
2469 at character position CHARPOS. CHARPOS < 0 means that no buffer
2470 position is specified which is useful when the iterator is assigned
2471 a position later. BYTEPOS is the byte position corresponding to
2472 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2474 If ROW is not null, calls to produce_glyphs with IT as parameter
2475 will produce glyphs in that row.
2477 BASE_FACE_ID is the id of a base face to use. It must be one of
2478 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2479 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2480 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2482 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2483 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2484 will be initialized to use the corresponding mode line glyph row of
2485 the desired matrix of W. */
2488 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2491 int charpos
, bytepos
;
2492 struct glyph_row
*row
;
2493 enum face_id base_face_id
;
2495 int highlight_region_p
;
2497 /* Some precondition checks. */
2498 xassert (w
!= NULL
&& it
!= NULL
);
2499 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2502 /* If face attributes have been changed since the last redisplay,
2503 free realized faces now because they depend on face definitions
2504 that might have changed. Don't free faces while there might be
2505 desired matrices pending which reference these faces. */
2506 if (face_change_count
&& !inhibit_free_realized_faces
)
2508 face_change_count
= 0;
2509 free_all_realized_faces (Qnil
);
2512 /* Use one of the mode line rows of W's desired matrix if
2516 if (base_face_id
== MODE_LINE_FACE_ID
2517 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2518 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2519 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2520 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2524 bzero (it
, sizeof *it
);
2525 it
->current
.overlay_string_index
= -1;
2526 it
->current
.dpvec_index
= -1;
2527 it
->base_face_id
= base_face_id
;
2529 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2531 /* The window in which we iterate over current_buffer: */
2532 XSETWINDOW (it
->window
, w
);
2534 it
->f
= XFRAME (w
->frame
);
2536 /* Extra space between lines (on window systems only). */
2537 if (base_face_id
== DEFAULT_FACE_ID
2538 && FRAME_WINDOW_P (it
->f
))
2540 if (NATNUMP (current_buffer
->extra_line_spacing
))
2541 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2542 else if (FLOATP (current_buffer
->extra_line_spacing
))
2543 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2544 * FRAME_LINE_HEIGHT (it
->f
));
2545 else if (it
->f
->extra_line_spacing
> 0)
2546 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2547 it
->max_extra_line_spacing
= 0;
2550 /* If realized faces have been removed, e.g. because of face
2551 attribute changes of named faces, recompute them. When running
2552 in batch mode, the face cache of the initial frame is null. If
2553 we happen to get called, make a dummy face cache. */
2554 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2555 init_frame_faces (it
->f
);
2556 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2557 recompute_basic_faces (it
->f
);
2559 /* Current value of the `slice', `space-width', and 'height' properties. */
2560 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2561 it
->space_width
= Qnil
;
2562 it
->font_height
= Qnil
;
2563 it
->override_ascent
= -1;
2565 /* Are control characters displayed as `^C'? */
2566 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2568 /* -1 means everything between a CR and the following line end
2569 is invisible. >0 means lines indented more than this value are
2571 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2572 ? XFASTINT (current_buffer
->selective_display
)
2573 : (!NILP (current_buffer
->selective_display
)
2575 it
->selective_display_ellipsis_p
2576 = !NILP (current_buffer
->selective_display_ellipses
);
2578 /* Display table to use. */
2579 it
->dp
= window_display_table (w
);
2581 /* Are multibyte characters enabled in current_buffer? */
2582 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2584 /* Non-zero if we should highlight the region. */
2586 = (!NILP (Vtransient_mark_mode
)
2587 && !NILP (current_buffer
->mark_active
)
2588 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2590 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2591 start and end of a visible region in window IT->w. Set both to
2592 -1 to indicate no region. */
2593 if (highlight_region_p
2594 /* Maybe highlight only in selected window. */
2595 && (/* Either show region everywhere. */
2596 highlight_nonselected_windows
2597 /* Or show region in the selected window. */
2598 || w
== XWINDOW (selected_window
)
2599 /* Or show the region if we are in the mini-buffer and W is
2600 the window the mini-buffer refers to. */
2601 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2602 && WINDOWP (minibuf_selected_window
)
2603 && w
== XWINDOW (minibuf_selected_window
))))
2605 int charpos
= marker_position (current_buffer
->mark
);
2606 it
->region_beg_charpos
= min (PT
, charpos
);
2607 it
->region_end_charpos
= max (PT
, charpos
);
2610 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2612 /* Get the position at which the redisplay_end_trigger hook should
2613 be run, if it is to be run at all. */
2614 if (MARKERP (w
->redisplay_end_trigger
)
2615 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2616 it
->redisplay_end_trigger_charpos
2617 = marker_position (w
->redisplay_end_trigger
);
2618 else if (INTEGERP (w
->redisplay_end_trigger
))
2619 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2621 /* Correct bogus values of tab_width. */
2622 it
->tab_width
= XINT (current_buffer
->tab_width
);
2623 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2626 /* Are lines in the display truncated? */
2627 it
->truncate_lines_p
2628 = (base_face_id
!= DEFAULT_FACE_ID
2629 || XINT (it
->w
->hscroll
)
2630 || (truncate_partial_width_windows
2631 && !WINDOW_FULL_WIDTH_P (it
->w
))
2632 || !NILP (current_buffer
->truncate_lines
));
2634 /* Get dimensions of truncation and continuation glyphs. These are
2635 displayed as fringe bitmaps under X, so we don't need them for such
2637 if (!FRAME_WINDOW_P (it
->f
))
2639 if (it
->truncate_lines_p
)
2641 /* We will need the truncation glyph. */
2642 xassert (it
->glyph_row
== NULL
);
2643 produce_special_glyphs (it
, IT_TRUNCATION
);
2644 it
->truncation_pixel_width
= it
->pixel_width
;
2648 /* We will need the continuation glyph. */
2649 xassert (it
->glyph_row
== NULL
);
2650 produce_special_glyphs (it
, IT_CONTINUATION
);
2651 it
->continuation_pixel_width
= it
->pixel_width
;
2654 /* Reset these values to zero because the produce_special_glyphs
2655 above has changed them. */
2656 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2657 it
->phys_ascent
= it
->phys_descent
= 0;
2660 /* Set this after getting the dimensions of truncation and
2661 continuation glyphs, so that we don't produce glyphs when calling
2662 produce_special_glyphs, above. */
2663 it
->glyph_row
= row
;
2664 it
->area
= TEXT_AREA
;
2666 /* Get the dimensions of the display area. The display area
2667 consists of the visible window area plus a horizontally scrolled
2668 part to the left of the window. All x-values are relative to the
2669 start of this total display area. */
2670 if (base_face_id
!= DEFAULT_FACE_ID
)
2672 /* Mode lines, menu bar in terminal frames. */
2673 it
->first_visible_x
= 0;
2674 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2679 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2680 it
->last_visible_x
= (it
->first_visible_x
2681 + window_box_width (w
, TEXT_AREA
));
2683 /* If we truncate lines, leave room for the truncator glyph(s) at
2684 the right margin. Otherwise, leave room for the continuation
2685 glyph(s). Truncation and continuation glyphs are not inserted
2686 for window-based redisplay. */
2687 if (!FRAME_WINDOW_P (it
->f
))
2689 if (it
->truncate_lines_p
)
2690 it
->last_visible_x
-= it
->truncation_pixel_width
;
2692 it
->last_visible_x
-= it
->continuation_pixel_width
;
2695 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2696 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2699 /* Leave room for a border glyph. */
2700 if (!FRAME_WINDOW_P (it
->f
)
2701 && !WINDOW_RIGHTMOST_P (it
->w
))
2702 it
->last_visible_x
-= 1;
2704 it
->last_visible_y
= window_text_bottom_y (w
);
2706 /* For mode lines and alike, arrange for the first glyph having a
2707 left box line if the face specifies a box. */
2708 if (base_face_id
!= DEFAULT_FACE_ID
)
2712 it
->face_id
= base_face_id
;
2714 /* If we have a boxed mode line, make the first character appear
2715 with a left box line. */
2716 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2717 if (face
->box
!= FACE_NO_BOX
)
2718 it
->start_of_box_run_p
= 1;
2721 /* If a buffer position was specified, set the iterator there,
2722 getting overlays and face properties from that position. */
2723 if (charpos
>= BUF_BEG (current_buffer
))
2725 it
->end_charpos
= ZV
;
2727 IT_CHARPOS (*it
) = charpos
;
2729 /* Compute byte position if not specified. */
2730 if (bytepos
< charpos
)
2731 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2733 IT_BYTEPOS (*it
) = bytepos
;
2735 it
->start
= it
->current
;
2737 /* Compute faces etc. */
2738 reseat (it
, it
->current
.pos
, 1);
2745 /* Initialize IT for the display of window W with window start POS. */
2748 start_display (it
, w
, pos
)
2751 struct text_pos pos
;
2753 struct glyph_row
*row
;
2754 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2756 row
= w
->desired_matrix
->rows
+ first_vpos
;
2757 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2758 it
->first_vpos
= first_vpos
;
2760 /* Don't reseat to previous visible line start if current start
2761 position is in a string or image. */
2762 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2764 int start_at_line_beg_p
;
2765 int first_y
= it
->current_y
;
2767 /* If window start is not at a line start, skip forward to POS to
2768 get the correct continuation lines width. */
2769 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2770 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2771 if (!start_at_line_beg_p
)
2775 reseat_at_previous_visible_line_start (it
);
2776 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2778 new_x
= it
->current_x
+ it
->pixel_width
;
2780 /* If lines are continued, this line may end in the middle
2781 of a multi-glyph character (e.g. a control character
2782 displayed as \003, or in the middle of an overlay
2783 string). In this case move_it_to above will not have
2784 taken us to the start of the continuation line but to the
2785 end of the continued line. */
2786 if (it
->current_x
> 0
2787 && !it
->truncate_lines_p
/* Lines are continued. */
2788 && (/* And glyph doesn't fit on the line. */
2789 new_x
> it
->last_visible_x
2790 /* Or it fits exactly and we're on a window
2792 || (new_x
== it
->last_visible_x
2793 && FRAME_WINDOW_P (it
->f
))))
2795 if (it
->current
.dpvec_index
>= 0
2796 || it
->current
.overlay_string_index
>= 0)
2798 set_iterator_to_next (it
, 1);
2799 move_it_in_display_line_to (it
, -1, -1, 0);
2802 it
->continuation_lines_width
+= it
->current_x
;
2805 /* We're starting a new display line, not affected by the
2806 height of the continued line, so clear the appropriate
2807 fields in the iterator structure. */
2808 it
->max_ascent
= it
->max_descent
= 0;
2809 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2811 it
->current_y
= first_y
;
2813 it
->current_x
= it
->hpos
= 0;
2817 #if 0 /* Don't assert the following because start_display is sometimes
2818 called intentionally with a window start that is not at a
2819 line start. Please leave this code in as a comment. */
2821 /* Window start should be on a line start, now. */
2822 xassert (it
->continuation_lines_width
2823 || IT_CHARPOS (it
) == BEGV
2824 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2829 /* Return 1 if POS is a position in ellipses displayed for invisible
2830 text. W is the window we display, for text property lookup. */
2833 in_ellipses_for_invisible_text_p (pos
, w
)
2834 struct display_pos
*pos
;
2837 Lisp_Object prop
, window
;
2839 int charpos
= CHARPOS (pos
->pos
);
2841 /* If POS specifies a position in a display vector, this might
2842 be for an ellipsis displayed for invisible text. We won't
2843 get the iterator set up for delivering that ellipsis unless
2844 we make sure that it gets aware of the invisible text. */
2845 if (pos
->dpvec_index
>= 0
2846 && pos
->overlay_string_index
< 0
2847 && CHARPOS (pos
->string_pos
) < 0
2849 && (XSETWINDOW (window
, w
),
2850 prop
= Fget_char_property (make_number (charpos
),
2851 Qinvisible
, window
),
2852 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2854 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2856 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2863 /* Initialize IT for stepping through current_buffer in window W,
2864 starting at position POS that includes overlay string and display
2865 vector/ control character translation position information. Value
2866 is zero if there are overlay strings with newlines at POS. */
2869 init_from_display_pos (it
, w
, pos
)
2872 struct display_pos
*pos
;
2874 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2875 int i
, overlay_strings_with_newlines
= 0;
2877 /* If POS specifies a position in a display vector, this might
2878 be for an ellipsis displayed for invisible text. We won't
2879 get the iterator set up for delivering that ellipsis unless
2880 we make sure that it gets aware of the invisible text. */
2881 if (in_ellipses_for_invisible_text_p (pos
, w
))
2887 /* Keep in mind: the call to reseat in init_iterator skips invisible
2888 text, so we might end up at a position different from POS. This
2889 is only a problem when POS is a row start after a newline and an
2890 overlay starts there with an after-string, and the overlay has an
2891 invisible property. Since we don't skip invisible text in
2892 display_line and elsewhere immediately after consuming the
2893 newline before the row start, such a POS will not be in a string,
2894 but the call to init_iterator below will move us to the
2896 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2898 /* This only scans the current chunk -- it should scan all chunks.
2899 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2900 to 16 in 22.1 to make this a lesser problem. */
2901 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2903 const char *s
= SDATA (it
->overlay_strings
[i
]);
2904 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2906 while (s
< e
&& *s
!= '\n')
2911 overlay_strings_with_newlines
= 1;
2916 /* If position is within an overlay string, set up IT to the right
2918 if (pos
->overlay_string_index
>= 0)
2922 /* If the first overlay string happens to have a `display'
2923 property for an image, the iterator will be set up for that
2924 image, and we have to undo that setup first before we can
2925 correct the overlay string index. */
2926 if (it
->method
== GET_FROM_IMAGE
)
2929 /* We already have the first chunk of overlay strings in
2930 IT->overlay_strings. Load more until the one for
2931 pos->overlay_string_index is in IT->overlay_strings. */
2932 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2934 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2935 it
->current
.overlay_string_index
= 0;
2938 load_overlay_strings (it
, 0);
2939 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2943 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2944 relative_index
= (it
->current
.overlay_string_index
2945 % OVERLAY_STRING_CHUNK_SIZE
);
2946 it
->string
= it
->overlay_strings
[relative_index
];
2947 xassert (STRINGP (it
->string
));
2948 it
->current
.string_pos
= pos
->string_pos
;
2949 it
->method
= GET_FROM_STRING
;
2952 #if 0 /* This is bogus because POS not having an overlay string
2953 position does not mean it's after the string. Example: A
2954 line starting with a before-string and initialization of IT
2955 to the previous row's end position. */
2956 else if (it
->current
.overlay_string_index
>= 0)
2958 /* If POS says we're already after an overlay string ending at
2959 POS, make sure to pop the iterator because it will be in
2960 front of that overlay string. When POS is ZV, we've thereby
2961 also ``processed'' overlay strings at ZV. */
2964 xassert (it
->current
.overlay_string_index
== -1);
2965 xassert (it
->method
== GET_FROM_BUFFER
);
2966 if (CHARPOS (pos
->pos
) == ZV
)
2967 it
->overlay_strings_at_end_processed_p
= 1;
2971 if (CHARPOS (pos
->string_pos
) >= 0)
2973 /* Recorded position is not in an overlay string, but in another
2974 string. This can only be a string from a `display' property.
2975 IT should already be filled with that string. */
2976 it
->current
.string_pos
= pos
->string_pos
;
2977 xassert (STRINGP (it
->string
));
2980 /* Restore position in display vector translations, control
2981 character translations or ellipses. */
2982 if (pos
->dpvec_index
>= 0)
2984 if (it
->dpvec
== NULL
)
2985 get_next_display_element (it
);
2986 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2987 it
->current
.dpvec_index
= pos
->dpvec_index
;
2991 return !overlay_strings_with_newlines
;
2995 /* Initialize IT for stepping through current_buffer in window W
2996 starting at ROW->start. */
2999 init_to_row_start (it
, w
, row
)
3002 struct glyph_row
*row
;
3004 init_from_display_pos (it
, w
, &row
->start
);
3005 it
->start
= row
->start
;
3006 it
->continuation_lines_width
= row
->continuation_lines_width
;
3011 /* Initialize IT for stepping through current_buffer in window W
3012 starting in the line following ROW, i.e. starting at ROW->end.
3013 Value is zero if there are overlay strings with newlines at ROW's
3017 init_to_row_end (it
, w
, row
)
3020 struct glyph_row
*row
;
3024 if (init_from_display_pos (it
, w
, &row
->end
))
3026 if (row
->continued_p
)
3027 it
->continuation_lines_width
3028 = row
->continuation_lines_width
+ row
->pixel_width
;
3039 /***********************************************************************
3041 ***********************************************************************/
3043 /* Called when IT reaches IT->stop_charpos. Handle text property and
3044 overlay changes. Set IT->stop_charpos to the next position where
3051 enum prop_handled handled
;
3052 int handle_overlay_change_p
;
3056 it
->current
.dpvec_index
= -1;
3057 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3058 it
->ignore_overlay_strings_at_pos_p
= 0;
3060 /* Use face of preceding text for ellipsis (if invisible) */
3061 if (it
->selective_display_ellipsis_p
)
3062 it
->saved_face_id
= it
->face_id
;
3066 handled
= HANDLED_NORMALLY
;
3068 /* Call text property handlers. */
3069 for (p
= it_props
; p
->handler
; ++p
)
3071 handled
= p
->handler (it
);
3073 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3075 else if (handled
== HANDLED_RETURN
)
3077 /* We still want to show before and after strings from
3078 overlays even if the actual buffer text is replaced. */
3079 if (!handle_overlay_change_p
|| it
->sp
> 1)
3081 if (!get_overlay_strings_1 (it
, 0, 0))
3083 it
->ignore_overlay_strings_at_pos_p
= 1;
3084 it
->string_from_display_prop_p
= 0;
3085 handle_overlay_change_p
= 0;
3086 handled
= HANDLED_RECOMPUTE_PROPS
;
3089 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3090 handle_overlay_change_p
= 0;
3093 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3095 /* Don't check for overlay strings below when set to deliver
3096 characters from a display vector. */
3097 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3098 handle_overlay_change_p
= 0;
3100 /* Handle overlay changes.
3101 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3102 if it finds overlays. */
3103 if (handle_overlay_change_p
)
3104 handled
= handle_overlay_change (it
);
3107 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3109 /* Determine where to stop next. */
3110 if (handled
== HANDLED_NORMALLY
)
3111 compute_stop_pos (it
);
3115 /* Compute IT->stop_charpos from text property and overlay change
3116 information for IT's current position. */
3119 compute_stop_pos (it
)
3122 register INTERVAL iv
, next_iv
;
3123 Lisp_Object object
, limit
, position
;
3125 /* If nowhere else, stop at the end. */
3126 it
->stop_charpos
= it
->end_charpos
;
3128 if (STRINGP (it
->string
))
3130 /* Strings are usually short, so don't limit the search for
3132 object
= it
->string
;
3134 position
= make_number (IT_STRING_CHARPOS (*it
));
3140 /* If next overlay change is in front of the current stop pos
3141 (which is IT->end_charpos), stop there. Note: value of
3142 next_overlay_change is point-max if no overlay change
3144 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3145 if (charpos
< it
->stop_charpos
)
3146 it
->stop_charpos
= charpos
;
3148 /* If showing the region, we have to stop at the region
3149 start or end because the face might change there. */
3150 if (it
->region_beg_charpos
> 0)
3152 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3153 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3154 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3155 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3158 /* Set up variables for computing the stop position from text
3159 property changes. */
3160 XSETBUFFER (object
, current_buffer
);
3161 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3162 position
= make_number (IT_CHARPOS (*it
));
3166 /* Get the interval containing IT's position. Value is a null
3167 interval if there isn't such an interval. */
3168 iv
= validate_interval_range (object
, &position
, &position
, 0);
3169 if (!NULL_INTERVAL_P (iv
))
3171 Lisp_Object values_here
[LAST_PROP_IDX
];
3174 /* Get properties here. */
3175 for (p
= it_props
; p
->handler
; ++p
)
3176 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3178 /* Look for an interval following iv that has different
3180 for (next_iv
= next_interval (iv
);
3181 (!NULL_INTERVAL_P (next_iv
)
3183 || XFASTINT (limit
) > next_iv
->position
));
3184 next_iv
= next_interval (next_iv
))
3186 for (p
= it_props
; p
->handler
; ++p
)
3188 Lisp_Object new_value
;
3190 new_value
= textget (next_iv
->plist
, *p
->name
);
3191 if (!EQ (values_here
[p
->idx
], new_value
))
3199 if (!NULL_INTERVAL_P (next_iv
))
3201 if (INTEGERP (limit
)
3202 && next_iv
->position
>= XFASTINT (limit
))
3203 /* No text property change up to limit. */
3204 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3206 /* Text properties change in next_iv. */
3207 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3211 xassert (STRINGP (it
->string
)
3212 || (it
->stop_charpos
>= BEGV
3213 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3217 /* Return the position of the next overlay change after POS in
3218 current_buffer. Value is point-max if no overlay change
3219 follows. This is like `next-overlay-change' but doesn't use
3223 next_overlay_change (pos
)
3228 Lisp_Object
*overlays
;
3231 /* Get all overlays at the given position. */
3232 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3234 /* If any of these overlays ends before endpos,
3235 use its ending point instead. */
3236 for (i
= 0; i
< noverlays
; ++i
)
3241 oend
= OVERLAY_END (overlays
[i
]);
3242 oendpos
= OVERLAY_POSITION (oend
);
3243 endpos
= min (endpos
, oendpos
);
3251 /***********************************************************************
3253 ***********************************************************************/
3255 /* Handle changes in the `fontified' property of the current buffer by
3256 calling hook functions from Qfontification_functions to fontify
3259 static enum prop_handled
3260 handle_fontified_prop (it
)
3263 Lisp_Object prop
, pos
;
3264 enum prop_handled handled
= HANDLED_NORMALLY
;
3266 if (!NILP (Vmemory_full
))
3269 /* Get the value of the `fontified' property at IT's current buffer
3270 position. (The `fontified' property doesn't have a special
3271 meaning in strings.) If the value is nil, call functions from
3272 Qfontification_functions. */
3273 if (!STRINGP (it
->string
)
3275 && !NILP (Vfontification_functions
)
3276 && !NILP (Vrun_hooks
)
3277 && (pos
= make_number (IT_CHARPOS (*it
)),
3278 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3279 /* Ignore the special cased nil value always present at EOB since
3280 no amount of fontifying will be able to change it. */
3281 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3283 int count
= SPECPDL_INDEX ();
3286 val
= Vfontification_functions
;
3287 specbind (Qfontification_functions
, Qnil
);
3289 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3290 safe_call1 (val
, pos
);
3293 Lisp_Object globals
, fn
;
3294 struct gcpro gcpro1
, gcpro2
;
3297 GCPRO2 (val
, globals
);
3299 for (; CONSP (val
); val
= XCDR (val
))
3305 /* A value of t indicates this hook has a local
3306 binding; it means to run the global binding too.
3307 In a global value, t should not occur. If it
3308 does, we must ignore it to avoid an endless
3310 for (globals
= Fdefault_value (Qfontification_functions
);
3312 globals
= XCDR (globals
))
3314 fn
= XCAR (globals
);
3316 safe_call1 (fn
, pos
);
3320 safe_call1 (fn
, pos
);
3326 unbind_to (count
, Qnil
);
3328 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3329 something. This avoids an endless loop if they failed to
3330 fontify the text for which reason ever. */
3331 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3332 handled
= HANDLED_RECOMPUTE_PROPS
;
3340 /***********************************************************************
3342 ***********************************************************************/
3344 /* Set up iterator IT from face properties at its current position.
3345 Called from handle_stop. */
3347 static enum prop_handled
3348 handle_face_prop (it
)
3352 EMACS_INT next_stop
;
3354 if (!STRINGP (it
->string
))
3357 = face_at_buffer_position (it
->w
,
3359 it
->region_beg_charpos
,
3360 it
->region_end_charpos
,
3363 + TEXT_PROP_DISTANCE_LIMIT
),
3366 /* Is this a start of a run of characters with box face?
3367 Caveat: this can be called for a freshly initialized
3368 iterator; face_id is -1 in this case. We know that the new
3369 face will not change until limit, i.e. if the new face has a
3370 box, all characters up to limit will have one. But, as
3371 usual, we don't know whether limit is really the end. */
3372 if (new_face_id
!= it
->face_id
)
3374 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3376 /* If new face has a box but old face has not, this is
3377 the start of a run of characters with box, i.e. it has
3378 a shadow on the left side. The value of face_id of the
3379 iterator will be -1 if this is the initial call that gets
3380 the face. In this case, we have to look in front of IT's
3381 position and see whether there is a face != new_face_id. */
3382 it
->start_of_box_run_p
3383 = (new_face
->box
!= FACE_NO_BOX
3384 && (it
->face_id
>= 0
3385 || IT_CHARPOS (*it
) == BEG
3386 || new_face_id
!= face_before_it_pos (it
)));
3387 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3392 int base_face_id
, bufpos
;
3394 Lisp_Object from_overlay
3395 = (it
->current
.overlay_string_index
>= 0
3396 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3399 /* See if we got to this string directly or indirectly from
3400 an overlay property. That includes the before-string or
3401 after-string of an overlay, strings in display properties
3402 provided by an overlay, their text properties, etc.
3404 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3405 if (! NILP (from_overlay
))
3406 for (i
= it
->sp
- 1; i
>= 0; i
--)
3408 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3410 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3411 else if (! NILP (it
->stack
[i
].from_overlay
))
3412 from_overlay
= it
->stack
[i
].from_overlay
;
3414 if (!NILP (from_overlay
))
3418 if (! NILP (from_overlay
))
3420 bufpos
= IT_CHARPOS (*it
);
3421 /* For a string from an overlay, the base face depends
3422 only on text properties and ignores overlays. */
3424 = face_for_overlay_string (it
->w
,
3426 it
->region_beg_charpos
,
3427 it
->region_end_charpos
,
3430 + TEXT_PROP_DISTANCE_LIMIT
),
3438 /* For strings from a `display' property, use the face at
3439 IT's current buffer position as the base face to merge
3440 with, so that overlay strings appear in the same face as
3441 surrounding text, unless they specify their own
3443 base_face_id
= underlying_face_id (it
);
3446 new_face_id
= face_at_string_position (it
->w
,
3448 IT_STRING_CHARPOS (*it
),
3450 it
->region_beg_charpos
,
3451 it
->region_end_charpos
,
3455 #if 0 /* This shouldn't be neccessary. Let's check it. */
3456 /* If IT is used to display a mode line we would really like to
3457 use the mode line face instead of the frame's default face. */
3458 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3459 && new_face_id
== DEFAULT_FACE_ID
)
3460 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3463 /* Is this a start of a run of characters with box? Caveat:
3464 this can be called for a freshly allocated iterator; face_id
3465 is -1 is this case. We know that the new face will not
3466 change until the next check pos, i.e. if the new face has a
3467 box, all characters up to that position will have a
3468 box. But, as usual, we don't know whether that position
3469 is really the end. */
3470 if (new_face_id
!= it
->face_id
)
3472 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3473 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3475 /* If new face has a box but old face hasn't, this is the
3476 start of a run of characters with box, i.e. it has a
3477 shadow on the left side. */
3478 it
->start_of_box_run_p
3479 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3480 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3484 it
->face_id
= new_face_id
;
3485 return HANDLED_NORMALLY
;
3489 /* Return the ID of the face ``underlying'' IT's current position,
3490 which is in a string. If the iterator is associated with a
3491 buffer, return the face at IT's current buffer position.
3492 Otherwise, use the iterator's base_face_id. */
3495 underlying_face_id (it
)
3498 int face_id
= it
->base_face_id
, i
;
3500 xassert (STRINGP (it
->string
));
3502 for (i
= it
->sp
- 1; i
>= 0; --i
)
3503 if (NILP (it
->stack
[i
].string
))
3504 face_id
= it
->stack
[i
].face_id
;
3510 /* Compute the face one character before or after the current position
3511 of IT. BEFORE_P non-zero means get the face in front of IT's
3512 position. Value is the id of the face. */
3515 face_before_or_after_it_pos (it
, before_p
)
3520 EMACS_INT next_check_charpos
;
3521 struct text_pos pos
;
3523 xassert (it
->s
== NULL
);
3525 if (STRINGP (it
->string
))
3527 int bufpos
, base_face_id
;
3529 /* No face change past the end of the string (for the case
3530 we are padding with spaces). No face change before the
3532 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3533 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3536 /* Set pos to the position before or after IT's current position. */
3538 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3540 /* For composition, we must check the character after the
3542 pos
= (it
->what
== IT_COMPOSITION
3543 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3544 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3546 if (it
->current
.overlay_string_index
>= 0)
3547 bufpos
= IT_CHARPOS (*it
);
3551 base_face_id
= underlying_face_id (it
);
3553 /* Get the face for ASCII, or unibyte. */
3554 face_id
= face_at_string_position (it
->w
,
3558 it
->region_beg_charpos
,
3559 it
->region_end_charpos
,
3560 &next_check_charpos
,
3563 /* Correct the face for charsets different from ASCII. Do it
3564 for the multibyte case only. The face returned above is
3565 suitable for unibyte text if IT->string is unibyte. */
3566 if (STRING_MULTIBYTE (it
->string
))
3568 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3569 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3571 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3573 c
= string_char_and_length (p
, rest
, &len
);
3574 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3579 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3580 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3583 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3584 pos
= it
->current
.pos
;
3587 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3590 if (it
->what
== IT_COMPOSITION
)
3591 /* For composition, we must check the position after the
3593 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3595 INC_TEXT_POS (pos
, it
->multibyte_p
);
3598 /* Determine face for CHARSET_ASCII, or unibyte. */
3599 face_id
= face_at_buffer_position (it
->w
,
3601 it
->region_beg_charpos
,
3602 it
->region_end_charpos
,
3603 &next_check_charpos
,
3606 /* Correct the face for charsets different from ASCII. Do it
3607 for the multibyte case only. The face returned above is
3608 suitable for unibyte text if current_buffer is unibyte. */
3609 if (it
->multibyte_p
)
3611 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3612 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3613 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3622 /***********************************************************************
3624 ***********************************************************************/
3626 /* Set up iterator IT from invisible properties at its current
3627 position. Called from handle_stop. */
3629 static enum prop_handled
3630 handle_invisible_prop (it
)
3633 enum prop_handled handled
= HANDLED_NORMALLY
;
3635 if (STRINGP (it
->string
))
3637 extern Lisp_Object Qinvisible
;
3638 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3640 /* Get the value of the invisible text property at the
3641 current position. Value will be nil if there is no such
3643 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3644 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3647 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3649 handled
= HANDLED_RECOMPUTE_PROPS
;
3651 /* Get the position at which the next change of the
3652 invisible text property can be found in IT->string.
3653 Value will be nil if the property value is the same for
3654 all the rest of IT->string. */
3655 XSETINT (limit
, SCHARS (it
->string
));
3656 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3659 /* Text at current position is invisible. The next
3660 change in the property is at position end_charpos.
3661 Move IT's current position to that position. */
3662 if (INTEGERP (end_charpos
)
3663 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3665 struct text_pos old
;
3666 old
= it
->current
.string_pos
;
3667 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3668 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3672 /* The rest of the string is invisible. If this is an
3673 overlay string, proceed with the next overlay string
3674 or whatever comes and return a character from there. */
3675 if (it
->current
.overlay_string_index
>= 0)
3677 next_overlay_string (it
);
3678 /* Don't check for overlay strings when we just
3679 finished processing them. */
3680 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3684 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3685 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3693 EMACS_INT newpos
, next_stop
, start_charpos
;
3694 Lisp_Object pos
, prop
, overlay
;
3696 /* First of all, is there invisible text at this position? */
3697 start_charpos
= IT_CHARPOS (*it
);
3698 pos
= make_number (IT_CHARPOS (*it
));
3699 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3701 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3703 /* If we are on invisible text, skip over it. */
3704 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3706 /* Record whether we have to display an ellipsis for the
3708 int display_ellipsis_p
= invis_p
== 2;
3710 handled
= HANDLED_RECOMPUTE_PROPS
;
3712 /* Loop skipping over invisible text. The loop is left at
3713 ZV or with IT on the first char being visible again. */
3716 /* Try to skip some invisible text. Return value is the
3717 position reached which can be equal to IT's position
3718 if there is nothing invisible here. This skips both
3719 over invisible text properties and overlays with
3720 invisible property. */
3721 newpos
= skip_invisible (IT_CHARPOS (*it
),
3722 &next_stop
, ZV
, it
->window
);
3724 /* If we skipped nothing at all we weren't at invisible
3725 text in the first place. If everything to the end of
3726 the buffer was skipped, end the loop. */
3727 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3731 /* We skipped some characters but not necessarily
3732 all there are. Check if we ended up on visible
3733 text. Fget_char_property returns the property of
3734 the char before the given position, i.e. if we
3735 get invis_p = 0, this means that the char at
3736 newpos is visible. */
3737 pos
= make_number (newpos
);
3738 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3739 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3742 /* If we ended up on invisible text, proceed to
3743 skip starting with next_stop. */
3745 IT_CHARPOS (*it
) = next_stop
;
3747 /* If there are adjacent invisible texts, don't lose the
3748 second one's ellipsis. */
3750 display_ellipsis_p
= 1;
3754 /* The position newpos is now either ZV or on visible text. */
3755 IT_CHARPOS (*it
) = newpos
;
3756 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3758 /* If there are before-strings at the start of invisible
3759 text, and the text is invisible because of a text
3760 property, arrange to show before-strings because 20.x did
3761 it that way. (If the text is invisible because of an
3762 overlay property instead of a text property, this is
3763 already handled in the overlay code.) */
3765 && get_overlay_strings (it
, start_charpos
))
3767 handled
= HANDLED_RECOMPUTE_PROPS
;
3768 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3770 else if (display_ellipsis_p
)
3772 /* Make sure that the glyphs of the ellipsis will get
3773 correct `charpos' values. If we would not update
3774 it->position here, the glyphs would belong to the
3775 last visible character _before_ the invisible
3776 text, which confuses `set_cursor_from_row'.
3778 We use the last invisible position instead of the
3779 first because this way the cursor is always drawn on
3780 the first "." of the ellipsis, whenever PT is inside
3781 the invisible text. Otherwise the cursor would be
3782 placed _after_ the ellipsis when the point is after the
3783 first invisible character. */
3784 if (!STRINGP (it
->object
))
3786 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3787 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3789 setup_for_ellipsis (it
, 0);
3790 /* Let the ellipsis display before
3791 considering any properties of the following char.
3792 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3793 handled
= HANDLED_RETURN
;
3802 /* Make iterator IT return `...' next.
3803 Replaces LEN characters from buffer. */
3806 setup_for_ellipsis (it
, len
)
3810 /* Use the display table definition for `...'. Invalid glyphs
3811 will be handled by the method returning elements from dpvec. */
3812 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3814 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3815 it
->dpvec
= v
->contents
;
3816 it
->dpend
= v
->contents
+ v
->size
;
3820 /* Default `...'. */
3821 it
->dpvec
= default_invis_vector
;
3822 it
->dpend
= default_invis_vector
+ 3;
3825 it
->dpvec_char_len
= len
;
3826 it
->current
.dpvec_index
= 0;
3827 it
->dpvec_face_id
= -1;
3829 /* Remember the current face id in case glyphs specify faces.
3830 IT's face is restored in set_iterator_to_next.
3831 saved_face_id was set to preceding char's face in handle_stop. */
3832 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3833 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3835 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3841 /***********************************************************************
3843 ***********************************************************************/
3845 /* Set up iterator IT from `display' property at its current position.
3846 Called from handle_stop.
3847 We return HANDLED_RETURN if some part of the display property
3848 overrides the display of the buffer text itself.
3849 Otherwise we return HANDLED_NORMALLY. */
3851 static enum prop_handled
3852 handle_display_prop (it
)
3855 Lisp_Object prop
, object
, overlay
;
3856 struct text_pos
*position
;
3857 /* Nonzero if some property replaces the display of the text itself. */
3858 int display_replaced_p
= 0;
3860 if (STRINGP (it
->string
))
3862 object
= it
->string
;
3863 position
= &it
->current
.string_pos
;
3867 XSETWINDOW (object
, it
->w
);
3868 position
= &it
->current
.pos
;
3871 /* Reset those iterator values set from display property values. */
3872 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3873 it
->space_width
= Qnil
;
3874 it
->font_height
= Qnil
;
3877 /* We don't support recursive `display' properties, i.e. string
3878 values that have a string `display' property, that have a string
3879 `display' property etc. */
3880 if (!it
->string_from_display_prop_p
)
3881 it
->area
= TEXT_AREA
;
3883 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3884 Qdisplay
, object
, &overlay
);
3886 return HANDLED_NORMALLY
;
3887 /* Now OVERLAY is the overlay that gave us this property, or nil
3888 if it was a text property. */
3890 if (!STRINGP (it
->string
))
3891 object
= it
->w
->buffer
;
3894 /* Simple properties. */
3895 && !EQ (XCAR (prop
), Qimage
)
3896 && !EQ (XCAR (prop
), Qspace
)
3897 && !EQ (XCAR (prop
), Qwhen
)
3898 && !EQ (XCAR (prop
), Qslice
)
3899 && !EQ (XCAR (prop
), Qspace_width
)
3900 && !EQ (XCAR (prop
), Qheight
)
3901 && !EQ (XCAR (prop
), Qraise
)
3902 /* Marginal area specifications. */
3903 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3904 && !EQ (XCAR (prop
), Qleft_fringe
)
3905 && !EQ (XCAR (prop
), Qright_fringe
)
3906 && !NILP (XCAR (prop
)))
3908 for (; CONSP (prop
); prop
= XCDR (prop
))
3910 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3911 position
, display_replaced_p
))
3913 display_replaced_p
= 1;
3914 /* If some text in a string is replaced, `position' no
3915 longer points to the position of `object'. */
3916 if (STRINGP (object
))
3921 else if (VECTORP (prop
))
3924 for (i
= 0; i
< ASIZE (prop
); ++i
)
3925 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3926 position
, display_replaced_p
))
3928 display_replaced_p
= 1;
3929 /* If some text in a string is replaced, `position' no
3930 longer points to the position of `object'. */
3931 if (STRINGP (object
))
3937 int ret
= handle_single_display_spec (it
, prop
, object
, overlay
,
3939 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3940 return HANDLED_RECOMPUTE_PROPS
;
3942 display_replaced_p
= 1;
3945 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3949 /* Value is the position of the end of the `display' property starting
3950 at START_POS in OBJECT. */
3952 static struct text_pos
3953 display_prop_end (it
, object
, start_pos
)
3956 struct text_pos start_pos
;
3959 struct text_pos end_pos
;
3961 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3962 Qdisplay
, object
, Qnil
);
3963 CHARPOS (end_pos
) = XFASTINT (end
);
3964 if (STRINGP (object
))
3965 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3967 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3973 /* Set up IT from a single `display' specification PROP. OBJECT
3974 is the object in which the `display' property was found. *POSITION
3975 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3976 means that we previously saw a display specification which already
3977 replaced text display with something else, for example an image;
3978 we ignore such properties after the first one has been processed.
3980 OVERLAY is the overlay this `display' property came from,
3981 or nil if it was a text property.
3983 If PROP is a `space' or `image' specification, and in some other
3984 cases too, set *POSITION to the position where the `display'
3987 Value is non-zero if something was found which replaces the display
3988 of buffer or string text. Specifically, the value is -1 if that
3989 "something" is "nothing". */
3992 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
3993 display_replaced_before_p
)
3997 Lisp_Object overlay
;
3998 struct text_pos
*position
;
3999 int display_replaced_before_p
;
4002 Lisp_Object location
, value
;
4003 struct text_pos start_pos
, save_pos
;
4006 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4007 If the result is non-nil, use VALUE instead of SPEC. */
4009 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4018 if (!NILP (form
) && !EQ (form
, Qt
))
4020 int count
= SPECPDL_INDEX ();
4021 struct gcpro gcpro1
;
4023 /* Bind `object' to the object having the `display' property, a
4024 buffer or string. Bind `position' to the position in the
4025 object where the property was found, and `buffer-position'
4026 to the current position in the buffer. */
4027 specbind (Qobject
, object
);
4028 specbind (Qposition
, make_number (CHARPOS (*position
)));
4029 specbind (Qbuffer_position
,
4030 make_number (STRINGP (object
)
4031 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4033 form
= safe_eval (form
);
4035 unbind_to (count
, Qnil
);
4041 /* Handle `(height HEIGHT)' specifications. */
4043 && EQ (XCAR (spec
), Qheight
)
4044 && CONSP (XCDR (spec
)))
4046 if (!FRAME_WINDOW_P (it
->f
))
4049 it
->font_height
= XCAR (XCDR (spec
));
4050 if (!NILP (it
->font_height
))
4052 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4053 int new_height
= -1;
4055 if (CONSP (it
->font_height
)
4056 && (EQ (XCAR (it
->font_height
), Qplus
)
4057 || EQ (XCAR (it
->font_height
), Qminus
))
4058 && CONSP (XCDR (it
->font_height
))
4059 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4061 /* `(+ N)' or `(- N)' where N is an integer. */
4062 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4063 if (EQ (XCAR (it
->font_height
), Qplus
))
4065 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4067 else if (FUNCTIONP (it
->font_height
))
4069 /* Call function with current height as argument.
4070 Value is the new height. */
4072 height
= safe_call1 (it
->font_height
,
4073 face
->lface
[LFACE_HEIGHT_INDEX
]);
4074 if (NUMBERP (height
))
4075 new_height
= XFLOATINT (height
);
4077 else if (NUMBERP (it
->font_height
))
4079 /* Value is a multiple of the canonical char height. */
4082 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
4083 new_height
= (XFLOATINT (it
->font_height
)
4084 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4088 /* Evaluate IT->font_height with `height' bound to the
4089 current specified height to get the new height. */
4090 int count
= SPECPDL_INDEX ();
4092 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4093 value
= safe_eval (it
->font_height
);
4094 unbind_to (count
, Qnil
);
4096 if (NUMBERP (value
))
4097 new_height
= XFLOATINT (value
);
4101 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4107 /* Handle `(space-width WIDTH)'. */
4109 && EQ (XCAR (spec
), Qspace_width
)
4110 && CONSP (XCDR (spec
)))
4112 if (!FRAME_WINDOW_P (it
->f
))
4115 value
= XCAR (XCDR (spec
));
4116 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4117 it
->space_width
= value
;
4122 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4124 && EQ (XCAR (spec
), Qslice
))
4128 if (!FRAME_WINDOW_P (it
->f
))
4131 if (tem
= XCDR (spec
), CONSP (tem
))
4133 it
->slice
.x
= XCAR (tem
);
4134 if (tem
= XCDR (tem
), CONSP (tem
))
4136 it
->slice
.y
= XCAR (tem
);
4137 if (tem
= XCDR (tem
), CONSP (tem
))
4139 it
->slice
.width
= XCAR (tem
);
4140 if (tem
= XCDR (tem
), CONSP (tem
))
4141 it
->slice
.height
= XCAR (tem
);
4149 /* Handle `(raise FACTOR)'. */
4151 && EQ (XCAR (spec
), Qraise
)
4152 && CONSP (XCDR (spec
)))
4154 if (!FRAME_WINDOW_P (it
->f
))
4157 #ifdef HAVE_WINDOW_SYSTEM
4158 value
= XCAR (XCDR (spec
));
4159 if (NUMBERP (value
))
4161 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4162 it
->voffset
= - (XFLOATINT (value
)
4163 * (FONT_HEIGHT (face
->font
)));
4165 #endif /* HAVE_WINDOW_SYSTEM */
4170 /* Don't handle the other kinds of display specifications
4171 inside a string that we got from a `display' property. */
4172 if (it
->string_from_display_prop_p
)
4175 /* Characters having this form of property are not displayed, so
4176 we have to find the end of the property. */
4177 start_pos
= *position
;
4178 *position
= display_prop_end (it
, object
, start_pos
);
4181 /* Stop the scan at that end position--we assume that all
4182 text properties change there. */
4183 it
->stop_charpos
= position
->charpos
;
4185 /* Handle `(left-fringe BITMAP [FACE])'
4186 and `(right-fringe BITMAP [FACE])'. */
4188 && (EQ (XCAR (spec
), Qleft_fringe
)
4189 || EQ (XCAR (spec
), Qright_fringe
))
4190 && CONSP (XCDR (spec
)))
4192 int face_id
= DEFAULT_FACE_ID
;
4195 if (!FRAME_WINDOW_P (it
->f
))
4196 /* If we return here, POSITION has been advanced
4197 across the text with this property. */
4200 #ifdef HAVE_WINDOW_SYSTEM
4201 value
= XCAR (XCDR (spec
));
4202 if (!SYMBOLP (value
)
4203 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4204 /* If we return here, POSITION has been advanced
4205 across the text with this property. */
4208 if (CONSP (XCDR (XCDR (spec
))))
4210 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4211 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4217 /* Save current settings of IT so that we can restore them
4218 when we are finished with the glyph property value. */
4220 save_pos
= it
->position
;
4221 it
->position
= *position
;
4223 it
->position
= save_pos
;
4225 it
->area
= TEXT_AREA
;
4226 it
->what
= IT_IMAGE
;
4227 it
->image_id
= -1; /* no image */
4228 it
->position
= start_pos
;
4229 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4230 it
->method
= GET_FROM_IMAGE
;
4231 it
->from_overlay
= Qnil
;
4232 it
->face_id
= face_id
;
4234 /* Say that we haven't consumed the characters with
4235 `display' property yet. The call to pop_it in
4236 set_iterator_to_next will clean this up. */
4237 *position
= start_pos
;
4239 if (EQ (XCAR (spec
), Qleft_fringe
))
4241 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4242 it
->left_user_fringe_face_id
= face_id
;
4246 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4247 it
->right_user_fringe_face_id
= face_id
;
4249 #endif /* HAVE_WINDOW_SYSTEM */
4253 /* Prepare to handle `((margin left-margin) ...)',
4254 `((margin right-margin) ...)' and `((margin nil) ...)'
4255 prefixes for display specifications. */
4256 location
= Qunbound
;
4257 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4261 value
= XCDR (spec
);
4263 value
= XCAR (value
);
4266 if (EQ (XCAR (tem
), Qmargin
)
4267 && (tem
= XCDR (tem
),
4268 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4270 || EQ (tem
, Qleft_margin
)
4271 || EQ (tem
, Qright_margin
))))
4275 if (EQ (location
, Qunbound
))
4281 /* After this point, VALUE is the property after any
4282 margin prefix has been stripped. It must be a string,
4283 an image specification, or `(space ...)'.
4285 LOCATION specifies where to display: `left-margin',
4286 `right-margin' or nil. */
4288 valid_p
= (STRINGP (value
)
4289 #ifdef HAVE_WINDOW_SYSTEM
4290 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4291 #endif /* not HAVE_WINDOW_SYSTEM */
4292 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4294 if (valid_p
&& !display_replaced_before_p
)
4296 /* Save current settings of IT so that we can restore them
4297 when we are finished with the glyph property value. */
4298 save_pos
= it
->position
;
4299 it
->position
= *position
;
4301 it
->position
= save_pos
;
4302 it
->from_overlay
= overlay
;
4304 if (NILP (location
))
4305 it
->area
= TEXT_AREA
;
4306 else if (EQ (location
, Qleft_margin
))
4307 it
->area
= LEFT_MARGIN_AREA
;
4309 it
->area
= RIGHT_MARGIN_AREA
;
4311 if (STRINGP (value
))
4313 if (SCHARS (value
) == 0)
4316 return -1; /* Replaced by "", i.e. nothing. */
4319 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4320 it
->current
.overlay_string_index
= -1;
4321 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4322 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4323 it
->method
= GET_FROM_STRING
;
4324 it
->stop_charpos
= 0;
4325 it
->string_from_display_prop_p
= 1;
4326 /* Say that we haven't consumed the characters with
4327 `display' property yet. The call to pop_it in
4328 set_iterator_to_next will clean this up. */
4329 if (BUFFERP (object
))
4330 *position
= start_pos
;
4332 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4334 it
->method
= GET_FROM_STRETCH
;
4336 *position
= it
->position
= start_pos
;
4338 #ifdef HAVE_WINDOW_SYSTEM
4341 it
->what
= IT_IMAGE
;
4342 it
->image_id
= lookup_image (it
->f
, value
);
4343 it
->position
= start_pos
;
4344 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4345 it
->method
= GET_FROM_IMAGE
;
4347 /* Say that we haven't consumed the characters with
4348 `display' property yet. The call to pop_it in
4349 set_iterator_to_next will clean this up. */
4350 *position
= start_pos
;
4352 #endif /* HAVE_WINDOW_SYSTEM */
4357 /* Invalid property or property not supported. Restore
4358 POSITION to what it was before. */
4359 *position
= start_pos
;
4364 /* Check if SPEC is a display sub-property value whose text should be
4365 treated as intangible. */
4368 single_display_spec_intangible_p (prop
)
4371 /* Skip over `when FORM'. */
4372 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4386 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4387 we don't need to treat text as intangible. */
4388 if (EQ (XCAR (prop
), Qmargin
))
4396 || EQ (XCAR (prop
), Qleft_margin
)
4397 || EQ (XCAR (prop
), Qright_margin
))
4401 return (CONSP (prop
)
4402 && (EQ (XCAR (prop
), Qimage
)
4403 || EQ (XCAR (prop
), Qspace
)));
4407 /* Check if PROP is a display property value whose text should be
4408 treated as intangible. */
4411 display_prop_intangible_p (prop
)
4415 && CONSP (XCAR (prop
))
4416 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4418 /* A list of sub-properties. */
4419 while (CONSP (prop
))
4421 if (single_display_spec_intangible_p (XCAR (prop
)))
4426 else if (VECTORP (prop
))
4428 /* A vector of sub-properties. */
4430 for (i
= 0; i
< ASIZE (prop
); ++i
)
4431 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4435 return single_display_spec_intangible_p (prop
);
4441 /* Return 1 if PROP is a display sub-property value containing STRING. */
4444 single_display_spec_string_p (prop
, string
)
4445 Lisp_Object prop
, string
;
4447 if (EQ (string
, prop
))
4450 /* Skip over `when FORM'. */
4451 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4460 /* Skip over `margin LOCATION'. */
4461 if (EQ (XCAR (prop
), Qmargin
))
4472 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4476 /* Return 1 if STRING appears in the `display' property PROP. */
4479 display_prop_string_p (prop
, string
)
4480 Lisp_Object prop
, string
;
4483 && CONSP (XCAR (prop
))
4484 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4486 /* A list of sub-properties. */
4487 while (CONSP (prop
))
4489 if (single_display_spec_string_p (XCAR (prop
), string
))
4494 else if (VECTORP (prop
))
4496 /* A vector of sub-properties. */
4498 for (i
= 0; i
< ASIZE (prop
); ++i
)
4499 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4503 return single_display_spec_string_p (prop
, string
);
4509 /* Determine from which buffer position in W's buffer STRING comes
4510 from. AROUND_CHARPOS is an approximate position where it could
4511 be from. Value is the buffer position or 0 if it couldn't be
4514 W's buffer must be current.
4516 This function is necessary because we don't record buffer positions
4517 in glyphs generated from strings (to keep struct glyph small).
4518 This function may only use code that doesn't eval because it is
4519 called asynchronously from note_mouse_highlight. */
4522 string_buffer_position (w
, string
, around_charpos
)
4527 Lisp_Object limit
, prop
, pos
;
4528 const int MAX_DISTANCE
= 1000;
4531 pos
= make_number (around_charpos
);
4532 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4533 while (!found
&& !EQ (pos
, limit
))
4535 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4536 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4539 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4544 pos
= make_number (around_charpos
);
4545 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4546 while (!found
&& !EQ (pos
, limit
))
4548 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4549 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4552 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4557 return found
? XINT (pos
) : 0;
4562 /***********************************************************************
4563 `composition' property
4564 ***********************************************************************/
4566 static enum prop_handled
4567 handle_auto_composed_prop (it
)
4570 enum prop_handled handled
= HANDLED_NORMALLY
;
4572 if (FRAME_WINDOW_P (it
->f
) && FUNCTIONP (Vauto_composition_function
))
4574 Lisp_Object val
= Qnil
;
4575 EMACS_INT pos
, limit
= -1;
4577 if (STRINGP (it
->string
))
4578 pos
= IT_STRING_CHARPOS (*it
);
4580 pos
= IT_CHARPOS (*it
);
4582 val
= Fget_text_property (make_number (pos
), Qauto_composed
, it
->string
);
4585 Lisp_Object cmp_prop
;
4586 EMACS_INT cmp_start
, cmp_end
;
4588 if (get_property_and_range (pos
, Qcomposition
, &cmp_prop
,
4589 &cmp_start
, &cmp_end
, it
->string
)
4591 && COMPOSITION_METHOD (cmp_prop
) == COMPOSITION_WITH_GLYPH_STRING
)
4593 Lisp_Object gstring
= COMPOSITION_COMPONENTS (cmp_prop
);
4594 Lisp_Object font_object
= LGSTRING_FONT (gstring
);
4596 if (! EQ (font_object
,
4597 font_at (-1, pos
, FACE_FROM_ID (it
->f
, it
->face_id
),
4598 it
->w
, it
->string
)))
4599 /* We must re-compute the composition for the
4608 /* As Fnext_single_char_property_change is very slow, we
4609 limit the search to the current line. */
4610 if (STRINGP (it
->string
))
4611 limit
= SCHARS (it
->string
);
4613 limit
= find_next_newline_no_quit (pos
, 1);
4614 end
= Fnext_single_char_property_change (make_number (pos
),
4617 make_number (limit
));
4619 if (XINT (end
) < limit
)
4620 /* The current point is auto-composed, but there exist
4621 characters not yet composed beyond the
4622 auto-composed region. There's a possiblity that
4623 the last characters in the region may be newly
4628 if (NILP (val
) && ! STRINGP (it
->string
))
4631 limit
= (STRINGP (it
->string
) ? SCHARS (it
->string
)
4632 : find_next_newline_no_quit (pos
, 1));
4635 int count
= SPECPDL_INDEX ();
4636 Lisp_Object args
[5];
4638 limit
= font_range (pos
, limit
, FACE_FROM_ID (it
->f
, it
->face_id
),
4640 args
[0] = Vauto_composition_function
;
4641 specbind (Qauto_composition_function
, Qnil
);
4642 args
[1] = make_number (pos
);
4643 args
[2] = make_number (limit
);
4644 args
[3] = it
->window
;
4645 args
[4] = it
->string
;
4646 safe_call (5, args
);
4647 unbind_to (count
, Qnil
);
4655 /* Set up iterator IT from `composition' property at its current
4656 position. Called from handle_stop. */
4658 static enum prop_handled
4659 handle_composition_prop (it
)
4662 Lisp_Object prop
, string
;
4663 EMACS_INT pos
, pos_byte
, start
, end
;
4664 enum prop_handled handled
= HANDLED_NORMALLY
;
4666 if (STRINGP (it
->string
))
4670 pos
= IT_STRING_CHARPOS (*it
);
4671 pos_byte
= IT_STRING_BYTEPOS (*it
);
4672 string
= it
->string
;
4673 s
= SDATA (string
) + pos_byte
;
4674 it
->c
= STRING_CHAR (s
, 0);
4678 pos
= IT_CHARPOS (*it
);
4679 pos_byte
= IT_BYTEPOS (*it
);
4681 it
->c
= FETCH_CHAR (pos_byte
);
4684 /* If there's a valid composition and point is not inside of the
4685 composition (in the case that the composition is from the current
4686 buffer), draw a glyph composed from the composition components. */
4687 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4688 && COMPOSITION_VALID_P (start
, end
, prop
)
4689 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4695 if (STRINGP (it
->string
))
4696 pos_byte
= string_char_to_byte (it
->string
, start
);
4698 pos_byte
= CHAR_TO_BYTE (start
);
4700 id
= get_composition_id (start
, pos_byte
, end
- start
, prop
, string
);
4704 struct composition
*cmp
= composition_table
[id
];
4706 if (cmp
->glyph_len
== 0)
4709 if (STRINGP (it
->string
))
4711 IT_STRING_CHARPOS (*it
) = end
;
4712 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4717 IT_CHARPOS (*it
) = end
;
4718 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4720 return HANDLED_RECOMPUTE_PROPS
;
4723 it
->stop_charpos
= end
;
4726 it
->method
= GET_FROM_COMPOSITION
;
4728 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4729 /* For a terminal, draw only the first (non-TAB) character
4730 of the components. */
4731 if (composition_table
[id
]->method
== COMPOSITION_WITH_GLYPH_STRING
)
4733 /* FIXME: This doesn't do anything!?! */
4734 Lisp_Object lgstring
= AREF (XHASH_TABLE (composition_hash_table
)
4736 cmp
->hash_index
* 2);
4742 for (i
= 0; i
< cmp
->glyph_len
; i
++)
4743 if ((it
->c
= COMPOSITION_GLYPH (composition_table
[id
], i
))
4749 it
->len
= (STRINGP (it
->string
)
4750 ? string_char_to_byte (it
->string
, end
)
4751 : CHAR_TO_BYTE (end
)) - pos_byte
;
4752 handled
= HANDLED_RETURN
;
4761 /***********************************************************************
4763 ***********************************************************************/
4765 /* The following structure is used to record overlay strings for
4766 later sorting in load_overlay_strings. */
4768 struct overlay_entry
4770 Lisp_Object overlay
;
4777 /* Set up iterator IT from overlay strings at its current position.
4778 Called from handle_stop. */
4780 static enum prop_handled
4781 handle_overlay_change (it
)
4784 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4785 return HANDLED_RECOMPUTE_PROPS
;
4787 return HANDLED_NORMALLY
;
4791 /* Set up the next overlay string for delivery by IT, if there is an
4792 overlay string to deliver. Called by set_iterator_to_next when the
4793 end of the current overlay string is reached. If there are more
4794 overlay strings to display, IT->string and
4795 IT->current.overlay_string_index are set appropriately here.
4796 Otherwise IT->string is set to nil. */
4799 next_overlay_string (it
)
4802 ++it
->current
.overlay_string_index
;
4803 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4805 /* No more overlay strings. Restore IT's settings to what
4806 they were before overlay strings were processed, and
4807 continue to deliver from current_buffer. */
4808 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4812 || it
->method
== GET_FROM_COMPOSITION
4813 || (NILP (it
->string
)
4814 && it
->method
== GET_FROM_BUFFER
4815 && it
->stop_charpos
>= BEGV
4816 && it
->stop_charpos
<= it
->end_charpos
));
4817 it
->current
.overlay_string_index
= -1;
4818 it
->n_overlay_strings
= 0;
4820 /* If we're at the end of the buffer, record that we have
4821 processed the overlay strings there already, so that
4822 next_element_from_buffer doesn't try it again. */
4823 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4824 it
->overlay_strings_at_end_processed_p
= 1;
4826 /* If we have to display `...' for invisible text, set
4827 the iterator up for that. */
4828 if (display_ellipsis_p
)
4829 setup_for_ellipsis (it
, 0);
4833 /* There are more overlay strings to process. If
4834 IT->current.overlay_string_index has advanced to a position
4835 where we must load IT->overlay_strings with more strings, do
4837 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4839 if (it
->current
.overlay_string_index
&& i
== 0)
4840 load_overlay_strings (it
, 0);
4842 /* Initialize IT to deliver display elements from the overlay
4844 it
->string
= it
->overlay_strings
[i
];
4845 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4846 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4847 it
->method
= GET_FROM_STRING
;
4848 it
->stop_charpos
= 0;
4855 /* Compare two overlay_entry structures E1 and E2. Used as a
4856 comparison function for qsort in load_overlay_strings. Overlay
4857 strings for the same position are sorted so that
4859 1. All after-strings come in front of before-strings, except
4860 when they come from the same overlay.
4862 2. Within after-strings, strings are sorted so that overlay strings
4863 from overlays with higher priorities come first.
4865 2. Within before-strings, strings are sorted so that overlay
4866 strings from overlays with higher priorities come last.
4868 Value is analogous to strcmp. */
4872 compare_overlay_entries (e1
, e2
)
4875 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4876 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4879 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4881 /* Let after-strings appear in front of before-strings if
4882 they come from different overlays. */
4883 if (EQ (entry1
->overlay
, entry2
->overlay
))
4884 result
= entry1
->after_string_p
? 1 : -1;
4886 result
= entry1
->after_string_p
? -1 : 1;
4888 else if (entry1
->after_string_p
)
4889 /* After-strings sorted in order of decreasing priority. */
4890 result
= entry2
->priority
- entry1
->priority
;
4892 /* Before-strings sorted in order of increasing priority. */
4893 result
= entry1
->priority
- entry2
->priority
;
4899 /* Load the vector IT->overlay_strings with overlay strings from IT's
4900 current buffer position, or from CHARPOS if that is > 0. Set
4901 IT->n_overlays to the total number of overlay strings found.
4903 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4904 a time. On entry into load_overlay_strings,
4905 IT->current.overlay_string_index gives the number of overlay
4906 strings that have already been loaded by previous calls to this
4909 IT->add_overlay_start contains an additional overlay start
4910 position to consider for taking overlay strings from, if non-zero.
4911 This position comes into play when the overlay has an `invisible'
4912 property, and both before and after-strings. When we've skipped to
4913 the end of the overlay, because of its `invisible' property, we
4914 nevertheless want its before-string to appear.
4915 IT->add_overlay_start will contain the overlay start position
4918 Overlay strings are sorted so that after-string strings come in
4919 front of before-string strings. Within before and after-strings,
4920 strings are sorted by overlay priority. See also function
4921 compare_overlay_entries. */
4924 load_overlay_strings (it
, charpos
)
4928 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4929 Lisp_Object overlay
, window
, str
, invisible
;
4930 struct Lisp_Overlay
*ov
;
4933 int n
= 0, i
, j
, invis_p
;
4934 struct overlay_entry
*entries
4935 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4938 charpos
= IT_CHARPOS (*it
);
4940 /* Append the overlay string STRING of overlay OVERLAY to vector
4941 `entries' which has size `size' and currently contains `n'
4942 elements. AFTER_P non-zero means STRING is an after-string of
4944 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4947 Lisp_Object priority; \
4951 int new_size = 2 * size; \
4952 struct overlay_entry *old = entries; \
4954 (struct overlay_entry *) alloca (new_size \
4955 * sizeof *entries); \
4956 bcopy (old, entries, size * sizeof *entries); \
4960 entries[n].string = (STRING); \
4961 entries[n].overlay = (OVERLAY); \
4962 priority = Foverlay_get ((OVERLAY), Qpriority); \
4963 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4964 entries[n].after_string_p = (AFTER_P); \
4969 /* Process overlay before the overlay center. */
4970 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4972 XSETMISC (overlay
, ov
);
4973 xassert (OVERLAYP (overlay
));
4974 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4975 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4980 /* Skip this overlay if it doesn't start or end at IT's current
4982 if (end
!= charpos
&& start
!= charpos
)
4985 /* Skip this overlay if it doesn't apply to IT->w. */
4986 window
= Foverlay_get (overlay
, Qwindow
);
4987 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4990 /* If the text ``under'' the overlay is invisible, both before-
4991 and after-strings from this overlay are visible; start and
4992 end position are indistinguishable. */
4993 invisible
= Foverlay_get (overlay
, Qinvisible
);
4994 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4996 /* If overlay has a non-empty before-string, record it. */
4997 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4998 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5000 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5002 /* If overlay has a non-empty after-string, record it. */
5003 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5004 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5006 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5009 /* Process overlays after the overlay center. */
5010 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5012 XSETMISC (overlay
, ov
);
5013 xassert (OVERLAYP (overlay
));
5014 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5015 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5017 if (start
> charpos
)
5020 /* Skip this overlay if it doesn't start or end at IT's current
5022 if (end
!= charpos
&& start
!= charpos
)
5025 /* Skip this overlay if it doesn't apply to IT->w. */
5026 window
= Foverlay_get (overlay
, Qwindow
);
5027 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5030 /* If the text ``under'' the overlay is invisible, it has a zero
5031 dimension, and both before- and after-strings apply. */
5032 invisible
= Foverlay_get (overlay
, Qinvisible
);
5033 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5035 /* If overlay has a non-empty before-string, record it. */
5036 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5037 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5039 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5041 /* If overlay has a non-empty after-string, record it. */
5042 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5043 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5045 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5048 #undef RECORD_OVERLAY_STRING
5052 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5054 /* Record the total number of strings to process. */
5055 it
->n_overlay_strings
= n
;
5057 /* IT->current.overlay_string_index is the number of overlay strings
5058 that have already been consumed by IT. Copy some of the
5059 remaining overlay strings to IT->overlay_strings. */
5061 j
= it
->current
.overlay_string_index
;
5062 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5064 it
->overlay_strings
[i
] = entries
[j
].string
;
5065 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5072 /* Get the first chunk of overlay strings at IT's current buffer
5073 position, or at CHARPOS if that is > 0. Value is non-zero if at
5074 least one overlay string was found. */
5077 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5082 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5083 process. This fills IT->overlay_strings with strings, and sets
5084 IT->n_overlay_strings to the total number of strings to process.
5085 IT->pos.overlay_string_index has to be set temporarily to zero
5086 because load_overlay_strings needs this; it must be set to -1
5087 when no overlay strings are found because a zero value would
5088 indicate a position in the first overlay string. */
5089 it
->current
.overlay_string_index
= 0;
5090 load_overlay_strings (it
, charpos
);
5092 /* If we found overlay strings, set up IT to deliver display
5093 elements from the first one. Otherwise set up IT to deliver
5094 from current_buffer. */
5095 if (it
->n_overlay_strings
)
5097 /* Make sure we know settings in current_buffer, so that we can
5098 restore meaningful values when we're done with the overlay
5101 compute_stop_pos (it
);
5102 xassert (it
->face_id
>= 0);
5104 /* Save IT's settings. They are restored after all overlay
5105 strings have been processed. */
5106 xassert (!compute_stop_p
|| it
->sp
== 0);
5109 /* Set up IT to deliver display elements from the first overlay
5111 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5112 it
->string
= it
->overlay_strings
[0];
5113 it
->from_overlay
= Qnil
;
5114 it
->stop_charpos
= 0;
5115 xassert (STRINGP (it
->string
));
5116 it
->end_charpos
= SCHARS (it
->string
);
5117 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5118 it
->method
= GET_FROM_STRING
;
5122 it
->current
.overlay_string_index
= -1;
5127 get_overlay_strings (it
, charpos
)
5132 it
->method
= GET_FROM_BUFFER
;
5134 (void) get_overlay_strings_1 (it
, charpos
, 1);
5138 /* Value is non-zero if we found at least one overlay string. */
5139 return STRINGP (it
->string
);
5144 /***********************************************************************
5145 Saving and restoring state
5146 ***********************************************************************/
5148 /* Save current settings of IT on IT->stack. Called, for example,
5149 before setting up IT for an overlay string, to be able to restore
5150 IT's settings to what they were after the overlay string has been
5157 struct iterator_stack_entry
*p
;
5159 xassert (it
->sp
< IT_STACK_SIZE
);
5160 p
= it
->stack
+ it
->sp
;
5162 p
->stop_charpos
= it
->stop_charpos
;
5163 xassert (it
->face_id
>= 0);
5164 p
->face_id
= it
->face_id
;
5165 p
->string
= it
->string
;
5166 p
->method
= it
->method
;
5167 p
->from_overlay
= it
->from_overlay
;
5170 case GET_FROM_IMAGE
:
5171 p
->u
.image
.object
= it
->object
;
5172 p
->u
.image
.image_id
= it
->image_id
;
5173 p
->u
.image
.slice
= it
->slice
;
5175 case GET_FROM_COMPOSITION
:
5176 p
->u
.comp
.object
= it
->object
;
5177 p
->u
.comp
.c
= it
->c
;
5178 p
->u
.comp
.len
= it
->len
;
5179 p
->u
.comp
.cmp_id
= it
->cmp_id
;
5180 p
->u
.comp
.cmp_len
= it
->cmp_len
;
5182 case GET_FROM_STRETCH
:
5183 p
->u
.stretch
.object
= it
->object
;
5186 p
->position
= it
->position
;
5187 p
->current
= it
->current
;
5188 p
->end_charpos
= it
->end_charpos
;
5189 p
->string_nchars
= it
->string_nchars
;
5191 p
->multibyte_p
= it
->multibyte_p
;
5192 p
->space_width
= it
->space_width
;
5193 p
->font_height
= it
->font_height
;
5194 p
->voffset
= it
->voffset
;
5195 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5196 p
->display_ellipsis_p
= 0;
5201 /* Restore IT's settings from IT->stack. Called, for example, when no
5202 more overlay strings must be processed, and we return to delivering
5203 display elements from a buffer, or when the end of a string from a
5204 `display' property is reached and we return to delivering display
5205 elements from an overlay string, or from a buffer. */
5211 struct iterator_stack_entry
*p
;
5213 xassert (it
->sp
> 0);
5215 p
= it
->stack
+ it
->sp
;
5216 it
->stop_charpos
= p
->stop_charpos
;
5217 it
->face_id
= p
->face_id
;
5218 it
->current
= p
->current
;
5219 it
->position
= p
->position
;
5220 it
->string
= p
->string
;
5221 it
->from_overlay
= p
->from_overlay
;
5222 if (NILP (it
->string
))
5223 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5224 it
->method
= p
->method
;
5227 case GET_FROM_IMAGE
:
5228 it
->image_id
= p
->u
.image
.image_id
;
5229 it
->object
= p
->u
.image
.object
;
5230 it
->slice
= p
->u
.image
.slice
;
5232 case GET_FROM_COMPOSITION
:
5233 it
->object
= p
->u
.comp
.object
;
5234 it
->c
= p
->u
.comp
.c
;
5235 it
->len
= p
->u
.comp
.len
;
5236 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5237 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5239 case GET_FROM_STRETCH
:
5240 it
->object
= p
->u
.comp
.object
;
5242 case GET_FROM_BUFFER
:
5243 it
->object
= it
->w
->buffer
;
5245 case GET_FROM_STRING
:
5246 it
->object
= it
->string
;
5249 it
->end_charpos
= p
->end_charpos
;
5250 it
->string_nchars
= p
->string_nchars
;
5252 it
->multibyte_p
= p
->multibyte_p
;
5253 it
->space_width
= p
->space_width
;
5254 it
->font_height
= p
->font_height
;
5255 it
->voffset
= p
->voffset
;
5256 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5261 /***********************************************************************
5263 ***********************************************************************/
5265 /* Set IT's current position to the previous line start. */
5268 back_to_previous_line_start (it
)
5271 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5272 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5276 /* Move IT to the next line start.
5278 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5279 we skipped over part of the text (as opposed to moving the iterator
5280 continuously over the text). Otherwise, don't change the value
5283 Newlines may come from buffer text, overlay strings, or strings
5284 displayed via the `display' property. That's the reason we can't
5285 simply use find_next_newline_no_quit.
5287 Note that this function may not skip over invisible text that is so
5288 because of text properties and immediately follows a newline. If
5289 it would, function reseat_at_next_visible_line_start, when called
5290 from set_iterator_to_next, would effectively make invisible
5291 characters following a newline part of the wrong glyph row, which
5292 leads to wrong cursor motion. */
5295 forward_to_next_line_start (it
, skipped_p
)
5299 int old_selective
, newline_found_p
, n
;
5300 const int MAX_NEWLINE_DISTANCE
= 500;
5302 /* If already on a newline, just consume it to avoid unintended
5303 skipping over invisible text below. */
5304 if (it
->what
== IT_CHARACTER
5306 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5308 set_iterator_to_next (it
, 0);
5313 /* Don't handle selective display in the following. It's (a)
5314 unnecessary because it's done by the caller, and (b) leads to an
5315 infinite recursion because next_element_from_ellipsis indirectly
5316 calls this function. */
5317 old_selective
= it
->selective
;
5320 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5321 from buffer text. */
5322 for (n
= newline_found_p
= 0;
5323 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5324 n
+= STRINGP (it
->string
) ? 0 : 1)
5326 if (!get_next_display_element (it
))
5328 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5329 set_iterator_to_next (it
, 0);
5332 /* If we didn't find a newline near enough, see if we can use a
5334 if (!newline_found_p
)
5336 int start
= IT_CHARPOS (*it
);
5337 int limit
= find_next_newline_no_quit (start
, 1);
5340 xassert (!STRINGP (it
->string
));
5342 /* If there isn't any `display' property in sight, and no
5343 overlays, we can just use the position of the newline in
5345 if (it
->stop_charpos
>= limit
5346 || ((pos
= Fnext_single_property_change (make_number (start
),
5348 Qnil
, make_number (limit
)),
5350 && next_overlay_change (start
) == ZV
))
5352 IT_CHARPOS (*it
) = limit
;
5353 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5354 *skipped_p
= newline_found_p
= 1;
5358 while (get_next_display_element (it
)
5359 && !newline_found_p
)
5361 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5362 set_iterator_to_next (it
, 0);
5367 it
->selective
= old_selective
;
5368 return newline_found_p
;
5372 /* Set IT's current position to the previous visible line start. Skip
5373 invisible text that is so either due to text properties or due to
5374 selective display. Caution: this does not change IT->current_x and
5378 back_to_previous_visible_line_start (it
)
5381 while (IT_CHARPOS (*it
) > BEGV
)
5383 back_to_previous_line_start (it
);
5385 if (IT_CHARPOS (*it
) <= BEGV
)
5388 /* If selective > 0, then lines indented more than that values
5390 if (it
->selective
> 0
5391 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5392 (double) it
->selective
)) /* iftc */
5395 /* Check the newline before point for invisibility. */
5398 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5399 Qinvisible
, it
->window
);
5400 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5404 if (IT_CHARPOS (*it
) <= BEGV
)
5411 Lisp_Object val
, overlay
;
5413 /* If newline is part of a composition, continue from start of composition */
5414 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5415 && beg
< IT_CHARPOS (*it
))
5418 /* If newline is replaced by a display property, find start of overlay
5419 or interval and continue search from that point. */
5421 pos
= --IT_CHARPOS (it2
);
5424 if (handle_display_prop (&it2
) == HANDLED_RETURN
5425 && !NILP (val
= get_char_property_and_overlay
5426 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5427 && (OVERLAYP (overlay
)
5428 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5429 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5432 /* Newline is not replaced by anything -- so we are done. */
5438 IT_CHARPOS (*it
) = beg
;
5439 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5443 it
->continuation_lines_width
= 0;
5445 xassert (IT_CHARPOS (*it
) >= BEGV
);
5446 xassert (IT_CHARPOS (*it
) == BEGV
5447 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5452 /* Reseat iterator IT at the previous visible line start. Skip
5453 invisible text that is so either due to text properties or due to
5454 selective display. At the end, update IT's overlay information,
5455 face information etc. */
5458 reseat_at_previous_visible_line_start (it
)
5461 back_to_previous_visible_line_start (it
);
5462 reseat (it
, it
->current
.pos
, 1);
5467 /* Reseat iterator IT on the next visible line start in the current
5468 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5469 preceding the line start. Skip over invisible text that is so
5470 because of selective display. Compute faces, overlays etc at the
5471 new position. Note that this function does not skip over text that
5472 is invisible because of text properties. */
5475 reseat_at_next_visible_line_start (it
, on_newline_p
)
5479 int newline_found_p
, skipped_p
= 0;
5481 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5483 /* Skip over lines that are invisible because they are indented
5484 more than the value of IT->selective. */
5485 if (it
->selective
> 0)
5486 while (IT_CHARPOS (*it
) < ZV
5487 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5488 (double) it
->selective
)) /* iftc */
5490 xassert (IT_BYTEPOS (*it
) == BEGV
5491 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5492 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5495 /* Position on the newline if that's what's requested. */
5496 if (on_newline_p
&& newline_found_p
)
5498 if (STRINGP (it
->string
))
5500 if (IT_STRING_CHARPOS (*it
) > 0)
5502 --IT_STRING_CHARPOS (*it
);
5503 --IT_STRING_BYTEPOS (*it
);
5506 else if (IT_CHARPOS (*it
) > BEGV
)
5510 reseat (it
, it
->current
.pos
, 0);
5514 reseat (it
, it
->current
.pos
, 0);
5521 /***********************************************************************
5522 Changing an iterator's position
5523 ***********************************************************************/
5525 /* Change IT's current position to POS in current_buffer. If FORCE_P
5526 is non-zero, always check for text properties at the new position.
5527 Otherwise, text properties are only looked up if POS >=
5528 IT->check_charpos of a property. */
5531 reseat (it
, pos
, force_p
)
5533 struct text_pos pos
;
5536 int original_pos
= IT_CHARPOS (*it
);
5538 reseat_1 (it
, pos
, 0);
5540 /* Determine where to check text properties. Avoid doing it
5541 where possible because text property lookup is very expensive. */
5543 || CHARPOS (pos
) > it
->stop_charpos
5544 || CHARPOS (pos
) < original_pos
)
5551 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5552 IT->stop_pos to POS, also. */
5555 reseat_1 (it
, pos
, set_stop_p
)
5557 struct text_pos pos
;
5560 /* Don't call this function when scanning a C string. */
5561 xassert (it
->s
== NULL
);
5563 /* POS must be a reasonable value. */
5564 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5566 it
->current
.pos
= it
->position
= pos
;
5567 it
->end_charpos
= ZV
;
5569 it
->current
.dpvec_index
= -1;
5570 it
->current
.overlay_string_index
= -1;
5571 IT_STRING_CHARPOS (*it
) = -1;
5572 IT_STRING_BYTEPOS (*it
) = -1;
5574 it
->method
= GET_FROM_BUFFER
;
5575 it
->object
= it
->w
->buffer
;
5576 it
->area
= TEXT_AREA
;
5577 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5579 it
->string_from_display_prop_p
= 0;
5580 it
->face_before_selective_p
= 0;
5583 it
->stop_charpos
= CHARPOS (pos
);
5587 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5588 If S is non-null, it is a C string to iterate over. Otherwise,
5589 STRING gives a Lisp string to iterate over.
5591 If PRECISION > 0, don't return more then PRECISION number of
5592 characters from the string.
5594 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5595 characters have been returned. FIELD_WIDTH < 0 means an infinite
5598 MULTIBYTE = 0 means disable processing of multibyte characters,
5599 MULTIBYTE > 0 means enable it,
5600 MULTIBYTE < 0 means use IT->multibyte_p.
5602 IT must be initialized via a prior call to init_iterator before
5603 calling this function. */
5606 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5611 int precision
, field_width
, multibyte
;
5613 /* No region in strings. */
5614 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5616 /* No text property checks performed by default, but see below. */
5617 it
->stop_charpos
= -1;
5619 /* Set iterator position and end position. */
5620 bzero (&it
->current
, sizeof it
->current
);
5621 it
->current
.overlay_string_index
= -1;
5622 it
->current
.dpvec_index
= -1;
5623 xassert (charpos
>= 0);
5625 /* If STRING is specified, use its multibyteness, otherwise use the
5626 setting of MULTIBYTE, if specified. */
5628 it
->multibyte_p
= multibyte
> 0;
5632 xassert (STRINGP (string
));
5633 it
->string
= string
;
5635 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5636 it
->method
= GET_FROM_STRING
;
5637 it
->current
.string_pos
= string_pos (charpos
, string
);
5644 /* Note that we use IT->current.pos, not it->current.string_pos,
5645 for displaying C strings. */
5646 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5647 if (it
->multibyte_p
)
5649 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5650 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5654 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5655 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5658 it
->method
= GET_FROM_C_STRING
;
5661 /* PRECISION > 0 means don't return more than PRECISION characters
5663 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5664 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5666 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5667 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5668 FIELD_WIDTH < 0 means infinite field width. This is useful for
5669 padding with `-' at the end of a mode line. */
5670 if (field_width
< 0)
5671 field_width
= INFINITY
;
5672 if (field_width
> it
->end_charpos
- charpos
)
5673 it
->end_charpos
= charpos
+ field_width
;
5675 /* Use the standard display table for displaying strings. */
5676 if (DISP_TABLE_P (Vstandard_display_table
))
5677 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5679 it
->stop_charpos
= charpos
;
5685 /***********************************************************************
5687 ***********************************************************************/
5689 /* Map enum it_method value to corresponding next_element_from_* function. */
5691 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5693 next_element_from_buffer
,
5694 next_element_from_display_vector
,
5695 next_element_from_composition
,
5696 next_element_from_string
,
5697 next_element_from_c_string
,
5698 next_element_from_image
,
5699 next_element_from_stretch
5702 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5704 /* Load IT's display element fields with information about the next
5705 display element from the current position of IT. Value is zero if
5706 end of buffer (or C string) is reached. */
5708 static struct frame
*last_escape_glyph_frame
= NULL
;
5709 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5710 static int last_escape_glyph_merged_face_id
= 0;
5713 get_next_display_element (it
)
5716 /* Non-zero means that we found a display element. Zero means that
5717 we hit the end of what we iterate over. Performance note: the
5718 function pointer `method' used here turns out to be faster than
5719 using a sequence of if-statements. */
5723 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5725 if (it
->what
== IT_CHARACTER
)
5727 /* Map via display table or translate control characters.
5728 IT->c, IT->len etc. have been set to the next character by
5729 the function call above. If we have a display table, and it
5730 contains an entry for IT->c, translate it. Don't do this if
5731 IT->c itself comes from a display table, otherwise we could
5732 end up in an infinite recursion. (An alternative could be to
5733 count the recursion depth of this function and signal an
5734 error when a certain maximum depth is reached.) Is it worth
5736 if (success_p
&& it
->dpvec
== NULL
)
5741 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5744 struct Lisp_Vector
*v
= XVECTOR (dv
);
5746 /* Return the first character from the display table
5747 entry, if not empty. If empty, don't display the
5748 current character. */
5751 it
->dpvec_char_len
= it
->len
;
5752 it
->dpvec
= v
->contents
;
5753 it
->dpend
= v
->contents
+ v
->size
;
5754 it
->current
.dpvec_index
= 0;
5755 it
->dpvec_face_id
= -1;
5756 it
->saved_face_id
= it
->face_id
;
5757 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5762 set_iterator_to_next (it
, 0);
5767 /* Translate control characters into `\003' or `^C' form.
5768 Control characters coming from a display table entry are
5769 currently not translated because we use IT->dpvec to hold
5770 the translation. This could easily be changed but I
5771 don't believe that it is worth doing.
5773 If it->multibyte_p is nonzero, non-printable non-ASCII
5774 characters are also translated to octal form.
5776 If it->multibyte_p is zero, eight-bit characters that
5777 don't have corresponding multibyte char code are also
5778 translated to octal form. */
5779 else if ((it
->c
< ' '
5780 ? (it
->area
!= TEXT_AREA
5781 /* In mode line, treat \n, \t like other crl chars. */
5783 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5784 || (it
->c
!= '\n' && it
->c
!= '\t'))
5786 ? (!CHAR_PRINTABLE_P (it
->c
)
5787 || (!NILP (Vnobreak_char_display
)
5788 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5789 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5791 && (! unibyte_display_via_language_environment
5792 || (UNIBYTE_CHAR_HAS_MULTIBYTE_P (it
->c
)))))))
5794 /* IT->c is a control character which must be displayed
5795 either as '\003' or as `^C' where the '\\' and '^'
5796 can be defined in the display table. Fill
5797 IT->ctl_chars with glyphs for what we have to
5798 display. Then, set IT->dpvec to these glyphs. */
5801 int face_id
, lface_id
= 0 ;
5804 /* Handle control characters with ^. */
5806 if (it
->c
< 128 && it
->ctl_arrow_p
)
5810 g
= '^'; /* default glyph for Control */
5811 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5813 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5814 && GLYPH_CODE_CHAR_VALID_P (gc
))
5816 g
= GLYPH_CODE_CHAR (gc
);
5817 lface_id
= GLYPH_CODE_FACE (gc
);
5821 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5823 else if (it
->f
== last_escape_glyph_frame
5824 && it
->face_id
== last_escape_glyph_face_id
)
5826 face_id
= last_escape_glyph_merged_face_id
;
5830 /* Merge the escape-glyph face into the current face. */
5831 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5833 last_escape_glyph_frame
= it
->f
;
5834 last_escape_glyph_face_id
= it
->face_id
;
5835 last_escape_glyph_merged_face_id
= face_id
;
5838 XSETINT (it
->ctl_chars
[0], g
);
5839 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5841 goto display_control
;
5844 /* Handle non-break space in the mode where it only gets
5847 if (EQ (Vnobreak_char_display
, Qt
)
5850 /* Merge the no-break-space face into the current face. */
5851 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5855 XSETINT (it
->ctl_chars
[0], ' ');
5857 goto display_control
;
5860 /* Handle sequences that start with the "escape glyph". */
5862 /* the default escape glyph is \. */
5863 escape_glyph
= '\\';
5866 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5867 && GLYPH_CODE_CHAR_VALID_P (gc
))
5869 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5870 lface_id
= GLYPH_CODE_FACE (gc
);
5874 /* The display table specified a face.
5875 Merge it into face_id and also into escape_glyph. */
5876 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5879 else if (it
->f
== last_escape_glyph_frame
5880 && it
->face_id
== last_escape_glyph_face_id
)
5882 face_id
= last_escape_glyph_merged_face_id
;
5886 /* Merge the escape-glyph face into the current face. */
5887 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5889 last_escape_glyph_frame
= it
->f
;
5890 last_escape_glyph_face_id
= it
->face_id
;
5891 last_escape_glyph_merged_face_id
= face_id
;
5894 /* Handle soft hyphens in the mode where they only get
5897 if (EQ (Vnobreak_char_display
, Qt
)
5901 XSETINT (it
->ctl_chars
[0], '-');
5903 goto display_control
;
5906 /* Handle non-break space and soft hyphen
5907 with the escape glyph. */
5909 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5911 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5912 it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5913 XSETINT (it
->ctl_chars
[1], it
->c
);
5915 goto display_control
;
5919 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5923 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5924 if (CHAR_BYTE8_P (it
->c
))
5926 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5929 else if (it
->c
< 256)
5936 /* It's an invalid character, which shouldn't
5937 happen actually, but due to bugs it may
5938 happen. Let's print the char as is, there's
5939 not much meaningful we can do with it. */
5941 str
[1] = it
->c
>> 8;
5942 str
[2] = it
->c
>> 16;
5943 str
[3] = it
->c
>> 24;
5947 for (i
= 0; i
< len
; i
++)
5950 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5951 /* Insert three more glyphs into IT->ctl_chars for
5952 the octal display of the character. */
5953 g
= ((str
[i
] >> 6) & 7) + '0';
5954 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5955 g
= ((str
[i
] >> 3) & 7) + '0';
5956 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5957 g
= (str
[i
] & 7) + '0';
5958 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5964 /* Set up IT->dpvec and return first character from it. */
5965 it
->dpvec_char_len
= it
->len
;
5966 it
->dpvec
= it
->ctl_chars
;
5967 it
->dpend
= it
->dpvec
+ ctl_len
;
5968 it
->current
.dpvec_index
= 0;
5969 it
->dpvec_face_id
= face_id
;
5970 it
->saved_face_id
= it
->face_id
;
5971 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5978 /* Adjust face id for a multibyte character. There are no multibyte
5979 character in unibyte text. */
5980 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5983 && FRAME_WINDOW_P (it
->f
))
5985 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5986 int pos
= (it
->s
? -1
5987 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5988 : IT_CHARPOS (*it
));
5990 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5993 /* Is this character the last one of a run of characters with
5994 box? If yes, set IT->end_of_box_run_p to 1. */
6001 it
->end_of_box_run_p
6002 = ((face_id
= face_after_it_pos (it
),
6003 face_id
!= it
->face_id
)
6004 && (face
= FACE_FROM_ID (it
->f
, face_id
),
6005 face
->box
== FACE_NO_BOX
));
6008 /* Value is 0 if end of buffer or string reached. */
6013 /* Move IT to the next display element.
6015 RESEAT_P non-zero means if called on a newline in buffer text,
6016 skip to the next visible line start.
6018 Functions get_next_display_element and set_iterator_to_next are
6019 separate because I find this arrangement easier to handle than a
6020 get_next_display_element function that also increments IT's
6021 position. The way it is we can first look at an iterator's current
6022 display element, decide whether it fits on a line, and if it does,
6023 increment the iterator position. The other way around we probably
6024 would either need a flag indicating whether the iterator has to be
6025 incremented the next time, or we would have to implement a
6026 decrement position function which would not be easy to write. */
6029 set_iterator_to_next (it
, reseat_p
)
6033 /* Reset flags indicating start and end of a sequence of characters
6034 with box. Reset them at the start of this function because
6035 moving the iterator to a new position might set them. */
6036 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6040 case GET_FROM_BUFFER
:
6041 /* The current display element of IT is a character from
6042 current_buffer. Advance in the buffer, and maybe skip over
6043 invisible lines that are so because of selective display. */
6044 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6045 reseat_at_next_visible_line_start (it
, 0);
6048 xassert (it
->len
!= 0);
6049 IT_BYTEPOS (*it
) += it
->len
;
6050 IT_CHARPOS (*it
) += 1;
6051 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6055 case GET_FROM_COMPOSITION
:
6056 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
6057 xassert (it
->sp
> 0);
6059 if (it
->method
== GET_FROM_STRING
)
6061 IT_STRING_BYTEPOS (*it
) += it
->len
;
6062 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
6063 goto consider_string_end
;
6065 else if (it
->method
== GET_FROM_BUFFER
)
6067 IT_BYTEPOS (*it
) += it
->len
;
6068 IT_CHARPOS (*it
) += it
->cmp_len
;
6072 case GET_FROM_C_STRING
:
6073 /* Current display element of IT is from a C string. */
6074 IT_BYTEPOS (*it
) += it
->len
;
6075 IT_CHARPOS (*it
) += 1;
6078 case GET_FROM_DISPLAY_VECTOR
:
6079 /* Current display element of IT is from a display table entry.
6080 Advance in the display table definition. Reset it to null if
6081 end reached, and continue with characters from buffers/
6083 ++it
->current
.dpvec_index
;
6085 /* Restore face of the iterator to what they were before the
6086 display vector entry (these entries may contain faces). */
6087 it
->face_id
= it
->saved_face_id
;
6089 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6091 int recheck_faces
= it
->ellipsis_p
;
6094 it
->method
= GET_FROM_C_STRING
;
6095 else if (STRINGP (it
->string
))
6096 it
->method
= GET_FROM_STRING
;
6099 it
->method
= GET_FROM_BUFFER
;
6100 it
->object
= it
->w
->buffer
;
6104 it
->current
.dpvec_index
= -1;
6106 /* Skip over characters which were displayed via IT->dpvec. */
6107 if (it
->dpvec_char_len
< 0)
6108 reseat_at_next_visible_line_start (it
, 1);
6109 else if (it
->dpvec_char_len
> 0)
6111 if (it
->method
== GET_FROM_STRING
6112 && it
->n_overlay_strings
> 0)
6113 it
->ignore_overlay_strings_at_pos_p
= 1;
6114 it
->len
= it
->dpvec_char_len
;
6115 set_iterator_to_next (it
, reseat_p
);
6118 /* Maybe recheck faces after display vector */
6120 it
->stop_charpos
= IT_CHARPOS (*it
);
6124 case GET_FROM_STRING
:
6125 /* Current display element is a character from a Lisp string. */
6126 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6127 IT_STRING_BYTEPOS (*it
) += it
->len
;
6128 IT_STRING_CHARPOS (*it
) += 1;
6130 consider_string_end
:
6132 if (it
->current
.overlay_string_index
>= 0)
6134 /* IT->string is an overlay string. Advance to the
6135 next, if there is one. */
6136 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6137 next_overlay_string (it
);
6141 /* IT->string is not an overlay string. If we reached
6142 its end, and there is something on IT->stack, proceed
6143 with what is on the stack. This can be either another
6144 string, this time an overlay string, or a buffer. */
6145 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6149 if (it
->method
== GET_FROM_STRING
)
6150 goto consider_string_end
;
6155 case GET_FROM_IMAGE
:
6156 case GET_FROM_STRETCH
:
6157 /* The position etc with which we have to proceed are on
6158 the stack. The position may be at the end of a string,
6159 if the `display' property takes up the whole string. */
6160 xassert (it
->sp
> 0);
6162 if (it
->method
== GET_FROM_STRING
)
6163 goto consider_string_end
;
6167 /* There are no other methods defined, so this should be a bug. */
6171 xassert (it
->method
!= GET_FROM_STRING
6172 || (STRINGP (it
->string
)
6173 && IT_STRING_CHARPOS (*it
) >= 0));
6176 /* Load IT's display element fields with information about the next
6177 display element which comes from a display table entry or from the
6178 result of translating a control character to one of the forms `^C'
6181 IT->dpvec holds the glyphs to return as characters.
6182 IT->saved_face_id holds the face id before the display vector--
6183 it is restored into IT->face_idin set_iterator_to_next. */
6186 next_element_from_display_vector (it
)
6192 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6194 it
->face_id
= it
->saved_face_id
;
6196 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6197 That seemed totally bogus - so I changed it... */
6199 if ((gc
= it
->dpvec
[it
->current
.dpvec_index
], GLYPH_CODE_P (gc
))
6200 && GLYPH_CODE_CHAR_VALID_P (gc
))
6202 it
->c
= GLYPH_CODE_CHAR (gc
);
6203 it
->len
= CHAR_BYTES (it
->c
);
6205 /* The entry may contain a face id to use. Such a face id is
6206 the id of a Lisp face, not a realized face. A face id of
6207 zero means no face is specified. */
6208 if (it
->dpvec_face_id
>= 0)
6209 it
->face_id
= it
->dpvec_face_id
;
6212 int lface_id
= GLYPH_CODE_FACE (gc
);
6214 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6219 /* Display table entry is invalid. Return a space. */
6220 it
->c
= ' ', it
->len
= 1;
6222 /* Don't change position and object of the iterator here. They are
6223 still the values of the character that had this display table
6224 entry or was translated, and that's what we want. */
6225 it
->what
= IT_CHARACTER
;
6230 /* Load IT with the next display element from Lisp string IT->string.
6231 IT->current.string_pos is the current position within the string.
6232 If IT->current.overlay_string_index >= 0, the Lisp string is an
6236 next_element_from_string (it
)
6239 struct text_pos position
;
6241 xassert (STRINGP (it
->string
));
6242 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6243 position
= it
->current
.string_pos
;
6245 /* Time to check for invisible text? */
6246 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6247 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6251 /* Since a handler may have changed IT->method, we must
6253 return GET_NEXT_DISPLAY_ELEMENT (it
);
6256 if (it
->current
.overlay_string_index
>= 0)
6258 /* Get the next character from an overlay string. In overlay
6259 strings, There is no field width or padding with spaces to
6261 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6266 else if (STRING_MULTIBYTE (it
->string
))
6268 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6269 const unsigned char *s
= (SDATA (it
->string
)
6270 + IT_STRING_BYTEPOS (*it
));
6271 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6275 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6281 /* Get the next character from a Lisp string that is not an
6282 overlay string. Such strings come from the mode line, for
6283 example. We may have to pad with spaces, or truncate the
6284 string. See also next_element_from_c_string. */
6285 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6290 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6292 /* Pad with spaces. */
6293 it
->c
= ' ', it
->len
= 1;
6294 CHARPOS (position
) = BYTEPOS (position
) = -1;
6296 else if (STRING_MULTIBYTE (it
->string
))
6298 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6299 const unsigned char *s
= (SDATA (it
->string
)
6300 + IT_STRING_BYTEPOS (*it
));
6301 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6305 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6310 /* Record what we have and where it came from. */
6311 it
->what
= IT_CHARACTER
;
6312 it
->object
= it
->string
;
6313 it
->position
= position
;
6318 /* Load IT with next display element from C string IT->s.
6319 IT->string_nchars is the maximum number of characters to return
6320 from the string. IT->end_charpos may be greater than
6321 IT->string_nchars when this function is called, in which case we
6322 may have to return padding spaces. Value is zero if end of string
6323 reached, including padding spaces. */
6326 next_element_from_c_string (it
)
6332 it
->what
= IT_CHARACTER
;
6333 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6336 /* IT's position can be greater IT->string_nchars in case a field
6337 width or precision has been specified when the iterator was
6339 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6341 /* End of the game. */
6345 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6347 /* Pad with spaces. */
6348 it
->c
= ' ', it
->len
= 1;
6349 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6351 else if (it
->multibyte_p
)
6353 /* Implementation note: The calls to strlen apparently aren't a
6354 performance problem because there is no noticeable performance
6355 difference between Emacs running in unibyte or multibyte mode. */
6356 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6357 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6361 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6367 /* Set up IT to return characters from an ellipsis, if appropriate.
6368 The definition of the ellipsis glyphs may come from a display table
6369 entry. This function Fills IT with the first glyph from the
6370 ellipsis if an ellipsis is to be displayed. */
6373 next_element_from_ellipsis (it
)
6376 if (it
->selective_display_ellipsis_p
)
6377 setup_for_ellipsis (it
, it
->len
);
6380 /* The face at the current position may be different from the
6381 face we find after the invisible text. Remember what it
6382 was in IT->saved_face_id, and signal that it's there by
6383 setting face_before_selective_p. */
6384 it
->saved_face_id
= it
->face_id
;
6385 it
->method
= GET_FROM_BUFFER
;
6386 it
->object
= it
->w
->buffer
;
6387 reseat_at_next_visible_line_start (it
, 1);
6388 it
->face_before_selective_p
= 1;
6391 return GET_NEXT_DISPLAY_ELEMENT (it
);
6395 /* Deliver an image display element. The iterator IT is already
6396 filled with image information (done in handle_display_prop). Value
6401 next_element_from_image (it
)
6404 it
->what
= IT_IMAGE
;
6409 /* Fill iterator IT with next display element from a stretch glyph
6410 property. IT->object is the value of the text property. Value is
6414 next_element_from_stretch (it
)
6417 it
->what
= IT_STRETCH
;
6422 /* Load IT with the next display element from current_buffer. Value
6423 is zero if end of buffer reached. IT->stop_charpos is the next
6424 position at which to stop and check for text properties or buffer
6428 next_element_from_buffer (it
)
6433 /* Check this assumption, otherwise, we would never enter the
6434 if-statement, below. */
6435 xassert (IT_CHARPOS (*it
) >= BEGV
6436 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6438 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6440 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6442 int overlay_strings_follow_p
;
6444 /* End of the game, except when overlay strings follow that
6445 haven't been returned yet. */
6446 if (it
->overlay_strings_at_end_processed_p
)
6447 overlay_strings_follow_p
= 0;
6450 it
->overlay_strings_at_end_processed_p
= 1;
6451 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6454 if (overlay_strings_follow_p
)
6455 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6459 it
->position
= it
->current
.pos
;
6466 return GET_NEXT_DISPLAY_ELEMENT (it
);
6471 /* No face changes, overlays etc. in sight, so just return a
6472 character from current_buffer. */
6475 /* Maybe run the redisplay end trigger hook. Performance note:
6476 This doesn't seem to cost measurable time. */
6477 if (it
->redisplay_end_trigger_charpos
6479 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6480 run_redisplay_end_trigger_hook (it
);
6482 /* Get the next character, maybe multibyte. */
6483 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6484 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6486 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6487 - IT_BYTEPOS (*it
));
6488 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6491 it
->c
= *p
, it
->len
= 1;
6493 /* Record what we have and where it came from. */
6494 it
->what
= IT_CHARACTER
;
6495 it
->object
= it
->w
->buffer
;
6496 it
->position
= it
->current
.pos
;
6498 /* Normally we return the character found above, except when we
6499 really want to return an ellipsis for selective display. */
6504 /* A value of selective > 0 means hide lines indented more
6505 than that number of columns. */
6506 if (it
->selective
> 0
6507 && IT_CHARPOS (*it
) + 1 < ZV
6508 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6509 IT_BYTEPOS (*it
) + 1,
6510 (double) it
->selective
)) /* iftc */
6512 success_p
= next_element_from_ellipsis (it
);
6513 it
->dpvec_char_len
= -1;
6516 else if (it
->c
== '\r' && it
->selective
== -1)
6518 /* A value of selective == -1 means that everything from the
6519 CR to the end of the line is invisible, with maybe an
6520 ellipsis displayed for it. */
6521 success_p
= next_element_from_ellipsis (it
);
6522 it
->dpvec_char_len
= -1;
6527 /* Value is zero if end of buffer reached. */
6528 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6533 /* Run the redisplay end trigger hook for IT. */
6536 run_redisplay_end_trigger_hook (it
)
6539 Lisp_Object args
[3];
6541 /* IT->glyph_row should be non-null, i.e. we should be actually
6542 displaying something, or otherwise we should not run the hook. */
6543 xassert (it
->glyph_row
);
6545 /* Set up hook arguments. */
6546 args
[0] = Qredisplay_end_trigger_functions
;
6547 args
[1] = it
->window
;
6548 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6549 it
->redisplay_end_trigger_charpos
= 0;
6551 /* Since we are *trying* to run these functions, don't try to run
6552 them again, even if they get an error. */
6553 it
->w
->redisplay_end_trigger
= Qnil
;
6554 Frun_hook_with_args (3, args
);
6556 /* Notice if it changed the face of the character we are on. */
6557 handle_face_prop (it
);
6561 /* Deliver a composition display element. The iterator IT is already
6562 filled with composition information (done in
6563 handle_composition_prop). Value is always 1. */
6566 next_element_from_composition (it
)
6569 it
->what
= IT_COMPOSITION
;
6570 it
->position
= (STRINGP (it
->string
)
6571 ? it
->current
.string_pos
6573 if (STRINGP (it
->string
))
6574 it
->object
= it
->string
;
6576 it
->object
= it
->w
->buffer
;
6582 /***********************************************************************
6583 Moving an iterator without producing glyphs
6584 ***********************************************************************/
6586 /* Check if iterator is at a position corresponding to a valid buffer
6587 position after some move_it_ call. */
6589 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6590 ((it)->method == GET_FROM_STRING \
6591 ? IT_STRING_CHARPOS (*it) == 0 \
6595 /* Move iterator IT to a specified buffer or X position within one
6596 line on the display without producing glyphs.
6598 OP should be a bit mask including some or all of these bits:
6599 MOVE_TO_X: Stop on reaching x-position TO_X.
6600 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6601 Regardless of OP's value, stop in reaching the end of the display line.
6603 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6604 This means, in particular, that TO_X includes window's horizontal
6607 The return value has several possible values that
6608 say what condition caused the scan to stop:
6610 MOVE_POS_MATCH_OR_ZV
6611 - when TO_POS or ZV was reached.
6614 -when TO_X was reached before TO_POS or ZV were reached.
6617 - when we reached the end of the display area and the line must
6621 - when we reached the end of the display area and the line is
6625 - when we stopped at a line end, i.e. a newline or a CR and selective
6628 static enum move_it_result
6629 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6631 int to_charpos
, to_x
, op
;
6633 enum move_it_result result
= MOVE_UNDEFINED
;
6634 struct glyph_row
*saved_glyph_row
;
6636 /* Don't produce glyphs in produce_glyphs. */
6637 saved_glyph_row
= it
->glyph_row
;
6638 it
->glyph_row
= NULL
;
6640 #define BUFFER_POS_REACHED_P() \
6641 ((op & MOVE_TO_POS) != 0 \
6642 && BUFFERP (it->object) \
6643 && IT_CHARPOS (*it) >= to_charpos \
6644 && (it->method == GET_FROM_BUFFER \
6645 || (it->method == GET_FROM_DISPLAY_VECTOR \
6646 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6651 int x
, i
, ascent
= 0, descent
= 0;
6653 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6654 if ((op
& MOVE_TO_POS
) != 0
6655 && BUFFERP (it
->object
)
6656 && it
->method
== GET_FROM_BUFFER
6657 && IT_CHARPOS (*it
) > to_charpos
)
6659 result
= MOVE_POS_MATCH_OR_ZV
;
6663 /* Stop when ZV reached.
6664 We used to stop here when TO_CHARPOS reached as well, but that is
6665 too soon if this glyph does not fit on this line. So we handle it
6666 explicitly below. */
6667 if (!get_next_display_element (it
)
6668 || (it
->truncate_lines_p
6669 && BUFFER_POS_REACHED_P ()))
6671 result
= MOVE_POS_MATCH_OR_ZV
;
6675 /* The call to produce_glyphs will get the metrics of the
6676 display element IT is loaded with. We record in x the
6677 x-position before this display element in case it does not
6681 /* Remember the line height so far in case the next element doesn't
6683 if (!it
->truncate_lines_p
)
6685 ascent
= it
->max_ascent
;
6686 descent
= it
->max_descent
;
6689 PRODUCE_GLYPHS (it
);
6691 if (it
->area
!= TEXT_AREA
)
6693 set_iterator_to_next (it
, 1);
6697 /* The number of glyphs we get back in IT->nglyphs will normally
6698 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6699 character on a terminal frame, or (iii) a line end. For the
6700 second case, IT->nglyphs - 1 padding glyphs will be present
6701 (on X frames, there is only one glyph produced for a
6702 composite character.
6704 The behavior implemented below means, for continuation lines,
6705 that as many spaces of a TAB as fit on the current line are
6706 displayed there. For terminal frames, as many glyphs of a
6707 multi-glyph character are displayed in the current line, too.
6708 This is what the old redisplay code did, and we keep it that
6709 way. Under X, the whole shape of a complex character must
6710 fit on the line or it will be completely displayed in the
6713 Note that both for tabs and padding glyphs, all glyphs have
6717 /* More than one glyph or glyph doesn't fit on line. All
6718 glyphs have the same width. */
6719 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6721 int x_before_this_char
= x
;
6722 int hpos_before_this_char
= it
->hpos
;
6724 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6726 new_x
= x
+ single_glyph_width
;
6728 /* We want to leave anything reaching TO_X to the caller. */
6729 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6731 if (BUFFER_POS_REACHED_P ())
6732 goto buffer_pos_reached
;
6734 result
= MOVE_X_REACHED
;
6737 else if (/* Lines are continued. */
6738 !it
->truncate_lines_p
6739 && (/* And glyph doesn't fit on the line. */
6740 new_x
> it
->last_visible_x
6741 /* Or it fits exactly and we're on a window
6743 || (new_x
== it
->last_visible_x
6744 && FRAME_WINDOW_P (it
->f
))))
6746 if (/* IT->hpos == 0 means the very first glyph
6747 doesn't fit on the line, e.g. a wide image. */
6749 || (new_x
== it
->last_visible_x
6750 && FRAME_WINDOW_P (it
->f
)))
6753 it
->current_x
= new_x
;
6755 /* The character's last glyph just barely fits
6757 if (i
== it
->nglyphs
- 1)
6759 /* If this is the destination position,
6760 return a position *before* it in this row,
6761 now that we know it fits in this row. */
6762 if (BUFFER_POS_REACHED_P ())
6764 it
->hpos
= hpos_before_this_char
;
6765 it
->current_x
= x_before_this_char
;
6766 result
= MOVE_POS_MATCH_OR_ZV
;
6770 set_iterator_to_next (it
, 1);
6771 #ifdef HAVE_WINDOW_SYSTEM
6772 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6774 if (!get_next_display_element (it
))
6776 result
= MOVE_POS_MATCH_OR_ZV
;
6779 if (BUFFER_POS_REACHED_P ())
6781 if (ITERATOR_AT_END_OF_LINE_P (it
))
6782 result
= MOVE_POS_MATCH_OR_ZV
;
6784 result
= MOVE_LINE_CONTINUED
;
6787 if (ITERATOR_AT_END_OF_LINE_P (it
))
6789 result
= MOVE_NEWLINE_OR_CR
;
6793 #endif /* HAVE_WINDOW_SYSTEM */
6799 it
->max_ascent
= ascent
;
6800 it
->max_descent
= descent
;
6803 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6805 result
= MOVE_LINE_CONTINUED
;
6808 else if (BUFFER_POS_REACHED_P ())
6809 goto buffer_pos_reached
;
6810 else if (new_x
> it
->first_visible_x
)
6812 /* Glyph is visible. Increment number of glyphs that
6813 would be displayed. */
6818 /* Glyph is completely off the left margin of the display
6819 area. Nothing to do. */
6823 if (result
!= MOVE_UNDEFINED
)
6826 else if (BUFFER_POS_REACHED_P ())
6830 it
->max_ascent
= ascent
;
6831 it
->max_descent
= descent
;
6832 result
= MOVE_POS_MATCH_OR_ZV
;
6835 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6837 /* Stop when TO_X specified and reached. This check is
6838 necessary here because of lines consisting of a line end,
6839 only. The line end will not produce any glyphs and we
6840 would never get MOVE_X_REACHED. */
6841 xassert (it
->nglyphs
== 0);
6842 result
= MOVE_X_REACHED
;
6846 /* Is this a line end? If yes, we're done. */
6847 if (ITERATOR_AT_END_OF_LINE_P (it
))
6849 result
= MOVE_NEWLINE_OR_CR
;
6853 /* The current display element has been consumed. Advance
6855 set_iterator_to_next (it
, 1);
6857 /* Stop if lines are truncated and IT's current x-position is
6858 past the right edge of the window now. */
6859 if (it
->truncate_lines_p
6860 && it
->current_x
>= it
->last_visible_x
)
6862 #ifdef HAVE_WINDOW_SYSTEM
6863 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6865 if (!get_next_display_element (it
)
6866 || BUFFER_POS_REACHED_P ())
6868 result
= MOVE_POS_MATCH_OR_ZV
;
6871 if (ITERATOR_AT_END_OF_LINE_P (it
))
6873 result
= MOVE_NEWLINE_OR_CR
;
6877 #endif /* HAVE_WINDOW_SYSTEM */
6878 result
= MOVE_LINE_TRUNCATED
;
6883 #undef BUFFER_POS_REACHED_P
6885 /* Restore the iterator settings altered at the beginning of this
6887 it
->glyph_row
= saved_glyph_row
;
6892 /* Move IT forward until it satisfies one or more of the criteria in
6893 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6895 OP is a bit-mask that specifies where to stop, and in particular,
6896 which of those four position arguments makes a difference. See the
6897 description of enum move_operation_enum.
6899 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6900 screen line, this function will set IT to the next position >
6904 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6906 int to_charpos
, to_x
, to_y
, to_vpos
;
6909 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6915 if (op
& MOVE_TO_VPOS
)
6917 /* If no TO_CHARPOS and no TO_X specified, stop at the
6918 start of the line TO_VPOS. */
6919 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6921 if (it
->vpos
== to_vpos
)
6927 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6931 /* TO_VPOS >= 0 means stop at TO_X in the line at
6932 TO_VPOS, or at TO_POS, whichever comes first. */
6933 if (it
->vpos
== to_vpos
)
6939 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6941 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6946 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6948 /* We have reached TO_X but not in the line we want. */
6949 skip
= move_it_in_display_line_to (it
, to_charpos
,
6951 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6959 else if (op
& MOVE_TO_Y
)
6961 struct it it_backup
;
6963 /* TO_Y specified means stop at TO_X in the line containing
6964 TO_Y---or at TO_CHARPOS if this is reached first. The
6965 problem is that we can't really tell whether the line
6966 contains TO_Y before we have completely scanned it, and
6967 this may skip past TO_X. What we do is to first scan to
6970 If TO_X is not specified, use a TO_X of zero. The reason
6971 is to make the outcome of this function more predictable.
6972 If we didn't use TO_X == 0, we would stop at the end of
6973 the line which is probably not what a caller would expect
6975 skip
= move_it_in_display_line_to (it
, to_charpos
,
6979 | (op
& MOVE_TO_POS
)));
6981 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6982 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6988 /* If TO_X was reached, we would like to know whether TO_Y
6989 is in the line. This can only be said if we know the
6990 total line height which requires us to scan the rest of
6992 if (skip
== MOVE_X_REACHED
)
6994 /* Wait! We can conclude that TO_Y is in the line if
6995 the already scanned glyphs make the line tall enough
6996 because further scanning doesn't make it shorter. */
6997 line_height
= it
->max_ascent
+ it
->max_descent
;
6998 if (to_y
>= it
->current_y
6999 && to_y
< it
->current_y
+ line_height
)
7005 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7006 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7008 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7011 /* Now, decide whether TO_Y is in this line. */
7012 line_height
= it
->max_ascent
+ it
->max_descent
;
7013 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7015 if (to_y
>= it
->current_y
7016 && to_y
< it
->current_y
+ line_height
)
7018 if (skip
== MOVE_X_REACHED
)
7019 /* If TO_Y is in this line and TO_X was reached above,
7020 we scanned too far. We have to restore IT's settings
7021 to the ones before skipping. */
7025 else if (skip
== MOVE_X_REACHED
)
7028 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7035 else if (BUFFERP (it
->object
)
7036 && it
->method
== GET_FROM_BUFFER
7037 && IT_CHARPOS (*it
) >= to_charpos
)
7038 skip
= MOVE_POS_MATCH_OR_ZV
;
7040 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7044 case MOVE_POS_MATCH_OR_ZV
:
7048 case MOVE_NEWLINE_OR_CR
:
7049 set_iterator_to_next (it
, 1);
7050 it
->continuation_lines_width
= 0;
7053 case MOVE_LINE_TRUNCATED
:
7054 it
->continuation_lines_width
= 0;
7055 reseat_at_next_visible_line_start (it
, 0);
7056 if ((op
& MOVE_TO_POS
) != 0
7057 && IT_CHARPOS (*it
) > to_charpos
)
7064 case MOVE_LINE_CONTINUED
:
7065 /* For continued lines ending in a tab, some of the glyphs
7066 associated with the tab are displayed on the current
7067 line. Since it->current_x does not include these glyphs,
7068 we use it->last_visible_x instead. */
7069 it
->continuation_lines_width
+=
7070 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
7077 /* Reset/increment for the next run. */
7078 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7079 it
->current_x
= it
->hpos
= 0;
7080 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7082 last_height
= it
->max_ascent
+ it
->max_descent
;
7083 last_max_ascent
= it
->max_ascent
;
7084 it
->max_ascent
= it
->max_descent
= 0;
7089 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7093 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7095 If DY > 0, move IT backward at least that many pixels. DY = 0
7096 means move IT backward to the preceding line start or BEGV. This
7097 function may move over more than DY pixels if IT->current_y - DY
7098 ends up in the middle of a line; in this case IT->current_y will be
7099 set to the top of the line moved to. */
7102 move_it_vertically_backward (it
, dy
)
7113 start_pos
= IT_CHARPOS (*it
);
7115 /* Estimate how many newlines we must move back. */
7116 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7118 /* Set the iterator's position that many lines back. */
7119 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7120 back_to_previous_visible_line_start (it
);
7122 /* Reseat the iterator here. When moving backward, we don't want
7123 reseat to skip forward over invisible text, set up the iterator
7124 to deliver from overlay strings at the new position etc. So,
7125 use reseat_1 here. */
7126 reseat_1 (it
, it
->current
.pos
, 1);
7128 /* We are now surely at a line start. */
7129 it
->current_x
= it
->hpos
= 0;
7130 it
->continuation_lines_width
= 0;
7132 /* Move forward and see what y-distance we moved. First move to the
7133 start of the next line so that we get its height. We need this
7134 height to be able to tell whether we reached the specified
7137 it2
.max_ascent
= it2
.max_descent
= 0;
7140 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7141 MOVE_TO_POS
| MOVE_TO_VPOS
);
7143 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7144 xassert (IT_CHARPOS (*it
) >= BEGV
);
7147 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7148 xassert (IT_CHARPOS (*it
) >= BEGV
);
7149 /* H is the actual vertical distance from the position in *IT
7150 and the starting position. */
7151 h
= it2
.current_y
- it
->current_y
;
7152 /* NLINES is the distance in number of lines. */
7153 nlines
= it2
.vpos
- it
->vpos
;
7155 /* Correct IT's y and vpos position
7156 so that they are relative to the starting point. */
7162 /* DY == 0 means move to the start of the screen line. The
7163 value of nlines is > 0 if continuation lines were involved. */
7165 move_it_by_lines (it
, nlines
, 1);
7167 /* I think this assert is bogus if buffer contains
7168 invisible text or images. KFS. */
7169 xassert (IT_CHARPOS (*it
) <= start_pos
);
7174 /* The y-position we try to reach, relative to *IT.
7175 Note that H has been subtracted in front of the if-statement. */
7176 int target_y
= it
->current_y
+ h
- dy
;
7177 int y0
= it3
.current_y
;
7178 int y1
= line_bottom_y (&it3
);
7179 int line_height
= y1
- y0
;
7181 /* If we did not reach target_y, try to move further backward if
7182 we can. If we moved too far backward, try to move forward. */
7183 if (target_y
< it
->current_y
7184 /* This is heuristic. In a window that's 3 lines high, with
7185 a line height of 13 pixels each, recentering with point
7186 on the bottom line will try to move -39/2 = 19 pixels
7187 backward. Try to avoid moving into the first line. */
7188 && (it
->current_y
- target_y
7189 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7190 && IT_CHARPOS (*it
) > BEGV
)
7192 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7193 target_y
- it
->current_y
));
7194 dy
= it
->current_y
- target_y
;
7195 goto move_further_back
;
7197 else if (target_y
>= it
->current_y
+ line_height
7198 && IT_CHARPOS (*it
) < ZV
)
7200 /* Should move forward by at least one line, maybe more.
7202 Note: Calling move_it_by_lines can be expensive on
7203 terminal frames, where compute_motion is used (via
7204 vmotion) to do the job, when there are very long lines
7205 and truncate-lines is nil. That's the reason for
7206 treating terminal frames specially here. */
7208 if (!FRAME_WINDOW_P (it
->f
))
7209 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7214 move_it_by_lines (it
, 1, 1);
7216 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7220 /* I think this assert is bogus if buffer contains
7221 invisible text or images. KFS. */
7222 xassert (IT_CHARPOS (*it
) >= BEGV
);
7229 /* Move IT by a specified amount of pixel lines DY. DY negative means
7230 move backwards. DY = 0 means move to start of screen line. At the
7231 end, IT will be on the start of a screen line. */
7234 move_it_vertically (it
, dy
)
7239 move_it_vertically_backward (it
, -dy
);
7242 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7243 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7244 MOVE_TO_POS
| MOVE_TO_Y
);
7245 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7247 /* If buffer ends in ZV without a newline, move to the start of
7248 the line to satisfy the post-condition. */
7249 if (IT_CHARPOS (*it
) == ZV
7251 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7252 move_it_by_lines (it
, 0, 0);
7257 /* Move iterator IT past the end of the text line it is in. */
7260 move_it_past_eol (it
)
7263 enum move_it_result rc
;
7265 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7266 if (rc
== MOVE_NEWLINE_OR_CR
)
7267 set_iterator_to_next (it
, 0);
7271 #if 0 /* Currently not used. */
7273 /* Return non-zero if some text between buffer positions START_CHARPOS
7274 and END_CHARPOS is invisible. IT->window is the window for text
7278 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7280 int start_charpos
, end_charpos
;
7282 Lisp_Object prop
, limit
;
7283 int invisible_found_p
;
7285 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7287 /* Is text at START invisible? */
7288 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7290 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7291 invisible_found_p
= 1;
7294 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7296 make_number (end_charpos
));
7297 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7300 return invisible_found_p
;
7306 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7307 negative means move up. DVPOS == 0 means move to the start of the
7308 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7309 NEED_Y_P is zero, IT->current_y will be left unchanged.
7311 Further optimization ideas: If we would know that IT->f doesn't use
7312 a face with proportional font, we could be faster for
7313 truncate-lines nil. */
7316 move_it_by_lines (it
, dvpos
, need_y_p
)
7318 int dvpos
, need_y_p
;
7320 struct position pos
;
7322 /* The commented-out optimization uses vmotion on terminals. This
7323 gives bad results, because elements like it->what, on which
7324 callers such as pos_visible_p rely, aren't updated. */
7325 /* if (!FRAME_WINDOW_P (it->f))
7327 struct text_pos textpos;
7329 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7330 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7331 reseat (it, textpos, 1);
7332 it->vpos += pos.vpos;
7333 it->current_y += pos.vpos;
7339 /* DVPOS == 0 means move to the start of the screen line. */
7340 move_it_vertically_backward (it
, 0);
7341 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7342 /* Let next call to line_bottom_y calculate real line height */
7347 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7348 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7349 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7354 int start_charpos
, i
;
7356 /* Start at the beginning of the screen line containing IT's
7357 position. This may actually move vertically backwards,
7358 in case of overlays, so adjust dvpos accordingly. */
7360 move_it_vertically_backward (it
, 0);
7363 /* Go back -DVPOS visible lines and reseat the iterator there. */
7364 start_charpos
= IT_CHARPOS (*it
);
7365 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7366 back_to_previous_visible_line_start (it
);
7367 reseat (it
, it
->current
.pos
, 1);
7369 /* Move further back if we end up in a string or an image. */
7370 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7372 /* First try to move to start of display line. */
7374 move_it_vertically_backward (it
, 0);
7376 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7378 /* If start of line is still in string or image,
7379 move further back. */
7380 back_to_previous_visible_line_start (it
);
7381 reseat (it
, it
->current
.pos
, 1);
7385 it
->current_x
= it
->hpos
= 0;
7387 /* Above call may have moved too far if continuation lines
7388 are involved. Scan forward and see if it did. */
7390 it2
.vpos
= it2
.current_y
= 0;
7391 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7392 it
->vpos
-= it2
.vpos
;
7393 it
->current_y
-= it2
.current_y
;
7394 it
->current_x
= it
->hpos
= 0;
7396 /* If we moved too far back, move IT some lines forward. */
7397 if (it2
.vpos
> -dvpos
)
7399 int delta
= it2
.vpos
+ dvpos
;
7401 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7402 /* Move back again if we got too far ahead. */
7403 if (IT_CHARPOS (*it
) >= start_charpos
)
7409 /* Return 1 if IT points into the middle of a display vector. */
7412 in_display_vector_p (it
)
7415 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7416 && it
->current
.dpvec_index
> 0
7417 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7421 /***********************************************************************
7423 ***********************************************************************/
7426 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7430 add_to_log (format
, arg1
, arg2
)
7432 Lisp_Object arg1
, arg2
;
7434 Lisp_Object args
[3];
7435 Lisp_Object msg
, fmt
;
7438 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7441 /* Do nothing if called asynchronously. Inserting text into
7442 a buffer may call after-change-functions and alike and
7443 that would means running Lisp asynchronously. */
7444 if (handling_signal
)
7448 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7450 args
[0] = fmt
= build_string (format
);
7453 msg
= Fformat (3, args
);
7455 len
= SBYTES (msg
) + 1;
7456 SAFE_ALLOCA (buffer
, char *, len
);
7457 bcopy (SDATA (msg
), buffer
, len
);
7459 message_dolog (buffer
, len
- 1, 1, 0);
7466 /* Output a newline in the *Messages* buffer if "needs" one. */
7469 message_log_maybe_newline ()
7471 if (message_log_need_newline
)
7472 message_dolog ("", 0, 1, 0);
7476 /* Add a string M of length NBYTES to the message log, optionally
7477 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7478 nonzero, means interpret the contents of M as multibyte. This
7479 function calls low-level routines in order to bypass text property
7480 hooks, etc. which might not be safe to run.
7482 This may GC (insert may run before/after change hooks),
7483 so the buffer M must NOT point to a Lisp string. */
7486 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7488 int nbytes
, nlflag
, multibyte
;
7490 if (!NILP (Vmemory_full
))
7493 if (!NILP (Vmessage_log_max
))
7495 struct buffer
*oldbuf
;
7496 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7497 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7498 int point_at_end
= 0;
7500 Lisp_Object old_deactivate_mark
, tem
;
7501 struct gcpro gcpro1
;
7503 old_deactivate_mark
= Vdeactivate_mark
;
7504 oldbuf
= current_buffer
;
7505 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7506 current_buffer
->undo_list
= Qt
;
7508 oldpoint
= message_dolog_marker1
;
7509 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7510 oldbegv
= message_dolog_marker2
;
7511 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7512 oldzv
= message_dolog_marker3
;
7513 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7514 GCPRO1 (old_deactivate_mark
);
7522 BEGV_BYTE
= BEG_BYTE
;
7525 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7527 /* Insert the string--maybe converting multibyte to single byte
7528 or vice versa, so that all the text fits the buffer. */
7530 && NILP (current_buffer
->enable_multibyte_characters
))
7532 int i
, c
, char_bytes
;
7533 unsigned char work
[1];
7535 /* Convert a multibyte string to single-byte
7536 for the *Message* buffer. */
7537 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7539 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7540 work
[0] = (ASCII_CHAR_P (c
)
7542 : multibyte_char_to_unibyte (c
, Qnil
));
7543 insert_1_both (work
, 1, 1, 1, 0, 0);
7546 else if (! multibyte
7547 && ! NILP (current_buffer
->enable_multibyte_characters
))
7549 int i
, c
, char_bytes
;
7550 unsigned char *msg
= (unsigned char *) m
;
7551 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7552 /* Convert a single-byte string to multibyte
7553 for the *Message* buffer. */
7554 for (i
= 0; i
< nbytes
; i
++)
7557 c
= unibyte_char_to_multibyte (c
);
7558 char_bytes
= CHAR_STRING (c
, str
);
7559 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7563 insert_1 (m
, nbytes
, 1, 0, 0);
7567 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7568 insert_1 ("\n", 1, 1, 0, 0);
7570 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7572 this_bol_byte
= PT_BYTE
;
7574 /* See if this line duplicates the previous one.
7575 If so, combine duplicates. */
7578 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7580 prev_bol_byte
= PT_BYTE
;
7582 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7583 this_bol
, this_bol_byte
);
7586 del_range_both (prev_bol
, prev_bol_byte
,
7587 this_bol
, this_bol_byte
, 0);
7593 /* If you change this format, don't forget to also
7594 change message_log_check_duplicate. */
7595 sprintf (dupstr
, " [%d times]", dup
);
7596 duplen
= strlen (dupstr
);
7597 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7598 insert_1 (dupstr
, duplen
, 1, 0, 1);
7603 /* If we have more than the desired maximum number of lines
7604 in the *Messages* buffer now, delete the oldest ones.
7605 This is safe because we don't have undo in this buffer. */
7607 if (NATNUMP (Vmessage_log_max
))
7609 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7610 -XFASTINT (Vmessage_log_max
) - 1, 0);
7611 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7614 BEGV
= XMARKER (oldbegv
)->charpos
;
7615 BEGV_BYTE
= marker_byte_position (oldbegv
);
7624 ZV
= XMARKER (oldzv
)->charpos
;
7625 ZV_BYTE
= marker_byte_position (oldzv
);
7629 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7631 /* We can't do Fgoto_char (oldpoint) because it will run some
7633 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7634 XMARKER (oldpoint
)->bytepos
);
7637 unchain_marker (XMARKER (oldpoint
));
7638 unchain_marker (XMARKER (oldbegv
));
7639 unchain_marker (XMARKER (oldzv
));
7641 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7642 set_buffer_internal (oldbuf
);
7644 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7645 message_log_need_newline
= !nlflag
;
7646 Vdeactivate_mark
= old_deactivate_mark
;
7651 /* We are at the end of the buffer after just having inserted a newline.
7652 (Note: We depend on the fact we won't be crossing the gap.)
7653 Check to see if the most recent message looks a lot like the previous one.
7654 Return 0 if different, 1 if the new one should just replace it, or a
7655 value N > 1 if we should also append " [N times]". */
7658 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7659 int prev_bol
, this_bol
;
7660 int prev_bol_byte
, this_bol_byte
;
7663 int len
= Z_BYTE
- 1 - this_bol_byte
;
7665 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7666 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7668 for (i
= 0; i
< len
; i
++)
7670 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7678 if (*p1
++ == ' ' && *p1
++ == '[')
7681 while (*p1
>= '0' && *p1
<= '9')
7682 n
= n
* 10 + *p1
++ - '0';
7683 if (strncmp (p1
, " times]\n", 8) == 0)
7690 /* Display an echo area message M with a specified length of NBYTES
7691 bytes. The string may include null characters. If M is 0, clear
7692 out any existing message, and let the mini-buffer text show
7695 This may GC, so the buffer M must NOT point to a Lisp string. */
7698 message2 (m
, nbytes
, multibyte
)
7703 /* First flush out any partial line written with print. */
7704 message_log_maybe_newline ();
7706 message_dolog (m
, nbytes
, 1, multibyte
);
7707 message2_nolog (m
, nbytes
, multibyte
);
7711 /* The non-logging counterpart of message2. */
7714 message2_nolog (m
, nbytes
, multibyte
)
7716 int nbytes
, multibyte
;
7718 struct frame
*sf
= SELECTED_FRAME ();
7719 message_enable_multibyte
= multibyte
;
7723 if (noninteractive_need_newline
)
7724 putc ('\n', stderr
);
7725 noninteractive_need_newline
= 0;
7727 fwrite (m
, nbytes
, 1, stderr
);
7728 if (cursor_in_echo_area
== 0)
7729 fprintf (stderr
, "\n");
7732 /* A null message buffer means that the frame hasn't really been
7733 initialized yet. Error messages get reported properly by
7734 cmd_error, so this must be just an informative message; toss it. */
7735 else if (INTERACTIVE
7736 && sf
->glyphs_initialized_p
7737 && FRAME_MESSAGE_BUF (sf
))
7739 Lisp_Object mini_window
;
7742 /* Get the frame containing the mini-buffer
7743 that the selected frame is using. */
7744 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7745 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7747 FRAME_SAMPLE_VISIBILITY (f
);
7748 if (FRAME_VISIBLE_P (sf
)
7749 && ! FRAME_VISIBLE_P (f
))
7750 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7754 set_message (m
, Qnil
, nbytes
, multibyte
);
7755 if (minibuffer_auto_raise
)
7756 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7759 clear_message (1, 1);
7761 do_pending_window_change (0);
7762 echo_area_display (1);
7763 do_pending_window_change (0);
7764 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7765 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7770 /* Display an echo area message M with a specified length of NBYTES
7771 bytes. The string may include null characters. If M is not a
7772 string, clear out any existing message, and let the mini-buffer
7775 This function cancels echoing. */
7778 message3 (m
, nbytes
, multibyte
)
7783 struct gcpro gcpro1
;
7786 clear_message (1,1);
7789 /* First flush out any partial line written with print. */
7790 message_log_maybe_newline ();
7796 SAFE_ALLOCA (buffer
, char *, nbytes
);
7797 bcopy (SDATA (m
), buffer
, nbytes
);
7798 message_dolog (buffer
, nbytes
, 1, multibyte
);
7801 message3_nolog (m
, nbytes
, multibyte
);
7807 /* The non-logging version of message3.
7808 This does not cancel echoing, because it is used for echoing.
7809 Perhaps we need to make a separate function for echoing
7810 and make this cancel echoing. */
7813 message3_nolog (m
, nbytes
, multibyte
)
7815 int nbytes
, multibyte
;
7817 struct frame
*sf
= SELECTED_FRAME ();
7818 message_enable_multibyte
= multibyte
;
7822 if (noninteractive_need_newline
)
7823 putc ('\n', stderr
);
7824 noninteractive_need_newline
= 0;
7826 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7827 if (cursor_in_echo_area
== 0)
7828 fprintf (stderr
, "\n");
7831 /* A null message buffer means that the frame hasn't really been
7832 initialized yet. Error messages get reported properly by
7833 cmd_error, so this must be just an informative message; toss it. */
7834 else if (INTERACTIVE
7835 && sf
->glyphs_initialized_p
7836 && FRAME_MESSAGE_BUF (sf
))
7838 Lisp_Object mini_window
;
7842 /* Get the frame containing the mini-buffer
7843 that the selected frame is using. */
7844 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7845 frame
= XWINDOW (mini_window
)->frame
;
7848 FRAME_SAMPLE_VISIBILITY (f
);
7849 if (FRAME_VISIBLE_P (sf
)
7850 && !FRAME_VISIBLE_P (f
))
7851 Fmake_frame_visible (frame
);
7853 if (STRINGP (m
) && SCHARS (m
) > 0)
7855 set_message (NULL
, m
, nbytes
, multibyte
);
7856 if (minibuffer_auto_raise
)
7857 Fraise_frame (frame
);
7858 /* Assume we are not echoing.
7859 (If we are, echo_now will override this.) */
7860 echo_message_buffer
= Qnil
;
7863 clear_message (1, 1);
7865 do_pending_window_change (0);
7866 echo_area_display (1);
7867 do_pending_window_change (0);
7868 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7869 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7874 /* Display a null-terminated echo area message M. If M is 0, clear
7875 out any existing message, and let the mini-buffer text show through.
7877 The buffer M must continue to exist until after the echo area gets
7878 cleared or some other message gets displayed there. Do not pass
7879 text that is stored in a Lisp string. Do not pass text in a buffer
7880 that was alloca'd. */
7886 message2 (m
, (m
? strlen (m
) : 0), 0);
7890 /* The non-logging counterpart of message1. */
7896 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7899 /* Display a message M which contains a single %s
7900 which gets replaced with STRING. */
7903 message_with_string (m
, string
, log
)
7908 CHECK_STRING (string
);
7914 if (noninteractive_need_newline
)
7915 putc ('\n', stderr
);
7916 noninteractive_need_newline
= 0;
7917 fprintf (stderr
, m
, SDATA (string
));
7918 if (cursor_in_echo_area
== 0)
7919 fprintf (stderr
, "\n");
7923 else if (INTERACTIVE
)
7925 /* The frame whose minibuffer we're going to display the message on.
7926 It may be larger than the selected frame, so we need
7927 to use its buffer, not the selected frame's buffer. */
7928 Lisp_Object mini_window
;
7929 struct frame
*f
, *sf
= SELECTED_FRAME ();
7931 /* Get the frame containing the minibuffer
7932 that the selected frame is using. */
7933 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7934 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7936 /* A null message buffer means that the frame hasn't really been
7937 initialized yet. Error messages get reported properly by
7938 cmd_error, so this must be just an informative message; toss it. */
7939 if (FRAME_MESSAGE_BUF (f
))
7941 Lisp_Object args
[2], message
;
7942 struct gcpro gcpro1
, gcpro2
;
7944 args
[0] = build_string (m
);
7945 args
[1] = message
= string
;
7946 GCPRO2 (args
[0], message
);
7949 message
= Fformat (2, args
);
7952 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7954 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7958 /* Print should start at the beginning of the message
7959 buffer next time. */
7960 message_buf_print
= 0;
7966 /* Dump an informative message to the minibuf. If M is 0, clear out
7967 any existing message, and let the mini-buffer text show through. */
7971 message (m
, a1
, a2
, a3
)
7973 EMACS_INT a1
, a2
, a3
;
7979 if (noninteractive_need_newline
)
7980 putc ('\n', stderr
);
7981 noninteractive_need_newline
= 0;
7982 fprintf (stderr
, m
, a1
, a2
, a3
);
7983 if (cursor_in_echo_area
== 0)
7984 fprintf (stderr
, "\n");
7988 else if (INTERACTIVE
)
7990 /* The frame whose mini-buffer we're going to display the message
7991 on. It may be larger than the selected frame, so we need to
7992 use its buffer, not the selected frame's buffer. */
7993 Lisp_Object mini_window
;
7994 struct frame
*f
, *sf
= SELECTED_FRAME ();
7996 /* Get the frame containing the mini-buffer
7997 that the selected frame is using. */
7998 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7999 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8001 /* A null message buffer means that the frame hasn't really been
8002 initialized yet. Error messages get reported properly by
8003 cmd_error, so this must be just an informative message; toss
8005 if (FRAME_MESSAGE_BUF (f
))
8016 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8017 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8019 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8020 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8022 #endif /* NO_ARG_ARRAY */
8024 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8029 /* Print should start at the beginning of the message
8030 buffer next time. */
8031 message_buf_print
= 0;
8037 /* The non-logging version of message. */
8040 message_nolog (m
, a1
, a2
, a3
)
8042 EMACS_INT a1
, a2
, a3
;
8044 Lisp_Object old_log_max
;
8045 old_log_max
= Vmessage_log_max
;
8046 Vmessage_log_max
= Qnil
;
8047 message (m
, a1
, a2
, a3
);
8048 Vmessage_log_max
= old_log_max
;
8052 /* Display the current message in the current mini-buffer. This is
8053 only called from error handlers in process.c, and is not time
8059 if (!NILP (echo_area_buffer
[0]))
8062 string
= Fcurrent_message ();
8063 message3 (string
, SBYTES (string
),
8064 !NILP (current_buffer
->enable_multibyte_characters
));
8069 /* Make sure echo area buffers in `echo_buffers' are live.
8070 If they aren't, make new ones. */
8073 ensure_echo_area_buffers ()
8077 for (i
= 0; i
< 2; ++i
)
8078 if (!BUFFERP (echo_buffer
[i
])
8079 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8082 Lisp_Object old_buffer
;
8085 old_buffer
= echo_buffer
[i
];
8086 sprintf (name
, " *Echo Area %d*", i
);
8087 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8088 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8090 for (j
= 0; j
< 2; ++j
)
8091 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8092 echo_area_buffer
[j
] = echo_buffer
[i
];
8097 /* Call FN with args A1..A4 with either the current or last displayed
8098 echo_area_buffer as current buffer.
8100 WHICH zero means use the current message buffer
8101 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8102 from echo_buffer[] and clear it.
8104 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8105 suitable buffer from echo_buffer[] and clear it.
8107 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8108 that the current message becomes the last displayed one, make
8109 choose a suitable buffer for echo_area_buffer[0], and clear it.
8111 Value is what FN returns. */
8114 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8117 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8123 int this_one
, the_other
, clear_buffer_p
, rc
;
8124 int count
= SPECPDL_INDEX ();
8126 /* If buffers aren't live, make new ones. */
8127 ensure_echo_area_buffers ();
8132 this_one
= 0, the_other
= 1;
8134 this_one
= 1, the_other
= 0;
8137 this_one
= 0, the_other
= 1;
8140 /* We need a fresh one in case the current echo buffer equals
8141 the one containing the last displayed echo area message. */
8142 if (!NILP (echo_area_buffer
[this_one
])
8143 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8144 echo_area_buffer
[this_one
] = Qnil
;
8147 /* Choose a suitable buffer from echo_buffer[] is we don't
8149 if (NILP (echo_area_buffer
[this_one
]))
8151 echo_area_buffer
[this_one
]
8152 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8153 ? echo_buffer
[the_other
]
8154 : echo_buffer
[this_one
]);
8158 buffer
= echo_area_buffer
[this_one
];
8160 /* Don't get confused by reusing the buffer used for echoing
8161 for a different purpose. */
8162 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8165 record_unwind_protect (unwind_with_echo_area_buffer
,
8166 with_echo_area_buffer_unwind_data (w
));
8168 /* Make the echo area buffer current. Note that for display
8169 purposes, it is not necessary that the displayed window's buffer
8170 == current_buffer, except for text property lookup. So, let's
8171 only set that buffer temporarily here without doing a full
8172 Fset_window_buffer. We must also change w->pointm, though,
8173 because otherwise an assertions in unshow_buffer fails, and Emacs
8175 set_buffer_internal_1 (XBUFFER (buffer
));
8179 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8182 current_buffer
->undo_list
= Qt
;
8183 current_buffer
->read_only
= Qnil
;
8184 specbind (Qinhibit_read_only
, Qt
);
8185 specbind (Qinhibit_modification_hooks
, Qt
);
8187 if (clear_buffer_p
&& Z
> BEG
)
8190 xassert (BEGV
>= BEG
);
8191 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8193 rc
= fn (a1
, a2
, a3
, a4
);
8195 xassert (BEGV
>= BEG
);
8196 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8198 unbind_to (count
, Qnil
);
8203 /* Save state that should be preserved around the call to the function
8204 FN called in with_echo_area_buffer. */
8207 with_echo_area_buffer_unwind_data (w
)
8211 Lisp_Object vector
, tmp
;
8213 /* Reduce consing by keeping one vector in
8214 Vwith_echo_area_save_vector. */
8215 vector
= Vwith_echo_area_save_vector
;
8216 Vwith_echo_area_save_vector
= Qnil
;
8219 vector
= Fmake_vector (make_number (7), Qnil
);
8221 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8222 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8223 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8227 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8228 ASET (vector
, i
, w
->buffer
); ++i
;
8229 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8230 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8235 for (; i
< end
; ++i
)
8236 ASET (vector
, i
, Qnil
);
8239 xassert (i
== ASIZE (vector
));
8244 /* Restore global state from VECTOR which was created by
8245 with_echo_area_buffer_unwind_data. */
8248 unwind_with_echo_area_buffer (vector
)
8251 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8252 Vdeactivate_mark
= AREF (vector
, 1);
8253 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8255 if (WINDOWP (AREF (vector
, 3)))
8258 Lisp_Object buffer
, charpos
, bytepos
;
8260 w
= XWINDOW (AREF (vector
, 3));
8261 buffer
= AREF (vector
, 4);
8262 charpos
= AREF (vector
, 5);
8263 bytepos
= AREF (vector
, 6);
8266 set_marker_both (w
->pointm
, buffer
,
8267 XFASTINT (charpos
), XFASTINT (bytepos
));
8270 Vwith_echo_area_save_vector
= vector
;
8275 /* Set up the echo area for use by print functions. MULTIBYTE_P
8276 non-zero means we will print multibyte. */
8279 setup_echo_area_for_printing (multibyte_p
)
8282 /* If we can't find an echo area any more, exit. */
8283 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8286 ensure_echo_area_buffers ();
8288 if (!message_buf_print
)
8290 /* A message has been output since the last time we printed.
8291 Choose a fresh echo area buffer. */
8292 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8293 echo_area_buffer
[0] = echo_buffer
[1];
8295 echo_area_buffer
[0] = echo_buffer
[0];
8297 /* Switch to that buffer and clear it. */
8298 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8299 current_buffer
->truncate_lines
= Qnil
;
8303 int count
= SPECPDL_INDEX ();
8304 specbind (Qinhibit_read_only
, Qt
);
8305 /* Note that undo recording is always disabled. */
8307 unbind_to (count
, Qnil
);
8309 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8311 /* Set up the buffer for the multibyteness we need. */
8313 != !NILP (current_buffer
->enable_multibyte_characters
))
8314 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8316 /* Raise the frame containing the echo area. */
8317 if (minibuffer_auto_raise
)
8319 struct frame
*sf
= SELECTED_FRAME ();
8320 Lisp_Object mini_window
;
8321 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8322 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8325 message_log_maybe_newline ();
8326 message_buf_print
= 1;
8330 if (NILP (echo_area_buffer
[0]))
8332 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8333 echo_area_buffer
[0] = echo_buffer
[1];
8335 echo_area_buffer
[0] = echo_buffer
[0];
8338 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8340 /* Someone switched buffers between print requests. */
8341 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8342 current_buffer
->truncate_lines
= Qnil
;
8348 /* Display an echo area message in window W. Value is non-zero if W's
8349 height is changed. If display_last_displayed_message_p is
8350 non-zero, display the message that was last displayed, otherwise
8351 display the current message. */
8354 display_echo_area (w
)
8357 int i
, no_message_p
, window_height_changed_p
, count
;
8359 /* Temporarily disable garbage collections while displaying the echo
8360 area. This is done because a GC can print a message itself.
8361 That message would modify the echo area buffer's contents while a
8362 redisplay of the buffer is going on, and seriously confuse
8364 count
= inhibit_garbage_collection ();
8366 /* If there is no message, we must call display_echo_area_1
8367 nevertheless because it resizes the window. But we will have to
8368 reset the echo_area_buffer in question to nil at the end because
8369 with_echo_area_buffer will sets it to an empty buffer. */
8370 i
= display_last_displayed_message_p
? 1 : 0;
8371 no_message_p
= NILP (echo_area_buffer
[i
]);
8373 window_height_changed_p
8374 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8375 display_echo_area_1
,
8376 (EMACS_INT
) w
, Qnil
, 0, 0);
8379 echo_area_buffer
[i
] = Qnil
;
8381 unbind_to (count
, Qnil
);
8382 return window_height_changed_p
;
8386 /* Helper for display_echo_area. Display the current buffer which
8387 contains the current echo area message in window W, a mini-window,
8388 a pointer to which is passed in A1. A2..A4 are currently not used.
8389 Change the height of W so that all of the message is displayed.
8390 Value is non-zero if height of W was changed. */
8393 display_echo_area_1 (a1
, a2
, a3
, a4
)
8398 struct window
*w
= (struct window
*) a1
;
8400 struct text_pos start
;
8401 int window_height_changed_p
= 0;
8403 /* Do this before displaying, so that we have a large enough glyph
8404 matrix for the display. If we can't get enough space for the
8405 whole text, display the last N lines. That works by setting w->start. */
8406 window_height_changed_p
= resize_mini_window (w
, 0);
8408 /* Use the starting position chosen by resize_mini_window. */
8409 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8412 clear_glyph_matrix (w
->desired_matrix
);
8413 XSETWINDOW (window
, w
);
8414 try_window (window
, start
, 0);
8416 return window_height_changed_p
;
8420 /* Resize the echo area window to exactly the size needed for the
8421 currently displayed message, if there is one. If a mini-buffer
8422 is active, don't shrink it. */
8425 resize_echo_area_exactly ()
8427 if (BUFFERP (echo_area_buffer
[0])
8428 && WINDOWP (echo_area_window
))
8430 struct window
*w
= XWINDOW (echo_area_window
);
8432 Lisp_Object resize_exactly
;
8434 if (minibuf_level
== 0)
8435 resize_exactly
= Qt
;
8437 resize_exactly
= Qnil
;
8439 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8440 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8443 ++windows_or_buffers_changed
;
8444 ++update_mode_lines
;
8445 redisplay_internal (0);
8451 /* Callback function for with_echo_area_buffer, when used from
8452 resize_echo_area_exactly. A1 contains a pointer to the window to
8453 resize, EXACTLY non-nil means resize the mini-window exactly to the
8454 size of the text displayed. A3 and A4 are not used. Value is what
8455 resize_mini_window returns. */
8458 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8460 Lisp_Object exactly
;
8463 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8467 /* Resize mini-window W to fit the size of its contents. EXACT_P
8468 means size the window exactly to the size needed. Otherwise, it's
8469 only enlarged until W's buffer is empty.
8471 Set W->start to the right place to begin display. If the whole
8472 contents fit, start at the beginning. Otherwise, start so as
8473 to make the end of the contents appear. This is particularly
8474 important for y-or-n-p, but seems desirable generally.
8476 Value is non-zero if the window height has been changed. */
8479 resize_mini_window (w
, exact_p
)
8483 struct frame
*f
= XFRAME (w
->frame
);
8484 int window_height_changed_p
= 0;
8486 xassert (MINI_WINDOW_P (w
));
8488 /* By default, start display at the beginning. */
8489 set_marker_both (w
->start
, w
->buffer
,
8490 BUF_BEGV (XBUFFER (w
->buffer
)),
8491 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8493 /* Don't resize windows while redisplaying a window; it would
8494 confuse redisplay functions when the size of the window they are
8495 displaying changes from under them. Such a resizing can happen,
8496 for instance, when which-func prints a long message while
8497 we are running fontification-functions. We're running these
8498 functions with safe_call which binds inhibit-redisplay to t. */
8499 if (!NILP (Vinhibit_redisplay
))
8502 /* Nil means don't try to resize. */
8503 if (NILP (Vresize_mini_windows
)
8504 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8507 if (!FRAME_MINIBUF_ONLY_P (f
))
8510 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8511 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8512 int height
, max_height
;
8513 int unit
= FRAME_LINE_HEIGHT (f
);
8514 struct text_pos start
;
8515 struct buffer
*old_current_buffer
= NULL
;
8517 if (current_buffer
!= XBUFFER (w
->buffer
))
8519 old_current_buffer
= current_buffer
;
8520 set_buffer_internal (XBUFFER (w
->buffer
));
8523 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8525 /* Compute the max. number of lines specified by the user. */
8526 if (FLOATP (Vmax_mini_window_height
))
8527 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8528 else if (INTEGERP (Vmax_mini_window_height
))
8529 max_height
= XINT (Vmax_mini_window_height
);
8531 max_height
= total_height
/ 4;
8533 /* Correct that max. height if it's bogus. */
8534 max_height
= max (1, max_height
);
8535 max_height
= min (total_height
, max_height
);
8537 /* Find out the height of the text in the window. */
8538 if (it
.truncate_lines_p
)
8543 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8544 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8545 height
= it
.current_y
+ last_height
;
8547 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8548 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8549 height
= (height
+ unit
- 1) / unit
;
8552 /* Compute a suitable window start. */
8553 if (height
> max_height
)
8555 height
= max_height
;
8556 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8557 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8558 start
= it
.current
.pos
;
8561 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8562 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8564 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8566 /* Let it grow only, until we display an empty message, in which
8567 case the window shrinks again. */
8568 if (height
> WINDOW_TOTAL_LINES (w
))
8570 int old_height
= WINDOW_TOTAL_LINES (w
);
8571 freeze_window_starts (f
, 1);
8572 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8573 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8575 else if (height
< WINDOW_TOTAL_LINES (w
)
8576 && (exact_p
|| BEGV
== ZV
))
8578 int old_height
= WINDOW_TOTAL_LINES (w
);
8579 freeze_window_starts (f
, 0);
8580 shrink_mini_window (w
);
8581 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8586 /* Always resize to exact size needed. */
8587 if (height
> WINDOW_TOTAL_LINES (w
))
8589 int old_height
= WINDOW_TOTAL_LINES (w
);
8590 freeze_window_starts (f
, 1);
8591 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8592 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8594 else if (height
< WINDOW_TOTAL_LINES (w
))
8596 int old_height
= WINDOW_TOTAL_LINES (w
);
8597 freeze_window_starts (f
, 0);
8598 shrink_mini_window (w
);
8602 freeze_window_starts (f
, 1);
8603 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8606 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8610 if (old_current_buffer
)
8611 set_buffer_internal (old_current_buffer
);
8614 return window_height_changed_p
;
8618 /* Value is the current message, a string, or nil if there is no
8626 if (!BUFFERP (echo_area_buffer
[0]))
8630 with_echo_area_buffer (0, 0, current_message_1
,
8631 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8633 echo_area_buffer
[0] = Qnil
;
8641 current_message_1 (a1
, a2
, a3
, a4
)
8646 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8649 *msg
= make_buffer_string (BEG
, Z
, 1);
8656 /* Push the current message on Vmessage_stack for later restauration
8657 by restore_message. Value is non-zero if the current message isn't
8658 empty. This is a relatively infrequent operation, so it's not
8659 worth optimizing. */
8665 msg
= current_message ();
8666 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8667 return STRINGP (msg
);
8671 /* Restore message display from the top of Vmessage_stack. */
8678 xassert (CONSP (Vmessage_stack
));
8679 msg
= XCAR (Vmessage_stack
);
8681 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8683 message3_nolog (msg
, 0, 0);
8687 /* Handler for record_unwind_protect calling pop_message. */
8690 pop_message_unwind (dummy
)
8697 /* Pop the top-most entry off Vmessage_stack. */
8702 xassert (CONSP (Vmessage_stack
));
8703 Vmessage_stack
= XCDR (Vmessage_stack
);
8707 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8708 exits. If the stack is not empty, we have a missing pop_message
8712 check_message_stack ()
8714 if (!NILP (Vmessage_stack
))
8719 /* Truncate to NCHARS what will be displayed in the echo area the next
8720 time we display it---but don't redisplay it now. */
8723 truncate_echo_area (nchars
)
8727 echo_area_buffer
[0] = Qnil
;
8728 /* A null message buffer means that the frame hasn't really been
8729 initialized yet. Error messages get reported properly by
8730 cmd_error, so this must be just an informative message; toss it. */
8731 else if (!noninteractive
8733 && !NILP (echo_area_buffer
[0]))
8735 struct frame
*sf
= SELECTED_FRAME ();
8736 if (FRAME_MESSAGE_BUF (sf
))
8737 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8742 /* Helper function for truncate_echo_area. Truncate the current
8743 message to at most NCHARS characters. */
8746 truncate_message_1 (nchars
, a2
, a3
, a4
)
8751 if (BEG
+ nchars
< Z
)
8752 del_range (BEG
+ nchars
, Z
);
8754 echo_area_buffer
[0] = Qnil
;
8759 /* Set the current message to a substring of S or STRING.
8761 If STRING is a Lisp string, set the message to the first NBYTES
8762 bytes from STRING. NBYTES zero means use the whole string. If
8763 STRING is multibyte, the message will be displayed multibyte.
8765 If S is not null, set the message to the first LEN bytes of S. LEN
8766 zero means use the whole string. MULTIBYTE_P non-zero means S is
8767 multibyte. Display the message multibyte in that case.
8769 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8770 to t before calling set_message_1 (which calls insert).
8774 set_message (s
, string
, nbytes
, multibyte_p
)
8777 int nbytes
, multibyte_p
;
8779 message_enable_multibyte
8780 = ((s
&& multibyte_p
)
8781 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8783 with_echo_area_buffer (0, -1, set_message_1
,
8784 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8785 message_buf_print
= 0;
8786 help_echo_showing_p
= 0;
8790 /* Helper function for set_message. Arguments have the same meaning
8791 as there, with A1 corresponding to S and A2 corresponding to STRING
8792 This function is called with the echo area buffer being
8796 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8799 EMACS_INT nbytes
, multibyte_p
;
8801 const char *s
= (const char *) a1
;
8802 Lisp_Object string
= a2
;
8804 /* Change multibyteness of the echo buffer appropriately. */
8805 if (message_enable_multibyte
8806 != !NILP (current_buffer
->enable_multibyte_characters
))
8807 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8809 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8811 /* Insert new message at BEG. */
8812 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8814 if (STRINGP (string
))
8819 nbytes
= SBYTES (string
);
8820 nchars
= string_byte_to_char (string
, nbytes
);
8822 /* This function takes care of single/multibyte conversion. We
8823 just have to ensure that the echo area buffer has the right
8824 setting of enable_multibyte_characters. */
8825 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8830 nbytes
= strlen (s
);
8832 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8834 /* Convert from multi-byte to single-byte. */
8836 unsigned char work
[1];
8838 /* Convert a multibyte string to single-byte. */
8839 for (i
= 0; i
< nbytes
; i
+= n
)
8841 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8842 work
[0] = (ASCII_CHAR_P (c
)
8844 : multibyte_char_to_unibyte (c
, Qnil
));
8845 insert_1_both (work
, 1, 1, 1, 0, 0);
8848 else if (!multibyte_p
8849 && !NILP (current_buffer
->enable_multibyte_characters
))
8851 /* Convert from single-byte to multi-byte. */
8853 const unsigned char *msg
= (const unsigned char *) s
;
8854 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8856 /* Convert a single-byte string to multibyte. */
8857 for (i
= 0; i
< nbytes
; i
++)
8860 c
= unibyte_char_to_multibyte (c
);
8861 n
= CHAR_STRING (c
, str
);
8862 insert_1_both (str
, 1, n
, 1, 0, 0);
8866 insert_1 (s
, nbytes
, 1, 0, 0);
8873 /* Clear messages. CURRENT_P non-zero means clear the current
8874 message. LAST_DISPLAYED_P non-zero means clear the message
8878 clear_message (current_p
, last_displayed_p
)
8879 int current_p
, last_displayed_p
;
8883 echo_area_buffer
[0] = Qnil
;
8884 message_cleared_p
= 1;
8887 if (last_displayed_p
)
8888 echo_area_buffer
[1] = Qnil
;
8890 message_buf_print
= 0;
8893 /* Clear garbaged frames.
8895 This function is used where the old redisplay called
8896 redraw_garbaged_frames which in turn called redraw_frame which in
8897 turn called clear_frame. The call to clear_frame was a source of
8898 flickering. I believe a clear_frame is not necessary. It should
8899 suffice in the new redisplay to invalidate all current matrices,
8900 and ensure a complete redisplay of all windows. */
8903 clear_garbaged_frames ()
8907 Lisp_Object tail
, frame
;
8908 int changed_count
= 0;
8910 FOR_EACH_FRAME (tail
, frame
)
8912 struct frame
*f
= XFRAME (frame
);
8914 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8918 Fredraw_frame (frame
);
8919 f
->force_flush_display_p
= 1;
8921 clear_current_matrices (f
);
8930 ++windows_or_buffers_changed
;
8935 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8936 is non-zero update selected_frame. Value is non-zero if the
8937 mini-windows height has been changed. */
8940 echo_area_display (update_frame_p
)
8943 Lisp_Object mini_window
;
8946 int window_height_changed_p
= 0;
8947 struct frame
*sf
= SELECTED_FRAME ();
8949 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8950 w
= XWINDOW (mini_window
);
8951 f
= XFRAME (WINDOW_FRAME (w
));
8953 /* Don't display if frame is invisible or not yet initialized. */
8954 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8957 #ifdef HAVE_WINDOW_SYSTEM
8958 /* When Emacs starts, selected_frame may be the initial terminal
8959 frame. If we let this through, a message would be displayed on
8961 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
8963 #endif /* HAVE_WINDOW_SYSTEM */
8965 /* Redraw garbaged frames. */
8967 clear_garbaged_frames ();
8969 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8971 echo_area_window
= mini_window
;
8972 window_height_changed_p
= display_echo_area (w
);
8973 w
->must_be_updated_p
= 1;
8975 /* Update the display, unless called from redisplay_internal.
8976 Also don't update the screen during redisplay itself. The
8977 update will happen at the end of redisplay, and an update
8978 here could cause confusion. */
8979 if (update_frame_p
&& !redisplaying_p
)
8983 /* If the display update has been interrupted by pending
8984 input, update mode lines in the frame. Due to the
8985 pending input, it might have been that redisplay hasn't
8986 been called, so that mode lines above the echo area are
8987 garbaged. This looks odd, so we prevent it here. */
8988 if (!display_completed
)
8989 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8991 if (window_height_changed_p
8992 /* Don't do this if Emacs is shutting down. Redisplay
8993 needs to run hooks. */
8994 && !NILP (Vrun_hooks
))
8996 /* Must update other windows. Likewise as in other
8997 cases, don't let this update be interrupted by
8999 int count
= SPECPDL_INDEX ();
9000 specbind (Qredisplay_dont_pause
, Qt
);
9001 windows_or_buffers_changed
= 1;
9002 redisplay_internal (0);
9003 unbind_to (count
, Qnil
);
9005 else if (FRAME_WINDOW_P (f
) && n
== 0)
9007 /* Window configuration is the same as before.
9008 Can do with a display update of the echo area,
9009 unless we displayed some mode lines. */
9010 update_single_window (w
, 1);
9011 FRAME_RIF (f
)->flush_display (f
);
9014 update_frame (f
, 1, 1);
9016 /* If cursor is in the echo area, make sure that the next
9017 redisplay displays the minibuffer, so that the cursor will
9018 be replaced with what the minibuffer wants. */
9019 if (cursor_in_echo_area
)
9020 ++windows_or_buffers_changed
;
9023 else if (!EQ (mini_window
, selected_window
))
9024 windows_or_buffers_changed
++;
9026 /* Last displayed message is now the current message. */
9027 echo_area_buffer
[1] = echo_area_buffer
[0];
9028 /* Inform read_char that we're not echoing. */
9029 echo_message_buffer
= Qnil
;
9031 /* Prevent redisplay optimization in redisplay_internal by resetting
9032 this_line_start_pos. This is done because the mini-buffer now
9033 displays the message instead of its buffer text. */
9034 if (EQ (mini_window
, selected_window
))
9035 CHARPOS (this_line_start_pos
) = 0;
9037 return window_height_changed_p
;
9042 /***********************************************************************
9043 Mode Lines and Frame Titles
9044 ***********************************************************************/
9046 /* A buffer for constructing non-propertized mode-line strings and
9047 frame titles in it; allocated from the heap in init_xdisp and
9048 resized as needed in store_mode_line_noprop_char. */
9050 static char *mode_line_noprop_buf
;
9052 /* The buffer's end, and a current output position in it. */
9054 static char *mode_line_noprop_buf_end
;
9055 static char *mode_line_noprop_ptr
;
9057 #define MODE_LINE_NOPROP_LEN(start) \
9058 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9061 MODE_LINE_DISPLAY
= 0,
9067 /* Alist that caches the results of :propertize.
9068 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9069 static Lisp_Object mode_line_proptrans_alist
;
9071 /* List of strings making up the mode-line. */
9072 static Lisp_Object mode_line_string_list
;
9074 /* Base face property when building propertized mode line string. */
9075 static Lisp_Object mode_line_string_face
;
9076 static Lisp_Object mode_line_string_face_prop
;
9079 /* Unwind data for mode line strings */
9081 static Lisp_Object Vmode_line_unwind_vector
;
9084 format_mode_line_unwind_data (struct buffer
*obuf
,
9088 Lisp_Object vector
, tmp
;
9090 /* Reduce consing by keeping one vector in
9091 Vwith_echo_area_save_vector. */
9092 vector
= Vmode_line_unwind_vector
;
9093 Vmode_line_unwind_vector
= Qnil
;
9096 vector
= Fmake_vector (make_number (8), Qnil
);
9098 ASET (vector
, 0, make_number (mode_line_target
));
9099 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9100 ASET (vector
, 2, mode_line_string_list
);
9101 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9102 ASET (vector
, 4, mode_line_string_face
);
9103 ASET (vector
, 5, mode_line_string_face_prop
);
9106 XSETBUFFER (tmp
, obuf
);
9109 ASET (vector
, 6, tmp
);
9110 ASET (vector
, 7, owin
);
9116 unwind_format_mode_line (vector
)
9119 mode_line_target
= XINT (AREF (vector
, 0));
9120 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9121 mode_line_string_list
= AREF (vector
, 2);
9122 if (! EQ (AREF (vector
, 3), Qt
))
9123 mode_line_proptrans_alist
= AREF (vector
, 3);
9124 mode_line_string_face
= AREF (vector
, 4);
9125 mode_line_string_face_prop
= AREF (vector
, 5);
9127 if (!NILP (AREF (vector
, 7)))
9128 /* Select window before buffer, since it may change the buffer. */
9129 Fselect_window (AREF (vector
, 7), Qt
);
9131 if (!NILP (AREF (vector
, 6)))
9133 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9134 ASET (vector
, 6, Qnil
);
9137 Vmode_line_unwind_vector
= vector
;
9142 /* Store a single character C for the frame title in mode_line_noprop_buf.
9143 Re-allocate mode_line_noprop_buf if necessary. */
9147 store_mode_line_noprop_char (char c
)
9149 store_mode_line_noprop_char (c
)
9153 /* If output position has reached the end of the allocated buffer,
9154 double the buffer's size. */
9155 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9157 int len
= MODE_LINE_NOPROP_LEN (0);
9158 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9159 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9160 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9161 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9164 *mode_line_noprop_ptr
++ = c
;
9168 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9169 mode_line_noprop_ptr. STR is the string to store. Do not copy
9170 characters that yield more columns than PRECISION; PRECISION <= 0
9171 means copy the whole string. Pad with spaces until FIELD_WIDTH
9172 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9173 pad. Called from display_mode_element when it is used to build a
9177 store_mode_line_noprop (str
, field_width
, precision
)
9178 const unsigned char *str
;
9179 int field_width
, precision
;
9184 /* Copy at most PRECISION chars from STR. */
9185 nbytes
= strlen (str
);
9186 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9188 store_mode_line_noprop_char (*str
++);
9190 /* Fill up with spaces until FIELD_WIDTH reached. */
9191 while (field_width
> 0
9194 store_mode_line_noprop_char (' ');
9201 /***********************************************************************
9203 ***********************************************************************/
9205 #ifdef HAVE_WINDOW_SYSTEM
9207 /* Set the title of FRAME, if it has changed. The title format is
9208 Vicon_title_format if FRAME is iconified, otherwise it is
9209 frame_title_format. */
9212 x_consider_frame_title (frame
)
9215 struct frame
*f
= XFRAME (frame
);
9217 if (FRAME_WINDOW_P (f
)
9218 || FRAME_MINIBUF_ONLY_P (f
)
9219 || f
->explicit_name
)
9221 /* Do we have more than one visible frame on this X display? */
9228 int count
= SPECPDL_INDEX ();
9230 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9232 Lisp_Object other_frame
= XCAR (tail
);
9233 struct frame
*tf
= XFRAME (other_frame
);
9236 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9237 && !FRAME_MINIBUF_ONLY_P (tf
)
9238 && !EQ (other_frame
, tip_frame
)
9239 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9243 /* Set global variable indicating that multiple frames exist. */
9244 multiple_frames
= CONSP (tail
);
9246 /* Switch to the buffer of selected window of the frame. Set up
9247 mode_line_target so that display_mode_element will output into
9248 mode_line_noprop_buf; then display the title. */
9249 record_unwind_protect (unwind_format_mode_line
,
9250 format_mode_line_unwind_data
9251 (current_buffer
, selected_window
, 0));
9253 Fselect_window (f
->selected_window
, Qt
);
9254 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9255 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9257 mode_line_target
= MODE_LINE_TITLE
;
9258 title_start
= MODE_LINE_NOPROP_LEN (0);
9259 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9260 NULL
, DEFAULT_FACE_ID
);
9261 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9262 len
= MODE_LINE_NOPROP_LEN (title_start
);
9263 title
= mode_line_noprop_buf
+ title_start
;
9264 unbind_to (count
, Qnil
);
9266 /* Set the title only if it's changed. This avoids consing in
9267 the common case where it hasn't. (If it turns out that we've
9268 already wasted too much time by walking through the list with
9269 display_mode_element, then we might need to optimize at a
9270 higher level than this.) */
9271 if (! STRINGP (f
->name
)
9272 || SBYTES (f
->name
) != len
9273 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9274 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9278 #endif /* not HAVE_WINDOW_SYSTEM */
9283 /***********************************************************************
9285 ***********************************************************************/
9288 /* Prepare for redisplay by updating menu-bar item lists when
9289 appropriate. This can call eval. */
9292 prepare_menu_bars ()
9295 struct gcpro gcpro1
, gcpro2
;
9297 Lisp_Object tooltip_frame
;
9299 #ifdef HAVE_WINDOW_SYSTEM
9300 tooltip_frame
= tip_frame
;
9302 tooltip_frame
= Qnil
;
9305 /* Update all frame titles based on their buffer names, etc. We do
9306 this before the menu bars so that the buffer-menu will show the
9307 up-to-date frame titles. */
9308 #ifdef HAVE_WINDOW_SYSTEM
9309 if (windows_or_buffers_changed
|| update_mode_lines
)
9311 Lisp_Object tail
, frame
;
9313 FOR_EACH_FRAME (tail
, frame
)
9316 if (!EQ (frame
, tooltip_frame
)
9317 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9318 x_consider_frame_title (frame
);
9321 #endif /* HAVE_WINDOW_SYSTEM */
9323 /* Update the menu bar item lists, if appropriate. This has to be
9324 done before any actual redisplay or generation of display lines. */
9325 all_windows
= (update_mode_lines
9326 || buffer_shared
> 1
9327 || windows_or_buffers_changed
);
9330 Lisp_Object tail
, frame
;
9331 int count
= SPECPDL_INDEX ();
9332 /* 1 means that update_menu_bar has run its hooks
9333 so any further calls to update_menu_bar shouldn't do so again. */
9334 int menu_bar_hooks_run
= 0;
9336 record_unwind_save_match_data ();
9338 FOR_EACH_FRAME (tail
, frame
)
9342 /* Ignore tooltip frame. */
9343 if (EQ (frame
, tooltip_frame
))
9346 /* If a window on this frame changed size, report that to
9347 the user and clear the size-change flag. */
9348 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9350 Lisp_Object functions
;
9352 /* Clear flag first in case we get an error below. */
9353 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9354 functions
= Vwindow_size_change_functions
;
9355 GCPRO2 (tail
, functions
);
9357 while (CONSP (functions
))
9359 call1 (XCAR (functions
), frame
);
9360 functions
= XCDR (functions
);
9366 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9367 #ifdef HAVE_WINDOW_SYSTEM
9368 update_tool_bar (f
, 0);
9370 mac_update_title_bar (f
, 0);
9376 unbind_to (count
, Qnil
);
9380 struct frame
*sf
= SELECTED_FRAME ();
9381 update_menu_bar (sf
, 1, 0);
9382 #ifdef HAVE_WINDOW_SYSTEM
9383 update_tool_bar (sf
, 1);
9385 mac_update_title_bar (sf
, 1);
9390 /* Motif needs this. See comment in xmenu.c. Turn it off when
9391 pending_menu_activation is not defined. */
9392 #ifdef USE_X_TOOLKIT
9393 pending_menu_activation
= 0;
9398 /* Update the menu bar item list for frame F. This has to be done
9399 before we start to fill in any display lines, because it can call
9402 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9404 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9405 already ran the menu bar hooks for this redisplay, so there
9406 is no need to run them again. The return value is the
9407 updated value of this flag, to pass to the next call. */
9410 update_menu_bar (f
, save_match_data
, hooks_run
)
9412 int save_match_data
;
9416 register struct window
*w
;
9418 /* If called recursively during a menu update, do nothing. This can
9419 happen when, for instance, an activate-menubar-hook causes a
9421 if (inhibit_menubar_update
)
9424 window
= FRAME_SELECTED_WINDOW (f
);
9425 w
= XWINDOW (window
);
9427 #if 0 /* The if statement below this if statement used to include the
9428 condition !NILP (w->update_mode_line), rather than using
9429 update_mode_lines directly, and this if statement may have
9430 been added to make that condition work. Now the if
9431 statement below matches its comment, this isn't needed. */
9432 if (update_mode_lines
)
9433 w
->update_mode_line
= Qt
;
9436 if (FRAME_WINDOW_P (f
)
9438 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9439 || defined (USE_GTK)
9440 FRAME_EXTERNAL_MENU_BAR (f
)
9442 FRAME_MENU_BAR_LINES (f
) > 0
9444 : FRAME_MENU_BAR_LINES (f
) > 0)
9446 /* If the user has switched buffers or windows, we need to
9447 recompute to reflect the new bindings. But we'll
9448 recompute when update_mode_lines is set too; that means
9449 that people can use force-mode-line-update to request
9450 that the menu bar be recomputed. The adverse effect on
9451 the rest of the redisplay algorithm is about the same as
9452 windows_or_buffers_changed anyway. */
9453 if (windows_or_buffers_changed
9454 /* This used to test w->update_mode_line, but we believe
9455 there is no need to recompute the menu in that case. */
9456 || update_mode_lines
9457 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9458 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9459 != !NILP (w
->last_had_star
))
9460 || ((!NILP (Vtransient_mark_mode
)
9461 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9462 != !NILP (w
->region_showing
)))
9464 struct buffer
*prev
= current_buffer
;
9465 int count
= SPECPDL_INDEX ();
9467 specbind (Qinhibit_menubar_update
, Qt
);
9469 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9470 if (save_match_data
)
9471 record_unwind_save_match_data ();
9472 if (NILP (Voverriding_local_map_menu_flag
))
9474 specbind (Qoverriding_terminal_local_map
, Qnil
);
9475 specbind (Qoverriding_local_map
, Qnil
);
9480 /* Run the Lucid hook. */
9481 safe_run_hooks (Qactivate_menubar_hook
);
9483 /* If it has changed current-menubar from previous value,
9484 really recompute the menu-bar from the value. */
9485 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9486 call0 (Qrecompute_lucid_menubar
);
9488 safe_run_hooks (Qmenu_bar_update_hook
);
9493 XSETFRAME (Vmenu_updating_frame
, f
);
9494 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9496 /* Redisplay the menu bar in case we changed it. */
9497 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9498 || defined (USE_GTK)
9499 if (FRAME_WINDOW_P (f
))
9502 /* All frames on Mac OS share the same menubar. So only
9503 the selected frame should be allowed to set it. */
9504 if (f
== SELECTED_FRAME ())
9506 set_frame_menubar (f
, 0, 0);
9509 /* On a terminal screen, the menu bar is an ordinary screen
9510 line, and this makes it get updated. */
9511 w
->update_mode_line
= Qt
;
9512 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9513 /* In the non-toolkit version, the menu bar is an ordinary screen
9514 line, and this makes it get updated. */
9515 w
->update_mode_line
= Qt
;
9516 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9518 unbind_to (count
, Qnil
);
9519 set_buffer_internal_1 (prev
);
9528 /***********************************************************************
9530 ***********************************************************************/
9532 #ifdef HAVE_WINDOW_SYSTEM
9535 Nominal cursor position -- where to draw output.
9536 HPOS and VPOS are window relative glyph matrix coordinates.
9537 X and Y are window relative pixel coordinates. */
9539 struct cursor_pos output_cursor
;
9543 Set the global variable output_cursor to CURSOR. All cursor
9544 positions are relative to updated_window. */
9547 set_output_cursor (cursor
)
9548 struct cursor_pos
*cursor
;
9550 output_cursor
.hpos
= cursor
->hpos
;
9551 output_cursor
.vpos
= cursor
->vpos
;
9552 output_cursor
.x
= cursor
->x
;
9553 output_cursor
.y
= cursor
->y
;
9558 Set a nominal cursor position.
9560 HPOS and VPOS are column/row positions in a window glyph matrix. X
9561 and Y are window text area relative pixel positions.
9563 If this is done during an update, updated_window will contain the
9564 window that is being updated and the position is the future output
9565 cursor position for that window. If updated_window is null, use
9566 selected_window and display the cursor at the given position. */
9569 x_cursor_to (vpos
, hpos
, y
, x
)
9570 int vpos
, hpos
, y
, x
;
9574 /* If updated_window is not set, work on selected_window. */
9578 w
= XWINDOW (selected_window
);
9580 /* Set the output cursor. */
9581 output_cursor
.hpos
= hpos
;
9582 output_cursor
.vpos
= vpos
;
9583 output_cursor
.x
= x
;
9584 output_cursor
.y
= y
;
9586 /* If not called as part of an update, really display the cursor.
9587 This will also set the cursor position of W. */
9588 if (updated_window
== NULL
)
9591 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9592 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9593 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9598 #endif /* HAVE_WINDOW_SYSTEM */
9601 /***********************************************************************
9603 ***********************************************************************/
9605 #ifdef HAVE_WINDOW_SYSTEM
9607 /* Where the mouse was last time we reported a mouse event. */
9609 FRAME_PTR last_mouse_frame
;
9611 /* Tool-bar item index of the item on which a mouse button was pressed
9614 int last_tool_bar_item
;
9617 /* Update the tool-bar item list for frame F. This has to be done
9618 before we start to fill in any display lines. Called from
9619 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9620 and restore it here. */
9623 update_tool_bar (f
, save_match_data
)
9625 int save_match_data
;
9627 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9628 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9630 int do_update
= WINDOWP (f
->tool_bar_window
)
9631 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9639 window
= FRAME_SELECTED_WINDOW (f
);
9640 w
= XWINDOW (window
);
9642 /* If the user has switched buffers or windows, we need to
9643 recompute to reflect the new bindings. But we'll
9644 recompute when update_mode_lines is set too; that means
9645 that people can use force-mode-line-update to request
9646 that the menu bar be recomputed. The adverse effect on
9647 the rest of the redisplay algorithm is about the same as
9648 windows_or_buffers_changed anyway. */
9649 if (windows_or_buffers_changed
9650 || !NILP (w
->update_mode_line
)
9651 || update_mode_lines
9652 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9653 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9654 != !NILP (w
->last_had_star
))
9655 || ((!NILP (Vtransient_mark_mode
)
9656 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9657 != !NILP (w
->region_showing
)))
9659 struct buffer
*prev
= current_buffer
;
9660 int count
= SPECPDL_INDEX ();
9661 Lisp_Object new_tool_bar
;
9663 struct gcpro gcpro1
;
9665 /* Set current_buffer to the buffer of the selected
9666 window of the frame, so that we get the right local
9668 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9670 /* Save match data, if we must. */
9671 if (save_match_data
)
9672 record_unwind_save_match_data ();
9674 /* Make sure that we don't accidentally use bogus keymaps. */
9675 if (NILP (Voverriding_local_map_menu_flag
))
9677 specbind (Qoverriding_terminal_local_map
, Qnil
);
9678 specbind (Qoverriding_local_map
, Qnil
);
9681 GCPRO1 (new_tool_bar
);
9683 /* Build desired tool-bar items from keymaps. */
9684 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9687 /* Redisplay the tool-bar if we changed it. */
9688 if (new_n_tool_bar
!= f
->n_tool_bar_items
9689 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9691 /* Redisplay that happens asynchronously due to an expose event
9692 may access f->tool_bar_items. Make sure we update both
9693 variables within BLOCK_INPUT so no such event interrupts. */
9695 f
->tool_bar_items
= new_tool_bar
;
9696 f
->n_tool_bar_items
= new_n_tool_bar
;
9697 w
->update_mode_line
= Qt
;
9703 unbind_to (count
, Qnil
);
9704 set_buffer_internal_1 (prev
);
9710 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9711 F's desired tool-bar contents. F->tool_bar_items must have
9712 been set up previously by calling prepare_menu_bars. */
9715 build_desired_tool_bar_string (f
)
9718 int i
, size
, size_needed
;
9719 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9720 Lisp_Object image
, plist
, props
;
9722 image
= plist
= props
= Qnil
;
9723 GCPRO3 (image
, plist
, props
);
9725 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9726 Otherwise, make a new string. */
9728 /* The size of the string we might be able to reuse. */
9729 size
= (STRINGP (f
->desired_tool_bar_string
)
9730 ? SCHARS (f
->desired_tool_bar_string
)
9733 /* We need one space in the string for each image. */
9734 size_needed
= f
->n_tool_bar_items
;
9736 /* Reuse f->desired_tool_bar_string, if possible. */
9737 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9738 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9742 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9743 Fremove_text_properties (make_number (0), make_number (size
),
9744 props
, f
->desired_tool_bar_string
);
9747 /* Put a `display' property on the string for the images to display,
9748 put a `menu_item' property on tool-bar items with a value that
9749 is the index of the item in F's tool-bar item vector. */
9750 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9752 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9754 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9755 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9756 int hmargin
, vmargin
, relief
, idx
, end
;
9757 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9759 /* If image is a vector, choose the image according to the
9761 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9762 if (VECTORP (image
))
9766 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9767 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9770 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9771 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9773 xassert (ASIZE (image
) >= idx
);
9774 image
= AREF (image
, idx
);
9779 /* Ignore invalid image specifications. */
9780 if (!valid_image_p (image
))
9783 /* Display the tool-bar button pressed, or depressed. */
9784 plist
= Fcopy_sequence (XCDR (image
));
9786 /* Compute margin and relief to draw. */
9787 relief
= (tool_bar_button_relief
>= 0
9788 ? tool_bar_button_relief
9789 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9790 hmargin
= vmargin
= relief
;
9792 if (INTEGERP (Vtool_bar_button_margin
)
9793 && XINT (Vtool_bar_button_margin
) > 0)
9795 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9796 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9798 else if (CONSP (Vtool_bar_button_margin
))
9800 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9801 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9802 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9804 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9805 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9806 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9809 if (auto_raise_tool_bar_buttons_p
)
9811 /* Add a `:relief' property to the image spec if the item is
9815 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9822 /* If image is selected, display it pressed, i.e. with a
9823 negative relief. If it's not selected, display it with a
9825 plist
= Fplist_put (plist
, QCrelief
,
9827 ? make_number (-relief
)
9828 : make_number (relief
)));
9833 /* Put a margin around the image. */
9834 if (hmargin
|| vmargin
)
9836 if (hmargin
== vmargin
)
9837 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9839 plist
= Fplist_put (plist
, QCmargin
,
9840 Fcons (make_number (hmargin
),
9841 make_number (vmargin
)));
9844 /* If button is not enabled, and we don't have special images
9845 for the disabled state, make the image appear disabled by
9846 applying an appropriate algorithm to it. */
9847 if (!enabled_p
&& idx
< 0)
9848 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9850 /* Put a `display' text property on the string for the image to
9851 display. Put a `menu-item' property on the string that gives
9852 the start of this item's properties in the tool-bar items
9854 image
= Fcons (Qimage
, plist
);
9855 props
= list4 (Qdisplay
, image
,
9856 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9858 /* Let the last image hide all remaining spaces in the tool bar
9859 string. The string can be longer than needed when we reuse a
9861 if (i
+ 1 == f
->n_tool_bar_items
)
9862 end
= SCHARS (f
->desired_tool_bar_string
);
9865 Fadd_text_properties (make_number (i
), make_number (end
),
9866 props
, f
->desired_tool_bar_string
);
9874 /* Display one line of the tool-bar of frame IT->f.
9876 HEIGHT specifies the desired height of the tool-bar line.
9877 If the actual height of the glyph row is less than HEIGHT, the
9878 row's height is increased to HEIGHT, and the icons are centered
9879 vertically in the new height.
9881 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9882 count a final empty row in case the tool-bar width exactly matches
9887 display_tool_bar_line (it
, height
)
9891 struct glyph_row
*row
= it
->glyph_row
;
9892 int max_x
= it
->last_visible_x
;
9895 prepare_desired_row (row
);
9896 row
->y
= it
->current_y
;
9898 /* Note that this isn't made use of if the face hasn't a box,
9899 so there's no need to check the face here. */
9900 it
->start_of_box_run_p
= 1;
9902 while (it
->current_x
< max_x
)
9904 int x
, n_glyphs_before
, i
, nglyphs
;
9905 struct it it_before
;
9907 /* Get the next display element. */
9908 if (!get_next_display_element (it
))
9910 /* Don't count empty row if we are counting needed tool-bar lines. */
9911 if (height
< 0 && !it
->hpos
)
9916 /* Produce glyphs. */
9917 n_glyphs_before
= row
->used
[TEXT_AREA
];
9920 PRODUCE_GLYPHS (it
);
9922 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9924 x
= it_before
.current_x
;
9927 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9929 if (x
+ glyph
->pixel_width
> max_x
)
9931 /* Glyph doesn't fit on line. Backtrack. */
9932 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9934 /* If this is the only glyph on this line, it will never fit on the
9935 toolbar, so skip it. But ensure there is at least one glyph,
9936 so we don't accidentally disable the tool-bar. */
9937 if (n_glyphs_before
== 0
9938 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9944 x
+= glyph
->pixel_width
;
9948 /* Stop at line ends. */
9949 if (ITERATOR_AT_END_OF_LINE_P (it
))
9952 set_iterator_to_next (it
, 1);
9957 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9959 /* Use default face for the border below the tool bar.
9961 FIXME: When auto-resize-tool-bars is grow-only, there is
9962 no additional border below the possibly empty tool-bar lines.
9963 So to make the extra empty lines look "normal", we have to
9964 use the tool-bar face for the border too. */
9965 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
9966 it
->face_id
= DEFAULT_FACE_ID
;
9968 extend_face_to_end_of_line (it
);
9969 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9970 last
->right_box_line_p
= 1;
9971 if (last
== row
->glyphs
[TEXT_AREA
])
9972 last
->left_box_line_p
= 1;
9974 /* Make line the desired height and center it vertically. */
9975 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9977 /* Don't add more than one line height. */
9978 height
%= FRAME_LINE_HEIGHT (it
->f
);
9979 it
->max_ascent
+= height
/ 2;
9980 it
->max_descent
+= (height
+ 1) / 2;
9983 compute_line_metrics (it
);
9985 /* If line is empty, make it occupy the rest of the tool-bar. */
9986 if (!row
->displays_text_p
)
9988 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9989 row
->visible_height
= row
->height
;
9990 row
->ascent
= row
->phys_ascent
= 0;
9991 row
->extra_line_spacing
= 0;
9994 row
->full_width_p
= 1;
9995 row
->continued_p
= 0;
9996 row
->truncated_on_left_p
= 0;
9997 row
->truncated_on_right_p
= 0;
9999 it
->current_x
= it
->hpos
= 0;
10000 it
->current_y
+= row
->height
;
10006 /* Max tool-bar height. */
10008 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10009 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10011 /* Value is the number of screen lines needed to make all tool-bar
10012 items of frame F visible. The number of actual rows needed is
10013 returned in *N_ROWS if non-NULL. */
10016 tool_bar_lines_needed (f
, n_rows
)
10020 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10022 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10023 the desired matrix, so use (unused) mode-line row as temporary row to
10024 avoid destroying the first tool-bar row. */
10025 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10027 /* Initialize an iterator for iteration over
10028 F->desired_tool_bar_string in the tool-bar window of frame F. */
10029 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10030 it
.first_visible_x
= 0;
10031 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10032 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10034 while (!ITERATOR_AT_END_P (&it
))
10036 clear_glyph_row (temp_row
);
10037 it
.glyph_row
= temp_row
;
10038 display_tool_bar_line (&it
, -1);
10040 clear_glyph_row (temp_row
);
10042 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10044 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10046 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10050 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10052 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10061 frame
= selected_frame
;
10063 CHECK_FRAME (frame
);
10064 f
= XFRAME (frame
);
10066 if (WINDOWP (f
->tool_bar_window
)
10067 || (w
= XWINDOW (f
->tool_bar_window
),
10068 WINDOW_TOTAL_LINES (w
) > 0))
10070 update_tool_bar (f
, 1);
10071 if (f
->n_tool_bar_items
)
10073 build_desired_tool_bar_string (f
);
10074 nlines
= tool_bar_lines_needed (f
, NULL
);
10078 return make_number (nlines
);
10082 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10083 height should be changed. */
10086 redisplay_tool_bar (f
)
10091 struct glyph_row
*row
;
10093 #if defined (USE_GTK) || USE_MAC_TOOLBAR
10094 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10095 update_frame_tool_bar (f
);
10099 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10100 do anything. This means you must start with tool-bar-lines
10101 non-zero to get the auto-sizing effect. Or in other words, you
10102 can turn off tool-bars by specifying tool-bar-lines zero. */
10103 if (!WINDOWP (f
->tool_bar_window
)
10104 || (w
= XWINDOW (f
->tool_bar_window
),
10105 WINDOW_TOTAL_LINES (w
) == 0))
10108 /* Set up an iterator for the tool-bar window. */
10109 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10110 it
.first_visible_x
= 0;
10111 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10112 row
= it
.glyph_row
;
10114 /* Build a string that represents the contents of the tool-bar. */
10115 build_desired_tool_bar_string (f
);
10116 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10118 if (f
->n_tool_bar_rows
== 0)
10122 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10123 nlines
!= WINDOW_TOTAL_LINES (w
)))
10125 extern Lisp_Object Qtool_bar_lines
;
10127 int old_height
= WINDOW_TOTAL_LINES (w
);
10129 XSETFRAME (frame
, f
);
10130 Fmodify_frame_parameters (frame
,
10131 Fcons (Fcons (Qtool_bar_lines
,
10132 make_number (nlines
)),
10134 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10136 clear_glyph_matrix (w
->desired_matrix
);
10137 fonts_changed_p
= 1;
10143 /* Display as many lines as needed to display all tool-bar items. */
10145 if (f
->n_tool_bar_rows
> 0)
10147 int border
, rows
, height
, extra
;
10149 if (INTEGERP (Vtool_bar_border
))
10150 border
= XINT (Vtool_bar_border
);
10151 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10152 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10153 else if (EQ (Vtool_bar_border
, Qborder_width
))
10154 border
= f
->border_width
;
10160 rows
= f
->n_tool_bar_rows
;
10161 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10162 extra
= it
.last_visible_y
- border
- height
* rows
;
10164 while (it
.current_y
< it
.last_visible_y
)
10167 if (extra
> 0 && rows
-- > 0)
10169 h
= (extra
+ rows
- 1) / rows
;
10172 display_tool_bar_line (&it
, height
+ h
);
10177 while (it
.current_y
< it
.last_visible_y
)
10178 display_tool_bar_line (&it
, 0);
10181 /* It doesn't make much sense to try scrolling in the tool-bar
10182 window, so don't do it. */
10183 w
->desired_matrix
->no_scrolling_p
= 1;
10184 w
->must_be_updated_p
= 1;
10186 if (!NILP (Vauto_resize_tool_bars
))
10188 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10189 int change_height_p
= 0;
10191 /* If we couldn't display everything, change the tool-bar's
10192 height if there is room for more. */
10193 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10194 && it
.current_y
< max_tool_bar_height
)
10195 change_height_p
= 1;
10197 row
= it
.glyph_row
- 1;
10199 /* If there are blank lines at the end, except for a partially
10200 visible blank line at the end that is smaller than
10201 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10202 if (!row
->displays_text_p
10203 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10204 change_height_p
= 1;
10206 /* If row displays tool-bar items, but is partially visible,
10207 change the tool-bar's height. */
10208 if (row
->displays_text_p
10209 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10210 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10211 change_height_p
= 1;
10213 /* Resize windows as needed by changing the `tool-bar-lines'
10214 frame parameter. */
10215 if (change_height_p
)
10217 extern Lisp_Object Qtool_bar_lines
;
10219 int old_height
= WINDOW_TOTAL_LINES (w
);
10221 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10223 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10224 && !f
->minimize_tool_bar_window_p
)
10225 ? (nlines
> old_height
)
10226 : (nlines
!= old_height
));
10227 f
->minimize_tool_bar_window_p
= 0;
10229 if (change_height_p
)
10231 XSETFRAME (frame
, f
);
10232 Fmodify_frame_parameters (frame
,
10233 Fcons (Fcons (Qtool_bar_lines
,
10234 make_number (nlines
)),
10236 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10238 clear_glyph_matrix (w
->desired_matrix
);
10239 f
->n_tool_bar_rows
= nrows
;
10240 fonts_changed_p
= 1;
10247 f
->minimize_tool_bar_window_p
= 0;
10252 /* Get information about the tool-bar item which is displayed in GLYPH
10253 on frame F. Return in *PROP_IDX the index where tool-bar item
10254 properties start in F->tool_bar_items. Value is zero if
10255 GLYPH doesn't display a tool-bar item. */
10258 tool_bar_item_info (f
, glyph
, prop_idx
)
10260 struct glyph
*glyph
;
10267 /* This function can be called asynchronously, which means we must
10268 exclude any possibility that Fget_text_property signals an
10270 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10271 charpos
= max (0, charpos
);
10273 /* Get the text property `menu-item' at pos. The value of that
10274 property is the start index of this item's properties in
10275 F->tool_bar_items. */
10276 prop
= Fget_text_property (make_number (charpos
),
10277 Qmenu_item
, f
->current_tool_bar_string
);
10278 if (INTEGERP (prop
))
10280 *prop_idx
= XINT (prop
);
10290 /* Get information about the tool-bar item at position X/Y on frame F.
10291 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10292 the current matrix of the tool-bar window of F, or NULL if not
10293 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10294 item in F->tool_bar_items. Value is
10296 -1 if X/Y is not on a tool-bar item
10297 0 if X/Y is on the same item that was highlighted before.
10301 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10304 struct glyph
**glyph
;
10305 int *hpos
, *vpos
, *prop_idx
;
10307 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10308 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10311 /* Find the glyph under X/Y. */
10312 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10313 if (*glyph
== NULL
)
10316 /* Get the start of this tool-bar item's properties in
10317 f->tool_bar_items. */
10318 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10321 /* Is mouse on the highlighted item? */
10322 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10323 && *vpos
>= dpyinfo
->mouse_face_beg_row
10324 && *vpos
<= dpyinfo
->mouse_face_end_row
10325 && (*vpos
> dpyinfo
->mouse_face_beg_row
10326 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10327 && (*vpos
< dpyinfo
->mouse_face_end_row
10328 || *hpos
< dpyinfo
->mouse_face_end_col
10329 || dpyinfo
->mouse_face_past_end
))
10337 Handle mouse button event on the tool-bar of frame F, at
10338 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10339 0 for button release. MODIFIERS is event modifiers for button
10343 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10346 unsigned int modifiers
;
10348 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10349 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10350 int hpos
, vpos
, prop_idx
;
10351 struct glyph
*glyph
;
10352 Lisp_Object enabled_p
;
10354 /* If not on the highlighted tool-bar item, return. */
10355 frame_to_window_pixel_xy (w
, &x
, &y
);
10356 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10359 /* If item is disabled, do nothing. */
10360 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10361 if (NILP (enabled_p
))
10366 /* Show item in pressed state. */
10367 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10368 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10369 last_tool_bar_item
= prop_idx
;
10373 Lisp_Object key
, frame
;
10374 struct input_event event
;
10375 EVENT_INIT (event
);
10377 /* Show item in released state. */
10378 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10379 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10381 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10383 XSETFRAME (frame
, f
);
10384 event
.kind
= TOOL_BAR_EVENT
;
10385 event
.frame_or_window
= frame
;
10387 kbd_buffer_store_event (&event
);
10389 event
.kind
= TOOL_BAR_EVENT
;
10390 event
.frame_or_window
= frame
;
10392 event
.modifiers
= modifiers
;
10393 kbd_buffer_store_event (&event
);
10394 last_tool_bar_item
= -1;
10399 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10400 tool-bar window-relative coordinates X/Y. Called from
10401 note_mouse_highlight. */
10404 note_tool_bar_highlight (f
, x
, y
)
10408 Lisp_Object window
= f
->tool_bar_window
;
10409 struct window
*w
= XWINDOW (window
);
10410 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10412 struct glyph
*glyph
;
10413 struct glyph_row
*row
;
10415 Lisp_Object enabled_p
;
10417 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10418 int mouse_down_p
, rc
;
10420 /* Function note_mouse_highlight is called with negative x(y
10421 values when mouse moves outside of the frame. */
10422 if (x
<= 0 || y
<= 0)
10424 clear_mouse_face (dpyinfo
);
10428 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10431 /* Not on tool-bar item. */
10432 clear_mouse_face (dpyinfo
);
10436 /* On same tool-bar item as before. */
10437 goto set_help_echo
;
10439 clear_mouse_face (dpyinfo
);
10441 /* Mouse is down, but on different tool-bar item? */
10442 mouse_down_p
= (dpyinfo
->grabbed
10443 && f
== last_mouse_frame
10444 && FRAME_LIVE_P (f
));
10446 && last_tool_bar_item
!= prop_idx
)
10449 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10450 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10452 /* If tool-bar item is not enabled, don't highlight it. */
10453 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10454 if (!NILP (enabled_p
))
10456 /* Compute the x-position of the glyph. In front and past the
10457 image is a space. We include this in the highlighted area. */
10458 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10459 for (i
= x
= 0; i
< hpos
; ++i
)
10460 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10462 /* Record this as the current active region. */
10463 dpyinfo
->mouse_face_beg_col
= hpos
;
10464 dpyinfo
->mouse_face_beg_row
= vpos
;
10465 dpyinfo
->mouse_face_beg_x
= x
;
10466 dpyinfo
->mouse_face_beg_y
= row
->y
;
10467 dpyinfo
->mouse_face_past_end
= 0;
10469 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10470 dpyinfo
->mouse_face_end_row
= vpos
;
10471 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10472 dpyinfo
->mouse_face_end_y
= row
->y
;
10473 dpyinfo
->mouse_face_window
= window
;
10474 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10476 /* Display it as active. */
10477 show_mouse_face (dpyinfo
, draw
);
10478 dpyinfo
->mouse_face_image_state
= draw
;
10483 /* Set help_echo_string to a help string to display for this tool-bar item.
10484 XTread_socket does the rest. */
10485 help_echo_object
= help_echo_window
= Qnil
;
10486 help_echo_pos
= -1;
10487 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10488 if (NILP (help_echo_string
))
10489 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10492 #endif /* HAVE_WINDOW_SYSTEM */
10496 /************************************************************************
10497 Horizontal scrolling
10498 ************************************************************************/
10500 static int hscroll_window_tree
P_ ((Lisp_Object
));
10501 static int hscroll_windows
P_ ((Lisp_Object
));
10503 /* For all leaf windows in the window tree rooted at WINDOW, set their
10504 hscroll value so that PT is (i) visible in the window, and (ii) so
10505 that it is not within a certain margin at the window's left and
10506 right border. Value is non-zero if any window's hscroll has been
10510 hscroll_window_tree (window
)
10511 Lisp_Object window
;
10513 int hscrolled_p
= 0;
10514 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10515 int hscroll_step_abs
= 0;
10516 double hscroll_step_rel
= 0;
10518 if (hscroll_relative_p
)
10520 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10521 if (hscroll_step_rel
< 0)
10523 hscroll_relative_p
= 0;
10524 hscroll_step_abs
= 0;
10527 else if (INTEGERP (Vhscroll_step
))
10529 hscroll_step_abs
= XINT (Vhscroll_step
);
10530 if (hscroll_step_abs
< 0)
10531 hscroll_step_abs
= 0;
10534 hscroll_step_abs
= 0;
10536 while (WINDOWP (window
))
10538 struct window
*w
= XWINDOW (window
);
10540 if (WINDOWP (w
->hchild
))
10541 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10542 else if (WINDOWP (w
->vchild
))
10543 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10544 else if (w
->cursor
.vpos
>= 0)
10547 int text_area_width
;
10548 struct glyph_row
*current_cursor_row
10549 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10550 struct glyph_row
*desired_cursor_row
10551 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10552 struct glyph_row
*cursor_row
10553 = (desired_cursor_row
->enabled_p
10554 ? desired_cursor_row
10555 : current_cursor_row
);
10557 text_area_width
= window_box_width (w
, TEXT_AREA
);
10559 /* Scroll when cursor is inside this scroll margin. */
10560 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10562 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10563 && ((XFASTINT (w
->hscroll
)
10564 && w
->cursor
.x
<= h_margin
)
10565 || (cursor_row
->enabled_p
10566 && cursor_row
->truncated_on_right_p
10567 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10571 struct buffer
*saved_current_buffer
;
10575 /* Find point in a display of infinite width. */
10576 saved_current_buffer
= current_buffer
;
10577 current_buffer
= XBUFFER (w
->buffer
);
10579 if (w
== XWINDOW (selected_window
))
10580 pt
= BUF_PT (current_buffer
);
10583 pt
= marker_position (w
->pointm
);
10584 pt
= max (BEGV
, pt
);
10588 /* Move iterator to pt starting at cursor_row->start in
10589 a line with infinite width. */
10590 init_to_row_start (&it
, w
, cursor_row
);
10591 it
.last_visible_x
= INFINITY
;
10592 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10593 current_buffer
= saved_current_buffer
;
10595 /* Position cursor in window. */
10596 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10597 hscroll
= max (0, (it
.current_x
10598 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10599 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10600 : (text_area_width
/ 2))))
10601 / FRAME_COLUMN_WIDTH (it
.f
);
10602 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10604 if (hscroll_relative_p
)
10605 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10608 wanted_x
= text_area_width
10609 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10612 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10616 if (hscroll_relative_p
)
10617 wanted_x
= text_area_width
* hscroll_step_rel
10620 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10623 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10625 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10627 /* Don't call Fset_window_hscroll if value hasn't
10628 changed because it will prevent redisplay
10630 if (XFASTINT (w
->hscroll
) != hscroll
)
10632 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10633 w
->hscroll
= make_number (hscroll
);
10642 /* Value is non-zero if hscroll of any leaf window has been changed. */
10643 return hscrolled_p
;
10647 /* Set hscroll so that cursor is visible and not inside horizontal
10648 scroll margins for all windows in the tree rooted at WINDOW. See
10649 also hscroll_window_tree above. Value is non-zero if any window's
10650 hscroll has been changed. If it has, desired matrices on the frame
10651 of WINDOW are cleared. */
10654 hscroll_windows (window
)
10655 Lisp_Object window
;
10657 int hscrolled_p
= hscroll_window_tree (window
);
10659 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10660 return hscrolled_p
;
10665 /************************************************************************
10667 ************************************************************************/
10669 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10670 to a non-zero value. This is sometimes handy to have in a debugger
10675 /* First and last unchanged row for try_window_id. */
10677 int debug_first_unchanged_at_end_vpos
;
10678 int debug_last_unchanged_at_beg_vpos
;
10680 /* Delta vpos and y. */
10682 int debug_dvpos
, debug_dy
;
10684 /* Delta in characters and bytes for try_window_id. */
10686 int debug_delta
, debug_delta_bytes
;
10688 /* Values of window_end_pos and window_end_vpos at the end of
10691 EMACS_INT debug_end_pos
, debug_end_vpos
;
10693 /* Append a string to W->desired_matrix->method. FMT is a printf
10694 format string. A1...A9 are a supplement for a variable-length
10695 argument list. If trace_redisplay_p is non-zero also printf the
10696 resulting string to stderr. */
10699 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10702 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10705 char *method
= w
->desired_matrix
->method
;
10706 int len
= strlen (method
);
10707 int size
= sizeof w
->desired_matrix
->method
;
10708 int remaining
= size
- len
- 1;
10710 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10711 if (len
&& remaining
)
10714 --remaining
, ++len
;
10717 strncpy (method
+ len
, buffer
, remaining
);
10719 if (trace_redisplay_p
)
10720 fprintf (stderr
, "%p (%s): %s\n",
10722 ((BUFFERP (w
->buffer
)
10723 && STRINGP (XBUFFER (w
->buffer
)->name
))
10724 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10729 #endif /* GLYPH_DEBUG */
10732 /* Value is non-zero if all changes in window W, which displays
10733 current_buffer, are in the text between START and END. START is a
10734 buffer position, END is given as a distance from Z. Used in
10735 redisplay_internal for display optimization. */
10738 text_outside_line_unchanged_p (w
, start
, end
)
10742 int unchanged_p
= 1;
10744 /* If text or overlays have changed, see where. */
10745 if (XFASTINT (w
->last_modified
) < MODIFF
10746 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10748 /* Gap in the line? */
10749 if (GPT
< start
|| Z
- GPT
< end
)
10752 /* Changes start in front of the line, or end after it? */
10754 && (BEG_UNCHANGED
< start
- 1
10755 || END_UNCHANGED
< end
))
10758 /* If selective display, can't optimize if changes start at the
10759 beginning of the line. */
10761 && INTEGERP (current_buffer
->selective_display
)
10762 && XINT (current_buffer
->selective_display
) > 0
10763 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10766 /* If there are overlays at the start or end of the line, these
10767 may have overlay strings with newlines in them. A change at
10768 START, for instance, may actually concern the display of such
10769 overlay strings as well, and they are displayed on different
10770 lines. So, quickly rule out this case. (For the future, it
10771 might be desirable to implement something more telling than
10772 just BEG/END_UNCHANGED.) */
10775 if (BEG
+ BEG_UNCHANGED
== start
10776 && overlay_touches_p (start
))
10778 if (END_UNCHANGED
== end
10779 && overlay_touches_p (Z
- end
))
10784 return unchanged_p
;
10788 /* Do a frame update, taking possible shortcuts into account. This is
10789 the main external entry point for redisplay.
10791 If the last redisplay displayed an echo area message and that message
10792 is no longer requested, we clear the echo area or bring back the
10793 mini-buffer if that is in use. */
10798 redisplay_internal (0);
10803 overlay_arrow_string_or_property (var
)
10808 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10811 return Voverlay_arrow_string
;
10814 /* Return 1 if there are any overlay-arrows in current_buffer. */
10816 overlay_arrow_in_current_buffer_p ()
10820 for (vlist
= Voverlay_arrow_variable_list
;
10822 vlist
= XCDR (vlist
))
10824 Lisp_Object var
= XCAR (vlist
);
10827 if (!SYMBOLP (var
))
10829 val
= find_symbol_value (var
);
10831 && current_buffer
== XMARKER (val
)->buffer
)
10838 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10842 overlay_arrows_changed_p ()
10846 for (vlist
= Voverlay_arrow_variable_list
;
10848 vlist
= XCDR (vlist
))
10850 Lisp_Object var
= XCAR (vlist
);
10851 Lisp_Object val
, pstr
;
10853 if (!SYMBOLP (var
))
10855 val
= find_symbol_value (var
);
10856 if (!MARKERP (val
))
10858 if (! EQ (COERCE_MARKER (val
),
10859 Fget (var
, Qlast_arrow_position
))
10860 || ! (pstr
= overlay_arrow_string_or_property (var
),
10861 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10867 /* Mark overlay arrows to be updated on next redisplay. */
10870 update_overlay_arrows (up_to_date
)
10875 for (vlist
= Voverlay_arrow_variable_list
;
10877 vlist
= XCDR (vlist
))
10879 Lisp_Object var
= XCAR (vlist
);
10881 if (!SYMBOLP (var
))
10884 if (up_to_date
> 0)
10886 Lisp_Object val
= find_symbol_value (var
);
10887 Fput (var
, Qlast_arrow_position
,
10888 COERCE_MARKER (val
));
10889 Fput (var
, Qlast_arrow_string
,
10890 overlay_arrow_string_or_property (var
));
10892 else if (up_to_date
< 0
10893 || !NILP (Fget (var
, Qlast_arrow_position
)))
10895 Fput (var
, Qlast_arrow_position
, Qt
);
10896 Fput (var
, Qlast_arrow_string
, Qt
);
10902 /* Return overlay arrow string to display at row.
10903 Return integer (bitmap number) for arrow bitmap in left fringe.
10904 Return nil if no overlay arrow. */
10907 overlay_arrow_at_row (it
, row
)
10909 struct glyph_row
*row
;
10913 for (vlist
= Voverlay_arrow_variable_list
;
10915 vlist
= XCDR (vlist
))
10917 Lisp_Object var
= XCAR (vlist
);
10920 if (!SYMBOLP (var
))
10923 val
= find_symbol_value (var
);
10926 && current_buffer
== XMARKER (val
)->buffer
10927 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10929 if (FRAME_WINDOW_P (it
->f
)
10930 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10932 #ifdef HAVE_WINDOW_SYSTEM
10933 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10936 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10937 return make_number (fringe_bitmap
);
10940 return make_number (-1); /* Use default arrow bitmap */
10942 return overlay_arrow_string_or_property (var
);
10949 /* Return 1 if point moved out of or into a composition. Otherwise
10950 return 0. PREV_BUF and PREV_PT are the last point buffer and
10951 position. BUF and PT are the current point buffer and position. */
10954 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10955 struct buffer
*prev_buf
, *buf
;
10958 EMACS_INT start
, end
;
10960 Lisp_Object buffer
;
10962 XSETBUFFER (buffer
, buf
);
10963 /* Check a composition at the last point if point moved within the
10965 if (prev_buf
== buf
)
10968 /* Point didn't move. */
10971 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10972 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10973 && COMPOSITION_VALID_P (start
, end
, prop
)
10974 && start
< prev_pt
&& end
> prev_pt
)
10975 /* The last point was within the composition. Return 1 iff
10976 point moved out of the composition. */
10977 return (pt
<= start
|| pt
>= end
);
10980 /* Check a composition at the current point. */
10981 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10982 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10983 && COMPOSITION_VALID_P (start
, end
, prop
)
10984 && start
< pt
&& end
> pt
);
10988 /* Reconsider the setting of B->clip_changed which is displayed
10992 reconsider_clip_changes (w
, b
)
10996 if (b
->clip_changed
10997 && !NILP (w
->window_end_valid
)
10998 && w
->current_matrix
->buffer
== b
10999 && w
->current_matrix
->zv
== BUF_ZV (b
)
11000 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11001 b
->clip_changed
= 0;
11003 /* If display wasn't paused, and W is not a tool bar window, see if
11004 point has been moved into or out of a composition. In that case,
11005 we set b->clip_changed to 1 to force updating the screen. If
11006 b->clip_changed has already been set to 1, we can skip this
11008 if (!b
->clip_changed
11009 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11013 if (w
== XWINDOW (selected_window
))
11014 pt
= BUF_PT (current_buffer
);
11016 pt
= marker_position (w
->pointm
);
11018 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11019 || pt
!= XINT (w
->last_point
))
11020 && check_point_in_composition (w
->current_matrix
->buffer
,
11021 XINT (w
->last_point
),
11022 XBUFFER (w
->buffer
), pt
))
11023 b
->clip_changed
= 1;
11028 /* Select FRAME to forward the values of frame-local variables into C
11029 variables so that the redisplay routines can access those values
11033 select_frame_for_redisplay (frame
)
11036 Lisp_Object tail
, sym
, val
;
11037 Lisp_Object old
= selected_frame
;
11039 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11041 selected_frame
= frame
;
11045 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11046 if (CONSP (XCAR (tail
))
11047 && (sym
= XCAR (XCAR (tail
)),
11049 && (sym
= indirect_variable (sym
),
11050 val
= SYMBOL_VALUE (sym
),
11051 (BUFFER_LOCAL_VALUEP (val
)))
11052 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11053 /* Use find_symbol_value rather than Fsymbol_value
11054 to avoid an error if it is void. */
11055 find_symbol_value (sym
);
11056 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11060 #define STOP_POLLING \
11061 do { if (! polling_stopped_here) stop_polling (); \
11062 polling_stopped_here = 1; } while (0)
11064 #define RESUME_POLLING \
11065 do { if (polling_stopped_here) start_polling (); \
11066 polling_stopped_here = 0; } while (0)
11069 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11070 response to any user action; therefore, we should preserve the echo
11071 area. (Actually, our caller does that job.) Perhaps in the future
11072 avoid recentering windows if it is not necessary; currently that
11073 causes some problems. */
11076 redisplay_internal (preserve_echo_area
)
11077 int preserve_echo_area
;
11079 struct window
*w
= XWINDOW (selected_window
);
11082 int must_finish
= 0;
11083 struct text_pos tlbufpos
, tlendpos
;
11084 int number_of_visible_frames
;
11087 int polling_stopped_here
= 0;
11088 Lisp_Object old_frame
= selected_frame
;
11090 /* Non-zero means redisplay has to consider all windows on all
11091 frames. Zero means, only selected_window is considered. */
11092 int consider_all_windows_p
;
11094 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11096 /* No redisplay if running in batch mode or frame is not yet fully
11097 initialized, or redisplay is explicitly turned off by setting
11098 Vinhibit_redisplay. */
11100 || !NILP (Vinhibit_redisplay
))
11103 /* Don't examine these until after testing Vinhibit_redisplay.
11104 When Emacs is shutting down, perhaps because its connection to
11105 X has dropped, we should not look at them at all. */
11106 f
= XFRAME (w
->frame
);
11107 sf
= SELECTED_FRAME ();
11109 if (!f
->glyphs_initialized_p
)
11112 /* The flag redisplay_performed_directly_p is set by
11113 direct_output_for_insert when it already did the whole screen
11114 update necessary. */
11115 if (redisplay_performed_directly_p
)
11117 redisplay_performed_directly_p
= 0;
11118 if (!hscroll_windows (selected_window
))
11122 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
11123 if (popup_activated ())
11127 /* I don't think this happens but let's be paranoid. */
11128 if (redisplaying_p
)
11131 /* Record a function that resets redisplaying_p to its old value
11132 when we leave this function. */
11133 count
= SPECPDL_INDEX ();
11134 record_unwind_protect (unwind_redisplay
,
11135 Fcons (make_number (redisplaying_p
), selected_frame
));
11137 specbind (Qinhibit_free_realized_faces
, Qnil
);
11140 Lisp_Object tail
, frame
;
11142 FOR_EACH_FRAME (tail
, frame
)
11144 struct frame
*f
= XFRAME (frame
);
11145 f
->already_hscrolled_p
= 0;
11150 if (!EQ (old_frame
, selected_frame
)
11151 && FRAME_LIVE_P (XFRAME (old_frame
)))
11152 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11153 selected_frame and selected_window to be temporarily out-of-sync so
11154 when we come back here via `goto retry', we need to resync because we
11155 may need to run Elisp code (via prepare_menu_bars). */
11156 select_frame_for_redisplay (old_frame
);
11159 reconsider_clip_changes (w
, current_buffer
);
11160 last_escape_glyph_frame
= NULL
;
11161 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11163 /* If new fonts have been loaded that make a glyph matrix adjustment
11164 necessary, do it. */
11165 if (fonts_changed_p
)
11167 adjust_glyphs (NULL
);
11168 ++windows_or_buffers_changed
;
11169 fonts_changed_p
= 0;
11172 /* If face_change_count is non-zero, init_iterator will free all
11173 realized faces, which includes the faces referenced from current
11174 matrices. So, we can't reuse current matrices in this case. */
11175 if (face_change_count
)
11176 ++windows_or_buffers_changed
;
11178 if (FRAME_TERMCAP_P (sf
)
11179 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11181 /* Since frames on a single ASCII terminal share the same
11182 display area, displaying a different frame means redisplay
11183 the whole thing. */
11184 windows_or_buffers_changed
++;
11185 SET_FRAME_GARBAGED (sf
);
11187 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11189 FRAME_TTY (sf
)->previous_frame
= sf
;
11192 /* Set the visible flags for all frames. Do this before checking
11193 for resized or garbaged frames; they want to know if their frames
11194 are visible. See the comment in frame.h for
11195 FRAME_SAMPLE_VISIBILITY. */
11197 Lisp_Object tail
, frame
;
11199 number_of_visible_frames
= 0;
11201 FOR_EACH_FRAME (tail
, frame
)
11203 struct frame
*f
= XFRAME (frame
);
11205 FRAME_SAMPLE_VISIBILITY (f
);
11206 if (FRAME_VISIBLE_P (f
))
11207 ++number_of_visible_frames
;
11208 clear_desired_matrices (f
);
11213 /* Notice any pending interrupt request to change frame size. */
11214 do_pending_window_change (1);
11216 /* Clear frames marked as garbaged. */
11217 if (frame_garbaged
)
11218 clear_garbaged_frames ();
11220 /* Build menubar and tool-bar items. */
11221 if (NILP (Vmemory_full
))
11222 prepare_menu_bars ();
11224 if (windows_or_buffers_changed
)
11225 update_mode_lines
++;
11227 /* Detect case that we need to write or remove a star in the mode line. */
11228 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11230 w
->update_mode_line
= Qt
;
11231 if (buffer_shared
> 1)
11232 update_mode_lines
++;
11235 /* Avoid invocation of point motion hooks by `current_column' below. */
11236 count1
= SPECPDL_INDEX ();
11237 specbind (Qinhibit_point_motion_hooks
, Qt
);
11239 /* If %c is in the mode line, update it if needed. */
11240 if (!NILP (w
->column_number_displayed
)
11241 /* This alternative quickly identifies a common case
11242 where no change is needed. */
11243 && !(PT
== XFASTINT (w
->last_point
)
11244 && XFASTINT (w
->last_modified
) >= MODIFF
11245 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11246 && (XFASTINT (w
->column_number_displayed
)
11247 != (int) current_column ())) /* iftc */
11248 w
->update_mode_line
= Qt
;
11250 unbind_to (count1
, Qnil
);
11252 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11254 /* The variable buffer_shared is set in redisplay_window and
11255 indicates that we redisplay a buffer in different windows. See
11257 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11258 || cursor_type_changed
);
11260 /* If specs for an arrow have changed, do thorough redisplay
11261 to ensure we remove any arrow that should no longer exist. */
11262 if (overlay_arrows_changed_p ())
11263 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11265 /* Normally the message* functions will have already displayed and
11266 updated the echo area, but the frame may have been trashed, or
11267 the update may have been preempted, so display the echo area
11268 again here. Checking message_cleared_p captures the case that
11269 the echo area should be cleared. */
11270 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11271 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11272 || (message_cleared_p
11273 && minibuf_level
== 0
11274 /* If the mini-window is currently selected, this means the
11275 echo-area doesn't show through. */
11276 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11278 int window_height_changed_p
= echo_area_display (0);
11281 /* If we don't display the current message, don't clear the
11282 message_cleared_p flag, because, if we did, we wouldn't clear
11283 the echo area in the next redisplay which doesn't preserve
11285 if (!display_last_displayed_message_p
)
11286 message_cleared_p
= 0;
11288 if (fonts_changed_p
)
11290 else if (window_height_changed_p
)
11292 consider_all_windows_p
= 1;
11293 ++update_mode_lines
;
11294 ++windows_or_buffers_changed
;
11296 /* If window configuration was changed, frames may have been
11297 marked garbaged. Clear them or we will experience
11298 surprises wrt scrolling. */
11299 if (frame_garbaged
)
11300 clear_garbaged_frames ();
11303 else if (EQ (selected_window
, minibuf_window
)
11304 && (current_buffer
->clip_changed
11305 || XFASTINT (w
->last_modified
) < MODIFF
11306 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11307 && resize_mini_window (w
, 0))
11309 /* Resized active mini-window to fit the size of what it is
11310 showing if its contents might have changed. */
11312 consider_all_windows_p
= 1;
11313 ++windows_or_buffers_changed
;
11314 ++update_mode_lines
;
11316 /* If window configuration was changed, frames may have been
11317 marked garbaged. Clear them or we will experience
11318 surprises wrt scrolling. */
11319 if (frame_garbaged
)
11320 clear_garbaged_frames ();
11324 /* If showing the region, and mark has changed, we must redisplay
11325 the whole window. The assignment to this_line_start_pos prevents
11326 the optimization directly below this if-statement. */
11327 if (((!NILP (Vtransient_mark_mode
)
11328 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11329 != !NILP (w
->region_showing
))
11330 || (!NILP (w
->region_showing
)
11331 && !EQ (w
->region_showing
,
11332 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11333 CHARPOS (this_line_start_pos
) = 0;
11335 /* Optimize the case that only the line containing the cursor in the
11336 selected window has changed. Variables starting with this_ are
11337 set in display_line and record information about the line
11338 containing the cursor. */
11339 tlbufpos
= this_line_start_pos
;
11340 tlendpos
= this_line_end_pos
;
11341 if (!consider_all_windows_p
11342 && CHARPOS (tlbufpos
) > 0
11343 && NILP (w
->update_mode_line
)
11344 && !current_buffer
->clip_changed
11345 && !current_buffer
->prevent_redisplay_optimizations_p
11346 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11347 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11348 /* Make sure recorded data applies to current buffer, etc. */
11349 && this_line_buffer
== current_buffer
11350 && current_buffer
== XBUFFER (w
->buffer
)
11351 && NILP (w
->force_start
)
11352 && NILP (w
->optional_new_start
)
11353 /* Point must be on the line that we have info recorded about. */
11354 && PT
>= CHARPOS (tlbufpos
)
11355 && PT
<= Z
- CHARPOS (tlendpos
)
11356 /* All text outside that line, including its final newline,
11357 must be unchanged */
11358 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11359 CHARPOS (tlendpos
)))
11361 if (CHARPOS (tlbufpos
) > BEGV
11362 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11363 && (CHARPOS (tlbufpos
) == ZV
11364 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11365 /* Former continuation line has disappeared by becoming empty */
11367 else if (XFASTINT (w
->last_modified
) < MODIFF
11368 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11369 || MINI_WINDOW_P (w
))
11371 /* We have to handle the case of continuation around a
11372 wide-column character (See the comment in indent.c around
11375 For instance, in the following case:
11377 -------- Insert --------
11378 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11379 J_I_ ==> J_I_ `^^' are cursors.
11383 As we have to redraw the line above, we should goto cancel. */
11386 int line_height_before
= this_line_pixel_height
;
11388 /* Note that start_display will handle the case that the
11389 line starting at tlbufpos is a continuation lines. */
11390 start_display (&it
, w
, tlbufpos
);
11392 /* Implementation note: It this still necessary? */
11393 if (it
.current_x
!= this_line_start_x
)
11396 TRACE ((stderr
, "trying display optimization 1\n"));
11397 w
->cursor
.vpos
= -1;
11398 overlay_arrow_seen
= 0;
11399 it
.vpos
= this_line_vpos
;
11400 it
.current_y
= this_line_y
;
11401 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11402 display_line (&it
);
11404 /* If line contains point, is not continued,
11405 and ends at same distance from eob as before, we win */
11406 if (w
->cursor
.vpos
>= 0
11407 /* Line is not continued, otherwise this_line_start_pos
11408 would have been set to 0 in display_line. */
11409 && CHARPOS (this_line_start_pos
)
11410 /* Line ends as before. */
11411 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11412 /* Line has same height as before. Otherwise other lines
11413 would have to be shifted up or down. */
11414 && this_line_pixel_height
== line_height_before
)
11416 /* If this is not the window's last line, we must adjust
11417 the charstarts of the lines below. */
11418 if (it
.current_y
< it
.last_visible_y
)
11420 struct glyph_row
*row
11421 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11422 int delta
, delta_bytes
;
11424 if (Z
- CHARPOS (tlendpos
) == ZV
)
11426 /* This line ends at end of (accessible part of)
11427 buffer. There is no newline to count. */
11429 - CHARPOS (tlendpos
)
11430 - MATRIX_ROW_START_CHARPOS (row
));
11431 delta_bytes
= (Z_BYTE
11432 - BYTEPOS (tlendpos
)
11433 - MATRIX_ROW_START_BYTEPOS (row
));
11437 /* This line ends in a newline. Must take
11438 account of the newline and the rest of the
11439 text that follows. */
11441 - CHARPOS (tlendpos
)
11442 - MATRIX_ROW_START_CHARPOS (row
));
11443 delta_bytes
= (Z_BYTE
11444 - BYTEPOS (tlendpos
)
11445 - MATRIX_ROW_START_BYTEPOS (row
));
11448 increment_matrix_positions (w
->current_matrix
,
11449 this_line_vpos
+ 1,
11450 w
->current_matrix
->nrows
,
11451 delta
, delta_bytes
);
11454 /* If this row displays text now but previously didn't,
11455 or vice versa, w->window_end_vpos may have to be
11457 if ((it
.glyph_row
- 1)->displays_text_p
)
11459 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11460 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11462 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11463 && this_line_vpos
> 0)
11464 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11465 w
->window_end_valid
= Qnil
;
11467 /* Update hint: No need to try to scroll in update_window. */
11468 w
->desired_matrix
->no_scrolling_p
= 1;
11471 *w
->desired_matrix
->method
= 0;
11472 debug_method_add (w
, "optimization 1");
11474 #ifdef HAVE_WINDOW_SYSTEM
11475 update_window_fringes (w
, 0);
11482 else if (/* Cursor position hasn't changed. */
11483 PT
== XFASTINT (w
->last_point
)
11484 /* Make sure the cursor was last displayed
11485 in this window. Otherwise we have to reposition it. */
11486 && 0 <= w
->cursor
.vpos
11487 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11491 do_pending_window_change (1);
11493 /* We used to always goto end_of_redisplay here, but this
11494 isn't enough if we have a blinking cursor. */
11495 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11496 goto end_of_redisplay
;
11500 /* If highlighting the region, or if the cursor is in the echo area,
11501 then we can't just move the cursor. */
11502 else if (! (!NILP (Vtransient_mark_mode
)
11503 && !NILP (current_buffer
->mark_active
))
11504 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11505 || highlight_nonselected_windows
)
11506 && NILP (w
->region_showing
)
11507 && NILP (Vshow_trailing_whitespace
)
11508 && !cursor_in_echo_area
)
11511 struct glyph_row
*row
;
11513 /* Skip from tlbufpos to PT and see where it is. Note that
11514 PT may be in invisible text. If so, we will end at the
11515 next visible position. */
11516 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11517 NULL
, DEFAULT_FACE_ID
);
11518 it
.current_x
= this_line_start_x
;
11519 it
.current_y
= this_line_y
;
11520 it
.vpos
= this_line_vpos
;
11522 /* The call to move_it_to stops in front of PT, but
11523 moves over before-strings. */
11524 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11526 if (it
.vpos
== this_line_vpos
11527 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11530 xassert (this_line_vpos
== it
.vpos
);
11531 xassert (this_line_y
== it
.current_y
);
11532 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11534 *w
->desired_matrix
->method
= 0;
11535 debug_method_add (w
, "optimization 3");
11544 /* Text changed drastically or point moved off of line. */
11545 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11548 CHARPOS (this_line_start_pos
) = 0;
11549 consider_all_windows_p
|= buffer_shared
> 1;
11550 ++clear_face_cache_count
;
11551 #ifdef HAVE_WINDOW_SYSTEM
11552 ++clear_image_cache_count
;
11555 /* Build desired matrices, and update the display. If
11556 consider_all_windows_p is non-zero, do it for all windows on all
11557 frames. Otherwise do it for selected_window, only. */
11559 if (consider_all_windows_p
)
11561 Lisp_Object tail
, frame
;
11563 FOR_EACH_FRAME (tail
, frame
)
11564 XFRAME (frame
)->updated_p
= 0;
11566 /* Recompute # windows showing selected buffer. This will be
11567 incremented each time such a window is displayed. */
11570 FOR_EACH_FRAME (tail
, frame
)
11572 struct frame
*f
= XFRAME (frame
);
11574 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11576 if (! EQ (frame
, selected_frame
))
11577 /* Select the frame, for the sake of frame-local
11579 select_frame_for_redisplay (frame
);
11581 /* Mark all the scroll bars to be removed; we'll redeem
11582 the ones we want when we redisplay their windows. */
11583 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11584 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11586 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11587 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11589 /* Any scroll bars which redisplay_windows should have
11590 nuked should now go away. */
11591 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11592 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11594 /* If fonts changed, display again. */
11595 /* ??? rms: I suspect it is a mistake to jump all the way
11596 back to retry here. It should just retry this frame. */
11597 if (fonts_changed_p
)
11600 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11602 /* See if we have to hscroll. */
11603 if (!f
->already_hscrolled_p
)
11605 f
->already_hscrolled_p
= 1;
11606 if (hscroll_windows (f
->root_window
))
11610 /* Prevent various kinds of signals during display
11611 update. stdio is not robust about handling
11612 signals, which can cause an apparent I/O
11614 if (interrupt_input
)
11615 unrequest_sigio ();
11618 /* Update the display. */
11619 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11620 pause
|= update_frame (f
, 0, 0);
11621 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11631 if (!EQ (old_frame
, selected_frame
)
11632 && FRAME_LIVE_P (XFRAME (old_frame
)))
11633 /* We played a bit fast-and-loose above and allowed selected_frame
11634 and selected_window to be temporarily out-of-sync but let's make
11635 sure this stays contained. */
11636 select_frame_for_redisplay (old_frame
);
11637 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11641 /* Do the mark_window_display_accurate after all windows have
11642 been redisplayed because this call resets flags in buffers
11643 which are needed for proper redisplay. */
11644 FOR_EACH_FRAME (tail
, frame
)
11646 struct frame
*f
= XFRAME (frame
);
11649 mark_window_display_accurate (f
->root_window
, 1);
11650 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11651 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11656 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11658 Lisp_Object mini_window
;
11659 struct frame
*mini_frame
;
11661 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11662 /* Use list_of_error, not Qerror, so that
11663 we catch only errors and don't run the debugger. */
11664 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11666 redisplay_window_error
);
11668 /* Compare desired and current matrices, perform output. */
11671 /* If fonts changed, display again. */
11672 if (fonts_changed_p
)
11675 /* Prevent various kinds of signals during display update.
11676 stdio is not robust about handling signals,
11677 which can cause an apparent I/O error. */
11678 if (interrupt_input
)
11679 unrequest_sigio ();
11682 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11684 if (hscroll_windows (selected_window
))
11687 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11688 pause
= update_frame (sf
, 0, 0);
11691 /* We may have called echo_area_display at the top of this
11692 function. If the echo area is on another frame, that may
11693 have put text on a frame other than the selected one, so the
11694 above call to update_frame would not have caught it. Catch
11696 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11697 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11699 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11701 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11702 pause
|= update_frame (mini_frame
, 0, 0);
11703 if (!pause
&& hscroll_windows (mini_window
))
11708 /* If display was paused because of pending input, make sure we do a
11709 thorough update the next time. */
11712 /* Prevent the optimization at the beginning of
11713 redisplay_internal that tries a single-line update of the
11714 line containing the cursor in the selected window. */
11715 CHARPOS (this_line_start_pos
) = 0;
11717 /* Let the overlay arrow be updated the next time. */
11718 update_overlay_arrows (0);
11720 /* If we pause after scrolling, some rows in the current
11721 matrices of some windows are not valid. */
11722 if (!WINDOW_FULL_WIDTH_P (w
)
11723 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11724 update_mode_lines
= 1;
11728 if (!consider_all_windows_p
)
11730 /* This has already been done above if
11731 consider_all_windows_p is set. */
11732 mark_window_display_accurate_1 (w
, 1);
11734 /* Say overlay arrows are up to date. */
11735 update_overlay_arrows (1);
11737 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11738 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11741 update_mode_lines
= 0;
11742 windows_or_buffers_changed
= 0;
11743 cursor_type_changed
= 0;
11746 /* Start SIGIO interrupts coming again. Having them off during the
11747 code above makes it less likely one will discard output, but not
11748 impossible, since there might be stuff in the system buffer here.
11749 But it is much hairier to try to do anything about that. */
11750 if (interrupt_input
)
11754 /* If a frame has become visible which was not before, redisplay
11755 again, so that we display it. Expose events for such a frame
11756 (which it gets when becoming visible) don't call the parts of
11757 redisplay constructing glyphs, so simply exposing a frame won't
11758 display anything in this case. So, we have to display these
11759 frames here explicitly. */
11762 Lisp_Object tail
, frame
;
11765 FOR_EACH_FRAME (tail
, frame
)
11767 int this_is_visible
= 0;
11769 if (XFRAME (frame
)->visible
)
11770 this_is_visible
= 1;
11771 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11772 if (XFRAME (frame
)->visible
)
11773 this_is_visible
= 1;
11775 if (this_is_visible
)
11779 if (new_count
!= number_of_visible_frames
)
11780 windows_or_buffers_changed
++;
11783 /* Change frame size now if a change is pending. */
11784 do_pending_window_change (1);
11786 /* If we just did a pending size change, or have additional
11787 visible frames, redisplay again. */
11788 if (windows_or_buffers_changed
&& !pause
)
11791 /* Clear the face cache eventually. */
11792 if (consider_all_windows_p
)
11794 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11796 clear_face_cache (0);
11797 clear_face_cache_count
= 0;
11799 #ifdef HAVE_WINDOW_SYSTEM
11800 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11802 clear_image_caches (Qnil
);
11803 clear_image_cache_count
= 0;
11805 #endif /* HAVE_WINDOW_SYSTEM */
11809 unbind_to (count
, Qnil
);
11814 /* Redisplay, but leave alone any recent echo area message unless
11815 another message has been requested in its place.
11817 This is useful in situations where you need to redisplay but no
11818 user action has occurred, making it inappropriate for the message
11819 area to be cleared. See tracking_off and
11820 wait_reading_process_output for examples of these situations.
11822 FROM_WHERE is an integer saying from where this function was
11823 called. This is useful for debugging. */
11826 redisplay_preserve_echo_area (from_where
)
11829 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11831 if (!NILP (echo_area_buffer
[1]))
11833 /* We have a previously displayed message, but no current
11834 message. Redisplay the previous message. */
11835 display_last_displayed_message_p
= 1;
11836 redisplay_internal (1);
11837 display_last_displayed_message_p
= 0;
11840 redisplay_internal (1);
11842 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
11843 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11844 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
11848 /* Function registered with record_unwind_protect in
11849 redisplay_internal. Reset redisplaying_p to the value it had
11850 before redisplay_internal was called, and clear
11851 prevent_freeing_realized_faces_p. It also selects the previously
11852 selected frame, unless it has been deleted (by an X connection
11853 failure during redisplay, for example). */
11856 unwind_redisplay (val
)
11859 Lisp_Object old_redisplaying_p
, old_frame
;
11861 old_redisplaying_p
= XCAR (val
);
11862 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11863 old_frame
= XCDR (val
);
11864 if (! EQ (old_frame
, selected_frame
)
11865 && FRAME_LIVE_P (XFRAME (old_frame
)))
11866 select_frame_for_redisplay (old_frame
);
11871 /* Mark the display of window W as accurate or inaccurate. If
11872 ACCURATE_P is non-zero mark display of W as accurate. If
11873 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11874 redisplay_internal is called. */
11877 mark_window_display_accurate_1 (w
, accurate_p
)
11881 if (BUFFERP (w
->buffer
))
11883 struct buffer
*b
= XBUFFER (w
->buffer
);
11886 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11887 w
->last_overlay_modified
11888 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11890 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11894 b
->clip_changed
= 0;
11895 b
->prevent_redisplay_optimizations_p
= 0;
11897 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11898 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11899 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11900 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11902 w
->current_matrix
->buffer
= b
;
11903 w
->current_matrix
->begv
= BUF_BEGV (b
);
11904 w
->current_matrix
->zv
= BUF_ZV (b
);
11906 w
->last_cursor
= w
->cursor
;
11907 w
->last_cursor_off_p
= w
->cursor_off_p
;
11909 if (w
== XWINDOW (selected_window
))
11910 w
->last_point
= make_number (BUF_PT (b
));
11912 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11918 w
->window_end_valid
= w
->buffer
;
11919 #if 0 /* This is incorrect with variable-height lines. */
11920 xassert (XINT (w
->window_end_vpos
)
11921 < (WINDOW_TOTAL_LINES (w
)
11922 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11924 w
->update_mode_line
= Qnil
;
11929 /* Mark the display of windows in the window tree rooted at WINDOW as
11930 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11931 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11932 be redisplayed the next time redisplay_internal is called. */
11935 mark_window_display_accurate (window
, accurate_p
)
11936 Lisp_Object window
;
11941 for (; !NILP (window
); window
= w
->next
)
11943 w
= XWINDOW (window
);
11944 mark_window_display_accurate_1 (w
, accurate_p
);
11946 if (!NILP (w
->vchild
))
11947 mark_window_display_accurate (w
->vchild
, accurate_p
);
11948 if (!NILP (w
->hchild
))
11949 mark_window_display_accurate (w
->hchild
, accurate_p
);
11954 update_overlay_arrows (1);
11958 /* Force a thorough redisplay the next time by setting
11959 last_arrow_position and last_arrow_string to t, which is
11960 unequal to any useful value of Voverlay_arrow_... */
11961 update_overlay_arrows (-1);
11966 /* Return value in display table DP (Lisp_Char_Table *) for character
11967 C. Since a display table doesn't have any parent, we don't have to
11968 follow parent. Do not call this function directly but use the
11969 macro DISP_CHAR_VECTOR. */
11972 disp_char_vector (dp
, c
)
11973 struct Lisp_Char_Table
*dp
;
11978 if (ASCII_CHAR_P (c
))
11981 if (SUB_CHAR_TABLE_P (val
))
11982 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
11988 XSETCHAR_TABLE (table
, dp
);
11989 val
= char_table_ref (table
, c
);
11998 /***********************************************************************
12000 ***********************************************************************/
12002 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12005 redisplay_windows (window
)
12006 Lisp_Object window
;
12008 while (!NILP (window
))
12010 struct window
*w
= XWINDOW (window
);
12012 if (!NILP (w
->hchild
))
12013 redisplay_windows (w
->hchild
);
12014 else if (!NILP (w
->vchild
))
12015 redisplay_windows (w
->vchild
);
12018 displayed_buffer
= XBUFFER (w
->buffer
);
12019 /* Use list_of_error, not Qerror, so that
12020 we catch only errors and don't run the debugger. */
12021 internal_condition_case_1 (redisplay_window_0
, window
,
12023 redisplay_window_error
);
12031 redisplay_window_error ()
12033 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12038 redisplay_window_0 (window
)
12039 Lisp_Object window
;
12041 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12042 redisplay_window (window
, 0);
12047 redisplay_window_1 (window
)
12048 Lisp_Object window
;
12050 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12051 redisplay_window (window
, 1);
12056 /* Increment GLYPH until it reaches END or CONDITION fails while
12057 adding (GLYPH)->pixel_width to X. */
12059 #define SKIP_GLYPHS(glyph, end, x, condition) \
12062 (x) += (glyph)->pixel_width; \
12065 while ((glyph) < (end) && (condition))
12068 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12069 DELTA is the number of bytes by which positions recorded in ROW
12070 differ from current buffer positions.
12072 Return 0 if cursor is not on this row. 1 otherwise. */
12075 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12077 struct glyph_row
*row
;
12078 struct glyph_matrix
*matrix
;
12079 int delta
, delta_bytes
, dy
, dvpos
;
12081 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12082 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12083 struct glyph
*cursor
= NULL
;
12084 /* The first glyph that starts a sequence of glyphs from string. */
12085 struct glyph
*string_start
;
12086 /* The X coordinate of string_start. */
12087 int string_start_x
;
12088 /* The last known character position. */
12089 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12090 /* The last known character position before string_start. */
12091 int string_before_pos
;
12094 int cursor_from_overlay_pos
= 0;
12095 int pt_old
= PT
- delta
;
12097 /* Skip over glyphs not having an object at the start of the row.
12098 These are special glyphs like truncation marks on terminal
12100 if (row
->displays_text_p
)
12102 && INTEGERP (glyph
->object
)
12103 && glyph
->charpos
< 0)
12105 x
+= glyph
->pixel_width
;
12109 string_start
= NULL
;
12111 && !INTEGERP (glyph
->object
)
12112 && (!BUFFERP (glyph
->object
)
12113 || (last_pos
= glyph
->charpos
) < pt_old
))
12115 if (! STRINGP (glyph
->object
))
12117 string_start
= NULL
;
12118 x
+= glyph
->pixel_width
;
12120 if (cursor_from_overlay_pos
12121 && last_pos
>= cursor_from_overlay_pos
)
12123 cursor_from_overlay_pos
= 0;
12129 if (string_start
== NULL
)
12131 string_before_pos
= last_pos
;
12132 string_start
= glyph
;
12133 string_start_x
= x
;
12135 /* Skip all glyphs from string. */
12140 if ((cursor
== NULL
|| glyph
> cursor
)
12141 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12142 Qcursor
, (glyph
)->object
),
12144 && (pos
= string_buffer_position (w
, glyph
->object
,
12145 string_before_pos
),
12146 (pos
== 0 /* From overlay */
12147 || pos
== pt_old
)))
12149 /* Estimate overlay buffer position from the buffer
12150 positions of the glyphs before and after the overlay.
12151 Add 1 to last_pos so that if point corresponds to the
12152 glyph right after the overlay, we still use a 'cursor'
12153 property found in that overlay. */
12154 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12155 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12159 x
+= glyph
->pixel_width
;
12162 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12166 if (cursor
!= NULL
)
12171 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12173 /* Scan back over the ellipsis glyphs, decrementing positions. */
12174 while (glyph
> row
->glyphs
[TEXT_AREA
]
12175 && (glyph
- 1)->charpos
== last_pos
)
12176 glyph
--, x
-= glyph
->pixel_width
;
12177 /* That loop always goes one position too far,
12178 including the glyph before the ellipsis.
12179 So scan forward over that one. */
12180 x
+= glyph
->pixel_width
;
12183 else if (string_start
12184 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12186 /* We may have skipped over point because the previous glyphs
12187 are from string. As there's no easy way to know the
12188 character position of the current glyph, find the correct
12189 glyph on point by scanning from string_start again. */
12191 Lisp_Object string
;
12192 struct glyph
*stop
= glyph
;
12195 limit
= make_number (pt_old
+ 1);
12196 glyph
= string_start
;
12197 x
= string_start_x
;
12198 string
= glyph
->object
;
12199 pos
= string_buffer_position (w
, string
, string_before_pos
);
12200 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12201 because we always put cursor after overlay strings. */
12202 while (pos
== 0 && glyph
< stop
)
12204 string
= glyph
->object
;
12205 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12207 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12210 while (glyph
< stop
)
12212 pos
= XINT (Fnext_single_char_property_change
12213 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12216 /* Skip glyphs from the same string. */
12217 string
= glyph
->object
;
12218 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12219 /* Skip glyphs from an overlay. */
12220 while (glyph
< stop
12221 && ! string_buffer_position (w
, glyph
->object
, pos
))
12223 string
= glyph
->object
;
12224 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12228 /* If we reached the end of the line, and end was from a string,
12229 cursor is not on this line. */
12230 if (glyph
== end
&& row
->continued_p
)
12234 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12236 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12237 w
->cursor
.y
= row
->y
+ dy
;
12239 if (w
== XWINDOW (selected_window
))
12241 if (!row
->continued_p
12242 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12245 this_line_buffer
= XBUFFER (w
->buffer
);
12247 CHARPOS (this_line_start_pos
)
12248 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12249 BYTEPOS (this_line_start_pos
)
12250 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12252 CHARPOS (this_line_end_pos
)
12253 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12254 BYTEPOS (this_line_end_pos
)
12255 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12257 this_line_y
= w
->cursor
.y
;
12258 this_line_pixel_height
= row
->height
;
12259 this_line_vpos
= w
->cursor
.vpos
;
12260 this_line_start_x
= row
->x
;
12263 CHARPOS (this_line_start_pos
) = 0;
12270 /* Run window scroll functions, if any, for WINDOW with new window
12271 start STARTP. Sets the window start of WINDOW to that position.
12273 We assume that the window's buffer is really current. */
12275 static INLINE
struct text_pos
12276 run_window_scroll_functions (window
, startp
)
12277 Lisp_Object window
;
12278 struct text_pos startp
;
12280 struct window
*w
= XWINDOW (window
);
12281 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12283 if (current_buffer
!= XBUFFER (w
->buffer
))
12286 if (!NILP (Vwindow_scroll_functions
))
12288 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12289 make_number (CHARPOS (startp
)));
12290 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12291 /* In case the hook functions switch buffers. */
12292 if (current_buffer
!= XBUFFER (w
->buffer
))
12293 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12300 /* Make sure the line containing the cursor is fully visible.
12301 A value of 1 means there is nothing to be done.
12302 (Either the line is fully visible, or it cannot be made so,
12303 or we cannot tell.)
12305 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12306 is higher than window.
12308 A value of 0 means the caller should do scrolling
12309 as if point had gone off the screen. */
12312 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12315 int current_matrix_p
;
12317 struct glyph_matrix
*matrix
;
12318 struct glyph_row
*row
;
12321 if (!make_cursor_line_fully_visible_p
)
12324 /* It's not always possible to find the cursor, e.g, when a window
12325 is full of overlay strings. Don't do anything in that case. */
12326 if (w
->cursor
.vpos
< 0)
12329 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12330 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12332 /* If the cursor row is not partially visible, there's nothing to do. */
12333 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12336 /* If the row the cursor is in is taller than the window's height,
12337 it's not clear what to do, so do nothing. */
12338 window_height
= window_box_height (w
);
12339 if (row
->height
>= window_height
)
12341 if (!force_p
|| MINI_WINDOW_P (w
)
12342 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12348 /* This code used to try to scroll the window just enough to make
12349 the line visible. It returned 0 to say that the caller should
12350 allocate larger glyph matrices. */
12352 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12354 int dy
= row
->height
- row
->visible_height
;
12357 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12359 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12361 int dy
= - (row
->height
- row
->visible_height
);
12364 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12367 /* When we change the cursor y-position of the selected window,
12368 change this_line_y as well so that the display optimization for
12369 the cursor line of the selected window in redisplay_internal uses
12370 the correct y-position. */
12371 if (w
== XWINDOW (selected_window
))
12372 this_line_y
= w
->cursor
.y
;
12374 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12375 redisplay with larger matrices. */
12376 if (matrix
->nrows
< required_matrix_height (w
))
12378 fonts_changed_p
= 1;
12387 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12388 non-zero means only WINDOW is redisplayed in redisplay_internal.
12389 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12390 in redisplay_window to bring a partially visible line into view in
12391 the case that only the cursor has moved.
12393 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12394 last screen line's vertical height extends past the end of the screen.
12398 1 if scrolling succeeded
12400 0 if scrolling didn't find point.
12402 -1 if new fonts have been loaded so that we must interrupt
12403 redisplay, adjust glyph matrices, and try again. */
12409 SCROLLING_NEED_LARGER_MATRICES
12413 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12414 scroll_step
, temp_scroll_step
, last_line_misfit
)
12415 Lisp_Object window
;
12416 int just_this_one_p
;
12417 EMACS_INT scroll_conservatively
, scroll_step
;
12418 int temp_scroll_step
;
12419 int last_line_misfit
;
12421 struct window
*w
= XWINDOW (window
);
12422 struct frame
*f
= XFRAME (w
->frame
);
12423 struct text_pos scroll_margin_pos
;
12424 struct text_pos pos
;
12425 struct text_pos startp
;
12427 Lisp_Object window_end
;
12428 int this_scroll_margin
;
12432 int amount_to_scroll
= 0;
12433 Lisp_Object aggressive
;
12435 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12438 debug_method_add (w
, "try_scrolling");
12441 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12443 /* Compute scroll margin height in pixels. We scroll when point is
12444 within this distance from the top or bottom of the window. */
12445 if (scroll_margin
> 0)
12447 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12448 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12451 this_scroll_margin
= 0;
12453 /* Force scroll_conservatively to have a reasonable value so it doesn't
12454 cause an overflow while computing how much to scroll. */
12455 if (scroll_conservatively
)
12456 scroll_conservatively
= min (scroll_conservatively
,
12457 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12459 /* Compute how much we should try to scroll maximally to bring point
12461 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12462 scroll_max
= max (scroll_step
,
12463 max (scroll_conservatively
, temp_scroll_step
));
12464 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12465 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12466 /* We're trying to scroll because of aggressive scrolling
12467 but no scroll_step is set. Choose an arbitrary one. Maybe
12468 there should be a variable for this. */
12472 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12474 /* Decide whether we have to scroll down. Start at the window end
12475 and move this_scroll_margin up to find the position of the scroll
12477 window_end
= Fwindow_end (window
, Qt
);
12481 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12482 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12484 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12486 start_display (&it
, w
, scroll_margin_pos
);
12487 if (this_scroll_margin
)
12488 move_it_vertically_backward (&it
, this_scroll_margin
);
12489 if (extra_scroll_margin_lines
)
12490 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12491 scroll_margin_pos
= it
.current
.pos
;
12494 if (PT
>= CHARPOS (scroll_margin_pos
))
12498 /* Point is in the scroll margin at the bottom of the window, or
12499 below. Compute a new window start that makes point visible. */
12501 /* Compute the distance from the scroll margin to PT.
12502 Give up if the distance is greater than scroll_max. */
12503 start_display (&it
, w
, scroll_margin_pos
);
12505 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12506 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12508 /* To make point visible, we have to move the window start
12509 down so that the line the cursor is in is visible, which
12510 means we have to add in the height of the cursor line. */
12511 dy
= line_bottom_y (&it
) - y0
;
12513 if (dy
> scroll_max
)
12514 return SCROLLING_FAILED
;
12516 /* Move the window start down. If scrolling conservatively,
12517 move it just enough down to make point visible. If
12518 scroll_step is set, move it down by scroll_step. */
12519 start_display (&it
, w
, startp
);
12521 if (scroll_conservatively
)
12522 /* Set AMOUNT_TO_SCROLL to at least one line,
12523 and at most scroll_conservatively lines. */
12525 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12526 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12527 else if (scroll_step
|| temp_scroll_step
)
12528 amount_to_scroll
= scroll_max
;
12531 aggressive
= current_buffer
->scroll_up_aggressively
;
12532 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12533 if (NUMBERP (aggressive
))
12535 double float_amount
= XFLOATINT (aggressive
) * height
;
12536 amount_to_scroll
= float_amount
;
12537 if (amount_to_scroll
== 0 && float_amount
> 0)
12538 amount_to_scroll
= 1;
12542 if (amount_to_scroll
<= 0)
12543 return SCROLLING_FAILED
;
12545 /* If moving by amount_to_scroll leaves STARTP unchanged,
12546 move it down one screen line. */
12548 move_it_vertically (&it
, amount_to_scroll
);
12549 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12550 move_it_by_lines (&it
, 1, 1);
12551 startp
= it
.current
.pos
;
12555 /* See if point is inside the scroll margin at the top of the
12557 scroll_margin_pos
= startp
;
12558 if (this_scroll_margin
)
12560 start_display (&it
, w
, startp
);
12561 move_it_vertically (&it
, this_scroll_margin
);
12562 scroll_margin_pos
= it
.current
.pos
;
12565 if (PT
< CHARPOS (scroll_margin_pos
))
12567 /* Point is in the scroll margin at the top of the window or
12568 above what is displayed in the window. */
12571 /* Compute the vertical distance from PT to the scroll
12572 margin position. Give up if distance is greater than
12574 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12575 start_display (&it
, w
, pos
);
12577 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12578 it
.last_visible_y
, -1,
12579 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12580 dy
= it
.current_y
- y0
;
12581 if (dy
> scroll_max
)
12582 return SCROLLING_FAILED
;
12584 /* Compute new window start. */
12585 start_display (&it
, w
, startp
);
12587 if (scroll_conservatively
)
12589 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12590 else if (scroll_step
|| temp_scroll_step
)
12591 amount_to_scroll
= scroll_max
;
12594 aggressive
= current_buffer
->scroll_down_aggressively
;
12595 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12596 if (NUMBERP (aggressive
))
12598 double float_amount
= XFLOATINT (aggressive
) * height
;
12599 amount_to_scroll
= float_amount
;
12600 if (amount_to_scroll
== 0 && float_amount
> 0)
12601 amount_to_scroll
= 1;
12605 if (amount_to_scroll
<= 0)
12606 return SCROLLING_FAILED
;
12608 move_it_vertically_backward (&it
, amount_to_scroll
);
12609 startp
= it
.current
.pos
;
12613 /* Run window scroll functions. */
12614 startp
= run_window_scroll_functions (window
, startp
);
12616 /* Display the window. Give up if new fonts are loaded, or if point
12618 if (!try_window (window
, startp
, 0))
12619 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12620 else if (w
->cursor
.vpos
< 0)
12622 clear_glyph_matrix (w
->desired_matrix
);
12623 rc
= SCROLLING_FAILED
;
12627 /* Maybe forget recorded base line for line number display. */
12628 if (!just_this_one_p
12629 || current_buffer
->clip_changed
12630 || BEG_UNCHANGED
< CHARPOS (startp
))
12631 w
->base_line_number
= Qnil
;
12633 /* If cursor ends up on a partially visible line,
12634 treat that as being off the bottom of the screen. */
12635 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12637 clear_glyph_matrix (w
->desired_matrix
);
12638 ++extra_scroll_margin_lines
;
12641 rc
= SCROLLING_SUCCESS
;
12648 /* Compute a suitable window start for window W if display of W starts
12649 on a continuation line. Value is non-zero if a new window start
12652 The new window start will be computed, based on W's width, starting
12653 from the start of the continued line. It is the start of the
12654 screen line with the minimum distance from the old start W->start. */
12657 compute_window_start_on_continuation_line (w
)
12660 struct text_pos pos
, start_pos
;
12661 int window_start_changed_p
= 0;
12663 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12665 /* If window start is on a continuation line... Window start may be
12666 < BEGV in case there's invisible text at the start of the
12667 buffer (M-x rmail, for example). */
12668 if (CHARPOS (start_pos
) > BEGV
12669 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12672 struct glyph_row
*row
;
12674 /* Handle the case that the window start is out of range. */
12675 if (CHARPOS (start_pos
) < BEGV
)
12676 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12677 else if (CHARPOS (start_pos
) > ZV
)
12678 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12680 /* Find the start of the continued line. This should be fast
12681 because scan_buffer is fast (newline cache). */
12682 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12683 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12684 row
, DEFAULT_FACE_ID
);
12685 reseat_at_previous_visible_line_start (&it
);
12687 /* If the line start is "too far" away from the window start,
12688 say it takes too much time to compute a new window start. */
12689 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12690 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12692 int min_distance
, distance
;
12694 /* Move forward by display lines to find the new window
12695 start. If window width was enlarged, the new start can
12696 be expected to be > the old start. If window width was
12697 decreased, the new window start will be < the old start.
12698 So, we're looking for the display line start with the
12699 minimum distance from the old window start. */
12700 pos
= it
.current
.pos
;
12701 min_distance
= INFINITY
;
12702 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12703 distance
< min_distance
)
12705 min_distance
= distance
;
12706 pos
= it
.current
.pos
;
12707 move_it_by_lines (&it
, 1, 0);
12710 /* Set the window start there. */
12711 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12712 window_start_changed_p
= 1;
12716 return window_start_changed_p
;
12720 /* Try cursor movement in case text has not changed in window WINDOW,
12721 with window start STARTP. Value is
12723 CURSOR_MOVEMENT_SUCCESS if successful
12725 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12727 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12728 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12729 we want to scroll as if scroll-step were set to 1. See the code.
12731 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12732 which case we have to abort this redisplay, and adjust matrices
12737 CURSOR_MOVEMENT_SUCCESS
,
12738 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12739 CURSOR_MOVEMENT_MUST_SCROLL
,
12740 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12744 try_cursor_movement (window
, startp
, scroll_step
)
12745 Lisp_Object window
;
12746 struct text_pos startp
;
12749 struct window
*w
= XWINDOW (window
);
12750 struct frame
*f
= XFRAME (w
->frame
);
12751 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12754 if (inhibit_try_cursor_movement
)
12758 /* Handle case where text has not changed, only point, and it has
12759 not moved off the frame. */
12760 if (/* Point may be in this window. */
12761 PT
>= CHARPOS (startp
)
12762 /* Selective display hasn't changed. */
12763 && !current_buffer
->clip_changed
12764 /* Function force-mode-line-update is used to force a thorough
12765 redisplay. It sets either windows_or_buffers_changed or
12766 update_mode_lines. So don't take a shortcut here for these
12768 && !update_mode_lines
12769 && !windows_or_buffers_changed
12770 && !cursor_type_changed
12771 /* Can't use this case if highlighting a region. When a
12772 region exists, cursor movement has to do more than just
12774 && !(!NILP (Vtransient_mark_mode
)
12775 && !NILP (current_buffer
->mark_active
))
12776 && NILP (w
->region_showing
)
12777 && NILP (Vshow_trailing_whitespace
)
12778 /* Right after splitting windows, last_point may be nil. */
12779 && INTEGERP (w
->last_point
)
12780 /* This code is not used for mini-buffer for the sake of the case
12781 of redisplaying to replace an echo area message; since in
12782 that case the mini-buffer contents per se are usually
12783 unchanged. This code is of no real use in the mini-buffer
12784 since the handling of this_line_start_pos, etc., in redisplay
12785 handles the same cases. */
12786 && !EQ (window
, minibuf_window
)
12787 /* When splitting windows or for new windows, it happens that
12788 redisplay is called with a nil window_end_vpos or one being
12789 larger than the window. This should really be fixed in
12790 window.c. I don't have this on my list, now, so we do
12791 approximately the same as the old redisplay code. --gerd. */
12792 && INTEGERP (w
->window_end_vpos
)
12793 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12794 && (FRAME_WINDOW_P (f
)
12795 || !overlay_arrow_in_current_buffer_p ()))
12797 int this_scroll_margin
, top_scroll_margin
;
12798 struct glyph_row
*row
= NULL
;
12801 debug_method_add (w
, "cursor movement");
12804 /* Scroll if point within this distance from the top or bottom
12805 of the window. This is a pixel value. */
12806 this_scroll_margin
= max (0, scroll_margin
);
12807 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12808 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12810 top_scroll_margin
= this_scroll_margin
;
12811 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12812 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12814 /* Start with the row the cursor was displayed during the last
12815 not paused redisplay. Give up if that row is not valid. */
12816 if (w
->last_cursor
.vpos
< 0
12817 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12818 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12821 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12822 if (row
->mode_line_p
)
12824 if (!row
->enabled_p
)
12825 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12828 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12831 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12833 if (PT
> XFASTINT (w
->last_point
))
12835 /* Point has moved forward. */
12836 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12837 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12839 xassert (row
->enabled_p
);
12843 /* The end position of a row equals the start position
12844 of the next row. If PT is there, we would rather
12845 display it in the next line. */
12846 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12847 && MATRIX_ROW_END_CHARPOS (row
) == PT
12848 && !cursor_row_p (w
, row
))
12851 /* If within the scroll margin, scroll. Note that
12852 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12853 the next line would be drawn, and that
12854 this_scroll_margin can be zero. */
12855 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12856 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12857 /* Line is completely visible last line in window
12858 and PT is to be set in the next line. */
12859 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12860 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12861 && !row
->ends_at_zv_p
12862 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12865 else if (PT
< XFASTINT (w
->last_point
))
12867 /* Cursor has to be moved backward. Note that PT >=
12868 CHARPOS (startp) because of the outer if-statement. */
12869 while (!row
->mode_line_p
12870 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12871 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12872 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12873 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12874 row
> w
->current_matrix
->rows
12875 && (row
-1)->ends_in_newline_from_string_p
))))
12876 && (row
->y
> top_scroll_margin
12877 || CHARPOS (startp
) == BEGV
))
12879 xassert (row
->enabled_p
);
12883 /* Consider the following case: Window starts at BEGV,
12884 there is invisible, intangible text at BEGV, so that
12885 display starts at some point START > BEGV. It can
12886 happen that we are called with PT somewhere between
12887 BEGV and START. Try to handle that case. */
12888 if (row
< w
->current_matrix
->rows
12889 || row
->mode_line_p
)
12891 row
= w
->current_matrix
->rows
;
12892 if (row
->mode_line_p
)
12896 /* Due to newlines in overlay strings, we may have to
12897 skip forward over overlay strings. */
12898 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12899 && MATRIX_ROW_END_CHARPOS (row
) == PT
12900 && !cursor_row_p (w
, row
))
12903 /* If within the scroll margin, scroll. */
12904 if (row
->y
< top_scroll_margin
12905 && CHARPOS (startp
) != BEGV
)
12910 /* Cursor did not move. So don't scroll even if cursor line
12911 is partially visible, as it was so before. */
12912 rc
= CURSOR_MOVEMENT_SUCCESS
;
12915 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12916 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12918 /* if PT is not in the glyph row, give up. */
12919 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12921 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12922 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12923 && make_cursor_line_fully_visible_p
)
12925 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12926 && !row
->ends_at_zv_p
12927 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12928 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12929 else if (row
->height
> window_box_height (w
))
12931 /* If we end up in a partially visible line, let's
12932 make it fully visible, except when it's taller
12933 than the window, in which case we can't do much
12936 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12940 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12941 if (!cursor_row_fully_visible_p (w
, 0, 1))
12942 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12944 rc
= CURSOR_MOVEMENT_SUCCESS
;
12948 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12953 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12955 rc
= CURSOR_MOVEMENT_SUCCESS
;
12960 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12961 && MATRIX_ROW_START_CHARPOS (row
) == PT
12962 && cursor_row_p (w
, row
));
12971 set_vertical_scroll_bar (w
)
12974 int start
, end
, whole
;
12976 /* Calculate the start and end positions for the current window.
12977 At some point, it would be nice to choose between scrollbars
12978 which reflect the whole buffer size, with special markers
12979 indicating narrowing, and scrollbars which reflect only the
12982 Note that mini-buffers sometimes aren't displaying any text. */
12983 if (!MINI_WINDOW_P (w
)
12984 || (w
== XWINDOW (minibuf_window
)
12985 && NILP (echo_area_buffer
[0])))
12987 struct buffer
*buf
= XBUFFER (w
->buffer
);
12988 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12989 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12990 /* I don't think this is guaranteed to be right. For the
12991 moment, we'll pretend it is. */
12992 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12996 if (whole
< (end
- start
))
12997 whole
= end
- start
;
13000 start
= end
= whole
= 0;
13002 /* Indicate what this scroll bar ought to be displaying now. */
13003 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13004 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13005 (w
, end
- start
, whole
, start
);
13009 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13010 selected_window is redisplayed.
13012 We can return without actually redisplaying the window if
13013 fonts_changed_p is nonzero. In that case, redisplay_internal will
13017 redisplay_window (window
, just_this_one_p
)
13018 Lisp_Object window
;
13019 int just_this_one_p
;
13021 struct window
*w
= XWINDOW (window
);
13022 struct frame
*f
= XFRAME (w
->frame
);
13023 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13024 struct buffer
*old
= current_buffer
;
13025 struct text_pos lpoint
, opoint
, startp
;
13026 int update_mode_line
;
13029 /* Record it now because it's overwritten. */
13030 int current_matrix_up_to_date_p
= 0;
13031 int used_current_matrix_p
= 0;
13032 /* This is less strict than current_matrix_up_to_date_p.
13033 It indictes that the buffer contents and narrowing are unchanged. */
13034 int buffer_unchanged_p
= 0;
13035 int temp_scroll_step
= 0;
13036 int count
= SPECPDL_INDEX ();
13038 int centering_position
= -1;
13039 int last_line_misfit
= 0;
13040 int beg_unchanged
, end_unchanged
;
13042 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13045 /* W must be a leaf window here. */
13046 xassert (!NILP (w
->buffer
));
13048 *w
->desired_matrix
->method
= 0;
13052 reconsider_clip_changes (w
, buffer
);
13054 /* Has the mode line to be updated? */
13055 update_mode_line
= (!NILP (w
->update_mode_line
)
13056 || update_mode_lines
13057 || buffer
->clip_changed
13058 || buffer
->prevent_redisplay_optimizations_p
);
13060 if (MINI_WINDOW_P (w
))
13062 if (w
== XWINDOW (echo_area_window
)
13063 && !NILP (echo_area_buffer
[0]))
13065 if (update_mode_line
)
13066 /* We may have to update a tty frame's menu bar or a
13067 tool-bar. Example `M-x C-h C-h C-g'. */
13068 goto finish_menu_bars
;
13070 /* We've already displayed the echo area glyphs in this window. */
13071 goto finish_scroll_bars
;
13073 else if ((w
!= XWINDOW (minibuf_window
)
13074 || minibuf_level
== 0)
13075 /* When buffer is nonempty, redisplay window normally. */
13076 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13077 /* Quail displays non-mini buffers in minibuffer window.
13078 In that case, redisplay the window normally. */
13079 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13081 /* W is a mini-buffer window, but it's not active, so clear
13083 int yb
= window_text_bottom_y (w
);
13084 struct glyph_row
*row
;
13087 for (y
= 0, row
= w
->desired_matrix
->rows
;
13089 y
+= row
->height
, ++row
)
13090 blank_row (w
, row
, y
);
13091 goto finish_scroll_bars
;
13094 clear_glyph_matrix (w
->desired_matrix
);
13097 /* Otherwise set up data on this window; select its buffer and point
13099 /* Really select the buffer, for the sake of buffer-local
13101 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13103 current_matrix_up_to_date_p
13104 = (!NILP (w
->window_end_valid
)
13105 && !current_buffer
->clip_changed
13106 && !current_buffer
->prevent_redisplay_optimizations_p
13107 && XFASTINT (w
->last_modified
) >= MODIFF
13108 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13110 /* Run the window-bottom-change-functions
13111 if it is possible that the text on the screen has changed
13112 (either due to modification of the text, or any other reason). */
13113 if (!current_matrix_up_to_date_p
13114 && !NILP (Vwindow_text_change_functions
))
13116 safe_run_hooks (Qwindow_text_change_functions
);
13120 beg_unchanged
= BEG_UNCHANGED
;
13121 end_unchanged
= END_UNCHANGED
;
13123 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13125 specbind (Qinhibit_point_motion_hooks
, Qt
);
13128 = (!NILP (w
->window_end_valid
)
13129 && !current_buffer
->clip_changed
13130 && XFASTINT (w
->last_modified
) >= MODIFF
13131 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13133 /* When windows_or_buffers_changed is non-zero, we can't rely on
13134 the window end being valid, so set it to nil there. */
13135 if (windows_or_buffers_changed
)
13137 /* If window starts on a continuation line, maybe adjust the
13138 window start in case the window's width changed. */
13139 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13140 compute_window_start_on_continuation_line (w
);
13142 w
->window_end_valid
= Qnil
;
13145 /* Some sanity checks. */
13146 CHECK_WINDOW_END (w
);
13147 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13149 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13152 /* If %c is in mode line, update it if needed. */
13153 if (!NILP (w
->column_number_displayed
)
13154 /* This alternative quickly identifies a common case
13155 where no change is needed. */
13156 && !(PT
== XFASTINT (w
->last_point
)
13157 && XFASTINT (w
->last_modified
) >= MODIFF
13158 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13159 && (XFASTINT (w
->column_number_displayed
)
13160 != (int) current_column ())) /* iftc */
13161 update_mode_line
= 1;
13163 /* Count number of windows showing the selected buffer. An indirect
13164 buffer counts as its base buffer. */
13165 if (!just_this_one_p
)
13167 struct buffer
*current_base
, *window_base
;
13168 current_base
= current_buffer
;
13169 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13170 if (current_base
->base_buffer
)
13171 current_base
= current_base
->base_buffer
;
13172 if (window_base
->base_buffer
)
13173 window_base
= window_base
->base_buffer
;
13174 if (current_base
== window_base
)
13178 /* Point refers normally to the selected window. For any other
13179 window, set up appropriate value. */
13180 if (!EQ (window
, selected_window
))
13182 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13183 int new_pt_byte
= marker_byte_position (w
->pointm
);
13187 new_pt_byte
= BEGV_BYTE
;
13188 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13190 else if (new_pt
> (ZV
- 1))
13193 new_pt_byte
= ZV_BYTE
;
13194 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13197 /* We don't use SET_PT so that the point-motion hooks don't run. */
13198 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13201 /* If any of the character widths specified in the display table
13202 have changed, invalidate the width run cache. It's true that
13203 this may be a bit late to catch such changes, but the rest of
13204 redisplay goes (non-fatally) haywire when the display table is
13205 changed, so why should we worry about doing any better? */
13206 if (current_buffer
->width_run_cache
)
13208 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13210 if (! disptab_matches_widthtab (disptab
,
13211 XVECTOR (current_buffer
->width_table
)))
13213 invalidate_region_cache (current_buffer
,
13214 current_buffer
->width_run_cache
,
13216 recompute_width_table (current_buffer
, disptab
);
13220 /* If window-start is screwed up, choose a new one. */
13221 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13224 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13226 /* If someone specified a new starting point but did not insist,
13227 check whether it can be used. */
13228 if (!NILP (w
->optional_new_start
)
13229 && CHARPOS (startp
) >= BEGV
13230 && CHARPOS (startp
) <= ZV
)
13232 w
->optional_new_start
= Qnil
;
13233 start_display (&it
, w
, startp
);
13234 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13235 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13236 if (IT_CHARPOS (it
) == PT
)
13237 w
->force_start
= Qt
;
13238 /* IT may overshoot PT if text at PT is invisible. */
13239 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13240 w
->force_start
= Qt
;
13245 /* Handle case where place to start displaying has been specified,
13246 unless the specified location is outside the accessible range. */
13247 if (!NILP (w
->force_start
)
13248 || w
->frozen_window_start_p
)
13250 /* We set this later on if we have to adjust point. */
13254 w
->force_start
= Qnil
;
13256 w
->window_end_valid
= Qnil
;
13258 /* Forget any recorded base line for line number display. */
13259 if (!buffer_unchanged_p
)
13260 w
->base_line_number
= Qnil
;
13262 /* Redisplay the mode line. Select the buffer properly for that.
13263 Also, run the hook window-scroll-functions
13264 because we have scrolled. */
13265 /* Note, we do this after clearing force_start because
13266 if there's an error, it is better to forget about force_start
13267 than to get into an infinite loop calling the hook functions
13268 and having them get more errors. */
13269 if (!update_mode_line
13270 || ! NILP (Vwindow_scroll_functions
))
13272 update_mode_line
= 1;
13273 w
->update_mode_line
= Qt
;
13274 startp
= run_window_scroll_functions (window
, startp
);
13277 w
->last_modified
= make_number (0);
13278 w
->last_overlay_modified
= make_number (0);
13279 if (CHARPOS (startp
) < BEGV
)
13280 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13281 else if (CHARPOS (startp
) > ZV
)
13282 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13284 /* Redisplay, then check if cursor has been set during the
13285 redisplay. Give up if new fonts were loaded. */
13286 val
= try_window (window
, startp
, 1);
13289 w
->force_start
= Qt
;
13290 clear_glyph_matrix (w
->desired_matrix
);
13291 goto need_larger_matrices
;
13293 /* Point was outside the scroll margins. */
13295 new_vpos
= window_box_height (w
) / 2;
13297 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13299 /* If point does not appear, try to move point so it does
13300 appear. The desired matrix has been built above, so we
13301 can use it here. */
13302 new_vpos
= window_box_height (w
) / 2;
13305 if (!cursor_row_fully_visible_p (w
, 0, 0))
13307 /* Point does appear, but on a line partly visible at end of window.
13308 Move it back to a fully-visible line. */
13309 new_vpos
= window_box_height (w
);
13312 /* If we need to move point for either of the above reasons,
13313 now actually do it. */
13316 struct glyph_row
*row
;
13318 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13319 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13322 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13323 MATRIX_ROW_START_BYTEPOS (row
));
13325 if (w
!= XWINDOW (selected_window
))
13326 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13327 else if (current_buffer
== old
)
13328 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13330 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13332 /* If we are highlighting the region, then we just changed
13333 the region, so redisplay to show it. */
13334 if (!NILP (Vtransient_mark_mode
)
13335 && !NILP (current_buffer
->mark_active
))
13337 clear_glyph_matrix (w
->desired_matrix
);
13338 if (!try_window (window
, startp
, 0))
13339 goto need_larger_matrices
;
13344 debug_method_add (w
, "forced window start");
13349 /* Handle case where text has not changed, only point, and it has
13350 not moved off the frame, and we are not retrying after hscroll.
13351 (current_matrix_up_to_date_p is nonzero when retrying.) */
13352 if (current_matrix_up_to_date_p
13353 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13354 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13358 case CURSOR_MOVEMENT_SUCCESS
:
13359 used_current_matrix_p
= 1;
13362 #if 0 /* try_cursor_movement never returns this value. */
13363 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13364 goto need_larger_matrices
;
13367 case CURSOR_MOVEMENT_MUST_SCROLL
:
13368 goto try_to_scroll
;
13374 /* If current starting point was originally the beginning of a line
13375 but no longer is, find a new starting point. */
13376 else if (!NILP (w
->start_at_line_beg
)
13377 && !(CHARPOS (startp
) <= BEGV
13378 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13381 debug_method_add (w
, "recenter 1");
13386 /* Try scrolling with try_window_id. Value is > 0 if update has
13387 been done, it is -1 if we know that the same window start will
13388 not work. It is 0 if unsuccessful for some other reason. */
13389 else if ((tem
= try_window_id (w
)) != 0)
13392 debug_method_add (w
, "try_window_id %d", tem
);
13395 if (fonts_changed_p
)
13396 goto need_larger_matrices
;
13400 /* Otherwise try_window_id has returned -1 which means that we
13401 don't want the alternative below this comment to execute. */
13403 else if (CHARPOS (startp
) >= BEGV
13404 && CHARPOS (startp
) <= ZV
13405 && PT
>= CHARPOS (startp
)
13406 && (CHARPOS (startp
) < ZV
13407 /* Avoid starting at end of buffer. */
13408 || CHARPOS (startp
) == BEGV
13409 || (XFASTINT (w
->last_modified
) >= MODIFF
13410 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13413 /* If first window line is a continuation line, and window start
13414 is inside the modified region, but the first change is before
13415 current window start, we must select a new window start.
13417 However, if this is the result of a down-mouse event (e.g. by
13418 extending the mouse-drag-overlay), we don't want to select a
13419 new window start, since that would change the position under
13420 the mouse, resulting in an unwanted mouse-movement rather
13421 than a simple mouse-click. */
13422 if (NILP (w
->start_at_line_beg
)
13423 && NILP (do_mouse_tracking
)
13424 && CHARPOS (startp
) > BEGV
13425 && CHARPOS (startp
) > BEG
+ beg_unchanged
13426 && CHARPOS (startp
) <= Z
- end_unchanged
)
13428 w
->force_start
= Qt
;
13429 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13430 compute_window_start_on_continuation_line (w
);
13431 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13436 debug_method_add (w
, "same window start");
13439 /* Try to redisplay starting at same place as before.
13440 If point has not moved off frame, accept the results. */
13441 if (!current_matrix_up_to_date_p
13442 /* Don't use try_window_reusing_current_matrix in this case
13443 because a window scroll function can have changed the
13445 || !NILP (Vwindow_scroll_functions
)
13446 || MINI_WINDOW_P (w
)
13447 || !(used_current_matrix_p
13448 = try_window_reusing_current_matrix (w
)))
13450 IF_DEBUG (debug_method_add (w
, "1"));
13451 if (try_window (window
, startp
, 1) < 0)
13452 /* -1 means we need to scroll.
13453 0 means we need new matrices, but fonts_changed_p
13454 is set in that case, so we will detect it below. */
13455 goto try_to_scroll
;
13458 if (fonts_changed_p
)
13459 goto need_larger_matrices
;
13461 if (w
->cursor
.vpos
>= 0)
13463 if (!just_this_one_p
13464 || current_buffer
->clip_changed
13465 || BEG_UNCHANGED
< CHARPOS (startp
))
13466 /* Forget any recorded base line for line number display. */
13467 w
->base_line_number
= Qnil
;
13469 if (!cursor_row_fully_visible_p (w
, 1, 0))
13471 clear_glyph_matrix (w
->desired_matrix
);
13472 last_line_misfit
= 1;
13474 /* Drop through and scroll. */
13479 clear_glyph_matrix (w
->desired_matrix
);
13484 w
->last_modified
= make_number (0);
13485 w
->last_overlay_modified
= make_number (0);
13487 /* Redisplay the mode line. Select the buffer properly for that. */
13488 if (!update_mode_line
)
13490 update_mode_line
= 1;
13491 w
->update_mode_line
= Qt
;
13494 /* Try to scroll by specified few lines. */
13495 if ((scroll_conservatively
13497 || temp_scroll_step
13498 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13499 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13500 && !current_buffer
->clip_changed
13501 && CHARPOS (startp
) >= BEGV
13502 && CHARPOS (startp
) <= ZV
)
13504 /* The function returns -1 if new fonts were loaded, 1 if
13505 successful, 0 if not successful. */
13506 int rc
= try_scrolling (window
, just_this_one_p
,
13507 scroll_conservatively
,
13509 temp_scroll_step
, last_line_misfit
);
13512 case SCROLLING_SUCCESS
:
13515 case SCROLLING_NEED_LARGER_MATRICES
:
13516 goto need_larger_matrices
;
13518 case SCROLLING_FAILED
:
13526 /* Finally, just choose place to start which centers point */
13529 if (centering_position
< 0)
13530 centering_position
= window_box_height (w
) / 2;
13533 debug_method_add (w
, "recenter");
13536 /* w->vscroll = 0; */
13538 /* Forget any previously recorded base line for line number display. */
13539 if (!buffer_unchanged_p
)
13540 w
->base_line_number
= Qnil
;
13542 /* Move backward half the height of the window. */
13543 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13544 it
.current_y
= it
.last_visible_y
;
13545 move_it_vertically_backward (&it
, centering_position
);
13546 xassert (IT_CHARPOS (it
) >= BEGV
);
13548 /* The function move_it_vertically_backward may move over more
13549 than the specified y-distance. If it->w is small, e.g. a
13550 mini-buffer window, we may end up in front of the window's
13551 display area. Start displaying at the start of the line
13552 containing PT in this case. */
13553 if (it
.current_y
<= 0)
13555 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13556 move_it_vertically_backward (&it
, 0);
13558 /* I think this assert is bogus if buffer contains
13559 invisible text or images. KFS. */
13560 xassert (IT_CHARPOS (it
) <= PT
);
13565 it
.current_x
= it
.hpos
= 0;
13567 /* Set startp here explicitly in case that helps avoid an infinite loop
13568 in case the window-scroll-functions functions get errors. */
13569 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13571 /* Run scroll hooks. */
13572 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13574 /* Redisplay the window. */
13575 if (!current_matrix_up_to_date_p
13576 || windows_or_buffers_changed
13577 || cursor_type_changed
13578 /* Don't use try_window_reusing_current_matrix in this case
13579 because it can have changed the buffer. */
13580 || !NILP (Vwindow_scroll_functions
)
13581 || !just_this_one_p
13582 || MINI_WINDOW_P (w
)
13583 || !(used_current_matrix_p
13584 = try_window_reusing_current_matrix (w
)))
13585 try_window (window
, startp
, 0);
13587 /* If new fonts have been loaded (due to fontsets), give up. We
13588 have to start a new redisplay since we need to re-adjust glyph
13590 if (fonts_changed_p
)
13591 goto need_larger_matrices
;
13593 /* If cursor did not appear assume that the middle of the window is
13594 in the first line of the window. Do it again with the next line.
13595 (Imagine a window of height 100, displaying two lines of height
13596 60. Moving back 50 from it->last_visible_y will end in the first
13598 if (w
->cursor
.vpos
< 0)
13600 if (!NILP (w
->window_end_valid
)
13601 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13603 clear_glyph_matrix (w
->desired_matrix
);
13604 move_it_by_lines (&it
, 1, 0);
13605 try_window (window
, it
.current
.pos
, 0);
13607 else if (PT
< IT_CHARPOS (it
))
13609 clear_glyph_matrix (w
->desired_matrix
);
13610 move_it_by_lines (&it
, -1, 0);
13611 try_window (window
, it
.current
.pos
, 0);
13615 /* Not much we can do about it. */
13619 /* Consider the following case: Window starts at BEGV, there is
13620 invisible, intangible text at BEGV, so that display starts at
13621 some point START > BEGV. It can happen that we are called with
13622 PT somewhere between BEGV and START. Try to handle that case. */
13623 if (w
->cursor
.vpos
< 0)
13625 struct glyph_row
*row
= w
->current_matrix
->rows
;
13626 if (row
->mode_line_p
)
13628 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13631 if (!cursor_row_fully_visible_p (w
, 0, 0))
13633 /* If vscroll is enabled, disable it and try again. */
13637 clear_glyph_matrix (w
->desired_matrix
);
13641 /* If centering point failed to make the whole line visible,
13642 put point at the top instead. That has to make the whole line
13643 visible, if it can be done. */
13644 if (centering_position
== 0)
13647 clear_glyph_matrix (w
->desired_matrix
);
13648 centering_position
= 0;
13654 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13655 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13656 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13659 /* Display the mode line, if we must. */
13660 if ((update_mode_line
13661 /* If window not full width, must redo its mode line
13662 if (a) the window to its side is being redone and
13663 (b) we do a frame-based redisplay. This is a consequence
13664 of how inverted lines are drawn in frame-based redisplay. */
13665 || (!just_this_one_p
13666 && !FRAME_WINDOW_P (f
)
13667 && !WINDOW_FULL_WIDTH_P (w
))
13668 /* Line number to display. */
13669 || INTEGERP (w
->base_line_pos
)
13670 /* Column number is displayed and different from the one displayed. */
13671 || (!NILP (w
->column_number_displayed
)
13672 && (XFASTINT (w
->column_number_displayed
)
13673 != (int) current_column ()))) /* iftc */
13674 /* This means that the window has a mode line. */
13675 && (WINDOW_WANTS_MODELINE_P (w
)
13676 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13678 display_mode_lines (w
);
13680 /* If mode line height has changed, arrange for a thorough
13681 immediate redisplay using the correct mode line height. */
13682 if (WINDOW_WANTS_MODELINE_P (w
)
13683 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13685 fonts_changed_p
= 1;
13686 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13687 = DESIRED_MODE_LINE_HEIGHT (w
);
13690 /* If top line height has changed, arrange for a thorough
13691 immediate redisplay using the correct mode line height. */
13692 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13693 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13695 fonts_changed_p
= 1;
13696 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13697 = DESIRED_HEADER_LINE_HEIGHT (w
);
13700 if (fonts_changed_p
)
13701 goto need_larger_matrices
;
13704 if (!line_number_displayed
13705 && !BUFFERP (w
->base_line_pos
))
13707 w
->base_line_pos
= Qnil
;
13708 w
->base_line_number
= Qnil
;
13713 /* When we reach a frame's selected window, redo the frame's menu bar. */
13714 if (update_mode_line
13715 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13717 int redisplay_menu_p
= 0;
13718 int redisplay_tool_bar_p
= 0;
13720 if (FRAME_WINDOW_P (f
))
13722 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13723 || defined (USE_GTK)
13724 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13726 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13730 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13732 if (redisplay_menu_p
)
13733 display_menu_bar (w
);
13735 #ifdef HAVE_WINDOW_SYSTEM
13736 if (FRAME_WINDOW_P (f
))
13738 #if defined (USE_GTK) || USE_MAC_TOOLBAR
13739 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13741 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13742 && (FRAME_TOOL_BAR_LINES (f
) > 0
13743 || !NILP (Vauto_resize_tool_bars
));
13746 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13748 extern int ignore_mouse_drag_p
;
13749 ignore_mouse_drag_p
= 1;
13755 #ifdef HAVE_WINDOW_SYSTEM
13756 if (FRAME_WINDOW_P (f
)
13757 && update_window_fringes (w
, (just_this_one_p
13758 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13759 || w
->pseudo_window_p
)))
13763 if (draw_window_fringes (w
, 1))
13764 x_draw_vertical_border (w
);
13768 #endif /* HAVE_WINDOW_SYSTEM */
13770 /* We go to this label, with fonts_changed_p nonzero,
13771 if it is necessary to try again using larger glyph matrices.
13772 We have to redeem the scroll bar even in this case,
13773 because the loop in redisplay_internal expects that. */
13774 need_larger_matrices
:
13776 finish_scroll_bars
:
13778 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13780 /* Set the thumb's position and size. */
13781 set_vertical_scroll_bar (w
);
13783 /* Note that we actually used the scroll bar attached to this
13784 window, so it shouldn't be deleted at the end of redisplay. */
13785 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13786 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13789 /* Restore current_buffer and value of point in it. */
13790 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13791 set_buffer_internal_1 (old
);
13792 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13793 shorter. This can be caused by log truncation in *Messages*. */
13794 if (CHARPOS (lpoint
) <= ZV
)
13795 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13797 unbind_to (count
, Qnil
);
13801 /* Build the complete desired matrix of WINDOW with a window start
13802 buffer position POS.
13804 Value is 1 if successful. It is zero if fonts were loaded during
13805 redisplay which makes re-adjusting glyph matrices necessary, and -1
13806 if point would appear in the scroll margins.
13807 (We check that only if CHECK_MARGINS is nonzero. */
13810 try_window (window
, pos
, check_margins
)
13811 Lisp_Object window
;
13812 struct text_pos pos
;
13815 struct window
*w
= XWINDOW (window
);
13817 struct glyph_row
*last_text_row
= NULL
;
13818 struct frame
*f
= XFRAME (w
->frame
);
13820 /* Make POS the new window start. */
13821 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13823 /* Mark cursor position as unknown. No overlay arrow seen. */
13824 w
->cursor
.vpos
= -1;
13825 overlay_arrow_seen
= 0;
13827 /* Initialize iterator and info to start at POS. */
13828 start_display (&it
, w
, pos
);
13830 /* Display all lines of W. */
13831 while (it
.current_y
< it
.last_visible_y
)
13833 if (display_line (&it
))
13834 last_text_row
= it
.glyph_row
- 1;
13835 if (fonts_changed_p
)
13839 /* Don't let the cursor end in the scroll margins. */
13841 && !MINI_WINDOW_P (w
))
13843 int this_scroll_margin
;
13845 this_scroll_margin
= max (0, scroll_margin
);
13846 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13847 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13849 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13850 && w
->cursor
.y
< this_scroll_margin
13851 && CHARPOS (pos
) > BEGV
13852 && IT_CHARPOS (it
) < ZV
)
13853 /* rms: considering make_cursor_line_fully_visible_p here
13854 seems to give wrong results. We don't want to recenter
13855 when the last line is partly visible, we want to allow
13856 that case to be handled in the usual way. */
13857 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13859 w
->cursor
.vpos
= -1;
13860 clear_glyph_matrix (w
->desired_matrix
);
13865 /* If bottom moved off end of frame, change mode line percentage. */
13866 if (XFASTINT (w
->window_end_pos
) <= 0
13867 && Z
!= IT_CHARPOS (it
))
13868 w
->update_mode_line
= Qt
;
13870 /* Set window_end_pos to the offset of the last character displayed
13871 on the window from the end of current_buffer. Set
13872 window_end_vpos to its row number. */
13875 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13876 w
->window_end_bytepos
13877 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13879 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13881 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13882 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13883 ->displays_text_p
);
13887 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13888 w
->window_end_pos
= make_number (Z
- ZV
);
13889 w
->window_end_vpos
= make_number (0);
13892 /* But that is not valid info until redisplay finishes. */
13893 w
->window_end_valid
= Qnil
;
13899 /************************************************************************
13900 Window redisplay reusing current matrix when buffer has not changed
13901 ************************************************************************/
13903 /* Try redisplay of window W showing an unchanged buffer with a
13904 different window start than the last time it was displayed by
13905 reusing its current matrix. Value is non-zero if successful.
13906 W->start is the new window start. */
13909 try_window_reusing_current_matrix (w
)
13912 struct frame
*f
= XFRAME (w
->frame
);
13913 struct glyph_row
*row
, *bottom_row
;
13916 struct text_pos start
, new_start
;
13917 int nrows_scrolled
, i
;
13918 struct glyph_row
*last_text_row
;
13919 struct glyph_row
*last_reused_text_row
;
13920 struct glyph_row
*start_row
;
13921 int start_vpos
, min_y
, max_y
;
13924 if (inhibit_try_window_reusing
)
13928 if (/* This function doesn't handle terminal frames. */
13929 !FRAME_WINDOW_P (f
)
13930 /* Don't try to reuse the display if windows have been split
13932 || windows_or_buffers_changed
13933 || cursor_type_changed
)
13936 /* Can't do this if region may have changed. */
13937 if ((!NILP (Vtransient_mark_mode
)
13938 && !NILP (current_buffer
->mark_active
))
13939 || !NILP (w
->region_showing
)
13940 || !NILP (Vshow_trailing_whitespace
))
13943 /* If top-line visibility has changed, give up. */
13944 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13945 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13948 /* Give up if old or new display is scrolled vertically. We could
13949 make this function handle this, but right now it doesn't. */
13950 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13951 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13954 /* The variable new_start now holds the new window start. The old
13955 start `start' can be determined from the current matrix. */
13956 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13957 start
= start_row
->start
.pos
;
13958 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13960 /* Clear the desired matrix for the display below. */
13961 clear_glyph_matrix (w
->desired_matrix
);
13963 if (CHARPOS (new_start
) <= CHARPOS (start
))
13967 /* Don't use this method if the display starts with an ellipsis
13968 displayed for invisible text. It's not easy to handle that case
13969 below, and it's certainly not worth the effort since this is
13970 not a frequent case. */
13971 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13974 IF_DEBUG (debug_method_add (w
, "twu1"));
13976 /* Display up to a row that can be reused. The variable
13977 last_text_row is set to the last row displayed that displays
13978 text. Note that it.vpos == 0 if or if not there is a
13979 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13980 start_display (&it
, w
, new_start
);
13981 first_row_y
= it
.current_y
;
13982 w
->cursor
.vpos
= -1;
13983 last_text_row
= last_reused_text_row
= NULL
;
13985 while (it
.current_y
< it
.last_visible_y
13986 && !fonts_changed_p
)
13988 /* If we have reached into the characters in the START row,
13989 that means the line boundaries have changed. So we
13990 can't start copying with the row START. Maybe it will
13991 work to start copying with the following row. */
13992 while (IT_CHARPOS (it
) > CHARPOS (start
))
13994 /* Advance to the next row as the "start". */
13996 start
= start_row
->start
.pos
;
13997 /* If there are no more rows to try, or just one, give up. */
13998 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13999 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14000 || CHARPOS (start
) == ZV
)
14002 clear_glyph_matrix (w
->desired_matrix
);
14006 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14008 /* If we have reached alignment,
14009 we can copy the rest of the rows. */
14010 if (IT_CHARPOS (it
) == CHARPOS (start
))
14013 if (display_line (&it
))
14014 last_text_row
= it
.glyph_row
- 1;
14017 /* A value of current_y < last_visible_y means that we stopped
14018 at the previous window start, which in turn means that we
14019 have at least one reusable row. */
14020 if (it
.current_y
< it
.last_visible_y
)
14022 /* IT.vpos always starts from 0; it counts text lines. */
14023 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14025 /* Find PT if not already found in the lines displayed. */
14026 if (w
->cursor
.vpos
< 0)
14028 int dy
= it
.current_y
- start_row
->y
;
14030 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14031 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14033 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14034 dy
, nrows_scrolled
);
14037 clear_glyph_matrix (w
->desired_matrix
);
14042 /* Scroll the display. Do it before the current matrix is
14043 changed. The problem here is that update has not yet
14044 run, i.e. part of the current matrix is not up to date.
14045 scroll_run_hook will clear the cursor, and use the
14046 current matrix to get the height of the row the cursor is
14048 run
.current_y
= start_row
->y
;
14049 run
.desired_y
= it
.current_y
;
14050 run
.height
= it
.last_visible_y
- it
.current_y
;
14052 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14055 FRAME_RIF (f
)->update_window_begin_hook (w
);
14056 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14057 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14058 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14062 /* Shift current matrix down by nrows_scrolled lines. */
14063 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14064 rotate_matrix (w
->current_matrix
,
14066 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14069 /* Disable lines that must be updated. */
14070 for (i
= 0; i
< nrows_scrolled
; ++i
)
14071 (start_row
+ i
)->enabled_p
= 0;
14073 /* Re-compute Y positions. */
14074 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14075 max_y
= it
.last_visible_y
;
14076 for (row
= start_row
+ nrows_scrolled
;
14080 row
->y
= it
.current_y
;
14081 row
->visible_height
= row
->height
;
14083 if (row
->y
< min_y
)
14084 row
->visible_height
-= min_y
- row
->y
;
14085 if (row
->y
+ row
->height
> max_y
)
14086 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14087 row
->redraw_fringe_bitmaps_p
= 1;
14089 it
.current_y
+= row
->height
;
14091 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14092 last_reused_text_row
= row
;
14093 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14097 /* Disable lines in the current matrix which are now
14098 below the window. */
14099 for (++row
; row
< bottom_row
; ++row
)
14100 row
->enabled_p
= row
->mode_line_p
= 0;
14103 /* Update window_end_pos etc.; last_reused_text_row is the last
14104 reused row from the current matrix containing text, if any.
14105 The value of last_text_row is the last displayed line
14106 containing text. */
14107 if (last_reused_text_row
)
14109 w
->window_end_bytepos
14110 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14112 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14114 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14115 w
->current_matrix
));
14117 else if (last_text_row
)
14119 w
->window_end_bytepos
14120 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14122 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14124 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14128 /* This window must be completely empty. */
14129 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14130 w
->window_end_pos
= make_number (Z
- ZV
);
14131 w
->window_end_vpos
= make_number (0);
14133 w
->window_end_valid
= Qnil
;
14135 /* Update hint: don't try scrolling again in update_window. */
14136 w
->desired_matrix
->no_scrolling_p
= 1;
14139 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14143 else if (CHARPOS (new_start
) > CHARPOS (start
))
14145 struct glyph_row
*pt_row
, *row
;
14146 struct glyph_row
*first_reusable_row
;
14147 struct glyph_row
*first_row_to_display
;
14149 int yb
= window_text_bottom_y (w
);
14151 /* Find the row starting at new_start, if there is one. Don't
14152 reuse a partially visible line at the end. */
14153 first_reusable_row
= start_row
;
14154 while (first_reusable_row
->enabled_p
14155 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14156 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14157 < CHARPOS (new_start
)))
14158 ++first_reusable_row
;
14160 /* Give up if there is no row to reuse. */
14161 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14162 || !first_reusable_row
->enabled_p
14163 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14164 != CHARPOS (new_start
)))
14167 /* We can reuse fully visible rows beginning with
14168 first_reusable_row to the end of the window. Set
14169 first_row_to_display to the first row that cannot be reused.
14170 Set pt_row to the row containing point, if there is any. */
14172 for (first_row_to_display
= first_reusable_row
;
14173 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14174 ++first_row_to_display
)
14176 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14177 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14178 pt_row
= first_row_to_display
;
14181 /* Start displaying at the start of first_row_to_display. */
14182 xassert (first_row_to_display
->y
< yb
);
14183 init_to_row_start (&it
, w
, first_row_to_display
);
14185 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14187 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14189 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14190 + WINDOW_HEADER_LINE_HEIGHT (w
));
14192 /* Display lines beginning with first_row_to_display in the
14193 desired matrix. Set last_text_row to the last row displayed
14194 that displays text. */
14195 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14196 if (pt_row
== NULL
)
14197 w
->cursor
.vpos
= -1;
14198 last_text_row
= NULL
;
14199 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14200 if (display_line (&it
))
14201 last_text_row
= it
.glyph_row
- 1;
14203 /* Give up If point isn't in a row displayed or reused. */
14204 if (w
->cursor
.vpos
< 0)
14206 clear_glyph_matrix (w
->desired_matrix
);
14210 /* If point is in a reused row, adjust y and vpos of the cursor
14214 w
->cursor
.vpos
-= nrows_scrolled
;
14215 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14218 /* Scroll the display. */
14219 run
.current_y
= first_reusable_row
->y
;
14220 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14221 run
.height
= it
.last_visible_y
- run
.current_y
;
14222 dy
= run
.current_y
- run
.desired_y
;
14227 FRAME_RIF (f
)->update_window_begin_hook (w
);
14228 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14229 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14230 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14234 /* Adjust Y positions of reused rows. */
14235 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14236 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14237 max_y
= it
.last_visible_y
;
14238 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14241 row
->visible_height
= row
->height
;
14242 if (row
->y
< min_y
)
14243 row
->visible_height
-= min_y
- row
->y
;
14244 if (row
->y
+ row
->height
> max_y
)
14245 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14246 row
->redraw_fringe_bitmaps_p
= 1;
14249 /* Scroll the current matrix. */
14250 xassert (nrows_scrolled
> 0);
14251 rotate_matrix (w
->current_matrix
,
14253 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14256 /* Disable rows not reused. */
14257 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14258 row
->enabled_p
= 0;
14260 /* Point may have moved to a different line, so we cannot assume that
14261 the previous cursor position is valid; locate the correct row. */
14264 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14265 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14269 w
->cursor
.y
= row
->y
;
14271 if (row
< bottom_row
)
14273 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14274 while (glyph
->charpos
< PT
)
14277 w
->cursor
.x
+= glyph
->pixel_width
;
14283 /* Adjust window end. A null value of last_text_row means that
14284 the window end is in reused rows which in turn means that
14285 only its vpos can have changed. */
14288 w
->window_end_bytepos
14289 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14291 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14293 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14298 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14301 w
->window_end_valid
= Qnil
;
14302 w
->desired_matrix
->no_scrolling_p
= 1;
14305 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14315 /************************************************************************
14316 Window redisplay reusing current matrix when buffer has changed
14317 ************************************************************************/
14319 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14320 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14322 static struct glyph_row
*
14323 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14324 struct glyph_row
*));
14327 /* Return the last row in MATRIX displaying text. If row START is
14328 non-null, start searching with that row. IT gives the dimensions
14329 of the display. Value is null if matrix is empty; otherwise it is
14330 a pointer to the row found. */
14332 static struct glyph_row
*
14333 find_last_row_displaying_text (matrix
, it
, start
)
14334 struct glyph_matrix
*matrix
;
14336 struct glyph_row
*start
;
14338 struct glyph_row
*row
, *row_found
;
14340 /* Set row_found to the last row in IT->w's current matrix
14341 displaying text. The loop looks funny but think of partially
14344 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14345 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14347 xassert (row
->enabled_p
);
14349 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14358 /* Return the last row in the current matrix of W that is not affected
14359 by changes at the start of current_buffer that occurred since W's
14360 current matrix was built. Value is null if no such row exists.
14362 BEG_UNCHANGED us the number of characters unchanged at the start of
14363 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14364 first changed character in current_buffer. Characters at positions <
14365 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14366 when the current matrix was built. */
14368 static struct glyph_row
*
14369 find_last_unchanged_at_beg_row (w
)
14372 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14373 struct glyph_row
*row
;
14374 struct glyph_row
*row_found
= NULL
;
14375 int yb
= window_text_bottom_y (w
);
14377 /* Find the last row displaying unchanged text. */
14378 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14379 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14380 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14382 if (/* If row ends before first_changed_pos, it is unchanged,
14383 except in some case. */
14384 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14385 /* When row ends in ZV and we write at ZV it is not
14387 && !row
->ends_at_zv_p
14388 /* When first_changed_pos is the end of a continued line,
14389 row is not unchanged because it may be no longer
14391 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14392 && (row
->continued_p
14393 || row
->exact_window_width_line_p
)))
14396 /* Stop if last visible row. */
14397 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14407 /* Find the first glyph row in the current matrix of W that is not
14408 affected by changes at the end of current_buffer since the
14409 time W's current matrix was built.
14411 Return in *DELTA the number of chars by which buffer positions in
14412 unchanged text at the end of current_buffer must be adjusted.
14414 Return in *DELTA_BYTES the corresponding number of bytes.
14416 Value is null if no such row exists, i.e. all rows are affected by
14419 static struct glyph_row
*
14420 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14422 int *delta
, *delta_bytes
;
14424 struct glyph_row
*row
;
14425 struct glyph_row
*row_found
= NULL
;
14427 *delta
= *delta_bytes
= 0;
14429 /* Display must not have been paused, otherwise the current matrix
14430 is not up to date. */
14431 eassert (!NILP (w
->window_end_valid
));
14433 /* A value of window_end_pos >= END_UNCHANGED means that the window
14434 end is in the range of changed text. If so, there is no
14435 unchanged row at the end of W's current matrix. */
14436 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14439 /* Set row to the last row in W's current matrix displaying text. */
14440 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14442 /* If matrix is entirely empty, no unchanged row exists. */
14443 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14445 /* The value of row is the last glyph row in the matrix having a
14446 meaningful buffer position in it. The end position of row
14447 corresponds to window_end_pos. This allows us to translate
14448 buffer positions in the current matrix to current buffer
14449 positions for characters not in changed text. */
14450 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14451 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14452 int last_unchanged_pos
, last_unchanged_pos_old
;
14453 struct glyph_row
*first_text_row
14454 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14456 *delta
= Z
- Z_old
;
14457 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14459 /* Set last_unchanged_pos to the buffer position of the last
14460 character in the buffer that has not been changed. Z is the
14461 index + 1 of the last character in current_buffer, i.e. by
14462 subtracting END_UNCHANGED we get the index of the last
14463 unchanged character, and we have to add BEG to get its buffer
14465 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14466 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14468 /* Search backward from ROW for a row displaying a line that
14469 starts at a minimum position >= last_unchanged_pos_old. */
14470 for (; row
> first_text_row
; --row
)
14472 /* This used to abort, but it can happen.
14473 It is ok to just stop the search instead here. KFS. */
14474 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14477 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14482 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14488 /* Make sure that glyph rows in the current matrix of window W
14489 reference the same glyph memory as corresponding rows in the
14490 frame's frame matrix. This function is called after scrolling W's
14491 current matrix on a terminal frame in try_window_id and
14492 try_window_reusing_current_matrix. */
14495 sync_frame_with_window_matrix_rows (w
)
14498 struct frame
*f
= XFRAME (w
->frame
);
14499 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14501 /* Preconditions: W must be a leaf window and full-width. Its frame
14502 must have a frame matrix. */
14503 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14504 xassert (WINDOW_FULL_WIDTH_P (w
));
14505 xassert (!FRAME_WINDOW_P (f
));
14507 /* If W is a full-width window, glyph pointers in W's current matrix
14508 have, by definition, to be the same as glyph pointers in the
14509 corresponding frame matrix. Note that frame matrices have no
14510 marginal areas (see build_frame_matrix). */
14511 window_row
= w
->current_matrix
->rows
;
14512 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14513 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14514 while (window_row
< window_row_end
)
14516 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14517 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14519 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14520 frame_row
->glyphs
[TEXT_AREA
] = start
;
14521 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14522 frame_row
->glyphs
[LAST_AREA
] = end
;
14524 /* Disable frame rows whose corresponding window rows have
14525 been disabled in try_window_id. */
14526 if (!window_row
->enabled_p
)
14527 frame_row
->enabled_p
= 0;
14529 ++window_row
, ++frame_row
;
14534 /* Find the glyph row in window W containing CHARPOS. Consider all
14535 rows between START and END (not inclusive). END null means search
14536 all rows to the end of the display area of W. Value is the row
14537 containing CHARPOS or null. */
14540 row_containing_pos (w
, charpos
, start
, end
, dy
)
14543 struct glyph_row
*start
, *end
;
14546 struct glyph_row
*row
= start
;
14549 /* If we happen to start on a header-line, skip that. */
14550 if (row
->mode_line_p
)
14553 if ((end
&& row
>= end
) || !row
->enabled_p
)
14556 last_y
= window_text_bottom_y (w
) - dy
;
14560 /* Give up if we have gone too far. */
14561 if (end
&& row
>= end
)
14563 /* This formerly returned if they were equal.
14564 I think that both quantities are of a "last plus one" type;
14565 if so, when they are equal, the row is within the screen. -- rms. */
14566 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14569 /* If it is in this row, return this row. */
14570 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14571 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14572 /* The end position of a row equals the start
14573 position of the next row. If CHARPOS is there, we
14574 would rather display it in the next line, except
14575 when this line ends in ZV. */
14576 && !row
->ends_at_zv_p
14577 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14578 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14585 /* Try to redisplay window W by reusing its existing display. W's
14586 current matrix must be up to date when this function is called,
14587 i.e. window_end_valid must not be nil.
14591 1 if display has been updated
14592 0 if otherwise unsuccessful
14593 -1 if redisplay with same window start is known not to succeed
14595 The following steps are performed:
14597 1. Find the last row in the current matrix of W that is not
14598 affected by changes at the start of current_buffer. If no such row
14601 2. Find the first row in W's current matrix that is not affected by
14602 changes at the end of current_buffer. Maybe there is no such row.
14604 3. Display lines beginning with the row + 1 found in step 1 to the
14605 row found in step 2 or, if step 2 didn't find a row, to the end of
14608 4. If cursor is not known to appear on the window, give up.
14610 5. If display stopped at the row found in step 2, scroll the
14611 display and current matrix as needed.
14613 6. Maybe display some lines at the end of W, if we must. This can
14614 happen under various circumstances, like a partially visible line
14615 becoming fully visible, or because newly displayed lines are displayed
14616 in smaller font sizes.
14618 7. Update W's window end information. */
14624 struct frame
*f
= XFRAME (w
->frame
);
14625 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14626 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14627 struct glyph_row
*last_unchanged_at_beg_row
;
14628 struct glyph_row
*first_unchanged_at_end_row
;
14629 struct glyph_row
*row
;
14630 struct glyph_row
*bottom_row
;
14633 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14634 struct text_pos start_pos
;
14636 int first_unchanged_at_end_vpos
= 0;
14637 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14638 struct text_pos start
;
14639 int first_changed_charpos
, last_changed_charpos
;
14642 if (inhibit_try_window_id
)
14646 /* This is handy for debugging. */
14648 #define GIVE_UP(X) \
14650 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14654 #define GIVE_UP(X) return 0
14657 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14659 /* Don't use this for mini-windows because these can show
14660 messages and mini-buffers, and we don't handle that here. */
14661 if (MINI_WINDOW_P (w
))
14664 /* This flag is used to prevent redisplay optimizations. */
14665 if (windows_or_buffers_changed
|| cursor_type_changed
)
14668 /* Verify that narrowing has not changed.
14669 Also verify that we were not told to prevent redisplay optimizations.
14670 It would be nice to further
14671 reduce the number of cases where this prevents try_window_id. */
14672 if (current_buffer
->clip_changed
14673 || current_buffer
->prevent_redisplay_optimizations_p
)
14676 /* Window must either use window-based redisplay or be full width. */
14677 if (!FRAME_WINDOW_P (f
)
14678 && (!FRAME_LINE_INS_DEL_OK (f
)
14679 || !WINDOW_FULL_WIDTH_P (w
)))
14682 /* Give up if point is not known NOT to appear in W. */
14683 if (PT
< CHARPOS (start
))
14686 /* Another way to prevent redisplay optimizations. */
14687 if (XFASTINT (w
->last_modified
) == 0)
14690 /* Verify that window is not hscrolled. */
14691 if (XFASTINT (w
->hscroll
) != 0)
14694 /* Verify that display wasn't paused. */
14695 if (NILP (w
->window_end_valid
))
14698 /* Can't use this if highlighting a region because a cursor movement
14699 will do more than just set the cursor. */
14700 if (!NILP (Vtransient_mark_mode
)
14701 && !NILP (current_buffer
->mark_active
))
14704 /* Likewise if highlighting trailing whitespace. */
14705 if (!NILP (Vshow_trailing_whitespace
))
14708 /* Likewise if showing a region. */
14709 if (!NILP (w
->region_showing
))
14712 /* Can use this if overlay arrow position and or string have changed. */
14713 if (overlay_arrows_changed_p ())
14717 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14718 only if buffer has really changed. The reason is that the gap is
14719 initially at Z for freshly visited files. The code below would
14720 set end_unchanged to 0 in that case. */
14721 if (MODIFF
> SAVE_MODIFF
14722 /* This seems to happen sometimes after saving a buffer. */
14723 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14725 if (GPT
- BEG
< BEG_UNCHANGED
)
14726 BEG_UNCHANGED
= GPT
- BEG
;
14727 if (Z
- GPT
< END_UNCHANGED
)
14728 END_UNCHANGED
= Z
- GPT
;
14731 /* The position of the first and last character that has been changed. */
14732 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14733 last_changed_charpos
= Z
- END_UNCHANGED
;
14735 /* If window starts after a line end, and the last change is in
14736 front of that newline, then changes don't affect the display.
14737 This case happens with stealth-fontification. Note that although
14738 the display is unchanged, glyph positions in the matrix have to
14739 be adjusted, of course. */
14740 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14741 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14742 && ((last_changed_charpos
< CHARPOS (start
)
14743 && CHARPOS (start
) == BEGV
)
14744 || (last_changed_charpos
< CHARPOS (start
) - 1
14745 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14747 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14748 struct glyph_row
*r0
;
14750 /* Compute how many chars/bytes have been added to or removed
14751 from the buffer. */
14752 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14753 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14755 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14757 /* Give up if PT is not in the window. Note that it already has
14758 been checked at the start of try_window_id that PT is not in
14759 front of the window start. */
14760 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14763 /* If window start is unchanged, we can reuse the whole matrix
14764 as is, after adjusting glyph positions. No need to compute
14765 the window end again, since its offset from Z hasn't changed. */
14766 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14767 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14768 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14769 /* PT must not be in a partially visible line. */
14770 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14771 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14773 /* Adjust positions in the glyph matrix. */
14774 if (delta
|| delta_bytes
)
14776 struct glyph_row
*r1
14777 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14778 increment_matrix_positions (w
->current_matrix
,
14779 MATRIX_ROW_VPOS (r0
, current_matrix
),
14780 MATRIX_ROW_VPOS (r1
, current_matrix
),
14781 delta
, delta_bytes
);
14784 /* Set the cursor. */
14785 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14787 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14794 /* Handle the case that changes are all below what is displayed in
14795 the window, and that PT is in the window. This shortcut cannot
14796 be taken if ZV is visible in the window, and text has been added
14797 there that is visible in the window. */
14798 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14799 /* ZV is not visible in the window, or there are no
14800 changes at ZV, actually. */
14801 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14802 || first_changed_charpos
== last_changed_charpos
))
14804 struct glyph_row
*r0
;
14806 /* Give up if PT is not in the window. Note that it already has
14807 been checked at the start of try_window_id that PT is not in
14808 front of the window start. */
14809 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14812 /* If window start is unchanged, we can reuse the whole matrix
14813 as is, without changing glyph positions since no text has
14814 been added/removed in front of the window end. */
14815 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14816 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14817 /* PT must not be in a partially visible line. */
14818 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14819 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14821 /* We have to compute the window end anew since text
14822 can have been added/removed after it. */
14824 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14825 w
->window_end_bytepos
14826 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14828 /* Set the cursor. */
14829 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14831 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14838 /* Give up if window start is in the changed area.
14840 The condition used to read
14842 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14844 but why that was tested escapes me at the moment. */
14845 if (CHARPOS (start
) >= first_changed_charpos
14846 && CHARPOS (start
) <= last_changed_charpos
)
14849 /* Check that window start agrees with the start of the first glyph
14850 row in its current matrix. Check this after we know the window
14851 start is not in changed text, otherwise positions would not be
14853 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14854 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14857 /* Give up if the window ends in strings. Overlay strings
14858 at the end are difficult to handle, so don't try. */
14859 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14860 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14863 /* Compute the position at which we have to start displaying new
14864 lines. Some of the lines at the top of the window might be
14865 reusable because they are not displaying changed text. Find the
14866 last row in W's current matrix not affected by changes at the
14867 start of current_buffer. Value is null if changes start in the
14868 first line of window. */
14869 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14870 if (last_unchanged_at_beg_row
)
14872 /* Avoid starting to display in the moddle of a character, a TAB
14873 for instance. This is easier than to set up the iterator
14874 exactly, and it's not a frequent case, so the additional
14875 effort wouldn't really pay off. */
14876 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14877 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14878 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14879 --last_unchanged_at_beg_row
;
14881 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14884 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14886 start_pos
= it
.current
.pos
;
14888 /* Start displaying new lines in the desired matrix at the same
14889 vpos we would use in the current matrix, i.e. below
14890 last_unchanged_at_beg_row. */
14891 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14893 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14894 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14896 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14900 /* There are no reusable lines at the start of the window.
14901 Start displaying in the first text line. */
14902 start_display (&it
, w
, start
);
14903 it
.vpos
= it
.first_vpos
;
14904 start_pos
= it
.current
.pos
;
14907 /* Find the first row that is not affected by changes at the end of
14908 the buffer. Value will be null if there is no unchanged row, in
14909 which case we must redisplay to the end of the window. delta
14910 will be set to the value by which buffer positions beginning with
14911 first_unchanged_at_end_row have to be adjusted due to text
14913 first_unchanged_at_end_row
14914 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14915 IF_DEBUG (debug_delta
= delta
);
14916 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14918 /* Set stop_pos to the buffer position up to which we will have to
14919 display new lines. If first_unchanged_at_end_row != NULL, this
14920 is the buffer position of the start of the line displayed in that
14921 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14922 that we don't stop at a buffer position. */
14924 if (first_unchanged_at_end_row
)
14926 xassert (last_unchanged_at_beg_row
== NULL
14927 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14929 /* If this is a continuation line, move forward to the next one
14930 that isn't. Changes in lines above affect this line.
14931 Caution: this may move first_unchanged_at_end_row to a row
14932 not displaying text. */
14933 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14934 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14935 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14936 < it
.last_visible_y
))
14937 ++first_unchanged_at_end_row
;
14939 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14940 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14941 >= it
.last_visible_y
))
14942 first_unchanged_at_end_row
= NULL
;
14945 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14947 first_unchanged_at_end_vpos
14948 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14949 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14952 else if (last_unchanged_at_beg_row
== NULL
)
14958 /* Either there is no unchanged row at the end, or the one we have
14959 now displays text. This is a necessary condition for the window
14960 end pos calculation at the end of this function. */
14961 xassert (first_unchanged_at_end_row
== NULL
14962 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14964 debug_last_unchanged_at_beg_vpos
14965 = (last_unchanged_at_beg_row
14966 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14968 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14970 #endif /* GLYPH_DEBUG != 0 */
14973 /* Display new lines. Set last_text_row to the last new line
14974 displayed which has text on it, i.e. might end up as being the
14975 line where the window_end_vpos is. */
14976 w
->cursor
.vpos
= -1;
14977 last_text_row
= NULL
;
14978 overlay_arrow_seen
= 0;
14979 while (it
.current_y
< it
.last_visible_y
14980 && !fonts_changed_p
14981 && (first_unchanged_at_end_row
== NULL
14982 || IT_CHARPOS (it
) < stop_pos
))
14984 if (display_line (&it
))
14985 last_text_row
= it
.glyph_row
- 1;
14988 if (fonts_changed_p
)
14992 /* Compute differences in buffer positions, y-positions etc. for
14993 lines reused at the bottom of the window. Compute what we can
14995 if (first_unchanged_at_end_row
14996 /* No lines reused because we displayed everything up to the
14997 bottom of the window. */
14998 && it
.current_y
< it
.last_visible_y
)
15001 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15003 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15004 run
.current_y
= first_unchanged_at_end_row
->y
;
15005 run
.desired_y
= run
.current_y
+ dy
;
15006 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15010 delta
= delta_bytes
= dvpos
= dy
15011 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15012 first_unchanged_at_end_row
= NULL
;
15014 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15017 /* Find the cursor if not already found. We have to decide whether
15018 PT will appear on this window (it sometimes doesn't, but this is
15019 not a very frequent case.) This decision has to be made before
15020 the current matrix is altered. A value of cursor.vpos < 0 means
15021 that PT is either in one of the lines beginning at
15022 first_unchanged_at_end_row or below the window. Don't care for
15023 lines that might be displayed later at the window end; as
15024 mentioned, this is not a frequent case. */
15025 if (w
->cursor
.vpos
< 0)
15027 /* Cursor in unchanged rows at the top? */
15028 if (PT
< CHARPOS (start_pos
)
15029 && last_unchanged_at_beg_row
)
15031 row
= row_containing_pos (w
, PT
,
15032 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15033 last_unchanged_at_beg_row
+ 1, 0);
15035 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15038 /* Start from first_unchanged_at_end_row looking for PT. */
15039 else if (first_unchanged_at_end_row
)
15041 row
= row_containing_pos (w
, PT
- delta
,
15042 first_unchanged_at_end_row
, NULL
, 0);
15044 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15045 delta_bytes
, dy
, dvpos
);
15048 /* Give up if cursor was not found. */
15049 if (w
->cursor
.vpos
< 0)
15051 clear_glyph_matrix (w
->desired_matrix
);
15056 /* Don't let the cursor end in the scroll margins. */
15058 int this_scroll_margin
, cursor_height
;
15060 this_scroll_margin
= max (0, scroll_margin
);
15061 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15062 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15063 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15065 if ((w
->cursor
.y
< this_scroll_margin
15066 && CHARPOS (start
) > BEGV
)
15067 /* Old redisplay didn't take scroll margin into account at the bottom,
15068 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15069 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15070 ? cursor_height
+ this_scroll_margin
15071 : 1)) > it
.last_visible_y
)
15073 w
->cursor
.vpos
= -1;
15074 clear_glyph_matrix (w
->desired_matrix
);
15079 /* Scroll the display. Do it before changing the current matrix so
15080 that xterm.c doesn't get confused about where the cursor glyph is
15082 if (dy
&& run
.height
)
15086 if (FRAME_WINDOW_P (f
))
15088 FRAME_RIF (f
)->update_window_begin_hook (w
);
15089 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15090 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15091 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15095 /* Terminal frame. In this case, dvpos gives the number of
15096 lines to scroll by; dvpos < 0 means scroll up. */
15097 int first_unchanged_at_end_vpos
15098 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15099 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15100 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15101 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15102 + window_internal_height (w
));
15104 /* Perform the operation on the screen. */
15107 /* Scroll last_unchanged_at_beg_row to the end of the
15108 window down dvpos lines. */
15109 set_terminal_window (f
, end
);
15111 /* On dumb terminals delete dvpos lines at the end
15112 before inserting dvpos empty lines. */
15113 if (!FRAME_SCROLL_REGION_OK (f
))
15114 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15116 /* Insert dvpos empty lines in front of
15117 last_unchanged_at_beg_row. */
15118 ins_del_lines (f
, from
, dvpos
);
15120 else if (dvpos
< 0)
15122 /* Scroll up last_unchanged_at_beg_vpos to the end of
15123 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15124 set_terminal_window (f
, end
);
15126 /* Delete dvpos lines in front of
15127 last_unchanged_at_beg_vpos. ins_del_lines will set
15128 the cursor to the given vpos and emit |dvpos| delete
15130 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15132 /* On a dumb terminal insert dvpos empty lines at the
15134 if (!FRAME_SCROLL_REGION_OK (f
))
15135 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15138 set_terminal_window (f
, 0);
15144 /* Shift reused rows of the current matrix to the right position.
15145 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15147 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15148 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15151 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15152 bottom_vpos
, dvpos
);
15153 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15156 else if (dvpos
> 0)
15158 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15159 bottom_vpos
, dvpos
);
15160 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15161 first_unchanged_at_end_vpos
+ dvpos
, 0);
15164 /* For frame-based redisplay, make sure that current frame and window
15165 matrix are in sync with respect to glyph memory. */
15166 if (!FRAME_WINDOW_P (f
))
15167 sync_frame_with_window_matrix_rows (w
);
15169 /* Adjust buffer positions in reused rows. */
15170 if (delta
|| delta_bytes
)
15171 increment_matrix_positions (current_matrix
,
15172 first_unchanged_at_end_vpos
+ dvpos
,
15173 bottom_vpos
, delta
, delta_bytes
);
15175 /* Adjust Y positions. */
15177 shift_glyph_matrix (w
, current_matrix
,
15178 first_unchanged_at_end_vpos
+ dvpos
,
15181 if (first_unchanged_at_end_row
)
15183 first_unchanged_at_end_row
+= dvpos
;
15184 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15185 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15186 first_unchanged_at_end_row
= NULL
;
15189 /* If scrolling up, there may be some lines to display at the end of
15191 last_text_row_at_end
= NULL
;
15194 /* Scrolling up can leave for example a partially visible line
15195 at the end of the window to be redisplayed. */
15196 /* Set last_row to the glyph row in the current matrix where the
15197 window end line is found. It has been moved up or down in
15198 the matrix by dvpos. */
15199 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15200 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15202 /* If last_row is the window end line, it should display text. */
15203 xassert (last_row
->displays_text_p
);
15205 /* If window end line was partially visible before, begin
15206 displaying at that line. Otherwise begin displaying with the
15207 line following it. */
15208 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15210 init_to_row_start (&it
, w
, last_row
);
15211 it
.vpos
= last_vpos
;
15212 it
.current_y
= last_row
->y
;
15216 init_to_row_end (&it
, w
, last_row
);
15217 it
.vpos
= 1 + last_vpos
;
15218 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15222 /* We may start in a continuation line. If so, we have to
15223 get the right continuation_lines_width and current_x. */
15224 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15225 it
.hpos
= it
.current_x
= 0;
15227 /* Display the rest of the lines at the window end. */
15228 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15229 while (it
.current_y
< it
.last_visible_y
15230 && !fonts_changed_p
)
15232 /* Is it always sure that the display agrees with lines in
15233 the current matrix? I don't think so, so we mark rows
15234 displayed invalid in the current matrix by setting their
15235 enabled_p flag to zero. */
15236 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15237 if (display_line (&it
))
15238 last_text_row_at_end
= it
.glyph_row
- 1;
15242 /* Update window_end_pos and window_end_vpos. */
15243 if (first_unchanged_at_end_row
15244 && !last_text_row_at_end
)
15246 /* Window end line if one of the preserved rows from the current
15247 matrix. Set row to the last row displaying text in current
15248 matrix starting at first_unchanged_at_end_row, after
15250 xassert (first_unchanged_at_end_row
->displays_text_p
);
15251 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15252 first_unchanged_at_end_row
);
15253 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15255 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15256 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15258 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15259 xassert (w
->window_end_bytepos
>= 0);
15260 IF_DEBUG (debug_method_add (w
, "A"));
15262 else if (last_text_row_at_end
)
15265 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15266 w
->window_end_bytepos
15267 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15269 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15270 xassert (w
->window_end_bytepos
>= 0);
15271 IF_DEBUG (debug_method_add (w
, "B"));
15273 else if (last_text_row
)
15275 /* We have displayed either to the end of the window or at the
15276 end of the window, i.e. the last row with text is to be found
15277 in the desired matrix. */
15279 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15280 w
->window_end_bytepos
15281 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15283 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15284 xassert (w
->window_end_bytepos
>= 0);
15286 else if (first_unchanged_at_end_row
== NULL
15287 && last_text_row
== NULL
15288 && last_text_row_at_end
== NULL
)
15290 /* Displayed to end of window, but no line containing text was
15291 displayed. Lines were deleted at the end of the window. */
15292 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15293 int vpos
= XFASTINT (w
->window_end_vpos
);
15294 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15295 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15298 row
== NULL
&& vpos
>= first_vpos
;
15299 --vpos
, --current_row
, --desired_row
)
15301 if (desired_row
->enabled_p
)
15303 if (desired_row
->displays_text_p
)
15306 else if (current_row
->displays_text_p
)
15310 xassert (row
!= NULL
);
15311 w
->window_end_vpos
= make_number (vpos
+ 1);
15312 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15313 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15314 xassert (w
->window_end_bytepos
>= 0);
15315 IF_DEBUG (debug_method_add (w
, "C"));
15320 #if 0 /* This leads to problems, for instance when the cursor is
15321 at ZV, and the cursor line displays no text. */
15322 /* Disable rows below what's displayed in the window. This makes
15323 debugging easier. */
15324 enable_glyph_matrix_rows (current_matrix
,
15325 XFASTINT (w
->window_end_vpos
) + 1,
15329 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15330 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15332 /* Record that display has not been completed. */
15333 w
->window_end_valid
= Qnil
;
15334 w
->desired_matrix
->no_scrolling_p
= 1;
15342 /***********************************************************************
15343 More debugging support
15344 ***********************************************************************/
15348 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15349 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15350 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15353 /* Dump the contents of glyph matrix MATRIX on stderr.
15355 GLYPHS 0 means don't show glyph contents.
15356 GLYPHS 1 means show glyphs in short form
15357 GLYPHS > 1 means show glyphs in long form. */
15360 dump_glyph_matrix (matrix
, glyphs
)
15361 struct glyph_matrix
*matrix
;
15365 for (i
= 0; i
< matrix
->nrows
; ++i
)
15366 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15370 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15371 the glyph row and area where the glyph comes from. */
15374 dump_glyph (row
, glyph
, area
)
15375 struct glyph_row
*row
;
15376 struct glyph
*glyph
;
15379 if (glyph
->type
== CHAR_GLYPH
)
15382 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15383 glyph
- row
->glyphs
[TEXT_AREA
],
15386 (BUFFERP (glyph
->object
)
15388 : (STRINGP (glyph
->object
)
15391 glyph
->pixel_width
,
15393 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15397 glyph
->left_box_line_p
,
15398 glyph
->right_box_line_p
);
15400 else if (glyph
->type
== STRETCH_GLYPH
)
15403 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15404 glyph
- row
->glyphs
[TEXT_AREA
],
15407 (BUFFERP (glyph
->object
)
15409 : (STRINGP (glyph
->object
)
15412 glyph
->pixel_width
,
15416 glyph
->left_box_line_p
,
15417 glyph
->right_box_line_p
);
15419 else if (glyph
->type
== IMAGE_GLYPH
)
15422 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15423 glyph
- row
->glyphs
[TEXT_AREA
],
15426 (BUFFERP (glyph
->object
)
15428 : (STRINGP (glyph
->object
)
15431 glyph
->pixel_width
,
15435 glyph
->left_box_line_p
,
15436 glyph
->right_box_line_p
);
15438 else if (glyph
->type
== COMPOSITE_GLYPH
)
15441 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15442 glyph
- row
->glyphs
[TEXT_AREA
],
15445 (BUFFERP (glyph
->object
)
15447 : (STRINGP (glyph
->object
)
15450 glyph
->pixel_width
,
15454 glyph
->left_box_line_p
,
15455 glyph
->right_box_line_p
);
15460 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15461 GLYPHS 0 means don't show glyph contents.
15462 GLYPHS 1 means show glyphs in short form
15463 GLYPHS > 1 means show glyphs in long form. */
15466 dump_glyph_row (row
, vpos
, glyphs
)
15467 struct glyph_row
*row
;
15472 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15473 fprintf (stderr
, "======================================================================\n");
15475 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15476 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15478 MATRIX_ROW_START_CHARPOS (row
),
15479 MATRIX_ROW_END_CHARPOS (row
),
15480 row
->used
[TEXT_AREA
],
15481 row
->contains_overlapping_glyphs_p
,
15483 row
->truncated_on_left_p
,
15484 row
->truncated_on_right_p
,
15486 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15487 row
->displays_text_p
,
15490 row
->ends_in_middle_of_char_p
,
15491 row
->starts_in_middle_of_char_p
,
15497 row
->visible_height
,
15500 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15501 row
->end
.overlay_string_index
,
15502 row
->continuation_lines_width
);
15503 fprintf (stderr
, "%9d %5d\n",
15504 CHARPOS (row
->start
.string_pos
),
15505 CHARPOS (row
->end
.string_pos
));
15506 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15507 row
->end
.dpvec_index
);
15514 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15516 struct glyph
*glyph
= row
->glyphs
[area
];
15517 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15519 /* Glyph for a line end in text. */
15520 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15523 if (glyph
< glyph_end
)
15524 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15526 for (; glyph
< glyph_end
; ++glyph
)
15527 dump_glyph (row
, glyph
, area
);
15530 else if (glyphs
== 1)
15534 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15536 char *s
= (char *) alloca (row
->used
[area
] + 1);
15539 for (i
= 0; i
< row
->used
[area
]; ++i
)
15541 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15542 if (glyph
->type
== CHAR_GLYPH
15543 && glyph
->u
.ch
< 0x80
15544 && glyph
->u
.ch
>= ' ')
15545 s
[i
] = glyph
->u
.ch
;
15551 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15557 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15558 Sdump_glyph_matrix
, 0, 1, "p",
15559 doc
: /* Dump the current matrix of the selected window to stderr.
15560 Shows contents of glyph row structures. With non-nil
15561 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15562 glyphs in short form, otherwise show glyphs in long form. */)
15564 Lisp_Object glyphs
;
15566 struct window
*w
= XWINDOW (selected_window
);
15567 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15569 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15570 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15571 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15572 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15573 fprintf (stderr
, "=============================================\n");
15574 dump_glyph_matrix (w
->current_matrix
,
15575 NILP (glyphs
) ? 0 : XINT (glyphs
));
15580 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15581 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15584 struct frame
*f
= XFRAME (selected_frame
);
15585 dump_glyph_matrix (f
->current_matrix
, 1);
15590 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15591 doc
: /* Dump glyph row ROW to stderr.
15592 GLYPH 0 means don't dump glyphs.
15593 GLYPH 1 means dump glyphs in short form.
15594 GLYPH > 1 or omitted means dump glyphs in long form. */)
15596 Lisp_Object row
, glyphs
;
15598 struct glyph_matrix
*matrix
;
15601 CHECK_NUMBER (row
);
15602 matrix
= XWINDOW (selected_window
)->current_matrix
;
15604 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15605 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15607 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15612 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15613 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15614 GLYPH 0 means don't dump glyphs.
15615 GLYPH 1 means dump glyphs in short form.
15616 GLYPH > 1 or omitted means dump glyphs in long form. */)
15618 Lisp_Object row
, glyphs
;
15620 struct frame
*sf
= SELECTED_FRAME ();
15621 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15624 CHECK_NUMBER (row
);
15626 if (vpos
>= 0 && vpos
< m
->nrows
)
15627 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15628 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15633 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15634 doc
: /* Toggle tracing of redisplay.
15635 With ARG, turn tracing on if and only if ARG is positive. */)
15640 trace_redisplay_p
= !trace_redisplay_p
;
15643 arg
= Fprefix_numeric_value (arg
);
15644 trace_redisplay_p
= XINT (arg
) > 0;
15651 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15652 doc
: /* Like `format', but print result to stderr.
15653 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15658 Lisp_Object s
= Fformat (nargs
, args
);
15659 fprintf (stderr
, "%s", SDATA (s
));
15663 #endif /* GLYPH_DEBUG */
15667 /***********************************************************************
15668 Building Desired Matrix Rows
15669 ***********************************************************************/
15671 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15672 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15674 static struct glyph_row
*
15675 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15677 Lisp_Object overlay_arrow_string
;
15679 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15680 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15681 struct buffer
*old
= current_buffer
;
15682 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15683 int arrow_len
= SCHARS (overlay_arrow_string
);
15684 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15685 const unsigned char *p
;
15688 int n_glyphs_before
;
15690 set_buffer_temp (buffer
);
15691 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15692 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15693 SET_TEXT_POS (it
.position
, 0, 0);
15695 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15697 while (p
< arrow_end
)
15699 Lisp_Object face
, ilisp
;
15701 /* Get the next character. */
15703 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15705 it
.c
= *p
, it
.len
= 1;
15708 /* Get its face. */
15709 ilisp
= make_number (p
- arrow_string
);
15710 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15711 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15713 /* Compute its width, get its glyphs. */
15714 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15715 SET_TEXT_POS (it
.position
, -1, -1);
15716 PRODUCE_GLYPHS (&it
);
15718 /* If this character doesn't fit any more in the line, we have
15719 to remove some glyphs. */
15720 if (it
.current_x
> it
.last_visible_x
)
15722 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15727 set_buffer_temp (old
);
15728 return it
.glyph_row
;
15732 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15733 glyphs are only inserted for terminal frames since we can't really
15734 win with truncation glyphs when partially visible glyphs are
15735 involved. Which glyphs to insert is determined by
15736 produce_special_glyphs. */
15739 insert_left_trunc_glyphs (it
)
15742 struct it truncate_it
;
15743 struct glyph
*from
, *end
, *to
, *toend
;
15745 xassert (!FRAME_WINDOW_P (it
->f
));
15747 /* Get the truncation glyphs. */
15749 truncate_it
.current_x
= 0;
15750 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15751 truncate_it
.glyph_row
= &scratch_glyph_row
;
15752 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15753 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15754 truncate_it
.object
= make_number (0);
15755 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15757 /* Overwrite glyphs from IT with truncation glyphs. */
15758 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15759 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15760 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15761 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15766 /* There may be padding glyphs left over. Overwrite them too. */
15767 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15769 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15775 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15779 /* Compute the pixel height and width of IT->glyph_row.
15781 Most of the time, ascent and height of a display line will be equal
15782 to the max_ascent and max_height values of the display iterator
15783 structure. This is not the case if
15785 1. We hit ZV without displaying anything. In this case, max_ascent
15786 and max_height will be zero.
15788 2. We have some glyphs that don't contribute to the line height.
15789 (The glyph row flag contributes_to_line_height_p is for future
15790 pixmap extensions).
15792 The first case is easily covered by using default values because in
15793 these cases, the line height does not really matter, except that it
15794 must not be zero. */
15797 compute_line_metrics (it
)
15800 struct glyph_row
*row
= it
->glyph_row
;
15803 if (FRAME_WINDOW_P (it
->f
))
15805 int i
, min_y
, max_y
;
15807 /* The line may consist of one space only, that was added to
15808 place the cursor on it. If so, the row's height hasn't been
15810 if (row
->height
== 0)
15812 if (it
->max_ascent
+ it
->max_descent
== 0)
15813 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15814 row
->ascent
= it
->max_ascent
;
15815 row
->height
= it
->max_ascent
+ it
->max_descent
;
15816 row
->phys_ascent
= it
->max_phys_ascent
;
15817 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15818 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15821 /* Compute the width of this line. */
15822 row
->pixel_width
= row
->x
;
15823 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15824 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15826 xassert (row
->pixel_width
>= 0);
15827 xassert (row
->ascent
>= 0 && row
->height
> 0);
15829 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15830 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15832 /* If first line's physical ascent is larger than its logical
15833 ascent, use the physical ascent, and make the row taller.
15834 This makes accented characters fully visible. */
15835 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15836 && row
->phys_ascent
> row
->ascent
)
15838 row
->height
+= row
->phys_ascent
- row
->ascent
;
15839 row
->ascent
= row
->phys_ascent
;
15842 /* Compute how much of the line is visible. */
15843 row
->visible_height
= row
->height
;
15845 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15846 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15848 if (row
->y
< min_y
)
15849 row
->visible_height
-= min_y
- row
->y
;
15850 if (row
->y
+ row
->height
> max_y
)
15851 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15855 row
->pixel_width
= row
->used
[TEXT_AREA
];
15856 if (row
->continued_p
)
15857 row
->pixel_width
-= it
->continuation_pixel_width
;
15858 else if (row
->truncated_on_right_p
)
15859 row
->pixel_width
-= it
->truncation_pixel_width
;
15860 row
->ascent
= row
->phys_ascent
= 0;
15861 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15862 row
->extra_line_spacing
= 0;
15865 /* Compute a hash code for this row. */
15867 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15868 for (i
= 0; i
< row
->used
[area
]; ++i
)
15869 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15870 + row
->glyphs
[area
][i
].u
.val
15871 + row
->glyphs
[area
][i
].face_id
15872 + row
->glyphs
[area
][i
].padding_p
15873 + (row
->glyphs
[area
][i
].type
<< 2));
15875 it
->max_ascent
= it
->max_descent
= 0;
15876 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15880 /* Append one space to the glyph row of iterator IT if doing a
15881 window-based redisplay. The space has the same face as
15882 IT->face_id. Value is non-zero if a space was added.
15884 This function is called to make sure that there is always one glyph
15885 at the end of a glyph row that the cursor can be set on under
15886 window-systems. (If there weren't such a glyph we would not know
15887 how wide and tall a box cursor should be displayed).
15889 At the same time this space let's a nicely handle clearing to the
15890 end of the line if the row ends in italic text. */
15893 append_space_for_newline (it
, default_face_p
)
15895 int default_face_p
;
15897 if (FRAME_WINDOW_P (it
->f
))
15899 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15901 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15902 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15904 /* Save some values that must not be changed.
15905 Must save IT->c and IT->len because otherwise
15906 ITERATOR_AT_END_P wouldn't work anymore after
15907 append_space_for_newline has been called. */
15908 enum display_element_type saved_what
= it
->what
;
15909 int saved_c
= it
->c
, saved_len
= it
->len
;
15910 int saved_x
= it
->current_x
;
15911 int saved_face_id
= it
->face_id
;
15912 struct text_pos saved_pos
;
15913 Lisp_Object saved_object
;
15916 saved_object
= it
->object
;
15917 saved_pos
= it
->position
;
15919 it
->what
= IT_CHARACTER
;
15920 bzero (&it
->position
, sizeof it
->position
);
15921 it
->object
= make_number (0);
15925 if (default_face_p
)
15926 it
->face_id
= DEFAULT_FACE_ID
;
15927 else if (it
->face_before_selective_p
)
15928 it
->face_id
= it
->saved_face_id
;
15929 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15930 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
15932 PRODUCE_GLYPHS (it
);
15934 it
->override_ascent
= -1;
15935 it
->constrain_row_ascent_descent_p
= 0;
15936 it
->current_x
= saved_x
;
15937 it
->object
= saved_object
;
15938 it
->position
= saved_pos
;
15939 it
->what
= saved_what
;
15940 it
->face_id
= saved_face_id
;
15941 it
->len
= saved_len
;
15951 /* Extend the face of the last glyph in the text area of IT->glyph_row
15952 to the end of the display line. Called from display_line.
15953 If the glyph row is empty, add a space glyph to it so that we
15954 know the face to draw. Set the glyph row flag fill_line_p. */
15957 extend_face_to_end_of_line (it
)
15961 struct frame
*f
= it
->f
;
15963 /* If line is already filled, do nothing. */
15964 if (it
->current_x
>= it
->last_visible_x
)
15967 /* Face extension extends the background and box of IT->face_id
15968 to the end of the line. If the background equals the background
15969 of the frame, we don't have to do anything. */
15970 if (it
->face_before_selective_p
)
15971 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15973 face
= FACE_FROM_ID (f
, it
->face_id
);
15975 if (FRAME_WINDOW_P (f
)
15976 && it
->glyph_row
->displays_text_p
15977 && face
->box
== FACE_NO_BOX
15978 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15982 /* Set the glyph row flag indicating that the face of the last glyph
15983 in the text area has to be drawn to the end of the text area. */
15984 it
->glyph_row
->fill_line_p
= 1;
15986 /* If current character of IT is not ASCII, make sure we have the
15987 ASCII face. This will be automatically undone the next time
15988 get_next_display_element returns a multibyte character. Note
15989 that the character will always be single byte in unibyte text. */
15990 if (!ASCII_CHAR_P (it
->c
))
15992 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
15995 if (FRAME_WINDOW_P (f
))
15997 /* If the row is empty, add a space with the current face of IT,
15998 so that we know which face to draw. */
15999 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16001 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16002 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16003 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16008 /* Save some values that must not be changed. */
16009 int saved_x
= it
->current_x
;
16010 struct text_pos saved_pos
;
16011 Lisp_Object saved_object
;
16012 enum display_element_type saved_what
= it
->what
;
16013 int saved_face_id
= it
->face_id
;
16015 saved_object
= it
->object
;
16016 saved_pos
= it
->position
;
16018 it
->what
= IT_CHARACTER
;
16019 bzero (&it
->position
, sizeof it
->position
);
16020 it
->object
= make_number (0);
16023 it
->face_id
= face
->id
;
16025 PRODUCE_GLYPHS (it
);
16027 while (it
->current_x
<= it
->last_visible_x
)
16028 PRODUCE_GLYPHS (it
);
16030 /* Don't count these blanks really. It would let us insert a left
16031 truncation glyph below and make us set the cursor on them, maybe. */
16032 it
->current_x
= saved_x
;
16033 it
->object
= saved_object
;
16034 it
->position
= saved_pos
;
16035 it
->what
= saved_what
;
16036 it
->face_id
= saved_face_id
;
16041 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16042 trailing whitespace. */
16045 trailing_whitespace_p (charpos
)
16048 int bytepos
= CHAR_TO_BYTE (charpos
);
16051 while (bytepos
< ZV_BYTE
16052 && (c
= FETCH_CHAR (bytepos
),
16053 c
== ' ' || c
== '\t'))
16056 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16058 if (bytepos
!= PT_BYTE
)
16065 /* Highlight trailing whitespace, if any, in ROW. */
16068 highlight_trailing_whitespace (f
, row
)
16070 struct glyph_row
*row
;
16072 int used
= row
->used
[TEXT_AREA
];
16076 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16077 struct glyph
*glyph
= start
+ used
- 1;
16079 /* Skip over glyphs inserted to display the cursor at the
16080 end of a line, for extending the face of the last glyph
16081 to the end of the line on terminals, and for truncation
16082 and continuation glyphs. */
16083 while (glyph
>= start
16084 && glyph
->type
== CHAR_GLYPH
16085 && INTEGERP (glyph
->object
))
16088 /* If last glyph is a space or stretch, and it's trailing
16089 whitespace, set the face of all trailing whitespace glyphs in
16090 IT->glyph_row to `trailing-whitespace'. */
16092 && BUFFERP (glyph
->object
)
16093 && (glyph
->type
== STRETCH_GLYPH
16094 || (glyph
->type
== CHAR_GLYPH
16095 && glyph
->u
.ch
== ' '))
16096 && trailing_whitespace_p (glyph
->charpos
))
16098 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16102 while (glyph
>= start
16103 && BUFFERP (glyph
->object
)
16104 && (glyph
->type
== STRETCH_GLYPH
16105 || (glyph
->type
== CHAR_GLYPH
16106 && glyph
->u
.ch
== ' ')))
16107 (glyph
--)->face_id
= face_id
;
16113 /* Value is non-zero if glyph row ROW in window W should be
16114 used to hold the cursor. */
16117 cursor_row_p (w
, row
)
16119 struct glyph_row
*row
;
16121 int cursor_row_p
= 1;
16123 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16125 /* Suppose the row ends on a string.
16126 Unless the row is continued, that means it ends on a newline
16127 in the string. If it's anything other than a display string
16128 (e.g. a before-string from an overlay), we don't want the
16129 cursor there. (This heuristic seems to give the optimal
16130 behavior for the various types of multi-line strings.) */
16131 if (CHARPOS (row
->end
.string_pos
) >= 0)
16133 if (row
->continued_p
)
16137 /* Check for `display' property. */
16138 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16139 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16140 struct glyph
*glyph
;
16143 for (glyph
= end
; glyph
>= beg
; --glyph
)
16144 if (STRINGP (glyph
->object
))
16147 = Fget_char_property (make_number (PT
),
16151 && display_prop_string_p (prop
, glyph
->object
));
16156 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16158 /* If the row ends in middle of a real character,
16159 and the line is continued, we want the cursor here.
16160 That's because MATRIX_ROW_END_CHARPOS would equal
16161 PT if PT is before the character. */
16162 if (!row
->ends_in_ellipsis_p
)
16163 cursor_row_p
= row
->continued_p
;
16165 /* If the row ends in an ellipsis, then
16166 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16167 We want that position to be displayed after the ellipsis. */
16170 /* If the row ends at ZV, display the cursor at the end of that
16171 row instead of at the start of the row below. */
16172 else if (row
->ends_at_zv_p
)
16178 return cursor_row_p
;
16182 /* Construct the glyph row IT->glyph_row in the desired matrix of
16183 IT->w from text at the current position of IT. See dispextern.h
16184 for an overview of struct it. Value is non-zero if
16185 IT->glyph_row displays text, as opposed to a line displaying ZV
16192 struct glyph_row
*row
= it
->glyph_row
;
16193 Lisp_Object overlay_arrow_string
;
16195 /* We always start displaying at hpos zero even if hscrolled. */
16196 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16198 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16199 >= it
->w
->desired_matrix
->nrows
)
16201 it
->w
->nrows_scale_factor
++;
16202 fonts_changed_p
= 1;
16206 /* Is IT->w showing the region? */
16207 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16209 /* Clear the result glyph row and enable it. */
16210 prepare_desired_row (row
);
16212 row
->y
= it
->current_y
;
16213 row
->start
= it
->start
;
16214 row
->continuation_lines_width
= it
->continuation_lines_width
;
16215 row
->displays_text_p
= 1;
16216 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16217 it
->starts_in_middle_of_char_p
= 0;
16219 /* Arrange the overlays nicely for our purposes. Usually, we call
16220 display_line on only one line at a time, in which case this
16221 can't really hurt too much, or we call it on lines which appear
16222 one after another in the buffer, in which case all calls to
16223 recenter_overlay_lists but the first will be pretty cheap. */
16224 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16226 /* Move over display elements that are not visible because we are
16227 hscrolled. This may stop at an x-position < IT->first_visible_x
16228 if the first glyph is partially visible or if we hit a line end. */
16229 if (it
->current_x
< it
->first_visible_x
)
16231 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16232 MOVE_TO_POS
| MOVE_TO_X
);
16235 /* Get the initial row height. This is either the height of the
16236 text hscrolled, if there is any, or zero. */
16237 row
->ascent
= it
->max_ascent
;
16238 row
->height
= it
->max_ascent
+ it
->max_descent
;
16239 row
->phys_ascent
= it
->max_phys_ascent
;
16240 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16241 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16243 /* Loop generating characters. The loop is left with IT on the next
16244 character to display. */
16247 int n_glyphs_before
, hpos_before
, x_before
;
16249 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16251 /* Retrieve the next thing to display. Value is zero if end of
16253 if (!get_next_display_element (it
))
16255 /* Maybe add a space at the end of this line that is used to
16256 display the cursor there under X. Set the charpos of the
16257 first glyph of blank lines not corresponding to any text
16259 #ifdef HAVE_WINDOW_SYSTEM
16260 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16261 row
->exact_window_width_line_p
= 1;
16263 #endif /* HAVE_WINDOW_SYSTEM */
16264 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16265 || row
->used
[TEXT_AREA
] == 0)
16267 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16268 row
->displays_text_p
= 0;
16270 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16271 && (!MINI_WINDOW_P (it
->w
)
16272 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16273 row
->indicate_empty_line_p
= 1;
16276 it
->continuation_lines_width
= 0;
16277 row
->ends_at_zv_p
= 1;
16281 /* Now, get the metrics of what we want to display. This also
16282 generates glyphs in `row' (which is IT->glyph_row). */
16283 n_glyphs_before
= row
->used
[TEXT_AREA
];
16286 /* Remember the line height so far in case the next element doesn't
16287 fit on the line. */
16288 if (!it
->truncate_lines_p
)
16290 ascent
= it
->max_ascent
;
16291 descent
= it
->max_descent
;
16292 phys_ascent
= it
->max_phys_ascent
;
16293 phys_descent
= it
->max_phys_descent
;
16296 PRODUCE_GLYPHS (it
);
16298 /* If this display element was in marginal areas, continue with
16300 if (it
->area
!= TEXT_AREA
)
16302 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16303 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16304 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16305 row
->phys_height
= max (row
->phys_height
,
16306 it
->max_phys_ascent
+ it
->max_phys_descent
);
16307 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16308 it
->max_extra_line_spacing
);
16309 set_iterator_to_next (it
, 1);
16313 /* Does the display element fit on the line? If we truncate
16314 lines, we should draw past the right edge of the window. If
16315 we don't truncate, we want to stop so that we can display the
16316 continuation glyph before the right margin. If lines are
16317 continued, there are two possible strategies for characters
16318 resulting in more than 1 glyph (e.g. tabs): Display as many
16319 glyphs as possible in this line and leave the rest for the
16320 continuation line, or display the whole element in the next
16321 line. Original redisplay did the former, so we do it also. */
16322 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16323 hpos_before
= it
->hpos
;
16326 if (/* Not a newline. */
16328 /* Glyphs produced fit entirely in the line. */
16329 && it
->current_x
< it
->last_visible_x
)
16331 it
->hpos
+= nglyphs
;
16332 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16333 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16334 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16335 row
->phys_height
= max (row
->phys_height
,
16336 it
->max_phys_ascent
+ it
->max_phys_descent
);
16337 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16338 it
->max_extra_line_spacing
);
16339 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16340 row
->x
= x
- it
->first_visible_x
;
16345 struct glyph
*glyph
;
16347 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16349 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16350 new_x
= x
+ glyph
->pixel_width
;
16352 if (/* Lines are continued. */
16353 !it
->truncate_lines_p
16354 && (/* Glyph doesn't fit on the line. */
16355 new_x
> it
->last_visible_x
16356 /* Or it fits exactly on a window system frame. */
16357 || (new_x
== it
->last_visible_x
16358 && FRAME_WINDOW_P (it
->f
))))
16360 /* End of a continued line. */
16363 || (new_x
== it
->last_visible_x
16364 && FRAME_WINDOW_P (it
->f
)))
16366 /* Current glyph is the only one on the line or
16367 fits exactly on the line. We must continue
16368 the line because we can't draw the cursor
16369 after the glyph. */
16370 row
->continued_p
= 1;
16371 it
->current_x
= new_x
;
16372 it
->continuation_lines_width
+= new_x
;
16374 if (i
== nglyphs
- 1)
16376 set_iterator_to_next (it
, 1);
16377 #ifdef HAVE_WINDOW_SYSTEM
16378 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16380 if (!get_next_display_element (it
))
16382 row
->exact_window_width_line_p
= 1;
16383 it
->continuation_lines_width
= 0;
16384 row
->continued_p
= 0;
16385 row
->ends_at_zv_p
= 1;
16387 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16389 row
->continued_p
= 0;
16390 row
->exact_window_width_line_p
= 1;
16393 #endif /* HAVE_WINDOW_SYSTEM */
16396 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16397 && !FRAME_WINDOW_P (it
->f
))
16399 /* A padding glyph that doesn't fit on this line.
16400 This means the whole character doesn't fit
16402 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16404 /* Fill the rest of the row with continuation
16405 glyphs like in 20.x. */
16406 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16407 < row
->glyphs
[1 + TEXT_AREA
])
16408 produce_special_glyphs (it
, IT_CONTINUATION
);
16410 row
->continued_p
= 1;
16411 it
->current_x
= x_before
;
16412 it
->continuation_lines_width
+= x_before
;
16414 /* Restore the height to what it was before the
16415 element not fitting on the line. */
16416 it
->max_ascent
= ascent
;
16417 it
->max_descent
= descent
;
16418 it
->max_phys_ascent
= phys_ascent
;
16419 it
->max_phys_descent
= phys_descent
;
16421 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16423 /* A TAB that extends past the right edge of the
16424 window. This produces a single glyph on
16425 window system frames. We leave the glyph in
16426 this row and let it fill the row, but don't
16427 consume the TAB. */
16428 it
->continuation_lines_width
+= it
->last_visible_x
;
16429 row
->ends_in_middle_of_char_p
= 1;
16430 row
->continued_p
= 1;
16431 glyph
->pixel_width
= it
->last_visible_x
- x
;
16432 it
->starts_in_middle_of_char_p
= 1;
16436 /* Something other than a TAB that draws past
16437 the right edge of the window. Restore
16438 positions to values before the element. */
16439 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16441 /* Display continuation glyphs. */
16442 if (!FRAME_WINDOW_P (it
->f
))
16443 produce_special_glyphs (it
, IT_CONTINUATION
);
16444 row
->continued_p
= 1;
16446 it
->current_x
= x_before
;
16447 it
->continuation_lines_width
+= x
;
16448 extend_face_to_end_of_line (it
);
16450 if (nglyphs
> 1 && i
> 0)
16452 row
->ends_in_middle_of_char_p
= 1;
16453 it
->starts_in_middle_of_char_p
= 1;
16456 /* Restore the height to what it was before the
16457 element not fitting on the line. */
16458 it
->max_ascent
= ascent
;
16459 it
->max_descent
= descent
;
16460 it
->max_phys_ascent
= phys_ascent
;
16461 it
->max_phys_descent
= phys_descent
;
16466 else if (new_x
> it
->first_visible_x
)
16468 /* Increment number of glyphs actually displayed. */
16471 if (x
< it
->first_visible_x
)
16472 /* Glyph is partially visible, i.e. row starts at
16473 negative X position. */
16474 row
->x
= x
- it
->first_visible_x
;
16478 /* Glyph is completely off the left margin of the
16479 window. This should not happen because of the
16480 move_it_in_display_line at the start of this
16481 function, unless the text display area of the
16482 window is empty. */
16483 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16487 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16488 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16489 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16490 row
->phys_height
= max (row
->phys_height
,
16491 it
->max_phys_ascent
+ it
->max_phys_descent
);
16492 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16493 it
->max_extra_line_spacing
);
16495 /* End of this display line if row is continued. */
16496 if (row
->continued_p
|| row
->ends_at_zv_p
)
16501 /* Is this a line end? If yes, we're also done, after making
16502 sure that a non-default face is extended up to the right
16503 margin of the window. */
16504 if (ITERATOR_AT_END_OF_LINE_P (it
))
16506 int used_before
= row
->used
[TEXT_AREA
];
16508 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16510 #ifdef HAVE_WINDOW_SYSTEM
16511 /* Add a space at the end of the line that is used to
16512 display the cursor there. */
16513 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16514 append_space_for_newline (it
, 0);
16515 #endif /* HAVE_WINDOW_SYSTEM */
16517 /* Extend the face to the end of the line. */
16518 extend_face_to_end_of_line (it
);
16520 /* Make sure we have the position. */
16521 if (used_before
== 0)
16522 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16524 /* Consume the line end. This skips over invisible lines. */
16525 set_iterator_to_next (it
, 1);
16526 it
->continuation_lines_width
= 0;
16530 /* Proceed with next display element. Note that this skips
16531 over lines invisible because of selective display. */
16532 set_iterator_to_next (it
, 1);
16534 /* If we truncate lines, we are done when the last displayed
16535 glyphs reach past the right margin of the window. */
16536 if (it
->truncate_lines_p
16537 && (FRAME_WINDOW_P (it
->f
)
16538 ? (it
->current_x
>= it
->last_visible_x
)
16539 : (it
->current_x
> it
->last_visible_x
)))
16541 /* Maybe add truncation glyphs. */
16542 if (!FRAME_WINDOW_P (it
->f
))
16546 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16547 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16550 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16552 row
->used
[TEXT_AREA
] = i
;
16553 produce_special_glyphs (it
, IT_TRUNCATION
);
16556 #ifdef HAVE_WINDOW_SYSTEM
16559 /* Don't truncate if we can overflow newline into fringe. */
16560 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16562 if (!get_next_display_element (it
))
16564 it
->continuation_lines_width
= 0;
16565 row
->ends_at_zv_p
= 1;
16566 row
->exact_window_width_line_p
= 1;
16569 if (ITERATOR_AT_END_OF_LINE_P (it
))
16571 row
->exact_window_width_line_p
= 1;
16572 goto at_end_of_line
;
16576 #endif /* HAVE_WINDOW_SYSTEM */
16578 row
->truncated_on_right_p
= 1;
16579 it
->continuation_lines_width
= 0;
16580 reseat_at_next_visible_line_start (it
, 0);
16581 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16582 it
->hpos
= hpos_before
;
16583 it
->current_x
= x_before
;
16588 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16589 at the left window margin. */
16590 if (it
->first_visible_x
16591 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16593 if (!FRAME_WINDOW_P (it
->f
))
16594 insert_left_trunc_glyphs (it
);
16595 row
->truncated_on_left_p
= 1;
16598 /* If the start of this line is the overlay arrow-position, then
16599 mark this glyph row as the one containing the overlay arrow.
16600 This is clearly a mess with variable size fonts. It would be
16601 better to let it be displayed like cursors under X. */
16602 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16603 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16604 !NILP (overlay_arrow_string
)))
16606 /* Overlay arrow in window redisplay is a fringe bitmap. */
16607 if (STRINGP (overlay_arrow_string
))
16609 struct glyph_row
*arrow_row
16610 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16611 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16612 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16613 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16614 struct glyph
*p2
, *end
;
16616 /* Copy the arrow glyphs. */
16617 while (glyph
< arrow_end
)
16620 /* Throw away padding glyphs. */
16622 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16623 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16629 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16634 xassert (INTEGERP (overlay_arrow_string
));
16635 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16637 overlay_arrow_seen
= 1;
16640 /* Compute pixel dimensions of this line. */
16641 compute_line_metrics (it
);
16643 /* Remember the position at which this line ends. */
16644 row
->end
= it
->current
;
16646 /* Record whether this row ends inside an ellipsis. */
16647 row
->ends_in_ellipsis_p
16648 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16649 && it
->ellipsis_p
);
16651 /* Save fringe bitmaps in this row. */
16652 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16653 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16654 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16655 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16657 it
->left_user_fringe_bitmap
= 0;
16658 it
->left_user_fringe_face_id
= 0;
16659 it
->right_user_fringe_bitmap
= 0;
16660 it
->right_user_fringe_face_id
= 0;
16662 /* Maybe set the cursor. */
16663 if (it
->w
->cursor
.vpos
< 0
16664 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16665 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16666 && cursor_row_p (it
->w
, row
))
16667 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16669 /* Highlight trailing whitespace. */
16670 if (!NILP (Vshow_trailing_whitespace
))
16671 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16673 /* Prepare for the next line. This line starts horizontally at (X
16674 HPOS) = (0 0). Vertical positions are incremented. As a
16675 convenience for the caller, IT->glyph_row is set to the next
16677 it
->current_x
= it
->hpos
= 0;
16678 it
->current_y
+= row
->height
;
16681 it
->start
= it
->current
;
16682 return row
->displays_text_p
;
16687 /***********************************************************************
16689 ***********************************************************************/
16691 /* Redisplay the menu bar in the frame for window W.
16693 The menu bar of X frames that don't have X toolkit support is
16694 displayed in a special window W->frame->menu_bar_window.
16696 The menu bar of terminal frames is treated specially as far as
16697 glyph matrices are concerned. Menu bar lines are not part of
16698 windows, so the update is done directly on the frame matrix rows
16699 for the menu bar. */
16702 display_menu_bar (w
)
16705 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16710 /* Don't do all this for graphical frames. */
16712 if (FRAME_W32_P (f
))
16715 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16720 if (FRAME_MAC_P (f
))
16724 #ifdef USE_X_TOOLKIT
16725 xassert (!FRAME_WINDOW_P (f
));
16726 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16727 it
.first_visible_x
= 0;
16728 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16729 #else /* not USE_X_TOOLKIT */
16730 if (FRAME_WINDOW_P (f
))
16732 /* Menu bar lines are displayed in the desired matrix of the
16733 dummy window menu_bar_window. */
16734 struct window
*menu_w
;
16735 xassert (WINDOWP (f
->menu_bar_window
));
16736 menu_w
= XWINDOW (f
->menu_bar_window
);
16737 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16739 it
.first_visible_x
= 0;
16740 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16744 /* This is a TTY frame, i.e. character hpos/vpos are used as
16746 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16748 it
.first_visible_x
= 0;
16749 it
.last_visible_x
= FRAME_COLS (f
);
16751 #endif /* not USE_X_TOOLKIT */
16753 if (! mode_line_inverse_video
)
16754 /* Force the menu-bar to be displayed in the default face. */
16755 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16757 /* Clear all rows of the menu bar. */
16758 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16760 struct glyph_row
*row
= it
.glyph_row
+ i
;
16761 clear_glyph_row (row
);
16762 row
->enabled_p
= 1;
16763 row
->full_width_p
= 1;
16766 /* Display all items of the menu bar. */
16767 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16768 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16770 Lisp_Object string
;
16772 /* Stop at nil string. */
16773 string
= AREF (items
, i
+ 1);
16777 /* Remember where item was displayed. */
16778 ASET (items
, i
+ 3, make_number (it
.hpos
));
16780 /* Display the item, pad with one space. */
16781 if (it
.current_x
< it
.last_visible_x
)
16782 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16783 SCHARS (string
) + 1, 0, 0, -1);
16786 /* Fill out the line with spaces. */
16787 if (it
.current_x
< it
.last_visible_x
)
16788 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16790 /* Compute the total height of the lines. */
16791 compute_line_metrics (&it
);
16796 /***********************************************************************
16798 ***********************************************************************/
16800 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16801 FORCE is non-zero, redisplay mode lines unconditionally.
16802 Otherwise, redisplay only mode lines that are garbaged. Value is
16803 the number of windows whose mode lines were redisplayed. */
16806 redisplay_mode_lines (window
, force
)
16807 Lisp_Object window
;
16812 while (!NILP (window
))
16814 struct window
*w
= XWINDOW (window
);
16816 if (WINDOWP (w
->hchild
))
16817 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16818 else if (WINDOWP (w
->vchild
))
16819 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16821 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16822 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16824 struct text_pos lpoint
;
16825 struct buffer
*old
= current_buffer
;
16827 /* Set the window's buffer for the mode line display. */
16828 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16829 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16831 /* Point refers normally to the selected window. For any
16832 other window, set up appropriate value. */
16833 if (!EQ (window
, selected_window
))
16835 struct text_pos pt
;
16837 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16838 if (CHARPOS (pt
) < BEGV
)
16839 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16840 else if (CHARPOS (pt
) > (ZV
- 1))
16841 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16843 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16846 /* Display mode lines. */
16847 clear_glyph_matrix (w
->desired_matrix
);
16848 if (display_mode_lines (w
))
16851 w
->must_be_updated_p
= 1;
16854 /* Restore old settings. */
16855 set_buffer_internal_1 (old
);
16856 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16866 /* Display the mode and/or top line of window W. Value is the number
16867 of mode lines displayed. */
16870 display_mode_lines (w
)
16873 Lisp_Object old_selected_window
, old_selected_frame
;
16876 old_selected_frame
= selected_frame
;
16877 selected_frame
= w
->frame
;
16878 old_selected_window
= selected_window
;
16879 XSETWINDOW (selected_window
, w
);
16881 /* These will be set while the mode line specs are processed. */
16882 line_number_displayed
= 0;
16883 w
->column_number_displayed
= Qnil
;
16885 if (WINDOW_WANTS_MODELINE_P (w
))
16887 struct window
*sel_w
= XWINDOW (old_selected_window
);
16889 /* Select mode line face based on the real selected window. */
16890 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16891 current_buffer
->mode_line_format
);
16895 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16897 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16898 current_buffer
->header_line_format
);
16902 selected_frame
= old_selected_frame
;
16903 selected_window
= old_selected_window
;
16908 /* Display mode or top line of window W. FACE_ID specifies which line
16909 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16910 FORMAT is the mode line format to display. Value is the pixel
16911 height of the mode line displayed. */
16914 display_mode_line (w
, face_id
, format
)
16916 enum face_id face_id
;
16917 Lisp_Object format
;
16921 int count
= SPECPDL_INDEX ();
16923 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16924 /* Don't extend on a previously drawn mode-line.
16925 This may happen if called from pos_visible_p. */
16926 it
.glyph_row
->enabled_p
= 0;
16927 prepare_desired_row (it
.glyph_row
);
16929 it
.glyph_row
->mode_line_p
= 1;
16931 if (! mode_line_inverse_video
)
16932 /* Force the mode-line to be displayed in the default face. */
16933 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16935 record_unwind_protect (unwind_format_mode_line
,
16936 format_mode_line_unwind_data (NULL
, Qnil
, 0));
16938 mode_line_target
= MODE_LINE_DISPLAY
;
16940 /* Temporarily make frame's keyboard the current kboard so that
16941 kboard-local variables in the mode_line_format will get the right
16943 push_kboard (FRAME_KBOARD (it
.f
));
16944 record_unwind_save_match_data ();
16945 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16948 unbind_to (count
, Qnil
);
16950 /* Fill up with spaces. */
16951 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16953 compute_line_metrics (&it
);
16954 it
.glyph_row
->full_width_p
= 1;
16955 it
.glyph_row
->continued_p
= 0;
16956 it
.glyph_row
->truncated_on_left_p
= 0;
16957 it
.glyph_row
->truncated_on_right_p
= 0;
16959 /* Make a 3D mode-line have a shadow at its right end. */
16960 face
= FACE_FROM_ID (it
.f
, face_id
);
16961 extend_face_to_end_of_line (&it
);
16962 if (face
->box
!= FACE_NO_BOX
)
16964 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16965 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16966 last
->right_box_line_p
= 1;
16969 return it
.glyph_row
->height
;
16972 /* Move element ELT in LIST to the front of LIST.
16973 Return the updated list. */
16976 move_elt_to_front (elt
, list
)
16977 Lisp_Object elt
, list
;
16979 register Lisp_Object tail
, prev
;
16980 register Lisp_Object tem
;
16984 while (CONSP (tail
))
16990 /* Splice out the link TAIL. */
16992 list
= XCDR (tail
);
16994 Fsetcdr (prev
, XCDR (tail
));
16996 /* Now make it the first. */
16997 Fsetcdr (tail
, list
);
17002 tail
= XCDR (tail
);
17006 /* Not found--return unchanged LIST. */
17010 /* Contribute ELT to the mode line for window IT->w. How it
17011 translates into text depends on its data type.
17013 IT describes the display environment in which we display, as usual.
17015 DEPTH is the depth in recursion. It is used to prevent
17016 infinite recursion here.
17018 FIELD_WIDTH is the number of characters the display of ELT should
17019 occupy in the mode line, and PRECISION is the maximum number of
17020 characters to display from ELT's representation. See
17021 display_string for details.
17023 Returns the hpos of the end of the text generated by ELT.
17025 PROPS is a property list to add to any string we encounter.
17027 If RISKY is nonzero, remove (disregard) any properties in any string
17028 we encounter, and ignore :eval and :propertize.
17030 The global variable `mode_line_target' determines whether the
17031 output is passed to `store_mode_line_noprop',
17032 `store_mode_line_string', or `display_string'. */
17035 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17038 int field_width
, precision
;
17039 Lisp_Object elt
, props
;
17042 int n
= 0, field
, prec
;
17047 elt
= build_string ("*too-deep*");
17051 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17055 /* A string: output it and check for %-constructs within it. */
17059 if (SCHARS (elt
) > 0
17060 && (!NILP (props
) || risky
))
17062 Lisp_Object oprops
, aelt
;
17063 oprops
= Ftext_properties_at (make_number (0), elt
);
17065 /* If the starting string's properties are not what
17066 we want, translate the string. Also, if the string
17067 is risky, do that anyway. */
17069 if (NILP (Fequal (props
, oprops
)) || risky
)
17071 /* If the starting string has properties,
17072 merge the specified ones onto the existing ones. */
17073 if (! NILP (oprops
) && !risky
)
17077 oprops
= Fcopy_sequence (oprops
);
17079 while (CONSP (tem
))
17081 oprops
= Fplist_put (oprops
, XCAR (tem
),
17082 XCAR (XCDR (tem
)));
17083 tem
= XCDR (XCDR (tem
));
17088 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17089 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17091 /* AELT is what we want. Move it to the front
17092 without consing. */
17094 mode_line_proptrans_alist
17095 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17101 /* If AELT has the wrong props, it is useless.
17102 so get rid of it. */
17104 mode_line_proptrans_alist
17105 = Fdelq (aelt
, mode_line_proptrans_alist
);
17107 elt
= Fcopy_sequence (elt
);
17108 Fset_text_properties (make_number (0), Flength (elt
),
17110 /* Add this item to mode_line_proptrans_alist. */
17111 mode_line_proptrans_alist
17112 = Fcons (Fcons (elt
, props
),
17113 mode_line_proptrans_alist
);
17114 /* Truncate mode_line_proptrans_alist
17115 to at most 50 elements. */
17116 tem
= Fnthcdr (make_number (50),
17117 mode_line_proptrans_alist
);
17119 XSETCDR (tem
, Qnil
);
17128 prec
= precision
- n
;
17129 switch (mode_line_target
)
17131 case MODE_LINE_NOPROP
:
17132 case MODE_LINE_TITLE
:
17133 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17135 case MODE_LINE_STRING
:
17136 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17138 case MODE_LINE_DISPLAY
:
17139 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17140 0, prec
, 0, STRING_MULTIBYTE (elt
));
17147 /* Handle the non-literal case. */
17149 while ((precision
<= 0 || n
< precision
)
17150 && SREF (elt
, offset
) != 0
17151 && (mode_line_target
!= MODE_LINE_DISPLAY
17152 || it
->current_x
< it
->last_visible_x
))
17154 int last_offset
= offset
;
17156 /* Advance to end of string or next format specifier. */
17157 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17160 if (offset
- 1 != last_offset
)
17162 int nchars
, nbytes
;
17164 /* Output to end of string or up to '%'. Field width
17165 is length of string. Don't output more than
17166 PRECISION allows us. */
17169 prec
= c_string_width (SDATA (elt
) + last_offset
,
17170 offset
- last_offset
, precision
- n
,
17173 switch (mode_line_target
)
17175 case MODE_LINE_NOPROP
:
17176 case MODE_LINE_TITLE
:
17177 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17179 case MODE_LINE_STRING
:
17181 int bytepos
= last_offset
;
17182 int charpos
= string_byte_to_char (elt
, bytepos
);
17183 int endpos
= (precision
<= 0
17184 ? string_byte_to_char (elt
, offset
)
17185 : charpos
+ nchars
);
17187 n
+= store_mode_line_string (NULL
,
17188 Fsubstring (elt
, make_number (charpos
),
17189 make_number (endpos
)),
17193 case MODE_LINE_DISPLAY
:
17195 int bytepos
= last_offset
;
17196 int charpos
= string_byte_to_char (elt
, bytepos
);
17198 if (precision
<= 0)
17199 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17200 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17202 STRING_MULTIBYTE (elt
));
17207 else /* c == '%' */
17209 int percent_position
= offset
;
17211 /* Get the specified minimum width. Zero means
17214 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17215 field
= field
* 10 + c
- '0';
17217 /* Don't pad beyond the total padding allowed. */
17218 if (field_width
- n
> 0 && field
> field_width
- n
)
17219 field
= field_width
- n
;
17221 /* Note that either PRECISION <= 0 or N < PRECISION. */
17222 prec
= precision
- n
;
17225 n
+= display_mode_element (it
, depth
, field
, prec
,
17226 Vglobal_mode_string
, props
,
17231 int bytepos
, charpos
;
17232 unsigned char *spec
;
17234 bytepos
= percent_position
;
17235 charpos
= (STRING_MULTIBYTE (elt
)
17236 ? string_byte_to_char (elt
, bytepos
)
17239 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17241 switch (mode_line_target
)
17243 case MODE_LINE_NOPROP
:
17244 case MODE_LINE_TITLE
:
17245 n
+= store_mode_line_noprop (spec
, field
, prec
);
17247 case MODE_LINE_STRING
:
17249 int len
= strlen (spec
);
17250 Lisp_Object tem
= make_string (spec
, len
);
17251 props
= Ftext_properties_at (make_number (charpos
), elt
);
17252 /* Should only keep face property in props */
17253 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17256 case MODE_LINE_DISPLAY
:
17258 int nglyphs_before
, nwritten
;
17260 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17261 nwritten
= display_string (spec
, Qnil
, elt
,
17266 /* Assign to the glyphs written above the
17267 string where the `%x' came from, position
17271 struct glyph
*glyph
17272 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17276 for (i
= 0; i
< nwritten
; ++i
)
17278 glyph
[i
].object
= elt
;
17279 glyph
[i
].charpos
= charpos
;
17296 /* A symbol: process the value of the symbol recursively
17297 as if it appeared here directly. Avoid error if symbol void.
17298 Special case: if value of symbol is a string, output the string
17301 register Lisp_Object tem
;
17303 /* If the variable is not marked as risky to set
17304 then its contents are risky to use. */
17305 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17308 tem
= Fboundp (elt
);
17311 tem
= Fsymbol_value (elt
);
17312 /* If value is a string, output that string literally:
17313 don't check for % within it. */
17317 if (!EQ (tem
, elt
))
17319 /* Give up right away for nil or t. */
17329 register Lisp_Object car
, tem
;
17331 /* A cons cell: five distinct cases.
17332 If first element is :eval or :propertize, do something special.
17333 If first element is a string or a cons, process all the elements
17334 and effectively concatenate them.
17335 If first element is a negative number, truncate displaying cdr to
17336 at most that many characters. If positive, pad (with spaces)
17337 to at least that many characters.
17338 If first element is a symbol, process the cadr or caddr recursively
17339 according to whether the symbol's value is non-nil or nil. */
17341 if (EQ (car
, QCeval
))
17343 /* An element of the form (:eval FORM) means evaluate FORM
17344 and use the result as mode line elements. */
17349 if (CONSP (XCDR (elt
)))
17352 spec
= safe_eval (XCAR (XCDR (elt
)));
17353 n
+= display_mode_element (it
, depth
, field_width
- n
,
17354 precision
- n
, spec
, props
,
17358 else if (EQ (car
, QCpropertize
))
17360 /* An element of the form (:propertize ELT PROPS...)
17361 means display ELT but applying properties PROPS. */
17366 if (CONSP (XCDR (elt
)))
17367 n
+= display_mode_element (it
, depth
, field_width
- n
,
17368 precision
- n
, XCAR (XCDR (elt
)),
17369 XCDR (XCDR (elt
)), risky
);
17371 else if (SYMBOLP (car
))
17373 tem
= Fboundp (car
);
17377 /* elt is now the cdr, and we know it is a cons cell.
17378 Use its car if CAR has a non-nil value. */
17381 tem
= Fsymbol_value (car
);
17388 /* Symbol's value is nil (or symbol is unbound)
17389 Get the cddr of the original list
17390 and if possible find the caddr and use that. */
17394 else if (!CONSP (elt
))
17399 else if (INTEGERP (car
))
17401 register int lim
= XINT (car
);
17405 /* Negative int means reduce maximum width. */
17406 if (precision
<= 0)
17409 precision
= min (precision
, -lim
);
17413 /* Padding specified. Don't let it be more than
17414 current maximum. */
17416 lim
= min (precision
, lim
);
17418 /* If that's more padding than already wanted, queue it.
17419 But don't reduce padding already specified even if
17420 that is beyond the current truncation point. */
17421 field_width
= max (lim
, field_width
);
17425 else if (STRINGP (car
) || CONSP (car
))
17427 register int limit
= 50;
17428 /* Limit is to protect against circular lists. */
17431 && (precision
<= 0 || n
< precision
))
17433 n
+= display_mode_element (it
, depth
,
17434 /* Do padding only after the last
17435 element in the list. */
17436 (! CONSP (XCDR (elt
))
17439 precision
- n
, XCAR (elt
),
17449 elt
= build_string ("*invalid*");
17453 /* Pad to FIELD_WIDTH. */
17454 if (field_width
> 0 && n
< field_width
)
17456 switch (mode_line_target
)
17458 case MODE_LINE_NOPROP
:
17459 case MODE_LINE_TITLE
:
17460 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17462 case MODE_LINE_STRING
:
17463 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17465 case MODE_LINE_DISPLAY
:
17466 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17475 /* Store a mode-line string element in mode_line_string_list.
17477 If STRING is non-null, display that C string. Otherwise, the Lisp
17478 string LISP_STRING is displayed.
17480 FIELD_WIDTH is the minimum number of output glyphs to produce.
17481 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17482 with spaces. FIELD_WIDTH <= 0 means don't pad.
17484 PRECISION is the maximum number of characters to output from
17485 STRING. PRECISION <= 0 means don't truncate the string.
17487 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17488 properties to the string.
17490 PROPS are the properties to add to the string.
17491 The mode_line_string_face face property is always added to the string.
17495 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17497 Lisp_Object lisp_string
;
17506 if (string
!= NULL
)
17508 len
= strlen (string
);
17509 if (precision
> 0 && len
> precision
)
17511 lisp_string
= make_string (string
, len
);
17513 props
= mode_line_string_face_prop
;
17514 else if (!NILP (mode_line_string_face
))
17516 Lisp_Object face
= Fplist_get (props
, Qface
);
17517 props
= Fcopy_sequence (props
);
17519 face
= mode_line_string_face
;
17521 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17522 props
= Fplist_put (props
, Qface
, face
);
17524 Fadd_text_properties (make_number (0), make_number (len
),
17525 props
, lisp_string
);
17529 len
= XFASTINT (Flength (lisp_string
));
17530 if (precision
> 0 && len
> precision
)
17533 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17536 if (!NILP (mode_line_string_face
))
17540 props
= Ftext_properties_at (make_number (0), lisp_string
);
17541 face
= Fplist_get (props
, Qface
);
17543 face
= mode_line_string_face
;
17545 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17546 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17548 lisp_string
= Fcopy_sequence (lisp_string
);
17551 Fadd_text_properties (make_number (0), make_number (len
),
17552 props
, lisp_string
);
17557 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17561 if (field_width
> len
)
17563 field_width
-= len
;
17564 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17566 Fadd_text_properties (make_number (0), make_number (field_width
),
17567 props
, lisp_string
);
17568 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17576 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17578 doc
: /* Format a string out of a mode line format specification.
17579 First arg FORMAT specifies the mode line format (see `mode-line-format'
17580 for details) to use.
17582 Optional second arg FACE specifies the face property to put
17583 on all characters for which no face is specified.
17584 The value t means whatever face the window's mode line currently uses
17585 \(either `mode-line' or `mode-line-inactive', depending).
17586 A value of nil means the default is no face property.
17587 If FACE is an integer, the value string has no text properties.
17589 Optional third and fourth args WINDOW and BUFFER specify the window
17590 and buffer to use as the context for the formatting (defaults
17591 are the selected window and the window's buffer). */)
17592 (format
, face
, window
, buffer
)
17593 Lisp_Object format
, face
, window
, buffer
;
17598 struct buffer
*old_buffer
= NULL
;
17600 int no_props
= INTEGERP (face
);
17601 int count
= SPECPDL_INDEX ();
17603 int string_start
= 0;
17606 window
= selected_window
;
17607 CHECK_WINDOW (window
);
17608 w
= XWINDOW (window
);
17611 buffer
= w
->buffer
;
17612 CHECK_BUFFER (buffer
);
17614 /* Make formatting the modeline a non-op when noninteractive, otherwise
17615 there will be problems later caused by a partially initialized frame. */
17616 if (NILP (format
) || noninteractive
)
17617 return empty_unibyte_string
;
17625 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17626 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17630 face_id
= DEFAULT_FACE_ID
;
17632 if (XBUFFER (buffer
) != current_buffer
)
17633 old_buffer
= current_buffer
;
17635 /* Save things including mode_line_proptrans_alist,
17636 and set that to nil so that we don't alter the outer value. */
17637 record_unwind_protect (unwind_format_mode_line
,
17638 format_mode_line_unwind_data
17639 (old_buffer
, selected_window
, 1));
17640 mode_line_proptrans_alist
= Qnil
;
17642 Fselect_window (window
, Qt
);
17644 set_buffer_internal_1 (XBUFFER (buffer
));
17646 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17650 mode_line_target
= MODE_LINE_NOPROP
;
17651 mode_line_string_face_prop
= Qnil
;
17652 mode_line_string_list
= Qnil
;
17653 string_start
= MODE_LINE_NOPROP_LEN (0);
17657 mode_line_target
= MODE_LINE_STRING
;
17658 mode_line_string_list
= Qnil
;
17659 mode_line_string_face
= face
;
17660 mode_line_string_face_prop
17661 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17664 push_kboard (FRAME_KBOARD (it
.f
));
17665 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17670 len
= MODE_LINE_NOPROP_LEN (string_start
);
17671 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17675 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17676 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17677 empty_unibyte_string
);
17680 unbind_to (count
, Qnil
);
17684 /* Write a null-terminated, right justified decimal representation of
17685 the positive integer D to BUF using a minimal field width WIDTH. */
17688 pint2str (buf
, width
, d
)
17689 register char *buf
;
17690 register int width
;
17693 register char *p
= buf
;
17701 *p
++ = d
% 10 + '0';
17706 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17717 /* Write a null-terminated, right justified decimal and "human
17718 readable" representation of the nonnegative integer D to BUF using
17719 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17721 static const char power_letter
[] =
17735 pint2hrstr (buf
, width
, d
)
17740 /* We aim to represent the nonnegative integer D as
17741 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17744 /* -1 means: do not use TENTHS. */
17748 /* Length of QUOTIENT.TENTHS as a string. */
17754 if (1000 <= quotient
)
17756 /* Scale to the appropriate EXPONENT. */
17759 remainder
= quotient
% 1000;
17763 while (1000 <= quotient
);
17765 /* Round to nearest and decide whether to use TENTHS or not. */
17768 tenths
= remainder
/ 100;
17769 if (50 <= remainder
% 100)
17776 if (quotient
== 10)
17784 if (500 <= remainder
)
17786 if (quotient
< 999)
17797 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17798 if (tenths
== -1 && quotient
<= 99)
17805 p
= psuffix
= buf
+ max (width
, length
);
17807 /* Print EXPONENT. */
17809 *psuffix
++ = power_letter
[exponent
];
17812 /* Print TENTHS. */
17815 *--p
= '0' + tenths
;
17819 /* Print QUOTIENT. */
17822 int digit
= quotient
% 10;
17823 *--p
= '0' + digit
;
17825 while ((quotient
/= 10) != 0);
17827 /* Print leading spaces. */
17832 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17833 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17834 type of CODING_SYSTEM. Return updated pointer into BUF. */
17836 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17839 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17840 Lisp_Object coding_system
;
17841 register char *buf
;
17845 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17846 const unsigned char *eol_str
;
17848 /* The EOL conversion we are using. */
17849 Lisp_Object eoltype
;
17851 val
= CODING_SYSTEM_SPEC (coding_system
);
17854 if (!VECTORP (val
)) /* Not yet decided. */
17859 eoltype
= eol_mnemonic_undecided
;
17860 /* Don't mention EOL conversion if it isn't decided. */
17865 Lisp_Object eolvalue
;
17867 attrs
= AREF (val
, 0);
17868 eolvalue
= AREF (val
, 2);
17871 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
17875 /* The EOL conversion that is normal on this system. */
17877 if (NILP (eolvalue
)) /* Not yet decided. */
17878 eoltype
= eol_mnemonic_undecided
;
17879 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17880 eoltype
= eol_mnemonic_undecided
;
17881 else /* eolvalue is Qunix, Qdos, or Qmac. */
17882 eoltype
= (EQ (eolvalue
, Qunix
)
17883 ? eol_mnemonic_unix
17884 : (EQ (eolvalue
, Qdos
) == 1
17885 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17891 /* Mention the EOL conversion if it is not the usual one. */
17892 if (STRINGP (eoltype
))
17894 eol_str
= SDATA (eoltype
);
17895 eol_str_len
= SBYTES (eoltype
);
17897 else if (CHARACTERP (eoltype
))
17899 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17900 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17905 eol_str
= invalid_eol_type
;
17906 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17908 bcopy (eol_str
, buf
, eol_str_len
);
17909 buf
+= eol_str_len
;
17915 /* Return a string for the output of a mode line %-spec for window W,
17916 generated by character C. PRECISION >= 0 means don't return a
17917 string longer than that value. FIELD_WIDTH > 0 means pad the
17918 string returned with spaces to that value. Return 1 in *MULTIBYTE
17919 if the result is multibyte text.
17921 Note we operate on the current buffer for most purposes,
17922 the exception being w->base_line_pos. */
17924 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17927 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17930 int field_width
, precision
;
17934 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17935 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17936 struct buffer
*b
= current_buffer
;
17944 if (!NILP (b
->read_only
))
17946 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17951 /* This differs from %* only for a modified read-only buffer. */
17952 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17954 if (!NILP (b
->read_only
))
17959 /* This differs from %* in ignoring read-only-ness. */
17960 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17972 if (command_loop_level
> 5)
17974 p
= decode_mode_spec_buf
;
17975 for (i
= 0; i
< command_loop_level
; i
++)
17978 return decode_mode_spec_buf
;
17986 if (command_loop_level
> 5)
17988 p
= decode_mode_spec_buf
;
17989 for (i
= 0; i
< command_loop_level
; i
++)
17992 return decode_mode_spec_buf
;
17999 /* Let lots_of_dashes be a string of infinite length. */
18000 if (mode_line_target
== MODE_LINE_NOPROP
||
18001 mode_line_target
== MODE_LINE_STRING
)
18003 if (field_width
<= 0
18004 || field_width
> sizeof (lots_of_dashes
))
18006 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18007 decode_mode_spec_buf
[i
] = '-';
18008 decode_mode_spec_buf
[i
] = '\0';
18009 return decode_mode_spec_buf
;
18012 return lots_of_dashes
;
18020 /* %c and %l are ignored in `frame-title-format'.
18021 (In redisplay_internal, the frame title is drawn _before_ the
18022 windows are updated, so the stuff which depends on actual
18023 window contents (such as %l) may fail to render properly, or
18024 even crash emacs.) */
18025 if (mode_line_target
== MODE_LINE_TITLE
)
18029 int col
= (int) current_column (); /* iftc */
18030 w
->column_number_displayed
= make_number (col
);
18031 pint2str (decode_mode_spec_buf
, field_width
, col
);
18032 return decode_mode_spec_buf
;
18036 #ifndef SYSTEM_MALLOC
18038 if (NILP (Vmemory_full
))
18041 return "!MEM FULL! ";
18048 /* %F displays the frame name. */
18049 if (!NILP (f
->title
))
18050 return (char *) SDATA (f
->title
);
18051 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18052 return (char *) SDATA (f
->name
);
18061 int size
= ZV
- BEGV
;
18062 pint2str (decode_mode_spec_buf
, field_width
, size
);
18063 return decode_mode_spec_buf
;
18068 int size
= ZV
- BEGV
;
18069 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18070 return decode_mode_spec_buf
;
18075 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18076 int topline
, nlines
, junk
, height
;
18078 /* %c and %l are ignored in `frame-title-format'. */
18079 if (mode_line_target
== MODE_LINE_TITLE
)
18082 startpos
= XMARKER (w
->start
)->charpos
;
18083 startpos_byte
= marker_byte_position (w
->start
);
18084 height
= WINDOW_TOTAL_LINES (w
);
18086 /* If we decided that this buffer isn't suitable for line numbers,
18087 don't forget that too fast. */
18088 if (EQ (w
->base_line_pos
, w
->buffer
))
18090 /* But do forget it, if the window shows a different buffer now. */
18091 else if (BUFFERP (w
->base_line_pos
))
18092 w
->base_line_pos
= Qnil
;
18094 /* If the buffer is very big, don't waste time. */
18095 if (INTEGERP (Vline_number_display_limit
)
18096 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18098 w
->base_line_pos
= Qnil
;
18099 w
->base_line_number
= Qnil
;
18103 if (INTEGERP (w
->base_line_number
)
18104 && INTEGERP (w
->base_line_pos
)
18105 && XFASTINT (w
->base_line_pos
) <= startpos
)
18107 line
= XFASTINT (w
->base_line_number
);
18108 linepos
= XFASTINT (w
->base_line_pos
);
18109 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18114 linepos
= BUF_BEGV (b
);
18115 linepos_byte
= BUF_BEGV_BYTE (b
);
18118 /* Count lines from base line to window start position. */
18119 nlines
= display_count_lines (linepos
, linepos_byte
,
18123 topline
= nlines
+ line
;
18125 /* Determine a new base line, if the old one is too close
18126 or too far away, or if we did not have one.
18127 "Too close" means it's plausible a scroll-down would
18128 go back past it. */
18129 if (startpos
== BUF_BEGV (b
))
18131 w
->base_line_number
= make_number (topline
);
18132 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18134 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18135 || linepos
== BUF_BEGV (b
))
18137 int limit
= BUF_BEGV (b
);
18138 int limit_byte
= BUF_BEGV_BYTE (b
);
18140 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18142 if (startpos
- distance
> limit
)
18144 limit
= startpos
- distance
;
18145 limit_byte
= CHAR_TO_BYTE (limit
);
18148 nlines
= display_count_lines (startpos
, startpos_byte
,
18150 - (height
* 2 + 30),
18152 /* If we couldn't find the lines we wanted within
18153 line_number_display_limit_width chars per line,
18154 give up on line numbers for this window. */
18155 if (position
== limit_byte
&& limit
== startpos
- distance
)
18157 w
->base_line_pos
= w
->buffer
;
18158 w
->base_line_number
= Qnil
;
18162 w
->base_line_number
= make_number (topline
- nlines
);
18163 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18166 /* Now count lines from the start pos to point. */
18167 nlines
= display_count_lines (startpos
, startpos_byte
,
18168 PT_BYTE
, PT
, &junk
);
18170 /* Record that we did display the line number. */
18171 line_number_displayed
= 1;
18173 /* Make the string to show. */
18174 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18175 return decode_mode_spec_buf
;
18178 char* p
= decode_mode_spec_buf
;
18179 int pad
= field_width
- 2;
18185 return decode_mode_spec_buf
;
18191 obj
= b
->mode_name
;
18195 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18201 int pos
= marker_position (w
->start
);
18202 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18204 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18206 if (pos
<= BUF_BEGV (b
))
18211 else if (pos
<= BUF_BEGV (b
))
18215 if (total
> 1000000)
18216 /* Do it differently for a large value, to avoid overflow. */
18217 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18219 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18220 /* We can't normally display a 3-digit number,
18221 so get us a 2-digit number that is close. */
18224 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18225 return decode_mode_spec_buf
;
18229 /* Display percentage of size above the bottom of the screen. */
18232 int toppos
= marker_position (w
->start
);
18233 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18234 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18236 if (botpos
>= BUF_ZV (b
))
18238 if (toppos
<= BUF_BEGV (b
))
18245 if (total
> 1000000)
18246 /* Do it differently for a large value, to avoid overflow. */
18247 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18249 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18250 /* We can't normally display a 3-digit number,
18251 so get us a 2-digit number that is close. */
18254 if (toppos
<= BUF_BEGV (b
))
18255 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18257 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18258 return decode_mode_spec_buf
;
18263 /* status of process */
18264 obj
= Fget_buffer_process (Fcurrent_buffer ());
18266 return "no process";
18267 #ifdef subprocesses
18268 obj
= Fsymbol_name (Fprocess_status (obj
));
18275 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18282 case 't': /* indicate TEXT or BINARY */
18283 #ifdef MODE_LINE_BINARY_TEXT
18284 return MODE_LINE_BINARY_TEXT (b
);
18290 /* coding-system (not including end-of-line format) */
18292 /* coding-system (including end-of-line type) */
18294 int eol_flag
= (c
== 'Z');
18295 char *p
= decode_mode_spec_buf
;
18297 if (! FRAME_WINDOW_P (f
))
18299 /* No need to mention EOL here--the terminal never needs
18300 to do EOL conversion. */
18301 p
= decode_mode_spec_coding (CODING_ID_NAME
18302 (FRAME_KEYBOARD_CODING (f
)->id
),
18304 p
= decode_mode_spec_coding (CODING_ID_NAME
18305 (FRAME_TERMINAL_CODING (f
)->id
),
18308 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18311 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18312 #ifdef subprocesses
18313 obj
= Fget_buffer_process (Fcurrent_buffer ());
18314 if (PROCESSP (obj
))
18316 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18318 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18321 #endif /* subprocesses */
18324 return decode_mode_spec_buf
;
18330 *multibyte
= STRING_MULTIBYTE (obj
);
18331 return (char *) SDATA (obj
);
18338 /* Count up to COUNT lines starting from START / START_BYTE.
18339 But don't go beyond LIMIT_BYTE.
18340 Return the number of lines thus found (always nonnegative).
18342 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18345 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18346 int start
, start_byte
, limit_byte
, count
;
18349 register unsigned char *cursor
;
18350 unsigned char *base
;
18352 register int ceiling
;
18353 register unsigned char *ceiling_addr
;
18354 int orig_count
= count
;
18356 /* If we are not in selective display mode,
18357 check only for newlines. */
18358 int selective_display
= (!NILP (current_buffer
->selective_display
)
18359 && !INTEGERP (current_buffer
->selective_display
));
18363 while (start_byte
< limit_byte
)
18365 ceiling
= BUFFER_CEILING_OF (start_byte
);
18366 ceiling
= min (limit_byte
- 1, ceiling
);
18367 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18368 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18371 if (selective_display
)
18372 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18375 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18378 if (cursor
!= ceiling_addr
)
18382 start_byte
+= cursor
- base
+ 1;
18383 *byte_pos_ptr
= start_byte
;
18387 if (++cursor
== ceiling_addr
)
18393 start_byte
+= cursor
- base
;
18398 while (start_byte
> limit_byte
)
18400 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18401 ceiling
= max (limit_byte
, ceiling
);
18402 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18403 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18406 if (selective_display
)
18407 while (--cursor
!= ceiling_addr
18408 && *cursor
!= '\n' && *cursor
!= 015)
18411 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18414 if (cursor
!= ceiling_addr
)
18418 start_byte
+= cursor
- base
+ 1;
18419 *byte_pos_ptr
= start_byte
;
18420 /* When scanning backwards, we should
18421 not count the newline posterior to which we stop. */
18422 return - orig_count
- 1;
18428 /* Here we add 1 to compensate for the last decrement
18429 of CURSOR, which took it past the valid range. */
18430 start_byte
+= cursor
- base
+ 1;
18434 *byte_pos_ptr
= limit_byte
;
18437 return - orig_count
+ count
;
18438 return orig_count
- count
;
18444 /***********************************************************************
18446 ***********************************************************************/
18448 /* Display a NUL-terminated string, starting with index START.
18450 If STRING is non-null, display that C string. Otherwise, the Lisp
18451 string LISP_STRING is displayed.
18453 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18454 FACE_STRING. Display STRING or LISP_STRING with the face at
18455 FACE_STRING_POS in FACE_STRING:
18457 Display the string in the environment given by IT, but use the
18458 standard display table, temporarily.
18460 FIELD_WIDTH is the minimum number of output glyphs to produce.
18461 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18462 with spaces. If STRING has more characters, more than FIELD_WIDTH
18463 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18465 PRECISION is the maximum number of characters to output from
18466 STRING. PRECISION < 0 means don't truncate the string.
18468 This is roughly equivalent to printf format specifiers:
18470 FIELD_WIDTH PRECISION PRINTF
18471 ----------------------------------------
18477 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18478 display them, and < 0 means obey the current buffer's value of
18479 enable_multibyte_characters.
18481 Value is the number of columns displayed. */
18484 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18485 start
, it
, field_width
, precision
, max_x
, multibyte
)
18486 unsigned char *string
;
18487 Lisp_Object lisp_string
;
18488 Lisp_Object face_string
;
18489 EMACS_INT face_string_pos
;
18492 int field_width
, precision
, max_x
;
18495 int hpos_at_start
= it
->hpos
;
18496 int saved_face_id
= it
->face_id
;
18497 struct glyph_row
*row
= it
->glyph_row
;
18499 /* Initialize the iterator IT for iteration over STRING beginning
18500 with index START. */
18501 reseat_to_string (it
, string
, lisp_string
, start
,
18502 precision
, field_width
, multibyte
);
18504 /* If displaying STRING, set up the face of the iterator
18505 from LISP_STRING, if that's given. */
18506 if (STRINGP (face_string
))
18512 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18513 0, it
->region_beg_charpos
,
18514 it
->region_end_charpos
,
18515 &endptr
, it
->base_face_id
, 0);
18516 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18517 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18520 /* Set max_x to the maximum allowed X position. Don't let it go
18521 beyond the right edge of the window. */
18523 max_x
= it
->last_visible_x
;
18525 max_x
= min (max_x
, it
->last_visible_x
);
18527 /* Skip over display elements that are not visible. because IT->w is
18529 if (it
->current_x
< it
->first_visible_x
)
18530 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18531 MOVE_TO_POS
| MOVE_TO_X
);
18533 row
->ascent
= it
->max_ascent
;
18534 row
->height
= it
->max_ascent
+ it
->max_descent
;
18535 row
->phys_ascent
= it
->max_phys_ascent
;
18536 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18537 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18539 /* This condition is for the case that we are called with current_x
18540 past last_visible_x. */
18541 while (it
->current_x
< max_x
)
18543 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18545 /* Get the next display element. */
18546 if (!get_next_display_element (it
))
18549 /* Produce glyphs. */
18550 x_before
= it
->current_x
;
18551 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18552 PRODUCE_GLYPHS (it
);
18554 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18557 while (i
< nglyphs
)
18559 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18561 if (!it
->truncate_lines_p
18562 && x
+ glyph
->pixel_width
> max_x
)
18564 /* End of continued line or max_x reached. */
18565 if (CHAR_GLYPH_PADDING_P (*glyph
))
18567 /* A wide character is unbreakable. */
18568 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18569 it
->current_x
= x_before
;
18573 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18578 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18580 /* Glyph is at least partially visible. */
18582 if (x
< it
->first_visible_x
)
18583 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18587 /* Glyph is off the left margin of the display area.
18588 Should not happen. */
18592 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18593 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18594 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18595 row
->phys_height
= max (row
->phys_height
,
18596 it
->max_phys_ascent
+ it
->max_phys_descent
);
18597 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18598 it
->max_extra_line_spacing
);
18599 x
+= glyph
->pixel_width
;
18603 /* Stop if max_x reached. */
18607 /* Stop at line ends. */
18608 if (ITERATOR_AT_END_OF_LINE_P (it
))
18610 it
->continuation_lines_width
= 0;
18614 set_iterator_to_next (it
, 1);
18616 /* Stop if truncating at the right edge. */
18617 if (it
->truncate_lines_p
18618 && it
->current_x
>= it
->last_visible_x
)
18620 /* Add truncation mark, but don't do it if the line is
18621 truncated at a padding space. */
18622 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18624 if (!FRAME_WINDOW_P (it
->f
))
18628 if (it
->current_x
> it
->last_visible_x
)
18630 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18631 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18633 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18635 row
->used
[TEXT_AREA
] = i
;
18636 produce_special_glyphs (it
, IT_TRUNCATION
);
18639 produce_special_glyphs (it
, IT_TRUNCATION
);
18641 it
->glyph_row
->truncated_on_right_p
= 1;
18647 /* Maybe insert a truncation at the left. */
18648 if (it
->first_visible_x
18649 && IT_CHARPOS (*it
) > 0)
18651 if (!FRAME_WINDOW_P (it
->f
))
18652 insert_left_trunc_glyphs (it
);
18653 it
->glyph_row
->truncated_on_left_p
= 1;
18656 it
->face_id
= saved_face_id
;
18658 /* Value is number of columns displayed. */
18659 return it
->hpos
- hpos_at_start
;
18664 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18665 appears as an element of LIST or as the car of an element of LIST.
18666 If PROPVAL is a list, compare each element against LIST in that
18667 way, and return 1/2 if any element of PROPVAL is found in LIST.
18668 Otherwise return 0. This function cannot quit.
18669 The return value is 2 if the text is invisible but with an ellipsis
18670 and 1 if it's invisible and without an ellipsis. */
18673 invisible_p (propval
, list
)
18674 register Lisp_Object propval
;
18677 register Lisp_Object tail
, proptail
;
18679 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18681 register Lisp_Object tem
;
18683 if (EQ (propval
, tem
))
18685 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18686 return NILP (XCDR (tem
)) ? 1 : 2;
18689 if (CONSP (propval
))
18691 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18693 Lisp_Object propelt
;
18694 propelt
= XCAR (proptail
);
18695 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18697 register Lisp_Object tem
;
18699 if (EQ (propelt
, tem
))
18701 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18702 return NILP (XCDR (tem
)) ? 1 : 2;
18710 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
18711 doc
: /* Non-nil if the property makes the text invisible.
18712 POS-OR-PROP can be a marker or number, in which case it is taken to be
18713 a position in the current buffer and the value of the `invisible' property
18714 is checked; or it can be some other value, which is then presumed to be the
18715 value of the `invisible' property of the text of interest.
18716 The non-nil value returned can be t for truly invisible text or something
18717 else if the text is replaced by an ellipsis. */)
18719 Lisp_Object pos_or_prop
;
18722 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
18723 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
18725 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
18726 return (invis
== 0 ? Qnil
18728 : make_number (invis
));
18731 /* Calculate a width or height in pixels from a specification using
18732 the following elements:
18735 NUM - a (fractional) multiple of the default font width/height
18736 (NUM) - specifies exactly NUM pixels
18737 UNIT - a fixed number of pixels, see below.
18738 ELEMENT - size of a display element in pixels, see below.
18739 (NUM . SPEC) - equals NUM * SPEC
18740 (+ SPEC SPEC ...) - add pixel values
18741 (- SPEC SPEC ...) - subtract pixel values
18742 (- SPEC) - negate pixel value
18745 INT or FLOAT - a number constant
18746 SYMBOL - use symbol's (buffer local) variable binding.
18749 in - pixels per inch *)
18750 mm - pixels per 1/1000 meter *)
18751 cm - pixels per 1/100 meter *)
18752 width - width of current font in pixels.
18753 height - height of current font in pixels.
18755 *) using the ratio(s) defined in display-pixels-per-inch.
18759 left-fringe - left fringe width in pixels
18760 right-fringe - right fringe width in pixels
18762 left-margin - left margin width in pixels
18763 right-margin - right margin width in pixels
18765 scroll-bar - scroll-bar area width in pixels
18769 Pixels corresponding to 5 inches:
18772 Total width of non-text areas on left side of window (if scroll-bar is on left):
18773 '(space :width (+ left-fringe left-margin scroll-bar))
18775 Align to first text column (in header line):
18776 '(space :align-to 0)
18778 Align to middle of text area minus half the width of variable `my-image'
18779 containing a loaded image:
18780 '(space :align-to (0.5 . (- text my-image)))
18782 Width of left margin minus width of 1 character in the default font:
18783 '(space :width (- left-margin 1))
18785 Width of left margin minus width of 2 characters in the current font:
18786 '(space :width (- left-margin (2 . width)))
18788 Center 1 character over left-margin (in header line):
18789 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18791 Different ways to express width of left fringe plus left margin minus one pixel:
18792 '(space :width (- (+ left-fringe left-margin) (1)))
18793 '(space :width (+ left-fringe left-margin (- (1))))
18794 '(space :width (+ left-fringe left-margin (-1)))
18798 #define NUMVAL(X) \
18799 ((INTEGERP (X) || FLOATP (X)) \
18804 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18809 int width_p
, *align_to
;
18813 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18814 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18817 return OK_PIXELS (0);
18819 xassert (FRAME_LIVE_P (it
->f
));
18821 if (SYMBOLP (prop
))
18823 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18825 char *unit
= SDATA (SYMBOL_NAME (prop
));
18827 if (unit
[0] == 'i' && unit
[1] == 'n')
18829 else if (unit
[0] == 'm' && unit
[1] == 'm')
18831 else if (unit
[0] == 'c' && unit
[1] == 'm')
18838 #ifdef HAVE_WINDOW_SYSTEM
18839 if (FRAME_WINDOW_P (it
->f
)
18841 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18842 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18844 return OK_PIXELS (ppi
/ pixels
);
18847 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18848 || (CONSP (Vdisplay_pixels_per_inch
)
18850 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18851 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18853 return OK_PIXELS (ppi
/ pixels
);
18859 #ifdef HAVE_WINDOW_SYSTEM
18860 if (EQ (prop
, Qheight
))
18861 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
18862 if (EQ (prop
, Qwidth
))
18863 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
18865 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18866 return OK_PIXELS (1);
18869 if (EQ (prop
, Qtext
))
18870 return OK_PIXELS (width_p
18871 ? window_box_width (it
->w
, TEXT_AREA
)
18872 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18874 if (align_to
&& *align_to
< 0)
18877 if (EQ (prop
, Qleft
))
18878 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18879 if (EQ (prop
, Qright
))
18880 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18881 if (EQ (prop
, Qcenter
))
18882 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18883 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18884 if (EQ (prop
, Qleft_fringe
))
18885 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18886 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18887 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18888 if (EQ (prop
, Qright_fringe
))
18889 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18890 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18891 : window_box_right_offset (it
->w
, TEXT_AREA
));
18892 if (EQ (prop
, Qleft_margin
))
18893 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18894 if (EQ (prop
, Qright_margin
))
18895 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18896 if (EQ (prop
, Qscroll_bar
))
18897 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18899 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18900 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18901 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18906 if (EQ (prop
, Qleft_fringe
))
18907 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18908 if (EQ (prop
, Qright_fringe
))
18909 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18910 if (EQ (prop
, Qleft_margin
))
18911 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18912 if (EQ (prop
, Qright_margin
))
18913 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18914 if (EQ (prop
, Qscroll_bar
))
18915 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18918 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18921 if (INTEGERP (prop
) || FLOATP (prop
))
18923 int base_unit
= (width_p
18924 ? FRAME_COLUMN_WIDTH (it
->f
)
18925 : FRAME_LINE_HEIGHT (it
->f
));
18926 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18931 Lisp_Object car
= XCAR (prop
);
18932 Lisp_Object cdr
= XCDR (prop
);
18936 #ifdef HAVE_WINDOW_SYSTEM
18937 if (FRAME_WINDOW_P (it
->f
)
18938 && valid_image_p (prop
))
18940 int id
= lookup_image (it
->f
, prop
);
18941 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18943 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18946 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18952 while (CONSP (cdr
))
18954 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18955 font
, width_p
, align_to
))
18958 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18963 if (EQ (car
, Qminus
))
18965 return OK_PIXELS (pixels
);
18968 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18971 if (INTEGERP (car
) || FLOATP (car
))
18974 pixels
= XFLOATINT (car
);
18976 return OK_PIXELS (pixels
);
18977 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18978 font
, width_p
, align_to
))
18979 return OK_PIXELS (pixels
* fact
);
18990 /***********************************************************************
18992 ***********************************************************************/
18994 #ifdef HAVE_WINDOW_SYSTEM
18999 dump_glyph_string (s
)
19000 struct glyph_string
*s
;
19002 fprintf (stderr
, "glyph string\n");
19003 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19004 s
->x
, s
->y
, s
->width
, s
->height
);
19005 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19006 fprintf (stderr
, " hl = %d\n", s
->hl
);
19007 fprintf (stderr
, " left overhang = %d, right = %d\n",
19008 s
->left_overhang
, s
->right_overhang
);
19009 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19010 fprintf (stderr
, " extends to end of line = %d\n",
19011 s
->extends_to_end_of_line_p
);
19012 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19013 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19016 #endif /* GLYPH_DEBUG */
19018 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19019 of XChar2b structures for S; it can't be allocated in
19020 init_glyph_string because it must be allocated via `alloca'. W
19021 is the window on which S is drawn. ROW and AREA are the glyph row
19022 and area within the row from which S is constructed. START is the
19023 index of the first glyph structure covered by S. HL is a
19024 face-override for drawing S. */
19027 #define OPTIONAL_HDC(hdc) hdc,
19028 #define DECLARE_HDC(hdc) HDC hdc;
19029 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19030 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19033 #ifndef OPTIONAL_HDC
19034 #define OPTIONAL_HDC(hdc)
19035 #define DECLARE_HDC(hdc)
19036 #define ALLOCATE_HDC(hdc, f)
19037 #define RELEASE_HDC(hdc, f)
19041 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19042 struct glyph_string
*s
;
19046 struct glyph_row
*row
;
19047 enum glyph_row_area area
;
19049 enum draw_glyphs_face hl
;
19051 bzero (s
, sizeof *s
);
19053 s
->f
= XFRAME (w
->frame
);
19057 s
->display
= FRAME_X_DISPLAY (s
->f
);
19058 s
->window
= FRAME_X_WINDOW (s
->f
);
19059 s
->char2b
= char2b
;
19063 s
->first_glyph
= row
->glyphs
[area
] + start
;
19064 s
->height
= row
->height
;
19065 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19067 /* Display the internal border below the tool-bar window. */
19068 if (WINDOWP (s
->f
->tool_bar_window
)
19069 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19070 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19072 s
->ybase
= s
->y
+ row
->ascent
;
19076 /* Append the list of glyph strings with head H and tail T to the list
19077 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19080 append_glyph_string_lists (head
, tail
, h
, t
)
19081 struct glyph_string
**head
, **tail
;
19082 struct glyph_string
*h
, *t
;
19096 /* Prepend the list of glyph strings with head H and tail T to the
19097 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19101 prepend_glyph_string_lists (head
, tail
, h
, t
)
19102 struct glyph_string
**head
, **tail
;
19103 struct glyph_string
*h
, *t
;
19117 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19118 Set *HEAD and *TAIL to the resulting list. */
19121 append_glyph_string (head
, tail
, s
)
19122 struct glyph_string
**head
, **tail
;
19123 struct glyph_string
*s
;
19125 s
->next
= s
->prev
= NULL
;
19126 append_glyph_string_lists (head
, tail
, s
, s
);
19130 /* Get face and two-byte form of character C in face FACE_ID on frame
19131 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19132 means we want to display multibyte text. DISPLAY_P non-zero means
19133 make sure that X resources for the face returned are allocated.
19134 Value is a pointer to a realized face that is ready for display if
19135 DISPLAY_P is non-zero. */
19137 static INLINE
struct face
*
19138 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19142 int multibyte_p
, display_p
;
19144 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19148 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19150 if (code
!= FONT_INVALID_CODE
)
19151 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19153 STORE_XCHAR2B (char2b
, 0, 0);
19156 /* Make sure X resources of the face are allocated. */
19157 #ifdef HAVE_X_WINDOWS
19161 xassert (face
!= NULL
);
19162 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19169 /* Get face and two-byte form of character glyph GLYPH on frame F.
19170 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19171 a pointer to a realized face that is ready for display. */
19173 static INLINE
struct face
*
19174 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19176 struct glyph
*glyph
;
19182 xassert (glyph
->type
== CHAR_GLYPH
);
19183 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19190 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19192 if (code
!= FONT_INVALID_CODE
)
19193 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19195 STORE_XCHAR2B (char2b
, 0, code
);
19198 /* Make sure X resources of the face are allocated. */
19199 xassert (face
!= NULL
);
19200 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19205 /* Fill glyph string S with composition components specified by S->cmp.
19207 BASE_FACE is the base face of the composition.
19208 S->gidx is the index of the first component for S.
19210 OVERLAPS non-zero means S should draw the foreground only, and use
19211 its physical height for clipping. See also draw_glyphs.
19213 Value is the index of a component not in S. */
19216 fill_composite_glyph_string (s
, base_face
, overlaps
)
19217 struct glyph_string
*s
;
19218 struct face
*base_face
;
19225 s
->for_overlaps
= overlaps
;
19227 if (s
->cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
19229 Lisp_Object gstring
19230 = AREF (XHASH_TABLE (composition_hash_table
)->key_and_value
,
19231 s
->cmp
->hash_index
* 2);
19233 s
->face
= base_face
;
19234 s
->font
= base_face
->font
;
19235 for (i
= 0, s
->nchars
= 0; i
< s
->cmp
->glyph_len
; i
++, s
->nchars
++)
19237 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
19239 XChar2b
* store_pos
;
19242 code
= LGLYPH_CODE (g
);
19243 store_pos
= s
->char2b
+ i
;
19244 STORE_XCHAR2B (store_pos
, code
>> 8, code
& 0xFF);
19246 s
->width
= s
->cmp
->pixel_width
;
19250 /* For all glyphs of this composition, starting at the offset
19251 S->gidx, until we reach the end of the definition or encounter a
19252 glyph that requires the different face, add it to S. */
19257 for (i
= s
->gidx
; i
< s
->cmp
->glyph_len
; i
++)
19259 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19263 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19266 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19267 s
->char2b
+ i
, 1, 1);
19273 s
->font
= s
->face
->font
;
19275 else if (s
->face
!= face
)
19282 /* All glyph strings for the same composition has the same width,
19283 i.e. the width set for the first component of the composition. */
19284 s
->width
= s
->first_glyph
->pixel_width
;
19287 /* If the specified font could not be loaded, use the frame's
19288 default font, but record the fact that we couldn't load it in
19289 the glyph string so that we can draw rectangles for the
19290 characters of the glyph string. */
19291 if (s
->font
== NULL
)
19293 s
->font_not_found_p
= 1;
19294 s
->font
= FRAME_FONT (s
->f
);
19297 /* Adjust base line for subscript/superscript text. */
19298 s
->ybase
+= s
->first_glyph
->voffset
;
19300 /* This glyph string must always be drawn with 16-bit functions. */
19303 return s
->gidx
+ s
->nchars
;
19307 /* Fill glyph string S from a sequence of character glyphs.
19309 FACE_ID is the face id of the string. START is the index of the
19310 first glyph to consider, END is the index of the last + 1.
19311 OVERLAPS non-zero means S should draw the foreground only, and use
19312 its physical height for clipping. See also draw_glyphs.
19314 Value is the index of the first glyph not in S. */
19317 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19318 struct glyph_string
*s
;
19320 int start
, end
, overlaps
;
19322 struct glyph
*glyph
, *last
;
19324 int glyph_not_available_p
;
19326 xassert (s
->f
== XFRAME (s
->w
->frame
));
19327 xassert (s
->nchars
== 0);
19328 xassert (start
>= 0 && end
> start
);
19330 s
->for_overlaps
= overlaps
,
19331 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19332 last
= s
->row
->glyphs
[s
->area
] + end
;
19333 voffset
= glyph
->voffset
;
19334 s
->padding_p
= glyph
->padding_p
;
19335 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19337 while (glyph
< last
19338 && glyph
->type
== CHAR_GLYPH
19339 && glyph
->voffset
== voffset
19340 /* Same face id implies same font, nowadays. */
19341 && glyph
->face_id
== face_id
19342 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19346 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19347 s
->char2b
+ s
->nchars
,
19349 s
->two_byte_p
= two_byte_p
;
19351 xassert (s
->nchars
<= end
- start
);
19352 s
->width
+= glyph
->pixel_width
;
19353 if (glyph
++->padding_p
!= s
->padding_p
)
19357 s
->font
= s
->face
->font
;
19359 /* If the specified font could not be loaded, use the frame's font,
19360 but record the fact that we couldn't load it in
19361 S->font_not_found_p so that we can draw rectangles for the
19362 characters of the glyph string. */
19363 if (s
->font
== NULL
|| glyph_not_available_p
)
19365 s
->font_not_found_p
= 1;
19366 s
->font
= FRAME_FONT (s
->f
);
19369 /* Adjust base line for subscript/superscript text. */
19370 s
->ybase
+= voffset
;
19372 xassert (s
->face
&& s
->face
->gc
);
19373 return glyph
- s
->row
->glyphs
[s
->area
];
19377 /* Fill glyph string S from image glyph S->first_glyph. */
19380 fill_image_glyph_string (s
)
19381 struct glyph_string
*s
;
19383 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19384 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19386 s
->slice
= s
->first_glyph
->slice
;
19387 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19388 s
->font
= s
->face
->font
;
19389 s
->width
= s
->first_glyph
->pixel_width
;
19391 /* Adjust base line for subscript/superscript text. */
19392 s
->ybase
+= s
->first_glyph
->voffset
;
19396 /* Fill glyph string S from a sequence of stretch glyphs.
19398 ROW is the glyph row in which the glyphs are found, AREA is the
19399 area within the row. START is the index of the first glyph to
19400 consider, END is the index of the last + 1.
19402 Value is the index of the first glyph not in S. */
19405 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19406 struct glyph_string
*s
;
19407 struct glyph_row
*row
;
19408 enum glyph_row_area area
;
19411 struct glyph
*glyph
, *last
;
19412 int voffset
, face_id
;
19414 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19416 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19417 last
= s
->row
->glyphs
[s
->area
] + end
;
19418 face_id
= glyph
->face_id
;
19419 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19420 s
->font
= s
->face
->font
;
19421 s
->width
= glyph
->pixel_width
;
19423 voffset
= glyph
->voffset
;
19427 && glyph
->type
== STRETCH_GLYPH
19428 && glyph
->voffset
== voffset
19429 && glyph
->face_id
== face_id
);
19431 s
->width
+= glyph
->pixel_width
;
19433 /* Adjust base line for subscript/superscript text. */
19434 s
->ybase
+= voffset
;
19436 /* The case that face->gc == 0 is handled when drawing the glyph
19437 string by calling PREPARE_FACE_FOR_DISPLAY. */
19439 return glyph
- s
->row
->glyphs
[s
->area
];
19442 static struct font_metrics
*
19443 get_per_char_metric (f
, font
, char2b
)
19448 static struct font_metrics metrics
;
19449 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19450 struct font
*fontp
;
19452 if (! font
|| code
== FONT_INVALID_CODE
)
19454 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19459 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19460 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19461 assumed to be zero. */
19464 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19465 struct glyph
*glyph
;
19469 *left
= *right
= 0;
19471 if (glyph
->type
== CHAR_GLYPH
)
19475 struct font_metrics
*pcm
;
19477 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19478 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19480 if (pcm
->rbearing
> pcm
->width
)
19481 *right
= pcm
->rbearing
- pcm
->width
;
19482 if (pcm
->lbearing
< 0)
19483 *left
= -pcm
->lbearing
;
19486 else if (glyph
->type
== COMPOSITE_GLYPH
)
19488 struct composition
*cmp
= composition_table
[glyph
->u
.cmp_id
];
19490 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19491 *left
= - cmp
->lbearing
;
19496 /* Return the index of the first glyph preceding glyph string S that
19497 is overwritten by S because of S's left overhang. Value is -1
19498 if no glyphs are overwritten. */
19501 left_overwritten (s
)
19502 struct glyph_string
*s
;
19506 if (s
->left_overhang
)
19509 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19510 int first
= s
->first_glyph
- glyphs
;
19512 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19513 x
-= glyphs
[i
].pixel_width
;
19524 /* Return the index of the first glyph preceding glyph string S that
19525 is overwriting S because of its right overhang. Value is -1 if no
19526 glyph in front of S overwrites S. */
19529 left_overwriting (s
)
19530 struct glyph_string
*s
;
19533 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19534 int first
= s
->first_glyph
- glyphs
;
19538 for (i
= first
- 1; i
>= 0; --i
)
19541 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19544 x
-= glyphs
[i
].pixel_width
;
19551 /* Return the index of the last glyph following glyph string S that is
19552 not overwritten by S because of S's right overhang. Value is -1 if
19553 no such glyph is found. */
19556 right_overwritten (s
)
19557 struct glyph_string
*s
;
19561 if (s
->right_overhang
)
19564 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19565 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19566 int end
= s
->row
->used
[s
->area
];
19568 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19569 x
+= glyphs
[i
].pixel_width
;
19578 /* Return the index of the last glyph following glyph string S that
19579 overwrites S because of its left overhang. Value is negative
19580 if no such glyph is found. */
19583 right_overwriting (s
)
19584 struct glyph_string
*s
;
19587 int end
= s
->row
->used
[s
->area
];
19588 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19589 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19593 for (i
= first
; i
< end
; ++i
)
19596 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19599 x
+= glyphs
[i
].pixel_width
;
19606 /* Set background width of glyph string S. START is the index of the
19607 first glyph following S. LAST_X is the right-most x-position + 1
19608 in the drawing area. */
19611 set_glyph_string_background_width (s
, start
, last_x
)
19612 struct glyph_string
*s
;
19616 /* If the face of this glyph string has to be drawn to the end of
19617 the drawing area, set S->extends_to_end_of_line_p. */
19619 if (start
== s
->row
->used
[s
->area
]
19620 && s
->area
== TEXT_AREA
19621 && ((s
->row
->fill_line_p
19622 && (s
->hl
== DRAW_NORMAL_TEXT
19623 || s
->hl
== DRAW_IMAGE_RAISED
19624 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19625 || s
->hl
== DRAW_MOUSE_FACE
))
19626 s
->extends_to_end_of_line_p
= 1;
19628 /* If S extends its face to the end of the line, set its
19629 background_width to the distance to the right edge of the drawing
19631 if (s
->extends_to_end_of_line_p
)
19632 s
->background_width
= last_x
- s
->x
+ 1;
19634 s
->background_width
= s
->width
;
19638 /* Compute overhangs and x-positions for glyph string S and its
19639 predecessors, or successors. X is the starting x-position for S.
19640 BACKWARD_P non-zero means process predecessors. */
19643 compute_overhangs_and_x (s
, x
, backward_p
)
19644 struct glyph_string
*s
;
19652 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19653 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19663 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
19664 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
19674 /* The following macros are only called from draw_glyphs below.
19675 They reference the following parameters of that function directly:
19676 `w', `row', `area', and `overlap_p'
19677 as well as the following local variables:
19678 `s', `f', and `hdc' (in W32) */
19681 /* On W32, silently add local `hdc' variable to argument list of
19682 init_glyph_string. */
19683 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19684 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19686 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19687 init_glyph_string (s, char2b, w, row, area, start, hl)
19690 /* Add a glyph string for a stretch glyph to the list of strings
19691 between HEAD and TAIL. START is the index of the stretch glyph in
19692 row area AREA of glyph row ROW. END is the index of the last glyph
19693 in that glyph row area. X is the current output position assigned
19694 to the new glyph string constructed. HL overrides that face of the
19695 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19696 is the right-most x-position of the drawing area. */
19698 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19699 and below -- keep them on one line. */
19700 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19703 s = (struct glyph_string *) alloca (sizeof *s); \
19704 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19705 START = fill_stretch_glyph_string (s, row, area, START, END); \
19706 append_glyph_string (&HEAD, &TAIL, s); \
19712 /* Add a glyph string for an image glyph to the list of strings
19713 between HEAD and TAIL. START is the index of the image glyph in
19714 row area AREA of glyph row ROW. END is the index of the last glyph
19715 in that glyph row area. X is the current output position assigned
19716 to the new glyph string constructed. HL overrides that face of the
19717 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19718 is the right-most x-position of the drawing area. */
19720 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19723 s = (struct glyph_string *) alloca (sizeof *s); \
19724 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19725 fill_image_glyph_string (s); \
19726 append_glyph_string (&HEAD, &TAIL, s); \
19733 /* Add a glyph string for a sequence of character glyphs to the list
19734 of strings between HEAD and TAIL. START is the index of the first
19735 glyph in row area AREA of glyph row ROW that is part of the new
19736 glyph string. END is the index of the last glyph in that glyph row
19737 area. X is the current output position assigned to the new glyph
19738 string constructed. HL overrides that face of the glyph; e.g. it
19739 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19740 right-most x-position of the drawing area. */
19742 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19748 face_id = (row)->glyphs[area][START].face_id; \
19750 s = (struct glyph_string *) alloca (sizeof *s); \
19751 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19752 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19753 append_glyph_string (&HEAD, &TAIL, s); \
19755 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19760 /* Add a glyph string for a composite sequence to the list of strings
19761 between HEAD and TAIL. START is the index of the first glyph in
19762 row area AREA of glyph row ROW that is part of the new glyph
19763 string. END is the index of the last glyph in that glyph row area.
19764 X is the current output position assigned to the new glyph string
19765 constructed. HL overrides that face of the glyph; e.g. it is
19766 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19767 x-position of the drawing area. */
19769 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19771 int face_id = (row)->glyphs[area][START].face_id; \
19772 struct face *base_face = FACE_FROM_ID (f, face_id); \
19773 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19774 struct composition *cmp = composition_table[cmp_id]; \
19776 struct glyph_string *first_s; \
19779 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
19781 /* Make glyph_strings for each glyph sequence that is drawable by \
19782 the same face, and append them to HEAD/TAIL. */ \
19783 for (n = 0; n < cmp->glyph_len;) \
19785 s = (struct glyph_string *) alloca (sizeof *s); \
19786 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19787 append_glyph_string (&(HEAD), &(TAIL), s); \
19793 n = fill_composite_glyph_string (s, base_face, overlaps); \
19801 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19802 of AREA of glyph row ROW on window W between indices START and END.
19803 HL overrides the face for drawing glyph strings, e.g. it is
19804 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19805 x-positions of the drawing area.
19807 This is an ugly monster macro construct because we must use alloca
19808 to allocate glyph strings (because draw_glyphs can be called
19809 asynchronously). */
19811 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19814 HEAD = TAIL = NULL; \
19815 while (START < END) \
19817 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19818 switch (first_glyph->type) \
19821 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19825 case COMPOSITE_GLYPH: \
19826 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19830 case STRETCH_GLYPH: \
19831 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19835 case IMAGE_GLYPH: \
19836 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19846 set_glyph_string_background_width (s, START, LAST_X); \
19854 /* Draw glyphs between START and END in AREA of ROW on window W,
19855 starting at x-position X. X is relative to AREA in W. HL is a
19856 face-override with the following meaning:
19858 DRAW_NORMAL_TEXT draw normally
19859 DRAW_CURSOR draw in cursor face
19860 DRAW_MOUSE_FACE draw in mouse face.
19861 DRAW_INVERSE_VIDEO draw in mode line face
19862 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19863 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19865 If OVERLAPS is non-zero, draw only the foreground of characters and
19866 clip to the physical height of ROW. Non-zero value also defines
19867 the overlapping part to be drawn:
19869 OVERLAPS_PRED overlap with preceding rows
19870 OVERLAPS_SUCC overlap with succeeding rows
19871 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19872 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19874 Value is the x-position reached, relative to AREA of W. */
19877 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19880 struct glyph_row
*row
;
19881 enum glyph_row_area area
;
19882 EMACS_INT start
, end
;
19883 enum draw_glyphs_face hl
;
19886 struct glyph_string
*head
, *tail
;
19887 struct glyph_string
*s
;
19888 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19889 int last_x
, area_width
;
19892 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19895 ALLOCATE_HDC (hdc
, f
);
19897 /* Let's rather be paranoid than getting a SEGV. */
19898 end
= min (end
, row
->used
[area
]);
19899 start
= max (0, start
);
19900 start
= min (end
, start
);
19902 /* Translate X to frame coordinates. Set last_x to the right
19903 end of the drawing area. */
19904 if (row
->full_width_p
)
19906 /* X is relative to the left edge of W, without scroll bars
19908 x
+= WINDOW_LEFT_EDGE_X (w
);
19909 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19913 int area_left
= window_box_left (w
, area
);
19915 area_width
= window_box_width (w
, area
);
19916 last_x
= area_left
+ area_width
;
19919 /* Build a doubly-linked list of glyph_string structures between
19920 head and tail from what we have to draw. Note that the macro
19921 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19922 the reason we use a separate variable `i'. */
19924 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19926 x_reached
= tail
->x
+ tail
->background_width
;
19930 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19931 the row, redraw some glyphs in front or following the glyph
19932 strings built above. */
19933 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19936 struct glyph_string
*h
, *t
;
19938 /* Compute overhangs for all glyph strings. */
19939 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
19940 for (s
= head
; s
; s
= s
->next
)
19941 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
19943 /* Prepend glyph strings for glyphs in front of the first glyph
19944 string that are overwritten because of the first glyph
19945 string's left overhang. The background of all strings
19946 prepended must be drawn because the first glyph string
19948 i
= left_overwritten (head
);
19952 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19953 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19955 compute_overhangs_and_x (t
, head
->x
, 1);
19956 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19960 /* Prepend glyph strings for glyphs in front of the first glyph
19961 string that overwrite that glyph string because of their
19962 right overhang. For these strings, only the foreground must
19963 be drawn, because it draws over the glyph string at `head'.
19964 The background must not be drawn because this would overwrite
19965 right overhangs of preceding glyphs for which no glyph
19967 i
= left_overwriting (head
);
19971 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19972 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19973 for (s
= h
; s
; s
= s
->next
)
19974 s
->background_filled_p
= 1;
19975 compute_overhangs_and_x (t
, head
->x
, 1);
19976 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19979 /* Append glyphs strings for glyphs following the last glyph
19980 string tail that are overwritten by tail. The background of
19981 these strings has to be drawn because tail's foreground draws
19983 i
= right_overwritten (tail
);
19986 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19987 DRAW_NORMAL_TEXT
, x
, last_x
);
19988 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19989 append_glyph_string_lists (&head
, &tail
, h
, t
);
19993 /* Append glyph strings for glyphs following the last glyph
19994 string tail that overwrite tail. The foreground of such
19995 glyphs has to be drawn because it writes into the background
19996 of tail. The background must not be drawn because it could
19997 paint over the foreground of following glyphs. */
19998 i
= right_overwriting (tail
);
20002 i
++; /* We must include the Ith glyph. */
20003 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20004 DRAW_NORMAL_TEXT
, x
, last_x
);
20005 for (s
= h
; s
; s
= s
->next
)
20006 s
->background_filled_p
= 1;
20007 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20008 append_glyph_string_lists (&head
, &tail
, h
, t
);
20010 if (clip_head
|| clip_tail
)
20011 for (s
= head
; s
; s
= s
->next
)
20013 s
->clip_head
= clip_head
;
20014 s
->clip_tail
= clip_tail
;
20018 /* Draw all strings. */
20019 for (s
= head
; s
; s
= s
->next
)
20020 FRAME_RIF (f
)->draw_glyph_string (s
);
20022 if (area
== TEXT_AREA
20023 && !row
->full_width_p
20024 /* When drawing overlapping rows, only the glyph strings'
20025 foreground is drawn, which doesn't erase a cursor
20029 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20030 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20031 : (tail
? tail
->x
+ tail
->background_width
: x
));
20033 int text_left
= window_box_left (w
, TEXT_AREA
);
20037 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20038 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20041 /* Value is the x-position up to which drawn, relative to AREA of W.
20042 This doesn't include parts drawn because of overhangs. */
20043 if (row
->full_width_p
)
20044 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20046 x_reached
-= window_box_left (w
, area
);
20048 RELEASE_HDC (hdc
, f
);
20053 /* Expand row matrix if too narrow. Don't expand if area
20056 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20058 if (!fonts_changed_p \
20059 && (it->glyph_row->glyphs[area] \
20060 < it->glyph_row->glyphs[area + 1])) \
20062 it->w->ncols_scale_factor++; \
20063 fonts_changed_p = 1; \
20067 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20068 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20074 struct glyph
*glyph
;
20075 enum glyph_row_area area
= it
->area
;
20077 xassert (it
->glyph_row
);
20078 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20080 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20081 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20083 glyph
->charpos
= CHARPOS (it
->position
);
20084 glyph
->object
= it
->object
;
20085 if (it
->pixel_width
> 0)
20087 glyph
->pixel_width
= it
->pixel_width
;
20088 glyph
->padding_p
= 0;
20092 /* Assure at least 1-pixel width. Otherwise, cursor can't
20093 be displayed correctly. */
20094 glyph
->pixel_width
= 1;
20095 glyph
->padding_p
= 1;
20097 glyph
->ascent
= it
->ascent
;
20098 glyph
->descent
= it
->descent
;
20099 glyph
->voffset
= it
->voffset
;
20100 glyph
->type
= CHAR_GLYPH
;
20101 glyph
->multibyte_p
= it
->multibyte_p
;
20102 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20103 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20104 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20105 || it
->phys_descent
> it
->descent
);
20106 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20107 glyph
->face_id
= it
->face_id
;
20108 glyph
->u
.ch
= it
->char_to_display
;
20109 glyph
->slice
= null_glyph_slice
;
20110 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20111 ++it
->glyph_row
->used
[area
];
20114 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20117 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
20118 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20121 append_composite_glyph (it
)
20124 struct glyph
*glyph
;
20125 enum glyph_row_area area
= it
->area
;
20127 xassert (it
->glyph_row
);
20129 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20130 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20132 glyph
->charpos
= CHARPOS (it
->position
);
20133 glyph
->object
= it
->object
;
20134 glyph
->pixel_width
= it
->pixel_width
;
20135 glyph
->ascent
= it
->ascent
;
20136 glyph
->descent
= it
->descent
;
20137 glyph
->voffset
= it
->voffset
;
20138 glyph
->type
= COMPOSITE_GLYPH
;
20139 glyph
->multibyte_p
= it
->multibyte_p
;
20140 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20141 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20142 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20143 || it
->phys_descent
> it
->descent
);
20144 glyph
->padding_p
= 0;
20145 glyph
->glyph_not_available_p
= 0;
20146 glyph
->face_id
= it
->face_id
;
20147 glyph
->u
.cmp_id
= it
->cmp_id
;
20148 glyph
->slice
= null_glyph_slice
;
20149 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20150 ++it
->glyph_row
->used
[area
];
20153 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20157 /* Change IT->ascent and IT->height according to the setting of
20161 take_vertical_position_into_account (it
)
20166 if (it
->voffset
< 0)
20167 /* Increase the ascent so that we can display the text higher
20169 it
->ascent
-= it
->voffset
;
20171 /* Increase the descent so that we can display the text lower
20173 it
->descent
+= it
->voffset
;
20178 /* Produce glyphs/get display metrics for the image IT is loaded with.
20179 See the description of struct display_iterator in dispextern.h for
20180 an overview of struct display_iterator. */
20183 produce_image_glyph (it
)
20188 int glyph_ascent
, crop
;
20189 struct glyph_slice slice
;
20191 xassert (it
->what
== IT_IMAGE
);
20193 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20195 /* Make sure X resources of the face is loaded. */
20196 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20198 if (it
->image_id
< 0)
20200 /* Fringe bitmap. */
20201 it
->ascent
= it
->phys_ascent
= 0;
20202 it
->descent
= it
->phys_descent
= 0;
20203 it
->pixel_width
= 0;
20208 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20210 /* Make sure X resources of the image is loaded. */
20211 prepare_image_for_display (it
->f
, img
);
20213 slice
.x
= slice
.y
= 0;
20214 slice
.width
= img
->width
;
20215 slice
.height
= img
->height
;
20217 if (INTEGERP (it
->slice
.x
))
20218 slice
.x
= XINT (it
->slice
.x
);
20219 else if (FLOATP (it
->slice
.x
))
20220 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20222 if (INTEGERP (it
->slice
.y
))
20223 slice
.y
= XINT (it
->slice
.y
);
20224 else if (FLOATP (it
->slice
.y
))
20225 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20227 if (INTEGERP (it
->slice
.width
))
20228 slice
.width
= XINT (it
->slice
.width
);
20229 else if (FLOATP (it
->slice
.width
))
20230 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20232 if (INTEGERP (it
->slice
.height
))
20233 slice
.height
= XINT (it
->slice
.height
);
20234 else if (FLOATP (it
->slice
.height
))
20235 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20237 if (slice
.x
>= img
->width
)
20238 slice
.x
= img
->width
;
20239 if (slice
.y
>= img
->height
)
20240 slice
.y
= img
->height
;
20241 if (slice
.x
+ slice
.width
>= img
->width
)
20242 slice
.width
= img
->width
- slice
.x
;
20243 if (slice
.y
+ slice
.height
> img
->height
)
20244 slice
.height
= img
->height
- slice
.y
;
20246 if (slice
.width
== 0 || slice
.height
== 0)
20249 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20251 it
->descent
= slice
.height
- glyph_ascent
;
20253 it
->descent
+= img
->vmargin
;
20254 if (slice
.y
+ slice
.height
== img
->height
)
20255 it
->descent
+= img
->vmargin
;
20256 it
->phys_descent
= it
->descent
;
20258 it
->pixel_width
= slice
.width
;
20260 it
->pixel_width
+= img
->hmargin
;
20261 if (slice
.x
+ slice
.width
== img
->width
)
20262 it
->pixel_width
+= img
->hmargin
;
20264 /* It's quite possible for images to have an ascent greater than
20265 their height, so don't get confused in that case. */
20266 if (it
->descent
< 0)
20269 #if 0 /* this breaks image tiling */
20270 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
20271 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
20272 if (face_ascent
> it
->ascent
)
20273 it
->ascent
= it
->phys_ascent
= face_ascent
;
20278 if (face
->box
!= FACE_NO_BOX
)
20280 if (face
->box_line_width
> 0)
20283 it
->ascent
+= face
->box_line_width
;
20284 if (slice
.y
+ slice
.height
== img
->height
)
20285 it
->descent
+= face
->box_line_width
;
20288 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20289 it
->pixel_width
+= eabs (face
->box_line_width
);
20290 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20291 it
->pixel_width
+= eabs (face
->box_line_width
);
20294 take_vertical_position_into_account (it
);
20296 /* Automatically crop wide image glyphs at right edge so we can
20297 draw the cursor on same display row. */
20298 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20299 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20301 it
->pixel_width
-= crop
;
20302 slice
.width
-= crop
;
20307 struct glyph
*glyph
;
20308 enum glyph_row_area area
= it
->area
;
20310 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20311 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20313 glyph
->charpos
= CHARPOS (it
->position
);
20314 glyph
->object
= it
->object
;
20315 glyph
->pixel_width
= it
->pixel_width
;
20316 glyph
->ascent
= glyph_ascent
;
20317 glyph
->descent
= it
->descent
;
20318 glyph
->voffset
= it
->voffset
;
20319 glyph
->type
= IMAGE_GLYPH
;
20320 glyph
->multibyte_p
= it
->multibyte_p
;
20321 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20322 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20323 glyph
->overlaps_vertically_p
= 0;
20324 glyph
->padding_p
= 0;
20325 glyph
->glyph_not_available_p
= 0;
20326 glyph
->face_id
= it
->face_id
;
20327 glyph
->u
.img_id
= img
->id
;
20328 glyph
->slice
= slice
;
20329 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20330 ++it
->glyph_row
->used
[area
];
20333 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20338 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20339 of the glyph, WIDTH and HEIGHT are the width and height of the
20340 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20343 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20345 Lisp_Object object
;
20349 struct glyph
*glyph
;
20350 enum glyph_row_area area
= it
->area
;
20352 xassert (ascent
>= 0 && ascent
<= height
);
20354 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20355 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20357 glyph
->charpos
= CHARPOS (it
->position
);
20358 glyph
->object
= object
;
20359 glyph
->pixel_width
= width
;
20360 glyph
->ascent
= ascent
;
20361 glyph
->descent
= height
- ascent
;
20362 glyph
->voffset
= it
->voffset
;
20363 glyph
->type
= STRETCH_GLYPH
;
20364 glyph
->multibyte_p
= it
->multibyte_p
;
20365 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20366 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20367 glyph
->overlaps_vertically_p
= 0;
20368 glyph
->padding_p
= 0;
20369 glyph
->glyph_not_available_p
= 0;
20370 glyph
->face_id
= it
->face_id
;
20371 glyph
->u
.stretch
.ascent
= ascent
;
20372 glyph
->u
.stretch
.height
= height
;
20373 glyph
->slice
= null_glyph_slice
;
20374 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20375 ++it
->glyph_row
->used
[area
];
20378 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20382 /* Produce a stretch glyph for iterator IT. IT->object is the value
20383 of the glyph property displayed. The value must be a list
20384 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20387 1. `:width WIDTH' specifies that the space should be WIDTH *
20388 canonical char width wide. WIDTH may be an integer or floating
20391 2. `:relative-width FACTOR' specifies that the width of the stretch
20392 should be computed from the width of the first character having the
20393 `glyph' property, and should be FACTOR times that width.
20395 3. `:align-to HPOS' specifies that the space should be wide enough
20396 to reach HPOS, a value in canonical character units.
20398 Exactly one of the above pairs must be present.
20400 4. `:height HEIGHT' specifies that the height of the stretch produced
20401 should be HEIGHT, measured in canonical character units.
20403 5. `:relative-height FACTOR' specifies that the height of the
20404 stretch should be FACTOR times the height of the characters having
20405 the glyph property.
20407 Either none or exactly one of 4 or 5 must be present.
20409 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20410 of the stretch should be used for the ascent of the stretch.
20411 ASCENT must be in the range 0 <= ASCENT <= 100. */
20414 produce_stretch_glyph (it
)
20417 /* (space :width WIDTH :height HEIGHT ...) */
20418 Lisp_Object prop
, plist
;
20419 int width
= 0, height
= 0, align_to
= -1;
20420 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20423 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20424 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20426 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20428 /* List should start with `space'. */
20429 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20430 plist
= XCDR (it
->object
);
20432 /* Compute the width of the stretch. */
20433 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20434 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20436 /* Absolute width `:width WIDTH' specified and valid. */
20437 zero_width_ok_p
= 1;
20440 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20443 /* Relative width `:relative-width FACTOR' specified and valid.
20444 Compute the width of the characters having the `glyph'
20447 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20450 if (it
->multibyte_p
)
20452 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20453 - IT_BYTEPOS (*it
));
20454 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20457 it2
.c
= *p
, it2
.len
= 1;
20459 it2
.glyph_row
= NULL
;
20460 it2
.what
= IT_CHARACTER
;
20461 x_produce_glyphs (&it2
);
20462 width
= NUMVAL (prop
) * it2
.pixel_width
;
20464 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20465 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20467 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20468 align_to
= (align_to
< 0
20470 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20471 else if (align_to
< 0)
20472 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20473 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20474 zero_width_ok_p
= 1;
20477 /* Nothing specified -> width defaults to canonical char width. */
20478 width
= FRAME_COLUMN_WIDTH (it
->f
);
20480 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20483 /* Compute height. */
20484 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20485 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20488 zero_height_ok_p
= 1;
20490 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20492 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20494 height
= FONT_HEIGHT (font
);
20496 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20499 /* Compute percentage of height used for ascent. If
20500 `:ascent ASCENT' is present and valid, use that. Otherwise,
20501 derive the ascent from the font in use. */
20502 if (prop
= Fplist_get (plist
, QCascent
),
20503 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20504 ascent
= height
* NUMVAL (prop
) / 100.0;
20505 else if (!NILP (prop
)
20506 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20507 ascent
= min (max (0, (int)tem
), height
);
20509 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20511 if (width
> 0 && !it
->truncate_lines_p
20512 && it
->current_x
+ width
> it
->last_visible_x
)
20513 width
= it
->last_visible_x
- it
->current_x
- 1;
20515 if (width
> 0 && height
> 0 && it
->glyph_row
)
20517 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20518 if (!STRINGP (object
))
20519 object
= it
->w
->buffer
;
20520 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20523 it
->pixel_width
= width
;
20524 it
->ascent
= it
->phys_ascent
= ascent
;
20525 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20526 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20528 take_vertical_position_into_account (it
);
20531 /* Get line-height and line-spacing property at point.
20532 If line-height has format (HEIGHT TOTAL), return TOTAL
20533 in TOTAL_HEIGHT. */
20536 get_line_height_property (it
, prop
)
20540 Lisp_Object position
;
20542 if (STRINGP (it
->object
))
20543 position
= make_number (IT_STRING_CHARPOS (*it
));
20544 else if (BUFFERP (it
->object
))
20545 position
= make_number (IT_CHARPOS (*it
));
20549 return Fget_char_property (position
, prop
, it
->object
);
20552 /* Calculate line-height and line-spacing properties.
20553 An integer value specifies explicit pixel value.
20554 A float value specifies relative value to current face height.
20555 A cons (float . face-name) specifies relative value to
20556 height of specified face font.
20558 Returns height in pixels, or nil. */
20562 calc_line_height_property (it
, val
, font
, boff
, override
)
20566 int boff
, override
;
20568 Lisp_Object face_name
= Qnil
;
20569 int ascent
, descent
, height
;
20571 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20576 face_name
= XCAR (val
);
20578 if (!NUMBERP (val
))
20579 val
= make_number (1);
20580 if (NILP (face_name
))
20582 height
= it
->ascent
+ it
->descent
;
20587 if (NILP (face_name
))
20589 font
= FRAME_FONT (it
->f
);
20590 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20592 else if (EQ (face_name
, Qt
))
20601 face_id
= lookup_named_face (it
->f
, face_name
, 0);
20603 return make_number (-1);
20605 face
= FACE_FROM_ID (it
->f
, face_id
);
20608 return make_number (-1);
20609 boff
= font
->baseline_offset
;
20610 if (font
->vertical_centering
)
20611 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20614 ascent
= FONT_BASE (font
) + boff
;
20615 descent
= FONT_DESCENT (font
) - boff
;
20619 it
->override_ascent
= ascent
;
20620 it
->override_descent
= descent
;
20621 it
->override_boff
= boff
;
20624 height
= ascent
+ descent
;
20628 height
= (int)(XFLOAT_DATA (val
) * height
);
20629 else if (INTEGERP (val
))
20630 height
*= XINT (val
);
20632 return make_number (height
);
20637 Produce glyphs/get display metrics for the display element IT is
20638 loaded with. See the description of struct it in dispextern.h
20639 for an overview of struct it. */
20642 x_produce_glyphs (it
)
20645 int extra_line_spacing
= it
->extra_line_spacing
;
20647 it
->glyph_not_available_p
= 0;
20649 if (it
->what
== IT_CHARACTER
)
20653 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20654 struct font_metrics
*pcm
;
20655 int font_not_found_p
;
20656 int boff
; /* baseline offset */
20657 /* We may change it->multibyte_p upon unibyte<->multibyte
20658 conversion. So, save the current value now and restore it
20661 Note: It seems that we don't have to record multibyte_p in
20662 struct glyph because the character code itself tells if or
20663 not the character is multibyte. Thus, in the future, we must
20664 consider eliminating the field `multibyte_p' in the struct
20666 int saved_multibyte_p
= it
->multibyte_p
;
20668 /* Maybe translate single-byte characters to multibyte, or the
20670 it
->char_to_display
= it
->c
;
20671 if (!ASCII_BYTE_P (it
->c
)
20672 && ! it
->multibyte_p
)
20674 if (SINGLE_BYTE_CHAR_P (it
->c
)
20675 && unibyte_display_via_language_environment
)
20676 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20677 if (! SINGLE_BYTE_CHAR_P (it
->char_to_display
))
20679 it
->multibyte_p
= 1;
20680 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
20682 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20686 /* Get font to use. Encode IT->char_to_display. */
20687 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20688 &char2b
, it
->multibyte_p
, 0);
20691 /* When no suitable font found, use the default font. */
20692 font_not_found_p
= font
== NULL
;
20693 if (font_not_found_p
)
20695 font
= FRAME_FONT (it
->f
);
20696 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20700 boff
= font
->baseline_offset
;
20701 if (font
->vertical_centering
)
20702 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20705 if (it
->char_to_display
>= ' '
20706 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20708 /* Either unibyte or ASCII. */
20713 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
20715 if (it
->override_ascent
>= 0)
20717 it
->ascent
= it
->override_ascent
;
20718 it
->descent
= it
->override_descent
;
20719 boff
= it
->override_boff
;
20723 it
->ascent
= FONT_BASE (font
) + boff
;
20724 it
->descent
= FONT_DESCENT (font
) - boff
;
20729 it
->phys_ascent
= pcm
->ascent
+ boff
;
20730 it
->phys_descent
= pcm
->descent
- boff
;
20731 it
->pixel_width
= pcm
->width
;
20735 it
->glyph_not_available_p
= 1;
20736 it
->phys_ascent
= it
->ascent
;
20737 it
->phys_descent
= it
->descent
;
20738 it
->pixel_width
= FONT_WIDTH (font
);
20741 if (it
->constrain_row_ascent_descent_p
)
20743 if (it
->descent
> it
->max_descent
)
20745 it
->ascent
+= it
->descent
- it
->max_descent
;
20746 it
->descent
= it
->max_descent
;
20748 if (it
->ascent
> it
->max_ascent
)
20750 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20751 it
->ascent
= it
->max_ascent
;
20753 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20754 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20755 extra_line_spacing
= 0;
20758 /* If this is a space inside a region of text with
20759 `space-width' property, change its width. */
20760 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20762 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20764 /* If face has a box, add the box thickness to the character
20765 height. If character has a box line to the left and/or
20766 right, add the box line width to the character's width. */
20767 if (face
->box
!= FACE_NO_BOX
)
20769 int thick
= face
->box_line_width
;
20773 it
->ascent
+= thick
;
20774 it
->descent
+= thick
;
20779 if (it
->start_of_box_run_p
)
20780 it
->pixel_width
+= thick
;
20781 if (it
->end_of_box_run_p
)
20782 it
->pixel_width
+= thick
;
20785 /* If face has an overline, add the height of the overline
20786 (1 pixel) and a 1 pixel margin to the character height. */
20787 if (face
->overline_p
)
20788 it
->ascent
+= overline_margin
;
20790 if (it
->constrain_row_ascent_descent_p
)
20792 if (it
->ascent
> it
->max_ascent
)
20793 it
->ascent
= it
->max_ascent
;
20794 if (it
->descent
> it
->max_descent
)
20795 it
->descent
= it
->max_descent
;
20798 take_vertical_position_into_account (it
);
20800 /* If we have to actually produce glyphs, do it. */
20805 /* Translate a space with a `space-width' property
20806 into a stretch glyph. */
20807 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20808 / FONT_HEIGHT (font
));
20809 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20810 it
->ascent
+ it
->descent
, ascent
);
20815 /* If characters with lbearing or rbearing are displayed
20816 in this line, record that fact in a flag of the
20817 glyph row. This is used to optimize X output code. */
20818 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20819 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20821 if (! stretched_p
&& it
->pixel_width
== 0)
20822 /* We assure that all visible glyphs have at least 1-pixel
20824 it
->pixel_width
= 1;
20826 else if (it
->char_to_display
== '\n')
20828 /* A newline has no width but we need the height of the line.
20829 But if previous part of the line set a height, don't
20830 increase that height */
20832 Lisp_Object height
;
20833 Lisp_Object total_height
= Qnil
;
20835 it
->override_ascent
= -1;
20836 it
->pixel_width
= 0;
20839 height
= get_line_height_property(it
, Qline_height
);
20840 /* Split (line-height total-height) list */
20842 && CONSP (XCDR (height
))
20843 && NILP (XCDR (XCDR (height
))))
20845 total_height
= XCAR (XCDR (height
));
20846 height
= XCAR (height
);
20848 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20850 if (it
->override_ascent
>= 0)
20852 it
->ascent
= it
->override_ascent
;
20853 it
->descent
= it
->override_descent
;
20854 boff
= it
->override_boff
;
20858 it
->ascent
= FONT_BASE (font
) + boff
;
20859 it
->descent
= FONT_DESCENT (font
) - boff
;
20862 if (EQ (height
, Qt
))
20864 if (it
->descent
> it
->max_descent
)
20866 it
->ascent
+= it
->descent
- it
->max_descent
;
20867 it
->descent
= it
->max_descent
;
20869 if (it
->ascent
> it
->max_ascent
)
20871 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20872 it
->ascent
= it
->max_ascent
;
20874 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20875 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20876 it
->constrain_row_ascent_descent_p
= 1;
20877 extra_line_spacing
= 0;
20881 Lisp_Object spacing
;
20883 it
->phys_ascent
= it
->ascent
;
20884 it
->phys_descent
= it
->descent
;
20886 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20887 && face
->box
!= FACE_NO_BOX
20888 && face
->box_line_width
> 0)
20890 it
->ascent
+= face
->box_line_width
;
20891 it
->descent
+= face
->box_line_width
;
20894 && XINT (height
) > it
->ascent
+ it
->descent
)
20895 it
->ascent
= XINT (height
) - it
->descent
;
20897 if (!NILP (total_height
))
20898 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20901 spacing
= get_line_height_property(it
, Qline_spacing
);
20902 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20904 if (INTEGERP (spacing
))
20906 extra_line_spacing
= XINT (spacing
);
20907 if (!NILP (total_height
))
20908 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20912 else if (it
->char_to_display
== '\t')
20914 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20915 int x
= it
->current_x
+ it
->continuation_lines_width
;
20916 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20918 /* If the distance from the current position to the next tab
20919 stop is less than a space character width, use the
20920 tab stop after that. */
20921 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20922 next_tab_x
+= tab_width
;
20924 it
->pixel_width
= next_tab_x
- x
;
20926 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20927 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20931 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20932 it
->ascent
+ it
->descent
, it
->ascent
);
20937 /* A multi-byte character. Assume that the display width of the
20938 character is the width of the character multiplied by the
20939 width of the font. */
20941 /* If we found a font, this font should give us the right
20942 metrics. If we didn't find a font, use the frame's
20943 default font and calculate the width of the character by
20944 multiplying the width of font by the width of the
20947 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
20949 if (font_not_found_p
|| !pcm
)
20951 int char_width
= CHAR_WIDTH (it
->char_to_display
);
20953 if (char_width
== 0)
20954 /* This is a non spacing character. But, as we are
20955 going to display an empty box, the box must occupy
20956 at least one column. */
20958 it
->glyph_not_available_p
= 1;
20959 it
->pixel_width
= FRAME_COLUMN_WIDTH (it
->f
) * char_width
;
20960 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20961 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20965 it
->pixel_width
= pcm
->width
;
20966 it
->phys_ascent
= pcm
->ascent
+ boff
;
20967 it
->phys_descent
= pcm
->descent
- boff
;
20969 && (pcm
->lbearing
< 0
20970 || pcm
->rbearing
> pcm
->width
))
20971 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20974 it
->ascent
= FONT_BASE (font
) + boff
;
20975 it
->descent
= FONT_DESCENT (font
) - boff
;
20976 if (face
->box
!= FACE_NO_BOX
)
20978 int thick
= face
->box_line_width
;
20982 it
->ascent
+= thick
;
20983 it
->descent
+= thick
;
20988 if (it
->start_of_box_run_p
)
20989 it
->pixel_width
+= thick
;
20990 if (it
->end_of_box_run_p
)
20991 it
->pixel_width
+= thick
;
20994 /* If face has an overline, add the height of the overline
20995 (1 pixel) and a 1 pixel margin to the character height. */
20996 if (face
->overline_p
)
20997 it
->ascent
+= overline_margin
;
20999 take_vertical_position_into_account (it
);
21001 if (it
->ascent
< 0)
21003 if (it
->descent
< 0)
21008 if (it
->pixel_width
== 0)
21009 /* We assure that all visible glyphs have at least 1-pixel
21011 it
->pixel_width
= 1;
21013 it
->multibyte_p
= saved_multibyte_p
;
21015 else if (it
->what
== IT_COMPOSITION
)
21017 /* Note: A composition is represented as one glyph in the
21018 glyph matrix. There are no padding glyphs.
21020 Important is that pixel_width, ascent, and descent are the
21021 values of what is drawn by draw_glyphs (i.e. the values of
21022 the overall glyphs composed). */
21023 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21024 int boff
; /* baseline offset */
21025 struct composition
*cmp
= composition_table
[it
->cmp_id
];
21026 int glyph_len
= cmp
->glyph_len
;
21027 struct font
*font
= face
->font
;
21031 if (cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
21033 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21034 font_prepare_composition (cmp
, it
->f
);
21037 /* If we have not yet calculated pixel size data of glyphs of
21038 the composition for the current face font, calculate them
21039 now. Theoretically, we have to check all fonts for the
21040 glyphs, but that requires much time and memory space. So,
21041 here we check only the font of the first glyph. This leads
21042 to incorrect display, but it's very rare, and C-l (recenter)
21043 can correct the display anyway. */
21044 if (! cmp
->font
|| cmp
->font
!= font
)
21046 /* Ascent and descent of the font of the first character
21047 of this composition (adjusted by baseline offset).
21048 Ascent and descent of overall glyphs should not be less
21049 than them respectively. */
21050 int font_ascent
, font_descent
, font_height
;
21051 /* Bounding box of the overall glyphs. */
21052 int leftmost
, rightmost
, lowest
, highest
;
21053 int lbearing
, rbearing
;
21054 int i
, width
, ascent
, descent
;
21055 int left_padded
= 0, right_padded
= 0;
21059 struct font_metrics
*pcm
;
21060 int font_not_found_p
;
21063 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21064 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21066 if (glyph_len
< cmp
->glyph_len
)
21068 for (i
= 0; i
< glyph_len
; i
++)
21070 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21072 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21077 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21078 : IT_CHARPOS (*it
));
21079 /* When no suitable font found, use the default font. */
21080 font_not_found_p
= font
== NULL
;
21081 if (font_not_found_p
)
21083 face
= face
->ascii_face
;
21086 boff
= font
->baseline_offset
;
21087 if (font
->vertical_centering
)
21088 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21089 font_ascent
= FONT_BASE (font
) + boff
;
21090 font_descent
= FONT_DESCENT (font
) - boff
;
21091 font_height
= FONT_HEIGHT (font
);
21093 cmp
->font
= (void *) font
;
21096 if (! font_not_found_p
)
21098 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21099 &char2b
, it
->multibyte_p
, 0);
21100 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21103 /* Initialize the bounding box. */
21106 width
= pcm
->width
;
21107 ascent
= pcm
->ascent
;
21108 descent
= pcm
->descent
;
21109 lbearing
= pcm
->lbearing
;
21110 rbearing
= pcm
->rbearing
;
21114 width
= FONT_WIDTH (font
);
21115 ascent
= FONT_BASE (font
);
21116 descent
= FONT_DESCENT (font
);
21123 lowest
= - descent
+ boff
;
21124 highest
= ascent
+ boff
;
21126 if (! font_not_found_p
21127 && font
->default_ascent
21128 && CHAR_TABLE_P (Vuse_default_ascent
)
21129 && !NILP (Faref (Vuse_default_ascent
,
21130 make_number (it
->char_to_display
))))
21131 highest
= font
->default_ascent
+ boff
;
21133 /* Draw the first glyph at the normal position. It may be
21134 shifted to right later if some other glyphs are drawn
21136 cmp
->offsets
[i
* 2] = 0;
21137 cmp
->offsets
[i
* 2 + 1] = boff
;
21138 cmp
->lbearing
= lbearing
;
21139 cmp
->rbearing
= rbearing
;
21141 /* Set cmp->offsets for the remaining glyphs. */
21142 for (i
++; i
< glyph_len
; i
++)
21144 int left
, right
, btm
, top
;
21145 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21147 struct face
*this_face
;
21152 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21153 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21154 font
= this_face
->font
;
21160 this_boff
= font
->baseline_offset
;
21161 if (font
->vertical_centering
)
21162 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21163 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21164 &char2b
, it
->multibyte_p
, 0);
21165 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21168 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21171 width
= pcm
->width
;
21172 ascent
= pcm
->ascent
;
21173 descent
= pcm
->descent
;
21174 lbearing
= pcm
->lbearing
;
21175 rbearing
= pcm
->rbearing
;
21176 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21178 /* Relative composition with or without
21179 alternate chars. */
21180 left
= (leftmost
+ rightmost
- width
) / 2;
21181 btm
= - descent
+ boff
;
21182 if (font
->relative_compose
21183 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21184 || NILP (Faref (Vignore_relative_composition
,
21185 make_number (ch
)))))
21188 if (- descent
>= font
->relative_compose
)
21189 /* One extra pixel between two glyphs. */
21191 else if (ascent
<= 0)
21192 /* One extra pixel between two glyphs. */
21193 btm
= lowest
- 1 - ascent
- descent
;
21198 /* A composition rule is specified by an integer
21199 value that encodes global and new reference
21200 points (GREF and NREF). GREF and NREF are
21201 specified by numbers as below:
21203 0---1---2 -- ascent
21207 9--10--11 -- center
21209 ---3---4---5--- baseline
21211 6---7---8 -- descent
21213 int rule
= COMPOSITION_RULE (cmp
, i
);
21214 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21216 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21217 grefx
= gref
% 3, nrefx
= nref
% 3;
21218 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21220 xoff
= font_height
* (xoff
- 128) / 256;
21222 yoff
= font_height
* (yoff
- 128) / 256;
21225 + grefx
* (rightmost
- leftmost
) / 2
21226 - nrefx
* width
/ 2
21229 btm
= ((grefy
== 0 ? highest
21231 : grefy
== 2 ? lowest
21232 : (highest
+ lowest
) / 2)
21233 - (nrefy
== 0 ? ascent
+ descent
21234 : nrefy
== 1 ? descent
- boff
21236 : (ascent
+ descent
) / 2)
21240 cmp
->offsets
[i
* 2] = left
;
21241 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21243 /* Update the bounding box of the overall glyphs. */
21246 right
= left
+ width
;
21247 if (left
< leftmost
)
21249 if (right
> rightmost
)
21252 top
= btm
+ descent
+ ascent
;
21258 if (cmp
->lbearing
> left
+ lbearing
)
21259 cmp
->lbearing
= left
+ lbearing
;
21260 if (cmp
->rbearing
< left
+ rbearing
)
21261 cmp
->rbearing
= left
+ rbearing
;
21265 /* If there are glyphs whose x-offsets are negative,
21266 shift all glyphs to the right and make all x-offsets
21270 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21271 cmp
->offsets
[i
* 2] -= leftmost
;
21272 rightmost
-= leftmost
;
21273 cmp
->lbearing
-= leftmost
;
21274 cmp
->rbearing
-= leftmost
;
21277 if (left_padded
&& cmp
->lbearing
< 0)
21279 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21280 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21281 rightmost
-= cmp
->lbearing
;
21282 cmp
->rbearing
-= cmp
->lbearing
;
21285 if (right_padded
&& rightmost
< cmp
->rbearing
)
21287 rightmost
= cmp
->rbearing
;
21290 cmp
->pixel_width
= rightmost
;
21291 cmp
->ascent
= highest
;
21292 cmp
->descent
= - lowest
;
21293 if (cmp
->ascent
< font_ascent
)
21294 cmp
->ascent
= font_ascent
;
21295 if (cmp
->descent
< font_descent
)
21296 cmp
->descent
= font_descent
;
21300 && (cmp
->lbearing
< 0
21301 || cmp
->rbearing
> cmp
->pixel_width
))
21302 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21304 it
->pixel_width
= cmp
->pixel_width
;
21305 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21306 it
->descent
= it
->phys_descent
= cmp
->descent
;
21307 if (face
->box
!= FACE_NO_BOX
)
21309 int thick
= face
->box_line_width
;
21313 it
->ascent
+= thick
;
21314 it
->descent
+= thick
;
21319 if (it
->start_of_box_run_p
)
21320 it
->pixel_width
+= thick
;
21321 if (it
->end_of_box_run_p
)
21322 it
->pixel_width
+= thick
;
21325 /* If face has an overline, add the height of the overline
21326 (1 pixel) and a 1 pixel margin to the character height. */
21327 if (face
->overline_p
)
21328 it
->ascent
+= overline_margin
;
21330 take_vertical_position_into_account (it
);
21331 if (it
->ascent
< 0)
21333 if (it
->descent
< 0)
21337 append_composite_glyph (it
);
21339 else if (it
->what
== IT_IMAGE
)
21340 produce_image_glyph (it
);
21341 else if (it
->what
== IT_STRETCH
)
21342 produce_stretch_glyph (it
);
21344 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21345 because this isn't true for images with `:ascent 100'. */
21346 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21347 if (it
->area
== TEXT_AREA
)
21348 it
->current_x
+= it
->pixel_width
;
21350 if (extra_line_spacing
> 0)
21352 it
->descent
+= extra_line_spacing
;
21353 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21354 it
->max_extra_line_spacing
= extra_line_spacing
;
21357 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21358 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21359 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21360 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21364 Output LEN glyphs starting at START at the nominal cursor position.
21365 Advance the nominal cursor over the text. The global variable
21366 updated_window contains the window being updated, updated_row is
21367 the glyph row being updated, and updated_area is the area of that
21368 row being updated. */
21371 x_write_glyphs (start
, len
)
21372 struct glyph
*start
;
21377 xassert (updated_window
&& updated_row
);
21380 /* Write glyphs. */
21382 hpos
= start
- updated_row
->glyphs
[updated_area
];
21383 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21384 updated_row
, updated_area
,
21386 DRAW_NORMAL_TEXT
, 0);
21388 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21389 if (updated_area
== TEXT_AREA
21390 && updated_window
->phys_cursor_on_p
21391 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21392 && updated_window
->phys_cursor
.hpos
>= hpos
21393 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21394 updated_window
->phys_cursor_on_p
= 0;
21398 /* Advance the output cursor. */
21399 output_cursor
.hpos
+= len
;
21400 output_cursor
.x
= x
;
21405 Insert LEN glyphs from START at the nominal cursor position. */
21408 x_insert_glyphs (start
, len
)
21409 struct glyph
*start
;
21414 int line_height
, shift_by_width
, shifted_region_width
;
21415 struct glyph_row
*row
;
21416 struct glyph
*glyph
;
21417 int frame_x
, frame_y
;
21420 xassert (updated_window
&& updated_row
);
21422 w
= updated_window
;
21423 f
= XFRAME (WINDOW_FRAME (w
));
21425 /* Get the height of the line we are in. */
21427 line_height
= row
->height
;
21429 /* Get the width of the glyphs to insert. */
21430 shift_by_width
= 0;
21431 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21432 shift_by_width
+= glyph
->pixel_width
;
21434 /* Get the width of the region to shift right. */
21435 shifted_region_width
= (window_box_width (w
, updated_area
)
21440 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21441 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21443 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21444 line_height
, shift_by_width
);
21446 /* Write the glyphs. */
21447 hpos
= start
- row
->glyphs
[updated_area
];
21448 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21450 DRAW_NORMAL_TEXT
, 0);
21452 /* Advance the output cursor. */
21453 output_cursor
.hpos
+= len
;
21454 output_cursor
.x
+= shift_by_width
;
21460 Erase the current text line from the nominal cursor position
21461 (inclusive) to pixel column TO_X (exclusive). The idea is that
21462 everything from TO_X onward is already erased.
21464 TO_X is a pixel position relative to updated_area of
21465 updated_window. TO_X == -1 means clear to the end of this area. */
21468 x_clear_end_of_line (to_x
)
21472 struct window
*w
= updated_window
;
21473 int max_x
, min_y
, max_y
;
21474 int from_x
, from_y
, to_y
;
21476 xassert (updated_window
&& updated_row
);
21477 f
= XFRAME (w
->frame
);
21479 if (updated_row
->full_width_p
)
21480 max_x
= WINDOW_TOTAL_WIDTH (w
);
21482 max_x
= window_box_width (w
, updated_area
);
21483 max_y
= window_text_bottom_y (w
);
21485 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21486 of window. For TO_X > 0, truncate to end of drawing area. */
21492 to_x
= min (to_x
, max_x
);
21494 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21496 /* Notice if the cursor will be cleared by this operation. */
21497 if (!updated_row
->full_width_p
)
21498 notice_overwritten_cursor (w
, updated_area
,
21499 output_cursor
.x
, -1,
21501 MATRIX_ROW_BOTTOM_Y (updated_row
));
21503 from_x
= output_cursor
.x
;
21505 /* Translate to frame coordinates. */
21506 if (updated_row
->full_width_p
)
21508 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21509 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21513 int area_left
= window_box_left (w
, updated_area
);
21514 from_x
+= area_left
;
21518 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21519 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21520 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21522 /* Prevent inadvertently clearing to end of the X window. */
21523 if (to_x
> from_x
&& to_y
> from_y
)
21526 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21527 to_x
- from_x
, to_y
- from_y
);
21532 #endif /* HAVE_WINDOW_SYSTEM */
21536 /***********************************************************************
21538 ***********************************************************************/
21540 /* Value is the internal representation of the specified cursor type
21541 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21542 of the bar cursor. */
21544 static enum text_cursor_kinds
21545 get_specified_cursor_type (arg
, width
)
21549 enum text_cursor_kinds type
;
21554 if (EQ (arg
, Qbox
))
21555 return FILLED_BOX_CURSOR
;
21557 if (EQ (arg
, Qhollow
))
21558 return HOLLOW_BOX_CURSOR
;
21560 if (EQ (arg
, Qbar
))
21567 && EQ (XCAR (arg
), Qbar
)
21568 && INTEGERP (XCDR (arg
))
21569 && XINT (XCDR (arg
)) >= 0)
21571 *width
= XINT (XCDR (arg
));
21575 if (EQ (arg
, Qhbar
))
21578 return HBAR_CURSOR
;
21582 && EQ (XCAR (arg
), Qhbar
)
21583 && INTEGERP (XCDR (arg
))
21584 && XINT (XCDR (arg
)) >= 0)
21586 *width
= XINT (XCDR (arg
));
21587 return HBAR_CURSOR
;
21590 /* Treat anything unknown as "hollow box cursor".
21591 It was bad to signal an error; people have trouble fixing
21592 .Xdefaults with Emacs, when it has something bad in it. */
21593 type
= HOLLOW_BOX_CURSOR
;
21598 /* Set the default cursor types for specified frame. */
21600 set_frame_cursor_types (f
, arg
)
21607 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21608 FRAME_CURSOR_WIDTH (f
) = width
;
21610 /* By default, set up the blink-off state depending on the on-state. */
21612 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21615 FRAME_BLINK_OFF_CURSOR (f
)
21616 = get_specified_cursor_type (XCDR (tem
), &width
);
21617 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21620 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21624 /* Return the cursor we want to be displayed in window W. Return
21625 width of bar/hbar cursor through WIDTH arg. Return with
21626 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21627 (i.e. if the `system caret' should track this cursor).
21629 In a mini-buffer window, we want the cursor only to appear if we
21630 are reading input from this window. For the selected window, we
21631 want the cursor type given by the frame parameter or buffer local
21632 setting of cursor-type. If explicitly marked off, draw no cursor.
21633 In all other cases, we want a hollow box cursor. */
21635 static enum text_cursor_kinds
21636 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21638 struct glyph
*glyph
;
21640 int *active_cursor
;
21642 struct frame
*f
= XFRAME (w
->frame
);
21643 struct buffer
*b
= XBUFFER (w
->buffer
);
21644 int cursor_type
= DEFAULT_CURSOR
;
21645 Lisp_Object alt_cursor
;
21646 int non_selected
= 0;
21648 *active_cursor
= 1;
21651 if (cursor_in_echo_area
21652 && FRAME_HAS_MINIBUF_P (f
)
21653 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21655 if (w
== XWINDOW (echo_area_window
))
21657 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21659 *width
= FRAME_CURSOR_WIDTH (f
);
21660 return FRAME_DESIRED_CURSOR (f
);
21663 return get_specified_cursor_type (b
->cursor_type
, width
);
21666 *active_cursor
= 0;
21670 /* Detect a nonselected window or nonselected frame. */
21671 else if (w
!= XWINDOW (f
->selected_window
)
21672 #ifdef HAVE_WINDOW_SYSTEM
21673 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21677 *active_cursor
= 0;
21679 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21685 /* Never display a cursor in a window in which cursor-type is nil. */
21686 if (NILP (b
->cursor_type
))
21689 /* Get the normal cursor type for this window. */
21690 if (EQ (b
->cursor_type
, Qt
))
21692 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21693 *width
= FRAME_CURSOR_WIDTH (f
);
21696 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21698 /* Use cursor-in-non-selected-windows instead
21699 for non-selected window or frame. */
21702 alt_cursor
= b
->cursor_in_non_selected_windows
;
21703 if (!EQ (Qt
, alt_cursor
))
21704 return get_specified_cursor_type (alt_cursor
, width
);
21705 /* t means modify the normal cursor type. */
21706 if (cursor_type
== FILLED_BOX_CURSOR
)
21707 cursor_type
= HOLLOW_BOX_CURSOR
;
21708 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
21710 return cursor_type
;
21713 /* Use normal cursor if not blinked off. */
21714 if (!w
->cursor_off_p
)
21716 #ifdef HAVE_WINDOW_SYSTEM
21717 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21719 if (cursor_type
== FILLED_BOX_CURSOR
)
21721 /* Using a block cursor on large images can be very annoying.
21722 So use a hollow cursor for "large" images.
21723 If image is not transparent (no mask), also use hollow cursor. */
21724 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21725 if (img
!= NULL
&& IMAGEP (img
->spec
))
21727 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21728 where N = size of default frame font size.
21729 This should cover most of the "tiny" icons people may use. */
21731 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21732 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21733 cursor_type
= HOLLOW_BOX_CURSOR
;
21736 else if (cursor_type
!= NO_CURSOR
)
21738 /* Display current only supports BOX and HOLLOW cursors for images.
21739 So for now, unconditionally use a HOLLOW cursor when cursor is
21740 not a solid box cursor. */
21741 cursor_type
= HOLLOW_BOX_CURSOR
;
21745 return cursor_type
;
21748 /* Cursor is blinked off, so determine how to "toggle" it. */
21750 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21751 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21752 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21754 /* Then see if frame has specified a specific blink off cursor type. */
21755 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21757 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21758 return FRAME_BLINK_OFF_CURSOR (f
);
21762 /* Some people liked having a permanently visible blinking cursor,
21763 while others had very strong opinions against it. So it was
21764 decided to remove it. KFS 2003-09-03 */
21766 /* Finally perform built-in cursor blinking:
21767 filled box <-> hollow box
21768 wide [h]bar <-> narrow [h]bar
21769 narrow [h]bar <-> no cursor
21770 other type <-> no cursor */
21772 if (cursor_type
== FILLED_BOX_CURSOR
)
21773 return HOLLOW_BOX_CURSOR
;
21775 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21778 return cursor_type
;
21786 #ifdef HAVE_WINDOW_SYSTEM
21788 /* Notice when the text cursor of window W has been completely
21789 overwritten by a drawing operation that outputs glyphs in AREA
21790 starting at X0 and ending at X1 in the line starting at Y0 and
21791 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21792 the rest of the line after X0 has been written. Y coordinates
21793 are window-relative. */
21796 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21798 enum glyph_row_area area
;
21799 int x0
, y0
, x1
, y1
;
21801 int cx0
, cx1
, cy0
, cy1
;
21802 struct glyph_row
*row
;
21804 if (!w
->phys_cursor_on_p
)
21806 if (area
!= TEXT_AREA
)
21809 if (w
->phys_cursor
.vpos
< 0
21810 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21811 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21812 !(row
->enabled_p
&& row
->displays_text_p
)))
21815 if (row
->cursor_in_fringe_p
)
21817 row
->cursor_in_fringe_p
= 0;
21818 draw_fringe_bitmap (w
, row
, 0);
21819 w
->phys_cursor_on_p
= 0;
21823 cx0
= w
->phys_cursor
.x
;
21824 cx1
= cx0
+ w
->phys_cursor_width
;
21825 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21828 /* The cursor image will be completely removed from the
21829 screen if the output area intersects the cursor area in
21830 y-direction. When we draw in [y0 y1[, and some part of
21831 the cursor is at y < y0, that part must have been drawn
21832 before. When scrolling, the cursor is erased before
21833 actually scrolling, so we don't come here. When not
21834 scrolling, the rows above the old cursor row must have
21835 changed, and in this case these rows must have written
21836 over the cursor image.
21838 Likewise if part of the cursor is below y1, with the
21839 exception of the cursor being in the first blank row at
21840 the buffer and window end because update_text_area
21841 doesn't draw that row. (Except when it does, but
21842 that's handled in update_text_area.) */
21844 cy0
= w
->phys_cursor
.y
;
21845 cy1
= cy0
+ w
->phys_cursor_height
;
21846 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21849 w
->phys_cursor_on_p
= 0;
21852 #endif /* HAVE_WINDOW_SYSTEM */
21855 /************************************************************************
21857 ************************************************************************/
21859 #ifdef HAVE_WINDOW_SYSTEM
21862 Fix the display of area AREA of overlapping row ROW in window W
21863 with respect to the overlapping part OVERLAPS. */
21866 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21868 struct glyph_row
*row
;
21869 enum glyph_row_area area
;
21877 for (i
= 0; i
< row
->used
[area
];)
21879 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21881 int start
= i
, start_x
= x
;
21885 x
+= row
->glyphs
[area
][i
].pixel_width
;
21888 while (i
< row
->used
[area
]
21889 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21891 draw_glyphs (w
, start_x
, row
, area
,
21893 DRAW_NORMAL_TEXT
, overlaps
);
21897 x
+= row
->glyphs
[area
][i
].pixel_width
;
21907 Draw the cursor glyph of window W in glyph row ROW. See the
21908 comment of draw_glyphs for the meaning of HL. */
21911 draw_phys_cursor_glyph (w
, row
, hl
)
21913 struct glyph_row
*row
;
21914 enum draw_glyphs_face hl
;
21916 /* If cursor hpos is out of bounds, don't draw garbage. This can
21917 happen in mini-buffer windows when switching between echo area
21918 glyphs and mini-buffer. */
21919 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21921 int on_p
= w
->phys_cursor_on_p
;
21923 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21924 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21926 w
->phys_cursor_on_p
= on_p
;
21928 if (hl
== DRAW_CURSOR
)
21929 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21930 /* When we erase the cursor, and ROW is overlapped by other
21931 rows, make sure that these overlapping parts of other rows
21933 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21935 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21937 if (row
> w
->current_matrix
->rows
21938 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21939 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21940 OVERLAPS_ERASED_CURSOR
);
21942 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21943 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21944 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21945 OVERLAPS_ERASED_CURSOR
);
21952 Erase the image of a cursor of window W from the screen. */
21955 erase_phys_cursor (w
)
21958 struct frame
*f
= XFRAME (w
->frame
);
21959 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21960 int hpos
= w
->phys_cursor
.hpos
;
21961 int vpos
= w
->phys_cursor
.vpos
;
21962 int mouse_face_here_p
= 0;
21963 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21964 struct glyph_row
*cursor_row
;
21965 struct glyph
*cursor_glyph
;
21966 enum draw_glyphs_face hl
;
21968 /* No cursor displayed or row invalidated => nothing to do on the
21970 if (w
->phys_cursor_type
== NO_CURSOR
)
21971 goto mark_cursor_off
;
21973 /* VPOS >= active_glyphs->nrows means that window has been resized.
21974 Don't bother to erase the cursor. */
21975 if (vpos
>= active_glyphs
->nrows
)
21976 goto mark_cursor_off
;
21978 /* If row containing cursor is marked invalid, there is nothing we
21980 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21981 if (!cursor_row
->enabled_p
)
21982 goto mark_cursor_off
;
21984 /* If line spacing is > 0, old cursor may only be partially visible in
21985 window after split-window. So adjust visible height. */
21986 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21987 window_text_bottom_y (w
) - cursor_row
->y
);
21989 /* If row is completely invisible, don't attempt to delete a cursor which
21990 isn't there. This can happen if cursor is at top of a window, and
21991 we switch to a buffer with a header line in that window. */
21992 if (cursor_row
->visible_height
<= 0)
21993 goto mark_cursor_off
;
21995 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21996 if (cursor_row
->cursor_in_fringe_p
)
21998 cursor_row
->cursor_in_fringe_p
= 0;
21999 draw_fringe_bitmap (w
, cursor_row
, 0);
22000 goto mark_cursor_off
;
22003 /* This can happen when the new row is shorter than the old one.
22004 In this case, either draw_glyphs or clear_end_of_line
22005 should have cleared the cursor. Note that we wouldn't be
22006 able to erase the cursor in this case because we don't have a
22007 cursor glyph at hand. */
22008 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22009 goto mark_cursor_off
;
22011 /* If the cursor is in the mouse face area, redisplay that when
22012 we clear the cursor. */
22013 if (! NILP (dpyinfo
->mouse_face_window
)
22014 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22015 && (vpos
> dpyinfo
->mouse_face_beg_row
22016 || (vpos
== dpyinfo
->mouse_face_beg_row
22017 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22018 && (vpos
< dpyinfo
->mouse_face_end_row
22019 || (vpos
== dpyinfo
->mouse_face_end_row
22020 && hpos
< dpyinfo
->mouse_face_end_col
))
22021 /* Don't redraw the cursor's spot in mouse face if it is at the
22022 end of a line (on a newline). The cursor appears there, but
22023 mouse highlighting does not. */
22024 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22025 mouse_face_here_p
= 1;
22027 /* Maybe clear the display under the cursor. */
22028 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22031 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22034 cursor_glyph
= get_phys_cursor_glyph (w
);
22035 if (cursor_glyph
== NULL
)
22036 goto mark_cursor_off
;
22038 width
= cursor_glyph
->pixel_width
;
22039 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22040 x
= w
->phys_cursor
.x
;
22042 width
-= left_x
- x
;
22043 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22044 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22045 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22048 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22051 /* Erase the cursor by redrawing the character underneath it. */
22052 if (mouse_face_here_p
)
22053 hl
= DRAW_MOUSE_FACE
;
22055 hl
= DRAW_NORMAL_TEXT
;
22056 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22059 w
->phys_cursor_on_p
= 0;
22060 w
->phys_cursor_type
= NO_CURSOR
;
22065 Display or clear cursor of window W. If ON is zero, clear the
22066 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22067 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22070 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22072 int on
, hpos
, vpos
, x
, y
;
22074 struct frame
*f
= XFRAME (w
->frame
);
22075 int new_cursor_type
;
22076 int new_cursor_width
;
22078 struct glyph_row
*glyph_row
;
22079 struct glyph
*glyph
;
22081 /* This is pointless on invisible frames, and dangerous on garbaged
22082 windows and frames; in the latter case, the frame or window may
22083 be in the midst of changing its size, and x and y may be off the
22085 if (! FRAME_VISIBLE_P (f
)
22086 || FRAME_GARBAGED_P (f
)
22087 || vpos
>= w
->current_matrix
->nrows
22088 || hpos
>= w
->current_matrix
->matrix_w
)
22091 /* If cursor is off and we want it off, return quickly. */
22092 if (!on
&& !w
->phys_cursor_on_p
)
22095 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22096 /* If cursor row is not enabled, we don't really know where to
22097 display the cursor. */
22098 if (!glyph_row
->enabled_p
)
22100 w
->phys_cursor_on_p
= 0;
22105 if (!glyph_row
->exact_window_width_line_p
22106 || hpos
< glyph_row
->used
[TEXT_AREA
])
22107 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22109 xassert (interrupt_input_blocked
);
22111 /* Set new_cursor_type to the cursor we want to be displayed. */
22112 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22113 &new_cursor_width
, &active_cursor
);
22115 /* If cursor is currently being shown and we don't want it to be or
22116 it is in the wrong place, or the cursor type is not what we want,
22118 if (w
->phys_cursor_on_p
22120 || w
->phys_cursor
.x
!= x
22121 || w
->phys_cursor
.y
!= y
22122 || new_cursor_type
!= w
->phys_cursor_type
22123 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22124 && new_cursor_width
!= w
->phys_cursor_width
)))
22125 erase_phys_cursor (w
);
22127 /* Don't check phys_cursor_on_p here because that flag is only set
22128 to zero in some cases where we know that the cursor has been
22129 completely erased, to avoid the extra work of erasing the cursor
22130 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22131 still not be visible, or it has only been partly erased. */
22134 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22135 w
->phys_cursor_height
= glyph_row
->height
;
22137 /* Set phys_cursor_.* before x_draw_.* is called because some
22138 of them may need the information. */
22139 w
->phys_cursor
.x
= x
;
22140 w
->phys_cursor
.y
= glyph_row
->y
;
22141 w
->phys_cursor
.hpos
= hpos
;
22142 w
->phys_cursor
.vpos
= vpos
;
22145 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22146 new_cursor_type
, new_cursor_width
,
22147 on
, active_cursor
);
22151 /* Switch the display of W's cursor on or off, according to the value
22155 update_window_cursor (w
, on
)
22159 /* Don't update cursor in windows whose frame is in the process
22160 of being deleted. */
22161 if (w
->current_matrix
)
22164 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22165 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22171 /* Call update_window_cursor with parameter ON_P on all leaf windows
22172 in the window tree rooted at W. */
22175 update_cursor_in_window_tree (w
, on_p
)
22181 if (!NILP (w
->hchild
))
22182 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22183 else if (!NILP (w
->vchild
))
22184 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22186 update_window_cursor (w
, on_p
);
22188 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22194 Display the cursor on window W, or clear it, according to ON_P.
22195 Don't change the cursor's position. */
22198 x_update_cursor (f
, on_p
)
22202 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22207 Clear the cursor of window W to background color, and mark the
22208 cursor as not shown. This is used when the text where the cursor
22209 is is about to be rewritten. */
22215 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22216 update_window_cursor (w
, 0);
22221 Display the active region described by mouse_face_* according to DRAW. */
22224 show_mouse_face (dpyinfo
, draw
)
22225 Display_Info
*dpyinfo
;
22226 enum draw_glyphs_face draw
;
22228 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22229 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22231 if (/* If window is in the process of being destroyed, don't bother
22233 w
->current_matrix
!= NULL
22234 /* Don't update mouse highlight if hidden */
22235 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22236 /* Recognize when we are called to operate on rows that don't exist
22237 anymore. This can happen when a window is split. */
22238 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22240 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22241 struct glyph_row
*row
, *first
, *last
;
22243 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22244 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22246 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22248 int start_hpos
, end_hpos
, start_x
;
22250 /* For all but the first row, the highlight starts at column 0. */
22253 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22254 start_x
= dpyinfo
->mouse_face_beg_x
;
22263 end_hpos
= dpyinfo
->mouse_face_end_col
;
22266 end_hpos
= row
->used
[TEXT_AREA
];
22267 if (draw
== DRAW_NORMAL_TEXT
)
22268 row
->fill_line_p
= 1; /* Clear to end of line */
22271 if (end_hpos
> start_hpos
)
22273 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22274 start_hpos
, end_hpos
,
22278 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22282 /* When we've written over the cursor, arrange for it to
22283 be displayed again. */
22284 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22287 display_and_set_cursor (w
, 1,
22288 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22289 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22294 /* Change the mouse cursor. */
22295 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22296 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22297 else if (draw
== DRAW_MOUSE_FACE
)
22298 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22300 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22304 Clear out the mouse-highlighted active region.
22305 Redraw it un-highlighted first. Value is non-zero if mouse
22306 face was actually drawn unhighlighted. */
22309 clear_mouse_face (dpyinfo
)
22310 Display_Info
*dpyinfo
;
22314 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22316 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22320 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22321 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22322 dpyinfo
->mouse_face_window
= Qnil
;
22323 dpyinfo
->mouse_face_overlay
= Qnil
;
22329 Non-zero if physical cursor of window W is within mouse face. */
22332 cursor_in_mouse_face_p (w
)
22335 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22336 int in_mouse_face
= 0;
22338 if (WINDOWP (dpyinfo
->mouse_face_window
)
22339 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22341 int hpos
= w
->phys_cursor
.hpos
;
22342 int vpos
= w
->phys_cursor
.vpos
;
22344 if (vpos
>= dpyinfo
->mouse_face_beg_row
22345 && vpos
<= dpyinfo
->mouse_face_end_row
22346 && (vpos
> dpyinfo
->mouse_face_beg_row
22347 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22348 && (vpos
< dpyinfo
->mouse_face_end_row
22349 || hpos
< dpyinfo
->mouse_face_end_col
22350 || dpyinfo
->mouse_face_past_end
))
22354 return in_mouse_face
;
22360 /* Find the glyph matrix position of buffer position CHARPOS in window
22361 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
22362 current glyphs must be up to date. If CHARPOS is above window
22363 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22364 of last line in W. In the row containing CHARPOS, stop before glyphs
22365 having STOP as object. */
22367 #if 1 /* This is a version of fast_find_position that's more correct
22368 in the presence of hscrolling, for example. I didn't install
22369 it right away because the problem fixed is minor, it failed
22370 in 20.x as well, and I think it's too risky to install
22371 so near the release of 21.1. 2001-09-25 gerd. */
22373 #ifndef HAVE_CARBON
22377 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22380 int *hpos
, *vpos
, *x
, *y
;
22383 struct glyph_row
*row
, *first
;
22384 struct glyph
*glyph
, *end
;
22387 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22388 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22393 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22397 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22400 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22404 /* If whole rows or last part of a row came from a display overlay,
22405 row_containing_pos will skip over such rows because their end pos
22406 equals the start pos of the overlay or interval.
22408 Move back if we have a STOP object and previous row's
22409 end glyph came from STOP. */
22412 struct glyph_row
*prev
;
22413 while ((prev
= row
- 1, prev
>= first
)
22414 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22415 && prev
->used
[TEXT_AREA
] > 0)
22417 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22418 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22419 while (--glyph
>= beg
22420 && INTEGERP (glyph
->object
));
22422 || !EQ (stop
, glyph
->object
))
22430 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22432 glyph
= row
->glyphs
[TEXT_AREA
];
22433 end
= glyph
+ row
->used
[TEXT_AREA
];
22435 /* Skip over glyphs not having an object at the start of the row.
22436 These are special glyphs like truncation marks on terminal
22438 if (row
->displays_text_p
)
22440 && INTEGERP (glyph
->object
)
22441 && !EQ (stop
, glyph
->object
)
22442 && glyph
->charpos
< 0)
22444 *x
+= glyph
->pixel_width
;
22449 && !INTEGERP (glyph
->object
)
22450 && !EQ (stop
, glyph
->object
)
22451 && (!BUFFERP (glyph
->object
)
22452 || glyph
->charpos
< charpos
))
22454 *x
+= glyph
->pixel_width
;
22458 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22465 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22468 int *hpos
, *vpos
, *x
, *y
;
22473 int maybe_next_line_p
= 0;
22474 int line_start_position
;
22475 int yb
= window_text_bottom_y (w
);
22476 struct glyph_row
*row
, *best_row
;
22477 int row_vpos
, best_row_vpos
;
22480 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22481 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22483 while (row
->y
< yb
)
22485 if (row
->used
[TEXT_AREA
])
22486 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22488 line_start_position
= 0;
22490 if (line_start_position
> pos
)
22492 /* If the position sought is the end of the buffer,
22493 don't include the blank lines at the bottom of the window. */
22494 else if (line_start_position
== pos
22495 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22497 maybe_next_line_p
= 1;
22500 else if (line_start_position
> 0)
22503 best_row_vpos
= row_vpos
;
22506 if (row
->y
+ row
->height
>= yb
)
22513 /* Find the right column within BEST_ROW. */
22515 current_x
= best_row
->x
;
22516 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22518 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22519 int charpos
= glyph
->charpos
;
22521 if (BUFFERP (glyph
->object
))
22523 if (charpos
== pos
)
22526 *vpos
= best_row_vpos
;
22531 else if (charpos
> pos
)
22534 else if (EQ (glyph
->object
, stop
))
22539 current_x
+= glyph
->pixel_width
;
22542 /* If we're looking for the end of the buffer,
22543 and we didn't find it in the line we scanned,
22544 use the start of the following line. */
22545 if (maybe_next_line_p
)
22550 current_x
= best_row
->x
;
22553 *vpos
= best_row_vpos
;
22554 *hpos
= lastcol
+ 1;
22563 /* Find the position of the glyph for position POS in OBJECT in
22564 window W's current matrix, and return in *X, *Y the pixel
22565 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22567 RIGHT_P non-zero means return the position of the right edge of the
22568 glyph, RIGHT_P zero means return the left edge position.
22570 If no glyph for POS exists in the matrix, return the position of
22571 the glyph with the next smaller position that is in the matrix, if
22572 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22573 exists in the matrix, return the position of the glyph with the
22574 next larger position in OBJECT.
22576 Value is non-zero if a glyph was found. */
22579 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22582 Lisp_Object object
;
22583 int *hpos
, *vpos
, *x
, *y
;
22586 int yb
= window_text_bottom_y (w
);
22587 struct glyph_row
*r
;
22588 struct glyph
*best_glyph
= NULL
;
22589 struct glyph_row
*best_row
= NULL
;
22592 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22593 r
->enabled_p
&& r
->y
< yb
;
22596 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22597 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22600 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22601 if (EQ (g
->object
, object
))
22603 if (g
->charpos
== pos
)
22610 else if (best_glyph
== NULL
22611 || ((eabs (g
->charpos
- pos
)
22612 < eabs (best_glyph
->charpos
- pos
))
22615 : g
->charpos
> pos
)))
22629 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22633 *x
+= best_glyph
->pixel_width
;
22638 *vpos
= best_row
- w
->current_matrix
->rows
;
22641 return best_glyph
!= NULL
;
22645 /* See if position X, Y is within a hot-spot of an image. */
22648 on_hot_spot_p (hot_spot
, x
, y
)
22649 Lisp_Object hot_spot
;
22652 if (!CONSP (hot_spot
))
22655 if (EQ (XCAR (hot_spot
), Qrect
))
22657 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22658 Lisp_Object rect
= XCDR (hot_spot
);
22662 if (!CONSP (XCAR (rect
)))
22664 if (!CONSP (XCDR (rect
)))
22666 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22668 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22670 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22672 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22676 else if (EQ (XCAR (hot_spot
), Qcircle
))
22678 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22679 Lisp_Object circ
= XCDR (hot_spot
);
22680 Lisp_Object lr
, lx0
, ly0
;
22682 && CONSP (XCAR (circ
))
22683 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22684 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22685 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22687 double r
= XFLOATINT (lr
);
22688 double dx
= XINT (lx0
) - x
;
22689 double dy
= XINT (ly0
) - y
;
22690 return (dx
* dx
+ dy
* dy
<= r
* r
);
22693 else if (EQ (XCAR (hot_spot
), Qpoly
))
22695 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22696 if (VECTORP (XCDR (hot_spot
)))
22698 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22699 Lisp_Object
*poly
= v
->contents
;
22703 Lisp_Object lx
, ly
;
22706 /* Need an even number of coordinates, and at least 3 edges. */
22707 if (n
< 6 || n
& 1)
22710 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22711 If count is odd, we are inside polygon. Pixels on edges
22712 may or may not be included depending on actual geometry of the
22714 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22715 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22717 x0
= XINT (lx
), y0
= XINT (ly
);
22718 for (i
= 0; i
< n
; i
+= 2)
22720 int x1
= x0
, y1
= y0
;
22721 if ((lx
= poly
[i
], !INTEGERP (lx
))
22722 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22724 x0
= XINT (lx
), y0
= XINT (ly
);
22726 /* Does this segment cross the X line? */
22734 if (y
> y0
&& y
> y1
)
22736 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22746 find_hot_spot (map
, x
, y
)
22750 while (CONSP (map
))
22752 if (CONSP (XCAR (map
))
22753 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22761 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22763 doc
: /* Lookup in image map MAP coordinates X and Y.
22764 An image map is an alist where each element has the format (AREA ID PLIST).
22765 An AREA is specified as either a rectangle, a circle, or a polygon:
22766 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22767 pixel coordinates of the upper left and bottom right corners.
22768 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22769 and the radius of the circle; r may be a float or integer.
22770 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22771 vector describes one corner in the polygon.
22772 Returns the alist element for the first matching AREA in MAP. */)
22783 return find_hot_spot (map
, XINT (x
), XINT (y
));
22787 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22789 define_frame_cursor1 (f
, cursor
, pointer
)
22792 Lisp_Object pointer
;
22794 /* Do not change cursor shape while dragging mouse. */
22795 if (!NILP (do_mouse_tracking
))
22798 if (!NILP (pointer
))
22800 if (EQ (pointer
, Qarrow
))
22801 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22802 else if (EQ (pointer
, Qhand
))
22803 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22804 else if (EQ (pointer
, Qtext
))
22805 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22806 else if (EQ (pointer
, intern ("hdrag")))
22807 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22808 #ifdef HAVE_X_WINDOWS
22809 else if (EQ (pointer
, intern ("vdrag")))
22810 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22812 else if (EQ (pointer
, intern ("hourglass")))
22813 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22814 else if (EQ (pointer
, Qmodeline
))
22815 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22817 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22820 if (cursor
!= No_Cursor
)
22821 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
22824 /* Take proper action when mouse has moved to the mode or header line
22825 or marginal area AREA of window W, x-position X and y-position Y.
22826 X is relative to the start of the text display area of W, so the
22827 width of bitmap areas and scroll bars must be subtracted to get a
22828 position relative to the start of the mode line. */
22831 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22832 Lisp_Object window
;
22834 enum window_part area
;
22836 struct window
*w
= XWINDOW (window
);
22837 struct frame
*f
= XFRAME (w
->frame
);
22838 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22839 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22840 Lisp_Object pointer
= Qnil
;
22841 int charpos
, dx
, dy
, width
, height
;
22842 Lisp_Object string
, object
= Qnil
;
22843 Lisp_Object pos
, help
;
22845 Lisp_Object mouse_face
;
22846 int original_x_pixel
= x
;
22847 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
22848 struct glyph_row
*row
;
22850 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22855 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22856 &object
, &dx
, &dy
, &width
, &height
);
22858 row
= (area
== ON_MODE_LINE
22859 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22860 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22863 if (row
->mode_line_p
&& row
->enabled_p
)
22865 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
22866 end
= glyph
+ row
->used
[TEXT_AREA
];
22868 for (x0
= original_x_pixel
;
22869 glyph
< end
&& x0
>= glyph
->pixel_width
;
22871 x0
-= glyph
->pixel_width
;
22879 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22880 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22881 &object
, &dx
, &dy
, &width
, &height
);
22886 if (IMAGEP (object
))
22888 Lisp_Object image_map
, hotspot
;
22889 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22891 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22893 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22895 Lisp_Object area_id
, plist
;
22897 area_id
= XCAR (hotspot
);
22898 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22899 If so, we could look for mouse-enter, mouse-leave
22900 properties in PLIST (and do something...). */
22901 hotspot
= XCDR (hotspot
);
22902 if (CONSP (hotspot
)
22903 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22905 pointer
= Fplist_get (plist
, Qpointer
);
22906 if (NILP (pointer
))
22908 help
= Fplist_get (plist
, Qhelp_echo
);
22911 help_echo_string
= help
;
22912 /* Is this correct? ++kfs */
22913 XSETWINDOW (help_echo_window
, w
);
22914 help_echo_object
= w
->buffer
;
22915 help_echo_pos
= charpos
;
22919 if (NILP (pointer
))
22920 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22923 if (STRINGP (string
))
22925 pos
= make_number (charpos
);
22926 /* If we're on a string with `help-echo' text property, arrange
22927 for the help to be displayed. This is done by setting the
22928 global variable help_echo_string to the help string. */
22931 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22934 help_echo_string
= help
;
22935 XSETWINDOW (help_echo_window
, w
);
22936 help_echo_object
= string
;
22937 help_echo_pos
= charpos
;
22941 if (NILP (pointer
))
22942 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22944 /* Change the mouse pointer according to what is under X/Y. */
22945 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22948 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22949 if (!KEYMAPP (map
))
22950 map
= Fget_text_property (pos
, Qkeymap
, string
);
22951 if (!KEYMAPP (map
))
22952 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22955 /* Change the mouse face according to what is under X/Y. */
22956 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22957 if (!NILP (mouse_face
)
22958 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22963 struct glyph
* tmp_glyph
;
22967 int total_pixel_width
;
22972 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22973 Qmouse_face
, string
, Qnil
);
22975 b
= make_number (0);
22977 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22979 e
= make_number (SCHARS (string
));
22981 /* Calculate the position(glyph position: GPOS) of GLYPH in
22982 displayed string. GPOS is different from CHARPOS.
22984 CHARPOS is the position of glyph in internal string
22985 object. A mode line string format has structures which
22986 is converted to a flatten by emacs lisp interpreter.
22987 The internal string is an element of the structures.
22988 The displayed string is the flatten string. */
22990 if (glyph
> row_start_glyph
)
22992 tmp_glyph
= glyph
- 1;
22993 while (tmp_glyph
>= row_start_glyph
22994 && tmp_glyph
->charpos
>= XINT (b
)
22995 && EQ (tmp_glyph
->object
, glyph
->object
))
23002 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23003 displayed string holding GLYPH.
23005 GSEQ_LENGTH is different from SCHARS (STRING).
23006 SCHARS (STRING) returns the length of the internal string. */
23007 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23008 tmp_glyph
->charpos
< XINT (e
);
23009 tmp_glyph
++, gseq_length
++)
23011 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23015 total_pixel_width
= 0;
23016 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23017 total_pixel_width
+= tmp_glyph
->pixel_width
;
23019 /* Pre calculation of re-rendering position */
23021 hpos
= (area
== ON_MODE_LINE
23022 ? (w
->current_matrix
)->nrows
- 1
23025 /* If the re-rendering position is included in the last
23026 re-rendering area, we should do nothing. */
23027 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23028 && dpyinfo
->mouse_face_beg_col
<= vpos
23029 && vpos
< dpyinfo
->mouse_face_end_col
23030 && dpyinfo
->mouse_face_beg_row
== hpos
)
23033 if (clear_mouse_face (dpyinfo
))
23034 cursor
= No_Cursor
;
23036 dpyinfo
->mouse_face_beg_col
= vpos
;
23037 dpyinfo
->mouse_face_beg_row
= hpos
;
23039 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23040 dpyinfo
->mouse_face_beg_y
= 0;
23042 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23043 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23045 dpyinfo
->mouse_face_end_x
= 0;
23046 dpyinfo
->mouse_face_end_y
= 0;
23048 dpyinfo
->mouse_face_past_end
= 0;
23049 dpyinfo
->mouse_face_window
= window
;
23051 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23054 glyph
->face_id
, 1);
23055 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23057 if (NILP (pointer
))
23060 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23061 clear_mouse_face (dpyinfo
);
23063 define_frame_cursor1 (f
, cursor
, pointer
);
23068 Take proper action when the mouse has moved to position X, Y on
23069 frame F as regards highlighting characters that have mouse-face
23070 properties. Also de-highlighting chars where the mouse was before.
23071 X and Y can be negative or out of range. */
23074 note_mouse_highlight (f
, x
, y
)
23078 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23079 enum window_part part
;
23080 Lisp_Object window
;
23082 Cursor cursor
= No_Cursor
;
23083 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23086 /* When a menu is active, don't highlight because this looks odd. */
23087 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
23088 if (popup_activated ())
23092 if (NILP (Vmouse_highlight
)
23093 || !f
->glyphs_initialized_p
)
23096 dpyinfo
->mouse_face_mouse_x
= x
;
23097 dpyinfo
->mouse_face_mouse_y
= y
;
23098 dpyinfo
->mouse_face_mouse_frame
= f
;
23100 if (dpyinfo
->mouse_face_defer
)
23103 if (gc_in_progress
)
23105 dpyinfo
->mouse_face_deferred_gc
= 1;
23109 /* Which window is that in? */
23110 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23112 /* If we were displaying active text in another window, clear that.
23113 Also clear if we move out of text area in same window. */
23114 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23115 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23116 && !NILP (dpyinfo
->mouse_face_window
)))
23117 clear_mouse_face (dpyinfo
);
23119 /* Not on a window -> return. */
23120 if (!WINDOWP (window
))
23123 /* Reset help_echo_string. It will get recomputed below. */
23124 help_echo_string
= Qnil
;
23126 /* Convert to window-relative pixel coordinates. */
23127 w
= XWINDOW (window
);
23128 frame_to_window_pixel_xy (w
, &x
, &y
);
23130 /* Handle tool-bar window differently since it doesn't display a
23132 if (EQ (window
, f
->tool_bar_window
))
23134 note_tool_bar_highlight (f
, x
, y
);
23138 /* Mouse is on the mode, header line or margin? */
23139 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23140 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23142 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23146 if (part
== ON_VERTICAL_BORDER
)
23148 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23149 help_echo_string
= build_string ("drag-mouse-1: resize");
23151 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23152 || part
== ON_SCROLL_BAR
)
23153 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23155 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23157 /* Are we in a window whose display is up to date?
23158 And verify the buffer's text has not changed. */
23159 b
= XBUFFER (w
->buffer
);
23160 if (part
== ON_TEXT
23161 && EQ (w
->window_end_valid
, w
->buffer
)
23162 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23163 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23165 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23166 struct glyph
*glyph
;
23167 Lisp_Object object
;
23168 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23169 Lisp_Object
*overlay_vec
= NULL
;
23171 struct buffer
*obuf
;
23172 int obegv
, ozv
, same_region
;
23174 /* Find the glyph under X/Y. */
23175 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23177 /* Look for :pointer property on image. */
23178 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23180 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23181 if (img
!= NULL
&& IMAGEP (img
->spec
))
23183 Lisp_Object image_map
, hotspot
;
23184 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23186 && (hotspot
= find_hot_spot (image_map
,
23187 glyph
->slice
.x
+ dx
,
23188 glyph
->slice
.y
+ dy
),
23190 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23192 Lisp_Object area_id
, plist
;
23194 area_id
= XCAR (hotspot
);
23195 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23196 If so, we could look for mouse-enter, mouse-leave
23197 properties in PLIST (and do something...). */
23198 hotspot
= XCDR (hotspot
);
23199 if (CONSP (hotspot
)
23200 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23202 pointer
= Fplist_get (plist
, Qpointer
);
23203 if (NILP (pointer
))
23205 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23206 if (!NILP (help_echo_string
))
23208 help_echo_window
= window
;
23209 help_echo_object
= glyph
->object
;
23210 help_echo_pos
= glyph
->charpos
;
23214 if (NILP (pointer
))
23215 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23219 /* Clear mouse face if X/Y not over text. */
23221 || area
!= TEXT_AREA
23222 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23224 if (clear_mouse_face (dpyinfo
))
23225 cursor
= No_Cursor
;
23226 if (NILP (pointer
))
23228 if (area
!= TEXT_AREA
)
23229 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23231 pointer
= Vvoid_text_area_pointer
;
23236 pos
= glyph
->charpos
;
23237 object
= glyph
->object
;
23238 if (!STRINGP (object
) && !BUFFERP (object
))
23241 /* If we get an out-of-range value, return now; avoid an error. */
23242 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23245 /* Make the window's buffer temporarily current for
23246 overlays_at and compute_char_face. */
23247 obuf
= current_buffer
;
23248 current_buffer
= b
;
23254 /* Is this char mouse-active or does it have help-echo? */
23255 position
= make_number (pos
);
23257 if (BUFFERP (object
))
23259 /* Put all the overlays we want in a vector in overlay_vec. */
23260 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23261 /* Sort overlays into increasing priority order. */
23262 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23267 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23268 && vpos
>= dpyinfo
->mouse_face_beg_row
23269 && vpos
<= dpyinfo
->mouse_face_end_row
23270 && (vpos
> dpyinfo
->mouse_face_beg_row
23271 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23272 && (vpos
< dpyinfo
->mouse_face_end_row
23273 || hpos
< dpyinfo
->mouse_face_end_col
23274 || dpyinfo
->mouse_face_past_end
));
23277 cursor
= No_Cursor
;
23279 /* Check mouse-face highlighting. */
23281 /* If there exists an overlay with mouse-face overlapping
23282 the one we are currently highlighting, we have to
23283 check if we enter the overlapping overlay, and then
23284 highlight only that. */
23285 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23286 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23288 /* Find the highest priority overlay that has a mouse-face
23291 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23293 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23294 if (!NILP (mouse_face
))
23295 overlay
= overlay_vec
[i
];
23298 /* If we're actually highlighting the same overlay as
23299 before, there's no need to do that again. */
23300 if (!NILP (overlay
)
23301 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23302 goto check_help_echo
;
23304 dpyinfo
->mouse_face_overlay
= overlay
;
23306 /* Clear the display of the old active region, if any. */
23307 if (clear_mouse_face (dpyinfo
))
23308 cursor
= No_Cursor
;
23310 /* If no overlay applies, get a text property. */
23311 if (NILP (overlay
))
23312 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23314 /* Handle the overlay case. */
23315 if (!NILP (overlay
))
23317 /* Find the range of text around this char that
23318 should be active. */
23319 Lisp_Object before
, after
;
23322 before
= Foverlay_start (overlay
);
23323 after
= Foverlay_end (overlay
);
23324 /* Record this as the current active region. */
23325 fast_find_position (w
, XFASTINT (before
),
23326 &dpyinfo
->mouse_face_beg_col
,
23327 &dpyinfo
->mouse_face_beg_row
,
23328 &dpyinfo
->mouse_face_beg_x
,
23329 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23331 dpyinfo
->mouse_face_past_end
23332 = !fast_find_position (w
, XFASTINT (after
),
23333 &dpyinfo
->mouse_face_end_col
,
23334 &dpyinfo
->mouse_face_end_row
,
23335 &dpyinfo
->mouse_face_end_x
,
23336 &dpyinfo
->mouse_face_end_y
, Qnil
);
23337 dpyinfo
->mouse_face_window
= window
;
23339 dpyinfo
->mouse_face_face_id
23340 = face_at_buffer_position (w
, pos
, 0, 0,
23342 !dpyinfo
->mouse_face_hidden
);
23344 /* Display it as active. */
23345 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23346 cursor
= No_Cursor
;
23348 /* Handle the text property case. */
23349 else if (!NILP (mouse_face
) && BUFFERP (object
))
23351 /* Find the range of text around this char that
23352 should be active. */
23353 Lisp_Object before
, after
, beginning
, end
;
23356 beginning
= Fmarker_position (w
->start
);
23357 end
= make_number (BUF_Z (XBUFFER (object
))
23358 - XFASTINT (w
->window_end_pos
));
23360 = Fprevious_single_property_change (make_number (pos
+ 1),
23362 object
, beginning
);
23364 = Fnext_single_property_change (position
, Qmouse_face
,
23367 /* Record this as the current active region. */
23368 fast_find_position (w
, XFASTINT (before
),
23369 &dpyinfo
->mouse_face_beg_col
,
23370 &dpyinfo
->mouse_face_beg_row
,
23371 &dpyinfo
->mouse_face_beg_x
,
23372 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23373 dpyinfo
->mouse_face_past_end
23374 = !fast_find_position (w
, XFASTINT (after
),
23375 &dpyinfo
->mouse_face_end_col
,
23376 &dpyinfo
->mouse_face_end_row
,
23377 &dpyinfo
->mouse_face_end_x
,
23378 &dpyinfo
->mouse_face_end_y
, Qnil
);
23379 dpyinfo
->mouse_face_window
= window
;
23381 if (BUFFERP (object
))
23382 dpyinfo
->mouse_face_face_id
23383 = face_at_buffer_position (w
, pos
, 0, 0,
23385 !dpyinfo
->mouse_face_hidden
);
23387 /* Display it as active. */
23388 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23389 cursor
= No_Cursor
;
23391 else if (!NILP (mouse_face
) && STRINGP (object
))
23396 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23399 e
= Fnext_single_property_change (position
, Qmouse_face
,
23402 b
= make_number (0);
23404 e
= make_number (SCHARS (object
) - 1);
23406 fast_find_string_pos (w
, XINT (b
), object
,
23407 &dpyinfo
->mouse_face_beg_col
,
23408 &dpyinfo
->mouse_face_beg_row
,
23409 &dpyinfo
->mouse_face_beg_x
,
23410 &dpyinfo
->mouse_face_beg_y
, 0);
23411 fast_find_string_pos (w
, XINT (e
), object
,
23412 &dpyinfo
->mouse_face_end_col
,
23413 &dpyinfo
->mouse_face_end_row
,
23414 &dpyinfo
->mouse_face_end_x
,
23415 &dpyinfo
->mouse_face_end_y
, 1);
23416 dpyinfo
->mouse_face_past_end
= 0;
23417 dpyinfo
->mouse_face_window
= window
;
23418 dpyinfo
->mouse_face_face_id
23419 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23420 glyph
->face_id
, 1);
23421 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23422 cursor
= No_Cursor
;
23424 else if (STRINGP (object
) && NILP (mouse_face
))
23426 /* A string which doesn't have mouse-face, but
23427 the text ``under'' it might have. */
23428 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23429 int start
= MATRIX_ROW_START_CHARPOS (r
);
23431 pos
= string_buffer_position (w
, object
, start
);
23433 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23437 if (!NILP (mouse_face
) && !NILP (overlay
))
23439 Lisp_Object before
= Foverlay_start (overlay
);
23440 Lisp_Object after
= Foverlay_end (overlay
);
23443 /* Note that we might not be able to find position
23444 BEFORE in the glyph matrix if the overlay is
23445 entirely covered by a `display' property. In
23446 this case, we overshoot. So let's stop in
23447 the glyph matrix before glyphs for OBJECT. */
23448 fast_find_position (w
, XFASTINT (before
),
23449 &dpyinfo
->mouse_face_beg_col
,
23450 &dpyinfo
->mouse_face_beg_row
,
23451 &dpyinfo
->mouse_face_beg_x
,
23452 &dpyinfo
->mouse_face_beg_y
,
23455 dpyinfo
->mouse_face_past_end
23456 = !fast_find_position (w
, XFASTINT (after
),
23457 &dpyinfo
->mouse_face_end_col
,
23458 &dpyinfo
->mouse_face_end_row
,
23459 &dpyinfo
->mouse_face_end_x
,
23460 &dpyinfo
->mouse_face_end_y
,
23462 dpyinfo
->mouse_face_window
= window
;
23463 dpyinfo
->mouse_face_face_id
23464 = face_at_buffer_position (w
, pos
, 0, 0,
23466 !dpyinfo
->mouse_face_hidden
);
23468 /* Display it as active. */
23469 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23470 cursor
= No_Cursor
;
23477 /* Look for a `help-echo' property. */
23478 if (NILP (help_echo_string
)) {
23479 Lisp_Object help
, overlay
;
23481 /* Check overlays first. */
23482 help
= overlay
= Qnil
;
23483 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23485 overlay
= overlay_vec
[i
];
23486 help
= Foverlay_get (overlay
, Qhelp_echo
);
23491 help_echo_string
= help
;
23492 help_echo_window
= window
;
23493 help_echo_object
= overlay
;
23494 help_echo_pos
= pos
;
23498 Lisp_Object object
= glyph
->object
;
23499 int charpos
= glyph
->charpos
;
23501 /* Try text properties. */
23502 if (STRINGP (object
)
23504 && charpos
< SCHARS (object
))
23506 help
= Fget_text_property (make_number (charpos
),
23507 Qhelp_echo
, object
);
23510 /* If the string itself doesn't specify a help-echo,
23511 see if the buffer text ``under'' it does. */
23512 struct glyph_row
*r
23513 = MATRIX_ROW (w
->current_matrix
, vpos
);
23514 int start
= MATRIX_ROW_START_CHARPOS (r
);
23515 int pos
= string_buffer_position (w
, object
, start
);
23518 help
= Fget_char_property (make_number (pos
),
23519 Qhelp_echo
, w
->buffer
);
23523 object
= w
->buffer
;
23528 else if (BUFFERP (object
)
23531 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23536 help_echo_string
= help
;
23537 help_echo_window
= window
;
23538 help_echo_object
= object
;
23539 help_echo_pos
= charpos
;
23544 /* Look for a `pointer' property. */
23545 if (NILP (pointer
))
23547 /* Check overlays first. */
23548 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23549 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23551 if (NILP (pointer
))
23553 Lisp_Object object
= glyph
->object
;
23554 int charpos
= glyph
->charpos
;
23556 /* Try text properties. */
23557 if (STRINGP (object
)
23559 && charpos
< SCHARS (object
))
23561 pointer
= Fget_text_property (make_number (charpos
),
23563 if (NILP (pointer
))
23565 /* If the string itself doesn't specify a pointer,
23566 see if the buffer text ``under'' it does. */
23567 struct glyph_row
*r
23568 = MATRIX_ROW (w
->current_matrix
, vpos
);
23569 int start
= MATRIX_ROW_START_CHARPOS (r
);
23570 int pos
= string_buffer_position (w
, object
, start
);
23572 pointer
= Fget_char_property (make_number (pos
),
23573 Qpointer
, w
->buffer
);
23576 else if (BUFFERP (object
)
23579 pointer
= Fget_text_property (make_number (charpos
),
23586 current_buffer
= obuf
;
23591 define_frame_cursor1 (f
, cursor
, pointer
);
23596 Clear any mouse-face on window W. This function is part of the
23597 redisplay interface, and is called from try_window_id and similar
23598 functions to ensure the mouse-highlight is off. */
23601 x_clear_window_mouse_face (w
)
23604 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23605 Lisp_Object window
;
23608 XSETWINDOW (window
, w
);
23609 if (EQ (window
, dpyinfo
->mouse_face_window
))
23610 clear_mouse_face (dpyinfo
);
23616 Just discard the mouse face information for frame F, if any.
23617 This is used when the size of F is changed. */
23620 cancel_mouse_face (f
)
23623 Lisp_Object window
;
23624 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23626 window
= dpyinfo
->mouse_face_window
;
23627 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23629 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23630 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23631 dpyinfo
->mouse_face_window
= Qnil
;
23636 #endif /* HAVE_WINDOW_SYSTEM */
23639 /***********************************************************************
23641 ***********************************************************************/
23643 #ifdef HAVE_WINDOW_SYSTEM
23645 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23646 which intersects rectangle R. R is in window-relative coordinates. */
23649 expose_area (w
, row
, r
, area
)
23651 struct glyph_row
*row
;
23653 enum glyph_row_area area
;
23655 struct glyph
*first
= row
->glyphs
[area
];
23656 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23657 struct glyph
*last
;
23658 int first_x
, start_x
, x
;
23660 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23661 /* If row extends face to end of line write the whole line. */
23662 draw_glyphs (w
, 0, row
, area
,
23663 0, row
->used
[area
],
23664 DRAW_NORMAL_TEXT
, 0);
23667 /* Set START_X to the window-relative start position for drawing glyphs of
23668 AREA. The first glyph of the text area can be partially visible.
23669 The first glyphs of other areas cannot. */
23670 start_x
= window_box_left_offset (w
, area
);
23672 if (area
== TEXT_AREA
)
23675 /* Find the first glyph that must be redrawn. */
23677 && x
+ first
->pixel_width
< r
->x
)
23679 x
+= first
->pixel_width
;
23683 /* Find the last one. */
23687 && x
< r
->x
+ r
->width
)
23689 x
+= last
->pixel_width
;
23695 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23696 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23697 DRAW_NORMAL_TEXT
, 0);
23702 /* Redraw the parts of the glyph row ROW on window W intersecting
23703 rectangle R. R is in window-relative coordinates. Value is
23704 non-zero if mouse-face was overwritten. */
23707 expose_line (w
, row
, r
)
23709 struct glyph_row
*row
;
23712 xassert (row
->enabled_p
);
23714 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23715 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23716 0, row
->used
[TEXT_AREA
],
23717 DRAW_NORMAL_TEXT
, 0);
23720 if (row
->used
[LEFT_MARGIN_AREA
])
23721 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23722 if (row
->used
[TEXT_AREA
])
23723 expose_area (w
, row
, r
, TEXT_AREA
);
23724 if (row
->used
[RIGHT_MARGIN_AREA
])
23725 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23726 draw_row_fringe_bitmaps (w
, row
);
23729 return row
->mouse_face_p
;
23733 /* Redraw those parts of glyphs rows during expose event handling that
23734 overlap other rows. Redrawing of an exposed line writes over parts
23735 of lines overlapping that exposed line; this function fixes that.
23737 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23738 row in W's current matrix that is exposed and overlaps other rows.
23739 LAST_OVERLAPPING_ROW is the last such row. */
23742 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
23744 struct glyph_row
*first_overlapping_row
;
23745 struct glyph_row
*last_overlapping_row
;
23748 struct glyph_row
*row
;
23750 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23751 if (row
->overlapping_p
)
23753 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23756 if (row
->used
[LEFT_MARGIN_AREA
])
23757 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23759 if (row
->used
[TEXT_AREA
])
23760 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23762 if (row
->used
[RIGHT_MARGIN_AREA
])
23763 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23769 /* Return non-zero if W's cursor intersects rectangle R. */
23772 phys_cursor_in_rect_p (w
, r
)
23776 XRectangle cr
, result
;
23777 struct glyph
*cursor_glyph
;
23778 struct glyph_row
*row
;
23780 if (w
->phys_cursor
.vpos
>= 0
23781 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
23782 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
23784 && row
->cursor_in_fringe_p
)
23786 /* Cursor is in the fringe. */
23787 cr
.x
= window_box_right_offset (w
,
23788 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
23789 ? RIGHT_MARGIN_AREA
23792 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
23793 cr
.height
= row
->height
;
23794 return x_intersect_rectangles (&cr
, r
, &result
);
23797 cursor_glyph
= get_phys_cursor_glyph (w
);
23800 /* r is relative to W's box, but w->phys_cursor.x is relative
23801 to left edge of W's TEXT area. Adjust it. */
23802 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23803 cr
.y
= w
->phys_cursor
.y
;
23804 cr
.width
= cursor_glyph
->pixel_width
;
23805 cr
.height
= w
->phys_cursor_height
;
23806 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23807 I assume the effect is the same -- and this is portable. */
23808 return x_intersect_rectangles (&cr
, r
, &result
);
23810 /* If we don't understand the format, pretend we're not in the hot-spot. */
23816 Draw a vertical window border to the right of window W if W doesn't
23817 have vertical scroll bars. */
23820 x_draw_vertical_border (w
)
23823 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23825 /* We could do better, if we knew what type of scroll-bar the adjacent
23826 windows (on either side) have... But we don't :-(
23827 However, I think this works ok. ++KFS 2003-04-25 */
23829 /* Redraw borders between horizontally adjacent windows. Don't
23830 do it for frames with vertical scroll bars because either the
23831 right scroll bar of a window, or the left scroll bar of its
23832 neighbor will suffice as a border. */
23833 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23836 if (!WINDOW_RIGHTMOST_P (w
)
23837 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23839 int x0
, x1
, y0
, y1
;
23841 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23844 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23847 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
23849 else if (!WINDOW_LEFTMOST_P (w
)
23850 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23852 int x0
, x1
, y0
, y1
;
23854 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23857 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23860 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
23865 /* Redraw the part of window W intersection rectangle FR. Pixel
23866 coordinates in FR are frame-relative. Call this function with
23867 input blocked. Value is non-zero if the exposure overwrites
23871 expose_window (w
, fr
)
23875 struct frame
*f
= XFRAME (w
->frame
);
23877 int mouse_face_overwritten_p
= 0;
23879 /* If window is not yet fully initialized, do nothing. This can
23880 happen when toolkit scroll bars are used and a window is split.
23881 Reconfiguring the scroll bar will generate an expose for a newly
23883 if (w
->current_matrix
== NULL
)
23886 /* When we're currently updating the window, display and current
23887 matrix usually don't agree. Arrange for a thorough display
23889 if (w
== updated_window
)
23891 SET_FRAME_GARBAGED (f
);
23895 /* Frame-relative pixel rectangle of W. */
23896 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23897 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23898 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23899 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23901 if (x_intersect_rectangles (fr
, &wr
, &r
))
23903 int yb
= window_text_bottom_y (w
);
23904 struct glyph_row
*row
;
23905 int cursor_cleared_p
;
23906 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23908 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23909 r
.x
, r
.y
, r
.width
, r
.height
));
23911 /* Convert to window coordinates. */
23912 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23913 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23915 /* Turn off the cursor. */
23916 if (!w
->pseudo_window_p
23917 && phys_cursor_in_rect_p (w
, &r
))
23919 x_clear_cursor (w
);
23920 cursor_cleared_p
= 1;
23923 cursor_cleared_p
= 0;
23925 /* Update lines intersecting rectangle R. */
23926 first_overlapping_row
= last_overlapping_row
= NULL
;
23927 for (row
= w
->current_matrix
->rows
;
23932 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23934 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23935 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23936 || (r
.y
>= y0
&& r
.y
< y1
)
23937 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23939 /* A header line may be overlapping, but there is no need
23940 to fix overlapping areas for them. KFS 2005-02-12 */
23941 if (row
->overlapping_p
&& !row
->mode_line_p
)
23943 if (first_overlapping_row
== NULL
)
23944 first_overlapping_row
= row
;
23945 last_overlapping_row
= row
;
23949 if (expose_line (w
, row
, &r
))
23950 mouse_face_overwritten_p
= 1;
23953 else if (row
->overlapping_p
)
23955 /* We must redraw a row overlapping the exposed area. */
23957 ? y0
+ row
->phys_height
> r
.y
23958 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
23960 if (first_overlapping_row
== NULL
)
23961 first_overlapping_row
= row
;
23962 last_overlapping_row
= row
;
23970 /* Display the mode line if there is one. */
23971 if (WINDOW_WANTS_MODELINE_P (w
)
23972 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23974 && row
->y
< r
.y
+ r
.height
)
23976 if (expose_line (w
, row
, &r
))
23977 mouse_face_overwritten_p
= 1;
23980 if (!w
->pseudo_window_p
)
23982 /* Fix the display of overlapping rows. */
23983 if (first_overlapping_row
)
23984 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
23987 /* Draw border between windows. */
23988 x_draw_vertical_border (w
);
23990 /* Turn the cursor on again. */
23991 if (cursor_cleared_p
)
23992 update_window_cursor (w
, 1);
23996 return mouse_face_overwritten_p
;
24001 /* Redraw (parts) of all windows in the window tree rooted at W that
24002 intersect R. R contains frame pixel coordinates. Value is
24003 non-zero if the exposure overwrites mouse-face. */
24006 expose_window_tree (w
, r
)
24010 struct frame
*f
= XFRAME (w
->frame
);
24011 int mouse_face_overwritten_p
= 0;
24013 while (w
&& !FRAME_GARBAGED_P (f
))
24015 if (!NILP (w
->hchild
))
24016 mouse_face_overwritten_p
24017 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24018 else if (!NILP (w
->vchild
))
24019 mouse_face_overwritten_p
24020 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24022 mouse_face_overwritten_p
|= expose_window (w
, r
);
24024 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24027 return mouse_face_overwritten_p
;
24032 Redisplay an exposed area of frame F. X and Y are the upper-left
24033 corner of the exposed rectangle. W and H are width and height of
24034 the exposed area. All are pixel values. W or H zero means redraw
24035 the entire frame. */
24038 expose_frame (f
, x
, y
, w
, h
)
24043 int mouse_face_overwritten_p
= 0;
24045 TRACE ((stderr
, "expose_frame "));
24047 /* No need to redraw if frame will be redrawn soon. */
24048 if (FRAME_GARBAGED_P (f
))
24050 TRACE ((stderr
, " garbaged\n"));
24054 /* If basic faces haven't been realized yet, there is no point in
24055 trying to redraw anything. This can happen when we get an expose
24056 event while Emacs is starting, e.g. by moving another window. */
24057 if (FRAME_FACE_CACHE (f
) == NULL
24058 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24060 TRACE ((stderr
, " no faces\n"));
24064 if (w
== 0 || h
== 0)
24067 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24068 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24078 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24079 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24081 if (WINDOWP (f
->tool_bar_window
))
24082 mouse_face_overwritten_p
24083 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24085 #ifdef HAVE_X_WINDOWS
24087 #ifndef USE_X_TOOLKIT
24088 if (WINDOWP (f
->menu_bar_window
))
24089 mouse_face_overwritten_p
24090 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24091 #endif /* not USE_X_TOOLKIT */
24095 /* Some window managers support a focus-follows-mouse style with
24096 delayed raising of frames. Imagine a partially obscured frame,
24097 and moving the mouse into partially obscured mouse-face on that
24098 frame. The visible part of the mouse-face will be highlighted,
24099 then the WM raises the obscured frame. With at least one WM, KDE
24100 2.1, Emacs is not getting any event for the raising of the frame
24101 (even tried with SubstructureRedirectMask), only Expose events.
24102 These expose events will draw text normally, i.e. not
24103 highlighted. Which means we must redo the highlight here.
24104 Subsume it under ``we love X''. --gerd 2001-08-15 */
24105 /* Included in Windows version because Windows most likely does not
24106 do the right thing if any third party tool offers
24107 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24108 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24110 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24111 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24113 int x
= dpyinfo
->mouse_face_mouse_x
;
24114 int y
= dpyinfo
->mouse_face_mouse_y
;
24115 clear_mouse_face (dpyinfo
);
24116 note_mouse_highlight (f
, x
, y
);
24123 Determine the intersection of two rectangles R1 and R2. Return
24124 the intersection in *RESULT. Value is non-zero if RESULT is not
24128 x_intersect_rectangles (r1
, r2
, result
)
24129 XRectangle
*r1
, *r2
, *result
;
24131 XRectangle
*left
, *right
;
24132 XRectangle
*upper
, *lower
;
24133 int intersection_p
= 0;
24135 /* Rearrange so that R1 is the left-most rectangle. */
24137 left
= r1
, right
= r2
;
24139 left
= r2
, right
= r1
;
24141 /* X0 of the intersection is right.x0, if this is inside R1,
24142 otherwise there is no intersection. */
24143 if (right
->x
<= left
->x
+ left
->width
)
24145 result
->x
= right
->x
;
24147 /* The right end of the intersection is the minimum of the
24148 the right ends of left and right. */
24149 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24152 /* Same game for Y. */
24154 upper
= r1
, lower
= r2
;
24156 upper
= r2
, lower
= r1
;
24158 /* The upper end of the intersection is lower.y0, if this is inside
24159 of upper. Otherwise, there is no intersection. */
24160 if (lower
->y
<= upper
->y
+ upper
->height
)
24162 result
->y
= lower
->y
;
24164 /* The lower end of the intersection is the minimum of the lower
24165 ends of upper and lower. */
24166 result
->height
= (min (lower
->y
+ lower
->height
,
24167 upper
->y
+ upper
->height
)
24169 intersection_p
= 1;
24173 return intersection_p
;
24176 #endif /* HAVE_WINDOW_SYSTEM */
24179 /***********************************************************************
24181 ***********************************************************************/
24186 Vwith_echo_area_save_vector
= Qnil
;
24187 staticpro (&Vwith_echo_area_save_vector
);
24189 Vmessage_stack
= Qnil
;
24190 staticpro (&Vmessage_stack
);
24192 Qinhibit_redisplay
= intern ("inhibit-redisplay");
24193 staticpro (&Qinhibit_redisplay
);
24195 message_dolog_marker1
= Fmake_marker ();
24196 staticpro (&message_dolog_marker1
);
24197 message_dolog_marker2
= Fmake_marker ();
24198 staticpro (&message_dolog_marker2
);
24199 message_dolog_marker3
= Fmake_marker ();
24200 staticpro (&message_dolog_marker3
);
24203 defsubr (&Sdump_frame_glyph_matrix
);
24204 defsubr (&Sdump_glyph_matrix
);
24205 defsubr (&Sdump_glyph_row
);
24206 defsubr (&Sdump_tool_bar_row
);
24207 defsubr (&Strace_redisplay
);
24208 defsubr (&Strace_to_stderr
);
24210 #ifdef HAVE_WINDOW_SYSTEM
24211 defsubr (&Stool_bar_lines_needed
);
24212 defsubr (&Slookup_image_map
);
24214 defsubr (&Sformat_mode_line
);
24215 defsubr (&Sinvisible_p
);
24217 staticpro (&Qmenu_bar_update_hook
);
24218 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
24220 staticpro (&Qoverriding_terminal_local_map
);
24221 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
24223 staticpro (&Qoverriding_local_map
);
24224 Qoverriding_local_map
= intern ("overriding-local-map");
24226 staticpro (&Qwindow_scroll_functions
);
24227 Qwindow_scroll_functions
= intern ("window-scroll-functions");
24229 staticpro (&Qwindow_text_change_functions
);
24230 Qwindow_text_change_functions
= intern ("window-text-change-functions");
24232 staticpro (&Qredisplay_end_trigger_functions
);
24233 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
24235 staticpro (&Qinhibit_point_motion_hooks
);
24236 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
24238 Qeval
= intern ("eval");
24239 staticpro (&Qeval
);
24241 QCdata
= intern (":data");
24242 staticpro (&QCdata
);
24243 Qdisplay
= intern ("display");
24244 staticpro (&Qdisplay
);
24245 Qspace_width
= intern ("space-width");
24246 staticpro (&Qspace_width
);
24247 Qraise
= intern ("raise");
24248 staticpro (&Qraise
);
24249 Qslice
= intern ("slice");
24250 staticpro (&Qslice
);
24251 Qspace
= intern ("space");
24252 staticpro (&Qspace
);
24253 Qmargin
= intern ("margin");
24254 staticpro (&Qmargin
);
24255 Qpointer
= intern ("pointer");
24256 staticpro (&Qpointer
);
24257 Qleft_margin
= intern ("left-margin");
24258 staticpro (&Qleft_margin
);
24259 Qright_margin
= intern ("right-margin");
24260 staticpro (&Qright_margin
);
24261 Qcenter
= intern ("center");
24262 staticpro (&Qcenter
);
24263 Qline_height
= intern ("line-height");
24264 staticpro (&Qline_height
);
24265 QCalign_to
= intern (":align-to");
24266 staticpro (&QCalign_to
);
24267 QCrelative_width
= intern (":relative-width");
24268 staticpro (&QCrelative_width
);
24269 QCrelative_height
= intern (":relative-height");
24270 staticpro (&QCrelative_height
);
24271 QCeval
= intern (":eval");
24272 staticpro (&QCeval
);
24273 QCpropertize
= intern (":propertize");
24274 staticpro (&QCpropertize
);
24275 QCfile
= intern (":file");
24276 staticpro (&QCfile
);
24277 Qfontified
= intern ("fontified");
24278 staticpro (&Qfontified
);
24279 Qfontification_functions
= intern ("fontification-functions");
24280 staticpro (&Qfontification_functions
);
24281 Qtrailing_whitespace
= intern ("trailing-whitespace");
24282 staticpro (&Qtrailing_whitespace
);
24283 Qescape_glyph
= intern ("escape-glyph");
24284 staticpro (&Qescape_glyph
);
24285 Qnobreak_space
= intern ("nobreak-space");
24286 staticpro (&Qnobreak_space
);
24287 Qimage
= intern ("image");
24288 staticpro (&Qimage
);
24289 QCmap
= intern (":map");
24290 staticpro (&QCmap
);
24291 QCpointer
= intern (":pointer");
24292 staticpro (&QCpointer
);
24293 Qrect
= intern ("rect");
24294 staticpro (&Qrect
);
24295 Qcircle
= intern ("circle");
24296 staticpro (&Qcircle
);
24297 Qpoly
= intern ("poly");
24298 staticpro (&Qpoly
);
24299 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24300 staticpro (&Qmessage_truncate_lines
);
24301 Qgrow_only
= intern ("grow-only");
24302 staticpro (&Qgrow_only
);
24303 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24304 staticpro (&Qinhibit_menubar_update
);
24305 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24306 staticpro (&Qinhibit_eval_during_redisplay
);
24307 Qposition
= intern ("position");
24308 staticpro (&Qposition
);
24309 Qbuffer_position
= intern ("buffer-position");
24310 staticpro (&Qbuffer_position
);
24311 Qobject
= intern ("object");
24312 staticpro (&Qobject
);
24313 Qbar
= intern ("bar");
24315 Qhbar
= intern ("hbar");
24316 staticpro (&Qhbar
);
24317 Qbox
= intern ("box");
24319 Qhollow
= intern ("hollow");
24320 staticpro (&Qhollow
);
24321 Qhand
= intern ("hand");
24322 staticpro (&Qhand
);
24323 Qarrow
= intern ("arrow");
24324 staticpro (&Qarrow
);
24325 Qtext
= intern ("text");
24326 staticpro (&Qtext
);
24327 Qrisky_local_variable
= intern ("risky-local-variable");
24328 staticpro (&Qrisky_local_variable
);
24329 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24330 staticpro (&Qinhibit_free_realized_faces
);
24332 list_of_error
= Fcons (Fcons (intern ("error"),
24333 Fcons (intern ("void-variable"), Qnil
)),
24335 staticpro (&list_of_error
);
24337 Qlast_arrow_position
= intern ("last-arrow-position");
24338 staticpro (&Qlast_arrow_position
);
24339 Qlast_arrow_string
= intern ("last-arrow-string");
24340 staticpro (&Qlast_arrow_string
);
24342 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24343 staticpro (&Qoverlay_arrow_string
);
24344 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24345 staticpro (&Qoverlay_arrow_bitmap
);
24347 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24348 staticpro (&echo_buffer
[0]);
24349 staticpro (&echo_buffer
[1]);
24351 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24352 staticpro (&echo_area_buffer
[0]);
24353 staticpro (&echo_area_buffer
[1]);
24355 Vmessages_buffer_name
= build_string ("*Messages*");
24356 staticpro (&Vmessages_buffer_name
);
24358 mode_line_proptrans_alist
= Qnil
;
24359 staticpro (&mode_line_proptrans_alist
);
24360 mode_line_string_list
= Qnil
;
24361 staticpro (&mode_line_string_list
);
24362 mode_line_string_face
= Qnil
;
24363 staticpro (&mode_line_string_face
);
24364 mode_line_string_face_prop
= Qnil
;
24365 staticpro (&mode_line_string_face_prop
);
24366 Vmode_line_unwind_vector
= Qnil
;
24367 staticpro (&Vmode_line_unwind_vector
);
24369 help_echo_string
= Qnil
;
24370 staticpro (&help_echo_string
);
24371 help_echo_object
= Qnil
;
24372 staticpro (&help_echo_object
);
24373 help_echo_window
= Qnil
;
24374 staticpro (&help_echo_window
);
24375 previous_help_echo_string
= Qnil
;
24376 staticpro (&previous_help_echo_string
);
24377 help_echo_pos
= -1;
24379 #ifdef HAVE_WINDOW_SYSTEM
24380 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24381 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24382 For example, if a block cursor is over a tab, it will be drawn as
24383 wide as that tab on the display. */);
24384 x_stretch_cursor_p
= 0;
24387 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24388 doc
: /* *Non-nil means highlight trailing whitespace.
24389 The face used for trailing whitespace is `trailing-whitespace'. */);
24390 Vshow_trailing_whitespace
= Qnil
;
24392 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24393 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24394 A value of t means highlight the character itself (for nobreak space,
24395 use face `nobreak-space').
24396 A value of nil means no highlighting.
24397 Other values mean display the escape glyph followed by an ordinary
24398 space or ordinary hyphen. */);
24399 Vnobreak_char_display
= Qt
;
24401 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24402 doc
: /* *The pointer shape to show in void text areas.
24403 A value of nil means to show the text pointer. Other options are `arrow',
24404 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24405 Vvoid_text_area_pointer
= Qarrow
;
24407 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24408 doc
: /* Non-nil means don't actually do any redisplay.
24409 This is used for internal purposes. */);
24410 Vinhibit_redisplay
= Qnil
;
24412 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24413 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24414 Vglobal_mode_string
= Qnil
;
24416 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24417 doc
: /* Marker for where to display an arrow on top of the buffer text.
24418 This must be the beginning of a line in order to work.
24419 See also `overlay-arrow-string'. */);
24420 Voverlay_arrow_position
= Qnil
;
24422 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24423 doc
: /* String to display as an arrow in non-window frames.
24424 See also `overlay-arrow-position'. */);
24425 Voverlay_arrow_string
= build_string ("=>");
24427 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24428 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24429 The symbols on this list are examined during redisplay to determine
24430 where to display overlay arrows. */);
24431 Voverlay_arrow_variable_list
24432 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24434 DEFVAR_INT ("scroll-step", &scroll_step
,
24435 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24436 If that fails to bring point back on frame, point is centered instead.
24437 If this is zero, point is always centered after it moves off frame.
24438 If you want scrolling to always be a line at a time, you should set
24439 `scroll-conservatively' to a large value rather than set this to 1. */);
24441 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24442 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24443 If point moves off-screen, redisplay will scroll by up to
24444 `scroll-conservatively' lines in order to bring point just barely
24445 onto the screen again. If that cannot be done, then redisplay
24446 recenters point as usual.
24448 A value of zero means always recenter point if it moves off screen. */);
24449 scroll_conservatively
= 0;
24451 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24452 doc
: /* *Number of lines of margin at the top and bottom of a window.
24453 Recenter the window whenever point gets within this many lines
24454 of the top or bottom of the window. */);
24457 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24458 doc
: /* Pixels per inch value for non-window system displays.
24459 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24460 Vdisplay_pixels_per_inch
= make_float (72.0);
24463 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24466 DEFVAR_BOOL ("truncate-partial-width-windows",
24467 &truncate_partial_width_windows
,
24468 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide.
24469 Nil means to respect the value of `truncate-lines'. */);
24470 truncate_partial_width_windows
= 1;
24472 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24473 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24474 Any other value means to use the appropriate face, `mode-line',
24475 `header-line', or `menu' respectively. */);
24476 mode_line_inverse_video
= 1;
24478 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24479 doc
: /* *Maximum buffer size for which line number should be displayed.
24480 If the buffer is bigger than this, the line number does not appear
24481 in the mode line. A value of nil means no limit. */);
24482 Vline_number_display_limit
= Qnil
;
24484 DEFVAR_INT ("line-number-display-limit-width",
24485 &line_number_display_limit_width
,
24486 doc
: /* *Maximum line width (in characters) for line number display.
24487 If the average length of the lines near point is bigger than this, then the
24488 line number may be omitted from the mode line. */);
24489 line_number_display_limit_width
= 200;
24491 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24492 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24493 highlight_nonselected_windows
= 0;
24495 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24496 doc
: /* Non-nil if more than one frame is visible on this display.
24497 Minibuffer-only frames don't count, but iconified frames do.
24498 This variable is not guaranteed to be accurate except while processing
24499 `frame-title-format' and `icon-title-format'. */);
24501 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24502 doc
: /* Template for displaying the title bar of visible frames.
24503 \(Assuming the window manager supports this feature.)
24505 This variable has the same structure as `mode-line-format', except that
24506 the %c and %l constructs are ignored. It is used only on frames for
24507 which no explicit name has been set \(see `modify-frame-parameters'). */);
24509 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24510 doc
: /* Template for displaying the title bar of an iconified frame.
24511 \(Assuming the window manager supports this feature.)
24512 This variable has the same structure as `mode-line-format' (which see),
24513 and is used only on frames for which no explicit name has been set
24514 \(see `modify-frame-parameters'). */);
24516 = Vframe_title_format
24517 = Fcons (intern ("multiple-frames"),
24518 Fcons (build_string ("%b"),
24519 Fcons (Fcons (empty_unibyte_string
,
24520 Fcons (intern ("invocation-name"),
24521 Fcons (build_string ("@"),
24522 Fcons (intern ("system-name"),
24526 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24527 doc
: /* Maximum number of lines to keep in the message log buffer.
24528 If nil, disable message logging. If t, log messages but don't truncate
24529 the buffer when it becomes large. */);
24530 Vmessage_log_max
= make_number (100);
24532 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24533 doc
: /* Functions called before redisplay, if window sizes have changed.
24534 The value should be a list of functions that take one argument.
24535 Just before redisplay, for each frame, if any of its windows have changed
24536 size since the last redisplay, or have been split or deleted,
24537 all the functions in the list are called, with the frame as argument. */);
24538 Vwindow_size_change_functions
= Qnil
;
24540 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24541 doc
: /* List of functions to call before redisplaying a window with scrolling.
24542 Each function is called with two arguments, the window
24543 and its new display-start position. Note that the value of `window-end'
24544 is not valid when these functions are called. */);
24545 Vwindow_scroll_functions
= Qnil
;
24547 DEFVAR_LISP ("window-text-change-functions",
24548 &Vwindow_text_change_functions
,
24549 doc
: /* Functions to call in redisplay when text in the window might change. */);
24550 Vwindow_text_change_functions
= Qnil
;
24552 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24553 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24554 Each function is called with two arguments, the window and the end trigger value.
24555 See `set-window-redisplay-end-trigger'. */);
24556 Vredisplay_end_trigger_functions
= Qnil
;
24558 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24559 doc
: /* *Non-nil means autoselect window with mouse pointer.
24560 If nil, do not autoselect windows.
24561 A positive number means delay autoselection by that many seconds: a
24562 window is autoselected only after the mouse has remained in that
24563 window for the duration of the delay.
24564 A negative number has a similar effect, but causes windows to be
24565 autoselected only after the mouse has stopped moving. \(Because of
24566 the way Emacs compares mouse events, you will occasionally wait twice
24567 that time before the window gets selected.\)
24568 Any other value means to autoselect window instantaneously when the
24569 mouse pointer enters it.
24571 Autoselection selects the minibuffer only if it is active, and never
24572 unselects the minibuffer if it is active.
24574 When customizing this variable make sure that the actual value of
24575 `focus-follows-mouse' matches the behavior of your window manager. */);
24576 Vmouse_autoselect_window
= Qnil
;
24578 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24579 doc
: /* *Non-nil means automatically resize tool-bars.
24580 This dynamically changes the tool-bar's height to the minimum height
24581 that is needed to make all tool-bar items visible.
24582 If value is `grow-only', the tool-bar's height is only increased
24583 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24584 Vauto_resize_tool_bars
= Qt
;
24586 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24587 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24588 auto_raise_tool_bar_buttons_p
= 1;
24590 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24591 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24592 make_cursor_line_fully_visible_p
= 1;
24594 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24595 doc
: /* *Border below tool-bar in pixels.
24596 If an integer, use it as the height of the border.
24597 If it is one of `internal-border-width' or `border-width', use the
24598 value of the corresponding frame parameter.
24599 Otherwise, no border is added below the tool-bar. */);
24600 Vtool_bar_border
= Qinternal_border_width
;
24602 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24603 doc
: /* *Margin around tool-bar buttons in pixels.
24604 If an integer, use that for both horizontal and vertical margins.
24605 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24606 HORZ specifying the horizontal margin, and VERT specifying the
24607 vertical margin. */);
24608 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24610 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24611 doc
: /* *Relief thickness of tool-bar buttons. */);
24612 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24614 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24615 doc
: /* List of functions to call to fontify regions of text.
24616 Each function is called with one argument POS. Functions must
24617 fontify a region starting at POS in the current buffer, and give
24618 fontified regions the property `fontified'. */);
24619 Vfontification_functions
= Qnil
;
24620 Fmake_variable_buffer_local (Qfontification_functions
);
24622 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24623 &unibyte_display_via_language_environment
,
24624 doc
: /* *Non-nil means display unibyte text according to language environment.
24625 Specifically this means that unibyte non-ASCII characters
24626 are displayed by converting them to the equivalent multibyte characters
24627 according to the current language environment. As a result, they are
24628 displayed according to the current fontset. */);
24629 unibyte_display_via_language_environment
= 0;
24631 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24632 doc
: /* *Maximum height for resizing mini-windows.
24633 If a float, it specifies a fraction of the mini-window frame's height.
24634 If an integer, it specifies a number of lines. */);
24635 Vmax_mini_window_height
= make_float (0.25);
24637 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24638 doc
: /* *How to resize mini-windows.
24639 A value of nil means don't automatically resize mini-windows.
24640 A value of t means resize them to fit the text displayed in them.
24641 A value of `grow-only', the default, means let mini-windows grow
24642 only, until their display becomes empty, at which point the windows
24643 go back to their normal size. */);
24644 Vresize_mini_windows
= Qgrow_only
;
24646 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24647 doc
: /* Alist specifying how to blink the cursor off.
24648 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24649 `cursor-type' frame-parameter or variable equals ON-STATE,
24650 comparing using `equal', Emacs uses OFF-STATE to specify
24651 how to blink it off. ON-STATE and OFF-STATE are values for
24652 the `cursor-type' frame parameter.
24654 If a frame's ON-STATE has no entry in this list,
24655 the frame's other specifications determine how to blink the cursor off. */);
24656 Vblink_cursor_alist
= Qnil
;
24658 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24659 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24660 automatic_hscrolling_p
= 1;
24661 Qauto_hscroll_mode
= intern ("auto-hscroll-mode");
24662 staticpro (&Qauto_hscroll_mode
);
24664 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24665 doc
: /* *How many columns away from the window edge point is allowed to get
24666 before automatic hscrolling will horizontally scroll the window. */);
24667 hscroll_margin
= 5;
24669 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24670 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24671 When point is less than `hscroll-margin' columns from the window
24672 edge, automatic hscrolling will scroll the window by the amount of columns
24673 determined by this variable. If its value is a positive integer, scroll that
24674 many columns. If it's a positive floating-point number, it specifies the
24675 fraction of the window's width to scroll. If it's nil or zero, point will be
24676 centered horizontally after the scroll. Any other value, including negative
24677 numbers, are treated as if the value were zero.
24679 Automatic hscrolling always moves point outside the scroll margin, so if
24680 point was more than scroll step columns inside the margin, the window will
24681 scroll more than the value given by the scroll step.
24683 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24684 and `scroll-right' overrides this variable's effect. */);
24685 Vhscroll_step
= make_number (0);
24687 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24688 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24689 Bind this around calls to `message' to let it take effect. */);
24690 message_truncate_lines
= 0;
24692 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24693 doc
: /* Normal hook run to update the menu bar definitions.
24694 Redisplay runs this hook before it redisplays the menu bar.
24695 This is used to update submenus such as Buffers,
24696 whose contents depend on various data. */);
24697 Vmenu_bar_update_hook
= Qnil
;
24699 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24700 doc
: /* Frame for which we are updating a menu.
24701 The enable predicate for a menu binding should check this variable. */);
24702 Vmenu_updating_frame
= Qnil
;
24704 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24705 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24706 inhibit_menubar_update
= 0;
24708 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24709 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24710 inhibit_eval_during_redisplay
= 0;
24712 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24713 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24714 inhibit_free_realized_faces
= 0;
24717 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24718 doc
: /* Inhibit try_window_id display optimization. */);
24719 inhibit_try_window_id
= 0;
24721 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24722 doc
: /* Inhibit try_window_reusing display optimization. */);
24723 inhibit_try_window_reusing
= 0;
24725 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24726 doc
: /* Inhibit try_cursor_movement display optimization. */);
24727 inhibit_try_cursor_movement
= 0;
24728 #endif /* GLYPH_DEBUG */
24730 DEFVAR_INT ("overline-margin", &overline_margin
,
24731 doc
: /* *Space between overline and text, in pixels.
24732 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24733 margin to the caracter height. */);
24734 overline_margin
= 2;
24738 /* Initialize this module when Emacs starts. */
24743 Lisp_Object root_window
;
24744 struct window
*mini_w
;
24746 current_header_line_height
= current_mode_line_height
= -1;
24748 CHARPOS (this_line_start_pos
) = 0;
24750 mini_w
= XWINDOW (minibuf_window
);
24751 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24753 if (!noninteractive
)
24755 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24758 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24759 set_window_height (root_window
,
24760 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24762 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24763 set_window_height (minibuf_window
, 1, 0);
24765 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24766 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24768 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24769 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24770 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24772 /* The default ellipsis glyphs `...'. */
24773 for (i
= 0; i
< 3; ++i
)
24774 default_invis_vector
[i
] = make_number ('.');
24778 /* Allocate the buffer for frame titles.
24779 Also used for `format-mode-line'. */
24781 mode_line_noprop_buf
= (char *) xmalloc (size
);
24782 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24783 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24784 mode_line_target
= MODE_LINE_DISPLAY
;
24787 help_echo_showing_p
= 0;
24791 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24792 (do not change this comment) */