1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
181 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
203 #ifndef FRAME_X_OUTPUT
204 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
207 #define INFINITY 10000000
209 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
211 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
212 extern int pending_menu_activation
;
215 extern int interrupt_input
;
216 extern int command_loop_level
;
218 extern Lisp_Object do_mouse_tracking
;
220 extern int minibuffer_auto_raise
;
221 extern Lisp_Object Vminibuffer_list
;
223 extern Lisp_Object Qface
;
224 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
226 extern Lisp_Object Voverriding_local_map
;
227 extern Lisp_Object Voverriding_local_map_menu_flag
;
228 extern Lisp_Object Qmenu_item
;
229 extern Lisp_Object Qwhen
;
230 extern Lisp_Object Qhelp_echo
;
232 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
233 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
234 Lisp_Object Qredisplay_end_trigger_functions
;
235 Lisp_Object Qinhibit_point_motion_hooks
;
236 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
237 Lisp_Object Qfontified
;
238 Lisp_Object Qgrow_only
;
239 Lisp_Object Qinhibit_eval_during_redisplay
;
240 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
243 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
246 Lisp_Object Qarrow
, Qhand
, Qtext
;
248 Lisp_Object Qrisky_local_variable
;
250 /* Holds the list (error). */
251 Lisp_Object list_of_error
;
253 /* Functions called to fontify regions of text. */
255 Lisp_Object Vfontification_functions
;
256 Lisp_Object Qfontification_functions
;
258 /* Non-zero means automatically select any window when the mouse
259 cursor moves into it. */
260 int mouse_autoselect_window
;
262 /* Non-zero means draw tool bar buttons raised when the mouse moves
265 int auto_raise_tool_bar_buttons_p
;
267 /* Non-zero means to reposition window if cursor line is only partially visible. */
269 int make_cursor_line_fully_visible_p
;
271 /* Margin around tool bar buttons in pixels. */
273 Lisp_Object Vtool_bar_button_margin
;
275 /* Thickness of shadow to draw around tool bar buttons. */
277 EMACS_INT tool_bar_button_relief
;
279 /* Non-zero means automatically resize tool-bars so that all tool-bar
280 items are visible, and no blank lines remain. */
282 int auto_resize_tool_bars_p
;
284 /* Non-zero means draw block and hollow cursor as wide as the glyph
285 under it. For example, if a block cursor is over a tab, it will be
286 drawn as wide as that tab on the display. */
288 int x_stretch_cursor_p
;
290 /* Non-nil means don't actually do any redisplay. */
292 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
294 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
296 int inhibit_eval_during_redisplay
;
298 /* Names of text properties relevant for redisplay. */
300 Lisp_Object Qdisplay
;
301 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
303 /* Symbols used in text property values. */
305 Lisp_Object Vdisplay_pixels_per_inch
;
306 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
307 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
310 Lisp_Object Qmargin
, Qpointer
;
311 Lisp_Object Qline_height
;
312 extern Lisp_Object Qheight
;
313 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
314 extern Lisp_Object Qscroll_bar
;
315 extern Lisp_Object Qcursor
;
317 /* Non-nil means highlight trailing whitespace. */
319 Lisp_Object Vshow_trailing_whitespace
;
321 /* Non-nil means escape non-break space and hyphens. */
323 Lisp_Object Vnobreak_char_display
;
325 #ifdef HAVE_WINDOW_SYSTEM
326 extern Lisp_Object Voverflow_newline_into_fringe
;
328 /* Test if overflow newline into fringe. Called with iterator IT
329 at or past right window margin, and with IT->current_x set. */
331 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
332 (!NILP (Voverflow_newline_into_fringe) \
333 && FRAME_WINDOW_P (it->f) \
334 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
335 && it->current_x == it->last_visible_x)
337 #endif /* HAVE_WINDOW_SYSTEM */
339 /* Non-nil means show the text cursor in void text areas
340 i.e. in blank areas after eol and eob. This used to be
341 the default in 21.3. */
343 Lisp_Object Vvoid_text_area_pointer
;
345 /* Name of the face used to highlight trailing whitespace. */
347 Lisp_Object Qtrailing_whitespace
;
349 /* Name and number of the face used to highlight escape glyphs. */
351 Lisp_Object Qescape_glyph
;
353 /* Name and number of the face used to highlight non-breaking spaces. */
355 Lisp_Object Qnobreak_space
;
357 /* The symbol `image' which is the car of the lists used to represent
362 /* The image map types. */
363 Lisp_Object QCmap
, QCpointer
;
364 Lisp_Object Qrect
, Qcircle
, Qpoly
;
366 /* Non-zero means print newline to stdout before next mini-buffer
369 int noninteractive_need_newline
;
371 /* Non-zero means print newline to message log before next message. */
373 static int message_log_need_newline
;
375 /* Three markers that message_dolog uses.
376 It could allocate them itself, but that causes trouble
377 in handling memory-full errors. */
378 static Lisp_Object message_dolog_marker1
;
379 static Lisp_Object message_dolog_marker2
;
380 static Lisp_Object message_dolog_marker3
;
382 /* The buffer position of the first character appearing entirely or
383 partially on the line of the selected window which contains the
384 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
385 redisplay optimization in redisplay_internal. */
387 static struct text_pos this_line_start_pos
;
389 /* Number of characters past the end of the line above, including the
390 terminating newline. */
392 static struct text_pos this_line_end_pos
;
394 /* The vertical positions and the height of this line. */
396 static int this_line_vpos
;
397 static int this_line_y
;
398 static int this_line_pixel_height
;
400 /* X position at which this display line starts. Usually zero;
401 negative if first character is partially visible. */
403 static int this_line_start_x
;
405 /* Buffer that this_line_.* variables are referring to. */
407 static struct buffer
*this_line_buffer
;
409 /* Nonzero means truncate lines in all windows less wide than the
412 int truncate_partial_width_windows
;
414 /* A flag to control how to display unibyte 8-bit character. */
416 int unibyte_display_via_language_environment
;
418 /* Nonzero means we have more than one non-mini-buffer-only frame.
419 Not guaranteed to be accurate except while parsing
420 frame-title-format. */
424 Lisp_Object Vglobal_mode_string
;
427 /* List of variables (symbols) which hold markers for overlay arrows.
428 The symbols on this list are examined during redisplay to determine
429 where to display overlay arrows. */
431 Lisp_Object Voverlay_arrow_variable_list
;
433 /* Marker for where to display an arrow on top of the buffer text. */
435 Lisp_Object Voverlay_arrow_position
;
437 /* String to display for the arrow. Only used on terminal frames. */
439 Lisp_Object Voverlay_arrow_string
;
441 /* Values of those variables at last redisplay are stored as
442 properties on `overlay-arrow-position' symbol. However, if
443 Voverlay_arrow_position is a marker, last-arrow-position is its
444 numerical position. */
446 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
448 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
449 properties on a symbol in overlay-arrow-variable-list. */
451 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
453 /* Like mode-line-format, but for the title bar on a visible frame. */
455 Lisp_Object Vframe_title_format
;
457 /* Like mode-line-format, but for the title bar on an iconified frame. */
459 Lisp_Object Vicon_title_format
;
461 /* List of functions to call when a window's size changes. These
462 functions get one arg, a frame on which one or more windows' sizes
465 static Lisp_Object Vwindow_size_change_functions
;
467 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
469 /* Nonzero if an overlay arrow has been displayed in this window. */
471 static int overlay_arrow_seen
;
473 /* Nonzero means highlight the region even in nonselected windows. */
475 int highlight_nonselected_windows
;
477 /* If cursor motion alone moves point off frame, try scrolling this
478 many lines up or down if that will bring it back. */
480 static EMACS_INT scroll_step
;
482 /* Nonzero means scroll just far enough to bring point back on the
483 screen, when appropriate. */
485 static EMACS_INT scroll_conservatively
;
487 /* Recenter the window whenever point gets within this many lines of
488 the top or bottom of the window. This value is translated into a
489 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
490 that there is really a fixed pixel height scroll margin. */
492 EMACS_INT scroll_margin
;
494 /* Number of windows showing the buffer of the selected window (or
495 another buffer with the same base buffer). keyboard.c refers to
500 /* Vector containing glyphs for an ellipsis `...'. */
502 static Lisp_Object default_invis_vector
[3];
504 /* Zero means display the mode-line/header-line/menu-bar in the default face
505 (this slightly odd definition is for compatibility with previous versions
506 of emacs), non-zero means display them using their respective faces.
508 This variable is deprecated. */
510 int mode_line_inverse_video
;
512 /* Prompt to display in front of the mini-buffer contents. */
514 Lisp_Object minibuf_prompt
;
516 /* Width of current mini-buffer prompt. Only set after display_line
517 of the line that contains the prompt. */
519 int minibuf_prompt_width
;
521 /* This is the window where the echo area message was displayed. It
522 is always a mini-buffer window, but it may not be the same window
523 currently active as a mini-buffer. */
525 Lisp_Object echo_area_window
;
527 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
528 pushes the current message and the value of
529 message_enable_multibyte on the stack, the function restore_message
530 pops the stack and displays MESSAGE again. */
532 Lisp_Object Vmessage_stack
;
534 /* Nonzero means multibyte characters were enabled when the echo area
535 message was specified. */
537 int message_enable_multibyte
;
539 /* Nonzero if we should redraw the mode lines on the next redisplay. */
541 int update_mode_lines
;
543 /* Nonzero if window sizes or contents have changed since last
544 redisplay that finished. */
546 int windows_or_buffers_changed
;
548 /* Nonzero means a frame's cursor type has been changed. */
550 int cursor_type_changed
;
552 /* Nonzero after display_mode_line if %l was used and it displayed a
555 int line_number_displayed
;
557 /* Maximum buffer size for which to display line numbers. */
559 Lisp_Object Vline_number_display_limit
;
561 /* Line width to consider when repositioning for line number display. */
563 static EMACS_INT line_number_display_limit_width
;
565 /* Number of lines to keep in the message log buffer. t means
566 infinite. nil means don't log at all. */
568 Lisp_Object Vmessage_log_max
;
570 /* The name of the *Messages* buffer, a string. */
572 static Lisp_Object Vmessages_buffer_name
;
574 /* Index 0 is the buffer that holds the current (desired) echo area message,
575 or nil if none is desired right now.
577 Index 1 is the buffer that holds the previously displayed echo area message,
578 or nil to indicate no message. This is normally what's on the screen now.
580 These two can point to the same buffer. That happens when the last
581 message output by the user (or made by echoing) has been displayed. */
583 Lisp_Object echo_area_buffer
[2];
585 /* Permanent pointers to the two buffers that are used for echo area
586 purposes. Once the two buffers are made, and their pointers are
587 placed here, these two slots remain unchanged unless those buffers
588 need to be created afresh. */
590 static Lisp_Object echo_buffer
[2];
592 /* A vector saved used in with_area_buffer to reduce consing. */
594 static Lisp_Object Vwith_echo_area_save_vector
;
596 /* Non-zero means display_echo_area should display the last echo area
597 message again. Set by redisplay_preserve_echo_area. */
599 static int display_last_displayed_message_p
;
601 /* Nonzero if echo area is being used by print; zero if being used by
604 int message_buf_print
;
606 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
608 Lisp_Object Qinhibit_menubar_update
;
609 int inhibit_menubar_update
;
611 /* Maximum height for resizing mini-windows. Either a float
612 specifying a fraction of the available height, or an integer
613 specifying a number of lines. */
615 Lisp_Object Vmax_mini_window_height
;
617 /* Non-zero means messages should be displayed with truncated
618 lines instead of being continued. */
620 int message_truncate_lines
;
621 Lisp_Object Qmessage_truncate_lines
;
623 /* Set to 1 in clear_message to make redisplay_internal aware
624 of an emptied echo area. */
626 static int message_cleared_p
;
628 /* How to blink the default frame cursor off. */
629 Lisp_Object Vblink_cursor_alist
;
631 /* A scratch glyph row with contents used for generating truncation
632 glyphs. Also used in direct_output_for_insert. */
634 #define MAX_SCRATCH_GLYPHS 100
635 struct glyph_row scratch_glyph_row
;
636 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
638 /* Ascent and height of the last line processed by move_it_to. */
640 static int last_max_ascent
, last_height
;
642 /* Non-zero if there's a help-echo in the echo area. */
644 int help_echo_showing_p
;
646 /* If >= 0, computed, exact values of mode-line and header-line height
647 to use in the macros CURRENT_MODE_LINE_HEIGHT and
648 CURRENT_HEADER_LINE_HEIGHT. */
650 int current_mode_line_height
, current_header_line_height
;
652 /* The maximum distance to look ahead for text properties. Values
653 that are too small let us call compute_char_face and similar
654 functions too often which is expensive. Values that are too large
655 let us call compute_char_face and alike too often because we
656 might not be interested in text properties that far away. */
658 #define TEXT_PROP_DISTANCE_LIMIT 100
662 /* Variables to turn off display optimizations from Lisp. */
664 int inhibit_try_window_id
, inhibit_try_window_reusing
;
665 int inhibit_try_cursor_movement
;
667 /* Non-zero means print traces of redisplay if compiled with
670 int trace_redisplay_p
;
672 #endif /* GLYPH_DEBUG */
674 #ifdef DEBUG_TRACE_MOVE
675 /* Non-zero means trace with TRACE_MOVE to stderr. */
678 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
680 #define TRACE_MOVE(x) (void) 0
683 /* Non-zero means automatically scroll windows horizontally to make
686 int automatic_hscrolling_p
;
688 /* How close to the margin can point get before the window is scrolled
690 EMACS_INT hscroll_margin
;
692 /* How much to scroll horizontally when point is inside the above margin. */
693 Lisp_Object Vhscroll_step
;
695 /* The variable `resize-mini-windows'. If nil, don't resize
696 mini-windows. If t, always resize them to fit the text they
697 display. If `grow-only', let mini-windows grow only until they
700 Lisp_Object Vresize_mini_windows
;
702 /* Buffer being redisplayed -- for redisplay_window_error. */
704 struct buffer
*displayed_buffer
;
706 /* Value returned from text property handlers (see below). */
711 HANDLED_RECOMPUTE_PROPS
,
712 HANDLED_OVERLAY_STRING_CONSUMED
,
716 /* A description of text properties that redisplay is interested
721 /* The name of the property. */
724 /* A unique index for the property. */
727 /* A handler function called to set up iterator IT from the property
728 at IT's current position. Value is used to steer handle_stop. */
729 enum prop_handled (*handler
) P_ ((struct it
*it
));
732 static enum prop_handled handle_face_prop
P_ ((struct it
*));
733 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
734 static enum prop_handled handle_display_prop
P_ ((struct it
*));
735 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
736 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
737 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
739 /* Properties handled by iterators. */
741 static struct props it_props
[] =
743 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
744 /* Handle `face' before `display' because some sub-properties of
745 `display' need to know the face. */
746 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
747 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
748 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
749 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
753 /* Value is the position described by X. If X is a marker, value is
754 the marker_position of X. Otherwise, value is X. */
756 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
758 /* Enumeration returned by some move_it_.* functions internally. */
762 /* Not used. Undefined value. */
765 /* Move ended at the requested buffer position or ZV. */
766 MOVE_POS_MATCH_OR_ZV
,
768 /* Move ended at the requested X pixel position. */
771 /* Move within a line ended at the end of a line that must be
775 /* Move within a line ended at the end of a line that would
776 be displayed truncated. */
779 /* Move within a line ended at a line end. */
783 /* This counter is used to clear the face cache every once in a while
784 in redisplay_internal. It is incremented for each redisplay.
785 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
788 #define CLEAR_FACE_CACHE_COUNT 500
789 static int clear_face_cache_count
;
791 /* Similarly for the image cache. */
793 #ifdef HAVE_WINDOW_SYSTEM
794 #define CLEAR_IMAGE_CACHE_COUNT 101
795 static int clear_image_cache_count
;
798 /* Record the previous terminal frame we displayed. */
800 static struct frame
*previous_terminal_frame
;
802 /* Non-zero while redisplay_internal is in progress. */
806 /* Non-zero means don't free realized faces. Bound while freeing
807 realized faces is dangerous because glyph matrices might still
810 int inhibit_free_realized_faces
;
811 Lisp_Object Qinhibit_free_realized_faces
;
813 /* If a string, XTread_socket generates an event to display that string.
814 (The display is done in read_char.) */
816 Lisp_Object help_echo_string
;
817 Lisp_Object help_echo_window
;
818 Lisp_Object help_echo_object
;
821 /* Temporary variable for XTread_socket. */
823 Lisp_Object previous_help_echo_string
;
825 /* Null glyph slice */
827 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
830 /* Function prototypes. */
832 static void setup_for_ellipsis
P_ ((struct it
*, int));
833 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
834 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
835 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
836 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
837 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
838 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
841 static int invisible_text_between_p
P_ ((struct it
*, int, int));
844 static void pint2str
P_ ((char *, int, int));
845 static void pint2hrstr
P_ ((char *, int, int));
846 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
848 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
849 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
850 static void store_mode_line_noprop_char
P_ ((char));
851 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
852 static void x_consider_frame_title
P_ ((Lisp_Object
));
853 static void handle_stop
P_ ((struct it
*));
854 static int tool_bar_lines_needed
P_ ((struct frame
*));
855 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
856 static void ensure_echo_area_buffers
P_ ((void));
857 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
858 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
859 static int with_echo_area_buffer
P_ ((struct window
*, int,
860 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
861 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
862 static void clear_garbaged_frames
P_ ((void));
863 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
864 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
865 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
866 static int display_echo_area
P_ ((struct window
*));
867 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
868 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
869 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
870 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
871 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
873 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
874 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
875 static void insert_left_trunc_glyphs
P_ ((struct it
*));
876 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
878 static void extend_face_to_end_of_line
P_ ((struct it
*));
879 static int append_space_for_newline
P_ ((struct it
*, int));
880 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
881 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
882 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
883 static int trailing_whitespace_p
P_ ((int));
884 static int message_log_check_duplicate
P_ ((int, int, int, int));
885 static void push_it
P_ ((struct it
*));
886 static void pop_it
P_ ((struct it
*));
887 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
888 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
889 static void redisplay_internal
P_ ((int));
890 static int echo_area_display
P_ ((int));
891 static void redisplay_windows
P_ ((Lisp_Object
));
892 static void redisplay_window
P_ ((Lisp_Object
, int));
893 static Lisp_Object
redisplay_window_error ();
894 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
895 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
896 static void update_menu_bar
P_ ((struct frame
*, int));
897 static int try_window_reusing_current_matrix
P_ ((struct window
*));
898 static int try_window_id
P_ ((struct window
*));
899 static int display_line
P_ ((struct it
*));
900 static int display_mode_lines
P_ ((struct window
*));
901 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
902 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
903 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
904 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
905 static void display_menu_bar
P_ ((struct window
*));
906 static int display_count_lines
P_ ((int, int, int, int, int *));
907 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
908 int, int, struct it
*, int, int, int, int));
909 static void compute_line_metrics
P_ ((struct it
*));
910 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
911 static int get_overlay_strings
P_ ((struct it
*, int));
912 static void next_overlay_string
P_ ((struct it
*));
913 static void reseat
P_ ((struct it
*, struct text_pos
, int));
914 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
915 static void back_to_previous_visible_line_start
P_ ((struct it
*));
916 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
917 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
918 static int next_element_from_ellipsis
P_ ((struct it
*));
919 static int next_element_from_display_vector
P_ ((struct it
*));
920 static int next_element_from_string
P_ ((struct it
*));
921 static int next_element_from_c_string
P_ ((struct it
*));
922 static int next_element_from_buffer
P_ ((struct it
*));
923 static int next_element_from_composition
P_ ((struct it
*));
924 static int next_element_from_image
P_ ((struct it
*));
925 static int next_element_from_stretch
P_ ((struct it
*));
926 static void load_overlay_strings
P_ ((struct it
*, int));
927 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
928 struct display_pos
*));
929 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
930 Lisp_Object
, int, int, int, int));
931 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
933 void move_it_vertically_backward
P_ ((struct it
*, int));
934 static void init_to_row_start
P_ ((struct it
*, struct window
*,
935 struct glyph_row
*));
936 static int init_to_row_end
P_ ((struct it
*, struct window
*,
937 struct glyph_row
*));
938 static void back_to_previous_line_start
P_ ((struct it
*));
939 static int forward_to_next_line_start
P_ ((struct it
*, int *));
940 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
942 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
943 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
944 static int number_of_chars
P_ ((unsigned char *, int));
945 static void compute_stop_pos
P_ ((struct it
*));
946 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
948 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
949 static int next_overlay_change
P_ ((int));
950 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
951 Lisp_Object
, struct text_pos
*,
953 static int underlying_face_id
P_ ((struct it
*));
954 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
957 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
958 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
960 #ifdef HAVE_WINDOW_SYSTEM
962 static void update_tool_bar
P_ ((struct frame
*, int));
963 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
964 static int redisplay_tool_bar
P_ ((struct frame
*));
965 static void display_tool_bar_line
P_ ((struct it
*));
966 static void notice_overwritten_cursor
P_ ((struct window
*,
968 int, int, int, int));
972 #endif /* HAVE_WINDOW_SYSTEM */
975 /***********************************************************************
976 Window display dimensions
977 ***********************************************************************/
979 /* Return the bottom boundary y-position for text lines in window W.
980 This is the first y position at which a line cannot start.
981 It is relative to the top of the window.
983 This is the height of W minus the height of a mode line, if any. */
986 window_text_bottom_y (w
)
989 int height
= WINDOW_TOTAL_HEIGHT (w
);
991 if (WINDOW_WANTS_MODELINE_P (w
))
992 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
996 /* Return the pixel width of display area AREA of window W. AREA < 0
997 means return the total width of W, not including fringes to
998 the left and right of the window. */
1001 window_box_width (w
, area
)
1005 int cols
= XFASTINT (w
->total_cols
);
1008 if (!w
->pseudo_window_p
)
1010 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1012 if (area
== TEXT_AREA
)
1014 if (INTEGERP (w
->left_margin_cols
))
1015 cols
-= XFASTINT (w
->left_margin_cols
);
1016 if (INTEGERP (w
->right_margin_cols
))
1017 cols
-= XFASTINT (w
->right_margin_cols
);
1018 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1020 else if (area
== LEFT_MARGIN_AREA
)
1022 cols
= (INTEGERP (w
->left_margin_cols
)
1023 ? XFASTINT (w
->left_margin_cols
) : 0);
1026 else if (area
== RIGHT_MARGIN_AREA
)
1028 cols
= (INTEGERP (w
->right_margin_cols
)
1029 ? XFASTINT (w
->right_margin_cols
) : 0);
1034 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1038 /* Return the pixel height of the display area of window W, not
1039 including mode lines of W, if any. */
1042 window_box_height (w
)
1045 struct frame
*f
= XFRAME (w
->frame
);
1046 int height
= WINDOW_TOTAL_HEIGHT (w
);
1048 xassert (height
>= 0);
1050 /* Note: the code below that determines the mode-line/header-line
1051 height is essentially the same as that contained in the macro
1052 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1053 the appropriate glyph row has its `mode_line_p' flag set,
1054 and if it doesn't, uses estimate_mode_line_height instead. */
1056 if (WINDOW_WANTS_MODELINE_P (w
))
1058 struct glyph_row
*ml_row
1059 = (w
->current_matrix
&& w
->current_matrix
->rows
1060 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1062 if (ml_row
&& ml_row
->mode_line_p
)
1063 height
-= ml_row
->height
;
1065 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1068 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1070 struct glyph_row
*hl_row
1071 = (w
->current_matrix
&& w
->current_matrix
->rows
1072 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1074 if (hl_row
&& hl_row
->mode_line_p
)
1075 height
-= hl_row
->height
;
1077 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1080 /* With a very small font and a mode-line that's taller than
1081 default, we might end up with a negative height. */
1082 return max (0, height
);
1085 /* Return the window-relative coordinate of the left edge of display
1086 area AREA of window W. AREA < 0 means return the left edge of the
1087 whole window, to the right of the left fringe of W. */
1090 window_box_left_offset (w
, area
)
1096 if (w
->pseudo_window_p
)
1099 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1101 if (area
== TEXT_AREA
)
1102 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1103 + window_box_width (w
, LEFT_MARGIN_AREA
));
1104 else if (area
== RIGHT_MARGIN_AREA
)
1105 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1106 + window_box_width (w
, LEFT_MARGIN_AREA
)
1107 + window_box_width (w
, TEXT_AREA
)
1108 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1110 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1111 else if (area
== LEFT_MARGIN_AREA
1112 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1113 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1119 /* Return the window-relative coordinate of the right edge of display
1120 area AREA of window W. AREA < 0 means return the left edge of the
1121 whole window, to the left of the right fringe of W. */
1124 window_box_right_offset (w
, area
)
1128 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1131 /* Return the frame-relative coordinate of the left edge of display
1132 area AREA of window W. AREA < 0 means return the left edge of the
1133 whole window, to the right of the left fringe of W. */
1136 window_box_left (w
, area
)
1140 struct frame
*f
= XFRAME (w
->frame
);
1143 if (w
->pseudo_window_p
)
1144 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1146 x
= (WINDOW_LEFT_EDGE_X (w
)
1147 + window_box_left_offset (w
, area
));
1153 /* Return the frame-relative coordinate of the right edge of display
1154 area AREA of window W. AREA < 0 means return the left edge of the
1155 whole window, to the left of the right fringe of W. */
1158 window_box_right (w
, area
)
1162 return window_box_left (w
, area
) + window_box_width (w
, area
);
1165 /* Get the bounding box of the display area AREA of window W, without
1166 mode lines, in frame-relative coordinates. AREA < 0 means the
1167 whole window, not including the left and right fringes of
1168 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1169 coordinates of the upper-left corner of the box. Return in
1170 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1173 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1176 int *box_x
, *box_y
, *box_width
, *box_height
;
1179 *box_width
= window_box_width (w
, area
);
1181 *box_height
= window_box_height (w
);
1183 *box_x
= window_box_left (w
, area
);
1186 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1187 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1188 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1193 /* Get the bounding box of the display area AREA of window W, without
1194 mode lines. AREA < 0 means the whole window, not including the
1195 left and right fringe of the window. Return in *TOP_LEFT_X
1196 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1197 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1198 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1202 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1203 bottom_right_x
, bottom_right_y
)
1206 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1208 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1210 *bottom_right_x
+= *top_left_x
;
1211 *bottom_right_y
+= *top_left_y
;
1216 /***********************************************************************
1218 ***********************************************************************/
1220 /* Return the bottom y-position of the line the iterator IT is in.
1221 This can modify IT's settings. */
1227 int line_height
= it
->max_ascent
+ it
->max_descent
;
1228 int line_top_y
= it
->current_y
;
1230 if (line_height
== 0)
1233 line_height
= last_height
;
1234 else if (IT_CHARPOS (*it
) < ZV
)
1236 move_it_by_lines (it
, 1, 1);
1237 line_height
= (it
->max_ascent
|| it
->max_descent
1238 ? it
->max_ascent
+ it
->max_descent
1243 struct glyph_row
*row
= it
->glyph_row
;
1245 /* Use the default character height. */
1246 it
->glyph_row
= NULL
;
1247 it
->what
= IT_CHARACTER
;
1250 PRODUCE_GLYPHS (it
);
1251 line_height
= it
->ascent
+ it
->descent
;
1252 it
->glyph_row
= row
;
1256 return line_top_y
+ line_height
;
1260 /* Return 1 if position CHARPOS is visible in window W.
1261 If visible, set *X and *Y to pixel coordinates of top left corner.
1262 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1263 EXACT_MODE_LINE_HEIGHTS_P non-zero means compute exact mode-line
1264 and header-lines heights. */
1267 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, exact_mode_line_heights_p
)
1269 int charpos
, *x
, *y
, *rtop
, *rbot
, exact_mode_line_heights_p
;
1272 struct text_pos top
;
1274 struct buffer
*old_buffer
= NULL
;
1279 if (XBUFFER (w
->buffer
) != current_buffer
)
1281 old_buffer
= current_buffer
;
1282 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1285 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1287 /* Compute exact mode line heights, if requested. */
1288 if (exact_mode_line_heights_p
)
1290 if (WINDOW_WANTS_MODELINE_P (w
))
1291 current_mode_line_height
1292 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1293 current_buffer
->mode_line_format
);
1295 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1296 current_header_line_height
1297 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1298 current_buffer
->header_line_format
);
1301 start_display (&it
, w
, top
);
1302 move_it_to (&it
, charpos
, -1, it
.last_visible_y
, -1,
1303 MOVE_TO_POS
| MOVE_TO_Y
);
1305 /* Note that we may overshoot because of invisible text. */
1306 if (IT_CHARPOS (it
) >= charpos
)
1308 int top_x
= it
.current_x
;
1309 int top_y
= it
.current_y
;
1310 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1311 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1313 if (top_y
< window_top_y
)
1314 visible_p
= bottom_y
> window_top_y
;
1315 else if (top_y
< it
.last_visible_y
)
1320 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1321 *rtop
= max (0, window_top_y
- top_y
);
1322 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1330 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1331 move_it_by_lines (&it
, 1, 0);
1332 if (charpos
< IT_CHARPOS (it
))
1335 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1337 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1338 *rtop
= max (0, -it2
.current_y
);
1339 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1340 - it
.last_visible_y
));
1345 set_buffer_internal_1 (old_buffer
);
1347 current_header_line_height
= current_mode_line_height
= -1;
1353 /* Return the next character from STR which is MAXLEN bytes long.
1354 Return in *LEN the length of the character. This is like
1355 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1356 we find one, we return a `?', but with the length of the invalid
1360 string_char_and_length (str
, maxlen
, len
)
1361 const unsigned char *str
;
1366 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1367 if (!CHAR_VALID_P (c
, 1))
1368 /* We may not change the length here because other places in Emacs
1369 don't use this function, i.e. they silently accept invalid
1378 /* Given a position POS containing a valid character and byte position
1379 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1381 static struct text_pos
1382 string_pos_nchars_ahead (pos
, string
, nchars
)
1383 struct text_pos pos
;
1387 xassert (STRINGP (string
) && nchars
>= 0);
1389 if (STRING_MULTIBYTE (string
))
1391 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1392 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1397 string_char_and_length (p
, rest
, &len
);
1398 p
+= len
, rest
-= len
;
1399 xassert (rest
>= 0);
1401 BYTEPOS (pos
) += len
;
1405 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1411 /* Value is the text position, i.e. character and byte position,
1412 for character position CHARPOS in STRING. */
1414 static INLINE
struct text_pos
1415 string_pos (charpos
, string
)
1419 struct text_pos pos
;
1420 xassert (STRINGP (string
));
1421 xassert (charpos
>= 0);
1422 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1427 /* Value is a text position, i.e. character and byte position, for
1428 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1429 means recognize multibyte characters. */
1431 static struct text_pos
1432 c_string_pos (charpos
, s
, multibyte_p
)
1437 struct text_pos pos
;
1439 xassert (s
!= NULL
);
1440 xassert (charpos
>= 0);
1444 int rest
= strlen (s
), len
;
1446 SET_TEXT_POS (pos
, 0, 0);
1449 string_char_and_length (s
, rest
, &len
);
1450 s
+= len
, rest
-= len
;
1451 xassert (rest
>= 0);
1453 BYTEPOS (pos
) += len
;
1457 SET_TEXT_POS (pos
, charpos
, charpos
);
1463 /* Value is the number of characters in C string S. MULTIBYTE_P
1464 non-zero means recognize multibyte characters. */
1467 number_of_chars (s
, multibyte_p
)
1475 int rest
= strlen (s
), len
;
1476 unsigned char *p
= (unsigned char *) s
;
1478 for (nchars
= 0; rest
> 0; ++nchars
)
1480 string_char_and_length (p
, rest
, &len
);
1481 rest
-= len
, p
+= len
;
1485 nchars
= strlen (s
);
1491 /* Compute byte position NEWPOS->bytepos corresponding to
1492 NEWPOS->charpos. POS is a known position in string STRING.
1493 NEWPOS->charpos must be >= POS.charpos. */
1496 compute_string_pos (newpos
, pos
, string
)
1497 struct text_pos
*newpos
, pos
;
1500 xassert (STRINGP (string
));
1501 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1503 if (STRING_MULTIBYTE (string
))
1504 *newpos
= string_pos_nchars_ahead (pos
, string
,
1505 CHARPOS (*newpos
) - CHARPOS (pos
));
1507 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1511 Return an estimation of the pixel height of mode or top lines on
1512 frame F. FACE_ID specifies what line's height to estimate. */
1515 estimate_mode_line_height (f
, face_id
)
1517 enum face_id face_id
;
1519 #ifdef HAVE_WINDOW_SYSTEM
1520 if (FRAME_WINDOW_P (f
))
1522 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1524 /* This function is called so early when Emacs starts that the face
1525 cache and mode line face are not yet initialized. */
1526 if (FRAME_FACE_CACHE (f
))
1528 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1532 height
= FONT_HEIGHT (face
->font
);
1533 if (face
->box_line_width
> 0)
1534 height
+= 2 * face
->box_line_width
;
1545 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1546 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1547 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1548 not force the value into range. */
1551 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1553 register int pix_x
, pix_y
;
1555 NativeRectangle
*bounds
;
1559 #ifdef HAVE_WINDOW_SYSTEM
1560 if (FRAME_WINDOW_P (f
))
1562 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1563 even for negative values. */
1565 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1567 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1569 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1570 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1573 STORE_NATIVE_RECT (*bounds
,
1574 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1575 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1576 FRAME_COLUMN_WIDTH (f
) - 1,
1577 FRAME_LINE_HEIGHT (f
) - 1);
1583 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1584 pix_x
= FRAME_TOTAL_COLS (f
);
1588 else if (pix_y
> FRAME_LINES (f
))
1589 pix_y
= FRAME_LINES (f
);
1599 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1600 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1601 can't tell the positions because W's display is not up to date,
1605 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1608 int *frame_x
, *frame_y
;
1610 #ifdef HAVE_WINDOW_SYSTEM
1611 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1615 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1616 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1618 if (display_completed
)
1620 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1621 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1622 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1628 hpos
+= glyph
->pixel_width
;
1632 /* If first glyph is partially visible, its first visible position is still 0. */
1644 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1645 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1656 #ifdef HAVE_WINDOW_SYSTEM
1658 /* Find the glyph under window-relative coordinates X/Y in window W.
1659 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1660 strings. Return in *HPOS and *VPOS the row and column number of
1661 the glyph found. Return in *AREA the glyph area containing X.
1662 Value is a pointer to the glyph found or null if X/Y is not on
1663 text, or we can't tell because W's current matrix is not up to
1666 static struct glyph
*
1667 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1670 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1672 struct glyph
*glyph
, *end
;
1673 struct glyph_row
*row
= NULL
;
1676 /* Find row containing Y. Give up if some row is not enabled. */
1677 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1679 row
= MATRIX_ROW (w
->current_matrix
, i
);
1680 if (!row
->enabled_p
)
1682 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1689 /* Give up if Y is not in the window. */
1690 if (i
== w
->current_matrix
->nrows
)
1693 /* Get the glyph area containing X. */
1694 if (w
->pseudo_window_p
)
1701 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1703 *area
= LEFT_MARGIN_AREA
;
1704 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1706 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1709 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1713 *area
= RIGHT_MARGIN_AREA
;
1714 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1718 /* Find glyph containing X. */
1719 glyph
= row
->glyphs
[*area
];
1720 end
= glyph
+ row
->used
[*area
];
1722 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1724 x
-= glyph
->pixel_width
;
1734 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1737 *hpos
= glyph
- row
->glyphs
[*area
];
1743 Convert frame-relative x/y to coordinates relative to window W.
1744 Takes pseudo-windows into account. */
1747 frame_to_window_pixel_xy (w
, x
, y
)
1751 if (w
->pseudo_window_p
)
1753 /* A pseudo-window is always full-width, and starts at the
1754 left edge of the frame, plus a frame border. */
1755 struct frame
*f
= XFRAME (w
->frame
);
1756 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1757 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1761 *x
-= WINDOW_LEFT_EDGE_X (w
);
1762 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1767 Return in *R the clipping rectangle for glyph string S. */
1770 get_glyph_string_clip_rect (s
, nr
)
1771 struct glyph_string
*s
;
1772 NativeRectangle
*nr
;
1776 if (s
->row
->full_width_p
)
1778 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1779 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1780 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1782 /* Unless displaying a mode or menu bar line, which are always
1783 fully visible, clip to the visible part of the row. */
1784 if (s
->w
->pseudo_window_p
)
1785 r
.height
= s
->row
->visible_height
;
1787 r
.height
= s
->height
;
1791 /* This is a text line that may be partially visible. */
1792 r
.x
= window_box_left (s
->w
, s
->area
);
1793 r
.width
= window_box_width (s
->w
, s
->area
);
1794 r
.height
= s
->row
->visible_height
;
1798 if (r
.x
< s
->clip_head
->x
)
1800 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1801 r
.width
-= s
->clip_head
->x
- r
.x
;
1804 r
.x
= s
->clip_head
->x
;
1807 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1809 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1810 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1815 /* If S draws overlapping rows, it's sufficient to use the top and
1816 bottom of the window for clipping because this glyph string
1817 intentionally draws over other lines. */
1818 if (s
->for_overlaps_p
)
1820 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1821 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1825 /* Don't use S->y for clipping because it doesn't take partially
1826 visible lines into account. For example, it can be negative for
1827 partially visible lines at the top of a window. */
1828 if (!s
->row
->full_width_p
1829 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1830 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1832 r
.y
= max (0, s
->row
->y
);
1834 /* If drawing a tool-bar window, draw it over the internal border
1835 at the top of the window. */
1836 if (WINDOWP (s
->f
->tool_bar_window
)
1837 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1838 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1841 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1843 /* If drawing the cursor, don't let glyph draw outside its
1844 advertised boundaries. Cleartype does this under some circumstances. */
1845 if (s
->hl
== DRAW_CURSOR
)
1847 struct glyph
*glyph
= s
->first_glyph
;
1852 r
.width
-= s
->x
- r
.x
;
1855 r
.width
= min (r
.width
, glyph
->pixel_width
);
1857 /* If r.y is below window bottom, ensure that we still see a cursor. */
1858 height
= min (glyph
->ascent
+ glyph
->descent
,
1859 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1860 max_y
= window_text_bottom_y (s
->w
) - height
;
1861 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1862 if (s
->ybase
- glyph
->ascent
> max_y
)
1869 /* Don't draw cursor glyph taller than our actual glyph. */
1870 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1871 if (height
< r
.height
)
1873 max_y
= r
.y
+ r
.height
;
1874 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1875 r
.height
= min (max_y
- r
.y
, height
);
1880 #ifdef CONVERT_FROM_XRECT
1881 CONVERT_FROM_XRECT (r
, *nr
);
1889 Return the position and height of the phys cursor in window W.
1890 Set w->phys_cursor_width to width of phys cursor.
1894 get_phys_cursor_geometry (w
, row
, glyph
, heightp
)
1896 struct glyph_row
*row
;
1897 struct glyph
*glyph
;
1900 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1901 int y
, wd
, h
, h0
, y0
;
1903 /* Compute the width of the rectangle to draw. If on a stretch
1904 glyph, and `x-stretch-block-cursor' is nil, don't draw a
1905 rectangle as wide as the glyph, but use a canonical character
1907 wd
= glyph
->pixel_width
- 1;
1911 if (glyph
->type
== STRETCH_GLYPH
1912 && !x_stretch_cursor_p
)
1913 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
1914 w
->phys_cursor_width
= wd
;
1916 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
1918 /* If y is below window bottom, ensure that we still see a cursor. */
1919 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
1921 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
1922 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
1924 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
1927 h
= max (h
- (y0
- y
) + 1, h0
);
1932 y0
= window_text_bottom_y (w
) - h0
;
1941 return WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
1945 #endif /* HAVE_WINDOW_SYSTEM */
1948 /***********************************************************************
1949 Lisp form evaluation
1950 ***********************************************************************/
1952 /* Error handler for safe_eval and safe_call. */
1955 safe_eval_handler (arg
)
1958 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
1963 /* Evaluate SEXPR and return the result, or nil if something went
1964 wrong. Prevent redisplay during the evaluation. */
1972 if (inhibit_eval_during_redisplay
)
1976 int count
= SPECPDL_INDEX ();
1977 struct gcpro gcpro1
;
1980 specbind (Qinhibit_redisplay
, Qt
);
1981 /* Use Qt to ensure debugger does not run,
1982 so there is no possibility of wanting to redisplay. */
1983 val
= internal_condition_case_1 (Feval
, sexpr
, Qt
,
1986 val
= unbind_to (count
, val
);
1993 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
1994 Return the result, or nil if something went wrong. Prevent
1995 redisplay during the evaluation. */
1998 safe_call (nargs
, args
)
2004 if (inhibit_eval_during_redisplay
)
2008 int count
= SPECPDL_INDEX ();
2009 struct gcpro gcpro1
;
2012 gcpro1
.nvars
= nargs
;
2013 specbind (Qinhibit_redisplay
, Qt
);
2014 /* Use Qt to ensure debugger does not run,
2015 so there is no possibility of wanting to redisplay. */
2016 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2019 val
= unbind_to (count
, val
);
2026 /* Call function FN with one argument ARG.
2027 Return the result, or nil if something went wrong. */
2030 safe_call1 (fn
, arg
)
2031 Lisp_Object fn
, arg
;
2033 Lisp_Object args
[2];
2036 return safe_call (2, args
);
2041 /***********************************************************************
2043 ***********************************************************************/
2047 /* Define CHECK_IT to perform sanity checks on iterators.
2048 This is for debugging. It is too slow to do unconditionally. */
2054 if (it
->method
== GET_FROM_STRING
)
2056 xassert (STRINGP (it
->string
));
2057 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2061 xassert (IT_STRING_CHARPOS (*it
) < 0);
2062 if (it
->method
== GET_FROM_BUFFER
)
2064 /* Check that character and byte positions agree. */
2065 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2070 xassert (it
->current
.dpvec_index
>= 0);
2072 xassert (it
->current
.dpvec_index
< 0);
2075 #define CHECK_IT(IT) check_it ((IT))
2079 #define CHECK_IT(IT) (void) 0
2086 /* Check that the window end of window W is what we expect it
2087 to be---the last row in the current matrix displaying text. */
2090 check_window_end (w
)
2093 if (!MINI_WINDOW_P (w
)
2094 && !NILP (w
->window_end_valid
))
2096 struct glyph_row
*row
;
2097 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2098 XFASTINT (w
->window_end_vpos
)),
2100 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2101 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2105 #define CHECK_WINDOW_END(W) check_window_end ((W))
2107 #else /* not GLYPH_DEBUG */
2109 #define CHECK_WINDOW_END(W) (void) 0
2111 #endif /* not GLYPH_DEBUG */
2115 /***********************************************************************
2116 Iterator initialization
2117 ***********************************************************************/
2119 /* Initialize IT for displaying current_buffer in window W, starting
2120 at character position CHARPOS. CHARPOS < 0 means that no buffer
2121 position is specified which is useful when the iterator is assigned
2122 a position later. BYTEPOS is the byte position corresponding to
2123 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2125 If ROW is not null, calls to produce_glyphs with IT as parameter
2126 will produce glyphs in that row.
2128 BASE_FACE_ID is the id of a base face to use. It must be one of
2129 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2130 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2131 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2133 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2134 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2135 will be initialized to use the corresponding mode line glyph row of
2136 the desired matrix of W. */
2139 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2142 int charpos
, bytepos
;
2143 struct glyph_row
*row
;
2144 enum face_id base_face_id
;
2146 int highlight_region_p
;
2148 /* Some precondition checks. */
2149 xassert (w
!= NULL
&& it
!= NULL
);
2150 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2153 /* If face attributes have been changed since the last redisplay,
2154 free realized faces now because they depend on face definitions
2155 that might have changed. Don't free faces while there might be
2156 desired matrices pending which reference these faces. */
2157 if (face_change_count
&& !inhibit_free_realized_faces
)
2159 face_change_count
= 0;
2160 free_all_realized_faces (Qnil
);
2163 /* Use one of the mode line rows of W's desired matrix if
2167 if (base_face_id
== MODE_LINE_FACE_ID
2168 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2169 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2170 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2171 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2175 bzero (it
, sizeof *it
);
2176 it
->current
.overlay_string_index
= -1;
2177 it
->current
.dpvec_index
= -1;
2178 it
->base_face_id
= base_face_id
;
2180 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2182 /* The window in which we iterate over current_buffer: */
2183 XSETWINDOW (it
->window
, w
);
2185 it
->f
= XFRAME (w
->frame
);
2187 /* Extra space between lines (on window systems only). */
2188 if (base_face_id
== DEFAULT_FACE_ID
2189 && FRAME_WINDOW_P (it
->f
))
2191 if (NATNUMP (current_buffer
->extra_line_spacing
))
2192 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2193 else if (FLOATP (current_buffer
->extra_line_spacing
))
2194 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2195 * FRAME_LINE_HEIGHT (it
->f
));
2196 else if (it
->f
->extra_line_spacing
> 0)
2197 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2198 it
->max_extra_line_spacing
= 0;
2201 /* If realized faces have been removed, e.g. because of face
2202 attribute changes of named faces, recompute them. When running
2203 in batch mode, the face cache of Vterminal_frame is null. If
2204 we happen to get called, make a dummy face cache. */
2205 if (noninteractive
&& FRAME_FACE_CACHE (it
->f
) == NULL
)
2206 init_frame_faces (it
->f
);
2207 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2208 recompute_basic_faces (it
->f
);
2210 /* Current value of the `slice', `space-width', and 'height' properties. */
2211 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2212 it
->space_width
= Qnil
;
2213 it
->font_height
= Qnil
;
2214 it
->override_ascent
= -1;
2216 /* Are control characters displayed as `^C'? */
2217 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2219 /* -1 means everything between a CR and the following line end
2220 is invisible. >0 means lines indented more than this value are
2222 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2223 ? XFASTINT (current_buffer
->selective_display
)
2224 : (!NILP (current_buffer
->selective_display
)
2226 it
->selective_display_ellipsis_p
2227 = !NILP (current_buffer
->selective_display_ellipses
);
2229 /* Display table to use. */
2230 it
->dp
= window_display_table (w
);
2232 /* Are multibyte characters enabled in current_buffer? */
2233 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2235 /* Non-zero if we should highlight the region. */
2237 = (!NILP (Vtransient_mark_mode
)
2238 && !NILP (current_buffer
->mark_active
)
2239 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2241 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2242 start and end of a visible region in window IT->w. Set both to
2243 -1 to indicate no region. */
2244 if (highlight_region_p
2245 /* Maybe highlight only in selected window. */
2246 && (/* Either show region everywhere. */
2247 highlight_nonselected_windows
2248 /* Or show region in the selected window. */
2249 || w
== XWINDOW (selected_window
)
2250 /* Or show the region if we are in the mini-buffer and W is
2251 the window the mini-buffer refers to. */
2252 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2253 && WINDOWP (minibuf_selected_window
)
2254 && w
== XWINDOW (minibuf_selected_window
))))
2256 int charpos
= marker_position (current_buffer
->mark
);
2257 it
->region_beg_charpos
= min (PT
, charpos
);
2258 it
->region_end_charpos
= max (PT
, charpos
);
2261 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2263 /* Get the position at which the redisplay_end_trigger hook should
2264 be run, if it is to be run at all. */
2265 if (MARKERP (w
->redisplay_end_trigger
)
2266 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2267 it
->redisplay_end_trigger_charpos
2268 = marker_position (w
->redisplay_end_trigger
);
2269 else if (INTEGERP (w
->redisplay_end_trigger
))
2270 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2272 /* Correct bogus values of tab_width. */
2273 it
->tab_width
= XINT (current_buffer
->tab_width
);
2274 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2277 /* Are lines in the display truncated? */
2278 it
->truncate_lines_p
2279 = (base_face_id
!= DEFAULT_FACE_ID
2280 || XINT (it
->w
->hscroll
)
2281 || (truncate_partial_width_windows
2282 && !WINDOW_FULL_WIDTH_P (it
->w
))
2283 || !NILP (current_buffer
->truncate_lines
));
2285 /* Get dimensions of truncation and continuation glyphs. These are
2286 displayed as fringe bitmaps under X, so we don't need them for such
2288 if (!FRAME_WINDOW_P (it
->f
))
2290 if (it
->truncate_lines_p
)
2292 /* We will need the truncation glyph. */
2293 xassert (it
->glyph_row
== NULL
);
2294 produce_special_glyphs (it
, IT_TRUNCATION
);
2295 it
->truncation_pixel_width
= it
->pixel_width
;
2299 /* We will need the continuation glyph. */
2300 xassert (it
->glyph_row
== NULL
);
2301 produce_special_glyphs (it
, IT_CONTINUATION
);
2302 it
->continuation_pixel_width
= it
->pixel_width
;
2305 /* Reset these values to zero because the produce_special_glyphs
2306 above has changed them. */
2307 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2308 it
->phys_ascent
= it
->phys_descent
= 0;
2311 /* Set this after getting the dimensions of truncation and
2312 continuation glyphs, so that we don't produce glyphs when calling
2313 produce_special_glyphs, above. */
2314 it
->glyph_row
= row
;
2315 it
->area
= TEXT_AREA
;
2317 /* Get the dimensions of the display area. The display area
2318 consists of the visible window area plus a horizontally scrolled
2319 part to the left of the window. All x-values are relative to the
2320 start of this total display area. */
2321 if (base_face_id
!= DEFAULT_FACE_ID
)
2323 /* Mode lines, menu bar in terminal frames. */
2324 it
->first_visible_x
= 0;
2325 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2330 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2331 it
->last_visible_x
= (it
->first_visible_x
2332 + window_box_width (w
, TEXT_AREA
));
2334 /* If we truncate lines, leave room for the truncator glyph(s) at
2335 the right margin. Otherwise, leave room for the continuation
2336 glyph(s). Truncation and continuation glyphs are not inserted
2337 for window-based redisplay. */
2338 if (!FRAME_WINDOW_P (it
->f
))
2340 if (it
->truncate_lines_p
)
2341 it
->last_visible_x
-= it
->truncation_pixel_width
;
2343 it
->last_visible_x
-= it
->continuation_pixel_width
;
2346 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2347 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2350 /* Leave room for a border glyph. */
2351 if (!FRAME_WINDOW_P (it
->f
)
2352 && !WINDOW_RIGHTMOST_P (it
->w
))
2353 it
->last_visible_x
-= 1;
2355 it
->last_visible_y
= window_text_bottom_y (w
);
2357 /* For mode lines and alike, arrange for the first glyph having a
2358 left box line if the face specifies a box. */
2359 if (base_face_id
!= DEFAULT_FACE_ID
)
2363 it
->face_id
= base_face_id
;
2365 /* If we have a boxed mode line, make the first character appear
2366 with a left box line. */
2367 face
= FACE_FROM_ID (it
->f
, base_face_id
);
2368 if (face
->box
!= FACE_NO_BOX
)
2369 it
->start_of_box_run_p
= 1;
2372 /* If a buffer position was specified, set the iterator there,
2373 getting overlays and face properties from that position. */
2374 if (charpos
>= BUF_BEG (current_buffer
))
2376 it
->end_charpos
= ZV
;
2378 IT_CHARPOS (*it
) = charpos
;
2380 /* Compute byte position if not specified. */
2381 if (bytepos
< charpos
)
2382 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2384 IT_BYTEPOS (*it
) = bytepos
;
2386 it
->start
= it
->current
;
2388 /* Compute faces etc. */
2389 reseat (it
, it
->current
.pos
, 1);
2396 /* Initialize IT for the display of window W with window start POS. */
2399 start_display (it
, w
, pos
)
2402 struct text_pos pos
;
2404 struct glyph_row
*row
;
2405 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2407 row
= w
->desired_matrix
->rows
+ first_vpos
;
2408 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2409 it
->first_vpos
= first_vpos
;
2411 if (!it
->truncate_lines_p
)
2413 int start_at_line_beg_p
;
2414 int first_y
= it
->current_y
;
2416 /* If window start is not at a line start, skip forward to POS to
2417 get the correct continuation lines width. */
2418 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2419 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2420 if (!start_at_line_beg_p
)
2424 reseat_at_previous_visible_line_start (it
);
2425 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2427 new_x
= it
->current_x
+ it
->pixel_width
;
2429 /* If lines are continued, this line may end in the middle
2430 of a multi-glyph character (e.g. a control character
2431 displayed as \003, or in the middle of an overlay
2432 string). In this case move_it_to above will not have
2433 taken us to the start of the continuation line but to the
2434 end of the continued line. */
2435 if (it
->current_x
> 0
2436 && !it
->truncate_lines_p
/* Lines are continued. */
2437 && (/* And glyph doesn't fit on the line. */
2438 new_x
> it
->last_visible_x
2439 /* Or it fits exactly and we're on a window
2441 || (new_x
== it
->last_visible_x
2442 && FRAME_WINDOW_P (it
->f
))))
2444 if (it
->current
.dpvec_index
>= 0
2445 || it
->current
.overlay_string_index
>= 0)
2447 set_iterator_to_next (it
, 1);
2448 move_it_in_display_line_to (it
, -1, -1, 0);
2451 it
->continuation_lines_width
+= it
->current_x
;
2454 /* We're starting a new display line, not affected by the
2455 height of the continued line, so clear the appropriate
2456 fields in the iterator structure. */
2457 it
->max_ascent
= it
->max_descent
= 0;
2458 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2460 it
->current_y
= first_y
;
2462 it
->current_x
= it
->hpos
= 0;
2466 #if 0 /* Don't assert the following because start_display is sometimes
2467 called intentionally with a window start that is not at a
2468 line start. Please leave this code in as a comment. */
2470 /* Window start should be on a line start, now. */
2471 xassert (it
->continuation_lines_width
2472 || IT_CHARPOS (it
) == BEGV
2473 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2478 /* Return 1 if POS is a position in ellipses displayed for invisible
2479 text. W is the window we display, for text property lookup. */
2482 in_ellipses_for_invisible_text_p (pos
, w
)
2483 struct display_pos
*pos
;
2486 Lisp_Object prop
, window
;
2488 int charpos
= CHARPOS (pos
->pos
);
2490 /* If POS specifies a position in a display vector, this might
2491 be for an ellipsis displayed for invisible text. We won't
2492 get the iterator set up for delivering that ellipsis unless
2493 we make sure that it gets aware of the invisible text. */
2494 if (pos
->dpvec_index
>= 0
2495 && pos
->overlay_string_index
< 0
2496 && CHARPOS (pos
->string_pos
) < 0
2498 && (XSETWINDOW (window
, w
),
2499 prop
= Fget_char_property (make_number (charpos
),
2500 Qinvisible
, window
),
2501 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2503 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2505 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2512 /* Initialize IT for stepping through current_buffer in window W,
2513 starting at position POS that includes overlay string and display
2514 vector/ control character translation position information. Value
2515 is zero if there are overlay strings with newlines at POS. */
2518 init_from_display_pos (it
, w
, pos
)
2521 struct display_pos
*pos
;
2523 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2524 int i
, overlay_strings_with_newlines
= 0;
2526 /* If POS specifies a position in a display vector, this might
2527 be for an ellipsis displayed for invisible text. We won't
2528 get the iterator set up for delivering that ellipsis unless
2529 we make sure that it gets aware of the invisible text. */
2530 if (in_ellipses_for_invisible_text_p (pos
, w
))
2536 /* Keep in mind: the call to reseat in init_iterator skips invisible
2537 text, so we might end up at a position different from POS. This
2538 is only a problem when POS is a row start after a newline and an
2539 overlay starts there with an after-string, and the overlay has an
2540 invisible property. Since we don't skip invisible text in
2541 display_line and elsewhere immediately after consuming the
2542 newline before the row start, such a POS will not be in a string,
2543 but the call to init_iterator below will move us to the
2545 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2547 /* This only scans the current chunk -- it should scan all chunks.
2548 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2549 to 16 in 22.1 to make this a lesser problem. */
2550 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2552 const char *s
= SDATA (it
->overlay_strings
[i
]);
2553 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2555 while (s
< e
&& *s
!= '\n')
2560 overlay_strings_with_newlines
= 1;
2565 /* If position is within an overlay string, set up IT to the right
2567 if (pos
->overlay_string_index
>= 0)
2571 /* If the first overlay string happens to have a `display'
2572 property for an image, the iterator will be set up for that
2573 image, and we have to undo that setup first before we can
2574 correct the overlay string index. */
2575 if (it
->method
== GET_FROM_IMAGE
)
2578 /* We already have the first chunk of overlay strings in
2579 IT->overlay_strings. Load more until the one for
2580 pos->overlay_string_index is in IT->overlay_strings. */
2581 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2583 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2584 it
->current
.overlay_string_index
= 0;
2587 load_overlay_strings (it
, 0);
2588 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2592 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2593 relative_index
= (it
->current
.overlay_string_index
2594 % OVERLAY_STRING_CHUNK_SIZE
);
2595 it
->string
= it
->overlay_strings
[relative_index
];
2596 xassert (STRINGP (it
->string
));
2597 it
->current
.string_pos
= pos
->string_pos
;
2598 it
->method
= GET_FROM_STRING
;
2601 #if 0 /* This is bogus because POS not having an overlay string
2602 position does not mean it's after the string. Example: A
2603 line starting with a before-string and initialization of IT
2604 to the previous row's end position. */
2605 else if (it
->current
.overlay_string_index
>= 0)
2607 /* If POS says we're already after an overlay string ending at
2608 POS, make sure to pop the iterator because it will be in
2609 front of that overlay string. When POS is ZV, we've thereby
2610 also ``processed'' overlay strings at ZV. */
2613 it
->current
.overlay_string_index
= -1;
2614 it
->method
= GET_FROM_BUFFER
;
2615 if (CHARPOS (pos
->pos
) == ZV
)
2616 it
->overlay_strings_at_end_processed_p
= 1;
2620 if (CHARPOS (pos
->string_pos
) >= 0)
2622 /* Recorded position is not in an overlay string, but in another
2623 string. This can only be a string from a `display' property.
2624 IT should already be filled with that string. */
2625 it
->current
.string_pos
= pos
->string_pos
;
2626 xassert (STRINGP (it
->string
));
2629 /* Restore position in display vector translations, control
2630 character translations or ellipses. */
2631 if (pos
->dpvec_index
>= 0)
2633 if (it
->dpvec
== NULL
)
2634 get_next_display_element (it
);
2635 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2636 it
->current
.dpvec_index
= pos
->dpvec_index
;
2640 return !overlay_strings_with_newlines
;
2644 /* Initialize IT for stepping through current_buffer in window W
2645 starting at ROW->start. */
2648 init_to_row_start (it
, w
, row
)
2651 struct glyph_row
*row
;
2653 init_from_display_pos (it
, w
, &row
->start
);
2654 it
->start
= row
->start
;
2655 it
->continuation_lines_width
= row
->continuation_lines_width
;
2660 /* Initialize IT for stepping through current_buffer in window W
2661 starting in the line following ROW, i.e. starting at ROW->end.
2662 Value is zero if there are overlay strings with newlines at ROW's
2666 init_to_row_end (it
, w
, row
)
2669 struct glyph_row
*row
;
2673 if (init_from_display_pos (it
, w
, &row
->end
))
2675 if (row
->continued_p
)
2676 it
->continuation_lines_width
2677 = row
->continuation_lines_width
+ row
->pixel_width
;
2688 /***********************************************************************
2690 ***********************************************************************/
2692 /* Called when IT reaches IT->stop_charpos. Handle text property and
2693 overlay changes. Set IT->stop_charpos to the next position where
2700 enum prop_handled handled
;
2701 int handle_overlay_change_p
= 1;
2705 it
->current
.dpvec_index
= -1;
2707 /* Use face of preceding text for ellipsis (if invisible) */
2708 if (it
->selective_display_ellipsis_p
)
2709 it
->saved_face_id
= it
->face_id
;
2713 handled
= HANDLED_NORMALLY
;
2715 /* Call text property handlers. */
2716 for (p
= it_props
; p
->handler
; ++p
)
2718 handled
= p
->handler (it
);
2720 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2722 else if (handled
== HANDLED_RETURN
)
2724 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2725 handle_overlay_change_p
= 0;
2728 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2730 /* Don't check for overlay strings below when set to deliver
2731 characters from a display vector. */
2732 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2733 handle_overlay_change_p
= 0;
2735 /* Handle overlay changes. */
2736 if (handle_overlay_change_p
)
2737 handled
= handle_overlay_change (it
);
2739 /* Determine where to stop next. */
2740 if (handled
== HANDLED_NORMALLY
)
2741 compute_stop_pos (it
);
2744 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2748 /* Compute IT->stop_charpos from text property and overlay change
2749 information for IT's current position. */
2752 compute_stop_pos (it
)
2755 register INTERVAL iv
, next_iv
;
2756 Lisp_Object object
, limit
, position
;
2758 /* If nowhere else, stop at the end. */
2759 it
->stop_charpos
= it
->end_charpos
;
2761 if (STRINGP (it
->string
))
2763 /* Strings are usually short, so don't limit the search for
2765 object
= it
->string
;
2767 position
= make_number (IT_STRING_CHARPOS (*it
));
2773 /* If next overlay change is in front of the current stop pos
2774 (which is IT->end_charpos), stop there. Note: value of
2775 next_overlay_change is point-max if no overlay change
2777 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2778 if (charpos
< it
->stop_charpos
)
2779 it
->stop_charpos
= charpos
;
2781 /* If showing the region, we have to stop at the region
2782 start or end because the face might change there. */
2783 if (it
->region_beg_charpos
> 0)
2785 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2786 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2787 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2788 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2791 /* Set up variables for computing the stop position from text
2792 property changes. */
2793 XSETBUFFER (object
, current_buffer
);
2794 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2795 position
= make_number (IT_CHARPOS (*it
));
2799 /* Get the interval containing IT's position. Value is a null
2800 interval if there isn't such an interval. */
2801 iv
= validate_interval_range (object
, &position
, &position
, 0);
2802 if (!NULL_INTERVAL_P (iv
))
2804 Lisp_Object values_here
[LAST_PROP_IDX
];
2807 /* Get properties here. */
2808 for (p
= it_props
; p
->handler
; ++p
)
2809 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2811 /* Look for an interval following iv that has different
2813 for (next_iv
= next_interval (iv
);
2814 (!NULL_INTERVAL_P (next_iv
)
2816 || XFASTINT (limit
) > next_iv
->position
));
2817 next_iv
= next_interval (next_iv
))
2819 for (p
= it_props
; p
->handler
; ++p
)
2821 Lisp_Object new_value
;
2823 new_value
= textget (next_iv
->plist
, *p
->name
);
2824 if (!EQ (values_here
[p
->idx
], new_value
))
2832 if (!NULL_INTERVAL_P (next_iv
))
2834 if (INTEGERP (limit
)
2835 && next_iv
->position
>= XFASTINT (limit
))
2836 /* No text property change up to limit. */
2837 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2839 /* Text properties change in next_iv. */
2840 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2844 xassert (STRINGP (it
->string
)
2845 || (it
->stop_charpos
>= BEGV
2846 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2850 /* Return the position of the next overlay change after POS in
2851 current_buffer. Value is point-max if no overlay change
2852 follows. This is like `next-overlay-change' but doesn't use
2856 next_overlay_change (pos
)
2861 Lisp_Object
*overlays
;
2864 /* Get all overlays at the given position. */
2865 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2867 /* If any of these overlays ends before endpos,
2868 use its ending point instead. */
2869 for (i
= 0; i
< noverlays
; ++i
)
2874 oend
= OVERLAY_END (overlays
[i
]);
2875 oendpos
= OVERLAY_POSITION (oend
);
2876 endpos
= min (endpos
, oendpos
);
2884 /***********************************************************************
2886 ***********************************************************************/
2888 /* Handle changes in the `fontified' property of the current buffer by
2889 calling hook functions from Qfontification_functions to fontify
2892 static enum prop_handled
2893 handle_fontified_prop (it
)
2896 Lisp_Object prop
, pos
;
2897 enum prop_handled handled
= HANDLED_NORMALLY
;
2899 /* Get the value of the `fontified' property at IT's current buffer
2900 position. (The `fontified' property doesn't have a special
2901 meaning in strings.) If the value is nil, call functions from
2902 Qfontification_functions. */
2903 if (!STRINGP (it
->string
)
2905 && !NILP (Vfontification_functions
)
2906 && !NILP (Vrun_hooks
)
2907 && (pos
= make_number (IT_CHARPOS (*it
)),
2908 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2911 int count
= SPECPDL_INDEX ();
2914 val
= Vfontification_functions
;
2915 specbind (Qfontification_functions
, Qnil
);
2917 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2918 safe_call1 (val
, pos
);
2921 Lisp_Object globals
, fn
;
2922 struct gcpro gcpro1
, gcpro2
;
2925 GCPRO2 (val
, globals
);
2927 for (; CONSP (val
); val
= XCDR (val
))
2933 /* A value of t indicates this hook has a local
2934 binding; it means to run the global binding too.
2935 In a global value, t should not occur. If it
2936 does, we must ignore it to avoid an endless
2938 for (globals
= Fdefault_value (Qfontification_functions
);
2940 globals
= XCDR (globals
))
2942 fn
= XCAR (globals
);
2944 safe_call1 (fn
, pos
);
2948 safe_call1 (fn
, pos
);
2954 unbind_to (count
, Qnil
);
2956 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2957 something. This avoids an endless loop if they failed to
2958 fontify the text for which reason ever. */
2959 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2960 handled
= HANDLED_RECOMPUTE_PROPS
;
2968 /***********************************************************************
2970 ***********************************************************************/
2972 /* Set up iterator IT from face properties at its current position.
2973 Called from handle_stop. */
2975 static enum prop_handled
2976 handle_face_prop (it
)
2979 int new_face_id
, next_stop
;
2981 if (!STRINGP (it
->string
))
2984 = face_at_buffer_position (it
->w
,
2986 it
->region_beg_charpos
,
2987 it
->region_end_charpos
,
2990 + TEXT_PROP_DISTANCE_LIMIT
),
2993 /* Is this a start of a run of characters with box face?
2994 Caveat: this can be called for a freshly initialized
2995 iterator; face_id is -1 in this case. We know that the new
2996 face will not change until limit, i.e. if the new face has a
2997 box, all characters up to limit will have one. But, as
2998 usual, we don't know whether limit is really the end. */
2999 if (new_face_id
!= it
->face_id
)
3001 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3003 /* If new face has a box but old face has not, this is
3004 the start of a run of characters with box, i.e. it has
3005 a shadow on the left side. The value of face_id of the
3006 iterator will be -1 if this is the initial call that gets
3007 the face. In this case, we have to look in front of IT's
3008 position and see whether there is a face != new_face_id. */
3009 it
->start_of_box_run_p
3010 = (new_face
->box
!= FACE_NO_BOX
3011 && (it
->face_id
>= 0
3012 || IT_CHARPOS (*it
) == BEG
3013 || new_face_id
!= face_before_it_pos (it
)));
3014 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3019 int base_face_id
, bufpos
;
3021 if (it
->current
.overlay_string_index
>= 0)
3022 bufpos
= IT_CHARPOS (*it
);
3026 /* For strings from a buffer, i.e. overlay strings or strings
3027 from a `display' property, use the face at IT's current
3028 buffer position as the base face to merge with, so that
3029 overlay strings appear in the same face as surrounding
3030 text, unless they specify their own faces. */
3031 base_face_id
= underlying_face_id (it
);
3033 new_face_id
= face_at_string_position (it
->w
,
3035 IT_STRING_CHARPOS (*it
),
3037 it
->region_beg_charpos
,
3038 it
->region_end_charpos
,
3042 #if 0 /* This shouldn't be neccessary. Let's check it. */
3043 /* If IT is used to display a mode line we would really like to
3044 use the mode line face instead of the frame's default face. */
3045 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3046 && new_face_id
== DEFAULT_FACE_ID
)
3047 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3050 /* Is this a start of a run of characters with box? Caveat:
3051 this can be called for a freshly allocated iterator; face_id
3052 is -1 is this case. We know that the new face will not
3053 change until the next check pos, i.e. if the new face has a
3054 box, all characters up to that position will have a
3055 box. But, as usual, we don't know whether that position
3056 is really the end. */
3057 if (new_face_id
!= it
->face_id
)
3059 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3060 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3062 /* If new face has a box but old face hasn't, this is the
3063 start of a run of characters with box, i.e. it has a
3064 shadow on the left side. */
3065 it
->start_of_box_run_p
3066 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3067 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3071 it
->face_id
= new_face_id
;
3072 return HANDLED_NORMALLY
;
3076 /* Return the ID of the face ``underlying'' IT's current position,
3077 which is in a string. If the iterator is associated with a
3078 buffer, return the face at IT's current buffer position.
3079 Otherwise, use the iterator's base_face_id. */
3082 underlying_face_id (it
)
3085 int face_id
= it
->base_face_id
, i
;
3087 xassert (STRINGP (it
->string
));
3089 for (i
= it
->sp
- 1; i
>= 0; --i
)
3090 if (NILP (it
->stack
[i
].string
))
3091 face_id
= it
->stack
[i
].face_id
;
3097 /* Compute the face one character before or after the current position
3098 of IT. BEFORE_P non-zero means get the face in front of IT's
3099 position. Value is the id of the face. */
3102 face_before_or_after_it_pos (it
, before_p
)
3107 int next_check_charpos
;
3108 struct text_pos pos
;
3110 xassert (it
->s
== NULL
);
3112 if (STRINGP (it
->string
))
3114 int bufpos
, base_face_id
;
3116 /* No face change past the end of the string (for the case
3117 we are padding with spaces). No face change before the
3119 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3120 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3123 /* Set pos to the position before or after IT's current position. */
3125 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3127 /* For composition, we must check the character after the
3129 pos
= (it
->what
== IT_COMPOSITION
3130 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3131 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3133 if (it
->current
.overlay_string_index
>= 0)
3134 bufpos
= IT_CHARPOS (*it
);
3138 base_face_id
= underlying_face_id (it
);
3140 /* Get the face for ASCII, or unibyte. */
3141 face_id
= face_at_string_position (it
->w
,
3145 it
->region_beg_charpos
,
3146 it
->region_end_charpos
,
3147 &next_check_charpos
,
3150 /* Correct the face for charsets different from ASCII. Do it
3151 for the multibyte case only. The face returned above is
3152 suitable for unibyte text if IT->string is unibyte. */
3153 if (STRING_MULTIBYTE (it
->string
))
3155 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3156 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3158 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3160 c
= string_char_and_length (p
, rest
, &len
);
3161 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3166 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3167 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3170 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3171 pos
= it
->current
.pos
;
3174 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3177 if (it
->what
== IT_COMPOSITION
)
3178 /* For composition, we must check the position after the
3180 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3182 INC_TEXT_POS (pos
, it
->multibyte_p
);
3185 /* Determine face for CHARSET_ASCII, or unibyte. */
3186 face_id
= face_at_buffer_position (it
->w
,
3188 it
->region_beg_charpos
,
3189 it
->region_end_charpos
,
3190 &next_check_charpos
,
3193 /* Correct the face for charsets different from ASCII. Do it
3194 for the multibyte case only. The face returned above is
3195 suitable for unibyte text if current_buffer is unibyte. */
3196 if (it
->multibyte_p
)
3198 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3199 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3200 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3209 /***********************************************************************
3211 ***********************************************************************/
3213 /* Set up iterator IT from invisible properties at its current
3214 position. Called from handle_stop. */
3216 static enum prop_handled
3217 handle_invisible_prop (it
)
3220 enum prop_handled handled
= HANDLED_NORMALLY
;
3222 if (STRINGP (it
->string
))
3224 extern Lisp_Object Qinvisible
;
3225 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3227 /* Get the value of the invisible text property at the
3228 current position. Value will be nil if there is no such
3230 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3231 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3234 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3236 handled
= HANDLED_RECOMPUTE_PROPS
;
3238 /* Get the position at which the next change of the
3239 invisible text property can be found in IT->string.
3240 Value will be nil if the property value is the same for
3241 all the rest of IT->string. */
3242 XSETINT (limit
, SCHARS (it
->string
));
3243 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3246 /* Text at current position is invisible. The next
3247 change in the property is at position end_charpos.
3248 Move IT's current position to that position. */
3249 if (INTEGERP (end_charpos
)
3250 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3252 struct text_pos old
;
3253 old
= it
->current
.string_pos
;
3254 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3255 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3259 /* The rest of the string is invisible. If this is an
3260 overlay string, proceed with the next overlay string
3261 or whatever comes and return a character from there. */
3262 if (it
->current
.overlay_string_index
>= 0)
3264 next_overlay_string (it
);
3265 /* Don't check for overlay strings when we just
3266 finished processing them. */
3267 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3271 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3272 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3279 int invis_p
, newpos
, next_stop
, start_charpos
;
3280 Lisp_Object pos
, prop
, overlay
;
3282 /* First of all, is there invisible text at this position? */
3283 start_charpos
= IT_CHARPOS (*it
);
3284 pos
= make_number (IT_CHARPOS (*it
));
3285 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3287 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3289 /* If we are on invisible text, skip over it. */
3290 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3292 /* Record whether we have to display an ellipsis for the
3294 int display_ellipsis_p
= invis_p
== 2;
3296 handled
= HANDLED_RECOMPUTE_PROPS
;
3298 /* Loop skipping over invisible text. The loop is left at
3299 ZV or with IT on the first char being visible again. */
3302 /* Try to skip some invisible text. Return value is the
3303 position reached which can be equal to IT's position
3304 if there is nothing invisible here. This skips both
3305 over invisible text properties and overlays with
3306 invisible property. */
3307 newpos
= skip_invisible (IT_CHARPOS (*it
),
3308 &next_stop
, ZV
, it
->window
);
3310 /* If we skipped nothing at all we weren't at invisible
3311 text in the first place. If everything to the end of
3312 the buffer was skipped, end the loop. */
3313 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3317 /* We skipped some characters but not necessarily
3318 all there are. Check if we ended up on visible
3319 text. Fget_char_property returns the property of
3320 the char before the given position, i.e. if we
3321 get invis_p = 0, this means that the char at
3322 newpos is visible. */
3323 pos
= make_number (newpos
);
3324 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3325 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3328 /* If we ended up on invisible text, proceed to
3329 skip starting with next_stop. */
3331 IT_CHARPOS (*it
) = next_stop
;
3335 /* The position newpos is now either ZV or on visible text. */
3336 IT_CHARPOS (*it
) = newpos
;
3337 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3339 /* If there are before-strings at the start of invisible
3340 text, and the text is invisible because of a text
3341 property, arrange to show before-strings because 20.x did
3342 it that way. (If the text is invisible because of an
3343 overlay property instead of a text property, this is
3344 already handled in the overlay code.) */
3346 && get_overlay_strings (it
, start_charpos
))
3348 handled
= HANDLED_RECOMPUTE_PROPS
;
3349 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3351 else if (display_ellipsis_p
)
3352 setup_for_ellipsis (it
, 0);
3360 /* Make iterator IT return `...' next.
3361 Replaces LEN characters from buffer. */
3364 setup_for_ellipsis (it
, len
)
3368 /* Use the display table definition for `...'. Invalid glyphs
3369 will be handled by the method returning elements from dpvec. */
3370 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3372 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3373 it
->dpvec
= v
->contents
;
3374 it
->dpend
= v
->contents
+ v
->size
;
3378 /* Default `...'. */
3379 it
->dpvec
= default_invis_vector
;
3380 it
->dpend
= default_invis_vector
+ 3;
3383 it
->dpvec_char_len
= len
;
3384 it
->current
.dpvec_index
= 0;
3385 it
->dpvec_face_id
= -1;
3387 /* Remember the current face id in case glyphs specify faces.
3388 IT's face is restored in set_iterator_to_next.
3389 saved_face_id was set to preceding char's face in handle_stop. */
3390 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3391 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3393 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3399 /***********************************************************************
3401 ***********************************************************************/
3403 /* Set up iterator IT from `display' property at its current position.
3404 Called from handle_stop.
3405 We return HANDLED_RETURN if some part of the display property
3406 overrides the display of the buffer text itself.
3407 Otherwise we return HANDLED_NORMALLY. */
3409 static enum prop_handled
3410 handle_display_prop (it
)
3413 Lisp_Object prop
, object
;
3414 struct text_pos
*position
;
3415 /* Nonzero if some property replaces the display of the text itself. */
3416 int display_replaced_p
= 0;
3418 if (STRINGP (it
->string
))
3420 object
= it
->string
;
3421 position
= &it
->current
.string_pos
;
3425 object
= it
->w
->buffer
;
3426 position
= &it
->current
.pos
;
3429 /* Reset those iterator values set from display property values. */
3430 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3431 it
->space_width
= Qnil
;
3432 it
->font_height
= Qnil
;
3435 /* We don't support recursive `display' properties, i.e. string
3436 values that have a string `display' property, that have a string
3437 `display' property etc. */
3438 if (!it
->string_from_display_prop_p
)
3439 it
->area
= TEXT_AREA
;
3441 prop
= Fget_char_property (make_number (position
->charpos
),
3444 return HANDLED_NORMALLY
;
3447 /* Simple properties. */
3448 && !EQ (XCAR (prop
), Qimage
)
3449 && !EQ (XCAR (prop
), Qspace
)
3450 && !EQ (XCAR (prop
), Qwhen
)
3451 && !EQ (XCAR (prop
), Qslice
)
3452 && !EQ (XCAR (prop
), Qspace_width
)
3453 && !EQ (XCAR (prop
), Qheight
)
3454 && !EQ (XCAR (prop
), Qraise
)
3455 /* Marginal area specifications. */
3456 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3457 && !EQ (XCAR (prop
), Qleft_fringe
)
3458 && !EQ (XCAR (prop
), Qright_fringe
)
3459 && !NILP (XCAR (prop
)))
3461 for (; CONSP (prop
); prop
= XCDR (prop
))
3463 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3464 position
, display_replaced_p
))
3465 display_replaced_p
= 1;
3468 else if (VECTORP (prop
))
3471 for (i
= 0; i
< ASIZE (prop
); ++i
)
3472 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3473 position
, display_replaced_p
))
3474 display_replaced_p
= 1;
3478 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3479 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3480 return HANDLED_RECOMPUTE_PROPS
;
3482 display_replaced_p
= 1;
3485 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3489 /* Value is the position of the end of the `display' property starting
3490 at START_POS in OBJECT. */
3492 static struct text_pos
3493 display_prop_end (it
, object
, start_pos
)
3496 struct text_pos start_pos
;
3499 struct text_pos end_pos
;
3501 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3502 Qdisplay
, object
, Qnil
);
3503 CHARPOS (end_pos
) = XFASTINT (end
);
3504 if (STRINGP (object
))
3505 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3507 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3513 /* Set up IT from a single `display' specification PROP. OBJECT
3514 is the object in which the `display' property was found. *POSITION
3515 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3516 means that we previously saw a display specification which already
3517 replaced text display with something else, for example an image;
3518 we ignore such properties after the first one has been processed.
3520 If PROP is a `space' or `image' specification, and in some other
3521 cases too, set *POSITION to the position where the `display'
3524 Value is non-zero if something was found which replaces the display
3525 of buffer or string text. Specifically, the value is -1 if that
3526 "something" is "nothing". */
3529 handle_single_display_spec (it
, spec
, object
, position
,
3530 display_replaced_before_p
)
3534 struct text_pos
*position
;
3535 int display_replaced_before_p
;
3538 Lisp_Object location
, value
;
3539 struct text_pos start_pos
;
3542 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3543 If the result is non-nil, use VALUE instead of SPEC. */
3545 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3554 if (!NILP (form
) && !EQ (form
, Qt
))
3556 int count
= SPECPDL_INDEX ();
3557 struct gcpro gcpro1
;
3559 /* Bind `object' to the object having the `display' property, a
3560 buffer or string. Bind `position' to the position in the
3561 object where the property was found, and `buffer-position'
3562 to the current position in the buffer. */
3563 specbind (Qobject
, object
);
3564 specbind (Qposition
, make_number (CHARPOS (*position
)));
3565 specbind (Qbuffer_position
,
3566 make_number (STRINGP (object
)
3567 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3569 form
= safe_eval (form
);
3571 unbind_to (count
, Qnil
);
3577 /* Handle `(height HEIGHT)' specifications. */
3579 && EQ (XCAR (spec
), Qheight
)
3580 && CONSP (XCDR (spec
)))
3582 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3585 it
->font_height
= XCAR (XCDR (spec
));
3586 if (!NILP (it
->font_height
))
3588 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3589 int new_height
= -1;
3591 if (CONSP (it
->font_height
)
3592 && (EQ (XCAR (it
->font_height
), Qplus
)
3593 || EQ (XCAR (it
->font_height
), Qminus
))
3594 && CONSP (XCDR (it
->font_height
))
3595 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3597 /* `(+ N)' or `(- N)' where N is an integer. */
3598 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3599 if (EQ (XCAR (it
->font_height
), Qplus
))
3601 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3603 else if (FUNCTIONP (it
->font_height
))
3605 /* Call function with current height as argument.
3606 Value is the new height. */
3608 height
= safe_call1 (it
->font_height
,
3609 face
->lface
[LFACE_HEIGHT_INDEX
]);
3610 if (NUMBERP (height
))
3611 new_height
= XFLOATINT (height
);
3613 else if (NUMBERP (it
->font_height
))
3615 /* Value is a multiple of the canonical char height. */
3618 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3619 new_height
= (XFLOATINT (it
->font_height
)
3620 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3624 /* Evaluate IT->font_height with `height' bound to the
3625 current specified height to get the new height. */
3626 int count
= SPECPDL_INDEX ();
3628 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3629 value
= safe_eval (it
->font_height
);
3630 unbind_to (count
, Qnil
);
3632 if (NUMBERP (value
))
3633 new_height
= XFLOATINT (value
);
3637 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3643 /* Handle `(space_width WIDTH)'. */
3645 && EQ (XCAR (spec
), Qspace_width
)
3646 && CONSP (XCDR (spec
)))
3648 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3651 value
= XCAR (XCDR (spec
));
3652 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3653 it
->space_width
= value
;
3658 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3660 && EQ (XCAR (spec
), Qslice
))
3664 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3667 if (tem
= XCDR (spec
), CONSP (tem
))
3669 it
->slice
.x
= XCAR (tem
);
3670 if (tem
= XCDR (tem
), CONSP (tem
))
3672 it
->slice
.y
= XCAR (tem
);
3673 if (tem
= XCDR (tem
), CONSP (tem
))
3675 it
->slice
.width
= XCAR (tem
);
3676 if (tem
= XCDR (tem
), CONSP (tem
))
3677 it
->slice
.height
= XCAR (tem
);
3685 /* Handle `(raise FACTOR)'. */
3687 && EQ (XCAR (spec
), Qraise
)
3688 && CONSP (XCDR (spec
)))
3690 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3693 #ifdef HAVE_WINDOW_SYSTEM
3694 value
= XCAR (XCDR (spec
));
3695 if (NUMBERP (value
))
3697 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3698 it
->voffset
= - (XFLOATINT (value
)
3699 * (FONT_HEIGHT (face
->font
)));
3701 #endif /* HAVE_WINDOW_SYSTEM */
3706 /* Don't handle the other kinds of display specifications
3707 inside a string that we got from a `display' property. */
3708 if (it
->string_from_display_prop_p
)
3711 /* Characters having this form of property are not displayed, so
3712 we have to find the end of the property. */
3713 start_pos
= *position
;
3714 *position
= display_prop_end (it
, object
, start_pos
);
3717 /* Stop the scan at that end position--we assume that all
3718 text properties change there. */
3719 it
->stop_charpos
= position
->charpos
;
3721 /* Handle `(left-fringe BITMAP [FACE])'
3722 and `(right-fringe BITMAP [FACE])'. */
3724 && (EQ (XCAR (spec
), Qleft_fringe
)
3725 || EQ (XCAR (spec
), Qright_fringe
))
3726 && CONSP (XCDR (spec
)))
3728 int face_id
= DEFAULT_FACE_ID
;
3731 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3732 /* If we return here, POSITION has been advanced
3733 across the text with this property. */
3736 #ifdef HAVE_WINDOW_SYSTEM
3737 value
= XCAR (XCDR (spec
));
3738 if (!SYMBOLP (value
)
3739 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3740 /* If we return here, POSITION has been advanced
3741 across the text with this property. */
3744 if (CONSP (XCDR (XCDR (spec
))))
3746 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3747 int face_id2
= lookup_derived_face (it
->f
, face_name
,
3748 'A', FRINGE_FACE_ID
, 0);
3753 /* Save current settings of IT so that we can restore them
3754 when we are finished with the glyph property value. */
3758 it
->area
= TEXT_AREA
;
3759 it
->what
= IT_IMAGE
;
3760 it
->image_id
= -1; /* no image */
3761 it
->position
= start_pos
;
3762 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3763 it
->method
= GET_FROM_IMAGE
;
3764 it
->face_id
= face_id
;
3766 /* Say that we haven't consumed the characters with
3767 `display' property yet. The call to pop_it in
3768 set_iterator_to_next will clean this up. */
3769 *position
= start_pos
;
3771 if (EQ (XCAR (spec
), Qleft_fringe
))
3773 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3774 it
->left_user_fringe_face_id
= face_id
;
3778 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3779 it
->right_user_fringe_face_id
= face_id
;
3781 #endif /* HAVE_WINDOW_SYSTEM */
3785 /* Prepare to handle `((margin left-margin) ...)',
3786 `((margin right-margin) ...)' and `((margin nil) ...)'
3787 prefixes for display specifications. */
3788 location
= Qunbound
;
3789 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3793 value
= XCDR (spec
);
3795 value
= XCAR (value
);
3798 if (EQ (XCAR (tem
), Qmargin
)
3799 && (tem
= XCDR (tem
),
3800 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3802 || EQ (tem
, Qleft_margin
)
3803 || EQ (tem
, Qright_margin
))))
3807 if (EQ (location
, Qunbound
))
3813 /* After this point, VALUE is the property after any
3814 margin prefix has been stripped. It must be a string,
3815 an image specification, or `(space ...)'.
3817 LOCATION specifies where to display: `left-margin',
3818 `right-margin' or nil. */
3820 valid_p
= (STRINGP (value
)
3821 #ifdef HAVE_WINDOW_SYSTEM
3822 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3823 #endif /* not HAVE_WINDOW_SYSTEM */
3824 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3826 if (valid_p
&& !display_replaced_before_p
)
3828 /* Save current settings of IT so that we can restore them
3829 when we are finished with the glyph property value. */
3832 if (NILP (location
))
3833 it
->area
= TEXT_AREA
;
3834 else if (EQ (location
, Qleft_margin
))
3835 it
->area
= LEFT_MARGIN_AREA
;
3837 it
->area
= RIGHT_MARGIN_AREA
;
3839 if (STRINGP (value
))
3841 if (SCHARS (value
) == 0)
3844 return -1; /* Replaced by "", i.e. nothing. */
3847 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3848 it
->current
.overlay_string_index
= -1;
3849 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3850 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3851 it
->method
= GET_FROM_STRING
;
3852 it
->stop_charpos
= 0;
3853 it
->string_from_display_prop_p
= 1;
3854 /* Say that we haven't consumed the characters with
3855 `display' property yet. The call to pop_it in
3856 set_iterator_to_next will clean this up. */
3857 *position
= start_pos
;
3859 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3861 it
->method
= GET_FROM_STRETCH
;
3863 it
->current
.pos
= it
->position
= start_pos
;
3865 #ifdef HAVE_WINDOW_SYSTEM
3868 it
->what
= IT_IMAGE
;
3869 it
->image_id
= lookup_image (it
->f
, value
);
3870 it
->position
= start_pos
;
3871 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3872 it
->method
= GET_FROM_IMAGE
;
3874 /* Say that we haven't consumed the characters with
3875 `display' property yet. The call to pop_it in
3876 set_iterator_to_next will clean this up. */
3877 *position
= start_pos
;
3879 #endif /* HAVE_WINDOW_SYSTEM */
3884 /* Invalid property or property not supported. Restore
3885 POSITION to what it was before. */
3886 *position
= start_pos
;
3891 /* Check if SPEC is a display specification value whose text should be
3892 treated as intangible. */
3895 single_display_spec_intangible_p (prop
)
3898 /* Skip over `when FORM'. */
3899 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3913 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3914 we don't need to treat text as intangible. */
3915 if (EQ (XCAR (prop
), Qmargin
))
3923 || EQ (XCAR (prop
), Qleft_margin
)
3924 || EQ (XCAR (prop
), Qright_margin
))
3928 return (CONSP (prop
)
3929 && (EQ (XCAR (prop
), Qimage
)
3930 || EQ (XCAR (prop
), Qspace
)));
3934 /* Check if PROP is a display property value whose text should be
3935 treated as intangible. */
3938 display_prop_intangible_p (prop
)
3942 && CONSP (XCAR (prop
))
3943 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3945 /* A list of sub-properties. */
3946 while (CONSP (prop
))
3948 if (single_display_spec_intangible_p (XCAR (prop
)))
3953 else if (VECTORP (prop
))
3955 /* A vector of sub-properties. */
3957 for (i
= 0; i
< ASIZE (prop
); ++i
)
3958 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3962 return single_display_spec_intangible_p (prop
);
3968 /* Return 1 if PROP is a display sub-property value containing STRING. */
3971 single_display_spec_string_p (prop
, string
)
3972 Lisp_Object prop
, string
;
3974 if (EQ (string
, prop
))
3977 /* Skip over `when FORM'. */
3978 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3987 /* Skip over `margin LOCATION'. */
3988 if (EQ (XCAR (prop
), Qmargin
))
3999 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4003 /* Return 1 if STRING appears in the `display' property PROP. */
4006 display_prop_string_p (prop
, string
)
4007 Lisp_Object prop
, string
;
4010 && CONSP (XCAR (prop
))
4011 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4013 /* A list of sub-properties. */
4014 while (CONSP (prop
))
4016 if (single_display_spec_string_p (XCAR (prop
), string
))
4021 else if (VECTORP (prop
))
4023 /* A vector of sub-properties. */
4025 for (i
= 0; i
< ASIZE (prop
); ++i
)
4026 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4030 return single_display_spec_string_p (prop
, string
);
4036 /* Determine from which buffer position in W's buffer STRING comes
4037 from. AROUND_CHARPOS is an approximate position where it could
4038 be from. Value is the buffer position or 0 if it couldn't be
4041 W's buffer must be current.
4043 This function is necessary because we don't record buffer positions
4044 in glyphs generated from strings (to keep struct glyph small).
4045 This function may only use code that doesn't eval because it is
4046 called asynchronously from note_mouse_highlight. */
4049 string_buffer_position (w
, string
, around_charpos
)
4054 Lisp_Object limit
, prop
, pos
;
4055 const int MAX_DISTANCE
= 1000;
4058 pos
= make_number (around_charpos
);
4059 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4060 while (!found
&& !EQ (pos
, limit
))
4062 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4063 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4066 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4071 pos
= make_number (around_charpos
);
4072 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4073 while (!found
&& !EQ (pos
, limit
))
4075 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4076 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4079 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4084 return found
? XINT (pos
) : 0;
4089 /***********************************************************************
4090 `composition' property
4091 ***********************************************************************/
4093 /* Set up iterator IT from `composition' property at its current
4094 position. Called from handle_stop. */
4096 static enum prop_handled
4097 handle_composition_prop (it
)
4100 Lisp_Object prop
, string
;
4101 int pos
, pos_byte
, end
;
4102 enum prop_handled handled
= HANDLED_NORMALLY
;
4104 if (STRINGP (it
->string
))
4106 pos
= IT_STRING_CHARPOS (*it
);
4107 pos_byte
= IT_STRING_BYTEPOS (*it
);
4108 string
= it
->string
;
4112 pos
= IT_CHARPOS (*it
);
4113 pos_byte
= IT_BYTEPOS (*it
);
4117 /* If there's a valid composition and point is not inside of the
4118 composition (in the case that the composition is from the current
4119 buffer), draw a glyph composed from the composition components. */
4120 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4121 && COMPOSITION_VALID_P (pos
, end
, prop
)
4122 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4124 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4128 it
->method
= GET_FROM_COMPOSITION
;
4130 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4131 /* For a terminal, draw only the first character of the
4133 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4134 it
->len
= (STRINGP (it
->string
)
4135 ? string_char_to_byte (it
->string
, end
)
4136 : CHAR_TO_BYTE (end
)) - pos_byte
;
4137 it
->stop_charpos
= end
;
4138 handled
= HANDLED_RETURN
;
4147 /***********************************************************************
4149 ***********************************************************************/
4151 /* The following structure is used to record overlay strings for
4152 later sorting in load_overlay_strings. */
4154 struct overlay_entry
4156 Lisp_Object overlay
;
4163 /* Set up iterator IT from overlay strings at its current position.
4164 Called from handle_stop. */
4166 static enum prop_handled
4167 handle_overlay_change (it
)
4170 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4171 return HANDLED_RECOMPUTE_PROPS
;
4173 return HANDLED_NORMALLY
;
4177 /* Set up the next overlay string for delivery by IT, if there is an
4178 overlay string to deliver. Called by set_iterator_to_next when the
4179 end of the current overlay string is reached. If there are more
4180 overlay strings to display, IT->string and
4181 IT->current.overlay_string_index are set appropriately here.
4182 Otherwise IT->string is set to nil. */
4185 next_overlay_string (it
)
4188 ++it
->current
.overlay_string_index
;
4189 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4191 /* No more overlay strings. Restore IT's settings to what
4192 they were before overlay strings were processed, and
4193 continue to deliver from current_buffer. */
4194 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4197 xassert (it
->stop_charpos
>= BEGV
4198 && it
->stop_charpos
<= it
->end_charpos
);
4200 it
->current
.overlay_string_index
= -1;
4201 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4202 it
->n_overlay_strings
= 0;
4203 it
->method
= GET_FROM_BUFFER
;
4205 /* If we're at the end of the buffer, record that we have
4206 processed the overlay strings there already, so that
4207 next_element_from_buffer doesn't try it again. */
4208 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4209 it
->overlay_strings_at_end_processed_p
= 1;
4211 /* If we have to display `...' for invisible text, set
4212 the iterator up for that. */
4213 if (display_ellipsis_p
)
4214 setup_for_ellipsis (it
, 0);
4218 /* There are more overlay strings to process. If
4219 IT->current.overlay_string_index has advanced to a position
4220 where we must load IT->overlay_strings with more strings, do
4222 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4224 if (it
->current
.overlay_string_index
&& i
== 0)
4225 load_overlay_strings (it
, 0);
4227 /* Initialize IT to deliver display elements from the overlay
4229 it
->string
= it
->overlay_strings
[i
];
4230 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4231 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4232 it
->method
= GET_FROM_STRING
;
4233 it
->stop_charpos
= 0;
4240 /* Compare two overlay_entry structures E1 and E2. Used as a
4241 comparison function for qsort in load_overlay_strings. Overlay
4242 strings for the same position are sorted so that
4244 1. All after-strings come in front of before-strings, except
4245 when they come from the same overlay.
4247 2. Within after-strings, strings are sorted so that overlay strings
4248 from overlays with higher priorities come first.
4250 2. Within before-strings, strings are sorted so that overlay
4251 strings from overlays with higher priorities come last.
4253 Value is analogous to strcmp. */
4257 compare_overlay_entries (e1
, e2
)
4260 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4261 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4264 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4266 /* Let after-strings appear in front of before-strings if
4267 they come from different overlays. */
4268 if (EQ (entry1
->overlay
, entry2
->overlay
))
4269 result
= entry1
->after_string_p
? 1 : -1;
4271 result
= entry1
->after_string_p
? -1 : 1;
4273 else if (entry1
->after_string_p
)
4274 /* After-strings sorted in order of decreasing priority. */
4275 result
= entry2
->priority
- entry1
->priority
;
4277 /* Before-strings sorted in order of increasing priority. */
4278 result
= entry1
->priority
- entry2
->priority
;
4284 /* Load the vector IT->overlay_strings with overlay strings from IT's
4285 current buffer position, or from CHARPOS if that is > 0. Set
4286 IT->n_overlays to the total number of overlay strings found.
4288 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4289 a time. On entry into load_overlay_strings,
4290 IT->current.overlay_string_index gives the number of overlay
4291 strings that have already been loaded by previous calls to this
4294 IT->add_overlay_start contains an additional overlay start
4295 position to consider for taking overlay strings from, if non-zero.
4296 This position comes into play when the overlay has an `invisible'
4297 property, and both before and after-strings. When we've skipped to
4298 the end of the overlay, because of its `invisible' property, we
4299 nevertheless want its before-string to appear.
4300 IT->add_overlay_start will contain the overlay start position
4303 Overlay strings are sorted so that after-string strings come in
4304 front of before-string strings. Within before and after-strings,
4305 strings are sorted by overlay priority. See also function
4306 compare_overlay_entries. */
4309 load_overlay_strings (it
, charpos
)
4313 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4314 Lisp_Object overlay
, window
, str
, invisible
;
4315 struct Lisp_Overlay
*ov
;
4318 int n
= 0, i
, j
, invis_p
;
4319 struct overlay_entry
*entries
4320 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4323 charpos
= IT_CHARPOS (*it
);
4325 /* Append the overlay string STRING of overlay OVERLAY to vector
4326 `entries' which has size `size' and currently contains `n'
4327 elements. AFTER_P non-zero means STRING is an after-string of
4329 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4332 Lisp_Object priority; \
4336 int new_size = 2 * size; \
4337 struct overlay_entry *old = entries; \
4339 (struct overlay_entry *) alloca (new_size \
4340 * sizeof *entries); \
4341 bcopy (old, entries, size * sizeof *entries); \
4345 entries[n].string = (STRING); \
4346 entries[n].overlay = (OVERLAY); \
4347 priority = Foverlay_get ((OVERLAY), Qpriority); \
4348 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4349 entries[n].after_string_p = (AFTER_P); \
4354 /* Process overlay before the overlay center. */
4355 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4357 XSETMISC (overlay
, ov
);
4358 xassert (OVERLAYP (overlay
));
4359 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4360 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4365 /* Skip this overlay if it doesn't start or end at IT's current
4367 if (end
!= charpos
&& start
!= charpos
)
4370 /* Skip this overlay if it doesn't apply to IT->w. */
4371 window
= Foverlay_get (overlay
, Qwindow
);
4372 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4375 /* If the text ``under'' the overlay is invisible, both before-
4376 and after-strings from this overlay are visible; start and
4377 end position are indistinguishable. */
4378 invisible
= Foverlay_get (overlay
, Qinvisible
);
4379 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4381 /* If overlay has a non-empty before-string, record it. */
4382 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4383 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4385 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4387 /* If overlay has a non-empty after-string, record it. */
4388 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4389 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4391 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4394 /* Process overlays after the overlay center. */
4395 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4397 XSETMISC (overlay
, ov
);
4398 xassert (OVERLAYP (overlay
));
4399 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4400 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4402 if (start
> charpos
)
4405 /* Skip this overlay if it doesn't start or end at IT's current
4407 if (end
!= charpos
&& start
!= charpos
)
4410 /* Skip this overlay if it doesn't apply to IT->w. */
4411 window
= Foverlay_get (overlay
, Qwindow
);
4412 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4415 /* If the text ``under'' the overlay is invisible, it has a zero
4416 dimension, and both before- and after-strings apply. */
4417 invisible
= Foverlay_get (overlay
, Qinvisible
);
4418 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4420 /* If overlay has a non-empty before-string, record it. */
4421 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4422 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4424 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4426 /* If overlay has a non-empty after-string, record it. */
4427 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4428 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4430 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4433 #undef RECORD_OVERLAY_STRING
4437 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4439 /* Record the total number of strings to process. */
4440 it
->n_overlay_strings
= n
;
4442 /* IT->current.overlay_string_index is the number of overlay strings
4443 that have already been consumed by IT. Copy some of the
4444 remaining overlay strings to IT->overlay_strings. */
4446 j
= it
->current
.overlay_string_index
;
4447 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4448 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4454 /* Get the first chunk of overlay strings at IT's current buffer
4455 position, or at CHARPOS if that is > 0. Value is non-zero if at
4456 least one overlay string was found. */
4459 get_overlay_strings (it
, charpos
)
4463 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4464 process. This fills IT->overlay_strings with strings, and sets
4465 IT->n_overlay_strings to the total number of strings to process.
4466 IT->pos.overlay_string_index has to be set temporarily to zero
4467 because load_overlay_strings needs this; it must be set to -1
4468 when no overlay strings are found because a zero value would
4469 indicate a position in the first overlay string. */
4470 it
->current
.overlay_string_index
= 0;
4471 load_overlay_strings (it
, charpos
);
4473 /* If we found overlay strings, set up IT to deliver display
4474 elements from the first one. Otherwise set up IT to deliver
4475 from current_buffer. */
4476 if (it
->n_overlay_strings
)
4478 /* Make sure we know settings in current_buffer, so that we can
4479 restore meaningful values when we're done with the overlay
4481 compute_stop_pos (it
);
4482 xassert (it
->face_id
>= 0);
4484 /* Save IT's settings. They are restored after all overlay
4485 strings have been processed. */
4486 xassert (it
->sp
== 0);
4489 /* Set up IT to deliver display elements from the first overlay
4491 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4492 it
->string
= it
->overlay_strings
[0];
4493 it
->stop_charpos
= 0;
4494 xassert (STRINGP (it
->string
));
4495 it
->end_charpos
= SCHARS (it
->string
);
4496 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4497 it
->method
= GET_FROM_STRING
;
4502 it
->current
.overlay_string_index
= -1;
4503 it
->method
= GET_FROM_BUFFER
;
4508 /* Value is non-zero if we found at least one overlay string. */
4509 return STRINGP (it
->string
);
4514 /***********************************************************************
4515 Saving and restoring state
4516 ***********************************************************************/
4518 /* Save current settings of IT on IT->stack. Called, for example,
4519 before setting up IT for an overlay string, to be able to restore
4520 IT's settings to what they were after the overlay string has been
4527 struct iterator_stack_entry
*p
;
4529 xassert (it
->sp
< 2);
4530 p
= it
->stack
+ it
->sp
;
4532 p
->stop_charpos
= it
->stop_charpos
;
4533 xassert (it
->face_id
>= 0);
4534 p
->face_id
= it
->face_id
;
4535 p
->string
= it
->string
;
4536 p
->pos
= it
->current
;
4537 p
->end_charpos
= it
->end_charpos
;
4538 p
->string_nchars
= it
->string_nchars
;
4540 p
->multibyte_p
= it
->multibyte_p
;
4541 p
->slice
= it
->slice
;
4542 p
->space_width
= it
->space_width
;
4543 p
->font_height
= it
->font_height
;
4544 p
->voffset
= it
->voffset
;
4545 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4546 p
->display_ellipsis_p
= 0;
4551 /* Restore IT's settings from IT->stack. Called, for example, when no
4552 more overlay strings must be processed, and we return to delivering
4553 display elements from a buffer, or when the end of a string from a
4554 `display' property is reached and we return to delivering display
4555 elements from an overlay string, or from a buffer. */
4561 struct iterator_stack_entry
*p
;
4563 xassert (it
->sp
> 0);
4565 p
= it
->stack
+ it
->sp
;
4566 it
->stop_charpos
= p
->stop_charpos
;
4567 it
->face_id
= p
->face_id
;
4568 it
->string
= p
->string
;
4569 it
->current
= p
->pos
;
4570 it
->end_charpos
= p
->end_charpos
;
4571 it
->string_nchars
= p
->string_nchars
;
4573 it
->multibyte_p
= p
->multibyte_p
;
4574 it
->slice
= p
->slice
;
4575 it
->space_width
= p
->space_width
;
4576 it
->font_height
= p
->font_height
;
4577 it
->voffset
= p
->voffset
;
4578 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4583 /***********************************************************************
4585 ***********************************************************************/
4587 /* Set IT's current position to the previous line start. */
4590 back_to_previous_line_start (it
)
4593 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4594 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4598 /* Move IT to the next line start.
4600 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4601 we skipped over part of the text (as opposed to moving the iterator
4602 continuously over the text). Otherwise, don't change the value
4605 Newlines may come from buffer text, overlay strings, or strings
4606 displayed via the `display' property. That's the reason we can't
4607 simply use find_next_newline_no_quit.
4609 Note that this function may not skip over invisible text that is so
4610 because of text properties and immediately follows a newline. If
4611 it would, function reseat_at_next_visible_line_start, when called
4612 from set_iterator_to_next, would effectively make invisible
4613 characters following a newline part of the wrong glyph row, which
4614 leads to wrong cursor motion. */
4617 forward_to_next_line_start (it
, skipped_p
)
4621 int old_selective
, newline_found_p
, n
;
4622 const int MAX_NEWLINE_DISTANCE
= 500;
4624 /* If already on a newline, just consume it to avoid unintended
4625 skipping over invisible text below. */
4626 if (it
->what
== IT_CHARACTER
4628 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4630 set_iterator_to_next (it
, 0);
4635 /* Don't handle selective display in the following. It's (a)
4636 unnecessary because it's done by the caller, and (b) leads to an
4637 infinite recursion because next_element_from_ellipsis indirectly
4638 calls this function. */
4639 old_selective
= it
->selective
;
4642 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4643 from buffer text. */
4644 for (n
= newline_found_p
= 0;
4645 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4646 n
+= STRINGP (it
->string
) ? 0 : 1)
4648 if (!get_next_display_element (it
))
4650 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4651 set_iterator_to_next (it
, 0);
4654 /* If we didn't find a newline near enough, see if we can use a
4656 if (!newline_found_p
)
4658 int start
= IT_CHARPOS (*it
);
4659 int limit
= find_next_newline_no_quit (start
, 1);
4662 xassert (!STRINGP (it
->string
));
4664 /* If there isn't any `display' property in sight, and no
4665 overlays, we can just use the position of the newline in
4667 if (it
->stop_charpos
>= limit
4668 || ((pos
= Fnext_single_property_change (make_number (start
),
4670 Qnil
, make_number (limit
)),
4672 && next_overlay_change (start
) == ZV
))
4674 IT_CHARPOS (*it
) = limit
;
4675 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4676 *skipped_p
= newline_found_p
= 1;
4680 while (get_next_display_element (it
)
4681 && !newline_found_p
)
4683 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4684 set_iterator_to_next (it
, 0);
4689 it
->selective
= old_selective
;
4690 return newline_found_p
;
4694 /* Set IT's current position to the previous visible line start. Skip
4695 invisible text that is so either due to text properties or due to
4696 selective display. Caution: this does not change IT->current_x and
4700 back_to_previous_visible_line_start (it
)
4703 while (IT_CHARPOS (*it
) > BEGV
)
4705 back_to_previous_line_start (it
);
4706 if (IT_CHARPOS (*it
) <= BEGV
)
4709 /* If selective > 0, then lines indented more than that values
4711 if (it
->selective
> 0
4712 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4713 (double) it
->selective
)) /* iftc */
4716 /* Check the newline before point for invisibility. */
4719 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4720 Qinvisible
, it
->window
);
4721 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4725 /* If newline has a display property that replaces the newline with something
4726 else (image or text), find start of overlay or interval and continue search
4728 if (IT_CHARPOS (*it
) > BEGV
)
4730 struct it it2
= *it
;
4733 Lisp_Object val
, overlay
;
4735 pos
= --IT_CHARPOS (it2
);
4738 if (handle_display_prop (&it2
) == HANDLED_RETURN
4739 && !NILP (val
= get_char_property_and_overlay
4740 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
4741 && (OVERLAYP (overlay
)
4742 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
4743 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
4747 IT_CHARPOS (*it
) = beg
;
4748 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
4756 xassert (IT_CHARPOS (*it
) >= BEGV
);
4757 xassert (IT_CHARPOS (*it
) == BEGV
4758 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4763 /* Reseat iterator IT at the previous visible line start. Skip
4764 invisible text that is so either due to text properties or due to
4765 selective display. At the end, update IT's overlay information,
4766 face information etc. */
4769 reseat_at_previous_visible_line_start (it
)
4772 back_to_previous_visible_line_start (it
);
4773 reseat (it
, it
->current
.pos
, 1);
4778 /* Reseat iterator IT on the next visible line start in the current
4779 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4780 preceding the line start. Skip over invisible text that is so
4781 because of selective display. Compute faces, overlays etc at the
4782 new position. Note that this function does not skip over text that
4783 is invisible because of text properties. */
4786 reseat_at_next_visible_line_start (it
, on_newline_p
)
4790 int newline_found_p
, skipped_p
= 0;
4792 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4794 /* Skip over lines that are invisible because they are indented
4795 more than the value of IT->selective. */
4796 if (it
->selective
> 0)
4797 while (IT_CHARPOS (*it
) < ZV
4798 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4799 (double) it
->selective
)) /* iftc */
4801 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4802 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4805 /* Position on the newline if that's what's requested. */
4806 if (on_newline_p
&& newline_found_p
)
4808 if (STRINGP (it
->string
))
4810 if (IT_STRING_CHARPOS (*it
) > 0)
4812 --IT_STRING_CHARPOS (*it
);
4813 --IT_STRING_BYTEPOS (*it
);
4816 else if (IT_CHARPOS (*it
) > BEGV
)
4820 reseat (it
, it
->current
.pos
, 0);
4824 reseat (it
, it
->current
.pos
, 0);
4831 /***********************************************************************
4832 Changing an iterator's position
4833 ***********************************************************************/
4835 /* Change IT's current position to POS in current_buffer. If FORCE_P
4836 is non-zero, always check for text properties at the new position.
4837 Otherwise, text properties are only looked up if POS >=
4838 IT->check_charpos of a property. */
4841 reseat (it
, pos
, force_p
)
4843 struct text_pos pos
;
4846 int original_pos
= IT_CHARPOS (*it
);
4848 reseat_1 (it
, pos
, 0);
4850 /* Determine where to check text properties. Avoid doing it
4851 where possible because text property lookup is very expensive. */
4853 || CHARPOS (pos
) > it
->stop_charpos
4854 || CHARPOS (pos
) < original_pos
)
4861 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4862 IT->stop_pos to POS, also. */
4865 reseat_1 (it
, pos
, set_stop_p
)
4867 struct text_pos pos
;
4870 /* Don't call this function when scanning a C string. */
4871 xassert (it
->s
== NULL
);
4873 /* POS must be a reasonable value. */
4874 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4876 it
->current
.pos
= it
->position
= pos
;
4877 XSETBUFFER (it
->object
, current_buffer
);
4878 it
->end_charpos
= ZV
;
4880 it
->current
.dpvec_index
= -1;
4881 it
->current
.overlay_string_index
= -1;
4882 IT_STRING_CHARPOS (*it
) = -1;
4883 IT_STRING_BYTEPOS (*it
) = -1;
4885 it
->method
= GET_FROM_BUFFER
;
4886 /* RMS: I added this to fix a bug in move_it_vertically_backward
4887 where it->area continued to relate to the starting point
4888 for the backward motion. Bug report from
4889 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4890 However, I am not sure whether reseat still does the right thing
4891 in general after this change. */
4892 it
->area
= TEXT_AREA
;
4893 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4895 it
->face_before_selective_p
= 0;
4898 it
->stop_charpos
= CHARPOS (pos
);
4902 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4903 If S is non-null, it is a C string to iterate over. Otherwise,
4904 STRING gives a Lisp string to iterate over.
4906 If PRECISION > 0, don't return more then PRECISION number of
4907 characters from the string.
4909 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4910 characters have been returned. FIELD_WIDTH < 0 means an infinite
4913 MULTIBYTE = 0 means disable processing of multibyte characters,
4914 MULTIBYTE > 0 means enable it,
4915 MULTIBYTE < 0 means use IT->multibyte_p.
4917 IT must be initialized via a prior call to init_iterator before
4918 calling this function. */
4921 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4926 int precision
, field_width
, multibyte
;
4928 /* No region in strings. */
4929 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4931 /* No text property checks performed by default, but see below. */
4932 it
->stop_charpos
= -1;
4934 /* Set iterator position and end position. */
4935 bzero (&it
->current
, sizeof it
->current
);
4936 it
->current
.overlay_string_index
= -1;
4937 it
->current
.dpvec_index
= -1;
4938 xassert (charpos
>= 0);
4940 /* If STRING is specified, use its multibyteness, otherwise use the
4941 setting of MULTIBYTE, if specified. */
4943 it
->multibyte_p
= multibyte
> 0;
4947 xassert (STRINGP (string
));
4948 it
->string
= string
;
4950 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4951 it
->method
= GET_FROM_STRING
;
4952 it
->current
.string_pos
= string_pos (charpos
, string
);
4959 /* Note that we use IT->current.pos, not it->current.string_pos,
4960 for displaying C strings. */
4961 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4962 if (it
->multibyte_p
)
4964 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4965 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4969 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4970 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4973 it
->method
= GET_FROM_C_STRING
;
4976 /* PRECISION > 0 means don't return more than PRECISION characters
4978 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4979 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4981 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4982 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4983 FIELD_WIDTH < 0 means infinite field width. This is useful for
4984 padding with `-' at the end of a mode line. */
4985 if (field_width
< 0)
4986 field_width
= INFINITY
;
4987 if (field_width
> it
->end_charpos
- charpos
)
4988 it
->end_charpos
= charpos
+ field_width
;
4990 /* Use the standard display table for displaying strings. */
4991 if (DISP_TABLE_P (Vstandard_display_table
))
4992 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4994 it
->stop_charpos
= charpos
;
5000 /***********************************************************************
5002 ***********************************************************************/
5004 /* Map enum it_method value to corresponding next_element_from_* function. */
5006 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5008 next_element_from_buffer
,
5009 next_element_from_display_vector
,
5010 next_element_from_composition
,
5011 next_element_from_string
,
5012 next_element_from_c_string
,
5013 next_element_from_image
,
5014 next_element_from_stretch
5018 /* Load IT's display element fields with information about the next
5019 display element from the current position of IT. Value is zero if
5020 end of buffer (or C string) is reached. */
5023 get_next_display_element (it
)
5026 /* Non-zero means that we found a display element. Zero means that
5027 we hit the end of what we iterate over. Performance note: the
5028 function pointer `method' used here turns out to be faster than
5029 using a sequence of if-statements. */
5033 success_p
= (*get_next_element
[it
->method
]) (it
);
5035 if (it
->what
== IT_CHARACTER
)
5037 /* Map via display table or translate control characters.
5038 IT->c, IT->len etc. have been set to the next character by
5039 the function call above. If we have a display table, and it
5040 contains an entry for IT->c, translate it. Don't do this if
5041 IT->c itself comes from a display table, otherwise we could
5042 end up in an infinite recursion. (An alternative could be to
5043 count the recursion depth of this function and signal an
5044 error when a certain maximum depth is reached.) Is it worth
5046 if (success_p
&& it
->dpvec
== NULL
)
5051 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5054 struct Lisp_Vector
*v
= XVECTOR (dv
);
5056 /* Return the first character from the display table
5057 entry, if not empty. If empty, don't display the
5058 current character. */
5061 it
->dpvec_char_len
= it
->len
;
5062 it
->dpvec
= v
->contents
;
5063 it
->dpend
= v
->contents
+ v
->size
;
5064 it
->current
.dpvec_index
= 0;
5065 it
->dpvec_face_id
= -1;
5066 it
->saved_face_id
= it
->face_id
;
5067 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5072 set_iterator_to_next (it
, 0);
5077 /* Translate control characters into `\003' or `^C' form.
5078 Control characters coming from a display table entry are
5079 currently not translated because we use IT->dpvec to hold
5080 the translation. This could easily be changed but I
5081 don't believe that it is worth doing.
5083 If it->multibyte_p is nonzero, eight-bit characters and
5084 non-printable multibyte characters are also translated to
5087 If it->multibyte_p is zero, eight-bit characters that
5088 don't have corresponding multibyte char code are also
5089 translated to octal form. */
5090 else if ((it
->c
< ' '
5091 && (it
->area
!= TEXT_AREA
5092 /* In mode line, treat \n like other crl chars. */
5094 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5095 || (it
->c
!= '\n' && it
->c
!= '\t')))
5099 || !CHAR_PRINTABLE_P (it
->c
)
5100 || (!NILP (Vnobreak_char_display
)
5101 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5102 || it
->c
== 0x920 || it
->c
== 0x92d
5103 || it
->c
== 0xe20 || it
->c
== 0xe2d
5104 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5106 && (!unibyte_display_via_language_environment
5107 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5109 /* IT->c is a control character which must be displayed
5110 either as '\003' or as `^C' where the '\\' and '^'
5111 can be defined in the display table. Fill
5112 IT->ctl_chars with glyphs for what we have to
5113 display. Then, set IT->dpvec to these glyphs. */
5116 int face_id
, lface_id
= 0 ;
5119 /* Handle control characters with ^. */
5121 if (it
->c
< 128 && it
->ctl_arrow_p
)
5123 g
= '^'; /* default glyph for Control */
5124 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5126 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5127 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5129 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5130 lface_id
= FAST_GLYPH_FACE (g
);
5134 g
= FAST_GLYPH_CHAR (g
);
5135 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5140 /* Merge the escape-glyph face into the current face. */
5141 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5145 XSETINT (it
->ctl_chars
[0], g
);
5147 XSETINT (it
->ctl_chars
[1], g
);
5149 goto display_control
;
5152 /* Handle non-break space in the mode where it only gets
5155 if (EQ (Vnobreak_char_display
, Qt
)
5156 && (it
->c
== 0x8a0 || it
->c
== 0x920
5157 || it
->c
== 0xe20 || it
->c
== 0xf20))
5159 /* Merge the no-break-space face into the current face. */
5160 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5164 XSETINT (it
->ctl_chars
[0], g
);
5166 goto display_control
;
5169 /* Handle sequences that start with the "escape glyph". */
5171 /* the default escape glyph is \. */
5172 escape_glyph
= '\\';
5175 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5176 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5178 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5179 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5183 /* The display table specified a face.
5184 Merge it into face_id and also into escape_glyph. */
5185 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5186 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5191 /* Merge the escape-glyph face into the current face. */
5192 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5196 /* Handle soft hyphens in the mode where they only get
5199 if (EQ (Vnobreak_char_display
, Qt
)
5200 && (it
->c
== 0x8ad || it
->c
== 0x92d
5201 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5204 XSETINT (it
->ctl_chars
[0], g
);
5206 goto display_control
;
5209 /* Handle non-break space and soft hyphen
5210 with the escape glyph. */
5212 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5213 || it
->c
== 0x920 || it
->c
== 0x92d
5214 || it
->c
== 0xe20 || it
->c
== 0xe2d
5215 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5217 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5218 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5219 XSETINT (it
->ctl_chars
[1], g
);
5221 goto display_control
;
5225 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5229 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5230 if (SINGLE_BYTE_CHAR_P (it
->c
))
5231 str
[0] = it
->c
, len
= 1;
5234 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5237 /* It's an invalid character, which shouldn't
5238 happen actually, but due to bugs it may
5239 happen. Let's print the char as is, there's
5240 not much meaningful we can do with it. */
5242 str
[1] = it
->c
>> 8;
5243 str
[2] = it
->c
>> 16;
5244 str
[3] = it
->c
>> 24;
5249 for (i
= 0; i
< len
; i
++)
5251 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5252 /* Insert three more glyphs into IT->ctl_chars for
5253 the octal display of the character. */
5254 g
= ((str
[i
] >> 6) & 7) + '0';
5255 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5256 g
= ((str
[i
] >> 3) & 7) + '0';
5257 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5258 g
= (str
[i
] & 7) + '0';
5259 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5265 /* Set up IT->dpvec and return first character from it. */
5266 it
->dpvec_char_len
= it
->len
;
5267 it
->dpvec
= it
->ctl_chars
;
5268 it
->dpend
= it
->dpvec
+ ctl_len
;
5269 it
->current
.dpvec_index
= 0;
5270 it
->dpvec_face_id
= face_id
;
5271 it
->saved_face_id
= it
->face_id
;
5272 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5278 /* Adjust face id for a multibyte character. There are no
5279 multibyte character in unibyte text. */
5282 && FRAME_WINDOW_P (it
->f
))
5284 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5285 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5289 /* Is this character the last one of a run of characters with
5290 box? If yes, set IT->end_of_box_run_p to 1. */
5297 it
->end_of_box_run_p
5298 = ((face_id
= face_after_it_pos (it
),
5299 face_id
!= it
->face_id
)
5300 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5301 face
->box
== FACE_NO_BOX
));
5304 /* Value is 0 if end of buffer or string reached. */
5309 /* Move IT to the next display element.
5311 RESEAT_P non-zero means if called on a newline in buffer text,
5312 skip to the next visible line start.
5314 Functions get_next_display_element and set_iterator_to_next are
5315 separate because I find this arrangement easier to handle than a
5316 get_next_display_element function that also increments IT's
5317 position. The way it is we can first look at an iterator's current
5318 display element, decide whether it fits on a line, and if it does,
5319 increment the iterator position. The other way around we probably
5320 would either need a flag indicating whether the iterator has to be
5321 incremented the next time, or we would have to implement a
5322 decrement position function which would not be easy to write. */
5325 set_iterator_to_next (it
, reseat_p
)
5329 /* Reset flags indicating start and end of a sequence of characters
5330 with box. Reset them at the start of this function because
5331 moving the iterator to a new position might set them. */
5332 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5336 case GET_FROM_BUFFER
:
5337 /* The current display element of IT is a character from
5338 current_buffer. Advance in the buffer, and maybe skip over
5339 invisible lines that are so because of selective display. */
5340 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5341 reseat_at_next_visible_line_start (it
, 0);
5344 xassert (it
->len
!= 0);
5345 IT_BYTEPOS (*it
) += it
->len
;
5346 IT_CHARPOS (*it
) += 1;
5347 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5351 case GET_FROM_COMPOSITION
:
5352 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5353 if (STRINGP (it
->string
))
5355 IT_STRING_BYTEPOS (*it
) += it
->len
;
5356 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5357 it
->method
= GET_FROM_STRING
;
5358 goto consider_string_end
;
5362 IT_BYTEPOS (*it
) += it
->len
;
5363 IT_CHARPOS (*it
) += it
->cmp_len
;
5364 it
->method
= GET_FROM_BUFFER
;
5368 case GET_FROM_C_STRING
:
5369 /* Current display element of IT is from a C string. */
5370 IT_BYTEPOS (*it
) += it
->len
;
5371 IT_CHARPOS (*it
) += 1;
5374 case GET_FROM_DISPLAY_VECTOR
:
5375 /* Current display element of IT is from a display table entry.
5376 Advance in the display table definition. Reset it to null if
5377 end reached, and continue with characters from buffers/
5379 ++it
->current
.dpvec_index
;
5381 /* Restore face of the iterator to what they were before the
5382 display vector entry (these entries may contain faces). */
5383 it
->face_id
= it
->saved_face_id
;
5385 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5388 it
->method
= GET_FROM_C_STRING
;
5389 else if (STRINGP (it
->string
))
5390 it
->method
= GET_FROM_STRING
;
5392 it
->method
= GET_FROM_BUFFER
;
5395 it
->current
.dpvec_index
= -1;
5397 /* Skip over characters which were displayed via IT->dpvec. */
5398 if (it
->dpvec_char_len
< 0)
5399 reseat_at_next_visible_line_start (it
, 1);
5400 else if (it
->dpvec_char_len
> 0)
5402 it
->len
= it
->dpvec_char_len
;
5403 set_iterator_to_next (it
, reseat_p
);
5406 /* Recheck faces after display vector */
5407 it
->stop_charpos
= IT_CHARPOS (*it
);
5411 case GET_FROM_STRING
:
5412 /* Current display element is a character from a Lisp string. */
5413 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5414 IT_STRING_BYTEPOS (*it
) += it
->len
;
5415 IT_STRING_CHARPOS (*it
) += 1;
5417 consider_string_end
:
5419 if (it
->current
.overlay_string_index
>= 0)
5421 /* IT->string is an overlay string. Advance to the
5422 next, if there is one. */
5423 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5424 next_overlay_string (it
);
5428 /* IT->string is not an overlay string. If we reached
5429 its end, and there is something on IT->stack, proceed
5430 with what is on the stack. This can be either another
5431 string, this time an overlay string, or a buffer. */
5432 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5436 if (STRINGP (it
->string
))
5437 goto consider_string_end
;
5438 it
->method
= GET_FROM_BUFFER
;
5443 case GET_FROM_IMAGE
:
5444 case GET_FROM_STRETCH
:
5445 /* The position etc with which we have to proceed are on
5446 the stack. The position may be at the end of a string,
5447 if the `display' property takes up the whole string. */
5448 xassert (it
->sp
> 0);
5451 if (STRINGP (it
->string
))
5453 it
->method
= GET_FROM_STRING
;
5454 goto consider_string_end
;
5456 it
->method
= GET_FROM_BUFFER
;
5460 /* There are no other methods defined, so this should be a bug. */
5464 xassert (it
->method
!= GET_FROM_STRING
5465 || (STRINGP (it
->string
)
5466 && IT_STRING_CHARPOS (*it
) >= 0));
5469 /* Load IT's display element fields with information about the next
5470 display element which comes from a display table entry or from the
5471 result of translating a control character to one of the forms `^C'
5474 IT->dpvec holds the glyphs to return as characters.
5475 IT->saved_face_id holds the face id before the display vector--
5476 it is restored into IT->face_idin set_iterator_to_next. */
5479 next_element_from_display_vector (it
)
5483 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5485 it
->face_id
= it
->saved_face_id
;
5487 if (INTEGERP (*it
->dpvec
)
5488 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5492 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5493 it
->c
= FAST_GLYPH_CHAR (g
);
5494 it
->len
= CHAR_BYTES (it
->c
);
5496 /* The entry may contain a face id to use. Such a face id is
5497 the id of a Lisp face, not a realized face. A face id of
5498 zero means no face is specified. */
5499 if (it
->dpvec_face_id
>= 0)
5500 it
->face_id
= it
->dpvec_face_id
;
5503 int lface_id
= FAST_GLYPH_FACE (g
);
5505 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5510 /* Display table entry is invalid. Return a space. */
5511 it
->c
= ' ', it
->len
= 1;
5513 /* Don't change position and object of the iterator here. They are
5514 still the values of the character that had this display table
5515 entry or was translated, and that's what we want. */
5516 it
->what
= IT_CHARACTER
;
5521 /* Load IT with the next display element from Lisp string IT->string.
5522 IT->current.string_pos is the current position within the string.
5523 If IT->current.overlay_string_index >= 0, the Lisp string is an
5527 next_element_from_string (it
)
5530 struct text_pos position
;
5532 xassert (STRINGP (it
->string
));
5533 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5534 position
= it
->current
.string_pos
;
5536 /* Time to check for invisible text? */
5537 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5538 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5542 /* Since a handler may have changed IT->method, we must
5544 return get_next_display_element (it
);
5547 if (it
->current
.overlay_string_index
>= 0)
5549 /* Get the next character from an overlay string. In overlay
5550 strings, There is no field width or padding with spaces to
5552 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5557 else if (STRING_MULTIBYTE (it
->string
))
5559 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5560 const unsigned char *s
= (SDATA (it
->string
)
5561 + IT_STRING_BYTEPOS (*it
));
5562 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5566 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5572 /* Get the next character from a Lisp string that is not an
5573 overlay string. Such strings come from the mode line, for
5574 example. We may have to pad with spaces, or truncate the
5575 string. See also next_element_from_c_string. */
5576 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5581 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5583 /* Pad with spaces. */
5584 it
->c
= ' ', it
->len
= 1;
5585 CHARPOS (position
) = BYTEPOS (position
) = -1;
5587 else if (STRING_MULTIBYTE (it
->string
))
5589 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5590 const unsigned char *s
= (SDATA (it
->string
)
5591 + IT_STRING_BYTEPOS (*it
));
5592 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5596 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5601 /* Record what we have and where it came from. Note that we store a
5602 buffer position in IT->position although it could arguably be a
5604 it
->what
= IT_CHARACTER
;
5605 it
->object
= it
->string
;
5606 it
->position
= position
;
5611 /* Load IT with next display element from C string IT->s.
5612 IT->string_nchars is the maximum number of characters to return
5613 from the string. IT->end_charpos may be greater than
5614 IT->string_nchars when this function is called, in which case we
5615 may have to return padding spaces. Value is zero if end of string
5616 reached, including padding spaces. */
5619 next_element_from_c_string (it
)
5625 it
->what
= IT_CHARACTER
;
5626 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5629 /* IT's position can be greater IT->string_nchars in case a field
5630 width or precision has been specified when the iterator was
5632 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5634 /* End of the game. */
5638 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5640 /* Pad with spaces. */
5641 it
->c
= ' ', it
->len
= 1;
5642 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5644 else if (it
->multibyte_p
)
5646 /* Implementation note: The calls to strlen apparently aren't a
5647 performance problem because there is no noticeable performance
5648 difference between Emacs running in unibyte or multibyte mode. */
5649 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5650 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5654 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5660 /* Set up IT to return characters from an ellipsis, if appropriate.
5661 The definition of the ellipsis glyphs may come from a display table
5662 entry. This function Fills IT with the first glyph from the
5663 ellipsis if an ellipsis is to be displayed. */
5666 next_element_from_ellipsis (it
)
5669 if (it
->selective_display_ellipsis_p
)
5670 setup_for_ellipsis (it
, it
->len
);
5673 /* The face at the current position may be different from the
5674 face we find after the invisible text. Remember what it
5675 was in IT->saved_face_id, and signal that it's there by
5676 setting face_before_selective_p. */
5677 it
->saved_face_id
= it
->face_id
;
5678 it
->method
= GET_FROM_BUFFER
;
5679 reseat_at_next_visible_line_start (it
, 1);
5680 it
->face_before_selective_p
= 1;
5683 return get_next_display_element (it
);
5687 /* Deliver an image display element. The iterator IT is already
5688 filled with image information (done in handle_display_prop). Value
5693 next_element_from_image (it
)
5696 it
->what
= IT_IMAGE
;
5701 /* Fill iterator IT with next display element from a stretch glyph
5702 property. IT->object is the value of the text property. Value is
5706 next_element_from_stretch (it
)
5709 it
->what
= IT_STRETCH
;
5714 /* Load IT with the next display element from current_buffer. Value
5715 is zero if end of buffer reached. IT->stop_charpos is the next
5716 position at which to stop and check for text properties or buffer
5720 next_element_from_buffer (it
)
5725 /* Check this assumption, otherwise, we would never enter the
5726 if-statement, below. */
5727 xassert (IT_CHARPOS (*it
) >= BEGV
5728 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5730 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5732 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5734 int overlay_strings_follow_p
;
5736 /* End of the game, except when overlay strings follow that
5737 haven't been returned yet. */
5738 if (it
->overlay_strings_at_end_processed_p
)
5739 overlay_strings_follow_p
= 0;
5742 it
->overlay_strings_at_end_processed_p
= 1;
5743 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5746 if (overlay_strings_follow_p
)
5747 success_p
= get_next_display_element (it
);
5751 it
->position
= it
->current
.pos
;
5758 return get_next_display_element (it
);
5763 /* No face changes, overlays etc. in sight, so just return a
5764 character from current_buffer. */
5767 /* Maybe run the redisplay end trigger hook. Performance note:
5768 This doesn't seem to cost measurable time. */
5769 if (it
->redisplay_end_trigger_charpos
5771 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5772 run_redisplay_end_trigger_hook (it
);
5774 /* Get the next character, maybe multibyte. */
5775 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5776 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5778 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5779 - IT_BYTEPOS (*it
));
5780 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5783 it
->c
= *p
, it
->len
= 1;
5785 /* Record what we have and where it came from. */
5786 it
->what
= IT_CHARACTER
;;
5787 it
->object
= it
->w
->buffer
;
5788 it
->position
= it
->current
.pos
;
5790 /* Normally we return the character found above, except when we
5791 really want to return an ellipsis for selective display. */
5796 /* A value of selective > 0 means hide lines indented more
5797 than that number of columns. */
5798 if (it
->selective
> 0
5799 && IT_CHARPOS (*it
) + 1 < ZV
5800 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5801 IT_BYTEPOS (*it
) + 1,
5802 (double) it
->selective
)) /* iftc */
5804 success_p
= next_element_from_ellipsis (it
);
5805 it
->dpvec_char_len
= -1;
5808 else if (it
->c
== '\r' && it
->selective
== -1)
5810 /* A value of selective == -1 means that everything from the
5811 CR to the end of the line is invisible, with maybe an
5812 ellipsis displayed for it. */
5813 success_p
= next_element_from_ellipsis (it
);
5814 it
->dpvec_char_len
= -1;
5819 /* Value is zero if end of buffer reached. */
5820 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5825 /* Run the redisplay end trigger hook for IT. */
5828 run_redisplay_end_trigger_hook (it
)
5831 Lisp_Object args
[3];
5833 /* IT->glyph_row should be non-null, i.e. we should be actually
5834 displaying something, or otherwise we should not run the hook. */
5835 xassert (it
->glyph_row
);
5837 /* Set up hook arguments. */
5838 args
[0] = Qredisplay_end_trigger_functions
;
5839 args
[1] = it
->window
;
5840 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5841 it
->redisplay_end_trigger_charpos
= 0;
5843 /* Since we are *trying* to run these functions, don't try to run
5844 them again, even if they get an error. */
5845 it
->w
->redisplay_end_trigger
= Qnil
;
5846 Frun_hook_with_args (3, args
);
5848 /* Notice if it changed the face of the character we are on. */
5849 handle_face_prop (it
);
5853 /* Deliver a composition display element. The iterator IT is already
5854 filled with composition information (done in
5855 handle_composition_prop). Value is always 1. */
5858 next_element_from_composition (it
)
5861 it
->what
= IT_COMPOSITION
;
5862 it
->position
= (STRINGP (it
->string
)
5863 ? it
->current
.string_pos
5870 /***********************************************************************
5871 Moving an iterator without producing glyphs
5872 ***********************************************************************/
5874 /* Move iterator IT to a specified buffer or X position within one
5875 line on the display without producing glyphs.
5877 OP should be a bit mask including some or all of these bits:
5878 MOVE_TO_X: Stop on reaching x-position TO_X.
5879 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5880 Regardless of OP's value, stop in reaching the end of the display line.
5882 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5883 This means, in particular, that TO_X includes window's horizontal
5886 The return value has several possible values that
5887 say what condition caused the scan to stop:
5889 MOVE_POS_MATCH_OR_ZV
5890 - when TO_POS or ZV was reached.
5893 -when TO_X was reached before TO_POS or ZV were reached.
5896 - when we reached the end of the display area and the line must
5900 - when we reached the end of the display area and the line is
5904 - when we stopped at a line end, i.e. a newline or a CR and selective
5907 static enum move_it_result
5908 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5910 int to_charpos
, to_x
, op
;
5912 enum move_it_result result
= MOVE_UNDEFINED
;
5913 struct glyph_row
*saved_glyph_row
;
5915 /* Don't produce glyphs in produce_glyphs. */
5916 saved_glyph_row
= it
->glyph_row
;
5917 it
->glyph_row
= NULL
;
5919 #define BUFFER_POS_REACHED_P() \
5920 ((op & MOVE_TO_POS) != 0 \
5921 && BUFFERP (it->object) \
5922 && IT_CHARPOS (*it) >= to_charpos \
5923 && (it->method == GET_FROM_BUFFER \
5924 || (it->method == GET_FROM_DISPLAY_VECTOR \
5925 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
5930 int x
, i
, ascent
= 0, descent
= 0;
5932 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
5933 if ((op
& MOVE_TO_POS
) != 0
5934 && BUFFERP (it
->object
)
5935 && it
->method
== GET_FROM_BUFFER
5936 && IT_CHARPOS (*it
) > to_charpos
)
5938 result
= MOVE_POS_MATCH_OR_ZV
;
5942 /* Stop when ZV reached.
5943 We used to stop here when TO_CHARPOS reached as well, but that is
5944 too soon if this glyph does not fit on this line. So we handle it
5945 explicitly below. */
5946 if (!get_next_display_element (it
)
5947 || (it
->truncate_lines_p
5948 && BUFFER_POS_REACHED_P ()))
5950 result
= MOVE_POS_MATCH_OR_ZV
;
5954 /* The call to produce_glyphs will get the metrics of the
5955 display element IT is loaded with. We record in x the
5956 x-position before this display element in case it does not
5960 /* Remember the line height so far in case the next element doesn't
5962 if (!it
->truncate_lines_p
)
5964 ascent
= it
->max_ascent
;
5965 descent
= it
->max_descent
;
5968 PRODUCE_GLYPHS (it
);
5970 if (it
->area
!= TEXT_AREA
)
5972 set_iterator_to_next (it
, 1);
5976 /* The number of glyphs we get back in IT->nglyphs will normally
5977 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5978 character on a terminal frame, or (iii) a line end. For the
5979 second case, IT->nglyphs - 1 padding glyphs will be present
5980 (on X frames, there is only one glyph produced for a
5981 composite character.
5983 The behavior implemented below means, for continuation lines,
5984 that as many spaces of a TAB as fit on the current line are
5985 displayed there. For terminal frames, as many glyphs of a
5986 multi-glyph character are displayed in the current line, too.
5987 This is what the old redisplay code did, and we keep it that
5988 way. Under X, the whole shape of a complex character must
5989 fit on the line or it will be completely displayed in the
5992 Note that both for tabs and padding glyphs, all glyphs have
5996 /* More than one glyph or glyph doesn't fit on line. All
5997 glyphs have the same width. */
5998 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6001 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6003 new_x
= x
+ single_glyph_width
;
6005 /* We want to leave anything reaching TO_X to the caller. */
6006 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6008 if (BUFFER_POS_REACHED_P ())
6009 goto buffer_pos_reached
;
6011 result
= MOVE_X_REACHED
;
6014 else if (/* Lines are continued. */
6015 !it
->truncate_lines_p
6016 && (/* And glyph doesn't fit on the line. */
6017 new_x
> it
->last_visible_x
6018 /* Or it fits exactly and we're on a window
6020 || (new_x
== it
->last_visible_x
6021 && FRAME_WINDOW_P (it
->f
))))
6023 if (/* IT->hpos == 0 means the very first glyph
6024 doesn't fit on the line, e.g. a wide image. */
6026 || (new_x
== it
->last_visible_x
6027 && FRAME_WINDOW_P (it
->f
)))
6030 it
->current_x
= new_x
;
6031 if (i
== it
->nglyphs
- 1)
6033 set_iterator_to_next (it
, 1);
6034 #ifdef HAVE_WINDOW_SYSTEM
6035 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6037 if (!get_next_display_element (it
))
6039 result
= MOVE_POS_MATCH_OR_ZV
;
6042 if (BUFFER_POS_REACHED_P ())
6044 if (ITERATOR_AT_END_OF_LINE_P (it
))
6045 result
= MOVE_POS_MATCH_OR_ZV
;
6047 result
= MOVE_LINE_CONTINUED
;
6050 if (ITERATOR_AT_END_OF_LINE_P (it
))
6052 result
= MOVE_NEWLINE_OR_CR
;
6056 #endif /* HAVE_WINDOW_SYSTEM */
6062 it
->max_ascent
= ascent
;
6063 it
->max_descent
= descent
;
6066 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6068 result
= MOVE_LINE_CONTINUED
;
6071 else if (BUFFER_POS_REACHED_P ())
6072 goto buffer_pos_reached
;
6073 else if (new_x
> it
->first_visible_x
)
6075 /* Glyph is visible. Increment number of glyphs that
6076 would be displayed. */
6081 /* Glyph is completely off the left margin of the display
6082 area. Nothing to do. */
6086 if (result
!= MOVE_UNDEFINED
)
6089 else if (BUFFER_POS_REACHED_P ())
6093 it
->max_ascent
= ascent
;
6094 it
->max_descent
= descent
;
6095 result
= MOVE_POS_MATCH_OR_ZV
;
6098 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6100 /* Stop when TO_X specified and reached. This check is
6101 necessary here because of lines consisting of a line end,
6102 only. The line end will not produce any glyphs and we
6103 would never get MOVE_X_REACHED. */
6104 xassert (it
->nglyphs
== 0);
6105 result
= MOVE_X_REACHED
;
6109 /* Is this a line end? If yes, we're done. */
6110 if (ITERATOR_AT_END_OF_LINE_P (it
))
6112 result
= MOVE_NEWLINE_OR_CR
;
6116 /* The current display element has been consumed. Advance
6118 set_iterator_to_next (it
, 1);
6120 /* Stop if lines are truncated and IT's current x-position is
6121 past the right edge of the window now. */
6122 if (it
->truncate_lines_p
6123 && it
->current_x
>= it
->last_visible_x
)
6125 #ifdef HAVE_WINDOW_SYSTEM
6126 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6128 if (!get_next_display_element (it
)
6129 || BUFFER_POS_REACHED_P ())
6131 result
= MOVE_POS_MATCH_OR_ZV
;
6134 if (ITERATOR_AT_END_OF_LINE_P (it
))
6136 result
= MOVE_NEWLINE_OR_CR
;
6140 #endif /* HAVE_WINDOW_SYSTEM */
6141 result
= MOVE_LINE_TRUNCATED
;
6146 #undef BUFFER_POS_REACHED_P
6148 /* Restore the iterator settings altered at the beginning of this
6150 it
->glyph_row
= saved_glyph_row
;
6155 /* Move IT forward until it satisfies one or more of the criteria in
6156 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6158 OP is a bit-mask that specifies where to stop, and in particular,
6159 which of those four position arguments makes a difference. See the
6160 description of enum move_operation_enum.
6162 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6163 screen line, this function will set IT to the next position >
6167 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6169 int to_charpos
, to_x
, to_y
, to_vpos
;
6172 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6178 if (op
& MOVE_TO_VPOS
)
6180 /* If no TO_CHARPOS and no TO_X specified, stop at the
6181 start of the line TO_VPOS. */
6182 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6184 if (it
->vpos
== to_vpos
)
6190 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6194 /* TO_VPOS >= 0 means stop at TO_X in the line at
6195 TO_VPOS, or at TO_POS, whichever comes first. */
6196 if (it
->vpos
== to_vpos
)
6202 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6204 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6209 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6211 /* We have reached TO_X but not in the line we want. */
6212 skip
= move_it_in_display_line_to (it
, to_charpos
,
6214 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6222 else if (op
& MOVE_TO_Y
)
6224 struct it it_backup
;
6226 /* TO_Y specified means stop at TO_X in the line containing
6227 TO_Y---or at TO_CHARPOS if this is reached first. The
6228 problem is that we can't really tell whether the line
6229 contains TO_Y before we have completely scanned it, and
6230 this may skip past TO_X. What we do is to first scan to
6233 If TO_X is not specified, use a TO_X of zero. The reason
6234 is to make the outcome of this function more predictable.
6235 If we didn't use TO_X == 0, we would stop at the end of
6236 the line which is probably not what a caller would expect
6238 skip
= move_it_in_display_line_to (it
, to_charpos
,
6242 | (op
& MOVE_TO_POS
)));
6244 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6245 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6251 /* If TO_X was reached, we would like to know whether TO_Y
6252 is in the line. This can only be said if we know the
6253 total line height which requires us to scan the rest of
6255 if (skip
== MOVE_X_REACHED
)
6258 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6259 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6261 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6264 /* Now, decide whether TO_Y is in this line. */
6265 line_height
= it
->max_ascent
+ it
->max_descent
;
6266 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6268 if (to_y
>= it
->current_y
6269 && to_y
< it
->current_y
+ line_height
)
6271 if (skip
== MOVE_X_REACHED
)
6272 /* If TO_Y is in this line and TO_X was reached above,
6273 we scanned too far. We have to restore IT's settings
6274 to the ones before skipping. */
6278 else if (skip
== MOVE_X_REACHED
)
6281 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6289 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6293 case MOVE_POS_MATCH_OR_ZV
:
6297 case MOVE_NEWLINE_OR_CR
:
6298 set_iterator_to_next (it
, 1);
6299 it
->continuation_lines_width
= 0;
6302 case MOVE_LINE_TRUNCATED
:
6303 it
->continuation_lines_width
= 0;
6304 reseat_at_next_visible_line_start (it
, 0);
6305 if ((op
& MOVE_TO_POS
) != 0
6306 && IT_CHARPOS (*it
) > to_charpos
)
6313 case MOVE_LINE_CONTINUED
:
6314 it
->continuation_lines_width
+= it
->current_x
;
6321 /* Reset/increment for the next run. */
6322 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6323 it
->current_x
= it
->hpos
= 0;
6324 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6326 last_height
= it
->max_ascent
+ it
->max_descent
;
6327 last_max_ascent
= it
->max_ascent
;
6328 it
->max_ascent
= it
->max_descent
= 0;
6333 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6337 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6339 If DY > 0, move IT backward at least that many pixels. DY = 0
6340 means move IT backward to the preceding line start or BEGV. This
6341 function may move over more than DY pixels if IT->current_y - DY
6342 ends up in the middle of a line; in this case IT->current_y will be
6343 set to the top of the line moved to. */
6346 move_it_vertically_backward (it
, dy
)
6357 start_pos
= IT_CHARPOS (*it
);
6359 /* Estimate how many newlines we must move back. */
6360 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6362 /* Set the iterator's position that many lines back. */
6363 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6364 back_to_previous_visible_line_start (it
);
6366 /* Reseat the iterator here. When moving backward, we don't want
6367 reseat to skip forward over invisible text, set up the iterator
6368 to deliver from overlay strings at the new position etc. So,
6369 use reseat_1 here. */
6370 reseat_1 (it
, it
->current
.pos
, 1);
6372 /* We are now surely at a line start. */
6373 it
->current_x
= it
->hpos
= 0;
6374 it
->continuation_lines_width
= 0;
6376 /* Move forward and see what y-distance we moved. First move to the
6377 start of the next line so that we get its height. We need this
6378 height to be able to tell whether we reached the specified
6381 it2
.max_ascent
= it2
.max_descent
= 0;
6382 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6383 MOVE_TO_POS
| MOVE_TO_VPOS
);
6384 xassert (IT_CHARPOS (*it
) >= BEGV
);
6387 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6388 xassert (IT_CHARPOS (*it
) >= BEGV
);
6389 /* H is the actual vertical distance from the position in *IT
6390 and the starting position. */
6391 h
= it2
.current_y
- it
->current_y
;
6392 /* NLINES is the distance in number of lines. */
6393 nlines
= it2
.vpos
- it
->vpos
;
6395 /* Correct IT's y and vpos position
6396 so that they are relative to the starting point. */
6402 /* DY == 0 means move to the start of the screen line. The
6403 value of nlines is > 0 if continuation lines were involved. */
6405 move_it_by_lines (it
, nlines
, 1);
6407 /* I think this assert is bogus if buffer contains
6408 invisible text or images. KFS. */
6409 xassert (IT_CHARPOS (*it
) <= start_pos
);
6414 /* The y-position we try to reach, relative to *IT.
6415 Note that H has been subtracted in front of the if-statement. */
6416 int target_y
= it
->current_y
+ h
- dy
;
6417 int y0
= it3
.current_y
;
6418 int y1
= line_bottom_y (&it3
);
6419 int line_height
= y1
- y0
;
6421 /* If we did not reach target_y, try to move further backward if
6422 we can. If we moved too far backward, try to move forward. */
6423 if (target_y
< it
->current_y
6424 /* This is heuristic. In a window that's 3 lines high, with
6425 a line height of 13 pixels each, recentering with point
6426 on the bottom line will try to move -39/2 = 19 pixels
6427 backward. Try to avoid moving into the first line. */
6428 && (it
->current_y
- target_y
6429 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6430 && IT_CHARPOS (*it
) > BEGV
)
6432 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6433 target_y
- it
->current_y
));
6434 dy
= it
->current_y
- target_y
;
6435 goto move_further_back
;
6437 else if (target_y
>= it
->current_y
+ line_height
6438 && IT_CHARPOS (*it
) < ZV
)
6440 /* Should move forward by at least one line, maybe more.
6442 Note: Calling move_it_by_lines can be expensive on
6443 terminal frames, where compute_motion is used (via
6444 vmotion) to do the job, when there are very long lines
6445 and truncate-lines is nil. That's the reason for
6446 treating terminal frames specially here. */
6448 if (!FRAME_WINDOW_P (it
->f
))
6449 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6454 move_it_by_lines (it
, 1, 1);
6456 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6460 /* I think this assert is bogus if buffer contains
6461 invisible text or images. KFS. */
6462 xassert (IT_CHARPOS (*it
) >= BEGV
);
6469 /* Move IT by a specified amount of pixel lines DY. DY negative means
6470 move backwards. DY = 0 means move to start of screen line. At the
6471 end, IT will be on the start of a screen line. */
6474 move_it_vertically (it
, dy
)
6479 move_it_vertically_backward (it
, -dy
);
6482 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6483 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6484 MOVE_TO_POS
| MOVE_TO_Y
);
6485 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6487 /* If buffer ends in ZV without a newline, move to the start of
6488 the line to satisfy the post-condition. */
6489 if (IT_CHARPOS (*it
) == ZV
6490 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6491 move_it_by_lines (it
, 0, 0);
6496 /* Move iterator IT past the end of the text line it is in. */
6499 move_it_past_eol (it
)
6502 enum move_it_result rc
;
6504 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6505 if (rc
== MOVE_NEWLINE_OR_CR
)
6506 set_iterator_to_next (it
, 0);
6510 #if 0 /* Currently not used. */
6512 /* Return non-zero if some text between buffer positions START_CHARPOS
6513 and END_CHARPOS is invisible. IT->window is the window for text
6517 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6519 int start_charpos
, end_charpos
;
6521 Lisp_Object prop
, limit
;
6522 int invisible_found_p
;
6524 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6526 /* Is text at START invisible? */
6527 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6529 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6530 invisible_found_p
= 1;
6533 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6535 make_number (end_charpos
));
6536 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6539 return invisible_found_p
;
6545 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6546 negative means move up. DVPOS == 0 means move to the start of the
6547 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6548 NEED_Y_P is zero, IT->current_y will be left unchanged.
6550 Further optimization ideas: If we would know that IT->f doesn't use
6551 a face with proportional font, we could be faster for
6552 truncate-lines nil. */
6555 move_it_by_lines (it
, dvpos
, need_y_p
)
6557 int dvpos
, need_y_p
;
6559 struct position pos
;
6561 if (!FRAME_WINDOW_P (it
->f
))
6563 struct text_pos textpos
;
6565 /* We can use vmotion on frames without proportional fonts. */
6566 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6567 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6568 reseat (it
, textpos
, 1);
6569 it
->vpos
+= pos
.vpos
;
6570 it
->current_y
+= pos
.vpos
;
6572 else if (dvpos
== 0)
6574 /* DVPOS == 0 means move to the start of the screen line. */
6575 move_it_vertically_backward (it
, 0);
6576 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6577 /* Let next call to line_bottom_y calculate real line height */
6581 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6585 int start_charpos
, i
;
6587 /* Start at the beginning of the screen line containing IT's
6589 move_it_vertically_backward (it
, 0);
6591 /* Go back -DVPOS visible lines and reseat the iterator there. */
6592 start_charpos
= IT_CHARPOS (*it
);
6593 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
6594 back_to_previous_visible_line_start (it
);
6595 reseat (it
, it
->current
.pos
, 1);
6596 it
->current_x
= it
->hpos
= 0;
6598 /* Above call may have moved too far if continuation lines
6599 are involved. Scan forward and see if it did. */
6601 it2
.vpos
= it2
.current_y
= 0;
6602 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6603 it
->vpos
-= it2
.vpos
;
6604 it
->current_y
-= it2
.current_y
;
6605 it
->current_x
= it
->hpos
= 0;
6607 /* If we moved too far back, move IT some lines forward. */
6608 if (it2
.vpos
> -dvpos
)
6610 int delta
= it2
.vpos
+ dvpos
;
6612 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6613 /* Move back again if we got too far ahead. */
6614 if (IT_CHARPOS (*it
) >= start_charpos
)
6620 /* Return 1 if IT points into the middle of a display vector. */
6623 in_display_vector_p (it
)
6626 return (it
->method
== GET_FROM_DISPLAY_VECTOR
6627 && it
->current
.dpvec_index
> 0
6628 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6632 /***********************************************************************
6634 ***********************************************************************/
6637 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6641 add_to_log (format
, arg1
, arg2
)
6643 Lisp_Object arg1
, arg2
;
6645 Lisp_Object args
[3];
6646 Lisp_Object msg
, fmt
;
6649 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6652 /* Do nothing if called asynchronously. Inserting text into
6653 a buffer may call after-change-functions and alike and
6654 that would means running Lisp asynchronously. */
6655 if (handling_signal
)
6659 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6661 args
[0] = fmt
= build_string (format
);
6664 msg
= Fformat (3, args
);
6666 len
= SBYTES (msg
) + 1;
6667 SAFE_ALLOCA (buffer
, char *, len
);
6668 bcopy (SDATA (msg
), buffer
, len
);
6670 message_dolog (buffer
, len
- 1, 1, 0);
6677 /* Output a newline in the *Messages* buffer if "needs" one. */
6680 message_log_maybe_newline ()
6682 if (message_log_need_newline
)
6683 message_dolog ("", 0, 1, 0);
6687 /* Add a string M of length NBYTES to the message log, optionally
6688 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6689 nonzero, means interpret the contents of M as multibyte. This
6690 function calls low-level routines in order to bypass text property
6691 hooks, etc. which might not be safe to run. */
6694 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6696 int nbytes
, nlflag
, multibyte
;
6698 if (!NILP (Vmemory_full
))
6701 if (!NILP (Vmessage_log_max
))
6703 struct buffer
*oldbuf
;
6704 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6705 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6706 int point_at_end
= 0;
6708 Lisp_Object old_deactivate_mark
, tem
;
6709 struct gcpro gcpro1
;
6711 old_deactivate_mark
= Vdeactivate_mark
;
6712 oldbuf
= current_buffer
;
6713 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6714 current_buffer
->undo_list
= Qt
;
6716 oldpoint
= message_dolog_marker1
;
6717 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6718 oldbegv
= message_dolog_marker2
;
6719 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6720 oldzv
= message_dolog_marker3
;
6721 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6722 GCPRO1 (old_deactivate_mark
);
6730 BEGV_BYTE
= BEG_BYTE
;
6733 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6735 /* Insert the string--maybe converting multibyte to single byte
6736 or vice versa, so that all the text fits the buffer. */
6738 && NILP (current_buffer
->enable_multibyte_characters
))
6740 int i
, c
, char_bytes
;
6741 unsigned char work
[1];
6743 /* Convert a multibyte string to single-byte
6744 for the *Message* buffer. */
6745 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6747 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6748 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6750 : multibyte_char_to_unibyte (c
, Qnil
));
6751 insert_1_both (work
, 1, 1, 1, 0, 0);
6754 else if (! multibyte
6755 && ! NILP (current_buffer
->enable_multibyte_characters
))
6757 int i
, c
, char_bytes
;
6758 unsigned char *msg
= (unsigned char *) m
;
6759 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6760 /* Convert a single-byte string to multibyte
6761 for the *Message* buffer. */
6762 for (i
= 0; i
< nbytes
; i
++)
6764 c
= unibyte_char_to_multibyte (msg
[i
]);
6765 char_bytes
= CHAR_STRING (c
, str
);
6766 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6770 insert_1 (m
, nbytes
, 1, 0, 0);
6774 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6775 insert_1 ("\n", 1, 1, 0, 0);
6777 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6779 this_bol_byte
= PT_BYTE
;
6781 /* See if this line duplicates the previous one.
6782 If so, combine duplicates. */
6785 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6787 prev_bol_byte
= PT_BYTE
;
6789 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6790 this_bol
, this_bol_byte
);
6793 del_range_both (prev_bol
, prev_bol_byte
,
6794 this_bol
, this_bol_byte
, 0);
6800 /* If you change this format, don't forget to also
6801 change message_log_check_duplicate. */
6802 sprintf (dupstr
, " [%d times]", dup
);
6803 duplen
= strlen (dupstr
);
6804 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6805 insert_1 (dupstr
, duplen
, 1, 0, 1);
6810 /* If we have more than the desired maximum number of lines
6811 in the *Messages* buffer now, delete the oldest ones.
6812 This is safe because we don't have undo in this buffer. */
6814 if (NATNUMP (Vmessage_log_max
))
6816 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6817 -XFASTINT (Vmessage_log_max
) - 1, 0);
6818 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6821 BEGV
= XMARKER (oldbegv
)->charpos
;
6822 BEGV_BYTE
= marker_byte_position (oldbegv
);
6831 ZV
= XMARKER (oldzv
)->charpos
;
6832 ZV_BYTE
= marker_byte_position (oldzv
);
6836 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6838 /* We can't do Fgoto_char (oldpoint) because it will run some
6840 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6841 XMARKER (oldpoint
)->bytepos
);
6844 unchain_marker (XMARKER (oldpoint
));
6845 unchain_marker (XMARKER (oldbegv
));
6846 unchain_marker (XMARKER (oldzv
));
6848 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6849 set_buffer_internal (oldbuf
);
6851 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6852 message_log_need_newline
= !nlflag
;
6853 Vdeactivate_mark
= old_deactivate_mark
;
6858 /* We are at the end of the buffer after just having inserted a newline.
6859 (Note: We depend on the fact we won't be crossing the gap.)
6860 Check to see if the most recent message looks a lot like the previous one.
6861 Return 0 if different, 1 if the new one should just replace it, or a
6862 value N > 1 if we should also append " [N times]". */
6865 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6866 int prev_bol
, this_bol
;
6867 int prev_bol_byte
, this_bol_byte
;
6870 int len
= Z_BYTE
- 1 - this_bol_byte
;
6872 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6873 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6875 for (i
= 0; i
< len
; i
++)
6877 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6885 if (*p1
++ == ' ' && *p1
++ == '[')
6888 while (*p1
>= '0' && *p1
<= '9')
6889 n
= n
* 10 + *p1
++ - '0';
6890 if (strncmp (p1
, " times]\n", 8) == 0)
6897 /* Display an echo area message M with a specified length of NBYTES
6898 bytes. The string may include null characters. If M is 0, clear
6899 out any existing message, and let the mini-buffer text show
6902 The buffer M must continue to exist until after the echo area gets
6903 cleared or some other message gets displayed there. This means do
6904 not pass text that is stored in a Lisp string; do not pass text in
6905 a buffer that was alloca'd. */
6908 message2 (m
, nbytes
, multibyte
)
6913 /* First flush out any partial line written with print. */
6914 message_log_maybe_newline ();
6916 message_dolog (m
, nbytes
, 1, multibyte
);
6917 message2_nolog (m
, nbytes
, multibyte
);
6921 /* The non-logging counterpart of message2. */
6924 message2_nolog (m
, nbytes
, multibyte
)
6926 int nbytes
, multibyte
;
6928 struct frame
*sf
= SELECTED_FRAME ();
6929 message_enable_multibyte
= multibyte
;
6933 if (noninteractive_need_newline
)
6934 putc ('\n', stderr
);
6935 noninteractive_need_newline
= 0;
6937 fwrite (m
, nbytes
, 1, stderr
);
6938 if (cursor_in_echo_area
== 0)
6939 fprintf (stderr
, "\n");
6942 /* A null message buffer means that the frame hasn't really been
6943 initialized yet. Error messages get reported properly by
6944 cmd_error, so this must be just an informative message; toss it. */
6945 else if (INTERACTIVE
6946 && sf
->glyphs_initialized_p
6947 && FRAME_MESSAGE_BUF (sf
))
6949 Lisp_Object mini_window
;
6952 /* Get the frame containing the mini-buffer
6953 that the selected frame is using. */
6954 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6955 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6957 FRAME_SAMPLE_VISIBILITY (f
);
6958 if (FRAME_VISIBLE_P (sf
)
6959 && ! FRAME_VISIBLE_P (f
))
6960 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
6964 set_message (m
, Qnil
, nbytes
, multibyte
);
6965 if (minibuffer_auto_raise
)
6966 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
6969 clear_message (1, 1);
6971 do_pending_window_change (0);
6972 echo_area_display (1);
6973 do_pending_window_change (0);
6974 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
6975 (*frame_up_to_date_hook
) (f
);
6980 /* Display an echo area message M with a specified length of NBYTES
6981 bytes. The string may include null characters. If M is not a
6982 string, clear out any existing message, and let the mini-buffer
6985 This function cancels echoing. */
6988 message3 (m
, nbytes
, multibyte
)
6993 struct gcpro gcpro1
;
6996 clear_message (1,1);
6999 /* First flush out any partial line written with print. */
7000 message_log_maybe_newline ();
7002 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
7003 message3_nolog (m
, nbytes
, multibyte
);
7009 /* The non-logging version of message3.
7010 This does not cancel echoing, because it is used for echoing.
7011 Perhaps we need to make a separate function for echoing
7012 and make this cancel echoing. */
7015 message3_nolog (m
, nbytes
, multibyte
)
7017 int nbytes
, multibyte
;
7019 struct frame
*sf
= SELECTED_FRAME ();
7020 message_enable_multibyte
= multibyte
;
7024 if (noninteractive_need_newline
)
7025 putc ('\n', stderr
);
7026 noninteractive_need_newline
= 0;
7028 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7029 if (cursor_in_echo_area
== 0)
7030 fprintf (stderr
, "\n");
7033 /* A null message buffer means that the frame hasn't really been
7034 initialized yet. Error messages get reported properly by
7035 cmd_error, so this must be just an informative message; toss it. */
7036 else if (INTERACTIVE
7037 && sf
->glyphs_initialized_p
7038 && FRAME_MESSAGE_BUF (sf
))
7040 Lisp_Object mini_window
;
7044 /* Get the frame containing the mini-buffer
7045 that the selected frame is using. */
7046 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7047 frame
= XWINDOW (mini_window
)->frame
;
7050 FRAME_SAMPLE_VISIBILITY (f
);
7051 if (FRAME_VISIBLE_P (sf
)
7052 && !FRAME_VISIBLE_P (f
))
7053 Fmake_frame_visible (frame
);
7055 if (STRINGP (m
) && SCHARS (m
) > 0)
7057 set_message (NULL
, m
, nbytes
, multibyte
);
7058 if (minibuffer_auto_raise
)
7059 Fraise_frame (frame
);
7062 clear_message (1, 1);
7064 do_pending_window_change (0);
7065 echo_area_display (1);
7066 do_pending_window_change (0);
7067 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7068 (*frame_up_to_date_hook
) (f
);
7073 /* Display a null-terminated echo area message M. If M is 0, clear
7074 out any existing message, and let the mini-buffer text show through.
7076 The buffer M must continue to exist until after the echo area gets
7077 cleared or some other message gets displayed there. Do not pass
7078 text that is stored in a Lisp string. Do not pass text in a buffer
7079 that was alloca'd. */
7085 message2 (m
, (m
? strlen (m
) : 0), 0);
7089 /* The non-logging counterpart of message1. */
7095 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7098 /* Display a message M which contains a single %s
7099 which gets replaced with STRING. */
7102 message_with_string (m
, string
, log
)
7107 CHECK_STRING (string
);
7113 if (noninteractive_need_newline
)
7114 putc ('\n', stderr
);
7115 noninteractive_need_newline
= 0;
7116 fprintf (stderr
, m
, SDATA (string
));
7117 if (cursor_in_echo_area
== 0)
7118 fprintf (stderr
, "\n");
7122 else if (INTERACTIVE
)
7124 /* The frame whose minibuffer we're going to display the message on.
7125 It may be larger than the selected frame, so we need
7126 to use its buffer, not the selected frame's buffer. */
7127 Lisp_Object mini_window
;
7128 struct frame
*f
, *sf
= SELECTED_FRAME ();
7130 /* Get the frame containing the minibuffer
7131 that the selected frame is using. */
7132 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7133 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7135 /* A null message buffer means that the frame hasn't really been
7136 initialized yet. Error messages get reported properly by
7137 cmd_error, so this must be just an informative message; toss it. */
7138 if (FRAME_MESSAGE_BUF (f
))
7140 Lisp_Object args
[2], message
;
7141 struct gcpro gcpro1
, gcpro2
;
7143 args
[0] = build_string (m
);
7144 args
[1] = message
= string
;
7145 GCPRO2 (args
[0], message
);
7148 message
= Fformat (2, args
);
7151 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7153 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7157 /* Print should start at the beginning of the message
7158 buffer next time. */
7159 message_buf_print
= 0;
7165 /* Dump an informative message to the minibuf. If M is 0, clear out
7166 any existing message, and let the mini-buffer text show through. */
7170 message (m
, a1
, a2
, a3
)
7172 EMACS_INT a1
, a2
, a3
;
7178 if (noninteractive_need_newline
)
7179 putc ('\n', stderr
);
7180 noninteractive_need_newline
= 0;
7181 fprintf (stderr
, m
, a1
, a2
, a3
);
7182 if (cursor_in_echo_area
== 0)
7183 fprintf (stderr
, "\n");
7187 else if (INTERACTIVE
)
7189 /* The frame whose mini-buffer we're going to display the message
7190 on. It may be larger than the selected frame, so we need to
7191 use its buffer, not the selected frame's buffer. */
7192 Lisp_Object mini_window
;
7193 struct frame
*f
, *sf
= SELECTED_FRAME ();
7195 /* Get the frame containing the mini-buffer
7196 that the selected frame is using. */
7197 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7198 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7200 /* A null message buffer means that the frame hasn't really been
7201 initialized yet. Error messages get reported properly by
7202 cmd_error, so this must be just an informative message; toss
7204 if (FRAME_MESSAGE_BUF (f
))
7215 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7216 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7218 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7219 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7221 #endif /* NO_ARG_ARRAY */
7223 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7228 /* Print should start at the beginning of the message
7229 buffer next time. */
7230 message_buf_print
= 0;
7236 /* The non-logging version of message. */
7239 message_nolog (m
, a1
, a2
, a3
)
7241 EMACS_INT a1
, a2
, a3
;
7243 Lisp_Object old_log_max
;
7244 old_log_max
= Vmessage_log_max
;
7245 Vmessage_log_max
= Qnil
;
7246 message (m
, a1
, a2
, a3
);
7247 Vmessage_log_max
= old_log_max
;
7251 /* Display the current message in the current mini-buffer. This is
7252 only called from error handlers in process.c, and is not time
7258 if (!NILP (echo_area_buffer
[0]))
7261 string
= Fcurrent_message ();
7262 message3 (string
, SBYTES (string
),
7263 !NILP (current_buffer
->enable_multibyte_characters
));
7268 /* Make sure echo area buffers in `echo_buffers' are live.
7269 If they aren't, make new ones. */
7272 ensure_echo_area_buffers ()
7276 for (i
= 0; i
< 2; ++i
)
7277 if (!BUFFERP (echo_buffer
[i
])
7278 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7281 Lisp_Object old_buffer
;
7284 old_buffer
= echo_buffer
[i
];
7285 sprintf (name
, " *Echo Area %d*", i
);
7286 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7287 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7289 for (j
= 0; j
< 2; ++j
)
7290 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7291 echo_area_buffer
[j
] = echo_buffer
[i
];
7296 /* Call FN with args A1..A4 with either the current or last displayed
7297 echo_area_buffer as current buffer.
7299 WHICH zero means use the current message buffer
7300 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7301 from echo_buffer[] and clear it.
7303 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7304 suitable buffer from echo_buffer[] and clear it.
7306 Value is what FN returns. */
7309 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7312 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7318 int this_one
, the_other
, clear_buffer_p
, rc
;
7319 int count
= SPECPDL_INDEX ();
7321 /* If buffers aren't live, make new ones. */
7322 ensure_echo_area_buffers ();
7327 this_one
= 0, the_other
= 1;
7329 this_one
= 1, the_other
= 0;
7331 /* Choose a suitable buffer from echo_buffer[] is we don't
7333 if (NILP (echo_area_buffer
[this_one
]))
7335 echo_area_buffer
[this_one
]
7336 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7337 ? echo_buffer
[the_other
]
7338 : echo_buffer
[this_one
]);
7342 buffer
= echo_area_buffer
[this_one
];
7344 /* Don't get confused by reusing the buffer used for echoing
7345 for a different purpose. */
7346 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7349 record_unwind_protect (unwind_with_echo_area_buffer
,
7350 with_echo_area_buffer_unwind_data (w
));
7352 /* Make the echo area buffer current. Note that for display
7353 purposes, it is not necessary that the displayed window's buffer
7354 == current_buffer, except for text property lookup. So, let's
7355 only set that buffer temporarily here without doing a full
7356 Fset_window_buffer. We must also change w->pointm, though,
7357 because otherwise an assertions in unshow_buffer fails, and Emacs
7359 set_buffer_internal_1 (XBUFFER (buffer
));
7363 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7366 current_buffer
->undo_list
= Qt
;
7367 current_buffer
->read_only
= Qnil
;
7368 specbind (Qinhibit_read_only
, Qt
);
7369 specbind (Qinhibit_modification_hooks
, Qt
);
7371 if (clear_buffer_p
&& Z
> BEG
)
7374 xassert (BEGV
>= BEG
);
7375 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7377 rc
= fn (a1
, a2
, a3
, a4
);
7379 xassert (BEGV
>= BEG
);
7380 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7382 unbind_to (count
, Qnil
);
7387 /* Save state that should be preserved around the call to the function
7388 FN called in with_echo_area_buffer. */
7391 with_echo_area_buffer_unwind_data (w
)
7397 /* Reduce consing by keeping one vector in
7398 Vwith_echo_area_save_vector. */
7399 vector
= Vwith_echo_area_save_vector
;
7400 Vwith_echo_area_save_vector
= Qnil
;
7403 vector
= Fmake_vector (make_number (7), Qnil
);
7405 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7406 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7407 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7411 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7412 AREF (vector
, i
) = w
->buffer
; ++i
;
7413 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7414 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7419 for (; i
< end
; ++i
)
7420 AREF (vector
, i
) = Qnil
;
7423 xassert (i
== ASIZE (vector
));
7428 /* Restore global state from VECTOR which was created by
7429 with_echo_area_buffer_unwind_data. */
7432 unwind_with_echo_area_buffer (vector
)
7435 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7436 Vdeactivate_mark
= AREF (vector
, 1);
7437 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7439 if (WINDOWP (AREF (vector
, 3)))
7442 Lisp_Object buffer
, charpos
, bytepos
;
7444 w
= XWINDOW (AREF (vector
, 3));
7445 buffer
= AREF (vector
, 4);
7446 charpos
= AREF (vector
, 5);
7447 bytepos
= AREF (vector
, 6);
7450 set_marker_both (w
->pointm
, buffer
,
7451 XFASTINT (charpos
), XFASTINT (bytepos
));
7454 Vwith_echo_area_save_vector
= vector
;
7459 /* Set up the echo area for use by print functions. MULTIBYTE_P
7460 non-zero means we will print multibyte. */
7463 setup_echo_area_for_printing (multibyte_p
)
7466 /* If we can't find an echo area any more, exit. */
7467 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7470 ensure_echo_area_buffers ();
7472 if (!message_buf_print
)
7474 /* A message has been output since the last time we printed.
7475 Choose a fresh echo area buffer. */
7476 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7477 echo_area_buffer
[0] = echo_buffer
[1];
7479 echo_area_buffer
[0] = echo_buffer
[0];
7481 /* Switch to that buffer and clear it. */
7482 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7483 current_buffer
->truncate_lines
= Qnil
;
7487 int count
= SPECPDL_INDEX ();
7488 specbind (Qinhibit_read_only
, Qt
);
7489 /* Note that undo recording is always disabled. */
7491 unbind_to (count
, Qnil
);
7493 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7495 /* Set up the buffer for the multibyteness we need. */
7497 != !NILP (current_buffer
->enable_multibyte_characters
))
7498 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7500 /* Raise the frame containing the echo area. */
7501 if (minibuffer_auto_raise
)
7503 struct frame
*sf
= SELECTED_FRAME ();
7504 Lisp_Object mini_window
;
7505 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7506 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7509 message_log_maybe_newline ();
7510 message_buf_print
= 1;
7514 if (NILP (echo_area_buffer
[0]))
7516 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7517 echo_area_buffer
[0] = echo_buffer
[1];
7519 echo_area_buffer
[0] = echo_buffer
[0];
7522 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7524 /* Someone switched buffers between print requests. */
7525 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7526 current_buffer
->truncate_lines
= Qnil
;
7532 /* Display an echo area message in window W. Value is non-zero if W's
7533 height is changed. If display_last_displayed_message_p is
7534 non-zero, display the message that was last displayed, otherwise
7535 display the current message. */
7538 display_echo_area (w
)
7541 int i
, no_message_p
, window_height_changed_p
, count
;
7543 /* Temporarily disable garbage collections while displaying the echo
7544 area. This is done because a GC can print a message itself.
7545 That message would modify the echo area buffer's contents while a
7546 redisplay of the buffer is going on, and seriously confuse
7548 count
= inhibit_garbage_collection ();
7550 /* If there is no message, we must call display_echo_area_1
7551 nevertheless because it resizes the window. But we will have to
7552 reset the echo_area_buffer in question to nil at the end because
7553 with_echo_area_buffer will sets it to an empty buffer. */
7554 i
= display_last_displayed_message_p
? 1 : 0;
7555 no_message_p
= NILP (echo_area_buffer
[i
]);
7557 window_height_changed_p
7558 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7559 display_echo_area_1
,
7560 (EMACS_INT
) w
, Qnil
, 0, 0);
7563 echo_area_buffer
[i
] = Qnil
;
7565 unbind_to (count
, Qnil
);
7566 return window_height_changed_p
;
7570 /* Helper for display_echo_area. Display the current buffer which
7571 contains the current echo area message in window W, a mini-window,
7572 a pointer to which is passed in A1. A2..A4 are currently not used.
7573 Change the height of W so that all of the message is displayed.
7574 Value is non-zero if height of W was changed. */
7577 display_echo_area_1 (a1
, a2
, a3
, a4
)
7582 struct window
*w
= (struct window
*) a1
;
7584 struct text_pos start
;
7585 int window_height_changed_p
= 0;
7587 /* Do this before displaying, so that we have a large enough glyph
7588 matrix for the display. */
7589 window_height_changed_p
= resize_mini_window (w
, 0);
7592 clear_glyph_matrix (w
->desired_matrix
);
7593 XSETWINDOW (window
, w
);
7594 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7595 try_window (window
, start
, 0);
7597 return window_height_changed_p
;
7601 /* Resize the echo area window to exactly the size needed for the
7602 currently displayed message, if there is one. If a mini-buffer
7603 is active, don't shrink it. */
7606 resize_echo_area_exactly ()
7608 if (BUFFERP (echo_area_buffer
[0])
7609 && WINDOWP (echo_area_window
))
7611 struct window
*w
= XWINDOW (echo_area_window
);
7613 Lisp_Object resize_exactly
;
7615 if (minibuf_level
== 0)
7616 resize_exactly
= Qt
;
7618 resize_exactly
= Qnil
;
7620 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7621 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7624 ++windows_or_buffers_changed
;
7625 ++update_mode_lines
;
7626 redisplay_internal (0);
7632 /* Callback function for with_echo_area_buffer, when used from
7633 resize_echo_area_exactly. A1 contains a pointer to the window to
7634 resize, EXACTLY non-nil means resize the mini-window exactly to the
7635 size of the text displayed. A3 and A4 are not used. Value is what
7636 resize_mini_window returns. */
7639 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7641 Lisp_Object exactly
;
7644 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7648 /* Resize mini-window W to fit the size of its contents. EXACT:P
7649 means size the window exactly to the size needed. Otherwise, it's
7650 only enlarged until W's buffer is empty. Value is non-zero if
7651 the window height has been changed. */
7654 resize_mini_window (w
, exact_p
)
7658 struct frame
*f
= XFRAME (w
->frame
);
7659 int window_height_changed_p
= 0;
7661 xassert (MINI_WINDOW_P (w
));
7663 /* Don't resize windows while redisplaying a window; it would
7664 confuse redisplay functions when the size of the window they are
7665 displaying changes from under them. Such a resizing can happen,
7666 for instance, when which-func prints a long message while
7667 we are running fontification-functions. We're running these
7668 functions with safe_call which binds inhibit-redisplay to t. */
7669 if (!NILP (Vinhibit_redisplay
))
7672 /* Nil means don't try to resize. */
7673 if (NILP (Vresize_mini_windows
)
7674 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7677 if (!FRAME_MINIBUF_ONLY_P (f
))
7680 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7681 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7682 int height
, max_height
;
7683 int unit
= FRAME_LINE_HEIGHT (f
);
7684 struct text_pos start
;
7685 struct buffer
*old_current_buffer
= NULL
;
7687 if (current_buffer
!= XBUFFER (w
->buffer
))
7689 old_current_buffer
= current_buffer
;
7690 set_buffer_internal (XBUFFER (w
->buffer
));
7693 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7695 /* Compute the max. number of lines specified by the user. */
7696 if (FLOATP (Vmax_mini_window_height
))
7697 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7698 else if (INTEGERP (Vmax_mini_window_height
))
7699 max_height
= XINT (Vmax_mini_window_height
);
7701 max_height
= total_height
/ 4;
7703 /* Correct that max. height if it's bogus. */
7704 max_height
= max (1, max_height
);
7705 max_height
= min (total_height
, max_height
);
7707 /* Find out the height of the text in the window. */
7708 if (it
.truncate_lines_p
)
7713 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7714 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7715 height
= it
.current_y
+ last_height
;
7717 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7718 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7719 height
= (height
+ unit
- 1) / unit
;
7722 /* Compute a suitable window start. */
7723 if (height
> max_height
)
7725 height
= max_height
;
7726 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7727 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7728 start
= it
.current
.pos
;
7731 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7732 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7734 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7736 /* Let it grow only, until we display an empty message, in which
7737 case the window shrinks again. */
7738 if (height
> WINDOW_TOTAL_LINES (w
))
7740 int old_height
= WINDOW_TOTAL_LINES (w
);
7741 freeze_window_starts (f
, 1);
7742 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7743 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7745 else if (height
< WINDOW_TOTAL_LINES (w
)
7746 && (exact_p
|| BEGV
== ZV
))
7748 int old_height
= WINDOW_TOTAL_LINES (w
);
7749 freeze_window_starts (f
, 0);
7750 shrink_mini_window (w
);
7751 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7756 /* Always resize to exact size needed. */
7757 if (height
> WINDOW_TOTAL_LINES (w
))
7759 int old_height
= WINDOW_TOTAL_LINES (w
);
7760 freeze_window_starts (f
, 1);
7761 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7762 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7764 else if (height
< WINDOW_TOTAL_LINES (w
))
7766 int old_height
= WINDOW_TOTAL_LINES (w
);
7767 freeze_window_starts (f
, 0);
7768 shrink_mini_window (w
);
7772 freeze_window_starts (f
, 1);
7773 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7776 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7780 if (old_current_buffer
)
7781 set_buffer_internal (old_current_buffer
);
7784 return window_height_changed_p
;
7788 /* Value is the current message, a string, or nil if there is no
7796 if (NILP (echo_area_buffer
[0]))
7800 with_echo_area_buffer (0, 0, current_message_1
,
7801 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7803 echo_area_buffer
[0] = Qnil
;
7811 current_message_1 (a1
, a2
, a3
, a4
)
7816 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7819 *msg
= make_buffer_string (BEG
, Z
, 1);
7826 /* Push the current message on Vmessage_stack for later restauration
7827 by restore_message. Value is non-zero if the current message isn't
7828 empty. This is a relatively infrequent operation, so it's not
7829 worth optimizing. */
7835 msg
= current_message ();
7836 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7837 return STRINGP (msg
);
7841 /* Restore message display from the top of Vmessage_stack. */
7848 xassert (CONSP (Vmessage_stack
));
7849 msg
= XCAR (Vmessage_stack
);
7851 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7853 message3_nolog (msg
, 0, 0);
7857 /* Handler for record_unwind_protect calling pop_message. */
7860 pop_message_unwind (dummy
)
7867 /* Pop the top-most entry off Vmessage_stack. */
7872 xassert (CONSP (Vmessage_stack
));
7873 Vmessage_stack
= XCDR (Vmessage_stack
);
7877 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7878 exits. If the stack is not empty, we have a missing pop_message
7882 check_message_stack ()
7884 if (!NILP (Vmessage_stack
))
7889 /* Truncate to NCHARS what will be displayed in the echo area the next
7890 time we display it---but don't redisplay it now. */
7893 truncate_echo_area (nchars
)
7897 echo_area_buffer
[0] = Qnil
;
7898 /* A null message buffer means that the frame hasn't really been
7899 initialized yet. Error messages get reported properly by
7900 cmd_error, so this must be just an informative message; toss it. */
7901 else if (!noninteractive
7903 && !NILP (echo_area_buffer
[0]))
7905 struct frame
*sf
= SELECTED_FRAME ();
7906 if (FRAME_MESSAGE_BUF (sf
))
7907 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7912 /* Helper function for truncate_echo_area. Truncate the current
7913 message to at most NCHARS characters. */
7916 truncate_message_1 (nchars
, a2
, a3
, a4
)
7921 if (BEG
+ nchars
< Z
)
7922 del_range (BEG
+ nchars
, Z
);
7924 echo_area_buffer
[0] = Qnil
;
7929 /* Set the current message to a substring of S or STRING.
7931 If STRING is a Lisp string, set the message to the first NBYTES
7932 bytes from STRING. NBYTES zero means use the whole string. If
7933 STRING is multibyte, the message will be displayed multibyte.
7935 If S is not null, set the message to the first LEN bytes of S. LEN
7936 zero means use the whole string. MULTIBYTE_P non-zero means S is
7937 multibyte. Display the message multibyte in that case. */
7940 set_message (s
, string
, nbytes
, multibyte_p
)
7943 int nbytes
, multibyte_p
;
7945 message_enable_multibyte
7946 = ((s
&& multibyte_p
)
7947 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7949 with_echo_area_buffer (0, 0, set_message_1
,
7950 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7951 message_buf_print
= 0;
7952 help_echo_showing_p
= 0;
7956 /* Helper function for set_message. Arguments have the same meaning
7957 as there, with A1 corresponding to S and A2 corresponding to STRING
7958 This function is called with the echo area buffer being
7962 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
7965 EMACS_INT nbytes
, multibyte_p
;
7967 const char *s
= (const char *) a1
;
7968 Lisp_Object string
= a2
;
7970 /* Change multibyteness of the echo buffer appropriately. */
7971 if (message_enable_multibyte
7972 != !NILP (current_buffer
->enable_multibyte_characters
))
7973 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
7975 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
7977 /* Insert new message at BEG. */
7978 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7981 if (STRINGP (string
))
7986 nbytes
= SBYTES (string
);
7987 nchars
= string_byte_to_char (string
, nbytes
);
7989 /* This function takes care of single/multibyte conversion. We
7990 just have to ensure that the echo area buffer has the right
7991 setting of enable_multibyte_characters. */
7992 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
7997 nbytes
= strlen (s
);
7999 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8001 /* Convert from multi-byte to single-byte. */
8003 unsigned char work
[1];
8005 /* Convert a multibyte string to single-byte. */
8006 for (i
= 0; i
< nbytes
; i
+= n
)
8008 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8009 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8011 : multibyte_char_to_unibyte (c
, Qnil
));
8012 insert_1_both (work
, 1, 1, 1, 0, 0);
8015 else if (!multibyte_p
8016 && !NILP (current_buffer
->enable_multibyte_characters
))
8018 /* Convert from single-byte to multi-byte. */
8020 const unsigned char *msg
= (const unsigned char *) s
;
8021 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8023 /* Convert a single-byte string to multibyte. */
8024 for (i
= 0; i
< nbytes
; i
++)
8026 c
= unibyte_char_to_multibyte (msg
[i
]);
8027 n
= CHAR_STRING (c
, str
);
8028 insert_1_both (str
, 1, n
, 1, 0, 0);
8032 insert_1 (s
, nbytes
, 1, 0, 0);
8039 /* Clear messages. CURRENT_P non-zero means clear the current
8040 message. LAST_DISPLAYED_P non-zero means clear the message
8044 clear_message (current_p
, last_displayed_p
)
8045 int current_p
, last_displayed_p
;
8049 echo_area_buffer
[0] = Qnil
;
8050 message_cleared_p
= 1;
8053 if (last_displayed_p
)
8054 echo_area_buffer
[1] = Qnil
;
8056 message_buf_print
= 0;
8059 /* Clear garbaged frames.
8061 This function is used where the old redisplay called
8062 redraw_garbaged_frames which in turn called redraw_frame which in
8063 turn called clear_frame. The call to clear_frame was a source of
8064 flickering. I believe a clear_frame is not necessary. It should
8065 suffice in the new redisplay to invalidate all current matrices,
8066 and ensure a complete redisplay of all windows. */
8069 clear_garbaged_frames ()
8073 Lisp_Object tail
, frame
;
8074 int changed_count
= 0;
8076 FOR_EACH_FRAME (tail
, frame
)
8078 struct frame
*f
= XFRAME (frame
);
8080 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8084 Fredraw_frame (frame
);
8085 f
->force_flush_display_p
= 1;
8087 clear_current_matrices (f
);
8096 ++windows_or_buffers_changed
;
8101 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8102 is non-zero update selected_frame. Value is non-zero if the
8103 mini-windows height has been changed. */
8106 echo_area_display (update_frame_p
)
8109 Lisp_Object mini_window
;
8112 int window_height_changed_p
= 0;
8113 struct frame
*sf
= SELECTED_FRAME ();
8115 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8116 w
= XWINDOW (mini_window
);
8117 f
= XFRAME (WINDOW_FRAME (w
));
8119 /* Don't display if frame is invisible or not yet initialized. */
8120 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8123 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8125 #ifdef HAVE_WINDOW_SYSTEM
8126 /* When Emacs starts, selected_frame may be a visible terminal
8127 frame, even if we run under a window system. If we let this
8128 through, a message would be displayed on the terminal. */
8129 if (EQ (selected_frame
, Vterminal_frame
)
8130 && !NILP (Vwindow_system
))
8132 #endif /* HAVE_WINDOW_SYSTEM */
8135 /* Redraw garbaged frames. */
8137 clear_garbaged_frames ();
8139 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8141 echo_area_window
= mini_window
;
8142 window_height_changed_p
= display_echo_area (w
);
8143 w
->must_be_updated_p
= 1;
8145 /* Update the display, unless called from redisplay_internal.
8146 Also don't update the screen during redisplay itself. The
8147 update will happen at the end of redisplay, and an update
8148 here could cause confusion. */
8149 if (update_frame_p
&& !redisplaying_p
)
8153 /* If the display update has been interrupted by pending
8154 input, update mode lines in the frame. Due to the
8155 pending input, it might have been that redisplay hasn't
8156 been called, so that mode lines above the echo area are
8157 garbaged. This looks odd, so we prevent it here. */
8158 if (!display_completed
)
8159 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8161 if (window_height_changed_p
8162 /* Don't do this if Emacs is shutting down. Redisplay
8163 needs to run hooks. */
8164 && !NILP (Vrun_hooks
))
8166 /* Must update other windows. Likewise as in other
8167 cases, don't let this update be interrupted by
8169 int count
= SPECPDL_INDEX ();
8170 specbind (Qredisplay_dont_pause
, Qt
);
8171 windows_or_buffers_changed
= 1;
8172 redisplay_internal (0);
8173 unbind_to (count
, Qnil
);
8175 else if (FRAME_WINDOW_P (f
) && n
== 0)
8177 /* Window configuration is the same as before.
8178 Can do with a display update of the echo area,
8179 unless we displayed some mode lines. */
8180 update_single_window (w
, 1);
8181 rif
->flush_display (f
);
8184 update_frame (f
, 1, 1);
8186 /* If cursor is in the echo area, make sure that the next
8187 redisplay displays the minibuffer, so that the cursor will
8188 be replaced with what the minibuffer wants. */
8189 if (cursor_in_echo_area
)
8190 ++windows_or_buffers_changed
;
8193 else if (!EQ (mini_window
, selected_window
))
8194 windows_or_buffers_changed
++;
8196 /* The current message is now also the last one displayed. */
8197 echo_area_buffer
[1] = echo_area_buffer
[0];
8199 /* Prevent redisplay optimization in redisplay_internal by resetting
8200 this_line_start_pos. This is done because the mini-buffer now
8201 displays the message instead of its buffer text. */
8202 if (EQ (mini_window
, selected_window
))
8203 CHARPOS (this_line_start_pos
) = 0;
8205 return window_height_changed_p
;
8210 /***********************************************************************
8211 Mode Lines and Frame Titles
8212 ***********************************************************************/
8214 /* A buffer for constructing non-propertized mode-line strings and
8215 frame titles in it; allocated from the heap in init_xdisp and
8216 resized as needed in store_mode_line_noprop_char. */
8218 static char *mode_line_noprop_buf
;
8220 /* The buffer's end, and a current output position in it. */
8222 static char *mode_line_noprop_buf_end
;
8223 static char *mode_line_noprop_ptr
;
8225 #define MODE_LINE_NOPROP_LEN(start) \
8226 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8229 MODE_LINE_DISPLAY
= 0,
8235 /* Alist that caches the results of :propertize.
8236 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8237 static Lisp_Object mode_line_proptrans_alist
;
8239 /* List of strings making up the mode-line. */
8240 static Lisp_Object mode_line_string_list
;
8242 /* Base face property when building propertized mode line string. */
8243 static Lisp_Object mode_line_string_face
;
8244 static Lisp_Object mode_line_string_face_prop
;
8247 /* Unwind data for mode line strings */
8249 static Lisp_Object Vmode_line_unwind_vector
;
8252 format_mode_line_unwind_data (obuf
)
8253 struct buffer
*obuf
;
8257 /* Reduce consing by keeping one vector in
8258 Vwith_echo_area_save_vector. */
8259 vector
= Vmode_line_unwind_vector
;
8260 Vmode_line_unwind_vector
= Qnil
;
8263 vector
= Fmake_vector (make_number (7), Qnil
);
8265 AREF (vector
, 0) = make_number (mode_line_target
);
8266 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8267 AREF (vector
, 2) = mode_line_string_list
;
8268 AREF (vector
, 3) = mode_line_proptrans_alist
;
8269 AREF (vector
, 4) = mode_line_string_face
;
8270 AREF (vector
, 5) = mode_line_string_face_prop
;
8273 XSETBUFFER (AREF (vector
, 6), obuf
);
8275 AREF (vector
, 6) = Qnil
;
8281 unwind_format_mode_line (vector
)
8284 mode_line_target
= XINT (AREF (vector
, 0));
8285 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8286 mode_line_string_list
= AREF (vector
, 2);
8287 mode_line_proptrans_alist
= AREF (vector
, 3);
8288 mode_line_string_face
= AREF (vector
, 4);
8289 mode_line_string_face_prop
= AREF (vector
, 5);
8291 if (!NILP (AREF (vector
, 6)))
8293 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8294 AREF (vector
, 6) = Qnil
;
8297 Vmode_line_unwind_vector
= vector
;
8302 /* Store a single character C for the frame title in mode_line_noprop_buf.
8303 Re-allocate mode_line_noprop_buf if necessary. */
8307 store_mode_line_noprop_char (char c
)
8309 store_mode_line_noprop_char (c
)
8313 /* If output position has reached the end of the allocated buffer,
8314 double the buffer's size. */
8315 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8317 int len
= MODE_LINE_NOPROP_LEN (0);
8318 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8319 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8320 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8321 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8324 *mode_line_noprop_ptr
++ = c
;
8328 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8329 mode_line_noprop_ptr. STR is the string to store. Do not copy
8330 characters that yield more columns than PRECISION; PRECISION <= 0
8331 means copy the whole string. Pad with spaces until FIELD_WIDTH
8332 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8333 pad. Called from display_mode_element when it is used to build a
8337 store_mode_line_noprop (str
, field_width
, precision
)
8338 const unsigned char *str
;
8339 int field_width
, precision
;
8344 /* Copy at most PRECISION chars from STR. */
8345 nbytes
= strlen (str
);
8346 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8348 store_mode_line_noprop_char (*str
++);
8350 /* Fill up with spaces until FIELD_WIDTH reached. */
8351 while (field_width
> 0
8354 store_mode_line_noprop_char (' ');
8361 /***********************************************************************
8363 ***********************************************************************/
8365 #ifdef HAVE_WINDOW_SYSTEM
8367 /* Set the title of FRAME, if it has changed. The title format is
8368 Vicon_title_format if FRAME is iconified, otherwise it is
8369 frame_title_format. */
8372 x_consider_frame_title (frame
)
8375 struct frame
*f
= XFRAME (frame
);
8377 if (FRAME_WINDOW_P (f
)
8378 || FRAME_MINIBUF_ONLY_P (f
)
8379 || f
->explicit_name
)
8381 /* Do we have more than one visible frame on this X display? */
8388 int count
= SPECPDL_INDEX ();
8390 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8392 Lisp_Object other_frame
= XCAR (tail
);
8393 struct frame
*tf
= XFRAME (other_frame
);
8396 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8397 && !FRAME_MINIBUF_ONLY_P (tf
)
8398 && !EQ (other_frame
, tip_frame
)
8399 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8403 /* Set global variable indicating that multiple frames exist. */
8404 multiple_frames
= CONSP (tail
);
8406 /* Switch to the buffer of selected window of the frame. Set up
8407 mode_line_target so that display_mode_element will output into
8408 mode_line_noprop_buf; then display the title. */
8409 record_unwind_protect (unwind_format_mode_line
,
8410 format_mode_line_unwind_data (current_buffer
));
8412 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8413 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8415 mode_line_target
= MODE_LINE_TITLE
;
8416 title_start
= MODE_LINE_NOPROP_LEN (0);
8417 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8418 NULL
, DEFAULT_FACE_ID
);
8419 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8420 len
= MODE_LINE_NOPROP_LEN (title_start
);
8421 title
= mode_line_noprop_buf
+ title_start
;
8422 unbind_to (count
, Qnil
);
8424 /* Set the title only if it's changed. This avoids consing in
8425 the common case where it hasn't. (If it turns out that we've
8426 already wasted too much time by walking through the list with
8427 display_mode_element, then we might need to optimize at a
8428 higher level than this.) */
8429 if (! STRINGP (f
->name
)
8430 || SBYTES (f
->name
) != len
8431 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8432 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8436 #endif /* not HAVE_WINDOW_SYSTEM */
8441 /***********************************************************************
8443 ***********************************************************************/
8446 /* Prepare for redisplay by updating menu-bar item lists when
8447 appropriate. This can call eval. */
8450 prepare_menu_bars ()
8453 struct gcpro gcpro1
, gcpro2
;
8455 Lisp_Object tooltip_frame
;
8457 #ifdef HAVE_WINDOW_SYSTEM
8458 tooltip_frame
= tip_frame
;
8460 tooltip_frame
= Qnil
;
8463 /* Update all frame titles based on their buffer names, etc. We do
8464 this before the menu bars so that the buffer-menu will show the
8465 up-to-date frame titles. */
8466 #ifdef HAVE_WINDOW_SYSTEM
8467 if (windows_or_buffers_changed
|| update_mode_lines
)
8469 Lisp_Object tail
, frame
;
8471 FOR_EACH_FRAME (tail
, frame
)
8474 if (!EQ (frame
, tooltip_frame
)
8475 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8476 x_consider_frame_title (frame
);
8479 #endif /* HAVE_WINDOW_SYSTEM */
8481 /* Update the menu bar item lists, if appropriate. This has to be
8482 done before any actual redisplay or generation of display lines. */
8483 all_windows
= (update_mode_lines
8484 || buffer_shared
> 1
8485 || windows_or_buffers_changed
);
8488 Lisp_Object tail
, frame
;
8489 int count
= SPECPDL_INDEX ();
8491 record_unwind_save_match_data ();
8493 FOR_EACH_FRAME (tail
, frame
)
8497 /* Ignore tooltip frame. */
8498 if (EQ (frame
, tooltip_frame
))
8501 /* If a window on this frame changed size, report that to
8502 the user and clear the size-change flag. */
8503 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8505 Lisp_Object functions
;
8507 /* Clear flag first in case we get an error below. */
8508 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8509 functions
= Vwindow_size_change_functions
;
8510 GCPRO2 (tail
, functions
);
8512 while (CONSP (functions
))
8514 call1 (XCAR (functions
), frame
);
8515 functions
= XCDR (functions
);
8521 update_menu_bar (f
, 0);
8522 #ifdef HAVE_WINDOW_SYSTEM
8523 update_tool_bar (f
, 0);
8528 unbind_to (count
, Qnil
);
8532 struct frame
*sf
= SELECTED_FRAME ();
8533 update_menu_bar (sf
, 1);
8534 #ifdef HAVE_WINDOW_SYSTEM
8535 update_tool_bar (sf
, 1);
8539 /* Motif needs this. See comment in xmenu.c. Turn it off when
8540 pending_menu_activation is not defined. */
8541 #ifdef USE_X_TOOLKIT
8542 pending_menu_activation
= 0;
8547 /* Update the menu bar item list for frame F. This has to be done
8548 before we start to fill in any display lines, because it can call
8551 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8554 update_menu_bar (f
, save_match_data
)
8556 int save_match_data
;
8559 register struct window
*w
;
8561 /* If called recursively during a menu update, do nothing. This can
8562 happen when, for instance, an activate-menubar-hook causes a
8564 if (inhibit_menubar_update
)
8567 window
= FRAME_SELECTED_WINDOW (f
);
8568 w
= XWINDOW (window
);
8570 #if 0 /* The if statement below this if statement used to include the
8571 condition !NILP (w->update_mode_line), rather than using
8572 update_mode_lines directly, and this if statement may have
8573 been added to make that condition work. Now the if
8574 statement below matches its comment, this isn't needed. */
8575 if (update_mode_lines
)
8576 w
->update_mode_line
= Qt
;
8579 if (FRAME_WINDOW_P (f
)
8581 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8582 || defined (USE_GTK)
8583 FRAME_EXTERNAL_MENU_BAR (f
)
8585 FRAME_MENU_BAR_LINES (f
) > 0
8587 : FRAME_MENU_BAR_LINES (f
) > 0)
8589 /* If the user has switched buffers or windows, we need to
8590 recompute to reflect the new bindings. But we'll
8591 recompute when update_mode_lines is set too; that means
8592 that people can use force-mode-line-update to request
8593 that the menu bar be recomputed. The adverse effect on
8594 the rest of the redisplay algorithm is about the same as
8595 windows_or_buffers_changed anyway. */
8596 if (windows_or_buffers_changed
8597 /* This used to test w->update_mode_line, but we believe
8598 there is no need to recompute the menu in that case. */
8599 || update_mode_lines
8600 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8601 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8602 != !NILP (w
->last_had_star
))
8603 || ((!NILP (Vtransient_mark_mode
)
8604 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8605 != !NILP (w
->region_showing
)))
8607 struct buffer
*prev
= current_buffer
;
8608 int count
= SPECPDL_INDEX ();
8610 specbind (Qinhibit_menubar_update
, Qt
);
8612 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8613 if (save_match_data
)
8614 record_unwind_save_match_data ();
8615 if (NILP (Voverriding_local_map_menu_flag
))
8617 specbind (Qoverriding_terminal_local_map
, Qnil
);
8618 specbind (Qoverriding_local_map
, Qnil
);
8621 /* Run the Lucid hook. */
8622 safe_run_hooks (Qactivate_menubar_hook
);
8624 /* If it has changed current-menubar from previous value,
8625 really recompute the menu-bar from the value. */
8626 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8627 call0 (Qrecompute_lucid_menubar
);
8629 safe_run_hooks (Qmenu_bar_update_hook
);
8630 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8632 /* Redisplay the menu bar in case we changed it. */
8633 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8634 || defined (USE_GTK)
8635 if (FRAME_WINDOW_P (f
)
8636 #if defined (MAC_OS)
8637 /* All frames on Mac OS share the same menubar. So only the
8638 selected frame should be allowed to set it. */
8639 && f
== SELECTED_FRAME ()
8642 set_frame_menubar (f
, 0, 0);
8644 /* On a terminal screen, the menu bar is an ordinary screen
8645 line, and this makes it get updated. */
8646 w
->update_mode_line
= Qt
;
8647 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8648 /* In the non-toolkit version, the menu bar is an ordinary screen
8649 line, and this makes it get updated. */
8650 w
->update_mode_line
= Qt
;
8651 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8653 unbind_to (count
, Qnil
);
8654 set_buffer_internal_1 (prev
);
8661 /***********************************************************************
8663 ***********************************************************************/
8665 #ifdef HAVE_WINDOW_SYSTEM
8668 Nominal cursor position -- where to draw output.
8669 HPOS and VPOS are window relative glyph matrix coordinates.
8670 X and Y are window relative pixel coordinates. */
8672 struct cursor_pos output_cursor
;
8676 Set the global variable output_cursor to CURSOR. All cursor
8677 positions are relative to updated_window. */
8680 set_output_cursor (cursor
)
8681 struct cursor_pos
*cursor
;
8683 output_cursor
.hpos
= cursor
->hpos
;
8684 output_cursor
.vpos
= cursor
->vpos
;
8685 output_cursor
.x
= cursor
->x
;
8686 output_cursor
.y
= cursor
->y
;
8691 Set a nominal cursor position.
8693 HPOS and VPOS are column/row positions in a window glyph matrix. X
8694 and Y are window text area relative pixel positions.
8696 If this is done during an update, updated_window will contain the
8697 window that is being updated and the position is the future output
8698 cursor position for that window. If updated_window is null, use
8699 selected_window and display the cursor at the given position. */
8702 x_cursor_to (vpos
, hpos
, y
, x
)
8703 int vpos
, hpos
, y
, x
;
8707 /* If updated_window is not set, work on selected_window. */
8711 w
= XWINDOW (selected_window
);
8713 /* Set the output cursor. */
8714 output_cursor
.hpos
= hpos
;
8715 output_cursor
.vpos
= vpos
;
8716 output_cursor
.x
= x
;
8717 output_cursor
.y
= y
;
8719 /* If not called as part of an update, really display the cursor.
8720 This will also set the cursor position of W. */
8721 if (updated_window
== NULL
)
8724 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8725 if (rif
->flush_display_optional
)
8726 rif
->flush_display_optional (SELECTED_FRAME ());
8731 #endif /* HAVE_WINDOW_SYSTEM */
8734 /***********************************************************************
8736 ***********************************************************************/
8738 #ifdef HAVE_WINDOW_SYSTEM
8740 /* Where the mouse was last time we reported a mouse event. */
8742 FRAME_PTR last_mouse_frame
;
8744 /* Tool-bar item index of the item on which a mouse button was pressed
8747 int last_tool_bar_item
;
8750 /* Update the tool-bar item list for frame F. This has to be done
8751 before we start to fill in any display lines. Called from
8752 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8753 and restore it here. */
8756 update_tool_bar (f
, save_match_data
)
8758 int save_match_data
;
8761 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8763 int do_update
= WINDOWP (f
->tool_bar_window
)
8764 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8772 window
= FRAME_SELECTED_WINDOW (f
);
8773 w
= XWINDOW (window
);
8775 /* If the user has switched buffers or windows, we need to
8776 recompute to reflect the new bindings. But we'll
8777 recompute when update_mode_lines is set too; that means
8778 that people can use force-mode-line-update to request
8779 that the menu bar be recomputed. The adverse effect on
8780 the rest of the redisplay algorithm is about the same as
8781 windows_or_buffers_changed anyway. */
8782 if (windows_or_buffers_changed
8783 || !NILP (w
->update_mode_line
)
8784 || update_mode_lines
8785 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8786 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8787 != !NILP (w
->last_had_star
))
8788 || ((!NILP (Vtransient_mark_mode
)
8789 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8790 != !NILP (w
->region_showing
)))
8792 struct buffer
*prev
= current_buffer
;
8793 int count
= SPECPDL_INDEX ();
8794 Lisp_Object new_tool_bar
;
8796 struct gcpro gcpro1
;
8798 /* Set current_buffer to the buffer of the selected
8799 window of the frame, so that we get the right local
8801 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8803 /* Save match data, if we must. */
8804 if (save_match_data
)
8805 record_unwind_save_match_data ();
8807 /* Make sure that we don't accidentally use bogus keymaps. */
8808 if (NILP (Voverriding_local_map_menu_flag
))
8810 specbind (Qoverriding_terminal_local_map
, Qnil
);
8811 specbind (Qoverriding_local_map
, Qnil
);
8814 GCPRO1 (new_tool_bar
);
8816 /* Build desired tool-bar items from keymaps. */
8817 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8820 /* Redisplay the tool-bar if we changed it. */
8821 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8823 /* Redisplay that happens asynchronously due to an expose event
8824 may access f->tool_bar_items. Make sure we update both
8825 variables within BLOCK_INPUT so no such event interrupts. */
8827 f
->tool_bar_items
= new_tool_bar
;
8828 f
->n_tool_bar_items
= new_n_tool_bar
;
8829 w
->update_mode_line
= Qt
;
8835 unbind_to (count
, Qnil
);
8836 set_buffer_internal_1 (prev
);
8842 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8843 F's desired tool-bar contents. F->tool_bar_items must have
8844 been set up previously by calling prepare_menu_bars. */
8847 build_desired_tool_bar_string (f
)
8850 int i
, size
, size_needed
;
8851 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8852 Lisp_Object image
, plist
, props
;
8854 image
= plist
= props
= Qnil
;
8855 GCPRO3 (image
, plist
, props
);
8857 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8858 Otherwise, make a new string. */
8860 /* The size of the string we might be able to reuse. */
8861 size
= (STRINGP (f
->desired_tool_bar_string
)
8862 ? SCHARS (f
->desired_tool_bar_string
)
8865 /* We need one space in the string for each image. */
8866 size_needed
= f
->n_tool_bar_items
;
8868 /* Reuse f->desired_tool_bar_string, if possible. */
8869 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8870 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8874 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8875 Fremove_text_properties (make_number (0), make_number (size
),
8876 props
, f
->desired_tool_bar_string
);
8879 /* Put a `display' property on the string for the images to display,
8880 put a `menu_item' property on tool-bar items with a value that
8881 is the index of the item in F's tool-bar item vector. */
8882 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8884 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8886 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8887 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8888 int hmargin
, vmargin
, relief
, idx
, end
;
8889 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8891 /* If image is a vector, choose the image according to the
8893 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8894 if (VECTORP (image
))
8898 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8899 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8902 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8903 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8905 xassert (ASIZE (image
) >= idx
);
8906 image
= AREF (image
, idx
);
8911 /* Ignore invalid image specifications. */
8912 if (!valid_image_p (image
))
8915 /* Display the tool-bar button pressed, or depressed. */
8916 plist
= Fcopy_sequence (XCDR (image
));
8918 /* Compute margin and relief to draw. */
8919 relief
= (tool_bar_button_relief
>= 0
8920 ? tool_bar_button_relief
8921 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8922 hmargin
= vmargin
= relief
;
8924 if (INTEGERP (Vtool_bar_button_margin
)
8925 && XINT (Vtool_bar_button_margin
) > 0)
8927 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8928 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8930 else if (CONSP (Vtool_bar_button_margin
))
8932 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8933 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8934 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8936 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8937 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8938 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8941 if (auto_raise_tool_bar_buttons_p
)
8943 /* Add a `:relief' property to the image spec if the item is
8947 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8954 /* If image is selected, display it pressed, i.e. with a
8955 negative relief. If it's not selected, display it with a
8957 plist
= Fplist_put (plist
, QCrelief
,
8959 ? make_number (-relief
)
8960 : make_number (relief
)));
8965 /* Put a margin around the image. */
8966 if (hmargin
|| vmargin
)
8968 if (hmargin
== vmargin
)
8969 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
8971 plist
= Fplist_put (plist
, QCmargin
,
8972 Fcons (make_number (hmargin
),
8973 make_number (vmargin
)));
8976 /* If button is not enabled, and we don't have special images
8977 for the disabled state, make the image appear disabled by
8978 applying an appropriate algorithm to it. */
8979 if (!enabled_p
&& idx
< 0)
8980 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
8982 /* Put a `display' text property on the string for the image to
8983 display. Put a `menu-item' property on the string that gives
8984 the start of this item's properties in the tool-bar items
8986 image
= Fcons (Qimage
, plist
);
8987 props
= list4 (Qdisplay
, image
,
8988 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
8990 /* Let the last image hide all remaining spaces in the tool bar
8991 string. The string can be longer than needed when we reuse a
8993 if (i
+ 1 == f
->n_tool_bar_items
)
8994 end
= SCHARS (f
->desired_tool_bar_string
);
8997 Fadd_text_properties (make_number (i
), make_number (end
),
8998 props
, f
->desired_tool_bar_string
);
9006 /* Display one line of the tool-bar of frame IT->f. */
9009 display_tool_bar_line (it
)
9012 struct glyph_row
*row
= it
->glyph_row
;
9013 int max_x
= it
->last_visible_x
;
9016 prepare_desired_row (row
);
9017 row
->y
= it
->current_y
;
9019 /* Note that this isn't made use of if the face hasn't a box,
9020 so there's no need to check the face here. */
9021 it
->start_of_box_run_p
= 1;
9023 while (it
->current_x
< max_x
)
9025 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9027 /* Get the next display element. */
9028 if (!get_next_display_element (it
))
9031 /* Produce glyphs. */
9032 x_before
= it
->current_x
;
9033 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9034 PRODUCE_GLYPHS (it
);
9036 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9041 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9043 if (x
+ glyph
->pixel_width
> max_x
)
9045 /* Glyph doesn't fit on line. */
9046 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9052 x
+= glyph
->pixel_width
;
9056 /* Stop at line ends. */
9057 if (ITERATOR_AT_END_OF_LINE_P (it
))
9060 set_iterator_to_next (it
, 1);
9065 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9066 extend_face_to_end_of_line (it
);
9067 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9068 last
->right_box_line_p
= 1;
9069 if (last
== row
->glyphs
[TEXT_AREA
])
9070 last
->left_box_line_p
= 1;
9071 compute_line_metrics (it
);
9073 /* If line is empty, make it occupy the rest of the tool-bar. */
9074 if (!row
->displays_text_p
)
9076 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9077 row
->ascent
= row
->phys_ascent
= 0;
9078 row
->extra_line_spacing
= 0;
9081 row
->full_width_p
= 1;
9082 row
->continued_p
= 0;
9083 row
->truncated_on_left_p
= 0;
9084 row
->truncated_on_right_p
= 0;
9086 it
->current_x
= it
->hpos
= 0;
9087 it
->current_y
+= row
->height
;
9093 /* Value is the number of screen lines needed to make all tool-bar
9094 items of frame F visible. */
9097 tool_bar_lines_needed (f
)
9100 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9103 /* Initialize an iterator for iteration over
9104 F->desired_tool_bar_string in the tool-bar window of frame F. */
9105 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9106 it
.first_visible_x
= 0;
9107 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9108 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9110 while (!ITERATOR_AT_END_P (&it
))
9112 it
.glyph_row
= w
->desired_matrix
->rows
;
9113 clear_glyph_row (it
.glyph_row
);
9114 display_tool_bar_line (&it
);
9117 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9121 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9123 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9132 frame
= selected_frame
;
9134 CHECK_FRAME (frame
);
9137 if (WINDOWP (f
->tool_bar_window
)
9138 || (w
= XWINDOW (f
->tool_bar_window
),
9139 WINDOW_TOTAL_LINES (w
) > 0))
9141 update_tool_bar (f
, 1);
9142 if (f
->n_tool_bar_items
)
9144 build_desired_tool_bar_string (f
);
9145 nlines
= tool_bar_lines_needed (f
);
9149 return make_number (nlines
);
9153 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9154 height should be changed. */
9157 redisplay_tool_bar (f
)
9162 struct glyph_row
*row
;
9163 int change_height_p
= 0;
9166 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9167 update_frame_tool_bar (f
);
9171 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9172 do anything. This means you must start with tool-bar-lines
9173 non-zero to get the auto-sizing effect. Or in other words, you
9174 can turn off tool-bars by specifying tool-bar-lines zero. */
9175 if (!WINDOWP (f
->tool_bar_window
)
9176 || (w
= XWINDOW (f
->tool_bar_window
),
9177 WINDOW_TOTAL_LINES (w
) == 0))
9180 /* Set up an iterator for the tool-bar window. */
9181 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9182 it
.first_visible_x
= 0;
9183 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9186 /* Build a string that represents the contents of the tool-bar. */
9187 build_desired_tool_bar_string (f
);
9188 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9190 /* Display as many lines as needed to display all tool-bar items. */
9191 while (it
.current_y
< it
.last_visible_y
)
9192 display_tool_bar_line (&it
);
9194 /* It doesn't make much sense to try scrolling in the tool-bar
9195 window, so don't do it. */
9196 w
->desired_matrix
->no_scrolling_p
= 1;
9197 w
->must_be_updated_p
= 1;
9199 if (auto_resize_tool_bars_p
)
9203 /* If we couldn't display everything, change the tool-bar's
9205 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9206 change_height_p
= 1;
9208 /* If there are blank lines at the end, except for a partially
9209 visible blank line at the end that is smaller than
9210 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9211 row
= it
.glyph_row
- 1;
9212 if (!row
->displays_text_p
9213 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9214 change_height_p
= 1;
9216 /* If row displays tool-bar items, but is partially visible,
9217 change the tool-bar's height. */
9218 if (row
->displays_text_p
9219 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9220 change_height_p
= 1;
9222 /* Resize windows as needed by changing the `tool-bar-lines'
9225 && (nlines
= tool_bar_lines_needed (f
),
9226 nlines
!= WINDOW_TOTAL_LINES (w
)))
9228 extern Lisp_Object Qtool_bar_lines
;
9230 int old_height
= WINDOW_TOTAL_LINES (w
);
9232 XSETFRAME (frame
, f
);
9233 clear_glyph_matrix (w
->desired_matrix
);
9234 Fmodify_frame_parameters (frame
,
9235 Fcons (Fcons (Qtool_bar_lines
,
9236 make_number (nlines
)),
9238 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9239 fonts_changed_p
= 1;
9243 return change_height_p
;
9247 /* Get information about the tool-bar item which is displayed in GLYPH
9248 on frame F. Return in *PROP_IDX the index where tool-bar item
9249 properties start in F->tool_bar_items. Value is zero if
9250 GLYPH doesn't display a tool-bar item. */
9253 tool_bar_item_info (f
, glyph
, prop_idx
)
9255 struct glyph
*glyph
;
9262 /* This function can be called asynchronously, which means we must
9263 exclude any possibility that Fget_text_property signals an
9265 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9266 charpos
= max (0, charpos
);
9268 /* Get the text property `menu-item' at pos. The value of that
9269 property is the start index of this item's properties in
9270 F->tool_bar_items. */
9271 prop
= Fget_text_property (make_number (charpos
),
9272 Qmenu_item
, f
->current_tool_bar_string
);
9273 if (INTEGERP (prop
))
9275 *prop_idx
= XINT (prop
);
9285 /* Get information about the tool-bar item at position X/Y on frame F.
9286 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9287 the current matrix of the tool-bar window of F, or NULL if not
9288 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9289 item in F->tool_bar_items. Value is
9291 -1 if X/Y is not on a tool-bar item
9292 0 if X/Y is on the same item that was highlighted before.
9296 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9299 struct glyph
**glyph
;
9300 int *hpos
, *vpos
, *prop_idx
;
9302 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9303 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9306 /* Find the glyph under X/Y. */
9307 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9311 /* Get the start of this tool-bar item's properties in
9312 f->tool_bar_items. */
9313 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9316 /* Is mouse on the highlighted item? */
9317 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9318 && *vpos
>= dpyinfo
->mouse_face_beg_row
9319 && *vpos
<= dpyinfo
->mouse_face_end_row
9320 && (*vpos
> dpyinfo
->mouse_face_beg_row
9321 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9322 && (*vpos
< dpyinfo
->mouse_face_end_row
9323 || *hpos
< dpyinfo
->mouse_face_end_col
9324 || dpyinfo
->mouse_face_past_end
))
9332 Handle mouse button event on the tool-bar of frame F, at
9333 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9334 0 for button release. MODIFIERS is event modifiers for button
9338 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9341 unsigned int modifiers
;
9343 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9344 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9345 int hpos
, vpos
, prop_idx
;
9346 struct glyph
*glyph
;
9347 Lisp_Object enabled_p
;
9349 /* If not on the highlighted tool-bar item, return. */
9350 frame_to_window_pixel_xy (w
, &x
, &y
);
9351 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9354 /* If item is disabled, do nothing. */
9355 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9356 if (NILP (enabled_p
))
9361 /* Show item in pressed state. */
9362 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9363 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9364 last_tool_bar_item
= prop_idx
;
9368 Lisp_Object key
, frame
;
9369 struct input_event event
;
9372 /* Show item in released state. */
9373 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9374 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9376 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9378 XSETFRAME (frame
, f
);
9379 event
.kind
= TOOL_BAR_EVENT
;
9380 event
.frame_or_window
= frame
;
9382 kbd_buffer_store_event (&event
);
9384 event
.kind
= TOOL_BAR_EVENT
;
9385 event
.frame_or_window
= frame
;
9387 event
.modifiers
= modifiers
;
9388 kbd_buffer_store_event (&event
);
9389 last_tool_bar_item
= -1;
9394 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9395 tool-bar window-relative coordinates X/Y. Called from
9396 note_mouse_highlight. */
9399 note_tool_bar_highlight (f
, x
, y
)
9403 Lisp_Object window
= f
->tool_bar_window
;
9404 struct window
*w
= XWINDOW (window
);
9405 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9407 struct glyph
*glyph
;
9408 struct glyph_row
*row
;
9410 Lisp_Object enabled_p
;
9412 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9413 int mouse_down_p
, rc
;
9415 /* Function note_mouse_highlight is called with negative x(y
9416 values when mouse moves outside of the frame. */
9417 if (x
<= 0 || y
<= 0)
9419 clear_mouse_face (dpyinfo
);
9423 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9426 /* Not on tool-bar item. */
9427 clear_mouse_face (dpyinfo
);
9431 /* On same tool-bar item as before. */
9434 clear_mouse_face (dpyinfo
);
9436 /* Mouse is down, but on different tool-bar item? */
9437 mouse_down_p
= (dpyinfo
->grabbed
9438 && f
== last_mouse_frame
9439 && FRAME_LIVE_P (f
));
9441 && last_tool_bar_item
!= prop_idx
)
9444 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9445 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9447 /* If tool-bar item is not enabled, don't highlight it. */
9448 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9449 if (!NILP (enabled_p
))
9451 /* Compute the x-position of the glyph. In front and past the
9452 image is a space. We include this in the highlighted area. */
9453 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9454 for (i
= x
= 0; i
< hpos
; ++i
)
9455 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9457 /* Record this as the current active region. */
9458 dpyinfo
->mouse_face_beg_col
= hpos
;
9459 dpyinfo
->mouse_face_beg_row
= vpos
;
9460 dpyinfo
->mouse_face_beg_x
= x
;
9461 dpyinfo
->mouse_face_beg_y
= row
->y
;
9462 dpyinfo
->mouse_face_past_end
= 0;
9464 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9465 dpyinfo
->mouse_face_end_row
= vpos
;
9466 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9467 dpyinfo
->mouse_face_end_y
= row
->y
;
9468 dpyinfo
->mouse_face_window
= window
;
9469 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9471 /* Display it as active. */
9472 show_mouse_face (dpyinfo
, draw
);
9473 dpyinfo
->mouse_face_image_state
= draw
;
9478 /* Set help_echo_string to a help string to display for this tool-bar item.
9479 XTread_socket does the rest. */
9480 help_echo_object
= help_echo_window
= Qnil
;
9482 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9483 if (NILP (help_echo_string
))
9484 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9487 #endif /* HAVE_WINDOW_SYSTEM */
9491 /************************************************************************
9492 Horizontal scrolling
9493 ************************************************************************/
9495 static int hscroll_window_tree
P_ ((Lisp_Object
));
9496 static int hscroll_windows
P_ ((Lisp_Object
));
9498 /* For all leaf windows in the window tree rooted at WINDOW, set their
9499 hscroll value so that PT is (i) visible in the window, and (ii) so
9500 that it is not within a certain margin at the window's left and
9501 right border. Value is non-zero if any window's hscroll has been
9505 hscroll_window_tree (window
)
9508 int hscrolled_p
= 0;
9509 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9510 int hscroll_step_abs
= 0;
9511 double hscroll_step_rel
= 0;
9513 if (hscroll_relative_p
)
9515 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9516 if (hscroll_step_rel
< 0)
9518 hscroll_relative_p
= 0;
9519 hscroll_step_abs
= 0;
9522 else if (INTEGERP (Vhscroll_step
))
9524 hscroll_step_abs
= XINT (Vhscroll_step
);
9525 if (hscroll_step_abs
< 0)
9526 hscroll_step_abs
= 0;
9529 hscroll_step_abs
= 0;
9531 while (WINDOWP (window
))
9533 struct window
*w
= XWINDOW (window
);
9535 if (WINDOWP (w
->hchild
))
9536 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9537 else if (WINDOWP (w
->vchild
))
9538 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9539 else if (w
->cursor
.vpos
>= 0)
9542 int text_area_width
;
9543 struct glyph_row
*current_cursor_row
9544 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9545 struct glyph_row
*desired_cursor_row
9546 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9547 struct glyph_row
*cursor_row
9548 = (desired_cursor_row
->enabled_p
9549 ? desired_cursor_row
9550 : current_cursor_row
);
9552 text_area_width
= window_box_width (w
, TEXT_AREA
);
9554 /* Scroll when cursor is inside this scroll margin. */
9555 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9557 if ((XFASTINT (w
->hscroll
)
9558 && w
->cursor
.x
<= h_margin
)
9559 || (cursor_row
->enabled_p
9560 && cursor_row
->truncated_on_right_p
9561 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9565 struct buffer
*saved_current_buffer
;
9569 /* Find point in a display of infinite width. */
9570 saved_current_buffer
= current_buffer
;
9571 current_buffer
= XBUFFER (w
->buffer
);
9573 if (w
== XWINDOW (selected_window
))
9574 pt
= BUF_PT (current_buffer
);
9577 pt
= marker_position (w
->pointm
);
9578 pt
= max (BEGV
, pt
);
9582 /* Move iterator to pt starting at cursor_row->start in
9583 a line with infinite width. */
9584 init_to_row_start (&it
, w
, cursor_row
);
9585 it
.last_visible_x
= INFINITY
;
9586 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9587 current_buffer
= saved_current_buffer
;
9589 /* Position cursor in window. */
9590 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9591 hscroll
= max (0, (it
.current_x
9592 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9593 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9594 : (text_area_width
/ 2))))
9595 / FRAME_COLUMN_WIDTH (it
.f
);
9596 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9598 if (hscroll_relative_p
)
9599 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9602 wanted_x
= text_area_width
9603 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9606 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9610 if (hscroll_relative_p
)
9611 wanted_x
= text_area_width
* hscroll_step_rel
9614 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9617 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9619 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9621 /* Don't call Fset_window_hscroll if value hasn't
9622 changed because it will prevent redisplay
9624 if (XFASTINT (w
->hscroll
) != hscroll
)
9626 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9627 w
->hscroll
= make_number (hscroll
);
9636 /* Value is non-zero if hscroll of any leaf window has been changed. */
9641 /* Set hscroll so that cursor is visible and not inside horizontal
9642 scroll margins for all windows in the tree rooted at WINDOW. See
9643 also hscroll_window_tree above. Value is non-zero if any window's
9644 hscroll has been changed. If it has, desired matrices on the frame
9645 of WINDOW are cleared. */
9648 hscroll_windows (window
)
9653 if (automatic_hscrolling_p
)
9655 hscrolled_p
= hscroll_window_tree (window
);
9657 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9666 /************************************************************************
9668 ************************************************************************/
9670 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9671 to a non-zero value. This is sometimes handy to have in a debugger
9676 /* First and last unchanged row for try_window_id. */
9678 int debug_first_unchanged_at_end_vpos
;
9679 int debug_last_unchanged_at_beg_vpos
;
9681 /* Delta vpos and y. */
9683 int debug_dvpos
, debug_dy
;
9685 /* Delta in characters and bytes for try_window_id. */
9687 int debug_delta
, debug_delta_bytes
;
9689 /* Values of window_end_pos and window_end_vpos at the end of
9692 EMACS_INT debug_end_pos
, debug_end_vpos
;
9694 /* Append a string to W->desired_matrix->method. FMT is a printf
9695 format string. A1...A9 are a supplement for a variable-length
9696 argument list. If trace_redisplay_p is non-zero also printf the
9697 resulting string to stderr. */
9700 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9703 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9706 char *method
= w
->desired_matrix
->method
;
9707 int len
= strlen (method
);
9708 int size
= sizeof w
->desired_matrix
->method
;
9709 int remaining
= size
- len
- 1;
9711 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9712 if (len
&& remaining
)
9718 strncpy (method
+ len
, buffer
, remaining
);
9720 if (trace_redisplay_p
)
9721 fprintf (stderr
, "%p (%s): %s\n",
9723 ((BUFFERP (w
->buffer
)
9724 && STRINGP (XBUFFER (w
->buffer
)->name
))
9725 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9730 #endif /* GLYPH_DEBUG */
9733 /* Value is non-zero if all changes in window W, which displays
9734 current_buffer, are in the text between START and END. START is a
9735 buffer position, END is given as a distance from Z. Used in
9736 redisplay_internal for display optimization. */
9739 text_outside_line_unchanged_p (w
, start
, end
)
9743 int unchanged_p
= 1;
9745 /* If text or overlays have changed, see where. */
9746 if (XFASTINT (w
->last_modified
) < MODIFF
9747 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9749 /* Gap in the line? */
9750 if (GPT
< start
|| Z
- GPT
< end
)
9753 /* Changes start in front of the line, or end after it? */
9755 && (BEG_UNCHANGED
< start
- 1
9756 || END_UNCHANGED
< end
))
9759 /* If selective display, can't optimize if changes start at the
9760 beginning of the line. */
9762 && INTEGERP (current_buffer
->selective_display
)
9763 && XINT (current_buffer
->selective_display
) > 0
9764 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9767 /* If there are overlays at the start or end of the line, these
9768 may have overlay strings with newlines in them. A change at
9769 START, for instance, may actually concern the display of such
9770 overlay strings as well, and they are displayed on different
9771 lines. So, quickly rule out this case. (For the future, it
9772 might be desirable to implement something more telling than
9773 just BEG/END_UNCHANGED.) */
9776 if (BEG
+ BEG_UNCHANGED
== start
9777 && overlay_touches_p (start
))
9779 if (END_UNCHANGED
== end
9780 && overlay_touches_p (Z
- end
))
9789 /* Do a frame update, taking possible shortcuts into account. This is
9790 the main external entry point for redisplay.
9792 If the last redisplay displayed an echo area message and that message
9793 is no longer requested, we clear the echo area or bring back the
9794 mini-buffer if that is in use. */
9799 redisplay_internal (0);
9804 overlay_arrow_string_or_property (var
)
9809 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
9812 return Voverlay_arrow_string
;
9815 /* Return 1 if there are any overlay-arrows in current_buffer. */
9817 overlay_arrow_in_current_buffer_p ()
9821 for (vlist
= Voverlay_arrow_variable_list
;
9823 vlist
= XCDR (vlist
))
9825 Lisp_Object var
= XCAR (vlist
);
9830 val
= find_symbol_value (var
);
9832 && current_buffer
== XMARKER (val
)->buffer
)
9839 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9843 overlay_arrows_changed_p ()
9847 for (vlist
= Voverlay_arrow_variable_list
;
9849 vlist
= XCDR (vlist
))
9851 Lisp_Object var
= XCAR (vlist
);
9852 Lisp_Object val
, pstr
;
9856 val
= find_symbol_value (var
);
9859 if (! EQ (COERCE_MARKER (val
),
9860 Fget (var
, Qlast_arrow_position
))
9861 || ! (pstr
= overlay_arrow_string_or_property (var
),
9862 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9868 /* Mark overlay arrows to be updated on next redisplay. */
9871 update_overlay_arrows (up_to_date
)
9876 for (vlist
= Voverlay_arrow_variable_list
;
9878 vlist
= XCDR (vlist
))
9880 Lisp_Object var
= XCAR (vlist
);
9887 Lisp_Object val
= find_symbol_value (var
);
9888 Fput (var
, Qlast_arrow_position
,
9889 COERCE_MARKER (val
));
9890 Fput (var
, Qlast_arrow_string
,
9891 overlay_arrow_string_or_property (var
));
9893 else if (up_to_date
< 0
9894 || !NILP (Fget (var
, Qlast_arrow_position
)))
9896 Fput (var
, Qlast_arrow_position
, Qt
);
9897 Fput (var
, Qlast_arrow_string
, Qt
);
9903 /* Return overlay arrow string to display at row.
9904 Return integer (bitmap number) for arrow bitmap in left fringe.
9905 Return nil if no overlay arrow. */
9908 overlay_arrow_at_row (it
, row
)
9910 struct glyph_row
*row
;
9914 for (vlist
= Voverlay_arrow_variable_list
;
9916 vlist
= XCDR (vlist
))
9918 Lisp_Object var
= XCAR (vlist
);
9924 val
= find_symbol_value (var
);
9927 && current_buffer
== XMARKER (val
)->buffer
9928 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9930 if (FRAME_WINDOW_P (it
->f
)
9931 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9933 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
9936 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
9937 return make_number (fringe_bitmap
);
9939 return make_number (-1); /* Use default arrow bitmap */
9941 return overlay_arrow_string_or_property (var
);
9948 /* Return 1 if point moved out of or into a composition. Otherwise
9949 return 0. PREV_BUF and PREV_PT are the last point buffer and
9950 position. BUF and PT are the current point buffer and position. */
9953 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9954 struct buffer
*prev_buf
, *buf
;
9961 XSETBUFFER (buffer
, buf
);
9962 /* Check a composition at the last point if point moved within the
9964 if (prev_buf
== buf
)
9967 /* Point didn't move. */
9970 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
9971 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
9972 && COMPOSITION_VALID_P (start
, end
, prop
)
9973 && start
< prev_pt
&& end
> prev_pt
)
9974 /* The last point was within the composition. Return 1 iff
9975 point moved out of the composition. */
9976 return (pt
<= start
|| pt
>= end
);
9979 /* Check a composition at the current point. */
9980 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
9981 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
9982 && COMPOSITION_VALID_P (start
, end
, prop
)
9983 && start
< pt
&& end
> pt
);
9987 /* Reconsider the setting of B->clip_changed which is displayed
9991 reconsider_clip_changes (w
, b
)
9996 && !NILP (w
->window_end_valid
)
9997 && w
->current_matrix
->buffer
== b
9998 && w
->current_matrix
->zv
== BUF_ZV (b
)
9999 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10000 b
->clip_changed
= 0;
10002 /* If display wasn't paused, and W is not a tool bar window, see if
10003 point has been moved into or out of a composition. In that case,
10004 we set b->clip_changed to 1 to force updating the screen. If
10005 b->clip_changed has already been set to 1, we can skip this
10007 if (!b
->clip_changed
10008 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10012 if (w
== XWINDOW (selected_window
))
10013 pt
= BUF_PT (current_buffer
);
10015 pt
= marker_position (w
->pointm
);
10017 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10018 || pt
!= XINT (w
->last_point
))
10019 && check_point_in_composition (w
->current_matrix
->buffer
,
10020 XINT (w
->last_point
),
10021 XBUFFER (w
->buffer
), pt
))
10022 b
->clip_changed
= 1;
10027 /* Select FRAME to forward the values of frame-local variables into C
10028 variables so that the redisplay routines can access those values
10032 select_frame_for_redisplay (frame
)
10035 Lisp_Object tail
, sym
, val
;
10036 Lisp_Object old
= selected_frame
;
10038 selected_frame
= frame
;
10040 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10041 if (CONSP (XCAR (tail
))
10042 && (sym
= XCAR (XCAR (tail
)),
10044 && (sym
= indirect_variable (sym
),
10045 val
= SYMBOL_VALUE (sym
),
10046 (BUFFER_LOCAL_VALUEP (val
)
10047 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10048 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10049 Fsymbol_value (sym
);
10051 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10052 if (CONSP (XCAR (tail
))
10053 && (sym
= XCAR (XCAR (tail
)),
10055 && (sym
= indirect_variable (sym
),
10056 val
= SYMBOL_VALUE (sym
),
10057 (BUFFER_LOCAL_VALUEP (val
)
10058 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10059 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10060 Fsymbol_value (sym
);
10064 #define STOP_POLLING \
10065 do { if (! polling_stopped_here) stop_polling (); \
10066 polling_stopped_here = 1; } while (0)
10068 #define RESUME_POLLING \
10069 do { if (polling_stopped_here) start_polling (); \
10070 polling_stopped_here = 0; } while (0)
10073 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10074 response to any user action; therefore, we should preserve the echo
10075 area. (Actually, our caller does that job.) Perhaps in the future
10076 avoid recentering windows if it is not necessary; currently that
10077 causes some problems. */
10080 redisplay_internal (preserve_echo_area
)
10081 int preserve_echo_area
;
10083 struct window
*w
= XWINDOW (selected_window
);
10084 struct frame
*f
= XFRAME (w
->frame
);
10086 int must_finish
= 0;
10087 struct text_pos tlbufpos
, tlendpos
;
10088 int number_of_visible_frames
;
10090 struct frame
*sf
= SELECTED_FRAME ();
10091 int polling_stopped_here
= 0;
10093 /* Non-zero means redisplay has to consider all windows on all
10094 frames. Zero means, only selected_window is considered. */
10095 int consider_all_windows_p
;
10097 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10099 /* No redisplay if running in batch mode or frame is not yet fully
10100 initialized, or redisplay is explicitly turned off by setting
10101 Vinhibit_redisplay. */
10103 || !NILP (Vinhibit_redisplay
)
10104 || !f
->glyphs_initialized_p
)
10107 /* The flag redisplay_performed_directly_p is set by
10108 direct_output_for_insert when it already did the whole screen
10109 update necessary. */
10110 if (redisplay_performed_directly_p
)
10112 redisplay_performed_directly_p
= 0;
10113 if (!hscroll_windows (selected_window
))
10117 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10118 if (popup_activated ())
10122 /* I don't think this happens but let's be paranoid. */
10123 if (redisplaying_p
)
10126 /* Record a function that resets redisplaying_p to its old value
10127 when we leave this function. */
10128 count
= SPECPDL_INDEX ();
10129 record_unwind_protect (unwind_redisplay
,
10130 Fcons (make_number (redisplaying_p
), selected_frame
));
10132 specbind (Qinhibit_free_realized_faces
, Qnil
);
10136 reconsider_clip_changes (w
, current_buffer
);
10138 /* If new fonts have been loaded that make a glyph matrix adjustment
10139 necessary, do it. */
10140 if (fonts_changed_p
)
10142 adjust_glyphs (NULL
);
10143 ++windows_or_buffers_changed
;
10144 fonts_changed_p
= 0;
10147 /* If face_change_count is non-zero, init_iterator will free all
10148 realized faces, which includes the faces referenced from current
10149 matrices. So, we can't reuse current matrices in this case. */
10150 if (face_change_count
)
10151 ++windows_or_buffers_changed
;
10153 if (! FRAME_WINDOW_P (sf
)
10154 && previous_terminal_frame
!= sf
)
10156 /* Since frames on an ASCII terminal share the same display
10157 area, displaying a different frame means redisplay the whole
10159 windows_or_buffers_changed
++;
10160 SET_FRAME_GARBAGED (sf
);
10161 XSETFRAME (Vterminal_frame
, sf
);
10163 previous_terminal_frame
= sf
;
10165 /* Set the visible flags for all frames. Do this before checking
10166 for resized or garbaged frames; they want to know if their frames
10167 are visible. See the comment in frame.h for
10168 FRAME_SAMPLE_VISIBILITY. */
10170 Lisp_Object tail
, frame
;
10172 number_of_visible_frames
= 0;
10174 FOR_EACH_FRAME (tail
, frame
)
10176 struct frame
*f
= XFRAME (frame
);
10178 FRAME_SAMPLE_VISIBILITY (f
);
10179 if (FRAME_VISIBLE_P (f
))
10180 ++number_of_visible_frames
;
10181 clear_desired_matrices (f
);
10185 /* Notice any pending interrupt request to change frame size. */
10186 do_pending_window_change (1);
10188 /* Clear frames marked as garbaged. */
10189 if (frame_garbaged
)
10190 clear_garbaged_frames ();
10192 /* Build menubar and tool-bar items. */
10193 prepare_menu_bars ();
10195 if (windows_or_buffers_changed
)
10196 update_mode_lines
++;
10198 /* Detect case that we need to write or remove a star in the mode line. */
10199 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10201 w
->update_mode_line
= Qt
;
10202 if (buffer_shared
> 1)
10203 update_mode_lines
++;
10206 /* If %c is in the mode line, update it if needed. */
10207 if (!NILP (w
->column_number_displayed
)
10208 /* This alternative quickly identifies a common case
10209 where no change is needed. */
10210 && !(PT
== XFASTINT (w
->last_point
)
10211 && XFASTINT (w
->last_modified
) >= MODIFF
10212 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10213 && (XFASTINT (w
->column_number_displayed
)
10214 != (int) current_column ())) /* iftc */
10215 w
->update_mode_line
= Qt
;
10217 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10219 /* The variable buffer_shared is set in redisplay_window and
10220 indicates that we redisplay a buffer in different windows. See
10222 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10223 || cursor_type_changed
);
10225 /* If specs for an arrow have changed, do thorough redisplay
10226 to ensure we remove any arrow that should no longer exist. */
10227 if (overlay_arrows_changed_p ())
10228 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10230 /* Normally the message* functions will have already displayed and
10231 updated the echo area, but the frame may have been trashed, or
10232 the update may have been preempted, so display the echo area
10233 again here. Checking message_cleared_p captures the case that
10234 the echo area should be cleared. */
10235 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10236 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10237 || (message_cleared_p
10238 && minibuf_level
== 0
10239 /* If the mini-window is currently selected, this means the
10240 echo-area doesn't show through. */
10241 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10243 int window_height_changed_p
= echo_area_display (0);
10246 /* If we don't display the current message, don't clear the
10247 message_cleared_p flag, because, if we did, we wouldn't clear
10248 the echo area in the next redisplay which doesn't preserve
10250 if (!display_last_displayed_message_p
)
10251 message_cleared_p
= 0;
10253 if (fonts_changed_p
)
10255 else if (window_height_changed_p
)
10257 consider_all_windows_p
= 1;
10258 ++update_mode_lines
;
10259 ++windows_or_buffers_changed
;
10261 /* If window configuration was changed, frames may have been
10262 marked garbaged. Clear them or we will experience
10263 surprises wrt scrolling. */
10264 if (frame_garbaged
)
10265 clear_garbaged_frames ();
10268 else if (EQ (selected_window
, minibuf_window
)
10269 && (current_buffer
->clip_changed
10270 || XFASTINT (w
->last_modified
) < MODIFF
10271 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10272 && resize_mini_window (w
, 0))
10274 /* Resized active mini-window to fit the size of what it is
10275 showing if its contents might have changed. */
10277 consider_all_windows_p
= 1;
10278 ++windows_or_buffers_changed
;
10279 ++update_mode_lines
;
10281 /* If window configuration was changed, frames may have been
10282 marked garbaged. Clear them or we will experience
10283 surprises wrt scrolling. */
10284 if (frame_garbaged
)
10285 clear_garbaged_frames ();
10289 /* If showing the region, and mark has changed, we must redisplay
10290 the whole window. The assignment to this_line_start_pos prevents
10291 the optimization directly below this if-statement. */
10292 if (((!NILP (Vtransient_mark_mode
)
10293 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10294 != !NILP (w
->region_showing
))
10295 || (!NILP (w
->region_showing
)
10296 && !EQ (w
->region_showing
,
10297 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10298 CHARPOS (this_line_start_pos
) = 0;
10300 /* Optimize the case that only the line containing the cursor in the
10301 selected window has changed. Variables starting with this_ are
10302 set in display_line and record information about the line
10303 containing the cursor. */
10304 tlbufpos
= this_line_start_pos
;
10305 tlendpos
= this_line_end_pos
;
10306 if (!consider_all_windows_p
10307 && CHARPOS (tlbufpos
) > 0
10308 && NILP (w
->update_mode_line
)
10309 && !current_buffer
->clip_changed
10310 && !current_buffer
->prevent_redisplay_optimizations_p
10311 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10312 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10313 /* Make sure recorded data applies to current buffer, etc. */
10314 && this_line_buffer
== current_buffer
10315 && current_buffer
== XBUFFER (w
->buffer
)
10316 && NILP (w
->force_start
)
10317 && NILP (w
->optional_new_start
)
10318 /* Point must be on the line that we have info recorded about. */
10319 && PT
>= CHARPOS (tlbufpos
)
10320 && PT
<= Z
- CHARPOS (tlendpos
)
10321 /* All text outside that line, including its final newline,
10322 must be unchanged */
10323 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10324 CHARPOS (tlendpos
)))
10326 if (CHARPOS (tlbufpos
) > BEGV
10327 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10328 && (CHARPOS (tlbufpos
) == ZV
10329 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10330 /* Former continuation line has disappeared by becoming empty */
10332 else if (XFASTINT (w
->last_modified
) < MODIFF
10333 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10334 || MINI_WINDOW_P (w
))
10336 /* We have to handle the case of continuation around a
10337 wide-column character (See the comment in indent.c around
10340 For instance, in the following case:
10342 -------- Insert --------
10343 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10344 J_I_ ==> J_I_ `^^' are cursors.
10348 As we have to redraw the line above, we should goto cancel. */
10351 int line_height_before
= this_line_pixel_height
;
10353 /* Note that start_display will handle the case that the
10354 line starting at tlbufpos is a continuation lines. */
10355 start_display (&it
, w
, tlbufpos
);
10357 /* Implementation note: It this still necessary? */
10358 if (it
.current_x
!= this_line_start_x
)
10361 TRACE ((stderr
, "trying display optimization 1\n"));
10362 w
->cursor
.vpos
= -1;
10363 overlay_arrow_seen
= 0;
10364 it
.vpos
= this_line_vpos
;
10365 it
.current_y
= this_line_y
;
10366 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10367 display_line (&it
);
10369 /* If line contains point, is not continued,
10370 and ends at same distance from eob as before, we win */
10371 if (w
->cursor
.vpos
>= 0
10372 /* Line is not continued, otherwise this_line_start_pos
10373 would have been set to 0 in display_line. */
10374 && CHARPOS (this_line_start_pos
)
10375 /* Line ends as before. */
10376 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10377 /* Line has same height as before. Otherwise other lines
10378 would have to be shifted up or down. */
10379 && this_line_pixel_height
== line_height_before
)
10381 /* If this is not the window's last line, we must adjust
10382 the charstarts of the lines below. */
10383 if (it
.current_y
< it
.last_visible_y
)
10385 struct glyph_row
*row
10386 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10387 int delta
, delta_bytes
;
10389 if (Z
- CHARPOS (tlendpos
) == ZV
)
10391 /* This line ends at end of (accessible part of)
10392 buffer. There is no newline to count. */
10394 - CHARPOS (tlendpos
)
10395 - MATRIX_ROW_START_CHARPOS (row
));
10396 delta_bytes
= (Z_BYTE
10397 - BYTEPOS (tlendpos
)
10398 - MATRIX_ROW_START_BYTEPOS (row
));
10402 /* This line ends in a newline. Must take
10403 account of the newline and the rest of the
10404 text that follows. */
10406 - CHARPOS (tlendpos
)
10407 - MATRIX_ROW_START_CHARPOS (row
));
10408 delta_bytes
= (Z_BYTE
10409 - BYTEPOS (tlendpos
)
10410 - MATRIX_ROW_START_BYTEPOS (row
));
10413 increment_matrix_positions (w
->current_matrix
,
10414 this_line_vpos
+ 1,
10415 w
->current_matrix
->nrows
,
10416 delta
, delta_bytes
);
10419 /* If this row displays text now but previously didn't,
10420 or vice versa, w->window_end_vpos may have to be
10422 if ((it
.glyph_row
- 1)->displays_text_p
)
10424 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10425 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10427 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10428 && this_line_vpos
> 0)
10429 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10430 w
->window_end_valid
= Qnil
;
10432 /* Update hint: No need to try to scroll in update_window. */
10433 w
->desired_matrix
->no_scrolling_p
= 1;
10436 *w
->desired_matrix
->method
= 0;
10437 debug_method_add (w
, "optimization 1");
10439 #ifdef HAVE_WINDOW_SYSTEM
10440 update_window_fringes (w
, 0);
10447 else if (/* Cursor position hasn't changed. */
10448 PT
== XFASTINT (w
->last_point
)
10449 /* Make sure the cursor was last displayed
10450 in this window. Otherwise we have to reposition it. */
10451 && 0 <= w
->cursor
.vpos
10452 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10456 do_pending_window_change (1);
10458 /* We used to always goto end_of_redisplay here, but this
10459 isn't enough if we have a blinking cursor. */
10460 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10461 goto end_of_redisplay
;
10465 /* If highlighting the region, or if the cursor is in the echo area,
10466 then we can't just move the cursor. */
10467 else if (! (!NILP (Vtransient_mark_mode
)
10468 && !NILP (current_buffer
->mark_active
))
10469 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10470 || highlight_nonselected_windows
)
10471 && NILP (w
->region_showing
)
10472 && NILP (Vshow_trailing_whitespace
)
10473 && !cursor_in_echo_area
)
10476 struct glyph_row
*row
;
10478 /* Skip from tlbufpos to PT and see where it is. Note that
10479 PT may be in invisible text. If so, we will end at the
10480 next visible position. */
10481 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10482 NULL
, DEFAULT_FACE_ID
);
10483 it
.current_x
= this_line_start_x
;
10484 it
.current_y
= this_line_y
;
10485 it
.vpos
= this_line_vpos
;
10487 /* The call to move_it_to stops in front of PT, but
10488 moves over before-strings. */
10489 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10491 if (it
.vpos
== this_line_vpos
10492 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10495 xassert (this_line_vpos
== it
.vpos
);
10496 xassert (this_line_y
== it
.current_y
);
10497 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10499 *w
->desired_matrix
->method
= 0;
10500 debug_method_add (w
, "optimization 3");
10509 /* Text changed drastically or point moved off of line. */
10510 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10513 CHARPOS (this_line_start_pos
) = 0;
10514 consider_all_windows_p
|= buffer_shared
> 1;
10515 ++clear_face_cache_count
;
10516 #ifdef HAVE_WINDOW_SYSTEM
10517 ++clear_image_cache_count
;
10520 /* Build desired matrices, and update the display. If
10521 consider_all_windows_p is non-zero, do it for all windows on all
10522 frames. Otherwise do it for selected_window, only. */
10524 if (consider_all_windows_p
)
10526 Lisp_Object tail
, frame
;
10527 int i
, n
= 0, size
= 50;
10528 struct frame
**updated
10529 = (struct frame
**) alloca (size
* sizeof *updated
);
10531 /* Recompute # windows showing selected buffer. This will be
10532 incremented each time such a window is displayed. */
10535 FOR_EACH_FRAME (tail
, frame
)
10537 struct frame
*f
= XFRAME (frame
);
10539 if (FRAME_WINDOW_P (f
) || f
== sf
)
10541 if (! EQ (frame
, selected_frame
))
10542 /* Select the frame, for the sake of frame-local
10544 select_frame_for_redisplay (frame
);
10546 /* Mark all the scroll bars to be removed; we'll redeem
10547 the ones we want when we redisplay their windows. */
10548 if (condemn_scroll_bars_hook
)
10549 condemn_scroll_bars_hook (f
);
10551 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10552 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10554 /* Any scroll bars which redisplay_windows should have
10555 nuked should now go away. */
10556 if (judge_scroll_bars_hook
)
10557 judge_scroll_bars_hook (f
);
10559 /* If fonts changed, display again. */
10560 /* ??? rms: I suspect it is a mistake to jump all the way
10561 back to retry here. It should just retry this frame. */
10562 if (fonts_changed_p
)
10565 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10567 /* See if we have to hscroll. */
10568 if (hscroll_windows (f
->root_window
))
10571 /* Prevent various kinds of signals during display
10572 update. stdio is not robust about handling
10573 signals, which can cause an apparent I/O
10575 if (interrupt_input
)
10576 unrequest_sigio ();
10579 /* Update the display. */
10580 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10581 pause
|= update_frame (f
, 0, 0);
10582 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10589 int nbytes
= size
* sizeof *updated
;
10590 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10591 bcopy (updated
, p
, nbytes
);
10602 /* Do the mark_window_display_accurate after all windows have
10603 been redisplayed because this call resets flags in buffers
10604 which are needed for proper redisplay. */
10605 for (i
= 0; i
< n
; ++i
)
10607 struct frame
*f
= updated
[i
];
10608 mark_window_display_accurate (f
->root_window
, 1);
10609 if (frame_up_to_date_hook
)
10610 frame_up_to_date_hook (f
);
10614 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10616 Lisp_Object mini_window
;
10617 struct frame
*mini_frame
;
10619 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10620 /* Use list_of_error, not Qerror, so that
10621 we catch only errors and don't run the debugger. */
10622 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10624 redisplay_window_error
);
10626 /* Compare desired and current matrices, perform output. */
10629 /* If fonts changed, display again. */
10630 if (fonts_changed_p
)
10633 /* Prevent various kinds of signals during display update.
10634 stdio is not robust about handling signals,
10635 which can cause an apparent I/O error. */
10636 if (interrupt_input
)
10637 unrequest_sigio ();
10640 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10642 if (hscroll_windows (selected_window
))
10645 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10646 pause
= update_frame (sf
, 0, 0);
10649 /* We may have called echo_area_display at the top of this
10650 function. If the echo area is on another frame, that may
10651 have put text on a frame other than the selected one, so the
10652 above call to update_frame would not have caught it. Catch
10654 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10655 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10657 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10659 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10660 pause
|= update_frame (mini_frame
, 0, 0);
10661 if (!pause
&& hscroll_windows (mini_window
))
10666 /* If display was paused because of pending input, make sure we do a
10667 thorough update the next time. */
10670 /* Prevent the optimization at the beginning of
10671 redisplay_internal that tries a single-line update of the
10672 line containing the cursor in the selected window. */
10673 CHARPOS (this_line_start_pos
) = 0;
10675 /* Let the overlay arrow be updated the next time. */
10676 update_overlay_arrows (0);
10678 /* If we pause after scrolling, some rows in the current
10679 matrices of some windows are not valid. */
10680 if (!WINDOW_FULL_WIDTH_P (w
)
10681 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10682 update_mode_lines
= 1;
10686 if (!consider_all_windows_p
)
10688 /* This has already been done above if
10689 consider_all_windows_p is set. */
10690 mark_window_display_accurate_1 (w
, 1);
10692 /* Say overlay arrows are up to date. */
10693 update_overlay_arrows (1);
10695 if (frame_up_to_date_hook
!= 0)
10696 frame_up_to_date_hook (sf
);
10699 update_mode_lines
= 0;
10700 windows_or_buffers_changed
= 0;
10701 cursor_type_changed
= 0;
10704 /* Start SIGIO interrupts coming again. Having them off during the
10705 code above makes it less likely one will discard output, but not
10706 impossible, since there might be stuff in the system buffer here.
10707 But it is much hairier to try to do anything about that. */
10708 if (interrupt_input
)
10712 /* If a frame has become visible which was not before, redisplay
10713 again, so that we display it. Expose events for such a frame
10714 (which it gets when becoming visible) don't call the parts of
10715 redisplay constructing glyphs, so simply exposing a frame won't
10716 display anything in this case. So, we have to display these
10717 frames here explicitly. */
10720 Lisp_Object tail
, frame
;
10723 FOR_EACH_FRAME (tail
, frame
)
10725 int this_is_visible
= 0;
10727 if (XFRAME (frame
)->visible
)
10728 this_is_visible
= 1;
10729 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10730 if (XFRAME (frame
)->visible
)
10731 this_is_visible
= 1;
10733 if (this_is_visible
)
10737 if (new_count
!= number_of_visible_frames
)
10738 windows_or_buffers_changed
++;
10741 /* Change frame size now if a change is pending. */
10742 do_pending_window_change (1);
10744 /* If we just did a pending size change, or have additional
10745 visible frames, redisplay again. */
10746 if (windows_or_buffers_changed
&& !pause
)
10749 /* Clear the face cache eventually. */
10750 if (consider_all_windows_p
)
10752 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10754 clear_face_cache (0);
10755 clear_face_cache_count
= 0;
10757 #ifdef HAVE_WINDOW_SYSTEM
10758 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
10760 Lisp_Object tail
, frame
;
10761 FOR_EACH_FRAME (tail
, frame
)
10763 struct frame
*f
= XFRAME (frame
);
10764 if (FRAME_WINDOW_P (f
))
10765 clear_image_cache (f
, 0);
10767 clear_image_cache_count
= 0;
10769 #endif /* HAVE_WINDOW_SYSTEM */
10773 unbind_to (count
, Qnil
);
10778 /* Redisplay, but leave alone any recent echo area message unless
10779 another message has been requested in its place.
10781 This is useful in situations where you need to redisplay but no
10782 user action has occurred, making it inappropriate for the message
10783 area to be cleared. See tracking_off and
10784 wait_reading_process_output for examples of these situations.
10786 FROM_WHERE is an integer saying from where this function was
10787 called. This is useful for debugging. */
10790 redisplay_preserve_echo_area (from_where
)
10793 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10795 if (!NILP (echo_area_buffer
[1]))
10797 /* We have a previously displayed message, but no current
10798 message. Redisplay the previous message. */
10799 display_last_displayed_message_p
= 1;
10800 redisplay_internal (1);
10801 display_last_displayed_message_p
= 0;
10804 redisplay_internal (1);
10806 if (rif
!= NULL
&& rif
->flush_display_optional
)
10807 rif
->flush_display_optional (NULL
);
10811 /* Function registered with record_unwind_protect in
10812 redisplay_internal. Reset redisplaying_p to the value it had
10813 before redisplay_internal was called, and clear
10814 prevent_freeing_realized_faces_p. It also selects the previously
10818 unwind_redisplay (val
)
10821 Lisp_Object old_redisplaying_p
, old_frame
;
10823 old_redisplaying_p
= XCAR (val
);
10824 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10825 old_frame
= XCDR (val
);
10826 if (! EQ (old_frame
, selected_frame
))
10827 select_frame_for_redisplay (old_frame
);
10832 /* Mark the display of window W as accurate or inaccurate. If
10833 ACCURATE_P is non-zero mark display of W as accurate. If
10834 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10835 redisplay_internal is called. */
10838 mark_window_display_accurate_1 (w
, accurate_p
)
10842 if (BUFFERP (w
->buffer
))
10844 struct buffer
*b
= XBUFFER (w
->buffer
);
10847 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10848 w
->last_overlay_modified
10849 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10851 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10855 b
->clip_changed
= 0;
10856 b
->prevent_redisplay_optimizations_p
= 0;
10858 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10859 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10860 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10861 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10863 w
->current_matrix
->buffer
= b
;
10864 w
->current_matrix
->begv
= BUF_BEGV (b
);
10865 w
->current_matrix
->zv
= BUF_ZV (b
);
10867 w
->last_cursor
= w
->cursor
;
10868 w
->last_cursor_off_p
= w
->cursor_off_p
;
10870 if (w
== XWINDOW (selected_window
))
10871 w
->last_point
= make_number (BUF_PT (b
));
10873 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10879 w
->window_end_valid
= w
->buffer
;
10880 #if 0 /* This is incorrect with variable-height lines. */
10881 xassert (XINT (w
->window_end_vpos
)
10882 < (WINDOW_TOTAL_LINES (w
)
10883 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10885 w
->update_mode_line
= Qnil
;
10890 /* Mark the display of windows in the window tree rooted at WINDOW as
10891 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10892 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10893 be redisplayed the next time redisplay_internal is called. */
10896 mark_window_display_accurate (window
, accurate_p
)
10897 Lisp_Object window
;
10902 for (; !NILP (window
); window
= w
->next
)
10904 w
= XWINDOW (window
);
10905 mark_window_display_accurate_1 (w
, accurate_p
);
10907 if (!NILP (w
->vchild
))
10908 mark_window_display_accurate (w
->vchild
, accurate_p
);
10909 if (!NILP (w
->hchild
))
10910 mark_window_display_accurate (w
->hchild
, accurate_p
);
10915 update_overlay_arrows (1);
10919 /* Force a thorough redisplay the next time by setting
10920 last_arrow_position and last_arrow_string to t, which is
10921 unequal to any useful value of Voverlay_arrow_... */
10922 update_overlay_arrows (-1);
10927 /* Return value in display table DP (Lisp_Char_Table *) for character
10928 C. Since a display table doesn't have any parent, we don't have to
10929 follow parent. Do not call this function directly but use the
10930 macro DISP_CHAR_VECTOR. */
10933 disp_char_vector (dp
, c
)
10934 struct Lisp_Char_Table
*dp
;
10940 if (SINGLE_BYTE_CHAR_P (c
))
10941 return (dp
->contents
[c
]);
10943 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10946 else if (code
[2] < 32)
10949 /* Here, the possible range of code[0] (== charset ID) is
10950 128..max_charset. Since the top level char table contains data
10951 for multibyte characters after 256th element, we must increment
10952 code[0] by 128 to get a correct index. */
10954 code
[3] = -1; /* anchor */
10956 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10958 val
= dp
->contents
[code
[i
]];
10959 if (!SUB_CHAR_TABLE_P (val
))
10960 return (NILP (val
) ? dp
->defalt
: val
);
10963 /* Here, val is a sub char table. We return the default value of
10965 return (dp
->defalt
);
10970 /***********************************************************************
10972 ***********************************************************************/
10974 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
10977 redisplay_windows (window
)
10978 Lisp_Object window
;
10980 while (!NILP (window
))
10982 struct window
*w
= XWINDOW (window
);
10984 if (!NILP (w
->hchild
))
10985 redisplay_windows (w
->hchild
);
10986 else if (!NILP (w
->vchild
))
10987 redisplay_windows (w
->vchild
);
10990 displayed_buffer
= XBUFFER (w
->buffer
);
10991 /* Use list_of_error, not Qerror, so that
10992 we catch only errors and don't run the debugger. */
10993 internal_condition_case_1 (redisplay_window_0
, window
,
10995 redisplay_window_error
);
11003 redisplay_window_error ()
11005 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11010 redisplay_window_0 (window
)
11011 Lisp_Object window
;
11013 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11014 redisplay_window (window
, 0);
11019 redisplay_window_1 (window
)
11020 Lisp_Object window
;
11022 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11023 redisplay_window (window
, 1);
11028 /* Increment GLYPH until it reaches END or CONDITION fails while
11029 adding (GLYPH)->pixel_width to X. */
11031 #define SKIP_GLYPHS(glyph, end, x, condition) \
11034 (x) += (glyph)->pixel_width; \
11037 while ((glyph) < (end) && (condition))
11040 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11041 DELTA is the number of bytes by which positions recorded in ROW
11042 differ from current buffer positions. */
11045 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11047 struct glyph_row
*row
;
11048 struct glyph_matrix
*matrix
;
11049 int delta
, delta_bytes
, dy
, dvpos
;
11051 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11052 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11053 struct glyph
*cursor
= NULL
;
11054 /* The first glyph that starts a sequence of glyphs from string. */
11055 struct glyph
*string_start
;
11056 /* The X coordinate of string_start. */
11057 int string_start_x
;
11058 /* The last known character position. */
11059 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11060 /* The last known character position before string_start. */
11061 int string_before_pos
;
11064 int cursor_from_overlay_pos
= 0;
11065 int pt_old
= PT
- delta
;
11067 /* Skip over glyphs not having an object at the start of the row.
11068 These are special glyphs like truncation marks on terminal
11070 if (row
->displays_text_p
)
11072 && INTEGERP (glyph
->object
)
11073 && glyph
->charpos
< 0)
11075 x
+= glyph
->pixel_width
;
11079 string_start
= NULL
;
11081 && !INTEGERP (glyph
->object
)
11082 && (!BUFFERP (glyph
->object
)
11083 || (last_pos
= glyph
->charpos
) < pt_old
))
11085 if (! STRINGP (glyph
->object
))
11087 string_start
= NULL
;
11088 x
+= glyph
->pixel_width
;
11090 if (cursor_from_overlay_pos
11091 && last_pos
> cursor_from_overlay_pos
)
11093 cursor_from_overlay_pos
= 0;
11099 string_before_pos
= last_pos
;
11100 string_start
= glyph
;
11101 string_start_x
= x
;
11102 /* Skip all glyphs from string. */
11106 if ((cursor
== NULL
|| glyph
> cursor
)
11107 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11108 Qcursor
, (glyph
)->object
))
11109 && (pos
= string_buffer_position (w
, glyph
->object
,
11110 string_before_pos
),
11111 (pos
== 0 /* From overlay */
11112 || pos
== pt_old
)))
11114 /* Estimate overlay buffer position from the buffer
11115 positions of the glyphs before and after the overlay.
11116 Add 1 to last_pos so that if point corresponds to the
11117 glyph right after the overlay, we still use a 'cursor'
11118 property found in that overlay. */
11119 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11123 x
+= glyph
->pixel_width
;
11126 while (glyph
< end
&& STRINGP (glyph
->object
));
11130 if (cursor
!= NULL
)
11135 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11137 /* Scan back over the ellipsis glyphs, decrementing positions. */
11138 while (glyph
> row
->glyphs
[TEXT_AREA
]
11139 && (glyph
- 1)->charpos
== last_pos
)
11140 glyph
--, x
-= glyph
->pixel_width
;
11141 /* That loop always goes one position too far,
11142 including the glyph before the ellipsis.
11143 So scan forward over that one. */
11144 x
+= glyph
->pixel_width
;
11147 else if (string_start
11148 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11150 /* We may have skipped over point because the previous glyphs
11151 are from string. As there's no easy way to know the
11152 character position of the current glyph, find the correct
11153 glyph on point by scanning from string_start again. */
11155 Lisp_Object string
;
11158 limit
= make_number (pt_old
+ 1);
11160 glyph
= string_start
;
11161 x
= string_start_x
;
11162 string
= glyph
->object
;
11163 pos
= string_buffer_position (w
, string
, string_before_pos
);
11164 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11165 because we always put cursor after overlay strings. */
11166 while (pos
== 0 && glyph
< end
)
11168 string
= glyph
->object
;
11169 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11171 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11174 while (glyph
< end
)
11176 pos
= XINT (Fnext_single_char_property_change
11177 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11180 /* Skip glyphs from the same string. */
11181 string
= glyph
->object
;
11182 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11183 /* Skip glyphs from an overlay. */
11185 && ! string_buffer_position (w
, glyph
->object
, pos
))
11187 string
= glyph
->object
;
11188 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11193 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11195 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11196 w
->cursor
.y
= row
->y
+ dy
;
11198 if (w
== XWINDOW (selected_window
))
11200 if (!row
->continued_p
11201 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11204 this_line_buffer
= XBUFFER (w
->buffer
);
11206 CHARPOS (this_line_start_pos
)
11207 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11208 BYTEPOS (this_line_start_pos
)
11209 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11211 CHARPOS (this_line_end_pos
)
11212 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11213 BYTEPOS (this_line_end_pos
)
11214 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11216 this_line_y
= w
->cursor
.y
;
11217 this_line_pixel_height
= row
->height
;
11218 this_line_vpos
= w
->cursor
.vpos
;
11219 this_line_start_x
= row
->x
;
11222 CHARPOS (this_line_start_pos
) = 0;
11227 /* Run window scroll functions, if any, for WINDOW with new window
11228 start STARTP. Sets the window start of WINDOW to that position.
11230 We assume that the window's buffer is really current. */
11232 static INLINE
struct text_pos
11233 run_window_scroll_functions (window
, startp
)
11234 Lisp_Object window
;
11235 struct text_pos startp
;
11237 struct window
*w
= XWINDOW (window
);
11238 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11240 if (current_buffer
!= XBUFFER (w
->buffer
))
11243 if (!NILP (Vwindow_scroll_functions
))
11245 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11246 make_number (CHARPOS (startp
)));
11247 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11248 /* In case the hook functions switch buffers. */
11249 if (current_buffer
!= XBUFFER (w
->buffer
))
11250 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11257 /* Make sure the line containing the cursor is fully visible.
11258 A value of 1 means there is nothing to be done.
11259 (Either the line is fully visible, or it cannot be made so,
11260 or we cannot tell.)
11262 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11263 is higher than window.
11265 A value of 0 means the caller should do scrolling
11266 as if point had gone off the screen. */
11269 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11273 struct glyph_matrix
*matrix
;
11274 struct glyph_row
*row
;
11277 if (!make_cursor_line_fully_visible_p
)
11280 /* It's not always possible to find the cursor, e.g, when a window
11281 is full of overlay strings. Don't do anything in that case. */
11282 if (w
->cursor
.vpos
< 0)
11285 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11286 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11288 /* If the cursor row is not partially visible, there's nothing to do. */
11289 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11292 /* If the row the cursor is in is taller than the window's height,
11293 it's not clear what to do, so do nothing. */
11294 window_height
= window_box_height (w
);
11295 if (row
->height
>= window_height
)
11297 if (!force_p
|| w
->vscroll
)
11303 /* This code used to try to scroll the window just enough to make
11304 the line visible. It returned 0 to say that the caller should
11305 allocate larger glyph matrices. */
11307 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11309 int dy
= row
->height
- row
->visible_height
;
11312 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11314 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11316 int dy
= - (row
->height
- row
->visible_height
);
11319 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11322 /* When we change the cursor y-position of the selected window,
11323 change this_line_y as well so that the display optimization for
11324 the cursor line of the selected window in redisplay_internal uses
11325 the correct y-position. */
11326 if (w
== XWINDOW (selected_window
))
11327 this_line_y
= w
->cursor
.y
;
11329 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11330 redisplay with larger matrices. */
11331 if (matrix
->nrows
< required_matrix_height (w
))
11333 fonts_changed_p
= 1;
11342 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11343 non-zero means only WINDOW is redisplayed in redisplay_internal.
11344 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11345 in redisplay_window to bring a partially visible line into view in
11346 the case that only the cursor has moved.
11348 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11349 last screen line's vertical height extends past the end of the screen.
11353 1 if scrolling succeeded
11355 0 if scrolling didn't find point.
11357 -1 if new fonts have been loaded so that we must interrupt
11358 redisplay, adjust glyph matrices, and try again. */
11364 SCROLLING_NEED_LARGER_MATRICES
11368 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11369 scroll_step
, temp_scroll_step
, last_line_misfit
)
11370 Lisp_Object window
;
11371 int just_this_one_p
;
11372 EMACS_INT scroll_conservatively
, scroll_step
;
11373 int temp_scroll_step
;
11374 int last_line_misfit
;
11376 struct window
*w
= XWINDOW (window
);
11377 struct frame
*f
= XFRAME (w
->frame
);
11378 struct text_pos scroll_margin_pos
;
11379 struct text_pos pos
;
11380 struct text_pos startp
;
11382 Lisp_Object window_end
;
11383 int this_scroll_margin
;
11387 int amount_to_scroll
= 0;
11388 Lisp_Object aggressive
;
11390 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11393 debug_method_add (w
, "try_scrolling");
11396 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11398 /* Compute scroll margin height in pixels. We scroll when point is
11399 within this distance from the top or bottom of the window. */
11400 if (scroll_margin
> 0)
11402 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11403 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11406 this_scroll_margin
= 0;
11408 /* Force scroll_conservatively to have a reasonable value so it doesn't
11409 cause an overflow while computing how much to scroll. */
11410 if (scroll_conservatively
)
11411 scroll_conservatively
= min (scroll_conservatively
,
11412 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11414 /* Compute how much we should try to scroll maximally to bring point
11416 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11417 scroll_max
= max (scroll_step
,
11418 max (scroll_conservatively
, temp_scroll_step
));
11419 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11420 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11421 /* We're trying to scroll because of aggressive scrolling
11422 but no scroll_step is set. Choose an arbitrary one. Maybe
11423 there should be a variable for this. */
11427 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11429 /* Decide whether we have to scroll down. Start at the window end
11430 and move this_scroll_margin up to find the position of the scroll
11432 window_end
= Fwindow_end (window
, Qt
);
11436 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11437 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11439 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11441 start_display (&it
, w
, scroll_margin_pos
);
11442 if (this_scroll_margin
)
11443 move_it_vertically_backward (&it
, this_scroll_margin
);
11444 if (extra_scroll_margin_lines
)
11445 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11446 scroll_margin_pos
= it
.current
.pos
;
11449 if (PT
>= CHARPOS (scroll_margin_pos
))
11453 /* Point is in the scroll margin at the bottom of the window, or
11454 below. Compute a new window start that makes point visible. */
11456 /* Compute the distance from the scroll margin to PT.
11457 Give up if the distance is greater than scroll_max. */
11458 start_display (&it
, w
, scroll_margin_pos
);
11460 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11461 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11463 /* To make point visible, we have to move the window start
11464 down so that the line the cursor is in is visible, which
11465 means we have to add in the height of the cursor line. */
11466 dy
= line_bottom_y (&it
) - y0
;
11468 if (dy
> scroll_max
)
11469 return SCROLLING_FAILED
;
11471 /* Move the window start down. If scrolling conservatively,
11472 move it just enough down to make point visible. If
11473 scroll_step is set, move it down by scroll_step. */
11474 start_display (&it
, w
, startp
);
11476 if (scroll_conservatively
)
11477 /* Set AMOUNT_TO_SCROLL to at least one line,
11478 and at most scroll_conservatively lines. */
11480 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11481 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11482 else if (scroll_step
|| temp_scroll_step
)
11483 amount_to_scroll
= scroll_max
;
11486 aggressive
= current_buffer
->scroll_up_aggressively
;
11487 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11488 if (NUMBERP (aggressive
))
11490 double float_amount
= XFLOATINT (aggressive
) * height
;
11491 amount_to_scroll
= float_amount
;
11492 if (amount_to_scroll
== 0 && float_amount
> 0)
11493 amount_to_scroll
= 1;
11497 if (amount_to_scroll
<= 0)
11498 return SCROLLING_FAILED
;
11500 /* If moving by amount_to_scroll leaves STARTP unchanged,
11501 move it down one screen line. */
11503 move_it_vertically (&it
, amount_to_scroll
);
11504 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11505 move_it_by_lines (&it
, 1, 1);
11506 startp
= it
.current
.pos
;
11510 /* See if point is inside the scroll margin at the top of the
11512 scroll_margin_pos
= startp
;
11513 if (this_scroll_margin
)
11515 start_display (&it
, w
, startp
);
11516 move_it_vertically (&it
, this_scroll_margin
);
11517 scroll_margin_pos
= it
.current
.pos
;
11520 if (PT
< CHARPOS (scroll_margin_pos
))
11522 /* Point is in the scroll margin at the top of the window or
11523 above what is displayed in the window. */
11526 /* Compute the vertical distance from PT to the scroll
11527 margin position. Give up if distance is greater than
11529 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11530 start_display (&it
, w
, pos
);
11532 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11533 it
.last_visible_y
, -1,
11534 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11535 dy
= it
.current_y
- y0
;
11536 if (dy
> scroll_max
)
11537 return SCROLLING_FAILED
;
11539 /* Compute new window start. */
11540 start_display (&it
, w
, startp
);
11542 if (scroll_conservatively
)
11544 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11545 else if (scroll_step
|| temp_scroll_step
)
11546 amount_to_scroll
= scroll_max
;
11549 aggressive
= current_buffer
->scroll_down_aggressively
;
11550 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11551 if (NUMBERP (aggressive
))
11553 double float_amount
= XFLOATINT (aggressive
) * height
;
11554 amount_to_scroll
= float_amount
;
11555 if (amount_to_scroll
== 0 && float_amount
> 0)
11556 amount_to_scroll
= 1;
11560 if (amount_to_scroll
<= 0)
11561 return SCROLLING_FAILED
;
11563 move_it_vertically_backward (&it
, amount_to_scroll
);
11564 startp
= it
.current
.pos
;
11568 /* Run window scroll functions. */
11569 startp
= run_window_scroll_functions (window
, startp
);
11571 /* Display the window. Give up if new fonts are loaded, or if point
11573 if (!try_window (window
, startp
, 0))
11574 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11575 else if (w
->cursor
.vpos
< 0)
11577 clear_glyph_matrix (w
->desired_matrix
);
11578 rc
= SCROLLING_FAILED
;
11582 /* Maybe forget recorded base line for line number display. */
11583 if (!just_this_one_p
11584 || current_buffer
->clip_changed
11585 || BEG_UNCHANGED
< CHARPOS (startp
))
11586 w
->base_line_number
= Qnil
;
11588 /* If cursor ends up on a partially visible line,
11589 treat that as being off the bottom of the screen. */
11590 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11592 clear_glyph_matrix (w
->desired_matrix
);
11593 ++extra_scroll_margin_lines
;
11596 rc
= SCROLLING_SUCCESS
;
11603 /* Compute a suitable window start for window W if display of W starts
11604 on a continuation line. Value is non-zero if a new window start
11607 The new window start will be computed, based on W's width, starting
11608 from the start of the continued line. It is the start of the
11609 screen line with the minimum distance from the old start W->start. */
11612 compute_window_start_on_continuation_line (w
)
11615 struct text_pos pos
, start_pos
;
11616 int window_start_changed_p
= 0;
11618 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11620 /* If window start is on a continuation line... Window start may be
11621 < BEGV in case there's invisible text at the start of the
11622 buffer (M-x rmail, for example). */
11623 if (CHARPOS (start_pos
) > BEGV
11624 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11627 struct glyph_row
*row
;
11629 /* Handle the case that the window start is out of range. */
11630 if (CHARPOS (start_pos
) < BEGV
)
11631 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11632 else if (CHARPOS (start_pos
) > ZV
)
11633 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11635 /* Find the start of the continued line. This should be fast
11636 because scan_buffer is fast (newline cache). */
11637 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11638 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11639 row
, DEFAULT_FACE_ID
);
11640 reseat_at_previous_visible_line_start (&it
);
11642 /* If the line start is "too far" away from the window start,
11643 say it takes too much time to compute a new window start. */
11644 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11645 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11647 int min_distance
, distance
;
11649 /* Move forward by display lines to find the new window
11650 start. If window width was enlarged, the new start can
11651 be expected to be > the old start. If window width was
11652 decreased, the new window start will be < the old start.
11653 So, we're looking for the display line start with the
11654 minimum distance from the old window start. */
11655 pos
= it
.current
.pos
;
11656 min_distance
= INFINITY
;
11657 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11658 distance
< min_distance
)
11660 min_distance
= distance
;
11661 pos
= it
.current
.pos
;
11662 move_it_by_lines (&it
, 1, 0);
11665 /* Set the window start there. */
11666 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11667 window_start_changed_p
= 1;
11671 return window_start_changed_p
;
11675 /* Try cursor movement in case text has not changed in window WINDOW,
11676 with window start STARTP. Value is
11678 CURSOR_MOVEMENT_SUCCESS if successful
11680 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11682 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11683 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11684 we want to scroll as if scroll-step were set to 1. See the code.
11686 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11687 which case we have to abort this redisplay, and adjust matrices
11692 CURSOR_MOVEMENT_SUCCESS
,
11693 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11694 CURSOR_MOVEMENT_MUST_SCROLL
,
11695 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11699 try_cursor_movement (window
, startp
, scroll_step
)
11700 Lisp_Object window
;
11701 struct text_pos startp
;
11704 struct window
*w
= XWINDOW (window
);
11705 struct frame
*f
= XFRAME (w
->frame
);
11706 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11709 if (inhibit_try_cursor_movement
)
11713 /* Handle case where text has not changed, only point, and it has
11714 not moved off the frame. */
11715 if (/* Point may be in this window. */
11716 PT
>= CHARPOS (startp
)
11717 /* Selective display hasn't changed. */
11718 && !current_buffer
->clip_changed
11719 /* Function force-mode-line-update is used to force a thorough
11720 redisplay. It sets either windows_or_buffers_changed or
11721 update_mode_lines. So don't take a shortcut here for these
11723 && !update_mode_lines
11724 && !windows_or_buffers_changed
11725 && !cursor_type_changed
11726 /* Can't use this case if highlighting a region. When a
11727 region exists, cursor movement has to do more than just
11729 && !(!NILP (Vtransient_mark_mode
)
11730 && !NILP (current_buffer
->mark_active
))
11731 && NILP (w
->region_showing
)
11732 && NILP (Vshow_trailing_whitespace
)
11733 /* Right after splitting windows, last_point may be nil. */
11734 && INTEGERP (w
->last_point
)
11735 /* This code is not used for mini-buffer for the sake of the case
11736 of redisplaying to replace an echo area message; since in
11737 that case the mini-buffer contents per se are usually
11738 unchanged. This code is of no real use in the mini-buffer
11739 since the handling of this_line_start_pos, etc., in redisplay
11740 handles the same cases. */
11741 && !EQ (window
, minibuf_window
)
11742 /* When splitting windows or for new windows, it happens that
11743 redisplay is called with a nil window_end_vpos or one being
11744 larger than the window. This should really be fixed in
11745 window.c. I don't have this on my list, now, so we do
11746 approximately the same as the old redisplay code. --gerd. */
11747 && INTEGERP (w
->window_end_vpos
)
11748 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11749 && (FRAME_WINDOW_P (f
)
11750 || !overlay_arrow_in_current_buffer_p ()))
11752 int this_scroll_margin
, top_scroll_margin
;
11753 struct glyph_row
*row
= NULL
;
11756 debug_method_add (w
, "cursor movement");
11759 /* Scroll if point within this distance from the top or bottom
11760 of the window. This is a pixel value. */
11761 this_scroll_margin
= max (0, scroll_margin
);
11762 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11763 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11765 top_scroll_margin
= this_scroll_margin
;
11766 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11767 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11769 /* Start with the row the cursor was displayed during the last
11770 not paused redisplay. Give up if that row is not valid. */
11771 if (w
->last_cursor
.vpos
< 0
11772 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11773 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11776 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11777 if (row
->mode_line_p
)
11779 if (!row
->enabled_p
)
11780 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11783 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11786 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11788 if (PT
> XFASTINT (w
->last_point
))
11790 /* Point has moved forward. */
11791 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11792 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11794 xassert (row
->enabled_p
);
11798 /* The end position of a row equals the start position
11799 of the next row. If PT is there, we would rather
11800 display it in the next line. */
11801 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11802 && MATRIX_ROW_END_CHARPOS (row
) == PT
11803 && !cursor_row_p (w
, row
))
11806 /* If within the scroll margin, scroll. Note that
11807 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11808 the next line would be drawn, and that
11809 this_scroll_margin can be zero. */
11810 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11811 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11812 /* Line is completely visible last line in window
11813 and PT is to be set in the next line. */
11814 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11815 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11816 && !row
->ends_at_zv_p
11817 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11820 else if (PT
< XFASTINT (w
->last_point
))
11822 /* Cursor has to be moved backward. Note that PT >=
11823 CHARPOS (startp) because of the outer if-statement. */
11824 while (!row
->mode_line_p
11825 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11826 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11827 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
11828 && (row
->y
> top_scroll_margin
11829 || CHARPOS (startp
) == BEGV
))
11831 xassert (row
->enabled_p
);
11835 /* Consider the following case: Window starts at BEGV,
11836 there is invisible, intangible text at BEGV, so that
11837 display starts at some point START > BEGV. It can
11838 happen that we are called with PT somewhere between
11839 BEGV and START. Try to handle that case. */
11840 if (row
< w
->current_matrix
->rows
11841 || row
->mode_line_p
)
11843 row
= w
->current_matrix
->rows
;
11844 if (row
->mode_line_p
)
11848 /* Due to newlines in overlay strings, we may have to
11849 skip forward over overlay strings. */
11850 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11851 && MATRIX_ROW_END_CHARPOS (row
) == PT
11852 && !cursor_row_p (w
, row
))
11855 /* If within the scroll margin, scroll. */
11856 if (row
->y
< top_scroll_margin
11857 && CHARPOS (startp
) != BEGV
)
11862 /* Cursor did not move. So don't scroll even if cursor line
11863 is partially visible, as it was so before. */
11864 rc
= CURSOR_MOVEMENT_SUCCESS
;
11867 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11868 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11870 /* if PT is not in the glyph row, give up. */
11871 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11873 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
11874 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11875 && make_cursor_line_fully_visible_p
)
11877 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11878 && !row
->ends_at_zv_p
11879 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11880 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11881 else if (row
->height
> window_box_height (w
))
11883 /* If we end up in a partially visible line, let's
11884 make it fully visible, except when it's taller
11885 than the window, in which case we can't do much
11888 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11892 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11893 if (!cursor_row_fully_visible_p (w
, 0, 1))
11894 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11896 rc
= CURSOR_MOVEMENT_SUCCESS
;
11900 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11903 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11904 rc
= CURSOR_MOVEMENT_SUCCESS
;
11913 set_vertical_scroll_bar (w
)
11916 int start
, end
, whole
;
11918 /* Calculate the start and end positions for the current window.
11919 At some point, it would be nice to choose between scrollbars
11920 which reflect the whole buffer size, with special markers
11921 indicating narrowing, and scrollbars which reflect only the
11924 Note that mini-buffers sometimes aren't displaying any text. */
11925 if (!MINI_WINDOW_P (w
)
11926 || (w
== XWINDOW (minibuf_window
)
11927 && NILP (echo_area_buffer
[0])))
11929 struct buffer
*buf
= XBUFFER (w
->buffer
);
11930 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11931 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11932 /* I don't think this is guaranteed to be right. For the
11933 moment, we'll pretend it is. */
11934 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11938 if (whole
< (end
- start
))
11939 whole
= end
- start
;
11942 start
= end
= whole
= 0;
11944 /* Indicate what this scroll bar ought to be displaying now. */
11945 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11949 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11950 selected_window is redisplayed.
11952 We can return without actually redisplaying the window if
11953 fonts_changed_p is nonzero. In that case, redisplay_internal will
11957 redisplay_window (window
, just_this_one_p
)
11958 Lisp_Object window
;
11959 int just_this_one_p
;
11961 struct window
*w
= XWINDOW (window
);
11962 struct frame
*f
= XFRAME (w
->frame
);
11963 struct buffer
*buffer
= XBUFFER (w
->buffer
);
11964 struct buffer
*old
= current_buffer
;
11965 struct text_pos lpoint
, opoint
, startp
;
11966 int update_mode_line
;
11969 /* Record it now because it's overwritten. */
11970 int current_matrix_up_to_date_p
= 0;
11971 int used_current_matrix_p
= 0;
11972 /* This is less strict than current_matrix_up_to_date_p.
11973 It indictes that the buffer contents and narrowing are unchanged. */
11974 int buffer_unchanged_p
= 0;
11975 int temp_scroll_step
= 0;
11976 int count
= SPECPDL_INDEX ();
11978 int centering_position
= -1;
11979 int last_line_misfit
= 0;
11981 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
11984 /* W must be a leaf window here. */
11985 xassert (!NILP (w
->buffer
));
11987 *w
->desired_matrix
->method
= 0;
11990 specbind (Qinhibit_point_motion_hooks
, Qt
);
11992 reconsider_clip_changes (w
, buffer
);
11994 /* Has the mode line to be updated? */
11995 update_mode_line
= (!NILP (w
->update_mode_line
)
11996 || update_mode_lines
11997 || buffer
->clip_changed
11998 || buffer
->prevent_redisplay_optimizations_p
);
12000 if (MINI_WINDOW_P (w
))
12002 if (w
== XWINDOW (echo_area_window
)
12003 && !NILP (echo_area_buffer
[0]))
12005 if (update_mode_line
)
12006 /* We may have to update a tty frame's menu bar or a
12007 tool-bar. Example `M-x C-h C-h C-g'. */
12008 goto finish_menu_bars
;
12010 /* We've already displayed the echo area glyphs in this window. */
12011 goto finish_scroll_bars
;
12013 else if ((w
!= XWINDOW (minibuf_window
)
12014 || minibuf_level
== 0)
12015 /* When buffer is nonempty, redisplay window normally. */
12016 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12017 /* Quail displays non-mini buffers in minibuffer window.
12018 In that case, redisplay the window normally. */
12019 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12021 /* W is a mini-buffer window, but it's not active, so clear
12023 int yb
= window_text_bottom_y (w
);
12024 struct glyph_row
*row
;
12027 for (y
= 0, row
= w
->desired_matrix
->rows
;
12029 y
+= row
->height
, ++row
)
12030 blank_row (w
, row
, y
);
12031 goto finish_scroll_bars
;
12034 clear_glyph_matrix (w
->desired_matrix
);
12037 /* Otherwise set up data on this window; select its buffer and point
12039 /* Really select the buffer, for the sake of buffer-local
12041 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12042 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12044 current_matrix_up_to_date_p
12045 = (!NILP (w
->window_end_valid
)
12046 && !current_buffer
->clip_changed
12047 && !current_buffer
->prevent_redisplay_optimizations_p
12048 && XFASTINT (w
->last_modified
) >= MODIFF
12049 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12052 = (!NILP (w
->window_end_valid
)
12053 && !current_buffer
->clip_changed
12054 && XFASTINT (w
->last_modified
) >= MODIFF
12055 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12057 /* When windows_or_buffers_changed is non-zero, we can't rely on
12058 the window end being valid, so set it to nil there. */
12059 if (windows_or_buffers_changed
)
12061 /* If window starts on a continuation line, maybe adjust the
12062 window start in case the window's width changed. */
12063 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12064 compute_window_start_on_continuation_line (w
);
12066 w
->window_end_valid
= Qnil
;
12069 /* Some sanity checks. */
12070 CHECK_WINDOW_END (w
);
12071 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12073 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12076 /* If %c is in mode line, update it if needed. */
12077 if (!NILP (w
->column_number_displayed
)
12078 /* This alternative quickly identifies a common case
12079 where no change is needed. */
12080 && !(PT
== XFASTINT (w
->last_point
)
12081 && XFASTINT (w
->last_modified
) >= MODIFF
12082 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12083 && (XFASTINT (w
->column_number_displayed
)
12084 != (int) current_column ())) /* iftc */
12085 update_mode_line
= 1;
12087 /* Count number of windows showing the selected buffer. An indirect
12088 buffer counts as its base buffer. */
12089 if (!just_this_one_p
)
12091 struct buffer
*current_base
, *window_base
;
12092 current_base
= current_buffer
;
12093 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12094 if (current_base
->base_buffer
)
12095 current_base
= current_base
->base_buffer
;
12096 if (window_base
->base_buffer
)
12097 window_base
= window_base
->base_buffer
;
12098 if (current_base
== window_base
)
12102 /* Point refers normally to the selected window. For any other
12103 window, set up appropriate value. */
12104 if (!EQ (window
, selected_window
))
12106 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12107 int new_pt_byte
= marker_byte_position (w
->pointm
);
12111 new_pt_byte
= BEGV_BYTE
;
12112 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12114 else if (new_pt
> (ZV
- 1))
12117 new_pt_byte
= ZV_BYTE
;
12118 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12121 /* We don't use SET_PT so that the point-motion hooks don't run. */
12122 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12125 /* If any of the character widths specified in the display table
12126 have changed, invalidate the width run cache. It's true that
12127 this may be a bit late to catch such changes, but the rest of
12128 redisplay goes (non-fatally) haywire when the display table is
12129 changed, so why should we worry about doing any better? */
12130 if (current_buffer
->width_run_cache
)
12132 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12134 if (! disptab_matches_widthtab (disptab
,
12135 XVECTOR (current_buffer
->width_table
)))
12137 invalidate_region_cache (current_buffer
,
12138 current_buffer
->width_run_cache
,
12140 recompute_width_table (current_buffer
, disptab
);
12144 /* If window-start is screwed up, choose a new one. */
12145 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12148 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12150 /* If someone specified a new starting point but did not insist,
12151 check whether it can be used. */
12152 if (!NILP (w
->optional_new_start
)
12153 && CHARPOS (startp
) >= BEGV
12154 && CHARPOS (startp
) <= ZV
)
12156 w
->optional_new_start
= Qnil
;
12157 start_display (&it
, w
, startp
);
12158 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12159 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12160 if (IT_CHARPOS (it
) == PT
)
12161 w
->force_start
= Qt
;
12162 /* IT may overshoot PT if text at PT is invisible. */
12163 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12164 w
->force_start
= Qt
;
12169 /* Handle case where place to start displaying has been specified,
12170 unless the specified location is outside the accessible range. */
12171 if (!NILP (w
->force_start
)
12172 || w
->frozen_window_start_p
)
12174 /* We set this later on if we have to adjust point. */
12178 w
->force_start
= Qnil
;
12180 w
->window_end_valid
= Qnil
;
12182 /* Forget any recorded base line for line number display. */
12183 if (!buffer_unchanged_p
)
12184 w
->base_line_number
= Qnil
;
12186 /* Redisplay the mode line. Select the buffer properly for that.
12187 Also, run the hook window-scroll-functions
12188 because we have scrolled. */
12189 /* Note, we do this after clearing force_start because
12190 if there's an error, it is better to forget about force_start
12191 than to get into an infinite loop calling the hook functions
12192 and having them get more errors. */
12193 if (!update_mode_line
12194 || ! NILP (Vwindow_scroll_functions
))
12196 update_mode_line
= 1;
12197 w
->update_mode_line
= Qt
;
12198 startp
= run_window_scroll_functions (window
, startp
);
12201 w
->last_modified
= make_number (0);
12202 w
->last_overlay_modified
= make_number (0);
12203 if (CHARPOS (startp
) < BEGV
)
12204 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12205 else if (CHARPOS (startp
) > ZV
)
12206 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12208 /* Redisplay, then check if cursor has been set during the
12209 redisplay. Give up if new fonts were loaded. */
12210 val
= try_window (window
, startp
, 1);
12213 w
->force_start
= Qt
;
12214 clear_glyph_matrix (w
->desired_matrix
);
12215 goto need_larger_matrices
;
12217 /* Point was outside the scroll margins. */
12219 new_vpos
= window_box_height (w
) / 2;
12221 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12223 /* If point does not appear, try to move point so it does
12224 appear. The desired matrix has been built above, so we
12225 can use it here. */
12226 new_vpos
= window_box_height (w
) / 2;
12229 if (!cursor_row_fully_visible_p (w
, 0, 0))
12231 /* Point does appear, but on a line partly visible at end of window.
12232 Move it back to a fully-visible line. */
12233 new_vpos
= window_box_height (w
);
12236 /* If we need to move point for either of the above reasons,
12237 now actually do it. */
12240 struct glyph_row
*row
;
12242 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12243 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12246 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12247 MATRIX_ROW_START_BYTEPOS (row
));
12249 if (w
!= XWINDOW (selected_window
))
12250 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12251 else if (current_buffer
== old
)
12252 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12254 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12256 /* If we are highlighting the region, then we just changed
12257 the region, so redisplay to show it. */
12258 if (!NILP (Vtransient_mark_mode
)
12259 && !NILP (current_buffer
->mark_active
))
12261 clear_glyph_matrix (w
->desired_matrix
);
12262 if (!try_window (window
, startp
, 0))
12263 goto need_larger_matrices
;
12268 debug_method_add (w
, "forced window start");
12273 /* Handle case where text has not changed, only point, and it has
12274 not moved off the frame, and we are not retrying after hscroll.
12275 (current_matrix_up_to_date_p is nonzero when retrying.) */
12276 if (current_matrix_up_to_date_p
12277 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12278 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12282 case CURSOR_MOVEMENT_SUCCESS
:
12283 used_current_matrix_p
= 1;
12286 #if 0 /* try_cursor_movement never returns this value. */
12287 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12288 goto need_larger_matrices
;
12291 case CURSOR_MOVEMENT_MUST_SCROLL
:
12292 goto try_to_scroll
;
12298 /* If current starting point was originally the beginning of a line
12299 but no longer is, find a new starting point. */
12300 else if (!NILP (w
->start_at_line_beg
)
12301 && !(CHARPOS (startp
) <= BEGV
12302 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12305 debug_method_add (w
, "recenter 1");
12310 /* Try scrolling with try_window_id. Value is > 0 if update has
12311 been done, it is -1 if we know that the same window start will
12312 not work. It is 0 if unsuccessful for some other reason. */
12313 else if ((tem
= try_window_id (w
)) != 0)
12316 debug_method_add (w
, "try_window_id %d", tem
);
12319 if (fonts_changed_p
)
12320 goto need_larger_matrices
;
12324 /* Otherwise try_window_id has returned -1 which means that we
12325 don't want the alternative below this comment to execute. */
12327 else if (CHARPOS (startp
) >= BEGV
12328 && CHARPOS (startp
) <= ZV
12329 && PT
>= CHARPOS (startp
)
12330 && (CHARPOS (startp
) < ZV
12331 /* Avoid starting at end of buffer. */
12332 || CHARPOS (startp
) == BEGV
12333 || (XFASTINT (w
->last_modified
) >= MODIFF
12334 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12337 debug_method_add (w
, "same window start");
12340 /* Try to redisplay starting at same place as before.
12341 If point has not moved off frame, accept the results. */
12342 if (!current_matrix_up_to_date_p
12343 /* Don't use try_window_reusing_current_matrix in this case
12344 because a window scroll function can have changed the
12346 || !NILP (Vwindow_scroll_functions
)
12347 || MINI_WINDOW_P (w
)
12348 || !(used_current_matrix_p
12349 = try_window_reusing_current_matrix (w
)))
12351 IF_DEBUG (debug_method_add (w
, "1"));
12352 if (try_window (window
, startp
, 1) < 0)
12353 /* -1 means we need to scroll.
12354 0 means we need new matrices, but fonts_changed_p
12355 is set in that case, so we will detect it below. */
12356 goto try_to_scroll
;
12359 if (fonts_changed_p
)
12360 goto need_larger_matrices
;
12362 if (w
->cursor
.vpos
>= 0)
12364 if (!just_this_one_p
12365 || current_buffer
->clip_changed
12366 || BEG_UNCHANGED
< CHARPOS (startp
))
12367 /* Forget any recorded base line for line number display. */
12368 w
->base_line_number
= Qnil
;
12370 if (!cursor_row_fully_visible_p (w
, 1, 0))
12372 clear_glyph_matrix (w
->desired_matrix
);
12373 last_line_misfit
= 1;
12375 /* Drop through and scroll. */
12380 clear_glyph_matrix (w
->desired_matrix
);
12385 w
->last_modified
= make_number (0);
12386 w
->last_overlay_modified
= make_number (0);
12388 /* Redisplay the mode line. Select the buffer properly for that. */
12389 if (!update_mode_line
)
12391 update_mode_line
= 1;
12392 w
->update_mode_line
= Qt
;
12395 /* Try to scroll by specified few lines. */
12396 if ((scroll_conservatively
12398 || temp_scroll_step
12399 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12400 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12401 && !current_buffer
->clip_changed
12402 && CHARPOS (startp
) >= BEGV
12403 && CHARPOS (startp
) <= ZV
)
12405 /* The function returns -1 if new fonts were loaded, 1 if
12406 successful, 0 if not successful. */
12407 int rc
= try_scrolling (window
, just_this_one_p
,
12408 scroll_conservatively
,
12410 temp_scroll_step
, last_line_misfit
);
12413 case SCROLLING_SUCCESS
:
12416 case SCROLLING_NEED_LARGER_MATRICES
:
12417 goto need_larger_matrices
;
12419 case SCROLLING_FAILED
:
12427 /* Finally, just choose place to start which centers point */
12430 if (centering_position
< 0)
12431 centering_position
= window_box_height (w
) / 2;
12434 debug_method_add (w
, "recenter");
12437 /* w->vscroll = 0; */
12439 /* Forget any previously recorded base line for line number display. */
12440 if (!buffer_unchanged_p
)
12441 w
->base_line_number
= Qnil
;
12443 /* Move backward half the height of the window. */
12444 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12445 it
.current_y
= it
.last_visible_y
;
12446 move_it_vertically_backward (&it
, centering_position
);
12447 xassert (IT_CHARPOS (it
) >= BEGV
);
12449 /* The function move_it_vertically_backward may move over more
12450 than the specified y-distance. If it->w is small, e.g. a
12451 mini-buffer window, we may end up in front of the window's
12452 display area. Start displaying at the start of the line
12453 containing PT in this case. */
12454 if (it
.current_y
<= 0)
12456 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12457 move_it_vertically_backward (&it
, 0);
12459 /* I think this assert is bogus if buffer contains
12460 invisible text or images. KFS. */
12461 xassert (IT_CHARPOS (it
) <= PT
);
12466 it
.current_x
= it
.hpos
= 0;
12468 /* Set startp here explicitly in case that helps avoid an infinite loop
12469 in case the window-scroll-functions functions get errors. */
12470 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12472 /* Run scroll hooks. */
12473 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12475 /* Redisplay the window. */
12476 if (!current_matrix_up_to_date_p
12477 || windows_or_buffers_changed
12478 || cursor_type_changed
12479 /* Don't use try_window_reusing_current_matrix in this case
12480 because it can have changed the buffer. */
12481 || !NILP (Vwindow_scroll_functions
)
12482 || !just_this_one_p
12483 || MINI_WINDOW_P (w
)
12484 || !(used_current_matrix_p
12485 = try_window_reusing_current_matrix (w
)))
12486 try_window (window
, startp
, 0);
12488 /* If new fonts have been loaded (due to fontsets), give up. We
12489 have to start a new redisplay since we need to re-adjust glyph
12491 if (fonts_changed_p
)
12492 goto need_larger_matrices
;
12494 /* If cursor did not appear assume that the middle of the window is
12495 in the first line of the window. Do it again with the next line.
12496 (Imagine a window of height 100, displaying two lines of height
12497 60. Moving back 50 from it->last_visible_y will end in the first
12499 if (w
->cursor
.vpos
< 0)
12501 if (!NILP (w
->window_end_valid
)
12502 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12504 clear_glyph_matrix (w
->desired_matrix
);
12505 move_it_by_lines (&it
, 1, 0);
12506 try_window (window
, it
.current
.pos
, 0);
12508 else if (PT
< IT_CHARPOS (it
))
12510 clear_glyph_matrix (w
->desired_matrix
);
12511 move_it_by_lines (&it
, -1, 0);
12512 try_window (window
, it
.current
.pos
, 0);
12516 /* Not much we can do about it. */
12520 /* Consider the following case: Window starts at BEGV, there is
12521 invisible, intangible text at BEGV, so that display starts at
12522 some point START > BEGV. It can happen that we are called with
12523 PT somewhere between BEGV and START. Try to handle that case. */
12524 if (w
->cursor
.vpos
< 0)
12526 struct glyph_row
*row
= w
->current_matrix
->rows
;
12527 if (row
->mode_line_p
)
12529 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12532 if (!cursor_row_fully_visible_p (w
, 0, 0))
12534 /* If vscroll is enabled, disable it and try again. */
12538 clear_glyph_matrix (w
->desired_matrix
);
12542 /* If centering point failed to make the whole line visible,
12543 put point at the top instead. That has to make the whole line
12544 visible, if it can be done. */
12545 if (centering_position
== 0)
12548 clear_glyph_matrix (w
->desired_matrix
);
12549 centering_position
= 0;
12555 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12556 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12557 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12560 /* Display the mode line, if we must. */
12561 if ((update_mode_line
12562 /* If window not full width, must redo its mode line
12563 if (a) the window to its side is being redone and
12564 (b) we do a frame-based redisplay. This is a consequence
12565 of how inverted lines are drawn in frame-based redisplay. */
12566 || (!just_this_one_p
12567 && !FRAME_WINDOW_P (f
)
12568 && !WINDOW_FULL_WIDTH_P (w
))
12569 /* Line number to display. */
12570 || INTEGERP (w
->base_line_pos
)
12571 /* Column number is displayed and different from the one displayed. */
12572 || (!NILP (w
->column_number_displayed
)
12573 && (XFASTINT (w
->column_number_displayed
)
12574 != (int) current_column ()))) /* iftc */
12575 /* This means that the window has a mode line. */
12576 && (WINDOW_WANTS_MODELINE_P (w
)
12577 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12579 display_mode_lines (w
);
12581 /* If mode line height has changed, arrange for a thorough
12582 immediate redisplay using the correct mode line height. */
12583 if (WINDOW_WANTS_MODELINE_P (w
)
12584 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12586 fonts_changed_p
= 1;
12587 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12588 = DESIRED_MODE_LINE_HEIGHT (w
);
12591 /* If top line height has changed, arrange for a thorough
12592 immediate redisplay using the correct mode line height. */
12593 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12594 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12596 fonts_changed_p
= 1;
12597 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12598 = DESIRED_HEADER_LINE_HEIGHT (w
);
12601 if (fonts_changed_p
)
12602 goto need_larger_matrices
;
12605 if (!line_number_displayed
12606 && !BUFFERP (w
->base_line_pos
))
12608 w
->base_line_pos
= Qnil
;
12609 w
->base_line_number
= Qnil
;
12614 /* When we reach a frame's selected window, redo the frame's menu bar. */
12615 if (update_mode_line
12616 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12618 int redisplay_menu_p
= 0;
12619 int redisplay_tool_bar_p
= 0;
12621 if (FRAME_WINDOW_P (f
))
12623 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12624 || defined (USE_GTK)
12625 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12627 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12631 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12633 if (redisplay_menu_p
)
12634 display_menu_bar (w
);
12636 #ifdef HAVE_WINDOW_SYSTEM
12638 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12640 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12641 && (FRAME_TOOL_BAR_LINES (f
) > 0
12642 || auto_resize_tool_bars_p
);
12646 if (redisplay_tool_bar_p
)
12647 redisplay_tool_bar (f
);
12651 #ifdef HAVE_WINDOW_SYSTEM
12652 if (FRAME_WINDOW_P (f
)
12653 && update_window_fringes (w
, 0)
12654 && !just_this_one_p
12655 && (used_current_matrix_p
|| overlay_arrow_seen
)
12656 && !w
->pseudo_window_p
)
12660 if (draw_window_fringes (w
, 1))
12661 x_draw_vertical_border (w
);
12665 #endif /* HAVE_WINDOW_SYSTEM */
12667 /* We go to this label, with fonts_changed_p nonzero,
12668 if it is necessary to try again using larger glyph matrices.
12669 We have to redeem the scroll bar even in this case,
12670 because the loop in redisplay_internal expects that. */
12671 need_larger_matrices
:
12673 finish_scroll_bars
:
12675 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12677 /* Set the thumb's position and size. */
12678 set_vertical_scroll_bar (w
);
12680 /* Note that we actually used the scroll bar attached to this
12681 window, so it shouldn't be deleted at the end of redisplay. */
12682 redeem_scroll_bar_hook (w
);
12685 /* Restore current_buffer and value of point in it. */
12686 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12687 set_buffer_internal_1 (old
);
12688 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12690 unbind_to (count
, Qnil
);
12694 /* Build the complete desired matrix of WINDOW with a window start
12695 buffer position POS.
12697 Value is 1 if successful. It is zero if fonts were loaded during
12698 redisplay which makes re-adjusting glyph matrices necessary, and -1
12699 if point would appear in the scroll margins.
12700 (We check that only if CHECK_MARGINS is nonzero. */
12703 try_window (window
, pos
, check_margins
)
12704 Lisp_Object window
;
12705 struct text_pos pos
;
12708 struct window
*w
= XWINDOW (window
);
12710 struct glyph_row
*last_text_row
= NULL
;
12712 /* Make POS the new window start. */
12713 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12715 /* Mark cursor position as unknown. No overlay arrow seen. */
12716 w
->cursor
.vpos
= -1;
12717 overlay_arrow_seen
= 0;
12719 /* Initialize iterator and info to start at POS. */
12720 start_display (&it
, w
, pos
);
12722 /* Display all lines of W. */
12723 while (it
.current_y
< it
.last_visible_y
)
12725 if (display_line (&it
))
12726 last_text_row
= it
.glyph_row
- 1;
12727 if (fonts_changed_p
)
12731 /* Don't let the cursor end in the scroll margins. */
12734 int this_scroll_margin
, cursor_height
;
12736 this_scroll_margin
= max (0, scroll_margin
);
12737 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12738 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
12739 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
12741 if ((w
->cursor
.y
< this_scroll_margin
12742 && CHARPOS (pos
) > BEGV
)
12743 /* rms: considering make_cursor_line_fully_visible_p here
12744 seems to give wrong results. We don't want to recenter
12745 when the last line is partly visible, we want to allow
12746 that case to be handled in the usual way. */
12747 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
12749 w
->cursor
.vpos
= -1;
12750 clear_glyph_matrix (w
->desired_matrix
);
12755 /* If bottom moved off end of frame, change mode line percentage. */
12756 if (XFASTINT (w
->window_end_pos
) <= 0
12757 && Z
!= IT_CHARPOS (it
))
12758 w
->update_mode_line
= Qt
;
12760 /* Set window_end_pos to the offset of the last character displayed
12761 on the window from the end of current_buffer. Set
12762 window_end_vpos to its row number. */
12765 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12766 w
->window_end_bytepos
12767 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12769 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12771 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12772 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12773 ->displays_text_p
);
12777 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12778 w
->window_end_pos
= make_number (Z
- ZV
);
12779 w
->window_end_vpos
= make_number (0);
12782 /* But that is not valid info until redisplay finishes. */
12783 w
->window_end_valid
= Qnil
;
12789 /************************************************************************
12790 Window redisplay reusing current matrix when buffer has not changed
12791 ************************************************************************/
12793 /* Try redisplay of window W showing an unchanged buffer with a
12794 different window start than the last time it was displayed by
12795 reusing its current matrix. Value is non-zero if successful.
12796 W->start is the new window start. */
12799 try_window_reusing_current_matrix (w
)
12802 struct frame
*f
= XFRAME (w
->frame
);
12803 struct glyph_row
*row
, *bottom_row
;
12806 struct text_pos start
, new_start
;
12807 int nrows_scrolled
, i
;
12808 struct glyph_row
*last_text_row
;
12809 struct glyph_row
*last_reused_text_row
;
12810 struct glyph_row
*start_row
;
12811 int start_vpos
, min_y
, max_y
;
12814 if (inhibit_try_window_reusing
)
12818 if (/* This function doesn't handle terminal frames. */
12819 !FRAME_WINDOW_P (f
)
12820 /* Don't try to reuse the display if windows have been split
12822 || windows_or_buffers_changed
12823 || cursor_type_changed
)
12826 /* Can't do this if region may have changed. */
12827 if ((!NILP (Vtransient_mark_mode
)
12828 && !NILP (current_buffer
->mark_active
))
12829 || !NILP (w
->region_showing
)
12830 || !NILP (Vshow_trailing_whitespace
))
12833 /* If top-line visibility has changed, give up. */
12834 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12835 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12838 /* Give up if old or new display is scrolled vertically. We could
12839 make this function handle this, but right now it doesn't. */
12840 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12841 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12844 /* The variable new_start now holds the new window start. The old
12845 start `start' can be determined from the current matrix. */
12846 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12847 start
= start_row
->start
.pos
;
12848 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12850 /* Clear the desired matrix for the display below. */
12851 clear_glyph_matrix (w
->desired_matrix
);
12853 if (CHARPOS (new_start
) <= CHARPOS (start
))
12857 /* Don't use this method if the display starts with an ellipsis
12858 displayed for invisible text. It's not easy to handle that case
12859 below, and it's certainly not worth the effort since this is
12860 not a frequent case. */
12861 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12864 IF_DEBUG (debug_method_add (w
, "twu1"));
12866 /* Display up to a row that can be reused. The variable
12867 last_text_row is set to the last row displayed that displays
12868 text. Note that it.vpos == 0 if or if not there is a
12869 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12870 start_display (&it
, w
, new_start
);
12871 first_row_y
= it
.current_y
;
12872 w
->cursor
.vpos
= -1;
12873 last_text_row
= last_reused_text_row
= NULL
;
12875 while (it
.current_y
< it
.last_visible_y
12876 && !fonts_changed_p
)
12878 /* If we have reached into the characters in the START row,
12879 that means the line boundaries have changed. So we
12880 can't start copying with the row START. Maybe it will
12881 work to start copying with the following row. */
12882 while (IT_CHARPOS (it
) > CHARPOS (start
))
12884 /* Advance to the next row as the "start". */
12886 start
= start_row
->start
.pos
;
12887 /* If there are no more rows to try, or just one, give up. */
12888 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12889 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12890 || CHARPOS (start
) == ZV
)
12892 clear_glyph_matrix (w
->desired_matrix
);
12896 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12898 /* If we have reached alignment,
12899 we can copy the rest of the rows. */
12900 if (IT_CHARPOS (it
) == CHARPOS (start
))
12903 if (display_line (&it
))
12904 last_text_row
= it
.glyph_row
- 1;
12907 /* A value of current_y < last_visible_y means that we stopped
12908 at the previous window start, which in turn means that we
12909 have at least one reusable row. */
12910 if (it
.current_y
< it
.last_visible_y
)
12912 /* IT.vpos always starts from 0; it counts text lines. */
12913 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12915 /* Find PT if not already found in the lines displayed. */
12916 if (w
->cursor
.vpos
< 0)
12918 int dy
= it
.current_y
- start_row
->y
;
12920 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12921 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12923 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12924 dy
, nrows_scrolled
);
12927 clear_glyph_matrix (w
->desired_matrix
);
12932 /* Scroll the display. Do it before the current matrix is
12933 changed. The problem here is that update has not yet
12934 run, i.e. part of the current matrix is not up to date.
12935 scroll_run_hook will clear the cursor, and use the
12936 current matrix to get the height of the row the cursor is
12938 run
.current_y
= start_row
->y
;
12939 run
.desired_y
= it
.current_y
;
12940 run
.height
= it
.last_visible_y
- it
.current_y
;
12942 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12945 rif
->update_window_begin_hook (w
);
12946 rif
->clear_window_mouse_face (w
);
12947 rif
->scroll_run_hook (w
, &run
);
12948 rif
->update_window_end_hook (w
, 0, 0);
12952 /* Shift current matrix down by nrows_scrolled lines. */
12953 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12954 rotate_matrix (w
->current_matrix
,
12956 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
12959 /* Disable lines that must be updated. */
12960 for (i
= 0; i
< it
.vpos
; ++i
)
12961 (start_row
+ i
)->enabled_p
= 0;
12963 /* Re-compute Y positions. */
12964 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
12965 max_y
= it
.last_visible_y
;
12966 for (row
= start_row
+ nrows_scrolled
;
12970 row
->y
= it
.current_y
;
12971 row
->visible_height
= row
->height
;
12973 if (row
->y
< min_y
)
12974 row
->visible_height
-= min_y
- row
->y
;
12975 if (row
->y
+ row
->height
> max_y
)
12976 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
12977 row
->redraw_fringe_bitmaps_p
= 1;
12979 it
.current_y
+= row
->height
;
12981 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12982 last_reused_text_row
= row
;
12983 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
12987 /* Disable lines in the current matrix which are now
12988 below the window. */
12989 for (++row
; row
< bottom_row
; ++row
)
12990 row
->enabled_p
= 0;
12993 /* Update window_end_pos etc.; last_reused_text_row is the last
12994 reused row from the current matrix containing text, if any.
12995 The value of last_text_row is the last displayed line
12996 containing text. */
12997 if (last_reused_text_row
)
12999 w
->window_end_bytepos
13000 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13002 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13004 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13005 w
->current_matrix
));
13007 else if (last_text_row
)
13009 w
->window_end_bytepos
13010 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13012 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13014 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13018 /* This window must be completely empty. */
13019 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13020 w
->window_end_pos
= make_number (Z
- ZV
);
13021 w
->window_end_vpos
= make_number (0);
13023 w
->window_end_valid
= Qnil
;
13025 /* Update hint: don't try scrolling again in update_window. */
13026 w
->desired_matrix
->no_scrolling_p
= 1;
13029 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13033 else if (CHARPOS (new_start
) > CHARPOS (start
))
13035 struct glyph_row
*pt_row
, *row
;
13036 struct glyph_row
*first_reusable_row
;
13037 struct glyph_row
*first_row_to_display
;
13039 int yb
= window_text_bottom_y (w
);
13041 /* Find the row starting at new_start, if there is one. Don't
13042 reuse a partially visible line at the end. */
13043 first_reusable_row
= start_row
;
13044 while (first_reusable_row
->enabled_p
13045 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13046 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13047 < CHARPOS (new_start
)))
13048 ++first_reusable_row
;
13050 /* Give up if there is no row to reuse. */
13051 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13052 || !first_reusable_row
->enabled_p
13053 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13054 != CHARPOS (new_start
)))
13057 /* We can reuse fully visible rows beginning with
13058 first_reusable_row to the end of the window. Set
13059 first_row_to_display to the first row that cannot be reused.
13060 Set pt_row to the row containing point, if there is any. */
13062 for (first_row_to_display
= first_reusable_row
;
13063 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13064 ++first_row_to_display
)
13066 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13067 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13068 pt_row
= first_row_to_display
;
13071 /* Start displaying at the start of first_row_to_display. */
13072 xassert (first_row_to_display
->y
< yb
);
13073 init_to_row_start (&it
, w
, first_row_to_display
);
13075 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13077 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13079 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13080 + WINDOW_HEADER_LINE_HEIGHT (w
));
13082 /* Display lines beginning with first_row_to_display in the
13083 desired matrix. Set last_text_row to the last row displayed
13084 that displays text. */
13085 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13086 if (pt_row
== NULL
)
13087 w
->cursor
.vpos
= -1;
13088 last_text_row
= NULL
;
13089 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13090 if (display_line (&it
))
13091 last_text_row
= it
.glyph_row
- 1;
13093 /* Give up If point isn't in a row displayed or reused. */
13094 if (w
->cursor
.vpos
< 0)
13096 clear_glyph_matrix (w
->desired_matrix
);
13100 /* If point is in a reused row, adjust y and vpos of the cursor
13104 w
->cursor
.vpos
-= nrows_scrolled
;
13105 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13108 /* Scroll the display. */
13109 run
.current_y
= first_reusable_row
->y
;
13110 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13111 run
.height
= it
.last_visible_y
- run
.current_y
;
13112 dy
= run
.current_y
- run
.desired_y
;
13117 rif
->update_window_begin_hook (w
);
13118 rif
->clear_window_mouse_face (w
);
13119 rif
->scroll_run_hook (w
, &run
);
13120 rif
->update_window_end_hook (w
, 0, 0);
13124 /* Adjust Y positions of reused rows. */
13125 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13126 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13127 max_y
= it
.last_visible_y
;
13128 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13131 row
->visible_height
= row
->height
;
13132 if (row
->y
< min_y
)
13133 row
->visible_height
-= min_y
- row
->y
;
13134 if (row
->y
+ row
->height
> max_y
)
13135 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13136 row
->redraw_fringe_bitmaps_p
= 1;
13139 /* Scroll the current matrix. */
13140 xassert (nrows_scrolled
> 0);
13141 rotate_matrix (w
->current_matrix
,
13143 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13146 /* Disable rows not reused. */
13147 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13148 row
->enabled_p
= 0;
13150 /* Point may have moved to a different line, so we cannot assume that
13151 the previous cursor position is valid; locate the correct row. */
13154 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13155 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13159 w
->cursor
.y
= row
->y
;
13161 if (row
< bottom_row
)
13163 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13164 while (glyph
->charpos
< PT
)
13167 w
->cursor
.x
+= glyph
->pixel_width
;
13173 /* Adjust window end. A null value of last_text_row means that
13174 the window end is in reused rows which in turn means that
13175 only its vpos can have changed. */
13178 w
->window_end_bytepos
13179 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13181 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13183 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13188 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13191 w
->window_end_valid
= Qnil
;
13192 w
->desired_matrix
->no_scrolling_p
= 1;
13195 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13205 /************************************************************************
13206 Window redisplay reusing current matrix when buffer has changed
13207 ************************************************************************/
13209 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13210 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13212 static struct glyph_row
*
13213 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13214 struct glyph_row
*));
13217 /* Return the last row in MATRIX displaying text. If row START is
13218 non-null, start searching with that row. IT gives the dimensions
13219 of the display. Value is null if matrix is empty; otherwise it is
13220 a pointer to the row found. */
13222 static struct glyph_row
*
13223 find_last_row_displaying_text (matrix
, it
, start
)
13224 struct glyph_matrix
*matrix
;
13226 struct glyph_row
*start
;
13228 struct glyph_row
*row
, *row_found
;
13230 /* Set row_found to the last row in IT->w's current matrix
13231 displaying text. The loop looks funny but think of partially
13234 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13235 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13237 xassert (row
->enabled_p
);
13239 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13248 /* Return the last row in the current matrix of W that is not affected
13249 by changes at the start of current_buffer that occurred since W's
13250 current matrix was built. Value is null if no such row exists.
13252 BEG_UNCHANGED us the number of characters unchanged at the start of
13253 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13254 first changed character in current_buffer. Characters at positions <
13255 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13256 when the current matrix was built. */
13258 static struct glyph_row
*
13259 find_last_unchanged_at_beg_row (w
)
13262 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13263 struct glyph_row
*row
;
13264 struct glyph_row
*row_found
= NULL
;
13265 int yb
= window_text_bottom_y (w
);
13267 /* Find the last row displaying unchanged text. */
13268 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13269 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13270 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13272 if (/* If row ends before first_changed_pos, it is unchanged,
13273 except in some case. */
13274 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13275 /* When row ends in ZV and we write at ZV it is not
13277 && !row
->ends_at_zv_p
13278 /* When first_changed_pos is the end of a continued line,
13279 row is not unchanged because it may be no longer
13281 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13282 && (row
->continued_p
13283 || row
->exact_window_width_line_p
)))
13286 /* Stop if last visible row. */
13287 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13297 /* Find the first glyph row in the current matrix of W that is not
13298 affected by changes at the end of current_buffer since the
13299 time W's current matrix was built.
13301 Return in *DELTA the number of chars by which buffer positions in
13302 unchanged text at the end of current_buffer must be adjusted.
13304 Return in *DELTA_BYTES the corresponding number of bytes.
13306 Value is null if no such row exists, i.e. all rows are affected by
13309 static struct glyph_row
*
13310 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13312 int *delta
, *delta_bytes
;
13314 struct glyph_row
*row
;
13315 struct glyph_row
*row_found
= NULL
;
13317 *delta
= *delta_bytes
= 0;
13319 /* Display must not have been paused, otherwise the current matrix
13320 is not up to date. */
13321 if (NILP (w
->window_end_valid
))
13324 /* A value of window_end_pos >= END_UNCHANGED means that the window
13325 end is in the range of changed text. If so, there is no
13326 unchanged row at the end of W's current matrix. */
13327 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13330 /* Set row to the last row in W's current matrix displaying text. */
13331 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13333 /* If matrix is entirely empty, no unchanged row exists. */
13334 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13336 /* The value of row is the last glyph row in the matrix having a
13337 meaningful buffer position in it. The end position of row
13338 corresponds to window_end_pos. This allows us to translate
13339 buffer positions in the current matrix to current buffer
13340 positions for characters not in changed text. */
13341 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13342 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13343 int last_unchanged_pos
, last_unchanged_pos_old
;
13344 struct glyph_row
*first_text_row
13345 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13347 *delta
= Z
- Z_old
;
13348 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13350 /* Set last_unchanged_pos to the buffer position of the last
13351 character in the buffer that has not been changed. Z is the
13352 index + 1 of the last character in current_buffer, i.e. by
13353 subtracting END_UNCHANGED we get the index of the last
13354 unchanged character, and we have to add BEG to get its buffer
13356 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13357 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13359 /* Search backward from ROW for a row displaying a line that
13360 starts at a minimum position >= last_unchanged_pos_old. */
13361 for (; row
> first_text_row
; --row
)
13363 /* This used to abort, but it can happen.
13364 It is ok to just stop the search instead here. KFS. */
13365 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13368 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13373 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13380 /* Make sure that glyph rows in the current matrix of window W
13381 reference the same glyph memory as corresponding rows in the
13382 frame's frame matrix. This function is called after scrolling W's
13383 current matrix on a terminal frame in try_window_id and
13384 try_window_reusing_current_matrix. */
13387 sync_frame_with_window_matrix_rows (w
)
13390 struct frame
*f
= XFRAME (w
->frame
);
13391 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13393 /* Preconditions: W must be a leaf window and full-width. Its frame
13394 must have a frame matrix. */
13395 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13396 xassert (WINDOW_FULL_WIDTH_P (w
));
13397 xassert (!FRAME_WINDOW_P (f
));
13399 /* If W is a full-width window, glyph pointers in W's current matrix
13400 have, by definition, to be the same as glyph pointers in the
13401 corresponding frame matrix. Note that frame matrices have no
13402 marginal areas (see build_frame_matrix). */
13403 window_row
= w
->current_matrix
->rows
;
13404 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13405 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13406 while (window_row
< window_row_end
)
13408 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13409 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13411 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13412 frame_row
->glyphs
[TEXT_AREA
] = start
;
13413 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13414 frame_row
->glyphs
[LAST_AREA
] = end
;
13416 /* Disable frame rows whose corresponding window rows have
13417 been disabled in try_window_id. */
13418 if (!window_row
->enabled_p
)
13419 frame_row
->enabled_p
= 0;
13421 ++window_row
, ++frame_row
;
13426 /* Find the glyph row in window W containing CHARPOS. Consider all
13427 rows between START and END (not inclusive). END null means search
13428 all rows to the end of the display area of W. Value is the row
13429 containing CHARPOS or null. */
13432 row_containing_pos (w
, charpos
, start
, end
, dy
)
13435 struct glyph_row
*start
, *end
;
13438 struct glyph_row
*row
= start
;
13441 /* If we happen to start on a header-line, skip that. */
13442 if (row
->mode_line_p
)
13445 if ((end
&& row
>= end
) || !row
->enabled_p
)
13448 last_y
= window_text_bottom_y (w
) - dy
;
13452 /* Give up if we have gone too far. */
13453 if (end
&& row
>= end
)
13455 /* This formerly returned if they were equal.
13456 I think that both quantities are of a "last plus one" type;
13457 if so, when they are equal, the row is within the screen. -- rms. */
13458 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13461 /* If it is in this row, return this row. */
13462 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13463 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13464 /* The end position of a row equals the start
13465 position of the next row. If CHARPOS is there, we
13466 would rather display it in the next line, except
13467 when this line ends in ZV. */
13468 && !row
->ends_at_zv_p
13469 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13470 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13477 /* Try to redisplay window W by reusing its existing display. W's
13478 current matrix must be up to date when this function is called,
13479 i.e. window_end_valid must not be nil.
13483 1 if display has been updated
13484 0 if otherwise unsuccessful
13485 -1 if redisplay with same window start is known not to succeed
13487 The following steps are performed:
13489 1. Find the last row in the current matrix of W that is not
13490 affected by changes at the start of current_buffer. If no such row
13493 2. Find the first row in W's current matrix that is not affected by
13494 changes at the end of current_buffer. Maybe there is no such row.
13496 3. Display lines beginning with the row + 1 found in step 1 to the
13497 row found in step 2 or, if step 2 didn't find a row, to the end of
13500 4. If cursor is not known to appear on the window, give up.
13502 5. If display stopped at the row found in step 2, scroll the
13503 display and current matrix as needed.
13505 6. Maybe display some lines at the end of W, if we must. This can
13506 happen under various circumstances, like a partially visible line
13507 becoming fully visible, or because newly displayed lines are displayed
13508 in smaller font sizes.
13510 7. Update W's window end information. */
13516 struct frame
*f
= XFRAME (w
->frame
);
13517 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13518 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13519 struct glyph_row
*last_unchanged_at_beg_row
;
13520 struct glyph_row
*first_unchanged_at_end_row
;
13521 struct glyph_row
*row
;
13522 struct glyph_row
*bottom_row
;
13525 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13526 struct text_pos start_pos
;
13528 int first_unchanged_at_end_vpos
= 0;
13529 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13530 struct text_pos start
;
13531 int first_changed_charpos
, last_changed_charpos
;
13534 if (inhibit_try_window_id
)
13538 /* This is handy for debugging. */
13540 #define GIVE_UP(X) \
13542 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13546 #define GIVE_UP(X) return 0
13549 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13551 /* Don't use this for mini-windows because these can show
13552 messages and mini-buffers, and we don't handle that here. */
13553 if (MINI_WINDOW_P (w
))
13556 /* This flag is used to prevent redisplay optimizations. */
13557 if (windows_or_buffers_changed
|| cursor_type_changed
)
13560 /* Verify that narrowing has not changed.
13561 Also verify that we were not told to prevent redisplay optimizations.
13562 It would be nice to further
13563 reduce the number of cases where this prevents try_window_id. */
13564 if (current_buffer
->clip_changed
13565 || current_buffer
->prevent_redisplay_optimizations_p
)
13568 /* Window must either use window-based redisplay or be full width. */
13569 if (!FRAME_WINDOW_P (f
)
13570 && (!line_ins_del_ok
13571 || !WINDOW_FULL_WIDTH_P (w
)))
13574 /* Give up if point is not known NOT to appear in W. */
13575 if (PT
< CHARPOS (start
))
13578 /* Another way to prevent redisplay optimizations. */
13579 if (XFASTINT (w
->last_modified
) == 0)
13582 /* Verify that window is not hscrolled. */
13583 if (XFASTINT (w
->hscroll
) != 0)
13586 /* Verify that display wasn't paused. */
13587 if (NILP (w
->window_end_valid
))
13590 /* Can't use this if highlighting a region because a cursor movement
13591 will do more than just set the cursor. */
13592 if (!NILP (Vtransient_mark_mode
)
13593 && !NILP (current_buffer
->mark_active
))
13596 /* Likewise if highlighting trailing whitespace. */
13597 if (!NILP (Vshow_trailing_whitespace
))
13600 /* Likewise if showing a region. */
13601 if (!NILP (w
->region_showing
))
13604 /* Can use this if overlay arrow position and or string have changed. */
13605 if (overlay_arrows_changed_p ())
13609 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13610 only if buffer has really changed. The reason is that the gap is
13611 initially at Z for freshly visited files. The code below would
13612 set end_unchanged to 0 in that case. */
13613 if (MODIFF
> SAVE_MODIFF
13614 /* This seems to happen sometimes after saving a buffer. */
13615 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13617 if (GPT
- BEG
< BEG_UNCHANGED
)
13618 BEG_UNCHANGED
= GPT
- BEG
;
13619 if (Z
- GPT
< END_UNCHANGED
)
13620 END_UNCHANGED
= Z
- GPT
;
13623 /* The position of the first and last character that has been changed. */
13624 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13625 last_changed_charpos
= Z
- END_UNCHANGED
;
13627 /* If window starts after a line end, and the last change is in
13628 front of that newline, then changes don't affect the display.
13629 This case happens with stealth-fontification. Note that although
13630 the display is unchanged, glyph positions in the matrix have to
13631 be adjusted, of course. */
13632 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13633 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13634 && ((last_changed_charpos
< CHARPOS (start
)
13635 && CHARPOS (start
) == BEGV
)
13636 || (last_changed_charpos
< CHARPOS (start
) - 1
13637 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13639 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13640 struct glyph_row
*r0
;
13642 /* Compute how many chars/bytes have been added to or removed
13643 from the buffer. */
13644 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13645 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13647 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13649 /* Give up if PT is not in the window. Note that it already has
13650 been checked at the start of try_window_id that PT is not in
13651 front of the window start. */
13652 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13655 /* If window start is unchanged, we can reuse the whole matrix
13656 as is, after adjusting glyph positions. No need to compute
13657 the window end again, since its offset from Z hasn't changed. */
13658 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13659 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13660 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13661 /* PT must not be in a partially visible line. */
13662 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13663 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13665 /* Adjust positions in the glyph matrix. */
13666 if (delta
|| delta_bytes
)
13668 struct glyph_row
*r1
13669 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13670 increment_matrix_positions (w
->current_matrix
,
13671 MATRIX_ROW_VPOS (r0
, current_matrix
),
13672 MATRIX_ROW_VPOS (r1
, current_matrix
),
13673 delta
, delta_bytes
);
13676 /* Set the cursor. */
13677 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13679 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13686 /* Handle the case that changes are all below what is displayed in
13687 the window, and that PT is in the window. This shortcut cannot
13688 be taken if ZV is visible in the window, and text has been added
13689 there that is visible in the window. */
13690 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13691 /* ZV is not visible in the window, or there are no
13692 changes at ZV, actually. */
13693 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13694 || first_changed_charpos
== last_changed_charpos
))
13696 struct glyph_row
*r0
;
13698 /* Give up if PT is not in the window. Note that it already has
13699 been checked at the start of try_window_id that PT is not in
13700 front of the window start. */
13701 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13704 /* If window start is unchanged, we can reuse the whole matrix
13705 as is, without changing glyph positions since no text has
13706 been added/removed in front of the window end. */
13707 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13708 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13709 /* PT must not be in a partially visible line. */
13710 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13711 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13713 /* We have to compute the window end anew since text
13714 can have been added/removed after it. */
13716 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13717 w
->window_end_bytepos
13718 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13720 /* Set the cursor. */
13721 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13723 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13730 /* Give up if window start is in the changed area.
13732 The condition used to read
13734 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13736 but why that was tested escapes me at the moment. */
13737 if (CHARPOS (start
) >= first_changed_charpos
13738 && CHARPOS (start
) <= last_changed_charpos
)
13741 /* Check that window start agrees with the start of the first glyph
13742 row in its current matrix. Check this after we know the window
13743 start is not in changed text, otherwise positions would not be
13745 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13746 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13749 /* Give up if the window ends in strings. Overlay strings
13750 at the end are difficult to handle, so don't try. */
13751 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13752 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13755 /* Compute the position at which we have to start displaying new
13756 lines. Some of the lines at the top of the window might be
13757 reusable because they are not displaying changed text. Find the
13758 last row in W's current matrix not affected by changes at the
13759 start of current_buffer. Value is null if changes start in the
13760 first line of window. */
13761 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13762 if (last_unchanged_at_beg_row
)
13764 /* Avoid starting to display in the moddle of a character, a TAB
13765 for instance. This is easier than to set up the iterator
13766 exactly, and it's not a frequent case, so the additional
13767 effort wouldn't really pay off. */
13768 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13769 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13770 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13771 --last_unchanged_at_beg_row
;
13773 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13776 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13778 start_pos
= it
.current
.pos
;
13780 /* Start displaying new lines in the desired matrix at the same
13781 vpos we would use in the current matrix, i.e. below
13782 last_unchanged_at_beg_row. */
13783 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13785 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13786 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13788 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13792 /* There are no reusable lines at the start of the window.
13793 Start displaying in the first text line. */
13794 start_display (&it
, w
, start
);
13795 it
.vpos
= it
.first_vpos
;
13796 start_pos
= it
.current
.pos
;
13799 /* Find the first row that is not affected by changes at the end of
13800 the buffer. Value will be null if there is no unchanged row, in
13801 which case we must redisplay to the end of the window. delta
13802 will be set to the value by which buffer positions beginning with
13803 first_unchanged_at_end_row have to be adjusted due to text
13805 first_unchanged_at_end_row
13806 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13807 IF_DEBUG (debug_delta
= delta
);
13808 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13810 /* Set stop_pos to the buffer position up to which we will have to
13811 display new lines. If first_unchanged_at_end_row != NULL, this
13812 is the buffer position of the start of the line displayed in that
13813 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13814 that we don't stop at a buffer position. */
13816 if (first_unchanged_at_end_row
)
13818 xassert (last_unchanged_at_beg_row
== NULL
13819 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13821 /* If this is a continuation line, move forward to the next one
13822 that isn't. Changes in lines above affect this line.
13823 Caution: this may move first_unchanged_at_end_row to a row
13824 not displaying text. */
13825 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13826 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13827 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13828 < it
.last_visible_y
))
13829 ++first_unchanged_at_end_row
;
13831 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13832 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13833 >= it
.last_visible_y
))
13834 first_unchanged_at_end_row
= NULL
;
13837 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13839 first_unchanged_at_end_vpos
13840 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13841 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13844 else if (last_unchanged_at_beg_row
== NULL
)
13850 /* Either there is no unchanged row at the end, or the one we have
13851 now displays text. This is a necessary condition for the window
13852 end pos calculation at the end of this function. */
13853 xassert (first_unchanged_at_end_row
== NULL
13854 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13856 debug_last_unchanged_at_beg_vpos
13857 = (last_unchanged_at_beg_row
13858 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13860 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13862 #endif /* GLYPH_DEBUG != 0 */
13865 /* Display new lines. Set last_text_row to the last new line
13866 displayed which has text on it, i.e. might end up as being the
13867 line where the window_end_vpos is. */
13868 w
->cursor
.vpos
= -1;
13869 last_text_row
= NULL
;
13870 overlay_arrow_seen
= 0;
13871 while (it
.current_y
< it
.last_visible_y
13872 && !fonts_changed_p
13873 && (first_unchanged_at_end_row
== NULL
13874 || IT_CHARPOS (it
) < stop_pos
))
13876 if (display_line (&it
))
13877 last_text_row
= it
.glyph_row
- 1;
13880 if (fonts_changed_p
)
13884 /* Compute differences in buffer positions, y-positions etc. for
13885 lines reused at the bottom of the window. Compute what we can
13887 if (first_unchanged_at_end_row
13888 /* No lines reused because we displayed everything up to the
13889 bottom of the window. */
13890 && it
.current_y
< it
.last_visible_y
)
13893 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13895 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13896 run
.current_y
= first_unchanged_at_end_row
->y
;
13897 run
.desired_y
= run
.current_y
+ dy
;
13898 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13902 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13903 first_unchanged_at_end_row
= NULL
;
13905 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13908 /* Find the cursor if not already found. We have to decide whether
13909 PT will appear on this window (it sometimes doesn't, but this is
13910 not a very frequent case.) This decision has to be made before
13911 the current matrix is altered. A value of cursor.vpos < 0 means
13912 that PT is either in one of the lines beginning at
13913 first_unchanged_at_end_row or below the window. Don't care for
13914 lines that might be displayed later at the window end; as
13915 mentioned, this is not a frequent case. */
13916 if (w
->cursor
.vpos
< 0)
13918 /* Cursor in unchanged rows at the top? */
13919 if (PT
< CHARPOS (start_pos
)
13920 && last_unchanged_at_beg_row
)
13922 row
= row_containing_pos (w
, PT
,
13923 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13924 last_unchanged_at_beg_row
+ 1, 0);
13926 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13929 /* Start from first_unchanged_at_end_row looking for PT. */
13930 else if (first_unchanged_at_end_row
)
13932 row
= row_containing_pos (w
, PT
- delta
,
13933 first_unchanged_at_end_row
, NULL
, 0);
13935 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13936 delta_bytes
, dy
, dvpos
);
13939 /* Give up if cursor was not found. */
13940 if (w
->cursor
.vpos
< 0)
13942 clear_glyph_matrix (w
->desired_matrix
);
13947 /* Don't let the cursor end in the scroll margins. */
13949 int this_scroll_margin
, cursor_height
;
13951 this_scroll_margin
= max (0, scroll_margin
);
13952 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13953 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13954 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13956 if ((w
->cursor
.y
< this_scroll_margin
13957 && CHARPOS (start
) > BEGV
)
13958 /* Old redisplay didn't take scroll margin into account at the bottom,
13959 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
13960 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
13961 ? cursor_height
+ this_scroll_margin
13962 : 1)) > it
.last_visible_y
)
13964 w
->cursor
.vpos
= -1;
13965 clear_glyph_matrix (w
->desired_matrix
);
13970 /* Scroll the display. Do it before changing the current matrix so
13971 that xterm.c doesn't get confused about where the cursor glyph is
13973 if (dy
&& run
.height
)
13977 if (FRAME_WINDOW_P (f
))
13979 rif
->update_window_begin_hook (w
);
13980 rif
->clear_window_mouse_face (w
);
13981 rif
->scroll_run_hook (w
, &run
);
13982 rif
->update_window_end_hook (w
, 0, 0);
13986 /* Terminal frame. In this case, dvpos gives the number of
13987 lines to scroll by; dvpos < 0 means scroll up. */
13988 int first_unchanged_at_end_vpos
13989 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
13990 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
13991 int end
= (WINDOW_TOP_EDGE_LINE (w
)
13992 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
13993 + window_internal_height (w
));
13995 /* Perform the operation on the screen. */
13998 /* Scroll last_unchanged_at_beg_row to the end of the
13999 window down dvpos lines. */
14000 set_terminal_window (end
);
14002 /* On dumb terminals delete dvpos lines at the end
14003 before inserting dvpos empty lines. */
14004 if (!scroll_region_ok
)
14005 ins_del_lines (end
- dvpos
, -dvpos
);
14007 /* Insert dvpos empty lines in front of
14008 last_unchanged_at_beg_row. */
14009 ins_del_lines (from
, dvpos
);
14011 else if (dvpos
< 0)
14013 /* Scroll up last_unchanged_at_beg_vpos to the end of
14014 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14015 set_terminal_window (end
);
14017 /* Delete dvpos lines in front of
14018 last_unchanged_at_beg_vpos. ins_del_lines will set
14019 the cursor to the given vpos and emit |dvpos| delete
14021 ins_del_lines (from
+ dvpos
, dvpos
);
14023 /* On a dumb terminal insert dvpos empty lines at the
14025 if (!scroll_region_ok
)
14026 ins_del_lines (end
+ dvpos
, -dvpos
);
14029 set_terminal_window (0);
14035 /* Shift reused rows of the current matrix to the right position.
14036 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14038 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14039 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14042 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14043 bottom_vpos
, dvpos
);
14044 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14047 else if (dvpos
> 0)
14049 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14050 bottom_vpos
, dvpos
);
14051 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14052 first_unchanged_at_end_vpos
+ dvpos
, 0);
14055 /* For frame-based redisplay, make sure that current frame and window
14056 matrix are in sync with respect to glyph memory. */
14057 if (!FRAME_WINDOW_P (f
))
14058 sync_frame_with_window_matrix_rows (w
);
14060 /* Adjust buffer positions in reused rows. */
14062 increment_matrix_positions (current_matrix
,
14063 first_unchanged_at_end_vpos
+ dvpos
,
14064 bottom_vpos
, delta
, delta_bytes
);
14066 /* Adjust Y positions. */
14068 shift_glyph_matrix (w
, current_matrix
,
14069 first_unchanged_at_end_vpos
+ dvpos
,
14072 if (first_unchanged_at_end_row
)
14074 first_unchanged_at_end_row
+= dvpos
;
14075 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14076 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14077 first_unchanged_at_end_row
= NULL
;
14080 /* If scrolling up, there may be some lines to display at the end of
14082 last_text_row_at_end
= NULL
;
14085 /* Scrolling up can leave for example a partially visible line
14086 at the end of the window to be redisplayed. */
14087 /* Set last_row to the glyph row in the current matrix where the
14088 window end line is found. It has been moved up or down in
14089 the matrix by dvpos. */
14090 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14091 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14093 /* If last_row is the window end line, it should display text. */
14094 xassert (last_row
->displays_text_p
);
14096 /* If window end line was partially visible before, begin
14097 displaying at that line. Otherwise begin displaying with the
14098 line following it. */
14099 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14101 init_to_row_start (&it
, w
, last_row
);
14102 it
.vpos
= last_vpos
;
14103 it
.current_y
= last_row
->y
;
14107 init_to_row_end (&it
, w
, last_row
);
14108 it
.vpos
= 1 + last_vpos
;
14109 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14113 /* We may start in a continuation line. If so, we have to
14114 get the right continuation_lines_width and current_x. */
14115 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14116 it
.hpos
= it
.current_x
= 0;
14118 /* Display the rest of the lines at the window end. */
14119 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14120 while (it
.current_y
< it
.last_visible_y
14121 && !fonts_changed_p
)
14123 /* Is it always sure that the display agrees with lines in
14124 the current matrix? I don't think so, so we mark rows
14125 displayed invalid in the current matrix by setting their
14126 enabled_p flag to zero. */
14127 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14128 if (display_line (&it
))
14129 last_text_row_at_end
= it
.glyph_row
- 1;
14133 /* Update window_end_pos and window_end_vpos. */
14134 if (first_unchanged_at_end_row
14135 && !last_text_row_at_end
)
14137 /* Window end line if one of the preserved rows from the current
14138 matrix. Set row to the last row displaying text in current
14139 matrix starting at first_unchanged_at_end_row, after
14141 xassert (first_unchanged_at_end_row
->displays_text_p
);
14142 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14143 first_unchanged_at_end_row
);
14144 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14146 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14147 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14149 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14150 xassert (w
->window_end_bytepos
>= 0);
14151 IF_DEBUG (debug_method_add (w
, "A"));
14153 else if (last_text_row_at_end
)
14156 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14157 w
->window_end_bytepos
14158 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14160 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14161 xassert (w
->window_end_bytepos
>= 0);
14162 IF_DEBUG (debug_method_add (w
, "B"));
14164 else if (last_text_row
)
14166 /* We have displayed either to the end of the window or at the
14167 end of the window, i.e. the last row with text is to be found
14168 in the desired matrix. */
14170 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14171 w
->window_end_bytepos
14172 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14174 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14175 xassert (w
->window_end_bytepos
>= 0);
14177 else if (first_unchanged_at_end_row
== NULL
14178 && last_text_row
== NULL
14179 && last_text_row_at_end
== NULL
)
14181 /* Displayed to end of window, but no line containing text was
14182 displayed. Lines were deleted at the end of the window. */
14183 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14184 int vpos
= XFASTINT (w
->window_end_vpos
);
14185 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14186 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14189 row
== NULL
&& vpos
>= first_vpos
;
14190 --vpos
, --current_row
, --desired_row
)
14192 if (desired_row
->enabled_p
)
14194 if (desired_row
->displays_text_p
)
14197 else if (current_row
->displays_text_p
)
14201 xassert (row
!= NULL
);
14202 w
->window_end_vpos
= make_number (vpos
+ 1);
14203 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14204 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14205 xassert (w
->window_end_bytepos
>= 0);
14206 IF_DEBUG (debug_method_add (w
, "C"));
14211 #if 0 /* This leads to problems, for instance when the cursor is
14212 at ZV, and the cursor line displays no text. */
14213 /* Disable rows below what's displayed in the window. This makes
14214 debugging easier. */
14215 enable_glyph_matrix_rows (current_matrix
,
14216 XFASTINT (w
->window_end_vpos
) + 1,
14220 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14221 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14223 /* Record that display has not been completed. */
14224 w
->window_end_valid
= Qnil
;
14225 w
->desired_matrix
->no_scrolling_p
= 1;
14233 /***********************************************************************
14234 More debugging support
14235 ***********************************************************************/
14239 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14240 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14241 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14244 /* Dump the contents of glyph matrix MATRIX on stderr.
14246 GLYPHS 0 means don't show glyph contents.
14247 GLYPHS 1 means show glyphs in short form
14248 GLYPHS > 1 means show glyphs in long form. */
14251 dump_glyph_matrix (matrix
, glyphs
)
14252 struct glyph_matrix
*matrix
;
14256 for (i
= 0; i
< matrix
->nrows
; ++i
)
14257 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14261 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14262 the glyph row and area where the glyph comes from. */
14265 dump_glyph (row
, glyph
, area
)
14266 struct glyph_row
*row
;
14267 struct glyph
*glyph
;
14270 if (glyph
->type
== CHAR_GLYPH
)
14273 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14274 glyph
- row
->glyphs
[TEXT_AREA
],
14277 (BUFFERP (glyph
->object
)
14279 : (STRINGP (glyph
->object
)
14282 glyph
->pixel_width
,
14284 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14288 glyph
->left_box_line_p
,
14289 glyph
->right_box_line_p
);
14291 else if (glyph
->type
== STRETCH_GLYPH
)
14294 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14295 glyph
- row
->glyphs
[TEXT_AREA
],
14298 (BUFFERP (glyph
->object
)
14300 : (STRINGP (glyph
->object
)
14303 glyph
->pixel_width
,
14307 glyph
->left_box_line_p
,
14308 glyph
->right_box_line_p
);
14310 else if (glyph
->type
== IMAGE_GLYPH
)
14313 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14314 glyph
- row
->glyphs
[TEXT_AREA
],
14317 (BUFFERP (glyph
->object
)
14319 : (STRINGP (glyph
->object
)
14322 glyph
->pixel_width
,
14326 glyph
->left_box_line_p
,
14327 glyph
->right_box_line_p
);
14332 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14333 GLYPHS 0 means don't show glyph contents.
14334 GLYPHS 1 means show glyphs in short form
14335 GLYPHS > 1 means show glyphs in long form. */
14338 dump_glyph_row (row
, vpos
, glyphs
)
14339 struct glyph_row
*row
;
14344 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14345 fprintf (stderr
, "======================================================================\n");
14347 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14348 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14350 MATRIX_ROW_START_CHARPOS (row
),
14351 MATRIX_ROW_END_CHARPOS (row
),
14352 row
->used
[TEXT_AREA
],
14353 row
->contains_overlapping_glyphs_p
,
14355 row
->truncated_on_left_p
,
14356 row
->truncated_on_right_p
,
14358 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14359 row
->displays_text_p
,
14362 row
->ends_in_middle_of_char_p
,
14363 row
->starts_in_middle_of_char_p
,
14369 row
->visible_height
,
14372 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14373 row
->end
.overlay_string_index
,
14374 row
->continuation_lines_width
);
14375 fprintf (stderr
, "%9d %5d\n",
14376 CHARPOS (row
->start
.string_pos
),
14377 CHARPOS (row
->end
.string_pos
));
14378 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14379 row
->end
.dpvec_index
);
14386 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14388 struct glyph
*glyph
= row
->glyphs
[area
];
14389 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14391 /* Glyph for a line end in text. */
14392 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14395 if (glyph
< glyph_end
)
14396 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14398 for (; glyph
< glyph_end
; ++glyph
)
14399 dump_glyph (row
, glyph
, area
);
14402 else if (glyphs
== 1)
14406 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14408 char *s
= (char *) alloca (row
->used
[area
] + 1);
14411 for (i
= 0; i
< row
->used
[area
]; ++i
)
14413 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14414 if (glyph
->type
== CHAR_GLYPH
14415 && glyph
->u
.ch
< 0x80
14416 && glyph
->u
.ch
>= ' ')
14417 s
[i
] = glyph
->u
.ch
;
14423 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14429 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14430 Sdump_glyph_matrix
, 0, 1, "p",
14431 doc
: /* Dump the current matrix of the selected window to stderr.
14432 Shows contents of glyph row structures. With non-nil
14433 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14434 glyphs in short form, otherwise show glyphs in long form. */)
14436 Lisp_Object glyphs
;
14438 struct window
*w
= XWINDOW (selected_window
);
14439 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14441 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14442 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14443 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14444 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14445 fprintf (stderr
, "=============================================\n");
14446 dump_glyph_matrix (w
->current_matrix
,
14447 NILP (glyphs
) ? 0 : XINT (glyphs
));
14452 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14453 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14456 struct frame
*f
= XFRAME (selected_frame
);
14457 dump_glyph_matrix (f
->current_matrix
, 1);
14462 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14463 doc
: /* Dump glyph row ROW to stderr.
14464 GLYPH 0 means don't dump glyphs.
14465 GLYPH 1 means dump glyphs in short form.
14466 GLYPH > 1 or omitted means dump glyphs in long form. */)
14468 Lisp_Object row
, glyphs
;
14470 struct glyph_matrix
*matrix
;
14473 CHECK_NUMBER (row
);
14474 matrix
= XWINDOW (selected_window
)->current_matrix
;
14476 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14477 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14479 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14484 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14485 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14486 GLYPH 0 means don't dump glyphs.
14487 GLYPH 1 means dump glyphs in short form.
14488 GLYPH > 1 or omitted means dump glyphs in long form. */)
14490 Lisp_Object row
, glyphs
;
14492 struct frame
*sf
= SELECTED_FRAME ();
14493 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14496 CHECK_NUMBER (row
);
14498 if (vpos
>= 0 && vpos
< m
->nrows
)
14499 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14500 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14505 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14506 doc
: /* Toggle tracing of redisplay.
14507 With ARG, turn tracing on if and only if ARG is positive. */)
14512 trace_redisplay_p
= !trace_redisplay_p
;
14515 arg
= Fprefix_numeric_value (arg
);
14516 trace_redisplay_p
= XINT (arg
) > 0;
14523 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14524 doc
: /* Like `format', but print result to stderr.
14525 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14530 Lisp_Object s
= Fformat (nargs
, args
);
14531 fprintf (stderr
, "%s", SDATA (s
));
14535 #endif /* GLYPH_DEBUG */
14539 /***********************************************************************
14540 Building Desired Matrix Rows
14541 ***********************************************************************/
14543 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14544 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14546 static struct glyph_row
*
14547 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14549 Lisp_Object overlay_arrow_string
;
14551 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14552 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14553 struct buffer
*old
= current_buffer
;
14554 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14555 int arrow_len
= SCHARS (overlay_arrow_string
);
14556 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14557 const unsigned char *p
;
14560 int n_glyphs_before
;
14562 set_buffer_temp (buffer
);
14563 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14564 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14565 SET_TEXT_POS (it
.position
, 0, 0);
14567 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14569 while (p
< arrow_end
)
14571 Lisp_Object face
, ilisp
;
14573 /* Get the next character. */
14575 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14577 it
.c
= *p
, it
.len
= 1;
14580 /* Get its face. */
14581 ilisp
= make_number (p
- arrow_string
);
14582 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14583 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14585 /* Compute its width, get its glyphs. */
14586 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14587 SET_TEXT_POS (it
.position
, -1, -1);
14588 PRODUCE_GLYPHS (&it
);
14590 /* If this character doesn't fit any more in the line, we have
14591 to remove some glyphs. */
14592 if (it
.current_x
> it
.last_visible_x
)
14594 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14599 set_buffer_temp (old
);
14600 return it
.glyph_row
;
14604 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14605 glyphs are only inserted for terminal frames since we can't really
14606 win with truncation glyphs when partially visible glyphs are
14607 involved. Which glyphs to insert is determined by
14608 produce_special_glyphs. */
14611 insert_left_trunc_glyphs (it
)
14614 struct it truncate_it
;
14615 struct glyph
*from
, *end
, *to
, *toend
;
14617 xassert (!FRAME_WINDOW_P (it
->f
));
14619 /* Get the truncation glyphs. */
14621 truncate_it
.current_x
= 0;
14622 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14623 truncate_it
.glyph_row
= &scratch_glyph_row
;
14624 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14625 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14626 truncate_it
.object
= make_number (0);
14627 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14629 /* Overwrite glyphs from IT with truncation glyphs. */
14630 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14631 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14632 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14633 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14638 /* There may be padding glyphs left over. Overwrite them too. */
14639 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14641 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14647 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14651 /* Compute the pixel height and width of IT->glyph_row.
14653 Most of the time, ascent and height of a display line will be equal
14654 to the max_ascent and max_height values of the display iterator
14655 structure. This is not the case if
14657 1. We hit ZV without displaying anything. In this case, max_ascent
14658 and max_height will be zero.
14660 2. We have some glyphs that don't contribute to the line height.
14661 (The glyph row flag contributes_to_line_height_p is for future
14662 pixmap extensions).
14664 The first case is easily covered by using default values because in
14665 these cases, the line height does not really matter, except that it
14666 must not be zero. */
14669 compute_line_metrics (it
)
14672 struct glyph_row
*row
= it
->glyph_row
;
14675 if (FRAME_WINDOW_P (it
->f
))
14677 int i
, min_y
, max_y
;
14679 /* The line may consist of one space only, that was added to
14680 place the cursor on it. If so, the row's height hasn't been
14682 if (row
->height
== 0)
14684 if (it
->max_ascent
+ it
->max_descent
== 0)
14685 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14686 row
->ascent
= it
->max_ascent
;
14687 row
->height
= it
->max_ascent
+ it
->max_descent
;
14688 row
->phys_ascent
= it
->max_phys_ascent
;
14689 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14690 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14693 /* Compute the width of this line. */
14694 row
->pixel_width
= row
->x
;
14695 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14696 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14698 xassert (row
->pixel_width
>= 0);
14699 xassert (row
->ascent
>= 0 && row
->height
> 0);
14701 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14702 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14704 /* If first line's physical ascent is larger than its logical
14705 ascent, use the physical ascent, and make the row taller.
14706 This makes accented characters fully visible. */
14707 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14708 && row
->phys_ascent
> row
->ascent
)
14710 row
->height
+= row
->phys_ascent
- row
->ascent
;
14711 row
->ascent
= row
->phys_ascent
;
14714 /* Compute how much of the line is visible. */
14715 row
->visible_height
= row
->height
;
14717 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14718 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14720 if (row
->y
< min_y
)
14721 row
->visible_height
-= min_y
- row
->y
;
14722 if (row
->y
+ row
->height
> max_y
)
14723 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14727 row
->pixel_width
= row
->used
[TEXT_AREA
];
14728 if (row
->continued_p
)
14729 row
->pixel_width
-= it
->continuation_pixel_width
;
14730 else if (row
->truncated_on_right_p
)
14731 row
->pixel_width
-= it
->truncation_pixel_width
;
14732 row
->ascent
= row
->phys_ascent
= 0;
14733 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14734 row
->extra_line_spacing
= 0;
14737 /* Compute a hash code for this row. */
14739 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14740 for (i
= 0; i
< row
->used
[area
]; ++i
)
14741 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14742 + row
->glyphs
[area
][i
].u
.val
14743 + row
->glyphs
[area
][i
].face_id
14744 + row
->glyphs
[area
][i
].padding_p
14745 + (row
->glyphs
[area
][i
].type
<< 2));
14747 it
->max_ascent
= it
->max_descent
= 0;
14748 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14752 /* Append one space to the glyph row of iterator IT if doing a
14753 window-based redisplay. The space has the same face as
14754 IT->face_id. Value is non-zero if a space was added.
14756 This function is called to make sure that there is always one glyph
14757 at the end of a glyph row that the cursor can be set on under
14758 window-systems. (If there weren't such a glyph we would not know
14759 how wide and tall a box cursor should be displayed).
14761 At the same time this space let's a nicely handle clearing to the
14762 end of the line if the row ends in italic text. */
14765 append_space_for_newline (it
, default_face_p
)
14767 int default_face_p
;
14769 if (FRAME_WINDOW_P (it
->f
))
14771 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14773 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14774 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14776 /* Save some values that must not be changed.
14777 Must save IT->c and IT->len because otherwise
14778 ITERATOR_AT_END_P wouldn't work anymore after
14779 append_space_for_newline has been called. */
14780 enum display_element_type saved_what
= it
->what
;
14781 int saved_c
= it
->c
, saved_len
= it
->len
;
14782 int saved_x
= it
->current_x
;
14783 int saved_face_id
= it
->face_id
;
14784 struct text_pos saved_pos
;
14785 Lisp_Object saved_object
;
14788 saved_object
= it
->object
;
14789 saved_pos
= it
->position
;
14791 it
->what
= IT_CHARACTER
;
14792 bzero (&it
->position
, sizeof it
->position
);
14793 it
->object
= make_number (0);
14797 if (default_face_p
)
14798 it
->face_id
= DEFAULT_FACE_ID
;
14799 else if (it
->face_before_selective_p
)
14800 it
->face_id
= it
->saved_face_id
;
14801 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14802 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14804 PRODUCE_GLYPHS (it
);
14806 it
->override_ascent
= -1;
14807 it
->constrain_row_ascent_descent_p
= 0;
14808 it
->current_x
= saved_x
;
14809 it
->object
= saved_object
;
14810 it
->position
= saved_pos
;
14811 it
->what
= saved_what
;
14812 it
->face_id
= saved_face_id
;
14813 it
->len
= saved_len
;
14823 /* Extend the face of the last glyph in the text area of IT->glyph_row
14824 to the end of the display line. Called from display_line.
14825 If the glyph row is empty, add a space glyph to it so that we
14826 know the face to draw. Set the glyph row flag fill_line_p. */
14829 extend_face_to_end_of_line (it
)
14833 struct frame
*f
= it
->f
;
14835 /* If line is already filled, do nothing. */
14836 if (it
->current_x
>= it
->last_visible_x
)
14839 /* Face extension extends the background and box of IT->face_id
14840 to the end of the line. If the background equals the background
14841 of the frame, we don't have to do anything. */
14842 if (it
->face_before_selective_p
)
14843 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14845 face
= FACE_FROM_ID (f
, it
->face_id
);
14847 if (FRAME_WINDOW_P (f
)
14848 && face
->box
== FACE_NO_BOX
14849 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14853 /* Set the glyph row flag indicating that the face of the last glyph
14854 in the text area has to be drawn to the end of the text area. */
14855 it
->glyph_row
->fill_line_p
= 1;
14857 /* If current character of IT is not ASCII, make sure we have the
14858 ASCII face. This will be automatically undone the next time
14859 get_next_display_element returns a multibyte character. Note
14860 that the character will always be single byte in unibyte text. */
14861 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14863 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14866 if (FRAME_WINDOW_P (f
))
14868 /* If the row is empty, add a space with the current face of IT,
14869 so that we know which face to draw. */
14870 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14872 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14873 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14874 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14879 /* Save some values that must not be changed. */
14880 int saved_x
= it
->current_x
;
14881 struct text_pos saved_pos
;
14882 Lisp_Object saved_object
;
14883 enum display_element_type saved_what
= it
->what
;
14884 int saved_face_id
= it
->face_id
;
14886 saved_object
= it
->object
;
14887 saved_pos
= it
->position
;
14889 it
->what
= IT_CHARACTER
;
14890 bzero (&it
->position
, sizeof it
->position
);
14891 it
->object
= make_number (0);
14894 it
->face_id
= face
->id
;
14896 PRODUCE_GLYPHS (it
);
14898 while (it
->current_x
<= it
->last_visible_x
)
14899 PRODUCE_GLYPHS (it
);
14901 /* Don't count these blanks really. It would let us insert a left
14902 truncation glyph below and make us set the cursor on them, maybe. */
14903 it
->current_x
= saved_x
;
14904 it
->object
= saved_object
;
14905 it
->position
= saved_pos
;
14906 it
->what
= saved_what
;
14907 it
->face_id
= saved_face_id
;
14912 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14913 trailing whitespace. */
14916 trailing_whitespace_p (charpos
)
14919 int bytepos
= CHAR_TO_BYTE (charpos
);
14922 while (bytepos
< ZV_BYTE
14923 && (c
= FETCH_CHAR (bytepos
),
14924 c
== ' ' || c
== '\t'))
14927 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14929 if (bytepos
!= PT_BYTE
)
14936 /* Highlight trailing whitespace, if any, in ROW. */
14939 highlight_trailing_whitespace (f
, row
)
14941 struct glyph_row
*row
;
14943 int used
= row
->used
[TEXT_AREA
];
14947 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14948 struct glyph
*glyph
= start
+ used
- 1;
14950 /* Skip over glyphs inserted to display the cursor at the
14951 end of a line, for extending the face of the last glyph
14952 to the end of the line on terminals, and for truncation
14953 and continuation glyphs. */
14954 while (glyph
>= start
14955 && glyph
->type
== CHAR_GLYPH
14956 && INTEGERP (glyph
->object
))
14959 /* If last glyph is a space or stretch, and it's trailing
14960 whitespace, set the face of all trailing whitespace glyphs in
14961 IT->glyph_row to `trailing-whitespace'. */
14963 && BUFFERP (glyph
->object
)
14964 && (glyph
->type
== STRETCH_GLYPH
14965 || (glyph
->type
== CHAR_GLYPH
14966 && glyph
->u
.ch
== ' '))
14967 && trailing_whitespace_p (glyph
->charpos
))
14969 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
14973 while (glyph
>= start
14974 && BUFFERP (glyph
->object
)
14975 && (glyph
->type
== STRETCH_GLYPH
14976 || (glyph
->type
== CHAR_GLYPH
14977 && glyph
->u
.ch
== ' ')))
14978 (glyph
--)->face_id
= face_id
;
14984 /* Value is non-zero if glyph row ROW in window W should be
14985 used to hold the cursor. */
14988 cursor_row_p (w
, row
)
14990 struct glyph_row
*row
;
14992 int cursor_row_p
= 1;
14994 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
14996 /* If the row ends with a newline from a string, we don't want
14997 the cursor there (if the row is continued it doesn't end in a
14999 if (CHARPOS (row
->end
.string_pos
) >= 0)
15000 cursor_row_p
= row
->continued_p
;
15001 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15003 /* If the row ends in middle of a real character,
15004 and the line is continued, we want the cursor here.
15005 That's because MATRIX_ROW_END_CHARPOS would equal
15006 PT if PT is before the character. */
15007 if (!row
->ends_in_ellipsis_p
)
15008 cursor_row_p
= row
->continued_p
;
15010 /* If the row ends in an ellipsis, then
15011 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15012 We want that position to be displayed after the ellipsis. */
15015 /* If the row ends at ZV, display the cursor at the end of that
15016 row instead of at the start of the row below. */
15017 else if (row
->ends_at_zv_p
)
15023 return cursor_row_p
;
15027 /* Construct the glyph row IT->glyph_row in the desired matrix of
15028 IT->w from text at the current position of IT. See dispextern.h
15029 for an overview of struct it. Value is non-zero if
15030 IT->glyph_row displays text, as opposed to a line displaying ZV
15037 struct glyph_row
*row
= it
->glyph_row
;
15038 Lisp_Object overlay_arrow_string
;
15040 /* We always start displaying at hpos zero even if hscrolled. */
15041 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15043 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15044 >= it
->w
->desired_matrix
->nrows
)
15046 it
->w
->nrows_scale_factor
++;
15047 fonts_changed_p
= 1;
15051 /* Is IT->w showing the region? */
15052 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15054 /* Clear the result glyph row and enable it. */
15055 prepare_desired_row (row
);
15057 row
->y
= it
->current_y
;
15058 row
->start
= it
->start
;
15059 row
->continuation_lines_width
= it
->continuation_lines_width
;
15060 row
->displays_text_p
= 1;
15061 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15062 it
->starts_in_middle_of_char_p
= 0;
15064 /* Arrange the overlays nicely for our purposes. Usually, we call
15065 display_line on only one line at a time, in which case this
15066 can't really hurt too much, or we call it on lines which appear
15067 one after another in the buffer, in which case all calls to
15068 recenter_overlay_lists but the first will be pretty cheap. */
15069 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15071 /* Move over display elements that are not visible because we are
15072 hscrolled. This may stop at an x-position < IT->first_visible_x
15073 if the first glyph is partially visible or if we hit a line end. */
15074 if (it
->current_x
< it
->first_visible_x
)
15076 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15077 MOVE_TO_POS
| MOVE_TO_X
);
15080 /* Get the initial row height. This is either the height of the
15081 text hscrolled, if there is any, or zero. */
15082 row
->ascent
= it
->max_ascent
;
15083 row
->height
= it
->max_ascent
+ it
->max_descent
;
15084 row
->phys_ascent
= it
->max_phys_ascent
;
15085 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15086 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15088 /* Loop generating characters. The loop is left with IT on the next
15089 character to display. */
15092 int n_glyphs_before
, hpos_before
, x_before
;
15094 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15096 /* Retrieve the next thing to display. Value is zero if end of
15098 if (!get_next_display_element (it
))
15100 /* Maybe add a space at the end of this line that is used to
15101 display the cursor there under X. Set the charpos of the
15102 first glyph of blank lines not corresponding to any text
15104 #ifdef HAVE_WINDOW_SYSTEM
15105 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15106 row
->exact_window_width_line_p
= 1;
15108 #endif /* HAVE_WINDOW_SYSTEM */
15109 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15110 || row
->used
[TEXT_AREA
] == 0)
15112 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15113 row
->displays_text_p
= 0;
15115 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15116 && (!MINI_WINDOW_P (it
->w
)
15117 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15118 row
->indicate_empty_line_p
= 1;
15121 it
->continuation_lines_width
= 0;
15122 row
->ends_at_zv_p
= 1;
15126 /* Now, get the metrics of what we want to display. This also
15127 generates glyphs in `row' (which is IT->glyph_row). */
15128 n_glyphs_before
= row
->used
[TEXT_AREA
];
15131 /* Remember the line height so far in case the next element doesn't
15132 fit on the line. */
15133 if (!it
->truncate_lines_p
)
15135 ascent
= it
->max_ascent
;
15136 descent
= it
->max_descent
;
15137 phys_ascent
= it
->max_phys_ascent
;
15138 phys_descent
= it
->max_phys_descent
;
15141 PRODUCE_GLYPHS (it
);
15143 /* If this display element was in marginal areas, continue with
15145 if (it
->area
!= TEXT_AREA
)
15147 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15148 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15149 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15150 row
->phys_height
= max (row
->phys_height
,
15151 it
->max_phys_ascent
+ it
->max_phys_descent
);
15152 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15153 it
->max_extra_line_spacing
);
15154 set_iterator_to_next (it
, 1);
15158 /* Does the display element fit on the line? If we truncate
15159 lines, we should draw past the right edge of the window. If
15160 we don't truncate, we want to stop so that we can display the
15161 continuation glyph before the right margin. If lines are
15162 continued, there are two possible strategies for characters
15163 resulting in more than 1 glyph (e.g. tabs): Display as many
15164 glyphs as possible in this line and leave the rest for the
15165 continuation line, or display the whole element in the next
15166 line. Original redisplay did the former, so we do it also. */
15167 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15168 hpos_before
= it
->hpos
;
15171 if (/* Not a newline. */
15173 /* Glyphs produced fit entirely in the line. */
15174 && it
->current_x
< it
->last_visible_x
)
15176 it
->hpos
+= nglyphs
;
15177 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15178 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15179 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15180 row
->phys_height
= max (row
->phys_height
,
15181 it
->max_phys_ascent
+ it
->max_phys_descent
);
15182 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15183 it
->max_extra_line_spacing
);
15184 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15185 row
->x
= x
- it
->first_visible_x
;
15190 struct glyph
*glyph
;
15192 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15194 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15195 new_x
= x
+ glyph
->pixel_width
;
15197 if (/* Lines are continued. */
15198 !it
->truncate_lines_p
15199 && (/* Glyph doesn't fit on the line. */
15200 new_x
> it
->last_visible_x
15201 /* Or it fits exactly on a window system frame. */
15202 || (new_x
== it
->last_visible_x
15203 && FRAME_WINDOW_P (it
->f
))))
15205 /* End of a continued line. */
15208 || (new_x
== it
->last_visible_x
15209 && FRAME_WINDOW_P (it
->f
)))
15211 /* Current glyph is the only one on the line or
15212 fits exactly on the line. We must continue
15213 the line because we can't draw the cursor
15214 after the glyph. */
15215 row
->continued_p
= 1;
15216 it
->current_x
= new_x
;
15217 it
->continuation_lines_width
+= new_x
;
15219 if (i
== nglyphs
- 1)
15221 set_iterator_to_next (it
, 1);
15222 #ifdef HAVE_WINDOW_SYSTEM
15223 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15225 if (!get_next_display_element (it
))
15227 row
->exact_window_width_line_p
= 1;
15228 it
->continuation_lines_width
= 0;
15229 row
->continued_p
= 0;
15230 row
->ends_at_zv_p
= 1;
15232 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15234 row
->continued_p
= 0;
15235 row
->exact_window_width_line_p
= 1;
15238 #endif /* HAVE_WINDOW_SYSTEM */
15241 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15242 && !FRAME_WINDOW_P (it
->f
))
15244 /* A padding glyph that doesn't fit on this line.
15245 This means the whole character doesn't fit
15247 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15249 /* Fill the rest of the row with continuation
15250 glyphs like in 20.x. */
15251 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15252 < row
->glyphs
[1 + TEXT_AREA
])
15253 produce_special_glyphs (it
, IT_CONTINUATION
);
15255 row
->continued_p
= 1;
15256 it
->current_x
= x_before
;
15257 it
->continuation_lines_width
+= x_before
;
15259 /* Restore the height to what it was before the
15260 element not fitting on the line. */
15261 it
->max_ascent
= ascent
;
15262 it
->max_descent
= descent
;
15263 it
->max_phys_ascent
= phys_ascent
;
15264 it
->max_phys_descent
= phys_descent
;
15266 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15268 /* A TAB that extends past the right edge of the
15269 window. This produces a single glyph on
15270 window system frames. We leave the glyph in
15271 this row and let it fill the row, but don't
15272 consume the TAB. */
15273 it
->continuation_lines_width
+= it
->last_visible_x
;
15274 row
->ends_in_middle_of_char_p
= 1;
15275 row
->continued_p
= 1;
15276 glyph
->pixel_width
= it
->last_visible_x
- x
;
15277 it
->starts_in_middle_of_char_p
= 1;
15281 /* Something other than a TAB that draws past
15282 the right edge of the window. Restore
15283 positions to values before the element. */
15284 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15286 /* Display continuation glyphs. */
15287 if (!FRAME_WINDOW_P (it
->f
))
15288 produce_special_glyphs (it
, IT_CONTINUATION
);
15289 row
->continued_p
= 1;
15291 it
->continuation_lines_width
+= x
;
15293 if (nglyphs
> 1 && i
> 0)
15295 row
->ends_in_middle_of_char_p
= 1;
15296 it
->starts_in_middle_of_char_p
= 1;
15299 /* Restore the height to what it was before the
15300 element not fitting on the line. */
15301 it
->max_ascent
= ascent
;
15302 it
->max_descent
= descent
;
15303 it
->max_phys_ascent
= phys_ascent
;
15304 it
->max_phys_descent
= phys_descent
;
15309 else if (new_x
> it
->first_visible_x
)
15311 /* Increment number of glyphs actually displayed. */
15314 if (x
< it
->first_visible_x
)
15315 /* Glyph is partially visible, i.e. row starts at
15316 negative X position. */
15317 row
->x
= x
- it
->first_visible_x
;
15321 /* Glyph is completely off the left margin of the
15322 window. This should not happen because of the
15323 move_it_in_display_line at the start of this
15324 function, unless the text display area of the
15325 window is empty. */
15326 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15330 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15331 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15332 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15333 row
->phys_height
= max (row
->phys_height
,
15334 it
->max_phys_ascent
+ it
->max_phys_descent
);
15335 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15336 it
->max_extra_line_spacing
);
15338 /* End of this display line if row is continued. */
15339 if (row
->continued_p
|| row
->ends_at_zv_p
)
15344 /* Is this a line end? If yes, we're also done, after making
15345 sure that a non-default face is extended up to the right
15346 margin of the window. */
15347 if (ITERATOR_AT_END_OF_LINE_P (it
))
15349 int used_before
= row
->used
[TEXT_AREA
];
15351 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15353 #ifdef HAVE_WINDOW_SYSTEM
15354 /* Add a space at the end of the line that is used to
15355 display the cursor there. */
15356 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15357 append_space_for_newline (it
, 0);
15358 #endif /* HAVE_WINDOW_SYSTEM */
15360 /* Extend the face to the end of the line. */
15361 extend_face_to_end_of_line (it
);
15363 /* Make sure we have the position. */
15364 if (used_before
== 0)
15365 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15367 /* Consume the line end. This skips over invisible lines. */
15368 set_iterator_to_next (it
, 1);
15369 it
->continuation_lines_width
= 0;
15373 /* Proceed with next display element. Note that this skips
15374 over lines invisible because of selective display. */
15375 set_iterator_to_next (it
, 1);
15377 /* If we truncate lines, we are done when the last displayed
15378 glyphs reach past the right margin of the window. */
15379 if (it
->truncate_lines_p
15380 && (FRAME_WINDOW_P (it
->f
)
15381 ? (it
->current_x
>= it
->last_visible_x
)
15382 : (it
->current_x
> it
->last_visible_x
)))
15384 /* Maybe add truncation glyphs. */
15385 if (!FRAME_WINDOW_P (it
->f
))
15389 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15390 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15393 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15395 row
->used
[TEXT_AREA
] = i
;
15396 produce_special_glyphs (it
, IT_TRUNCATION
);
15399 #ifdef HAVE_WINDOW_SYSTEM
15402 /* Don't truncate if we can overflow newline into fringe. */
15403 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15405 if (!get_next_display_element (it
))
15407 it
->continuation_lines_width
= 0;
15408 row
->ends_at_zv_p
= 1;
15409 row
->exact_window_width_line_p
= 1;
15412 if (ITERATOR_AT_END_OF_LINE_P (it
))
15414 row
->exact_window_width_line_p
= 1;
15415 goto at_end_of_line
;
15419 #endif /* HAVE_WINDOW_SYSTEM */
15421 row
->truncated_on_right_p
= 1;
15422 it
->continuation_lines_width
= 0;
15423 reseat_at_next_visible_line_start (it
, 0);
15424 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15425 it
->hpos
= hpos_before
;
15426 it
->current_x
= x_before
;
15431 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15432 at the left window margin. */
15433 if (it
->first_visible_x
15434 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15436 if (!FRAME_WINDOW_P (it
->f
))
15437 insert_left_trunc_glyphs (it
);
15438 row
->truncated_on_left_p
= 1;
15441 /* If the start of this line is the overlay arrow-position, then
15442 mark this glyph row as the one containing the overlay arrow.
15443 This is clearly a mess with variable size fonts. It would be
15444 better to let it be displayed like cursors under X. */
15445 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15446 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15447 !NILP (overlay_arrow_string
)))
15449 /* Overlay arrow in window redisplay is a fringe bitmap. */
15450 if (STRINGP (overlay_arrow_string
))
15452 struct glyph_row
*arrow_row
15453 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15454 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15455 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15456 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15457 struct glyph
*p2
, *end
;
15459 /* Copy the arrow glyphs. */
15460 while (glyph
< arrow_end
)
15463 /* Throw away padding glyphs. */
15465 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15466 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15472 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15477 xassert (INTEGERP (overlay_arrow_string
));
15478 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15480 overlay_arrow_seen
= 1;
15483 /* Compute pixel dimensions of this line. */
15484 compute_line_metrics (it
);
15486 /* Remember the position at which this line ends. */
15487 row
->end
= it
->current
;
15489 /* Record whether this row ends inside an ellipsis. */
15490 row
->ends_in_ellipsis_p
15491 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15492 && it
->ellipsis_p
);
15494 /* Save fringe bitmaps in this row. */
15495 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15496 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15497 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15498 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15500 it
->left_user_fringe_bitmap
= 0;
15501 it
->left_user_fringe_face_id
= 0;
15502 it
->right_user_fringe_bitmap
= 0;
15503 it
->right_user_fringe_face_id
= 0;
15505 /* Maybe set the cursor. */
15506 if (it
->w
->cursor
.vpos
< 0
15507 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15508 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15509 && cursor_row_p (it
->w
, row
))
15510 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15512 /* Highlight trailing whitespace. */
15513 if (!NILP (Vshow_trailing_whitespace
))
15514 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15516 /* Prepare for the next line. This line starts horizontally at (X
15517 HPOS) = (0 0). Vertical positions are incremented. As a
15518 convenience for the caller, IT->glyph_row is set to the next
15520 it
->current_x
= it
->hpos
= 0;
15521 it
->current_y
+= row
->height
;
15524 it
->start
= it
->current
;
15525 return row
->displays_text_p
;
15530 /***********************************************************************
15532 ***********************************************************************/
15534 /* Redisplay the menu bar in the frame for window W.
15536 The menu bar of X frames that don't have X toolkit support is
15537 displayed in a special window W->frame->menu_bar_window.
15539 The menu bar of terminal frames is treated specially as far as
15540 glyph matrices are concerned. Menu bar lines are not part of
15541 windows, so the update is done directly on the frame matrix rows
15542 for the menu bar. */
15545 display_menu_bar (w
)
15548 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15553 /* Don't do all this for graphical frames. */
15555 if (!NILP (Vwindow_system
))
15558 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15563 if (FRAME_MAC_P (f
))
15567 #ifdef USE_X_TOOLKIT
15568 xassert (!FRAME_WINDOW_P (f
));
15569 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15570 it
.first_visible_x
= 0;
15571 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15572 #else /* not USE_X_TOOLKIT */
15573 if (FRAME_WINDOW_P (f
))
15575 /* Menu bar lines are displayed in the desired matrix of the
15576 dummy window menu_bar_window. */
15577 struct window
*menu_w
;
15578 xassert (WINDOWP (f
->menu_bar_window
));
15579 menu_w
= XWINDOW (f
->menu_bar_window
);
15580 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15582 it
.first_visible_x
= 0;
15583 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15587 /* This is a TTY frame, i.e. character hpos/vpos are used as
15589 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15591 it
.first_visible_x
= 0;
15592 it
.last_visible_x
= FRAME_COLS (f
);
15594 #endif /* not USE_X_TOOLKIT */
15596 if (! mode_line_inverse_video
)
15597 /* Force the menu-bar to be displayed in the default face. */
15598 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15600 /* Clear all rows of the menu bar. */
15601 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15603 struct glyph_row
*row
= it
.glyph_row
+ i
;
15604 clear_glyph_row (row
);
15605 row
->enabled_p
= 1;
15606 row
->full_width_p
= 1;
15609 /* Display all items of the menu bar. */
15610 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15611 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15613 Lisp_Object string
;
15615 /* Stop at nil string. */
15616 string
= AREF (items
, i
+ 1);
15620 /* Remember where item was displayed. */
15621 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15623 /* Display the item, pad with one space. */
15624 if (it
.current_x
< it
.last_visible_x
)
15625 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15626 SCHARS (string
) + 1, 0, 0, -1);
15629 /* Fill out the line with spaces. */
15630 if (it
.current_x
< it
.last_visible_x
)
15631 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15633 /* Compute the total height of the lines. */
15634 compute_line_metrics (&it
);
15639 /***********************************************************************
15641 ***********************************************************************/
15643 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15644 FORCE is non-zero, redisplay mode lines unconditionally.
15645 Otherwise, redisplay only mode lines that are garbaged. Value is
15646 the number of windows whose mode lines were redisplayed. */
15649 redisplay_mode_lines (window
, force
)
15650 Lisp_Object window
;
15655 while (!NILP (window
))
15657 struct window
*w
= XWINDOW (window
);
15659 if (WINDOWP (w
->hchild
))
15660 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15661 else if (WINDOWP (w
->vchild
))
15662 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15664 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15665 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15667 struct text_pos lpoint
;
15668 struct buffer
*old
= current_buffer
;
15670 /* Set the window's buffer for the mode line display. */
15671 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15672 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15674 /* Point refers normally to the selected window. For any
15675 other window, set up appropriate value. */
15676 if (!EQ (window
, selected_window
))
15678 struct text_pos pt
;
15680 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15681 if (CHARPOS (pt
) < BEGV
)
15682 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15683 else if (CHARPOS (pt
) > (ZV
- 1))
15684 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15686 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15689 /* Display mode lines. */
15690 clear_glyph_matrix (w
->desired_matrix
);
15691 if (display_mode_lines (w
))
15694 w
->must_be_updated_p
= 1;
15697 /* Restore old settings. */
15698 set_buffer_internal_1 (old
);
15699 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15709 /* Display the mode and/or top line of window W. Value is the number
15710 of mode lines displayed. */
15713 display_mode_lines (w
)
15716 Lisp_Object old_selected_window
, old_selected_frame
;
15719 old_selected_frame
= selected_frame
;
15720 selected_frame
= w
->frame
;
15721 old_selected_window
= selected_window
;
15722 XSETWINDOW (selected_window
, w
);
15724 /* These will be set while the mode line specs are processed. */
15725 line_number_displayed
= 0;
15726 w
->column_number_displayed
= Qnil
;
15728 if (WINDOW_WANTS_MODELINE_P (w
))
15730 struct window
*sel_w
= XWINDOW (old_selected_window
);
15732 /* Select mode line face based on the real selected window. */
15733 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15734 current_buffer
->mode_line_format
);
15738 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15740 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15741 current_buffer
->header_line_format
);
15745 selected_frame
= old_selected_frame
;
15746 selected_window
= old_selected_window
;
15751 /* Display mode or top line of window W. FACE_ID specifies which line
15752 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15753 FORMAT is the mode line format to display. Value is the pixel
15754 height of the mode line displayed. */
15757 display_mode_line (w
, face_id
, format
)
15759 enum face_id face_id
;
15760 Lisp_Object format
;
15764 int count
= SPECPDL_INDEX ();
15766 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15767 prepare_desired_row (it
.glyph_row
);
15769 it
.glyph_row
->mode_line_p
= 1;
15771 if (! mode_line_inverse_video
)
15772 /* Force the mode-line to be displayed in the default face. */
15773 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15775 record_unwind_protect (unwind_format_mode_line
,
15776 format_mode_line_unwind_data (NULL
));
15778 mode_line_target
= MODE_LINE_DISPLAY
;
15780 /* Temporarily make frame's keyboard the current kboard so that
15781 kboard-local variables in the mode_line_format will get the right
15783 push_frame_kboard (it
.f
);
15784 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15785 pop_frame_kboard ();
15787 unbind_to (count
, Qnil
);
15789 /* Fill up with spaces. */
15790 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15792 compute_line_metrics (&it
);
15793 it
.glyph_row
->full_width_p
= 1;
15794 it
.glyph_row
->continued_p
= 0;
15795 it
.glyph_row
->truncated_on_left_p
= 0;
15796 it
.glyph_row
->truncated_on_right_p
= 0;
15798 /* Make a 3D mode-line have a shadow at its right end. */
15799 face
= FACE_FROM_ID (it
.f
, face_id
);
15800 extend_face_to_end_of_line (&it
);
15801 if (face
->box
!= FACE_NO_BOX
)
15803 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15804 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15805 last
->right_box_line_p
= 1;
15808 return it
.glyph_row
->height
;
15811 /* Contribute ELT to the mode line for window IT->w. How it
15812 translates into text depends on its data type.
15814 IT describes the display environment in which we display, as usual.
15816 DEPTH is the depth in recursion. It is used to prevent
15817 infinite recursion here.
15819 FIELD_WIDTH is the number of characters the display of ELT should
15820 occupy in the mode line, and PRECISION is the maximum number of
15821 characters to display from ELT's representation. See
15822 display_string for details.
15824 Returns the hpos of the end of the text generated by ELT.
15826 PROPS is a property list to add to any string we encounter.
15828 If RISKY is nonzero, remove (disregard) any properties in any string
15829 we encounter, and ignore :eval and :propertize.
15831 The global variable `mode_line_target' determines whether the
15832 output is passed to `store_mode_line_noprop',
15833 `store_mode_line_string', or `display_string'. */
15836 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15839 int field_width
, precision
;
15840 Lisp_Object elt
, props
;
15843 int n
= 0, field
, prec
;
15848 elt
= build_string ("*too-deep*");
15852 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15856 /* A string: output it and check for %-constructs within it. */
15858 const unsigned char *this, *lisp_string
;
15860 if (!NILP (props
) || risky
)
15862 Lisp_Object oprops
, aelt
;
15863 oprops
= Ftext_properties_at (make_number (0), elt
);
15865 /* If the starting string's properties are not what
15866 we want, translate the string. Also, if the string
15867 is risky, do that anyway. */
15869 if (NILP (Fequal (props
, oprops
)) || risky
)
15871 /* If the starting string has properties,
15872 merge the specified ones onto the existing ones. */
15873 if (! NILP (oprops
) && !risky
)
15877 oprops
= Fcopy_sequence (oprops
);
15879 while (CONSP (tem
))
15881 oprops
= Fplist_put (oprops
, XCAR (tem
),
15882 XCAR (XCDR (tem
)));
15883 tem
= XCDR (XCDR (tem
));
15888 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15889 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15891 mode_line_proptrans_alist
15892 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15899 elt
= Fcopy_sequence (elt
);
15900 Fset_text_properties (make_number (0), Flength (elt
),
15902 /* Add this item to mode_line_proptrans_alist. */
15903 mode_line_proptrans_alist
15904 = Fcons (Fcons (elt
, props
),
15905 mode_line_proptrans_alist
);
15906 /* Truncate mode_line_proptrans_alist
15907 to at most 50 elements. */
15908 tem
= Fnthcdr (make_number (50),
15909 mode_line_proptrans_alist
);
15911 XSETCDR (tem
, Qnil
);
15916 this = SDATA (elt
);
15917 lisp_string
= this;
15921 prec
= precision
- n
;
15922 switch (mode_line_target
)
15924 case MODE_LINE_NOPROP
:
15925 case MODE_LINE_TITLE
:
15926 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
15928 case MODE_LINE_STRING
:
15929 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15931 case MODE_LINE_DISPLAY
:
15932 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15933 0, prec
, 0, STRING_MULTIBYTE (elt
));
15940 while ((precision
<= 0 || n
< precision
)
15942 && (mode_line_target
!= MODE_LINE_DISPLAY
15943 || it
->current_x
< it
->last_visible_x
))
15945 const unsigned char *last
= this;
15947 /* Advance to end of string or next format specifier. */
15948 while ((c
= *this++) != '\0' && c
!= '%')
15951 if (this - 1 != last
)
15953 int nchars
, nbytes
;
15955 /* Output to end of string or up to '%'. Field width
15956 is length of string. Don't output more than
15957 PRECISION allows us. */
15960 prec
= c_string_width (last
, this - last
, precision
- n
,
15963 switch (mode_line_target
)
15965 case MODE_LINE_NOPROP
:
15966 case MODE_LINE_TITLE
:
15967 n
+= store_mode_line_noprop (last
, 0, prec
);
15969 case MODE_LINE_STRING
:
15971 int bytepos
= last
- lisp_string
;
15972 int charpos
= string_byte_to_char (elt
, bytepos
);
15973 int endpos
= (precision
<= 0
15974 ? string_byte_to_char (elt
,
15975 this - lisp_string
)
15976 : charpos
+ nchars
);
15978 n
+= store_mode_line_string (NULL
,
15979 Fsubstring (elt
, make_number (charpos
),
15980 make_number (endpos
)),
15984 case MODE_LINE_DISPLAY
:
15986 int bytepos
= last
- lisp_string
;
15987 int charpos
= string_byte_to_char (elt
, bytepos
);
15988 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
15990 STRING_MULTIBYTE (elt
));
15995 else /* c == '%' */
15997 const unsigned char *percent_position
= this;
15999 /* Get the specified minimum width. Zero means
16002 while ((c
= *this++) >= '0' && c
<= '9')
16003 field
= field
* 10 + c
- '0';
16005 /* Don't pad beyond the total padding allowed. */
16006 if (field_width
- n
> 0 && field
> field_width
- n
)
16007 field
= field_width
- n
;
16009 /* Note that either PRECISION <= 0 or N < PRECISION. */
16010 prec
= precision
- n
;
16013 n
+= display_mode_element (it
, depth
, field
, prec
,
16014 Vglobal_mode_string
, props
,
16019 int bytepos
, charpos
;
16020 unsigned char *spec
;
16022 bytepos
= percent_position
- lisp_string
;
16023 charpos
= (STRING_MULTIBYTE (elt
)
16024 ? string_byte_to_char (elt
, bytepos
)
16028 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16030 switch (mode_line_target
)
16032 case MODE_LINE_NOPROP
:
16033 case MODE_LINE_TITLE
:
16034 n
+= store_mode_line_noprop (spec
, field
, prec
);
16036 case MODE_LINE_STRING
:
16038 int len
= strlen (spec
);
16039 Lisp_Object tem
= make_string (spec
, len
);
16040 props
= Ftext_properties_at (make_number (charpos
), elt
);
16041 /* Should only keep face property in props */
16042 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16045 case MODE_LINE_DISPLAY
:
16047 int nglyphs_before
, nwritten
;
16049 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16050 nwritten
= display_string (spec
, Qnil
, elt
,
16055 /* Assign to the glyphs written above the
16056 string where the `%x' came from, position
16060 struct glyph
*glyph
16061 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16065 for (i
= 0; i
< nwritten
; ++i
)
16067 glyph
[i
].object
= elt
;
16068 glyph
[i
].charpos
= charpos
;
16085 /* A symbol: process the value of the symbol recursively
16086 as if it appeared here directly. Avoid error if symbol void.
16087 Special case: if value of symbol is a string, output the string
16090 register Lisp_Object tem
;
16092 /* If the variable is not marked as risky to set
16093 then its contents are risky to use. */
16094 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16097 tem
= Fboundp (elt
);
16100 tem
= Fsymbol_value (elt
);
16101 /* If value is a string, output that string literally:
16102 don't check for % within it. */
16106 if (!EQ (tem
, elt
))
16108 /* Give up right away for nil or t. */
16118 register Lisp_Object car
, tem
;
16120 /* A cons cell: five distinct cases.
16121 If first element is :eval or :propertize, do something special.
16122 If first element is a string or a cons, process all the elements
16123 and effectively concatenate them.
16124 If first element is a negative number, truncate displaying cdr to
16125 at most that many characters. If positive, pad (with spaces)
16126 to at least that many characters.
16127 If first element is a symbol, process the cadr or caddr recursively
16128 according to whether the symbol's value is non-nil or nil. */
16130 if (EQ (car
, QCeval
))
16132 /* An element of the form (:eval FORM) means evaluate FORM
16133 and use the result as mode line elements. */
16138 if (CONSP (XCDR (elt
)))
16141 spec
= safe_eval (XCAR (XCDR (elt
)));
16142 n
+= display_mode_element (it
, depth
, field_width
- n
,
16143 precision
- n
, spec
, props
,
16147 else if (EQ (car
, QCpropertize
))
16149 /* An element of the form (:propertize ELT PROPS...)
16150 means display ELT but applying properties PROPS. */
16155 if (CONSP (XCDR (elt
)))
16156 n
+= display_mode_element (it
, depth
, field_width
- n
,
16157 precision
- n
, XCAR (XCDR (elt
)),
16158 XCDR (XCDR (elt
)), risky
);
16160 else if (SYMBOLP (car
))
16162 tem
= Fboundp (car
);
16166 /* elt is now the cdr, and we know it is a cons cell.
16167 Use its car if CAR has a non-nil value. */
16170 tem
= Fsymbol_value (car
);
16177 /* Symbol's value is nil (or symbol is unbound)
16178 Get the cddr of the original list
16179 and if possible find the caddr and use that. */
16183 else if (!CONSP (elt
))
16188 else if (INTEGERP (car
))
16190 register int lim
= XINT (car
);
16194 /* Negative int means reduce maximum width. */
16195 if (precision
<= 0)
16198 precision
= min (precision
, -lim
);
16202 /* Padding specified. Don't let it be more than
16203 current maximum. */
16205 lim
= min (precision
, lim
);
16207 /* If that's more padding than already wanted, queue it.
16208 But don't reduce padding already specified even if
16209 that is beyond the current truncation point. */
16210 field_width
= max (lim
, field_width
);
16214 else if (STRINGP (car
) || CONSP (car
))
16216 register int limit
= 50;
16217 /* Limit is to protect against circular lists. */
16220 && (precision
<= 0 || n
< precision
))
16222 n
+= display_mode_element (it
, depth
,
16223 /* Do padding only after the last
16224 element in the list. */
16225 (! CONSP (XCDR (elt
))
16228 precision
- n
, XCAR (elt
),
16238 elt
= build_string ("*invalid*");
16242 /* Pad to FIELD_WIDTH. */
16243 if (field_width
> 0 && n
< field_width
)
16245 switch (mode_line_target
)
16247 case MODE_LINE_NOPROP
:
16248 case MODE_LINE_TITLE
:
16249 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16251 case MODE_LINE_STRING
:
16252 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16254 case MODE_LINE_DISPLAY
:
16255 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16264 /* Store a mode-line string element in mode_line_string_list.
16266 If STRING is non-null, display that C string. Otherwise, the Lisp
16267 string LISP_STRING is displayed.
16269 FIELD_WIDTH is the minimum number of output glyphs to produce.
16270 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16271 with spaces. FIELD_WIDTH <= 0 means don't pad.
16273 PRECISION is the maximum number of characters to output from
16274 STRING. PRECISION <= 0 means don't truncate the string.
16276 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16277 properties to the string.
16279 PROPS are the properties to add to the string.
16280 The mode_line_string_face face property is always added to the string.
16284 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16286 Lisp_Object lisp_string
;
16295 if (string
!= NULL
)
16297 len
= strlen (string
);
16298 if (precision
> 0 && len
> precision
)
16300 lisp_string
= make_string (string
, len
);
16302 props
= mode_line_string_face_prop
;
16303 else if (!NILP (mode_line_string_face
))
16305 Lisp_Object face
= Fplist_get (props
, Qface
);
16306 props
= Fcopy_sequence (props
);
16308 face
= mode_line_string_face
;
16310 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16311 props
= Fplist_put (props
, Qface
, face
);
16313 Fadd_text_properties (make_number (0), make_number (len
),
16314 props
, lisp_string
);
16318 len
= XFASTINT (Flength (lisp_string
));
16319 if (precision
> 0 && len
> precision
)
16322 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16325 if (!NILP (mode_line_string_face
))
16329 props
= Ftext_properties_at (make_number (0), lisp_string
);
16330 face
= Fplist_get (props
, Qface
);
16332 face
= mode_line_string_face
;
16334 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16335 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16337 lisp_string
= Fcopy_sequence (lisp_string
);
16340 Fadd_text_properties (make_number (0), make_number (len
),
16341 props
, lisp_string
);
16346 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16350 if (field_width
> len
)
16352 field_width
-= len
;
16353 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16355 Fadd_text_properties (make_number (0), make_number (field_width
),
16356 props
, lisp_string
);
16357 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16365 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16367 doc
: /* Format a string out of a mode line format specification.
16368 First arg FORMAT specifies the mode line format (see `mode-line-format'
16369 for details) to use.
16371 Optional second arg FACE specifies the face property to put
16372 on all characters for which no face is specified.
16373 t means whatever face the window's mode line currently uses
16374 \(either `mode-line' or `mode-line-inactive', depending).
16375 nil means the default is no face property.
16376 If FACE is an integer, the value string has no text properties.
16378 Optional third and fourth args WINDOW and BUFFER specify the window
16379 and buffer to use as the context for the formatting (defaults
16380 are the selected window and the window's buffer). */)
16381 (format
, face
, window
, buffer
)
16382 Lisp_Object format
, face
, window
, buffer
;
16387 struct buffer
*old_buffer
= NULL
;
16389 int no_props
= INTEGERP (face
);
16390 int count
= SPECPDL_INDEX ();
16392 int string_start
= 0;
16395 window
= selected_window
;
16396 CHECK_WINDOW (window
);
16397 w
= XWINDOW (window
);
16400 buffer
= w
->buffer
;
16401 CHECK_BUFFER (buffer
);
16404 return build_string ("");
16412 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16413 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16417 face_id
= DEFAULT_FACE_ID
;
16419 if (XBUFFER (buffer
) != current_buffer
)
16420 old_buffer
= current_buffer
;
16422 record_unwind_protect (unwind_format_mode_line
,
16423 format_mode_line_unwind_data (old_buffer
));
16426 set_buffer_internal_1 (XBUFFER (buffer
));
16428 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16432 mode_line_target
= MODE_LINE_NOPROP
;
16433 mode_line_string_face_prop
= Qnil
;
16434 mode_line_string_list
= Qnil
;
16435 string_start
= MODE_LINE_NOPROP_LEN (0);
16439 mode_line_target
= MODE_LINE_STRING
;
16440 mode_line_string_list
= Qnil
;
16441 mode_line_string_face
= face
;
16442 mode_line_string_face_prop
16443 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16446 push_frame_kboard (it
.f
);
16447 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16448 pop_frame_kboard ();
16452 len
= MODE_LINE_NOPROP_LEN (string_start
);
16453 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16457 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16458 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16459 make_string ("", 0));
16462 unbind_to (count
, Qnil
);
16466 /* Write a null-terminated, right justified decimal representation of
16467 the positive integer D to BUF using a minimal field width WIDTH. */
16470 pint2str (buf
, width
, d
)
16471 register char *buf
;
16472 register int width
;
16475 register char *p
= buf
;
16483 *p
++ = d
% 10 + '0';
16488 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16499 /* Write a null-terminated, right justified decimal and "human
16500 readable" representation of the nonnegative integer D to BUF using
16501 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16503 static const char power_letter
[] =
16517 pint2hrstr (buf
, width
, d
)
16522 /* We aim to represent the nonnegative integer D as
16523 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16526 /* -1 means: do not use TENTHS. */
16530 /* Length of QUOTIENT.TENTHS as a string. */
16536 if (1000 <= quotient
)
16538 /* Scale to the appropriate EXPONENT. */
16541 remainder
= quotient
% 1000;
16545 while (1000 <= quotient
);
16547 /* Round to nearest and decide whether to use TENTHS or not. */
16550 tenths
= remainder
/ 100;
16551 if (50 <= remainder
% 100)
16558 if (quotient
== 10)
16566 if (500 <= remainder
)
16568 if (quotient
< 999)
16579 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16580 if (tenths
== -1 && quotient
<= 99)
16587 p
= psuffix
= buf
+ max (width
, length
);
16589 /* Print EXPONENT. */
16591 *psuffix
++ = power_letter
[exponent
];
16594 /* Print TENTHS. */
16597 *--p
= '0' + tenths
;
16601 /* Print QUOTIENT. */
16604 int digit
= quotient
% 10;
16605 *--p
= '0' + digit
;
16607 while ((quotient
/= 10) != 0);
16609 /* Print leading spaces. */
16614 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16615 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16616 type of CODING_SYSTEM. Return updated pointer into BUF. */
16618 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16621 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16622 Lisp_Object coding_system
;
16623 register char *buf
;
16627 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16628 const unsigned char *eol_str
;
16630 /* The EOL conversion we are using. */
16631 Lisp_Object eoltype
;
16633 val
= Fget (coding_system
, Qcoding_system
);
16636 if (!VECTORP (val
)) /* Not yet decided. */
16641 eoltype
= eol_mnemonic_undecided
;
16642 /* Don't mention EOL conversion if it isn't decided. */
16646 Lisp_Object eolvalue
;
16648 eolvalue
= Fget (coding_system
, Qeol_type
);
16651 *buf
++ = XFASTINT (AREF (val
, 1));
16655 /* The EOL conversion that is normal on this system. */
16657 if (NILP (eolvalue
)) /* Not yet decided. */
16658 eoltype
= eol_mnemonic_undecided
;
16659 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16660 eoltype
= eol_mnemonic_undecided
;
16661 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16662 eoltype
= (XFASTINT (eolvalue
) == 0
16663 ? eol_mnemonic_unix
16664 : (XFASTINT (eolvalue
) == 1
16665 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16671 /* Mention the EOL conversion if it is not the usual one. */
16672 if (STRINGP (eoltype
))
16674 eol_str
= SDATA (eoltype
);
16675 eol_str_len
= SBYTES (eoltype
);
16677 else if (INTEGERP (eoltype
)
16678 && CHAR_VALID_P (XINT (eoltype
), 0))
16680 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16681 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16686 eol_str
= invalid_eol_type
;
16687 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16689 bcopy (eol_str
, buf
, eol_str_len
);
16690 buf
+= eol_str_len
;
16696 /* Return a string for the output of a mode line %-spec for window W,
16697 generated by character C. PRECISION >= 0 means don't return a
16698 string longer than that value. FIELD_WIDTH > 0 means pad the
16699 string returned with spaces to that value. Return 1 in *MULTIBYTE
16700 if the result is multibyte text.
16702 Note we operate on the current buffer for most purposes,
16703 the exception being w->base_line_pos. */
16705 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16708 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16711 int field_width
, precision
;
16715 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16716 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16717 struct buffer
*b
= current_buffer
;
16725 if (!NILP (b
->read_only
))
16727 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16732 /* This differs from %* only for a modified read-only buffer. */
16733 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16735 if (!NILP (b
->read_only
))
16740 /* This differs from %* in ignoring read-only-ness. */
16741 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16753 if (command_loop_level
> 5)
16755 p
= decode_mode_spec_buf
;
16756 for (i
= 0; i
< command_loop_level
; i
++)
16759 return decode_mode_spec_buf
;
16767 if (command_loop_level
> 5)
16769 p
= decode_mode_spec_buf
;
16770 for (i
= 0; i
< command_loop_level
; i
++)
16773 return decode_mode_spec_buf
;
16780 /* Let lots_of_dashes be a string of infinite length. */
16781 if (mode_line_target
== MODE_LINE_NOPROP
||
16782 mode_line_target
== MODE_LINE_STRING
)
16784 if (field_width
<= 0
16785 || field_width
> sizeof (lots_of_dashes
))
16787 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16788 decode_mode_spec_buf
[i
] = '-';
16789 decode_mode_spec_buf
[i
] = '\0';
16790 return decode_mode_spec_buf
;
16793 return lots_of_dashes
;
16802 int col
= (int) current_column (); /* iftc */
16803 w
->column_number_displayed
= make_number (col
);
16804 pint2str (decode_mode_spec_buf
, field_width
, col
);
16805 return decode_mode_spec_buf
;
16809 /* %F displays the frame name. */
16810 if (!NILP (f
->title
))
16811 return (char *) SDATA (f
->title
);
16812 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16813 return (char *) SDATA (f
->name
);
16822 int size
= ZV
- BEGV
;
16823 pint2str (decode_mode_spec_buf
, field_width
, size
);
16824 return decode_mode_spec_buf
;
16829 int size
= ZV
- BEGV
;
16830 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16831 return decode_mode_spec_buf
;
16836 int startpos
= XMARKER (w
->start
)->charpos
;
16837 int startpos_byte
= marker_byte_position (w
->start
);
16838 int line
, linepos
, linepos_byte
, topline
;
16840 int height
= WINDOW_TOTAL_LINES (w
);
16842 /* If we decided that this buffer isn't suitable for line numbers,
16843 don't forget that too fast. */
16844 if (EQ (w
->base_line_pos
, w
->buffer
))
16846 /* But do forget it, if the window shows a different buffer now. */
16847 else if (BUFFERP (w
->base_line_pos
))
16848 w
->base_line_pos
= Qnil
;
16850 /* If the buffer is very big, don't waste time. */
16851 if (INTEGERP (Vline_number_display_limit
)
16852 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16854 w
->base_line_pos
= Qnil
;
16855 w
->base_line_number
= Qnil
;
16859 if (!NILP (w
->base_line_number
)
16860 && !NILP (w
->base_line_pos
)
16861 && XFASTINT (w
->base_line_pos
) <= startpos
)
16863 line
= XFASTINT (w
->base_line_number
);
16864 linepos
= XFASTINT (w
->base_line_pos
);
16865 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16870 linepos
= BUF_BEGV (b
);
16871 linepos_byte
= BUF_BEGV_BYTE (b
);
16874 /* Count lines from base line to window start position. */
16875 nlines
= display_count_lines (linepos
, linepos_byte
,
16879 topline
= nlines
+ line
;
16881 /* Determine a new base line, if the old one is too close
16882 or too far away, or if we did not have one.
16883 "Too close" means it's plausible a scroll-down would
16884 go back past it. */
16885 if (startpos
== BUF_BEGV (b
))
16887 w
->base_line_number
= make_number (topline
);
16888 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16890 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16891 || linepos
== BUF_BEGV (b
))
16893 int limit
= BUF_BEGV (b
);
16894 int limit_byte
= BUF_BEGV_BYTE (b
);
16896 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16898 if (startpos
- distance
> limit
)
16900 limit
= startpos
- distance
;
16901 limit_byte
= CHAR_TO_BYTE (limit
);
16904 nlines
= display_count_lines (startpos
, startpos_byte
,
16906 - (height
* 2 + 30),
16908 /* If we couldn't find the lines we wanted within
16909 line_number_display_limit_width chars per line,
16910 give up on line numbers for this window. */
16911 if (position
== limit_byte
&& limit
== startpos
- distance
)
16913 w
->base_line_pos
= w
->buffer
;
16914 w
->base_line_number
= Qnil
;
16918 w
->base_line_number
= make_number (topline
- nlines
);
16919 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16922 /* Now count lines from the start pos to point. */
16923 nlines
= display_count_lines (startpos
, startpos_byte
,
16924 PT_BYTE
, PT
, &junk
);
16926 /* Record that we did display the line number. */
16927 line_number_displayed
= 1;
16929 /* Make the string to show. */
16930 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16931 return decode_mode_spec_buf
;
16934 char* p
= decode_mode_spec_buf
;
16935 int pad
= field_width
- 2;
16941 return decode_mode_spec_buf
;
16947 obj
= b
->mode_name
;
16951 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
16957 int pos
= marker_position (w
->start
);
16958 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16960 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
16962 if (pos
<= BUF_BEGV (b
))
16967 else if (pos
<= BUF_BEGV (b
))
16971 if (total
> 1000000)
16972 /* Do it differently for a large value, to avoid overflow. */
16973 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
16975 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
16976 /* We can't normally display a 3-digit number,
16977 so get us a 2-digit number that is close. */
16980 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
16981 return decode_mode_spec_buf
;
16985 /* Display percentage of size above the bottom of the screen. */
16988 int toppos
= marker_position (w
->start
);
16989 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
16990 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
16992 if (botpos
>= BUF_ZV (b
))
16994 if (toppos
<= BUF_BEGV (b
))
17001 if (total
> 1000000)
17002 /* Do it differently for a large value, to avoid overflow. */
17003 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17005 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17006 /* We can't normally display a 3-digit number,
17007 so get us a 2-digit number that is close. */
17010 if (toppos
<= BUF_BEGV (b
))
17011 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17013 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17014 return decode_mode_spec_buf
;
17019 /* status of process */
17020 obj
= Fget_buffer_process (Fcurrent_buffer ());
17022 return "no process";
17023 #ifdef subprocesses
17024 obj
= Fsymbol_name (Fprocess_status (obj
));
17028 case 't': /* indicate TEXT or BINARY */
17029 #ifdef MODE_LINE_BINARY_TEXT
17030 return MODE_LINE_BINARY_TEXT (b
);
17036 /* coding-system (not including end-of-line format) */
17038 /* coding-system (including end-of-line type) */
17040 int eol_flag
= (c
== 'Z');
17041 char *p
= decode_mode_spec_buf
;
17043 if (! FRAME_WINDOW_P (f
))
17045 /* No need to mention EOL here--the terminal never needs
17046 to do EOL conversion. */
17047 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17048 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17050 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17053 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17054 #ifdef subprocesses
17055 obj
= Fget_buffer_process (Fcurrent_buffer ());
17056 if (PROCESSP (obj
))
17058 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17060 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17063 #endif /* subprocesses */
17066 return decode_mode_spec_buf
;
17072 *multibyte
= STRING_MULTIBYTE (obj
);
17073 return (char *) SDATA (obj
);
17080 /* Count up to COUNT lines starting from START / START_BYTE.
17081 But don't go beyond LIMIT_BYTE.
17082 Return the number of lines thus found (always nonnegative).
17084 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17087 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17088 int start
, start_byte
, limit_byte
, count
;
17091 register unsigned char *cursor
;
17092 unsigned char *base
;
17094 register int ceiling
;
17095 register unsigned char *ceiling_addr
;
17096 int orig_count
= count
;
17098 /* If we are not in selective display mode,
17099 check only for newlines. */
17100 int selective_display
= (!NILP (current_buffer
->selective_display
)
17101 && !INTEGERP (current_buffer
->selective_display
));
17105 while (start_byte
< limit_byte
)
17107 ceiling
= BUFFER_CEILING_OF (start_byte
);
17108 ceiling
= min (limit_byte
- 1, ceiling
);
17109 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17110 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17113 if (selective_display
)
17114 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17117 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17120 if (cursor
!= ceiling_addr
)
17124 start_byte
+= cursor
- base
+ 1;
17125 *byte_pos_ptr
= start_byte
;
17129 if (++cursor
== ceiling_addr
)
17135 start_byte
+= cursor
- base
;
17140 while (start_byte
> limit_byte
)
17142 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17143 ceiling
= max (limit_byte
, ceiling
);
17144 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17145 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17148 if (selective_display
)
17149 while (--cursor
!= ceiling_addr
17150 && *cursor
!= '\n' && *cursor
!= 015)
17153 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17156 if (cursor
!= ceiling_addr
)
17160 start_byte
+= cursor
- base
+ 1;
17161 *byte_pos_ptr
= start_byte
;
17162 /* When scanning backwards, we should
17163 not count the newline posterior to which we stop. */
17164 return - orig_count
- 1;
17170 /* Here we add 1 to compensate for the last decrement
17171 of CURSOR, which took it past the valid range. */
17172 start_byte
+= cursor
- base
+ 1;
17176 *byte_pos_ptr
= limit_byte
;
17179 return - orig_count
+ count
;
17180 return orig_count
- count
;
17186 /***********************************************************************
17188 ***********************************************************************/
17190 /* Display a NUL-terminated string, starting with index START.
17192 If STRING is non-null, display that C string. Otherwise, the Lisp
17193 string LISP_STRING is displayed.
17195 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17196 FACE_STRING. Display STRING or LISP_STRING with the face at
17197 FACE_STRING_POS in FACE_STRING:
17199 Display the string in the environment given by IT, but use the
17200 standard display table, temporarily.
17202 FIELD_WIDTH is the minimum number of output glyphs to produce.
17203 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17204 with spaces. If STRING has more characters, more than FIELD_WIDTH
17205 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17207 PRECISION is the maximum number of characters to output from
17208 STRING. PRECISION < 0 means don't truncate the string.
17210 This is roughly equivalent to printf format specifiers:
17212 FIELD_WIDTH PRECISION PRINTF
17213 ----------------------------------------
17219 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17220 display them, and < 0 means obey the current buffer's value of
17221 enable_multibyte_characters.
17223 Value is the number of glyphs produced. */
17226 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17227 start
, it
, field_width
, precision
, max_x
, multibyte
)
17228 unsigned char *string
;
17229 Lisp_Object lisp_string
;
17230 Lisp_Object face_string
;
17231 int face_string_pos
;
17234 int field_width
, precision
, max_x
;
17237 int hpos_at_start
= it
->hpos
;
17238 int saved_face_id
= it
->face_id
;
17239 struct glyph_row
*row
= it
->glyph_row
;
17241 /* Initialize the iterator IT for iteration over STRING beginning
17242 with index START. */
17243 reseat_to_string (it
, string
, lisp_string
, start
,
17244 precision
, field_width
, multibyte
);
17246 /* If displaying STRING, set up the face of the iterator
17247 from LISP_STRING, if that's given. */
17248 if (STRINGP (face_string
))
17254 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17255 0, it
->region_beg_charpos
,
17256 it
->region_end_charpos
,
17257 &endptr
, it
->base_face_id
, 0);
17258 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17259 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17262 /* Set max_x to the maximum allowed X position. Don't let it go
17263 beyond the right edge of the window. */
17265 max_x
= it
->last_visible_x
;
17267 max_x
= min (max_x
, it
->last_visible_x
);
17269 /* Skip over display elements that are not visible. because IT->w is
17271 if (it
->current_x
< it
->first_visible_x
)
17272 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17273 MOVE_TO_POS
| MOVE_TO_X
);
17275 row
->ascent
= it
->max_ascent
;
17276 row
->height
= it
->max_ascent
+ it
->max_descent
;
17277 row
->phys_ascent
= it
->max_phys_ascent
;
17278 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17279 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17281 /* This condition is for the case that we are called with current_x
17282 past last_visible_x. */
17283 while (it
->current_x
< max_x
)
17285 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17287 /* Get the next display element. */
17288 if (!get_next_display_element (it
))
17291 /* Produce glyphs. */
17292 x_before
= it
->current_x
;
17293 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17294 PRODUCE_GLYPHS (it
);
17296 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17299 while (i
< nglyphs
)
17301 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17303 if (!it
->truncate_lines_p
17304 && x
+ glyph
->pixel_width
> max_x
)
17306 /* End of continued line or max_x reached. */
17307 if (CHAR_GLYPH_PADDING_P (*glyph
))
17309 /* A wide character is unbreakable. */
17310 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17311 it
->current_x
= x_before
;
17315 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17320 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17322 /* Glyph is at least partially visible. */
17324 if (x
< it
->first_visible_x
)
17325 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17329 /* Glyph is off the left margin of the display area.
17330 Should not happen. */
17334 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17335 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17336 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17337 row
->phys_height
= max (row
->phys_height
,
17338 it
->max_phys_ascent
+ it
->max_phys_descent
);
17339 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17340 it
->max_extra_line_spacing
);
17341 x
+= glyph
->pixel_width
;
17345 /* Stop if max_x reached. */
17349 /* Stop at line ends. */
17350 if (ITERATOR_AT_END_OF_LINE_P (it
))
17352 it
->continuation_lines_width
= 0;
17356 set_iterator_to_next (it
, 1);
17358 /* Stop if truncating at the right edge. */
17359 if (it
->truncate_lines_p
17360 && it
->current_x
>= it
->last_visible_x
)
17362 /* Add truncation mark, but don't do it if the line is
17363 truncated at a padding space. */
17364 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17366 if (!FRAME_WINDOW_P (it
->f
))
17370 if (it
->current_x
> it
->last_visible_x
)
17372 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17373 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17375 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17377 row
->used
[TEXT_AREA
] = i
;
17378 produce_special_glyphs (it
, IT_TRUNCATION
);
17381 produce_special_glyphs (it
, IT_TRUNCATION
);
17383 it
->glyph_row
->truncated_on_right_p
= 1;
17389 /* Maybe insert a truncation at the left. */
17390 if (it
->first_visible_x
17391 && IT_CHARPOS (*it
) > 0)
17393 if (!FRAME_WINDOW_P (it
->f
))
17394 insert_left_trunc_glyphs (it
);
17395 it
->glyph_row
->truncated_on_left_p
= 1;
17398 it
->face_id
= saved_face_id
;
17400 /* Value is number of columns displayed. */
17401 return it
->hpos
- hpos_at_start
;
17406 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17407 appears as an element of LIST or as the car of an element of LIST.
17408 If PROPVAL is a list, compare each element against LIST in that
17409 way, and return 1/2 if any element of PROPVAL is found in LIST.
17410 Otherwise return 0. This function cannot quit.
17411 The return value is 2 if the text is invisible but with an ellipsis
17412 and 1 if it's invisible and without an ellipsis. */
17415 invisible_p (propval
, list
)
17416 register Lisp_Object propval
;
17419 register Lisp_Object tail
, proptail
;
17421 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17423 register Lisp_Object tem
;
17425 if (EQ (propval
, tem
))
17427 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17428 return NILP (XCDR (tem
)) ? 1 : 2;
17431 if (CONSP (propval
))
17433 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17435 Lisp_Object propelt
;
17436 propelt
= XCAR (proptail
);
17437 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17439 register Lisp_Object tem
;
17441 if (EQ (propelt
, tem
))
17443 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17444 return NILP (XCDR (tem
)) ? 1 : 2;
17452 /* Calculate a width or height in pixels from a specification using
17453 the following elements:
17456 NUM - a (fractional) multiple of the default font width/height
17457 (NUM) - specifies exactly NUM pixels
17458 UNIT - a fixed number of pixels, see below.
17459 ELEMENT - size of a display element in pixels, see below.
17460 (NUM . SPEC) - equals NUM * SPEC
17461 (+ SPEC SPEC ...) - add pixel values
17462 (- SPEC SPEC ...) - subtract pixel values
17463 (- SPEC) - negate pixel value
17466 INT or FLOAT - a number constant
17467 SYMBOL - use symbol's (buffer local) variable binding.
17470 in - pixels per inch *)
17471 mm - pixels per 1/1000 meter *)
17472 cm - pixels per 1/100 meter *)
17473 width - width of current font in pixels.
17474 height - height of current font in pixels.
17476 *) using the ratio(s) defined in display-pixels-per-inch.
17480 left-fringe - left fringe width in pixels
17481 right-fringe - right fringe width in pixels
17483 left-margin - left margin width in pixels
17484 right-margin - right margin width in pixels
17486 scroll-bar - scroll-bar area width in pixels
17490 Pixels corresponding to 5 inches:
17493 Total width of non-text areas on left side of window (if scroll-bar is on left):
17494 '(space :width (+ left-fringe left-margin scroll-bar))
17496 Align to first text column (in header line):
17497 '(space :align-to 0)
17499 Align to middle of text area minus half the width of variable `my-image'
17500 containing a loaded image:
17501 '(space :align-to (0.5 . (- text my-image)))
17503 Width of left margin minus width of 1 character in the default font:
17504 '(space :width (- left-margin 1))
17506 Width of left margin minus width of 2 characters in the current font:
17507 '(space :width (- left-margin (2 . width)))
17509 Center 1 character over left-margin (in header line):
17510 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17512 Different ways to express width of left fringe plus left margin minus one pixel:
17513 '(space :width (- (+ left-fringe left-margin) (1)))
17514 '(space :width (+ left-fringe left-margin (- (1))))
17515 '(space :width (+ left-fringe left-margin (-1)))
17519 #define NUMVAL(X) \
17520 ((INTEGERP (X) || FLOATP (X)) \
17525 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17530 int width_p
, *align_to
;
17534 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17535 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17538 return OK_PIXELS (0);
17540 if (SYMBOLP (prop
))
17542 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17544 char *unit
= SDATA (SYMBOL_NAME (prop
));
17546 if (unit
[0] == 'i' && unit
[1] == 'n')
17548 else if (unit
[0] == 'm' && unit
[1] == 'm')
17550 else if (unit
[0] == 'c' && unit
[1] == 'm')
17557 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17558 || (CONSP (Vdisplay_pixels_per_inch
)
17560 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17561 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17563 return OK_PIXELS (ppi
/ pixels
);
17569 #ifdef HAVE_WINDOW_SYSTEM
17570 if (EQ (prop
, Qheight
))
17571 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17572 if (EQ (prop
, Qwidth
))
17573 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17575 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17576 return OK_PIXELS (1);
17579 if (EQ (prop
, Qtext
))
17580 return OK_PIXELS (width_p
17581 ? window_box_width (it
->w
, TEXT_AREA
)
17582 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17584 if (align_to
&& *align_to
< 0)
17587 if (EQ (prop
, Qleft
))
17588 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17589 if (EQ (prop
, Qright
))
17590 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17591 if (EQ (prop
, Qcenter
))
17592 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17593 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17594 if (EQ (prop
, Qleft_fringe
))
17595 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17596 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17597 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17598 if (EQ (prop
, Qright_fringe
))
17599 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17600 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17601 : window_box_right_offset (it
->w
, TEXT_AREA
));
17602 if (EQ (prop
, Qleft_margin
))
17603 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17604 if (EQ (prop
, Qright_margin
))
17605 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17606 if (EQ (prop
, Qscroll_bar
))
17607 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17609 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17610 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17611 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17616 if (EQ (prop
, Qleft_fringe
))
17617 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17618 if (EQ (prop
, Qright_fringe
))
17619 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17620 if (EQ (prop
, Qleft_margin
))
17621 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17622 if (EQ (prop
, Qright_margin
))
17623 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17624 if (EQ (prop
, Qscroll_bar
))
17625 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17628 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17631 if (INTEGERP (prop
) || FLOATP (prop
))
17633 int base_unit
= (width_p
17634 ? FRAME_COLUMN_WIDTH (it
->f
)
17635 : FRAME_LINE_HEIGHT (it
->f
));
17636 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17641 Lisp_Object car
= XCAR (prop
);
17642 Lisp_Object cdr
= XCDR (prop
);
17646 #ifdef HAVE_WINDOW_SYSTEM
17647 if (valid_image_p (prop
))
17649 int id
= lookup_image (it
->f
, prop
);
17650 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17652 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17655 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17661 while (CONSP (cdr
))
17663 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17664 font
, width_p
, align_to
))
17667 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17672 if (EQ (car
, Qminus
))
17674 return OK_PIXELS (pixels
);
17677 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17680 if (INTEGERP (car
) || FLOATP (car
))
17683 pixels
= XFLOATINT (car
);
17685 return OK_PIXELS (pixels
);
17686 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17687 font
, width_p
, align_to
))
17688 return OK_PIXELS (pixels
* fact
);
17699 /***********************************************************************
17701 ***********************************************************************/
17703 #ifdef HAVE_WINDOW_SYSTEM
17708 dump_glyph_string (s
)
17709 struct glyph_string
*s
;
17711 fprintf (stderr
, "glyph string\n");
17712 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17713 s
->x
, s
->y
, s
->width
, s
->height
);
17714 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17715 fprintf (stderr
, " hl = %d\n", s
->hl
);
17716 fprintf (stderr
, " left overhang = %d, right = %d\n",
17717 s
->left_overhang
, s
->right_overhang
);
17718 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17719 fprintf (stderr
, " extends to end of line = %d\n",
17720 s
->extends_to_end_of_line_p
);
17721 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17722 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17725 #endif /* GLYPH_DEBUG */
17727 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17728 of XChar2b structures for S; it can't be allocated in
17729 init_glyph_string because it must be allocated via `alloca'. W
17730 is the window on which S is drawn. ROW and AREA are the glyph row
17731 and area within the row from which S is constructed. START is the
17732 index of the first glyph structure covered by S. HL is a
17733 face-override for drawing S. */
17736 #define OPTIONAL_HDC(hdc) hdc,
17737 #define DECLARE_HDC(hdc) HDC hdc;
17738 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17739 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17742 #ifndef OPTIONAL_HDC
17743 #define OPTIONAL_HDC(hdc)
17744 #define DECLARE_HDC(hdc)
17745 #define ALLOCATE_HDC(hdc, f)
17746 #define RELEASE_HDC(hdc, f)
17750 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17751 struct glyph_string
*s
;
17755 struct glyph_row
*row
;
17756 enum glyph_row_area area
;
17758 enum draw_glyphs_face hl
;
17760 bzero (s
, sizeof *s
);
17762 s
->f
= XFRAME (w
->frame
);
17766 s
->display
= FRAME_X_DISPLAY (s
->f
);
17767 s
->window
= FRAME_X_WINDOW (s
->f
);
17768 s
->char2b
= char2b
;
17772 s
->first_glyph
= row
->glyphs
[area
] + start
;
17773 s
->height
= row
->height
;
17774 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17776 /* Display the internal border below the tool-bar window. */
17777 if (WINDOWP (s
->f
->tool_bar_window
)
17778 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17779 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17781 s
->ybase
= s
->y
+ row
->ascent
;
17785 /* Append the list of glyph strings with head H and tail T to the list
17786 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17789 append_glyph_string_lists (head
, tail
, h
, t
)
17790 struct glyph_string
**head
, **tail
;
17791 struct glyph_string
*h
, *t
;
17805 /* Prepend the list of glyph strings with head H and tail T to the
17806 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17810 prepend_glyph_string_lists (head
, tail
, h
, t
)
17811 struct glyph_string
**head
, **tail
;
17812 struct glyph_string
*h
, *t
;
17826 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17827 Set *HEAD and *TAIL to the resulting list. */
17830 append_glyph_string (head
, tail
, s
)
17831 struct glyph_string
**head
, **tail
;
17832 struct glyph_string
*s
;
17834 s
->next
= s
->prev
= NULL
;
17835 append_glyph_string_lists (head
, tail
, s
, s
);
17839 /* Get face and two-byte form of character glyph GLYPH on frame F.
17840 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17841 a pointer to a realized face that is ready for display. */
17843 static INLINE
struct face
*
17844 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17846 struct glyph
*glyph
;
17852 xassert (glyph
->type
== CHAR_GLYPH
);
17853 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17858 if (!glyph
->multibyte_p
)
17860 /* Unibyte case. We don't have to encode, but we have to make
17861 sure to use a face suitable for unibyte. */
17862 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17864 else if (glyph
->u
.ch
< 128
17865 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17867 /* Case of ASCII in a face known to fit ASCII. */
17868 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17872 int c1
, c2
, charset
;
17874 /* Split characters into bytes. If c2 is -1 afterwards, C is
17875 really a one-byte character so that byte1 is zero. */
17876 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17878 STORE_XCHAR2B (char2b
, c1
, c2
);
17880 STORE_XCHAR2B (char2b
, 0, c1
);
17882 /* Maybe encode the character in *CHAR2B. */
17883 if (charset
!= CHARSET_ASCII
)
17885 struct font_info
*font_info
17886 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17889 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17893 /* Make sure X resources of the face are allocated. */
17894 xassert (face
!= NULL
);
17895 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17900 /* Fill glyph string S with composition components specified by S->cmp.
17902 FACES is an array of faces for all components of this composition.
17903 S->gidx is the index of the first component for S.
17904 OVERLAPS_P non-zero means S should draw the foreground only, and
17905 use its physical height for clipping.
17907 Value is the index of a component not in S. */
17910 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17911 struct glyph_string
*s
;
17912 struct face
**faces
;
17919 s
->for_overlaps_p
= overlaps_p
;
17921 s
->face
= faces
[s
->gidx
];
17922 s
->font
= s
->face
->font
;
17923 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17925 /* For all glyphs of this composition, starting at the offset
17926 S->gidx, until we reach the end of the definition or encounter a
17927 glyph that requires the different face, add it to S. */
17929 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17932 /* All glyph strings for the same composition has the same width,
17933 i.e. the width set for the first component of the composition. */
17935 s
->width
= s
->first_glyph
->pixel_width
;
17937 /* If the specified font could not be loaded, use the frame's
17938 default font, but record the fact that we couldn't load it in
17939 the glyph string so that we can draw rectangles for the
17940 characters of the glyph string. */
17941 if (s
->font
== NULL
)
17943 s
->font_not_found_p
= 1;
17944 s
->font
= FRAME_FONT (s
->f
);
17947 /* Adjust base line for subscript/superscript text. */
17948 s
->ybase
+= s
->first_glyph
->voffset
;
17950 xassert (s
->face
&& s
->face
->gc
);
17952 /* This glyph string must always be drawn with 16-bit functions. */
17955 return s
->gidx
+ s
->nchars
;
17959 /* Fill glyph string S from a sequence of character glyphs.
17961 FACE_ID is the face id of the string. START is the index of the
17962 first glyph to consider, END is the index of the last + 1.
17963 OVERLAPS_P non-zero means S should draw the foreground only, and
17964 use its physical height for clipping.
17966 Value is the index of the first glyph not in S. */
17969 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
17970 struct glyph_string
*s
;
17972 int start
, end
, overlaps_p
;
17974 struct glyph
*glyph
, *last
;
17976 int glyph_not_available_p
;
17978 xassert (s
->f
== XFRAME (s
->w
->frame
));
17979 xassert (s
->nchars
== 0);
17980 xassert (start
>= 0 && end
> start
);
17982 s
->for_overlaps_p
= overlaps_p
,
17983 glyph
= s
->row
->glyphs
[s
->area
] + start
;
17984 last
= s
->row
->glyphs
[s
->area
] + end
;
17985 voffset
= glyph
->voffset
;
17987 glyph_not_available_p
= glyph
->glyph_not_available_p
;
17989 while (glyph
< last
17990 && glyph
->type
== CHAR_GLYPH
17991 && glyph
->voffset
== voffset
17992 /* Same face id implies same font, nowadays. */
17993 && glyph
->face_id
== face_id
17994 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
17998 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
17999 s
->char2b
+ s
->nchars
,
18001 s
->two_byte_p
= two_byte_p
;
18003 xassert (s
->nchars
<= end
- start
);
18004 s
->width
+= glyph
->pixel_width
;
18008 s
->font
= s
->face
->font
;
18009 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18011 /* If the specified font could not be loaded, use the frame's font,
18012 but record the fact that we couldn't load it in
18013 S->font_not_found_p so that we can draw rectangles for the
18014 characters of the glyph string. */
18015 if (s
->font
== NULL
|| glyph_not_available_p
)
18017 s
->font_not_found_p
= 1;
18018 s
->font
= FRAME_FONT (s
->f
);
18021 /* Adjust base line for subscript/superscript text. */
18022 s
->ybase
+= voffset
;
18024 xassert (s
->face
&& s
->face
->gc
);
18025 return glyph
- s
->row
->glyphs
[s
->area
];
18029 /* Fill glyph string S from image glyph S->first_glyph. */
18032 fill_image_glyph_string (s
)
18033 struct glyph_string
*s
;
18035 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18036 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18038 s
->slice
= s
->first_glyph
->slice
;
18039 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18040 s
->font
= s
->face
->font
;
18041 s
->width
= s
->first_glyph
->pixel_width
;
18043 /* Adjust base line for subscript/superscript text. */
18044 s
->ybase
+= s
->first_glyph
->voffset
;
18048 /* Fill glyph string S from a sequence of stretch glyphs.
18050 ROW is the glyph row in which the glyphs are found, AREA is the
18051 area within the row. START is the index of the first glyph to
18052 consider, END is the index of the last + 1.
18054 Value is the index of the first glyph not in S. */
18057 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18058 struct glyph_string
*s
;
18059 struct glyph_row
*row
;
18060 enum glyph_row_area area
;
18063 struct glyph
*glyph
, *last
;
18064 int voffset
, face_id
;
18066 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18068 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18069 last
= s
->row
->glyphs
[s
->area
] + end
;
18070 face_id
= glyph
->face_id
;
18071 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18072 s
->font
= s
->face
->font
;
18073 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18074 s
->width
= glyph
->pixel_width
;
18075 voffset
= glyph
->voffset
;
18079 && glyph
->type
== STRETCH_GLYPH
18080 && glyph
->voffset
== voffset
18081 && glyph
->face_id
== face_id
);
18083 s
->width
+= glyph
->pixel_width
;
18085 /* Adjust base line for subscript/superscript text. */
18086 s
->ybase
+= voffset
;
18088 /* The case that face->gc == 0 is handled when drawing the glyph
18089 string by calling PREPARE_FACE_FOR_DISPLAY. */
18091 return glyph
- s
->row
->glyphs
[s
->area
];
18096 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18097 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18098 assumed to be zero. */
18101 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18102 struct glyph
*glyph
;
18106 *left
= *right
= 0;
18108 if (glyph
->type
== CHAR_GLYPH
)
18112 struct font_info
*font_info
;
18116 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18118 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18119 if (font
/* ++KFS: Should this be font_info ? */
18120 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18122 if (pcm
->rbearing
> pcm
->width
)
18123 *right
= pcm
->rbearing
- pcm
->width
;
18124 if (pcm
->lbearing
< 0)
18125 *left
= -pcm
->lbearing
;
18131 /* Return the index of the first glyph preceding glyph string S that
18132 is overwritten by S because of S's left overhang. Value is -1
18133 if no glyphs are overwritten. */
18136 left_overwritten (s
)
18137 struct glyph_string
*s
;
18141 if (s
->left_overhang
)
18144 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18145 int first
= s
->first_glyph
- glyphs
;
18147 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18148 x
-= glyphs
[i
].pixel_width
;
18159 /* Return the index of the first glyph preceding glyph string S that
18160 is overwriting S because of its right overhang. Value is -1 if no
18161 glyph in front of S overwrites S. */
18164 left_overwriting (s
)
18165 struct glyph_string
*s
;
18168 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18169 int first
= s
->first_glyph
- glyphs
;
18173 for (i
= first
- 1; i
>= 0; --i
)
18176 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18179 x
-= glyphs
[i
].pixel_width
;
18186 /* Return the index of the last glyph following glyph string S that is
18187 not overwritten by S because of S's right overhang. Value is -1 if
18188 no such glyph is found. */
18191 right_overwritten (s
)
18192 struct glyph_string
*s
;
18196 if (s
->right_overhang
)
18199 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18200 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18201 int end
= s
->row
->used
[s
->area
];
18203 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18204 x
+= glyphs
[i
].pixel_width
;
18213 /* Return the index of the last glyph following glyph string S that
18214 overwrites S because of its left overhang. Value is negative
18215 if no such glyph is found. */
18218 right_overwriting (s
)
18219 struct glyph_string
*s
;
18222 int end
= s
->row
->used
[s
->area
];
18223 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18224 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18228 for (i
= first
; i
< end
; ++i
)
18231 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18234 x
+= glyphs
[i
].pixel_width
;
18241 /* Get face and two-byte form of character C in face FACE_ID on frame
18242 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18243 means we want to display multibyte text. DISPLAY_P non-zero means
18244 make sure that X resources for the face returned are allocated.
18245 Value is a pointer to a realized face that is ready for display if
18246 DISPLAY_P is non-zero. */
18248 static INLINE
struct face
*
18249 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18253 int multibyte_p
, display_p
;
18255 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18259 /* Unibyte case. We don't have to encode, but we have to make
18260 sure to use a face suitable for unibyte. */
18261 STORE_XCHAR2B (char2b
, 0, c
);
18262 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18263 face
= FACE_FROM_ID (f
, face_id
);
18265 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18267 /* Case of ASCII in a face known to fit ASCII. */
18268 STORE_XCHAR2B (char2b
, 0, c
);
18272 int c1
, c2
, charset
;
18274 /* Split characters into bytes. If c2 is -1 afterwards, C is
18275 really a one-byte character so that byte1 is zero. */
18276 SPLIT_CHAR (c
, charset
, c1
, c2
);
18278 STORE_XCHAR2B (char2b
, c1
, c2
);
18280 STORE_XCHAR2B (char2b
, 0, c1
);
18282 /* Maybe encode the character in *CHAR2B. */
18283 if (face
->font
!= NULL
)
18285 struct font_info
*font_info
18286 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18288 rif
->encode_char (c
, char2b
, font_info
, 0);
18292 /* Make sure X resources of the face are allocated. */
18293 #ifdef HAVE_X_WINDOWS
18297 xassert (face
!= NULL
);
18298 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18305 /* Set background width of glyph string S. START is the index of the
18306 first glyph following S. LAST_X is the right-most x-position + 1
18307 in the drawing area. */
18310 set_glyph_string_background_width (s
, start
, last_x
)
18311 struct glyph_string
*s
;
18315 /* If the face of this glyph string has to be drawn to the end of
18316 the drawing area, set S->extends_to_end_of_line_p. */
18317 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18319 if (start
== s
->row
->used
[s
->area
]
18320 && s
->area
== TEXT_AREA
18321 && ((s
->hl
== DRAW_NORMAL_TEXT
18322 && (s
->row
->fill_line_p
18323 || s
->face
->background
!= default_face
->background
18324 || s
->face
->stipple
!= default_face
->stipple
18325 || s
->row
->mouse_face_p
))
18326 || s
->hl
== DRAW_MOUSE_FACE
18327 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18328 && s
->row
->fill_line_p
)))
18329 s
->extends_to_end_of_line_p
= 1;
18331 /* If S extends its face to the end of the line, set its
18332 background_width to the distance to the right edge of the drawing
18334 if (s
->extends_to_end_of_line_p
)
18335 s
->background_width
= last_x
- s
->x
+ 1;
18337 s
->background_width
= s
->width
;
18341 /* Compute overhangs and x-positions for glyph string S and its
18342 predecessors, or successors. X is the starting x-position for S.
18343 BACKWARD_P non-zero means process predecessors. */
18346 compute_overhangs_and_x (s
, x
, backward_p
)
18347 struct glyph_string
*s
;
18355 if (rif
->compute_glyph_string_overhangs
)
18356 rif
->compute_glyph_string_overhangs (s
);
18366 if (rif
->compute_glyph_string_overhangs
)
18367 rif
->compute_glyph_string_overhangs (s
);
18377 /* The following macros are only called from draw_glyphs below.
18378 They reference the following parameters of that function directly:
18379 `w', `row', `area', and `overlap_p'
18380 as well as the following local variables:
18381 `s', `f', and `hdc' (in W32) */
18384 /* On W32, silently add local `hdc' variable to argument list of
18385 init_glyph_string. */
18386 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18387 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18389 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18390 init_glyph_string (s, char2b, w, row, area, start, hl)
18393 /* Add a glyph string for a stretch glyph to the list of strings
18394 between HEAD and TAIL. START is the index of the stretch glyph in
18395 row area AREA of glyph row ROW. END is the index of the last glyph
18396 in that glyph row area. X is the current output position assigned
18397 to the new glyph string constructed. HL overrides that face of the
18398 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18399 is the right-most x-position of the drawing area. */
18401 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18402 and below -- keep them on one line. */
18403 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18406 s = (struct glyph_string *) alloca (sizeof *s); \
18407 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18408 START = fill_stretch_glyph_string (s, row, area, START, END); \
18409 append_glyph_string (&HEAD, &TAIL, s); \
18415 /* Add a glyph string for an image glyph to the list of strings
18416 between HEAD and TAIL. START is the index of the image glyph in
18417 row area AREA of glyph row ROW. END is the index of the last glyph
18418 in that glyph row area. X is the current output position assigned
18419 to the new glyph string constructed. HL overrides that face of the
18420 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18421 is the right-most x-position of the drawing area. */
18423 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18426 s = (struct glyph_string *) alloca (sizeof *s); \
18427 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18428 fill_image_glyph_string (s); \
18429 append_glyph_string (&HEAD, &TAIL, s); \
18436 /* Add a glyph string for a sequence of character glyphs to the list
18437 of strings between HEAD and TAIL. START is the index of the first
18438 glyph in row area AREA of glyph row ROW that is part of the new
18439 glyph string. END is the index of the last glyph in that glyph row
18440 area. X is the current output position assigned to the new glyph
18441 string constructed. HL overrides that face of the glyph; e.g. it
18442 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18443 right-most x-position of the drawing area. */
18445 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18451 c = (row)->glyphs[area][START].u.ch; \
18452 face_id = (row)->glyphs[area][START].face_id; \
18454 s = (struct glyph_string *) alloca (sizeof *s); \
18455 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18456 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18457 append_glyph_string (&HEAD, &TAIL, s); \
18459 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18464 /* Add a glyph string for a composite sequence to the list of strings
18465 between HEAD and TAIL. START is the index of the first glyph in
18466 row area AREA of glyph row ROW that is part of the new glyph
18467 string. END is the index of the last glyph in that glyph row area.
18468 X is the current output position assigned to the new glyph string
18469 constructed. HL overrides that face of the glyph; e.g. it is
18470 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18471 x-position of the drawing area. */
18473 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18475 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18476 int face_id = (row)->glyphs[area][START].face_id; \
18477 struct face *base_face = FACE_FROM_ID (f, face_id); \
18478 struct composition *cmp = composition_table[cmp_id]; \
18479 int glyph_len = cmp->glyph_len; \
18481 struct face **faces; \
18482 struct glyph_string *first_s = NULL; \
18485 base_face = base_face->ascii_face; \
18486 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18487 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18488 /* At first, fill in `char2b' and `faces'. */ \
18489 for (n = 0; n < glyph_len; n++) \
18491 int c = COMPOSITION_GLYPH (cmp, n); \
18492 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18493 faces[n] = FACE_FROM_ID (f, this_face_id); \
18494 get_char_face_and_encoding (f, c, this_face_id, \
18495 char2b + n, 1, 1); \
18498 /* Make glyph_strings for each glyph sequence that is drawable by \
18499 the same face, and append them to HEAD/TAIL. */ \
18500 for (n = 0; n < cmp->glyph_len;) \
18502 s = (struct glyph_string *) alloca (sizeof *s); \
18503 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18504 append_glyph_string (&(HEAD), &(TAIL), s); \
18512 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18520 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18521 of AREA of glyph row ROW on window W between indices START and END.
18522 HL overrides the face for drawing glyph strings, e.g. it is
18523 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18524 x-positions of the drawing area.
18526 This is an ugly monster macro construct because we must use alloca
18527 to allocate glyph strings (because draw_glyphs can be called
18528 asynchronously). */
18530 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18533 HEAD = TAIL = NULL; \
18534 while (START < END) \
18536 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18537 switch (first_glyph->type) \
18540 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18544 case COMPOSITE_GLYPH: \
18545 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18549 case STRETCH_GLYPH: \
18550 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18554 case IMAGE_GLYPH: \
18555 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18563 set_glyph_string_background_width (s, START, LAST_X); \
18570 /* Draw glyphs between START and END in AREA of ROW on window W,
18571 starting at x-position X. X is relative to AREA in W. HL is a
18572 face-override with the following meaning:
18574 DRAW_NORMAL_TEXT draw normally
18575 DRAW_CURSOR draw in cursor face
18576 DRAW_MOUSE_FACE draw in mouse face.
18577 DRAW_INVERSE_VIDEO draw in mode line face
18578 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18579 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18581 If OVERLAPS_P is non-zero, draw only the foreground of characters
18582 and clip to the physical height of ROW.
18584 Value is the x-position reached, relative to AREA of W. */
18587 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18590 struct glyph_row
*row
;
18591 enum glyph_row_area area
;
18593 enum draw_glyphs_face hl
;
18596 struct glyph_string
*head
, *tail
;
18597 struct glyph_string
*s
;
18598 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18599 int last_x
, area_width
;
18602 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18605 ALLOCATE_HDC (hdc
, f
);
18607 /* Let's rather be paranoid than getting a SEGV. */
18608 end
= min (end
, row
->used
[area
]);
18609 start
= max (0, start
);
18610 start
= min (end
, start
);
18612 /* Translate X to frame coordinates. Set last_x to the right
18613 end of the drawing area. */
18614 if (row
->full_width_p
)
18616 /* X is relative to the left edge of W, without scroll bars
18618 x
+= WINDOW_LEFT_EDGE_X (w
);
18619 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18623 int area_left
= window_box_left (w
, area
);
18625 area_width
= window_box_width (w
, area
);
18626 last_x
= area_left
+ area_width
;
18629 /* Build a doubly-linked list of glyph_string structures between
18630 head and tail from what we have to draw. Note that the macro
18631 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18632 the reason we use a separate variable `i'. */
18634 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18636 x_reached
= tail
->x
+ tail
->background_width
;
18640 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18641 the row, redraw some glyphs in front or following the glyph
18642 strings built above. */
18643 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18646 struct glyph_string
*h
, *t
;
18648 /* Compute overhangs for all glyph strings. */
18649 if (rif
->compute_glyph_string_overhangs
)
18650 for (s
= head
; s
; s
= s
->next
)
18651 rif
->compute_glyph_string_overhangs (s
);
18653 /* Prepend glyph strings for glyphs in front of the first glyph
18654 string that are overwritten because of the first glyph
18655 string's left overhang. The background of all strings
18656 prepended must be drawn because the first glyph string
18658 i
= left_overwritten (head
);
18662 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18663 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18665 compute_overhangs_and_x (t
, head
->x
, 1);
18666 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18670 /* Prepend glyph strings for glyphs in front of the first glyph
18671 string that overwrite that glyph string because of their
18672 right overhang. For these strings, only the foreground must
18673 be drawn, because it draws over the glyph string at `head'.
18674 The background must not be drawn because this would overwrite
18675 right overhangs of preceding glyphs for which no glyph
18677 i
= left_overwriting (head
);
18681 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18682 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18683 for (s
= h
; s
; s
= s
->next
)
18684 s
->background_filled_p
= 1;
18685 compute_overhangs_and_x (t
, head
->x
, 1);
18686 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18689 /* Append glyphs strings for glyphs following the last glyph
18690 string tail that are overwritten by tail. The background of
18691 these strings has to be drawn because tail's foreground draws
18693 i
= right_overwritten (tail
);
18696 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18697 DRAW_NORMAL_TEXT
, x
, last_x
);
18698 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18699 append_glyph_string_lists (&head
, &tail
, h
, t
);
18703 /* Append glyph strings for glyphs following the last glyph
18704 string tail that overwrite tail. The foreground of such
18705 glyphs has to be drawn because it writes into the background
18706 of tail. The background must not be drawn because it could
18707 paint over the foreground of following glyphs. */
18708 i
= right_overwriting (tail
);
18712 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18713 DRAW_NORMAL_TEXT
, x
, last_x
);
18714 for (s
= h
; s
; s
= s
->next
)
18715 s
->background_filled_p
= 1;
18716 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18717 append_glyph_string_lists (&head
, &tail
, h
, t
);
18719 if (clip_head
|| clip_tail
)
18720 for (s
= head
; s
; s
= s
->next
)
18722 s
->clip_head
= clip_head
;
18723 s
->clip_tail
= clip_tail
;
18727 /* Draw all strings. */
18728 for (s
= head
; s
; s
= s
->next
)
18729 rif
->draw_glyph_string (s
);
18731 if (area
== TEXT_AREA
18732 && !row
->full_width_p
18733 /* When drawing overlapping rows, only the glyph strings'
18734 foreground is drawn, which doesn't erase a cursor
18738 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18739 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18740 : (tail
? tail
->x
+ tail
->background_width
: x
));
18742 int text_left
= window_box_left (w
, TEXT_AREA
);
18746 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18747 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18750 /* Value is the x-position up to which drawn, relative to AREA of W.
18751 This doesn't include parts drawn because of overhangs. */
18752 if (row
->full_width_p
)
18753 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18755 x_reached
-= window_box_left (w
, area
);
18757 RELEASE_HDC (hdc
, f
);
18762 /* Expand row matrix if too narrow. Don't expand if area
18765 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18767 if (!fonts_changed_p \
18768 && (it->glyph_row->glyphs[area] \
18769 < it->glyph_row->glyphs[area + 1])) \
18771 it->w->ncols_scale_factor++; \
18772 fonts_changed_p = 1; \
18776 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18777 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18783 struct glyph
*glyph
;
18784 enum glyph_row_area area
= it
->area
;
18786 xassert (it
->glyph_row
);
18787 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18789 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18790 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18792 glyph
->charpos
= CHARPOS (it
->position
);
18793 glyph
->object
= it
->object
;
18794 glyph
->pixel_width
= it
->pixel_width
;
18795 glyph
->ascent
= it
->ascent
;
18796 glyph
->descent
= it
->descent
;
18797 glyph
->voffset
= it
->voffset
;
18798 glyph
->type
= CHAR_GLYPH
;
18799 glyph
->multibyte_p
= it
->multibyte_p
;
18800 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18801 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18802 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18803 || it
->phys_descent
> it
->descent
);
18804 glyph
->padding_p
= 0;
18805 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18806 glyph
->face_id
= it
->face_id
;
18807 glyph
->u
.ch
= it
->char_to_display
;
18808 glyph
->slice
= null_glyph_slice
;
18809 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18810 ++it
->glyph_row
->used
[area
];
18813 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18816 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18817 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18820 append_composite_glyph (it
)
18823 struct glyph
*glyph
;
18824 enum glyph_row_area area
= it
->area
;
18826 xassert (it
->glyph_row
);
18828 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18829 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18831 glyph
->charpos
= CHARPOS (it
->position
);
18832 glyph
->object
= it
->object
;
18833 glyph
->pixel_width
= it
->pixel_width
;
18834 glyph
->ascent
= it
->ascent
;
18835 glyph
->descent
= it
->descent
;
18836 glyph
->voffset
= it
->voffset
;
18837 glyph
->type
= COMPOSITE_GLYPH
;
18838 glyph
->multibyte_p
= it
->multibyte_p
;
18839 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18840 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18841 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18842 || it
->phys_descent
> it
->descent
);
18843 glyph
->padding_p
= 0;
18844 glyph
->glyph_not_available_p
= 0;
18845 glyph
->face_id
= it
->face_id
;
18846 glyph
->u
.cmp_id
= it
->cmp_id
;
18847 glyph
->slice
= null_glyph_slice
;
18848 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18849 ++it
->glyph_row
->used
[area
];
18852 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18856 /* Change IT->ascent and IT->height according to the setting of
18860 take_vertical_position_into_account (it
)
18865 if (it
->voffset
< 0)
18866 /* Increase the ascent so that we can display the text higher
18868 it
->ascent
-= it
->voffset
;
18870 /* Increase the descent so that we can display the text lower
18872 it
->descent
+= it
->voffset
;
18877 /* Produce glyphs/get display metrics for the image IT is loaded with.
18878 See the description of struct display_iterator in dispextern.h for
18879 an overview of struct display_iterator. */
18882 produce_image_glyph (it
)
18888 struct glyph_slice slice
;
18890 xassert (it
->what
== IT_IMAGE
);
18892 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18894 /* Make sure X resources of the face is loaded. */
18895 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18897 if (it
->image_id
< 0)
18899 /* Fringe bitmap. */
18900 it
->ascent
= it
->phys_ascent
= 0;
18901 it
->descent
= it
->phys_descent
= 0;
18902 it
->pixel_width
= 0;
18907 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18909 /* Make sure X resources of the image is loaded. */
18910 prepare_image_for_display (it
->f
, img
);
18912 slice
.x
= slice
.y
= 0;
18913 slice
.width
= img
->width
;
18914 slice
.height
= img
->height
;
18916 if (INTEGERP (it
->slice
.x
))
18917 slice
.x
= XINT (it
->slice
.x
);
18918 else if (FLOATP (it
->slice
.x
))
18919 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18921 if (INTEGERP (it
->slice
.y
))
18922 slice
.y
= XINT (it
->slice
.y
);
18923 else if (FLOATP (it
->slice
.y
))
18924 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18926 if (INTEGERP (it
->slice
.width
))
18927 slice
.width
= XINT (it
->slice
.width
);
18928 else if (FLOATP (it
->slice
.width
))
18929 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18931 if (INTEGERP (it
->slice
.height
))
18932 slice
.height
= XINT (it
->slice
.height
);
18933 else if (FLOATP (it
->slice
.height
))
18934 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18936 if (slice
.x
>= img
->width
)
18937 slice
.x
= img
->width
;
18938 if (slice
.y
>= img
->height
)
18939 slice
.y
= img
->height
;
18940 if (slice
.x
+ slice
.width
>= img
->width
)
18941 slice
.width
= img
->width
- slice
.x
;
18942 if (slice
.y
+ slice
.height
> img
->height
)
18943 slice
.height
= img
->height
- slice
.y
;
18945 if (slice
.width
== 0 || slice
.height
== 0)
18948 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18950 it
->descent
= slice
.height
- glyph_ascent
;
18952 it
->descent
+= img
->vmargin
;
18953 if (slice
.y
+ slice
.height
== img
->height
)
18954 it
->descent
+= img
->vmargin
;
18955 it
->phys_descent
= it
->descent
;
18957 it
->pixel_width
= slice
.width
;
18959 it
->pixel_width
+= img
->hmargin
;
18960 if (slice
.x
+ slice
.width
== img
->width
)
18961 it
->pixel_width
+= img
->hmargin
;
18963 /* It's quite possible for images to have an ascent greater than
18964 their height, so don't get confused in that case. */
18965 if (it
->descent
< 0)
18968 #if 0 /* this breaks image tiling */
18969 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
18970 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
18971 if (face_ascent
> it
->ascent
)
18972 it
->ascent
= it
->phys_ascent
= face_ascent
;
18977 if (face
->box
!= FACE_NO_BOX
)
18979 if (face
->box_line_width
> 0)
18982 it
->ascent
+= face
->box_line_width
;
18983 if (slice
.y
+ slice
.height
== img
->height
)
18984 it
->descent
+= face
->box_line_width
;
18987 if (it
->start_of_box_run_p
&& slice
.x
== 0)
18988 it
->pixel_width
+= abs (face
->box_line_width
);
18989 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
18990 it
->pixel_width
+= abs (face
->box_line_width
);
18993 take_vertical_position_into_account (it
);
18997 struct glyph
*glyph
;
18998 enum glyph_row_area area
= it
->area
;
19000 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19001 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19003 glyph
->charpos
= CHARPOS (it
->position
);
19004 glyph
->object
= it
->object
;
19005 glyph
->pixel_width
= it
->pixel_width
;
19006 glyph
->ascent
= glyph_ascent
;
19007 glyph
->descent
= it
->descent
;
19008 glyph
->voffset
= it
->voffset
;
19009 glyph
->type
= IMAGE_GLYPH
;
19010 glyph
->multibyte_p
= it
->multibyte_p
;
19011 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19012 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19013 glyph
->overlaps_vertically_p
= 0;
19014 glyph
->padding_p
= 0;
19015 glyph
->glyph_not_available_p
= 0;
19016 glyph
->face_id
= it
->face_id
;
19017 glyph
->u
.img_id
= img
->id
;
19018 glyph
->slice
= slice
;
19019 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19020 ++it
->glyph_row
->used
[area
];
19023 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19028 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19029 of the glyph, WIDTH and HEIGHT are the width and height of the
19030 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19033 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19035 Lisp_Object object
;
19039 struct glyph
*glyph
;
19040 enum glyph_row_area area
= it
->area
;
19042 xassert (ascent
>= 0 && ascent
<= height
);
19044 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19045 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19047 glyph
->charpos
= CHARPOS (it
->position
);
19048 glyph
->object
= object
;
19049 glyph
->pixel_width
= width
;
19050 glyph
->ascent
= ascent
;
19051 glyph
->descent
= height
- ascent
;
19052 glyph
->voffset
= it
->voffset
;
19053 glyph
->type
= STRETCH_GLYPH
;
19054 glyph
->multibyte_p
= it
->multibyte_p
;
19055 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19056 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19057 glyph
->overlaps_vertically_p
= 0;
19058 glyph
->padding_p
= 0;
19059 glyph
->glyph_not_available_p
= 0;
19060 glyph
->face_id
= it
->face_id
;
19061 glyph
->u
.stretch
.ascent
= ascent
;
19062 glyph
->u
.stretch
.height
= height
;
19063 glyph
->slice
= null_glyph_slice
;
19064 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19065 ++it
->glyph_row
->used
[area
];
19068 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19072 /* Produce a stretch glyph for iterator IT. IT->object is the value
19073 of the glyph property displayed. The value must be a list
19074 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19077 1. `:width WIDTH' specifies that the space should be WIDTH *
19078 canonical char width wide. WIDTH may be an integer or floating
19081 2. `:relative-width FACTOR' specifies that the width of the stretch
19082 should be computed from the width of the first character having the
19083 `glyph' property, and should be FACTOR times that width.
19085 3. `:align-to HPOS' specifies that the space should be wide enough
19086 to reach HPOS, a value in canonical character units.
19088 Exactly one of the above pairs must be present.
19090 4. `:height HEIGHT' specifies that the height of the stretch produced
19091 should be HEIGHT, measured in canonical character units.
19093 5. `:relative-height FACTOR' specifies that the height of the
19094 stretch should be FACTOR times the height of the characters having
19095 the glyph property.
19097 Either none or exactly one of 4 or 5 must be present.
19099 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19100 of the stretch should be used for the ascent of the stretch.
19101 ASCENT must be in the range 0 <= ASCENT <= 100. */
19104 produce_stretch_glyph (it
)
19107 /* (space :width WIDTH :height HEIGHT ...) */
19108 Lisp_Object prop
, plist
;
19109 int width
= 0, height
= 0, align_to
= -1;
19110 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19113 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19114 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19116 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19118 /* List should start with `space'. */
19119 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19120 plist
= XCDR (it
->object
);
19122 /* Compute the width of the stretch. */
19123 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19124 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19126 /* Absolute width `:width WIDTH' specified and valid. */
19127 zero_width_ok_p
= 1;
19130 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19133 /* Relative width `:relative-width FACTOR' specified and valid.
19134 Compute the width of the characters having the `glyph'
19137 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19140 if (it
->multibyte_p
)
19142 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19143 - IT_BYTEPOS (*it
));
19144 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19147 it2
.c
= *p
, it2
.len
= 1;
19149 it2
.glyph_row
= NULL
;
19150 it2
.what
= IT_CHARACTER
;
19151 x_produce_glyphs (&it2
);
19152 width
= NUMVAL (prop
) * it2
.pixel_width
;
19154 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19155 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19157 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19158 align_to
= (align_to
< 0
19160 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19161 else if (align_to
< 0)
19162 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19163 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19164 zero_width_ok_p
= 1;
19167 /* Nothing specified -> width defaults to canonical char width. */
19168 width
= FRAME_COLUMN_WIDTH (it
->f
);
19170 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19173 /* Compute height. */
19174 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19175 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19178 zero_height_ok_p
= 1;
19180 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19182 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19184 height
= FONT_HEIGHT (font
);
19186 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19189 /* Compute percentage of height used for ascent. If
19190 `:ascent ASCENT' is present and valid, use that. Otherwise,
19191 derive the ascent from the font in use. */
19192 if (prop
= Fplist_get (plist
, QCascent
),
19193 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19194 ascent
= height
* NUMVAL (prop
) / 100.0;
19195 else if (!NILP (prop
)
19196 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19197 ascent
= min (max (0, (int)tem
), height
);
19199 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19201 if (width
> 0 && height
> 0 && it
->glyph_row
)
19203 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19204 if (!STRINGP (object
))
19205 object
= it
->w
->buffer
;
19206 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19209 it
->pixel_width
= width
;
19210 it
->ascent
= it
->phys_ascent
= ascent
;
19211 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19212 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19214 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19216 if (face
->box_line_width
> 0)
19218 it
->ascent
+= face
->box_line_width
;
19219 it
->descent
+= face
->box_line_width
;
19222 if (it
->start_of_box_run_p
)
19223 it
->pixel_width
+= abs (face
->box_line_width
);
19224 if (it
->end_of_box_run_p
)
19225 it
->pixel_width
+= abs (face
->box_line_width
);
19228 take_vertical_position_into_account (it
);
19231 /* Get line-height and line-spacing property at point.
19232 If line-height has format (HEIGHT TOTAL), return TOTAL
19233 in TOTAL_HEIGHT. */
19236 get_line_height_property (it
, prop
)
19240 Lisp_Object position
;
19242 if (STRINGP (it
->object
))
19243 position
= make_number (IT_STRING_CHARPOS (*it
));
19244 else if (BUFFERP (it
->object
))
19245 position
= make_number (IT_CHARPOS (*it
));
19249 return Fget_char_property (position
, prop
, it
->object
);
19252 /* Calculate line-height and line-spacing properties.
19253 An integer value specifies explicit pixel value.
19254 A float value specifies relative value to current face height.
19255 A cons (float . face-name) specifies relative value to
19256 height of specified face font.
19258 Returns height in pixels, or nil. */
19262 calc_line_height_property (it
, val
, font
, boff
, override
)
19266 int boff
, override
;
19268 Lisp_Object face_name
= Qnil
;
19269 int ascent
, descent
, height
;
19271 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19276 face_name
= XCAR (val
);
19278 if (!NUMBERP (val
))
19279 val
= make_number (1);
19280 if (NILP (face_name
))
19282 height
= it
->ascent
+ it
->descent
;
19287 if (NILP (face_name
))
19289 font
= FRAME_FONT (it
->f
);
19290 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19292 else if (EQ (face_name
, Qt
))
19300 struct font_info
*font_info
;
19302 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19304 return make_number (-1);
19306 face
= FACE_FROM_ID (it
->f
, face_id
);
19309 return make_number (-1);
19311 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19312 boff
= font_info
->baseline_offset
;
19313 if (font_info
->vertical_centering
)
19314 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19317 ascent
= FONT_BASE (font
) + boff
;
19318 descent
= FONT_DESCENT (font
) - boff
;
19322 it
->override_ascent
= ascent
;
19323 it
->override_descent
= descent
;
19324 it
->override_boff
= boff
;
19327 height
= ascent
+ descent
;
19331 height
= (int)(XFLOAT_DATA (val
) * height
);
19332 else if (INTEGERP (val
))
19333 height
*= XINT (val
);
19335 return make_number (height
);
19340 Produce glyphs/get display metrics for the display element IT is
19341 loaded with. See the description of struct display_iterator in
19342 dispextern.h for an overview of struct display_iterator. */
19345 x_produce_glyphs (it
)
19348 int extra_line_spacing
= it
->extra_line_spacing
;
19350 it
->glyph_not_available_p
= 0;
19352 if (it
->what
== IT_CHARACTER
)
19356 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19358 int font_not_found_p
;
19359 struct font_info
*font_info
;
19360 int boff
; /* baseline offset */
19361 /* We may change it->multibyte_p upon unibyte<->multibyte
19362 conversion. So, save the current value now and restore it
19365 Note: It seems that we don't have to record multibyte_p in
19366 struct glyph because the character code itself tells if or
19367 not the character is multibyte. Thus, in the future, we must
19368 consider eliminating the field `multibyte_p' in the struct
19370 int saved_multibyte_p
= it
->multibyte_p
;
19372 /* Maybe translate single-byte characters to multibyte, or the
19374 it
->char_to_display
= it
->c
;
19375 if (!ASCII_BYTE_P (it
->c
))
19377 if (unibyte_display_via_language_environment
19378 && SINGLE_BYTE_CHAR_P (it
->c
)
19380 || !NILP (Vnonascii_translation_table
)))
19382 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19383 it
->multibyte_p
= 1;
19384 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19385 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19387 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19388 && !it
->multibyte_p
)
19390 it
->multibyte_p
= 1;
19391 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19392 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19396 /* Get font to use. Encode IT->char_to_display. */
19397 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19398 &char2b
, it
->multibyte_p
, 0);
19401 /* When no suitable font found, use the default font. */
19402 font_not_found_p
= font
== NULL
;
19403 if (font_not_found_p
)
19405 font
= FRAME_FONT (it
->f
);
19406 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19411 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19412 boff
= font_info
->baseline_offset
;
19413 if (font_info
->vertical_centering
)
19414 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19417 if (it
->char_to_display
>= ' '
19418 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19420 /* Either unibyte or ASCII. */
19425 pcm
= rif
->per_char_metric (font
, &char2b
,
19426 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19428 if (it
->override_ascent
>= 0)
19430 it
->ascent
= it
->override_ascent
;
19431 it
->descent
= it
->override_descent
;
19432 boff
= it
->override_boff
;
19436 it
->ascent
= FONT_BASE (font
) + boff
;
19437 it
->descent
= FONT_DESCENT (font
) - boff
;
19442 it
->phys_ascent
= pcm
->ascent
+ boff
;
19443 it
->phys_descent
= pcm
->descent
- boff
;
19444 it
->pixel_width
= pcm
->width
;
19448 it
->glyph_not_available_p
= 1;
19449 it
->phys_ascent
= it
->ascent
;
19450 it
->phys_descent
= it
->descent
;
19451 it
->pixel_width
= FONT_WIDTH (font
);
19454 if (it
->constrain_row_ascent_descent_p
)
19456 if (it
->descent
> it
->max_descent
)
19458 it
->ascent
+= it
->descent
- it
->max_descent
;
19459 it
->descent
= it
->max_descent
;
19461 if (it
->ascent
> it
->max_ascent
)
19463 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19464 it
->ascent
= it
->max_ascent
;
19466 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19467 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19468 extra_line_spacing
= 0;
19471 /* If this is a space inside a region of text with
19472 `space-width' property, change its width. */
19473 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19475 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19477 /* If face has a box, add the box thickness to the character
19478 height. If character has a box line to the left and/or
19479 right, add the box line width to the character's width. */
19480 if (face
->box
!= FACE_NO_BOX
)
19482 int thick
= face
->box_line_width
;
19486 it
->ascent
+= thick
;
19487 it
->descent
+= thick
;
19492 if (it
->start_of_box_run_p
)
19493 it
->pixel_width
+= thick
;
19494 if (it
->end_of_box_run_p
)
19495 it
->pixel_width
+= thick
;
19498 /* If face has an overline, add the height of the overline
19499 (1 pixel) and a 1 pixel margin to the character height. */
19500 if (face
->overline_p
)
19503 if (it
->constrain_row_ascent_descent_p
)
19505 if (it
->ascent
> it
->max_ascent
)
19506 it
->ascent
= it
->max_ascent
;
19507 if (it
->descent
> it
->max_descent
)
19508 it
->descent
= it
->max_descent
;
19511 take_vertical_position_into_account (it
);
19513 /* If we have to actually produce glyphs, do it. */
19518 /* Translate a space with a `space-width' property
19519 into a stretch glyph. */
19520 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19521 / FONT_HEIGHT (font
));
19522 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19523 it
->ascent
+ it
->descent
, ascent
);
19528 /* If characters with lbearing or rbearing are displayed
19529 in this line, record that fact in a flag of the
19530 glyph row. This is used to optimize X output code. */
19531 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19532 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19535 else if (it
->char_to_display
== '\n')
19537 /* A newline has no width but we need the height of the line.
19538 But if previous part of the line set a height, don't
19539 increase that height */
19541 Lisp_Object height
;
19542 Lisp_Object total_height
= Qnil
;
19544 it
->override_ascent
= -1;
19545 it
->pixel_width
= 0;
19548 height
= get_line_height_property(it
, Qline_height
);
19549 /* Split (line-height total-height) list */
19551 && CONSP (XCDR (height
))
19552 && NILP (XCDR (XCDR (height
))))
19554 total_height
= XCAR (XCDR (height
));
19555 height
= XCAR (height
);
19557 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19559 if (it
->override_ascent
>= 0)
19561 it
->ascent
= it
->override_ascent
;
19562 it
->descent
= it
->override_descent
;
19563 boff
= it
->override_boff
;
19567 it
->ascent
= FONT_BASE (font
) + boff
;
19568 it
->descent
= FONT_DESCENT (font
) - boff
;
19571 if (EQ (height
, Qt
))
19573 if (it
->descent
> it
->max_descent
)
19575 it
->ascent
+= it
->descent
- it
->max_descent
;
19576 it
->descent
= it
->max_descent
;
19578 if (it
->ascent
> it
->max_ascent
)
19580 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19581 it
->ascent
= it
->max_ascent
;
19583 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19584 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19585 it
->constrain_row_ascent_descent_p
= 1;
19586 extra_line_spacing
= 0;
19590 Lisp_Object spacing
;
19592 it
->phys_ascent
= it
->ascent
;
19593 it
->phys_descent
= it
->descent
;
19595 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19596 && face
->box
!= FACE_NO_BOX
19597 && face
->box_line_width
> 0)
19599 it
->ascent
+= face
->box_line_width
;
19600 it
->descent
+= face
->box_line_width
;
19603 && XINT (height
) > it
->ascent
+ it
->descent
)
19604 it
->ascent
= XINT (height
) - it
->descent
;
19606 if (!NILP (total_height
))
19607 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19610 spacing
= get_line_height_property(it
, Qline_spacing
);
19611 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19613 if (INTEGERP (spacing
))
19615 extra_line_spacing
= XINT (spacing
);
19616 if (!NILP (total_height
))
19617 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19621 else if (it
->char_to_display
== '\t')
19623 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19624 int x
= it
->current_x
+ it
->continuation_lines_width
;
19625 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19627 /* If the distance from the current position to the next tab
19628 stop is less than a space character width, use the
19629 tab stop after that. */
19630 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19631 next_tab_x
+= tab_width
;
19633 it
->pixel_width
= next_tab_x
- x
;
19635 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19636 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19640 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19641 it
->ascent
+ it
->descent
, it
->ascent
);
19646 /* A multi-byte character. Assume that the display width of the
19647 character is the width of the character multiplied by the
19648 width of the font. */
19650 /* If we found a font, this font should give us the right
19651 metrics. If we didn't find a font, use the frame's
19652 default font and calculate the width of the character
19653 from the charset width; this is what old redisplay code
19656 pcm
= rif
->per_char_metric (font
, &char2b
,
19657 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19659 if (font_not_found_p
|| !pcm
)
19661 int charset
= CHAR_CHARSET (it
->char_to_display
);
19663 it
->glyph_not_available_p
= 1;
19664 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19665 * CHARSET_WIDTH (charset
));
19666 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19667 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19671 it
->pixel_width
= pcm
->width
;
19672 it
->phys_ascent
= pcm
->ascent
+ boff
;
19673 it
->phys_descent
= pcm
->descent
- boff
;
19675 && (pcm
->lbearing
< 0
19676 || pcm
->rbearing
> pcm
->width
))
19677 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19680 it
->ascent
= FONT_BASE (font
) + boff
;
19681 it
->descent
= FONT_DESCENT (font
) - boff
;
19682 if (face
->box
!= FACE_NO_BOX
)
19684 int thick
= face
->box_line_width
;
19688 it
->ascent
+= thick
;
19689 it
->descent
+= thick
;
19694 if (it
->start_of_box_run_p
)
19695 it
->pixel_width
+= thick
;
19696 if (it
->end_of_box_run_p
)
19697 it
->pixel_width
+= thick
;
19700 /* If face has an overline, add the height of the overline
19701 (1 pixel) and a 1 pixel margin to the character height. */
19702 if (face
->overline_p
)
19705 take_vertical_position_into_account (it
);
19710 it
->multibyte_p
= saved_multibyte_p
;
19712 else if (it
->what
== IT_COMPOSITION
)
19714 /* Note: A composition is represented as one glyph in the
19715 glyph matrix. There are no padding glyphs. */
19718 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19720 int font_not_found_p
;
19721 struct font_info
*font_info
;
19722 int boff
; /* baseline offset */
19723 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19725 /* Maybe translate single-byte characters to multibyte. */
19726 it
->char_to_display
= it
->c
;
19727 if (unibyte_display_via_language_environment
19728 && SINGLE_BYTE_CHAR_P (it
->c
)
19731 && !NILP (Vnonascii_translation_table
))))
19733 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19736 /* Get face and font to use. Encode IT->char_to_display. */
19737 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19738 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19739 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19740 &char2b
, it
->multibyte_p
, 0);
19743 /* When no suitable font found, use the default font. */
19744 font_not_found_p
= font
== NULL
;
19745 if (font_not_found_p
)
19747 font
= FRAME_FONT (it
->f
);
19748 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19753 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19754 boff
= font_info
->baseline_offset
;
19755 if (font_info
->vertical_centering
)
19756 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19759 /* There are no padding glyphs, so there is only one glyph to
19760 produce for the composition. Important is that pixel_width,
19761 ascent and descent are the values of what is drawn by
19762 draw_glyphs (i.e. the values of the overall glyphs composed). */
19765 /* If we have not yet calculated pixel size data of glyphs of
19766 the composition for the current face font, calculate them
19767 now. Theoretically, we have to check all fonts for the
19768 glyphs, but that requires much time and memory space. So,
19769 here we check only the font of the first glyph. This leads
19770 to incorrect display very rarely, and C-l (recenter) can
19771 correct the display anyway. */
19772 if (cmp
->font
!= (void *) font
)
19774 /* Ascent and descent of the font of the first character of
19775 this composition (adjusted by baseline offset). Ascent
19776 and descent of overall glyphs should not be less than
19777 them respectively. */
19778 int font_ascent
= FONT_BASE (font
) + boff
;
19779 int font_descent
= FONT_DESCENT (font
) - boff
;
19780 /* Bounding box of the overall glyphs. */
19781 int leftmost
, rightmost
, lowest
, highest
;
19782 int i
, width
, ascent
, descent
;
19784 cmp
->font
= (void *) font
;
19786 /* Initialize the bounding box. */
19788 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19789 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19791 width
= pcm
->width
;
19792 ascent
= pcm
->ascent
;
19793 descent
= pcm
->descent
;
19797 width
= FONT_WIDTH (font
);
19798 ascent
= FONT_BASE (font
);
19799 descent
= FONT_DESCENT (font
);
19803 lowest
= - descent
+ boff
;
19804 highest
= ascent
+ boff
;
19808 && font_info
->default_ascent
19809 && CHAR_TABLE_P (Vuse_default_ascent
)
19810 && !NILP (Faref (Vuse_default_ascent
,
19811 make_number (it
->char_to_display
))))
19812 highest
= font_info
->default_ascent
+ boff
;
19814 /* Draw the first glyph at the normal position. It may be
19815 shifted to right later if some other glyphs are drawn at
19817 cmp
->offsets
[0] = 0;
19818 cmp
->offsets
[1] = boff
;
19820 /* Set cmp->offsets for the remaining glyphs. */
19821 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19823 int left
, right
, btm
, top
;
19824 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19825 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19827 face
= FACE_FROM_ID (it
->f
, face_id
);
19828 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19829 &char2b
, it
->multibyte_p
, 0);
19833 font
= FRAME_FONT (it
->f
);
19834 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19840 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19841 boff
= font_info
->baseline_offset
;
19842 if (font_info
->vertical_centering
)
19843 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19847 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19848 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19850 width
= pcm
->width
;
19851 ascent
= pcm
->ascent
;
19852 descent
= pcm
->descent
;
19856 width
= FONT_WIDTH (font
);
19861 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19863 /* Relative composition with or without
19864 alternate chars. */
19865 left
= (leftmost
+ rightmost
- width
) / 2;
19866 btm
= - descent
+ boff
;
19867 if (font_info
&& font_info
->relative_compose
19868 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19869 || NILP (Faref (Vignore_relative_composition
,
19870 make_number (ch
)))))
19873 if (- descent
>= font_info
->relative_compose
)
19874 /* One extra pixel between two glyphs. */
19876 else if (ascent
<= 0)
19877 /* One extra pixel between two glyphs. */
19878 btm
= lowest
- 1 - ascent
- descent
;
19883 /* A composition rule is specified by an integer
19884 value that encodes global and new reference
19885 points (GREF and NREF). GREF and NREF are
19886 specified by numbers as below:
19888 0---1---2 -- ascent
19892 9--10--11 -- center
19894 ---3---4---5--- baseline
19896 6---7---8 -- descent
19898 int rule
= COMPOSITION_RULE (cmp
, i
);
19899 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19901 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19902 grefx
= gref
% 3, nrefx
= nref
% 3;
19903 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19906 + grefx
* (rightmost
- leftmost
) / 2
19907 - nrefx
* width
/ 2);
19908 btm
= ((grefy
== 0 ? highest
19910 : grefy
== 2 ? lowest
19911 : (highest
+ lowest
) / 2)
19912 - (nrefy
== 0 ? ascent
+ descent
19913 : nrefy
== 1 ? descent
- boff
19915 : (ascent
+ descent
) / 2));
19918 cmp
->offsets
[i
* 2] = left
;
19919 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19921 /* Update the bounding box of the overall glyphs. */
19922 right
= left
+ width
;
19923 top
= btm
+ descent
+ ascent
;
19924 if (left
< leftmost
)
19926 if (right
> rightmost
)
19934 /* If there are glyphs whose x-offsets are negative,
19935 shift all glyphs to the right and make all x-offsets
19939 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19940 cmp
->offsets
[i
* 2] -= leftmost
;
19941 rightmost
-= leftmost
;
19944 cmp
->pixel_width
= rightmost
;
19945 cmp
->ascent
= highest
;
19946 cmp
->descent
= - lowest
;
19947 if (cmp
->ascent
< font_ascent
)
19948 cmp
->ascent
= font_ascent
;
19949 if (cmp
->descent
< font_descent
)
19950 cmp
->descent
= font_descent
;
19953 it
->pixel_width
= cmp
->pixel_width
;
19954 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
19955 it
->descent
= it
->phys_descent
= cmp
->descent
;
19957 if (face
->box
!= FACE_NO_BOX
)
19959 int thick
= face
->box_line_width
;
19963 it
->ascent
+= thick
;
19964 it
->descent
+= thick
;
19969 if (it
->start_of_box_run_p
)
19970 it
->pixel_width
+= thick
;
19971 if (it
->end_of_box_run_p
)
19972 it
->pixel_width
+= thick
;
19975 /* If face has an overline, add the height of the overline
19976 (1 pixel) and a 1 pixel margin to the character height. */
19977 if (face
->overline_p
)
19980 take_vertical_position_into_account (it
);
19983 append_composite_glyph (it
);
19985 else if (it
->what
== IT_IMAGE
)
19986 produce_image_glyph (it
);
19987 else if (it
->what
== IT_STRETCH
)
19988 produce_stretch_glyph (it
);
19990 /* Accumulate dimensions. Note: can't assume that it->descent > 0
19991 because this isn't true for images with `:ascent 100'. */
19992 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
19993 if (it
->area
== TEXT_AREA
)
19994 it
->current_x
+= it
->pixel_width
;
19996 if (extra_line_spacing
> 0)
19998 it
->descent
+= extra_line_spacing
;
19999 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20000 it
->max_extra_line_spacing
= extra_line_spacing
;
20003 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20004 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20005 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20006 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20010 Output LEN glyphs starting at START at the nominal cursor position.
20011 Advance the nominal cursor over the text. The global variable
20012 updated_window contains the window being updated, updated_row is
20013 the glyph row being updated, and updated_area is the area of that
20014 row being updated. */
20017 x_write_glyphs (start
, len
)
20018 struct glyph
*start
;
20023 xassert (updated_window
&& updated_row
);
20026 /* Write glyphs. */
20028 hpos
= start
- updated_row
->glyphs
[updated_area
];
20029 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20030 updated_row
, updated_area
,
20032 DRAW_NORMAL_TEXT
, 0);
20034 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20035 if (updated_area
== TEXT_AREA
20036 && updated_window
->phys_cursor_on_p
20037 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20038 && updated_window
->phys_cursor
.hpos
>= hpos
20039 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20040 updated_window
->phys_cursor_on_p
= 0;
20044 /* Advance the output cursor. */
20045 output_cursor
.hpos
+= len
;
20046 output_cursor
.x
= x
;
20051 Insert LEN glyphs from START at the nominal cursor position. */
20054 x_insert_glyphs (start
, len
)
20055 struct glyph
*start
;
20060 int line_height
, shift_by_width
, shifted_region_width
;
20061 struct glyph_row
*row
;
20062 struct glyph
*glyph
;
20063 int frame_x
, frame_y
, hpos
;
20065 xassert (updated_window
&& updated_row
);
20067 w
= updated_window
;
20068 f
= XFRAME (WINDOW_FRAME (w
));
20070 /* Get the height of the line we are in. */
20072 line_height
= row
->height
;
20074 /* Get the width of the glyphs to insert. */
20075 shift_by_width
= 0;
20076 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20077 shift_by_width
+= glyph
->pixel_width
;
20079 /* Get the width of the region to shift right. */
20080 shifted_region_width
= (window_box_width (w
, updated_area
)
20085 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20086 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20088 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20089 line_height
, shift_by_width
);
20091 /* Write the glyphs. */
20092 hpos
= start
- row
->glyphs
[updated_area
];
20093 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20095 DRAW_NORMAL_TEXT
, 0);
20097 /* Advance the output cursor. */
20098 output_cursor
.hpos
+= len
;
20099 output_cursor
.x
+= shift_by_width
;
20105 Erase the current text line from the nominal cursor position
20106 (inclusive) to pixel column TO_X (exclusive). The idea is that
20107 everything from TO_X onward is already erased.
20109 TO_X is a pixel position relative to updated_area of
20110 updated_window. TO_X == -1 means clear to the end of this area. */
20113 x_clear_end_of_line (to_x
)
20117 struct window
*w
= updated_window
;
20118 int max_x
, min_y
, max_y
;
20119 int from_x
, from_y
, to_y
;
20121 xassert (updated_window
&& updated_row
);
20122 f
= XFRAME (w
->frame
);
20124 if (updated_row
->full_width_p
)
20125 max_x
= WINDOW_TOTAL_WIDTH (w
);
20127 max_x
= window_box_width (w
, updated_area
);
20128 max_y
= window_text_bottom_y (w
);
20130 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20131 of window. For TO_X > 0, truncate to end of drawing area. */
20137 to_x
= min (to_x
, max_x
);
20139 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20141 /* Notice if the cursor will be cleared by this operation. */
20142 if (!updated_row
->full_width_p
)
20143 notice_overwritten_cursor (w
, updated_area
,
20144 output_cursor
.x
, -1,
20146 MATRIX_ROW_BOTTOM_Y (updated_row
));
20148 from_x
= output_cursor
.x
;
20150 /* Translate to frame coordinates. */
20151 if (updated_row
->full_width_p
)
20153 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20154 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20158 int area_left
= window_box_left (w
, updated_area
);
20159 from_x
+= area_left
;
20163 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20164 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20165 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20167 /* Prevent inadvertently clearing to end of the X window. */
20168 if (to_x
> from_x
&& to_y
> from_y
)
20171 rif
->clear_frame_area (f
, from_x
, from_y
,
20172 to_x
- from_x
, to_y
- from_y
);
20177 #endif /* HAVE_WINDOW_SYSTEM */
20181 /***********************************************************************
20183 ***********************************************************************/
20185 /* Value is the internal representation of the specified cursor type
20186 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20187 of the bar cursor. */
20189 static enum text_cursor_kinds
20190 get_specified_cursor_type (arg
, width
)
20194 enum text_cursor_kinds type
;
20199 if (EQ (arg
, Qbox
))
20200 return FILLED_BOX_CURSOR
;
20202 if (EQ (arg
, Qhollow
))
20203 return HOLLOW_BOX_CURSOR
;
20205 if (EQ (arg
, Qbar
))
20212 && EQ (XCAR (arg
), Qbar
)
20213 && INTEGERP (XCDR (arg
))
20214 && XINT (XCDR (arg
)) >= 0)
20216 *width
= XINT (XCDR (arg
));
20220 if (EQ (arg
, Qhbar
))
20223 return HBAR_CURSOR
;
20227 && EQ (XCAR (arg
), Qhbar
)
20228 && INTEGERP (XCDR (arg
))
20229 && XINT (XCDR (arg
)) >= 0)
20231 *width
= XINT (XCDR (arg
));
20232 return HBAR_CURSOR
;
20235 /* Treat anything unknown as "hollow box cursor".
20236 It was bad to signal an error; people have trouble fixing
20237 .Xdefaults with Emacs, when it has something bad in it. */
20238 type
= HOLLOW_BOX_CURSOR
;
20243 /* Set the default cursor types for specified frame. */
20245 set_frame_cursor_types (f
, arg
)
20252 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20253 FRAME_CURSOR_WIDTH (f
) = width
;
20255 /* By default, set up the blink-off state depending on the on-state. */
20257 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20260 FRAME_BLINK_OFF_CURSOR (f
)
20261 = get_specified_cursor_type (XCDR (tem
), &width
);
20262 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20265 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20269 /* Return the cursor we want to be displayed in window W. Return
20270 width of bar/hbar cursor through WIDTH arg. Return with
20271 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20272 (i.e. if the `system caret' should track this cursor).
20274 In a mini-buffer window, we want the cursor only to appear if we
20275 are reading input from this window. For the selected window, we
20276 want the cursor type given by the frame parameter or buffer local
20277 setting of cursor-type. If explicitly marked off, draw no cursor.
20278 In all other cases, we want a hollow box cursor. */
20280 static enum text_cursor_kinds
20281 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20283 struct glyph
*glyph
;
20285 int *active_cursor
;
20287 struct frame
*f
= XFRAME (w
->frame
);
20288 struct buffer
*b
= XBUFFER (w
->buffer
);
20289 int cursor_type
= DEFAULT_CURSOR
;
20290 Lisp_Object alt_cursor
;
20291 int non_selected
= 0;
20293 *active_cursor
= 1;
20296 if (cursor_in_echo_area
20297 && FRAME_HAS_MINIBUF_P (f
)
20298 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20300 if (w
== XWINDOW (echo_area_window
))
20302 *width
= FRAME_CURSOR_WIDTH (f
);
20303 return FRAME_DESIRED_CURSOR (f
);
20306 *active_cursor
= 0;
20310 /* Nonselected window or nonselected frame. */
20311 else if (w
!= XWINDOW (f
->selected_window
)
20312 #ifdef HAVE_WINDOW_SYSTEM
20313 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20317 *active_cursor
= 0;
20319 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20325 /* Never display a cursor in a window in which cursor-type is nil. */
20326 if (NILP (b
->cursor_type
))
20329 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20332 alt_cursor
= XBUFFER (w
->buffer
)->cursor_in_non_selected_windows
;
20333 return get_specified_cursor_type (alt_cursor
, width
);
20336 /* Get the normal cursor type for this window. */
20337 if (EQ (b
->cursor_type
, Qt
))
20339 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20340 *width
= FRAME_CURSOR_WIDTH (f
);
20343 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20345 /* Use normal cursor if not blinked off. */
20346 if (!w
->cursor_off_p
)
20348 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20349 if (cursor_type
== FILLED_BOX_CURSOR
)
20350 cursor_type
= HOLLOW_BOX_CURSOR
;
20352 return cursor_type
;
20355 /* Cursor is blinked off, so determine how to "toggle" it. */
20357 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20358 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20359 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20361 /* Then see if frame has specified a specific blink off cursor type. */
20362 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20364 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20365 return FRAME_BLINK_OFF_CURSOR (f
);
20369 /* Some people liked having a permanently visible blinking cursor,
20370 while others had very strong opinions against it. So it was
20371 decided to remove it. KFS 2003-09-03 */
20373 /* Finally perform built-in cursor blinking:
20374 filled box <-> hollow box
20375 wide [h]bar <-> narrow [h]bar
20376 narrow [h]bar <-> no cursor
20377 other type <-> no cursor */
20379 if (cursor_type
== FILLED_BOX_CURSOR
)
20380 return HOLLOW_BOX_CURSOR
;
20382 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20385 return cursor_type
;
20393 #ifdef HAVE_WINDOW_SYSTEM
20395 /* Notice when the text cursor of window W has been completely
20396 overwritten by a drawing operation that outputs glyphs in AREA
20397 starting at X0 and ending at X1 in the line starting at Y0 and
20398 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20399 the rest of the line after X0 has been written. Y coordinates
20400 are window-relative. */
20403 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20405 enum glyph_row_area area
;
20406 int x0
, y0
, x1
, y1
;
20408 int cx0
, cx1
, cy0
, cy1
;
20409 struct glyph_row
*row
;
20411 if (!w
->phys_cursor_on_p
)
20413 if (area
!= TEXT_AREA
)
20416 if (w
->phys_cursor
.vpos
< 0
20417 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20418 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20419 !(row
->enabled_p
&& row
->displays_text_p
)))
20422 if (row
->cursor_in_fringe_p
)
20424 row
->cursor_in_fringe_p
= 0;
20425 draw_fringe_bitmap (w
, row
, 0);
20426 w
->phys_cursor_on_p
= 0;
20430 cx0
= w
->phys_cursor
.x
;
20431 cx1
= cx0
+ w
->phys_cursor_width
;
20432 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20435 /* The cursor image will be completely removed from the
20436 screen if the output area intersects the cursor area in
20437 y-direction. When we draw in [y0 y1[, and some part of
20438 the cursor is at y < y0, that part must have been drawn
20439 before. When scrolling, the cursor is erased before
20440 actually scrolling, so we don't come here. When not
20441 scrolling, the rows above the old cursor row must have
20442 changed, and in this case these rows must have written
20443 over the cursor image.
20445 Likewise if part of the cursor is below y1, with the
20446 exception of the cursor being in the first blank row at
20447 the buffer and window end because update_text_area
20448 doesn't draw that row. (Except when it does, but
20449 that's handled in update_text_area.) */
20451 cy0
= w
->phys_cursor
.y
;
20452 cy1
= cy0
+ w
->phys_cursor_height
;
20453 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20456 w
->phys_cursor_on_p
= 0;
20459 #endif /* HAVE_WINDOW_SYSTEM */
20462 /************************************************************************
20464 ************************************************************************/
20466 #ifdef HAVE_WINDOW_SYSTEM
20469 Fix the display of area AREA of overlapping row ROW in window W. */
20472 x_fix_overlapping_area (w
, row
, area
)
20474 struct glyph_row
*row
;
20475 enum glyph_row_area area
;
20482 for (i
= 0; i
< row
->used
[area
];)
20484 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20486 int start
= i
, start_x
= x
;
20490 x
+= row
->glyphs
[area
][i
].pixel_width
;
20493 while (i
< row
->used
[area
]
20494 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20496 draw_glyphs (w
, start_x
, row
, area
,
20498 DRAW_NORMAL_TEXT
, 1);
20502 x
+= row
->glyphs
[area
][i
].pixel_width
;
20512 Draw the cursor glyph of window W in glyph row ROW. See the
20513 comment of draw_glyphs for the meaning of HL. */
20516 draw_phys_cursor_glyph (w
, row
, hl
)
20518 struct glyph_row
*row
;
20519 enum draw_glyphs_face hl
;
20521 /* If cursor hpos is out of bounds, don't draw garbage. This can
20522 happen in mini-buffer windows when switching between echo area
20523 glyphs and mini-buffer. */
20524 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20526 int on_p
= w
->phys_cursor_on_p
;
20528 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20529 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20531 w
->phys_cursor_on_p
= on_p
;
20533 if (hl
== DRAW_CURSOR
)
20534 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20535 /* When we erase the cursor, and ROW is overlapped by other
20536 rows, make sure that these overlapping parts of other rows
20538 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20540 if (row
> w
->current_matrix
->rows
20541 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20542 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20544 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20545 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20546 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20553 Erase the image of a cursor of window W from the screen. */
20556 erase_phys_cursor (w
)
20559 struct frame
*f
= XFRAME (w
->frame
);
20560 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20561 int hpos
= w
->phys_cursor
.hpos
;
20562 int vpos
= w
->phys_cursor
.vpos
;
20563 int mouse_face_here_p
= 0;
20564 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20565 struct glyph_row
*cursor_row
;
20566 struct glyph
*cursor_glyph
;
20567 enum draw_glyphs_face hl
;
20569 /* No cursor displayed or row invalidated => nothing to do on the
20571 if (w
->phys_cursor_type
== NO_CURSOR
)
20572 goto mark_cursor_off
;
20574 /* VPOS >= active_glyphs->nrows means that window has been resized.
20575 Don't bother to erase the cursor. */
20576 if (vpos
>= active_glyphs
->nrows
)
20577 goto mark_cursor_off
;
20579 /* If row containing cursor is marked invalid, there is nothing we
20581 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20582 if (!cursor_row
->enabled_p
)
20583 goto mark_cursor_off
;
20585 /* If line spacing is > 0, old cursor may only be partially visible in
20586 window after split-window. So adjust visible height. */
20587 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20588 window_text_bottom_y (w
) - cursor_row
->y
);
20590 /* If row is completely invisible, don't attempt to delete a cursor which
20591 isn't there. This can happen if cursor is at top of a window, and
20592 we switch to a buffer with a header line in that window. */
20593 if (cursor_row
->visible_height
<= 0)
20594 goto mark_cursor_off
;
20596 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20597 if (cursor_row
->cursor_in_fringe_p
)
20599 cursor_row
->cursor_in_fringe_p
= 0;
20600 draw_fringe_bitmap (w
, cursor_row
, 0);
20601 goto mark_cursor_off
;
20604 /* This can happen when the new row is shorter than the old one.
20605 In this case, either draw_glyphs or clear_end_of_line
20606 should have cleared the cursor. Note that we wouldn't be
20607 able to erase the cursor in this case because we don't have a
20608 cursor glyph at hand. */
20609 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20610 goto mark_cursor_off
;
20612 /* If the cursor is in the mouse face area, redisplay that when
20613 we clear the cursor. */
20614 if (! NILP (dpyinfo
->mouse_face_window
)
20615 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20616 && (vpos
> dpyinfo
->mouse_face_beg_row
20617 || (vpos
== dpyinfo
->mouse_face_beg_row
20618 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20619 && (vpos
< dpyinfo
->mouse_face_end_row
20620 || (vpos
== dpyinfo
->mouse_face_end_row
20621 && hpos
< dpyinfo
->mouse_face_end_col
))
20622 /* Don't redraw the cursor's spot in mouse face if it is at the
20623 end of a line (on a newline). The cursor appears there, but
20624 mouse highlighting does not. */
20625 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20626 mouse_face_here_p
= 1;
20628 /* Maybe clear the display under the cursor. */
20629 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20632 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20635 cursor_glyph
= get_phys_cursor_glyph (w
);
20636 if (cursor_glyph
== NULL
)
20637 goto mark_cursor_off
;
20639 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20640 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20641 width
= min (cursor_glyph
->pixel_width
,
20642 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20644 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20647 /* Erase the cursor by redrawing the character underneath it. */
20648 if (mouse_face_here_p
)
20649 hl
= DRAW_MOUSE_FACE
;
20651 hl
= DRAW_NORMAL_TEXT
;
20652 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20655 w
->phys_cursor_on_p
= 0;
20656 w
->phys_cursor_type
= NO_CURSOR
;
20661 Display or clear cursor of window W. If ON is zero, clear the
20662 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20663 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20666 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20668 int on
, hpos
, vpos
, x
, y
;
20670 struct frame
*f
= XFRAME (w
->frame
);
20671 int new_cursor_type
;
20672 int new_cursor_width
;
20674 struct glyph_row
*glyph_row
;
20675 struct glyph
*glyph
;
20677 /* This is pointless on invisible frames, and dangerous on garbaged
20678 windows and frames; in the latter case, the frame or window may
20679 be in the midst of changing its size, and x and y may be off the
20681 if (! FRAME_VISIBLE_P (f
)
20682 || FRAME_GARBAGED_P (f
)
20683 || vpos
>= w
->current_matrix
->nrows
20684 || hpos
>= w
->current_matrix
->matrix_w
)
20687 /* If cursor is off and we want it off, return quickly. */
20688 if (!on
&& !w
->phys_cursor_on_p
)
20691 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20692 /* If cursor row is not enabled, we don't really know where to
20693 display the cursor. */
20694 if (!glyph_row
->enabled_p
)
20696 w
->phys_cursor_on_p
= 0;
20701 if (!glyph_row
->exact_window_width_line_p
20702 || hpos
< glyph_row
->used
[TEXT_AREA
])
20703 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20705 xassert (interrupt_input_blocked
);
20707 /* Set new_cursor_type to the cursor we want to be displayed. */
20708 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20709 &new_cursor_width
, &active_cursor
);
20711 /* If cursor is currently being shown and we don't want it to be or
20712 it is in the wrong place, or the cursor type is not what we want,
20714 if (w
->phys_cursor_on_p
20716 || w
->phys_cursor
.x
!= x
20717 || w
->phys_cursor
.y
!= y
20718 || new_cursor_type
!= w
->phys_cursor_type
20719 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20720 && new_cursor_width
!= w
->phys_cursor_width
)))
20721 erase_phys_cursor (w
);
20723 /* Don't check phys_cursor_on_p here because that flag is only set
20724 to zero in some cases where we know that the cursor has been
20725 completely erased, to avoid the extra work of erasing the cursor
20726 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20727 still not be visible, or it has only been partly erased. */
20730 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20731 w
->phys_cursor_height
= glyph_row
->height
;
20733 /* Set phys_cursor_.* before x_draw_.* is called because some
20734 of them may need the information. */
20735 w
->phys_cursor
.x
= x
;
20736 w
->phys_cursor
.y
= glyph_row
->y
;
20737 w
->phys_cursor
.hpos
= hpos
;
20738 w
->phys_cursor
.vpos
= vpos
;
20741 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20742 new_cursor_type
, new_cursor_width
,
20743 on
, active_cursor
);
20747 /* Switch the display of W's cursor on or off, according to the value
20751 update_window_cursor (w
, on
)
20755 /* Don't update cursor in windows whose frame is in the process
20756 of being deleted. */
20757 if (w
->current_matrix
)
20760 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20761 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20767 /* Call update_window_cursor with parameter ON_P on all leaf windows
20768 in the window tree rooted at W. */
20771 update_cursor_in_window_tree (w
, on_p
)
20777 if (!NILP (w
->hchild
))
20778 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20779 else if (!NILP (w
->vchild
))
20780 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20782 update_window_cursor (w
, on_p
);
20784 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20790 Display the cursor on window W, or clear it, according to ON_P.
20791 Don't change the cursor's position. */
20794 x_update_cursor (f
, on_p
)
20798 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20803 Clear the cursor of window W to background color, and mark the
20804 cursor as not shown. This is used when the text where the cursor
20805 is is about to be rewritten. */
20811 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20812 update_window_cursor (w
, 0);
20817 Display the active region described by mouse_face_* according to DRAW. */
20820 show_mouse_face (dpyinfo
, draw
)
20821 Display_Info
*dpyinfo
;
20822 enum draw_glyphs_face draw
;
20824 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20825 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20827 if (/* If window is in the process of being destroyed, don't bother
20829 w
->current_matrix
!= NULL
20830 /* Don't update mouse highlight if hidden */
20831 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20832 /* Recognize when we are called to operate on rows that don't exist
20833 anymore. This can happen when a window is split. */
20834 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20836 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20837 struct glyph_row
*row
, *first
, *last
;
20839 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20840 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20842 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20844 int start_hpos
, end_hpos
, start_x
;
20846 /* For all but the first row, the highlight starts at column 0. */
20849 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20850 start_x
= dpyinfo
->mouse_face_beg_x
;
20859 end_hpos
= dpyinfo
->mouse_face_end_col
;
20861 end_hpos
= row
->used
[TEXT_AREA
];
20863 if (end_hpos
> start_hpos
)
20865 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20866 start_hpos
, end_hpos
,
20870 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20874 /* When we've written over the cursor, arrange for it to
20875 be displayed again. */
20876 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20879 display_and_set_cursor (w
, 1,
20880 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20881 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20886 /* Change the mouse cursor. */
20887 if (draw
== DRAW_NORMAL_TEXT
)
20888 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20889 else if (draw
== DRAW_MOUSE_FACE
)
20890 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20892 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20896 Clear out the mouse-highlighted active region.
20897 Redraw it un-highlighted first. Value is non-zero if mouse
20898 face was actually drawn unhighlighted. */
20901 clear_mouse_face (dpyinfo
)
20902 Display_Info
*dpyinfo
;
20906 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20908 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20912 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20913 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20914 dpyinfo
->mouse_face_window
= Qnil
;
20915 dpyinfo
->mouse_face_overlay
= Qnil
;
20921 Non-zero if physical cursor of window W is within mouse face. */
20924 cursor_in_mouse_face_p (w
)
20927 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20928 int in_mouse_face
= 0;
20930 if (WINDOWP (dpyinfo
->mouse_face_window
)
20931 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20933 int hpos
= w
->phys_cursor
.hpos
;
20934 int vpos
= w
->phys_cursor
.vpos
;
20936 if (vpos
>= dpyinfo
->mouse_face_beg_row
20937 && vpos
<= dpyinfo
->mouse_face_end_row
20938 && (vpos
> dpyinfo
->mouse_face_beg_row
20939 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20940 && (vpos
< dpyinfo
->mouse_face_end_row
20941 || hpos
< dpyinfo
->mouse_face_end_col
20942 || dpyinfo
->mouse_face_past_end
))
20946 return in_mouse_face
;
20952 /* Find the glyph matrix position of buffer position CHARPOS in window
20953 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20954 current glyphs must be up to date. If CHARPOS is above window
20955 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
20956 of last line in W. In the row containing CHARPOS, stop before glyphs
20957 having STOP as object. */
20959 #if 1 /* This is a version of fast_find_position that's more correct
20960 in the presence of hscrolling, for example. I didn't install
20961 it right away because the problem fixed is minor, it failed
20962 in 20.x as well, and I think it's too risky to install
20963 so near the release of 21.1. 2001-09-25 gerd. */
20966 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
20969 int *hpos
, *vpos
, *x
, *y
;
20972 struct glyph_row
*row
, *first
;
20973 struct glyph
*glyph
, *end
;
20976 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
20977 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
20982 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
20986 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
20989 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
20993 /* If whole rows or last part of a row came from a display overlay,
20994 row_containing_pos will skip over such rows because their end pos
20995 equals the start pos of the overlay or interval.
20997 Move back if we have a STOP object and previous row's
20998 end glyph came from STOP. */
21001 struct glyph_row
*prev
;
21002 while ((prev
= row
- 1, prev
>= first
)
21003 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21004 && prev
->used
[TEXT_AREA
] > 0)
21006 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21007 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21008 while (--glyph
>= beg
21009 && INTEGERP (glyph
->object
));
21011 || !EQ (stop
, glyph
->object
))
21019 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21021 glyph
= row
->glyphs
[TEXT_AREA
];
21022 end
= glyph
+ row
->used
[TEXT_AREA
];
21024 /* Skip over glyphs not having an object at the start of the row.
21025 These are special glyphs like truncation marks on terminal
21027 if (row
->displays_text_p
)
21029 && INTEGERP (glyph
->object
)
21030 && !EQ (stop
, glyph
->object
)
21031 && glyph
->charpos
< 0)
21033 *x
+= glyph
->pixel_width
;
21038 && !INTEGERP (glyph
->object
)
21039 && !EQ (stop
, glyph
->object
)
21040 && (!BUFFERP (glyph
->object
)
21041 || glyph
->charpos
< charpos
))
21043 *x
+= glyph
->pixel_width
;
21047 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21054 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21057 int *hpos
, *vpos
, *x
, *y
;
21062 int maybe_next_line_p
= 0;
21063 int line_start_position
;
21064 int yb
= window_text_bottom_y (w
);
21065 struct glyph_row
*row
, *best_row
;
21066 int row_vpos
, best_row_vpos
;
21069 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21070 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21072 while (row
->y
< yb
)
21074 if (row
->used
[TEXT_AREA
])
21075 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21077 line_start_position
= 0;
21079 if (line_start_position
> pos
)
21081 /* If the position sought is the end of the buffer,
21082 don't include the blank lines at the bottom of the window. */
21083 else if (line_start_position
== pos
21084 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21086 maybe_next_line_p
= 1;
21089 else if (line_start_position
> 0)
21092 best_row_vpos
= row_vpos
;
21095 if (row
->y
+ row
->height
>= yb
)
21102 /* Find the right column within BEST_ROW. */
21104 current_x
= best_row
->x
;
21105 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21107 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21108 int charpos
= glyph
->charpos
;
21110 if (BUFFERP (glyph
->object
))
21112 if (charpos
== pos
)
21115 *vpos
= best_row_vpos
;
21120 else if (charpos
> pos
)
21123 else if (EQ (glyph
->object
, stop
))
21128 current_x
+= glyph
->pixel_width
;
21131 /* If we're looking for the end of the buffer,
21132 and we didn't find it in the line we scanned,
21133 use the start of the following line. */
21134 if (maybe_next_line_p
)
21139 current_x
= best_row
->x
;
21142 *vpos
= best_row_vpos
;
21143 *hpos
= lastcol
+ 1;
21152 /* Find the position of the glyph for position POS in OBJECT in
21153 window W's current matrix, and return in *X, *Y the pixel
21154 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21156 RIGHT_P non-zero means return the position of the right edge of the
21157 glyph, RIGHT_P zero means return the left edge position.
21159 If no glyph for POS exists in the matrix, return the position of
21160 the glyph with the next smaller position that is in the matrix, if
21161 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21162 exists in the matrix, return the position of the glyph with the
21163 next larger position in OBJECT.
21165 Value is non-zero if a glyph was found. */
21168 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21171 Lisp_Object object
;
21172 int *hpos
, *vpos
, *x
, *y
;
21175 int yb
= window_text_bottom_y (w
);
21176 struct glyph_row
*r
;
21177 struct glyph
*best_glyph
= NULL
;
21178 struct glyph_row
*best_row
= NULL
;
21181 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21182 r
->enabled_p
&& r
->y
< yb
;
21185 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21186 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21189 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21190 if (EQ (g
->object
, object
))
21192 if (g
->charpos
== pos
)
21199 else if (best_glyph
== NULL
21200 || ((abs (g
->charpos
- pos
)
21201 < abs (best_glyph
->charpos
- pos
))
21204 : g
->charpos
> pos
)))
21218 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21222 *x
+= best_glyph
->pixel_width
;
21227 *vpos
= best_row
- w
->current_matrix
->rows
;
21230 return best_glyph
!= NULL
;
21234 /* See if position X, Y is within a hot-spot of an image. */
21237 on_hot_spot_p (hot_spot
, x
, y
)
21238 Lisp_Object hot_spot
;
21241 if (!CONSP (hot_spot
))
21244 if (EQ (XCAR (hot_spot
), Qrect
))
21246 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21247 Lisp_Object rect
= XCDR (hot_spot
);
21251 if (!CONSP (XCAR (rect
)))
21253 if (!CONSP (XCDR (rect
)))
21255 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21257 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21259 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21261 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21265 else if (EQ (XCAR (hot_spot
), Qcircle
))
21267 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21268 Lisp_Object circ
= XCDR (hot_spot
);
21269 Lisp_Object lr
, lx0
, ly0
;
21271 && CONSP (XCAR (circ
))
21272 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21273 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21274 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21276 double r
= XFLOATINT (lr
);
21277 double dx
= XINT (lx0
) - x
;
21278 double dy
= XINT (ly0
) - y
;
21279 return (dx
* dx
+ dy
* dy
<= r
* r
);
21282 else if (EQ (XCAR (hot_spot
), Qpoly
))
21284 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21285 if (VECTORP (XCDR (hot_spot
)))
21287 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21288 Lisp_Object
*poly
= v
->contents
;
21292 Lisp_Object lx
, ly
;
21295 /* Need an even number of coordinates, and at least 3 edges. */
21296 if (n
< 6 || n
& 1)
21299 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21300 If count is odd, we are inside polygon. Pixels on edges
21301 may or may not be included depending on actual geometry of the
21303 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21304 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21306 x0
= XINT (lx
), y0
= XINT (ly
);
21307 for (i
= 0; i
< n
; i
+= 2)
21309 int x1
= x0
, y1
= y0
;
21310 if ((lx
= poly
[i
], !INTEGERP (lx
))
21311 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21313 x0
= XINT (lx
), y0
= XINT (ly
);
21315 /* Does this segment cross the X line? */
21323 if (y
> y0
&& y
> y1
)
21325 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21331 /* If we don't understand the format, pretend we're not in the hot-spot. */
21336 find_hot_spot (map
, x
, y
)
21340 while (CONSP (map
))
21342 if (CONSP (XCAR (map
))
21343 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21351 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21353 doc
: /* Lookup in image map MAP coordinates X and Y.
21354 An image map is an alist where each element has the format (AREA ID PLIST).
21355 An AREA is specified as either a rectangle, a circle, or a polygon:
21356 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21357 pixel coordinates of the upper left and bottom right corners.
21358 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21359 and the radius of the circle; r may be a float or integer.
21360 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21361 vector describes one corner in the polygon.
21362 Returns the alist element for the first matching AREA in MAP. */)
21373 return find_hot_spot (map
, XINT (x
), XINT (y
));
21377 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21379 define_frame_cursor1 (f
, cursor
, pointer
)
21382 Lisp_Object pointer
;
21384 /* Do not change cursor shape while dragging mouse. */
21385 if (!NILP (do_mouse_tracking
))
21388 if (!NILP (pointer
))
21390 if (EQ (pointer
, Qarrow
))
21391 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21392 else if (EQ (pointer
, Qhand
))
21393 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21394 else if (EQ (pointer
, Qtext
))
21395 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21396 else if (EQ (pointer
, intern ("hdrag")))
21397 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21398 #ifdef HAVE_X_WINDOWS
21399 else if (EQ (pointer
, intern ("vdrag")))
21400 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21402 else if (EQ (pointer
, intern ("hourglass")))
21403 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21404 else if (EQ (pointer
, Qmodeline
))
21405 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21407 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21410 if (cursor
!= No_Cursor
)
21411 rif
->define_frame_cursor (f
, cursor
);
21414 /* Take proper action when mouse has moved to the mode or header line
21415 or marginal area AREA of window W, x-position X and y-position Y.
21416 X is relative to the start of the text display area of W, so the
21417 width of bitmap areas and scroll bars must be subtracted to get a
21418 position relative to the start of the mode line. */
21421 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21422 Lisp_Object window
;
21424 enum window_part area
;
21426 struct window
*w
= XWINDOW (window
);
21427 struct frame
*f
= XFRAME (w
->frame
);
21428 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21429 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21430 Lisp_Object pointer
= Qnil
;
21431 int charpos
, dx
, dy
, width
, height
;
21432 Lisp_Object string
, object
= Qnil
;
21433 Lisp_Object pos
, help
;
21435 Lisp_Object mouse_face
;
21436 int original_x_pixel
= x
;
21437 struct glyph
* glyph
= NULL
;
21438 struct glyph_row
*row
;
21440 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21445 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21446 &object
, &dx
, &dy
, &width
, &height
);
21448 row
= (area
== ON_MODE_LINE
21449 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21450 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21453 if (row
->mode_line_p
&& row
->enabled_p
)
21455 glyph
= row
->glyphs
[TEXT_AREA
];
21456 end
= glyph
+ row
->used
[TEXT_AREA
];
21458 for (x0
= original_x_pixel
;
21459 glyph
< end
&& x0
>= glyph
->pixel_width
;
21461 x0
-= glyph
->pixel_width
;
21469 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21470 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21471 &object
, &dx
, &dy
, &width
, &height
);
21476 if (IMAGEP (object
))
21478 Lisp_Object image_map
, hotspot
;
21479 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
21481 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21483 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21485 Lisp_Object area_id
, plist
;
21487 area_id
= XCAR (hotspot
);
21488 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21489 If so, we could look for mouse-enter, mouse-leave
21490 properties in PLIST (and do something...). */
21491 hotspot
= XCDR (hotspot
);
21492 if (CONSP (hotspot
)
21493 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21495 pointer
= Fplist_get (plist
, Qpointer
);
21496 if (NILP (pointer
))
21498 help
= Fplist_get (plist
, Qhelp_echo
);
21501 help_echo_string
= help
;
21502 /* Is this correct? ++kfs */
21503 XSETWINDOW (help_echo_window
, w
);
21504 help_echo_object
= w
->buffer
;
21505 help_echo_pos
= charpos
;
21509 if (NILP (pointer
))
21510 pointer
= Fplist_get (XCDR (object
), QCpointer
);
21513 if (STRINGP (string
))
21515 pos
= make_number (charpos
);
21516 /* If we're on a string with `help-echo' text property, arrange
21517 for the help to be displayed. This is done by setting the
21518 global variable help_echo_string to the help string. */
21521 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21524 help_echo_string
= help
;
21525 XSETWINDOW (help_echo_window
, w
);
21526 help_echo_object
= string
;
21527 help_echo_pos
= charpos
;
21531 if (NILP (pointer
))
21532 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21534 /* Change the mouse pointer according to what is under X/Y. */
21535 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21538 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21539 if (!KEYMAPP (map
))
21540 map
= Fget_text_property (pos
, Qkeymap
, string
);
21541 if (!KEYMAPP (map
))
21542 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21545 /* Change the mouse face according to what is under X/Y. */
21546 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
21547 if (!NILP (mouse_face
)
21548 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21553 struct glyph
* tmp_glyph
;
21557 int total_pixel_width
;
21562 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
21563 Qmouse_face
, string
, Qnil
);
21565 b
= make_number (0);
21567 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
21569 e
= make_number (SCHARS (string
));
21571 /* Calculate the position(glyph position: GPOS) of GLYPH in
21572 displayed string. GPOS is different from CHARPOS.
21574 CHARPOS is the position of glyph in internal string
21575 object. A mode line string format has structures which
21576 is converted to a flatten by emacs lisp interpreter.
21577 The internal string is an element of the structures.
21578 The displayed string is the flatten string. */
21579 for (tmp_glyph
= glyph
- 1, gpos
= 0;
21580 tmp_glyph
->charpos
>= XINT (b
);
21581 tmp_glyph
--, gpos
++)
21583 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21587 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
21588 displayed string holding GLYPH.
21590 GSEQ_LENGTH is different from SCHARS (STRING).
21591 SCHARS (STRING) returns the length of the internal string. */
21592 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
21593 tmp_glyph
->charpos
< XINT (e
);
21594 tmp_glyph
++, gseq_length
++)
21596 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21600 total_pixel_width
= 0;
21601 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
21602 total_pixel_width
+= tmp_glyph
->pixel_width
;
21604 /* Pre calculation of re-rendering position */
21606 hpos
= (area
== ON_MODE_LINE
21607 ? (w
->current_matrix
)->nrows
- 1
21610 /* If the re-rendering position is included in the last
21611 re-rendering area, we should do nothing. */
21612 if ( EQ (window
, dpyinfo
->mouse_face_window
)
21613 && dpyinfo
->mouse_face_beg_col
<= vpos
21614 && vpos
< dpyinfo
->mouse_face_end_col
21615 && dpyinfo
->mouse_face_beg_row
== hpos
)
21618 if (clear_mouse_face (dpyinfo
))
21619 cursor
= No_Cursor
;
21621 dpyinfo
->mouse_face_beg_col
= vpos
;
21622 dpyinfo
->mouse_face_beg_row
= hpos
;
21624 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
21625 dpyinfo
->mouse_face_beg_y
= 0;
21627 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
21628 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
21630 dpyinfo
->mouse_face_end_x
= 0;
21631 dpyinfo
->mouse_face_end_y
= 0;
21633 dpyinfo
->mouse_face_past_end
= 0;
21634 dpyinfo
->mouse_face_window
= window
;
21636 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
21639 glyph
->face_id
, 1);
21640 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21642 if (NILP (pointer
))
21645 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21646 clear_mouse_face (dpyinfo
);
21648 define_frame_cursor1 (f
, cursor
, pointer
);
21653 Take proper action when the mouse has moved to position X, Y on
21654 frame F as regards highlighting characters that have mouse-face
21655 properties. Also de-highlighting chars where the mouse was before.
21656 X and Y can be negative or out of range. */
21659 note_mouse_highlight (f
, x
, y
)
21663 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21664 enum window_part part
;
21665 Lisp_Object window
;
21667 Cursor cursor
= No_Cursor
;
21668 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21671 /* When a menu is active, don't highlight because this looks odd. */
21672 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21673 if (popup_activated ())
21677 if (NILP (Vmouse_highlight
)
21678 || !f
->glyphs_initialized_p
)
21681 dpyinfo
->mouse_face_mouse_x
= x
;
21682 dpyinfo
->mouse_face_mouse_y
= y
;
21683 dpyinfo
->mouse_face_mouse_frame
= f
;
21685 if (dpyinfo
->mouse_face_defer
)
21688 if (gc_in_progress
)
21690 dpyinfo
->mouse_face_deferred_gc
= 1;
21694 /* Which window is that in? */
21695 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21697 /* If we were displaying active text in another window, clear that.
21698 Also clear if we move out of text area in same window. */
21699 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21700 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
21701 && !NILP (dpyinfo
->mouse_face_window
)))
21702 clear_mouse_face (dpyinfo
);
21704 /* Not on a window -> return. */
21705 if (!WINDOWP (window
))
21708 /* Reset help_echo_string. It will get recomputed below. */
21709 help_echo_string
= Qnil
;
21711 /* Convert to window-relative pixel coordinates. */
21712 w
= XWINDOW (window
);
21713 frame_to_window_pixel_xy (w
, &x
, &y
);
21715 /* Handle tool-bar window differently since it doesn't display a
21717 if (EQ (window
, f
->tool_bar_window
))
21719 note_tool_bar_highlight (f
, x
, y
);
21723 /* Mouse is on the mode, header line or margin? */
21724 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21725 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21727 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
21731 if (part
== ON_VERTICAL_BORDER
)
21732 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21733 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21734 || part
== ON_SCROLL_BAR
)
21735 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21737 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21739 /* Are we in a window whose display is up to date?
21740 And verify the buffer's text has not changed. */
21741 b
= XBUFFER (w
->buffer
);
21742 if (part
== ON_TEXT
21743 && EQ (w
->window_end_valid
, w
->buffer
)
21744 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21745 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21747 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21748 struct glyph
*glyph
;
21749 Lisp_Object object
;
21750 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21751 Lisp_Object
*overlay_vec
= NULL
;
21753 struct buffer
*obuf
;
21754 int obegv
, ozv
, same_region
;
21756 /* Find the glyph under X/Y. */
21757 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21759 /* Look for :pointer property on image. */
21760 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21762 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21763 if (img
!= NULL
&& IMAGEP (img
->spec
))
21765 Lisp_Object image_map
, hotspot
;
21766 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
21768 && (hotspot
= find_hot_spot (image_map
,
21769 glyph
->slice
.x
+ dx
,
21770 glyph
->slice
.y
+ dy
),
21772 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21774 Lisp_Object area_id
, plist
;
21776 area_id
= XCAR (hotspot
);
21777 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21778 If so, we could look for mouse-enter, mouse-leave
21779 properties in PLIST (and do something...). */
21780 hotspot
= XCDR (hotspot
);
21781 if (CONSP (hotspot
)
21782 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21784 pointer
= Fplist_get (plist
, Qpointer
);
21785 if (NILP (pointer
))
21787 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
21788 if (!NILP (help_echo_string
))
21790 help_echo_window
= window
;
21791 help_echo_object
= glyph
->object
;
21792 help_echo_pos
= glyph
->charpos
;
21796 if (NILP (pointer
))
21797 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
21801 /* Clear mouse face if X/Y not over text. */
21803 || area
!= TEXT_AREA
21804 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21806 if (clear_mouse_face (dpyinfo
))
21807 cursor
= No_Cursor
;
21808 if (NILP (pointer
))
21810 if (area
!= TEXT_AREA
)
21811 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21813 pointer
= Vvoid_text_area_pointer
;
21818 pos
= glyph
->charpos
;
21819 object
= glyph
->object
;
21820 if (!STRINGP (object
) && !BUFFERP (object
))
21823 /* If we get an out-of-range value, return now; avoid an error. */
21824 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21827 /* Make the window's buffer temporarily current for
21828 overlays_at and compute_char_face. */
21829 obuf
= current_buffer
;
21830 current_buffer
= b
;
21836 /* Is this char mouse-active or does it have help-echo? */
21837 position
= make_number (pos
);
21839 if (BUFFERP (object
))
21841 /* Put all the overlays we want in a vector in overlay_vec. */
21842 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21843 /* Sort overlays into increasing priority order. */
21844 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21849 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21850 && vpos
>= dpyinfo
->mouse_face_beg_row
21851 && vpos
<= dpyinfo
->mouse_face_end_row
21852 && (vpos
> dpyinfo
->mouse_face_beg_row
21853 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21854 && (vpos
< dpyinfo
->mouse_face_end_row
21855 || hpos
< dpyinfo
->mouse_face_end_col
21856 || dpyinfo
->mouse_face_past_end
));
21859 cursor
= No_Cursor
;
21861 /* Check mouse-face highlighting. */
21863 /* If there exists an overlay with mouse-face overlapping
21864 the one we are currently highlighting, we have to
21865 check if we enter the overlapping overlay, and then
21866 highlight only that. */
21867 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21868 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21870 /* Find the highest priority overlay that has a mouse-face
21873 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21875 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21876 if (!NILP (mouse_face
))
21877 overlay
= overlay_vec
[i
];
21880 /* If we're actually highlighting the same overlay as
21881 before, there's no need to do that again. */
21882 if (!NILP (overlay
)
21883 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21884 goto check_help_echo
;
21886 dpyinfo
->mouse_face_overlay
= overlay
;
21888 /* Clear the display of the old active region, if any. */
21889 if (clear_mouse_face (dpyinfo
))
21890 cursor
= No_Cursor
;
21892 /* If no overlay applies, get a text property. */
21893 if (NILP (overlay
))
21894 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21896 /* Handle the overlay case. */
21897 if (!NILP (overlay
))
21899 /* Find the range of text around this char that
21900 should be active. */
21901 Lisp_Object before
, after
;
21904 before
= Foverlay_start (overlay
);
21905 after
= Foverlay_end (overlay
);
21906 /* Record this as the current active region. */
21907 fast_find_position (w
, XFASTINT (before
),
21908 &dpyinfo
->mouse_face_beg_col
,
21909 &dpyinfo
->mouse_face_beg_row
,
21910 &dpyinfo
->mouse_face_beg_x
,
21911 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21913 dpyinfo
->mouse_face_past_end
21914 = !fast_find_position (w
, XFASTINT (after
),
21915 &dpyinfo
->mouse_face_end_col
,
21916 &dpyinfo
->mouse_face_end_row
,
21917 &dpyinfo
->mouse_face_end_x
,
21918 &dpyinfo
->mouse_face_end_y
, Qnil
);
21919 dpyinfo
->mouse_face_window
= window
;
21921 dpyinfo
->mouse_face_face_id
21922 = face_at_buffer_position (w
, pos
, 0, 0,
21924 !dpyinfo
->mouse_face_hidden
);
21926 /* Display it as active. */
21927 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21928 cursor
= No_Cursor
;
21930 /* Handle the text property case. */
21931 else if (!NILP (mouse_face
) && BUFFERP (object
))
21933 /* Find the range of text around this char that
21934 should be active. */
21935 Lisp_Object before
, after
, beginning
, end
;
21938 beginning
= Fmarker_position (w
->start
);
21939 end
= make_number (BUF_Z (XBUFFER (object
))
21940 - XFASTINT (w
->window_end_pos
));
21942 = Fprevious_single_property_change (make_number (pos
+ 1),
21944 object
, beginning
);
21946 = Fnext_single_property_change (position
, Qmouse_face
,
21949 /* Record this as the current active region. */
21950 fast_find_position (w
, XFASTINT (before
),
21951 &dpyinfo
->mouse_face_beg_col
,
21952 &dpyinfo
->mouse_face_beg_row
,
21953 &dpyinfo
->mouse_face_beg_x
,
21954 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21955 dpyinfo
->mouse_face_past_end
21956 = !fast_find_position (w
, XFASTINT (after
),
21957 &dpyinfo
->mouse_face_end_col
,
21958 &dpyinfo
->mouse_face_end_row
,
21959 &dpyinfo
->mouse_face_end_x
,
21960 &dpyinfo
->mouse_face_end_y
, Qnil
);
21961 dpyinfo
->mouse_face_window
= window
;
21963 if (BUFFERP (object
))
21964 dpyinfo
->mouse_face_face_id
21965 = face_at_buffer_position (w
, pos
, 0, 0,
21967 !dpyinfo
->mouse_face_hidden
);
21969 /* Display it as active. */
21970 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21971 cursor
= No_Cursor
;
21973 else if (!NILP (mouse_face
) && STRINGP (object
))
21978 b
= Fprevious_single_property_change (make_number (pos
+ 1),
21981 e
= Fnext_single_property_change (position
, Qmouse_face
,
21984 b
= make_number (0);
21986 e
= make_number (SCHARS (object
) - 1);
21988 fast_find_string_pos (w
, XINT (b
), object
,
21989 &dpyinfo
->mouse_face_beg_col
,
21990 &dpyinfo
->mouse_face_beg_row
,
21991 &dpyinfo
->mouse_face_beg_x
,
21992 &dpyinfo
->mouse_face_beg_y
, 0);
21993 fast_find_string_pos (w
, XINT (e
), object
,
21994 &dpyinfo
->mouse_face_end_col
,
21995 &dpyinfo
->mouse_face_end_row
,
21996 &dpyinfo
->mouse_face_end_x
,
21997 &dpyinfo
->mouse_face_end_y
, 1);
21998 dpyinfo
->mouse_face_past_end
= 0;
21999 dpyinfo
->mouse_face_window
= window
;
22000 dpyinfo
->mouse_face_face_id
22001 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22002 glyph
->face_id
, 1);
22003 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22004 cursor
= No_Cursor
;
22006 else if (STRINGP (object
) && NILP (mouse_face
))
22008 /* A string which doesn't have mouse-face, but
22009 the text ``under'' it might have. */
22010 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22011 int start
= MATRIX_ROW_START_CHARPOS (r
);
22013 pos
= string_buffer_position (w
, object
, start
);
22015 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22019 if (!NILP (mouse_face
) && !NILP (overlay
))
22021 Lisp_Object before
= Foverlay_start (overlay
);
22022 Lisp_Object after
= Foverlay_end (overlay
);
22025 /* Note that we might not be able to find position
22026 BEFORE in the glyph matrix if the overlay is
22027 entirely covered by a `display' property. In
22028 this case, we overshoot. So let's stop in
22029 the glyph matrix before glyphs for OBJECT. */
22030 fast_find_position (w
, XFASTINT (before
),
22031 &dpyinfo
->mouse_face_beg_col
,
22032 &dpyinfo
->mouse_face_beg_row
,
22033 &dpyinfo
->mouse_face_beg_x
,
22034 &dpyinfo
->mouse_face_beg_y
,
22037 dpyinfo
->mouse_face_past_end
22038 = !fast_find_position (w
, XFASTINT (after
),
22039 &dpyinfo
->mouse_face_end_col
,
22040 &dpyinfo
->mouse_face_end_row
,
22041 &dpyinfo
->mouse_face_end_x
,
22042 &dpyinfo
->mouse_face_end_y
,
22044 dpyinfo
->mouse_face_window
= window
;
22045 dpyinfo
->mouse_face_face_id
22046 = face_at_buffer_position (w
, pos
, 0, 0,
22048 !dpyinfo
->mouse_face_hidden
);
22050 /* Display it as active. */
22051 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22052 cursor
= No_Cursor
;
22059 /* Look for a `help-echo' property. */
22060 if (NILP (help_echo_string
)) {
22061 Lisp_Object help
, overlay
;
22063 /* Check overlays first. */
22064 help
= overlay
= Qnil
;
22065 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22067 overlay
= overlay_vec
[i
];
22068 help
= Foverlay_get (overlay
, Qhelp_echo
);
22073 help_echo_string
= help
;
22074 help_echo_window
= window
;
22075 help_echo_object
= overlay
;
22076 help_echo_pos
= pos
;
22080 Lisp_Object object
= glyph
->object
;
22081 int charpos
= glyph
->charpos
;
22083 /* Try text properties. */
22084 if (STRINGP (object
)
22086 && charpos
< SCHARS (object
))
22088 help
= Fget_text_property (make_number (charpos
),
22089 Qhelp_echo
, object
);
22092 /* If the string itself doesn't specify a help-echo,
22093 see if the buffer text ``under'' it does. */
22094 struct glyph_row
*r
22095 = MATRIX_ROW (w
->current_matrix
, vpos
);
22096 int start
= MATRIX_ROW_START_CHARPOS (r
);
22097 int pos
= string_buffer_position (w
, object
, start
);
22100 help
= Fget_char_property (make_number (pos
),
22101 Qhelp_echo
, w
->buffer
);
22105 object
= w
->buffer
;
22110 else if (BUFFERP (object
)
22113 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22118 help_echo_string
= help
;
22119 help_echo_window
= window
;
22120 help_echo_object
= object
;
22121 help_echo_pos
= charpos
;
22126 /* Look for a `pointer' property. */
22127 if (NILP (pointer
))
22129 /* Check overlays first. */
22130 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22131 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22133 if (NILP (pointer
))
22135 Lisp_Object object
= glyph
->object
;
22136 int charpos
= glyph
->charpos
;
22138 /* Try text properties. */
22139 if (STRINGP (object
)
22141 && charpos
< SCHARS (object
))
22143 pointer
= Fget_text_property (make_number (charpos
),
22145 if (NILP (pointer
))
22147 /* If the string itself doesn't specify a pointer,
22148 see if the buffer text ``under'' it does. */
22149 struct glyph_row
*r
22150 = MATRIX_ROW (w
->current_matrix
, vpos
);
22151 int start
= MATRIX_ROW_START_CHARPOS (r
);
22152 int pos
= string_buffer_position (w
, object
, start
);
22154 pointer
= Fget_char_property (make_number (pos
),
22155 Qpointer
, w
->buffer
);
22158 else if (BUFFERP (object
)
22161 pointer
= Fget_text_property (make_number (charpos
),
22168 current_buffer
= obuf
;
22173 define_frame_cursor1 (f
, cursor
, pointer
);
22178 Clear any mouse-face on window W. This function is part of the
22179 redisplay interface, and is called from try_window_id and similar
22180 functions to ensure the mouse-highlight is off. */
22183 x_clear_window_mouse_face (w
)
22186 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22187 Lisp_Object window
;
22190 XSETWINDOW (window
, w
);
22191 if (EQ (window
, dpyinfo
->mouse_face_window
))
22192 clear_mouse_face (dpyinfo
);
22198 Just discard the mouse face information for frame F, if any.
22199 This is used when the size of F is changed. */
22202 cancel_mouse_face (f
)
22205 Lisp_Object window
;
22206 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22208 window
= dpyinfo
->mouse_face_window
;
22209 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22211 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22212 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22213 dpyinfo
->mouse_face_window
= Qnil
;
22218 #endif /* HAVE_WINDOW_SYSTEM */
22221 /***********************************************************************
22223 ***********************************************************************/
22225 #ifdef HAVE_WINDOW_SYSTEM
22227 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22228 which intersects rectangle R. R is in window-relative coordinates. */
22231 expose_area (w
, row
, r
, area
)
22233 struct glyph_row
*row
;
22235 enum glyph_row_area area
;
22237 struct glyph
*first
= row
->glyphs
[area
];
22238 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22239 struct glyph
*last
;
22240 int first_x
, start_x
, x
;
22242 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22243 /* If row extends face to end of line write the whole line. */
22244 draw_glyphs (w
, 0, row
, area
,
22245 0, row
->used
[area
],
22246 DRAW_NORMAL_TEXT
, 0);
22249 /* Set START_X to the window-relative start position for drawing glyphs of
22250 AREA. The first glyph of the text area can be partially visible.
22251 The first glyphs of other areas cannot. */
22252 start_x
= window_box_left_offset (w
, area
);
22254 if (area
== TEXT_AREA
)
22257 /* Find the first glyph that must be redrawn. */
22259 && x
+ first
->pixel_width
< r
->x
)
22261 x
+= first
->pixel_width
;
22265 /* Find the last one. */
22269 && x
< r
->x
+ r
->width
)
22271 x
+= last
->pixel_width
;
22277 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22278 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22279 DRAW_NORMAL_TEXT
, 0);
22284 /* Redraw the parts of the glyph row ROW on window W intersecting
22285 rectangle R. R is in window-relative coordinates. Value is
22286 non-zero if mouse-face was overwritten. */
22289 expose_line (w
, row
, r
)
22291 struct glyph_row
*row
;
22294 xassert (row
->enabled_p
);
22296 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22297 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22298 0, row
->used
[TEXT_AREA
],
22299 DRAW_NORMAL_TEXT
, 0);
22302 if (row
->used
[LEFT_MARGIN_AREA
])
22303 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22304 if (row
->used
[TEXT_AREA
])
22305 expose_area (w
, row
, r
, TEXT_AREA
);
22306 if (row
->used
[RIGHT_MARGIN_AREA
])
22307 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22308 draw_row_fringe_bitmaps (w
, row
);
22311 return row
->mouse_face_p
;
22315 /* Redraw those parts of glyphs rows during expose event handling that
22316 overlap other rows. Redrawing of an exposed line writes over parts
22317 of lines overlapping that exposed line; this function fixes that.
22319 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22320 row in W's current matrix that is exposed and overlaps other rows.
22321 LAST_OVERLAPPING_ROW is the last such row. */
22324 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22326 struct glyph_row
*first_overlapping_row
;
22327 struct glyph_row
*last_overlapping_row
;
22329 struct glyph_row
*row
;
22331 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22332 if (row
->overlapping_p
)
22334 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22336 if (row
->used
[LEFT_MARGIN_AREA
])
22337 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
22339 if (row
->used
[TEXT_AREA
])
22340 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
22342 if (row
->used
[RIGHT_MARGIN_AREA
])
22343 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
22348 /* Return non-zero if W's cursor intersects rectangle R. */
22351 phys_cursor_in_rect_p (w
, r
)
22355 XRectangle cr
, result
;
22356 struct glyph
*cursor_glyph
;
22358 cursor_glyph
= get_phys_cursor_glyph (w
);
22361 /* r is relative to W's box, but w->phys_cursor.x is relative
22362 to left edge of W's TEXT area. Adjust it. */
22363 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22364 cr
.y
= w
->phys_cursor
.y
;
22365 cr
.width
= cursor_glyph
->pixel_width
;
22366 cr
.height
= w
->phys_cursor_height
;
22367 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22368 I assume the effect is the same -- and this is portable. */
22369 return x_intersect_rectangles (&cr
, r
, &result
);
22377 Draw a vertical window border to the right of window W if W doesn't
22378 have vertical scroll bars. */
22381 x_draw_vertical_border (w
)
22384 /* We could do better, if we knew what type of scroll-bar the adjacent
22385 windows (on either side) have... But we don't :-(
22386 However, I think this works ok. ++KFS 2003-04-25 */
22388 /* Redraw borders between horizontally adjacent windows. Don't
22389 do it for frames with vertical scroll bars because either the
22390 right scroll bar of a window, or the left scroll bar of its
22391 neighbor will suffice as a border. */
22392 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22395 if (!WINDOW_RIGHTMOST_P (w
)
22396 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22398 int x0
, x1
, y0
, y1
;
22400 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22403 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22406 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22408 else if (!WINDOW_LEFTMOST_P (w
)
22409 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22411 int x0
, x1
, y0
, y1
;
22413 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22416 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22419 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22424 /* Redraw the part of window W intersection rectangle FR. Pixel
22425 coordinates in FR are frame-relative. Call this function with
22426 input blocked. Value is non-zero if the exposure overwrites
22430 expose_window (w
, fr
)
22434 struct frame
*f
= XFRAME (w
->frame
);
22436 int mouse_face_overwritten_p
= 0;
22438 /* If window is not yet fully initialized, do nothing. This can
22439 happen when toolkit scroll bars are used and a window is split.
22440 Reconfiguring the scroll bar will generate an expose for a newly
22442 if (w
->current_matrix
== NULL
)
22445 /* When we're currently updating the window, display and current
22446 matrix usually don't agree. Arrange for a thorough display
22448 if (w
== updated_window
)
22450 SET_FRAME_GARBAGED (f
);
22454 /* Frame-relative pixel rectangle of W. */
22455 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22456 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22457 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22458 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22460 if (x_intersect_rectangles (fr
, &wr
, &r
))
22462 int yb
= window_text_bottom_y (w
);
22463 struct glyph_row
*row
;
22464 int cursor_cleared_p
;
22465 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22467 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22468 r
.x
, r
.y
, r
.width
, r
.height
));
22470 /* Convert to window coordinates. */
22471 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22472 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22474 /* Turn off the cursor. */
22475 if (!w
->pseudo_window_p
22476 && phys_cursor_in_rect_p (w
, &r
))
22478 x_clear_cursor (w
);
22479 cursor_cleared_p
= 1;
22482 cursor_cleared_p
= 0;
22484 /* Update lines intersecting rectangle R. */
22485 first_overlapping_row
= last_overlapping_row
= NULL
;
22486 for (row
= w
->current_matrix
->rows
;
22491 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22493 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22494 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22495 || (r
.y
>= y0
&& r
.y
< y1
)
22496 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22498 /* A header line may be overlapping, but there is no need
22499 to fix overlapping areas for them. KFS 2005-02-12 */
22500 if (row
->overlapping_p
&& !row
->mode_line_p
)
22502 if (first_overlapping_row
== NULL
)
22503 first_overlapping_row
= row
;
22504 last_overlapping_row
= row
;
22507 if (expose_line (w
, row
, &r
))
22508 mouse_face_overwritten_p
= 1;
22515 /* Display the mode line if there is one. */
22516 if (WINDOW_WANTS_MODELINE_P (w
)
22517 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22519 && row
->y
< r
.y
+ r
.height
)
22521 if (expose_line (w
, row
, &r
))
22522 mouse_face_overwritten_p
= 1;
22525 if (!w
->pseudo_window_p
)
22527 /* Fix the display of overlapping rows. */
22528 if (first_overlapping_row
)
22529 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22531 /* Draw border between windows. */
22532 x_draw_vertical_border (w
);
22534 /* Turn the cursor on again. */
22535 if (cursor_cleared_p
)
22536 update_window_cursor (w
, 1);
22540 return mouse_face_overwritten_p
;
22545 /* Redraw (parts) of all windows in the window tree rooted at W that
22546 intersect R. R contains frame pixel coordinates. Value is
22547 non-zero if the exposure overwrites mouse-face. */
22550 expose_window_tree (w
, r
)
22554 struct frame
*f
= XFRAME (w
->frame
);
22555 int mouse_face_overwritten_p
= 0;
22557 while (w
&& !FRAME_GARBAGED_P (f
))
22559 if (!NILP (w
->hchild
))
22560 mouse_face_overwritten_p
22561 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22562 else if (!NILP (w
->vchild
))
22563 mouse_face_overwritten_p
22564 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22566 mouse_face_overwritten_p
|= expose_window (w
, r
);
22568 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22571 return mouse_face_overwritten_p
;
22576 Redisplay an exposed area of frame F. X and Y are the upper-left
22577 corner of the exposed rectangle. W and H are width and height of
22578 the exposed area. All are pixel values. W or H zero means redraw
22579 the entire frame. */
22582 expose_frame (f
, x
, y
, w
, h
)
22587 int mouse_face_overwritten_p
= 0;
22589 TRACE ((stderr
, "expose_frame "));
22591 /* No need to redraw if frame will be redrawn soon. */
22592 if (FRAME_GARBAGED_P (f
))
22594 TRACE ((stderr
, " garbaged\n"));
22598 /* If basic faces haven't been realized yet, there is no point in
22599 trying to redraw anything. This can happen when we get an expose
22600 event while Emacs is starting, e.g. by moving another window. */
22601 if (FRAME_FACE_CACHE (f
) == NULL
22602 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22604 TRACE ((stderr
, " no faces\n"));
22608 if (w
== 0 || h
== 0)
22611 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22612 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22622 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22623 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22625 if (WINDOWP (f
->tool_bar_window
))
22626 mouse_face_overwritten_p
22627 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22629 #ifdef HAVE_X_WINDOWS
22631 #ifndef USE_X_TOOLKIT
22632 if (WINDOWP (f
->menu_bar_window
))
22633 mouse_face_overwritten_p
22634 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22635 #endif /* not USE_X_TOOLKIT */
22639 /* Some window managers support a focus-follows-mouse style with
22640 delayed raising of frames. Imagine a partially obscured frame,
22641 and moving the mouse into partially obscured mouse-face on that
22642 frame. The visible part of the mouse-face will be highlighted,
22643 then the WM raises the obscured frame. With at least one WM, KDE
22644 2.1, Emacs is not getting any event for the raising of the frame
22645 (even tried with SubstructureRedirectMask), only Expose events.
22646 These expose events will draw text normally, i.e. not
22647 highlighted. Which means we must redo the highlight here.
22648 Subsume it under ``we love X''. --gerd 2001-08-15 */
22649 /* Included in Windows version because Windows most likely does not
22650 do the right thing if any third party tool offers
22651 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22652 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22654 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22655 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22657 int x
= dpyinfo
->mouse_face_mouse_x
;
22658 int y
= dpyinfo
->mouse_face_mouse_y
;
22659 clear_mouse_face (dpyinfo
);
22660 note_mouse_highlight (f
, x
, y
);
22667 Determine the intersection of two rectangles R1 and R2. Return
22668 the intersection in *RESULT. Value is non-zero if RESULT is not
22672 x_intersect_rectangles (r1
, r2
, result
)
22673 XRectangle
*r1
, *r2
, *result
;
22675 XRectangle
*left
, *right
;
22676 XRectangle
*upper
, *lower
;
22677 int intersection_p
= 0;
22679 /* Rearrange so that R1 is the left-most rectangle. */
22681 left
= r1
, right
= r2
;
22683 left
= r2
, right
= r1
;
22685 /* X0 of the intersection is right.x0, if this is inside R1,
22686 otherwise there is no intersection. */
22687 if (right
->x
<= left
->x
+ left
->width
)
22689 result
->x
= right
->x
;
22691 /* The right end of the intersection is the minimum of the
22692 the right ends of left and right. */
22693 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22696 /* Same game for Y. */
22698 upper
= r1
, lower
= r2
;
22700 upper
= r2
, lower
= r1
;
22702 /* The upper end of the intersection is lower.y0, if this is inside
22703 of upper. Otherwise, there is no intersection. */
22704 if (lower
->y
<= upper
->y
+ upper
->height
)
22706 result
->y
= lower
->y
;
22708 /* The lower end of the intersection is the minimum of the lower
22709 ends of upper and lower. */
22710 result
->height
= (min (lower
->y
+ lower
->height
,
22711 upper
->y
+ upper
->height
)
22713 intersection_p
= 1;
22717 return intersection_p
;
22720 #endif /* HAVE_WINDOW_SYSTEM */
22723 /***********************************************************************
22725 ***********************************************************************/
22730 Vwith_echo_area_save_vector
= Qnil
;
22731 staticpro (&Vwith_echo_area_save_vector
);
22733 Vmessage_stack
= Qnil
;
22734 staticpro (&Vmessage_stack
);
22736 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22737 staticpro (&Qinhibit_redisplay
);
22739 message_dolog_marker1
= Fmake_marker ();
22740 staticpro (&message_dolog_marker1
);
22741 message_dolog_marker2
= Fmake_marker ();
22742 staticpro (&message_dolog_marker2
);
22743 message_dolog_marker3
= Fmake_marker ();
22744 staticpro (&message_dolog_marker3
);
22747 defsubr (&Sdump_frame_glyph_matrix
);
22748 defsubr (&Sdump_glyph_matrix
);
22749 defsubr (&Sdump_glyph_row
);
22750 defsubr (&Sdump_tool_bar_row
);
22751 defsubr (&Strace_redisplay
);
22752 defsubr (&Strace_to_stderr
);
22754 #ifdef HAVE_WINDOW_SYSTEM
22755 defsubr (&Stool_bar_lines_needed
);
22756 defsubr (&Slookup_image_map
);
22758 defsubr (&Sformat_mode_line
);
22760 staticpro (&Qmenu_bar_update_hook
);
22761 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22763 staticpro (&Qoverriding_terminal_local_map
);
22764 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22766 staticpro (&Qoverriding_local_map
);
22767 Qoverriding_local_map
= intern ("overriding-local-map");
22769 staticpro (&Qwindow_scroll_functions
);
22770 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22772 staticpro (&Qredisplay_end_trigger_functions
);
22773 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22775 staticpro (&Qinhibit_point_motion_hooks
);
22776 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22778 QCdata
= intern (":data");
22779 staticpro (&QCdata
);
22780 Qdisplay
= intern ("display");
22781 staticpro (&Qdisplay
);
22782 Qspace_width
= intern ("space-width");
22783 staticpro (&Qspace_width
);
22784 Qraise
= intern ("raise");
22785 staticpro (&Qraise
);
22786 Qslice
= intern ("slice");
22787 staticpro (&Qslice
);
22788 Qspace
= intern ("space");
22789 staticpro (&Qspace
);
22790 Qmargin
= intern ("margin");
22791 staticpro (&Qmargin
);
22792 Qpointer
= intern ("pointer");
22793 staticpro (&Qpointer
);
22794 Qleft_margin
= intern ("left-margin");
22795 staticpro (&Qleft_margin
);
22796 Qright_margin
= intern ("right-margin");
22797 staticpro (&Qright_margin
);
22798 Qcenter
= intern ("center");
22799 staticpro (&Qcenter
);
22800 Qline_height
= intern ("line-height");
22801 staticpro (&Qline_height
);
22802 QCalign_to
= intern (":align-to");
22803 staticpro (&QCalign_to
);
22804 QCrelative_width
= intern (":relative-width");
22805 staticpro (&QCrelative_width
);
22806 QCrelative_height
= intern (":relative-height");
22807 staticpro (&QCrelative_height
);
22808 QCeval
= intern (":eval");
22809 staticpro (&QCeval
);
22810 QCpropertize
= intern (":propertize");
22811 staticpro (&QCpropertize
);
22812 QCfile
= intern (":file");
22813 staticpro (&QCfile
);
22814 Qfontified
= intern ("fontified");
22815 staticpro (&Qfontified
);
22816 Qfontification_functions
= intern ("fontification-functions");
22817 staticpro (&Qfontification_functions
);
22818 Qtrailing_whitespace
= intern ("trailing-whitespace");
22819 staticpro (&Qtrailing_whitespace
);
22820 Qescape_glyph
= intern ("escape-glyph");
22821 staticpro (&Qescape_glyph
);
22822 Qnobreak_space
= intern ("nobreak-space");
22823 staticpro (&Qnobreak_space
);
22824 Qimage
= intern ("image");
22825 staticpro (&Qimage
);
22826 QCmap
= intern (":map");
22827 staticpro (&QCmap
);
22828 QCpointer
= intern (":pointer");
22829 staticpro (&QCpointer
);
22830 Qrect
= intern ("rect");
22831 staticpro (&Qrect
);
22832 Qcircle
= intern ("circle");
22833 staticpro (&Qcircle
);
22834 Qpoly
= intern ("poly");
22835 staticpro (&Qpoly
);
22836 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22837 staticpro (&Qmessage_truncate_lines
);
22838 Qgrow_only
= intern ("grow-only");
22839 staticpro (&Qgrow_only
);
22840 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22841 staticpro (&Qinhibit_menubar_update
);
22842 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22843 staticpro (&Qinhibit_eval_during_redisplay
);
22844 Qposition
= intern ("position");
22845 staticpro (&Qposition
);
22846 Qbuffer_position
= intern ("buffer-position");
22847 staticpro (&Qbuffer_position
);
22848 Qobject
= intern ("object");
22849 staticpro (&Qobject
);
22850 Qbar
= intern ("bar");
22852 Qhbar
= intern ("hbar");
22853 staticpro (&Qhbar
);
22854 Qbox
= intern ("box");
22856 Qhollow
= intern ("hollow");
22857 staticpro (&Qhollow
);
22858 Qhand
= intern ("hand");
22859 staticpro (&Qhand
);
22860 Qarrow
= intern ("arrow");
22861 staticpro (&Qarrow
);
22862 Qtext
= intern ("text");
22863 staticpro (&Qtext
);
22864 Qrisky_local_variable
= intern ("risky-local-variable");
22865 staticpro (&Qrisky_local_variable
);
22866 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22867 staticpro (&Qinhibit_free_realized_faces
);
22869 list_of_error
= Fcons (Fcons (intern ("error"),
22870 Fcons (intern ("void-variable"), Qnil
)),
22872 staticpro (&list_of_error
);
22874 Qlast_arrow_position
= intern ("last-arrow-position");
22875 staticpro (&Qlast_arrow_position
);
22876 Qlast_arrow_string
= intern ("last-arrow-string");
22877 staticpro (&Qlast_arrow_string
);
22879 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22880 staticpro (&Qoverlay_arrow_string
);
22881 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22882 staticpro (&Qoverlay_arrow_bitmap
);
22884 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22885 staticpro (&echo_buffer
[0]);
22886 staticpro (&echo_buffer
[1]);
22888 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22889 staticpro (&echo_area_buffer
[0]);
22890 staticpro (&echo_area_buffer
[1]);
22892 Vmessages_buffer_name
= build_string ("*Messages*");
22893 staticpro (&Vmessages_buffer_name
);
22895 mode_line_proptrans_alist
= Qnil
;
22896 staticpro (&mode_line_proptrans_alist
);
22897 mode_line_string_list
= Qnil
;
22898 staticpro (&mode_line_string_list
);
22899 mode_line_string_face
= Qnil
;
22900 staticpro (&mode_line_string_face
);
22901 mode_line_string_face_prop
= Qnil
;
22902 staticpro (&mode_line_string_face_prop
);
22903 Vmode_line_unwind_vector
= Qnil
;
22904 staticpro (&Vmode_line_unwind_vector
);
22906 help_echo_string
= Qnil
;
22907 staticpro (&help_echo_string
);
22908 help_echo_object
= Qnil
;
22909 staticpro (&help_echo_object
);
22910 help_echo_window
= Qnil
;
22911 staticpro (&help_echo_window
);
22912 previous_help_echo_string
= Qnil
;
22913 staticpro (&previous_help_echo_string
);
22914 help_echo_pos
= -1;
22916 #ifdef HAVE_WINDOW_SYSTEM
22917 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22918 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22919 For example, if a block cursor is over a tab, it will be drawn as
22920 wide as that tab on the display. */);
22921 x_stretch_cursor_p
= 0;
22924 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22925 doc
: /* *Non-nil means highlight trailing whitespace.
22926 The face used for trailing whitespace is `trailing-whitespace'. */);
22927 Vshow_trailing_whitespace
= Qnil
;
22929 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
22930 doc
: /* *Control highlighting of nobreak space and soft hyphen.
22931 A value of t means highlight the character itself (for nobreak space,
22932 use face `nobreak-space').
22933 A value of nil means no highlighting.
22934 Other values mean display the escape glyph followed by an ordinary
22935 space or ordinary hyphen. */);
22936 Vnobreak_char_display
= Qt
;
22938 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22939 doc
: /* *The pointer shape to show in void text areas.
22940 A value of nil means to show the text pointer. Other options are `arrow',
22941 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22942 Vvoid_text_area_pointer
= Qarrow
;
22944 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22945 doc
: /* Non-nil means don't actually do any redisplay.
22946 This is used for internal purposes. */);
22947 Vinhibit_redisplay
= Qnil
;
22949 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22950 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22951 Vglobal_mode_string
= Qnil
;
22953 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22954 doc
: /* Marker for where to display an arrow on top of the buffer text.
22955 This must be the beginning of a line in order to work.
22956 See also `overlay-arrow-string'. */);
22957 Voverlay_arrow_position
= Qnil
;
22959 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
22960 doc
: /* String to display as an arrow in non-window frames.
22961 See also `overlay-arrow-position'. */);
22962 Voverlay_arrow_string
= build_string ("=>");
22964 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
22965 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
22966 The symbols on this list are examined during redisplay to determine
22967 where to display overlay arrows. */);
22968 Voverlay_arrow_variable_list
22969 = Fcons (intern ("overlay-arrow-position"), Qnil
);
22971 DEFVAR_INT ("scroll-step", &scroll_step
,
22972 doc
: /* *The number of lines to try scrolling a window by when point moves out.
22973 If that fails to bring point back on frame, point is centered instead.
22974 If this is zero, point is always centered after it moves off frame.
22975 If you want scrolling to always be a line at a time, you should set
22976 `scroll-conservatively' to a large value rather than set this to 1. */);
22978 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
22979 doc
: /* *Scroll up to this many lines, to bring point back on screen.
22980 A value of zero means to scroll the text to center point vertically
22981 in the window. */);
22982 scroll_conservatively
= 0;
22984 DEFVAR_INT ("scroll-margin", &scroll_margin
,
22985 doc
: /* *Number of lines of margin at the top and bottom of a window.
22986 Recenter the window whenever point gets within this many lines
22987 of the top or bottom of the window. */);
22990 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
22991 doc
: /* Pixels per inch on current display.
22992 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
22993 Vdisplay_pixels_per_inch
= make_float (72.0);
22996 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
22999 DEFVAR_BOOL ("truncate-partial-width-windows",
23000 &truncate_partial_width_windows
,
23001 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23002 truncate_partial_width_windows
= 1;
23004 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23005 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23006 Any other value means to use the appropriate face, `mode-line',
23007 `header-line', or `menu' respectively. */);
23008 mode_line_inverse_video
= 1;
23010 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23011 doc
: /* *Maximum buffer size for which line number should be displayed.
23012 If the buffer is bigger than this, the line number does not appear
23013 in the mode line. A value of nil means no limit. */);
23014 Vline_number_display_limit
= Qnil
;
23016 DEFVAR_INT ("line-number-display-limit-width",
23017 &line_number_display_limit_width
,
23018 doc
: /* *Maximum line width (in characters) for line number display.
23019 If the average length of the lines near point is bigger than this, then the
23020 line number may be omitted from the mode line. */);
23021 line_number_display_limit_width
= 200;
23023 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23024 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23025 highlight_nonselected_windows
= 0;
23027 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23028 doc
: /* Non-nil if more than one frame is visible on this display.
23029 Minibuffer-only frames don't count, but iconified frames do.
23030 This variable is not guaranteed to be accurate except while processing
23031 `frame-title-format' and `icon-title-format'. */);
23033 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23034 doc
: /* Template for displaying the title bar of visible frames.
23035 \(Assuming the window manager supports this feature.)
23036 This variable has the same structure as `mode-line-format' (which see),
23037 and is used only on frames for which no explicit name has been set
23038 \(see `modify-frame-parameters'). */);
23040 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23041 doc
: /* Template for displaying the title bar of an iconified frame.
23042 \(Assuming the window manager supports this feature.)
23043 This variable has the same structure as `mode-line-format' (which see),
23044 and is used only on frames for which no explicit name has been set
23045 \(see `modify-frame-parameters'). */);
23047 = Vframe_title_format
23048 = Fcons (intern ("multiple-frames"),
23049 Fcons (build_string ("%b"),
23050 Fcons (Fcons (empty_string
,
23051 Fcons (intern ("invocation-name"),
23052 Fcons (build_string ("@"),
23053 Fcons (intern ("system-name"),
23057 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23058 doc
: /* Maximum number of lines to keep in the message log buffer.
23059 If nil, disable message logging. If t, log messages but don't truncate
23060 the buffer when it becomes large. */);
23061 Vmessage_log_max
= make_number (50);
23063 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23064 doc
: /* Functions called before redisplay, if window sizes have changed.
23065 The value should be a list of functions that take one argument.
23066 Just before redisplay, for each frame, if any of its windows have changed
23067 size since the last redisplay, or have been split or deleted,
23068 all the functions in the list are called, with the frame as argument. */);
23069 Vwindow_size_change_functions
= Qnil
;
23071 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23072 doc
: /* List of functions to call before redisplaying a window with scrolling.
23073 Each function is called with two arguments, the window
23074 and its new display-start position. Note that the value of `window-end'
23075 is not valid when these functions are called. */);
23076 Vwindow_scroll_functions
= Qnil
;
23078 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23079 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23080 mouse_autoselect_window
= 0;
23082 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23083 doc
: /* *Non-nil means automatically resize tool-bars.
23084 This increases a tool-bar's height if not all tool-bar items are visible.
23085 It decreases a tool-bar's height when it would display blank lines
23087 auto_resize_tool_bars_p
= 1;
23089 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23090 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23091 auto_raise_tool_bar_buttons_p
= 1;
23093 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23094 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23095 make_cursor_line_fully_visible_p
= 1;
23097 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23098 doc
: /* *Margin around tool-bar buttons in pixels.
23099 If an integer, use that for both horizontal and vertical margins.
23100 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23101 HORZ specifying the horizontal margin, and VERT specifying the
23102 vertical margin. */);
23103 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23105 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23106 doc
: /* *Relief thickness of tool-bar buttons. */);
23107 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23109 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23110 doc
: /* List of functions to call to fontify regions of text.
23111 Each function is called with one argument POS. Functions must
23112 fontify a region starting at POS in the current buffer, and give
23113 fontified regions the property `fontified'. */);
23114 Vfontification_functions
= Qnil
;
23115 Fmake_variable_buffer_local (Qfontification_functions
);
23117 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23118 &unibyte_display_via_language_environment
,
23119 doc
: /* *Non-nil means display unibyte text according to language environment.
23120 Specifically this means that unibyte non-ASCII characters
23121 are displayed by converting them to the equivalent multibyte characters
23122 according to the current language environment. As a result, they are
23123 displayed according to the current fontset. */);
23124 unibyte_display_via_language_environment
= 0;
23126 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23127 doc
: /* *Maximum height for resizing mini-windows.
23128 If a float, it specifies a fraction of the mini-window frame's height.
23129 If an integer, it specifies a number of lines. */);
23130 Vmax_mini_window_height
= make_float (0.25);
23132 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23133 doc
: /* *How to resize mini-windows.
23134 A value of nil means don't automatically resize mini-windows.
23135 A value of t means resize them to fit the text displayed in them.
23136 A value of `grow-only', the default, means let mini-windows grow
23137 only, until their display becomes empty, at which point the windows
23138 go back to their normal size. */);
23139 Vresize_mini_windows
= Qgrow_only
;
23141 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23142 doc
: /* Alist specifying how to blink the cursor off.
23143 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23144 `cursor-type' frame-parameter or variable equals ON-STATE,
23145 comparing using `equal', Emacs uses OFF-STATE to specify
23146 how to blink it off. */);
23147 Vblink_cursor_alist
= Qnil
;
23149 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23150 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23151 automatic_hscrolling_p
= 1;
23153 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23154 doc
: /* *How many columns away from the window edge point is allowed to get
23155 before automatic hscrolling will horizontally scroll the window. */);
23156 hscroll_margin
= 5;
23158 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23159 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23160 When point is less than `automatic-hscroll-margin' columns from the window
23161 edge, automatic hscrolling will scroll the window by the amount of columns
23162 determined by this variable. If its value is a positive integer, scroll that
23163 many columns. If it's a positive floating-point number, it specifies the
23164 fraction of the window's width to scroll. If it's nil or zero, point will be
23165 centered horizontally after the scroll. Any other value, including negative
23166 numbers, are treated as if the value were zero.
23168 Automatic hscrolling always moves point outside the scroll margin, so if
23169 point was more than scroll step columns inside the margin, the window will
23170 scroll more than the value given by the scroll step.
23172 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23173 and `scroll-right' overrides this variable's effect. */);
23174 Vhscroll_step
= make_number (0);
23176 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23177 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23178 Bind this around calls to `message' to let it take effect. */);
23179 message_truncate_lines
= 0;
23181 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23182 doc
: /* Normal hook run to update the menu bar definitions.
23183 Redisplay runs this hook before it redisplays the menu bar.
23184 This is used to update submenus such as Buffers,
23185 whose contents depend on various data. */);
23186 Vmenu_bar_update_hook
= Qnil
;
23188 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23189 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23190 inhibit_menubar_update
= 0;
23192 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23193 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23194 inhibit_eval_during_redisplay
= 0;
23196 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23197 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23198 inhibit_free_realized_faces
= 0;
23201 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23202 doc
: /* Inhibit try_window_id display optimization. */);
23203 inhibit_try_window_id
= 0;
23205 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23206 doc
: /* Inhibit try_window_reusing display optimization. */);
23207 inhibit_try_window_reusing
= 0;
23209 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23210 doc
: /* Inhibit try_cursor_movement display optimization. */);
23211 inhibit_try_cursor_movement
= 0;
23212 #endif /* GLYPH_DEBUG */
23216 /* Initialize this module when Emacs starts. */
23221 Lisp_Object root_window
;
23222 struct window
*mini_w
;
23224 current_header_line_height
= current_mode_line_height
= -1;
23226 CHARPOS (this_line_start_pos
) = 0;
23228 mini_w
= XWINDOW (minibuf_window
);
23229 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23231 if (!noninteractive
)
23233 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23236 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23237 set_window_height (root_window
,
23238 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23240 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23241 set_window_height (minibuf_window
, 1, 0);
23243 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23244 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23246 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23247 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23248 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23250 /* The default ellipsis glyphs `...'. */
23251 for (i
= 0; i
< 3; ++i
)
23252 default_invis_vector
[i
] = make_number ('.');
23256 /* Allocate the buffer for frame titles.
23257 Also used for `format-mode-line'. */
23259 mode_line_noprop_buf
= (char *) xmalloc (size
);
23260 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23261 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23262 mode_line_target
= MODE_LINE_DISPLAY
;
23265 help_echo_showing_p
= 0;
23269 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23270 (do not change this comment) */