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 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 2, 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"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
204 #ifndef FRAME_X_OUTPUT
205 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
208 #define INFINITY 10000000
210 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
212 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
213 extern int pending_menu_activation
;
216 extern int interrupt_input
;
217 extern int command_loop_level
;
219 extern Lisp_Object do_mouse_tracking
;
221 extern int minibuffer_auto_raise
;
222 extern Lisp_Object Vminibuffer_list
;
224 extern Lisp_Object Qface
;
225 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
227 extern Lisp_Object Voverriding_local_map
;
228 extern Lisp_Object Voverriding_local_map_menu_flag
;
229 extern Lisp_Object Qmenu_item
;
230 extern Lisp_Object Qwhen
;
231 extern Lisp_Object Qhelp_echo
;
233 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
234 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
235 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
236 Lisp_Object Qinhibit_point_motion_hooks
;
237 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
238 Lisp_Object Qfontified
;
239 Lisp_Object Qgrow_only
;
240 Lisp_Object Qinhibit_eval_during_redisplay
;
241 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
244 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
247 Lisp_Object Qarrow
, Qhand
, Qtext
;
249 Lisp_Object Qrisky_local_variable
;
251 /* Holds the list (error). */
252 Lisp_Object list_of_error
;
254 /* Functions called to fontify regions of text. */
256 Lisp_Object Vfontification_functions
;
257 Lisp_Object Qfontification_functions
;
259 /* Non-zero means automatically select any window when the mouse
260 cursor moves into it. */
261 int mouse_autoselect_window
;
263 /* Non-zero means draw tool bar buttons raised when the mouse moves
266 int auto_raise_tool_bar_buttons_p
;
268 /* Non-zero means to reposition window if cursor line is only partially visible. */
270 int make_cursor_line_fully_visible_p
;
272 /* Margin around tool bar buttons in pixels. */
274 Lisp_Object Vtool_bar_button_margin
;
276 /* Thickness of shadow to draw around tool bar buttons. */
278 EMACS_INT tool_bar_button_relief
;
280 /* Non-zero means automatically resize tool-bars so that all tool-bar
281 items are visible, and no blank lines remain. */
283 int auto_resize_tool_bars_p
;
285 /* Non-zero means draw block and hollow cursor as wide as the glyph
286 under it. For example, if a block cursor is over a tab, it will be
287 drawn as wide as that tab on the display. */
289 int x_stretch_cursor_p
;
291 /* Non-nil means don't actually do any redisplay. */
293 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
295 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
297 int inhibit_eval_during_redisplay
;
299 /* Names of text properties relevant for redisplay. */
301 Lisp_Object Qdisplay
;
302 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
304 /* Symbols used in text property values. */
306 Lisp_Object Vdisplay_pixels_per_inch
;
307 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
308 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
311 Lisp_Object Qmargin
, Qpointer
;
312 Lisp_Object Qline_height
;
313 extern Lisp_Object Qheight
;
314 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
315 extern Lisp_Object Qscroll_bar
;
316 extern Lisp_Object Qcursor
;
318 /* Non-nil means highlight trailing whitespace. */
320 Lisp_Object Vshow_trailing_whitespace
;
322 /* Non-nil means escape non-break space and hyphens. */
324 Lisp_Object Vnobreak_char_display
;
326 #ifdef HAVE_WINDOW_SYSTEM
327 extern Lisp_Object Voverflow_newline_into_fringe
;
329 /* Test if overflow newline into fringe. Called with iterator IT
330 at or past right window margin, and with IT->current_x set. */
332 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
333 (!NILP (Voverflow_newline_into_fringe) \
334 && FRAME_WINDOW_P (it->f) \
335 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
336 && it->current_x == it->last_visible_x)
338 #endif /* HAVE_WINDOW_SYSTEM */
340 /* Non-nil means show the text cursor in void text areas
341 i.e. in blank areas after eol and eob. This used to be
342 the default in 21.3. */
344 Lisp_Object Vvoid_text_area_pointer
;
346 /* Name of the face used to highlight trailing whitespace. */
348 Lisp_Object Qtrailing_whitespace
;
350 /* Name and number of the face used to highlight escape glyphs. */
352 Lisp_Object Qescape_glyph
;
354 /* Name and number of the face used to highlight non-breaking spaces. */
356 Lisp_Object Qnobreak_space
;
358 /* The symbol `image' which is the car of the lists used to represent
363 /* The image map types. */
364 Lisp_Object QCmap
, QCpointer
;
365 Lisp_Object Qrect
, Qcircle
, Qpoly
;
367 /* Non-zero means print newline to stdout before next mini-buffer
370 int noninteractive_need_newline
;
372 /* Non-zero means print newline to message log before next message. */
374 static int message_log_need_newline
;
376 /* Three markers that message_dolog uses.
377 It could allocate them itself, but that causes trouble
378 in handling memory-full errors. */
379 static Lisp_Object message_dolog_marker1
;
380 static Lisp_Object message_dolog_marker2
;
381 static Lisp_Object message_dolog_marker3
;
383 /* The buffer position of the first character appearing entirely or
384 partially on the line of the selected window which contains the
385 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
386 redisplay optimization in redisplay_internal. */
388 static struct text_pos this_line_start_pos
;
390 /* Number of characters past the end of the line above, including the
391 terminating newline. */
393 static struct text_pos this_line_end_pos
;
395 /* The vertical positions and the height of this line. */
397 static int this_line_vpos
;
398 static int this_line_y
;
399 static int this_line_pixel_height
;
401 /* X position at which this display line starts. Usually zero;
402 negative if first character is partially visible. */
404 static int this_line_start_x
;
406 /* Buffer that this_line_.* variables are referring to. */
408 static struct buffer
*this_line_buffer
;
410 /* Nonzero means truncate lines in all windows less wide than the
413 int truncate_partial_width_windows
;
415 /* A flag to control how to display unibyte 8-bit character. */
417 int unibyte_display_via_language_environment
;
419 /* Nonzero means we have more than one non-mini-buffer-only frame.
420 Not guaranteed to be accurate except while parsing
421 frame-title-format. */
425 Lisp_Object Vglobal_mode_string
;
428 /* List of variables (symbols) which hold markers for overlay arrows.
429 The symbols on this list are examined during redisplay to determine
430 where to display overlay arrows. */
432 Lisp_Object Voverlay_arrow_variable_list
;
434 /* Marker for where to display an arrow on top of the buffer text. */
436 Lisp_Object Voverlay_arrow_position
;
438 /* String to display for the arrow. Only used on terminal frames. */
440 Lisp_Object Voverlay_arrow_string
;
442 /* Values of those variables at last redisplay are stored as
443 properties on `overlay-arrow-position' symbol. However, if
444 Voverlay_arrow_position is a marker, last-arrow-position is its
445 numerical position. */
447 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
449 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
450 properties on a symbol in overlay-arrow-variable-list. */
452 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
454 /* Like mode-line-format, but for the title bar on a visible frame. */
456 Lisp_Object Vframe_title_format
;
458 /* Like mode-line-format, but for the title bar on an iconified frame. */
460 Lisp_Object Vicon_title_format
;
462 /* List of functions to call when a window's size changes. These
463 functions get one arg, a frame on which one or more windows' sizes
466 static Lisp_Object Vwindow_size_change_functions
;
468 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
470 /* Nonzero if an overlay arrow has been displayed in this window. */
472 static int overlay_arrow_seen
;
474 /* Nonzero means highlight the region even in nonselected windows. */
476 int highlight_nonselected_windows
;
478 /* If cursor motion alone moves point off frame, try scrolling this
479 many lines up or down if that will bring it back. */
481 static EMACS_INT scroll_step
;
483 /* Nonzero means scroll just far enough to bring point back on the
484 screen, when appropriate. */
486 static EMACS_INT scroll_conservatively
;
488 /* Recenter the window whenever point gets within this many lines of
489 the top or bottom of the window. This value is translated into a
490 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
491 that there is really a fixed pixel height scroll margin. */
493 EMACS_INT scroll_margin
;
495 /* Number of windows showing the buffer of the selected window (or
496 another buffer with the same base buffer). keyboard.c refers to
501 /* Vector containing glyphs for an ellipsis `...'. */
503 static Lisp_Object default_invis_vector
[3];
505 /* Zero means display the mode-line/header-line/menu-bar in the default face
506 (this slightly odd definition is for compatibility with previous versions
507 of emacs), non-zero means display them using their respective faces.
509 This variable is deprecated. */
511 int mode_line_inverse_video
;
513 /* Prompt to display in front of the mini-buffer contents. */
515 Lisp_Object minibuf_prompt
;
517 /* Width of current mini-buffer prompt. Only set after display_line
518 of the line that contains the prompt. */
520 int minibuf_prompt_width
;
522 /* This is the window where the echo area message was displayed. It
523 is always a mini-buffer window, but it may not be the same window
524 currently active as a mini-buffer. */
526 Lisp_Object echo_area_window
;
528 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
529 pushes the current message and the value of
530 message_enable_multibyte on the stack, the function restore_message
531 pops the stack and displays MESSAGE again. */
533 Lisp_Object Vmessage_stack
;
535 /* Nonzero means multibyte characters were enabled when the echo area
536 message was specified. */
538 int message_enable_multibyte
;
540 /* Nonzero if we should redraw the mode lines on the next redisplay. */
542 int update_mode_lines
;
544 /* Nonzero if window sizes or contents have changed since last
545 redisplay that finished. */
547 int windows_or_buffers_changed
;
549 /* Nonzero means a frame's cursor type has been changed. */
551 int cursor_type_changed
;
553 /* Nonzero after display_mode_line if %l was used and it displayed a
556 int line_number_displayed
;
558 /* Maximum buffer size for which to display line numbers. */
560 Lisp_Object Vline_number_display_limit
;
562 /* Line width to consider when repositioning for line number display. */
564 static EMACS_INT line_number_display_limit_width
;
566 /* Number of lines to keep in the message log buffer. t means
567 infinite. nil means don't log at all. */
569 Lisp_Object Vmessage_log_max
;
571 /* The name of the *Messages* buffer, a string. */
573 static Lisp_Object Vmessages_buffer_name
;
575 /* Index 0 is the buffer that holds the current (desired) echo area message,
576 or nil if none is desired right now.
578 Index 1 is the buffer that holds the previously displayed echo area message,
579 or nil to indicate no message. This is normally what's on the screen now.
581 These two can point to the same buffer. That happens when the last
582 message output by the user (or made by echoing) has been displayed. */
584 Lisp_Object echo_area_buffer
[2];
586 /* Permanent pointers to the two buffers that are used for echo area
587 purposes. Once the two buffers are made, and their pointers are
588 placed here, these two slots remain unchanged unless those buffers
589 need to be created afresh. */
591 static Lisp_Object echo_buffer
[2];
593 /* A vector saved used in with_area_buffer to reduce consing. */
595 static Lisp_Object Vwith_echo_area_save_vector
;
597 /* Non-zero means display_echo_area should display the last echo area
598 message again. Set by redisplay_preserve_echo_area. */
600 static int display_last_displayed_message_p
;
602 /* Nonzero if echo area is being used by print; zero if being used by
605 int message_buf_print
;
607 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
609 Lisp_Object Qinhibit_menubar_update
;
610 int inhibit_menubar_update
;
612 /* Maximum height for resizing mini-windows. Either a float
613 specifying a fraction of the available height, or an integer
614 specifying a number of lines. */
616 Lisp_Object Vmax_mini_window_height
;
618 /* Non-zero means messages should be displayed with truncated
619 lines instead of being continued. */
621 int message_truncate_lines
;
622 Lisp_Object Qmessage_truncate_lines
;
624 /* Set to 1 in clear_message to make redisplay_internal aware
625 of an emptied echo area. */
627 static int message_cleared_p
;
629 /* How to blink the default frame cursor off. */
630 Lisp_Object Vblink_cursor_alist
;
632 /* A scratch glyph row with contents used for generating truncation
633 glyphs. Also used in direct_output_for_insert. */
635 #define MAX_SCRATCH_GLYPHS 100
636 struct glyph_row scratch_glyph_row
;
637 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
639 /* Ascent and height of the last line processed by move_it_to. */
641 static int last_max_ascent
, last_height
;
643 /* Non-zero if there's a help-echo in the echo area. */
645 int help_echo_showing_p
;
647 /* If >= 0, computed, exact values of mode-line and header-line height
648 to use in the macros CURRENT_MODE_LINE_HEIGHT and
649 CURRENT_HEADER_LINE_HEIGHT. */
651 int current_mode_line_height
, current_header_line_height
;
653 /* The maximum distance to look ahead for text properties. Values
654 that are too small let us call compute_char_face and similar
655 functions too often which is expensive. Values that are too large
656 let us call compute_char_face and alike too often because we
657 might not be interested in text properties that far away. */
659 #define TEXT_PROP_DISTANCE_LIMIT 100
663 /* Variables to turn off display optimizations from Lisp. */
665 int inhibit_try_window_id
, inhibit_try_window_reusing
;
666 int inhibit_try_cursor_movement
;
668 /* Non-zero means print traces of redisplay if compiled with
671 int trace_redisplay_p
;
673 #endif /* GLYPH_DEBUG */
675 #ifdef DEBUG_TRACE_MOVE
676 /* Non-zero means trace with TRACE_MOVE to stderr. */
679 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
681 #define TRACE_MOVE(x) (void) 0
684 /* Non-zero means automatically scroll windows horizontally to make
687 int automatic_hscrolling_p
;
689 /* How close to the margin can point get before the window is scrolled
691 EMACS_INT hscroll_margin
;
693 /* How much to scroll horizontally when point is inside the above margin. */
694 Lisp_Object Vhscroll_step
;
696 /* The variable `resize-mini-windows'. If nil, don't resize
697 mini-windows. If t, always resize them to fit the text they
698 display. If `grow-only', let mini-windows grow only until they
701 Lisp_Object Vresize_mini_windows
;
703 /* Buffer being redisplayed -- for redisplay_window_error. */
705 struct buffer
*displayed_buffer
;
707 /* Value returned from text property handlers (see below). */
712 HANDLED_RECOMPUTE_PROPS
,
713 HANDLED_OVERLAY_STRING_CONSUMED
,
717 /* A description of text properties that redisplay is interested
722 /* The name of the property. */
725 /* A unique index for the property. */
728 /* A handler function called to set up iterator IT from the property
729 at IT's current position. Value is used to steer handle_stop. */
730 enum prop_handled (*handler
) P_ ((struct it
*it
));
733 static enum prop_handled handle_face_prop
P_ ((struct it
*));
734 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
735 static enum prop_handled handle_display_prop
P_ ((struct it
*));
736 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
737 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
738 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
740 /* Properties handled by iterators. */
742 static struct props it_props
[] =
744 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
745 /* Handle `face' before `display' because some sub-properties of
746 `display' need to know the face. */
747 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
748 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
749 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
750 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
754 /* Value is the position described by X. If X is a marker, value is
755 the marker_position of X. Otherwise, value is X. */
757 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
759 /* Enumeration returned by some move_it_.* functions internally. */
763 /* Not used. Undefined value. */
766 /* Move ended at the requested buffer position or ZV. */
767 MOVE_POS_MATCH_OR_ZV
,
769 /* Move ended at the requested X pixel position. */
772 /* Move within a line ended at the end of a line that must be
776 /* Move within a line ended at the end of a line that would
777 be displayed truncated. */
780 /* Move within a line ended at a line end. */
784 /* This counter is used to clear the face cache every once in a while
785 in redisplay_internal. It is incremented for each redisplay.
786 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
789 #define CLEAR_FACE_CACHE_COUNT 500
790 static int clear_face_cache_count
;
792 /* Similarly for the image cache. */
794 #ifdef HAVE_WINDOW_SYSTEM
795 #define CLEAR_IMAGE_CACHE_COUNT 101
796 static int clear_image_cache_count
;
799 /* Record the previous terminal frame we displayed. */
801 static struct frame
*previous_terminal_frame
;
803 /* Non-zero while redisplay_internal is in progress. */
807 /* Non-zero means don't free realized faces. Bound while freeing
808 realized faces is dangerous because glyph matrices might still
811 int inhibit_free_realized_faces
;
812 Lisp_Object Qinhibit_free_realized_faces
;
814 /* If a string, XTread_socket generates an event to display that string.
815 (The display is done in read_char.) */
817 Lisp_Object help_echo_string
;
818 Lisp_Object help_echo_window
;
819 Lisp_Object help_echo_object
;
822 /* Temporary variable for XTread_socket. */
824 Lisp_Object previous_help_echo_string
;
826 /* Null glyph slice */
828 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
831 /* Function prototypes. */
833 static void setup_for_ellipsis
P_ ((struct it
*, int));
834 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
835 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
836 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
837 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
838 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
839 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
842 static int invisible_text_between_p
P_ ((struct it
*, int, int));
845 static void pint2str
P_ ((char *, int, int));
846 static void pint2hrstr
P_ ((char *, int, int));
847 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
849 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
850 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
851 static void store_mode_line_noprop_char
P_ ((char));
852 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
853 static void x_consider_frame_title
P_ ((Lisp_Object
));
854 static void handle_stop
P_ ((struct it
*));
855 static int tool_bar_lines_needed
P_ ((struct frame
*));
856 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
857 static void ensure_echo_area_buffers
P_ ((void));
858 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
859 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
860 static int with_echo_area_buffer
P_ ((struct window
*, int,
861 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
862 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
863 static void clear_garbaged_frames
P_ ((void));
864 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
865 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
866 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
867 static int display_echo_area
P_ ((struct window
*));
868 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
869 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
870 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
871 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
872 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
874 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
875 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
876 static void insert_left_trunc_glyphs
P_ ((struct it
*));
877 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
879 static void extend_face_to_end_of_line
P_ ((struct it
*));
880 static int append_space_for_newline
P_ ((struct it
*, int));
881 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
882 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
883 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
884 static int trailing_whitespace_p
P_ ((int));
885 static int message_log_check_duplicate
P_ ((int, int, int, int));
886 static void push_it
P_ ((struct it
*));
887 static void pop_it
P_ ((struct it
*));
888 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
889 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
890 static void redisplay_internal
P_ ((int));
891 static int echo_area_display
P_ ((int));
892 static void redisplay_windows
P_ ((Lisp_Object
));
893 static void redisplay_window
P_ ((Lisp_Object
, int));
894 static Lisp_Object
redisplay_window_error ();
895 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
896 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
897 static void update_menu_bar
P_ ((struct frame
*, int));
898 static int try_window_reusing_current_matrix
P_ ((struct window
*));
899 static int try_window_id
P_ ((struct window
*));
900 static int display_line
P_ ((struct it
*));
901 static int display_mode_lines
P_ ((struct window
*));
902 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
903 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
904 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
905 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
906 static void display_menu_bar
P_ ((struct window
*));
907 static int display_count_lines
P_ ((int, int, int, int, int *));
908 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
909 int, int, struct it
*, int, int, int, int));
910 static void compute_line_metrics
P_ ((struct it
*));
911 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
912 static int get_overlay_strings
P_ ((struct it
*, int));
913 static void next_overlay_string
P_ ((struct it
*));
914 static void reseat
P_ ((struct it
*, struct text_pos
, int));
915 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
916 static void back_to_previous_visible_line_start
P_ ((struct it
*));
917 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
918 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
919 static int next_element_from_ellipsis
P_ ((struct it
*));
920 static int next_element_from_display_vector
P_ ((struct it
*));
921 static int next_element_from_string
P_ ((struct it
*));
922 static int next_element_from_c_string
P_ ((struct it
*));
923 static int next_element_from_buffer
P_ ((struct it
*));
924 static int next_element_from_composition
P_ ((struct it
*));
925 static int next_element_from_image
P_ ((struct it
*));
926 static int next_element_from_stretch
P_ ((struct it
*));
927 static void load_overlay_strings
P_ ((struct it
*, int));
928 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
929 struct display_pos
*));
930 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
931 Lisp_Object
, int, int, int, int));
932 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
934 void move_it_vertically_backward
P_ ((struct it
*, int));
935 static void init_to_row_start
P_ ((struct it
*, struct window
*,
936 struct glyph_row
*));
937 static int init_to_row_end
P_ ((struct it
*, struct window
*,
938 struct glyph_row
*));
939 static void back_to_previous_line_start
P_ ((struct it
*));
940 static int forward_to_next_line_start
P_ ((struct it
*, int *));
941 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
943 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
944 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
945 static int number_of_chars
P_ ((unsigned char *, int));
946 static void compute_stop_pos
P_ ((struct it
*));
947 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
949 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
950 static int next_overlay_change
P_ ((int));
951 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
952 Lisp_Object
, struct text_pos
*,
954 static int underlying_face_id
P_ ((struct it
*));
955 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
958 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
959 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
961 #ifdef HAVE_WINDOW_SYSTEM
963 static void update_tool_bar
P_ ((struct frame
*, int));
964 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
965 static int redisplay_tool_bar
P_ ((struct frame
*));
966 static void display_tool_bar_line
P_ ((struct it
*));
967 static void notice_overwritten_cursor
P_ ((struct window
*,
969 int, int, int, int));
973 #endif /* HAVE_WINDOW_SYSTEM */
976 /***********************************************************************
977 Window display dimensions
978 ***********************************************************************/
980 /* Return the bottom boundary y-position for text lines in window W.
981 This is the first y position at which a line cannot start.
982 It is relative to the top of the window.
984 This is the height of W minus the height of a mode line, if any. */
987 window_text_bottom_y (w
)
990 int height
= WINDOW_TOTAL_HEIGHT (w
);
992 if (WINDOW_WANTS_MODELINE_P (w
))
993 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
997 /* Return the pixel width of display area AREA of window W. AREA < 0
998 means return the total width of W, not including fringes to
999 the left and right of the window. */
1002 window_box_width (w
, area
)
1006 int cols
= XFASTINT (w
->total_cols
);
1009 if (!w
->pseudo_window_p
)
1011 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1013 if (area
== TEXT_AREA
)
1015 if (INTEGERP (w
->left_margin_cols
))
1016 cols
-= XFASTINT (w
->left_margin_cols
);
1017 if (INTEGERP (w
->right_margin_cols
))
1018 cols
-= XFASTINT (w
->right_margin_cols
);
1019 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1021 else if (area
== LEFT_MARGIN_AREA
)
1023 cols
= (INTEGERP (w
->left_margin_cols
)
1024 ? XFASTINT (w
->left_margin_cols
) : 0);
1027 else if (area
== RIGHT_MARGIN_AREA
)
1029 cols
= (INTEGERP (w
->right_margin_cols
)
1030 ? XFASTINT (w
->right_margin_cols
) : 0);
1035 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1039 /* Return the pixel height of the display area of window W, not
1040 including mode lines of W, if any. */
1043 window_box_height (w
)
1046 struct frame
*f
= XFRAME (w
->frame
);
1047 int height
= WINDOW_TOTAL_HEIGHT (w
);
1049 xassert (height
>= 0);
1051 /* Note: the code below that determines the mode-line/header-line
1052 height is essentially the same as that contained in the macro
1053 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1054 the appropriate glyph row has its `mode_line_p' flag set,
1055 and if it doesn't, uses estimate_mode_line_height instead. */
1057 if (WINDOW_WANTS_MODELINE_P (w
))
1059 struct glyph_row
*ml_row
1060 = (w
->current_matrix
&& w
->current_matrix
->rows
1061 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1063 if (ml_row
&& ml_row
->mode_line_p
)
1064 height
-= ml_row
->height
;
1066 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1069 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1071 struct glyph_row
*hl_row
1072 = (w
->current_matrix
&& w
->current_matrix
->rows
1073 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1075 if (hl_row
&& hl_row
->mode_line_p
)
1076 height
-= hl_row
->height
;
1078 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1081 /* With a very small font and a mode-line that's taller than
1082 default, we might end up with a negative height. */
1083 return max (0, height
);
1086 /* Return the window-relative coordinate of the left edge of display
1087 area AREA of window W. AREA < 0 means return the left edge of the
1088 whole window, to the right of the left fringe of W. */
1091 window_box_left_offset (w
, area
)
1097 if (w
->pseudo_window_p
)
1100 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1102 if (area
== TEXT_AREA
)
1103 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1104 + window_box_width (w
, LEFT_MARGIN_AREA
));
1105 else if (area
== RIGHT_MARGIN_AREA
)
1106 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1107 + window_box_width (w
, LEFT_MARGIN_AREA
)
1108 + window_box_width (w
, TEXT_AREA
)
1109 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1111 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1112 else if (area
== LEFT_MARGIN_AREA
1113 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1114 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1120 /* Return the window-relative coordinate of the right edge of display
1121 area AREA of window W. AREA < 0 means return the left edge of the
1122 whole window, to the left of the right fringe of W. */
1125 window_box_right_offset (w
, area
)
1129 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1132 /* Return the frame-relative coordinate of the left edge of display
1133 area AREA of window W. AREA < 0 means return the left edge of the
1134 whole window, to the right of the left fringe of W. */
1137 window_box_left (w
, area
)
1141 struct frame
*f
= XFRAME (w
->frame
);
1144 if (w
->pseudo_window_p
)
1145 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1147 x
= (WINDOW_LEFT_EDGE_X (w
)
1148 + window_box_left_offset (w
, area
));
1154 /* Return the frame-relative coordinate of the right edge of display
1155 area AREA of window W. AREA < 0 means return the left edge of the
1156 whole window, to the left of the right fringe of W. */
1159 window_box_right (w
, area
)
1163 return window_box_left (w
, area
) + window_box_width (w
, area
);
1166 /* Get the bounding box of the display area AREA of window W, without
1167 mode lines, in frame-relative coordinates. AREA < 0 means the
1168 whole window, not including the left and right fringes of
1169 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1170 coordinates of the upper-left corner of the box. Return in
1171 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1174 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1177 int *box_x
, *box_y
, *box_width
, *box_height
;
1180 *box_width
= window_box_width (w
, area
);
1182 *box_height
= window_box_height (w
);
1184 *box_x
= window_box_left (w
, area
);
1187 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1188 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1189 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1194 /* Get the bounding box of the display area AREA of window W, without
1195 mode lines. AREA < 0 means the whole window, not including the
1196 left and right fringe of the window. Return in *TOP_LEFT_X
1197 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1198 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1199 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1203 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1204 bottom_right_x
, bottom_right_y
)
1207 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1209 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1211 *bottom_right_x
+= *top_left_x
;
1212 *bottom_right_y
+= *top_left_y
;
1217 /***********************************************************************
1219 ***********************************************************************/
1221 /* Return the bottom y-position of the line the iterator IT is in.
1222 This can modify IT's settings. */
1228 int line_height
= it
->max_ascent
+ it
->max_descent
;
1229 int line_top_y
= it
->current_y
;
1231 if (line_height
== 0)
1234 line_height
= last_height
;
1235 else if (IT_CHARPOS (*it
) < ZV
)
1237 move_it_by_lines (it
, 1, 1);
1238 line_height
= (it
->max_ascent
|| it
->max_descent
1239 ? it
->max_ascent
+ it
->max_descent
1244 struct glyph_row
*row
= it
->glyph_row
;
1246 /* Use the default character height. */
1247 it
->glyph_row
= NULL
;
1248 it
->what
= IT_CHARACTER
;
1251 PRODUCE_GLYPHS (it
);
1252 line_height
= it
->ascent
+ it
->descent
;
1253 it
->glyph_row
= row
;
1257 return line_top_y
+ line_height
;
1261 /* Return 1 if position CHARPOS is visible in window W.
1262 If visible, set *X and *Y to pixel coordinates of top left corner.
1263 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1264 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1265 and header-lines heights. */
1268 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1270 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1273 struct text_pos top
;
1275 struct buffer
*old_buffer
= NULL
;
1280 if (XBUFFER (w
->buffer
) != current_buffer
)
1282 old_buffer
= current_buffer
;
1283 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1286 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1288 /* Compute exact mode line heights, if requested. */
1289 if (exact_mode_line_heights_p
)
1291 if (WINDOW_WANTS_MODELINE_P (w
))
1292 current_mode_line_height
1293 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1294 current_buffer
->mode_line_format
);
1296 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1297 current_header_line_height
1298 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1299 current_buffer
->header_line_format
);
1302 start_display (&it
, w
, top
);
1303 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1304 MOVE_TO_POS
| MOVE_TO_Y
);
1306 /* Note that we may overshoot because of invisible text. */
1307 if (IT_CHARPOS (it
) >= charpos
)
1309 int top_x
= it
.current_x
;
1310 int top_y
= it
.current_y
;
1311 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1312 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1314 if (top_y
< window_top_y
)
1315 visible_p
= bottom_y
> window_top_y
;
1316 else if (top_y
< it
.last_visible_y
)
1321 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1322 *rtop
= max (0, window_top_y
- top_y
);
1323 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1331 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1332 move_it_by_lines (&it
, 1, 0);
1333 if (charpos
< IT_CHARPOS (it
))
1336 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1338 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1339 *rtop
= max (0, -it2
.current_y
);
1340 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1341 - it
.last_visible_y
));
1346 set_buffer_internal_1 (old_buffer
);
1348 current_header_line_height
= current_mode_line_height
= -1;
1350 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1351 *x
-= XFASTINT (w
->hscroll
);
1357 /* Return the next character from STR which is MAXLEN bytes long.
1358 Return in *LEN the length of the character. This is like
1359 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1360 we find one, we return a `?', but with the length of the invalid
1364 string_char_and_length (str
, maxlen
, len
)
1365 const unsigned char *str
;
1370 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1371 if (!CHAR_VALID_P (c
, 1))
1372 /* We may not change the length here because other places in Emacs
1373 don't use this function, i.e. they silently accept invalid
1382 /* Given a position POS containing a valid character and byte position
1383 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1385 static struct text_pos
1386 string_pos_nchars_ahead (pos
, string
, nchars
)
1387 struct text_pos pos
;
1391 xassert (STRINGP (string
) && nchars
>= 0);
1393 if (STRING_MULTIBYTE (string
))
1395 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1396 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1401 string_char_and_length (p
, rest
, &len
);
1402 p
+= len
, rest
-= len
;
1403 xassert (rest
>= 0);
1405 BYTEPOS (pos
) += len
;
1409 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1415 /* Value is the text position, i.e. character and byte position,
1416 for character position CHARPOS in STRING. */
1418 static INLINE
struct text_pos
1419 string_pos (charpos
, string
)
1423 struct text_pos pos
;
1424 xassert (STRINGP (string
));
1425 xassert (charpos
>= 0);
1426 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1431 /* Value is a text position, i.e. character and byte position, for
1432 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1433 means recognize multibyte characters. */
1435 static struct text_pos
1436 c_string_pos (charpos
, s
, multibyte_p
)
1441 struct text_pos pos
;
1443 xassert (s
!= NULL
);
1444 xassert (charpos
>= 0);
1448 int rest
= strlen (s
), len
;
1450 SET_TEXT_POS (pos
, 0, 0);
1453 string_char_and_length (s
, rest
, &len
);
1454 s
+= len
, rest
-= len
;
1455 xassert (rest
>= 0);
1457 BYTEPOS (pos
) += len
;
1461 SET_TEXT_POS (pos
, charpos
, charpos
);
1467 /* Value is the number of characters in C string S. MULTIBYTE_P
1468 non-zero means recognize multibyte characters. */
1471 number_of_chars (s
, multibyte_p
)
1479 int rest
= strlen (s
), len
;
1480 unsigned char *p
= (unsigned char *) s
;
1482 for (nchars
= 0; rest
> 0; ++nchars
)
1484 string_char_and_length (p
, rest
, &len
);
1485 rest
-= len
, p
+= len
;
1489 nchars
= strlen (s
);
1495 /* Compute byte position NEWPOS->bytepos corresponding to
1496 NEWPOS->charpos. POS is a known position in string STRING.
1497 NEWPOS->charpos must be >= POS.charpos. */
1500 compute_string_pos (newpos
, pos
, string
)
1501 struct text_pos
*newpos
, pos
;
1504 xassert (STRINGP (string
));
1505 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1507 if (STRING_MULTIBYTE (string
))
1508 *newpos
= string_pos_nchars_ahead (pos
, string
,
1509 CHARPOS (*newpos
) - CHARPOS (pos
));
1511 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1515 Return an estimation of the pixel height of mode or top lines on
1516 frame F. FACE_ID specifies what line's height to estimate. */
1519 estimate_mode_line_height (f
, face_id
)
1521 enum face_id face_id
;
1523 #ifdef HAVE_WINDOW_SYSTEM
1524 if (FRAME_WINDOW_P (f
))
1526 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1528 /* This function is called so early when Emacs starts that the face
1529 cache and mode line face are not yet initialized. */
1530 if (FRAME_FACE_CACHE (f
))
1532 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1536 height
= FONT_HEIGHT (face
->font
);
1537 if (face
->box_line_width
> 0)
1538 height
+= 2 * face
->box_line_width
;
1549 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1550 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1551 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1552 not force the value into range. */
1555 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1557 register int pix_x
, pix_y
;
1559 NativeRectangle
*bounds
;
1563 #ifdef HAVE_WINDOW_SYSTEM
1564 if (FRAME_WINDOW_P (f
))
1566 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1567 even for negative values. */
1569 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1571 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1573 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1574 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1577 STORE_NATIVE_RECT (*bounds
,
1578 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1579 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1580 FRAME_COLUMN_WIDTH (f
) - 1,
1581 FRAME_LINE_HEIGHT (f
) - 1);
1587 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1588 pix_x
= FRAME_TOTAL_COLS (f
);
1592 else if (pix_y
> FRAME_LINES (f
))
1593 pix_y
= FRAME_LINES (f
);
1603 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1604 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1605 can't tell the positions because W's display is not up to date,
1609 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1612 int *frame_x
, *frame_y
;
1614 #ifdef HAVE_WINDOW_SYSTEM
1615 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1619 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1620 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1622 if (display_completed
)
1624 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1625 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1626 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1632 hpos
+= glyph
->pixel_width
;
1636 /* If first glyph is partially visible, its first visible position is still 0. */
1648 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1649 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1660 #ifdef HAVE_WINDOW_SYSTEM
1662 /* Find the glyph under window-relative coordinates X/Y in window W.
1663 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1664 strings. Return in *HPOS and *VPOS the row and column number of
1665 the glyph found. Return in *AREA the glyph area containing X.
1666 Value is a pointer to the glyph found or null if X/Y is not on
1667 text, or we can't tell because W's current matrix is not up to
1670 static struct glyph
*
1671 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1674 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1676 struct glyph
*glyph
, *end
;
1677 struct glyph_row
*row
= NULL
;
1680 /* Find row containing Y. Give up if some row is not enabled. */
1681 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1683 row
= MATRIX_ROW (w
->current_matrix
, i
);
1684 if (!row
->enabled_p
)
1686 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1693 /* Give up if Y is not in the window. */
1694 if (i
== w
->current_matrix
->nrows
)
1697 /* Get the glyph area containing X. */
1698 if (w
->pseudo_window_p
)
1705 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1707 *area
= LEFT_MARGIN_AREA
;
1708 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1710 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1713 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1717 *area
= RIGHT_MARGIN_AREA
;
1718 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1722 /* Find glyph containing X. */
1723 glyph
= row
->glyphs
[*area
];
1724 end
= glyph
+ row
->used
[*area
];
1726 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1728 x
-= glyph
->pixel_width
;
1738 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1741 *hpos
= glyph
- row
->glyphs
[*area
];
1747 Convert frame-relative x/y to coordinates relative to window W.
1748 Takes pseudo-windows into account. */
1751 frame_to_window_pixel_xy (w
, x
, y
)
1755 if (w
->pseudo_window_p
)
1757 /* A pseudo-window is always full-width, and starts at the
1758 left edge of the frame, plus a frame border. */
1759 struct frame
*f
= XFRAME (w
->frame
);
1760 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1761 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1765 *x
-= WINDOW_LEFT_EDGE_X (w
);
1766 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1771 Return in *R the clipping rectangle for glyph string S. */
1774 get_glyph_string_clip_rect (s
, nr
)
1775 struct glyph_string
*s
;
1776 NativeRectangle
*nr
;
1780 if (s
->row
->full_width_p
)
1782 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1783 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1784 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1786 /* Unless displaying a mode or menu bar line, which are always
1787 fully visible, clip to the visible part of the row. */
1788 if (s
->w
->pseudo_window_p
)
1789 r
.height
= s
->row
->visible_height
;
1791 r
.height
= s
->height
;
1795 /* This is a text line that may be partially visible. */
1796 r
.x
= window_box_left (s
->w
, s
->area
);
1797 r
.width
= window_box_width (s
->w
, s
->area
);
1798 r
.height
= s
->row
->visible_height
;
1802 if (r
.x
< s
->clip_head
->x
)
1804 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1805 r
.width
-= s
->clip_head
->x
- r
.x
;
1808 r
.x
= s
->clip_head
->x
;
1811 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1813 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1814 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1819 /* If S draws overlapping rows, it's sufficient to use the top and
1820 bottom of the window for clipping because this glyph string
1821 intentionally draws over other lines. */
1822 if (s
->for_overlaps_p
)
1824 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1825 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1829 /* Don't use S->y for clipping because it doesn't take partially
1830 visible lines into account. For example, it can be negative for
1831 partially visible lines at the top of a window. */
1832 if (!s
->row
->full_width_p
1833 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1834 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1836 r
.y
= max (0, s
->row
->y
);
1838 /* If drawing a tool-bar window, draw it over the internal border
1839 at the top of the window. */
1840 if (WINDOWP (s
->f
->tool_bar_window
)
1841 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1842 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1845 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1847 /* If drawing the cursor, don't let glyph draw outside its
1848 advertised boundaries. Cleartype does this under some circumstances. */
1849 if (s
->hl
== DRAW_CURSOR
)
1851 struct glyph
*glyph
= s
->first_glyph
;
1856 r
.width
-= s
->x
- r
.x
;
1859 r
.width
= min (r
.width
, glyph
->pixel_width
);
1861 /* If r.y is below window bottom, ensure that we still see a cursor. */
1862 height
= min (glyph
->ascent
+ glyph
->descent
,
1863 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1864 max_y
= window_text_bottom_y (s
->w
) - height
;
1865 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1866 if (s
->ybase
- glyph
->ascent
> max_y
)
1873 /* Don't draw cursor glyph taller than our actual glyph. */
1874 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1875 if (height
< r
.height
)
1877 max_y
= r
.y
+ r
.height
;
1878 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1879 r
.height
= min (max_y
- r
.y
, height
);
1884 #ifdef CONVERT_FROM_XRECT
1885 CONVERT_FROM_XRECT (r
, *nr
);
1893 Return the position and height of the phys cursor in window W.
1894 Set w->phys_cursor_width to width of phys cursor.
1898 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1900 struct glyph_row
*row
;
1901 struct glyph
*glyph
;
1904 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1905 int y
, wd
, h
, h0
, y0
;
1907 /* Compute the width of the rectangle to draw. If on a stretch
1908 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1909 rectangle as wide as the glyph, but use a canonical character
1911 wd
= glyph
->pixel_width
- 1;
1915 if (glyph
->type
== STRETCH_GLYPH
1916 && !x_stretch_cursor_p
)
1917 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1918 w
->phys_cursor_width
= wd
;
1920 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1922 /* If y is below window bottom, ensure that we still see a cursor. */
1923 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1925 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1926 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1928 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1931 h
= max (h
- (y0
- y
) + 1, h0
);
1936 y0
= window_text_bottom_y (w
) - h0
;
1945 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1949 #endif /* HAVE_WINDOW_SYSTEM */
1952 /***********************************************************************
1953 Lisp form evaluation
1954 ***********************************************************************/
1956 /* Error handler for safe_eval and safe_call. */
1959 safe_eval_handler (arg
)
1962 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1967 /* Evaluate SEXPR and return the result, or nil if something went
1968 wrong. Prevent redisplay during the evaluation. */
1976 if (inhibit_eval_during_redisplay
)
1980 int count
= SPECPDL_INDEX ();
1981 struct gcpro gcpro1
;
1984 specbind (Qinhibit_redisplay
, Qt
);
1985 /* Use Qt to ensure debugger does not run,
1986 so there is no possibility of wanting to redisplay. */
1987 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1990 val
= unbind_to (count
, val
);
1997 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1998 Return the result, or nil if something went wrong. Prevent
1999 redisplay during the evaluation. */
2002 safe_call (nargs
, args
)
2008 if (inhibit_eval_during_redisplay
)
2012 int count
= SPECPDL_INDEX ();
2013 struct gcpro gcpro1
;
2016 gcpro1
.nvars
= nargs
;
2017 specbind (Qinhibit_redisplay
, Qt
);
2018 /* Use Qt to ensure debugger does not run,
2019 so there is no possibility of wanting to redisplay. */
2020 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2023 val
= unbind_to (count
, val
);
2030 /* Call function FN with one argument ARG.
2031 Return the result, or nil if something went wrong. */
2034 safe_call1 (fn
, arg
)
2035 Lisp_Object fn
, arg
;
2037 Lisp_Object args
[2];
2040 return safe_call (2, args
);
2045 /***********************************************************************
2047 ***********************************************************************/
2051 /* Define CHECK_IT to perform sanity checks on iterators.
2052 This is for debugging. It is too slow to do unconditionally. */
2058 if (it
->method
== GET_FROM_STRING
)
2060 xassert (STRINGP (it
->string
));
2061 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2065 xassert (IT_STRING_CHARPOS (*it
) < 0);
2066 if (it
->method
== GET_FROM_BUFFER
)
2068 /* Check that character and byte positions agree. */
2069 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2074 xassert (it
->current
.dpvec_index
>= 0);
2076 xassert (it
->current
.dpvec_index
< 0);
2079 #define CHECK_IT(IT) check_it ((IT))
2083 #define CHECK_IT(IT) (void) 0
2090 /* Check that the window end of window W is what we expect it
2091 to be---the last row in the current matrix displaying text. */
2094 check_window_end (w
)
2097 if (!MINI_WINDOW_P (w
)
2098 && !NILP (w
->window_end_valid
))
2100 struct glyph_row
*row
;
2101 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2102 XFASTINT (w
->window_end_vpos
)),
2104 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2105 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2109 #define CHECK_WINDOW_END(W) check_window_end ((W))
2111 #else /* not GLYPH_DEBUG */
2113 #define CHECK_WINDOW_END(W) (void) 0
2115 #endif /* not GLYPH_DEBUG */
2119 /***********************************************************************
2120 Iterator initialization
2121 ***********************************************************************/
2123 /* Initialize IT for displaying current_buffer in window W, starting
2124 at character position CHARPOS. CHARPOS < 0 means that no buffer
2125 position is specified which is useful when the iterator is assigned
2126 a position later. BYTEPOS is the byte position corresponding to
2127 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2129 If ROW is not null, calls to produce_glyphs with IT as parameter
2130 will produce glyphs in that row.
2132 BASE_FACE_ID is the id of a base face to use. It must be one of
2133 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2134 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2135 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2137 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2138 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2139 will be initialized to use the corresponding mode line glyph row of
2140 the desired matrix of W. */
2143 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2146 int charpos
, bytepos
;
2147 struct glyph_row
*row
;
2148 enum face_id base_face_id
;
2150 int highlight_region_p
;
2152 /* Some precondition checks. */
2153 xassert (w
!= NULL
&& it
!= NULL
);
2154 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2157 /* If face attributes have been changed since the last redisplay,
2158 free realized faces now because they depend on face definitions
2159 that might have changed. Don't free faces while there might be
2160 desired matrices pending which reference these faces. */
2161 if (face_change_count
&& !inhibit_free_realized_faces
)
2163 face_change_count
= 0;
2164 free_all_realized_faces (Qnil
);
2167 /* Use one of the mode line rows of W's desired matrix if
2171 if (base_face_id
== MODE_LINE_FACE_ID
2172 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2173 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2174 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2175 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2179 bzero (it
, sizeof *it
);
2180 it
->current
.overlay_string_index
= -1;
2181 it
->current
.dpvec_index
= -1;
2182 it
->base_face_id
= base_face_id
;
2184 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2186 /* The window in which we iterate over current_buffer: */
2187 XSETWINDOW (it
->window
, w
);
2189 it
->f
= XFRAME (w
->frame
);
2191 /* Extra space between lines (on window systems only). */
2192 if (base_face_id
== DEFAULT_FACE_ID
2193 && FRAME_WINDOW_P (it
->f
))
2195 if (NATNUMP (current_buffer
->extra_line_spacing
))
2196 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2197 else if (FLOATP (current_buffer
->extra_line_spacing
))
2198 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2199 * FRAME_LINE_HEIGHT (it
->f
));
2200 else if (it
->f
->extra_line_spacing
> 0)
2201 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2202 it
->max_extra_line_spacing
= 0;
2205 /* If realized faces have been removed, e.g. because of face
2206 attribute changes of named faces, recompute them. When running
2207 in batch mode, the face cache of Vterminal_frame is null. If
2208 we happen to get called, make a dummy face cache. */
2209 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2210 init_frame_faces (it
->f
);
2211 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2212 recompute_basic_faces (it
->f
);
2214 /* Current value of the `slice', `space-width', and 'height' properties. */
2215 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2216 it
->space_width
= Qnil
;
2217 it
->font_height
= Qnil
;
2218 it
->override_ascent
= -1;
2220 /* Are control characters displayed as `^C'? */
2221 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2223 /* -1 means everything between a CR and the following line end
2224 is invisible. >0 means lines indented more than this value are
2226 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2227 ? XFASTINT (current_buffer
->selective_display
)
2228 : (!NILP (current_buffer
->selective_display
)
2230 it
->selective_display_ellipsis_p
2231 = !NILP (current_buffer
->selective_display_ellipses
);
2233 /* Display table to use. */
2234 it
->dp
= window_display_table (w
);
2236 /* Are multibyte characters enabled in current_buffer? */
2237 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2239 /* Non-zero if we should highlight the region. */
2241 = (!NILP (Vtransient_mark_mode
)
2242 && !NILP (current_buffer
->mark_active
)
2243 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2245 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2246 start and end of a visible region in window IT->w. Set both to
2247 -1 to indicate no region. */
2248 if (highlight_region_p
2249 /* Maybe highlight only in selected window. */
2250 && (/* Either show region everywhere. */
2251 highlight_nonselected_windows
2252 /* Or show region in the selected window. */
2253 || w
== XWINDOW (selected_window
)
2254 /* Or show the region if we are in the mini-buffer and W is
2255 the window the mini-buffer refers to. */
2256 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2257 && WINDOWP (minibuf_selected_window
)
2258 && w
== XWINDOW (minibuf_selected_window
))))
2260 int charpos
= marker_position (current_buffer
->mark
);
2261 it
->region_beg_charpos
= min (PT
, charpos
);
2262 it
->region_end_charpos
= max (PT
, charpos
);
2265 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2267 /* Get the position at which the redisplay_end_trigger hook should
2268 be run, if it is to be run at all. */
2269 if (MARKERP (w
->redisplay_end_trigger
)
2270 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2271 it
->redisplay_end_trigger_charpos
2272 = marker_position (w
->redisplay_end_trigger
);
2273 else if (INTEGERP (w
->redisplay_end_trigger
))
2274 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2276 /* Correct bogus values of tab_width. */
2277 it
->tab_width
= XINT (current_buffer
->tab_width
);
2278 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2281 /* Are lines in the display truncated? */
2282 it
->truncate_lines_p
2283 = (base_face_id
!= DEFAULT_FACE_ID
2284 || XINT (it
->w
->hscroll
)
2285 || (truncate_partial_width_windows
2286 && !WINDOW_FULL_WIDTH_P (it
->w
))
2287 || !NILP (current_buffer
->truncate_lines
));
2289 /* Get dimensions of truncation and continuation glyphs. These are
2290 displayed as fringe bitmaps under X, so we don't need them for such
2292 if (!FRAME_WINDOW_P (it
->f
))
2294 if (it
->truncate_lines_p
)
2296 /* We will need the truncation glyph. */
2297 xassert (it
->glyph_row
== NULL
);
2298 produce_special_glyphs (it
, IT_TRUNCATION
);
2299 it
->truncation_pixel_width
= it
->pixel_width
;
2303 /* We will need the continuation glyph. */
2304 xassert (it
->glyph_row
== NULL
);
2305 produce_special_glyphs (it
, IT_CONTINUATION
);
2306 it
->continuation_pixel_width
= it
->pixel_width
;
2309 /* Reset these values to zero because the produce_special_glyphs
2310 above has changed them. */
2311 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2312 it
->phys_ascent
= it
->phys_descent
= 0;
2315 /* Set this after getting the dimensions of truncation and
2316 continuation glyphs, so that we don't produce glyphs when calling
2317 produce_special_glyphs, above. */
2318 it
->glyph_row
= row
;
2319 it
->area
= TEXT_AREA
;
2321 /* Get the dimensions of the display area. The display area
2322 consists of the visible window area plus a horizontally scrolled
2323 part to the left of the window. All x-values are relative to the
2324 start of this total display area. */
2325 if (base_face_id
!= DEFAULT_FACE_ID
)
2327 /* Mode lines, menu bar in terminal frames. */
2328 it
->first_visible_x
= 0;
2329 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2334 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2335 it
->last_visible_x
= (it
->first_visible_x
2336 + window_box_width (w
, TEXT_AREA
));
2338 /* If we truncate lines, leave room for the truncator glyph(s) at
2339 the right margin. Otherwise, leave room for the continuation
2340 glyph(s). Truncation and continuation glyphs are not inserted
2341 for window-based redisplay. */
2342 if (!FRAME_WINDOW_P (it
->f
))
2344 if (it
->truncate_lines_p
)
2345 it
->last_visible_x
-= it
->truncation_pixel_width
;
2347 it
->last_visible_x
-= it
->continuation_pixel_width
;
2350 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2351 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2354 /* Leave room for a border glyph. */
2355 if (!FRAME_WINDOW_P (it
->f
)
2356 && !WINDOW_RIGHTMOST_P (it
->w
))
2357 it
->last_visible_x
-= 1;
2359 it
->last_visible_y
= window_text_bottom_y (w
);
2361 /* For mode lines and alike, arrange for the first glyph having a
2362 left box line if the face specifies a box. */
2363 if (base_face_id
!= DEFAULT_FACE_ID
)
2367 it
->face_id
= base_face_id
;
2369 /* If we have a boxed mode line, make the first character appear
2370 with a left box line. */
2371 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2372 if (face
->box
!= FACE_NO_BOX
)
2373 it
->start_of_box_run_p
= 1;
2376 /* If a buffer position was specified, set the iterator there,
2377 getting overlays and face properties from that position. */
2378 if (charpos
>= BUF_BEG (current_buffer
))
2380 it
->end_charpos
= ZV
;
2382 IT_CHARPOS (*it
) = charpos
;
2384 /* Compute byte position if not specified. */
2385 if (bytepos
< charpos
)
2386 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2388 IT_BYTEPOS (*it
) = bytepos
;
2390 it
->start
= it
->current
;
2392 /* Compute faces etc. */
2393 reseat (it
, it
->current
.pos
, 1);
2400 /* Initialize IT for the display of window W with window start POS. */
2403 start_display (it
, w
, pos
)
2406 struct text_pos pos
;
2408 struct glyph_row
*row
;
2409 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2411 row
= w
->desired_matrix
->rows
+ first_vpos
;
2412 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2413 it
->first_vpos
= first_vpos
;
2415 /* Don't reseat to previous visible line start if current start
2416 position is in a string or image. */
2417 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2419 int start_at_line_beg_p
;
2420 int first_y
= it
->current_y
;
2422 /* If window start is not at a line start, skip forward to POS to
2423 get the correct continuation lines width. */
2424 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2425 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2426 if (!start_at_line_beg_p
)
2430 reseat_at_previous_visible_line_start (it
);
2431 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2433 new_x
= it
->current_x
+ it
->pixel_width
;
2435 /* If lines are continued, this line may end in the middle
2436 of a multi-glyph character (e.g. a control character
2437 displayed as \003, or in the middle of an overlay
2438 string). In this case move_it_to above will not have
2439 taken us to the start of the continuation line but to the
2440 end of the continued line. */
2441 if (it
->current_x
> 0
2442 && !it
->truncate_lines_p
/* Lines are continued. */
2443 && (/* And glyph doesn't fit on the line. */
2444 new_x
> it
->last_visible_x
2445 /* Or it fits exactly and we're on a window
2447 || (new_x
== it
->last_visible_x
2448 && FRAME_WINDOW_P (it
->f
))))
2450 if (it
->current
.dpvec_index
>= 0
2451 || it
->current
.overlay_string_index
>= 0)
2453 set_iterator_to_next (it
, 1);
2454 move_it_in_display_line_to (it
, -1, -1, 0);
2457 it
->continuation_lines_width
+= it
->current_x
;
2460 /* We're starting a new display line, not affected by the
2461 height of the continued line, so clear the appropriate
2462 fields in the iterator structure. */
2463 it
->max_ascent
= it
->max_descent
= 0;
2464 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2466 it
->current_y
= first_y
;
2468 it
->current_x
= it
->hpos
= 0;
2472 #if 0 /* Don't assert the following because start_display is sometimes
2473 called intentionally with a window start that is not at a
2474 line start. Please leave this code in as a comment. */
2476 /* Window start should be on a line start, now. */
2477 xassert (it
->continuation_lines_width
2478 || IT_CHARPOS (it
) == BEGV
2479 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2484 /* Return 1 if POS is a position in ellipses displayed for invisible
2485 text. W is the window we display, for text property lookup. */
2488 in_ellipses_for_invisible_text_p (pos
, w
)
2489 struct display_pos
*pos
;
2492 Lisp_Object prop
, window
;
2494 int charpos
= CHARPOS (pos
->pos
);
2496 /* If POS specifies a position in a display vector, this might
2497 be for an ellipsis displayed for invisible text. We won't
2498 get the iterator set up for delivering that ellipsis unless
2499 we make sure that it gets aware of the invisible text. */
2500 if (pos
->dpvec_index
>= 0
2501 && pos
->overlay_string_index
< 0
2502 && CHARPOS (pos
->string_pos
) < 0
2504 && (XSETWINDOW (window
, w
),
2505 prop
= Fget_char_property (make_number (charpos
),
2506 Qinvisible
, window
),
2507 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2509 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2511 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2518 /* Initialize IT for stepping through current_buffer in window W,
2519 starting at position POS that includes overlay string and display
2520 vector/ control character translation position information. Value
2521 is zero if there are overlay strings with newlines at POS. */
2524 init_from_display_pos (it
, w
, pos
)
2527 struct display_pos
*pos
;
2529 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2530 int i
, overlay_strings_with_newlines
= 0;
2532 /* If POS specifies a position in a display vector, this might
2533 be for an ellipsis displayed for invisible text. We won't
2534 get the iterator set up for delivering that ellipsis unless
2535 we make sure that it gets aware of the invisible text. */
2536 if (in_ellipses_for_invisible_text_p (pos
, w
))
2542 /* Keep in mind: the call to reseat in init_iterator skips invisible
2543 text, so we might end up at a position different from POS. This
2544 is only a problem when POS is a row start after a newline and an
2545 overlay starts there with an after-string, and the overlay has an
2546 invisible property. Since we don't skip invisible text in
2547 display_line and elsewhere immediately after consuming the
2548 newline before the row start, such a POS will not be in a string,
2549 but the call to init_iterator below will move us to the
2551 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2553 /* This only scans the current chunk -- it should scan all chunks.
2554 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2555 to 16 in 22.1 to make this a lesser problem. */
2556 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2558 const char *s
= SDATA (it
->overlay_strings
[i
]);
2559 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2561 while (s
< e
&& *s
!= '\n')
2566 overlay_strings_with_newlines
= 1;
2571 /* If position is within an overlay string, set up IT to the right
2573 if (pos
->overlay_string_index
>= 0)
2577 /* If the first overlay string happens to have a `display'
2578 property for an image, the iterator will be set up for that
2579 image, and we have to undo that setup first before we can
2580 correct the overlay string index. */
2581 if (it
->method
== GET_FROM_IMAGE
)
2584 /* We already have the first chunk of overlay strings in
2585 IT->overlay_strings. Load more until the one for
2586 pos->overlay_string_index is in IT->overlay_strings. */
2587 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2589 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2590 it
->current
.overlay_string_index
= 0;
2593 load_overlay_strings (it
, 0);
2594 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2598 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2599 relative_index
= (it
->current
.overlay_string_index
2600 % OVERLAY_STRING_CHUNK_SIZE
);
2601 it
->string
= it
->overlay_strings
[relative_index
];
2602 xassert (STRINGP (it
->string
));
2603 it
->current
.string_pos
= pos
->string_pos
;
2604 it
->method
= GET_FROM_STRING
;
2607 #if 0 /* This is bogus because POS not having an overlay string
2608 position does not mean it's after the string. Example: A
2609 line starting with a before-string and initialization of IT
2610 to the previous row's end position. */
2611 else if (it
->current
.overlay_string_index
>= 0)
2613 /* If POS says we're already after an overlay string ending at
2614 POS, make sure to pop the iterator because it will be in
2615 front of that overlay string. When POS is ZV, we've thereby
2616 also ``processed'' overlay strings at ZV. */
2619 it
->current
.overlay_string_index
= -1;
2620 it
->method
= GET_FROM_BUFFER
;
2621 if (CHARPOS (pos
->pos
) == ZV
)
2622 it
->overlay_strings_at_end_processed_p
= 1;
2626 if (CHARPOS (pos
->string_pos
) >= 0)
2628 /* Recorded position is not in an overlay string, but in another
2629 string. This can only be a string from a `display' property.
2630 IT should already be filled with that string. */
2631 it
->current
.string_pos
= pos
->string_pos
;
2632 xassert (STRINGP (it
->string
));
2635 /* Restore position in display vector translations, control
2636 character translations or ellipses. */
2637 if (pos
->dpvec_index
>= 0)
2639 if (it
->dpvec
== NULL
)
2640 get_next_display_element (it
);
2641 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2642 it
->current
.dpvec_index
= pos
->dpvec_index
;
2646 return !overlay_strings_with_newlines
;
2650 /* Initialize IT for stepping through current_buffer in window W
2651 starting at ROW->start. */
2654 init_to_row_start (it
, w
, row
)
2657 struct glyph_row
*row
;
2659 init_from_display_pos (it
, w
, &row
->start
);
2660 it
->start
= row
->start
;
2661 it
->continuation_lines_width
= row
->continuation_lines_width
;
2666 /* Initialize IT for stepping through current_buffer in window W
2667 starting in the line following ROW, i.e. starting at ROW->end.
2668 Value is zero if there are overlay strings with newlines at ROW's
2672 init_to_row_end (it
, w
, row
)
2675 struct glyph_row
*row
;
2679 if (init_from_display_pos (it
, w
, &row
->end
))
2681 if (row
->continued_p
)
2682 it
->continuation_lines_width
2683 = row
->continuation_lines_width
+ row
->pixel_width
;
2694 /***********************************************************************
2696 ***********************************************************************/
2698 /* Called when IT reaches IT->stop_charpos. Handle text property and
2699 overlay changes. Set IT->stop_charpos to the next position where
2706 enum prop_handled handled
;
2707 int handle_overlay_change_p
= 1;
2711 it
->current
.dpvec_index
= -1;
2713 /* Use face of preceding text for ellipsis (if invisible) */
2714 if (it
->selective_display_ellipsis_p
)
2715 it
->saved_face_id
= it
->face_id
;
2719 handled
= HANDLED_NORMALLY
;
2721 /* Call text property handlers. */
2722 for (p
= it_props
; p
->handler
; ++p
)
2724 handled
= p
->handler (it
);
2726 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2728 else if (handled
== HANDLED_RETURN
)
2730 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2731 handle_overlay_change_p
= 0;
2734 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2736 /* Don't check for overlay strings below when set to deliver
2737 characters from a display vector. */
2738 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2739 handle_overlay_change_p
= 0;
2741 /* Handle overlay changes. */
2742 if (handle_overlay_change_p
)
2743 handled
= handle_overlay_change (it
);
2745 /* Determine where to stop next. */
2746 if (handled
== HANDLED_NORMALLY
)
2747 compute_stop_pos (it
);
2750 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2754 /* Compute IT->stop_charpos from text property and overlay change
2755 information for IT's current position. */
2758 compute_stop_pos (it
)
2761 register INTERVAL iv
, next_iv
;
2762 Lisp_Object object
, limit
, position
;
2764 /* If nowhere else, stop at the end. */
2765 it
->stop_charpos
= it
->end_charpos
;
2767 if (STRINGP (it
->string
))
2769 /* Strings are usually short, so don't limit the search for
2771 object
= it
->string
;
2773 position
= make_number (IT_STRING_CHARPOS (*it
));
2779 /* If next overlay change is in front of the current stop pos
2780 (which is IT->end_charpos), stop there. Note: value of
2781 next_overlay_change is point-max if no overlay change
2783 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2784 if (charpos
< it
->stop_charpos
)
2785 it
->stop_charpos
= charpos
;
2787 /* If showing the region, we have to stop at the region
2788 start or end because the face might change there. */
2789 if (it
->region_beg_charpos
> 0)
2791 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2792 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2793 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2794 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2797 /* Set up variables for computing the stop position from text
2798 property changes. */
2799 XSETBUFFER (object
, current_buffer
);
2800 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2801 position
= make_number (IT_CHARPOS (*it
));
2805 /* Get the interval containing IT's position. Value is a null
2806 interval if there isn't such an interval. */
2807 iv
= validate_interval_range (object
, &position
, &position
, 0);
2808 if (!NULL_INTERVAL_P (iv
))
2810 Lisp_Object values_here
[LAST_PROP_IDX
];
2813 /* Get properties here. */
2814 for (p
= it_props
; p
->handler
; ++p
)
2815 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2817 /* Look for an interval following iv that has different
2819 for (next_iv
= next_interval (iv
);
2820 (!NULL_INTERVAL_P (next_iv
)
2822 || XFASTINT (limit
) > next_iv
->position
));
2823 next_iv
= next_interval (next_iv
))
2825 for (p
= it_props
; p
->handler
; ++p
)
2827 Lisp_Object new_value
;
2829 new_value
= textget (next_iv
->plist
, *p
->name
);
2830 if (!EQ (values_here
[p
->idx
], new_value
))
2838 if (!NULL_INTERVAL_P (next_iv
))
2840 if (INTEGERP (limit
)
2841 && next_iv
->position
>= XFASTINT (limit
))
2842 /* No text property change up to limit. */
2843 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2845 /* Text properties change in next_iv. */
2846 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2850 xassert (STRINGP (it
->string
)
2851 || (it
->stop_charpos
>= BEGV
2852 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2856 /* Return the position of the next overlay change after POS in
2857 current_buffer. Value is point-max if no overlay change
2858 follows. This is like `next-overlay-change' but doesn't use
2862 next_overlay_change (pos
)
2867 Lisp_Object
*overlays
;
2870 /* Get all overlays at the given position. */
2871 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2873 /* If any of these overlays ends before endpos,
2874 use its ending point instead. */
2875 for (i
= 0; i
< noverlays
; ++i
)
2880 oend
= OVERLAY_END (overlays
[i
]);
2881 oendpos
= OVERLAY_POSITION (oend
);
2882 endpos
= min (endpos
, oendpos
);
2890 /***********************************************************************
2892 ***********************************************************************/
2894 /* Handle changes in the `fontified' property of the current buffer by
2895 calling hook functions from Qfontification_functions to fontify
2898 static enum prop_handled
2899 handle_fontified_prop (it
)
2902 Lisp_Object prop
, pos
;
2903 enum prop_handled handled
= HANDLED_NORMALLY
;
2905 /* Get the value of the `fontified' property at IT's current buffer
2906 position. (The `fontified' property doesn't have a special
2907 meaning in strings.) If the value is nil, call functions from
2908 Qfontification_functions. */
2909 if (!STRINGP (it
->string
)
2911 && !NILP (Vfontification_functions
)
2912 && !NILP (Vrun_hooks
)
2913 && (pos
= make_number (IT_CHARPOS (*it
)),
2914 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2917 int count
= SPECPDL_INDEX ();
2920 val
= Vfontification_functions
;
2921 specbind (Qfontification_functions
, Qnil
);
2923 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2924 safe_call1 (val
, pos
);
2927 Lisp_Object globals
, fn
;
2928 struct gcpro gcpro1
, gcpro2
;
2931 GCPRO2 (val
, globals
);
2933 for (; CONSP (val
); val
= XCDR (val
))
2939 /* A value of t indicates this hook has a local
2940 binding; it means to run the global binding too.
2941 In a global value, t should not occur. If it
2942 does, we must ignore it to avoid an endless
2944 for (globals
= Fdefault_value (Qfontification_functions
);
2946 globals
= XCDR (globals
))
2948 fn
= XCAR (globals
);
2950 safe_call1 (fn
, pos
);
2954 safe_call1 (fn
, pos
);
2960 unbind_to (count
, Qnil
);
2962 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2963 something. This avoids an endless loop if they failed to
2964 fontify the text for which reason ever. */
2965 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2966 handled
= HANDLED_RECOMPUTE_PROPS
;
2974 /***********************************************************************
2976 ***********************************************************************/
2978 /* Set up iterator IT from face properties at its current position.
2979 Called from handle_stop. */
2981 static enum prop_handled
2982 handle_face_prop (it
)
2985 int new_face_id
, next_stop
;
2987 if (!STRINGP (it
->string
))
2990 = face_at_buffer_position (it
->w
,
2992 it
->region_beg_charpos
,
2993 it
->region_end_charpos
,
2996 + TEXT_PROP_DISTANCE_LIMIT
),
2999 /* Is this a start of a run of characters with box face?
3000 Caveat: this can be called for a freshly initialized
3001 iterator; face_id is -1 in this case. We know that the new
3002 face will not change until limit, i.e. if the new face has a
3003 box, all characters up to limit will have one. But, as
3004 usual, we don't know whether limit is really the end. */
3005 if (new_face_id
!= it
->face_id
)
3007 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3009 /* If new face has a box but old face has not, this is
3010 the start of a run of characters with box, i.e. it has
3011 a shadow on the left side. The value of face_id of the
3012 iterator will be -1 if this is the initial call that gets
3013 the face. In this case, we have to look in front of IT's
3014 position and see whether there is a face != new_face_id. */
3015 it
->start_of_box_run_p
3016 = (new_face
->box
!= FACE_NO_BOX
3017 && (it
->face_id
>= 0
3018 || IT_CHARPOS (*it
) == BEG
3019 || new_face_id
!= face_before_it_pos (it
)));
3020 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3025 int base_face_id
, bufpos
;
3027 if (it
->current
.overlay_string_index
>= 0)
3028 bufpos
= IT_CHARPOS (*it
);
3032 /* For strings from a buffer, i.e. overlay strings or strings
3033 from a `display' property, use the face at IT's current
3034 buffer position as the base face to merge with, so that
3035 overlay strings appear in the same face as surrounding
3036 text, unless they specify their own faces. */
3037 base_face_id
= underlying_face_id (it
);
3039 new_face_id
= face_at_string_position (it
->w
,
3041 IT_STRING_CHARPOS (*it
),
3043 it
->region_beg_charpos
,
3044 it
->region_end_charpos
,
3048 #if 0 /* This shouldn't be neccessary. Let's check it. */
3049 /* If IT is used to display a mode line we would really like to
3050 use the mode line face instead of the frame's default face. */
3051 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3052 && new_face_id
== DEFAULT_FACE_ID
)
3053 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3056 /* Is this a start of a run of characters with box? Caveat:
3057 this can be called for a freshly allocated iterator; face_id
3058 is -1 is this case. We know that the new face will not
3059 change until the next check pos, i.e. if the new face has a
3060 box, all characters up to that position will have a
3061 box. But, as usual, we don't know whether that position
3062 is really the end. */
3063 if (new_face_id
!= it
->face_id
)
3065 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3066 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3068 /* If new face has a box but old face hasn't, this is the
3069 start of a run of characters with box, i.e. it has a
3070 shadow on the left side. */
3071 it
->start_of_box_run_p
3072 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3073 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3077 it
->face_id
= new_face_id
;
3078 return HANDLED_NORMALLY
;
3082 /* Return the ID of the face ``underlying'' IT's current position,
3083 which is in a string. If the iterator is associated with a
3084 buffer, return the face at IT's current buffer position.
3085 Otherwise, use the iterator's base_face_id. */
3088 underlying_face_id (it
)
3091 int face_id
= it
->base_face_id
, i
;
3093 xassert (STRINGP (it
->string
));
3095 for (i
= it
->sp
- 1; i
>= 0; --i
)
3096 if (NILP (it
->stack
[i
].string
))
3097 face_id
= it
->stack
[i
].face_id
;
3103 /* Compute the face one character before or after the current position
3104 of IT. BEFORE_P non-zero means get the face in front of IT's
3105 position. Value is the id of the face. */
3108 face_before_or_after_it_pos (it
, before_p
)
3113 int next_check_charpos
;
3114 struct text_pos pos
;
3116 xassert (it
->s
== NULL
);
3118 if (STRINGP (it
->string
))
3120 int bufpos
, base_face_id
;
3122 /* No face change past the end of the string (for the case
3123 we are padding with spaces). No face change before the
3125 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3126 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3129 /* Set pos to the position before or after IT's current position. */
3131 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3133 /* For composition, we must check the character after the
3135 pos
= (it
->what
== IT_COMPOSITION
3136 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3137 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3139 if (it
->current
.overlay_string_index
>= 0)
3140 bufpos
= IT_CHARPOS (*it
);
3144 base_face_id
= underlying_face_id (it
);
3146 /* Get the face for ASCII, or unibyte. */
3147 face_id
= face_at_string_position (it
->w
,
3151 it
->region_beg_charpos
,
3152 it
->region_end_charpos
,
3153 &next_check_charpos
,
3156 /* Correct the face for charsets different from ASCII. Do it
3157 for the multibyte case only. The face returned above is
3158 suitable for unibyte text if IT->string is unibyte. */
3159 if (STRING_MULTIBYTE (it
->string
))
3161 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3162 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3164 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3166 c
= string_char_and_length (p
, rest
, &len
);
3167 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3172 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3173 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3176 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3177 pos
= it
->current
.pos
;
3180 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3183 if (it
->what
== IT_COMPOSITION
)
3184 /* For composition, we must check the position after the
3186 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3188 INC_TEXT_POS (pos
, it
->multibyte_p
);
3191 /* Determine face for CHARSET_ASCII, or unibyte. */
3192 face_id
= face_at_buffer_position (it
->w
,
3194 it
->region_beg_charpos
,
3195 it
->region_end_charpos
,
3196 &next_check_charpos
,
3199 /* Correct the face for charsets different from ASCII. Do it
3200 for the multibyte case only. The face returned above is
3201 suitable for unibyte text if current_buffer is unibyte. */
3202 if (it
->multibyte_p
)
3204 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3205 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3206 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3215 /***********************************************************************
3217 ***********************************************************************/
3219 /* Set up iterator IT from invisible properties at its current
3220 position. Called from handle_stop. */
3222 static enum prop_handled
3223 handle_invisible_prop (it
)
3226 enum prop_handled handled
= HANDLED_NORMALLY
;
3228 if (STRINGP (it
->string
))
3230 extern Lisp_Object Qinvisible
;
3231 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3233 /* Get the value of the invisible text property at the
3234 current position. Value will be nil if there is no such
3236 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3237 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3240 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3242 handled
= HANDLED_RECOMPUTE_PROPS
;
3244 /* Get the position at which the next change of the
3245 invisible text property can be found in IT->string.
3246 Value will be nil if the property value is the same for
3247 all the rest of IT->string. */
3248 XSETINT (limit
, SCHARS (it
->string
));
3249 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3252 /* Text at current position is invisible. The next
3253 change in the property is at position end_charpos.
3254 Move IT's current position to that position. */
3255 if (INTEGERP (end_charpos
)
3256 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3258 struct text_pos old
;
3259 old
= it
->current
.string_pos
;
3260 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3261 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3265 /* The rest of the string is invisible. If this is an
3266 overlay string, proceed with the next overlay string
3267 or whatever comes and return a character from there. */
3268 if (it
->current
.overlay_string_index
>= 0)
3270 next_overlay_string (it
);
3271 /* Don't check for overlay strings when we just
3272 finished processing them. */
3273 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3277 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3278 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3285 int invis_p
, newpos
, next_stop
, start_charpos
;
3286 Lisp_Object pos
, prop
, overlay
;
3288 /* First of all, is there invisible text at this position? */
3289 start_charpos
= IT_CHARPOS (*it
);
3290 pos
= make_number (IT_CHARPOS (*it
));
3291 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3293 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3295 /* If we are on invisible text, skip over it. */
3296 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3298 /* Record whether we have to display an ellipsis for the
3300 int display_ellipsis_p
= invis_p
== 2;
3302 handled
= HANDLED_RECOMPUTE_PROPS
;
3304 /* Loop skipping over invisible text. The loop is left at
3305 ZV or with IT on the first char being visible again. */
3308 /* Try to skip some invisible text. Return value is the
3309 position reached which can be equal to IT's position
3310 if there is nothing invisible here. This skips both
3311 over invisible text properties and overlays with
3312 invisible property. */
3313 newpos
= skip_invisible (IT_CHARPOS (*it
),
3314 &next_stop
, ZV
, it
->window
);
3316 /* If we skipped nothing at all we weren't at invisible
3317 text in the first place. If everything to the end of
3318 the buffer was skipped, end the loop. */
3319 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3323 /* We skipped some characters but not necessarily
3324 all there are. Check if we ended up on visible
3325 text. Fget_char_property returns the property of
3326 the char before the given position, i.e. if we
3327 get invis_p = 0, this means that the char at
3328 newpos is visible. */
3329 pos
= make_number (newpos
);
3330 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3331 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3334 /* If we ended up on invisible text, proceed to
3335 skip starting with next_stop. */
3337 IT_CHARPOS (*it
) = next_stop
;
3341 /* The position newpos is now either ZV or on visible text. */
3342 IT_CHARPOS (*it
) = newpos
;
3343 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3345 /* If there are before-strings at the start of invisible
3346 text, and the text is invisible because of a text
3347 property, arrange to show before-strings because 20.x did
3348 it that way. (If the text is invisible because of an
3349 overlay property instead of a text property, this is
3350 already handled in the overlay code.) */
3352 && get_overlay_strings (it
, start_charpos
))
3354 handled
= HANDLED_RECOMPUTE_PROPS
;
3355 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3357 else if (display_ellipsis_p
)
3358 setup_for_ellipsis (it
, 0);
3366 /* Make iterator IT return `...' next.
3367 Replaces LEN characters from buffer. */
3370 setup_for_ellipsis (it
, len
)
3374 /* Use the display table definition for `...'. Invalid glyphs
3375 will be handled by the method returning elements from dpvec. */
3376 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3378 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3379 it
->dpvec
= v
->contents
;
3380 it
->dpend
= v
->contents
+ v
->size
;
3384 /* Default `...'. */
3385 it
->dpvec
= default_invis_vector
;
3386 it
->dpend
= default_invis_vector
+ 3;
3389 it
->dpvec_char_len
= len
;
3390 it
->current
.dpvec_index
= 0;
3391 it
->dpvec_face_id
= -1;
3393 /* Remember the current face id in case glyphs specify faces.
3394 IT's face is restored in set_iterator_to_next.
3395 saved_face_id was set to preceding char's face in handle_stop. */
3396 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3397 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3399 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3405 /***********************************************************************
3407 ***********************************************************************/
3409 /* Set up iterator IT from `display' property at its current position.
3410 Called from handle_stop.
3411 We return HANDLED_RETURN if some part of the display property
3412 overrides the display of the buffer text itself.
3413 Otherwise we return HANDLED_NORMALLY. */
3415 static enum prop_handled
3416 handle_display_prop (it
)
3419 Lisp_Object prop
, object
;
3420 struct text_pos
*position
;
3421 /* Nonzero if some property replaces the display of the text itself. */
3422 int display_replaced_p
= 0;
3424 if (STRINGP (it
->string
))
3426 object
= it
->string
;
3427 position
= &it
->current
.string_pos
;
3431 XSETWINDOW (object
, it
->w
);
3432 position
= &it
->current
.pos
;
3435 /* Reset those iterator values set from display property values. */
3436 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3437 it
->space_width
= Qnil
;
3438 it
->font_height
= Qnil
;
3441 /* We don't support recursive `display' properties, i.e. string
3442 values that have a string `display' property, that have a string
3443 `display' property etc. */
3444 if (!it
->string_from_display_prop_p
)
3445 it
->area
= TEXT_AREA
;
3447 prop
= Fget_char_property (make_number (position
->charpos
),
3450 return HANDLED_NORMALLY
;
3452 if (!STRINGP (it
->string
))
3453 object
= it
->w
->buffer
;
3456 /* Simple properties. */
3457 && !EQ (XCAR (prop
), Qimage
)
3458 && !EQ (XCAR (prop
), Qspace
)
3459 && !EQ (XCAR (prop
), Qwhen
)
3460 && !EQ (XCAR (prop
), Qslice
)
3461 && !EQ (XCAR (prop
), Qspace_width
)
3462 && !EQ (XCAR (prop
), Qheight
)
3463 && !EQ (XCAR (prop
), Qraise
)
3464 /* Marginal area specifications. */
3465 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3466 && !EQ (XCAR (prop
), Qleft_fringe
)
3467 && !EQ (XCAR (prop
), Qright_fringe
)
3468 && !NILP (XCAR (prop
)))
3470 for (; CONSP (prop
); prop
= XCDR (prop
))
3472 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3473 position
, display_replaced_p
))
3474 display_replaced_p
= 1;
3477 else if (VECTORP (prop
))
3480 for (i
= 0; i
< ASIZE (prop
); ++i
)
3481 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3482 position
, display_replaced_p
))
3483 display_replaced_p
= 1;
3487 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3488 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3489 return HANDLED_RECOMPUTE_PROPS
;
3491 display_replaced_p
= 1;
3494 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3498 /* Value is the position of the end of the `display' property starting
3499 at START_POS in OBJECT. */
3501 static struct text_pos
3502 display_prop_end (it
, object
, start_pos
)
3505 struct text_pos start_pos
;
3508 struct text_pos end_pos
;
3510 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3511 Qdisplay
, object
, Qnil
);
3512 CHARPOS (end_pos
) = XFASTINT (end
);
3513 if (STRINGP (object
))
3514 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3516 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3522 /* Set up IT from a single `display' specification PROP. OBJECT
3523 is the object in which the `display' property was found. *POSITION
3524 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3525 means that we previously saw a display specification which already
3526 replaced text display with something else, for example an image;
3527 we ignore such properties after the first one has been processed.
3529 If PROP is a `space' or `image' specification, and in some other
3530 cases too, set *POSITION to the position where the `display'
3533 Value is non-zero if something was found which replaces the display
3534 of buffer or string text. Specifically, the value is -1 if that
3535 "something" is "nothing". */
3538 handle_single_display_spec (it
, spec
, object
, position
,
3539 display_replaced_before_p
)
3543 struct text_pos
*position
;
3544 int display_replaced_before_p
;
3547 Lisp_Object location
, value
;
3548 struct text_pos start_pos
;
3551 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3552 If the result is non-nil, use VALUE instead of SPEC. */
3554 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3563 if (!NILP (form
) && !EQ (form
, Qt
))
3565 int count
= SPECPDL_INDEX ();
3566 struct gcpro gcpro1
;
3568 /* Bind `object' to the object having the `display' property, a
3569 buffer or string. Bind `position' to the position in the
3570 object where the property was found, and `buffer-position'
3571 to the current position in the buffer. */
3572 specbind (Qobject
, object
);
3573 specbind (Qposition
, make_number (CHARPOS (*position
)));
3574 specbind (Qbuffer_position
,
3575 make_number (STRINGP (object
)
3576 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3578 form
= safe_eval (form
);
3580 unbind_to (count
, Qnil
);
3586 /* Handle `(height HEIGHT)' specifications. */
3588 && EQ (XCAR (spec
), Qheight
)
3589 && CONSP (XCDR (spec
)))
3591 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3594 it
->font_height
= XCAR (XCDR (spec
));
3595 if (!NILP (it
->font_height
))
3597 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3598 int new_height
= -1;
3600 if (CONSP (it
->font_height
)
3601 && (EQ (XCAR (it
->font_height
), Qplus
)
3602 || EQ (XCAR (it
->font_height
), Qminus
))
3603 && CONSP (XCDR (it
->font_height
))
3604 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3606 /* `(+ N)' or `(- N)' where N is an integer. */
3607 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3608 if (EQ (XCAR (it
->font_height
), Qplus
))
3610 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3612 else if (FUNCTIONP (it
->font_height
))
3614 /* Call function with current height as argument.
3615 Value is the new height. */
3617 height
= safe_call1 (it
->font_height
,
3618 face
->lface
[LFACE_HEIGHT_INDEX
]);
3619 if (NUMBERP (height
))
3620 new_height
= XFLOATINT (height
);
3622 else if (NUMBERP (it
->font_height
))
3624 /* Value is a multiple of the canonical char height. */
3627 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3628 new_height
= (XFLOATINT (it
->font_height
)
3629 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3633 /* Evaluate IT->font_height with `height' bound to the
3634 current specified height to get the new height. */
3635 int count
= SPECPDL_INDEX ();
3637 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3638 value
= safe_eval (it
->font_height
);
3639 unbind_to (count
, Qnil
);
3641 if (NUMBERP (value
))
3642 new_height
= XFLOATINT (value
);
3646 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3652 /* Handle `(space_width WIDTH)'. */
3654 && EQ (XCAR (spec
), Qspace_width
)
3655 && CONSP (XCDR (spec
)))
3657 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3660 value
= XCAR (XCDR (spec
));
3661 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3662 it
->space_width
= value
;
3667 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3669 && EQ (XCAR (spec
), Qslice
))
3673 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3676 if (tem
= XCDR (spec
), CONSP (tem
))
3678 it
->slice
.x
= XCAR (tem
);
3679 if (tem
= XCDR (tem
), CONSP (tem
))
3681 it
->slice
.y
= XCAR (tem
);
3682 if (tem
= XCDR (tem
), CONSP (tem
))
3684 it
->slice
.width
= XCAR (tem
);
3685 if (tem
= XCDR (tem
), CONSP (tem
))
3686 it
->slice
.height
= XCAR (tem
);
3694 /* Handle `(raise FACTOR)'. */
3696 && EQ (XCAR (spec
), Qraise
)
3697 && CONSP (XCDR (spec
)))
3699 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3702 #ifdef HAVE_WINDOW_SYSTEM
3703 value
= XCAR (XCDR (spec
));
3704 if (NUMBERP (value
))
3706 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3707 it
->voffset
= - (XFLOATINT (value
)
3708 * (FONT_HEIGHT (face
->font
)));
3710 #endif /* HAVE_WINDOW_SYSTEM */
3715 /* Don't handle the other kinds of display specifications
3716 inside a string that we got from a `display' property. */
3717 if (it
->string_from_display_prop_p
)
3720 /* Characters having this form of property are not displayed, so
3721 we have to find the end of the property. */
3722 start_pos
= *position
;
3723 *position
= display_prop_end (it
, object
, start_pos
);
3726 /* Stop the scan at that end position--we assume that all
3727 text properties change there. */
3728 it
->stop_charpos
= position
->charpos
;
3730 /* Handle `(left-fringe BITMAP [FACE])'
3731 and `(right-fringe BITMAP [FACE])'. */
3733 && (EQ (XCAR (spec
), Qleft_fringe
)
3734 || EQ (XCAR (spec
), Qright_fringe
))
3735 && CONSP (XCDR (spec
)))
3737 int face_id
= DEFAULT_FACE_ID
;
3740 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3741 /* If we return here, POSITION has been advanced
3742 across the text with this property. */
3745 #ifdef HAVE_WINDOW_SYSTEM
3746 value
= XCAR (XCDR (spec
));
3747 if (!SYMBOLP (value
)
3748 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3749 /* If we return here, POSITION has been advanced
3750 across the text with this property. */
3753 if (CONSP (XCDR (XCDR (spec
))))
3755 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3756 int face_id2
= lookup_derived_face (it
->f
, face_name
,
3757 'A', FRINGE_FACE_ID
, 0);
3762 /* Save current settings of IT so that we can restore them
3763 when we are finished with the glyph property value. */
3767 it
->area
= TEXT_AREA
;
3768 it
->what
= IT_IMAGE
;
3769 it
->image_id
= -1; /* no image */
3770 it
->position
= start_pos
;
3771 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3772 it
->method
= GET_FROM_IMAGE
;
3773 it
->face_id
= face_id
;
3775 /* Say that we haven't consumed the characters with
3776 `display' property yet. The call to pop_it in
3777 set_iterator_to_next will clean this up. */
3778 *position
= start_pos
;
3780 if (EQ (XCAR (spec
), Qleft_fringe
))
3782 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3783 it
->left_user_fringe_face_id
= face_id
;
3787 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3788 it
->right_user_fringe_face_id
= face_id
;
3790 #endif /* HAVE_WINDOW_SYSTEM */
3794 /* Prepare to handle `((margin left-margin) ...)',
3795 `((margin right-margin) ...)' and `((margin nil) ...)'
3796 prefixes for display specifications. */
3797 location
= Qunbound
;
3798 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3802 value
= XCDR (spec
);
3804 value
= XCAR (value
);
3807 if (EQ (XCAR (tem
), Qmargin
)
3808 && (tem
= XCDR (tem
),
3809 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3811 || EQ (tem
, Qleft_margin
)
3812 || EQ (tem
, Qright_margin
))))
3816 if (EQ (location
, Qunbound
))
3822 /* After this point, VALUE is the property after any
3823 margin prefix has been stripped. It must be a string,
3824 an image specification, or `(space ...)'.
3826 LOCATION specifies where to display: `left-margin',
3827 `right-margin' or nil. */
3829 valid_p
= (STRINGP (value
)
3830 #ifdef HAVE_WINDOW_SYSTEM
3831 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3832 #endif /* not HAVE_WINDOW_SYSTEM */
3833 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3835 if (valid_p
&& !display_replaced_before_p
)
3837 /* Save current settings of IT so that we can restore them
3838 when we are finished with the glyph property value. */
3841 if (NILP (location
))
3842 it
->area
= TEXT_AREA
;
3843 else if (EQ (location
, Qleft_margin
))
3844 it
->area
= LEFT_MARGIN_AREA
;
3846 it
->area
= RIGHT_MARGIN_AREA
;
3848 if (STRINGP (value
))
3850 if (SCHARS (value
) == 0)
3853 return -1; /* Replaced by "", i.e. nothing. */
3856 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3857 it
->current
.overlay_string_index
= -1;
3858 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3859 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3860 it
->method
= GET_FROM_STRING
;
3861 it
->stop_charpos
= 0;
3862 it
->string_from_display_prop_p
= 1;
3863 /* Say that we haven't consumed the characters with
3864 `display' property yet. The call to pop_it in
3865 set_iterator_to_next will clean this up. */
3866 *position
= start_pos
;
3868 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3870 it
->method
= GET_FROM_STRETCH
;
3872 it
->current
.pos
= it
->position
= start_pos
;
3874 #ifdef HAVE_WINDOW_SYSTEM
3877 it
->what
= IT_IMAGE
;
3878 it
->image_id
= lookup_image (it
->f
, value
);
3879 it
->position
= start_pos
;
3880 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3881 it
->method
= GET_FROM_IMAGE
;
3883 /* Say that we haven't consumed the characters with
3884 `display' property yet. The call to pop_it in
3885 set_iterator_to_next will clean this up. */
3886 *position
= start_pos
;
3888 #endif /* HAVE_WINDOW_SYSTEM */
3893 /* Invalid property or property not supported. Restore
3894 POSITION to what it was before. */
3895 *position
= start_pos
;
3900 /* Check if SPEC is a display specification value whose text should be
3901 treated as intangible. */
3904 single_display_spec_intangible_p (prop
)
3907 /* Skip over `when FORM'. */
3908 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3922 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3923 we don't need to treat text as intangible. */
3924 if (EQ (XCAR (prop
), Qmargin
))
3932 || EQ (XCAR (prop
), Qleft_margin
)
3933 || EQ (XCAR (prop
), Qright_margin
))
3937 return (CONSP (prop
)
3938 && (EQ (XCAR (prop
), Qimage
)
3939 || EQ (XCAR (prop
), Qspace
)));
3943 /* Check if PROP is a display property value whose text should be
3944 treated as intangible. */
3947 display_prop_intangible_p (prop
)
3951 && CONSP (XCAR (prop
))
3952 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3954 /* A list of sub-properties. */
3955 while (CONSP (prop
))
3957 if (single_display_spec_intangible_p (XCAR (prop
)))
3962 else if (VECTORP (prop
))
3964 /* A vector of sub-properties. */
3966 for (i
= 0; i
< ASIZE (prop
); ++i
)
3967 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3971 return single_display_spec_intangible_p (prop
);
3977 /* Return 1 if PROP is a display sub-property value containing STRING. */
3980 single_display_spec_string_p (prop
, string
)
3981 Lisp_Object prop
, string
;
3983 if (EQ (string
, prop
))
3986 /* Skip over `when FORM'. */
3987 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3996 /* Skip over `margin LOCATION'. */
3997 if (EQ (XCAR (prop
), Qmargin
))
4008 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4012 /* Return 1 if STRING appears in the `display' property PROP. */
4015 display_prop_string_p (prop
, string
)
4016 Lisp_Object prop
, string
;
4019 && CONSP (XCAR (prop
))
4020 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4022 /* A list of sub-properties. */
4023 while (CONSP (prop
))
4025 if (single_display_spec_string_p (XCAR (prop
), string
))
4030 else if (VECTORP (prop
))
4032 /* A vector of sub-properties. */
4034 for (i
= 0; i
< ASIZE (prop
); ++i
)
4035 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4039 return single_display_spec_string_p (prop
, string
);
4045 /* Determine from which buffer position in W's buffer STRING comes
4046 from. AROUND_CHARPOS is an approximate position where it could
4047 be from. Value is the buffer position or 0 if it couldn't be
4050 W's buffer must be current.
4052 This function is necessary because we don't record buffer positions
4053 in glyphs generated from strings (to keep struct glyph small).
4054 This function may only use code that doesn't eval because it is
4055 called asynchronously from note_mouse_highlight. */
4058 string_buffer_position (w
, string
, around_charpos
)
4063 Lisp_Object limit
, prop
, pos
;
4064 const int MAX_DISTANCE
= 1000;
4067 pos
= make_number (around_charpos
);
4068 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4069 while (!found
&& !EQ (pos
, limit
))
4071 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4072 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4075 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4080 pos
= make_number (around_charpos
);
4081 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4082 while (!found
&& !EQ (pos
, limit
))
4084 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4085 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4088 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4093 return found
? XINT (pos
) : 0;
4098 /***********************************************************************
4099 `composition' property
4100 ***********************************************************************/
4102 /* Set up iterator IT from `composition' property at its current
4103 position. Called from handle_stop. */
4105 static enum prop_handled
4106 handle_composition_prop (it
)
4109 Lisp_Object prop
, string
;
4110 int pos
, pos_byte
, end
;
4111 enum prop_handled handled
= HANDLED_NORMALLY
;
4113 if (STRINGP (it
->string
))
4115 pos
= IT_STRING_CHARPOS (*it
);
4116 pos_byte
= IT_STRING_BYTEPOS (*it
);
4117 string
= it
->string
;
4121 pos
= IT_CHARPOS (*it
);
4122 pos_byte
= IT_BYTEPOS (*it
);
4126 /* If there's a valid composition and point is not inside of the
4127 composition (in the case that the composition is from the current
4128 buffer), draw a glyph composed from the composition components. */
4129 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4130 && COMPOSITION_VALID_P (pos
, end
, prop
)
4131 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4133 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4137 it
->method
= GET_FROM_COMPOSITION
;
4139 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4140 /* For a terminal, draw only the first character of the
4142 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4143 it
->len
= (STRINGP (it
->string
)
4144 ? string_char_to_byte (it
->string
, end
)
4145 : CHAR_TO_BYTE (end
)) - pos_byte
;
4146 it
->stop_charpos
= end
;
4147 handled
= HANDLED_RETURN
;
4156 /***********************************************************************
4158 ***********************************************************************/
4160 /* The following structure is used to record overlay strings for
4161 later sorting in load_overlay_strings. */
4163 struct overlay_entry
4165 Lisp_Object overlay
;
4172 /* Set up iterator IT from overlay strings at its current position.
4173 Called from handle_stop. */
4175 static enum prop_handled
4176 handle_overlay_change (it
)
4179 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4180 return HANDLED_RECOMPUTE_PROPS
;
4182 return HANDLED_NORMALLY
;
4186 /* Set up the next overlay string for delivery by IT, if there is an
4187 overlay string to deliver. Called by set_iterator_to_next when the
4188 end of the current overlay string is reached. If there are more
4189 overlay strings to display, IT->string and
4190 IT->current.overlay_string_index are set appropriately here.
4191 Otherwise IT->string is set to nil. */
4194 next_overlay_string (it
)
4197 ++it
->current
.overlay_string_index
;
4198 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4200 /* No more overlay strings. Restore IT's settings to what
4201 they were before overlay strings were processed, and
4202 continue to deliver from current_buffer. */
4203 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4206 xassert (it
->stop_charpos
>= BEGV
4207 && it
->stop_charpos
<= it
->end_charpos
);
4209 it
->current
.overlay_string_index
= -1;
4210 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4211 it
->n_overlay_strings
= 0;
4212 it
->method
= GET_FROM_BUFFER
;
4214 /* If we're at the end of the buffer, record that we have
4215 processed the overlay strings there already, so that
4216 next_element_from_buffer doesn't try it again. */
4217 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4218 it
->overlay_strings_at_end_processed_p
= 1;
4220 /* If we have to display `...' for invisible text, set
4221 the iterator up for that. */
4222 if (display_ellipsis_p
)
4223 setup_for_ellipsis (it
, 0);
4227 /* There are more overlay strings to process. If
4228 IT->current.overlay_string_index has advanced to a position
4229 where we must load IT->overlay_strings with more strings, do
4231 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4233 if (it
->current
.overlay_string_index
&& i
== 0)
4234 load_overlay_strings (it
, 0);
4236 /* Initialize IT to deliver display elements from the overlay
4238 it
->string
= it
->overlay_strings
[i
];
4239 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4240 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4241 it
->method
= GET_FROM_STRING
;
4242 it
->stop_charpos
= 0;
4249 /* Compare two overlay_entry structures E1 and E2. Used as a
4250 comparison function for qsort in load_overlay_strings. Overlay
4251 strings for the same position are sorted so that
4253 1. All after-strings come in front of before-strings, except
4254 when they come from the same overlay.
4256 2. Within after-strings, strings are sorted so that overlay strings
4257 from overlays with higher priorities come first.
4259 2. Within before-strings, strings are sorted so that overlay
4260 strings from overlays with higher priorities come last.
4262 Value is analogous to strcmp. */
4266 compare_overlay_entries (e1
, e2
)
4269 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4270 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4273 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4275 /* Let after-strings appear in front of before-strings if
4276 they come from different overlays. */
4277 if (EQ (entry1
->overlay
, entry2
->overlay
))
4278 result
= entry1
->after_string_p
? 1 : -1;
4280 result
= entry1
->after_string_p
? -1 : 1;
4282 else if (entry1
->after_string_p
)
4283 /* After-strings sorted in order of decreasing priority. */
4284 result
= entry2
->priority
- entry1
->priority
;
4286 /* Before-strings sorted in order of increasing priority. */
4287 result
= entry1
->priority
- entry2
->priority
;
4293 /* Load the vector IT->overlay_strings with overlay strings from IT's
4294 current buffer position, or from CHARPOS if that is > 0. Set
4295 IT->n_overlays to the total number of overlay strings found.
4297 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4298 a time. On entry into load_overlay_strings,
4299 IT->current.overlay_string_index gives the number of overlay
4300 strings that have already been loaded by previous calls to this
4303 IT->add_overlay_start contains an additional overlay start
4304 position to consider for taking overlay strings from, if non-zero.
4305 This position comes into play when the overlay has an `invisible'
4306 property, and both before and after-strings. When we've skipped to
4307 the end of the overlay, because of its `invisible' property, we
4308 nevertheless want its before-string to appear.
4309 IT->add_overlay_start will contain the overlay start position
4312 Overlay strings are sorted so that after-string strings come in
4313 front of before-string strings. Within before and after-strings,
4314 strings are sorted by overlay priority. See also function
4315 compare_overlay_entries. */
4318 load_overlay_strings (it
, charpos
)
4322 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4323 Lisp_Object overlay
, window
, str
, invisible
;
4324 struct Lisp_Overlay
*ov
;
4327 int n
= 0, i
, j
, invis_p
;
4328 struct overlay_entry
*entries
4329 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4332 charpos
= IT_CHARPOS (*it
);
4334 /* Append the overlay string STRING of overlay OVERLAY to vector
4335 `entries' which has size `size' and currently contains `n'
4336 elements. AFTER_P non-zero means STRING is an after-string of
4338 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4341 Lisp_Object priority; \
4345 int new_size = 2 * size; \
4346 struct overlay_entry *old = entries; \
4348 (struct overlay_entry *) alloca (new_size \
4349 * sizeof *entries); \
4350 bcopy (old, entries, size * sizeof *entries); \
4354 entries[n].string = (STRING); \
4355 entries[n].overlay = (OVERLAY); \
4356 priority = Foverlay_get ((OVERLAY), Qpriority); \
4357 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4358 entries[n].after_string_p = (AFTER_P); \
4363 /* Process overlay before the overlay center. */
4364 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4366 XSETMISC (overlay
, ov
);
4367 xassert (OVERLAYP (overlay
));
4368 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4369 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4374 /* Skip this overlay if it doesn't start or end at IT's current
4376 if (end
!= charpos
&& start
!= charpos
)
4379 /* Skip this overlay if it doesn't apply to IT->w. */
4380 window
= Foverlay_get (overlay
, Qwindow
);
4381 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4384 /* If the text ``under'' the overlay is invisible, both before-
4385 and after-strings from this overlay are visible; start and
4386 end position are indistinguishable. */
4387 invisible
= Foverlay_get (overlay
, Qinvisible
);
4388 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4390 /* If overlay has a non-empty before-string, record it. */
4391 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4392 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4394 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4396 /* If overlay has a non-empty after-string, record it. */
4397 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4398 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4400 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4403 /* Process overlays after the overlay center. */
4404 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4406 XSETMISC (overlay
, ov
);
4407 xassert (OVERLAYP (overlay
));
4408 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4409 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4411 if (start
> charpos
)
4414 /* Skip this overlay if it doesn't start or end at IT's current
4416 if (end
!= charpos
&& start
!= charpos
)
4419 /* Skip this overlay if it doesn't apply to IT->w. */
4420 window
= Foverlay_get (overlay
, Qwindow
);
4421 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4424 /* If the text ``under'' the overlay is invisible, it has a zero
4425 dimension, and both before- and after-strings apply. */
4426 invisible
= Foverlay_get (overlay
, Qinvisible
);
4427 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4429 /* If overlay has a non-empty before-string, record it. */
4430 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4431 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4433 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4435 /* If overlay has a non-empty after-string, record it. */
4436 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4437 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4439 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4442 #undef RECORD_OVERLAY_STRING
4446 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4448 /* Record the total number of strings to process. */
4449 it
->n_overlay_strings
= n
;
4451 /* IT->current.overlay_string_index is the number of overlay strings
4452 that have already been consumed by IT. Copy some of the
4453 remaining overlay strings to IT->overlay_strings. */
4455 j
= it
->current
.overlay_string_index
;
4456 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4457 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4463 /* Get the first chunk of overlay strings at IT's current buffer
4464 position, or at CHARPOS if that is > 0. Value is non-zero if at
4465 least one overlay string was found. */
4468 get_overlay_strings (it
, charpos
)
4472 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4473 process. This fills IT->overlay_strings with strings, and sets
4474 IT->n_overlay_strings to the total number of strings to process.
4475 IT->pos.overlay_string_index has to be set temporarily to zero
4476 because load_overlay_strings needs this; it must be set to -1
4477 when no overlay strings are found because a zero value would
4478 indicate a position in the first overlay string. */
4479 it
->current
.overlay_string_index
= 0;
4480 load_overlay_strings (it
, charpos
);
4482 /* If we found overlay strings, set up IT to deliver display
4483 elements from the first one. Otherwise set up IT to deliver
4484 from current_buffer. */
4485 if (it
->n_overlay_strings
)
4487 /* Make sure we know settings in current_buffer, so that we can
4488 restore meaningful values when we're done with the overlay
4490 compute_stop_pos (it
);
4491 xassert (it
->face_id
>= 0);
4493 /* Save IT's settings. They are restored after all overlay
4494 strings have been processed. */
4495 xassert (it
->sp
== 0);
4498 /* Set up IT to deliver display elements from the first overlay
4500 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4501 it
->string
= it
->overlay_strings
[0];
4502 it
->stop_charpos
= 0;
4503 xassert (STRINGP (it
->string
));
4504 it
->end_charpos
= SCHARS (it
->string
);
4505 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4506 it
->method
= GET_FROM_STRING
;
4511 it
->current
.overlay_string_index
= -1;
4512 it
->method
= GET_FROM_BUFFER
;
4517 /* Value is non-zero if we found at least one overlay string. */
4518 return STRINGP (it
->string
);
4523 /***********************************************************************
4524 Saving and restoring state
4525 ***********************************************************************/
4527 /* Save current settings of IT on IT->stack. Called, for example,
4528 before setting up IT for an overlay string, to be able to restore
4529 IT's settings to what they were after the overlay string has been
4536 struct iterator_stack_entry
*p
;
4538 xassert (it
->sp
< 2);
4539 p
= it
->stack
+ it
->sp
;
4541 p
->stop_charpos
= it
->stop_charpos
;
4542 xassert (it
->face_id
>= 0);
4543 p
->face_id
= it
->face_id
;
4544 p
->string
= it
->string
;
4545 p
->pos
= it
->current
;
4546 p
->end_charpos
= it
->end_charpos
;
4547 p
->string_nchars
= it
->string_nchars
;
4549 p
->multibyte_p
= it
->multibyte_p
;
4550 p
->slice
= it
->slice
;
4551 p
->space_width
= it
->space_width
;
4552 p
->font_height
= it
->font_height
;
4553 p
->voffset
= it
->voffset
;
4554 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4555 p
->display_ellipsis_p
= 0;
4560 /* Restore IT's settings from IT->stack. Called, for example, when no
4561 more overlay strings must be processed, and we return to delivering
4562 display elements from a buffer, or when the end of a string from a
4563 `display' property is reached and we return to delivering display
4564 elements from an overlay string, or from a buffer. */
4570 struct iterator_stack_entry
*p
;
4572 xassert (it
->sp
> 0);
4574 p
= it
->stack
+ it
->sp
;
4575 it
->stop_charpos
= p
->stop_charpos
;
4576 it
->face_id
= p
->face_id
;
4577 it
->string
= p
->string
;
4578 it
->current
= p
->pos
;
4579 it
->end_charpos
= p
->end_charpos
;
4580 it
->string_nchars
= p
->string_nchars
;
4582 it
->multibyte_p
= p
->multibyte_p
;
4583 it
->slice
= p
->slice
;
4584 it
->space_width
= p
->space_width
;
4585 it
->font_height
= p
->font_height
;
4586 it
->voffset
= p
->voffset
;
4587 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4592 /***********************************************************************
4594 ***********************************************************************/
4596 /* Set IT's current position to the previous line start. */
4599 back_to_previous_line_start (it
)
4602 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4603 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4607 /* Move IT to the next line start.
4609 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4610 we skipped over part of the text (as opposed to moving the iterator
4611 continuously over the text). Otherwise, don't change the value
4614 Newlines may come from buffer text, overlay strings, or strings
4615 displayed via the `display' property. That's the reason we can't
4616 simply use find_next_newline_no_quit.
4618 Note that this function may not skip over invisible text that is so
4619 because of text properties and immediately follows a newline. If
4620 it would, function reseat_at_next_visible_line_start, when called
4621 from set_iterator_to_next, would effectively make invisible
4622 characters following a newline part of the wrong glyph row, which
4623 leads to wrong cursor motion. */
4626 forward_to_next_line_start (it
, skipped_p
)
4630 int old_selective
, newline_found_p
, n
;
4631 const int MAX_NEWLINE_DISTANCE
= 500;
4633 /* If already on a newline, just consume it to avoid unintended
4634 skipping over invisible text below. */
4635 if (it
->what
== IT_CHARACTER
4637 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4639 set_iterator_to_next (it
, 0);
4644 /* Don't handle selective display in the following. It's (a)
4645 unnecessary because it's done by the caller, and (b) leads to an
4646 infinite recursion because next_element_from_ellipsis indirectly
4647 calls this function. */
4648 old_selective
= it
->selective
;
4651 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4652 from buffer text. */
4653 for (n
= newline_found_p
= 0;
4654 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4655 n
+= STRINGP (it
->string
) ? 0 : 1)
4657 if (!get_next_display_element (it
))
4659 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4660 set_iterator_to_next (it
, 0);
4663 /* If we didn't find a newline near enough, see if we can use a
4665 if (!newline_found_p
)
4667 int start
= IT_CHARPOS (*it
);
4668 int limit
= find_next_newline_no_quit (start
, 1);
4671 xassert (!STRINGP (it
->string
));
4673 /* If there isn't any `display' property in sight, and no
4674 overlays, we can just use the position of the newline in
4676 if (it
->stop_charpos
>= limit
4677 || ((pos
= Fnext_single_property_change (make_number (start
),
4679 Qnil
, make_number (limit
)),
4681 && next_overlay_change (start
) == ZV
))
4683 IT_CHARPOS (*it
) = limit
;
4684 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4685 *skipped_p
= newline_found_p
= 1;
4689 while (get_next_display_element (it
)
4690 && !newline_found_p
)
4692 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4693 set_iterator_to_next (it
, 0);
4698 it
->selective
= old_selective
;
4699 return newline_found_p
;
4703 /* Set IT's current position to the previous visible line start. Skip
4704 invisible text that is so either due to text properties or due to
4705 selective display. Caution: this does not change IT->current_x and
4709 back_to_previous_visible_line_start (it
)
4712 while (IT_CHARPOS (*it
) > BEGV
)
4714 back_to_previous_line_start (it
);
4715 if (IT_CHARPOS (*it
) <= BEGV
)
4718 /* If selective > 0, then lines indented more than that values
4720 if (it
->selective
> 0
4721 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4722 (double) it
->selective
)) /* iftc */
4725 /* Check the newline before point for invisibility. */
4728 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4729 Qinvisible
, it
->window
);
4730 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4734 /* If newline has a display property that replaces the newline with something
4735 else (image or text), find start of overlay or interval and continue search
4737 if (IT_CHARPOS (*it
) > BEGV
)
4739 struct it it2
= *it
;
4742 Lisp_Object val
, overlay
;
4744 pos
= --IT_CHARPOS (it2
);
4747 if (handle_display_prop (&it2
) == HANDLED_RETURN
4748 && !NILP (val
= get_char_property_and_overlay
4749 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
4750 && (OVERLAYP (overlay
)
4751 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
4752 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
4756 IT_CHARPOS (*it
) = beg
;
4757 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
4765 xassert (IT_CHARPOS (*it
) >= BEGV
);
4766 xassert (IT_CHARPOS (*it
) == BEGV
4767 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4772 /* Reseat iterator IT at the previous visible line start. Skip
4773 invisible text that is so either due to text properties or due to
4774 selective display. At the end, update IT's overlay information,
4775 face information etc. */
4778 reseat_at_previous_visible_line_start (it
)
4781 back_to_previous_visible_line_start (it
);
4782 reseat (it
, it
->current
.pos
, 1);
4787 /* Reseat iterator IT on the next visible line start in the current
4788 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4789 preceding the line start. Skip over invisible text that is so
4790 because of selective display. Compute faces, overlays etc at the
4791 new position. Note that this function does not skip over text that
4792 is invisible because of text properties. */
4795 reseat_at_next_visible_line_start (it
, on_newline_p
)
4799 int newline_found_p
, skipped_p
= 0;
4801 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4803 /* Skip over lines that are invisible because they are indented
4804 more than the value of IT->selective. */
4805 if (it
->selective
> 0)
4806 while (IT_CHARPOS (*it
) < ZV
4807 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4808 (double) it
->selective
)) /* iftc */
4810 xassert (IT_BYTEPOS (*it
) == BEGV
4811 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4812 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4815 /* Position on the newline if that's what's requested. */
4816 if (on_newline_p
&& newline_found_p
)
4818 if (STRINGP (it
->string
))
4820 if (IT_STRING_CHARPOS (*it
) > 0)
4822 --IT_STRING_CHARPOS (*it
);
4823 --IT_STRING_BYTEPOS (*it
);
4826 else if (IT_CHARPOS (*it
) > BEGV
)
4830 reseat (it
, it
->current
.pos
, 0);
4834 reseat (it
, it
->current
.pos
, 0);
4841 /***********************************************************************
4842 Changing an iterator's position
4843 ***********************************************************************/
4845 /* Change IT's current position to POS in current_buffer. If FORCE_P
4846 is non-zero, always check for text properties at the new position.
4847 Otherwise, text properties are only looked up if POS >=
4848 IT->check_charpos of a property. */
4851 reseat (it
, pos
, force_p
)
4853 struct text_pos pos
;
4856 int original_pos
= IT_CHARPOS (*it
);
4858 reseat_1 (it
, pos
, 0);
4860 /* Determine where to check text properties. Avoid doing it
4861 where possible because text property lookup is very expensive. */
4863 || CHARPOS (pos
) > it
->stop_charpos
4864 || CHARPOS (pos
) < original_pos
)
4871 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4872 IT->stop_pos to POS, also. */
4875 reseat_1 (it
, pos
, set_stop_p
)
4877 struct text_pos pos
;
4880 /* Don't call this function when scanning a C string. */
4881 xassert (it
->s
== NULL
);
4883 /* POS must be a reasonable value. */
4884 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4886 it
->current
.pos
= it
->position
= pos
;
4887 XSETBUFFER (it
->object
, current_buffer
);
4888 it
->end_charpos
= ZV
;
4890 it
->current
.dpvec_index
= -1;
4891 it
->current
.overlay_string_index
= -1;
4892 IT_STRING_CHARPOS (*it
) = -1;
4893 IT_STRING_BYTEPOS (*it
) = -1;
4895 it
->method
= GET_FROM_BUFFER
;
4896 /* RMS: I added this to fix a bug in move_it_vertically_backward
4897 where it->area continued to relate to the starting point
4898 for the backward motion. Bug report from
4899 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4900 However, I am not sure whether reseat still does the right thing
4901 in general after this change. */
4902 it
->area
= TEXT_AREA
;
4903 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4905 it
->face_before_selective_p
= 0;
4908 it
->stop_charpos
= CHARPOS (pos
);
4912 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4913 If S is non-null, it is a C string to iterate over. Otherwise,
4914 STRING gives a Lisp string to iterate over.
4916 If PRECISION > 0, don't return more then PRECISION number of
4917 characters from the string.
4919 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4920 characters have been returned. FIELD_WIDTH < 0 means an infinite
4923 MULTIBYTE = 0 means disable processing of multibyte characters,
4924 MULTIBYTE > 0 means enable it,
4925 MULTIBYTE < 0 means use IT->multibyte_p.
4927 IT must be initialized via a prior call to init_iterator before
4928 calling this function. */
4931 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4936 int precision
, field_width
, multibyte
;
4938 /* No region in strings. */
4939 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4941 /* No text property checks performed by default, but see below. */
4942 it
->stop_charpos
= -1;
4944 /* Set iterator position and end position. */
4945 bzero (&it
->current
, sizeof it
->current
);
4946 it
->current
.overlay_string_index
= -1;
4947 it
->current
.dpvec_index
= -1;
4948 xassert (charpos
>= 0);
4950 /* If STRING is specified, use its multibyteness, otherwise use the
4951 setting of MULTIBYTE, if specified. */
4953 it
->multibyte_p
= multibyte
> 0;
4957 xassert (STRINGP (string
));
4958 it
->string
= string
;
4960 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4961 it
->method
= GET_FROM_STRING
;
4962 it
->current
.string_pos
= string_pos (charpos
, string
);
4969 /* Note that we use IT->current.pos, not it->current.string_pos,
4970 for displaying C strings. */
4971 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4972 if (it
->multibyte_p
)
4974 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4975 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4979 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4980 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4983 it
->method
= GET_FROM_C_STRING
;
4986 /* PRECISION > 0 means don't return more than PRECISION characters
4988 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4989 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4991 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4992 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4993 FIELD_WIDTH < 0 means infinite field width. This is useful for
4994 padding with `-' at the end of a mode line. */
4995 if (field_width
< 0)
4996 field_width
= INFINITY
;
4997 if (field_width
> it
->end_charpos
- charpos
)
4998 it
->end_charpos
= charpos
+ field_width
;
5000 /* Use the standard display table for displaying strings. */
5001 if (DISP_TABLE_P (Vstandard_display_table
))
5002 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5004 it
->stop_charpos
= charpos
;
5010 /***********************************************************************
5012 ***********************************************************************/
5014 /* Map enum it_method value to corresponding next_element_from_* function. */
5016 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5018 next_element_from_buffer
,
5019 next_element_from_display_vector
,
5020 next_element_from_composition
,
5021 next_element_from_string
,
5022 next_element_from_c_string
,
5023 next_element_from_image
,
5024 next_element_from_stretch
5028 /* Load IT's display element fields with information about the next
5029 display element from the current position of IT. Value is zero if
5030 end of buffer (or C string) is reached. */
5033 get_next_display_element (it
)
5036 /* Non-zero means that we found a display element. Zero means that
5037 we hit the end of what we iterate over. Performance note: the
5038 function pointer `method' used here turns out to be faster than
5039 using a sequence of if-statements. */
5043 success_p
= (*get_next_element
[it
->method
]) (it
);
5045 if (it
->what
== IT_CHARACTER
)
5047 /* Map via display table or translate control characters.
5048 IT->c, IT->len etc. have been set to the next character by
5049 the function call above. If we have a display table, and it
5050 contains an entry for IT->c, translate it. Don't do this if
5051 IT->c itself comes from a display table, otherwise we could
5052 end up in an infinite recursion. (An alternative could be to
5053 count the recursion depth of this function and signal an
5054 error when a certain maximum depth is reached.) Is it worth
5056 if (success_p
&& it
->dpvec
== NULL
)
5061 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5064 struct Lisp_Vector
*v
= XVECTOR (dv
);
5066 /* Return the first character from the display table
5067 entry, if not empty. If empty, don't display the
5068 current character. */
5071 it
->dpvec_char_len
= it
->len
;
5072 it
->dpvec
= v
->contents
;
5073 it
->dpend
= v
->contents
+ v
->size
;
5074 it
->current
.dpvec_index
= 0;
5075 it
->dpvec_face_id
= -1;
5076 it
->saved_face_id
= it
->face_id
;
5077 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5082 set_iterator_to_next (it
, 0);
5087 /* Translate control characters into `\003' or `^C' form.
5088 Control characters coming from a display table entry are
5089 currently not translated because we use IT->dpvec to hold
5090 the translation. This could easily be changed but I
5091 don't believe that it is worth doing.
5093 If it->multibyte_p is nonzero, eight-bit characters and
5094 non-printable multibyte characters are also translated to
5097 If it->multibyte_p is zero, eight-bit characters that
5098 don't have corresponding multibyte char code are also
5099 translated to octal form. */
5100 else if ((it
->c
< ' '
5101 && (it
->area
!= TEXT_AREA
5102 /* In mode line, treat \n like other crl chars. */
5104 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5105 || (it
->c
!= '\n' && it
->c
!= '\t')))
5109 || !CHAR_PRINTABLE_P (it
->c
)
5110 || (!NILP (Vnobreak_char_display
)
5111 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5112 || it
->c
== 0x920 || it
->c
== 0x92d
5113 || it
->c
== 0xe20 || it
->c
== 0xe2d
5114 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5116 && (!unibyte_display_via_language_environment
5117 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5119 /* IT->c is a control character which must be displayed
5120 either as '\003' or as `^C' where the '\\' and '^'
5121 can be defined in the display table. Fill
5122 IT->ctl_chars with glyphs for what we have to
5123 display. Then, set IT->dpvec to these glyphs. */
5126 int face_id
, lface_id
= 0 ;
5129 /* Handle control characters with ^. */
5131 if (it
->c
< 128 && it
->ctl_arrow_p
)
5133 g
= '^'; /* default glyph for Control */
5134 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5136 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5137 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5139 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5140 lface_id
= FAST_GLYPH_FACE (g
);
5144 g
= FAST_GLYPH_CHAR (g
);
5145 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5150 /* Merge the escape-glyph face into the current face. */
5151 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5155 XSETINT (it
->ctl_chars
[0], g
);
5157 XSETINT (it
->ctl_chars
[1], g
);
5159 goto display_control
;
5162 /* Handle non-break space in the mode where it only gets
5165 if (EQ (Vnobreak_char_display
, Qt
)
5166 && (it
->c
== 0x8a0 || it
->c
== 0x920
5167 || it
->c
== 0xe20 || it
->c
== 0xf20))
5169 /* Merge the no-break-space face into the current face. */
5170 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5174 XSETINT (it
->ctl_chars
[0], g
);
5176 goto display_control
;
5179 /* Handle sequences that start with the "escape glyph". */
5181 /* the default escape glyph is \. */
5182 escape_glyph
= '\\';
5185 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5186 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5188 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5189 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5193 /* The display table specified a face.
5194 Merge it into face_id and also into escape_glyph. */
5195 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5196 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5201 /* Merge the escape-glyph face into the current face. */
5202 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5206 /* Handle soft hyphens in the mode where they only get
5209 if (EQ (Vnobreak_char_display
, Qt
)
5210 && (it
->c
== 0x8ad || it
->c
== 0x92d
5211 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5214 XSETINT (it
->ctl_chars
[0], g
);
5216 goto display_control
;
5219 /* Handle non-break space and soft hyphen
5220 with the escape glyph. */
5222 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5223 || it
->c
== 0x920 || it
->c
== 0x92d
5224 || it
->c
== 0xe20 || it
->c
== 0xe2d
5225 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5227 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5228 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5229 XSETINT (it
->ctl_chars
[1], g
);
5231 goto display_control
;
5235 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5239 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5240 if (SINGLE_BYTE_CHAR_P (it
->c
))
5241 str
[0] = it
->c
, len
= 1;
5244 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5247 /* It's an invalid character, which shouldn't
5248 happen actually, but due to bugs it may
5249 happen. Let's print the char as is, there's
5250 not much meaningful we can do with it. */
5252 str
[1] = it
->c
>> 8;
5253 str
[2] = it
->c
>> 16;
5254 str
[3] = it
->c
>> 24;
5259 for (i
= 0; i
< len
; i
++)
5261 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5262 /* Insert three more glyphs into IT->ctl_chars for
5263 the octal display of the character. */
5264 g
= ((str
[i
] >> 6) & 7) + '0';
5265 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5266 g
= ((str
[i
] >> 3) & 7) + '0';
5267 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5268 g
= (str
[i
] & 7) + '0';
5269 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5275 /* Set up IT->dpvec and return first character from it. */
5276 it
->dpvec_char_len
= it
->len
;
5277 it
->dpvec
= it
->ctl_chars
;
5278 it
->dpend
= it
->dpvec
+ ctl_len
;
5279 it
->current
.dpvec_index
= 0;
5280 it
->dpvec_face_id
= face_id
;
5281 it
->saved_face_id
= it
->face_id
;
5282 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5288 /* Adjust face id for a multibyte character. There are no
5289 multibyte character in unibyte text. */
5292 && FRAME_WINDOW_P (it
->f
))
5294 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5295 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5299 /* Is this character the last one of a run of characters with
5300 box? If yes, set IT->end_of_box_run_p to 1. */
5307 it
->end_of_box_run_p
5308 = ((face_id
= face_after_it_pos (it
),
5309 face_id
!= it
->face_id
)
5310 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5311 face
->box
== FACE_NO_BOX
));
5314 /* Value is 0 if end of buffer or string reached. */
5319 /* Move IT to the next display element.
5321 RESEAT_P non-zero means if called on a newline in buffer text,
5322 skip to the next visible line start.
5324 Functions get_next_display_element and set_iterator_to_next are
5325 separate because I find this arrangement easier to handle than a
5326 get_next_display_element function that also increments IT's
5327 position. The way it is we can first look at an iterator's current
5328 display element, decide whether it fits on a line, and if it does,
5329 increment the iterator position. The other way around we probably
5330 would either need a flag indicating whether the iterator has to be
5331 incremented the next time, or we would have to implement a
5332 decrement position function which would not be easy to write. */
5335 set_iterator_to_next (it
, reseat_p
)
5339 /* Reset flags indicating start and end of a sequence of characters
5340 with box. Reset them at the start of this function because
5341 moving the iterator to a new position might set them. */
5342 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5346 case GET_FROM_BUFFER
:
5347 /* The current display element of IT is a character from
5348 current_buffer. Advance in the buffer, and maybe skip over
5349 invisible lines that are so because of selective display. */
5350 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5351 reseat_at_next_visible_line_start (it
, 0);
5354 xassert (it
->len
!= 0);
5355 IT_BYTEPOS (*it
) += it
->len
;
5356 IT_CHARPOS (*it
) += 1;
5357 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5361 case GET_FROM_COMPOSITION
:
5362 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5363 if (STRINGP (it
->string
))
5365 IT_STRING_BYTEPOS (*it
) += it
->len
;
5366 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5367 it
->method
= GET_FROM_STRING
;
5368 goto consider_string_end
;
5372 IT_BYTEPOS (*it
) += it
->len
;
5373 IT_CHARPOS (*it
) += it
->cmp_len
;
5374 it
->method
= GET_FROM_BUFFER
;
5378 case GET_FROM_C_STRING
:
5379 /* Current display element of IT is from a C string. */
5380 IT_BYTEPOS (*it
) += it
->len
;
5381 IT_CHARPOS (*it
) += 1;
5384 case GET_FROM_DISPLAY_VECTOR
:
5385 /* Current display element of IT is from a display table entry.
5386 Advance in the display table definition. Reset it to null if
5387 end reached, and continue with characters from buffers/
5389 ++it
->current
.dpvec_index
;
5391 /* Restore face of the iterator to what they were before the
5392 display vector entry (these entries may contain faces). */
5393 it
->face_id
= it
->saved_face_id
;
5395 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5398 it
->method
= GET_FROM_C_STRING
;
5399 else if (STRINGP (it
->string
))
5400 it
->method
= GET_FROM_STRING
;
5402 it
->method
= GET_FROM_BUFFER
;
5405 it
->current
.dpvec_index
= -1;
5407 /* Skip over characters which were displayed via IT->dpvec. */
5408 if (it
->dpvec_char_len
< 0)
5409 reseat_at_next_visible_line_start (it
, 1);
5410 else if (it
->dpvec_char_len
> 0)
5412 it
->len
= it
->dpvec_char_len
;
5413 set_iterator_to_next (it
, reseat_p
);
5416 /* Recheck faces after display vector */
5417 it
->stop_charpos
= IT_CHARPOS (*it
);
5421 case GET_FROM_STRING
:
5422 /* Current display element is a character from a Lisp string. */
5423 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5424 IT_STRING_BYTEPOS (*it
) += it
->len
;
5425 IT_STRING_CHARPOS (*it
) += 1;
5427 consider_string_end
:
5429 if (it
->current
.overlay_string_index
>= 0)
5431 /* IT->string is an overlay string. Advance to the
5432 next, if there is one. */
5433 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5434 next_overlay_string (it
);
5438 /* IT->string is not an overlay string. If we reached
5439 its end, and there is something on IT->stack, proceed
5440 with what is on the stack. This can be either another
5441 string, this time an overlay string, or a buffer. */
5442 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5446 if (STRINGP (it
->string
))
5447 goto consider_string_end
;
5448 it
->method
= GET_FROM_BUFFER
;
5453 case GET_FROM_IMAGE
:
5454 case GET_FROM_STRETCH
:
5455 /* The position etc with which we have to proceed are on
5456 the stack. The position may be at the end of a string,
5457 if the `display' property takes up the whole string. */
5458 xassert (it
->sp
> 0);
5461 if (STRINGP (it
->string
))
5463 it
->method
= GET_FROM_STRING
;
5464 goto consider_string_end
;
5466 it
->method
= GET_FROM_BUFFER
;
5470 /* There are no other methods defined, so this should be a bug. */
5474 xassert (it
->method
!= GET_FROM_STRING
5475 || (STRINGP (it
->string
)
5476 && IT_STRING_CHARPOS (*it
) >= 0));
5479 /* Load IT's display element fields with information about the next
5480 display element which comes from a display table entry or from the
5481 result of translating a control character to one of the forms `^C'
5484 IT->dpvec holds the glyphs to return as characters.
5485 IT->saved_face_id holds the face id before the display vector--
5486 it is restored into IT->face_idin set_iterator_to_next. */
5489 next_element_from_display_vector (it
)
5493 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5495 it
->face_id
= it
->saved_face_id
;
5497 if (INTEGERP (*it
->dpvec
)
5498 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5502 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5503 it
->c
= FAST_GLYPH_CHAR (g
);
5504 it
->len
= CHAR_BYTES (it
->c
);
5506 /* The entry may contain a face id to use. Such a face id is
5507 the id of a Lisp face, not a realized face. A face id of
5508 zero means no face is specified. */
5509 if (it
->dpvec_face_id
>= 0)
5510 it
->face_id
= it
->dpvec_face_id
;
5513 int lface_id
= FAST_GLYPH_FACE (g
);
5515 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5520 /* Display table entry is invalid. Return a space. */
5521 it
->c
= ' ', it
->len
= 1;
5523 /* Don't change position and object of the iterator here. They are
5524 still the values of the character that had this display table
5525 entry or was translated, and that's what we want. */
5526 it
->what
= IT_CHARACTER
;
5531 /* Load IT with the next display element from Lisp string IT->string.
5532 IT->current.string_pos is the current position within the string.
5533 If IT->current.overlay_string_index >= 0, the Lisp string is an
5537 next_element_from_string (it
)
5540 struct text_pos position
;
5542 xassert (STRINGP (it
->string
));
5543 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5544 position
= it
->current
.string_pos
;
5546 /* Time to check for invisible text? */
5547 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5548 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5552 /* Since a handler may have changed IT->method, we must
5554 return get_next_display_element (it
);
5557 if (it
->current
.overlay_string_index
>= 0)
5559 /* Get the next character from an overlay string. In overlay
5560 strings, There is no field width or padding with spaces to
5562 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5567 else if (STRING_MULTIBYTE (it
->string
))
5569 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5570 const unsigned char *s
= (SDATA (it
->string
)
5571 + IT_STRING_BYTEPOS (*it
));
5572 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5576 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5582 /* Get the next character from a Lisp string that is not an
5583 overlay string. Such strings come from the mode line, for
5584 example. We may have to pad with spaces, or truncate the
5585 string. See also next_element_from_c_string. */
5586 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5591 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5593 /* Pad with spaces. */
5594 it
->c
= ' ', it
->len
= 1;
5595 CHARPOS (position
) = BYTEPOS (position
) = -1;
5597 else if (STRING_MULTIBYTE (it
->string
))
5599 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5600 const unsigned char *s
= (SDATA (it
->string
)
5601 + IT_STRING_BYTEPOS (*it
));
5602 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5606 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5611 /* Record what we have and where it came from. Note that we store a
5612 buffer position in IT->position although it could arguably be a
5614 it
->what
= IT_CHARACTER
;
5615 it
->object
= it
->string
;
5616 it
->position
= position
;
5621 /* Load IT with next display element from C string IT->s.
5622 IT->string_nchars is the maximum number of characters to return
5623 from the string. IT->end_charpos may be greater than
5624 IT->string_nchars when this function is called, in which case we
5625 may have to return padding spaces. Value is zero if end of string
5626 reached, including padding spaces. */
5629 next_element_from_c_string (it
)
5635 it
->what
= IT_CHARACTER
;
5636 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5639 /* IT's position can be greater IT->string_nchars in case a field
5640 width or precision has been specified when the iterator was
5642 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5644 /* End of the game. */
5648 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5650 /* Pad with spaces. */
5651 it
->c
= ' ', it
->len
= 1;
5652 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5654 else if (it
->multibyte_p
)
5656 /* Implementation note: The calls to strlen apparently aren't a
5657 performance problem because there is no noticeable performance
5658 difference between Emacs running in unibyte or multibyte mode. */
5659 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5660 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5664 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5670 /* Set up IT to return characters from an ellipsis, if appropriate.
5671 The definition of the ellipsis glyphs may come from a display table
5672 entry. This function Fills IT with the first glyph from the
5673 ellipsis if an ellipsis is to be displayed. */
5676 next_element_from_ellipsis (it
)
5679 if (it
->selective_display_ellipsis_p
)
5680 setup_for_ellipsis (it
, it
->len
);
5683 /* The face at the current position may be different from the
5684 face we find after the invisible text. Remember what it
5685 was in IT->saved_face_id, and signal that it's there by
5686 setting face_before_selective_p. */
5687 it
->saved_face_id
= it
->face_id
;
5688 it
->method
= GET_FROM_BUFFER
;
5689 reseat_at_next_visible_line_start (it
, 1);
5690 it
->face_before_selective_p
= 1;
5693 return get_next_display_element (it
);
5697 /* Deliver an image display element. The iterator IT is already
5698 filled with image information (done in handle_display_prop). Value
5703 next_element_from_image (it
)
5706 it
->what
= IT_IMAGE
;
5711 /* Fill iterator IT with next display element from a stretch glyph
5712 property. IT->object is the value of the text property. Value is
5716 next_element_from_stretch (it
)
5719 it
->what
= IT_STRETCH
;
5724 /* Load IT with the next display element from current_buffer. Value
5725 is zero if end of buffer reached. IT->stop_charpos is the next
5726 position at which to stop and check for text properties or buffer
5730 next_element_from_buffer (it
)
5735 /* Check this assumption, otherwise, we would never enter the
5736 if-statement, below. */
5737 xassert (IT_CHARPOS (*it
) >= BEGV
5738 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5740 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5742 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5744 int overlay_strings_follow_p
;
5746 /* End of the game, except when overlay strings follow that
5747 haven't been returned yet. */
5748 if (it
->overlay_strings_at_end_processed_p
)
5749 overlay_strings_follow_p
= 0;
5752 it
->overlay_strings_at_end_processed_p
= 1;
5753 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5756 if (overlay_strings_follow_p
)
5757 success_p
= get_next_display_element (it
);
5761 it
->position
= it
->current
.pos
;
5768 return get_next_display_element (it
);
5773 /* No face changes, overlays etc. in sight, so just return a
5774 character from current_buffer. */
5777 /* Maybe run the redisplay end trigger hook. Performance note:
5778 This doesn't seem to cost measurable time. */
5779 if (it
->redisplay_end_trigger_charpos
5781 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5782 run_redisplay_end_trigger_hook (it
);
5784 /* Get the next character, maybe multibyte. */
5785 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5786 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5788 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5789 - IT_BYTEPOS (*it
));
5790 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5793 it
->c
= *p
, it
->len
= 1;
5795 /* Record what we have and where it came from. */
5796 it
->what
= IT_CHARACTER
;;
5797 it
->object
= it
->w
->buffer
;
5798 it
->position
= it
->current
.pos
;
5800 /* Normally we return the character found above, except when we
5801 really want to return an ellipsis for selective display. */
5806 /* A value of selective > 0 means hide lines indented more
5807 than that number of columns. */
5808 if (it
->selective
> 0
5809 && IT_CHARPOS (*it
) + 1 < ZV
5810 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5811 IT_BYTEPOS (*it
) + 1,
5812 (double) it
->selective
)) /* iftc */
5814 success_p
= next_element_from_ellipsis (it
);
5815 it
->dpvec_char_len
= -1;
5818 else if (it
->c
== '\r' && it
->selective
== -1)
5820 /* A value of selective == -1 means that everything from the
5821 CR to the end of the line is invisible, with maybe an
5822 ellipsis displayed for it. */
5823 success_p
= next_element_from_ellipsis (it
);
5824 it
->dpvec_char_len
= -1;
5829 /* Value is zero if end of buffer reached. */
5830 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5835 /* Run the redisplay end trigger hook for IT. */
5838 run_redisplay_end_trigger_hook (it
)
5841 Lisp_Object args
[3];
5843 /* IT->glyph_row should be non-null, i.e. we should be actually
5844 displaying something, or otherwise we should not run the hook. */
5845 xassert (it
->glyph_row
);
5847 /* Set up hook arguments. */
5848 args
[0] = Qredisplay_end_trigger_functions
;
5849 args
[1] = it
->window
;
5850 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5851 it
->redisplay_end_trigger_charpos
= 0;
5853 /* Since we are *trying* to run these functions, don't try to run
5854 them again, even if they get an error. */
5855 it
->w
->redisplay_end_trigger
= Qnil
;
5856 Frun_hook_with_args (3, args
);
5858 /* Notice if it changed the face of the character we are on. */
5859 handle_face_prop (it
);
5863 /* Deliver a composition display element. The iterator IT is already
5864 filled with composition information (done in
5865 handle_composition_prop). Value is always 1. */
5868 next_element_from_composition (it
)
5871 it
->what
= IT_COMPOSITION
;
5872 it
->position
= (STRINGP (it
->string
)
5873 ? it
->current
.string_pos
5880 /***********************************************************************
5881 Moving an iterator without producing glyphs
5882 ***********************************************************************/
5884 /* Check if iterator is at a position corresponding to a valid buffer
5885 position after some move_it_ call. */
5887 #define IT_POS_VALID_AFTER_MOVE_P(it) \
5888 ((it)->method == GET_FROM_STRING \
5889 ? IT_STRING_CHARPOS (*it) == 0 \
5893 /* Move iterator IT to a specified buffer or X position within one
5894 line on the display without producing glyphs.
5896 OP should be a bit mask including some or all of these bits:
5897 MOVE_TO_X: Stop on reaching x-position TO_X.
5898 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5899 Regardless of OP's value, stop in reaching the end of the display line.
5901 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5902 This means, in particular, that TO_X includes window's horizontal
5905 The return value has several possible values that
5906 say what condition caused the scan to stop:
5908 MOVE_POS_MATCH_OR_ZV
5909 - when TO_POS or ZV was reached.
5912 -when TO_X was reached before TO_POS or ZV were reached.
5915 - when we reached the end of the display area and the line must
5919 - when we reached the end of the display area and the line is
5923 - when we stopped at a line end, i.e. a newline or a CR and selective
5926 static enum move_it_result
5927 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5929 int to_charpos
, to_x
, op
;
5931 enum move_it_result result
= MOVE_UNDEFINED
;
5932 struct glyph_row
*saved_glyph_row
;
5934 /* Don't produce glyphs in produce_glyphs. */
5935 saved_glyph_row
= it
->glyph_row
;
5936 it
->glyph_row
= NULL
;
5938 #define BUFFER_POS_REACHED_P() \
5939 ((op & MOVE_TO_POS) != 0 \
5940 && BUFFERP (it->object) \
5941 && IT_CHARPOS (*it) >= to_charpos \
5942 && (it->method == GET_FROM_BUFFER \
5943 || (it->method == GET_FROM_DISPLAY_VECTOR \
5944 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
5949 int x
, i
, ascent
= 0, descent
= 0;
5951 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
5952 if ((op
& MOVE_TO_POS
) != 0
5953 && BUFFERP (it
->object
)
5954 && it
->method
== GET_FROM_BUFFER
5955 && IT_CHARPOS (*it
) > to_charpos
)
5957 result
= MOVE_POS_MATCH_OR_ZV
;
5961 /* Stop when ZV reached.
5962 We used to stop here when TO_CHARPOS reached as well, but that is
5963 too soon if this glyph does not fit on this line. So we handle it
5964 explicitly below. */
5965 if (!get_next_display_element (it
)
5966 || (it
->truncate_lines_p
5967 && BUFFER_POS_REACHED_P ()))
5969 result
= MOVE_POS_MATCH_OR_ZV
;
5973 /* The call to produce_glyphs will get the metrics of the
5974 display element IT is loaded with. We record in x the
5975 x-position before this display element in case it does not
5979 /* Remember the line height so far in case the next element doesn't
5981 if (!it
->truncate_lines_p
)
5983 ascent
= it
->max_ascent
;
5984 descent
= it
->max_descent
;
5987 PRODUCE_GLYPHS (it
);
5989 if (it
->area
!= TEXT_AREA
)
5991 set_iterator_to_next (it
, 1);
5995 /* The number of glyphs we get back in IT->nglyphs will normally
5996 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5997 character on a terminal frame, or (iii) a line end. For the
5998 second case, IT->nglyphs - 1 padding glyphs will be present
5999 (on X frames, there is only one glyph produced for a
6000 composite character.
6002 The behavior implemented below means, for continuation lines,
6003 that as many spaces of a TAB as fit on the current line are
6004 displayed there. For terminal frames, as many glyphs of a
6005 multi-glyph character are displayed in the current line, too.
6006 This is what the old redisplay code did, and we keep it that
6007 way. Under X, the whole shape of a complex character must
6008 fit on the line or it will be completely displayed in the
6011 Note that both for tabs and padding glyphs, all glyphs have
6015 /* More than one glyph or glyph doesn't fit on line. All
6016 glyphs have the same width. */
6017 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6019 int x_before_this_char
= x
;
6020 int hpos_before_this_char
= it
->hpos
;
6022 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6024 new_x
= x
+ single_glyph_width
;
6026 /* We want to leave anything reaching TO_X to the caller. */
6027 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6029 if (BUFFER_POS_REACHED_P ())
6030 goto buffer_pos_reached
;
6032 result
= MOVE_X_REACHED
;
6035 else if (/* Lines are continued. */
6036 !it
->truncate_lines_p
6037 && (/* And glyph doesn't fit on the line. */
6038 new_x
> it
->last_visible_x
6039 /* Or it fits exactly and we're on a window
6041 || (new_x
== it
->last_visible_x
6042 && FRAME_WINDOW_P (it
->f
))))
6044 if (/* IT->hpos == 0 means the very first glyph
6045 doesn't fit on the line, e.g. a wide image. */
6047 || (new_x
== it
->last_visible_x
6048 && FRAME_WINDOW_P (it
->f
)))
6051 it
->current_x
= new_x
;
6053 /* The character's last glyph just barely fits
6055 if (i
== it
->nglyphs
- 1)
6057 /* If this is the destination position,
6058 return a position *before* it in this row,
6059 now that we know it fits in this row. */
6060 if (BUFFER_POS_REACHED_P ())
6062 it
->hpos
= hpos_before_this_char
;
6063 it
->current_x
= x_before_this_char
;
6064 result
= MOVE_POS_MATCH_OR_ZV
;
6068 set_iterator_to_next (it
, 1);
6069 #ifdef HAVE_WINDOW_SYSTEM
6070 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6072 if (!get_next_display_element (it
))
6074 result
= MOVE_POS_MATCH_OR_ZV
;
6077 if (BUFFER_POS_REACHED_P ())
6079 if (ITERATOR_AT_END_OF_LINE_P (it
))
6080 result
= MOVE_POS_MATCH_OR_ZV
;
6082 result
= MOVE_LINE_CONTINUED
;
6085 if (ITERATOR_AT_END_OF_LINE_P (it
))
6087 result
= MOVE_NEWLINE_OR_CR
;
6091 #endif /* HAVE_WINDOW_SYSTEM */
6097 it
->max_ascent
= ascent
;
6098 it
->max_descent
= descent
;
6101 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6103 result
= MOVE_LINE_CONTINUED
;
6106 else if (BUFFER_POS_REACHED_P ())
6107 goto buffer_pos_reached
;
6108 else if (new_x
> it
->first_visible_x
)
6110 /* Glyph is visible. Increment number of glyphs that
6111 would be displayed. */
6116 /* Glyph is completely off the left margin of the display
6117 area. Nothing to do. */
6121 if (result
!= MOVE_UNDEFINED
)
6124 else if (BUFFER_POS_REACHED_P ())
6128 it
->max_ascent
= ascent
;
6129 it
->max_descent
= descent
;
6130 result
= MOVE_POS_MATCH_OR_ZV
;
6133 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6135 /* Stop when TO_X specified and reached. This check is
6136 necessary here because of lines consisting of a line end,
6137 only. The line end will not produce any glyphs and we
6138 would never get MOVE_X_REACHED. */
6139 xassert (it
->nglyphs
== 0);
6140 result
= MOVE_X_REACHED
;
6144 /* Is this a line end? If yes, we're done. */
6145 if (ITERATOR_AT_END_OF_LINE_P (it
))
6147 result
= MOVE_NEWLINE_OR_CR
;
6151 /* The current display element has been consumed. Advance
6153 set_iterator_to_next (it
, 1);
6155 /* Stop if lines are truncated and IT's current x-position is
6156 past the right edge of the window now. */
6157 if (it
->truncate_lines_p
6158 && it
->current_x
>= it
->last_visible_x
)
6160 #ifdef HAVE_WINDOW_SYSTEM
6161 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6163 if (!get_next_display_element (it
)
6164 || BUFFER_POS_REACHED_P ())
6166 result
= MOVE_POS_MATCH_OR_ZV
;
6169 if (ITERATOR_AT_END_OF_LINE_P (it
))
6171 result
= MOVE_NEWLINE_OR_CR
;
6175 #endif /* HAVE_WINDOW_SYSTEM */
6176 result
= MOVE_LINE_TRUNCATED
;
6181 #undef BUFFER_POS_REACHED_P
6183 /* Restore the iterator settings altered at the beginning of this
6185 it
->glyph_row
= saved_glyph_row
;
6190 /* Move IT forward until it satisfies one or more of the criteria in
6191 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6193 OP is a bit-mask that specifies where to stop, and in particular,
6194 which of those four position arguments makes a difference. See the
6195 description of enum move_operation_enum.
6197 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6198 screen line, this function will set IT to the next position >
6202 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6204 int to_charpos
, to_x
, to_y
, to_vpos
;
6207 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6213 if (op
& MOVE_TO_VPOS
)
6215 /* If no TO_CHARPOS and no TO_X specified, stop at the
6216 start of the line TO_VPOS. */
6217 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6219 if (it
->vpos
== to_vpos
)
6225 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6229 /* TO_VPOS >= 0 means stop at TO_X in the line at
6230 TO_VPOS, or at TO_POS, whichever comes first. */
6231 if (it
->vpos
== to_vpos
)
6237 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6239 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6244 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6246 /* We have reached TO_X but not in the line we want. */
6247 skip
= move_it_in_display_line_to (it
, to_charpos
,
6249 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6257 else if (op
& MOVE_TO_Y
)
6259 struct it it_backup
;
6261 /* TO_Y specified means stop at TO_X in the line containing
6262 TO_Y---or at TO_CHARPOS if this is reached first. The
6263 problem is that we can't really tell whether the line
6264 contains TO_Y before we have completely scanned it, and
6265 this may skip past TO_X. What we do is to first scan to
6268 If TO_X is not specified, use a TO_X of zero. The reason
6269 is to make the outcome of this function more predictable.
6270 If we didn't use TO_X == 0, we would stop at the end of
6271 the line which is probably not what a caller would expect
6273 skip
= move_it_in_display_line_to (it
, to_charpos
,
6277 | (op
& MOVE_TO_POS
)));
6279 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6280 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6286 /* If TO_X was reached, we would like to know whether TO_Y
6287 is in the line. This can only be said if we know the
6288 total line height which requires us to scan the rest of
6290 if (skip
== MOVE_X_REACHED
)
6293 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6294 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6296 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6299 /* Now, decide whether TO_Y is in this line. */
6300 line_height
= it
->max_ascent
+ it
->max_descent
;
6301 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6303 if (to_y
>= it
->current_y
6304 && to_y
< it
->current_y
+ line_height
)
6306 if (skip
== MOVE_X_REACHED
)
6307 /* If TO_Y is in this line and TO_X was reached above,
6308 we scanned too far. We have to restore IT's settings
6309 to the ones before skipping. */
6313 else if (skip
== MOVE_X_REACHED
)
6316 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6324 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6328 case MOVE_POS_MATCH_OR_ZV
:
6332 case MOVE_NEWLINE_OR_CR
:
6333 set_iterator_to_next (it
, 1);
6334 it
->continuation_lines_width
= 0;
6337 case MOVE_LINE_TRUNCATED
:
6338 it
->continuation_lines_width
= 0;
6339 reseat_at_next_visible_line_start (it
, 0);
6340 if ((op
& MOVE_TO_POS
) != 0
6341 && IT_CHARPOS (*it
) > to_charpos
)
6348 case MOVE_LINE_CONTINUED
:
6349 it
->continuation_lines_width
+= it
->current_x
;
6356 /* Reset/increment for the next run. */
6357 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6358 it
->current_x
= it
->hpos
= 0;
6359 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6361 last_height
= it
->max_ascent
+ it
->max_descent
;
6362 last_max_ascent
= it
->max_ascent
;
6363 it
->max_ascent
= it
->max_descent
= 0;
6368 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6372 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6374 If DY > 0, move IT backward at least that many pixels. DY = 0
6375 means move IT backward to the preceding line start or BEGV. This
6376 function may move over more than DY pixels if IT->current_y - DY
6377 ends up in the middle of a line; in this case IT->current_y will be
6378 set to the top of the line moved to. */
6381 move_it_vertically_backward (it
, dy
)
6392 start_pos
= IT_CHARPOS (*it
);
6394 /* Estimate how many newlines we must move back. */
6395 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6397 /* Set the iterator's position that many lines back. */
6398 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6399 back_to_previous_visible_line_start (it
);
6401 /* Reseat the iterator here. When moving backward, we don't want
6402 reseat to skip forward over invisible text, set up the iterator
6403 to deliver from overlay strings at the new position etc. So,
6404 use reseat_1 here. */
6405 reseat_1 (it
, it
->current
.pos
, 1);
6407 /* We are now surely at a line start. */
6408 it
->current_x
= it
->hpos
= 0;
6409 it
->continuation_lines_width
= 0;
6411 /* Move forward and see what y-distance we moved. First move to the
6412 start of the next line so that we get its height. We need this
6413 height to be able to tell whether we reached the specified
6416 it2
.max_ascent
= it2
.max_descent
= 0;
6419 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6420 MOVE_TO_POS
| MOVE_TO_VPOS
);
6422 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6423 xassert (IT_CHARPOS (*it
) >= BEGV
);
6426 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6427 xassert (IT_CHARPOS (*it
) >= BEGV
);
6428 /* H is the actual vertical distance from the position in *IT
6429 and the starting position. */
6430 h
= it2
.current_y
- it
->current_y
;
6431 /* NLINES is the distance in number of lines. */
6432 nlines
= it2
.vpos
- it
->vpos
;
6434 /* Correct IT's y and vpos position
6435 so that they are relative to the starting point. */
6441 /* DY == 0 means move to the start of the screen line. The
6442 value of nlines is > 0 if continuation lines were involved. */
6444 move_it_by_lines (it
, nlines
, 1);
6446 /* I think this assert is bogus if buffer contains
6447 invisible text or images. KFS. */
6448 xassert (IT_CHARPOS (*it
) <= start_pos
);
6453 /* The y-position we try to reach, relative to *IT.
6454 Note that H has been subtracted in front of the if-statement. */
6455 int target_y
= it
->current_y
+ h
- dy
;
6456 int y0
= it3
.current_y
;
6457 int y1
= line_bottom_y (&it3
);
6458 int line_height
= y1
- y0
;
6460 /* If we did not reach target_y, try to move further backward if
6461 we can. If we moved too far backward, try to move forward. */
6462 if (target_y
< it
->current_y
6463 /* This is heuristic. In a window that's 3 lines high, with
6464 a line height of 13 pixels each, recentering with point
6465 on the bottom line will try to move -39/2 = 19 pixels
6466 backward. Try to avoid moving into the first line. */
6467 && (it
->current_y
- target_y
6468 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6469 && IT_CHARPOS (*it
) > BEGV
)
6471 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6472 target_y
- it
->current_y
));
6473 dy
= it
->current_y
- target_y
;
6474 goto move_further_back
;
6476 else if (target_y
>= it
->current_y
+ line_height
6477 && IT_CHARPOS (*it
) < ZV
)
6479 /* Should move forward by at least one line, maybe more.
6481 Note: Calling move_it_by_lines can be expensive on
6482 terminal frames, where compute_motion is used (via
6483 vmotion) to do the job, when there are very long lines
6484 and truncate-lines is nil. That's the reason for
6485 treating terminal frames specially here. */
6487 if (!FRAME_WINDOW_P (it
->f
))
6488 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6493 move_it_by_lines (it
, 1, 1);
6495 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6499 /* I think this assert is bogus if buffer contains
6500 invisible text or images. KFS. */
6501 xassert (IT_CHARPOS (*it
) >= BEGV
);
6508 /* Move IT by a specified amount of pixel lines DY. DY negative means
6509 move backwards. DY = 0 means move to start of screen line. At the
6510 end, IT will be on the start of a screen line. */
6513 move_it_vertically (it
, dy
)
6518 move_it_vertically_backward (it
, -dy
);
6521 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6522 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6523 MOVE_TO_POS
| MOVE_TO_Y
);
6524 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6526 /* If buffer ends in ZV without a newline, move to the start of
6527 the line to satisfy the post-condition. */
6528 if (IT_CHARPOS (*it
) == ZV
6530 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6531 move_it_by_lines (it
, 0, 0);
6536 /* Move iterator IT past the end of the text line it is in. */
6539 move_it_past_eol (it
)
6542 enum move_it_result rc
;
6544 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6545 if (rc
== MOVE_NEWLINE_OR_CR
)
6546 set_iterator_to_next (it
, 0);
6550 #if 0 /* Currently not used. */
6552 /* Return non-zero if some text between buffer positions START_CHARPOS
6553 and END_CHARPOS is invisible. IT->window is the window for text
6557 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6559 int start_charpos
, end_charpos
;
6561 Lisp_Object prop
, limit
;
6562 int invisible_found_p
;
6564 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6566 /* Is text at START invisible? */
6567 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6569 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6570 invisible_found_p
= 1;
6573 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6575 make_number (end_charpos
));
6576 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6579 return invisible_found_p
;
6585 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6586 negative means move up. DVPOS == 0 means move to the start of the
6587 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6588 NEED_Y_P is zero, IT->current_y will be left unchanged.
6590 Further optimization ideas: If we would know that IT->f doesn't use
6591 a face with proportional font, we could be faster for
6592 truncate-lines nil. */
6595 move_it_by_lines (it
, dvpos
, need_y_p
)
6597 int dvpos
, need_y_p
;
6599 struct position pos
;
6601 if (!FRAME_WINDOW_P (it
->f
))
6603 struct text_pos textpos
;
6605 /* We can use vmotion on frames without proportional fonts. */
6606 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6607 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6608 reseat (it
, textpos
, 1);
6609 it
->vpos
+= pos
.vpos
;
6610 it
->current_y
+= pos
.vpos
;
6612 else if (dvpos
== 0)
6614 /* DVPOS == 0 means move to the start of the screen line. */
6615 move_it_vertically_backward (it
, 0);
6616 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6617 /* Let next call to line_bottom_y calculate real line height */
6622 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6623 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6624 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6629 int start_charpos
, i
;
6631 /* Start at the beginning of the screen line containing IT's
6632 position. This may actually move vertically backwards,
6633 in case of overlays, so adjust dvpos accordingly. */
6635 move_it_vertically_backward (it
, 0);
6638 /* Go back -DVPOS visible lines and reseat the iterator there. */
6639 start_charpos
= IT_CHARPOS (*it
);
6640 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6641 back_to_previous_visible_line_start (it
);
6642 reseat (it
, it
->current
.pos
, 1);
6644 /* Move further back if we end up in a string or an image. */
6645 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
6647 /* First try to move to start of display line. */
6649 move_it_vertically_backward (it
, 0);
6651 if (IT_POS_VALID_AFTER_MOVE_P (it
))
6653 /* If start of line is still in string or image,
6654 move further back. */
6655 back_to_previous_visible_line_start (it
);
6656 reseat (it
, it
->current
.pos
, 1);
6660 it
->current_x
= it
->hpos
= 0;
6662 /* Above call may have moved too far if continuation lines
6663 are involved. Scan forward and see if it did. */
6665 it2
.vpos
= it2
.current_y
= 0;
6666 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6667 it
->vpos
-= it2
.vpos
;
6668 it
->current_y
-= it2
.current_y
;
6669 it
->current_x
= it
->hpos
= 0;
6671 /* If we moved too far back, move IT some lines forward. */
6672 if (it2
.vpos
> -dvpos
)
6674 int delta
= it2
.vpos
+ dvpos
;
6676 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6677 /* Move back again if we got too far ahead. */
6678 if (IT_CHARPOS (*it
) >= start_charpos
)
6684 /* Return 1 if IT points into the middle of a display vector. */
6687 in_display_vector_p (it
)
6690 return (it
->method
== GET_FROM_DISPLAY_VECTOR
6691 && it
->current
.dpvec_index
> 0
6692 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6696 /***********************************************************************
6698 ***********************************************************************/
6701 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6705 add_to_log (format
, arg1
, arg2
)
6707 Lisp_Object arg1
, arg2
;
6709 Lisp_Object args
[3];
6710 Lisp_Object msg
, fmt
;
6713 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6716 /* Do nothing if called asynchronously. Inserting text into
6717 a buffer may call after-change-functions and alike and
6718 that would means running Lisp asynchronously. */
6719 if (handling_signal
)
6723 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6725 args
[0] = fmt
= build_string (format
);
6728 msg
= Fformat (3, args
);
6730 len
= SBYTES (msg
) + 1;
6731 SAFE_ALLOCA (buffer
, char *, len
);
6732 bcopy (SDATA (msg
), buffer
, len
);
6734 message_dolog (buffer
, len
- 1, 1, 0);
6741 /* Output a newline in the *Messages* buffer if "needs" one. */
6744 message_log_maybe_newline ()
6746 if (message_log_need_newline
)
6747 message_dolog ("", 0, 1, 0);
6751 /* Add a string M of length NBYTES to the message log, optionally
6752 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6753 nonzero, means interpret the contents of M as multibyte. This
6754 function calls low-level routines in order to bypass text property
6755 hooks, etc. which might not be safe to run.
6757 This may GC (insert may run before/after change hooks),
6758 so the buffer M must NOT point to a Lisp string. */
6761 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6763 int nbytes
, nlflag
, multibyte
;
6765 if (!NILP (Vmemory_full
))
6768 if (!NILP (Vmessage_log_max
))
6770 struct buffer
*oldbuf
;
6771 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6772 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6773 int point_at_end
= 0;
6775 Lisp_Object old_deactivate_mark
, tem
;
6776 struct gcpro gcpro1
;
6778 old_deactivate_mark
= Vdeactivate_mark
;
6779 oldbuf
= current_buffer
;
6780 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6781 current_buffer
->undo_list
= Qt
;
6783 oldpoint
= message_dolog_marker1
;
6784 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6785 oldbegv
= message_dolog_marker2
;
6786 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6787 oldzv
= message_dolog_marker3
;
6788 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6789 GCPRO1 (old_deactivate_mark
);
6797 BEGV_BYTE
= BEG_BYTE
;
6800 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6802 /* Insert the string--maybe converting multibyte to single byte
6803 or vice versa, so that all the text fits the buffer. */
6805 && NILP (current_buffer
->enable_multibyte_characters
))
6807 int i
, c
, char_bytes
;
6808 unsigned char work
[1];
6810 /* Convert a multibyte string to single-byte
6811 for the *Message* buffer. */
6812 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6814 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6815 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6817 : multibyte_char_to_unibyte (c
, Qnil
));
6818 insert_1_both (work
, 1, 1, 1, 0, 0);
6821 else if (! multibyte
6822 && ! NILP (current_buffer
->enable_multibyte_characters
))
6824 int i
, c
, char_bytes
;
6825 unsigned char *msg
= (unsigned char *) m
;
6826 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6827 /* Convert a single-byte string to multibyte
6828 for the *Message* buffer. */
6829 for (i
= 0; i
< nbytes
; i
++)
6831 c
= unibyte_char_to_multibyte (msg
[i
]);
6832 char_bytes
= CHAR_STRING (c
, str
);
6833 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6837 insert_1 (m
, nbytes
, 1, 0, 0);
6841 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6842 insert_1 ("\n", 1, 1, 0, 0);
6844 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6846 this_bol_byte
= PT_BYTE
;
6848 /* See if this line duplicates the previous one.
6849 If so, combine duplicates. */
6852 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6854 prev_bol_byte
= PT_BYTE
;
6856 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6857 this_bol
, this_bol_byte
);
6860 del_range_both (prev_bol
, prev_bol_byte
,
6861 this_bol
, this_bol_byte
, 0);
6867 /* If you change this format, don't forget to also
6868 change message_log_check_duplicate. */
6869 sprintf (dupstr
, " [%d times]", dup
);
6870 duplen
= strlen (dupstr
);
6871 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6872 insert_1 (dupstr
, duplen
, 1, 0, 1);
6877 /* If we have more than the desired maximum number of lines
6878 in the *Messages* buffer now, delete the oldest ones.
6879 This is safe because we don't have undo in this buffer. */
6881 if (NATNUMP (Vmessage_log_max
))
6883 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6884 -XFASTINT (Vmessage_log_max
) - 1, 0);
6885 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6888 BEGV
= XMARKER (oldbegv
)->charpos
;
6889 BEGV_BYTE
= marker_byte_position (oldbegv
);
6898 ZV
= XMARKER (oldzv
)->charpos
;
6899 ZV_BYTE
= marker_byte_position (oldzv
);
6903 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6905 /* We can't do Fgoto_char (oldpoint) because it will run some
6907 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6908 XMARKER (oldpoint
)->bytepos
);
6911 unchain_marker (XMARKER (oldpoint
));
6912 unchain_marker (XMARKER (oldbegv
));
6913 unchain_marker (XMARKER (oldzv
));
6915 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6916 set_buffer_internal (oldbuf
);
6918 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6919 message_log_need_newline
= !nlflag
;
6920 Vdeactivate_mark
= old_deactivate_mark
;
6925 /* We are at the end of the buffer after just having inserted a newline.
6926 (Note: We depend on the fact we won't be crossing the gap.)
6927 Check to see if the most recent message looks a lot like the previous one.
6928 Return 0 if different, 1 if the new one should just replace it, or a
6929 value N > 1 if we should also append " [N times]". */
6932 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6933 int prev_bol
, this_bol
;
6934 int prev_bol_byte
, this_bol_byte
;
6937 int len
= Z_BYTE
- 1 - this_bol_byte
;
6939 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6940 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6942 for (i
= 0; i
< len
; i
++)
6944 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6952 if (*p1
++ == ' ' && *p1
++ == '[')
6955 while (*p1
>= '0' && *p1
<= '9')
6956 n
= n
* 10 + *p1
++ - '0';
6957 if (strncmp (p1
, " times]\n", 8) == 0)
6964 /* Display an echo area message M with a specified length of NBYTES
6965 bytes. The string may include null characters. If M is 0, clear
6966 out any existing message, and let the mini-buffer text show
6969 This may GC, so the buffer M must NOT point to a Lisp string. */
6972 message2 (m
, nbytes
, multibyte
)
6977 /* First flush out any partial line written with print. */
6978 message_log_maybe_newline ();
6980 message_dolog (m
, nbytes
, 1, multibyte
);
6981 message2_nolog (m
, nbytes
, multibyte
);
6985 /* The non-logging counterpart of message2. */
6988 message2_nolog (m
, nbytes
, multibyte
)
6990 int nbytes
, multibyte
;
6992 struct frame
*sf
= SELECTED_FRAME ();
6993 message_enable_multibyte
= multibyte
;
6997 if (noninteractive_need_newline
)
6998 putc ('\n', stderr
);
6999 noninteractive_need_newline
= 0;
7001 fwrite (m
, nbytes
, 1, stderr
);
7002 if (cursor_in_echo_area
== 0)
7003 fprintf (stderr
, "\n");
7006 /* A null message buffer means that the frame hasn't really been
7007 initialized yet. Error messages get reported properly by
7008 cmd_error, so this must be just an informative message; toss it. */
7009 else if (INTERACTIVE
7010 && sf
->glyphs_initialized_p
7011 && FRAME_MESSAGE_BUF (sf
))
7013 Lisp_Object mini_window
;
7016 /* Get the frame containing the mini-buffer
7017 that the selected frame is using. */
7018 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7019 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7021 FRAME_SAMPLE_VISIBILITY (f
);
7022 if (FRAME_VISIBLE_P (sf
)
7023 && ! FRAME_VISIBLE_P (f
))
7024 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7028 set_message (m
, Qnil
, nbytes
, multibyte
);
7029 if (minibuffer_auto_raise
)
7030 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7033 clear_message (1, 1);
7035 do_pending_window_change (0);
7036 echo_area_display (1);
7037 do_pending_window_change (0);
7038 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7039 (*frame_up_to_date_hook
) (f
);
7044 /* Display an echo area message M with a specified length of NBYTES
7045 bytes. The string may include null characters. If M is not a
7046 string, clear out any existing message, and let the mini-buffer
7049 This function cancels echoing. */
7052 message3 (m
, nbytes
, multibyte
)
7057 struct gcpro gcpro1
;
7060 clear_message (1,1);
7063 /* First flush out any partial line written with print. */
7064 message_log_maybe_newline ();
7070 SAFE_ALLOCA (buffer
, char *, nbytes
);
7071 bcopy (SDATA (m
), buffer
, nbytes
);
7072 message_dolog (buffer
, nbytes
, 1, multibyte
);
7075 message3_nolog (m
, nbytes
, multibyte
);
7081 /* The non-logging version of message3.
7082 This does not cancel echoing, because it is used for echoing.
7083 Perhaps we need to make a separate function for echoing
7084 and make this cancel echoing. */
7087 message3_nolog (m
, nbytes
, multibyte
)
7089 int nbytes
, multibyte
;
7091 struct frame
*sf
= SELECTED_FRAME ();
7092 message_enable_multibyte
= multibyte
;
7096 if (noninteractive_need_newline
)
7097 putc ('\n', stderr
);
7098 noninteractive_need_newline
= 0;
7100 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7101 if (cursor_in_echo_area
== 0)
7102 fprintf (stderr
, "\n");
7105 /* A null message buffer means that the frame hasn't really been
7106 initialized yet. Error messages get reported properly by
7107 cmd_error, so this must be just an informative message; toss it. */
7108 else if (INTERACTIVE
7109 && sf
->glyphs_initialized_p
7110 && FRAME_MESSAGE_BUF (sf
))
7112 Lisp_Object mini_window
;
7116 /* Get the frame containing the mini-buffer
7117 that the selected frame is using. */
7118 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7119 frame
= XWINDOW (mini_window
)->frame
;
7122 FRAME_SAMPLE_VISIBILITY (f
);
7123 if (FRAME_VISIBLE_P (sf
)
7124 && !FRAME_VISIBLE_P (f
))
7125 Fmake_frame_visible (frame
);
7127 if (STRINGP (m
) && SCHARS (m
) > 0)
7129 set_message (NULL
, m
, nbytes
, multibyte
);
7130 if (minibuffer_auto_raise
)
7131 Fraise_frame (frame
);
7132 /* Assume we are not echoing.
7133 (If we are, echo_now will override this.) */
7134 echo_message_buffer
= Qnil
;
7137 clear_message (1, 1);
7139 do_pending_window_change (0);
7140 echo_area_display (1);
7141 do_pending_window_change (0);
7142 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7143 (*frame_up_to_date_hook
) (f
);
7148 /* Display a null-terminated echo area message M. If M is 0, clear
7149 out any existing message, and let the mini-buffer text show through.
7151 The buffer M must continue to exist until after the echo area gets
7152 cleared or some other message gets displayed there. Do not pass
7153 text that is stored in a Lisp string. Do not pass text in a buffer
7154 that was alloca'd. */
7160 message2 (m
, (m
? strlen (m
) : 0), 0);
7164 /* The non-logging counterpart of message1. */
7170 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7173 /* Display a message M which contains a single %s
7174 which gets replaced with STRING. */
7177 message_with_string (m
, string
, log
)
7182 CHECK_STRING (string
);
7188 if (noninteractive_need_newline
)
7189 putc ('\n', stderr
);
7190 noninteractive_need_newline
= 0;
7191 fprintf (stderr
, m
, SDATA (string
));
7192 if (cursor_in_echo_area
== 0)
7193 fprintf (stderr
, "\n");
7197 else if (INTERACTIVE
)
7199 /* The frame whose minibuffer we're going to display the message on.
7200 It may be larger than the selected frame, so we need
7201 to use its buffer, not the selected frame's buffer. */
7202 Lisp_Object mini_window
;
7203 struct frame
*f
, *sf
= SELECTED_FRAME ();
7205 /* Get the frame containing the minibuffer
7206 that the selected frame is using. */
7207 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7208 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7210 /* A null message buffer means that the frame hasn't really been
7211 initialized yet. Error messages get reported properly by
7212 cmd_error, so this must be just an informative message; toss it. */
7213 if (FRAME_MESSAGE_BUF (f
))
7215 Lisp_Object args
[2], message
;
7216 struct gcpro gcpro1
, gcpro2
;
7218 args
[0] = build_string (m
);
7219 args
[1] = message
= string
;
7220 GCPRO2 (args
[0], message
);
7223 message
= Fformat (2, args
);
7226 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7228 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7232 /* Print should start at the beginning of the message
7233 buffer next time. */
7234 message_buf_print
= 0;
7240 /* Dump an informative message to the minibuf. If M is 0, clear out
7241 any existing message, and let the mini-buffer text show through. */
7245 message (m
, a1
, a2
, a3
)
7247 EMACS_INT a1
, a2
, a3
;
7253 if (noninteractive_need_newline
)
7254 putc ('\n', stderr
);
7255 noninteractive_need_newline
= 0;
7256 fprintf (stderr
, m
, a1
, a2
, a3
);
7257 if (cursor_in_echo_area
== 0)
7258 fprintf (stderr
, "\n");
7262 else if (INTERACTIVE
)
7264 /* The frame whose mini-buffer we're going to display the message
7265 on. It may be larger than the selected frame, so we need to
7266 use its buffer, not the selected frame's buffer. */
7267 Lisp_Object mini_window
;
7268 struct frame
*f
, *sf
= SELECTED_FRAME ();
7270 /* Get the frame containing the mini-buffer
7271 that the selected frame is using. */
7272 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7273 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7275 /* A null message buffer means that the frame hasn't really been
7276 initialized yet. Error messages get reported properly by
7277 cmd_error, so this must be just an informative message; toss
7279 if (FRAME_MESSAGE_BUF (f
))
7290 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7291 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7293 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7294 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7296 #endif /* NO_ARG_ARRAY */
7298 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7303 /* Print should start at the beginning of the message
7304 buffer next time. */
7305 message_buf_print
= 0;
7311 /* The non-logging version of message. */
7314 message_nolog (m
, a1
, a2
, a3
)
7316 EMACS_INT a1
, a2
, a3
;
7318 Lisp_Object old_log_max
;
7319 old_log_max
= Vmessage_log_max
;
7320 Vmessage_log_max
= Qnil
;
7321 message (m
, a1
, a2
, a3
);
7322 Vmessage_log_max
= old_log_max
;
7326 /* Display the current message in the current mini-buffer. This is
7327 only called from error handlers in process.c, and is not time
7333 if (!NILP (echo_area_buffer
[0]))
7336 string
= Fcurrent_message ();
7337 message3 (string
, SBYTES (string
),
7338 !NILP (current_buffer
->enable_multibyte_characters
));
7343 /* Make sure echo area buffers in `echo_buffers' are live.
7344 If they aren't, make new ones. */
7347 ensure_echo_area_buffers ()
7351 for (i
= 0; i
< 2; ++i
)
7352 if (!BUFFERP (echo_buffer
[i
])
7353 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7356 Lisp_Object old_buffer
;
7359 old_buffer
= echo_buffer
[i
];
7360 sprintf (name
, " *Echo Area %d*", i
);
7361 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7362 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7364 for (j
= 0; j
< 2; ++j
)
7365 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7366 echo_area_buffer
[j
] = echo_buffer
[i
];
7371 /* Call FN with args A1..A4 with either the current or last displayed
7372 echo_area_buffer as current buffer.
7374 WHICH zero means use the current message buffer
7375 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7376 from echo_buffer[] and clear it.
7378 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7379 suitable buffer from echo_buffer[] and clear it.
7381 Value is what FN returns. */
7384 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7387 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7393 int this_one
, the_other
, clear_buffer_p
, rc
;
7394 int count
= SPECPDL_INDEX ();
7396 /* If buffers aren't live, make new ones. */
7397 ensure_echo_area_buffers ();
7402 this_one
= 0, the_other
= 1;
7404 this_one
= 1, the_other
= 0;
7406 /* Choose a suitable buffer from echo_buffer[] is we don't
7408 if (NILP (echo_area_buffer
[this_one
]))
7410 echo_area_buffer
[this_one
]
7411 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7412 ? echo_buffer
[the_other
]
7413 : echo_buffer
[this_one
]);
7417 buffer
= echo_area_buffer
[this_one
];
7419 /* Don't get confused by reusing the buffer used for echoing
7420 for a different purpose. */
7421 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7424 record_unwind_protect (unwind_with_echo_area_buffer
,
7425 with_echo_area_buffer_unwind_data (w
));
7427 /* Make the echo area buffer current. Note that for display
7428 purposes, it is not necessary that the displayed window's buffer
7429 == current_buffer, except for text property lookup. So, let's
7430 only set that buffer temporarily here without doing a full
7431 Fset_window_buffer. We must also change w->pointm, though,
7432 because otherwise an assertions in unshow_buffer fails, and Emacs
7434 set_buffer_internal_1 (XBUFFER (buffer
));
7438 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7441 current_buffer
->undo_list
= Qt
;
7442 current_buffer
->read_only
= Qnil
;
7443 specbind (Qinhibit_read_only
, Qt
);
7444 specbind (Qinhibit_modification_hooks
, Qt
);
7446 if (clear_buffer_p
&& Z
> BEG
)
7449 xassert (BEGV
>= BEG
);
7450 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7452 rc
= fn (a1
, a2
, a3
, a4
);
7454 xassert (BEGV
>= BEG
);
7455 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7457 unbind_to (count
, Qnil
);
7462 /* Save state that should be preserved around the call to the function
7463 FN called in with_echo_area_buffer. */
7466 with_echo_area_buffer_unwind_data (w
)
7472 /* Reduce consing by keeping one vector in
7473 Vwith_echo_area_save_vector. */
7474 vector
= Vwith_echo_area_save_vector
;
7475 Vwith_echo_area_save_vector
= Qnil
;
7478 vector
= Fmake_vector (make_number (7), Qnil
);
7480 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7481 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7482 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7486 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7487 AREF (vector
, i
) = w
->buffer
; ++i
;
7488 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7489 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7494 for (; i
< end
; ++i
)
7495 AREF (vector
, i
) = Qnil
;
7498 xassert (i
== ASIZE (vector
));
7503 /* Restore global state from VECTOR which was created by
7504 with_echo_area_buffer_unwind_data. */
7507 unwind_with_echo_area_buffer (vector
)
7510 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7511 Vdeactivate_mark
= AREF (vector
, 1);
7512 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7514 if (WINDOWP (AREF (vector
, 3)))
7517 Lisp_Object buffer
, charpos
, bytepos
;
7519 w
= XWINDOW (AREF (vector
, 3));
7520 buffer
= AREF (vector
, 4);
7521 charpos
= AREF (vector
, 5);
7522 bytepos
= AREF (vector
, 6);
7525 set_marker_both (w
->pointm
, buffer
,
7526 XFASTINT (charpos
), XFASTINT (bytepos
));
7529 Vwith_echo_area_save_vector
= vector
;
7534 /* Set up the echo area for use by print functions. MULTIBYTE_P
7535 non-zero means we will print multibyte. */
7538 setup_echo_area_for_printing (multibyte_p
)
7541 /* If we can't find an echo area any more, exit. */
7542 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7545 ensure_echo_area_buffers ();
7547 if (!message_buf_print
)
7549 /* A message has been output since the last time we printed.
7550 Choose a fresh echo area buffer. */
7551 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7552 echo_area_buffer
[0] = echo_buffer
[1];
7554 echo_area_buffer
[0] = echo_buffer
[0];
7556 /* Switch to that buffer and clear it. */
7557 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7558 current_buffer
->truncate_lines
= Qnil
;
7562 int count
= SPECPDL_INDEX ();
7563 specbind (Qinhibit_read_only
, Qt
);
7564 /* Note that undo recording is always disabled. */
7566 unbind_to (count
, Qnil
);
7568 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7570 /* Set up the buffer for the multibyteness we need. */
7572 != !NILP (current_buffer
->enable_multibyte_characters
))
7573 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7575 /* Raise the frame containing the echo area. */
7576 if (minibuffer_auto_raise
)
7578 struct frame
*sf
= SELECTED_FRAME ();
7579 Lisp_Object mini_window
;
7580 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7581 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7584 message_log_maybe_newline ();
7585 message_buf_print
= 1;
7589 if (NILP (echo_area_buffer
[0]))
7591 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7592 echo_area_buffer
[0] = echo_buffer
[1];
7594 echo_area_buffer
[0] = echo_buffer
[0];
7597 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7599 /* Someone switched buffers between print requests. */
7600 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7601 current_buffer
->truncate_lines
= Qnil
;
7607 /* Display an echo area message in window W. Value is non-zero if W's
7608 height is changed. If display_last_displayed_message_p is
7609 non-zero, display the message that was last displayed, otherwise
7610 display the current message. */
7613 display_echo_area (w
)
7616 int i
, no_message_p
, window_height_changed_p
, count
;
7618 /* Temporarily disable garbage collections while displaying the echo
7619 area. This is done because a GC can print a message itself.
7620 That message would modify the echo area buffer's contents while a
7621 redisplay of the buffer is going on, and seriously confuse
7623 count
= inhibit_garbage_collection ();
7625 /* If there is no message, we must call display_echo_area_1
7626 nevertheless because it resizes the window. But we will have to
7627 reset the echo_area_buffer in question to nil at the end because
7628 with_echo_area_buffer will sets it to an empty buffer. */
7629 i
= display_last_displayed_message_p
? 1 : 0;
7630 no_message_p
= NILP (echo_area_buffer
[i
]);
7632 window_height_changed_p
7633 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7634 display_echo_area_1
,
7635 (EMACS_INT
) w
, Qnil
, 0, 0);
7638 echo_area_buffer
[i
] = Qnil
;
7640 unbind_to (count
, Qnil
);
7641 return window_height_changed_p
;
7645 /* Helper for display_echo_area. Display the current buffer which
7646 contains the current echo area message in window W, a mini-window,
7647 a pointer to which is passed in A1. A2..A4 are currently not used.
7648 Change the height of W so that all of the message is displayed.
7649 Value is non-zero if height of W was changed. */
7652 display_echo_area_1 (a1
, a2
, a3
, a4
)
7657 struct window
*w
= (struct window
*) a1
;
7659 struct text_pos start
;
7660 int window_height_changed_p
= 0;
7662 /* Do this before displaying, so that we have a large enough glyph
7663 matrix for the display. If we can't get enough space for the
7664 whole text, display the last N lines. That works by setting w->start. */
7665 window_height_changed_p
= resize_mini_window (w
, 0);
7667 /* Use the starting position chosen by resize_mini_window. */
7668 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
7671 clear_glyph_matrix (w
->desired_matrix
);
7672 XSETWINDOW (window
, w
);
7673 try_window (window
, start
, 0);
7675 return window_height_changed_p
;
7679 /* Resize the echo area window to exactly the size needed for the
7680 currently displayed message, if there is one. If a mini-buffer
7681 is active, don't shrink it. */
7684 resize_echo_area_exactly ()
7686 if (BUFFERP (echo_area_buffer
[0])
7687 && WINDOWP (echo_area_window
))
7689 struct window
*w
= XWINDOW (echo_area_window
);
7691 Lisp_Object resize_exactly
;
7693 if (minibuf_level
== 0)
7694 resize_exactly
= Qt
;
7696 resize_exactly
= Qnil
;
7698 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7699 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7702 ++windows_or_buffers_changed
;
7703 ++update_mode_lines
;
7704 redisplay_internal (0);
7710 /* Callback function for with_echo_area_buffer, when used from
7711 resize_echo_area_exactly. A1 contains a pointer to the window to
7712 resize, EXACTLY non-nil means resize the mini-window exactly to the
7713 size of the text displayed. A3 and A4 are not used. Value is what
7714 resize_mini_window returns. */
7717 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7719 Lisp_Object exactly
;
7722 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7726 /* Resize mini-window W to fit the size of its contents. EXACT:P
7727 means size the window exactly to the size needed. Otherwise, it's
7728 only enlarged until W's buffer is empty.
7730 Set W->start to the right place to begin display. If the whole
7731 contents fit, start at the beginning. Otherwise, start so as
7732 to make the end of the contents appear. This is particularly
7733 important for y-or-n-p, but seems desirable generally.
7735 Value is non-zero if the window height has been changed. */
7738 resize_mini_window (w
, exact_p
)
7742 struct frame
*f
= XFRAME (w
->frame
);
7743 int window_height_changed_p
= 0;
7745 xassert (MINI_WINDOW_P (w
));
7747 /* By default, start display at the beginning. */
7748 set_marker_both (w
->start
, w
->buffer
,
7749 BUF_BEGV (XBUFFER (w
->buffer
)),
7750 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
7752 /* Don't resize windows while redisplaying a window; it would
7753 confuse redisplay functions when the size of the window they are
7754 displaying changes from under them. Such a resizing can happen,
7755 for instance, when which-func prints a long message while
7756 we are running fontification-functions. We're running these
7757 functions with safe_call which binds inhibit-redisplay to t. */
7758 if (!NILP (Vinhibit_redisplay
))
7761 /* Nil means don't try to resize. */
7762 if (NILP (Vresize_mini_windows
)
7763 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7766 if (!FRAME_MINIBUF_ONLY_P (f
))
7769 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7770 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7771 int height
, max_height
;
7772 int unit
= FRAME_LINE_HEIGHT (f
);
7773 struct text_pos start
;
7774 struct buffer
*old_current_buffer
= NULL
;
7776 if (current_buffer
!= XBUFFER (w
->buffer
))
7778 old_current_buffer
= current_buffer
;
7779 set_buffer_internal (XBUFFER (w
->buffer
));
7782 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7784 /* Compute the max. number of lines specified by the user. */
7785 if (FLOATP (Vmax_mini_window_height
))
7786 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7787 else if (INTEGERP (Vmax_mini_window_height
))
7788 max_height
= XINT (Vmax_mini_window_height
);
7790 max_height
= total_height
/ 4;
7792 /* Correct that max. height if it's bogus. */
7793 max_height
= max (1, max_height
);
7794 max_height
= min (total_height
, max_height
);
7796 /* Find out the height of the text in the window. */
7797 if (it
.truncate_lines_p
)
7802 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7803 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7804 height
= it
.current_y
+ last_height
;
7806 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7807 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7808 height
= (height
+ unit
- 1) / unit
;
7811 /* Compute a suitable window start. */
7812 if (height
> max_height
)
7814 height
= max_height
;
7815 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7816 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7817 start
= it
.current
.pos
;
7820 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7821 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7823 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7825 /* Let it grow only, until we display an empty message, in which
7826 case the window shrinks again. */
7827 if (height
> WINDOW_TOTAL_LINES (w
))
7829 int old_height
= WINDOW_TOTAL_LINES (w
);
7830 freeze_window_starts (f
, 1);
7831 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7832 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7834 else if (height
< WINDOW_TOTAL_LINES (w
)
7835 && (exact_p
|| BEGV
== ZV
))
7837 int old_height
= WINDOW_TOTAL_LINES (w
);
7838 freeze_window_starts (f
, 0);
7839 shrink_mini_window (w
);
7840 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7845 /* Always resize to exact size needed. */
7846 if (height
> WINDOW_TOTAL_LINES (w
))
7848 int old_height
= WINDOW_TOTAL_LINES (w
);
7849 freeze_window_starts (f
, 1);
7850 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7851 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7853 else if (height
< WINDOW_TOTAL_LINES (w
))
7855 int old_height
= WINDOW_TOTAL_LINES (w
);
7856 freeze_window_starts (f
, 0);
7857 shrink_mini_window (w
);
7861 freeze_window_starts (f
, 1);
7862 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7865 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7869 if (old_current_buffer
)
7870 set_buffer_internal (old_current_buffer
);
7873 return window_height_changed_p
;
7877 /* Value is the current message, a string, or nil if there is no
7885 if (NILP (echo_area_buffer
[0]))
7889 with_echo_area_buffer (0, 0, current_message_1
,
7890 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7892 echo_area_buffer
[0] = Qnil
;
7900 current_message_1 (a1
, a2
, a3
, a4
)
7905 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7908 *msg
= make_buffer_string (BEG
, Z
, 1);
7915 /* Push the current message on Vmessage_stack for later restauration
7916 by restore_message. Value is non-zero if the current message isn't
7917 empty. This is a relatively infrequent operation, so it's not
7918 worth optimizing. */
7924 msg
= current_message ();
7925 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7926 return STRINGP (msg
);
7930 /* Restore message display from the top of Vmessage_stack. */
7937 xassert (CONSP (Vmessage_stack
));
7938 msg
= XCAR (Vmessage_stack
);
7940 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7942 message3_nolog (msg
, 0, 0);
7946 /* Handler for record_unwind_protect calling pop_message. */
7949 pop_message_unwind (dummy
)
7956 /* Pop the top-most entry off Vmessage_stack. */
7961 xassert (CONSP (Vmessage_stack
));
7962 Vmessage_stack
= XCDR (Vmessage_stack
);
7966 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7967 exits. If the stack is not empty, we have a missing pop_message
7971 check_message_stack ()
7973 if (!NILP (Vmessage_stack
))
7978 /* Truncate to NCHARS what will be displayed in the echo area the next
7979 time we display it---but don't redisplay it now. */
7982 truncate_echo_area (nchars
)
7986 echo_area_buffer
[0] = Qnil
;
7987 /* A null message buffer means that the frame hasn't really been
7988 initialized yet. Error messages get reported properly by
7989 cmd_error, so this must be just an informative message; toss it. */
7990 else if (!noninteractive
7992 && !NILP (echo_area_buffer
[0]))
7994 struct frame
*sf
= SELECTED_FRAME ();
7995 if (FRAME_MESSAGE_BUF (sf
))
7996 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8001 /* Helper function for truncate_echo_area. Truncate the current
8002 message to at most NCHARS characters. */
8005 truncate_message_1 (nchars
, a2
, a3
, a4
)
8010 if (BEG
+ nchars
< Z
)
8011 del_range (BEG
+ nchars
, Z
);
8013 echo_area_buffer
[0] = Qnil
;
8018 /* Set the current message to a substring of S or STRING.
8020 If STRING is a Lisp string, set the message to the first NBYTES
8021 bytes from STRING. NBYTES zero means use the whole string. If
8022 STRING is multibyte, the message will be displayed multibyte.
8024 If S is not null, set the message to the first LEN bytes of S. LEN
8025 zero means use the whole string. MULTIBYTE_P non-zero means S is
8026 multibyte. Display the message multibyte in that case.
8028 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8029 to t before calling set_message_1 (which calls insert).
8033 set_message (s
, string
, nbytes
, multibyte_p
)
8036 int nbytes
, multibyte_p
;
8038 message_enable_multibyte
8039 = ((s
&& multibyte_p
)
8040 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8042 with_echo_area_buffer (0, 0, set_message_1
,
8043 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8044 message_buf_print
= 0;
8045 help_echo_showing_p
= 0;
8049 /* Helper function for set_message. Arguments have the same meaning
8050 as there, with A1 corresponding to S and A2 corresponding to STRING
8051 This function is called with the echo area buffer being
8055 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8058 EMACS_INT nbytes
, multibyte_p
;
8060 const char *s
= (const char *) a1
;
8061 Lisp_Object string
= a2
;
8063 /* Change multibyteness of the echo buffer appropriately. */
8064 if (message_enable_multibyte
8065 != !NILP (current_buffer
->enable_multibyte_characters
))
8066 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8068 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8070 /* Insert new message at BEG. */
8071 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8074 if (STRINGP (string
))
8079 nbytes
= SBYTES (string
);
8080 nchars
= string_byte_to_char (string
, nbytes
);
8082 /* This function takes care of single/multibyte conversion. We
8083 just have to ensure that the echo area buffer has the right
8084 setting of enable_multibyte_characters. */
8085 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8090 nbytes
= strlen (s
);
8092 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8094 /* Convert from multi-byte to single-byte. */
8096 unsigned char work
[1];
8098 /* Convert a multibyte string to single-byte. */
8099 for (i
= 0; i
< nbytes
; i
+= n
)
8101 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8102 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8104 : multibyte_char_to_unibyte (c
, Qnil
));
8105 insert_1_both (work
, 1, 1, 1, 0, 0);
8108 else if (!multibyte_p
8109 && !NILP (current_buffer
->enable_multibyte_characters
))
8111 /* Convert from single-byte to multi-byte. */
8113 const unsigned char *msg
= (const unsigned char *) s
;
8114 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8116 /* Convert a single-byte string to multibyte. */
8117 for (i
= 0; i
< nbytes
; i
++)
8119 c
= unibyte_char_to_multibyte (msg
[i
]);
8120 n
= CHAR_STRING (c
, str
);
8121 insert_1_both (str
, 1, n
, 1, 0, 0);
8125 insert_1 (s
, nbytes
, 1, 0, 0);
8132 /* Clear messages. CURRENT_P non-zero means clear the current
8133 message. LAST_DISPLAYED_P non-zero means clear the message
8137 clear_message (current_p
, last_displayed_p
)
8138 int current_p
, last_displayed_p
;
8142 echo_area_buffer
[0] = Qnil
;
8143 message_cleared_p
= 1;
8146 if (last_displayed_p
)
8147 echo_area_buffer
[1] = Qnil
;
8149 message_buf_print
= 0;
8152 /* Clear garbaged frames.
8154 This function is used where the old redisplay called
8155 redraw_garbaged_frames which in turn called redraw_frame which in
8156 turn called clear_frame. The call to clear_frame was a source of
8157 flickering. I believe a clear_frame is not necessary. It should
8158 suffice in the new redisplay to invalidate all current matrices,
8159 and ensure a complete redisplay of all windows. */
8162 clear_garbaged_frames ()
8166 Lisp_Object tail
, frame
;
8167 int changed_count
= 0;
8169 FOR_EACH_FRAME (tail
, frame
)
8171 struct frame
*f
= XFRAME (frame
);
8173 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8177 Fredraw_frame (frame
);
8178 f
->force_flush_display_p
= 1;
8180 clear_current_matrices (f
);
8189 ++windows_or_buffers_changed
;
8194 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8195 is non-zero update selected_frame. Value is non-zero if the
8196 mini-windows height has been changed. */
8199 echo_area_display (update_frame_p
)
8202 Lisp_Object mini_window
;
8205 int window_height_changed_p
= 0;
8206 struct frame
*sf
= SELECTED_FRAME ();
8208 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8209 w
= XWINDOW (mini_window
);
8210 f
= XFRAME (WINDOW_FRAME (w
));
8212 /* Don't display if frame is invisible or not yet initialized. */
8213 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8216 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8218 #ifdef HAVE_WINDOW_SYSTEM
8219 /* When Emacs starts, selected_frame may be a visible terminal
8220 frame, even if we run under a window system. If we let this
8221 through, a message would be displayed on the terminal. */
8222 if (EQ (selected_frame
, Vterminal_frame
)
8223 && !NILP (Vwindow_system
))
8225 #endif /* HAVE_WINDOW_SYSTEM */
8228 /* Redraw garbaged frames. */
8230 clear_garbaged_frames ();
8232 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8234 echo_area_window
= mini_window
;
8235 window_height_changed_p
= display_echo_area (w
);
8236 w
->must_be_updated_p
= 1;
8238 /* Update the display, unless called from redisplay_internal.
8239 Also don't update the screen during redisplay itself. The
8240 update will happen at the end of redisplay, and an update
8241 here could cause confusion. */
8242 if (update_frame_p
&& !redisplaying_p
)
8246 /* If the display update has been interrupted by pending
8247 input, update mode lines in the frame. Due to the
8248 pending input, it might have been that redisplay hasn't
8249 been called, so that mode lines above the echo area are
8250 garbaged. This looks odd, so we prevent it here. */
8251 if (!display_completed
)
8252 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8254 if (window_height_changed_p
8255 /* Don't do this if Emacs is shutting down. Redisplay
8256 needs to run hooks. */
8257 && !NILP (Vrun_hooks
))
8259 /* Must update other windows. Likewise as in other
8260 cases, don't let this update be interrupted by
8262 int count
= SPECPDL_INDEX ();
8263 specbind (Qredisplay_dont_pause
, Qt
);
8264 windows_or_buffers_changed
= 1;
8265 redisplay_internal (0);
8266 unbind_to (count
, Qnil
);
8268 else if (FRAME_WINDOW_P (f
) && n
== 0)
8270 /* Window configuration is the same as before.
8271 Can do with a display update of the echo area,
8272 unless we displayed some mode lines. */
8273 update_single_window (w
, 1);
8274 rif
->flush_display (f
);
8277 update_frame (f
, 1, 1);
8279 /* If cursor is in the echo area, make sure that the next
8280 redisplay displays the minibuffer, so that the cursor will
8281 be replaced with what the minibuffer wants. */
8282 if (cursor_in_echo_area
)
8283 ++windows_or_buffers_changed
;
8286 else if (!EQ (mini_window
, selected_window
))
8287 windows_or_buffers_changed
++;
8289 /* The current message is now also the last one displayed. */
8290 echo_area_buffer
[1] = echo_area_buffer
[0];
8292 /* Prevent redisplay optimization in redisplay_internal by resetting
8293 this_line_start_pos. This is done because the mini-buffer now
8294 displays the message instead of its buffer text. */
8295 if (EQ (mini_window
, selected_window
))
8296 CHARPOS (this_line_start_pos
) = 0;
8298 return window_height_changed_p
;
8303 /***********************************************************************
8304 Mode Lines and Frame Titles
8305 ***********************************************************************/
8307 /* A buffer for constructing non-propertized mode-line strings and
8308 frame titles in it; allocated from the heap in init_xdisp and
8309 resized as needed in store_mode_line_noprop_char. */
8311 static char *mode_line_noprop_buf
;
8313 /* The buffer's end, and a current output position in it. */
8315 static char *mode_line_noprop_buf_end
;
8316 static char *mode_line_noprop_ptr
;
8318 #define MODE_LINE_NOPROP_LEN(start) \
8319 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8322 MODE_LINE_DISPLAY
= 0,
8328 /* Alist that caches the results of :propertize.
8329 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8330 static Lisp_Object mode_line_proptrans_alist
;
8332 /* List of strings making up the mode-line. */
8333 static Lisp_Object mode_line_string_list
;
8335 /* Base face property when building propertized mode line string. */
8336 static Lisp_Object mode_line_string_face
;
8337 static Lisp_Object mode_line_string_face_prop
;
8340 /* Unwind data for mode line strings */
8342 static Lisp_Object Vmode_line_unwind_vector
;
8345 format_mode_line_unwind_data (obuf
)
8346 struct buffer
*obuf
;
8350 /* Reduce consing by keeping one vector in
8351 Vwith_echo_area_save_vector. */
8352 vector
= Vmode_line_unwind_vector
;
8353 Vmode_line_unwind_vector
= Qnil
;
8356 vector
= Fmake_vector (make_number (7), Qnil
);
8358 AREF (vector
, 0) = make_number (mode_line_target
);
8359 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8360 AREF (vector
, 2) = mode_line_string_list
;
8361 AREF (vector
, 3) = mode_line_proptrans_alist
;
8362 AREF (vector
, 4) = mode_line_string_face
;
8363 AREF (vector
, 5) = mode_line_string_face_prop
;
8366 XSETBUFFER (AREF (vector
, 6), obuf
);
8368 AREF (vector
, 6) = Qnil
;
8374 unwind_format_mode_line (vector
)
8377 mode_line_target
= XINT (AREF (vector
, 0));
8378 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8379 mode_line_string_list
= AREF (vector
, 2);
8380 mode_line_proptrans_alist
= AREF (vector
, 3);
8381 mode_line_string_face
= AREF (vector
, 4);
8382 mode_line_string_face_prop
= AREF (vector
, 5);
8384 if (!NILP (AREF (vector
, 6)))
8386 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8387 AREF (vector
, 6) = Qnil
;
8390 Vmode_line_unwind_vector
= vector
;
8395 /* Store a single character C for the frame title in mode_line_noprop_buf.
8396 Re-allocate mode_line_noprop_buf if necessary. */
8400 store_mode_line_noprop_char (char c
)
8402 store_mode_line_noprop_char (c
)
8406 /* If output position has reached the end of the allocated buffer,
8407 double the buffer's size. */
8408 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8410 int len
= MODE_LINE_NOPROP_LEN (0);
8411 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8412 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8413 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8414 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8417 *mode_line_noprop_ptr
++ = c
;
8421 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8422 mode_line_noprop_ptr. STR is the string to store. Do not copy
8423 characters that yield more columns than PRECISION; PRECISION <= 0
8424 means copy the whole string. Pad with spaces until FIELD_WIDTH
8425 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8426 pad. Called from display_mode_element when it is used to build a
8430 store_mode_line_noprop (str
, field_width
, precision
)
8431 const unsigned char *str
;
8432 int field_width
, precision
;
8437 /* Copy at most PRECISION chars from STR. */
8438 nbytes
= strlen (str
);
8439 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8441 store_mode_line_noprop_char (*str
++);
8443 /* Fill up with spaces until FIELD_WIDTH reached. */
8444 while (field_width
> 0
8447 store_mode_line_noprop_char (' ');
8454 /***********************************************************************
8456 ***********************************************************************/
8458 #ifdef HAVE_WINDOW_SYSTEM
8460 /* Set the title of FRAME, if it has changed. The title format is
8461 Vicon_title_format if FRAME is iconified, otherwise it is
8462 frame_title_format. */
8465 x_consider_frame_title (frame
)
8468 struct frame
*f
= XFRAME (frame
);
8470 if (FRAME_WINDOW_P (f
)
8471 || FRAME_MINIBUF_ONLY_P (f
)
8472 || f
->explicit_name
)
8474 /* Do we have more than one visible frame on this X display? */
8481 int count
= SPECPDL_INDEX ();
8483 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8485 Lisp_Object other_frame
= XCAR (tail
);
8486 struct frame
*tf
= XFRAME (other_frame
);
8489 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8490 && !FRAME_MINIBUF_ONLY_P (tf
)
8491 && !EQ (other_frame
, tip_frame
)
8492 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8496 /* Set global variable indicating that multiple frames exist. */
8497 multiple_frames
= CONSP (tail
);
8499 /* Switch to the buffer of selected window of the frame. Set up
8500 mode_line_target so that display_mode_element will output into
8501 mode_line_noprop_buf; then display the title. */
8502 record_unwind_protect (unwind_format_mode_line
,
8503 format_mode_line_unwind_data (current_buffer
));
8505 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8506 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8508 mode_line_target
= MODE_LINE_TITLE
;
8509 title_start
= MODE_LINE_NOPROP_LEN (0);
8510 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8511 NULL
, DEFAULT_FACE_ID
);
8512 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8513 len
= MODE_LINE_NOPROP_LEN (title_start
);
8514 title
= mode_line_noprop_buf
+ title_start
;
8515 unbind_to (count
, Qnil
);
8517 /* Set the title only if it's changed. This avoids consing in
8518 the common case where it hasn't. (If it turns out that we've
8519 already wasted too much time by walking through the list with
8520 display_mode_element, then we might need to optimize at a
8521 higher level than this.) */
8522 if (! STRINGP (f
->name
)
8523 || SBYTES (f
->name
) != len
8524 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8525 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8529 #endif /* not HAVE_WINDOW_SYSTEM */
8534 /***********************************************************************
8536 ***********************************************************************/
8539 /* Prepare for redisplay by updating menu-bar item lists when
8540 appropriate. This can call eval. */
8543 prepare_menu_bars ()
8546 struct gcpro gcpro1
, gcpro2
;
8548 Lisp_Object tooltip_frame
;
8550 #ifdef HAVE_WINDOW_SYSTEM
8551 tooltip_frame
= tip_frame
;
8553 tooltip_frame
= Qnil
;
8556 /* Update all frame titles based on their buffer names, etc. We do
8557 this before the menu bars so that the buffer-menu will show the
8558 up-to-date frame titles. */
8559 #ifdef HAVE_WINDOW_SYSTEM
8560 if (windows_or_buffers_changed
|| update_mode_lines
)
8562 Lisp_Object tail
, frame
;
8564 FOR_EACH_FRAME (tail
, frame
)
8567 if (!EQ (frame
, tooltip_frame
)
8568 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8569 x_consider_frame_title (frame
);
8572 #endif /* HAVE_WINDOW_SYSTEM */
8574 /* Update the menu bar item lists, if appropriate. This has to be
8575 done before any actual redisplay or generation of display lines. */
8576 all_windows
= (update_mode_lines
8577 || buffer_shared
> 1
8578 || windows_or_buffers_changed
);
8581 Lisp_Object tail
, frame
;
8582 int count
= SPECPDL_INDEX ();
8584 record_unwind_save_match_data ();
8586 FOR_EACH_FRAME (tail
, frame
)
8590 /* Ignore tooltip frame. */
8591 if (EQ (frame
, tooltip_frame
))
8594 /* If a window on this frame changed size, report that to
8595 the user and clear the size-change flag. */
8596 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8598 Lisp_Object functions
;
8600 /* Clear flag first in case we get an error below. */
8601 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8602 functions
= Vwindow_size_change_functions
;
8603 GCPRO2 (tail
, functions
);
8605 while (CONSP (functions
))
8607 call1 (XCAR (functions
), frame
);
8608 functions
= XCDR (functions
);
8614 update_menu_bar (f
, 0);
8615 #ifdef HAVE_WINDOW_SYSTEM
8616 update_tool_bar (f
, 0);
8621 unbind_to (count
, Qnil
);
8625 struct frame
*sf
= SELECTED_FRAME ();
8626 update_menu_bar (sf
, 1);
8627 #ifdef HAVE_WINDOW_SYSTEM
8628 update_tool_bar (sf
, 1);
8632 /* Motif needs this. See comment in xmenu.c. Turn it off when
8633 pending_menu_activation is not defined. */
8634 #ifdef USE_X_TOOLKIT
8635 pending_menu_activation
= 0;
8640 /* Update the menu bar item list for frame F. This has to be done
8641 before we start to fill in any display lines, because it can call
8644 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8647 update_menu_bar (f
, save_match_data
)
8649 int save_match_data
;
8652 register struct window
*w
;
8654 /* If called recursively during a menu update, do nothing. This can
8655 happen when, for instance, an activate-menubar-hook causes a
8657 if (inhibit_menubar_update
)
8660 window
= FRAME_SELECTED_WINDOW (f
);
8661 w
= XWINDOW (window
);
8663 #if 0 /* The if statement below this if statement used to include the
8664 condition !NILP (w->update_mode_line), rather than using
8665 update_mode_lines directly, and this if statement may have
8666 been added to make that condition work. Now the if
8667 statement below matches its comment, this isn't needed. */
8668 if (update_mode_lines
)
8669 w
->update_mode_line
= Qt
;
8672 if (FRAME_WINDOW_P (f
)
8674 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8675 || defined (USE_GTK)
8676 FRAME_EXTERNAL_MENU_BAR (f
)
8678 FRAME_MENU_BAR_LINES (f
) > 0
8680 : FRAME_MENU_BAR_LINES (f
) > 0)
8682 /* If the user has switched buffers or windows, we need to
8683 recompute to reflect the new bindings. But we'll
8684 recompute when update_mode_lines is set too; that means
8685 that people can use force-mode-line-update to request
8686 that the menu bar be recomputed. The adverse effect on
8687 the rest of the redisplay algorithm is about the same as
8688 windows_or_buffers_changed anyway. */
8689 if (windows_or_buffers_changed
8690 /* This used to test w->update_mode_line, but we believe
8691 there is no need to recompute the menu in that case. */
8692 || update_mode_lines
8693 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8694 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8695 != !NILP (w
->last_had_star
))
8696 || ((!NILP (Vtransient_mark_mode
)
8697 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8698 != !NILP (w
->region_showing
)))
8700 struct buffer
*prev
= current_buffer
;
8701 int count
= SPECPDL_INDEX ();
8703 specbind (Qinhibit_menubar_update
, Qt
);
8705 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8706 if (save_match_data
)
8707 record_unwind_save_match_data ();
8708 if (NILP (Voverriding_local_map_menu_flag
))
8710 specbind (Qoverriding_terminal_local_map
, Qnil
);
8711 specbind (Qoverriding_local_map
, Qnil
);
8714 /* Run the Lucid hook. */
8715 safe_run_hooks (Qactivate_menubar_hook
);
8717 /* If it has changed current-menubar from previous value,
8718 really recompute the menu-bar from the value. */
8719 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8720 call0 (Qrecompute_lucid_menubar
);
8722 safe_run_hooks (Qmenu_bar_update_hook
);
8723 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8725 /* Redisplay the menu bar in case we changed it. */
8726 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8727 || defined (USE_GTK)
8728 if (FRAME_WINDOW_P (f
)
8729 #if defined (MAC_OS)
8730 /* All frames on Mac OS share the same menubar. So only the
8731 selected frame should be allowed to set it. */
8732 && f
== SELECTED_FRAME ()
8735 set_frame_menubar (f
, 0, 0);
8737 /* On a terminal screen, the menu bar is an ordinary screen
8738 line, and this makes it get updated. */
8739 w
->update_mode_line
= Qt
;
8740 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8741 /* In the non-toolkit version, the menu bar is an ordinary screen
8742 line, and this makes it get updated. */
8743 w
->update_mode_line
= Qt
;
8744 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8746 unbind_to (count
, Qnil
);
8747 set_buffer_internal_1 (prev
);
8754 /***********************************************************************
8756 ***********************************************************************/
8758 #ifdef HAVE_WINDOW_SYSTEM
8761 Nominal cursor position -- where to draw output.
8762 HPOS and VPOS are window relative glyph matrix coordinates.
8763 X and Y are window relative pixel coordinates. */
8765 struct cursor_pos output_cursor
;
8769 Set the global variable output_cursor to CURSOR. All cursor
8770 positions are relative to updated_window. */
8773 set_output_cursor (cursor
)
8774 struct cursor_pos
*cursor
;
8776 output_cursor
.hpos
= cursor
->hpos
;
8777 output_cursor
.vpos
= cursor
->vpos
;
8778 output_cursor
.x
= cursor
->x
;
8779 output_cursor
.y
= cursor
->y
;
8784 Set a nominal cursor position.
8786 HPOS and VPOS are column/row positions in a window glyph matrix. X
8787 and Y are window text area relative pixel positions.
8789 If this is done during an update, updated_window will contain the
8790 window that is being updated and the position is the future output
8791 cursor position for that window. If updated_window is null, use
8792 selected_window and display the cursor at the given position. */
8795 x_cursor_to (vpos
, hpos
, y
, x
)
8796 int vpos
, hpos
, y
, x
;
8800 /* If updated_window is not set, work on selected_window. */
8804 w
= XWINDOW (selected_window
);
8806 /* Set the output cursor. */
8807 output_cursor
.hpos
= hpos
;
8808 output_cursor
.vpos
= vpos
;
8809 output_cursor
.x
= x
;
8810 output_cursor
.y
= y
;
8812 /* If not called as part of an update, really display the cursor.
8813 This will also set the cursor position of W. */
8814 if (updated_window
== NULL
)
8817 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8818 if (rif
->flush_display_optional
)
8819 rif
->flush_display_optional (SELECTED_FRAME ());
8824 #endif /* HAVE_WINDOW_SYSTEM */
8827 /***********************************************************************
8829 ***********************************************************************/
8831 #ifdef HAVE_WINDOW_SYSTEM
8833 /* Where the mouse was last time we reported a mouse event. */
8835 FRAME_PTR last_mouse_frame
;
8837 /* Tool-bar item index of the item on which a mouse button was pressed
8840 int last_tool_bar_item
;
8843 /* Update the tool-bar item list for frame F. This has to be done
8844 before we start to fill in any display lines. Called from
8845 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8846 and restore it here. */
8849 update_tool_bar (f
, save_match_data
)
8851 int save_match_data
;
8854 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8856 int do_update
= WINDOWP (f
->tool_bar_window
)
8857 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8865 window
= FRAME_SELECTED_WINDOW (f
);
8866 w
= XWINDOW (window
);
8868 /* If the user has switched buffers or windows, we need to
8869 recompute to reflect the new bindings. But we'll
8870 recompute when update_mode_lines is set too; that means
8871 that people can use force-mode-line-update to request
8872 that the menu bar be recomputed. The adverse effect on
8873 the rest of the redisplay algorithm is about the same as
8874 windows_or_buffers_changed anyway. */
8875 if (windows_or_buffers_changed
8876 || !NILP (w
->update_mode_line
)
8877 || update_mode_lines
8878 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8879 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8880 != !NILP (w
->last_had_star
))
8881 || ((!NILP (Vtransient_mark_mode
)
8882 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8883 != !NILP (w
->region_showing
)))
8885 struct buffer
*prev
= current_buffer
;
8886 int count
= SPECPDL_INDEX ();
8887 Lisp_Object new_tool_bar
;
8889 struct gcpro gcpro1
;
8891 /* Set current_buffer to the buffer of the selected
8892 window of the frame, so that we get the right local
8894 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8896 /* Save match data, if we must. */
8897 if (save_match_data
)
8898 record_unwind_save_match_data ();
8900 /* Make sure that we don't accidentally use bogus keymaps. */
8901 if (NILP (Voverriding_local_map_menu_flag
))
8903 specbind (Qoverriding_terminal_local_map
, Qnil
);
8904 specbind (Qoverriding_local_map
, Qnil
);
8907 GCPRO1 (new_tool_bar
);
8909 /* Build desired tool-bar items from keymaps. */
8910 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8913 /* Redisplay the tool-bar if we changed it. */
8914 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8916 /* Redisplay that happens asynchronously due to an expose event
8917 may access f->tool_bar_items. Make sure we update both
8918 variables within BLOCK_INPUT so no such event interrupts. */
8920 f
->tool_bar_items
= new_tool_bar
;
8921 f
->n_tool_bar_items
= new_n_tool_bar
;
8922 w
->update_mode_line
= Qt
;
8928 unbind_to (count
, Qnil
);
8929 set_buffer_internal_1 (prev
);
8935 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8936 F's desired tool-bar contents. F->tool_bar_items must have
8937 been set up previously by calling prepare_menu_bars. */
8940 build_desired_tool_bar_string (f
)
8943 int i
, size
, size_needed
;
8944 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8945 Lisp_Object image
, plist
, props
;
8947 image
= plist
= props
= Qnil
;
8948 GCPRO3 (image
, plist
, props
);
8950 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8951 Otherwise, make a new string. */
8953 /* The size of the string we might be able to reuse. */
8954 size
= (STRINGP (f
->desired_tool_bar_string
)
8955 ? SCHARS (f
->desired_tool_bar_string
)
8958 /* We need one space in the string for each image. */
8959 size_needed
= f
->n_tool_bar_items
;
8961 /* Reuse f->desired_tool_bar_string, if possible. */
8962 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8963 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8967 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8968 Fremove_text_properties (make_number (0), make_number (size
),
8969 props
, f
->desired_tool_bar_string
);
8972 /* Put a `display' property on the string for the images to display,
8973 put a `menu_item' property on tool-bar items with a value that
8974 is the index of the item in F's tool-bar item vector. */
8975 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8977 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8979 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8980 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8981 int hmargin
, vmargin
, relief
, idx
, end
;
8982 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8984 /* If image is a vector, choose the image according to the
8986 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8987 if (VECTORP (image
))
8991 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8992 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8995 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8996 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8998 xassert (ASIZE (image
) >= idx
);
8999 image
= AREF (image
, idx
);
9004 /* Ignore invalid image specifications. */
9005 if (!valid_image_p (image
))
9008 /* Display the tool-bar button pressed, or depressed. */
9009 plist
= Fcopy_sequence (XCDR (image
));
9011 /* Compute margin and relief to draw. */
9012 relief
= (tool_bar_button_relief
>= 0
9013 ? tool_bar_button_relief
9014 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9015 hmargin
= vmargin
= relief
;
9017 if (INTEGERP (Vtool_bar_button_margin
)
9018 && XINT (Vtool_bar_button_margin
) > 0)
9020 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9021 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9023 else if (CONSP (Vtool_bar_button_margin
))
9025 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9026 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9027 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9029 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9030 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9031 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9034 if (auto_raise_tool_bar_buttons_p
)
9036 /* Add a `:relief' property to the image spec if the item is
9040 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9047 /* If image is selected, display it pressed, i.e. with a
9048 negative relief. If it's not selected, display it with a
9050 plist
= Fplist_put (plist
, QCrelief
,
9052 ? make_number (-relief
)
9053 : make_number (relief
)));
9058 /* Put a margin around the image. */
9059 if (hmargin
|| vmargin
)
9061 if (hmargin
== vmargin
)
9062 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9064 plist
= Fplist_put (plist
, QCmargin
,
9065 Fcons (make_number (hmargin
),
9066 make_number (vmargin
)));
9069 /* If button is not enabled, and we don't have special images
9070 for the disabled state, make the image appear disabled by
9071 applying an appropriate algorithm to it. */
9072 if (!enabled_p
&& idx
< 0)
9073 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9075 /* Put a `display' text property on the string for the image to
9076 display. Put a `menu-item' property on the string that gives
9077 the start of this item's properties in the tool-bar items
9079 image
= Fcons (Qimage
, plist
);
9080 props
= list4 (Qdisplay
, image
,
9081 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9083 /* Let the last image hide all remaining spaces in the tool bar
9084 string. The string can be longer than needed when we reuse a
9086 if (i
+ 1 == f
->n_tool_bar_items
)
9087 end
= SCHARS (f
->desired_tool_bar_string
);
9090 Fadd_text_properties (make_number (i
), make_number (end
),
9091 props
, f
->desired_tool_bar_string
);
9099 /* Display one line of the tool-bar of frame IT->f. */
9102 display_tool_bar_line (it
)
9105 struct glyph_row
*row
= it
->glyph_row
;
9106 int max_x
= it
->last_visible_x
;
9109 prepare_desired_row (row
);
9110 row
->y
= it
->current_y
;
9112 /* Note that this isn't made use of if the face hasn't a box,
9113 so there's no need to check the face here. */
9114 it
->start_of_box_run_p
= 1;
9116 while (it
->current_x
< max_x
)
9118 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9120 /* Get the next display element. */
9121 if (!get_next_display_element (it
))
9124 /* Produce glyphs. */
9125 x_before
= it
->current_x
;
9126 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9127 PRODUCE_GLYPHS (it
);
9129 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9134 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9136 if (x
+ glyph
->pixel_width
> max_x
)
9138 /* Glyph doesn't fit on line. */
9139 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9145 x
+= glyph
->pixel_width
;
9149 /* Stop at line ends. */
9150 if (ITERATOR_AT_END_OF_LINE_P (it
))
9153 set_iterator_to_next (it
, 1);
9158 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9159 extend_face_to_end_of_line (it
);
9160 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9161 last
->right_box_line_p
= 1;
9162 if (last
== row
->glyphs
[TEXT_AREA
])
9163 last
->left_box_line_p
= 1;
9164 compute_line_metrics (it
);
9166 /* If line is empty, make it occupy the rest of the tool-bar. */
9167 if (!row
->displays_text_p
)
9169 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9170 row
->ascent
= row
->phys_ascent
= 0;
9171 row
->extra_line_spacing
= 0;
9174 row
->full_width_p
= 1;
9175 row
->continued_p
= 0;
9176 row
->truncated_on_left_p
= 0;
9177 row
->truncated_on_right_p
= 0;
9179 it
->current_x
= it
->hpos
= 0;
9180 it
->current_y
+= row
->height
;
9186 /* Value is the number of screen lines needed to make all tool-bar
9187 items of frame F visible. */
9190 tool_bar_lines_needed (f
)
9193 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9196 /* Initialize an iterator for iteration over
9197 F->desired_tool_bar_string in the tool-bar window of frame F. */
9198 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9199 it
.first_visible_x
= 0;
9200 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9201 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9203 while (!ITERATOR_AT_END_P (&it
))
9205 it
.glyph_row
= w
->desired_matrix
->rows
;
9206 clear_glyph_row (it
.glyph_row
);
9207 display_tool_bar_line (&it
);
9210 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9214 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9216 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9225 frame
= selected_frame
;
9227 CHECK_FRAME (frame
);
9230 if (WINDOWP (f
->tool_bar_window
)
9231 || (w
= XWINDOW (f
->tool_bar_window
),
9232 WINDOW_TOTAL_LINES (w
) > 0))
9234 update_tool_bar (f
, 1);
9235 if (f
->n_tool_bar_items
)
9237 build_desired_tool_bar_string (f
);
9238 nlines
= tool_bar_lines_needed (f
);
9242 return make_number (nlines
);
9246 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9247 height should be changed. */
9250 redisplay_tool_bar (f
)
9255 struct glyph_row
*row
;
9256 int change_height_p
= 0;
9259 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9260 update_frame_tool_bar (f
);
9264 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9265 do anything. This means you must start with tool-bar-lines
9266 non-zero to get the auto-sizing effect. Or in other words, you
9267 can turn off tool-bars by specifying tool-bar-lines zero. */
9268 if (!WINDOWP (f
->tool_bar_window
)
9269 || (w
= XWINDOW (f
->tool_bar_window
),
9270 WINDOW_TOTAL_LINES (w
) == 0))
9273 /* Set up an iterator for the tool-bar window. */
9274 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9275 it
.first_visible_x
= 0;
9276 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9279 /* Build a string that represents the contents of the tool-bar. */
9280 build_desired_tool_bar_string (f
);
9281 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9283 /* Display as many lines as needed to display all tool-bar items. */
9284 while (it
.current_y
< it
.last_visible_y
)
9285 display_tool_bar_line (&it
);
9287 /* It doesn't make much sense to try scrolling in the tool-bar
9288 window, so don't do it. */
9289 w
->desired_matrix
->no_scrolling_p
= 1;
9290 w
->must_be_updated_p
= 1;
9292 if (auto_resize_tool_bars_p
)
9296 /* If we couldn't display everything, change the tool-bar's
9298 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9299 change_height_p
= 1;
9301 /* If there are blank lines at the end, except for a partially
9302 visible blank line at the end that is smaller than
9303 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9304 row
= it
.glyph_row
- 1;
9305 if (!row
->displays_text_p
9306 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9307 change_height_p
= 1;
9309 /* If row displays tool-bar items, but is partially visible,
9310 change the tool-bar's height. */
9311 if (row
->displays_text_p
9312 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9313 change_height_p
= 1;
9315 /* Resize windows as needed by changing the `tool-bar-lines'
9318 && (nlines
= tool_bar_lines_needed (f
),
9319 nlines
!= WINDOW_TOTAL_LINES (w
)))
9321 extern Lisp_Object Qtool_bar_lines
;
9323 int old_height
= WINDOW_TOTAL_LINES (w
);
9325 XSETFRAME (frame
, f
);
9326 clear_glyph_matrix (w
->desired_matrix
);
9327 Fmodify_frame_parameters (frame
,
9328 Fcons (Fcons (Qtool_bar_lines
,
9329 make_number (nlines
)),
9331 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9332 fonts_changed_p
= 1;
9336 return change_height_p
;
9340 /* Get information about the tool-bar item which is displayed in GLYPH
9341 on frame F. Return in *PROP_IDX the index where tool-bar item
9342 properties start in F->tool_bar_items. Value is zero if
9343 GLYPH doesn't display a tool-bar item. */
9346 tool_bar_item_info (f
, glyph
, prop_idx
)
9348 struct glyph
*glyph
;
9355 /* This function can be called asynchronously, which means we must
9356 exclude any possibility that Fget_text_property signals an
9358 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9359 charpos
= max (0, charpos
);
9361 /* Get the text property `menu-item' at pos. The value of that
9362 property is the start index of this item's properties in
9363 F->tool_bar_items. */
9364 prop
= Fget_text_property (make_number (charpos
),
9365 Qmenu_item
, f
->current_tool_bar_string
);
9366 if (INTEGERP (prop
))
9368 *prop_idx
= XINT (prop
);
9378 /* Get information about the tool-bar item at position X/Y on frame F.
9379 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9380 the current matrix of the tool-bar window of F, or NULL if not
9381 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9382 item in F->tool_bar_items. Value is
9384 -1 if X/Y is not on a tool-bar item
9385 0 if X/Y is on the same item that was highlighted before.
9389 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9392 struct glyph
**glyph
;
9393 int *hpos
, *vpos
, *prop_idx
;
9395 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9396 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9399 /* Find the glyph under X/Y. */
9400 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9404 /* Get the start of this tool-bar item's properties in
9405 f->tool_bar_items. */
9406 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9409 /* Is mouse on the highlighted item? */
9410 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9411 && *vpos
>= dpyinfo
->mouse_face_beg_row
9412 && *vpos
<= dpyinfo
->mouse_face_end_row
9413 && (*vpos
> dpyinfo
->mouse_face_beg_row
9414 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9415 && (*vpos
< dpyinfo
->mouse_face_end_row
9416 || *hpos
< dpyinfo
->mouse_face_end_col
9417 || dpyinfo
->mouse_face_past_end
))
9425 Handle mouse button event on the tool-bar of frame F, at
9426 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9427 0 for button release. MODIFIERS is event modifiers for button
9431 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9434 unsigned int modifiers
;
9436 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9437 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9438 int hpos
, vpos
, prop_idx
;
9439 struct glyph
*glyph
;
9440 Lisp_Object enabled_p
;
9442 /* If not on the highlighted tool-bar item, return. */
9443 frame_to_window_pixel_xy (w
, &x
, &y
);
9444 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9447 /* If item is disabled, do nothing. */
9448 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9449 if (NILP (enabled_p
))
9454 /* Show item in pressed state. */
9455 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9456 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9457 last_tool_bar_item
= prop_idx
;
9461 Lisp_Object key
, frame
;
9462 struct input_event event
;
9465 /* Show item in released state. */
9466 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9467 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9469 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9471 XSETFRAME (frame
, f
);
9472 event
.kind
= TOOL_BAR_EVENT
;
9473 event
.frame_or_window
= frame
;
9475 kbd_buffer_store_event (&event
);
9477 event
.kind
= TOOL_BAR_EVENT
;
9478 event
.frame_or_window
= frame
;
9480 event
.modifiers
= modifiers
;
9481 kbd_buffer_store_event (&event
);
9482 last_tool_bar_item
= -1;
9487 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9488 tool-bar window-relative coordinates X/Y. Called from
9489 note_mouse_highlight. */
9492 note_tool_bar_highlight (f
, x
, y
)
9496 Lisp_Object window
= f
->tool_bar_window
;
9497 struct window
*w
= XWINDOW (window
);
9498 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9500 struct glyph
*glyph
;
9501 struct glyph_row
*row
;
9503 Lisp_Object enabled_p
;
9505 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9506 int mouse_down_p
, rc
;
9508 /* Function note_mouse_highlight is called with negative x(y
9509 values when mouse moves outside of the frame. */
9510 if (x
<= 0 || y
<= 0)
9512 clear_mouse_face (dpyinfo
);
9516 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9519 /* Not on tool-bar item. */
9520 clear_mouse_face (dpyinfo
);
9524 /* On same tool-bar item as before. */
9527 clear_mouse_face (dpyinfo
);
9529 /* Mouse is down, but on different tool-bar item? */
9530 mouse_down_p
= (dpyinfo
->grabbed
9531 && f
== last_mouse_frame
9532 && FRAME_LIVE_P (f
));
9534 && last_tool_bar_item
!= prop_idx
)
9537 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9538 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9540 /* If tool-bar item is not enabled, don't highlight it. */
9541 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9542 if (!NILP (enabled_p
))
9544 /* Compute the x-position of the glyph. In front and past the
9545 image is a space. We include this in the highlighted area. */
9546 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9547 for (i
= x
= 0; i
< hpos
; ++i
)
9548 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9550 /* Record this as the current active region. */
9551 dpyinfo
->mouse_face_beg_col
= hpos
;
9552 dpyinfo
->mouse_face_beg_row
= vpos
;
9553 dpyinfo
->mouse_face_beg_x
= x
;
9554 dpyinfo
->mouse_face_beg_y
= row
->y
;
9555 dpyinfo
->mouse_face_past_end
= 0;
9557 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9558 dpyinfo
->mouse_face_end_row
= vpos
;
9559 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9560 dpyinfo
->mouse_face_end_y
= row
->y
;
9561 dpyinfo
->mouse_face_window
= window
;
9562 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9564 /* Display it as active. */
9565 show_mouse_face (dpyinfo
, draw
);
9566 dpyinfo
->mouse_face_image_state
= draw
;
9571 /* Set help_echo_string to a help string to display for this tool-bar item.
9572 XTread_socket does the rest. */
9573 help_echo_object
= help_echo_window
= Qnil
;
9575 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9576 if (NILP (help_echo_string
))
9577 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9580 #endif /* HAVE_WINDOW_SYSTEM */
9584 /************************************************************************
9585 Horizontal scrolling
9586 ************************************************************************/
9588 static int hscroll_window_tree
P_ ((Lisp_Object
));
9589 static int hscroll_windows
P_ ((Lisp_Object
));
9591 /* For all leaf windows in the window tree rooted at WINDOW, set their
9592 hscroll value so that PT is (i) visible in the window, and (ii) so
9593 that it is not within a certain margin at the window's left and
9594 right border. Value is non-zero if any window's hscroll has been
9598 hscroll_window_tree (window
)
9601 int hscrolled_p
= 0;
9602 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9603 int hscroll_step_abs
= 0;
9604 double hscroll_step_rel
= 0;
9606 if (hscroll_relative_p
)
9608 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9609 if (hscroll_step_rel
< 0)
9611 hscroll_relative_p
= 0;
9612 hscroll_step_abs
= 0;
9615 else if (INTEGERP (Vhscroll_step
))
9617 hscroll_step_abs
= XINT (Vhscroll_step
);
9618 if (hscroll_step_abs
< 0)
9619 hscroll_step_abs
= 0;
9622 hscroll_step_abs
= 0;
9624 while (WINDOWP (window
))
9626 struct window
*w
= XWINDOW (window
);
9628 if (WINDOWP (w
->hchild
))
9629 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9630 else if (WINDOWP (w
->vchild
))
9631 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9632 else if (w
->cursor
.vpos
>= 0)
9635 int text_area_width
;
9636 struct glyph_row
*current_cursor_row
9637 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9638 struct glyph_row
*desired_cursor_row
9639 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9640 struct glyph_row
*cursor_row
9641 = (desired_cursor_row
->enabled_p
9642 ? desired_cursor_row
9643 : current_cursor_row
);
9645 text_area_width
= window_box_width (w
, TEXT_AREA
);
9647 /* Scroll when cursor is inside this scroll margin. */
9648 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9650 if ((XFASTINT (w
->hscroll
)
9651 && w
->cursor
.x
<= h_margin
)
9652 || (cursor_row
->enabled_p
9653 && cursor_row
->truncated_on_right_p
9654 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9658 struct buffer
*saved_current_buffer
;
9662 /* Find point in a display of infinite width. */
9663 saved_current_buffer
= current_buffer
;
9664 current_buffer
= XBUFFER (w
->buffer
);
9666 if (w
== XWINDOW (selected_window
))
9667 pt
= BUF_PT (current_buffer
);
9670 pt
= marker_position (w
->pointm
);
9671 pt
= max (BEGV
, pt
);
9675 /* Move iterator to pt starting at cursor_row->start in
9676 a line with infinite width. */
9677 init_to_row_start (&it
, w
, cursor_row
);
9678 it
.last_visible_x
= INFINITY
;
9679 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9680 current_buffer
= saved_current_buffer
;
9682 /* Position cursor in window. */
9683 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9684 hscroll
= max (0, (it
.current_x
9685 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9686 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9687 : (text_area_width
/ 2))))
9688 / FRAME_COLUMN_WIDTH (it
.f
);
9689 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9691 if (hscroll_relative_p
)
9692 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9695 wanted_x
= text_area_width
9696 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9699 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9703 if (hscroll_relative_p
)
9704 wanted_x
= text_area_width
* hscroll_step_rel
9707 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9710 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9712 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9714 /* Don't call Fset_window_hscroll if value hasn't
9715 changed because it will prevent redisplay
9717 if (XFASTINT (w
->hscroll
) != hscroll
)
9719 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9720 w
->hscroll
= make_number (hscroll
);
9729 /* Value is non-zero if hscroll of any leaf window has been changed. */
9734 /* Set hscroll so that cursor is visible and not inside horizontal
9735 scroll margins for all windows in the tree rooted at WINDOW. See
9736 also hscroll_window_tree above. Value is non-zero if any window's
9737 hscroll has been changed. If it has, desired matrices on the frame
9738 of WINDOW are cleared. */
9741 hscroll_windows (window
)
9746 if (automatic_hscrolling_p
)
9748 hscrolled_p
= hscroll_window_tree (window
);
9750 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9759 /************************************************************************
9761 ************************************************************************/
9763 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9764 to a non-zero value. This is sometimes handy to have in a debugger
9769 /* First and last unchanged row for try_window_id. */
9771 int debug_first_unchanged_at_end_vpos
;
9772 int debug_last_unchanged_at_beg_vpos
;
9774 /* Delta vpos and y. */
9776 int debug_dvpos
, debug_dy
;
9778 /* Delta in characters and bytes for try_window_id. */
9780 int debug_delta
, debug_delta_bytes
;
9782 /* Values of window_end_pos and window_end_vpos at the end of
9785 EMACS_INT debug_end_pos
, debug_end_vpos
;
9787 /* Append a string to W->desired_matrix->method. FMT is a printf
9788 format string. A1...A9 are a supplement for a variable-length
9789 argument list. If trace_redisplay_p is non-zero also printf the
9790 resulting string to stderr. */
9793 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9796 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9799 char *method
= w
->desired_matrix
->method
;
9800 int len
= strlen (method
);
9801 int size
= sizeof w
->desired_matrix
->method
;
9802 int remaining
= size
- len
- 1;
9804 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9805 if (len
&& remaining
)
9811 strncpy (method
+ len
, buffer
, remaining
);
9813 if (trace_redisplay_p
)
9814 fprintf (stderr
, "%p (%s): %s\n",
9816 ((BUFFERP (w
->buffer
)
9817 && STRINGP (XBUFFER (w
->buffer
)->name
))
9818 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9823 #endif /* GLYPH_DEBUG */
9826 /* Value is non-zero if all changes in window W, which displays
9827 current_buffer, are in the text between START and END. START is a
9828 buffer position, END is given as a distance from Z. Used in
9829 redisplay_internal for display optimization. */
9832 text_outside_line_unchanged_p (w
, start
, end
)
9836 int unchanged_p
= 1;
9838 /* If text or overlays have changed, see where. */
9839 if (XFASTINT (w
->last_modified
) < MODIFF
9840 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9842 /* Gap in the line? */
9843 if (GPT
< start
|| Z
- GPT
< end
)
9846 /* Changes start in front of the line, or end after it? */
9848 && (BEG_UNCHANGED
< start
- 1
9849 || END_UNCHANGED
< end
))
9852 /* If selective display, can't optimize if changes start at the
9853 beginning of the line. */
9855 && INTEGERP (current_buffer
->selective_display
)
9856 && XINT (current_buffer
->selective_display
) > 0
9857 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9860 /* If there are overlays at the start or end of the line, these
9861 may have overlay strings with newlines in them. A change at
9862 START, for instance, may actually concern the display of such
9863 overlay strings as well, and they are displayed on different
9864 lines. So, quickly rule out this case. (For the future, it
9865 might be desirable to implement something more telling than
9866 just BEG/END_UNCHANGED.) */
9869 if (BEG
+ BEG_UNCHANGED
== start
9870 && overlay_touches_p (start
))
9872 if (END_UNCHANGED
== end
9873 && overlay_touches_p (Z
- end
))
9882 /* Do a frame update, taking possible shortcuts into account. This is
9883 the main external entry point for redisplay.
9885 If the last redisplay displayed an echo area message and that message
9886 is no longer requested, we clear the echo area or bring back the
9887 mini-buffer if that is in use. */
9892 redisplay_internal (0);
9897 overlay_arrow_string_or_property (var
)
9902 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
9905 return Voverlay_arrow_string
;
9908 /* Return 1 if there are any overlay-arrows in current_buffer. */
9910 overlay_arrow_in_current_buffer_p ()
9914 for (vlist
= Voverlay_arrow_variable_list
;
9916 vlist
= XCDR (vlist
))
9918 Lisp_Object var
= XCAR (vlist
);
9923 val
= find_symbol_value (var
);
9925 && current_buffer
== XMARKER (val
)->buffer
)
9932 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9936 overlay_arrows_changed_p ()
9940 for (vlist
= Voverlay_arrow_variable_list
;
9942 vlist
= XCDR (vlist
))
9944 Lisp_Object var
= XCAR (vlist
);
9945 Lisp_Object val
, pstr
;
9949 val
= find_symbol_value (var
);
9952 if (! EQ (COERCE_MARKER (val
),
9953 Fget (var
, Qlast_arrow_position
))
9954 || ! (pstr
= overlay_arrow_string_or_property (var
),
9955 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9961 /* Mark overlay arrows to be updated on next redisplay. */
9964 update_overlay_arrows (up_to_date
)
9969 for (vlist
= Voverlay_arrow_variable_list
;
9971 vlist
= XCDR (vlist
))
9973 Lisp_Object var
= XCAR (vlist
);
9980 Lisp_Object val
= find_symbol_value (var
);
9981 Fput (var
, Qlast_arrow_position
,
9982 COERCE_MARKER (val
));
9983 Fput (var
, Qlast_arrow_string
,
9984 overlay_arrow_string_or_property (var
));
9986 else if (up_to_date
< 0
9987 || !NILP (Fget (var
, Qlast_arrow_position
)))
9989 Fput (var
, Qlast_arrow_position
, Qt
);
9990 Fput (var
, Qlast_arrow_string
, Qt
);
9996 /* Return overlay arrow string to display at row.
9997 Return integer (bitmap number) for arrow bitmap in left fringe.
9998 Return nil if no overlay arrow. */
10001 overlay_arrow_at_row (it
, row
)
10003 struct glyph_row
*row
;
10007 for (vlist
= Voverlay_arrow_variable_list
;
10009 vlist
= XCDR (vlist
))
10011 Lisp_Object var
= XCAR (vlist
);
10014 if (!SYMBOLP (var
))
10017 val
= find_symbol_value (var
);
10020 && current_buffer
== XMARKER (val
)->buffer
10021 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10023 if (FRAME_WINDOW_P (it
->f
)
10024 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10026 #ifdef HAVE_WINDOW_SYSTEM
10027 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10030 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10031 return make_number (fringe_bitmap
);
10034 return make_number (-1); /* Use default arrow bitmap */
10036 return overlay_arrow_string_or_property (var
);
10043 /* Return 1 if point moved out of or into a composition. Otherwise
10044 return 0. PREV_BUF and PREV_PT are the last point buffer and
10045 position. BUF and PT are the current point buffer and position. */
10048 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10049 struct buffer
*prev_buf
, *buf
;
10054 Lisp_Object buffer
;
10056 XSETBUFFER (buffer
, buf
);
10057 /* Check a composition at the last point if point moved within the
10059 if (prev_buf
== buf
)
10062 /* Point didn't move. */
10065 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10066 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10067 && COMPOSITION_VALID_P (start
, end
, prop
)
10068 && start
< prev_pt
&& end
> prev_pt
)
10069 /* The last point was within the composition. Return 1 iff
10070 point moved out of the composition. */
10071 return (pt
<= start
|| pt
>= end
);
10074 /* Check a composition at the current point. */
10075 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10076 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10077 && COMPOSITION_VALID_P (start
, end
, prop
)
10078 && start
< pt
&& end
> pt
);
10082 /* Reconsider the setting of B->clip_changed which is displayed
10086 reconsider_clip_changes (w
, b
)
10090 if (b
->clip_changed
10091 && !NILP (w
->window_end_valid
)
10092 && w
->current_matrix
->buffer
== b
10093 && w
->current_matrix
->zv
== BUF_ZV (b
)
10094 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10095 b
->clip_changed
= 0;
10097 /* If display wasn't paused, and W is not a tool bar window, see if
10098 point has been moved into or out of a composition. In that case,
10099 we set b->clip_changed to 1 to force updating the screen. If
10100 b->clip_changed has already been set to 1, we can skip this
10102 if (!b
->clip_changed
10103 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10107 if (w
== XWINDOW (selected_window
))
10108 pt
= BUF_PT (current_buffer
);
10110 pt
= marker_position (w
->pointm
);
10112 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10113 || pt
!= XINT (w
->last_point
))
10114 && check_point_in_composition (w
->current_matrix
->buffer
,
10115 XINT (w
->last_point
),
10116 XBUFFER (w
->buffer
), pt
))
10117 b
->clip_changed
= 1;
10122 /* Select FRAME to forward the values of frame-local variables into C
10123 variables so that the redisplay routines can access those values
10127 select_frame_for_redisplay (frame
)
10130 Lisp_Object tail
, sym
, val
;
10131 Lisp_Object old
= selected_frame
;
10133 selected_frame
= frame
;
10135 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10136 if (CONSP (XCAR (tail
))
10137 && (sym
= XCAR (XCAR (tail
)),
10139 && (sym
= indirect_variable (sym
),
10140 val
= SYMBOL_VALUE (sym
),
10141 (BUFFER_LOCAL_VALUEP (val
)
10142 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10143 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10144 /* Use find_symbol_value rather than Fsymbol_value
10145 to avoid an error if it is void. */
10146 find_symbol_value (sym
);
10148 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10149 if (CONSP (XCAR (tail
))
10150 && (sym
= XCAR (XCAR (tail
)),
10152 && (sym
= indirect_variable (sym
),
10153 val
= SYMBOL_VALUE (sym
),
10154 (BUFFER_LOCAL_VALUEP (val
)
10155 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10156 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10157 find_symbol_value (sym
);
10161 #define STOP_POLLING \
10162 do { if (! polling_stopped_here) stop_polling (); \
10163 polling_stopped_here = 1; } while (0)
10165 #define RESUME_POLLING \
10166 do { if (polling_stopped_here) start_polling (); \
10167 polling_stopped_here = 0; } while (0)
10170 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10171 response to any user action; therefore, we should preserve the echo
10172 area. (Actually, our caller does that job.) Perhaps in the future
10173 avoid recentering windows if it is not necessary; currently that
10174 causes some problems. */
10177 redisplay_internal (preserve_echo_area
)
10178 int preserve_echo_area
;
10180 struct window
*w
= XWINDOW (selected_window
);
10181 struct frame
*f
= XFRAME (w
->frame
);
10183 int must_finish
= 0;
10184 struct text_pos tlbufpos
, tlendpos
;
10185 int number_of_visible_frames
;
10187 struct frame
*sf
= SELECTED_FRAME ();
10188 int polling_stopped_here
= 0;
10190 /* Non-zero means redisplay has to consider all windows on all
10191 frames. Zero means, only selected_window is considered. */
10192 int consider_all_windows_p
;
10194 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10196 /* No redisplay if running in batch mode or frame is not yet fully
10197 initialized, or redisplay is explicitly turned off by setting
10198 Vinhibit_redisplay. */
10200 || !NILP (Vinhibit_redisplay
)
10201 || !f
->glyphs_initialized_p
)
10204 /* The flag redisplay_performed_directly_p is set by
10205 direct_output_for_insert when it already did the whole screen
10206 update necessary. */
10207 if (redisplay_performed_directly_p
)
10209 redisplay_performed_directly_p
= 0;
10210 if (!hscroll_windows (selected_window
))
10214 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10215 if (popup_activated ())
10219 /* I don't think this happens but let's be paranoid. */
10220 if (redisplaying_p
)
10223 /* Record a function that resets redisplaying_p to its old value
10224 when we leave this function. */
10225 count
= SPECPDL_INDEX ();
10226 record_unwind_protect (unwind_redisplay
,
10227 Fcons (make_number (redisplaying_p
), selected_frame
));
10229 specbind (Qinhibit_free_realized_faces
, Qnil
);
10232 Lisp_Object tail
, frame
;
10234 FOR_EACH_FRAME (tail
, frame
)
10236 struct frame
*f
= XFRAME (frame
);
10237 f
->already_hscrolled_p
= 0;
10243 reconsider_clip_changes (w
, current_buffer
);
10245 /* If new fonts have been loaded that make a glyph matrix adjustment
10246 necessary, do it. */
10247 if (fonts_changed_p
)
10249 adjust_glyphs (NULL
);
10250 ++windows_or_buffers_changed
;
10251 fonts_changed_p
= 0;
10254 /* If face_change_count is non-zero, init_iterator will free all
10255 realized faces, which includes the faces referenced from current
10256 matrices. So, we can't reuse current matrices in this case. */
10257 if (face_change_count
)
10258 ++windows_or_buffers_changed
;
10260 if (! FRAME_WINDOW_P (sf
)
10261 && previous_terminal_frame
!= sf
)
10263 /* Since frames on an ASCII terminal share the same display
10264 area, displaying a different frame means redisplay the whole
10266 windows_or_buffers_changed
++;
10267 SET_FRAME_GARBAGED (sf
);
10268 XSETFRAME (Vterminal_frame
, sf
);
10270 previous_terminal_frame
= sf
;
10272 /* Set the visible flags for all frames. Do this before checking
10273 for resized or garbaged frames; they want to know if their frames
10274 are visible. See the comment in frame.h for
10275 FRAME_SAMPLE_VISIBILITY. */
10277 Lisp_Object tail
, frame
;
10279 number_of_visible_frames
= 0;
10281 FOR_EACH_FRAME (tail
, frame
)
10283 struct frame
*f
= XFRAME (frame
);
10285 FRAME_SAMPLE_VISIBILITY (f
);
10286 if (FRAME_VISIBLE_P (f
))
10287 ++number_of_visible_frames
;
10288 clear_desired_matrices (f
);
10292 /* Notice any pending interrupt request to change frame size. */
10293 do_pending_window_change (1);
10295 /* Clear frames marked as garbaged. */
10296 if (frame_garbaged
)
10297 clear_garbaged_frames ();
10299 /* Build menubar and tool-bar items. */
10300 prepare_menu_bars ();
10302 if (windows_or_buffers_changed
)
10303 update_mode_lines
++;
10305 /* Detect case that we need to write or remove a star in the mode line. */
10306 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10308 w
->update_mode_line
= Qt
;
10309 if (buffer_shared
> 1)
10310 update_mode_lines
++;
10313 /* If %c is in the mode line, update it if needed. */
10314 if (!NILP (w
->column_number_displayed
)
10315 /* This alternative quickly identifies a common case
10316 where no change is needed. */
10317 && !(PT
== XFASTINT (w
->last_point
)
10318 && XFASTINT (w
->last_modified
) >= MODIFF
10319 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10320 && (XFASTINT (w
->column_number_displayed
)
10321 != (int) current_column ())) /* iftc */
10322 w
->update_mode_line
= Qt
;
10324 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10326 /* The variable buffer_shared is set in redisplay_window and
10327 indicates that we redisplay a buffer in different windows. See
10329 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10330 || cursor_type_changed
);
10332 /* If specs for an arrow have changed, do thorough redisplay
10333 to ensure we remove any arrow that should no longer exist. */
10334 if (overlay_arrows_changed_p ())
10335 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10337 /* Normally the message* functions will have already displayed and
10338 updated the echo area, but the frame may have been trashed, or
10339 the update may have been preempted, so display the echo area
10340 again here. Checking message_cleared_p captures the case that
10341 the echo area should be cleared. */
10342 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10343 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10344 || (message_cleared_p
10345 && minibuf_level
== 0
10346 /* If the mini-window is currently selected, this means the
10347 echo-area doesn't show through. */
10348 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10350 int window_height_changed_p
= echo_area_display (0);
10353 /* If we don't display the current message, don't clear the
10354 message_cleared_p flag, because, if we did, we wouldn't clear
10355 the echo area in the next redisplay which doesn't preserve
10357 if (!display_last_displayed_message_p
)
10358 message_cleared_p
= 0;
10360 if (fonts_changed_p
)
10362 else if (window_height_changed_p
)
10364 consider_all_windows_p
= 1;
10365 ++update_mode_lines
;
10366 ++windows_or_buffers_changed
;
10368 /* If window configuration was changed, frames may have been
10369 marked garbaged. Clear them or we will experience
10370 surprises wrt scrolling. */
10371 if (frame_garbaged
)
10372 clear_garbaged_frames ();
10375 else if (EQ (selected_window
, minibuf_window
)
10376 && (current_buffer
->clip_changed
10377 || XFASTINT (w
->last_modified
) < MODIFF
10378 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10379 && resize_mini_window (w
, 0))
10381 /* Resized active mini-window to fit the size of what it is
10382 showing if its contents might have changed. */
10384 consider_all_windows_p
= 1;
10385 ++windows_or_buffers_changed
;
10386 ++update_mode_lines
;
10388 /* If window configuration was changed, frames may have been
10389 marked garbaged. Clear them or we will experience
10390 surprises wrt scrolling. */
10391 if (frame_garbaged
)
10392 clear_garbaged_frames ();
10396 /* If showing the region, and mark has changed, we must redisplay
10397 the whole window. The assignment to this_line_start_pos prevents
10398 the optimization directly below this if-statement. */
10399 if (((!NILP (Vtransient_mark_mode
)
10400 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10401 != !NILP (w
->region_showing
))
10402 || (!NILP (w
->region_showing
)
10403 && !EQ (w
->region_showing
,
10404 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10405 CHARPOS (this_line_start_pos
) = 0;
10407 /* Optimize the case that only the line containing the cursor in the
10408 selected window has changed. Variables starting with this_ are
10409 set in display_line and record information about the line
10410 containing the cursor. */
10411 tlbufpos
= this_line_start_pos
;
10412 tlendpos
= this_line_end_pos
;
10413 if (!consider_all_windows_p
10414 && CHARPOS (tlbufpos
) > 0
10415 && NILP (w
->update_mode_line
)
10416 && !current_buffer
->clip_changed
10417 && !current_buffer
->prevent_redisplay_optimizations_p
10418 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10419 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10420 /* Make sure recorded data applies to current buffer, etc. */
10421 && this_line_buffer
== current_buffer
10422 && current_buffer
== XBUFFER (w
->buffer
)
10423 && NILP (w
->force_start
)
10424 && NILP (w
->optional_new_start
)
10425 /* Point must be on the line that we have info recorded about. */
10426 && PT
>= CHARPOS (tlbufpos
)
10427 && PT
<= Z
- CHARPOS (tlendpos
)
10428 /* All text outside that line, including its final newline,
10429 must be unchanged */
10430 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10431 CHARPOS (tlendpos
)))
10433 if (CHARPOS (tlbufpos
) > BEGV
10434 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10435 && (CHARPOS (tlbufpos
) == ZV
10436 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10437 /* Former continuation line has disappeared by becoming empty */
10439 else if (XFASTINT (w
->last_modified
) < MODIFF
10440 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10441 || MINI_WINDOW_P (w
))
10443 /* We have to handle the case of continuation around a
10444 wide-column character (See the comment in indent.c around
10447 For instance, in the following case:
10449 -------- Insert --------
10450 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10451 J_I_ ==> J_I_ `^^' are cursors.
10455 As we have to redraw the line above, we should goto cancel. */
10458 int line_height_before
= this_line_pixel_height
;
10460 /* Note that start_display will handle the case that the
10461 line starting at tlbufpos is a continuation lines. */
10462 start_display (&it
, w
, tlbufpos
);
10464 /* Implementation note: It this still necessary? */
10465 if (it
.current_x
!= this_line_start_x
)
10468 TRACE ((stderr
, "trying display optimization 1\n"));
10469 w
->cursor
.vpos
= -1;
10470 overlay_arrow_seen
= 0;
10471 it
.vpos
= this_line_vpos
;
10472 it
.current_y
= this_line_y
;
10473 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10474 display_line (&it
);
10476 /* If line contains point, is not continued,
10477 and ends at same distance from eob as before, we win */
10478 if (w
->cursor
.vpos
>= 0
10479 /* Line is not continued, otherwise this_line_start_pos
10480 would have been set to 0 in display_line. */
10481 && CHARPOS (this_line_start_pos
)
10482 /* Line ends as before. */
10483 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10484 /* Line has same height as before. Otherwise other lines
10485 would have to be shifted up or down. */
10486 && this_line_pixel_height
== line_height_before
)
10488 /* If this is not the window's last line, we must adjust
10489 the charstarts of the lines below. */
10490 if (it
.current_y
< it
.last_visible_y
)
10492 struct glyph_row
*row
10493 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10494 int delta
, delta_bytes
;
10496 if (Z
- CHARPOS (tlendpos
) == ZV
)
10498 /* This line ends at end of (accessible part of)
10499 buffer. There is no newline to count. */
10501 - CHARPOS (tlendpos
)
10502 - MATRIX_ROW_START_CHARPOS (row
));
10503 delta_bytes
= (Z_BYTE
10504 - BYTEPOS (tlendpos
)
10505 - MATRIX_ROW_START_BYTEPOS (row
));
10509 /* This line ends in a newline. Must take
10510 account of the newline and the rest of the
10511 text that follows. */
10513 - CHARPOS (tlendpos
)
10514 - MATRIX_ROW_START_CHARPOS (row
));
10515 delta_bytes
= (Z_BYTE
10516 - BYTEPOS (tlendpos
)
10517 - MATRIX_ROW_START_BYTEPOS (row
));
10520 increment_matrix_positions (w
->current_matrix
,
10521 this_line_vpos
+ 1,
10522 w
->current_matrix
->nrows
,
10523 delta
, delta_bytes
);
10526 /* If this row displays text now but previously didn't,
10527 or vice versa, w->window_end_vpos may have to be
10529 if ((it
.glyph_row
- 1)->displays_text_p
)
10531 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10532 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10534 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10535 && this_line_vpos
> 0)
10536 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10537 w
->window_end_valid
= Qnil
;
10539 /* Update hint: No need to try to scroll in update_window. */
10540 w
->desired_matrix
->no_scrolling_p
= 1;
10543 *w
->desired_matrix
->method
= 0;
10544 debug_method_add (w
, "optimization 1");
10546 #ifdef HAVE_WINDOW_SYSTEM
10547 update_window_fringes (w
, 0);
10554 else if (/* Cursor position hasn't changed. */
10555 PT
== XFASTINT (w
->last_point
)
10556 /* Make sure the cursor was last displayed
10557 in this window. Otherwise we have to reposition it. */
10558 && 0 <= w
->cursor
.vpos
10559 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10563 do_pending_window_change (1);
10565 /* We used to always goto end_of_redisplay here, but this
10566 isn't enough if we have a blinking cursor. */
10567 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10568 goto end_of_redisplay
;
10572 /* If highlighting the region, or if the cursor is in the echo area,
10573 then we can't just move the cursor. */
10574 else if (! (!NILP (Vtransient_mark_mode
)
10575 && !NILP (current_buffer
->mark_active
))
10576 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10577 || highlight_nonselected_windows
)
10578 && NILP (w
->region_showing
)
10579 && NILP (Vshow_trailing_whitespace
)
10580 && !cursor_in_echo_area
)
10583 struct glyph_row
*row
;
10585 /* Skip from tlbufpos to PT and see where it is. Note that
10586 PT may be in invisible text. If so, we will end at the
10587 next visible position. */
10588 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10589 NULL
, DEFAULT_FACE_ID
);
10590 it
.current_x
= this_line_start_x
;
10591 it
.current_y
= this_line_y
;
10592 it
.vpos
= this_line_vpos
;
10594 /* The call to move_it_to stops in front of PT, but
10595 moves over before-strings. */
10596 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10598 if (it
.vpos
== this_line_vpos
10599 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10602 xassert (this_line_vpos
== it
.vpos
);
10603 xassert (this_line_y
== it
.current_y
);
10604 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10606 *w
->desired_matrix
->method
= 0;
10607 debug_method_add (w
, "optimization 3");
10616 /* Text changed drastically or point moved off of line. */
10617 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10620 CHARPOS (this_line_start_pos
) = 0;
10621 consider_all_windows_p
|= buffer_shared
> 1;
10622 ++clear_face_cache_count
;
10623 #ifdef HAVE_WINDOW_SYSTEM
10624 ++clear_image_cache_count
;
10627 /* Build desired matrices, and update the display. If
10628 consider_all_windows_p is non-zero, do it for all windows on all
10629 frames. Otherwise do it for selected_window, only. */
10631 if (consider_all_windows_p
)
10633 Lisp_Object tail
, frame
;
10635 FOR_EACH_FRAME (tail
, frame
)
10636 XFRAME (frame
)->updated_p
= 0;
10638 /* Recompute # windows showing selected buffer. This will be
10639 incremented each time such a window is displayed. */
10642 FOR_EACH_FRAME (tail
, frame
)
10644 struct frame
*f
= XFRAME (frame
);
10646 if (FRAME_WINDOW_P (f
) || f
== sf
)
10648 if (! EQ (frame
, selected_frame
))
10649 /* Select the frame, for the sake of frame-local
10651 select_frame_for_redisplay (frame
);
10653 /* Mark all the scroll bars to be removed; we'll redeem
10654 the ones we want when we redisplay their windows. */
10655 if (condemn_scroll_bars_hook
)
10656 condemn_scroll_bars_hook (f
);
10658 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10659 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10661 /* Any scroll bars which redisplay_windows should have
10662 nuked should now go away. */
10663 if (judge_scroll_bars_hook
)
10664 judge_scroll_bars_hook (f
);
10666 /* If fonts changed, display again. */
10667 /* ??? rms: I suspect it is a mistake to jump all the way
10668 back to retry here. It should just retry this frame. */
10669 if (fonts_changed_p
)
10672 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10674 /* See if we have to hscroll. */
10675 if (!f
->already_hscrolled_p
)
10677 f
->already_hscrolled_p
= 1;
10678 if (hscroll_windows (f
->root_window
))
10682 /* Prevent various kinds of signals during display
10683 update. stdio is not robust about handling
10684 signals, which can cause an apparent I/O
10686 if (interrupt_input
)
10687 unrequest_sigio ();
10690 /* Update the display. */
10691 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10692 pause
|= update_frame (f
, 0, 0);
10693 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10705 /* Do the mark_window_display_accurate after all windows have
10706 been redisplayed because this call resets flags in buffers
10707 which are needed for proper redisplay. */
10708 FOR_EACH_FRAME (tail
, frame
)
10710 struct frame
*f
= XFRAME (frame
);
10713 mark_window_display_accurate (f
->root_window
, 1);
10714 if (frame_up_to_date_hook
)
10715 frame_up_to_date_hook (f
);
10720 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10722 Lisp_Object mini_window
;
10723 struct frame
*mini_frame
;
10725 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10726 /* Use list_of_error, not Qerror, so that
10727 we catch only errors and don't run the debugger. */
10728 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10730 redisplay_window_error
);
10732 /* Compare desired and current matrices, perform output. */
10735 /* If fonts changed, display again. */
10736 if (fonts_changed_p
)
10739 /* Prevent various kinds of signals during display update.
10740 stdio is not robust about handling signals,
10741 which can cause an apparent I/O error. */
10742 if (interrupt_input
)
10743 unrequest_sigio ();
10746 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10748 if (hscroll_windows (selected_window
))
10751 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10752 pause
= update_frame (sf
, 0, 0);
10755 /* We may have called echo_area_display at the top of this
10756 function. If the echo area is on another frame, that may
10757 have put text on a frame other than the selected one, so the
10758 above call to update_frame would not have caught it. Catch
10760 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10761 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10763 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10765 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10766 pause
|= update_frame (mini_frame
, 0, 0);
10767 if (!pause
&& hscroll_windows (mini_window
))
10772 /* If display was paused because of pending input, make sure we do a
10773 thorough update the next time. */
10776 /* Prevent the optimization at the beginning of
10777 redisplay_internal that tries a single-line update of the
10778 line containing the cursor in the selected window. */
10779 CHARPOS (this_line_start_pos
) = 0;
10781 /* Let the overlay arrow be updated the next time. */
10782 update_overlay_arrows (0);
10784 /* If we pause after scrolling, some rows in the current
10785 matrices of some windows are not valid. */
10786 if (!WINDOW_FULL_WIDTH_P (w
)
10787 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10788 update_mode_lines
= 1;
10792 if (!consider_all_windows_p
)
10794 /* This has already been done above if
10795 consider_all_windows_p is set. */
10796 mark_window_display_accurate_1 (w
, 1);
10798 /* Say overlay arrows are up to date. */
10799 update_overlay_arrows (1);
10801 if (frame_up_to_date_hook
!= 0)
10802 frame_up_to_date_hook (sf
);
10805 update_mode_lines
= 0;
10806 windows_or_buffers_changed
= 0;
10807 cursor_type_changed
= 0;
10810 /* Start SIGIO interrupts coming again. Having them off during the
10811 code above makes it less likely one will discard output, but not
10812 impossible, since there might be stuff in the system buffer here.
10813 But it is much hairier to try to do anything about that. */
10814 if (interrupt_input
)
10818 /* If a frame has become visible which was not before, redisplay
10819 again, so that we display it. Expose events for such a frame
10820 (which it gets when becoming visible) don't call the parts of
10821 redisplay constructing glyphs, so simply exposing a frame won't
10822 display anything in this case. So, we have to display these
10823 frames here explicitly. */
10826 Lisp_Object tail
, frame
;
10829 FOR_EACH_FRAME (tail
, frame
)
10831 int this_is_visible
= 0;
10833 if (XFRAME (frame
)->visible
)
10834 this_is_visible
= 1;
10835 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10836 if (XFRAME (frame
)->visible
)
10837 this_is_visible
= 1;
10839 if (this_is_visible
)
10843 if (new_count
!= number_of_visible_frames
)
10844 windows_or_buffers_changed
++;
10847 /* Change frame size now if a change is pending. */
10848 do_pending_window_change (1);
10850 /* If we just did a pending size change, or have additional
10851 visible frames, redisplay again. */
10852 if (windows_or_buffers_changed
&& !pause
)
10855 /* Clear the face cache eventually. */
10856 if (consider_all_windows_p
)
10858 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10860 clear_face_cache (0);
10861 clear_face_cache_count
= 0;
10863 #ifdef HAVE_WINDOW_SYSTEM
10864 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
10866 Lisp_Object tail
, frame
;
10867 FOR_EACH_FRAME (tail
, frame
)
10869 struct frame
*f
= XFRAME (frame
);
10870 if (FRAME_WINDOW_P (f
))
10871 clear_image_cache (f
, 0);
10873 clear_image_cache_count
= 0;
10875 #endif /* HAVE_WINDOW_SYSTEM */
10879 unbind_to (count
, Qnil
);
10884 /* Redisplay, but leave alone any recent echo area message unless
10885 another message has been requested in its place.
10887 This is useful in situations where you need to redisplay but no
10888 user action has occurred, making it inappropriate for the message
10889 area to be cleared. See tracking_off and
10890 wait_reading_process_output for examples of these situations.
10892 FROM_WHERE is an integer saying from where this function was
10893 called. This is useful for debugging. */
10896 redisplay_preserve_echo_area (from_where
)
10899 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10901 if (!NILP (echo_area_buffer
[1]))
10903 /* We have a previously displayed message, but no current
10904 message. Redisplay the previous message. */
10905 display_last_displayed_message_p
= 1;
10906 redisplay_internal (1);
10907 display_last_displayed_message_p
= 0;
10910 redisplay_internal (1);
10912 if (rif
!= NULL
&& rif
->flush_display_optional
)
10913 rif
->flush_display_optional (NULL
);
10917 /* Function registered with record_unwind_protect in
10918 redisplay_internal. Reset redisplaying_p to the value it had
10919 before redisplay_internal was called, and clear
10920 prevent_freeing_realized_faces_p. It also selects the previously
10924 unwind_redisplay (val
)
10927 Lisp_Object old_redisplaying_p
, old_frame
;
10929 old_redisplaying_p
= XCAR (val
);
10930 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10931 old_frame
= XCDR (val
);
10932 if (! EQ (old_frame
, selected_frame
))
10933 select_frame_for_redisplay (old_frame
);
10938 /* Mark the display of window W as accurate or inaccurate. If
10939 ACCURATE_P is non-zero mark display of W as accurate. If
10940 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10941 redisplay_internal is called. */
10944 mark_window_display_accurate_1 (w
, accurate_p
)
10948 if (BUFFERP (w
->buffer
))
10950 struct buffer
*b
= XBUFFER (w
->buffer
);
10953 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10954 w
->last_overlay_modified
10955 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10957 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10961 b
->clip_changed
= 0;
10962 b
->prevent_redisplay_optimizations_p
= 0;
10964 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10965 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10966 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10967 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10969 w
->current_matrix
->buffer
= b
;
10970 w
->current_matrix
->begv
= BUF_BEGV (b
);
10971 w
->current_matrix
->zv
= BUF_ZV (b
);
10973 w
->last_cursor
= w
->cursor
;
10974 w
->last_cursor_off_p
= w
->cursor_off_p
;
10976 if (w
== XWINDOW (selected_window
))
10977 w
->last_point
= make_number (BUF_PT (b
));
10979 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10985 w
->window_end_valid
= w
->buffer
;
10986 #if 0 /* This is incorrect with variable-height lines. */
10987 xassert (XINT (w
->window_end_vpos
)
10988 < (WINDOW_TOTAL_LINES (w
)
10989 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10991 w
->update_mode_line
= Qnil
;
10996 /* Mark the display of windows in the window tree rooted at WINDOW as
10997 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10998 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10999 be redisplayed the next time redisplay_internal is called. */
11002 mark_window_display_accurate (window
, accurate_p
)
11003 Lisp_Object window
;
11008 for (; !NILP (window
); window
= w
->next
)
11010 w
= XWINDOW (window
);
11011 mark_window_display_accurate_1 (w
, accurate_p
);
11013 if (!NILP (w
->vchild
))
11014 mark_window_display_accurate (w
->vchild
, accurate_p
);
11015 if (!NILP (w
->hchild
))
11016 mark_window_display_accurate (w
->hchild
, accurate_p
);
11021 update_overlay_arrows (1);
11025 /* Force a thorough redisplay the next time by setting
11026 last_arrow_position and last_arrow_string to t, which is
11027 unequal to any useful value of Voverlay_arrow_... */
11028 update_overlay_arrows (-1);
11033 /* Return value in display table DP (Lisp_Char_Table *) for character
11034 C. Since a display table doesn't have any parent, we don't have to
11035 follow parent. Do not call this function directly but use the
11036 macro DISP_CHAR_VECTOR. */
11039 disp_char_vector (dp
, c
)
11040 struct Lisp_Char_Table
*dp
;
11046 if (SINGLE_BYTE_CHAR_P (c
))
11047 return (dp
->contents
[c
]);
11049 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11052 else if (code
[2] < 32)
11055 /* Here, the possible range of code[0] (== charset ID) is
11056 128..max_charset. Since the top level char table contains data
11057 for multibyte characters after 256th element, we must increment
11058 code[0] by 128 to get a correct index. */
11060 code
[3] = -1; /* anchor */
11062 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11064 val
= dp
->contents
[code
[i
]];
11065 if (!SUB_CHAR_TABLE_P (val
))
11066 return (NILP (val
) ? dp
->defalt
: val
);
11069 /* Here, val is a sub char table. We return the default value of
11071 return (dp
->defalt
);
11076 /***********************************************************************
11078 ***********************************************************************/
11080 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11083 redisplay_windows (window
)
11084 Lisp_Object window
;
11086 while (!NILP (window
))
11088 struct window
*w
= XWINDOW (window
);
11090 if (!NILP (w
->hchild
))
11091 redisplay_windows (w
->hchild
);
11092 else if (!NILP (w
->vchild
))
11093 redisplay_windows (w
->vchild
);
11096 displayed_buffer
= XBUFFER (w
->buffer
);
11097 /* Use list_of_error, not Qerror, so that
11098 we catch only errors and don't run the debugger. */
11099 internal_condition_case_1 (redisplay_window_0
, window
,
11101 redisplay_window_error
);
11109 redisplay_window_error ()
11111 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11116 redisplay_window_0 (window
)
11117 Lisp_Object window
;
11119 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11120 redisplay_window (window
, 0);
11125 redisplay_window_1 (window
)
11126 Lisp_Object window
;
11128 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11129 redisplay_window (window
, 1);
11134 /* Increment GLYPH until it reaches END or CONDITION fails while
11135 adding (GLYPH)->pixel_width to X. */
11137 #define SKIP_GLYPHS(glyph, end, x, condition) \
11140 (x) += (glyph)->pixel_width; \
11143 while ((glyph) < (end) && (condition))
11146 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11147 DELTA is the number of bytes by which positions recorded in ROW
11148 differ from current buffer positions. */
11151 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11153 struct glyph_row
*row
;
11154 struct glyph_matrix
*matrix
;
11155 int delta
, delta_bytes
, dy
, dvpos
;
11157 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11158 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11159 struct glyph
*cursor
= NULL
;
11160 /* The first glyph that starts a sequence of glyphs from string. */
11161 struct glyph
*string_start
;
11162 /* The X coordinate of string_start. */
11163 int string_start_x
;
11164 /* The last known character position. */
11165 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11166 /* The last known character position before string_start. */
11167 int string_before_pos
;
11170 int cursor_from_overlay_pos
= 0;
11171 int pt_old
= PT
- delta
;
11173 /* Skip over glyphs not having an object at the start of the row.
11174 These are special glyphs like truncation marks on terminal
11176 if (row
->displays_text_p
)
11178 && INTEGERP (glyph
->object
)
11179 && glyph
->charpos
< 0)
11181 x
+= glyph
->pixel_width
;
11185 string_start
= NULL
;
11187 && !INTEGERP (glyph
->object
)
11188 && (!BUFFERP (glyph
->object
)
11189 || (last_pos
= glyph
->charpos
) < pt_old
))
11191 if (! STRINGP (glyph
->object
))
11193 string_start
= NULL
;
11194 x
+= glyph
->pixel_width
;
11196 if (cursor_from_overlay_pos
11197 && last_pos
> cursor_from_overlay_pos
)
11199 cursor_from_overlay_pos
= 0;
11205 string_before_pos
= last_pos
;
11206 string_start
= glyph
;
11207 string_start_x
= x
;
11208 /* Skip all glyphs from string. */
11212 if ((cursor
== NULL
|| glyph
> cursor
)
11213 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11214 Qcursor
, (glyph
)->object
))
11215 && (pos
= string_buffer_position (w
, glyph
->object
,
11216 string_before_pos
),
11217 (pos
== 0 /* From overlay */
11218 || pos
== pt_old
)))
11220 /* Estimate overlay buffer position from the buffer
11221 positions of the glyphs before and after the overlay.
11222 Add 1 to last_pos so that if point corresponds to the
11223 glyph right after the overlay, we still use a 'cursor'
11224 property found in that overlay. */
11225 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11229 x
+= glyph
->pixel_width
;
11232 while (glyph
< end
&& STRINGP (glyph
->object
));
11236 if (cursor
!= NULL
)
11241 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11243 /* Scan back over the ellipsis glyphs, decrementing positions. */
11244 while (glyph
> row
->glyphs
[TEXT_AREA
]
11245 && (glyph
- 1)->charpos
== last_pos
)
11246 glyph
--, x
-= glyph
->pixel_width
;
11247 /* That loop always goes one position too far,
11248 including the glyph before the ellipsis.
11249 So scan forward over that one. */
11250 x
+= glyph
->pixel_width
;
11253 else if (string_start
11254 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11256 /* We may have skipped over point because the previous glyphs
11257 are from string. As there's no easy way to know the
11258 character position of the current glyph, find the correct
11259 glyph on point by scanning from string_start again. */
11261 Lisp_Object string
;
11264 limit
= make_number (pt_old
+ 1);
11266 glyph
= string_start
;
11267 x
= string_start_x
;
11268 string
= glyph
->object
;
11269 pos
= string_buffer_position (w
, string
, string_before_pos
);
11270 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11271 because we always put cursor after overlay strings. */
11272 while (pos
== 0 && glyph
< end
)
11274 string
= glyph
->object
;
11275 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11277 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11280 while (glyph
< end
)
11282 pos
= XINT (Fnext_single_char_property_change
11283 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11286 /* Skip glyphs from the same string. */
11287 string
= glyph
->object
;
11288 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11289 /* Skip glyphs from an overlay. */
11291 && ! string_buffer_position (w
, glyph
->object
, pos
))
11293 string
= glyph
->object
;
11294 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11299 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11301 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11302 w
->cursor
.y
= row
->y
+ dy
;
11304 if (w
== XWINDOW (selected_window
))
11306 if (!row
->continued_p
11307 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11310 this_line_buffer
= XBUFFER (w
->buffer
);
11312 CHARPOS (this_line_start_pos
)
11313 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11314 BYTEPOS (this_line_start_pos
)
11315 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11317 CHARPOS (this_line_end_pos
)
11318 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11319 BYTEPOS (this_line_end_pos
)
11320 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11322 this_line_y
= w
->cursor
.y
;
11323 this_line_pixel_height
= row
->height
;
11324 this_line_vpos
= w
->cursor
.vpos
;
11325 this_line_start_x
= row
->x
;
11328 CHARPOS (this_line_start_pos
) = 0;
11333 /* Run window scroll functions, if any, for WINDOW with new window
11334 start STARTP. Sets the window start of WINDOW to that position.
11336 We assume that the window's buffer is really current. */
11338 static INLINE
struct text_pos
11339 run_window_scroll_functions (window
, startp
)
11340 Lisp_Object window
;
11341 struct text_pos startp
;
11343 struct window
*w
= XWINDOW (window
);
11344 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11346 if (current_buffer
!= XBUFFER (w
->buffer
))
11349 if (!NILP (Vwindow_scroll_functions
))
11351 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11352 make_number (CHARPOS (startp
)));
11353 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11354 /* In case the hook functions switch buffers. */
11355 if (current_buffer
!= XBUFFER (w
->buffer
))
11356 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11363 /* Make sure the line containing the cursor is fully visible.
11364 A value of 1 means there is nothing to be done.
11365 (Either the line is fully visible, or it cannot be made so,
11366 or we cannot tell.)
11368 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11369 is higher than window.
11371 A value of 0 means the caller should do scrolling
11372 as if point had gone off the screen. */
11375 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11378 int current_matrix_p
;
11380 struct glyph_matrix
*matrix
;
11381 struct glyph_row
*row
;
11384 if (!make_cursor_line_fully_visible_p
)
11387 /* It's not always possible to find the cursor, e.g, when a window
11388 is full of overlay strings. Don't do anything in that case. */
11389 if (w
->cursor
.vpos
< 0)
11392 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11393 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11395 /* If the cursor row is not partially visible, there's nothing to do. */
11396 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11399 /* If the row the cursor is in is taller than the window's height,
11400 it's not clear what to do, so do nothing. */
11401 window_height
= window_box_height (w
);
11402 if (row
->height
>= window_height
)
11404 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11410 /* This code used to try to scroll the window just enough to make
11411 the line visible. It returned 0 to say that the caller should
11412 allocate larger glyph matrices. */
11414 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11416 int dy
= row
->height
- row
->visible_height
;
11419 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11421 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11423 int dy
= - (row
->height
- row
->visible_height
);
11426 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11429 /* When we change the cursor y-position of the selected window,
11430 change this_line_y as well so that the display optimization for
11431 the cursor line of the selected window in redisplay_internal uses
11432 the correct y-position. */
11433 if (w
== XWINDOW (selected_window
))
11434 this_line_y
= w
->cursor
.y
;
11436 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11437 redisplay with larger matrices. */
11438 if (matrix
->nrows
< required_matrix_height (w
))
11440 fonts_changed_p
= 1;
11449 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11450 non-zero means only WINDOW is redisplayed in redisplay_internal.
11451 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11452 in redisplay_window to bring a partially visible line into view in
11453 the case that only the cursor has moved.
11455 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11456 last screen line's vertical height extends past the end of the screen.
11460 1 if scrolling succeeded
11462 0 if scrolling didn't find point.
11464 -1 if new fonts have been loaded so that we must interrupt
11465 redisplay, adjust glyph matrices, and try again. */
11471 SCROLLING_NEED_LARGER_MATRICES
11475 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11476 scroll_step
, temp_scroll_step
, last_line_misfit
)
11477 Lisp_Object window
;
11478 int just_this_one_p
;
11479 EMACS_INT scroll_conservatively
, scroll_step
;
11480 int temp_scroll_step
;
11481 int last_line_misfit
;
11483 struct window
*w
= XWINDOW (window
);
11484 struct frame
*f
= XFRAME (w
->frame
);
11485 struct text_pos scroll_margin_pos
;
11486 struct text_pos pos
;
11487 struct text_pos startp
;
11489 Lisp_Object window_end
;
11490 int this_scroll_margin
;
11494 int amount_to_scroll
= 0;
11495 Lisp_Object aggressive
;
11497 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11500 debug_method_add (w
, "try_scrolling");
11503 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11505 /* Compute scroll margin height in pixels. We scroll when point is
11506 within this distance from the top or bottom of the window. */
11507 if (scroll_margin
> 0)
11509 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11510 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11513 this_scroll_margin
= 0;
11515 /* Force scroll_conservatively to have a reasonable value so it doesn't
11516 cause an overflow while computing how much to scroll. */
11517 if (scroll_conservatively
)
11518 scroll_conservatively
= min (scroll_conservatively
,
11519 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11521 /* Compute how much we should try to scroll maximally to bring point
11523 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11524 scroll_max
= max (scroll_step
,
11525 max (scroll_conservatively
, temp_scroll_step
));
11526 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11527 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11528 /* We're trying to scroll because of aggressive scrolling
11529 but no scroll_step is set. Choose an arbitrary one. Maybe
11530 there should be a variable for this. */
11534 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11536 /* Decide whether we have to scroll down. Start at the window end
11537 and move this_scroll_margin up to find the position of the scroll
11539 window_end
= Fwindow_end (window
, Qt
);
11543 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11544 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11546 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11548 start_display (&it
, w
, scroll_margin_pos
);
11549 if (this_scroll_margin
)
11550 move_it_vertically_backward (&it
, this_scroll_margin
);
11551 if (extra_scroll_margin_lines
)
11552 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11553 scroll_margin_pos
= it
.current
.pos
;
11556 if (PT
>= CHARPOS (scroll_margin_pos
))
11560 /* Point is in the scroll margin at the bottom of the window, or
11561 below. Compute a new window start that makes point visible. */
11563 /* Compute the distance from the scroll margin to PT.
11564 Give up if the distance is greater than scroll_max. */
11565 start_display (&it
, w
, scroll_margin_pos
);
11567 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11568 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11570 /* To make point visible, we have to move the window start
11571 down so that the line the cursor is in is visible, which
11572 means we have to add in the height of the cursor line. */
11573 dy
= line_bottom_y (&it
) - y0
;
11575 if (dy
> scroll_max
)
11576 return SCROLLING_FAILED
;
11578 /* Move the window start down. If scrolling conservatively,
11579 move it just enough down to make point visible. If
11580 scroll_step is set, move it down by scroll_step. */
11581 start_display (&it
, w
, startp
);
11583 if (scroll_conservatively
)
11584 /* Set AMOUNT_TO_SCROLL to at least one line,
11585 and at most scroll_conservatively lines. */
11587 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11588 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11589 else if (scroll_step
|| temp_scroll_step
)
11590 amount_to_scroll
= scroll_max
;
11593 aggressive
= current_buffer
->scroll_up_aggressively
;
11594 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11595 if (NUMBERP (aggressive
))
11597 double float_amount
= XFLOATINT (aggressive
) * height
;
11598 amount_to_scroll
= float_amount
;
11599 if (amount_to_scroll
== 0 && float_amount
> 0)
11600 amount_to_scroll
= 1;
11604 if (amount_to_scroll
<= 0)
11605 return SCROLLING_FAILED
;
11607 /* If moving by amount_to_scroll leaves STARTP unchanged,
11608 move it down one screen line. */
11610 move_it_vertically (&it
, amount_to_scroll
);
11611 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11612 move_it_by_lines (&it
, 1, 1);
11613 startp
= it
.current
.pos
;
11617 /* See if point is inside the scroll margin at the top of the
11619 scroll_margin_pos
= startp
;
11620 if (this_scroll_margin
)
11622 start_display (&it
, w
, startp
);
11623 move_it_vertically (&it
, this_scroll_margin
);
11624 scroll_margin_pos
= it
.current
.pos
;
11627 if (PT
< CHARPOS (scroll_margin_pos
))
11629 /* Point is in the scroll margin at the top of the window or
11630 above what is displayed in the window. */
11633 /* Compute the vertical distance from PT to the scroll
11634 margin position. Give up if distance is greater than
11636 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11637 start_display (&it
, w
, pos
);
11639 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11640 it
.last_visible_y
, -1,
11641 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11642 dy
= it
.current_y
- y0
;
11643 if (dy
> scroll_max
)
11644 return SCROLLING_FAILED
;
11646 /* Compute new window start. */
11647 start_display (&it
, w
, startp
);
11649 if (scroll_conservatively
)
11651 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11652 else if (scroll_step
|| temp_scroll_step
)
11653 amount_to_scroll
= scroll_max
;
11656 aggressive
= current_buffer
->scroll_down_aggressively
;
11657 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11658 if (NUMBERP (aggressive
))
11660 double float_amount
= XFLOATINT (aggressive
) * height
;
11661 amount_to_scroll
= float_amount
;
11662 if (amount_to_scroll
== 0 && float_amount
> 0)
11663 amount_to_scroll
= 1;
11667 if (amount_to_scroll
<= 0)
11668 return SCROLLING_FAILED
;
11670 move_it_vertically_backward (&it
, amount_to_scroll
);
11671 startp
= it
.current
.pos
;
11675 /* Run window scroll functions. */
11676 startp
= run_window_scroll_functions (window
, startp
);
11678 /* Display the window. Give up if new fonts are loaded, or if point
11680 if (!try_window (window
, startp
, 0))
11681 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11682 else if (w
->cursor
.vpos
< 0)
11684 clear_glyph_matrix (w
->desired_matrix
);
11685 rc
= SCROLLING_FAILED
;
11689 /* Maybe forget recorded base line for line number display. */
11690 if (!just_this_one_p
11691 || current_buffer
->clip_changed
11692 || BEG_UNCHANGED
< CHARPOS (startp
))
11693 w
->base_line_number
= Qnil
;
11695 /* If cursor ends up on a partially visible line,
11696 treat that as being off the bottom of the screen. */
11697 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11699 clear_glyph_matrix (w
->desired_matrix
);
11700 ++extra_scroll_margin_lines
;
11703 rc
= SCROLLING_SUCCESS
;
11710 /* Compute a suitable window start for window W if display of W starts
11711 on a continuation line. Value is non-zero if a new window start
11714 The new window start will be computed, based on W's width, starting
11715 from the start of the continued line. It is the start of the
11716 screen line with the minimum distance from the old start W->start. */
11719 compute_window_start_on_continuation_line (w
)
11722 struct text_pos pos
, start_pos
;
11723 int window_start_changed_p
= 0;
11725 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11727 /* If window start is on a continuation line... Window start may be
11728 < BEGV in case there's invisible text at the start of the
11729 buffer (M-x rmail, for example). */
11730 if (CHARPOS (start_pos
) > BEGV
11731 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11734 struct glyph_row
*row
;
11736 /* Handle the case that the window start is out of range. */
11737 if (CHARPOS (start_pos
) < BEGV
)
11738 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11739 else if (CHARPOS (start_pos
) > ZV
)
11740 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11742 /* Find the start of the continued line. This should be fast
11743 because scan_buffer is fast (newline cache). */
11744 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11745 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11746 row
, DEFAULT_FACE_ID
);
11747 reseat_at_previous_visible_line_start (&it
);
11749 /* If the line start is "too far" away from the window start,
11750 say it takes too much time to compute a new window start. */
11751 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11752 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11754 int min_distance
, distance
;
11756 /* Move forward by display lines to find the new window
11757 start. If window width was enlarged, the new start can
11758 be expected to be > the old start. If window width was
11759 decreased, the new window start will be < the old start.
11760 So, we're looking for the display line start with the
11761 minimum distance from the old window start. */
11762 pos
= it
.current
.pos
;
11763 min_distance
= INFINITY
;
11764 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11765 distance
< min_distance
)
11767 min_distance
= distance
;
11768 pos
= it
.current
.pos
;
11769 move_it_by_lines (&it
, 1, 0);
11772 /* Set the window start there. */
11773 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11774 window_start_changed_p
= 1;
11778 return window_start_changed_p
;
11782 /* Try cursor movement in case text has not changed in window WINDOW,
11783 with window start STARTP. Value is
11785 CURSOR_MOVEMENT_SUCCESS if successful
11787 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11789 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11790 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11791 we want to scroll as if scroll-step were set to 1. See the code.
11793 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11794 which case we have to abort this redisplay, and adjust matrices
11799 CURSOR_MOVEMENT_SUCCESS
,
11800 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11801 CURSOR_MOVEMENT_MUST_SCROLL
,
11802 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11806 try_cursor_movement (window
, startp
, scroll_step
)
11807 Lisp_Object window
;
11808 struct text_pos startp
;
11811 struct window
*w
= XWINDOW (window
);
11812 struct frame
*f
= XFRAME (w
->frame
);
11813 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11816 if (inhibit_try_cursor_movement
)
11820 /* Handle case where text has not changed, only point, and it has
11821 not moved off the frame. */
11822 if (/* Point may be in this window. */
11823 PT
>= CHARPOS (startp
)
11824 /* Selective display hasn't changed. */
11825 && !current_buffer
->clip_changed
11826 /* Function force-mode-line-update is used to force a thorough
11827 redisplay. It sets either windows_or_buffers_changed or
11828 update_mode_lines. So don't take a shortcut here for these
11830 && !update_mode_lines
11831 && !windows_or_buffers_changed
11832 && !cursor_type_changed
11833 /* Can't use this case if highlighting a region. When a
11834 region exists, cursor movement has to do more than just
11836 && !(!NILP (Vtransient_mark_mode
)
11837 && !NILP (current_buffer
->mark_active
))
11838 && NILP (w
->region_showing
)
11839 && NILP (Vshow_trailing_whitespace
)
11840 /* Right after splitting windows, last_point may be nil. */
11841 && INTEGERP (w
->last_point
)
11842 /* This code is not used for mini-buffer for the sake of the case
11843 of redisplaying to replace an echo area message; since in
11844 that case the mini-buffer contents per se are usually
11845 unchanged. This code is of no real use in the mini-buffer
11846 since the handling of this_line_start_pos, etc., in redisplay
11847 handles the same cases. */
11848 && !EQ (window
, minibuf_window
)
11849 /* When splitting windows or for new windows, it happens that
11850 redisplay is called with a nil window_end_vpos or one being
11851 larger than the window. This should really be fixed in
11852 window.c. I don't have this on my list, now, so we do
11853 approximately the same as the old redisplay code. --gerd. */
11854 && INTEGERP (w
->window_end_vpos
)
11855 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11856 && (FRAME_WINDOW_P (f
)
11857 || !overlay_arrow_in_current_buffer_p ()))
11859 int this_scroll_margin
, top_scroll_margin
;
11860 struct glyph_row
*row
= NULL
;
11863 debug_method_add (w
, "cursor movement");
11866 /* Scroll if point within this distance from the top or bottom
11867 of the window. This is a pixel value. */
11868 this_scroll_margin
= max (0, scroll_margin
);
11869 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11870 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11872 top_scroll_margin
= this_scroll_margin
;
11873 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11874 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11876 /* Start with the row the cursor was displayed during the last
11877 not paused redisplay. Give up if that row is not valid. */
11878 if (w
->last_cursor
.vpos
< 0
11879 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11880 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11883 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11884 if (row
->mode_line_p
)
11886 if (!row
->enabled_p
)
11887 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11890 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11893 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11895 if (PT
> XFASTINT (w
->last_point
))
11897 /* Point has moved forward. */
11898 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11899 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11901 xassert (row
->enabled_p
);
11905 /* The end position of a row equals the start position
11906 of the next row. If PT is there, we would rather
11907 display it in the next line. */
11908 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11909 && MATRIX_ROW_END_CHARPOS (row
) == PT
11910 && !cursor_row_p (w
, row
))
11913 /* If within the scroll margin, scroll. Note that
11914 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11915 the next line would be drawn, and that
11916 this_scroll_margin can be zero. */
11917 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11918 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11919 /* Line is completely visible last line in window
11920 and PT is to be set in the next line. */
11921 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11922 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11923 && !row
->ends_at_zv_p
11924 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11927 else if (PT
< XFASTINT (w
->last_point
))
11929 /* Cursor has to be moved backward. Note that PT >=
11930 CHARPOS (startp) because of the outer if-statement. */
11931 while (!row
->mode_line_p
11932 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11933 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11934 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
11935 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
11936 row
> w
->current_matrix
->rows
11937 && (row
-1)->ends_in_newline_from_string_p
))))
11938 && (row
->y
> top_scroll_margin
11939 || CHARPOS (startp
) == BEGV
))
11941 xassert (row
->enabled_p
);
11945 /* Consider the following case: Window starts at BEGV,
11946 there is invisible, intangible text at BEGV, so that
11947 display starts at some point START > BEGV. It can
11948 happen that we are called with PT somewhere between
11949 BEGV and START. Try to handle that case. */
11950 if (row
< w
->current_matrix
->rows
11951 || row
->mode_line_p
)
11953 row
= w
->current_matrix
->rows
;
11954 if (row
->mode_line_p
)
11958 /* Due to newlines in overlay strings, we may have to
11959 skip forward over overlay strings. */
11960 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11961 && MATRIX_ROW_END_CHARPOS (row
) == PT
11962 && !cursor_row_p (w
, row
))
11965 /* If within the scroll margin, scroll. */
11966 if (row
->y
< top_scroll_margin
11967 && CHARPOS (startp
) != BEGV
)
11972 /* Cursor did not move. So don't scroll even if cursor line
11973 is partially visible, as it was so before. */
11974 rc
= CURSOR_MOVEMENT_SUCCESS
;
11977 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11978 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11980 /* if PT is not in the glyph row, give up. */
11981 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11983 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
11984 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11985 && make_cursor_line_fully_visible_p
)
11987 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11988 && !row
->ends_at_zv_p
11989 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11990 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11991 else if (row
->height
> window_box_height (w
))
11993 /* If we end up in a partially visible line, let's
11994 make it fully visible, except when it's taller
11995 than the window, in which case we can't do much
11998 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12002 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12003 if (!cursor_row_fully_visible_p (w
, 0, 1))
12004 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12006 rc
= CURSOR_MOVEMENT_SUCCESS
;
12010 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12013 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12014 rc
= CURSOR_MOVEMENT_SUCCESS
;
12023 set_vertical_scroll_bar (w
)
12026 int start
, end
, whole
;
12028 /* Calculate the start and end positions for the current window.
12029 At some point, it would be nice to choose between scrollbars
12030 which reflect the whole buffer size, with special markers
12031 indicating narrowing, and scrollbars which reflect only the
12034 Note that mini-buffers sometimes aren't displaying any text. */
12035 if (!MINI_WINDOW_P (w
)
12036 || (w
== XWINDOW (minibuf_window
)
12037 && NILP (echo_area_buffer
[0])))
12039 struct buffer
*buf
= XBUFFER (w
->buffer
);
12040 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12041 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12042 /* I don't think this is guaranteed to be right. For the
12043 moment, we'll pretend it is. */
12044 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12048 if (whole
< (end
- start
))
12049 whole
= end
- start
;
12052 start
= end
= whole
= 0;
12054 /* Indicate what this scroll bar ought to be displaying now. */
12055 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12059 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12060 selected_window is redisplayed.
12062 We can return without actually redisplaying the window if
12063 fonts_changed_p is nonzero. In that case, redisplay_internal will
12067 redisplay_window (window
, just_this_one_p
)
12068 Lisp_Object window
;
12069 int just_this_one_p
;
12071 struct window
*w
= XWINDOW (window
);
12072 struct frame
*f
= XFRAME (w
->frame
);
12073 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12074 struct buffer
*old
= current_buffer
;
12075 struct text_pos lpoint
, opoint
, startp
;
12076 int update_mode_line
;
12079 /* Record it now because it's overwritten. */
12080 int current_matrix_up_to_date_p
= 0;
12081 int used_current_matrix_p
= 0;
12082 /* This is less strict than current_matrix_up_to_date_p.
12083 It indictes that the buffer contents and narrowing are unchanged. */
12084 int buffer_unchanged_p
= 0;
12085 int temp_scroll_step
= 0;
12086 int count
= SPECPDL_INDEX ();
12088 int centering_position
= -1;
12089 int last_line_misfit
= 0;
12091 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12094 /* W must be a leaf window here. */
12095 xassert (!NILP (w
->buffer
));
12097 *w
->desired_matrix
->method
= 0;
12100 specbind (Qinhibit_point_motion_hooks
, Qt
);
12102 reconsider_clip_changes (w
, buffer
);
12104 /* Has the mode line to be updated? */
12105 update_mode_line
= (!NILP (w
->update_mode_line
)
12106 || update_mode_lines
12107 || buffer
->clip_changed
12108 || buffer
->prevent_redisplay_optimizations_p
);
12110 if (MINI_WINDOW_P (w
))
12112 if (w
== XWINDOW (echo_area_window
)
12113 && !NILP (echo_area_buffer
[0]))
12115 if (update_mode_line
)
12116 /* We may have to update a tty frame's menu bar or a
12117 tool-bar. Example `M-x C-h C-h C-g'. */
12118 goto finish_menu_bars
;
12120 /* We've already displayed the echo area glyphs in this window. */
12121 goto finish_scroll_bars
;
12123 else if ((w
!= XWINDOW (minibuf_window
)
12124 || minibuf_level
== 0)
12125 /* When buffer is nonempty, redisplay window normally. */
12126 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12127 /* Quail displays non-mini buffers in minibuffer window.
12128 In that case, redisplay the window normally. */
12129 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12131 /* W is a mini-buffer window, but it's not active, so clear
12133 int yb
= window_text_bottom_y (w
);
12134 struct glyph_row
*row
;
12137 for (y
= 0, row
= w
->desired_matrix
->rows
;
12139 y
+= row
->height
, ++row
)
12140 blank_row (w
, row
, y
);
12141 goto finish_scroll_bars
;
12144 clear_glyph_matrix (w
->desired_matrix
);
12147 /* Otherwise set up data on this window; select its buffer and point
12149 /* Really select the buffer, for the sake of buffer-local
12151 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12152 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12154 current_matrix_up_to_date_p
12155 = (!NILP (w
->window_end_valid
)
12156 && !current_buffer
->clip_changed
12157 && !current_buffer
->prevent_redisplay_optimizations_p
12158 && XFASTINT (w
->last_modified
) >= MODIFF
12159 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12162 = (!NILP (w
->window_end_valid
)
12163 && !current_buffer
->clip_changed
12164 && XFASTINT (w
->last_modified
) >= MODIFF
12165 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12167 /* When windows_or_buffers_changed is non-zero, we can't rely on
12168 the window end being valid, so set it to nil there. */
12169 if (windows_or_buffers_changed
)
12171 /* If window starts on a continuation line, maybe adjust the
12172 window start in case the window's width changed. */
12173 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12174 compute_window_start_on_continuation_line (w
);
12176 w
->window_end_valid
= Qnil
;
12179 /* Some sanity checks. */
12180 CHECK_WINDOW_END (w
);
12181 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12183 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12186 /* If %c is in mode line, update it if needed. */
12187 if (!NILP (w
->column_number_displayed
)
12188 /* This alternative quickly identifies a common case
12189 where no change is needed. */
12190 && !(PT
== XFASTINT (w
->last_point
)
12191 && XFASTINT (w
->last_modified
) >= MODIFF
12192 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12193 && (XFASTINT (w
->column_number_displayed
)
12194 != (int) current_column ())) /* iftc */
12195 update_mode_line
= 1;
12197 /* Count number of windows showing the selected buffer. An indirect
12198 buffer counts as its base buffer. */
12199 if (!just_this_one_p
)
12201 struct buffer
*current_base
, *window_base
;
12202 current_base
= current_buffer
;
12203 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12204 if (current_base
->base_buffer
)
12205 current_base
= current_base
->base_buffer
;
12206 if (window_base
->base_buffer
)
12207 window_base
= window_base
->base_buffer
;
12208 if (current_base
== window_base
)
12212 /* Point refers normally to the selected window. For any other
12213 window, set up appropriate value. */
12214 if (!EQ (window
, selected_window
))
12216 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12217 int new_pt_byte
= marker_byte_position (w
->pointm
);
12221 new_pt_byte
= BEGV_BYTE
;
12222 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12224 else if (new_pt
> (ZV
- 1))
12227 new_pt_byte
= ZV_BYTE
;
12228 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12231 /* We don't use SET_PT so that the point-motion hooks don't run. */
12232 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12235 /* If any of the character widths specified in the display table
12236 have changed, invalidate the width run cache. It's true that
12237 this may be a bit late to catch such changes, but the rest of
12238 redisplay goes (non-fatally) haywire when the display table is
12239 changed, so why should we worry about doing any better? */
12240 if (current_buffer
->width_run_cache
)
12242 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12244 if (! disptab_matches_widthtab (disptab
,
12245 XVECTOR (current_buffer
->width_table
)))
12247 invalidate_region_cache (current_buffer
,
12248 current_buffer
->width_run_cache
,
12250 recompute_width_table (current_buffer
, disptab
);
12254 /* If window-start is screwed up, choose a new one. */
12255 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12258 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12260 /* If someone specified a new starting point but did not insist,
12261 check whether it can be used. */
12262 if (!NILP (w
->optional_new_start
)
12263 && CHARPOS (startp
) >= BEGV
12264 && CHARPOS (startp
) <= ZV
)
12266 w
->optional_new_start
= Qnil
;
12267 start_display (&it
, w
, startp
);
12268 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12269 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12270 if (IT_CHARPOS (it
) == PT
)
12271 w
->force_start
= Qt
;
12272 /* IT may overshoot PT if text at PT is invisible. */
12273 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12274 w
->force_start
= Qt
;
12279 /* Handle case where place to start displaying has been specified,
12280 unless the specified location is outside the accessible range. */
12281 if (!NILP (w
->force_start
)
12282 || w
->frozen_window_start_p
)
12284 /* We set this later on if we have to adjust point. */
12288 w
->force_start
= Qnil
;
12290 w
->window_end_valid
= Qnil
;
12292 /* Forget any recorded base line for line number display. */
12293 if (!buffer_unchanged_p
)
12294 w
->base_line_number
= Qnil
;
12296 /* Redisplay the mode line. Select the buffer properly for that.
12297 Also, run the hook window-scroll-functions
12298 because we have scrolled. */
12299 /* Note, we do this after clearing force_start because
12300 if there's an error, it is better to forget about force_start
12301 than to get into an infinite loop calling the hook functions
12302 and having them get more errors. */
12303 if (!update_mode_line
12304 || ! NILP (Vwindow_scroll_functions
))
12306 update_mode_line
= 1;
12307 w
->update_mode_line
= Qt
;
12308 startp
= run_window_scroll_functions (window
, startp
);
12311 w
->last_modified
= make_number (0);
12312 w
->last_overlay_modified
= make_number (0);
12313 if (CHARPOS (startp
) < BEGV
)
12314 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12315 else if (CHARPOS (startp
) > ZV
)
12316 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12318 /* Redisplay, then check if cursor has been set during the
12319 redisplay. Give up if new fonts were loaded. */
12320 val
= try_window (window
, startp
, 1);
12323 w
->force_start
= Qt
;
12324 clear_glyph_matrix (w
->desired_matrix
);
12325 goto need_larger_matrices
;
12327 /* Point was outside the scroll margins. */
12329 new_vpos
= window_box_height (w
) / 2;
12331 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12333 /* If point does not appear, try to move point so it does
12334 appear. The desired matrix has been built above, so we
12335 can use it here. */
12336 new_vpos
= window_box_height (w
) / 2;
12339 if (!cursor_row_fully_visible_p (w
, 0, 0))
12341 /* Point does appear, but on a line partly visible at end of window.
12342 Move it back to a fully-visible line. */
12343 new_vpos
= window_box_height (w
);
12346 /* If we need to move point for either of the above reasons,
12347 now actually do it. */
12350 struct glyph_row
*row
;
12352 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12353 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12356 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12357 MATRIX_ROW_START_BYTEPOS (row
));
12359 if (w
!= XWINDOW (selected_window
))
12360 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12361 else if (current_buffer
== old
)
12362 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12364 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12366 /* If we are highlighting the region, then we just changed
12367 the region, so redisplay to show it. */
12368 if (!NILP (Vtransient_mark_mode
)
12369 && !NILP (current_buffer
->mark_active
))
12371 clear_glyph_matrix (w
->desired_matrix
);
12372 if (!try_window (window
, startp
, 0))
12373 goto need_larger_matrices
;
12378 debug_method_add (w
, "forced window start");
12383 /* Handle case where text has not changed, only point, and it has
12384 not moved off the frame, and we are not retrying after hscroll.
12385 (current_matrix_up_to_date_p is nonzero when retrying.) */
12386 if (current_matrix_up_to_date_p
12387 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12388 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12392 case CURSOR_MOVEMENT_SUCCESS
:
12393 used_current_matrix_p
= 1;
12396 #if 0 /* try_cursor_movement never returns this value. */
12397 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12398 goto need_larger_matrices
;
12401 case CURSOR_MOVEMENT_MUST_SCROLL
:
12402 goto try_to_scroll
;
12408 /* If current starting point was originally the beginning of a line
12409 but no longer is, find a new starting point. */
12410 else if (!NILP (w
->start_at_line_beg
)
12411 && !(CHARPOS (startp
) <= BEGV
12412 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12415 debug_method_add (w
, "recenter 1");
12420 /* Try scrolling with try_window_id. Value is > 0 if update has
12421 been done, it is -1 if we know that the same window start will
12422 not work. It is 0 if unsuccessful for some other reason. */
12423 else if ((tem
= try_window_id (w
)) != 0)
12426 debug_method_add (w
, "try_window_id %d", tem
);
12429 if (fonts_changed_p
)
12430 goto need_larger_matrices
;
12434 /* Otherwise try_window_id has returned -1 which means that we
12435 don't want the alternative below this comment to execute. */
12437 else if (CHARPOS (startp
) >= BEGV
12438 && CHARPOS (startp
) <= ZV
12439 && PT
>= CHARPOS (startp
)
12440 && (CHARPOS (startp
) < ZV
12441 /* Avoid starting at end of buffer. */
12442 || CHARPOS (startp
) == BEGV
12443 || (XFASTINT (w
->last_modified
) >= MODIFF
12444 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12447 debug_method_add (w
, "same window start");
12450 /* Try to redisplay starting at same place as before.
12451 If point has not moved off frame, accept the results. */
12452 if (!current_matrix_up_to_date_p
12453 /* Don't use try_window_reusing_current_matrix in this case
12454 because a window scroll function can have changed the
12456 || !NILP (Vwindow_scroll_functions
)
12457 || MINI_WINDOW_P (w
)
12458 || !(used_current_matrix_p
12459 = try_window_reusing_current_matrix (w
)))
12461 IF_DEBUG (debug_method_add (w
, "1"));
12462 if (try_window (window
, startp
, 1) < 0)
12463 /* -1 means we need to scroll.
12464 0 means we need new matrices, but fonts_changed_p
12465 is set in that case, so we will detect it below. */
12466 goto try_to_scroll
;
12469 if (fonts_changed_p
)
12470 goto need_larger_matrices
;
12472 if (w
->cursor
.vpos
>= 0)
12474 if (!just_this_one_p
12475 || current_buffer
->clip_changed
12476 || BEG_UNCHANGED
< CHARPOS (startp
))
12477 /* Forget any recorded base line for line number display. */
12478 w
->base_line_number
= Qnil
;
12480 if (!cursor_row_fully_visible_p (w
, 1, 0))
12482 clear_glyph_matrix (w
->desired_matrix
);
12483 last_line_misfit
= 1;
12485 /* Drop through and scroll. */
12490 clear_glyph_matrix (w
->desired_matrix
);
12495 w
->last_modified
= make_number (0);
12496 w
->last_overlay_modified
= make_number (0);
12498 /* Redisplay the mode line. Select the buffer properly for that. */
12499 if (!update_mode_line
)
12501 update_mode_line
= 1;
12502 w
->update_mode_line
= Qt
;
12505 /* Try to scroll by specified few lines. */
12506 if ((scroll_conservatively
12508 || temp_scroll_step
12509 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12510 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12511 && !current_buffer
->clip_changed
12512 && CHARPOS (startp
) >= BEGV
12513 && CHARPOS (startp
) <= ZV
)
12515 /* The function returns -1 if new fonts were loaded, 1 if
12516 successful, 0 if not successful. */
12517 int rc
= try_scrolling (window
, just_this_one_p
,
12518 scroll_conservatively
,
12520 temp_scroll_step
, last_line_misfit
);
12523 case SCROLLING_SUCCESS
:
12526 case SCROLLING_NEED_LARGER_MATRICES
:
12527 goto need_larger_matrices
;
12529 case SCROLLING_FAILED
:
12537 /* Finally, just choose place to start which centers point */
12540 if (centering_position
< 0)
12541 centering_position
= window_box_height (w
) / 2;
12544 debug_method_add (w
, "recenter");
12547 /* w->vscroll = 0; */
12549 /* Forget any previously recorded base line for line number display. */
12550 if (!buffer_unchanged_p
)
12551 w
->base_line_number
= Qnil
;
12553 /* Move backward half the height of the window. */
12554 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12555 it
.current_y
= it
.last_visible_y
;
12556 move_it_vertically_backward (&it
, centering_position
);
12557 xassert (IT_CHARPOS (it
) >= BEGV
);
12559 /* The function move_it_vertically_backward may move over more
12560 than the specified y-distance. If it->w is small, e.g. a
12561 mini-buffer window, we may end up in front of the window's
12562 display area. Start displaying at the start of the line
12563 containing PT in this case. */
12564 if (it
.current_y
<= 0)
12566 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12567 move_it_vertically_backward (&it
, 0);
12569 /* I think this assert is bogus if buffer contains
12570 invisible text or images. KFS. */
12571 xassert (IT_CHARPOS (it
) <= PT
);
12576 it
.current_x
= it
.hpos
= 0;
12578 /* Set startp here explicitly in case that helps avoid an infinite loop
12579 in case the window-scroll-functions functions get errors. */
12580 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12582 /* Run scroll hooks. */
12583 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12585 /* Redisplay the window. */
12586 if (!current_matrix_up_to_date_p
12587 || windows_or_buffers_changed
12588 || cursor_type_changed
12589 /* Don't use try_window_reusing_current_matrix in this case
12590 because it can have changed the buffer. */
12591 || !NILP (Vwindow_scroll_functions
)
12592 || !just_this_one_p
12593 || MINI_WINDOW_P (w
)
12594 || !(used_current_matrix_p
12595 = try_window_reusing_current_matrix (w
)))
12596 try_window (window
, startp
, 0);
12598 /* If new fonts have been loaded (due to fontsets), give up. We
12599 have to start a new redisplay since we need to re-adjust glyph
12601 if (fonts_changed_p
)
12602 goto need_larger_matrices
;
12604 /* If cursor did not appear assume that the middle of the window is
12605 in the first line of the window. Do it again with the next line.
12606 (Imagine a window of height 100, displaying two lines of height
12607 60. Moving back 50 from it->last_visible_y will end in the first
12609 if (w
->cursor
.vpos
< 0)
12611 if (!NILP (w
->window_end_valid
)
12612 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12614 clear_glyph_matrix (w
->desired_matrix
);
12615 move_it_by_lines (&it
, 1, 0);
12616 try_window (window
, it
.current
.pos
, 0);
12618 else if (PT
< IT_CHARPOS (it
))
12620 clear_glyph_matrix (w
->desired_matrix
);
12621 move_it_by_lines (&it
, -1, 0);
12622 try_window (window
, it
.current
.pos
, 0);
12626 /* Not much we can do about it. */
12630 /* Consider the following case: Window starts at BEGV, there is
12631 invisible, intangible text at BEGV, so that display starts at
12632 some point START > BEGV. It can happen that we are called with
12633 PT somewhere between BEGV and START. Try to handle that case. */
12634 if (w
->cursor
.vpos
< 0)
12636 struct glyph_row
*row
= w
->current_matrix
->rows
;
12637 if (row
->mode_line_p
)
12639 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12642 if (!cursor_row_fully_visible_p (w
, 0, 0))
12644 /* If vscroll is enabled, disable it and try again. */
12648 clear_glyph_matrix (w
->desired_matrix
);
12652 /* If centering point failed to make the whole line visible,
12653 put point at the top instead. That has to make the whole line
12654 visible, if it can be done. */
12655 if (centering_position
== 0)
12658 clear_glyph_matrix (w
->desired_matrix
);
12659 centering_position
= 0;
12665 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12666 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12667 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12670 /* Display the mode line, if we must. */
12671 if ((update_mode_line
12672 /* If window not full width, must redo its mode line
12673 if (a) the window to its side is being redone and
12674 (b) we do a frame-based redisplay. This is a consequence
12675 of how inverted lines are drawn in frame-based redisplay. */
12676 || (!just_this_one_p
12677 && !FRAME_WINDOW_P (f
)
12678 && !WINDOW_FULL_WIDTH_P (w
))
12679 /* Line number to display. */
12680 || INTEGERP (w
->base_line_pos
)
12681 /* Column number is displayed and different from the one displayed. */
12682 || (!NILP (w
->column_number_displayed
)
12683 && (XFASTINT (w
->column_number_displayed
)
12684 != (int) current_column ()))) /* iftc */
12685 /* This means that the window has a mode line. */
12686 && (WINDOW_WANTS_MODELINE_P (w
)
12687 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12689 display_mode_lines (w
);
12691 /* If mode line height has changed, arrange for a thorough
12692 immediate redisplay using the correct mode line height. */
12693 if (WINDOW_WANTS_MODELINE_P (w
)
12694 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12696 fonts_changed_p
= 1;
12697 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12698 = DESIRED_MODE_LINE_HEIGHT (w
);
12701 /* If top line height has changed, arrange for a thorough
12702 immediate redisplay using the correct mode line height. */
12703 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12704 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12706 fonts_changed_p
= 1;
12707 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12708 = DESIRED_HEADER_LINE_HEIGHT (w
);
12711 if (fonts_changed_p
)
12712 goto need_larger_matrices
;
12715 if (!line_number_displayed
12716 && !BUFFERP (w
->base_line_pos
))
12718 w
->base_line_pos
= Qnil
;
12719 w
->base_line_number
= Qnil
;
12724 /* When we reach a frame's selected window, redo the frame's menu bar. */
12725 if (update_mode_line
12726 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12728 int redisplay_menu_p
= 0;
12729 int redisplay_tool_bar_p
= 0;
12731 if (FRAME_WINDOW_P (f
))
12733 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12734 || defined (USE_GTK)
12735 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12737 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12741 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12743 if (redisplay_menu_p
)
12744 display_menu_bar (w
);
12746 #ifdef HAVE_WINDOW_SYSTEM
12748 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12750 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12751 && (FRAME_TOOL_BAR_LINES (f
) > 0
12752 || auto_resize_tool_bars_p
);
12756 if (redisplay_tool_bar_p
)
12757 redisplay_tool_bar (f
);
12761 #ifdef HAVE_WINDOW_SYSTEM
12762 if (FRAME_WINDOW_P (f
)
12763 && update_window_fringes (w
, (just_this_one_p
12764 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
12765 || w
->pseudo_window_p
)))
12769 if (draw_window_fringes (w
, 1))
12770 x_draw_vertical_border (w
);
12774 #endif /* HAVE_WINDOW_SYSTEM */
12776 /* We go to this label, with fonts_changed_p nonzero,
12777 if it is necessary to try again using larger glyph matrices.
12778 We have to redeem the scroll bar even in this case,
12779 because the loop in redisplay_internal expects that. */
12780 need_larger_matrices
:
12782 finish_scroll_bars
:
12784 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12786 /* Set the thumb's position and size. */
12787 set_vertical_scroll_bar (w
);
12789 /* Note that we actually used the scroll bar attached to this
12790 window, so it shouldn't be deleted at the end of redisplay. */
12791 redeem_scroll_bar_hook (w
);
12794 /* Restore current_buffer and value of point in it. */
12795 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12796 set_buffer_internal_1 (old
);
12797 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12799 unbind_to (count
, Qnil
);
12803 /* Build the complete desired matrix of WINDOW with a window start
12804 buffer position POS.
12806 Value is 1 if successful. It is zero if fonts were loaded during
12807 redisplay which makes re-adjusting glyph matrices necessary, and -1
12808 if point would appear in the scroll margins.
12809 (We check that only if CHECK_MARGINS is nonzero. */
12812 try_window (window
, pos
, check_margins
)
12813 Lisp_Object window
;
12814 struct text_pos pos
;
12817 struct window
*w
= XWINDOW (window
);
12819 struct glyph_row
*last_text_row
= NULL
;
12821 /* Make POS the new window start. */
12822 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12824 /* Mark cursor position as unknown. No overlay arrow seen. */
12825 w
->cursor
.vpos
= -1;
12826 overlay_arrow_seen
= 0;
12828 /* Initialize iterator and info to start at POS. */
12829 start_display (&it
, w
, pos
);
12831 /* Display all lines of W. */
12832 while (it
.current_y
< it
.last_visible_y
)
12834 if (display_line (&it
))
12835 last_text_row
= it
.glyph_row
- 1;
12836 if (fonts_changed_p
)
12840 /* Don't let the cursor end in the scroll margins. */
12842 && !MINI_WINDOW_P (w
))
12844 int this_scroll_margin
;
12846 this_scroll_margin
= max (0, scroll_margin
);
12847 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12848 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
12850 if ((w
->cursor
.y
< this_scroll_margin
12851 && CHARPOS (pos
) > BEGV
)
12852 /* rms: considering make_cursor_line_fully_visible_p here
12853 seems to give wrong results. We don't want to recenter
12854 when the last line is partly visible, we want to allow
12855 that case to be handled in the usual way. */
12856 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
12858 w
->cursor
.vpos
= -1;
12859 clear_glyph_matrix (w
->desired_matrix
);
12864 /* If bottom moved off end of frame, change mode line percentage. */
12865 if (XFASTINT (w
->window_end_pos
) <= 0
12866 && Z
!= IT_CHARPOS (it
))
12867 w
->update_mode_line
= Qt
;
12869 /* Set window_end_pos to the offset of the last character displayed
12870 on the window from the end of current_buffer. Set
12871 window_end_vpos to its row number. */
12874 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12875 w
->window_end_bytepos
12876 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12878 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12880 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12881 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12882 ->displays_text_p
);
12886 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12887 w
->window_end_pos
= make_number (Z
- ZV
);
12888 w
->window_end_vpos
= make_number (0);
12891 /* But that is not valid info until redisplay finishes. */
12892 w
->window_end_valid
= Qnil
;
12898 /************************************************************************
12899 Window redisplay reusing current matrix when buffer has not changed
12900 ************************************************************************/
12902 /* Try redisplay of window W showing an unchanged buffer with a
12903 different window start than the last time it was displayed by
12904 reusing its current matrix. Value is non-zero if successful.
12905 W->start is the new window start. */
12908 try_window_reusing_current_matrix (w
)
12911 struct frame
*f
= XFRAME (w
->frame
);
12912 struct glyph_row
*row
, *bottom_row
;
12915 struct text_pos start
, new_start
;
12916 int nrows_scrolled
, i
;
12917 struct glyph_row
*last_text_row
;
12918 struct glyph_row
*last_reused_text_row
;
12919 struct glyph_row
*start_row
;
12920 int start_vpos
, min_y
, max_y
;
12923 if (inhibit_try_window_reusing
)
12927 if (/* This function doesn't handle terminal frames. */
12928 !FRAME_WINDOW_P (f
)
12929 /* Don't try to reuse the display if windows have been split
12931 || windows_or_buffers_changed
12932 || cursor_type_changed
)
12935 /* Can't do this if region may have changed. */
12936 if ((!NILP (Vtransient_mark_mode
)
12937 && !NILP (current_buffer
->mark_active
))
12938 || !NILP (w
->region_showing
)
12939 || !NILP (Vshow_trailing_whitespace
))
12942 /* If top-line visibility has changed, give up. */
12943 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12944 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12947 /* Give up if old or new display is scrolled vertically. We could
12948 make this function handle this, but right now it doesn't. */
12949 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12950 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12953 /* The variable new_start now holds the new window start. The old
12954 start `start' can be determined from the current matrix. */
12955 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12956 start
= start_row
->start
.pos
;
12957 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12959 /* Clear the desired matrix for the display below. */
12960 clear_glyph_matrix (w
->desired_matrix
);
12962 if (CHARPOS (new_start
) <= CHARPOS (start
))
12966 /* Don't use this method if the display starts with an ellipsis
12967 displayed for invisible text. It's not easy to handle that case
12968 below, and it's certainly not worth the effort since this is
12969 not a frequent case. */
12970 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12973 IF_DEBUG (debug_method_add (w
, "twu1"));
12975 /* Display up to a row that can be reused. The variable
12976 last_text_row is set to the last row displayed that displays
12977 text. Note that it.vpos == 0 if or if not there is a
12978 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12979 start_display (&it
, w
, new_start
);
12980 first_row_y
= it
.current_y
;
12981 w
->cursor
.vpos
= -1;
12982 last_text_row
= last_reused_text_row
= NULL
;
12984 while (it
.current_y
< it
.last_visible_y
12985 && !fonts_changed_p
)
12987 /* If we have reached into the characters in the START row,
12988 that means the line boundaries have changed. So we
12989 can't start copying with the row START. Maybe it will
12990 work to start copying with the following row. */
12991 while (IT_CHARPOS (it
) > CHARPOS (start
))
12993 /* Advance to the next row as the "start". */
12995 start
= start_row
->start
.pos
;
12996 /* If there are no more rows to try, or just one, give up. */
12997 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12998 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12999 || CHARPOS (start
) == ZV
)
13001 clear_glyph_matrix (w
->desired_matrix
);
13005 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13007 /* If we have reached alignment,
13008 we can copy the rest of the rows. */
13009 if (IT_CHARPOS (it
) == CHARPOS (start
))
13012 if (display_line (&it
))
13013 last_text_row
= it
.glyph_row
- 1;
13016 /* A value of current_y < last_visible_y means that we stopped
13017 at the previous window start, which in turn means that we
13018 have at least one reusable row. */
13019 if (it
.current_y
< it
.last_visible_y
)
13021 /* IT.vpos always starts from 0; it counts text lines. */
13022 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13024 /* Find PT if not already found in the lines displayed. */
13025 if (w
->cursor
.vpos
< 0)
13027 int dy
= it
.current_y
- start_row
->y
;
13029 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13030 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13032 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13033 dy
, nrows_scrolled
);
13036 clear_glyph_matrix (w
->desired_matrix
);
13041 /* Scroll the display. Do it before the current matrix is
13042 changed. The problem here is that update has not yet
13043 run, i.e. part of the current matrix is not up to date.
13044 scroll_run_hook will clear the cursor, and use the
13045 current matrix to get the height of the row the cursor is
13047 run
.current_y
= start_row
->y
;
13048 run
.desired_y
= it
.current_y
;
13049 run
.height
= it
.last_visible_y
- it
.current_y
;
13051 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13054 rif
->update_window_begin_hook (w
);
13055 rif
->clear_window_mouse_face (w
);
13056 rif
->scroll_run_hook (w
, &run
);
13057 rif
->update_window_end_hook (w
, 0, 0);
13061 /* Shift current matrix down by nrows_scrolled lines. */
13062 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13063 rotate_matrix (w
->current_matrix
,
13065 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13068 /* Disable lines that must be updated. */
13069 for (i
= 0; i
< it
.vpos
; ++i
)
13070 (start_row
+ i
)->enabled_p
= 0;
13072 /* Re-compute Y positions. */
13073 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13074 max_y
= it
.last_visible_y
;
13075 for (row
= start_row
+ nrows_scrolled
;
13079 row
->y
= it
.current_y
;
13080 row
->visible_height
= row
->height
;
13082 if (row
->y
< min_y
)
13083 row
->visible_height
-= min_y
- row
->y
;
13084 if (row
->y
+ row
->height
> max_y
)
13085 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13086 row
->redraw_fringe_bitmaps_p
= 1;
13088 it
.current_y
+= row
->height
;
13090 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13091 last_reused_text_row
= row
;
13092 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13096 /* Disable lines in the current matrix which are now
13097 below the window. */
13098 for (++row
; row
< bottom_row
; ++row
)
13099 row
->enabled_p
= row
->mode_line_p
= 0;
13102 /* Update window_end_pos etc.; last_reused_text_row is the last
13103 reused row from the current matrix containing text, if any.
13104 The value of last_text_row is the last displayed line
13105 containing text. */
13106 if (last_reused_text_row
)
13108 w
->window_end_bytepos
13109 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13111 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13113 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13114 w
->current_matrix
));
13116 else if (last_text_row
)
13118 w
->window_end_bytepos
13119 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13121 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13123 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13127 /* This window must be completely empty. */
13128 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13129 w
->window_end_pos
= make_number (Z
- ZV
);
13130 w
->window_end_vpos
= make_number (0);
13132 w
->window_end_valid
= Qnil
;
13134 /* Update hint: don't try scrolling again in update_window. */
13135 w
->desired_matrix
->no_scrolling_p
= 1;
13138 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13142 else if (CHARPOS (new_start
) > CHARPOS (start
))
13144 struct glyph_row
*pt_row
, *row
;
13145 struct glyph_row
*first_reusable_row
;
13146 struct glyph_row
*first_row_to_display
;
13148 int yb
= window_text_bottom_y (w
);
13150 /* Find the row starting at new_start, if there is one. Don't
13151 reuse a partially visible line at the end. */
13152 first_reusable_row
= start_row
;
13153 while (first_reusable_row
->enabled_p
13154 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13155 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13156 < CHARPOS (new_start
)))
13157 ++first_reusable_row
;
13159 /* Give up if there is no row to reuse. */
13160 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13161 || !first_reusable_row
->enabled_p
13162 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13163 != CHARPOS (new_start
)))
13166 /* We can reuse fully visible rows beginning with
13167 first_reusable_row to the end of the window. Set
13168 first_row_to_display to the first row that cannot be reused.
13169 Set pt_row to the row containing point, if there is any. */
13171 for (first_row_to_display
= first_reusable_row
;
13172 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13173 ++first_row_to_display
)
13175 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13176 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13177 pt_row
= first_row_to_display
;
13180 /* Start displaying at the start of first_row_to_display. */
13181 xassert (first_row_to_display
->y
< yb
);
13182 init_to_row_start (&it
, w
, first_row_to_display
);
13184 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13186 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13188 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13189 + WINDOW_HEADER_LINE_HEIGHT (w
));
13191 /* Display lines beginning with first_row_to_display in the
13192 desired matrix. Set last_text_row to the last row displayed
13193 that displays text. */
13194 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13195 if (pt_row
== NULL
)
13196 w
->cursor
.vpos
= -1;
13197 last_text_row
= NULL
;
13198 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13199 if (display_line (&it
))
13200 last_text_row
= it
.glyph_row
- 1;
13202 /* Give up If point isn't in a row displayed or reused. */
13203 if (w
->cursor
.vpos
< 0)
13205 clear_glyph_matrix (w
->desired_matrix
);
13209 /* If point is in a reused row, adjust y and vpos of the cursor
13213 w
->cursor
.vpos
-= nrows_scrolled
;
13214 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13217 /* Scroll the display. */
13218 run
.current_y
= first_reusable_row
->y
;
13219 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13220 run
.height
= it
.last_visible_y
- run
.current_y
;
13221 dy
= run
.current_y
- run
.desired_y
;
13226 rif
->update_window_begin_hook (w
);
13227 rif
->clear_window_mouse_face (w
);
13228 rif
->scroll_run_hook (w
, &run
);
13229 rif
->update_window_end_hook (w
, 0, 0);
13233 /* Adjust Y positions of reused rows. */
13234 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13235 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13236 max_y
= it
.last_visible_y
;
13237 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13240 row
->visible_height
= row
->height
;
13241 if (row
->y
< min_y
)
13242 row
->visible_height
-= min_y
- row
->y
;
13243 if (row
->y
+ row
->height
> max_y
)
13244 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13245 row
->redraw_fringe_bitmaps_p
= 1;
13248 /* Scroll the current matrix. */
13249 xassert (nrows_scrolled
> 0);
13250 rotate_matrix (w
->current_matrix
,
13252 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13255 /* Disable rows not reused. */
13256 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13257 row
->enabled_p
= 0;
13259 /* Point may have moved to a different line, so we cannot assume that
13260 the previous cursor position is valid; locate the correct row. */
13263 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13264 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13268 w
->cursor
.y
= row
->y
;
13270 if (row
< bottom_row
)
13272 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13273 while (glyph
->charpos
< PT
)
13276 w
->cursor
.x
+= glyph
->pixel_width
;
13282 /* Adjust window end. A null value of last_text_row means that
13283 the window end is in reused rows which in turn means that
13284 only its vpos can have changed. */
13287 w
->window_end_bytepos
13288 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13290 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13292 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13297 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13300 w
->window_end_valid
= Qnil
;
13301 w
->desired_matrix
->no_scrolling_p
= 1;
13304 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13314 /************************************************************************
13315 Window redisplay reusing current matrix when buffer has changed
13316 ************************************************************************/
13318 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13319 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13321 static struct glyph_row
*
13322 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13323 struct glyph_row
*));
13326 /* Return the last row in MATRIX displaying text. If row START is
13327 non-null, start searching with that row. IT gives the dimensions
13328 of the display. Value is null if matrix is empty; otherwise it is
13329 a pointer to the row found. */
13331 static struct glyph_row
*
13332 find_last_row_displaying_text (matrix
, it
, start
)
13333 struct glyph_matrix
*matrix
;
13335 struct glyph_row
*start
;
13337 struct glyph_row
*row
, *row_found
;
13339 /* Set row_found to the last row in IT->w's current matrix
13340 displaying text. The loop looks funny but think of partially
13343 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13344 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13346 xassert (row
->enabled_p
);
13348 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13357 /* Return the last row in the current matrix of W that is not affected
13358 by changes at the start of current_buffer that occurred since W's
13359 current matrix was built. Value is null if no such row exists.
13361 BEG_UNCHANGED us the number of characters unchanged at the start of
13362 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13363 first changed character in current_buffer. Characters at positions <
13364 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13365 when the current matrix was built. */
13367 static struct glyph_row
*
13368 find_last_unchanged_at_beg_row (w
)
13371 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13372 struct glyph_row
*row
;
13373 struct glyph_row
*row_found
= NULL
;
13374 int yb
= window_text_bottom_y (w
);
13376 /* Find the last row displaying unchanged text. */
13377 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13378 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13379 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13381 if (/* If row ends before first_changed_pos, it is unchanged,
13382 except in some case. */
13383 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13384 /* When row ends in ZV and we write at ZV it is not
13386 && !row
->ends_at_zv_p
13387 /* When first_changed_pos is the end of a continued line,
13388 row is not unchanged because it may be no longer
13390 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13391 && (row
->continued_p
13392 || row
->exact_window_width_line_p
)))
13395 /* Stop if last visible row. */
13396 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13406 /* Find the first glyph row in the current matrix of W that is not
13407 affected by changes at the end of current_buffer since the
13408 time W's current matrix was built.
13410 Return in *DELTA the number of chars by which buffer positions in
13411 unchanged text at the end of current_buffer must be adjusted.
13413 Return in *DELTA_BYTES the corresponding number of bytes.
13415 Value is null if no such row exists, i.e. all rows are affected by
13418 static struct glyph_row
*
13419 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13421 int *delta
, *delta_bytes
;
13423 struct glyph_row
*row
;
13424 struct glyph_row
*row_found
= NULL
;
13426 *delta
= *delta_bytes
= 0;
13428 /* Display must not have been paused, otherwise the current matrix
13429 is not up to date. */
13430 if (NILP (w
->window_end_valid
))
13433 /* A value of window_end_pos >= END_UNCHANGED means that the window
13434 end is in the range of changed text. If so, there is no
13435 unchanged row at the end of W's current matrix. */
13436 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13439 /* Set row to the last row in W's current matrix displaying text. */
13440 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13442 /* If matrix is entirely empty, no unchanged row exists. */
13443 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13445 /* The value of row is the last glyph row in the matrix having a
13446 meaningful buffer position in it. The end position of row
13447 corresponds to window_end_pos. This allows us to translate
13448 buffer positions in the current matrix to current buffer
13449 positions for characters not in changed text. */
13450 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13451 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13452 int last_unchanged_pos
, last_unchanged_pos_old
;
13453 struct glyph_row
*first_text_row
13454 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13456 *delta
= Z
- Z_old
;
13457 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13459 /* Set last_unchanged_pos to the buffer position of the last
13460 character in the buffer that has not been changed. Z is the
13461 index + 1 of the last character in current_buffer, i.e. by
13462 subtracting END_UNCHANGED we get the index of the last
13463 unchanged character, and we have to add BEG to get its buffer
13465 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13466 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13468 /* Search backward from ROW for a row displaying a line that
13469 starts at a minimum position >= last_unchanged_pos_old. */
13470 for (; row
> first_text_row
; --row
)
13472 /* This used to abort, but it can happen.
13473 It is ok to just stop the search instead here. KFS. */
13474 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13477 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13482 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13489 /* Make sure that glyph rows in the current matrix of window W
13490 reference the same glyph memory as corresponding rows in the
13491 frame's frame matrix. This function is called after scrolling W's
13492 current matrix on a terminal frame in try_window_id and
13493 try_window_reusing_current_matrix. */
13496 sync_frame_with_window_matrix_rows (w
)
13499 struct frame
*f
= XFRAME (w
->frame
);
13500 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13502 /* Preconditions: W must be a leaf window and full-width. Its frame
13503 must have a frame matrix. */
13504 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13505 xassert (WINDOW_FULL_WIDTH_P (w
));
13506 xassert (!FRAME_WINDOW_P (f
));
13508 /* If W is a full-width window, glyph pointers in W's current matrix
13509 have, by definition, to be the same as glyph pointers in the
13510 corresponding frame matrix. Note that frame matrices have no
13511 marginal areas (see build_frame_matrix). */
13512 window_row
= w
->current_matrix
->rows
;
13513 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13514 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13515 while (window_row
< window_row_end
)
13517 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13518 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13520 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13521 frame_row
->glyphs
[TEXT_AREA
] = start
;
13522 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13523 frame_row
->glyphs
[LAST_AREA
] = end
;
13525 /* Disable frame rows whose corresponding window rows have
13526 been disabled in try_window_id. */
13527 if (!window_row
->enabled_p
)
13528 frame_row
->enabled_p
= 0;
13530 ++window_row
, ++frame_row
;
13535 /* Find the glyph row in window W containing CHARPOS. Consider all
13536 rows between START and END (not inclusive). END null means search
13537 all rows to the end of the display area of W. Value is the row
13538 containing CHARPOS or null. */
13541 row_containing_pos (w
, charpos
, start
, end
, dy
)
13544 struct glyph_row
*start
, *end
;
13547 struct glyph_row
*row
= start
;
13550 /* If we happen to start on a header-line, skip that. */
13551 if (row
->mode_line_p
)
13554 if ((end
&& row
>= end
) || !row
->enabled_p
)
13557 last_y
= window_text_bottom_y (w
) - dy
;
13561 /* Give up if we have gone too far. */
13562 if (end
&& row
>= end
)
13564 /* This formerly returned if they were equal.
13565 I think that both quantities are of a "last plus one" type;
13566 if so, when they are equal, the row is within the screen. -- rms. */
13567 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13570 /* If it is in this row, return this row. */
13571 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13572 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13573 /* The end position of a row equals the start
13574 position of the next row. If CHARPOS is there, we
13575 would rather display it in the next line, except
13576 when this line ends in ZV. */
13577 && !row
->ends_at_zv_p
13578 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13579 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13586 /* Try to redisplay window W by reusing its existing display. W's
13587 current matrix must be up to date when this function is called,
13588 i.e. window_end_valid must not be nil.
13592 1 if display has been updated
13593 0 if otherwise unsuccessful
13594 -1 if redisplay with same window start is known not to succeed
13596 The following steps are performed:
13598 1. Find the last row in the current matrix of W that is not
13599 affected by changes at the start of current_buffer. If no such row
13602 2. Find the first row in W's current matrix that is not affected by
13603 changes at the end of current_buffer. Maybe there is no such row.
13605 3. Display lines beginning with the row + 1 found in step 1 to the
13606 row found in step 2 or, if step 2 didn't find a row, to the end of
13609 4. If cursor is not known to appear on the window, give up.
13611 5. If display stopped at the row found in step 2, scroll the
13612 display and current matrix as needed.
13614 6. Maybe display some lines at the end of W, if we must. This can
13615 happen under various circumstances, like a partially visible line
13616 becoming fully visible, or because newly displayed lines are displayed
13617 in smaller font sizes.
13619 7. Update W's window end information. */
13625 struct frame
*f
= XFRAME (w
->frame
);
13626 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13627 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13628 struct glyph_row
*last_unchanged_at_beg_row
;
13629 struct glyph_row
*first_unchanged_at_end_row
;
13630 struct glyph_row
*row
;
13631 struct glyph_row
*bottom_row
;
13634 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13635 struct text_pos start_pos
;
13637 int first_unchanged_at_end_vpos
= 0;
13638 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13639 struct text_pos start
;
13640 int first_changed_charpos
, last_changed_charpos
;
13643 if (inhibit_try_window_id
)
13647 /* This is handy for debugging. */
13649 #define GIVE_UP(X) \
13651 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13655 #define GIVE_UP(X) return 0
13658 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13660 /* Don't use this for mini-windows because these can show
13661 messages and mini-buffers, and we don't handle that here. */
13662 if (MINI_WINDOW_P (w
))
13665 /* This flag is used to prevent redisplay optimizations. */
13666 if (windows_or_buffers_changed
|| cursor_type_changed
)
13669 /* Verify that narrowing has not changed.
13670 Also verify that we were not told to prevent redisplay optimizations.
13671 It would be nice to further
13672 reduce the number of cases where this prevents try_window_id. */
13673 if (current_buffer
->clip_changed
13674 || current_buffer
->prevent_redisplay_optimizations_p
)
13677 /* Window must either use window-based redisplay or be full width. */
13678 if (!FRAME_WINDOW_P (f
)
13679 && (!line_ins_del_ok
13680 || !WINDOW_FULL_WIDTH_P (w
)))
13683 /* Give up if point is not known NOT to appear in W. */
13684 if (PT
< CHARPOS (start
))
13687 /* Another way to prevent redisplay optimizations. */
13688 if (XFASTINT (w
->last_modified
) == 0)
13691 /* Verify that window is not hscrolled. */
13692 if (XFASTINT (w
->hscroll
) != 0)
13695 /* Verify that display wasn't paused. */
13696 if (NILP (w
->window_end_valid
))
13699 /* Can't use this if highlighting a region because a cursor movement
13700 will do more than just set the cursor. */
13701 if (!NILP (Vtransient_mark_mode
)
13702 && !NILP (current_buffer
->mark_active
))
13705 /* Likewise if highlighting trailing whitespace. */
13706 if (!NILP (Vshow_trailing_whitespace
))
13709 /* Likewise if showing a region. */
13710 if (!NILP (w
->region_showing
))
13713 /* Can use this if overlay arrow position and or string have changed. */
13714 if (overlay_arrows_changed_p ())
13718 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13719 only if buffer has really changed. The reason is that the gap is
13720 initially at Z for freshly visited files. The code below would
13721 set end_unchanged to 0 in that case. */
13722 if (MODIFF
> SAVE_MODIFF
13723 /* This seems to happen sometimes after saving a buffer. */
13724 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13726 if (GPT
- BEG
< BEG_UNCHANGED
)
13727 BEG_UNCHANGED
= GPT
- BEG
;
13728 if (Z
- GPT
< END_UNCHANGED
)
13729 END_UNCHANGED
= Z
- GPT
;
13732 /* The position of the first and last character that has been changed. */
13733 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13734 last_changed_charpos
= Z
- END_UNCHANGED
;
13736 /* If window starts after a line end, and the last change is in
13737 front of that newline, then changes don't affect the display.
13738 This case happens with stealth-fontification. Note that although
13739 the display is unchanged, glyph positions in the matrix have to
13740 be adjusted, of course. */
13741 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13742 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13743 && ((last_changed_charpos
< CHARPOS (start
)
13744 && CHARPOS (start
) == BEGV
)
13745 || (last_changed_charpos
< CHARPOS (start
) - 1
13746 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13748 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13749 struct glyph_row
*r0
;
13751 /* Compute how many chars/bytes have been added to or removed
13752 from the buffer. */
13753 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13754 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13756 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13758 /* Give up if PT is not in the window. Note that it already has
13759 been checked at the start of try_window_id that PT is not in
13760 front of the window start. */
13761 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13764 /* If window start is unchanged, we can reuse the whole matrix
13765 as is, after adjusting glyph positions. No need to compute
13766 the window end again, since its offset from Z hasn't changed. */
13767 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13768 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13769 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13770 /* PT must not be in a partially visible line. */
13771 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13772 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13774 /* Adjust positions in the glyph matrix. */
13775 if (delta
|| delta_bytes
)
13777 struct glyph_row
*r1
13778 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13779 increment_matrix_positions (w
->current_matrix
,
13780 MATRIX_ROW_VPOS (r0
, current_matrix
),
13781 MATRIX_ROW_VPOS (r1
, current_matrix
),
13782 delta
, delta_bytes
);
13785 /* Set the cursor. */
13786 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13788 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13795 /* Handle the case that changes are all below what is displayed in
13796 the window, and that PT is in the window. This shortcut cannot
13797 be taken if ZV is visible in the window, and text has been added
13798 there that is visible in the window. */
13799 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13800 /* ZV is not visible in the window, or there are no
13801 changes at ZV, actually. */
13802 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13803 || first_changed_charpos
== last_changed_charpos
))
13805 struct glyph_row
*r0
;
13807 /* Give up if PT is not in the window. Note that it already has
13808 been checked at the start of try_window_id that PT is not in
13809 front of the window start. */
13810 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13813 /* If window start is unchanged, we can reuse the whole matrix
13814 as is, without changing glyph positions since no text has
13815 been added/removed in front of the window end. */
13816 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13817 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13818 /* PT must not be in a partially visible line. */
13819 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13820 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13822 /* We have to compute the window end anew since text
13823 can have been added/removed after it. */
13825 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13826 w
->window_end_bytepos
13827 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13829 /* Set the cursor. */
13830 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13832 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13839 /* Give up if window start is in the changed area.
13841 The condition used to read
13843 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13845 but why that was tested escapes me at the moment. */
13846 if (CHARPOS (start
) >= first_changed_charpos
13847 && CHARPOS (start
) <= last_changed_charpos
)
13850 /* Check that window start agrees with the start of the first glyph
13851 row in its current matrix. Check this after we know the window
13852 start is not in changed text, otherwise positions would not be
13854 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13855 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13858 /* Give up if the window ends in strings. Overlay strings
13859 at the end are difficult to handle, so don't try. */
13860 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13861 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13864 /* Compute the position at which we have to start displaying new
13865 lines. Some of the lines at the top of the window might be
13866 reusable because they are not displaying changed text. Find the
13867 last row in W's current matrix not affected by changes at the
13868 start of current_buffer. Value is null if changes start in the
13869 first line of window. */
13870 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13871 if (last_unchanged_at_beg_row
)
13873 /* Avoid starting to display in the moddle of a character, a TAB
13874 for instance. This is easier than to set up the iterator
13875 exactly, and it's not a frequent case, so the additional
13876 effort wouldn't really pay off. */
13877 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13878 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13879 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13880 --last_unchanged_at_beg_row
;
13882 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13885 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13887 start_pos
= it
.current
.pos
;
13889 /* Start displaying new lines in the desired matrix at the same
13890 vpos we would use in the current matrix, i.e. below
13891 last_unchanged_at_beg_row. */
13892 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13894 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13895 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13897 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13901 /* There are no reusable lines at the start of the window.
13902 Start displaying in the first text line. */
13903 start_display (&it
, w
, start
);
13904 it
.vpos
= it
.first_vpos
;
13905 start_pos
= it
.current
.pos
;
13908 /* Find the first row that is not affected by changes at the end of
13909 the buffer. Value will be null if there is no unchanged row, in
13910 which case we must redisplay to the end of the window. delta
13911 will be set to the value by which buffer positions beginning with
13912 first_unchanged_at_end_row have to be adjusted due to text
13914 first_unchanged_at_end_row
13915 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13916 IF_DEBUG (debug_delta
= delta
);
13917 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13919 /* Set stop_pos to the buffer position up to which we will have to
13920 display new lines. If first_unchanged_at_end_row != NULL, this
13921 is the buffer position of the start of the line displayed in that
13922 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13923 that we don't stop at a buffer position. */
13925 if (first_unchanged_at_end_row
)
13927 xassert (last_unchanged_at_beg_row
== NULL
13928 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13930 /* If this is a continuation line, move forward to the next one
13931 that isn't. Changes in lines above affect this line.
13932 Caution: this may move first_unchanged_at_end_row to a row
13933 not displaying text. */
13934 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13935 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13936 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13937 < it
.last_visible_y
))
13938 ++first_unchanged_at_end_row
;
13940 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13941 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13942 >= it
.last_visible_y
))
13943 first_unchanged_at_end_row
= NULL
;
13946 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13948 first_unchanged_at_end_vpos
13949 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13950 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13953 else if (last_unchanged_at_beg_row
== NULL
)
13959 /* Either there is no unchanged row at the end, or the one we have
13960 now displays text. This is a necessary condition for the window
13961 end pos calculation at the end of this function. */
13962 xassert (first_unchanged_at_end_row
== NULL
13963 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13965 debug_last_unchanged_at_beg_vpos
13966 = (last_unchanged_at_beg_row
13967 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13969 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13971 #endif /* GLYPH_DEBUG != 0 */
13974 /* Display new lines. Set last_text_row to the last new line
13975 displayed which has text on it, i.e. might end up as being the
13976 line where the window_end_vpos is. */
13977 w
->cursor
.vpos
= -1;
13978 last_text_row
= NULL
;
13979 overlay_arrow_seen
= 0;
13980 while (it
.current_y
< it
.last_visible_y
13981 && !fonts_changed_p
13982 && (first_unchanged_at_end_row
== NULL
13983 || IT_CHARPOS (it
) < stop_pos
))
13985 if (display_line (&it
))
13986 last_text_row
= it
.glyph_row
- 1;
13989 if (fonts_changed_p
)
13993 /* Compute differences in buffer positions, y-positions etc. for
13994 lines reused at the bottom of the window. Compute what we can
13996 if (first_unchanged_at_end_row
13997 /* No lines reused because we displayed everything up to the
13998 bottom of the window. */
13999 && it
.current_y
< it
.last_visible_y
)
14002 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
14004 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14005 run
.current_y
= first_unchanged_at_end_row
->y
;
14006 run
.desired_y
= run
.current_y
+ dy
;
14007 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14011 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14012 first_unchanged_at_end_row
= NULL
;
14014 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14017 /* Find the cursor if not already found. We have to decide whether
14018 PT will appear on this window (it sometimes doesn't, but this is
14019 not a very frequent case.) This decision has to be made before
14020 the current matrix is altered. A value of cursor.vpos < 0 means
14021 that PT is either in one of the lines beginning at
14022 first_unchanged_at_end_row or below the window. Don't care for
14023 lines that might be displayed later at the window end; as
14024 mentioned, this is not a frequent case. */
14025 if (w
->cursor
.vpos
< 0)
14027 /* Cursor in unchanged rows at the top? */
14028 if (PT
< CHARPOS (start_pos
)
14029 && last_unchanged_at_beg_row
)
14031 row
= row_containing_pos (w
, PT
,
14032 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14033 last_unchanged_at_beg_row
+ 1, 0);
14035 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14038 /* Start from first_unchanged_at_end_row looking for PT. */
14039 else if (first_unchanged_at_end_row
)
14041 row
= row_containing_pos (w
, PT
- delta
,
14042 first_unchanged_at_end_row
, NULL
, 0);
14044 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14045 delta_bytes
, dy
, dvpos
);
14048 /* Give up if cursor was not found. */
14049 if (w
->cursor
.vpos
< 0)
14051 clear_glyph_matrix (w
->desired_matrix
);
14056 /* Don't let the cursor end in the scroll margins. */
14058 int this_scroll_margin
, cursor_height
;
14060 this_scroll_margin
= max (0, scroll_margin
);
14061 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14062 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14063 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14065 if ((w
->cursor
.y
< this_scroll_margin
14066 && CHARPOS (start
) > BEGV
)
14067 /* Old redisplay didn't take scroll margin into account at the bottom,
14068 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14069 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14070 ? cursor_height
+ this_scroll_margin
14071 : 1)) > it
.last_visible_y
)
14073 w
->cursor
.vpos
= -1;
14074 clear_glyph_matrix (w
->desired_matrix
);
14079 /* Scroll the display. Do it before changing the current matrix so
14080 that xterm.c doesn't get confused about where the cursor glyph is
14082 if (dy
&& run
.height
)
14086 if (FRAME_WINDOW_P (f
))
14088 rif
->update_window_begin_hook (w
);
14089 rif
->clear_window_mouse_face (w
);
14090 rif
->scroll_run_hook (w
, &run
);
14091 rif
->update_window_end_hook (w
, 0, 0);
14095 /* Terminal frame. In this case, dvpos gives the number of
14096 lines to scroll by; dvpos < 0 means scroll up. */
14097 int first_unchanged_at_end_vpos
14098 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14099 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14100 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14101 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14102 + window_internal_height (w
));
14104 /* Perform the operation on the screen. */
14107 /* Scroll last_unchanged_at_beg_row to the end of the
14108 window down dvpos lines. */
14109 set_terminal_window (end
);
14111 /* On dumb terminals delete dvpos lines at the end
14112 before inserting dvpos empty lines. */
14113 if (!scroll_region_ok
)
14114 ins_del_lines (end
- dvpos
, -dvpos
);
14116 /* Insert dvpos empty lines in front of
14117 last_unchanged_at_beg_row. */
14118 ins_del_lines (from
, dvpos
);
14120 else if (dvpos
< 0)
14122 /* Scroll up last_unchanged_at_beg_vpos to the end of
14123 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14124 set_terminal_window (end
);
14126 /* Delete dvpos lines in front of
14127 last_unchanged_at_beg_vpos. ins_del_lines will set
14128 the cursor to the given vpos and emit |dvpos| delete
14130 ins_del_lines (from
+ dvpos
, dvpos
);
14132 /* On a dumb terminal insert dvpos empty lines at the
14134 if (!scroll_region_ok
)
14135 ins_del_lines (end
+ dvpos
, -dvpos
);
14138 set_terminal_window (0);
14144 /* Shift reused rows of the current matrix to the right position.
14145 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14147 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14148 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14151 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14152 bottom_vpos
, dvpos
);
14153 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14156 else if (dvpos
> 0)
14158 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14159 bottom_vpos
, dvpos
);
14160 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14161 first_unchanged_at_end_vpos
+ dvpos
, 0);
14164 /* For frame-based redisplay, make sure that current frame and window
14165 matrix are in sync with respect to glyph memory. */
14166 if (!FRAME_WINDOW_P (f
))
14167 sync_frame_with_window_matrix_rows (w
);
14169 /* Adjust buffer positions in reused rows. */
14171 increment_matrix_positions (current_matrix
,
14172 first_unchanged_at_end_vpos
+ dvpos
,
14173 bottom_vpos
, delta
, delta_bytes
);
14175 /* Adjust Y positions. */
14177 shift_glyph_matrix (w
, current_matrix
,
14178 first_unchanged_at_end_vpos
+ dvpos
,
14181 if (first_unchanged_at_end_row
)
14183 first_unchanged_at_end_row
+= dvpos
;
14184 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14185 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14186 first_unchanged_at_end_row
= NULL
;
14189 /* If scrolling up, there may be some lines to display at the end of
14191 last_text_row_at_end
= NULL
;
14194 /* Scrolling up can leave for example a partially visible line
14195 at the end of the window to be redisplayed. */
14196 /* Set last_row to the glyph row in the current matrix where the
14197 window end line is found. It has been moved up or down in
14198 the matrix by dvpos. */
14199 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14200 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14202 /* If last_row is the window end line, it should display text. */
14203 xassert (last_row
->displays_text_p
);
14205 /* If window end line was partially visible before, begin
14206 displaying at that line. Otherwise begin displaying with the
14207 line following it. */
14208 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14210 init_to_row_start (&it
, w
, last_row
);
14211 it
.vpos
= last_vpos
;
14212 it
.current_y
= last_row
->y
;
14216 init_to_row_end (&it
, w
, last_row
);
14217 it
.vpos
= 1 + last_vpos
;
14218 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14222 /* We may start in a continuation line. If so, we have to
14223 get the right continuation_lines_width and current_x. */
14224 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14225 it
.hpos
= it
.current_x
= 0;
14227 /* Display the rest of the lines at the window end. */
14228 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14229 while (it
.current_y
< it
.last_visible_y
14230 && !fonts_changed_p
)
14232 /* Is it always sure that the display agrees with lines in
14233 the current matrix? I don't think so, so we mark rows
14234 displayed invalid in the current matrix by setting their
14235 enabled_p flag to zero. */
14236 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14237 if (display_line (&it
))
14238 last_text_row_at_end
= it
.glyph_row
- 1;
14242 /* Update window_end_pos and window_end_vpos. */
14243 if (first_unchanged_at_end_row
14244 && !last_text_row_at_end
)
14246 /* Window end line if one of the preserved rows from the current
14247 matrix. Set row to the last row displaying text in current
14248 matrix starting at first_unchanged_at_end_row, after
14250 xassert (first_unchanged_at_end_row
->displays_text_p
);
14251 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14252 first_unchanged_at_end_row
);
14253 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14255 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14256 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14258 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14259 xassert (w
->window_end_bytepos
>= 0);
14260 IF_DEBUG (debug_method_add (w
, "A"));
14262 else if (last_text_row_at_end
)
14265 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14266 w
->window_end_bytepos
14267 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14269 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14270 xassert (w
->window_end_bytepos
>= 0);
14271 IF_DEBUG (debug_method_add (w
, "B"));
14273 else if (last_text_row
)
14275 /* We have displayed either to the end of the window or at the
14276 end of the window, i.e. the last row with text is to be found
14277 in the desired matrix. */
14279 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14280 w
->window_end_bytepos
14281 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14283 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14284 xassert (w
->window_end_bytepos
>= 0);
14286 else if (first_unchanged_at_end_row
== NULL
14287 && last_text_row
== NULL
14288 && last_text_row_at_end
== NULL
)
14290 /* Displayed to end of window, but no line containing text was
14291 displayed. Lines were deleted at the end of the window. */
14292 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14293 int vpos
= XFASTINT (w
->window_end_vpos
);
14294 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14295 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14298 row
== NULL
&& vpos
>= first_vpos
;
14299 --vpos
, --current_row
, --desired_row
)
14301 if (desired_row
->enabled_p
)
14303 if (desired_row
->displays_text_p
)
14306 else if (current_row
->displays_text_p
)
14310 xassert (row
!= NULL
);
14311 w
->window_end_vpos
= make_number (vpos
+ 1);
14312 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14313 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14314 xassert (w
->window_end_bytepos
>= 0);
14315 IF_DEBUG (debug_method_add (w
, "C"));
14320 #if 0 /* This leads to problems, for instance when the cursor is
14321 at ZV, and the cursor line displays no text. */
14322 /* Disable rows below what's displayed in the window. This makes
14323 debugging easier. */
14324 enable_glyph_matrix_rows (current_matrix
,
14325 XFASTINT (w
->window_end_vpos
) + 1,
14329 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14330 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14332 /* Record that display has not been completed. */
14333 w
->window_end_valid
= Qnil
;
14334 w
->desired_matrix
->no_scrolling_p
= 1;
14342 /***********************************************************************
14343 More debugging support
14344 ***********************************************************************/
14348 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14349 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14350 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14353 /* Dump the contents of glyph matrix MATRIX on stderr.
14355 GLYPHS 0 means don't show glyph contents.
14356 GLYPHS 1 means show glyphs in short form
14357 GLYPHS > 1 means show glyphs in long form. */
14360 dump_glyph_matrix (matrix
, glyphs
)
14361 struct glyph_matrix
*matrix
;
14365 for (i
= 0; i
< matrix
->nrows
; ++i
)
14366 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14370 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14371 the glyph row and area where the glyph comes from. */
14374 dump_glyph (row
, glyph
, area
)
14375 struct glyph_row
*row
;
14376 struct glyph
*glyph
;
14379 if (glyph
->type
== CHAR_GLYPH
)
14382 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14383 glyph
- row
->glyphs
[TEXT_AREA
],
14386 (BUFFERP (glyph
->object
)
14388 : (STRINGP (glyph
->object
)
14391 glyph
->pixel_width
,
14393 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14397 glyph
->left_box_line_p
,
14398 glyph
->right_box_line_p
);
14400 else if (glyph
->type
== STRETCH_GLYPH
)
14403 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14404 glyph
- row
->glyphs
[TEXT_AREA
],
14407 (BUFFERP (glyph
->object
)
14409 : (STRINGP (glyph
->object
)
14412 glyph
->pixel_width
,
14416 glyph
->left_box_line_p
,
14417 glyph
->right_box_line_p
);
14419 else if (glyph
->type
== IMAGE_GLYPH
)
14422 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14423 glyph
- row
->glyphs
[TEXT_AREA
],
14426 (BUFFERP (glyph
->object
)
14428 : (STRINGP (glyph
->object
)
14431 glyph
->pixel_width
,
14435 glyph
->left_box_line_p
,
14436 glyph
->right_box_line_p
);
14441 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14442 GLYPHS 0 means don't show glyph contents.
14443 GLYPHS 1 means show glyphs in short form
14444 GLYPHS > 1 means show glyphs in long form. */
14447 dump_glyph_row (row
, vpos
, glyphs
)
14448 struct glyph_row
*row
;
14453 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14454 fprintf (stderr
, "======================================================================\n");
14456 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14457 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14459 MATRIX_ROW_START_CHARPOS (row
),
14460 MATRIX_ROW_END_CHARPOS (row
),
14461 row
->used
[TEXT_AREA
],
14462 row
->contains_overlapping_glyphs_p
,
14464 row
->truncated_on_left_p
,
14465 row
->truncated_on_right_p
,
14467 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14468 row
->displays_text_p
,
14471 row
->ends_in_middle_of_char_p
,
14472 row
->starts_in_middle_of_char_p
,
14478 row
->visible_height
,
14481 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14482 row
->end
.overlay_string_index
,
14483 row
->continuation_lines_width
);
14484 fprintf (stderr
, "%9d %5d\n",
14485 CHARPOS (row
->start
.string_pos
),
14486 CHARPOS (row
->end
.string_pos
));
14487 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14488 row
->end
.dpvec_index
);
14495 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14497 struct glyph
*glyph
= row
->glyphs
[area
];
14498 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14500 /* Glyph for a line end in text. */
14501 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14504 if (glyph
< glyph_end
)
14505 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14507 for (; glyph
< glyph_end
; ++glyph
)
14508 dump_glyph (row
, glyph
, area
);
14511 else if (glyphs
== 1)
14515 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14517 char *s
= (char *) alloca (row
->used
[area
] + 1);
14520 for (i
= 0; i
< row
->used
[area
]; ++i
)
14522 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14523 if (glyph
->type
== CHAR_GLYPH
14524 && glyph
->u
.ch
< 0x80
14525 && glyph
->u
.ch
>= ' ')
14526 s
[i
] = glyph
->u
.ch
;
14532 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14538 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14539 Sdump_glyph_matrix
, 0, 1, "p",
14540 doc
: /* Dump the current matrix of the selected window to stderr.
14541 Shows contents of glyph row structures. With non-nil
14542 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14543 glyphs in short form, otherwise show glyphs in long form. */)
14545 Lisp_Object glyphs
;
14547 struct window
*w
= XWINDOW (selected_window
);
14548 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14550 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14551 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14552 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14553 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14554 fprintf (stderr
, "=============================================\n");
14555 dump_glyph_matrix (w
->current_matrix
,
14556 NILP (glyphs
) ? 0 : XINT (glyphs
));
14561 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14562 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14565 struct frame
*f
= XFRAME (selected_frame
);
14566 dump_glyph_matrix (f
->current_matrix
, 1);
14571 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14572 doc
: /* Dump glyph row ROW to stderr.
14573 GLYPH 0 means don't dump glyphs.
14574 GLYPH 1 means dump glyphs in short form.
14575 GLYPH > 1 or omitted means dump glyphs in long form. */)
14577 Lisp_Object row
, glyphs
;
14579 struct glyph_matrix
*matrix
;
14582 CHECK_NUMBER (row
);
14583 matrix
= XWINDOW (selected_window
)->current_matrix
;
14585 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14586 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14588 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14593 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14594 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14595 GLYPH 0 means don't dump glyphs.
14596 GLYPH 1 means dump glyphs in short form.
14597 GLYPH > 1 or omitted means dump glyphs in long form. */)
14599 Lisp_Object row
, glyphs
;
14601 struct frame
*sf
= SELECTED_FRAME ();
14602 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14605 CHECK_NUMBER (row
);
14607 if (vpos
>= 0 && vpos
< m
->nrows
)
14608 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14609 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14614 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14615 doc
: /* Toggle tracing of redisplay.
14616 With ARG, turn tracing on if and only if ARG is positive. */)
14621 trace_redisplay_p
= !trace_redisplay_p
;
14624 arg
= Fprefix_numeric_value (arg
);
14625 trace_redisplay_p
= XINT (arg
) > 0;
14632 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14633 doc
: /* Like `format', but print result to stderr.
14634 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14639 Lisp_Object s
= Fformat (nargs
, args
);
14640 fprintf (stderr
, "%s", SDATA (s
));
14644 #endif /* GLYPH_DEBUG */
14648 /***********************************************************************
14649 Building Desired Matrix Rows
14650 ***********************************************************************/
14652 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14653 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14655 static struct glyph_row
*
14656 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14658 Lisp_Object overlay_arrow_string
;
14660 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14661 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14662 struct buffer
*old
= current_buffer
;
14663 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14664 int arrow_len
= SCHARS (overlay_arrow_string
);
14665 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14666 const unsigned char *p
;
14669 int n_glyphs_before
;
14671 set_buffer_temp (buffer
);
14672 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14673 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14674 SET_TEXT_POS (it
.position
, 0, 0);
14676 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14678 while (p
< arrow_end
)
14680 Lisp_Object face
, ilisp
;
14682 /* Get the next character. */
14684 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14686 it
.c
= *p
, it
.len
= 1;
14689 /* Get its face. */
14690 ilisp
= make_number (p
- arrow_string
);
14691 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14692 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14694 /* Compute its width, get its glyphs. */
14695 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14696 SET_TEXT_POS (it
.position
, -1, -1);
14697 PRODUCE_GLYPHS (&it
);
14699 /* If this character doesn't fit any more in the line, we have
14700 to remove some glyphs. */
14701 if (it
.current_x
> it
.last_visible_x
)
14703 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14708 set_buffer_temp (old
);
14709 return it
.glyph_row
;
14713 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14714 glyphs are only inserted for terminal frames since we can't really
14715 win with truncation glyphs when partially visible glyphs are
14716 involved. Which glyphs to insert is determined by
14717 produce_special_glyphs. */
14720 insert_left_trunc_glyphs (it
)
14723 struct it truncate_it
;
14724 struct glyph
*from
, *end
, *to
, *toend
;
14726 xassert (!FRAME_WINDOW_P (it
->f
));
14728 /* Get the truncation glyphs. */
14730 truncate_it
.current_x
= 0;
14731 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14732 truncate_it
.glyph_row
= &scratch_glyph_row
;
14733 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14734 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14735 truncate_it
.object
= make_number (0);
14736 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14738 /* Overwrite glyphs from IT with truncation glyphs. */
14739 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14740 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14741 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14742 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14747 /* There may be padding glyphs left over. Overwrite them too. */
14748 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14750 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14756 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14760 /* Compute the pixel height and width of IT->glyph_row.
14762 Most of the time, ascent and height of a display line will be equal
14763 to the max_ascent and max_height values of the display iterator
14764 structure. This is not the case if
14766 1. We hit ZV without displaying anything. In this case, max_ascent
14767 and max_height will be zero.
14769 2. We have some glyphs that don't contribute to the line height.
14770 (The glyph row flag contributes_to_line_height_p is for future
14771 pixmap extensions).
14773 The first case is easily covered by using default values because in
14774 these cases, the line height does not really matter, except that it
14775 must not be zero. */
14778 compute_line_metrics (it
)
14781 struct glyph_row
*row
= it
->glyph_row
;
14784 if (FRAME_WINDOW_P (it
->f
))
14786 int i
, min_y
, max_y
;
14788 /* The line may consist of one space only, that was added to
14789 place the cursor on it. If so, the row's height hasn't been
14791 if (row
->height
== 0)
14793 if (it
->max_ascent
+ it
->max_descent
== 0)
14794 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14795 row
->ascent
= it
->max_ascent
;
14796 row
->height
= it
->max_ascent
+ it
->max_descent
;
14797 row
->phys_ascent
= it
->max_phys_ascent
;
14798 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14799 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14802 /* Compute the width of this line. */
14803 row
->pixel_width
= row
->x
;
14804 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14805 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14807 xassert (row
->pixel_width
>= 0);
14808 xassert (row
->ascent
>= 0 && row
->height
> 0);
14810 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14811 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14813 /* If first line's physical ascent is larger than its logical
14814 ascent, use the physical ascent, and make the row taller.
14815 This makes accented characters fully visible. */
14816 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14817 && row
->phys_ascent
> row
->ascent
)
14819 row
->height
+= row
->phys_ascent
- row
->ascent
;
14820 row
->ascent
= row
->phys_ascent
;
14823 /* Compute how much of the line is visible. */
14824 row
->visible_height
= row
->height
;
14826 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14827 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14829 if (row
->y
< min_y
)
14830 row
->visible_height
-= min_y
- row
->y
;
14831 if (row
->y
+ row
->height
> max_y
)
14832 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14836 row
->pixel_width
= row
->used
[TEXT_AREA
];
14837 if (row
->continued_p
)
14838 row
->pixel_width
-= it
->continuation_pixel_width
;
14839 else if (row
->truncated_on_right_p
)
14840 row
->pixel_width
-= it
->truncation_pixel_width
;
14841 row
->ascent
= row
->phys_ascent
= 0;
14842 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14843 row
->extra_line_spacing
= 0;
14846 /* Compute a hash code for this row. */
14848 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14849 for (i
= 0; i
< row
->used
[area
]; ++i
)
14850 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14851 + row
->glyphs
[area
][i
].u
.val
14852 + row
->glyphs
[area
][i
].face_id
14853 + row
->glyphs
[area
][i
].padding_p
14854 + (row
->glyphs
[area
][i
].type
<< 2));
14856 it
->max_ascent
= it
->max_descent
= 0;
14857 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14861 /* Append one space to the glyph row of iterator IT if doing a
14862 window-based redisplay. The space has the same face as
14863 IT->face_id. Value is non-zero if a space was added.
14865 This function is called to make sure that there is always one glyph
14866 at the end of a glyph row that the cursor can be set on under
14867 window-systems. (If there weren't such a glyph we would not know
14868 how wide and tall a box cursor should be displayed).
14870 At the same time this space let's a nicely handle clearing to the
14871 end of the line if the row ends in italic text. */
14874 append_space_for_newline (it
, default_face_p
)
14876 int default_face_p
;
14878 if (FRAME_WINDOW_P (it
->f
))
14880 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14882 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14883 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14885 /* Save some values that must not be changed.
14886 Must save IT->c and IT->len because otherwise
14887 ITERATOR_AT_END_P wouldn't work anymore after
14888 append_space_for_newline has been called. */
14889 enum display_element_type saved_what
= it
->what
;
14890 int saved_c
= it
->c
, saved_len
= it
->len
;
14891 int saved_x
= it
->current_x
;
14892 int saved_face_id
= it
->face_id
;
14893 struct text_pos saved_pos
;
14894 Lisp_Object saved_object
;
14897 saved_object
= it
->object
;
14898 saved_pos
= it
->position
;
14900 it
->what
= IT_CHARACTER
;
14901 bzero (&it
->position
, sizeof it
->position
);
14902 it
->object
= make_number (0);
14906 if (default_face_p
)
14907 it
->face_id
= DEFAULT_FACE_ID
;
14908 else if (it
->face_before_selective_p
)
14909 it
->face_id
= it
->saved_face_id
;
14910 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14911 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14913 PRODUCE_GLYPHS (it
);
14915 it
->override_ascent
= -1;
14916 it
->constrain_row_ascent_descent_p
= 0;
14917 it
->current_x
= saved_x
;
14918 it
->object
= saved_object
;
14919 it
->position
= saved_pos
;
14920 it
->what
= saved_what
;
14921 it
->face_id
= saved_face_id
;
14922 it
->len
= saved_len
;
14932 /* Extend the face of the last glyph in the text area of IT->glyph_row
14933 to the end of the display line. Called from display_line.
14934 If the glyph row is empty, add a space glyph to it so that we
14935 know the face to draw. Set the glyph row flag fill_line_p. */
14938 extend_face_to_end_of_line (it
)
14942 struct frame
*f
= it
->f
;
14944 /* If line is already filled, do nothing. */
14945 if (it
->current_x
>= it
->last_visible_x
)
14948 /* Face extension extends the background and box of IT->face_id
14949 to the end of the line. If the background equals the background
14950 of the frame, we don't have to do anything. */
14951 if (it
->face_before_selective_p
)
14952 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14954 face
= FACE_FROM_ID (f
, it
->face_id
);
14956 if (FRAME_WINDOW_P (f
)
14957 && face
->box
== FACE_NO_BOX
14958 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14962 /* Set the glyph row flag indicating that the face of the last glyph
14963 in the text area has to be drawn to the end of the text area. */
14964 it
->glyph_row
->fill_line_p
= 1;
14966 /* If current character of IT is not ASCII, make sure we have the
14967 ASCII face. This will be automatically undone the next time
14968 get_next_display_element returns a multibyte character. Note
14969 that the character will always be single byte in unibyte text. */
14970 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14972 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14975 if (FRAME_WINDOW_P (f
))
14977 /* If the row is empty, add a space with the current face of IT,
14978 so that we know which face to draw. */
14979 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14981 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14982 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14983 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14988 /* Save some values that must not be changed. */
14989 int saved_x
= it
->current_x
;
14990 struct text_pos saved_pos
;
14991 Lisp_Object saved_object
;
14992 enum display_element_type saved_what
= it
->what
;
14993 int saved_face_id
= it
->face_id
;
14995 saved_object
= it
->object
;
14996 saved_pos
= it
->position
;
14998 it
->what
= IT_CHARACTER
;
14999 bzero (&it
->position
, sizeof it
->position
);
15000 it
->object
= make_number (0);
15003 it
->face_id
= face
->id
;
15005 PRODUCE_GLYPHS (it
);
15007 while (it
->current_x
<= it
->last_visible_x
)
15008 PRODUCE_GLYPHS (it
);
15010 /* Don't count these blanks really. It would let us insert a left
15011 truncation glyph below and make us set the cursor on them, maybe. */
15012 it
->current_x
= saved_x
;
15013 it
->object
= saved_object
;
15014 it
->position
= saved_pos
;
15015 it
->what
= saved_what
;
15016 it
->face_id
= saved_face_id
;
15021 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15022 trailing whitespace. */
15025 trailing_whitespace_p (charpos
)
15028 int bytepos
= CHAR_TO_BYTE (charpos
);
15031 while (bytepos
< ZV_BYTE
15032 && (c
= FETCH_CHAR (bytepos
),
15033 c
== ' ' || c
== '\t'))
15036 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15038 if (bytepos
!= PT_BYTE
)
15045 /* Highlight trailing whitespace, if any, in ROW. */
15048 highlight_trailing_whitespace (f
, row
)
15050 struct glyph_row
*row
;
15052 int used
= row
->used
[TEXT_AREA
];
15056 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15057 struct glyph
*glyph
= start
+ used
- 1;
15059 /* Skip over glyphs inserted to display the cursor at the
15060 end of a line, for extending the face of the last glyph
15061 to the end of the line on terminals, and for truncation
15062 and continuation glyphs. */
15063 while (glyph
>= start
15064 && glyph
->type
== CHAR_GLYPH
15065 && INTEGERP (glyph
->object
))
15068 /* If last glyph is a space or stretch, and it's trailing
15069 whitespace, set the face of all trailing whitespace glyphs in
15070 IT->glyph_row to `trailing-whitespace'. */
15072 && BUFFERP (glyph
->object
)
15073 && (glyph
->type
== STRETCH_GLYPH
15074 || (glyph
->type
== CHAR_GLYPH
15075 && glyph
->u
.ch
== ' '))
15076 && trailing_whitespace_p (glyph
->charpos
))
15078 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15082 while (glyph
>= start
15083 && BUFFERP (glyph
->object
)
15084 && (glyph
->type
== STRETCH_GLYPH
15085 || (glyph
->type
== CHAR_GLYPH
15086 && glyph
->u
.ch
== ' ')))
15087 (glyph
--)->face_id
= face_id
;
15093 /* Value is non-zero if glyph row ROW in window W should be
15094 used to hold the cursor. */
15097 cursor_row_p (w
, row
)
15099 struct glyph_row
*row
;
15101 int cursor_row_p
= 1;
15103 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15105 /* If the row ends with a newline from a string, we don't want
15106 the cursor there, but we still want it at the start of the
15107 string if the string starts in this row.
15108 If the row is continued it doesn't end in a newline. */
15109 if (CHARPOS (row
->end
.string_pos
) >= 0)
15110 cursor_row_p
= (row
->continued_p
15111 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15112 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15114 /* If the row ends in middle of a real character,
15115 and the line is continued, we want the cursor here.
15116 That's because MATRIX_ROW_END_CHARPOS would equal
15117 PT if PT is before the character. */
15118 if (!row
->ends_in_ellipsis_p
)
15119 cursor_row_p
= row
->continued_p
;
15121 /* If the row ends in an ellipsis, then
15122 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15123 We want that position to be displayed after the ellipsis. */
15126 /* If the row ends at ZV, display the cursor at the end of that
15127 row instead of at the start of the row below. */
15128 else if (row
->ends_at_zv_p
)
15134 return cursor_row_p
;
15138 /* Construct the glyph row IT->glyph_row in the desired matrix of
15139 IT->w from text at the current position of IT. See dispextern.h
15140 for an overview of struct it. Value is non-zero if
15141 IT->glyph_row displays text, as opposed to a line displaying ZV
15148 struct glyph_row
*row
= it
->glyph_row
;
15149 Lisp_Object overlay_arrow_string
;
15151 /* We always start displaying at hpos zero even if hscrolled. */
15152 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15154 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15155 >= it
->w
->desired_matrix
->nrows
)
15157 it
->w
->nrows_scale_factor
++;
15158 fonts_changed_p
= 1;
15162 /* Is IT->w showing the region? */
15163 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15165 /* Clear the result glyph row and enable it. */
15166 prepare_desired_row (row
);
15168 row
->y
= it
->current_y
;
15169 row
->start
= it
->start
;
15170 row
->continuation_lines_width
= it
->continuation_lines_width
;
15171 row
->displays_text_p
= 1;
15172 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15173 it
->starts_in_middle_of_char_p
= 0;
15175 /* Arrange the overlays nicely for our purposes. Usually, we call
15176 display_line on only one line at a time, in which case this
15177 can't really hurt too much, or we call it on lines which appear
15178 one after another in the buffer, in which case all calls to
15179 recenter_overlay_lists but the first will be pretty cheap. */
15180 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15182 /* Move over display elements that are not visible because we are
15183 hscrolled. This may stop at an x-position < IT->first_visible_x
15184 if the first glyph is partially visible or if we hit a line end. */
15185 if (it
->current_x
< it
->first_visible_x
)
15187 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15188 MOVE_TO_POS
| MOVE_TO_X
);
15191 /* Get the initial row height. This is either the height of the
15192 text hscrolled, if there is any, or zero. */
15193 row
->ascent
= it
->max_ascent
;
15194 row
->height
= it
->max_ascent
+ it
->max_descent
;
15195 row
->phys_ascent
= it
->max_phys_ascent
;
15196 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15197 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15199 /* Loop generating characters. The loop is left with IT on the next
15200 character to display. */
15203 int n_glyphs_before
, hpos_before
, x_before
;
15205 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15207 /* Retrieve the next thing to display. Value is zero if end of
15209 if (!get_next_display_element (it
))
15211 /* Maybe add a space at the end of this line that is used to
15212 display the cursor there under X. Set the charpos of the
15213 first glyph of blank lines not corresponding to any text
15215 #ifdef HAVE_WINDOW_SYSTEM
15216 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15217 row
->exact_window_width_line_p
= 1;
15219 #endif /* HAVE_WINDOW_SYSTEM */
15220 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15221 || row
->used
[TEXT_AREA
] == 0)
15223 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15224 row
->displays_text_p
= 0;
15226 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15227 && (!MINI_WINDOW_P (it
->w
)
15228 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15229 row
->indicate_empty_line_p
= 1;
15232 it
->continuation_lines_width
= 0;
15233 row
->ends_at_zv_p
= 1;
15237 /* Now, get the metrics of what we want to display. This also
15238 generates glyphs in `row' (which is IT->glyph_row). */
15239 n_glyphs_before
= row
->used
[TEXT_AREA
];
15242 /* Remember the line height so far in case the next element doesn't
15243 fit on the line. */
15244 if (!it
->truncate_lines_p
)
15246 ascent
= it
->max_ascent
;
15247 descent
= it
->max_descent
;
15248 phys_ascent
= it
->max_phys_ascent
;
15249 phys_descent
= it
->max_phys_descent
;
15252 PRODUCE_GLYPHS (it
);
15254 /* If this display element was in marginal areas, continue with
15256 if (it
->area
!= TEXT_AREA
)
15258 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15259 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15260 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15261 row
->phys_height
= max (row
->phys_height
,
15262 it
->max_phys_ascent
+ it
->max_phys_descent
);
15263 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15264 it
->max_extra_line_spacing
);
15265 set_iterator_to_next (it
, 1);
15269 /* Does the display element fit on the line? If we truncate
15270 lines, we should draw past the right edge of the window. If
15271 we don't truncate, we want to stop so that we can display the
15272 continuation glyph before the right margin. If lines are
15273 continued, there are two possible strategies for characters
15274 resulting in more than 1 glyph (e.g. tabs): Display as many
15275 glyphs as possible in this line and leave the rest for the
15276 continuation line, or display the whole element in the next
15277 line. Original redisplay did the former, so we do it also. */
15278 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15279 hpos_before
= it
->hpos
;
15282 if (/* Not a newline. */
15284 /* Glyphs produced fit entirely in the line. */
15285 && it
->current_x
< it
->last_visible_x
)
15287 it
->hpos
+= nglyphs
;
15288 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15289 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15290 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15291 row
->phys_height
= max (row
->phys_height
,
15292 it
->max_phys_ascent
+ it
->max_phys_descent
);
15293 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15294 it
->max_extra_line_spacing
);
15295 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15296 row
->x
= x
- it
->first_visible_x
;
15301 struct glyph
*glyph
;
15303 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15305 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15306 new_x
= x
+ glyph
->pixel_width
;
15308 if (/* Lines are continued. */
15309 !it
->truncate_lines_p
15310 && (/* Glyph doesn't fit on the line. */
15311 new_x
> it
->last_visible_x
15312 /* Or it fits exactly on a window system frame. */
15313 || (new_x
== it
->last_visible_x
15314 && FRAME_WINDOW_P (it
->f
))))
15316 /* End of a continued line. */
15319 || (new_x
== it
->last_visible_x
15320 && FRAME_WINDOW_P (it
->f
)))
15322 /* Current glyph is the only one on the line or
15323 fits exactly on the line. We must continue
15324 the line because we can't draw the cursor
15325 after the glyph. */
15326 row
->continued_p
= 1;
15327 it
->current_x
= new_x
;
15328 it
->continuation_lines_width
+= new_x
;
15330 if (i
== nglyphs
- 1)
15332 set_iterator_to_next (it
, 1);
15333 #ifdef HAVE_WINDOW_SYSTEM
15334 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15336 if (!get_next_display_element (it
))
15338 row
->exact_window_width_line_p
= 1;
15339 it
->continuation_lines_width
= 0;
15340 row
->continued_p
= 0;
15341 row
->ends_at_zv_p
= 1;
15343 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15345 row
->continued_p
= 0;
15346 row
->exact_window_width_line_p
= 1;
15349 #endif /* HAVE_WINDOW_SYSTEM */
15352 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15353 && !FRAME_WINDOW_P (it
->f
))
15355 /* A padding glyph that doesn't fit on this line.
15356 This means the whole character doesn't fit
15358 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15360 /* Fill the rest of the row with continuation
15361 glyphs like in 20.x. */
15362 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15363 < row
->glyphs
[1 + TEXT_AREA
])
15364 produce_special_glyphs (it
, IT_CONTINUATION
);
15366 row
->continued_p
= 1;
15367 it
->current_x
= x_before
;
15368 it
->continuation_lines_width
+= x_before
;
15370 /* Restore the height to what it was before the
15371 element not fitting on the line. */
15372 it
->max_ascent
= ascent
;
15373 it
->max_descent
= descent
;
15374 it
->max_phys_ascent
= phys_ascent
;
15375 it
->max_phys_descent
= phys_descent
;
15377 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15379 /* A TAB that extends past the right edge of the
15380 window. This produces a single glyph on
15381 window system frames. We leave the glyph in
15382 this row and let it fill the row, but don't
15383 consume the TAB. */
15384 it
->continuation_lines_width
+= it
->last_visible_x
;
15385 row
->ends_in_middle_of_char_p
= 1;
15386 row
->continued_p
= 1;
15387 glyph
->pixel_width
= it
->last_visible_x
- x
;
15388 it
->starts_in_middle_of_char_p
= 1;
15392 /* Something other than a TAB that draws past
15393 the right edge of the window. Restore
15394 positions to values before the element. */
15395 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15397 /* Display continuation glyphs. */
15398 if (!FRAME_WINDOW_P (it
->f
))
15399 produce_special_glyphs (it
, IT_CONTINUATION
);
15400 row
->continued_p
= 1;
15402 it
->continuation_lines_width
+= x
;
15404 if (nglyphs
> 1 && i
> 0)
15406 row
->ends_in_middle_of_char_p
= 1;
15407 it
->starts_in_middle_of_char_p
= 1;
15410 /* Restore the height to what it was before the
15411 element not fitting on the line. */
15412 it
->max_ascent
= ascent
;
15413 it
->max_descent
= descent
;
15414 it
->max_phys_ascent
= phys_ascent
;
15415 it
->max_phys_descent
= phys_descent
;
15420 else if (new_x
> it
->first_visible_x
)
15422 /* Increment number of glyphs actually displayed. */
15425 if (x
< it
->first_visible_x
)
15426 /* Glyph is partially visible, i.e. row starts at
15427 negative X position. */
15428 row
->x
= x
- it
->first_visible_x
;
15432 /* Glyph is completely off the left margin of the
15433 window. This should not happen because of the
15434 move_it_in_display_line at the start of this
15435 function, unless the text display area of the
15436 window is empty. */
15437 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15441 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15442 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15443 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15444 row
->phys_height
= max (row
->phys_height
,
15445 it
->max_phys_ascent
+ it
->max_phys_descent
);
15446 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15447 it
->max_extra_line_spacing
);
15449 /* End of this display line if row is continued. */
15450 if (row
->continued_p
|| row
->ends_at_zv_p
)
15455 /* Is this a line end? If yes, we're also done, after making
15456 sure that a non-default face is extended up to the right
15457 margin of the window. */
15458 if (ITERATOR_AT_END_OF_LINE_P (it
))
15460 int used_before
= row
->used
[TEXT_AREA
];
15462 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15464 #ifdef HAVE_WINDOW_SYSTEM
15465 /* Add a space at the end of the line that is used to
15466 display the cursor there. */
15467 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15468 append_space_for_newline (it
, 0);
15469 #endif /* HAVE_WINDOW_SYSTEM */
15471 /* Extend the face to the end of the line. */
15472 extend_face_to_end_of_line (it
);
15474 /* Make sure we have the position. */
15475 if (used_before
== 0)
15476 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15478 /* Consume the line end. This skips over invisible lines. */
15479 set_iterator_to_next (it
, 1);
15480 it
->continuation_lines_width
= 0;
15484 /* Proceed with next display element. Note that this skips
15485 over lines invisible because of selective display. */
15486 set_iterator_to_next (it
, 1);
15488 /* If we truncate lines, we are done when the last displayed
15489 glyphs reach past the right margin of the window. */
15490 if (it
->truncate_lines_p
15491 && (FRAME_WINDOW_P (it
->f
)
15492 ? (it
->current_x
>= it
->last_visible_x
)
15493 : (it
->current_x
> it
->last_visible_x
)))
15495 /* Maybe add truncation glyphs. */
15496 if (!FRAME_WINDOW_P (it
->f
))
15500 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15501 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15504 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15506 row
->used
[TEXT_AREA
] = i
;
15507 produce_special_glyphs (it
, IT_TRUNCATION
);
15510 #ifdef HAVE_WINDOW_SYSTEM
15513 /* Don't truncate if we can overflow newline into fringe. */
15514 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15516 if (!get_next_display_element (it
))
15518 it
->continuation_lines_width
= 0;
15519 row
->ends_at_zv_p
= 1;
15520 row
->exact_window_width_line_p
= 1;
15523 if (ITERATOR_AT_END_OF_LINE_P (it
))
15525 row
->exact_window_width_line_p
= 1;
15526 goto at_end_of_line
;
15530 #endif /* HAVE_WINDOW_SYSTEM */
15532 row
->truncated_on_right_p
= 1;
15533 it
->continuation_lines_width
= 0;
15534 reseat_at_next_visible_line_start (it
, 0);
15535 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15536 it
->hpos
= hpos_before
;
15537 it
->current_x
= x_before
;
15542 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15543 at the left window margin. */
15544 if (it
->first_visible_x
15545 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15547 if (!FRAME_WINDOW_P (it
->f
))
15548 insert_left_trunc_glyphs (it
);
15549 row
->truncated_on_left_p
= 1;
15552 /* If the start of this line is the overlay arrow-position, then
15553 mark this glyph row as the one containing the overlay arrow.
15554 This is clearly a mess with variable size fonts. It would be
15555 better to let it be displayed like cursors under X. */
15556 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15557 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15558 !NILP (overlay_arrow_string
)))
15560 /* Overlay arrow in window redisplay is a fringe bitmap. */
15561 if (STRINGP (overlay_arrow_string
))
15563 struct glyph_row
*arrow_row
15564 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15565 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15566 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15567 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15568 struct glyph
*p2
, *end
;
15570 /* Copy the arrow glyphs. */
15571 while (glyph
< arrow_end
)
15574 /* Throw away padding glyphs. */
15576 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15577 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15583 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15588 xassert (INTEGERP (overlay_arrow_string
));
15589 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15591 overlay_arrow_seen
= 1;
15594 /* Compute pixel dimensions of this line. */
15595 compute_line_metrics (it
);
15597 /* Remember the position at which this line ends. */
15598 row
->end
= it
->current
;
15600 /* Record whether this row ends inside an ellipsis. */
15601 row
->ends_in_ellipsis_p
15602 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15603 && it
->ellipsis_p
);
15605 /* Save fringe bitmaps in this row. */
15606 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15607 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15608 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15609 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15611 it
->left_user_fringe_bitmap
= 0;
15612 it
->left_user_fringe_face_id
= 0;
15613 it
->right_user_fringe_bitmap
= 0;
15614 it
->right_user_fringe_face_id
= 0;
15616 /* Maybe set the cursor. */
15617 if (it
->w
->cursor
.vpos
< 0
15618 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15619 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15620 && cursor_row_p (it
->w
, row
))
15621 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15623 /* Highlight trailing whitespace. */
15624 if (!NILP (Vshow_trailing_whitespace
))
15625 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15627 /* Prepare for the next line. This line starts horizontally at (X
15628 HPOS) = (0 0). Vertical positions are incremented. As a
15629 convenience for the caller, IT->glyph_row is set to the next
15631 it
->current_x
= it
->hpos
= 0;
15632 it
->current_y
+= row
->height
;
15635 it
->start
= it
->current
;
15636 return row
->displays_text_p
;
15641 /***********************************************************************
15643 ***********************************************************************/
15645 /* Redisplay the menu bar in the frame for window W.
15647 The menu bar of X frames that don't have X toolkit support is
15648 displayed in a special window W->frame->menu_bar_window.
15650 The menu bar of terminal frames is treated specially as far as
15651 glyph matrices are concerned. Menu bar lines are not part of
15652 windows, so the update is done directly on the frame matrix rows
15653 for the menu bar. */
15656 display_menu_bar (w
)
15659 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15664 /* Don't do all this for graphical frames. */
15666 if (!NILP (Vwindow_system
))
15669 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15674 if (FRAME_MAC_P (f
))
15678 #ifdef USE_X_TOOLKIT
15679 xassert (!FRAME_WINDOW_P (f
));
15680 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15681 it
.first_visible_x
= 0;
15682 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15683 #else /* not USE_X_TOOLKIT */
15684 if (FRAME_WINDOW_P (f
))
15686 /* Menu bar lines are displayed in the desired matrix of the
15687 dummy window menu_bar_window. */
15688 struct window
*menu_w
;
15689 xassert (WINDOWP (f
->menu_bar_window
));
15690 menu_w
= XWINDOW (f
->menu_bar_window
);
15691 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15693 it
.first_visible_x
= 0;
15694 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15698 /* This is a TTY frame, i.e. character hpos/vpos are used as
15700 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15702 it
.first_visible_x
= 0;
15703 it
.last_visible_x
= FRAME_COLS (f
);
15705 #endif /* not USE_X_TOOLKIT */
15707 if (! mode_line_inverse_video
)
15708 /* Force the menu-bar to be displayed in the default face. */
15709 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15711 /* Clear all rows of the menu bar. */
15712 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15714 struct glyph_row
*row
= it
.glyph_row
+ i
;
15715 clear_glyph_row (row
);
15716 row
->enabled_p
= 1;
15717 row
->full_width_p
= 1;
15720 /* Display all items of the menu bar. */
15721 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15722 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15724 Lisp_Object string
;
15726 /* Stop at nil string. */
15727 string
= AREF (items
, i
+ 1);
15731 /* Remember where item was displayed. */
15732 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15734 /* Display the item, pad with one space. */
15735 if (it
.current_x
< it
.last_visible_x
)
15736 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15737 SCHARS (string
) + 1, 0, 0, -1);
15740 /* Fill out the line with spaces. */
15741 if (it
.current_x
< it
.last_visible_x
)
15742 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15744 /* Compute the total height of the lines. */
15745 compute_line_metrics (&it
);
15750 /***********************************************************************
15752 ***********************************************************************/
15754 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15755 FORCE is non-zero, redisplay mode lines unconditionally.
15756 Otherwise, redisplay only mode lines that are garbaged. Value is
15757 the number of windows whose mode lines were redisplayed. */
15760 redisplay_mode_lines (window
, force
)
15761 Lisp_Object window
;
15766 while (!NILP (window
))
15768 struct window
*w
= XWINDOW (window
);
15770 if (WINDOWP (w
->hchild
))
15771 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15772 else if (WINDOWP (w
->vchild
))
15773 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15775 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15776 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15778 struct text_pos lpoint
;
15779 struct buffer
*old
= current_buffer
;
15781 /* Set the window's buffer for the mode line display. */
15782 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15783 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15785 /* Point refers normally to the selected window. For any
15786 other window, set up appropriate value. */
15787 if (!EQ (window
, selected_window
))
15789 struct text_pos pt
;
15791 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15792 if (CHARPOS (pt
) < BEGV
)
15793 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15794 else if (CHARPOS (pt
) > (ZV
- 1))
15795 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15797 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15800 /* Display mode lines. */
15801 clear_glyph_matrix (w
->desired_matrix
);
15802 if (display_mode_lines (w
))
15805 w
->must_be_updated_p
= 1;
15808 /* Restore old settings. */
15809 set_buffer_internal_1 (old
);
15810 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15820 /* Display the mode and/or top line of window W. Value is the number
15821 of mode lines displayed. */
15824 display_mode_lines (w
)
15827 Lisp_Object old_selected_window
, old_selected_frame
;
15830 old_selected_frame
= selected_frame
;
15831 selected_frame
= w
->frame
;
15832 old_selected_window
= selected_window
;
15833 XSETWINDOW (selected_window
, w
);
15835 /* These will be set while the mode line specs are processed. */
15836 line_number_displayed
= 0;
15837 w
->column_number_displayed
= Qnil
;
15839 if (WINDOW_WANTS_MODELINE_P (w
))
15841 struct window
*sel_w
= XWINDOW (old_selected_window
);
15843 /* Select mode line face based on the real selected window. */
15844 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15845 current_buffer
->mode_line_format
);
15849 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15851 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15852 current_buffer
->header_line_format
);
15856 selected_frame
= old_selected_frame
;
15857 selected_window
= old_selected_window
;
15862 /* Display mode or top line of window W. FACE_ID specifies which line
15863 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15864 FORMAT is the mode line format to display. Value is the pixel
15865 height of the mode line displayed. */
15868 display_mode_line (w
, face_id
, format
)
15870 enum face_id face_id
;
15871 Lisp_Object format
;
15875 int count
= SPECPDL_INDEX ();
15877 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15878 prepare_desired_row (it
.glyph_row
);
15880 it
.glyph_row
->mode_line_p
= 1;
15882 if (! mode_line_inverse_video
)
15883 /* Force the mode-line to be displayed in the default face. */
15884 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15886 record_unwind_protect (unwind_format_mode_line
,
15887 format_mode_line_unwind_data (NULL
));
15889 mode_line_target
= MODE_LINE_DISPLAY
;
15891 /* Temporarily make frame's keyboard the current kboard so that
15892 kboard-local variables in the mode_line_format will get the right
15894 push_frame_kboard (it
.f
);
15895 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15896 pop_frame_kboard ();
15898 unbind_to (count
, Qnil
);
15900 /* Fill up with spaces. */
15901 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15903 compute_line_metrics (&it
);
15904 it
.glyph_row
->full_width_p
= 1;
15905 it
.glyph_row
->continued_p
= 0;
15906 it
.glyph_row
->truncated_on_left_p
= 0;
15907 it
.glyph_row
->truncated_on_right_p
= 0;
15909 /* Make a 3D mode-line have a shadow at its right end. */
15910 face
= FACE_FROM_ID (it
.f
, face_id
);
15911 extend_face_to_end_of_line (&it
);
15912 if (face
->box
!= FACE_NO_BOX
)
15914 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15915 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15916 last
->right_box_line_p
= 1;
15919 return it
.glyph_row
->height
;
15922 /* Contribute ELT to the mode line for window IT->w. How it
15923 translates into text depends on its data type.
15925 IT describes the display environment in which we display, as usual.
15927 DEPTH is the depth in recursion. It is used to prevent
15928 infinite recursion here.
15930 FIELD_WIDTH is the number of characters the display of ELT should
15931 occupy in the mode line, and PRECISION is the maximum number of
15932 characters to display from ELT's representation. See
15933 display_string for details.
15935 Returns the hpos of the end of the text generated by ELT.
15937 PROPS is a property list to add to any string we encounter.
15939 If RISKY is nonzero, remove (disregard) any properties in any string
15940 we encounter, and ignore :eval and :propertize.
15942 The global variable `mode_line_target' determines whether the
15943 output is passed to `store_mode_line_noprop',
15944 `store_mode_line_string', or `display_string'. */
15947 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15950 int field_width
, precision
;
15951 Lisp_Object elt
, props
;
15954 int n
= 0, field
, prec
;
15959 elt
= build_string ("*too-deep*");
15963 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15967 /* A string: output it and check for %-constructs within it. */
15971 if (!NILP (props
) || risky
)
15973 Lisp_Object oprops
, aelt
;
15974 oprops
= Ftext_properties_at (make_number (0), elt
);
15976 /* If the starting string's properties are not what
15977 we want, translate the string. Also, if the string
15978 is risky, do that anyway. */
15980 if (NILP (Fequal (props
, oprops
)) || risky
)
15982 /* If the starting string has properties,
15983 merge the specified ones onto the existing ones. */
15984 if (! NILP (oprops
) && !risky
)
15988 oprops
= Fcopy_sequence (oprops
);
15990 while (CONSP (tem
))
15992 oprops
= Fplist_put (oprops
, XCAR (tem
),
15993 XCAR (XCDR (tem
)));
15994 tem
= XCDR (XCDR (tem
));
15999 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
16000 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
16002 mode_line_proptrans_alist
16003 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
16010 elt
= Fcopy_sequence (elt
);
16011 Fset_text_properties (make_number (0), Flength (elt
),
16013 /* Add this item to mode_line_proptrans_alist. */
16014 mode_line_proptrans_alist
16015 = Fcons (Fcons (elt
, props
),
16016 mode_line_proptrans_alist
);
16017 /* Truncate mode_line_proptrans_alist
16018 to at most 50 elements. */
16019 tem
= Fnthcdr (make_number (50),
16020 mode_line_proptrans_alist
);
16022 XSETCDR (tem
, Qnil
);
16031 prec
= precision
- n
;
16032 switch (mode_line_target
)
16034 case MODE_LINE_NOPROP
:
16035 case MODE_LINE_TITLE
:
16036 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16038 case MODE_LINE_STRING
:
16039 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16041 case MODE_LINE_DISPLAY
:
16042 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16043 0, prec
, 0, STRING_MULTIBYTE (elt
));
16050 /* Handle the non-literal case. */
16052 while ((precision
<= 0 || n
< precision
)
16053 && SREF (elt
, offset
) != 0
16054 && (mode_line_target
!= MODE_LINE_DISPLAY
16055 || it
->current_x
< it
->last_visible_x
))
16057 int last_offset
= offset
;
16059 /* Advance to end of string or next format specifier. */
16060 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16063 if (offset
- 1 != last_offset
)
16065 int nchars
, nbytes
;
16067 /* Output to end of string or up to '%'. Field width
16068 is length of string. Don't output more than
16069 PRECISION allows us. */
16072 prec
= c_string_width (SDATA (elt
) + last_offset
,
16073 offset
- last_offset
, precision
- n
,
16076 switch (mode_line_target
)
16078 case MODE_LINE_NOPROP
:
16079 case MODE_LINE_TITLE
:
16080 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16082 case MODE_LINE_STRING
:
16084 int bytepos
= last_offset
;
16085 int charpos
= string_byte_to_char (elt
, bytepos
);
16086 int endpos
= (precision
<= 0
16087 ? string_byte_to_char (elt
, offset
)
16088 : charpos
+ nchars
);
16090 n
+= store_mode_line_string (NULL
,
16091 Fsubstring (elt
, make_number (charpos
),
16092 make_number (endpos
)),
16096 case MODE_LINE_DISPLAY
:
16098 int bytepos
= last_offset
;
16099 int charpos
= string_byte_to_char (elt
, bytepos
);
16100 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16102 STRING_MULTIBYTE (elt
));
16107 else /* c == '%' */
16109 int percent_position
= offset
;
16111 /* Get the specified minimum width. Zero means
16114 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16115 field
= field
* 10 + c
- '0';
16117 /* Don't pad beyond the total padding allowed. */
16118 if (field_width
- n
> 0 && field
> field_width
- n
)
16119 field
= field_width
- n
;
16121 /* Note that either PRECISION <= 0 or N < PRECISION. */
16122 prec
= precision
- n
;
16125 n
+= display_mode_element (it
, depth
, field
, prec
,
16126 Vglobal_mode_string
, props
,
16131 int bytepos
, charpos
;
16132 unsigned char *spec
;
16134 bytepos
= percent_position
;
16135 charpos
= (STRING_MULTIBYTE (elt
)
16136 ? string_byte_to_char (elt
, bytepos
)
16140 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16142 switch (mode_line_target
)
16144 case MODE_LINE_NOPROP
:
16145 case MODE_LINE_TITLE
:
16146 n
+= store_mode_line_noprop (spec
, field
, prec
);
16148 case MODE_LINE_STRING
:
16150 int len
= strlen (spec
);
16151 Lisp_Object tem
= make_string (spec
, len
);
16152 props
= Ftext_properties_at (make_number (charpos
), elt
);
16153 /* Should only keep face property in props */
16154 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16157 case MODE_LINE_DISPLAY
:
16159 int nglyphs_before
, nwritten
;
16161 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16162 nwritten
= display_string (spec
, Qnil
, elt
,
16167 /* Assign to the glyphs written above the
16168 string where the `%x' came from, position
16172 struct glyph
*glyph
16173 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16177 for (i
= 0; i
< nwritten
; ++i
)
16179 glyph
[i
].object
= elt
;
16180 glyph
[i
].charpos
= charpos
;
16197 /* A symbol: process the value of the symbol recursively
16198 as if it appeared here directly. Avoid error if symbol void.
16199 Special case: if value of symbol is a string, output the string
16202 register Lisp_Object tem
;
16204 /* If the variable is not marked as risky to set
16205 then its contents are risky to use. */
16206 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16209 tem
= Fboundp (elt
);
16212 tem
= Fsymbol_value (elt
);
16213 /* If value is a string, output that string literally:
16214 don't check for % within it. */
16218 if (!EQ (tem
, elt
))
16220 /* Give up right away for nil or t. */
16230 register Lisp_Object car
, tem
;
16232 /* A cons cell: five distinct cases.
16233 If first element is :eval or :propertize, do something special.
16234 If first element is a string or a cons, process all the elements
16235 and effectively concatenate them.
16236 If first element is a negative number, truncate displaying cdr to
16237 at most that many characters. If positive, pad (with spaces)
16238 to at least that many characters.
16239 If first element is a symbol, process the cadr or caddr recursively
16240 according to whether the symbol's value is non-nil or nil. */
16242 if (EQ (car
, QCeval
))
16244 /* An element of the form (:eval FORM) means evaluate FORM
16245 and use the result as mode line elements. */
16250 if (CONSP (XCDR (elt
)))
16253 spec
= safe_eval (XCAR (XCDR (elt
)));
16254 n
+= display_mode_element (it
, depth
, field_width
- n
,
16255 precision
- n
, spec
, props
,
16259 else if (EQ (car
, QCpropertize
))
16261 /* An element of the form (:propertize ELT PROPS...)
16262 means display ELT but applying properties PROPS. */
16267 if (CONSP (XCDR (elt
)))
16268 n
+= display_mode_element (it
, depth
, field_width
- n
,
16269 precision
- n
, XCAR (XCDR (elt
)),
16270 XCDR (XCDR (elt
)), risky
);
16272 else if (SYMBOLP (car
))
16274 tem
= Fboundp (car
);
16278 /* elt is now the cdr, and we know it is a cons cell.
16279 Use its car if CAR has a non-nil value. */
16282 tem
= Fsymbol_value (car
);
16289 /* Symbol's value is nil (or symbol is unbound)
16290 Get the cddr of the original list
16291 and if possible find the caddr and use that. */
16295 else if (!CONSP (elt
))
16300 else if (INTEGERP (car
))
16302 register int lim
= XINT (car
);
16306 /* Negative int means reduce maximum width. */
16307 if (precision
<= 0)
16310 precision
= min (precision
, -lim
);
16314 /* Padding specified. Don't let it be more than
16315 current maximum. */
16317 lim
= min (precision
, lim
);
16319 /* If that's more padding than already wanted, queue it.
16320 But don't reduce padding already specified even if
16321 that is beyond the current truncation point. */
16322 field_width
= max (lim
, field_width
);
16326 else if (STRINGP (car
) || CONSP (car
))
16328 register int limit
= 50;
16329 /* Limit is to protect against circular lists. */
16332 && (precision
<= 0 || n
< precision
))
16334 n
+= display_mode_element (it
, depth
,
16335 /* Do padding only after the last
16336 element in the list. */
16337 (! CONSP (XCDR (elt
))
16340 precision
- n
, XCAR (elt
),
16350 elt
= build_string ("*invalid*");
16354 /* Pad to FIELD_WIDTH. */
16355 if (field_width
> 0 && n
< field_width
)
16357 switch (mode_line_target
)
16359 case MODE_LINE_NOPROP
:
16360 case MODE_LINE_TITLE
:
16361 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16363 case MODE_LINE_STRING
:
16364 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16366 case MODE_LINE_DISPLAY
:
16367 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16376 /* Store a mode-line string element in mode_line_string_list.
16378 If STRING is non-null, display that C string. Otherwise, the Lisp
16379 string LISP_STRING is displayed.
16381 FIELD_WIDTH is the minimum number of output glyphs to produce.
16382 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16383 with spaces. FIELD_WIDTH <= 0 means don't pad.
16385 PRECISION is the maximum number of characters to output from
16386 STRING. PRECISION <= 0 means don't truncate the string.
16388 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16389 properties to the string.
16391 PROPS are the properties to add to the string.
16392 The mode_line_string_face face property is always added to the string.
16396 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16398 Lisp_Object lisp_string
;
16407 if (string
!= NULL
)
16409 len
= strlen (string
);
16410 if (precision
> 0 && len
> precision
)
16412 lisp_string
= make_string (string
, len
);
16414 props
= mode_line_string_face_prop
;
16415 else if (!NILP (mode_line_string_face
))
16417 Lisp_Object face
= Fplist_get (props
, Qface
);
16418 props
= Fcopy_sequence (props
);
16420 face
= mode_line_string_face
;
16422 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16423 props
= Fplist_put (props
, Qface
, face
);
16425 Fadd_text_properties (make_number (0), make_number (len
),
16426 props
, lisp_string
);
16430 len
= XFASTINT (Flength (lisp_string
));
16431 if (precision
> 0 && len
> precision
)
16434 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16437 if (!NILP (mode_line_string_face
))
16441 props
= Ftext_properties_at (make_number (0), lisp_string
);
16442 face
= Fplist_get (props
, Qface
);
16444 face
= mode_line_string_face
;
16446 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16447 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16449 lisp_string
= Fcopy_sequence (lisp_string
);
16452 Fadd_text_properties (make_number (0), make_number (len
),
16453 props
, lisp_string
);
16458 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16462 if (field_width
> len
)
16464 field_width
-= len
;
16465 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16467 Fadd_text_properties (make_number (0), make_number (field_width
),
16468 props
, lisp_string
);
16469 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16477 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16479 doc
: /* Format a string out of a mode line format specification.
16480 First arg FORMAT specifies the mode line format (see `mode-line-format'
16481 for details) to use.
16483 Optional second arg FACE specifies the face property to put
16484 on all characters for which no face is specified.
16485 t means whatever face the window's mode line currently uses
16486 \(either `mode-line' or `mode-line-inactive', depending).
16487 nil means the default is no face property.
16488 If FACE is an integer, the value string has no text properties.
16490 Optional third and fourth args WINDOW and BUFFER specify the window
16491 and buffer to use as the context for the formatting (defaults
16492 are the selected window and the window's buffer). */)
16493 (format
, face
, window
, buffer
)
16494 Lisp_Object format
, face
, window
, buffer
;
16499 struct buffer
*old_buffer
= NULL
;
16501 int no_props
= INTEGERP (face
);
16502 int count
= SPECPDL_INDEX ();
16504 int string_start
= 0;
16507 window
= selected_window
;
16508 CHECK_WINDOW (window
);
16509 w
= XWINDOW (window
);
16512 buffer
= w
->buffer
;
16513 CHECK_BUFFER (buffer
);
16516 return build_string ("");
16524 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16525 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16529 face_id
= DEFAULT_FACE_ID
;
16531 if (XBUFFER (buffer
) != current_buffer
)
16532 old_buffer
= current_buffer
;
16534 record_unwind_protect (unwind_format_mode_line
,
16535 format_mode_line_unwind_data (old_buffer
));
16538 set_buffer_internal_1 (XBUFFER (buffer
));
16540 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16544 mode_line_target
= MODE_LINE_NOPROP
;
16545 mode_line_string_face_prop
= Qnil
;
16546 mode_line_string_list
= Qnil
;
16547 string_start
= MODE_LINE_NOPROP_LEN (0);
16551 mode_line_target
= MODE_LINE_STRING
;
16552 mode_line_string_list
= Qnil
;
16553 mode_line_string_face
= face
;
16554 mode_line_string_face_prop
16555 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16558 push_frame_kboard (it
.f
);
16559 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16560 pop_frame_kboard ();
16564 len
= MODE_LINE_NOPROP_LEN (string_start
);
16565 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16569 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16570 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16571 make_string ("", 0));
16574 unbind_to (count
, Qnil
);
16578 /* Write a null-terminated, right justified decimal representation of
16579 the positive integer D to BUF using a minimal field width WIDTH. */
16582 pint2str (buf
, width
, d
)
16583 register char *buf
;
16584 register int width
;
16587 register char *p
= buf
;
16595 *p
++ = d
% 10 + '0';
16600 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16611 /* Write a null-terminated, right justified decimal and "human
16612 readable" representation of the nonnegative integer D to BUF using
16613 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16615 static const char power_letter
[] =
16629 pint2hrstr (buf
, width
, d
)
16634 /* We aim to represent the nonnegative integer D as
16635 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16638 /* -1 means: do not use TENTHS. */
16642 /* Length of QUOTIENT.TENTHS as a string. */
16648 if (1000 <= quotient
)
16650 /* Scale to the appropriate EXPONENT. */
16653 remainder
= quotient
% 1000;
16657 while (1000 <= quotient
);
16659 /* Round to nearest and decide whether to use TENTHS or not. */
16662 tenths
= remainder
/ 100;
16663 if (50 <= remainder
% 100)
16670 if (quotient
== 10)
16678 if (500 <= remainder
)
16680 if (quotient
< 999)
16691 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16692 if (tenths
== -1 && quotient
<= 99)
16699 p
= psuffix
= buf
+ max (width
, length
);
16701 /* Print EXPONENT. */
16703 *psuffix
++ = power_letter
[exponent
];
16706 /* Print TENTHS. */
16709 *--p
= '0' + tenths
;
16713 /* Print QUOTIENT. */
16716 int digit
= quotient
% 10;
16717 *--p
= '0' + digit
;
16719 while ((quotient
/= 10) != 0);
16721 /* Print leading spaces. */
16726 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16727 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16728 type of CODING_SYSTEM. Return updated pointer into BUF. */
16730 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16733 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16734 Lisp_Object coding_system
;
16735 register char *buf
;
16739 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16740 const unsigned char *eol_str
;
16742 /* The EOL conversion we are using. */
16743 Lisp_Object eoltype
;
16745 val
= Fget (coding_system
, Qcoding_system
);
16748 if (!VECTORP (val
)) /* Not yet decided. */
16753 eoltype
= eol_mnemonic_undecided
;
16754 /* Don't mention EOL conversion if it isn't decided. */
16758 Lisp_Object eolvalue
;
16760 eolvalue
= Fget (coding_system
, Qeol_type
);
16763 *buf
++ = XFASTINT (AREF (val
, 1));
16767 /* The EOL conversion that is normal on this system. */
16769 if (NILP (eolvalue
)) /* Not yet decided. */
16770 eoltype
= eol_mnemonic_undecided
;
16771 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16772 eoltype
= eol_mnemonic_undecided
;
16773 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16774 eoltype
= (XFASTINT (eolvalue
) == 0
16775 ? eol_mnemonic_unix
16776 : (XFASTINT (eolvalue
) == 1
16777 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16783 /* Mention the EOL conversion if it is not the usual one. */
16784 if (STRINGP (eoltype
))
16786 eol_str
= SDATA (eoltype
);
16787 eol_str_len
= SBYTES (eoltype
);
16789 else if (INTEGERP (eoltype
)
16790 && CHAR_VALID_P (XINT (eoltype
), 0))
16792 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16793 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16798 eol_str
= invalid_eol_type
;
16799 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16801 bcopy (eol_str
, buf
, eol_str_len
);
16802 buf
+= eol_str_len
;
16808 /* Return a string for the output of a mode line %-spec for window W,
16809 generated by character C. PRECISION >= 0 means don't return a
16810 string longer than that value. FIELD_WIDTH > 0 means pad the
16811 string returned with spaces to that value. Return 1 in *MULTIBYTE
16812 if the result is multibyte text.
16814 Note we operate on the current buffer for most purposes,
16815 the exception being w->base_line_pos. */
16817 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16820 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16823 int field_width
, precision
;
16827 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16828 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16829 struct buffer
*b
= current_buffer
;
16837 if (!NILP (b
->read_only
))
16839 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16844 /* This differs from %* only for a modified read-only buffer. */
16845 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16847 if (!NILP (b
->read_only
))
16852 /* This differs from %* in ignoring read-only-ness. */
16853 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16865 if (command_loop_level
> 5)
16867 p
= decode_mode_spec_buf
;
16868 for (i
= 0; i
< command_loop_level
; i
++)
16871 return decode_mode_spec_buf
;
16879 if (command_loop_level
> 5)
16881 p
= decode_mode_spec_buf
;
16882 for (i
= 0; i
< command_loop_level
; i
++)
16885 return decode_mode_spec_buf
;
16892 /* Let lots_of_dashes be a string of infinite length. */
16893 if (mode_line_target
== MODE_LINE_NOPROP
||
16894 mode_line_target
== MODE_LINE_STRING
)
16896 if (field_width
<= 0
16897 || field_width
> sizeof (lots_of_dashes
))
16899 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16900 decode_mode_spec_buf
[i
] = '-';
16901 decode_mode_spec_buf
[i
] = '\0';
16902 return decode_mode_spec_buf
;
16905 return lots_of_dashes
;
16914 int col
= (int) current_column (); /* iftc */
16915 w
->column_number_displayed
= make_number (col
);
16916 pint2str (decode_mode_spec_buf
, field_width
, col
);
16917 return decode_mode_spec_buf
;
16921 /* %F displays the frame name. */
16922 if (!NILP (f
->title
))
16923 return (char *) SDATA (f
->title
);
16924 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16925 return (char *) SDATA (f
->name
);
16934 int size
= ZV
- BEGV
;
16935 pint2str (decode_mode_spec_buf
, field_width
, size
);
16936 return decode_mode_spec_buf
;
16941 int size
= ZV
- BEGV
;
16942 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16943 return decode_mode_spec_buf
;
16948 int startpos
= XMARKER (w
->start
)->charpos
;
16949 int startpos_byte
= marker_byte_position (w
->start
);
16950 int line
, linepos
, linepos_byte
, topline
;
16952 int height
= WINDOW_TOTAL_LINES (w
);
16954 /* If we decided that this buffer isn't suitable for line numbers,
16955 don't forget that too fast. */
16956 if (EQ (w
->base_line_pos
, w
->buffer
))
16958 /* But do forget it, if the window shows a different buffer now. */
16959 else if (BUFFERP (w
->base_line_pos
))
16960 w
->base_line_pos
= Qnil
;
16962 /* If the buffer is very big, don't waste time. */
16963 if (INTEGERP (Vline_number_display_limit
)
16964 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16966 w
->base_line_pos
= Qnil
;
16967 w
->base_line_number
= Qnil
;
16971 if (!NILP (w
->base_line_number
)
16972 && !NILP (w
->base_line_pos
)
16973 && XFASTINT (w
->base_line_pos
) <= startpos
)
16975 line
= XFASTINT (w
->base_line_number
);
16976 linepos
= XFASTINT (w
->base_line_pos
);
16977 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16982 linepos
= BUF_BEGV (b
);
16983 linepos_byte
= BUF_BEGV_BYTE (b
);
16986 /* Count lines from base line to window start position. */
16987 nlines
= display_count_lines (linepos
, linepos_byte
,
16991 topline
= nlines
+ line
;
16993 /* Determine a new base line, if the old one is too close
16994 or too far away, or if we did not have one.
16995 "Too close" means it's plausible a scroll-down would
16996 go back past it. */
16997 if (startpos
== BUF_BEGV (b
))
16999 w
->base_line_number
= make_number (topline
);
17000 w
->base_line_pos
= make_number (BUF_BEGV (b
));
17002 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
17003 || linepos
== BUF_BEGV (b
))
17005 int limit
= BUF_BEGV (b
);
17006 int limit_byte
= BUF_BEGV_BYTE (b
);
17008 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17010 if (startpos
- distance
> limit
)
17012 limit
= startpos
- distance
;
17013 limit_byte
= CHAR_TO_BYTE (limit
);
17016 nlines
= display_count_lines (startpos
, startpos_byte
,
17018 - (height
* 2 + 30),
17020 /* If we couldn't find the lines we wanted within
17021 line_number_display_limit_width chars per line,
17022 give up on line numbers for this window. */
17023 if (position
== limit_byte
&& limit
== startpos
- distance
)
17025 w
->base_line_pos
= w
->buffer
;
17026 w
->base_line_number
= Qnil
;
17030 w
->base_line_number
= make_number (topline
- nlines
);
17031 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17034 /* Now count lines from the start pos to point. */
17035 nlines
= display_count_lines (startpos
, startpos_byte
,
17036 PT_BYTE
, PT
, &junk
);
17038 /* Record that we did display the line number. */
17039 line_number_displayed
= 1;
17041 /* Make the string to show. */
17042 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17043 return decode_mode_spec_buf
;
17046 char* p
= decode_mode_spec_buf
;
17047 int pad
= field_width
- 2;
17053 return decode_mode_spec_buf
;
17059 obj
= b
->mode_name
;
17063 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17069 int pos
= marker_position (w
->start
);
17070 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17072 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17074 if (pos
<= BUF_BEGV (b
))
17079 else if (pos
<= BUF_BEGV (b
))
17083 if (total
> 1000000)
17084 /* Do it differently for a large value, to avoid overflow. */
17085 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17087 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17088 /* We can't normally display a 3-digit number,
17089 so get us a 2-digit number that is close. */
17092 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17093 return decode_mode_spec_buf
;
17097 /* Display percentage of size above the bottom of the screen. */
17100 int toppos
= marker_position (w
->start
);
17101 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17102 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17104 if (botpos
>= BUF_ZV (b
))
17106 if (toppos
<= BUF_BEGV (b
))
17113 if (total
> 1000000)
17114 /* Do it differently for a large value, to avoid overflow. */
17115 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17117 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17118 /* We can't normally display a 3-digit number,
17119 so get us a 2-digit number that is close. */
17122 if (toppos
<= BUF_BEGV (b
))
17123 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17125 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17126 return decode_mode_spec_buf
;
17131 /* status of process */
17132 obj
= Fget_buffer_process (Fcurrent_buffer ());
17134 return "no process";
17135 #ifdef subprocesses
17136 obj
= Fsymbol_name (Fprocess_status (obj
));
17140 case 't': /* indicate TEXT or BINARY */
17141 #ifdef MODE_LINE_BINARY_TEXT
17142 return MODE_LINE_BINARY_TEXT (b
);
17148 /* coding-system (not including end-of-line format) */
17150 /* coding-system (including end-of-line type) */
17152 int eol_flag
= (c
== 'Z');
17153 char *p
= decode_mode_spec_buf
;
17155 if (! FRAME_WINDOW_P (f
))
17157 /* No need to mention EOL here--the terminal never needs
17158 to do EOL conversion. */
17159 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17160 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17162 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17165 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17166 #ifdef subprocesses
17167 obj
= Fget_buffer_process (Fcurrent_buffer ());
17168 if (PROCESSP (obj
))
17170 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17172 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17175 #endif /* subprocesses */
17178 return decode_mode_spec_buf
;
17184 *multibyte
= STRING_MULTIBYTE (obj
);
17185 return (char *) SDATA (obj
);
17192 /* Count up to COUNT lines starting from START / START_BYTE.
17193 But don't go beyond LIMIT_BYTE.
17194 Return the number of lines thus found (always nonnegative).
17196 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17199 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17200 int start
, start_byte
, limit_byte
, count
;
17203 register unsigned char *cursor
;
17204 unsigned char *base
;
17206 register int ceiling
;
17207 register unsigned char *ceiling_addr
;
17208 int orig_count
= count
;
17210 /* If we are not in selective display mode,
17211 check only for newlines. */
17212 int selective_display
= (!NILP (current_buffer
->selective_display
)
17213 && !INTEGERP (current_buffer
->selective_display
));
17217 while (start_byte
< limit_byte
)
17219 ceiling
= BUFFER_CEILING_OF (start_byte
);
17220 ceiling
= min (limit_byte
- 1, ceiling
);
17221 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17222 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17225 if (selective_display
)
17226 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17229 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17232 if (cursor
!= ceiling_addr
)
17236 start_byte
+= cursor
- base
+ 1;
17237 *byte_pos_ptr
= start_byte
;
17241 if (++cursor
== ceiling_addr
)
17247 start_byte
+= cursor
- base
;
17252 while (start_byte
> limit_byte
)
17254 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17255 ceiling
= max (limit_byte
, ceiling
);
17256 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17257 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17260 if (selective_display
)
17261 while (--cursor
!= ceiling_addr
17262 && *cursor
!= '\n' && *cursor
!= 015)
17265 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17268 if (cursor
!= ceiling_addr
)
17272 start_byte
+= cursor
- base
+ 1;
17273 *byte_pos_ptr
= start_byte
;
17274 /* When scanning backwards, we should
17275 not count the newline posterior to which we stop. */
17276 return - orig_count
- 1;
17282 /* Here we add 1 to compensate for the last decrement
17283 of CURSOR, which took it past the valid range. */
17284 start_byte
+= cursor
- base
+ 1;
17288 *byte_pos_ptr
= limit_byte
;
17291 return - orig_count
+ count
;
17292 return orig_count
- count
;
17298 /***********************************************************************
17300 ***********************************************************************/
17302 /* Display a NUL-terminated string, starting with index START.
17304 If STRING is non-null, display that C string. Otherwise, the Lisp
17305 string LISP_STRING is displayed.
17307 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17308 FACE_STRING. Display STRING or LISP_STRING with the face at
17309 FACE_STRING_POS in FACE_STRING:
17311 Display the string in the environment given by IT, but use the
17312 standard display table, temporarily.
17314 FIELD_WIDTH is the minimum number of output glyphs to produce.
17315 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17316 with spaces. If STRING has more characters, more than FIELD_WIDTH
17317 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17319 PRECISION is the maximum number of characters to output from
17320 STRING. PRECISION < 0 means don't truncate the string.
17322 This is roughly equivalent to printf format specifiers:
17324 FIELD_WIDTH PRECISION PRINTF
17325 ----------------------------------------
17331 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17332 display them, and < 0 means obey the current buffer's value of
17333 enable_multibyte_characters.
17335 Value is the number of glyphs produced. */
17338 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17339 start
, it
, field_width
, precision
, max_x
, multibyte
)
17340 unsigned char *string
;
17341 Lisp_Object lisp_string
;
17342 Lisp_Object face_string
;
17343 int face_string_pos
;
17346 int field_width
, precision
, max_x
;
17349 int hpos_at_start
= it
->hpos
;
17350 int saved_face_id
= it
->face_id
;
17351 struct glyph_row
*row
= it
->glyph_row
;
17353 /* Initialize the iterator IT for iteration over STRING beginning
17354 with index START. */
17355 reseat_to_string (it
, string
, lisp_string
, start
,
17356 precision
, field_width
, multibyte
);
17358 /* If displaying STRING, set up the face of the iterator
17359 from LISP_STRING, if that's given. */
17360 if (STRINGP (face_string
))
17366 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17367 0, it
->region_beg_charpos
,
17368 it
->region_end_charpos
,
17369 &endptr
, it
->base_face_id
, 0);
17370 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17371 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17374 /* Set max_x to the maximum allowed X position. Don't let it go
17375 beyond the right edge of the window. */
17377 max_x
= it
->last_visible_x
;
17379 max_x
= min (max_x
, it
->last_visible_x
);
17381 /* Skip over display elements that are not visible. because IT->w is
17383 if (it
->current_x
< it
->first_visible_x
)
17384 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17385 MOVE_TO_POS
| MOVE_TO_X
);
17387 row
->ascent
= it
->max_ascent
;
17388 row
->height
= it
->max_ascent
+ it
->max_descent
;
17389 row
->phys_ascent
= it
->max_phys_ascent
;
17390 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17391 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17393 /* This condition is for the case that we are called with current_x
17394 past last_visible_x. */
17395 while (it
->current_x
< max_x
)
17397 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17399 /* Get the next display element. */
17400 if (!get_next_display_element (it
))
17403 /* Produce glyphs. */
17404 x_before
= it
->current_x
;
17405 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17406 PRODUCE_GLYPHS (it
);
17408 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17411 while (i
< nglyphs
)
17413 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17415 if (!it
->truncate_lines_p
17416 && x
+ glyph
->pixel_width
> max_x
)
17418 /* End of continued line or max_x reached. */
17419 if (CHAR_GLYPH_PADDING_P (*glyph
))
17421 /* A wide character is unbreakable. */
17422 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17423 it
->current_x
= x_before
;
17427 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17432 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17434 /* Glyph is at least partially visible. */
17436 if (x
< it
->first_visible_x
)
17437 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17441 /* Glyph is off the left margin of the display area.
17442 Should not happen. */
17446 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17447 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17448 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17449 row
->phys_height
= max (row
->phys_height
,
17450 it
->max_phys_ascent
+ it
->max_phys_descent
);
17451 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17452 it
->max_extra_line_spacing
);
17453 x
+= glyph
->pixel_width
;
17457 /* Stop if max_x reached. */
17461 /* Stop at line ends. */
17462 if (ITERATOR_AT_END_OF_LINE_P (it
))
17464 it
->continuation_lines_width
= 0;
17468 set_iterator_to_next (it
, 1);
17470 /* Stop if truncating at the right edge. */
17471 if (it
->truncate_lines_p
17472 && it
->current_x
>= it
->last_visible_x
)
17474 /* Add truncation mark, but don't do it if the line is
17475 truncated at a padding space. */
17476 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17478 if (!FRAME_WINDOW_P (it
->f
))
17482 if (it
->current_x
> it
->last_visible_x
)
17484 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17485 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17487 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17489 row
->used
[TEXT_AREA
] = i
;
17490 produce_special_glyphs (it
, IT_TRUNCATION
);
17493 produce_special_glyphs (it
, IT_TRUNCATION
);
17495 it
->glyph_row
->truncated_on_right_p
= 1;
17501 /* Maybe insert a truncation at the left. */
17502 if (it
->first_visible_x
17503 && IT_CHARPOS (*it
) > 0)
17505 if (!FRAME_WINDOW_P (it
->f
))
17506 insert_left_trunc_glyphs (it
);
17507 it
->glyph_row
->truncated_on_left_p
= 1;
17510 it
->face_id
= saved_face_id
;
17512 /* Value is number of columns displayed. */
17513 return it
->hpos
- hpos_at_start
;
17518 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17519 appears as an element of LIST or as the car of an element of LIST.
17520 If PROPVAL is a list, compare each element against LIST in that
17521 way, and return 1/2 if any element of PROPVAL is found in LIST.
17522 Otherwise return 0. This function cannot quit.
17523 The return value is 2 if the text is invisible but with an ellipsis
17524 and 1 if it's invisible and without an ellipsis. */
17527 invisible_p (propval
, list
)
17528 register Lisp_Object propval
;
17531 register Lisp_Object tail
, proptail
;
17533 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17535 register Lisp_Object tem
;
17537 if (EQ (propval
, tem
))
17539 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17540 return NILP (XCDR (tem
)) ? 1 : 2;
17543 if (CONSP (propval
))
17545 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17547 Lisp_Object propelt
;
17548 propelt
= XCAR (proptail
);
17549 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17551 register Lisp_Object tem
;
17553 if (EQ (propelt
, tem
))
17555 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17556 return NILP (XCDR (tem
)) ? 1 : 2;
17564 /* Calculate a width or height in pixels from a specification using
17565 the following elements:
17568 NUM - a (fractional) multiple of the default font width/height
17569 (NUM) - specifies exactly NUM pixels
17570 UNIT - a fixed number of pixels, see below.
17571 ELEMENT - size of a display element in pixels, see below.
17572 (NUM . SPEC) - equals NUM * SPEC
17573 (+ SPEC SPEC ...) - add pixel values
17574 (- SPEC SPEC ...) - subtract pixel values
17575 (- SPEC) - negate pixel value
17578 INT or FLOAT - a number constant
17579 SYMBOL - use symbol's (buffer local) variable binding.
17582 in - pixels per inch *)
17583 mm - pixels per 1/1000 meter *)
17584 cm - pixels per 1/100 meter *)
17585 width - width of current font in pixels.
17586 height - height of current font in pixels.
17588 *) using the ratio(s) defined in display-pixels-per-inch.
17592 left-fringe - left fringe width in pixels
17593 right-fringe - right fringe width in pixels
17595 left-margin - left margin width in pixels
17596 right-margin - right margin width in pixels
17598 scroll-bar - scroll-bar area width in pixels
17602 Pixels corresponding to 5 inches:
17605 Total width of non-text areas on left side of window (if scroll-bar is on left):
17606 '(space :width (+ left-fringe left-margin scroll-bar))
17608 Align to first text column (in header line):
17609 '(space :align-to 0)
17611 Align to middle of text area minus half the width of variable `my-image'
17612 containing a loaded image:
17613 '(space :align-to (0.5 . (- text my-image)))
17615 Width of left margin minus width of 1 character in the default font:
17616 '(space :width (- left-margin 1))
17618 Width of left margin minus width of 2 characters in the current font:
17619 '(space :width (- left-margin (2 . width)))
17621 Center 1 character over left-margin (in header line):
17622 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17624 Different ways to express width of left fringe plus left margin minus one pixel:
17625 '(space :width (- (+ left-fringe left-margin) (1)))
17626 '(space :width (+ left-fringe left-margin (- (1))))
17627 '(space :width (+ left-fringe left-margin (-1)))
17631 #define NUMVAL(X) \
17632 ((INTEGERP (X) || FLOATP (X)) \
17637 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17642 int width_p
, *align_to
;
17646 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17647 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17650 return OK_PIXELS (0);
17652 if (SYMBOLP (prop
))
17654 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17656 char *unit
= SDATA (SYMBOL_NAME (prop
));
17658 if (unit
[0] == 'i' && unit
[1] == 'n')
17660 else if (unit
[0] == 'm' && unit
[1] == 'm')
17662 else if (unit
[0] == 'c' && unit
[1] == 'm')
17669 #ifdef HAVE_WINDOW_SYSTEM
17670 if (FRAME_WINDOW_P (it
->f
)
17672 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
17673 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
17675 return OK_PIXELS (ppi
/ pixels
);
17678 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17679 || (CONSP (Vdisplay_pixels_per_inch
)
17681 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17682 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17684 return OK_PIXELS (ppi
/ pixels
);
17690 #ifdef HAVE_WINDOW_SYSTEM
17691 if (EQ (prop
, Qheight
))
17692 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17693 if (EQ (prop
, Qwidth
))
17694 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17696 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17697 return OK_PIXELS (1);
17700 if (EQ (prop
, Qtext
))
17701 return OK_PIXELS (width_p
17702 ? window_box_width (it
->w
, TEXT_AREA
)
17703 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17705 if (align_to
&& *align_to
< 0)
17708 if (EQ (prop
, Qleft
))
17709 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17710 if (EQ (prop
, Qright
))
17711 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17712 if (EQ (prop
, Qcenter
))
17713 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17714 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17715 if (EQ (prop
, Qleft_fringe
))
17716 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17717 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17718 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17719 if (EQ (prop
, Qright_fringe
))
17720 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17721 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17722 : window_box_right_offset (it
->w
, TEXT_AREA
));
17723 if (EQ (prop
, Qleft_margin
))
17724 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17725 if (EQ (prop
, Qright_margin
))
17726 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17727 if (EQ (prop
, Qscroll_bar
))
17728 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17730 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17731 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17732 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17737 if (EQ (prop
, Qleft_fringe
))
17738 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17739 if (EQ (prop
, Qright_fringe
))
17740 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17741 if (EQ (prop
, Qleft_margin
))
17742 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17743 if (EQ (prop
, Qright_margin
))
17744 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17745 if (EQ (prop
, Qscroll_bar
))
17746 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17749 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17752 if (INTEGERP (prop
) || FLOATP (prop
))
17754 int base_unit
= (width_p
17755 ? FRAME_COLUMN_WIDTH (it
->f
)
17756 : FRAME_LINE_HEIGHT (it
->f
));
17757 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17762 Lisp_Object car
= XCAR (prop
);
17763 Lisp_Object cdr
= XCDR (prop
);
17767 #ifdef HAVE_WINDOW_SYSTEM
17768 if (valid_image_p (prop
))
17770 int id
= lookup_image (it
->f
, prop
);
17771 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17773 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17776 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17782 while (CONSP (cdr
))
17784 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17785 font
, width_p
, align_to
))
17788 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17793 if (EQ (car
, Qminus
))
17795 return OK_PIXELS (pixels
);
17798 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17801 if (INTEGERP (car
) || FLOATP (car
))
17804 pixels
= XFLOATINT (car
);
17806 return OK_PIXELS (pixels
);
17807 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17808 font
, width_p
, align_to
))
17809 return OK_PIXELS (pixels
* fact
);
17820 /***********************************************************************
17822 ***********************************************************************/
17824 #ifdef HAVE_WINDOW_SYSTEM
17829 dump_glyph_string (s
)
17830 struct glyph_string
*s
;
17832 fprintf (stderr
, "glyph string\n");
17833 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17834 s
->x
, s
->y
, s
->width
, s
->height
);
17835 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17836 fprintf (stderr
, " hl = %d\n", s
->hl
);
17837 fprintf (stderr
, " left overhang = %d, right = %d\n",
17838 s
->left_overhang
, s
->right_overhang
);
17839 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17840 fprintf (stderr
, " extends to end of line = %d\n",
17841 s
->extends_to_end_of_line_p
);
17842 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17843 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17846 #endif /* GLYPH_DEBUG */
17848 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17849 of XChar2b structures for S; it can't be allocated in
17850 init_glyph_string because it must be allocated via `alloca'. W
17851 is the window on which S is drawn. ROW and AREA are the glyph row
17852 and area within the row from which S is constructed. START is the
17853 index of the first glyph structure covered by S. HL is a
17854 face-override for drawing S. */
17857 #define OPTIONAL_HDC(hdc) hdc,
17858 #define DECLARE_HDC(hdc) HDC hdc;
17859 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17860 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17863 #ifndef OPTIONAL_HDC
17864 #define OPTIONAL_HDC(hdc)
17865 #define DECLARE_HDC(hdc)
17866 #define ALLOCATE_HDC(hdc, f)
17867 #define RELEASE_HDC(hdc, f)
17871 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17872 struct glyph_string
*s
;
17876 struct glyph_row
*row
;
17877 enum glyph_row_area area
;
17879 enum draw_glyphs_face hl
;
17881 bzero (s
, sizeof *s
);
17883 s
->f
= XFRAME (w
->frame
);
17887 s
->display
= FRAME_X_DISPLAY (s
->f
);
17888 s
->window
= FRAME_X_WINDOW (s
->f
);
17889 s
->char2b
= char2b
;
17893 s
->first_glyph
= row
->glyphs
[area
] + start
;
17894 s
->height
= row
->height
;
17895 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17897 /* Display the internal border below the tool-bar window. */
17898 if (WINDOWP (s
->f
->tool_bar_window
)
17899 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17900 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17902 s
->ybase
= s
->y
+ row
->ascent
;
17906 /* Append the list of glyph strings with head H and tail T to the list
17907 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17910 append_glyph_string_lists (head
, tail
, h
, t
)
17911 struct glyph_string
**head
, **tail
;
17912 struct glyph_string
*h
, *t
;
17926 /* Prepend the list of glyph strings with head H and tail T to the
17927 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17931 prepend_glyph_string_lists (head
, tail
, h
, t
)
17932 struct glyph_string
**head
, **tail
;
17933 struct glyph_string
*h
, *t
;
17947 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17948 Set *HEAD and *TAIL to the resulting list. */
17951 append_glyph_string (head
, tail
, s
)
17952 struct glyph_string
**head
, **tail
;
17953 struct glyph_string
*s
;
17955 s
->next
= s
->prev
= NULL
;
17956 append_glyph_string_lists (head
, tail
, s
, s
);
17960 /* Get face and two-byte form of character glyph GLYPH on frame F.
17961 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17962 a pointer to a realized face that is ready for display. */
17964 static INLINE
struct face
*
17965 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17967 struct glyph
*glyph
;
17973 xassert (glyph
->type
== CHAR_GLYPH
);
17974 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17979 if (!glyph
->multibyte_p
)
17981 /* Unibyte case. We don't have to encode, but we have to make
17982 sure to use a face suitable for unibyte. */
17983 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17985 else if (glyph
->u
.ch
< 128
17986 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17988 /* Case of ASCII in a face known to fit ASCII. */
17989 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17993 int c1
, c2
, charset
;
17995 /* Split characters into bytes. If c2 is -1 afterwards, C is
17996 really a one-byte character so that byte1 is zero. */
17997 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17999 STORE_XCHAR2B (char2b
, c1
, c2
);
18001 STORE_XCHAR2B (char2b
, 0, c1
);
18003 /* Maybe encode the character in *CHAR2B. */
18004 if (charset
!= CHARSET_ASCII
)
18006 struct font_info
*font_info
18007 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18010 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18014 /* Make sure X resources of the face are allocated. */
18015 xassert (face
!= NULL
);
18016 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18021 /* Fill glyph string S with composition components specified by S->cmp.
18023 FACES is an array of faces for all components of this composition.
18024 S->gidx is the index of the first component for S.
18025 OVERLAPS_P non-zero means S should draw the foreground only, and
18026 use its physical height for clipping.
18028 Value is the index of a component not in S. */
18031 fill_composite_glyph_string (s
, faces
, overlaps_p
)
18032 struct glyph_string
*s
;
18033 struct face
**faces
;
18040 s
->for_overlaps_p
= overlaps_p
;
18042 s
->face
= faces
[s
->gidx
];
18043 s
->font
= s
->face
->font
;
18044 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18046 /* For all glyphs of this composition, starting at the offset
18047 S->gidx, until we reach the end of the definition or encounter a
18048 glyph that requires the different face, add it to S. */
18050 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18053 /* All glyph strings for the same composition has the same width,
18054 i.e. the width set for the first component of the composition. */
18056 s
->width
= s
->first_glyph
->pixel_width
;
18058 /* If the specified font could not be loaded, use the frame's
18059 default font, but record the fact that we couldn't load it in
18060 the glyph string so that we can draw rectangles for the
18061 characters of the glyph string. */
18062 if (s
->font
== NULL
)
18064 s
->font_not_found_p
= 1;
18065 s
->font
= FRAME_FONT (s
->f
);
18068 /* Adjust base line for subscript/superscript text. */
18069 s
->ybase
+= s
->first_glyph
->voffset
;
18071 xassert (s
->face
&& s
->face
->gc
);
18073 /* This glyph string must always be drawn with 16-bit functions. */
18076 return s
->gidx
+ s
->nchars
;
18080 /* Fill glyph string S from a sequence of character glyphs.
18082 FACE_ID is the face id of the string. START is the index of the
18083 first glyph to consider, END is the index of the last + 1.
18084 OVERLAPS_P non-zero means S should draw the foreground only, and
18085 use its physical height for clipping.
18087 Value is the index of the first glyph not in S. */
18090 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
18091 struct glyph_string
*s
;
18093 int start
, end
, overlaps_p
;
18095 struct glyph
*glyph
, *last
;
18097 int glyph_not_available_p
;
18099 xassert (s
->f
== XFRAME (s
->w
->frame
));
18100 xassert (s
->nchars
== 0);
18101 xassert (start
>= 0 && end
> start
);
18103 s
->for_overlaps_p
= overlaps_p
,
18104 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18105 last
= s
->row
->glyphs
[s
->area
] + end
;
18106 voffset
= glyph
->voffset
;
18108 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18110 while (glyph
< last
18111 && glyph
->type
== CHAR_GLYPH
18112 && glyph
->voffset
== voffset
18113 /* Same face id implies same font, nowadays. */
18114 && glyph
->face_id
== face_id
18115 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18119 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18120 s
->char2b
+ s
->nchars
,
18122 s
->two_byte_p
= two_byte_p
;
18124 xassert (s
->nchars
<= end
- start
);
18125 s
->width
+= glyph
->pixel_width
;
18129 s
->font
= s
->face
->font
;
18130 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18132 /* If the specified font could not be loaded, use the frame's font,
18133 but record the fact that we couldn't load it in
18134 S->font_not_found_p so that we can draw rectangles for the
18135 characters of the glyph string. */
18136 if (s
->font
== NULL
|| glyph_not_available_p
)
18138 s
->font_not_found_p
= 1;
18139 s
->font
= FRAME_FONT (s
->f
);
18142 /* Adjust base line for subscript/superscript text. */
18143 s
->ybase
+= voffset
;
18145 xassert (s
->face
&& s
->face
->gc
);
18146 return glyph
- s
->row
->glyphs
[s
->area
];
18150 /* Fill glyph string S from image glyph S->first_glyph. */
18153 fill_image_glyph_string (s
)
18154 struct glyph_string
*s
;
18156 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18157 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18159 s
->slice
= s
->first_glyph
->slice
;
18160 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18161 s
->font
= s
->face
->font
;
18162 s
->width
= s
->first_glyph
->pixel_width
;
18164 /* Adjust base line for subscript/superscript text. */
18165 s
->ybase
+= s
->first_glyph
->voffset
;
18169 /* Fill glyph string S from a sequence of stretch glyphs.
18171 ROW is the glyph row in which the glyphs are found, AREA is the
18172 area within the row. START is the index of the first glyph to
18173 consider, END is the index of the last + 1.
18175 Value is the index of the first glyph not in S. */
18178 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18179 struct glyph_string
*s
;
18180 struct glyph_row
*row
;
18181 enum glyph_row_area area
;
18184 struct glyph
*glyph
, *last
;
18185 int voffset
, face_id
;
18187 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18189 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18190 last
= s
->row
->glyphs
[s
->area
] + end
;
18191 face_id
= glyph
->face_id
;
18192 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18193 s
->font
= s
->face
->font
;
18194 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18195 s
->width
= glyph
->pixel_width
;
18196 voffset
= glyph
->voffset
;
18200 && glyph
->type
== STRETCH_GLYPH
18201 && glyph
->voffset
== voffset
18202 && glyph
->face_id
== face_id
);
18204 s
->width
+= glyph
->pixel_width
;
18206 /* Adjust base line for subscript/superscript text. */
18207 s
->ybase
+= voffset
;
18209 /* The case that face->gc == 0 is handled when drawing the glyph
18210 string by calling PREPARE_FACE_FOR_DISPLAY. */
18212 return glyph
- s
->row
->glyphs
[s
->area
];
18217 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18218 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18219 assumed to be zero. */
18222 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18223 struct glyph
*glyph
;
18227 *left
= *right
= 0;
18229 if (glyph
->type
== CHAR_GLYPH
)
18233 struct font_info
*font_info
;
18237 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18239 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18240 if (font
/* ++KFS: Should this be font_info ? */
18241 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18243 if (pcm
->rbearing
> pcm
->width
)
18244 *right
= pcm
->rbearing
- pcm
->width
;
18245 if (pcm
->lbearing
< 0)
18246 *left
= -pcm
->lbearing
;
18252 /* Return the index of the first glyph preceding glyph string S that
18253 is overwritten by S because of S's left overhang. Value is -1
18254 if no glyphs are overwritten. */
18257 left_overwritten (s
)
18258 struct glyph_string
*s
;
18262 if (s
->left_overhang
)
18265 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18266 int first
= s
->first_glyph
- glyphs
;
18268 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18269 x
-= glyphs
[i
].pixel_width
;
18280 /* Return the index of the first glyph preceding glyph string S that
18281 is overwriting S because of its right overhang. Value is -1 if no
18282 glyph in front of S overwrites S. */
18285 left_overwriting (s
)
18286 struct glyph_string
*s
;
18289 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18290 int first
= s
->first_glyph
- glyphs
;
18294 for (i
= first
- 1; i
>= 0; --i
)
18297 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18300 x
-= glyphs
[i
].pixel_width
;
18307 /* Return the index of the last glyph following glyph string S that is
18308 not overwritten by S because of S's right overhang. Value is -1 if
18309 no such glyph is found. */
18312 right_overwritten (s
)
18313 struct glyph_string
*s
;
18317 if (s
->right_overhang
)
18320 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18321 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18322 int end
= s
->row
->used
[s
->area
];
18324 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18325 x
+= glyphs
[i
].pixel_width
;
18334 /* Return the index of the last glyph following glyph string S that
18335 overwrites S because of its left overhang. Value is negative
18336 if no such glyph is found. */
18339 right_overwriting (s
)
18340 struct glyph_string
*s
;
18343 int end
= s
->row
->used
[s
->area
];
18344 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18345 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18349 for (i
= first
; i
< end
; ++i
)
18352 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18355 x
+= glyphs
[i
].pixel_width
;
18362 /* Get face and two-byte form of character C in face FACE_ID on frame
18363 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18364 means we want to display multibyte text. DISPLAY_P non-zero means
18365 make sure that X resources for the face returned are allocated.
18366 Value is a pointer to a realized face that is ready for display if
18367 DISPLAY_P is non-zero. */
18369 static INLINE
struct face
*
18370 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18374 int multibyte_p
, display_p
;
18376 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18380 /* Unibyte case. We don't have to encode, but we have to make
18381 sure to use a face suitable for unibyte. */
18382 STORE_XCHAR2B (char2b
, 0, c
);
18383 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18384 face
= FACE_FROM_ID (f
, face_id
);
18386 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18388 /* Case of ASCII in a face known to fit ASCII. */
18389 STORE_XCHAR2B (char2b
, 0, c
);
18393 int c1
, c2
, charset
;
18395 /* Split characters into bytes. If c2 is -1 afterwards, C is
18396 really a one-byte character so that byte1 is zero. */
18397 SPLIT_CHAR (c
, charset
, c1
, c2
);
18399 STORE_XCHAR2B (char2b
, c1
, c2
);
18401 STORE_XCHAR2B (char2b
, 0, c1
);
18403 /* Maybe encode the character in *CHAR2B. */
18404 if (face
->font
!= NULL
)
18406 struct font_info
*font_info
18407 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18409 rif
->encode_char (c
, char2b
, font_info
, 0);
18413 /* Make sure X resources of the face are allocated. */
18414 #ifdef HAVE_X_WINDOWS
18418 xassert (face
!= NULL
);
18419 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18426 /* Set background width of glyph string S. START is the index of the
18427 first glyph following S. LAST_X is the right-most x-position + 1
18428 in the drawing area. */
18431 set_glyph_string_background_width (s
, start
, last_x
)
18432 struct glyph_string
*s
;
18436 /* If the face of this glyph string has to be drawn to the end of
18437 the drawing area, set S->extends_to_end_of_line_p. */
18438 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18440 if (start
== s
->row
->used
[s
->area
]
18441 && s
->area
== TEXT_AREA
18442 && ((s
->hl
== DRAW_NORMAL_TEXT
18443 && (s
->row
->fill_line_p
18444 || s
->face
->background
!= default_face
->background
18445 || s
->face
->stipple
!= default_face
->stipple
18446 || s
->row
->mouse_face_p
))
18447 || s
->hl
== DRAW_MOUSE_FACE
18448 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18449 && s
->row
->fill_line_p
)))
18450 s
->extends_to_end_of_line_p
= 1;
18452 /* If S extends its face to the end of the line, set its
18453 background_width to the distance to the right edge of the drawing
18455 if (s
->extends_to_end_of_line_p
)
18456 s
->background_width
= last_x
- s
->x
+ 1;
18458 s
->background_width
= s
->width
;
18462 /* Compute overhangs and x-positions for glyph string S and its
18463 predecessors, or successors. X is the starting x-position for S.
18464 BACKWARD_P non-zero means process predecessors. */
18467 compute_overhangs_and_x (s
, x
, backward_p
)
18468 struct glyph_string
*s
;
18476 if (rif
->compute_glyph_string_overhangs
)
18477 rif
->compute_glyph_string_overhangs (s
);
18487 if (rif
->compute_glyph_string_overhangs
)
18488 rif
->compute_glyph_string_overhangs (s
);
18498 /* The following macros are only called from draw_glyphs below.
18499 They reference the following parameters of that function directly:
18500 `w', `row', `area', and `overlap_p'
18501 as well as the following local variables:
18502 `s', `f', and `hdc' (in W32) */
18505 /* On W32, silently add local `hdc' variable to argument list of
18506 init_glyph_string. */
18507 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18508 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18510 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18511 init_glyph_string (s, char2b, w, row, area, start, hl)
18514 /* Add a glyph string for a stretch glyph to the list of strings
18515 between HEAD and TAIL. START is the index of the stretch glyph in
18516 row area AREA of glyph row ROW. END is the index of the last glyph
18517 in that glyph row area. X is the current output position assigned
18518 to the new glyph string constructed. HL overrides that face of the
18519 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18520 is the right-most x-position of the drawing area. */
18522 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18523 and below -- keep them on one line. */
18524 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18527 s = (struct glyph_string *) alloca (sizeof *s); \
18528 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18529 START = fill_stretch_glyph_string (s, row, area, START, END); \
18530 append_glyph_string (&HEAD, &TAIL, s); \
18536 /* Add a glyph string for an image glyph to the list of strings
18537 between HEAD and TAIL. START is the index of the image glyph in
18538 row area AREA of glyph row ROW. END is the index of the last glyph
18539 in that glyph row area. X is the current output position assigned
18540 to the new glyph string constructed. HL overrides that face of the
18541 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18542 is the right-most x-position of the drawing area. */
18544 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18547 s = (struct glyph_string *) alloca (sizeof *s); \
18548 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18549 fill_image_glyph_string (s); \
18550 append_glyph_string (&HEAD, &TAIL, s); \
18557 /* Add a glyph string for a sequence of character glyphs to the list
18558 of strings between HEAD and TAIL. START is the index of the first
18559 glyph in row area AREA of glyph row ROW that is part of the new
18560 glyph string. END is the index of the last glyph in that glyph row
18561 area. X is the current output position assigned to the new glyph
18562 string constructed. HL overrides that face of the glyph; e.g. it
18563 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18564 right-most x-position of the drawing area. */
18566 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18572 c = (row)->glyphs[area][START].u.ch; \
18573 face_id = (row)->glyphs[area][START].face_id; \
18575 s = (struct glyph_string *) alloca (sizeof *s); \
18576 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18577 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18578 append_glyph_string (&HEAD, &TAIL, s); \
18580 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18585 /* Add a glyph string for a composite sequence to the list of strings
18586 between HEAD and TAIL. START is the index of the first glyph in
18587 row area AREA of glyph row ROW that is part of the new glyph
18588 string. END is the index of the last glyph in that glyph row area.
18589 X is the current output position assigned to the new glyph string
18590 constructed. HL overrides that face of the glyph; e.g. it is
18591 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18592 x-position of the drawing area. */
18594 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18596 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18597 int face_id = (row)->glyphs[area][START].face_id; \
18598 struct face *base_face = FACE_FROM_ID (f, face_id); \
18599 struct composition *cmp = composition_table[cmp_id]; \
18600 int glyph_len = cmp->glyph_len; \
18602 struct face **faces; \
18603 struct glyph_string *first_s = NULL; \
18606 base_face = base_face->ascii_face; \
18607 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18608 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18609 /* At first, fill in `char2b' and `faces'. */ \
18610 for (n = 0; n < glyph_len; n++) \
18612 int c = COMPOSITION_GLYPH (cmp, n); \
18613 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18614 faces[n] = FACE_FROM_ID (f, this_face_id); \
18615 get_char_face_and_encoding (f, c, this_face_id, \
18616 char2b + n, 1, 1); \
18619 /* Make glyph_strings for each glyph sequence that is drawable by \
18620 the same face, and append them to HEAD/TAIL. */ \
18621 for (n = 0; n < cmp->glyph_len;) \
18623 s = (struct glyph_string *) alloca (sizeof *s); \
18624 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18625 append_glyph_string (&(HEAD), &(TAIL), s); \
18633 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18641 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18642 of AREA of glyph row ROW on window W between indices START and END.
18643 HL overrides the face for drawing glyph strings, e.g. it is
18644 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18645 x-positions of the drawing area.
18647 This is an ugly monster macro construct because we must use alloca
18648 to allocate glyph strings (because draw_glyphs can be called
18649 asynchronously). */
18651 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18654 HEAD = TAIL = NULL; \
18655 while (START < END) \
18657 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18658 switch (first_glyph->type) \
18661 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18665 case COMPOSITE_GLYPH: \
18666 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18670 case STRETCH_GLYPH: \
18671 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18675 case IMAGE_GLYPH: \
18676 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18684 set_glyph_string_background_width (s, START, LAST_X); \
18691 /* Draw glyphs between START and END in AREA of ROW on window W,
18692 starting at x-position X. X is relative to AREA in W. HL is a
18693 face-override with the following meaning:
18695 DRAW_NORMAL_TEXT draw normally
18696 DRAW_CURSOR draw in cursor face
18697 DRAW_MOUSE_FACE draw in mouse face.
18698 DRAW_INVERSE_VIDEO draw in mode line face
18699 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18700 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18702 If OVERLAPS_P is non-zero, draw only the foreground of characters
18703 and clip to the physical height of ROW.
18705 Value is the x-position reached, relative to AREA of W. */
18708 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18711 struct glyph_row
*row
;
18712 enum glyph_row_area area
;
18714 enum draw_glyphs_face hl
;
18717 struct glyph_string
*head
, *tail
;
18718 struct glyph_string
*s
;
18719 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18720 int last_x
, area_width
;
18723 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18726 ALLOCATE_HDC (hdc
, f
);
18728 /* Let's rather be paranoid than getting a SEGV. */
18729 end
= min (end
, row
->used
[area
]);
18730 start
= max (0, start
);
18731 start
= min (end
, start
);
18733 /* Translate X to frame coordinates. Set last_x to the right
18734 end of the drawing area. */
18735 if (row
->full_width_p
)
18737 /* X is relative to the left edge of W, without scroll bars
18739 x
+= WINDOW_LEFT_EDGE_X (w
);
18740 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18744 int area_left
= window_box_left (w
, area
);
18746 area_width
= window_box_width (w
, area
);
18747 last_x
= area_left
+ area_width
;
18750 /* Build a doubly-linked list of glyph_string structures between
18751 head and tail from what we have to draw. Note that the macro
18752 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18753 the reason we use a separate variable `i'. */
18755 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18757 x_reached
= tail
->x
+ tail
->background_width
;
18761 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18762 the row, redraw some glyphs in front or following the glyph
18763 strings built above. */
18764 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18767 struct glyph_string
*h
, *t
;
18769 /* Compute overhangs for all glyph strings. */
18770 if (rif
->compute_glyph_string_overhangs
)
18771 for (s
= head
; s
; s
= s
->next
)
18772 rif
->compute_glyph_string_overhangs (s
);
18774 /* Prepend glyph strings for glyphs in front of the first glyph
18775 string that are overwritten because of the first glyph
18776 string's left overhang. The background of all strings
18777 prepended must be drawn because the first glyph string
18779 i
= left_overwritten (head
);
18783 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18784 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18786 compute_overhangs_and_x (t
, head
->x
, 1);
18787 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18791 /* Prepend glyph strings for glyphs in front of the first glyph
18792 string that overwrite that glyph string because of their
18793 right overhang. For these strings, only the foreground must
18794 be drawn, because it draws over the glyph string at `head'.
18795 The background must not be drawn because this would overwrite
18796 right overhangs of preceding glyphs for which no glyph
18798 i
= left_overwriting (head
);
18802 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18803 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18804 for (s
= h
; s
; s
= s
->next
)
18805 s
->background_filled_p
= 1;
18806 compute_overhangs_and_x (t
, head
->x
, 1);
18807 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18810 /* Append glyphs strings for glyphs following the last glyph
18811 string tail that are overwritten by tail. The background of
18812 these strings has to be drawn because tail's foreground draws
18814 i
= right_overwritten (tail
);
18817 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18818 DRAW_NORMAL_TEXT
, x
, last_x
);
18819 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18820 append_glyph_string_lists (&head
, &tail
, h
, t
);
18824 /* Append glyph strings for glyphs following the last glyph
18825 string tail that overwrite tail. The foreground of such
18826 glyphs has to be drawn because it writes into the background
18827 of tail. The background must not be drawn because it could
18828 paint over the foreground of following glyphs. */
18829 i
= right_overwriting (tail
);
18833 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18834 DRAW_NORMAL_TEXT
, x
, last_x
);
18835 for (s
= h
; s
; s
= s
->next
)
18836 s
->background_filled_p
= 1;
18837 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18838 append_glyph_string_lists (&head
, &tail
, h
, t
);
18840 if (clip_head
|| clip_tail
)
18841 for (s
= head
; s
; s
= s
->next
)
18843 s
->clip_head
= clip_head
;
18844 s
->clip_tail
= clip_tail
;
18848 /* Draw all strings. */
18849 for (s
= head
; s
; s
= s
->next
)
18850 rif
->draw_glyph_string (s
);
18852 if (area
== TEXT_AREA
18853 && !row
->full_width_p
18854 /* When drawing overlapping rows, only the glyph strings'
18855 foreground is drawn, which doesn't erase a cursor
18859 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18860 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18861 : (tail
? tail
->x
+ tail
->background_width
: x
));
18863 int text_left
= window_box_left (w
, TEXT_AREA
);
18867 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18868 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18871 /* Value is the x-position up to which drawn, relative to AREA of W.
18872 This doesn't include parts drawn because of overhangs. */
18873 if (row
->full_width_p
)
18874 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18876 x_reached
-= window_box_left (w
, area
);
18878 RELEASE_HDC (hdc
, f
);
18883 /* Expand row matrix if too narrow. Don't expand if area
18886 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18888 if (!fonts_changed_p \
18889 && (it->glyph_row->glyphs[area] \
18890 < it->glyph_row->glyphs[area + 1])) \
18892 it->w->ncols_scale_factor++; \
18893 fonts_changed_p = 1; \
18897 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18898 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18904 struct glyph
*glyph
;
18905 enum glyph_row_area area
= it
->area
;
18907 xassert (it
->glyph_row
);
18908 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18910 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18911 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18913 glyph
->charpos
= CHARPOS (it
->position
);
18914 glyph
->object
= it
->object
;
18915 glyph
->pixel_width
= it
->pixel_width
;
18916 glyph
->ascent
= it
->ascent
;
18917 glyph
->descent
= it
->descent
;
18918 glyph
->voffset
= it
->voffset
;
18919 glyph
->type
= CHAR_GLYPH
;
18920 glyph
->multibyte_p
= it
->multibyte_p
;
18921 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18922 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18923 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18924 || it
->phys_descent
> it
->descent
);
18925 glyph
->padding_p
= 0;
18926 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18927 glyph
->face_id
= it
->face_id
;
18928 glyph
->u
.ch
= it
->char_to_display
;
18929 glyph
->slice
= null_glyph_slice
;
18930 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18931 ++it
->glyph_row
->used
[area
];
18934 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18937 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18938 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18941 append_composite_glyph (it
)
18944 struct glyph
*glyph
;
18945 enum glyph_row_area area
= it
->area
;
18947 xassert (it
->glyph_row
);
18949 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18950 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18952 glyph
->charpos
= CHARPOS (it
->position
);
18953 glyph
->object
= it
->object
;
18954 glyph
->pixel_width
= it
->pixel_width
;
18955 glyph
->ascent
= it
->ascent
;
18956 glyph
->descent
= it
->descent
;
18957 glyph
->voffset
= it
->voffset
;
18958 glyph
->type
= COMPOSITE_GLYPH
;
18959 glyph
->multibyte_p
= it
->multibyte_p
;
18960 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18961 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18962 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18963 || it
->phys_descent
> it
->descent
);
18964 glyph
->padding_p
= 0;
18965 glyph
->glyph_not_available_p
= 0;
18966 glyph
->face_id
= it
->face_id
;
18967 glyph
->u
.cmp_id
= it
->cmp_id
;
18968 glyph
->slice
= null_glyph_slice
;
18969 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18970 ++it
->glyph_row
->used
[area
];
18973 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18977 /* Change IT->ascent and IT->height according to the setting of
18981 take_vertical_position_into_account (it
)
18986 if (it
->voffset
< 0)
18987 /* Increase the ascent so that we can display the text higher
18989 it
->ascent
-= it
->voffset
;
18991 /* Increase the descent so that we can display the text lower
18993 it
->descent
+= it
->voffset
;
18998 /* Produce glyphs/get display metrics for the image IT is loaded with.
18999 See the description of struct display_iterator in dispextern.h for
19000 an overview of struct display_iterator. */
19003 produce_image_glyph (it
)
19009 struct glyph_slice slice
;
19011 xassert (it
->what
== IT_IMAGE
);
19013 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19015 /* Make sure X resources of the face is loaded. */
19016 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19018 if (it
->image_id
< 0)
19020 /* Fringe bitmap. */
19021 it
->ascent
= it
->phys_ascent
= 0;
19022 it
->descent
= it
->phys_descent
= 0;
19023 it
->pixel_width
= 0;
19028 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19030 /* Make sure X resources of the image is loaded. */
19031 prepare_image_for_display (it
->f
, img
);
19033 slice
.x
= slice
.y
= 0;
19034 slice
.width
= img
->width
;
19035 slice
.height
= img
->height
;
19037 if (INTEGERP (it
->slice
.x
))
19038 slice
.x
= XINT (it
->slice
.x
);
19039 else if (FLOATP (it
->slice
.x
))
19040 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19042 if (INTEGERP (it
->slice
.y
))
19043 slice
.y
= XINT (it
->slice
.y
);
19044 else if (FLOATP (it
->slice
.y
))
19045 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19047 if (INTEGERP (it
->slice
.width
))
19048 slice
.width
= XINT (it
->slice
.width
);
19049 else if (FLOATP (it
->slice
.width
))
19050 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19052 if (INTEGERP (it
->slice
.height
))
19053 slice
.height
= XINT (it
->slice
.height
);
19054 else if (FLOATP (it
->slice
.height
))
19055 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19057 if (slice
.x
>= img
->width
)
19058 slice
.x
= img
->width
;
19059 if (slice
.y
>= img
->height
)
19060 slice
.y
= img
->height
;
19061 if (slice
.x
+ slice
.width
>= img
->width
)
19062 slice
.width
= img
->width
- slice
.x
;
19063 if (slice
.y
+ slice
.height
> img
->height
)
19064 slice
.height
= img
->height
- slice
.y
;
19066 if (slice
.width
== 0 || slice
.height
== 0)
19069 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19071 it
->descent
= slice
.height
- glyph_ascent
;
19073 it
->descent
+= img
->vmargin
;
19074 if (slice
.y
+ slice
.height
== img
->height
)
19075 it
->descent
+= img
->vmargin
;
19076 it
->phys_descent
= it
->descent
;
19078 it
->pixel_width
= slice
.width
;
19080 it
->pixel_width
+= img
->hmargin
;
19081 if (slice
.x
+ slice
.width
== img
->width
)
19082 it
->pixel_width
+= img
->hmargin
;
19084 /* It's quite possible for images to have an ascent greater than
19085 their height, so don't get confused in that case. */
19086 if (it
->descent
< 0)
19089 #if 0 /* this breaks image tiling */
19090 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19091 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19092 if (face_ascent
> it
->ascent
)
19093 it
->ascent
= it
->phys_ascent
= face_ascent
;
19098 if (face
->box
!= FACE_NO_BOX
)
19100 if (face
->box_line_width
> 0)
19103 it
->ascent
+= face
->box_line_width
;
19104 if (slice
.y
+ slice
.height
== img
->height
)
19105 it
->descent
+= face
->box_line_width
;
19108 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19109 it
->pixel_width
+= abs (face
->box_line_width
);
19110 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19111 it
->pixel_width
+= abs (face
->box_line_width
);
19114 take_vertical_position_into_account (it
);
19118 struct glyph
*glyph
;
19119 enum glyph_row_area area
= it
->area
;
19121 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19122 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19124 glyph
->charpos
= CHARPOS (it
->position
);
19125 glyph
->object
= it
->object
;
19126 glyph
->pixel_width
= it
->pixel_width
;
19127 glyph
->ascent
= glyph_ascent
;
19128 glyph
->descent
= it
->descent
;
19129 glyph
->voffset
= it
->voffset
;
19130 glyph
->type
= IMAGE_GLYPH
;
19131 glyph
->multibyte_p
= it
->multibyte_p
;
19132 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19133 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19134 glyph
->overlaps_vertically_p
= 0;
19135 glyph
->padding_p
= 0;
19136 glyph
->glyph_not_available_p
= 0;
19137 glyph
->face_id
= it
->face_id
;
19138 glyph
->u
.img_id
= img
->id
;
19139 glyph
->slice
= slice
;
19140 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19141 ++it
->glyph_row
->used
[area
];
19144 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19149 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19150 of the glyph, WIDTH and HEIGHT are the width and height of the
19151 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19154 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19156 Lisp_Object object
;
19160 struct glyph
*glyph
;
19161 enum glyph_row_area area
= it
->area
;
19163 xassert (ascent
>= 0 && ascent
<= height
);
19165 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19166 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19168 glyph
->charpos
= CHARPOS (it
->position
);
19169 glyph
->object
= object
;
19170 glyph
->pixel_width
= width
;
19171 glyph
->ascent
= ascent
;
19172 glyph
->descent
= height
- ascent
;
19173 glyph
->voffset
= it
->voffset
;
19174 glyph
->type
= STRETCH_GLYPH
;
19175 glyph
->multibyte_p
= it
->multibyte_p
;
19176 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19177 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19178 glyph
->overlaps_vertically_p
= 0;
19179 glyph
->padding_p
= 0;
19180 glyph
->glyph_not_available_p
= 0;
19181 glyph
->face_id
= it
->face_id
;
19182 glyph
->u
.stretch
.ascent
= ascent
;
19183 glyph
->u
.stretch
.height
= height
;
19184 glyph
->slice
= null_glyph_slice
;
19185 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19186 ++it
->glyph_row
->used
[area
];
19189 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19193 /* Produce a stretch glyph for iterator IT. IT->object is the value
19194 of the glyph property displayed. The value must be a list
19195 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19198 1. `:width WIDTH' specifies that the space should be WIDTH *
19199 canonical char width wide. WIDTH may be an integer or floating
19202 2. `:relative-width FACTOR' specifies that the width of the stretch
19203 should be computed from the width of the first character having the
19204 `glyph' property, and should be FACTOR times that width.
19206 3. `:align-to HPOS' specifies that the space should be wide enough
19207 to reach HPOS, a value in canonical character units.
19209 Exactly one of the above pairs must be present.
19211 4. `:height HEIGHT' specifies that the height of the stretch produced
19212 should be HEIGHT, measured in canonical character units.
19214 5. `:relative-height FACTOR' specifies that the height of the
19215 stretch should be FACTOR times the height of the characters having
19216 the glyph property.
19218 Either none or exactly one of 4 or 5 must be present.
19220 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19221 of the stretch should be used for the ascent of the stretch.
19222 ASCENT must be in the range 0 <= ASCENT <= 100. */
19225 produce_stretch_glyph (it
)
19228 /* (space :width WIDTH :height HEIGHT ...) */
19229 Lisp_Object prop
, plist
;
19230 int width
= 0, height
= 0, align_to
= -1;
19231 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19234 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19235 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19237 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19239 /* List should start with `space'. */
19240 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19241 plist
= XCDR (it
->object
);
19243 /* Compute the width of the stretch. */
19244 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19245 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19247 /* Absolute width `:width WIDTH' specified and valid. */
19248 zero_width_ok_p
= 1;
19251 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19254 /* Relative width `:relative-width FACTOR' specified and valid.
19255 Compute the width of the characters having the `glyph'
19258 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19261 if (it
->multibyte_p
)
19263 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19264 - IT_BYTEPOS (*it
));
19265 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19268 it2
.c
= *p
, it2
.len
= 1;
19270 it2
.glyph_row
= NULL
;
19271 it2
.what
= IT_CHARACTER
;
19272 x_produce_glyphs (&it2
);
19273 width
= NUMVAL (prop
) * it2
.pixel_width
;
19275 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19276 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19278 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19279 align_to
= (align_to
< 0
19281 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19282 else if (align_to
< 0)
19283 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19284 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19285 zero_width_ok_p
= 1;
19288 /* Nothing specified -> width defaults to canonical char width. */
19289 width
= FRAME_COLUMN_WIDTH (it
->f
);
19291 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19294 /* Compute height. */
19295 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19296 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19299 zero_height_ok_p
= 1;
19301 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19303 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19305 height
= FONT_HEIGHT (font
);
19307 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19310 /* Compute percentage of height used for ascent. If
19311 `:ascent ASCENT' is present and valid, use that. Otherwise,
19312 derive the ascent from the font in use. */
19313 if (prop
= Fplist_get (plist
, QCascent
),
19314 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19315 ascent
= height
* NUMVAL (prop
) / 100.0;
19316 else if (!NILP (prop
)
19317 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19318 ascent
= min (max (0, (int)tem
), height
);
19320 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19322 if (width
> 0 && height
> 0 && it
->glyph_row
)
19324 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19325 if (!STRINGP (object
))
19326 object
= it
->w
->buffer
;
19327 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19330 it
->pixel_width
= width
;
19331 it
->ascent
= it
->phys_ascent
= ascent
;
19332 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19333 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19335 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19337 if (face
->box_line_width
> 0)
19339 it
->ascent
+= face
->box_line_width
;
19340 it
->descent
+= face
->box_line_width
;
19343 if (it
->start_of_box_run_p
)
19344 it
->pixel_width
+= abs (face
->box_line_width
);
19345 if (it
->end_of_box_run_p
)
19346 it
->pixel_width
+= abs (face
->box_line_width
);
19349 take_vertical_position_into_account (it
);
19352 /* Get line-height and line-spacing property at point.
19353 If line-height has format (HEIGHT TOTAL), return TOTAL
19354 in TOTAL_HEIGHT. */
19357 get_line_height_property (it
, prop
)
19361 Lisp_Object position
;
19363 if (STRINGP (it
->object
))
19364 position
= make_number (IT_STRING_CHARPOS (*it
));
19365 else if (BUFFERP (it
->object
))
19366 position
= make_number (IT_CHARPOS (*it
));
19370 return Fget_char_property (position
, prop
, it
->object
);
19373 /* Calculate line-height and line-spacing properties.
19374 An integer value specifies explicit pixel value.
19375 A float value specifies relative value to current face height.
19376 A cons (float . face-name) specifies relative value to
19377 height of specified face font.
19379 Returns height in pixels, or nil. */
19383 calc_line_height_property (it
, val
, font
, boff
, override
)
19387 int boff
, override
;
19389 Lisp_Object face_name
= Qnil
;
19390 int ascent
, descent
, height
;
19392 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19397 face_name
= XCAR (val
);
19399 if (!NUMBERP (val
))
19400 val
= make_number (1);
19401 if (NILP (face_name
))
19403 height
= it
->ascent
+ it
->descent
;
19408 if (NILP (face_name
))
19410 font
= FRAME_FONT (it
->f
);
19411 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19413 else if (EQ (face_name
, Qt
))
19421 struct font_info
*font_info
;
19423 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19425 return make_number (-1);
19427 face
= FACE_FROM_ID (it
->f
, face_id
);
19430 return make_number (-1);
19432 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19433 boff
= font_info
->baseline_offset
;
19434 if (font_info
->vertical_centering
)
19435 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19438 ascent
= FONT_BASE (font
) + boff
;
19439 descent
= FONT_DESCENT (font
) - boff
;
19443 it
->override_ascent
= ascent
;
19444 it
->override_descent
= descent
;
19445 it
->override_boff
= boff
;
19448 height
= ascent
+ descent
;
19452 height
= (int)(XFLOAT_DATA (val
) * height
);
19453 else if (INTEGERP (val
))
19454 height
*= XINT (val
);
19456 return make_number (height
);
19461 Produce glyphs/get display metrics for the display element IT is
19462 loaded with. See the description of struct display_iterator in
19463 dispextern.h for an overview of struct display_iterator. */
19466 x_produce_glyphs (it
)
19469 int extra_line_spacing
= it
->extra_line_spacing
;
19471 it
->glyph_not_available_p
= 0;
19473 if (it
->what
== IT_CHARACTER
)
19477 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19479 int font_not_found_p
;
19480 struct font_info
*font_info
;
19481 int boff
; /* baseline offset */
19482 /* We may change it->multibyte_p upon unibyte<->multibyte
19483 conversion. So, save the current value now and restore it
19486 Note: It seems that we don't have to record multibyte_p in
19487 struct glyph because the character code itself tells if or
19488 not the character is multibyte. Thus, in the future, we must
19489 consider eliminating the field `multibyte_p' in the struct
19491 int saved_multibyte_p
= it
->multibyte_p
;
19493 /* Maybe translate single-byte characters to multibyte, or the
19495 it
->char_to_display
= it
->c
;
19496 if (!ASCII_BYTE_P (it
->c
))
19498 if (unibyte_display_via_language_environment
19499 && SINGLE_BYTE_CHAR_P (it
->c
)
19501 || !NILP (Vnonascii_translation_table
)))
19503 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19504 it
->multibyte_p
= 1;
19505 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19506 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19508 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19509 && !it
->multibyte_p
)
19511 it
->multibyte_p
= 1;
19512 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19513 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19517 /* Get font to use. Encode IT->char_to_display. */
19518 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19519 &char2b
, it
->multibyte_p
, 0);
19522 /* When no suitable font found, use the default font. */
19523 font_not_found_p
= font
== NULL
;
19524 if (font_not_found_p
)
19526 font
= FRAME_FONT (it
->f
);
19527 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19532 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19533 boff
= font_info
->baseline_offset
;
19534 if (font_info
->vertical_centering
)
19535 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19538 if (it
->char_to_display
>= ' '
19539 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19541 /* Either unibyte or ASCII. */
19546 pcm
= rif
->per_char_metric (font
, &char2b
,
19547 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19549 if (it
->override_ascent
>= 0)
19551 it
->ascent
= it
->override_ascent
;
19552 it
->descent
= it
->override_descent
;
19553 boff
= it
->override_boff
;
19557 it
->ascent
= FONT_BASE (font
) + boff
;
19558 it
->descent
= FONT_DESCENT (font
) - boff
;
19563 it
->phys_ascent
= pcm
->ascent
+ boff
;
19564 it
->phys_descent
= pcm
->descent
- boff
;
19565 it
->pixel_width
= pcm
->width
;
19569 it
->glyph_not_available_p
= 1;
19570 it
->phys_ascent
= it
->ascent
;
19571 it
->phys_descent
= it
->descent
;
19572 it
->pixel_width
= FONT_WIDTH (font
);
19575 if (it
->constrain_row_ascent_descent_p
)
19577 if (it
->descent
> it
->max_descent
)
19579 it
->ascent
+= it
->descent
- it
->max_descent
;
19580 it
->descent
= it
->max_descent
;
19582 if (it
->ascent
> it
->max_ascent
)
19584 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19585 it
->ascent
= it
->max_ascent
;
19587 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19588 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19589 extra_line_spacing
= 0;
19592 /* If this is a space inside a region of text with
19593 `space-width' property, change its width. */
19594 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19596 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19598 /* If face has a box, add the box thickness to the character
19599 height. If character has a box line to the left and/or
19600 right, add the box line width to the character's width. */
19601 if (face
->box
!= FACE_NO_BOX
)
19603 int thick
= face
->box_line_width
;
19607 it
->ascent
+= thick
;
19608 it
->descent
+= thick
;
19613 if (it
->start_of_box_run_p
)
19614 it
->pixel_width
+= thick
;
19615 if (it
->end_of_box_run_p
)
19616 it
->pixel_width
+= thick
;
19619 /* If face has an overline, add the height of the overline
19620 (1 pixel) and a 1 pixel margin to the character height. */
19621 if (face
->overline_p
)
19624 if (it
->constrain_row_ascent_descent_p
)
19626 if (it
->ascent
> it
->max_ascent
)
19627 it
->ascent
= it
->max_ascent
;
19628 if (it
->descent
> it
->max_descent
)
19629 it
->descent
= it
->max_descent
;
19632 take_vertical_position_into_account (it
);
19634 /* If we have to actually produce glyphs, do it. */
19639 /* Translate a space with a `space-width' property
19640 into a stretch glyph. */
19641 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19642 / FONT_HEIGHT (font
));
19643 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19644 it
->ascent
+ it
->descent
, ascent
);
19649 /* If characters with lbearing or rbearing are displayed
19650 in this line, record that fact in a flag of the
19651 glyph row. This is used to optimize X output code. */
19652 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19653 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19656 else if (it
->char_to_display
== '\n')
19658 /* A newline has no width but we need the height of the line.
19659 But if previous part of the line set a height, don't
19660 increase that height */
19662 Lisp_Object height
;
19663 Lisp_Object total_height
= Qnil
;
19665 it
->override_ascent
= -1;
19666 it
->pixel_width
= 0;
19669 height
= get_line_height_property(it
, Qline_height
);
19670 /* Split (line-height total-height) list */
19672 && CONSP (XCDR (height
))
19673 && NILP (XCDR (XCDR (height
))))
19675 total_height
= XCAR (XCDR (height
));
19676 height
= XCAR (height
);
19678 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19680 if (it
->override_ascent
>= 0)
19682 it
->ascent
= it
->override_ascent
;
19683 it
->descent
= it
->override_descent
;
19684 boff
= it
->override_boff
;
19688 it
->ascent
= FONT_BASE (font
) + boff
;
19689 it
->descent
= FONT_DESCENT (font
) - boff
;
19692 if (EQ (height
, Qt
))
19694 if (it
->descent
> it
->max_descent
)
19696 it
->ascent
+= it
->descent
- it
->max_descent
;
19697 it
->descent
= it
->max_descent
;
19699 if (it
->ascent
> it
->max_ascent
)
19701 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19702 it
->ascent
= it
->max_ascent
;
19704 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19705 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19706 it
->constrain_row_ascent_descent_p
= 1;
19707 extra_line_spacing
= 0;
19711 Lisp_Object spacing
;
19713 it
->phys_ascent
= it
->ascent
;
19714 it
->phys_descent
= it
->descent
;
19716 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19717 && face
->box
!= FACE_NO_BOX
19718 && face
->box_line_width
> 0)
19720 it
->ascent
+= face
->box_line_width
;
19721 it
->descent
+= face
->box_line_width
;
19724 && XINT (height
) > it
->ascent
+ it
->descent
)
19725 it
->ascent
= XINT (height
) - it
->descent
;
19727 if (!NILP (total_height
))
19728 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19731 spacing
= get_line_height_property(it
, Qline_spacing
);
19732 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19734 if (INTEGERP (spacing
))
19736 extra_line_spacing
= XINT (spacing
);
19737 if (!NILP (total_height
))
19738 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19742 else if (it
->char_to_display
== '\t')
19744 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19745 int x
= it
->current_x
+ it
->continuation_lines_width
;
19746 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19748 /* If the distance from the current position to the next tab
19749 stop is less than a space character width, use the
19750 tab stop after that. */
19751 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19752 next_tab_x
+= tab_width
;
19754 it
->pixel_width
= next_tab_x
- x
;
19756 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19757 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19761 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19762 it
->ascent
+ it
->descent
, it
->ascent
);
19767 /* A multi-byte character. Assume that the display width of the
19768 character is the width of the character multiplied by the
19769 width of the font. */
19771 /* If we found a font, this font should give us the right
19772 metrics. If we didn't find a font, use the frame's
19773 default font and calculate the width of the character
19774 from the charset width; this is what old redisplay code
19777 pcm
= rif
->per_char_metric (font
, &char2b
,
19778 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19780 if (font_not_found_p
|| !pcm
)
19782 int charset
= CHAR_CHARSET (it
->char_to_display
);
19784 it
->glyph_not_available_p
= 1;
19785 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19786 * CHARSET_WIDTH (charset
));
19787 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19788 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19792 it
->pixel_width
= pcm
->width
;
19793 it
->phys_ascent
= pcm
->ascent
+ boff
;
19794 it
->phys_descent
= pcm
->descent
- boff
;
19796 && (pcm
->lbearing
< 0
19797 || pcm
->rbearing
> pcm
->width
))
19798 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19801 it
->ascent
= FONT_BASE (font
) + boff
;
19802 it
->descent
= FONT_DESCENT (font
) - boff
;
19803 if (face
->box
!= FACE_NO_BOX
)
19805 int thick
= face
->box_line_width
;
19809 it
->ascent
+= thick
;
19810 it
->descent
+= thick
;
19815 if (it
->start_of_box_run_p
)
19816 it
->pixel_width
+= thick
;
19817 if (it
->end_of_box_run_p
)
19818 it
->pixel_width
+= thick
;
19821 /* If face has an overline, add the height of the overline
19822 (1 pixel) and a 1 pixel margin to the character height. */
19823 if (face
->overline_p
)
19826 take_vertical_position_into_account (it
);
19831 it
->multibyte_p
= saved_multibyte_p
;
19833 else if (it
->what
== IT_COMPOSITION
)
19835 /* Note: A composition is represented as one glyph in the
19836 glyph matrix. There are no padding glyphs. */
19839 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19841 int font_not_found_p
;
19842 struct font_info
*font_info
;
19843 int boff
; /* baseline offset */
19844 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19846 /* Maybe translate single-byte characters to multibyte. */
19847 it
->char_to_display
= it
->c
;
19848 if (unibyte_display_via_language_environment
19849 && SINGLE_BYTE_CHAR_P (it
->c
)
19852 && !NILP (Vnonascii_translation_table
))))
19854 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19857 /* Get face and font to use. Encode IT->char_to_display. */
19858 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19859 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19860 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19861 &char2b
, it
->multibyte_p
, 0);
19864 /* When no suitable font found, use the default font. */
19865 font_not_found_p
= font
== NULL
;
19866 if (font_not_found_p
)
19868 font
= FRAME_FONT (it
->f
);
19869 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19874 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19875 boff
= font_info
->baseline_offset
;
19876 if (font_info
->vertical_centering
)
19877 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19880 /* There are no padding glyphs, so there is only one glyph to
19881 produce for the composition. Important is that pixel_width,
19882 ascent and descent are the values of what is drawn by
19883 draw_glyphs (i.e. the values of the overall glyphs composed). */
19886 /* If we have not yet calculated pixel size data of glyphs of
19887 the composition for the current face font, calculate them
19888 now. Theoretically, we have to check all fonts for the
19889 glyphs, but that requires much time and memory space. So,
19890 here we check only the font of the first glyph. This leads
19891 to incorrect display very rarely, and C-l (recenter) can
19892 correct the display anyway. */
19893 if (cmp
->font
!= (void *) font
)
19895 /* Ascent and descent of the font of the first character of
19896 this composition (adjusted by baseline offset). Ascent
19897 and descent of overall glyphs should not be less than
19898 them respectively. */
19899 int font_ascent
= FONT_BASE (font
) + boff
;
19900 int font_descent
= FONT_DESCENT (font
) - boff
;
19901 /* Bounding box of the overall glyphs. */
19902 int leftmost
, rightmost
, lowest
, highest
;
19903 int i
, width
, ascent
, descent
;
19905 cmp
->font
= (void *) font
;
19907 /* Initialize the bounding box. */
19909 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19910 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19912 width
= pcm
->width
;
19913 ascent
= pcm
->ascent
;
19914 descent
= pcm
->descent
;
19918 width
= FONT_WIDTH (font
);
19919 ascent
= FONT_BASE (font
);
19920 descent
= FONT_DESCENT (font
);
19924 lowest
= - descent
+ boff
;
19925 highest
= ascent
+ boff
;
19929 && font_info
->default_ascent
19930 && CHAR_TABLE_P (Vuse_default_ascent
)
19931 && !NILP (Faref (Vuse_default_ascent
,
19932 make_number (it
->char_to_display
))))
19933 highest
= font_info
->default_ascent
+ boff
;
19935 /* Draw the first glyph at the normal position. It may be
19936 shifted to right later if some other glyphs are drawn at
19938 cmp
->offsets
[0] = 0;
19939 cmp
->offsets
[1] = boff
;
19941 /* Set cmp->offsets for the remaining glyphs. */
19942 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19944 int left
, right
, btm
, top
;
19945 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19946 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19948 face
= FACE_FROM_ID (it
->f
, face_id
);
19949 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19950 &char2b
, it
->multibyte_p
, 0);
19954 font
= FRAME_FONT (it
->f
);
19955 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19961 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19962 boff
= font_info
->baseline_offset
;
19963 if (font_info
->vertical_centering
)
19964 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19968 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19969 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19971 width
= pcm
->width
;
19972 ascent
= pcm
->ascent
;
19973 descent
= pcm
->descent
;
19977 width
= FONT_WIDTH (font
);
19982 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19984 /* Relative composition with or without
19985 alternate chars. */
19986 left
= (leftmost
+ rightmost
- width
) / 2;
19987 btm
= - descent
+ boff
;
19988 if (font_info
&& font_info
->relative_compose
19989 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19990 || NILP (Faref (Vignore_relative_composition
,
19991 make_number (ch
)))))
19994 if (- descent
>= font_info
->relative_compose
)
19995 /* One extra pixel between two glyphs. */
19997 else if (ascent
<= 0)
19998 /* One extra pixel between two glyphs. */
19999 btm
= lowest
- 1 - ascent
- descent
;
20004 /* A composition rule is specified by an integer
20005 value that encodes global and new reference
20006 points (GREF and NREF). GREF and NREF are
20007 specified by numbers as below:
20009 0---1---2 -- ascent
20013 9--10--11 -- center
20015 ---3---4---5--- baseline
20017 6---7---8 -- descent
20019 int rule
= COMPOSITION_RULE (cmp
, i
);
20020 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20022 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20023 grefx
= gref
% 3, nrefx
= nref
% 3;
20024 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20027 + grefx
* (rightmost
- leftmost
) / 2
20028 - nrefx
* width
/ 2);
20029 btm
= ((grefy
== 0 ? highest
20031 : grefy
== 2 ? lowest
20032 : (highest
+ lowest
) / 2)
20033 - (nrefy
== 0 ? ascent
+ descent
20034 : nrefy
== 1 ? descent
- boff
20036 : (ascent
+ descent
) / 2));
20039 cmp
->offsets
[i
* 2] = left
;
20040 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20042 /* Update the bounding box of the overall glyphs. */
20043 right
= left
+ width
;
20044 top
= btm
+ descent
+ ascent
;
20045 if (left
< leftmost
)
20047 if (right
> rightmost
)
20055 /* If there are glyphs whose x-offsets are negative,
20056 shift all glyphs to the right and make all x-offsets
20060 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20061 cmp
->offsets
[i
* 2] -= leftmost
;
20062 rightmost
-= leftmost
;
20065 cmp
->pixel_width
= rightmost
;
20066 cmp
->ascent
= highest
;
20067 cmp
->descent
= - lowest
;
20068 if (cmp
->ascent
< font_ascent
)
20069 cmp
->ascent
= font_ascent
;
20070 if (cmp
->descent
< font_descent
)
20071 cmp
->descent
= font_descent
;
20074 it
->pixel_width
= cmp
->pixel_width
;
20075 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20076 it
->descent
= it
->phys_descent
= cmp
->descent
;
20078 if (face
->box
!= FACE_NO_BOX
)
20080 int thick
= face
->box_line_width
;
20084 it
->ascent
+= thick
;
20085 it
->descent
+= thick
;
20090 if (it
->start_of_box_run_p
)
20091 it
->pixel_width
+= thick
;
20092 if (it
->end_of_box_run_p
)
20093 it
->pixel_width
+= thick
;
20096 /* If face has an overline, add the height of the overline
20097 (1 pixel) and a 1 pixel margin to the character height. */
20098 if (face
->overline_p
)
20101 take_vertical_position_into_account (it
);
20104 append_composite_glyph (it
);
20106 else if (it
->what
== IT_IMAGE
)
20107 produce_image_glyph (it
);
20108 else if (it
->what
== IT_STRETCH
)
20109 produce_stretch_glyph (it
);
20111 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20112 because this isn't true for images with `:ascent 100'. */
20113 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20114 if (it
->area
== TEXT_AREA
)
20115 it
->current_x
+= it
->pixel_width
;
20117 if (extra_line_spacing
> 0)
20119 it
->descent
+= extra_line_spacing
;
20120 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20121 it
->max_extra_line_spacing
= extra_line_spacing
;
20124 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20125 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20126 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20127 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20131 Output LEN glyphs starting at START at the nominal cursor position.
20132 Advance the nominal cursor over the text. The global variable
20133 updated_window contains the window being updated, updated_row is
20134 the glyph row being updated, and updated_area is the area of that
20135 row being updated. */
20138 x_write_glyphs (start
, len
)
20139 struct glyph
*start
;
20144 xassert (updated_window
&& updated_row
);
20147 /* Write glyphs. */
20149 hpos
= start
- updated_row
->glyphs
[updated_area
];
20150 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20151 updated_row
, updated_area
,
20153 DRAW_NORMAL_TEXT
, 0);
20155 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20156 if (updated_area
== TEXT_AREA
20157 && updated_window
->phys_cursor_on_p
20158 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20159 && updated_window
->phys_cursor
.hpos
>= hpos
20160 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20161 updated_window
->phys_cursor_on_p
= 0;
20165 /* Advance the output cursor. */
20166 output_cursor
.hpos
+= len
;
20167 output_cursor
.x
= x
;
20172 Insert LEN glyphs from START at the nominal cursor position. */
20175 x_insert_glyphs (start
, len
)
20176 struct glyph
*start
;
20181 int line_height
, shift_by_width
, shifted_region_width
;
20182 struct glyph_row
*row
;
20183 struct glyph
*glyph
;
20184 int frame_x
, frame_y
, hpos
;
20186 xassert (updated_window
&& updated_row
);
20188 w
= updated_window
;
20189 f
= XFRAME (WINDOW_FRAME (w
));
20191 /* Get the height of the line we are in. */
20193 line_height
= row
->height
;
20195 /* Get the width of the glyphs to insert. */
20196 shift_by_width
= 0;
20197 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20198 shift_by_width
+= glyph
->pixel_width
;
20200 /* Get the width of the region to shift right. */
20201 shifted_region_width
= (window_box_width (w
, updated_area
)
20206 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20207 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20209 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20210 line_height
, shift_by_width
);
20212 /* Write the glyphs. */
20213 hpos
= start
- row
->glyphs
[updated_area
];
20214 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20216 DRAW_NORMAL_TEXT
, 0);
20218 /* Advance the output cursor. */
20219 output_cursor
.hpos
+= len
;
20220 output_cursor
.x
+= shift_by_width
;
20226 Erase the current text line from the nominal cursor position
20227 (inclusive) to pixel column TO_X (exclusive). The idea is that
20228 everything from TO_X onward is already erased.
20230 TO_X is a pixel position relative to updated_area of
20231 updated_window. TO_X == -1 means clear to the end of this area. */
20234 x_clear_end_of_line (to_x
)
20238 struct window
*w
= updated_window
;
20239 int max_x
, min_y
, max_y
;
20240 int from_x
, from_y
, to_y
;
20242 xassert (updated_window
&& updated_row
);
20243 f
= XFRAME (w
->frame
);
20245 if (updated_row
->full_width_p
)
20246 max_x
= WINDOW_TOTAL_WIDTH (w
);
20248 max_x
= window_box_width (w
, updated_area
);
20249 max_y
= window_text_bottom_y (w
);
20251 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20252 of window. For TO_X > 0, truncate to end of drawing area. */
20258 to_x
= min (to_x
, max_x
);
20260 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20262 /* Notice if the cursor will be cleared by this operation. */
20263 if (!updated_row
->full_width_p
)
20264 notice_overwritten_cursor (w
, updated_area
,
20265 output_cursor
.x
, -1,
20267 MATRIX_ROW_BOTTOM_Y (updated_row
));
20269 from_x
= output_cursor
.x
;
20271 /* Translate to frame coordinates. */
20272 if (updated_row
->full_width_p
)
20274 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20275 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20279 int area_left
= window_box_left (w
, updated_area
);
20280 from_x
+= area_left
;
20284 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20285 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20286 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20288 /* Prevent inadvertently clearing to end of the X window. */
20289 if (to_x
> from_x
&& to_y
> from_y
)
20292 rif
->clear_frame_area (f
, from_x
, from_y
,
20293 to_x
- from_x
, to_y
- from_y
);
20298 #endif /* HAVE_WINDOW_SYSTEM */
20302 /***********************************************************************
20304 ***********************************************************************/
20306 /* Value is the internal representation of the specified cursor type
20307 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20308 of the bar cursor. */
20310 static enum text_cursor_kinds
20311 get_specified_cursor_type (arg
, width
)
20315 enum text_cursor_kinds type
;
20320 if (EQ (arg
, Qbox
))
20321 return FILLED_BOX_CURSOR
;
20323 if (EQ (arg
, Qhollow
))
20324 return HOLLOW_BOX_CURSOR
;
20326 if (EQ (arg
, Qbar
))
20333 && EQ (XCAR (arg
), Qbar
)
20334 && INTEGERP (XCDR (arg
))
20335 && XINT (XCDR (arg
)) >= 0)
20337 *width
= XINT (XCDR (arg
));
20341 if (EQ (arg
, Qhbar
))
20344 return HBAR_CURSOR
;
20348 && EQ (XCAR (arg
), Qhbar
)
20349 && INTEGERP (XCDR (arg
))
20350 && XINT (XCDR (arg
)) >= 0)
20352 *width
= XINT (XCDR (arg
));
20353 return HBAR_CURSOR
;
20356 /* Treat anything unknown as "hollow box cursor".
20357 It was bad to signal an error; people have trouble fixing
20358 .Xdefaults with Emacs, when it has something bad in it. */
20359 type
= HOLLOW_BOX_CURSOR
;
20364 /* Set the default cursor types for specified frame. */
20366 set_frame_cursor_types (f
, arg
)
20373 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20374 FRAME_CURSOR_WIDTH (f
) = width
;
20376 /* By default, set up the blink-off state depending on the on-state. */
20378 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20381 FRAME_BLINK_OFF_CURSOR (f
)
20382 = get_specified_cursor_type (XCDR (tem
), &width
);
20383 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20386 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20390 /* Return the cursor we want to be displayed in window W. Return
20391 width of bar/hbar cursor through WIDTH arg. Return with
20392 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20393 (i.e. if the `system caret' should track this cursor).
20395 In a mini-buffer window, we want the cursor only to appear if we
20396 are reading input from this window. For the selected window, we
20397 want the cursor type given by the frame parameter or buffer local
20398 setting of cursor-type. If explicitly marked off, draw no cursor.
20399 In all other cases, we want a hollow box cursor. */
20401 static enum text_cursor_kinds
20402 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20404 struct glyph
*glyph
;
20406 int *active_cursor
;
20408 struct frame
*f
= XFRAME (w
->frame
);
20409 struct buffer
*b
= XBUFFER (w
->buffer
);
20410 int cursor_type
= DEFAULT_CURSOR
;
20411 Lisp_Object alt_cursor
;
20412 int non_selected
= 0;
20414 *active_cursor
= 1;
20417 if (cursor_in_echo_area
20418 && FRAME_HAS_MINIBUF_P (f
)
20419 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20421 if (w
== XWINDOW (echo_area_window
))
20423 *width
= FRAME_CURSOR_WIDTH (f
);
20424 return FRAME_DESIRED_CURSOR (f
);
20427 *active_cursor
= 0;
20431 /* Nonselected window or nonselected frame. */
20432 else if (w
!= XWINDOW (f
->selected_window
)
20433 #ifdef HAVE_WINDOW_SYSTEM
20434 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20438 *active_cursor
= 0;
20440 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20446 /* Never display a cursor in a window in which cursor-type is nil. */
20447 if (NILP (b
->cursor_type
))
20450 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20453 alt_cursor
= XBUFFER (w
->buffer
)->cursor_in_non_selected_windows
;
20454 return get_specified_cursor_type (alt_cursor
, width
);
20457 /* Get the normal cursor type for this window. */
20458 if (EQ (b
->cursor_type
, Qt
))
20460 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20461 *width
= FRAME_CURSOR_WIDTH (f
);
20464 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20466 /* Use normal cursor if not blinked off. */
20467 if (!w
->cursor_off_p
)
20469 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20470 if (cursor_type
== FILLED_BOX_CURSOR
)
20471 cursor_type
= HOLLOW_BOX_CURSOR
;
20473 return cursor_type
;
20476 /* Cursor is blinked off, so determine how to "toggle" it. */
20478 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20479 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20480 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20482 /* Then see if frame has specified a specific blink off cursor type. */
20483 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20485 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20486 return FRAME_BLINK_OFF_CURSOR (f
);
20490 /* Some people liked having a permanently visible blinking cursor,
20491 while others had very strong opinions against it. So it was
20492 decided to remove it. KFS 2003-09-03 */
20494 /* Finally perform built-in cursor blinking:
20495 filled box <-> hollow box
20496 wide [h]bar <-> narrow [h]bar
20497 narrow [h]bar <-> no cursor
20498 other type <-> no cursor */
20500 if (cursor_type
== FILLED_BOX_CURSOR
)
20501 return HOLLOW_BOX_CURSOR
;
20503 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20506 return cursor_type
;
20514 #ifdef HAVE_WINDOW_SYSTEM
20516 /* Notice when the text cursor of window W has been completely
20517 overwritten by a drawing operation that outputs glyphs in AREA
20518 starting at X0 and ending at X1 in the line starting at Y0 and
20519 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20520 the rest of the line after X0 has been written. Y coordinates
20521 are window-relative. */
20524 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20526 enum glyph_row_area area
;
20527 int x0
, y0
, x1
, y1
;
20529 int cx0
, cx1
, cy0
, cy1
;
20530 struct glyph_row
*row
;
20532 if (!w
->phys_cursor_on_p
)
20534 if (area
!= TEXT_AREA
)
20537 if (w
->phys_cursor
.vpos
< 0
20538 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20539 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20540 !(row
->enabled_p
&& row
->displays_text_p
)))
20543 if (row
->cursor_in_fringe_p
)
20545 row
->cursor_in_fringe_p
= 0;
20546 draw_fringe_bitmap (w
, row
, 0);
20547 w
->phys_cursor_on_p
= 0;
20551 cx0
= w
->phys_cursor
.x
;
20552 cx1
= cx0
+ w
->phys_cursor_width
;
20553 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20556 /* The cursor image will be completely removed from the
20557 screen if the output area intersects the cursor area in
20558 y-direction. When we draw in [y0 y1[, and some part of
20559 the cursor is at y < y0, that part must have been drawn
20560 before. When scrolling, the cursor is erased before
20561 actually scrolling, so we don't come here. When not
20562 scrolling, the rows above the old cursor row must have
20563 changed, and in this case these rows must have written
20564 over the cursor image.
20566 Likewise if part of the cursor is below y1, with the
20567 exception of the cursor being in the first blank row at
20568 the buffer and window end because update_text_area
20569 doesn't draw that row. (Except when it does, but
20570 that's handled in update_text_area.) */
20572 cy0
= w
->phys_cursor
.y
;
20573 cy1
= cy0
+ w
->phys_cursor_height
;
20574 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20577 w
->phys_cursor_on_p
= 0;
20580 #endif /* HAVE_WINDOW_SYSTEM */
20583 /************************************************************************
20585 ************************************************************************/
20587 #ifdef HAVE_WINDOW_SYSTEM
20590 Fix the display of area AREA of overlapping row ROW in window W. */
20593 x_fix_overlapping_area (w
, row
, area
)
20595 struct glyph_row
*row
;
20596 enum glyph_row_area area
;
20603 for (i
= 0; i
< row
->used
[area
];)
20605 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20607 int start
= i
, start_x
= x
;
20611 x
+= row
->glyphs
[area
][i
].pixel_width
;
20614 while (i
< row
->used
[area
]
20615 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20617 draw_glyphs (w
, start_x
, row
, area
,
20619 DRAW_NORMAL_TEXT
, 1);
20623 x
+= row
->glyphs
[area
][i
].pixel_width
;
20633 Draw the cursor glyph of window W in glyph row ROW. See the
20634 comment of draw_glyphs for the meaning of HL. */
20637 draw_phys_cursor_glyph (w
, row
, hl
)
20639 struct glyph_row
*row
;
20640 enum draw_glyphs_face hl
;
20642 /* If cursor hpos is out of bounds, don't draw garbage. This can
20643 happen in mini-buffer windows when switching between echo area
20644 glyphs and mini-buffer. */
20645 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20647 int on_p
= w
->phys_cursor_on_p
;
20649 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20650 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20652 w
->phys_cursor_on_p
= on_p
;
20654 if (hl
== DRAW_CURSOR
)
20655 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20656 /* When we erase the cursor, and ROW is overlapped by other
20657 rows, make sure that these overlapping parts of other rows
20659 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20661 if (row
> w
->current_matrix
->rows
20662 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20663 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20665 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20666 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20667 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20674 Erase the image of a cursor of window W from the screen. */
20677 erase_phys_cursor (w
)
20680 struct frame
*f
= XFRAME (w
->frame
);
20681 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20682 int hpos
= w
->phys_cursor
.hpos
;
20683 int vpos
= w
->phys_cursor
.vpos
;
20684 int mouse_face_here_p
= 0;
20685 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20686 struct glyph_row
*cursor_row
;
20687 struct glyph
*cursor_glyph
;
20688 enum draw_glyphs_face hl
;
20690 /* No cursor displayed or row invalidated => nothing to do on the
20692 if (w
->phys_cursor_type
== NO_CURSOR
)
20693 goto mark_cursor_off
;
20695 /* VPOS >= active_glyphs->nrows means that window has been resized.
20696 Don't bother to erase the cursor. */
20697 if (vpos
>= active_glyphs
->nrows
)
20698 goto mark_cursor_off
;
20700 /* If row containing cursor is marked invalid, there is nothing we
20702 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20703 if (!cursor_row
->enabled_p
)
20704 goto mark_cursor_off
;
20706 /* If line spacing is > 0, old cursor may only be partially visible in
20707 window after split-window. So adjust visible height. */
20708 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20709 window_text_bottom_y (w
) - cursor_row
->y
);
20711 /* If row is completely invisible, don't attempt to delete a cursor which
20712 isn't there. This can happen if cursor is at top of a window, and
20713 we switch to a buffer with a header line in that window. */
20714 if (cursor_row
->visible_height
<= 0)
20715 goto mark_cursor_off
;
20717 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20718 if (cursor_row
->cursor_in_fringe_p
)
20720 cursor_row
->cursor_in_fringe_p
= 0;
20721 draw_fringe_bitmap (w
, cursor_row
, 0);
20722 goto mark_cursor_off
;
20725 /* This can happen when the new row is shorter than the old one.
20726 In this case, either draw_glyphs or clear_end_of_line
20727 should have cleared the cursor. Note that we wouldn't be
20728 able to erase the cursor in this case because we don't have a
20729 cursor glyph at hand. */
20730 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20731 goto mark_cursor_off
;
20733 /* If the cursor is in the mouse face area, redisplay that when
20734 we clear the cursor. */
20735 if (! NILP (dpyinfo
->mouse_face_window
)
20736 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20737 && (vpos
> dpyinfo
->mouse_face_beg_row
20738 || (vpos
== dpyinfo
->mouse_face_beg_row
20739 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20740 && (vpos
< dpyinfo
->mouse_face_end_row
20741 || (vpos
== dpyinfo
->mouse_face_end_row
20742 && hpos
< dpyinfo
->mouse_face_end_col
))
20743 /* Don't redraw the cursor's spot in mouse face if it is at the
20744 end of a line (on a newline). The cursor appears there, but
20745 mouse highlighting does not. */
20746 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20747 mouse_face_here_p
= 1;
20749 /* Maybe clear the display under the cursor. */
20750 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20753 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20756 cursor_glyph
= get_phys_cursor_glyph (w
);
20757 if (cursor_glyph
== NULL
)
20758 goto mark_cursor_off
;
20760 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20761 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20762 width
= min (cursor_glyph
->pixel_width
,
20763 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20765 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20768 /* Erase the cursor by redrawing the character underneath it. */
20769 if (mouse_face_here_p
)
20770 hl
= DRAW_MOUSE_FACE
;
20772 hl
= DRAW_NORMAL_TEXT
;
20773 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20776 w
->phys_cursor_on_p
= 0;
20777 w
->phys_cursor_type
= NO_CURSOR
;
20782 Display or clear cursor of window W. If ON is zero, clear the
20783 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20784 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20787 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20789 int on
, hpos
, vpos
, x
, y
;
20791 struct frame
*f
= XFRAME (w
->frame
);
20792 int new_cursor_type
;
20793 int new_cursor_width
;
20795 struct glyph_row
*glyph_row
;
20796 struct glyph
*glyph
;
20798 /* This is pointless on invisible frames, and dangerous on garbaged
20799 windows and frames; in the latter case, the frame or window may
20800 be in the midst of changing its size, and x and y may be off the
20802 if (! FRAME_VISIBLE_P (f
)
20803 || FRAME_GARBAGED_P (f
)
20804 || vpos
>= w
->current_matrix
->nrows
20805 || hpos
>= w
->current_matrix
->matrix_w
)
20808 /* If cursor is off and we want it off, return quickly. */
20809 if (!on
&& !w
->phys_cursor_on_p
)
20812 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20813 /* If cursor row is not enabled, we don't really know where to
20814 display the cursor. */
20815 if (!glyph_row
->enabled_p
)
20817 w
->phys_cursor_on_p
= 0;
20822 if (!glyph_row
->exact_window_width_line_p
20823 || hpos
< glyph_row
->used
[TEXT_AREA
])
20824 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20826 xassert (interrupt_input_blocked
);
20828 /* Set new_cursor_type to the cursor we want to be displayed. */
20829 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20830 &new_cursor_width
, &active_cursor
);
20832 /* If cursor is currently being shown and we don't want it to be or
20833 it is in the wrong place, or the cursor type is not what we want,
20835 if (w
->phys_cursor_on_p
20837 || w
->phys_cursor
.x
!= x
20838 || w
->phys_cursor
.y
!= y
20839 || new_cursor_type
!= w
->phys_cursor_type
20840 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20841 && new_cursor_width
!= w
->phys_cursor_width
)))
20842 erase_phys_cursor (w
);
20844 /* Don't check phys_cursor_on_p here because that flag is only set
20845 to zero in some cases where we know that the cursor has been
20846 completely erased, to avoid the extra work of erasing the cursor
20847 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20848 still not be visible, or it has only been partly erased. */
20851 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20852 w
->phys_cursor_height
= glyph_row
->height
;
20854 /* Set phys_cursor_.* before x_draw_.* is called because some
20855 of them may need the information. */
20856 w
->phys_cursor
.x
= x
;
20857 w
->phys_cursor
.y
= glyph_row
->y
;
20858 w
->phys_cursor
.hpos
= hpos
;
20859 w
->phys_cursor
.vpos
= vpos
;
20862 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20863 new_cursor_type
, new_cursor_width
,
20864 on
, active_cursor
);
20868 /* Switch the display of W's cursor on or off, according to the value
20872 update_window_cursor (w
, on
)
20876 /* Don't update cursor in windows whose frame is in the process
20877 of being deleted. */
20878 if (w
->current_matrix
)
20881 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20882 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20888 /* Call update_window_cursor with parameter ON_P on all leaf windows
20889 in the window tree rooted at W. */
20892 update_cursor_in_window_tree (w
, on_p
)
20898 if (!NILP (w
->hchild
))
20899 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20900 else if (!NILP (w
->vchild
))
20901 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20903 update_window_cursor (w
, on_p
);
20905 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20911 Display the cursor on window W, or clear it, according to ON_P.
20912 Don't change the cursor's position. */
20915 x_update_cursor (f
, on_p
)
20919 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20924 Clear the cursor of window W to background color, and mark the
20925 cursor as not shown. This is used when the text where the cursor
20926 is is about to be rewritten. */
20932 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20933 update_window_cursor (w
, 0);
20938 Display the active region described by mouse_face_* according to DRAW. */
20941 show_mouse_face (dpyinfo
, draw
)
20942 Display_Info
*dpyinfo
;
20943 enum draw_glyphs_face draw
;
20945 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20946 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20948 if (/* If window is in the process of being destroyed, don't bother
20950 w
->current_matrix
!= NULL
20951 /* Don't update mouse highlight if hidden */
20952 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20953 /* Recognize when we are called to operate on rows that don't exist
20954 anymore. This can happen when a window is split. */
20955 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20957 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20958 struct glyph_row
*row
, *first
, *last
;
20960 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20961 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20963 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20965 int start_hpos
, end_hpos
, start_x
;
20967 /* For all but the first row, the highlight starts at column 0. */
20970 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20971 start_x
= dpyinfo
->mouse_face_beg_x
;
20980 end_hpos
= dpyinfo
->mouse_face_end_col
;
20982 end_hpos
= row
->used
[TEXT_AREA
];
20984 if (end_hpos
> start_hpos
)
20986 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20987 start_hpos
, end_hpos
,
20991 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20995 /* When we've written over the cursor, arrange for it to
20996 be displayed again. */
20997 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
21000 display_and_set_cursor (w
, 1,
21001 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
21002 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21007 /* Change the mouse cursor. */
21008 if (draw
== DRAW_NORMAL_TEXT
)
21009 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21010 else if (draw
== DRAW_MOUSE_FACE
)
21011 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21013 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21017 Clear out the mouse-highlighted active region.
21018 Redraw it un-highlighted first. Value is non-zero if mouse
21019 face was actually drawn unhighlighted. */
21022 clear_mouse_face (dpyinfo
)
21023 Display_Info
*dpyinfo
;
21027 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21029 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21033 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21034 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21035 dpyinfo
->mouse_face_window
= Qnil
;
21036 dpyinfo
->mouse_face_overlay
= Qnil
;
21042 Non-zero if physical cursor of window W is within mouse face. */
21045 cursor_in_mouse_face_p (w
)
21048 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21049 int in_mouse_face
= 0;
21051 if (WINDOWP (dpyinfo
->mouse_face_window
)
21052 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21054 int hpos
= w
->phys_cursor
.hpos
;
21055 int vpos
= w
->phys_cursor
.vpos
;
21057 if (vpos
>= dpyinfo
->mouse_face_beg_row
21058 && vpos
<= dpyinfo
->mouse_face_end_row
21059 && (vpos
> dpyinfo
->mouse_face_beg_row
21060 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21061 && (vpos
< dpyinfo
->mouse_face_end_row
21062 || hpos
< dpyinfo
->mouse_face_end_col
21063 || dpyinfo
->mouse_face_past_end
))
21067 return in_mouse_face
;
21073 /* Find the glyph matrix position of buffer position CHARPOS in window
21074 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21075 current glyphs must be up to date. If CHARPOS is above window
21076 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21077 of last line in W. In the row containing CHARPOS, stop before glyphs
21078 having STOP as object. */
21080 #if 1 /* This is a version of fast_find_position that's more correct
21081 in the presence of hscrolling, for example. I didn't install
21082 it right away because the problem fixed is minor, it failed
21083 in 20.x as well, and I think it's too risky to install
21084 so near the release of 21.1. 2001-09-25 gerd. */
21087 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21090 int *hpos
, *vpos
, *x
, *y
;
21093 struct glyph_row
*row
, *first
;
21094 struct glyph
*glyph
, *end
;
21097 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21098 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21103 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21107 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21110 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21114 /* If whole rows or last part of a row came from a display overlay,
21115 row_containing_pos will skip over such rows because their end pos
21116 equals the start pos of the overlay or interval.
21118 Move back if we have a STOP object and previous row's
21119 end glyph came from STOP. */
21122 struct glyph_row
*prev
;
21123 while ((prev
= row
- 1, prev
>= first
)
21124 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21125 && prev
->used
[TEXT_AREA
] > 0)
21127 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21128 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21129 while (--glyph
>= beg
21130 && INTEGERP (glyph
->object
));
21132 || !EQ (stop
, glyph
->object
))
21140 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21142 glyph
= row
->glyphs
[TEXT_AREA
];
21143 end
= glyph
+ row
->used
[TEXT_AREA
];
21145 /* Skip over glyphs not having an object at the start of the row.
21146 These are special glyphs like truncation marks on terminal
21148 if (row
->displays_text_p
)
21150 && INTEGERP (glyph
->object
)
21151 && !EQ (stop
, glyph
->object
)
21152 && glyph
->charpos
< 0)
21154 *x
+= glyph
->pixel_width
;
21159 && !INTEGERP (glyph
->object
)
21160 && !EQ (stop
, glyph
->object
)
21161 && (!BUFFERP (glyph
->object
)
21162 || glyph
->charpos
< charpos
))
21164 *x
+= glyph
->pixel_width
;
21168 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21175 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21178 int *hpos
, *vpos
, *x
, *y
;
21183 int maybe_next_line_p
= 0;
21184 int line_start_position
;
21185 int yb
= window_text_bottom_y (w
);
21186 struct glyph_row
*row
, *best_row
;
21187 int row_vpos
, best_row_vpos
;
21190 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21191 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21193 while (row
->y
< yb
)
21195 if (row
->used
[TEXT_AREA
])
21196 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21198 line_start_position
= 0;
21200 if (line_start_position
> pos
)
21202 /* If the position sought is the end of the buffer,
21203 don't include the blank lines at the bottom of the window. */
21204 else if (line_start_position
== pos
21205 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21207 maybe_next_line_p
= 1;
21210 else if (line_start_position
> 0)
21213 best_row_vpos
= row_vpos
;
21216 if (row
->y
+ row
->height
>= yb
)
21223 /* Find the right column within BEST_ROW. */
21225 current_x
= best_row
->x
;
21226 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21228 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21229 int charpos
= glyph
->charpos
;
21231 if (BUFFERP (glyph
->object
))
21233 if (charpos
== pos
)
21236 *vpos
= best_row_vpos
;
21241 else if (charpos
> pos
)
21244 else if (EQ (glyph
->object
, stop
))
21249 current_x
+= glyph
->pixel_width
;
21252 /* If we're looking for the end of the buffer,
21253 and we didn't find it in the line we scanned,
21254 use the start of the following line. */
21255 if (maybe_next_line_p
)
21260 current_x
= best_row
->x
;
21263 *vpos
= best_row_vpos
;
21264 *hpos
= lastcol
+ 1;
21273 /* Find the position of the glyph for position POS in OBJECT in
21274 window W's current matrix, and return in *X, *Y the pixel
21275 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21277 RIGHT_P non-zero means return the position of the right edge of the
21278 glyph, RIGHT_P zero means return the left edge position.
21280 If no glyph for POS exists in the matrix, return the position of
21281 the glyph with the next smaller position that is in the matrix, if
21282 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21283 exists in the matrix, return the position of the glyph with the
21284 next larger position in OBJECT.
21286 Value is non-zero if a glyph was found. */
21289 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21292 Lisp_Object object
;
21293 int *hpos
, *vpos
, *x
, *y
;
21296 int yb
= window_text_bottom_y (w
);
21297 struct glyph_row
*r
;
21298 struct glyph
*best_glyph
= NULL
;
21299 struct glyph_row
*best_row
= NULL
;
21302 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21303 r
->enabled_p
&& r
->y
< yb
;
21306 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21307 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21310 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21311 if (EQ (g
->object
, object
))
21313 if (g
->charpos
== pos
)
21320 else if (best_glyph
== NULL
21321 || ((abs (g
->charpos
- pos
)
21322 < abs (best_glyph
->charpos
- pos
))
21325 : g
->charpos
> pos
)))
21339 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21343 *x
+= best_glyph
->pixel_width
;
21348 *vpos
= best_row
- w
->current_matrix
->rows
;
21351 return best_glyph
!= NULL
;
21355 /* See if position X, Y is within a hot-spot of an image. */
21358 on_hot_spot_p (hot_spot
, x
, y
)
21359 Lisp_Object hot_spot
;
21362 if (!CONSP (hot_spot
))
21365 if (EQ (XCAR (hot_spot
), Qrect
))
21367 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21368 Lisp_Object rect
= XCDR (hot_spot
);
21372 if (!CONSP (XCAR (rect
)))
21374 if (!CONSP (XCDR (rect
)))
21376 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21378 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21380 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21382 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21386 else if (EQ (XCAR (hot_spot
), Qcircle
))
21388 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21389 Lisp_Object circ
= XCDR (hot_spot
);
21390 Lisp_Object lr
, lx0
, ly0
;
21392 && CONSP (XCAR (circ
))
21393 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21394 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21395 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21397 double r
= XFLOATINT (lr
);
21398 double dx
= XINT (lx0
) - x
;
21399 double dy
= XINT (ly0
) - y
;
21400 return (dx
* dx
+ dy
* dy
<= r
* r
);
21403 else if (EQ (XCAR (hot_spot
), Qpoly
))
21405 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21406 if (VECTORP (XCDR (hot_spot
)))
21408 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21409 Lisp_Object
*poly
= v
->contents
;
21413 Lisp_Object lx
, ly
;
21416 /* Need an even number of coordinates, and at least 3 edges. */
21417 if (n
< 6 || n
& 1)
21420 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21421 If count is odd, we are inside polygon. Pixels on edges
21422 may or may not be included depending on actual geometry of the
21424 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21425 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21427 x0
= XINT (lx
), y0
= XINT (ly
);
21428 for (i
= 0; i
< n
; i
+= 2)
21430 int x1
= x0
, y1
= y0
;
21431 if ((lx
= poly
[i
], !INTEGERP (lx
))
21432 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21434 x0
= XINT (lx
), y0
= XINT (ly
);
21436 /* Does this segment cross the X line? */
21444 if (y
> y0
&& y
> y1
)
21446 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21452 /* If we don't understand the format, pretend we're not in the hot-spot. */
21457 find_hot_spot (map
, x
, y
)
21461 while (CONSP (map
))
21463 if (CONSP (XCAR (map
))
21464 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21472 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21474 doc
: /* Lookup in image map MAP coordinates X and Y.
21475 An image map is an alist where each element has the format (AREA ID PLIST).
21476 An AREA is specified as either a rectangle, a circle, or a polygon:
21477 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21478 pixel coordinates of the upper left and bottom right corners.
21479 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21480 and the radius of the circle; r may be a float or integer.
21481 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21482 vector describes one corner in the polygon.
21483 Returns the alist element for the first matching AREA in MAP. */)
21494 return find_hot_spot (map
, XINT (x
), XINT (y
));
21498 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21500 define_frame_cursor1 (f
, cursor
, pointer
)
21503 Lisp_Object pointer
;
21505 /* Do not change cursor shape while dragging mouse. */
21506 if (!NILP (do_mouse_tracking
))
21509 if (!NILP (pointer
))
21511 if (EQ (pointer
, Qarrow
))
21512 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21513 else if (EQ (pointer
, Qhand
))
21514 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21515 else if (EQ (pointer
, Qtext
))
21516 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21517 else if (EQ (pointer
, intern ("hdrag")))
21518 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21519 #ifdef HAVE_X_WINDOWS
21520 else if (EQ (pointer
, intern ("vdrag")))
21521 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21523 else if (EQ (pointer
, intern ("hourglass")))
21524 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21525 else if (EQ (pointer
, Qmodeline
))
21526 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21528 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21531 if (cursor
!= No_Cursor
)
21532 rif
->define_frame_cursor (f
, cursor
);
21535 /* Take proper action when mouse has moved to the mode or header line
21536 or marginal area AREA of window W, x-position X and y-position Y.
21537 X is relative to the start of the text display area of W, so the
21538 width of bitmap areas and scroll bars must be subtracted to get a
21539 position relative to the start of the mode line. */
21542 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21543 Lisp_Object window
;
21545 enum window_part area
;
21547 struct window
*w
= XWINDOW (window
);
21548 struct frame
*f
= XFRAME (w
->frame
);
21549 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21550 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21551 Lisp_Object pointer
= Qnil
;
21552 int charpos
, dx
, dy
, width
, height
;
21553 Lisp_Object string
, object
= Qnil
;
21554 Lisp_Object pos
, help
;
21556 Lisp_Object mouse_face
;
21557 int original_x_pixel
= x
;
21558 struct glyph
* glyph
= NULL
;
21559 struct glyph_row
*row
;
21561 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21566 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21567 &object
, &dx
, &dy
, &width
, &height
);
21569 row
= (area
== ON_MODE_LINE
21570 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21571 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21574 if (row
->mode_line_p
&& row
->enabled_p
)
21576 glyph
= row
->glyphs
[TEXT_AREA
];
21577 end
= glyph
+ row
->used
[TEXT_AREA
];
21579 for (x0
= original_x_pixel
;
21580 glyph
< end
&& x0
>= glyph
->pixel_width
;
21582 x0
-= glyph
->pixel_width
;
21590 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21591 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21592 &object
, &dx
, &dy
, &width
, &height
);
21597 if (IMAGEP (object
))
21599 Lisp_Object image_map
, hotspot
;
21600 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
21602 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21604 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21606 Lisp_Object area_id
, plist
;
21608 area_id
= XCAR (hotspot
);
21609 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21610 If so, we could look for mouse-enter, mouse-leave
21611 properties in PLIST (and do something...). */
21612 hotspot
= XCDR (hotspot
);
21613 if (CONSP (hotspot
)
21614 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21616 pointer
= Fplist_get (plist
, Qpointer
);
21617 if (NILP (pointer
))
21619 help
= Fplist_get (plist
, Qhelp_echo
);
21622 help_echo_string
= help
;
21623 /* Is this correct? ++kfs */
21624 XSETWINDOW (help_echo_window
, w
);
21625 help_echo_object
= w
->buffer
;
21626 help_echo_pos
= charpos
;
21630 if (NILP (pointer
))
21631 pointer
= Fplist_get (XCDR (object
), QCpointer
);
21634 if (STRINGP (string
))
21636 pos
= make_number (charpos
);
21637 /* If we're on a string with `help-echo' text property, arrange
21638 for the help to be displayed. This is done by setting the
21639 global variable help_echo_string to the help string. */
21642 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21645 help_echo_string
= help
;
21646 XSETWINDOW (help_echo_window
, w
);
21647 help_echo_object
= string
;
21648 help_echo_pos
= charpos
;
21652 if (NILP (pointer
))
21653 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21655 /* Change the mouse pointer according to what is under X/Y. */
21656 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21659 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21660 if (!KEYMAPP (map
))
21661 map
= Fget_text_property (pos
, Qkeymap
, string
);
21662 if (!KEYMAPP (map
))
21663 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21666 /* Change the mouse face according to what is under X/Y. */
21667 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
21668 if (!NILP (mouse_face
)
21669 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21674 struct glyph
* tmp_glyph
;
21678 int total_pixel_width
;
21683 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
21684 Qmouse_face
, string
, Qnil
);
21686 b
= make_number (0);
21688 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
21690 e
= make_number (SCHARS (string
));
21692 /* Calculate the position(glyph position: GPOS) of GLYPH in
21693 displayed string. GPOS is different from CHARPOS.
21695 CHARPOS is the position of glyph in internal string
21696 object. A mode line string format has structures which
21697 is converted to a flatten by emacs lisp interpreter.
21698 The internal string is an element of the structures.
21699 The displayed string is the flatten string. */
21700 for (tmp_glyph
= glyph
- 1, gpos
= 0;
21701 tmp_glyph
->charpos
>= XINT (b
);
21702 tmp_glyph
--, gpos
++)
21704 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21708 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
21709 displayed string holding GLYPH.
21711 GSEQ_LENGTH is different from SCHARS (STRING).
21712 SCHARS (STRING) returns the length of the internal string. */
21713 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
21714 tmp_glyph
->charpos
< XINT (e
);
21715 tmp_glyph
++, gseq_length
++)
21717 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21721 total_pixel_width
= 0;
21722 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
21723 total_pixel_width
+= tmp_glyph
->pixel_width
;
21725 /* Pre calculation of re-rendering position */
21727 hpos
= (area
== ON_MODE_LINE
21728 ? (w
->current_matrix
)->nrows
- 1
21731 /* If the re-rendering position is included in the last
21732 re-rendering area, we should do nothing. */
21733 if ( EQ (window
, dpyinfo
->mouse_face_window
)
21734 && dpyinfo
->mouse_face_beg_col
<= vpos
21735 && vpos
< dpyinfo
->mouse_face_end_col
21736 && dpyinfo
->mouse_face_beg_row
== hpos
)
21739 if (clear_mouse_face (dpyinfo
))
21740 cursor
= No_Cursor
;
21742 dpyinfo
->mouse_face_beg_col
= vpos
;
21743 dpyinfo
->mouse_face_beg_row
= hpos
;
21745 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
21746 dpyinfo
->mouse_face_beg_y
= 0;
21748 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
21749 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
21751 dpyinfo
->mouse_face_end_x
= 0;
21752 dpyinfo
->mouse_face_end_y
= 0;
21754 dpyinfo
->mouse_face_past_end
= 0;
21755 dpyinfo
->mouse_face_window
= window
;
21757 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
21760 glyph
->face_id
, 1);
21761 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21763 if (NILP (pointer
))
21766 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21767 clear_mouse_face (dpyinfo
);
21769 define_frame_cursor1 (f
, cursor
, pointer
);
21774 Take proper action when the mouse has moved to position X, Y on
21775 frame F as regards highlighting characters that have mouse-face
21776 properties. Also de-highlighting chars where the mouse was before.
21777 X and Y can be negative or out of range. */
21780 note_mouse_highlight (f
, x
, y
)
21784 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21785 enum window_part part
;
21786 Lisp_Object window
;
21788 Cursor cursor
= No_Cursor
;
21789 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21792 /* When a menu is active, don't highlight because this looks odd. */
21793 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21794 if (popup_activated ())
21798 if (NILP (Vmouse_highlight
)
21799 || !f
->glyphs_initialized_p
)
21802 dpyinfo
->mouse_face_mouse_x
= x
;
21803 dpyinfo
->mouse_face_mouse_y
= y
;
21804 dpyinfo
->mouse_face_mouse_frame
= f
;
21806 if (dpyinfo
->mouse_face_defer
)
21809 if (gc_in_progress
)
21811 dpyinfo
->mouse_face_deferred_gc
= 1;
21815 /* Which window is that in? */
21816 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21818 /* If we were displaying active text in another window, clear that.
21819 Also clear if we move out of text area in same window. */
21820 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21821 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
21822 && !NILP (dpyinfo
->mouse_face_window
)))
21823 clear_mouse_face (dpyinfo
);
21825 /* Not on a window -> return. */
21826 if (!WINDOWP (window
))
21829 /* Reset help_echo_string. It will get recomputed below. */
21830 help_echo_string
= Qnil
;
21832 /* Convert to window-relative pixel coordinates. */
21833 w
= XWINDOW (window
);
21834 frame_to_window_pixel_xy (w
, &x
, &y
);
21836 /* Handle tool-bar window differently since it doesn't display a
21838 if (EQ (window
, f
->tool_bar_window
))
21840 note_tool_bar_highlight (f
, x
, y
);
21844 /* Mouse is on the mode, header line or margin? */
21845 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21846 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21848 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
21852 if (part
== ON_VERTICAL_BORDER
)
21853 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21854 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21855 || part
== ON_SCROLL_BAR
)
21856 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21858 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21860 /* Are we in a window whose display is up to date?
21861 And verify the buffer's text has not changed. */
21862 b
= XBUFFER (w
->buffer
);
21863 if (part
== ON_TEXT
21864 && EQ (w
->window_end_valid
, w
->buffer
)
21865 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21866 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21868 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21869 struct glyph
*glyph
;
21870 Lisp_Object object
;
21871 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21872 Lisp_Object
*overlay_vec
= NULL
;
21874 struct buffer
*obuf
;
21875 int obegv
, ozv
, same_region
;
21877 /* Find the glyph under X/Y. */
21878 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21880 /* Look for :pointer property on image. */
21881 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21883 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21884 if (img
!= NULL
&& IMAGEP (img
->spec
))
21886 Lisp_Object image_map
, hotspot
;
21887 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
21889 && (hotspot
= find_hot_spot (image_map
,
21890 glyph
->slice
.x
+ dx
,
21891 glyph
->slice
.y
+ dy
),
21893 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21895 Lisp_Object area_id
, plist
;
21897 area_id
= XCAR (hotspot
);
21898 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21899 If so, we could look for mouse-enter, mouse-leave
21900 properties in PLIST (and do something...). */
21901 hotspot
= XCDR (hotspot
);
21902 if (CONSP (hotspot
)
21903 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21905 pointer
= Fplist_get (plist
, Qpointer
);
21906 if (NILP (pointer
))
21908 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
21909 if (!NILP (help_echo_string
))
21911 help_echo_window
= window
;
21912 help_echo_object
= glyph
->object
;
21913 help_echo_pos
= glyph
->charpos
;
21917 if (NILP (pointer
))
21918 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
21922 /* Clear mouse face if X/Y not over text. */
21924 || area
!= TEXT_AREA
21925 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21927 if (clear_mouse_face (dpyinfo
))
21928 cursor
= No_Cursor
;
21929 if (NILP (pointer
))
21931 if (area
!= TEXT_AREA
)
21932 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21934 pointer
= Vvoid_text_area_pointer
;
21939 pos
= glyph
->charpos
;
21940 object
= glyph
->object
;
21941 if (!STRINGP (object
) && !BUFFERP (object
))
21944 /* If we get an out-of-range value, return now; avoid an error. */
21945 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21948 /* Make the window's buffer temporarily current for
21949 overlays_at and compute_char_face. */
21950 obuf
= current_buffer
;
21951 current_buffer
= b
;
21957 /* Is this char mouse-active or does it have help-echo? */
21958 position
= make_number (pos
);
21960 if (BUFFERP (object
))
21962 /* Put all the overlays we want in a vector in overlay_vec. */
21963 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21964 /* Sort overlays into increasing priority order. */
21965 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21970 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21971 && vpos
>= dpyinfo
->mouse_face_beg_row
21972 && vpos
<= dpyinfo
->mouse_face_end_row
21973 && (vpos
> dpyinfo
->mouse_face_beg_row
21974 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21975 && (vpos
< dpyinfo
->mouse_face_end_row
21976 || hpos
< dpyinfo
->mouse_face_end_col
21977 || dpyinfo
->mouse_face_past_end
));
21980 cursor
= No_Cursor
;
21982 /* Check mouse-face highlighting. */
21984 /* If there exists an overlay with mouse-face overlapping
21985 the one we are currently highlighting, we have to
21986 check if we enter the overlapping overlay, and then
21987 highlight only that. */
21988 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21989 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21991 /* Find the highest priority overlay that has a mouse-face
21994 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21996 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21997 if (!NILP (mouse_face
))
21998 overlay
= overlay_vec
[i
];
22001 /* If we're actually highlighting the same overlay as
22002 before, there's no need to do that again. */
22003 if (!NILP (overlay
)
22004 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22005 goto check_help_echo
;
22007 dpyinfo
->mouse_face_overlay
= overlay
;
22009 /* Clear the display of the old active region, if any. */
22010 if (clear_mouse_face (dpyinfo
))
22011 cursor
= No_Cursor
;
22013 /* If no overlay applies, get a text property. */
22014 if (NILP (overlay
))
22015 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22017 /* Handle the overlay case. */
22018 if (!NILP (overlay
))
22020 /* Find the range of text around this char that
22021 should be active. */
22022 Lisp_Object before
, after
;
22025 before
= Foverlay_start (overlay
);
22026 after
= Foverlay_end (overlay
);
22027 /* Record this as the current active region. */
22028 fast_find_position (w
, XFASTINT (before
),
22029 &dpyinfo
->mouse_face_beg_col
,
22030 &dpyinfo
->mouse_face_beg_row
,
22031 &dpyinfo
->mouse_face_beg_x
,
22032 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22034 dpyinfo
->mouse_face_past_end
22035 = !fast_find_position (w
, XFASTINT (after
),
22036 &dpyinfo
->mouse_face_end_col
,
22037 &dpyinfo
->mouse_face_end_row
,
22038 &dpyinfo
->mouse_face_end_x
,
22039 &dpyinfo
->mouse_face_end_y
, Qnil
);
22040 dpyinfo
->mouse_face_window
= window
;
22042 dpyinfo
->mouse_face_face_id
22043 = face_at_buffer_position (w
, pos
, 0, 0,
22045 !dpyinfo
->mouse_face_hidden
);
22047 /* Display it as active. */
22048 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22049 cursor
= No_Cursor
;
22051 /* Handle the text property case. */
22052 else if (!NILP (mouse_face
) && BUFFERP (object
))
22054 /* Find the range of text around this char that
22055 should be active. */
22056 Lisp_Object before
, after
, beginning
, end
;
22059 beginning
= Fmarker_position (w
->start
);
22060 end
= make_number (BUF_Z (XBUFFER (object
))
22061 - XFASTINT (w
->window_end_pos
));
22063 = Fprevious_single_property_change (make_number (pos
+ 1),
22065 object
, beginning
);
22067 = Fnext_single_property_change (position
, Qmouse_face
,
22070 /* Record this as the current active region. */
22071 fast_find_position (w
, XFASTINT (before
),
22072 &dpyinfo
->mouse_face_beg_col
,
22073 &dpyinfo
->mouse_face_beg_row
,
22074 &dpyinfo
->mouse_face_beg_x
,
22075 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22076 dpyinfo
->mouse_face_past_end
22077 = !fast_find_position (w
, XFASTINT (after
),
22078 &dpyinfo
->mouse_face_end_col
,
22079 &dpyinfo
->mouse_face_end_row
,
22080 &dpyinfo
->mouse_face_end_x
,
22081 &dpyinfo
->mouse_face_end_y
, Qnil
);
22082 dpyinfo
->mouse_face_window
= window
;
22084 if (BUFFERP (object
))
22085 dpyinfo
->mouse_face_face_id
22086 = face_at_buffer_position (w
, pos
, 0, 0,
22088 !dpyinfo
->mouse_face_hidden
);
22090 /* Display it as active. */
22091 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22092 cursor
= No_Cursor
;
22094 else if (!NILP (mouse_face
) && STRINGP (object
))
22099 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22102 e
= Fnext_single_property_change (position
, Qmouse_face
,
22105 b
= make_number (0);
22107 e
= make_number (SCHARS (object
) - 1);
22109 fast_find_string_pos (w
, XINT (b
), object
,
22110 &dpyinfo
->mouse_face_beg_col
,
22111 &dpyinfo
->mouse_face_beg_row
,
22112 &dpyinfo
->mouse_face_beg_x
,
22113 &dpyinfo
->mouse_face_beg_y
, 0);
22114 fast_find_string_pos (w
, XINT (e
), object
,
22115 &dpyinfo
->mouse_face_end_col
,
22116 &dpyinfo
->mouse_face_end_row
,
22117 &dpyinfo
->mouse_face_end_x
,
22118 &dpyinfo
->mouse_face_end_y
, 1);
22119 dpyinfo
->mouse_face_past_end
= 0;
22120 dpyinfo
->mouse_face_window
= window
;
22121 dpyinfo
->mouse_face_face_id
22122 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22123 glyph
->face_id
, 1);
22124 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22125 cursor
= No_Cursor
;
22127 else if (STRINGP (object
) && NILP (mouse_face
))
22129 /* A string which doesn't have mouse-face, but
22130 the text ``under'' it might have. */
22131 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22132 int start
= MATRIX_ROW_START_CHARPOS (r
);
22134 pos
= string_buffer_position (w
, object
, start
);
22136 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22140 if (!NILP (mouse_face
) && !NILP (overlay
))
22142 Lisp_Object before
= Foverlay_start (overlay
);
22143 Lisp_Object after
= Foverlay_end (overlay
);
22146 /* Note that we might not be able to find position
22147 BEFORE in the glyph matrix if the overlay is
22148 entirely covered by a `display' property. In
22149 this case, we overshoot. So let's stop in
22150 the glyph matrix before glyphs for OBJECT. */
22151 fast_find_position (w
, XFASTINT (before
),
22152 &dpyinfo
->mouse_face_beg_col
,
22153 &dpyinfo
->mouse_face_beg_row
,
22154 &dpyinfo
->mouse_face_beg_x
,
22155 &dpyinfo
->mouse_face_beg_y
,
22158 dpyinfo
->mouse_face_past_end
22159 = !fast_find_position (w
, XFASTINT (after
),
22160 &dpyinfo
->mouse_face_end_col
,
22161 &dpyinfo
->mouse_face_end_row
,
22162 &dpyinfo
->mouse_face_end_x
,
22163 &dpyinfo
->mouse_face_end_y
,
22165 dpyinfo
->mouse_face_window
= window
;
22166 dpyinfo
->mouse_face_face_id
22167 = face_at_buffer_position (w
, pos
, 0, 0,
22169 !dpyinfo
->mouse_face_hidden
);
22171 /* Display it as active. */
22172 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22173 cursor
= No_Cursor
;
22180 /* Look for a `help-echo' property. */
22181 if (NILP (help_echo_string
)) {
22182 Lisp_Object help
, overlay
;
22184 /* Check overlays first. */
22185 help
= overlay
= Qnil
;
22186 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22188 overlay
= overlay_vec
[i
];
22189 help
= Foverlay_get (overlay
, Qhelp_echo
);
22194 help_echo_string
= help
;
22195 help_echo_window
= window
;
22196 help_echo_object
= overlay
;
22197 help_echo_pos
= pos
;
22201 Lisp_Object object
= glyph
->object
;
22202 int charpos
= glyph
->charpos
;
22204 /* Try text properties. */
22205 if (STRINGP (object
)
22207 && charpos
< SCHARS (object
))
22209 help
= Fget_text_property (make_number (charpos
),
22210 Qhelp_echo
, object
);
22213 /* If the string itself doesn't specify a help-echo,
22214 see if the buffer text ``under'' it does. */
22215 struct glyph_row
*r
22216 = MATRIX_ROW (w
->current_matrix
, vpos
);
22217 int start
= MATRIX_ROW_START_CHARPOS (r
);
22218 int pos
= string_buffer_position (w
, object
, start
);
22221 help
= Fget_char_property (make_number (pos
),
22222 Qhelp_echo
, w
->buffer
);
22226 object
= w
->buffer
;
22231 else if (BUFFERP (object
)
22234 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22239 help_echo_string
= help
;
22240 help_echo_window
= window
;
22241 help_echo_object
= object
;
22242 help_echo_pos
= charpos
;
22247 /* Look for a `pointer' property. */
22248 if (NILP (pointer
))
22250 /* Check overlays first. */
22251 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22252 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22254 if (NILP (pointer
))
22256 Lisp_Object object
= glyph
->object
;
22257 int charpos
= glyph
->charpos
;
22259 /* Try text properties. */
22260 if (STRINGP (object
)
22262 && charpos
< SCHARS (object
))
22264 pointer
= Fget_text_property (make_number (charpos
),
22266 if (NILP (pointer
))
22268 /* If the string itself doesn't specify a pointer,
22269 see if the buffer text ``under'' it does. */
22270 struct glyph_row
*r
22271 = MATRIX_ROW (w
->current_matrix
, vpos
);
22272 int start
= MATRIX_ROW_START_CHARPOS (r
);
22273 int pos
= string_buffer_position (w
, object
, start
);
22275 pointer
= Fget_char_property (make_number (pos
),
22276 Qpointer
, w
->buffer
);
22279 else if (BUFFERP (object
)
22282 pointer
= Fget_text_property (make_number (charpos
),
22289 current_buffer
= obuf
;
22294 define_frame_cursor1 (f
, cursor
, pointer
);
22299 Clear any mouse-face on window W. This function is part of the
22300 redisplay interface, and is called from try_window_id and similar
22301 functions to ensure the mouse-highlight is off. */
22304 x_clear_window_mouse_face (w
)
22307 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22308 Lisp_Object window
;
22311 XSETWINDOW (window
, w
);
22312 if (EQ (window
, dpyinfo
->mouse_face_window
))
22313 clear_mouse_face (dpyinfo
);
22319 Just discard the mouse face information for frame F, if any.
22320 This is used when the size of F is changed. */
22323 cancel_mouse_face (f
)
22326 Lisp_Object window
;
22327 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22329 window
= dpyinfo
->mouse_face_window
;
22330 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22332 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22333 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22334 dpyinfo
->mouse_face_window
= Qnil
;
22339 #endif /* HAVE_WINDOW_SYSTEM */
22342 /***********************************************************************
22344 ***********************************************************************/
22346 #ifdef HAVE_WINDOW_SYSTEM
22348 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22349 which intersects rectangle R. R is in window-relative coordinates. */
22352 expose_area (w
, row
, r
, area
)
22354 struct glyph_row
*row
;
22356 enum glyph_row_area area
;
22358 struct glyph
*first
= row
->glyphs
[area
];
22359 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22360 struct glyph
*last
;
22361 int first_x
, start_x
, x
;
22363 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22364 /* If row extends face to end of line write the whole line. */
22365 draw_glyphs (w
, 0, row
, area
,
22366 0, row
->used
[area
],
22367 DRAW_NORMAL_TEXT
, 0);
22370 /* Set START_X to the window-relative start position for drawing glyphs of
22371 AREA. The first glyph of the text area can be partially visible.
22372 The first glyphs of other areas cannot. */
22373 start_x
= window_box_left_offset (w
, area
);
22375 if (area
== TEXT_AREA
)
22378 /* Find the first glyph that must be redrawn. */
22380 && x
+ first
->pixel_width
< r
->x
)
22382 x
+= first
->pixel_width
;
22386 /* Find the last one. */
22390 && x
< r
->x
+ r
->width
)
22392 x
+= last
->pixel_width
;
22398 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22399 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22400 DRAW_NORMAL_TEXT
, 0);
22405 /* Redraw the parts of the glyph row ROW on window W intersecting
22406 rectangle R. R is in window-relative coordinates. Value is
22407 non-zero if mouse-face was overwritten. */
22410 expose_line (w
, row
, r
)
22412 struct glyph_row
*row
;
22415 xassert (row
->enabled_p
);
22417 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22418 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22419 0, row
->used
[TEXT_AREA
],
22420 DRAW_NORMAL_TEXT
, 0);
22423 if (row
->used
[LEFT_MARGIN_AREA
])
22424 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22425 if (row
->used
[TEXT_AREA
])
22426 expose_area (w
, row
, r
, TEXT_AREA
);
22427 if (row
->used
[RIGHT_MARGIN_AREA
])
22428 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22429 draw_row_fringe_bitmaps (w
, row
);
22432 return row
->mouse_face_p
;
22436 /* Redraw those parts of glyphs rows during expose event handling that
22437 overlap other rows. Redrawing of an exposed line writes over parts
22438 of lines overlapping that exposed line; this function fixes that.
22440 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22441 row in W's current matrix that is exposed and overlaps other rows.
22442 LAST_OVERLAPPING_ROW is the last such row. */
22445 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22447 struct glyph_row
*first_overlapping_row
;
22448 struct glyph_row
*last_overlapping_row
;
22450 struct glyph_row
*row
;
22452 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22453 if (row
->overlapping_p
)
22455 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22457 if (row
->used
[LEFT_MARGIN_AREA
])
22458 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
22460 if (row
->used
[TEXT_AREA
])
22461 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
22463 if (row
->used
[RIGHT_MARGIN_AREA
])
22464 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
22469 /* Return non-zero if W's cursor intersects rectangle R. */
22472 phys_cursor_in_rect_p (w
, r
)
22476 XRectangle cr
, result
;
22477 struct glyph
*cursor_glyph
;
22479 cursor_glyph
= get_phys_cursor_glyph (w
);
22482 /* r is relative to W's box, but w->phys_cursor.x is relative
22483 to left edge of W's TEXT area. Adjust it. */
22484 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22485 cr
.y
= w
->phys_cursor
.y
;
22486 cr
.width
= cursor_glyph
->pixel_width
;
22487 cr
.height
= w
->phys_cursor_height
;
22488 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22489 I assume the effect is the same -- and this is portable. */
22490 return x_intersect_rectangles (&cr
, r
, &result
);
22498 Draw a vertical window border to the right of window W if W doesn't
22499 have vertical scroll bars. */
22502 x_draw_vertical_border (w
)
22505 /* We could do better, if we knew what type of scroll-bar the adjacent
22506 windows (on either side) have... But we don't :-(
22507 However, I think this works ok. ++KFS 2003-04-25 */
22509 /* Redraw borders between horizontally adjacent windows. Don't
22510 do it for frames with vertical scroll bars because either the
22511 right scroll bar of a window, or the left scroll bar of its
22512 neighbor will suffice as a border. */
22513 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22516 if (!WINDOW_RIGHTMOST_P (w
)
22517 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22519 int x0
, x1
, y0
, y1
;
22521 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22524 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22527 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22529 else if (!WINDOW_LEFTMOST_P (w
)
22530 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22532 int x0
, x1
, y0
, y1
;
22534 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22537 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22540 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22545 /* Redraw the part of window W intersection rectangle FR. Pixel
22546 coordinates in FR are frame-relative. Call this function with
22547 input blocked. Value is non-zero if the exposure overwrites
22551 expose_window (w
, fr
)
22555 struct frame
*f
= XFRAME (w
->frame
);
22557 int mouse_face_overwritten_p
= 0;
22559 /* If window is not yet fully initialized, do nothing. This can
22560 happen when toolkit scroll bars are used and a window is split.
22561 Reconfiguring the scroll bar will generate an expose for a newly
22563 if (w
->current_matrix
== NULL
)
22566 /* When we're currently updating the window, display and current
22567 matrix usually don't agree. Arrange for a thorough display
22569 if (w
== updated_window
)
22571 SET_FRAME_GARBAGED (f
);
22575 /* Frame-relative pixel rectangle of W. */
22576 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22577 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22578 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22579 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22581 if (x_intersect_rectangles (fr
, &wr
, &r
))
22583 int yb
= window_text_bottom_y (w
);
22584 struct glyph_row
*row
;
22585 int cursor_cleared_p
;
22586 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22588 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22589 r
.x
, r
.y
, r
.width
, r
.height
));
22591 /* Convert to window coordinates. */
22592 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22593 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22595 /* Turn off the cursor. */
22596 if (!w
->pseudo_window_p
22597 && phys_cursor_in_rect_p (w
, &r
))
22599 x_clear_cursor (w
);
22600 cursor_cleared_p
= 1;
22603 cursor_cleared_p
= 0;
22605 /* Update lines intersecting rectangle R. */
22606 first_overlapping_row
= last_overlapping_row
= NULL
;
22607 for (row
= w
->current_matrix
->rows
;
22612 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22614 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22615 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22616 || (r
.y
>= y0
&& r
.y
< y1
)
22617 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22619 /* A header line may be overlapping, but there is no need
22620 to fix overlapping areas for them. KFS 2005-02-12 */
22621 if (row
->overlapping_p
&& !row
->mode_line_p
)
22623 if (first_overlapping_row
== NULL
)
22624 first_overlapping_row
= row
;
22625 last_overlapping_row
= row
;
22628 if (expose_line (w
, row
, &r
))
22629 mouse_face_overwritten_p
= 1;
22636 /* Display the mode line if there is one. */
22637 if (WINDOW_WANTS_MODELINE_P (w
)
22638 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22640 && row
->y
< r
.y
+ r
.height
)
22642 if (expose_line (w
, row
, &r
))
22643 mouse_face_overwritten_p
= 1;
22646 if (!w
->pseudo_window_p
)
22648 /* Fix the display of overlapping rows. */
22649 if (first_overlapping_row
)
22650 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22652 /* Draw border between windows. */
22653 x_draw_vertical_border (w
);
22655 /* Turn the cursor on again. */
22656 if (cursor_cleared_p
)
22657 update_window_cursor (w
, 1);
22661 return mouse_face_overwritten_p
;
22666 /* Redraw (parts) of all windows in the window tree rooted at W that
22667 intersect R. R contains frame pixel coordinates. Value is
22668 non-zero if the exposure overwrites mouse-face. */
22671 expose_window_tree (w
, r
)
22675 struct frame
*f
= XFRAME (w
->frame
);
22676 int mouse_face_overwritten_p
= 0;
22678 while (w
&& !FRAME_GARBAGED_P (f
))
22680 if (!NILP (w
->hchild
))
22681 mouse_face_overwritten_p
22682 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22683 else if (!NILP (w
->vchild
))
22684 mouse_face_overwritten_p
22685 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22687 mouse_face_overwritten_p
|= expose_window (w
, r
);
22689 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22692 return mouse_face_overwritten_p
;
22697 Redisplay an exposed area of frame F. X and Y are the upper-left
22698 corner of the exposed rectangle. W and H are width and height of
22699 the exposed area. All are pixel values. W or H zero means redraw
22700 the entire frame. */
22703 expose_frame (f
, x
, y
, w
, h
)
22708 int mouse_face_overwritten_p
= 0;
22710 TRACE ((stderr
, "expose_frame "));
22712 /* No need to redraw if frame will be redrawn soon. */
22713 if (FRAME_GARBAGED_P (f
))
22715 TRACE ((stderr
, " garbaged\n"));
22719 /* If basic faces haven't been realized yet, there is no point in
22720 trying to redraw anything. This can happen when we get an expose
22721 event while Emacs is starting, e.g. by moving another window. */
22722 if (FRAME_FACE_CACHE (f
) == NULL
22723 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22725 TRACE ((stderr
, " no faces\n"));
22729 if (w
== 0 || h
== 0)
22732 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22733 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22743 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22744 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22746 if (WINDOWP (f
->tool_bar_window
))
22747 mouse_face_overwritten_p
22748 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22750 #ifdef HAVE_X_WINDOWS
22752 #ifndef USE_X_TOOLKIT
22753 if (WINDOWP (f
->menu_bar_window
))
22754 mouse_face_overwritten_p
22755 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22756 #endif /* not USE_X_TOOLKIT */
22760 /* Some window managers support a focus-follows-mouse style with
22761 delayed raising of frames. Imagine a partially obscured frame,
22762 and moving the mouse into partially obscured mouse-face on that
22763 frame. The visible part of the mouse-face will be highlighted,
22764 then the WM raises the obscured frame. With at least one WM, KDE
22765 2.1, Emacs is not getting any event for the raising of the frame
22766 (even tried with SubstructureRedirectMask), only Expose events.
22767 These expose events will draw text normally, i.e. not
22768 highlighted. Which means we must redo the highlight here.
22769 Subsume it under ``we love X''. --gerd 2001-08-15 */
22770 /* Included in Windows version because Windows most likely does not
22771 do the right thing if any third party tool offers
22772 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22773 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22775 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22776 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22778 int x
= dpyinfo
->mouse_face_mouse_x
;
22779 int y
= dpyinfo
->mouse_face_mouse_y
;
22780 clear_mouse_face (dpyinfo
);
22781 note_mouse_highlight (f
, x
, y
);
22788 Determine the intersection of two rectangles R1 and R2. Return
22789 the intersection in *RESULT. Value is non-zero if RESULT is not
22793 x_intersect_rectangles (r1
, r2
, result
)
22794 XRectangle
*r1
, *r2
, *result
;
22796 XRectangle
*left
, *right
;
22797 XRectangle
*upper
, *lower
;
22798 int intersection_p
= 0;
22800 /* Rearrange so that R1 is the left-most rectangle. */
22802 left
= r1
, right
= r2
;
22804 left
= r2
, right
= r1
;
22806 /* X0 of the intersection is right.x0, if this is inside R1,
22807 otherwise there is no intersection. */
22808 if (right
->x
<= left
->x
+ left
->width
)
22810 result
->x
= right
->x
;
22812 /* The right end of the intersection is the minimum of the
22813 the right ends of left and right. */
22814 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22817 /* Same game for Y. */
22819 upper
= r1
, lower
= r2
;
22821 upper
= r2
, lower
= r1
;
22823 /* The upper end of the intersection is lower.y0, if this is inside
22824 of upper. Otherwise, there is no intersection. */
22825 if (lower
->y
<= upper
->y
+ upper
->height
)
22827 result
->y
= lower
->y
;
22829 /* The lower end of the intersection is the minimum of the lower
22830 ends of upper and lower. */
22831 result
->height
= (min (lower
->y
+ lower
->height
,
22832 upper
->y
+ upper
->height
)
22834 intersection_p
= 1;
22838 return intersection_p
;
22841 #endif /* HAVE_WINDOW_SYSTEM */
22844 /***********************************************************************
22846 ***********************************************************************/
22851 Vwith_echo_area_save_vector
= Qnil
;
22852 staticpro (&Vwith_echo_area_save_vector
);
22854 Vmessage_stack
= Qnil
;
22855 staticpro (&Vmessage_stack
);
22857 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22858 staticpro (&Qinhibit_redisplay
);
22860 message_dolog_marker1
= Fmake_marker ();
22861 staticpro (&message_dolog_marker1
);
22862 message_dolog_marker2
= Fmake_marker ();
22863 staticpro (&message_dolog_marker2
);
22864 message_dolog_marker3
= Fmake_marker ();
22865 staticpro (&message_dolog_marker3
);
22868 defsubr (&Sdump_frame_glyph_matrix
);
22869 defsubr (&Sdump_glyph_matrix
);
22870 defsubr (&Sdump_glyph_row
);
22871 defsubr (&Sdump_tool_bar_row
);
22872 defsubr (&Strace_redisplay
);
22873 defsubr (&Strace_to_stderr
);
22875 #ifdef HAVE_WINDOW_SYSTEM
22876 defsubr (&Stool_bar_lines_needed
);
22877 defsubr (&Slookup_image_map
);
22879 defsubr (&Sformat_mode_line
);
22881 staticpro (&Qmenu_bar_update_hook
);
22882 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22884 staticpro (&Qoverriding_terminal_local_map
);
22885 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22887 staticpro (&Qoverriding_local_map
);
22888 Qoverriding_local_map
= intern ("overriding-local-map");
22890 staticpro (&Qwindow_scroll_functions
);
22891 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22893 staticpro (&Qredisplay_end_trigger_functions
);
22894 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22896 staticpro (&Qinhibit_point_motion_hooks
);
22897 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22899 QCdata
= intern (":data");
22900 staticpro (&QCdata
);
22901 Qdisplay
= intern ("display");
22902 staticpro (&Qdisplay
);
22903 Qspace_width
= intern ("space-width");
22904 staticpro (&Qspace_width
);
22905 Qraise
= intern ("raise");
22906 staticpro (&Qraise
);
22907 Qslice
= intern ("slice");
22908 staticpro (&Qslice
);
22909 Qspace
= intern ("space");
22910 staticpro (&Qspace
);
22911 Qmargin
= intern ("margin");
22912 staticpro (&Qmargin
);
22913 Qpointer
= intern ("pointer");
22914 staticpro (&Qpointer
);
22915 Qleft_margin
= intern ("left-margin");
22916 staticpro (&Qleft_margin
);
22917 Qright_margin
= intern ("right-margin");
22918 staticpro (&Qright_margin
);
22919 Qcenter
= intern ("center");
22920 staticpro (&Qcenter
);
22921 Qline_height
= intern ("line-height");
22922 staticpro (&Qline_height
);
22923 QCalign_to
= intern (":align-to");
22924 staticpro (&QCalign_to
);
22925 QCrelative_width
= intern (":relative-width");
22926 staticpro (&QCrelative_width
);
22927 QCrelative_height
= intern (":relative-height");
22928 staticpro (&QCrelative_height
);
22929 QCeval
= intern (":eval");
22930 staticpro (&QCeval
);
22931 QCpropertize
= intern (":propertize");
22932 staticpro (&QCpropertize
);
22933 QCfile
= intern (":file");
22934 staticpro (&QCfile
);
22935 Qfontified
= intern ("fontified");
22936 staticpro (&Qfontified
);
22937 Qfontification_functions
= intern ("fontification-functions");
22938 staticpro (&Qfontification_functions
);
22939 Qtrailing_whitespace
= intern ("trailing-whitespace");
22940 staticpro (&Qtrailing_whitespace
);
22941 Qescape_glyph
= intern ("escape-glyph");
22942 staticpro (&Qescape_glyph
);
22943 Qnobreak_space
= intern ("nobreak-space");
22944 staticpro (&Qnobreak_space
);
22945 Qimage
= intern ("image");
22946 staticpro (&Qimage
);
22947 QCmap
= intern (":map");
22948 staticpro (&QCmap
);
22949 QCpointer
= intern (":pointer");
22950 staticpro (&QCpointer
);
22951 Qrect
= intern ("rect");
22952 staticpro (&Qrect
);
22953 Qcircle
= intern ("circle");
22954 staticpro (&Qcircle
);
22955 Qpoly
= intern ("poly");
22956 staticpro (&Qpoly
);
22957 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22958 staticpro (&Qmessage_truncate_lines
);
22959 Qgrow_only
= intern ("grow-only");
22960 staticpro (&Qgrow_only
);
22961 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22962 staticpro (&Qinhibit_menubar_update
);
22963 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22964 staticpro (&Qinhibit_eval_during_redisplay
);
22965 Qposition
= intern ("position");
22966 staticpro (&Qposition
);
22967 Qbuffer_position
= intern ("buffer-position");
22968 staticpro (&Qbuffer_position
);
22969 Qobject
= intern ("object");
22970 staticpro (&Qobject
);
22971 Qbar
= intern ("bar");
22973 Qhbar
= intern ("hbar");
22974 staticpro (&Qhbar
);
22975 Qbox
= intern ("box");
22977 Qhollow
= intern ("hollow");
22978 staticpro (&Qhollow
);
22979 Qhand
= intern ("hand");
22980 staticpro (&Qhand
);
22981 Qarrow
= intern ("arrow");
22982 staticpro (&Qarrow
);
22983 Qtext
= intern ("text");
22984 staticpro (&Qtext
);
22985 Qrisky_local_variable
= intern ("risky-local-variable");
22986 staticpro (&Qrisky_local_variable
);
22987 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22988 staticpro (&Qinhibit_free_realized_faces
);
22990 list_of_error
= Fcons (Fcons (intern ("error"),
22991 Fcons (intern ("void-variable"), Qnil
)),
22993 staticpro (&list_of_error
);
22995 Qlast_arrow_position
= intern ("last-arrow-position");
22996 staticpro (&Qlast_arrow_position
);
22997 Qlast_arrow_string
= intern ("last-arrow-string");
22998 staticpro (&Qlast_arrow_string
);
23000 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
23001 staticpro (&Qoverlay_arrow_string
);
23002 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
23003 staticpro (&Qoverlay_arrow_bitmap
);
23005 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23006 staticpro (&echo_buffer
[0]);
23007 staticpro (&echo_buffer
[1]);
23009 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23010 staticpro (&echo_area_buffer
[0]);
23011 staticpro (&echo_area_buffer
[1]);
23013 Vmessages_buffer_name
= build_string ("*Messages*");
23014 staticpro (&Vmessages_buffer_name
);
23016 mode_line_proptrans_alist
= Qnil
;
23017 staticpro (&mode_line_proptrans_alist
);
23018 mode_line_string_list
= Qnil
;
23019 staticpro (&mode_line_string_list
);
23020 mode_line_string_face
= Qnil
;
23021 staticpro (&mode_line_string_face
);
23022 mode_line_string_face_prop
= Qnil
;
23023 staticpro (&mode_line_string_face_prop
);
23024 Vmode_line_unwind_vector
= Qnil
;
23025 staticpro (&Vmode_line_unwind_vector
);
23027 help_echo_string
= Qnil
;
23028 staticpro (&help_echo_string
);
23029 help_echo_object
= Qnil
;
23030 staticpro (&help_echo_object
);
23031 help_echo_window
= Qnil
;
23032 staticpro (&help_echo_window
);
23033 previous_help_echo_string
= Qnil
;
23034 staticpro (&previous_help_echo_string
);
23035 help_echo_pos
= -1;
23037 #ifdef HAVE_WINDOW_SYSTEM
23038 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23039 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23040 For example, if a block cursor is over a tab, it will be drawn as
23041 wide as that tab on the display. */);
23042 x_stretch_cursor_p
= 0;
23045 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23046 doc
: /* *Non-nil means highlight trailing whitespace.
23047 The face used for trailing whitespace is `trailing-whitespace'. */);
23048 Vshow_trailing_whitespace
= Qnil
;
23050 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23051 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23052 A value of t means highlight the character itself (for nobreak space,
23053 use face `nobreak-space').
23054 A value of nil means no highlighting.
23055 Other values mean display the escape glyph followed by an ordinary
23056 space or ordinary hyphen. */);
23057 Vnobreak_char_display
= Qt
;
23059 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23060 doc
: /* *The pointer shape to show in void text areas.
23061 A value of nil means to show the text pointer. Other options are `arrow',
23062 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23063 Vvoid_text_area_pointer
= Qarrow
;
23065 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23066 doc
: /* Non-nil means don't actually do any redisplay.
23067 This is used for internal purposes. */);
23068 Vinhibit_redisplay
= Qnil
;
23070 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23071 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23072 Vglobal_mode_string
= Qnil
;
23074 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23075 doc
: /* Marker for where to display an arrow on top of the buffer text.
23076 This must be the beginning of a line in order to work.
23077 See also `overlay-arrow-string'. */);
23078 Voverlay_arrow_position
= Qnil
;
23080 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23081 doc
: /* String to display as an arrow in non-window frames.
23082 See also `overlay-arrow-position'. */);
23083 Voverlay_arrow_string
= build_string ("=>");
23085 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23086 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23087 The symbols on this list are examined during redisplay to determine
23088 where to display overlay arrows. */);
23089 Voverlay_arrow_variable_list
23090 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23092 DEFVAR_INT ("scroll-step", &scroll_step
,
23093 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23094 If that fails to bring point back on frame, point is centered instead.
23095 If this is zero, point is always centered after it moves off frame.
23096 If you want scrolling to always be a line at a time, you should set
23097 `scroll-conservatively' to a large value rather than set this to 1. */);
23099 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23100 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23101 A value of zero means to scroll the text to center point vertically
23102 in the window. */);
23103 scroll_conservatively
= 0;
23105 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23106 doc
: /* *Number of lines of margin at the top and bottom of a window.
23107 Recenter the window whenever point gets within this many lines
23108 of the top or bottom of the window. */);
23111 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23112 doc
: /* Pixels per inch value for non-window system displays.
23113 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23114 Vdisplay_pixels_per_inch
= make_float (72.0);
23117 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23120 DEFVAR_BOOL ("truncate-partial-width-windows",
23121 &truncate_partial_width_windows
,
23122 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23123 truncate_partial_width_windows
= 1;
23125 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23126 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23127 Any other value means to use the appropriate face, `mode-line',
23128 `header-line', or `menu' respectively. */);
23129 mode_line_inverse_video
= 1;
23131 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23132 doc
: /* *Maximum buffer size for which line number should be displayed.
23133 If the buffer is bigger than this, the line number does not appear
23134 in the mode line. A value of nil means no limit. */);
23135 Vline_number_display_limit
= Qnil
;
23137 DEFVAR_INT ("line-number-display-limit-width",
23138 &line_number_display_limit_width
,
23139 doc
: /* *Maximum line width (in characters) for line number display.
23140 If the average length of the lines near point is bigger than this, then the
23141 line number may be omitted from the mode line. */);
23142 line_number_display_limit_width
= 200;
23144 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23145 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23146 highlight_nonselected_windows
= 0;
23148 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23149 doc
: /* Non-nil if more than one frame is visible on this display.
23150 Minibuffer-only frames don't count, but iconified frames do.
23151 This variable is not guaranteed to be accurate except while processing
23152 `frame-title-format' and `icon-title-format'. */);
23154 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23155 doc
: /* Template for displaying the title bar of visible frames.
23156 \(Assuming the window manager supports this feature.)
23157 This variable has the same structure as `mode-line-format' (which see),
23158 and is used only on frames for which no explicit name has been set
23159 \(see `modify-frame-parameters'). */);
23161 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23162 doc
: /* Template for displaying the title bar of an iconified frame.
23163 \(Assuming the window manager supports this feature.)
23164 This variable has the same structure as `mode-line-format' (which see),
23165 and is used only on frames for which no explicit name has been set
23166 \(see `modify-frame-parameters'). */);
23168 = Vframe_title_format
23169 = Fcons (intern ("multiple-frames"),
23170 Fcons (build_string ("%b"),
23171 Fcons (Fcons (empty_string
,
23172 Fcons (intern ("invocation-name"),
23173 Fcons (build_string ("@"),
23174 Fcons (intern ("system-name"),
23178 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23179 doc
: /* Maximum number of lines to keep in the message log buffer.
23180 If nil, disable message logging. If t, log messages but don't truncate
23181 the buffer when it becomes large. */);
23182 Vmessage_log_max
= make_number (50);
23184 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23185 doc
: /* Functions called before redisplay, if window sizes have changed.
23186 The value should be a list of functions that take one argument.
23187 Just before redisplay, for each frame, if any of its windows have changed
23188 size since the last redisplay, or have been split or deleted,
23189 all the functions in the list are called, with the frame as argument. */);
23190 Vwindow_size_change_functions
= Qnil
;
23192 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23193 doc
: /* List of functions to call before redisplaying a window with scrolling.
23194 Each function is called with two arguments, the window
23195 and its new display-start position. Note that the value of `window-end'
23196 is not valid when these functions are called. */);
23197 Vwindow_scroll_functions
= Qnil
;
23199 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23200 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23201 Each function is called with two arguments, the window and the end trigger value.
23202 See `set-window-redisplay-end-trigger'. */);
23203 Vredisplay_end_trigger_functions
= Qnil
;
23205 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23206 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23207 mouse_autoselect_window
= 0;
23209 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23210 doc
: /* *Non-nil means automatically resize tool-bars.
23211 This increases a tool-bar's height if not all tool-bar items are visible.
23212 It decreases a tool-bar's height when it would display blank lines
23214 auto_resize_tool_bars_p
= 1;
23216 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23217 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23218 auto_raise_tool_bar_buttons_p
= 1;
23220 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23221 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23222 make_cursor_line_fully_visible_p
= 1;
23224 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23225 doc
: /* *Margin around tool-bar buttons in pixels.
23226 If an integer, use that for both horizontal and vertical margins.
23227 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23228 HORZ specifying the horizontal margin, and VERT specifying the
23229 vertical margin. */);
23230 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23232 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23233 doc
: /* *Relief thickness of tool-bar buttons. */);
23234 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23236 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23237 doc
: /* List of functions to call to fontify regions of text.
23238 Each function is called with one argument POS. Functions must
23239 fontify a region starting at POS in the current buffer, and give
23240 fontified regions the property `fontified'. */);
23241 Vfontification_functions
= Qnil
;
23242 Fmake_variable_buffer_local (Qfontification_functions
);
23244 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23245 &unibyte_display_via_language_environment
,
23246 doc
: /* *Non-nil means display unibyte text according to language environment.
23247 Specifically this means that unibyte non-ASCII characters
23248 are displayed by converting them to the equivalent multibyte characters
23249 according to the current language environment. As a result, they are
23250 displayed according to the current fontset. */);
23251 unibyte_display_via_language_environment
= 0;
23253 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23254 doc
: /* *Maximum height for resizing mini-windows.
23255 If a float, it specifies a fraction of the mini-window frame's height.
23256 If an integer, it specifies a number of lines. */);
23257 Vmax_mini_window_height
= make_float (0.25);
23259 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23260 doc
: /* *How to resize mini-windows.
23261 A value of nil means don't automatically resize mini-windows.
23262 A value of t means resize them to fit the text displayed in them.
23263 A value of `grow-only', the default, means let mini-windows grow
23264 only, until their display becomes empty, at which point the windows
23265 go back to their normal size. */);
23266 Vresize_mini_windows
= Qgrow_only
;
23268 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23269 doc
: /* Alist specifying how to blink the cursor off.
23270 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23271 `cursor-type' frame-parameter or variable equals ON-STATE,
23272 comparing using `equal', Emacs uses OFF-STATE to specify
23273 how to blink it off. */);
23274 Vblink_cursor_alist
= Qnil
;
23276 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23277 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23278 automatic_hscrolling_p
= 1;
23280 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23281 doc
: /* *How many columns away from the window edge point is allowed to get
23282 before automatic hscrolling will horizontally scroll the window. */);
23283 hscroll_margin
= 5;
23285 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23286 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23287 When point is less than `automatic-hscroll-margin' columns from the window
23288 edge, automatic hscrolling will scroll the window by the amount of columns
23289 determined by this variable. If its value is a positive integer, scroll that
23290 many columns. If it's a positive floating-point number, it specifies the
23291 fraction of the window's width to scroll. If it's nil or zero, point will be
23292 centered horizontally after the scroll. Any other value, including negative
23293 numbers, are treated as if the value were zero.
23295 Automatic hscrolling always moves point outside the scroll margin, so if
23296 point was more than scroll step columns inside the margin, the window will
23297 scroll more than the value given by the scroll step.
23299 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23300 and `scroll-right' overrides this variable's effect. */);
23301 Vhscroll_step
= make_number (0);
23303 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23304 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23305 Bind this around calls to `message' to let it take effect. */);
23306 message_truncate_lines
= 0;
23308 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23309 doc
: /* Normal hook run to update the menu bar definitions.
23310 Redisplay runs this hook before it redisplays the menu bar.
23311 This is used to update submenus such as Buffers,
23312 whose contents depend on various data. */);
23313 Vmenu_bar_update_hook
= Qnil
;
23315 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23316 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23317 inhibit_menubar_update
= 0;
23319 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23320 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23321 inhibit_eval_during_redisplay
= 0;
23323 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23324 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23325 inhibit_free_realized_faces
= 0;
23328 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23329 doc
: /* Inhibit try_window_id display optimization. */);
23330 inhibit_try_window_id
= 0;
23332 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23333 doc
: /* Inhibit try_window_reusing display optimization. */);
23334 inhibit_try_window_reusing
= 0;
23336 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23337 doc
: /* Inhibit try_cursor_movement display optimization. */);
23338 inhibit_try_cursor_movement
= 0;
23339 #endif /* GLYPH_DEBUG */
23343 /* Initialize this module when Emacs starts. */
23348 Lisp_Object root_window
;
23349 struct window
*mini_w
;
23351 current_header_line_height
= current_mode_line_height
= -1;
23353 CHARPOS (this_line_start_pos
) = 0;
23355 mini_w
= XWINDOW (minibuf_window
);
23356 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23358 if (!noninteractive
)
23360 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23363 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23364 set_window_height (root_window
,
23365 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23367 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23368 set_window_height (minibuf_window
, 1, 0);
23370 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23371 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23373 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23374 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23375 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23377 /* The default ellipsis glyphs `...'. */
23378 for (i
= 0; i
< 3; ++i
)
23379 default_invis_vector
[i
] = make_number ('.');
23383 /* Allocate the buffer for frame titles.
23384 Also used for `format-mode-line'. */
23386 mode_line_noprop_buf
= (char *) xmalloc (size
);
23387 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23388 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23389 mode_line_target
= MODE_LINE_DISPLAY
;
23392 help_echo_showing_p
= 0;
23396 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23397 (do not change this comment) */