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 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, or (at your option)
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; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
27 Emacs separates the task of updating the display from code
28 modifying global state, e.g. buffer text. This way functions
29 operating on buffers don't also have to be concerned with updating
32 Updating the display is triggered by the Lisp interpreter when it
33 decides it's time to do it. This is done either automatically for
34 you as part of the interpreter's command loop or as the result of
35 calling Lisp functions like `sit-for'. The C function `redisplay'
36 in xdisp.c is the only entry into the inner redisplay code. (Or,
37 let's say almost---see the description of direct update
40 The following diagram shows how redisplay code is invoked. As you
41 can see, Lisp calls redisplay and vice versa. Under window systems
42 like X, some portions of the redisplay code are also called
43 asynchronously during mouse movement or expose events. It is very
44 important that these code parts do NOT use the C library (malloc,
45 free) because many C libraries under Unix are not reentrant. They
46 may also NOT call functions of the Lisp interpreter which could
47 change the interpreter's state. If you don't follow these rules,
48 you will encounter bugs which are very hard to explain.
50 (Direct functions, see below)
51 direct_output_for_insert,
52 direct_forward_char (dispnew.c)
53 +---------------------------------+
56 +--------------+ redisplay +----------------+
57 | Lisp machine |---------------->| Redisplay code |<--+
58 +--------------+ (xdisp.c) +----------------+ |
60 +----------------------------------+ |
61 Don't use this path when called |
64 expose_window (asynchronous) |
66 X expose events -----+
68 What does redisplay do? Obviously, it has to figure out somehow what
69 has been changed since the last time the display has been updated,
70 and to make these changes visible. Preferably it would do that in
71 a moderately intelligent way, i.e. fast.
73 Changes in buffer text can be deduced from window and buffer
74 structures, and from some global variables like `beg_unchanged' and
75 `end_unchanged'. The contents of the display are additionally
76 recorded in a `glyph matrix', a two-dimensional matrix of glyph
77 structures. Each row in such a matrix corresponds to a line on the
78 display, and each glyph in a row corresponds to a column displaying
79 a character, an image, or what else. This matrix is called the
80 `current glyph matrix' or `current matrix' in redisplay
83 For buffer parts that have been changed since the last update, a
84 second glyph matrix is constructed, the so called `desired glyph
85 matrix' or short `desired matrix'. Current and desired matrix are
86 then compared to find a cheap way to update the display, e.g. by
87 reusing part of the display by scrolling lines.
92 You will find a lot of redisplay optimizations when you start
93 looking at the innards of redisplay. The overall goal of all these
94 optimizations is to make redisplay fast because it is done
97 Two optimizations are not found in xdisp.c. These are the direct
98 operations mentioned above. As the name suggests they follow a
99 different principle than the rest of redisplay. Instead of
100 building a desired matrix and then comparing it with the current
101 display, they perform their actions directly on the display and on
104 One direct operation updates the display after one character has
105 been entered. The other one moves the cursor by one position
106 forward or backward. You find these functions under the names
107 `direct_output_for_insert' and `direct_output_forward_char' in
113 Desired matrices are always built per Emacs window. The function
114 `display_line' is the central function to look at if you are
115 interested. It constructs one row in a desired matrix given an
116 iterator structure containing both a buffer position and a
117 description of the environment in which the text is to be
118 displayed. But this is too early, read on.
120 Characters and pixmaps displayed for a range of buffer text depend
121 on various settings of buffers and windows, on overlays and text
122 properties, on display tables, on selective display. The good news
123 is that all this hairy stuff is hidden behind a small set of
124 interface functions taking an iterator structure (struct it)
127 Iteration over things to be displayed is then simple. It is
128 started by initializing an iterator with a call to init_iterator.
129 Calls to get_next_display_element fill the iterator structure with
130 relevant information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
180 #include "character.h"
183 #include "commands.h"
187 #include "termhooks.h"
188 #include "intervals.h"
191 #include "region-cache.h"
193 #include "blockinput.h"
195 #ifdef HAVE_X_WINDOWS
205 #ifdef HAVE_WINDOW_SYSTEM
206 #ifdef USE_FONT_BACKEND
208 #endif /* USE_FONT_BACKEND */
209 #endif /* HAVE_WINDOW_SYSTEM */
211 #ifndef FRAME_X_OUTPUT
212 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
215 #define INFINITY 10000000
217 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
219 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
220 extern int pending_menu_activation
;
223 extern int interrupt_input
;
224 extern int command_loop_level
;
226 extern Lisp_Object do_mouse_tracking
;
228 extern int minibuffer_auto_raise
;
229 extern Lisp_Object Vminibuffer_list
;
231 extern Lisp_Object Qface
;
232 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
234 extern Lisp_Object Voverriding_local_map
;
235 extern Lisp_Object Voverriding_local_map_menu_flag
;
236 extern Lisp_Object Qmenu_item
;
237 extern Lisp_Object Qwhen
;
238 extern Lisp_Object Qhelp_echo
;
240 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
241 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
242 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
243 Lisp_Object Qinhibit_point_motion_hooks
;
244 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
245 Lisp_Object Qfontified
;
246 Lisp_Object Qgrow_only
;
247 Lisp_Object Qinhibit_eval_during_redisplay
;
248 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
251 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
254 Lisp_Object Qarrow
, Qhand
, Qtext
;
256 Lisp_Object Qrisky_local_variable
;
258 /* Holds the list (error). */
259 Lisp_Object list_of_error
;
261 /* Functions called to fontify regions of text. */
263 Lisp_Object Vfontification_functions
;
264 Lisp_Object Qfontification_functions
;
266 /* Non-nil means automatically select any window when the mouse
267 cursor moves into it. */
268 Lisp_Object Vmouse_autoselect_window
;
270 /* Non-zero means draw tool bar buttons raised when the mouse moves
273 int auto_raise_tool_bar_buttons_p
;
275 /* Non-zero means to reposition window if cursor line is only partially visible. */
277 int make_cursor_line_fully_visible_p
;
279 /* Margin below tool bar in pixels. 0 or nil means no margin.
280 If value is `internal-border-width' or `border-width',
281 the corresponding frame parameter is used. */
283 Lisp_Object Vtool_bar_border
;
285 /* Margin around tool bar buttons in pixels. */
287 Lisp_Object Vtool_bar_button_margin
;
289 /* Thickness of shadow to draw around tool bar buttons. */
291 EMACS_INT tool_bar_button_relief
;
293 /* Non-nil means automatically resize tool-bars so that all tool-bar
294 items are visible, and no blank lines remain.
296 If value is `grow-only', only make tool-bar bigger. */
298 Lisp_Object Vauto_resize_tool_bars
;
300 /* Non-zero means draw block and hollow cursor as wide as the glyph
301 under it. For example, if a block cursor is over a tab, it will be
302 drawn as wide as that tab on the display. */
304 int x_stretch_cursor_p
;
306 /* Non-nil means don't actually do any redisplay. */
308 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
310 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
312 int inhibit_eval_during_redisplay
;
314 /* Names of text properties relevant for redisplay. */
316 Lisp_Object Qdisplay
;
317 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
319 /* Symbols used in text property values. */
321 Lisp_Object Vdisplay_pixels_per_inch
;
322 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
323 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
326 Lisp_Object Qmargin
, Qpointer
;
327 Lisp_Object Qline_height
;
328 extern Lisp_Object Qheight
;
329 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
330 extern Lisp_Object Qscroll_bar
;
331 extern Lisp_Object Qcursor
;
333 /* Non-nil means highlight trailing whitespace. */
335 Lisp_Object Vshow_trailing_whitespace
;
337 /* Non-nil means escape non-break space and hyphens. */
339 Lisp_Object Vnobreak_char_display
;
341 #ifdef HAVE_WINDOW_SYSTEM
342 extern Lisp_Object Voverflow_newline_into_fringe
;
344 /* Test if overflow newline into fringe. Called with iterator IT
345 at or past right window margin, and with IT->current_x set. */
347 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
348 (!NILP (Voverflow_newline_into_fringe) \
349 && FRAME_WINDOW_P (it->f) \
350 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
351 && it->current_x == it->last_visible_x)
353 #endif /* HAVE_WINDOW_SYSTEM */
355 /* Non-nil means show the text cursor in void text areas
356 i.e. in blank areas after eol and eob. This used to be
357 the default in 21.3. */
359 Lisp_Object Vvoid_text_area_pointer
;
361 /* Name of the face used to highlight trailing whitespace. */
363 Lisp_Object Qtrailing_whitespace
;
365 /* Name and number of the face used to highlight escape glyphs. */
367 Lisp_Object Qescape_glyph
;
369 /* Name and number of the face used to highlight non-breaking spaces. */
371 Lisp_Object Qnobreak_space
;
373 /* The symbol `image' which is the car of the lists used to represent
378 /* The image map types. */
379 Lisp_Object QCmap
, QCpointer
;
380 Lisp_Object Qrect
, Qcircle
, Qpoly
;
382 /* Non-zero means print newline to stdout before next mini-buffer
385 int noninteractive_need_newline
;
387 /* Non-zero means print newline to message log before next message. */
389 static int message_log_need_newline
;
391 /* Three markers that message_dolog uses.
392 It could allocate them itself, but that causes trouble
393 in handling memory-full errors. */
394 static Lisp_Object message_dolog_marker1
;
395 static Lisp_Object message_dolog_marker2
;
396 static Lisp_Object message_dolog_marker3
;
398 /* The buffer position of the first character appearing entirely or
399 partially on the line of the selected window which contains the
400 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
401 redisplay optimization in redisplay_internal. */
403 static struct text_pos this_line_start_pos
;
405 /* Number of characters past the end of the line above, including the
406 terminating newline. */
408 static struct text_pos this_line_end_pos
;
410 /* The vertical positions and the height of this line. */
412 static int this_line_vpos
;
413 static int this_line_y
;
414 static int this_line_pixel_height
;
416 /* X position at which this display line starts. Usually zero;
417 negative if first character is partially visible. */
419 static int this_line_start_x
;
421 /* Buffer that this_line_.* variables are referring to. */
423 static struct buffer
*this_line_buffer
;
425 /* Nonzero means truncate lines in all windows less wide than the
428 int truncate_partial_width_windows
;
430 /* A flag to control how to display unibyte 8-bit character. */
432 int unibyte_display_via_language_environment
;
434 /* Nonzero means we have more than one non-mini-buffer-only frame.
435 Not guaranteed to be accurate except while parsing
436 frame-title-format. */
440 Lisp_Object Vglobal_mode_string
;
443 /* List of variables (symbols) which hold markers for overlay arrows.
444 The symbols on this list are examined during redisplay to determine
445 where to display overlay arrows. */
447 Lisp_Object Voverlay_arrow_variable_list
;
449 /* Marker for where to display an arrow on top of the buffer text. */
451 Lisp_Object Voverlay_arrow_position
;
453 /* String to display for the arrow. Only used on terminal frames. */
455 Lisp_Object Voverlay_arrow_string
;
457 /* Values of those variables at last redisplay are stored as
458 properties on `overlay-arrow-position' symbol. However, if
459 Voverlay_arrow_position is a marker, last-arrow-position is its
460 numerical position. */
462 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
464 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
465 properties on a symbol in overlay-arrow-variable-list. */
467 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
469 /* Like mode-line-format, but for the title bar on a visible frame. */
471 Lisp_Object Vframe_title_format
;
473 /* Like mode-line-format, but for the title bar on an iconified frame. */
475 Lisp_Object Vicon_title_format
;
477 /* List of functions to call when a window's size changes. These
478 functions get one arg, a frame on which one or more windows' sizes
481 static Lisp_Object Vwindow_size_change_functions
;
483 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
485 /* Nonzero if an overlay arrow has been displayed in this window. */
487 static int overlay_arrow_seen
;
489 /* Nonzero means highlight the region even in nonselected windows. */
491 int highlight_nonselected_windows
;
493 /* If cursor motion alone moves point off frame, try scrolling this
494 many lines up or down if that will bring it back. */
496 static EMACS_INT scroll_step
;
498 /* Nonzero means scroll just far enough to bring point back on the
499 screen, when appropriate. */
501 static EMACS_INT scroll_conservatively
;
503 /* Recenter the window whenever point gets within this many lines of
504 the top or bottom of the window. This value is translated into a
505 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
506 that there is really a fixed pixel height scroll margin. */
508 EMACS_INT scroll_margin
;
510 /* Number of windows showing the buffer of the selected window (or
511 another buffer with the same base buffer). keyboard.c refers to
516 /* Vector containing glyphs for an ellipsis `...'. */
518 static Lisp_Object default_invis_vector
[3];
520 /* Zero means display the mode-line/header-line/menu-bar in the default face
521 (this slightly odd definition is for compatibility with previous versions
522 of emacs), non-zero means display them using their respective faces.
524 This variable is deprecated. */
526 int mode_line_inverse_video
;
528 /* Prompt to display in front of the mini-buffer contents. */
530 Lisp_Object minibuf_prompt
;
532 /* Width of current mini-buffer prompt. Only set after display_line
533 of the line that contains the prompt. */
535 int minibuf_prompt_width
;
537 /* This is the window where the echo area message was displayed. It
538 is always a mini-buffer window, but it may not be the same window
539 currently active as a mini-buffer. */
541 Lisp_Object echo_area_window
;
543 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
544 pushes the current message and the value of
545 message_enable_multibyte on the stack, the function restore_message
546 pops the stack and displays MESSAGE again. */
548 Lisp_Object Vmessage_stack
;
550 /* Nonzero means multibyte characters were enabled when the echo area
551 message was specified. */
553 int message_enable_multibyte
;
555 /* Nonzero if we should redraw the mode lines on the next redisplay. */
557 int update_mode_lines
;
559 /* Nonzero if window sizes or contents have changed since last
560 redisplay that finished. */
562 int windows_or_buffers_changed
;
564 /* Nonzero means a frame's cursor type has been changed. */
566 int cursor_type_changed
;
568 /* Nonzero after display_mode_line if %l was used and it displayed a
571 int line_number_displayed
;
573 /* Maximum buffer size for which to display line numbers. */
575 Lisp_Object Vline_number_display_limit
;
577 /* Line width to consider when repositioning for line number display. */
579 static EMACS_INT line_number_display_limit_width
;
581 /* Number of lines to keep in the message log buffer. t means
582 infinite. nil means don't log at all. */
584 Lisp_Object Vmessage_log_max
;
586 /* The name of the *Messages* buffer, a string. */
588 static Lisp_Object Vmessages_buffer_name
;
590 /* Index 0 is the buffer that holds the current (desired) echo area message,
591 or nil if none is desired right now.
593 Index 1 is the buffer that holds the previously displayed echo area message,
594 or nil to indicate no message. This is normally what's on the screen now.
596 These two can point to the same buffer. That happens when the last
597 message output by the user (or made by echoing) has been displayed. */
599 Lisp_Object echo_area_buffer
[2];
601 /* Permanent pointers to the two buffers that are used for echo area
602 purposes. Once the two buffers are made, and their pointers are
603 placed here, these two slots remain unchanged unless those buffers
604 need to be created afresh. */
606 static Lisp_Object echo_buffer
[2];
608 /* A vector saved used in with_area_buffer to reduce consing. */
610 static Lisp_Object Vwith_echo_area_save_vector
;
612 /* Non-zero means display_echo_area should display the last echo area
613 message again. Set by redisplay_preserve_echo_area. */
615 static int display_last_displayed_message_p
;
617 /* Nonzero if echo area is being used by print; zero if being used by
620 int message_buf_print
;
622 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
624 Lisp_Object Qinhibit_menubar_update
;
625 int inhibit_menubar_update
;
627 /* When evaluating expressions from menu bar items (enable conditions,
628 for instance), this is the frame they are being processed for. */
630 Lisp_Object Vmenu_updating_frame
;
632 /* Maximum height for resizing mini-windows. Either a float
633 specifying a fraction of the available height, or an integer
634 specifying a number of lines. */
636 Lisp_Object Vmax_mini_window_height
;
638 /* Non-zero means messages should be displayed with truncated
639 lines instead of being continued. */
641 int message_truncate_lines
;
642 Lisp_Object Qmessage_truncate_lines
;
644 /* Set to 1 in clear_message to make redisplay_internal aware
645 of an emptied echo area. */
647 static int message_cleared_p
;
649 /* How to blink the default frame cursor off. */
650 Lisp_Object Vblink_cursor_alist
;
652 /* A scratch glyph row with contents used for generating truncation
653 glyphs. Also used in direct_output_for_insert. */
655 #define MAX_SCRATCH_GLYPHS 100
656 struct glyph_row scratch_glyph_row
;
657 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
659 /* Ascent and height of the last line processed by move_it_to. */
661 static int last_max_ascent
, last_height
;
663 /* Non-zero if there's a help-echo in the echo area. */
665 int help_echo_showing_p
;
667 /* If >= 0, computed, exact values of mode-line and header-line height
668 to use in the macros CURRENT_MODE_LINE_HEIGHT and
669 CURRENT_HEADER_LINE_HEIGHT. */
671 int current_mode_line_height
, current_header_line_height
;
673 /* The maximum distance to look ahead for text properties. Values
674 that are too small let us call compute_char_face and similar
675 functions too often which is expensive. Values that are too large
676 let us call compute_char_face and alike too often because we
677 might not be interested in text properties that far away. */
679 #define TEXT_PROP_DISTANCE_LIMIT 100
683 /* Variables to turn off display optimizations from Lisp. */
685 int inhibit_try_window_id
, inhibit_try_window_reusing
;
686 int inhibit_try_cursor_movement
;
688 /* Non-zero means print traces of redisplay if compiled with
691 int trace_redisplay_p
;
693 #endif /* GLYPH_DEBUG */
695 #ifdef DEBUG_TRACE_MOVE
696 /* Non-zero means trace with TRACE_MOVE to stderr. */
699 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
701 #define TRACE_MOVE(x) (void) 0
704 /* Non-zero means automatically scroll windows horizontally to make
707 int automatic_hscrolling_p
;
709 /* How close to the margin can point get before the window is scrolled
711 EMACS_INT hscroll_margin
;
713 /* How much to scroll horizontally when point is inside the above margin. */
714 Lisp_Object Vhscroll_step
;
716 /* The variable `resize-mini-windows'. If nil, don't resize
717 mini-windows. If t, always resize them to fit the text they
718 display. If `grow-only', let mini-windows grow only until they
721 Lisp_Object Vresize_mini_windows
;
723 /* Buffer being redisplayed -- for redisplay_window_error. */
725 struct buffer
*displayed_buffer
;
727 /* Space between overline and text. */
729 EMACS_INT overline_margin
;
731 /* Value returned from text property handlers (see below). */
736 HANDLED_RECOMPUTE_PROPS
,
737 HANDLED_OVERLAY_STRING_CONSUMED
,
741 /* A description of text properties that redisplay is interested
746 /* The name of the property. */
749 /* A unique index for the property. */
752 /* A handler function called to set up iterator IT from the property
753 at IT's current position. Value is used to steer handle_stop. */
754 enum prop_handled (*handler
) P_ ((struct it
*it
));
757 static enum prop_handled handle_face_prop
P_ ((struct it
*));
758 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
759 static enum prop_handled handle_display_prop
P_ ((struct it
*));
760 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
761 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
762 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
763 static enum prop_handled handle_auto_composed_prop
P_ ((struct it
*));
765 /* Properties handled by iterators. */
767 static struct props it_props
[] =
769 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
770 /* Handle `face' before `display' because some sub-properties of
771 `display' need to know the face. */
772 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
773 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
774 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
775 {&Qauto_composed
, AUTO_COMPOSED_PROP_IDX
, handle_auto_composed_prop
},
776 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
780 /* Value is the position described by X. If X is a marker, value is
781 the marker_position of X. Otherwise, value is X. */
783 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
785 /* Enumeration returned by some move_it_.* functions internally. */
789 /* Not used. Undefined value. */
792 /* Move ended at the requested buffer position or ZV. */
793 MOVE_POS_MATCH_OR_ZV
,
795 /* Move ended at the requested X pixel position. */
798 /* Move within a line ended at the end of a line that must be
802 /* Move within a line ended at the end of a line that would
803 be displayed truncated. */
806 /* Move within a line ended at a line end. */
810 /* This counter is used to clear the face cache every once in a while
811 in redisplay_internal. It is incremented for each redisplay.
812 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
815 #define CLEAR_FACE_CACHE_COUNT 500
816 static int clear_face_cache_count
;
818 /* Similarly for the image cache. */
820 #ifdef HAVE_WINDOW_SYSTEM
821 #define CLEAR_IMAGE_CACHE_COUNT 101
822 static int clear_image_cache_count
;
825 /* Record the previous terminal frame we displayed. */
827 static struct frame
*previous_terminal_frame
;
829 /* Non-zero while redisplay_internal is in progress. */
833 /* Non-zero means don't free realized faces. Bound while freeing
834 realized faces is dangerous because glyph matrices might still
837 int inhibit_free_realized_faces
;
838 Lisp_Object Qinhibit_free_realized_faces
;
840 /* If a string, XTread_socket generates an event to display that string.
841 (The display is done in read_char.) */
843 Lisp_Object help_echo_string
;
844 Lisp_Object help_echo_window
;
845 Lisp_Object help_echo_object
;
848 /* Temporary variable for XTread_socket. */
850 Lisp_Object previous_help_echo_string
;
852 /* Null glyph slice */
854 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
857 /* Function prototypes. */
859 static void setup_for_ellipsis
P_ ((struct it
*, int));
860 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
861 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
862 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
863 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
864 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
865 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
868 static int invisible_text_between_p
P_ ((struct it
*, int, int));
871 static void pint2str
P_ ((char *, int, int));
872 static void pint2hrstr
P_ ((char *, int, int));
873 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
875 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
876 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
877 static void store_mode_line_noprop_char
P_ ((char));
878 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
879 static void x_consider_frame_title
P_ ((Lisp_Object
));
880 static void handle_stop
P_ ((struct it
*));
881 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
882 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
883 static void ensure_echo_area_buffers
P_ ((void));
884 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
885 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
886 static int with_echo_area_buffer
P_ ((struct window
*, int,
887 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
888 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
889 static void clear_garbaged_frames
P_ ((void));
890 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
891 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
892 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
893 static int display_echo_area
P_ ((struct window
*));
894 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
895 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
896 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
897 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
898 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
900 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
901 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
902 static void insert_left_trunc_glyphs
P_ ((struct it
*));
903 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
905 static void extend_face_to_end_of_line
P_ ((struct it
*));
906 static int append_space_for_newline
P_ ((struct it
*, int));
907 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
908 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
909 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
910 static int trailing_whitespace_p
P_ ((int));
911 static int message_log_check_duplicate
P_ ((int, int, int, int));
912 static void push_it
P_ ((struct it
*));
913 static void pop_it
P_ ((struct it
*));
914 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
915 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
916 static void redisplay_internal
P_ ((int));
917 static int echo_area_display
P_ ((int));
918 static void redisplay_windows
P_ ((Lisp_Object
));
919 static void redisplay_window
P_ ((Lisp_Object
, int));
920 static Lisp_Object
redisplay_window_error ();
921 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
922 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
923 static int update_menu_bar
P_ ((struct frame
*, int, int));
924 static int try_window_reusing_current_matrix
P_ ((struct window
*));
925 static int try_window_id
P_ ((struct window
*));
926 static int display_line
P_ ((struct it
*));
927 static int display_mode_lines
P_ ((struct window
*));
928 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
929 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
930 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
931 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
932 static void display_menu_bar
P_ ((struct window
*));
933 static int display_count_lines
P_ ((int, int, int, int, int *));
934 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
935 int, int, struct it
*, int, int, int, int));
936 static void compute_line_metrics
P_ ((struct it
*));
937 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
938 static int get_overlay_strings
P_ ((struct it
*, int));
939 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
940 static void next_overlay_string
P_ ((struct it
*));
941 static void reseat
P_ ((struct it
*, struct text_pos
, int));
942 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
943 static void back_to_previous_visible_line_start
P_ ((struct it
*));
944 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
945 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
946 static int next_element_from_ellipsis
P_ ((struct it
*));
947 static int next_element_from_display_vector
P_ ((struct it
*));
948 static int next_element_from_string
P_ ((struct it
*));
949 static int next_element_from_c_string
P_ ((struct it
*));
950 static int next_element_from_buffer
P_ ((struct it
*));
951 static int next_element_from_composition
P_ ((struct it
*));
952 static int next_element_from_image
P_ ((struct it
*));
953 static int next_element_from_stretch
P_ ((struct it
*));
954 static void load_overlay_strings
P_ ((struct it
*, int));
955 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
956 struct display_pos
*));
957 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
958 Lisp_Object
, int, int, int, int));
959 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
961 void move_it_vertically_backward
P_ ((struct it
*, int));
962 static void init_to_row_start
P_ ((struct it
*, struct window
*,
963 struct glyph_row
*));
964 static int init_to_row_end
P_ ((struct it
*, struct window
*,
965 struct glyph_row
*));
966 static void back_to_previous_line_start
P_ ((struct it
*));
967 static int forward_to_next_line_start
P_ ((struct it
*, int *));
968 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
970 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
971 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
972 static int number_of_chars
P_ ((unsigned char *, int));
973 static void compute_stop_pos
P_ ((struct it
*));
974 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
976 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
977 static int next_overlay_change
P_ ((int));
978 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
979 Lisp_Object
, struct text_pos
*,
981 static int underlying_face_id
P_ ((struct it
*));
982 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
985 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
986 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
988 #ifdef HAVE_WINDOW_SYSTEM
990 static void update_tool_bar
P_ ((struct frame
*, int));
991 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
992 static int redisplay_tool_bar
P_ ((struct frame
*));
993 static void display_tool_bar_line
P_ ((struct it
*, int));
994 static void notice_overwritten_cursor
P_ ((struct window
*,
996 int, int, int, int));
1000 #endif /* HAVE_WINDOW_SYSTEM */
1003 /***********************************************************************
1004 Window display dimensions
1005 ***********************************************************************/
1007 /* Return the bottom boundary y-position for text lines in window W.
1008 This is the first y position at which a line cannot start.
1009 It is relative to the top of the window.
1011 This is the height of W minus the height of a mode line, if any. */
1014 window_text_bottom_y (w
)
1017 int height
= WINDOW_TOTAL_HEIGHT (w
);
1019 if (WINDOW_WANTS_MODELINE_P (w
))
1020 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1024 /* Return the pixel width of display area AREA of window W. AREA < 0
1025 means return the total width of W, not including fringes to
1026 the left and right of the window. */
1029 window_box_width (w
, area
)
1033 int cols
= XFASTINT (w
->total_cols
);
1036 if (!w
->pseudo_window_p
)
1038 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1040 if (area
== TEXT_AREA
)
1042 if (INTEGERP (w
->left_margin_cols
))
1043 cols
-= XFASTINT (w
->left_margin_cols
);
1044 if (INTEGERP (w
->right_margin_cols
))
1045 cols
-= XFASTINT (w
->right_margin_cols
);
1046 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1048 else if (area
== LEFT_MARGIN_AREA
)
1050 cols
= (INTEGERP (w
->left_margin_cols
)
1051 ? XFASTINT (w
->left_margin_cols
) : 0);
1054 else if (area
== RIGHT_MARGIN_AREA
)
1056 cols
= (INTEGERP (w
->right_margin_cols
)
1057 ? XFASTINT (w
->right_margin_cols
) : 0);
1062 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1066 /* Return the pixel height of the display area of window W, not
1067 including mode lines of W, if any. */
1070 window_box_height (w
)
1073 struct frame
*f
= XFRAME (w
->frame
);
1074 int height
= WINDOW_TOTAL_HEIGHT (w
);
1076 xassert (height
>= 0);
1078 /* Note: the code below that determines the mode-line/header-line
1079 height is essentially the same as that contained in the macro
1080 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1081 the appropriate glyph row has its `mode_line_p' flag set,
1082 and if it doesn't, uses estimate_mode_line_height instead. */
1084 if (WINDOW_WANTS_MODELINE_P (w
))
1086 struct glyph_row
*ml_row
1087 = (w
->current_matrix
&& w
->current_matrix
->rows
1088 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1090 if (ml_row
&& ml_row
->mode_line_p
)
1091 height
-= ml_row
->height
;
1093 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1096 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1098 struct glyph_row
*hl_row
1099 = (w
->current_matrix
&& w
->current_matrix
->rows
1100 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1102 if (hl_row
&& hl_row
->mode_line_p
)
1103 height
-= hl_row
->height
;
1105 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1108 /* With a very small font and a mode-line that's taller than
1109 default, we might end up with a negative height. */
1110 return max (0, height
);
1113 /* Return the window-relative coordinate of the left edge of display
1114 area AREA of window W. AREA < 0 means return the left edge of the
1115 whole window, to the right of the left fringe of W. */
1118 window_box_left_offset (w
, area
)
1124 if (w
->pseudo_window_p
)
1127 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1129 if (area
== TEXT_AREA
)
1130 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1131 + window_box_width (w
, LEFT_MARGIN_AREA
));
1132 else if (area
== RIGHT_MARGIN_AREA
)
1133 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1134 + window_box_width (w
, LEFT_MARGIN_AREA
)
1135 + window_box_width (w
, TEXT_AREA
)
1136 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1138 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1139 else if (area
== LEFT_MARGIN_AREA
1140 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1141 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1147 /* Return the window-relative coordinate of the right edge of display
1148 area AREA of window W. AREA < 0 means return the left edge of the
1149 whole window, to the left of the right fringe of W. */
1152 window_box_right_offset (w
, area
)
1156 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1159 /* Return the frame-relative coordinate of the left edge of display
1160 area AREA of window W. AREA < 0 means return the left edge of the
1161 whole window, to the right of the left fringe of W. */
1164 window_box_left (w
, area
)
1168 struct frame
*f
= XFRAME (w
->frame
);
1171 if (w
->pseudo_window_p
)
1172 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1174 x
= (WINDOW_LEFT_EDGE_X (w
)
1175 + window_box_left_offset (w
, area
));
1181 /* Return the frame-relative coordinate of the right edge of display
1182 area AREA of window W. AREA < 0 means return the left edge of the
1183 whole window, to the left of the right fringe of W. */
1186 window_box_right (w
, area
)
1190 return window_box_left (w
, area
) + window_box_width (w
, area
);
1193 /* Get the bounding box of the display area AREA of window W, without
1194 mode lines, in frame-relative coordinates. AREA < 0 means the
1195 whole window, not including the left and right fringes of
1196 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1197 coordinates of the upper-left corner of the box. Return in
1198 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1201 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1204 int *box_x
, *box_y
, *box_width
, *box_height
;
1207 *box_width
= window_box_width (w
, area
);
1209 *box_height
= window_box_height (w
);
1211 *box_x
= window_box_left (w
, area
);
1214 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1215 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1216 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1221 /* Get the bounding box of the display area AREA of window W, without
1222 mode lines. AREA < 0 means the whole window, not including the
1223 left and right fringe of the window. Return in *TOP_LEFT_X
1224 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1225 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1226 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1230 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1231 bottom_right_x
, bottom_right_y
)
1234 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1236 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1238 *bottom_right_x
+= *top_left_x
;
1239 *bottom_right_y
+= *top_left_y
;
1244 /***********************************************************************
1246 ***********************************************************************/
1248 /* Return the bottom y-position of the line the iterator IT is in.
1249 This can modify IT's settings. */
1255 int line_height
= it
->max_ascent
+ it
->max_descent
;
1256 int line_top_y
= it
->current_y
;
1258 if (line_height
== 0)
1261 line_height
= last_height
;
1262 else if (IT_CHARPOS (*it
) < ZV
)
1264 move_it_by_lines (it
, 1, 1);
1265 line_height
= (it
->max_ascent
|| it
->max_descent
1266 ? it
->max_ascent
+ it
->max_descent
1271 struct glyph_row
*row
= it
->glyph_row
;
1273 /* Use the default character height. */
1274 it
->glyph_row
= NULL
;
1275 it
->what
= IT_CHARACTER
;
1278 PRODUCE_GLYPHS (it
);
1279 line_height
= it
->ascent
+ it
->descent
;
1280 it
->glyph_row
= row
;
1284 return line_top_y
+ line_height
;
1288 /* Return 1 if position CHARPOS is visible in window W.
1289 CHARPOS < 0 means return info about WINDOW_END position.
1290 If visible, set *X and *Y to pixel coordinates of top left corner.
1291 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1292 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1295 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1297 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1300 struct text_pos top
;
1302 struct buffer
*old_buffer
= NULL
;
1307 if (XBUFFER (w
->buffer
) != current_buffer
)
1309 old_buffer
= current_buffer
;
1310 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1313 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1315 /* Compute exact mode line heights. */
1316 if (WINDOW_WANTS_MODELINE_P (w
))
1317 current_mode_line_height
1318 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1319 current_buffer
->mode_line_format
);
1321 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1322 current_header_line_height
1323 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1324 current_buffer
->header_line_format
);
1326 start_display (&it
, w
, top
);
1327 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1328 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1330 /* Note that we may overshoot because of invisible text. */
1331 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1333 int top_x
= it
.current_x
;
1334 int top_y
= it
.current_y
;
1335 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1336 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1338 if (top_y
< window_top_y
)
1339 visible_p
= bottom_y
> window_top_y
;
1340 else if (top_y
< it
.last_visible_y
)
1345 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1346 *rtop
= max (0, window_top_y
- top_y
);
1347 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1348 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1349 - max (top_y
, window_top_y
)));
1358 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1359 move_it_by_lines (&it
, 1, 0);
1360 if (charpos
< IT_CHARPOS (it
)
1361 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1364 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1366 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1367 *rtop
= max (0, -it2
.current_y
);
1368 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1369 - it
.last_visible_y
));
1370 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1372 - max (it2
.current_y
,
1373 WINDOW_HEADER_LINE_HEIGHT (w
))));
1379 set_buffer_internal_1 (old_buffer
);
1381 current_header_line_height
= current_mode_line_height
= -1;
1383 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1384 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1387 /* Debugging code. */
1389 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1390 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1392 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1399 /* Return the next character from STR which is MAXLEN bytes long.
1400 Return in *LEN the length of the character. This is like
1401 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1402 we find one, we return a `?', but with the length of the invalid
1406 string_char_and_length (str
, maxlen
, len
)
1407 const unsigned char *str
;
1412 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1413 if (!CHAR_VALID_P (c
, 1))
1414 /* We may not change the length here because other places in Emacs
1415 don't use this function, i.e. they silently accept invalid
1424 /* Given a position POS containing a valid character and byte position
1425 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1427 static struct text_pos
1428 string_pos_nchars_ahead (pos
, string
, nchars
)
1429 struct text_pos pos
;
1433 xassert (STRINGP (string
) && nchars
>= 0);
1435 if (STRING_MULTIBYTE (string
))
1437 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1438 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1443 string_char_and_length (p
, rest
, &len
);
1444 p
+= len
, rest
-= len
;
1445 xassert (rest
>= 0);
1447 BYTEPOS (pos
) += len
;
1451 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1457 /* Value is the text position, i.e. character and byte position,
1458 for character position CHARPOS in STRING. */
1460 static INLINE
struct text_pos
1461 string_pos (charpos
, string
)
1465 struct text_pos pos
;
1466 xassert (STRINGP (string
));
1467 xassert (charpos
>= 0);
1468 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1473 /* Value is a text position, i.e. character and byte position, for
1474 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1475 means recognize multibyte characters. */
1477 static struct text_pos
1478 c_string_pos (charpos
, s
, multibyte_p
)
1483 struct text_pos pos
;
1485 xassert (s
!= NULL
);
1486 xassert (charpos
>= 0);
1490 int rest
= strlen (s
), len
;
1492 SET_TEXT_POS (pos
, 0, 0);
1495 string_char_and_length (s
, rest
, &len
);
1496 s
+= len
, rest
-= len
;
1497 xassert (rest
>= 0);
1499 BYTEPOS (pos
) += len
;
1503 SET_TEXT_POS (pos
, charpos
, charpos
);
1509 /* Value is the number of characters in C string S. MULTIBYTE_P
1510 non-zero means recognize multibyte characters. */
1513 number_of_chars (s
, multibyte_p
)
1521 int rest
= strlen (s
), len
;
1522 unsigned char *p
= (unsigned char *) s
;
1524 for (nchars
= 0; rest
> 0; ++nchars
)
1526 string_char_and_length (p
, rest
, &len
);
1527 rest
-= len
, p
+= len
;
1531 nchars
= strlen (s
);
1537 /* Compute byte position NEWPOS->bytepos corresponding to
1538 NEWPOS->charpos. POS is a known position in string STRING.
1539 NEWPOS->charpos must be >= POS.charpos. */
1542 compute_string_pos (newpos
, pos
, string
)
1543 struct text_pos
*newpos
, pos
;
1546 xassert (STRINGP (string
));
1547 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1549 if (STRING_MULTIBYTE (string
))
1550 *newpos
= string_pos_nchars_ahead (pos
, string
,
1551 CHARPOS (*newpos
) - CHARPOS (pos
));
1553 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1557 Return an estimation of the pixel height of mode or top lines on
1558 frame F. FACE_ID specifies what line's height to estimate. */
1561 estimate_mode_line_height (f
, face_id
)
1563 enum face_id face_id
;
1565 #ifdef HAVE_WINDOW_SYSTEM
1566 if (FRAME_WINDOW_P (f
))
1568 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1570 /* This function is called so early when Emacs starts that the face
1571 cache and mode line face are not yet initialized. */
1572 if (FRAME_FACE_CACHE (f
))
1574 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1578 height
= FONT_HEIGHT (face
->font
);
1579 if (face
->box_line_width
> 0)
1580 height
+= 2 * face
->box_line_width
;
1591 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1592 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1593 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1594 not force the value into range. */
1597 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1599 register int pix_x
, pix_y
;
1601 NativeRectangle
*bounds
;
1605 #ifdef HAVE_WINDOW_SYSTEM
1606 if (FRAME_WINDOW_P (f
))
1608 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1609 even for negative values. */
1611 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1613 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1615 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1616 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1619 STORE_NATIVE_RECT (*bounds
,
1620 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1621 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1622 FRAME_COLUMN_WIDTH (f
) - 1,
1623 FRAME_LINE_HEIGHT (f
) - 1);
1629 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1630 pix_x
= FRAME_TOTAL_COLS (f
);
1634 else if (pix_y
> FRAME_LINES (f
))
1635 pix_y
= FRAME_LINES (f
);
1645 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1646 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1647 can't tell the positions because W's display is not up to date,
1651 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1654 int *frame_x
, *frame_y
;
1656 #ifdef HAVE_WINDOW_SYSTEM
1657 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1661 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1662 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1664 if (display_completed
)
1666 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1667 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1668 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1674 hpos
+= glyph
->pixel_width
;
1678 /* If first glyph is partially visible, its first visible position is still 0. */
1690 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1691 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1702 #ifdef HAVE_WINDOW_SYSTEM
1704 /* Find the glyph under window-relative coordinates X/Y in window W.
1705 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1706 strings. Return in *HPOS and *VPOS the row and column number of
1707 the glyph found. Return in *AREA the glyph area containing X.
1708 Value is a pointer to the glyph found or null if X/Y is not on
1709 text, or we can't tell because W's current matrix is not up to
1712 static struct glyph
*
1713 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1716 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1718 struct glyph
*glyph
, *end
;
1719 struct glyph_row
*row
= NULL
;
1722 /* Find row containing Y. Give up if some row is not enabled. */
1723 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1725 row
= MATRIX_ROW (w
->current_matrix
, i
);
1726 if (!row
->enabled_p
)
1728 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1735 /* Give up if Y is not in the window. */
1736 if (i
== w
->current_matrix
->nrows
)
1739 /* Get the glyph area containing X. */
1740 if (w
->pseudo_window_p
)
1747 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1749 *area
= LEFT_MARGIN_AREA
;
1750 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1752 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1755 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1759 *area
= RIGHT_MARGIN_AREA
;
1760 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1764 /* Find glyph containing X. */
1765 glyph
= row
->glyphs
[*area
];
1766 end
= glyph
+ row
->used
[*area
];
1768 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1770 x
-= glyph
->pixel_width
;
1780 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1783 *hpos
= glyph
- row
->glyphs
[*area
];
1789 Convert frame-relative x/y to coordinates relative to window W.
1790 Takes pseudo-windows into account. */
1793 frame_to_window_pixel_xy (w
, x
, y
)
1797 if (w
->pseudo_window_p
)
1799 /* A pseudo-window is always full-width, and starts at the
1800 left edge of the frame, plus a frame border. */
1801 struct frame
*f
= XFRAME (w
->frame
);
1802 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1803 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1807 *x
-= WINDOW_LEFT_EDGE_X (w
);
1808 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1813 Return in RECTS[] at most N clipping rectangles for glyph string S.
1814 Return the number of stored rectangles. */
1817 get_glyph_string_clip_rects (s
, rects
, n
)
1818 struct glyph_string
*s
;
1819 NativeRectangle
*rects
;
1827 if (s
->row
->full_width_p
)
1829 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1830 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1831 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1833 /* Unless displaying a mode or menu bar line, which are always
1834 fully visible, clip to the visible part of the row. */
1835 if (s
->w
->pseudo_window_p
)
1836 r
.height
= s
->row
->visible_height
;
1838 r
.height
= s
->height
;
1842 /* This is a text line that may be partially visible. */
1843 r
.x
= window_box_left (s
->w
, s
->area
);
1844 r
.width
= window_box_width (s
->w
, s
->area
);
1845 r
.height
= s
->row
->visible_height
;
1849 if (r
.x
< s
->clip_head
->x
)
1851 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1852 r
.width
-= s
->clip_head
->x
- r
.x
;
1855 r
.x
= s
->clip_head
->x
;
1858 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1860 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1861 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1866 /* If S draws overlapping rows, it's sufficient to use the top and
1867 bottom of the window for clipping because this glyph string
1868 intentionally draws over other lines. */
1869 if (s
->for_overlaps
)
1871 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1872 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1874 /* Alas, the above simple strategy does not work for the
1875 environments with anti-aliased text: if the same text is
1876 drawn onto the same place multiple times, it gets thicker.
1877 If the overlap we are processing is for the erased cursor, we
1878 take the intersection with the rectagle of the cursor. */
1879 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1881 XRectangle rc
, r_save
= r
;
1883 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1884 rc
.y
= s
->w
->phys_cursor
.y
;
1885 rc
.width
= s
->w
->phys_cursor_width
;
1886 rc
.height
= s
->w
->phys_cursor_height
;
1888 x_intersect_rectangles (&r_save
, &rc
, &r
);
1893 /* Don't use S->y for clipping because it doesn't take partially
1894 visible lines into account. For example, it can be negative for
1895 partially visible lines at the top of a window. */
1896 if (!s
->row
->full_width_p
1897 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1898 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1900 r
.y
= max (0, s
->row
->y
);
1902 /* If drawing a tool-bar window, draw it over the internal border
1903 at the top of the window. */
1904 if (WINDOWP (s
->f
->tool_bar_window
)
1905 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1906 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1909 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1911 /* If drawing the cursor, don't let glyph draw outside its
1912 advertised boundaries. Cleartype does this under some circumstances. */
1913 if (s
->hl
== DRAW_CURSOR
)
1915 struct glyph
*glyph
= s
->first_glyph
;
1920 r
.width
-= s
->x
- r
.x
;
1923 r
.width
= min (r
.width
, glyph
->pixel_width
);
1925 /* If r.y is below window bottom, ensure that we still see a cursor. */
1926 height
= min (glyph
->ascent
+ glyph
->descent
,
1927 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1928 max_y
= window_text_bottom_y (s
->w
) - height
;
1929 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1930 if (s
->ybase
- glyph
->ascent
> max_y
)
1937 /* Don't draw cursor glyph taller than our actual glyph. */
1938 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1939 if (height
< r
.height
)
1941 max_y
= r
.y
+ r
.height
;
1942 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1943 r
.height
= min (max_y
- r
.y
, height
);
1948 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1949 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1951 #ifdef CONVERT_FROM_XRECT
1952 CONVERT_FROM_XRECT (r
, *rects
);
1960 /* If we are processing overlapping and allowed to return
1961 multiple clipping rectangles, we exclude the row of the glyph
1962 string from the clipping rectangle. This is to avoid drawing
1963 the same text on the environment with anti-aliasing. */
1964 #ifdef CONVERT_FROM_XRECT
1967 XRectangle
*rs
= rects
;
1969 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
1971 if (s
->for_overlaps
& OVERLAPS_PRED
)
1974 if (r
.y
+ r
.height
> row_y
)
1977 rs
[i
].height
= row_y
- r
.y
;
1983 if (s
->for_overlaps
& OVERLAPS_SUCC
)
1986 if (r
.y
< row_y
+ s
->row
->visible_height
)
1988 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
1990 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
1991 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2000 #ifdef CONVERT_FROM_XRECT
2001 for (i
= 0; i
< n
; i
++)
2002 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2009 Return in *NR the clipping rectangle for glyph string S. */
2012 get_glyph_string_clip_rect (s
, nr
)
2013 struct glyph_string
*s
;
2014 NativeRectangle
*nr
;
2016 get_glyph_string_clip_rects (s
, nr
, 1);
2021 Return the position and height of the phys cursor in window W.
2022 Set w->phys_cursor_width to width of phys cursor.
2026 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2028 struct glyph_row
*row
;
2029 struct glyph
*glyph
;
2030 int *xp
, *yp
, *heightp
;
2032 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2033 int x
, y
, wd
, h
, h0
, y0
;
2035 /* Compute the width of the rectangle to draw. If on a stretch
2036 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2037 rectangle as wide as the glyph, but use a canonical character
2039 wd
= glyph
->pixel_width
- 1;
2044 x
= w
->phys_cursor
.x
;
2051 if (glyph
->type
== STRETCH_GLYPH
2052 && !x_stretch_cursor_p
)
2053 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2054 w
->phys_cursor_width
= wd
;
2056 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2058 /* If y is below window bottom, ensure that we still see a cursor. */
2059 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2061 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2062 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2064 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2067 h
= max (h
- (y0
- y
) + 1, h0
);
2072 y0
= window_text_bottom_y (w
) - h0
;
2080 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2081 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2086 * Remember which glyph the mouse is over.
2090 remember_mouse_glyph (f
, gx
, gy
, rect
)
2093 NativeRectangle
*rect
;
2097 struct glyph_row
*r
, *gr
, *end_row
;
2098 enum window_part part
;
2099 enum glyph_row_area area
;
2100 int x
, y
, width
, height
;
2102 /* Try to determine frame pixel position and size of the glyph under
2103 frame pixel coordinates X/Y on frame F. */
2105 if (!f
->glyphs_initialized_p
2106 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2109 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2110 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2114 w
= XWINDOW (window
);
2115 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2116 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2118 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2119 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2121 if (w
->pseudo_window_p
)
2124 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2130 case ON_LEFT_MARGIN
:
2131 area
= LEFT_MARGIN_AREA
;
2134 case ON_RIGHT_MARGIN
:
2135 area
= RIGHT_MARGIN_AREA
;
2138 case ON_HEADER_LINE
:
2140 gr
= (part
== ON_HEADER_LINE
2141 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2142 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2145 goto text_glyph_row_found
;
2152 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2153 if (r
->y
+ r
->height
> y
)
2159 text_glyph_row_found
:
2162 struct glyph
*g
= gr
->glyphs
[area
];
2163 struct glyph
*end
= g
+ gr
->used
[area
];
2165 height
= gr
->height
;
2166 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2167 if (gx
+ g
->pixel_width
> x
)
2172 if (g
->type
== IMAGE_GLYPH
)
2174 /* Don't remember when mouse is over image, as
2175 image may have hot-spots. */
2176 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2179 width
= g
->pixel_width
;
2183 /* Use nominal char spacing at end of line. */
2185 gx
+= (x
/ width
) * width
;
2188 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2189 gx
+= window_box_left_offset (w
, area
);
2193 /* Use nominal line height at end of window. */
2194 gx
= (x
/ width
) * width
;
2196 gy
+= (y
/ height
) * height
;
2200 case ON_LEFT_FRINGE
:
2201 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2202 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2203 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2204 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2207 case ON_RIGHT_FRINGE
:
2208 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2209 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2210 : window_box_right_offset (w
, TEXT_AREA
));
2211 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2215 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2217 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2218 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2219 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2221 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2225 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2226 if (r
->y
+ r
->height
> y
)
2233 height
= gr
->height
;
2236 /* Use nominal line height at end of window. */
2238 gy
+= (y
/ height
) * height
;
2245 /* If there is no glyph under the mouse, then we divide the screen
2246 into a grid of the smallest glyph in the frame, and use that
2249 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2250 round down even for negative values. */
2256 gx
= (gx
/ width
) * width
;
2257 gy
= (gy
/ height
) * height
;
2262 gx
+= WINDOW_LEFT_EDGE_X (w
);
2263 gy
+= WINDOW_TOP_EDGE_Y (w
);
2266 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2268 /* Visible feedback for debugging. */
2271 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2272 f
->output_data
.x
->normal_gc
,
2273 gx
, gy
, width
, height
);
2279 #endif /* HAVE_WINDOW_SYSTEM */
2282 /***********************************************************************
2283 Lisp form evaluation
2284 ***********************************************************************/
2286 /* Error handler for safe_eval and safe_call. */
2289 safe_eval_handler (arg
)
2292 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2297 /* Evaluate SEXPR and return the result, or nil if something went
2298 wrong. Prevent redisplay during the evaluation. */
2306 if (inhibit_eval_during_redisplay
)
2310 int count
= SPECPDL_INDEX ();
2311 struct gcpro gcpro1
;
2314 specbind (Qinhibit_redisplay
, Qt
);
2315 /* Use Qt to ensure debugger does not run,
2316 so there is no possibility of wanting to redisplay. */
2317 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
2320 val
= unbind_to (count
, val
);
2327 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2328 Return the result, or nil if something went wrong. Prevent
2329 redisplay during the evaluation. */
2332 safe_call (nargs
, args
)
2338 if (inhibit_eval_during_redisplay
)
2342 int count
= SPECPDL_INDEX ();
2343 struct gcpro gcpro1
;
2346 gcpro1
.nvars
= nargs
;
2347 specbind (Qinhibit_redisplay
, Qt
);
2348 /* Use Qt to ensure debugger does not run,
2349 so there is no possibility of wanting to redisplay. */
2350 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2353 val
= unbind_to (count
, val
);
2360 /* Call function FN with one argument ARG.
2361 Return the result, or nil if something went wrong. */
2364 safe_call1 (fn
, arg
)
2365 Lisp_Object fn
, arg
;
2367 Lisp_Object args
[2];
2370 return safe_call (2, args
);
2375 /***********************************************************************
2377 ***********************************************************************/
2381 /* Define CHECK_IT to perform sanity checks on iterators.
2382 This is for debugging. It is too slow to do unconditionally. */
2388 if (it
->method
== GET_FROM_STRING
)
2390 xassert (STRINGP (it
->string
));
2391 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2395 xassert (IT_STRING_CHARPOS (*it
) < 0);
2396 if (it
->method
== GET_FROM_BUFFER
)
2398 /* Check that character and byte positions agree. */
2399 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2404 xassert (it
->current
.dpvec_index
>= 0);
2406 xassert (it
->current
.dpvec_index
< 0);
2409 #define CHECK_IT(IT) check_it ((IT))
2413 #define CHECK_IT(IT) (void) 0
2420 /* Check that the window end of window W is what we expect it
2421 to be---the last row in the current matrix displaying text. */
2424 check_window_end (w
)
2427 if (!MINI_WINDOW_P (w
)
2428 && !NILP (w
->window_end_valid
))
2430 struct glyph_row
*row
;
2431 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2432 XFASTINT (w
->window_end_vpos
)),
2434 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2435 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2439 #define CHECK_WINDOW_END(W) check_window_end ((W))
2441 #else /* not GLYPH_DEBUG */
2443 #define CHECK_WINDOW_END(W) (void) 0
2445 #endif /* not GLYPH_DEBUG */
2449 /***********************************************************************
2450 Iterator initialization
2451 ***********************************************************************/
2453 /* Initialize IT for displaying current_buffer in window W, starting
2454 at character position CHARPOS. CHARPOS < 0 means that no buffer
2455 position is specified which is useful when the iterator is assigned
2456 a position later. BYTEPOS is the byte position corresponding to
2457 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2459 If ROW is not null, calls to produce_glyphs with IT as parameter
2460 will produce glyphs in that row.
2462 BASE_FACE_ID is the id of a base face to use. It must be one of
2463 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2464 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2465 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2467 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2468 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2469 will be initialized to use the corresponding mode line glyph row of
2470 the desired matrix of W. */
2473 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2476 int charpos
, bytepos
;
2477 struct glyph_row
*row
;
2478 enum face_id base_face_id
;
2480 int highlight_region_p
;
2482 /* Some precondition checks. */
2483 xassert (w
!= NULL
&& it
!= NULL
);
2484 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2487 /* If face attributes have been changed since the last redisplay,
2488 free realized faces now because they depend on face definitions
2489 that might have changed. Don't free faces while there might be
2490 desired matrices pending which reference these faces. */
2491 if (face_change_count
&& !inhibit_free_realized_faces
)
2493 face_change_count
= 0;
2494 free_all_realized_faces (Qnil
);
2497 /* Use one of the mode line rows of W's desired matrix if
2501 if (base_face_id
== MODE_LINE_FACE_ID
2502 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2503 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2504 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2505 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2509 bzero (it
, sizeof *it
);
2510 it
->current
.overlay_string_index
= -1;
2511 it
->current
.dpvec_index
= -1;
2512 it
->base_face_id
= base_face_id
;
2514 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2516 /* The window in which we iterate over current_buffer: */
2517 XSETWINDOW (it
->window
, w
);
2519 it
->f
= XFRAME (w
->frame
);
2521 /* Extra space between lines (on window systems only). */
2522 if (base_face_id
== DEFAULT_FACE_ID
2523 && FRAME_WINDOW_P (it
->f
))
2525 if (NATNUMP (current_buffer
->extra_line_spacing
))
2526 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2527 else if (FLOATP (current_buffer
->extra_line_spacing
))
2528 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2529 * FRAME_LINE_HEIGHT (it
->f
));
2530 else if (it
->f
->extra_line_spacing
> 0)
2531 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2532 it
->max_extra_line_spacing
= 0;
2535 /* If realized faces have been removed, e.g. because of face
2536 attribute changes of named faces, recompute them. When running
2537 in batch mode, the face cache of Vterminal_frame is null. If
2538 we happen to get called, make a dummy face cache. */
2539 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2540 init_frame_faces (it
->f
);
2541 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2542 recompute_basic_faces (it
->f
);
2544 /* Current value of the `slice', `space-width', and 'height' properties. */
2545 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2546 it
->space_width
= Qnil
;
2547 it
->font_height
= Qnil
;
2548 it
->override_ascent
= -1;
2550 /* Are control characters displayed as `^C'? */
2551 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2553 /* -1 means everything between a CR and the following line end
2554 is invisible. >0 means lines indented more than this value are
2556 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2557 ? XFASTINT (current_buffer
->selective_display
)
2558 : (!NILP (current_buffer
->selective_display
)
2560 it
->selective_display_ellipsis_p
2561 = !NILP (current_buffer
->selective_display_ellipses
);
2563 /* Display table to use. */
2564 it
->dp
= window_display_table (w
);
2566 /* Are multibyte characters enabled in current_buffer? */
2567 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2569 /* Non-zero if we should highlight the region. */
2571 = (!NILP (Vtransient_mark_mode
)
2572 && !NILP (current_buffer
->mark_active
)
2573 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2575 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2576 start and end of a visible region in window IT->w. Set both to
2577 -1 to indicate no region. */
2578 if (highlight_region_p
2579 /* Maybe highlight only in selected window. */
2580 && (/* Either show region everywhere. */
2581 highlight_nonselected_windows
2582 /* Or show region in the selected window. */
2583 || w
== XWINDOW (selected_window
)
2584 /* Or show the region if we are in the mini-buffer and W is
2585 the window the mini-buffer refers to. */
2586 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2587 && WINDOWP (minibuf_selected_window
)
2588 && w
== XWINDOW (minibuf_selected_window
))))
2590 int charpos
= marker_position (current_buffer
->mark
);
2591 it
->region_beg_charpos
= min (PT
, charpos
);
2592 it
->region_end_charpos
= max (PT
, charpos
);
2595 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2597 /* Get the position at which the redisplay_end_trigger hook should
2598 be run, if it is to be run at all. */
2599 if (MARKERP (w
->redisplay_end_trigger
)
2600 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2601 it
->redisplay_end_trigger_charpos
2602 = marker_position (w
->redisplay_end_trigger
);
2603 else if (INTEGERP (w
->redisplay_end_trigger
))
2604 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2606 /* Correct bogus values of tab_width. */
2607 it
->tab_width
= XINT (current_buffer
->tab_width
);
2608 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2611 /* Are lines in the display truncated? */
2612 it
->truncate_lines_p
2613 = (base_face_id
!= DEFAULT_FACE_ID
2614 || XINT (it
->w
->hscroll
)
2615 || (truncate_partial_width_windows
2616 && !WINDOW_FULL_WIDTH_P (it
->w
))
2617 || !NILP (current_buffer
->truncate_lines
));
2619 /* Get dimensions of truncation and continuation glyphs. These are
2620 displayed as fringe bitmaps under X, so we don't need them for such
2622 if (!FRAME_WINDOW_P (it
->f
))
2624 if (it
->truncate_lines_p
)
2626 /* We will need the truncation glyph. */
2627 xassert (it
->glyph_row
== NULL
);
2628 produce_special_glyphs (it
, IT_TRUNCATION
);
2629 it
->truncation_pixel_width
= it
->pixel_width
;
2633 /* We will need the continuation glyph. */
2634 xassert (it
->glyph_row
== NULL
);
2635 produce_special_glyphs (it
, IT_CONTINUATION
);
2636 it
->continuation_pixel_width
= it
->pixel_width
;
2639 /* Reset these values to zero because the produce_special_glyphs
2640 above has changed them. */
2641 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2642 it
->phys_ascent
= it
->phys_descent
= 0;
2645 /* Set this after getting the dimensions of truncation and
2646 continuation glyphs, so that we don't produce glyphs when calling
2647 produce_special_glyphs, above. */
2648 it
->glyph_row
= row
;
2649 it
->area
= TEXT_AREA
;
2651 /* Get the dimensions of the display area. The display area
2652 consists of the visible window area plus a horizontally scrolled
2653 part to the left of the window. All x-values are relative to the
2654 start of this total display area. */
2655 if (base_face_id
!= DEFAULT_FACE_ID
)
2657 /* Mode lines, menu bar in terminal frames. */
2658 it
->first_visible_x
= 0;
2659 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2664 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2665 it
->last_visible_x
= (it
->first_visible_x
2666 + window_box_width (w
, TEXT_AREA
));
2668 /* If we truncate lines, leave room for the truncator glyph(s) at
2669 the right margin. Otherwise, leave room for the continuation
2670 glyph(s). Truncation and continuation glyphs are not inserted
2671 for window-based redisplay. */
2672 if (!FRAME_WINDOW_P (it
->f
))
2674 if (it
->truncate_lines_p
)
2675 it
->last_visible_x
-= it
->truncation_pixel_width
;
2677 it
->last_visible_x
-= it
->continuation_pixel_width
;
2680 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2681 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2684 /* Leave room for a border glyph. */
2685 if (!FRAME_WINDOW_P (it
->f
)
2686 && !WINDOW_RIGHTMOST_P (it
->w
))
2687 it
->last_visible_x
-= 1;
2689 it
->last_visible_y
= window_text_bottom_y (w
);
2691 /* For mode lines and alike, arrange for the first glyph having a
2692 left box line if the face specifies a box. */
2693 if (base_face_id
!= DEFAULT_FACE_ID
)
2697 it
->face_id
= base_face_id
;
2699 /* If we have a boxed mode line, make the first character appear
2700 with a left box line. */
2701 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2702 if (face
->box
!= FACE_NO_BOX
)
2703 it
->start_of_box_run_p
= 1;
2706 /* If a buffer position was specified, set the iterator there,
2707 getting overlays and face properties from that position. */
2708 if (charpos
>= BUF_BEG (current_buffer
))
2710 it
->end_charpos
= ZV
;
2712 IT_CHARPOS (*it
) = charpos
;
2714 /* Compute byte position if not specified. */
2715 if (bytepos
< charpos
)
2716 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2718 IT_BYTEPOS (*it
) = bytepos
;
2720 it
->start
= it
->current
;
2722 /* Compute faces etc. */
2723 reseat (it
, it
->current
.pos
, 1);
2730 /* Initialize IT for the display of window W with window start POS. */
2733 start_display (it
, w
, pos
)
2736 struct text_pos pos
;
2738 struct glyph_row
*row
;
2739 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2741 row
= w
->desired_matrix
->rows
+ first_vpos
;
2742 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2743 it
->first_vpos
= first_vpos
;
2745 /* Don't reseat to previous visible line start if current start
2746 position is in a string or image. */
2747 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2749 int start_at_line_beg_p
;
2750 int first_y
= it
->current_y
;
2752 /* If window start is not at a line start, skip forward to POS to
2753 get the correct continuation lines width. */
2754 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2755 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2756 if (!start_at_line_beg_p
)
2760 reseat_at_previous_visible_line_start (it
);
2761 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2763 new_x
= it
->current_x
+ it
->pixel_width
;
2765 /* If lines are continued, this line may end in the middle
2766 of a multi-glyph character (e.g. a control character
2767 displayed as \003, or in the middle of an overlay
2768 string). In this case move_it_to above will not have
2769 taken us to the start of the continuation line but to the
2770 end of the continued line. */
2771 if (it
->current_x
> 0
2772 && !it
->truncate_lines_p
/* Lines are continued. */
2773 && (/* And glyph doesn't fit on the line. */
2774 new_x
> it
->last_visible_x
2775 /* Or it fits exactly and we're on a window
2777 || (new_x
== it
->last_visible_x
2778 && FRAME_WINDOW_P (it
->f
))))
2780 if (it
->current
.dpvec_index
>= 0
2781 || it
->current
.overlay_string_index
>= 0)
2783 set_iterator_to_next (it
, 1);
2784 move_it_in_display_line_to (it
, -1, -1, 0);
2787 it
->continuation_lines_width
+= it
->current_x
;
2790 /* We're starting a new display line, not affected by the
2791 height of the continued line, so clear the appropriate
2792 fields in the iterator structure. */
2793 it
->max_ascent
= it
->max_descent
= 0;
2794 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2796 it
->current_y
= first_y
;
2798 it
->current_x
= it
->hpos
= 0;
2802 #if 0 /* Don't assert the following because start_display is sometimes
2803 called intentionally with a window start that is not at a
2804 line start. Please leave this code in as a comment. */
2806 /* Window start should be on a line start, now. */
2807 xassert (it
->continuation_lines_width
2808 || IT_CHARPOS (it
) == BEGV
2809 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2814 /* Return 1 if POS is a position in ellipses displayed for invisible
2815 text. W is the window we display, for text property lookup. */
2818 in_ellipses_for_invisible_text_p (pos
, w
)
2819 struct display_pos
*pos
;
2822 Lisp_Object prop
, window
;
2824 int charpos
= CHARPOS (pos
->pos
);
2826 /* If POS specifies a position in a display vector, this might
2827 be for an ellipsis displayed for invisible text. We won't
2828 get the iterator set up for delivering that ellipsis unless
2829 we make sure that it gets aware of the invisible text. */
2830 if (pos
->dpvec_index
>= 0
2831 && pos
->overlay_string_index
< 0
2832 && CHARPOS (pos
->string_pos
) < 0
2834 && (XSETWINDOW (window
, w
),
2835 prop
= Fget_char_property (make_number (charpos
),
2836 Qinvisible
, window
),
2837 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2839 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2841 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2848 /* Initialize IT for stepping through current_buffer in window W,
2849 starting at position POS that includes overlay string and display
2850 vector/ control character translation position information. Value
2851 is zero if there are overlay strings with newlines at POS. */
2854 init_from_display_pos (it
, w
, pos
)
2857 struct display_pos
*pos
;
2859 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2860 int i
, overlay_strings_with_newlines
= 0;
2862 /* If POS specifies a position in a display vector, this might
2863 be for an ellipsis displayed for invisible text. We won't
2864 get the iterator set up for delivering that ellipsis unless
2865 we make sure that it gets aware of the invisible text. */
2866 if (in_ellipses_for_invisible_text_p (pos
, w
))
2872 /* Keep in mind: the call to reseat in init_iterator skips invisible
2873 text, so we might end up at a position different from POS. This
2874 is only a problem when POS is a row start after a newline and an
2875 overlay starts there with an after-string, and the overlay has an
2876 invisible property. Since we don't skip invisible text in
2877 display_line and elsewhere immediately after consuming the
2878 newline before the row start, such a POS will not be in a string,
2879 but the call to init_iterator below will move us to the
2881 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2883 /* This only scans the current chunk -- it should scan all chunks.
2884 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2885 to 16 in 22.1 to make this a lesser problem. */
2886 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2888 const char *s
= SDATA (it
->overlay_strings
[i
]);
2889 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2891 while (s
< e
&& *s
!= '\n')
2896 overlay_strings_with_newlines
= 1;
2901 /* If position is within an overlay string, set up IT to the right
2903 if (pos
->overlay_string_index
>= 0)
2907 /* If the first overlay string happens to have a `display'
2908 property for an image, the iterator will be set up for that
2909 image, and we have to undo that setup first before we can
2910 correct the overlay string index. */
2911 if (it
->method
== GET_FROM_IMAGE
)
2914 /* We already have the first chunk of overlay strings in
2915 IT->overlay_strings. Load more until the one for
2916 pos->overlay_string_index is in IT->overlay_strings. */
2917 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2919 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2920 it
->current
.overlay_string_index
= 0;
2923 load_overlay_strings (it
, 0);
2924 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2928 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2929 relative_index
= (it
->current
.overlay_string_index
2930 % OVERLAY_STRING_CHUNK_SIZE
);
2931 it
->string
= it
->overlay_strings
[relative_index
];
2932 xassert (STRINGP (it
->string
));
2933 it
->current
.string_pos
= pos
->string_pos
;
2934 it
->method
= GET_FROM_STRING
;
2937 #if 0 /* This is bogus because POS not having an overlay string
2938 position does not mean it's after the string. Example: A
2939 line starting with a before-string and initialization of IT
2940 to the previous row's end position. */
2941 else if (it
->current
.overlay_string_index
>= 0)
2943 /* If POS says we're already after an overlay string ending at
2944 POS, make sure to pop the iterator because it will be in
2945 front of that overlay string. When POS is ZV, we've thereby
2946 also ``processed'' overlay strings at ZV. */
2949 xassert (it
->current
.overlay_string_index
== -1);
2950 xassert (it
->method
== GET_FROM_BUFFER
);
2951 if (CHARPOS (pos
->pos
) == ZV
)
2952 it
->overlay_strings_at_end_processed_p
= 1;
2956 if (CHARPOS (pos
->string_pos
) >= 0)
2958 /* Recorded position is not in an overlay string, but in another
2959 string. This can only be a string from a `display' property.
2960 IT should already be filled with that string. */
2961 it
->current
.string_pos
= pos
->string_pos
;
2962 xassert (STRINGP (it
->string
));
2965 /* Restore position in display vector translations, control
2966 character translations or ellipses. */
2967 if (pos
->dpvec_index
>= 0)
2969 if (it
->dpvec
== NULL
)
2970 get_next_display_element (it
);
2971 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2972 it
->current
.dpvec_index
= pos
->dpvec_index
;
2976 return !overlay_strings_with_newlines
;
2980 /* Initialize IT for stepping through current_buffer in window W
2981 starting at ROW->start. */
2984 init_to_row_start (it
, w
, row
)
2987 struct glyph_row
*row
;
2989 init_from_display_pos (it
, w
, &row
->start
);
2990 it
->start
= row
->start
;
2991 it
->continuation_lines_width
= row
->continuation_lines_width
;
2996 /* Initialize IT for stepping through current_buffer in window W
2997 starting in the line following ROW, i.e. starting at ROW->end.
2998 Value is zero if there are overlay strings with newlines at ROW's
3002 init_to_row_end (it
, w
, row
)
3005 struct glyph_row
*row
;
3009 if (init_from_display_pos (it
, w
, &row
->end
))
3011 if (row
->continued_p
)
3012 it
->continuation_lines_width
3013 = row
->continuation_lines_width
+ row
->pixel_width
;
3024 /***********************************************************************
3026 ***********************************************************************/
3028 /* Called when IT reaches IT->stop_charpos. Handle text property and
3029 overlay changes. Set IT->stop_charpos to the next position where
3036 enum prop_handled handled
;
3037 int handle_overlay_change_p
;
3041 it
->current
.dpvec_index
= -1;
3042 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3043 it
->ignore_overlay_strings_at_pos_p
= 0;
3045 /* Use face of preceding text for ellipsis (if invisible) */
3046 if (it
->selective_display_ellipsis_p
)
3047 it
->saved_face_id
= it
->face_id
;
3051 handled
= HANDLED_NORMALLY
;
3053 /* Call text property handlers. */
3054 for (p
= it_props
; p
->handler
; ++p
)
3056 handled
= p
->handler (it
);
3058 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3060 else if (handled
== HANDLED_RETURN
)
3062 /* We still want to show before and after strings from
3063 overlays even if the actual buffer text is replaced. */
3064 if (!handle_overlay_change_p
|| it
->sp
> 1)
3066 if (!get_overlay_strings_1 (it
, 0, 0))
3068 it
->ignore_overlay_strings_at_pos_p
= 1;
3069 it
->string_from_display_prop_p
= 0;
3070 handle_overlay_change_p
= 0;
3071 handled
= HANDLED_RECOMPUTE_PROPS
;
3074 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3075 handle_overlay_change_p
= 0;
3078 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3080 /* Don't check for overlay strings below when set to deliver
3081 characters from a display vector. */
3082 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3083 handle_overlay_change_p
= 0;
3085 /* Handle overlay changes. */
3086 if (handle_overlay_change_p
)
3087 handled
= handle_overlay_change (it
);
3089 /* Determine where to stop next. */
3090 if (handled
== HANDLED_NORMALLY
)
3091 compute_stop_pos (it
);
3094 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3098 /* Compute IT->stop_charpos from text property and overlay change
3099 information for IT's current position. */
3102 compute_stop_pos (it
)
3105 register INTERVAL iv
, next_iv
;
3106 Lisp_Object object
, limit
, position
;
3108 /* If nowhere else, stop at the end. */
3109 it
->stop_charpos
= it
->end_charpos
;
3111 if (STRINGP (it
->string
))
3113 /* Strings are usually short, so don't limit the search for
3115 object
= it
->string
;
3117 position
= make_number (IT_STRING_CHARPOS (*it
));
3123 /* If next overlay change is in front of the current stop pos
3124 (which is IT->end_charpos), stop there. Note: value of
3125 next_overlay_change is point-max if no overlay change
3127 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3128 if (charpos
< it
->stop_charpos
)
3129 it
->stop_charpos
= charpos
;
3131 /* If showing the region, we have to stop at the region
3132 start or end because the face might change there. */
3133 if (it
->region_beg_charpos
> 0)
3135 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3136 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3137 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3138 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3141 /* Set up variables for computing the stop position from text
3142 property changes. */
3143 XSETBUFFER (object
, current_buffer
);
3144 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3145 position
= make_number (IT_CHARPOS (*it
));
3149 /* Get the interval containing IT's position. Value is a null
3150 interval if there isn't such an interval. */
3151 iv
= validate_interval_range (object
, &position
, &position
, 0);
3152 if (!NULL_INTERVAL_P (iv
))
3154 Lisp_Object values_here
[LAST_PROP_IDX
];
3157 /* Get properties here. */
3158 for (p
= it_props
; p
->handler
; ++p
)
3159 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3161 /* Look for an interval following iv that has different
3163 for (next_iv
= next_interval (iv
);
3164 (!NULL_INTERVAL_P (next_iv
)
3166 || XFASTINT (limit
) > next_iv
->position
));
3167 next_iv
= next_interval (next_iv
))
3169 for (p
= it_props
; p
->handler
; ++p
)
3171 Lisp_Object new_value
;
3173 new_value
= textget (next_iv
->plist
, *p
->name
);
3174 if (!EQ (values_here
[p
->idx
], new_value
))
3182 if (!NULL_INTERVAL_P (next_iv
))
3184 if (INTEGERP (limit
)
3185 && next_iv
->position
>= XFASTINT (limit
))
3186 /* No text property change up to limit. */
3187 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3189 /* Text properties change in next_iv. */
3190 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3194 xassert (STRINGP (it
->string
)
3195 || (it
->stop_charpos
>= BEGV
3196 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3200 /* Return the position of the next overlay change after POS in
3201 current_buffer. Value is point-max if no overlay change
3202 follows. This is like `next-overlay-change' but doesn't use
3206 next_overlay_change (pos
)
3211 Lisp_Object
*overlays
;
3214 /* Get all overlays at the given position. */
3215 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3217 /* If any of these overlays ends before endpos,
3218 use its ending point instead. */
3219 for (i
= 0; i
< noverlays
; ++i
)
3224 oend
= OVERLAY_END (overlays
[i
]);
3225 oendpos
= OVERLAY_POSITION (oend
);
3226 endpos
= min (endpos
, oendpos
);
3234 /***********************************************************************
3236 ***********************************************************************/
3238 /* Handle changes in the `fontified' property of the current buffer by
3239 calling hook functions from Qfontification_functions to fontify
3242 static enum prop_handled
3243 handle_fontified_prop (it
)
3246 Lisp_Object prop
, pos
;
3247 enum prop_handled handled
= HANDLED_NORMALLY
;
3249 if (!NILP (Vmemory_full
))
3252 /* Get the value of the `fontified' property at IT's current buffer
3253 position. (The `fontified' property doesn't have a special
3254 meaning in strings.) If the value is nil, call functions from
3255 Qfontification_functions. */
3256 if (!STRINGP (it
->string
)
3258 && !NILP (Vfontification_functions
)
3259 && !NILP (Vrun_hooks
)
3260 && (pos
= make_number (IT_CHARPOS (*it
)),
3261 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3262 /* Ignore the special cased nil value always present at EOB since
3263 no amount of fontifying will be able to change it. */
3264 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3266 int count
= SPECPDL_INDEX ();
3269 val
= Vfontification_functions
;
3270 specbind (Qfontification_functions
, Qnil
);
3272 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3273 safe_call1 (val
, pos
);
3276 Lisp_Object globals
, fn
;
3277 struct gcpro gcpro1
, gcpro2
;
3280 GCPRO2 (val
, globals
);
3282 for (; CONSP (val
); val
= XCDR (val
))
3288 /* A value of t indicates this hook has a local
3289 binding; it means to run the global binding too.
3290 In a global value, t should not occur. If it
3291 does, we must ignore it to avoid an endless
3293 for (globals
= Fdefault_value (Qfontification_functions
);
3295 globals
= XCDR (globals
))
3297 fn
= XCAR (globals
);
3299 safe_call1 (fn
, pos
);
3303 safe_call1 (fn
, pos
);
3309 unbind_to (count
, Qnil
);
3311 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3312 something. This avoids an endless loop if they failed to
3313 fontify the text for which reason ever. */
3314 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3315 handled
= HANDLED_RECOMPUTE_PROPS
;
3323 /***********************************************************************
3325 ***********************************************************************/
3327 /* Set up iterator IT from face properties at its current position.
3328 Called from handle_stop. */
3330 static enum prop_handled
3331 handle_face_prop (it
)
3334 int new_face_id
, next_stop
;
3336 if (!STRINGP (it
->string
))
3339 = face_at_buffer_position (it
->w
,
3341 it
->region_beg_charpos
,
3342 it
->region_end_charpos
,
3345 + TEXT_PROP_DISTANCE_LIMIT
),
3348 /* Is this a start of a run of characters with box face?
3349 Caveat: this can be called for a freshly initialized
3350 iterator; face_id is -1 in this case. We know that the new
3351 face will not change until limit, i.e. if the new face has a
3352 box, all characters up to limit will have one. But, as
3353 usual, we don't know whether limit is really the end. */
3354 if (new_face_id
!= it
->face_id
)
3356 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3358 /* If new face has a box but old face has not, this is
3359 the start of a run of characters with box, i.e. it has
3360 a shadow on the left side. The value of face_id of the
3361 iterator will be -1 if this is the initial call that gets
3362 the face. In this case, we have to look in front of IT's
3363 position and see whether there is a face != new_face_id. */
3364 it
->start_of_box_run_p
3365 = (new_face
->box
!= FACE_NO_BOX
3366 && (it
->face_id
>= 0
3367 || IT_CHARPOS (*it
) == BEG
3368 || new_face_id
!= face_before_it_pos (it
)));
3369 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3374 int base_face_id
, bufpos
;
3376 if (it
->current
.overlay_string_index
>= 0)
3377 bufpos
= IT_CHARPOS (*it
);
3381 /* For strings from a buffer, i.e. overlay strings or strings
3382 from a `display' property, use the face at IT's current
3383 buffer position as the base face to merge with, so that
3384 overlay strings appear in the same face as surrounding
3385 text, unless they specify their own faces. */
3386 base_face_id
= underlying_face_id (it
);
3388 new_face_id
= face_at_string_position (it
->w
,
3390 IT_STRING_CHARPOS (*it
),
3392 it
->region_beg_charpos
,
3393 it
->region_end_charpos
,
3397 #if 0 /* This shouldn't be neccessary. Let's check it. */
3398 /* If IT is used to display a mode line we would really like to
3399 use the mode line face instead of the frame's default face. */
3400 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3401 && new_face_id
== DEFAULT_FACE_ID
)
3402 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3405 /* Is this a start of a run of characters with box? Caveat:
3406 this can be called for a freshly allocated iterator; face_id
3407 is -1 is this case. We know that the new face will not
3408 change until the next check pos, i.e. if the new face has a
3409 box, all characters up to that position will have a
3410 box. But, as usual, we don't know whether that position
3411 is really the end. */
3412 if (new_face_id
!= it
->face_id
)
3414 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3415 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3417 /* If new face has a box but old face hasn't, this is the
3418 start of a run of characters with box, i.e. it has a
3419 shadow on the left side. */
3420 it
->start_of_box_run_p
3421 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3422 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3426 it
->face_id
= new_face_id
;
3427 return HANDLED_NORMALLY
;
3431 /* Return the ID of the face ``underlying'' IT's current position,
3432 which is in a string. If the iterator is associated with a
3433 buffer, return the face at IT's current buffer position.
3434 Otherwise, use the iterator's base_face_id. */
3437 underlying_face_id (it
)
3440 int face_id
= it
->base_face_id
, i
;
3442 xassert (STRINGP (it
->string
));
3444 for (i
= it
->sp
- 1; i
>= 0; --i
)
3445 if (NILP (it
->stack
[i
].string
))
3446 face_id
= it
->stack
[i
].face_id
;
3452 /* Compute the face one character before or after the current position
3453 of IT. BEFORE_P non-zero means get the face in front of IT's
3454 position. Value is the id of the face. */
3457 face_before_or_after_it_pos (it
, before_p
)
3462 int next_check_charpos
;
3463 struct text_pos pos
;
3465 xassert (it
->s
== NULL
);
3467 if (STRINGP (it
->string
))
3469 int bufpos
, base_face_id
;
3471 /* No face change past the end of the string (for the case
3472 we are padding with spaces). No face change before the
3474 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3475 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3478 /* Set pos to the position before or after IT's current position. */
3480 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3482 /* For composition, we must check the character after the
3484 pos
= (it
->what
== IT_COMPOSITION
3485 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3486 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3488 if (it
->current
.overlay_string_index
>= 0)
3489 bufpos
= IT_CHARPOS (*it
);
3493 base_face_id
= underlying_face_id (it
);
3495 /* Get the face for ASCII, or unibyte. */
3496 face_id
= face_at_string_position (it
->w
,
3500 it
->region_beg_charpos
,
3501 it
->region_end_charpos
,
3502 &next_check_charpos
,
3505 /* Correct the face for charsets different from ASCII. Do it
3506 for the multibyte case only. The face returned above is
3507 suitable for unibyte text if IT->string is unibyte. */
3508 if (STRING_MULTIBYTE (it
->string
))
3510 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3511 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3513 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3515 c
= string_char_and_length (p
, rest
, &len
);
3516 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3521 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3522 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3525 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3526 pos
= it
->current
.pos
;
3529 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3532 if (it
->what
== IT_COMPOSITION
)
3533 /* For composition, we must check the position after the
3535 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3537 INC_TEXT_POS (pos
, it
->multibyte_p
);
3540 /* Determine face for CHARSET_ASCII, or unibyte. */
3541 face_id
= face_at_buffer_position (it
->w
,
3543 it
->region_beg_charpos
,
3544 it
->region_end_charpos
,
3545 &next_check_charpos
,
3548 /* Correct the face for charsets different from ASCII. Do it
3549 for the multibyte case only. The face returned above is
3550 suitable for unibyte text if current_buffer is unibyte. */
3551 if (it
->multibyte_p
)
3553 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3554 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3555 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3564 /***********************************************************************
3566 ***********************************************************************/
3568 /* Set up iterator IT from invisible properties at its current
3569 position. Called from handle_stop. */
3571 static enum prop_handled
3572 handle_invisible_prop (it
)
3575 enum prop_handled handled
= HANDLED_NORMALLY
;
3577 if (STRINGP (it
->string
))
3579 extern Lisp_Object Qinvisible
;
3580 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3582 /* Get the value of the invisible text property at the
3583 current position. Value will be nil if there is no such
3585 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3586 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3589 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3591 handled
= HANDLED_RECOMPUTE_PROPS
;
3593 /* Get the position at which the next change of the
3594 invisible text property can be found in IT->string.
3595 Value will be nil if the property value is the same for
3596 all the rest of IT->string. */
3597 XSETINT (limit
, SCHARS (it
->string
));
3598 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3601 /* Text at current position is invisible. The next
3602 change in the property is at position end_charpos.
3603 Move IT's current position to that position. */
3604 if (INTEGERP (end_charpos
)
3605 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3607 struct text_pos old
;
3608 old
= it
->current
.string_pos
;
3609 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3610 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3614 /* The rest of the string is invisible. If this is an
3615 overlay string, proceed with the next overlay string
3616 or whatever comes and return a character from there. */
3617 if (it
->current
.overlay_string_index
>= 0)
3619 next_overlay_string (it
);
3620 /* Don't check for overlay strings when we just
3621 finished processing them. */
3622 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3626 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3627 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3634 int invis_p
, newpos
, next_stop
, start_charpos
;
3635 Lisp_Object pos
, prop
, overlay
;
3637 /* First of all, is there invisible text at this position? */
3638 start_charpos
= IT_CHARPOS (*it
);
3639 pos
= make_number (IT_CHARPOS (*it
));
3640 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3642 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3644 /* If we are on invisible text, skip over it. */
3645 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3647 /* Record whether we have to display an ellipsis for the
3649 int display_ellipsis_p
= invis_p
== 2;
3651 handled
= HANDLED_RECOMPUTE_PROPS
;
3653 /* Loop skipping over invisible text. The loop is left at
3654 ZV or with IT on the first char being visible again. */
3657 /* Try to skip some invisible text. Return value is the
3658 position reached which can be equal to IT's position
3659 if there is nothing invisible here. This skips both
3660 over invisible text properties and overlays with
3661 invisible property. */
3662 newpos
= skip_invisible (IT_CHARPOS (*it
),
3663 &next_stop
, ZV
, it
->window
);
3665 /* If we skipped nothing at all we weren't at invisible
3666 text in the first place. If everything to the end of
3667 the buffer was skipped, end the loop. */
3668 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3672 /* We skipped some characters but not necessarily
3673 all there are. Check if we ended up on visible
3674 text. Fget_char_property returns the property of
3675 the char before the given position, i.e. if we
3676 get invis_p = 0, this means that the char at
3677 newpos is visible. */
3678 pos
= make_number (newpos
);
3679 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3680 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3683 /* If we ended up on invisible text, proceed to
3684 skip starting with next_stop. */
3686 IT_CHARPOS (*it
) = next_stop
;
3688 /* If there are adjacent invisible texts, don't lose the
3689 second one's ellipsis. */
3691 display_ellipsis_p
= 1;
3695 /* The position newpos is now either ZV or on visible text. */
3696 IT_CHARPOS (*it
) = newpos
;
3697 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3699 /* If there are before-strings at the start of invisible
3700 text, and the text is invisible because of a text
3701 property, arrange to show before-strings because 20.x did
3702 it that way. (If the text is invisible because of an
3703 overlay property instead of a text property, this is
3704 already handled in the overlay code.) */
3706 && get_overlay_strings (it
, start_charpos
))
3708 handled
= HANDLED_RECOMPUTE_PROPS
;
3709 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3711 else if (display_ellipsis_p
)
3713 /* Make sure that the glyphs of the ellipsis will get
3714 correct `charpos' values. If we would not update
3715 it->position here, the glyphs would belong to the
3716 last visible character _before_ the invisible
3717 text, which confuses `set_cursor_from_row'.
3719 We use the last invisible position instead of the
3720 first because this way the cursor is always drawn on
3721 the first "." of the ellipsis, whenever PT is inside
3722 the invisible text. Otherwise the cursor would be
3723 placed _after_ the ellipsis when the point is after the
3724 first invisible character. */
3725 if (!STRINGP (it
->object
))
3727 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3728 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3730 setup_for_ellipsis (it
, 0);
3739 /* Make iterator IT return `...' next.
3740 Replaces LEN characters from buffer. */
3743 setup_for_ellipsis (it
, len
)
3747 /* Use the display table definition for `...'. Invalid glyphs
3748 will be handled by the method returning elements from dpvec. */
3749 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3751 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3752 it
->dpvec
= v
->contents
;
3753 it
->dpend
= v
->contents
+ v
->size
;
3757 /* Default `...'. */
3758 it
->dpvec
= default_invis_vector
;
3759 it
->dpend
= default_invis_vector
+ 3;
3762 it
->dpvec_char_len
= len
;
3763 it
->current
.dpvec_index
= 0;
3764 it
->dpvec_face_id
= -1;
3766 /* Remember the current face id in case glyphs specify faces.
3767 IT's face is restored in set_iterator_to_next.
3768 saved_face_id was set to preceding char's face in handle_stop. */
3769 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3770 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3772 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3778 /***********************************************************************
3780 ***********************************************************************/
3782 /* Set up iterator IT from `display' property at its current position.
3783 Called from handle_stop.
3784 We return HANDLED_RETURN if some part of the display property
3785 overrides the display of the buffer text itself.
3786 Otherwise we return HANDLED_NORMALLY. */
3788 static enum prop_handled
3789 handle_display_prop (it
)
3792 Lisp_Object prop
, object
;
3793 struct text_pos
*position
;
3794 /* Nonzero if some property replaces the display of the text itself. */
3795 int display_replaced_p
= 0;
3797 if (STRINGP (it
->string
))
3799 object
= it
->string
;
3800 position
= &it
->current
.string_pos
;
3804 XSETWINDOW (object
, it
->w
);
3805 position
= &it
->current
.pos
;
3808 /* Reset those iterator values set from display property values. */
3809 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3810 it
->space_width
= Qnil
;
3811 it
->font_height
= Qnil
;
3814 /* We don't support recursive `display' properties, i.e. string
3815 values that have a string `display' property, that have a string
3816 `display' property etc. */
3817 if (!it
->string_from_display_prop_p
)
3818 it
->area
= TEXT_AREA
;
3820 prop
= Fget_char_property (make_number (position
->charpos
),
3823 return HANDLED_NORMALLY
;
3825 if (!STRINGP (it
->string
))
3826 object
= it
->w
->buffer
;
3829 /* Simple properties. */
3830 && !EQ (XCAR (prop
), Qimage
)
3831 && !EQ (XCAR (prop
), Qspace
)
3832 && !EQ (XCAR (prop
), Qwhen
)
3833 && !EQ (XCAR (prop
), Qslice
)
3834 && !EQ (XCAR (prop
), Qspace_width
)
3835 && !EQ (XCAR (prop
), Qheight
)
3836 && !EQ (XCAR (prop
), Qraise
)
3837 /* Marginal area specifications. */
3838 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3839 && !EQ (XCAR (prop
), Qleft_fringe
)
3840 && !EQ (XCAR (prop
), Qright_fringe
)
3841 && !NILP (XCAR (prop
)))
3843 for (; CONSP (prop
); prop
= XCDR (prop
))
3845 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3846 position
, display_replaced_p
))
3847 display_replaced_p
= 1;
3850 else if (VECTORP (prop
))
3853 for (i
= 0; i
< ASIZE (prop
); ++i
)
3854 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3855 position
, display_replaced_p
))
3856 display_replaced_p
= 1;
3860 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3861 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3862 return HANDLED_RECOMPUTE_PROPS
;
3864 display_replaced_p
= 1;
3867 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3871 /* Value is the position of the end of the `display' property starting
3872 at START_POS in OBJECT. */
3874 static struct text_pos
3875 display_prop_end (it
, object
, start_pos
)
3878 struct text_pos start_pos
;
3881 struct text_pos end_pos
;
3883 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3884 Qdisplay
, object
, Qnil
);
3885 CHARPOS (end_pos
) = XFASTINT (end
);
3886 if (STRINGP (object
))
3887 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3889 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3895 /* Set up IT from a single `display' specification PROP. OBJECT
3896 is the object in which the `display' property was found. *POSITION
3897 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3898 means that we previously saw a display specification which already
3899 replaced text display with something else, for example an image;
3900 we ignore such properties after the first one has been processed.
3902 If PROP is a `space' or `image' specification, and in some other
3903 cases too, set *POSITION to the position where the `display'
3906 Value is non-zero if something was found which replaces the display
3907 of buffer or string text. Specifically, the value is -1 if that
3908 "something" is "nothing". */
3911 handle_single_display_spec (it
, spec
, object
, position
,
3912 display_replaced_before_p
)
3916 struct text_pos
*position
;
3917 int display_replaced_before_p
;
3920 Lisp_Object location
, value
;
3921 struct text_pos start_pos
, save_pos
;
3924 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3925 If the result is non-nil, use VALUE instead of SPEC. */
3927 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3936 if (!NILP (form
) && !EQ (form
, Qt
))
3938 int count
= SPECPDL_INDEX ();
3939 struct gcpro gcpro1
;
3941 /* Bind `object' to the object having the `display' property, a
3942 buffer or string. Bind `position' to the position in the
3943 object where the property was found, and `buffer-position'
3944 to the current position in the buffer. */
3945 specbind (Qobject
, object
);
3946 specbind (Qposition
, make_number (CHARPOS (*position
)));
3947 specbind (Qbuffer_position
,
3948 make_number (STRINGP (object
)
3949 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3951 form
= safe_eval (form
);
3953 unbind_to (count
, Qnil
);
3959 /* Handle `(height HEIGHT)' specifications. */
3961 && EQ (XCAR (spec
), Qheight
)
3962 && CONSP (XCDR (spec
)))
3964 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3967 it
->font_height
= XCAR (XCDR (spec
));
3968 if (!NILP (it
->font_height
))
3970 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3971 int new_height
= -1;
3973 if (CONSP (it
->font_height
)
3974 && (EQ (XCAR (it
->font_height
), Qplus
)
3975 || EQ (XCAR (it
->font_height
), Qminus
))
3976 && CONSP (XCDR (it
->font_height
))
3977 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3979 /* `(+ N)' or `(- N)' where N is an integer. */
3980 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3981 if (EQ (XCAR (it
->font_height
), Qplus
))
3983 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3985 else if (FUNCTIONP (it
->font_height
))
3987 /* Call function with current height as argument.
3988 Value is the new height. */
3990 height
= safe_call1 (it
->font_height
,
3991 face
->lface
[LFACE_HEIGHT_INDEX
]);
3992 if (NUMBERP (height
))
3993 new_height
= XFLOATINT (height
);
3995 else if (NUMBERP (it
->font_height
))
3997 /* Value is a multiple of the canonical char height. */
4000 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
4001 new_height
= (XFLOATINT (it
->font_height
)
4002 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4006 /* Evaluate IT->font_height with `height' bound to the
4007 current specified height to get the new height. */
4008 int count
= SPECPDL_INDEX ();
4010 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4011 value
= safe_eval (it
->font_height
);
4012 unbind_to (count
, Qnil
);
4014 if (NUMBERP (value
))
4015 new_height
= XFLOATINT (value
);
4019 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4025 /* Handle `(space_width WIDTH)'. */
4027 && EQ (XCAR (spec
), Qspace_width
)
4028 && CONSP (XCDR (spec
)))
4030 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4033 value
= XCAR (XCDR (spec
));
4034 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4035 it
->space_width
= value
;
4040 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4042 && EQ (XCAR (spec
), Qslice
))
4046 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4049 if (tem
= XCDR (spec
), CONSP (tem
))
4051 it
->slice
.x
= XCAR (tem
);
4052 if (tem
= XCDR (tem
), CONSP (tem
))
4054 it
->slice
.y
= XCAR (tem
);
4055 if (tem
= XCDR (tem
), CONSP (tem
))
4057 it
->slice
.width
= XCAR (tem
);
4058 if (tem
= XCDR (tem
), CONSP (tem
))
4059 it
->slice
.height
= XCAR (tem
);
4067 /* Handle `(raise FACTOR)'. */
4069 && EQ (XCAR (spec
), Qraise
)
4070 && CONSP (XCDR (spec
)))
4072 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4075 #ifdef HAVE_WINDOW_SYSTEM
4076 value
= XCAR (XCDR (spec
));
4077 if (NUMBERP (value
))
4079 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4080 it
->voffset
= - (XFLOATINT (value
)
4081 * (FONT_HEIGHT (face
->font
)));
4083 #endif /* HAVE_WINDOW_SYSTEM */
4088 /* Don't handle the other kinds of display specifications
4089 inside a string that we got from a `display' property. */
4090 if (it
->string_from_display_prop_p
)
4093 /* Characters having this form of property are not displayed, so
4094 we have to find the end of the property. */
4095 start_pos
= *position
;
4096 *position
= display_prop_end (it
, object
, start_pos
);
4099 /* Stop the scan at that end position--we assume that all
4100 text properties change there. */
4101 it
->stop_charpos
= position
->charpos
;
4103 /* Handle `(left-fringe BITMAP [FACE])'
4104 and `(right-fringe BITMAP [FACE])'. */
4106 && (EQ (XCAR (spec
), Qleft_fringe
)
4107 || EQ (XCAR (spec
), Qright_fringe
))
4108 && CONSP (XCDR (spec
)))
4110 int face_id
= DEFAULT_FACE_ID
;
4113 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
4114 /* If we return here, POSITION has been advanced
4115 across the text with this property. */
4118 #ifdef HAVE_WINDOW_SYSTEM
4119 value
= XCAR (XCDR (spec
));
4120 if (!SYMBOLP (value
)
4121 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4122 /* If we return here, POSITION has been advanced
4123 across the text with this property. */
4126 if (CONSP (XCDR (XCDR (spec
))))
4128 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4129 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4135 /* Save current settings of IT so that we can restore them
4136 when we are finished with the glyph property value. */
4138 save_pos
= it
->position
;
4139 it
->position
= *position
;
4141 it
->position
= save_pos
;
4143 it
->area
= TEXT_AREA
;
4144 it
->what
= IT_IMAGE
;
4145 it
->image_id
= -1; /* no image */
4146 it
->position
= start_pos
;
4147 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4148 it
->method
= GET_FROM_IMAGE
;
4149 it
->face_id
= face_id
;
4151 /* Say that we haven't consumed the characters with
4152 `display' property yet. The call to pop_it in
4153 set_iterator_to_next will clean this up. */
4154 *position
= start_pos
;
4156 if (EQ (XCAR (spec
), Qleft_fringe
))
4158 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4159 it
->left_user_fringe_face_id
= face_id
;
4163 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4164 it
->right_user_fringe_face_id
= face_id
;
4166 #endif /* HAVE_WINDOW_SYSTEM */
4170 /* Prepare to handle `((margin left-margin) ...)',
4171 `((margin right-margin) ...)' and `((margin nil) ...)'
4172 prefixes for display specifications. */
4173 location
= Qunbound
;
4174 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4178 value
= XCDR (spec
);
4180 value
= XCAR (value
);
4183 if (EQ (XCAR (tem
), Qmargin
)
4184 && (tem
= XCDR (tem
),
4185 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4187 || EQ (tem
, Qleft_margin
)
4188 || EQ (tem
, Qright_margin
))))
4192 if (EQ (location
, Qunbound
))
4198 /* After this point, VALUE is the property after any
4199 margin prefix has been stripped. It must be a string,
4200 an image specification, or `(space ...)'.
4202 LOCATION specifies where to display: `left-margin',
4203 `right-margin' or nil. */
4205 valid_p
= (STRINGP (value
)
4206 #ifdef HAVE_WINDOW_SYSTEM
4207 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
4208 #endif /* not HAVE_WINDOW_SYSTEM */
4209 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4211 if (valid_p
&& !display_replaced_before_p
)
4213 /* Save current settings of IT so that we can restore them
4214 when we are finished with the glyph property value. */
4215 save_pos
= it
->position
;
4216 it
->position
= *position
;
4218 it
->position
= save_pos
;
4220 if (NILP (location
))
4221 it
->area
= TEXT_AREA
;
4222 else if (EQ (location
, Qleft_margin
))
4223 it
->area
= LEFT_MARGIN_AREA
;
4225 it
->area
= RIGHT_MARGIN_AREA
;
4227 if (STRINGP (value
))
4229 if (SCHARS (value
) == 0)
4232 return -1; /* Replaced by "", i.e. nothing. */
4235 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4236 it
->current
.overlay_string_index
= -1;
4237 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4238 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4239 it
->method
= GET_FROM_STRING
;
4240 it
->stop_charpos
= 0;
4241 it
->string_from_display_prop_p
= 1;
4242 /* Say that we haven't consumed the characters with
4243 `display' property yet. The call to pop_it in
4244 set_iterator_to_next will clean this up. */
4245 *position
= start_pos
;
4247 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4249 it
->method
= GET_FROM_STRETCH
;
4251 *position
= it
->position
= start_pos
;
4253 #ifdef HAVE_WINDOW_SYSTEM
4256 it
->what
= IT_IMAGE
;
4257 it
->image_id
= lookup_image (it
->f
, value
);
4258 it
->position
= start_pos
;
4259 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4260 it
->method
= GET_FROM_IMAGE
;
4262 /* Say that we haven't consumed the characters with
4263 `display' property yet. The call to pop_it in
4264 set_iterator_to_next will clean this up. */
4265 *position
= start_pos
;
4267 #endif /* HAVE_WINDOW_SYSTEM */
4272 /* Invalid property or property not supported. Restore
4273 POSITION to what it was before. */
4274 *position
= start_pos
;
4279 /* Check if SPEC is a display specification value whose text should be
4280 treated as intangible. */
4283 single_display_spec_intangible_p (prop
)
4286 /* Skip over `when FORM'. */
4287 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4301 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4302 we don't need to treat text as intangible. */
4303 if (EQ (XCAR (prop
), Qmargin
))
4311 || EQ (XCAR (prop
), Qleft_margin
)
4312 || EQ (XCAR (prop
), Qright_margin
))
4316 return (CONSP (prop
)
4317 && (EQ (XCAR (prop
), Qimage
)
4318 || EQ (XCAR (prop
), Qspace
)));
4322 /* Check if PROP is a display property value whose text should be
4323 treated as intangible. */
4326 display_prop_intangible_p (prop
)
4330 && CONSP (XCAR (prop
))
4331 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4333 /* A list of sub-properties. */
4334 while (CONSP (prop
))
4336 if (single_display_spec_intangible_p (XCAR (prop
)))
4341 else if (VECTORP (prop
))
4343 /* A vector of sub-properties. */
4345 for (i
= 0; i
< ASIZE (prop
); ++i
)
4346 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4350 return single_display_spec_intangible_p (prop
);
4356 /* Return 1 if PROP is a display sub-property value containing STRING. */
4359 single_display_spec_string_p (prop
, string
)
4360 Lisp_Object prop
, string
;
4362 if (EQ (string
, prop
))
4365 /* Skip over `when FORM'. */
4366 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4375 /* Skip over `margin LOCATION'. */
4376 if (EQ (XCAR (prop
), Qmargin
))
4387 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4391 /* Return 1 if STRING appears in the `display' property PROP. */
4394 display_prop_string_p (prop
, string
)
4395 Lisp_Object prop
, string
;
4398 && CONSP (XCAR (prop
))
4399 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4401 /* A list of sub-properties. */
4402 while (CONSP (prop
))
4404 if (single_display_spec_string_p (XCAR (prop
), string
))
4409 else if (VECTORP (prop
))
4411 /* A vector of sub-properties. */
4413 for (i
= 0; i
< ASIZE (prop
); ++i
)
4414 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4418 return single_display_spec_string_p (prop
, string
);
4424 /* Determine from which buffer position in W's buffer STRING comes
4425 from. AROUND_CHARPOS is an approximate position where it could
4426 be from. Value is the buffer position or 0 if it couldn't be
4429 W's buffer must be current.
4431 This function is necessary because we don't record buffer positions
4432 in glyphs generated from strings (to keep struct glyph small).
4433 This function may only use code that doesn't eval because it is
4434 called asynchronously from note_mouse_highlight. */
4437 string_buffer_position (w
, string
, around_charpos
)
4442 Lisp_Object limit
, prop
, pos
;
4443 const int MAX_DISTANCE
= 1000;
4446 pos
= make_number (around_charpos
);
4447 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4448 while (!found
&& !EQ (pos
, limit
))
4450 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4451 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4454 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4459 pos
= make_number (around_charpos
);
4460 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4461 while (!found
&& !EQ (pos
, limit
))
4463 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4464 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4467 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4472 return found
? XINT (pos
) : 0;
4477 /***********************************************************************
4478 `composition' property
4479 ***********************************************************************/
4481 static enum prop_handled
4482 handle_auto_composed_prop (it
)
4485 enum prop_handled handled
= HANDLED_NORMALLY
;
4487 if (FUNCTIONP (Vauto_composition_function
))
4490 EMACS_INT pos
, this_pos
;
4492 if (STRINGP (it
->string
))
4493 pos
= IT_STRING_CHARPOS (*it
);
4495 pos
= IT_CHARPOS (*it
);
4498 val
=Fget_char_property (make_number (pos
), Qauto_composed
, it
->string
);
4501 Lisp_Object limit
= Qnil
, next
;
4503 /* As Fnext_single_char_property_change is very slow, we
4504 limit the search to the current line. */
4505 if (STRINGP (it
->string
))
4506 limit
= make_number (SCHARS (it
->string
));
4508 limit
= make_number (find_next_newline_no_quit (pos
, 1));
4510 next
= (Fnext_single_property_change
4511 (make_number (pos
), Qauto_composed
, it
->string
, limit
));
4512 if (XINT (next
) < XINT (limit
))
4514 /* The current point is auto-composed, but there exist
4515 characters not yet composed beyond the auto-composed
4516 region. There's a possiblity that the last
4517 characters in the region may be newly composed. */
4518 int charpos
= XINT (next
) - 1, bytepos
, c
;
4520 if (STRINGP (it
->string
))
4522 bytepos
= string_char_to_byte (it
->string
, charpos
);
4523 c
= SDATA (it
->string
)[bytepos
];
4527 bytepos
= CHAR_TO_BYTE (charpos
);
4528 c
= FETCH_BYTE (bytepos
);
4531 /* If the last character is not newline, it may be
4532 composed with the following characters. */
4533 val
= Qnil
, pos
= charpos
+ 1;
4538 int count
= SPECPDL_INDEX ();
4539 Lisp_Object args
[4];
4541 args
[0] = Vauto_composition_function
;
4542 specbind (Qauto_composition_function
, Qnil
);
4543 args
[1] = make_number (pos
);
4544 args
[2] = it
->string
;
4545 #ifdef USE_FONT_BACKEND
4546 if (enable_font_backend
)
4548 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4551 if (STRINGP (it
->string
))
4553 EMACS_INT pos_byte
= IT_STRING_BYTEPOS (*it
);
4554 const unsigned char *s
= SDATA (it
->string
) + pos_byte
;
4556 if (STRING_MULTIBYTE (it
->string
))
4557 it
->c
= STRING_CHAR (s
, 0);
4563 EMACS_INT pos_byte
= IT_BYTEPOS (*it
);
4565 it
->c
= FETCH_CHAR (pos_byte
);
4567 args
[3] = font_at (it
->c
, this_pos
, face
, it
->w
, it
->string
);
4570 #endif /* USE_FONT_BACKEND */
4572 safe_call (4, args
);
4573 unbind_to (count
, Qnil
);
4575 if (this_pos
== pos
)
4577 val
= Fget_char_property (args
[1], Qauto_composed
, it
->string
);
4578 /* Return HANDLED_RECOMPUTE_PROPS only if function composed
4579 something. This avoids an endless loop if they failed to
4580 fontify the text for which reason ever. */
4582 handled
= HANDLED_RECOMPUTE_PROPS
;
4585 handled
= HANDLED_RECOMPUTE_PROPS
;
4592 /* Set up iterator IT from `composition' property at its current
4593 position. Called from handle_stop. */
4595 static enum prop_handled
4596 handle_composition_prop (it
)
4599 Lisp_Object prop
, string
;
4600 EMACS_INT pos
, pos_byte
, start
, end
;
4601 enum prop_handled handled
= HANDLED_NORMALLY
;
4603 if (STRINGP (it
->string
))
4605 pos
= IT_STRING_CHARPOS (*it
);
4606 pos_byte
= IT_STRING_BYTEPOS (*it
);
4607 string
= it
->string
;
4611 pos
= IT_CHARPOS (*it
);
4612 pos_byte
= IT_BYTEPOS (*it
);
4616 /* If there's a valid composition and point is not inside of the
4617 composition (in the case that the composition is from the current
4618 buffer), draw a glyph composed from the composition components. */
4619 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4620 && COMPOSITION_VALID_P (start
, end
, prop
)
4621 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4627 if (STRINGP (it
->string
))
4628 pos_byte
= string_char_to_byte (it
->string
, start
);
4630 pos_byte
= CHAR_TO_BYTE (start
);
4632 id
= get_composition_id (start
, pos_byte
, end
- start
, prop
, string
);
4636 struct composition
*cmp
= composition_table
[id
];
4638 if (cmp
->glyph_len
== 0)
4641 if (STRINGP (it
->string
))
4643 IT_STRING_CHARPOS (*it
) = end
;
4644 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4649 IT_CHARPOS (*it
) = end
;
4650 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4652 return HANDLED_RECOMPUTE_PROPS
;
4655 it
->stop_charpos
= end
;
4658 it
->method
= GET_FROM_COMPOSITION
;
4660 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4661 /* For a terminal, draw only the first (non-TAB) character
4662 of the components. */
4663 #ifdef USE_FONT_BACKEND
4664 if (composition_table
[id
]->method
== COMPOSITION_WITH_GLYPH_STRING
)
4666 Lisp_Object lgstring
= AREF (XHASH_TABLE (composition_hash_table
)
4668 cmp
->hash_index
* 2);
4670 it
->c
= XINT (LGLYPH_CHAR (LGSTRING_GLYPH (lgstring
, 0)));
4673 #endif /* USE_FONT_BACKEND */
4677 for (i
= 0; i
< cmp
->glyph_len
; i
++)
4678 if ((it
->c
= COMPOSITION_GLYPH (composition_table
[id
], i
))
4684 it
->len
= (STRINGP (it
->string
)
4685 ? string_char_to_byte (it
->string
, end
)
4686 : CHAR_TO_BYTE (end
)) - pos_byte
;
4687 handled
= HANDLED_RETURN
;
4696 /***********************************************************************
4698 ***********************************************************************/
4700 /* The following structure is used to record overlay strings for
4701 later sorting in load_overlay_strings. */
4703 struct overlay_entry
4705 Lisp_Object overlay
;
4712 /* Set up iterator IT from overlay strings at its current position.
4713 Called from handle_stop. */
4715 static enum prop_handled
4716 handle_overlay_change (it
)
4719 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4720 return HANDLED_RECOMPUTE_PROPS
;
4722 return HANDLED_NORMALLY
;
4726 /* Set up the next overlay string for delivery by IT, if there is an
4727 overlay string to deliver. Called by set_iterator_to_next when the
4728 end of the current overlay string is reached. If there are more
4729 overlay strings to display, IT->string and
4730 IT->current.overlay_string_index are set appropriately here.
4731 Otherwise IT->string is set to nil. */
4734 next_overlay_string (it
)
4737 ++it
->current
.overlay_string_index
;
4738 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4740 /* No more overlay strings. Restore IT's settings to what
4741 they were before overlay strings were processed, and
4742 continue to deliver from current_buffer. */
4743 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4747 || it
->method
== GET_FROM_COMPOSITION
4748 || (NILP (it
->string
)
4749 && it
->method
== GET_FROM_BUFFER
4750 && it
->stop_charpos
>= BEGV
4751 && it
->stop_charpos
<= it
->end_charpos
));
4752 it
->current
.overlay_string_index
= -1;
4753 it
->n_overlay_strings
= 0;
4755 /* If we're at the end of the buffer, record that we have
4756 processed the overlay strings there already, so that
4757 next_element_from_buffer doesn't try it again. */
4758 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4759 it
->overlay_strings_at_end_processed_p
= 1;
4761 /* If we have to display `...' for invisible text, set
4762 the iterator up for that. */
4763 if (display_ellipsis_p
)
4764 setup_for_ellipsis (it
, 0);
4768 /* There are more overlay strings to process. If
4769 IT->current.overlay_string_index has advanced to a position
4770 where we must load IT->overlay_strings with more strings, do
4772 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4774 if (it
->current
.overlay_string_index
&& i
== 0)
4775 load_overlay_strings (it
, 0);
4777 /* Initialize IT to deliver display elements from the overlay
4779 it
->string
= it
->overlay_strings
[i
];
4780 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4781 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4782 it
->method
= GET_FROM_STRING
;
4783 it
->stop_charpos
= 0;
4790 /* Compare two overlay_entry structures E1 and E2. Used as a
4791 comparison function for qsort in load_overlay_strings. Overlay
4792 strings for the same position are sorted so that
4794 1. All after-strings come in front of before-strings, except
4795 when they come from the same overlay.
4797 2. Within after-strings, strings are sorted so that overlay strings
4798 from overlays with higher priorities come first.
4800 2. Within before-strings, strings are sorted so that overlay
4801 strings from overlays with higher priorities come last.
4803 Value is analogous to strcmp. */
4807 compare_overlay_entries (e1
, e2
)
4810 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4811 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4814 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4816 /* Let after-strings appear in front of before-strings if
4817 they come from different overlays. */
4818 if (EQ (entry1
->overlay
, entry2
->overlay
))
4819 result
= entry1
->after_string_p
? 1 : -1;
4821 result
= entry1
->after_string_p
? -1 : 1;
4823 else if (entry1
->after_string_p
)
4824 /* After-strings sorted in order of decreasing priority. */
4825 result
= entry2
->priority
- entry1
->priority
;
4827 /* Before-strings sorted in order of increasing priority. */
4828 result
= entry1
->priority
- entry2
->priority
;
4834 /* Load the vector IT->overlay_strings with overlay strings from IT's
4835 current buffer position, or from CHARPOS if that is > 0. Set
4836 IT->n_overlays to the total number of overlay strings found.
4838 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4839 a time. On entry into load_overlay_strings,
4840 IT->current.overlay_string_index gives the number of overlay
4841 strings that have already been loaded by previous calls to this
4844 IT->add_overlay_start contains an additional overlay start
4845 position to consider for taking overlay strings from, if non-zero.
4846 This position comes into play when the overlay has an `invisible'
4847 property, and both before and after-strings. When we've skipped to
4848 the end of the overlay, because of its `invisible' property, we
4849 nevertheless want its before-string to appear.
4850 IT->add_overlay_start will contain the overlay start position
4853 Overlay strings are sorted so that after-string strings come in
4854 front of before-string strings. Within before and after-strings,
4855 strings are sorted by overlay priority. See also function
4856 compare_overlay_entries. */
4859 load_overlay_strings (it
, charpos
)
4863 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4864 Lisp_Object overlay
, window
, str
, invisible
;
4865 struct Lisp_Overlay
*ov
;
4868 int n
= 0, i
, j
, invis_p
;
4869 struct overlay_entry
*entries
4870 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4873 charpos
= IT_CHARPOS (*it
);
4875 /* Append the overlay string STRING of overlay OVERLAY to vector
4876 `entries' which has size `size' and currently contains `n'
4877 elements. AFTER_P non-zero means STRING is an after-string of
4879 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4882 Lisp_Object priority; \
4886 int new_size = 2 * size; \
4887 struct overlay_entry *old = entries; \
4889 (struct overlay_entry *) alloca (new_size \
4890 * sizeof *entries); \
4891 bcopy (old, entries, size * sizeof *entries); \
4895 entries[n].string = (STRING); \
4896 entries[n].overlay = (OVERLAY); \
4897 priority = Foverlay_get ((OVERLAY), Qpriority); \
4898 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4899 entries[n].after_string_p = (AFTER_P); \
4904 /* Process overlay before the overlay center. */
4905 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4907 XSETMISC (overlay
, ov
);
4908 xassert (OVERLAYP (overlay
));
4909 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4910 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4915 /* Skip this overlay if it doesn't start or end at IT's current
4917 if (end
!= charpos
&& start
!= charpos
)
4920 /* Skip this overlay if it doesn't apply to IT->w. */
4921 window
= Foverlay_get (overlay
, Qwindow
);
4922 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4925 /* If the text ``under'' the overlay is invisible, both before-
4926 and after-strings from this overlay are visible; start and
4927 end position are indistinguishable. */
4928 invisible
= Foverlay_get (overlay
, Qinvisible
);
4929 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4931 /* If overlay has a non-empty before-string, record it. */
4932 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4933 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4935 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4937 /* If overlay has a non-empty after-string, record it. */
4938 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4939 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4941 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4944 /* Process overlays after the overlay center. */
4945 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4947 XSETMISC (overlay
, ov
);
4948 xassert (OVERLAYP (overlay
));
4949 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4950 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4952 if (start
> charpos
)
4955 /* Skip this overlay if it doesn't start or end at IT's current
4957 if (end
!= charpos
&& start
!= charpos
)
4960 /* Skip this overlay if it doesn't apply to IT->w. */
4961 window
= Foverlay_get (overlay
, Qwindow
);
4962 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4965 /* If the text ``under'' the overlay is invisible, it has a zero
4966 dimension, and both before- and after-strings apply. */
4967 invisible
= Foverlay_get (overlay
, Qinvisible
);
4968 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4970 /* If overlay has a non-empty before-string, record it. */
4971 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4972 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4974 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4976 /* If overlay has a non-empty after-string, record it. */
4977 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4978 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4980 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4983 #undef RECORD_OVERLAY_STRING
4987 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4989 /* Record the total number of strings to process. */
4990 it
->n_overlay_strings
= n
;
4992 /* IT->current.overlay_string_index is the number of overlay strings
4993 that have already been consumed by IT. Copy some of the
4994 remaining overlay strings to IT->overlay_strings. */
4996 j
= it
->current
.overlay_string_index
;
4997 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4998 it
->overlay_strings
[i
++] = entries
[j
++].string
;
5004 /* Get the first chunk of overlay strings at IT's current buffer
5005 position, or at CHARPOS if that is > 0. Value is non-zero if at
5006 least one overlay string was found. */
5009 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5013 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5014 process. This fills IT->overlay_strings with strings, and sets
5015 IT->n_overlay_strings to the total number of strings to process.
5016 IT->pos.overlay_string_index has to be set temporarily to zero
5017 because load_overlay_strings needs this; it must be set to -1
5018 when no overlay strings are found because a zero value would
5019 indicate a position in the first overlay string. */
5020 it
->current
.overlay_string_index
= 0;
5021 load_overlay_strings (it
, charpos
);
5023 /* If we found overlay strings, set up IT to deliver display
5024 elements from the first one. Otherwise set up IT to deliver
5025 from current_buffer. */
5026 if (it
->n_overlay_strings
)
5028 /* Make sure we know settings in current_buffer, so that we can
5029 restore meaningful values when we're done with the overlay
5032 compute_stop_pos (it
);
5033 xassert (it
->face_id
>= 0);
5035 /* Save IT's settings. They are restored after all overlay
5036 strings have been processed. */
5037 xassert (!compute_stop_p
|| it
->sp
== 0);
5040 /* Set up IT to deliver display elements from the first overlay
5042 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5043 it
->string
= it
->overlay_strings
[0];
5044 it
->stop_charpos
= 0;
5045 xassert (STRINGP (it
->string
));
5046 it
->end_charpos
= SCHARS (it
->string
);
5047 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5048 it
->method
= GET_FROM_STRING
;
5052 it
->current
.overlay_string_index
= -1;
5057 get_overlay_strings (it
, charpos
)
5062 it
->method
= GET_FROM_BUFFER
;
5064 (void) get_overlay_strings_1 (it
, charpos
, 1);
5068 /* Value is non-zero if we found at least one overlay string. */
5069 return STRINGP (it
->string
);
5074 /***********************************************************************
5075 Saving and restoring state
5076 ***********************************************************************/
5078 /* Save current settings of IT on IT->stack. Called, for example,
5079 before setting up IT for an overlay string, to be able to restore
5080 IT's settings to what they were after the overlay string has been
5087 struct iterator_stack_entry
*p
;
5089 xassert (it
->sp
< IT_STACK_SIZE
);
5090 p
= it
->stack
+ it
->sp
;
5092 p
->stop_charpos
= it
->stop_charpos
;
5093 xassert (it
->face_id
>= 0);
5094 p
->face_id
= it
->face_id
;
5095 p
->string
= it
->string
;
5096 p
->method
= it
->method
;
5099 case GET_FROM_IMAGE
:
5100 p
->u
.image
.object
= it
->object
;
5101 p
->u
.image
.image_id
= it
->image_id
;
5102 p
->u
.image
.slice
= it
->slice
;
5104 case GET_FROM_COMPOSITION
:
5105 p
->u
.comp
.object
= it
->object
;
5106 p
->u
.comp
.c
= it
->c
;
5107 p
->u
.comp
.len
= it
->len
;
5108 p
->u
.comp
.cmp_id
= it
->cmp_id
;
5109 p
->u
.comp
.cmp_len
= it
->cmp_len
;
5111 case GET_FROM_STRETCH
:
5112 p
->u
.stretch
.object
= it
->object
;
5115 p
->position
= it
->position
;
5116 p
->current
= it
->current
;
5117 p
->end_charpos
= it
->end_charpos
;
5118 p
->string_nchars
= it
->string_nchars
;
5120 p
->multibyte_p
= it
->multibyte_p
;
5121 p
->space_width
= it
->space_width
;
5122 p
->font_height
= it
->font_height
;
5123 p
->voffset
= it
->voffset
;
5124 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5125 p
->display_ellipsis_p
= 0;
5130 /* Restore IT's settings from IT->stack. Called, for example, when no
5131 more overlay strings must be processed, and we return to delivering
5132 display elements from a buffer, or when the end of a string from a
5133 `display' property is reached and we return to delivering display
5134 elements from an overlay string, or from a buffer. */
5140 struct iterator_stack_entry
*p
;
5142 xassert (it
->sp
> 0);
5144 p
= it
->stack
+ it
->sp
;
5145 it
->stop_charpos
= p
->stop_charpos
;
5146 it
->face_id
= p
->face_id
;
5147 it
->current
= p
->current
;
5148 it
->position
= p
->position
;
5149 it
->string
= p
->string
;
5150 if (NILP (it
->string
))
5151 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5152 it
->method
= p
->method
;
5155 case GET_FROM_IMAGE
:
5156 it
->image_id
= p
->u
.image
.image_id
;
5157 it
->object
= p
->u
.image
.object
;
5158 it
->slice
= p
->u
.image
.slice
;
5160 case GET_FROM_COMPOSITION
:
5161 it
->object
= p
->u
.comp
.object
;
5162 it
->c
= p
->u
.comp
.c
;
5163 it
->len
= p
->u
.comp
.len
;
5164 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5165 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5167 case GET_FROM_STRETCH
:
5168 it
->object
= p
->u
.comp
.object
;
5170 case GET_FROM_BUFFER
:
5171 it
->object
= it
->w
->buffer
;
5173 case GET_FROM_STRING
:
5174 it
->object
= it
->string
;
5177 it
->end_charpos
= p
->end_charpos
;
5178 it
->string_nchars
= p
->string_nchars
;
5180 it
->multibyte_p
= p
->multibyte_p
;
5181 it
->space_width
= p
->space_width
;
5182 it
->font_height
= p
->font_height
;
5183 it
->voffset
= p
->voffset
;
5184 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5189 /***********************************************************************
5191 ***********************************************************************/
5193 /* Set IT's current position to the previous line start. */
5196 back_to_previous_line_start (it
)
5199 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5200 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5204 /* Move IT to the next line start.
5206 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5207 we skipped over part of the text (as opposed to moving the iterator
5208 continuously over the text). Otherwise, don't change the value
5211 Newlines may come from buffer text, overlay strings, or strings
5212 displayed via the `display' property. That's the reason we can't
5213 simply use find_next_newline_no_quit.
5215 Note that this function may not skip over invisible text that is so
5216 because of text properties and immediately follows a newline. If
5217 it would, function reseat_at_next_visible_line_start, when called
5218 from set_iterator_to_next, would effectively make invisible
5219 characters following a newline part of the wrong glyph row, which
5220 leads to wrong cursor motion. */
5223 forward_to_next_line_start (it
, skipped_p
)
5227 int old_selective
, newline_found_p
, n
;
5228 const int MAX_NEWLINE_DISTANCE
= 500;
5230 /* If already on a newline, just consume it to avoid unintended
5231 skipping over invisible text below. */
5232 if (it
->what
== IT_CHARACTER
5234 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5236 set_iterator_to_next (it
, 0);
5241 /* Don't handle selective display in the following. It's (a)
5242 unnecessary because it's done by the caller, and (b) leads to an
5243 infinite recursion because next_element_from_ellipsis indirectly
5244 calls this function. */
5245 old_selective
= it
->selective
;
5248 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5249 from buffer text. */
5250 for (n
= newline_found_p
= 0;
5251 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5252 n
+= STRINGP (it
->string
) ? 0 : 1)
5254 if (!get_next_display_element (it
))
5256 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5257 set_iterator_to_next (it
, 0);
5260 /* If we didn't find a newline near enough, see if we can use a
5262 if (!newline_found_p
)
5264 int start
= IT_CHARPOS (*it
);
5265 int limit
= find_next_newline_no_quit (start
, 1);
5268 xassert (!STRINGP (it
->string
));
5270 /* If there isn't any `display' property in sight, and no
5271 overlays, we can just use the position of the newline in
5273 if (it
->stop_charpos
>= limit
5274 || ((pos
= Fnext_single_property_change (make_number (start
),
5276 Qnil
, make_number (limit
)),
5278 && next_overlay_change (start
) == ZV
))
5280 IT_CHARPOS (*it
) = limit
;
5281 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5282 *skipped_p
= newline_found_p
= 1;
5286 while (get_next_display_element (it
)
5287 && !newline_found_p
)
5289 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5290 set_iterator_to_next (it
, 0);
5295 it
->selective
= old_selective
;
5296 return newline_found_p
;
5300 /* Set IT's current position to the previous visible line start. Skip
5301 invisible text that is so either due to text properties or due to
5302 selective display. Caution: this does not change IT->current_x and
5306 back_to_previous_visible_line_start (it
)
5309 while (IT_CHARPOS (*it
) > BEGV
)
5311 back_to_previous_line_start (it
);
5313 if (IT_CHARPOS (*it
) <= BEGV
)
5316 /* If selective > 0, then lines indented more than that values
5318 if (it
->selective
> 0
5319 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5320 (double) it
->selective
)) /* iftc */
5323 /* Check the newline before point for invisibility. */
5326 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5327 Qinvisible
, it
->window
);
5328 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5332 if (IT_CHARPOS (*it
) <= BEGV
)
5339 Lisp_Object val
, overlay
;
5341 /* If newline is part of a composition, continue from start of composition */
5342 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5343 && beg
< IT_CHARPOS (*it
))
5346 /* If newline is replaced by a display property, find start of overlay
5347 or interval and continue search from that point. */
5349 pos
= --IT_CHARPOS (it2
);
5352 if (handle_display_prop (&it2
) == HANDLED_RETURN
5353 && !NILP (val
= get_char_property_and_overlay
5354 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5355 && (OVERLAYP (overlay
)
5356 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5357 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5360 /* Newline is not replaced by anything -- so we are done. */
5366 IT_CHARPOS (*it
) = beg
;
5367 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5371 it
->continuation_lines_width
= 0;
5373 xassert (IT_CHARPOS (*it
) >= BEGV
);
5374 xassert (IT_CHARPOS (*it
) == BEGV
5375 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5380 /* Reseat iterator IT at the previous visible line start. Skip
5381 invisible text that is so either due to text properties or due to
5382 selective display. At the end, update IT's overlay information,
5383 face information etc. */
5386 reseat_at_previous_visible_line_start (it
)
5389 back_to_previous_visible_line_start (it
);
5390 reseat (it
, it
->current
.pos
, 1);
5395 /* Reseat iterator IT on the next visible line start in the current
5396 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5397 preceding the line start. Skip over invisible text that is so
5398 because of selective display. Compute faces, overlays etc at the
5399 new position. Note that this function does not skip over text that
5400 is invisible because of text properties. */
5403 reseat_at_next_visible_line_start (it
, on_newline_p
)
5407 int newline_found_p
, skipped_p
= 0;
5409 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5411 /* Skip over lines that are invisible because they are indented
5412 more than the value of IT->selective. */
5413 if (it
->selective
> 0)
5414 while (IT_CHARPOS (*it
) < ZV
5415 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5416 (double) it
->selective
)) /* iftc */
5418 xassert (IT_BYTEPOS (*it
) == BEGV
5419 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5420 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5423 /* Position on the newline if that's what's requested. */
5424 if (on_newline_p
&& newline_found_p
)
5426 if (STRINGP (it
->string
))
5428 if (IT_STRING_CHARPOS (*it
) > 0)
5430 --IT_STRING_CHARPOS (*it
);
5431 --IT_STRING_BYTEPOS (*it
);
5434 else if (IT_CHARPOS (*it
) > BEGV
)
5438 reseat (it
, it
->current
.pos
, 0);
5442 reseat (it
, it
->current
.pos
, 0);
5449 /***********************************************************************
5450 Changing an iterator's position
5451 ***********************************************************************/
5453 /* Change IT's current position to POS in current_buffer. If FORCE_P
5454 is non-zero, always check for text properties at the new position.
5455 Otherwise, text properties are only looked up if POS >=
5456 IT->check_charpos of a property. */
5459 reseat (it
, pos
, force_p
)
5461 struct text_pos pos
;
5464 int original_pos
= IT_CHARPOS (*it
);
5466 reseat_1 (it
, pos
, 0);
5468 /* Determine where to check text properties. Avoid doing it
5469 where possible because text property lookup is very expensive. */
5471 || CHARPOS (pos
) > it
->stop_charpos
5472 || CHARPOS (pos
) < original_pos
)
5479 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5480 IT->stop_pos to POS, also. */
5483 reseat_1 (it
, pos
, set_stop_p
)
5485 struct text_pos pos
;
5488 /* Don't call this function when scanning a C string. */
5489 xassert (it
->s
== NULL
);
5491 /* POS must be a reasonable value. */
5492 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5494 it
->current
.pos
= it
->position
= pos
;
5495 it
->end_charpos
= ZV
;
5497 it
->current
.dpvec_index
= -1;
5498 it
->current
.overlay_string_index
= -1;
5499 IT_STRING_CHARPOS (*it
) = -1;
5500 IT_STRING_BYTEPOS (*it
) = -1;
5502 it
->method
= GET_FROM_BUFFER
;
5503 it
->object
= it
->w
->buffer
;
5504 it
->area
= TEXT_AREA
;
5505 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5507 it
->string_from_display_prop_p
= 0;
5508 it
->face_before_selective_p
= 0;
5511 it
->stop_charpos
= CHARPOS (pos
);
5515 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5516 If S is non-null, it is a C string to iterate over. Otherwise,
5517 STRING gives a Lisp string to iterate over.
5519 If PRECISION > 0, don't return more then PRECISION number of
5520 characters from the string.
5522 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5523 characters have been returned. FIELD_WIDTH < 0 means an infinite
5526 MULTIBYTE = 0 means disable processing of multibyte characters,
5527 MULTIBYTE > 0 means enable it,
5528 MULTIBYTE < 0 means use IT->multibyte_p.
5530 IT must be initialized via a prior call to init_iterator before
5531 calling this function. */
5534 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5539 int precision
, field_width
, multibyte
;
5541 /* No region in strings. */
5542 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5544 /* No text property checks performed by default, but see below. */
5545 it
->stop_charpos
= -1;
5547 /* Set iterator position and end position. */
5548 bzero (&it
->current
, sizeof it
->current
);
5549 it
->current
.overlay_string_index
= -1;
5550 it
->current
.dpvec_index
= -1;
5551 xassert (charpos
>= 0);
5553 /* If STRING is specified, use its multibyteness, otherwise use the
5554 setting of MULTIBYTE, if specified. */
5556 it
->multibyte_p
= multibyte
> 0;
5560 xassert (STRINGP (string
));
5561 it
->string
= string
;
5563 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5564 it
->method
= GET_FROM_STRING
;
5565 it
->current
.string_pos
= string_pos (charpos
, string
);
5572 /* Note that we use IT->current.pos, not it->current.string_pos,
5573 for displaying C strings. */
5574 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5575 if (it
->multibyte_p
)
5577 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5578 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5582 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5583 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5586 it
->method
= GET_FROM_C_STRING
;
5589 /* PRECISION > 0 means don't return more than PRECISION characters
5591 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5592 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5594 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5595 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5596 FIELD_WIDTH < 0 means infinite field width. This is useful for
5597 padding with `-' at the end of a mode line. */
5598 if (field_width
< 0)
5599 field_width
= INFINITY
;
5600 if (field_width
> it
->end_charpos
- charpos
)
5601 it
->end_charpos
= charpos
+ field_width
;
5603 /* Use the standard display table for displaying strings. */
5604 if (DISP_TABLE_P (Vstandard_display_table
))
5605 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5607 it
->stop_charpos
= charpos
;
5613 /***********************************************************************
5615 ***********************************************************************/
5617 /* Map enum it_method value to corresponding next_element_from_* function. */
5619 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5621 next_element_from_buffer
,
5622 next_element_from_display_vector
,
5623 next_element_from_composition
,
5624 next_element_from_string
,
5625 next_element_from_c_string
,
5626 next_element_from_image
,
5627 next_element_from_stretch
5631 /* Load IT's display element fields with information about the next
5632 display element from the current position of IT. Value is zero if
5633 end of buffer (or C string) is reached. */
5635 static struct frame
*last_escape_glyph_frame
= NULL
;
5636 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5637 static int last_escape_glyph_merged_face_id
= 0;
5640 get_next_display_element (it
)
5643 /* Non-zero means that we found a display element. Zero means that
5644 we hit the end of what we iterate over. Performance note: the
5645 function pointer `method' used here turns out to be faster than
5646 using a sequence of if-statements. */
5650 success_p
= (*get_next_element
[it
->method
]) (it
);
5652 if (it
->what
== IT_CHARACTER
)
5654 /* Map via display table or translate control characters.
5655 IT->c, IT->len etc. have been set to the next character by
5656 the function call above. If we have a display table, and it
5657 contains an entry for IT->c, translate it. Don't do this if
5658 IT->c itself comes from a display table, otherwise we could
5659 end up in an infinite recursion. (An alternative could be to
5660 count the recursion depth of this function and signal an
5661 error when a certain maximum depth is reached.) Is it worth
5663 if (success_p
&& it
->dpvec
== NULL
)
5668 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5671 struct Lisp_Vector
*v
= XVECTOR (dv
);
5673 /* Return the first character from the display table
5674 entry, if not empty. If empty, don't display the
5675 current character. */
5678 it
->dpvec_char_len
= it
->len
;
5679 it
->dpvec
= v
->contents
;
5680 it
->dpend
= v
->contents
+ v
->size
;
5681 it
->current
.dpvec_index
= 0;
5682 it
->dpvec_face_id
= -1;
5683 it
->saved_face_id
= it
->face_id
;
5684 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5689 set_iterator_to_next (it
, 0);
5694 /* Translate control characters into `\003' or `^C' form.
5695 Control characters coming from a display table entry are
5696 currently not translated because we use IT->dpvec to hold
5697 the translation. This could easily be changed but I
5698 don't believe that it is worth doing.
5700 If it->multibyte_p is nonzero, non-printable non-ASCII
5701 characters are also translated to octal form.
5703 If it->multibyte_p is zero, eight-bit characters that
5704 don't have corresponding multibyte char code are also
5705 translated to octal form. */
5706 else if ((it
->c
< ' '
5707 ? (it
->area
!= TEXT_AREA
5708 /* In mode line, treat \n, \t like other crl chars. */
5710 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5711 || (it
->c
!= '\n' && it
->c
!= '\t'))
5713 ? (!CHAR_PRINTABLE_P (it
->c
)
5714 || (!NILP (Vnobreak_char_display
)
5715 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5716 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5718 && (! unibyte_display_via_language_environment
5719 || (UNIBYTE_CHAR_HAS_MULTIBYTE_P (it
->c
)))))))
5721 /* IT->c is a control character which must be displayed
5722 either as '\003' or as `^C' where the '\\' and '^'
5723 can be defined in the display table. Fill
5724 IT->ctl_chars with glyphs for what we have to
5725 display. Then, set IT->dpvec to these glyphs. */
5728 int face_id
, lface_id
= 0 ;
5731 /* Handle control characters with ^. */
5733 if (it
->c
< 128 && it
->ctl_arrow_p
)
5735 g
= '^'; /* default glyph for Control */
5736 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5738 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5739 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5741 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5742 lface_id
= FAST_GLYPH_FACE (g
);
5746 g
= FAST_GLYPH_CHAR (g
);
5747 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5750 else if (it
->f
== last_escape_glyph_frame
5751 && it
->face_id
== last_escape_glyph_face_id
)
5753 face_id
= last_escape_glyph_merged_face_id
;
5757 /* Merge the escape-glyph face into the current face. */
5758 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5760 last_escape_glyph_frame
= it
->f
;
5761 last_escape_glyph_face_id
= it
->face_id
;
5762 last_escape_glyph_merged_face_id
= face_id
;
5765 XSETINT (it
->ctl_chars
[0], g
);
5767 XSETINT (it
->ctl_chars
[1], g
);
5769 goto display_control
;
5772 /* Handle non-break space in the mode where it only gets
5775 if (EQ (Vnobreak_char_display
, Qt
)
5778 /* Merge the no-break-space face into the current face. */
5779 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5783 XSETINT (it
->ctl_chars
[0], g
);
5785 goto display_control
;
5788 /* Handle sequences that start with the "escape glyph". */
5790 /* the default escape glyph is \. */
5791 escape_glyph
= '\\';
5794 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5795 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5797 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5798 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5802 /* The display table specified a face.
5803 Merge it into face_id and also into escape_glyph. */
5804 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5805 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5808 else if (it
->f
== last_escape_glyph_frame
5809 && it
->face_id
== last_escape_glyph_face_id
)
5811 face_id
= last_escape_glyph_merged_face_id
;
5815 /* Merge the escape-glyph face into the current face. */
5816 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5818 last_escape_glyph_frame
= it
->f
;
5819 last_escape_glyph_face_id
= it
->face_id
;
5820 last_escape_glyph_merged_face_id
= face_id
;
5823 /* Handle soft hyphens in the mode where they only get
5826 if (EQ (Vnobreak_char_display
, Qt
)
5830 XSETINT (it
->ctl_chars
[0], g
);
5832 goto display_control
;
5835 /* Handle non-break space and soft hyphen
5836 with the escape glyph. */
5838 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5840 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5841 g
= it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5842 XSETINT (it
->ctl_chars
[1], g
);
5844 goto display_control
;
5848 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5852 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5853 if (CHAR_BYTE8_P (it
->c
))
5855 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5858 else if (it
->c
< 256)
5865 /* It's an invalid character, which shouldn't
5866 happen actually, but due to bugs it may
5867 happen. Let's print the char as is, there's
5868 not much meaningful we can do with it. */
5870 str
[1] = it
->c
>> 8;
5871 str
[2] = it
->c
>> 16;
5872 str
[3] = it
->c
>> 24;
5876 for (i
= 0; i
< len
; i
++)
5878 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5879 /* Insert three more glyphs into IT->ctl_chars for
5880 the octal display of the character. */
5881 g
= ((str
[i
] >> 6) & 7) + '0';
5882 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5883 g
= ((str
[i
] >> 3) & 7) + '0';
5884 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5885 g
= (str
[i
] & 7) + '0';
5886 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5892 /* Set up IT->dpvec and return first character from it. */
5893 it
->dpvec_char_len
= it
->len
;
5894 it
->dpvec
= it
->ctl_chars
;
5895 it
->dpend
= it
->dpvec
+ ctl_len
;
5896 it
->current
.dpvec_index
= 0;
5897 it
->dpvec_face_id
= face_id
;
5898 it
->saved_face_id
= it
->face_id
;
5899 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5906 /* Adjust face id for a multibyte character. There are no multibyte
5907 character in unibyte text. */
5908 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5911 && FRAME_WINDOW_P (it
->f
))
5913 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5914 int pos
= (it
->s
? -1
5915 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5916 : IT_CHARPOS (*it
));
5918 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5921 /* Is this character the last one of a run of characters with
5922 box? If yes, set IT->end_of_box_run_p to 1. */
5929 it
->end_of_box_run_p
5930 = ((face_id
= face_after_it_pos (it
),
5931 face_id
!= it
->face_id
)
5932 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5933 face
->box
== FACE_NO_BOX
));
5936 /* Value is 0 if end of buffer or string reached. */
5941 /* Move IT to the next display element.
5943 RESEAT_P non-zero means if called on a newline in buffer text,
5944 skip to the next visible line start.
5946 Functions get_next_display_element and set_iterator_to_next are
5947 separate because I find this arrangement easier to handle than a
5948 get_next_display_element function that also increments IT's
5949 position. The way it is we can first look at an iterator's current
5950 display element, decide whether it fits on a line, and if it does,
5951 increment the iterator position. The other way around we probably
5952 would either need a flag indicating whether the iterator has to be
5953 incremented the next time, or we would have to implement a
5954 decrement position function which would not be easy to write. */
5957 set_iterator_to_next (it
, reseat_p
)
5961 /* Reset flags indicating start and end of a sequence of characters
5962 with box. Reset them at the start of this function because
5963 moving the iterator to a new position might set them. */
5964 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5968 case GET_FROM_BUFFER
:
5969 /* The current display element of IT is a character from
5970 current_buffer. Advance in the buffer, and maybe skip over
5971 invisible lines that are so because of selective display. */
5972 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5973 reseat_at_next_visible_line_start (it
, 0);
5976 xassert (it
->len
!= 0);
5977 IT_BYTEPOS (*it
) += it
->len
;
5978 IT_CHARPOS (*it
) += 1;
5979 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5983 case GET_FROM_COMPOSITION
:
5984 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5985 xassert (it
->sp
> 0);
5987 if (it
->method
== GET_FROM_STRING
)
5989 IT_STRING_BYTEPOS (*it
) += it
->len
;
5990 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5991 goto consider_string_end
;
5993 else if (it
->method
== GET_FROM_BUFFER
)
5995 IT_BYTEPOS (*it
) += it
->len
;
5996 IT_CHARPOS (*it
) += it
->cmp_len
;
6000 case GET_FROM_C_STRING
:
6001 /* Current display element of IT is from a C string. */
6002 IT_BYTEPOS (*it
) += it
->len
;
6003 IT_CHARPOS (*it
) += 1;
6006 case GET_FROM_DISPLAY_VECTOR
:
6007 /* Current display element of IT is from a display table entry.
6008 Advance in the display table definition. Reset it to null if
6009 end reached, and continue with characters from buffers/
6011 ++it
->current
.dpvec_index
;
6013 /* Restore face of the iterator to what they were before the
6014 display vector entry (these entries may contain faces). */
6015 it
->face_id
= it
->saved_face_id
;
6017 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6019 int recheck_faces
= it
->ellipsis_p
;
6022 it
->method
= GET_FROM_C_STRING
;
6023 else if (STRINGP (it
->string
))
6024 it
->method
= GET_FROM_STRING
;
6027 it
->method
= GET_FROM_BUFFER
;
6028 it
->object
= it
->w
->buffer
;
6032 it
->current
.dpvec_index
= -1;
6034 /* Skip over characters which were displayed via IT->dpvec. */
6035 if (it
->dpvec_char_len
< 0)
6036 reseat_at_next_visible_line_start (it
, 1);
6037 else if (it
->dpvec_char_len
> 0)
6039 if (it
->method
== GET_FROM_STRING
6040 && it
->n_overlay_strings
> 0)
6041 it
->ignore_overlay_strings_at_pos_p
= 1;
6042 it
->len
= it
->dpvec_char_len
;
6043 set_iterator_to_next (it
, reseat_p
);
6046 /* Maybe recheck faces after display vector */
6048 it
->stop_charpos
= IT_CHARPOS (*it
);
6052 case GET_FROM_STRING
:
6053 /* Current display element is a character from a Lisp string. */
6054 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6055 IT_STRING_BYTEPOS (*it
) += it
->len
;
6056 IT_STRING_CHARPOS (*it
) += 1;
6058 consider_string_end
:
6060 if (it
->current
.overlay_string_index
>= 0)
6062 /* IT->string is an overlay string. Advance to the
6063 next, if there is one. */
6064 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6065 next_overlay_string (it
);
6069 /* IT->string is not an overlay string. If we reached
6070 its end, and there is something on IT->stack, proceed
6071 with what is on the stack. This can be either another
6072 string, this time an overlay string, or a buffer. */
6073 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6077 if (it
->method
== GET_FROM_STRING
)
6078 goto consider_string_end
;
6083 case GET_FROM_IMAGE
:
6084 case GET_FROM_STRETCH
:
6085 /* The position etc with which we have to proceed are on
6086 the stack. The position may be at the end of a string,
6087 if the `display' property takes up the whole string. */
6088 xassert (it
->sp
> 0);
6090 if (it
->method
== GET_FROM_STRING
)
6091 goto consider_string_end
;
6095 /* There are no other methods defined, so this should be a bug. */
6099 xassert (it
->method
!= GET_FROM_STRING
6100 || (STRINGP (it
->string
)
6101 && IT_STRING_CHARPOS (*it
) >= 0));
6104 /* Load IT's display element fields with information about the next
6105 display element which comes from a display table entry or from the
6106 result of translating a control character to one of the forms `^C'
6109 IT->dpvec holds the glyphs to return as characters.
6110 IT->saved_face_id holds the face id before the display vector--
6111 it is restored into IT->face_idin set_iterator_to_next. */
6114 next_element_from_display_vector (it
)
6118 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6120 it
->face_id
= it
->saved_face_id
;
6122 if (INTEGERP (*it
->dpvec
)
6123 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
6127 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
6128 it
->c
= FAST_GLYPH_CHAR (g
);
6129 it
->len
= CHAR_BYTES (it
->c
);
6131 /* The entry may contain a face id to use. Such a face id is
6132 the id of a Lisp face, not a realized face. A face id of
6133 zero means no face is specified. */
6134 if (it
->dpvec_face_id
>= 0)
6135 it
->face_id
= it
->dpvec_face_id
;
6138 int lface_id
= FAST_GLYPH_FACE (g
);
6140 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6145 /* Display table entry is invalid. Return a space. */
6146 it
->c
= ' ', it
->len
= 1;
6148 /* Don't change position and object of the iterator here. They are
6149 still the values of the character that had this display table
6150 entry or was translated, and that's what we want. */
6151 it
->what
= IT_CHARACTER
;
6156 /* Load IT with the next display element from Lisp string IT->string.
6157 IT->current.string_pos is the current position within the string.
6158 If IT->current.overlay_string_index >= 0, the Lisp string is an
6162 next_element_from_string (it
)
6165 struct text_pos position
;
6167 xassert (STRINGP (it
->string
));
6168 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6169 position
= it
->current
.string_pos
;
6171 /* Time to check for invisible text? */
6172 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6173 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6177 /* Since a handler may have changed IT->method, we must
6179 return get_next_display_element (it
);
6182 if (it
->current
.overlay_string_index
>= 0)
6184 /* Get the next character from an overlay string. In overlay
6185 strings, There is no field width or padding with spaces to
6187 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6192 else if (STRING_MULTIBYTE (it
->string
))
6194 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6195 const unsigned char *s
= (SDATA (it
->string
)
6196 + IT_STRING_BYTEPOS (*it
));
6197 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6201 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6207 /* Get the next character from a Lisp string that is not an
6208 overlay string. Such strings come from the mode line, for
6209 example. We may have to pad with spaces, or truncate the
6210 string. See also next_element_from_c_string. */
6211 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6216 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6218 /* Pad with spaces. */
6219 it
->c
= ' ', it
->len
= 1;
6220 CHARPOS (position
) = BYTEPOS (position
) = -1;
6222 else if (STRING_MULTIBYTE (it
->string
))
6224 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6225 const unsigned char *s
= (SDATA (it
->string
)
6226 + IT_STRING_BYTEPOS (*it
));
6227 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6231 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6236 /* Record what we have and where it came from. */
6237 it
->what
= IT_CHARACTER
;
6238 it
->object
= it
->string
;
6239 it
->position
= position
;
6244 /* Load IT with next display element from C string IT->s.
6245 IT->string_nchars is the maximum number of characters to return
6246 from the string. IT->end_charpos may be greater than
6247 IT->string_nchars when this function is called, in which case we
6248 may have to return padding spaces. Value is zero if end of string
6249 reached, including padding spaces. */
6252 next_element_from_c_string (it
)
6258 it
->what
= IT_CHARACTER
;
6259 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6262 /* IT's position can be greater IT->string_nchars in case a field
6263 width or precision has been specified when the iterator was
6265 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6267 /* End of the game. */
6271 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6273 /* Pad with spaces. */
6274 it
->c
= ' ', it
->len
= 1;
6275 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6277 else if (it
->multibyte_p
)
6279 /* Implementation note: The calls to strlen apparently aren't a
6280 performance problem because there is no noticeable performance
6281 difference between Emacs running in unibyte or multibyte mode. */
6282 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6283 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6287 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6293 /* Set up IT to return characters from an ellipsis, if appropriate.
6294 The definition of the ellipsis glyphs may come from a display table
6295 entry. This function Fills IT with the first glyph from the
6296 ellipsis if an ellipsis is to be displayed. */
6299 next_element_from_ellipsis (it
)
6302 if (it
->selective_display_ellipsis_p
)
6303 setup_for_ellipsis (it
, it
->len
);
6306 /* The face at the current position may be different from the
6307 face we find after the invisible text. Remember what it
6308 was in IT->saved_face_id, and signal that it's there by
6309 setting face_before_selective_p. */
6310 it
->saved_face_id
= it
->face_id
;
6311 it
->method
= GET_FROM_BUFFER
;
6312 it
->object
= it
->w
->buffer
;
6313 reseat_at_next_visible_line_start (it
, 1);
6314 it
->face_before_selective_p
= 1;
6317 return get_next_display_element (it
);
6321 /* Deliver an image display element. The iterator IT is already
6322 filled with image information (done in handle_display_prop). Value
6327 next_element_from_image (it
)
6330 it
->what
= IT_IMAGE
;
6335 /* Fill iterator IT with next display element from a stretch glyph
6336 property. IT->object is the value of the text property. Value is
6340 next_element_from_stretch (it
)
6343 it
->what
= IT_STRETCH
;
6348 /* Load IT with the next display element from current_buffer. Value
6349 is zero if end of buffer reached. IT->stop_charpos is the next
6350 position at which to stop and check for text properties or buffer
6354 next_element_from_buffer (it
)
6359 /* Check this assumption, otherwise, we would never enter the
6360 if-statement, below. */
6361 xassert (IT_CHARPOS (*it
) >= BEGV
6362 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6364 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6366 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6368 int overlay_strings_follow_p
;
6370 /* End of the game, except when overlay strings follow that
6371 haven't been returned yet. */
6372 if (it
->overlay_strings_at_end_processed_p
)
6373 overlay_strings_follow_p
= 0;
6376 it
->overlay_strings_at_end_processed_p
= 1;
6377 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6380 if (overlay_strings_follow_p
)
6381 success_p
= get_next_display_element (it
);
6385 it
->position
= it
->current
.pos
;
6392 return get_next_display_element (it
);
6397 /* No face changes, overlays etc. in sight, so just return a
6398 character from current_buffer. */
6401 /* Maybe run the redisplay end trigger hook. Performance note:
6402 This doesn't seem to cost measurable time. */
6403 if (it
->redisplay_end_trigger_charpos
6405 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6406 run_redisplay_end_trigger_hook (it
);
6408 /* Get the next character, maybe multibyte. */
6409 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6410 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6412 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6413 - IT_BYTEPOS (*it
));
6414 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6417 it
->c
= *p
, it
->len
= 1;
6419 /* Record what we have and where it came from. */
6420 it
->what
= IT_CHARACTER
;
6421 it
->object
= it
->w
->buffer
;
6422 it
->position
= it
->current
.pos
;
6424 /* Normally we return the character found above, except when we
6425 really want to return an ellipsis for selective display. */
6430 /* A value of selective > 0 means hide lines indented more
6431 than that number of columns. */
6432 if (it
->selective
> 0
6433 && IT_CHARPOS (*it
) + 1 < ZV
6434 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6435 IT_BYTEPOS (*it
) + 1,
6436 (double) it
->selective
)) /* iftc */
6438 success_p
= next_element_from_ellipsis (it
);
6439 it
->dpvec_char_len
= -1;
6442 else if (it
->c
== '\r' && it
->selective
== -1)
6444 /* A value of selective == -1 means that everything from the
6445 CR to the end of the line is invisible, with maybe an
6446 ellipsis displayed for it. */
6447 success_p
= next_element_from_ellipsis (it
);
6448 it
->dpvec_char_len
= -1;
6453 /* Value is zero if end of buffer reached. */
6454 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6459 /* Run the redisplay end trigger hook for IT. */
6462 run_redisplay_end_trigger_hook (it
)
6465 Lisp_Object args
[3];
6467 /* IT->glyph_row should be non-null, i.e. we should be actually
6468 displaying something, or otherwise we should not run the hook. */
6469 xassert (it
->glyph_row
);
6471 /* Set up hook arguments. */
6472 args
[0] = Qredisplay_end_trigger_functions
;
6473 args
[1] = it
->window
;
6474 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6475 it
->redisplay_end_trigger_charpos
= 0;
6477 /* Since we are *trying* to run these functions, don't try to run
6478 them again, even if they get an error. */
6479 it
->w
->redisplay_end_trigger
= Qnil
;
6480 Frun_hook_with_args (3, args
);
6482 /* Notice if it changed the face of the character we are on. */
6483 handle_face_prop (it
);
6487 /* Deliver a composition display element. The iterator IT is already
6488 filled with composition information (done in
6489 handle_composition_prop). Value is always 1. */
6492 next_element_from_composition (it
)
6495 it
->what
= IT_COMPOSITION
;
6496 it
->position
= (STRINGP (it
->string
)
6497 ? it
->current
.string_pos
6499 if (STRINGP (it
->string
))
6500 it
->object
= it
->string
;
6502 it
->object
= it
->w
->buffer
;
6508 /***********************************************************************
6509 Moving an iterator without producing glyphs
6510 ***********************************************************************/
6512 /* Check if iterator is at a position corresponding to a valid buffer
6513 position after some move_it_ call. */
6515 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6516 ((it)->method == GET_FROM_STRING \
6517 ? IT_STRING_CHARPOS (*it) == 0 \
6521 /* Move iterator IT to a specified buffer or X position within one
6522 line on the display without producing glyphs.
6524 OP should be a bit mask including some or all of these bits:
6525 MOVE_TO_X: Stop on reaching x-position TO_X.
6526 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6527 Regardless of OP's value, stop in reaching the end of the display line.
6529 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6530 This means, in particular, that TO_X includes window's horizontal
6533 The return value has several possible values that
6534 say what condition caused the scan to stop:
6536 MOVE_POS_MATCH_OR_ZV
6537 - when TO_POS or ZV was reached.
6540 -when TO_X was reached before TO_POS or ZV were reached.
6543 - when we reached the end of the display area and the line must
6547 - when we reached the end of the display area and the line is
6551 - when we stopped at a line end, i.e. a newline or a CR and selective
6554 static enum move_it_result
6555 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
6557 int to_charpos
, to_x
, op
;
6559 enum move_it_result result
= MOVE_UNDEFINED
;
6560 struct glyph_row
*saved_glyph_row
;
6562 /* Don't produce glyphs in produce_glyphs. */
6563 saved_glyph_row
= it
->glyph_row
;
6564 it
->glyph_row
= NULL
;
6566 #define BUFFER_POS_REACHED_P() \
6567 ((op & MOVE_TO_POS) != 0 \
6568 && BUFFERP (it->object) \
6569 && IT_CHARPOS (*it) >= to_charpos \
6570 && (it->method == GET_FROM_BUFFER \
6571 || (it->method == GET_FROM_DISPLAY_VECTOR \
6572 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6577 int x
, i
, ascent
= 0, descent
= 0;
6579 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
6580 if ((op
& MOVE_TO_POS
) != 0
6581 && BUFFERP (it
->object
)
6582 && it
->method
== GET_FROM_BUFFER
6583 && IT_CHARPOS (*it
) > to_charpos
)
6585 result
= MOVE_POS_MATCH_OR_ZV
;
6589 /* Stop when ZV reached.
6590 We used to stop here when TO_CHARPOS reached as well, but that is
6591 too soon if this glyph does not fit on this line. So we handle it
6592 explicitly below. */
6593 if (!get_next_display_element (it
)
6594 || (it
->truncate_lines_p
6595 && BUFFER_POS_REACHED_P ()))
6597 result
= MOVE_POS_MATCH_OR_ZV
;
6601 /* The call to produce_glyphs will get the metrics of the
6602 display element IT is loaded with. We record in x the
6603 x-position before this display element in case it does not
6607 /* Remember the line height so far in case the next element doesn't
6609 if (!it
->truncate_lines_p
)
6611 ascent
= it
->max_ascent
;
6612 descent
= it
->max_descent
;
6615 PRODUCE_GLYPHS (it
);
6617 if (it
->area
!= TEXT_AREA
)
6619 set_iterator_to_next (it
, 1);
6623 /* The number of glyphs we get back in IT->nglyphs will normally
6624 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6625 character on a terminal frame, or (iii) a line end. For the
6626 second case, IT->nglyphs - 1 padding glyphs will be present
6627 (on X frames, there is only one glyph produced for a
6628 composite character.
6630 The behavior implemented below means, for continuation lines,
6631 that as many spaces of a TAB as fit on the current line are
6632 displayed there. For terminal frames, as many glyphs of a
6633 multi-glyph character are displayed in the current line, too.
6634 This is what the old redisplay code did, and we keep it that
6635 way. Under X, the whole shape of a complex character must
6636 fit on the line or it will be completely displayed in the
6639 Note that both for tabs and padding glyphs, all glyphs have
6643 /* More than one glyph or glyph doesn't fit on line. All
6644 glyphs have the same width. */
6645 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6647 int x_before_this_char
= x
;
6648 int hpos_before_this_char
= it
->hpos
;
6650 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6652 new_x
= x
+ single_glyph_width
;
6654 /* We want to leave anything reaching TO_X to the caller. */
6655 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6657 if (BUFFER_POS_REACHED_P ())
6658 goto buffer_pos_reached
;
6660 result
= MOVE_X_REACHED
;
6663 else if (/* Lines are continued. */
6664 !it
->truncate_lines_p
6665 && (/* And glyph doesn't fit on the line. */
6666 new_x
> it
->last_visible_x
6667 /* Or it fits exactly and we're on a window
6669 || (new_x
== it
->last_visible_x
6670 && FRAME_WINDOW_P (it
->f
))))
6672 if (/* IT->hpos == 0 means the very first glyph
6673 doesn't fit on the line, e.g. a wide image. */
6675 || (new_x
== it
->last_visible_x
6676 && FRAME_WINDOW_P (it
->f
)))
6679 it
->current_x
= new_x
;
6681 /* The character's last glyph just barely fits
6683 if (i
== it
->nglyphs
- 1)
6685 /* If this is the destination position,
6686 return a position *before* it in this row,
6687 now that we know it fits in this row. */
6688 if (BUFFER_POS_REACHED_P ())
6690 it
->hpos
= hpos_before_this_char
;
6691 it
->current_x
= x_before_this_char
;
6692 result
= MOVE_POS_MATCH_OR_ZV
;
6696 set_iterator_to_next (it
, 1);
6697 #ifdef HAVE_WINDOW_SYSTEM
6698 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6700 if (!get_next_display_element (it
))
6702 result
= MOVE_POS_MATCH_OR_ZV
;
6705 if (BUFFER_POS_REACHED_P ())
6707 if (ITERATOR_AT_END_OF_LINE_P (it
))
6708 result
= MOVE_POS_MATCH_OR_ZV
;
6710 result
= MOVE_LINE_CONTINUED
;
6713 if (ITERATOR_AT_END_OF_LINE_P (it
))
6715 result
= MOVE_NEWLINE_OR_CR
;
6719 #endif /* HAVE_WINDOW_SYSTEM */
6725 it
->max_ascent
= ascent
;
6726 it
->max_descent
= descent
;
6729 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6731 result
= MOVE_LINE_CONTINUED
;
6734 else if (BUFFER_POS_REACHED_P ())
6735 goto buffer_pos_reached
;
6736 else if (new_x
> it
->first_visible_x
)
6738 /* Glyph is visible. Increment number of glyphs that
6739 would be displayed. */
6744 /* Glyph is completely off the left margin of the display
6745 area. Nothing to do. */
6749 if (result
!= MOVE_UNDEFINED
)
6752 else if (BUFFER_POS_REACHED_P ())
6756 it
->max_ascent
= ascent
;
6757 it
->max_descent
= descent
;
6758 result
= MOVE_POS_MATCH_OR_ZV
;
6761 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6763 /* Stop when TO_X specified and reached. This check is
6764 necessary here because of lines consisting of a line end,
6765 only. The line end will not produce any glyphs and we
6766 would never get MOVE_X_REACHED. */
6767 xassert (it
->nglyphs
== 0);
6768 result
= MOVE_X_REACHED
;
6772 /* Is this a line end? If yes, we're done. */
6773 if (ITERATOR_AT_END_OF_LINE_P (it
))
6775 result
= MOVE_NEWLINE_OR_CR
;
6779 /* The current display element has been consumed. Advance
6781 set_iterator_to_next (it
, 1);
6783 /* Stop if lines are truncated and IT's current x-position is
6784 past the right edge of the window now. */
6785 if (it
->truncate_lines_p
6786 && it
->current_x
>= it
->last_visible_x
)
6788 #ifdef HAVE_WINDOW_SYSTEM
6789 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6791 if (!get_next_display_element (it
)
6792 || BUFFER_POS_REACHED_P ())
6794 result
= MOVE_POS_MATCH_OR_ZV
;
6797 if (ITERATOR_AT_END_OF_LINE_P (it
))
6799 result
= MOVE_NEWLINE_OR_CR
;
6803 #endif /* HAVE_WINDOW_SYSTEM */
6804 result
= MOVE_LINE_TRUNCATED
;
6809 #undef BUFFER_POS_REACHED_P
6811 /* Restore the iterator settings altered at the beginning of this
6813 it
->glyph_row
= saved_glyph_row
;
6818 /* Move IT forward until it satisfies one or more of the criteria in
6819 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6821 OP is a bit-mask that specifies where to stop, and in particular,
6822 which of those four position arguments makes a difference. See the
6823 description of enum move_operation_enum.
6825 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6826 screen line, this function will set IT to the next position >
6830 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6832 int to_charpos
, to_x
, to_y
, to_vpos
;
6835 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6841 if (op
& MOVE_TO_VPOS
)
6843 /* If no TO_CHARPOS and no TO_X specified, stop at the
6844 start of the line TO_VPOS. */
6845 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6847 if (it
->vpos
== to_vpos
)
6853 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6857 /* TO_VPOS >= 0 means stop at TO_X in the line at
6858 TO_VPOS, or at TO_POS, whichever comes first. */
6859 if (it
->vpos
== to_vpos
)
6865 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6867 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6872 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6874 /* We have reached TO_X but not in the line we want. */
6875 skip
= move_it_in_display_line_to (it
, to_charpos
,
6877 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6885 else if (op
& MOVE_TO_Y
)
6887 struct it it_backup
;
6889 /* TO_Y specified means stop at TO_X in the line containing
6890 TO_Y---or at TO_CHARPOS if this is reached first. The
6891 problem is that we can't really tell whether the line
6892 contains TO_Y before we have completely scanned it, and
6893 this may skip past TO_X. What we do is to first scan to
6896 If TO_X is not specified, use a TO_X of zero. The reason
6897 is to make the outcome of this function more predictable.
6898 If we didn't use TO_X == 0, we would stop at the end of
6899 the line which is probably not what a caller would expect
6901 skip
= move_it_in_display_line_to (it
, to_charpos
,
6905 | (op
& MOVE_TO_POS
)));
6907 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6908 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6914 /* If TO_X was reached, we would like to know whether TO_Y
6915 is in the line. This can only be said if we know the
6916 total line height which requires us to scan the rest of
6918 if (skip
== MOVE_X_REACHED
)
6920 /* Wait! We can conclude that TO_Y is in the line if
6921 the already scanned glyphs make the line tall enough
6922 because further scanning doesn't make it shorter. */
6923 line_height
= it
->max_ascent
+ it
->max_descent
;
6924 if (to_y
>= it
->current_y
6925 && to_y
< it
->current_y
+ line_height
)
6931 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6932 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6934 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6937 /* Now, decide whether TO_Y is in this line. */
6938 line_height
= it
->max_ascent
+ it
->max_descent
;
6939 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6941 if (to_y
>= it
->current_y
6942 && to_y
< it
->current_y
+ line_height
)
6944 if (skip
== MOVE_X_REACHED
)
6945 /* If TO_Y is in this line and TO_X was reached above,
6946 we scanned too far. We have to restore IT's settings
6947 to the ones before skipping. */
6951 else if (skip
== MOVE_X_REACHED
)
6954 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6961 else if (BUFFERP (it
->object
)
6962 && it
->method
== GET_FROM_BUFFER
6963 && IT_CHARPOS (*it
) >= to_charpos
)
6964 skip
= MOVE_POS_MATCH_OR_ZV
;
6966 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6970 case MOVE_POS_MATCH_OR_ZV
:
6974 case MOVE_NEWLINE_OR_CR
:
6975 set_iterator_to_next (it
, 1);
6976 it
->continuation_lines_width
= 0;
6979 case MOVE_LINE_TRUNCATED
:
6980 it
->continuation_lines_width
= 0;
6981 reseat_at_next_visible_line_start (it
, 0);
6982 if ((op
& MOVE_TO_POS
) != 0
6983 && IT_CHARPOS (*it
) > to_charpos
)
6990 case MOVE_LINE_CONTINUED
:
6991 /* For continued lines ending in a tab, some of the glyphs
6992 associated with the tab are displayed on the current
6993 line. Since it->current_x does not include these glyphs,
6994 we use it->last_visible_x instead. */
6995 it
->continuation_lines_width
+=
6996 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
7003 /* Reset/increment for the next run. */
7004 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7005 it
->current_x
= it
->hpos
= 0;
7006 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7008 last_height
= it
->max_ascent
+ it
->max_descent
;
7009 last_max_ascent
= it
->max_ascent
;
7010 it
->max_ascent
= it
->max_descent
= 0;
7015 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7019 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7021 If DY > 0, move IT backward at least that many pixels. DY = 0
7022 means move IT backward to the preceding line start or BEGV. This
7023 function may move over more than DY pixels if IT->current_y - DY
7024 ends up in the middle of a line; in this case IT->current_y will be
7025 set to the top of the line moved to. */
7028 move_it_vertically_backward (it
, dy
)
7039 start_pos
= IT_CHARPOS (*it
);
7041 /* Estimate how many newlines we must move back. */
7042 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7044 /* Set the iterator's position that many lines back. */
7045 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7046 back_to_previous_visible_line_start (it
);
7048 /* Reseat the iterator here. When moving backward, we don't want
7049 reseat to skip forward over invisible text, set up the iterator
7050 to deliver from overlay strings at the new position etc. So,
7051 use reseat_1 here. */
7052 reseat_1 (it
, it
->current
.pos
, 1);
7054 /* We are now surely at a line start. */
7055 it
->current_x
= it
->hpos
= 0;
7056 it
->continuation_lines_width
= 0;
7058 /* Move forward and see what y-distance we moved. First move to the
7059 start of the next line so that we get its height. We need this
7060 height to be able to tell whether we reached the specified
7063 it2
.max_ascent
= it2
.max_descent
= 0;
7066 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7067 MOVE_TO_POS
| MOVE_TO_VPOS
);
7069 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7070 xassert (IT_CHARPOS (*it
) >= BEGV
);
7073 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7074 xassert (IT_CHARPOS (*it
) >= BEGV
);
7075 /* H is the actual vertical distance from the position in *IT
7076 and the starting position. */
7077 h
= it2
.current_y
- it
->current_y
;
7078 /* NLINES is the distance in number of lines. */
7079 nlines
= it2
.vpos
- it
->vpos
;
7081 /* Correct IT's y and vpos position
7082 so that they are relative to the starting point. */
7088 /* DY == 0 means move to the start of the screen line. The
7089 value of nlines is > 0 if continuation lines were involved. */
7091 move_it_by_lines (it
, nlines
, 1);
7093 /* I think this assert is bogus if buffer contains
7094 invisible text or images. KFS. */
7095 xassert (IT_CHARPOS (*it
) <= start_pos
);
7100 /* The y-position we try to reach, relative to *IT.
7101 Note that H has been subtracted in front of the if-statement. */
7102 int target_y
= it
->current_y
+ h
- dy
;
7103 int y0
= it3
.current_y
;
7104 int y1
= line_bottom_y (&it3
);
7105 int line_height
= y1
- y0
;
7107 /* If we did not reach target_y, try to move further backward if
7108 we can. If we moved too far backward, try to move forward. */
7109 if (target_y
< it
->current_y
7110 /* This is heuristic. In a window that's 3 lines high, with
7111 a line height of 13 pixels each, recentering with point
7112 on the bottom line will try to move -39/2 = 19 pixels
7113 backward. Try to avoid moving into the first line. */
7114 && (it
->current_y
- target_y
7115 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7116 && IT_CHARPOS (*it
) > BEGV
)
7118 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7119 target_y
- it
->current_y
));
7120 dy
= it
->current_y
- target_y
;
7121 goto move_further_back
;
7123 else if (target_y
>= it
->current_y
+ line_height
7124 && IT_CHARPOS (*it
) < ZV
)
7126 /* Should move forward by at least one line, maybe more.
7128 Note: Calling move_it_by_lines can be expensive on
7129 terminal frames, where compute_motion is used (via
7130 vmotion) to do the job, when there are very long lines
7131 and truncate-lines is nil. That's the reason for
7132 treating terminal frames specially here. */
7134 if (!FRAME_WINDOW_P (it
->f
))
7135 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7140 move_it_by_lines (it
, 1, 1);
7142 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7146 /* I think this assert is bogus if buffer contains
7147 invisible text or images. KFS. */
7148 xassert (IT_CHARPOS (*it
) >= BEGV
);
7155 /* Move IT by a specified amount of pixel lines DY. DY negative means
7156 move backwards. DY = 0 means move to start of screen line. At the
7157 end, IT will be on the start of a screen line. */
7160 move_it_vertically (it
, dy
)
7165 move_it_vertically_backward (it
, -dy
);
7168 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7169 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7170 MOVE_TO_POS
| MOVE_TO_Y
);
7171 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7173 /* If buffer ends in ZV without a newline, move to the start of
7174 the line to satisfy the post-condition. */
7175 if (IT_CHARPOS (*it
) == ZV
7177 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7178 move_it_by_lines (it
, 0, 0);
7183 /* Move iterator IT past the end of the text line it is in. */
7186 move_it_past_eol (it
)
7189 enum move_it_result rc
;
7191 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7192 if (rc
== MOVE_NEWLINE_OR_CR
)
7193 set_iterator_to_next (it
, 0);
7197 #if 0 /* Currently not used. */
7199 /* Return non-zero if some text between buffer positions START_CHARPOS
7200 and END_CHARPOS is invisible. IT->window is the window for text
7204 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7206 int start_charpos
, end_charpos
;
7208 Lisp_Object prop
, limit
;
7209 int invisible_found_p
;
7211 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7213 /* Is text at START invisible? */
7214 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7216 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7217 invisible_found_p
= 1;
7220 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7222 make_number (end_charpos
));
7223 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7226 return invisible_found_p
;
7232 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7233 negative means move up. DVPOS == 0 means move to the start of the
7234 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7235 NEED_Y_P is zero, IT->current_y will be left unchanged.
7237 Further optimization ideas: If we would know that IT->f doesn't use
7238 a face with proportional font, we could be faster for
7239 truncate-lines nil. */
7242 move_it_by_lines (it
, dvpos
, need_y_p
)
7244 int dvpos
, need_y_p
;
7246 struct position pos
;
7248 /* The commented-out optimization uses vmotion on terminals. This
7249 gives bad results, because elements like it->what, on which
7250 callers such as pos_visible_p rely, aren't updated. */
7251 /* if (!FRAME_WINDOW_P (it->f))
7253 struct text_pos textpos;
7255 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7256 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7257 reseat (it, textpos, 1);
7258 it->vpos += pos.vpos;
7259 it->current_y += pos.vpos;
7265 /* DVPOS == 0 means move to the start of the screen line. */
7266 move_it_vertically_backward (it
, 0);
7267 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7268 /* Let next call to line_bottom_y calculate real line height */
7273 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7274 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7275 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7280 int start_charpos
, i
;
7282 /* Start at the beginning of the screen line containing IT's
7283 position. This may actually move vertically backwards,
7284 in case of overlays, so adjust dvpos accordingly. */
7286 move_it_vertically_backward (it
, 0);
7289 /* Go back -DVPOS visible lines and reseat the iterator there. */
7290 start_charpos
= IT_CHARPOS (*it
);
7291 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7292 back_to_previous_visible_line_start (it
);
7293 reseat (it
, it
->current
.pos
, 1);
7295 /* Move further back if we end up in a string or an image. */
7296 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7298 /* First try to move to start of display line. */
7300 move_it_vertically_backward (it
, 0);
7302 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7304 /* If start of line is still in string or image,
7305 move further back. */
7306 back_to_previous_visible_line_start (it
);
7307 reseat (it
, it
->current
.pos
, 1);
7311 it
->current_x
= it
->hpos
= 0;
7313 /* Above call may have moved too far if continuation lines
7314 are involved. Scan forward and see if it did. */
7316 it2
.vpos
= it2
.current_y
= 0;
7317 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7318 it
->vpos
-= it2
.vpos
;
7319 it
->current_y
-= it2
.current_y
;
7320 it
->current_x
= it
->hpos
= 0;
7322 /* If we moved too far back, move IT some lines forward. */
7323 if (it2
.vpos
> -dvpos
)
7325 int delta
= it2
.vpos
+ dvpos
;
7327 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7328 /* Move back again if we got too far ahead. */
7329 if (IT_CHARPOS (*it
) >= start_charpos
)
7335 /* Return 1 if IT points into the middle of a display vector. */
7338 in_display_vector_p (it
)
7341 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7342 && it
->current
.dpvec_index
> 0
7343 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7347 /***********************************************************************
7349 ***********************************************************************/
7352 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7356 add_to_log (format
, arg1
, arg2
)
7358 Lisp_Object arg1
, arg2
;
7360 Lisp_Object args
[3];
7361 Lisp_Object msg
, fmt
;
7364 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7367 /* Do nothing if called asynchronously. Inserting text into
7368 a buffer may call after-change-functions and alike and
7369 that would means running Lisp asynchronously. */
7370 if (handling_signal
)
7374 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7376 args
[0] = fmt
= build_string (format
);
7379 msg
= Fformat (3, args
);
7381 len
= SBYTES (msg
) + 1;
7382 SAFE_ALLOCA (buffer
, char *, len
);
7383 bcopy (SDATA (msg
), buffer
, len
);
7385 message_dolog (buffer
, len
- 1, 1, 0);
7392 /* Output a newline in the *Messages* buffer if "needs" one. */
7395 message_log_maybe_newline ()
7397 if (message_log_need_newline
)
7398 message_dolog ("", 0, 1, 0);
7402 /* Add a string M of length NBYTES to the message log, optionally
7403 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7404 nonzero, means interpret the contents of M as multibyte. This
7405 function calls low-level routines in order to bypass text property
7406 hooks, etc. which might not be safe to run.
7408 This may GC (insert may run before/after change hooks),
7409 so the buffer M must NOT point to a Lisp string. */
7412 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7414 int nbytes
, nlflag
, multibyte
;
7416 if (!NILP (Vmemory_full
))
7419 if (!NILP (Vmessage_log_max
))
7421 struct buffer
*oldbuf
;
7422 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7423 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7424 int point_at_end
= 0;
7426 Lisp_Object old_deactivate_mark
, tem
;
7427 struct gcpro gcpro1
;
7429 old_deactivate_mark
= Vdeactivate_mark
;
7430 oldbuf
= current_buffer
;
7431 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7432 current_buffer
->undo_list
= Qt
;
7434 oldpoint
= message_dolog_marker1
;
7435 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7436 oldbegv
= message_dolog_marker2
;
7437 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7438 oldzv
= message_dolog_marker3
;
7439 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7440 GCPRO1 (old_deactivate_mark
);
7448 BEGV_BYTE
= BEG_BYTE
;
7451 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7453 /* Insert the string--maybe converting multibyte to single byte
7454 or vice versa, so that all the text fits the buffer. */
7456 && NILP (current_buffer
->enable_multibyte_characters
))
7458 int i
, c
, char_bytes
;
7459 unsigned char work
[1];
7461 /* Convert a multibyte string to single-byte
7462 for the *Message* buffer. */
7463 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7465 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7466 work
[0] = (ASCII_CHAR_P (c
)
7468 : multibyte_char_to_unibyte (c
, Qnil
));
7469 insert_1_both (work
, 1, 1, 1, 0, 0);
7472 else if (! multibyte
7473 && ! NILP (current_buffer
->enable_multibyte_characters
))
7475 int i
, c
, char_bytes
;
7476 unsigned char *msg
= (unsigned char *) m
;
7477 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7478 /* Convert a single-byte string to multibyte
7479 for the *Message* buffer. */
7480 for (i
= 0; i
< nbytes
; i
++)
7483 c
= unibyte_char_to_multibyte (c
);
7484 char_bytes
= CHAR_STRING (c
, str
);
7485 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7489 insert_1 (m
, nbytes
, 1, 0, 0);
7493 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7494 insert_1 ("\n", 1, 1, 0, 0);
7496 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7498 this_bol_byte
= PT_BYTE
;
7500 /* See if this line duplicates the previous one.
7501 If so, combine duplicates. */
7504 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7506 prev_bol_byte
= PT_BYTE
;
7508 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7509 this_bol
, this_bol_byte
);
7512 del_range_both (prev_bol
, prev_bol_byte
,
7513 this_bol
, this_bol_byte
, 0);
7519 /* If you change this format, don't forget to also
7520 change message_log_check_duplicate. */
7521 sprintf (dupstr
, " [%d times]", dup
);
7522 duplen
= strlen (dupstr
);
7523 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7524 insert_1 (dupstr
, duplen
, 1, 0, 1);
7529 /* If we have more than the desired maximum number of lines
7530 in the *Messages* buffer now, delete the oldest ones.
7531 This is safe because we don't have undo in this buffer. */
7533 if (NATNUMP (Vmessage_log_max
))
7535 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7536 -XFASTINT (Vmessage_log_max
) - 1, 0);
7537 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7540 BEGV
= XMARKER (oldbegv
)->charpos
;
7541 BEGV_BYTE
= marker_byte_position (oldbegv
);
7550 ZV
= XMARKER (oldzv
)->charpos
;
7551 ZV_BYTE
= marker_byte_position (oldzv
);
7555 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7557 /* We can't do Fgoto_char (oldpoint) because it will run some
7559 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7560 XMARKER (oldpoint
)->bytepos
);
7563 unchain_marker (XMARKER (oldpoint
));
7564 unchain_marker (XMARKER (oldbegv
));
7565 unchain_marker (XMARKER (oldzv
));
7567 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7568 set_buffer_internal (oldbuf
);
7570 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7571 message_log_need_newline
= !nlflag
;
7572 Vdeactivate_mark
= old_deactivate_mark
;
7577 /* We are at the end of the buffer after just having inserted a newline.
7578 (Note: We depend on the fact we won't be crossing the gap.)
7579 Check to see if the most recent message looks a lot like the previous one.
7580 Return 0 if different, 1 if the new one should just replace it, or a
7581 value N > 1 if we should also append " [N times]". */
7584 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7585 int prev_bol
, this_bol
;
7586 int prev_bol_byte
, this_bol_byte
;
7589 int len
= Z_BYTE
- 1 - this_bol_byte
;
7591 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7592 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7594 for (i
= 0; i
< len
; i
++)
7596 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7604 if (*p1
++ == ' ' && *p1
++ == '[')
7607 while (*p1
>= '0' && *p1
<= '9')
7608 n
= n
* 10 + *p1
++ - '0';
7609 if (strncmp (p1
, " times]\n", 8) == 0)
7616 /* Display an echo area message M with a specified length of NBYTES
7617 bytes. The string may include null characters. If M is 0, clear
7618 out any existing message, and let the mini-buffer text show
7621 This may GC, so the buffer M must NOT point to a Lisp string. */
7624 message2 (m
, nbytes
, multibyte
)
7629 /* First flush out any partial line written with print. */
7630 message_log_maybe_newline ();
7632 message_dolog (m
, nbytes
, 1, multibyte
);
7633 message2_nolog (m
, nbytes
, multibyte
);
7637 /* The non-logging counterpart of message2. */
7640 message2_nolog (m
, nbytes
, multibyte
)
7642 int nbytes
, multibyte
;
7644 struct frame
*sf
= SELECTED_FRAME ();
7645 message_enable_multibyte
= multibyte
;
7649 if (noninteractive_need_newline
)
7650 putc ('\n', stderr
);
7651 noninteractive_need_newline
= 0;
7653 fwrite (m
, nbytes
, 1, stderr
);
7654 if (cursor_in_echo_area
== 0)
7655 fprintf (stderr
, "\n");
7658 /* A null message buffer means that the frame hasn't really been
7659 initialized yet. Error messages get reported properly by
7660 cmd_error, so this must be just an informative message; toss it. */
7661 else if (INTERACTIVE
7662 && sf
->glyphs_initialized_p
7663 && FRAME_MESSAGE_BUF (sf
))
7665 Lisp_Object mini_window
;
7668 /* Get the frame containing the mini-buffer
7669 that the selected frame is using. */
7670 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7671 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7673 FRAME_SAMPLE_VISIBILITY (f
);
7674 if (FRAME_VISIBLE_P (sf
)
7675 && ! FRAME_VISIBLE_P (f
))
7676 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7680 set_message (m
, Qnil
, nbytes
, multibyte
);
7681 if (minibuffer_auto_raise
)
7682 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7685 clear_message (1, 1);
7687 do_pending_window_change (0);
7688 echo_area_display (1);
7689 do_pending_window_change (0);
7690 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7691 (*frame_up_to_date_hook
) (f
);
7696 /* Display an echo area message M with a specified length of NBYTES
7697 bytes. The string may include null characters. If M is not a
7698 string, clear out any existing message, and let the mini-buffer
7701 This function cancels echoing. */
7704 message3 (m
, nbytes
, multibyte
)
7709 struct gcpro gcpro1
;
7712 clear_message (1,1);
7715 /* First flush out any partial line written with print. */
7716 message_log_maybe_newline ();
7722 SAFE_ALLOCA (buffer
, char *, nbytes
);
7723 bcopy (SDATA (m
), buffer
, nbytes
);
7724 message_dolog (buffer
, nbytes
, 1, multibyte
);
7727 message3_nolog (m
, nbytes
, multibyte
);
7733 /* The non-logging version of message3.
7734 This does not cancel echoing, because it is used for echoing.
7735 Perhaps we need to make a separate function for echoing
7736 and make this cancel echoing. */
7739 message3_nolog (m
, nbytes
, multibyte
)
7741 int nbytes
, multibyte
;
7743 struct frame
*sf
= SELECTED_FRAME ();
7744 message_enable_multibyte
= multibyte
;
7748 if (noninteractive_need_newline
)
7749 putc ('\n', stderr
);
7750 noninteractive_need_newline
= 0;
7752 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7753 if (cursor_in_echo_area
== 0)
7754 fprintf (stderr
, "\n");
7757 /* A null message buffer means that the frame hasn't really been
7758 initialized yet. Error messages get reported properly by
7759 cmd_error, so this must be just an informative message; toss it. */
7760 else if (INTERACTIVE
7761 && sf
->glyphs_initialized_p
7762 && FRAME_MESSAGE_BUF (sf
))
7764 Lisp_Object mini_window
;
7768 /* Get the frame containing the mini-buffer
7769 that the selected frame is using. */
7770 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7771 frame
= XWINDOW (mini_window
)->frame
;
7774 FRAME_SAMPLE_VISIBILITY (f
);
7775 if (FRAME_VISIBLE_P (sf
)
7776 && !FRAME_VISIBLE_P (f
))
7777 Fmake_frame_visible (frame
);
7779 if (STRINGP (m
) && SCHARS (m
) > 0)
7781 set_message (NULL
, m
, nbytes
, multibyte
);
7782 if (minibuffer_auto_raise
)
7783 Fraise_frame (frame
);
7784 /* Assume we are not echoing.
7785 (If we are, echo_now will override this.) */
7786 echo_message_buffer
= Qnil
;
7789 clear_message (1, 1);
7791 do_pending_window_change (0);
7792 echo_area_display (1);
7793 do_pending_window_change (0);
7794 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7795 (*frame_up_to_date_hook
) (f
);
7800 /* Display a null-terminated echo area message M. If M is 0, clear
7801 out any existing message, and let the mini-buffer text show through.
7803 The buffer M must continue to exist until after the echo area gets
7804 cleared or some other message gets displayed there. Do not pass
7805 text that is stored in a Lisp string. Do not pass text in a buffer
7806 that was alloca'd. */
7812 message2 (m
, (m
? strlen (m
) : 0), 0);
7816 /* The non-logging counterpart of message1. */
7822 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7825 /* Display a message M which contains a single %s
7826 which gets replaced with STRING. */
7829 message_with_string (m
, string
, log
)
7834 CHECK_STRING (string
);
7840 if (noninteractive_need_newline
)
7841 putc ('\n', stderr
);
7842 noninteractive_need_newline
= 0;
7843 fprintf (stderr
, m
, SDATA (string
));
7844 if (cursor_in_echo_area
== 0)
7845 fprintf (stderr
, "\n");
7849 else if (INTERACTIVE
)
7851 /* The frame whose minibuffer we're going to display the message on.
7852 It may be larger than the selected frame, so we need
7853 to use its buffer, not the selected frame's buffer. */
7854 Lisp_Object mini_window
;
7855 struct frame
*f
, *sf
= SELECTED_FRAME ();
7857 /* Get the frame containing the minibuffer
7858 that the selected frame is using. */
7859 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7860 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7862 /* A null message buffer means that the frame hasn't really been
7863 initialized yet. Error messages get reported properly by
7864 cmd_error, so this must be just an informative message; toss it. */
7865 if (FRAME_MESSAGE_BUF (f
))
7867 Lisp_Object args
[2], message
;
7868 struct gcpro gcpro1
, gcpro2
;
7870 args
[0] = build_string (m
);
7871 args
[1] = message
= string
;
7872 GCPRO2 (args
[0], message
);
7875 message
= Fformat (2, args
);
7878 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7880 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7884 /* Print should start at the beginning of the message
7885 buffer next time. */
7886 message_buf_print
= 0;
7892 /* Dump an informative message to the minibuf. If M is 0, clear out
7893 any existing message, and let the mini-buffer text show through. */
7897 message (m
, a1
, a2
, a3
)
7899 EMACS_INT a1
, a2
, a3
;
7905 if (noninteractive_need_newline
)
7906 putc ('\n', stderr
);
7907 noninteractive_need_newline
= 0;
7908 fprintf (stderr
, m
, a1
, a2
, a3
);
7909 if (cursor_in_echo_area
== 0)
7910 fprintf (stderr
, "\n");
7914 else if (INTERACTIVE
)
7916 /* The frame whose mini-buffer we're going to display the message
7917 on. It may be larger than the selected frame, so we need to
7918 use its buffer, not the selected frame's buffer. */
7919 Lisp_Object mini_window
;
7920 struct frame
*f
, *sf
= SELECTED_FRAME ();
7922 /* Get the frame containing the mini-buffer
7923 that the selected frame is using. */
7924 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7925 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7927 /* A null message buffer means that the frame hasn't really been
7928 initialized yet. Error messages get reported properly by
7929 cmd_error, so this must be just an informative message; toss
7931 if (FRAME_MESSAGE_BUF (f
))
7942 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7943 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7945 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7946 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7948 #endif /* NO_ARG_ARRAY */
7950 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7955 /* Print should start at the beginning of the message
7956 buffer next time. */
7957 message_buf_print
= 0;
7963 /* The non-logging version of message. */
7966 message_nolog (m
, a1
, a2
, a3
)
7968 EMACS_INT a1
, a2
, a3
;
7970 Lisp_Object old_log_max
;
7971 old_log_max
= Vmessage_log_max
;
7972 Vmessage_log_max
= Qnil
;
7973 message (m
, a1
, a2
, a3
);
7974 Vmessage_log_max
= old_log_max
;
7978 /* Display the current message in the current mini-buffer. This is
7979 only called from error handlers in process.c, and is not time
7985 if (!NILP (echo_area_buffer
[0]))
7988 string
= Fcurrent_message ();
7989 message3 (string
, SBYTES (string
),
7990 !NILP (current_buffer
->enable_multibyte_characters
));
7995 /* Make sure echo area buffers in `echo_buffers' are live.
7996 If they aren't, make new ones. */
7999 ensure_echo_area_buffers ()
8003 for (i
= 0; i
< 2; ++i
)
8004 if (!BUFFERP (echo_buffer
[i
])
8005 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8008 Lisp_Object old_buffer
;
8011 old_buffer
= echo_buffer
[i
];
8012 sprintf (name
, " *Echo Area %d*", i
);
8013 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8014 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8016 for (j
= 0; j
< 2; ++j
)
8017 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8018 echo_area_buffer
[j
] = echo_buffer
[i
];
8023 /* Call FN with args A1..A4 with either the current or last displayed
8024 echo_area_buffer as current buffer.
8026 WHICH zero means use the current message buffer
8027 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8028 from echo_buffer[] and clear it.
8030 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8031 suitable buffer from echo_buffer[] and clear it.
8033 Value is what FN returns. */
8036 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8039 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8045 int this_one
, the_other
, clear_buffer_p
, rc
;
8046 int count
= SPECPDL_INDEX ();
8048 /* If buffers aren't live, make new ones. */
8049 ensure_echo_area_buffers ();
8054 this_one
= 0, the_other
= 1;
8056 this_one
= 1, the_other
= 0;
8058 /* Choose a suitable buffer from echo_buffer[] is we don't
8060 if (NILP (echo_area_buffer
[this_one
]))
8062 echo_area_buffer
[this_one
]
8063 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8064 ? echo_buffer
[the_other
]
8065 : echo_buffer
[this_one
]);
8069 buffer
= echo_area_buffer
[this_one
];
8071 /* Don't get confused by reusing the buffer used for echoing
8072 for a different purpose. */
8073 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8076 record_unwind_protect (unwind_with_echo_area_buffer
,
8077 with_echo_area_buffer_unwind_data (w
));
8079 /* Make the echo area buffer current. Note that for display
8080 purposes, it is not necessary that the displayed window's buffer
8081 == current_buffer, except for text property lookup. So, let's
8082 only set that buffer temporarily here without doing a full
8083 Fset_window_buffer. We must also change w->pointm, though,
8084 because otherwise an assertions in unshow_buffer fails, and Emacs
8086 set_buffer_internal_1 (XBUFFER (buffer
));
8090 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8093 current_buffer
->undo_list
= Qt
;
8094 current_buffer
->read_only
= Qnil
;
8095 specbind (Qinhibit_read_only
, Qt
);
8096 specbind (Qinhibit_modification_hooks
, Qt
);
8098 if (clear_buffer_p
&& Z
> BEG
)
8101 xassert (BEGV
>= BEG
);
8102 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8104 rc
= fn (a1
, a2
, a3
, a4
);
8106 xassert (BEGV
>= BEG
);
8107 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8109 unbind_to (count
, Qnil
);
8114 /* Save state that should be preserved around the call to the function
8115 FN called in with_echo_area_buffer. */
8118 with_echo_area_buffer_unwind_data (w
)
8124 /* Reduce consing by keeping one vector in
8125 Vwith_echo_area_save_vector. */
8126 vector
= Vwith_echo_area_save_vector
;
8127 Vwith_echo_area_save_vector
= Qnil
;
8130 vector
= Fmake_vector (make_number (7), Qnil
);
8132 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
8133 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
8134 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
8138 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
8139 AREF (vector
, i
) = w
->buffer
; ++i
;
8140 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
8141 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
8146 for (; i
< end
; ++i
)
8147 AREF (vector
, i
) = Qnil
;
8150 xassert (i
== ASIZE (vector
));
8155 /* Restore global state from VECTOR which was created by
8156 with_echo_area_buffer_unwind_data. */
8159 unwind_with_echo_area_buffer (vector
)
8162 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8163 Vdeactivate_mark
= AREF (vector
, 1);
8164 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8166 if (WINDOWP (AREF (vector
, 3)))
8169 Lisp_Object buffer
, charpos
, bytepos
;
8171 w
= XWINDOW (AREF (vector
, 3));
8172 buffer
= AREF (vector
, 4);
8173 charpos
= AREF (vector
, 5);
8174 bytepos
= AREF (vector
, 6);
8177 set_marker_both (w
->pointm
, buffer
,
8178 XFASTINT (charpos
), XFASTINT (bytepos
));
8181 Vwith_echo_area_save_vector
= vector
;
8186 /* Set up the echo area for use by print functions. MULTIBYTE_P
8187 non-zero means we will print multibyte. */
8190 setup_echo_area_for_printing (multibyte_p
)
8193 /* If we can't find an echo area any more, exit. */
8194 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8197 ensure_echo_area_buffers ();
8199 if (!message_buf_print
)
8201 /* A message has been output since the last time we printed.
8202 Choose a fresh echo area buffer. */
8203 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8204 echo_area_buffer
[0] = echo_buffer
[1];
8206 echo_area_buffer
[0] = echo_buffer
[0];
8208 /* Switch to that buffer and clear it. */
8209 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8210 current_buffer
->truncate_lines
= Qnil
;
8214 int count
= SPECPDL_INDEX ();
8215 specbind (Qinhibit_read_only
, Qt
);
8216 /* Note that undo recording is always disabled. */
8218 unbind_to (count
, Qnil
);
8220 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8222 /* Set up the buffer for the multibyteness we need. */
8224 != !NILP (current_buffer
->enable_multibyte_characters
))
8225 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8227 /* Raise the frame containing the echo area. */
8228 if (minibuffer_auto_raise
)
8230 struct frame
*sf
= SELECTED_FRAME ();
8231 Lisp_Object mini_window
;
8232 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8233 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8236 message_log_maybe_newline ();
8237 message_buf_print
= 1;
8241 if (NILP (echo_area_buffer
[0]))
8243 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8244 echo_area_buffer
[0] = echo_buffer
[1];
8246 echo_area_buffer
[0] = echo_buffer
[0];
8249 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8251 /* Someone switched buffers between print requests. */
8252 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8253 current_buffer
->truncate_lines
= Qnil
;
8259 /* Display an echo area message in window W. Value is non-zero if W's
8260 height is changed. If display_last_displayed_message_p is
8261 non-zero, display the message that was last displayed, otherwise
8262 display the current message. */
8265 display_echo_area (w
)
8268 int i
, no_message_p
, window_height_changed_p
, count
;
8270 /* Temporarily disable garbage collections while displaying the echo
8271 area. This is done because a GC can print a message itself.
8272 That message would modify the echo area buffer's contents while a
8273 redisplay of the buffer is going on, and seriously confuse
8275 count
= inhibit_garbage_collection ();
8277 /* If there is no message, we must call display_echo_area_1
8278 nevertheless because it resizes the window. But we will have to
8279 reset the echo_area_buffer in question to nil at the end because
8280 with_echo_area_buffer will sets it to an empty buffer. */
8281 i
= display_last_displayed_message_p
? 1 : 0;
8282 no_message_p
= NILP (echo_area_buffer
[i
]);
8284 window_height_changed_p
8285 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8286 display_echo_area_1
,
8287 (EMACS_INT
) w
, Qnil
, 0, 0);
8290 echo_area_buffer
[i
] = Qnil
;
8292 unbind_to (count
, Qnil
);
8293 return window_height_changed_p
;
8297 /* Helper for display_echo_area. Display the current buffer which
8298 contains the current echo area message in window W, a mini-window,
8299 a pointer to which is passed in A1. A2..A4 are currently not used.
8300 Change the height of W so that all of the message is displayed.
8301 Value is non-zero if height of W was changed. */
8304 display_echo_area_1 (a1
, a2
, a3
, a4
)
8309 struct window
*w
= (struct window
*) a1
;
8311 struct text_pos start
;
8312 int window_height_changed_p
= 0;
8314 /* Do this before displaying, so that we have a large enough glyph
8315 matrix for the display. If we can't get enough space for the
8316 whole text, display the last N lines. That works by setting w->start. */
8317 window_height_changed_p
= resize_mini_window (w
, 0);
8319 /* Use the starting position chosen by resize_mini_window. */
8320 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8323 clear_glyph_matrix (w
->desired_matrix
);
8324 XSETWINDOW (window
, w
);
8325 try_window (window
, start
, 0);
8327 return window_height_changed_p
;
8331 /* Resize the echo area window to exactly the size needed for the
8332 currently displayed message, if there is one. If a mini-buffer
8333 is active, don't shrink it. */
8336 resize_echo_area_exactly ()
8338 if (BUFFERP (echo_area_buffer
[0])
8339 && WINDOWP (echo_area_window
))
8341 struct window
*w
= XWINDOW (echo_area_window
);
8343 Lisp_Object resize_exactly
;
8345 if (minibuf_level
== 0)
8346 resize_exactly
= Qt
;
8348 resize_exactly
= Qnil
;
8350 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8351 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8354 ++windows_or_buffers_changed
;
8355 ++update_mode_lines
;
8356 redisplay_internal (0);
8362 /* Callback function for with_echo_area_buffer, when used from
8363 resize_echo_area_exactly. A1 contains a pointer to the window to
8364 resize, EXACTLY non-nil means resize the mini-window exactly to the
8365 size of the text displayed. A3 and A4 are not used. Value is what
8366 resize_mini_window returns. */
8369 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8371 Lisp_Object exactly
;
8374 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8378 /* Resize mini-window W to fit the size of its contents. EXACT:P
8379 means size the window exactly to the size needed. Otherwise, it's
8380 only enlarged until W's buffer is empty.
8382 Set W->start to the right place to begin display. If the whole
8383 contents fit, start at the beginning. Otherwise, start so as
8384 to make the end of the contents appear. This is particularly
8385 important for y-or-n-p, but seems desirable generally.
8387 Value is non-zero if the window height has been changed. */
8390 resize_mini_window (w
, exact_p
)
8394 struct frame
*f
= XFRAME (w
->frame
);
8395 int window_height_changed_p
= 0;
8397 xassert (MINI_WINDOW_P (w
));
8399 /* By default, start display at the beginning. */
8400 set_marker_both (w
->start
, w
->buffer
,
8401 BUF_BEGV (XBUFFER (w
->buffer
)),
8402 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8404 /* Don't resize windows while redisplaying a window; it would
8405 confuse redisplay functions when the size of the window they are
8406 displaying changes from under them. Such a resizing can happen,
8407 for instance, when which-func prints a long message while
8408 we are running fontification-functions. We're running these
8409 functions with safe_call which binds inhibit-redisplay to t. */
8410 if (!NILP (Vinhibit_redisplay
))
8413 /* Nil means don't try to resize. */
8414 if (NILP (Vresize_mini_windows
)
8415 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8418 if (!FRAME_MINIBUF_ONLY_P (f
))
8421 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8422 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8423 int height
, max_height
;
8424 int unit
= FRAME_LINE_HEIGHT (f
);
8425 struct text_pos start
;
8426 struct buffer
*old_current_buffer
= NULL
;
8428 if (current_buffer
!= XBUFFER (w
->buffer
))
8430 old_current_buffer
= current_buffer
;
8431 set_buffer_internal (XBUFFER (w
->buffer
));
8434 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8436 /* Compute the max. number of lines specified by the user. */
8437 if (FLOATP (Vmax_mini_window_height
))
8438 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8439 else if (INTEGERP (Vmax_mini_window_height
))
8440 max_height
= XINT (Vmax_mini_window_height
);
8442 max_height
= total_height
/ 4;
8444 /* Correct that max. height if it's bogus. */
8445 max_height
= max (1, max_height
);
8446 max_height
= min (total_height
, max_height
);
8448 /* Find out the height of the text in the window. */
8449 if (it
.truncate_lines_p
)
8454 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8455 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8456 height
= it
.current_y
+ last_height
;
8458 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8459 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8460 height
= (height
+ unit
- 1) / unit
;
8463 /* Compute a suitable window start. */
8464 if (height
> max_height
)
8466 height
= max_height
;
8467 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8468 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8469 start
= it
.current
.pos
;
8472 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8473 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8475 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8477 /* Let it grow only, until we display an empty message, in which
8478 case the window shrinks again. */
8479 if (height
> WINDOW_TOTAL_LINES (w
))
8481 int old_height
= WINDOW_TOTAL_LINES (w
);
8482 freeze_window_starts (f
, 1);
8483 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8484 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8486 else if (height
< WINDOW_TOTAL_LINES (w
)
8487 && (exact_p
|| BEGV
== ZV
))
8489 int old_height
= WINDOW_TOTAL_LINES (w
);
8490 freeze_window_starts (f
, 0);
8491 shrink_mini_window (w
);
8492 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8497 /* Always resize to exact size needed. */
8498 if (height
> WINDOW_TOTAL_LINES (w
))
8500 int old_height
= WINDOW_TOTAL_LINES (w
);
8501 freeze_window_starts (f
, 1);
8502 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8503 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8505 else if (height
< WINDOW_TOTAL_LINES (w
))
8507 int old_height
= WINDOW_TOTAL_LINES (w
);
8508 freeze_window_starts (f
, 0);
8509 shrink_mini_window (w
);
8513 freeze_window_starts (f
, 1);
8514 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8517 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8521 if (old_current_buffer
)
8522 set_buffer_internal (old_current_buffer
);
8525 return window_height_changed_p
;
8529 /* Value is the current message, a string, or nil if there is no
8537 if (NILP (echo_area_buffer
[0]))
8541 with_echo_area_buffer (0, 0, current_message_1
,
8542 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8544 echo_area_buffer
[0] = Qnil
;
8552 current_message_1 (a1
, a2
, a3
, a4
)
8557 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8560 *msg
= make_buffer_string (BEG
, Z
, 1);
8567 /* Push the current message on Vmessage_stack for later restauration
8568 by restore_message. Value is non-zero if the current message isn't
8569 empty. This is a relatively infrequent operation, so it's not
8570 worth optimizing. */
8576 msg
= current_message ();
8577 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8578 return STRINGP (msg
);
8582 /* Restore message display from the top of Vmessage_stack. */
8589 xassert (CONSP (Vmessage_stack
));
8590 msg
= XCAR (Vmessage_stack
);
8592 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8594 message3_nolog (msg
, 0, 0);
8598 /* Handler for record_unwind_protect calling pop_message. */
8601 pop_message_unwind (dummy
)
8608 /* Pop the top-most entry off Vmessage_stack. */
8613 xassert (CONSP (Vmessage_stack
));
8614 Vmessage_stack
= XCDR (Vmessage_stack
);
8618 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8619 exits. If the stack is not empty, we have a missing pop_message
8623 check_message_stack ()
8625 if (!NILP (Vmessage_stack
))
8630 /* Truncate to NCHARS what will be displayed in the echo area the next
8631 time we display it---but don't redisplay it now. */
8634 truncate_echo_area (nchars
)
8638 echo_area_buffer
[0] = Qnil
;
8639 /* A null message buffer means that the frame hasn't really been
8640 initialized yet. Error messages get reported properly by
8641 cmd_error, so this must be just an informative message; toss it. */
8642 else if (!noninteractive
8644 && !NILP (echo_area_buffer
[0]))
8646 struct frame
*sf
= SELECTED_FRAME ();
8647 if (FRAME_MESSAGE_BUF (sf
))
8648 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8653 /* Helper function for truncate_echo_area. Truncate the current
8654 message to at most NCHARS characters. */
8657 truncate_message_1 (nchars
, a2
, a3
, a4
)
8662 if (BEG
+ nchars
< Z
)
8663 del_range (BEG
+ nchars
, Z
);
8665 echo_area_buffer
[0] = Qnil
;
8670 /* Set the current message to a substring of S or STRING.
8672 If STRING is a Lisp string, set the message to the first NBYTES
8673 bytes from STRING. NBYTES zero means use the whole string. If
8674 STRING is multibyte, the message will be displayed multibyte.
8676 If S is not null, set the message to the first LEN bytes of S. LEN
8677 zero means use the whole string. MULTIBYTE_P non-zero means S is
8678 multibyte. Display the message multibyte in that case.
8680 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8681 to t before calling set_message_1 (which calls insert).
8685 set_message (s
, string
, nbytes
, multibyte_p
)
8688 int nbytes
, multibyte_p
;
8690 message_enable_multibyte
8691 = ((s
&& multibyte_p
)
8692 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8694 with_echo_area_buffer (0, 0, set_message_1
,
8695 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8696 message_buf_print
= 0;
8697 help_echo_showing_p
= 0;
8701 /* Helper function for set_message. Arguments have the same meaning
8702 as there, with A1 corresponding to S and A2 corresponding to STRING
8703 This function is called with the echo area buffer being
8707 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8710 EMACS_INT nbytes
, multibyte_p
;
8712 const char *s
= (const char *) a1
;
8713 Lisp_Object string
= a2
;
8715 /* Change multibyteness of the echo buffer appropriately. */
8716 if (message_enable_multibyte
8717 != !NILP (current_buffer
->enable_multibyte_characters
))
8718 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8720 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8722 /* Insert new message at BEG. */
8723 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8726 if (STRINGP (string
))
8731 nbytes
= SBYTES (string
);
8732 nchars
= string_byte_to_char (string
, nbytes
);
8734 /* This function takes care of single/multibyte conversion. We
8735 just have to ensure that the echo area buffer has the right
8736 setting of enable_multibyte_characters. */
8737 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8742 nbytes
= strlen (s
);
8744 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8746 /* Convert from multi-byte to single-byte. */
8748 unsigned char work
[1];
8750 /* Convert a multibyte string to single-byte. */
8751 for (i
= 0; i
< nbytes
; i
+= n
)
8753 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8754 work
[0] = (ASCII_CHAR_P (c
)
8756 : multibyte_char_to_unibyte (c
, Qnil
));
8757 insert_1_both (work
, 1, 1, 1, 0, 0);
8760 else if (!multibyte_p
8761 && !NILP (current_buffer
->enable_multibyte_characters
))
8763 /* Convert from single-byte to multi-byte. */
8765 const unsigned char *msg
= (const unsigned char *) s
;
8766 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8768 /* Convert a single-byte string to multibyte. */
8769 for (i
= 0; i
< nbytes
; i
++)
8772 c
= unibyte_char_to_multibyte (c
);
8773 n
= CHAR_STRING (c
, str
);
8774 insert_1_both (str
, 1, n
, 1, 0, 0);
8778 insert_1 (s
, nbytes
, 1, 0, 0);
8785 /* Clear messages. CURRENT_P non-zero means clear the current
8786 message. LAST_DISPLAYED_P non-zero means clear the message
8790 clear_message (current_p
, last_displayed_p
)
8791 int current_p
, last_displayed_p
;
8795 echo_area_buffer
[0] = Qnil
;
8796 message_cleared_p
= 1;
8799 if (last_displayed_p
)
8800 echo_area_buffer
[1] = Qnil
;
8802 message_buf_print
= 0;
8805 /* Clear garbaged frames.
8807 This function is used where the old redisplay called
8808 redraw_garbaged_frames which in turn called redraw_frame which in
8809 turn called clear_frame. The call to clear_frame was a source of
8810 flickering. I believe a clear_frame is not necessary. It should
8811 suffice in the new redisplay to invalidate all current matrices,
8812 and ensure a complete redisplay of all windows. */
8815 clear_garbaged_frames ()
8819 Lisp_Object tail
, frame
;
8820 int changed_count
= 0;
8822 FOR_EACH_FRAME (tail
, frame
)
8824 struct frame
*f
= XFRAME (frame
);
8826 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8830 Fredraw_frame (frame
);
8831 f
->force_flush_display_p
= 1;
8833 clear_current_matrices (f
);
8842 ++windows_or_buffers_changed
;
8847 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8848 is non-zero update selected_frame. Value is non-zero if the
8849 mini-windows height has been changed. */
8852 echo_area_display (update_frame_p
)
8855 Lisp_Object mini_window
;
8858 int window_height_changed_p
= 0;
8859 struct frame
*sf
= SELECTED_FRAME ();
8861 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8862 w
= XWINDOW (mini_window
);
8863 f
= XFRAME (WINDOW_FRAME (w
));
8865 /* Don't display if frame is invisible or not yet initialized. */
8866 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8869 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8871 #ifdef HAVE_WINDOW_SYSTEM
8872 /* When Emacs starts, selected_frame may be a visible terminal
8873 frame, even if we run under a window system. If we let this
8874 through, a message would be displayed on the terminal. */
8875 if (EQ (selected_frame
, Vterminal_frame
)
8876 && !NILP (Vwindow_system
))
8878 #endif /* HAVE_WINDOW_SYSTEM */
8881 /* Redraw garbaged frames. */
8883 clear_garbaged_frames ();
8885 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8887 echo_area_window
= mini_window
;
8888 window_height_changed_p
= display_echo_area (w
);
8889 w
->must_be_updated_p
= 1;
8891 /* Update the display, unless called from redisplay_internal.
8892 Also don't update the screen during redisplay itself. The
8893 update will happen at the end of redisplay, and an update
8894 here could cause confusion. */
8895 if (update_frame_p
&& !redisplaying_p
)
8899 /* If the display update has been interrupted by pending
8900 input, update mode lines in the frame. Due to the
8901 pending input, it might have been that redisplay hasn't
8902 been called, so that mode lines above the echo area are
8903 garbaged. This looks odd, so we prevent it here. */
8904 if (!display_completed
)
8905 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8907 if (window_height_changed_p
8908 /* Don't do this if Emacs is shutting down. Redisplay
8909 needs to run hooks. */
8910 && !NILP (Vrun_hooks
))
8912 /* Must update other windows. Likewise as in other
8913 cases, don't let this update be interrupted by
8915 int count
= SPECPDL_INDEX ();
8916 specbind (Qredisplay_dont_pause
, Qt
);
8917 windows_or_buffers_changed
= 1;
8918 redisplay_internal (0);
8919 unbind_to (count
, Qnil
);
8921 else if (FRAME_WINDOW_P (f
) && n
== 0)
8923 /* Window configuration is the same as before.
8924 Can do with a display update of the echo area,
8925 unless we displayed some mode lines. */
8926 update_single_window (w
, 1);
8927 rif
->flush_display (f
);
8930 update_frame (f
, 1, 1);
8932 /* If cursor is in the echo area, make sure that the next
8933 redisplay displays the minibuffer, so that the cursor will
8934 be replaced with what the minibuffer wants. */
8935 if (cursor_in_echo_area
)
8936 ++windows_or_buffers_changed
;
8939 else if (!EQ (mini_window
, selected_window
))
8940 windows_or_buffers_changed
++;
8942 /* The current message is now also the last one displayed. */
8943 echo_area_buffer
[1] = echo_area_buffer
[0];
8945 /* Prevent redisplay optimization in redisplay_internal by resetting
8946 this_line_start_pos. This is done because the mini-buffer now
8947 displays the message instead of its buffer text. */
8948 if (EQ (mini_window
, selected_window
))
8949 CHARPOS (this_line_start_pos
) = 0;
8951 return window_height_changed_p
;
8956 /***********************************************************************
8957 Mode Lines and Frame Titles
8958 ***********************************************************************/
8960 /* A buffer for constructing non-propertized mode-line strings and
8961 frame titles in it; allocated from the heap in init_xdisp and
8962 resized as needed in store_mode_line_noprop_char. */
8964 static char *mode_line_noprop_buf
;
8966 /* The buffer's end, and a current output position in it. */
8968 static char *mode_line_noprop_buf_end
;
8969 static char *mode_line_noprop_ptr
;
8971 #define MODE_LINE_NOPROP_LEN(start) \
8972 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8975 MODE_LINE_DISPLAY
= 0,
8981 /* Alist that caches the results of :propertize.
8982 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8983 static Lisp_Object mode_line_proptrans_alist
;
8985 /* List of strings making up the mode-line. */
8986 static Lisp_Object mode_line_string_list
;
8988 /* Base face property when building propertized mode line string. */
8989 static Lisp_Object mode_line_string_face
;
8990 static Lisp_Object mode_line_string_face_prop
;
8993 /* Unwind data for mode line strings */
8995 static Lisp_Object Vmode_line_unwind_vector
;
8998 format_mode_line_unwind_data (obuf
, save_proptrans
)
8999 struct buffer
*obuf
;
9003 /* Reduce consing by keeping one vector in
9004 Vwith_echo_area_save_vector. */
9005 vector
= Vmode_line_unwind_vector
;
9006 Vmode_line_unwind_vector
= Qnil
;
9009 vector
= Fmake_vector (make_number (7), Qnil
);
9011 AREF (vector
, 0) = make_number (mode_line_target
);
9012 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
9013 AREF (vector
, 2) = mode_line_string_list
;
9014 AREF (vector
, 3) = (save_proptrans
? mode_line_proptrans_alist
: Qt
);
9015 AREF (vector
, 4) = mode_line_string_face
;
9016 AREF (vector
, 5) = mode_line_string_face_prop
;
9019 XSETBUFFER (AREF (vector
, 6), obuf
);
9021 AREF (vector
, 6) = Qnil
;
9027 unwind_format_mode_line (vector
)
9030 mode_line_target
= XINT (AREF (vector
, 0));
9031 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9032 mode_line_string_list
= AREF (vector
, 2);
9033 if (! EQ (AREF (vector
, 3), Qt
))
9034 mode_line_proptrans_alist
= AREF (vector
, 3);
9035 mode_line_string_face
= AREF (vector
, 4);
9036 mode_line_string_face_prop
= AREF (vector
, 5);
9038 if (!NILP (AREF (vector
, 6)))
9040 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9041 AREF (vector
, 6) = Qnil
;
9044 Vmode_line_unwind_vector
= vector
;
9049 /* Store a single character C for the frame title in mode_line_noprop_buf.
9050 Re-allocate mode_line_noprop_buf if necessary. */
9054 store_mode_line_noprop_char (char c
)
9056 store_mode_line_noprop_char (c
)
9060 /* If output position has reached the end of the allocated buffer,
9061 double the buffer's size. */
9062 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9064 int len
= MODE_LINE_NOPROP_LEN (0);
9065 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9066 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9067 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9068 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9071 *mode_line_noprop_ptr
++ = c
;
9075 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9076 mode_line_noprop_ptr. STR is the string to store. Do not copy
9077 characters that yield more columns than PRECISION; PRECISION <= 0
9078 means copy the whole string. Pad with spaces until FIELD_WIDTH
9079 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9080 pad. Called from display_mode_element when it is used to build a
9084 store_mode_line_noprop (str
, field_width
, precision
)
9085 const unsigned char *str
;
9086 int field_width
, precision
;
9091 /* Copy at most PRECISION chars from STR. */
9092 nbytes
= strlen (str
);
9093 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9095 store_mode_line_noprop_char (*str
++);
9097 /* Fill up with spaces until FIELD_WIDTH reached. */
9098 while (field_width
> 0
9101 store_mode_line_noprop_char (' ');
9108 /***********************************************************************
9110 ***********************************************************************/
9112 #ifdef HAVE_WINDOW_SYSTEM
9114 /* Set the title of FRAME, if it has changed. The title format is
9115 Vicon_title_format if FRAME is iconified, otherwise it is
9116 frame_title_format. */
9119 x_consider_frame_title (frame
)
9122 struct frame
*f
= XFRAME (frame
);
9124 if (FRAME_WINDOW_P (f
)
9125 || FRAME_MINIBUF_ONLY_P (f
)
9126 || f
->explicit_name
)
9128 /* Do we have more than one visible frame on this X display? */
9135 int count
= SPECPDL_INDEX ();
9137 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9139 Lisp_Object other_frame
= XCAR (tail
);
9140 struct frame
*tf
= XFRAME (other_frame
);
9143 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9144 && !FRAME_MINIBUF_ONLY_P (tf
)
9145 && !EQ (other_frame
, tip_frame
)
9146 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9150 /* Set global variable indicating that multiple frames exist. */
9151 multiple_frames
= CONSP (tail
);
9153 /* Switch to the buffer of selected window of the frame. Set up
9154 mode_line_target so that display_mode_element will output into
9155 mode_line_noprop_buf; then display the title. */
9156 record_unwind_protect (unwind_format_mode_line
,
9157 format_mode_line_unwind_data (current_buffer
, 0));
9159 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9160 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9162 mode_line_target
= MODE_LINE_TITLE
;
9163 title_start
= MODE_LINE_NOPROP_LEN (0);
9164 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9165 NULL
, DEFAULT_FACE_ID
);
9166 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9167 len
= MODE_LINE_NOPROP_LEN (title_start
);
9168 title
= mode_line_noprop_buf
+ title_start
;
9169 unbind_to (count
, Qnil
);
9171 /* Set the title only if it's changed. This avoids consing in
9172 the common case where it hasn't. (If it turns out that we've
9173 already wasted too much time by walking through the list with
9174 display_mode_element, then we might need to optimize at a
9175 higher level than this.) */
9176 if (! STRINGP (f
->name
)
9177 || SBYTES (f
->name
) != len
9178 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9179 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9183 #endif /* not HAVE_WINDOW_SYSTEM */
9188 /***********************************************************************
9190 ***********************************************************************/
9193 /* Prepare for redisplay by updating menu-bar item lists when
9194 appropriate. This can call eval. */
9197 prepare_menu_bars ()
9200 struct gcpro gcpro1
, gcpro2
;
9202 Lisp_Object tooltip_frame
;
9204 #ifdef HAVE_WINDOW_SYSTEM
9205 tooltip_frame
= tip_frame
;
9207 tooltip_frame
= Qnil
;
9210 /* Update all frame titles based on their buffer names, etc. We do
9211 this before the menu bars so that the buffer-menu will show the
9212 up-to-date frame titles. */
9213 #ifdef HAVE_WINDOW_SYSTEM
9214 if (windows_or_buffers_changed
|| update_mode_lines
)
9216 Lisp_Object tail
, frame
;
9218 FOR_EACH_FRAME (tail
, frame
)
9221 if (!EQ (frame
, tooltip_frame
)
9222 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9223 x_consider_frame_title (frame
);
9226 #endif /* HAVE_WINDOW_SYSTEM */
9228 /* Update the menu bar item lists, if appropriate. This has to be
9229 done before any actual redisplay or generation of display lines. */
9230 all_windows
= (update_mode_lines
9231 || buffer_shared
> 1
9232 || windows_or_buffers_changed
);
9235 Lisp_Object tail
, frame
;
9236 int count
= SPECPDL_INDEX ();
9237 /* 1 means that update_menu_bar has run its hooks
9238 so any further calls to update_menu_bar shouldn't do so again. */
9239 int menu_bar_hooks_run
= 0;
9241 record_unwind_save_match_data ();
9243 FOR_EACH_FRAME (tail
, frame
)
9247 /* Ignore tooltip frame. */
9248 if (EQ (frame
, tooltip_frame
))
9251 /* If a window on this frame changed size, report that to
9252 the user and clear the size-change flag. */
9253 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9255 Lisp_Object functions
;
9257 /* Clear flag first in case we get an error below. */
9258 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9259 functions
= Vwindow_size_change_functions
;
9260 GCPRO2 (tail
, functions
);
9262 while (CONSP (functions
))
9264 call1 (XCAR (functions
), frame
);
9265 functions
= XCDR (functions
);
9271 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9272 #ifdef HAVE_WINDOW_SYSTEM
9273 update_tool_bar (f
, 0);
9275 mac_update_title_bar (f
, 0);
9281 unbind_to (count
, Qnil
);
9285 struct frame
*sf
= SELECTED_FRAME ();
9286 update_menu_bar (sf
, 1, 0);
9287 #ifdef HAVE_WINDOW_SYSTEM
9288 update_tool_bar (sf
, 1);
9290 mac_update_title_bar (sf
, 1);
9295 /* Motif needs this. See comment in xmenu.c. Turn it off when
9296 pending_menu_activation is not defined. */
9297 #ifdef USE_X_TOOLKIT
9298 pending_menu_activation
= 0;
9303 /* Update the menu bar item list for frame F. This has to be done
9304 before we start to fill in any display lines, because it can call
9307 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9309 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9310 already ran the menu bar hooks for this redisplay, so there
9311 is no need to run them again. The return value is the
9312 updated value of this flag, to pass to the next call. */
9315 update_menu_bar (f
, save_match_data
, hooks_run
)
9317 int save_match_data
;
9321 register struct window
*w
;
9323 /* If called recursively during a menu update, do nothing. This can
9324 happen when, for instance, an activate-menubar-hook causes a
9326 if (inhibit_menubar_update
)
9329 window
= FRAME_SELECTED_WINDOW (f
);
9330 w
= XWINDOW (window
);
9332 #if 0 /* The if statement below this if statement used to include the
9333 condition !NILP (w->update_mode_line), rather than using
9334 update_mode_lines directly, and this if statement may have
9335 been added to make that condition work. Now the if
9336 statement below matches its comment, this isn't needed. */
9337 if (update_mode_lines
)
9338 w
->update_mode_line
= Qt
;
9341 if (FRAME_WINDOW_P (f
)
9343 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9344 || defined (USE_GTK)
9345 FRAME_EXTERNAL_MENU_BAR (f
)
9347 FRAME_MENU_BAR_LINES (f
) > 0
9349 : FRAME_MENU_BAR_LINES (f
) > 0)
9351 /* If the user has switched buffers or windows, we need to
9352 recompute to reflect the new bindings. But we'll
9353 recompute when update_mode_lines is set too; that means
9354 that people can use force-mode-line-update to request
9355 that the menu bar be recomputed. The adverse effect on
9356 the rest of the redisplay algorithm is about the same as
9357 windows_or_buffers_changed anyway. */
9358 if (windows_or_buffers_changed
9359 /* This used to test w->update_mode_line, but we believe
9360 there is no need to recompute the menu in that case. */
9361 || update_mode_lines
9362 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9363 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9364 != !NILP (w
->last_had_star
))
9365 || ((!NILP (Vtransient_mark_mode
)
9366 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9367 != !NILP (w
->region_showing
)))
9369 struct buffer
*prev
= current_buffer
;
9370 int count
= SPECPDL_INDEX ();
9372 specbind (Qinhibit_menubar_update
, Qt
);
9374 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9375 if (save_match_data
)
9376 record_unwind_save_match_data ();
9377 if (NILP (Voverriding_local_map_menu_flag
))
9379 specbind (Qoverriding_terminal_local_map
, Qnil
);
9380 specbind (Qoverriding_local_map
, Qnil
);
9385 /* Run the Lucid hook. */
9386 safe_run_hooks (Qactivate_menubar_hook
);
9388 /* If it has changed current-menubar from previous value,
9389 really recompute the menu-bar from the value. */
9390 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9391 call0 (Qrecompute_lucid_menubar
);
9393 safe_run_hooks (Qmenu_bar_update_hook
);
9398 XSETFRAME (Vmenu_updating_frame
, f
);
9399 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9401 /* Redisplay the menu bar in case we changed it. */
9402 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
9403 || defined (USE_GTK)
9404 if (FRAME_WINDOW_P (f
))
9407 /* All frames on Mac OS share the same menubar. So only
9408 the selected frame should be allowed to set it. */
9409 if (f
== SELECTED_FRAME ())
9411 set_frame_menubar (f
, 0, 0);
9414 /* On a terminal screen, the menu bar is an ordinary screen
9415 line, and this makes it get updated. */
9416 w
->update_mode_line
= Qt
;
9417 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9418 /* In the non-toolkit version, the menu bar is an ordinary screen
9419 line, and this makes it get updated. */
9420 w
->update_mode_line
= Qt
;
9421 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
9423 unbind_to (count
, Qnil
);
9424 set_buffer_internal_1 (prev
);
9433 /***********************************************************************
9435 ***********************************************************************/
9437 #ifdef HAVE_WINDOW_SYSTEM
9440 Nominal cursor position -- where to draw output.
9441 HPOS and VPOS are window relative glyph matrix coordinates.
9442 X and Y are window relative pixel coordinates. */
9444 struct cursor_pos output_cursor
;
9448 Set the global variable output_cursor to CURSOR. All cursor
9449 positions are relative to updated_window. */
9452 set_output_cursor (cursor
)
9453 struct cursor_pos
*cursor
;
9455 output_cursor
.hpos
= cursor
->hpos
;
9456 output_cursor
.vpos
= cursor
->vpos
;
9457 output_cursor
.x
= cursor
->x
;
9458 output_cursor
.y
= cursor
->y
;
9463 Set a nominal cursor position.
9465 HPOS and VPOS are column/row positions in a window glyph matrix. X
9466 and Y are window text area relative pixel positions.
9468 If this is done during an update, updated_window will contain the
9469 window that is being updated and the position is the future output
9470 cursor position for that window. If updated_window is null, use
9471 selected_window and display the cursor at the given position. */
9474 x_cursor_to (vpos
, hpos
, y
, x
)
9475 int vpos
, hpos
, y
, x
;
9479 /* If updated_window is not set, work on selected_window. */
9483 w
= XWINDOW (selected_window
);
9485 /* Set the output cursor. */
9486 output_cursor
.hpos
= hpos
;
9487 output_cursor
.vpos
= vpos
;
9488 output_cursor
.x
= x
;
9489 output_cursor
.y
= y
;
9491 /* If not called as part of an update, really display the cursor.
9492 This will also set the cursor position of W. */
9493 if (updated_window
== NULL
)
9496 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9497 if (rif
->flush_display_optional
)
9498 rif
->flush_display_optional (SELECTED_FRAME ());
9503 #endif /* HAVE_WINDOW_SYSTEM */
9506 /***********************************************************************
9508 ***********************************************************************/
9510 #ifdef HAVE_WINDOW_SYSTEM
9512 /* Where the mouse was last time we reported a mouse event. */
9514 FRAME_PTR last_mouse_frame
;
9516 /* Tool-bar item index of the item on which a mouse button was pressed
9519 int last_tool_bar_item
;
9522 /* Update the tool-bar item list for frame F. This has to be done
9523 before we start to fill in any display lines. Called from
9524 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9525 and restore it here. */
9528 update_tool_bar (f
, save_match_data
)
9530 int save_match_data
;
9532 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9533 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9535 int do_update
= WINDOWP (f
->tool_bar_window
)
9536 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9544 window
= FRAME_SELECTED_WINDOW (f
);
9545 w
= XWINDOW (window
);
9547 /* If the user has switched buffers or windows, we need to
9548 recompute to reflect the new bindings. But we'll
9549 recompute when update_mode_lines is set too; that means
9550 that people can use force-mode-line-update to request
9551 that the menu bar be recomputed. The adverse effect on
9552 the rest of the redisplay algorithm is about the same as
9553 windows_or_buffers_changed anyway. */
9554 if (windows_or_buffers_changed
9555 || !NILP (w
->update_mode_line
)
9556 || update_mode_lines
9557 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9558 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9559 != !NILP (w
->last_had_star
))
9560 || ((!NILP (Vtransient_mark_mode
)
9561 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9562 != !NILP (w
->region_showing
)))
9564 struct buffer
*prev
= current_buffer
;
9565 int count
= SPECPDL_INDEX ();
9566 Lisp_Object new_tool_bar
;
9568 struct gcpro gcpro1
;
9570 /* Set current_buffer to the buffer of the selected
9571 window of the frame, so that we get the right local
9573 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9575 /* Save match data, if we must. */
9576 if (save_match_data
)
9577 record_unwind_save_match_data ();
9579 /* Make sure that we don't accidentally use bogus keymaps. */
9580 if (NILP (Voverriding_local_map_menu_flag
))
9582 specbind (Qoverriding_terminal_local_map
, Qnil
);
9583 specbind (Qoverriding_local_map
, Qnil
);
9586 GCPRO1 (new_tool_bar
);
9588 /* Build desired tool-bar items from keymaps. */
9589 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9592 /* Redisplay the tool-bar if we changed it. */
9593 if (new_n_tool_bar
!= f
->n_tool_bar_items
9594 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9596 /* Redisplay that happens asynchronously due to an expose event
9597 may access f->tool_bar_items. Make sure we update both
9598 variables within BLOCK_INPUT so no such event interrupts. */
9600 f
->tool_bar_items
= new_tool_bar
;
9601 f
->n_tool_bar_items
= new_n_tool_bar
;
9602 w
->update_mode_line
= Qt
;
9608 unbind_to (count
, Qnil
);
9609 set_buffer_internal_1 (prev
);
9615 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9616 F's desired tool-bar contents. F->tool_bar_items must have
9617 been set up previously by calling prepare_menu_bars. */
9620 build_desired_tool_bar_string (f
)
9623 int i
, size
, size_needed
;
9624 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9625 Lisp_Object image
, plist
, props
;
9627 image
= plist
= props
= Qnil
;
9628 GCPRO3 (image
, plist
, props
);
9630 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9631 Otherwise, make a new string. */
9633 /* The size of the string we might be able to reuse. */
9634 size
= (STRINGP (f
->desired_tool_bar_string
)
9635 ? SCHARS (f
->desired_tool_bar_string
)
9638 /* We need one space in the string for each image. */
9639 size_needed
= f
->n_tool_bar_items
;
9641 /* Reuse f->desired_tool_bar_string, if possible. */
9642 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9643 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9647 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9648 Fremove_text_properties (make_number (0), make_number (size
),
9649 props
, f
->desired_tool_bar_string
);
9652 /* Put a `display' property on the string for the images to display,
9653 put a `menu_item' property on tool-bar items with a value that
9654 is the index of the item in F's tool-bar item vector. */
9655 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9657 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9659 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9660 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9661 int hmargin
, vmargin
, relief
, idx
, end
;
9662 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9664 /* If image is a vector, choose the image according to the
9666 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9667 if (VECTORP (image
))
9671 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9672 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9675 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9676 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9678 xassert (ASIZE (image
) >= idx
);
9679 image
= AREF (image
, idx
);
9684 /* Ignore invalid image specifications. */
9685 if (!valid_image_p (image
))
9688 /* Display the tool-bar button pressed, or depressed. */
9689 plist
= Fcopy_sequence (XCDR (image
));
9691 /* Compute margin and relief to draw. */
9692 relief
= (tool_bar_button_relief
>= 0
9693 ? tool_bar_button_relief
9694 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9695 hmargin
= vmargin
= relief
;
9697 if (INTEGERP (Vtool_bar_button_margin
)
9698 && XINT (Vtool_bar_button_margin
) > 0)
9700 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9701 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9703 else if (CONSP (Vtool_bar_button_margin
))
9705 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9706 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9707 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9709 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9710 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9711 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9714 if (auto_raise_tool_bar_buttons_p
)
9716 /* Add a `:relief' property to the image spec if the item is
9720 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9727 /* If image is selected, display it pressed, i.e. with a
9728 negative relief. If it's not selected, display it with a
9730 plist
= Fplist_put (plist
, QCrelief
,
9732 ? make_number (-relief
)
9733 : make_number (relief
)));
9738 /* Put a margin around the image. */
9739 if (hmargin
|| vmargin
)
9741 if (hmargin
== vmargin
)
9742 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9744 plist
= Fplist_put (plist
, QCmargin
,
9745 Fcons (make_number (hmargin
),
9746 make_number (vmargin
)));
9749 /* If button is not enabled, and we don't have special images
9750 for the disabled state, make the image appear disabled by
9751 applying an appropriate algorithm to it. */
9752 if (!enabled_p
&& idx
< 0)
9753 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9755 /* Put a `display' text property on the string for the image to
9756 display. Put a `menu-item' property on the string that gives
9757 the start of this item's properties in the tool-bar items
9759 image
= Fcons (Qimage
, plist
);
9760 props
= list4 (Qdisplay
, image
,
9761 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9763 /* Let the last image hide all remaining spaces in the tool bar
9764 string. The string can be longer than needed when we reuse a
9766 if (i
+ 1 == f
->n_tool_bar_items
)
9767 end
= SCHARS (f
->desired_tool_bar_string
);
9770 Fadd_text_properties (make_number (i
), make_number (end
),
9771 props
, f
->desired_tool_bar_string
);
9779 /* Display one line of the tool-bar of frame IT->f.
9781 HEIGHT specifies the desired height of the tool-bar line.
9782 If the actual height of the glyph row is less than HEIGHT, the
9783 row's height is increased to HEIGHT, and the icons are centered
9784 vertically in the new height.
9786 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
9787 count a final empty row in case the tool-bar width exactly matches
9792 display_tool_bar_line (it
, height
)
9796 struct glyph_row
*row
= it
->glyph_row
;
9797 int max_x
= it
->last_visible_x
;
9800 prepare_desired_row (row
);
9801 row
->y
= it
->current_y
;
9803 /* Note that this isn't made use of if the face hasn't a box,
9804 so there's no need to check the face here. */
9805 it
->start_of_box_run_p
= 1;
9807 while (it
->current_x
< max_x
)
9809 int x
, n_glyphs_before
, i
, nglyphs
;
9810 struct it it_before
;
9812 /* Get the next display element. */
9813 if (!get_next_display_element (it
))
9815 /* Don't count empty row if we are counting needed tool-bar lines. */
9816 if (height
< 0 && !it
->hpos
)
9821 /* Produce glyphs. */
9822 n_glyphs_before
= row
->used
[TEXT_AREA
];
9825 PRODUCE_GLYPHS (it
);
9827 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
9829 x
= it_before
.current_x
;
9832 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9834 if (x
+ glyph
->pixel_width
> max_x
)
9836 /* Glyph doesn't fit on line. Backtrack. */
9837 row
->used
[TEXT_AREA
] = n_glyphs_before
;
9839 /* If this is the only glyph on this line, it will never fit on the
9840 toolbar, so skip it. But ensure there is at least one glyph,
9841 so we don't accidentally disable the tool-bar. */
9842 if (n_glyphs_before
== 0
9843 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
9849 x
+= glyph
->pixel_width
;
9853 /* Stop at line ends. */
9854 if (ITERATOR_AT_END_OF_LINE_P (it
))
9857 set_iterator_to_next (it
, 1);
9862 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9864 /* Use default face for the border below the tool bar.
9866 FIXME: When auto-resize-tool-bars is grow-only, there is
9867 no additional border below the possibly empty tool-bar lines.
9868 So to make the extra empty lines look "normal", we have to
9869 use the tool-bar face for the border too. */
9870 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
9871 it
->face_id
= DEFAULT_FACE_ID
;
9873 extend_face_to_end_of_line (it
);
9874 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9875 last
->right_box_line_p
= 1;
9876 if (last
== row
->glyphs
[TEXT_AREA
])
9877 last
->left_box_line_p
= 1;
9879 /* Make line the desired height and center it vertically. */
9880 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
9882 /* Don't add more than one line height. */
9883 height
%= FRAME_LINE_HEIGHT (it
->f
);
9884 it
->max_ascent
+= height
/ 2;
9885 it
->max_descent
+= (height
+ 1) / 2;
9888 compute_line_metrics (it
);
9890 /* If line is empty, make it occupy the rest of the tool-bar. */
9891 if (!row
->displays_text_p
)
9893 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9894 row
->visible_height
= row
->height
;
9895 row
->ascent
= row
->phys_ascent
= 0;
9896 row
->extra_line_spacing
= 0;
9899 row
->full_width_p
= 1;
9900 row
->continued_p
= 0;
9901 row
->truncated_on_left_p
= 0;
9902 row
->truncated_on_right_p
= 0;
9904 it
->current_x
= it
->hpos
= 0;
9905 it
->current_y
+= row
->height
;
9911 /* Max tool-bar height. */
9913 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
9914 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
9916 /* Value is the number of screen lines needed to make all tool-bar
9917 items of frame F visible. The number of actual rows needed is
9918 returned in *N_ROWS if non-NULL. */
9921 tool_bar_lines_needed (f
, n_rows
)
9925 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9927 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
9928 the desired matrix, so use (unused) mode-line row as temporary row to
9929 avoid destroying the first tool-bar row. */
9930 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
9932 /* Initialize an iterator for iteration over
9933 F->desired_tool_bar_string in the tool-bar window of frame F. */
9934 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
9935 it
.first_visible_x
= 0;
9936 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9937 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9939 while (!ITERATOR_AT_END_P (&it
))
9941 clear_glyph_row (temp_row
);
9942 it
.glyph_row
= temp_row
;
9943 display_tool_bar_line (&it
, -1);
9945 clear_glyph_row (temp_row
);
9947 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
9949 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
9951 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9955 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9957 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9966 frame
= selected_frame
;
9968 CHECK_FRAME (frame
);
9971 if (WINDOWP (f
->tool_bar_window
)
9972 || (w
= XWINDOW (f
->tool_bar_window
),
9973 WINDOW_TOTAL_LINES (w
) > 0))
9975 update_tool_bar (f
, 1);
9976 if (f
->n_tool_bar_items
)
9978 build_desired_tool_bar_string (f
);
9979 nlines
= tool_bar_lines_needed (f
, NULL
);
9983 return make_number (nlines
);
9987 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9988 height should be changed. */
9991 redisplay_tool_bar (f
)
9996 struct glyph_row
*row
;
9998 #if defined (USE_GTK) || USE_MAC_TOOLBAR
9999 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10000 update_frame_tool_bar (f
);
10004 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10005 do anything. This means you must start with tool-bar-lines
10006 non-zero to get the auto-sizing effect. Or in other words, you
10007 can turn off tool-bars by specifying tool-bar-lines zero. */
10008 if (!WINDOWP (f
->tool_bar_window
)
10009 || (w
= XWINDOW (f
->tool_bar_window
),
10010 WINDOW_TOTAL_LINES (w
) == 0))
10013 /* Set up an iterator for the tool-bar window. */
10014 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10015 it
.first_visible_x
= 0;
10016 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10017 row
= it
.glyph_row
;
10019 /* Build a string that represents the contents of the tool-bar. */
10020 build_desired_tool_bar_string (f
);
10021 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10023 if (f
->n_tool_bar_rows
== 0)
10027 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10028 nlines
!= WINDOW_TOTAL_LINES (w
)))
10030 extern Lisp_Object Qtool_bar_lines
;
10032 int old_height
= WINDOW_TOTAL_LINES (w
);
10034 XSETFRAME (frame
, f
);
10035 Fmodify_frame_parameters (frame
,
10036 Fcons (Fcons (Qtool_bar_lines
,
10037 make_number (nlines
)),
10039 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10041 clear_glyph_matrix (w
->desired_matrix
);
10042 fonts_changed_p
= 1;
10048 /* Display as many lines as needed to display all tool-bar items. */
10050 if (f
->n_tool_bar_rows
> 0)
10052 int border
, rows
, height
, extra
;
10054 if (INTEGERP (Vtool_bar_border
))
10055 border
= XINT (Vtool_bar_border
);
10056 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10057 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10058 else if (EQ (Vtool_bar_border
, Qborder_width
))
10059 border
= f
->border_width
;
10065 rows
= f
->n_tool_bar_rows
;
10066 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10067 extra
= it
.last_visible_y
- border
- height
* rows
;
10069 while (it
.current_y
< it
.last_visible_y
)
10072 if (extra
> 0 && rows
-- > 0)
10074 h
= (extra
+ rows
- 1) / rows
;
10077 display_tool_bar_line (&it
, height
+ h
);
10082 while (it
.current_y
< it
.last_visible_y
)
10083 display_tool_bar_line (&it
, 0);
10086 /* It doesn't make much sense to try scrolling in the tool-bar
10087 window, so don't do it. */
10088 w
->desired_matrix
->no_scrolling_p
= 1;
10089 w
->must_be_updated_p
= 1;
10091 if (!NILP (Vauto_resize_tool_bars
))
10093 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10094 int change_height_p
= 0;
10096 /* If we couldn't display everything, change the tool-bar's
10097 height if there is room for more. */
10098 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10099 && it
.current_y
< max_tool_bar_height
)
10100 change_height_p
= 1;
10102 row
= it
.glyph_row
- 1;
10104 /* If there are blank lines at the end, except for a partially
10105 visible blank line at the end that is smaller than
10106 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10107 if (!row
->displays_text_p
10108 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10109 change_height_p
= 1;
10111 /* If row displays tool-bar items, but is partially visible,
10112 change the tool-bar's height. */
10113 if (row
->displays_text_p
10114 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10115 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10116 change_height_p
= 1;
10118 /* Resize windows as needed by changing the `tool-bar-lines'
10119 frame parameter. */
10120 if (change_height_p
)
10122 extern Lisp_Object Qtool_bar_lines
;
10124 int old_height
= WINDOW_TOTAL_LINES (w
);
10126 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10128 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10129 && !f
->minimize_tool_bar_window_p
)
10130 ? (nlines
> old_height
)
10131 : (nlines
!= old_height
));
10132 f
->minimize_tool_bar_window_p
= 0;
10134 if (change_height_p
)
10136 XSETFRAME (frame
, f
);
10137 Fmodify_frame_parameters (frame
,
10138 Fcons (Fcons (Qtool_bar_lines
,
10139 make_number (nlines
)),
10141 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10143 clear_glyph_matrix (w
->desired_matrix
);
10144 f
->n_tool_bar_rows
= nrows
;
10145 fonts_changed_p
= 1;
10152 f
->minimize_tool_bar_window_p
= 0;
10157 /* Get information about the tool-bar item which is displayed in GLYPH
10158 on frame F. Return in *PROP_IDX the index where tool-bar item
10159 properties start in F->tool_bar_items. Value is zero if
10160 GLYPH doesn't display a tool-bar item. */
10163 tool_bar_item_info (f
, glyph
, prop_idx
)
10165 struct glyph
*glyph
;
10172 /* This function can be called asynchronously, which means we must
10173 exclude any possibility that Fget_text_property signals an
10175 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10176 charpos
= max (0, charpos
);
10178 /* Get the text property `menu-item' at pos. The value of that
10179 property is the start index of this item's properties in
10180 F->tool_bar_items. */
10181 prop
= Fget_text_property (make_number (charpos
),
10182 Qmenu_item
, f
->current_tool_bar_string
);
10183 if (INTEGERP (prop
))
10185 *prop_idx
= XINT (prop
);
10195 /* Get information about the tool-bar item at position X/Y on frame F.
10196 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10197 the current matrix of the tool-bar window of F, or NULL if not
10198 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10199 item in F->tool_bar_items. Value is
10201 -1 if X/Y is not on a tool-bar item
10202 0 if X/Y is on the same item that was highlighted before.
10206 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10209 struct glyph
**glyph
;
10210 int *hpos
, *vpos
, *prop_idx
;
10212 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10213 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10216 /* Find the glyph under X/Y. */
10217 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10218 if (*glyph
== NULL
)
10221 /* Get the start of this tool-bar item's properties in
10222 f->tool_bar_items. */
10223 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10226 /* Is mouse on the highlighted item? */
10227 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10228 && *vpos
>= dpyinfo
->mouse_face_beg_row
10229 && *vpos
<= dpyinfo
->mouse_face_end_row
10230 && (*vpos
> dpyinfo
->mouse_face_beg_row
10231 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10232 && (*vpos
< dpyinfo
->mouse_face_end_row
10233 || *hpos
< dpyinfo
->mouse_face_end_col
10234 || dpyinfo
->mouse_face_past_end
))
10242 Handle mouse button event on the tool-bar of frame F, at
10243 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10244 0 for button release. MODIFIERS is event modifiers for button
10248 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10251 unsigned int modifiers
;
10253 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10254 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10255 int hpos
, vpos
, prop_idx
;
10256 struct glyph
*glyph
;
10257 Lisp_Object enabled_p
;
10259 /* If not on the highlighted tool-bar item, return. */
10260 frame_to_window_pixel_xy (w
, &x
, &y
);
10261 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10264 /* If item is disabled, do nothing. */
10265 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10266 if (NILP (enabled_p
))
10271 /* Show item in pressed state. */
10272 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10273 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10274 last_tool_bar_item
= prop_idx
;
10278 Lisp_Object key
, frame
;
10279 struct input_event event
;
10280 EVENT_INIT (event
);
10282 /* Show item in released state. */
10283 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10284 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10286 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10288 XSETFRAME (frame
, f
);
10289 event
.kind
= TOOL_BAR_EVENT
;
10290 event
.frame_or_window
= frame
;
10292 kbd_buffer_store_event (&event
);
10294 event
.kind
= TOOL_BAR_EVENT
;
10295 event
.frame_or_window
= frame
;
10297 event
.modifiers
= modifiers
;
10298 kbd_buffer_store_event (&event
);
10299 last_tool_bar_item
= -1;
10304 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10305 tool-bar window-relative coordinates X/Y. Called from
10306 note_mouse_highlight. */
10309 note_tool_bar_highlight (f
, x
, y
)
10313 Lisp_Object window
= f
->tool_bar_window
;
10314 struct window
*w
= XWINDOW (window
);
10315 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10317 struct glyph
*glyph
;
10318 struct glyph_row
*row
;
10320 Lisp_Object enabled_p
;
10322 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10323 int mouse_down_p
, rc
;
10325 /* Function note_mouse_highlight is called with negative x(y
10326 values when mouse moves outside of the frame. */
10327 if (x
<= 0 || y
<= 0)
10329 clear_mouse_face (dpyinfo
);
10333 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10336 /* Not on tool-bar item. */
10337 clear_mouse_face (dpyinfo
);
10341 /* On same tool-bar item as before. */
10342 goto set_help_echo
;
10344 clear_mouse_face (dpyinfo
);
10346 /* Mouse is down, but on different tool-bar item? */
10347 mouse_down_p
= (dpyinfo
->grabbed
10348 && f
== last_mouse_frame
10349 && FRAME_LIVE_P (f
));
10351 && last_tool_bar_item
!= prop_idx
)
10354 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10355 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10357 /* If tool-bar item is not enabled, don't highlight it. */
10358 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10359 if (!NILP (enabled_p
))
10361 /* Compute the x-position of the glyph. In front and past the
10362 image is a space. We include this in the highlighted area. */
10363 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10364 for (i
= x
= 0; i
< hpos
; ++i
)
10365 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10367 /* Record this as the current active region. */
10368 dpyinfo
->mouse_face_beg_col
= hpos
;
10369 dpyinfo
->mouse_face_beg_row
= vpos
;
10370 dpyinfo
->mouse_face_beg_x
= x
;
10371 dpyinfo
->mouse_face_beg_y
= row
->y
;
10372 dpyinfo
->mouse_face_past_end
= 0;
10374 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10375 dpyinfo
->mouse_face_end_row
= vpos
;
10376 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10377 dpyinfo
->mouse_face_end_y
= row
->y
;
10378 dpyinfo
->mouse_face_window
= window
;
10379 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10381 /* Display it as active. */
10382 show_mouse_face (dpyinfo
, draw
);
10383 dpyinfo
->mouse_face_image_state
= draw
;
10388 /* Set help_echo_string to a help string to display for this tool-bar item.
10389 XTread_socket does the rest. */
10390 help_echo_object
= help_echo_window
= Qnil
;
10391 help_echo_pos
= -1;
10392 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10393 if (NILP (help_echo_string
))
10394 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10397 #endif /* HAVE_WINDOW_SYSTEM */
10401 /************************************************************************
10402 Horizontal scrolling
10403 ************************************************************************/
10405 static int hscroll_window_tree
P_ ((Lisp_Object
));
10406 static int hscroll_windows
P_ ((Lisp_Object
));
10408 /* For all leaf windows in the window tree rooted at WINDOW, set their
10409 hscroll value so that PT is (i) visible in the window, and (ii) so
10410 that it is not within a certain margin at the window's left and
10411 right border. Value is non-zero if any window's hscroll has been
10415 hscroll_window_tree (window
)
10416 Lisp_Object window
;
10418 int hscrolled_p
= 0;
10419 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10420 int hscroll_step_abs
= 0;
10421 double hscroll_step_rel
= 0;
10423 if (hscroll_relative_p
)
10425 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10426 if (hscroll_step_rel
< 0)
10428 hscroll_relative_p
= 0;
10429 hscroll_step_abs
= 0;
10432 else if (INTEGERP (Vhscroll_step
))
10434 hscroll_step_abs
= XINT (Vhscroll_step
);
10435 if (hscroll_step_abs
< 0)
10436 hscroll_step_abs
= 0;
10439 hscroll_step_abs
= 0;
10441 while (WINDOWP (window
))
10443 struct window
*w
= XWINDOW (window
);
10445 if (WINDOWP (w
->hchild
))
10446 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10447 else if (WINDOWP (w
->vchild
))
10448 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10449 else if (w
->cursor
.vpos
>= 0)
10452 int text_area_width
;
10453 struct glyph_row
*current_cursor_row
10454 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10455 struct glyph_row
*desired_cursor_row
10456 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10457 struct glyph_row
*cursor_row
10458 = (desired_cursor_row
->enabled_p
10459 ? desired_cursor_row
10460 : current_cursor_row
);
10462 text_area_width
= window_box_width (w
, TEXT_AREA
);
10464 /* Scroll when cursor is inside this scroll margin. */
10465 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10467 if ((XFASTINT (w
->hscroll
)
10468 && w
->cursor
.x
<= h_margin
)
10469 || (cursor_row
->enabled_p
10470 && cursor_row
->truncated_on_right_p
10471 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
10475 struct buffer
*saved_current_buffer
;
10479 /* Find point in a display of infinite width. */
10480 saved_current_buffer
= current_buffer
;
10481 current_buffer
= XBUFFER (w
->buffer
);
10483 if (w
== XWINDOW (selected_window
))
10484 pt
= BUF_PT (current_buffer
);
10487 pt
= marker_position (w
->pointm
);
10488 pt
= max (BEGV
, pt
);
10492 /* Move iterator to pt starting at cursor_row->start in
10493 a line with infinite width. */
10494 init_to_row_start (&it
, w
, cursor_row
);
10495 it
.last_visible_x
= INFINITY
;
10496 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10497 current_buffer
= saved_current_buffer
;
10499 /* Position cursor in window. */
10500 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10501 hscroll
= max (0, (it
.current_x
10502 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10503 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10504 : (text_area_width
/ 2))))
10505 / FRAME_COLUMN_WIDTH (it
.f
);
10506 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10508 if (hscroll_relative_p
)
10509 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10512 wanted_x
= text_area_width
10513 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10516 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10520 if (hscroll_relative_p
)
10521 wanted_x
= text_area_width
* hscroll_step_rel
10524 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10527 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10529 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10531 /* Don't call Fset_window_hscroll if value hasn't
10532 changed because it will prevent redisplay
10534 if (XFASTINT (w
->hscroll
) != hscroll
)
10536 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10537 w
->hscroll
= make_number (hscroll
);
10546 /* Value is non-zero if hscroll of any leaf window has been changed. */
10547 return hscrolled_p
;
10551 /* Set hscroll so that cursor is visible and not inside horizontal
10552 scroll margins for all windows in the tree rooted at WINDOW. See
10553 also hscroll_window_tree above. Value is non-zero if any window's
10554 hscroll has been changed. If it has, desired matrices on the frame
10555 of WINDOW are cleared. */
10558 hscroll_windows (window
)
10559 Lisp_Object window
;
10563 if (automatic_hscrolling_p
)
10565 hscrolled_p
= hscroll_window_tree (window
);
10567 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10571 return hscrolled_p
;
10576 /************************************************************************
10578 ************************************************************************/
10580 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10581 to a non-zero value. This is sometimes handy to have in a debugger
10586 /* First and last unchanged row for try_window_id. */
10588 int debug_first_unchanged_at_end_vpos
;
10589 int debug_last_unchanged_at_beg_vpos
;
10591 /* Delta vpos and y. */
10593 int debug_dvpos
, debug_dy
;
10595 /* Delta in characters and bytes for try_window_id. */
10597 int debug_delta
, debug_delta_bytes
;
10599 /* Values of window_end_pos and window_end_vpos at the end of
10602 EMACS_INT debug_end_pos
, debug_end_vpos
;
10604 /* Append a string to W->desired_matrix->method. FMT is a printf
10605 format string. A1...A9 are a supplement for a variable-length
10606 argument list. If trace_redisplay_p is non-zero also printf the
10607 resulting string to stderr. */
10610 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10613 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10616 char *method
= w
->desired_matrix
->method
;
10617 int len
= strlen (method
);
10618 int size
= sizeof w
->desired_matrix
->method
;
10619 int remaining
= size
- len
- 1;
10621 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10622 if (len
&& remaining
)
10625 --remaining
, ++len
;
10628 strncpy (method
+ len
, buffer
, remaining
);
10630 if (trace_redisplay_p
)
10631 fprintf (stderr
, "%p (%s): %s\n",
10633 ((BUFFERP (w
->buffer
)
10634 && STRINGP (XBUFFER (w
->buffer
)->name
))
10635 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10640 #endif /* GLYPH_DEBUG */
10643 /* Value is non-zero if all changes in window W, which displays
10644 current_buffer, are in the text between START and END. START is a
10645 buffer position, END is given as a distance from Z. Used in
10646 redisplay_internal for display optimization. */
10649 text_outside_line_unchanged_p (w
, start
, end
)
10653 int unchanged_p
= 1;
10655 /* If text or overlays have changed, see where. */
10656 if (XFASTINT (w
->last_modified
) < MODIFF
10657 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10659 /* Gap in the line? */
10660 if (GPT
< start
|| Z
- GPT
< end
)
10663 /* Changes start in front of the line, or end after it? */
10665 && (BEG_UNCHANGED
< start
- 1
10666 || END_UNCHANGED
< end
))
10669 /* If selective display, can't optimize if changes start at the
10670 beginning of the line. */
10672 && INTEGERP (current_buffer
->selective_display
)
10673 && XINT (current_buffer
->selective_display
) > 0
10674 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10677 /* If there are overlays at the start or end of the line, these
10678 may have overlay strings with newlines in them. A change at
10679 START, for instance, may actually concern the display of such
10680 overlay strings as well, and they are displayed on different
10681 lines. So, quickly rule out this case. (For the future, it
10682 might be desirable to implement something more telling than
10683 just BEG/END_UNCHANGED.) */
10686 if (BEG
+ BEG_UNCHANGED
== start
10687 && overlay_touches_p (start
))
10689 if (END_UNCHANGED
== end
10690 && overlay_touches_p (Z
- end
))
10695 return unchanged_p
;
10699 /* Do a frame update, taking possible shortcuts into account. This is
10700 the main external entry point for redisplay.
10702 If the last redisplay displayed an echo area message and that message
10703 is no longer requested, we clear the echo area or bring back the
10704 mini-buffer if that is in use. */
10709 redisplay_internal (0);
10714 overlay_arrow_string_or_property (var
)
10719 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
10722 return Voverlay_arrow_string
;
10725 /* Return 1 if there are any overlay-arrows in current_buffer. */
10727 overlay_arrow_in_current_buffer_p ()
10731 for (vlist
= Voverlay_arrow_variable_list
;
10733 vlist
= XCDR (vlist
))
10735 Lisp_Object var
= XCAR (vlist
);
10738 if (!SYMBOLP (var
))
10740 val
= find_symbol_value (var
);
10742 && current_buffer
== XMARKER (val
)->buffer
)
10749 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
10753 overlay_arrows_changed_p ()
10757 for (vlist
= Voverlay_arrow_variable_list
;
10759 vlist
= XCDR (vlist
))
10761 Lisp_Object var
= XCAR (vlist
);
10762 Lisp_Object val
, pstr
;
10764 if (!SYMBOLP (var
))
10766 val
= find_symbol_value (var
);
10767 if (!MARKERP (val
))
10769 if (! EQ (COERCE_MARKER (val
),
10770 Fget (var
, Qlast_arrow_position
))
10771 || ! (pstr
= overlay_arrow_string_or_property (var
),
10772 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
10778 /* Mark overlay arrows to be updated on next redisplay. */
10781 update_overlay_arrows (up_to_date
)
10786 for (vlist
= Voverlay_arrow_variable_list
;
10788 vlist
= XCDR (vlist
))
10790 Lisp_Object var
= XCAR (vlist
);
10792 if (!SYMBOLP (var
))
10795 if (up_to_date
> 0)
10797 Lisp_Object val
= find_symbol_value (var
);
10798 Fput (var
, Qlast_arrow_position
,
10799 COERCE_MARKER (val
));
10800 Fput (var
, Qlast_arrow_string
,
10801 overlay_arrow_string_or_property (var
));
10803 else if (up_to_date
< 0
10804 || !NILP (Fget (var
, Qlast_arrow_position
)))
10806 Fput (var
, Qlast_arrow_position
, Qt
);
10807 Fput (var
, Qlast_arrow_string
, Qt
);
10813 /* Return overlay arrow string to display at row.
10814 Return integer (bitmap number) for arrow bitmap in left fringe.
10815 Return nil if no overlay arrow. */
10818 overlay_arrow_at_row (it
, row
)
10820 struct glyph_row
*row
;
10824 for (vlist
= Voverlay_arrow_variable_list
;
10826 vlist
= XCDR (vlist
))
10828 Lisp_Object var
= XCAR (vlist
);
10831 if (!SYMBOLP (var
))
10834 val
= find_symbol_value (var
);
10837 && current_buffer
== XMARKER (val
)->buffer
10838 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10840 if (FRAME_WINDOW_P (it
->f
)
10841 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10843 #ifdef HAVE_WINDOW_SYSTEM
10844 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10847 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10848 return make_number (fringe_bitmap
);
10851 return make_number (-1); /* Use default arrow bitmap */
10853 return overlay_arrow_string_or_property (var
);
10860 /* Return 1 if point moved out of or into a composition. Otherwise
10861 return 0. PREV_BUF and PREV_PT are the last point buffer and
10862 position. BUF and PT are the current point buffer and position. */
10865 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10866 struct buffer
*prev_buf
, *buf
;
10869 EMACS_INT start
, end
;
10871 Lisp_Object buffer
;
10873 XSETBUFFER (buffer
, buf
);
10874 /* Check a composition at the last point if point moved within the
10876 if (prev_buf
== buf
)
10879 /* Point didn't move. */
10882 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10883 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10884 && COMPOSITION_VALID_P (start
, end
, prop
)
10885 && start
< prev_pt
&& end
> prev_pt
)
10886 /* The last point was within the composition. Return 1 iff
10887 point moved out of the composition. */
10888 return (pt
<= start
|| pt
>= end
);
10891 /* Check a composition at the current point. */
10892 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10893 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10894 && COMPOSITION_VALID_P (start
, end
, prop
)
10895 && start
< pt
&& end
> pt
);
10899 /* Reconsider the setting of B->clip_changed which is displayed
10903 reconsider_clip_changes (w
, b
)
10907 if (b
->clip_changed
10908 && !NILP (w
->window_end_valid
)
10909 && w
->current_matrix
->buffer
== b
10910 && w
->current_matrix
->zv
== BUF_ZV (b
)
10911 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10912 b
->clip_changed
= 0;
10914 /* If display wasn't paused, and W is not a tool bar window, see if
10915 point has been moved into or out of a composition. In that case,
10916 we set b->clip_changed to 1 to force updating the screen. If
10917 b->clip_changed has already been set to 1, we can skip this
10919 if (!b
->clip_changed
10920 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10924 if (w
== XWINDOW (selected_window
))
10925 pt
= BUF_PT (current_buffer
);
10927 pt
= marker_position (w
->pointm
);
10929 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10930 || pt
!= XINT (w
->last_point
))
10931 && check_point_in_composition (w
->current_matrix
->buffer
,
10932 XINT (w
->last_point
),
10933 XBUFFER (w
->buffer
), pt
))
10934 b
->clip_changed
= 1;
10939 /* Select FRAME to forward the values of frame-local variables into C
10940 variables so that the redisplay routines can access those values
10944 select_frame_for_redisplay (frame
)
10947 Lisp_Object tail
, sym
, val
;
10948 Lisp_Object old
= selected_frame
;
10950 selected_frame
= frame
;
10952 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10953 if (CONSP (XCAR (tail
))
10954 && (sym
= XCAR (XCAR (tail
)),
10956 && (sym
= indirect_variable (sym
),
10957 val
= SYMBOL_VALUE (sym
),
10958 (BUFFER_LOCAL_VALUEP (val
)
10959 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10960 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10961 /* Use find_symbol_value rather than Fsymbol_value
10962 to avoid an error if it is void. */
10963 find_symbol_value (sym
);
10965 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10966 if (CONSP (XCAR (tail
))
10967 && (sym
= XCAR (XCAR (tail
)),
10969 && (sym
= indirect_variable (sym
),
10970 val
= SYMBOL_VALUE (sym
),
10971 (BUFFER_LOCAL_VALUEP (val
)
10972 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10973 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10974 find_symbol_value (sym
);
10978 #define STOP_POLLING \
10979 do { if (! polling_stopped_here) stop_polling (); \
10980 polling_stopped_here = 1; } while (0)
10982 #define RESUME_POLLING \
10983 do { if (polling_stopped_here) start_polling (); \
10984 polling_stopped_here = 0; } while (0)
10987 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10988 response to any user action; therefore, we should preserve the echo
10989 area. (Actually, our caller does that job.) Perhaps in the future
10990 avoid recentering windows if it is not necessary; currently that
10991 causes some problems. */
10994 redisplay_internal (preserve_echo_area
)
10995 int preserve_echo_area
;
10997 struct window
*w
= XWINDOW (selected_window
);
11000 int must_finish
= 0;
11001 struct text_pos tlbufpos
, tlendpos
;
11002 int number_of_visible_frames
;
11005 int polling_stopped_here
= 0;
11007 /* Non-zero means redisplay has to consider all windows on all
11008 frames. Zero means, only selected_window is considered. */
11009 int consider_all_windows_p
;
11011 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11013 /* No redisplay if running in batch mode or frame is not yet fully
11014 initialized, or redisplay is explicitly turned off by setting
11015 Vinhibit_redisplay. */
11017 || !NILP (Vinhibit_redisplay
))
11020 /* Don't examine these until after testing Vinhibit_redisplay.
11021 When Emacs is shutting down, perhaps because its connection to
11022 X has dropped, we should not look at them at all. */
11023 f
= XFRAME (w
->frame
);
11024 sf
= SELECTED_FRAME ();
11026 if (!f
->glyphs_initialized_p
)
11029 /* The flag redisplay_performed_directly_p is set by
11030 direct_output_for_insert when it already did the whole screen
11031 update necessary. */
11032 if (redisplay_performed_directly_p
)
11034 redisplay_performed_directly_p
= 0;
11035 if (!hscroll_windows (selected_window
))
11039 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
11040 if (popup_activated ())
11044 /* I don't think this happens but let's be paranoid. */
11045 if (redisplaying_p
)
11048 /* Record a function that resets redisplaying_p to its old value
11049 when we leave this function. */
11050 count
= SPECPDL_INDEX ();
11051 record_unwind_protect (unwind_redisplay
,
11052 Fcons (make_number (redisplaying_p
), selected_frame
));
11054 specbind (Qinhibit_free_realized_faces
, Qnil
);
11057 Lisp_Object tail
, frame
;
11059 FOR_EACH_FRAME (tail
, frame
)
11061 struct frame
*f
= XFRAME (frame
);
11062 f
->already_hscrolled_p
= 0;
11068 reconsider_clip_changes (w
, current_buffer
);
11069 last_escape_glyph_frame
= NULL
;
11070 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11072 /* If new fonts have been loaded that make a glyph matrix adjustment
11073 necessary, do it. */
11074 if (fonts_changed_p
)
11076 adjust_glyphs (NULL
);
11077 ++windows_or_buffers_changed
;
11078 fonts_changed_p
= 0;
11081 /* If face_change_count is non-zero, init_iterator will free all
11082 realized faces, which includes the faces referenced from current
11083 matrices. So, we can't reuse current matrices in this case. */
11084 if (face_change_count
)
11085 ++windows_or_buffers_changed
;
11087 if (! FRAME_WINDOW_P (sf
)
11088 && previous_terminal_frame
!= sf
)
11090 /* Since frames on an ASCII terminal share the same display
11091 area, displaying a different frame means redisplay the whole
11093 windows_or_buffers_changed
++;
11094 SET_FRAME_GARBAGED (sf
);
11095 XSETFRAME (Vterminal_frame
, sf
);
11097 previous_terminal_frame
= sf
;
11099 /* Set the visible flags for all frames. Do this before checking
11100 for resized or garbaged frames; they want to know if their frames
11101 are visible. See the comment in frame.h for
11102 FRAME_SAMPLE_VISIBILITY. */
11104 Lisp_Object tail
, frame
;
11106 number_of_visible_frames
= 0;
11108 FOR_EACH_FRAME (tail
, frame
)
11110 struct frame
*f
= XFRAME (frame
);
11112 FRAME_SAMPLE_VISIBILITY (f
);
11113 if (FRAME_VISIBLE_P (f
))
11114 ++number_of_visible_frames
;
11115 clear_desired_matrices (f
);
11119 /* Notice any pending interrupt request to change frame size. */
11120 do_pending_window_change (1);
11122 /* Clear frames marked as garbaged. */
11123 if (frame_garbaged
)
11124 clear_garbaged_frames ();
11126 /* Build menubar and tool-bar items. */
11127 if (NILP (Vmemory_full
))
11128 prepare_menu_bars ();
11130 if (windows_or_buffers_changed
)
11131 update_mode_lines
++;
11133 /* Detect case that we need to write or remove a star in the mode line. */
11134 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11136 w
->update_mode_line
= Qt
;
11137 if (buffer_shared
> 1)
11138 update_mode_lines
++;
11141 /* Avoid invocation of point motion hooks by `current_column' below. */
11142 count1
= SPECPDL_INDEX ();
11143 specbind (Qinhibit_point_motion_hooks
, Qt
);
11145 /* If %c is in the mode line, update it if needed. */
11146 if (!NILP (w
->column_number_displayed
)
11147 /* This alternative quickly identifies a common case
11148 where no change is needed. */
11149 && !(PT
== XFASTINT (w
->last_point
)
11150 && XFASTINT (w
->last_modified
) >= MODIFF
11151 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11152 && (XFASTINT (w
->column_number_displayed
)
11153 != (int) current_column ())) /* iftc */
11154 w
->update_mode_line
= Qt
;
11156 unbind_to (count1
, Qnil
);
11158 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11160 /* The variable buffer_shared is set in redisplay_window and
11161 indicates that we redisplay a buffer in different windows. See
11163 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11164 || cursor_type_changed
);
11166 /* If specs for an arrow have changed, do thorough redisplay
11167 to ensure we remove any arrow that should no longer exist. */
11168 if (overlay_arrows_changed_p ())
11169 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11171 /* Normally the message* functions will have already displayed and
11172 updated the echo area, but the frame may have been trashed, or
11173 the update may have been preempted, so display the echo area
11174 again here. Checking message_cleared_p captures the case that
11175 the echo area should be cleared. */
11176 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11177 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11178 || (message_cleared_p
11179 && minibuf_level
== 0
11180 /* If the mini-window is currently selected, this means the
11181 echo-area doesn't show through. */
11182 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11184 int window_height_changed_p
= echo_area_display (0);
11187 /* If we don't display the current message, don't clear the
11188 message_cleared_p flag, because, if we did, we wouldn't clear
11189 the echo area in the next redisplay which doesn't preserve
11191 if (!display_last_displayed_message_p
)
11192 message_cleared_p
= 0;
11194 if (fonts_changed_p
)
11196 else if (window_height_changed_p
)
11198 consider_all_windows_p
= 1;
11199 ++update_mode_lines
;
11200 ++windows_or_buffers_changed
;
11202 /* If window configuration was changed, frames may have been
11203 marked garbaged. Clear them or we will experience
11204 surprises wrt scrolling. */
11205 if (frame_garbaged
)
11206 clear_garbaged_frames ();
11209 else if (EQ (selected_window
, minibuf_window
)
11210 && (current_buffer
->clip_changed
11211 || XFASTINT (w
->last_modified
) < MODIFF
11212 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11213 && resize_mini_window (w
, 0))
11215 /* Resized active mini-window to fit the size of what it is
11216 showing if its contents might have changed. */
11218 consider_all_windows_p
= 1;
11219 ++windows_or_buffers_changed
;
11220 ++update_mode_lines
;
11222 /* If window configuration was changed, frames may have been
11223 marked garbaged. Clear them or we will experience
11224 surprises wrt scrolling. */
11225 if (frame_garbaged
)
11226 clear_garbaged_frames ();
11230 /* If showing the region, and mark has changed, we must redisplay
11231 the whole window. The assignment to this_line_start_pos prevents
11232 the optimization directly below this if-statement. */
11233 if (((!NILP (Vtransient_mark_mode
)
11234 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11235 != !NILP (w
->region_showing
))
11236 || (!NILP (w
->region_showing
)
11237 && !EQ (w
->region_showing
,
11238 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11239 CHARPOS (this_line_start_pos
) = 0;
11241 /* Optimize the case that only the line containing the cursor in the
11242 selected window has changed. Variables starting with this_ are
11243 set in display_line and record information about the line
11244 containing the cursor. */
11245 tlbufpos
= this_line_start_pos
;
11246 tlendpos
= this_line_end_pos
;
11247 if (!consider_all_windows_p
11248 && CHARPOS (tlbufpos
) > 0
11249 && NILP (w
->update_mode_line
)
11250 && !current_buffer
->clip_changed
11251 && !current_buffer
->prevent_redisplay_optimizations_p
11252 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11253 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11254 /* Make sure recorded data applies to current buffer, etc. */
11255 && this_line_buffer
== current_buffer
11256 && current_buffer
== XBUFFER (w
->buffer
)
11257 && NILP (w
->force_start
)
11258 && NILP (w
->optional_new_start
)
11259 /* Point must be on the line that we have info recorded about. */
11260 && PT
>= CHARPOS (tlbufpos
)
11261 && PT
<= Z
- CHARPOS (tlendpos
)
11262 /* All text outside that line, including its final newline,
11263 must be unchanged */
11264 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11265 CHARPOS (tlendpos
)))
11267 if (CHARPOS (tlbufpos
) > BEGV
11268 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11269 && (CHARPOS (tlbufpos
) == ZV
11270 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11271 /* Former continuation line has disappeared by becoming empty */
11273 else if (XFASTINT (w
->last_modified
) < MODIFF
11274 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11275 || MINI_WINDOW_P (w
))
11277 /* We have to handle the case of continuation around a
11278 wide-column character (See the comment in indent.c around
11281 For instance, in the following case:
11283 -------- Insert --------
11284 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11285 J_I_ ==> J_I_ `^^' are cursors.
11289 As we have to redraw the line above, we should goto cancel. */
11292 int line_height_before
= this_line_pixel_height
;
11294 /* Note that start_display will handle the case that the
11295 line starting at tlbufpos is a continuation lines. */
11296 start_display (&it
, w
, tlbufpos
);
11298 /* Implementation note: It this still necessary? */
11299 if (it
.current_x
!= this_line_start_x
)
11302 TRACE ((stderr
, "trying display optimization 1\n"));
11303 w
->cursor
.vpos
= -1;
11304 overlay_arrow_seen
= 0;
11305 it
.vpos
= this_line_vpos
;
11306 it
.current_y
= this_line_y
;
11307 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11308 display_line (&it
);
11310 /* If line contains point, is not continued,
11311 and ends at same distance from eob as before, we win */
11312 if (w
->cursor
.vpos
>= 0
11313 /* Line is not continued, otherwise this_line_start_pos
11314 would have been set to 0 in display_line. */
11315 && CHARPOS (this_line_start_pos
)
11316 /* Line ends as before. */
11317 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11318 /* Line has same height as before. Otherwise other lines
11319 would have to be shifted up or down. */
11320 && this_line_pixel_height
== line_height_before
)
11322 /* If this is not the window's last line, we must adjust
11323 the charstarts of the lines below. */
11324 if (it
.current_y
< it
.last_visible_y
)
11326 struct glyph_row
*row
11327 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11328 int delta
, delta_bytes
;
11330 if (Z
- CHARPOS (tlendpos
) == ZV
)
11332 /* This line ends at end of (accessible part of)
11333 buffer. There is no newline to count. */
11335 - CHARPOS (tlendpos
)
11336 - MATRIX_ROW_START_CHARPOS (row
));
11337 delta_bytes
= (Z_BYTE
11338 - BYTEPOS (tlendpos
)
11339 - MATRIX_ROW_START_BYTEPOS (row
));
11343 /* This line ends in a newline. Must take
11344 account of the newline and the rest of the
11345 text that follows. */
11347 - CHARPOS (tlendpos
)
11348 - MATRIX_ROW_START_CHARPOS (row
));
11349 delta_bytes
= (Z_BYTE
11350 - BYTEPOS (tlendpos
)
11351 - MATRIX_ROW_START_BYTEPOS (row
));
11354 increment_matrix_positions (w
->current_matrix
,
11355 this_line_vpos
+ 1,
11356 w
->current_matrix
->nrows
,
11357 delta
, delta_bytes
);
11360 /* If this row displays text now but previously didn't,
11361 or vice versa, w->window_end_vpos may have to be
11363 if ((it
.glyph_row
- 1)->displays_text_p
)
11365 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11366 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11368 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11369 && this_line_vpos
> 0)
11370 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11371 w
->window_end_valid
= Qnil
;
11373 /* Update hint: No need to try to scroll in update_window. */
11374 w
->desired_matrix
->no_scrolling_p
= 1;
11377 *w
->desired_matrix
->method
= 0;
11378 debug_method_add (w
, "optimization 1");
11380 #ifdef HAVE_WINDOW_SYSTEM
11381 update_window_fringes (w
, 0);
11388 else if (/* Cursor position hasn't changed. */
11389 PT
== XFASTINT (w
->last_point
)
11390 /* Make sure the cursor was last displayed
11391 in this window. Otherwise we have to reposition it. */
11392 && 0 <= w
->cursor
.vpos
11393 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11397 do_pending_window_change (1);
11399 /* We used to always goto end_of_redisplay here, but this
11400 isn't enough if we have a blinking cursor. */
11401 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11402 goto end_of_redisplay
;
11406 /* If highlighting the region, or if the cursor is in the echo area,
11407 then we can't just move the cursor. */
11408 else if (! (!NILP (Vtransient_mark_mode
)
11409 && !NILP (current_buffer
->mark_active
))
11410 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11411 || highlight_nonselected_windows
)
11412 && NILP (w
->region_showing
)
11413 && NILP (Vshow_trailing_whitespace
)
11414 && !cursor_in_echo_area
)
11417 struct glyph_row
*row
;
11419 /* Skip from tlbufpos to PT and see where it is. Note that
11420 PT may be in invisible text. If so, we will end at the
11421 next visible position. */
11422 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11423 NULL
, DEFAULT_FACE_ID
);
11424 it
.current_x
= this_line_start_x
;
11425 it
.current_y
= this_line_y
;
11426 it
.vpos
= this_line_vpos
;
11428 /* The call to move_it_to stops in front of PT, but
11429 moves over before-strings. */
11430 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11432 if (it
.vpos
== this_line_vpos
11433 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11436 xassert (this_line_vpos
== it
.vpos
);
11437 xassert (this_line_y
== it
.current_y
);
11438 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11440 *w
->desired_matrix
->method
= 0;
11441 debug_method_add (w
, "optimization 3");
11450 /* Text changed drastically or point moved off of line. */
11451 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11454 CHARPOS (this_line_start_pos
) = 0;
11455 consider_all_windows_p
|= buffer_shared
> 1;
11456 ++clear_face_cache_count
;
11457 #ifdef HAVE_WINDOW_SYSTEM
11458 ++clear_image_cache_count
;
11461 /* Build desired matrices, and update the display. If
11462 consider_all_windows_p is non-zero, do it for all windows on all
11463 frames. Otherwise do it for selected_window, only. */
11465 if (consider_all_windows_p
)
11467 Lisp_Object tail
, frame
;
11469 FOR_EACH_FRAME (tail
, frame
)
11470 XFRAME (frame
)->updated_p
= 0;
11472 /* Recompute # windows showing selected buffer. This will be
11473 incremented each time such a window is displayed. */
11476 FOR_EACH_FRAME (tail
, frame
)
11478 struct frame
*f
= XFRAME (frame
);
11480 if (FRAME_WINDOW_P (f
) || f
== sf
)
11482 if (! EQ (frame
, selected_frame
))
11483 /* Select the frame, for the sake of frame-local
11485 select_frame_for_redisplay (frame
);
11487 /* Mark all the scroll bars to be removed; we'll redeem
11488 the ones we want when we redisplay their windows. */
11489 if (condemn_scroll_bars_hook
)
11490 condemn_scroll_bars_hook (f
);
11492 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11493 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11495 /* Any scroll bars which redisplay_windows should have
11496 nuked should now go away. */
11497 if (judge_scroll_bars_hook
)
11498 judge_scroll_bars_hook (f
);
11500 /* If fonts changed, display again. */
11501 /* ??? rms: I suspect it is a mistake to jump all the way
11502 back to retry here. It should just retry this frame. */
11503 if (fonts_changed_p
)
11506 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11508 /* See if we have to hscroll. */
11509 if (!f
->already_hscrolled_p
)
11511 f
->already_hscrolled_p
= 1;
11512 if (hscroll_windows (f
->root_window
))
11516 /* Prevent various kinds of signals during display
11517 update. stdio is not robust about handling
11518 signals, which can cause an apparent I/O
11520 if (interrupt_input
)
11521 unrequest_sigio ();
11524 /* Update the display. */
11525 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11526 pause
|= update_frame (f
, 0, 0);
11527 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11539 /* Do the mark_window_display_accurate after all windows have
11540 been redisplayed because this call resets flags in buffers
11541 which are needed for proper redisplay. */
11542 FOR_EACH_FRAME (tail
, frame
)
11544 struct frame
*f
= XFRAME (frame
);
11547 mark_window_display_accurate (f
->root_window
, 1);
11548 if (frame_up_to_date_hook
)
11549 frame_up_to_date_hook (f
);
11554 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11556 Lisp_Object mini_window
;
11557 struct frame
*mini_frame
;
11559 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11560 /* Use list_of_error, not Qerror, so that
11561 we catch only errors and don't run the debugger. */
11562 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11564 redisplay_window_error
);
11566 /* Compare desired and current matrices, perform output. */
11569 /* If fonts changed, display again. */
11570 if (fonts_changed_p
)
11573 /* Prevent various kinds of signals during display update.
11574 stdio is not robust about handling signals,
11575 which can cause an apparent I/O error. */
11576 if (interrupt_input
)
11577 unrequest_sigio ();
11580 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11582 if (hscroll_windows (selected_window
))
11585 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11586 pause
= update_frame (sf
, 0, 0);
11589 /* We may have called echo_area_display at the top of this
11590 function. If the echo area is on another frame, that may
11591 have put text on a frame other than the selected one, so the
11592 above call to update_frame would not have caught it. Catch
11594 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11595 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11597 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11599 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11600 pause
|= update_frame (mini_frame
, 0, 0);
11601 if (!pause
&& hscroll_windows (mini_window
))
11606 /* If display was paused because of pending input, make sure we do a
11607 thorough update the next time. */
11610 /* Prevent the optimization at the beginning of
11611 redisplay_internal that tries a single-line update of the
11612 line containing the cursor in the selected window. */
11613 CHARPOS (this_line_start_pos
) = 0;
11615 /* Let the overlay arrow be updated the next time. */
11616 update_overlay_arrows (0);
11618 /* If we pause after scrolling, some rows in the current
11619 matrices of some windows are not valid. */
11620 if (!WINDOW_FULL_WIDTH_P (w
)
11621 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11622 update_mode_lines
= 1;
11626 if (!consider_all_windows_p
)
11628 /* This has already been done above if
11629 consider_all_windows_p is set. */
11630 mark_window_display_accurate_1 (w
, 1);
11632 /* Say overlay arrows are up to date. */
11633 update_overlay_arrows (1);
11635 if (frame_up_to_date_hook
!= 0)
11636 frame_up_to_date_hook (sf
);
11639 update_mode_lines
= 0;
11640 windows_or_buffers_changed
= 0;
11641 cursor_type_changed
= 0;
11644 /* Start SIGIO interrupts coming again. Having them off during the
11645 code above makes it less likely one will discard output, but not
11646 impossible, since there might be stuff in the system buffer here.
11647 But it is much hairier to try to do anything about that. */
11648 if (interrupt_input
)
11652 /* If a frame has become visible which was not before, redisplay
11653 again, so that we display it. Expose events for such a frame
11654 (which it gets when becoming visible) don't call the parts of
11655 redisplay constructing glyphs, so simply exposing a frame won't
11656 display anything in this case. So, we have to display these
11657 frames here explicitly. */
11660 Lisp_Object tail
, frame
;
11663 FOR_EACH_FRAME (tail
, frame
)
11665 int this_is_visible
= 0;
11667 if (XFRAME (frame
)->visible
)
11668 this_is_visible
= 1;
11669 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
11670 if (XFRAME (frame
)->visible
)
11671 this_is_visible
= 1;
11673 if (this_is_visible
)
11677 if (new_count
!= number_of_visible_frames
)
11678 windows_or_buffers_changed
++;
11681 /* Change frame size now if a change is pending. */
11682 do_pending_window_change (1);
11684 /* If we just did a pending size change, or have additional
11685 visible frames, redisplay again. */
11686 if (windows_or_buffers_changed
&& !pause
)
11689 /* Clear the face cache eventually. */
11690 if (consider_all_windows_p
)
11692 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
11694 clear_face_cache (0);
11695 clear_face_cache_count
= 0;
11697 #ifdef HAVE_WINDOW_SYSTEM
11698 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
11700 Lisp_Object tail
, frame
;
11701 FOR_EACH_FRAME (tail
, frame
)
11703 struct frame
*f
= XFRAME (frame
);
11704 if (FRAME_WINDOW_P (f
))
11705 clear_image_cache (f
, 0);
11707 clear_image_cache_count
= 0;
11709 #endif /* HAVE_WINDOW_SYSTEM */
11713 unbind_to (count
, Qnil
);
11718 /* Redisplay, but leave alone any recent echo area message unless
11719 another message has been requested in its place.
11721 This is useful in situations where you need to redisplay but no
11722 user action has occurred, making it inappropriate for the message
11723 area to be cleared. See tracking_off and
11724 wait_reading_process_output for examples of these situations.
11726 FROM_WHERE is an integer saying from where this function was
11727 called. This is useful for debugging. */
11730 redisplay_preserve_echo_area (from_where
)
11733 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
11735 if (!NILP (echo_area_buffer
[1]))
11737 /* We have a previously displayed message, but no current
11738 message. Redisplay the previous message. */
11739 display_last_displayed_message_p
= 1;
11740 redisplay_internal (1);
11741 display_last_displayed_message_p
= 0;
11744 redisplay_internal (1);
11746 if (rif
!= NULL
&& rif
->flush_display_optional
)
11747 rif
->flush_display_optional (NULL
);
11751 /* Function registered with record_unwind_protect in
11752 redisplay_internal. Reset redisplaying_p to the value it had
11753 before redisplay_internal was called, and clear
11754 prevent_freeing_realized_faces_p. It also selects the previously
11758 unwind_redisplay (val
)
11761 Lisp_Object old_redisplaying_p
, old_frame
;
11763 old_redisplaying_p
= XCAR (val
);
11764 redisplaying_p
= XFASTINT (old_redisplaying_p
);
11765 old_frame
= XCDR (val
);
11766 if (! EQ (old_frame
, selected_frame
))
11767 select_frame_for_redisplay (old_frame
);
11772 /* Mark the display of window W as accurate or inaccurate. If
11773 ACCURATE_P is non-zero mark display of W as accurate. If
11774 ACCURATE_P is zero, arrange for W to be redisplayed the next time
11775 redisplay_internal is called. */
11778 mark_window_display_accurate_1 (w
, accurate_p
)
11782 if (BUFFERP (w
->buffer
))
11784 struct buffer
*b
= XBUFFER (w
->buffer
);
11787 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
11788 w
->last_overlay_modified
11789 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
11791 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
11795 b
->clip_changed
= 0;
11796 b
->prevent_redisplay_optimizations_p
= 0;
11798 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
11799 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
11800 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
11801 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
11803 w
->current_matrix
->buffer
= b
;
11804 w
->current_matrix
->begv
= BUF_BEGV (b
);
11805 w
->current_matrix
->zv
= BUF_ZV (b
);
11807 w
->last_cursor
= w
->cursor
;
11808 w
->last_cursor_off_p
= w
->cursor_off_p
;
11810 if (w
== XWINDOW (selected_window
))
11811 w
->last_point
= make_number (BUF_PT (b
));
11813 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
11819 w
->window_end_valid
= w
->buffer
;
11820 #if 0 /* This is incorrect with variable-height lines. */
11821 xassert (XINT (w
->window_end_vpos
)
11822 < (WINDOW_TOTAL_LINES (w
)
11823 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
11825 w
->update_mode_line
= Qnil
;
11830 /* Mark the display of windows in the window tree rooted at WINDOW as
11831 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
11832 windows as accurate. If ACCURATE_P is zero, arrange for windows to
11833 be redisplayed the next time redisplay_internal is called. */
11836 mark_window_display_accurate (window
, accurate_p
)
11837 Lisp_Object window
;
11842 for (; !NILP (window
); window
= w
->next
)
11844 w
= XWINDOW (window
);
11845 mark_window_display_accurate_1 (w
, accurate_p
);
11847 if (!NILP (w
->vchild
))
11848 mark_window_display_accurate (w
->vchild
, accurate_p
);
11849 if (!NILP (w
->hchild
))
11850 mark_window_display_accurate (w
->hchild
, accurate_p
);
11855 update_overlay_arrows (1);
11859 /* Force a thorough redisplay the next time by setting
11860 last_arrow_position and last_arrow_string to t, which is
11861 unequal to any useful value of Voverlay_arrow_... */
11862 update_overlay_arrows (-1);
11867 /* Return value in display table DP (Lisp_Char_Table *) for character
11868 C. Since a display table doesn't have any parent, we don't have to
11869 follow parent. Do not call this function directly but use the
11870 macro DISP_CHAR_VECTOR. */
11873 disp_char_vector (dp
, c
)
11874 struct Lisp_Char_Table
*dp
;
11879 if (ASCII_CHAR_P (c
))
11882 if (SUB_CHAR_TABLE_P (val
))
11883 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
11889 XSETCHAR_TABLE (table
, dp
);
11890 val
= char_table_ref (table
, c
);
11899 /***********************************************************************
11901 ***********************************************************************/
11903 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11906 redisplay_windows (window
)
11907 Lisp_Object window
;
11909 while (!NILP (window
))
11911 struct window
*w
= XWINDOW (window
);
11913 if (!NILP (w
->hchild
))
11914 redisplay_windows (w
->hchild
);
11915 else if (!NILP (w
->vchild
))
11916 redisplay_windows (w
->vchild
);
11919 displayed_buffer
= XBUFFER (w
->buffer
);
11920 /* Use list_of_error, not Qerror, so that
11921 we catch only errors and don't run the debugger. */
11922 internal_condition_case_1 (redisplay_window_0
, window
,
11924 redisplay_window_error
);
11932 redisplay_window_error ()
11934 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11939 redisplay_window_0 (window
)
11940 Lisp_Object window
;
11942 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11943 redisplay_window (window
, 0);
11948 redisplay_window_1 (window
)
11949 Lisp_Object window
;
11951 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11952 redisplay_window (window
, 1);
11957 /* Increment GLYPH until it reaches END or CONDITION fails while
11958 adding (GLYPH)->pixel_width to X. */
11960 #define SKIP_GLYPHS(glyph, end, x, condition) \
11963 (x) += (glyph)->pixel_width; \
11966 while ((glyph) < (end) && (condition))
11969 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11970 DELTA is the number of bytes by which positions recorded in ROW
11971 differ from current buffer positions.
11973 Return 0 if cursor is not on this row. 1 otherwise. */
11976 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11978 struct glyph_row
*row
;
11979 struct glyph_matrix
*matrix
;
11980 int delta
, delta_bytes
, dy
, dvpos
;
11982 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11983 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11984 struct glyph
*cursor
= NULL
;
11985 /* The first glyph that starts a sequence of glyphs from string. */
11986 struct glyph
*string_start
;
11987 /* The X coordinate of string_start. */
11988 int string_start_x
;
11989 /* The last known character position. */
11990 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11991 /* The last known character position before string_start. */
11992 int string_before_pos
;
11995 int cursor_from_overlay_pos
= 0;
11996 int pt_old
= PT
- delta
;
11998 /* Skip over glyphs not having an object at the start of the row.
11999 These are special glyphs like truncation marks on terminal
12001 if (row
->displays_text_p
)
12003 && INTEGERP (glyph
->object
)
12004 && glyph
->charpos
< 0)
12006 x
+= glyph
->pixel_width
;
12010 string_start
= NULL
;
12012 && !INTEGERP (glyph
->object
)
12013 && (!BUFFERP (glyph
->object
)
12014 || (last_pos
= glyph
->charpos
) < pt_old
))
12016 if (! STRINGP (glyph
->object
))
12018 string_start
= NULL
;
12019 x
+= glyph
->pixel_width
;
12021 if (cursor_from_overlay_pos
12022 && last_pos
>= cursor_from_overlay_pos
)
12024 cursor_from_overlay_pos
= 0;
12030 if (string_start
== NULL
)
12032 string_before_pos
= last_pos
;
12033 string_start
= glyph
;
12034 string_start_x
= x
;
12036 /* Skip all glyphs from string. */
12041 if ((cursor
== NULL
|| glyph
> cursor
)
12042 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12043 Qcursor
, (glyph
)->object
),
12045 && (pos
= string_buffer_position (w
, glyph
->object
,
12046 string_before_pos
),
12047 (pos
== 0 /* From overlay */
12048 || pos
== pt_old
)))
12050 /* Estimate overlay buffer position from the buffer
12051 positions of the glyphs before and after the overlay.
12052 Add 1 to last_pos so that if point corresponds to the
12053 glyph right after the overlay, we still use a 'cursor'
12054 property found in that overlay. */
12055 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12056 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12060 x
+= glyph
->pixel_width
;
12063 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12067 if (cursor
!= NULL
)
12072 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12074 /* Scan back over the ellipsis glyphs, decrementing positions. */
12075 while (glyph
> row
->glyphs
[TEXT_AREA
]
12076 && (glyph
- 1)->charpos
== last_pos
)
12077 glyph
--, x
-= glyph
->pixel_width
;
12078 /* That loop always goes one position too far,
12079 including the glyph before the ellipsis.
12080 So scan forward over that one. */
12081 x
+= glyph
->pixel_width
;
12084 else if (string_start
12085 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12087 /* We may have skipped over point because the previous glyphs
12088 are from string. As there's no easy way to know the
12089 character position of the current glyph, find the correct
12090 glyph on point by scanning from string_start again. */
12092 Lisp_Object string
;
12093 struct glyph
*stop
= glyph
;
12096 limit
= make_number (pt_old
+ 1);
12097 glyph
= string_start
;
12098 x
= string_start_x
;
12099 string
= glyph
->object
;
12100 pos
= string_buffer_position (w
, string
, string_before_pos
);
12101 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12102 because we always put cursor after overlay strings. */
12103 while (pos
== 0 && glyph
< stop
)
12105 string
= glyph
->object
;
12106 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12108 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12111 while (glyph
< stop
)
12113 pos
= XINT (Fnext_single_char_property_change
12114 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12117 /* Skip glyphs from the same string. */
12118 string
= glyph
->object
;
12119 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12120 /* Skip glyphs from an overlay. */
12121 while (glyph
< stop
12122 && ! string_buffer_position (w
, glyph
->object
, pos
))
12124 string
= glyph
->object
;
12125 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12129 /* If we reached the end of the line, and end was from a string,
12130 cursor is not on this line. */
12131 if (glyph
== end
&& row
->continued_p
)
12135 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12137 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12138 w
->cursor
.y
= row
->y
+ dy
;
12140 if (w
== XWINDOW (selected_window
))
12142 if (!row
->continued_p
12143 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12146 this_line_buffer
= XBUFFER (w
->buffer
);
12148 CHARPOS (this_line_start_pos
)
12149 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12150 BYTEPOS (this_line_start_pos
)
12151 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12153 CHARPOS (this_line_end_pos
)
12154 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12155 BYTEPOS (this_line_end_pos
)
12156 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12158 this_line_y
= w
->cursor
.y
;
12159 this_line_pixel_height
= row
->height
;
12160 this_line_vpos
= w
->cursor
.vpos
;
12161 this_line_start_x
= row
->x
;
12164 CHARPOS (this_line_start_pos
) = 0;
12171 /* Run window scroll functions, if any, for WINDOW with new window
12172 start STARTP. Sets the window start of WINDOW to that position.
12174 We assume that the window's buffer is really current. */
12176 static INLINE
struct text_pos
12177 run_window_scroll_functions (window
, startp
)
12178 Lisp_Object window
;
12179 struct text_pos startp
;
12181 struct window
*w
= XWINDOW (window
);
12182 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12184 if (current_buffer
!= XBUFFER (w
->buffer
))
12187 if (!NILP (Vwindow_scroll_functions
))
12189 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12190 make_number (CHARPOS (startp
)));
12191 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12192 /* In case the hook functions switch buffers. */
12193 if (current_buffer
!= XBUFFER (w
->buffer
))
12194 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12201 /* Make sure the line containing the cursor is fully visible.
12202 A value of 1 means there is nothing to be done.
12203 (Either the line is fully visible, or it cannot be made so,
12204 or we cannot tell.)
12206 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12207 is higher than window.
12209 A value of 0 means the caller should do scrolling
12210 as if point had gone off the screen. */
12213 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12216 int current_matrix_p
;
12218 struct glyph_matrix
*matrix
;
12219 struct glyph_row
*row
;
12222 if (!make_cursor_line_fully_visible_p
)
12225 /* It's not always possible to find the cursor, e.g, when a window
12226 is full of overlay strings. Don't do anything in that case. */
12227 if (w
->cursor
.vpos
< 0)
12230 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12231 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12233 /* If the cursor row is not partially visible, there's nothing to do. */
12234 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12237 /* If the row the cursor is in is taller than the window's height,
12238 it's not clear what to do, so do nothing. */
12239 window_height
= window_box_height (w
);
12240 if (row
->height
>= window_height
)
12242 if (!force_p
|| MINI_WINDOW_P (w
)
12243 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12249 /* This code used to try to scroll the window just enough to make
12250 the line visible. It returned 0 to say that the caller should
12251 allocate larger glyph matrices. */
12253 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12255 int dy
= row
->height
- row
->visible_height
;
12258 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12260 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12262 int dy
= - (row
->height
- row
->visible_height
);
12265 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12268 /* When we change the cursor y-position of the selected window,
12269 change this_line_y as well so that the display optimization for
12270 the cursor line of the selected window in redisplay_internal uses
12271 the correct y-position. */
12272 if (w
== XWINDOW (selected_window
))
12273 this_line_y
= w
->cursor
.y
;
12275 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12276 redisplay with larger matrices. */
12277 if (matrix
->nrows
< required_matrix_height (w
))
12279 fonts_changed_p
= 1;
12288 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12289 non-zero means only WINDOW is redisplayed in redisplay_internal.
12290 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12291 in redisplay_window to bring a partially visible line into view in
12292 the case that only the cursor has moved.
12294 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12295 last screen line's vertical height extends past the end of the screen.
12299 1 if scrolling succeeded
12301 0 if scrolling didn't find point.
12303 -1 if new fonts have been loaded so that we must interrupt
12304 redisplay, adjust glyph matrices, and try again. */
12310 SCROLLING_NEED_LARGER_MATRICES
12314 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12315 scroll_step
, temp_scroll_step
, last_line_misfit
)
12316 Lisp_Object window
;
12317 int just_this_one_p
;
12318 EMACS_INT scroll_conservatively
, scroll_step
;
12319 int temp_scroll_step
;
12320 int last_line_misfit
;
12322 struct window
*w
= XWINDOW (window
);
12323 struct frame
*f
= XFRAME (w
->frame
);
12324 struct text_pos scroll_margin_pos
;
12325 struct text_pos pos
;
12326 struct text_pos startp
;
12328 Lisp_Object window_end
;
12329 int this_scroll_margin
;
12333 int amount_to_scroll
= 0;
12334 Lisp_Object aggressive
;
12336 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12339 debug_method_add (w
, "try_scrolling");
12342 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12344 /* Compute scroll margin height in pixels. We scroll when point is
12345 within this distance from the top or bottom of the window. */
12346 if (scroll_margin
> 0)
12348 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12349 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12352 this_scroll_margin
= 0;
12354 /* Force scroll_conservatively to have a reasonable value so it doesn't
12355 cause an overflow while computing how much to scroll. */
12356 if (scroll_conservatively
)
12357 scroll_conservatively
= min (scroll_conservatively
,
12358 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12360 /* Compute how much we should try to scroll maximally to bring point
12362 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12363 scroll_max
= max (scroll_step
,
12364 max (scroll_conservatively
, temp_scroll_step
));
12365 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12366 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12367 /* We're trying to scroll because of aggressive scrolling
12368 but no scroll_step is set. Choose an arbitrary one. Maybe
12369 there should be a variable for this. */
12373 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12375 /* Decide whether we have to scroll down. Start at the window end
12376 and move this_scroll_margin up to find the position of the scroll
12378 window_end
= Fwindow_end (window
, Qt
);
12382 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12383 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12385 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12387 start_display (&it
, w
, scroll_margin_pos
);
12388 if (this_scroll_margin
)
12389 move_it_vertically_backward (&it
, this_scroll_margin
);
12390 if (extra_scroll_margin_lines
)
12391 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12392 scroll_margin_pos
= it
.current
.pos
;
12395 if (PT
>= CHARPOS (scroll_margin_pos
))
12399 /* Point is in the scroll margin at the bottom of the window, or
12400 below. Compute a new window start that makes point visible. */
12402 /* Compute the distance from the scroll margin to PT.
12403 Give up if the distance is greater than scroll_max. */
12404 start_display (&it
, w
, scroll_margin_pos
);
12406 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12407 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12409 /* To make point visible, we have to move the window start
12410 down so that the line the cursor is in is visible, which
12411 means we have to add in the height of the cursor line. */
12412 dy
= line_bottom_y (&it
) - y0
;
12414 if (dy
> scroll_max
)
12415 return SCROLLING_FAILED
;
12417 /* Move the window start down. If scrolling conservatively,
12418 move it just enough down to make point visible. If
12419 scroll_step is set, move it down by scroll_step. */
12420 start_display (&it
, w
, startp
);
12422 if (scroll_conservatively
)
12423 /* Set AMOUNT_TO_SCROLL to at least one line,
12424 and at most scroll_conservatively lines. */
12426 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12427 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12428 else if (scroll_step
|| temp_scroll_step
)
12429 amount_to_scroll
= scroll_max
;
12432 aggressive
= current_buffer
->scroll_up_aggressively
;
12433 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12434 if (NUMBERP (aggressive
))
12436 double float_amount
= XFLOATINT (aggressive
) * height
;
12437 amount_to_scroll
= float_amount
;
12438 if (amount_to_scroll
== 0 && float_amount
> 0)
12439 amount_to_scroll
= 1;
12443 if (amount_to_scroll
<= 0)
12444 return SCROLLING_FAILED
;
12446 /* If moving by amount_to_scroll leaves STARTP unchanged,
12447 move it down one screen line. */
12449 move_it_vertically (&it
, amount_to_scroll
);
12450 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12451 move_it_by_lines (&it
, 1, 1);
12452 startp
= it
.current
.pos
;
12456 /* See if point is inside the scroll margin at the top of the
12458 scroll_margin_pos
= startp
;
12459 if (this_scroll_margin
)
12461 start_display (&it
, w
, startp
);
12462 move_it_vertically (&it
, this_scroll_margin
);
12463 scroll_margin_pos
= it
.current
.pos
;
12466 if (PT
< CHARPOS (scroll_margin_pos
))
12468 /* Point is in the scroll margin at the top of the window or
12469 above what is displayed in the window. */
12472 /* Compute the vertical distance from PT to the scroll
12473 margin position. Give up if distance is greater than
12475 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12476 start_display (&it
, w
, pos
);
12478 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12479 it
.last_visible_y
, -1,
12480 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12481 dy
= it
.current_y
- y0
;
12482 if (dy
> scroll_max
)
12483 return SCROLLING_FAILED
;
12485 /* Compute new window start. */
12486 start_display (&it
, w
, startp
);
12488 if (scroll_conservatively
)
12490 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12491 else if (scroll_step
|| temp_scroll_step
)
12492 amount_to_scroll
= scroll_max
;
12495 aggressive
= current_buffer
->scroll_down_aggressively
;
12496 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12497 if (NUMBERP (aggressive
))
12499 double float_amount
= XFLOATINT (aggressive
) * height
;
12500 amount_to_scroll
= float_amount
;
12501 if (amount_to_scroll
== 0 && float_amount
> 0)
12502 amount_to_scroll
= 1;
12506 if (amount_to_scroll
<= 0)
12507 return SCROLLING_FAILED
;
12509 move_it_vertically_backward (&it
, amount_to_scroll
);
12510 startp
= it
.current
.pos
;
12514 /* Run window scroll functions. */
12515 startp
= run_window_scroll_functions (window
, startp
);
12517 /* Display the window. Give up if new fonts are loaded, or if point
12519 if (!try_window (window
, startp
, 0))
12520 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12521 else if (w
->cursor
.vpos
< 0)
12523 clear_glyph_matrix (w
->desired_matrix
);
12524 rc
= SCROLLING_FAILED
;
12528 /* Maybe forget recorded base line for line number display. */
12529 if (!just_this_one_p
12530 || current_buffer
->clip_changed
12531 || BEG_UNCHANGED
< CHARPOS (startp
))
12532 w
->base_line_number
= Qnil
;
12534 /* If cursor ends up on a partially visible line,
12535 treat that as being off the bottom of the screen. */
12536 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12538 clear_glyph_matrix (w
->desired_matrix
);
12539 ++extra_scroll_margin_lines
;
12542 rc
= SCROLLING_SUCCESS
;
12549 /* Compute a suitable window start for window W if display of W starts
12550 on a continuation line. Value is non-zero if a new window start
12553 The new window start will be computed, based on W's width, starting
12554 from the start of the continued line. It is the start of the
12555 screen line with the minimum distance from the old start W->start. */
12558 compute_window_start_on_continuation_line (w
)
12561 struct text_pos pos
, start_pos
;
12562 int window_start_changed_p
= 0;
12564 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12566 /* If window start is on a continuation line... Window start may be
12567 < BEGV in case there's invisible text at the start of the
12568 buffer (M-x rmail, for example). */
12569 if (CHARPOS (start_pos
) > BEGV
12570 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12573 struct glyph_row
*row
;
12575 /* Handle the case that the window start is out of range. */
12576 if (CHARPOS (start_pos
) < BEGV
)
12577 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12578 else if (CHARPOS (start_pos
) > ZV
)
12579 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12581 /* Find the start of the continued line. This should be fast
12582 because scan_buffer is fast (newline cache). */
12583 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12584 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12585 row
, DEFAULT_FACE_ID
);
12586 reseat_at_previous_visible_line_start (&it
);
12588 /* If the line start is "too far" away from the window start,
12589 say it takes too much time to compute a new window start. */
12590 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12591 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12593 int min_distance
, distance
;
12595 /* Move forward by display lines to find the new window
12596 start. If window width was enlarged, the new start can
12597 be expected to be > the old start. If window width was
12598 decreased, the new window start will be < the old start.
12599 So, we're looking for the display line start with the
12600 minimum distance from the old window start. */
12601 pos
= it
.current
.pos
;
12602 min_distance
= INFINITY
;
12603 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12604 distance
< min_distance
)
12606 min_distance
= distance
;
12607 pos
= it
.current
.pos
;
12608 move_it_by_lines (&it
, 1, 0);
12611 /* Set the window start there. */
12612 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12613 window_start_changed_p
= 1;
12617 return window_start_changed_p
;
12621 /* Try cursor movement in case text has not changed in window WINDOW,
12622 with window start STARTP. Value is
12624 CURSOR_MOVEMENT_SUCCESS if successful
12626 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12628 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12629 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12630 we want to scroll as if scroll-step were set to 1. See the code.
12632 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12633 which case we have to abort this redisplay, and adjust matrices
12638 CURSOR_MOVEMENT_SUCCESS
,
12639 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12640 CURSOR_MOVEMENT_MUST_SCROLL
,
12641 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12645 try_cursor_movement (window
, startp
, scroll_step
)
12646 Lisp_Object window
;
12647 struct text_pos startp
;
12650 struct window
*w
= XWINDOW (window
);
12651 struct frame
*f
= XFRAME (w
->frame
);
12652 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12655 if (inhibit_try_cursor_movement
)
12659 /* Handle case where text has not changed, only point, and it has
12660 not moved off the frame. */
12661 if (/* Point may be in this window. */
12662 PT
>= CHARPOS (startp
)
12663 /* Selective display hasn't changed. */
12664 && !current_buffer
->clip_changed
12665 /* Function force-mode-line-update is used to force a thorough
12666 redisplay. It sets either windows_or_buffers_changed or
12667 update_mode_lines. So don't take a shortcut here for these
12669 && !update_mode_lines
12670 && !windows_or_buffers_changed
12671 && !cursor_type_changed
12672 /* Can't use this case if highlighting a region. When a
12673 region exists, cursor movement has to do more than just
12675 && !(!NILP (Vtransient_mark_mode
)
12676 && !NILP (current_buffer
->mark_active
))
12677 && NILP (w
->region_showing
)
12678 && NILP (Vshow_trailing_whitespace
)
12679 /* Right after splitting windows, last_point may be nil. */
12680 && INTEGERP (w
->last_point
)
12681 /* This code is not used for mini-buffer for the sake of the case
12682 of redisplaying to replace an echo area message; since in
12683 that case the mini-buffer contents per se are usually
12684 unchanged. This code is of no real use in the mini-buffer
12685 since the handling of this_line_start_pos, etc., in redisplay
12686 handles the same cases. */
12687 && !EQ (window
, minibuf_window
)
12688 /* When splitting windows or for new windows, it happens that
12689 redisplay is called with a nil window_end_vpos or one being
12690 larger than the window. This should really be fixed in
12691 window.c. I don't have this on my list, now, so we do
12692 approximately the same as the old redisplay code. --gerd. */
12693 && INTEGERP (w
->window_end_vpos
)
12694 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12695 && (FRAME_WINDOW_P (f
)
12696 || !overlay_arrow_in_current_buffer_p ()))
12698 int this_scroll_margin
, top_scroll_margin
;
12699 struct glyph_row
*row
= NULL
;
12702 debug_method_add (w
, "cursor movement");
12705 /* Scroll if point within this distance from the top or bottom
12706 of the window. This is a pixel value. */
12707 this_scroll_margin
= max (0, scroll_margin
);
12708 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12709 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12711 top_scroll_margin
= this_scroll_margin
;
12712 if (WINDOW_WANTS_HEADER_LINE_P (w
))
12713 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
12715 /* Start with the row the cursor was displayed during the last
12716 not paused redisplay. Give up if that row is not valid. */
12717 if (w
->last_cursor
.vpos
< 0
12718 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
12719 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12722 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
12723 if (row
->mode_line_p
)
12725 if (!row
->enabled_p
)
12726 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12729 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
12732 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
12734 if (PT
> XFASTINT (w
->last_point
))
12736 /* Point has moved forward. */
12737 while (MATRIX_ROW_END_CHARPOS (row
) < PT
12738 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
12740 xassert (row
->enabled_p
);
12744 /* The end position of a row equals the start position
12745 of the next row. If PT is there, we would rather
12746 display it in the next line. */
12747 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12748 && MATRIX_ROW_END_CHARPOS (row
) == PT
12749 && !cursor_row_p (w
, row
))
12752 /* If within the scroll margin, scroll. Note that
12753 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
12754 the next line would be drawn, and that
12755 this_scroll_margin can be zero. */
12756 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
12757 || PT
> MATRIX_ROW_END_CHARPOS (row
)
12758 /* Line is completely visible last line in window
12759 and PT is to be set in the next line. */
12760 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
12761 && PT
== MATRIX_ROW_END_CHARPOS (row
)
12762 && !row
->ends_at_zv_p
12763 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
12766 else if (PT
< XFASTINT (w
->last_point
))
12768 /* Cursor has to be moved backward. Note that PT >=
12769 CHARPOS (startp) because of the outer if-statement. */
12770 while (!row
->mode_line_p
12771 && (MATRIX_ROW_START_CHARPOS (row
) > PT
12772 || (MATRIX_ROW_START_CHARPOS (row
) == PT
12773 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
12774 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
12775 row
> w
->current_matrix
->rows
12776 && (row
-1)->ends_in_newline_from_string_p
))))
12777 && (row
->y
> top_scroll_margin
12778 || CHARPOS (startp
) == BEGV
))
12780 xassert (row
->enabled_p
);
12784 /* Consider the following case: Window starts at BEGV,
12785 there is invisible, intangible text at BEGV, so that
12786 display starts at some point START > BEGV. It can
12787 happen that we are called with PT somewhere between
12788 BEGV and START. Try to handle that case. */
12789 if (row
< w
->current_matrix
->rows
12790 || row
->mode_line_p
)
12792 row
= w
->current_matrix
->rows
;
12793 if (row
->mode_line_p
)
12797 /* Due to newlines in overlay strings, we may have to
12798 skip forward over overlay strings. */
12799 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12800 && MATRIX_ROW_END_CHARPOS (row
) == PT
12801 && !cursor_row_p (w
, row
))
12804 /* If within the scroll margin, scroll. */
12805 if (row
->y
< top_scroll_margin
12806 && CHARPOS (startp
) != BEGV
)
12811 /* Cursor did not move. So don't scroll even if cursor line
12812 is partially visible, as it was so before. */
12813 rc
= CURSOR_MOVEMENT_SUCCESS
;
12816 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
12817 || PT
> MATRIX_ROW_END_CHARPOS (row
))
12819 /* if PT is not in the glyph row, give up. */
12820 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12822 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
12823 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
12824 && make_cursor_line_fully_visible_p
)
12826 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
12827 && !row
->ends_at_zv_p
12828 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
12829 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12830 else if (row
->height
> window_box_height (w
))
12832 /* If we end up in a partially visible line, let's
12833 make it fully visible, except when it's taller
12834 than the window, in which case we can't do much
12837 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12841 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12842 if (!cursor_row_fully_visible_p (w
, 0, 1))
12843 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12845 rc
= CURSOR_MOVEMENT_SUCCESS
;
12849 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12854 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
12856 rc
= CURSOR_MOVEMENT_SUCCESS
;
12861 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
12862 && MATRIX_ROW_START_CHARPOS (row
) == PT
12863 && cursor_row_p (w
, row
));
12872 set_vertical_scroll_bar (w
)
12875 int start
, end
, whole
;
12877 /* Calculate the start and end positions for the current window.
12878 At some point, it would be nice to choose between scrollbars
12879 which reflect the whole buffer size, with special markers
12880 indicating narrowing, and scrollbars which reflect only the
12883 Note that mini-buffers sometimes aren't displaying any text. */
12884 if (!MINI_WINDOW_P (w
)
12885 || (w
== XWINDOW (minibuf_window
)
12886 && NILP (echo_area_buffer
[0])))
12888 struct buffer
*buf
= XBUFFER (w
->buffer
);
12889 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12890 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12891 /* I don't think this is guaranteed to be right. For the
12892 moment, we'll pretend it is. */
12893 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12897 if (whole
< (end
- start
))
12898 whole
= end
- start
;
12901 start
= end
= whole
= 0;
12903 /* Indicate what this scroll bar ought to be displaying now. */
12904 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12908 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12909 selected_window is redisplayed.
12911 We can return without actually redisplaying the window if
12912 fonts_changed_p is nonzero. In that case, redisplay_internal will
12916 redisplay_window (window
, just_this_one_p
)
12917 Lisp_Object window
;
12918 int just_this_one_p
;
12920 struct window
*w
= XWINDOW (window
);
12921 struct frame
*f
= XFRAME (w
->frame
);
12922 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12923 struct buffer
*old
= current_buffer
;
12924 struct text_pos lpoint
, opoint
, startp
;
12925 int update_mode_line
;
12928 /* Record it now because it's overwritten. */
12929 int current_matrix_up_to_date_p
= 0;
12930 int used_current_matrix_p
= 0;
12931 /* This is less strict than current_matrix_up_to_date_p.
12932 It indictes that the buffer contents and narrowing are unchanged. */
12933 int buffer_unchanged_p
= 0;
12934 int temp_scroll_step
= 0;
12935 int count
= SPECPDL_INDEX ();
12937 int centering_position
= -1;
12938 int last_line_misfit
= 0;
12939 int beg_unchanged
, end_unchanged
;
12941 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12944 /* W must be a leaf window here. */
12945 xassert (!NILP (w
->buffer
));
12947 *w
->desired_matrix
->method
= 0;
12950 specbind (Qinhibit_point_motion_hooks
, Qt
);
12952 reconsider_clip_changes (w
, buffer
);
12954 /* Has the mode line to be updated? */
12955 update_mode_line
= (!NILP (w
->update_mode_line
)
12956 || update_mode_lines
12957 || buffer
->clip_changed
12958 || buffer
->prevent_redisplay_optimizations_p
);
12960 if (MINI_WINDOW_P (w
))
12962 if (w
== XWINDOW (echo_area_window
)
12963 && !NILP (echo_area_buffer
[0]))
12965 if (update_mode_line
)
12966 /* We may have to update a tty frame's menu bar or a
12967 tool-bar. Example `M-x C-h C-h C-g'. */
12968 goto finish_menu_bars
;
12970 /* We've already displayed the echo area glyphs in this window. */
12971 goto finish_scroll_bars
;
12973 else if ((w
!= XWINDOW (minibuf_window
)
12974 || minibuf_level
== 0)
12975 /* When buffer is nonempty, redisplay window normally. */
12976 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12977 /* Quail displays non-mini buffers in minibuffer window.
12978 In that case, redisplay the window normally. */
12979 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12981 /* W is a mini-buffer window, but it's not active, so clear
12983 int yb
= window_text_bottom_y (w
);
12984 struct glyph_row
*row
;
12987 for (y
= 0, row
= w
->desired_matrix
->rows
;
12989 y
+= row
->height
, ++row
)
12990 blank_row (w
, row
, y
);
12991 goto finish_scroll_bars
;
12994 clear_glyph_matrix (w
->desired_matrix
);
12997 /* Otherwise set up data on this window; select its buffer and point
12999 /* Really select the buffer, for the sake of buffer-local
13001 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13002 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13004 beg_unchanged
= BEG_UNCHANGED
;
13005 end_unchanged
= END_UNCHANGED
;
13007 current_matrix_up_to_date_p
13008 = (!NILP (w
->window_end_valid
)
13009 && !current_buffer
->clip_changed
13010 && !current_buffer
->prevent_redisplay_optimizations_p
13011 && XFASTINT (w
->last_modified
) >= MODIFF
13012 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13015 = (!NILP (w
->window_end_valid
)
13016 && !current_buffer
->clip_changed
13017 && XFASTINT (w
->last_modified
) >= MODIFF
13018 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13020 /* When windows_or_buffers_changed is non-zero, we can't rely on
13021 the window end being valid, so set it to nil there. */
13022 if (windows_or_buffers_changed
)
13024 /* If window starts on a continuation line, maybe adjust the
13025 window start in case the window's width changed. */
13026 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13027 compute_window_start_on_continuation_line (w
);
13029 w
->window_end_valid
= Qnil
;
13032 /* Some sanity checks. */
13033 CHECK_WINDOW_END (w
);
13034 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13036 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13039 /* If %c is in mode line, update it if needed. */
13040 if (!NILP (w
->column_number_displayed
)
13041 /* This alternative quickly identifies a common case
13042 where no change is needed. */
13043 && !(PT
== XFASTINT (w
->last_point
)
13044 && XFASTINT (w
->last_modified
) >= MODIFF
13045 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13046 && (XFASTINT (w
->column_number_displayed
)
13047 != (int) current_column ())) /* iftc */
13048 update_mode_line
= 1;
13050 /* Count number of windows showing the selected buffer. An indirect
13051 buffer counts as its base buffer. */
13052 if (!just_this_one_p
)
13054 struct buffer
*current_base
, *window_base
;
13055 current_base
= current_buffer
;
13056 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13057 if (current_base
->base_buffer
)
13058 current_base
= current_base
->base_buffer
;
13059 if (window_base
->base_buffer
)
13060 window_base
= window_base
->base_buffer
;
13061 if (current_base
== window_base
)
13065 /* Point refers normally to the selected window. For any other
13066 window, set up appropriate value. */
13067 if (!EQ (window
, selected_window
))
13069 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13070 int new_pt_byte
= marker_byte_position (w
->pointm
);
13074 new_pt_byte
= BEGV_BYTE
;
13075 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13077 else if (new_pt
> (ZV
- 1))
13080 new_pt_byte
= ZV_BYTE
;
13081 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13084 /* We don't use SET_PT so that the point-motion hooks don't run. */
13085 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13088 /* If any of the character widths specified in the display table
13089 have changed, invalidate the width run cache. It's true that
13090 this may be a bit late to catch such changes, but the rest of
13091 redisplay goes (non-fatally) haywire when the display table is
13092 changed, so why should we worry about doing any better? */
13093 if (current_buffer
->width_run_cache
)
13095 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13097 if (! disptab_matches_widthtab (disptab
,
13098 XVECTOR (current_buffer
->width_table
)))
13100 invalidate_region_cache (current_buffer
,
13101 current_buffer
->width_run_cache
,
13103 recompute_width_table (current_buffer
, disptab
);
13107 /* If window-start is screwed up, choose a new one. */
13108 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13111 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13113 /* If someone specified a new starting point but did not insist,
13114 check whether it can be used. */
13115 if (!NILP (w
->optional_new_start
)
13116 && CHARPOS (startp
) >= BEGV
13117 && CHARPOS (startp
) <= ZV
)
13119 w
->optional_new_start
= Qnil
;
13120 start_display (&it
, w
, startp
);
13121 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13122 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13123 if (IT_CHARPOS (it
) == PT
)
13124 w
->force_start
= Qt
;
13125 /* IT may overshoot PT if text at PT is invisible. */
13126 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13127 w
->force_start
= Qt
;
13132 /* Handle case where place to start displaying has been specified,
13133 unless the specified location is outside the accessible range. */
13134 if (!NILP (w
->force_start
)
13135 || w
->frozen_window_start_p
)
13137 /* We set this later on if we have to adjust point. */
13141 w
->force_start
= Qnil
;
13143 w
->window_end_valid
= Qnil
;
13145 /* Forget any recorded base line for line number display. */
13146 if (!buffer_unchanged_p
)
13147 w
->base_line_number
= Qnil
;
13149 /* Redisplay the mode line. Select the buffer properly for that.
13150 Also, run the hook window-scroll-functions
13151 because we have scrolled. */
13152 /* Note, we do this after clearing force_start because
13153 if there's an error, it is better to forget about force_start
13154 than to get into an infinite loop calling the hook functions
13155 and having them get more errors. */
13156 if (!update_mode_line
13157 || ! NILP (Vwindow_scroll_functions
))
13159 update_mode_line
= 1;
13160 w
->update_mode_line
= Qt
;
13161 startp
= run_window_scroll_functions (window
, startp
);
13164 w
->last_modified
= make_number (0);
13165 w
->last_overlay_modified
= make_number (0);
13166 if (CHARPOS (startp
) < BEGV
)
13167 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13168 else if (CHARPOS (startp
) > ZV
)
13169 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13171 /* Redisplay, then check if cursor has been set during the
13172 redisplay. Give up if new fonts were loaded. */
13173 val
= try_window (window
, startp
, 1);
13176 w
->force_start
= Qt
;
13177 clear_glyph_matrix (w
->desired_matrix
);
13178 goto need_larger_matrices
;
13180 /* Point was outside the scroll margins. */
13182 new_vpos
= window_box_height (w
) / 2;
13184 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13186 /* If point does not appear, try to move point so it does
13187 appear. The desired matrix has been built above, so we
13188 can use it here. */
13189 new_vpos
= window_box_height (w
) / 2;
13192 if (!cursor_row_fully_visible_p (w
, 0, 0))
13194 /* Point does appear, but on a line partly visible at end of window.
13195 Move it back to a fully-visible line. */
13196 new_vpos
= window_box_height (w
);
13199 /* If we need to move point for either of the above reasons,
13200 now actually do it. */
13203 struct glyph_row
*row
;
13205 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13206 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13209 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13210 MATRIX_ROW_START_BYTEPOS (row
));
13212 if (w
!= XWINDOW (selected_window
))
13213 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13214 else if (current_buffer
== old
)
13215 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13217 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13219 /* If we are highlighting the region, then we just changed
13220 the region, so redisplay to show it. */
13221 if (!NILP (Vtransient_mark_mode
)
13222 && !NILP (current_buffer
->mark_active
))
13224 clear_glyph_matrix (w
->desired_matrix
);
13225 if (!try_window (window
, startp
, 0))
13226 goto need_larger_matrices
;
13231 debug_method_add (w
, "forced window start");
13236 /* Handle case where text has not changed, only point, and it has
13237 not moved off the frame, and we are not retrying after hscroll.
13238 (current_matrix_up_to_date_p is nonzero when retrying.) */
13239 if (current_matrix_up_to_date_p
13240 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13241 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13245 case CURSOR_MOVEMENT_SUCCESS
:
13246 used_current_matrix_p
= 1;
13249 #if 0 /* try_cursor_movement never returns this value. */
13250 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13251 goto need_larger_matrices
;
13254 case CURSOR_MOVEMENT_MUST_SCROLL
:
13255 goto try_to_scroll
;
13261 /* If current starting point was originally the beginning of a line
13262 but no longer is, find a new starting point. */
13263 else if (!NILP (w
->start_at_line_beg
)
13264 && !(CHARPOS (startp
) <= BEGV
13265 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13268 debug_method_add (w
, "recenter 1");
13273 /* Try scrolling with try_window_id. Value is > 0 if update has
13274 been done, it is -1 if we know that the same window start will
13275 not work. It is 0 if unsuccessful for some other reason. */
13276 else if ((tem
= try_window_id (w
)) != 0)
13279 debug_method_add (w
, "try_window_id %d", tem
);
13282 if (fonts_changed_p
)
13283 goto need_larger_matrices
;
13287 /* Otherwise try_window_id has returned -1 which means that we
13288 don't want the alternative below this comment to execute. */
13290 else if (CHARPOS (startp
) >= BEGV
13291 && CHARPOS (startp
) <= ZV
13292 && PT
>= CHARPOS (startp
)
13293 && (CHARPOS (startp
) < ZV
13294 /* Avoid starting at end of buffer. */
13295 || CHARPOS (startp
) == BEGV
13296 || (XFASTINT (w
->last_modified
) >= MODIFF
13297 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13300 /* If first window line is a continuation line, and window start
13301 is inside the modified region, but the first change is before
13302 current window start, we must select a new window start.
13304 However, if this is the result of a down-mouse event (e.g. by
13305 extending the mouse-drag-overlay), we don't want to select a
13306 new window start, since that would change the position under
13307 the mouse, resulting in an unwanted mouse-movement rather
13308 than a simple mouse-click. */
13309 if (NILP (w
->start_at_line_beg
)
13310 && NILP (do_mouse_tracking
)
13311 && CHARPOS (startp
) > BEGV
13312 && CHARPOS (startp
) > BEG
+ beg_unchanged
13313 && CHARPOS (startp
) <= Z
- end_unchanged
)
13315 w
->force_start
= Qt
;
13316 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13317 compute_window_start_on_continuation_line (w
);
13318 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13323 debug_method_add (w
, "same window start");
13326 /* Try to redisplay starting at same place as before.
13327 If point has not moved off frame, accept the results. */
13328 if (!current_matrix_up_to_date_p
13329 /* Don't use try_window_reusing_current_matrix in this case
13330 because a window scroll function can have changed the
13332 || !NILP (Vwindow_scroll_functions
)
13333 || MINI_WINDOW_P (w
)
13334 || !(used_current_matrix_p
13335 = try_window_reusing_current_matrix (w
)))
13337 IF_DEBUG (debug_method_add (w
, "1"));
13338 if (try_window (window
, startp
, 1) < 0)
13339 /* -1 means we need to scroll.
13340 0 means we need new matrices, but fonts_changed_p
13341 is set in that case, so we will detect it below. */
13342 goto try_to_scroll
;
13345 if (fonts_changed_p
)
13346 goto need_larger_matrices
;
13348 if (w
->cursor
.vpos
>= 0)
13350 if (!just_this_one_p
13351 || current_buffer
->clip_changed
13352 || BEG_UNCHANGED
< CHARPOS (startp
))
13353 /* Forget any recorded base line for line number display. */
13354 w
->base_line_number
= Qnil
;
13356 if (!cursor_row_fully_visible_p (w
, 1, 0))
13358 clear_glyph_matrix (w
->desired_matrix
);
13359 last_line_misfit
= 1;
13361 /* Drop through and scroll. */
13366 clear_glyph_matrix (w
->desired_matrix
);
13371 w
->last_modified
= make_number (0);
13372 w
->last_overlay_modified
= make_number (0);
13374 /* Redisplay the mode line. Select the buffer properly for that. */
13375 if (!update_mode_line
)
13377 update_mode_line
= 1;
13378 w
->update_mode_line
= Qt
;
13381 /* Try to scroll by specified few lines. */
13382 if ((scroll_conservatively
13384 || temp_scroll_step
13385 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13386 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13387 && !current_buffer
->clip_changed
13388 && CHARPOS (startp
) >= BEGV
13389 && CHARPOS (startp
) <= ZV
)
13391 /* The function returns -1 if new fonts were loaded, 1 if
13392 successful, 0 if not successful. */
13393 int rc
= try_scrolling (window
, just_this_one_p
,
13394 scroll_conservatively
,
13396 temp_scroll_step
, last_line_misfit
);
13399 case SCROLLING_SUCCESS
:
13402 case SCROLLING_NEED_LARGER_MATRICES
:
13403 goto need_larger_matrices
;
13405 case SCROLLING_FAILED
:
13413 /* Finally, just choose place to start which centers point */
13416 if (centering_position
< 0)
13417 centering_position
= window_box_height (w
) / 2;
13420 debug_method_add (w
, "recenter");
13423 /* w->vscroll = 0; */
13425 /* Forget any previously recorded base line for line number display. */
13426 if (!buffer_unchanged_p
)
13427 w
->base_line_number
= Qnil
;
13429 /* Move backward half the height of the window. */
13430 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13431 it
.current_y
= it
.last_visible_y
;
13432 move_it_vertically_backward (&it
, centering_position
);
13433 xassert (IT_CHARPOS (it
) >= BEGV
);
13435 /* The function move_it_vertically_backward may move over more
13436 than the specified y-distance. If it->w is small, e.g. a
13437 mini-buffer window, we may end up in front of the window's
13438 display area. Start displaying at the start of the line
13439 containing PT in this case. */
13440 if (it
.current_y
<= 0)
13442 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13443 move_it_vertically_backward (&it
, 0);
13445 /* I think this assert is bogus if buffer contains
13446 invisible text or images. KFS. */
13447 xassert (IT_CHARPOS (it
) <= PT
);
13452 it
.current_x
= it
.hpos
= 0;
13454 /* Set startp here explicitly in case that helps avoid an infinite loop
13455 in case the window-scroll-functions functions get errors. */
13456 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13458 /* Run scroll hooks. */
13459 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13461 /* Redisplay the window. */
13462 if (!current_matrix_up_to_date_p
13463 || windows_or_buffers_changed
13464 || cursor_type_changed
13465 /* Don't use try_window_reusing_current_matrix in this case
13466 because it can have changed the buffer. */
13467 || !NILP (Vwindow_scroll_functions
)
13468 || !just_this_one_p
13469 || MINI_WINDOW_P (w
)
13470 || !(used_current_matrix_p
13471 = try_window_reusing_current_matrix (w
)))
13472 try_window (window
, startp
, 0);
13474 /* If new fonts have been loaded (due to fontsets), give up. We
13475 have to start a new redisplay since we need to re-adjust glyph
13477 if (fonts_changed_p
)
13478 goto need_larger_matrices
;
13480 /* If cursor did not appear assume that the middle of the window is
13481 in the first line of the window. Do it again with the next line.
13482 (Imagine a window of height 100, displaying two lines of height
13483 60. Moving back 50 from it->last_visible_y will end in the first
13485 if (w
->cursor
.vpos
< 0)
13487 if (!NILP (w
->window_end_valid
)
13488 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13490 clear_glyph_matrix (w
->desired_matrix
);
13491 move_it_by_lines (&it
, 1, 0);
13492 try_window (window
, it
.current
.pos
, 0);
13494 else if (PT
< IT_CHARPOS (it
))
13496 clear_glyph_matrix (w
->desired_matrix
);
13497 move_it_by_lines (&it
, -1, 0);
13498 try_window (window
, it
.current
.pos
, 0);
13502 /* Not much we can do about it. */
13506 /* Consider the following case: Window starts at BEGV, there is
13507 invisible, intangible text at BEGV, so that display starts at
13508 some point START > BEGV. It can happen that we are called with
13509 PT somewhere between BEGV and START. Try to handle that case. */
13510 if (w
->cursor
.vpos
< 0)
13512 struct glyph_row
*row
= w
->current_matrix
->rows
;
13513 if (row
->mode_line_p
)
13515 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13518 if (!cursor_row_fully_visible_p (w
, 0, 0))
13520 /* If vscroll is enabled, disable it and try again. */
13524 clear_glyph_matrix (w
->desired_matrix
);
13528 /* If centering point failed to make the whole line visible,
13529 put point at the top instead. That has to make the whole line
13530 visible, if it can be done. */
13531 if (centering_position
== 0)
13534 clear_glyph_matrix (w
->desired_matrix
);
13535 centering_position
= 0;
13541 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13542 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13543 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13546 /* Display the mode line, if we must. */
13547 if ((update_mode_line
13548 /* If window not full width, must redo its mode line
13549 if (a) the window to its side is being redone and
13550 (b) we do a frame-based redisplay. This is a consequence
13551 of how inverted lines are drawn in frame-based redisplay. */
13552 || (!just_this_one_p
13553 && !FRAME_WINDOW_P (f
)
13554 && !WINDOW_FULL_WIDTH_P (w
))
13555 /* Line number to display. */
13556 || INTEGERP (w
->base_line_pos
)
13557 /* Column number is displayed and different from the one displayed. */
13558 || (!NILP (w
->column_number_displayed
)
13559 && (XFASTINT (w
->column_number_displayed
)
13560 != (int) current_column ()))) /* iftc */
13561 /* This means that the window has a mode line. */
13562 && (WINDOW_WANTS_MODELINE_P (w
)
13563 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13565 display_mode_lines (w
);
13567 /* If mode line height has changed, arrange for a thorough
13568 immediate redisplay using the correct mode line height. */
13569 if (WINDOW_WANTS_MODELINE_P (w
)
13570 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13572 fonts_changed_p
= 1;
13573 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13574 = DESIRED_MODE_LINE_HEIGHT (w
);
13577 /* If top line height has changed, arrange for a thorough
13578 immediate redisplay using the correct mode line height. */
13579 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13580 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13582 fonts_changed_p
= 1;
13583 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13584 = DESIRED_HEADER_LINE_HEIGHT (w
);
13587 if (fonts_changed_p
)
13588 goto need_larger_matrices
;
13591 if (!line_number_displayed
13592 && !BUFFERP (w
->base_line_pos
))
13594 w
->base_line_pos
= Qnil
;
13595 w
->base_line_number
= Qnil
;
13600 /* When we reach a frame's selected window, redo the frame's menu bar. */
13601 if (update_mode_line
13602 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13604 int redisplay_menu_p
= 0;
13605 int redisplay_tool_bar_p
= 0;
13607 if (FRAME_WINDOW_P (f
))
13609 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
13610 || defined (USE_GTK)
13611 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13613 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13617 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13619 if (redisplay_menu_p
)
13620 display_menu_bar (w
);
13622 #ifdef HAVE_WINDOW_SYSTEM
13623 #if defined (USE_GTK) || USE_MAC_TOOLBAR
13624 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13626 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13627 && (FRAME_TOOL_BAR_LINES (f
) > 0
13628 || !NILP (Vauto_resize_tool_bars
));
13632 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13634 extern int ignore_mouse_drag_p
;
13635 ignore_mouse_drag_p
= 1;
13640 #ifdef HAVE_WINDOW_SYSTEM
13641 if (FRAME_WINDOW_P (f
)
13642 && update_window_fringes (w
, (just_this_one_p
13643 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13644 || w
->pseudo_window_p
)))
13648 if (draw_window_fringes (w
, 1))
13649 x_draw_vertical_border (w
);
13653 #endif /* HAVE_WINDOW_SYSTEM */
13655 /* We go to this label, with fonts_changed_p nonzero,
13656 if it is necessary to try again using larger glyph matrices.
13657 We have to redeem the scroll bar even in this case,
13658 because the loop in redisplay_internal expects that. */
13659 need_larger_matrices
:
13661 finish_scroll_bars
:
13663 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13665 /* Set the thumb's position and size. */
13666 set_vertical_scroll_bar (w
);
13668 /* Note that we actually used the scroll bar attached to this
13669 window, so it shouldn't be deleted at the end of redisplay. */
13670 redeem_scroll_bar_hook (w
);
13673 /* Restore current_buffer and value of point in it. */
13674 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13675 set_buffer_internal_1 (old
);
13676 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13677 shorter. This can be caused by log truncation in *Messages*. */
13678 if (CHARPOS (lpoint
) <= ZV
)
13679 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13681 unbind_to (count
, Qnil
);
13685 /* Build the complete desired matrix of WINDOW with a window start
13686 buffer position POS.
13688 Value is 1 if successful. It is zero if fonts were loaded during
13689 redisplay which makes re-adjusting glyph matrices necessary, and -1
13690 if point would appear in the scroll margins.
13691 (We check that only if CHECK_MARGINS is nonzero. */
13694 try_window (window
, pos
, check_margins
)
13695 Lisp_Object window
;
13696 struct text_pos pos
;
13699 struct window
*w
= XWINDOW (window
);
13701 struct glyph_row
*last_text_row
= NULL
;
13702 struct frame
*f
= XFRAME (w
->frame
);
13704 /* Make POS the new window start. */
13705 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
13707 /* Mark cursor position as unknown. No overlay arrow seen. */
13708 w
->cursor
.vpos
= -1;
13709 overlay_arrow_seen
= 0;
13711 /* Initialize iterator and info to start at POS. */
13712 start_display (&it
, w
, pos
);
13714 /* Display all lines of W. */
13715 while (it
.current_y
< it
.last_visible_y
)
13717 if (display_line (&it
))
13718 last_text_row
= it
.glyph_row
- 1;
13719 if (fonts_changed_p
)
13723 /* Don't let the cursor end in the scroll margins. */
13725 && !MINI_WINDOW_P (w
))
13727 int this_scroll_margin
;
13729 this_scroll_margin
= max (0, scroll_margin
);
13730 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13731 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13733 if ((w
->cursor
.y
>= 0 /* not vscrolled */
13734 && w
->cursor
.y
< this_scroll_margin
13735 && CHARPOS (pos
) > BEGV
13736 && IT_CHARPOS (it
) < ZV
)
13737 /* rms: considering make_cursor_line_fully_visible_p here
13738 seems to give wrong results. We don't want to recenter
13739 when the last line is partly visible, we want to allow
13740 that case to be handled in the usual way. */
13741 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
13743 w
->cursor
.vpos
= -1;
13744 clear_glyph_matrix (w
->desired_matrix
);
13749 /* If bottom moved off end of frame, change mode line percentage. */
13750 if (XFASTINT (w
->window_end_pos
) <= 0
13751 && Z
!= IT_CHARPOS (it
))
13752 w
->update_mode_line
= Qt
;
13754 /* Set window_end_pos to the offset of the last character displayed
13755 on the window from the end of current_buffer. Set
13756 window_end_vpos to its row number. */
13759 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
13760 w
->window_end_bytepos
13761 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13763 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13765 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13766 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
13767 ->displays_text_p
);
13771 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13772 w
->window_end_pos
= make_number (Z
- ZV
);
13773 w
->window_end_vpos
= make_number (0);
13776 /* But that is not valid info until redisplay finishes. */
13777 w
->window_end_valid
= Qnil
;
13783 /************************************************************************
13784 Window redisplay reusing current matrix when buffer has not changed
13785 ************************************************************************/
13787 /* Try redisplay of window W showing an unchanged buffer with a
13788 different window start than the last time it was displayed by
13789 reusing its current matrix. Value is non-zero if successful.
13790 W->start is the new window start. */
13793 try_window_reusing_current_matrix (w
)
13796 struct frame
*f
= XFRAME (w
->frame
);
13797 struct glyph_row
*row
, *bottom_row
;
13800 struct text_pos start
, new_start
;
13801 int nrows_scrolled
, i
;
13802 struct glyph_row
*last_text_row
;
13803 struct glyph_row
*last_reused_text_row
;
13804 struct glyph_row
*start_row
;
13805 int start_vpos
, min_y
, max_y
;
13808 if (inhibit_try_window_reusing
)
13812 if (/* This function doesn't handle terminal frames. */
13813 !FRAME_WINDOW_P (f
)
13814 /* Don't try to reuse the display if windows have been split
13816 || windows_or_buffers_changed
13817 || cursor_type_changed
)
13820 /* Can't do this if region may have changed. */
13821 if ((!NILP (Vtransient_mark_mode
)
13822 && !NILP (current_buffer
->mark_active
))
13823 || !NILP (w
->region_showing
)
13824 || !NILP (Vshow_trailing_whitespace
))
13827 /* If top-line visibility has changed, give up. */
13828 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13829 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
13832 /* Give up if old or new display is scrolled vertically. We could
13833 make this function handle this, but right now it doesn't. */
13834 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13835 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
13838 /* The variable new_start now holds the new window start. The old
13839 start `start' can be determined from the current matrix. */
13840 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
13841 start
= start_row
->start
.pos
;
13842 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13844 /* Clear the desired matrix for the display below. */
13845 clear_glyph_matrix (w
->desired_matrix
);
13847 if (CHARPOS (new_start
) <= CHARPOS (start
))
13851 /* Don't use this method if the display starts with an ellipsis
13852 displayed for invisible text. It's not easy to handle that case
13853 below, and it's certainly not worth the effort since this is
13854 not a frequent case. */
13855 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
13858 IF_DEBUG (debug_method_add (w
, "twu1"));
13860 /* Display up to a row that can be reused. The variable
13861 last_text_row is set to the last row displayed that displays
13862 text. Note that it.vpos == 0 if or if not there is a
13863 header-line; it's not the same as the MATRIX_ROW_VPOS! */
13864 start_display (&it
, w
, new_start
);
13865 first_row_y
= it
.current_y
;
13866 w
->cursor
.vpos
= -1;
13867 last_text_row
= last_reused_text_row
= NULL
;
13869 while (it
.current_y
< it
.last_visible_y
13870 && !fonts_changed_p
)
13872 /* If we have reached into the characters in the START row,
13873 that means the line boundaries have changed. So we
13874 can't start copying with the row START. Maybe it will
13875 work to start copying with the following row. */
13876 while (IT_CHARPOS (it
) > CHARPOS (start
))
13878 /* Advance to the next row as the "start". */
13880 start
= start_row
->start
.pos
;
13881 /* If there are no more rows to try, or just one, give up. */
13882 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
13883 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
13884 || CHARPOS (start
) == ZV
)
13886 clear_glyph_matrix (w
->desired_matrix
);
13890 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13892 /* If we have reached alignment,
13893 we can copy the rest of the rows. */
13894 if (IT_CHARPOS (it
) == CHARPOS (start
))
13897 if (display_line (&it
))
13898 last_text_row
= it
.glyph_row
- 1;
13901 /* A value of current_y < last_visible_y means that we stopped
13902 at the previous window start, which in turn means that we
13903 have at least one reusable row. */
13904 if (it
.current_y
< it
.last_visible_y
)
13906 /* IT.vpos always starts from 0; it counts text lines. */
13907 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13909 /* Find PT if not already found in the lines displayed. */
13910 if (w
->cursor
.vpos
< 0)
13912 int dy
= it
.current_y
- start_row
->y
;
13914 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13915 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13917 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13918 dy
, nrows_scrolled
);
13921 clear_glyph_matrix (w
->desired_matrix
);
13926 /* Scroll the display. Do it before the current matrix is
13927 changed. The problem here is that update has not yet
13928 run, i.e. part of the current matrix is not up to date.
13929 scroll_run_hook will clear the cursor, and use the
13930 current matrix to get the height of the row the cursor is
13932 run
.current_y
= start_row
->y
;
13933 run
.desired_y
= it
.current_y
;
13934 run
.height
= it
.last_visible_y
- it
.current_y
;
13936 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13939 rif
->update_window_begin_hook (w
);
13940 rif
->clear_window_mouse_face (w
);
13941 rif
->scroll_run_hook (w
, &run
);
13942 rif
->update_window_end_hook (w
, 0, 0);
13946 /* Shift current matrix down by nrows_scrolled lines. */
13947 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13948 rotate_matrix (w
->current_matrix
,
13950 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13953 /* Disable lines that must be updated. */
13954 for (i
= 0; i
< nrows_scrolled
; ++i
)
13955 (start_row
+ i
)->enabled_p
= 0;
13957 /* Re-compute Y positions. */
13958 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13959 max_y
= it
.last_visible_y
;
13960 for (row
= start_row
+ nrows_scrolled
;
13964 row
->y
= it
.current_y
;
13965 row
->visible_height
= row
->height
;
13967 if (row
->y
< min_y
)
13968 row
->visible_height
-= min_y
- row
->y
;
13969 if (row
->y
+ row
->height
> max_y
)
13970 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13971 row
->redraw_fringe_bitmaps_p
= 1;
13973 it
.current_y
+= row
->height
;
13975 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13976 last_reused_text_row
= row
;
13977 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13981 /* Disable lines in the current matrix which are now
13982 below the window. */
13983 for (++row
; row
< bottom_row
; ++row
)
13984 row
->enabled_p
= row
->mode_line_p
= 0;
13987 /* Update window_end_pos etc.; last_reused_text_row is the last
13988 reused row from the current matrix containing text, if any.
13989 The value of last_text_row is the last displayed line
13990 containing text. */
13991 if (last_reused_text_row
)
13993 w
->window_end_bytepos
13994 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13996 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13998 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13999 w
->current_matrix
));
14001 else if (last_text_row
)
14003 w
->window_end_bytepos
14004 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14006 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14008 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14012 /* This window must be completely empty. */
14013 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14014 w
->window_end_pos
= make_number (Z
- ZV
);
14015 w
->window_end_vpos
= make_number (0);
14017 w
->window_end_valid
= Qnil
;
14019 /* Update hint: don't try scrolling again in update_window. */
14020 w
->desired_matrix
->no_scrolling_p
= 1;
14023 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14027 else if (CHARPOS (new_start
) > CHARPOS (start
))
14029 struct glyph_row
*pt_row
, *row
;
14030 struct glyph_row
*first_reusable_row
;
14031 struct glyph_row
*first_row_to_display
;
14033 int yb
= window_text_bottom_y (w
);
14035 /* Find the row starting at new_start, if there is one. Don't
14036 reuse a partially visible line at the end. */
14037 first_reusable_row
= start_row
;
14038 while (first_reusable_row
->enabled_p
14039 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14040 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14041 < CHARPOS (new_start
)))
14042 ++first_reusable_row
;
14044 /* Give up if there is no row to reuse. */
14045 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14046 || !first_reusable_row
->enabled_p
14047 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14048 != CHARPOS (new_start
)))
14051 /* We can reuse fully visible rows beginning with
14052 first_reusable_row to the end of the window. Set
14053 first_row_to_display to the first row that cannot be reused.
14054 Set pt_row to the row containing point, if there is any. */
14056 for (first_row_to_display
= first_reusable_row
;
14057 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14058 ++first_row_to_display
)
14060 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14061 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14062 pt_row
= first_row_to_display
;
14065 /* Start displaying at the start of first_row_to_display. */
14066 xassert (first_row_to_display
->y
< yb
);
14067 init_to_row_start (&it
, w
, first_row_to_display
);
14069 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14071 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14073 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14074 + WINDOW_HEADER_LINE_HEIGHT (w
));
14076 /* Display lines beginning with first_row_to_display in the
14077 desired matrix. Set last_text_row to the last row displayed
14078 that displays text. */
14079 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14080 if (pt_row
== NULL
)
14081 w
->cursor
.vpos
= -1;
14082 last_text_row
= NULL
;
14083 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14084 if (display_line (&it
))
14085 last_text_row
= it
.glyph_row
- 1;
14087 /* Give up If point isn't in a row displayed or reused. */
14088 if (w
->cursor
.vpos
< 0)
14090 clear_glyph_matrix (w
->desired_matrix
);
14094 /* If point is in a reused row, adjust y and vpos of the cursor
14098 w
->cursor
.vpos
-= nrows_scrolled
;
14099 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14102 /* Scroll the display. */
14103 run
.current_y
= first_reusable_row
->y
;
14104 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14105 run
.height
= it
.last_visible_y
- run
.current_y
;
14106 dy
= run
.current_y
- run
.desired_y
;
14111 rif
->update_window_begin_hook (w
);
14112 rif
->clear_window_mouse_face (w
);
14113 rif
->scroll_run_hook (w
, &run
);
14114 rif
->update_window_end_hook (w
, 0, 0);
14118 /* Adjust Y positions of reused rows. */
14119 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14120 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14121 max_y
= it
.last_visible_y
;
14122 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14125 row
->visible_height
= row
->height
;
14126 if (row
->y
< min_y
)
14127 row
->visible_height
-= min_y
- row
->y
;
14128 if (row
->y
+ row
->height
> max_y
)
14129 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14130 row
->redraw_fringe_bitmaps_p
= 1;
14133 /* Scroll the current matrix. */
14134 xassert (nrows_scrolled
> 0);
14135 rotate_matrix (w
->current_matrix
,
14137 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14140 /* Disable rows not reused. */
14141 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14142 row
->enabled_p
= 0;
14144 /* Point may have moved to a different line, so we cannot assume that
14145 the previous cursor position is valid; locate the correct row. */
14148 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14149 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14153 w
->cursor
.y
= row
->y
;
14155 if (row
< bottom_row
)
14157 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14158 while (glyph
->charpos
< PT
)
14161 w
->cursor
.x
+= glyph
->pixel_width
;
14167 /* Adjust window end. A null value of last_text_row means that
14168 the window end is in reused rows which in turn means that
14169 only its vpos can have changed. */
14172 w
->window_end_bytepos
14173 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14175 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14177 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14182 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14185 w
->window_end_valid
= Qnil
;
14186 w
->desired_matrix
->no_scrolling_p
= 1;
14189 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14199 /************************************************************************
14200 Window redisplay reusing current matrix when buffer has changed
14201 ************************************************************************/
14203 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14204 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14206 static struct glyph_row
*
14207 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14208 struct glyph_row
*));
14211 /* Return the last row in MATRIX displaying text. If row START is
14212 non-null, start searching with that row. IT gives the dimensions
14213 of the display. Value is null if matrix is empty; otherwise it is
14214 a pointer to the row found. */
14216 static struct glyph_row
*
14217 find_last_row_displaying_text (matrix
, it
, start
)
14218 struct glyph_matrix
*matrix
;
14220 struct glyph_row
*start
;
14222 struct glyph_row
*row
, *row_found
;
14224 /* Set row_found to the last row in IT->w's current matrix
14225 displaying text. The loop looks funny but think of partially
14228 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14229 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14231 xassert (row
->enabled_p
);
14233 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14242 /* Return the last row in the current matrix of W that is not affected
14243 by changes at the start of current_buffer that occurred since W's
14244 current matrix was built. Value is null if no such row exists.
14246 BEG_UNCHANGED us the number of characters unchanged at the start of
14247 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14248 first changed character in current_buffer. Characters at positions <
14249 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14250 when the current matrix was built. */
14252 static struct glyph_row
*
14253 find_last_unchanged_at_beg_row (w
)
14256 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14257 struct glyph_row
*row
;
14258 struct glyph_row
*row_found
= NULL
;
14259 int yb
= window_text_bottom_y (w
);
14261 /* Find the last row displaying unchanged text. */
14262 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14263 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14264 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
14266 if (/* If row ends before first_changed_pos, it is unchanged,
14267 except in some case. */
14268 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14269 /* When row ends in ZV and we write at ZV it is not
14271 && !row
->ends_at_zv_p
14272 /* When first_changed_pos is the end of a continued line,
14273 row is not unchanged because it may be no longer
14275 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14276 && (row
->continued_p
14277 || row
->exact_window_width_line_p
)))
14280 /* Stop if last visible row. */
14281 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14291 /* Find the first glyph row in the current matrix of W that is not
14292 affected by changes at the end of current_buffer since the
14293 time W's current matrix was built.
14295 Return in *DELTA the number of chars by which buffer positions in
14296 unchanged text at the end of current_buffer must be adjusted.
14298 Return in *DELTA_BYTES the corresponding number of bytes.
14300 Value is null if no such row exists, i.e. all rows are affected by
14303 static struct glyph_row
*
14304 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14306 int *delta
, *delta_bytes
;
14308 struct glyph_row
*row
;
14309 struct glyph_row
*row_found
= NULL
;
14311 *delta
= *delta_bytes
= 0;
14313 /* Display must not have been paused, otherwise the current matrix
14314 is not up to date. */
14315 if (NILP (w
->window_end_valid
))
14318 /* A value of window_end_pos >= END_UNCHANGED means that the window
14319 end is in the range of changed text. If so, there is no
14320 unchanged row at the end of W's current matrix. */
14321 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14324 /* Set row to the last row in W's current matrix displaying text. */
14325 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14327 /* If matrix is entirely empty, no unchanged row exists. */
14328 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14330 /* The value of row is the last glyph row in the matrix having a
14331 meaningful buffer position in it. The end position of row
14332 corresponds to window_end_pos. This allows us to translate
14333 buffer positions in the current matrix to current buffer
14334 positions for characters not in changed text. */
14335 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14336 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14337 int last_unchanged_pos
, last_unchanged_pos_old
;
14338 struct glyph_row
*first_text_row
14339 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14341 *delta
= Z
- Z_old
;
14342 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14344 /* Set last_unchanged_pos to the buffer position of the last
14345 character in the buffer that has not been changed. Z is the
14346 index + 1 of the last character in current_buffer, i.e. by
14347 subtracting END_UNCHANGED we get the index of the last
14348 unchanged character, and we have to add BEG to get its buffer
14350 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14351 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14353 /* Search backward from ROW for a row displaying a line that
14354 starts at a minimum position >= last_unchanged_pos_old. */
14355 for (; row
> first_text_row
; --row
)
14357 /* This used to abort, but it can happen.
14358 It is ok to just stop the search instead here. KFS. */
14359 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14362 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14367 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
14374 /* Make sure that glyph rows in the current matrix of window W
14375 reference the same glyph memory as corresponding rows in the
14376 frame's frame matrix. This function is called after scrolling W's
14377 current matrix on a terminal frame in try_window_id and
14378 try_window_reusing_current_matrix. */
14381 sync_frame_with_window_matrix_rows (w
)
14384 struct frame
*f
= XFRAME (w
->frame
);
14385 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14387 /* Preconditions: W must be a leaf window and full-width. Its frame
14388 must have a frame matrix. */
14389 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14390 xassert (WINDOW_FULL_WIDTH_P (w
));
14391 xassert (!FRAME_WINDOW_P (f
));
14393 /* If W is a full-width window, glyph pointers in W's current matrix
14394 have, by definition, to be the same as glyph pointers in the
14395 corresponding frame matrix. Note that frame matrices have no
14396 marginal areas (see build_frame_matrix). */
14397 window_row
= w
->current_matrix
->rows
;
14398 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14399 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14400 while (window_row
< window_row_end
)
14402 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14403 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14405 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14406 frame_row
->glyphs
[TEXT_AREA
] = start
;
14407 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14408 frame_row
->glyphs
[LAST_AREA
] = end
;
14410 /* Disable frame rows whose corresponding window rows have
14411 been disabled in try_window_id. */
14412 if (!window_row
->enabled_p
)
14413 frame_row
->enabled_p
= 0;
14415 ++window_row
, ++frame_row
;
14420 /* Find the glyph row in window W containing CHARPOS. Consider all
14421 rows between START and END (not inclusive). END null means search
14422 all rows to the end of the display area of W. Value is the row
14423 containing CHARPOS or null. */
14426 row_containing_pos (w
, charpos
, start
, end
, dy
)
14429 struct glyph_row
*start
, *end
;
14432 struct glyph_row
*row
= start
;
14435 /* If we happen to start on a header-line, skip that. */
14436 if (row
->mode_line_p
)
14439 if ((end
&& row
>= end
) || !row
->enabled_p
)
14442 last_y
= window_text_bottom_y (w
) - dy
;
14446 /* Give up if we have gone too far. */
14447 if (end
&& row
>= end
)
14449 /* This formerly returned if they were equal.
14450 I think that both quantities are of a "last plus one" type;
14451 if so, when they are equal, the row is within the screen. -- rms. */
14452 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14455 /* If it is in this row, return this row. */
14456 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14457 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14458 /* The end position of a row equals the start
14459 position of the next row. If CHARPOS is there, we
14460 would rather display it in the next line, except
14461 when this line ends in ZV. */
14462 && !row
->ends_at_zv_p
14463 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14464 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14471 /* Try to redisplay window W by reusing its existing display. W's
14472 current matrix must be up to date when this function is called,
14473 i.e. window_end_valid must not be nil.
14477 1 if display has been updated
14478 0 if otherwise unsuccessful
14479 -1 if redisplay with same window start is known not to succeed
14481 The following steps are performed:
14483 1. Find the last row in the current matrix of W that is not
14484 affected by changes at the start of current_buffer. If no such row
14487 2. Find the first row in W's current matrix that is not affected by
14488 changes at the end of current_buffer. Maybe there is no such row.
14490 3. Display lines beginning with the row + 1 found in step 1 to the
14491 row found in step 2 or, if step 2 didn't find a row, to the end of
14494 4. If cursor is not known to appear on the window, give up.
14496 5. If display stopped at the row found in step 2, scroll the
14497 display and current matrix as needed.
14499 6. Maybe display some lines at the end of W, if we must. This can
14500 happen under various circumstances, like a partially visible line
14501 becoming fully visible, or because newly displayed lines are displayed
14502 in smaller font sizes.
14504 7. Update W's window end information. */
14510 struct frame
*f
= XFRAME (w
->frame
);
14511 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14512 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14513 struct glyph_row
*last_unchanged_at_beg_row
;
14514 struct glyph_row
*first_unchanged_at_end_row
;
14515 struct glyph_row
*row
;
14516 struct glyph_row
*bottom_row
;
14519 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14520 struct text_pos start_pos
;
14522 int first_unchanged_at_end_vpos
= 0;
14523 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14524 struct text_pos start
;
14525 int first_changed_charpos
, last_changed_charpos
;
14528 if (inhibit_try_window_id
)
14532 /* This is handy for debugging. */
14534 #define GIVE_UP(X) \
14536 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14540 #define GIVE_UP(X) return 0
14543 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14545 /* Don't use this for mini-windows because these can show
14546 messages and mini-buffers, and we don't handle that here. */
14547 if (MINI_WINDOW_P (w
))
14550 /* This flag is used to prevent redisplay optimizations. */
14551 if (windows_or_buffers_changed
|| cursor_type_changed
)
14554 /* Verify that narrowing has not changed.
14555 Also verify that we were not told to prevent redisplay optimizations.
14556 It would be nice to further
14557 reduce the number of cases where this prevents try_window_id. */
14558 if (current_buffer
->clip_changed
14559 || current_buffer
->prevent_redisplay_optimizations_p
)
14562 /* Window must either use window-based redisplay or be full width. */
14563 if (!FRAME_WINDOW_P (f
)
14564 && (!line_ins_del_ok
14565 || !WINDOW_FULL_WIDTH_P (w
)))
14568 /* Give up if point is not known NOT to appear in W. */
14569 if (PT
< CHARPOS (start
))
14572 /* Another way to prevent redisplay optimizations. */
14573 if (XFASTINT (w
->last_modified
) == 0)
14576 /* Verify that window is not hscrolled. */
14577 if (XFASTINT (w
->hscroll
) != 0)
14580 /* Verify that display wasn't paused. */
14581 if (NILP (w
->window_end_valid
))
14584 /* Can't use this if highlighting a region because a cursor movement
14585 will do more than just set the cursor. */
14586 if (!NILP (Vtransient_mark_mode
)
14587 && !NILP (current_buffer
->mark_active
))
14590 /* Likewise if highlighting trailing whitespace. */
14591 if (!NILP (Vshow_trailing_whitespace
))
14594 /* Likewise if showing a region. */
14595 if (!NILP (w
->region_showing
))
14598 /* Can use this if overlay arrow position and or string have changed. */
14599 if (overlay_arrows_changed_p ())
14603 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14604 only if buffer has really changed. The reason is that the gap is
14605 initially at Z for freshly visited files. The code below would
14606 set end_unchanged to 0 in that case. */
14607 if (MODIFF
> SAVE_MODIFF
14608 /* This seems to happen sometimes after saving a buffer. */
14609 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14611 if (GPT
- BEG
< BEG_UNCHANGED
)
14612 BEG_UNCHANGED
= GPT
- BEG
;
14613 if (Z
- GPT
< END_UNCHANGED
)
14614 END_UNCHANGED
= Z
- GPT
;
14617 /* The position of the first and last character that has been changed. */
14618 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14619 last_changed_charpos
= Z
- END_UNCHANGED
;
14621 /* If window starts after a line end, and the last change is in
14622 front of that newline, then changes don't affect the display.
14623 This case happens with stealth-fontification. Note that although
14624 the display is unchanged, glyph positions in the matrix have to
14625 be adjusted, of course. */
14626 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14627 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14628 && ((last_changed_charpos
< CHARPOS (start
)
14629 && CHARPOS (start
) == BEGV
)
14630 || (last_changed_charpos
< CHARPOS (start
) - 1
14631 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14633 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14634 struct glyph_row
*r0
;
14636 /* Compute how many chars/bytes have been added to or removed
14637 from the buffer. */
14638 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14639 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14641 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14643 /* Give up if PT is not in the window. Note that it already has
14644 been checked at the start of try_window_id that PT is not in
14645 front of the window start. */
14646 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14649 /* If window start is unchanged, we can reuse the whole matrix
14650 as is, after adjusting glyph positions. No need to compute
14651 the window end again, since its offset from Z hasn't changed. */
14652 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14653 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14654 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14655 /* PT must not be in a partially visible line. */
14656 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14657 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14659 /* Adjust positions in the glyph matrix. */
14660 if (delta
|| delta_bytes
)
14662 struct glyph_row
*r1
14663 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14664 increment_matrix_positions (w
->current_matrix
,
14665 MATRIX_ROW_VPOS (r0
, current_matrix
),
14666 MATRIX_ROW_VPOS (r1
, current_matrix
),
14667 delta
, delta_bytes
);
14670 /* Set the cursor. */
14671 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14673 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14680 /* Handle the case that changes are all below what is displayed in
14681 the window, and that PT is in the window. This shortcut cannot
14682 be taken if ZV is visible in the window, and text has been added
14683 there that is visible in the window. */
14684 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
14685 /* ZV is not visible in the window, or there are no
14686 changes at ZV, actually. */
14687 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
14688 || first_changed_charpos
== last_changed_charpos
))
14690 struct glyph_row
*r0
;
14692 /* Give up if PT is not in the window. Note that it already has
14693 been checked at the start of try_window_id that PT is not in
14694 front of the window start. */
14695 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
14698 /* If window start is unchanged, we can reuse the whole matrix
14699 as is, without changing glyph positions since no text has
14700 been added/removed in front of the window end. */
14701 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14702 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
14703 /* PT must not be in a partially visible line. */
14704 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
14705 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14707 /* We have to compute the window end anew since text
14708 can have been added/removed after it. */
14710 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14711 w
->window_end_bytepos
14712 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14714 /* Set the cursor. */
14715 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14717 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
14724 /* Give up if window start is in the changed area.
14726 The condition used to read
14728 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
14730 but why that was tested escapes me at the moment. */
14731 if (CHARPOS (start
) >= first_changed_charpos
14732 && CHARPOS (start
) <= last_changed_charpos
)
14735 /* Check that window start agrees with the start of the first glyph
14736 row in its current matrix. Check this after we know the window
14737 start is not in changed text, otherwise positions would not be
14739 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14740 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
14743 /* Give up if the window ends in strings. Overlay strings
14744 at the end are difficult to handle, so don't try. */
14745 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
14746 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
14749 /* Compute the position at which we have to start displaying new
14750 lines. Some of the lines at the top of the window might be
14751 reusable because they are not displaying changed text. Find the
14752 last row in W's current matrix not affected by changes at the
14753 start of current_buffer. Value is null if changes start in the
14754 first line of window. */
14755 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
14756 if (last_unchanged_at_beg_row
)
14758 /* Avoid starting to display in the moddle of a character, a TAB
14759 for instance. This is easier than to set up the iterator
14760 exactly, and it's not a frequent case, so the additional
14761 effort wouldn't really pay off. */
14762 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
14763 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
14764 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
14765 --last_unchanged_at_beg_row
;
14767 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
14770 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
14772 start_pos
= it
.current
.pos
;
14774 /* Start displaying new lines in the desired matrix at the same
14775 vpos we would use in the current matrix, i.e. below
14776 last_unchanged_at_beg_row. */
14777 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
14779 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14780 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
14782 xassert (it
.hpos
== 0 && it
.current_x
== 0);
14786 /* There are no reusable lines at the start of the window.
14787 Start displaying in the first text line. */
14788 start_display (&it
, w
, start
);
14789 it
.vpos
= it
.first_vpos
;
14790 start_pos
= it
.current
.pos
;
14793 /* Find the first row that is not affected by changes at the end of
14794 the buffer. Value will be null if there is no unchanged row, in
14795 which case we must redisplay to the end of the window. delta
14796 will be set to the value by which buffer positions beginning with
14797 first_unchanged_at_end_row have to be adjusted due to text
14799 first_unchanged_at_end_row
14800 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
14801 IF_DEBUG (debug_delta
= delta
);
14802 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
14804 /* Set stop_pos to the buffer position up to which we will have to
14805 display new lines. If first_unchanged_at_end_row != NULL, this
14806 is the buffer position of the start of the line displayed in that
14807 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
14808 that we don't stop at a buffer position. */
14810 if (first_unchanged_at_end_row
)
14812 xassert (last_unchanged_at_beg_row
== NULL
14813 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
14815 /* If this is a continuation line, move forward to the next one
14816 that isn't. Changes in lines above affect this line.
14817 Caution: this may move first_unchanged_at_end_row to a row
14818 not displaying text. */
14819 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
14820 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14821 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14822 < it
.last_visible_y
))
14823 ++first_unchanged_at_end_row
;
14825 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
14826 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
14827 >= it
.last_visible_y
))
14828 first_unchanged_at_end_row
= NULL
;
14831 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
14833 first_unchanged_at_end_vpos
14834 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
14835 xassert (stop_pos
>= Z
- END_UNCHANGED
);
14838 else if (last_unchanged_at_beg_row
== NULL
)
14844 /* Either there is no unchanged row at the end, or the one we have
14845 now displays text. This is a necessary condition for the window
14846 end pos calculation at the end of this function. */
14847 xassert (first_unchanged_at_end_row
== NULL
14848 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
14850 debug_last_unchanged_at_beg_vpos
14851 = (last_unchanged_at_beg_row
14852 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
14854 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
14856 #endif /* GLYPH_DEBUG != 0 */
14859 /* Display new lines. Set last_text_row to the last new line
14860 displayed which has text on it, i.e. might end up as being the
14861 line where the window_end_vpos is. */
14862 w
->cursor
.vpos
= -1;
14863 last_text_row
= NULL
;
14864 overlay_arrow_seen
= 0;
14865 while (it
.current_y
< it
.last_visible_y
14866 && !fonts_changed_p
14867 && (first_unchanged_at_end_row
== NULL
14868 || IT_CHARPOS (it
) < stop_pos
))
14870 if (display_line (&it
))
14871 last_text_row
= it
.glyph_row
- 1;
14874 if (fonts_changed_p
)
14878 /* Compute differences in buffer positions, y-positions etc. for
14879 lines reused at the bottom of the window. Compute what we can
14881 if (first_unchanged_at_end_row
14882 /* No lines reused because we displayed everything up to the
14883 bottom of the window. */
14884 && it
.current_y
< it
.last_visible_y
)
14887 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14889 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14890 run
.current_y
= first_unchanged_at_end_row
->y
;
14891 run
.desired_y
= run
.current_y
+ dy
;
14892 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14896 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14897 first_unchanged_at_end_row
= NULL
;
14899 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14902 /* Find the cursor if not already found. We have to decide whether
14903 PT will appear on this window (it sometimes doesn't, but this is
14904 not a very frequent case.) This decision has to be made before
14905 the current matrix is altered. A value of cursor.vpos < 0 means
14906 that PT is either in one of the lines beginning at
14907 first_unchanged_at_end_row or below the window. Don't care for
14908 lines that might be displayed later at the window end; as
14909 mentioned, this is not a frequent case. */
14910 if (w
->cursor
.vpos
< 0)
14912 /* Cursor in unchanged rows at the top? */
14913 if (PT
< CHARPOS (start_pos
)
14914 && last_unchanged_at_beg_row
)
14916 row
= row_containing_pos (w
, PT
,
14917 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14918 last_unchanged_at_beg_row
+ 1, 0);
14920 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14923 /* Start from first_unchanged_at_end_row looking for PT. */
14924 else if (first_unchanged_at_end_row
)
14926 row
= row_containing_pos (w
, PT
- delta
,
14927 first_unchanged_at_end_row
, NULL
, 0);
14929 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14930 delta_bytes
, dy
, dvpos
);
14933 /* Give up if cursor was not found. */
14934 if (w
->cursor
.vpos
< 0)
14936 clear_glyph_matrix (w
->desired_matrix
);
14941 /* Don't let the cursor end in the scroll margins. */
14943 int this_scroll_margin
, cursor_height
;
14945 this_scroll_margin
= max (0, scroll_margin
);
14946 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14947 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14948 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14950 if ((w
->cursor
.y
< this_scroll_margin
14951 && CHARPOS (start
) > BEGV
)
14952 /* Old redisplay didn't take scroll margin into account at the bottom,
14953 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14954 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14955 ? cursor_height
+ this_scroll_margin
14956 : 1)) > it
.last_visible_y
)
14958 w
->cursor
.vpos
= -1;
14959 clear_glyph_matrix (w
->desired_matrix
);
14964 /* Scroll the display. Do it before changing the current matrix so
14965 that xterm.c doesn't get confused about where the cursor glyph is
14967 if (dy
&& run
.height
)
14971 if (FRAME_WINDOW_P (f
))
14973 rif
->update_window_begin_hook (w
);
14974 rif
->clear_window_mouse_face (w
);
14975 rif
->scroll_run_hook (w
, &run
);
14976 rif
->update_window_end_hook (w
, 0, 0);
14980 /* Terminal frame. In this case, dvpos gives the number of
14981 lines to scroll by; dvpos < 0 means scroll up. */
14982 int first_unchanged_at_end_vpos
14983 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14984 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14985 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14986 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14987 + window_internal_height (w
));
14989 /* Perform the operation on the screen. */
14992 /* Scroll last_unchanged_at_beg_row to the end of the
14993 window down dvpos lines. */
14994 set_terminal_window (end
);
14996 /* On dumb terminals delete dvpos lines at the end
14997 before inserting dvpos empty lines. */
14998 if (!scroll_region_ok
)
14999 ins_del_lines (end
- dvpos
, -dvpos
);
15001 /* Insert dvpos empty lines in front of
15002 last_unchanged_at_beg_row. */
15003 ins_del_lines (from
, dvpos
);
15005 else if (dvpos
< 0)
15007 /* Scroll up last_unchanged_at_beg_vpos to the end of
15008 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15009 set_terminal_window (end
);
15011 /* Delete dvpos lines in front of
15012 last_unchanged_at_beg_vpos. ins_del_lines will set
15013 the cursor to the given vpos and emit |dvpos| delete
15015 ins_del_lines (from
+ dvpos
, dvpos
);
15017 /* On a dumb terminal insert dvpos empty lines at the
15019 if (!scroll_region_ok
)
15020 ins_del_lines (end
+ dvpos
, -dvpos
);
15023 set_terminal_window (0);
15029 /* Shift reused rows of the current matrix to the right position.
15030 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15032 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15033 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15036 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15037 bottom_vpos
, dvpos
);
15038 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15041 else if (dvpos
> 0)
15043 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15044 bottom_vpos
, dvpos
);
15045 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15046 first_unchanged_at_end_vpos
+ dvpos
, 0);
15049 /* For frame-based redisplay, make sure that current frame and window
15050 matrix are in sync with respect to glyph memory. */
15051 if (!FRAME_WINDOW_P (f
))
15052 sync_frame_with_window_matrix_rows (w
);
15054 /* Adjust buffer positions in reused rows. */
15055 if (delta
|| delta_bytes
)
15056 increment_matrix_positions (current_matrix
,
15057 first_unchanged_at_end_vpos
+ dvpos
,
15058 bottom_vpos
, delta
, delta_bytes
);
15060 /* Adjust Y positions. */
15062 shift_glyph_matrix (w
, current_matrix
,
15063 first_unchanged_at_end_vpos
+ dvpos
,
15066 if (first_unchanged_at_end_row
)
15068 first_unchanged_at_end_row
+= dvpos
;
15069 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15070 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15071 first_unchanged_at_end_row
= NULL
;
15074 /* If scrolling up, there may be some lines to display at the end of
15076 last_text_row_at_end
= NULL
;
15079 /* Scrolling up can leave for example a partially visible line
15080 at the end of the window to be redisplayed. */
15081 /* Set last_row to the glyph row in the current matrix where the
15082 window end line is found. It has been moved up or down in
15083 the matrix by dvpos. */
15084 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15085 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15087 /* If last_row is the window end line, it should display text. */
15088 xassert (last_row
->displays_text_p
);
15090 /* If window end line was partially visible before, begin
15091 displaying at that line. Otherwise begin displaying with the
15092 line following it. */
15093 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15095 init_to_row_start (&it
, w
, last_row
);
15096 it
.vpos
= last_vpos
;
15097 it
.current_y
= last_row
->y
;
15101 init_to_row_end (&it
, w
, last_row
);
15102 it
.vpos
= 1 + last_vpos
;
15103 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15107 /* We may start in a continuation line. If so, we have to
15108 get the right continuation_lines_width and current_x. */
15109 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15110 it
.hpos
= it
.current_x
= 0;
15112 /* Display the rest of the lines at the window end. */
15113 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15114 while (it
.current_y
< it
.last_visible_y
15115 && !fonts_changed_p
)
15117 /* Is it always sure that the display agrees with lines in
15118 the current matrix? I don't think so, so we mark rows
15119 displayed invalid in the current matrix by setting their
15120 enabled_p flag to zero. */
15121 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15122 if (display_line (&it
))
15123 last_text_row_at_end
= it
.glyph_row
- 1;
15127 /* Update window_end_pos and window_end_vpos. */
15128 if (first_unchanged_at_end_row
15129 && !last_text_row_at_end
)
15131 /* Window end line if one of the preserved rows from the current
15132 matrix. Set row to the last row displaying text in current
15133 matrix starting at first_unchanged_at_end_row, after
15135 xassert (first_unchanged_at_end_row
->displays_text_p
);
15136 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15137 first_unchanged_at_end_row
);
15138 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15140 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15141 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15143 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15144 xassert (w
->window_end_bytepos
>= 0);
15145 IF_DEBUG (debug_method_add (w
, "A"));
15147 else if (last_text_row_at_end
)
15150 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15151 w
->window_end_bytepos
15152 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15154 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15155 xassert (w
->window_end_bytepos
>= 0);
15156 IF_DEBUG (debug_method_add (w
, "B"));
15158 else if (last_text_row
)
15160 /* We have displayed either to the end of the window or at the
15161 end of the window, i.e. the last row with text is to be found
15162 in the desired matrix. */
15164 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15165 w
->window_end_bytepos
15166 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15168 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15169 xassert (w
->window_end_bytepos
>= 0);
15171 else if (first_unchanged_at_end_row
== NULL
15172 && last_text_row
== NULL
15173 && last_text_row_at_end
== NULL
)
15175 /* Displayed to end of window, but no line containing text was
15176 displayed. Lines were deleted at the end of the window. */
15177 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15178 int vpos
= XFASTINT (w
->window_end_vpos
);
15179 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15180 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15183 row
== NULL
&& vpos
>= first_vpos
;
15184 --vpos
, --current_row
, --desired_row
)
15186 if (desired_row
->enabled_p
)
15188 if (desired_row
->displays_text_p
)
15191 else if (current_row
->displays_text_p
)
15195 xassert (row
!= NULL
);
15196 w
->window_end_vpos
= make_number (vpos
+ 1);
15197 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15198 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15199 xassert (w
->window_end_bytepos
>= 0);
15200 IF_DEBUG (debug_method_add (w
, "C"));
15205 #if 0 /* This leads to problems, for instance when the cursor is
15206 at ZV, and the cursor line displays no text. */
15207 /* Disable rows below what's displayed in the window. This makes
15208 debugging easier. */
15209 enable_glyph_matrix_rows (current_matrix
,
15210 XFASTINT (w
->window_end_vpos
) + 1,
15214 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15215 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15217 /* Record that display has not been completed. */
15218 w
->window_end_valid
= Qnil
;
15219 w
->desired_matrix
->no_scrolling_p
= 1;
15227 /***********************************************************************
15228 More debugging support
15229 ***********************************************************************/
15233 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15234 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15235 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15238 /* Dump the contents of glyph matrix MATRIX on stderr.
15240 GLYPHS 0 means don't show glyph contents.
15241 GLYPHS 1 means show glyphs in short form
15242 GLYPHS > 1 means show glyphs in long form. */
15245 dump_glyph_matrix (matrix
, glyphs
)
15246 struct glyph_matrix
*matrix
;
15250 for (i
= 0; i
< matrix
->nrows
; ++i
)
15251 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15255 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15256 the glyph row and area where the glyph comes from. */
15259 dump_glyph (row
, glyph
, area
)
15260 struct glyph_row
*row
;
15261 struct glyph
*glyph
;
15264 if (glyph
->type
== CHAR_GLYPH
)
15267 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15268 glyph
- row
->glyphs
[TEXT_AREA
],
15271 (BUFFERP (glyph
->object
)
15273 : (STRINGP (glyph
->object
)
15276 glyph
->pixel_width
,
15278 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15282 glyph
->left_box_line_p
,
15283 glyph
->right_box_line_p
);
15285 else if (glyph
->type
== STRETCH_GLYPH
)
15288 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15289 glyph
- row
->glyphs
[TEXT_AREA
],
15292 (BUFFERP (glyph
->object
)
15294 : (STRINGP (glyph
->object
)
15297 glyph
->pixel_width
,
15301 glyph
->left_box_line_p
,
15302 glyph
->right_box_line_p
);
15304 else if (glyph
->type
== IMAGE_GLYPH
)
15307 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15308 glyph
- row
->glyphs
[TEXT_AREA
],
15311 (BUFFERP (glyph
->object
)
15313 : (STRINGP (glyph
->object
)
15316 glyph
->pixel_width
,
15320 glyph
->left_box_line_p
,
15321 glyph
->right_box_line_p
);
15323 else if (glyph
->type
== COMPOSITE_GLYPH
)
15326 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15327 glyph
- row
->glyphs
[TEXT_AREA
],
15330 (BUFFERP (glyph
->object
)
15332 : (STRINGP (glyph
->object
)
15335 glyph
->pixel_width
,
15339 glyph
->left_box_line_p
,
15340 glyph
->right_box_line_p
);
15345 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15346 GLYPHS 0 means don't show glyph contents.
15347 GLYPHS 1 means show glyphs in short form
15348 GLYPHS > 1 means show glyphs in long form. */
15351 dump_glyph_row (row
, vpos
, glyphs
)
15352 struct glyph_row
*row
;
15357 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15358 fprintf (stderr
, "======================================================================\n");
15360 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15361 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15363 MATRIX_ROW_START_CHARPOS (row
),
15364 MATRIX_ROW_END_CHARPOS (row
),
15365 row
->used
[TEXT_AREA
],
15366 row
->contains_overlapping_glyphs_p
,
15368 row
->truncated_on_left_p
,
15369 row
->truncated_on_right_p
,
15371 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15372 row
->displays_text_p
,
15375 row
->ends_in_middle_of_char_p
,
15376 row
->starts_in_middle_of_char_p
,
15382 row
->visible_height
,
15385 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15386 row
->end
.overlay_string_index
,
15387 row
->continuation_lines_width
);
15388 fprintf (stderr
, "%9d %5d\n",
15389 CHARPOS (row
->start
.string_pos
),
15390 CHARPOS (row
->end
.string_pos
));
15391 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15392 row
->end
.dpvec_index
);
15399 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15401 struct glyph
*glyph
= row
->glyphs
[area
];
15402 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15404 /* Glyph for a line end in text. */
15405 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15408 if (glyph
< glyph_end
)
15409 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15411 for (; glyph
< glyph_end
; ++glyph
)
15412 dump_glyph (row
, glyph
, area
);
15415 else if (glyphs
== 1)
15419 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15421 char *s
= (char *) alloca (row
->used
[area
] + 1);
15424 for (i
= 0; i
< row
->used
[area
]; ++i
)
15426 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15427 if (glyph
->type
== CHAR_GLYPH
15428 && glyph
->u
.ch
< 0x80
15429 && glyph
->u
.ch
>= ' ')
15430 s
[i
] = glyph
->u
.ch
;
15436 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15442 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15443 Sdump_glyph_matrix
, 0, 1, "p",
15444 doc
: /* Dump the current matrix of the selected window to stderr.
15445 Shows contents of glyph row structures. With non-nil
15446 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15447 glyphs in short form, otherwise show glyphs in long form. */)
15449 Lisp_Object glyphs
;
15451 struct window
*w
= XWINDOW (selected_window
);
15452 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15454 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15455 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15456 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15457 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15458 fprintf (stderr
, "=============================================\n");
15459 dump_glyph_matrix (w
->current_matrix
,
15460 NILP (glyphs
) ? 0 : XINT (glyphs
));
15465 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15466 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15469 struct frame
*f
= XFRAME (selected_frame
);
15470 dump_glyph_matrix (f
->current_matrix
, 1);
15475 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15476 doc
: /* Dump glyph row ROW to stderr.
15477 GLYPH 0 means don't dump glyphs.
15478 GLYPH 1 means dump glyphs in short form.
15479 GLYPH > 1 or omitted means dump glyphs in long form. */)
15481 Lisp_Object row
, glyphs
;
15483 struct glyph_matrix
*matrix
;
15486 CHECK_NUMBER (row
);
15487 matrix
= XWINDOW (selected_window
)->current_matrix
;
15489 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15490 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15492 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15497 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15498 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15499 GLYPH 0 means don't dump glyphs.
15500 GLYPH 1 means dump glyphs in short form.
15501 GLYPH > 1 or omitted means dump glyphs in long form. */)
15503 Lisp_Object row
, glyphs
;
15505 struct frame
*sf
= SELECTED_FRAME ();
15506 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15509 CHECK_NUMBER (row
);
15511 if (vpos
>= 0 && vpos
< m
->nrows
)
15512 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15513 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15518 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15519 doc
: /* Toggle tracing of redisplay.
15520 With ARG, turn tracing on if and only if ARG is positive. */)
15525 trace_redisplay_p
= !trace_redisplay_p
;
15528 arg
= Fprefix_numeric_value (arg
);
15529 trace_redisplay_p
= XINT (arg
) > 0;
15536 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15537 doc
: /* Like `format', but print result to stderr.
15538 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15543 Lisp_Object s
= Fformat (nargs
, args
);
15544 fprintf (stderr
, "%s", SDATA (s
));
15548 #endif /* GLYPH_DEBUG */
15552 /***********************************************************************
15553 Building Desired Matrix Rows
15554 ***********************************************************************/
15556 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15557 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15559 static struct glyph_row
*
15560 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15562 Lisp_Object overlay_arrow_string
;
15564 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15565 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15566 struct buffer
*old
= current_buffer
;
15567 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15568 int arrow_len
= SCHARS (overlay_arrow_string
);
15569 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15570 const unsigned char *p
;
15573 int n_glyphs_before
;
15575 set_buffer_temp (buffer
);
15576 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15577 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15578 SET_TEXT_POS (it
.position
, 0, 0);
15580 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15582 while (p
< arrow_end
)
15584 Lisp_Object face
, ilisp
;
15586 /* Get the next character. */
15588 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15590 it
.c
= *p
, it
.len
= 1;
15593 /* Get its face. */
15594 ilisp
= make_number (p
- arrow_string
);
15595 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15596 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15598 /* Compute its width, get its glyphs. */
15599 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15600 SET_TEXT_POS (it
.position
, -1, -1);
15601 PRODUCE_GLYPHS (&it
);
15603 /* If this character doesn't fit any more in the line, we have
15604 to remove some glyphs. */
15605 if (it
.current_x
> it
.last_visible_x
)
15607 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15612 set_buffer_temp (old
);
15613 return it
.glyph_row
;
15617 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15618 glyphs are only inserted for terminal frames since we can't really
15619 win with truncation glyphs when partially visible glyphs are
15620 involved. Which glyphs to insert is determined by
15621 produce_special_glyphs. */
15624 insert_left_trunc_glyphs (it
)
15627 struct it truncate_it
;
15628 struct glyph
*from
, *end
, *to
, *toend
;
15630 xassert (!FRAME_WINDOW_P (it
->f
));
15632 /* Get the truncation glyphs. */
15634 truncate_it
.current_x
= 0;
15635 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15636 truncate_it
.glyph_row
= &scratch_glyph_row
;
15637 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15638 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15639 truncate_it
.object
= make_number (0);
15640 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15642 /* Overwrite glyphs from IT with truncation glyphs. */
15643 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15644 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15645 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15646 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15651 /* There may be padding glyphs left over. Overwrite them too. */
15652 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15654 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15660 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15664 /* Compute the pixel height and width of IT->glyph_row.
15666 Most of the time, ascent and height of a display line will be equal
15667 to the max_ascent and max_height values of the display iterator
15668 structure. This is not the case if
15670 1. We hit ZV without displaying anything. In this case, max_ascent
15671 and max_height will be zero.
15673 2. We have some glyphs that don't contribute to the line height.
15674 (The glyph row flag contributes_to_line_height_p is for future
15675 pixmap extensions).
15677 The first case is easily covered by using default values because in
15678 these cases, the line height does not really matter, except that it
15679 must not be zero. */
15682 compute_line_metrics (it
)
15685 struct glyph_row
*row
= it
->glyph_row
;
15688 if (FRAME_WINDOW_P (it
->f
))
15690 int i
, min_y
, max_y
;
15692 /* The line may consist of one space only, that was added to
15693 place the cursor on it. If so, the row's height hasn't been
15695 if (row
->height
== 0)
15697 if (it
->max_ascent
+ it
->max_descent
== 0)
15698 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
15699 row
->ascent
= it
->max_ascent
;
15700 row
->height
= it
->max_ascent
+ it
->max_descent
;
15701 row
->phys_ascent
= it
->max_phys_ascent
;
15702 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15703 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15706 /* Compute the width of this line. */
15707 row
->pixel_width
= row
->x
;
15708 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
15709 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
15711 xassert (row
->pixel_width
>= 0);
15712 xassert (row
->ascent
>= 0 && row
->height
> 0);
15714 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
15715 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
15717 /* If first line's physical ascent is larger than its logical
15718 ascent, use the physical ascent, and make the row taller.
15719 This makes accented characters fully visible. */
15720 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
15721 && row
->phys_ascent
> row
->ascent
)
15723 row
->height
+= row
->phys_ascent
- row
->ascent
;
15724 row
->ascent
= row
->phys_ascent
;
15727 /* Compute how much of the line is visible. */
15728 row
->visible_height
= row
->height
;
15730 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
15731 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
15733 if (row
->y
< min_y
)
15734 row
->visible_height
-= min_y
- row
->y
;
15735 if (row
->y
+ row
->height
> max_y
)
15736 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15740 row
->pixel_width
= row
->used
[TEXT_AREA
];
15741 if (row
->continued_p
)
15742 row
->pixel_width
-= it
->continuation_pixel_width
;
15743 else if (row
->truncated_on_right_p
)
15744 row
->pixel_width
-= it
->truncation_pixel_width
;
15745 row
->ascent
= row
->phys_ascent
= 0;
15746 row
->height
= row
->phys_height
= row
->visible_height
= 1;
15747 row
->extra_line_spacing
= 0;
15750 /* Compute a hash code for this row. */
15752 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15753 for (i
= 0; i
< row
->used
[area
]; ++i
)
15754 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
15755 + row
->glyphs
[area
][i
].u
.val
15756 + row
->glyphs
[area
][i
].face_id
15757 + row
->glyphs
[area
][i
].padding_p
15758 + (row
->glyphs
[area
][i
].type
<< 2));
15760 it
->max_ascent
= it
->max_descent
= 0;
15761 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
15765 /* Append one space to the glyph row of iterator IT if doing a
15766 window-based redisplay. The space has the same face as
15767 IT->face_id. Value is non-zero if a space was added.
15769 This function is called to make sure that there is always one glyph
15770 at the end of a glyph row that the cursor can be set on under
15771 window-systems. (If there weren't such a glyph we would not know
15772 how wide and tall a box cursor should be displayed).
15774 At the same time this space let's a nicely handle clearing to the
15775 end of the line if the row ends in italic text. */
15778 append_space_for_newline (it
, default_face_p
)
15780 int default_face_p
;
15782 if (FRAME_WINDOW_P (it
->f
))
15784 int n
= it
->glyph_row
->used
[TEXT_AREA
];
15786 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
15787 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
15789 /* Save some values that must not be changed.
15790 Must save IT->c and IT->len because otherwise
15791 ITERATOR_AT_END_P wouldn't work anymore after
15792 append_space_for_newline has been called. */
15793 enum display_element_type saved_what
= it
->what
;
15794 int saved_c
= it
->c
, saved_len
= it
->len
;
15795 int saved_x
= it
->current_x
;
15796 int saved_face_id
= it
->face_id
;
15797 struct text_pos saved_pos
;
15798 Lisp_Object saved_object
;
15801 saved_object
= it
->object
;
15802 saved_pos
= it
->position
;
15804 it
->what
= IT_CHARACTER
;
15805 bzero (&it
->position
, sizeof it
->position
);
15806 it
->object
= make_number (0);
15810 if (default_face_p
)
15811 it
->face_id
= DEFAULT_FACE_ID
;
15812 else if (it
->face_before_selective_p
)
15813 it
->face_id
= it
->saved_face_id
;
15814 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
15815 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
15817 PRODUCE_GLYPHS (it
);
15819 it
->override_ascent
= -1;
15820 it
->constrain_row_ascent_descent_p
= 0;
15821 it
->current_x
= saved_x
;
15822 it
->object
= saved_object
;
15823 it
->position
= saved_pos
;
15824 it
->what
= saved_what
;
15825 it
->face_id
= saved_face_id
;
15826 it
->len
= saved_len
;
15836 /* Extend the face of the last glyph in the text area of IT->glyph_row
15837 to the end of the display line. Called from display_line.
15838 If the glyph row is empty, add a space glyph to it so that we
15839 know the face to draw. Set the glyph row flag fill_line_p. */
15842 extend_face_to_end_of_line (it
)
15846 struct frame
*f
= it
->f
;
15848 /* If line is already filled, do nothing. */
15849 if (it
->current_x
>= it
->last_visible_x
)
15852 /* Face extension extends the background and box of IT->face_id
15853 to the end of the line. If the background equals the background
15854 of the frame, we don't have to do anything. */
15855 if (it
->face_before_selective_p
)
15856 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
15858 face
= FACE_FROM_ID (f
, it
->face_id
);
15860 if (FRAME_WINDOW_P (f
)
15861 && it
->glyph_row
->displays_text_p
15862 && face
->box
== FACE_NO_BOX
15863 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
15867 /* Set the glyph row flag indicating that the face of the last glyph
15868 in the text area has to be drawn to the end of the text area. */
15869 it
->glyph_row
->fill_line_p
= 1;
15871 /* If current character of IT is not ASCII, make sure we have the
15872 ASCII face. This will be automatically undone the next time
15873 get_next_display_element returns a multibyte character. Note
15874 that the character will always be single byte in unibyte text. */
15875 if (!ASCII_CHAR_P (it
->c
))
15877 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
15880 if (FRAME_WINDOW_P (f
))
15882 /* If the row is empty, add a space with the current face of IT,
15883 so that we know which face to draw. */
15884 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
15886 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
15887 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
15888 it
->glyph_row
->used
[TEXT_AREA
] = 1;
15893 /* Save some values that must not be changed. */
15894 int saved_x
= it
->current_x
;
15895 struct text_pos saved_pos
;
15896 Lisp_Object saved_object
;
15897 enum display_element_type saved_what
= it
->what
;
15898 int saved_face_id
= it
->face_id
;
15900 saved_object
= it
->object
;
15901 saved_pos
= it
->position
;
15903 it
->what
= IT_CHARACTER
;
15904 bzero (&it
->position
, sizeof it
->position
);
15905 it
->object
= make_number (0);
15908 it
->face_id
= face
->id
;
15910 PRODUCE_GLYPHS (it
);
15912 while (it
->current_x
<= it
->last_visible_x
)
15913 PRODUCE_GLYPHS (it
);
15915 /* Don't count these blanks really. It would let us insert a left
15916 truncation glyph below and make us set the cursor on them, maybe. */
15917 it
->current_x
= saved_x
;
15918 it
->object
= saved_object
;
15919 it
->position
= saved_pos
;
15920 it
->what
= saved_what
;
15921 it
->face_id
= saved_face_id
;
15926 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15927 trailing whitespace. */
15930 trailing_whitespace_p (charpos
)
15933 int bytepos
= CHAR_TO_BYTE (charpos
);
15936 while (bytepos
< ZV_BYTE
15937 && (c
= FETCH_CHAR (bytepos
),
15938 c
== ' ' || c
== '\t'))
15941 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15943 if (bytepos
!= PT_BYTE
)
15950 /* Highlight trailing whitespace, if any, in ROW. */
15953 highlight_trailing_whitespace (f
, row
)
15955 struct glyph_row
*row
;
15957 int used
= row
->used
[TEXT_AREA
];
15961 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15962 struct glyph
*glyph
= start
+ used
- 1;
15964 /* Skip over glyphs inserted to display the cursor at the
15965 end of a line, for extending the face of the last glyph
15966 to the end of the line on terminals, and for truncation
15967 and continuation glyphs. */
15968 while (glyph
>= start
15969 && glyph
->type
== CHAR_GLYPH
15970 && INTEGERP (glyph
->object
))
15973 /* If last glyph is a space or stretch, and it's trailing
15974 whitespace, set the face of all trailing whitespace glyphs in
15975 IT->glyph_row to `trailing-whitespace'. */
15977 && BUFFERP (glyph
->object
)
15978 && (glyph
->type
== STRETCH_GLYPH
15979 || (glyph
->type
== CHAR_GLYPH
15980 && glyph
->u
.ch
== ' '))
15981 && trailing_whitespace_p (glyph
->charpos
))
15983 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
15987 while (glyph
>= start
15988 && BUFFERP (glyph
->object
)
15989 && (glyph
->type
== STRETCH_GLYPH
15990 || (glyph
->type
== CHAR_GLYPH
15991 && glyph
->u
.ch
== ' ')))
15992 (glyph
--)->face_id
= face_id
;
15998 /* Value is non-zero if glyph row ROW in window W should be
15999 used to hold the cursor. */
16002 cursor_row_p (w
, row
)
16004 struct glyph_row
*row
;
16006 int cursor_row_p
= 1;
16008 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16010 /* Suppose the row ends on a string.
16011 Unless the row is continued, that means it ends on a newline
16012 in the string. If it's anything other than a display string
16013 (e.g. a before-string from an overlay), we don't want the
16014 cursor there. (This heuristic seems to give the optimal
16015 behavior for the various types of multi-line strings.) */
16016 if (CHARPOS (row
->end
.string_pos
) >= 0)
16018 if (row
->continued_p
)
16022 /* Check for `display' property. */
16023 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16024 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16025 struct glyph
*glyph
;
16028 for (glyph
= end
; glyph
>= beg
; --glyph
)
16029 if (STRINGP (glyph
->object
))
16032 = Fget_char_property (make_number (PT
),
16036 && display_prop_string_p (prop
, glyph
->object
));
16041 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16043 /* If the row ends in middle of a real character,
16044 and the line is continued, we want the cursor here.
16045 That's because MATRIX_ROW_END_CHARPOS would equal
16046 PT if PT is before the character. */
16047 if (!row
->ends_in_ellipsis_p
)
16048 cursor_row_p
= row
->continued_p
;
16050 /* If the row ends in an ellipsis, then
16051 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16052 We want that position to be displayed after the ellipsis. */
16055 /* If the row ends at ZV, display the cursor at the end of that
16056 row instead of at the start of the row below. */
16057 else if (row
->ends_at_zv_p
)
16063 return cursor_row_p
;
16067 /* Construct the glyph row IT->glyph_row in the desired matrix of
16068 IT->w from text at the current position of IT. See dispextern.h
16069 for an overview of struct it. Value is non-zero if
16070 IT->glyph_row displays text, as opposed to a line displaying ZV
16077 struct glyph_row
*row
= it
->glyph_row
;
16078 Lisp_Object overlay_arrow_string
;
16080 /* We always start displaying at hpos zero even if hscrolled. */
16081 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16083 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16084 >= it
->w
->desired_matrix
->nrows
)
16086 it
->w
->nrows_scale_factor
++;
16087 fonts_changed_p
= 1;
16091 /* Is IT->w showing the region? */
16092 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16094 /* Clear the result glyph row and enable it. */
16095 prepare_desired_row (row
);
16097 row
->y
= it
->current_y
;
16098 row
->start
= it
->start
;
16099 row
->continuation_lines_width
= it
->continuation_lines_width
;
16100 row
->displays_text_p
= 1;
16101 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16102 it
->starts_in_middle_of_char_p
= 0;
16104 /* Arrange the overlays nicely for our purposes. Usually, we call
16105 display_line on only one line at a time, in which case this
16106 can't really hurt too much, or we call it on lines which appear
16107 one after another in the buffer, in which case all calls to
16108 recenter_overlay_lists but the first will be pretty cheap. */
16109 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16111 /* Move over display elements that are not visible because we are
16112 hscrolled. This may stop at an x-position < IT->first_visible_x
16113 if the first glyph is partially visible or if we hit a line end. */
16114 if (it
->current_x
< it
->first_visible_x
)
16116 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16117 MOVE_TO_POS
| MOVE_TO_X
);
16120 /* Get the initial row height. This is either the height of the
16121 text hscrolled, if there is any, or zero. */
16122 row
->ascent
= it
->max_ascent
;
16123 row
->height
= it
->max_ascent
+ it
->max_descent
;
16124 row
->phys_ascent
= it
->max_phys_ascent
;
16125 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16126 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16128 /* Loop generating characters. The loop is left with IT on the next
16129 character to display. */
16132 int n_glyphs_before
, hpos_before
, x_before
;
16134 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16136 /* Retrieve the next thing to display. Value is zero if end of
16138 if (!get_next_display_element (it
))
16140 /* Maybe add a space at the end of this line that is used to
16141 display the cursor there under X. Set the charpos of the
16142 first glyph of blank lines not corresponding to any text
16144 #ifdef HAVE_WINDOW_SYSTEM
16145 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16146 row
->exact_window_width_line_p
= 1;
16148 #endif /* HAVE_WINDOW_SYSTEM */
16149 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16150 || row
->used
[TEXT_AREA
] == 0)
16152 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16153 row
->displays_text_p
= 0;
16155 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16156 && (!MINI_WINDOW_P (it
->w
)
16157 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16158 row
->indicate_empty_line_p
= 1;
16161 it
->continuation_lines_width
= 0;
16162 row
->ends_at_zv_p
= 1;
16166 /* Now, get the metrics of what we want to display. This also
16167 generates glyphs in `row' (which is IT->glyph_row). */
16168 n_glyphs_before
= row
->used
[TEXT_AREA
];
16171 /* Remember the line height so far in case the next element doesn't
16172 fit on the line. */
16173 if (!it
->truncate_lines_p
)
16175 ascent
= it
->max_ascent
;
16176 descent
= it
->max_descent
;
16177 phys_ascent
= it
->max_phys_ascent
;
16178 phys_descent
= it
->max_phys_descent
;
16181 PRODUCE_GLYPHS (it
);
16183 /* If this display element was in marginal areas, continue with
16185 if (it
->area
!= TEXT_AREA
)
16187 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16188 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16189 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16190 row
->phys_height
= max (row
->phys_height
,
16191 it
->max_phys_ascent
+ it
->max_phys_descent
);
16192 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16193 it
->max_extra_line_spacing
);
16194 set_iterator_to_next (it
, 1);
16198 /* Does the display element fit on the line? If we truncate
16199 lines, we should draw past the right edge of the window. If
16200 we don't truncate, we want to stop so that we can display the
16201 continuation glyph before the right margin. If lines are
16202 continued, there are two possible strategies for characters
16203 resulting in more than 1 glyph (e.g. tabs): Display as many
16204 glyphs as possible in this line and leave the rest for the
16205 continuation line, or display the whole element in the next
16206 line. Original redisplay did the former, so we do it also. */
16207 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16208 hpos_before
= it
->hpos
;
16211 if (/* Not a newline. */
16213 /* Glyphs produced fit entirely in the line. */
16214 && it
->current_x
< it
->last_visible_x
)
16216 it
->hpos
+= nglyphs
;
16217 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16218 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16219 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16220 row
->phys_height
= max (row
->phys_height
,
16221 it
->max_phys_ascent
+ it
->max_phys_descent
);
16222 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16223 it
->max_extra_line_spacing
);
16224 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16225 row
->x
= x
- it
->first_visible_x
;
16230 struct glyph
*glyph
;
16232 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16234 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16235 new_x
= x
+ glyph
->pixel_width
;
16237 if (/* Lines are continued. */
16238 !it
->truncate_lines_p
16239 && (/* Glyph doesn't fit on the line. */
16240 new_x
> it
->last_visible_x
16241 /* Or it fits exactly on a window system frame. */
16242 || (new_x
== it
->last_visible_x
16243 && FRAME_WINDOW_P (it
->f
))))
16245 /* End of a continued line. */
16248 || (new_x
== it
->last_visible_x
16249 && FRAME_WINDOW_P (it
->f
)))
16251 /* Current glyph is the only one on the line or
16252 fits exactly on the line. We must continue
16253 the line because we can't draw the cursor
16254 after the glyph. */
16255 row
->continued_p
= 1;
16256 it
->current_x
= new_x
;
16257 it
->continuation_lines_width
+= new_x
;
16259 if (i
== nglyphs
- 1)
16261 set_iterator_to_next (it
, 1);
16262 #ifdef HAVE_WINDOW_SYSTEM
16263 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16265 if (!get_next_display_element (it
))
16267 row
->exact_window_width_line_p
= 1;
16268 it
->continuation_lines_width
= 0;
16269 row
->continued_p
= 0;
16270 row
->ends_at_zv_p
= 1;
16272 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16274 row
->continued_p
= 0;
16275 row
->exact_window_width_line_p
= 1;
16278 #endif /* HAVE_WINDOW_SYSTEM */
16281 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16282 && !FRAME_WINDOW_P (it
->f
))
16284 /* A padding glyph that doesn't fit on this line.
16285 This means the whole character doesn't fit
16287 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16289 /* Fill the rest of the row with continuation
16290 glyphs like in 20.x. */
16291 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16292 < row
->glyphs
[1 + TEXT_AREA
])
16293 produce_special_glyphs (it
, IT_CONTINUATION
);
16295 row
->continued_p
= 1;
16296 it
->current_x
= x_before
;
16297 it
->continuation_lines_width
+= x_before
;
16299 /* Restore the height to what it was before the
16300 element not fitting on the line. */
16301 it
->max_ascent
= ascent
;
16302 it
->max_descent
= descent
;
16303 it
->max_phys_ascent
= phys_ascent
;
16304 it
->max_phys_descent
= phys_descent
;
16306 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16308 /* A TAB that extends past the right edge of the
16309 window. This produces a single glyph on
16310 window system frames. We leave the glyph in
16311 this row and let it fill the row, but don't
16312 consume the TAB. */
16313 it
->continuation_lines_width
+= it
->last_visible_x
;
16314 row
->ends_in_middle_of_char_p
= 1;
16315 row
->continued_p
= 1;
16316 glyph
->pixel_width
= it
->last_visible_x
- x
;
16317 it
->starts_in_middle_of_char_p
= 1;
16321 /* Something other than a TAB that draws past
16322 the right edge of the window. Restore
16323 positions to values before the element. */
16324 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16326 /* Display continuation glyphs. */
16327 if (!FRAME_WINDOW_P (it
->f
))
16328 produce_special_glyphs (it
, IT_CONTINUATION
);
16329 row
->continued_p
= 1;
16331 it
->current_x
= x_before
;
16332 it
->continuation_lines_width
+= x
;
16333 extend_face_to_end_of_line (it
);
16335 if (nglyphs
> 1 && i
> 0)
16337 row
->ends_in_middle_of_char_p
= 1;
16338 it
->starts_in_middle_of_char_p
= 1;
16341 /* Restore the height to what it was before the
16342 element not fitting on the line. */
16343 it
->max_ascent
= ascent
;
16344 it
->max_descent
= descent
;
16345 it
->max_phys_ascent
= phys_ascent
;
16346 it
->max_phys_descent
= phys_descent
;
16351 else if (new_x
> it
->first_visible_x
)
16353 /* Increment number of glyphs actually displayed. */
16356 if (x
< it
->first_visible_x
)
16357 /* Glyph is partially visible, i.e. row starts at
16358 negative X position. */
16359 row
->x
= x
- it
->first_visible_x
;
16363 /* Glyph is completely off the left margin of the
16364 window. This should not happen because of the
16365 move_it_in_display_line at the start of this
16366 function, unless the text display area of the
16367 window is empty. */
16368 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16372 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16373 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16374 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16375 row
->phys_height
= max (row
->phys_height
,
16376 it
->max_phys_ascent
+ it
->max_phys_descent
);
16377 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16378 it
->max_extra_line_spacing
);
16380 /* End of this display line if row is continued. */
16381 if (row
->continued_p
|| row
->ends_at_zv_p
)
16386 /* Is this a line end? If yes, we're also done, after making
16387 sure that a non-default face is extended up to the right
16388 margin of the window. */
16389 if (ITERATOR_AT_END_OF_LINE_P (it
))
16391 int used_before
= row
->used
[TEXT_AREA
];
16393 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16395 #ifdef HAVE_WINDOW_SYSTEM
16396 /* Add a space at the end of the line that is used to
16397 display the cursor there. */
16398 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16399 append_space_for_newline (it
, 0);
16400 #endif /* HAVE_WINDOW_SYSTEM */
16402 /* Extend the face to the end of the line. */
16403 extend_face_to_end_of_line (it
);
16405 /* Make sure we have the position. */
16406 if (used_before
== 0)
16407 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16409 /* Consume the line end. This skips over invisible lines. */
16410 set_iterator_to_next (it
, 1);
16411 it
->continuation_lines_width
= 0;
16415 /* Proceed with next display element. Note that this skips
16416 over lines invisible because of selective display. */
16417 set_iterator_to_next (it
, 1);
16419 /* If we truncate lines, we are done when the last displayed
16420 glyphs reach past the right margin of the window. */
16421 if (it
->truncate_lines_p
16422 && (FRAME_WINDOW_P (it
->f
)
16423 ? (it
->current_x
>= it
->last_visible_x
)
16424 : (it
->current_x
> it
->last_visible_x
)))
16426 /* Maybe add truncation glyphs. */
16427 if (!FRAME_WINDOW_P (it
->f
))
16431 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16432 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16435 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16437 row
->used
[TEXT_AREA
] = i
;
16438 produce_special_glyphs (it
, IT_TRUNCATION
);
16441 #ifdef HAVE_WINDOW_SYSTEM
16444 /* Don't truncate if we can overflow newline into fringe. */
16445 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16447 if (!get_next_display_element (it
))
16449 it
->continuation_lines_width
= 0;
16450 row
->ends_at_zv_p
= 1;
16451 row
->exact_window_width_line_p
= 1;
16454 if (ITERATOR_AT_END_OF_LINE_P (it
))
16456 row
->exact_window_width_line_p
= 1;
16457 goto at_end_of_line
;
16461 #endif /* HAVE_WINDOW_SYSTEM */
16463 row
->truncated_on_right_p
= 1;
16464 it
->continuation_lines_width
= 0;
16465 reseat_at_next_visible_line_start (it
, 0);
16466 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16467 it
->hpos
= hpos_before
;
16468 it
->current_x
= x_before
;
16473 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16474 at the left window margin. */
16475 if (it
->first_visible_x
16476 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16478 if (!FRAME_WINDOW_P (it
->f
))
16479 insert_left_trunc_glyphs (it
);
16480 row
->truncated_on_left_p
= 1;
16483 /* If the start of this line is the overlay arrow-position, then
16484 mark this glyph row as the one containing the overlay arrow.
16485 This is clearly a mess with variable size fonts. It would be
16486 better to let it be displayed like cursors under X. */
16487 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16488 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16489 !NILP (overlay_arrow_string
)))
16491 /* Overlay arrow in window redisplay is a fringe bitmap. */
16492 if (STRINGP (overlay_arrow_string
))
16494 struct glyph_row
*arrow_row
16495 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16496 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16497 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16498 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16499 struct glyph
*p2
, *end
;
16501 /* Copy the arrow glyphs. */
16502 while (glyph
< arrow_end
)
16505 /* Throw away padding glyphs. */
16507 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16508 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16514 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16519 xassert (INTEGERP (overlay_arrow_string
));
16520 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16522 overlay_arrow_seen
= 1;
16525 /* Compute pixel dimensions of this line. */
16526 compute_line_metrics (it
);
16528 /* Remember the position at which this line ends. */
16529 row
->end
= it
->current
;
16531 /* Record whether this row ends inside an ellipsis. */
16532 row
->ends_in_ellipsis_p
16533 = (it
->method
== GET_FROM_DISPLAY_VECTOR
16534 && it
->ellipsis_p
);
16536 /* Save fringe bitmaps in this row. */
16537 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
16538 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
16539 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
16540 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
16542 it
->left_user_fringe_bitmap
= 0;
16543 it
->left_user_fringe_face_id
= 0;
16544 it
->right_user_fringe_bitmap
= 0;
16545 it
->right_user_fringe_face_id
= 0;
16547 /* Maybe set the cursor. */
16548 if (it
->w
->cursor
.vpos
< 0
16549 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
16550 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
16551 && cursor_row_p (it
->w
, row
))
16552 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
16554 /* Highlight trailing whitespace. */
16555 if (!NILP (Vshow_trailing_whitespace
))
16556 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
16558 /* Prepare for the next line. This line starts horizontally at (X
16559 HPOS) = (0 0). Vertical positions are incremented. As a
16560 convenience for the caller, IT->glyph_row is set to the next
16562 it
->current_x
= it
->hpos
= 0;
16563 it
->current_y
+= row
->height
;
16566 it
->start
= it
->current
;
16567 return row
->displays_text_p
;
16572 /***********************************************************************
16574 ***********************************************************************/
16576 /* Redisplay the menu bar in the frame for window W.
16578 The menu bar of X frames that don't have X toolkit support is
16579 displayed in a special window W->frame->menu_bar_window.
16581 The menu bar of terminal frames is treated specially as far as
16582 glyph matrices are concerned. Menu bar lines are not part of
16583 windows, so the update is done directly on the frame matrix rows
16584 for the menu bar. */
16587 display_menu_bar (w
)
16590 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16595 /* Don't do all this for graphical frames. */
16597 if (!NILP (Vwindow_system
))
16600 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
16605 if (FRAME_MAC_P (f
))
16609 #ifdef USE_X_TOOLKIT
16610 xassert (!FRAME_WINDOW_P (f
));
16611 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
16612 it
.first_visible_x
= 0;
16613 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16614 #else /* not USE_X_TOOLKIT */
16615 if (FRAME_WINDOW_P (f
))
16617 /* Menu bar lines are displayed in the desired matrix of the
16618 dummy window menu_bar_window. */
16619 struct window
*menu_w
;
16620 xassert (WINDOWP (f
->menu_bar_window
));
16621 menu_w
= XWINDOW (f
->menu_bar_window
);
16622 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
16624 it
.first_visible_x
= 0;
16625 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
16629 /* This is a TTY frame, i.e. character hpos/vpos are used as
16631 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
16633 it
.first_visible_x
= 0;
16634 it
.last_visible_x
= FRAME_COLS (f
);
16636 #endif /* not USE_X_TOOLKIT */
16638 if (! mode_line_inverse_video
)
16639 /* Force the menu-bar to be displayed in the default face. */
16640 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16642 /* Clear all rows of the menu bar. */
16643 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
16645 struct glyph_row
*row
= it
.glyph_row
+ i
;
16646 clear_glyph_row (row
);
16647 row
->enabled_p
= 1;
16648 row
->full_width_p
= 1;
16651 /* Display all items of the menu bar. */
16652 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
16653 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
16655 Lisp_Object string
;
16657 /* Stop at nil string. */
16658 string
= AREF (items
, i
+ 1);
16662 /* Remember where item was displayed. */
16663 AREF (items
, i
+ 3) = make_number (it
.hpos
);
16665 /* Display the item, pad with one space. */
16666 if (it
.current_x
< it
.last_visible_x
)
16667 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
16668 SCHARS (string
) + 1, 0, 0, -1);
16671 /* Fill out the line with spaces. */
16672 if (it
.current_x
< it
.last_visible_x
)
16673 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
16675 /* Compute the total height of the lines. */
16676 compute_line_metrics (&it
);
16681 /***********************************************************************
16683 ***********************************************************************/
16685 /* Redisplay mode lines in the window tree whose root is WINDOW. If
16686 FORCE is non-zero, redisplay mode lines unconditionally.
16687 Otherwise, redisplay only mode lines that are garbaged. Value is
16688 the number of windows whose mode lines were redisplayed. */
16691 redisplay_mode_lines (window
, force
)
16692 Lisp_Object window
;
16697 while (!NILP (window
))
16699 struct window
*w
= XWINDOW (window
);
16701 if (WINDOWP (w
->hchild
))
16702 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
16703 else if (WINDOWP (w
->vchild
))
16704 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
16706 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
16707 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
16709 struct text_pos lpoint
;
16710 struct buffer
*old
= current_buffer
;
16712 /* Set the window's buffer for the mode line display. */
16713 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16714 set_buffer_internal_1 (XBUFFER (w
->buffer
));
16716 /* Point refers normally to the selected window. For any
16717 other window, set up appropriate value. */
16718 if (!EQ (window
, selected_window
))
16720 struct text_pos pt
;
16722 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
16723 if (CHARPOS (pt
) < BEGV
)
16724 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16725 else if (CHARPOS (pt
) > (ZV
- 1))
16726 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
16728 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
16731 /* Display mode lines. */
16732 clear_glyph_matrix (w
->desired_matrix
);
16733 if (display_mode_lines (w
))
16736 w
->must_be_updated_p
= 1;
16739 /* Restore old settings. */
16740 set_buffer_internal_1 (old
);
16741 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16751 /* Display the mode and/or top line of window W. Value is the number
16752 of mode lines displayed. */
16755 display_mode_lines (w
)
16758 Lisp_Object old_selected_window
, old_selected_frame
;
16761 old_selected_frame
= selected_frame
;
16762 selected_frame
= w
->frame
;
16763 old_selected_window
= selected_window
;
16764 XSETWINDOW (selected_window
, w
);
16766 /* These will be set while the mode line specs are processed. */
16767 line_number_displayed
= 0;
16768 w
->column_number_displayed
= Qnil
;
16770 if (WINDOW_WANTS_MODELINE_P (w
))
16772 struct window
*sel_w
= XWINDOW (old_selected_window
);
16774 /* Select mode line face based on the real selected window. */
16775 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
16776 current_buffer
->mode_line_format
);
16780 if (WINDOW_WANTS_HEADER_LINE_P (w
))
16782 display_mode_line (w
, HEADER_LINE_FACE_ID
,
16783 current_buffer
->header_line_format
);
16787 selected_frame
= old_selected_frame
;
16788 selected_window
= old_selected_window
;
16793 /* Display mode or top line of window W. FACE_ID specifies which line
16794 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
16795 FORMAT is the mode line format to display. Value is the pixel
16796 height of the mode line displayed. */
16799 display_mode_line (w
, face_id
, format
)
16801 enum face_id face_id
;
16802 Lisp_Object format
;
16806 int count
= SPECPDL_INDEX ();
16808 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16809 /* Don't extend on a previously drawn mode-line.
16810 This may happen if called from pos_visible_p. */
16811 it
.glyph_row
->enabled_p
= 0;
16812 prepare_desired_row (it
.glyph_row
);
16814 it
.glyph_row
->mode_line_p
= 1;
16816 if (! mode_line_inverse_video
)
16817 /* Force the mode-line to be displayed in the default face. */
16818 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
16820 record_unwind_protect (unwind_format_mode_line
,
16821 format_mode_line_unwind_data (NULL
, 0));
16823 mode_line_target
= MODE_LINE_DISPLAY
;
16825 /* Temporarily make frame's keyboard the current kboard so that
16826 kboard-local variables in the mode_line_format will get the right
16828 push_frame_kboard (it
.f
);
16829 record_unwind_save_match_data ();
16830 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16831 pop_frame_kboard ();
16833 unbind_to (count
, Qnil
);
16835 /* Fill up with spaces. */
16836 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
16838 compute_line_metrics (&it
);
16839 it
.glyph_row
->full_width_p
= 1;
16840 it
.glyph_row
->continued_p
= 0;
16841 it
.glyph_row
->truncated_on_left_p
= 0;
16842 it
.glyph_row
->truncated_on_right_p
= 0;
16844 /* Make a 3D mode-line have a shadow at its right end. */
16845 face
= FACE_FROM_ID (it
.f
, face_id
);
16846 extend_face_to_end_of_line (&it
);
16847 if (face
->box
!= FACE_NO_BOX
)
16849 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
16850 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
16851 last
->right_box_line_p
= 1;
16854 return it
.glyph_row
->height
;
16857 /* Move element ELT in LIST to the front of LIST.
16858 Return the updated list. */
16861 move_elt_to_front (elt
, list
)
16862 Lisp_Object elt
, list
;
16864 register Lisp_Object tail
, prev
;
16865 register Lisp_Object tem
;
16869 while (CONSP (tail
))
16875 /* Splice out the link TAIL. */
16877 list
= XCDR (tail
);
16879 Fsetcdr (prev
, XCDR (tail
));
16881 /* Now make it the first. */
16882 Fsetcdr (tail
, list
);
16887 tail
= XCDR (tail
);
16891 /* Not found--return unchanged LIST. */
16895 /* Contribute ELT to the mode line for window IT->w. How it
16896 translates into text depends on its data type.
16898 IT describes the display environment in which we display, as usual.
16900 DEPTH is the depth in recursion. It is used to prevent
16901 infinite recursion here.
16903 FIELD_WIDTH is the number of characters the display of ELT should
16904 occupy in the mode line, and PRECISION is the maximum number of
16905 characters to display from ELT's representation. See
16906 display_string for details.
16908 Returns the hpos of the end of the text generated by ELT.
16910 PROPS is a property list to add to any string we encounter.
16912 If RISKY is nonzero, remove (disregard) any properties in any string
16913 we encounter, and ignore :eval and :propertize.
16915 The global variable `mode_line_target' determines whether the
16916 output is passed to `store_mode_line_noprop',
16917 `store_mode_line_string', or `display_string'. */
16920 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
16923 int field_width
, precision
;
16924 Lisp_Object elt
, props
;
16927 int n
= 0, field
, prec
;
16932 elt
= build_string ("*too-deep*");
16936 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
16940 /* A string: output it and check for %-constructs within it. */
16944 if (SCHARS (elt
) > 0
16945 && (!NILP (props
) || risky
))
16947 Lisp_Object oprops
, aelt
;
16948 oprops
= Ftext_properties_at (make_number (0), elt
);
16950 /* If the starting string's properties are not what
16951 we want, translate the string. Also, if the string
16952 is risky, do that anyway. */
16954 if (NILP (Fequal (props
, oprops
)) || risky
)
16956 /* If the starting string has properties,
16957 merge the specified ones onto the existing ones. */
16958 if (! NILP (oprops
) && !risky
)
16962 oprops
= Fcopy_sequence (oprops
);
16964 while (CONSP (tem
))
16966 oprops
= Fplist_put (oprops
, XCAR (tem
),
16967 XCAR (XCDR (tem
)));
16968 tem
= XCDR (XCDR (tem
));
16973 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16974 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16976 /* AELT is what we want. Move it to the front
16977 without consing. */
16979 mode_line_proptrans_alist
16980 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
16986 /* If AELT has the wrong props, it is useless.
16987 so get rid of it. */
16989 mode_line_proptrans_alist
16990 = Fdelq (aelt
, mode_line_proptrans_alist
);
16992 elt
= Fcopy_sequence (elt
);
16993 Fset_text_properties (make_number (0), Flength (elt
),
16995 /* Add this item to mode_line_proptrans_alist. */
16996 mode_line_proptrans_alist
16997 = Fcons (Fcons (elt
, props
),
16998 mode_line_proptrans_alist
);
16999 /* Truncate mode_line_proptrans_alist
17000 to at most 50 elements. */
17001 tem
= Fnthcdr (make_number (50),
17002 mode_line_proptrans_alist
);
17004 XSETCDR (tem
, Qnil
);
17013 prec
= precision
- n
;
17014 switch (mode_line_target
)
17016 case MODE_LINE_NOPROP
:
17017 case MODE_LINE_TITLE
:
17018 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17020 case MODE_LINE_STRING
:
17021 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17023 case MODE_LINE_DISPLAY
:
17024 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17025 0, prec
, 0, STRING_MULTIBYTE (elt
));
17032 /* Handle the non-literal case. */
17034 while ((precision
<= 0 || n
< precision
)
17035 && SREF (elt
, offset
) != 0
17036 && (mode_line_target
!= MODE_LINE_DISPLAY
17037 || it
->current_x
< it
->last_visible_x
))
17039 int last_offset
= offset
;
17041 /* Advance to end of string or next format specifier. */
17042 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17045 if (offset
- 1 != last_offset
)
17047 int nchars
, nbytes
;
17049 /* Output to end of string or up to '%'. Field width
17050 is length of string. Don't output more than
17051 PRECISION allows us. */
17054 prec
= c_string_width (SDATA (elt
) + last_offset
,
17055 offset
- last_offset
, precision
- n
,
17058 switch (mode_line_target
)
17060 case MODE_LINE_NOPROP
:
17061 case MODE_LINE_TITLE
:
17062 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17064 case MODE_LINE_STRING
:
17066 int bytepos
= last_offset
;
17067 int charpos
= string_byte_to_char (elt
, bytepos
);
17068 int endpos
= (precision
<= 0
17069 ? string_byte_to_char (elt
, offset
)
17070 : charpos
+ nchars
);
17072 n
+= store_mode_line_string (NULL
,
17073 Fsubstring (elt
, make_number (charpos
),
17074 make_number (endpos
)),
17078 case MODE_LINE_DISPLAY
:
17080 int bytepos
= last_offset
;
17081 int charpos
= string_byte_to_char (elt
, bytepos
);
17083 if (precision
<= 0)
17084 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17085 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17087 STRING_MULTIBYTE (elt
));
17092 else /* c == '%' */
17094 int percent_position
= offset
;
17096 /* Get the specified minimum width. Zero means
17099 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17100 field
= field
* 10 + c
- '0';
17102 /* Don't pad beyond the total padding allowed. */
17103 if (field_width
- n
> 0 && field
> field_width
- n
)
17104 field
= field_width
- n
;
17106 /* Note that either PRECISION <= 0 or N < PRECISION. */
17107 prec
= precision
- n
;
17110 n
+= display_mode_element (it
, depth
, field
, prec
,
17111 Vglobal_mode_string
, props
,
17116 int bytepos
, charpos
;
17117 unsigned char *spec
;
17119 bytepos
= percent_position
;
17120 charpos
= (STRING_MULTIBYTE (elt
)
17121 ? string_byte_to_char (elt
, bytepos
)
17125 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17127 switch (mode_line_target
)
17129 case MODE_LINE_NOPROP
:
17130 case MODE_LINE_TITLE
:
17131 n
+= store_mode_line_noprop (spec
, field
, prec
);
17133 case MODE_LINE_STRING
:
17135 int len
= strlen (spec
);
17136 Lisp_Object tem
= make_string (spec
, len
);
17137 props
= Ftext_properties_at (make_number (charpos
), elt
);
17138 /* Should only keep face property in props */
17139 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17142 case MODE_LINE_DISPLAY
:
17144 int nglyphs_before
, nwritten
;
17146 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17147 nwritten
= display_string (spec
, Qnil
, elt
,
17152 /* Assign to the glyphs written above the
17153 string where the `%x' came from, position
17157 struct glyph
*glyph
17158 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17162 for (i
= 0; i
< nwritten
; ++i
)
17164 glyph
[i
].object
= elt
;
17165 glyph
[i
].charpos
= charpos
;
17182 /* A symbol: process the value of the symbol recursively
17183 as if it appeared here directly. Avoid error if symbol void.
17184 Special case: if value of symbol is a string, output the string
17187 register Lisp_Object tem
;
17189 /* If the variable is not marked as risky to set
17190 then its contents are risky to use. */
17191 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17194 tem
= Fboundp (elt
);
17197 tem
= Fsymbol_value (elt
);
17198 /* If value is a string, output that string literally:
17199 don't check for % within it. */
17203 if (!EQ (tem
, elt
))
17205 /* Give up right away for nil or t. */
17215 register Lisp_Object car
, tem
;
17217 /* A cons cell: five distinct cases.
17218 If first element is :eval or :propertize, do something special.
17219 If first element is a string or a cons, process all the elements
17220 and effectively concatenate them.
17221 If first element is a negative number, truncate displaying cdr to
17222 at most that many characters. If positive, pad (with spaces)
17223 to at least that many characters.
17224 If first element is a symbol, process the cadr or caddr recursively
17225 according to whether the symbol's value is non-nil or nil. */
17227 if (EQ (car
, QCeval
))
17229 /* An element of the form (:eval FORM) means evaluate FORM
17230 and use the result as mode line elements. */
17235 if (CONSP (XCDR (elt
)))
17238 spec
= safe_eval (XCAR (XCDR (elt
)));
17239 n
+= display_mode_element (it
, depth
, field_width
- n
,
17240 precision
- n
, spec
, props
,
17244 else if (EQ (car
, QCpropertize
))
17246 /* An element of the form (:propertize ELT PROPS...)
17247 means display ELT but applying properties PROPS. */
17252 if (CONSP (XCDR (elt
)))
17253 n
+= display_mode_element (it
, depth
, field_width
- n
,
17254 precision
- n
, XCAR (XCDR (elt
)),
17255 XCDR (XCDR (elt
)), risky
);
17257 else if (SYMBOLP (car
))
17259 tem
= Fboundp (car
);
17263 /* elt is now the cdr, and we know it is a cons cell.
17264 Use its car if CAR has a non-nil value. */
17267 tem
= Fsymbol_value (car
);
17274 /* Symbol's value is nil (or symbol is unbound)
17275 Get the cddr of the original list
17276 and if possible find the caddr and use that. */
17280 else if (!CONSP (elt
))
17285 else if (INTEGERP (car
))
17287 register int lim
= XINT (car
);
17291 /* Negative int means reduce maximum width. */
17292 if (precision
<= 0)
17295 precision
= min (precision
, -lim
);
17299 /* Padding specified. Don't let it be more than
17300 current maximum. */
17302 lim
= min (precision
, lim
);
17304 /* If that's more padding than already wanted, queue it.
17305 But don't reduce padding already specified even if
17306 that is beyond the current truncation point. */
17307 field_width
= max (lim
, field_width
);
17311 else if (STRINGP (car
) || CONSP (car
))
17313 register int limit
= 50;
17314 /* Limit is to protect against circular lists. */
17317 && (precision
<= 0 || n
< precision
))
17319 n
+= display_mode_element (it
, depth
,
17320 /* Do padding only after the last
17321 element in the list. */
17322 (! CONSP (XCDR (elt
))
17325 precision
- n
, XCAR (elt
),
17335 elt
= build_string ("*invalid*");
17339 /* Pad to FIELD_WIDTH. */
17340 if (field_width
> 0 && n
< field_width
)
17342 switch (mode_line_target
)
17344 case MODE_LINE_NOPROP
:
17345 case MODE_LINE_TITLE
:
17346 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17348 case MODE_LINE_STRING
:
17349 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17351 case MODE_LINE_DISPLAY
:
17352 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17361 /* Store a mode-line string element in mode_line_string_list.
17363 If STRING is non-null, display that C string. Otherwise, the Lisp
17364 string LISP_STRING is displayed.
17366 FIELD_WIDTH is the minimum number of output glyphs to produce.
17367 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17368 with spaces. FIELD_WIDTH <= 0 means don't pad.
17370 PRECISION is the maximum number of characters to output from
17371 STRING. PRECISION <= 0 means don't truncate the string.
17373 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17374 properties to the string.
17376 PROPS are the properties to add to the string.
17377 The mode_line_string_face face property is always added to the string.
17381 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17383 Lisp_Object lisp_string
;
17392 if (string
!= NULL
)
17394 len
= strlen (string
);
17395 if (precision
> 0 && len
> precision
)
17397 lisp_string
= make_string (string
, len
);
17399 props
= mode_line_string_face_prop
;
17400 else if (!NILP (mode_line_string_face
))
17402 Lisp_Object face
= Fplist_get (props
, Qface
);
17403 props
= Fcopy_sequence (props
);
17405 face
= mode_line_string_face
;
17407 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17408 props
= Fplist_put (props
, Qface
, face
);
17410 Fadd_text_properties (make_number (0), make_number (len
),
17411 props
, lisp_string
);
17415 len
= XFASTINT (Flength (lisp_string
));
17416 if (precision
> 0 && len
> precision
)
17419 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17422 if (!NILP (mode_line_string_face
))
17426 props
= Ftext_properties_at (make_number (0), lisp_string
);
17427 face
= Fplist_get (props
, Qface
);
17429 face
= mode_line_string_face
;
17431 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17432 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17434 lisp_string
= Fcopy_sequence (lisp_string
);
17437 Fadd_text_properties (make_number (0), make_number (len
),
17438 props
, lisp_string
);
17443 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17447 if (field_width
> len
)
17449 field_width
-= len
;
17450 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17452 Fadd_text_properties (make_number (0), make_number (field_width
),
17453 props
, lisp_string
);
17454 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17462 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17464 doc
: /* Format a string out of a mode line format specification.
17465 First arg FORMAT specifies the mode line format (see `mode-line-format'
17466 for details) to use.
17468 Optional second arg FACE specifies the face property to put
17469 on all characters for which no face is specified.
17470 The value t means whatever face the window's mode line currently uses
17471 \(either `mode-line' or `mode-line-inactive', depending).
17472 A value of nil means the default is no face property.
17473 If FACE is an integer, the value string has no text properties.
17475 Optional third and fourth args WINDOW and BUFFER specify the window
17476 and buffer to use as the context for the formatting (defaults
17477 are the selected window and the window's buffer). */)
17478 (format
, face
, window
, buffer
)
17479 Lisp_Object format
, face
, window
, buffer
;
17484 struct buffer
*old_buffer
= NULL
;
17486 int no_props
= INTEGERP (face
);
17487 int count
= SPECPDL_INDEX ();
17489 int string_start
= 0;
17492 window
= selected_window
;
17493 CHECK_WINDOW (window
);
17494 w
= XWINDOW (window
);
17497 buffer
= w
->buffer
;
17498 CHECK_BUFFER (buffer
);
17501 return empty_unibyte_string
;
17509 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17510 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17514 face_id
= DEFAULT_FACE_ID
;
17516 if (XBUFFER (buffer
) != current_buffer
)
17517 old_buffer
= current_buffer
;
17519 /* Save things including mode_line_proptrans_alist,
17520 and set that to nil so that we don't alter the outer value. */
17521 record_unwind_protect (unwind_format_mode_line
,
17522 format_mode_line_unwind_data (old_buffer
, 1));
17523 mode_line_proptrans_alist
= Qnil
;
17526 set_buffer_internal_1 (XBUFFER (buffer
));
17528 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17532 mode_line_target
= MODE_LINE_NOPROP
;
17533 mode_line_string_face_prop
= Qnil
;
17534 mode_line_string_list
= Qnil
;
17535 string_start
= MODE_LINE_NOPROP_LEN (0);
17539 mode_line_target
= MODE_LINE_STRING
;
17540 mode_line_string_list
= Qnil
;
17541 mode_line_string_face
= face
;
17542 mode_line_string_face_prop
17543 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
17546 push_frame_kboard (it
.f
);
17547 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17548 pop_frame_kboard ();
17552 len
= MODE_LINE_NOPROP_LEN (string_start
);
17553 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
17557 mode_line_string_list
= Fnreverse (mode_line_string_list
);
17558 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
17559 empty_unibyte_string
);
17562 unbind_to (count
, Qnil
);
17566 /* Write a null-terminated, right justified decimal representation of
17567 the positive integer D to BUF using a minimal field width WIDTH. */
17570 pint2str (buf
, width
, d
)
17571 register char *buf
;
17572 register int width
;
17575 register char *p
= buf
;
17583 *p
++ = d
% 10 + '0';
17588 for (width
-= (int) (p
- buf
); width
> 0; --width
)
17599 /* Write a null-terminated, right justified decimal and "human
17600 readable" representation of the nonnegative integer D to BUF using
17601 a minimal field width WIDTH. D should be smaller than 999.5e24. */
17603 static const char power_letter
[] =
17617 pint2hrstr (buf
, width
, d
)
17622 /* We aim to represent the nonnegative integer D as
17623 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
17626 /* -1 means: do not use TENTHS. */
17630 /* Length of QUOTIENT.TENTHS as a string. */
17636 if (1000 <= quotient
)
17638 /* Scale to the appropriate EXPONENT. */
17641 remainder
= quotient
% 1000;
17645 while (1000 <= quotient
);
17647 /* Round to nearest and decide whether to use TENTHS or not. */
17650 tenths
= remainder
/ 100;
17651 if (50 <= remainder
% 100)
17658 if (quotient
== 10)
17666 if (500 <= remainder
)
17668 if (quotient
< 999)
17679 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
17680 if (tenths
== -1 && quotient
<= 99)
17687 p
= psuffix
= buf
+ max (width
, length
);
17689 /* Print EXPONENT. */
17691 *psuffix
++ = power_letter
[exponent
];
17694 /* Print TENTHS. */
17697 *--p
= '0' + tenths
;
17701 /* Print QUOTIENT. */
17704 int digit
= quotient
% 10;
17705 *--p
= '0' + digit
;
17707 while ((quotient
/= 10) != 0);
17709 /* Print leading spaces. */
17714 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
17715 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
17716 type of CODING_SYSTEM. Return updated pointer into BUF. */
17718 static unsigned char invalid_eol_type
[] = "(*invalid*)";
17721 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
17722 Lisp_Object coding_system
;
17723 register char *buf
;
17727 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
17728 const unsigned char *eol_str
;
17730 /* The EOL conversion we are using. */
17731 Lisp_Object eoltype
;
17733 val
= CODING_SYSTEM_SPEC (coding_system
);
17736 if (!VECTORP (val
)) /* Not yet decided. */
17741 eoltype
= eol_mnemonic_undecided
;
17742 /* Don't mention EOL conversion if it isn't decided. */
17747 Lisp_Object eolvalue
;
17749 attrs
= AREF (val
, 0);
17750 eolvalue
= AREF (val
, 2);
17753 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
17757 /* The EOL conversion that is normal on this system. */
17759 if (NILP (eolvalue
)) /* Not yet decided. */
17760 eoltype
= eol_mnemonic_undecided
;
17761 else if (VECTORP (eolvalue
)) /* Not yet decided. */
17762 eoltype
= eol_mnemonic_undecided
;
17763 else /* eolvalue is Qunix, Qdos, or Qmac. */
17764 eoltype
= (EQ (eolvalue
, Qunix
)
17765 ? eol_mnemonic_unix
17766 : (EQ (eolvalue
, Qdos
) == 1
17767 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
17773 /* Mention the EOL conversion if it is not the usual one. */
17774 if (STRINGP (eoltype
))
17776 eol_str
= SDATA (eoltype
);
17777 eol_str_len
= SBYTES (eoltype
);
17779 else if (CHARACTERP (eoltype
))
17781 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
17782 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
17787 eol_str
= invalid_eol_type
;
17788 eol_str_len
= sizeof (invalid_eol_type
) - 1;
17790 bcopy (eol_str
, buf
, eol_str_len
);
17791 buf
+= eol_str_len
;
17797 /* Return a string for the output of a mode line %-spec for window W,
17798 generated by character C. PRECISION >= 0 means don't return a
17799 string longer than that value. FIELD_WIDTH > 0 means pad the
17800 string returned with spaces to that value. Return 1 in *MULTIBYTE
17801 if the result is multibyte text.
17803 Note we operate on the current buffer for most purposes,
17804 the exception being w->base_line_pos. */
17806 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
17809 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
17812 int field_width
, precision
;
17816 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17817 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
17818 struct buffer
*b
= current_buffer
;
17826 if (!NILP (b
->read_only
))
17828 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17833 /* This differs from %* only for a modified read-only buffer. */
17834 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17836 if (!NILP (b
->read_only
))
17841 /* This differs from %* in ignoring read-only-ness. */
17842 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
17854 if (command_loop_level
> 5)
17856 p
= decode_mode_spec_buf
;
17857 for (i
= 0; i
< command_loop_level
; i
++)
17860 return decode_mode_spec_buf
;
17868 if (command_loop_level
> 5)
17870 p
= decode_mode_spec_buf
;
17871 for (i
= 0; i
< command_loop_level
; i
++)
17874 return decode_mode_spec_buf
;
17881 /* Let lots_of_dashes be a string of infinite length. */
17882 if (mode_line_target
== MODE_LINE_NOPROP
||
17883 mode_line_target
== MODE_LINE_STRING
)
17885 if (field_width
<= 0
17886 || field_width
> sizeof (lots_of_dashes
))
17888 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
17889 decode_mode_spec_buf
[i
] = '-';
17890 decode_mode_spec_buf
[i
] = '\0';
17891 return decode_mode_spec_buf
;
17894 return lots_of_dashes
;
17902 /* %c and %l are ignored in `frame-title-format'.
17903 (In redisplay_internal, the frame title is drawn _before_ the
17904 windows are updated, so the stuff which depends on actual
17905 window contents (such as %l) may fail to render properly, or
17906 even crash emacs.) */
17907 if (mode_line_target
== MODE_LINE_TITLE
)
17911 int col
= (int) current_column (); /* iftc */
17912 w
->column_number_displayed
= make_number (col
);
17913 pint2str (decode_mode_spec_buf
, field_width
, col
);
17914 return decode_mode_spec_buf
;
17918 #ifndef SYSTEM_MALLOC
17920 if (NILP (Vmemory_full
))
17923 return "!MEM FULL! ";
17930 /* %F displays the frame name. */
17931 if (!NILP (f
->title
))
17932 return (char *) SDATA (f
->title
);
17933 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
17934 return (char *) SDATA (f
->name
);
17943 int size
= ZV
- BEGV
;
17944 pint2str (decode_mode_spec_buf
, field_width
, size
);
17945 return decode_mode_spec_buf
;
17950 int size
= ZV
- BEGV
;
17951 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
17952 return decode_mode_spec_buf
;
17957 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
17958 int topline
, nlines
, junk
, height
;
17960 /* %c and %l are ignored in `frame-title-format'. */
17961 if (mode_line_target
== MODE_LINE_TITLE
)
17964 startpos
= XMARKER (w
->start
)->charpos
;
17965 startpos_byte
= marker_byte_position (w
->start
);
17966 height
= WINDOW_TOTAL_LINES (w
);
17968 /* If we decided that this buffer isn't suitable for line numbers,
17969 don't forget that too fast. */
17970 if (EQ (w
->base_line_pos
, w
->buffer
))
17972 /* But do forget it, if the window shows a different buffer now. */
17973 else if (BUFFERP (w
->base_line_pos
))
17974 w
->base_line_pos
= Qnil
;
17976 /* If the buffer is very big, don't waste time. */
17977 if (INTEGERP (Vline_number_display_limit
)
17978 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
17980 w
->base_line_pos
= Qnil
;
17981 w
->base_line_number
= Qnil
;
17985 if (!NILP (w
->base_line_number
)
17986 && !NILP (w
->base_line_pos
)
17987 && XFASTINT (w
->base_line_pos
) <= startpos
)
17989 line
= XFASTINT (w
->base_line_number
);
17990 linepos
= XFASTINT (w
->base_line_pos
);
17991 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
17996 linepos
= BUF_BEGV (b
);
17997 linepos_byte
= BUF_BEGV_BYTE (b
);
18000 /* Count lines from base line to window start position. */
18001 nlines
= display_count_lines (linepos
, linepos_byte
,
18005 topline
= nlines
+ line
;
18007 /* Determine a new base line, if the old one is too close
18008 or too far away, or if we did not have one.
18009 "Too close" means it's plausible a scroll-down would
18010 go back past it. */
18011 if (startpos
== BUF_BEGV (b
))
18013 w
->base_line_number
= make_number (topline
);
18014 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18016 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18017 || linepos
== BUF_BEGV (b
))
18019 int limit
= BUF_BEGV (b
);
18020 int limit_byte
= BUF_BEGV_BYTE (b
);
18022 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18024 if (startpos
- distance
> limit
)
18026 limit
= startpos
- distance
;
18027 limit_byte
= CHAR_TO_BYTE (limit
);
18030 nlines
= display_count_lines (startpos
, startpos_byte
,
18032 - (height
* 2 + 30),
18034 /* If we couldn't find the lines we wanted within
18035 line_number_display_limit_width chars per line,
18036 give up on line numbers for this window. */
18037 if (position
== limit_byte
&& limit
== startpos
- distance
)
18039 w
->base_line_pos
= w
->buffer
;
18040 w
->base_line_number
= Qnil
;
18044 w
->base_line_number
= make_number (topline
- nlines
);
18045 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18048 /* Now count lines from the start pos to point. */
18049 nlines
= display_count_lines (startpos
, startpos_byte
,
18050 PT_BYTE
, PT
, &junk
);
18052 /* Record that we did display the line number. */
18053 line_number_displayed
= 1;
18055 /* Make the string to show. */
18056 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18057 return decode_mode_spec_buf
;
18060 char* p
= decode_mode_spec_buf
;
18061 int pad
= field_width
- 2;
18067 return decode_mode_spec_buf
;
18073 obj
= b
->mode_name
;
18077 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18083 int pos
= marker_position (w
->start
);
18084 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18086 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18088 if (pos
<= BUF_BEGV (b
))
18093 else if (pos
<= BUF_BEGV (b
))
18097 if (total
> 1000000)
18098 /* Do it differently for a large value, to avoid overflow. */
18099 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18101 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18102 /* We can't normally display a 3-digit number,
18103 so get us a 2-digit number that is close. */
18106 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18107 return decode_mode_spec_buf
;
18111 /* Display percentage of size above the bottom of the screen. */
18114 int toppos
= marker_position (w
->start
);
18115 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18116 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18118 if (botpos
>= BUF_ZV (b
))
18120 if (toppos
<= BUF_BEGV (b
))
18127 if (total
> 1000000)
18128 /* Do it differently for a large value, to avoid overflow. */
18129 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18131 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18132 /* We can't normally display a 3-digit number,
18133 so get us a 2-digit number that is close. */
18136 if (toppos
<= BUF_BEGV (b
))
18137 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18139 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18140 return decode_mode_spec_buf
;
18145 /* status of process */
18146 obj
= Fget_buffer_process (Fcurrent_buffer ());
18148 return "no process";
18149 #ifdef subprocesses
18150 obj
= Fsymbol_name (Fprocess_status (obj
));
18157 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18164 case 't': /* indicate TEXT or BINARY */
18165 #ifdef MODE_LINE_BINARY_TEXT
18166 return MODE_LINE_BINARY_TEXT (b
);
18172 /* coding-system (not including end-of-line format) */
18174 /* coding-system (including end-of-line type) */
18176 int eol_flag
= (c
== 'Z');
18177 char *p
= decode_mode_spec_buf
;
18179 if (! FRAME_WINDOW_P (f
))
18181 /* No need to mention EOL here--the terminal never needs
18182 to do EOL conversion. */
18183 p
= decode_mode_spec_coding (CODING_ID_NAME (keyboard_coding
.id
),
18185 p
= decode_mode_spec_coding (CODING_ID_NAME (terminal_coding
.id
),
18188 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18191 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18192 #ifdef subprocesses
18193 obj
= Fget_buffer_process (Fcurrent_buffer ());
18194 if (PROCESSP (obj
))
18196 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18198 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18201 #endif /* subprocesses */
18204 return decode_mode_spec_buf
;
18210 *multibyte
= STRING_MULTIBYTE (obj
);
18211 return (char *) SDATA (obj
);
18218 /* Count up to COUNT lines starting from START / START_BYTE.
18219 But don't go beyond LIMIT_BYTE.
18220 Return the number of lines thus found (always nonnegative).
18222 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18225 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18226 int start
, start_byte
, limit_byte
, count
;
18229 register unsigned char *cursor
;
18230 unsigned char *base
;
18232 register int ceiling
;
18233 register unsigned char *ceiling_addr
;
18234 int orig_count
= count
;
18236 /* If we are not in selective display mode,
18237 check only for newlines. */
18238 int selective_display
= (!NILP (current_buffer
->selective_display
)
18239 && !INTEGERP (current_buffer
->selective_display
));
18243 while (start_byte
< limit_byte
)
18245 ceiling
= BUFFER_CEILING_OF (start_byte
);
18246 ceiling
= min (limit_byte
- 1, ceiling
);
18247 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18248 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18251 if (selective_display
)
18252 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18255 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18258 if (cursor
!= ceiling_addr
)
18262 start_byte
+= cursor
- base
+ 1;
18263 *byte_pos_ptr
= start_byte
;
18267 if (++cursor
== ceiling_addr
)
18273 start_byte
+= cursor
- base
;
18278 while (start_byte
> limit_byte
)
18280 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18281 ceiling
= max (limit_byte
, ceiling
);
18282 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18283 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18286 if (selective_display
)
18287 while (--cursor
!= ceiling_addr
18288 && *cursor
!= '\n' && *cursor
!= 015)
18291 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18294 if (cursor
!= ceiling_addr
)
18298 start_byte
+= cursor
- base
+ 1;
18299 *byte_pos_ptr
= start_byte
;
18300 /* When scanning backwards, we should
18301 not count the newline posterior to which we stop. */
18302 return - orig_count
- 1;
18308 /* Here we add 1 to compensate for the last decrement
18309 of CURSOR, which took it past the valid range. */
18310 start_byte
+= cursor
- base
+ 1;
18314 *byte_pos_ptr
= limit_byte
;
18317 return - orig_count
+ count
;
18318 return orig_count
- count
;
18324 /***********************************************************************
18326 ***********************************************************************/
18328 /* Display a NUL-terminated string, starting with index START.
18330 If STRING is non-null, display that C string. Otherwise, the Lisp
18331 string LISP_STRING is displayed.
18333 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18334 FACE_STRING. Display STRING or LISP_STRING with the face at
18335 FACE_STRING_POS in FACE_STRING:
18337 Display the string in the environment given by IT, but use the
18338 standard display table, temporarily.
18340 FIELD_WIDTH is the minimum number of output glyphs to produce.
18341 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18342 with spaces. If STRING has more characters, more than FIELD_WIDTH
18343 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18345 PRECISION is the maximum number of characters to output from
18346 STRING. PRECISION < 0 means don't truncate the string.
18348 This is roughly equivalent to printf format specifiers:
18350 FIELD_WIDTH PRECISION PRINTF
18351 ----------------------------------------
18357 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18358 display them, and < 0 means obey the current buffer's value of
18359 enable_multibyte_characters.
18361 Value is the number of columns displayed. */
18364 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18365 start
, it
, field_width
, precision
, max_x
, multibyte
)
18366 unsigned char *string
;
18367 Lisp_Object lisp_string
;
18368 Lisp_Object face_string
;
18369 int face_string_pos
;
18372 int field_width
, precision
, max_x
;
18375 int hpos_at_start
= it
->hpos
;
18376 int saved_face_id
= it
->face_id
;
18377 struct glyph_row
*row
= it
->glyph_row
;
18379 /* Initialize the iterator IT for iteration over STRING beginning
18380 with index START. */
18381 reseat_to_string (it
, string
, lisp_string
, start
,
18382 precision
, field_width
, multibyte
);
18384 /* If displaying STRING, set up the face of the iterator
18385 from LISP_STRING, if that's given. */
18386 if (STRINGP (face_string
))
18392 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18393 0, it
->region_beg_charpos
,
18394 it
->region_end_charpos
,
18395 &endptr
, it
->base_face_id
, 0);
18396 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18397 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18400 /* Set max_x to the maximum allowed X position. Don't let it go
18401 beyond the right edge of the window. */
18403 max_x
= it
->last_visible_x
;
18405 max_x
= min (max_x
, it
->last_visible_x
);
18407 /* Skip over display elements that are not visible. because IT->w is
18409 if (it
->current_x
< it
->first_visible_x
)
18410 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18411 MOVE_TO_POS
| MOVE_TO_X
);
18413 row
->ascent
= it
->max_ascent
;
18414 row
->height
= it
->max_ascent
+ it
->max_descent
;
18415 row
->phys_ascent
= it
->max_phys_ascent
;
18416 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18417 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18419 /* This condition is for the case that we are called with current_x
18420 past last_visible_x. */
18421 while (it
->current_x
< max_x
)
18423 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18425 /* Get the next display element. */
18426 if (!get_next_display_element (it
))
18429 /* Produce glyphs. */
18430 x_before
= it
->current_x
;
18431 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18432 PRODUCE_GLYPHS (it
);
18434 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18437 while (i
< nglyphs
)
18439 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18441 if (!it
->truncate_lines_p
18442 && x
+ glyph
->pixel_width
> max_x
)
18444 /* End of continued line or max_x reached. */
18445 if (CHAR_GLYPH_PADDING_P (*glyph
))
18447 /* A wide character is unbreakable. */
18448 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18449 it
->current_x
= x_before
;
18453 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18458 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18460 /* Glyph is at least partially visible. */
18462 if (x
< it
->first_visible_x
)
18463 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18467 /* Glyph is off the left margin of the display area.
18468 Should not happen. */
18472 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18473 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18474 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18475 row
->phys_height
= max (row
->phys_height
,
18476 it
->max_phys_ascent
+ it
->max_phys_descent
);
18477 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18478 it
->max_extra_line_spacing
);
18479 x
+= glyph
->pixel_width
;
18483 /* Stop if max_x reached. */
18487 /* Stop at line ends. */
18488 if (ITERATOR_AT_END_OF_LINE_P (it
))
18490 it
->continuation_lines_width
= 0;
18494 set_iterator_to_next (it
, 1);
18496 /* Stop if truncating at the right edge. */
18497 if (it
->truncate_lines_p
18498 && it
->current_x
>= it
->last_visible_x
)
18500 /* Add truncation mark, but don't do it if the line is
18501 truncated at a padding space. */
18502 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18504 if (!FRAME_WINDOW_P (it
->f
))
18508 if (it
->current_x
> it
->last_visible_x
)
18510 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18511 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18513 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18515 row
->used
[TEXT_AREA
] = i
;
18516 produce_special_glyphs (it
, IT_TRUNCATION
);
18519 produce_special_glyphs (it
, IT_TRUNCATION
);
18521 it
->glyph_row
->truncated_on_right_p
= 1;
18527 /* Maybe insert a truncation at the left. */
18528 if (it
->first_visible_x
18529 && IT_CHARPOS (*it
) > 0)
18531 if (!FRAME_WINDOW_P (it
->f
))
18532 insert_left_trunc_glyphs (it
);
18533 it
->glyph_row
->truncated_on_left_p
= 1;
18536 it
->face_id
= saved_face_id
;
18538 /* Value is number of columns displayed. */
18539 return it
->hpos
- hpos_at_start
;
18544 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
18545 appears as an element of LIST or as the car of an element of LIST.
18546 If PROPVAL is a list, compare each element against LIST in that
18547 way, and return 1/2 if any element of PROPVAL is found in LIST.
18548 Otherwise return 0. This function cannot quit.
18549 The return value is 2 if the text is invisible but with an ellipsis
18550 and 1 if it's invisible and without an ellipsis. */
18553 invisible_p (propval
, list
)
18554 register Lisp_Object propval
;
18557 register Lisp_Object tail
, proptail
;
18559 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18561 register Lisp_Object tem
;
18563 if (EQ (propval
, tem
))
18565 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
18566 return NILP (XCDR (tem
)) ? 1 : 2;
18569 if (CONSP (propval
))
18571 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
18573 Lisp_Object propelt
;
18574 propelt
= XCAR (proptail
);
18575 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
18577 register Lisp_Object tem
;
18579 if (EQ (propelt
, tem
))
18581 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
18582 return NILP (XCDR (tem
)) ? 1 : 2;
18590 /* Calculate a width or height in pixels from a specification using
18591 the following elements:
18594 NUM - a (fractional) multiple of the default font width/height
18595 (NUM) - specifies exactly NUM pixels
18596 UNIT - a fixed number of pixels, see below.
18597 ELEMENT - size of a display element in pixels, see below.
18598 (NUM . SPEC) - equals NUM * SPEC
18599 (+ SPEC SPEC ...) - add pixel values
18600 (- SPEC SPEC ...) - subtract pixel values
18601 (- SPEC) - negate pixel value
18604 INT or FLOAT - a number constant
18605 SYMBOL - use symbol's (buffer local) variable binding.
18608 in - pixels per inch *)
18609 mm - pixels per 1/1000 meter *)
18610 cm - pixels per 1/100 meter *)
18611 width - width of current font in pixels.
18612 height - height of current font in pixels.
18614 *) using the ratio(s) defined in display-pixels-per-inch.
18618 left-fringe - left fringe width in pixels
18619 right-fringe - right fringe width in pixels
18621 left-margin - left margin width in pixels
18622 right-margin - right margin width in pixels
18624 scroll-bar - scroll-bar area width in pixels
18628 Pixels corresponding to 5 inches:
18631 Total width of non-text areas on left side of window (if scroll-bar is on left):
18632 '(space :width (+ left-fringe left-margin scroll-bar))
18634 Align to first text column (in header line):
18635 '(space :align-to 0)
18637 Align to middle of text area minus half the width of variable `my-image'
18638 containing a loaded image:
18639 '(space :align-to (0.5 . (- text my-image)))
18641 Width of left margin minus width of 1 character in the default font:
18642 '(space :width (- left-margin 1))
18644 Width of left margin minus width of 2 characters in the current font:
18645 '(space :width (- left-margin (2 . width)))
18647 Center 1 character over left-margin (in header line):
18648 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
18650 Different ways to express width of left fringe plus left margin minus one pixel:
18651 '(space :width (- (+ left-fringe left-margin) (1)))
18652 '(space :width (+ left-fringe left-margin (- (1))))
18653 '(space :width (+ left-fringe left-margin (-1)))
18657 #define NUMVAL(X) \
18658 ((INTEGERP (X) || FLOATP (X)) \
18663 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
18668 int width_p
, *align_to
;
18672 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
18673 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
18676 return OK_PIXELS (0);
18678 if (SYMBOLP (prop
))
18680 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
18682 char *unit
= SDATA (SYMBOL_NAME (prop
));
18684 if (unit
[0] == 'i' && unit
[1] == 'n')
18686 else if (unit
[0] == 'm' && unit
[1] == 'm')
18688 else if (unit
[0] == 'c' && unit
[1] == 'm')
18695 #ifdef HAVE_WINDOW_SYSTEM
18696 if (FRAME_WINDOW_P (it
->f
)
18698 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
18699 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
18701 return OK_PIXELS (ppi
/ pixels
);
18704 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
18705 || (CONSP (Vdisplay_pixels_per_inch
)
18707 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
18708 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
18710 return OK_PIXELS (ppi
/ pixels
);
18716 #ifdef HAVE_WINDOW_SYSTEM
18717 if (EQ (prop
, Qheight
))
18718 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
18719 if (EQ (prop
, Qwidth
))
18720 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
18722 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
18723 return OK_PIXELS (1);
18726 if (EQ (prop
, Qtext
))
18727 return OK_PIXELS (width_p
18728 ? window_box_width (it
->w
, TEXT_AREA
)
18729 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
18731 if (align_to
&& *align_to
< 0)
18734 if (EQ (prop
, Qleft
))
18735 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
18736 if (EQ (prop
, Qright
))
18737 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
18738 if (EQ (prop
, Qcenter
))
18739 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
18740 + window_box_width (it
->w
, TEXT_AREA
) / 2);
18741 if (EQ (prop
, Qleft_fringe
))
18742 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18743 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
18744 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
18745 if (EQ (prop
, Qright_fringe
))
18746 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18747 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18748 : window_box_right_offset (it
->w
, TEXT_AREA
));
18749 if (EQ (prop
, Qleft_margin
))
18750 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
18751 if (EQ (prop
, Qright_margin
))
18752 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
18753 if (EQ (prop
, Qscroll_bar
))
18754 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
18756 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
18757 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
18758 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
18763 if (EQ (prop
, Qleft_fringe
))
18764 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
18765 if (EQ (prop
, Qright_fringe
))
18766 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
18767 if (EQ (prop
, Qleft_margin
))
18768 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
18769 if (EQ (prop
, Qright_margin
))
18770 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
18771 if (EQ (prop
, Qscroll_bar
))
18772 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
18775 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
18778 if (INTEGERP (prop
) || FLOATP (prop
))
18780 int base_unit
= (width_p
18781 ? FRAME_COLUMN_WIDTH (it
->f
)
18782 : FRAME_LINE_HEIGHT (it
->f
));
18783 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
18788 Lisp_Object car
= XCAR (prop
);
18789 Lisp_Object cdr
= XCDR (prop
);
18793 #ifdef HAVE_WINDOW_SYSTEM
18794 if (valid_image_p (prop
))
18796 int id
= lookup_image (it
->f
, prop
);
18797 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
18799 return OK_PIXELS (width_p
? img
->width
: img
->height
);
18802 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
18808 while (CONSP (cdr
))
18810 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
18811 font
, width_p
, align_to
))
18814 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
18819 if (EQ (car
, Qminus
))
18821 return OK_PIXELS (pixels
);
18824 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
18827 if (INTEGERP (car
) || FLOATP (car
))
18830 pixels
= XFLOATINT (car
);
18832 return OK_PIXELS (pixels
);
18833 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
18834 font
, width_p
, align_to
))
18835 return OK_PIXELS (pixels
* fact
);
18846 /***********************************************************************
18848 ***********************************************************************/
18850 #ifdef HAVE_WINDOW_SYSTEM
18855 dump_glyph_string (s
)
18856 struct glyph_string
*s
;
18858 fprintf (stderr
, "glyph string\n");
18859 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
18860 s
->x
, s
->y
, s
->width
, s
->height
);
18861 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
18862 fprintf (stderr
, " hl = %d\n", s
->hl
);
18863 fprintf (stderr
, " left overhang = %d, right = %d\n",
18864 s
->left_overhang
, s
->right_overhang
);
18865 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
18866 fprintf (stderr
, " extends to end of line = %d\n",
18867 s
->extends_to_end_of_line_p
);
18868 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
18869 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
18872 #endif /* GLYPH_DEBUG */
18874 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
18875 of XChar2b structures for S; it can't be allocated in
18876 init_glyph_string because it must be allocated via `alloca'. W
18877 is the window on which S is drawn. ROW and AREA are the glyph row
18878 and area within the row from which S is constructed. START is the
18879 index of the first glyph structure covered by S. HL is a
18880 face-override for drawing S. */
18883 #define OPTIONAL_HDC(hdc) hdc,
18884 #define DECLARE_HDC(hdc) HDC hdc;
18885 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
18886 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
18889 #ifndef OPTIONAL_HDC
18890 #define OPTIONAL_HDC(hdc)
18891 #define DECLARE_HDC(hdc)
18892 #define ALLOCATE_HDC(hdc, f)
18893 #define RELEASE_HDC(hdc, f)
18897 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
18898 struct glyph_string
*s
;
18902 struct glyph_row
*row
;
18903 enum glyph_row_area area
;
18905 enum draw_glyphs_face hl
;
18907 bzero (s
, sizeof *s
);
18909 s
->f
= XFRAME (w
->frame
);
18913 s
->display
= FRAME_X_DISPLAY (s
->f
);
18914 s
->window
= FRAME_X_WINDOW (s
->f
);
18915 s
->char2b
= char2b
;
18919 s
->first_glyph
= row
->glyphs
[area
] + start
;
18920 s
->height
= row
->height
;
18921 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
18923 /* Display the internal border below the tool-bar window. */
18924 if (WINDOWP (s
->f
->tool_bar_window
)
18925 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
18926 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
18928 s
->ybase
= s
->y
+ row
->ascent
;
18932 /* Append the list of glyph strings with head H and tail T to the list
18933 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
18936 append_glyph_string_lists (head
, tail
, h
, t
)
18937 struct glyph_string
**head
, **tail
;
18938 struct glyph_string
*h
, *t
;
18952 /* Prepend the list of glyph strings with head H and tail T to the
18953 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
18957 prepend_glyph_string_lists (head
, tail
, h
, t
)
18958 struct glyph_string
**head
, **tail
;
18959 struct glyph_string
*h
, *t
;
18973 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
18974 Set *HEAD and *TAIL to the resulting list. */
18977 append_glyph_string (head
, tail
, s
)
18978 struct glyph_string
**head
, **tail
;
18979 struct glyph_string
*s
;
18981 s
->next
= s
->prev
= NULL
;
18982 append_glyph_string_lists (head
, tail
, s
, s
);
18986 /* Get face and two-byte form of character C in face FACE_ID on frame
18987 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18988 means we want to display multibyte text. DISPLAY_P non-zero means
18989 make sure that X resources for the face returned are allocated.
18990 Value is a pointer to a realized face that is ready for display if
18991 DISPLAY_P is non-zero. */
18993 static INLINE
struct face
*
18994 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18998 int multibyte_p
, display_p
;
19000 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19002 #ifdef USE_FONT_BACKEND
19003 if (enable_font_backend
)
19005 struct font
*font
= (struct font
*) face
->font_info
;
19009 unsigned code
= font
->driver
->encode_char (font
, c
);
19011 if (code
!= FONT_INVALID_CODE
)
19012 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19014 STORE_XCHAR2B (char2b
, 0, 0);
19018 #endif /* USE_FONT_BACKEND */
19021 /* Unibyte case. We don't have to encode, but we have to make
19022 sure to use a face suitable for unibyte. */
19023 STORE_XCHAR2B (char2b
, 0, c
);
19024 face_id
= FACE_FOR_CHAR (f
, face
, c
, -1, Qnil
);
19025 face
= FACE_FROM_ID (f
, face_id
);
19029 /* Case of ASCII in a face known to fit ASCII. */
19030 STORE_XCHAR2B (char2b
, 0, c
);
19032 else if (face
->font
!= NULL
)
19034 struct font_info
*font_info
19035 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19036 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
19037 unsigned code
= ENCODE_CHAR (charset
, c
);
19039 if (CHARSET_DIMENSION (charset
) == 1)
19040 STORE_XCHAR2B (char2b
, 0, code
);
19042 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19043 /* Maybe encode the character in *CHAR2B. */
19044 rif
->encode_char (c
, char2b
, font_info
, charset
, NULL
);
19047 /* Make sure X resources of the face are allocated. */
19048 #ifdef HAVE_X_WINDOWS
19052 xassert (face
!= NULL
);
19053 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19060 /* Get face and two-byte form of character glyph GLYPH on frame F.
19061 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19062 a pointer to a realized face that is ready for display. */
19064 static INLINE
struct face
*
19065 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19067 struct glyph
*glyph
;
19073 xassert (glyph
->type
== CHAR_GLYPH
);
19074 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19079 #ifdef USE_FONT_BACKEND
19080 if (enable_font_backend
)
19082 struct font
*font
= (struct font
*) face
->font_info
;
19086 unsigned code
= font
->driver
->encode_char (font
, glyph
->u
.ch
);
19088 if (code
!= FONT_INVALID_CODE
)
19089 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19091 STORE_XCHAR2B (char2b
, 0, code
);
19095 #endif /* USE_FONT_BACKEND */
19096 if (!glyph
->multibyte_p
)
19098 /* Unibyte case. We don't have to encode, but we have to make
19099 sure to use a face suitable for unibyte. */
19100 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
19102 else if (glyph
->u
.ch
< 128)
19104 /* Case of ASCII in a face known to fit ASCII. */
19105 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
19109 struct font_info
*font_info
19110 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
19113 struct charset
*charset
= CHARSET_FROM_ID (font_info
->charset
);
19114 unsigned code
= ENCODE_CHAR (charset
, glyph
->u
.ch
);
19116 if (CHARSET_DIMENSION (charset
) == 1)
19117 STORE_XCHAR2B (char2b
, 0, code
);
19119 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19121 /* Maybe encode the character in *CHAR2B. */
19122 if (CHARSET_ID (charset
) != charset_ascii
)
19125 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, charset
,
19131 /* Make sure X resources of the face are allocated. */
19132 xassert (face
!= NULL
);
19133 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19138 /* Fill glyph string S with composition components specified by S->cmp.
19140 BASE_FACE is the base face of the composition.
19141 S->gidx is the index of the first component for S.
19143 OVERLAPS non-zero means S should draw the foreground only, and use
19144 its physical height for clipping. See also draw_glyphs.
19146 Value is the index of a component not in S. */
19149 fill_composite_glyph_string (s
, base_face
, overlaps
)
19150 struct glyph_string
*s
;
19151 struct face
*base_face
;
19158 s
->for_overlaps
= overlaps
;
19160 #ifdef USE_FONT_BACKEND
19161 if (enable_font_backend
&& s
->cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
19163 Lisp_Object gstring
19164 = AREF (XHASH_TABLE (composition_hash_table
)->key_and_value
,
19165 s
->cmp
->hash_index
* 2);
19167 s
->face
= base_face
;
19168 s
->font_info
= s
->cmp
->font
;
19169 s
->font
= s
->font_info
->font
;
19170 for (i
= 0, s
->nchars
= 0; i
< s
->cmp
->glyph_len
; i
++, s
->nchars
++)
19172 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
19174 XChar2b
* store_pos
;
19175 if (NILP (LGLYPH_FROM (g
)))
19177 code
= XUINT (LGLYPH_CODE (g
));
19178 store_pos
= s
->char2b
+ i
;
19179 STORE_XCHAR2B (store_pos
, code
>> 8, code
& 0xFF);
19181 s
->width
= s
->cmp
->pixel_width
;
19184 #endif /* USE_FONT_BACKEND */
19186 /* For all glyphs of this composition, starting at the offset
19187 S->gidx, until we reach the end of the definition or encounter a
19188 glyph that requires the different face, add it to S. */
19193 s
->font_info
= NULL
;
19194 for (i
= s
->gidx
; i
< s
->cmp
->glyph_len
; i
++)
19196 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19200 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
, c
, -1, Qnil
);
19202 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19203 s
->char2b
+ i
, 1, 1);
19209 s
->font
= s
->face
->font
;
19210 s
->font_info
= FONT_INFO_FROM_FACE (s
->f
, s
->face
);
19212 else if (s
->face
!= face
)
19219 /* All glyph strings for the same composition has the same width,
19220 i.e. the width set for the first component of the composition. */
19221 s
->width
= s
->first_glyph
->pixel_width
;
19224 /* If the specified font could not be loaded, use the frame's
19225 default font, but record the fact that we couldn't load it in
19226 the glyph string so that we can draw rectangles for the
19227 characters of the glyph string. */
19228 if (s
->font
== NULL
)
19230 s
->font_not_found_p
= 1;
19231 s
->font
= FRAME_FONT (s
->f
);
19234 /* Adjust base line for subscript/superscript text. */
19235 s
->ybase
+= s
->first_glyph
->voffset
;
19237 /* This glyph string must always be drawn with 16-bit functions. */
19240 return s
->gidx
+ s
->nchars
;
19244 /* Fill glyph string S from a sequence of character glyphs.
19246 FACE_ID is the face id of the string. START is the index of the
19247 first glyph to consider, END is the index of the last + 1.
19248 OVERLAPS non-zero means S should draw the foreground only, and use
19249 its physical height for clipping. See also draw_glyphs.
19251 Value is the index of the first glyph not in S. */
19254 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19255 struct glyph_string
*s
;
19257 int start
, end
, overlaps
;
19259 struct glyph
*glyph
, *last
;
19261 int glyph_not_available_p
;
19263 xassert (s
->f
== XFRAME (s
->w
->frame
));
19264 xassert (s
->nchars
== 0);
19265 xassert (start
>= 0 && end
> start
);
19267 s
->for_overlaps
= overlaps
,
19268 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19269 last
= s
->row
->glyphs
[s
->area
] + end
;
19270 voffset
= glyph
->voffset
;
19272 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19274 while (glyph
< last
19275 && glyph
->type
== CHAR_GLYPH
19276 && glyph
->voffset
== voffset
19277 /* Same face id implies same font, nowadays. */
19278 && glyph
->face_id
== face_id
19279 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19283 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19284 s
->char2b
+ s
->nchars
,
19286 s
->two_byte_p
= two_byte_p
;
19288 xassert (s
->nchars
<= end
- start
);
19289 s
->width
+= glyph
->pixel_width
;
19293 s
->font
= s
->face
->font
;
19294 s
->font_info
= FONT_INFO_FROM_FACE (s
->f
, s
->face
);
19296 /* If the specified font could not be loaded, use the frame's font,
19297 but record the fact that we couldn't load it in
19298 S->font_not_found_p so that we can draw rectangles for the
19299 characters of the glyph string. */
19300 if (s
->font
== NULL
|| glyph_not_available_p
)
19302 s
->font_not_found_p
= 1;
19303 s
->font
= FRAME_FONT (s
->f
);
19306 /* Adjust base line for subscript/superscript text. */
19307 s
->ybase
+= voffset
;
19309 xassert (s
->face
&& s
->face
->gc
);
19310 return glyph
- s
->row
->glyphs
[s
->area
];
19314 /* Fill glyph string S from image glyph S->first_glyph. */
19317 fill_image_glyph_string (s
)
19318 struct glyph_string
*s
;
19320 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19321 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19323 s
->slice
= s
->first_glyph
->slice
;
19324 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19325 s
->font
= s
->face
->font
;
19326 s
->width
= s
->first_glyph
->pixel_width
;
19328 /* Adjust base line for subscript/superscript text. */
19329 s
->ybase
+= s
->first_glyph
->voffset
;
19333 /* Fill glyph string S from a sequence of stretch glyphs.
19335 ROW is the glyph row in which the glyphs are found, AREA is the
19336 area within the row. START is the index of the first glyph to
19337 consider, END is the index of the last + 1.
19339 Value is the index of the first glyph not in S. */
19342 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19343 struct glyph_string
*s
;
19344 struct glyph_row
*row
;
19345 enum glyph_row_area area
;
19348 struct glyph
*glyph
, *last
;
19349 int voffset
, face_id
;
19351 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19353 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19354 last
= s
->row
->glyphs
[s
->area
] + end
;
19355 face_id
= glyph
->face_id
;
19356 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19357 s
->font
= s
->face
->font
;
19358 s
->font_info
= FONT_INFO_FROM_FACE (s
->f
, s
->face
);
19359 s
->width
= glyph
->pixel_width
;
19361 voffset
= glyph
->voffset
;
19365 && glyph
->type
== STRETCH_GLYPH
19366 && glyph
->voffset
== voffset
19367 && glyph
->face_id
== face_id
);
19369 s
->width
+= glyph
->pixel_width
;
19371 /* Adjust base line for subscript/superscript text. */
19372 s
->ybase
+= voffset
;
19374 /* The case that face->gc == 0 is handled when drawing the glyph
19375 string by calling PREPARE_FACE_FOR_DISPLAY. */
19377 return glyph
- s
->row
->glyphs
[s
->area
];
19380 static XCharStruct
*
19381 get_per_char_metric (font
, font_info
, char2b
, font_type
)
19383 struct font_info
*font_info
;
19387 #ifdef USE_FONT_BACKEND
19388 if (enable_font_backend
)
19390 static XCharStruct pcm_value
;
19391 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19392 struct font
*fontp
;
19393 struct font_metrics metrics
;
19395 if (! font_info
|| code
== FONT_INVALID_CODE
)
19397 fontp
= (struct font
*) font_info
;
19398 fontp
->driver
->text_extents (fontp
, &code
, 1, &metrics
);
19399 pcm_value
.lbearing
= metrics
.lbearing
;
19400 pcm_value
.rbearing
= metrics
.rbearing
;
19401 pcm_value
.ascent
= metrics
.ascent
;
19402 pcm_value
.descent
= metrics
.descent
;
19403 pcm_value
.width
= metrics
.width
;
19406 #endif /* USE_FONT_BACKEND */
19407 return rif
->per_char_metric (font
, char2b
, font_type
);
19411 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19412 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19413 assumed to be zero. */
19416 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19417 struct glyph
*glyph
;
19421 *left
= *right
= 0;
19423 if (glyph
->type
== CHAR_GLYPH
)
19427 struct font_info
*font_info
;
19431 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19433 font_info
= FONT_INFO_FROM_FACE (f
, face
);
19434 if (font
/* ++KFS: Should this be font_info ? */
19435 && (pcm
= get_per_char_metric (font
, font_info
, &char2b
, glyph
->font_type
)))
19437 if (pcm
->rbearing
> pcm
->width
)
19438 *right
= pcm
->rbearing
- pcm
->width
;
19439 if (pcm
->lbearing
< 0)
19440 *left
= -pcm
->lbearing
;
19443 else if (glyph
->type
== COMPOSITE_GLYPH
)
19445 struct composition
*cmp
= composition_table
[glyph
->u
.cmp_id
];
19447 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19448 *left
= - cmp
->lbearing
;
19453 /* Return the index of the first glyph preceding glyph string S that
19454 is overwritten by S because of S's left overhang. Value is -1
19455 if no glyphs are overwritten. */
19458 left_overwritten (s
)
19459 struct glyph_string
*s
;
19463 if (s
->left_overhang
)
19466 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19467 int first
= s
->first_glyph
- glyphs
;
19469 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19470 x
-= glyphs
[i
].pixel_width
;
19481 /* Return the index of the first glyph preceding glyph string S that
19482 is overwriting S because of its right overhang. Value is -1 if no
19483 glyph in front of S overwrites S. */
19486 left_overwriting (s
)
19487 struct glyph_string
*s
;
19490 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19491 int first
= s
->first_glyph
- glyphs
;
19495 for (i
= first
- 1; i
>= 0; --i
)
19498 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19501 x
-= glyphs
[i
].pixel_width
;
19508 /* Return the index of the last glyph following glyph string S that is
19509 not overwritten by S because of S's right overhang. Value is -1 if
19510 no such glyph is found. */
19513 right_overwritten (s
)
19514 struct glyph_string
*s
;
19518 if (s
->right_overhang
)
19521 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19522 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19523 int end
= s
->row
->used
[s
->area
];
19525 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19526 x
+= glyphs
[i
].pixel_width
;
19535 /* Return the index of the last glyph following glyph string S that
19536 overwrites S because of its left overhang. Value is negative
19537 if no such glyph is found. */
19540 right_overwriting (s
)
19541 struct glyph_string
*s
;
19544 int end
= s
->row
->used
[s
->area
];
19545 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19546 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19550 for (i
= first
; i
< end
; ++i
)
19553 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19556 x
+= glyphs
[i
].pixel_width
;
19563 /* Set background width of glyph string S. START is the index of the
19564 first glyph following S. LAST_X is the right-most x-position + 1
19565 in the drawing area. */
19568 set_glyph_string_background_width (s
, start
, last_x
)
19569 struct glyph_string
*s
;
19573 /* If the face of this glyph string has to be drawn to the end of
19574 the drawing area, set S->extends_to_end_of_line_p. */
19576 if (start
== s
->row
->used
[s
->area
]
19577 && s
->area
== TEXT_AREA
19578 && ((s
->row
->fill_line_p
19579 && (s
->hl
== DRAW_NORMAL_TEXT
19580 || s
->hl
== DRAW_IMAGE_RAISED
19581 || s
->hl
== DRAW_IMAGE_SUNKEN
))
19582 || s
->hl
== DRAW_MOUSE_FACE
))
19583 s
->extends_to_end_of_line_p
= 1;
19585 /* If S extends its face to the end of the line, set its
19586 background_width to the distance to the right edge of the drawing
19588 if (s
->extends_to_end_of_line_p
)
19589 s
->background_width
= last_x
- s
->x
+ 1;
19591 s
->background_width
= s
->width
;
19595 /* Compute overhangs and x-positions for glyph string S and its
19596 predecessors, or successors. X is the starting x-position for S.
19597 BACKWARD_P non-zero means process predecessors. */
19600 compute_overhangs_and_x (s
, x
, backward_p
)
19601 struct glyph_string
*s
;
19609 if (rif
->compute_glyph_string_overhangs
)
19610 rif
->compute_glyph_string_overhangs (s
);
19620 if (rif
->compute_glyph_string_overhangs
)
19621 rif
->compute_glyph_string_overhangs (s
);
19631 /* The following macros are only called from draw_glyphs below.
19632 They reference the following parameters of that function directly:
19633 `w', `row', `area', and `overlap_p'
19634 as well as the following local variables:
19635 `s', `f', and `hdc' (in W32) */
19638 /* On W32, silently add local `hdc' variable to argument list of
19639 init_glyph_string. */
19640 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19641 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
19643 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
19644 init_glyph_string (s, char2b, w, row, area, start, hl)
19647 /* Add a glyph string for a stretch glyph to the list of strings
19648 between HEAD and TAIL. START is the index of the stretch glyph in
19649 row area AREA of glyph row ROW. END is the index of the last glyph
19650 in that glyph row area. X is the current output position assigned
19651 to the new glyph string constructed. HL overrides that face of the
19652 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19653 is the right-most x-position of the drawing area. */
19655 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
19656 and below -- keep them on one line. */
19657 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19660 s = (struct glyph_string *) alloca (sizeof *s); \
19661 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19662 START = fill_stretch_glyph_string (s, row, area, START, END); \
19663 append_glyph_string (&HEAD, &TAIL, s); \
19669 /* Add a glyph string for an image glyph to the list of strings
19670 between HEAD and TAIL. START is the index of the image glyph in
19671 row area AREA of glyph row ROW. END is the index of the last glyph
19672 in that glyph row area. X is the current output position assigned
19673 to the new glyph string constructed. HL overrides that face of the
19674 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
19675 is the right-most x-position of the drawing area. */
19677 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19680 s = (struct glyph_string *) alloca (sizeof *s); \
19681 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
19682 fill_image_glyph_string (s); \
19683 append_glyph_string (&HEAD, &TAIL, s); \
19690 /* Add a glyph string for a sequence of character glyphs to the list
19691 of strings between HEAD and TAIL. START is the index of the first
19692 glyph in row area AREA of glyph row ROW that is part of the new
19693 glyph string. END is the index of the last glyph in that glyph row
19694 area. X is the current output position assigned to the new glyph
19695 string constructed. HL overrides that face of the glyph; e.g. it
19696 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
19697 right-most x-position of the drawing area. */
19699 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19705 face_id = (row)->glyphs[area][START].face_id; \
19707 s = (struct glyph_string *) alloca (sizeof *s); \
19708 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
19709 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19710 append_glyph_string (&HEAD, &TAIL, s); \
19712 START = fill_glyph_string (s, face_id, START, END, overlaps); \
19717 /* Add a glyph string for a composite sequence to the list of strings
19718 between HEAD and TAIL. START is the index of the first glyph in
19719 row area AREA of glyph row ROW that is part of the new glyph
19720 string. END is the index of the last glyph in that glyph row area.
19721 X is the current output position assigned to the new glyph string
19722 constructed. HL overrides that face of the glyph; e.g. it is
19723 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
19724 x-position of the drawing area. */
19726 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
19728 int face_id = (row)->glyphs[area][START].face_id; \
19729 struct face *base_face = FACE_FROM_ID (f, face_id); \
19730 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
19731 struct composition *cmp = composition_table[cmp_id]; \
19733 struct glyph_string *first_s; \
19736 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
19737 base_face = base_face->ascii_face; \
19739 /* Make glyph_strings for each glyph sequence that is drawable by \
19740 the same face, and append them to HEAD/TAIL. */ \
19741 for (n = 0; n < cmp->glyph_len;) \
19743 s = (struct glyph_string *) alloca (sizeof *s); \
19744 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
19745 append_glyph_string (&(HEAD), &(TAIL), s); \
19751 n = fill_composite_glyph_string (s, base_face, overlaps); \
19759 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
19760 of AREA of glyph row ROW on window W between indices START and END.
19761 HL overrides the face for drawing glyph strings, e.g. it is
19762 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
19763 x-positions of the drawing area.
19765 This is an ugly monster macro construct because we must use alloca
19766 to allocate glyph strings (because draw_glyphs can be called
19767 asynchronously). */
19769 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
19772 HEAD = TAIL = NULL; \
19773 while (START < END) \
19775 struct glyph *first_glyph = (row)->glyphs[area] + START; \
19776 switch (first_glyph->type) \
19779 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
19783 case COMPOSITE_GLYPH: \
19784 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
19788 case STRETCH_GLYPH: \
19789 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
19793 case IMAGE_GLYPH: \
19794 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
19804 set_glyph_string_background_width (s, START, LAST_X); \
19812 /* Draw glyphs between START and END in AREA of ROW on window W,
19813 starting at x-position X. X is relative to AREA in W. HL is a
19814 face-override with the following meaning:
19816 DRAW_NORMAL_TEXT draw normally
19817 DRAW_CURSOR draw in cursor face
19818 DRAW_MOUSE_FACE draw in mouse face.
19819 DRAW_INVERSE_VIDEO draw in mode line face
19820 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
19821 DRAW_IMAGE_RAISED draw an image with a raised relief around it
19823 If OVERLAPS is non-zero, draw only the foreground of characters and
19824 clip to the physical height of ROW. Non-zero value also defines
19825 the overlapping part to be drawn:
19827 OVERLAPS_PRED overlap with preceding rows
19828 OVERLAPS_SUCC overlap with succeeding rows
19829 OVERLAPS_BOTH overlap with both preceding/succeeding rows
19830 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
19832 Value is the x-position reached, relative to AREA of W. */
19835 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
19838 struct glyph_row
*row
;
19839 enum glyph_row_area area
;
19840 EMACS_INT start
, end
;
19841 enum draw_glyphs_face hl
;
19844 struct glyph_string
*head
, *tail
;
19845 struct glyph_string
*s
;
19846 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
19847 int last_x
, area_width
;
19850 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19853 ALLOCATE_HDC (hdc
, f
);
19855 /* Let's rather be paranoid than getting a SEGV. */
19856 end
= min (end
, row
->used
[area
]);
19857 start
= max (0, start
);
19858 start
= min (end
, start
);
19860 /* Translate X to frame coordinates. Set last_x to the right
19861 end of the drawing area. */
19862 if (row
->full_width_p
)
19864 /* X is relative to the left edge of W, without scroll bars
19866 x
+= WINDOW_LEFT_EDGE_X (w
);
19867 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
19871 int area_left
= window_box_left (w
, area
);
19873 area_width
= window_box_width (w
, area
);
19874 last_x
= area_left
+ area_width
;
19877 /* Build a doubly-linked list of glyph_string structures between
19878 head and tail from what we have to draw. Note that the macro
19879 BUILD_GLYPH_STRINGS will modify its start parameter. That's
19880 the reason we use a separate variable `i'. */
19882 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
19884 x_reached
= tail
->x
+ tail
->background_width
;
19888 /* If there are any glyphs with lbearing < 0 or rbearing > width in
19889 the row, redraw some glyphs in front or following the glyph
19890 strings built above. */
19891 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
19894 struct glyph_string
*h
, *t
;
19896 /* Compute overhangs for all glyph strings. */
19897 if (rif
->compute_glyph_string_overhangs
)
19898 for (s
= head
; s
; s
= s
->next
)
19899 rif
->compute_glyph_string_overhangs (s
);
19901 /* Prepend glyph strings for glyphs in front of the first glyph
19902 string that are overwritten because of the first glyph
19903 string's left overhang. The background of all strings
19904 prepended must be drawn because the first glyph string
19906 i
= left_overwritten (head
);
19910 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
19911 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19913 compute_overhangs_and_x (t
, head
->x
, 1);
19914 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19918 /* Prepend glyph strings for glyphs in front of the first glyph
19919 string that overwrite that glyph string because of their
19920 right overhang. For these strings, only the foreground must
19921 be drawn, because it draws over the glyph string at `head'.
19922 The background must not be drawn because this would overwrite
19923 right overhangs of preceding glyphs for which no glyph
19925 i
= left_overwriting (head
);
19929 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
19930 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
19931 for (s
= h
; s
; s
= s
->next
)
19932 s
->background_filled_p
= 1;
19933 compute_overhangs_and_x (t
, head
->x
, 1);
19934 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
19937 /* Append glyphs strings for glyphs following the last glyph
19938 string tail that are overwritten by tail. The background of
19939 these strings has to be drawn because tail's foreground draws
19941 i
= right_overwritten (tail
);
19944 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19945 DRAW_NORMAL_TEXT
, x
, last_x
);
19946 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19947 append_glyph_string_lists (&head
, &tail
, h
, t
);
19951 /* Append glyph strings for glyphs following the last glyph
19952 string tail that overwrite tail. The foreground of such
19953 glyphs has to be drawn because it writes into the background
19954 of tail. The background must not be drawn because it could
19955 paint over the foreground of following glyphs. */
19956 i
= right_overwriting (tail
);
19960 i
++; /* We must include the Ith glyph. */
19961 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
19962 DRAW_NORMAL_TEXT
, x
, last_x
);
19963 for (s
= h
; s
; s
= s
->next
)
19964 s
->background_filled_p
= 1;
19965 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
19966 append_glyph_string_lists (&head
, &tail
, h
, t
);
19968 if (clip_head
|| clip_tail
)
19969 for (s
= head
; s
; s
= s
->next
)
19971 s
->clip_head
= clip_head
;
19972 s
->clip_tail
= clip_tail
;
19976 /* Draw all strings. */
19977 for (s
= head
; s
; s
= s
->next
)
19978 rif
->draw_glyph_string (s
);
19980 if (area
== TEXT_AREA
19981 && !row
->full_width_p
19982 /* When drawing overlapping rows, only the glyph strings'
19983 foreground is drawn, which doesn't erase a cursor
19987 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
19988 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
19989 : (tail
? tail
->x
+ tail
->background_width
: x
));
19991 int text_left
= window_box_left (w
, TEXT_AREA
);
19995 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
19996 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
19999 /* Value is the x-position up to which drawn, relative to AREA of W.
20000 This doesn't include parts drawn because of overhangs. */
20001 if (row
->full_width_p
)
20002 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20004 x_reached
-= window_box_left (w
, area
);
20006 RELEASE_HDC (hdc
, f
);
20011 /* Expand row matrix if too narrow. Don't expand if area
20014 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20016 if (!fonts_changed_p \
20017 && (it->glyph_row->glyphs[area] \
20018 < it->glyph_row->glyphs[area + 1])) \
20020 it->w->ncols_scale_factor++; \
20021 fonts_changed_p = 1; \
20025 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20026 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20032 struct glyph
*glyph
;
20033 enum glyph_row_area area
= it
->area
;
20035 xassert (it
->glyph_row
);
20036 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20038 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20039 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20041 glyph
->charpos
= CHARPOS (it
->position
);
20042 glyph
->object
= it
->object
;
20043 glyph
->pixel_width
= it
->pixel_width
;
20044 glyph
->ascent
= it
->ascent
;
20045 glyph
->descent
= it
->descent
;
20046 glyph
->voffset
= it
->voffset
;
20047 glyph
->type
= CHAR_GLYPH
;
20048 glyph
->multibyte_p
= it
->multibyte_p
;
20049 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20050 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20051 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20052 || it
->phys_descent
> it
->descent
);
20053 glyph
->padding_p
= 0;
20054 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20055 glyph
->face_id
= it
->face_id
;
20056 glyph
->u
.ch
= it
->char_to_display
;
20057 glyph
->slice
= null_glyph_slice
;
20058 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20059 ++it
->glyph_row
->used
[area
];
20062 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20065 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
20066 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20069 append_composite_glyph (it
)
20072 struct glyph
*glyph
;
20073 enum glyph_row_area area
= it
->area
;
20075 xassert (it
->glyph_row
);
20077 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20078 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20080 glyph
->charpos
= CHARPOS (it
->position
);
20081 glyph
->object
= it
->object
;
20082 glyph
->pixel_width
= it
->pixel_width
;
20083 glyph
->ascent
= it
->ascent
;
20084 glyph
->descent
= it
->descent
;
20085 glyph
->voffset
= it
->voffset
;
20086 glyph
->type
= COMPOSITE_GLYPH
;
20087 glyph
->multibyte_p
= it
->multibyte_p
;
20088 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20089 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20090 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20091 || it
->phys_descent
> it
->descent
);
20092 glyph
->padding_p
= 0;
20093 glyph
->glyph_not_available_p
= 0;
20094 glyph
->face_id
= it
->face_id
;
20095 glyph
->u
.cmp_id
= it
->cmp_id
;
20096 glyph
->slice
= null_glyph_slice
;
20097 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20098 ++it
->glyph_row
->used
[area
];
20101 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20105 /* Change IT->ascent and IT->height according to the setting of
20109 take_vertical_position_into_account (it
)
20114 if (it
->voffset
< 0)
20115 /* Increase the ascent so that we can display the text higher
20117 it
->ascent
-= it
->voffset
;
20119 /* Increase the descent so that we can display the text lower
20121 it
->descent
+= it
->voffset
;
20126 /* Produce glyphs/get display metrics for the image IT is loaded with.
20127 See the description of struct display_iterator in dispextern.h for
20128 an overview of struct display_iterator. */
20131 produce_image_glyph (it
)
20136 int glyph_ascent
, crop
;
20137 struct glyph_slice slice
;
20139 xassert (it
->what
== IT_IMAGE
);
20141 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20143 /* Make sure X resources of the face is loaded. */
20144 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20146 if (it
->image_id
< 0)
20148 /* Fringe bitmap. */
20149 it
->ascent
= it
->phys_ascent
= 0;
20150 it
->descent
= it
->phys_descent
= 0;
20151 it
->pixel_width
= 0;
20156 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20158 /* Make sure X resources of the image is loaded. */
20159 prepare_image_for_display (it
->f
, img
);
20161 slice
.x
= slice
.y
= 0;
20162 slice
.width
= img
->width
;
20163 slice
.height
= img
->height
;
20165 if (INTEGERP (it
->slice
.x
))
20166 slice
.x
= XINT (it
->slice
.x
);
20167 else if (FLOATP (it
->slice
.x
))
20168 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20170 if (INTEGERP (it
->slice
.y
))
20171 slice
.y
= XINT (it
->slice
.y
);
20172 else if (FLOATP (it
->slice
.y
))
20173 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20175 if (INTEGERP (it
->slice
.width
))
20176 slice
.width
= XINT (it
->slice
.width
);
20177 else if (FLOATP (it
->slice
.width
))
20178 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20180 if (INTEGERP (it
->slice
.height
))
20181 slice
.height
= XINT (it
->slice
.height
);
20182 else if (FLOATP (it
->slice
.height
))
20183 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20185 if (slice
.x
>= img
->width
)
20186 slice
.x
= img
->width
;
20187 if (slice
.y
>= img
->height
)
20188 slice
.y
= img
->height
;
20189 if (slice
.x
+ slice
.width
>= img
->width
)
20190 slice
.width
= img
->width
- slice
.x
;
20191 if (slice
.y
+ slice
.height
> img
->height
)
20192 slice
.height
= img
->height
- slice
.y
;
20194 if (slice
.width
== 0 || slice
.height
== 0)
20197 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20199 it
->descent
= slice
.height
- glyph_ascent
;
20201 it
->descent
+= img
->vmargin
;
20202 if (slice
.y
+ slice
.height
== img
->height
)
20203 it
->descent
+= img
->vmargin
;
20204 it
->phys_descent
= it
->descent
;
20206 it
->pixel_width
= slice
.width
;
20208 it
->pixel_width
+= img
->hmargin
;
20209 if (slice
.x
+ slice
.width
== img
->width
)
20210 it
->pixel_width
+= img
->hmargin
;
20212 /* It's quite possible for images to have an ascent greater than
20213 their height, so don't get confused in that case. */
20214 if (it
->descent
< 0)
20217 #if 0 /* this breaks image tiling */
20218 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
20219 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
20220 if (face_ascent
> it
->ascent
)
20221 it
->ascent
= it
->phys_ascent
= face_ascent
;
20226 if (face
->box
!= FACE_NO_BOX
)
20228 if (face
->box_line_width
> 0)
20231 it
->ascent
+= face
->box_line_width
;
20232 if (slice
.y
+ slice
.height
== img
->height
)
20233 it
->descent
+= face
->box_line_width
;
20236 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20237 it
->pixel_width
+= abs (face
->box_line_width
);
20238 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20239 it
->pixel_width
+= abs (face
->box_line_width
);
20242 take_vertical_position_into_account (it
);
20244 /* Automatically crop wide image glyphs at right edge so we can
20245 draw the cursor on same display row. */
20246 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20247 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20249 it
->pixel_width
-= crop
;
20250 slice
.width
-= crop
;
20255 struct glyph
*glyph
;
20256 enum glyph_row_area area
= it
->area
;
20258 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20259 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20261 glyph
->charpos
= CHARPOS (it
->position
);
20262 glyph
->object
= it
->object
;
20263 glyph
->pixel_width
= it
->pixel_width
;
20264 glyph
->ascent
= glyph_ascent
;
20265 glyph
->descent
= it
->descent
;
20266 glyph
->voffset
= it
->voffset
;
20267 glyph
->type
= IMAGE_GLYPH
;
20268 glyph
->multibyte_p
= it
->multibyte_p
;
20269 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20270 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20271 glyph
->overlaps_vertically_p
= 0;
20272 glyph
->padding_p
= 0;
20273 glyph
->glyph_not_available_p
= 0;
20274 glyph
->face_id
= it
->face_id
;
20275 glyph
->u
.img_id
= img
->id
;
20276 glyph
->slice
= slice
;
20277 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20278 ++it
->glyph_row
->used
[area
];
20281 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20286 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20287 of the glyph, WIDTH and HEIGHT are the width and height of the
20288 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20291 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20293 Lisp_Object object
;
20297 struct glyph
*glyph
;
20298 enum glyph_row_area area
= it
->area
;
20300 xassert (ascent
>= 0 && ascent
<= height
);
20302 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20303 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20305 glyph
->charpos
= CHARPOS (it
->position
);
20306 glyph
->object
= object
;
20307 glyph
->pixel_width
= width
;
20308 glyph
->ascent
= ascent
;
20309 glyph
->descent
= height
- ascent
;
20310 glyph
->voffset
= it
->voffset
;
20311 glyph
->type
= STRETCH_GLYPH
;
20312 glyph
->multibyte_p
= it
->multibyte_p
;
20313 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20314 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20315 glyph
->overlaps_vertically_p
= 0;
20316 glyph
->padding_p
= 0;
20317 glyph
->glyph_not_available_p
= 0;
20318 glyph
->face_id
= it
->face_id
;
20319 glyph
->u
.stretch
.ascent
= ascent
;
20320 glyph
->u
.stretch
.height
= height
;
20321 glyph
->slice
= null_glyph_slice
;
20322 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20323 ++it
->glyph_row
->used
[area
];
20326 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20330 /* Produce a stretch glyph for iterator IT. IT->object is the value
20331 of the glyph property displayed. The value must be a list
20332 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20335 1. `:width WIDTH' specifies that the space should be WIDTH *
20336 canonical char width wide. WIDTH may be an integer or floating
20339 2. `:relative-width FACTOR' specifies that the width of the stretch
20340 should be computed from the width of the first character having the
20341 `glyph' property, and should be FACTOR times that width.
20343 3. `:align-to HPOS' specifies that the space should be wide enough
20344 to reach HPOS, a value in canonical character units.
20346 Exactly one of the above pairs must be present.
20348 4. `:height HEIGHT' specifies that the height of the stretch produced
20349 should be HEIGHT, measured in canonical character units.
20351 5. `:relative-height FACTOR' specifies that the height of the
20352 stretch should be FACTOR times the height of the characters having
20353 the glyph property.
20355 Either none or exactly one of 4 or 5 must be present.
20357 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20358 of the stretch should be used for the ascent of the stretch.
20359 ASCENT must be in the range 0 <= ASCENT <= 100. */
20362 produce_stretch_glyph (it
)
20365 /* (space :width WIDTH :height HEIGHT ...) */
20366 Lisp_Object prop
, plist
;
20367 int width
= 0, height
= 0, align_to
= -1;
20368 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20371 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20372 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20374 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20376 /* List should start with `space'. */
20377 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20378 plist
= XCDR (it
->object
);
20380 /* Compute the width of the stretch. */
20381 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20382 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20384 /* Absolute width `:width WIDTH' specified and valid. */
20385 zero_width_ok_p
= 1;
20388 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20391 /* Relative width `:relative-width FACTOR' specified and valid.
20392 Compute the width of the characters having the `glyph'
20395 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20398 if (it
->multibyte_p
)
20400 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20401 - IT_BYTEPOS (*it
));
20402 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20405 it2
.c
= *p
, it2
.len
= 1;
20407 it2
.glyph_row
= NULL
;
20408 it2
.what
= IT_CHARACTER
;
20409 x_produce_glyphs (&it2
);
20410 width
= NUMVAL (prop
) * it2
.pixel_width
;
20412 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20413 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20415 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20416 align_to
= (align_to
< 0
20418 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20419 else if (align_to
< 0)
20420 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20421 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20422 zero_width_ok_p
= 1;
20425 /* Nothing specified -> width defaults to canonical char width. */
20426 width
= FRAME_COLUMN_WIDTH (it
->f
);
20428 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20431 /* Compute height. */
20432 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20433 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20436 zero_height_ok_p
= 1;
20438 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20440 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20442 height
= FONT_HEIGHT (font
);
20444 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20447 /* Compute percentage of height used for ascent. If
20448 `:ascent ASCENT' is present and valid, use that. Otherwise,
20449 derive the ascent from the font in use. */
20450 if (prop
= Fplist_get (plist
, QCascent
),
20451 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20452 ascent
= height
* NUMVAL (prop
) / 100.0;
20453 else if (!NILP (prop
)
20454 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20455 ascent
= min (max (0, (int)tem
), height
);
20457 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20459 if (width
> 0 && !it
->truncate_lines_p
20460 && it
->current_x
+ width
> it
->last_visible_x
)
20461 width
= it
->last_visible_x
- it
->current_x
- 1;
20463 if (width
> 0 && height
> 0 && it
->glyph_row
)
20465 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20466 if (!STRINGP (object
))
20467 object
= it
->w
->buffer
;
20468 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20471 it
->pixel_width
= width
;
20472 it
->ascent
= it
->phys_ascent
= ascent
;
20473 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20474 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20476 take_vertical_position_into_account (it
);
20479 /* Get line-height and line-spacing property at point.
20480 If line-height has format (HEIGHT TOTAL), return TOTAL
20481 in TOTAL_HEIGHT. */
20484 get_line_height_property (it
, prop
)
20488 Lisp_Object position
;
20490 if (STRINGP (it
->object
))
20491 position
= make_number (IT_STRING_CHARPOS (*it
));
20492 else if (BUFFERP (it
->object
))
20493 position
= make_number (IT_CHARPOS (*it
));
20497 return Fget_char_property (position
, prop
, it
->object
);
20500 /* Calculate line-height and line-spacing properties.
20501 An integer value specifies explicit pixel value.
20502 A float value specifies relative value to current face height.
20503 A cons (float . face-name) specifies relative value to
20504 height of specified face font.
20506 Returns height in pixels, or nil. */
20510 calc_line_height_property (it
, val
, font
, boff
, override
)
20514 int boff
, override
;
20516 Lisp_Object face_name
= Qnil
;
20517 int ascent
, descent
, height
;
20519 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
20524 face_name
= XCAR (val
);
20526 if (!NUMBERP (val
))
20527 val
= make_number (1);
20528 if (NILP (face_name
))
20530 height
= it
->ascent
+ it
->descent
;
20535 if (NILP (face_name
))
20537 font
= FRAME_FONT (it
->f
);
20538 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20540 else if (EQ (face_name
, Qt
))
20548 struct font_info
*font_info
;
20550 face_id
= lookup_named_face (it
->f
, face_name
, 0);
20552 return make_number (-1);
20554 face
= FACE_FROM_ID (it
->f
, face_id
);
20557 return make_number (-1);
20559 font_info
= FONT_INFO_FROM_FACE (it
->f
, face
);
20560 boff
= font_info
->baseline_offset
;
20561 if (font_info
->vertical_centering
)
20562 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20565 ascent
= FONT_BASE (font
) + boff
;
20566 descent
= FONT_DESCENT (font
) - boff
;
20570 it
->override_ascent
= ascent
;
20571 it
->override_descent
= descent
;
20572 it
->override_boff
= boff
;
20575 height
= ascent
+ descent
;
20579 height
= (int)(XFLOAT_DATA (val
) * height
);
20580 else if (INTEGERP (val
))
20581 height
*= XINT (val
);
20583 return make_number (height
);
20588 Produce glyphs/get display metrics for the display element IT is
20589 loaded with. See the description of struct it in dispextern.h
20590 for an overview of struct it. */
20593 x_produce_glyphs (it
)
20596 int extra_line_spacing
= it
->extra_line_spacing
;
20598 it
->glyph_not_available_p
= 0;
20600 if (it
->what
== IT_CHARACTER
)
20604 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20606 int font_not_found_p
;
20607 struct font_info
*font_info
;
20608 int boff
; /* baseline offset */
20609 /* We may change it->multibyte_p upon unibyte<->multibyte
20610 conversion. So, save the current value now and restore it
20613 Note: It seems that we don't have to record multibyte_p in
20614 struct glyph because the character code itself tells if or
20615 not the character is multibyte. Thus, in the future, we must
20616 consider eliminating the field `multibyte_p' in the struct
20618 int saved_multibyte_p
= it
->multibyte_p
;
20620 /* Maybe translate single-byte characters to multibyte, or the
20622 it
->char_to_display
= it
->c
;
20623 if (!ASCII_BYTE_P (it
->c
)
20624 && ! it
->multibyte_p
)
20626 if (SINGLE_BYTE_CHAR_P (it
->c
)
20627 && unibyte_display_via_language_environment
)
20628 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
20629 if (! SINGLE_BYTE_CHAR_P (it
->char_to_display
))
20631 it
->multibyte_p
= 1;
20632 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
20634 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20638 /* Get font to use. Encode IT->char_to_display. */
20639 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
20640 &char2b
, it
->multibyte_p
, 0);
20643 /* When no suitable font found, use the default font. */
20644 font_not_found_p
= font
== NULL
;
20645 if (font_not_found_p
)
20647 font
= FRAME_FONT (it
->f
);
20648 boff
= FRAME_BASELINE_OFFSET (it
->f
);
20653 font_info
= FONT_INFO_FROM_FACE (it
->f
, face
);
20654 boff
= font_info
->baseline_offset
;
20655 if (font_info
->vertical_centering
)
20656 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
20659 if (it
->char_to_display
>= ' '
20660 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
20662 /* Either unibyte or ASCII. */
20667 pcm
= get_per_char_metric (font
, font_info
, &char2b
,
20668 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
20670 if (it
->override_ascent
>= 0)
20672 it
->ascent
= it
->override_ascent
;
20673 it
->descent
= it
->override_descent
;
20674 boff
= it
->override_boff
;
20678 it
->ascent
= FONT_BASE (font
) + boff
;
20679 it
->descent
= FONT_DESCENT (font
) - boff
;
20684 it
->phys_ascent
= pcm
->ascent
+ boff
;
20685 it
->phys_descent
= pcm
->descent
- boff
;
20686 it
->pixel_width
= pcm
->width
;
20690 it
->glyph_not_available_p
= 1;
20691 it
->phys_ascent
= it
->ascent
;
20692 it
->phys_descent
= it
->descent
;
20693 it
->pixel_width
= FONT_WIDTH (font
);
20696 if (it
->constrain_row_ascent_descent_p
)
20698 if (it
->descent
> it
->max_descent
)
20700 it
->ascent
+= it
->descent
- it
->max_descent
;
20701 it
->descent
= it
->max_descent
;
20703 if (it
->ascent
> it
->max_ascent
)
20705 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20706 it
->ascent
= it
->max_ascent
;
20708 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20709 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20710 extra_line_spacing
= 0;
20713 /* If this is a space inside a region of text with
20714 `space-width' property, change its width. */
20715 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
20717 it
->pixel_width
*= XFLOATINT (it
->space_width
);
20719 /* If face has a box, add the box thickness to the character
20720 height. If character has a box line to the left and/or
20721 right, add the box line width to the character's width. */
20722 if (face
->box
!= FACE_NO_BOX
)
20724 int thick
= face
->box_line_width
;
20728 it
->ascent
+= thick
;
20729 it
->descent
+= thick
;
20734 if (it
->start_of_box_run_p
)
20735 it
->pixel_width
+= thick
;
20736 if (it
->end_of_box_run_p
)
20737 it
->pixel_width
+= thick
;
20740 /* If face has an overline, add the height of the overline
20741 (1 pixel) and a 1 pixel margin to the character height. */
20742 if (face
->overline_p
)
20743 it
->ascent
+= overline_margin
;
20745 if (it
->constrain_row_ascent_descent_p
)
20747 if (it
->ascent
> it
->max_ascent
)
20748 it
->ascent
= it
->max_ascent
;
20749 if (it
->descent
> it
->max_descent
)
20750 it
->descent
= it
->max_descent
;
20753 take_vertical_position_into_account (it
);
20755 /* If we have to actually produce glyphs, do it. */
20760 /* Translate a space with a `space-width' property
20761 into a stretch glyph. */
20762 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
20763 / FONT_HEIGHT (font
));
20764 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20765 it
->ascent
+ it
->descent
, ascent
);
20770 /* If characters with lbearing or rbearing are displayed
20771 in this line, record that fact in a flag of the
20772 glyph row. This is used to optimize X output code. */
20773 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
20774 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20777 else if (it
->char_to_display
== '\n')
20779 /* A newline has no width but we need the height of the line.
20780 But if previous part of the line set a height, don't
20781 increase that height */
20783 Lisp_Object height
;
20784 Lisp_Object total_height
= Qnil
;
20786 it
->override_ascent
= -1;
20787 it
->pixel_width
= 0;
20790 height
= get_line_height_property(it
, Qline_height
);
20791 /* Split (line-height total-height) list */
20793 && CONSP (XCDR (height
))
20794 && NILP (XCDR (XCDR (height
))))
20796 total_height
= XCAR (XCDR (height
));
20797 height
= XCAR (height
);
20799 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
20801 if (it
->override_ascent
>= 0)
20803 it
->ascent
= it
->override_ascent
;
20804 it
->descent
= it
->override_descent
;
20805 boff
= it
->override_boff
;
20809 it
->ascent
= FONT_BASE (font
) + boff
;
20810 it
->descent
= FONT_DESCENT (font
) - boff
;
20813 if (EQ (height
, Qt
))
20815 if (it
->descent
> it
->max_descent
)
20817 it
->ascent
+= it
->descent
- it
->max_descent
;
20818 it
->descent
= it
->max_descent
;
20820 if (it
->ascent
> it
->max_ascent
)
20822 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
20823 it
->ascent
= it
->max_ascent
;
20825 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
20826 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
20827 it
->constrain_row_ascent_descent_p
= 1;
20828 extra_line_spacing
= 0;
20832 Lisp_Object spacing
;
20834 it
->phys_ascent
= it
->ascent
;
20835 it
->phys_descent
= it
->descent
;
20837 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
20838 && face
->box
!= FACE_NO_BOX
20839 && face
->box_line_width
> 0)
20841 it
->ascent
+= face
->box_line_width
;
20842 it
->descent
+= face
->box_line_width
;
20845 && XINT (height
) > it
->ascent
+ it
->descent
)
20846 it
->ascent
= XINT (height
) - it
->descent
;
20848 if (!NILP (total_height
))
20849 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
20852 spacing
= get_line_height_property(it
, Qline_spacing
);
20853 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
20855 if (INTEGERP (spacing
))
20857 extra_line_spacing
= XINT (spacing
);
20858 if (!NILP (total_height
))
20859 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
20863 else if (it
->char_to_display
== '\t')
20865 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
20866 int x
= it
->current_x
+ it
->continuation_lines_width
;
20867 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
20869 /* If the distance from the current position to the next tab
20870 stop is less than a space character width, use the
20871 tab stop after that. */
20872 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
20873 next_tab_x
+= tab_width
;
20875 it
->pixel_width
= next_tab_x
- x
;
20877 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
20878 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20882 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
20883 it
->ascent
+ it
->descent
, it
->ascent
);
20888 /* A multi-byte character. Assume that the display width of the
20889 character is the width of the character multiplied by the
20890 width of the font. */
20892 /* If we found a font, this font should give us the right
20893 metrics. If we didn't find a font, use the frame's
20894 default font and calculate the width of the character by
20895 multiplying the width of font by the width of the
20898 pcm
= get_per_char_metric (font
, font_info
, &char2b
,
20899 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
20901 if (font_not_found_p
|| !pcm
)
20903 int char_width
= CHAR_WIDTH (it
->char_to_display
);
20905 if (char_width
== 0)
20906 /* This is a non spacing character. But, as we are
20907 going to display an empty box, the box must occupy
20908 at least one column. */
20910 it
->glyph_not_available_p
= 1;
20911 it
->pixel_width
= FRAME_COLUMN_WIDTH (it
->f
) * char_width
;
20912 it
->phys_ascent
= FONT_BASE (font
) + boff
;
20913 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
20917 it
->pixel_width
= pcm
->width
;
20918 it
->phys_ascent
= pcm
->ascent
+ boff
;
20919 it
->phys_descent
= pcm
->descent
- boff
;
20921 && (pcm
->lbearing
< 0
20922 || pcm
->rbearing
> pcm
->width
))
20923 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
20926 it
->ascent
= FONT_BASE (font
) + boff
;
20927 it
->descent
= FONT_DESCENT (font
) - boff
;
20928 if (face
->box
!= FACE_NO_BOX
)
20930 int thick
= face
->box_line_width
;
20934 it
->ascent
+= thick
;
20935 it
->descent
+= thick
;
20940 if (it
->start_of_box_run_p
)
20941 it
->pixel_width
+= thick
;
20942 if (it
->end_of_box_run_p
)
20943 it
->pixel_width
+= thick
;
20946 /* If face has an overline, add the height of the overline
20947 (1 pixel) and a 1 pixel margin to the character height. */
20948 if (face
->overline_p
)
20949 it
->ascent
+= overline_margin
;
20951 take_vertical_position_into_account (it
);
20956 it
->multibyte_p
= saved_multibyte_p
;
20958 else if (it
->what
== IT_COMPOSITION
)
20960 /* Note: A composition is represented as one glyph in the
20961 glyph matrix. There are no padding glyphs.
20963 Important is that pixel_width, ascent, and descent are the
20964 values of what is drawn by draw_glyphs (i.e. the values of
20965 the overall glyphs composed). */
20966 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20967 int boff
; /* baseline offset */
20968 struct composition
*cmp
= composition_table
[it
->cmp_id
];
20969 int glyph_len
= cmp
->glyph_len
;
20970 XFontStruct
*font
= face
->font
;
20974 #ifdef USE_FONT_BACKEND
20975 if (cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
20977 if (! cmp
->font
|| cmp
->font
!= font
)
20978 font_prepare_composition (cmp
);
20981 #endif /* USE_FONT_BACKEND */
20982 /* If we have not yet calculated pixel size data of glyphs of
20983 the composition for the current face font, calculate them
20984 now. Theoretically, we have to check all fonts for the
20985 glyphs, but that requires much time and memory space. So,
20986 here we check only the font of the first glyph. This leads
20987 to incorrect display, but it's very rare, and C-l (recenter)
20988 can correct the display anyway. */
20989 if (! cmp
->font
|| cmp
->font
!= font
)
20991 /* Ascent and descent of the font of the first character
20992 of this composition (adjusted by baseline offset).
20993 Ascent and descent of overall glyphs should not be less
20994 than them respectively. */
20995 int font_ascent
, font_descent
, font_height
;
20996 /* Bounding box of the overall glyphs. */
20997 int leftmost
, rightmost
, lowest
, highest
;
20998 int lbearing
, rbearing
;
20999 int i
, width
, ascent
, descent
;
21000 int left_padded
= 0, right_padded
= 0;
21005 int font_not_found_p
;
21006 struct font_info
*font_info
;
21009 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21010 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21012 if (glyph_len
< cmp
->glyph_len
)
21014 for (i
= 0; i
< glyph_len
; i
++)
21016 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21018 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21023 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21024 : IT_CHARPOS (*it
));
21025 /* When no suitable font found, use the default font. */
21026 font_not_found_p
= font
== NULL
;
21027 if (font_not_found_p
)
21029 face
= face
->ascii_face
;
21032 font_info
= FONT_INFO_FROM_FACE (it
->f
, face
);
21033 boff
= font_info
->baseline_offset
;
21034 if (font_info
->vertical_centering
)
21035 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21036 font_ascent
= FONT_BASE (font
) + boff
;
21037 font_descent
= FONT_DESCENT (font
) - boff
;
21038 font_height
= FONT_HEIGHT (font
);
21040 cmp
->font
= (void *) font
;
21043 if (! font_not_found_p
)
21045 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21046 &char2b
, it
->multibyte_p
, 0);
21047 pcm
= get_per_char_metric (font
, font_info
, &char2b
,
21048 FONT_TYPE_FOR_MULTIBYTE (font
, c
));
21051 /* Initialize the bounding box. */
21054 width
= pcm
->width
;
21055 ascent
= pcm
->ascent
;
21056 descent
= pcm
->descent
;
21057 lbearing
= pcm
->lbearing
;
21058 rbearing
= pcm
->rbearing
;
21062 width
= FONT_WIDTH (font
);
21063 ascent
= FONT_BASE (font
);
21064 descent
= FONT_DESCENT (font
);
21071 lowest
= - descent
+ boff
;
21072 highest
= ascent
+ boff
;
21074 if (! font_not_found_p
21075 && font_info
->default_ascent
21076 && CHAR_TABLE_P (Vuse_default_ascent
)
21077 && !NILP (Faref (Vuse_default_ascent
,
21078 make_number (it
->char_to_display
))))
21079 highest
= font_info
->default_ascent
+ boff
;
21081 /* Draw the first glyph at the normal position. It may be
21082 shifted to right later if some other glyphs are drawn
21084 cmp
->offsets
[i
* 2] = 0;
21085 cmp
->offsets
[i
* 2 + 1] = boff
;
21086 cmp
->lbearing
= lbearing
;
21087 cmp
->rbearing
= rbearing
;
21089 /* Set cmp->offsets for the remaining glyphs. */
21090 for (i
++; i
< glyph_len
; i
++)
21092 int left
, right
, btm
, top
;
21093 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21095 struct face
*this_face
;
21100 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21101 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21102 font
= this_face
->font
;
21108 font_info
= FONT_INFO_FROM_FACE (it
->f
, this_face
);
21109 this_boff
= font_info
->baseline_offset
;
21110 if (font_info
->vertical_centering
)
21111 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21112 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21113 &char2b
, it
->multibyte_p
, 0);
21114 pcm
= get_per_char_metric (font
, font_info
, &char2b
,
21115 FONT_TYPE_FOR_MULTIBYTE (font
,
21119 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21122 width
= pcm
->width
;
21123 ascent
= pcm
->ascent
;
21124 descent
= pcm
->descent
;
21125 lbearing
= pcm
->lbearing
;
21126 rbearing
= pcm
->rbearing
;
21127 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21129 /* Relative composition with or without
21130 alternate chars. */
21131 left
= (leftmost
+ rightmost
- width
) / 2;
21132 btm
= - descent
+ boff
;
21133 if (font_info
->relative_compose
21134 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21135 || NILP (Faref (Vignore_relative_composition
,
21136 make_number (ch
)))))
21139 if (- descent
>= font_info
->relative_compose
)
21140 /* One extra pixel between two glyphs. */
21142 else if (ascent
<= 0)
21143 /* One extra pixel between two glyphs. */
21144 btm
= lowest
- 1 - ascent
- descent
;
21149 /* A composition rule is specified by an integer
21150 value that encodes global and new reference
21151 points (GREF and NREF). GREF and NREF are
21152 specified by numbers as below:
21154 0---1---2 -- ascent
21158 9--10--11 -- center
21160 ---3---4---5--- baseline
21162 6---7---8 -- descent
21164 int rule
= COMPOSITION_RULE (cmp
, i
);
21165 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21167 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21168 grefx
= gref
% 3, nrefx
= nref
% 3;
21169 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21171 xoff
= font_height
* (xoff
- 128) / 256;
21173 yoff
= font_height
* (yoff
- 128) / 256;
21176 + grefx
* (rightmost
- leftmost
) / 2
21177 - nrefx
* width
/ 2
21180 btm
= ((grefy
== 0 ? highest
21182 : grefy
== 2 ? lowest
21183 : (highest
+ lowest
) / 2)
21184 - (nrefy
== 0 ? ascent
+ descent
21185 : nrefy
== 1 ? descent
- boff
21187 : (ascent
+ descent
) / 2)
21191 cmp
->offsets
[i
* 2] = left
;
21192 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21194 /* Update the bounding box of the overall glyphs. */
21197 right
= left
+ width
;
21198 if (left
< leftmost
)
21200 if (right
> rightmost
)
21203 top
= btm
+ descent
+ ascent
;
21209 if (cmp
->lbearing
> left
+ lbearing
)
21210 cmp
->lbearing
= left
+ lbearing
;
21211 if (cmp
->rbearing
< left
+ rbearing
)
21212 cmp
->rbearing
= left
+ rbearing
;
21216 /* If there are glyphs whose x-offsets are negative,
21217 shift all glyphs to the right and make all x-offsets
21221 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21222 cmp
->offsets
[i
* 2] -= leftmost
;
21223 rightmost
-= leftmost
;
21224 cmp
->lbearing
-= leftmost
;
21225 cmp
->rbearing
-= leftmost
;
21228 if (left_padded
&& cmp
->lbearing
< 0)
21230 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21231 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21232 rightmost
-= cmp
->lbearing
;
21233 cmp
->rbearing
-= cmp
->lbearing
;
21236 if (right_padded
&& rightmost
< cmp
->rbearing
)
21238 rightmost
= cmp
->rbearing
;
21241 cmp
->pixel_width
= rightmost
;
21242 cmp
->ascent
= highest
;
21243 cmp
->descent
= - lowest
;
21244 if (cmp
->ascent
< font_ascent
)
21245 cmp
->ascent
= font_ascent
;
21246 if (cmp
->descent
< font_descent
)
21247 cmp
->descent
= font_descent
;
21251 && (cmp
->lbearing
< 0
21252 || cmp
->rbearing
> cmp
->pixel_width
))
21253 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21255 it
->pixel_width
= cmp
->pixel_width
;
21256 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21257 it
->descent
= it
->phys_descent
= cmp
->descent
;
21259 if (face
->box
!= FACE_NO_BOX
)
21261 int thick
= face
->box_line_width
;
21265 it
->ascent
+= thick
;
21266 it
->descent
+= thick
;
21271 if (it
->start_of_box_run_p
)
21272 it
->pixel_width
+= thick
;
21273 if (it
->end_of_box_run_p
)
21274 it
->pixel_width
+= thick
;
21277 /* If face has an overline, add the height of the overline
21278 (1 pixel) and a 1 pixel margin to the character height. */
21279 if (face
->overline_p
)
21280 it
->ascent
+= overline_margin
;
21282 take_vertical_position_into_account (it
);
21285 append_composite_glyph (it
);
21287 else if (it
->what
== IT_IMAGE
)
21288 produce_image_glyph (it
);
21289 else if (it
->what
== IT_STRETCH
)
21290 produce_stretch_glyph (it
);
21292 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21293 because this isn't true for images with `:ascent 100'. */
21294 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21295 if (it
->area
== TEXT_AREA
)
21296 it
->current_x
+= it
->pixel_width
;
21298 if (extra_line_spacing
> 0)
21300 it
->descent
+= extra_line_spacing
;
21301 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21302 it
->max_extra_line_spacing
= extra_line_spacing
;
21305 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21306 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21307 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21308 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21312 Output LEN glyphs starting at START at the nominal cursor position.
21313 Advance the nominal cursor over the text. The global variable
21314 updated_window contains the window being updated, updated_row is
21315 the glyph row being updated, and updated_area is the area of that
21316 row being updated. */
21319 x_write_glyphs (start
, len
)
21320 struct glyph
*start
;
21325 xassert (updated_window
&& updated_row
);
21328 /* Write glyphs. */
21330 hpos
= start
- updated_row
->glyphs
[updated_area
];
21331 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21332 updated_row
, updated_area
,
21334 DRAW_NORMAL_TEXT
, 0);
21336 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21337 if (updated_area
== TEXT_AREA
21338 && updated_window
->phys_cursor_on_p
21339 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21340 && updated_window
->phys_cursor
.hpos
>= hpos
21341 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21342 updated_window
->phys_cursor_on_p
= 0;
21346 /* Advance the output cursor. */
21347 output_cursor
.hpos
+= len
;
21348 output_cursor
.x
= x
;
21353 Insert LEN glyphs from START at the nominal cursor position. */
21356 x_insert_glyphs (start
, len
)
21357 struct glyph
*start
;
21362 int line_height
, shift_by_width
, shifted_region_width
;
21363 struct glyph_row
*row
;
21364 struct glyph
*glyph
;
21365 int frame_x
, frame_y
;
21368 xassert (updated_window
&& updated_row
);
21370 w
= updated_window
;
21371 f
= XFRAME (WINDOW_FRAME (w
));
21373 /* Get the height of the line we are in. */
21375 line_height
= row
->height
;
21377 /* Get the width of the glyphs to insert. */
21378 shift_by_width
= 0;
21379 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21380 shift_by_width
+= glyph
->pixel_width
;
21382 /* Get the width of the region to shift right. */
21383 shifted_region_width
= (window_box_width (w
, updated_area
)
21388 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21389 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21391 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21392 line_height
, shift_by_width
);
21394 /* Write the glyphs. */
21395 hpos
= start
- row
->glyphs
[updated_area
];
21396 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21398 DRAW_NORMAL_TEXT
, 0);
21400 /* Advance the output cursor. */
21401 output_cursor
.hpos
+= len
;
21402 output_cursor
.x
+= shift_by_width
;
21408 Erase the current text line from the nominal cursor position
21409 (inclusive) to pixel column TO_X (exclusive). The idea is that
21410 everything from TO_X onward is already erased.
21412 TO_X is a pixel position relative to updated_area of
21413 updated_window. TO_X == -1 means clear to the end of this area. */
21416 x_clear_end_of_line (to_x
)
21420 struct window
*w
= updated_window
;
21421 int max_x
, min_y
, max_y
;
21422 int from_x
, from_y
, to_y
;
21424 xassert (updated_window
&& updated_row
);
21425 f
= XFRAME (w
->frame
);
21427 if (updated_row
->full_width_p
)
21428 max_x
= WINDOW_TOTAL_WIDTH (w
);
21430 max_x
= window_box_width (w
, updated_area
);
21431 max_y
= window_text_bottom_y (w
);
21433 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21434 of window. For TO_X > 0, truncate to end of drawing area. */
21440 to_x
= min (to_x
, max_x
);
21442 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21444 /* Notice if the cursor will be cleared by this operation. */
21445 if (!updated_row
->full_width_p
)
21446 notice_overwritten_cursor (w
, updated_area
,
21447 output_cursor
.x
, -1,
21449 MATRIX_ROW_BOTTOM_Y (updated_row
));
21451 from_x
= output_cursor
.x
;
21453 /* Translate to frame coordinates. */
21454 if (updated_row
->full_width_p
)
21456 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21457 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21461 int area_left
= window_box_left (w
, updated_area
);
21462 from_x
+= area_left
;
21466 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21467 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21468 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21470 /* Prevent inadvertently clearing to end of the X window. */
21471 if (to_x
> from_x
&& to_y
> from_y
)
21474 rif
->clear_frame_area (f
, from_x
, from_y
,
21475 to_x
- from_x
, to_y
- from_y
);
21480 #endif /* HAVE_WINDOW_SYSTEM */
21484 /***********************************************************************
21486 ***********************************************************************/
21488 /* Value is the internal representation of the specified cursor type
21489 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21490 of the bar cursor. */
21492 static enum text_cursor_kinds
21493 get_specified_cursor_type (arg
, width
)
21497 enum text_cursor_kinds type
;
21502 if (EQ (arg
, Qbox
))
21503 return FILLED_BOX_CURSOR
;
21505 if (EQ (arg
, Qhollow
))
21506 return HOLLOW_BOX_CURSOR
;
21508 if (EQ (arg
, Qbar
))
21515 && EQ (XCAR (arg
), Qbar
)
21516 && INTEGERP (XCDR (arg
))
21517 && XINT (XCDR (arg
)) >= 0)
21519 *width
= XINT (XCDR (arg
));
21523 if (EQ (arg
, Qhbar
))
21526 return HBAR_CURSOR
;
21530 && EQ (XCAR (arg
), Qhbar
)
21531 && INTEGERP (XCDR (arg
))
21532 && XINT (XCDR (arg
)) >= 0)
21534 *width
= XINT (XCDR (arg
));
21535 return HBAR_CURSOR
;
21538 /* Treat anything unknown as "hollow box cursor".
21539 It was bad to signal an error; people have trouble fixing
21540 .Xdefaults with Emacs, when it has something bad in it. */
21541 type
= HOLLOW_BOX_CURSOR
;
21546 /* Set the default cursor types for specified frame. */
21548 set_frame_cursor_types (f
, arg
)
21555 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
21556 FRAME_CURSOR_WIDTH (f
) = width
;
21558 /* By default, set up the blink-off state depending on the on-state. */
21560 tem
= Fassoc (arg
, Vblink_cursor_alist
);
21563 FRAME_BLINK_OFF_CURSOR (f
)
21564 = get_specified_cursor_type (XCDR (tem
), &width
);
21565 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
21568 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
21572 /* Return the cursor we want to be displayed in window W. Return
21573 width of bar/hbar cursor through WIDTH arg. Return with
21574 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
21575 (i.e. if the `system caret' should track this cursor).
21577 In a mini-buffer window, we want the cursor only to appear if we
21578 are reading input from this window. For the selected window, we
21579 want the cursor type given by the frame parameter or buffer local
21580 setting of cursor-type. If explicitly marked off, draw no cursor.
21581 In all other cases, we want a hollow box cursor. */
21583 static enum text_cursor_kinds
21584 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
21586 struct glyph
*glyph
;
21588 int *active_cursor
;
21590 struct frame
*f
= XFRAME (w
->frame
);
21591 struct buffer
*b
= XBUFFER (w
->buffer
);
21592 int cursor_type
= DEFAULT_CURSOR
;
21593 Lisp_Object alt_cursor
;
21594 int non_selected
= 0;
21596 *active_cursor
= 1;
21599 if (cursor_in_echo_area
21600 && FRAME_HAS_MINIBUF_P (f
)
21601 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
21603 if (w
== XWINDOW (echo_area_window
))
21605 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
21607 *width
= FRAME_CURSOR_WIDTH (f
);
21608 return FRAME_DESIRED_CURSOR (f
);
21611 return get_specified_cursor_type (b
->cursor_type
, width
);
21614 *active_cursor
= 0;
21618 /* Nonselected window or nonselected frame. */
21619 else if (w
!= XWINDOW (f
->selected_window
)
21620 #ifdef HAVE_WINDOW_SYSTEM
21621 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
21625 *active_cursor
= 0;
21627 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
21633 /* Never display a cursor in a window in which cursor-type is nil. */
21634 if (NILP (b
->cursor_type
))
21637 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
21640 alt_cursor
= b
->cursor_in_non_selected_windows
;
21641 return get_specified_cursor_type (alt_cursor
, width
);
21644 /* Get the normal cursor type for this window. */
21645 if (EQ (b
->cursor_type
, Qt
))
21647 cursor_type
= FRAME_DESIRED_CURSOR (f
);
21648 *width
= FRAME_CURSOR_WIDTH (f
);
21651 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
21653 /* Use normal cursor if not blinked off. */
21654 if (!w
->cursor_off_p
)
21656 #ifdef HAVE_WINDOW_SYSTEM
21657 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21659 if (cursor_type
== FILLED_BOX_CURSOR
)
21661 /* Using a block cursor on large images can be very annoying.
21662 So use a hollow cursor for "large" images.
21663 If image is not transparent (no mask), also use hollow cursor. */
21664 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21665 if (img
!= NULL
&& IMAGEP (img
->spec
))
21667 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
21668 where N = size of default frame font size.
21669 This should cover most of the "tiny" icons people may use. */
21671 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
21672 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
21673 cursor_type
= HOLLOW_BOX_CURSOR
;
21676 else if (cursor_type
!= NO_CURSOR
)
21678 /* Display current only supports BOX and HOLLOW cursors for images.
21679 So for now, unconditionally use a HOLLOW cursor when cursor is
21680 not a solid box cursor. */
21681 cursor_type
= HOLLOW_BOX_CURSOR
;
21685 return cursor_type
;
21688 /* Cursor is blinked off, so determine how to "toggle" it. */
21690 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
21691 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
21692 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
21694 /* Then see if frame has specified a specific blink off cursor type. */
21695 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
21697 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
21698 return FRAME_BLINK_OFF_CURSOR (f
);
21702 /* Some people liked having a permanently visible blinking cursor,
21703 while others had very strong opinions against it. So it was
21704 decided to remove it. KFS 2003-09-03 */
21706 /* Finally perform built-in cursor blinking:
21707 filled box <-> hollow box
21708 wide [h]bar <-> narrow [h]bar
21709 narrow [h]bar <-> no cursor
21710 other type <-> no cursor */
21712 if (cursor_type
== FILLED_BOX_CURSOR
)
21713 return HOLLOW_BOX_CURSOR
;
21715 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
21718 return cursor_type
;
21726 #ifdef HAVE_WINDOW_SYSTEM
21728 /* Notice when the text cursor of window W has been completely
21729 overwritten by a drawing operation that outputs glyphs in AREA
21730 starting at X0 and ending at X1 in the line starting at Y0 and
21731 ending at Y1. X coordinates are area-relative. X1 < 0 means all
21732 the rest of the line after X0 has been written. Y coordinates
21733 are window-relative. */
21736 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
21738 enum glyph_row_area area
;
21739 int x0
, y0
, x1
, y1
;
21741 int cx0
, cx1
, cy0
, cy1
;
21742 struct glyph_row
*row
;
21744 if (!w
->phys_cursor_on_p
)
21746 if (area
!= TEXT_AREA
)
21749 if (w
->phys_cursor
.vpos
< 0
21750 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
21751 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
21752 !(row
->enabled_p
&& row
->displays_text_p
)))
21755 if (row
->cursor_in_fringe_p
)
21757 row
->cursor_in_fringe_p
= 0;
21758 draw_fringe_bitmap (w
, row
, 0);
21759 w
->phys_cursor_on_p
= 0;
21763 cx0
= w
->phys_cursor
.x
;
21764 cx1
= cx0
+ w
->phys_cursor_width
;
21765 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
21768 /* The cursor image will be completely removed from the
21769 screen if the output area intersects the cursor area in
21770 y-direction. When we draw in [y0 y1[, and some part of
21771 the cursor is at y < y0, that part must have been drawn
21772 before. When scrolling, the cursor is erased before
21773 actually scrolling, so we don't come here. When not
21774 scrolling, the rows above the old cursor row must have
21775 changed, and in this case these rows must have written
21776 over the cursor image.
21778 Likewise if part of the cursor is below y1, with the
21779 exception of the cursor being in the first blank row at
21780 the buffer and window end because update_text_area
21781 doesn't draw that row. (Except when it does, but
21782 that's handled in update_text_area.) */
21784 cy0
= w
->phys_cursor
.y
;
21785 cy1
= cy0
+ w
->phys_cursor_height
;
21786 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
21789 w
->phys_cursor_on_p
= 0;
21792 #endif /* HAVE_WINDOW_SYSTEM */
21795 /************************************************************************
21797 ************************************************************************/
21799 #ifdef HAVE_WINDOW_SYSTEM
21802 Fix the display of area AREA of overlapping row ROW in window W
21803 with respect to the overlapping part OVERLAPS. */
21806 x_fix_overlapping_area (w
, row
, area
, overlaps
)
21808 struct glyph_row
*row
;
21809 enum glyph_row_area area
;
21817 for (i
= 0; i
< row
->used
[area
];)
21819 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
21821 int start
= i
, start_x
= x
;
21825 x
+= row
->glyphs
[area
][i
].pixel_width
;
21828 while (i
< row
->used
[area
]
21829 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
21831 draw_glyphs (w
, start_x
, row
, area
,
21833 DRAW_NORMAL_TEXT
, overlaps
);
21837 x
+= row
->glyphs
[area
][i
].pixel_width
;
21847 Draw the cursor glyph of window W in glyph row ROW. See the
21848 comment of draw_glyphs for the meaning of HL. */
21851 draw_phys_cursor_glyph (w
, row
, hl
)
21853 struct glyph_row
*row
;
21854 enum draw_glyphs_face hl
;
21856 /* If cursor hpos is out of bounds, don't draw garbage. This can
21857 happen in mini-buffer windows when switching between echo area
21858 glyphs and mini-buffer. */
21859 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
21861 int on_p
= w
->phys_cursor_on_p
;
21863 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
21864 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
21866 w
->phys_cursor_on_p
= on_p
;
21868 if (hl
== DRAW_CURSOR
)
21869 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21870 /* When we erase the cursor, and ROW is overlapped by other
21871 rows, make sure that these overlapping parts of other rows
21873 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
21875 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
21877 if (row
> w
->current_matrix
->rows
21878 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
21879 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
21880 OVERLAPS_ERASED_CURSOR
);
21882 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
21883 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
21884 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
21885 OVERLAPS_ERASED_CURSOR
);
21892 Erase the image of a cursor of window W from the screen. */
21895 erase_phys_cursor (w
)
21898 struct frame
*f
= XFRAME (w
->frame
);
21899 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21900 int hpos
= w
->phys_cursor
.hpos
;
21901 int vpos
= w
->phys_cursor
.vpos
;
21902 int mouse_face_here_p
= 0;
21903 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
21904 struct glyph_row
*cursor_row
;
21905 struct glyph
*cursor_glyph
;
21906 enum draw_glyphs_face hl
;
21908 /* No cursor displayed or row invalidated => nothing to do on the
21910 if (w
->phys_cursor_type
== NO_CURSOR
)
21911 goto mark_cursor_off
;
21913 /* VPOS >= active_glyphs->nrows means that window has been resized.
21914 Don't bother to erase the cursor. */
21915 if (vpos
>= active_glyphs
->nrows
)
21916 goto mark_cursor_off
;
21918 /* If row containing cursor is marked invalid, there is nothing we
21920 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
21921 if (!cursor_row
->enabled_p
)
21922 goto mark_cursor_off
;
21924 /* If line spacing is > 0, old cursor may only be partially visible in
21925 window after split-window. So adjust visible height. */
21926 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
21927 window_text_bottom_y (w
) - cursor_row
->y
);
21929 /* If row is completely invisible, don't attempt to delete a cursor which
21930 isn't there. This can happen if cursor is at top of a window, and
21931 we switch to a buffer with a header line in that window. */
21932 if (cursor_row
->visible_height
<= 0)
21933 goto mark_cursor_off
;
21935 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
21936 if (cursor_row
->cursor_in_fringe_p
)
21938 cursor_row
->cursor_in_fringe_p
= 0;
21939 draw_fringe_bitmap (w
, cursor_row
, 0);
21940 goto mark_cursor_off
;
21943 /* This can happen when the new row is shorter than the old one.
21944 In this case, either draw_glyphs or clear_end_of_line
21945 should have cleared the cursor. Note that we wouldn't be
21946 able to erase the cursor in this case because we don't have a
21947 cursor glyph at hand. */
21948 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
21949 goto mark_cursor_off
;
21951 /* If the cursor is in the mouse face area, redisplay that when
21952 we clear the cursor. */
21953 if (! NILP (dpyinfo
->mouse_face_window
)
21954 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
21955 && (vpos
> dpyinfo
->mouse_face_beg_row
21956 || (vpos
== dpyinfo
->mouse_face_beg_row
21957 && hpos
>= dpyinfo
->mouse_face_beg_col
))
21958 && (vpos
< dpyinfo
->mouse_face_end_row
21959 || (vpos
== dpyinfo
->mouse_face_end_row
21960 && hpos
< dpyinfo
->mouse_face_end_col
))
21961 /* Don't redraw the cursor's spot in mouse face if it is at the
21962 end of a line (on a newline). The cursor appears there, but
21963 mouse highlighting does not. */
21964 && cursor_row
->used
[TEXT_AREA
] > hpos
)
21965 mouse_face_here_p
= 1;
21967 /* Maybe clear the display under the cursor. */
21968 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
21971 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
21974 cursor_glyph
= get_phys_cursor_glyph (w
);
21975 if (cursor_glyph
== NULL
)
21976 goto mark_cursor_off
;
21978 width
= cursor_glyph
->pixel_width
;
21979 left_x
= window_box_left_offset (w
, TEXT_AREA
);
21980 x
= w
->phys_cursor
.x
;
21982 width
-= left_x
- x
;
21983 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
21984 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
21985 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
21988 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
21991 /* Erase the cursor by redrawing the character underneath it. */
21992 if (mouse_face_here_p
)
21993 hl
= DRAW_MOUSE_FACE
;
21995 hl
= DRAW_NORMAL_TEXT
;
21996 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
21999 w
->phys_cursor_on_p
= 0;
22000 w
->phys_cursor_type
= NO_CURSOR
;
22005 Display or clear cursor of window W. If ON is zero, clear the
22006 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22007 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22010 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22012 int on
, hpos
, vpos
, x
, y
;
22014 struct frame
*f
= XFRAME (w
->frame
);
22015 int new_cursor_type
;
22016 int new_cursor_width
;
22018 struct glyph_row
*glyph_row
;
22019 struct glyph
*glyph
;
22021 /* This is pointless on invisible frames, and dangerous on garbaged
22022 windows and frames; in the latter case, the frame or window may
22023 be in the midst of changing its size, and x and y may be off the
22025 if (! FRAME_VISIBLE_P (f
)
22026 || FRAME_GARBAGED_P (f
)
22027 || vpos
>= w
->current_matrix
->nrows
22028 || hpos
>= w
->current_matrix
->matrix_w
)
22031 /* If cursor is off and we want it off, return quickly. */
22032 if (!on
&& !w
->phys_cursor_on_p
)
22035 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22036 /* If cursor row is not enabled, we don't really know where to
22037 display the cursor. */
22038 if (!glyph_row
->enabled_p
)
22040 w
->phys_cursor_on_p
= 0;
22045 if (!glyph_row
->exact_window_width_line_p
22046 || hpos
< glyph_row
->used
[TEXT_AREA
])
22047 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22049 xassert (interrupt_input_blocked
);
22051 /* Set new_cursor_type to the cursor we want to be displayed. */
22052 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22053 &new_cursor_width
, &active_cursor
);
22055 /* If cursor is currently being shown and we don't want it to be or
22056 it is in the wrong place, or the cursor type is not what we want,
22058 if (w
->phys_cursor_on_p
22060 || w
->phys_cursor
.x
!= x
22061 || w
->phys_cursor
.y
!= y
22062 || new_cursor_type
!= w
->phys_cursor_type
22063 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22064 && new_cursor_width
!= w
->phys_cursor_width
)))
22065 erase_phys_cursor (w
);
22067 /* Don't check phys_cursor_on_p here because that flag is only set
22068 to zero in some cases where we know that the cursor has been
22069 completely erased, to avoid the extra work of erasing the cursor
22070 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22071 still not be visible, or it has only been partly erased. */
22074 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22075 w
->phys_cursor_height
= glyph_row
->height
;
22077 /* Set phys_cursor_.* before x_draw_.* is called because some
22078 of them may need the information. */
22079 w
->phys_cursor
.x
= x
;
22080 w
->phys_cursor
.y
= glyph_row
->y
;
22081 w
->phys_cursor
.hpos
= hpos
;
22082 w
->phys_cursor
.vpos
= vpos
;
22085 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
22086 new_cursor_type
, new_cursor_width
,
22087 on
, active_cursor
);
22091 /* Switch the display of W's cursor on or off, according to the value
22095 update_window_cursor (w
, on
)
22099 /* Don't update cursor in windows whose frame is in the process
22100 of being deleted. */
22101 if (w
->current_matrix
)
22104 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22105 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22111 /* Call update_window_cursor with parameter ON_P on all leaf windows
22112 in the window tree rooted at W. */
22115 update_cursor_in_window_tree (w
, on_p
)
22121 if (!NILP (w
->hchild
))
22122 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22123 else if (!NILP (w
->vchild
))
22124 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22126 update_window_cursor (w
, on_p
);
22128 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22134 Display the cursor on window W, or clear it, according to ON_P.
22135 Don't change the cursor's position. */
22138 x_update_cursor (f
, on_p
)
22142 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22147 Clear the cursor of window W to background color, and mark the
22148 cursor as not shown. This is used when the text where the cursor
22149 is is about to be rewritten. */
22155 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22156 update_window_cursor (w
, 0);
22161 Display the active region described by mouse_face_* according to DRAW. */
22164 show_mouse_face (dpyinfo
, draw
)
22165 Display_Info
*dpyinfo
;
22166 enum draw_glyphs_face draw
;
22168 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22169 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22171 if (/* If window is in the process of being destroyed, don't bother
22173 w
->current_matrix
!= NULL
22174 /* Don't update mouse highlight if hidden */
22175 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22176 /* Recognize when we are called to operate on rows that don't exist
22177 anymore. This can happen when a window is split. */
22178 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22180 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22181 struct glyph_row
*row
, *first
, *last
;
22183 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22184 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22186 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22188 int start_hpos
, end_hpos
, start_x
;
22190 /* For all but the first row, the highlight starts at column 0. */
22193 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22194 start_x
= dpyinfo
->mouse_face_beg_x
;
22203 end_hpos
= dpyinfo
->mouse_face_end_col
;
22206 end_hpos
= row
->used
[TEXT_AREA
];
22207 if (draw
== DRAW_NORMAL_TEXT
)
22208 row
->fill_line_p
= 1; /* Clear to end of line */
22211 if (end_hpos
> start_hpos
)
22213 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22214 start_hpos
, end_hpos
,
22218 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22222 /* When we've written over the cursor, arrange for it to
22223 be displayed again. */
22224 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22227 display_and_set_cursor (w
, 1,
22228 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22229 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22234 /* Change the mouse cursor. */
22235 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22236 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22237 else if (draw
== DRAW_MOUSE_FACE
)
22238 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22240 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22244 Clear out the mouse-highlighted active region.
22245 Redraw it un-highlighted first. Value is non-zero if mouse
22246 face was actually drawn unhighlighted. */
22249 clear_mouse_face (dpyinfo
)
22250 Display_Info
*dpyinfo
;
22254 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22256 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22260 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22261 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22262 dpyinfo
->mouse_face_window
= Qnil
;
22263 dpyinfo
->mouse_face_overlay
= Qnil
;
22269 Non-zero if physical cursor of window W is within mouse face. */
22272 cursor_in_mouse_face_p (w
)
22275 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22276 int in_mouse_face
= 0;
22278 if (WINDOWP (dpyinfo
->mouse_face_window
)
22279 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22281 int hpos
= w
->phys_cursor
.hpos
;
22282 int vpos
= w
->phys_cursor
.vpos
;
22284 if (vpos
>= dpyinfo
->mouse_face_beg_row
22285 && vpos
<= dpyinfo
->mouse_face_end_row
22286 && (vpos
> dpyinfo
->mouse_face_beg_row
22287 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22288 && (vpos
< dpyinfo
->mouse_face_end_row
22289 || hpos
< dpyinfo
->mouse_face_end_col
22290 || dpyinfo
->mouse_face_past_end
))
22294 return in_mouse_face
;
22300 /* Find the glyph matrix position of buffer position CHARPOS in window
22301 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
22302 current glyphs must be up to date. If CHARPOS is above window
22303 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22304 of last line in W. In the row containing CHARPOS, stop before glyphs
22305 having STOP as object. */
22307 #if 1 /* This is a version of fast_find_position that's more correct
22308 in the presence of hscrolling, for example. I didn't install
22309 it right away because the problem fixed is minor, it failed
22310 in 20.x as well, and I think it's too risky to install
22311 so near the release of 21.1. 2001-09-25 gerd. */
22314 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22317 int *hpos
, *vpos
, *x
, *y
;
22320 struct glyph_row
*row
, *first
;
22321 struct glyph
*glyph
, *end
;
22324 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22325 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22330 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22334 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22337 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22341 /* If whole rows or last part of a row came from a display overlay,
22342 row_containing_pos will skip over such rows because their end pos
22343 equals the start pos of the overlay or interval.
22345 Move back if we have a STOP object and previous row's
22346 end glyph came from STOP. */
22349 struct glyph_row
*prev
;
22350 while ((prev
= row
- 1, prev
>= first
)
22351 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22352 && prev
->used
[TEXT_AREA
] > 0)
22354 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22355 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22356 while (--glyph
>= beg
22357 && INTEGERP (glyph
->object
));
22359 || !EQ (stop
, glyph
->object
))
22367 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22369 glyph
= row
->glyphs
[TEXT_AREA
];
22370 end
= glyph
+ row
->used
[TEXT_AREA
];
22372 /* Skip over glyphs not having an object at the start of the row.
22373 These are special glyphs like truncation marks on terminal
22375 if (row
->displays_text_p
)
22377 && INTEGERP (glyph
->object
)
22378 && !EQ (stop
, glyph
->object
)
22379 && glyph
->charpos
< 0)
22381 *x
+= glyph
->pixel_width
;
22386 && !INTEGERP (glyph
->object
)
22387 && !EQ (stop
, glyph
->object
)
22388 && (!BUFFERP (glyph
->object
)
22389 || glyph
->charpos
< charpos
))
22391 *x
+= glyph
->pixel_width
;
22395 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22402 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22405 int *hpos
, *vpos
, *x
, *y
;
22410 int maybe_next_line_p
= 0;
22411 int line_start_position
;
22412 int yb
= window_text_bottom_y (w
);
22413 struct glyph_row
*row
, *best_row
;
22414 int row_vpos
, best_row_vpos
;
22417 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22418 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22420 while (row
->y
< yb
)
22422 if (row
->used
[TEXT_AREA
])
22423 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22425 line_start_position
= 0;
22427 if (line_start_position
> pos
)
22429 /* If the position sought is the end of the buffer,
22430 don't include the blank lines at the bottom of the window. */
22431 else if (line_start_position
== pos
22432 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22434 maybe_next_line_p
= 1;
22437 else if (line_start_position
> 0)
22440 best_row_vpos
= row_vpos
;
22443 if (row
->y
+ row
->height
>= yb
)
22450 /* Find the right column within BEST_ROW. */
22452 current_x
= best_row
->x
;
22453 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22455 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22456 int charpos
= glyph
->charpos
;
22458 if (BUFFERP (glyph
->object
))
22460 if (charpos
== pos
)
22463 *vpos
= best_row_vpos
;
22468 else if (charpos
> pos
)
22471 else if (EQ (glyph
->object
, stop
))
22476 current_x
+= glyph
->pixel_width
;
22479 /* If we're looking for the end of the buffer,
22480 and we didn't find it in the line we scanned,
22481 use the start of the following line. */
22482 if (maybe_next_line_p
)
22487 current_x
= best_row
->x
;
22490 *vpos
= best_row_vpos
;
22491 *hpos
= lastcol
+ 1;
22500 /* Find the position of the glyph for position POS in OBJECT in
22501 window W's current matrix, and return in *X, *Y the pixel
22502 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22504 RIGHT_P non-zero means return the position of the right edge of the
22505 glyph, RIGHT_P zero means return the left edge position.
22507 If no glyph for POS exists in the matrix, return the position of
22508 the glyph with the next smaller position that is in the matrix, if
22509 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
22510 exists in the matrix, return the position of the glyph with the
22511 next larger position in OBJECT.
22513 Value is non-zero if a glyph was found. */
22516 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
22519 Lisp_Object object
;
22520 int *hpos
, *vpos
, *x
, *y
;
22523 int yb
= window_text_bottom_y (w
);
22524 struct glyph_row
*r
;
22525 struct glyph
*best_glyph
= NULL
;
22526 struct glyph_row
*best_row
= NULL
;
22529 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22530 r
->enabled_p
&& r
->y
< yb
;
22533 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
22534 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
22537 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
22538 if (EQ (g
->object
, object
))
22540 if (g
->charpos
== pos
)
22547 else if (best_glyph
== NULL
22548 || ((abs (g
->charpos
- pos
)
22549 < abs (best_glyph
->charpos
- pos
))
22552 : g
->charpos
> pos
)))
22566 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
22570 *x
+= best_glyph
->pixel_width
;
22575 *vpos
= best_row
- w
->current_matrix
->rows
;
22578 return best_glyph
!= NULL
;
22582 /* See if position X, Y is within a hot-spot of an image. */
22585 on_hot_spot_p (hot_spot
, x
, y
)
22586 Lisp_Object hot_spot
;
22589 if (!CONSP (hot_spot
))
22592 if (EQ (XCAR (hot_spot
), Qrect
))
22594 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
22595 Lisp_Object rect
= XCDR (hot_spot
);
22599 if (!CONSP (XCAR (rect
)))
22601 if (!CONSP (XCDR (rect
)))
22603 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
22605 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
22607 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
22609 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
22613 else if (EQ (XCAR (hot_spot
), Qcircle
))
22615 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
22616 Lisp_Object circ
= XCDR (hot_spot
);
22617 Lisp_Object lr
, lx0
, ly0
;
22619 && CONSP (XCAR (circ
))
22620 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
22621 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
22622 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
22624 double r
= XFLOATINT (lr
);
22625 double dx
= XINT (lx0
) - x
;
22626 double dy
= XINT (ly0
) - y
;
22627 return (dx
* dx
+ dy
* dy
<= r
* r
);
22630 else if (EQ (XCAR (hot_spot
), Qpoly
))
22632 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
22633 if (VECTORP (XCDR (hot_spot
)))
22635 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
22636 Lisp_Object
*poly
= v
->contents
;
22640 Lisp_Object lx
, ly
;
22643 /* Need an even number of coordinates, and at least 3 edges. */
22644 if (n
< 6 || n
& 1)
22647 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
22648 If count is odd, we are inside polygon. Pixels on edges
22649 may or may not be included depending on actual geometry of the
22651 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
22652 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
22654 x0
= XINT (lx
), y0
= XINT (ly
);
22655 for (i
= 0; i
< n
; i
+= 2)
22657 int x1
= x0
, y1
= y0
;
22658 if ((lx
= poly
[i
], !INTEGERP (lx
))
22659 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
22661 x0
= XINT (lx
), y0
= XINT (ly
);
22663 /* Does this segment cross the X line? */
22671 if (y
> y0
&& y
> y1
)
22673 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
22679 /* If we don't understand the format, pretend we're not in the hot-spot. */
22684 find_hot_spot (map
, x
, y
)
22688 while (CONSP (map
))
22690 if (CONSP (XCAR (map
))
22691 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
22699 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
22701 doc
: /* Lookup in image map MAP coordinates X and Y.
22702 An image map is an alist where each element has the format (AREA ID PLIST).
22703 An AREA is specified as either a rectangle, a circle, or a polygon:
22704 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
22705 pixel coordinates of the upper left and bottom right corners.
22706 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
22707 and the radius of the circle; r may be a float or integer.
22708 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
22709 vector describes one corner in the polygon.
22710 Returns the alist element for the first matching AREA in MAP. */)
22721 return find_hot_spot (map
, XINT (x
), XINT (y
));
22725 /* Display frame CURSOR, optionally using shape defined by POINTER. */
22727 define_frame_cursor1 (f
, cursor
, pointer
)
22730 Lisp_Object pointer
;
22732 /* Do not change cursor shape while dragging mouse. */
22733 if (!NILP (do_mouse_tracking
))
22736 if (!NILP (pointer
))
22738 if (EQ (pointer
, Qarrow
))
22739 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22740 else if (EQ (pointer
, Qhand
))
22741 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
22742 else if (EQ (pointer
, Qtext
))
22743 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
22744 else if (EQ (pointer
, intern ("hdrag")))
22745 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
22746 #ifdef HAVE_X_WINDOWS
22747 else if (EQ (pointer
, intern ("vdrag")))
22748 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
22750 else if (EQ (pointer
, intern ("hourglass")))
22751 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
22752 else if (EQ (pointer
, Qmodeline
))
22753 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
22755 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22758 if (cursor
!= No_Cursor
)
22759 rif
->define_frame_cursor (f
, cursor
);
22762 /* Take proper action when mouse has moved to the mode or header line
22763 or marginal area AREA of window W, x-position X and y-position Y.
22764 X is relative to the start of the text display area of W, so the
22765 width of bitmap areas and scroll bars must be subtracted to get a
22766 position relative to the start of the mode line. */
22769 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
22770 Lisp_Object window
;
22772 enum window_part area
;
22774 struct window
*w
= XWINDOW (window
);
22775 struct frame
*f
= XFRAME (w
->frame
);
22776 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22777 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
22778 Lisp_Object pointer
= Qnil
;
22779 int charpos
, dx
, dy
, width
, height
;
22780 Lisp_Object string
, object
= Qnil
;
22781 Lisp_Object pos
, help
;
22783 Lisp_Object mouse_face
;
22784 int original_x_pixel
= x
;
22785 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
22786 struct glyph_row
*row
;
22788 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
22793 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
22794 &object
, &dx
, &dy
, &width
, &height
);
22796 row
= (area
== ON_MODE_LINE
22797 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
22798 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
22801 if (row
->mode_line_p
&& row
->enabled_p
)
22803 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
22804 end
= glyph
+ row
->used
[TEXT_AREA
];
22806 for (x0
= original_x_pixel
;
22807 glyph
< end
&& x0
>= glyph
->pixel_width
;
22809 x0
-= glyph
->pixel_width
;
22817 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
22818 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
22819 &object
, &dx
, &dy
, &width
, &height
);
22824 if (IMAGEP (object
))
22826 Lisp_Object image_map
, hotspot
;
22827 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
22829 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
22831 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
22833 Lisp_Object area_id
, plist
;
22835 area_id
= XCAR (hotspot
);
22836 /* Could check AREA_ID to see if we enter/leave this hot-spot.
22837 If so, we could look for mouse-enter, mouse-leave
22838 properties in PLIST (and do something...). */
22839 hotspot
= XCDR (hotspot
);
22840 if (CONSP (hotspot
)
22841 && (plist
= XCAR (hotspot
), CONSP (plist
)))
22843 pointer
= Fplist_get (plist
, Qpointer
);
22844 if (NILP (pointer
))
22846 help
= Fplist_get (plist
, Qhelp_echo
);
22849 help_echo_string
= help
;
22850 /* Is this correct? ++kfs */
22851 XSETWINDOW (help_echo_window
, w
);
22852 help_echo_object
= w
->buffer
;
22853 help_echo_pos
= charpos
;
22857 if (NILP (pointer
))
22858 pointer
= Fplist_get (XCDR (object
), QCpointer
);
22861 if (STRINGP (string
))
22863 pos
= make_number (charpos
);
22864 /* If we're on a string with `help-echo' text property, arrange
22865 for the help to be displayed. This is done by setting the
22866 global variable help_echo_string to the help string. */
22869 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
22872 help_echo_string
= help
;
22873 XSETWINDOW (help_echo_window
, w
);
22874 help_echo_object
= string
;
22875 help_echo_pos
= charpos
;
22879 if (NILP (pointer
))
22880 pointer
= Fget_text_property (pos
, Qpointer
, string
);
22882 /* Change the mouse pointer according to what is under X/Y. */
22883 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
22886 map
= Fget_text_property (pos
, Qlocal_map
, string
);
22887 if (!KEYMAPP (map
))
22888 map
= Fget_text_property (pos
, Qkeymap
, string
);
22889 if (!KEYMAPP (map
))
22890 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
22893 /* Change the mouse face according to what is under X/Y. */
22894 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
22895 if (!NILP (mouse_face
)
22896 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22901 struct glyph
* tmp_glyph
;
22905 int total_pixel_width
;
22910 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
22911 Qmouse_face
, string
, Qnil
);
22913 b
= make_number (0);
22915 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
22917 e
= make_number (SCHARS (string
));
22919 /* Calculate the position(glyph position: GPOS) of GLYPH in
22920 displayed string. GPOS is different from CHARPOS.
22922 CHARPOS is the position of glyph in internal string
22923 object. A mode line string format has structures which
22924 is converted to a flatten by emacs lisp interpreter.
22925 The internal string is an element of the structures.
22926 The displayed string is the flatten string. */
22928 if (glyph
> row_start_glyph
)
22930 tmp_glyph
= glyph
- 1;
22931 while (tmp_glyph
>= row_start_glyph
22932 && tmp_glyph
->charpos
>= XINT (b
)
22933 && EQ (tmp_glyph
->object
, glyph
->object
))
22940 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
22941 displayed string holding GLYPH.
22943 GSEQ_LENGTH is different from SCHARS (STRING).
22944 SCHARS (STRING) returns the length of the internal string. */
22945 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
22946 tmp_glyph
->charpos
< XINT (e
);
22947 tmp_glyph
++, gseq_length
++)
22949 if (!EQ (tmp_glyph
->object
, glyph
->object
))
22953 total_pixel_width
= 0;
22954 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
22955 total_pixel_width
+= tmp_glyph
->pixel_width
;
22957 /* Pre calculation of re-rendering position */
22959 hpos
= (area
== ON_MODE_LINE
22960 ? (w
->current_matrix
)->nrows
- 1
22963 /* If the re-rendering position is included in the last
22964 re-rendering area, we should do nothing. */
22965 if ( EQ (window
, dpyinfo
->mouse_face_window
)
22966 && dpyinfo
->mouse_face_beg_col
<= vpos
22967 && vpos
< dpyinfo
->mouse_face_end_col
22968 && dpyinfo
->mouse_face_beg_row
== hpos
)
22971 if (clear_mouse_face (dpyinfo
))
22972 cursor
= No_Cursor
;
22974 dpyinfo
->mouse_face_beg_col
= vpos
;
22975 dpyinfo
->mouse_face_beg_row
= hpos
;
22977 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
22978 dpyinfo
->mouse_face_beg_y
= 0;
22980 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
22981 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
22983 dpyinfo
->mouse_face_end_x
= 0;
22984 dpyinfo
->mouse_face_end_y
= 0;
22986 dpyinfo
->mouse_face_past_end
= 0;
22987 dpyinfo
->mouse_face_window
= window
;
22989 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
22992 glyph
->face_id
, 1);
22993 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22995 if (NILP (pointer
))
22998 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
22999 clear_mouse_face (dpyinfo
);
23001 define_frame_cursor1 (f
, cursor
, pointer
);
23006 Take proper action when the mouse has moved to position X, Y on
23007 frame F as regards highlighting characters that have mouse-face
23008 properties. Also de-highlighting chars where the mouse was before.
23009 X and Y can be negative or out of range. */
23012 note_mouse_highlight (f
, x
, y
)
23016 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23017 enum window_part part
;
23018 Lisp_Object window
;
23020 Cursor cursor
= No_Cursor
;
23021 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23024 /* When a menu is active, don't highlight because this looks odd. */
23025 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (MAC_OS)
23026 if (popup_activated ())
23030 if (NILP (Vmouse_highlight
)
23031 || !f
->glyphs_initialized_p
)
23034 dpyinfo
->mouse_face_mouse_x
= x
;
23035 dpyinfo
->mouse_face_mouse_y
= y
;
23036 dpyinfo
->mouse_face_mouse_frame
= f
;
23038 if (dpyinfo
->mouse_face_defer
)
23041 if (gc_in_progress
)
23043 dpyinfo
->mouse_face_deferred_gc
= 1;
23047 /* Which window is that in? */
23048 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23050 /* If we were displaying active text in another window, clear that.
23051 Also clear if we move out of text area in same window. */
23052 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23053 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23054 && !NILP (dpyinfo
->mouse_face_window
)))
23055 clear_mouse_face (dpyinfo
);
23057 /* Not on a window -> return. */
23058 if (!WINDOWP (window
))
23061 /* Reset help_echo_string. It will get recomputed below. */
23062 help_echo_string
= Qnil
;
23064 /* Convert to window-relative pixel coordinates. */
23065 w
= XWINDOW (window
);
23066 frame_to_window_pixel_xy (w
, &x
, &y
);
23068 /* Handle tool-bar window differently since it doesn't display a
23070 if (EQ (window
, f
->tool_bar_window
))
23072 note_tool_bar_highlight (f
, x
, y
);
23076 /* Mouse is on the mode, header line or margin? */
23077 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23078 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23080 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23084 if (part
== ON_VERTICAL_BORDER
)
23086 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23087 help_echo_string
= build_string ("drag-mouse-1: resize");
23089 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23090 || part
== ON_SCROLL_BAR
)
23091 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23093 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23095 /* Are we in a window whose display is up to date?
23096 And verify the buffer's text has not changed. */
23097 b
= XBUFFER (w
->buffer
);
23098 if (part
== ON_TEXT
23099 && EQ (w
->window_end_valid
, w
->buffer
)
23100 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23101 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23103 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23104 struct glyph
*glyph
;
23105 Lisp_Object object
;
23106 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23107 Lisp_Object
*overlay_vec
= NULL
;
23109 struct buffer
*obuf
;
23110 int obegv
, ozv
, same_region
;
23112 /* Find the glyph under X/Y. */
23113 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23115 /* Look for :pointer property on image. */
23116 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23118 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23119 if (img
!= NULL
&& IMAGEP (img
->spec
))
23121 Lisp_Object image_map
, hotspot
;
23122 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23124 && (hotspot
= find_hot_spot (image_map
,
23125 glyph
->slice
.x
+ dx
,
23126 glyph
->slice
.y
+ dy
),
23128 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23130 Lisp_Object area_id
, plist
;
23132 area_id
= XCAR (hotspot
);
23133 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23134 If so, we could look for mouse-enter, mouse-leave
23135 properties in PLIST (and do something...). */
23136 hotspot
= XCDR (hotspot
);
23137 if (CONSP (hotspot
)
23138 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23140 pointer
= Fplist_get (plist
, Qpointer
);
23141 if (NILP (pointer
))
23143 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23144 if (!NILP (help_echo_string
))
23146 help_echo_window
= window
;
23147 help_echo_object
= glyph
->object
;
23148 help_echo_pos
= glyph
->charpos
;
23152 if (NILP (pointer
))
23153 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23157 /* Clear mouse face if X/Y not over text. */
23159 || area
!= TEXT_AREA
23160 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23162 if (clear_mouse_face (dpyinfo
))
23163 cursor
= No_Cursor
;
23164 if (NILP (pointer
))
23166 if (area
!= TEXT_AREA
)
23167 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23169 pointer
= Vvoid_text_area_pointer
;
23174 pos
= glyph
->charpos
;
23175 object
= glyph
->object
;
23176 if (!STRINGP (object
) && !BUFFERP (object
))
23179 /* If we get an out-of-range value, return now; avoid an error. */
23180 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23183 /* Make the window's buffer temporarily current for
23184 overlays_at and compute_char_face. */
23185 obuf
= current_buffer
;
23186 current_buffer
= b
;
23192 /* Is this char mouse-active or does it have help-echo? */
23193 position
= make_number (pos
);
23195 if (BUFFERP (object
))
23197 /* Put all the overlays we want in a vector in overlay_vec. */
23198 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23199 /* Sort overlays into increasing priority order. */
23200 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23205 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23206 && vpos
>= dpyinfo
->mouse_face_beg_row
23207 && vpos
<= dpyinfo
->mouse_face_end_row
23208 && (vpos
> dpyinfo
->mouse_face_beg_row
23209 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23210 && (vpos
< dpyinfo
->mouse_face_end_row
23211 || hpos
< dpyinfo
->mouse_face_end_col
23212 || dpyinfo
->mouse_face_past_end
));
23215 cursor
= No_Cursor
;
23217 /* Check mouse-face highlighting. */
23219 /* If there exists an overlay with mouse-face overlapping
23220 the one we are currently highlighting, we have to
23221 check if we enter the overlapping overlay, and then
23222 highlight only that. */
23223 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23224 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23226 /* Find the highest priority overlay that has a mouse-face
23229 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23231 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23232 if (!NILP (mouse_face
))
23233 overlay
= overlay_vec
[i
];
23236 /* If we're actually highlighting the same overlay as
23237 before, there's no need to do that again. */
23238 if (!NILP (overlay
)
23239 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23240 goto check_help_echo
;
23242 dpyinfo
->mouse_face_overlay
= overlay
;
23244 /* Clear the display of the old active region, if any. */
23245 if (clear_mouse_face (dpyinfo
))
23246 cursor
= No_Cursor
;
23248 /* If no overlay applies, get a text property. */
23249 if (NILP (overlay
))
23250 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23252 /* Handle the overlay case. */
23253 if (!NILP (overlay
))
23255 /* Find the range of text around this char that
23256 should be active. */
23257 Lisp_Object before
, after
;
23260 before
= Foverlay_start (overlay
);
23261 after
= Foverlay_end (overlay
);
23262 /* Record this as the current active region. */
23263 fast_find_position (w
, XFASTINT (before
),
23264 &dpyinfo
->mouse_face_beg_col
,
23265 &dpyinfo
->mouse_face_beg_row
,
23266 &dpyinfo
->mouse_face_beg_x
,
23267 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23269 dpyinfo
->mouse_face_past_end
23270 = !fast_find_position (w
, XFASTINT (after
),
23271 &dpyinfo
->mouse_face_end_col
,
23272 &dpyinfo
->mouse_face_end_row
,
23273 &dpyinfo
->mouse_face_end_x
,
23274 &dpyinfo
->mouse_face_end_y
, Qnil
);
23275 dpyinfo
->mouse_face_window
= window
;
23277 dpyinfo
->mouse_face_face_id
23278 = face_at_buffer_position (w
, pos
, 0, 0,
23280 !dpyinfo
->mouse_face_hidden
);
23282 /* Display it as active. */
23283 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23284 cursor
= No_Cursor
;
23286 /* Handle the text property case. */
23287 else if (!NILP (mouse_face
) && BUFFERP (object
))
23289 /* Find the range of text around this char that
23290 should be active. */
23291 Lisp_Object before
, after
, beginning
, end
;
23294 beginning
= Fmarker_position (w
->start
);
23295 end
= make_number (BUF_Z (XBUFFER (object
))
23296 - XFASTINT (w
->window_end_pos
));
23298 = Fprevious_single_property_change (make_number (pos
+ 1),
23300 object
, beginning
);
23302 = Fnext_single_property_change (position
, Qmouse_face
,
23305 /* Record this as the current active region. */
23306 fast_find_position (w
, XFASTINT (before
),
23307 &dpyinfo
->mouse_face_beg_col
,
23308 &dpyinfo
->mouse_face_beg_row
,
23309 &dpyinfo
->mouse_face_beg_x
,
23310 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23311 dpyinfo
->mouse_face_past_end
23312 = !fast_find_position (w
, XFASTINT (after
),
23313 &dpyinfo
->mouse_face_end_col
,
23314 &dpyinfo
->mouse_face_end_row
,
23315 &dpyinfo
->mouse_face_end_x
,
23316 &dpyinfo
->mouse_face_end_y
, Qnil
);
23317 dpyinfo
->mouse_face_window
= window
;
23319 if (BUFFERP (object
))
23320 dpyinfo
->mouse_face_face_id
23321 = face_at_buffer_position (w
, pos
, 0, 0,
23323 !dpyinfo
->mouse_face_hidden
);
23325 /* Display it as active. */
23326 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23327 cursor
= No_Cursor
;
23329 else if (!NILP (mouse_face
) && STRINGP (object
))
23334 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23337 e
= Fnext_single_property_change (position
, Qmouse_face
,
23340 b
= make_number (0);
23342 e
= make_number (SCHARS (object
) - 1);
23344 fast_find_string_pos (w
, XINT (b
), object
,
23345 &dpyinfo
->mouse_face_beg_col
,
23346 &dpyinfo
->mouse_face_beg_row
,
23347 &dpyinfo
->mouse_face_beg_x
,
23348 &dpyinfo
->mouse_face_beg_y
, 0);
23349 fast_find_string_pos (w
, XINT (e
), object
,
23350 &dpyinfo
->mouse_face_end_col
,
23351 &dpyinfo
->mouse_face_end_row
,
23352 &dpyinfo
->mouse_face_end_x
,
23353 &dpyinfo
->mouse_face_end_y
, 1);
23354 dpyinfo
->mouse_face_past_end
= 0;
23355 dpyinfo
->mouse_face_window
= window
;
23356 dpyinfo
->mouse_face_face_id
23357 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23358 glyph
->face_id
, 1);
23359 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23360 cursor
= No_Cursor
;
23362 else if (STRINGP (object
) && NILP (mouse_face
))
23364 /* A string which doesn't have mouse-face, but
23365 the text ``under'' it might have. */
23366 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23367 int start
= MATRIX_ROW_START_CHARPOS (r
);
23369 pos
= string_buffer_position (w
, object
, start
);
23371 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23375 if (!NILP (mouse_face
) && !NILP (overlay
))
23377 Lisp_Object before
= Foverlay_start (overlay
);
23378 Lisp_Object after
= Foverlay_end (overlay
);
23381 /* Note that we might not be able to find position
23382 BEFORE in the glyph matrix if the overlay is
23383 entirely covered by a `display' property. In
23384 this case, we overshoot. So let's stop in
23385 the glyph matrix before glyphs for OBJECT. */
23386 fast_find_position (w
, XFASTINT (before
),
23387 &dpyinfo
->mouse_face_beg_col
,
23388 &dpyinfo
->mouse_face_beg_row
,
23389 &dpyinfo
->mouse_face_beg_x
,
23390 &dpyinfo
->mouse_face_beg_y
,
23393 dpyinfo
->mouse_face_past_end
23394 = !fast_find_position (w
, XFASTINT (after
),
23395 &dpyinfo
->mouse_face_end_col
,
23396 &dpyinfo
->mouse_face_end_row
,
23397 &dpyinfo
->mouse_face_end_x
,
23398 &dpyinfo
->mouse_face_end_y
,
23400 dpyinfo
->mouse_face_window
= window
;
23401 dpyinfo
->mouse_face_face_id
23402 = face_at_buffer_position (w
, pos
, 0, 0,
23404 !dpyinfo
->mouse_face_hidden
);
23406 /* Display it as active. */
23407 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23408 cursor
= No_Cursor
;
23415 /* Look for a `help-echo' property. */
23416 if (NILP (help_echo_string
)) {
23417 Lisp_Object help
, overlay
;
23419 /* Check overlays first. */
23420 help
= overlay
= Qnil
;
23421 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23423 overlay
= overlay_vec
[i
];
23424 help
= Foverlay_get (overlay
, Qhelp_echo
);
23429 help_echo_string
= help
;
23430 help_echo_window
= window
;
23431 help_echo_object
= overlay
;
23432 help_echo_pos
= pos
;
23436 Lisp_Object object
= glyph
->object
;
23437 int charpos
= glyph
->charpos
;
23439 /* Try text properties. */
23440 if (STRINGP (object
)
23442 && charpos
< SCHARS (object
))
23444 help
= Fget_text_property (make_number (charpos
),
23445 Qhelp_echo
, object
);
23448 /* If the string itself doesn't specify a help-echo,
23449 see if the buffer text ``under'' it does. */
23450 struct glyph_row
*r
23451 = MATRIX_ROW (w
->current_matrix
, vpos
);
23452 int start
= MATRIX_ROW_START_CHARPOS (r
);
23453 int pos
= string_buffer_position (w
, object
, start
);
23456 help
= Fget_char_property (make_number (pos
),
23457 Qhelp_echo
, w
->buffer
);
23461 object
= w
->buffer
;
23466 else if (BUFFERP (object
)
23469 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23474 help_echo_string
= help
;
23475 help_echo_window
= window
;
23476 help_echo_object
= object
;
23477 help_echo_pos
= charpos
;
23482 /* Look for a `pointer' property. */
23483 if (NILP (pointer
))
23485 /* Check overlays first. */
23486 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23487 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23489 if (NILP (pointer
))
23491 Lisp_Object object
= glyph
->object
;
23492 int charpos
= glyph
->charpos
;
23494 /* Try text properties. */
23495 if (STRINGP (object
)
23497 && charpos
< SCHARS (object
))
23499 pointer
= Fget_text_property (make_number (charpos
),
23501 if (NILP (pointer
))
23503 /* If the string itself doesn't specify a pointer,
23504 see if the buffer text ``under'' it does. */
23505 struct glyph_row
*r
23506 = MATRIX_ROW (w
->current_matrix
, vpos
);
23507 int start
= MATRIX_ROW_START_CHARPOS (r
);
23508 int pos
= string_buffer_position (w
, object
, start
);
23510 pointer
= Fget_char_property (make_number (pos
),
23511 Qpointer
, w
->buffer
);
23514 else if (BUFFERP (object
)
23517 pointer
= Fget_text_property (make_number (charpos
),
23524 current_buffer
= obuf
;
23529 define_frame_cursor1 (f
, cursor
, pointer
);
23534 Clear any mouse-face on window W. This function is part of the
23535 redisplay interface, and is called from try_window_id and similar
23536 functions to ensure the mouse-highlight is off. */
23539 x_clear_window_mouse_face (w
)
23542 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23543 Lisp_Object window
;
23546 XSETWINDOW (window
, w
);
23547 if (EQ (window
, dpyinfo
->mouse_face_window
))
23548 clear_mouse_face (dpyinfo
);
23554 Just discard the mouse face information for frame F, if any.
23555 This is used when the size of F is changed. */
23558 cancel_mouse_face (f
)
23561 Lisp_Object window
;
23562 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23564 window
= dpyinfo
->mouse_face_window
;
23565 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
23567 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23568 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23569 dpyinfo
->mouse_face_window
= Qnil
;
23574 #endif /* HAVE_WINDOW_SYSTEM */
23577 /***********************************************************************
23579 ***********************************************************************/
23581 #ifdef HAVE_WINDOW_SYSTEM
23583 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
23584 which intersects rectangle R. R is in window-relative coordinates. */
23587 expose_area (w
, row
, r
, area
)
23589 struct glyph_row
*row
;
23591 enum glyph_row_area area
;
23593 struct glyph
*first
= row
->glyphs
[area
];
23594 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
23595 struct glyph
*last
;
23596 int first_x
, start_x
, x
;
23598 if (area
== TEXT_AREA
&& row
->fill_line_p
)
23599 /* If row extends face to end of line write the whole line. */
23600 draw_glyphs (w
, 0, row
, area
,
23601 0, row
->used
[area
],
23602 DRAW_NORMAL_TEXT
, 0);
23605 /* Set START_X to the window-relative start position for drawing glyphs of
23606 AREA. The first glyph of the text area can be partially visible.
23607 The first glyphs of other areas cannot. */
23608 start_x
= window_box_left_offset (w
, area
);
23610 if (area
== TEXT_AREA
)
23613 /* Find the first glyph that must be redrawn. */
23615 && x
+ first
->pixel_width
< r
->x
)
23617 x
+= first
->pixel_width
;
23621 /* Find the last one. */
23625 && x
< r
->x
+ r
->width
)
23627 x
+= last
->pixel_width
;
23633 draw_glyphs (w
, first_x
- start_x
, row
, area
,
23634 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
23635 DRAW_NORMAL_TEXT
, 0);
23640 /* Redraw the parts of the glyph row ROW on window W intersecting
23641 rectangle R. R is in window-relative coordinates. Value is
23642 non-zero if mouse-face was overwritten. */
23645 expose_line (w
, row
, r
)
23647 struct glyph_row
*row
;
23650 xassert (row
->enabled_p
);
23652 if (row
->mode_line_p
|| w
->pseudo_window_p
)
23653 draw_glyphs (w
, 0, row
, TEXT_AREA
,
23654 0, row
->used
[TEXT_AREA
],
23655 DRAW_NORMAL_TEXT
, 0);
23658 if (row
->used
[LEFT_MARGIN_AREA
])
23659 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
23660 if (row
->used
[TEXT_AREA
])
23661 expose_area (w
, row
, r
, TEXT_AREA
);
23662 if (row
->used
[RIGHT_MARGIN_AREA
])
23663 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
23664 draw_row_fringe_bitmaps (w
, row
);
23667 return row
->mouse_face_p
;
23671 /* Redraw those parts of glyphs rows during expose event handling that
23672 overlap other rows. Redrawing of an exposed line writes over parts
23673 of lines overlapping that exposed line; this function fixes that.
23675 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
23676 row in W's current matrix that is exposed and overlaps other rows.
23677 LAST_OVERLAPPING_ROW is the last such row. */
23680 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
23682 struct glyph_row
*first_overlapping_row
;
23683 struct glyph_row
*last_overlapping_row
;
23685 struct glyph_row
*row
;
23687 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
23688 if (row
->overlapping_p
)
23690 xassert (row
->enabled_p
&& !row
->mode_line_p
);
23692 if (row
->used
[LEFT_MARGIN_AREA
])
23693 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
23695 if (row
->used
[TEXT_AREA
])
23696 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
23698 if (row
->used
[RIGHT_MARGIN_AREA
])
23699 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
23704 /* Return non-zero if W's cursor intersects rectangle R. */
23707 phys_cursor_in_rect_p (w
, r
)
23711 XRectangle cr
, result
;
23712 struct glyph
*cursor_glyph
;
23714 cursor_glyph
= get_phys_cursor_glyph (w
);
23717 /* r is relative to W's box, but w->phys_cursor.x is relative
23718 to left edge of W's TEXT area. Adjust it. */
23719 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
23720 cr
.y
= w
->phys_cursor
.y
;
23721 cr
.width
= cursor_glyph
->pixel_width
;
23722 cr
.height
= w
->phys_cursor_height
;
23723 /* ++KFS: W32 version used W32-specific IntersectRect here, but
23724 I assume the effect is the same -- and this is portable. */
23725 return x_intersect_rectangles (&cr
, r
, &result
);
23733 Draw a vertical window border to the right of window W if W doesn't
23734 have vertical scroll bars. */
23737 x_draw_vertical_border (w
)
23740 /* We could do better, if we knew what type of scroll-bar the adjacent
23741 windows (on either side) have... But we don't :-(
23742 However, I think this works ok. ++KFS 2003-04-25 */
23744 /* Redraw borders between horizontally adjacent windows. Don't
23745 do it for frames with vertical scroll bars because either the
23746 right scroll bar of a window, or the left scroll bar of its
23747 neighbor will suffice as a border. */
23748 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
23751 if (!WINDOW_RIGHTMOST_P (w
)
23752 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
23754 int x0
, x1
, y0
, y1
;
23756 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23759 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23762 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
23764 else if (!WINDOW_LEFTMOST_P (w
)
23765 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
23767 int x0
, x1
, y0
, y1
;
23769 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
23772 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
23775 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
23780 /* Redraw the part of window W intersection rectangle FR. Pixel
23781 coordinates in FR are frame-relative. Call this function with
23782 input blocked. Value is non-zero if the exposure overwrites
23786 expose_window (w
, fr
)
23790 struct frame
*f
= XFRAME (w
->frame
);
23792 int mouse_face_overwritten_p
= 0;
23794 /* If window is not yet fully initialized, do nothing. This can
23795 happen when toolkit scroll bars are used and a window is split.
23796 Reconfiguring the scroll bar will generate an expose for a newly
23798 if (w
->current_matrix
== NULL
)
23801 /* When we're currently updating the window, display and current
23802 matrix usually don't agree. Arrange for a thorough display
23804 if (w
== updated_window
)
23806 SET_FRAME_GARBAGED (f
);
23810 /* Frame-relative pixel rectangle of W. */
23811 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
23812 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
23813 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
23814 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
23816 if (x_intersect_rectangles (fr
, &wr
, &r
))
23818 int yb
= window_text_bottom_y (w
);
23819 struct glyph_row
*row
;
23820 int cursor_cleared_p
;
23821 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
23823 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
23824 r
.x
, r
.y
, r
.width
, r
.height
));
23826 /* Convert to window coordinates. */
23827 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
23828 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
23830 /* Turn off the cursor. */
23831 if (!w
->pseudo_window_p
23832 && phys_cursor_in_rect_p (w
, &r
))
23834 x_clear_cursor (w
);
23835 cursor_cleared_p
= 1;
23838 cursor_cleared_p
= 0;
23840 /* Update lines intersecting rectangle R. */
23841 first_overlapping_row
= last_overlapping_row
= NULL
;
23842 for (row
= w
->current_matrix
->rows
;
23847 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
23849 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
23850 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
23851 || (r
.y
>= y0
&& r
.y
< y1
)
23852 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
23854 /* A header line may be overlapping, but there is no need
23855 to fix overlapping areas for them. KFS 2005-02-12 */
23856 if (row
->overlapping_p
&& !row
->mode_line_p
)
23858 if (first_overlapping_row
== NULL
)
23859 first_overlapping_row
= row
;
23860 last_overlapping_row
= row
;
23863 if (expose_line (w
, row
, &r
))
23864 mouse_face_overwritten_p
= 1;
23871 /* Display the mode line if there is one. */
23872 if (WINDOW_WANTS_MODELINE_P (w
)
23873 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
23875 && row
->y
< r
.y
+ r
.height
)
23877 if (expose_line (w
, row
, &r
))
23878 mouse_face_overwritten_p
= 1;
23881 if (!w
->pseudo_window_p
)
23883 /* Fix the display of overlapping rows. */
23884 if (first_overlapping_row
)
23885 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
23887 /* Draw border between windows. */
23888 x_draw_vertical_border (w
);
23890 /* Turn the cursor on again. */
23891 if (cursor_cleared_p
)
23892 update_window_cursor (w
, 1);
23896 return mouse_face_overwritten_p
;
23901 /* Redraw (parts) of all windows in the window tree rooted at W that
23902 intersect R. R contains frame pixel coordinates. Value is
23903 non-zero if the exposure overwrites mouse-face. */
23906 expose_window_tree (w
, r
)
23910 struct frame
*f
= XFRAME (w
->frame
);
23911 int mouse_face_overwritten_p
= 0;
23913 while (w
&& !FRAME_GARBAGED_P (f
))
23915 if (!NILP (w
->hchild
))
23916 mouse_face_overwritten_p
23917 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
23918 else if (!NILP (w
->vchild
))
23919 mouse_face_overwritten_p
23920 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
23922 mouse_face_overwritten_p
|= expose_window (w
, r
);
23924 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
23927 return mouse_face_overwritten_p
;
23932 Redisplay an exposed area of frame F. X and Y are the upper-left
23933 corner of the exposed rectangle. W and H are width and height of
23934 the exposed area. All are pixel values. W or H zero means redraw
23935 the entire frame. */
23938 expose_frame (f
, x
, y
, w
, h
)
23943 int mouse_face_overwritten_p
= 0;
23945 TRACE ((stderr
, "expose_frame "));
23947 /* No need to redraw if frame will be redrawn soon. */
23948 if (FRAME_GARBAGED_P (f
))
23950 TRACE ((stderr
, " garbaged\n"));
23954 /* If basic faces haven't been realized yet, there is no point in
23955 trying to redraw anything. This can happen when we get an expose
23956 event while Emacs is starting, e.g. by moving another window. */
23957 if (FRAME_FACE_CACHE (f
) == NULL
23958 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
23960 TRACE ((stderr
, " no faces\n"));
23964 if (w
== 0 || h
== 0)
23967 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
23968 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
23978 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
23979 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
23981 if (WINDOWP (f
->tool_bar_window
))
23982 mouse_face_overwritten_p
23983 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
23985 #ifdef HAVE_X_WINDOWS
23987 #ifndef USE_X_TOOLKIT
23988 if (WINDOWP (f
->menu_bar_window
))
23989 mouse_face_overwritten_p
23990 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
23991 #endif /* not USE_X_TOOLKIT */
23995 /* Some window managers support a focus-follows-mouse style with
23996 delayed raising of frames. Imagine a partially obscured frame,
23997 and moving the mouse into partially obscured mouse-face on that
23998 frame. The visible part of the mouse-face will be highlighted,
23999 then the WM raises the obscured frame. With at least one WM, KDE
24000 2.1, Emacs is not getting any event for the raising of the frame
24001 (even tried with SubstructureRedirectMask), only Expose events.
24002 These expose events will draw text normally, i.e. not
24003 highlighted. Which means we must redo the highlight here.
24004 Subsume it under ``we love X''. --gerd 2001-08-15 */
24005 /* Included in Windows version because Windows most likely does not
24006 do the right thing if any third party tool offers
24007 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24008 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24010 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24011 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24013 int x
= dpyinfo
->mouse_face_mouse_x
;
24014 int y
= dpyinfo
->mouse_face_mouse_y
;
24015 clear_mouse_face (dpyinfo
);
24016 note_mouse_highlight (f
, x
, y
);
24023 Determine the intersection of two rectangles R1 and R2. Return
24024 the intersection in *RESULT. Value is non-zero if RESULT is not
24028 x_intersect_rectangles (r1
, r2
, result
)
24029 XRectangle
*r1
, *r2
, *result
;
24031 XRectangle
*left
, *right
;
24032 XRectangle
*upper
, *lower
;
24033 int intersection_p
= 0;
24035 /* Rearrange so that R1 is the left-most rectangle. */
24037 left
= r1
, right
= r2
;
24039 left
= r2
, right
= r1
;
24041 /* X0 of the intersection is right.x0, if this is inside R1,
24042 otherwise there is no intersection. */
24043 if (right
->x
<= left
->x
+ left
->width
)
24045 result
->x
= right
->x
;
24047 /* The right end of the intersection is the minimum of the
24048 the right ends of left and right. */
24049 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24052 /* Same game for Y. */
24054 upper
= r1
, lower
= r2
;
24056 upper
= r2
, lower
= r1
;
24058 /* The upper end of the intersection is lower.y0, if this is inside
24059 of upper. Otherwise, there is no intersection. */
24060 if (lower
->y
<= upper
->y
+ upper
->height
)
24062 result
->y
= lower
->y
;
24064 /* The lower end of the intersection is the minimum of the lower
24065 ends of upper and lower. */
24066 result
->height
= (min (lower
->y
+ lower
->height
,
24067 upper
->y
+ upper
->height
)
24069 intersection_p
= 1;
24073 return intersection_p
;
24076 #endif /* HAVE_WINDOW_SYSTEM */
24079 /***********************************************************************
24081 ***********************************************************************/
24086 Vwith_echo_area_save_vector
= Qnil
;
24087 staticpro (&Vwith_echo_area_save_vector
);
24089 Vmessage_stack
= Qnil
;
24090 staticpro (&Vmessage_stack
);
24092 Qinhibit_redisplay
= intern ("inhibit-redisplay");
24093 staticpro (&Qinhibit_redisplay
);
24095 message_dolog_marker1
= Fmake_marker ();
24096 staticpro (&message_dolog_marker1
);
24097 message_dolog_marker2
= Fmake_marker ();
24098 staticpro (&message_dolog_marker2
);
24099 message_dolog_marker3
= Fmake_marker ();
24100 staticpro (&message_dolog_marker3
);
24103 defsubr (&Sdump_frame_glyph_matrix
);
24104 defsubr (&Sdump_glyph_matrix
);
24105 defsubr (&Sdump_glyph_row
);
24106 defsubr (&Sdump_tool_bar_row
);
24107 defsubr (&Strace_redisplay
);
24108 defsubr (&Strace_to_stderr
);
24110 #ifdef HAVE_WINDOW_SYSTEM
24111 defsubr (&Stool_bar_lines_needed
);
24112 defsubr (&Slookup_image_map
);
24114 defsubr (&Sformat_mode_line
);
24116 staticpro (&Qmenu_bar_update_hook
);
24117 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
24119 staticpro (&Qoverriding_terminal_local_map
);
24120 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
24122 staticpro (&Qoverriding_local_map
);
24123 Qoverriding_local_map
= intern ("overriding-local-map");
24125 staticpro (&Qwindow_scroll_functions
);
24126 Qwindow_scroll_functions
= intern ("window-scroll-functions");
24128 staticpro (&Qredisplay_end_trigger_functions
);
24129 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
24131 staticpro (&Qinhibit_point_motion_hooks
);
24132 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
24134 QCdata
= intern (":data");
24135 staticpro (&QCdata
);
24136 Qdisplay
= intern ("display");
24137 staticpro (&Qdisplay
);
24138 Qspace_width
= intern ("space-width");
24139 staticpro (&Qspace_width
);
24140 Qraise
= intern ("raise");
24141 staticpro (&Qraise
);
24142 Qslice
= intern ("slice");
24143 staticpro (&Qslice
);
24144 Qspace
= intern ("space");
24145 staticpro (&Qspace
);
24146 Qmargin
= intern ("margin");
24147 staticpro (&Qmargin
);
24148 Qpointer
= intern ("pointer");
24149 staticpro (&Qpointer
);
24150 Qleft_margin
= intern ("left-margin");
24151 staticpro (&Qleft_margin
);
24152 Qright_margin
= intern ("right-margin");
24153 staticpro (&Qright_margin
);
24154 Qcenter
= intern ("center");
24155 staticpro (&Qcenter
);
24156 Qline_height
= intern ("line-height");
24157 staticpro (&Qline_height
);
24158 QCalign_to
= intern (":align-to");
24159 staticpro (&QCalign_to
);
24160 QCrelative_width
= intern (":relative-width");
24161 staticpro (&QCrelative_width
);
24162 QCrelative_height
= intern (":relative-height");
24163 staticpro (&QCrelative_height
);
24164 QCeval
= intern (":eval");
24165 staticpro (&QCeval
);
24166 QCpropertize
= intern (":propertize");
24167 staticpro (&QCpropertize
);
24168 QCfile
= intern (":file");
24169 staticpro (&QCfile
);
24170 Qfontified
= intern ("fontified");
24171 staticpro (&Qfontified
);
24172 Qfontification_functions
= intern ("fontification-functions");
24173 staticpro (&Qfontification_functions
);
24174 Qtrailing_whitespace
= intern ("trailing-whitespace");
24175 staticpro (&Qtrailing_whitespace
);
24176 Qescape_glyph
= intern ("escape-glyph");
24177 staticpro (&Qescape_glyph
);
24178 Qnobreak_space
= intern ("nobreak-space");
24179 staticpro (&Qnobreak_space
);
24180 Qimage
= intern ("image");
24181 staticpro (&Qimage
);
24182 QCmap
= intern (":map");
24183 staticpro (&QCmap
);
24184 QCpointer
= intern (":pointer");
24185 staticpro (&QCpointer
);
24186 Qrect
= intern ("rect");
24187 staticpro (&Qrect
);
24188 Qcircle
= intern ("circle");
24189 staticpro (&Qcircle
);
24190 Qpoly
= intern ("poly");
24191 staticpro (&Qpoly
);
24192 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24193 staticpro (&Qmessage_truncate_lines
);
24194 Qgrow_only
= intern ("grow-only");
24195 staticpro (&Qgrow_only
);
24196 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24197 staticpro (&Qinhibit_menubar_update
);
24198 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24199 staticpro (&Qinhibit_eval_during_redisplay
);
24200 Qposition
= intern ("position");
24201 staticpro (&Qposition
);
24202 Qbuffer_position
= intern ("buffer-position");
24203 staticpro (&Qbuffer_position
);
24204 Qobject
= intern ("object");
24205 staticpro (&Qobject
);
24206 Qbar
= intern ("bar");
24208 Qhbar
= intern ("hbar");
24209 staticpro (&Qhbar
);
24210 Qbox
= intern ("box");
24212 Qhollow
= intern ("hollow");
24213 staticpro (&Qhollow
);
24214 Qhand
= intern ("hand");
24215 staticpro (&Qhand
);
24216 Qarrow
= intern ("arrow");
24217 staticpro (&Qarrow
);
24218 Qtext
= intern ("text");
24219 staticpro (&Qtext
);
24220 Qrisky_local_variable
= intern ("risky-local-variable");
24221 staticpro (&Qrisky_local_variable
);
24222 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24223 staticpro (&Qinhibit_free_realized_faces
);
24225 list_of_error
= Fcons (Fcons (intern ("error"),
24226 Fcons (intern ("void-variable"), Qnil
)),
24228 staticpro (&list_of_error
);
24230 Qlast_arrow_position
= intern ("last-arrow-position");
24231 staticpro (&Qlast_arrow_position
);
24232 Qlast_arrow_string
= intern ("last-arrow-string");
24233 staticpro (&Qlast_arrow_string
);
24235 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24236 staticpro (&Qoverlay_arrow_string
);
24237 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24238 staticpro (&Qoverlay_arrow_bitmap
);
24240 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24241 staticpro (&echo_buffer
[0]);
24242 staticpro (&echo_buffer
[1]);
24244 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24245 staticpro (&echo_area_buffer
[0]);
24246 staticpro (&echo_area_buffer
[1]);
24248 Vmessages_buffer_name
= build_string ("*Messages*");
24249 staticpro (&Vmessages_buffer_name
);
24251 mode_line_proptrans_alist
= Qnil
;
24252 staticpro (&mode_line_proptrans_alist
);
24253 mode_line_string_list
= Qnil
;
24254 staticpro (&mode_line_string_list
);
24255 mode_line_string_face
= Qnil
;
24256 staticpro (&mode_line_string_face
);
24257 mode_line_string_face_prop
= Qnil
;
24258 staticpro (&mode_line_string_face_prop
);
24259 Vmode_line_unwind_vector
= Qnil
;
24260 staticpro (&Vmode_line_unwind_vector
);
24262 help_echo_string
= Qnil
;
24263 staticpro (&help_echo_string
);
24264 help_echo_object
= Qnil
;
24265 staticpro (&help_echo_object
);
24266 help_echo_window
= Qnil
;
24267 staticpro (&help_echo_window
);
24268 previous_help_echo_string
= Qnil
;
24269 staticpro (&previous_help_echo_string
);
24270 help_echo_pos
= -1;
24272 #ifdef HAVE_WINDOW_SYSTEM
24273 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24274 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24275 For example, if a block cursor is over a tab, it will be drawn as
24276 wide as that tab on the display. */);
24277 x_stretch_cursor_p
= 0;
24280 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24281 doc
: /* *Non-nil means highlight trailing whitespace.
24282 The face used for trailing whitespace is `trailing-whitespace'. */);
24283 Vshow_trailing_whitespace
= Qnil
;
24285 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24286 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24287 A value of t means highlight the character itself (for nobreak space,
24288 use face `nobreak-space').
24289 A value of nil means no highlighting.
24290 Other values mean display the escape glyph followed by an ordinary
24291 space or ordinary hyphen. */);
24292 Vnobreak_char_display
= Qt
;
24294 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24295 doc
: /* *The pointer shape to show in void text areas.
24296 A value of nil means to show the text pointer. Other options are `arrow',
24297 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24298 Vvoid_text_area_pointer
= Qarrow
;
24300 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24301 doc
: /* Non-nil means don't actually do any redisplay.
24302 This is used for internal purposes. */);
24303 Vinhibit_redisplay
= Qnil
;
24305 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24306 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24307 Vglobal_mode_string
= Qnil
;
24309 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24310 doc
: /* Marker for where to display an arrow on top of the buffer text.
24311 This must be the beginning of a line in order to work.
24312 See also `overlay-arrow-string'. */);
24313 Voverlay_arrow_position
= Qnil
;
24315 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24316 doc
: /* String to display as an arrow in non-window frames.
24317 See also `overlay-arrow-position'. */);
24318 Voverlay_arrow_string
= build_string ("=>");
24320 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24321 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24322 The symbols on this list are examined during redisplay to determine
24323 where to display overlay arrows. */);
24324 Voverlay_arrow_variable_list
24325 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24327 DEFVAR_INT ("scroll-step", &scroll_step
,
24328 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24329 If that fails to bring point back on frame, point is centered instead.
24330 If this is zero, point is always centered after it moves off frame.
24331 If you want scrolling to always be a line at a time, you should set
24332 `scroll-conservatively' to a large value rather than set this to 1. */);
24334 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24335 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24336 A value of zero means to scroll the text to center point vertically
24337 in the window. */);
24338 scroll_conservatively
= 0;
24340 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24341 doc
: /* *Number of lines of margin at the top and bottom of a window.
24342 Recenter the window whenever point gets within this many lines
24343 of the top or bottom of the window. */);
24346 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24347 doc
: /* Pixels per inch value for non-window system displays.
24348 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24349 Vdisplay_pixels_per_inch
= make_float (72.0);
24352 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24355 DEFVAR_BOOL ("truncate-partial-width-windows",
24356 &truncate_partial_width_windows
,
24357 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
24358 truncate_partial_width_windows
= 1;
24360 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24361 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24362 Any other value means to use the appropriate face, `mode-line',
24363 `header-line', or `menu' respectively. */);
24364 mode_line_inverse_video
= 1;
24366 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24367 doc
: /* *Maximum buffer size for which line number should be displayed.
24368 If the buffer is bigger than this, the line number does not appear
24369 in the mode line. A value of nil means no limit. */);
24370 Vline_number_display_limit
= Qnil
;
24372 DEFVAR_INT ("line-number-display-limit-width",
24373 &line_number_display_limit_width
,
24374 doc
: /* *Maximum line width (in characters) for line number display.
24375 If the average length of the lines near point is bigger than this, then the
24376 line number may be omitted from the mode line. */);
24377 line_number_display_limit_width
= 200;
24379 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24380 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24381 highlight_nonselected_windows
= 0;
24383 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24384 doc
: /* Non-nil if more than one frame is visible on this display.
24385 Minibuffer-only frames don't count, but iconified frames do.
24386 This variable is not guaranteed to be accurate except while processing
24387 `frame-title-format' and `icon-title-format'. */);
24389 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24390 doc
: /* Template for displaying the title bar of visible frames.
24391 \(Assuming the window manager supports this feature.)
24393 This variable has the same structure as `mode-line-format', except that
24394 the %c and %l constructs are ignored. It is used only on frames for
24395 which no explicit name has been set \(see `modify-frame-parameters'). */);
24397 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24398 doc
: /* Template for displaying the title bar of an iconified frame.
24399 \(Assuming the window manager supports this feature.)
24400 This variable has the same structure as `mode-line-format' (which see),
24401 and is used only on frames for which no explicit name has been set
24402 \(see `modify-frame-parameters'). */);
24404 = Vframe_title_format
24405 = Fcons (intern ("multiple-frames"),
24406 Fcons (build_string ("%b"),
24407 Fcons (Fcons (empty_unibyte_string
,
24408 Fcons (intern ("invocation-name"),
24409 Fcons (build_string ("@"),
24410 Fcons (intern ("system-name"),
24414 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24415 doc
: /* Maximum number of lines to keep in the message log buffer.
24416 If nil, disable message logging. If t, log messages but don't truncate
24417 the buffer when it becomes large. */);
24418 Vmessage_log_max
= make_number (100);
24420 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24421 doc
: /* Functions called before redisplay, if window sizes have changed.
24422 The value should be a list of functions that take one argument.
24423 Just before redisplay, for each frame, if any of its windows have changed
24424 size since the last redisplay, or have been split or deleted,
24425 all the functions in the list are called, with the frame as argument. */);
24426 Vwindow_size_change_functions
= Qnil
;
24428 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24429 doc
: /* List of functions to call before redisplaying a window with scrolling.
24430 Each function is called with two arguments, the window
24431 and its new display-start position. Note that the value of `window-end'
24432 is not valid when these functions are called. */);
24433 Vwindow_scroll_functions
= Qnil
;
24435 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24436 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24437 Each function is called with two arguments, the window and the end trigger value.
24438 See `set-window-redisplay-end-trigger'. */);
24439 Vredisplay_end_trigger_functions
= Qnil
;
24441 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24442 doc
: /* *Non-nil means autoselect window with mouse pointer.
24443 If nil, do not autoselect windows.
24444 A positive number means delay autoselection by that many seconds: a
24445 window is autoselected only after the mouse has remained in that
24446 window for the duration of the delay.
24447 A negative number has a similar effect, but causes windows to be
24448 autoselected only after the mouse has stopped moving. \(Because of
24449 the way Emacs compares mouse events, you will occasionally wait twice
24450 that time before the window gets selected.\)
24451 Any other value means to autoselect window instantaneously when the
24452 mouse pointer enters it.
24454 Autoselection selects the minibuffer only if it is active, and never
24455 unselects the minibuffer if it is active. */);
24456 Vmouse_autoselect_window
= Qnil
;
24458 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
24459 doc
: /* *Non-nil means automatically resize tool-bars.
24460 This dynamically changes the tool-bar's height to the minimum height
24461 that is needed to make all tool-bar items visible.
24462 If value is `grow-only', the tool-bar's height is only increased
24463 automatically; to decrease the tool-bar height, use \\[recenter]. */);
24464 Vauto_resize_tool_bars
= Qt
;
24466 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
24467 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
24468 auto_raise_tool_bar_buttons_p
= 1;
24470 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
24471 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
24472 make_cursor_line_fully_visible_p
= 1;
24474 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
24475 doc
: /* *Border below tool-bar in pixels.
24476 If an integer, use it as the height of the border.
24477 If it is one of `internal-border-width' or `border-width', use the
24478 value of the corresponding frame parameter.
24479 Otherwise, no border is added below the tool-bar. */);
24480 Vtool_bar_border
= Qinternal_border_width
;
24482 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
24483 doc
: /* *Margin around tool-bar buttons in pixels.
24484 If an integer, use that for both horizontal and vertical margins.
24485 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
24486 HORZ specifying the horizontal margin, and VERT specifying the
24487 vertical margin. */);
24488 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
24490 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
24491 doc
: /* *Relief thickness of tool-bar buttons. */);
24492 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
24494 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
24495 doc
: /* List of functions to call to fontify regions of text.
24496 Each function is called with one argument POS. Functions must
24497 fontify a region starting at POS in the current buffer, and give
24498 fontified regions the property `fontified'. */);
24499 Vfontification_functions
= Qnil
;
24500 Fmake_variable_buffer_local (Qfontification_functions
);
24502 DEFVAR_BOOL ("unibyte-display-via-language-environment",
24503 &unibyte_display_via_language_environment
,
24504 doc
: /* *Non-nil means display unibyte text according to language environment.
24505 Specifically this means that unibyte non-ASCII characters
24506 are displayed by converting them to the equivalent multibyte characters
24507 according to the current language environment. As a result, they are
24508 displayed according to the current fontset. */);
24509 unibyte_display_via_language_environment
= 0;
24511 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
24512 doc
: /* *Maximum height for resizing mini-windows.
24513 If a float, it specifies a fraction of the mini-window frame's height.
24514 If an integer, it specifies a number of lines. */);
24515 Vmax_mini_window_height
= make_float (0.25);
24517 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
24518 doc
: /* *How to resize mini-windows.
24519 A value of nil means don't automatically resize mini-windows.
24520 A value of t means resize them to fit the text displayed in them.
24521 A value of `grow-only', the default, means let mini-windows grow
24522 only, until their display becomes empty, at which point the windows
24523 go back to their normal size. */);
24524 Vresize_mini_windows
= Qgrow_only
;
24526 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
24527 doc
: /* Alist specifying how to blink the cursor off.
24528 Each element has the form (ON-STATE . OFF-STATE). Whenever the
24529 `cursor-type' frame-parameter or variable equals ON-STATE,
24530 comparing using `equal', Emacs uses OFF-STATE to specify
24531 how to blink it off. ON-STATE and OFF-STATE are values for
24532 the `cursor-type' frame parameter.
24534 If a frame's ON-STATE has no entry in this list,
24535 the frame's other specifications determine how to blink the cursor off. */);
24536 Vblink_cursor_alist
= Qnil
;
24538 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
24539 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
24540 automatic_hscrolling_p
= 1;
24542 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
24543 doc
: /* *How many columns away from the window edge point is allowed to get
24544 before automatic hscrolling will horizontally scroll the window. */);
24545 hscroll_margin
= 5;
24547 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
24548 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
24549 When point is less than `hscroll-margin' columns from the window
24550 edge, automatic hscrolling will scroll the window by the amount of columns
24551 determined by this variable. If its value is a positive integer, scroll that
24552 many columns. If it's a positive floating-point number, it specifies the
24553 fraction of the window's width to scroll. If it's nil or zero, point will be
24554 centered horizontally after the scroll. Any other value, including negative
24555 numbers, are treated as if the value were zero.
24557 Automatic hscrolling always moves point outside the scroll margin, so if
24558 point was more than scroll step columns inside the margin, the window will
24559 scroll more than the value given by the scroll step.
24561 Note that the lower bound for automatic hscrolling specified by `scroll-left'
24562 and `scroll-right' overrides this variable's effect. */);
24563 Vhscroll_step
= make_number (0);
24565 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
24566 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
24567 Bind this around calls to `message' to let it take effect. */);
24568 message_truncate_lines
= 0;
24570 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
24571 doc
: /* Normal hook run to update the menu bar definitions.
24572 Redisplay runs this hook before it redisplays the menu bar.
24573 This is used to update submenus such as Buffers,
24574 whose contents depend on various data. */);
24575 Vmenu_bar_update_hook
= Qnil
;
24577 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
24578 doc
: /* Frame for which we are updating a menu.
24579 The enable predicate for a menu binding should check this variable. */);
24580 Vmenu_updating_frame
= Qnil
;
24582 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
24583 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
24584 inhibit_menubar_update
= 0;
24586 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
24587 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
24588 inhibit_eval_during_redisplay
= 0;
24590 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
24591 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
24592 inhibit_free_realized_faces
= 0;
24595 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
24596 doc
: /* Inhibit try_window_id display optimization. */);
24597 inhibit_try_window_id
= 0;
24599 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
24600 doc
: /* Inhibit try_window_reusing display optimization. */);
24601 inhibit_try_window_reusing
= 0;
24603 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
24604 doc
: /* Inhibit try_cursor_movement display optimization. */);
24605 inhibit_try_cursor_movement
= 0;
24606 #endif /* GLYPH_DEBUG */
24608 DEFVAR_INT ("overline-margin", &overline_margin
,
24609 doc
: /* *Space between overline and text, in pixels.
24610 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
24611 margin to the caracter height. */);
24612 overline_margin
= 2;
24616 /* Initialize this module when Emacs starts. */
24621 Lisp_Object root_window
;
24622 struct window
*mini_w
;
24624 current_header_line_height
= current_mode_line_height
= -1;
24626 CHARPOS (this_line_start_pos
) = 0;
24628 mini_w
= XWINDOW (minibuf_window
);
24629 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
24631 if (!noninteractive
)
24633 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
24636 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
24637 set_window_height (root_window
,
24638 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
24640 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
24641 set_window_height (minibuf_window
, 1, 0);
24643 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
24644 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
24646 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
24647 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
24648 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
24650 /* The default ellipsis glyphs `...'. */
24651 for (i
= 0; i
< 3; ++i
)
24652 default_invis_vector
[i
] = make_number ('.');
24656 /* Allocate the buffer for frame titles.
24657 Also used for `format-mode-line'. */
24659 mode_line_noprop_buf
= (char *) xmalloc (size
);
24660 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
24661 mode_line_noprop_ptr
= mode_line_noprop_buf
;
24662 mode_line_target
= MODE_LINE_DISPLAY
;
24665 help_echo_showing_p
= 0;
24669 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
24670 (do not change this comment) */