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. */
6758 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6760 int nbytes
, nlflag
, multibyte
;
6762 if (!NILP (Vmemory_full
))
6765 if (!NILP (Vmessage_log_max
))
6767 struct buffer
*oldbuf
;
6768 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6769 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6770 int point_at_end
= 0;
6772 Lisp_Object old_deactivate_mark
, tem
;
6773 struct gcpro gcpro1
;
6775 old_deactivate_mark
= Vdeactivate_mark
;
6776 oldbuf
= current_buffer
;
6777 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6778 current_buffer
->undo_list
= Qt
;
6780 oldpoint
= message_dolog_marker1
;
6781 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6782 oldbegv
= message_dolog_marker2
;
6783 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6784 oldzv
= message_dolog_marker3
;
6785 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6786 GCPRO1 (old_deactivate_mark
);
6794 BEGV_BYTE
= BEG_BYTE
;
6797 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6799 /* Insert the string--maybe converting multibyte to single byte
6800 or vice versa, so that all the text fits the buffer. */
6802 && NILP (current_buffer
->enable_multibyte_characters
))
6804 int i
, c
, char_bytes
;
6805 unsigned char work
[1];
6807 /* Convert a multibyte string to single-byte
6808 for the *Message* buffer. */
6809 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6811 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6812 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6814 : multibyte_char_to_unibyte (c
, Qnil
));
6815 insert_1_both (work
, 1, 1, 1, 0, 0);
6818 else if (! multibyte
6819 && ! NILP (current_buffer
->enable_multibyte_characters
))
6821 int i
, c
, char_bytes
;
6822 unsigned char *msg
= (unsigned char *) m
;
6823 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6824 /* Convert a single-byte string to multibyte
6825 for the *Message* buffer. */
6826 for (i
= 0; i
< nbytes
; i
++)
6828 c
= unibyte_char_to_multibyte (msg
[i
]);
6829 char_bytes
= CHAR_STRING (c
, str
);
6830 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6834 insert_1 (m
, nbytes
, 1, 0, 0);
6838 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6839 insert_1 ("\n", 1, 1, 0, 0);
6841 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6843 this_bol_byte
= PT_BYTE
;
6845 /* See if this line duplicates the previous one.
6846 If so, combine duplicates. */
6849 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6851 prev_bol_byte
= PT_BYTE
;
6853 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6854 this_bol
, this_bol_byte
);
6857 del_range_both (prev_bol
, prev_bol_byte
,
6858 this_bol
, this_bol_byte
, 0);
6864 /* If you change this format, don't forget to also
6865 change message_log_check_duplicate. */
6866 sprintf (dupstr
, " [%d times]", dup
);
6867 duplen
= strlen (dupstr
);
6868 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6869 insert_1 (dupstr
, duplen
, 1, 0, 1);
6874 /* If we have more than the desired maximum number of lines
6875 in the *Messages* buffer now, delete the oldest ones.
6876 This is safe because we don't have undo in this buffer. */
6878 if (NATNUMP (Vmessage_log_max
))
6880 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6881 -XFASTINT (Vmessage_log_max
) - 1, 0);
6882 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6885 BEGV
= XMARKER (oldbegv
)->charpos
;
6886 BEGV_BYTE
= marker_byte_position (oldbegv
);
6895 ZV
= XMARKER (oldzv
)->charpos
;
6896 ZV_BYTE
= marker_byte_position (oldzv
);
6900 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6902 /* We can't do Fgoto_char (oldpoint) because it will run some
6904 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6905 XMARKER (oldpoint
)->bytepos
);
6908 unchain_marker (XMARKER (oldpoint
));
6909 unchain_marker (XMARKER (oldbegv
));
6910 unchain_marker (XMARKER (oldzv
));
6912 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6913 set_buffer_internal (oldbuf
);
6915 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6916 message_log_need_newline
= !nlflag
;
6917 Vdeactivate_mark
= old_deactivate_mark
;
6922 /* We are at the end of the buffer after just having inserted a newline.
6923 (Note: We depend on the fact we won't be crossing the gap.)
6924 Check to see if the most recent message looks a lot like the previous one.
6925 Return 0 if different, 1 if the new one should just replace it, or a
6926 value N > 1 if we should also append " [N times]". */
6929 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6930 int prev_bol
, this_bol
;
6931 int prev_bol_byte
, this_bol_byte
;
6934 int len
= Z_BYTE
- 1 - this_bol_byte
;
6936 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6937 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6939 for (i
= 0; i
< len
; i
++)
6941 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6949 if (*p1
++ == ' ' && *p1
++ == '[')
6952 while (*p1
>= '0' && *p1
<= '9')
6953 n
= n
* 10 + *p1
++ - '0';
6954 if (strncmp (p1
, " times]\n", 8) == 0)
6961 /* Display an echo area message M with a specified length of NBYTES
6962 bytes. The string may include null characters. If M is 0, clear
6963 out any existing message, and let the mini-buffer text show
6966 The buffer M must continue to exist until after the echo area gets
6967 cleared or some other message gets displayed there. This means do
6968 not pass text that is stored in a Lisp string; do not pass text in
6969 a buffer that was alloca'd. */
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. */
8029 set_message (s
, string
, nbytes
, multibyte_p
)
8032 int nbytes
, multibyte_p
;
8034 message_enable_multibyte
8035 = ((s
&& multibyte_p
)
8036 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8038 with_echo_area_buffer (0, 0, set_message_1
,
8039 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8040 message_buf_print
= 0;
8041 help_echo_showing_p
= 0;
8045 /* Helper function for set_message. Arguments have the same meaning
8046 as there, with A1 corresponding to S and A2 corresponding to STRING
8047 This function is called with the echo area buffer being
8051 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8054 EMACS_INT nbytes
, multibyte_p
;
8056 const char *s
= (const char *) a1
;
8057 Lisp_Object string
= a2
;
8059 /* Change multibyteness of the echo buffer appropriately. */
8060 if (message_enable_multibyte
8061 != !NILP (current_buffer
->enable_multibyte_characters
))
8062 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8064 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8066 /* Insert new message at BEG. */
8067 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8070 if (STRINGP (string
))
8075 nbytes
= SBYTES (string
);
8076 nchars
= string_byte_to_char (string
, nbytes
);
8078 /* This function takes care of single/multibyte conversion. We
8079 just have to ensure that the echo area buffer has the right
8080 setting of enable_multibyte_characters. */
8081 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8086 nbytes
= strlen (s
);
8088 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8090 /* Convert from multi-byte to single-byte. */
8092 unsigned char work
[1];
8094 /* Convert a multibyte string to single-byte. */
8095 for (i
= 0; i
< nbytes
; i
+= n
)
8097 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8098 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8100 : multibyte_char_to_unibyte (c
, Qnil
));
8101 insert_1_both (work
, 1, 1, 1, 0, 0);
8104 else if (!multibyte_p
8105 && !NILP (current_buffer
->enable_multibyte_characters
))
8107 /* Convert from single-byte to multi-byte. */
8109 const unsigned char *msg
= (const unsigned char *) s
;
8110 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8112 /* Convert a single-byte string to multibyte. */
8113 for (i
= 0; i
< nbytes
; i
++)
8115 c
= unibyte_char_to_multibyte (msg
[i
]);
8116 n
= CHAR_STRING (c
, str
);
8117 insert_1_both (str
, 1, n
, 1, 0, 0);
8121 insert_1 (s
, nbytes
, 1, 0, 0);
8128 /* Clear messages. CURRENT_P non-zero means clear the current
8129 message. LAST_DISPLAYED_P non-zero means clear the message
8133 clear_message (current_p
, last_displayed_p
)
8134 int current_p
, last_displayed_p
;
8138 echo_area_buffer
[0] = Qnil
;
8139 message_cleared_p
= 1;
8142 if (last_displayed_p
)
8143 echo_area_buffer
[1] = Qnil
;
8145 message_buf_print
= 0;
8148 /* Clear garbaged frames.
8150 This function is used where the old redisplay called
8151 redraw_garbaged_frames which in turn called redraw_frame which in
8152 turn called clear_frame. The call to clear_frame was a source of
8153 flickering. I believe a clear_frame is not necessary. It should
8154 suffice in the new redisplay to invalidate all current matrices,
8155 and ensure a complete redisplay of all windows. */
8158 clear_garbaged_frames ()
8162 Lisp_Object tail
, frame
;
8163 int changed_count
= 0;
8165 FOR_EACH_FRAME (tail
, frame
)
8167 struct frame
*f
= XFRAME (frame
);
8169 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8173 Fredraw_frame (frame
);
8174 f
->force_flush_display_p
= 1;
8176 clear_current_matrices (f
);
8185 ++windows_or_buffers_changed
;
8190 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8191 is non-zero update selected_frame. Value is non-zero if the
8192 mini-windows height has been changed. */
8195 echo_area_display (update_frame_p
)
8198 Lisp_Object mini_window
;
8201 int window_height_changed_p
= 0;
8202 struct frame
*sf
= SELECTED_FRAME ();
8204 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8205 w
= XWINDOW (mini_window
);
8206 f
= XFRAME (WINDOW_FRAME (w
));
8208 /* Don't display if frame is invisible or not yet initialized. */
8209 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8212 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8214 #ifdef HAVE_WINDOW_SYSTEM
8215 /* When Emacs starts, selected_frame may be a visible terminal
8216 frame, even if we run under a window system. If we let this
8217 through, a message would be displayed on the terminal. */
8218 if (EQ (selected_frame
, Vterminal_frame
)
8219 && !NILP (Vwindow_system
))
8221 #endif /* HAVE_WINDOW_SYSTEM */
8224 /* Redraw garbaged frames. */
8226 clear_garbaged_frames ();
8228 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8230 echo_area_window
= mini_window
;
8231 window_height_changed_p
= display_echo_area (w
);
8232 w
->must_be_updated_p
= 1;
8234 /* Update the display, unless called from redisplay_internal.
8235 Also don't update the screen during redisplay itself. The
8236 update will happen at the end of redisplay, and an update
8237 here could cause confusion. */
8238 if (update_frame_p
&& !redisplaying_p
)
8242 /* If the display update has been interrupted by pending
8243 input, update mode lines in the frame. Due to the
8244 pending input, it might have been that redisplay hasn't
8245 been called, so that mode lines above the echo area are
8246 garbaged. This looks odd, so we prevent it here. */
8247 if (!display_completed
)
8248 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8250 if (window_height_changed_p
8251 /* Don't do this if Emacs is shutting down. Redisplay
8252 needs to run hooks. */
8253 && !NILP (Vrun_hooks
))
8255 /* Must update other windows. Likewise as in other
8256 cases, don't let this update be interrupted by
8258 int count
= SPECPDL_INDEX ();
8259 specbind (Qredisplay_dont_pause
, Qt
);
8260 windows_or_buffers_changed
= 1;
8261 redisplay_internal (0);
8262 unbind_to (count
, Qnil
);
8264 else if (FRAME_WINDOW_P (f
) && n
== 0)
8266 /* Window configuration is the same as before.
8267 Can do with a display update of the echo area,
8268 unless we displayed some mode lines. */
8269 update_single_window (w
, 1);
8270 rif
->flush_display (f
);
8273 update_frame (f
, 1, 1);
8275 /* If cursor is in the echo area, make sure that the next
8276 redisplay displays the minibuffer, so that the cursor will
8277 be replaced with what the minibuffer wants. */
8278 if (cursor_in_echo_area
)
8279 ++windows_or_buffers_changed
;
8282 else if (!EQ (mini_window
, selected_window
))
8283 windows_or_buffers_changed
++;
8285 /* The current message is now also the last one displayed. */
8286 echo_area_buffer
[1] = echo_area_buffer
[0];
8288 /* Prevent redisplay optimization in redisplay_internal by resetting
8289 this_line_start_pos. This is done because the mini-buffer now
8290 displays the message instead of its buffer text. */
8291 if (EQ (mini_window
, selected_window
))
8292 CHARPOS (this_line_start_pos
) = 0;
8294 return window_height_changed_p
;
8299 /***********************************************************************
8300 Mode Lines and Frame Titles
8301 ***********************************************************************/
8303 /* A buffer for constructing non-propertized mode-line strings and
8304 frame titles in it; allocated from the heap in init_xdisp and
8305 resized as needed in store_mode_line_noprop_char. */
8307 static char *mode_line_noprop_buf
;
8309 /* The buffer's end, and a current output position in it. */
8311 static char *mode_line_noprop_buf_end
;
8312 static char *mode_line_noprop_ptr
;
8314 #define MODE_LINE_NOPROP_LEN(start) \
8315 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8318 MODE_LINE_DISPLAY
= 0,
8324 /* Alist that caches the results of :propertize.
8325 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8326 static Lisp_Object mode_line_proptrans_alist
;
8328 /* List of strings making up the mode-line. */
8329 static Lisp_Object mode_line_string_list
;
8331 /* Base face property when building propertized mode line string. */
8332 static Lisp_Object mode_line_string_face
;
8333 static Lisp_Object mode_line_string_face_prop
;
8336 /* Unwind data for mode line strings */
8338 static Lisp_Object Vmode_line_unwind_vector
;
8341 format_mode_line_unwind_data (obuf
)
8342 struct buffer
*obuf
;
8346 /* Reduce consing by keeping one vector in
8347 Vwith_echo_area_save_vector. */
8348 vector
= Vmode_line_unwind_vector
;
8349 Vmode_line_unwind_vector
= Qnil
;
8352 vector
= Fmake_vector (make_number (7), Qnil
);
8354 AREF (vector
, 0) = make_number (mode_line_target
);
8355 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8356 AREF (vector
, 2) = mode_line_string_list
;
8357 AREF (vector
, 3) = mode_line_proptrans_alist
;
8358 AREF (vector
, 4) = mode_line_string_face
;
8359 AREF (vector
, 5) = mode_line_string_face_prop
;
8362 XSETBUFFER (AREF (vector
, 6), obuf
);
8364 AREF (vector
, 6) = Qnil
;
8370 unwind_format_mode_line (vector
)
8373 mode_line_target
= XINT (AREF (vector
, 0));
8374 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8375 mode_line_string_list
= AREF (vector
, 2);
8376 mode_line_proptrans_alist
= AREF (vector
, 3);
8377 mode_line_string_face
= AREF (vector
, 4);
8378 mode_line_string_face_prop
= AREF (vector
, 5);
8380 if (!NILP (AREF (vector
, 6)))
8382 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8383 AREF (vector
, 6) = Qnil
;
8386 Vmode_line_unwind_vector
= vector
;
8391 /* Store a single character C for the frame title in mode_line_noprop_buf.
8392 Re-allocate mode_line_noprop_buf if necessary. */
8396 store_mode_line_noprop_char (char c
)
8398 store_mode_line_noprop_char (c
)
8402 /* If output position has reached the end of the allocated buffer,
8403 double the buffer's size. */
8404 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8406 int len
= MODE_LINE_NOPROP_LEN (0);
8407 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8408 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8409 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8410 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8413 *mode_line_noprop_ptr
++ = c
;
8417 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8418 mode_line_noprop_ptr. STR is the string to store. Do not copy
8419 characters that yield more columns than PRECISION; PRECISION <= 0
8420 means copy the whole string. Pad with spaces until FIELD_WIDTH
8421 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8422 pad. Called from display_mode_element when it is used to build a
8426 store_mode_line_noprop (str
, field_width
, precision
)
8427 const unsigned char *str
;
8428 int field_width
, precision
;
8433 /* Copy at most PRECISION chars from STR. */
8434 nbytes
= strlen (str
);
8435 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8437 store_mode_line_noprop_char (*str
++);
8439 /* Fill up with spaces until FIELD_WIDTH reached. */
8440 while (field_width
> 0
8443 store_mode_line_noprop_char (' ');
8450 /***********************************************************************
8452 ***********************************************************************/
8454 #ifdef HAVE_WINDOW_SYSTEM
8456 /* Set the title of FRAME, if it has changed. The title format is
8457 Vicon_title_format if FRAME is iconified, otherwise it is
8458 frame_title_format. */
8461 x_consider_frame_title (frame
)
8464 struct frame
*f
= XFRAME (frame
);
8466 if (FRAME_WINDOW_P (f
)
8467 || FRAME_MINIBUF_ONLY_P (f
)
8468 || f
->explicit_name
)
8470 /* Do we have more than one visible frame on this X display? */
8477 int count
= SPECPDL_INDEX ();
8479 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8481 Lisp_Object other_frame
= XCAR (tail
);
8482 struct frame
*tf
= XFRAME (other_frame
);
8485 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8486 && !FRAME_MINIBUF_ONLY_P (tf
)
8487 && !EQ (other_frame
, tip_frame
)
8488 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8492 /* Set global variable indicating that multiple frames exist. */
8493 multiple_frames
= CONSP (tail
);
8495 /* Switch to the buffer of selected window of the frame. Set up
8496 mode_line_target so that display_mode_element will output into
8497 mode_line_noprop_buf; then display the title. */
8498 record_unwind_protect (unwind_format_mode_line
,
8499 format_mode_line_unwind_data (current_buffer
));
8501 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8502 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8504 mode_line_target
= MODE_LINE_TITLE
;
8505 title_start
= MODE_LINE_NOPROP_LEN (0);
8506 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8507 NULL
, DEFAULT_FACE_ID
);
8508 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8509 len
= MODE_LINE_NOPROP_LEN (title_start
);
8510 title
= mode_line_noprop_buf
+ title_start
;
8511 unbind_to (count
, Qnil
);
8513 /* Set the title only if it's changed. This avoids consing in
8514 the common case where it hasn't. (If it turns out that we've
8515 already wasted too much time by walking through the list with
8516 display_mode_element, then we might need to optimize at a
8517 higher level than this.) */
8518 if (! STRINGP (f
->name
)
8519 || SBYTES (f
->name
) != len
8520 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8521 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8525 #endif /* not HAVE_WINDOW_SYSTEM */
8530 /***********************************************************************
8532 ***********************************************************************/
8535 /* Prepare for redisplay by updating menu-bar item lists when
8536 appropriate. This can call eval. */
8539 prepare_menu_bars ()
8542 struct gcpro gcpro1
, gcpro2
;
8544 Lisp_Object tooltip_frame
;
8546 #ifdef HAVE_WINDOW_SYSTEM
8547 tooltip_frame
= tip_frame
;
8549 tooltip_frame
= Qnil
;
8552 /* Update all frame titles based on their buffer names, etc. We do
8553 this before the menu bars so that the buffer-menu will show the
8554 up-to-date frame titles. */
8555 #ifdef HAVE_WINDOW_SYSTEM
8556 if (windows_or_buffers_changed
|| update_mode_lines
)
8558 Lisp_Object tail
, frame
;
8560 FOR_EACH_FRAME (tail
, frame
)
8563 if (!EQ (frame
, tooltip_frame
)
8564 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8565 x_consider_frame_title (frame
);
8568 #endif /* HAVE_WINDOW_SYSTEM */
8570 /* Update the menu bar item lists, if appropriate. This has to be
8571 done before any actual redisplay or generation of display lines. */
8572 all_windows
= (update_mode_lines
8573 || buffer_shared
> 1
8574 || windows_or_buffers_changed
);
8577 Lisp_Object tail
, frame
;
8578 int count
= SPECPDL_INDEX ();
8580 record_unwind_save_match_data ();
8582 FOR_EACH_FRAME (tail
, frame
)
8586 /* Ignore tooltip frame. */
8587 if (EQ (frame
, tooltip_frame
))
8590 /* If a window on this frame changed size, report that to
8591 the user and clear the size-change flag. */
8592 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8594 Lisp_Object functions
;
8596 /* Clear flag first in case we get an error below. */
8597 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8598 functions
= Vwindow_size_change_functions
;
8599 GCPRO2 (tail
, functions
);
8601 while (CONSP (functions
))
8603 call1 (XCAR (functions
), frame
);
8604 functions
= XCDR (functions
);
8610 update_menu_bar (f
, 0);
8611 #ifdef HAVE_WINDOW_SYSTEM
8612 update_tool_bar (f
, 0);
8617 unbind_to (count
, Qnil
);
8621 struct frame
*sf
= SELECTED_FRAME ();
8622 update_menu_bar (sf
, 1);
8623 #ifdef HAVE_WINDOW_SYSTEM
8624 update_tool_bar (sf
, 1);
8628 /* Motif needs this. See comment in xmenu.c. Turn it off when
8629 pending_menu_activation is not defined. */
8630 #ifdef USE_X_TOOLKIT
8631 pending_menu_activation
= 0;
8636 /* Update the menu bar item list for frame F. This has to be done
8637 before we start to fill in any display lines, because it can call
8640 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8643 update_menu_bar (f
, save_match_data
)
8645 int save_match_data
;
8648 register struct window
*w
;
8650 /* If called recursively during a menu update, do nothing. This can
8651 happen when, for instance, an activate-menubar-hook causes a
8653 if (inhibit_menubar_update
)
8656 window
= FRAME_SELECTED_WINDOW (f
);
8657 w
= XWINDOW (window
);
8659 #if 0 /* The if statement below this if statement used to include the
8660 condition !NILP (w->update_mode_line), rather than using
8661 update_mode_lines directly, and this if statement may have
8662 been added to make that condition work. Now the if
8663 statement below matches its comment, this isn't needed. */
8664 if (update_mode_lines
)
8665 w
->update_mode_line
= Qt
;
8668 if (FRAME_WINDOW_P (f
)
8670 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8671 || defined (USE_GTK)
8672 FRAME_EXTERNAL_MENU_BAR (f
)
8674 FRAME_MENU_BAR_LINES (f
) > 0
8676 : FRAME_MENU_BAR_LINES (f
) > 0)
8678 /* If the user has switched buffers or windows, we need to
8679 recompute to reflect the new bindings. But we'll
8680 recompute when update_mode_lines is set too; that means
8681 that people can use force-mode-line-update to request
8682 that the menu bar be recomputed. The adverse effect on
8683 the rest of the redisplay algorithm is about the same as
8684 windows_or_buffers_changed anyway. */
8685 if (windows_or_buffers_changed
8686 /* This used to test w->update_mode_line, but we believe
8687 there is no need to recompute the menu in that case. */
8688 || update_mode_lines
8689 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8690 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8691 != !NILP (w
->last_had_star
))
8692 || ((!NILP (Vtransient_mark_mode
)
8693 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8694 != !NILP (w
->region_showing
)))
8696 struct buffer
*prev
= current_buffer
;
8697 int count
= SPECPDL_INDEX ();
8699 specbind (Qinhibit_menubar_update
, Qt
);
8701 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8702 if (save_match_data
)
8703 record_unwind_save_match_data ();
8704 if (NILP (Voverriding_local_map_menu_flag
))
8706 specbind (Qoverriding_terminal_local_map
, Qnil
);
8707 specbind (Qoverriding_local_map
, Qnil
);
8710 /* Run the Lucid hook. */
8711 safe_run_hooks (Qactivate_menubar_hook
);
8713 /* If it has changed current-menubar from previous value,
8714 really recompute the menu-bar from the value. */
8715 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8716 call0 (Qrecompute_lucid_menubar
);
8718 safe_run_hooks (Qmenu_bar_update_hook
);
8719 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8721 /* Redisplay the menu bar in case we changed it. */
8722 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8723 || defined (USE_GTK)
8724 if (FRAME_WINDOW_P (f
)
8725 #if defined (MAC_OS)
8726 /* All frames on Mac OS share the same menubar. So only the
8727 selected frame should be allowed to set it. */
8728 && f
== SELECTED_FRAME ()
8731 set_frame_menubar (f
, 0, 0);
8733 /* On a terminal screen, the menu bar is an ordinary screen
8734 line, and this makes it get updated. */
8735 w
->update_mode_line
= Qt
;
8736 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8737 /* In the non-toolkit version, the menu bar is an ordinary screen
8738 line, and this makes it get updated. */
8739 w
->update_mode_line
= Qt
;
8740 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8742 unbind_to (count
, Qnil
);
8743 set_buffer_internal_1 (prev
);
8750 /***********************************************************************
8752 ***********************************************************************/
8754 #ifdef HAVE_WINDOW_SYSTEM
8757 Nominal cursor position -- where to draw output.
8758 HPOS and VPOS are window relative glyph matrix coordinates.
8759 X and Y are window relative pixel coordinates. */
8761 struct cursor_pos output_cursor
;
8765 Set the global variable output_cursor to CURSOR. All cursor
8766 positions are relative to updated_window. */
8769 set_output_cursor (cursor
)
8770 struct cursor_pos
*cursor
;
8772 output_cursor
.hpos
= cursor
->hpos
;
8773 output_cursor
.vpos
= cursor
->vpos
;
8774 output_cursor
.x
= cursor
->x
;
8775 output_cursor
.y
= cursor
->y
;
8780 Set a nominal cursor position.
8782 HPOS and VPOS are column/row positions in a window glyph matrix. X
8783 and Y are window text area relative pixel positions.
8785 If this is done during an update, updated_window will contain the
8786 window that is being updated and the position is the future output
8787 cursor position for that window. If updated_window is null, use
8788 selected_window and display the cursor at the given position. */
8791 x_cursor_to (vpos
, hpos
, y
, x
)
8792 int vpos
, hpos
, y
, x
;
8796 /* If updated_window is not set, work on selected_window. */
8800 w
= XWINDOW (selected_window
);
8802 /* Set the output cursor. */
8803 output_cursor
.hpos
= hpos
;
8804 output_cursor
.vpos
= vpos
;
8805 output_cursor
.x
= x
;
8806 output_cursor
.y
= y
;
8808 /* If not called as part of an update, really display the cursor.
8809 This will also set the cursor position of W. */
8810 if (updated_window
== NULL
)
8813 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8814 if (rif
->flush_display_optional
)
8815 rif
->flush_display_optional (SELECTED_FRAME ());
8820 #endif /* HAVE_WINDOW_SYSTEM */
8823 /***********************************************************************
8825 ***********************************************************************/
8827 #ifdef HAVE_WINDOW_SYSTEM
8829 /* Where the mouse was last time we reported a mouse event. */
8831 FRAME_PTR last_mouse_frame
;
8833 /* Tool-bar item index of the item on which a mouse button was pressed
8836 int last_tool_bar_item
;
8839 /* Update the tool-bar item list for frame F. This has to be done
8840 before we start to fill in any display lines. Called from
8841 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8842 and restore it here. */
8845 update_tool_bar (f
, save_match_data
)
8847 int save_match_data
;
8850 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8852 int do_update
= WINDOWP (f
->tool_bar_window
)
8853 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8861 window
= FRAME_SELECTED_WINDOW (f
);
8862 w
= XWINDOW (window
);
8864 /* If the user has switched buffers or windows, we need to
8865 recompute to reflect the new bindings. But we'll
8866 recompute when update_mode_lines is set too; that means
8867 that people can use force-mode-line-update to request
8868 that the menu bar be recomputed. The adverse effect on
8869 the rest of the redisplay algorithm is about the same as
8870 windows_or_buffers_changed anyway. */
8871 if (windows_or_buffers_changed
8872 || !NILP (w
->update_mode_line
)
8873 || update_mode_lines
8874 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8875 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8876 != !NILP (w
->last_had_star
))
8877 || ((!NILP (Vtransient_mark_mode
)
8878 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8879 != !NILP (w
->region_showing
)))
8881 struct buffer
*prev
= current_buffer
;
8882 int count
= SPECPDL_INDEX ();
8883 Lisp_Object new_tool_bar
;
8885 struct gcpro gcpro1
;
8887 /* Set current_buffer to the buffer of the selected
8888 window of the frame, so that we get the right local
8890 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8892 /* Save match data, if we must. */
8893 if (save_match_data
)
8894 record_unwind_save_match_data ();
8896 /* Make sure that we don't accidentally use bogus keymaps. */
8897 if (NILP (Voverriding_local_map_menu_flag
))
8899 specbind (Qoverriding_terminal_local_map
, Qnil
);
8900 specbind (Qoverriding_local_map
, Qnil
);
8903 GCPRO1 (new_tool_bar
);
8905 /* Build desired tool-bar items from keymaps. */
8906 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8909 /* Redisplay the tool-bar if we changed it. */
8910 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8912 /* Redisplay that happens asynchronously due to an expose event
8913 may access f->tool_bar_items. Make sure we update both
8914 variables within BLOCK_INPUT so no such event interrupts. */
8916 f
->tool_bar_items
= new_tool_bar
;
8917 f
->n_tool_bar_items
= new_n_tool_bar
;
8918 w
->update_mode_line
= Qt
;
8924 unbind_to (count
, Qnil
);
8925 set_buffer_internal_1 (prev
);
8931 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8932 F's desired tool-bar contents. F->tool_bar_items must have
8933 been set up previously by calling prepare_menu_bars. */
8936 build_desired_tool_bar_string (f
)
8939 int i
, size
, size_needed
;
8940 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8941 Lisp_Object image
, plist
, props
;
8943 image
= plist
= props
= Qnil
;
8944 GCPRO3 (image
, plist
, props
);
8946 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8947 Otherwise, make a new string. */
8949 /* The size of the string we might be able to reuse. */
8950 size
= (STRINGP (f
->desired_tool_bar_string
)
8951 ? SCHARS (f
->desired_tool_bar_string
)
8954 /* We need one space in the string for each image. */
8955 size_needed
= f
->n_tool_bar_items
;
8957 /* Reuse f->desired_tool_bar_string, if possible. */
8958 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8959 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8963 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8964 Fremove_text_properties (make_number (0), make_number (size
),
8965 props
, f
->desired_tool_bar_string
);
8968 /* Put a `display' property on the string for the images to display,
8969 put a `menu_item' property on tool-bar items with a value that
8970 is the index of the item in F's tool-bar item vector. */
8971 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8973 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8975 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8976 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8977 int hmargin
, vmargin
, relief
, idx
, end
;
8978 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8980 /* If image is a vector, choose the image according to the
8982 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8983 if (VECTORP (image
))
8987 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8988 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8991 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8992 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8994 xassert (ASIZE (image
) >= idx
);
8995 image
= AREF (image
, idx
);
9000 /* Ignore invalid image specifications. */
9001 if (!valid_image_p (image
))
9004 /* Display the tool-bar button pressed, or depressed. */
9005 plist
= Fcopy_sequence (XCDR (image
));
9007 /* Compute margin and relief to draw. */
9008 relief
= (tool_bar_button_relief
>= 0
9009 ? tool_bar_button_relief
9010 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
9011 hmargin
= vmargin
= relief
;
9013 if (INTEGERP (Vtool_bar_button_margin
)
9014 && XINT (Vtool_bar_button_margin
) > 0)
9016 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
9017 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
9019 else if (CONSP (Vtool_bar_button_margin
))
9021 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
9022 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
9023 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
9025 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
9026 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
9027 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
9030 if (auto_raise_tool_bar_buttons_p
)
9032 /* Add a `:relief' property to the image spec if the item is
9036 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
9043 /* If image is selected, display it pressed, i.e. with a
9044 negative relief. If it's not selected, display it with a
9046 plist
= Fplist_put (plist
, QCrelief
,
9048 ? make_number (-relief
)
9049 : make_number (relief
)));
9054 /* Put a margin around the image. */
9055 if (hmargin
|| vmargin
)
9057 if (hmargin
== vmargin
)
9058 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9060 plist
= Fplist_put (plist
, QCmargin
,
9061 Fcons (make_number (hmargin
),
9062 make_number (vmargin
)));
9065 /* If button is not enabled, and we don't have special images
9066 for the disabled state, make the image appear disabled by
9067 applying an appropriate algorithm to it. */
9068 if (!enabled_p
&& idx
< 0)
9069 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9071 /* Put a `display' text property on the string for the image to
9072 display. Put a `menu-item' property on the string that gives
9073 the start of this item's properties in the tool-bar items
9075 image
= Fcons (Qimage
, plist
);
9076 props
= list4 (Qdisplay
, image
,
9077 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9079 /* Let the last image hide all remaining spaces in the tool bar
9080 string. The string can be longer than needed when we reuse a
9082 if (i
+ 1 == f
->n_tool_bar_items
)
9083 end
= SCHARS (f
->desired_tool_bar_string
);
9086 Fadd_text_properties (make_number (i
), make_number (end
),
9087 props
, f
->desired_tool_bar_string
);
9095 /* Display one line of the tool-bar of frame IT->f. */
9098 display_tool_bar_line (it
)
9101 struct glyph_row
*row
= it
->glyph_row
;
9102 int max_x
= it
->last_visible_x
;
9105 prepare_desired_row (row
);
9106 row
->y
= it
->current_y
;
9108 /* Note that this isn't made use of if the face hasn't a box,
9109 so there's no need to check the face here. */
9110 it
->start_of_box_run_p
= 1;
9112 while (it
->current_x
< max_x
)
9114 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9116 /* Get the next display element. */
9117 if (!get_next_display_element (it
))
9120 /* Produce glyphs. */
9121 x_before
= it
->current_x
;
9122 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9123 PRODUCE_GLYPHS (it
);
9125 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9130 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9132 if (x
+ glyph
->pixel_width
> max_x
)
9134 /* Glyph doesn't fit on line. */
9135 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9141 x
+= glyph
->pixel_width
;
9145 /* Stop at line ends. */
9146 if (ITERATOR_AT_END_OF_LINE_P (it
))
9149 set_iterator_to_next (it
, 1);
9154 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9155 extend_face_to_end_of_line (it
);
9156 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9157 last
->right_box_line_p
= 1;
9158 if (last
== row
->glyphs
[TEXT_AREA
])
9159 last
->left_box_line_p
= 1;
9160 compute_line_metrics (it
);
9162 /* If line is empty, make it occupy the rest of the tool-bar. */
9163 if (!row
->displays_text_p
)
9165 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9166 row
->ascent
= row
->phys_ascent
= 0;
9167 row
->extra_line_spacing
= 0;
9170 row
->full_width_p
= 1;
9171 row
->continued_p
= 0;
9172 row
->truncated_on_left_p
= 0;
9173 row
->truncated_on_right_p
= 0;
9175 it
->current_x
= it
->hpos
= 0;
9176 it
->current_y
+= row
->height
;
9182 /* Value is the number of screen lines needed to make all tool-bar
9183 items of frame F visible. */
9186 tool_bar_lines_needed (f
)
9189 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9192 /* Initialize an iterator for iteration over
9193 F->desired_tool_bar_string in the tool-bar window of frame F. */
9194 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9195 it
.first_visible_x
= 0;
9196 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9197 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9199 while (!ITERATOR_AT_END_P (&it
))
9201 it
.glyph_row
= w
->desired_matrix
->rows
;
9202 clear_glyph_row (it
.glyph_row
);
9203 display_tool_bar_line (&it
);
9206 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9210 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9212 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9221 frame
= selected_frame
;
9223 CHECK_FRAME (frame
);
9226 if (WINDOWP (f
->tool_bar_window
)
9227 || (w
= XWINDOW (f
->tool_bar_window
),
9228 WINDOW_TOTAL_LINES (w
) > 0))
9230 update_tool_bar (f
, 1);
9231 if (f
->n_tool_bar_items
)
9233 build_desired_tool_bar_string (f
);
9234 nlines
= tool_bar_lines_needed (f
);
9238 return make_number (nlines
);
9242 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9243 height should be changed. */
9246 redisplay_tool_bar (f
)
9251 struct glyph_row
*row
;
9252 int change_height_p
= 0;
9255 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9256 update_frame_tool_bar (f
);
9260 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9261 do anything. This means you must start with tool-bar-lines
9262 non-zero to get the auto-sizing effect. Or in other words, you
9263 can turn off tool-bars by specifying tool-bar-lines zero. */
9264 if (!WINDOWP (f
->tool_bar_window
)
9265 || (w
= XWINDOW (f
->tool_bar_window
),
9266 WINDOW_TOTAL_LINES (w
) == 0))
9269 /* Set up an iterator for the tool-bar window. */
9270 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9271 it
.first_visible_x
= 0;
9272 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9275 /* Build a string that represents the contents of the tool-bar. */
9276 build_desired_tool_bar_string (f
);
9277 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9279 /* Display as many lines as needed to display all tool-bar items. */
9280 while (it
.current_y
< it
.last_visible_y
)
9281 display_tool_bar_line (&it
);
9283 /* It doesn't make much sense to try scrolling in the tool-bar
9284 window, so don't do it. */
9285 w
->desired_matrix
->no_scrolling_p
= 1;
9286 w
->must_be_updated_p
= 1;
9288 if (auto_resize_tool_bars_p
)
9292 /* If we couldn't display everything, change the tool-bar's
9294 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9295 change_height_p
= 1;
9297 /* If there are blank lines at the end, except for a partially
9298 visible blank line at the end that is smaller than
9299 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9300 row
= it
.glyph_row
- 1;
9301 if (!row
->displays_text_p
9302 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9303 change_height_p
= 1;
9305 /* If row displays tool-bar items, but is partially visible,
9306 change the tool-bar's height. */
9307 if (row
->displays_text_p
9308 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9309 change_height_p
= 1;
9311 /* Resize windows as needed by changing the `tool-bar-lines'
9314 && (nlines
= tool_bar_lines_needed (f
),
9315 nlines
!= WINDOW_TOTAL_LINES (w
)))
9317 extern Lisp_Object Qtool_bar_lines
;
9319 int old_height
= WINDOW_TOTAL_LINES (w
);
9321 XSETFRAME (frame
, f
);
9322 clear_glyph_matrix (w
->desired_matrix
);
9323 Fmodify_frame_parameters (frame
,
9324 Fcons (Fcons (Qtool_bar_lines
,
9325 make_number (nlines
)),
9327 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9328 fonts_changed_p
= 1;
9332 return change_height_p
;
9336 /* Get information about the tool-bar item which is displayed in GLYPH
9337 on frame F. Return in *PROP_IDX the index where tool-bar item
9338 properties start in F->tool_bar_items. Value is zero if
9339 GLYPH doesn't display a tool-bar item. */
9342 tool_bar_item_info (f
, glyph
, prop_idx
)
9344 struct glyph
*glyph
;
9351 /* This function can be called asynchronously, which means we must
9352 exclude any possibility that Fget_text_property signals an
9354 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9355 charpos
= max (0, charpos
);
9357 /* Get the text property `menu-item' at pos. The value of that
9358 property is the start index of this item's properties in
9359 F->tool_bar_items. */
9360 prop
= Fget_text_property (make_number (charpos
),
9361 Qmenu_item
, f
->current_tool_bar_string
);
9362 if (INTEGERP (prop
))
9364 *prop_idx
= XINT (prop
);
9374 /* Get information about the tool-bar item at position X/Y on frame F.
9375 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9376 the current matrix of the tool-bar window of F, or NULL if not
9377 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9378 item in F->tool_bar_items. Value is
9380 -1 if X/Y is not on a tool-bar item
9381 0 if X/Y is on the same item that was highlighted before.
9385 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9388 struct glyph
**glyph
;
9389 int *hpos
, *vpos
, *prop_idx
;
9391 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9392 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9395 /* Find the glyph under X/Y. */
9396 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9400 /* Get the start of this tool-bar item's properties in
9401 f->tool_bar_items. */
9402 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9405 /* Is mouse on the highlighted item? */
9406 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9407 && *vpos
>= dpyinfo
->mouse_face_beg_row
9408 && *vpos
<= dpyinfo
->mouse_face_end_row
9409 && (*vpos
> dpyinfo
->mouse_face_beg_row
9410 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9411 && (*vpos
< dpyinfo
->mouse_face_end_row
9412 || *hpos
< dpyinfo
->mouse_face_end_col
9413 || dpyinfo
->mouse_face_past_end
))
9421 Handle mouse button event on the tool-bar of frame F, at
9422 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9423 0 for button release. MODIFIERS is event modifiers for button
9427 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9430 unsigned int modifiers
;
9432 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9433 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9434 int hpos
, vpos
, prop_idx
;
9435 struct glyph
*glyph
;
9436 Lisp_Object enabled_p
;
9438 /* If not on the highlighted tool-bar item, return. */
9439 frame_to_window_pixel_xy (w
, &x
, &y
);
9440 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9443 /* If item is disabled, do nothing. */
9444 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9445 if (NILP (enabled_p
))
9450 /* Show item in pressed state. */
9451 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9452 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9453 last_tool_bar_item
= prop_idx
;
9457 Lisp_Object key
, frame
;
9458 struct input_event event
;
9461 /* Show item in released state. */
9462 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9463 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9465 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9467 XSETFRAME (frame
, f
);
9468 event
.kind
= TOOL_BAR_EVENT
;
9469 event
.frame_or_window
= frame
;
9471 kbd_buffer_store_event (&event
);
9473 event
.kind
= TOOL_BAR_EVENT
;
9474 event
.frame_or_window
= frame
;
9476 event
.modifiers
= modifiers
;
9477 kbd_buffer_store_event (&event
);
9478 last_tool_bar_item
= -1;
9483 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9484 tool-bar window-relative coordinates X/Y. Called from
9485 note_mouse_highlight. */
9488 note_tool_bar_highlight (f
, x
, y
)
9492 Lisp_Object window
= f
->tool_bar_window
;
9493 struct window
*w
= XWINDOW (window
);
9494 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9496 struct glyph
*glyph
;
9497 struct glyph_row
*row
;
9499 Lisp_Object enabled_p
;
9501 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9502 int mouse_down_p
, rc
;
9504 /* Function note_mouse_highlight is called with negative x(y
9505 values when mouse moves outside of the frame. */
9506 if (x
<= 0 || y
<= 0)
9508 clear_mouse_face (dpyinfo
);
9512 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9515 /* Not on tool-bar item. */
9516 clear_mouse_face (dpyinfo
);
9520 /* On same tool-bar item as before. */
9523 clear_mouse_face (dpyinfo
);
9525 /* Mouse is down, but on different tool-bar item? */
9526 mouse_down_p
= (dpyinfo
->grabbed
9527 && f
== last_mouse_frame
9528 && FRAME_LIVE_P (f
));
9530 && last_tool_bar_item
!= prop_idx
)
9533 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9534 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9536 /* If tool-bar item is not enabled, don't highlight it. */
9537 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9538 if (!NILP (enabled_p
))
9540 /* Compute the x-position of the glyph. In front and past the
9541 image is a space. We include this in the highlighted area. */
9542 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9543 for (i
= x
= 0; i
< hpos
; ++i
)
9544 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9546 /* Record this as the current active region. */
9547 dpyinfo
->mouse_face_beg_col
= hpos
;
9548 dpyinfo
->mouse_face_beg_row
= vpos
;
9549 dpyinfo
->mouse_face_beg_x
= x
;
9550 dpyinfo
->mouse_face_beg_y
= row
->y
;
9551 dpyinfo
->mouse_face_past_end
= 0;
9553 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9554 dpyinfo
->mouse_face_end_row
= vpos
;
9555 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9556 dpyinfo
->mouse_face_end_y
= row
->y
;
9557 dpyinfo
->mouse_face_window
= window
;
9558 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9560 /* Display it as active. */
9561 show_mouse_face (dpyinfo
, draw
);
9562 dpyinfo
->mouse_face_image_state
= draw
;
9567 /* Set help_echo_string to a help string to display for this tool-bar item.
9568 XTread_socket does the rest. */
9569 help_echo_object
= help_echo_window
= Qnil
;
9571 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9572 if (NILP (help_echo_string
))
9573 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9576 #endif /* HAVE_WINDOW_SYSTEM */
9580 /************************************************************************
9581 Horizontal scrolling
9582 ************************************************************************/
9584 static int hscroll_window_tree
P_ ((Lisp_Object
));
9585 static int hscroll_windows
P_ ((Lisp_Object
));
9587 /* For all leaf windows in the window tree rooted at WINDOW, set their
9588 hscroll value so that PT is (i) visible in the window, and (ii) so
9589 that it is not within a certain margin at the window's left and
9590 right border. Value is non-zero if any window's hscroll has been
9594 hscroll_window_tree (window
)
9597 int hscrolled_p
= 0;
9598 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9599 int hscroll_step_abs
= 0;
9600 double hscroll_step_rel
= 0;
9602 if (hscroll_relative_p
)
9604 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9605 if (hscroll_step_rel
< 0)
9607 hscroll_relative_p
= 0;
9608 hscroll_step_abs
= 0;
9611 else if (INTEGERP (Vhscroll_step
))
9613 hscroll_step_abs
= XINT (Vhscroll_step
);
9614 if (hscroll_step_abs
< 0)
9615 hscroll_step_abs
= 0;
9618 hscroll_step_abs
= 0;
9620 while (WINDOWP (window
))
9622 struct window
*w
= XWINDOW (window
);
9624 if (WINDOWP (w
->hchild
))
9625 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9626 else if (WINDOWP (w
->vchild
))
9627 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9628 else if (w
->cursor
.vpos
>= 0)
9631 int text_area_width
;
9632 struct glyph_row
*current_cursor_row
9633 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9634 struct glyph_row
*desired_cursor_row
9635 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9636 struct glyph_row
*cursor_row
9637 = (desired_cursor_row
->enabled_p
9638 ? desired_cursor_row
9639 : current_cursor_row
);
9641 text_area_width
= window_box_width (w
, TEXT_AREA
);
9643 /* Scroll when cursor is inside this scroll margin. */
9644 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9646 if ((XFASTINT (w
->hscroll
)
9647 && w
->cursor
.x
<= h_margin
)
9648 || (cursor_row
->enabled_p
9649 && cursor_row
->truncated_on_right_p
9650 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9654 struct buffer
*saved_current_buffer
;
9658 /* Find point in a display of infinite width. */
9659 saved_current_buffer
= current_buffer
;
9660 current_buffer
= XBUFFER (w
->buffer
);
9662 if (w
== XWINDOW (selected_window
))
9663 pt
= BUF_PT (current_buffer
);
9666 pt
= marker_position (w
->pointm
);
9667 pt
= max (BEGV
, pt
);
9671 /* Move iterator to pt starting at cursor_row->start in
9672 a line with infinite width. */
9673 init_to_row_start (&it
, w
, cursor_row
);
9674 it
.last_visible_x
= INFINITY
;
9675 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9676 current_buffer
= saved_current_buffer
;
9678 /* Position cursor in window. */
9679 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9680 hscroll
= max (0, (it
.current_x
9681 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9682 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9683 : (text_area_width
/ 2))))
9684 / FRAME_COLUMN_WIDTH (it
.f
);
9685 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9687 if (hscroll_relative_p
)
9688 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9691 wanted_x
= text_area_width
9692 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9695 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9699 if (hscroll_relative_p
)
9700 wanted_x
= text_area_width
* hscroll_step_rel
9703 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9706 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9708 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9710 /* Don't call Fset_window_hscroll if value hasn't
9711 changed because it will prevent redisplay
9713 if (XFASTINT (w
->hscroll
) != hscroll
)
9715 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9716 w
->hscroll
= make_number (hscroll
);
9725 /* Value is non-zero if hscroll of any leaf window has been changed. */
9730 /* Set hscroll so that cursor is visible and not inside horizontal
9731 scroll margins for all windows in the tree rooted at WINDOW. See
9732 also hscroll_window_tree above. Value is non-zero if any window's
9733 hscroll has been changed. If it has, desired matrices on the frame
9734 of WINDOW are cleared. */
9737 hscroll_windows (window
)
9742 if (automatic_hscrolling_p
)
9744 hscrolled_p
= hscroll_window_tree (window
);
9746 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9755 /************************************************************************
9757 ************************************************************************/
9759 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9760 to a non-zero value. This is sometimes handy to have in a debugger
9765 /* First and last unchanged row for try_window_id. */
9767 int debug_first_unchanged_at_end_vpos
;
9768 int debug_last_unchanged_at_beg_vpos
;
9770 /* Delta vpos and y. */
9772 int debug_dvpos
, debug_dy
;
9774 /* Delta in characters and bytes for try_window_id. */
9776 int debug_delta
, debug_delta_bytes
;
9778 /* Values of window_end_pos and window_end_vpos at the end of
9781 EMACS_INT debug_end_pos
, debug_end_vpos
;
9783 /* Append a string to W->desired_matrix->method. FMT is a printf
9784 format string. A1...A9 are a supplement for a variable-length
9785 argument list. If trace_redisplay_p is non-zero also printf the
9786 resulting string to stderr. */
9789 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9792 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9795 char *method
= w
->desired_matrix
->method
;
9796 int len
= strlen (method
);
9797 int size
= sizeof w
->desired_matrix
->method
;
9798 int remaining
= size
- len
- 1;
9800 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9801 if (len
&& remaining
)
9807 strncpy (method
+ len
, buffer
, remaining
);
9809 if (trace_redisplay_p
)
9810 fprintf (stderr
, "%p (%s): %s\n",
9812 ((BUFFERP (w
->buffer
)
9813 && STRINGP (XBUFFER (w
->buffer
)->name
))
9814 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9819 #endif /* GLYPH_DEBUG */
9822 /* Value is non-zero if all changes in window W, which displays
9823 current_buffer, are in the text between START and END. START is a
9824 buffer position, END is given as a distance from Z. Used in
9825 redisplay_internal for display optimization. */
9828 text_outside_line_unchanged_p (w
, start
, end
)
9832 int unchanged_p
= 1;
9834 /* If text or overlays have changed, see where. */
9835 if (XFASTINT (w
->last_modified
) < MODIFF
9836 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9838 /* Gap in the line? */
9839 if (GPT
< start
|| Z
- GPT
< end
)
9842 /* Changes start in front of the line, or end after it? */
9844 && (BEG_UNCHANGED
< start
- 1
9845 || END_UNCHANGED
< end
))
9848 /* If selective display, can't optimize if changes start at the
9849 beginning of the line. */
9851 && INTEGERP (current_buffer
->selective_display
)
9852 && XINT (current_buffer
->selective_display
) > 0
9853 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9856 /* If there are overlays at the start or end of the line, these
9857 may have overlay strings with newlines in them. A change at
9858 START, for instance, may actually concern the display of such
9859 overlay strings as well, and they are displayed on different
9860 lines. So, quickly rule out this case. (For the future, it
9861 might be desirable to implement something more telling than
9862 just BEG/END_UNCHANGED.) */
9865 if (BEG
+ BEG_UNCHANGED
== start
9866 && overlay_touches_p (start
))
9868 if (END_UNCHANGED
== end
9869 && overlay_touches_p (Z
- end
))
9878 /* Do a frame update, taking possible shortcuts into account. This is
9879 the main external entry point for redisplay.
9881 If the last redisplay displayed an echo area message and that message
9882 is no longer requested, we clear the echo area or bring back the
9883 mini-buffer if that is in use. */
9888 redisplay_internal (0);
9893 overlay_arrow_string_or_property (var
)
9898 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
9901 return Voverlay_arrow_string
;
9904 /* Return 1 if there are any overlay-arrows in current_buffer. */
9906 overlay_arrow_in_current_buffer_p ()
9910 for (vlist
= Voverlay_arrow_variable_list
;
9912 vlist
= XCDR (vlist
))
9914 Lisp_Object var
= XCAR (vlist
);
9919 val
= find_symbol_value (var
);
9921 && current_buffer
== XMARKER (val
)->buffer
)
9928 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9932 overlay_arrows_changed_p ()
9936 for (vlist
= Voverlay_arrow_variable_list
;
9938 vlist
= XCDR (vlist
))
9940 Lisp_Object var
= XCAR (vlist
);
9941 Lisp_Object val
, pstr
;
9945 val
= find_symbol_value (var
);
9948 if (! EQ (COERCE_MARKER (val
),
9949 Fget (var
, Qlast_arrow_position
))
9950 || ! (pstr
= overlay_arrow_string_or_property (var
),
9951 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9957 /* Mark overlay arrows to be updated on next redisplay. */
9960 update_overlay_arrows (up_to_date
)
9965 for (vlist
= Voverlay_arrow_variable_list
;
9967 vlist
= XCDR (vlist
))
9969 Lisp_Object var
= XCAR (vlist
);
9976 Lisp_Object val
= find_symbol_value (var
);
9977 Fput (var
, Qlast_arrow_position
,
9978 COERCE_MARKER (val
));
9979 Fput (var
, Qlast_arrow_string
,
9980 overlay_arrow_string_or_property (var
));
9982 else if (up_to_date
< 0
9983 || !NILP (Fget (var
, Qlast_arrow_position
)))
9985 Fput (var
, Qlast_arrow_position
, Qt
);
9986 Fput (var
, Qlast_arrow_string
, Qt
);
9992 /* Return overlay arrow string to display at row.
9993 Return integer (bitmap number) for arrow bitmap in left fringe.
9994 Return nil if no overlay arrow. */
9997 overlay_arrow_at_row (it
, row
)
9999 struct glyph_row
*row
;
10003 for (vlist
= Voverlay_arrow_variable_list
;
10005 vlist
= XCDR (vlist
))
10007 Lisp_Object var
= XCAR (vlist
);
10010 if (!SYMBOLP (var
))
10013 val
= find_symbol_value (var
);
10016 && current_buffer
== XMARKER (val
)->buffer
10017 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
10019 if (FRAME_WINDOW_P (it
->f
)
10020 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
10022 #ifdef HAVE_WINDOW_SYSTEM
10023 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
10026 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
10027 return make_number (fringe_bitmap
);
10030 return make_number (-1); /* Use default arrow bitmap */
10032 return overlay_arrow_string_or_property (var
);
10039 /* Return 1 if point moved out of or into a composition. Otherwise
10040 return 0. PREV_BUF and PREV_PT are the last point buffer and
10041 position. BUF and PT are the current point buffer and position. */
10044 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
10045 struct buffer
*prev_buf
, *buf
;
10050 Lisp_Object buffer
;
10052 XSETBUFFER (buffer
, buf
);
10053 /* Check a composition at the last point if point moved within the
10055 if (prev_buf
== buf
)
10058 /* Point didn't move. */
10061 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10062 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10063 && COMPOSITION_VALID_P (start
, end
, prop
)
10064 && start
< prev_pt
&& end
> prev_pt
)
10065 /* The last point was within the composition. Return 1 iff
10066 point moved out of the composition. */
10067 return (pt
<= start
|| pt
>= end
);
10070 /* Check a composition at the current point. */
10071 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10072 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10073 && COMPOSITION_VALID_P (start
, end
, prop
)
10074 && start
< pt
&& end
> pt
);
10078 /* Reconsider the setting of B->clip_changed which is displayed
10082 reconsider_clip_changes (w
, b
)
10086 if (b
->clip_changed
10087 && !NILP (w
->window_end_valid
)
10088 && w
->current_matrix
->buffer
== b
10089 && w
->current_matrix
->zv
== BUF_ZV (b
)
10090 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10091 b
->clip_changed
= 0;
10093 /* If display wasn't paused, and W is not a tool bar window, see if
10094 point has been moved into or out of a composition. In that case,
10095 we set b->clip_changed to 1 to force updating the screen. If
10096 b->clip_changed has already been set to 1, we can skip this
10098 if (!b
->clip_changed
10099 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10103 if (w
== XWINDOW (selected_window
))
10104 pt
= BUF_PT (current_buffer
);
10106 pt
= marker_position (w
->pointm
);
10108 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10109 || pt
!= XINT (w
->last_point
))
10110 && check_point_in_composition (w
->current_matrix
->buffer
,
10111 XINT (w
->last_point
),
10112 XBUFFER (w
->buffer
), pt
))
10113 b
->clip_changed
= 1;
10118 /* Select FRAME to forward the values of frame-local variables into C
10119 variables so that the redisplay routines can access those values
10123 select_frame_for_redisplay (frame
)
10126 Lisp_Object tail
, sym
, val
;
10127 Lisp_Object old
= selected_frame
;
10129 selected_frame
= frame
;
10131 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10132 if (CONSP (XCAR (tail
))
10133 && (sym
= XCAR (XCAR (tail
)),
10135 && (sym
= indirect_variable (sym
),
10136 val
= SYMBOL_VALUE (sym
),
10137 (BUFFER_LOCAL_VALUEP (val
)
10138 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10139 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10140 /* Use find_symbol_value rather than Fsymbol_value
10141 to avoid an error if it is void. */
10142 find_symbol_value (sym
);
10144 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10145 if (CONSP (XCAR (tail
))
10146 && (sym
= XCAR (XCAR (tail
)),
10148 && (sym
= indirect_variable (sym
),
10149 val
= SYMBOL_VALUE (sym
),
10150 (BUFFER_LOCAL_VALUEP (val
)
10151 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10152 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10153 find_symbol_value (sym
);
10157 #define STOP_POLLING \
10158 do { if (! polling_stopped_here) stop_polling (); \
10159 polling_stopped_here = 1; } while (0)
10161 #define RESUME_POLLING \
10162 do { if (polling_stopped_here) start_polling (); \
10163 polling_stopped_here = 0; } while (0)
10166 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10167 response to any user action; therefore, we should preserve the echo
10168 area. (Actually, our caller does that job.) Perhaps in the future
10169 avoid recentering windows if it is not necessary; currently that
10170 causes some problems. */
10173 redisplay_internal (preserve_echo_area
)
10174 int preserve_echo_area
;
10176 struct window
*w
= XWINDOW (selected_window
);
10177 struct frame
*f
= XFRAME (w
->frame
);
10179 int must_finish
= 0;
10180 struct text_pos tlbufpos
, tlendpos
;
10181 int number_of_visible_frames
;
10183 struct frame
*sf
= SELECTED_FRAME ();
10184 int polling_stopped_here
= 0;
10186 /* Non-zero means redisplay has to consider all windows on all
10187 frames. Zero means, only selected_window is considered. */
10188 int consider_all_windows_p
;
10190 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10192 /* No redisplay if running in batch mode or frame is not yet fully
10193 initialized, or redisplay is explicitly turned off by setting
10194 Vinhibit_redisplay. */
10196 || !NILP (Vinhibit_redisplay
)
10197 || !f
->glyphs_initialized_p
)
10200 /* The flag redisplay_performed_directly_p is set by
10201 direct_output_for_insert when it already did the whole screen
10202 update necessary. */
10203 if (redisplay_performed_directly_p
)
10205 redisplay_performed_directly_p
= 0;
10206 if (!hscroll_windows (selected_window
))
10210 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10211 if (popup_activated ())
10215 /* I don't think this happens but let's be paranoid. */
10216 if (redisplaying_p
)
10219 /* Record a function that resets redisplaying_p to its old value
10220 when we leave this function. */
10221 count
= SPECPDL_INDEX ();
10222 record_unwind_protect (unwind_redisplay
,
10223 Fcons (make_number (redisplaying_p
), selected_frame
));
10225 specbind (Qinhibit_free_realized_faces
, Qnil
);
10228 Lisp_Object tail
, frame
;
10230 FOR_EACH_FRAME (tail
, frame
)
10232 struct frame
*f
= XFRAME (frame
);
10233 f
->already_hscrolled_p
= 0;
10239 reconsider_clip_changes (w
, current_buffer
);
10241 /* If new fonts have been loaded that make a glyph matrix adjustment
10242 necessary, do it. */
10243 if (fonts_changed_p
)
10245 adjust_glyphs (NULL
);
10246 ++windows_or_buffers_changed
;
10247 fonts_changed_p
= 0;
10250 /* If face_change_count is non-zero, init_iterator will free all
10251 realized faces, which includes the faces referenced from current
10252 matrices. So, we can't reuse current matrices in this case. */
10253 if (face_change_count
)
10254 ++windows_or_buffers_changed
;
10256 if (! FRAME_WINDOW_P (sf
)
10257 && previous_terminal_frame
!= sf
)
10259 /* Since frames on an ASCII terminal share the same display
10260 area, displaying a different frame means redisplay the whole
10262 windows_or_buffers_changed
++;
10263 SET_FRAME_GARBAGED (sf
);
10264 XSETFRAME (Vterminal_frame
, sf
);
10266 previous_terminal_frame
= sf
;
10268 /* Set the visible flags for all frames. Do this before checking
10269 for resized or garbaged frames; they want to know if their frames
10270 are visible. See the comment in frame.h for
10271 FRAME_SAMPLE_VISIBILITY. */
10273 Lisp_Object tail
, frame
;
10275 number_of_visible_frames
= 0;
10277 FOR_EACH_FRAME (tail
, frame
)
10279 struct frame
*f
= XFRAME (frame
);
10281 FRAME_SAMPLE_VISIBILITY (f
);
10282 if (FRAME_VISIBLE_P (f
))
10283 ++number_of_visible_frames
;
10284 clear_desired_matrices (f
);
10288 /* Notice any pending interrupt request to change frame size. */
10289 do_pending_window_change (1);
10291 /* Clear frames marked as garbaged. */
10292 if (frame_garbaged
)
10293 clear_garbaged_frames ();
10295 /* Build menubar and tool-bar items. */
10296 prepare_menu_bars ();
10298 if (windows_or_buffers_changed
)
10299 update_mode_lines
++;
10301 /* Detect case that we need to write or remove a star in the mode line. */
10302 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10304 w
->update_mode_line
= Qt
;
10305 if (buffer_shared
> 1)
10306 update_mode_lines
++;
10309 /* If %c is in the mode line, update it if needed. */
10310 if (!NILP (w
->column_number_displayed
)
10311 /* This alternative quickly identifies a common case
10312 where no change is needed. */
10313 && !(PT
== XFASTINT (w
->last_point
)
10314 && XFASTINT (w
->last_modified
) >= MODIFF
10315 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10316 && (XFASTINT (w
->column_number_displayed
)
10317 != (int) current_column ())) /* iftc */
10318 w
->update_mode_line
= Qt
;
10320 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10322 /* The variable buffer_shared is set in redisplay_window and
10323 indicates that we redisplay a buffer in different windows. See
10325 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10326 || cursor_type_changed
);
10328 /* If specs for an arrow have changed, do thorough redisplay
10329 to ensure we remove any arrow that should no longer exist. */
10330 if (overlay_arrows_changed_p ())
10331 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10333 /* Normally the message* functions will have already displayed and
10334 updated the echo area, but the frame may have been trashed, or
10335 the update may have been preempted, so display the echo area
10336 again here. Checking message_cleared_p captures the case that
10337 the echo area should be cleared. */
10338 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10339 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10340 || (message_cleared_p
10341 && minibuf_level
== 0
10342 /* If the mini-window is currently selected, this means the
10343 echo-area doesn't show through. */
10344 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10346 int window_height_changed_p
= echo_area_display (0);
10349 /* If we don't display the current message, don't clear the
10350 message_cleared_p flag, because, if we did, we wouldn't clear
10351 the echo area in the next redisplay which doesn't preserve
10353 if (!display_last_displayed_message_p
)
10354 message_cleared_p
= 0;
10356 if (fonts_changed_p
)
10358 else if (window_height_changed_p
)
10360 consider_all_windows_p
= 1;
10361 ++update_mode_lines
;
10362 ++windows_or_buffers_changed
;
10364 /* If window configuration was changed, frames may have been
10365 marked garbaged. Clear them or we will experience
10366 surprises wrt scrolling. */
10367 if (frame_garbaged
)
10368 clear_garbaged_frames ();
10371 else if (EQ (selected_window
, minibuf_window
)
10372 && (current_buffer
->clip_changed
10373 || XFASTINT (w
->last_modified
) < MODIFF
10374 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10375 && resize_mini_window (w
, 0))
10377 /* Resized active mini-window to fit the size of what it is
10378 showing if its contents might have changed. */
10380 consider_all_windows_p
= 1;
10381 ++windows_or_buffers_changed
;
10382 ++update_mode_lines
;
10384 /* If window configuration was changed, frames may have been
10385 marked garbaged. Clear them or we will experience
10386 surprises wrt scrolling. */
10387 if (frame_garbaged
)
10388 clear_garbaged_frames ();
10392 /* If showing the region, and mark has changed, we must redisplay
10393 the whole window. The assignment to this_line_start_pos prevents
10394 the optimization directly below this if-statement. */
10395 if (((!NILP (Vtransient_mark_mode
)
10396 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10397 != !NILP (w
->region_showing
))
10398 || (!NILP (w
->region_showing
)
10399 && !EQ (w
->region_showing
,
10400 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10401 CHARPOS (this_line_start_pos
) = 0;
10403 /* Optimize the case that only the line containing the cursor in the
10404 selected window has changed. Variables starting with this_ are
10405 set in display_line and record information about the line
10406 containing the cursor. */
10407 tlbufpos
= this_line_start_pos
;
10408 tlendpos
= this_line_end_pos
;
10409 if (!consider_all_windows_p
10410 && CHARPOS (tlbufpos
) > 0
10411 && NILP (w
->update_mode_line
)
10412 && !current_buffer
->clip_changed
10413 && !current_buffer
->prevent_redisplay_optimizations_p
10414 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10415 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10416 /* Make sure recorded data applies to current buffer, etc. */
10417 && this_line_buffer
== current_buffer
10418 && current_buffer
== XBUFFER (w
->buffer
)
10419 && NILP (w
->force_start
)
10420 && NILP (w
->optional_new_start
)
10421 /* Point must be on the line that we have info recorded about. */
10422 && PT
>= CHARPOS (tlbufpos
)
10423 && PT
<= Z
- CHARPOS (tlendpos
)
10424 /* All text outside that line, including its final newline,
10425 must be unchanged */
10426 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10427 CHARPOS (tlendpos
)))
10429 if (CHARPOS (tlbufpos
) > BEGV
10430 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10431 && (CHARPOS (tlbufpos
) == ZV
10432 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10433 /* Former continuation line has disappeared by becoming empty */
10435 else if (XFASTINT (w
->last_modified
) < MODIFF
10436 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10437 || MINI_WINDOW_P (w
))
10439 /* We have to handle the case of continuation around a
10440 wide-column character (See the comment in indent.c around
10443 For instance, in the following case:
10445 -------- Insert --------
10446 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10447 J_I_ ==> J_I_ `^^' are cursors.
10451 As we have to redraw the line above, we should goto cancel. */
10454 int line_height_before
= this_line_pixel_height
;
10456 /* Note that start_display will handle the case that the
10457 line starting at tlbufpos is a continuation lines. */
10458 start_display (&it
, w
, tlbufpos
);
10460 /* Implementation note: It this still necessary? */
10461 if (it
.current_x
!= this_line_start_x
)
10464 TRACE ((stderr
, "trying display optimization 1\n"));
10465 w
->cursor
.vpos
= -1;
10466 overlay_arrow_seen
= 0;
10467 it
.vpos
= this_line_vpos
;
10468 it
.current_y
= this_line_y
;
10469 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10470 display_line (&it
);
10472 /* If line contains point, is not continued,
10473 and ends at same distance from eob as before, we win */
10474 if (w
->cursor
.vpos
>= 0
10475 /* Line is not continued, otherwise this_line_start_pos
10476 would have been set to 0 in display_line. */
10477 && CHARPOS (this_line_start_pos
)
10478 /* Line ends as before. */
10479 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10480 /* Line has same height as before. Otherwise other lines
10481 would have to be shifted up or down. */
10482 && this_line_pixel_height
== line_height_before
)
10484 /* If this is not the window's last line, we must adjust
10485 the charstarts of the lines below. */
10486 if (it
.current_y
< it
.last_visible_y
)
10488 struct glyph_row
*row
10489 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10490 int delta
, delta_bytes
;
10492 if (Z
- CHARPOS (tlendpos
) == ZV
)
10494 /* This line ends at end of (accessible part of)
10495 buffer. There is no newline to count. */
10497 - CHARPOS (tlendpos
)
10498 - MATRIX_ROW_START_CHARPOS (row
));
10499 delta_bytes
= (Z_BYTE
10500 - BYTEPOS (tlendpos
)
10501 - MATRIX_ROW_START_BYTEPOS (row
));
10505 /* This line ends in a newline. Must take
10506 account of the newline and the rest of the
10507 text that follows. */
10509 - CHARPOS (tlendpos
)
10510 - MATRIX_ROW_START_CHARPOS (row
));
10511 delta_bytes
= (Z_BYTE
10512 - BYTEPOS (tlendpos
)
10513 - MATRIX_ROW_START_BYTEPOS (row
));
10516 increment_matrix_positions (w
->current_matrix
,
10517 this_line_vpos
+ 1,
10518 w
->current_matrix
->nrows
,
10519 delta
, delta_bytes
);
10522 /* If this row displays text now but previously didn't,
10523 or vice versa, w->window_end_vpos may have to be
10525 if ((it
.glyph_row
- 1)->displays_text_p
)
10527 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10528 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10530 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10531 && this_line_vpos
> 0)
10532 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10533 w
->window_end_valid
= Qnil
;
10535 /* Update hint: No need to try to scroll in update_window. */
10536 w
->desired_matrix
->no_scrolling_p
= 1;
10539 *w
->desired_matrix
->method
= 0;
10540 debug_method_add (w
, "optimization 1");
10542 #ifdef HAVE_WINDOW_SYSTEM
10543 update_window_fringes (w
, 0);
10550 else if (/* Cursor position hasn't changed. */
10551 PT
== XFASTINT (w
->last_point
)
10552 /* Make sure the cursor was last displayed
10553 in this window. Otherwise we have to reposition it. */
10554 && 0 <= w
->cursor
.vpos
10555 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10559 do_pending_window_change (1);
10561 /* We used to always goto end_of_redisplay here, but this
10562 isn't enough if we have a blinking cursor. */
10563 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10564 goto end_of_redisplay
;
10568 /* If highlighting the region, or if the cursor is in the echo area,
10569 then we can't just move the cursor. */
10570 else if (! (!NILP (Vtransient_mark_mode
)
10571 && !NILP (current_buffer
->mark_active
))
10572 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10573 || highlight_nonselected_windows
)
10574 && NILP (w
->region_showing
)
10575 && NILP (Vshow_trailing_whitespace
)
10576 && !cursor_in_echo_area
)
10579 struct glyph_row
*row
;
10581 /* Skip from tlbufpos to PT and see where it is. Note that
10582 PT may be in invisible text. If so, we will end at the
10583 next visible position. */
10584 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10585 NULL
, DEFAULT_FACE_ID
);
10586 it
.current_x
= this_line_start_x
;
10587 it
.current_y
= this_line_y
;
10588 it
.vpos
= this_line_vpos
;
10590 /* The call to move_it_to stops in front of PT, but
10591 moves over before-strings. */
10592 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10594 if (it
.vpos
== this_line_vpos
10595 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10598 xassert (this_line_vpos
== it
.vpos
);
10599 xassert (this_line_y
== it
.current_y
);
10600 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10602 *w
->desired_matrix
->method
= 0;
10603 debug_method_add (w
, "optimization 3");
10612 /* Text changed drastically or point moved off of line. */
10613 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10616 CHARPOS (this_line_start_pos
) = 0;
10617 consider_all_windows_p
|= buffer_shared
> 1;
10618 ++clear_face_cache_count
;
10619 #ifdef HAVE_WINDOW_SYSTEM
10620 ++clear_image_cache_count
;
10623 /* Build desired matrices, and update the display. If
10624 consider_all_windows_p is non-zero, do it for all windows on all
10625 frames. Otherwise do it for selected_window, only. */
10627 if (consider_all_windows_p
)
10629 Lisp_Object tail
, frame
;
10631 FOR_EACH_FRAME (tail
, frame
)
10632 XFRAME (frame
)->updated_p
= 0;
10634 /* Recompute # windows showing selected buffer. This will be
10635 incremented each time such a window is displayed. */
10638 FOR_EACH_FRAME (tail
, frame
)
10640 struct frame
*f
= XFRAME (frame
);
10642 if (FRAME_WINDOW_P (f
) || f
== sf
)
10644 if (! EQ (frame
, selected_frame
))
10645 /* Select the frame, for the sake of frame-local
10647 select_frame_for_redisplay (frame
);
10649 /* Mark all the scroll bars to be removed; we'll redeem
10650 the ones we want when we redisplay their windows. */
10651 if (condemn_scroll_bars_hook
)
10652 condemn_scroll_bars_hook (f
);
10654 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10655 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10657 /* Any scroll bars which redisplay_windows should have
10658 nuked should now go away. */
10659 if (judge_scroll_bars_hook
)
10660 judge_scroll_bars_hook (f
);
10662 /* If fonts changed, display again. */
10663 /* ??? rms: I suspect it is a mistake to jump all the way
10664 back to retry here. It should just retry this frame. */
10665 if (fonts_changed_p
)
10668 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10670 /* See if we have to hscroll. */
10671 if (!f
->already_hscrolled_p
)
10673 f
->already_hscrolled_p
= 1;
10674 if (hscroll_windows (f
->root_window
))
10678 /* Prevent various kinds of signals during display
10679 update. stdio is not robust about handling
10680 signals, which can cause an apparent I/O
10682 if (interrupt_input
)
10683 unrequest_sigio ();
10686 /* Update the display. */
10687 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10688 pause
|= update_frame (f
, 0, 0);
10689 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10701 /* Do the mark_window_display_accurate after all windows have
10702 been redisplayed because this call resets flags in buffers
10703 which are needed for proper redisplay. */
10704 FOR_EACH_FRAME (tail
, frame
)
10706 struct frame
*f
= XFRAME (frame
);
10709 mark_window_display_accurate (f
->root_window
, 1);
10710 if (frame_up_to_date_hook
)
10711 frame_up_to_date_hook (f
);
10716 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10718 Lisp_Object mini_window
;
10719 struct frame
*mini_frame
;
10721 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10722 /* Use list_of_error, not Qerror, so that
10723 we catch only errors and don't run the debugger. */
10724 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10726 redisplay_window_error
);
10728 /* Compare desired and current matrices, perform output. */
10731 /* If fonts changed, display again. */
10732 if (fonts_changed_p
)
10735 /* Prevent various kinds of signals during display update.
10736 stdio is not robust about handling signals,
10737 which can cause an apparent I/O error. */
10738 if (interrupt_input
)
10739 unrequest_sigio ();
10742 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10744 if (hscroll_windows (selected_window
))
10747 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10748 pause
= update_frame (sf
, 0, 0);
10751 /* We may have called echo_area_display at the top of this
10752 function. If the echo area is on another frame, that may
10753 have put text on a frame other than the selected one, so the
10754 above call to update_frame would not have caught it. Catch
10756 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10757 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10759 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10761 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10762 pause
|= update_frame (mini_frame
, 0, 0);
10763 if (!pause
&& hscroll_windows (mini_window
))
10768 /* If display was paused because of pending input, make sure we do a
10769 thorough update the next time. */
10772 /* Prevent the optimization at the beginning of
10773 redisplay_internal that tries a single-line update of the
10774 line containing the cursor in the selected window. */
10775 CHARPOS (this_line_start_pos
) = 0;
10777 /* Let the overlay arrow be updated the next time. */
10778 update_overlay_arrows (0);
10780 /* If we pause after scrolling, some rows in the current
10781 matrices of some windows are not valid. */
10782 if (!WINDOW_FULL_WIDTH_P (w
)
10783 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10784 update_mode_lines
= 1;
10788 if (!consider_all_windows_p
)
10790 /* This has already been done above if
10791 consider_all_windows_p is set. */
10792 mark_window_display_accurate_1 (w
, 1);
10794 /* Say overlay arrows are up to date. */
10795 update_overlay_arrows (1);
10797 if (frame_up_to_date_hook
!= 0)
10798 frame_up_to_date_hook (sf
);
10801 update_mode_lines
= 0;
10802 windows_or_buffers_changed
= 0;
10803 cursor_type_changed
= 0;
10806 /* Start SIGIO interrupts coming again. Having them off during the
10807 code above makes it less likely one will discard output, but not
10808 impossible, since there might be stuff in the system buffer here.
10809 But it is much hairier to try to do anything about that. */
10810 if (interrupt_input
)
10814 /* If a frame has become visible which was not before, redisplay
10815 again, so that we display it. Expose events for such a frame
10816 (which it gets when becoming visible) don't call the parts of
10817 redisplay constructing glyphs, so simply exposing a frame won't
10818 display anything in this case. So, we have to display these
10819 frames here explicitly. */
10822 Lisp_Object tail
, frame
;
10825 FOR_EACH_FRAME (tail
, frame
)
10827 int this_is_visible
= 0;
10829 if (XFRAME (frame
)->visible
)
10830 this_is_visible
= 1;
10831 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10832 if (XFRAME (frame
)->visible
)
10833 this_is_visible
= 1;
10835 if (this_is_visible
)
10839 if (new_count
!= number_of_visible_frames
)
10840 windows_or_buffers_changed
++;
10843 /* Change frame size now if a change is pending. */
10844 do_pending_window_change (1);
10846 /* If we just did a pending size change, or have additional
10847 visible frames, redisplay again. */
10848 if (windows_or_buffers_changed
&& !pause
)
10851 /* Clear the face cache eventually. */
10852 if (consider_all_windows_p
)
10854 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10856 clear_face_cache (0);
10857 clear_face_cache_count
= 0;
10859 #ifdef HAVE_WINDOW_SYSTEM
10860 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
10862 Lisp_Object tail
, frame
;
10863 FOR_EACH_FRAME (tail
, frame
)
10865 struct frame
*f
= XFRAME (frame
);
10866 if (FRAME_WINDOW_P (f
))
10867 clear_image_cache (f
, 0);
10869 clear_image_cache_count
= 0;
10871 #endif /* HAVE_WINDOW_SYSTEM */
10875 unbind_to (count
, Qnil
);
10880 /* Redisplay, but leave alone any recent echo area message unless
10881 another message has been requested in its place.
10883 This is useful in situations where you need to redisplay but no
10884 user action has occurred, making it inappropriate for the message
10885 area to be cleared. See tracking_off and
10886 wait_reading_process_output for examples of these situations.
10888 FROM_WHERE is an integer saying from where this function was
10889 called. This is useful for debugging. */
10892 redisplay_preserve_echo_area (from_where
)
10895 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10897 if (!NILP (echo_area_buffer
[1]))
10899 /* We have a previously displayed message, but no current
10900 message. Redisplay the previous message. */
10901 display_last_displayed_message_p
= 1;
10902 redisplay_internal (1);
10903 display_last_displayed_message_p
= 0;
10906 redisplay_internal (1);
10908 if (rif
!= NULL
&& rif
->flush_display_optional
)
10909 rif
->flush_display_optional (NULL
);
10913 /* Function registered with record_unwind_protect in
10914 redisplay_internal. Reset redisplaying_p to the value it had
10915 before redisplay_internal was called, and clear
10916 prevent_freeing_realized_faces_p. It also selects the previously
10920 unwind_redisplay (val
)
10923 Lisp_Object old_redisplaying_p
, old_frame
;
10925 old_redisplaying_p
= XCAR (val
);
10926 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10927 old_frame
= XCDR (val
);
10928 if (! EQ (old_frame
, selected_frame
))
10929 select_frame_for_redisplay (old_frame
);
10934 /* Mark the display of window W as accurate or inaccurate. If
10935 ACCURATE_P is non-zero mark display of W as accurate. If
10936 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10937 redisplay_internal is called. */
10940 mark_window_display_accurate_1 (w
, accurate_p
)
10944 if (BUFFERP (w
->buffer
))
10946 struct buffer
*b
= XBUFFER (w
->buffer
);
10949 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10950 w
->last_overlay_modified
10951 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10953 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10957 b
->clip_changed
= 0;
10958 b
->prevent_redisplay_optimizations_p
= 0;
10960 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10961 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10962 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10963 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10965 w
->current_matrix
->buffer
= b
;
10966 w
->current_matrix
->begv
= BUF_BEGV (b
);
10967 w
->current_matrix
->zv
= BUF_ZV (b
);
10969 w
->last_cursor
= w
->cursor
;
10970 w
->last_cursor_off_p
= w
->cursor_off_p
;
10972 if (w
== XWINDOW (selected_window
))
10973 w
->last_point
= make_number (BUF_PT (b
));
10975 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10981 w
->window_end_valid
= w
->buffer
;
10982 #if 0 /* This is incorrect with variable-height lines. */
10983 xassert (XINT (w
->window_end_vpos
)
10984 < (WINDOW_TOTAL_LINES (w
)
10985 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10987 w
->update_mode_line
= Qnil
;
10992 /* Mark the display of windows in the window tree rooted at WINDOW as
10993 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10994 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10995 be redisplayed the next time redisplay_internal is called. */
10998 mark_window_display_accurate (window
, accurate_p
)
10999 Lisp_Object window
;
11004 for (; !NILP (window
); window
= w
->next
)
11006 w
= XWINDOW (window
);
11007 mark_window_display_accurate_1 (w
, accurate_p
);
11009 if (!NILP (w
->vchild
))
11010 mark_window_display_accurate (w
->vchild
, accurate_p
);
11011 if (!NILP (w
->hchild
))
11012 mark_window_display_accurate (w
->hchild
, accurate_p
);
11017 update_overlay_arrows (1);
11021 /* Force a thorough redisplay the next time by setting
11022 last_arrow_position and last_arrow_string to t, which is
11023 unequal to any useful value of Voverlay_arrow_... */
11024 update_overlay_arrows (-1);
11029 /* Return value in display table DP (Lisp_Char_Table *) for character
11030 C. Since a display table doesn't have any parent, we don't have to
11031 follow parent. Do not call this function directly but use the
11032 macro DISP_CHAR_VECTOR. */
11035 disp_char_vector (dp
, c
)
11036 struct Lisp_Char_Table
*dp
;
11042 if (SINGLE_BYTE_CHAR_P (c
))
11043 return (dp
->contents
[c
]);
11045 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
11048 else if (code
[2] < 32)
11051 /* Here, the possible range of code[0] (== charset ID) is
11052 128..max_charset. Since the top level char table contains data
11053 for multibyte characters after 256th element, we must increment
11054 code[0] by 128 to get a correct index. */
11056 code
[3] = -1; /* anchor */
11058 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
11060 val
= dp
->contents
[code
[i
]];
11061 if (!SUB_CHAR_TABLE_P (val
))
11062 return (NILP (val
) ? dp
->defalt
: val
);
11065 /* Here, val is a sub char table. We return the default value of
11067 return (dp
->defalt
);
11072 /***********************************************************************
11074 ***********************************************************************/
11076 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11079 redisplay_windows (window
)
11080 Lisp_Object window
;
11082 while (!NILP (window
))
11084 struct window
*w
= XWINDOW (window
);
11086 if (!NILP (w
->hchild
))
11087 redisplay_windows (w
->hchild
);
11088 else if (!NILP (w
->vchild
))
11089 redisplay_windows (w
->vchild
);
11092 displayed_buffer
= XBUFFER (w
->buffer
);
11093 /* Use list_of_error, not Qerror, so that
11094 we catch only errors and don't run the debugger. */
11095 internal_condition_case_1 (redisplay_window_0
, window
,
11097 redisplay_window_error
);
11105 redisplay_window_error ()
11107 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11112 redisplay_window_0 (window
)
11113 Lisp_Object window
;
11115 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11116 redisplay_window (window
, 0);
11121 redisplay_window_1 (window
)
11122 Lisp_Object window
;
11124 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11125 redisplay_window (window
, 1);
11130 /* Increment GLYPH until it reaches END or CONDITION fails while
11131 adding (GLYPH)->pixel_width to X. */
11133 #define SKIP_GLYPHS(glyph, end, x, condition) \
11136 (x) += (glyph)->pixel_width; \
11139 while ((glyph) < (end) && (condition))
11142 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11143 DELTA is the number of bytes by which positions recorded in ROW
11144 differ from current buffer positions. */
11147 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11149 struct glyph_row
*row
;
11150 struct glyph_matrix
*matrix
;
11151 int delta
, delta_bytes
, dy
, dvpos
;
11153 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11154 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11155 struct glyph
*cursor
= NULL
;
11156 /* The first glyph that starts a sequence of glyphs from string. */
11157 struct glyph
*string_start
;
11158 /* The X coordinate of string_start. */
11159 int string_start_x
;
11160 /* The last known character position. */
11161 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11162 /* The last known character position before string_start. */
11163 int string_before_pos
;
11166 int cursor_from_overlay_pos
= 0;
11167 int pt_old
= PT
- delta
;
11169 /* Skip over glyphs not having an object at the start of the row.
11170 These are special glyphs like truncation marks on terminal
11172 if (row
->displays_text_p
)
11174 && INTEGERP (glyph
->object
)
11175 && glyph
->charpos
< 0)
11177 x
+= glyph
->pixel_width
;
11181 string_start
= NULL
;
11183 && !INTEGERP (glyph
->object
)
11184 && (!BUFFERP (glyph
->object
)
11185 || (last_pos
= glyph
->charpos
) < pt_old
))
11187 if (! STRINGP (glyph
->object
))
11189 string_start
= NULL
;
11190 x
+= glyph
->pixel_width
;
11192 if (cursor_from_overlay_pos
11193 && last_pos
> cursor_from_overlay_pos
)
11195 cursor_from_overlay_pos
= 0;
11201 string_before_pos
= last_pos
;
11202 string_start
= glyph
;
11203 string_start_x
= x
;
11204 /* Skip all glyphs from string. */
11208 if ((cursor
== NULL
|| glyph
> cursor
)
11209 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11210 Qcursor
, (glyph
)->object
))
11211 && (pos
= string_buffer_position (w
, glyph
->object
,
11212 string_before_pos
),
11213 (pos
== 0 /* From overlay */
11214 || pos
== pt_old
)))
11216 /* Estimate overlay buffer position from the buffer
11217 positions of the glyphs before and after the overlay.
11218 Add 1 to last_pos so that if point corresponds to the
11219 glyph right after the overlay, we still use a 'cursor'
11220 property found in that overlay. */
11221 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11225 x
+= glyph
->pixel_width
;
11228 while (glyph
< end
&& STRINGP (glyph
->object
));
11232 if (cursor
!= NULL
)
11237 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11239 /* Scan back over the ellipsis glyphs, decrementing positions. */
11240 while (glyph
> row
->glyphs
[TEXT_AREA
]
11241 && (glyph
- 1)->charpos
== last_pos
)
11242 glyph
--, x
-= glyph
->pixel_width
;
11243 /* That loop always goes one position too far,
11244 including the glyph before the ellipsis.
11245 So scan forward over that one. */
11246 x
+= glyph
->pixel_width
;
11249 else if (string_start
11250 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11252 /* We may have skipped over point because the previous glyphs
11253 are from string. As there's no easy way to know the
11254 character position of the current glyph, find the correct
11255 glyph on point by scanning from string_start again. */
11257 Lisp_Object string
;
11260 limit
= make_number (pt_old
+ 1);
11262 glyph
= string_start
;
11263 x
= string_start_x
;
11264 string
= glyph
->object
;
11265 pos
= string_buffer_position (w
, string
, string_before_pos
);
11266 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11267 because we always put cursor after overlay strings. */
11268 while (pos
== 0 && glyph
< end
)
11270 string
= glyph
->object
;
11271 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11273 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11276 while (glyph
< end
)
11278 pos
= XINT (Fnext_single_char_property_change
11279 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11282 /* Skip glyphs from the same string. */
11283 string
= glyph
->object
;
11284 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11285 /* Skip glyphs from an overlay. */
11287 && ! string_buffer_position (w
, glyph
->object
, pos
))
11289 string
= glyph
->object
;
11290 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11295 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11297 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11298 w
->cursor
.y
= row
->y
+ dy
;
11300 if (w
== XWINDOW (selected_window
))
11302 if (!row
->continued_p
11303 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11306 this_line_buffer
= XBUFFER (w
->buffer
);
11308 CHARPOS (this_line_start_pos
)
11309 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11310 BYTEPOS (this_line_start_pos
)
11311 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11313 CHARPOS (this_line_end_pos
)
11314 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11315 BYTEPOS (this_line_end_pos
)
11316 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11318 this_line_y
= w
->cursor
.y
;
11319 this_line_pixel_height
= row
->height
;
11320 this_line_vpos
= w
->cursor
.vpos
;
11321 this_line_start_x
= row
->x
;
11324 CHARPOS (this_line_start_pos
) = 0;
11329 /* Run window scroll functions, if any, for WINDOW with new window
11330 start STARTP. Sets the window start of WINDOW to that position.
11332 We assume that the window's buffer is really current. */
11334 static INLINE
struct text_pos
11335 run_window_scroll_functions (window
, startp
)
11336 Lisp_Object window
;
11337 struct text_pos startp
;
11339 struct window
*w
= XWINDOW (window
);
11340 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11342 if (current_buffer
!= XBUFFER (w
->buffer
))
11345 if (!NILP (Vwindow_scroll_functions
))
11347 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11348 make_number (CHARPOS (startp
)));
11349 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11350 /* In case the hook functions switch buffers. */
11351 if (current_buffer
!= XBUFFER (w
->buffer
))
11352 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11359 /* Make sure the line containing the cursor is fully visible.
11360 A value of 1 means there is nothing to be done.
11361 (Either the line is fully visible, or it cannot be made so,
11362 or we cannot tell.)
11364 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11365 is higher than window.
11367 A value of 0 means the caller should do scrolling
11368 as if point had gone off the screen. */
11371 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11375 struct glyph_matrix
*matrix
;
11376 struct glyph_row
*row
;
11379 if (!make_cursor_line_fully_visible_p
)
11382 /* It's not always possible to find the cursor, e.g, when a window
11383 is full of overlay strings. Don't do anything in that case. */
11384 if (w
->cursor
.vpos
< 0)
11387 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11388 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11390 /* If the cursor row is not partially visible, there's nothing to do. */
11391 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11394 /* If the row the cursor is in is taller than the window's height,
11395 it's not clear what to do, so do nothing. */
11396 window_height
= window_box_height (w
);
11397 if (row
->height
>= window_height
)
11399 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11405 /* This code used to try to scroll the window just enough to make
11406 the line visible. It returned 0 to say that the caller should
11407 allocate larger glyph matrices. */
11409 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11411 int dy
= row
->height
- row
->visible_height
;
11414 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11416 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11418 int dy
= - (row
->height
- row
->visible_height
);
11421 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11424 /* When we change the cursor y-position of the selected window,
11425 change this_line_y as well so that the display optimization for
11426 the cursor line of the selected window in redisplay_internal uses
11427 the correct y-position. */
11428 if (w
== XWINDOW (selected_window
))
11429 this_line_y
= w
->cursor
.y
;
11431 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11432 redisplay with larger matrices. */
11433 if (matrix
->nrows
< required_matrix_height (w
))
11435 fonts_changed_p
= 1;
11444 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11445 non-zero means only WINDOW is redisplayed in redisplay_internal.
11446 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11447 in redisplay_window to bring a partially visible line into view in
11448 the case that only the cursor has moved.
11450 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11451 last screen line's vertical height extends past the end of the screen.
11455 1 if scrolling succeeded
11457 0 if scrolling didn't find point.
11459 -1 if new fonts have been loaded so that we must interrupt
11460 redisplay, adjust glyph matrices, and try again. */
11466 SCROLLING_NEED_LARGER_MATRICES
11470 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11471 scroll_step
, temp_scroll_step
, last_line_misfit
)
11472 Lisp_Object window
;
11473 int just_this_one_p
;
11474 EMACS_INT scroll_conservatively
, scroll_step
;
11475 int temp_scroll_step
;
11476 int last_line_misfit
;
11478 struct window
*w
= XWINDOW (window
);
11479 struct frame
*f
= XFRAME (w
->frame
);
11480 struct text_pos scroll_margin_pos
;
11481 struct text_pos pos
;
11482 struct text_pos startp
;
11484 Lisp_Object window_end
;
11485 int this_scroll_margin
;
11489 int amount_to_scroll
= 0;
11490 Lisp_Object aggressive
;
11492 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11495 debug_method_add (w
, "try_scrolling");
11498 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11500 /* Compute scroll margin height in pixels. We scroll when point is
11501 within this distance from the top or bottom of the window. */
11502 if (scroll_margin
> 0)
11504 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11505 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11508 this_scroll_margin
= 0;
11510 /* Force scroll_conservatively to have a reasonable value so it doesn't
11511 cause an overflow while computing how much to scroll. */
11512 if (scroll_conservatively
)
11513 scroll_conservatively
= min (scroll_conservatively
,
11514 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11516 /* Compute how much we should try to scroll maximally to bring point
11518 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11519 scroll_max
= max (scroll_step
,
11520 max (scroll_conservatively
, temp_scroll_step
));
11521 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11522 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11523 /* We're trying to scroll because of aggressive scrolling
11524 but no scroll_step is set. Choose an arbitrary one. Maybe
11525 there should be a variable for this. */
11529 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11531 /* Decide whether we have to scroll down. Start at the window end
11532 and move this_scroll_margin up to find the position of the scroll
11534 window_end
= Fwindow_end (window
, Qt
);
11538 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11539 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11541 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11543 start_display (&it
, w
, scroll_margin_pos
);
11544 if (this_scroll_margin
)
11545 move_it_vertically_backward (&it
, this_scroll_margin
);
11546 if (extra_scroll_margin_lines
)
11547 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11548 scroll_margin_pos
= it
.current
.pos
;
11551 if (PT
>= CHARPOS (scroll_margin_pos
))
11555 /* Point is in the scroll margin at the bottom of the window, or
11556 below. Compute a new window start that makes point visible. */
11558 /* Compute the distance from the scroll margin to PT.
11559 Give up if the distance is greater than scroll_max. */
11560 start_display (&it
, w
, scroll_margin_pos
);
11562 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11563 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11565 /* To make point visible, we have to move the window start
11566 down so that the line the cursor is in is visible, which
11567 means we have to add in the height of the cursor line. */
11568 dy
= line_bottom_y (&it
) - y0
;
11570 if (dy
> scroll_max
)
11571 return SCROLLING_FAILED
;
11573 /* Move the window start down. If scrolling conservatively,
11574 move it just enough down to make point visible. If
11575 scroll_step is set, move it down by scroll_step. */
11576 start_display (&it
, w
, startp
);
11578 if (scroll_conservatively
)
11579 /* Set AMOUNT_TO_SCROLL to at least one line,
11580 and at most scroll_conservatively lines. */
11582 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11583 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11584 else if (scroll_step
|| temp_scroll_step
)
11585 amount_to_scroll
= scroll_max
;
11588 aggressive
= current_buffer
->scroll_up_aggressively
;
11589 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11590 if (NUMBERP (aggressive
))
11592 double float_amount
= XFLOATINT (aggressive
) * height
;
11593 amount_to_scroll
= float_amount
;
11594 if (amount_to_scroll
== 0 && float_amount
> 0)
11595 amount_to_scroll
= 1;
11599 if (amount_to_scroll
<= 0)
11600 return SCROLLING_FAILED
;
11602 /* If moving by amount_to_scroll leaves STARTP unchanged,
11603 move it down one screen line. */
11605 move_it_vertically (&it
, amount_to_scroll
);
11606 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11607 move_it_by_lines (&it
, 1, 1);
11608 startp
= it
.current
.pos
;
11612 /* See if point is inside the scroll margin at the top of the
11614 scroll_margin_pos
= startp
;
11615 if (this_scroll_margin
)
11617 start_display (&it
, w
, startp
);
11618 move_it_vertically (&it
, this_scroll_margin
);
11619 scroll_margin_pos
= it
.current
.pos
;
11622 if (PT
< CHARPOS (scroll_margin_pos
))
11624 /* Point is in the scroll margin at the top of the window or
11625 above what is displayed in the window. */
11628 /* Compute the vertical distance from PT to the scroll
11629 margin position. Give up if distance is greater than
11631 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11632 start_display (&it
, w
, pos
);
11634 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11635 it
.last_visible_y
, -1,
11636 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11637 dy
= it
.current_y
- y0
;
11638 if (dy
> scroll_max
)
11639 return SCROLLING_FAILED
;
11641 /* Compute new window start. */
11642 start_display (&it
, w
, startp
);
11644 if (scroll_conservatively
)
11646 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11647 else if (scroll_step
|| temp_scroll_step
)
11648 amount_to_scroll
= scroll_max
;
11651 aggressive
= current_buffer
->scroll_down_aggressively
;
11652 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11653 if (NUMBERP (aggressive
))
11655 double float_amount
= XFLOATINT (aggressive
) * height
;
11656 amount_to_scroll
= float_amount
;
11657 if (amount_to_scroll
== 0 && float_amount
> 0)
11658 amount_to_scroll
= 1;
11662 if (amount_to_scroll
<= 0)
11663 return SCROLLING_FAILED
;
11665 move_it_vertically_backward (&it
, amount_to_scroll
);
11666 startp
= it
.current
.pos
;
11670 /* Run window scroll functions. */
11671 startp
= run_window_scroll_functions (window
, startp
);
11673 /* Display the window. Give up if new fonts are loaded, or if point
11675 if (!try_window (window
, startp
, 0))
11676 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11677 else if (w
->cursor
.vpos
< 0)
11679 clear_glyph_matrix (w
->desired_matrix
);
11680 rc
= SCROLLING_FAILED
;
11684 /* Maybe forget recorded base line for line number display. */
11685 if (!just_this_one_p
11686 || current_buffer
->clip_changed
11687 || BEG_UNCHANGED
< CHARPOS (startp
))
11688 w
->base_line_number
= Qnil
;
11690 /* If cursor ends up on a partially visible line,
11691 treat that as being off the bottom of the screen. */
11692 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11694 clear_glyph_matrix (w
->desired_matrix
);
11695 ++extra_scroll_margin_lines
;
11698 rc
= SCROLLING_SUCCESS
;
11705 /* Compute a suitable window start for window W if display of W starts
11706 on a continuation line. Value is non-zero if a new window start
11709 The new window start will be computed, based on W's width, starting
11710 from the start of the continued line. It is the start of the
11711 screen line with the minimum distance from the old start W->start. */
11714 compute_window_start_on_continuation_line (w
)
11717 struct text_pos pos
, start_pos
;
11718 int window_start_changed_p
= 0;
11720 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11722 /* If window start is on a continuation line... Window start may be
11723 < BEGV in case there's invisible text at the start of the
11724 buffer (M-x rmail, for example). */
11725 if (CHARPOS (start_pos
) > BEGV
11726 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11729 struct glyph_row
*row
;
11731 /* Handle the case that the window start is out of range. */
11732 if (CHARPOS (start_pos
) < BEGV
)
11733 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11734 else if (CHARPOS (start_pos
) > ZV
)
11735 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11737 /* Find the start of the continued line. This should be fast
11738 because scan_buffer is fast (newline cache). */
11739 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11740 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11741 row
, DEFAULT_FACE_ID
);
11742 reseat_at_previous_visible_line_start (&it
);
11744 /* If the line start is "too far" away from the window start,
11745 say it takes too much time to compute a new window start. */
11746 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11747 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11749 int min_distance
, distance
;
11751 /* Move forward by display lines to find the new window
11752 start. If window width was enlarged, the new start can
11753 be expected to be > the old start. If window width was
11754 decreased, the new window start will be < the old start.
11755 So, we're looking for the display line start with the
11756 minimum distance from the old window start. */
11757 pos
= it
.current
.pos
;
11758 min_distance
= INFINITY
;
11759 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11760 distance
< min_distance
)
11762 min_distance
= distance
;
11763 pos
= it
.current
.pos
;
11764 move_it_by_lines (&it
, 1, 0);
11767 /* Set the window start there. */
11768 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11769 window_start_changed_p
= 1;
11773 return window_start_changed_p
;
11777 /* Try cursor movement in case text has not changed in window WINDOW,
11778 with window start STARTP. Value is
11780 CURSOR_MOVEMENT_SUCCESS if successful
11782 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11784 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11785 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11786 we want to scroll as if scroll-step were set to 1. See the code.
11788 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11789 which case we have to abort this redisplay, and adjust matrices
11794 CURSOR_MOVEMENT_SUCCESS
,
11795 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11796 CURSOR_MOVEMENT_MUST_SCROLL
,
11797 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11801 try_cursor_movement (window
, startp
, scroll_step
)
11802 Lisp_Object window
;
11803 struct text_pos startp
;
11806 struct window
*w
= XWINDOW (window
);
11807 struct frame
*f
= XFRAME (w
->frame
);
11808 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11811 if (inhibit_try_cursor_movement
)
11815 /* Handle case where text has not changed, only point, and it has
11816 not moved off the frame. */
11817 if (/* Point may be in this window. */
11818 PT
>= CHARPOS (startp
)
11819 /* Selective display hasn't changed. */
11820 && !current_buffer
->clip_changed
11821 /* Function force-mode-line-update is used to force a thorough
11822 redisplay. It sets either windows_or_buffers_changed or
11823 update_mode_lines. So don't take a shortcut here for these
11825 && !update_mode_lines
11826 && !windows_or_buffers_changed
11827 && !cursor_type_changed
11828 /* Can't use this case if highlighting a region. When a
11829 region exists, cursor movement has to do more than just
11831 && !(!NILP (Vtransient_mark_mode
)
11832 && !NILP (current_buffer
->mark_active
))
11833 && NILP (w
->region_showing
)
11834 && NILP (Vshow_trailing_whitespace
)
11835 /* Right after splitting windows, last_point may be nil. */
11836 && INTEGERP (w
->last_point
)
11837 /* This code is not used for mini-buffer for the sake of the case
11838 of redisplaying to replace an echo area message; since in
11839 that case the mini-buffer contents per se are usually
11840 unchanged. This code is of no real use in the mini-buffer
11841 since the handling of this_line_start_pos, etc., in redisplay
11842 handles the same cases. */
11843 && !EQ (window
, minibuf_window
)
11844 /* When splitting windows or for new windows, it happens that
11845 redisplay is called with a nil window_end_vpos or one being
11846 larger than the window. This should really be fixed in
11847 window.c. I don't have this on my list, now, so we do
11848 approximately the same as the old redisplay code. --gerd. */
11849 && INTEGERP (w
->window_end_vpos
)
11850 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11851 && (FRAME_WINDOW_P (f
)
11852 || !overlay_arrow_in_current_buffer_p ()))
11854 int this_scroll_margin
, top_scroll_margin
;
11855 struct glyph_row
*row
= NULL
;
11858 debug_method_add (w
, "cursor movement");
11861 /* Scroll if point within this distance from the top or bottom
11862 of the window. This is a pixel value. */
11863 this_scroll_margin
= max (0, scroll_margin
);
11864 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11865 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11867 top_scroll_margin
= this_scroll_margin
;
11868 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11869 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11871 /* Start with the row the cursor was displayed during the last
11872 not paused redisplay. Give up if that row is not valid. */
11873 if (w
->last_cursor
.vpos
< 0
11874 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11875 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11878 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11879 if (row
->mode_line_p
)
11881 if (!row
->enabled_p
)
11882 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11885 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11888 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11890 if (PT
> XFASTINT (w
->last_point
))
11892 /* Point has moved forward. */
11893 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11894 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11896 xassert (row
->enabled_p
);
11900 /* The end position of a row equals the start position
11901 of the next row. If PT is there, we would rather
11902 display it in the next line. */
11903 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11904 && MATRIX_ROW_END_CHARPOS (row
) == PT
11905 && !cursor_row_p (w
, row
))
11908 /* If within the scroll margin, scroll. Note that
11909 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11910 the next line would be drawn, and that
11911 this_scroll_margin can be zero. */
11912 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11913 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11914 /* Line is completely visible last line in window
11915 and PT is to be set in the next line. */
11916 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11917 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11918 && !row
->ends_at_zv_p
11919 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11922 else if (PT
< XFASTINT (w
->last_point
))
11924 /* Cursor has to be moved backward. Note that PT >=
11925 CHARPOS (startp) because of the outer if-statement. */
11926 while (!row
->mode_line_p
11927 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11928 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11929 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
11930 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
11931 row
> w
->current_matrix
->rows
11932 && (row
-1)->ends_in_newline_from_string_p
))))
11933 && (row
->y
> top_scroll_margin
11934 || CHARPOS (startp
) == BEGV
))
11936 xassert (row
->enabled_p
);
11940 /* Consider the following case: Window starts at BEGV,
11941 there is invisible, intangible text at BEGV, so that
11942 display starts at some point START > BEGV. It can
11943 happen that we are called with PT somewhere between
11944 BEGV and START. Try to handle that case. */
11945 if (row
< w
->current_matrix
->rows
11946 || row
->mode_line_p
)
11948 row
= w
->current_matrix
->rows
;
11949 if (row
->mode_line_p
)
11953 /* Due to newlines in overlay strings, we may have to
11954 skip forward over overlay strings. */
11955 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11956 && MATRIX_ROW_END_CHARPOS (row
) == PT
11957 && !cursor_row_p (w
, row
))
11960 /* If within the scroll margin, scroll. */
11961 if (row
->y
< top_scroll_margin
11962 && CHARPOS (startp
) != BEGV
)
11967 /* Cursor did not move. So don't scroll even if cursor line
11968 is partially visible, as it was so before. */
11969 rc
= CURSOR_MOVEMENT_SUCCESS
;
11972 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11973 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11975 /* if PT is not in the glyph row, give up. */
11976 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11978 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
11979 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11980 && make_cursor_line_fully_visible_p
)
11982 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11983 && !row
->ends_at_zv_p
11984 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11985 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11986 else if (row
->height
> window_box_height (w
))
11988 /* If we end up in a partially visible line, let's
11989 make it fully visible, except when it's taller
11990 than the window, in which case we can't do much
11993 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11997 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11998 if (!cursor_row_fully_visible_p (w
, 0, 1))
11999 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12001 rc
= CURSOR_MOVEMENT_SUCCESS
;
12005 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
12008 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12009 rc
= CURSOR_MOVEMENT_SUCCESS
;
12018 set_vertical_scroll_bar (w
)
12021 int start
, end
, whole
;
12023 /* Calculate the start and end positions for the current window.
12024 At some point, it would be nice to choose between scrollbars
12025 which reflect the whole buffer size, with special markers
12026 indicating narrowing, and scrollbars which reflect only the
12029 Note that mini-buffers sometimes aren't displaying any text. */
12030 if (!MINI_WINDOW_P (w
)
12031 || (w
== XWINDOW (minibuf_window
)
12032 && NILP (echo_area_buffer
[0])))
12034 struct buffer
*buf
= XBUFFER (w
->buffer
);
12035 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
12036 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
12037 /* I don't think this is guaranteed to be right. For the
12038 moment, we'll pretend it is. */
12039 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
12043 if (whole
< (end
- start
))
12044 whole
= end
- start
;
12047 start
= end
= whole
= 0;
12049 /* Indicate what this scroll bar ought to be displaying now. */
12050 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
12054 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
12055 selected_window is redisplayed.
12057 We can return without actually redisplaying the window if
12058 fonts_changed_p is nonzero. In that case, redisplay_internal will
12062 redisplay_window (window
, just_this_one_p
)
12063 Lisp_Object window
;
12064 int just_this_one_p
;
12066 struct window
*w
= XWINDOW (window
);
12067 struct frame
*f
= XFRAME (w
->frame
);
12068 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12069 struct buffer
*old
= current_buffer
;
12070 struct text_pos lpoint
, opoint
, startp
;
12071 int update_mode_line
;
12074 /* Record it now because it's overwritten. */
12075 int current_matrix_up_to_date_p
= 0;
12076 int used_current_matrix_p
= 0;
12077 /* This is less strict than current_matrix_up_to_date_p.
12078 It indictes that the buffer contents and narrowing are unchanged. */
12079 int buffer_unchanged_p
= 0;
12080 int temp_scroll_step
= 0;
12081 int count
= SPECPDL_INDEX ();
12083 int centering_position
= -1;
12084 int last_line_misfit
= 0;
12086 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12089 /* W must be a leaf window here. */
12090 xassert (!NILP (w
->buffer
));
12092 *w
->desired_matrix
->method
= 0;
12095 specbind (Qinhibit_point_motion_hooks
, Qt
);
12097 reconsider_clip_changes (w
, buffer
);
12099 /* Has the mode line to be updated? */
12100 update_mode_line
= (!NILP (w
->update_mode_line
)
12101 || update_mode_lines
12102 || buffer
->clip_changed
12103 || buffer
->prevent_redisplay_optimizations_p
);
12105 if (MINI_WINDOW_P (w
))
12107 if (w
== XWINDOW (echo_area_window
)
12108 && !NILP (echo_area_buffer
[0]))
12110 if (update_mode_line
)
12111 /* We may have to update a tty frame's menu bar or a
12112 tool-bar. Example `M-x C-h C-h C-g'. */
12113 goto finish_menu_bars
;
12115 /* We've already displayed the echo area glyphs in this window. */
12116 goto finish_scroll_bars
;
12118 else if ((w
!= XWINDOW (minibuf_window
)
12119 || minibuf_level
== 0)
12120 /* When buffer is nonempty, redisplay window normally. */
12121 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12122 /* Quail displays non-mini buffers in minibuffer window.
12123 In that case, redisplay the window normally. */
12124 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12126 /* W is a mini-buffer window, but it's not active, so clear
12128 int yb
= window_text_bottom_y (w
);
12129 struct glyph_row
*row
;
12132 for (y
= 0, row
= w
->desired_matrix
->rows
;
12134 y
+= row
->height
, ++row
)
12135 blank_row (w
, row
, y
);
12136 goto finish_scroll_bars
;
12139 clear_glyph_matrix (w
->desired_matrix
);
12142 /* Otherwise set up data on this window; select its buffer and point
12144 /* Really select the buffer, for the sake of buffer-local
12146 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12147 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12149 current_matrix_up_to_date_p
12150 = (!NILP (w
->window_end_valid
)
12151 && !current_buffer
->clip_changed
12152 && !current_buffer
->prevent_redisplay_optimizations_p
12153 && XFASTINT (w
->last_modified
) >= MODIFF
12154 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12157 = (!NILP (w
->window_end_valid
)
12158 && !current_buffer
->clip_changed
12159 && XFASTINT (w
->last_modified
) >= MODIFF
12160 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12162 /* When windows_or_buffers_changed is non-zero, we can't rely on
12163 the window end being valid, so set it to nil there. */
12164 if (windows_or_buffers_changed
)
12166 /* If window starts on a continuation line, maybe adjust the
12167 window start in case the window's width changed. */
12168 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12169 compute_window_start_on_continuation_line (w
);
12171 w
->window_end_valid
= Qnil
;
12174 /* Some sanity checks. */
12175 CHECK_WINDOW_END (w
);
12176 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12178 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12181 /* If %c is in mode line, update it if needed. */
12182 if (!NILP (w
->column_number_displayed
)
12183 /* This alternative quickly identifies a common case
12184 where no change is needed. */
12185 && !(PT
== XFASTINT (w
->last_point
)
12186 && XFASTINT (w
->last_modified
) >= MODIFF
12187 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12188 && (XFASTINT (w
->column_number_displayed
)
12189 != (int) current_column ())) /* iftc */
12190 update_mode_line
= 1;
12192 /* Count number of windows showing the selected buffer. An indirect
12193 buffer counts as its base buffer. */
12194 if (!just_this_one_p
)
12196 struct buffer
*current_base
, *window_base
;
12197 current_base
= current_buffer
;
12198 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12199 if (current_base
->base_buffer
)
12200 current_base
= current_base
->base_buffer
;
12201 if (window_base
->base_buffer
)
12202 window_base
= window_base
->base_buffer
;
12203 if (current_base
== window_base
)
12207 /* Point refers normally to the selected window. For any other
12208 window, set up appropriate value. */
12209 if (!EQ (window
, selected_window
))
12211 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12212 int new_pt_byte
= marker_byte_position (w
->pointm
);
12216 new_pt_byte
= BEGV_BYTE
;
12217 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12219 else if (new_pt
> (ZV
- 1))
12222 new_pt_byte
= ZV_BYTE
;
12223 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12226 /* We don't use SET_PT so that the point-motion hooks don't run. */
12227 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12230 /* If any of the character widths specified in the display table
12231 have changed, invalidate the width run cache. It's true that
12232 this may be a bit late to catch such changes, but the rest of
12233 redisplay goes (non-fatally) haywire when the display table is
12234 changed, so why should we worry about doing any better? */
12235 if (current_buffer
->width_run_cache
)
12237 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12239 if (! disptab_matches_widthtab (disptab
,
12240 XVECTOR (current_buffer
->width_table
)))
12242 invalidate_region_cache (current_buffer
,
12243 current_buffer
->width_run_cache
,
12245 recompute_width_table (current_buffer
, disptab
);
12249 /* If window-start is screwed up, choose a new one. */
12250 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12253 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12255 /* If someone specified a new starting point but did not insist,
12256 check whether it can be used. */
12257 if (!NILP (w
->optional_new_start
)
12258 && CHARPOS (startp
) >= BEGV
12259 && CHARPOS (startp
) <= ZV
)
12261 w
->optional_new_start
= Qnil
;
12262 start_display (&it
, w
, startp
);
12263 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12264 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12265 if (IT_CHARPOS (it
) == PT
)
12266 w
->force_start
= Qt
;
12267 /* IT may overshoot PT if text at PT is invisible. */
12268 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12269 w
->force_start
= Qt
;
12274 /* Handle case where place to start displaying has been specified,
12275 unless the specified location is outside the accessible range. */
12276 if (!NILP (w
->force_start
)
12277 || w
->frozen_window_start_p
)
12279 /* We set this later on if we have to adjust point. */
12283 w
->force_start
= Qnil
;
12285 w
->window_end_valid
= Qnil
;
12287 /* Forget any recorded base line for line number display. */
12288 if (!buffer_unchanged_p
)
12289 w
->base_line_number
= Qnil
;
12291 /* Redisplay the mode line. Select the buffer properly for that.
12292 Also, run the hook window-scroll-functions
12293 because we have scrolled. */
12294 /* Note, we do this after clearing force_start because
12295 if there's an error, it is better to forget about force_start
12296 than to get into an infinite loop calling the hook functions
12297 and having them get more errors. */
12298 if (!update_mode_line
12299 || ! NILP (Vwindow_scroll_functions
))
12301 update_mode_line
= 1;
12302 w
->update_mode_line
= Qt
;
12303 startp
= run_window_scroll_functions (window
, startp
);
12306 w
->last_modified
= make_number (0);
12307 w
->last_overlay_modified
= make_number (0);
12308 if (CHARPOS (startp
) < BEGV
)
12309 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12310 else if (CHARPOS (startp
) > ZV
)
12311 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12313 /* Redisplay, then check if cursor has been set during the
12314 redisplay. Give up if new fonts were loaded. */
12315 val
= try_window (window
, startp
, 1);
12318 w
->force_start
= Qt
;
12319 clear_glyph_matrix (w
->desired_matrix
);
12320 goto need_larger_matrices
;
12322 /* Point was outside the scroll margins. */
12324 new_vpos
= window_box_height (w
) / 2;
12326 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12328 /* If point does not appear, try to move point so it does
12329 appear. The desired matrix has been built above, so we
12330 can use it here. */
12331 new_vpos
= window_box_height (w
) / 2;
12334 if (!cursor_row_fully_visible_p (w
, 0, 0))
12336 /* Point does appear, but on a line partly visible at end of window.
12337 Move it back to a fully-visible line. */
12338 new_vpos
= window_box_height (w
);
12341 /* If we need to move point for either of the above reasons,
12342 now actually do it. */
12345 struct glyph_row
*row
;
12347 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12348 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12351 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12352 MATRIX_ROW_START_BYTEPOS (row
));
12354 if (w
!= XWINDOW (selected_window
))
12355 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12356 else if (current_buffer
== old
)
12357 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12359 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12361 /* If we are highlighting the region, then we just changed
12362 the region, so redisplay to show it. */
12363 if (!NILP (Vtransient_mark_mode
)
12364 && !NILP (current_buffer
->mark_active
))
12366 clear_glyph_matrix (w
->desired_matrix
);
12367 if (!try_window (window
, startp
, 0))
12368 goto need_larger_matrices
;
12373 debug_method_add (w
, "forced window start");
12378 /* Handle case where text has not changed, only point, and it has
12379 not moved off the frame, and we are not retrying after hscroll.
12380 (current_matrix_up_to_date_p is nonzero when retrying.) */
12381 if (current_matrix_up_to_date_p
12382 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12383 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12387 case CURSOR_MOVEMENT_SUCCESS
:
12388 used_current_matrix_p
= 1;
12391 #if 0 /* try_cursor_movement never returns this value. */
12392 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12393 goto need_larger_matrices
;
12396 case CURSOR_MOVEMENT_MUST_SCROLL
:
12397 goto try_to_scroll
;
12403 /* If current starting point was originally the beginning of a line
12404 but no longer is, find a new starting point. */
12405 else if (!NILP (w
->start_at_line_beg
)
12406 && !(CHARPOS (startp
) <= BEGV
12407 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12410 debug_method_add (w
, "recenter 1");
12415 /* Try scrolling with try_window_id. Value is > 0 if update has
12416 been done, it is -1 if we know that the same window start will
12417 not work. It is 0 if unsuccessful for some other reason. */
12418 else if ((tem
= try_window_id (w
)) != 0)
12421 debug_method_add (w
, "try_window_id %d", tem
);
12424 if (fonts_changed_p
)
12425 goto need_larger_matrices
;
12429 /* Otherwise try_window_id has returned -1 which means that we
12430 don't want the alternative below this comment to execute. */
12432 else if (CHARPOS (startp
) >= BEGV
12433 && CHARPOS (startp
) <= ZV
12434 && PT
>= CHARPOS (startp
)
12435 && (CHARPOS (startp
) < ZV
12436 /* Avoid starting at end of buffer. */
12437 || CHARPOS (startp
) == BEGV
12438 || (XFASTINT (w
->last_modified
) >= MODIFF
12439 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12442 debug_method_add (w
, "same window start");
12445 /* Try to redisplay starting at same place as before.
12446 If point has not moved off frame, accept the results. */
12447 if (!current_matrix_up_to_date_p
12448 /* Don't use try_window_reusing_current_matrix in this case
12449 because a window scroll function can have changed the
12451 || !NILP (Vwindow_scroll_functions
)
12452 || MINI_WINDOW_P (w
)
12453 || !(used_current_matrix_p
12454 = try_window_reusing_current_matrix (w
)))
12456 IF_DEBUG (debug_method_add (w
, "1"));
12457 if (try_window (window
, startp
, 1) < 0)
12458 /* -1 means we need to scroll.
12459 0 means we need new matrices, but fonts_changed_p
12460 is set in that case, so we will detect it below. */
12461 goto try_to_scroll
;
12464 if (fonts_changed_p
)
12465 goto need_larger_matrices
;
12467 if (w
->cursor
.vpos
>= 0)
12469 if (!just_this_one_p
12470 || current_buffer
->clip_changed
12471 || BEG_UNCHANGED
< CHARPOS (startp
))
12472 /* Forget any recorded base line for line number display. */
12473 w
->base_line_number
= Qnil
;
12475 if (!cursor_row_fully_visible_p (w
, 1, 0))
12477 clear_glyph_matrix (w
->desired_matrix
);
12478 last_line_misfit
= 1;
12480 /* Drop through and scroll. */
12485 clear_glyph_matrix (w
->desired_matrix
);
12490 w
->last_modified
= make_number (0);
12491 w
->last_overlay_modified
= make_number (0);
12493 /* Redisplay the mode line. Select the buffer properly for that. */
12494 if (!update_mode_line
)
12496 update_mode_line
= 1;
12497 w
->update_mode_line
= Qt
;
12500 /* Try to scroll by specified few lines. */
12501 if ((scroll_conservatively
12503 || temp_scroll_step
12504 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12505 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12506 && !current_buffer
->clip_changed
12507 && CHARPOS (startp
) >= BEGV
12508 && CHARPOS (startp
) <= ZV
)
12510 /* The function returns -1 if new fonts were loaded, 1 if
12511 successful, 0 if not successful. */
12512 int rc
= try_scrolling (window
, just_this_one_p
,
12513 scroll_conservatively
,
12515 temp_scroll_step
, last_line_misfit
);
12518 case SCROLLING_SUCCESS
:
12521 case SCROLLING_NEED_LARGER_MATRICES
:
12522 goto need_larger_matrices
;
12524 case SCROLLING_FAILED
:
12532 /* Finally, just choose place to start which centers point */
12535 if (centering_position
< 0)
12536 centering_position
= window_box_height (w
) / 2;
12539 debug_method_add (w
, "recenter");
12542 /* w->vscroll = 0; */
12544 /* Forget any previously recorded base line for line number display. */
12545 if (!buffer_unchanged_p
)
12546 w
->base_line_number
= Qnil
;
12548 /* Move backward half the height of the window. */
12549 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12550 it
.current_y
= it
.last_visible_y
;
12551 move_it_vertically_backward (&it
, centering_position
);
12552 xassert (IT_CHARPOS (it
) >= BEGV
);
12554 /* The function move_it_vertically_backward may move over more
12555 than the specified y-distance. If it->w is small, e.g. a
12556 mini-buffer window, we may end up in front of the window's
12557 display area. Start displaying at the start of the line
12558 containing PT in this case. */
12559 if (it
.current_y
<= 0)
12561 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12562 move_it_vertically_backward (&it
, 0);
12564 /* I think this assert is bogus if buffer contains
12565 invisible text or images. KFS. */
12566 xassert (IT_CHARPOS (it
) <= PT
);
12571 it
.current_x
= it
.hpos
= 0;
12573 /* Set startp here explicitly in case that helps avoid an infinite loop
12574 in case the window-scroll-functions functions get errors. */
12575 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12577 /* Run scroll hooks. */
12578 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12580 /* Redisplay the window. */
12581 if (!current_matrix_up_to_date_p
12582 || windows_or_buffers_changed
12583 || cursor_type_changed
12584 /* Don't use try_window_reusing_current_matrix in this case
12585 because it can have changed the buffer. */
12586 || !NILP (Vwindow_scroll_functions
)
12587 || !just_this_one_p
12588 || MINI_WINDOW_P (w
)
12589 || !(used_current_matrix_p
12590 = try_window_reusing_current_matrix (w
)))
12591 try_window (window
, startp
, 0);
12593 /* If new fonts have been loaded (due to fontsets), give up. We
12594 have to start a new redisplay since we need to re-adjust glyph
12596 if (fonts_changed_p
)
12597 goto need_larger_matrices
;
12599 /* If cursor did not appear assume that the middle of the window is
12600 in the first line of the window. Do it again with the next line.
12601 (Imagine a window of height 100, displaying two lines of height
12602 60. Moving back 50 from it->last_visible_y will end in the first
12604 if (w
->cursor
.vpos
< 0)
12606 if (!NILP (w
->window_end_valid
)
12607 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12609 clear_glyph_matrix (w
->desired_matrix
);
12610 move_it_by_lines (&it
, 1, 0);
12611 try_window (window
, it
.current
.pos
, 0);
12613 else if (PT
< IT_CHARPOS (it
))
12615 clear_glyph_matrix (w
->desired_matrix
);
12616 move_it_by_lines (&it
, -1, 0);
12617 try_window (window
, it
.current
.pos
, 0);
12621 /* Not much we can do about it. */
12625 /* Consider the following case: Window starts at BEGV, there is
12626 invisible, intangible text at BEGV, so that display starts at
12627 some point START > BEGV. It can happen that we are called with
12628 PT somewhere between BEGV and START. Try to handle that case. */
12629 if (w
->cursor
.vpos
< 0)
12631 struct glyph_row
*row
= w
->current_matrix
->rows
;
12632 if (row
->mode_line_p
)
12634 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12637 if (!cursor_row_fully_visible_p (w
, 0, 0))
12639 /* If vscroll is enabled, disable it and try again. */
12643 clear_glyph_matrix (w
->desired_matrix
);
12647 /* If centering point failed to make the whole line visible,
12648 put point at the top instead. That has to make the whole line
12649 visible, if it can be done. */
12650 if (centering_position
== 0)
12653 clear_glyph_matrix (w
->desired_matrix
);
12654 centering_position
= 0;
12660 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12661 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12662 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12665 /* Display the mode line, if we must. */
12666 if ((update_mode_line
12667 /* If window not full width, must redo its mode line
12668 if (a) the window to its side is being redone and
12669 (b) we do a frame-based redisplay. This is a consequence
12670 of how inverted lines are drawn in frame-based redisplay. */
12671 || (!just_this_one_p
12672 && !FRAME_WINDOW_P (f
)
12673 && !WINDOW_FULL_WIDTH_P (w
))
12674 /* Line number to display. */
12675 || INTEGERP (w
->base_line_pos
)
12676 /* Column number is displayed and different from the one displayed. */
12677 || (!NILP (w
->column_number_displayed
)
12678 && (XFASTINT (w
->column_number_displayed
)
12679 != (int) current_column ()))) /* iftc */
12680 /* This means that the window has a mode line. */
12681 && (WINDOW_WANTS_MODELINE_P (w
)
12682 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12684 display_mode_lines (w
);
12686 /* If mode line height has changed, arrange for a thorough
12687 immediate redisplay using the correct mode line height. */
12688 if (WINDOW_WANTS_MODELINE_P (w
)
12689 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12691 fonts_changed_p
= 1;
12692 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12693 = DESIRED_MODE_LINE_HEIGHT (w
);
12696 /* If top line height has changed, arrange for a thorough
12697 immediate redisplay using the correct mode line height. */
12698 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12699 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12701 fonts_changed_p
= 1;
12702 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12703 = DESIRED_HEADER_LINE_HEIGHT (w
);
12706 if (fonts_changed_p
)
12707 goto need_larger_matrices
;
12710 if (!line_number_displayed
12711 && !BUFFERP (w
->base_line_pos
))
12713 w
->base_line_pos
= Qnil
;
12714 w
->base_line_number
= Qnil
;
12719 /* When we reach a frame's selected window, redo the frame's menu bar. */
12720 if (update_mode_line
12721 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12723 int redisplay_menu_p
= 0;
12724 int redisplay_tool_bar_p
= 0;
12726 if (FRAME_WINDOW_P (f
))
12728 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12729 || defined (USE_GTK)
12730 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12732 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12736 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12738 if (redisplay_menu_p
)
12739 display_menu_bar (w
);
12741 #ifdef HAVE_WINDOW_SYSTEM
12743 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12745 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12746 && (FRAME_TOOL_BAR_LINES (f
) > 0
12747 || auto_resize_tool_bars_p
);
12751 if (redisplay_tool_bar_p
)
12752 redisplay_tool_bar (f
);
12756 #ifdef HAVE_WINDOW_SYSTEM
12757 if (FRAME_WINDOW_P (f
)
12758 && update_window_fringes (w
, (just_this_one_p
12759 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
12760 || w
->pseudo_window_p
)))
12764 if (draw_window_fringes (w
, 1))
12765 x_draw_vertical_border (w
);
12769 #endif /* HAVE_WINDOW_SYSTEM */
12771 /* We go to this label, with fonts_changed_p nonzero,
12772 if it is necessary to try again using larger glyph matrices.
12773 We have to redeem the scroll bar even in this case,
12774 because the loop in redisplay_internal expects that. */
12775 need_larger_matrices
:
12777 finish_scroll_bars
:
12779 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12781 /* Set the thumb's position and size. */
12782 set_vertical_scroll_bar (w
);
12784 /* Note that we actually used the scroll bar attached to this
12785 window, so it shouldn't be deleted at the end of redisplay. */
12786 redeem_scroll_bar_hook (w
);
12789 /* Restore current_buffer and value of point in it. */
12790 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12791 set_buffer_internal_1 (old
);
12792 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12794 unbind_to (count
, Qnil
);
12798 /* Build the complete desired matrix of WINDOW with a window start
12799 buffer position POS.
12801 Value is 1 if successful. It is zero if fonts were loaded during
12802 redisplay which makes re-adjusting glyph matrices necessary, and -1
12803 if point would appear in the scroll margins.
12804 (We check that only if CHECK_MARGINS is nonzero. */
12807 try_window (window
, pos
, check_margins
)
12808 Lisp_Object window
;
12809 struct text_pos pos
;
12812 struct window
*w
= XWINDOW (window
);
12814 struct glyph_row
*last_text_row
= NULL
;
12816 /* Make POS the new window start. */
12817 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12819 /* Mark cursor position as unknown. No overlay arrow seen. */
12820 w
->cursor
.vpos
= -1;
12821 overlay_arrow_seen
= 0;
12823 /* Initialize iterator and info to start at POS. */
12824 start_display (&it
, w
, pos
);
12826 /* Display all lines of W. */
12827 while (it
.current_y
< it
.last_visible_y
)
12829 if (display_line (&it
))
12830 last_text_row
= it
.glyph_row
- 1;
12831 if (fonts_changed_p
)
12835 /* Don't let the cursor end in the scroll margins. */
12837 && !MINI_WINDOW_P (w
))
12839 int this_scroll_margin
;
12841 this_scroll_margin
= max (0, scroll_margin
);
12842 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12843 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
12845 if ((w
->cursor
.y
< this_scroll_margin
12846 && CHARPOS (pos
) > BEGV
)
12847 /* rms: considering make_cursor_line_fully_visible_p here
12848 seems to give wrong results. We don't want to recenter
12849 when the last line is partly visible, we want to allow
12850 that case to be handled in the usual way. */
12851 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
12853 w
->cursor
.vpos
= -1;
12854 clear_glyph_matrix (w
->desired_matrix
);
12859 /* If bottom moved off end of frame, change mode line percentage. */
12860 if (XFASTINT (w
->window_end_pos
) <= 0
12861 && Z
!= IT_CHARPOS (it
))
12862 w
->update_mode_line
= Qt
;
12864 /* Set window_end_pos to the offset of the last character displayed
12865 on the window from the end of current_buffer. Set
12866 window_end_vpos to its row number. */
12869 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12870 w
->window_end_bytepos
12871 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12873 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12875 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12876 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12877 ->displays_text_p
);
12881 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12882 w
->window_end_pos
= make_number (Z
- ZV
);
12883 w
->window_end_vpos
= make_number (0);
12886 /* But that is not valid info until redisplay finishes. */
12887 w
->window_end_valid
= Qnil
;
12893 /************************************************************************
12894 Window redisplay reusing current matrix when buffer has not changed
12895 ************************************************************************/
12897 /* Try redisplay of window W showing an unchanged buffer with a
12898 different window start than the last time it was displayed by
12899 reusing its current matrix. Value is non-zero if successful.
12900 W->start is the new window start. */
12903 try_window_reusing_current_matrix (w
)
12906 struct frame
*f
= XFRAME (w
->frame
);
12907 struct glyph_row
*row
, *bottom_row
;
12910 struct text_pos start
, new_start
;
12911 int nrows_scrolled
, i
;
12912 struct glyph_row
*last_text_row
;
12913 struct glyph_row
*last_reused_text_row
;
12914 struct glyph_row
*start_row
;
12915 int start_vpos
, min_y
, max_y
;
12918 if (inhibit_try_window_reusing
)
12922 if (/* This function doesn't handle terminal frames. */
12923 !FRAME_WINDOW_P (f
)
12924 /* Don't try to reuse the display if windows have been split
12926 || windows_or_buffers_changed
12927 || cursor_type_changed
)
12930 /* Can't do this if region may have changed. */
12931 if ((!NILP (Vtransient_mark_mode
)
12932 && !NILP (current_buffer
->mark_active
))
12933 || !NILP (w
->region_showing
)
12934 || !NILP (Vshow_trailing_whitespace
))
12937 /* If top-line visibility has changed, give up. */
12938 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12939 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12942 /* Give up if old or new display is scrolled vertically. We could
12943 make this function handle this, but right now it doesn't. */
12944 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12945 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12948 /* The variable new_start now holds the new window start. The old
12949 start `start' can be determined from the current matrix. */
12950 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12951 start
= start_row
->start
.pos
;
12952 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12954 /* Clear the desired matrix for the display below. */
12955 clear_glyph_matrix (w
->desired_matrix
);
12957 if (CHARPOS (new_start
) <= CHARPOS (start
))
12961 /* Don't use this method if the display starts with an ellipsis
12962 displayed for invisible text. It's not easy to handle that case
12963 below, and it's certainly not worth the effort since this is
12964 not a frequent case. */
12965 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12968 IF_DEBUG (debug_method_add (w
, "twu1"));
12970 /* Display up to a row that can be reused. The variable
12971 last_text_row is set to the last row displayed that displays
12972 text. Note that it.vpos == 0 if or if not there is a
12973 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12974 start_display (&it
, w
, new_start
);
12975 first_row_y
= it
.current_y
;
12976 w
->cursor
.vpos
= -1;
12977 last_text_row
= last_reused_text_row
= NULL
;
12979 while (it
.current_y
< it
.last_visible_y
12980 && !fonts_changed_p
)
12982 /* If we have reached into the characters in the START row,
12983 that means the line boundaries have changed. So we
12984 can't start copying with the row START. Maybe it will
12985 work to start copying with the following row. */
12986 while (IT_CHARPOS (it
) > CHARPOS (start
))
12988 /* Advance to the next row as the "start". */
12990 start
= start_row
->start
.pos
;
12991 /* If there are no more rows to try, or just one, give up. */
12992 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12993 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12994 || CHARPOS (start
) == ZV
)
12996 clear_glyph_matrix (w
->desired_matrix
);
13000 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
13002 /* If we have reached alignment,
13003 we can copy the rest of the rows. */
13004 if (IT_CHARPOS (it
) == CHARPOS (start
))
13007 if (display_line (&it
))
13008 last_text_row
= it
.glyph_row
- 1;
13011 /* A value of current_y < last_visible_y means that we stopped
13012 at the previous window start, which in turn means that we
13013 have at least one reusable row. */
13014 if (it
.current_y
< it
.last_visible_y
)
13016 /* IT.vpos always starts from 0; it counts text lines. */
13017 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
13019 /* Find PT if not already found in the lines displayed. */
13020 if (w
->cursor
.vpos
< 0)
13022 int dy
= it
.current_y
- start_row
->y
;
13024 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13025 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
13027 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
13028 dy
, nrows_scrolled
);
13031 clear_glyph_matrix (w
->desired_matrix
);
13036 /* Scroll the display. Do it before the current matrix is
13037 changed. The problem here is that update has not yet
13038 run, i.e. part of the current matrix is not up to date.
13039 scroll_run_hook will clear the cursor, and use the
13040 current matrix to get the height of the row the cursor is
13042 run
.current_y
= start_row
->y
;
13043 run
.desired_y
= it
.current_y
;
13044 run
.height
= it
.last_visible_y
- it
.current_y
;
13046 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
13049 rif
->update_window_begin_hook (w
);
13050 rif
->clear_window_mouse_face (w
);
13051 rif
->scroll_run_hook (w
, &run
);
13052 rif
->update_window_end_hook (w
, 0, 0);
13056 /* Shift current matrix down by nrows_scrolled lines. */
13057 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13058 rotate_matrix (w
->current_matrix
,
13060 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13063 /* Disable lines that must be updated. */
13064 for (i
= 0; i
< it
.vpos
; ++i
)
13065 (start_row
+ i
)->enabled_p
= 0;
13067 /* Re-compute Y positions. */
13068 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13069 max_y
= it
.last_visible_y
;
13070 for (row
= start_row
+ nrows_scrolled
;
13074 row
->y
= it
.current_y
;
13075 row
->visible_height
= row
->height
;
13077 if (row
->y
< min_y
)
13078 row
->visible_height
-= min_y
- row
->y
;
13079 if (row
->y
+ row
->height
> max_y
)
13080 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13081 row
->redraw_fringe_bitmaps_p
= 1;
13083 it
.current_y
+= row
->height
;
13085 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13086 last_reused_text_row
= row
;
13087 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13091 /* Disable lines in the current matrix which are now
13092 below the window. */
13093 for (++row
; row
< bottom_row
; ++row
)
13094 row
->enabled_p
= row
->mode_line_p
= 0;
13097 /* Update window_end_pos etc.; last_reused_text_row is the last
13098 reused row from the current matrix containing text, if any.
13099 The value of last_text_row is the last displayed line
13100 containing text. */
13101 if (last_reused_text_row
)
13103 w
->window_end_bytepos
13104 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13106 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13108 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13109 w
->current_matrix
));
13111 else if (last_text_row
)
13113 w
->window_end_bytepos
13114 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13116 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13118 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13122 /* This window must be completely empty. */
13123 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13124 w
->window_end_pos
= make_number (Z
- ZV
);
13125 w
->window_end_vpos
= make_number (0);
13127 w
->window_end_valid
= Qnil
;
13129 /* Update hint: don't try scrolling again in update_window. */
13130 w
->desired_matrix
->no_scrolling_p
= 1;
13133 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13137 else if (CHARPOS (new_start
) > CHARPOS (start
))
13139 struct glyph_row
*pt_row
, *row
;
13140 struct glyph_row
*first_reusable_row
;
13141 struct glyph_row
*first_row_to_display
;
13143 int yb
= window_text_bottom_y (w
);
13145 /* Find the row starting at new_start, if there is one. Don't
13146 reuse a partially visible line at the end. */
13147 first_reusable_row
= start_row
;
13148 while (first_reusable_row
->enabled_p
13149 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13150 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13151 < CHARPOS (new_start
)))
13152 ++first_reusable_row
;
13154 /* Give up if there is no row to reuse. */
13155 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13156 || !first_reusable_row
->enabled_p
13157 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13158 != CHARPOS (new_start
)))
13161 /* We can reuse fully visible rows beginning with
13162 first_reusable_row to the end of the window. Set
13163 first_row_to_display to the first row that cannot be reused.
13164 Set pt_row to the row containing point, if there is any. */
13166 for (first_row_to_display
= first_reusable_row
;
13167 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13168 ++first_row_to_display
)
13170 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13171 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13172 pt_row
= first_row_to_display
;
13175 /* Start displaying at the start of first_row_to_display. */
13176 xassert (first_row_to_display
->y
< yb
);
13177 init_to_row_start (&it
, w
, first_row_to_display
);
13179 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13181 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13183 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13184 + WINDOW_HEADER_LINE_HEIGHT (w
));
13186 /* Display lines beginning with first_row_to_display in the
13187 desired matrix. Set last_text_row to the last row displayed
13188 that displays text. */
13189 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13190 if (pt_row
== NULL
)
13191 w
->cursor
.vpos
= -1;
13192 last_text_row
= NULL
;
13193 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13194 if (display_line (&it
))
13195 last_text_row
= it
.glyph_row
- 1;
13197 /* Give up If point isn't in a row displayed or reused. */
13198 if (w
->cursor
.vpos
< 0)
13200 clear_glyph_matrix (w
->desired_matrix
);
13204 /* If point is in a reused row, adjust y and vpos of the cursor
13208 w
->cursor
.vpos
-= nrows_scrolled
;
13209 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13212 /* Scroll the display. */
13213 run
.current_y
= first_reusable_row
->y
;
13214 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13215 run
.height
= it
.last_visible_y
- run
.current_y
;
13216 dy
= run
.current_y
- run
.desired_y
;
13221 rif
->update_window_begin_hook (w
);
13222 rif
->clear_window_mouse_face (w
);
13223 rif
->scroll_run_hook (w
, &run
);
13224 rif
->update_window_end_hook (w
, 0, 0);
13228 /* Adjust Y positions of reused rows. */
13229 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13230 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13231 max_y
= it
.last_visible_y
;
13232 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13235 row
->visible_height
= row
->height
;
13236 if (row
->y
< min_y
)
13237 row
->visible_height
-= min_y
- row
->y
;
13238 if (row
->y
+ row
->height
> max_y
)
13239 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13240 row
->redraw_fringe_bitmaps_p
= 1;
13243 /* Scroll the current matrix. */
13244 xassert (nrows_scrolled
> 0);
13245 rotate_matrix (w
->current_matrix
,
13247 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13250 /* Disable rows not reused. */
13251 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13252 row
->enabled_p
= 0;
13254 /* Point may have moved to a different line, so we cannot assume that
13255 the previous cursor position is valid; locate the correct row. */
13258 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13259 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13263 w
->cursor
.y
= row
->y
;
13265 if (row
< bottom_row
)
13267 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13268 while (glyph
->charpos
< PT
)
13271 w
->cursor
.x
+= glyph
->pixel_width
;
13277 /* Adjust window end. A null value of last_text_row means that
13278 the window end is in reused rows which in turn means that
13279 only its vpos can have changed. */
13282 w
->window_end_bytepos
13283 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13285 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13287 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13292 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13295 w
->window_end_valid
= Qnil
;
13296 w
->desired_matrix
->no_scrolling_p
= 1;
13299 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13309 /************************************************************************
13310 Window redisplay reusing current matrix when buffer has changed
13311 ************************************************************************/
13313 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13314 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13316 static struct glyph_row
*
13317 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13318 struct glyph_row
*));
13321 /* Return the last row in MATRIX displaying text. If row START is
13322 non-null, start searching with that row. IT gives the dimensions
13323 of the display. Value is null if matrix is empty; otherwise it is
13324 a pointer to the row found. */
13326 static struct glyph_row
*
13327 find_last_row_displaying_text (matrix
, it
, start
)
13328 struct glyph_matrix
*matrix
;
13330 struct glyph_row
*start
;
13332 struct glyph_row
*row
, *row_found
;
13334 /* Set row_found to the last row in IT->w's current matrix
13335 displaying text. The loop looks funny but think of partially
13338 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13339 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13341 xassert (row
->enabled_p
);
13343 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13352 /* Return the last row in the current matrix of W that is not affected
13353 by changes at the start of current_buffer that occurred since W's
13354 current matrix was built. Value is null if no such row exists.
13356 BEG_UNCHANGED us the number of characters unchanged at the start of
13357 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13358 first changed character in current_buffer. Characters at positions <
13359 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13360 when the current matrix was built. */
13362 static struct glyph_row
*
13363 find_last_unchanged_at_beg_row (w
)
13366 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13367 struct glyph_row
*row
;
13368 struct glyph_row
*row_found
= NULL
;
13369 int yb
= window_text_bottom_y (w
);
13371 /* Find the last row displaying unchanged text. */
13372 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13373 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13374 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13376 if (/* If row ends before first_changed_pos, it is unchanged,
13377 except in some case. */
13378 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13379 /* When row ends in ZV and we write at ZV it is not
13381 && !row
->ends_at_zv_p
13382 /* When first_changed_pos is the end of a continued line,
13383 row is not unchanged because it may be no longer
13385 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13386 && (row
->continued_p
13387 || row
->exact_window_width_line_p
)))
13390 /* Stop if last visible row. */
13391 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13401 /* Find the first glyph row in the current matrix of W that is not
13402 affected by changes at the end of current_buffer since the
13403 time W's current matrix was built.
13405 Return in *DELTA the number of chars by which buffer positions in
13406 unchanged text at the end of current_buffer must be adjusted.
13408 Return in *DELTA_BYTES the corresponding number of bytes.
13410 Value is null if no such row exists, i.e. all rows are affected by
13413 static struct glyph_row
*
13414 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13416 int *delta
, *delta_bytes
;
13418 struct glyph_row
*row
;
13419 struct glyph_row
*row_found
= NULL
;
13421 *delta
= *delta_bytes
= 0;
13423 /* Display must not have been paused, otherwise the current matrix
13424 is not up to date. */
13425 if (NILP (w
->window_end_valid
))
13428 /* A value of window_end_pos >= END_UNCHANGED means that the window
13429 end is in the range of changed text. If so, there is no
13430 unchanged row at the end of W's current matrix. */
13431 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13434 /* Set row to the last row in W's current matrix displaying text. */
13435 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13437 /* If matrix is entirely empty, no unchanged row exists. */
13438 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13440 /* The value of row is the last glyph row in the matrix having a
13441 meaningful buffer position in it. The end position of row
13442 corresponds to window_end_pos. This allows us to translate
13443 buffer positions in the current matrix to current buffer
13444 positions for characters not in changed text. */
13445 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13446 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13447 int last_unchanged_pos
, last_unchanged_pos_old
;
13448 struct glyph_row
*first_text_row
13449 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13451 *delta
= Z
- Z_old
;
13452 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13454 /* Set last_unchanged_pos to the buffer position of the last
13455 character in the buffer that has not been changed. Z is the
13456 index + 1 of the last character in current_buffer, i.e. by
13457 subtracting END_UNCHANGED we get the index of the last
13458 unchanged character, and we have to add BEG to get its buffer
13460 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13461 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13463 /* Search backward from ROW for a row displaying a line that
13464 starts at a minimum position >= last_unchanged_pos_old. */
13465 for (; row
> first_text_row
; --row
)
13467 /* This used to abort, but it can happen.
13468 It is ok to just stop the search instead here. KFS. */
13469 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13472 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13477 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13484 /* Make sure that glyph rows in the current matrix of window W
13485 reference the same glyph memory as corresponding rows in the
13486 frame's frame matrix. This function is called after scrolling W's
13487 current matrix on a terminal frame in try_window_id and
13488 try_window_reusing_current_matrix. */
13491 sync_frame_with_window_matrix_rows (w
)
13494 struct frame
*f
= XFRAME (w
->frame
);
13495 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13497 /* Preconditions: W must be a leaf window and full-width. Its frame
13498 must have a frame matrix. */
13499 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13500 xassert (WINDOW_FULL_WIDTH_P (w
));
13501 xassert (!FRAME_WINDOW_P (f
));
13503 /* If W is a full-width window, glyph pointers in W's current matrix
13504 have, by definition, to be the same as glyph pointers in the
13505 corresponding frame matrix. Note that frame matrices have no
13506 marginal areas (see build_frame_matrix). */
13507 window_row
= w
->current_matrix
->rows
;
13508 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13509 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13510 while (window_row
< window_row_end
)
13512 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13513 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13515 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13516 frame_row
->glyphs
[TEXT_AREA
] = start
;
13517 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13518 frame_row
->glyphs
[LAST_AREA
] = end
;
13520 /* Disable frame rows whose corresponding window rows have
13521 been disabled in try_window_id. */
13522 if (!window_row
->enabled_p
)
13523 frame_row
->enabled_p
= 0;
13525 ++window_row
, ++frame_row
;
13530 /* Find the glyph row in window W containing CHARPOS. Consider all
13531 rows between START and END (not inclusive). END null means search
13532 all rows to the end of the display area of W. Value is the row
13533 containing CHARPOS or null. */
13536 row_containing_pos (w
, charpos
, start
, end
, dy
)
13539 struct glyph_row
*start
, *end
;
13542 struct glyph_row
*row
= start
;
13545 /* If we happen to start on a header-line, skip that. */
13546 if (row
->mode_line_p
)
13549 if ((end
&& row
>= end
) || !row
->enabled_p
)
13552 last_y
= window_text_bottom_y (w
) - dy
;
13556 /* Give up if we have gone too far. */
13557 if (end
&& row
>= end
)
13559 /* This formerly returned if they were equal.
13560 I think that both quantities are of a "last plus one" type;
13561 if so, when they are equal, the row is within the screen. -- rms. */
13562 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13565 /* If it is in this row, return this row. */
13566 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13567 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13568 /* The end position of a row equals the start
13569 position of the next row. If CHARPOS is there, we
13570 would rather display it in the next line, except
13571 when this line ends in ZV. */
13572 && !row
->ends_at_zv_p
13573 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13574 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13581 /* Try to redisplay window W by reusing its existing display. W's
13582 current matrix must be up to date when this function is called,
13583 i.e. window_end_valid must not be nil.
13587 1 if display has been updated
13588 0 if otherwise unsuccessful
13589 -1 if redisplay with same window start is known not to succeed
13591 The following steps are performed:
13593 1. Find the last row in the current matrix of W that is not
13594 affected by changes at the start of current_buffer. If no such row
13597 2. Find the first row in W's current matrix that is not affected by
13598 changes at the end of current_buffer. Maybe there is no such row.
13600 3. Display lines beginning with the row + 1 found in step 1 to the
13601 row found in step 2 or, if step 2 didn't find a row, to the end of
13604 4. If cursor is not known to appear on the window, give up.
13606 5. If display stopped at the row found in step 2, scroll the
13607 display and current matrix as needed.
13609 6. Maybe display some lines at the end of W, if we must. This can
13610 happen under various circumstances, like a partially visible line
13611 becoming fully visible, or because newly displayed lines are displayed
13612 in smaller font sizes.
13614 7. Update W's window end information. */
13620 struct frame
*f
= XFRAME (w
->frame
);
13621 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13622 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13623 struct glyph_row
*last_unchanged_at_beg_row
;
13624 struct glyph_row
*first_unchanged_at_end_row
;
13625 struct glyph_row
*row
;
13626 struct glyph_row
*bottom_row
;
13629 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13630 struct text_pos start_pos
;
13632 int first_unchanged_at_end_vpos
= 0;
13633 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13634 struct text_pos start
;
13635 int first_changed_charpos
, last_changed_charpos
;
13638 if (inhibit_try_window_id
)
13642 /* This is handy for debugging. */
13644 #define GIVE_UP(X) \
13646 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13650 #define GIVE_UP(X) return 0
13653 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13655 /* Don't use this for mini-windows because these can show
13656 messages and mini-buffers, and we don't handle that here. */
13657 if (MINI_WINDOW_P (w
))
13660 /* This flag is used to prevent redisplay optimizations. */
13661 if (windows_or_buffers_changed
|| cursor_type_changed
)
13664 /* Verify that narrowing has not changed.
13665 Also verify that we were not told to prevent redisplay optimizations.
13666 It would be nice to further
13667 reduce the number of cases where this prevents try_window_id. */
13668 if (current_buffer
->clip_changed
13669 || current_buffer
->prevent_redisplay_optimizations_p
)
13672 /* Window must either use window-based redisplay or be full width. */
13673 if (!FRAME_WINDOW_P (f
)
13674 && (!line_ins_del_ok
13675 || !WINDOW_FULL_WIDTH_P (w
)))
13678 /* Give up if point is not known NOT to appear in W. */
13679 if (PT
< CHARPOS (start
))
13682 /* Another way to prevent redisplay optimizations. */
13683 if (XFASTINT (w
->last_modified
) == 0)
13686 /* Verify that window is not hscrolled. */
13687 if (XFASTINT (w
->hscroll
) != 0)
13690 /* Verify that display wasn't paused. */
13691 if (NILP (w
->window_end_valid
))
13694 /* Can't use this if highlighting a region because a cursor movement
13695 will do more than just set the cursor. */
13696 if (!NILP (Vtransient_mark_mode
)
13697 && !NILP (current_buffer
->mark_active
))
13700 /* Likewise if highlighting trailing whitespace. */
13701 if (!NILP (Vshow_trailing_whitespace
))
13704 /* Likewise if showing a region. */
13705 if (!NILP (w
->region_showing
))
13708 /* Can use this if overlay arrow position and or string have changed. */
13709 if (overlay_arrows_changed_p ())
13713 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13714 only if buffer has really changed. The reason is that the gap is
13715 initially at Z for freshly visited files. The code below would
13716 set end_unchanged to 0 in that case. */
13717 if (MODIFF
> SAVE_MODIFF
13718 /* This seems to happen sometimes after saving a buffer. */
13719 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13721 if (GPT
- BEG
< BEG_UNCHANGED
)
13722 BEG_UNCHANGED
= GPT
- BEG
;
13723 if (Z
- GPT
< END_UNCHANGED
)
13724 END_UNCHANGED
= Z
- GPT
;
13727 /* The position of the first and last character that has been changed. */
13728 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13729 last_changed_charpos
= Z
- END_UNCHANGED
;
13731 /* If window starts after a line end, and the last change is in
13732 front of that newline, then changes don't affect the display.
13733 This case happens with stealth-fontification. Note that although
13734 the display is unchanged, glyph positions in the matrix have to
13735 be adjusted, of course. */
13736 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13737 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13738 && ((last_changed_charpos
< CHARPOS (start
)
13739 && CHARPOS (start
) == BEGV
)
13740 || (last_changed_charpos
< CHARPOS (start
) - 1
13741 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13743 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13744 struct glyph_row
*r0
;
13746 /* Compute how many chars/bytes have been added to or removed
13747 from the buffer. */
13748 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13749 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13751 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13753 /* Give up if PT is not in the window. Note that it already has
13754 been checked at the start of try_window_id that PT is not in
13755 front of the window start. */
13756 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13759 /* If window start is unchanged, we can reuse the whole matrix
13760 as is, after adjusting glyph positions. No need to compute
13761 the window end again, since its offset from Z hasn't changed. */
13762 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13763 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13764 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13765 /* PT must not be in a partially visible line. */
13766 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13767 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13769 /* Adjust positions in the glyph matrix. */
13770 if (delta
|| delta_bytes
)
13772 struct glyph_row
*r1
13773 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13774 increment_matrix_positions (w
->current_matrix
,
13775 MATRIX_ROW_VPOS (r0
, current_matrix
),
13776 MATRIX_ROW_VPOS (r1
, current_matrix
),
13777 delta
, delta_bytes
);
13780 /* Set the cursor. */
13781 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13783 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13790 /* Handle the case that changes are all below what is displayed in
13791 the window, and that PT is in the window. This shortcut cannot
13792 be taken if ZV is visible in the window, and text has been added
13793 there that is visible in the window. */
13794 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13795 /* ZV is not visible in the window, or there are no
13796 changes at ZV, actually. */
13797 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13798 || first_changed_charpos
== last_changed_charpos
))
13800 struct glyph_row
*r0
;
13802 /* Give up if PT is not in the window. Note that it already has
13803 been checked at the start of try_window_id that PT is not in
13804 front of the window start. */
13805 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13808 /* If window start is unchanged, we can reuse the whole matrix
13809 as is, without changing glyph positions since no text has
13810 been added/removed in front of the window end. */
13811 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13812 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13813 /* PT must not be in a partially visible line. */
13814 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13815 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13817 /* We have to compute the window end anew since text
13818 can have been added/removed after it. */
13820 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13821 w
->window_end_bytepos
13822 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13824 /* Set the cursor. */
13825 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13827 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13834 /* Give up if window start is in the changed area.
13836 The condition used to read
13838 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13840 but why that was tested escapes me at the moment. */
13841 if (CHARPOS (start
) >= first_changed_charpos
13842 && CHARPOS (start
) <= last_changed_charpos
)
13845 /* Check that window start agrees with the start of the first glyph
13846 row in its current matrix. Check this after we know the window
13847 start is not in changed text, otherwise positions would not be
13849 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13850 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13853 /* Give up if the window ends in strings. Overlay strings
13854 at the end are difficult to handle, so don't try. */
13855 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13856 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13859 /* Compute the position at which we have to start displaying new
13860 lines. Some of the lines at the top of the window might be
13861 reusable because they are not displaying changed text. Find the
13862 last row in W's current matrix not affected by changes at the
13863 start of current_buffer. Value is null if changes start in the
13864 first line of window. */
13865 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13866 if (last_unchanged_at_beg_row
)
13868 /* Avoid starting to display in the moddle of a character, a TAB
13869 for instance. This is easier than to set up the iterator
13870 exactly, and it's not a frequent case, so the additional
13871 effort wouldn't really pay off. */
13872 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13873 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13874 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13875 --last_unchanged_at_beg_row
;
13877 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13880 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13882 start_pos
= it
.current
.pos
;
13884 /* Start displaying new lines in the desired matrix at the same
13885 vpos we would use in the current matrix, i.e. below
13886 last_unchanged_at_beg_row. */
13887 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13889 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13890 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13892 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13896 /* There are no reusable lines at the start of the window.
13897 Start displaying in the first text line. */
13898 start_display (&it
, w
, start
);
13899 it
.vpos
= it
.first_vpos
;
13900 start_pos
= it
.current
.pos
;
13903 /* Find the first row that is not affected by changes at the end of
13904 the buffer. Value will be null if there is no unchanged row, in
13905 which case we must redisplay to the end of the window. delta
13906 will be set to the value by which buffer positions beginning with
13907 first_unchanged_at_end_row have to be adjusted due to text
13909 first_unchanged_at_end_row
13910 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13911 IF_DEBUG (debug_delta
= delta
);
13912 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13914 /* Set stop_pos to the buffer position up to which we will have to
13915 display new lines. If first_unchanged_at_end_row != NULL, this
13916 is the buffer position of the start of the line displayed in that
13917 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13918 that we don't stop at a buffer position. */
13920 if (first_unchanged_at_end_row
)
13922 xassert (last_unchanged_at_beg_row
== NULL
13923 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13925 /* If this is a continuation line, move forward to the next one
13926 that isn't. Changes in lines above affect this line.
13927 Caution: this may move first_unchanged_at_end_row to a row
13928 not displaying text. */
13929 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13930 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13931 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13932 < it
.last_visible_y
))
13933 ++first_unchanged_at_end_row
;
13935 if (!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
= NULL
;
13941 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13943 first_unchanged_at_end_vpos
13944 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13945 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13948 else if (last_unchanged_at_beg_row
== NULL
)
13954 /* Either there is no unchanged row at the end, or the one we have
13955 now displays text. This is a necessary condition for the window
13956 end pos calculation at the end of this function. */
13957 xassert (first_unchanged_at_end_row
== NULL
13958 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13960 debug_last_unchanged_at_beg_vpos
13961 = (last_unchanged_at_beg_row
13962 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13964 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13966 #endif /* GLYPH_DEBUG != 0 */
13969 /* Display new lines. Set last_text_row to the last new line
13970 displayed which has text on it, i.e. might end up as being the
13971 line where the window_end_vpos is. */
13972 w
->cursor
.vpos
= -1;
13973 last_text_row
= NULL
;
13974 overlay_arrow_seen
= 0;
13975 while (it
.current_y
< it
.last_visible_y
13976 && !fonts_changed_p
13977 && (first_unchanged_at_end_row
== NULL
13978 || IT_CHARPOS (it
) < stop_pos
))
13980 if (display_line (&it
))
13981 last_text_row
= it
.glyph_row
- 1;
13984 if (fonts_changed_p
)
13988 /* Compute differences in buffer positions, y-positions etc. for
13989 lines reused at the bottom of the window. Compute what we can
13991 if (first_unchanged_at_end_row
13992 /* No lines reused because we displayed everything up to the
13993 bottom of the window. */
13994 && it
.current_y
< it
.last_visible_y
)
13997 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13999 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
14000 run
.current_y
= first_unchanged_at_end_row
->y
;
14001 run
.desired_y
= run
.current_y
+ dy
;
14002 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
14006 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
14007 first_unchanged_at_end_row
= NULL
;
14009 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
14012 /* Find the cursor if not already found. We have to decide whether
14013 PT will appear on this window (it sometimes doesn't, but this is
14014 not a very frequent case.) This decision has to be made before
14015 the current matrix is altered. A value of cursor.vpos < 0 means
14016 that PT is either in one of the lines beginning at
14017 first_unchanged_at_end_row or below the window. Don't care for
14018 lines that might be displayed later at the window end; as
14019 mentioned, this is not a frequent case. */
14020 if (w
->cursor
.vpos
< 0)
14022 /* Cursor in unchanged rows at the top? */
14023 if (PT
< CHARPOS (start_pos
)
14024 && last_unchanged_at_beg_row
)
14026 row
= row_containing_pos (w
, PT
,
14027 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
14028 last_unchanged_at_beg_row
+ 1, 0);
14030 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14033 /* Start from first_unchanged_at_end_row looking for PT. */
14034 else if (first_unchanged_at_end_row
)
14036 row
= row_containing_pos (w
, PT
- delta
,
14037 first_unchanged_at_end_row
, NULL
, 0);
14039 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
14040 delta_bytes
, dy
, dvpos
);
14043 /* Give up if cursor was not found. */
14044 if (w
->cursor
.vpos
< 0)
14046 clear_glyph_matrix (w
->desired_matrix
);
14051 /* Don't let the cursor end in the scroll margins. */
14053 int this_scroll_margin
, cursor_height
;
14055 this_scroll_margin
= max (0, scroll_margin
);
14056 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14057 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14058 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
14060 if ((w
->cursor
.y
< this_scroll_margin
14061 && CHARPOS (start
) > BEGV
)
14062 /* Old redisplay didn't take scroll margin into account at the bottom,
14063 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14064 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14065 ? cursor_height
+ this_scroll_margin
14066 : 1)) > it
.last_visible_y
)
14068 w
->cursor
.vpos
= -1;
14069 clear_glyph_matrix (w
->desired_matrix
);
14074 /* Scroll the display. Do it before changing the current matrix so
14075 that xterm.c doesn't get confused about where the cursor glyph is
14077 if (dy
&& run
.height
)
14081 if (FRAME_WINDOW_P (f
))
14083 rif
->update_window_begin_hook (w
);
14084 rif
->clear_window_mouse_face (w
);
14085 rif
->scroll_run_hook (w
, &run
);
14086 rif
->update_window_end_hook (w
, 0, 0);
14090 /* Terminal frame. In this case, dvpos gives the number of
14091 lines to scroll by; dvpos < 0 means scroll up. */
14092 int first_unchanged_at_end_vpos
14093 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14094 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14095 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14096 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14097 + window_internal_height (w
));
14099 /* Perform the operation on the screen. */
14102 /* Scroll last_unchanged_at_beg_row to the end of the
14103 window down dvpos lines. */
14104 set_terminal_window (end
);
14106 /* On dumb terminals delete dvpos lines at the end
14107 before inserting dvpos empty lines. */
14108 if (!scroll_region_ok
)
14109 ins_del_lines (end
- dvpos
, -dvpos
);
14111 /* Insert dvpos empty lines in front of
14112 last_unchanged_at_beg_row. */
14113 ins_del_lines (from
, dvpos
);
14115 else if (dvpos
< 0)
14117 /* Scroll up last_unchanged_at_beg_vpos to the end of
14118 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14119 set_terminal_window (end
);
14121 /* Delete dvpos lines in front of
14122 last_unchanged_at_beg_vpos. ins_del_lines will set
14123 the cursor to the given vpos and emit |dvpos| delete
14125 ins_del_lines (from
+ dvpos
, dvpos
);
14127 /* On a dumb terminal insert dvpos empty lines at the
14129 if (!scroll_region_ok
)
14130 ins_del_lines (end
+ dvpos
, -dvpos
);
14133 set_terminal_window (0);
14139 /* Shift reused rows of the current matrix to the right position.
14140 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14142 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14143 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14146 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14147 bottom_vpos
, dvpos
);
14148 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14151 else if (dvpos
> 0)
14153 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14154 bottom_vpos
, dvpos
);
14155 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14156 first_unchanged_at_end_vpos
+ dvpos
, 0);
14159 /* For frame-based redisplay, make sure that current frame and window
14160 matrix are in sync with respect to glyph memory. */
14161 if (!FRAME_WINDOW_P (f
))
14162 sync_frame_with_window_matrix_rows (w
);
14164 /* Adjust buffer positions in reused rows. */
14166 increment_matrix_positions (current_matrix
,
14167 first_unchanged_at_end_vpos
+ dvpos
,
14168 bottom_vpos
, delta
, delta_bytes
);
14170 /* Adjust Y positions. */
14172 shift_glyph_matrix (w
, current_matrix
,
14173 first_unchanged_at_end_vpos
+ dvpos
,
14176 if (first_unchanged_at_end_row
)
14178 first_unchanged_at_end_row
+= dvpos
;
14179 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14180 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14181 first_unchanged_at_end_row
= NULL
;
14184 /* If scrolling up, there may be some lines to display at the end of
14186 last_text_row_at_end
= NULL
;
14189 /* Scrolling up can leave for example a partially visible line
14190 at the end of the window to be redisplayed. */
14191 /* Set last_row to the glyph row in the current matrix where the
14192 window end line is found. It has been moved up or down in
14193 the matrix by dvpos. */
14194 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14195 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14197 /* If last_row is the window end line, it should display text. */
14198 xassert (last_row
->displays_text_p
);
14200 /* If window end line was partially visible before, begin
14201 displaying at that line. Otherwise begin displaying with the
14202 line following it. */
14203 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14205 init_to_row_start (&it
, w
, last_row
);
14206 it
.vpos
= last_vpos
;
14207 it
.current_y
= last_row
->y
;
14211 init_to_row_end (&it
, w
, last_row
);
14212 it
.vpos
= 1 + last_vpos
;
14213 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14217 /* We may start in a continuation line. If so, we have to
14218 get the right continuation_lines_width and current_x. */
14219 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14220 it
.hpos
= it
.current_x
= 0;
14222 /* Display the rest of the lines at the window end. */
14223 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14224 while (it
.current_y
< it
.last_visible_y
14225 && !fonts_changed_p
)
14227 /* Is it always sure that the display agrees with lines in
14228 the current matrix? I don't think so, so we mark rows
14229 displayed invalid in the current matrix by setting their
14230 enabled_p flag to zero. */
14231 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14232 if (display_line (&it
))
14233 last_text_row_at_end
= it
.glyph_row
- 1;
14237 /* Update window_end_pos and window_end_vpos. */
14238 if (first_unchanged_at_end_row
14239 && !last_text_row_at_end
)
14241 /* Window end line if one of the preserved rows from the current
14242 matrix. Set row to the last row displaying text in current
14243 matrix starting at first_unchanged_at_end_row, after
14245 xassert (first_unchanged_at_end_row
->displays_text_p
);
14246 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14247 first_unchanged_at_end_row
);
14248 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14250 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14251 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14253 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14254 xassert (w
->window_end_bytepos
>= 0);
14255 IF_DEBUG (debug_method_add (w
, "A"));
14257 else if (last_text_row_at_end
)
14260 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14261 w
->window_end_bytepos
14262 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14264 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14265 xassert (w
->window_end_bytepos
>= 0);
14266 IF_DEBUG (debug_method_add (w
, "B"));
14268 else if (last_text_row
)
14270 /* We have displayed either to the end of the window or at the
14271 end of the window, i.e. the last row with text is to be found
14272 in the desired matrix. */
14274 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14275 w
->window_end_bytepos
14276 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14278 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14279 xassert (w
->window_end_bytepos
>= 0);
14281 else if (first_unchanged_at_end_row
== NULL
14282 && last_text_row
== NULL
14283 && last_text_row_at_end
== NULL
)
14285 /* Displayed to end of window, but no line containing text was
14286 displayed. Lines were deleted at the end of the window. */
14287 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14288 int vpos
= XFASTINT (w
->window_end_vpos
);
14289 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14290 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14293 row
== NULL
&& vpos
>= first_vpos
;
14294 --vpos
, --current_row
, --desired_row
)
14296 if (desired_row
->enabled_p
)
14298 if (desired_row
->displays_text_p
)
14301 else if (current_row
->displays_text_p
)
14305 xassert (row
!= NULL
);
14306 w
->window_end_vpos
= make_number (vpos
+ 1);
14307 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14308 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14309 xassert (w
->window_end_bytepos
>= 0);
14310 IF_DEBUG (debug_method_add (w
, "C"));
14315 #if 0 /* This leads to problems, for instance when the cursor is
14316 at ZV, and the cursor line displays no text. */
14317 /* Disable rows below what's displayed in the window. This makes
14318 debugging easier. */
14319 enable_glyph_matrix_rows (current_matrix
,
14320 XFASTINT (w
->window_end_vpos
) + 1,
14324 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14325 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14327 /* Record that display has not been completed. */
14328 w
->window_end_valid
= Qnil
;
14329 w
->desired_matrix
->no_scrolling_p
= 1;
14337 /***********************************************************************
14338 More debugging support
14339 ***********************************************************************/
14343 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14344 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14345 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14348 /* Dump the contents of glyph matrix MATRIX on stderr.
14350 GLYPHS 0 means don't show glyph contents.
14351 GLYPHS 1 means show glyphs in short form
14352 GLYPHS > 1 means show glyphs in long form. */
14355 dump_glyph_matrix (matrix
, glyphs
)
14356 struct glyph_matrix
*matrix
;
14360 for (i
= 0; i
< matrix
->nrows
; ++i
)
14361 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14365 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14366 the glyph row and area where the glyph comes from. */
14369 dump_glyph (row
, glyph
, area
)
14370 struct glyph_row
*row
;
14371 struct glyph
*glyph
;
14374 if (glyph
->type
== CHAR_GLYPH
)
14377 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14378 glyph
- row
->glyphs
[TEXT_AREA
],
14381 (BUFFERP (glyph
->object
)
14383 : (STRINGP (glyph
->object
)
14386 glyph
->pixel_width
,
14388 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14392 glyph
->left_box_line_p
,
14393 glyph
->right_box_line_p
);
14395 else if (glyph
->type
== STRETCH_GLYPH
)
14398 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14399 glyph
- row
->glyphs
[TEXT_AREA
],
14402 (BUFFERP (glyph
->object
)
14404 : (STRINGP (glyph
->object
)
14407 glyph
->pixel_width
,
14411 glyph
->left_box_line_p
,
14412 glyph
->right_box_line_p
);
14414 else if (glyph
->type
== IMAGE_GLYPH
)
14417 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14418 glyph
- row
->glyphs
[TEXT_AREA
],
14421 (BUFFERP (glyph
->object
)
14423 : (STRINGP (glyph
->object
)
14426 glyph
->pixel_width
,
14430 glyph
->left_box_line_p
,
14431 glyph
->right_box_line_p
);
14436 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14437 GLYPHS 0 means don't show glyph contents.
14438 GLYPHS 1 means show glyphs in short form
14439 GLYPHS > 1 means show glyphs in long form. */
14442 dump_glyph_row (row
, vpos
, glyphs
)
14443 struct glyph_row
*row
;
14448 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14449 fprintf (stderr
, "======================================================================\n");
14451 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14452 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14454 MATRIX_ROW_START_CHARPOS (row
),
14455 MATRIX_ROW_END_CHARPOS (row
),
14456 row
->used
[TEXT_AREA
],
14457 row
->contains_overlapping_glyphs_p
,
14459 row
->truncated_on_left_p
,
14460 row
->truncated_on_right_p
,
14462 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14463 row
->displays_text_p
,
14466 row
->ends_in_middle_of_char_p
,
14467 row
->starts_in_middle_of_char_p
,
14473 row
->visible_height
,
14476 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14477 row
->end
.overlay_string_index
,
14478 row
->continuation_lines_width
);
14479 fprintf (stderr
, "%9d %5d\n",
14480 CHARPOS (row
->start
.string_pos
),
14481 CHARPOS (row
->end
.string_pos
));
14482 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14483 row
->end
.dpvec_index
);
14490 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14492 struct glyph
*glyph
= row
->glyphs
[area
];
14493 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14495 /* Glyph for a line end in text. */
14496 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14499 if (glyph
< glyph_end
)
14500 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14502 for (; glyph
< glyph_end
; ++glyph
)
14503 dump_glyph (row
, glyph
, area
);
14506 else if (glyphs
== 1)
14510 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14512 char *s
= (char *) alloca (row
->used
[area
] + 1);
14515 for (i
= 0; i
< row
->used
[area
]; ++i
)
14517 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14518 if (glyph
->type
== CHAR_GLYPH
14519 && glyph
->u
.ch
< 0x80
14520 && glyph
->u
.ch
>= ' ')
14521 s
[i
] = glyph
->u
.ch
;
14527 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14533 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14534 Sdump_glyph_matrix
, 0, 1, "p",
14535 doc
: /* Dump the current matrix of the selected window to stderr.
14536 Shows contents of glyph row structures. With non-nil
14537 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14538 glyphs in short form, otherwise show glyphs in long form. */)
14540 Lisp_Object glyphs
;
14542 struct window
*w
= XWINDOW (selected_window
);
14543 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14545 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14546 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14547 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14548 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14549 fprintf (stderr
, "=============================================\n");
14550 dump_glyph_matrix (w
->current_matrix
,
14551 NILP (glyphs
) ? 0 : XINT (glyphs
));
14556 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14557 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14560 struct frame
*f
= XFRAME (selected_frame
);
14561 dump_glyph_matrix (f
->current_matrix
, 1);
14566 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14567 doc
: /* Dump glyph row ROW to stderr.
14568 GLYPH 0 means don't dump glyphs.
14569 GLYPH 1 means dump glyphs in short form.
14570 GLYPH > 1 or omitted means dump glyphs in long form. */)
14572 Lisp_Object row
, glyphs
;
14574 struct glyph_matrix
*matrix
;
14577 CHECK_NUMBER (row
);
14578 matrix
= XWINDOW (selected_window
)->current_matrix
;
14580 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14581 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14583 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14588 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14589 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14590 GLYPH 0 means don't dump glyphs.
14591 GLYPH 1 means dump glyphs in short form.
14592 GLYPH > 1 or omitted means dump glyphs in long form. */)
14594 Lisp_Object row
, glyphs
;
14596 struct frame
*sf
= SELECTED_FRAME ();
14597 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14600 CHECK_NUMBER (row
);
14602 if (vpos
>= 0 && vpos
< m
->nrows
)
14603 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14604 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14609 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14610 doc
: /* Toggle tracing of redisplay.
14611 With ARG, turn tracing on if and only if ARG is positive. */)
14616 trace_redisplay_p
= !trace_redisplay_p
;
14619 arg
= Fprefix_numeric_value (arg
);
14620 trace_redisplay_p
= XINT (arg
) > 0;
14627 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14628 doc
: /* Like `format', but print result to stderr.
14629 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14634 Lisp_Object s
= Fformat (nargs
, args
);
14635 fprintf (stderr
, "%s", SDATA (s
));
14639 #endif /* GLYPH_DEBUG */
14643 /***********************************************************************
14644 Building Desired Matrix Rows
14645 ***********************************************************************/
14647 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14648 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14650 static struct glyph_row
*
14651 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14653 Lisp_Object overlay_arrow_string
;
14655 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14656 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14657 struct buffer
*old
= current_buffer
;
14658 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14659 int arrow_len
= SCHARS (overlay_arrow_string
);
14660 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14661 const unsigned char *p
;
14664 int n_glyphs_before
;
14666 set_buffer_temp (buffer
);
14667 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14668 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14669 SET_TEXT_POS (it
.position
, 0, 0);
14671 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14673 while (p
< arrow_end
)
14675 Lisp_Object face
, ilisp
;
14677 /* Get the next character. */
14679 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14681 it
.c
= *p
, it
.len
= 1;
14684 /* Get its face. */
14685 ilisp
= make_number (p
- arrow_string
);
14686 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14687 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14689 /* Compute its width, get its glyphs. */
14690 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14691 SET_TEXT_POS (it
.position
, -1, -1);
14692 PRODUCE_GLYPHS (&it
);
14694 /* If this character doesn't fit any more in the line, we have
14695 to remove some glyphs. */
14696 if (it
.current_x
> it
.last_visible_x
)
14698 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14703 set_buffer_temp (old
);
14704 return it
.glyph_row
;
14708 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14709 glyphs are only inserted for terminal frames since we can't really
14710 win with truncation glyphs when partially visible glyphs are
14711 involved. Which glyphs to insert is determined by
14712 produce_special_glyphs. */
14715 insert_left_trunc_glyphs (it
)
14718 struct it truncate_it
;
14719 struct glyph
*from
, *end
, *to
, *toend
;
14721 xassert (!FRAME_WINDOW_P (it
->f
));
14723 /* Get the truncation glyphs. */
14725 truncate_it
.current_x
= 0;
14726 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14727 truncate_it
.glyph_row
= &scratch_glyph_row
;
14728 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14729 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14730 truncate_it
.object
= make_number (0);
14731 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14733 /* Overwrite glyphs from IT with truncation glyphs. */
14734 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14735 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14736 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14737 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14742 /* There may be padding glyphs left over. Overwrite them too. */
14743 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14745 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14751 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14755 /* Compute the pixel height and width of IT->glyph_row.
14757 Most of the time, ascent and height of a display line will be equal
14758 to the max_ascent and max_height values of the display iterator
14759 structure. This is not the case if
14761 1. We hit ZV without displaying anything. In this case, max_ascent
14762 and max_height will be zero.
14764 2. We have some glyphs that don't contribute to the line height.
14765 (The glyph row flag contributes_to_line_height_p is for future
14766 pixmap extensions).
14768 The first case is easily covered by using default values because in
14769 these cases, the line height does not really matter, except that it
14770 must not be zero. */
14773 compute_line_metrics (it
)
14776 struct glyph_row
*row
= it
->glyph_row
;
14779 if (FRAME_WINDOW_P (it
->f
))
14781 int i
, min_y
, max_y
;
14783 /* The line may consist of one space only, that was added to
14784 place the cursor on it. If so, the row's height hasn't been
14786 if (row
->height
== 0)
14788 if (it
->max_ascent
+ it
->max_descent
== 0)
14789 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14790 row
->ascent
= it
->max_ascent
;
14791 row
->height
= it
->max_ascent
+ it
->max_descent
;
14792 row
->phys_ascent
= it
->max_phys_ascent
;
14793 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14794 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14797 /* Compute the width of this line. */
14798 row
->pixel_width
= row
->x
;
14799 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14800 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14802 xassert (row
->pixel_width
>= 0);
14803 xassert (row
->ascent
>= 0 && row
->height
> 0);
14805 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14806 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14808 /* If first line's physical ascent is larger than its logical
14809 ascent, use the physical ascent, and make the row taller.
14810 This makes accented characters fully visible. */
14811 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14812 && row
->phys_ascent
> row
->ascent
)
14814 row
->height
+= row
->phys_ascent
- row
->ascent
;
14815 row
->ascent
= row
->phys_ascent
;
14818 /* Compute how much of the line is visible. */
14819 row
->visible_height
= row
->height
;
14821 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14822 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14824 if (row
->y
< min_y
)
14825 row
->visible_height
-= min_y
- row
->y
;
14826 if (row
->y
+ row
->height
> max_y
)
14827 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14831 row
->pixel_width
= row
->used
[TEXT_AREA
];
14832 if (row
->continued_p
)
14833 row
->pixel_width
-= it
->continuation_pixel_width
;
14834 else if (row
->truncated_on_right_p
)
14835 row
->pixel_width
-= it
->truncation_pixel_width
;
14836 row
->ascent
= row
->phys_ascent
= 0;
14837 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14838 row
->extra_line_spacing
= 0;
14841 /* Compute a hash code for this row. */
14843 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14844 for (i
= 0; i
< row
->used
[area
]; ++i
)
14845 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14846 + row
->glyphs
[area
][i
].u
.val
14847 + row
->glyphs
[area
][i
].face_id
14848 + row
->glyphs
[area
][i
].padding_p
14849 + (row
->glyphs
[area
][i
].type
<< 2));
14851 it
->max_ascent
= it
->max_descent
= 0;
14852 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14856 /* Append one space to the glyph row of iterator IT if doing a
14857 window-based redisplay. The space has the same face as
14858 IT->face_id. Value is non-zero if a space was added.
14860 This function is called to make sure that there is always one glyph
14861 at the end of a glyph row that the cursor can be set on under
14862 window-systems. (If there weren't such a glyph we would not know
14863 how wide and tall a box cursor should be displayed).
14865 At the same time this space let's a nicely handle clearing to the
14866 end of the line if the row ends in italic text. */
14869 append_space_for_newline (it
, default_face_p
)
14871 int default_face_p
;
14873 if (FRAME_WINDOW_P (it
->f
))
14875 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14877 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14878 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14880 /* Save some values that must not be changed.
14881 Must save IT->c and IT->len because otherwise
14882 ITERATOR_AT_END_P wouldn't work anymore after
14883 append_space_for_newline has been called. */
14884 enum display_element_type saved_what
= it
->what
;
14885 int saved_c
= it
->c
, saved_len
= it
->len
;
14886 int saved_x
= it
->current_x
;
14887 int saved_face_id
= it
->face_id
;
14888 struct text_pos saved_pos
;
14889 Lisp_Object saved_object
;
14892 saved_object
= it
->object
;
14893 saved_pos
= it
->position
;
14895 it
->what
= IT_CHARACTER
;
14896 bzero (&it
->position
, sizeof it
->position
);
14897 it
->object
= make_number (0);
14901 if (default_face_p
)
14902 it
->face_id
= DEFAULT_FACE_ID
;
14903 else if (it
->face_before_selective_p
)
14904 it
->face_id
= it
->saved_face_id
;
14905 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14906 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14908 PRODUCE_GLYPHS (it
);
14910 it
->override_ascent
= -1;
14911 it
->constrain_row_ascent_descent_p
= 0;
14912 it
->current_x
= saved_x
;
14913 it
->object
= saved_object
;
14914 it
->position
= saved_pos
;
14915 it
->what
= saved_what
;
14916 it
->face_id
= saved_face_id
;
14917 it
->len
= saved_len
;
14927 /* Extend the face of the last glyph in the text area of IT->glyph_row
14928 to the end of the display line. Called from display_line.
14929 If the glyph row is empty, add a space glyph to it so that we
14930 know the face to draw. Set the glyph row flag fill_line_p. */
14933 extend_face_to_end_of_line (it
)
14937 struct frame
*f
= it
->f
;
14939 /* If line is already filled, do nothing. */
14940 if (it
->current_x
>= it
->last_visible_x
)
14943 /* Face extension extends the background and box of IT->face_id
14944 to the end of the line. If the background equals the background
14945 of the frame, we don't have to do anything. */
14946 if (it
->face_before_selective_p
)
14947 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14949 face
= FACE_FROM_ID (f
, it
->face_id
);
14951 if (FRAME_WINDOW_P (f
)
14952 && face
->box
== FACE_NO_BOX
14953 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14957 /* Set the glyph row flag indicating that the face of the last glyph
14958 in the text area has to be drawn to the end of the text area. */
14959 it
->glyph_row
->fill_line_p
= 1;
14961 /* If current character of IT is not ASCII, make sure we have the
14962 ASCII face. This will be automatically undone the next time
14963 get_next_display_element returns a multibyte character. Note
14964 that the character will always be single byte in unibyte text. */
14965 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14967 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14970 if (FRAME_WINDOW_P (f
))
14972 /* If the row is empty, add a space with the current face of IT,
14973 so that we know which face to draw. */
14974 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14976 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14977 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14978 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14983 /* Save some values that must not be changed. */
14984 int saved_x
= it
->current_x
;
14985 struct text_pos saved_pos
;
14986 Lisp_Object saved_object
;
14987 enum display_element_type saved_what
= it
->what
;
14988 int saved_face_id
= it
->face_id
;
14990 saved_object
= it
->object
;
14991 saved_pos
= it
->position
;
14993 it
->what
= IT_CHARACTER
;
14994 bzero (&it
->position
, sizeof it
->position
);
14995 it
->object
= make_number (0);
14998 it
->face_id
= face
->id
;
15000 PRODUCE_GLYPHS (it
);
15002 while (it
->current_x
<= it
->last_visible_x
)
15003 PRODUCE_GLYPHS (it
);
15005 /* Don't count these blanks really. It would let us insert a left
15006 truncation glyph below and make us set the cursor on them, maybe. */
15007 it
->current_x
= saved_x
;
15008 it
->object
= saved_object
;
15009 it
->position
= saved_pos
;
15010 it
->what
= saved_what
;
15011 it
->face_id
= saved_face_id
;
15016 /* Value is non-zero if text starting at CHARPOS in current_buffer is
15017 trailing whitespace. */
15020 trailing_whitespace_p (charpos
)
15023 int bytepos
= CHAR_TO_BYTE (charpos
);
15026 while (bytepos
< ZV_BYTE
15027 && (c
= FETCH_CHAR (bytepos
),
15028 c
== ' ' || c
== '\t'))
15031 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
15033 if (bytepos
!= PT_BYTE
)
15040 /* Highlight trailing whitespace, if any, in ROW. */
15043 highlight_trailing_whitespace (f
, row
)
15045 struct glyph_row
*row
;
15047 int used
= row
->used
[TEXT_AREA
];
15051 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
15052 struct glyph
*glyph
= start
+ used
- 1;
15054 /* Skip over glyphs inserted to display the cursor at the
15055 end of a line, for extending the face of the last glyph
15056 to the end of the line on terminals, and for truncation
15057 and continuation glyphs. */
15058 while (glyph
>= start
15059 && glyph
->type
== CHAR_GLYPH
15060 && INTEGERP (glyph
->object
))
15063 /* If last glyph is a space or stretch, and it's trailing
15064 whitespace, set the face of all trailing whitespace glyphs in
15065 IT->glyph_row to `trailing-whitespace'. */
15067 && BUFFERP (glyph
->object
)
15068 && (glyph
->type
== STRETCH_GLYPH
15069 || (glyph
->type
== CHAR_GLYPH
15070 && glyph
->u
.ch
== ' '))
15071 && trailing_whitespace_p (glyph
->charpos
))
15073 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15077 while (glyph
>= start
15078 && BUFFERP (glyph
->object
)
15079 && (glyph
->type
== STRETCH_GLYPH
15080 || (glyph
->type
== CHAR_GLYPH
15081 && glyph
->u
.ch
== ' ')))
15082 (glyph
--)->face_id
= face_id
;
15088 /* Value is non-zero if glyph row ROW in window W should be
15089 used to hold the cursor. */
15092 cursor_row_p (w
, row
)
15094 struct glyph_row
*row
;
15096 int cursor_row_p
= 1;
15098 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15100 /* If the row ends with a newline from a string, we don't want
15101 the cursor there, but we still want it at the start of the
15102 string if the string starts in this row.
15103 If the row is continued it doesn't end in a newline. */
15104 if (CHARPOS (row
->end
.string_pos
) >= 0)
15105 cursor_row_p
= (row
->continued_p
15106 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15107 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15109 /* If the row ends in middle of a real character,
15110 and the line is continued, we want the cursor here.
15111 That's because MATRIX_ROW_END_CHARPOS would equal
15112 PT if PT is before the character. */
15113 if (!row
->ends_in_ellipsis_p
)
15114 cursor_row_p
= row
->continued_p
;
15116 /* If the row ends in an ellipsis, then
15117 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15118 We want that position to be displayed after the ellipsis. */
15121 /* If the row ends at ZV, display the cursor at the end of that
15122 row instead of at the start of the row below. */
15123 else if (row
->ends_at_zv_p
)
15129 return cursor_row_p
;
15133 /* Construct the glyph row IT->glyph_row in the desired matrix of
15134 IT->w from text at the current position of IT. See dispextern.h
15135 for an overview of struct it. Value is non-zero if
15136 IT->glyph_row displays text, as opposed to a line displaying ZV
15143 struct glyph_row
*row
= it
->glyph_row
;
15144 Lisp_Object overlay_arrow_string
;
15146 /* We always start displaying at hpos zero even if hscrolled. */
15147 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15149 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15150 >= it
->w
->desired_matrix
->nrows
)
15152 it
->w
->nrows_scale_factor
++;
15153 fonts_changed_p
= 1;
15157 /* Is IT->w showing the region? */
15158 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15160 /* Clear the result glyph row and enable it. */
15161 prepare_desired_row (row
);
15163 row
->y
= it
->current_y
;
15164 row
->start
= it
->start
;
15165 row
->continuation_lines_width
= it
->continuation_lines_width
;
15166 row
->displays_text_p
= 1;
15167 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15168 it
->starts_in_middle_of_char_p
= 0;
15170 /* Arrange the overlays nicely for our purposes. Usually, we call
15171 display_line on only one line at a time, in which case this
15172 can't really hurt too much, or we call it on lines which appear
15173 one after another in the buffer, in which case all calls to
15174 recenter_overlay_lists but the first will be pretty cheap. */
15175 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15177 /* Move over display elements that are not visible because we are
15178 hscrolled. This may stop at an x-position < IT->first_visible_x
15179 if the first glyph is partially visible or if we hit a line end. */
15180 if (it
->current_x
< it
->first_visible_x
)
15182 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15183 MOVE_TO_POS
| MOVE_TO_X
);
15186 /* Get the initial row height. This is either the height of the
15187 text hscrolled, if there is any, or zero. */
15188 row
->ascent
= it
->max_ascent
;
15189 row
->height
= it
->max_ascent
+ it
->max_descent
;
15190 row
->phys_ascent
= it
->max_phys_ascent
;
15191 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15192 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15194 /* Loop generating characters. The loop is left with IT on the next
15195 character to display. */
15198 int n_glyphs_before
, hpos_before
, x_before
;
15200 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15202 /* Retrieve the next thing to display. Value is zero if end of
15204 if (!get_next_display_element (it
))
15206 /* Maybe add a space at the end of this line that is used to
15207 display the cursor there under X. Set the charpos of the
15208 first glyph of blank lines not corresponding to any text
15210 #ifdef HAVE_WINDOW_SYSTEM
15211 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15212 row
->exact_window_width_line_p
= 1;
15214 #endif /* HAVE_WINDOW_SYSTEM */
15215 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15216 || row
->used
[TEXT_AREA
] == 0)
15218 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15219 row
->displays_text_p
= 0;
15221 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15222 && (!MINI_WINDOW_P (it
->w
)
15223 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15224 row
->indicate_empty_line_p
= 1;
15227 it
->continuation_lines_width
= 0;
15228 row
->ends_at_zv_p
= 1;
15232 /* Now, get the metrics of what we want to display. This also
15233 generates glyphs in `row' (which is IT->glyph_row). */
15234 n_glyphs_before
= row
->used
[TEXT_AREA
];
15237 /* Remember the line height so far in case the next element doesn't
15238 fit on the line. */
15239 if (!it
->truncate_lines_p
)
15241 ascent
= it
->max_ascent
;
15242 descent
= it
->max_descent
;
15243 phys_ascent
= it
->max_phys_ascent
;
15244 phys_descent
= it
->max_phys_descent
;
15247 PRODUCE_GLYPHS (it
);
15249 /* If this display element was in marginal areas, continue with
15251 if (it
->area
!= TEXT_AREA
)
15253 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15254 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15255 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15256 row
->phys_height
= max (row
->phys_height
,
15257 it
->max_phys_ascent
+ it
->max_phys_descent
);
15258 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15259 it
->max_extra_line_spacing
);
15260 set_iterator_to_next (it
, 1);
15264 /* Does the display element fit on the line? If we truncate
15265 lines, we should draw past the right edge of the window. If
15266 we don't truncate, we want to stop so that we can display the
15267 continuation glyph before the right margin. If lines are
15268 continued, there are two possible strategies for characters
15269 resulting in more than 1 glyph (e.g. tabs): Display as many
15270 glyphs as possible in this line and leave the rest for the
15271 continuation line, or display the whole element in the next
15272 line. Original redisplay did the former, so we do it also. */
15273 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15274 hpos_before
= it
->hpos
;
15277 if (/* Not a newline. */
15279 /* Glyphs produced fit entirely in the line. */
15280 && it
->current_x
< it
->last_visible_x
)
15282 it
->hpos
+= nglyphs
;
15283 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15284 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15285 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15286 row
->phys_height
= max (row
->phys_height
,
15287 it
->max_phys_ascent
+ it
->max_phys_descent
);
15288 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15289 it
->max_extra_line_spacing
);
15290 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15291 row
->x
= x
- it
->first_visible_x
;
15296 struct glyph
*glyph
;
15298 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15300 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15301 new_x
= x
+ glyph
->pixel_width
;
15303 if (/* Lines are continued. */
15304 !it
->truncate_lines_p
15305 && (/* Glyph doesn't fit on the line. */
15306 new_x
> it
->last_visible_x
15307 /* Or it fits exactly on a window system frame. */
15308 || (new_x
== it
->last_visible_x
15309 && FRAME_WINDOW_P (it
->f
))))
15311 /* End of a continued line. */
15314 || (new_x
== it
->last_visible_x
15315 && FRAME_WINDOW_P (it
->f
)))
15317 /* Current glyph is the only one on the line or
15318 fits exactly on the line. We must continue
15319 the line because we can't draw the cursor
15320 after the glyph. */
15321 row
->continued_p
= 1;
15322 it
->current_x
= new_x
;
15323 it
->continuation_lines_width
+= new_x
;
15325 if (i
== nglyphs
- 1)
15327 set_iterator_to_next (it
, 1);
15328 #ifdef HAVE_WINDOW_SYSTEM
15329 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15331 if (!get_next_display_element (it
))
15333 row
->exact_window_width_line_p
= 1;
15334 it
->continuation_lines_width
= 0;
15335 row
->continued_p
= 0;
15336 row
->ends_at_zv_p
= 1;
15338 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15340 row
->continued_p
= 0;
15341 row
->exact_window_width_line_p
= 1;
15344 #endif /* HAVE_WINDOW_SYSTEM */
15347 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15348 && !FRAME_WINDOW_P (it
->f
))
15350 /* A padding glyph that doesn't fit on this line.
15351 This means the whole character doesn't fit
15353 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15355 /* Fill the rest of the row with continuation
15356 glyphs like in 20.x. */
15357 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15358 < row
->glyphs
[1 + TEXT_AREA
])
15359 produce_special_glyphs (it
, IT_CONTINUATION
);
15361 row
->continued_p
= 1;
15362 it
->current_x
= x_before
;
15363 it
->continuation_lines_width
+= x_before
;
15365 /* Restore the height to what it was before the
15366 element not fitting on the line. */
15367 it
->max_ascent
= ascent
;
15368 it
->max_descent
= descent
;
15369 it
->max_phys_ascent
= phys_ascent
;
15370 it
->max_phys_descent
= phys_descent
;
15372 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15374 /* A TAB that extends past the right edge of the
15375 window. This produces a single glyph on
15376 window system frames. We leave the glyph in
15377 this row and let it fill the row, but don't
15378 consume the TAB. */
15379 it
->continuation_lines_width
+= it
->last_visible_x
;
15380 row
->ends_in_middle_of_char_p
= 1;
15381 row
->continued_p
= 1;
15382 glyph
->pixel_width
= it
->last_visible_x
- x
;
15383 it
->starts_in_middle_of_char_p
= 1;
15387 /* Something other than a TAB that draws past
15388 the right edge of the window. Restore
15389 positions to values before the element. */
15390 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15392 /* Display continuation glyphs. */
15393 if (!FRAME_WINDOW_P (it
->f
))
15394 produce_special_glyphs (it
, IT_CONTINUATION
);
15395 row
->continued_p
= 1;
15397 it
->continuation_lines_width
+= x
;
15399 if (nglyphs
> 1 && i
> 0)
15401 row
->ends_in_middle_of_char_p
= 1;
15402 it
->starts_in_middle_of_char_p
= 1;
15405 /* Restore the height to what it was before the
15406 element not fitting on the line. */
15407 it
->max_ascent
= ascent
;
15408 it
->max_descent
= descent
;
15409 it
->max_phys_ascent
= phys_ascent
;
15410 it
->max_phys_descent
= phys_descent
;
15415 else if (new_x
> it
->first_visible_x
)
15417 /* Increment number of glyphs actually displayed. */
15420 if (x
< it
->first_visible_x
)
15421 /* Glyph is partially visible, i.e. row starts at
15422 negative X position. */
15423 row
->x
= x
- it
->first_visible_x
;
15427 /* Glyph is completely off the left margin of the
15428 window. This should not happen because of the
15429 move_it_in_display_line at the start of this
15430 function, unless the text display area of the
15431 window is empty. */
15432 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15436 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15437 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15438 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15439 row
->phys_height
= max (row
->phys_height
,
15440 it
->max_phys_ascent
+ it
->max_phys_descent
);
15441 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15442 it
->max_extra_line_spacing
);
15444 /* End of this display line if row is continued. */
15445 if (row
->continued_p
|| row
->ends_at_zv_p
)
15450 /* Is this a line end? If yes, we're also done, after making
15451 sure that a non-default face is extended up to the right
15452 margin of the window. */
15453 if (ITERATOR_AT_END_OF_LINE_P (it
))
15455 int used_before
= row
->used
[TEXT_AREA
];
15457 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15459 #ifdef HAVE_WINDOW_SYSTEM
15460 /* Add a space at the end of the line that is used to
15461 display the cursor there. */
15462 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15463 append_space_for_newline (it
, 0);
15464 #endif /* HAVE_WINDOW_SYSTEM */
15466 /* Extend the face to the end of the line. */
15467 extend_face_to_end_of_line (it
);
15469 /* Make sure we have the position. */
15470 if (used_before
== 0)
15471 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15473 /* Consume the line end. This skips over invisible lines. */
15474 set_iterator_to_next (it
, 1);
15475 it
->continuation_lines_width
= 0;
15479 /* Proceed with next display element. Note that this skips
15480 over lines invisible because of selective display. */
15481 set_iterator_to_next (it
, 1);
15483 /* If we truncate lines, we are done when the last displayed
15484 glyphs reach past the right margin of the window. */
15485 if (it
->truncate_lines_p
15486 && (FRAME_WINDOW_P (it
->f
)
15487 ? (it
->current_x
>= it
->last_visible_x
)
15488 : (it
->current_x
> it
->last_visible_x
)))
15490 /* Maybe add truncation glyphs. */
15491 if (!FRAME_WINDOW_P (it
->f
))
15495 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15496 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15499 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15501 row
->used
[TEXT_AREA
] = i
;
15502 produce_special_glyphs (it
, IT_TRUNCATION
);
15505 #ifdef HAVE_WINDOW_SYSTEM
15508 /* Don't truncate if we can overflow newline into fringe. */
15509 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15511 if (!get_next_display_element (it
))
15513 it
->continuation_lines_width
= 0;
15514 row
->ends_at_zv_p
= 1;
15515 row
->exact_window_width_line_p
= 1;
15518 if (ITERATOR_AT_END_OF_LINE_P (it
))
15520 row
->exact_window_width_line_p
= 1;
15521 goto at_end_of_line
;
15525 #endif /* HAVE_WINDOW_SYSTEM */
15527 row
->truncated_on_right_p
= 1;
15528 it
->continuation_lines_width
= 0;
15529 reseat_at_next_visible_line_start (it
, 0);
15530 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15531 it
->hpos
= hpos_before
;
15532 it
->current_x
= x_before
;
15537 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15538 at the left window margin. */
15539 if (it
->first_visible_x
15540 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15542 if (!FRAME_WINDOW_P (it
->f
))
15543 insert_left_trunc_glyphs (it
);
15544 row
->truncated_on_left_p
= 1;
15547 /* If the start of this line is the overlay arrow-position, then
15548 mark this glyph row as the one containing the overlay arrow.
15549 This is clearly a mess with variable size fonts. It would be
15550 better to let it be displayed like cursors under X. */
15551 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15552 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15553 !NILP (overlay_arrow_string
)))
15555 /* Overlay arrow in window redisplay is a fringe bitmap. */
15556 if (STRINGP (overlay_arrow_string
))
15558 struct glyph_row
*arrow_row
15559 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15560 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15561 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15562 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15563 struct glyph
*p2
, *end
;
15565 /* Copy the arrow glyphs. */
15566 while (glyph
< arrow_end
)
15569 /* Throw away padding glyphs. */
15571 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15572 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15578 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15583 xassert (INTEGERP (overlay_arrow_string
));
15584 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15586 overlay_arrow_seen
= 1;
15589 /* Compute pixel dimensions of this line. */
15590 compute_line_metrics (it
);
15592 /* Remember the position at which this line ends. */
15593 row
->end
= it
->current
;
15595 /* Record whether this row ends inside an ellipsis. */
15596 row
->ends_in_ellipsis_p
15597 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15598 && it
->ellipsis_p
);
15600 /* Save fringe bitmaps in this row. */
15601 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15602 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15603 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15604 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15606 it
->left_user_fringe_bitmap
= 0;
15607 it
->left_user_fringe_face_id
= 0;
15608 it
->right_user_fringe_bitmap
= 0;
15609 it
->right_user_fringe_face_id
= 0;
15611 /* Maybe set the cursor. */
15612 if (it
->w
->cursor
.vpos
< 0
15613 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15614 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15615 && cursor_row_p (it
->w
, row
))
15616 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15618 /* Highlight trailing whitespace. */
15619 if (!NILP (Vshow_trailing_whitespace
))
15620 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15622 /* Prepare for the next line. This line starts horizontally at (X
15623 HPOS) = (0 0). Vertical positions are incremented. As a
15624 convenience for the caller, IT->glyph_row is set to the next
15626 it
->current_x
= it
->hpos
= 0;
15627 it
->current_y
+= row
->height
;
15630 it
->start
= it
->current
;
15631 return row
->displays_text_p
;
15636 /***********************************************************************
15638 ***********************************************************************/
15640 /* Redisplay the menu bar in the frame for window W.
15642 The menu bar of X frames that don't have X toolkit support is
15643 displayed in a special window W->frame->menu_bar_window.
15645 The menu bar of terminal frames is treated specially as far as
15646 glyph matrices are concerned. Menu bar lines are not part of
15647 windows, so the update is done directly on the frame matrix rows
15648 for the menu bar. */
15651 display_menu_bar (w
)
15654 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15659 /* Don't do all this for graphical frames. */
15661 if (!NILP (Vwindow_system
))
15664 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15669 if (FRAME_MAC_P (f
))
15673 #ifdef USE_X_TOOLKIT
15674 xassert (!FRAME_WINDOW_P (f
));
15675 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15676 it
.first_visible_x
= 0;
15677 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15678 #else /* not USE_X_TOOLKIT */
15679 if (FRAME_WINDOW_P (f
))
15681 /* Menu bar lines are displayed in the desired matrix of the
15682 dummy window menu_bar_window. */
15683 struct window
*menu_w
;
15684 xassert (WINDOWP (f
->menu_bar_window
));
15685 menu_w
= XWINDOW (f
->menu_bar_window
);
15686 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15688 it
.first_visible_x
= 0;
15689 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15693 /* This is a TTY frame, i.e. character hpos/vpos are used as
15695 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15697 it
.first_visible_x
= 0;
15698 it
.last_visible_x
= FRAME_COLS (f
);
15700 #endif /* not USE_X_TOOLKIT */
15702 if (! mode_line_inverse_video
)
15703 /* Force the menu-bar to be displayed in the default face. */
15704 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15706 /* Clear all rows of the menu bar. */
15707 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15709 struct glyph_row
*row
= it
.glyph_row
+ i
;
15710 clear_glyph_row (row
);
15711 row
->enabled_p
= 1;
15712 row
->full_width_p
= 1;
15715 /* Display all items of the menu bar. */
15716 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15717 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15719 Lisp_Object string
;
15721 /* Stop at nil string. */
15722 string
= AREF (items
, i
+ 1);
15726 /* Remember where item was displayed. */
15727 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15729 /* Display the item, pad with one space. */
15730 if (it
.current_x
< it
.last_visible_x
)
15731 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15732 SCHARS (string
) + 1, 0, 0, -1);
15735 /* Fill out the line with spaces. */
15736 if (it
.current_x
< it
.last_visible_x
)
15737 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15739 /* Compute the total height of the lines. */
15740 compute_line_metrics (&it
);
15745 /***********************************************************************
15747 ***********************************************************************/
15749 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15750 FORCE is non-zero, redisplay mode lines unconditionally.
15751 Otherwise, redisplay only mode lines that are garbaged. Value is
15752 the number of windows whose mode lines were redisplayed. */
15755 redisplay_mode_lines (window
, force
)
15756 Lisp_Object window
;
15761 while (!NILP (window
))
15763 struct window
*w
= XWINDOW (window
);
15765 if (WINDOWP (w
->hchild
))
15766 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15767 else if (WINDOWP (w
->vchild
))
15768 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15770 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15771 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15773 struct text_pos lpoint
;
15774 struct buffer
*old
= current_buffer
;
15776 /* Set the window's buffer for the mode line display. */
15777 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15778 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15780 /* Point refers normally to the selected window. For any
15781 other window, set up appropriate value. */
15782 if (!EQ (window
, selected_window
))
15784 struct text_pos pt
;
15786 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15787 if (CHARPOS (pt
) < BEGV
)
15788 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15789 else if (CHARPOS (pt
) > (ZV
- 1))
15790 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15792 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15795 /* Display mode lines. */
15796 clear_glyph_matrix (w
->desired_matrix
);
15797 if (display_mode_lines (w
))
15800 w
->must_be_updated_p
= 1;
15803 /* Restore old settings. */
15804 set_buffer_internal_1 (old
);
15805 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15815 /* Display the mode and/or top line of window W. Value is the number
15816 of mode lines displayed. */
15819 display_mode_lines (w
)
15822 Lisp_Object old_selected_window
, old_selected_frame
;
15825 old_selected_frame
= selected_frame
;
15826 selected_frame
= w
->frame
;
15827 old_selected_window
= selected_window
;
15828 XSETWINDOW (selected_window
, w
);
15830 /* These will be set while the mode line specs are processed. */
15831 line_number_displayed
= 0;
15832 w
->column_number_displayed
= Qnil
;
15834 if (WINDOW_WANTS_MODELINE_P (w
))
15836 struct window
*sel_w
= XWINDOW (old_selected_window
);
15838 /* Select mode line face based on the real selected window. */
15839 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15840 current_buffer
->mode_line_format
);
15844 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15846 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15847 current_buffer
->header_line_format
);
15851 selected_frame
= old_selected_frame
;
15852 selected_window
= old_selected_window
;
15857 /* Display mode or top line of window W. FACE_ID specifies which line
15858 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15859 FORMAT is the mode line format to display. Value is the pixel
15860 height of the mode line displayed. */
15863 display_mode_line (w
, face_id
, format
)
15865 enum face_id face_id
;
15866 Lisp_Object format
;
15870 int count
= SPECPDL_INDEX ();
15872 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15873 prepare_desired_row (it
.glyph_row
);
15875 it
.glyph_row
->mode_line_p
= 1;
15877 if (! mode_line_inverse_video
)
15878 /* Force the mode-line to be displayed in the default face. */
15879 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15881 record_unwind_protect (unwind_format_mode_line
,
15882 format_mode_line_unwind_data (NULL
));
15884 mode_line_target
= MODE_LINE_DISPLAY
;
15886 /* Temporarily make frame's keyboard the current kboard so that
15887 kboard-local variables in the mode_line_format will get the right
15889 push_frame_kboard (it
.f
);
15890 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15891 pop_frame_kboard ();
15893 unbind_to (count
, Qnil
);
15895 /* Fill up with spaces. */
15896 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15898 compute_line_metrics (&it
);
15899 it
.glyph_row
->full_width_p
= 1;
15900 it
.glyph_row
->continued_p
= 0;
15901 it
.glyph_row
->truncated_on_left_p
= 0;
15902 it
.glyph_row
->truncated_on_right_p
= 0;
15904 /* Make a 3D mode-line have a shadow at its right end. */
15905 face
= FACE_FROM_ID (it
.f
, face_id
);
15906 extend_face_to_end_of_line (&it
);
15907 if (face
->box
!= FACE_NO_BOX
)
15909 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15910 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15911 last
->right_box_line_p
= 1;
15914 return it
.glyph_row
->height
;
15917 /* Contribute ELT to the mode line for window IT->w. How it
15918 translates into text depends on its data type.
15920 IT describes the display environment in which we display, as usual.
15922 DEPTH is the depth in recursion. It is used to prevent
15923 infinite recursion here.
15925 FIELD_WIDTH is the number of characters the display of ELT should
15926 occupy in the mode line, and PRECISION is the maximum number of
15927 characters to display from ELT's representation. See
15928 display_string for details.
15930 Returns the hpos of the end of the text generated by ELT.
15932 PROPS is a property list to add to any string we encounter.
15934 If RISKY is nonzero, remove (disregard) any properties in any string
15935 we encounter, and ignore :eval and :propertize.
15937 The global variable `mode_line_target' determines whether the
15938 output is passed to `store_mode_line_noprop',
15939 `store_mode_line_string', or `display_string'. */
15942 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15945 int field_width
, precision
;
15946 Lisp_Object elt
, props
;
15949 int n
= 0, field
, prec
;
15954 elt
= build_string ("*too-deep*");
15958 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15962 /* A string: output it and check for %-constructs within it. */
15966 if (!NILP (props
) || risky
)
15968 Lisp_Object oprops
, aelt
;
15969 oprops
= Ftext_properties_at (make_number (0), elt
);
15971 /* If the starting string's properties are not what
15972 we want, translate the string. Also, if the string
15973 is risky, do that anyway. */
15975 if (NILP (Fequal (props
, oprops
)) || risky
)
15977 /* If the starting string has properties,
15978 merge the specified ones onto the existing ones. */
15979 if (! NILP (oprops
) && !risky
)
15983 oprops
= Fcopy_sequence (oprops
);
15985 while (CONSP (tem
))
15987 oprops
= Fplist_put (oprops
, XCAR (tem
),
15988 XCAR (XCDR (tem
)));
15989 tem
= XCDR (XCDR (tem
));
15994 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15995 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15997 mode_line_proptrans_alist
15998 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
16005 elt
= Fcopy_sequence (elt
);
16006 Fset_text_properties (make_number (0), Flength (elt
),
16008 /* Add this item to mode_line_proptrans_alist. */
16009 mode_line_proptrans_alist
16010 = Fcons (Fcons (elt
, props
),
16011 mode_line_proptrans_alist
);
16012 /* Truncate mode_line_proptrans_alist
16013 to at most 50 elements. */
16014 tem
= Fnthcdr (make_number (50),
16015 mode_line_proptrans_alist
);
16017 XSETCDR (tem
, Qnil
);
16026 prec
= precision
- n
;
16027 switch (mode_line_target
)
16029 case MODE_LINE_NOPROP
:
16030 case MODE_LINE_TITLE
:
16031 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
16033 case MODE_LINE_STRING
:
16034 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
16036 case MODE_LINE_DISPLAY
:
16037 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
16038 0, prec
, 0, STRING_MULTIBYTE (elt
));
16045 /* Handle the non-literal case. */
16047 while ((precision
<= 0 || n
< precision
)
16048 && SREF (elt
, offset
) != 0
16049 && (mode_line_target
!= MODE_LINE_DISPLAY
16050 || it
->current_x
< it
->last_visible_x
))
16052 int last_offset
= offset
;
16054 /* Advance to end of string or next format specifier. */
16055 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
16058 if (offset
- 1 != last_offset
)
16060 int nchars
, nbytes
;
16062 /* Output to end of string or up to '%'. Field width
16063 is length of string. Don't output more than
16064 PRECISION allows us. */
16067 prec
= c_string_width (SDATA (elt
) + last_offset
,
16068 offset
- last_offset
, precision
- n
,
16071 switch (mode_line_target
)
16073 case MODE_LINE_NOPROP
:
16074 case MODE_LINE_TITLE
:
16075 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
16077 case MODE_LINE_STRING
:
16079 int bytepos
= last_offset
;
16080 int charpos
= string_byte_to_char (elt
, bytepos
);
16081 int endpos
= (precision
<= 0
16082 ? string_byte_to_char (elt
, offset
)
16083 : charpos
+ nchars
);
16085 n
+= store_mode_line_string (NULL
,
16086 Fsubstring (elt
, make_number (charpos
),
16087 make_number (endpos
)),
16091 case MODE_LINE_DISPLAY
:
16093 int bytepos
= last_offset
;
16094 int charpos
= string_byte_to_char (elt
, bytepos
);
16095 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16097 STRING_MULTIBYTE (elt
));
16102 else /* c == '%' */
16104 int percent_position
= offset
;
16106 /* Get the specified minimum width. Zero means
16109 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
16110 field
= field
* 10 + c
- '0';
16112 /* Don't pad beyond the total padding allowed. */
16113 if (field_width
- n
> 0 && field
> field_width
- n
)
16114 field
= field_width
- n
;
16116 /* Note that either PRECISION <= 0 or N < PRECISION. */
16117 prec
= precision
- n
;
16120 n
+= display_mode_element (it
, depth
, field
, prec
,
16121 Vglobal_mode_string
, props
,
16126 int bytepos
, charpos
;
16127 unsigned char *spec
;
16129 bytepos
= percent_position
;
16130 charpos
= (STRING_MULTIBYTE (elt
)
16131 ? string_byte_to_char (elt
, bytepos
)
16135 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16137 switch (mode_line_target
)
16139 case MODE_LINE_NOPROP
:
16140 case MODE_LINE_TITLE
:
16141 n
+= store_mode_line_noprop (spec
, field
, prec
);
16143 case MODE_LINE_STRING
:
16145 int len
= strlen (spec
);
16146 Lisp_Object tem
= make_string (spec
, len
);
16147 props
= Ftext_properties_at (make_number (charpos
), elt
);
16148 /* Should only keep face property in props */
16149 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16152 case MODE_LINE_DISPLAY
:
16154 int nglyphs_before
, nwritten
;
16156 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16157 nwritten
= display_string (spec
, Qnil
, elt
,
16162 /* Assign to the glyphs written above the
16163 string where the `%x' came from, position
16167 struct glyph
*glyph
16168 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16172 for (i
= 0; i
< nwritten
; ++i
)
16174 glyph
[i
].object
= elt
;
16175 glyph
[i
].charpos
= charpos
;
16192 /* A symbol: process the value of the symbol recursively
16193 as if it appeared here directly. Avoid error if symbol void.
16194 Special case: if value of symbol is a string, output the string
16197 register Lisp_Object tem
;
16199 /* If the variable is not marked as risky to set
16200 then its contents are risky to use. */
16201 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16204 tem
= Fboundp (elt
);
16207 tem
= Fsymbol_value (elt
);
16208 /* If value is a string, output that string literally:
16209 don't check for % within it. */
16213 if (!EQ (tem
, elt
))
16215 /* Give up right away for nil or t. */
16225 register Lisp_Object car
, tem
;
16227 /* A cons cell: five distinct cases.
16228 If first element is :eval or :propertize, do something special.
16229 If first element is a string or a cons, process all the elements
16230 and effectively concatenate them.
16231 If first element is a negative number, truncate displaying cdr to
16232 at most that many characters. If positive, pad (with spaces)
16233 to at least that many characters.
16234 If first element is a symbol, process the cadr or caddr recursively
16235 according to whether the symbol's value is non-nil or nil. */
16237 if (EQ (car
, QCeval
))
16239 /* An element of the form (:eval FORM) means evaluate FORM
16240 and use the result as mode line elements. */
16245 if (CONSP (XCDR (elt
)))
16248 spec
= safe_eval (XCAR (XCDR (elt
)));
16249 n
+= display_mode_element (it
, depth
, field_width
- n
,
16250 precision
- n
, spec
, props
,
16254 else if (EQ (car
, QCpropertize
))
16256 /* An element of the form (:propertize ELT PROPS...)
16257 means display ELT but applying properties PROPS. */
16262 if (CONSP (XCDR (elt
)))
16263 n
+= display_mode_element (it
, depth
, field_width
- n
,
16264 precision
- n
, XCAR (XCDR (elt
)),
16265 XCDR (XCDR (elt
)), risky
);
16267 else if (SYMBOLP (car
))
16269 tem
= Fboundp (car
);
16273 /* elt is now the cdr, and we know it is a cons cell.
16274 Use its car if CAR has a non-nil value. */
16277 tem
= Fsymbol_value (car
);
16284 /* Symbol's value is nil (or symbol is unbound)
16285 Get the cddr of the original list
16286 and if possible find the caddr and use that. */
16290 else if (!CONSP (elt
))
16295 else if (INTEGERP (car
))
16297 register int lim
= XINT (car
);
16301 /* Negative int means reduce maximum width. */
16302 if (precision
<= 0)
16305 precision
= min (precision
, -lim
);
16309 /* Padding specified. Don't let it be more than
16310 current maximum. */
16312 lim
= min (precision
, lim
);
16314 /* If that's more padding than already wanted, queue it.
16315 But don't reduce padding already specified even if
16316 that is beyond the current truncation point. */
16317 field_width
= max (lim
, field_width
);
16321 else if (STRINGP (car
) || CONSP (car
))
16323 register int limit
= 50;
16324 /* Limit is to protect against circular lists. */
16327 && (precision
<= 0 || n
< precision
))
16329 n
+= display_mode_element (it
, depth
,
16330 /* Do padding only after the last
16331 element in the list. */
16332 (! CONSP (XCDR (elt
))
16335 precision
- n
, XCAR (elt
),
16345 elt
= build_string ("*invalid*");
16349 /* Pad to FIELD_WIDTH. */
16350 if (field_width
> 0 && n
< field_width
)
16352 switch (mode_line_target
)
16354 case MODE_LINE_NOPROP
:
16355 case MODE_LINE_TITLE
:
16356 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16358 case MODE_LINE_STRING
:
16359 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16361 case MODE_LINE_DISPLAY
:
16362 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16371 /* Store a mode-line string element in mode_line_string_list.
16373 If STRING is non-null, display that C string. Otherwise, the Lisp
16374 string LISP_STRING is displayed.
16376 FIELD_WIDTH is the minimum number of output glyphs to produce.
16377 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16378 with spaces. FIELD_WIDTH <= 0 means don't pad.
16380 PRECISION is the maximum number of characters to output from
16381 STRING. PRECISION <= 0 means don't truncate the string.
16383 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16384 properties to the string.
16386 PROPS are the properties to add to the string.
16387 The mode_line_string_face face property is always added to the string.
16391 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16393 Lisp_Object lisp_string
;
16402 if (string
!= NULL
)
16404 len
= strlen (string
);
16405 if (precision
> 0 && len
> precision
)
16407 lisp_string
= make_string (string
, len
);
16409 props
= mode_line_string_face_prop
;
16410 else if (!NILP (mode_line_string_face
))
16412 Lisp_Object face
= Fplist_get (props
, Qface
);
16413 props
= Fcopy_sequence (props
);
16415 face
= mode_line_string_face
;
16417 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16418 props
= Fplist_put (props
, Qface
, face
);
16420 Fadd_text_properties (make_number (0), make_number (len
),
16421 props
, lisp_string
);
16425 len
= XFASTINT (Flength (lisp_string
));
16426 if (precision
> 0 && len
> precision
)
16429 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16432 if (!NILP (mode_line_string_face
))
16436 props
= Ftext_properties_at (make_number (0), lisp_string
);
16437 face
= Fplist_get (props
, Qface
);
16439 face
= mode_line_string_face
;
16441 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16442 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16444 lisp_string
= Fcopy_sequence (lisp_string
);
16447 Fadd_text_properties (make_number (0), make_number (len
),
16448 props
, lisp_string
);
16453 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16457 if (field_width
> len
)
16459 field_width
-= len
;
16460 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16462 Fadd_text_properties (make_number (0), make_number (field_width
),
16463 props
, lisp_string
);
16464 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16472 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16474 doc
: /* Format a string out of a mode line format specification.
16475 First arg FORMAT specifies the mode line format (see `mode-line-format'
16476 for details) to use.
16478 Optional second arg FACE specifies the face property to put
16479 on all characters for which no face is specified.
16480 t means whatever face the window's mode line currently uses
16481 \(either `mode-line' or `mode-line-inactive', depending).
16482 nil means the default is no face property.
16483 If FACE is an integer, the value string has no text properties.
16485 Optional third and fourth args WINDOW and BUFFER specify the window
16486 and buffer to use as the context for the formatting (defaults
16487 are the selected window and the window's buffer). */)
16488 (format
, face
, window
, buffer
)
16489 Lisp_Object format
, face
, window
, buffer
;
16494 struct buffer
*old_buffer
= NULL
;
16496 int no_props
= INTEGERP (face
);
16497 int count
= SPECPDL_INDEX ();
16499 int string_start
= 0;
16502 window
= selected_window
;
16503 CHECK_WINDOW (window
);
16504 w
= XWINDOW (window
);
16507 buffer
= w
->buffer
;
16508 CHECK_BUFFER (buffer
);
16511 return build_string ("");
16519 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16520 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16524 face_id
= DEFAULT_FACE_ID
;
16526 if (XBUFFER (buffer
) != current_buffer
)
16527 old_buffer
= current_buffer
;
16529 record_unwind_protect (unwind_format_mode_line
,
16530 format_mode_line_unwind_data (old_buffer
));
16533 set_buffer_internal_1 (XBUFFER (buffer
));
16535 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16539 mode_line_target
= MODE_LINE_NOPROP
;
16540 mode_line_string_face_prop
= Qnil
;
16541 mode_line_string_list
= Qnil
;
16542 string_start
= MODE_LINE_NOPROP_LEN (0);
16546 mode_line_target
= MODE_LINE_STRING
;
16547 mode_line_string_list
= Qnil
;
16548 mode_line_string_face
= face
;
16549 mode_line_string_face_prop
16550 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16553 push_frame_kboard (it
.f
);
16554 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16555 pop_frame_kboard ();
16559 len
= MODE_LINE_NOPROP_LEN (string_start
);
16560 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16564 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16565 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16566 make_string ("", 0));
16569 unbind_to (count
, Qnil
);
16573 /* Write a null-terminated, right justified decimal representation of
16574 the positive integer D to BUF using a minimal field width WIDTH. */
16577 pint2str (buf
, width
, d
)
16578 register char *buf
;
16579 register int width
;
16582 register char *p
= buf
;
16590 *p
++ = d
% 10 + '0';
16595 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16606 /* Write a null-terminated, right justified decimal and "human
16607 readable" representation of the nonnegative integer D to BUF using
16608 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16610 static const char power_letter
[] =
16624 pint2hrstr (buf
, width
, d
)
16629 /* We aim to represent the nonnegative integer D as
16630 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16633 /* -1 means: do not use TENTHS. */
16637 /* Length of QUOTIENT.TENTHS as a string. */
16643 if (1000 <= quotient
)
16645 /* Scale to the appropriate EXPONENT. */
16648 remainder
= quotient
% 1000;
16652 while (1000 <= quotient
);
16654 /* Round to nearest and decide whether to use TENTHS or not. */
16657 tenths
= remainder
/ 100;
16658 if (50 <= remainder
% 100)
16665 if (quotient
== 10)
16673 if (500 <= remainder
)
16675 if (quotient
< 999)
16686 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16687 if (tenths
== -1 && quotient
<= 99)
16694 p
= psuffix
= buf
+ max (width
, length
);
16696 /* Print EXPONENT. */
16698 *psuffix
++ = power_letter
[exponent
];
16701 /* Print TENTHS. */
16704 *--p
= '0' + tenths
;
16708 /* Print QUOTIENT. */
16711 int digit
= quotient
% 10;
16712 *--p
= '0' + digit
;
16714 while ((quotient
/= 10) != 0);
16716 /* Print leading spaces. */
16721 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16722 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16723 type of CODING_SYSTEM. Return updated pointer into BUF. */
16725 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16728 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16729 Lisp_Object coding_system
;
16730 register char *buf
;
16734 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16735 const unsigned char *eol_str
;
16737 /* The EOL conversion we are using. */
16738 Lisp_Object eoltype
;
16740 val
= Fget (coding_system
, Qcoding_system
);
16743 if (!VECTORP (val
)) /* Not yet decided. */
16748 eoltype
= eol_mnemonic_undecided
;
16749 /* Don't mention EOL conversion if it isn't decided. */
16753 Lisp_Object eolvalue
;
16755 eolvalue
= Fget (coding_system
, Qeol_type
);
16758 *buf
++ = XFASTINT (AREF (val
, 1));
16762 /* The EOL conversion that is normal on this system. */
16764 if (NILP (eolvalue
)) /* Not yet decided. */
16765 eoltype
= eol_mnemonic_undecided
;
16766 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16767 eoltype
= eol_mnemonic_undecided
;
16768 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16769 eoltype
= (XFASTINT (eolvalue
) == 0
16770 ? eol_mnemonic_unix
16771 : (XFASTINT (eolvalue
) == 1
16772 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16778 /* Mention the EOL conversion if it is not the usual one. */
16779 if (STRINGP (eoltype
))
16781 eol_str
= SDATA (eoltype
);
16782 eol_str_len
= SBYTES (eoltype
);
16784 else if (INTEGERP (eoltype
)
16785 && CHAR_VALID_P (XINT (eoltype
), 0))
16787 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16788 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16793 eol_str
= invalid_eol_type
;
16794 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16796 bcopy (eol_str
, buf
, eol_str_len
);
16797 buf
+= eol_str_len
;
16803 /* Return a string for the output of a mode line %-spec for window W,
16804 generated by character C. PRECISION >= 0 means don't return a
16805 string longer than that value. FIELD_WIDTH > 0 means pad the
16806 string returned with spaces to that value. Return 1 in *MULTIBYTE
16807 if the result is multibyte text.
16809 Note we operate on the current buffer for most purposes,
16810 the exception being w->base_line_pos. */
16812 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16815 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16818 int field_width
, precision
;
16822 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16823 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16824 struct buffer
*b
= current_buffer
;
16832 if (!NILP (b
->read_only
))
16834 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16839 /* This differs from %* only for a modified read-only buffer. */
16840 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16842 if (!NILP (b
->read_only
))
16847 /* This differs from %* in ignoring read-only-ness. */
16848 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16860 if (command_loop_level
> 5)
16862 p
= decode_mode_spec_buf
;
16863 for (i
= 0; i
< command_loop_level
; i
++)
16866 return decode_mode_spec_buf
;
16874 if (command_loop_level
> 5)
16876 p
= decode_mode_spec_buf
;
16877 for (i
= 0; i
< command_loop_level
; i
++)
16880 return decode_mode_spec_buf
;
16887 /* Let lots_of_dashes be a string of infinite length. */
16888 if (mode_line_target
== MODE_LINE_NOPROP
||
16889 mode_line_target
== MODE_LINE_STRING
)
16891 if (field_width
<= 0
16892 || field_width
> sizeof (lots_of_dashes
))
16894 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16895 decode_mode_spec_buf
[i
] = '-';
16896 decode_mode_spec_buf
[i
] = '\0';
16897 return decode_mode_spec_buf
;
16900 return lots_of_dashes
;
16909 int col
= (int) current_column (); /* iftc */
16910 w
->column_number_displayed
= make_number (col
);
16911 pint2str (decode_mode_spec_buf
, field_width
, col
);
16912 return decode_mode_spec_buf
;
16916 /* %F displays the frame name. */
16917 if (!NILP (f
->title
))
16918 return (char *) SDATA (f
->title
);
16919 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16920 return (char *) SDATA (f
->name
);
16929 int size
= ZV
- BEGV
;
16930 pint2str (decode_mode_spec_buf
, field_width
, size
);
16931 return decode_mode_spec_buf
;
16936 int size
= ZV
- BEGV
;
16937 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16938 return decode_mode_spec_buf
;
16943 int startpos
= XMARKER (w
->start
)->charpos
;
16944 int startpos_byte
= marker_byte_position (w
->start
);
16945 int line
, linepos
, linepos_byte
, topline
;
16947 int height
= WINDOW_TOTAL_LINES (w
);
16949 /* If we decided that this buffer isn't suitable for line numbers,
16950 don't forget that too fast. */
16951 if (EQ (w
->base_line_pos
, w
->buffer
))
16953 /* But do forget it, if the window shows a different buffer now. */
16954 else if (BUFFERP (w
->base_line_pos
))
16955 w
->base_line_pos
= Qnil
;
16957 /* If the buffer is very big, don't waste time. */
16958 if (INTEGERP (Vline_number_display_limit
)
16959 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16961 w
->base_line_pos
= Qnil
;
16962 w
->base_line_number
= Qnil
;
16966 if (!NILP (w
->base_line_number
)
16967 && !NILP (w
->base_line_pos
)
16968 && XFASTINT (w
->base_line_pos
) <= startpos
)
16970 line
= XFASTINT (w
->base_line_number
);
16971 linepos
= XFASTINT (w
->base_line_pos
);
16972 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16977 linepos
= BUF_BEGV (b
);
16978 linepos_byte
= BUF_BEGV_BYTE (b
);
16981 /* Count lines from base line to window start position. */
16982 nlines
= display_count_lines (linepos
, linepos_byte
,
16986 topline
= nlines
+ line
;
16988 /* Determine a new base line, if the old one is too close
16989 or too far away, or if we did not have one.
16990 "Too close" means it's plausible a scroll-down would
16991 go back past it. */
16992 if (startpos
== BUF_BEGV (b
))
16994 w
->base_line_number
= make_number (topline
);
16995 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16997 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16998 || linepos
== BUF_BEGV (b
))
17000 int limit
= BUF_BEGV (b
);
17001 int limit_byte
= BUF_BEGV_BYTE (b
);
17003 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
17005 if (startpos
- distance
> limit
)
17007 limit
= startpos
- distance
;
17008 limit_byte
= CHAR_TO_BYTE (limit
);
17011 nlines
= display_count_lines (startpos
, startpos_byte
,
17013 - (height
* 2 + 30),
17015 /* If we couldn't find the lines we wanted within
17016 line_number_display_limit_width chars per line,
17017 give up on line numbers for this window. */
17018 if (position
== limit_byte
&& limit
== startpos
- distance
)
17020 w
->base_line_pos
= w
->buffer
;
17021 w
->base_line_number
= Qnil
;
17025 w
->base_line_number
= make_number (topline
- nlines
);
17026 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
17029 /* Now count lines from the start pos to point. */
17030 nlines
= display_count_lines (startpos
, startpos_byte
,
17031 PT_BYTE
, PT
, &junk
);
17033 /* Record that we did display the line number. */
17034 line_number_displayed
= 1;
17036 /* Make the string to show. */
17037 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
17038 return decode_mode_spec_buf
;
17041 char* p
= decode_mode_spec_buf
;
17042 int pad
= field_width
- 2;
17048 return decode_mode_spec_buf
;
17054 obj
= b
->mode_name
;
17058 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17064 int pos
= marker_position (w
->start
);
17065 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17067 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17069 if (pos
<= BUF_BEGV (b
))
17074 else if (pos
<= BUF_BEGV (b
))
17078 if (total
> 1000000)
17079 /* Do it differently for a large value, to avoid overflow. */
17080 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17082 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17083 /* We can't normally display a 3-digit number,
17084 so get us a 2-digit number that is close. */
17087 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17088 return decode_mode_spec_buf
;
17092 /* Display percentage of size above the bottom of the screen. */
17095 int toppos
= marker_position (w
->start
);
17096 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17097 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17099 if (botpos
>= BUF_ZV (b
))
17101 if (toppos
<= BUF_BEGV (b
))
17108 if (total
> 1000000)
17109 /* Do it differently for a large value, to avoid overflow. */
17110 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17112 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17113 /* We can't normally display a 3-digit number,
17114 so get us a 2-digit number that is close. */
17117 if (toppos
<= BUF_BEGV (b
))
17118 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17120 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17121 return decode_mode_spec_buf
;
17126 /* status of process */
17127 obj
= Fget_buffer_process (Fcurrent_buffer ());
17129 return "no process";
17130 #ifdef subprocesses
17131 obj
= Fsymbol_name (Fprocess_status (obj
));
17135 case 't': /* indicate TEXT or BINARY */
17136 #ifdef MODE_LINE_BINARY_TEXT
17137 return MODE_LINE_BINARY_TEXT (b
);
17143 /* coding-system (not including end-of-line format) */
17145 /* coding-system (including end-of-line type) */
17147 int eol_flag
= (c
== 'Z');
17148 char *p
= decode_mode_spec_buf
;
17150 if (! FRAME_WINDOW_P (f
))
17152 /* No need to mention EOL here--the terminal never needs
17153 to do EOL conversion. */
17154 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17155 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17157 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17160 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17161 #ifdef subprocesses
17162 obj
= Fget_buffer_process (Fcurrent_buffer ());
17163 if (PROCESSP (obj
))
17165 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17167 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17170 #endif /* subprocesses */
17173 return decode_mode_spec_buf
;
17179 *multibyte
= STRING_MULTIBYTE (obj
);
17180 return (char *) SDATA (obj
);
17187 /* Count up to COUNT lines starting from START / START_BYTE.
17188 But don't go beyond LIMIT_BYTE.
17189 Return the number of lines thus found (always nonnegative).
17191 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17194 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17195 int start
, start_byte
, limit_byte
, count
;
17198 register unsigned char *cursor
;
17199 unsigned char *base
;
17201 register int ceiling
;
17202 register unsigned char *ceiling_addr
;
17203 int orig_count
= count
;
17205 /* If we are not in selective display mode,
17206 check only for newlines. */
17207 int selective_display
= (!NILP (current_buffer
->selective_display
)
17208 && !INTEGERP (current_buffer
->selective_display
));
17212 while (start_byte
< limit_byte
)
17214 ceiling
= BUFFER_CEILING_OF (start_byte
);
17215 ceiling
= min (limit_byte
- 1, ceiling
);
17216 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17217 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17220 if (selective_display
)
17221 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17224 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17227 if (cursor
!= ceiling_addr
)
17231 start_byte
+= cursor
- base
+ 1;
17232 *byte_pos_ptr
= start_byte
;
17236 if (++cursor
== ceiling_addr
)
17242 start_byte
+= cursor
- base
;
17247 while (start_byte
> limit_byte
)
17249 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17250 ceiling
= max (limit_byte
, ceiling
);
17251 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17252 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17255 if (selective_display
)
17256 while (--cursor
!= ceiling_addr
17257 && *cursor
!= '\n' && *cursor
!= 015)
17260 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17263 if (cursor
!= ceiling_addr
)
17267 start_byte
+= cursor
- base
+ 1;
17268 *byte_pos_ptr
= start_byte
;
17269 /* When scanning backwards, we should
17270 not count the newline posterior to which we stop. */
17271 return - orig_count
- 1;
17277 /* Here we add 1 to compensate for the last decrement
17278 of CURSOR, which took it past the valid range. */
17279 start_byte
+= cursor
- base
+ 1;
17283 *byte_pos_ptr
= limit_byte
;
17286 return - orig_count
+ count
;
17287 return orig_count
- count
;
17293 /***********************************************************************
17295 ***********************************************************************/
17297 /* Display a NUL-terminated string, starting with index START.
17299 If STRING is non-null, display that C string. Otherwise, the Lisp
17300 string LISP_STRING is displayed.
17302 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17303 FACE_STRING. Display STRING or LISP_STRING with the face at
17304 FACE_STRING_POS in FACE_STRING:
17306 Display the string in the environment given by IT, but use the
17307 standard display table, temporarily.
17309 FIELD_WIDTH is the minimum number of output glyphs to produce.
17310 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17311 with spaces. If STRING has more characters, more than FIELD_WIDTH
17312 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17314 PRECISION is the maximum number of characters to output from
17315 STRING. PRECISION < 0 means don't truncate the string.
17317 This is roughly equivalent to printf format specifiers:
17319 FIELD_WIDTH PRECISION PRINTF
17320 ----------------------------------------
17326 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17327 display them, and < 0 means obey the current buffer's value of
17328 enable_multibyte_characters.
17330 Value is the number of glyphs produced. */
17333 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17334 start
, it
, field_width
, precision
, max_x
, multibyte
)
17335 unsigned char *string
;
17336 Lisp_Object lisp_string
;
17337 Lisp_Object face_string
;
17338 int face_string_pos
;
17341 int field_width
, precision
, max_x
;
17344 int hpos_at_start
= it
->hpos
;
17345 int saved_face_id
= it
->face_id
;
17346 struct glyph_row
*row
= it
->glyph_row
;
17348 /* Initialize the iterator IT for iteration over STRING beginning
17349 with index START. */
17350 reseat_to_string (it
, string
, lisp_string
, start
,
17351 precision
, field_width
, multibyte
);
17353 /* If displaying STRING, set up the face of the iterator
17354 from LISP_STRING, if that's given. */
17355 if (STRINGP (face_string
))
17361 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17362 0, it
->region_beg_charpos
,
17363 it
->region_end_charpos
,
17364 &endptr
, it
->base_face_id
, 0);
17365 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17366 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17369 /* Set max_x to the maximum allowed X position. Don't let it go
17370 beyond the right edge of the window. */
17372 max_x
= it
->last_visible_x
;
17374 max_x
= min (max_x
, it
->last_visible_x
);
17376 /* Skip over display elements that are not visible. because IT->w is
17378 if (it
->current_x
< it
->first_visible_x
)
17379 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17380 MOVE_TO_POS
| MOVE_TO_X
);
17382 row
->ascent
= it
->max_ascent
;
17383 row
->height
= it
->max_ascent
+ it
->max_descent
;
17384 row
->phys_ascent
= it
->max_phys_ascent
;
17385 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17386 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17388 /* This condition is for the case that we are called with current_x
17389 past last_visible_x. */
17390 while (it
->current_x
< max_x
)
17392 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17394 /* Get the next display element. */
17395 if (!get_next_display_element (it
))
17398 /* Produce glyphs. */
17399 x_before
= it
->current_x
;
17400 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17401 PRODUCE_GLYPHS (it
);
17403 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17406 while (i
< nglyphs
)
17408 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17410 if (!it
->truncate_lines_p
17411 && x
+ glyph
->pixel_width
> max_x
)
17413 /* End of continued line or max_x reached. */
17414 if (CHAR_GLYPH_PADDING_P (*glyph
))
17416 /* A wide character is unbreakable. */
17417 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17418 it
->current_x
= x_before
;
17422 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17427 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17429 /* Glyph is at least partially visible. */
17431 if (x
< it
->first_visible_x
)
17432 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17436 /* Glyph is off the left margin of the display area.
17437 Should not happen. */
17441 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17442 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17443 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17444 row
->phys_height
= max (row
->phys_height
,
17445 it
->max_phys_ascent
+ it
->max_phys_descent
);
17446 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17447 it
->max_extra_line_spacing
);
17448 x
+= glyph
->pixel_width
;
17452 /* Stop if max_x reached. */
17456 /* Stop at line ends. */
17457 if (ITERATOR_AT_END_OF_LINE_P (it
))
17459 it
->continuation_lines_width
= 0;
17463 set_iterator_to_next (it
, 1);
17465 /* Stop if truncating at the right edge. */
17466 if (it
->truncate_lines_p
17467 && it
->current_x
>= it
->last_visible_x
)
17469 /* Add truncation mark, but don't do it if the line is
17470 truncated at a padding space. */
17471 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17473 if (!FRAME_WINDOW_P (it
->f
))
17477 if (it
->current_x
> it
->last_visible_x
)
17479 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17480 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17482 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17484 row
->used
[TEXT_AREA
] = i
;
17485 produce_special_glyphs (it
, IT_TRUNCATION
);
17488 produce_special_glyphs (it
, IT_TRUNCATION
);
17490 it
->glyph_row
->truncated_on_right_p
= 1;
17496 /* Maybe insert a truncation at the left. */
17497 if (it
->first_visible_x
17498 && IT_CHARPOS (*it
) > 0)
17500 if (!FRAME_WINDOW_P (it
->f
))
17501 insert_left_trunc_glyphs (it
);
17502 it
->glyph_row
->truncated_on_left_p
= 1;
17505 it
->face_id
= saved_face_id
;
17507 /* Value is number of columns displayed. */
17508 return it
->hpos
- hpos_at_start
;
17513 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17514 appears as an element of LIST or as the car of an element of LIST.
17515 If PROPVAL is a list, compare each element against LIST in that
17516 way, and return 1/2 if any element of PROPVAL is found in LIST.
17517 Otherwise return 0. This function cannot quit.
17518 The return value is 2 if the text is invisible but with an ellipsis
17519 and 1 if it's invisible and without an ellipsis. */
17522 invisible_p (propval
, list
)
17523 register Lisp_Object propval
;
17526 register Lisp_Object tail
, proptail
;
17528 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17530 register Lisp_Object tem
;
17532 if (EQ (propval
, tem
))
17534 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17535 return NILP (XCDR (tem
)) ? 1 : 2;
17538 if (CONSP (propval
))
17540 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17542 Lisp_Object propelt
;
17543 propelt
= XCAR (proptail
);
17544 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17546 register Lisp_Object tem
;
17548 if (EQ (propelt
, tem
))
17550 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17551 return NILP (XCDR (tem
)) ? 1 : 2;
17559 /* Calculate a width or height in pixels from a specification using
17560 the following elements:
17563 NUM - a (fractional) multiple of the default font width/height
17564 (NUM) - specifies exactly NUM pixels
17565 UNIT - a fixed number of pixels, see below.
17566 ELEMENT - size of a display element in pixels, see below.
17567 (NUM . SPEC) - equals NUM * SPEC
17568 (+ SPEC SPEC ...) - add pixel values
17569 (- SPEC SPEC ...) - subtract pixel values
17570 (- SPEC) - negate pixel value
17573 INT or FLOAT - a number constant
17574 SYMBOL - use symbol's (buffer local) variable binding.
17577 in - pixels per inch *)
17578 mm - pixels per 1/1000 meter *)
17579 cm - pixels per 1/100 meter *)
17580 width - width of current font in pixels.
17581 height - height of current font in pixels.
17583 *) using the ratio(s) defined in display-pixels-per-inch.
17587 left-fringe - left fringe width in pixels
17588 right-fringe - right fringe width in pixels
17590 left-margin - left margin width in pixels
17591 right-margin - right margin width in pixels
17593 scroll-bar - scroll-bar area width in pixels
17597 Pixels corresponding to 5 inches:
17600 Total width of non-text areas on left side of window (if scroll-bar is on left):
17601 '(space :width (+ left-fringe left-margin scroll-bar))
17603 Align to first text column (in header line):
17604 '(space :align-to 0)
17606 Align to middle of text area minus half the width of variable `my-image'
17607 containing a loaded image:
17608 '(space :align-to (0.5 . (- text my-image)))
17610 Width of left margin minus width of 1 character in the default font:
17611 '(space :width (- left-margin 1))
17613 Width of left margin minus width of 2 characters in the current font:
17614 '(space :width (- left-margin (2 . width)))
17616 Center 1 character over left-margin (in header line):
17617 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17619 Different ways to express width of left fringe plus left margin minus one pixel:
17620 '(space :width (- (+ left-fringe left-margin) (1)))
17621 '(space :width (+ left-fringe left-margin (- (1))))
17622 '(space :width (+ left-fringe left-margin (-1)))
17626 #define NUMVAL(X) \
17627 ((INTEGERP (X) || FLOATP (X)) \
17632 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17637 int width_p
, *align_to
;
17641 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17642 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17645 return OK_PIXELS (0);
17647 if (SYMBOLP (prop
))
17649 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17651 char *unit
= SDATA (SYMBOL_NAME (prop
));
17653 if (unit
[0] == 'i' && unit
[1] == 'n')
17655 else if (unit
[0] == 'm' && unit
[1] == 'm')
17657 else if (unit
[0] == 'c' && unit
[1] == 'm')
17664 #ifdef HAVE_WINDOW_SYSTEM
17665 if (FRAME_WINDOW_P (it
->f
)
17667 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
17668 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
17670 return OK_PIXELS (ppi
/ pixels
);
17673 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17674 || (CONSP (Vdisplay_pixels_per_inch
)
17676 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17677 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17679 return OK_PIXELS (ppi
/ pixels
);
17685 #ifdef HAVE_WINDOW_SYSTEM
17686 if (EQ (prop
, Qheight
))
17687 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17688 if (EQ (prop
, Qwidth
))
17689 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17691 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17692 return OK_PIXELS (1);
17695 if (EQ (prop
, Qtext
))
17696 return OK_PIXELS (width_p
17697 ? window_box_width (it
->w
, TEXT_AREA
)
17698 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17700 if (align_to
&& *align_to
< 0)
17703 if (EQ (prop
, Qleft
))
17704 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17705 if (EQ (prop
, Qright
))
17706 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17707 if (EQ (prop
, Qcenter
))
17708 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17709 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17710 if (EQ (prop
, Qleft_fringe
))
17711 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17712 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17713 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17714 if (EQ (prop
, Qright_fringe
))
17715 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17716 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17717 : window_box_right_offset (it
->w
, TEXT_AREA
));
17718 if (EQ (prop
, Qleft_margin
))
17719 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17720 if (EQ (prop
, Qright_margin
))
17721 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17722 if (EQ (prop
, Qscroll_bar
))
17723 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17725 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17726 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17727 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17732 if (EQ (prop
, Qleft_fringe
))
17733 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17734 if (EQ (prop
, Qright_fringe
))
17735 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17736 if (EQ (prop
, Qleft_margin
))
17737 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17738 if (EQ (prop
, Qright_margin
))
17739 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17740 if (EQ (prop
, Qscroll_bar
))
17741 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17744 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17747 if (INTEGERP (prop
) || FLOATP (prop
))
17749 int base_unit
= (width_p
17750 ? FRAME_COLUMN_WIDTH (it
->f
)
17751 : FRAME_LINE_HEIGHT (it
->f
));
17752 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17757 Lisp_Object car
= XCAR (prop
);
17758 Lisp_Object cdr
= XCDR (prop
);
17762 #ifdef HAVE_WINDOW_SYSTEM
17763 if (valid_image_p (prop
))
17765 int id
= lookup_image (it
->f
, prop
);
17766 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17768 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17771 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17777 while (CONSP (cdr
))
17779 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17780 font
, width_p
, align_to
))
17783 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17788 if (EQ (car
, Qminus
))
17790 return OK_PIXELS (pixels
);
17793 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17796 if (INTEGERP (car
) || FLOATP (car
))
17799 pixels
= XFLOATINT (car
);
17801 return OK_PIXELS (pixels
);
17802 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17803 font
, width_p
, align_to
))
17804 return OK_PIXELS (pixels
* fact
);
17815 /***********************************************************************
17817 ***********************************************************************/
17819 #ifdef HAVE_WINDOW_SYSTEM
17824 dump_glyph_string (s
)
17825 struct glyph_string
*s
;
17827 fprintf (stderr
, "glyph string\n");
17828 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17829 s
->x
, s
->y
, s
->width
, s
->height
);
17830 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17831 fprintf (stderr
, " hl = %d\n", s
->hl
);
17832 fprintf (stderr
, " left overhang = %d, right = %d\n",
17833 s
->left_overhang
, s
->right_overhang
);
17834 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17835 fprintf (stderr
, " extends to end of line = %d\n",
17836 s
->extends_to_end_of_line_p
);
17837 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17838 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17841 #endif /* GLYPH_DEBUG */
17843 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17844 of XChar2b structures for S; it can't be allocated in
17845 init_glyph_string because it must be allocated via `alloca'. W
17846 is the window on which S is drawn. ROW and AREA are the glyph row
17847 and area within the row from which S is constructed. START is the
17848 index of the first glyph structure covered by S. HL is a
17849 face-override for drawing S. */
17852 #define OPTIONAL_HDC(hdc) hdc,
17853 #define DECLARE_HDC(hdc) HDC hdc;
17854 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17855 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17858 #ifndef OPTIONAL_HDC
17859 #define OPTIONAL_HDC(hdc)
17860 #define DECLARE_HDC(hdc)
17861 #define ALLOCATE_HDC(hdc, f)
17862 #define RELEASE_HDC(hdc, f)
17866 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17867 struct glyph_string
*s
;
17871 struct glyph_row
*row
;
17872 enum glyph_row_area area
;
17874 enum draw_glyphs_face hl
;
17876 bzero (s
, sizeof *s
);
17878 s
->f
= XFRAME (w
->frame
);
17882 s
->display
= FRAME_X_DISPLAY (s
->f
);
17883 s
->window
= FRAME_X_WINDOW (s
->f
);
17884 s
->char2b
= char2b
;
17888 s
->first_glyph
= row
->glyphs
[area
] + start
;
17889 s
->height
= row
->height
;
17890 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17892 /* Display the internal border below the tool-bar window. */
17893 if (WINDOWP (s
->f
->tool_bar_window
)
17894 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17895 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17897 s
->ybase
= s
->y
+ row
->ascent
;
17901 /* Append the list of glyph strings with head H and tail T to the list
17902 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17905 append_glyph_string_lists (head
, tail
, h
, t
)
17906 struct glyph_string
**head
, **tail
;
17907 struct glyph_string
*h
, *t
;
17921 /* Prepend the list of glyph strings with head H and tail T to the
17922 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17926 prepend_glyph_string_lists (head
, tail
, h
, t
)
17927 struct glyph_string
**head
, **tail
;
17928 struct glyph_string
*h
, *t
;
17942 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17943 Set *HEAD and *TAIL to the resulting list. */
17946 append_glyph_string (head
, tail
, s
)
17947 struct glyph_string
**head
, **tail
;
17948 struct glyph_string
*s
;
17950 s
->next
= s
->prev
= NULL
;
17951 append_glyph_string_lists (head
, tail
, s
, s
);
17955 /* Get face and two-byte form of character glyph GLYPH on frame F.
17956 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17957 a pointer to a realized face that is ready for display. */
17959 static INLINE
struct face
*
17960 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17962 struct glyph
*glyph
;
17968 xassert (glyph
->type
== CHAR_GLYPH
);
17969 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17974 if (!glyph
->multibyte_p
)
17976 /* Unibyte case. We don't have to encode, but we have to make
17977 sure to use a face suitable for unibyte. */
17978 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17980 else if (glyph
->u
.ch
< 128
17981 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17983 /* Case of ASCII in a face known to fit ASCII. */
17984 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17988 int c1
, c2
, charset
;
17990 /* Split characters into bytes. If c2 is -1 afterwards, C is
17991 really a one-byte character so that byte1 is zero. */
17992 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17994 STORE_XCHAR2B (char2b
, c1
, c2
);
17996 STORE_XCHAR2B (char2b
, 0, c1
);
17998 /* Maybe encode the character in *CHAR2B. */
17999 if (charset
!= CHARSET_ASCII
)
18001 struct font_info
*font_info
18002 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18005 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
18009 /* Make sure X resources of the face are allocated. */
18010 xassert (face
!= NULL
);
18011 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18016 /* Fill glyph string S with composition components specified by S->cmp.
18018 FACES is an array of faces for all components of this composition.
18019 S->gidx is the index of the first component for S.
18020 OVERLAPS_P non-zero means S should draw the foreground only, and
18021 use its physical height for clipping.
18023 Value is the index of a component not in S. */
18026 fill_composite_glyph_string (s
, faces
, overlaps_p
)
18027 struct glyph_string
*s
;
18028 struct face
**faces
;
18035 s
->for_overlaps_p
= overlaps_p
;
18037 s
->face
= faces
[s
->gidx
];
18038 s
->font
= s
->face
->font
;
18039 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18041 /* For all glyphs of this composition, starting at the offset
18042 S->gidx, until we reach the end of the definition or encounter a
18043 glyph that requires the different face, add it to S. */
18045 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
18048 /* All glyph strings for the same composition has the same width,
18049 i.e. the width set for the first component of the composition. */
18051 s
->width
= s
->first_glyph
->pixel_width
;
18053 /* If the specified font could not be loaded, use the frame's
18054 default font, but record the fact that we couldn't load it in
18055 the glyph string so that we can draw rectangles for the
18056 characters of the glyph string. */
18057 if (s
->font
== NULL
)
18059 s
->font_not_found_p
= 1;
18060 s
->font
= FRAME_FONT (s
->f
);
18063 /* Adjust base line for subscript/superscript text. */
18064 s
->ybase
+= s
->first_glyph
->voffset
;
18066 xassert (s
->face
&& s
->face
->gc
);
18068 /* This glyph string must always be drawn with 16-bit functions. */
18071 return s
->gidx
+ s
->nchars
;
18075 /* Fill glyph string S from a sequence of character glyphs.
18077 FACE_ID is the face id of the string. START is the index of the
18078 first glyph to consider, END is the index of the last + 1.
18079 OVERLAPS_P non-zero means S should draw the foreground only, and
18080 use its physical height for clipping.
18082 Value is the index of the first glyph not in S. */
18085 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
18086 struct glyph_string
*s
;
18088 int start
, end
, overlaps_p
;
18090 struct glyph
*glyph
, *last
;
18092 int glyph_not_available_p
;
18094 xassert (s
->f
== XFRAME (s
->w
->frame
));
18095 xassert (s
->nchars
== 0);
18096 xassert (start
>= 0 && end
> start
);
18098 s
->for_overlaps_p
= overlaps_p
,
18099 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18100 last
= s
->row
->glyphs
[s
->area
] + end
;
18101 voffset
= glyph
->voffset
;
18103 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18105 while (glyph
< last
18106 && glyph
->type
== CHAR_GLYPH
18107 && glyph
->voffset
== voffset
18108 /* Same face id implies same font, nowadays. */
18109 && glyph
->face_id
== face_id
18110 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18114 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18115 s
->char2b
+ s
->nchars
,
18117 s
->two_byte_p
= two_byte_p
;
18119 xassert (s
->nchars
<= end
- start
);
18120 s
->width
+= glyph
->pixel_width
;
18124 s
->font
= s
->face
->font
;
18125 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18127 /* If the specified font could not be loaded, use the frame's font,
18128 but record the fact that we couldn't load it in
18129 S->font_not_found_p so that we can draw rectangles for the
18130 characters of the glyph string. */
18131 if (s
->font
== NULL
|| glyph_not_available_p
)
18133 s
->font_not_found_p
= 1;
18134 s
->font
= FRAME_FONT (s
->f
);
18137 /* Adjust base line for subscript/superscript text. */
18138 s
->ybase
+= voffset
;
18140 xassert (s
->face
&& s
->face
->gc
);
18141 return glyph
- s
->row
->glyphs
[s
->area
];
18145 /* Fill glyph string S from image glyph S->first_glyph. */
18148 fill_image_glyph_string (s
)
18149 struct glyph_string
*s
;
18151 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18152 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18154 s
->slice
= s
->first_glyph
->slice
;
18155 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18156 s
->font
= s
->face
->font
;
18157 s
->width
= s
->first_glyph
->pixel_width
;
18159 /* Adjust base line for subscript/superscript text. */
18160 s
->ybase
+= s
->first_glyph
->voffset
;
18164 /* Fill glyph string S from a sequence of stretch glyphs.
18166 ROW is the glyph row in which the glyphs are found, AREA is the
18167 area within the row. START is the index of the first glyph to
18168 consider, END is the index of the last + 1.
18170 Value is the index of the first glyph not in S. */
18173 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18174 struct glyph_string
*s
;
18175 struct glyph_row
*row
;
18176 enum glyph_row_area area
;
18179 struct glyph
*glyph
, *last
;
18180 int voffset
, face_id
;
18182 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18184 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18185 last
= s
->row
->glyphs
[s
->area
] + end
;
18186 face_id
= glyph
->face_id
;
18187 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18188 s
->font
= s
->face
->font
;
18189 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18190 s
->width
= glyph
->pixel_width
;
18191 voffset
= glyph
->voffset
;
18195 && glyph
->type
== STRETCH_GLYPH
18196 && glyph
->voffset
== voffset
18197 && glyph
->face_id
== face_id
);
18199 s
->width
+= glyph
->pixel_width
;
18201 /* Adjust base line for subscript/superscript text. */
18202 s
->ybase
+= voffset
;
18204 /* The case that face->gc == 0 is handled when drawing the glyph
18205 string by calling PREPARE_FACE_FOR_DISPLAY. */
18207 return glyph
- s
->row
->glyphs
[s
->area
];
18212 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18213 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18214 assumed to be zero. */
18217 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18218 struct glyph
*glyph
;
18222 *left
= *right
= 0;
18224 if (glyph
->type
== CHAR_GLYPH
)
18228 struct font_info
*font_info
;
18232 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18234 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18235 if (font
/* ++KFS: Should this be font_info ? */
18236 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18238 if (pcm
->rbearing
> pcm
->width
)
18239 *right
= pcm
->rbearing
- pcm
->width
;
18240 if (pcm
->lbearing
< 0)
18241 *left
= -pcm
->lbearing
;
18247 /* Return the index of the first glyph preceding glyph string S that
18248 is overwritten by S because of S's left overhang. Value is -1
18249 if no glyphs are overwritten. */
18252 left_overwritten (s
)
18253 struct glyph_string
*s
;
18257 if (s
->left_overhang
)
18260 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18261 int first
= s
->first_glyph
- glyphs
;
18263 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18264 x
-= glyphs
[i
].pixel_width
;
18275 /* Return the index of the first glyph preceding glyph string S that
18276 is overwriting S because of its right overhang. Value is -1 if no
18277 glyph in front of S overwrites S. */
18280 left_overwriting (s
)
18281 struct glyph_string
*s
;
18284 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18285 int first
= s
->first_glyph
- glyphs
;
18289 for (i
= first
- 1; i
>= 0; --i
)
18292 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18295 x
-= glyphs
[i
].pixel_width
;
18302 /* Return the index of the last glyph following glyph string S that is
18303 not overwritten by S because of S's right overhang. Value is -1 if
18304 no such glyph is found. */
18307 right_overwritten (s
)
18308 struct glyph_string
*s
;
18312 if (s
->right_overhang
)
18315 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18316 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18317 int end
= s
->row
->used
[s
->area
];
18319 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18320 x
+= glyphs
[i
].pixel_width
;
18329 /* Return the index of the last glyph following glyph string S that
18330 overwrites S because of its left overhang. Value is negative
18331 if no such glyph is found. */
18334 right_overwriting (s
)
18335 struct glyph_string
*s
;
18338 int end
= s
->row
->used
[s
->area
];
18339 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18340 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18344 for (i
= first
; i
< end
; ++i
)
18347 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18350 x
+= glyphs
[i
].pixel_width
;
18357 /* Get face and two-byte form of character C in face FACE_ID on frame
18358 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18359 means we want to display multibyte text. DISPLAY_P non-zero means
18360 make sure that X resources for the face returned are allocated.
18361 Value is a pointer to a realized face that is ready for display if
18362 DISPLAY_P is non-zero. */
18364 static INLINE
struct face
*
18365 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18369 int multibyte_p
, display_p
;
18371 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18375 /* Unibyte case. We don't have to encode, but we have to make
18376 sure to use a face suitable for unibyte. */
18377 STORE_XCHAR2B (char2b
, 0, c
);
18378 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18379 face
= FACE_FROM_ID (f
, face_id
);
18381 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18383 /* Case of ASCII in a face known to fit ASCII. */
18384 STORE_XCHAR2B (char2b
, 0, c
);
18388 int c1
, c2
, charset
;
18390 /* Split characters into bytes. If c2 is -1 afterwards, C is
18391 really a one-byte character so that byte1 is zero. */
18392 SPLIT_CHAR (c
, charset
, c1
, c2
);
18394 STORE_XCHAR2B (char2b
, c1
, c2
);
18396 STORE_XCHAR2B (char2b
, 0, c1
);
18398 /* Maybe encode the character in *CHAR2B. */
18399 if (face
->font
!= NULL
)
18401 struct font_info
*font_info
18402 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18404 rif
->encode_char (c
, char2b
, font_info
, 0);
18408 /* Make sure X resources of the face are allocated. */
18409 #ifdef HAVE_X_WINDOWS
18413 xassert (face
!= NULL
);
18414 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18421 /* Set background width of glyph string S. START is the index of the
18422 first glyph following S. LAST_X is the right-most x-position + 1
18423 in the drawing area. */
18426 set_glyph_string_background_width (s
, start
, last_x
)
18427 struct glyph_string
*s
;
18431 /* If the face of this glyph string has to be drawn to the end of
18432 the drawing area, set S->extends_to_end_of_line_p. */
18433 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18435 if (start
== s
->row
->used
[s
->area
]
18436 && s
->area
== TEXT_AREA
18437 && ((s
->hl
== DRAW_NORMAL_TEXT
18438 && (s
->row
->fill_line_p
18439 || s
->face
->background
!= default_face
->background
18440 || s
->face
->stipple
!= default_face
->stipple
18441 || s
->row
->mouse_face_p
))
18442 || s
->hl
== DRAW_MOUSE_FACE
18443 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18444 && s
->row
->fill_line_p
)))
18445 s
->extends_to_end_of_line_p
= 1;
18447 /* If S extends its face to the end of the line, set its
18448 background_width to the distance to the right edge of the drawing
18450 if (s
->extends_to_end_of_line_p
)
18451 s
->background_width
= last_x
- s
->x
+ 1;
18453 s
->background_width
= s
->width
;
18457 /* Compute overhangs and x-positions for glyph string S and its
18458 predecessors, or successors. X is the starting x-position for S.
18459 BACKWARD_P non-zero means process predecessors. */
18462 compute_overhangs_and_x (s
, x
, backward_p
)
18463 struct glyph_string
*s
;
18471 if (rif
->compute_glyph_string_overhangs
)
18472 rif
->compute_glyph_string_overhangs (s
);
18482 if (rif
->compute_glyph_string_overhangs
)
18483 rif
->compute_glyph_string_overhangs (s
);
18493 /* The following macros are only called from draw_glyphs below.
18494 They reference the following parameters of that function directly:
18495 `w', `row', `area', and `overlap_p'
18496 as well as the following local variables:
18497 `s', `f', and `hdc' (in W32) */
18500 /* On W32, silently add local `hdc' variable to argument list of
18501 init_glyph_string. */
18502 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18503 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18505 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18506 init_glyph_string (s, char2b, w, row, area, start, hl)
18509 /* Add a glyph string for a stretch glyph to the list of strings
18510 between HEAD and TAIL. START is the index of the stretch glyph in
18511 row area AREA of glyph row ROW. END is the index of the last glyph
18512 in that glyph row area. X is the current output position assigned
18513 to the new glyph string constructed. HL overrides that face of the
18514 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18515 is the right-most x-position of the drawing area. */
18517 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18518 and below -- keep them on one line. */
18519 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18522 s = (struct glyph_string *) alloca (sizeof *s); \
18523 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18524 START = fill_stretch_glyph_string (s, row, area, START, END); \
18525 append_glyph_string (&HEAD, &TAIL, s); \
18531 /* Add a glyph string for an image glyph to the list of strings
18532 between HEAD and TAIL. START is the index of the image glyph in
18533 row area AREA of glyph row ROW. END is the index of the last glyph
18534 in that glyph row area. X is the current output position assigned
18535 to the new glyph string constructed. HL overrides that face of the
18536 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18537 is the right-most x-position of the drawing area. */
18539 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18542 s = (struct glyph_string *) alloca (sizeof *s); \
18543 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18544 fill_image_glyph_string (s); \
18545 append_glyph_string (&HEAD, &TAIL, s); \
18552 /* Add a glyph string for a sequence of character glyphs to the list
18553 of strings between HEAD and TAIL. START is the index of the first
18554 glyph in row area AREA of glyph row ROW that is part of the new
18555 glyph string. END is the index of the last glyph in that glyph row
18556 area. X is the current output position assigned to the new glyph
18557 string constructed. HL overrides that face of the glyph; e.g. it
18558 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18559 right-most x-position of the drawing area. */
18561 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18567 c = (row)->glyphs[area][START].u.ch; \
18568 face_id = (row)->glyphs[area][START].face_id; \
18570 s = (struct glyph_string *) alloca (sizeof *s); \
18571 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18572 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18573 append_glyph_string (&HEAD, &TAIL, s); \
18575 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18580 /* Add a glyph string for a composite sequence to the list of strings
18581 between HEAD and TAIL. START is the index of the first glyph in
18582 row area AREA of glyph row ROW that is part of the new glyph
18583 string. END is the index of the last glyph in that glyph row area.
18584 X is the current output position assigned to the new glyph string
18585 constructed. HL overrides that face of the glyph; e.g. it is
18586 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18587 x-position of the drawing area. */
18589 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18591 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18592 int face_id = (row)->glyphs[area][START].face_id; \
18593 struct face *base_face = FACE_FROM_ID (f, face_id); \
18594 struct composition *cmp = composition_table[cmp_id]; \
18595 int glyph_len = cmp->glyph_len; \
18597 struct face **faces; \
18598 struct glyph_string *first_s = NULL; \
18601 base_face = base_face->ascii_face; \
18602 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18603 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18604 /* At first, fill in `char2b' and `faces'. */ \
18605 for (n = 0; n < glyph_len; n++) \
18607 int c = COMPOSITION_GLYPH (cmp, n); \
18608 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18609 faces[n] = FACE_FROM_ID (f, this_face_id); \
18610 get_char_face_and_encoding (f, c, this_face_id, \
18611 char2b + n, 1, 1); \
18614 /* Make glyph_strings for each glyph sequence that is drawable by \
18615 the same face, and append them to HEAD/TAIL. */ \
18616 for (n = 0; n < cmp->glyph_len;) \
18618 s = (struct glyph_string *) alloca (sizeof *s); \
18619 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18620 append_glyph_string (&(HEAD), &(TAIL), s); \
18628 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18636 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18637 of AREA of glyph row ROW on window W between indices START and END.
18638 HL overrides the face for drawing glyph strings, e.g. it is
18639 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18640 x-positions of the drawing area.
18642 This is an ugly monster macro construct because we must use alloca
18643 to allocate glyph strings (because draw_glyphs can be called
18644 asynchronously). */
18646 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18649 HEAD = TAIL = NULL; \
18650 while (START < END) \
18652 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18653 switch (first_glyph->type) \
18656 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18660 case COMPOSITE_GLYPH: \
18661 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18665 case STRETCH_GLYPH: \
18666 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18670 case IMAGE_GLYPH: \
18671 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18679 set_glyph_string_background_width (s, START, LAST_X); \
18686 /* Draw glyphs between START and END in AREA of ROW on window W,
18687 starting at x-position X. X is relative to AREA in W. HL is a
18688 face-override with the following meaning:
18690 DRAW_NORMAL_TEXT draw normally
18691 DRAW_CURSOR draw in cursor face
18692 DRAW_MOUSE_FACE draw in mouse face.
18693 DRAW_INVERSE_VIDEO draw in mode line face
18694 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18695 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18697 If OVERLAPS_P is non-zero, draw only the foreground of characters
18698 and clip to the physical height of ROW.
18700 Value is the x-position reached, relative to AREA of W. */
18703 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18706 struct glyph_row
*row
;
18707 enum glyph_row_area area
;
18709 enum draw_glyphs_face hl
;
18712 struct glyph_string
*head
, *tail
;
18713 struct glyph_string
*s
;
18714 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18715 int last_x
, area_width
;
18718 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18721 ALLOCATE_HDC (hdc
, f
);
18723 /* Let's rather be paranoid than getting a SEGV. */
18724 end
= min (end
, row
->used
[area
]);
18725 start
= max (0, start
);
18726 start
= min (end
, start
);
18728 /* Translate X to frame coordinates. Set last_x to the right
18729 end of the drawing area. */
18730 if (row
->full_width_p
)
18732 /* X is relative to the left edge of W, without scroll bars
18734 x
+= WINDOW_LEFT_EDGE_X (w
);
18735 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18739 int area_left
= window_box_left (w
, area
);
18741 area_width
= window_box_width (w
, area
);
18742 last_x
= area_left
+ area_width
;
18745 /* Build a doubly-linked list of glyph_string structures between
18746 head and tail from what we have to draw. Note that the macro
18747 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18748 the reason we use a separate variable `i'. */
18750 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18752 x_reached
= tail
->x
+ tail
->background_width
;
18756 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18757 the row, redraw some glyphs in front or following the glyph
18758 strings built above. */
18759 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18762 struct glyph_string
*h
, *t
;
18764 /* Compute overhangs for all glyph strings. */
18765 if (rif
->compute_glyph_string_overhangs
)
18766 for (s
= head
; s
; s
= s
->next
)
18767 rif
->compute_glyph_string_overhangs (s
);
18769 /* Prepend glyph strings for glyphs in front of the first glyph
18770 string that are overwritten because of the first glyph
18771 string's left overhang. The background of all strings
18772 prepended must be drawn because the first glyph string
18774 i
= left_overwritten (head
);
18778 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18779 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18781 compute_overhangs_and_x (t
, head
->x
, 1);
18782 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18786 /* Prepend glyph strings for glyphs in front of the first glyph
18787 string that overwrite that glyph string because of their
18788 right overhang. For these strings, only the foreground must
18789 be drawn, because it draws over the glyph string at `head'.
18790 The background must not be drawn because this would overwrite
18791 right overhangs of preceding glyphs for which no glyph
18793 i
= left_overwriting (head
);
18797 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18798 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18799 for (s
= h
; s
; s
= s
->next
)
18800 s
->background_filled_p
= 1;
18801 compute_overhangs_and_x (t
, head
->x
, 1);
18802 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18805 /* Append glyphs strings for glyphs following the last glyph
18806 string tail that are overwritten by tail. The background of
18807 these strings has to be drawn because tail's foreground draws
18809 i
= right_overwritten (tail
);
18812 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18813 DRAW_NORMAL_TEXT
, x
, last_x
);
18814 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18815 append_glyph_string_lists (&head
, &tail
, h
, t
);
18819 /* Append glyph strings for glyphs following the last glyph
18820 string tail that overwrite tail. The foreground of such
18821 glyphs has to be drawn because it writes into the background
18822 of tail. The background must not be drawn because it could
18823 paint over the foreground of following glyphs. */
18824 i
= right_overwriting (tail
);
18828 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18829 DRAW_NORMAL_TEXT
, x
, last_x
);
18830 for (s
= h
; s
; s
= s
->next
)
18831 s
->background_filled_p
= 1;
18832 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18833 append_glyph_string_lists (&head
, &tail
, h
, t
);
18835 if (clip_head
|| clip_tail
)
18836 for (s
= head
; s
; s
= s
->next
)
18838 s
->clip_head
= clip_head
;
18839 s
->clip_tail
= clip_tail
;
18843 /* Draw all strings. */
18844 for (s
= head
; s
; s
= s
->next
)
18845 rif
->draw_glyph_string (s
);
18847 if (area
== TEXT_AREA
18848 && !row
->full_width_p
18849 /* When drawing overlapping rows, only the glyph strings'
18850 foreground is drawn, which doesn't erase a cursor
18854 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18855 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18856 : (tail
? tail
->x
+ tail
->background_width
: x
));
18858 int text_left
= window_box_left (w
, TEXT_AREA
);
18862 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18863 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18866 /* Value is the x-position up to which drawn, relative to AREA of W.
18867 This doesn't include parts drawn because of overhangs. */
18868 if (row
->full_width_p
)
18869 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18871 x_reached
-= window_box_left (w
, area
);
18873 RELEASE_HDC (hdc
, f
);
18878 /* Expand row matrix if too narrow. Don't expand if area
18881 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18883 if (!fonts_changed_p \
18884 && (it->glyph_row->glyphs[area] \
18885 < it->glyph_row->glyphs[area + 1])) \
18887 it->w->ncols_scale_factor++; \
18888 fonts_changed_p = 1; \
18892 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18893 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18899 struct glyph
*glyph
;
18900 enum glyph_row_area area
= it
->area
;
18902 xassert (it
->glyph_row
);
18903 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18905 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18906 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18908 glyph
->charpos
= CHARPOS (it
->position
);
18909 glyph
->object
= it
->object
;
18910 glyph
->pixel_width
= it
->pixel_width
;
18911 glyph
->ascent
= it
->ascent
;
18912 glyph
->descent
= it
->descent
;
18913 glyph
->voffset
= it
->voffset
;
18914 glyph
->type
= CHAR_GLYPH
;
18915 glyph
->multibyte_p
= it
->multibyte_p
;
18916 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18917 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18918 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18919 || it
->phys_descent
> it
->descent
);
18920 glyph
->padding_p
= 0;
18921 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18922 glyph
->face_id
= it
->face_id
;
18923 glyph
->u
.ch
= it
->char_to_display
;
18924 glyph
->slice
= null_glyph_slice
;
18925 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18926 ++it
->glyph_row
->used
[area
];
18929 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18932 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18933 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18936 append_composite_glyph (it
)
18939 struct glyph
*glyph
;
18940 enum glyph_row_area area
= it
->area
;
18942 xassert (it
->glyph_row
);
18944 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18945 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18947 glyph
->charpos
= CHARPOS (it
->position
);
18948 glyph
->object
= it
->object
;
18949 glyph
->pixel_width
= it
->pixel_width
;
18950 glyph
->ascent
= it
->ascent
;
18951 glyph
->descent
= it
->descent
;
18952 glyph
->voffset
= it
->voffset
;
18953 glyph
->type
= COMPOSITE_GLYPH
;
18954 glyph
->multibyte_p
= it
->multibyte_p
;
18955 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18956 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18957 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18958 || it
->phys_descent
> it
->descent
);
18959 glyph
->padding_p
= 0;
18960 glyph
->glyph_not_available_p
= 0;
18961 glyph
->face_id
= it
->face_id
;
18962 glyph
->u
.cmp_id
= it
->cmp_id
;
18963 glyph
->slice
= null_glyph_slice
;
18964 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18965 ++it
->glyph_row
->used
[area
];
18968 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18972 /* Change IT->ascent and IT->height according to the setting of
18976 take_vertical_position_into_account (it
)
18981 if (it
->voffset
< 0)
18982 /* Increase the ascent so that we can display the text higher
18984 it
->ascent
-= it
->voffset
;
18986 /* Increase the descent so that we can display the text lower
18988 it
->descent
+= it
->voffset
;
18993 /* Produce glyphs/get display metrics for the image IT is loaded with.
18994 See the description of struct display_iterator in dispextern.h for
18995 an overview of struct display_iterator. */
18998 produce_image_glyph (it
)
19004 struct glyph_slice slice
;
19006 xassert (it
->what
== IT_IMAGE
);
19008 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19010 /* Make sure X resources of the face is loaded. */
19011 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19013 if (it
->image_id
< 0)
19015 /* Fringe bitmap. */
19016 it
->ascent
= it
->phys_ascent
= 0;
19017 it
->descent
= it
->phys_descent
= 0;
19018 it
->pixel_width
= 0;
19023 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
19025 /* Make sure X resources of the image is loaded. */
19026 prepare_image_for_display (it
->f
, img
);
19028 slice
.x
= slice
.y
= 0;
19029 slice
.width
= img
->width
;
19030 slice
.height
= img
->height
;
19032 if (INTEGERP (it
->slice
.x
))
19033 slice
.x
= XINT (it
->slice
.x
);
19034 else if (FLOATP (it
->slice
.x
))
19035 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
19037 if (INTEGERP (it
->slice
.y
))
19038 slice
.y
= XINT (it
->slice
.y
);
19039 else if (FLOATP (it
->slice
.y
))
19040 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
19042 if (INTEGERP (it
->slice
.width
))
19043 slice
.width
= XINT (it
->slice
.width
);
19044 else if (FLOATP (it
->slice
.width
))
19045 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
19047 if (INTEGERP (it
->slice
.height
))
19048 slice
.height
= XINT (it
->slice
.height
);
19049 else if (FLOATP (it
->slice
.height
))
19050 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
19052 if (slice
.x
>= img
->width
)
19053 slice
.x
= img
->width
;
19054 if (slice
.y
>= img
->height
)
19055 slice
.y
= img
->height
;
19056 if (slice
.x
+ slice
.width
>= img
->width
)
19057 slice
.width
= img
->width
- slice
.x
;
19058 if (slice
.y
+ slice
.height
> img
->height
)
19059 slice
.height
= img
->height
- slice
.y
;
19061 if (slice
.width
== 0 || slice
.height
== 0)
19064 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
19066 it
->descent
= slice
.height
- glyph_ascent
;
19068 it
->descent
+= img
->vmargin
;
19069 if (slice
.y
+ slice
.height
== img
->height
)
19070 it
->descent
+= img
->vmargin
;
19071 it
->phys_descent
= it
->descent
;
19073 it
->pixel_width
= slice
.width
;
19075 it
->pixel_width
+= img
->hmargin
;
19076 if (slice
.x
+ slice
.width
== img
->width
)
19077 it
->pixel_width
+= img
->hmargin
;
19079 /* It's quite possible for images to have an ascent greater than
19080 their height, so don't get confused in that case. */
19081 if (it
->descent
< 0)
19084 #if 0 /* this breaks image tiling */
19085 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19086 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19087 if (face_ascent
> it
->ascent
)
19088 it
->ascent
= it
->phys_ascent
= face_ascent
;
19093 if (face
->box
!= FACE_NO_BOX
)
19095 if (face
->box_line_width
> 0)
19098 it
->ascent
+= face
->box_line_width
;
19099 if (slice
.y
+ slice
.height
== img
->height
)
19100 it
->descent
+= face
->box_line_width
;
19103 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19104 it
->pixel_width
+= abs (face
->box_line_width
);
19105 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19106 it
->pixel_width
+= abs (face
->box_line_width
);
19109 take_vertical_position_into_account (it
);
19113 struct glyph
*glyph
;
19114 enum glyph_row_area area
= it
->area
;
19116 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19117 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19119 glyph
->charpos
= CHARPOS (it
->position
);
19120 glyph
->object
= it
->object
;
19121 glyph
->pixel_width
= it
->pixel_width
;
19122 glyph
->ascent
= glyph_ascent
;
19123 glyph
->descent
= it
->descent
;
19124 glyph
->voffset
= it
->voffset
;
19125 glyph
->type
= IMAGE_GLYPH
;
19126 glyph
->multibyte_p
= it
->multibyte_p
;
19127 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19128 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19129 glyph
->overlaps_vertically_p
= 0;
19130 glyph
->padding_p
= 0;
19131 glyph
->glyph_not_available_p
= 0;
19132 glyph
->face_id
= it
->face_id
;
19133 glyph
->u
.img_id
= img
->id
;
19134 glyph
->slice
= slice
;
19135 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19136 ++it
->glyph_row
->used
[area
];
19139 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19144 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19145 of the glyph, WIDTH and HEIGHT are the width and height of the
19146 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19149 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19151 Lisp_Object object
;
19155 struct glyph
*glyph
;
19156 enum glyph_row_area area
= it
->area
;
19158 xassert (ascent
>= 0 && ascent
<= height
);
19160 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19161 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19163 glyph
->charpos
= CHARPOS (it
->position
);
19164 glyph
->object
= object
;
19165 glyph
->pixel_width
= width
;
19166 glyph
->ascent
= ascent
;
19167 glyph
->descent
= height
- ascent
;
19168 glyph
->voffset
= it
->voffset
;
19169 glyph
->type
= STRETCH_GLYPH
;
19170 glyph
->multibyte_p
= it
->multibyte_p
;
19171 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19172 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19173 glyph
->overlaps_vertically_p
= 0;
19174 glyph
->padding_p
= 0;
19175 glyph
->glyph_not_available_p
= 0;
19176 glyph
->face_id
= it
->face_id
;
19177 glyph
->u
.stretch
.ascent
= ascent
;
19178 glyph
->u
.stretch
.height
= height
;
19179 glyph
->slice
= null_glyph_slice
;
19180 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19181 ++it
->glyph_row
->used
[area
];
19184 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19188 /* Produce a stretch glyph for iterator IT. IT->object is the value
19189 of the glyph property displayed. The value must be a list
19190 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19193 1. `:width WIDTH' specifies that the space should be WIDTH *
19194 canonical char width wide. WIDTH may be an integer or floating
19197 2. `:relative-width FACTOR' specifies that the width of the stretch
19198 should be computed from the width of the first character having the
19199 `glyph' property, and should be FACTOR times that width.
19201 3. `:align-to HPOS' specifies that the space should be wide enough
19202 to reach HPOS, a value in canonical character units.
19204 Exactly one of the above pairs must be present.
19206 4. `:height HEIGHT' specifies that the height of the stretch produced
19207 should be HEIGHT, measured in canonical character units.
19209 5. `:relative-height FACTOR' specifies that the height of the
19210 stretch should be FACTOR times the height of the characters having
19211 the glyph property.
19213 Either none or exactly one of 4 or 5 must be present.
19215 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19216 of the stretch should be used for the ascent of the stretch.
19217 ASCENT must be in the range 0 <= ASCENT <= 100. */
19220 produce_stretch_glyph (it
)
19223 /* (space :width WIDTH :height HEIGHT ...) */
19224 Lisp_Object prop
, plist
;
19225 int width
= 0, height
= 0, align_to
= -1;
19226 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19229 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19230 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19232 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19234 /* List should start with `space'. */
19235 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19236 plist
= XCDR (it
->object
);
19238 /* Compute the width of the stretch. */
19239 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19240 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19242 /* Absolute width `:width WIDTH' specified and valid. */
19243 zero_width_ok_p
= 1;
19246 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19249 /* Relative width `:relative-width FACTOR' specified and valid.
19250 Compute the width of the characters having the `glyph'
19253 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19256 if (it
->multibyte_p
)
19258 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19259 - IT_BYTEPOS (*it
));
19260 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19263 it2
.c
= *p
, it2
.len
= 1;
19265 it2
.glyph_row
= NULL
;
19266 it2
.what
= IT_CHARACTER
;
19267 x_produce_glyphs (&it2
);
19268 width
= NUMVAL (prop
) * it2
.pixel_width
;
19270 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19271 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19273 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19274 align_to
= (align_to
< 0
19276 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19277 else if (align_to
< 0)
19278 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19279 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19280 zero_width_ok_p
= 1;
19283 /* Nothing specified -> width defaults to canonical char width. */
19284 width
= FRAME_COLUMN_WIDTH (it
->f
);
19286 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19289 /* Compute height. */
19290 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19291 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19294 zero_height_ok_p
= 1;
19296 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19298 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19300 height
= FONT_HEIGHT (font
);
19302 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19305 /* Compute percentage of height used for ascent. If
19306 `:ascent ASCENT' is present and valid, use that. Otherwise,
19307 derive the ascent from the font in use. */
19308 if (prop
= Fplist_get (plist
, QCascent
),
19309 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19310 ascent
= height
* NUMVAL (prop
) / 100.0;
19311 else if (!NILP (prop
)
19312 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19313 ascent
= min (max (0, (int)tem
), height
);
19315 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19317 if (width
> 0 && height
> 0 && it
->glyph_row
)
19319 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19320 if (!STRINGP (object
))
19321 object
= it
->w
->buffer
;
19322 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19325 it
->pixel_width
= width
;
19326 it
->ascent
= it
->phys_ascent
= ascent
;
19327 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19328 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19330 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19332 if (face
->box_line_width
> 0)
19334 it
->ascent
+= face
->box_line_width
;
19335 it
->descent
+= face
->box_line_width
;
19338 if (it
->start_of_box_run_p
)
19339 it
->pixel_width
+= abs (face
->box_line_width
);
19340 if (it
->end_of_box_run_p
)
19341 it
->pixel_width
+= abs (face
->box_line_width
);
19344 take_vertical_position_into_account (it
);
19347 /* Get line-height and line-spacing property at point.
19348 If line-height has format (HEIGHT TOTAL), return TOTAL
19349 in TOTAL_HEIGHT. */
19352 get_line_height_property (it
, prop
)
19356 Lisp_Object position
;
19358 if (STRINGP (it
->object
))
19359 position
= make_number (IT_STRING_CHARPOS (*it
));
19360 else if (BUFFERP (it
->object
))
19361 position
= make_number (IT_CHARPOS (*it
));
19365 return Fget_char_property (position
, prop
, it
->object
);
19368 /* Calculate line-height and line-spacing properties.
19369 An integer value specifies explicit pixel value.
19370 A float value specifies relative value to current face height.
19371 A cons (float . face-name) specifies relative value to
19372 height of specified face font.
19374 Returns height in pixels, or nil. */
19378 calc_line_height_property (it
, val
, font
, boff
, override
)
19382 int boff
, override
;
19384 Lisp_Object face_name
= Qnil
;
19385 int ascent
, descent
, height
;
19387 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19392 face_name
= XCAR (val
);
19394 if (!NUMBERP (val
))
19395 val
= make_number (1);
19396 if (NILP (face_name
))
19398 height
= it
->ascent
+ it
->descent
;
19403 if (NILP (face_name
))
19405 font
= FRAME_FONT (it
->f
);
19406 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19408 else if (EQ (face_name
, Qt
))
19416 struct font_info
*font_info
;
19418 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19420 return make_number (-1);
19422 face
= FACE_FROM_ID (it
->f
, face_id
);
19425 return make_number (-1);
19427 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19428 boff
= font_info
->baseline_offset
;
19429 if (font_info
->vertical_centering
)
19430 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19433 ascent
= FONT_BASE (font
) + boff
;
19434 descent
= FONT_DESCENT (font
) - boff
;
19438 it
->override_ascent
= ascent
;
19439 it
->override_descent
= descent
;
19440 it
->override_boff
= boff
;
19443 height
= ascent
+ descent
;
19447 height
= (int)(XFLOAT_DATA (val
) * height
);
19448 else if (INTEGERP (val
))
19449 height
*= XINT (val
);
19451 return make_number (height
);
19456 Produce glyphs/get display metrics for the display element IT is
19457 loaded with. See the description of struct display_iterator in
19458 dispextern.h for an overview of struct display_iterator. */
19461 x_produce_glyphs (it
)
19464 int extra_line_spacing
= it
->extra_line_spacing
;
19466 it
->glyph_not_available_p
= 0;
19468 if (it
->what
== IT_CHARACTER
)
19472 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19474 int font_not_found_p
;
19475 struct font_info
*font_info
;
19476 int boff
; /* baseline offset */
19477 /* We may change it->multibyte_p upon unibyte<->multibyte
19478 conversion. So, save the current value now and restore it
19481 Note: It seems that we don't have to record multibyte_p in
19482 struct glyph because the character code itself tells if or
19483 not the character is multibyte. Thus, in the future, we must
19484 consider eliminating the field `multibyte_p' in the struct
19486 int saved_multibyte_p
= it
->multibyte_p
;
19488 /* Maybe translate single-byte characters to multibyte, or the
19490 it
->char_to_display
= it
->c
;
19491 if (!ASCII_BYTE_P (it
->c
))
19493 if (unibyte_display_via_language_environment
19494 && SINGLE_BYTE_CHAR_P (it
->c
)
19496 || !NILP (Vnonascii_translation_table
)))
19498 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19499 it
->multibyte_p
= 1;
19500 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19501 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19503 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19504 && !it
->multibyte_p
)
19506 it
->multibyte_p
= 1;
19507 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19508 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19512 /* Get font to use. Encode IT->char_to_display. */
19513 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19514 &char2b
, it
->multibyte_p
, 0);
19517 /* When no suitable font found, use the default font. */
19518 font_not_found_p
= font
== NULL
;
19519 if (font_not_found_p
)
19521 font
= FRAME_FONT (it
->f
);
19522 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19527 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19528 boff
= font_info
->baseline_offset
;
19529 if (font_info
->vertical_centering
)
19530 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19533 if (it
->char_to_display
>= ' '
19534 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19536 /* Either unibyte or ASCII. */
19541 pcm
= rif
->per_char_metric (font
, &char2b
,
19542 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19544 if (it
->override_ascent
>= 0)
19546 it
->ascent
= it
->override_ascent
;
19547 it
->descent
= it
->override_descent
;
19548 boff
= it
->override_boff
;
19552 it
->ascent
= FONT_BASE (font
) + boff
;
19553 it
->descent
= FONT_DESCENT (font
) - boff
;
19558 it
->phys_ascent
= pcm
->ascent
+ boff
;
19559 it
->phys_descent
= pcm
->descent
- boff
;
19560 it
->pixel_width
= pcm
->width
;
19564 it
->glyph_not_available_p
= 1;
19565 it
->phys_ascent
= it
->ascent
;
19566 it
->phys_descent
= it
->descent
;
19567 it
->pixel_width
= FONT_WIDTH (font
);
19570 if (it
->constrain_row_ascent_descent_p
)
19572 if (it
->descent
> it
->max_descent
)
19574 it
->ascent
+= it
->descent
- it
->max_descent
;
19575 it
->descent
= it
->max_descent
;
19577 if (it
->ascent
> it
->max_ascent
)
19579 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19580 it
->ascent
= it
->max_ascent
;
19582 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19583 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19584 extra_line_spacing
= 0;
19587 /* If this is a space inside a region of text with
19588 `space-width' property, change its width. */
19589 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19591 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19593 /* If face has a box, add the box thickness to the character
19594 height. If character has a box line to the left and/or
19595 right, add the box line width to the character's width. */
19596 if (face
->box
!= FACE_NO_BOX
)
19598 int thick
= face
->box_line_width
;
19602 it
->ascent
+= thick
;
19603 it
->descent
+= thick
;
19608 if (it
->start_of_box_run_p
)
19609 it
->pixel_width
+= thick
;
19610 if (it
->end_of_box_run_p
)
19611 it
->pixel_width
+= thick
;
19614 /* If face has an overline, add the height of the overline
19615 (1 pixel) and a 1 pixel margin to the character height. */
19616 if (face
->overline_p
)
19619 if (it
->constrain_row_ascent_descent_p
)
19621 if (it
->ascent
> it
->max_ascent
)
19622 it
->ascent
= it
->max_ascent
;
19623 if (it
->descent
> it
->max_descent
)
19624 it
->descent
= it
->max_descent
;
19627 take_vertical_position_into_account (it
);
19629 /* If we have to actually produce glyphs, do it. */
19634 /* Translate a space with a `space-width' property
19635 into a stretch glyph. */
19636 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19637 / FONT_HEIGHT (font
));
19638 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19639 it
->ascent
+ it
->descent
, ascent
);
19644 /* If characters with lbearing or rbearing are displayed
19645 in this line, record that fact in a flag of the
19646 glyph row. This is used to optimize X output code. */
19647 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19648 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19651 else if (it
->char_to_display
== '\n')
19653 /* A newline has no width but we need the height of the line.
19654 But if previous part of the line set a height, don't
19655 increase that height */
19657 Lisp_Object height
;
19658 Lisp_Object total_height
= Qnil
;
19660 it
->override_ascent
= -1;
19661 it
->pixel_width
= 0;
19664 height
= get_line_height_property(it
, Qline_height
);
19665 /* Split (line-height total-height) list */
19667 && CONSP (XCDR (height
))
19668 && NILP (XCDR (XCDR (height
))))
19670 total_height
= XCAR (XCDR (height
));
19671 height
= XCAR (height
);
19673 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19675 if (it
->override_ascent
>= 0)
19677 it
->ascent
= it
->override_ascent
;
19678 it
->descent
= it
->override_descent
;
19679 boff
= it
->override_boff
;
19683 it
->ascent
= FONT_BASE (font
) + boff
;
19684 it
->descent
= FONT_DESCENT (font
) - boff
;
19687 if (EQ (height
, Qt
))
19689 if (it
->descent
> it
->max_descent
)
19691 it
->ascent
+= it
->descent
- it
->max_descent
;
19692 it
->descent
= it
->max_descent
;
19694 if (it
->ascent
> it
->max_ascent
)
19696 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19697 it
->ascent
= it
->max_ascent
;
19699 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19700 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19701 it
->constrain_row_ascent_descent_p
= 1;
19702 extra_line_spacing
= 0;
19706 Lisp_Object spacing
;
19708 it
->phys_ascent
= it
->ascent
;
19709 it
->phys_descent
= it
->descent
;
19711 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19712 && face
->box
!= FACE_NO_BOX
19713 && face
->box_line_width
> 0)
19715 it
->ascent
+= face
->box_line_width
;
19716 it
->descent
+= face
->box_line_width
;
19719 && XINT (height
) > it
->ascent
+ it
->descent
)
19720 it
->ascent
= XINT (height
) - it
->descent
;
19722 if (!NILP (total_height
))
19723 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19726 spacing
= get_line_height_property(it
, Qline_spacing
);
19727 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19729 if (INTEGERP (spacing
))
19731 extra_line_spacing
= XINT (spacing
);
19732 if (!NILP (total_height
))
19733 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19737 else if (it
->char_to_display
== '\t')
19739 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19740 int x
= it
->current_x
+ it
->continuation_lines_width
;
19741 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19743 /* If the distance from the current position to the next tab
19744 stop is less than a space character width, use the
19745 tab stop after that. */
19746 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19747 next_tab_x
+= tab_width
;
19749 it
->pixel_width
= next_tab_x
- x
;
19751 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19752 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19756 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19757 it
->ascent
+ it
->descent
, it
->ascent
);
19762 /* A multi-byte character. Assume that the display width of the
19763 character is the width of the character multiplied by the
19764 width of the font. */
19766 /* If we found a font, this font should give us the right
19767 metrics. If we didn't find a font, use the frame's
19768 default font and calculate the width of the character
19769 from the charset width; this is what old redisplay code
19772 pcm
= rif
->per_char_metric (font
, &char2b
,
19773 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19775 if (font_not_found_p
|| !pcm
)
19777 int charset
= CHAR_CHARSET (it
->char_to_display
);
19779 it
->glyph_not_available_p
= 1;
19780 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19781 * CHARSET_WIDTH (charset
));
19782 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19783 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19787 it
->pixel_width
= pcm
->width
;
19788 it
->phys_ascent
= pcm
->ascent
+ boff
;
19789 it
->phys_descent
= pcm
->descent
- boff
;
19791 && (pcm
->lbearing
< 0
19792 || pcm
->rbearing
> pcm
->width
))
19793 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19796 it
->ascent
= FONT_BASE (font
) + boff
;
19797 it
->descent
= FONT_DESCENT (font
) - boff
;
19798 if (face
->box
!= FACE_NO_BOX
)
19800 int thick
= face
->box_line_width
;
19804 it
->ascent
+= thick
;
19805 it
->descent
+= thick
;
19810 if (it
->start_of_box_run_p
)
19811 it
->pixel_width
+= thick
;
19812 if (it
->end_of_box_run_p
)
19813 it
->pixel_width
+= thick
;
19816 /* If face has an overline, add the height of the overline
19817 (1 pixel) and a 1 pixel margin to the character height. */
19818 if (face
->overline_p
)
19821 take_vertical_position_into_account (it
);
19826 it
->multibyte_p
= saved_multibyte_p
;
19828 else if (it
->what
== IT_COMPOSITION
)
19830 /* Note: A composition is represented as one glyph in the
19831 glyph matrix. There are no padding glyphs. */
19834 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19836 int font_not_found_p
;
19837 struct font_info
*font_info
;
19838 int boff
; /* baseline offset */
19839 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19841 /* Maybe translate single-byte characters to multibyte. */
19842 it
->char_to_display
= it
->c
;
19843 if (unibyte_display_via_language_environment
19844 && SINGLE_BYTE_CHAR_P (it
->c
)
19847 && !NILP (Vnonascii_translation_table
))))
19849 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19852 /* Get face and font to use. Encode IT->char_to_display. */
19853 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19854 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19855 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19856 &char2b
, it
->multibyte_p
, 0);
19859 /* When no suitable font found, use the default font. */
19860 font_not_found_p
= font
== NULL
;
19861 if (font_not_found_p
)
19863 font
= FRAME_FONT (it
->f
);
19864 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19869 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19870 boff
= font_info
->baseline_offset
;
19871 if (font_info
->vertical_centering
)
19872 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19875 /* There are no padding glyphs, so there is only one glyph to
19876 produce for the composition. Important is that pixel_width,
19877 ascent and descent are the values of what is drawn by
19878 draw_glyphs (i.e. the values of the overall glyphs composed). */
19881 /* If we have not yet calculated pixel size data of glyphs of
19882 the composition for the current face font, calculate them
19883 now. Theoretically, we have to check all fonts for the
19884 glyphs, but that requires much time and memory space. So,
19885 here we check only the font of the first glyph. This leads
19886 to incorrect display very rarely, and C-l (recenter) can
19887 correct the display anyway. */
19888 if (cmp
->font
!= (void *) font
)
19890 /* Ascent and descent of the font of the first character of
19891 this composition (adjusted by baseline offset). Ascent
19892 and descent of overall glyphs should not be less than
19893 them respectively. */
19894 int font_ascent
= FONT_BASE (font
) + boff
;
19895 int font_descent
= FONT_DESCENT (font
) - boff
;
19896 /* Bounding box of the overall glyphs. */
19897 int leftmost
, rightmost
, lowest
, highest
;
19898 int i
, width
, ascent
, descent
;
19900 cmp
->font
= (void *) font
;
19902 /* Initialize the bounding box. */
19904 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19905 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19907 width
= pcm
->width
;
19908 ascent
= pcm
->ascent
;
19909 descent
= pcm
->descent
;
19913 width
= FONT_WIDTH (font
);
19914 ascent
= FONT_BASE (font
);
19915 descent
= FONT_DESCENT (font
);
19919 lowest
= - descent
+ boff
;
19920 highest
= ascent
+ boff
;
19924 && font_info
->default_ascent
19925 && CHAR_TABLE_P (Vuse_default_ascent
)
19926 && !NILP (Faref (Vuse_default_ascent
,
19927 make_number (it
->char_to_display
))))
19928 highest
= font_info
->default_ascent
+ boff
;
19930 /* Draw the first glyph at the normal position. It may be
19931 shifted to right later if some other glyphs are drawn at
19933 cmp
->offsets
[0] = 0;
19934 cmp
->offsets
[1] = boff
;
19936 /* Set cmp->offsets for the remaining glyphs. */
19937 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19939 int left
, right
, btm
, top
;
19940 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19941 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19943 face
= FACE_FROM_ID (it
->f
, face_id
);
19944 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19945 &char2b
, it
->multibyte_p
, 0);
19949 font
= FRAME_FONT (it
->f
);
19950 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19956 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19957 boff
= font_info
->baseline_offset
;
19958 if (font_info
->vertical_centering
)
19959 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19963 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19964 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19966 width
= pcm
->width
;
19967 ascent
= pcm
->ascent
;
19968 descent
= pcm
->descent
;
19972 width
= FONT_WIDTH (font
);
19977 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19979 /* Relative composition with or without
19980 alternate chars. */
19981 left
= (leftmost
+ rightmost
- width
) / 2;
19982 btm
= - descent
+ boff
;
19983 if (font_info
&& font_info
->relative_compose
19984 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19985 || NILP (Faref (Vignore_relative_composition
,
19986 make_number (ch
)))))
19989 if (- descent
>= font_info
->relative_compose
)
19990 /* One extra pixel between two glyphs. */
19992 else if (ascent
<= 0)
19993 /* One extra pixel between two glyphs. */
19994 btm
= lowest
- 1 - ascent
- descent
;
19999 /* A composition rule is specified by an integer
20000 value that encodes global and new reference
20001 points (GREF and NREF). GREF and NREF are
20002 specified by numbers as below:
20004 0---1---2 -- ascent
20008 9--10--11 -- center
20010 ---3---4---5--- baseline
20012 6---7---8 -- descent
20014 int rule
= COMPOSITION_RULE (cmp
, i
);
20015 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
20017 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
20018 grefx
= gref
% 3, nrefx
= nref
% 3;
20019 grefy
= gref
/ 3, nrefy
= nref
/ 3;
20022 + grefx
* (rightmost
- leftmost
) / 2
20023 - nrefx
* width
/ 2);
20024 btm
= ((grefy
== 0 ? highest
20026 : grefy
== 2 ? lowest
20027 : (highest
+ lowest
) / 2)
20028 - (nrefy
== 0 ? ascent
+ descent
20029 : nrefy
== 1 ? descent
- boff
20031 : (ascent
+ descent
) / 2));
20034 cmp
->offsets
[i
* 2] = left
;
20035 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
20037 /* Update the bounding box of the overall glyphs. */
20038 right
= left
+ width
;
20039 top
= btm
+ descent
+ ascent
;
20040 if (left
< leftmost
)
20042 if (right
> rightmost
)
20050 /* If there are glyphs whose x-offsets are negative,
20051 shift all glyphs to the right and make all x-offsets
20055 for (i
= 0; i
< cmp
->glyph_len
; i
++)
20056 cmp
->offsets
[i
* 2] -= leftmost
;
20057 rightmost
-= leftmost
;
20060 cmp
->pixel_width
= rightmost
;
20061 cmp
->ascent
= highest
;
20062 cmp
->descent
= - lowest
;
20063 if (cmp
->ascent
< font_ascent
)
20064 cmp
->ascent
= font_ascent
;
20065 if (cmp
->descent
< font_descent
)
20066 cmp
->descent
= font_descent
;
20069 it
->pixel_width
= cmp
->pixel_width
;
20070 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20071 it
->descent
= it
->phys_descent
= cmp
->descent
;
20073 if (face
->box
!= FACE_NO_BOX
)
20075 int thick
= face
->box_line_width
;
20079 it
->ascent
+= thick
;
20080 it
->descent
+= thick
;
20085 if (it
->start_of_box_run_p
)
20086 it
->pixel_width
+= thick
;
20087 if (it
->end_of_box_run_p
)
20088 it
->pixel_width
+= thick
;
20091 /* If face has an overline, add the height of the overline
20092 (1 pixel) and a 1 pixel margin to the character height. */
20093 if (face
->overline_p
)
20096 take_vertical_position_into_account (it
);
20099 append_composite_glyph (it
);
20101 else if (it
->what
== IT_IMAGE
)
20102 produce_image_glyph (it
);
20103 else if (it
->what
== IT_STRETCH
)
20104 produce_stretch_glyph (it
);
20106 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20107 because this isn't true for images with `:ascent 100'. */
20108 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20109 if (it
->area
== TEXT_AREA
)
20110 it
->current_x
+= it
->pixel_width
;
20112 if (extra_line_spacing
> 0)
20114 it
->descent
+= extra_line_spacing
;
20115 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20116 it
->max_extra_line_spacing
= extra_line_spacing
;
20119 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20120 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20121 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20122 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20126 Output LEN glyphs starting at START at the nominal cursor position.
20127 Advance the nominal cursor over the text. The global variable
20128 updated_window contains the window being updated, updated_row is
20129 the glyph row being updated, and updated_area is the area of that
20130 row being updated. */
20133 x_write_glyphs (start
, len
)
20134 struct glyph
*start
;
20139 xassert (updated_window
&& updated_row
);
20142 /* Write glyphs. */
20144 hpos
= start
- updated_row
->glyphs
[updated_area
];
20145 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20146 updated_row
, updated_area
,
20148 DRAW_NORMAL_TEXT
, 0);
20150 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20151 if (updated_area
== TEXT_AREA
20152 && updated_window
->phys_cursor_on_p
20153 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20154 && updated_window
->phys_cursor
.hpos
>= hpos
20155 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20156 updated_window
->phys_cursor_on_p
= 0;
20160 /* Advance the output cursor. */
20161 output_cursor
.hpos
+= len
;
20162 output_cursor
.x
= x
;
20167 Insert LEN glyphs from START at the nominal cursor position. */
20170 x_insert_glyphs (start
, len
)
20171 struct glyph
*start
;
20176 int line_height
, shift_by_width
, shifted_region_width
;
20177 struct glyph_row
*row
;
20178 struct glyph
*glyph
;
20179 int frame_x
, frame_y
, hpos
;
20181 xassert (updated_window
&& updated_row
);
20183 w
= updated_window
;
20184 f
= XFRAME (WINDOW_FRAME (w
));
20186 /* Get the height of the line we are in. */
20188 line_height
= row
->height
;
20190 /* Get the width of the glyphs to insert. */
20191 shift_by_width
= 0;
20192 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20193 shift_by_width
+= glyph
->pixel_width
;
20195 /* Get the width of the region to shift right. */
20196 shifted_region_width
= (window_box_width (w
, updated_area
)
20201 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20202 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20204 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20205 line_height
, shift_by_width
);
20207 /* Write the glyphs. */
20208 hpos
= start
- row
->glyphs
[updated_area
];
20209 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20211 DRAW_NORMAL_TEXT
, 0);
20213 /* Advance the output cursor. */
20214 output_cursor
.hpos
+= len
;
20215 output_cursor
.x
+= shift_by_width
;
20221 Erase the current text line from the nominal cursor position
20222 (inclusive) to pixel column TO_X (exclusive). The idea is that
20223 everything from TO_X onward is already erased.
20225 TO_X is a pixel position relative to updated_area of
20226 updated_window. TO_X == -1 means clear to the end of this area. */
20229 x_clear_end_of_line (to_x
)
20233 struct window
*w
= updated_window
;
20234 int max_x
, min_y
, max_y
;
20235 int from_x
, from_y
, to_y
;
20237 xassert (updated_window
&& updated_row
);
20238 f
= XFRAME (w
->frame
);
20240 if (updated_row
->full_width_p
)
20241 max_x
= WINDOW_TOTAL_WIDTH (w
);
20243 max_x
= window_box_width (w
, updated_area
);
20244 max_y
= window_text_bottom_y (w
);
20246 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20247 of window. For TO_X > 0, truncate to end of drawing area. */
20253 to_x
= min (to_x
, max_x
);
20255 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20257 /* Notice if the cursor will be cleared by this operation. */
20258 if (!updated_row
->full_width_p
)
20259 notice_overwritten_cursor (w
, updated_area
,
20260 output_cursor
.x
, -1,
20262 MATRIX_ROW_BOTTOM_Y (updated_row
));
20264 from_x
= output_cursor
.x
;
20266 /* Translate to frame coordinates. */
20267 if (updated_row
->full_width_p
)
20269 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20270 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20274 int area_left
= window_box_left (w
, updated_area
);
20275 from_x
+= area_left
;
20279 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20280 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20281 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20283 /* Prevent inadvertently clearing to end of the X window. */
20284 if (to_x
> from_x
&& to_y
> from_y
)
20287 rif
->clear_frame_area (f
, from_x
, from_y
,
20288 to_x
- from_x
, to_y
- from_y
);
20293 #endif /* HAVE_WINDOW_SYSTEM */
20297 /***********************************************************************
20299 ***********************************************************************/
20301 /* Value is the internal representation of the specified cursor type
20302 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20303 of the bar cursor. */
20305 static enum text_cursor_kinds
20306 get_specified_cursor_type (arg
, width
)
20310 enum text_cursor_kinds type
;
20315 if (EQ (arg
, Qbox
))
20316 return FILLED_BOX_CURSOR
;
20318 if (EQ (arg
, Qhollow
))
20319 return HOLLOW_BOX_CURSOR
;
20321 if (EQ (arg
, Qbar
))
20328 && EQ (XCAR (arg
), Qbar
)
20329 && INTEGERP (XCDR (arg
))
20330 && XINT (XCDR (arg
)) >= 0)
20332 *width
= XINT (XCDR (arg
));
20336 if (EQ (arg
, Qhbar
))
20339 return HBAR_CURSOR
;
20343 && EQ (XCAR (arg
), Qhbar
)
20344 && INTEGERP (XCDR (arg
))
20345 && XINT (XCDR (arg
)) >= 0)
20347 *width
= XINT (XCDR (arg
));
20348 return HBAR_CURSOR
;
20351 /* Treat anything unknown as "hollow box cursor".
20352 It was bad to signal an error; people have trouble fixing
20353 .Xdefaults with Emacs, when it has something bad in it. */
20354 type
= HOLLOW_BOX_CURSOR
;
20359 /* Set the default cursor types for specified frame. */
20361 set_frame_cursor_types (f
, arg
)
20368 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20369 FRAME_CURSOR_WIDTH (f
) = width
;
20371 /* By default, set up the blink-off state depending on the on-state. */
20373 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20376 FRAME_BLINK_OFF_CURSOR (f
)
20377 = get_specified_cursor_type (XCDR (tem
), &width
);
20378 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20381 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20385 /* Return the cursor we want to be displayed in window W. Return
20386 width of bar/hbar cursor through WIDTH arg. Return with
20387 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20388 (i.e. if the `system caret' should track this cursor).
20390 In a mini-buffer window, we want the cursor only to appear if we
20391 are reading input from this window. For the selected window, we
20392 want the cursor type given by the frame parameter or buffer local
20393 setting of cursor-type. If explicitly marked off, draw no cursor.
20394 In all other cases, we want a hollow box cursor. */
20396 static enum text_cursor_kinds
20397 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20399 struct glyph
*glyph
;
20401 int *active_cursor
;
20403 struct frame
*f
= XFRAME (w
->frame
);
20404 struct buffer
*b
= XBUFFER (w
->buffer
);
20405 int cursor_type
= DEFAULT_CURSOR
;
20406 Lisp_Object alt_cursor
;
20407 int non_selected
= 0;
20409 *active_cursor
= 1;
20412 if (cursor_in_echo_area
20413 && FRAME_HAS_MINIBUF_P (f
)
20414 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20416 if (w
== XWINDOW (echo_area_window
))
20418 *width
= FRAME_CURSOR_WIDTH (f
);
20419 return FRAME_DESIRED_CURSOR (f
);
20422 *active_cursor
= 0;
20426 /* Nonselected window or nonselected frame. */
20427 else if (w
!= XWINDOW (f
->selected_window
)
20428 #ifdef HAVE_WINDOW_SYSTEM
20429 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20433 *active_cursor
= 0;
20435 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20441 /* Never display a cursor in a window in which cursor-type is nil. */
20442 if (NILP (b
->cursor_type
))
20445 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20448 alt_cursor
= XBUFFER (w
->buffer
)->cursor_in_non_selected_windows
;
20449 return get_specified_cursor_type (alt_cursor
, width
);
20452 /* Get the normal cursor type for this window. */
20453 if (EQ (b
->cursor_type
, Qt
))
20455 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20456 *width
= FRAME_CURSOR_WIDTH (f
);
20459 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20461 /* Use normal cursor if not blinked off. */
20462 if (!w
->cursor_off_p
)
20464 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20465 if (cursor_type
== FILLED_BOX_CURSOR
)
20466 cursor_type
= HOLLOW_BOX_CURSOR
;
20468 return cursor_type
;
20471 /* Cursor is blinked off, so determine how to "toggle" it. */
20473 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20474 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20475 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20477 /* Then see if frame has specified a specific blink off cursor type. */
20478 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20480 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20481 return FRAME_BLINK_OFF_CURSOR (f
);
20485 /* Some people liked having a permanently visible blinking cursor,
20486 while others had very strong opinions against it. So it was
20487 decided to remove it. KFS 2003-09-03 */
20489 /* Finally perform built-in cursor blinking:
20490 filled box <-> hollow box
20491 wide [h]bar <-> narrow [h]bar
20492 narrow [h]bar <-> no cursor
20493 other type <-> no cursor */
20495 if (cursor_type
== FILLED_BOX_CURSOR
)
20496 return HOLLOW_BOX_CURSOR
;
20498 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20501 return cursor_type
;
20509 #ifdef HAVE_WINDOW_SYSTEM
20511 /* Notice when the text cursor of window W has been completely
20512 overwritten by a drawing operation that outputs glyphs in AREA
20513 starting at X0 and ending at X1 in the line starting at Y0 and
20514 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20515 the rest of the line after X0 has been written. Y coordinates
20516 are window-relative. */
20519 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20521 enum glyph_row_area area
;
20522 int x0
, y0
, x1
, y1
;
20524 int cx0
, cx1
, cy0
, cy1
;
20525 struct glyph_row
*row
;
20527 if (!w
->phys_cursor_on_p
)
20529 if (area
!= TEXT_AREA
)
20532 if (w
->phys_cursor
.vpos
< 0
20533 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20534 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20535 !(row
->enabled_p
&& row
->displays_text_p
)))
20538 if (row
->cursor_in_fringe_p
)
20540 row
->cursor_in_fringe_p
= 0;
20541 draw_fringe_bitmap (w
, row
, 0);
20542 w
->phys_cursor_on_p
= 0;
20546 cx0
= w
->phys_cursor
.x
;
20547 cx1
= cx0
+ w
->phys_cursor_width
;
20548 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20551 /* The cursor image will be completely removed from the
20552 screen if the output area intersects the cursor area in
20553 y-direction. When we draw in [y0 y1[, and some part of
20554 the cursor is at y < y0, that part must have been drawn
20555 before. When scrolling, the cursor is erased before
20556 actually scrolling, so we don't come here. When not
20557 scrolling, the rows above the old cursor row must have
20558 changed, and in this case these rows must have written
20559 over the cursor image.
20561 Likewise if part of the cursor is below y1, with the
20562 exception of the cursor being in the first blank row at
20563 the buffer and window end because update_text_area
20564 doesn't draw that row. (Except when it does, but
20565 that's handled in update_text_area.) */
20567 cy0
= w
->phys_cursor
.y
;
20568 cy1
= cy0
+ w
->phys_cursor_height
;
20569 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20572 w
->phys_cursor_on_p
= 0;
20575 #endif /* HAVE_WINDOW_SYSTEM */
20578 /************************************************************************
20580 ************************************************************************/
20582 #ifdef HAVE_WINDOW_SYSTEM
20585 Fix the display of area AREA of overlapping row ROW in window W. */
20588 x_fix_overlapping_area (w
, row
, area
)
20590 struct glyph_row
*row
;
20591 enum glyph_row_area area
;
20598 for (i
= 0; i
< row
->used
[area
];)
20600 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20602 int start
= i
, start_x
= x
;
20606 x
+= row
->glyphs
[area
][i
].pixel_width
;
20609 while (i
< row
->used
[area
]
20610 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20612 draw_glyphs (w
, start_x
, row
, area
,
20614 DRAW_NORMAL_TEXT
, 1);
20618 x
+= row
->glyphs
[area
][i
].pixel_width
;
20628 Draw the cursor glyph of window W in glyph row ROW. See the
20629 comment of draw_glyphs for the meaning of HL. */
20632 draw_phys_cursor_glyph (w
, row
, hl
)
20634 struct glyph_row
*row
;
20635 enum draw_glyphs_face hl
;
20637 /* If cursor hpos is out of bounds, don't draw garbage. This can
20638 happen in mini-buffer windows when switching between echo area
20639 glyphs and mini-buffer. */
20640 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20642 int on_p
= w
->phys_cursor_on_p
;
20644 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20645 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20647 w
->phys_cursor_on_p
= on_p
;
20649 if (hl
== DRAW_CURSOR
)
20650 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20651 /* When we erase the cursor, and ROW is overlapped by other
20652 rows, make sure that these overlapping parts of other rows
20654 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20656 if (row
> w
->current_matrix
->rows
20657 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20658 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20660 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20661 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20662 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20669 Erase the image of a cursor of window W from the screen. */
20672 erase_phys_cursor (w
)
20675 struct frame
*f
= XFRAME (w
->frame
);
20676 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20677 int hpos
= w
->phys_cursor
.hpos
;
20678 int vpos
= w
->phys_cursor
.vpos
;
20679 int mouse_face_here_p
= 0;
20680 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20681 struct glyph_row
*cursor_row
;
20682 struct glyph
*cursor_glyph
;
20683 enum draw_glyphs_face hl
;
20685 /* No cursor displayed or row invalidated => nothing to do on the
20687 if (w
->phys_cursor_type
== NO_CURSOR
)
20688 goto mark_cursor_off
;
20690 /* VPOS >= active_glyphs->nrows means that window has been resized.
20691 Don't bother to erase the cursor. */
20692 if (vpos
>= active_glyphs
->nrows
)
20693 goto mark_cursor_off
;
20695 /* If row containing cursor is marked invalid, there is nothing we
20697 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20698 if (!cursor_row
->enabled_p
)
20699 goto mark_cursor_off
;
20701 /* If line spacing is > 0, old cursor may only be partially visible in
20702 window after split-window. So adjust visible height. */
20703 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20704 window_text_bottom_y (w
) - cursor_row
->y
);
20706 /* If row is completely invisible, don't attempt to delete a cursor which
20707 isn't there. This can happen if cursor is at top of a window, and
20708 we switch to a buffer with a header line in that window. */
20709 if (cursor_row
->visible_height
<= 0)
20710 goto mark_cursor_off
;
20712 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20713 if (cursor_row
->cursor_in_fringe_p
)
20715 cursor_row
->cursor_in_fringe_p
= 0;
20716 draw_fringe_bitmap (w
, cursor_row
, 0);
20717 goto mark_cursor_off
;
20720 /* This can happen when the new row is shorter than the old one.
20721 In this case, either draw_glyphs or clear_end_of_line
20722 should have cleared the cursor. Note that we wouldn't be
20723 able to erase the cursor in this case because we don't have a
20724 cursor glyph at hand. */
20725 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20726 goto mark_cursor_off
;
20728 /* If the cursor is in the mouse face area, redisplay that when
20729 we clear the cursor. */
20730 if (! NILP (dpyinfo
->mouse_face_window
)
20731 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20732 && (vpos
> dpyinfo
->mouse_face_beg_row
20733 || (vpos
== dpyinfo
->mouse_face_beg_row
20734 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20735 && (vpos
< dpyinfo
->mouse_face_end_row
20736 || (vpos
== dpyinfo
->mouse_face_end_row
20737 && hpos
< dpyinfo
->mouse_face_end_col
))
20738 /* Don't redraw the cursor's spot in mouse face if it is at the
20739 end of a line (on a newline). The cursor appears there, but
20740 mouse highlighting does not. */
20741 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20742 mouse_face_here_p
= 1;
20744 /* Maybe clear the display under the cursor. */
20745 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20748 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20751 cursor_glyph
= get_phys_cursor_glyph (w
);
20752 if (cursor_glyph
== NULL
)
20753 goto mark_cursor_off
;
20755 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20756 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20757 width
= min (cursor_glyph
->pixel_width
,
20758 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20760 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20763 /* Erase the cursor by redrawing the character underneath it. */
20764 if (mouse_face_here_p
)
20765 hl
= DRAW_MOUSE_FACE
;
20767 hl
= DRAW_NORMAL_TEXT
;
20768 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20771 w
->phys_cursor_on_p
= 0;
20772 w
->phys_cursor_type
= NO_CURSOR
;
20777 Display or clear cursor of window W. If ON is zero, clear the
20778 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20779 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20782 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20784 int on
, hpos
, vpos
, x
, y
;
20786 struct frame
*f
= XFRAME (w
->frame
);
20787 int new_cursor_type
;
20788 int new_cursor_width
;
20790 struct glyph_row
*glyph_row
;
20791 struct glyph
*glyph
;
20793 /* This is pointless on invisible frames, and dangerous on garbaged
20794 windows and frames; in the latter case, the frame or window may
20795 be in the midst of changing its size, and x and y may be off the
20797 if (! FRAME_VISIBLE_P (f
)
20798 || FRAME_GARBAGED_P (f
)
20799 || vpos
>= w
->current_matrix
->nrows
20800 || hpos
>= w
->current_matrix
->matrix_w
)
20803 /* If cursor is off and we want it off, return quickly. */
20804 if (!on
&& !w
->phys_cursor_on_p
)
20807 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20808 /* If cursor row is not enabled, we don't really know where to
20809 display the cursor. */
20810 if (!glyph_row
->enabled_p
)
20812 w
->phys_cursor_on_p
= 0;
20817 if (!glyph_row
->exact_window_width_line_p
20818 || hpos
< glyph_row
->used
[TEXT_AREA
])
20819 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20821 xassert (interrupt_input_blocked
);
20823 /* Set new_cursor_type to the cursor we want to be displayed. */
20824 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20825 &new_cursor_width
, &active_cursor
);
20827 /* If cursor is currently being shown and we don't want it to be or
20828 it is in the wrong place, or the cursor type is not what we want,
20830 if (w
->phys_cursor_on_p
20832 || w
->phys_cursor
.x
!= x
20833 || w
->phys_cursor
.y
!= y
20834 || new_cursor_type
!= w
->phys_cursor_type
20835 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20836 && new_cursor_width
!= w
->phys_cursor_width
)))
20837 erase_phys_cursor (w
);
20839 /* Don't check phys_cursor_on_p here because that flag is only set
20840 to zero in some cases where we know that the cursor has been
20841 completely erased, to avoid the extra work of erasing the cursor
20842 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20843 still not be visible, or it has only been partly erased. */
20846 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20847 w
->phys_cursor_height
= glyph_row
->height
;
20849 /* Set phys_cursor_.* before x_draw_.* is called because some
20850 of them may need the information. */
20851 w
->phys_cursor
.x
= x
;
20852 w
->phys_cursor
.y
= glyph_row
->y
;
20853 w
->phys_cursor
.hpos
= hpos
;
20854 w
->phys_cursor
.vpos
= vpos
;
20857 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20858 new_cursor_type
, new_cursor_width
,
20859 on
, active_cursor
);
20863 /* Switch the display of W's cursor on or off, according to the value
20867 update_window_cursor (w
, on
)
20871 /* Don't update cursor in windows whose frame is in the process
20872 of being deleted. */
20873 if (w
->current_matrix
)
20876 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20877 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20883 /* Call update_window_cursor with parameter ON_P on all leaf windows
20884 in the window tree rooted at W. */
20887 update_cursor_in_window_tree (w
, on_p
)
20893 if (!NILP (w
->hchild
))
20894 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20895 else if (!NILP (w
->vchild
))
20896 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20898 update_window_cursor (w
, on_p
);
20900 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20906 Display the cursor on window W, or clear it, according to ON_P.
20907 Don't change the cursor's position. */
20910 x_update_cursor (f
, on_p
)
20914 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20919 Clear the cursor of window W to background color, and mark the
20920 cursor as not shown. This is used when the text where the cursor
20921 is is about to be rewritten. */
20927 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20928 update_window_cursor (w
, 0);
20933 Display the active region described by mouse_face_* according to DRAW. */
20936 show_mouse_face (dpyinfo
, draw
)
20937 Display_Info
*dpyinfo
;
20938 enum draw_glyphs_face draw
;
20940 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20941 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20943 if (/* If window is in the process of being destroyed, don't bother
20945 w
->current_matrix
!= NULL
20946 /* Don't update mouse highlight if hidden */
20947 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20948 /* Recognize when we are called to operate on rows that don't exist
20949 anymore. This can happen when a window is split. */
20950 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20952 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20953 struct glyph_row
*row
, *first
, *last
;
20955 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20956 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20958 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20960 int start_hpos
, end_hpos
, start_x
;
20962 /* For all but the first row, the highlight starts at column 0. */
20965 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20966 start_x
= dpyinfo
->mouse_face_beg_x
;
20975 end_hpos
= dpyinfo
->mouse_face_end_col
;
20977 end_hpos
= row
->used
[TEXT_AREA
];
20979 if (end_hpos
> start_hpos
)
20981 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20982 start_hpos
, end_hpos
,
20986 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20990 /* When we've written over the cursor, arrange for it to
20991 be displayed again. */
20992 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20995 display_and_set_cursor (w
, 1,
20996 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20997 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
21002 /* Change the mouse cursor. */
21003 if (draw
== DRAW_NORMAL_TEXT
)
21004 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
21005 else if (draw
== DRAW_MOUSE_FACE
)
21006 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
21008 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
21012 Clear out the mouse-highlighted active region.
21013 Redraw it un-highlighted first. Value is non-zero if mouse
21014 face was actually drawn unhighlighted. */
21017 clear_mouse_face (dpyinfo
)
21018 Display_Info
*dpyinfo
;
21022 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
21024 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
21028 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
21029 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
21030 dpyinfo
->mouse_face_window
= Qnil
;
21031 dpyinfo
->mouse_face_overlay
= Qnil
;
21037 Non-zero if physical cursor of window W is within mouse face. */
21040 cursor_in_mouse_face_p (w
)
21043 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
21044 int in_mouse_face
= 0;
21046 if (WINDOWP (dpyinfo
->mouse_face_window
)
21047 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
21049 int hpos
= w
->phys_cursor
.hpos
;
21050 int vpos
= w
->phys_cursor
.vpos
;
21052 if (vpos
>= dpyinfo
->mouse_face_beg_row
21053 && vpos
<= dpyinfo
->mouse_face_end_row
21054 && (vpos
> dpyinfo
->mouse_face_beg_row
21055 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21056 && (vpos
< dpyinfo
->mouse_face_end_row
21057 || hpos
< dpyinfo
->mouse_face_end_col
21058 || dpyinfo
->mouse_face_past_end
))
21062 return in_mouse_face
;
21068 /* Find the glyph matrix position of buffer position CHARPOS in window
21069 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
21070 current glyphs must be up to date. If CHARPOS is above window
21071 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21072 of last line in W. In the row containing CHARPOS, stop before glyphs
21073 having STOP as object. */
21075 #if 1 /* This is a version of fast_find_position that's more correct
21076 in the presence of hscrolling, for example. I didn't install
21077 it right away because the problem fixed is minor, it failed
21078 in 20.x as well, and I think it's too risky to install
21079 so near the release of 21.1. 2001-09-25 gerd. */
21082 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21085 int *hpos
, *vpos
, *x
, *y
;
21088 struct glyph_row
*row
, *first
;
21089 struct glyph
*glyph
, *end
;
21092 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21093 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21098 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21102 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21105 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21109 /* If whole rows or last part of a row came from a display overlay,
21110 row_containing_pos will skip over such rows because their end pos
21111 equals the start pos of the overlay or interval.
21113 Move back if we have a STOP object and previous row's
21114 end glyph came from STOP. */
21117 struct glyph_row
*prev
;
21118 while ((prev
= row
- 1, prev
>= first
)
21119 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21120 && prev
->used
[TEXT_AREA
] > 0)
21122 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21123 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21124 while (--glyph
>= beg
21125 && INTEGERP (glyph
->object
));
21127 || !EQ (stop
, glyph
->object
))
21135 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21137 glyph
= row
->glyphs
[TEXT_AREA
];
21138 end
= glyph
+ row
->used
[TEXT_AREA
];
21140 /* Skip over glyphs not having an object at the start of the row.
21141 These are special glyphs like truncation marks on terminal
21143 if (row
->displays_text_p
)
21145 && INTEGERP (glyph
->object
)
21146 && !EQ (stop
, glyph
->object
)
21147 && glyph
->charpos
< 0)
21149 *x
+= glyph
->pixel_width
;
21154 && !INTEGERP (glyph
->object
)
21155 && !EQ (stop
, glyph
->object
)
21156 && (!BUFFERP (glyph
->object
)
21157 || glyph
->charpos
< charpos
))
21159 *x
+= glyph
->pixel_width
;
21163 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21170 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21173 int *hpos
, *vpos
, *x
, *y
;
21178 int maybe_next_line_p
= 0;
21179 int line_start_position
;
21180 int yb
= window_text_bottom_y (w
);
21181 struct glyph_row
*row
, *best_row
;
21182 int row_vpos
, best_row_vpos
;
21185 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21186 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21188 while (row
->y
< yb
)
21190 if (row
->used
[TEXT_AREA
])
21191 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21193 line_start_position
= 0;
21195 if (line_start_position
> pos
)
21197 /* If the position sought is the end of the buffer,
21198 don't include the blank lines at the bottom of the window. */
21199 else if (line_start_position
== pos
21200 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21202 maybe_next_line_p
= 1;
21205 else if (line_start_position
> 0)
21208 best_row_vpos
= row_vpos
;
21211 if (row
->y
+ row
->height
>= yb
)
21218 /* Find the right column within BEST_ROW. */
21220 current_x
= best_row
->x
;
21221 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21223 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21224 int charpos
= glyph
->charpos
;
21226 if (BUFFERP (glyph
->object
))
21228 if (charpos
== pos
)
21231 *vpos
= best_row_vpos
;
21236 else if (charpos
> pos
)
21239 else if (EQ (glyph
->object
, stop
))
21244 current_x
+= glyph
->pixel_width
;
21247 /* If we're looking for the end of the buffer,
21248 and we didn't find it in the line we scanned,
21249 use the start of the following line. */
21250 if (maybe_next_line_p
)
21255 current_x
= best_row
->x
;
21258 *vpos
= best_row_vpos
;
21259 *hpos
= lastcol
+ 1;
21268 /* Find the position of the glyph for position POS in OBJECT in
21269 window W's current matrix, and return in *X, *Y the pixel
21270 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21272 RIGHT_P non-zero means return the position of the right edge of the
21273 glyph, RIGHT_P zero means return the left edge position.
21275 If no glyph for POS exists in the matrix, return the position of
21276 the glyph with the next smaller position that is in the matrix, if
21277 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21278 exists in the matrix, return the position of the glyph with the
21279 next larger position in OBJECT.
21281 Value is non-zero if a glyph was found. */
21284 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21287 Lisp_Object object
;
21288 int *hpos
, *vpos
, *x
, *y
;
21291 int yb
= window_text_bottom_y (w
);
21292 struct glyph_row
*r
;
21293 struct glyph
*best_glyph
= NULL
;
21294 struct glyph_row
*best_row
= NULL
;
21297 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21298 r
->enabled_p
&& r
->y
< yb
;
21301 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21302 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21305 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21306 if (EQ (g
->object
, object
))
21308 if (g
->charpos
== pos
)
21315 else if (best_glyph
== NULL
21316 || ((abs (g
->charpos
- pos
)
21317 < abs (best_glyph
->charpos
- pos
))
21320 : g
->charpos
> pos
)))
21334 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21338 *x
+= best_glyph
->pixel_width
;
21343 *vpos
= best_row
- w
->current_matrix
->rows
;
21346 return best_glyph
!= NULL
;
21350 /* See if position X, Y is within a hot-spot of an image. */
21353 on_hot_spot_p (hot_spot
, x
, y
)
21354 Lisp_Object hot_spot
;
21357 if (!CONSP (hot_spot
))
21360 if (EQ (XCAR (hot_spot
), Qrect
))
21362 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21363 Lisp_Object rect
= XCDR (hot_spot
);
21367 if (!CONSP (XCAR (rect
)))
21369 if (!CONSP (XCDR (rect
)))
21371 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21373 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21375 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21377 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21381 else if (EQ (XCAR (hot_spot
), Qcircle
))
21383 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21384 Lisp_Object circ
= XCDR (hot_spot
);
21385 Lisp_Object lr
, lx0
, ly0
;
21387 && CONSP (XCAR (circ
))
21388 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21389 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21390 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21392 double r
= XFLOATINT (lr
);
21393 double dx
= XINT (lx0
) - x
;
21394 double dy
= XINT (ly0
) - y
;
21395 return (dx
* dx
+ dy
* dy
<= r
* r
);
21398 else if (EQ (XCAR (hot_spot
), Qpoly
))
21400 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21401 if (VECTORP (XCDR (hot_spot
)))
21403 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21404 Lisp_Object
*poly
= v
->contents
;
21408 Lisp_Object lx
, ly
;
21411 /* Need an even number of coordinates, and at least 3 edges. */
21412 if (n
< 6 || n
& 1)
21415 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21416 If count is odd, we are inside polygon. Pixels on edges
21417 may or may not be included depending on actual geometry of the
21419 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21420 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21422 x0
= XINT (lx
), y0
= XINT (ly
);
21423 for (i
= 0; i
< n
; i
+= 2)
21425 int x1
= x0
, y1
= y0
;
21426 if ((lx
= poly
[i
], !INTEGERP (lx
))
21427 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21429 x0
= XINT (lx
), y0
= XINT (ly
);
21431 /* Does this segment cross the X line? */
21439 if (y
> y0
&& y
> y1
)
21441 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21447 /* If we don't understand the format, pretend we're not in the hot-spot. */
21452 find_hot_spot (map
, x
, y
)
21456 while (CONSP (map
))
21458 if (CONSP (XCAR (map
))
21459 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21467 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21469 doc
: /* Lookup in image map MAP coordinates X and Y.
21470 An image map is an alist where each element has the format (AREA ID PLIST).
21471 An AREA is specified as either a rectangle, a circle, or a polygon:
21472 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21473 pixel coordinates of the upper left and bottom right corners.
21474 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21475 and the radius of the circle; r may be a float or integer.
21476 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21477 vector describes one corner in the polygon.
21478 Returns the alist element for the first matching AREA in MAP. */)
21489 return find_hot_spot (map
, XINT (x
), XINT (y
));
21493 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21495 define_frame_cursor1 (f
, cursor
, pointer
)
21498 Lisp_Object pointer
;
21500 /* Do not change cursor shape while dragging mouse. */
21501 if (!NILP (do_mouse_tracking
))
21504 if (!NILP (pointer
))
21506 if (EQ (pointer
, Qarrow
))
21507 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21508 else if (EQ (pointer
, Qhand
))
21509 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21510 else if (EQ (pointer
, Qtext
))
21511 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21512 else if (EQ (pointer
, intern ("hdrag")))
21513 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21514 #ifdef HAVE_X_WINDOWS
21515 else if (EQ (pointer
, intern ("vdrag")))
21516 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21518 else if (EQ (pointer
, intern ("hourglass")))
21519 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21520 else if (EQ (pointer
, Qmodeline
))
21521 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21523 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21526 if (cursor
!= No_Cursor
)
21527 rif
->define_frame_cursor (f
, cursor
);
21530 /* Take proper action when mouse has moved to the mode or header line
21531 or marginal area AREA of window W, x-position X and y-position Y.
21532 X is relative to the start of the text display area of W, so the
21533 width of bitmap areas and scroll bars must be subtracted to get a
21534 position relative to the start of the mode line. */
21537 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21538 Lisp_Object window
;
21540 enum window_part area
;
21542 struct window
*w
= XWINDOW (window
);
21543 struct frame
*f
= XFRAME (w
->frame
);
21544 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21545 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21546 Lisp_Object pointer
= Qnil
;
21547 int charpos
, dx
, dy
, width
, height
;
21548 Lisp_Object string
, object
= Qnil
;
21549 Lisp_Object pos
, help
;
21551 Lisp_Object mouse_face
;
21552 int original_x_pixel
= x
;
21553 struct glyph
* glyph
= NULL
;
21554 struct glyph_row
*row
;
21556 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21561 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21562 &object
, &dx
, &dy
, &width
, &height
);
21564 row
= (area
== ON_MODE_LINE
21565 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21566 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21569 if (row
->mode_line_p
&& row
->enabled_p
)
21571 glyph
= row
->glyphs
[TEXT_AREA
];
21572 end
= glyph
+ row
->used
[TEXT_AREA
];
21574 for (x0
= original_x_pixel
;
21575 glyph
< end
&& x0
>= glyph
->pixel_width
;
21577 x0
-= glyph
->pixel_width
;
21585 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21586 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21587 &object
, &dx
, &dy
, &width
, &height
);
21592 if (IMAGEP (object
))
21594 Lisp_Object image_map
, hotspot
;
21595 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
21597 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21599 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21601 Lisp_Object area_id
, plist
;
21603 area_id
= XCAR (hotspot
);
21604 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21605 If so, we could look for mouse-enter, mouse-leave
21606 properties in PLIST (and do something...). */
21607 hotspot
= XCDR (hotspot
);
21608 if (CONSP (hotspot
)
21609 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21611 pointer
= Fplist_get (plist
, Qpointer
);
21612 if (NILP (pointer
))
21614 help
= Fplist_get (plist
, Qhelp_echo
);
21617 help_echo_string
= help
;
21618 /* Is this correct? ++kfs */
21619 XSETWINDOW (help_echo_window
, w
);
21620 help_echo_object
= w
->buffer
;
21621 help_echo_pos
= charpos
;
21625 if (NILP (pointer
))
21626 pointer
= Fplist_get (XCDR (object
), QCpointer
);
21629 if (STRINGP (string
))
21631 pos
= make_number (charpos
);
21632 /* If we're on a string with `help-echo' text property, arrange
21633 for the help to be displayed. This is done by setting the
21634 global variable help_echo_string to the help string. */
21637 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21640 help_echo_string
= help
;
21641 XSETWINDOW (help_echo_window
, w
);
21642 help_echo_object
= string
;
21643 help_echo_pos
= charpos
;
21647 if (NILP (pointer
))
21648 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21650 /* Change the mouse pointer according to what is under X/Y. */
21651 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21654 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21655 if (!KEYMAPP (map
))
21656 map
= Fget_text_property (pos
, Qkeymap
, string
);
21657 if (!KEYMAPP (map
))
21658 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21661 /* Change the mouse face according to what is under X/Y. */
21662 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
21663 if (!NILP (mouse_face
)
21664 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21669 struct glyph
* tmp_glyph
;
21673 int total_pixel_width
;
21678 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
21679 Qmouse_face
, string
, Qnil
);
21681 b
= make_number (0);
21683 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
21685 e
= make_number (SCHARS (string
));
21687 /* Calculate the position(glyph position: GPOS) of GLYPH in
21688 displayed string. GPOS is different from CHARPOS.
21690 CHARPOS is the position of glyph in internal string
21691 object. A mode line string format has structures which
21692 is converted to a flatten by emacs lisp interpreter.
21693 The internal string is an element of the structures.
21694 The displayed string is the flatten string. */
21695 for (tmp_glyph
= glyph
- 1, gpos
= 0;
21696 tmp_glyph
->charpos
>= XINT (b
);
21697 tmp_glyph
--, gpos
++)
21699 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21703 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
21704 displayed string holding GLYPH.
21706 GSEQ_LENGTH is different from SCHARS (STRING).
21707 SCHARS (STRING) returns the length of the internal string. */
21708 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
21709 tmp_glyph
->charpos
< XINT (e
);
21710 tmp_glyph
++, gseq_length
++)
21712 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21716 total_pixel_width
= 0;
21717 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
21718 total_pixel_width
+= tmp_glyph
->pixel_width
;
21720 /* Pre calculation of re-rendering position */
21722 hpos
= (area
== ON_MODE_LINE
21723 ? (w
->current_matrix
)->nrows
- 1
21726 /* If the re-rendering position is included in the last
21727 re-rendering area, we should do nothing. */
21728 if ( EQ (window
, dpyinfo
->mouse_face_window
)
21729 && dpyinfo
->mouse_face_beg_col
<= vpos
21730 && vpos
< dpyinfo
->mouse_face_end_col
21731 && dpyinfo
->mouse_face_beg_row
== hpos
)
21734 if (clear_mouse_face (dpyinfo
))
21735 cursor
= No_Cursor
;
21737 dpyinfo
->mouse_face_beg_col
= vpos
;
21738 dpyinfo
->mouse_face_beg_row
= hpos
;
21740 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
21741 dpyinfo
->mouse_face_beg_y
= 0;
21743 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
21744 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
21746 dpyinfo
->mouse_face_end_x
= 0;
21747 dpyinfo
->mouse_face_end_y
= 0;
21749 dpyinfo
->mouse_face_past_end
= 0;
21750 dpyinfo
->mouse_face_window
= window
;
21752 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
21755 glyph
->face_id
, 1);
21756 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21758 if (NILP (pointer
))
21761 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21762 clear_mouse_face (dpyinfo
);
21764 define_frame_cursor1 (f
, cursor
, pointer
);
21769 Take proper action when the mouse has moved to position X, Y on
21770 frame F as regards highlighting characters that have mouse-face
21771 properties. Also de-highlighting chars where the mouse was before.
21772 X and Y can be negative or out of range. */
21775 note_mouse_highlight (f
, x
, y
)
21779 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21780 enum window_part part
;
21781 Lisp_Object window
;
21783 Cursor cursor
= No_Cursor
;
21784 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21787 /* When a menu is active, don't highlight because this looks odd. */
21788 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21789 if (popup_activated ())
21793 if (NILP (Vmouse_highlight
)
21794 || !f
->glyphs_initialized_p
)
21797 dpyinfo
->mouse_face_mouse_x
= x
;
21798 dpyinfo
->mouse_face_mouse_y
= y
;
21799 dpyinfo
->mouse_face_mouse_frame
= f
;
21801 if (dpyinfo
->mouse_face_defer
)
21804 if (gc_in_progress
)
21806 dpyinfo
->mouse_face_deferred_gc
= 1;
21810 /* Which window is that in? */
21811 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21813 /* If we were displaying active text in another window, clear that.
21814 Also clear if we move out of text area in same window. */
21815 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21816 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
21817 && !NILP (dpyinfo
->mouse_face_window
)))
21818 clear_mouse_face (dpyinfo
);
21820 /* Not on a window -> return. */
21821 if (!WINDOWP (window
))
21824 /* Reset help_echo_string. It will get recomputed below. */
21825 help_echo_string
= Qnil
;
21827 /* Convert to window-relative pixel coordinates. */
21828 w
= XWINDOW (window
);
21829 frame_to_window_pixel_xy (w
, &x
, &y
);
21831 /* Handle tool-bar window differently since it doesn't display a
21833 if (EQ (window
, f
->tool_bar_window
))
21835 note_tool_bar_highlight (f
, x
, y
);
21839 /* Mouse is on the mode, header line or margin? */
21840 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21841 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21843 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
21847 if (part
== ON_VERTICAL_BORDER
)
21848 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21849 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21850 || part
== ON_SCROLL_BAR
)
21851 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21853 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21855 /* Are we in a window whose display is up to date?
21856 And verify the buffer's text has not changed. */
21857 b
= XBUFFER (w
->buffer
);
21858 if (part
== ON_TEXT
21859 && EQ (w
->window_end_valid
, w
->buffer
)
21860 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21861 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21863 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21864 struct glyph
*glyph
;
21865 Lisp_Object object
;
21866 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21867 Lisp_Object
*overlay_vec
= NULL
;
21869 struct buffer
*obuf
;
21870 int obegv
, ozv
, same_region
;
21872 /* Find the glyph under X/Y. */
21873 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21875 /* Look for :pointer property on image. */
21876 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21878 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21879 if (img
!= NULL
&& IMAGEP (img
->spec
))
21881 Lisp_Object image_map
, hotspot
;
21882 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
21884 && (hotspot
= find_hot_spot (image_map
,
21885 glyph
->slice
.x
+ dx
,
21886 glyph
->slice
.y
+ dy
),
21888 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21890 Lisp_Object area_id
, plist
;
21892 area_id
= XCAR (hotspot
);
21893 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21894 If so, we could look for mouse-enter, mouse-leave
21895 properties in PLIST (and do something...). */
21896 hotspot
= XCDR (hotspot
);
21897 if (CONSP (hotspot
)
21898 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21900 pointer
= Fplist_get (plist
, Qpointer
);
21901 if (NILP (pointer
))
21903 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
21904 if (!NILP (help_echo_string
))
21906 help_echo_window
= window
;
21907 help_echo_object
= glyph
->object
;
21908 help_echo_pos
= glyph
->charpos
;
21912 if (NILP (pointer
))
21913 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
21917 /* Clear mouse face if X/Y not over text. */
21919 || area
!= TEXT_AREA
21920 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21922 if (clear_mouse_face (dpyinfo
))
21923 cursor
= No_Cursor
;
21924 if (NILP (pointer
))
21926 if (area
!= TEXT_AREA
)
21927 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21929 pointer
= Vvoid_text_area_pointer
;
21934 pos
= glyph
->charpos
;
21935 object
= glyph
->object
;
21936 if (!STRINGP (object
) && !BUFFERP (object
))
21939 /* If we get an out-of-range value, return now; avoid an error. */
21940 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21943 /* Make the window's buffer temporarily current for
21944 overlays_at and compute_char_face. */
21945 obuf
= current_buffer
;
21946 current_buffer
= b
;
21952 /* Is this char mouse-active or does it have help-echo? */
21953 position
= make_number (pos
);
21955 if (BUFFERP (object
))
21957 /* Put all the overlays we want in a vector in overlay_vec. */
21958 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21959 /* Sort overlays into increasing priority order. */
21960 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21965 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21966 && vpos
>= dpyinfo
->mouse_face_beg_row
21967 && vpos
<= dpyinfo
->mouse_face_end_row
21968 && (vpos
> dpyinfo
->mouse_face_beg_row
21969 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21970 && (vpos
< dpyinfo
->mouse_face_end_row
21971 || hpos
< dpyinfo
->mouse_face_end_col
21972 || dpyinfo
->mouse_face_past_end
));
21975 cursor
= No_Cursor
;
21977 /* Check mouse-face highlighting. */
21979 /* If there exists an overlay with mouse-face overlapping
21980 the one we are currently highlighting, we have to
21981 check if we enter the overlapping overlay, and then
21982 highlight only that. */
21983 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21984 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21986 /* Find the highest priority overlay that has a mouse-face
21989 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21991 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21992 if (!NILP (mouse_face
))
21993 overlay
= overlay_vec
[i
];
21996 /* If we're actually highlighting the same overlay as
21997 before, there's no need to do that again. */
21998 if (!NILP (overlay
)
21999 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
22000 goto check_help_echo
;
22002 dpyinfo
->mouse_face_overlay
= overlay
;
22004 /* Clear the display of the old active region, if any. */
22005 if (clear_mouse_face (dpyinfo
))
22006 cursor
= No_Cursor
;
22008 /* If no overlay applies, get a text property. */
22009 if (NILP (overlay
))
22010 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
22012 /* Handle the overlay case. */
22013 if (!NILP (overlay
))
22015 /* Find the range of text around this char that
22016 should be active. */
22017 Lisp_Object before
, after
;
22020 before
= Foverlay_start (overlay
);
22021 after
= Foverlay_end (overlay
);
22022 /* Record this as the current active region. */
22023 fast_find_position (w
, XFASTINT (before
),
22024 &dpyinfo
->mouse_face_beg_col
,
22025 &dpyinfo
->mouse_face_beg_row
,
22026 &dpyinfo
->mouse_face_beg_x
,
22027 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22029 dpyinfo
->mouse_face_past_end
22030 = !fast_find_position (w
, XFASTINT (after
),
22031 &dpyinfo
->mouse_face_end_col
,
22032 &dpyinfo
->mouse_face_end_row
,
22033 &dpyinfo
->mouse_face_end_x
,
22034 &dpyinfo
->mouse_face_end_y
, Qnil
);
22035 dpyinfo
->mouse_face_window
= window
;
22037 dpyinfo
->mouse_face_face_id
22038 = face_at_buffer_position (w
, pos
, 0, 0,
22040 !dpyinfo
->mouse_face_hidden
);
22042 /* Display it as active. */
22043 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22044 cursor
= No_Cursor
;
22046 /* Handle the text property case. */
22047 else if (!NILP (mouse_face
) && BUFFERP (object
))
22049 /* Find the range of text around this char that
22050 should be active. */
22051 Lisp_Object before
, after
, beginning
, end
;
22054 beginning
= Fmarker_position (w
->start
);
22055 end
= make_number (BUF_Z (XBUFFER (object
))
22056 - XFASTINT (w
->window_end_pos
));
22058 = Fprevious_single_property_change (make_number (pos
+ 1),
22060 object
, beginning
);
22062 = Fnext_single_property_change (position
, Qmouse_face
,
22065 /* Record this as the current active region. */
22066 fast_find_position (w
, XFASTINT (before
),
22067 &dpyinfo
->mouse_face_beg_col
,
22068 &dpyinfo
->mouse_face_beg_row
,
22069 &dpyinfo
->mouse_face_beg_x
,
22070 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22071 dpyinfo
->mouse_face_past_end
22072 = !fast_find_position (w
, XFASTINT (after
),
22073 &dpyinfo
->mouse_face_end_col
,
22074 &dpyinfo
->mouse_face_end_row
,
22075 &dpyinfo
->mouse_face_end_x
,
22076 &dpyinfo
->mouse_face_end_y
, Qnil
);
22077 dpyinfo
->mouse_face_window
= window
;
22079 if (BUFFERP (object
))
22080 dpyinfo
->mouse_face_face_id
22081 = face_at_buffer_position (w
, pos
, 0, 0,
22083 !dpyinfo
->mouse_face_hidden
);
22085 /* Display it as active. */
22086 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22087 cursor
= No_Cursor
;
22089 else if (!NILP (mouse_face
) && STRINGP (object
))
22094 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22097 e
= Fnext_single_property_change (position
, Qmouse_face
,
22100 b
= make_number (0);
22102 e
= make_number (SCHARS (object
) - 1);
22104 fast_find_string_pos (w
, XINT (b
), object
,
22105 &dpyinfo
->mouse_face_beg_col
,
22106 &dpyinfo
->mouse_face_beg_row
,
22107 &dpyinfo
->mouse_face_beg_x
,
22108 &dpyinfo
->mouse_face_beg_y
, 0);
22109 fast_find_string_pos (w
, XINT (e
), object
,
22110 &dpyinfo
->mouse_face_end_col
,
22111 &dpyinfo
->mouse_face_end_row
,
22112 &dpyinfo
->mouse_face_end_x
,
22113 &dpyinfo
->mouse_face_end_y
, 1);
22114 dpyinfo
->mouse_face_past_end
= 0;
22115 dpyinfo
->mouse_face_window
= window
;
22116 dpyinfo
->mouse_face_face_id
22117 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22118 glyph
->face_id
, 1);
22119 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22120 cursor
= No_Cursor
;
22122 else if (STRINGP (object
) && NILP (mouse_face
))
22124 /* A string which doesn't have mouse-face, but
22125 the text ``under'' it might have. */
22126 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22127 int start
= MATRIX_ROW_START_CHARPOS (r
);
22129 pos
= string_buffer_position (w
, object
, start
);
22131 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22135 if (!NILP (mouse_face
) && !NILP (overlay
))
22137 Lisp_Object before
= Foverlay_start (overlay
);
22138 Lisp_Object after
= Foverlay_end (overlay
);
22141 /* Note that we might not be able to find position
22142 BEFORE in the glyph matrix if the overlay is
22143 entirely covered by a `display' property. In
22144 this case, we overshoot. So let's stop in
22145 the glyph matrix before glyphs for OBJECT. */
22146 fast_find_position (w
, XFASTINT (before
),
22147 &dpyinfo
->mouse_face_beg_col
,
22148 &dpyinfo
->mouse_face_beg_row
,
22149 &dpyinfo
->mouse_face_beg_x
,
22150 &dpyinfo
->mouse_face_beg_y
,
22153 dpyinfo
->mouse_face_past_end
22154 = !fast_find_position (w
, XFASTINT (after
),
22155 &dpyinfo
->mouse_face_end_col
,
22156 &dpyinfo
->mouse_face_end_row
,
22157 &dpyinfo
->mouse_face_end_x
,
22158 &dpyinfo
->mouse_face_end_y
,
22160 dpyinfo
->mouse_face_window
= window
;
22161 dpyinfo
->mouse_face_face_id
22162 = face_at_buffer_position (w
, pos
, 0, 0,
22164 !dpyinfo
->mouse_face_hidden
);
22166 /* Display it as active. */
22167 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22168 cursor
= No_Cursor
;
22175 /* Look for a `help-echo' property. */
22176 if (NILP (help_echo_string
)) {
22177 Lisp_Object help
, overlay
;
22179 /* Check overlays first. */
22180 help
= overlay
= Qnil
;
22181 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22183 overlay
= overlay_vec
[i
];
22184 help
= Foverlay_get (overlay
, Qhelp_echo
);
22189 help_echo_string
= help
;
22190 help_echo_window
= window
;
22191 help_echo_object
= overlay
;
22192 help_echo_pos
= pos
;
22196 Lisp_Object object
= glyph
->object
;
22197 int charpos
= glyph
->charpos
;
22199 /* Try text properties. */
22200 if (STRINGP (object
)
22202 && charpos
< SCHARS (object
))
22204 help
= Fget_text_property (make_number (charpos
),
22205 Qhelp_echo
, object
);
22208 /* If the string itself doesn't specify a help-echo,
22209 see if the buffer text ``under'' it does. */
22210 struct glyph_row
*r
22211 = MATRIX_ROW (w
->current_matrix
, vpos
);
22212 int start
= MATRIX_ROW_START_CHARPOS (r
);
22213 int pos
= string_buffer_position (w
, object
, start
);
22216 help
= Fget_char_property (make_number (pos
),
22217 Qhelp_echo
, w
->buffer
);
22221 object
= w
->buffer
;
22226 else if (BUFFERP (object
)
22229 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22234 help_echo_string
= help
;
22235 help_echo_window
= window
;
22236 help_echo_object
= object
;
22237 help_echo_pos
= charpos
;
22242 /* Look for a `pointer' property. */
22243 if (NILP (pointer
))
22245 /* Check overlays first. */
22246 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22247 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22249 if (NILP (pointer
))
22251 Lisp_Object object
= glyph
->object
;
22252 int charpos
= glyph
->charpos
;
22254 /* Try text properties. */
22255 if (STRINGP (object
)
22257 && charpos
< SCHARS (object
))
22259 pointer
= Fget_text_property (make_number (charpos
),
22261 if (NILP (pointer
))
22263 /* If the string itself doesn't specify a pointer,
22264 see if the buffer text ``under'' it does. */
22265 struct glyph_row
*r
22266 = MATRIX_ROW (w
->current_matrix
, vpos
);
22267 int start
= MATRIX_ROW_START_CHARPOS (r
);
22268 int pos
= string_buffer_position (w
, object
, start
);
22270 pointer
= Fget_char_property (make_number (pos
),
22271 Qpointer
, w
->buffer
);
22274 else if (BUFFERP (object
)
22277 pointer
= Fget_text_property (make_number (charpos
),
22284 current_buffer
= obuf
;
22289 define_frame_cursor1 (f
, cursor
, pointer
);
22294 Clear any mouse-face on window W. This function is part of the
22295 redisplay interface, and is called from try_window_id and similar
22296 functions to ensure the mouse-highlight is off. */
22299 x_clear_window_mouse_face (w
)
22302 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22303 Lisp_Object window
;
22306 XSETWINDOW (window
, w
);
22307 if (EQ (window
, dpyinfo
->mouse_face_window
))
22308 clear_mouse_face (dpyinfo
);
22314 Just discard the mouse face information for frame F, if any.
22315 This is used when the size of F is changed. */
22318 cancel_mouse_face (f
)
22321 Lisp_Object window
;
22322 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22324 window
= dpyinfo
->mouse_face_window
;
22325 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22327 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22328 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22329 dpyinfo
->mouse_face_window
= Qnil
;
22334 #endif /* HAVE_WINDOW_SYSTEM */
22337 /***********************************************************************
22339 ***********************************************************************/
22341 #ifdef HAVE_WINDOW_SYSTEM
22343 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22344 which intersects rectangle R. R is in window-relative coordinates. */
22347 expose_area (w
, row
, r
, area
)
22349 struct glyph_row
*row
;
22351 enum glyph_row_area area
;
22353 struct glyph
*first
= row
->glyphs
[area
];
22354 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22355 struct glyph
*last
;
22356 int first_x
, start_x
, x
;
22358 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22359 /* If row extends face to end of line write the whole line. */
22360 draw_glyphs (w
, 0, row
, area
,
22361 0, row
->used
[area
],
22362 DRAW_NORMAL_TEXT
, 0);
22365 /* Set START_X to the window-relative start position for drawing glyphs of
22366 AREA. The first glyph of the text area can be partially visible.
22367 The first glyphs of other areas cannot. */
22368 start_x
= window_box_left_offset (w
, area
);
22370 if (area
== TEXT_AREA
)
22373 /* Find the first glyph that must be redrawn. */
22375 && x
+ first
->pixel_width
< r
->x
)
22377 x
+= first
->pixel_width
;
22381 /* Find the last one. */
22385 && x
< r
->x
+ r
->width
)
22387 x
+= last
->pixel_width
;
22393 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22394 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22395 DRAW_NORMAL_TEXT
, 0);
22400 /* Redraw the parts of the glyph row ROW on window W intersecting
22401 rectangle R. R is in window-relative coordinates. Value is
22402 non-zero if mouse-face was overwritten. */
22405 expose_line (w
, row
, r
)
22407 struct glyph_row
*row
;
22410 xassert (row
->enabled_p
);
22412 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22413 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22414 0, row
->used
[TEXT_AREA
],
22415 DRAW_NORMAL_TEXT
, 0);
22418 if (row
->used
[LEFT_MARGIN_AREA
])
22419 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22420 if (row
->used
[TEXT_AREA
])
22421 expose_area (w
, row
, r
, TEXT_AREA
);
22422 if (row
->used
[RIGHT_MARGIN_AREA
])
22423 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22424 draw_row_fringe_bitmaps (w
, row
);
22427 return row
->mouse_face_p
;
22431 /* Redraw those parts of glyphs rows during expose event handling that
22432 overlap other rows. Redrawing of an exposed line writes over parts
22433 of lines overlapping that exposed line; this function fixes that.
22435 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22436 row in W's current matrix that is exposed and overlaps other rows.
22437 LAST_OVERLAPPING_ROW is the last such row. */
22440 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22442 struct glyph_row
*first_overlapping_row
;
22443 struct glyph_row
*last_overlapping_row
;
22445 struct glyph_row
*row
;
22447 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22448 if (row
->overlapping_p
)
22450 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22452 if (row
->used
[LEFT_MARGIN_AREA
])
22453 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
22455 if (row
->used
[TEXT_AREA
])
22456 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
22458 if (row
->used
[RIGHT_MARGIN_AREA
])
22459 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
22464 /* Return non-zero if W's cursor intersects rectangle R. */
22467 phys_cursor_in_rect_p (w
, r
)
22471 XRectangle cr
, result
;
22472 struct glyph
*cursor_glyph
;
22474 cursor_glyph
= get_phys_cursor_glyph (w
);
22477 /* r is relative to W's box, but w->phys_cursor.x is relative
22478 to left edge of W's TEXT area. Adjust it. */
22479 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22480 cr
.y
= w
->phys_cursor
.y
;
22481 cr
.width
= cursor_glyph
->pixel_width
;
22482 cr
.height
= w
->phys_cursor_height
;
22483 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22484 I assume the effect is the same -- and this is portable. */
22485 return x_intersect_rectangles (&cr
, r
, &result
);
22493 Draw a vertical window border to the right of window W if W doesn't
22494 have vertical scroll bars. */
22497 x_draw_vertical_border (w
)
22500 /* We could do better, if we knew what type of scroll-bar the adjacent
22501 windows (on either side) have... But we don't :-(
22502 However, I think this works ok. ++KFS 2003-04-25 */
22504 /* Redraw borders between horizontally adjacent windows. Don't
22505 do it for frames with vertical scroll bars because either the
22506 right scroll bar of a window, or the left scroll bar of its
22507 neighbor will suffice as a border. */
22508 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22511 if (!WINDOW_RIGHTMOST_P (w
)
22512 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22514 int x0
, x1
, y0
, y1
;
22516 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22519 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22522 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22524 else if (!WINDOW_LEFTMOST_P (w
)
22525 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22527 int x0
, x1
, y0
, y1
;
22529 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22532 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22535 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22540 /* Redraw the part of window W intersection rectangle FR. Pixel
22541 coordinates in FR are frame-relative. Call this function with
22542 input blocked. Value is non-zero if the exposure overwrites
22546 expose_window (w
, fr
)
22550 struct frame
*f
= XFRAME (w
->frame
);
22552 int mouse_face_overwritten_p
= 0;
22554 /* If window is not yet fully initialized, do nothing. This can
22555 happen when toolkit scroll bars are used and a window is split.
22556 Reconfiguring the scroll bar will generate an expose for a newly
22558 if (w
->current_matrix
== NULL
)
22561 /* When we're currently updating the window, display and current
22562 matrix usually don't agree. Arrange for a thorough display
22564 if (w
== updated_window
)
22566 SET_FRAME_GARBAGED (f
);
22570 /* Frame-relative pixel rectangle of W. */
22571 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22572 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22573 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22574 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22576 if (x_intersect_rectangles (fr
, &wr
, &r
))
22578 int yb
= window_text_bottom_y (w
);
22579 struct glyph_row
*row
;
22580 int cursor_cleared_p
;
22581 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22583 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22584 r
.x
, r
.y
, r
.width
, r
.height
));
22586 /* Convert to window coordinates. */
22587 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22588 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22590 /* Turn off the cursor. */
22591 if (!w
->pseudo_window_p
22592 && phys_cursor_in_rect_p (w
, &r
))
22594 x_clear_cursor (w
);
22595 cursor_cleared_p
= 1;
22598 cursor_cleared_p
= 0;
22600 /* Update lines intersecting rectangle R. */
22601 first_overlapping_row
= last_overlapping_row
= NULL
;
22602 for (row
= w
->current_matrix
->rows
;
22607 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22609 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22610 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22611 || (r
.y
>= y0
&& r
.y
< y1
)
22612 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22614 /* A header line may be overlapping, but there is no need
22615 to fix overlapping areas for them. KFS 2005-02-12 */
22616 if (row
->overlapping_p
&& !row
->mode_line_p
)
22618 if (first_overlapping_row
== NULL
)
22619 first_overlapping_row
= row
;
22620 last_overlapping_row
= row
;
22623 if (expose_line (w
, row
, &r
))
22624 mouse_face_overwritten_p
= 1;
22631 /* Display the mode line if there is one. */
22632 if (WINDOW_WANTS_MODELINE_P (w
)
22633 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22635 && row
->y
< r
.y
+ r
.height
)
22637 if (expose_line (w
, row
, &r
))
22638 mouse_face_overwritten_p
= 1;
22641 if (!w
->pseudo_window_p
)
22643 /* Fix the display of overlapping rows. */
22644 if (first_overlapping_row
)
22645 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22647 /* Draw border between windows. */
22648 x_draw_vertical_border (w
);
22650 /* Turn the cursor on again. */
22651 if (cursor_cleared_p
)
22652 update_window_cursor (w
, 1);
22656 return mouse_face_overwritten_p
;
22661 /* Redraw (parts) of all windows in the window tree rooted at W that
22662 intersect R. R contains frame pixel coordinates. Value is
22663 non-zero if the exposure overwrites mouse-face. */
22666 expose_window_tree (w
, r
)
22670 struct frame
*f
= XFRAME (w
->frame
);
22671 int mouse_face_overwritten_p
= 0;
22673 while (w
&& !FRAME_GARBAGED_P (f
))
22675 if (!NILP (w
->hchild
))
22676 mouse_face_overwritten_p
22677 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22678 else if (!NILP (w
->vchild
))
22679 mouse_face_overwritten_p
22680 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22682 mouse_face_overwritten_p
|= expose_window (w
, r
);
22684 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22687 return mouse_face_overwritten_p
;
22692 Redisplay an exposed area of frame F. X and Y are the upper-left
22693 corner of the exposed rectangle. W and H are width and height of
22694 the exposed area. All are pixel values. W or H zero means redraw
22695 the entire frame. */
22698 expose_frame (f
, x
, y
, w
, h
)
22703 int mouse_face_overwritten_p
= 0;
22705 TRACE ((stderr
, "expose_frame "));
22707 /* No need to redraw if frame will be redrawn soon. */
22708 if (FRAME_GARBAGED_P (f
))
22710 TRACE ((stderr
, " garbaged\n"));
22714 /* If basic faces haven't been realized yet, there is no point in
22715 trying to redraw anything. This can happen when we get an expose
22716 event while Emacs is starting, e.g. by moving another window. */
22717 if (FRAME_FACE_CACHE (f
) == NULL
22718 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22720 TRACE ((stderr
, " no faces\n"));
22724 if (w
== 0 || h
== 0)
22727 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22728 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22738 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22739 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22741 if (WINDOWP (f
->tool_bar_window
))
22742 mouse_face_overwritten_p
22743 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22745 #ifdef HAVE_X_WINDOWS
22747 #ifndef USE_X_TOOLKIT
22748 if (WINDOWP (f
->menu_bar_window
))
22749 mouse_face_overwritten_p
22750 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22751 #endif /* not USE_X_TOOLKIT */
22755 /* Some window managers support a focus-follows-mouse style with
22756 delayed raising of frames. Imagine a partially obscured frame,
22757 and moving the mouse into partially obscured mouse-face on that
22758 frame. The visible part of the mouse-face will be highlighted,
22759 then the WM raises the obscured frame. With at least one WM, KDE
22760 2.1, Emacs is not getting any event for the raising of the frame
22761 (even tried with SubstructureRedirectMask), only Expose events.
22762 These expose events will draw text normally, i.e. not
22763 highlighted. Which means we must redo the highlight here.
22764 Subsume it under ``we love X''. --gerd 2001-08-15 */
22765 /* Included in Windows version because Windows most likely does not
22766 do the right thing if any third party tool offers
22767 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22768 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22770 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22771 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22773 int x
= dpyinfo
->mouse_face_mouse_x
;
22774 int y
= dpyinfo
->mouse_face_mouse_y
;
22775 clear_mouse_face (dpyinfo
);
22776 note_mouse_highlight (f
, x
, y
);
22783 Determine the intersection of two rectangles R1 and R2. Return
22784 the intersection in *RESULT. Value is non-zero if RESULT is not
22788 x_intersect_rectangles (r1
, r2
, result
)
22789 XRectangle
*r1
, *r2
, *result
;
22791 XRectangle
*left
, *right
;
22792 XRectangle
*upper
, *lower
;
22793 int intersection_p
= 0;
22795 /* Rearrange so that R1 is the left-most rectangle. */
22797 left
= r1
, right
= r2
;
22799 left
= r2
, right
= r1
;
22801 /* X0 of the intersection is right.x0, if this is inside R1,
22802 otherwise there is no intersection. */
22803 if (right
->x
<= left
->x
+ left
->width
)
22805 result
->x
= right
->x
;
22807 /* The right end of the intersection is the minimum of the
22808 the right ends of left and right. */
22809 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22812 /* Same game for Y. */
22814 upper
= r1
, lower
= r2
;
22816 upper
= r2
, lower
= r1
;
22818 /* The upper end of the intersection is lower.y0, if this is inside
22819 of upper. Otherwise, there is no intersection. */
22820 if (lower
->y
<= upper
->y
+ upper
->height
)
22822 result
->y
= lower
->y
;
22824 /* The lower end of the intersection is the minimum of the lower
22825 ends of upper and lower. */
22826 result
->height
= (min (lower
->y
+ lower
->height
,
22827 upper
->y
+ upper
->height
)
22829 intersection_p
= 1;
22833 return intersection_p
;
22836 #endif /* HAVE_WINDOW_SYSTEM */
22839 /***********************************************************************
22841 ***********************************************************************/
22846 Vwith_echo_area_save_vector
= Qnil
;
22847 staticpro (&Vwith_echo_area_save_vector
);
22849 Vmessage_stack
= Qnil
;
22850 staticpro (&Vmessage_stack
);
22852 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22853 staticpro (&Qinhibit_redisplay
);
22855 message_dolog_marker1
= Fmake_marker ();
22856 staticpro (&message_dolog_marker1
);
22857 message_dolog_marker2
= Fmake_marker ();
22858 staticpro (&message_dolog_marker2
);
22859 message_dolog_marker3
= Fmake_marker ();
22860 staticpro (&message_dolog_marker3
);
22863 defsubr (&Sdump_frame_glyph_matrix
);
22864 defsubr (&Sdump_glyph_matrix
);
22865 defsubr (&Sdump_glyph_row
);
22866 defsubr (&Sdump_tool_bar_row
);
22867 defsubr (&Strace_redisplay
);
22868 defsubr (&Strace_to_stderr
);
22870 #ifdef HAVE_WINDOW_SYSTEM
22871 defsubr (&Stool_bar_lines_needed
);
22872 defsubr (&Slookup_image_map
);
22874 defsubr (&Sformat_mode_line
);
22876 staticpro (&Qmenu_bar_update_hook
);
22877 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22879 staticpro (&Qoverriding_terminal_local_map
);
22880 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22882 staticpro (&Qoverriding_local_map
);
22883 Qoverriding_local_map
= intern ("overriding-local-map");
22885 staticpro (&Qwindow_scroll_functions
);
22886 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22888 staticpro (&Qredisplay_end_trigger_functions
);
22889 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22891 staticpro (&Qinhibit_point_motion_hooks
);
22892 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22894 QCdata
= intern (":data");
22895 staticpro (&QCdata
);
22896 Qdisplay
= intern ("display");
22897 staticpro (&Qdisplay
);
22898 Qspace_width
= intern ("space-width");
22899 staticpro (&Qspace_width
);
22900 Qraise
= intern ("raise");
22901 staticpro (&Qraise
);
22902 Qslice
= intern ("slice");
22903 staticpro (&Qslice
);
22904 Qspace
= intern ("space");
22905 staticpro (&Qspace
);
22906 Qmargin
= intern ("margin");
22907 staticpro (&Qmargin
);
22908 Qpointer
= intern ("pointer");
22909 staticpro (&Qpointer
);
22910 Qleft_margin
= intern ("left-margin");
22911 staticpro (&Qleft_margin
);
22912 Qright_margin
= intern ("right-margin");
22913 staticpro (&Qright_margin
);
22914 Qcenter
= intern ("center");
22915 staticpro (&Qcenter
);
22916 Qline_height
= intern ("line-height");
22917 staticpro (&Qline_height
);
22918 QCalign_to
= intern (":align-to");
22919 staticpro (&QCalign_to
);
22920 QCrelative_width
= intern (":relative-width");
22921 staticpro (&QCrelative_width
);
22922 QCrelative_height
= intern (":relative-height");
22923 staticpro (&QCrelative_height
);
22924 QCeval
= intern (":eval");
22925 staticpro (&QCeval
);
22926 QCpropertize
= intern (":propertize");
22927 staticpro (&QCpropertize
);
22928 QCfile
= intern (":file");
22929 staticpro (&QCfile
);
22930 Qfontified
= intern ("fontified");
22931 staticpro (&Qfontified
);
22932 Qfontification_functions
= intern ("fontification-functions");
22933 staticpro (&Qfontification_functions
);
22934 Qtrailing_whitespace
= intern ("trailing-whitespace");
22935 staticpro (&Qtrailing_whitespace
);
22936 Qescape_glyph
= intern ("escape-glyph");
22937 staticpro (&Qescape_glyph
);
22938 Qnobreak_space
= intern ("nobreak-space");
22939 staticpro (&Qnobreak_space
);
22940 Qimage
= intern ("image");
22941 staticpro (&Qimage
);
22942 QCmap
= intern (":map");
22943 staticpro (&QCmap
);
22944 QCpointer
= intern (":pointer");
22945 staticpro (&QCpointer
);
22946 Qrect
= intern ("rect");
22947 staticpro (&Qrect
);
22948 Qcircle
= intern ("circle");
22949 staticpro (&Qcircle
);
22950 Qpoly
= intern ("poly");
22951 staticpro (&Qpoly
);
22952 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22953 staticpro (&Qmessage_truncate_lines
);
22954 Qgrow_only
= intern ("grow-only");
22955 staticpro (&Qgrow_only
);
22956 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22957 staticpro (&Qinhibit_menubar_update
);
22958 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22959 staticpro (&Qinhibit_eval_during_redisplay
);
22960 Qposition
= intern ("position");
22961 staticpro (&Qposition
);
22962 Qbuffer_position
= intern ("buffer-position");
22963 staticpro (&Qbuffer_position
);
22964 Qobject
= intern ("object");
22965 staticpro (&Qobject
);
22966 Qbar
= intern ("bar");
22968 Qhbar
= intern ("hbar");
22969 staticpro (&Qhbar
);
22970 Qbox
= intern ("box");
22972 Qhollow
= intern ("hollow");
22973 staticpro (&Qhollow
);
22974 Qhand
= intern ("hand");
22975 staticpro (&Qhand
);
22976 Qarrow
= intern ("arrow");
22977 staticpro (&Qarrow
);
22978 Qtext
= intern ("text");
22979 staticpro (&Qtext
);
22980 Qrisky_local_variable
= intern ("risky-local-variable");
22981 staticpro (&Qrisky_local_variable
);
22982 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22983 staticpro (&Qinhibit_free_realized_faces
);
22985 list_of_error
= Fcons (Fcons (intern ("error"),
22986 Fcons (intern ("void-variable"), Qnil
)),
22988 staticpro (&list_of_error
);
22990 Qlast_arrow_position
= intern ("last-arrow-position");
22991 staticpro (&Qlast_arrow_position
);
22992 Qlast_arrow_string
= intern ("last-arrow-string");
22993 staticpro (&Qlast_arrow_string
);
22995 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22996 staticpro (&Qoverlay_arrow_string
);
22997 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22998 staticpro (&Qoverlay_arrow_bitmap
);
23000 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
23001 staticpro (&echo_buffer
[0]);
23002 staticpro (&echo_buffer
[1]);
23004 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
23005 staticpro (&echo_area_buffer
[0]);
23006 staticpro (&echo_area_buffer
[1]);
23008 Vmessages_buffer_name
= build_string ("*Messages*");
23009 staticpro (&Vmessages_buffer_name
);
23011 mode_line_proptrans_alist
= Qnil
;
23012 staticpro (&mode_line_proptrans_alist
);
23013 mode_line_string_list
= Qnil
;
23014 staticpro (&mode_line_string_list
);
23015 mode_line_string_face
= Qnil
;
23016 staticpro (&mode_line_string_face
);
23017 mode_line_string_face_prop
= Qnil
;
23018 staticpro (&mode_line_string_face_prop
);
23019 Vmode_line_unwind_vector
= Qnil
;
23020 staticpro (&Vmode_line_unwind_vector
);
23022 help_echo_string
= Qnil
;
23023 staticpro (&help_echo_string
);
23024 help_echo_object
= Qnil
;
23025 staticpro (&help_echo_object
);
23026 help_echo_window
= Qnil
;
23027 staticpro (&help_echo_window
);
23028 previous_help_echo_string
= Qnil
;
23029 staticpro (&previous_help_echo_string
);
23030 help_echo_pos
= -1;
23032 #ifdef HAVE_WINDOW_SYSTEM
23033 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
23034 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
23035 For example, if a block cursor is over a tab, it will be drawn as
23036 wide as that tab on the display. */);
23037 x_stretch_cursor_p
= 0;
23040 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
23041 doc
: /* *Non-nil means highlight trailing whitespace.
23042 The face used for trailing whitespace is `trailing-whitespace'. */);
23043 Vshow_trailing_whitespace
= Qnil
;
23045 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
23046 doc
: /* *Control highlighting of nobreak space and soft hyphen.
23047 A value of t means highlight the character itself (for nobreak space,
23048 use face `nobreak-space').
23049 A value of nil means no highlighting.
23050 Other values mean display the escape glyph followed by an ordinary
23051 space or ordinary hyphen. */);
23052 Vnobreak_char_display
= Qt
;
23054 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
23055 doc
: /* *The pointer shape to show in void text areas.
23056 A value of nil means to show the text pointer. Other options are `arrow',
23057 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
23058 Vvoid_text_area_pointer
= Qarrow
;
23060 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
23061 doc
: /* Non-nil means don't actually do any redisplay.
23062 This is used for internal purposes. */);
23063 Vinhibit_redisplay
= Qnil
;
23065 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
23066 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
23067 Vglobal_mode_string
= Qnil
;
23069 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
23070 doc
: /* Marker for where to display an arrow on top of the buffer text.
23071 This must be the beginning of a line in order to work.
23072 See also `overlay-arrow-string'. */);
23073 Voverlay_arrow_position
= Qnil
;
23075 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23076 doc
: /* String to display as an arrow in non-window frames.
23077 See also `overlay-arrow-position'. */);
23078 Voverlay_arrow_string
= build_string ("=>");
23080 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23081 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23082 The symbols on this list are examined during redisplay to determine
23083 where to display overlay arrows. */);
23084 Voverlay_arrow_variable_list
23085 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23087 DEFVAR_INT ("scroll-step", &scroll_step
,
23088 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23089 If that fails to bring point back on frame, point is centered instead.
23090 If this is zero, point is always centered after it moves off frame.
23091 If you want scrolling to always be a line at a time, you should set
23092 `scroll-conservatively' to a large value rather than set this to 1. */);
23094 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23095 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23096 A value of zero means to scroll the text to center point vertically
23097 in the window. */);
23098 scroll_conservatively
= 0;
23100 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23101 doc
: /* *Number of lines of margin at the top and bottom of a window.
23102 Recenter the window whenever point gets within this many lines
23103 of the top or bottom of the window. */);
23106 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23107 doc
: /* Pixels per inch value for non-window system displays.
23108 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23109 Vdisplay_pixels_per_inch
= make_float (72.0);
23112 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23115 DEFVAR_BOOL ("truncate-partial-width-windows",
23116 &truncate_partial_width_windows
,
23117 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23118 truncate_partial_width_windows
= 1;
23120 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23121 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23122 Any other value means to use the appropriate face, `mode-line',
23123 `header-line', or `menu' respectively. */);
23124 mode_line_inverse_video
= 1;
23126 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23127 doc
: /* *Maximum buffer size for which line number should be displayed.
23128 If the buffer is bigger than this, the line number does not appear
23129 in the mode line. A value of nil means no limit. */);
23130 Vline_number_display_limit
= Qnil
;
23132 DEFVAR_INT ("line-number-display-limit-width",
23133 &line_number_display_limit_width
,
23134 doc
: /* *Maximum line width (in characters) for line number display.
23135 If the average length of the lines near point is bigger than this, then the
23136 line number may be omitted from the mode line. */);
23137 line_number_display_limit_width
= 200;
23139 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23140 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23141 highlight_nonselected_windows
= 0;
23143 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23144 doc
: /* Non-nil if more than one frame is visible on this display.
23145 Minibuffer-only frames don't count, but iconified frames do.
23146 This variable is not guaranteed to be accurate except while processing
23147 `frame-title-format' and `icon-title-format'. */);
23149 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23150 doc
: /* Template for displaying the title bar of visible frames.
23151 \(Assuming the window manager supports this feature.)
23152 This variable has the same structure as `mode-line-format' (which see),
23153 and is used only on frames for which no explicit name has been set
23154 \(see `modify-frame-parameters'). */);
23156 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23157 doc
: /* Template for displaying the title bar of an iconified frame.
23158 \(Assuming the window manager supports this feature.)
23159 This variable has the same structure as `mode-line-format' (which see),
23160 and is used only on frames for which no explicit name has been set
23161 \(see `modify-frame-parameters'). */);
23163 = Vframe_title_format
23164 = Fcons (intern ("multiple-frames"),
23165 Fcons (build_string ("%b"),
23166 Fcons (Fcons (empty_string
,
23167 Fcons (intern ("invocation-name"),
23168 Fcons (build_string ("@"),
23169 Fcons (intern ("system-name"),
23173 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23174 doc
: /* Maximum number of lines to keep in the message log buffer.
23175 If nil, disable message logging. If t, log messages but don't truncate
23176 the buffer when it becomes large. */);
23177 Vmessage_log_max
= make_number (50);
23179 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23180 doc
: /* Functions called before redisplay, if window sizes have changed.
23181 The value should be a list of functions that take one argument.
23182 Just before redisplay, for each frame, if any of its windows have changed
23183 size since the last redisplay, or have been split or deleted,
23184 all the functions in the list are called, with the frame as argument. */);
23185 Vwindow_size_change_functions
= Qnil
;
23187 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23188 doc
: /* List of functions to call before redisplaying a window with scrolling.
23189 Each function is called with two arguments, the window
23190 and its new display-start position. Note that the value of `window-end'
23191 is not valid when these functions are called. */);
23192 Vwindow_scroll_functions
= Qnil
;
23194 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
23195 doc
: /* Functions called when redisplay of a window reaches the end trigger.
23196 Each function is called with two arguments, the window and the end trigger value.
23197 See `set-window-redisplay-end-trigger'. */);
23198 Vredisplay_end_trigger_functions
= Qnil
;
23200 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23201 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23202 mouse_autoselect_window
= 0;
23204 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23205 doc
: /* *Non-nil means automatically resize tool-bars.
23206 This increases a tool-bar's height if not all tool-bar items are visible.
23207 It decreases a tool-bar's height when it would display blank lines
23209 auto_resize_tool_bars_p
= 1;
23211 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23212 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23213 auto_raise_tool_bar_buttons_p
= 1;
23215 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23216 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23217 make_cursor_line_fully_visible_p
= 1;
23219 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23220 doc
: /* *Margin around tool-bar buttons in pixels.
23221 If an integer, use that for both horizontal and vertical margins.
23222 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23223 HORZ specifying the horizontal margin, and VERT specifying the
23224 vertical margin. */);
23225 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23227 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23228 doc
: /* *Relief thickness of tool-bar buttons. */);
23229 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23231 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23232 doc
: /* List of functions to call to fontify regions of text.
23233 Each function is called with one argument POS. Functions must
23234 fontify a region starting at POS in the current buffer, and give
23235 fontified regions the property `fontified'. */);
23236 Vfontification_functions
= Qnil
;
23237 Fmake_variable_buffer_local (Qfontification_functions
);
23239 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23240 &unibyte_display_via_language_environment
,
23241 doc
: /* *Non-nil means display unibyte text according to language environment.
23242 Specifically this means that unibyte non-ASCII characters
23243 are displayed by converting them to the equivalent multibyte characters
23244 according to the current language environment. As a result, they are
23245 displayed according to the current fontset. */);
23246 unibyte_display_via_language_environment
= 0;
23248 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23249 doc
: /* *Maximum height for resizing mini-windows.
23250 If a float, it specifies a fraction of the mini-window frame's height.
23251 If an integer, it specifies a number of lines. */);
23252 Vmax_mini_window_height
= make_float (0.25);
23254 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23255 doc
: /* *How to resize mini-windows.
23256 A value of nil means don't automatically resize mini-windows.
23257 A value of t means resize them to fit the text displayed in them.
23258 A value of `grow-only', the default, means let mini-windows grow
23259 only, until their display becomes empty, at which point the windows
23260 go back to their normal size. */);
23261 Vresize_mini_windows
= Qgrow_only
;
23263 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23264 doc
: /* Alist specifying how to blink the cursor off.
23265 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23266 `cursor-type' frame-parameter or variable equals ON-STATE,
23267 comparing using `equal', Emacs uses OFF-STATE to specify
23268 how to blink it off. */);
23269 Vblink_cursor_alist
= Qnil
;
23271 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23272 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23273 automatic_hscrolling_p
= 1;
23275 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23276 doc
: /* *How many columns away from the window edge point is allowed to get
23277 before automatic hscrolling will horizontally scroll the window. */);
23278 hscroll_margin
= 5;
23280 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23281 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23282 When point is less than `automatic-hscroll-margin' columns from the window
23283 edge, automatic hscrolling will scroll the window by the amount of columns
23284 determined by this variable. If its value is a positive integer, scroll that
23285 many columns. If it's a positive floating-point number, it specifies the
23286 fraction of the window's width to scroll. If it's nil or zero, point will be
23287 centered horizontally after the scroll. Any other value, including negative
23288 numbers, are treated as if the value were zero.
23290 Automatic hscrolling always moves point outside the scroll margin, so if
23291 point was more than scroll step columns inside the margin, the window will
23292 scroll more than the value given by the scroll step.
23294 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23295 and `scroll-right' overrides this variable's effect. */);
23296 Vhscroll_step
= make_number (0);
23298 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23299 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23300 Bind this around calls to `message' to let it take effect. */);
23301 message_truncate_lines
= 0;
23303 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23304 doc
: /* Normal hook run to update the menu bar definitions.
23305 Redisplay runs this hook before it redisplays the menu bar.
23306 This is used to update submenus such as Buffers,
23307 whose contents depend on various data. */);
23308 Vmenu_bar_update_hook
= Qnil
;
23310 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23311 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23312 inhibit_menubar_update
= 0;
23314 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23315 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23316 inhibit_eval_during_redisplay
= 0;
23318 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23319 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23320 inhibit_free_realized_faces
= 0;
23323 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23324 doc
: /* Inhibit try_window_id display optimization. */);
23325 inhibit_try_window_id
= 0;
23327 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23328 doc
: /* Inhibit try_window_reusing display optimization. */);
23329 inhibit_try_window_reusing
= 0;
23331 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23332 doc
: /* Inhibit try_cursor_movement display optimization. */);
23333 inhibit_try_cursor_movement
= 0;
23334 #endif /* GLYPH_DEBUG */
23338 /* Initialize this module when Emacs starts. */
23343 Lisp_Object root_window
;
23344 struct window
*mini_w
;
23346 current_header_line_height
= current_mode_line_height
= -1;
23348 CHARPOS (this_line_start_pos
) = 0;
23350 mini_w
= XWINDOW (minibuf_window
);
23351 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23353 if (!noninteractive
)
23355 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23358 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23359 set_window_height (root_window
,
23360 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23362 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23363 set_window_height (minibuf_window
, 1, 0);
23365 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23366 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23368 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23369 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23370 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23372 /* The default ellipsis glyphs `...'. */
23373 for (i
= 0; i
< 3; ++i
)
23374 default_invis_vector
[i
] = make_number ('.');
23378 /* Allocate the buffer for frame titles.
23379 Also used for `format-mode-line'. */
23381 mode_line_noprop_buf
= (char *) xmalloc (size
);
23382 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23383 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23384 mode_line_target
= MODE_LINE_DISPLAY
;
23387 help_echo_showing_p
= 0;
23391 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23392 (do not change this comment) */