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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, 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 /* Don't reseat to previous visible line start if current start
2412 position is in a string or image. */
2413 if (it
->method
== GET_FROM_BUFFER
&& !it
->truncate_lines_p
)
2415 int start_at_line_beg_p
;
2416 int first_y
= it
->current_y
;
2418 /* If window start is not at a line start, skip forward to POS to
2419 get the correct continuation lines width. */
2420 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2421 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2422 if (!start_at_line_beg_p
)
2426 reseat_at_previous_visible_line_start (it
);
2427 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2429 new_x
= it
->current_x
+ it
->pixel_width
;
2431 /* If lines are continued, this line may end in the middle
2432 of a multi-glyph character (e.g. a control character
2433 displayed as \003, or in the middle of an overlay
2434 string). In this case move_it_to above will not have
2435 taken us to the start of the continuation line but to the
2436 end of the continued line. */
2437 if (it
->current_x
> 0
2438 && !it
->truncate_lines_p
/* Lines are continued. */
2439 && (/* And glyph doesn't fit on the line. */
2440 new_x
> it
->last_visible_x
2441 /* Or it fits exactly and we're on a window
2443 || (new_x
== it
->last_visible_x
2444 && FRAME_WINDOW_P (it
->f
))))
2446 if (it
->current
.dpvec_index
>= 0
2447 || it
->current
.overlay_string_index
>= 0)
2449 set_iterator_to_next (it
, 1);
2450 move_it_in_display_line_to (it
, -1, -1, 0);
2453 it
->continuation_lines_width
+= it
->current_x
;
2456 /* We're starting a new display line, not affected by the
2457 height of the continued line, so clear the appropriate
2458 fields in the iterator structure. */
2459 it
->max_ascent
= it
->max_descent
= 0;
2460 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2462 it
->current_y
= first_y
;
2464 it
->current_x
= it
->hpos
= 0;
2468 #if 0 /* Don't assert the following because start_display is sometimes
2469 called intentionally with a window start that is not at a
2470 line start. Please leave this code in as a comment. */
2472 /* Window start should be on a line start, now. */
2473 xassert (it
->continuation_lines_width
2474 || IT_CHARPOS (it
) == BEGV
2475 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2480 /* Return 1 if POS is a position in ellipses displayed for invisible
2481 text. W is the window we display, for text property lookup. */
2484 in_ellipses_for_invisible_text_p (pos
, w
)
2485 struct display_pos
*pos
;
2488 Lisp_Object prop
, window
;
2490 int charpos
= CHARPOS (pos
->pos
);
2492 /* If POS specifies a position in a display vector, this might
2493 be for an ellipsis displayed for invisible text. We won't
2494 get the iterator set up for delivering that ellipsis unless
2495 we make sure that it gets aware of the invisible text. */
2496 if (pos
->dpvec_index
>= 0
2497 && pos
->overlay_string_index
< 0
2498 && CHARPOS (pos
->string_pos
) < 0
2500 && (XSETWINDOW (window
, w
),
2501 prop
= Fget_char_property (make_number (charpos
),
2502 Qinvisible
, window
),
2503 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2505 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2507 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2514 /* Initialize IT for stepping through current_buffer in window W,
2515 starting at position POS that includes overlay string and display
2516 vector/ control character translation position information. Value
2517 is zero if there are overlay strings with newlines at POS. */
2520 init_from_display_pos (it
, w
, pos
)
2523 struct display_pos
*pos
;
2525 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2526 int i
, overlay_strings_with_newlines
= 0;
2528 /* If POS specifies a position in a display vector, this might
2529 be for an ellipsis displayed for invisible text. We won't
2530 get the iterator set up for delivering that ellipsis unless
2531 we make sure that it gets aware of the invisible text. */
2532 if (in_ellipses_for_invisible_text_p (pos
, w
))
2538 /* Keep in mind: the call to reseat in init_iterator skips invisible
2539 text, so we might end up at a position different from POS. This
2540 is only a problem when POS is a row start after a newline and an
2541 overlay starts there with an after-string, and the overlay has an
2542 invisible property. Since we don't skip invisible text in
2543 display_line and elsewhere immediately after consuming the
2544 newline before the row start, such a POS will not be in a string,
2545 but the call to init_iterator below will move us to the
2547 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2549 /* This only scans the current chunk -- it should scan all chunks.
2550 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2551 to 16 in 22.1 to make this a lesser problem. */
2552 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2554 const char *s
= SDATA (it
->overlay_strings
[i
]);
2555 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2557 while (s
< e
&& *s
!= '\n')
2562 overlay_strings_with_newlines
= 1;
2567 /* If position is within an overlay string, set up IT to the right
2569 if (pos
->overlay_string_index
>= 0)
2573 /* If the first overlay string happens to have a `display'
2574 property for an image, the iterator will be set up for that
2575 image, and we have to undo that setup first before we can
2576 correct the overlay string index. */
2577 if (it
->method
== GET_FROM_IMAGE
)
2580 /* We already have the first chunk of overlay strings in
2581 IT->overlay_strings. Load more until the one for
2582 pos->overlay_string_index is in IT->overlay_strings. */
2583 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2585 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2586 it
->current
.overlay_string_index
= 0;
2589 load_overlay_strings (it
, 0);
2590 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2594 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2595 relative_index
= (it
->current
.overlay_string_index
2596 % OVERLAY_STRING_CHUNK_SIZE
);
2597 it
->string
= it
->overlay_strings
[relative_index
];
2598 xassert (STRINGP (it
->string
));
2599 it
->current
.string_pos
= pos
->string_pos
;
2600 it
->method
= GET_FROM_STRING
;
2603 #if 0 /* This is bogus because POS not having an overlay string
2604 position does not mean it's after the string. Example: A
2605 line starting with a before-string and initialization of IT
2606 to the previous row's end position. */
2607 else if (it
->current
.overlay_string_index
>= 0)
2609 /* If POS says we're already after an overlay string ending at
2610 POS, make sure to pop the iterator because it will be in
2611 front of that overlay string. When POS is ZV, we've thereby
2612 also ``processed'' overlay strings at ZV. */
2615 it
->current
.overlay_string_index
= -1;
2616 it
->method
= GET_FROM_BUFFER
;
2617 if (CHARPOS (pos
->pos
) == ZV
)
2618 it
->overlay_strings_at_end_processed_p
= 1;
2622 if (CHARPOS (pos
->string_pos
) >= 0)
2624 /* Recorded position is not in an overlay string, but in another
2625 string. This can only be a string from a `display' property.
2626 IT should already be filled with that string. */
2627 it
->current
.string_pos
= pos
->string_pos
;
2628 xassert (STRINGP (it
->string
));
2631 /* Restore position in display vector translations, control
2632 character translations or ellipses. */
2633 if (pos
->dpvec_index
>= 0)
2635 if (it
->dpvec
== NULL
)
2636 get_next_display_element (it
);
2637 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
2638 it
->current
.dpvec_index
= pos
->dpvec_index
;
2642 return !overlay_strings_with_newlines
;
2646 /* Initialize IT for stepping through current_buffer in window W
2647 starting at ROW->start. */
2650 init_to_row_start (it
, w
, row
)
2653 struct glyph_row
*row
;
2655 init_from_display_pos (it
, w
, &row
->start
);
2656 it
->start
= row
->start
;
2657 it
->continuation_lines_width
= row
->continuation_lines_width
;
2662 /* Initialize IT for stepping through current_buffer in window W
2663 starting in the line following ROW, i.e. starting at ROW->end.
2664 Value is zero if there are overlay strings with newlines at ROW's
2668 init_to_row_end (it
, w
, row
)
2671 struct glyph_row
*row
;
2675 if (init_from_display_pos (it
, w
, &row
->end
))
2677 if (row
->continued_p
)
2678 it
->continuation_lines_width
2679 = row
->continuation_lines_width
+ row
->pixel_width
;
2690 /***********************************************************************
2692 ***********************************************************************/
2694 /* Called when IT reaches IT->stop_charpos. Handle text property and
2695 overlay changes. Set IT->stop_charpos to the next position where
2702 enum prop_handled handled
;
2703 int handle_overlay_change_p
= 1;
2707 it
->current
.dpvec_index
= -1;
2709 /* Use face of preceding text for ellipsis (if invisible) */
2710 if (it
->selective_display_ellipsis_p
)
2711 it
->saved_face_id
= it
->face_id
;
2715 handled
= HANDLED_NORMALLY
;
2717 /* Call text property handlers. */
2718 for (p
= it_props
; p
->handler
; ++p
)
2720 handled
= p
->handler (it
);
2722 if (handled
== HANDLED_RECOMPUTE_PROPS
)
2724 else if (handled
== HANDLED_RETURN
)
2726 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
2727 handle_overlay_change_p
= 0;
2730 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
2732 /* Don't check for overlay strings below when set to deliver
2733 characters from a display vector. */
2734 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
2735 handle_overlay_change_p
= 0;
2737 /* Handle overlay changes. */
2738 if (handle_overlay_change_p
)
2739 handled
= handle_overlay_change (it
);
2741 /* Determine where to stop next. */
2742 if (handled
== HANDLED_NORMALLY
)
2743 compute_stop_pos (it
);
2746 while (handled
== HANDLED_RECOMPUTE_PROPS
);
2750 /* Compute IT->stop_charpos from text property and overlay change
2751 information for IT's current position. */
2754 compute_stop_pos (it
)
2757 register INTERVAL iv
, next_iv
;
2758 Lisp_Object object
, limit
, position
;
2760 /* If nowhere else, stop at the end. */
2761 it
->stop_charpos
= it
->end_charpos
;
2763 if (STRINGP (it
->string
))
2765 /* Strings are usually short, so don't limit the search for
2767 object
= it
->string
;
2769 position
= make_number (IT_STRING_CHARPOS (*it
));
2775 /* If next overlay change is in front of the current stop pos
2776 (which is IT->end_charpos), stop there. Note: value of
2777 next_overlay_change is point-max if no overlay change
2779 charpos
= next_overlay_change (IT_CHARPOS (*it
));
2780 if (charpos
< it
->stop_charpos
)
2781 it
->stop_charpos
= charpos
;
2783 /* If showing the region, we have to stop at the region
2784 start or end because the face might change there. */
2785 if (it
->region_beg_charpos
> 0)
2787 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
2788 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
2789 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
2790 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
2793 /* Set up variables for computing the stop position from text
2794 property changes. */
2795 XSETBUFFER (object
, current_buffer
);
2796 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
2797 position
= make_number (IT_CHARPOS (*it
));
2801 /* Get the interval containing IT's position. Value is a null
2802 interval if there isn't such an interval. */
2803 iv
= validate_interval_range (object
, &position
, &position
, 0);
2804 if (!NULL_INTERVAL_P (iv
))
2806 Lisp_Object values_here
[LAST_PROP_IDX
];
2809 /* Get properties here. */
2810 for (p
= it_props
; p
->handler
; ++p
)
2811 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
2813 /* Look for an interval following iv that has different
2815 for (next_iv
= next_interval (iv
);
2816 (!NULL_INTERVAL_P (next_iv
)
2818 || XFASTINT (limit
) > next_iv
->position
));
2819 next_iv
= next_interval (next_iv
))
2821 for (p
= it_props
; p
->handler
; ++p
)
2823 Lisp_Object new_value
;
2825 new_value
= textget (next_iv
->plist
, *p
->name
);
2826 if (!EQ (values_here
[p
->idx
], new_value
))
2834 if (!NULL_INTERVAL_P (next_iv
))
2836 if (INTEGERP (limit
)
2837 && next_iv
->position
>= XFASTINT (limit
))
2838 /* No text property change up to limit. */
2839 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
2841 /* Text properties change in next_iv. */
2842 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
2846 xassert (STRINGP (it
->string
)
2847 || (it
->stop_charpos
>= BEGV
2848 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
2852 /* Return the position of the next overlay change after POS in
2853 current_buffer. Value is point-max if no overlay change
2854 follows. This is like `next-overlay-change' but doesn't use
2858 next_overlay_change (pos
)
2863 Lisp_Object
*overlays
;
2866 /* Get all overlays at the given position. */
2867 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
2869 /* If any of these overlays ends before endpos,
2870 use its ending point instead. */
2871 for (i
= 0; i
< noverlays
; ++i
)
2876 oend
= OVERLAY_END (overlays
[i
]);
2877 oendpos
= OVERLAY_POSITION (oend
);
2878 endpos
= min (endpos
, oendpos
);
2886 /***********************************************************************
2888 ***********************************************************************/
2890 /* Handle changes in the `fontified' property of the current buffer by
2891 calling hook functions from Qfontification_functions to fontify
2894 static enum prop_handled
2895 handle_fontified_prop (it
)
2898 Lisp_Object prop
, pos
;
2899 enum prop_handled handled
= HANDLED_NORMALLY
;
2901 /* Get the value of the `fontified' property at IT's current buffer
2902 position. (The `fontified' property doesn't have a special
2903 meaning in strings.) If the value is nil, call functions from
2904 Qfontification_functions. */
2905 if (!STRINGP (it
->string
)
2907 && !NILP (Vfontification_functions
)
2908 && !NILP (Vrun_hooks
)
2909 && (pos
= make_number (IT_CHARPOS (*it
)),
2910 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
2913 int count
= SPECPDL_INDEX ();
2916 val
= Vfontification_functions
;
2917 specbind (Qfontification_functions
, Qnil
);
2919 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2920 safe_call1 (val
, pos
);
2923 Lisp_Object globals
, fn
;
2924 struct gcpro gcpro1
, gcpro2
;
2927 GCPRO2 (val
, globals
);
2929 for (; CONSP (val
); val
= XCDR (val
))
2935 /* A value of t indicates this hook has a local
2936 binding; it means to run the global binding too.
2937 In a global value, t should not occur. If it
2938 does, we must ignore it to avoid an endless
2940 for (globals
= Fdefault_value (Qfontification_functions
);
2942 globals
= XCDR (globals
))
2944 fn
= XCAR (globals
);
2946 safe_call1 (fn
, pos
);
2950 safe_call1 (fn
, pos
);
2956 unbind_to (count
, Qnil
);
2958 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
2959 something. This avoids an endless loop if they failed to
2960 fontify the text for which reason ever. */
2961 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
2962 handled
= HANDLED_RECOMPUTE_PROPS
;
2970 /***********************************************************************
2972 ***********************************************************************/
2974 /* Set up iterator IT from face properties at its current position.
2975 Called from handle_stop. */
2977 static enum prop_handled
2978 handle_face_prop (it
)
2981 int new_face_id
, next_stop
;
2983 if (!STRINGP (it
->string
))
2986 = face_at_buffer_position (it
->w
,
2988 it
->region_beg_charpos
,
2989 it
->region_end_charpos
,
2992 + TEXT_PROP_DISTANCE_LIMIT
),
2995 /* Is this a start of a run of characters with box face?
2996 Caveat: this can be called for a freshly initialized
2997 iterator; face_id is -1 in this case. We know that the new
2998 face will not change until limit, i.e. if the new face has a
2999 box, all characters up to limit will have one. But, as
3000 usual, we don't know whether limit is really the end. */
3001 if (new_face_id
!= it
->face_id
)
3003 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3005 /* If new face has a box but old face has not, this is
3006 the start of a run of characters with box, i.e. it has
3007 a shadow on the left side. The value of face_id of the
3008 iterator will be -1 if this is the initial call that gets
3009 the face. In this case, we have to look in front of IT's
3010 position and see whether there is a face != new_face_id. */
3011 it
->start_of_box_run_p
3012 = (new_face
->box
!= FACE_NO_BOX
3013 && (it
->face_id
>= 0
3014 || IT_CHARPOS (*it
) == BEG
3015 || new_face_id
!= face_before_it_pos (it
)));
3016 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3021 int base_face_id
, bufpos
;
3023 if (it
->current
.overlay_string_index
>= 0)
3024 bufpos
= IT_CHARPOS (*it
);
3028 /* For strings from a buffer, i.e. overlay strings or strings
3029 from a `display' property, use the face at IT's current
3030 buffer position as the base face to merge with, so that
3031 overlay strings appear in the same face as surrounding
3032 text, unless they specify their own faces. */
3033 base_face_id
= underlying_face_id (it
);
3035 new_face_id
= face_at_string_position (it
->w
,
3037 IT_STRING_CHARPOS (*it
),
3039 it
->region_beg_charpos
,
3040 it
->region_end_charpos
,
3044 #if 0 /* This shouldn't be neccessary. Let's check it. */
3045 /* If IT is used to display a mode line we would really like to
3046 use the mode line face instead of the frame's default face. */
3047 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3048 && new_face_id
== DEFAULT_FACE_ID
)
3049 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3052 /* Is this a start of a run of characters with box? Caveat:
3053 this can be called for a freshly allocated iterator; face_id
3054 is -1 is this case. We know that the new face will not
3055 change until the next check pos, i.e. if the new face has a
3056 box, all characters up to that position will have a
3057 box. But, as usual, we don't know whether that position
3058 is really the end. */
3059 if (new_face_id
!= it
->face_id
)
3061 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3062 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3064 /* If new face has a box but old face hasn't, this is the
3065 start of a run of characters with box, i.e. it has a
3066 shadow on the left side. */
3067 it
->start_of_box_run_p
3068 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3069 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3073 it
->face_id
= new_face_id
;
3074 return HANDLED_NORMALLY
;
3078 /* Return the ID of the face ``underlying'' IT's current position,
3079 which is in a string. If the iterator is associated with a
3080 buffer, return the face at IT's current buffer position.
3081 Otherwise, use the iterator's base_face_id. */
3084 underlying_face_id (it
)
3087 int face_id
= it
->base_face_id
, i
;
3089 xassert (STRINGP (it
->string
));
3091 for (i
= it
->sp
- 1; i
>= 0; --i
)
3092 if (NILP (it
->stack
[i
].string
))
3093 face_id
= it
->stack
[i
].face_id
;
3099 /* Compute the face one character before or after the current position
3100 of IT. BEFORE_P non-zero means get the face in front of IT's
3101 position. Value is the id of the face. */
3104 face_before_or_after_it_pos (it
, before_p
)
3109 int next_check_charpos
;
3110 struct text_pos pos
;
3112 xassert (it
->s
== NULL
);
3114 if (STRINGP (it
->string
))
3116 int bufpos
, base_face_id
;
3118 /* No face change past the end of the string (for the case
3119 we are padding with spaces). No face change before the
3121 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3122 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3125 /* Set pos to the position before or after IT's current position. */
3127 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3129 /* For composition, we must check the character after the
3131 pos
= (it
->what
== IT_COMPOSITION
3132 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3133 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3135 if (it
->current
.overlay_string_index
>= 0)
3136 bufpos
= IT_CHARPOS (*it
);
3140 base_face_id
= underlying_face_id (it
);
3142 /* Get the face for ASCII, or unibyte. */
3143 face_id
= face_at_string_position (it
->w
,
3147 it
->region_beg_charpos
,
3148 it
->region_end_charpos
,
3149 &next_check_charpos
,
3152 /* Correct the face for charsets different from ASCII. Do it
3153 for the multibyte case only. The face returned above is
3154 suitable for unibyte text if IT->string is unibyte. */
3155 if (STRING_MULTIBYTE (it
->string
))
3157 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3158 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3160 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3162 c
= string_char_and_length (p
, rest
, &len
);
3163 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3168 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3169 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3172 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3173 pos
= it
->current
.pos
;
3176 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3179 if (it
->what
== IT_COMPOSITION
)
3180 /* For composition, we must check the position after the
3182 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3184 INC_TEXT_POS (pos
, it
->multibyte_p
);
3187 /* Determine face for CHARSET_ASCII, or unibyte. */
3188 face_id
= face_at_buffer_position (it
->w
,
3190 it
->region_beg_charpos
,
3191 it
->region_end_charpos
,
3192 &next_check_charpos
,
3195 /* Correct the face for charsets different from ASCII. Do it
3196 for the multibyte case only. The face returned above is
3197 suitable for unibyte text if current_buffer is unibyte. */
3198 if (it
->multibyte_p
)
3200 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3201 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3202 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
3211 /***********************************************************************
3213 ***********************************************************************/
3215 /* Set up iterator IT from invisible properties at its current
3216 position. Called from handle_stop. */
3218 static enum prop_handled
3219 handle_invisible_prop (it
)
3222 enum prop_handled handled
= HANDLED_NORMALLY
;
3224 if (STRINGP (it
->string
))
3226 extern Lisp_Object Qinvisible
;
3227 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3229 /* Get the value of the invisible text property at the
3230 current position. Value will be nil if there is no such
3232 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3233 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3236 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3238 handled
= HANDLED_RECOMPUTE_PROPS
;
3240 /* Get the position at which the next change of the
3241 invisible text property can be found in IT->string.
3242 Value will be nil if the property value is the same for
3243 all the rest of IT->string. */
3244 XSETINT (limit
, SCHARS (it
->string
));
3245 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3248 /* Text at current position is invisible. The next
3249 change in the property is at position end_charpos.
3250 Move IT's current position to that position. */
3251 if (INTEGERP (end_charpos
)
3252 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3254 struct text_pos old
;
3255 old
= it
->current
.string_pos
;
3256 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3257 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3261 /* The rest of the string is invisible. If this is an
3262 overlay string, proceed with the next overlay string
3263 or whatever comes and return a character from there. */
3264 if (it
->current
.overlay_string_index
>= 0)
3266 next_overlay_string (it
);
3267 /* Don't check for overlay strings when we just
3268 finished processing them. */
3269 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3273 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3274 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3281 int invis_p
, newpos
, next_stop
, start_charpos
;
3282 Lisp_Object pos
, prop
, overlay
;
3284 /* First of all, is there invisible text at this position? */
3285 start_charpos
= IT_CHARPOS (*it
);
3286 pos
= make_number (IT_CHARPOS (*it
));
3287 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3289 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3291 /* If we are on invisible text, skip over it. */
3292 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3294 /* Record whether we have to display an ellipsis for the
3296 int display_ellipsis_p
= invis_p
== 2;
3298 handled
= HANDLED_RECOMPUTE_PROPS
;
3300 /* Loop skipping over invisible text. The loop is left at
3301 ZV or with IT on the first char being visible again. */
3304 /* Try to skip some invisible text. Return value is the
3305 position reached which can be equal to IT's position
3306 if there is nothing invisible here. This skips both
3307 over invisible text properties and overlays with
3308 invisible property. */
3309 newpos
= skip_invisible (IT_CHARPOS (*it
),
3310 &next_stop
, ZV
, it
->window
);
3312 /* If we skipped nothing at all we weren't at invisible
3313 text in the first place. If everything to the end of
3314 the buffer was skipped, end the loop. */
3315 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3319 /* We skipped some characters but not necessarily
3320 all there are. Check if we ended up on visible
3321 text. Fget_char_property returns the property of
3322 the char before the given position, i.e. if we
3323 get invis_p = 0, this means that the char at
3324 newpos is visible. */
3325 pos
= make_number (newpos
);
3326 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3327 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3330 /* If we ended up on invisible text, proceed to
3331 skip starting with next_stop. */
3333 IT_CHARPOS (*it
) = next_stop
;
3337 /* The position newpos is now either ZV or on visible text. */
3338 IT_CHARPOS (*it
) = newpos
;
3339 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3341 /* If there are before-strings at the start of invisible
3342 text, and the text is invisible because of a text
3343 property, arrange to show before-strings because 20.x did
3344 it that way. (If the text is invisible because of an
3345 overlay property instead of a text property, this is
3346 already handled in the overlay code.) */
3348 && get_overlay_strings (it
, start_charpos
))
3350 handled
= HANDLED_RECOMPUTE_PROPS
;
3351 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3353 else if (display_ellipsis_p
)
3354 setup_for_ellipsis (it
, 0);
3362 /* Make iterator IT return `...' next.
3363 Replaces LEN characters from buffer. */
3366 setup_for_ellipsis (it
, len
)
3370 /* Use the display table definition for `...'. Invalid glyphs
3371 will be handled by the method returning elements from dpvec. */
3372 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3374 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3375 it
->dpvec
= v
->contents
;
3376 it
->dpend
= v
->contents
+ v
->size
;
3380 /* Default `...'. */
3381 it
->dpvec
= default_invis_vector
;
3382 it
->dpend
= default_invis_vector
+ 3;
3385 it
->dpvec_char_len
= len
;
3386 it
->current
.dpvec_index
= 0;
3387 it
->dpvec_face_id
= -1;
3389 /* Remember the current face id in case glyphs specify faces.
3390 IT's face is restored in set_iterator_to_next.
3391 saved_face_id was set to preceding char's face in handle_stop. */
3392 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3393 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3395 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3401 /***********************************************************************
3403 ***********************************************************************/
3405 /* Set up iterator IT from `display' property at its current position.
3406 Called from handle_stop.
3407 We return HANDLED_RETURN if some part of the display property
3408 overrides the display of the buffer text itself.
3409 Otherwise we return HANDLED_NORMALLY. */
3411 static enum prop_handled
3412 handle_display_prop (it
)
3415 Lisp_Object prop
, object
;
3416 struct text_pos
*position
;
3417 /* Nonzero if some property replaces the display of the text itself. */
3418 int display_replaced_p
= 0;
3420 if (STRINGP (it
->string
))
3422 object
= it
->string
;
3423 position
= &it
->current
.string_pos
;
3427 object
= it
->w
->buffer
;
3428 position
= &it
->current
.pos
;
3431 /* Reset those iterator values set from display property values. */
3432 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3433 it
->space_width
= Qnil
;
3434 it
->font_height
= Qnil
;
3437 /* We don't support recursive `display' properties, i.e. string
3438 values that have a string `display' property, that have a string
3439 `display' property etc. */
3440 if (!it
->string_from_display_prop_p
)
3441 it
->area
= TEXT_AREA
;
3443 prop
= Fget_char_property (make_number (position
->charpos
),
3446 return HANDLED_NORMALLY
;
3449 /* Simple properties. */
3450 && !EQ (XCAR (prop
), Qimage
)
3451 && !EQ (XCAR (prop
), Qspace
)
3452 && !EQ (XCAR (prop
), Qwhen
)
3453 && !EQ (XCAR (prop
), Qslice
)
3454 && !EQ (XCAR (prop
), Qspace_width
)
3455 && !EQ (XCAR (prop
), Qheight
)
3456 && !EQ (XCAR (prop
), Qraise
)
3457 /* Marginal area specifications. */
3458 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3459 && !EQ (XCAR (prop
), Qleft_fringe
)
3460 && !EQ (XCAR (prop
), Qright_fringe
)
3461 && !NILP (XCAR (prop
)))
3463 for (; CONSP (prop
); prop
= XCDR (prop
))
3465 if (handle_single_display_spec (it
, XCAR (prop
), object
,
3466 position
, display_replaced_p
))
3467 display_replaced_p
= 1;
3470 else if (VECTORP (prop
))
3473 for (i
= 0; i
< ASIZE (prop
); ++i
)
3474 if (handle_single_display_spec (it
, AREF (prop
, i
), object
,
3475 position
, display_replaced_p
))
3476 display_replaced_p
= 1;
3480 int ret
= handle_single_display_spec (it
, prop
, object
, position
, 0);
3481 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3482 return HANDLED_RECOMPUTE_PROPS
;
3484 display_replaced_p
= 1;
3487 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3491 /* Value is the position of the end of the `display' property starting
3492 at START_POS in OBJECT. */
3494 static struct text_pos
3495 display_prop_end (it
, object
, start_pos
)
3498 struct text_pos start_pos
;
3501 struct text_pos end_pos
;
3503 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
3504 Qdisplay
, object
, Qnil
);
3505 CHARPOS (end_pos
) = XFASTINT (end
);
3506 if (STRINGP (object
))
3507 compute_string_pos (&end_pos
, start_pos
, it
->string
);
3509 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
3515 /* Set up IT from a single `display' specification PROP. OBJECT
3516 is the object in which the `display' property was found. *POSITION
3517 is the position at which it was found. DISPLAY_REPLACED_P non-zero
3518 means that we previously saw a display specification which already
3519 replaced text display with something else, for example an image;
3520 we ignore such properties after the first one has been processed.
3522 If PROP is a `space' or `image' specification, and in some other
3523 cases too, set *POSITION to the position where the `display'
3526 Value is non-zero if something was found which replaces the display
3527 of buffer or string text. Specifically, the value is -1 if that
3528 "something" is "nothing". */
3531 handle_single_display_spec (it
, spec
, object
, position
,
3532 display_replaced_before_p
)
3536 struct text_pos
*position
;
3537 int display_replaced_before_p
;
3540 Lisp_Object location
, value
;
3541 struct text_pos start_pos
;
3544 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
3545 If the result is non-nil, use VALUE instead of SPEC. */
3547 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
3556 if (!NILP (form
) && !EQ (form
, Qt
))
3558 int count
= SPECPDL_INDEX ();
3559 struct gcpro gcpro1
;
3561 /* Bind `object' to the object having the `display' property, a
3562 buffer or string. Bind `position' to the position in the
3563 object where the property was found, and `buffer-position'
3564 to the current position in the buffer. */
3565 specbind (Qobject
, object
);
3566 specbind (Qposition
, make_number (CHARPOS (*position
)));
3567 specbind (Qbuffer_position
,
3568 make_number (STRINGP (object
)
3569 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
3571 form
= safe_eval (form
);
3573 unbind_to (count
, Qnil
);
3579 /* Handle `(height HEIGHT)' specifications. */
3581 && EQ (XCAR (spec
), Qheight
)
3582 && CONSP (XCDR (spec
)))
3584 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3587 it
->font_height
= XCAR (XCDR (spec
));
3588 if (!NILP (it
->font_height
))
3590 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3591 int new_height
= -1;
3593 if (CONSP (it
->font_height
)
3594 && (EQ (XCAR (it
->font_height
), Qplus
)
3595 || EQ (XCAR (it
->font_height
), Qminus
))
3596 && CONSP (XCDR (it
->font_height
))
3597 && INTEGERP (XCAR (XCDR (it
->font_height
))))
3599 /* `(+ N)' or `(- N)' where N is an integer. */
3600 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
3601 if (EQ (XCAR (it
->font_height
), Qplus
))
3603 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
3605 else if (FUNCTIONP (it
->font_height
))
3607 /* Call function with current height as argument.
3608 Value is the new height. */
3610 height
= safe_call1 (it
->font_height
,
3611 face
->lface
[LFACE_HEIGHT_INDEX
]);
3612 if (NUMBERP (height
))
3613 new_height
= XFLOATINT (height
);
3615 else if (NUMBERP (it
->font_height
))
3617 /* Value is a multiple of the canonical char height. */
3620 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
3621 new_height
= (XFLOATINT (it
->font_height
)
3622 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
3626 /* Evaluate IT->font_height with `height' bound to the
3627 current specified height to get the new height. */
3628 int count
= SPECPDL_INDEX ();
3630 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
3631 value
= safe_eval (it
->font_height
);
3632 unbind_to (count
, Qnil
);
3634 if (NUMBERP (value
))
3635 new_height
= XFLOATINT (value
);
3639 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
3645 /* Handle `(space_width WIDTH)'. */
3647 && EQ (XCAR (spec
), Qspace_width
)
3648 && CONSP (XCDR (spec
)))
3650 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3653 value
= XCAR (XCDR (spec
));
3654 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
3655 it
->space_width
= value
;
3660 /* Handle `(slice X Y WIDTH HEIGHT)'. */
3662 && EQ (XCAR (spec
), Qslice
))
3666 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3669 if (tem
= XCDR (spec
), CONSP (tem
))
3671 it
->slice
.x
= XCAR (tem
);
3672 if (tem
= XCDR (tem
), CONSP (tem
))
3674 it
->slice
.y
= XCAR (tem
);
3675 if (tem
= XCDR (tem
), CONSP (tem
))
3677 it
->slice
.width
= XCAR (tem
);
3678 if (tem
= XCDR (tem
), CONSP (tem
))
3679 it
->slice
.height
= XCAR (tem
);
3687 /* Handle `(raise FACTOR)'. */
3689 && EQ (XCAR (spec
), Qraise
)
3690 && CONSP (XCDR (spec
)))
3692 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3695 #ifdef HAVE_WINDOW_SYSTEM
3696 value
= XCAR (XCDR (spec
));
3697 if (NUMBERP (value
))
3699 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3700 it
->voffset
= - (XFLOATINT (value
)
3701 * (FONT_HEIGHT (face
->font
)));
3703 #endif /* HAVE_WINDOW_SYSTEM */
3708 /* Don't handle the other kinds of display specifications
3709 inside a string that we got from a `display' property. */
3710 if (it
->string_from_display_prop_p
)
3713 /* Characters having this form of property are not displayed, so
3714 we have to find the end of the property. */
3715 start_pos
= *position
;
3716 *position
= display_prop_end (it
, object
, start_pos
);
3719 /* Stop the scan at that end position--we assume that all
3720 text properties change there. */
3721 it
->stop_charpos
= position
->charpos
;
3723 /* Handle `(left-fringe BITMAP [FACE])'
3724 and `(right-fringe BITMAP [FACE])'. */
3726 && (EQ (XCAR (spec
), Qleft_fringe
)
3727 || EQ (XCAR (spec
), Qright_fringe
))
3728 && CONSP (XCDR (spec
)))
3730 int face_id
= DEFAULT_FACE_ID
;
3733 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
3734 /* If we return here, POSITION has been advanced
3735 across the text with this property. */
3738 #ifdef HAVE_WINDOW_SYSTEM
3739 value
= XCAR (XCDR (spec
));
3740 if (!SYMBOLP (value
)
3741 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
3742 /* If we return here, POSITION has been advanced
3743 across the text with this property. */
3746 if (CONSP (XCDR (XCDR (spec
))))
3748 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
3749 int face_id2
= lookup_derived_face (it
->f
, face_name
,
3750 'A', FRINGE_FACE_ID
, 0);
3755 /* Save current settings of IT so that we can restore them
3756 when we are finished with the glyph property value. */
3760 it
->area
= TEXT_AREA
;
3761 it
->what
= IT_IMAGE
;
3762 it
->image_id
= -1; /* no image */
3763 it
->position
= start_pos
;
3764 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3765 it
->method
= GET_FROM_IMAGE
;
3766 it
->face_id
= face_id
;
3768 /* Say that we haven't consumed the characters with
3769 `display' property yet. The call to pop_it in
3770 set_iterator_to_next will clean this up. */
3771 *position
= start_pos
;
3773 if (EQ (XCAR (spec
), Qleft_fringe
))
3775 it
->left_user_fringe_bitmap
= fringe_bitmap
;
3776 it
->left_user_fringe_face_id
= face_id
;
3780 it
->right_user_fringe_bitmap
= fringe_bitmap
;
3781 it
->right_user_fringe_face_id
= face_id
;
3783 #endif /* HAVE_WINDOW_SYSTEM */
3787 /* Prepare to handle `((margin left-margin) ...)',
3788 `((margin right-margin) ...)' and `((margin nil) ...)'
3789 prefixes for display specifications. */
3790 location
= Qunbound
;
3791 if (CONSP (spec
) && CONSP (XCAR (spec
)))
3795 value
= XCDR (spec
);
3797 value
= XCAR (value
);
3800 if (EQ (XCAR (tem
), Qmargin
)
3801 && (tem
= XCDR (tem
),
3802 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
3804 || EQ (tem
, Qleft_margin
)
3805 || EQ (tem
, Qright_margin
))))
3809 if (EQ (location
, Qunbound
))
3815 /* After this point, VALUE is the property after any
3816 margin prefix has been stripped. It must be a string,
3817 an image specification, or `(space ...)'.
3819 LOCATION specifies where to display: `left-margin',
3820 `right-margin' or nil. */
3822 valid_p
= (STRINGP (value
)
3823 #ifdef HAVE_WINDOW_SYSTEM
3824 || (!FRAME_TERMCAP_P (it
->f
) && valid_image_p (value
))
3825 #endif /* not HAVE_WINDOW_SYSTEM */
3826 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
3828 if (valid_p
&& !display_replaced_before_p
)
3830 /* Save current settings of IT so that we can restore them
3831 when we are finished with the glyph property value. */
3834 if (NILP (location
))
3835 it
->area
= TEXT_AREA
;
3836 else if (EQ (location
, Qleft_margin
))
3837 it
->area
= LEFT_MARGIN_AREA
;
3839 it
->area
= RIGHT_MARGIN_AREA
;
3841 if (STRINGP (value
))
3843 if (SCHARS (value
) == 0)
3846 return -1; /* Replaced by "", i.e. nothing. */
3849 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
3850 it
->current
.overlay_string_index
= -1;
3851 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
3852 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
3853 it
->method
= GET_FROM_STRING
;
3854 it
->stop_charpos
= 0;
3855 it
->string_from_display_prop_p
= 1;
3856 /* Say that we haven't consumed the characters with
3857 `display' property yet. The call to pop_it in
3858 set_iterator_to_next will clean this up. */
3859 *position
= start_pos
;
3861 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
3863 it
->method
= GET_FROM_STRETCH
;
3865 it
->current
.pos
= it
->position
= start_pos
;
3867 #ifdef HAVE_WINDOW_SYSTEM
3870 it
->what
= IT_IMAGE
;
3871 it
->image_id
= lookup_image (it
->f
, value
);
3872 it
->position
= start_pos
;
3873 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
3874 it
->method
= GET_FROM_IMAGE
;
3876 /* Say that we haven't consumed the characters with
3877 `display' property yet. The call to pop_it in
3878 set_iterator_to_next will clean this up. */
3879 *position
= start_pos
;
3881 #endif /* HAVE_WINDOW_SYSTEM */
3886 /* Invalid property or property not supported. Restore
3887 POSITION to what it was before. */
3888 *position
= start_pos
;
3893 /* Check if SPEC is a display specification value whose text should be
3894 treated as intangible. */
3897 single_display_spec_intangible_p (prop
)
3900 /* Skip over `when FORM'. */
3901 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3915 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
3916 we don't need to treat text as intangible. */
3917 if (EQ (XCAR (prop
), Qmargin
))
3925 || EQ (XCAR (prop
), Qleft_margin
)
3926 || EQ (XCAR (prop
), Qright_margin
))
3930 return (CONSP (prop
)
3931 && (EQ (XCAR (prop
), Qimage
)
3932 || EQ (XCAR (prop
), Qspace
)));
3936 /* Check if PROP is a display property value whose text should be
3937 treated as intangible. */
3940 display_prop_intangible_p (prop
)
3944 && CONSP (XCAR (prop
))
3945 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
3947 /* A list of sub-properties. */
3948 while (CONSP (prop
))
3950 if (single_display_spec_intangible_p (XCAR (prop
)))
3955 else if (VECTORP (prop
))
3957 /* A vector of sub-properties. */
3959 for (i
= 0; i
< ASIZE (prop
); ++i
)
3960 if (single_display_spec_intangible_p (AREF (prop
, i
)))
3964 return single_display_spec_intangible_p (prop
);
3970 /* Return 1 if PROP is a display sub-property value containing STRING. */
3973 single_display_spec_string_p (prop
, string
)
3974 Lisp_Object prop
, string
;
3976 if (EQ (string
, prop
))
3979 /* Skip over `when FORM'. */
3980 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
3989 /* Skip over `margin LOCATION'. */
3990 if (EQ (XCAR (prop
), Qmargin
))
4001 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4005 /* Return 1 if STRING appears in the `display' property PROP. */
4008 display_prop_string_p (prop
, string
)
4009 Lisp_Object prop
, string
;
4012 && CONSP (XCAR (prop
))
4013 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4015 /* A list of sub-properties. */
4016 while (CONSP (prop
))
4018 if (single_display_spec_string_p (XCAR (prop
), string
))
4023 else if (VECTORP (prop
))
4025 /* A vector of sub-properties. */
4027 for (i
= 0; i
< ASIZE (prop
); ++i
)
4028 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4032 return single_display_spec_string_p (prop
, string
);
4038 /* Determine from which buffer position in W's buffer STRING comes
4039 from. AROUND_CHARPOS is an approximate position where it could
4040 be from. Value is the buffer position or 0 if it couldn't be
4043 W's buffer must be current.
4045 This function is necessary because we don't record buffer positions
4046 in glyphs generated from strings (to keep struct glyph small).
4047 This function may only use code that doesn't eval because it is
4048 called asynchronously from note_mouse_highlight. */
4051 string_buffer_position (w
, string
, around_charpos
)
4056 Lisp_Object limit
, prop
, pos
;
4057 const int MAX_DISTANCE
= 1000;
4060 pos
= make_number (around_charpos
);
4061 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4062 while (!found
&& !EQ (pos
, limit
))
4064 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4065 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4068 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4073 pos
= make_number (around_charpos
);
4074 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4075 while (!found
&& !EQ (pos
, limit
))
4077 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4078 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4081 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4086 return found
? XINT (pos
) : 0;
4091 /***********************************************************************
4092 `composition' property
4093 ***********************************************************************/
4095 /* Set up iterator IT from `composition' property at its current
4096 position. Called from handle_stop. */
4098 static enum prop_handled
4099 handle_composition_prop (it
)
4102 Lisp_Object prop
, string
;
4103 int pos
, pos_byte
, end
;
4104 enum prop_handled handled
= HANDLED_NORMALLY
;
4106 if (STRINGP (it
->string
))
4108 pos
= IT_STRING_CHARPOS (*it
);
4109 pos_byte
= IT_STRING_BYTEPOS (*it
);
4110 string
= it
->string
;
4114 pos
= IT_CHARPOS (*it
);
4115 pos_byte
= IT_BYTEPOS (*it
);
4119 /* If there's a valid composition and point is not inside of the
4120 composition (in the case that the composition is from the current
4121 buffer), draw a glyph composed from the composition components. */
4122 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
4123 && COMPOSITION_VALID_P (pos
, end
, prop
)
4124 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
4126 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
4130 it
->method
= GET_FROM_COMPOSITION
;
4132 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4133 /* For a terminal, draw only the first character of the
4135 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
4136 it
->len
= (STRINGP (it
->string
)
4137 ? string_char_to_byte (it
->string
, end
)
4138 : CHAR_TO_BYTE (end
)) - pos_byte
;
4139 it
->stop_charpos
= end
;
4140 handled
= HANDLED_RETURN
;
4149 /***********************************************************************
4151 ***********************************************************************/
4153 /* The following structure is used to record overlay strings for
4154 later sorting in load_overlay_strings. */
4156 struct overlay_entry
4158 Lisp_Object overlay
;
4165 /* Set up iterator IT from overlay strings at its current position.
4166 Called from handle_stop. */
4168 static enum prop_handled
4169 handle_overlay_change (it
)
4172 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4173 return HANDLED_RECOMPUTE_PROPS
;
4175 return HANDLED_NORMALLY
;
4179 /* Set up the next overlay string for delivery by IT, if there is an
4180 overlay string to deliver. Called by set_iterator_to_next when the
4181 end of the current overlay string is reached. If there are more
4182 overlay strings to display, IT->string and
4183 IT->current.overlay_string_index are set appropriately here.
4184 Otherwise IT->string is set to nil. */
4187 next_overlay_string (it
)
4190 ++it
->current
.overlay_string_index
;
4191 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4193 /* No more overlay strings. Restore IT's settings to what
4194 they were before overlay strings were processed, and
4195 continue to deliver from current_buffer. */
4196 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4199 xassert (it
->stop_charpos
>= BEGV
4200 && it
->stop_charpos
<= it
->end_charpos
);
4202 it
->current
.overlay_string_index
= -1;
4203 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
4204 it
->n_overlay_strings
= 0;
4205 it
->method
= GET_FROM_BUFFER
;
4207 /* If we're at the end of the buffer, record that we have
4208 processed the overlay strings there already, so that
4209 next_element_from_buffer doesn't try it again. */
4210 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
4211 it
->overlay_strings_at_end_processed_p
= 1;
4213 /* If we have to display `...' for invisible text, set
4214 the iterator up for that. */
4215 if (display_ellipsis_p
)
4216 setup_for_ellipsis (it
, 0);
4220 /* There are more overlay strings to process. If
4221 IT->current.overlay_string_index has advanced to a position
4222 where we must load IT->overlay_strings with more strings, do
4224 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4226 if (it
->current
.overlay_string_index
&& i
== 0)
4227 load_overlay_strings (it
, 0);
4229 /* Initialize IT to deliver display elements from the overlay
4231 it
->string
= it
->overlay_strings
[i
];
4232 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4233 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4234 it
->method
= GET_FROM_STRING
;
4235 it
->stop_charpos
= 0;
4242 /* Compare two overlay_entry structures E1 and E2. Used as a
4243 comparison function for qsort in load_overlay_strings. Overlay
4244 strings for the same position are sorted so that
4246 1. All after-strings come in front of before-strings, except
4247 when they come from the same overlay.
4249 2. Within after-strings, strings are sorted so that overlay strings
4250 from overlays with higher priorities come first.
4252 2. Within before-strings, strings are sorted so that overlay
4253 strings from overlays with higher priorities come last.
4255 Value is analogous to strcmp. */
4259 compare_overlay_entries (e1
, e2
)
4262 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4263 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4266 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4268 /* Let after-strings appear in front of before-strings if
4269 they come from different overlays. */
4270 if (EQ (entry1
->overlay
, entry2
->overlay
))
4271 result
= entry1
->after_string_p
? 1 : -1;
4273 result
= entry1
->after_string_p
? -1 : 1;
4275 else if (entry1
->after_string_p
)
4276 /* After-strings sorted in order of decreasing priority. */
4277 result
= entry2
->priority
- entry1
->priority
;
4279 /* Before-strings sorted in order of increasing priority. */
4280 result
= entry1
->priority
- entry2
->priority
;
4286 /* Load the vector IT->overlay_strings with overlay strings from IT's
4287 current buffer position, or from CHARPOS if that is > 0. Set
4288 IT->n_overlays to the total number of overlay strings found.
4290 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4291 a time. On entry into load_overlay_strings,
4292 IT->current.overlay_string_index gives the number of overlay
4293 strings that have already been loaded by previous calls to this
4296 IT->add_overlay_start contains an additional overlay start
4297 position to consider for taking overlay strings from, if non-zero.
4298 This position comes into play when the overlay has an `invisible'
4299 property, and both before and after-strings. When we've skipped to
4300 the end of the overlay, because of its `invisible' property, we
4301 nevertheless want its before-string to appear.
4302 IT->add_overlay_start will contain the overlay start position
4305 Overlay strings are sorted so that after-string strings come in
4306 front of before-string strings. Within before and after-strings,
4307 strings are sorted by overlay priority. See also function
4308 compare_overlay_entries. */
4311 load_overlay_strings (it
, charpos
)
4315 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4316 Lisp_Object overlay
, window
, str
, invisible
;
4317 struct Lisp_Overlay
*ov
;
4320 int n
= 0, i
, j
, invis_p
;
4321 struct overlay_entry
*entries
4322 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4325 charpos
= IT_CHARPOS (*it
);
4327 /* Append the overlay string STRING of overlay OVERLAY to vector
4328 `entries' which has size `size' and currently contains `n'
4329 elements. AFTER_P non-zero means STRING is an after-string of
4331 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4334 Lisp_Object priority; \
4338 int new_size = 2 * size; \
4339 struct overlay_entry *old = entries; \
4341 (struct overlay_entry *) alloca (new_size \
4342 * sizeof *entries); \
4343 bcopy (old, entries, size * sizeof *entries); \
4347 entries[n].string = (STRING); \
4348 entries[n].overlay = (OVERLAY); \
4349 priority = Foverlay_get ((OVERLAY), Qpriority); \
4350 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4351 entries[n].after_string_p = (AFTER_P); \
4356 /* Process overlay before the overlay center. */
4357 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4359 XSETMISC (overlay
, ov
);
4360 xassert (OVERLAYP (overlay
));
4361 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4362 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4367 /* Skip this overlay if it doesn't start or end at IT's current
4369 if (end
!= charpos
&& start
!= charpos
)
4372 /* Skip this overlay if it doesn't apply to IT->w. */
4373 window
= Foverlay_get (overlay
, Qwindow
);
4374 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4377 /* If the text ``under'' the overlay is invisible, both before-
4378 and after-strings from this overlay are visible; start and
4379 end position are indistinguishable. */
4380 invisible
= Foverlay_get (overlay
, Qinvisible
);
4381 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4383 /* If overlay has a non-empty before-string, record it. */
4384 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4385 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4387 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4389 /* If overlay has a non-empty after-string, record it. */
4390 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4391 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4393 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4396 /* Process overlays after the overlay center. */
4397 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4399 XSETMISC (overlay
, ov
);
4400 xassert (OVERLAYP (overlay
));
4401 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4402 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4404 if (start
> charpos
)
4407 /* Skip this overlay if it doesn't start or end at IT's current
4409 if (end
!= charpos
&& start
!= charpos
)
4412 /* Skip this overlay if it doesn't apply to IT->w. */
4413 window
= Foverlay_get (overlay
, Qwindow
);
4414 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4417 /* If the text ``under'' the overlay is invisible, it has a zero
4418 dimension, and both before- and after-strings apply. */
4419 invisible
= Foverlay_get (overlay
, Qinvisible
);
4420 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4422 /* If overlay has a non-empty before-string, record it. */
4423 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4424 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4426 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4428 /* If overlay has a non-empty after-string, record it. */
4429 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4430 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4432 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4435 #undef RECORD_OVERLAY_STRING
4439 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4441 /* Record the total number of strings to process. */
4442 it
->n_overlay_strings
= n
;
4444 /* IT->current.overlay_string_index is the number of overlay strings
4445 that have already been consumed by IT. Copy some of the
4446 remaining overlay strings to IT->overlay_strings. */
4448 j
= it
->current
.overlay_string_index
;
4449 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4450 it
->overlay_strings
[i
++] = entries
[j
++].string
;
4456 /* Get the first chunk of overlay strings at IT's current buffer
4457 position, or at CHARPOS if that is > 0. Value is non-zero if at
4458 least one overlay string was found. */
4461 get_overlay_strings (it
, charpos
)
4465 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
4466 process. This fills IT->overlay_strings with strings, and sets
4467 IT->n_overlay_strings to the total number of strings to process.
4468 IT->pos.overlay_string_index has to be set temporarily to zero
4469 because load_overlay_strings needs this; it must be set to -1
4470 when no overlay strings are found because a zero value would
4471 indicate a position in the first overlay string. */
4472 it
->current
.overlay_string_index
= 0;
4473 load_overlay_strings (it
, charpos
);
4475 /* If we found overlay strings, set up IT to deliver display
4476 elements from the first one. Otherwise set up IT to deliver
4477 from current_buffer. */
4478 if (it
->n_overlay_strings
)
4480 /* Make sure we know settings in current_buffer, so that we can
4481 restore meaningful values when we're done with the overlay
4483 compute_stop_pos (it
);
4484 xassert (it
->face_id
>= 0);
4486 /* Save IT's settings. They are restored after all overlay
4487 strings have been processed. */
4488 xassert (it
->sp
== 0);
4491 /* Set up IT to deliver display elements from the first overlay
4493 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4494 it
->string
= it
->overlay_strings
[0];
4495 it
->stop_charpos
= 0;
4496 xassert (STRINGP (it
->string
));
4497 it
->end_charpos
= SCHARS (it
->string
);
4498 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4499 it
->method
= GET_FROM_STRING
;
4504 it
->current
.overlay_string_index
= -1;
4505 it
->method
= GET_FROM_BUFFER
;
4510 /* Value is non-zero if we found at least one overlay string. */
4511 return STRINGP (it
->string
);
4516 /***********************************************************************
4517 Saving and restoring state
4518 ***********************************************************************/
4520 /* Save current settings of IT on IT->stack. Called, for example,
4521 before setting up IT for an overlay string, to be able to restore
4522 IT's settings to what they were after the overlay string has been
4529 struct iterator_stack_entry
*p
;
4531 xassert (it
->sp
< 2);
4532 p
= it
->stack
+ it
->sp
;
4534 p
->stop_charpos
= it
->stop_charpos
;
4535 xassert (it
->face_id
>= 0);
4536 p
->face_id
= it
->face_id
;
4537 p
->string
= it
->string
;
4538 p
->pos
= it
->current
;
4539 p
->end_charpos
= it
->end_charpos
;
4540 p
->string_nchars
= it
->string_nchars
;
4542 p
->multibyte_p
= it
->multibyte_p
;
4543 p
->slice
= it
->slice
;
4544 p
->space_width
= it
->space_width
;
4545 p
->font_height
= it
->font_height
;
4546 p
->voffset
= it
->voffset
;
4547 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
4548 p
->display_ellipsis_p
= 0;
4553 /* Restore IT's settings from IT->stack. Called, for example, when no
4554 more overlay strings must be processed, and we return to delivering
4555 display elements from a buffer, or when the end of a string from a
4556 `display' property is reached and we return to delivering display
4557 elements from an overlay string, or from a buffer. */
4563 struct iterator_stack_entry
*p
;
4565 xassert (it
->sp
> 0);
4567 p
= it
->stack
+ it
->sp
;
4568 it
->stop_charpos
= p
->stop_charpos
;
4569 it
->face_id
= p
->face_id
;
4570 it
->string
= p
->string
;
4571 it
->current
= p
->pos
;
4572 it
->end_charpos
= p
->end_charpos
;
4573 it
->string_nchars
= p
->string_nchars
;
4575 it
->multibyte_p
= p
->multibyte_p
;
4576 it
->slice
= p
->slice
;
4577 it
->space_width
= p
->space_width
;
4578 it
->font_height
= p
->font_height
;
4579 it
->voffset
= p
->voffset
;
4580 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
4585 /***********************************************************************
4587 ***********************************************************************/
4589 /* Set IT's current position to the previous line start. */
4592 back_to_previous_line_start (it
)
4595 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
4596 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
4600 /* Move IT to the next line start.
4602 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
4603 we skipped over part of the text (as opposed to moving the iterator
4604 continuously over the text). Otherwise, don't change the value
4607 Newlines may come from buffer text, overlay strings, or strings
4608 displayed via the `display' property. That's the reason we can't
4609 simply use find_next_newline_no_quit.
4611 Note that this function may not skip over invisible text that is so
4612 because of text properties and immediately follows a newline. If
4613 it would, function reseat_at_next_visible_line_start, when called
4614 from set_iterator_to_next, would effectively make invisible
4615 characters following a newline part of the wrong glyph row, which
4616 leads to wrong cursor motion. */
4619 forward_to_next_line_start (it
, skipped_p
)
4623 int old_selective
, newline_found_p
, n
;
4624 const int MAX_NEWLINE_DISTANCE
= 500;
4626 /* If already on a newline, just consume it to avoid unintended
4627 skipping over invisible text below. */
4628 if (it
->what
== IT_CHARACTER
4630 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
4632 set_iterator_to_next (it
, 0);
4637 /* Don't handle selective display in the following. It's (a)
4638 unnecessary because it's done by the caller, and (b) leads to an
4639 infinite recursion because next_element_from_ellipsis indirectly
4640 calls this function. */
4641 old_selective
= it
->selective
;
4644 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
4645 from buffer text. */
4646 for (n
= newline_found_p
= 0;
4647 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
4648 n
+= STRINGP (it
->string
) ? 0 : 1)
4650 if (!get_next_display_element (it
))
4652 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
4653 set_iterator_to_next (it
, 0);
4656 /* If we didn't find a newline near enough, see if we can use a
4658 if (!newline_found_p
)
4660 int start
= IT_CHARPOS (*it
);
4661 int limit
= find_next_newline_no_quit (start
, 1);
4664 xassert (!STRINGP (it
->string
));
4666 /* If there isn't any `display' property in sight, and no
4667 overlays, we can just use the position of the newline in
4669 if (it
->stop_charpos
>= limit
4670 || ((pos
= Fnext_single_property_change (make_number (start
),
4672 Qnil
, make_number (limit
)),
4674 && next_overlay_change (start
) == ZV
))
4676 IT_CHARPOS (*it
) = limit
;
4677 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
4678 *skipped_p
= newline_found_p
= 1;
4682 while (get_next_display_element (it
)
4683 && !newline_found_p
)
4685 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
4686 set_iterator_to_next (it
, 0);
4691 it
->selective
= old_selective
;
4692 return newline_found_p
;
4696 /* Set IT's current position to the previous visible line start. Skip
4697 invisible text that is so either due to text properties or due to
4698 selective display. Caution: this does not change IT->current_x and
4702 back_to_previous_visible_line_start (it
)
4705 while (IT_CHARPOS (*it
) > BEGV
)
4707 back_to_previous_line_start (it
);
4708 if (IT_CHARPOS (*it
) <= BEGV
)
4711 /* If selective > 0, then lines indented more than that values
4713 if (it
->selective
> 0
4714 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4715 (double) it
->selective
)) /* iftc */
4718 /* Check the newline before point for invisibility. */
4721 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
4722 Qinvisible
, it
->window
);
4723 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4727 /* If newline has a display property that replaces the newline with something
4728 else (image or text), find start of overlay or interval and continue search
4730 if (IT_CHARPOS (*it
) > BEGV
)
4732 struct it it2
= *it
;
4735 Lisp_Object val
, overlay
;
4737 pos
= --IT_CHARPOS (it2
);
4740 if (handle_display_prop (&it2
) == HANDLED_RETURN
4741 && !NILP (val
= get_char_property_and_overlay
4742 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
4743 && (OVERLAYP (overlay
)
4744 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
4745 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
4749 IT_CHARPOS (*it
) = beg
;
4750 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
4758 xassert (IT_CHARPOS (*it
) >= BEGV
);
4759 xassert (IT_CHARPOS (*it
) == BEGV
4760 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4765 /* Reseat iterator IT at the previous visible line start. Skip
4766 invisible text that is so either due to text properties or due to
4767 selective display. At the end, update IT's overlay information,
4768 face information etc. */
4771 reseat_at_previous_visible_line_start (it
)
4774 back_to_previous_visible_line_start (it
);
4775 reseat (it
, it
->current
.pos
, 1);
4780 /* Reseat iterator IT on the next visible line start in the current
4781 buffer. ON_NEWLINE_P non-zero means position IT on the newline
4782 preceding the line start. Skip over invisible text that is so
4783 because of selective display. Compute faces, overlays etc at the
4784 new position. Note that this function does not skip over text that
4785 is invisible because of text properties. */
4788 reseat_at_next_visible_line_start (it
, on_newline_p
)
4792 int newline_found_p
, skipped_p
= 0;
4794 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4796 /* Skip over lines that are invisible because they are indented
4797 more than the value of IT->selective. */
4798 if (it
->selective
> 0)
4799 while (IT_CHARPOS (*it
) < ZV
4800 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
4801 (double) it
->selective
)) /* iftc */
4803 xassert (FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
4804 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
4807 /* Position on the newline if that's what's requested. */
4808 if (on_newline_p
&& newline_found_p
)
4810 if (STRINGP (it
->string
))
4812 if (IT_STRING_CHARPOS (*it
) > 0)
4814 --IT_STRING_CHARPOS (*it
);
4815 --IT_STRING_BYTEPOS (*it
);
4818 else if (IT_CHARPOS (*it
) > BEGV
)
4822 reseat (it
, it
->current
.pos
, 0);
4826 reseat (it
, it
->current
.pos
, 0);
4833 /***********************************************************************
4834 Changing an iterator's position
4835 ***********************************************************************/
4837 /* Change IT's current position to POS in current_buffer. If FORCE_P
4838 is non-zero, always check for text properties at the new position.
4839 Otherwise, text properties are only looked up if POS >=
4840 IT->check_charpos of a property. */
4843 reseat (it
, pos
, force_p
)
4845 struct text_pos pos
;
4848 int original_pos
= IT_CHARPOS (*it
);
4850 reseat_1 (it
, pos
, 0);
4852 /* Determine where to check text properties. Avoid doing it
4853 where possible because text property lookup is very expensive. */
4855 || CHARPOS (pos
) > it
->stop_charpos
4856 || CHARPOS (pos
) < original_pos
)
4863 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
4864 IT->stop_pos to POS, also. */
4867 reseat_1 (it
, pos
, set_stop_p
)
4869 struct text_pos pos
;
4872 /* Don't call this function when scanning a C string. */
4873 xassert (it
->s
== NULL
);
4875 /* POS must be a reasonable value. */
4876 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
4878 it
->current
.pos
= it
->position
= pos
;
4879 XSETBUFFER (it
->object
, current_buffer
);
4880 it
->end_charpos
= ZV
;
4882 it
->current
.dpvec_index
= -1;
4883 it
->current
.overlay_string_index
= -1;
4884 IT_STRING_CHARPOS (*it
) = -1;
4885 IT_STRING_BYTEPOS (*it
) = -1;
4887 it
->method
= GET_FROM_BUFFER
;
4888 /* RMS: I added this to fix a bug in move_it_vertically_backward
4889 where it->area continued to relate to the starting point
4890 for the backward motion. Bug report from
4891 Nick Roberts <nick@nick.uklinux.net> on 19 May 2003.
4892 However, I am not sure whether reseat still does the right thing
4893 in general after this change. */
4894 it
->area
= TEXT_AREA
;
4895 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
4897 it
->face_before_selective_p
= 0;
4900 it
->stop_charpos
= CHARPOS (pos
);
4904 /* Set up IT for displaying a string, starting at CHARPOS in window W.
4905 If S is non-null, it is a C string to iterate over. Otherwise,
4906 STRING gives a Lisp string to iterate over.
4908 If PRECISION > 0, don't return more then PRECISION number of
4909 characters from the string.
4911 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
4912 characters have been returned. FIELD_WIDTH < 0 means an infinite
4915 MULTIBYTE = 0 means disable processing of multibyte characters,
4916 MULTIBYTE > 0 means enable it,
4917 MULTIBYTE < 0 means use IT->multibyte_p.
4919 IT must be initialized via a prior call to init_iterator before
4920 calling this function. */
4923 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
4928 int precision
, field_width
, multibyte
;
4930 /* No region in strings. */
4931 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
4933 /* No text property checks performed by default, but see below. */
4934 it
->stop_charpos
= -1;
4936 /* Set iterator position and end position. */
4937 bzero (&it
->current
, sizeof it
->current
);
4938 it
->current
.overlay_string_index
= -1;
4939 it
->current
.dpvec_index
= -1;
4940 xassert (charpos
>= 0);
4942 /* If STRING is specified, use its multibyteness, otherwise use the
4943 setting of MULTIBYTE, if specified. */
4945 it
->multibyte_p
= multibyte
> 0;
4949 xassert (STRINGP (string
));
4950 it
->string
= string
;
4952 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
4953 it
->method
= GET_FROM_STRING
;
4954 it
->current
.string_pos
= string_pos (charpos
, string
);
4961 /* Note that we use IT->current.pos, not it->current.string_pos,
4962 for displaying C strings. */
4963 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
4964 if (it
->multibyte_p
)
4966 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
4967 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
4971 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
4972 it
->end_charpos
= it
->string_nchars
= strlen (s
);
4975 it
->method
= GET_FROM_C_STRING
;
4978 /* PRECISION > 0 means don't return more than PRECISION characters
4980 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
4981 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
4983 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
4984 characters have been returned. FIELD_WIDTH == 0 means don't pad,
4985 FIELD_WIDTH < 0 means infinite field width. This is useful for
4986 padding with `-' at the end of a mode line. */
4987 if (field_width
< 0)
4988 field_width
= INFINITY
;
4989 if (field_width
> it
->end_charpos
- charpos
)
4990 it
->end_charpos
= charpos
+ field_width
;
4992 /* Use the standard display table for displaying strings. */
4993 if (DISP_TABLE_P (Vstandard_display_table
))
4994 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
4996 it
->stop_charpos
= charpos
;
5002 /***********************************************************************
5004 ***********************************************************************/
5006 /* Map enum it_method value to corresponding next_element_from_* function. */
5008 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5010 next_element_from_buffer
,
5011 next_element_from_display_vector
,
5012 next_element_from_composition
,
5013 next_element_from_string
,
5014 next_element_from_c_string
,
5015 next_element_from_image
,
5016 next_element_from_stretch
5020 /* Load IT's display element fields with information about the next
5021 display element from the current position of IT. Value is zero if
5022 end of buffer (or C string) is reached. */
5025 get_next_display_element (it
)
5028 /* Non-zero means that we found a display element. Zero means that
5029 we hit the end of what we iterate over. Performance note: the
5030 function pointer `method' used here turns out to be faster than
5031 using a sequence of if-statements. */
5035 success_p
= (*get_next_element
[it
->method
]) (it
);
5037 if (it
->what
== IT_CHARACTER
)
5039 /* Map via display table or translate control characters.
5040 IT->c, IT->len etc. have been set to the next character by
5041 the function call above. If we have a display table, and it
5042 contains an entry for IT->c, translate it. Don't do this if
5043 IT->c itself comes from a display table, otherwise we could
5044 end up in an infinite recursion. (An alternative could be to
5045 count the recursion depth of this function and signal an
5046 error when a certain maximum depth is reached.) Is it worth
5048 if (success_p
&& it
->dpvec
== NULL
)
5053 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5056 struct Lisp_Vector
*v
= XVECTOR (dv
);
5058 /* Return the first character from the display table
5059 entry, if not empty. If empty, don't display the
5060 current character. */
5063 it
->dpvec_char_len
= it
->len
;
5064 it
->dpvec
= v
->contents
;
5065 it
->dpend
= v
->contents
+ v
->size
;
5066 it
->current
.dpvec_index
= 0;
5067 it
->dpvec_face_id
= -1;
5068 it
->saved_face_id
= it
->face_id
;
5069 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5074 set_iterator_to_next (it
, 0);
5079 /* Translate control characters into `\003' or `^C' form.
5080 Control characters coming from a display table entry are
5081 currently not translated because we use IT->dpvec to hold
5082 the translation. This could easily be changed but I
5083 don't believe that it is worth doing.
5085 If it->multibyte_p is nonzero, eight-bit characters and
5086 non-printable multibyte characters are also translated to
5089 If it->multibyte_p is zero, eight-bit characters that
5090 don't have corresponding multibyte char code are also
5091 translated to octal form. */
5092 else if ((it
->c
< ' '
5093 && (it
->area
!= TEXT_AREA
5094 /* In mode line, treat \n like other crl chars. */
5096 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5097 || (it
->c
!= '\n' && it
->c
!= '\t')))
5101 || !CHAR_PRINTABLE_P (it
->c
)
5102 || (!NILP (Vnobreak_char_display
)
5103 && (it
->c
== 0x8a0 || it
->c
== 0x8ad
5104 || it
->c
== 0x920 || it
->c
== 0x92d
5105 || it
->c
== 0xe20 || it
->c
== 0xe2d
5106 || it
->c
== 0xf20 || it
->c
== 0xf2d)))
5108 && (!unibyte_display_via_language_environment
5109 || it
->c
== unibyte_char_to_multibyte (it
->c
)))))
5111 /* IT->c is a control character which must be displayed
5112 either as '\003' or as `^C' where the '\\' and '^'
5113 can be defined in the display table. Fill
5114 IT->ctl_chars with glyphs for what we have to
5115 display. Then, set IT->dpvec to these glyphs. */
5118 int face_id
, lface_id
= 0 ;
5121 /* Handle control characters with ^. */
5123 if (it
->c
< 128 && it
->ctl_arrow_p
)
5125 g
= '^'; /* default glyph for Control */
5126 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5128 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
5129 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
5131 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
5132 lface_id
= FAST_GLYPH_FACE (g
);
5136 g
= FAST_GLYPH_CHAR (g
);
5137 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5142 /* Merge the escape-glyph face into the current face. */
5143 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5147 XSETINT (it
->ctl_chars
[0], g
);
5149 XSETINT (it
->ctl_chars
[1], g
);
5151 goto display_control
;
5154 /* Handle non-break space in the mode where it only gets
5157 if (EQ (Vnobreak_char_display
, Qt
)
5158 && (it
->c
== 0x8a0 || it
->c
== 0x920
5159 || it
->c
== 0xe20 || it
->c
== 0xf20))
5161 /* Merge the no-break-space face into the current face. */
5162 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5166 XSETINT (it
->ctl_chars
[0], g
);
5168 goto display_control
;
5171 /* Handle sequences that start with the "escape glyph". */
5173 /* the default escape glyph is \. */
5174 escape_glyph
= '\\';
5177 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
5178 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
5180 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
5181 lface_id
= FAST_GLYPH_FACE (escape_glyph
);
5185 /* The display table specified a face.
5186 Merge it into face_id and also into escape_glyph. */
5187 escape_glyph
= FAST_GLYPH_CHAR (escape_glyph
);
5188 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5193 /* Merge the escape-glyph face into the current face. */
5194 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5198 /* Handle soft hyphens in the mode where they only get
5201 if (EQ (Vnobreak_char_display
, Qt
)
5202 && (it
->c
== 0x8ad || it
->c
== 0x92d
5203 || it
->c
== 0xe2d || it
->c
== 0xf2d))
5206 XSETINT (it
->ctl_chars
[0], g
);
5208 goto display_control
;
5211 /* Handle non-break space and soft hyphen
5212 with the escape glyph. */
5214 if (it
->c
== 0x8a0 || it
->c
== 0x8ad
5215 || it
->c
== 0x920 || it
->c
== 0x92d
5216 || it
->c
== 0xe20 || it
->c
== 0xe2d
5217 || it
->c
== 0xf20 || it
->c
== 0xf2d)
5219 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5220 g
= it
->c
= ((it
->c
& 0xf) == 0 ? ' ' : '-');
5221 XSETINT (it
->ctl_chars
[1], g
);
5223 goto display_control
;
5227 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5231 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5232 if (SINGLE_BYTE_CHAR_P (it
->c
))
5233 str
[0] = it
->c
, len
= 1;
5236 len
= CHAR_STRING_NO_SIGNAL (it
->c
, str
);
5239 /* It's an invalid character, which shouldn't
5240 happen actually, but due to bugs it may
5241 happen. Let's print the char as is, there's
5242 not much meaningful we can do with it. */
5244 str
[1] = it
->c
>> 8;
5245 str
[2] = it
->c
>> 16;
5246 str
[3] = it
->c
>> 24;
5251 for (i
= 0; i
< len
; i
++)
5253 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5254 /* Insert three more glyphs into IT->ctl_chars for
5255 the octal display of the character. */
5256 g
= ((str
[i
] >> 6) & 7) + '0';
5257 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5258 g
= ((str
[i
] >> 3) & 7) + '0';
5259 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5260 g
= (str
[i
] & 7) + '0';
5261 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5267 /* Set up IT->dpvec and return first character from it. */
5268 it
->dpvec_char_len
= it
->len
;
5269 it
->dpvec
= it
->ctl_chars
;
5270 it
->dpend
= it
->dpvec
+ ctl_len
;
5271 it
->current
.dpvec_index
= 0;
5272 it
->dpvec_face_id
= face_id
;
5273 it
->saved_face_id
= it
->face_id
;
5274 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5280 /* Adjust face id for a multibyte character. There are no
5281 multibyte character in unibyte text. */
5284 && FRAME_WINDOW_P (it
->f
))
5286 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5287 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
5291 /* Is this character the last one of a run of characters with
5292 box? If yes, set IT->end_of_box_run_p to 1. */
5299 it
->end_of_box_run_p
5300 = ((face_id
= face_after_it_pos (it
),
5301 face_id
!= it
->face_id
)
5302 && (face
= FACE_FROM_ID (it
->f
, face_id
),
5303 face
->box
== FACE_NO_BOX
));
5306 /* Value is 0 if end of buffer or string reached. */
5311 /* Move IT to the next display element.
5313 RESEAT_P non-zero means if called on a newline in buffer text,
5314 skip to the next visible line start.
5316 Functions get_next_display_element and set_iterator_to_next are
5317 separate because I find this arrangement easier to handle than a
5318 get_next_display_element function that also increments IT's
5319 position. The way it is we can first look at an iterator's current
5320 display element, decide whether it fits on a line, and if it does,
5321 increment the iterator position. The other way around we probably
5322 would either need a flag indicating whether the iterator has to be
5323 incremented the next time, or we would have to implement a
5324 decrement position function which would not be easy to write. */
5327 set_iterator_to_next (it
, reseat_p
)
5331 /* Reset flags indicating start and end of a sequence of characters
5332 with box. Reset them at the start of this function because
5333 moving the iterator to a new position might set them. */
5334 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
5338 case GET_FROM_BUFFER
:
5339 /* The current display element of IT is a character from
5340 current_buffer. Advance in the buffer, and maybe skip over
5341 invisible lines that are so because of selective display. */
5342 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
5343 reseat_at_next_visible_line_start (it
, 0);
5346 xassert (it
->len
!= 0);
5347 IT_BYTEPOS (*it
) += it
->len
;
5348 IT_CHARPOS (*it
) += 1;
5349 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
5353 case GET_FROM_COMPOSITION
:
5354 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
5355 if (STRINGP (it
->string
))
5357 IT_STRING_BYTEPOS (*it
) += it
->len
;
5358 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
5359 it
->method
= GET_FROM_STRING
;
5360 goto consider_string_end
;
5364 IT_BYTEPOS (*it
) += it
->len
;
5365 IT_CHARPOS (*it
) += it
->cmp_len
;
5366 it
->method
= GET_FROM_BUFFER
;
5370 case GET_FROM_C_STRING
:
5371 /* Current display element of IT is from a C string. */
5372 IT_BYTEPOS (*it
) += it
->len
;
5373 IT_CHARPOS (*it
) += 1;
5376 case GET_FROM_DISPLAY_VECTOR
:
5377 /* Current display element of IT is from a display table entry.
5378 Advance in the display table definition. Reset it to null if
5379 end reached, and continue with characters from buffers/
5381 ++it
->current
.dpvec_index
;
5383 /* Restore face of the iterator to what they were before the
5384 display vector entry (these entries may contain faces). */
5385 it
->face_id
= it
->saved_face_id
;
5387 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
5390 it
->method
= GET_FROM_C_STRING
;
5391 else if (STRINGP (it
->string
))
5392 it
->method
= GET_FROM_STRING
;
5394 it
->method
= GET_FROM_BUFFER
;
5397 it
->current
.dpvec_index
= -1;
5399 /* Skip over characters which were displayed via IT->dpvec. */
5400 if (it
->dpvec_char_len
< 0)
5401 reseat_at_next_visible_line_start (it
, 1);
5402 else if (it
->dpvec_char_len
> 0)
5404 it
->len
= it
->dpvec_char_len
;
5405 set_iterator_to_next (it
, reseat_p
);
5408 /* Recheck faces after display vector */
5409 it
->stop_charpos
= IT_CHARPOS (*it
);
5413 case GET_FROM_STRING
:
5414 /* Current display element is a character from a Lisp string. */
5415 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
5416 IT_STRING_BYTEPOS (*it
) += it
->len
;
5417 IT_STRING_CHARPOS (*it
) += 1;
5419 consider_string_end
:
5421 if (it
->current
.overlay_string_index
>= 0)
5423 /* IT->string is an overlay string. Advance to the
5424 next, if there is one. */
5425 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5426 next_overlay_string (it
);
5430 /* IT->string is not an overlay string. If we reached
5431 its end, and there is something on IT->stack, proceed
5432 with what is on the stack. This can be either another
5433 string, this time an overlay string, or a buffer. */
5434 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
5438 if (STRINGP (it
->string
))
5439 goto consider_string_end
;
5440 it
->method
= GET_FROM_BUFFER
;
5445 case GET_FROM_IMAGE
:
5446 case GET_FROM_STRETCH
:
5447 /* The position etc with which we have to proceed are on
5448 the stack. The position may be at the end of a string,
5449 if the `display' property takes up the whole string. */
5450 xassert (it
->sp
> 0);
5453 if (STRINGP (it
->string
))
5455 it
->method
= GET_FROM_STRING
;
5456 goto consider_string_end
;
5458 it
->method
= GET_FROM_BUFFER
;
5462 /* There are no other methods defined, so this should be a bug. */
5466 xassert (it
->method
!= GET_FROM_STRING
5467 || (STRINGP (it
->string
)
5468 && IT_STRING_CHARPOS (*it
) >= 0));
5471 /* Load IT's display element fields with information about the next
5472 display element which comes from a display table entry or from the
5473 result of translating a control character to one of the forms `^C'
5476 IT->dpvec holds the glyphs to return as characters.
5477 IT->saved_face_id holds the face id before the display vector--
5478 it is restored into IT->face_idin set_iterator_to_next. */
5481 next_element_from_display_vector (it
)
5485 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
5487 it
->face_id
= it
->saved_face_id
;
5489 if (INTEGERP (*it
->dpvec
)
5490 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
5494 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
5495 it
->c
= FAST_GLYPH_CHAR (g
);
5496 it
->len
= CHAR_BYTES (it
->c
);
5498 /* The entry may contain a face id to use. Such a face id is
5499 the id of a Lisp face, not a realized face. A face id of
5500 zero means no face is specified. */
5501 if (it
->dpvec_face_id
>= 0)
5502 it
->face_id
= it
->dpvec_face_id
;
5505 int lface_id
= FAST_GLYPH_FACE (g
);
5507 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5512 /* Display table entry is invalid. Return a space. */
5513 it
->c
= ' ', it
->len
= 1;
5515 /* Don't change position and object of the iterator here. They are
5516 still the values of the character that had this display table
5517 entry or was translated, and that's what we want. */
5518 it
->what
= IT_CHARACTER
;
5523 /* Load IT with the next display element from Lisp string IT->string.
5524 IT->current.string_pos is the current position within the string.
5525 If IT->current.overlay_string_index >= 0, the Lisp string is an
5529 next_element_from_string (it
)
5532 struct text_pos position
;
5534 xassert (STRINGP (it
->string
));
5535 xassert (IT_STRING_CHARPOS (*it
) >= 0);
5536 position
= it
->current
.string_pos
;
5538 /* Time to check for invisible text? */
5539 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
5540 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
5544 /* Since a handler may have changed IT->method, we must
5546 return get_next_display_element (it
);
5549 if (it
->current
.overlay_string_index
>= 0)
5551 /* Get the next character from an overlay string. In overlay
5552 strings, There is no field width or padding with spaces to
5554 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
5559 else if (STRING_MULTIBYTE (it
->string
))
5561 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5562 const unsigned char *s
= (SDATA (it
->string
)
5563 + IT_STRING_BYTEPOS (*it
));
5564 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
5568 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5574 /* Get the next character from a Lisp string that is not an
5575 overlay string. Such strings come from the mode line, for
5576 example. We may have to pad with spaces, or truncate the
5577 string. See also next_element_from_c_string. */
5578 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
5583 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
5585 /* Pad with spaces. */
5586 it
->c
= ' ', it
->len
= 1;
5587 CHARPOS (position
) = BYTEPOS (position
) = -1;
5589 else if (STRING_MULTIBYTE (it
->string
))
5591 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
5592 const unsigned char *s
= (SDATA (it
->string
)
5593 + IT_STRING_BYTEPOS (*it
));
5594 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
5598 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
5603 /* Record what we have and where it came from. Note that we store a
5604 buffer position in IT->position although it could arguably be a
5606 it
->what
= IT_CHARACTER
;
5607 it
->object
= it
->string
;
5608 it
->position
= position
;
5613 /* Load IT with next display element from C string IT->s.
5614 IT->string_nchars is the maximum number of characters to return
5615 from the string. IT->end_charpos may be greater than
5616 IT->string_nchars when this function is called, in which case we
5617 may have to return padding spaces. Value is zero if end of string
5618 reached, including padding spaces. */
5621 next_element_from_c_string (it
)
5627 it
->what
= IT_CHARACTER
;
5628 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
5631 /* IT's position can be greater IT->string_nchars in case a field
5632 width or precision has been specified when the iterator was
5634 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5636 /* End of the game. */
5640 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
5642 /* Pad with spaces. */
5643 it
->c
= ' ', it
->len
= 1;
5644 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
5646 else if (it
->multibyte_p
)
5648 /* Implementation note: The calls to strlen apparently aren't a
5649 performance problem because there is no noticeable performance
5650 difference between Emacs running in unibyte or multibyte mode. */
5651 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
5652 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
5656 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
5662 /* Set up IT to return characters from an ellipsis, if appropriate.
5663 The definition of the ellipsis glyphs may come from a display table
5664 entry. This function Fills IT with the first glyph from the
5665 ellipsis if an ellipsis is to be displayed. */
5668 next_element_from_ellipsis (it
)
5671 if (it
->selective_display_ellipsis_p
)
5672 setup_for_ellipsis (it
, it
->len
);
5675 /* The face at the current position may be different from the
5676 face we find after the invisible text. Remember what it
5677 was in IT->saved_face_id, and signal that it's there by
5678 setting face_before_selective_p. */
5679 it
->saved_face_id
= it
->face_id
;
5680 it
->method
= GET_FROM_BUFFER
;
5681 reseat_at_next_visible_line_start (it
, 1);
5682 it
->face_before_selective_p
= 1;
5685 return get_next_display_element (it
);
5689 /* Deliver an image display element. The iterator IT is already
5690 filled with image information (done in handle_display_prop). Value
5695 next_element_from_image (it
)
5698 it
->what
= IT_IMAGE
;
5703 /* Fill iterator IT with next display element from a stretch glyph
5704 property. IT->object is the value of the text property. Value is
5708 next_element_from_stretch (it
)
5711 it
->what
= IT_STRETCH
;
5716 /* Load IT with the next display element from current_buffer. Value
5717 is zero if end of buffer reached. IT->stop_charpos is the next
5718 position at which to stop and check for text properties or buffer
5722 next_element_from_buffer (it
)
5727 /* Check this assumption, otherwise, we would never enter the
5728 if-statement, below. */
5729 xassert (IT_CHARPOS (*it
) >= BEGV
5730 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
5732 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
5734 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
5736 int overlay_strings_follow_p
;
5738 /* End of the game, except when overlay strings follow that
5739 haven't been returned yet. */
5740 if (it
->overlay_strings_at_end_processed_p
)
5741 overlay_strings_follow_p
= 0;
5744 it
->overlay_strings_at_end_processed_p
= 1;
5745 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
5748 if (overlay_strings_follow_p
)
5749 success_p
= get_next_display_element (it
);
5753 it
->position
= it
->current
.pos
;
5760 return get_next_display_element (it
);
5765 /* No face changes, overlays etc. in sight, so just return a
5766 character from current_buffer. */
5769 /* Maybe run the redisplay end trigger hook. Performance note:
5770 This doesn't seem to cost measurable time. */
5771 if (it
->redisplay_end_trigger_charpos
5773 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
5774 run_redisplay_end_trigger_hook (it
);
5776 /* Get the next character, maybe multibyte. */
5777 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
5778 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
5780 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
5781 - IT_BYTEPOS (*it
));
5782 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
5785 it
->c
= *p
, it
->len
= 1;
5787 /* Record what we have and where it came from. */
5788 it
->what
= IT_CHARACTER
;;
5789 it
->object
= it
->w
->buffer
;
5790 it
->position
= it
->current
.pos
;
5792 /* Normally we return the character found above, except when we
5793 really want to return an ellipsis for selective display. */
5798 /* A value of selective > 0 means hide lines indented more
5799 than that number of columns. */
5800 if (it
->selective
> 0
5801 && IT_CHARPOS (*it
) + 1 < ZV
5802 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
5803 IT_BYTEPOS (*it
) + 1,
5804 (double) it
->selective
)) /* iftc */
5806 success_p
= next_element_from_ellipsis (it
);
5807 it
->dpvec_char_len
= -1;
5810 else if (it
->c
== '\r' && it
->selective
== -1)
5812 /* A value of selective == -1 means that everything from the
5813 CR to the end of the line is invisible, with maybe an
5814 ellipsis displayed for it. */
5815 success_p
= next_element_from_ellipsis (it
);
5816 it
->dpvec_char_len
= -1;
5821 /* Value is zero if end of buffer reached. */
5822 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
5827 /* Run the redisplay end trigger hook for IT. */
5830 run_redisplay_end_trigger_hook (it
)
5833 Lisp_Object args
[3];
5835 /* IT->glyph_row should be non-null, i.e. we should be actually
5836 displaying something, or otherwise we should not run the hook. */
5837 xassert (it
->glyph_row
);
5839 /* Set up hook arguments. */
5840 args
[0] = Qredisplay_end_trigger_functions
;
5841 args
[1] = it
->window
;
5842 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
5843 it
->redisplay_end_trigger_charpos
= 0;
5845 /* Since we are *trying* to run these functions, don't try to run
5846 them again, even if they get an error. */
5847 it
->w
->redisplay_end_trigger
= Qnil
;
5848 Frun_hook_with_args (3, args
);
5850 /* Notice if it changed the face of the character we are on. */
5851 handle_face_prop (it
);
5855 /* Deliver a composition display element. The iterator IT is already
5856 filled with composition information (done in
5857 handle_composition_prop). Value is always 1. */
5860 next_element_from_composition (it
)
5863 it
->what
= IT_COMPOSITION
;
5864 it
->position
= (STRINGP (it
->string
)
5865 ? it
->current
.string_pos
5872 /***********************************************************************
5873 Moving an iterator without producing glyphs
5874 ***********************************************************************/
5876 /* Check if iterator is at a position corresponding to a valid buffer
5877 position after some move_it_ call. */
5879 #define IT_POS_VALID_AFTER_MOVE_P(it) \
5880 ((it)->method == GET_FROM_STRING \
5881 ? IT_STRING_CHARPOS (*it) == 0 \
5885 /* Move iterator IT to a specified buffer or X position within one
5886 line on the display without producing glyphs.
5888 OP should be a bit mask including some or all of these bits:
5889 MOVE_TO_X: Stop on reaching x-position TO_X.
5890 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
5891 Regardless of OP's value, stop in reaching the end of the display line.
5893 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
5894 This means, in particular, that TO_X includes window's horizontal
5897 The return value has several possible values that
5898 say what condition caused the scan to stop:
5900 MOVE_POS_MATCH_OR_ZV
5901 - when TO_POS or ZV was reached.
5904 -when TO_X was reached before TO_POS or ZV were reached.
5907 - when we reached the end of the display area and the line must
5911 - when we reached the end of the display area and the line is
5915 - when we stopped at a line end, i.e. a newline or a CR and selective
5918 static enum move_it_result
5919 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
5921 int to_charpos
, to_x
, op
;
5923 enum move_it_result result
= MOVE_UNDEFINED
;
5924 struct glyph_row
*saved_glyph_row
;
5926 /* Don't produce glyphs in produce_glyphs. */
5927 saved_glyph_row
= it
->glyph_row
;
5928 it
->glyph_row
= NULL
;
5930 #define BUFFER_POS_REACHED_P() \
5931 ((op & MOVE_TO_POS) != 0 \
5932 && BUFFERP (it->object) \
5933 && IT_CHARPOS (*it) >= to_charpos \
5934 && (it->method == GET_FROM_BUFFER \
5935 || (it->method == GET_FROM_DISPLAY_VECTOR \
5936 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
5941 int x
, i
, ascent
= 0, descent
= 0;
5943 /* Stop if we move beyond TO_CHARPOS (after an image or stretch glyph). */
5944 if ((op
& MOVE_TO_POS
) != 0
5945 && BUFFERP (it
->object
)
5946 && it
->method
== GET_FROM_BUFFER
5947 && IT_CHARPOS (*it
) > to_charpos
)
5949 result
= MOVE_POS_MATCH_OR_ZV
;
5953 /* Stop when ZV reached.
5954 We used to stop here when TO_CHARPOS reached as well, but that is
5955 too soon if this glyph does not fit on this line. So we handle it
5956 explicitly below. */
5957 if (!get_next_display_element (it
)
5958 || (it
->truncate_lines_p
5959 && BUFFER_POS_REACHED_P ()))
5961 result
= MOVE_POS_MATCH_OR_ZV
;
5965 /* The call to produce_glyphs will get the metrics of the
5966 display element IT is loaded with. We record in x the
5967 x-position before this display element in case it does not
5971 /* Remember the line height so far in case the next element doesn't
5973 if (!it
->truncate_lines_p
)
5975 ascent
= it
->max_ascent
;
5976 descent
= it
->max_descent
;
5979 PRODUCE_GLYPHS (it
);
5981 if (it
->area
!= TEXT_AREA
)
5983 set_iterator_to_next (it
, 1);
5987 /* The number of glyphs we get back in IT->nglyphs will normally
5988 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
5989 character on a terminal frame, or (iii) a line end. For the
5990 second case, IT->nglyphs - 1 padding glyphs will be present
5991 (on X frames, there is only one glyph produced for a
5992 composite character.
5994 The behavior implemented below means, for continuation lines,
5995 that as many spaces of a TAB as fit on the current line are
5996 displayed there. For terminal frames, as many glyphs of a
5997 multi-glyph character are displayed in the current line, too.
5998 This is what the old redisplay code did, and we keep it that
5999 way. Under X, the whole shape of a complex character must
6000 fit on the line or it will be completely displayed in the
6003 Note that both for tabs and padding glyphs, all glyphs have
6007 /* More than one glyph or glyph doesn't fit on line. All
6008 glyphs have the same width. */
6009 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6012 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6014 new_x
= x
+ single_glyph_width
;
6016 /* We want to leave anything reaching TO_X to the caller. */
6017 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6019 if (BUFFER_POS_REACHED_P ())
6020 goto buffer_pos_reached
;
6022 result
= MOVE_X_REACHED
;
6025 else if (/* Lines are continued. */
6026 !it
->truncate_lines_p
6027 && (/* And glyph doesn't fit on the line. */
6028 new_x
> it
->last_visible_x
6029 /* Or it fits exactly and we're on a window
6031 || (new_x
== it
->last_visible_x
6032 && FRAME_WINDOW_P (it
->f
))))
6034 if (/* IT->hpos == 0 means the very first glyph
6035 doesn't fit on the line, e.g. a wide image. */
6037 || (new_x
== it
->last_visible_x
6038 && FRAME_WINDOW_P (it
->f
)))
6041 it
->current_x
= new_x
;
6042 if (i
== it
->nglyphs
- 1)
6044 set_iterator_to_next (it
, 1);
6045 #ifdef HAVE_WINDOW_SYSTEM
6046 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6048 if (!get_next_display_element (it
))
6050 result
= MOVE_POS_MATCH_OR_ZV
;
6053 if (BUFFER_POS_REACHED_P ())
6055 if (ITERATOR_AT_END_OF_LINE_P (it
))
6056 result
= MOVE_POS_MATCH_OR_ZV
;
6058 result
= MOVE_LINE_CONTINUED
;
6061 if (ITERATOR_AT_END_OF_LINE_P (it
))
6063 result
= MOVE_NEWLINE_OR_CR
;
6067 #endif /* HAVE_WINDOW_SYSTEM */
6073 it
->max_ascent
= ascent
;
6074 it
->max_descent
= descent
;
6077 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6079 result
= MOVE_LINE_CONTINUED
;
6082 else if (BUFFER_POS_REACHED_P ())
6083 goto buffer_pos_reached
;
6084 else if (new_x
> it
->first_visible_x
)
6086 /* Glyph is visible. Increment number of glyphs that
6087 would be displayed. */
6092 /* Glyph is completely off the left margin of the display
6093 area. Nothing to do. */
6097 if (result
!= MOVE_UNDEFINED
)
6100 else if (BUFFER_POS_REACHED_P ())
6104 it
->max_ascent
= ascent
;
6105 it
->max_descent
= descent
;
6106 result
= MOVE_POS_MATCH_OR_ZV
;
6109 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6111 /* Stop when TO_X specified and reached. This check is
6112 necessary here because of lines consisting of a line end,
6113 only. The line end will not produce any glyphs and we
6114 would never get MOVE_X_REACHED. */
6115 xassert (it
->nglyphs
== 0);
6116 result
= MOVE_X_REACHED
;
6120 /* Is this a line end? If yes, we're done. */
6121 if (ITERATOR_AT_END_OF_LINE_P (it
))
6123 result
= MOVE_NEWLINE_OR_CR
;
6127 /* The current display element has been consumed. Advance
6129 set_iterator_to_next (it
, 1);
6131 /* Stop if lines are truncated and IT's current x-position is
6132 past the right edge of the window now. */
6133 if (it
->truncate_lines_p
6134 && it
->current_x
>= it
->last_visible_x
)
6136 #ifdef HAVE_WINDOW_SYSTEM
6137 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6139 if (!get_next_display_element (it
)
6140 || BUFFER_POS_REACHED_P ())
6142 result
= MOVE_POS_MATCH_OR_ZV
;
6145 if (ITERATOR_AT_END_OF_LINE_P (it
))
6147 result
= MOVE_NEWLINE_OR_CR
;
6151 #endif /* HAVE_WINDOW_SYSTEM */
6152 result
= MOVE_LINE_TRUNCATED
;
6157 #undef BUFFER_POS_REACHED_P
6159 /* Restore the iterator settings altered at the beginning of this
6161 it
->glyph_row
= saved_glyph_row
;
6166 /* Move IT forward until it satisfies one or more of the criteria in
6167 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
6169 OP is a bit-mask that specifies where to stop, and in particular,
6170 which of those four position arguments makes a difference. See the
6171 description of enum move_operation_enum.
6173 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
6174 screen line, this function will set IT to the next position >
6178 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
6180 int to_charpos
, to_x
, to_y
, to_vpos
;
6183 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
6189 if (op
& MOVE_TO_VPOS
)
6191 /* If no TO_CHARPOS and no TO_X specified, stop at the
6192 start of the line TO_VPOS. */
6193 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
6195 if (it
->vpos
== to_vpos
)
6201 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
6205 /* TO_VPOS >= 0 means stop at TO_X in the line at
6206 TO_VPOS, or at TO_POS, whichever comes first. */
6207 if (it
->vpos
== to_vpos
)
6213 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
6215 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
6220 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
6222 /* We have reached TO_X but not in the line we want. */
6223 skip
= move_it_in_display_line_to (it
, to_charpos
,
6225 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6233 else if (op
& MOVE_TO_Y
)
6235 struct it it_backup
;
6237 /* TO_Y specified means stop at TO_X in the line containing
6238 TO_Y---or at TO_CHARPOS if this is reached first. The
6239 problem is that we can't really tell whether the line
6240 contains TO_Y before we have completely scanned it, and
6241 this may skip past TO_X. What we do is to first scan to
6244 If TO_X is not specified, use a TO_X of zero. The reason
6245 is to make the outcome of this function more predictable.
6246 If we didn't use TO_X == 0, we would stop at the end of
6247 the line which is probably not what a caller would expect
6249 skip
= move_it_in_display_line_to (it
, to_charpos
,
6253 | (op
& MOVE_TO_POS
)));
6255 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
6256 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6262 /* If TO_X was reached, we would like to know whether TO_Y
6263 is in the line. This can only be said if we know the
6264 total line height which requires us to scan the rest of
6266 if (skip
== MOVE_X_REACHED
)
6269 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
6270 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
6272 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
6275 /* Now, decide whether TO_Y is in this line. */
6276 line_height
= it
->max_ascent
+ it
->max_descent
;
6277 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
6279 if (to_y
>= it
->current_y
6280 && to_y
< it
->current_y
+ line_height
)
6282 if (skip
== MOVE_X_REACHED
)
6283 /* If TO_Y is in this line and TO_X was reached above,
6284 we scanned too far. We have to restore IT's settings
6285 to the ones before skipping. */
6289 else if (skip
== MOVE_X_REACHED
)
6292 if (skip
== MOVE_POS_MATCH_OR_ZV
)
6300 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
6304 case MOVE_POS_MATCH_OR_ZV
:
6308 case MOVE_NEWLINE_OR_CR
:
6309 set_iterator_to_next (it
, 1);
6310 it
->continuation_lines_width
= 0;
6313 case MOVE_LINE_TRUNCATED
:
6314 it
->continuation_lines_width
= 0;
6315 reseat_at_next_visible_line_start (it
, 0);
6316 if ((op
& MOVE_TO_POS
) != 0
6317 && IT_CHARPOS (*it
) > to_charpos
)
6324 case MOVE_LINE_CONTINUED
:
6325 it
->continuation_lines_width
+= it
->current_x
;
6332 /* Reset/increment for the next run. */
6333 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
6334 it
->current_x
= it
->hpos
= 0;
6335 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
6337 last_height
= it
->max_ascent
+ it
->max_descent
;
6338 last_max_ascent
= it
->max_ascent
;
6339 it
->max_ascent
= it
->max_descent
= 0;
6344 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
6348 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
6350 If DY > 0, move IT backward at least that many pixels. DY = 0
6351 means move IT backward to the preceding line start or BEGV. This
6352 function may move over more than DY pixels if IT->current_y - DY
6353 ends up in the middle of a line; in this case IT->current_y will be
6354 set to the top of the line moved to. */
6357 move_it_vertically_backward (it
, dy
)
6368 start_pos
= IT_CHARPOS (*it
);
6370 /* Estimate how many newlines we must move back. */
6371 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
6373 /* Set the iterator's position that many lines back. */
6374 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
6375 back_to_previous_visible_line_start (it
);
6377 /* Reseat the iterator here. When moving backward, we don't want
6378 reseat to skip forward over invisible text, set up the iterator
6379 to deliver from overlay strings at the new position etc. So,
6380 use reseat_1 here. */
6381 reseat_1 (it
, it
->current
.pos
, 1);
6383 /* We are now surely at a line start. */
6384 it
->current_x
= it
->hpos
= 0;
6385 it
->continuation_lines_width
= 0;
6387 /* Move forward and see what y-distance we moved. First move to the
6388 start of the next line so that we get its height. We need this
6389 height to be able to tell whether we reached the specified
6392 it2
.max_ascent
= it2
.max_descent
= 0;
6395 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
6396 MOVE_TO_POS
| MOVE_TO_VPOS
);
6398 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
6399 xassert (IT_CHARPOS (*it
) >= BEGV
);
6402 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
6403 xassert (IT_CHARPOS (*it
) >= BEGV
);
6404 /* H is the actual vertical distance from the position in *IT
6405 and the starting position. */
6406 h
= it2
.current_y
- it
->current_y
;
6407 /* NLINES is the distance in number of lines. */
6408 nlines
= it2
.vpos
- it
->vpos
;
6410 /* Correct IT's y and vpos position
6411 so that they are relative to the starting point. */
6417 /* DY == 0 means move to the start of the screen line. The
6418 value of nlines is > 0 if continuation lines were involved. */
6420 move_it_by_lines (it
, nlines
, 1);
6422 /* I think this assert is bogus if buffer contains
6423 invisible text or images. KFS. */
6424 xassert (IT_CHARPOS (*it
) <= start_pos
);
6429 /* The y-position we try to reach, relative to *IT.
6430 Note that H has been subtracted in front of the if-statement. */
6431 int target_y
= it
->current_y
+ h
- dy
;
6432 int y0
= it3
.current_y
;
6433 int y1
= line_bottom_y (&it3
);
6434 int line_height
= y1
- y0
;
6436 /* If we did not reach target_y, try to move further backward if
6437 we can. If we moved too far backward, try to move forward. */
6438 if (target_y
< it
->current_y
6439 /* This is heuristic. In a window that's 3 lines high, with
6440 a line height of 13 pixels each, recentering with point
6441 on the bottom line will try to move -39/2 = 19 pixels
6442 backward. Try to avoid moving into the first line. */
6443 && (it
->current_y
- target_y
6444 > min (window_box_height (it
->w
), line_height
* 2 / 3))
6445 && IT_CHARPOS (*it
) > BEGV
)
6447 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
6448 target_y
- it
->current_y
));
6449 dy
= it
->current_y
- target_y
;
6450 goto move_further_back
;
6452 else if (target_y
>= it
->current_y
+ line_height
6453 && IT_CHARPOS (*it
) < ZV
)
6455 /* Should move forward by at least one line, maybe more.
6457 Note: Calling move_it_by_lines can be expensive on
6458 terminal frames, where compute_motion is used (via
6459 vmotion) to do the job, when there are very long lines
6460 and truncate-lines is nil. That's the reason for
6461 treating terminal frames specially here. */
6463 if (!FRAME_WINDOW_P (it
->f
))
6464 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
6469 move_it_by_lines (it
, 1, 1);
6471 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
6475 /* I think this assert is bogus if buffer contains
6476 invisible text or images. KFS. */
6477 xassert (IT_CHARPOS (*it
) >= BEGV
);
6484 /* Move IT by a specified amount of pixel lines DY. DY negative means
6485 move backwards. DY = 0 means move to start of screen line. At the
6486 end, IT will be on the start of a screen line. */
6489 move_it_vertically (it
, dy
)
6494 move_it_vertically_backward (it
, -dy
);
6497 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
6498 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
6499 MOVE_TO_POS
| MOVE_TO_Y
);
6500 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
6502 /* If buffer ends in ZV without a newline, move to the start of
6503 the line to satisfy the post-condition. */
6504 if (IT_CHARPOS (*it
) == ZV
6505 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
6506 move_it_by_lines (it
, 0, 0);
6511 /* Move iterator IT past the end of the text line it is in. */
6514 move_it_past_eol (it
)
6517 enum move_it_result rc
;
6519 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
6520 if (rc
== MOVE_NEWLINE_OR_CR
)
6521 set_iterator_to_next (it
, 0);
6525 #if 0 /* Currently not used. */
6527 /* Return non-zero if some text between buffer positions START_CHARPOS
6528 and END_CHARPOS is invisible. IT->window is the window for text
6532 invisible_text_between_p (it
, start_charpos
, end_charpos
)
6534 int start_charpos
, end_charpos
;
6536 Lisp_Object prop
, limit
;
6537 int invisible_found_p
;
6539 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
6541 /* Is text at START invisible? */
6542 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
6544 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6545 invisible_found_p
= 1;
6548 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
6550 make_number (end_charpos
));
6551 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
6554 return invisible_found_p
;
6560 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
6561 negative means move up. DVPOS == 0 means move to the start of the
6562 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
6563 NEED_Y_P is zero, IT->current_y will be left unchanged.
6565 Further optimization ideas: If we would know that IT->f doesn't use
6566 a face with proportional font, we could be faster for
6567 truncate-lines nil. */
6570 move_it_by_lines (it
, dvpos
, need_y_p
)
6572 int dvpos
, need_y_p
;
6574 struct position pos
;
6576 if (!FRAME_WINDOW_P (it
->f
))
6578 struct text_pos textpos
;
6580 /* We can use vmotion on frames without proportional fonts. */
6581 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
6582 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
6583 reseat (it
, textpos
, 1);
6584 it
->vpos
+= pos
.vpos
;
6585 it
->current_y
+= pos
.vpos
;
6587 else if (dvpos
== 0)
6589 /* DVPOS == 0 means move to the start of the screen line. */
6590 move_it_vertically_backward (it
, 0);
6591 xassert (it
->current_x
== 0 && it
->hpos
== 0);
6592 /* Let next call to line_bottom_y calculate real line height */
6597 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
6598 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
6599 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
6604 int start_charpos
, i
;
6606 /* Start at the beginning of the screen line containing IT's
6607 position. This may actually move vertically backwards,
6608 in case of overlays, so adjust dvpos accordingly. */
6610 move_it_vertically_backward (it
, 0);
6613 /* Go back -DVPOS visible lines and reseat the iterator there. */
6614 start_charpos
= IT_CHARPOS (*it
);
6615 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
6616 back_to_previous_visible_line_start (it
);
6617 reseat (it
, it
->current
.pos
, 1);
6619 /* Move further back if we end up in a string or an image. */
6620 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
6622 /* First try to move to start of display line. */
6624 move_it_vertically_backward (it
, 0);
6626 if (IT_POS_VALID_AFTER_MOVE_P (it
))
6628 /* If start of line is still in string or image,
6629 move further back. */
6630 back_to_previous_visible_line_start (it
);
6631 reseat (it
, it
->current
.pos
, 1);
6635 it
->current_x
= it
->hpos
= 0;
6637 /* Above call may have moved too far if continuation lines
6638 are involved. Scan forward and see if it did. */
6640 it2
.vpos
= it2
.current_y
= 0;
6641 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
6642 it
->vpos
-= it2
.vpos
;
6643 it
->current_y
-= it2
.current_y
;
6644 it
->current_x
= it
->hpos
= 0;
6646 /* If we moved too far back, move IT some lines forward. */
6647 if (it2
.vpos
> -dvpos
)
6649 int delta
= it2
.vpos
+ dvpos
;
6651 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
6652 /* Move back again if we got too far ahead. */
6653 if (IT_CHARPOS (*it
) >= start_charpos
)
6659 /* Return 1 if IT points into the middle of a display vector. */
6662 in_display_vector_p (it
)
6665 return (it
->method
== GET_FROM_DISPLAY_VECTOR
6666 && it
->current
.dpvec_index
> 0
6667 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
6671 /***********************************************************************
6673 ***********************************************************************/
6676 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
6680 add_to_log (format
, arg1
, arg2
)
6682 Lisp_Object arg1
, arg2
;
6684 Lisp_Object args
[3];
6685 Lisp_Object msg
, fmt
;
6688 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
6691 /* Do nothing if called asynchronously. Inserting text into
6692 a buffer may call after-change-functions and alike and
6693 that would means running Lisp asynchronously. */
6694 if (handling_signal
)
6698 GCPRO4 (fmt
, msg
, arg1
, arg2
);
6700 args
[0] = fmt
= build_string (format
);
6703 msg
= Fformat (3, args
);
6705 len
= SBYTES (msg
) + 1;
6706 SAFE_ALLOCA (buffer
, char *, len
);
6707 bcopy (SDATA (msg
), buffer
, len
);
6709 message_dolog (buffer
, len
- 1, 1, 0);
6716 /* Output a newline in the *Messages* buffer if "needs" one. */
6719 message_log_maybe_newline ()
6721 if (message_log_need_newline
)
6722 message_dolog ("", 0, 1, 0);
6726 /* Add a string M of length NBYTES to the message log, optionally
6727 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
6728 nonzero, means interpret the contents of M as multibyte. This
6729 function calls low-level routines in order to bypass text property
6730 hooks, etc. which might not be safe to run. */
6733 message_dolog (m
, nbytes
, nlflag
, multibyte
)
6735 int nbytes
, nlflag
, multibyte
;
6737 if (!NILP (Vmemory_full
))
6740 if (!NILP (Vmessage_log_max
))
6742 struct buffer
*oldbuf
;
6743 Lisp_Object oldpoint
, oldbegv
, oldzv
;
6744 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
6745 int point_at_end
= 0;
6747 Lisp_Object old_deactivate_mark
, tem
;
6748 struct gcpro gcpro1
;
6750 old_deactivate_mark
= Vdeactivate_mark
;
6751 oldbuf
= current_buffer
;
6752 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
6753 current_buffer
->undo_list
= Qt
;
6755 oldpoint
= message_dolog_marker1
;
6756 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
6757 oldbegv
= message_dolog_marker2
;
6758 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
6759 oldzv
= message_dolog_marker3
;
6760 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
6761 GCPRO1 (old_deactivate_mark
);
6769 BEGV_BYTE
= BEG_BYTE
;
6772 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6774 /* Insert the string--maybe converting multibyte to single byte
6775 or vice versa, so that all the text fits the buffer. */
6777 && NILP (current_buffer
->enable_multibyte_characters
))
6779 int i
, c
, char_bytes
;
6780 unsigned char work
[1];
6782 /* Convert a multibyte string to single-byte
6783 for the *Message* buffer. */
6784 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
6786 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
6787 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
6789 : multibyte_char_to_unibyte (c
, Qnil
));
6790 insert_1_both (work
, 1, 1, 1, 0, 0);
6793 else if (! multibyte
6794 && ! NILP (current_buffer
->enable_multibyte_characters
))
6796 int i
, c
, char_bytes
;
6797 unsigned char *msg
= (unsigned char *) m
;
6798 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6799 /* Convert a single-byte string to multibyte
6800 for the *Message* buffer. */
6801 for (i
= 0; i
< nbytes
; i
++)
6803 c
= unibyte_char_to_multibyte (msg
[i
]);
6804 char_bytes
= CHAR_STRING (c
, str
);
6805 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
6809 insert_1 (m
, nbytes
, 1, 0, 0);
6813 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
6814 insert_1 ("\n", 1, 1, 0, 0);
6816 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6818 this_bol_byte
= PT_BYTE
;
6820 /* See if this line duplicates the previous one.
6821 If so, combine duplicates. */
6824 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
6826 prev_bol_byte
= PT_BYTE
;
6828 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
6829 this_bol
, this_bol_byte
);
6832 del_range_both (prev_bol
, prev_bol_byte
,
6833 this_bol
, this_bol_byte
, 0);
6839 /* If you change this format, don't forget to also
6840 change message_log_check_duplicate. */
6841 sprintf (dupstr
, " [%d times]", dup
);
6842 duplen
= strlen (dupstr
);
6843 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
6844 insert_1 (dupstr
, duplen
, 1, 0, 1);
6849 /* If we have more than the desired maximum number of lines
6850 in the *Messages* buffer now, delete the oldest ones.
6851 This is safe because we don't have undo in this buffer. */
6853 if (NATNUMP (Vmessage_log_max
))
6855 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
6856 -XFASTINT (Vmessage_log_max
) - 1, 0);
6857 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
6860 BEGV
= XMARKER (oldbegv
)->charpos
;
6861 BEGV_BYTE
= marker_byte_position (oldbegv
);
6870 ZV
= XMARKER (oldzv
)->charpos
;
6871 ZV_BYTE
= marker_byte_position (oldzv
);
6875 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
6877 /* We can't do Fgoto_char (oldpoint) because it will run some
6879 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
6880 XMARKER (oldpoint
)->bytepos
);
6883 unchain_marker (XMARKER (oldpoint
));
6884 unchain_marker (XMARKER (oldbegv
));
6885 unchain_marker (XMARKER (oldzv
));
6887 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
6888 set_buffer_internal (oldbuf
);
6890 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
6891 message_log_need_newline
= !nlflag
;
6892 Vdeactivate_mark
= old_deactivate_mark
;
6897 /* We are at the end of the buffer after just having inserted a newline.
6898 (Note: We depend on the fact we won't be crossing the gap.)
6899 Check to see if the most recent message looks a lot like the previous one.
6900 Return 0 if different, 1 if the new one should just replace it, or a
6901 value N > 1 if we should also append " [N times]". */
6904 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
6905 int prev_bol
, this_bol
;
6906 int prev_bol_byte
, this_bol_byte
;
6909 int len
= Z_BYTE
- 1 - this_bol_byte
;
6911 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
6912 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
6914 for (i
= 0; i
< len
; i
++)
6916 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
6924 if (*p1
++ == ' ' && *p1
++ == '[')
6927 while (*p1
>= '0' && *p1
<= '9')
6928 n
= n
* 10 + *p1
++ - '0';
6929 if (strncmp (p1
, " times]\n", 8) == 0)
6936 /* Display an echo area message M with a specified length of NBYTES
6937 bytes. The string may include null characters. If M is 0, clear
6938 out any existing message, and let the mini-buffer text show
6941 The buffer M must continue to exist until after the echo area gets
6942 cleared or some other message gets displayed there. This means do
6943 not pass text that is stored in a Lisp string; do not pass text in
6944 a buffer that was alloca'd. */
6947 message2 (m
, nbytes
, multibyte
)
6952 /* First flush out any partial line written with print. */
6953 message_log_maybe_newline ();
6955 message_dolog (m
, nbytes
, 1, multibyte
);
6956 message2_nolog (m
, nbytes
, multibyte
);
6960 /* The non-logging counterpart of message2. */
6963 message2_nolog (m
, nbytes
, multibyte
)
6965 int nbytes
, multibyte
;
6967 struct frame
*sf
= SELECTED_FRAME ();
6968 message_enable_multibyte
= multibyte
;
6972 if (noninteractive_need_newline
)
6973 putc ('\n', stderr
);
6974 noninteractive_need_newline
= 0;
6976 fwrite (m
, nbytes
, 1, stderr
);
6977 if (cursor_in_echo_area
== 0)
6978 fprintf (stderr
, "\n");
6981 /* A null message buffer means that the frame hasn't really been
6982 initialized yet. Error messages get reported properly by
6983 cmd_error, so this must be just an informative message; toss it. */
6984 else if (INTERACTIVE
6985 && sf
->glyphs_initialized_p
6986 && FRAME_MESSAGE_BUF (sf
))
6988 Lisp_Object mini_window
;
6991 /* Get the frame containing the mini-buffer
6992 that the selected frame is using. */
6993 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
6994 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
6996 FRAME_SAMPLE_VISIBILITY (f
);
6997 if (FRAME_VISIBLE_P (sf
)
6998 && ! FRAME_VISIBLE_P (f
))
6999 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7003 set_message (m
, Qnil
, nbytes
, multibyte
);
7004 if (minibuffer_auto_raise
)
7005 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7008 clear_message (1, 1);
7010 do_pending_window_change (0);
7011 echo_area_display (1);
7012 do_pending_window_change (0);
7013 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7014 (*frame_up_to_date_hook
) (f
);
7019 /* Display an echo area message M with a specified length of NBYTES
7020 bytes. The string may include null characters. If M is not a
7021 string, clear out any existing message, and let the mini-buffer
7024 This function cancels echoing. */
7027 message3 (m
, nbytes
, multibyte
)
7032 struct gcpro gcpro1
;
7035 clear_message (1,1);
7038 /* First flush out any partial line written with print. */
7039 message_log_maybe_newline ();
7041 message_dolog (SDATA (m
), nbytes
, 1, multibyte
);
7042 message3_nolog (m
, nbytes
, multibyte
);
7048 /* The non-logging version of message3.
7049 This does not cancel echoing, because it is used for echoing.
7050 Perhaps we need to make a separate function for echoing
7051 and make this cancel echoing. */
7054 message3_nolog (m
, nbytes
, multibyte
)
7056 int nbytes
, multibyte
;
7058 struct frame
*sf
= SELECTED_FRAME ();
7059 message_enable_multibyte
= multibyte
;
7063 if (noninteractive_need_newline
)
7064 putc ('\n', stderr
);
7065 noninteractive_need_newline
= 0;
7067 fwrite (SDATA (m
), nbytes
, 1, stderr
);
7068 if (cursor_in_echo_area
== 0)
7069 fprintf (stderr
, "\n");
7072 /* A null message buffer means that the frame hasn't really been
7073 initialized yet. Error messages get reported properly by
7074 cmd_error, so this must be just an informative message; toss it. */
7075 else if (INTERACTIVE
7076 && sf
->glyphs_initialized_p
7077 && FRAME_MESSAGE_BUF (sf
))
7079 Lisp_Object mini_window
;
7083 /* Get the frame containing the mini-buffer
7084 that the selected frame is using. */
7085 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7086 frame
= XWINDOW (mini_window
)->frame
;
7089 FRAME_SAMPLE_VISIBILITY (f
);
7090 if (FRAME_VISIBLE_P (sf
)
7091 && !FRAME_VISIBLE_P (f
))
7092 Fmake_frame_visible (frame
);
7094 if (STRINGP (m
) && SCHARS (m
) > 0)
7096 set_message (NULL
, m
, nbytes
, multibyte
);
7097 if (minibuffer_auto_raise
)
7098 Fraise_frame (frame
);
7101 clear_message (1, 1);
7103 do_pending_window_change (0);
7104 echo_area_display (1);
7105 do_pending_window_change (0);
7106 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7107 (*frame_up_to_date_hook
) (f
);
7112 /* Display a null-terminated echo area message M. If M is 0, clear
7113 out any existing message, and let the mini-buffer text show through.
7115 The buffer M must continue to exist until after the echo area gets
7116 cleared or some other message gets displayed there. Do not pass
7117 text that is stored in a Lisp string. Do not pass text in a buffer
7118 that was alloca'd. */
7124 message2 (m
, (m
? strlen (m
) : 0), 0);
7128 /* The non-logging counterpart of message1. */
7134 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
7137 /* Display a message M which contains a single %s
7138 which gets replaced with STRING. */
7141 message_with_string (m
, string
, log
)
7146 CHECK_STRING (string
);
7152 if (noninteractive_need_newline
)
7153 putc ('\n', stderr
);
7154 noninteractive_need_newline
= 0;
7155 fprintf (stderr
, m
, SDATA (string
));
7156 if (cursor_in_echo_area
== 0)
7157 fprintf (stderr
, "\n");
7161 else if (INTERACTIVE
)
7163 /* The frame whose minibuffer we're going to display the message on.
7164 It may be larger than the selected frame, so we need
7165 to use its buffer, not the selected frame's buffer. */
7166 Lisp_Object mini_window
;
7167 struct frame
*f
, *sf
= SELECTED_FRAME ();
7169 /* Get the frame containing the minibuffer
7170 that the selected frame is using. */
7171 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7172 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7174 /* A null message buffer means that the frame hasn't really been
7175 initialized yet. Error messages get reported properly by
7176 cmd_error, so this must be just an informative message; toss it. */
7177 if (FRAME_MESSAGE_BUF (f
))
7179 Lisp_Object args
[2], message
;
7180 struct gcpro gcpro1
, gcpro2
;
7182 args
[0] = build_string (m
);
7183 args
[1] = message
= string
;
7184 GCPRO2 (args
[0], message
);
7187 message
= Fformat (2, args
);
7190 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7192 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
7196 /* Print should start at the beginning of the message
7197 buffer next time. */
7198 message_buf_print
= 0;
7204 /* Dump an informative message to the minibuf. If M is 0, clear out
7205 any existing message, and let the mini-buffer text show through. */
7209 message (m
, a1
, a2
, a3
)
7211 EMACS_INT a1
, a2
, a3
;
7217 if (noninteractive_need_newline
)
7218 putc ('\n', stderr
);
7219 noninteractive_need_newline
= 0;
7220 fprintf (stderr
, m
, a1
, a2
, a3
);
7221 if (cursor_in_echo_area
== 0)
7222 fprintf (stderr
, "\n");
7226 else if (INTERACTIVE
)
7228 /* The frame whose mini-buffer we're going to display the message
7229 on. It may be larger than the selected frame, so we need to
7230 use its buffer, not the selected frame's buffer. */
7231 Lisp_Object mini_window
;
7232 struct frame
*f
, *sf
= SELECTED_FRAME ();
7234 /* Get the frame containing the mini-buffer
7235 that the selected frame is using. */
7236 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7237 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7239 /* A null message buffer means that the frame hasn't really been
7240 initialized yet. Error messages get reported properly by
7241 cmd_error, so this must be just an informative message; toss
7243 if (FRAME_MESSAGE_BUF (f
))
7254 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7255 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
7257 len
= doprnt (FRAME_MESSAGE_BUF (f
),
7258 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
7260 #endif /* NO_ARG_ARRAY */
7262 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
7267 /* Print should start at the beginning of the message
7268 buffer next time. */
7269 message_buf_print
= 0;
7275 /* The non-logging version of message. */
7278 message_nolog (m
, a1
, a2
, a3
)
7280 EMACS_INT a1
, a2
, a3
;
7282 Lisp_Object old_log_max
;
7283 old_log_max
= Vmessage_log_max
;
7284 Vmessage_log_max
= Qnil
;
7285 message (m
, a1
, a2
, a3
);
7286 Vmessage_log_max
= old_log_max
;
7290 /* Display the current message in the current mini-buffer. This is
7291 only called from error handlers in process.c, and is not time
7297 if (!NILP (echo_area_buffer
[0]))
7300 string
= Fcurrent_message ();
7301 message3 (string
, SBYTES (string
),
7302 !NILP (current_buffer
->enable_multibyte_characters
));
7307 /* Make sure echo area buffers in `echo_buffers' are live.
7308 If they aren't, make new ones. */
7311 ensure_echo_area_buffers ()
7315 for (i
= 0; i
< 2; ++i
)
7316 if (!BUFFERP (echo_buffer
[i
])
7317 || NILP (XBUFFER (echo_buffer
[i
])->name
))
7320 Lisp_Object old_buffer
;
7323 old_buffer
= echo_buffer
[i
];
7324 sprintf (name
, " *Echo Area %d*", i
);
7325 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
7326 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
7328 for (j
= 0; j
< 2; ++j
)
7329 if (EQ (old_buffer
, echo_area_buffer
[j
]))
7330 echo_area_buffer
[j
] = echo_buffer
[i
];
7335 /* Call FN with args A1..A4 with either the current or last displayed
7336 echo_area_buffer as current buffer.
7338 WHICH zero means use the current message buffer
7339 echo_area_buffer[0]. If that is nil, choose a suitable buffer
7340 from echo_buffer[] and clear it.
7342 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
7343 suitable buffer from echo_buffer[] and clear it.
7345 Value is what FN returns. */
7348 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
7351 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
7357 int this_one
, the_other
, clear_buffer_p
, rc
;
7358 int count
= SPECPDL_INDEX ();
7360 /* If buffers aren't live, make new ones. */
7361 ensure_echo_area_buffers ();
7366 this_one
= 0, the_other
= 1;
7368 this_one
= 1, the_other
= 0;
7370 /* Choose a suitable buffer from echo_buffer[] is we don't
7372 if (NILP (echo_area_buffer
[this_one
]))
7374 echo_area_buffer
[this_one
]
7375 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
7376 ? echo_buffer
[the_other
]
7377 : echo_buffer
[this_one
]);
7381 buffer
= echo_area_buffer
[this_one
];
7383 /* Don't get confused by reusing the buffer used for echoing
7384 for a different purpose. */
7385 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
7388 record_unwind_protect (unwind_with_echo_area_buffer
,
7389 with_echo_area_buffer_unwind_data (w
));
7391 /* Make the echo area buffer current. Note that for display
7392 purposes, it is not necessary that the displayed window's buffer
7393 == current_buffer, except for text property lookup. So, let's
7394 only set that buffer temporarily here without doing a full
7395 Fset_window_buffer. We must also change w->pointm, though,
7396 because otherwise an assertions in unshow_buffer fails, and Emacs
7398 set_buffer_internal_1 (XBUFFER (buffer
));
7402 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
7405 current_buffer
->undo_list
= Qt
;
7406 current_buffer
->read_only
= Qnil
;
7407 specbind (Qinhibit_read_only
, Qt
);
7408 specbind (Qinhibit_modification_hooks
, Qt
);
7410 if (clear_buffer_p
&& Z
> BEG
)
7413 xassert (BEGV
>= BEG
);
7414 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7416 rc
= fn (a1
, a2
, a3
, a4
);
7418 xassert (BEGV
>= BEG
);
7419 xassert (ZV
<= Z
&& ZV
>= BEGV
);
7421 unbind_to (count
, Qnil
);
7426 /* Save state that should be preserved around the call to the function
7427 FN called in with_echo_area_buffer. */
7430 with_echo_area_buffer_unwind_data (w
)
7436 /* Reduce consing by keeping one vector in
7437 Vwith_echo_area_save_vector. */
7438 vector
= Vwith_echo_area_save_vector
;
7439 Vwith_echo_area_save_vector
= Qnil
;
7442 vector
= Fmake_vector (make_number (7), Qnil
);
7444 XSETBUFFER (AREF (vector
, i
), current_buffer
); ++i
;
7445 AREF (vector
, i
) = Vdeactivate_mark
, ++i
;
7446 AREF (vector
, i
) = make_number (windows_or_buffers_changed
), ++i
;
7450 XSETWINDOW (AREF (vector
, i
), w
); ++i
;
7451 AREF (vector
, i
) = w
->buffer
; ++i
;
7452 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->charpos
); ++i
;
7453 AREF (vector
, i
) = make_number (XMARKER (w
->pointm
)->bytepos
); ++i
;
7458 for (; i
< end
; ++i
)
7459 AREF (vector
, i
) = Qnil
;
7462 xassert (i
== ASIZE (vector
));
7467 /* Restore global state from VECTOR which was created by
7468 with_echo_area_buffer_unwind_data. */
7471 unwind_with_echo_area_buffer (vector
)
7474 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
7475 Vdeactivate_mark
= AREF (vector
, 1);
7476 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
7478 if (WINDOWP (AREF (vector
, 3)))
7481 Lisp_Object buffer
, charpos
, bytepos
;
7483 w
= XWINDOW (AREF (vector
, 3));
7484 buffer
= AREF (vector
, 4);
7485 charpos
= AREF (vector
, 5);
7486 bytepos
= AREF (vector
, 6);
7489 set_marker_both (w
->pointm
, buffer
,
7490 XFASTINT (charpos
), XFASTINT (bytepos
));
7493 Vwith_echo_area_save_vector
= vector
;
7498 /* Set up the echo area for use by print functions. MULTIBYTE_P
7499 non-zero means we will print multibyte. */
7502 setup_echo_area_for_printing (multibyte_p
)
7505 /* If we can't find an echo area any more, exit. */
7506 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
7509 ensure_echo_area_buffers ();
7511 if (!message_buf_print
)
7513 /* A message has been output since the last time we printed.
7514 Choose a fresh echo area buffer. */
7515 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7516 echo_area_buffer
[0] = echo_buffer
[1];
7518 echo_area_buffer
[0] = echo_buffer
[0];
7520 /* Switch to that buffer and clear it. */
7521 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7522 current_buffer
->truncate_lines
= Qnil
;
7526 int count
= SPECPDL_INDEX ();
7527 specbind (Qinhibit_read_only
, Qt
);
7528 /* Note that undo recording is always disabled. */
7530 unbind_to (count
, Qnil
);
7532 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
7534 /* Set up the buffer for the multibyteness we need. */
7536 != !NILP (current_buffer
->enable_multibyte_characters
))
7537 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
7539 /* Raise the frame containing the echo area. */
7540 if (minibuffer_auto_raise
)
7542 struct frame
*sf
= SELECTED_FRAME ();
7543 Lisp_Object mini_window
;
7544 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7545 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7548 message_log_maybe_newline ();
7549 message_buf_print
= 1;
7553 if (NILP (echo_area_buffer
[0]))
7555 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
7556 echo_area_buffer
[0] = echo_buffer
[1];
7558 echo_area_buffer
[0] = echo_buffer
[0];
7561 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
7563 /* Someone switched buffers between print requests. */
7564 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
7565 current_buffer
->truncate_lines
= Qnil
;
7571 /* Display an echo area message in window W. Value is non-zero if W's
7572 height is changed. If display_last_displayed_message_p is
7573 non-zero, display the message that was last displayed, otherwise
7574 display the current message. */
7577 display_echo_area (w
)
7580 int i
, no_message_p
, window_height_changed_p
, count
;
7582 /* Temporarily disable garbage collections while displaying the echo
7583 area. This is done because a GC can print a message itself.
7584 That message would modify the echo area buffer's contents while a
7585 redisplay of the buffer is going on, and seriously confuse
7587 count
= inhibit_garbage_collection ();
7589 /* If there is no message, we must call display_echo_area_1
7590 nevertheless because it resizes the window. But we will have to
7591 reset the echo_area_buffer in question to nil at the end because
7592 with_echo_area_buffer will sets it to an empty buffer. */
7593 i
= display_last_displayed_message_p
? 1 : 0;
7594 no_message_p
= NILP (echo_area_buffer
[i
]);
7596 window_height_changed_p
7597 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
7598 display_echo_area_1
,
7599 (EMACS_INT
) w
, Qnil
, 0, 0);
7602 echo_area_buffer
[i
] = Qnil
;
7604 unbind_to (count
, Qnil
);
7605 return window_height_changed_p
;
7609 /* Helper for display_echo_area. Display the current buffer which
7610 contains the current echo area message in window W, a mini-window,
7611 a pointer to which is passed in A1. A2..A4 are currently not used.
7612 Change the height of W so that all of the message is displayed.
7613 Value is non-zero if height of W was changed. */
7616 display_echo_area_1 (a1
, a2
, a3
, a4
)
7621 struct window
*w
= (struct window
*) a1
;
7623 struct text_pos start
;
7624 int window_height_changed_p
= 0;
7626 /* Do this before displaying, so that we have a large enough glyph
7627 matrix for the display. */
7628 window_height_changed_p
= resize_mini_window (w
, 0);
7631 clear_glyph_matrix (w
->desired_matrix
);
7632 XSETWINDOW (window
, w
);
7633 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
7634 try_window (window
, start
, 0);
7636 return window_height_changed_p
;
7640 /* Resize the echo area window to exactly the size needed for the
7641 currently displayed message, if there is one. If a mini-buffer
7642 is active, don't shrink it. */
7645 resize_echo_area_exactly ()
7647 if (BUFFERP (echo_area_buffer
[0])
7648 && WINDOWP (echo_area_window
))
7650 struct window
*w
= XWINDOW (echo_area_window
);
7652 Lisp_Object resize_exactly
;
7654 if (minibuf_level
== 0)
7655 resize_exactly
= Qt
;
7657 resize_exactly
= Qnil
;
7659 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
7660 (EMACS_INT
) w
, resize_exactly
, 0, 0);
7663 ++windows_or_buffers_changed
;
7664 ++update_mode_lines
;
7665 redisplay_internal (0);
7671 /* Callback function for with_echo_area_buffer, when used from
7672 resize_echo_area_exactly. A1 contains a pointer to the window to
7673 resize, EXACTLY non-nil means resize the mini-window exactly to the
7674 size of the text displayed. A3 and A4 are not used. Value is what
7675 resize_mini_window returns. */
7678 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
7680 Lisp_Object exactly
;
7683 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
7687 /* Resize mini-window W to fit the size of its contents. EXACT:P
7688 means size the window exactly to the size needed. Otherwise, it's
7689 only enlarged until W's buffer is empty. Value is non-zero if
7690 the window height has been changed. */
7693 resize_mini_window (w
, exact_p
)
7697 struct frame
*f
= XFRAME (w
->frame
);
7698 int window_height_changed_p
= 0;
7700 xassert (MINI_WINDOW_P (w
));
7702 /* Don't resize windows while redisplaying a window; it would
7703 confuse redisplay functions when the size of the window they are
7704 displaying changes from under them. Such a resizing can happen,
7705 for instance, when which-func prints a long message while
7706 we are running fontification-functions. We're running these
7707 functions with safe_call which binds inhibit-redisplay to t. */
7708 if (!NILP (Vinhibit_redisplay
))
7711 /* Nil means don't try to resize. */
7712 if (NILP (Vresize_mini_windows
)
7713 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
7716 if (!FRAME_MINIBUF_ONLY_P (f
))
7719 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
7720 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
7721 int height
, max_height
;
7722 int unit
= FRAME_LINE_HEIGHT (f
);
7723 struct text_pos start
;
7724 struct buffer
*old_current_buffer
= NULL
;
7726 if (current_buffer
!= XBUFFER (w
->buffer
))
7728 old_current_buffer
= current_buffer
;
7729 set_buffer_internal (XBUFFER (w
->buffer
));
7732 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
7734 /* Compute the max. number of lines specified by the user. */
7735 if (FLOATP (Vmax_mini_window_height
))
7736 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
7737 else if (INTEGERP (Vmax_mini_window_height
))
7738 max_height
= XINT (Vmax_mini_window_height
);
7740 max_height
= total_height
/ 4;
7742 /* Correct that max. height if it's bogus. */
7743 max_height
= max (1, max_height
);
7744 max_height
= min (total_height
, max_height
);
7746 /* Find out the height of the text in the window. */
7747 if (it
.truncate_lines_p
)
7752 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
7753 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
7754 height
= it
.current_y
+ last_height
;
7756 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
7757 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
7758 height
= (height
+ unit
- 1) / unit
;
7761 /* Compute a suitable window start. */
7762 if (height
> max_height
)
7764 height
= max_height
;
7765 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
7766 move_it_vertically_backward (&it
, (height
- 1) * unit
);
7767 start
= it
.current
.pos
;
7770 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
7771 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
7773 if (EQ (Vresize_mini_windows
, Qgrow_only
))
7775 /* Let it grow only, until we display an empty message, in which
7776 case the window shrinks again. */
7777 if (height
> WINDOW_TOTAL_LINES (w
))
7779 int old_height
= WINDOW_TOTAL_LINES (w
);
7780 freeze_window_starts (f
, 1);
7781 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7782 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7784 else if (height
< WINDOW_TOTAL_LINES (w
)
7785 && (exact_p
|| BEGV
== ZV
))
7787 int old_height
= WINDOW_TOTAL_LINES (w
);
7788 freeze_window_starts (f
, 0);
7789 shrink_mini_window (w
);
7790 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7795 /* Always resize to exact size needed. */
7796 if (height
> WINDOW_TOTAL_LINES (w
))
7798 int old_height
= WINDOW_TOTAL_LINES (w
);
7799 freeze_window_starts (f
, 1);
7800 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7801 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7803 else if (height
< WINDOW_TOTAL_LINES (w
))
7805 int old_height
= WINDOW_TOTAL_LINES (w
);
7806 freeze_window_starts (f
, 0);
7807 shrink_mini_window (w
);
7811 freeze_window_starts (f
, 1);
7812 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
7815 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
7819 if (old_current_buffer
)
7820 set_buffer_internal (old_current_buffer
);
7823 return window_height_changed_p
;
7827 /* Value is the current message, a string, or nil if there is no
7835 if (NILP (echo_area_buffer
[0]))
7839 with_echo_area_buffer (0, 0, current_message_1
,
7840 (EMACS_INT
) &msg
, Qnil
, 0, 0);
7842 echo_area_buffer
[0] = Qnil
;
7850 current_message_1 (a1
, a2
, a3
, a4
)
7855 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
7858 *msg
= make_buffer_string (BEG
, Z
, 1);
7865 /* Push the current message on Vmessage_stack for later restauration
7866 by restore_message. Value is non-zero if the current message isn't
7867 empty. This is a relatively infrequent operation, so it's not
7868 worth optimizing. */
7874 msg
= current_message ();
7875 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
7876 return STRINGP (msg
);
7880 /* Restore message display from the top of Vmessage_stack. */
7887 xassert (CONSP (Vmessage_stack
));
7888 msg
= XCAR (Vmessage_stack
);
7890 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
7892 message3_nolog (msg
, 0, 0);
7896 /* Handler for record_unwind_protect calling pop_message. */
7899 pop_message_unwind (dummy
)
7906 /* Pop the top-most entry off Vmessage_stack. */
7911 xassert (CONSP (Vmessage_stack
));
7912 Vmessage_stack
= XCDR (Vmessage_stack
);
7916 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
7917 exits. If the stack is not empty, we have a missing pop_message
7921 check_message_stack ()
7923 if (!NILP (Vmessage_stack
))
7928 /* Truncate to NCHARS what will be displayed in the echo area the next
7929 time we display it---but don't redisplay it now. */
7932 truncate_echo_area (nchars
)
7936 echo_area_buffer
[0] = Qnil
;
7937 /* A null message buffer means that the frame hasn't really been
7938 initialized yet. Error messages get reported properly by
7939 cmd_error, so this must be just an informative message; toss it. */
7940 else if (!noninteractive
7942 && !NILP (echo_area_buffer
[0]))
7944 struct frame
*sf
= SELECTED_FRAME ();
7945 if (FRAME_MESSAGE_BUF (sf
))
7946 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
7951 /* Helper function for truncate_echo_area. Truncate the current
7952 message to at most NCHARS characters. */
7955 truncate_message_1 (nchars
, a2
, a3
, a4
)
7960 if (BEG
+ nchars
< Z
)
7961 del_range (BEG
+ nchars
, Z
);
7963 echo_area_buffer
[0] = Qnil
;
7968 /* Set the current message to a substring of S or STRING.
7970 If STRING is a Lisp string, set the message to the first NBYTES
7971 bytes from STRING. NBYTES zero means use the whole string. If
7972 STRING is multibyte, the message will be displayed multibyte.
7974 If S is not null, set the message to the first LEN bytes of S. LEN
7975 zero means use the whole string. MULTIBYTE_P non-zero means S is
7976 multibyte. Display the message multibyte in that case. */
7979 set_message (s
, string
, nbytes
, multibyte_p
)
7982 int nbytes
, multibyte_p
;
7984 message_enable_multibyte
7985 = ((s
&& multibyte_p
)
7986 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
7988 with_echo_area_buffer (0, 0, set_message_1
,
7989 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
7990 message_buf_print
= 0;
7991 help_echo_showing_p
= 0;
7995 /* Helper function for set_message. Arguments have the same meaning
7996 as there, with A1 corresponding to S and A2 corresponding to STRING
7997 This function is called with the echo area buffer being
8001 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
8004 EMACS_INT nbytes
, multibyte_p
;
8006 const char *s
= (const char *) a1
;
8007 Lisp_Object string
= a2
;
8009 /* Change multibyteness of the echo buffer appropriately. */
8010 if (message_enable_multibyte
8011 != !NILP (current_buffer
->enable_multibyte_characters
))
8012 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
8014 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
8016 /* Insert new message at BEG. */
8017 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8020 if (STRINGP (string
))
8025 nbytes
= SBYTES (string
);
8026 nchars
= string_byte_to_char (string
, nbytes
);
8028 /* This function takes care of single/multibyte conversion. We
8029 just have to ensure that the echo area buffer has the right
8030 setting of enable_multibyte_characters. */
8031 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
8036 nbytes
= strlen (s
);
8038 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
8040 /* Convert from multi-byte to single-byte. */
8042 unsigned char work
[1];
8044 /* Convert a multibyte string to single-byte. */
8045 for (i
= 0; i
< nbytes
; i
+= n
)
8047 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
8048 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
8050 : multibyte_char_to_unibyte (c
, Qnil
));
8051 insert_1_both (work
, 1, 1, 1, 0, 0);
8054 else if (!multibyte_p
8055 && !NILP (current_buffer
->enable_multibyte_characters
))
8057 /* Convert from single-byte to multi-byte. */
8059 const unsigned char *msg
= (const unsigned char *) s
;
8060 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8062 /* Convert a single-byte string to multibyte. */
8063 for (i
= 0; i
< nbytes
; i
++)
8065 c
= unibyte_char_to_multibyte (msg
[i
]);
8066 n
= CHAR_STRING (c
, str
);
8067 insert_1_both (str
, 1, n
, 1, 0, 0);
8071 insert_1 (s
, nbytes
, 1, 0, 0);
8078 /* Clear messages. CURRENT_P non-zero means clear the current
8079 message. LAST_DISPLAYED_P non-zero means clear the message
8083 clear_message (current_p
, last_displayed_p
)
8084 int current_p
, last_displayed_p
;
8088 echo_area_buffer
[0] = Qnil
;
8089 message_cleared_p
= 1;
8092 if (last_displayed_p
)
8093 echo_area_buffer
[1] = Qnil
;
8095 message_buf_print
= 0;
8098 /* Clear garbaged frames.
8100 This function is used where the old redisplay called
8101 redraw_garbaged_frames which in turn called redraw_frame which in
8102 turn called clear_frame. The call to clear_frame was a source of
8103 flickering. I believe a clear_frame is not necessary. It should
8104 suffice in the new redisplay to invalidate all current matrices,
8105 and ensure a complete redisplay of all windows. */
8108 clear_garbaged_frames ()
8112 Lisp_Object tail
, frame
;
8113 int changed_count
= 0;
8115 FOR_EACH_FRAME (tail
, frame
)
8117 struct frame
*f
= XFRAME (frame
);
8119 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
8123 Fredraw_frame (frame
);
8124 f
->force_flush_display_p
= 1;
8126 clear_current_matrices (f
);
8135 ++windows_or_buffers_changed
;
8140 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
8141 is non-zero update selected_frame. Value is non-zero if the
8142 mini-windows height has been changed. */
8145 echo_area_display (update_frame_p
)
8148 Lisp_Object mini_window
;
8151 int window_height_changed_p
= 0;
8152 struct frame
*sf
= SELECTED_FRAME ();
8154 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8155 w
= XWINDOW (mini_window
);
8156 f
= XFRAME (WINDOW_FRAME (w
));
8158 /* Don't display if frame is invisible or not yet initialized. */
8159 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
8162 /* The terminal frame is used as the first Emacs frame on the Mac OS. */
8164 #ifdef HAVE_WINDOW_SYSTEM
8165 /* When Emacs starts, selected_frame may be a visible terminal
8166 frame, even if we run under a window system. If we let this
8167 through, a message would be displayed on the terminal. */
8168 if (EQ (selected_frame
, Vterminal_frame
)
8169 && !NILP (Vwindow_system
))
8171 #endif /* HAVE_WINDOW_SYSTEM */
8174 /* Redraw garbaged frames. */
8176 clear_garbaged_frames ();
8178 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
8180 echo_area_window
= mini_window
;
8181 window_height_changed_p
= display_echo_area (w
);
8182 w
->must_be_updated_p
= 1;
8184 /* Update the display, unless called from redisplay_internal.
8185 Also don't update the screen during redisplay itself. The
8186 update will happen at the end of redisplay, and an update
8187 here could cause confusion. */
8188 if (update_frame_p
&& !redisplaying_p
)
8192 /* If the display update has been interrupted by pending
8193 input, update mode lines in the frame. Due to the
8194 pending input, it might have been that redisplay hasn't
8195 been called, so that mode lines above the echo area are
8196 garbaged. This looks odd, so we prevent it here. */
8197 if (!display_completed
)
8198 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
8200 if (window_height_changed_p
8201 /* Don't do this if Emacs is shutting down. Redisplay
8202 needs to run hooks. */
8203 && !NILP (Vrun_hooks
))
8205 /* Must update other windows. Likewise as in other
8206 cases, don't let this update be interrupted by
8208 int count
= SPECPDL_INDEX ();
8209 specbind (Qredisplay_dont_pause
, Qt
);
8210 windows_or_buffers_changed
= 1;
8211 redisplay_internal (0);
8212 unbind_to (count
, Qnil
);
8214 else if (FRAME_WINDOW_P (f
) && n
== 0)
8216 /* Window configuration is the same as before.
8217 Can do with a display update of the echo area,
8218 unless we displayed some mode lines. */
8219 update_single_window (w
, 1);
8220 rif
->flush_display (f
);
8223 update_frame (f
, 1, 1);
8225 /* If cursor is in the echo area, make sure that the next
8226 redisplay displays the minibuffer, so that the cursor will
8227 be replaced with what the minibuffer wants. */
8228 if (cursor_in_echo_area
)
8229 ++windows_or_buffers_changed
;
8232 else if (!EQ (mini_window
, selected_window
))
8233 windows_or_buffers_changed
++;
8235 /* The current message is now also the last one displayed. */
8236 echo_area_buffer
[1] = echo_area_buffer
[0];
8238 /* Prevent redisplay optimization in redisplay_internal by resetting
8239 this_line_start_pos. This is done because the mini-buffer now
8240 displays the message instead of its buffer text. */
8241 if (EQ (mini_window
, selected_window
))
8242 CHARPOS (this_line_start_pos
) = 0;
8244 return window_height_changed_p
;
8249 /***********************************************************************
8250 Mode Lines and Frame Titles
8251 ***********************************************************************/
8253 /* A buffer for constructing non-propertized mode-line strings and
8254 frame titles in it; allocated from the heap in init_xdisp and
8255 resized as needed in store_mode_line_noprop_char. */
8257 static char *mode_line_noprop_buf
;
8259 /* The buffer's end, and a current output position in it. */
8261 static char *mode_line_noprop_buf_end
;
8262 static char *mode_line_noprop_ptr
;
8264 #define MODE_LINE_NOPROP_LEN(start) \
8265 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
8268 MODE_LINE_DISPLAY
= 0,
8274 /* Alist that caches the results of :propertize.
8275 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
8276 static Lisp_Object mode_line_proptrans_alist
;
8278 /* List of strings making up the mode-line. */
8279 static Lisp_Object mode_line_string_list
;
8281 /* Base face property when building propertized mode line string. */
8282 static Lisp_Object mode_line_string_face
;
8283 static Lisp_Object mode_line_string_face_prop
;
8286 /* Unwind data for mode line strings */
8288 static Lisp_Object Vmode_line_unwind_vector
;
8291 format_mode_line_unwind_data (obuf
)
8292 struct buffer
*obuf
;
8296 /* Reduce consing by keeping one vector in
8297 Vwith_echo_area_save_vector. */
8298 vector
= Vmode_line_unwind_vector
;
8299 Vmode_line_unwind_vector
= Qnil
;
8302 vector
= Fmake_vector (make_number (7), Qnil
);
8304 AREF (vector
, 0) = make_number (mode_line_target
);
8305 AREF (vector
, 1) = make_number (MODE_LINE_NOPROP_LEN (0));
8306 AREF (vector
, 2) = mode_line_string_list
;
8307 AREF (vector
, 3) = mode_line_proptrans_alist
;
8308 AREF (vector
, 4) = mode_line_string_face
;
8309 AREF (vector
, 5) = mode_line_string_face_prop
;
8312 XSETBUFFER (AREF (vector
, 6), obuf
);
8314 AREF (vector
, 6) = Qnil
;
8320 unwind_format_mode_line (vector
)
8323 mode_line_target
= XINT (AREF (vector
, 0));
8324 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
8325 mode_line_string_list
= AREF (vector
, 2);
8326 mode_line_proptrans_alist
= AREF (vector
, 3);
8327 mode_line_string_face
= AREF (vector
, 4);
8328 mode_line_string_face_prop
= AREF (vector
, 5);
8330 if (!NILP (AREF (vector
, 6)))
8332 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
8333 AREF (vector
, 6) = Qnil
;
8336 Vmode_line_unwind_vector
= vector
;
8341 /* Store a single character C for the frame title in mode_line_noprop_buf.
8342 Re-allocate mode_line_noprop_buf if necessary. */
8346 store_mode_line_noprop_char (char c
)
8348 store_mode_line_noprop_char (c
)
8352 /* If output position has reached the end of the allocated buffer,
8353 double the buffer's size. */
8354 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
8356 int len
= MODE_LINE_NOPROP_LEN (0);
8357 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
8358 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
8359 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
8360 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
8363 *mode_line_noprop_ptr
++ = c
;
8367 /* Store part of a frame title in mode_line_noprop_buf, beginning at
8368 mode_line_noprop_ptr. STR is the string to store. Do not copy
8369 characters that yield more columns than PRECISION; PRECISION <= 0
8370 means copy the whole string. Pad with spaces until FIELD_WIDTH
8371 number of characters have been copied; FIELD_WIDTH <= 0 means don't
8372 pad. Called from display_mode_element when it is used to build a
8376 store_mode_line_noprop (str
, field_width
, precision
)
8377 const unsigned char *str
;
8378 int field_width
, precision
;
8383 /* Copy at most PRECISION chars from STR. */
8384 nbytes
= strlen (str
);
8385 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
8387 store_mode_line_noprop_char (*str
++);
8389 /* Fill up with spaces until FIELD_WIDTH reached. */
8390 while (field_width
> 0
8393 store_mode_line_noprop_char (' ');
8400 /***********************************************************************
8402 ***********************************************************************/
8404 #ifdef HAVE_WINDOW_SYSTEM
8406 /* Set the title of FRAME, if it has changed. The title format is
8407 Vicon_title_format if FRAME is iconified, otherwise it is
8408 frame_title_format. */
8411 x_consider_frame_title (frame
)
8414 struct frame
*f
= XFRAME (frame
);
8416 if (FRAME_WINDOW_P (f
)
8417 || FRAME_MINIBUF_ONLY_P (f
)
8418 || f
->explicit_name
)
8420 /* Do we have more than one visible frame on this X display? */
8427 int count
= SPECPDL_INDEX ();
8429 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
8431 Lisp_Object other_frame
= XCAR (tail
);
8432 struct frame
*tf
= XFRAME (other_frame
);
8435 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
8436 && !FRAME_MINIBUF_ONLY_P (tf
)
8437 && !EQ (other_frame
, tip_frame
)
8438 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
8442 /* Set global variable indicating that multiple frames exist. */
8443 multiple_frames
= CONSP (tail
);
8445 /* Switch to the buffer of selected window of the frame. Set up
8446 mode_line_target so that display_mode_element will output into
8447 mode_line_noprop_buf; then display the title. */
8448 record_unwind_protect (unwind_format_mode_line
,
8449 format_mode_line_unwind_data (current_buffer
));
8451 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
8452 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
8454 mode_line_target
= MODE_LINE_TITLE
;
8455 title_start
= MODE_LINE_NOPROP_LEN (0);
8456 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
8457 NULL
, DEFAULT_FACE_ID
);
8458 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
8459 len
= MODE_LINE_NOPROP_LEN (title_start
);
8460 title
= mode_line_noprop_buf
+ title_start
;
8461 unbind_to (count
, Qnil
);
8463 /* Set the title only if it's changed. This avoids consing in
8464 the common case where it hasn't. (If it turns out that we've
8465 already wasted too much time by walking through the list with
8466 display_mode_element, then we might need to optimize at a
8467 higher level than this.) */
8468 if (! STRINGP (f
->name
)
8469 || SBYTES (f
->name
) != len
8470 || bcmp (title
, SDATA (f
->name
), len
) != 0)
8471 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
8475 #endif /* not HAVE_WINDOW_SYSTEM */
8480 /***********************************************************************
8482 ***********************************************************************/
8485 /* Prepare for redisplay by updating menu-bar item lists when
8486 appropriate. This can call eval. */
8489 prepare_menu_bars ()
8492 struct gcpro gcpro1
, gcpro2
;
8494 Lisp_Object tooltip_frame
;
8496 #ifdef HAVE_WINDOW_SYSTEM
8497 tooltip_frame
= tip_frame
;
8499 tooltip_frame
= Qnil
;
8502 /* Update all frame titles based on their buffer names, etc. We do
8503 this before the menu bars so that the buffer-menu will show the
8504 up-to-date frame titles. */
8505 #ifdef HAVE_WINDOW_SYSTEM
8506 if (windows_or_buffers_changed
|| update_mode_lines
)
8508 Lisp_Object tail
, frame
;
8510 FOR_EACH_FRAME (tail
, frame
)
8513 if (!EQ (frame
, tooltip_frame
)
8514 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
8515 x_consider_frame_title (frame
);
8518 #endif /* HAVE_WINDOW_SYSTEM */
8520 /* Update the menu bar item lists, if appropriate. This has to be
8521 done before any actual redisplay or generation of display lines. */
8522 all_windows
= (update_mode_lines
8523 || buffer_shared
> 1
8524 || windows_or_buffers_changed
);
8527 Lisp_Object tail
, frame
;
8528 int count
= SPECPDL_INDEX ();
8530 record_unwind_save_match_data ();
8532 FOR_EACH_FRAME (tail
, frame
)
8536 /* Ignore tooltip frame. */
8537 if (EQ (frame
, tooltip_frame
))
8540 /* If a window on this frame changed size, report that to
8541 the user and clear the size-change flag. */
8542 if (FRAME_WINDOW_SIZES_CHANGED (f
))
8544 Lisp_Object functions
;
8546 /* Clear flag first in case we get an error below. */
8547 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
8548 functions
= Vwindow_size_change_functions
;
8549 GCPRO2 (tail
, functions
);
8551 while (CONSP (functions
))
8553 call1 (XCAR (functions
), frame
);
8554 functions
= XCDR (functions
);
8560 update_menu_bar (f
, 0);
8561 #ifdef HAVE_WINDOW_SYSTEM
8562 update_tool_bar (f
, 0);
8567 unbind_to (count
, Qnil
);
8571 struct frame
*sf
= SELECTED_FRAME ();
8572 update_menu_bar (sf
, 1);
8573 #ifdef HAVE_WINDOW_SYSTEM
8574 update_tool_bar (sf
, 1);
8578 /* Motif needs this. See comment in xmenu.c. Turn it off when
8579 pending_menu_activation is not defined. */
8580 #ifdef USE_X_TOOLKIT
8581 pending_menu_activation
= 0;
8586 /* Update the menu bar item list for frame F. This has to be done
8587 before we start to fill in any display lines, because it can call
8590 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
8593 update_menu_bar (f
, save_match_data
)
8595 int save_match_data
;
8598 register struct window
*w
;
8600 /* If called recursively during a menu update, do nothing. This can
8601 happen when, for instance, an activate-menubar-hook causes a
8603 if (inhibit_menubar_update
)
8606 window
= FRAME_SELECTED_WINDOW (f
);
8607 w
= XWINDOW (window
);
8609 #if 0 /* The if statement below this if statement used to include the
8610 condition !NILP (w->update_mode_line), rather than using
8611 update_mode_lines directly, and this if statement may have
8612 been added to make that condition work. Now the if
8613 statement below matches its comment, this isn't needed. */
8614 if (update_mode_lines
)
8615 w
->update_mode_line
= Qt
;
8618 if (FRAME_WINDOW_P (f
)
8620 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8621 || defined (USE_GTK)
8622 FRAME_EXTERNAL_MENU_BAR (f
)
8624 FRAME_MENU_BAR_LINES (f
) > 0
8626 : FRAME_MENU_BAR_LINES (f
) > 0)
8628 /* If the user has switched buffers or windows, we need to
8629 recompute to reflect the new bindings. But we'll
8630 recompute when update_mode_lines is set too; that means
8631 that people can use force-mode-line-update to request
8632 that the menu bar be recomputed. The adverse effect on
8633 the rest of the redisplay algorithm is about the same as
8634 windows_or_buffers_changed anyway. */
8635 if (windows_or_buffers_changed
8636 /* This used to test w->update_mode_line, but we believe
8637 there is no need to recompute the menu in that case. */
8638 || update_mode_lines
8639 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8640 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8641 != !NILP (w
->last_had_star
))
8642 || ((!NILP (Vtransient_mark_mode
)
8643 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8644 != !NILP (w
->region_showing
)))
8646 struct buffer
*prev
= current_buffer
;
8647 int count
= SPECPDL_INDEX ();
8649 specbind (Qinhibit_menubar_update
, Qt
);
8651 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8652 if (save_match_data
)
8653 record_unwind_save_match_data ();
8654 if (NILP (Voverriding_local_map_menu_flag
))
8656 specbind (Qoverriding_terminal_local_map
, Qnil
);
8657 specbind (Qoverriding_local_map
, Qnil
);
8660 /* Run the Lucid hook. */
8661 safe_run_hooks (Qactivate_menubar_hook
);
8663 /* If it has changed current-menubar from previous value,
8664 really recompute the menu-bar from the value. */
8665 if (! NILP (Vlucid_menu_bar_dirty_flag
))
8666 call0 (Qrecompute_lucid_menubar
);
8668 safe_run_hooks (Qmenu_bar_update_hook
);
8669 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
8671 /* Redisplay the menu bar in case we changed it. */
8672 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
8673 || defined (USE_GTK)
8674 if (FRAME_WINDOW_P (f
)
8675 #if defined (MAC_OS)
8676 /* All frames on Mac OS share the same menubar. So only the
8677 selected frame should be allowed to set it. */
8678 && f
== SELECTED_FRAME ()
8681 set_frame_menubar (f
, 0, 0);
8683 /* On a terminal screen, the menu bar is an ordinary screen
8684 line, and this makes it get updated. */
8685 w
->update_mode_line
= Qt
;
8686 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8687 /* In the non-toolkit version, the menu bar is an ordinary screen
8688 line, and this makes it get updated. */
8689 w
->update_mode_line
= Qt
;
8690 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || MAC_OS || USE_GTK) */
8692 unbind_to (count
, Qnil
);
8693 set_buffer_internal_1 (prev
);
8700 /***********************************************************************
8702 ***********************************************************************/
8704 #ifdef HAVE_WINDOW_SYSTEM
8707 Nominal cursor position -- where to draw output.
8708 HPOS and VPOS are window relative glyph matrix coordinates.
8709 X and Y are window relative pixel coordinates. */
8711 struct cursor_pos output_cursor
;
8715 Set the global variable output_cursor to CURSOR. All cursor
8716 positions are relative to updated_window. */
8719 set_output_cursor (cursor
)
8720 struct cursor_pos
*cursor
;
8722 output_cursor
.hpos
= cursor
->hpos
;
8723 output_cursor
.vpos
= cursor
->vpos
;
8724 output_cursor
.x
= cursor
->x
;
8725 output_cursor
.y
= cursor
->y
;
8730 Set a nominal cursor position.
8732 HPOS and VPOS are column/row positions in a window glyph matrix. X
8733 and Y are window text area relative pixel positions.
8735 If this is done during an update, updated_window will contain the
8736 window that is being updated and the position is the future output
8737 cursor position for that window. If updated_window is null, use
8738 selected_window and display the cursor at the given position. */
8741 x_cursor_to (vpos
, hpos
, y
, x
)
8742 int vpos
, hpos
, y
, x
;
8746 /* If updated_window is not set, work on selected_window. */
8750 w
= XWINDOW (selected_window
);
8752 /* Set the output cursor. */
8753 output_cursor
.hpos
= hpos
;
8754 output_cursor
.vpos
= vpos
;
8755 output_cursor
.x
= x
;
8756 output_cursor
.y
= y
;
8758 /* If not called as part of an update, really display the cursor.
8759 This will also set the cursor position of W. */
8760 if (updated_window
== NULL
)
8763 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
8764 if (rif
->flush_display_optional
)
8765 rif
->flush_display_optional (SELECTED_FRAME ());
8770 #endif /* HAVE_WINDOW_SYSTEM */
8773 /***********************************************************************
8775 ***********************************************************************/
8777 #ifdef HAVE_WINDOW_SYSTEM
8779 /* Where the mouse was last time we reported a mouse event. */
8781 FRAME_PTR last_mouse_frame
;
8783 /* Tool-bar item index of the item on which a mouse button was pressed
8786 int last_tool_bar_item
;
8789 /* Update the tool-bar item list for frame F. This has to be done
8790 before we start to fill in any display lines. Called from
8791 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
8792 and restore it here. */
8795 update_tool_bar (f
, save_match_data
)
8797 int save_match_data
;
8800 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
8802 int do_update
= WINDOWP (f
->tool_bar_window
)
8803 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
8811 window
= FRAME_SELECTED_WINDOW (f
);
8812 w
= XWINDOW (window
);
8814 /* If the user has switched buffers or windows, we need to
8815 recompute to reflect the new bindings. But we'll
8816 recompute when update_mode_lines is set too; that means
8817 that people can use force-mode-line-update to request
8818 that the menu bar be recomputed. The adverse effect on
8819 the rest of the redisplay algorithm is about the same as
8820 windows_or_buffers_changed anyway. */
8821 if (windows_or_buffers_changed
8822 || !NILP (w
->update_mode_line
)
8823 || update_mode_lines
8824 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
8825 < BUF_MODIFF (XBUFFER (w
->buffer
)))
8826 != !NILP (w
->last_had_star
))
8827 || ((!NILP (Vtransient_mark_mode
)
8828 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
8829 != !NILP (w
->region_showing
)))
8831 struct buffer
*prev
= current_buffer
;
8832 int count
= SPECPDL_INDEX ();
8833 Lisp_Object new_tool_bar
;
8835 struct gcpro gcpro1
;
8837 /* Set current_buffer to the buffer of the selected
8838 window of the frame, so that we get the right local
8840 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8842 /* Save match data, if we must. */
8843 if (save_match_data
)
8844 record_unwind_save_match_data ();
8846 /* Make sure that we don't accidentally use bogus keymaps. */
8847 if (NILP (Voverriding_local_map_menu_flag
))
8849 specbind (Qoverriding_terminal_local_map
, Qnil
);
8850 specbind (Qoverriding_local_map
, Qnil
);
8853 GCPRO1 (new_tool_bar
);
8855 /* Build desired tool-bar items from keymaps. */
8856 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
8859 /* Redisplay the tool-bar if we changed it. */
8860 if (NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
8862 /* Redisplay that happens asynchronously due to an expose event
8863 may access f->tool_bar_items. Make sure we update both
8864 variables within BLOCK_INPUT so no such event interrupts. */
8866 f
->tool_bar_items
= new_tool_bar
;
8867 f
->n_tool_bar_items
= new_n_tool_bar
;
8868 w
->update_mode_line
= Qt
;
8874 unbind_to (count
, Qnil
);
8875 set_buffer_internal_1 (prev
);
8881 /* Set F->desired_tool_bar_string to a Lisp string representing frame
8882 F's desired tool-bar contents. F->tool_bar_items must have
8883 been set up previously by calling prepare_menu_bars. */
8886 build_desired_tool_bar_string (f
)
8889 int i
, size
, size_needed
;
8890 struct gcpro gcpro1
, gcpro2
, gcpro3
;
8891 Lisp_Object image
, plist
, props
;
8893 image
= plist
= props
= Qnil
;
8894 GCPRO3 (image
, plist
, props
);
8896 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
8897 Otherwise, make a new string. */
8899 /* The size of the string we might be able to reuse. */
8900 size
= (STRINGP (f
->desired_tool_bar_string
)
8901 ? SCHARS (f
->desired_tool_bar_string
)
8904 /* We need one space in the string for each image. */
8905 size_needed
= f
->n_tool_bar_items
;
8907 /* Reuse f->desired_tool_bar_string, if possible. */
8908 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
8909 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
8913 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
8914 Fremove_text_properties (make_number (0), make_number (size
),
8915 props
, f
->desired_tool_bar_string
);
8918 /* Put a `display' property on the string for the images to display,
8919 put a `menu_item' property on tool-bar items with a value that
8920 is the index of the item in F's tool-bar item vector. */
8921 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
8923 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
8925 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
8926 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
8927 int hmargin
, vmargin
, relief
, idx
, end
;
8928 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
8930 /* If image is a vector, choose the image according to the
8932 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
8933 if (VECTORP (image
))
8937 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
8938 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
8941 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
8942 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
8944 xassert (ASIZE (image
) >= idx
);
8945 image
= AREF (image
, idx
);
8950 /* Ignore invalid image specifications. */
8951 if (!valid_image_p (image
))
8954 /* Display the tool-bar button pressed, or depressed. */
8955 plist
= Fcopy_sequence (XCDR (image
));
8957 /* Compute margin and relief to draw. */
8958 relief
= (tool_bar_button_relief
>= 0
8959 ? tool_bar_button_relief
8960 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
8961 hmargin
= vmargin
= relief
;
8963 if (INTEGERP (Vtool_bar_button_margin
)
8964 && XINT (Vtool_bar_button_margin
) > 0)
8966 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
8967 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
8969 else if (CONSP (Vtool_bar_button_margin
))
8971 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
8972 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
8973 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
8975 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
8976 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
8977 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
8980 if (auto_raise_tool_bar_buttons_p
)
8982 /* Add a `:relief' property to the image spec if the item is
8986 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
8993 /* If image is selected, display it pressed, i.e. with a
8994 negative relief. If it's not selected, display it with a
8996 plist
= Fplist_put (plist
, QCrelief
,
8998 ? make_number (-relief
)
8999 : make_number (relief
)));
9004 /* Put a margin around the image. */
9005 if (hmargin
|| vmargin
)
9007 if (hmargin
== vmargin
)
9008 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
9010 plist
= Fplist_put (plist
, QCmargin
,
9011 Fcons (make_number (hmargin
),
9012 make_number (vmargin
)));
9015 /* If button is not enabled, and we don't have special images
9016 for the disabled state, make the image appear disabled by
9017 applying an appropriate algorithm to it. */
9018 if (!enabled_p
&& idx
< 0)
9019 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
9021 /* Put a `display' text property on the string for the image to
9022 display. Put a `menu-item' property on the string that gives
9023 the start of this item's properties in the tool-bar items
9025 image
= Fcons (Qimage
, plist
);
9026 props
= list4 (Qdisplay
, image
,
9027 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
9029 /* Let the last image hide all remaining spaces in the tool bar
9030 string. The string can be longer than needed when we reuse a
9032 if (i
+ 1 == f
->n_tool_bar_items
)
9033 end
= SCHARS (f
->desired_tool_bar_string
);
9036 Fadd_text_properties (make_number (i
), make_number (end
),
9037 props
, f
->desired_tool_bar_string
);
9045 /* Display one line of the tool-bar of frame IT->f. */
9048 display_tool_bar_line (it
)
9051 struct glyph_row
*row
= it
->glyph_row
;
9052 int max_x
= it
->last_visible_x
;
9055 prepare_desired_row (row
);
9056 row
->y
= it
->current_y
;
9058 /* Note that this isn't made use of if the face hasn't a box,
9059 so there's no need to check the face here. */
9060 it
->start_of_box_run_p
= 1;
9062 while (it
->current_x
< max_x
)
9064 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
9066 /* Get the next display element. */
9067 if (!get_next_display_element (it
))
9070 /* Produce glyphs. */
9071 x_before
= it
->current_x
;
9072 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
9073 PRODUCE_GLYPHS (it
);
9075 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
9080 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
9082 if (x
+ glyph
->pixel_width
> max_x
)
9084 /* Glyph doesn't fit on line. */
9085 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
9091 x
+= glyph
->pixel_width
;
9095 /* Stop at line ends. */
9096 if (ITERATOR_AT_END_OF_LINE_P (it
))
9099 set_iterator_to_next (it
, 1);
9104 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
9105 extend_face_to_end_of_line (it
);
9106 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
9107 last
->right_box_line_p
= 1;
9108 if (last
== row
->glyphs
[TEXT_AREA
])
9109 last
->left_box_line_p
= 1;
9110 compute_line_metrics (it
);
9112 /* If line is empty, make it occupy the rest of the tool-bar. */
9113 if (!row
->displays_text_p
)
9115 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
9116 row
->ascent
= row
->phys_ascent
= 0;
9117 row
->extra_line_spacing
= 0;
9120 row
->full_width_p
= 1;
9121 row
->continued_p
= 0;
9122 row
->truncated_on_left_p
= 0;
9123 row
->truncated_on_right_p
= 0;
9125 it
->current_x
= it
->hpos
= 0;
9126 it
->current_y
+= row
->height
;
9132 /* Value is the number of screen lines needed to make all tool-bar
9133 items of frame F visible. */
9136 tool_bar_lines_needed (f
)
9139 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9142 /* Initialize an iterator for iteration over
9143 F->desired_tool_bar_string in the tool-bar window of frame F. */
9144 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9145 it
.first_visible_x
= 0;
9146 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9147 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9149 while (!ITERATOR_AT_END_P (&it
))
9151 it
.glyph_row
= w
->desired_matrix
->rows
;
9152 clear_glyph_row (it
.glyph_row
);
9153 display_tool_bar_line (&it
);
9156 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
9160 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
9162 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
9171 frame
= selected_frame
;
9173 CHECK_FRAME (frame
);
9176 if (WINDOWP (f
->tool_bar_window
)
9177 || (w
= XWINDOW (f
->tool_bar_window
),
9178 WINDOW_TOTAL_LINES (w
) > 0))
9180 update_tool_bar (f
, 1);
9181 if (f
->n_tool_bar_items
)
9183 build_desired_tool_bar_string (f
);
9184 nlines
= tool_bar_lines_needed (f
);
9188 return make_number (nlines
);
9192 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
9193 height should be changed. */
9196 redisplay_tool_bar (f
)
9201 struct glyph_row
*row
;
9202 int change_height_p
= 0;
9205 if (FRAME_EXTERNAL_TOOL_BAR (f
))
9206 update_frame_tool_bar (f
);
9210 /* If frame hasn't a tool-bar window or if it is zero-height, don't
9211 do anything. This means you must start with tool-bar-lines
9212 non-zero to get the auto-sizing effect. Or in other words, you
9213 can turn off tool-bars by specifying tool-bar-lines zero. */
9214 if (!WINDOWP (f
->tool_bar_window
)
9215 || (w
= XWINDOW (f
->tool_bar_window
),
9216 WINDOW_TOTAL_LINES (w
) == 0))
9219 /* Set up an iterator for the tool-bar window. */
9220 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
9221 it
.first_visible_x
= 0;
9222 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
9225 /* Build a string that represents the contents of the tool-bar. */
9226 build_desired_tool_bar_string (f
);
9227 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
9229 /* Display as many lines as needed to display all tool-bar items. */
9230 while (it
.current_y
< it
.last_visible_y
)
9231 display_tool_bar_line (&it
);
9233 /* It doesn't make much sense to try scrolling in the tool-bar
9234 window, so don't do it. */
9235 w
->desired_matrix
->no_scrolling_p
= 1;
9236 w
->must_be_updated_p
= 1;
9238 if (auto_resize_tool_bars_p
)
9242 /* If we couldn't display everything, change the tool-bar's
9244 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
9245 change_height_p
= 1;
9247 /* If there are blank lines at the end, except for a partially
9248 visible blank line at the end that is smaller than
9249 FRAME_LINE_HEIGHT, change the tool-bar's height. */
9250 row
= it
.glyph_row
- 1;
9251 if (!row
->displays_text_p
9252 && row
->height
>= FRAME_LINE_HEIGHT (f
))
9253 change_height_p
= 1;
9255 /* If row displays tool-bar items, but is partially visible,
9256 change the tool-bar's height. */
9257 if (row
->displays_text_p
9258 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
9259 change_height_p
= 1;
9261 /* Resize windows as needed by changing the `tool-bar-lines'
9264 && (nlines
= tool_bar_lines_needed (f
),
9265 nlines
!= WINDOW_TOTAL_LINES (w
)))
9267 extern Lisp_Object Qtool_bar_lines
;
9269 int old_height
= WINDOW_TOTAL_LINES (w
);
9271 XSETFRAME (frame
, f
);
9272 clear_glyph_matrix (w
->desired_matrix
);
9273 Fmodify_frame_parameters (frame
,
9274 Fcons (Fcons (Qtool_bar_lines
,
9275 make_number (nlines
)),
9277 if (WINDOW_TOTAL_LINES (w
) != old_height
)
9278 fonts_changed_p
= 1;
9282 return change_height_p
;
9286 /* Get information about the tool-bar item which is displayed in GLYPH
9287 on frame F. Return in *PROP_IDX the index where tool-bar item
9288 properties start in F->tool_bar_items. Value is zero if
9289 GLYPH doesn't display a tool-bar item. */
9292 tool_bar_item_info (f
, glyph
, prop_idx
)
9294 struct glyph
*glyph
;
9301 /* This function can be called asynchronously, which means we must
9302 exclude any possibility that Fget_text_property signals an
9304 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
9305 charpos
= max (0, charpos
);
9307 /* Get the text property `menu-item' at pos. The value of that
9308 property is the start index of this item's properties in
9309 F->tool_bar_items. */
9310 prop
= Fget_text_property (make_number (charpos
),
9311 Qmenu_item
, f
->current_tool_bar_string
);
9312 if (INTEGERP (prop
))
9314 *prop_idx
= XINT (prop
);
9324 /* Get information about the tool-bar item at position X/Y on frame F.
9325 Return in *GLYPH a pointer to the glyph of the tool-bar item in
9326 the current matrix of the tool-bar window of F, or NULL if not
9327 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
9328 item in F->tool_bar_items. Value is
9330 -1 if X/Y is not on a tool-bar item
9331 0 if X/Y is on the same item that was highlighted before.
9335 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
9338 struct glyph
**glyph
;
9339 int *hpos
, *vpos
, *prop_idx
;
9341 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9342 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9345 /* Find the glyph under X/Y. */
9346 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
9350 /* Get the start of this tool-bar item's properties in
9351 f->tool_bar_items. */
9352 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
9355 /* Is mouse on the highlighted item? */
9356 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
9357 && *vpos
>= dpyinfo
->mouse_face_beg_row
9358 && *vpos
<= dpyinfo
->mouse_face_end_row
9359 && (*vpos
> dpyinfo
->mouse_face_beg_row
9360 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
9361 && (*vpos
< dpyinfo
->mouse_face_end_row
9362 || *hpos
< dpyinfo
->mouse_face_end_col
9363 || dpyinfo
->mouse_face_past_end
))
9371 Handle mouse button event on the tool-bar of frame F, at
9372 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
9373 0 for button release. MODIFIERS is event modifiers for button
9377 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
9380 unsigned int modifiers
;
9382 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9383 struct window
*w
= XWINDOW (f
->tool_bar_window
);
9384 int hpos
, vpos
, prop_idx
;
9385 struct glyph
*glyph
;
9386 Lisp_Object enabled_p
;
9388 /* If not on the highlighted tool-bar item, return. */
9389 frame_to_window_pixel_xy (w
, &x
, &y
);
9390 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
9393 /* If item is disabled, do nothing. */
9394 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9395 if (NILP (enabled_p
))
9400 /* Show item in pressed state. */
9401 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
9402 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
9403 last_tool_bar_item
= prop_idx
;
9407 Lisp_Object key
, frame
;
9408 struct input_event event
;
9411 /* Show item in released state. */
9412 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
9413 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
9415 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
9417 XSETFRAME (frame
, f
);
9418 event
.kind
= TOOL_BAR_EVENT
;
9419 event
.frame_or_window
= frame
;
9421 kbd_buffer_store_event (&event
);
9423 event
.kind
= TOOL_BAR_EVENT
;
9424 event
.frame_or_window
= frame
;
9426 event
.modifiers
= modifiers
;
9427 kbd_buffer_store_event (&event
);
9428 last_tool_bar_item
= -1;
9433 /* Possibly highlight a tool-bar item on frame F when mouse moves to
9434 tool-bar window-relative coordinates X/Y. Called from
9435 note_mouse_highlight. */
9438 note_tool_bar_highlight (f
, x
, y
)
9442 Lisp_Object window
= f
->tool_bar_window
;
9443 struct window
*w
= XWINDOW (window
);
9444 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9446 struct glyph
*glyph
;
9447 struct glyph_row
*row
;
9449 Lisp_Object enabled_p
;
9451 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
9452 int mouse_down_p
, rc
;
9454 /* Function note_mouse_highlight is called with negative x(y
9455 values when mouse moves outside of the frame. */
9456 if (x
<= 0 || y
<= 0)
9458 clear_mouse_face (dpyinfo
);
9462 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
9465 /* Not on tool-bar item. */
9466 clear_mouse_face (dpyinfo
);
9470 /* On same tool-bar item as before. */
9473 clear_mouse_face (dpyinfo
);
9475 /* Mouse is down, but on different tool-bar item? */
9476 mouse_down_p
= (dpyinfo
->grabbed
9477 && f
== last_mouse_frame
9478 && FRAME_LIVE_P (f
));
9480 && last_tool_bar_item
!= prop_idx
)
9483 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
9484 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
9486 /* If tool-bar item is not enabled, don't highlight it. */
9487 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
9488 if (!NILP (enabled_p
))
9490 /* Compute the x-position of the glyph. In front and past the
9491 image is a space. We include this in the highlighted area. */
9492 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
9493 for (i
= x
= 0; i
< hpos
; ++i
)
9494 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
9496 /* Record this as the current active region. */
9497 dpyinfo
->mouse_face_beg_col
= hpos
;
9498 dpyinfo
->mouse_face_beg_row
= vpos
;
9499 dpyinfo
->mouse_face_beg_x
= x
;
9500 dpyinfo
->mouse_face_beg_y
= row
->y
;
9501 dpyinfo
->mouse_face_past_end
= 0;
9503 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
9504 dpyinfo
->mouse_face_end_row
= vpos
;
9505 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
9506 dpyinfo
->mouse_face_end_y
= row
->y
;
9507 dpyinfo
->mouse_face_window
= window
;
9508 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
9510 /* Display it as active. */
9511 show_mouse_face (dpyinfo
, draw
);
9512 dpyinfo
->mouse_face_image_state
= draw
;
9517 /* Set help_echo_string to a help string to display for this tool-bar item.
9518 XTread_socket does the rest. */
9519 help_echo_object
= help_echo_window
= Qnil
;
9521 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
9522 if (NILP (help_echo_string
))
9523 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
9526 #endif /* HAVE_WINDOW_SYSTEM */
9530 /************************************************************************
9531 Horizontal scrolling
9532 ************************************************************************/
9534 static int hscroll_window_tree
P_ ((Lisp_Object
));
9535 static int hscroll_windows
P_ ((Lisp_Object
));
9537 /* For all leaf windows in the window tree rooted at WINDOW, set their
9538 hscroll value so that PT is (i) visible in the window, and (ii) so
9539 that it is not within a certain margin at the window's left and
9540 right border. Value is non-zero if any window's hscroll has been
9544 hscroll_window_tree (window
)
9547 int hscrolled_p
= 0;
9548 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
9549 int hscroll_step_abs
= 0;
9550 double hscroll_step_rel
= 0;
9552 if (hscroll_relative_p
)
9554 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
9555 if (hscroll_step_rel
< 0)
9557 hscroll_relative_p
= 0;
9558 hscroll_step_abs
= 0;
9561 else if (INTEGERP (Vhscroll_step
))
9563 hscroll_step_abs
= XINT (Vhscroll_step
);
9564 if (hscroll_step_abs
< 0)
9565 hscroll_step_abs
= 0;
9568 hscroll_step_abs
= 0;
9570 while (WINDOWP (window
))
9572 struct window
*w
= XWINDOW (window
);
9574 if (WINDOWP (w
->hchild
))
9575 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
9576 else if (WINDOWP (w
->vchild
))
9577 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
9578 else if (w
->cursor
.vpos
>= 0)
9581 int text_area_width
;
9582 struct glyph_row
*current_cursor_row
9583 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
9584 struct glyph_row
*desired_cursor_row
9585 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
9586 struct glyph_row
*cursor_row
9587 = (desired_cursor_row
->enabled_p
9588 ? desired_cursor_row
9589 : current_cursor_row
);
9591 text_area_width
= window_box_width (w
, TEXT_AREA
);
9593 /* Scroll when cursor is inside this scroll margin. */
9594 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
9596 if ((XFASTINT (w
->hscroll
)
9597 && w
->cursor
.x
<= h_margin
)
9598 || (cursor_row
->enabled_p
9599 && cursor_row
->truncated_on_right_p
9600 && (w
->cursor
.x
>= text_area_width
- h_margin
)))
9604 struct buffer
*saved_current_buffer
;
9608 /* Find point in a display of infinite width. */
9609 saved_current_buffer
= current_buffer
;
9610 current_buffer
= XBUFFER (w
->buffer
);
9612 if (w
== XWINDOW (selected_window
))
9613 pt
= BUF_PT (current_buffer
);
9616 pt
= marker_position (w
->pointm
);
9617 pt
= max (BEGV
, pt
);
9621 /* Move iterator to pt starting at cursor_row->start in
9622 a line with infinite width. */
9623 init_to_row_start (&it
, w
, cursor_row
);
9624 it
.last_visible_x
= INFINITY
;
9625 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
9626 current_buffer
= saved_current_buffer
;
9628 /* Position cursor in window. */
9629 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
9630 hscroll
= max (0, (it
.current_x
9631 - (ITERATOR_AT_END_OF_LINE_P (&it
)
9632 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
9633 : (text_area_width
/ 2))))
9634 / FRAME_COLUMN_WIDTH (it
.f
);
9635 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
9637 if (hscroll_relative_p
)
9638 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
9641 wanted_x
= text_area_width
9642 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9645 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9649 if (hscroll_relative_p
)
9650 wanted_x
= text_area_width
* hscroll_step_rel
9653 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
9656 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
9658 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
9660 /* Don't call Fset_window_hscroll if value hasn't
9661 changed because it will prevent redisplay
9663 if (XFASTINT (w
->hscroll
) != hscroll
)
9665 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
9666 w
->hscroll
= make_number (hscroll
);
9675 /* Value is non-zero if hscroll of any leaf window has been changed. */
9680 /* Set hscroll so that cursor is visible and not inside horizontal
9681 scroll margins for all windows in the tree rooted at WINDOW. See
9682 also hscroll_window_tree above. Value is non-zero if any window's
9683 hscroll has been changed. If it has, desired matrices on the frame
9684 of WINDOW are cleared. */
9687 hscroll_windows (window
)
9692 if (automatic_hscrolling_p
)
9694 hscrolled_p
= hscroll_window_tree (window
);
9696 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
9705 /************************************************************************
9707 ************************************************************************/
9709 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
9710 to a non-zero value. This is sometimes handy to have in a debugger
9715 /* First and last unchanged row for try_window_id. */
9717 int debug_first_unchanged_at_end_vpos
;
9718 int debug_last_unchanged_at_beg_vpos
;
9720 /* Delta vpos and y. */
9722 int debug_dvpos
, debug_dy
;
9724 /* Delta in characters and bytes for try_window_id. */
9726 int debug_delta
, debug_delta_bytes
;
9728 /* Values of window_end_pos and window_end_vpos at the end of
9731 EMACS_INT debug_end_pos
, debug_end_vpos
;
9733 /* Append a string to W->desired_matrix->method. FMT is a printf
9734 format string. A1...A9 are a supplement for a variable-length
9735 argument list. If trace_redisplay_p is non-zero also printf the
9736 resulting string to stderr. */
9739 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
9742 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
9745 char *method
= w
->desired_matrix
->method
;
9746 int len
= strlen (method
);
9747 int size
= sizeof w
->desired_matrix
->method
;
9748 int remaining
= size
- len
- 1;
9750 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
9751 if (len
&& remaining
)
9757 strncpy (method
+ len
, buffer
, remaining
);
9759 if (trace_redisplay_p
)
9760 fprintf (stderr
, "%p (%s): %s\n",
9762 ((BUFFERP (w
->buffer
)
9763 && STRINGP (XBUFFER (w
->buffer
)->name
))
9764 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
9769 #endif /* GLYPH_DEBUG */
9772 /* Value is non-zero if all changes in window W, which displays
9773 current_buffer, are in the text between START and END. START is a
9774 buffer position, END is given as a distance from Z. Used in
9775 redisplay_internal for display optimization. */
9778 text_outside_line_unchanged_p (w
, start
, end
)
9782 int unchanged_p
= 1;
9784 /* If text or overlays have changed, see where. */
9785 if (XFASTINT (w
->last_modified
) < MODIFF
9786 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
9788 /* Gap in the line? */
9789 if (GPT
< start
|| Z
- GPT
< end
)
9792 /* Changes start in front of the line, or end after it? */
9794 && (BEG_UNCHANGED
< start
- 1
9795 || END_UNCHANGED
< end
))
9798 /* If selective display, can't optimize if changes start at the
9799 beginning of the line. */
9801 && INTEGERP (current_buffer
->selective_display
)
9802 && XINT (current_buffer
->selective_display
) > 0
9803 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
9806 /* If there are overlays at the start or end of the line, these
9807 may have overlay strings with newlines in them. A change at
9808 START, for instance, may actually concern the display of such
9809 overlay strings as well, and they are displayed on different
9810 lines. So, quickly rule out this case. (For the future, it
9811 might be desirable to implement something more telling than
9812 just BEG/END_UNCHANGED.) */
9815 if (BEG
+ BEG_UNCHANGED
== start
9816 && overlay_touches_p (start
))
9818 if (END_UNCHANGED
== end
9819 && overlay_touches_p (Z
- end
))
9828 /* Do a frame update, taking possible shortcuts into account. This is
9829 the main external entry point for redisplay.
9831 If the last redisplay displayed an echo area message and that message
9832 is no longer requested, we clear the echo area or bring back the
9833 mini-buffer if that is in use. */
9838 redisplay_internal (0);
9843 overlay_arrow_string_or_property (var
)
9848 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
9851 return Voverlay_arrow_string
;
9854 /* Return 1 if there are any overlay-arrows in current_buffer. */
9856 overlay_arrow_in_current_buffer_p ()
9860 for (vlist
= Voverlay_arrow_variable_list
;
9862 vlist
= XCDR (vlist
))
9864 Lisp_Object var
= XCAR (vlist
);
9869 val
= find_symbol_value (var
);
9871 && current_buffer
== XMARKER (val
)->buffer
)
9878 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
9882 overlay_arrows_changed_p ()
9886 for (vlist
= Voverlay_arrow_variable_list
;
9888 vlist
= XCDR (vlist
))
9890 Lisp_Object var
= XCAR (vlist
);
9891 Lisp_Object val
, pstr
;
9895 val
= find_symbol_value (var
);
9898 if (! EQ (COERCE_MARKER (val
),
9899 Fget (var
, Qlast_arrow_position
))
9900 || ! (pstr
= overlay_arrow_string_or_property (var
),
9901 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
9907 /* Mark overlay arrows to be updated on next redisplay. */
9910 update_overlay_arrows (up_to_date
)
9915 for (vlist
= Voverlay_arrow_variable_list
;
9917 vlist
= XCDR (vlist
))
9919 Lisp_Object var
= XCAR (vlist
);
9926 Lisp_Object val
= find_symbol_value (var
);
9927 Fput (var
, Qlast_arrow_position
,
9928 COERCE_MARKER (val
));
9929 Fput (var
, Qlast_arrow_string
,
9930 overlay_arrow_string_or_property (var
));
9932 else if (up_to_date
< 0
9933 || !NILP (Fget (var
, Qlast_arrow_position
)))
9935 Fput (var
, Qlast_arrow_position
, Qt
);
9936 Fput (var
, Qlast_arrow_string
, Qt
);
9942 /* Return overlay arrow string to display at row.
9943 Return integer (bitmap number) for arrow bitmap in left fringe.
9944 Return nil if no overlay arrow. */
9947 overlay_arrow_at_row (it
, row
)
9949 struct glyph_row
*row
;
9953 for (vlist
= Voverlay_arrow_variable_list
;
9955 vlist
= XCDR (vlist
))
9957 Lisp_Object var
= XCAR (vlist
);
9963 val
= find_symbol_value (var
);
9966 && current_buffer
== XMARKER (val
)->buffer
9967 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
9969 if (FRAME_WINDOW_P (it
->f
)
9970 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
9972 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
9975 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
9976 return make_number (fringe_bitmap
);
9978 return make_number (-1); /* Use default arrow bitmap */
9980 return overlay_arrow_string_or_property (var
);
9987 /* Return 1 if point moved out of or into a composition. Otherwise
9988 return 0. PREV_BUF and PREV_PT are the last point buffer and
9989 position. BUF and PT are the current point buffer and position. */
9992 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
9993 struct buffer
*prev_buf
, *buf
;
10000 XSETBUFFER (buffer
, buf
);
10001 /* Check a composition at the last point if point moved within the
10003 if (prev_buf
== buf
)
10006 /* Point didn't move. */
10009 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
10010 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
10011 && COMPOSITION_VALID_P (start
, end
, prop
)
10012 && start
< prev_pt
&& end
> prev_pt
)
10013 /* The last point was within the composition. Return 1 iff
10014 point moved out of the composition. */
10015 return (pt
<= start
|| pt
>= end
);
10018 /* Check a composition at the current point. */
10019 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
10020 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
10021 && COMPOSITION_VALID_P (start
, end
, prop
)
10022 && start
< pt
&& end
> pt
);
10026 /* Reconsider the setting of B->clip_changed which is displayed
10030 reconsider_clip_changes (w
, b
)
10034 if (b
->clip_changed
10035 && !NILP (w
->window_end_valid
)
10036 && w
->current_matrix
->buffer
== b
10037 && w
->current_matrix
->zv
== BUF_ZV (b
)
10038 && w
->current_matrix
->begv
== BUF_BEGV (b
))
10039 b
->clip_changed
= 0;
10041 /* If display wasn't paused, and W is not a tool bar window, see if
10042 point has been moved into or out of a composition. In that case,
10043 we set b->clip_changed to 1 to force updating the screen. If
10044 b->clip_changed has already been set to 1, we can skip this
10046 if (!b
->clip_changed
10047 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
10051 if (w
== XWINDOW (selected_window
))
10052 pt
= BUF_PT (current_buffer
);
10054 pt
= marker_position (w
->pointm
);
10056 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
10057 || pt
!= XINT (w
->last_point
))
10058 && check_point_in_composition (w
->current_matrix
->buffer
,
10059 XINT (w
->last_point
),
10060 XBUFFER (w
->buffer
), pt
))
10061 b
->clip_changed
= 1;
10066 /* Select FRAME to forward the values of frame-local variables into C
10067 variables so that the redisplay routines can access those values
10071 select_frame_for_redisplay (frame
)
10074 Lisp_Object tail
, sym
, val
;
10075 Lisp_Object old
= selected_frame
;
10077 selected_frame
= frame
;
10079 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10080 if (CONSP (XCAR (tail
))
10081 && (sym
= XCAR (XCAR (tail
)),
10083 && (sym
= indirect_variable (sym
),
10084 val
= SYMBOL_VALUE (sym
),
10085 (BUFFER_LOCAL_VALUEP (val
)
10086 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10087 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10088 Fsymbol_value (sym
);
10090 for (tail
= XFRAME (old
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
10091 if (CONSP (XCAR (tail
))
10092 && (sym
= XCAR (XCAR (tail
)),
10094 && (sym
= indirect_variable (sym
),
10095 val
= SYMBOL_VALUE (sym
),
10096 (BUFFER_LOCAL_VALUEP (val
)
10097 || SOME_BUFFER_LOCAL_VALUEP (val
)))
10098 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
10099 Fsymbol_value (sym
);
10103 #define STOP_POLLING \
10104 do { if (! polling_stopped_here) stop_polling (); \
10105 polling_stopped_here = 1; } while (0)
10107 #define RESUME_POLLING \
10108 do { if (polling_stopped_here) start_polling (); \
10109 polling_stopped_here = 0; } while (0)
10112 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
10113 response to any user action; therefore, we should preserve the echo
10114 area. (Actually, our caller does that job.) Perhaps in the future
10115 avoid recentering windows if it is not necessary; currently that
10116 causes some problems. */
10119 redisplay_internal (preserve_echo_area
)
10120 int preserve_echo_area
;
10122 struct window
*w
= XWINDOW (selected_window
);
10123 struct frame
*f
= XFRAME (w
->frame
);
10125 int must_finish
= 0;
10126 struct text_pos tlbufpos
, tlendpos
;
10127 int number_of_visible_frames
;
10129 struct frame
*sf
= SELECTED_FRAME ();
10130 int polling_stopped_here
= 0;
10132 /* Non-zero means redisplay has to consider all windows on all
10133 frames. Zero means, only selected_window is considered. */
10134 int consider_all_windows_p
;
10136 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
10138 /* No redisplay if running in batch mode or frame is not yet fully
10139 initialized, or redisplay is explicitly turned off by setting
10140 Vinhibit_redisplay. */
10142 || !NILP (Vinhibit_redisplay
)
10143 || !f
->glyphs_initialized_p
)
10146 /* The flag redisplay_performed_directly_p is set by
10147 direct_output_for_insert when it already did the whole screen
10148 update necessary. */
10149 if (redisplay_performed_directly_p
)
10151 redisplay_performed_directly_p
= 0;
10152 if (!hscroll_windows (selected_window
))
10156 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
10157 if (popup_activated ())
10161 /* I don't think this happens but let's be paranoid. */
10162 if (redisplaying_p
)
10165 /* Record a function that resets redisplaying_p to its old value
10166 when we leave this function. */
10167 count
= SPECPDL_INDEX ();
10168 record_unwind_protect (unwind_redisplay
,
10169 Fcons (make_number (redisplaying_p
), selected_frame
));
10171 specbind (Qinhibit_free_realized_faces
, Qnil
);
10175 reconsider_clip_changes (w
, current_buffer
);
10177 /* If new fonts have been loaded that make a glyph matrix adjustment
10178 necessary, do it. */
10179 if (fonts_changed_p
)
10181 adjust_glyphs (NULL
);
10182 ++windows_or_buffers_changed
;
10183 fonts_changed_p
= 0;
10186 /* If face_change_count is non-zero, init_iterator will free all
10187 realized faces, which includes the faces referenced from current
10188 matrices. So, we can't reuse current matrices in this case. */
10189 if (face_change_count
)
10190 ++windows_or_buffers_changed
;
10192 if (! FRAME_WINDOW_P (sf
)
10193 && previous_terminal_frame
!= sf
)
10195 /* Since frames on an ASCII terminal share the same display
10196 area, displaying a different frame means redisplay the whole
10198 windows_or_buffers_changed
++;
10199 SET_FRAME_GARBAGED (sf
);
10200 XSETFRAME (Vterminal_frame
, sf
);
10202 previous_terminal_frame
= sf
;
10204 /* Set the visible flags for all frames. Do this before checking
10205 for resized or garbaged frames; they want to know if their frames
10206 are visible. See the comment in frame.h for
10207 FRAME_SAMPLE_VISIBILITY. */
10209 Lisp_Object tail
, frame
;
10211 number_of_visible_frames
= 0;
10213 FOR_EACH_FRAME (tail
, frame
)
10215 struct frame
*f
= XFRAME (frame
);
10217 FRAME_SAMPLE_VISIBILITY (f
);
10218 if (FRAME_VISIBLE_P (f
))
10219 ++number_of_visible_frames
;
10220 clear_desired_matrices (f
);
10224 /* Notice any pending interrupt request to change frame size. */
10225 do_pending_window_change (1);
10227 /* Clear frames marked as garbaged. */
10228 if (frame_garbaged
)
10229 clear_garbaged_frames ();
10231 /* Build menubar and tool-bar items. */
10232 prepare_menu_bars ();
10234 if (windows_or_buffers_changed
)
10235 update_mode_lines
++;
10237 /* Detect case that we need to write or remove a star in the mode line. */
10238 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
10240 w
->update_mode_line
= Qt
;
10241 if (buffer_shared
> 1)
10242 update_mode_lines
++;
10245 /* If %c is in the mode line, update it if needed. */
10246 if (!NILP (w
->column_number_displayed
)
10247 /* This alternative quickly identifies a common case
10248 where no change is needed. */
10249 && !(PT
== XFASTINT (w
->last_point
)
10250 && XFASTINT (w
->last_modified
) >= MODIFF
10251 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
10252 && (XFASTINT (w
->column_number_displayed
)
10253 != (int) current_column ())) /* iftc */
10254 w
->update_mode_line
= Qt
;
10256 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
10258 /* The variable buffer_shared is set in redisplay_window and
10259 indicates that we redisplay a buffer in different windows. See
10261 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
10262 || cursor_type_changed
);
10264 /* If specs for an arrow have changed, do thorough redisplay
10265 to ensure we remove any arrow that should no longer exist. */
10266 if (overlay_arrows_changed_p ())
10267 consider_all_windows_p
= windows_or_buffers_changed
= 1;
10269 /* Normally the message* functions will have already displayed and
10270 updated the echo area, but the frame may have been trashed, or
10271 the update may have been preempted, so display the echo area
10272 again here. Checking message_cleared_p captures the case that
10273 the echo area should be cleared. */
10274 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
10275 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
10276 || (message_cleared_p
10277 && minibuf_level
== 0
10278 /* If the mini-window is currently selected, this means the
10279 echo-area doesn't show through. */
10280 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
10282 int window_height_changed_p
= echo_area_display (0);
10285 /* If we don't display the current message, don't clear the
10286 message_cleared_p flag, because, if we did, we wouldn't clear
10287 the echo area in the next redisplay which doesn't preserve
10289 if (!display_last_displayed_message_p
)
10290 message_cleared_p
= 0;
10292 if (fonts_changed_p
)
10294 else if (window_height_changed_p
)
10296 consider_all_windows_p
= 1;
10297 ++update_mode_lines
;
10298 ++windows_or_buffers_changed
;
10300 /* If window configuration was changed, frames may have been
10301 marked garbaged. Clear them or we will experience
10302 surprises wrt scrolling. */
10303 if (frame_garbaged
)
10304 clear_garbaged_frames ();
10307 else if (EQ (selected_window
, minibuf_window
)
10308 && (current_buffer
->clip_changed
10309 || XFASTINT (w
->last_modified
) < MODIFF
10310 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10311 && resize_mini_window (w
, 0))
10313 /* Resized active mini-window to fit the size of what it is
10314 showing if its contents might have changed. */
10316 consider_all_windows_p
= 1;
10317 ++windows_or_buffers_changed
;
10318 ++update_mode_lines
;
10320 /* If window configuration was changed, frames may have been
10321 marked garbaged. Clear them or we will experience
10322 surprises wrt scrolling. */
10323 if (frame_garbaged
)
10324 clear_garbaged_frames ();
10328 /* If showing the region, and mark has changed, we must redisplay
10329 the whole window. The assignment to this_line_start_pos prevents
10330 the optimization directly below this if-statement. */
10331 if (((!NILP (Vtransient_mark_mode
)
10332 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10333 != !NILP (w
->region_showing
))
10334 || (!NILP (w
->region_showing
)
10335 && !EQ (w
->region_showing
,
10336 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
10337 CHARPOS (this_line_start_pos
) = 0;
10339 /* Optimize the case that only the line containing the cursor in the
10340 selected window has changed. Variables starting with this_ are
10341 set in display_line and record information about the line
10342 containing the cursor. */
10343 tlbufpos
= this_line_start_pos
;
10344 tlendpos
= this_line_end_pos
;
10345 if (!consider_all_windows_p
10346 && CHARPOS (tlbufpos
) > 0
10347 && NILP (w
->update_mode_line
)
10348 && !current_buffer
->clip_changed
10349 && !current_buffer
->prevent_redisplay_optimizations_p
10350 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
10351 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
10352 /* Make sure recorded data applies to current buffer, etc. */
10353 && this_line_buffer
== current_buffer
10354 && current_buffer
== XBUFFER (w
->buffer
)
10355 && NILP (w
->force_start
)
10356 && NILP (w
->optional_new_start
)
10357 /* Point must be on the line that we have info recorded about. */
10358 && PT
>= CHARPOS (tlbufpos
)
10359 && PT
<= Z
- CHARPOS (tlendpos
)
10360 /* All text outside that line, including its final newline,
10361 must be unchanged */
10362 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
10363 CHARPOS (tlendpos
)))
10365 if (CHARPOS (tlbufpos
) > BEGV
10366 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
10367 && (CHARPOS (tlbufpos
) == ZV
10368 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
10369 /* Former continuation line has disappeared by becoming empty */
10371 else if (XFASTINT (w
->last_modified
) < MODIFF
10372 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
10373 || MINI_WINDOW_P (w
))
10375 /* We have to handle the case of continuation around a
10376 wide-column character (See the comment in indent.c around
10379 For instance, in the following case:
10381 -------- Insert --------
10382 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
10383 J_I_ ==> J_I_ `^^' are cursors.
10387 As we have to redraw the line above, we should goto cancel. */
10390 int line_height_before
= this_line_pixel_height
;
10392 /* Note that start_display will handle the case that the
10393 line starting at tlbufpos is a continuation lines. */
10394 start_display (&it
, w
, tlbufpos
);
10396 /* Implementation note: It this still necessary? */
10397 if (it
.current_x
!= this_line_start_x
)
10400 TRACE ((stderr
, "trying display optimization 1\n"));
10401 w
->cursor
.vpos
= -1;
10402 overlay_arrow_seen
= 0;
10403 it
.vpos
= this_line_vpos
;
10404 it
.current_y
= this_line_y
;
10405 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
10406 display_line (&it
);
10408 /* If line contains point, is not continued,
10409 and ends at same distance from eob as before, we win */
10410 if (w
->cursor
.vpos
>= 0
10411 /* Line is not continued, otherwise this_line_start_pos
10412 would have been set to 0 in display_line. */
10413 && CHARPOS (this_line_start_pos
)
10414 /* Line ends as before. */
10415 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
10416 /* Line has same height as before. Otherwise other lines
10417 would have to be shifted up or down. */
10418 && this_line_pixel_height
== line_height_before
)
10420 /* If this is not the window's last line, we must adjust
10421 the charstarts of the lines below. */
10422 if (it
.current_y
< it
.last_visible_y
)
10424 struct glyph_row
*row
10425 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
10426 int delta
, delta_bytes
;
10428 if (Z
- CHARPOS (tlendpos
) == ZV
)
10430 /* This line ends at end of (accessible part of)
10431 buffer. There is no newline to count. */
10433 - CHARPOS (tlendpos
)
10434 - MATRIX_ROW_START_CHARPOS (row
));
10435 delta_bytes
= (Z_BYTE
10436 - BYTEPOS (tlendpos
)
10437 - MATRIX_ROW_START_BYTEPOS (row
));
10441 /* This line ends in a newline. Must take
10442 account of the newline and the rest of the
10443 text that follows. */
10445 - CHARPOS (tlendpos
)
10446 - MATRIX_ROW_START_CHARPOS (row
));
10447 delta_bytes
= (Z_BYTE
10448 - BYTEPOS (tlendpos
)
10449 - MATRIX_ROW_START_BYTEPOS (row
));
10452 increment_matrix_positions (w
->current_matrix
,
10453 this_line_vpos
+ 1,
10454 w
->current_matrix
->nrows
,
10455 delta
, delta_bytes
);
10458 /* If this row displays text now but previously didn't,
10459 or vice versa, w->window_end_vpos may have to be
10461 if ((it
.glyph_row
- 1)->displays_text_p
)
10463 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
10464 XSETINT (w
->window_end_vpos
, this_line_vpos
);
10466 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
10467 && this_line_vpos
> 0)
10468 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
10469 w
->window_end_valid
= Qnil
;
10471 /* Update hint: No need to try to scroll in update_window. */
10472 w
->desired_matrix
->no_scrolling_p
= 1;
10475 *w
->desired_matrix
->method
= 0;
10476 debug_method_add (w
, "optimization 1");
10478 #ifdef HAVE_WINDOW_SYSTEM
10479 update_window_fringes (w
, 0);
10486 else if (/* Cursor position hasn't changed. */
10487 PT
== XFASTINT (w
->last_point
)
10488 /* Make sure the cursor was last displayed
10489 in this window. Otherwise we have to reposition it. */
10490 && 0 <= w
->cursor
.vpos
10491 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
10495 do_pending_window_change (1);
10497 /* We used to always goto end_of_redisplay here, but this
10498 isn't enough if we have a blinking cursor. */
10499 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
10500 goto end_of_redisplay
;
10504 /* If highlighting the region, or if the cursor is in the echo area,
10505 then we can't just move the cursor. */
10506 else if (! (!NILP (Vtransient_mark_mode
)
10507 && !NILP (current_buffer
->mark_active
))
10508 && (EQ (selected_window
, current_buffer
->last_selected_window
)
10509 || highlight_nonselected_windows
)
10510 && NILP (w
->region_showing
)
10511 && NILP (Vshow_trailing_whitespace
)
10512 && !cursor_in_echo_area
)
10515 struct glyph_row
*row
;
10517 /* Skip from tlbufpos to PT and see where it is. Note that
10518 PT may be in invisible text. If so, we will end at the
10519 next visible position. */
10520 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
10521 NULL
, DEFAULT_FACE_ID
);
10522 it
.current_x
= this_line_start_x
;
10523 it
.current_y
= this_line_y
;
10524 it
.vpos
= this_line_vpos
;
10526 /* The call to move_it_to stops in front of PT, but
10527 moves over before-strings. */
10528 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
10530 if (it
.vpos
== this_line_vpos
10531 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
10534 xassert (this_line_vpos
== it
.vpos
);
10535 xassert (this_line_y
== it
.current_y
);
10536 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10538 *w
->desired_matrix
->method
= 0;
10539 debug_method_add (w
, "optimization 3");
10548 /* Text changed drastically or point moved off of line. */
10549 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
10552 CHARPOS (this_line_start_pos
) = 0;
10553 consider_all_windows_p
|= buffer_shared
> 1;
10554 ++clear_face_cache_count
;
10555 #ifdef HAVE_WINDOW_SYSTEM
10556 ++clear_image_cache_count
;
10559 /* Build desired matrices, and update the display. If
10560 consider_all_windows_p is non-zero, do it for all windows on all
10561 frames. Otherwise do it for selected_window, only. */
10563 if (consider_all_windows_p
)
10565 Lisp_Object tail
, frame
;
10566 int i
, n
= 0, size
= 50;
10567 struct frame
**updated
10568 = (struct frame
**) alloca (size
* sizeof *updated
);
10570 /* Recompute # windows showing selected buffer. This will be
10571 incremented each time such a window is displayed. */
10574 FOR_EACH_FRAME (tail
, frame
)
10576 struct frame
*f
= XFRAME (frame
);
10578 if (FRAME_WINDOW_P (f
) || f
== sf
)
10580 if (! EQ (frame
, selected_frame
))
10581 /* Select the frame, for the sake of frame-local
10583 select_frame_for_redisplay (frame
);
10585 /* Mark all the scroll bars to be removed; we'll redeem
10586 the ones we want when we redisplay their windows. */
10587 if (condemn_scroll_bars_hook
)
10588 condemn_scroll_bars_hook (f
);
10590 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10591 redisplay_windows (FRAME_ROOT_WINDOW (f
));
10593 /* Any scroll bars which redisplay_windows should have
10594 nuked should now go away. */
10595 if (judge_scroll_bars_hook
)
10596 judge_scroll_bars_hook (f
);
10598 /* If fonts changed, display again. */
10599 /* ??? rms: I suspect it is a mistake to jump all the way
10600 back to retry here. It should just retry this frame. */
10601 if (fonts_changed_p
)
10604 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
10606 /* See if we have to hscroll. */
10607 if (hscroll_windows (f
->root_window
))
10610 /* Prevent various kinds of signals during display
10611 update. stdio is not robust about handling
10612 signals, which can cause an apparent I/O
10614 if (interrupt_input
)
10615 unrequest_sigio ();
10618 /* Update the display. */
10619 set_window_update_flags (XWINDOW (f
->root_window
), 1);
10620 pause
|= update_frame (f
, 0, 0);
10621 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
10628 int nbytes
= size
* sizeof *updated
;
10629 struct frame
**p
= (struct frame
**) alloca (2 * nbytes
);
10630 bcopy (updated
, p
, nbytes
);
10641 /* Do the mark_window_display_accurate after all windows have
10642 been redisplayed because this call resets flags in buffers
10643 which are needed for proper redisplay. */
10644 for (i
= 0; i
< n
; ++i
)
10646 struct frame
*f
= updated
[i
];
10647 mark_window_display_accurate (f
->root_window
, 1);
10648 if (frame_up_to_date_hook
)
10649 frame_up_to_date_hook (f
);
10653 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10655 Lisp_Object mini_window
;
10656 struct frame
*mini_frame
;
10658 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
10659 /* Use list_of_error, not Qerror, so that
10660 we catch only errors and don't run the debugger. */
10661 internal_condition_case_1 (redisplay_window_1
, selected_window
,
10663 redisplay_window_error
);
10665 /* Compare desired and current matrices, perform output. */
10668 /* If fonts changed, display again. */
10669 if (fonts_changed_p
)
10672 /* Prevent various kinds of signals during display update.
10673 stdio is not robust about handling signals,
10674 which can cause an apparent I/O error. */
10675 if (interrupt_input
)
10676 unrequest_sigio ();
10679 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
10681 if (hscroll_windows (selected_window
))
10684 XWINDOW (selected_window
)->must_be_updated_p
= 1;
10685 pause
= update_frame (sf
, 0, 0);
10688 /* We may have called echo_area_display at the top of this
10689 function. If the echo area is on another frame, that may
10690 have put text on a frame other than the selected one, so the
10691 above call to update_frame would not have caught it. Catch
10693 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10694 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10696 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
10698 XWINDOW (mini_window
)->must_be_updated_p
= 1;
10699 pause
|= update_frame (mini_frame
, 0, 0);
10700 if (!pause
&& hscroll_windows (mini_window
))
10705 /* If display was paused because of pending input, make sure we do a
10706 thorough update the next time. */
10709 /* Prevent the optimization at the beginning of
10710 redisplay_internal that tries a single-line update of the
10711 line containing the cursor in the selected window. */
10712 CHARPOS (this_line_start_pos
) = 0;
10714 /* Let the overlay arrow be updated the next time. */
10715 update_overlay_arrows (0);
10717 /* If we pause after scrolling, some rows in the current
10718 matrices of some windows are not valid. */
10719 if (!WINDOW_FULL_WIDTH_P (w
)
10720 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
10721 update_mode_lines
= 1;
10725 if (!consider_all_windows_p
)
10727 /* This has already been done above if
10728 consider_all_windows_p is set. */
10729 mark_window_display_accurate_1 (w
, 1);
10731 /* Say overlay arrows are up to date. */
10732 update_overlay_arrows (1);
10734 if (frame_up_to_date_hook
!= 0)
10735 frame_up_to_date_hook (sf
);
10738 update_mode_lines
= 0;
10739 windows_or_buffers_changed
= 0;
10740 cursor_type_changed
= 0;
10743 /* Start SIGIO interrupts coming again. Having them off during the
10744 code above makes it less likely one will discard output, but not
10745 impossible, since there might be stuff in the system buffer here.
10746 But it is much hairier to try to do anything about that. */
10747 if (interrupt_input
)
10751 /* If a frame has become visible which was not before, redisplay
10752 again, so that we display it. Expose events for such a frame
10753 (which it gets when becoming visible) don't call the parts of
10754 redisplay constructing glyphs, so simply exposing a frame won't
10755 display anything in this case. So, we have to display these
10756 frames here explicitly. */
10759 Lisp_Object tail
, frame
;
10762 FOR_EACH_FRAME (tail
, frame
)
10764 int this_is_visible
= 0;
10766 if (XFRAME (frame
)->visible
)
10767 this_is_visible
= 1;
10768 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
10769 if (XFRAME (frame
)->visible
)
10770 this_is_visible
= 1;
10772 if (this_is_visible
)
10776 if (new_count
!= number_of_visible_frames
)
10777 windows_or_buffers_changed
++;
10780 /* Change frame size now if a change is pending. */
10781 do_pending_window_change (1);
10783 /* If we just did a pending size change, or have additional
10784 visible frames, redisplay again. */
10785 if (windows_or_buffers_changed
&& !pause
)
10788 /* Clear the face cache eventually. */
10789 if (consider_all_windows_p
)
10791 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
10793 clear_face_cache (0);
10794 clear_face_cache_count
= 0;
10796 #ifdef HAVE_WINDOW_SYSTEM
10797 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
10799 Lisp_Object tail
, frame
;
10800 FOR_EACH_FRAME (tail
, frame
)
10802 struct frame
*f
= XFRAME (frame
);
10803 if (FRAME_WINDOW_P (f
))
10804 clear_image_cache (f
, 0);
10806 clear_image_cache_count
= 0;
10808 #endif /* HAVE_WINDOW_SYSTEM */
10812 unbind_to (count
, Qnil
);
10817 /* Redisplay, but leave alone any recent echo area message unless
10818 another message has been requested in its place.
10820 This is useful in situations where you need to redisplay but no
10821 user action has occurred, making it inappropriate for the message
10822 area to be cleared. See tracking_off and
10823 wait_reading_process_output for examples of these situations.
10825 FROM_WHERE is an integer saying from where this function was
10826 called. This is useful for debugging. */
10829 redisplay_preserve_echo_area (from_where
)
10832 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
10834 if (!NILP (echo_area_buffer
[1]))
10836 /* We have a previously displayed message, but no current
10837 message. Redisplay the previous message. */
10838 display_last_displayed_message_p
= 1;
10839 redisplay_internal (1);
10840 display_last_displayed_message_p
= 0;
10843 redisplay_internal (1);
10845 if (rif
!= NULL
&& rif
->flush_display_optional
)
10846 rif
->flush_display_optional (NULL
);
10850 /* Function registered with record_unwind_protect in
10851 redisplay_internal. Reset redisplaying_p to the value it had
10852 before redisplay_internal was called, and clear
10853 prevent_freeing_realized_faces_p. It also selects the previously
10857 unwind_redisplay (val
)
10860 Lisp_Object old_redisplaying_p
, old_frame
;
10862 old_redisplaying_p
= XCAR (val
);
10863 redisplaying_p
= XFASTINT (old_redisplaying_p
);
10864 old_frame
= XCDR (val
);
10865 if (! EQ (old_frame
, selected_frame
))
10866 select_frame_for_redisplay (old_frame
);
10871 /* Mark the display of window W as accurate or inaccurate. If
10872 ACCURATE_P is non-zero mark display of W as accurate. If
10873 ACCURATE_P is zero, arrange for W to be redisplayed the next time
10874 redisplay_internal is called. */
10877 mark_window_display_accurate_1 (w
, accurate_p
)
10881 if (BUFFERP (w
->buffer
))
10883 struct buffer
*b
= XBUFFER (w
->buffer
);
10886 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
10887 w
->last_overlay_modified
10888 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
10890 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
10894 b
->clip_changed
= 0;
10895 b
->prevent_redisplay_optimizations_p
= 0;
10897 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
10898 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
10899 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
10900 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
10902 w
->current_matrix
->buffer
= b
;
10903 w
->current_matrix
->begv
= BUF_BEGV (b
);
10904 w
->current_matrix
->zv
= BUF_ZV (b
);
10906 w
->last_cursor
= w
->cursor
;
10907 w
->last_cursor_off_p
= w
->cursor_off_p
;
10909 if (w
== XWINDOW (selected_window
))
10910 w
->last_point
= make_number (BUF_PT (b
));
10912 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
10918 w
->window_end_valid
= w
->buffer
;
10919 #if 0 /* This is incorrect with variable-height lines. */
10920 xassert (XINT (w
->window_end_vpos
)
10921 < (WINDOW_TOTAL_LINES (w
)
10922 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
10924 w
->update_mode_line
= Qnil
;
10929 /* Mark the display of windows in the window tree rooted at WINDOW as
10930 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
10931 windows as accurate. If ACCURATE_P is zero, arrange for windows to
10932 be redisplayed the next time redisplay_internal is called. */
10935 mark_window_display_accurate (window
, accurate_p
)
10936 Lisp_Object window
;
10941 for (; !NILP (window
); window
= w
->next
)
10943 w
= XWINDOW (window
);
10944 mark_window_display_accurate_1 (w
, accurate_p
);
10946 if (!NILP (w
->vchild
))
10947 mark_window_display_accurate (w
->vchild
, accurate_p
);
10948 if (!NILP (w
->hchild
))
10949 mark_window_display_accurate (w
->hchild
, accurate_p
);
10954 update_overlay_arrows (1);
10958 /* Force a thorough redisplay the next time by setting
10959 last_arrow_position and last_arrow_string to t, which is
10960 unequal to any useful value of Voverlay_arrow_... */
10961 update_overlay_arrows (-1);
10966 /* Return value in display table DP (Lisp_Char_Table *) for character
10967 C. Since a display table doesn't have any parent, we don't have to
10968 follow parent. Do not call this function directly but use the
10969 macro DISP_CHAR_VECTOR. */
10972 disp_char_vector (dp
, c
)
10973 struct Lisp_Char_Table
*dp
;
10979 if (SINGLE_BYTE_CHAR_P (c
))
10980 return (dp
->contents
[c
]);
10982 SPLIT_CHAR (c
, code
[0], code
[1], code
[2]);
10985 else if (code
[2] < 32)
10988 /* Here, the possible range of code[0] (== charset ID) is
10989 128..max_charset. Since the top level char table contains data
10990 for multibyte characters after 256th element, we must increment
10991 code[0] by 128 to get a correct index. */
10993 code
[3] = -1; /* anchor */
10995 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
10997 val
= dp
->contents
[code
[i
]];
10998 if (!SUB_CHAR_TABLE_P (val
))
10999 return (NILP (val
) ? dp
->defalt
: val
);
11002 /* Here, val is a sub char table. We return the default value of
11004 return (dp
->defalt
);
11009 /***********************************************************************
11011 ***********************************************************************/
11013 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
11016 redisplay_windows (window
)
11017 Lisp_Object window
;
11019 while (!NILP (window
))
11021 struct window
*w
= XWINDOW (window
);
11023 if (!NILP (w
->hchild
))
11024 redisplay_windows (w
->hchild
);
11025 else if (!NILP (w
->vchild
))
11026 redisplay_windows (w
->vchild
);
11029 displayed_buffer
= XBUFFER (w
->buffer
);
11030 /* Use list_of_error, not Qerror, so that
11031 we catch only errors and don't run the debugger. */
11032 internal_condition_case_1 (redisplay_window_0
, window
,
11034 redisplay_window_error
);
11042 redisplay_window_error ()
11044 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
11049 redisplay_window_0 (window
)
11050 Lisp_Object window
;
11052 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11053 redisplay_window (window
, 0);
11058 redisplay_window_1 (window
)
11059 Lisp_Object window
;
11061 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
11062 redisplay_window (window
, 1);
11067 /* Increment GLYPH until it reaches END or CONDITION fails while
11068 adding (GLYPH)->pixel_width to X. */
11070 #define SKIP_GLYPHS(glyph, end, x, condition) \
11073 (x) += (glyph)->pixel_width; \
11076 while ((glyph) < (end) && (condition))
11079 /* Set cursor position of W. PT is assumed to be displayed in ROW.
11080 DELTA is the number of bytes by which positions recorded in ROW
11081 differ from current buffer positions. */
11084 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
11086 struct glyph_row
*row
;
11087 struct glyph_matrix
*matrix
;
11088 int delta
, delta_bytes
, dy
, dvpos
;
11090 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
11091 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
11092 struct glyph
*cursor
= NULL
;
11093 /* The first glyph that starts a sequence of glyphs from string. */
11094 struct glyph
*string_start
;
11095 /* The X coordinate of string_start. */
11096 int string_start_x
;
11097 /* The last known character position. */
11098 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
11099 /* The last known character position before string_start. */
11100 int string_before_pos
;
11103 int cursor_from_overlay_pos
= 0;
11104 int pt_old
= PT
- delta
;
11106 /* Skip over glyphs not having an object at the start of the row.
11107 These are special glyphs like truncation marks on terminal
11109 if (row
->displays_text_p
)
11111 && INTEGERP (glyph
->object
)
11112 && glyph
->charpos
< 0)
11114 x
+= glyph
->pixel_width
;
11118 string_start
= NULL
;
11120 && !INTEGERP (glyph
->object
)
11121 && (!BUFFERP (glyph
->object
)
11122 || (last_pos
= glyph
->charpos
) < pt_old
))
11124 if (! STRINGP (glyph
->object
))
11126 string_start
= NULL
;
11127 x
+= glyph
->pixel_width
;
11129 if (cursor_from_overlay_pos
11130 && last_pos
> cursor_from_overlay_pos
)
11132 cursor_from_overlay_pos
= 0;
11138 string_before_pos
= last_pos
;
11139 string_start
= glyph
;
11140 string_start_x
= x
;
11141 /* Skip all glyphs from string. */
11145 if ((cursor
== NULL
|| glyph
> cursor
)
11146 && !NILP (Fget_char_property (make_number ((glyph
)->charpos
),
11147 Qcursor
, (glyph
)->object
))
11148 && (pos
= string_buffer_position (w
, glyph
->object
,
11149 string_before_pos
),
11150 (pos
== 0 /* From overlay */
11151 || pos
== pt_old
)))
11153 /* Estimate overlay buffer position from the buffer
11154 positions of the glyphs before and after the overlay.
11155 Add 1 to last_pos so that if point corresponds to the
11156 glyph right after the overlay, we still use a 'cursor'
11157 property found in that overlay. */
11158 cursor_from_overlay_pos
= pos
== 0 ? last_pos
+1 : 0;
11162 x
+= glyph
->pixel_width
;
11165 while (glyph
< end
&& STRINGP (glyph
->object
));
11169 if (cursor
!= NULL
)
11174 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
11176 /* Scan back over the ellipsis glyphs, decrementing positions. */
11177 while (glyph
> row
->glyphs
[TEXT_AREA
]
11178 && (glyph
- 1)->charpos
== last_pos
)
11179 glyph
--, x
-= glyph
->pixel_width
;
11180 /* That loop always goes one position too far,
11181 including the glyph before the ellipsis.
11182 So scan forward over that one. */
11183 x
+= glyph
->pixel_width
;
11186 else if (string_start
11187 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
11189 /* We may have skipped over point because the previous glyphs
11190 are from string. As there's no easy way to know the
11191 character position of the current glyph, find the correct
11192 glyph on point by scanning from string_start again. */
11194 Lisp_Object string
;
11197 limit
= make_number (pt_old
+ 1);
11199 glyph
= string_start
;
11200 x
= string_start_x
;
11201 string
= glyph
->object
;
11202 pos
= string_buffer_position (w
, string
, string_before_pos
);
11203 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
11204 because we always put cursor after overlay strings. */
11205 while (pos
== 0 && glyph
< end
)
11207 string
= glyph
->object
;
11208 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11210 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
11213 while (glyph
< end
)
11215 pos
= XINT (Fnext_single_char_property_change
11216 (make_number (pos
), Qdisplay
, Qnil
, limit
));
11219 /* Skip glyphs from the same string. */
11220 string
= glyph
->object
;
11221 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11222 /* Skip glyphs from an overlay. */
11224 && ! string_buffer_position (w
, glyph
->object
, pos
))
11226 string
= glyph
->object
;
11227 SKIP_GLYPHS (glyph
, end
, x
, EQ (glyph
->object
, string
));
11232 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
11234 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
11235 w
->cursor
.y
= row
->y
+ dy
;
11237 if (w
== XWINDOW (selected_window
))
11239 if (!row
->continued_p
11240 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
11243 this_line_buffer
= XBUFFER (w
->buffer
);
11245 CHARPOS (this_line_start_pos
)
11246 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
11247 BYTEPOS (this_line_start_pos
)
11248 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
11250 CHARPOS (this_line_end_pos
)
11251 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
11252 BYTEPOS (this_line_end_pos
)
11253 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
11255 this_line_y
= w
->cursor
.y
;
11256 this_line_pixel_height
= row
->height
;
11257 this_line_vpos
= w
->cursor
.vpos
;
11258 this_line_start_x
= row
->x
;
11261 CHARPOS (this_line_start_pos
) = 0;
11266 /* Run window scroll functions, if any, for WINDOW with new window
11267 start STARTP. Sets the window start of WINDOW to that position.
11269 We assume that the window's buffer is really current. */
11271 static INLINE
struct text_pos
11272 run_window_scroll_functions (window
, startp
)
11273 Lisp_Object window
;
11274 struct text_pos startp
;
11276 struct window
*w
= XWINDOW (window
);
11277 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
11279 if (current_buffer
!= XBUFFER (w
->buffer
))
11282 if (!NILP (Vwindow_scroll_functions
))
11284 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
11285 make_number (CHARPOS (startp
)));
11286 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11287 /* In case the hook functions switch buffers. */
11288 if (current_buffer
!= XBUFFER (w
->buffer
))
11289 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11296 /* Make sure the line containing the cursor is fully visible.
11297 A value of 1 means there is nothing to be done.
11298 (Either the line is fully visible, or it cannot be made so,
11299 or we cannot tell.)
11301 If FORCE_P is non-zero, return 0 even if partial visible cursor row
11302 is higher than window.
11304 A value of 0 means the caller should do scrolling
11305 as if point had gone off the screen. */
11308 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
11312 struct glyph_matrix
*matrix
;
11313 struct glyph_row
*row
;
11316 if (!make_cursor_line_fully_visible_p
)
11319 /* It's not always possible to find the cursor, e.g, when a window
11320 is full of overlay strings. Don't do anything in that case. */
11321 if (w
->cursor
.vpos
< 0)
11324 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
11325 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
11327 /* If the cursor row is not partially visible, there's nothing to do. */
11328 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
11331 /* If the row the cursor is in is taller than the window's height,
11332 it's not clear what to do, so do nothing. */
11333 window_height
= window_box_height (w
);
11334 if (row
->height
>= window_height
)
11336 if (!force_p
|| MINI_WINDOW_P (w
) || w
->vscroll
)
11342 /* This code used to try to scroll the window just enough to make
11343 the line visible. It returned 0 to say that the caller should
11344 allocate larger glyph matrices. */
11346 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
11348 int dy
= row
->height
- row
->visible_height
;
11351 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11353 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
11355 int dy
= - (row
->height
- row
->visible_height
);
11358 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
11361 /* When we change the cursor y-position of the selected window,
11362 change this_line_y as well so that the display optimization for
11363 the cursor line of the selected window in redisplay_internal uses
11364 the correct y-position. */
11365 if (w
== XWINDOW (selected_window
))
11366 this_line_y
= w
->cursor
.y
;
11368 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
11369 redisplay with larger matrices. */
11370 if (matrix
->nrows
< required_matrix_height (w
))
11372 fonts_changed_p
= 1;
11381 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
11382 non-zero means only WINDOW is redisplayed in redisplay_internal.
11383 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
11384 in redisplay_window to bring a partially visible line into view in
11385 the case that only the cursor has moved.
11387 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
11388 last screen line's vertical height extends past the end of the screen.
11392 1 if scrolling succeeded
11394 0 if scrolling didn't find point.
11396 -1 if new fonts have been loaded so that we must interrupt
11397 redisplay, adjust glyph matrices, and try again. */
11403 SCROLLING_NEED_LARGER_MATRICES
11407 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
11408 scroll_step
, temp_scroll_step
, last_line_misfit
)
11409 Lisp_Object window
;
11410 int just_this_one_p
;
11411 EMACS_INT scroll_conservatively
, scroll_step
;
11412 int temp_scroll_step
;
11413 int last_line_misfit
;
11415 struct window
*w
= XWINDOW (window
);
11416 struct frame
*f
= XFRAME (w
->frame
);
11417 struct text_pos scroll_margin_pos
;
11418 struct text_pos pos
;
11419 struct text_pos startp
;
11421 Lisp_Object window_end
;
11422 int this_scroll_margin
;
11426 int amount_to_scroll
= 0;
11427 Lisp_Object aggressive
;
11429 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
11432 debug_method_add (w
, "try_scrolling");
11435 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
11437 /* Compute scroll margin height in pixels. We scroll when point is
11438 within this distance from the top or bottom of the window. */
11439 if (scroll_margin
> 0)
11441 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11442 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11445 this_scroll_margin
= 0;
11447 /* Force scroll_conservatively to have a reasonable value so it doesn't
11448 cause an overflow while computing how much to scroll. */
11449 if (scroll_conservatively
)
11450 scroll_conservatively
= min (scroll_conservatively
,
11451 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
11453 /* Compute how much we should try to scroll maximally to bring point
11455 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
11456 scroll_max
= max (scroll_step
,
11457 max (scroll_conservatively
, temp_scroll_step
));
11458 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
11459 || NUMBERP (current_buffer
->scroll_up_aggressively
))
11460 /* We're trying to scroll because of aggressive scrolling
11461 but no scroll_step is set. Choose an arbitrary one. Maybe
11462 there should be a variable for this. */
11466 scroll_max
*= FRAME_LINE_HEIGHT (f
);
11468 /* Decide whether we have to scroll down. Start at the window end
11469 and move this_scroll_margin up to find the position of the scroll
11471 window_end
= Fwindow_end (window
, Qt
);
11475 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
11476 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
11478 if (this_scroll_margin
|| extra_scroll_margin_lines
)
11480 start_display (&it
, w
, scroll_margin_pos
);
11481 if (this_scroll_margin
)
11482 move_it_vertically_backward (&it
, this_scroll_margin
);
11483 if (extra_scroll_margin_lines
)
11484 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
11485 scroll_margin_pos
= it
.current
.pos
;
11488 if (PT
>= CHARPOS (scroll_margin_pos
))
11492 /* Point is in the scroll margin at the bottom of the window, or
11493 below. Compute a new window start that makes point visible. */
11495 /* Compute the distance from the scroll margin to PT.
11496 Give up if the distance is greater than scroll_max. */
11497 start_display (&it
, w
, scroll_margin_pos
);
11499 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
11500 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11502 /* To make point visible, we have to move the window start
11503 down so that the line the cursor is in is visible, which
11504 means we have to add in the height of the cursor line. */
11505 dy
= line_bottom_y (&it
) - y0
;
11507 if (dy
> scroll_max
)
11508 return SCROLLING_FAILED
;
11510 /* Move the window start down. If scrolling conservatively,
11511 move it just enough down to make point visible. If
11512 scroll_step is set, move it down by scroll_step. */
11513 start_display (&it
, w
, startp
);
11515 if (scroll_conservatively
)
11516 /* Set AMOUNT_TO_SCROLL to at least one line,
11517 and at most scroll_conservatively lines. */
11519 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
11520 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
11521 else if (scroll_step
|| temp_scroll_step
)
11522 amount_to_scroll
= scroll_max
;
11525 aggressive
= current_buffer
->scroll_up_aggressively
;
11526 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11527 if (NUMBERP (aggressive
))
11529 double float_amount
= XFLOATINT (aggressive
) * height
;
11530 amount_to_scroll
= float_amount
;
11531 if (amount_to_scroll
== 0 && float_amount
> 0)
11532 amount_to_scroll
= 1;
11536 if (amount_to_scroll
<= 0)
11537 return SCROLLING_FAILED
;
11539 /* If moving by amount_to_scroll leaves STARTP unchanged,
11540 move it down one screen line. */
11542 move_it_vertically (&it
, amount_to_scroll
);
11543 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
11544 move_it_by_lines (&it
, 1, 1);
11545 startp
= it
.current
.pos
;
11549 /* See if point is inside the scroll margin at the top of the
11551 scroll_margin_pos
= startp
;
11552 if (this_scroll_margin
)
11554 start_display (&it
, w
, startp
);
11555 move_it_vertically (&it
, this_scroll_margin
);
11556 scroll_margin_pos
= it
.current
.pos
;
11559 if (PT
< CHARPOS (scroll_margin_pos
))
11561 /* Point is in the scroll margin at the top of the window or
11562 above what is displayed in the window. */
11565 /* Compute the vertical distance from PT to the scroll
11566 margin position. Give up if distance is greater than
11568 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
11569 start_display (&it
, w
, pos
);
11571 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
11572 it
.last_visible_y
, -1,
11573 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
11574 dy
= it
.current_y
- y0
;
11575 if (dy
> scroll_max
)
11576 return SCROLLING_FAILED
;
11578 /* Compute new window start. */
11579 start_display (&it
, w
, startp
);
11581 if (scroll_conservatively
)
11583 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
11584 else if (scroll_step
|| temp_scroll_step
)
11585 amount_to_scroll
= scroll_max
;
11588 aggressive
= current_buffer
->scroll_down_aggressively
;
11589 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
11590 if (NUMBERP (aggressive
))
11592 double float_amount
= XFLOATINT (aggressive
) * height
;
11593 amount_to_scroll
= float_amount
;
11594 if (amount_to_scroll
== 0 && float_amount
> 0)
11595 amount_to_scroll
= 1;
11599 if (amount_to_scroll
<= 0)
11600 return SCROLLING_FAILED
;
11602 move_it_vertically_backward (&it
, amount_to_scroll
);
11603 startp
= it
.current
.pos
;
11607 /* Run window scroll functions. */
11608 startp
= run_window_scroll_functions (window
, startp
);
11610 /* Display the window. Give up if new fonts are loaded, or if point
11612 if (!try_window (window
, startp
, 0))
11613 rc
= SCROLLING_NEED_LARGER_MATRICES
;
11614 else if (w
->cursor
.vpos
< 0)
11616 clear_glyph_matrix (w
->desired_matrix
);
11617 rc
= SCROLLING_FAILED
;
11621 /* Maybe forget recorded base line for line number display. */
11622 if (!just_this_one_p
11623 || current_buffer
->clip_changed
11624 || BEG_UNCHANGED
< CHARPOS (startp
))
11625 w
->base_line_number
= Qnil
;
11627 /* If cursor ends up on a partially visible line,
11628 treat that as being off the bottom of the screen. */
11629 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
11631 clear_glyph_matrix (w
->desired_matrix
);
11632 ++extra_scroll_margin_lines
;
11635 rc
= SCROLLING_SUCCESS
;
11642 /* Compute a suitable window start for window W if display of W starts
11643 on a continuation line. Value is non-zero if a new window start
11646 The new window start will be computed, based on W's width, starting
11647 from the start of the continued line. It is the start of the
11648 screen line with the minimum distance from the old start W->start. */
11651 compute_window_start_on_continuation_line (w
)
11654 struct text_pos pos
, start_pos
;
11655 int window_start_changed_p
= 0;
11657 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
11659 /* If window start is on a continuation line... Window start may be
11660 < BEGV in case there's invisible text at the start of the
11661 buffer (M-x rmail, for example). */
11662 if (CHARPOS (start_pos
) > BEGV
11663 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
11666 struct glyph_row
*row
;
11668 /* Handle the case that the window start is out of range. */
11669 if (CHARPOS (start_pos
) < BEGV
)
11670 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
11671 else if (CHARPOS (start_pos
) > ZV
)
11672 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
11674 /* Find the start of the continued line. This should be fast
11675 because scan_buffer is fast (newline cache). */
11676 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
11677 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
11678 row
, DEFAULT_FACE_ID
);
11679 reseat_at_previous_visible_line_start (&it
);
11681 /* If the line start is "too far" away from the window start,
11682 say it takes too much time to compute a new window start. */
11683 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
11684 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
11686 int min_distance
, distance
;
11688 /* Move forward by display lines to find the new window
11689 start. If window width was enlarged, the new start can
11690 be expected to be > the old start. If window width was
11691 decreased, the new window start will be < the old start.
11692 So, we're looking for the display line start with the
11693 minimum distance from the old window start. */
11694 pos
= it
.current
.pos
;
11695 min_distance
= INFINITY
;
11696 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
11697 distance
< min_distance
)
11699 min_distance
= distance
;
11700 pos
= it
.current
.pos
;
11701 move_it_by_lines (&it
, 1, 0);
11704 /* Set the window start there. */
11705 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
11706 window_start_changed_p
= 1;
11710 return window_start_changed_p
;
11714 /* Try cursor movement in case text has not changed in window WINDOW,
11715 with window start STARTP. Value is
11717 CURSOR_MOVEMENT_SUCCESS if successful
11719 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
11721 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
11722 display. *SCROLL_STEP is set to 1, under certain circumstances, if
11723 we want to scroll as if scroll-step were set to 1. See the code.
11725 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
11726 which case we have to abort this redisplay, and adjust matrices
11731 CURSOR_MOVEMENT_SUCCESS
,
11732 CURSOR_MOVEMENT_CANNOT_BE_USED
,
11733 CURSOR_MOVEMENT_MUST_SCROLL
,
11734 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
11738 try_cursor_movement (window
, startp
, scroll_step
)
11739 Lisp_Object window
;
11740 struct text_pos startp
;
11743 struct window
*w
= XWINDOW (window
);
11744 struct frame
*f
= XFRAME (w
->frame
);
11745 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
11748 if (inhibit_try_cursor_movement
)
11752 /* Handle case where text has not changed, only point, and it has
11753 not moved off the frame. */
11754 if (/* Point may be in this window. */
11755 PT
>= CHARPOS (startp
)
11756 /* Selective display hasn't changed. */
11757 && !current_buffer
->clip_changed
11758 /* Function force-mode-line-update is used to force a thorough
11759 redisplay. It sets either windows_or_buffers_changed or
11760 update_mode_lines. So don't take a shortcut here for these
11762 && !update_mode_lines
11763 && !windows_or_buffers_changed
11764 && !cursor_type_changed
11765 /* Can't use this case if highlighting a region. When a
11766 region exists, cursor movement has to do more than just
11768 && !(!NILP (Vtransient_mark_mode
)
11769 && !NILP (current_buffer
->mark_active
))
11770 && NILP (w
->region_showing
)
11771 && NILP (Vshow_trailing_whitespace
)
11772 /* Right after splitting windows, last_point may be nil. */
11773 && INTEGERP (w
->last_point
)
11774 /* This code is not used for mini-buffer for the sake of the case
11775 of redisplaying to replace an echo area message; since in
11776 that case the mini-buffer contents per se are usually
11777 unchanged. This code is of no real use in the mini-buffer
11778 since the handling of this_line_start_pos, etc., in redisplay
11779 handles the same cases. */
11780 && !EQ (window
, minibuf_window
)
11781 /* When splitting windows or for new windows, it happens that
11782 redisplay is called with a nil window_end_vpos or one being
11783 larger than the window. This should really be fixed in
11784 window.c. I don't have this on my list, now, so we do
11785 approximately the same as the old redisplay code. --gerd. */
11786 && INTEGERP (w
->window_end_vpos
)
11787 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
11788 && (FRAME_WINDOW_P (f
)
11789 || !overlay_arrow_in_current_buffer_p ()))
11791 int this_scroll_margin
, top_scroll_margin
;
11792 struct glyph_row
*row
= NULL
;
11795 debug_method_add (w
, "cursor movement");
11798 /* Scroll if point within this distance from the top or bottom
11799 of the window. This is a pixel value. */
11800 this_scroll_margin
= max (0, scroll_margin
);
11801 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
11802 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
11804 top_scroll_margin
= this_scroll_margin
;
11805 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11806 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
11808 /* Start with the row the cursor was displayed during the last
11809 not paused redisplay. Give up if that row is not valid. */
11810 if (w
->last_cursor
.vpos
< 0
11811 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
11812 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11815 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
11816 if (row
->mode_line_p
)
11818 if (!row
->enabled_p
)
11819 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11822 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
11825 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
11827 if (PT
> XFASTINT (w
->last_point
))
11829 /* Point has moved forward. */
11830 while (MATRIX_ROW_END_CHARPOS (row
) < PT
11831 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
11833 xassert (row
->enabled_p
);
11837 /* The end position of a row equals the start position
11838 of the next row. If PT is there, we would rather
11839 display it in the next line. */
11840 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11841 && MATRIX_ROW_END_CHARPOS (row
) == PT
11842 && !cursor_row_p (w
, row
))
11845 /* If within the scroll margin, scroll. Note that
11846 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
11847 the next line would be drawn, and that
11848 this_scroll_margin can be zero. */
11849 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
11850 || PT
> MATRIX_ROW_END_CHARPOS (row
)
11851 /* Line is completely visible last line in window
11852 and PT is to be set in the next line. */
11853 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
11854 && PT
== MATRIX_ROW_END_CHARPOS (row
)
11855 && !row
->ends_at_zv_p
11856 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
11859 else if (PT
< XFASTINT (w
->last_point
))
11861 /* Cursor has to be moved backward. Note that PT >=
11862 CHARPOS (startp) because of the outer if-statement. */
11863 while (!row
->mode_line_p
11864 && (MATRIX_ROW_START_CHARPOS (row
) > PT
11865 || (MATRIX_ROW_START_CHARPOS (row
) == PT
11866 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
11867 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
11868 row
> w
->current_matrix
->rows
11869 && (row
-1)->ends_in_newline_from_string_p
))))
11870 && (row
->y
> top_scroll_margin
11871 || CHARPOS (startp
) == BEGV
))
11873 xassert (row
->enabled_p
);
11877 /* Consider the following case: Window starts at BEGV,
11878 there is invisible, intangible text at BEGV, so that
11879 display starts at some point START > BEGV. It can
11880 happen that we are called with PT somewhere between
11881 BEGV and START. Try to handle that case. */
11882 if (row
< w
->current_matrix
->rows
11883 || row
->mode_line_p
)
11885 row
= w
->current_matrix
->rows
;
11886 if (row
->mode_line_p
)
11890 /* Due to newlines in overlay strings, we may have to
11891 skip forward over overlay strings. */
11892 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
11893 && MATRIX_ROW_END_CHARPOS (row
) == PT
11894 && !cursor_row_p (w
, row
))
11897 /* If within the scroll margin, scroll. */
11898 if (row
->y
< top_scroll_margin
11899 && CHARPOS (startp
) != BEGV
)
11904 /* Cursor did not move. So don't scroll even if cursor line
11905 is partially visible, as it was so before. */
11906 rc
= CURSOR_MOVEMENT_SUCCESS
;
11909 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
11910 || PT
> MATRIX_ROW_END_CHARPOS (row
))
11912 /* if PT is not in the glyph row, give up. */
11913 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11915 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
11916 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
11917 && make_cursor_line_fully_visible_p
)
11919 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
11920 && !row
->ends_at_zv_p
11921 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
11922 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11923 else if (row
->height
> window_box_height (w
))
11925 /* If we end up in a partially visible line, let's
11926 make it fully visible, except when it's taller
11927 than the window, in which case we can't do much
11930 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11934 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11935 if (!cursor_row_fully_visible_p (w
, 0, 1))
11936 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11938 rc
= CURSOR_MOVEMENT_SUCCESS
;
11942 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
11945 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11946 rc
= CURSOR_MOVEMENT_SUCCESS
;
11955 set_vertical_scroll_bar (w
)
11958 int start
, end
, whole
;
11960 /* Calculate the start and end positions for the current window.
11961 At some point, it would be nice to choose between scrollbars
11962 which reflect the whole buffer size, with special markers
11963 indicating narrowing, and scrollbars which reflect only the
11966 Note that mini-buffers sometimes aren't displaying any text. */
11967 if (!MINI_WINDOW_P (w
)
11968 || (w
== XWINDOW (minibuf_window
)
11969 && NILP (echo_area_buffer
[0])))
11971 struct buffer
*buf
= XBUFFER (w
->buffer
);
11972 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
11973 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
11974 /* I don't think this is guaranteed to be right. For the
11975 moment, we'll pretend it is. */
11976 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
11980 if (whole
< (end
- start
))
11981 whole
= end
- start
;
11984 start
= end
= whole
= 0;
11986 /* Indicate what this scroll bar ought to be displaying now. */
11987 set_vertical_scroll_bar_hook (w
, end
- start
, whole
, start
);
11991 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
11992 selected_window is redisplayed.
11994 We can return without actually redisplaying the window if
11995 fonts_changed_p is nonzero. In that case, redisplay_internal will
11999 redisplay_window (window
, just_this_one_p
)
12000 Lisp_Object window
;
12001 int just_this_one_p
;
12003 struct window
*w
= XWINDOW (window
);
12004 struct frame
*f
= XFRAME (w
->frame
);
12005 struct buffer
*buffer
= XBUFFER (w
->buffer
);
12006 struct buffer
*old
= current_buffer
;
12007 struct text_pos lpoint
, opoint
, startp
;
12008 int update_mode_line
;
12011 /* Record it now because it's overwritten. */
12012 int current_matrix_up_to_date_p
= 0;
12013 int used_current_matrix_p
= 0;
12014 /* This is less strict than current_matrix_up_to_date_p.
12015 It indictes that the buffer contents and narrowing are unchanged. */
12016 int buffer_unchanged_p
= 0;
12017 int temp_scroll_step
= 0;
12018 int count
= SPECPDL_INDEX ();
12020 int centering_position
= -1;
12021 int last_line_misfit
= 0;
12023 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12026 /* W must be a leaf window here. */
12027 xassert (!NILP (w
->buffer
));
12029 *w
->desired_matrix
->method
= 0;
12032 specbind (Qinhibit_point_motion_hooks
, Qt
);
12034 reconsider_clip_changes (w
, buffer
);
12036 /* Has the mode line to be updated? */
12037 update_mode_line
= (!NILP (w
->update_mode_line
)
12038 || update_mode_lines
12039 || buffer
->clip_changed
12040 || buffer
->prevent_redisplay_optimizations_p
);
12042 if (MINI_WINDOW_P (w
))
12044 if (w
== XWINDOW (echo_area_window
)
12045 && !NILP (echo_area_buffer
[0]))
12047 if (update_mode_line
)
12048 /* We may have to update a tty frame's menu bar or a
12049 tool-bar. Example `M-x C-h C-h C-g'. */
12050 goto finish_menu_bars
;
12052 /* We've already displayed the echo area glyphs in this window. */
12053 goto finish_scroll_bars
;
12055 else if ((w
!= XWINDOW (minibuf_window
)
12056 || minibuf_level
== 0)
12057 /* When buffer is nonempty, redisplay window normally. */
12058 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
12059 /* Quail displays non-mini buffers in minibuffer window.
12060 In that case, redisplay the window normally. */
12061 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
12063 /* W is a mini-buffer window, but it's not active, so clear
12065 int yb
= window_text_bottom_y (w
);
12066 struct glyph_row
*row
;
12069 for (y
= 0, row
= w
->desired_matrix
->rows
;
12071 y
+= row
->height
, ++row
)
12072 blank_row (w
, row
, y
);
12073 goto finish_scroll_bars
;
12076 clear_glyph_matrix (w
->desired_matrix
);
12079 /* Otherwise set up data on this window; select its buffer and point
12081 /* Really select the buffer, for the sake of buffer-local
12083 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12084 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
12086 current_matrix_up_to_date_p
12087 = (!NILP (w
->window_end_valid
)
12088 && !current_buffer
->clip_changed
12089 && !current_buffer
->prevent_redisplay_optimizations_p
12090 && XFASTINT (w
->last_modified
) >= MODIFF
12091 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12094 = (!NILP (w
->window_end_valid
)
12095 && !current_buffer
->clip_changed
12096 && XFASTINT (w
->last_modified
) >= MODIFF
12097 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
12099 /* When windows_or_buffers_changed is non-zero, we can't rely on
12100 the window end being valid, so set it to nil there. */
12101 if (windows_or_buffers_changed
)
12103 /* If window starts on a continuation line, maybe adjust the
12104 window start in case the window's width changed. */
12105 if (XMARKER (w
->start
)->buffer
== current_buffer
)
12106 compute_window_start_on_continuation_line (w
);
12108 w
->window_end_valid
= Qnil
;
12111 /* Some sanity checks. */
12112 CHECK_WINDOW_END (w
);
12113 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
12115 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
12118 /* If %c is in mode line, update it if needed. */
12119 if (!NILP (w
->column_number_displayed
)
12120 /* This alternative quickly identifies a common case
12121 where no change is needed. */
12122 && !(PT
== XFASTINT (w
->last_point
)
12123 && XFASTINT (w
->last_modified
) >= MODIFF
12124 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
12125 && (XFASTINT (w
->column_number_displayed
)
12126 != (int) current_column ())) /* iftc */
12127 update_mode_line
= 1;
12129 /* Count number of windows showing the selected buffer. An indirect
12130 buffer counts as its base buffer. */
12131 if (!just_this_one_p
)
12133 struct buffer
*current_base
, *window_base
;
12134 current_base
= current_buffer
;
12135 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12136 if (current_base
->base_buffer
)
12137 current_base
= current_base
->base_buffer
;
12138 if (window_base
->base_buffer
)
12139 window_base
= window_base
->base_buffer
;
12140 if (current_base
== window_base
)
12144 /* Point refers normally to the selected window. For any other
12145 window, set up appropriate value. */
12146 if (!EQ (window
, selected_window
))
12148 int new_pt
= XMARKER (w
->pointm
)->charpos
;
12149 int new_pt_byte
= marker_byte_position (w
->pointm
);
12153 new_pt_byte
= BEGV_BYTE
;
12154 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
12156 else if (new_pt
> (ZV
- 1))
12159 new_pt_byte
= ZV_BYTE
;
12160 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
12163 /* We don't use SET_PT so that the point-motion hooks don't run. */
12164 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
12167 /* If any of the character widths specified in the display table
12168 have changed, invalidate the width run cache. It's true that
12169 this may be a bit late to catch such changes, but the rest of
12170 redisplay goes (non-fatally) haywire when the display table is
12171 changed, so why should we worry about doing any better? */
12172 if (current_buffer
->width_run_cache
)
12174 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
12176 if (! disptab_matches_widthtab (disptab
,
12177 XVECTOR (current_buffer
->width_table
)))
12179 invalidate_region_cache (current_buffer
,
12180 current_buffer
->width_run_cache
,
12182 recompute_width_table (current_buffer
, disptab
);
12186 /* If window-start is screwed up, choose a new one. */
12187 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
12190 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12192 /* If someone specified a new starting point but did not insist,
12193 check whether it can be used. */
12194 if (!NILP (w
->optional_new_start
)
12195 && CHARPOS (startp
) >= BEGV
12196 && CHARPOS (startp
) <= ZV
)
12198 w
->optional_new_start
= Qnil
;
12199 start_display (&it
, w
, startp
);
12200 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12201 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12202 if (IT_CHARPOS (it
) == PT
)
12203 w
->force_start
= Qt
;
12204 /* IT may overshoot PT if text at PT is invisible. */
12205 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
12206 w
->force_start
= Qt
;
12211 /* Handle case where place to start displaying has been specified,
12212 unless the specified location is outside the accessible range. */
12213 if (!NILP (w
->force_start
)
12214 || w
->frozen_window_start_p
)
12216 /* We set this later on if we have to adjust point. */
12220 w
->force_start
= Qnil
;
12222 w
->window_end_valid
= Qnil
;
12224 /* Forget any recorded base line for line number display. */
12225 if (!buffer_unchanged_p
)
12226 w
->base_line_number
= Qnil
;
12228 /* Redisplay the mode line. Select the buffer properly for that.
12229 Also, run the hook window-scroll-functions
12230 because we have scrolled. */
12231 /* Note, we do this after clearing force_start because
12232 if there's an error, it is better to forget about force_start
12233 than to get into an infinite loop calling the hook functions
12234 and having them get more errors. */
12235 if (!update_mode_line
12236 || ! NILP (Vwindow_scroll_functions
))
12238 update_mode_line
= 1;
12239 w
->update_mode_line
= Qt
;
12240 startp
= run_window_scroll_functions (window
, startp
);
12243 w
->last_modified
= make_number (0);
12244 w
->last_overlay_modified
= make_number (0);
12245 if (CHARPOS (startp
) < BEGV
)
12246 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
12247 else if (CHARPOS (startp
) > ZV
)
12248 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
12250 /* Redisplay, then check if cursor has been set during the
12251 redisplay. Give up if new fonts were loaded. */
12252 val
= try_window (window
, startp
, 1);
12255 w
->force_start
= Qt
;
12256 clear_glyph_matrix (w
->desired_matrix
);
12257 goto need_larger_matrices
;
12259 /* Point was outside the scroll margins. */
12261 new_vpos
= window_box_height (w
) / 2;
12263 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
12265 /* If point does not appear, try to move point so it does
12266 appear. The desired matrix has been built above, so we
12267 can use it here. */
12268 new_vpos
= window_box_height (w
) / 2;
12271 if (!cursor_row_fully_visible_p (w
, 0, 0))
12273 /* Point does appear, but on a line partly visible at end of window.
12274 Move it back to a fully-visible line. */
12275 new_vpos
= window_box_height (w
);
12278 /* If we need to move point for either of the above reasons,
12279 now actually do it. */
12282 struct glyph_row
*row
;
12284 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
12285 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
12288 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
12289 MATRIX_ROW_START_BYTEPOS (row
));
12291 if (w
!= XWINDOW (selected_window
))
12292 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
12293 else if (current_buffer
== old
)
12294 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
12296 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
12298 /* If we are highlighting the region, then we just changed
12299 the region, so redisplay to show it. */
12300 if (!NILP (Vtransient_mark_mode
)
12301 && !NILP (current_buffer
->mark_active
))
12303 clear_glyph_matrix (w
->desired_matrix
);
12304 if (!try_window (window
, startp
, 0))
12305 goto need_larger_matrices
;
12310 debug_method_add (w
, "forced window start");
12315 /* Handle case where text has not changed, only point, and it has
12316 not moved off the frame, and we are not retrying after hscroll.
12317 (current_matrix_up_to_date_p is nonzero when retrying.) */
12318 if (current_matrix_up_to_date_p
12319 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
12320 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
12324 case CURSOR_MOVEMENT_SUCCESS
:
12325 used_current_matrix_p
= 1;
12328 #if 0 /* try_cursor_movement never returns this value. */
12329 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
12330 goto need_larger_matrices
;
12333 case CURSOR_MOVEMENT_MUST_SCROLL
:
12334 goto try_to_scroll
;
12340 /* If current starting point was originally the beginning of a line
12341 but no longer is, find a new starting point. */
12342 else if (!NILP (w
->start_at_line_beg
)
12343 && !(CHARPOS (startp
) <= BEGV
12344 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
12347 debug_method_add (w
, "recenter 1");
12352 /* Try scrolling with try_window_id. Value is > 0 if update has
12353 been done, it is -1 if we know that the same window start will
12354 not work. It is 0 if unsuccessful for some other reason. */
12355 else if ((tem
= try_window_id (w
)) != 0)
12358 debug_method_add (w
, "try_window_id %d", tem
);
12361 if (fonts_changed_p
)
12362 goto need_larger_matrices
;
12366 /* Otherwise try_window_id has returned -1 which means that we
12367 don't want the alternative below this comment to execute. */
12369 else if (CHARPOS (startp
) >= BEGV
12370 && CHARPOS (startp
) <= ZV
12371 && PT
>= CHARPOS (startp
)
12372 && (CHARPOS (startp
) < ZV
12373 /* Avoid starting at end of buffer. */
12374 || CHARPOS (startp
) == BEGV
12375 || (XFASTINT (w
->last_modified
) >= MODIFF
12376 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
12379 debug_method_add (w
, "same window start");
12382 /* Try to redisplay starting at same place as before.
12383 If point has not moved off frame, accept the results. */
12384 if (!current_matrix_up_to_date_p
12385 /* Don't use try_window_reusing_current_matrix in this case
12386 because a window scroll function can have changed the
12388 || !NILP (Vwindow_scroll_functions
)
12389 || MINI_WINDOW_P (w
)
12390 || !(used_current_matrix_p
12391 = try_window_reusing_current_matrix (w
)))
12393 IF_DEBUG (debug_method_add (w
, "1"));
12394 if (try_window (window
, startp
, 1) < 0)
12395 /* -1 means we need to scroll.
12396 0 means we need new matrices, but fonts_changed_p
12397 is set in that case, so we will detect it below. */
12398 goto try_to_scroll
;
12401 if (fonts_changed_p
)
12402 goto need_larger_matrices
;
12404 if (w
->cursor
.vpos
>= 0)
12406 if (!just_this_one_p
12407 || current_buffer
->clip_changed
12408 || BEG_UNCHANGED
< CHARPOS (startp
))
12409 /* Forget any recorded base line for line number display. */
12410 w
->base_line_number
= Qnil
;
12412 if (!cursor_row_fully_visible_p (w
, 1, 0))
12414 clear_glyph_matrix (w
->desired_matrix
);
12415 last_line_misfit
= 1;
12417 /* Drop through and scroll. */
12422 clear_glyph_matrix (w
->desired_matrix
);
12427 w
->last_modified
= make_number (0);
12428 w
->last_overlay_modified
= make_number (0);
12430 /* Redisplay the mode line. Select the buffer properly for that. */
12431 if (!update_mode_line
)
12433 update_mode_line
= 1;
12434 w
->update_mode_line
= Qt
;
12437 /* Try to scroll by specified few lines. */
12438 if ((scroll_conservatively
12440 || temp_scroll_step
12441 || NUMBERP (current_buffer
->scroll_up_aggressively
)
12442 || NUMBERP (current_buffer
->scroll_down_aggressively
))
12443 && !current_buffer
->clip_changed
12444 && CHARPOS (startp
) >= BEGV
12445 && CHARPOS (startp
) <= ZV
)
12447 /* The function returns -1 if new fonts were loaded, 1 if
12448 successful, 0 if not successful. */
12449 int rc
= try_scrolling (window
, just_this_one_p
,
12450 scroll_conservatively
,
12452 temp_scroll_step
, last_line_misfit
);
12455 case SCROLLING_SUCCESS
:
12458 case SCROLLING_NEED_LARGER_MATRICES
:
12459 goto need_larger_matrices
;
12461 case SCROLLING_FAILED
:
12469 /* Finally, just choose place to start which centers point */
12472 if (centering_position
< 0)
12473 centering_position
= window_box_height (w
) / 2;
12476 debug_method_add (w
, "recenter");
12479 /* w->vscroll = 0; */
12481 /* Forget any previously recorded base line for line number display. */
12482 if (!buffer_unchanged_p
)
12483 w
->base_line_number
= Qnil
;
12485 /* Move backward half the height of the window. */
12486 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12487 it
.current_y
= it
.last_visible_y
;
12488 move_it_vertically_backward (&it
, centering_position
);
12489 xassert (IT_CHARPOS (it
) >= BEGV
);
12491 /* The function move_it_vertically_backward may move over more
12492 than the specified y-distance. If it->w is small, e.g. a
12493 mini-buffer window, we may end up in front of the window's
12494 display area. Start displaying at the start of the line
12495 containing PT in this case. */
12496 if (it
.current_y
<= 0)
12498 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
12499 move_it_vertically_backward (&it
, 0);
12501 /* I think this assert is bogus if buffer contains
12502 invisible text or images. KFS. */
12503 xassert (IT_CHARPOS (it
) <= PT
);
12508 it
.current_x
= it
.hpos
= 0;
12510 /* Set startp here explicitly in case that helps avoid an infinite loop
12511 in case the window-scroll-functions functions get errors. */
12512 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
12514 /* Run scroll hooks. */
12515 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
12517 /* Redisplay the window. */
12518 if (!current_matrix_up_to_date_p
12519 || windows_or_buffers_changed
12520 || cursor_type_changed
12521 /* Don't use try_window_reusing_current_matrix in this case
12522 because it can have changed the buffer. */
12523 || !NILP (Vwindow_scroll_functions
)
12524 || !just_this_one_p
12525 || MINI_WINDOW_P (w
)
12526 || !(used_current_matrix_p
12527 = try_window_reusing_current_matrix (w
)))
12528 try_window (window
, startp
, 0);
12530 /* If new fonts have been loaded (due to fontsets), give up. We
12531 have to start a new redisplay since we need to re-adjust glyph
12533 if (fonts_changed_p
)
12534 goto need_larger_matrices
;
12536 /* If cursor did not appear assume that the middle of the window is
12537 in the first line of the window. Do it again with the next line.
12538 (Imagine a window of height 100, displaying two lines of height
12539 60. Moving back 50 from it->last_visible_y will end in the first
12541 if (w
->cursor
.vpos
< 0)
12543 if (!NILP (w
->window_end_valid
)
12544 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
12546 clear_glyph_matrix (w
->desired_matrix
);
12547 move_it_by_lines (&it
, 1, 0);
12548 try_window (window
, it
.current
.pos
, 0);
12550 else if (PT
< IT_CHARPOS (it
))
12552 clear_glyph_matrix (w
->desired_matrix
);
12553 move_it_by_lines (&it
, -1, 0);
12554 try_window (window
, it
.current
.pos
, 0);
12558 /* Not much we can do about it. */
12562 /* Consider the following case: Window starts at BEGV, there is
12563 invisible, intangible text at BEGV, so that display starts at
12564 some point START > BEGV. It can happen that we are called with
12565 PT somewhere between BEGV and START. Try to handle that case. */
12566 if (w
->cursor
.vpos
< 0)
12568 struct glyph_row
*row
= w
->current_matrix
->rows
;
12569 if (row
->mode_line_p
)
12571 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12574 if (!cursor_row_fully_visible_p (w
, 0, 0))
12576 /* If vscroll is enabled, disable it and try again. */
12580 clear_glyph_matrix (w
->desired_matrix
);
12584 /* If centering point failed to make the whole line visible,
12585 put point at the top instead. That has to make the whole line
12586 visible, if it can be done. */
12587 if (centering_position
== 0)
12590 clear_glyph_matrix (w
->desired_matrix
);
12591 centering_position
= 0;
12597 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12598 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
12599 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
12602 /* Display the mode line, if we must. */
12603 if ((update_mode_line
12604 /* If window not full width, must redo its mode line
12605 if (a) the window to its side is being redone and
12606 (b) we do a frame-based redisplay. This is a consequence
12607 of how inverted lines are drawn in frame-based redisplay. */
12608 || (!just_this_one_p
12609 && !FRAME_WINDOW_P (f
)
12610 && !WINDOW_FULL_WIDTH_P (w
))
12611 /* Line number to display. */
12612 || INTEGERP (w
->base_line_pos
)
12613 /* Column number is displayed and different from the one displayed. */
12614 || (!NILP (w
->column_number_displayed
)
12615 && (XFASTINT (w
->column_number_displayed
)
12616 != (int) current_column ()))) /* iftc */
12617 /* This means that the window has a mode line. */
12618 && (WINDOW_WANTS_MODELINE_P (w
)
12619 || WINDOW_WANTS_HEADER_LINE_P (w
)))
12621 display_mode_lines (w
);
12623 /* If mode line height has changed, arrange for a thorough
12624 immediate redisplay using the correct mode line height. */
12625 if (WINDOW_WANTS_MODELINE_P (w
)
12626 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
12628 fonts_changed_p
= 1;
12629 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
12630 = DESIRED_MODE_LINE_HEIGHT (w
);
12633 /* If top line height has changed, arrange for a thorough
12634 immediate redisplay using the correct mode line height. */
12635 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12636 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
12638 fonts_changed_p
= 1;
12639 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
12640 = DESIRED_HEADER_LINE_HEIGHT (w
);
12643 if (fonts_changed_p
)
12644 goto need_larger_matrices
;
12647 if (!line_number_displayed
12648 && !BUFFERP (w
->base_line_pos
))
12650 w
->base_line_pos
= Qnil
;
12651 w
->base_line_number
= Qnil
;
12656 /* When we reach a frame's selected window, redo the frame's menu bar. */
12657 if (update_mode_line
12658 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
12660 int redisplay_menu_p
= 0;
12661 int redisplay_tool_bar_p
= 0;
12663 if (FRAME_WINDOW_P (f
))
12665 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) || defined (MAC_OS) \
12666 || defined (USE_GTK)
12667 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
12669 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12673 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
12675 if (redisplay_menu_p
)
12676 display_menu_bar (w
);
12678 #ifdef HAVE_WINDOW_SYSTEM
12680 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
12682 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
12683 && (FRAME_TOOL_BAR_LINES (f
) > 0
12684 || auto_resize_tool_bars_p
);
12688 if (redisplay_tool_bar_p
)
12689 redisplay_tool_bar (f
);
12693 #ifdef HAVE_WINDOW_SYSTEM
12694 if (FRAME_WINDOW_P (f
)
12695 && update_window_fringes (w
, 0)
12696 && !just_this_one_p
12697 && (used_current_matrix_p
|| overlay_arrow_seen
)
12698 && !w
->pseudo_window_p
)
12702 if (draw_window_fringes (w
, 1))
12703 x_draw_vertical_border (w
);
12707 #endif /* HAVE_WINDOW_SYSTEM */
12709 /* We go to this label, with fonts_changed_p nonzero,
12710 if it is necessary to try again using larger glyph matrices.
12711 We have to redeem the scroll bar even in this case,
12712 because the loop in redisplay_internal expects that. */
12713 need_larger_matrices
:
12715 finish_scroll_bars
:
12717 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
12719 /* Set the thumb's position and size. */
12720 set_vertical_scroll_bar (w
);
12722 /* Note that we actually used the scroll bar attached to this
12723 window, so it shouldn't be deleted at the end of redisplay. */
12724 redeem_scroll_bar_hook (w
);
12727 /* Restore current_buffer and value of point in it. */
12728 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
12729 set_buffer_internal_1 (old
);
12730 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
12732 unbind_to (count
, Qnil
);
12736 /* Build the complete desired matrix of WINDOW with a window start
12737 buffer position POS.
12739 Value is 1 if successful. It is zero if fonts were loaded during
12740 redisplay which makes re-adjusting glyph matrices necessary, and -1
12741 if point would appear in the scroll margins.
12742 (We check that only if CHECK_MARGINS is nonzero. */
12745 try_window (window
, pos
, check_margins
)
12746 Lisp_Object window
;
12747 struct text_pos pos
;
12750 struct window
*w
= XWINDOW (window
);
12752 struct glyph_row
*last_text_row
= NULL
;
12754 /* Make POS the new window start. */
12755 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
12757 /* Mark cursor position as unknown. No overlay arrow seen. */
12758 w
->cursor
.vpos
= -1;
12759 overlay_arrow_seen
= 0;
12761 /* Initialize iterator and info to start at POS. */
12762 start_display (&it
, w
, pos
);
12764 /* Display all lines of W. */
12765 while (it
.current_y
< it
.last_visible_y
)
12767 if (display_line (&it
))
12768 last_text_row
= it
.glyph_row
- 1;
12769 if (fonts_changed_p
)
12773 /* Don't let the cursor end in the scroll margins. */
12775 && !MINI_WINDOW_P (w
))
12777 int this_scroll_margin
, cursor_height
;
12779 this_scroll_margin
= max (0, scroll_margin
);
12780 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12781 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
12782 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
12784 if ((w
->cursor
.y
< this_scroll_margin
12785 && CHARPOS (pos
) > BEGV
)
12786 /* rms: considering make_cursor_line_fully_visible_p here
12787 seems to give wrong results. We don't want to recenter
12788 when the last line is partly visible, we want to allow
12789 that case to be handled in the usual way. */
12790 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
12792 w
->cursor
.vpos
= -1;
12793 clear_glyph_matrix (w
->desired_matrix
);
12798 /* If bottom moved off end of frame, change mode line percentage. */
12799 if (XFASTINT (w
->window_end_pos
) <= 0
12800 && Z
!= IT_CHARPOS (it
))
12801 w
->update_mode_line
= Qt
;
12803 /* Set window_end_pos to the offset of the last character displayed
12804 on the window from the end of current_buffer. Set
12805 window_end_vpos to its row number. */
12808 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
12809 w
->window_end_bytepos
12810 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
12812 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
12814 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
12815 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
12816 ->displays_text_p
);
12820 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
12821 w
->window_end_pos
= make_number (Z
- ZV
);
12822 w
->window_end_vpos
= make_number (0);
12825 /* But that is not valid info until redisplay finishes. */
12826 w
->window_end_valid
= Qnil
;
12832 /************************************************************************
12833 Window redisplay reusing current matrix when buffer has not changed
12834 ************************************************************************/
12836 /* Try redisplay of window W showing an unchanged buffer with a
12837 different window start than the last time it was displayed by
12838 reusing its current matrix. Value is non-zero if successful.
12839 W->start is the new window start. */
12842 try_window_reusing_current_matrix (w
)
12845 struct frame
*f
= XFRAME (w
->frame
);
12846 struct glyph_row
*row
, *bottom_row
;
12849 struct text_pos start
, new_start
;
12850 int nrows_scrolled
, i
;
12851 struct glyph_row
*last_text_row
;
12852 struct glyph_row
*last_reused_text_row
;
12853 struct glyph_row
*start_row
;
12854 int start_vpos
, min_y
, max_y
;
12857 if (inhibit_try_window_reusing
)
12861 if (/* This function doesn't handle terminal frames. */
12862 !FRAME_WINDOW_P (f
)
12863 /* Don't try to reuse the display if windows have been split
12865 || windows_or_buffers_changed
12866 || cursor_type_changed
)
12869 /* Can't do this if region may have changed. */
12870 if ((!NILP (Vtransient_mark_mode
)
12871 && !NILP (current_buffer
->mark_active
))
12872 || !NILP (w
->region_showing
)
12873 || !NILP (Vshow_trailing_whitespace
))
12876 /* If top-line visibility has changed, give up. */
12877 if (WINDOW_WANTS_HEADER_LINE_P (w
)
12878 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
12881 /* Give up if old or new display is scrolled vertically. We could
12882 make this function handle this, but right now it doesn't. */
12883 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12884 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
12887 /* The variable new_start now holds the new window start. The old
12888 start `start' can be determined from the current matrix. */
12889 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
12890 start
= start_row
->start
.pos
;
12891 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12893 /* Clear the desired matrix for the display below. */
12894 clear_glyph_matrix (w
->desired_matrix
);
12896 if (CHARPOS (new_start
) <= CHARPOS (start
))
12900 /* Don't use this method if the display starts with an ellipsis
12901 displayed for invisible text. It's not easy to handle that case
12902 below, and it's certainly not worth the effort since this is
12903 not a frequent case. */
12904 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
12907 IF_DEBUG (debug_method_add (w
, "twu1"));
12909 /* Display up to a row that can be reused. The variable
12910 last_text_row is set to the last row displayed that displays
12911 text. Note that it.vpos == 0 if or if not there is a
12912 header-line; it's not the same as the MATRIX_ROW_VPOS! */
12913 start_display (&it
, w
, new_start
);
12914 first_row_y
= it
.current_y
;
12915 w
->cursor
.vpos
= -1;
12916 last_text_row
= last_reused_text_row
= NULL
;
12918 while (it
.current_y
< it
.last_visible_y
12919 && !fonts_changed_p
)
12921 /* If we have reached into the characters in the START row,
12922 that means the line boundaries have changed. So we
12923 can't start copying with the row START. Maybe it will
12924 work to start copying with the following row. */
12925 while (IT_CHARPOS (it
) > CHARPOS (start
))
12927 /* Advance to the next row as the "start". */
12929 start
= start_row
->start
.pos
;
12930 /* If there are no more rows to try, or just one, give up. */
12931 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
12932 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
12933 || CHARPOS (start
) == ZV
)
12935 clear_glyph_matrix (w
->desired_matrix
);
12939 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
12941 /* If we have reached alignment,
12942 we can copy the rest of the rows. */
12943 if (IT_CHARPOS (it
) == CHARPOS (start
))
12946 if (display_line (&it
))
12947 last_text_row
= it
.glyph_row
- 1;
12950 /* A value of current_y < last_visible_y means that we stopped
12951 at the previous window start, which in turn means that we
12952 have at least one reusable row. */
12953 if (it
.current_y
< it
.last_visible_y
)
12955 /* IT.vpos always starts from 0; it counts text lines. */
12956 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
12958 /* Find PT if not already found in the lines displayed. */
12959 if (w
->cursor
.vpos
< 0)
12961 int dy
= it
.current_y
- start_row
->y
;
12963 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
12964 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
12966 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
12967 dy
, nrows_scrolled
);
12970 clear_glyph_matrix (w
->desired_matrix
);
12975 /* Scroll the display. Do it before the current matrix is
12976 changed. The problem here is that update has not yet
12977 run, i.e. part of the current matrix is not up to date.
12978 scroll_run_hook will clear the cursor, and use the
12979 current matrix to get the height of the row the cursor is
12981 run
.current_y
= start_row
->y
;
12982 run
.desired_y
= it
.current_y
;
12983 run
.height
= it
.last_visible_y
- it
.current_y
;
12985 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
12988 rif
->update_window_begin_hook (w
);
12989 rif
->clear_window_mouse_face (w
);
12990 rif
->scroll_run_hook (w
, &run
);
12991 rif
->update_window_end_hook (w
, 0, 0);
12995 /* Shift current matrix down by nrows_scrolled lines. */
12996 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12997 rotate_matrix (w
->current_matrix
,
12999 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13002 /* Disable lines that must be updated. */
13003 for (i
= 0; i
< it
.vpos
; ++i
)
13004 (start_row
+ i
)->enabled_p
= 0;
13006 /* Re-compute Y positions. */
13007 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13008 max_y
= it
.last_visible_y
;
13009 for (row
= start_row
+ nrows_scrolled
;
13013 row
->y
= it
.current_y
;
13014 row
->visible_height
= row
->height
;
13016 if (row
->y
< min_y
)
13017 row
->visible_height
-= min_y
- row
->y
;
13018 if (row
->y
+ row
->height
> max_y
)
13019 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13020 row
->redraw_fringe_bitmaps_p
= 1;
13022 it
.current_y
+= row
->height
;
13024 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13025 last_reused_text_row
= row
;
13026 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
13030 /* Disable lines in the current matrix which are now
13031 below the window. */
13032 for (++row
; row
< bottom_row
; ++row
)
13033 row
->enabled_p
= 0;
13036 /* Update window_end_pos etc.; last_reused_text_row is the last
13037 reused row from the current matrix containing text, if any.
13038 The value of last_text_row is the last displayed line
13039 containing text. */
13040 if (last_reused_text_row
)
13042 w
->window_end_bytepos
13043 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
13045 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
13047 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
13048 w
->current_matrix
));
13050 else if (last_text_row
)
13052 w
->window_end_bytepos
13053 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13055 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13057 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13061 /* This window must be completely empty. */
13062 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
13063 w
->window_end_pos
= make_number (Z
- ZV
);
13064 w
->window_end_vpos
= make_number (0);
13066 w
->window_end_valid
= Qnil
;
13068 /* Update hint: don't try scrolling again in update_window. */
13069 w
->desired_matrix
->no_scrolling_p
= 1;
13072 debug_method_add (w
, "try_window_reusing_current_matrix 1");
13076 else if (CHARPOS (new_start
) > CHARPOS (start
))
13078 struct glyph_row
*pt_row
, *row
;
13079 struct glyph_row
*first_reusable_row
;
13080 struct glyph_row
*first_row_to_display
;
13082 int yb
= window_text_bottom_y (w
);
13084 /* Find the row starting at new_start, if there is one. Don't
13085 reuse a partially visible line at the end. */
13086 first_reusable_row
= start_row
;
13087 while (first_reusable_row
->enabled_p
13088 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
13089 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13090 < CHARPOS (new_start
)))
13091 ++first_reusable_row
;
13093 /* Give up if there is no row to reuse. */
13094 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
13095 || !first_reusable_row
->enabled_p
13096 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
13097 != CHARPOS (new_start
)))
13100 /* We can reuse fully visible rows beginning with
13101 first_reusable_row to the end of the window. Set
13102 first_row_to_display to the first row that cannot be reused.
13103 Set pt_row to the row containing point, if there is any. */
13105 for (first_row_to_display
= first_reusable_row
;
13106 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
13107 ++first_row_to_display
)
13109 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
13110 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
13111 pt_row
= first_row_to_display
;
13114 /* Start displaying at the start of first_row_to_display. */
13115 xassert (first_row_to_display
->y
< yb
);
13116 init_to_row_start (&it
, w
, first_row_to_display
);
13118 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
13120 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
13122 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
13123 + WINDOW_HEADER_LINE_HEIGHT (w
));
13125 /* Display lines beginning with first_row_to_display in the
13126 desired matrix. Set last_text_row to the last row displayed
13127 that displays text. */
13128 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
13129 if (pt_row
== NULL
)
13130 w
->cursor
.vpos
= -1;
13131 last_text_row
= NULL
;
13132 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
13133 if (display_line (&it
))
13134 last_text_row
= it
.glyph_row
- 1;
13136 /* Give up If point isn't in a row displayed or reused. */
13137 if (w
->cursor
.vpos
< 0)
13139 clear_glyph_matrix (w
->desired_matrix
);
13143 /* If point is in a reused row, adjust y and vpos of the cursor
13147 w
->cursor
.vpos
-= nrows_scrolled
;
13148 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
13151 /* Scroll the display. */
13152 run
.current_y
= first_reusable_row
->y
;
13153 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13154 run
.height
= it
.last_visible_y
- run
.current_y
;
13155 dy
= run
.current_y
- run
.desired_y
;
13160 rif
->update_window_begin_hook (w
);
13161 rif
->clear_window_mouse_face (w
);
13162 rif
->scroll_run_hook (w
, &run
);
13163 rif
->update_window_end_hook (w
, 0, 0);
13167 /* Adjust Y positions of reused rows. */
13168 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
13169 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
13170 max_y
= it
.last_visible_y
;
13171 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
13174 row
->visible_height
= row
->height
;
13175 if (row
->y
< min_y
)
13176 row
->visible_height
-= min_y
- row
->y
;
13177 if (row
->y
+ row
->height
> max_y
)
13178 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
13179 row
->redraw_fringe_bitmaps_p
= 1;
13182 /* Scroll the current matrix. */
13183 xassert (nrows_scrolled
> 0);
13184 rotate_matrix (w
->current_matrix
,
13186 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
13189 /* Disable rows not reused. */
13190 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
13191 row
->enabled_p
= 0;
13193 /* Point may have moved to a different line, so we cannot assume that
13194 the previous cursor position is valid; locate the correct row. */
13197 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
13198 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
13202 w
->cursor
.y
= row
->y
;
13204 if (row
< bottom_row
)
13206 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
13207 while (glyph
->charpos
< PT
)
13210 w
->cursor
.x
+= glyph
->pixel_width
;
13216 /* Adjust window end. A null value of last_text_row means that
13217 the window end is in reused rows which in turn means that
13218 only its vpos can have changed. */
13221 w
->window_end_bytepos
13222 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
13224 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
13226 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
13231 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
13234 w
->window_end_valid
= Qnil
;
13235 w
->desired_matrix
->no_scrolling_p
= 1;
13238 debug_method_add (w
, "try_window_reusing_current_matrix 2");
13248 /************************************************************************
13249 Window redisplay reusing current matrix when buffer has changed
13250 ************************************************************************/
13252 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
13253 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
13255 static struct glyph_row
*
13256 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
13257 struct glyph_row
*));
13260 /* Return the last row in MATRIX displaying text. If row START is
13261 non-null, start searching with that row. IT gives the dimensions
13262 of the display. Value is null if matrix is empty; otherwise it is
13263 a pointer to the row found. */
13265 static struct glyph_row
*
13266 find_last_row_displaying_text (matrix
, it
, start
)
13267 struct glyph_matrix
*matrix
;
13269 struct glyph_row
*start
;
13271 struct glyph_row
*row
, *row_found
;
13273 /* Set row_found to the last row in IT->w's current matrix
13274 displaying text. The loop looks funny but think of partially
13277 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
13278 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13280 xassert (row
->enabled_p
);
13282 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
13291 /* Return the last row in the current matrix of W that is not affected
13292 by changes at the start of current_buffer that occurred since W's
13293 current matrix was built. Value is null if no such row exists.
13295 BEG_UNCHANGED us the number of characters unchanged at the start of
13296 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
13297 first changed character in current_buffer. Characters at positions <
13298 BEG + BEG_UNCHANGED are at the same buffer positions as they were
13299 when the current matrix was built. */
13301 static struct glyph_row
*
13302 find_last_unchanged_at_beg_row (w
)
13305 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
13306 struct glyph_row
*row
;
13307 struct glyph_row
*row_found
= NULL
;
13308 int yb
= window_text_bottom_y (w
);
13310 /* Find the last row displaying unchanged text. */
13311 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13312 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13313 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
13315 if (/* If row ends before first_changed_pos, it is unchanged,
13316 except in some case. */
13317 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
13318 /* When row ends in ZV and we write at ZV it is not
13320 && !row
->ends_at_zv_p
13321 /* When first_changed_pos is the end of a continued line,
13322 row is not unchanged because it may be no longer
13324 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
13325 && (row
->continued_p
13326 || row
->exact_window_width_line_p
)))
13329 /* Stop if last visible row. */
13330 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
13340 /* Find the first glyph row in the current matrix of W that is not
13341 affected by changes at the end of current_buffer since the
13342 time W's current matrix was built.
13344 Return in *DELTA the number of chars by which buffer positions in
13345 unchanged text at the end of current_buffer must be adjusted.
13347 Return in *DELTA_BYTES the corresponding number of bytes.
13349 Value is null if no such row exists, i.e. all rows are affected by
13352 static struct glyph_row
*
13353 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
13355 int *delta
, *delta_bytes
;
13357 struct glyph_row
*row
;
13358 struct glyph_row
*row_found
= NULL
;
13360 *delta
= *delta_bytes
= 0;
13362 /* Display must not have been paused, otherwise the current matrix
13363 is not up to date. */
13364 if (NILP (w
->window_end_valid
))
13367 /* A value of window_end_pos >= END_UNCHANGED means that the window
13368 end is in the range of changed text. If so, there is no
13369 unchanged row at the end of W's current matrix. */
13370 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
13373 /* Set row to the last row in W's current matrix displaying text. */
13374 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13376 /* If matrix is entirely empty, no unchanged row exists. */
13377 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13379 /* The value of row is the last glyph row in the matrix having a
13380 meaningful buffer position in it. The end position of row
13381 corresponds to window_end_pos. This allows us to translate
13382 buffer positions in the current matrix to current buffer
13383 positions for characters not in changed text. */
13384 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13385 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13386 int last_unchanged_pos
, last_unchanged_pos_old
;
13387 struct glyph_row
*first_text_row
13388 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
13390 *delta
= Z
- Z_old
;
13391 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13393 /* Set last_unchanged_pos to the buffer position of the last
13394 character in the buffer that has not been changed. Z is the
13395 index + 1 of the last character in current_buffer, i.e. by
13396 subtracting END_UNCHANGED we get the index of the last
13397 unchanged character, and we have to add BEG to get its buffer
13399 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
13400 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
13402 /* Search backward from ROW for a row displaying a line that
13403 starts at a minimum position >= last_unchanged_pos_old. */
13404 for (; row
> first_text_row
; --row
)
13406 /* This used to abort, but it can happen.
13407 It is ok to just stop the search instead here. KFS. */
13408 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13411 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
13416 if (row_found
&& !MATRIX_ROW_DISPLAYS_TEXT_P (row_found
))
13423 /* Make sure that glyph rows in the current matrix of window W
13424 reference the same glyph memory as corresponding rows in the
13425 frame's frame matrix. This function is called after scrolling W's
13426 current matrix on a terminal frame in try_window_id and
13427 try_window_reusing_current_matrix. */
13430 sync_frame_with_window_matrix_rows (w
)
13433 struct frame
*f
= XFRAME (w
->frame
);
13434 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
13436 /* Preconditions: W must be a leaf window and full-width. Its frame
13437 must have a frame matrix. */
13438 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
13439 xassert (WINDOW_FULL_WIDTH_P (w
));
13440 xassert (!FRAME_WINDOW_P (f
));
13442 /* If W is a full-width window, glyph pointers in W's current matrix
13443 have, by definition, to be the same as glyph pointers in the
13444 corresponding frame matrix. Note that frame matrices have no
13445 marginal areas (see build_frame_matrix). */
13446 window_row
= w
->current_matrix
->rows
;
13447 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
13448 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
13449 while (window_row
< window_row_end
)
13451 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
13452 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
13454 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
13455 frame_row
->glyphs
[TEXT_AREA
] = start
;
13456 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
13457 frame_row
->glyphs
[LAST_AREA
] = end
;
13459 /* Disable frame rows whose corresponding window rows have
13460 been disabled in try_window_id. */
13461 if (!window_row
->enabled_p
)
13462 frame_row
->enabled_p
= 0;
13464 ++window_row
, ++frame_row
;
13469 /* Find the glyph row in window W containing CHARPOS. Consider all
13470 rows between START and END (not inclusive). END null means search
13471 all rows to the end of the display area of W. Value is the row
13472 containing CHARPOS or null. */
13475 row_containing_pos (w
, charpos
, start
, end
, dy
)
13478 struct glyph_row
*start
, *end
;
13481 struct glyph_row
*row
= start
;
13484 /* If we happen to start on a header-line, skip that. */
13485 if (row
->mode_line_p
)
13488 if ((end
&& row
>= end
) || !row
->enabled_p
)
13491 last_y
= window_text_bottom_y (w
) - dy
;
13495 /* Give up if we have gone too far. */
13496 if (end
&& row
>= end
)
13498 /* This formerly returned if they were equal.
13499 I think that both quantities are of a "last plus one" type;
13500 if so, when they are equal, the row is within the screen. -- rms. */
13501 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
13504 /* If it is in this row, return this row. */
13505 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
13506 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
13507 /* The end position of a row equals the start
13508 position of the next row. If CHARPOS is there, we
13509 would rather display it in the next line, except
13510 when this line ends in ZV. */
13511 && !row
->ends_at_zv_p
13512 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13513 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
13520 /* Try to redisplay window W by reusing its existing display. W's
13521 current matrix must be up to date when this function is called,
13522 i.e. window_end_valid must not be nil.
13526 1 if display has been updated
13527 0 if otherwise unsuccessful
13528 -1 if redisplay with same window start is known not to succeed
13530 The following steps are performed:
13532 1. Find the last row in the current matrix of W that is not
13533 affected by changes at the start of current_buffer. If no such row
13536 2. Find the first row in W's current matrix that is not affected by
13537 changes at the end of current_buffer. Maybe there is no such row.
13539 3. Display lines beginning with the row + 1 found in step 1 to the
13540 row found in step 2 or, if step 2 didn't find a row, to the end of
13543 4. If cursor is not known to appear on the window, give up.
13545 5. If display stopped at the row found in step 2, scroll the
13546 display and current matrix as needed.
13548 6. Maybe display some lines at the end of W, if we must. This can
13549 happen under various circumstances, like a partially visible line
13550 becoming fully visible, or because newly displayed lines are displayed
13551 in smaller font sizes.
13553 7. Update W's window end information. */
13559 struct frame
*f
= XFRAME (w
->frame
);
13560 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
13561 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
13562 struct glyph_row
*last_unchanged_at_beg_row
;
13563 struct glyph_row
*first_unchanged_at_end_row
;
13564 struct glyph_row
*row
;
13565 struct glyph_row
*bottom_row
;
13568 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
13569 struct text_pos start_pos
;
13571 int first_unchanged_at_end_vpos
= 0;
13572 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
13573 struct text_pos start
;
13574 int first_changed_charpos
, last_changed_charpos
;
13577 if (inhibit_try_window_id
)
13581 /* This is handy for debugging. */
13583 #define GIVE_UP(X) \
13585 fprintf (stderr, "try_window_id give up %d\n", (X)); \
13589 #define GIVE_UP(X) return 0
13592 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
13594 /* Don't use this for mini-windows because these can show
13595 messages and mini-buffers, and we don't handle that here. */
13596 if (MINI_WINDOW_P (w
))
13599 /* This flag is used to prevent redisplay optimizations. */
13600 if (windows_or_buffers_changed
|| cursor_type_changed
)
13603 /* Verify that narrowing has not changed.
13604 Also verify that we were not told to prevent redisplay optimizations.
13605 It would be nice to further
13606 reduce the number of cases where this prevents try_window_id. */
13607 if (current_buffer
->clip_changed
13608 || current_buffer
->prevent_redisplay_optimizations_p
)
13611 /* Window must either use window-based redisplay or be full width. */
13612 if (!FRAME_WINDOW_P (f
)
13613 && (!line_ins_del_ok
13614 || !WINDOW_FULL_WIDTH_P (w
)))
13617 /* Give up if point is not known NOT to appear in W. */
13618 if (PT
< CHARPOS (start
))
13621 /* Another way to prevent redisplay optimizations. */
13622 if (XFASTINT (w
->last_modified
) == 0)
13625 /* Verify that window is not hscrolled. */
13626 if (XFASTINT (w
->hscroll
) != 0)
13629 /* Verify that display wasn't paused. */
13630 if (NILP (w
->window_end_valid
))
13633 /* Can't use this if highlighting a region because a cursor movement
13634 will do more than just set the cursor. */
13635 if (!NILP (Vtransient_mark_mode
)
13636 && !NILP (current_buffer
->mark_active
))
13639 /* Likewise if highlighting trailing whitespace. */
13640 if (!NILP (Vshow_trailing_whitespace
))
13643 /* Likewise if showing a region. */
13644 if (!NILP (w
->region_showing
))
13647 /* Can use this if overlay arrow position and or string have changed. */
13648 if (overlay_arrows_changed_p ())
13652 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
13653 only if buffer has really changed. The reason is that the gap is
13654 initially at Z for freshly visited files. The code below would
13655 set end_unchanged to 0 in that case. */
13656 if (MODIFF
> SAVE_MODIFF
13657 /* This seems to happen sometimes after saving a buffer. */
13658 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
13660 if (GPT
- BEG
< BEG_UNCHANGED
)
13661 BEG_UNCHANGED
= GPT
- BEG
;
13662 if (Z
- GPT
< END_UNCHANGED
)
13663 END_UNCHANGED
= Z
- GPT
;
13666 /* The position of the first and last character that has been changed. */
13667 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
13668 last_changed_charpos
= Z
- END_UNCHANGED
;
13670 /* If window starts after a line end, and the last change is in
13671 front of that newline, then changes don't affect the display.
13672 This case happens with stealth-fontification. Note that although
13673 the display is unchanged, glyph positions in the matrix have to
13674 be adjusted, of course. */
13675 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
13676 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
13677 && ((last_changed_charpos
< CHARPOS (start
)
13678 && CHARPOS (start
) == BEGV
)
13679 || (last_changed_charpos
< CHARPOS (start
) - 1
13680 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
13682 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
13683 struct glyph_row
*r0
;
13685 /* Compute how many chars/bytes have been added to or removed
13686 from the buffer. */
13687 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
13688 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
13690 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
13692 /* Give up if PT is not in the window. Note that it already has
13693 been checked at the start of try_window_id that PT is not in
13694 front of the window start. */
13695 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
13698 /* If window start is unchanged, we can reuse the whole matrix
13699 as is, after adjusting glyph positions. No need to compute
13700 the window end again, since its offset from Z hasn't changed. */
13701 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13702 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
13703 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
13704 /* PT must not be in a partially visible line. */
13705 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
13706 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13708 /* Adjust positions in the glyph matrix. */
13709 if (delta
|| delta_bytes
)
13711 struct glyph_row
*r1
13712 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
13713 increment_matrix_positions (w
->current_matrix
,
13714 MATRIX_ROW_VPOS (r0
, current_matrix
),
13715 MATRIX_ROW_VPOS (r1
, current_matrix
),
13716 delta
, delta_bytes
);
13719 /* Set the cursor. */
13720 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13722 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13729 /* Handle the case that changes are all below what is displayed in
13730 the window, and that PT is in the window. This shortcut cannot
13731 be taken if ZV is visible in the window, and text has been added
13732 there that is visible in the window. */
13733 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
13734 /* ZV is not visible in the window, or there are no
13735 changes at ZV, actually. */
13736 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
13737 || first_changed_charpos
== last_changed_charpos
))
13739 struct glyph_row
*r0
;
13741 /* Give up if PT is not in the window. Note that it already has
13742 been checked at the start of try_window_id that PT is not in
13743 front of the window start. */
13744 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
13747 /* If window start is unchanged, we can reuse the whole matrix
13748 as is, without changing glyph positions since no text has
13749 been added/removed in front of the window end. */
13750 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13751 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
13752 /* PT must not be in a partially visible line. */
13753 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
13754 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
13756 /* We have to compute the window end anew since text
13757 can have been added/removed after it. */
13759 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
13760 w
->window_end_bytepos
13761 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
13763 /* Set the cursor. */
13764 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
13766 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
13773 /* Give up if window start is in the changed area.
13775 The condition used to read
13777 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
13779 but why that was tested escapes me at the moment. */
13780 if (CHARPOS (start
) >= first_changed_charpos
13781 && CHARPOS (start
) <= last_changed_charpos
)
13784 /* Check that window start agrees with the start of the first glyph
13785 row in its current matrix. Check this after we know the window
13786 start is not in changed text, otherwise positions would not be
13788 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
13789 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
13792 /* Give up if the window ends in strings. Overlay strings
13793 at the end are difficult to handle, so don't try. */
13794 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
13795 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
13798 /* Compute the position at which we have to start displaying new
13799 lines. Some of the lines at the top of the window might be
13800 reusable because they are not displaying changed text. Find the
13801 last row in W's current matrix not affected by changes at the
13802 start of current_buffer. Value is null if changes start in the
13803 first line of window. */
13804 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
13805 if (last_unchanged_at_beg_row
)
13807 /* Avoid starting to display in the moddle of a character, a TAB
13808 for instance. This is easier than to set up the iterator
13809 exactly, and it's not a frequent case, so the additional
13810 effort wouldn't really pay off. */
13811 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
13812 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
13813 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
13814 --last_unchanged_at_beg_row
;
13816 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
13819 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
13821 start_pos
= it
.current
.pos
;
13823 /* Start displaying new lines in the desired matrix at the same
13824 vpos we would use in the current matrix, i.e. below
13825 last_unchanged_at_beg_row. */
13826 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
13828 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
13829 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
13831 xassert (it
.hpos
== 0 && it
.current_x
== 0);
13835 /* There are no reusable lines at the start of the window.
13836 Start displaying in the first text line. */
13837 start_display (&it
, w
, start
);
13838 it
.vpos
= it
.first_vpos
;
13839 start_pos
= it
.current
.pos
;
13842 /* Find the first row that is not affected by changes at the end of
13843 the buffer. Value will be null if there is no unchanged row, in
13844 which case we must redisplay to the end of the window. delta
13845 will be set to the value by which buffer positions beginning with
13846 first_unchanged_at_end_row have to be adjusted due to text
13848 first_unchanged_at_end_row
13849 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
13850 IF_DEBUG (debug_delta
= delta
);
13851 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
13853 /* Set stop_pos to the buffer position up to which we will have to
13854 display new lines. If first_unchanged_at_end_row != NULL, this
13855 is the buffer position of the start of the line displayed in that
13856 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
13857 that we don't stop at a buffer position. */
13859 if (first_unchanged_at_end_row
)
13861 xassert (last_unchanged_at_beg_row
== NULL
13862 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
13864 /* If this is a continuation line, move forward to the next one
13865 that isn't. Changes in lines above affect this line.
13866 Caution: this may move first_unchanged_at_end_row to a row
13867 not displaying text. */
13868 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
13869 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13870 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13871 < it
.last_visible_y
))
13872 ++first_unchanged_at_end_row
;
13874 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
13875 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
13876 >= it
.last_visible_y
))
13877 first_unchanged_at_end_row
= NULL
;
13880 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
13882 first_unchanged_at_end_vpos
13883 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
13884 xassert (stop_pos
>= Z
- END_UNCHANGED
);
13887 else if (last_unchanged_at_beg_row
== NULL
)
13893 /* Either there is no unchanged row at the end, or the one we have
13894 now displays text. This is a necessary condition for the window
13895 end pos calculation at the end of this function. */
13896 xassert (first_unchanged_at_end_row
== NULL
13897 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
13899 debug_last_unchanged_at_beg_vpos
13900 = (last_unchanged_at_beg_row
13901 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
13903 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
13905 #endif /* GLYPH_DEBUG != 0 */
13908 /* Display new lines. Set last_text_row to the last new line
13909 displayed which has text on it, i.e. might end up as being the
13910 line where the window_end_vpos is. */
13911 w
->cursor
.vpos
= -1;
13912 last_text_row
= NULL
;
13913 overlay_arrow_seen
= 0;
13914 while (it
.current_y
< it
.last_visible_y
13915 && !fonts_changed_p
13916 && (first_unchanged_at_end_row
== NULL
13917 || IT_CHARPOS (it
) < stop_pos
))
13919 if (display_line (&it
))
13920 last_text_row
= it
.glyph_row
- 1;
13923 if (fonts_changed_p
)
13927 /* Compute differences in buffer positions, y-positions etc. for
13928 lines reused at the bottom of the window. Compute what we can
13930 if (first_unchanged_at_end_row
13931 /* No lines reused because we displayed everything up to the
13932 bottom of the window. */
13933 && it
.current_y
< it
.last_visible_y
)
13936 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
13938 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
13939 run
.current_y
= first_unchanged_at_end_row
->y
;
13940 run
.desired_y
= run
.current_y
+ dy
;
13941 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
13945 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
13946 first_unchanged_at_end_row
= NULL
;
13948 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
13951 /* Find the cursor if not already found. We have to decide whether
13952 PT will appear on this window (it sometimes doesn't, but this is
13953 not a very frequent case.) This decision has to be made before
13954 the current matrix is altered. A value of cursor.vpos < 0 means
13955 that PT is either in one of the lines beginning at
13956 first_unchanged_at_end_row or below the window. Don't care for
13957 lines that might be displayed later at the window end; as
13958 mentioned, this is not a frequent case. */
13959 if (w
->cursor
.vpos
< 0)
13961 /* Cursor in unchanged rows at the top? */
13962 if (PT
< CHARPOS (start_pos
)
13963 && last_unchanged_at_beg_row
)
13965 row
= row_containing_pos (w
, PT
,
13966 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
13967 last_unchanged_at_beg_row
+ 1, 0);
13969 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13972 /* Start from first_unchanged_at_end_row looking for PT. */
13973 else if (first_unchanged_at_end_row
)
13975 row
= row_containing_pos (w
, PT
- delta
,
13976 first_unchanged_at_end_row
, NULL
, 0);
13978 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
13979 delta_bytes
, dy
, dvpos
);
13982 /* Give up if cursor was not found. */
13983 if (w
->cursor
.vpos
< 0)
13985 clear_glyph_matrix (w
->desired_matrix
);
13990 /* Don't let the cursor end in the scroll margins. */
13992 int this_scroll_margin
, cursor_height
;
13994 this_scroll_margin
= max (0, scroll_margin
);
13995 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13996 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
13997 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
13999 if ((w
->cursor
.y
< this_scroll_margin
14000 && CHARPOS (start
) > BEGV
)
14001 /* Old redisplay didn't take scroll margin into account at the bottom,
14002 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
14003 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
14004 ? cursor_height
+ this_scroll_margin
14005 : 1)) > it
.last_visible_y
)
14007 w
->cursor
.vpos
= -1;
14008 clear_glyph_matrix (w
->desired_matrix
);
14013 /* Scroll the display. Do it before changing the current matrix so
14014 that xterm.c doesn't get confused about where the cursor glyph is
14016 if (dy
&& run
.height
)
14020 if (FRAME_WINDOW_P (f
))
14022 rif
->update_window_begin_hook (w
);
14023 rif
->clear_window_mouse_face (w
);
14024 rif
->scroll_run_hook (w
, &run
);
14025 rif
->update_window_end_hook (w
, 0, 0);
14029 /* Terminal frame. In this case, dvpos gives the number of
14030 lines to scroll by; dvpos < 0 means scroll up. */
14031 int first_unchanged_at_end_vpos
14032 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
14033 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
14034 int end
= (WINDOW_TOP_EDGE_LINE (w
)
14035 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
14036 + window_internal_height (w
));
14038 /* Perform the operation on the screen. */
14041 /* Scroll last_unchanged_at_beg_row to the end of the
14042 window down dvpos lines. */
14043 set_terminal_window (end
);
14045 /* On dumb terminals delete dvpos lines at the end
14046 before inserting dvpos empty lines. */
14047 if (!scroll_region_ok
)
14048 ins_del_lines (end
- dvpos
, -dvpos
);
14050 /* Insert dvpos empty lines in front of
14051 last_unchanged_at_beg_row. */
14052 ins_del_lines (from
, dvpos
);
14054 else if (dvpos
< 0)
14056 /* Scroll up last_unchanged_at_beg_vpos to the end of
14057 the window to last_unchanged_at_beg_vpos - |dvpos|. */
14058 set_terminal_window (end
);
14060 /* Delete dvpos lines in front of
14061 last_unchanged_at_beg_vpos. ins_del_lines will set
14062 the cursor to the given vpos and emit |dvpos| delete
14064 ins_del_lines (from
+ dvpos
, dvpos
);
14066 /* On a dumb terminal insert dvpos empty lines at the
14068 if (!scroll_region_ok
)
14069 ins_del_lines (end
+ dvpos
, -dvpos
);
14072 set_terminal_window (0);
14078 /* Shift reused rows of the current matrix to the right position.
14079 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
14081 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14082 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
14085 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
14086 bottom_vpos
, dvpos
);
14087 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
14090 else if (dvpos
> 0)
14092 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
14093 bottom_vpos
, dvpos
);
14094 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
14095 first_unchanged_at_end_vpos
+ dvpos
, 0);
14098 /* For frame-based redisplay, make sure that current frame and window
14099 matrix are in sync with respect to glyph memory. */
14100 if (!FRAME_WINDOW_P (f
))
14101 sync_frame_with_window_matrix_rows (w
);
14103 /* Adjust buffer positions in reused rows. */
14105 increment_matrix_positions (current_matrix
,
14106 first_unchanged_at_end_vpos
+ dvpos
,
14107 bottom_vpos
, delta
, delta_bytes
);
14109 /* Adjust Y positions. */
14111 shift_glyph_matrix (w
, current_matrix
,
14112 first_unchanged_at_end_vpos
+ dvpos
,
14115 if (first_unchanged_at_end_row
)
14117 first_unchanged_at_end_row
+= dvpos
;
14118 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
14119 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
14120 first_unchanged_at_end_row
= NULL
;
14123 /* If scrolling up, there may be some lines to display at the end of
14125 last_text_row_at_end
= NULL
;
14128 /* Scrolling up can leave for example a partially visible line
14129 at the end of the window to be redisplayed. */
14130 /* Set last_row to the glyph row in the current matrix where the
14131 window end line is found. It has been moved up or down in
14132 the matrix by dvpos. */
14133 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
14134 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
14136 /* If last_row is the window end line, it should display text. */
14137 xassert (last_row
->displays_text_p
);
14139 /* If window end line was partially visible before, begin
14140 displaying at that line. Otherwise begin displaying with the
14141 line following it. */
14142 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
14144 init_to_row_start (&it
, w
, last_row
);
14145 it
.vpos
= last_vpos
;
14146 it
.current_y
= last_row
->y
;
14150 init_to_row_end (&it
, w
, last_row
);
14151 it
.vpos
= 1 + last_vpos
;
14152 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
14156 /* We may start in a continuation line. If so, we have to
14157 get the right continuation_lines_width and current_x. */
14158 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
14159 it
.hpos
= it
.current_x
= 0;
14161 /* Display the rest of the lines at the window end. */
14162 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
14163 while (it
.current_y
< it
.last_visible_y
14164 && !fonts_changed_p
)
14166 /* Is it always sure that the display agrees with lines in
14167 the current matrix? I don't think so, so we mark rows
14168 displayed invalid in the current matrix by setting their
14169 enabled_p flag to zero. */
14170 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
14171 if (display_line (&it
))
14172 last_text_row_at_end
= it
.glyph_row
- 1;
14176 /* Update window_end_pos and window_end_vpos. */
14177 if (first_unchanged_at_end_row
14178 && !last_text_row_at_end
)
14180 /* Window end line if one of the preserved rows from the current
14181 matrix. Set row to the last row displaying text in current
14182 matrix starting at first_unchanged_at_end_row, after
14184 xassert (first_unchanged_at_end_row
->displays_text_p
);
14185 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
14186 first_unchanged_at_end_row
);
14187 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
14189 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14190 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14192 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
14193 xassert (w
->window_end_bytepos
>= 0);
14194 IF_DEBUG (debug_method_add (w
, "A"));
14196 else if (last_text_row_at_end
)
14199 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
14200 w
->window_end_bytepos
14201 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
14203 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
14204 xassert (w
->window_end_bytepos
>= 0);
14205 IF_DEBUG (debug_method_add (w
, "B"));
14207 else if (last_text_row
)
14209 /* We have displayed either to the end of the window or at the
14210 end of the window, i.e. the last row with text is to be found
14211 in the desired matrix. */
14213 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14214 w
->window_end_bytepos
14215 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14217 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
14218 xassert (w
->window_end_bytepos
>= 0);
14220 else if (first_unchanged_at_end_row
== NULL
14221 && last_text_row
== NULL
14222 && last_text_row_at_end
== NULL
)
14224 /* Displayed to end of window, but no line containing text was
14225 displayed. Lines were deleted at the end of the window. */
14226 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
14227 int vpos
= XFASTINT (w
->window_end_vpos
);
14228 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
14229 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
14232 row
== NULL
&& vpos
>= first_vpos
;
14233 --vpos
, --current_row
, --desired_row
)
14235 if (desired_row
->enabled_p
)
14237 if (desired_row
->displays_text_p
)
14240 else if (current_row
->displays_text_p
)
14244 xassert (row
!= NULL
);
14245 w
->window_end_vpos
= make_number (vpos
+ 1);
14246 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
14247 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
14248 xassert (w
->window_end_bytepos
>= 0);
14249 IF_DEBUG (debug_method_add (w
, "C"));
14254 #if 0 /* This leads to problems, for instance when the cursor is
14255 at ZV, and the cursor line displays no text. */
14256 /* Disable rows below what's displayed in the window. This makes
14257 debugging easier. */
14258 enable_glyph_matrix_rows (current_matrix
,
14259 XFASTINT (w
->window_end_vpos
) + 1,
14263 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
14264 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
14266 /* Record that display has not been completed. */
14267 w
->window_end_valid
= Qnil
;
14268 w
->desired_matrix
->no_scrolling_p
= 1;
14276 /***********************************************************************
14277 More debugging support
14278 ***********************************************************************/
14282 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
14283 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
14284 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
14287 /* Dump the contents of glyph matrix MATRIX on stderr.
14289 GLYPHS 0 means don't show glyph contents.
14290 GLYPHS 1 means show glyphs in short form
14291 GLYPHS > 1 means show glyphs in long form. */
14294 dump_glyph_matrix (matrix
, glyphs
)
14295 struct glyph_matrix
*matrix
;
14299 for (i
= 0; i
< matrix
->nrows
; ++i
)
14300 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
14304 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
14305 the glyph row and area where the glyph comes from. */
14308 dump_glyph (row
, glyph
, area
)
14309 struct glyph_row
*row
;
14310 struct glyph
*glyph
;
14313 if (glyph
->type
== CHAR_GLYPH
)
14316 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14317 glyph
- row
->glyphs
[TEXT_AREA
],
14320 (BUFFERP (glyph
->object
)
14322 : (STRINGP (glyph
->object
)
14325 glyph
->pixel_width
,
14327 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
14331 glyph
->left_box_line_p
,
14332 glyph
->right_box_line_p
);
14334 else if (glyph
->type
== STRETCH_GLYPH
)
14337 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14338 glyph
- row
->glyphs
[TEXT_AREA
],
14341 (BUFFERP (glyph
->object
)
14343 : (STRINGP (glyph
->object
)
14346 glyph
->pixel_width
,
14350 glyph
->left_box_line_p
,
14351 glyph
->right_box_line_p
);
14353 else if (glyph
->type
== IMAGE_GLYPH
)
14356 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
14357 glyph
- row
->glyphs
[TEXT_AREA
],
14360 (BUFFERP (glyph
->object
)
14362 : (STRINGP (glyph
->object
)
14365 glyph
->pixel_width
,
14369 glyph
->left_box_line_p
,
14370 glyph
->right_box_line_p
);
14375 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
14376 GLYPHS 0 means don't show glyph contents.
14377 GLYPHS 1 means show glyphs in short form
14378 GLYPHS > 1 means show glyphs in long form. */
14381 dump_glyph_row (row
, vpos
, glyphs
)
14382 struct glyph_row
*row
;
14387 fprintf (stderr
, "Row Start End Used oEI><\\CTZFesm X Y W H V A P\n");
14388 fprintf (stderr
, "======================================================================\n");
14390 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
14391 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
14393 MATRIX_ROW_START_CHARPOS (row
),
14394 MATRIX_ROW_END_CHARPOS (row
),
14395 row
->used
[TEXT_AREA
],
14396 row
->contains_overlapping_glyphs_p
,
14398 row
->truncated_on_left_p
,
14399 row
->truncated_on_right_p
,
14401 MATRIX_ROW_CONTINUATION_LINE_P (row
),
14402 row
->displays_text_p
,
14405 row
->ends_in_middle_of_char_p
,
14406 row
->starts_in_middle_of_char_p
,
14412 row
->visible_height
,
14415 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
14416 row
->end
.overlay_string_index
,
14417 row
->continuation_lines_width
);
14418 fprintf (stderr
, "%9d %5d\n",
14419 CHARPOS (row
->start
.string_pos
),
14420 CHARPOS (row
->end
.string_pos
));
14421 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
14422 row
->end
.dpvec_index
);
14429 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14431 struct glyph
*glyph
= row
->glyphs
[area
];
14432 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
14434 /* Glyph for a line end in text. */
14435 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
14438 if (glyph
< glyph_end
)
14439 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
14441 for (; glyph
< glyph_end
; ++glyph
)
14442 dump_glyph (row
, glyph
, area
);
14445 else if (glyphs
== 1)
14449 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14451 char *s
= (char *) alloca (row
->used
[area
] + 1);
14454 for (i
= 0; i
< row
->used
[area
]; ++i
)
14456 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
14457 if (glyph
->type
== CHAR_GLYPH
14458 && glyph
->u
.ch
< 0x80
14459 && glyph
->u
.ch
>= ' ')
14460 s
[i
] = glyph
->u
.ch
;
14466 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
14472 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
14473 Sdump_glyph_matrix
, 0, 1, "p",
14474 doc
: /* Dump the current matrix of the selected window to stderr.
14475 Shows contents of glyph row structures. With non-nil
14476 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
14477 glyphs in short form, otherwise show glyphs in long form. */)
14479 Lisp_Object glyphs
;
14481 struct window
*w
= XWINDOW (selected_window
);
14482 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14484 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
14485 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
14486 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
14487 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
14488 fprintf (stderr
, "=============================================\n");
14489 dump_glyph_matrix (w
->current_matrix
,
14490 NILP (glyphs
) ? 0 : XINT (glyphs
));
14495 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
14496 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
14499 struct frame
*f
= XFRAME (selected_frame
);
14500 dump_glyph_matrix (f
->current_matrix
, 1);
14505 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
14506 doc
: /* Dump glyph row ROW to stderr.
14507 GLYPH 0 means don't dump glyphs.
14508 GLYPH 1 means dump glyphs in short form.
14509 GLYPH > 1 or omitted means dump glyphs in long form. */)
14511 Lisp_Object row
, glyphs
;
14513 struct glyph_matrix
*matrix
;
14516 CHECK_NUMBER (row
);
14517 matrix
= XWINDOW (selected_window
)->current_matrix
;
14519 if (vpos
>= 0 && vpos
< matrix
->nrows
)
14520 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
14522 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14527 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
14528 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
14529 GLYPH 0 means don't dump glyphs.
14530 GLYPH 1 means dump glyphs in short form.
14531 GLYPH > 1 or omitted means dump glyphs in long form. */)
14533 Lisp_Object row
, glyphs
;
14535 struct frame
*sf
= SELECTED_FRAME ();
14536 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
14539 CHECK_NUMBER (row
);
14541 if (vpos
>= 0 && vpos
< m
->nrows
)
14542 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
14543 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
14548 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
14549 doc
: /* Toggle tracing of redisplay.
14550 With ARG, turn tracing on if and only if ARG is positive. */)
14555 trace_redisplay_p
= !trace_redisplay_p
;
14558 arg
= Fprefix_numeric_value (arg
);
14559 trace_redisplay_p
= XINT (arg
) > 0;
14566 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
14567 doc
: /* Like `format', but print result to stderr.
14568 usage: (trace-to-stderr STRING &rest OBJECTS) */)
14573 Lisp_Object s
= Fformat (nargs
, args
);
14574 fprintf (stderr
, "%s", SDATA (s
));
14578 #endif /* GLYPH_DEBUG */
14582 /***********************************************************************
14583 Building Desired Matrix Rows
14584 ***********************************************************************/
14586 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
14587 Used for non-window-redisplay windows, and for windows w/o left fringe. */
14589 static struct glyph_row
*
14590 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
14592 Lisp_Object overlay_arrow_string
;
14594 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
14595 struct buffer
*buffer
= XBUFFER (w
->buffer
);
14596 struct buffer
*old
= current_buffer
;
14597 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
14598 int arrow_len
= SCHARS (overlay_arrow_string
);
14599 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
14600 const unsigned char *p
;
14603 int n_glyphs_before
;
14605 set_buffer_temp (buffer
);
14606 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
14607 it
.glyph_row
->used
[TEXT_AREA
] = 0;
14608 SET_TEXT_POS (it
.position
, 0, 0);
14610 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
14612 while (p
< arrow_end
)
14614 Lisp_Object face
, ilisp
;
14616 /* Get the next character. */
14618 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
14620 it
.c
= *p
, it
.len
= 1;
14623 /* Get its face. */
14624 ilisp
= make_number (p
- arrow_string
);
14625 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
14626 it
.face_id
= compute_char_face (f
, it
.c
, face
);
14628 /* Compute its width, get its glyphs. */
14629 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
14630 SET_TEXT_POS (it
.position
, -1, -1);
14631 PRODUCE_GLYPHS (&it
);
14633 /* If this character doesn't fit any more in the line, we have
14634 to remove some glyphs. */
14635 if (it
.current_x
> it
.last_visible_x
)
14637 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
14642 set_buffer_temp (old
);
14643 return it
.glyph_row
;
14647 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
14648 glyphs are only inserted for terminal frames since we can't really
14649 win with truncation glyphs when partially visible glyphs are
14650 involved. Which glyphs to insert is determined by
14651 produce_special_glyphs. */
14654 insert_left_trunc_glyphs (it
)
14657 struct it truncate_it
;
14658 struct glyph
*from
, *end
, *to
, *toend
;
14660 xassert (!FRAME_WINDOW_P (it
->f
));
14662 /* Get the truncation glyphs. */
14664 truncate_it
.current_x
= 0;
14665 truncate_it
.face_id
= DEFAULT_FACE_ID
;
14666 truncate_it
.glyph_row
= &scratch_glyph_row
;
14667 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
14668 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
14669 truncate_it
.object
= make_number (0);
14670 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
14672 /* Overwrite glyphs from IT with truncation glyphs. */
14673 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14674 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
14675 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
14676 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
14681 /* There may be padding glyphs left over. Overwrite them too. */
14682 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
14684 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
14690 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
14694 /* Compute the pixel height and width of IT->glyph_row.
14696 Most of the time, ascent and height of a display line will be equal
14697 to the max_ascent and max_height values of the display iterator
14698 structure. This is not the case if
14700 1. We hit ZV without displaying anything. In this case, max_ascent
14701 and max_height will be zero.
14703 2. We have some glyphs that don't contribute to the line height.
14704 (The glyph row flag contributes_to_line_height_p is for future
14705 pixmap extensions).
14707 The first case is easily covered by using default values because in
14708 these cases, the line height does not really matter, except that it
14709 must not be zero. */
14712 compute_line_metrics (it
)
14715 struct glyph_row
*row
= it
->glyph_row
;
14718 if (FRAME_WINDOW_P (it
->f
))
14720 int i
, min_y
, max_y
;
14722 /* The line may consist of one space only, that was added to
14723 place the cursor on it. If so, the row's height hasn't been
14725 if (row
->height
== 0)
14727 if (it
->max_ascent
+ it
->max_descent
== 0)
14728 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
14729 row
->ascent
= it
->max_ascent
;
14730 row
->height
= it
->max_ascent
+ it
->max_descent
;
14731 row
->phys_ascent
= it
->max_phys_ascent
;
14732 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
14733 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
14736 /* Compute the width of this line. */
14737 row
->pixel_width
= row
->x
;
14738 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
14739 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
14741 xassert (row
->pixel_width
>= 0);
14742 xassert (row
->ascent
>= 0 && row
->height
> 0);
14744 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
14745 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
14747 /* If first line's physical ascent is larger than its logical
14748 ascent, use the physical ascent, and make the row taller.
14749 This makes accented characters fully visible. */
14750 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
14751 && row
->phys_ascent
> row
->ascent
)
14753 row
->height
+= row
->phys_ascent
- row
->ascent
;
14754 row
->ascent
= row
->phys_ascent
;
14757 /* Compute how much of the line is visible. */
14758 row
->visible_height
= row
->height
;
14760 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
14761 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
14763 if (row
->y
< min_y
)
14764 row
->visible_height
-= min_y
- row
->y
;
14765 if (row
->y
+ row
->height
> max_y
)
14766 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14770 row
->pixel_width
= row
->used
[TEXT_AREA
];
14771 if (row
->continued_p
)
14772 row
->pixel_width
-= it
->continuation_pixel_width
;
14773 else if (row
->truncated_on_right_p
)
14774 row
->pixel_width
-= it
->truncation_pixel_width
;
14775 row
->ascent
= row
->phys_ascent
= 0;
14776 row
->height
= row
->phys_height
= row
->visible_height
= 1;
14777 row
->extra_line_spacing
= 0;
14780 /* Compute a hash code for this row. */
14782 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
14783 for (i
= 0; i
< row
->used
[area
]; ++i
)
14784 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
14785 + row
->glyphs
[area
][i
].u
.val
14786 + row
->glyphs
[area
][i
].face_id
14787 + row
->glyphs
[area
][i
].padding_p
14788 + (row
->glyphs
[area
][i
].type
<< 2));
14790 it
->max_ascent
= it
->max_descent
= 0;
14791 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
14795 /* Append one space to the glyph row of iterator IT if doing a
14796 window-based redisplay. The space has the same face as
14797 IT->face_id. Value is non-zero if a space was added.
14799 This function is called to make sure that there is always one glyph
14800 at the end of a glyph row that the cursor can be set on under
14801 window-systems. (If there weren't such a glyph we would not know
14802 how wide and tall a box cursor should be displayed).
14804 At the same time this space let's a nicely handle clearing to the
14805 end of the line if the row ends in italic text. */
14808 append_space_for_newline (it
, default_face_p
)
14810 int default_face_p
;
14812 if (FRAME_WINDOW_P (it
->f
))
14814 int n
= it
->glyph_row
->used
[TEXT_AREA
];
14816 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
14817 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
14819 /* Save some values that must not be changed.
14820 Must save IT->c and IT->len because otherwise
14821 ITERATOR_AT_END_P wouldn't work anymore after
14822 append_space_for_newline has been called. */
14823 enum display_element_type saved_what
= it
->what
;
14824 int saved_c
= it
->c
, saved_len
= it
->len
;
14825 int saved_x
= it
->current_x
;
14826 int saved_face_id
= it
->face_id
;
14827 struct text_pos saved_pos
;
14828 Lisp_Object saved_object
;
14831 saved_object
= it
->object
;
14832 saved_pos
= it
->position
;
14834 it
->what
= IT_CHARACTER
;
14835 bzero (&it
->position
, sizeof it
->position
);
14836 it
->object
= make_number (0);
14840 if (default_face_p
)
14841 it
->face_id
= DEFAULT_FACE_ID
;
14842 else if (it
->face_before_selective_p
)
14843 it
->face_id
= it
->saved_face_id
;
14844 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
14845 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
14847 PRODUCE_GLYPHS (it
);
14849 it
->override_ascent
= -1;
14850 it
->constrain_row_ascent_descent_p
= 0;
14851 it
->current_x
= saved_x
;
14852 it
->object
= saved_object
;
14853 it
->position
= saved_pos
;
14854 it
->what
= saved_what
;
14855 it
->face_id
= saved_face_id
;
14856 it
->len
= saved_len
;
14866 /* Extend the face of the last glyph in the text area of IT->glyph_row
14867 to the end of the display line. Called from display_line.
14868 If the glyph row is empty, add a space glyph to it so that we
14869 know the face to draw. Set the glyph row flag fill_line_p. */
14872 extend_face_to_end_of_line (it
)
14876 struct frame
*f
= it
->f
;
14878 /* If line is already filled, do nothing. */
14879 if (it
->current_x
>= it
->last_visible_x
)
14882 /* Face extension extends the background and box of IT->face_id
14883 to the end of the line. If the background equals the background
14884 of the frame, we don't have to do anything. */
14885 if (it
->face_before_selective_p
)
14886 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
14888 face
= FACE_FROM_ID (f
, it
->face_id
);
14890 if (FRAME_WINDOW_P (f
)
14891 && face
->box
== FACE_NO_BOX
14892 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
14896 /* Set the glyph row flag indicating that the face of the last glyph
14897 in the text area has to be drawn to the end of the text area. */
14898 it
->glyph_row
->fill_line_p
= 1;
14900 /* If current character of IT is not ASCII, make sure we have the
14901 ASCII face. This will be automatically undone the next time
14902 get_next_display_element returns a multibyte character. Note
14903 that the character will always be single byte in unibyte text. */
14904 if (!SINGLE_BYTE_CHAR_P (it
->c
))
14906 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
14909 if (FRAME_WINDOW_P (f
))
14911 /* If the row is empty, add a space with the current face of IT,
14912 so that we know which face to draw. */
14913 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
14915 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
14916 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
14917 it
->glyph_row
->used
[TEXT_AREA
] = 1;
14922 /* Save some values that must not be changed. */
14923 int saved_x
= it
->current_x
;
14924 struct text_pos saved_pos
;
14925 Lisp_Object saved_object
;
14926 enum display_element_type saved_what
= it
->what
;
14927 int saved_face_id
= it
->face_id
;
14929 saved_object
= it
->object
;
14930 saved_pos
= it
->position
;
14932 it
->what
= IT_CHARACTER
;
14933 bzero (&it
->position
, sizeof it
->position
);
14934 it
->object
= make_number (0);
14937 it
->face_id
= face
->id
;
14939 PRODUCE_GLYPHS (it
);
14941 while (it
->current_x
<= it
->last_visible_x
)
14942 PRODUCE_GLYPHS (it
);
14944 /* Don't count these blanks really. It would let us insert a left
14945 truncation glyph below and make us set the cursor on them, maybe. */
14946 it
->current_x
= saved_x
;
14947 it
->object
= saved_object
;
14948 it
->position
= saved_pos
;
14949 it
->what
= saved_what
;
14950 it
->face_id
= saved_face_id
;
14955 /* Value is non-zero if text starting at CHARPOS in current_buffer is
14956 trailing whitespace. */
14959 trailing_whitespace_p (charpos
)
14962 int bytepos
= CHAR_TO_BYTE (charpos
);
14965 while (bytepos
< ZV_BYTE
14966 && (c
= FETCH_CHAR (bytepos
),
14967 c
== ' ' || c
== '\t'))
14970 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
14972 if (bytepos
!= PT_BYTE
)
14979 /* Highlight trailing whitespace, if any, in ROW. */
14982 highlight_trailing_whitespace (f
, row
)
14984 struct glyph_row
*row
;
14986 int used
= row
->used
[TEXT_AREA
];
14990 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
14991 struct glyph
*glyph
= start
+ used
- 1;
14993 /* Skip over glyphs inserted to display the cursor at the
14994 end of a line, for extending the face of the last glyph
14995 to the end of the line on terminals, and for truncation
14996 and continuation glyphs. */
14997 while (glyph
>= start
14998 && glyph
->type
== CHAR_GLYPH
14999 && INTEGERP (glyph
->object
))
15002 /* If last glyph is a space or stretch, and it's trailing
15003 whitespace, set the face of all trailing whitespace glyphs in
15004 IT->glyph_row to `trailing-whitespace'. */
15006 && BUFFERP (glyph
->object
)
15007 && (glyph
->type
== STRETCH_GLYPH
15008 || (glyph
->type
== CHAR_GLYPH
15009 && glyph
->u
.ch
== ' '))
15010 && trailing_whitespace_p (glyph
->charpos
))
15012 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0, 0);
15016 while (glyph
>= start
15017 && BUFFERP (glyph
->object
)
15018 && (glyph
->type
== STRETCH_GLYPH
15019 || (glyph
->type
== CHAR_GLYPH
15020 && glyph
->u
.ch
== ' ')))
15021 (glyph
--)->face_id
= face_id
;
15027 /* Value is non-zero if glyph row ROW in window W should be
15028 used to hold the cursor. */
15031 cursor_row_p (w
, row
)
15033 struct glyph_row
*row
;
15035 int cursor_row_p
= 1;
15037 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
15039 /* If the row ends with a newline from a string, we don't want
15040 the cursor there, but we still want it at the start of the
15041 string if the string starts in this row.
15042 If the row is continued it doesn't end in a newline. */
15043 if (CHARPOS (row
->end
.string_pos
) >= 0)
15044 cursor_row_p
= (row
->continued_p
15045 || PT
>= MATRIX_ROW_START_CHARPOS (row
));
15046 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15048 /* If the row ends in middle of a real character,
15049 and the line is continued, we want the cursor here.
15050 That's because MATRIX_ROW_END_CHARPOS would equal
15051 PT if PT is before the character. */
15052 if (!row
->ends_in_ellipsis_p
)
15053 cursor_row_p
= row
->continued_p
;
15055 /* If the row ends in an ellipsis, then
15056 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
15057 We want that position to be displayed after the ellipsis. */
15060 /* If the row ends at ZV, display the cursor at the end of that
15061 row instead of at the start of the row below. */
15062 else if (row
->ends_at_zv_p
)
15068 return cursor_row_p
;
15072 /* Construct the glyph row IT->glyph_row in the desired matrix of
15073 IT->w from text at the current position of IT. See dispextern.h
15074 for an overview of struct it. Value is non-zero if
15075 IT->glyph_row displays text, as opposed to a line displaying ZV
15082 struct glyph_row
*row
= it
->glyph_row
;
15083 Lisp_Object overlay_arrow_string
;
15085 /* We always start displaying at hpos zero even if hscrolled. */
15086 xassert (it
->hpos
== 0 && it
->current_x
== 0);
15088 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
15089 >= it
->w
->desired_matrix
->nrows
)
15091 it
->w
->nrows_scale_factor
++;
15092 fonts_changed_p
= 1;
15096 /* Is IT->w showing the region? */
15097 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
15099 /* Clear the result glyph row and enable it. */
15100 prepare_desired_row (row
);
15102 row
->y
= it
->current_y
;
15103 row
->start
= it
->start
;
15104 row
->continuation_lines_width
= it
->continuation_lines_width
;
15105 row
->displays_text_p
= 1;
15106 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
15107 it
->starts_in_middle_of_char_p
= 0;
15109 /* Arrange the overlays nicely for our purposes. Usually, we call
15110 display_line on only one line at a time, in which case this
15111 can't really hurt too much, or we call it on lines which appear
15112 one after another in the buffer, in which case all calls to
15113 recenter_overlay_lists but the first will be pretty cheap. */
15114 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
15116 /* Move over display elements that are not visible because we are
15117 hscrolled. This may stop at an x-position < IT->first_visible_x
15118 if the first glyph is partially visible or if we hit a line end. */
15119 if (it
->current_x
< it
->first_visible_x
)
15121 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
15122 MOVE_TO_POS
| MOVE_TO_X
);
15125 /* Get the initial row height. This is either the height of the
15126 text hscrolled, if there is any, or zero. */
15127 row
->ascent
= it
->max_ascent
;
15128 row
->height
= it
->max_ascent
+ it
->max_descent
;
15129 row
->phys_ascent
= it
->max_phys_ascent
;
15130 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
15131 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
15133 /* Loop generating characters. The loop is left with IT on the next
15134 character to display. */
15137 int n_glyphs_before
, hpos_before
, x_before
;
15139 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
15141 /* Retrieve the next thing to display. Value is zero if end of
15143 if (!get_next_display_element (it
))
15145 /* Maybe add a space at the end of this line that is used to
15146 display the cursor there under X. Set the charpos of the
15147 first glyph of blank lines not corresponding to any text
15149 #ifdef HAVE_WINDOW_SYSTEM
15150 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15151 row
->exact_window_width_line_p
= 1;
15153 #endif /* HAVE_WINDOW_SYSTEM */
15154 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
15155 || row
->used
[TEXT_AREA
] == 0)
15157 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
15158 row
->displays_text_p
= 0;
15160 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
15161 && (!MINI_WINDOW_P (it
->w
)
15162 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
15163 row
->indicate_empty_line_p
= 1;
15166 it
->continuation_lines_width
= 0;
15167 row
->ends_at_zv_p
= 1;
15171 /* Now, get the metrics of what we want to display. This also
15172 generates glyphs in `row' (which is IT->glyph_row). */
15173 n_glyphs_before
= row
->used
[TEXT_AREA
];
15176 /* Remember the line height so far in case the next element doesn't
15177 fit on the line. */
15178 if (!it
->truncate_lines_p
)
15180 ascent
= it
->max_ascent
;
15181 descent
= it
->max_descent
;
15182 phys_ascent
= it
->max_phys_ascent
;
15183 phys_descent
= it
->max_phys_descent
;
15186 PRODUCE_GLYPHS (it
);
15188 /* If this display element was in marginal areas, continue with
15190 if (it
->area
!= TEXT_AREA
)
15192 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15193 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15194 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15195 row
->phys_height
= max (row
->phys_height
,
15196 it
->max_phys_ascent
+ it
->max_phys_descent
);
15197 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15198 it
->max_extra_line_spacing
);
15199 set_iterator_to_next (it
, 1);
15203 /* Does the display element fit on the line? If we truncate
15204 lines, we should draw past the right edge of the window. If
15205 we don't truncate, we want to stop so that we can display the
15206 continuation glyph before the right margin. If lines are
15207 continued, there are two possible strategies for characters
15208 resulting in more than 1 glyph (e.g. tabs): Display as many
15209 glyphs as possible in this line and leave the rest for the
15210 continuation line, or display the whole element in the next
15211 line. Original redisplay did the former, so we do it also. */
15212 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
15213 hpos_before
= it
->hpos
;
15216 if (/* Not a newline. */
15218 /* Glyphs produced fit entirely in the line. */
15219 && it
->current_x
< it
->last_visible_x
)
15221 it
->hpos
+= nglyphs
;
15222 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15223 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15224 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15225 row
->phys_height
= max (row
->phys_height
,
15226 it
->max_phys_ascent
+ it
->max_phys_descent
);
15227 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15228 it
->max_extra_line_spacing
);
15229 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
15230 row
->x
= x
- it
->first_visible_x
;
15235 struct glyph
*glyph
;
15237 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
15239 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
15240 new_x
= x
+ glyph
->pixel_width
;
15242 if (/* Lines are continued. */
15243 !it
->truncate_lines_p
15244 && (/* Glyph doesn't fit on the line. */
15245 new_x
> it
->last_visible_x
15246 /* Or it fits exactly on a window system frame. */
15247 || (new_x
== it
->last_visible_x
15248 && FRAME_WINDOW_P (it
->f
))))
15250 /* End of a continued line. */
15253 || (new_x
== it
->last_visible_x
15254 && FRAME_WINDOW_P (it
->f
)))
15256 /* Current glyph is the only one on the line or
15257 fits exactly on the line. We must continue
15258 the line because we can't draw the cursor
15259 after the glyph. */
15260 row
->continued_p
= 1;
15261 it
->current_x
= new_x
;
15262 it
->continuation_lines_width
+= new_x
;
15264 if (i
== nglyphs
- 1)
15266 set_iterator_to_next (it
, 1);
15267 #ifdef HAVE_WINDOW_SYSTEM
15268 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15270 if (!get_next_display_element (it
))
15272 row
->exact_window_width_line_p
= 1;
15273 it
->continuation_lines_width
= 0;
15274 row
->continued_p
= 0;
15275 row
->ends_at_zv_p
= 1;
15277 else if (ITERATOR_AT_END_OF_LINE_P (it
))
15279 row
->continued_p
= 0;
15280 row
->exact_window_width_line_p
= 1;
15283 #endif /* HAVE_WINDOW_SYSTEM */
15286 else if (CHAR_GLYPH_PADDING_P (*glyph
)
15287 && !FRAME_WINDOW_P (it
->f
))
15289 /* A padding glyph that doesn't fit on this line.
15290 This means the whole character doesn't fit
15292 row
->used
[TEXT_AREA
] = n_glyphs_before
;
15294 /* Fill the rest of the row with continuation
15295 glyphs like in 20.x. */
15296 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
15297 < row
->glyphs
[1 + TEXT_AREA
])
15298 produce_special_glyphs (it
, IT_CONTINUATION
);
15300 row
->continued_p
= 1;
15301 it
->current_x
= x_before
;
15302 it
->continuation_lines_width
+= x_before
;
15304 /* Restore the height to what it was before the
15305 element not fitting on the line. */
15306 it
->max_ascent
= ascent
;
15307 it
->max_descent
= descent
;
15308 it
->max_phys_ascent
= phys_ascent
;
15309 it
->max_phys_descent
= phys_descent
;
15311 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
15313 /* A TAB that extends past the right edge of the
15314 window. This produces a single glyph on
15315 window system frames. We leave the glyph in
15316 this row and let it fill the row, but don't
15317 consume the TAB. */
15318 it
->continuation_lines_width
+= it
->last_visible_x
;
15319 row
->ends_in_middle_of_char_p
= 1;
15320 row
->continued_p
= 1;
15321 glyph
->pixel_width
= it
->last_visible_x
- x
;
15322 it
->starts_in_middle_of_char_p
= 1;
15326 /* Something other than a TAB that draws past
15327 the right edge of the window. Restore
15328 positions to values before the element. */
15329 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
15331 /* Display continuation glyphs. */
15332 if (!FRAME_WINDOW_P (it
->f
))
15333 produce_special_glyphs (it
, IT_CONTINUATION
);
15334 row
->continued_p
= 1;
15336 it
->continuation_lines_width
+= x
;
15338 if (nglyphs
> 1 && i
> 0)
15340 row
->ends_in_middle_of_char_p
= 1;
15341 it
->starts_in_middle_of_char_p
= 1;
15344 /* Restore the height to what it was before the
15345 element not fitting on the line. */
15346 it
->max_ascent
= ascent
;
15347 it
->max_descent
= descent
;
15348 it
->max_phys_ascent
= phys_ascent
;
15349 it
->max_phys_descent
= phys_descent
;
15354 else if (new_x
> it
->first_visible_x
)
15356 /* Increment number of glyphs actually displayed. */
15359 if (x
< it
->first_visible_x
)
15360 /* Glyph is partially visible, i.e. row starts at
15361 negative X position. */
15362 row
->x
= x
- it
->first_visible_x
;
15366 /* Glyph is completely off the left margin of the
15367 window. This should not happen because of the
15368 move_it_in_display_line at the start of this
15369 function, unless the text display area of the
15370 window is empty. */
15371 xassert (it
->first_visible_x
<= it
->last_visible_x
);
15375 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
15376 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
15377 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
15378 row
->phys_height
= max (row
->phys_height
,
15379 it
->max_phys_ascent
+ it
->max_phys_descent
);
15380 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
15381 it
->max_extra_line_spacing
);
15383 /* End of this display line if row is continued. */
15384 if (row
->continued_p
|| row
->ends_at_zv_p
)
15389 /* Is this a line end? If yes, we're also done, after making
15390 sure that a non-default face is extended up to the right
15391 margin of the window. */
15392 if (ITERATOR_AT_END_OF_LINE_P (it
))
15394 int used_before
= row
->used
[TEXT_AREA
];
15396 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
15398 #ifdef HAVE_WINDOW_SYSTEM
15399 /* Add a space at the end of the line that is used to
15400 display the cursor there. */
15401 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15402 append_space_for_newline (it
, 0);
15403 #endif /* HAVE_WINDOW_SYSTEM */
15405 /* Extend the face to the end of the line. */
15406 extend_face_to_end_of_line (it
);
15408 /* Make sure we have the position. */
15409 if (used_before
== 0)
15410 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
15412 /* Consume the line end. This skips over invisible lines. */
15413 set_iterator_to_next (it
, 1);
15414 it
->continuation_lines_width
= 0;
15418 /* Proceed with next display element. Note that this skips
15419 over lines invisible because of selective display. */
15420 set_iterator_to_next (it
, 1);
15422 /* If we truncate lines, we are done when the last displayed
15423 glyphs reach past the right margin of the window. */
15424 if (it
->truncate_lines_p
15425 && (FRAME_WINDOW_P (it
->f
)
15426 ? (it
->current_x
>= it
->last_visible_x
)
15427 : (it
->current_x
> it
->last_visible_x
)))
15429 /* Maybe add truncation glyphs. */
15430 if (!FRAME_WINDOW_P (it
->f
))
15434 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
15435 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
15438 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
15440 row
->used
[TEXT_AREA
] = i
;
15441 produce_special_glyphs (it
, IT_TRUNCATION
);
15444 #ifdef HAVE_WINDOW_SYSTEM
15447 /* Don't truncate if we can overflow newline into fringe. */
15448 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
15450 if (!get_next_display_element (it
))
15452 it
->continuation_lines_width
= 0;
15453 row
->ends_at_zv_p
= 1;
15454 row
->exact_window_width_line_p
= 1;
15457 if (ITERATOR_AT_END_OF_LINE_P (it
))
15459 row
->exact_window_width_line_p
= 1;
15460 goto at_end_of_line
;
15464 #endif /* HAVE_WINDOW_SYSTEM */
15466 row
->truncated_on_right_p
= 1;
15467 it
->continuation_lines_width
= 0;
15468 reseat_at_next_visible_line_start (it
, 0);
15469 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
15470 it
->hpos
= hpos_before
;
15471 it
->current_x
= x_before
;
15476 /* If line is not empty and hscrolled, maybe insert truncation glyphs
15477 at the left window margin. */
15478 if (it
->first_visible_x
15479 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
15481 if (!FRAME_WINDOW_P (it
->f
))
15482 insert_left_trunc_glyphs (it
);
15483 row
->truncated_on_left_p
= 1;
15486 /* If the start of this line is the overlay arrow-position, then
15487 mark this glyph row as the one containing the overlay arrow.
15488 This is clearly a mess with variable size fonts. It would be
15489 better to let it be displayed like cursors under X. */
15490 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
15491 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
15492 !NILP (overlay_arrow_string
)))
15494 /* Overlay arrow in window redisplay is a fringe bitmap. */
15495 if (STRINGP (overlay_arrow_string
))
15497 struct glyph_row
*arrow_row
15498 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
15499 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
15500 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
15501 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
15502 struct glyph
*p2
, *end
;
15504 /* Copy the arrow glyphs. */
15505 while (glyph
< arrow_end
)
15508 /* Throw away padding glyphs. */
15510 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15511 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
15517 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
15522 xassert (INTEGERP (overlay_arrow_string
));
15523 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
15525 overlay_arrow_seen
= 1;
15528 /* Compute pixel dimensions of this line. */
15529 compute_line_metrics (it
);
15531 /* Remember the position at which this line ends. */
15532 row
->end
= it
->current
;
15534 /* Record whether this row ends inside an ellipsis. */
15535 row
->ends_in_ellipsis_p
15536 = (it
->method
== GET_FROM_DISPLAY_VECTOR
15537 && it
->ellipsis_p
);
15539 /* Save fringe bitmaps in this row. */
15540 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
15541 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
15542 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
15543 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
15545 it
->left_user_fringe_bitmap
= 0;
15546 it
->left_user_fringe_face_id
= 0;
15547 it
->right_user_fringe_bitmap
= 0;
15548 it
->right_user_fringe_face_id
= 0;
15550 /* Maybe set the cursor. */
15551 if (it
->w
->cursor
.vpos
< 0
15552 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
15553 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15554 && cursor_row_p (it
->w
, row
))
15555 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
15557 /* Highlight trailing whitespace. */
15558 if (!NILP (Vshow_trailing_whitespace
))
15559 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
15561 /* Prepare for the next line. This line starts horizontally at (X
15562 HPOS) = (0 0). Vertical positions are incremented. As a
15563 convenience for the caller, IT->glyph_row is set to the next
15565 it
->current_x
= it
->hpos
= 0;
15566 it
->current_y
+= row
->height
;
15569 it
->start
= it
->current
;
15570 return row
->displays_text_p
;
15575 /***********************************************************************
15577 ***********************************************************************/
15579 /* Redisplay the menu bar in the frame for window W.
15581 The menu bar of X frames that don't have X toolkit support is
15582 displayed in a special window W->frame->menu_bar_window.
15584 The menu bar of terminal frames is treated specially as far as
15585 glyph matrices are concerned. Menu bar lines are not part of
15586 windows, so the update is done directly on the frame matrix rows
15587 for the menu bar. */
15590 display_menu_bar (w
)
15593 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15598 /* Don't do all this for graphical frames. */
15600 if (!NILP (Vwindow_system
))
15603 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
15608 if (FRAME_MAC_P (f
))
15612 #ifdef USE_X_TOOLKIT
15613 xassert (!FRAME_WINDOW_P (f
));
15614 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
15615 it
.first_visible_x
= 0;
15616 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15617 #else /* not USE_X_TOOLKIT */
15618 if (FRAME_WINDOW_P (f
))
15620 /* Menu bar lines are displayed in the desired matrix of the
15621 dummy window menu_bar_window. */
15622 struct window
*menu_w
;
15623 xassert (WINDOWP (f
->menu_bar_window
));
15624 menu_w
= XWINDOW (f
->menu_bar_window
);
15625 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
15627 it
.first_visible_x
= 0;
15628 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
15632 /* This is a TTY frame, i.e. character hpos/vpos are used as
15634 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
15636 it
.first_visible_x
= 0;
15637 it
.last_visible_x
= FRAME_COLS (f
);
15639 #endif /* not USE_X_TOOLKIT */
15641 if (! mode_line_inverse_video
)
15642 /* Force the menu-bar to be displayed in the default face. */
15643 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15645 /* Clear all rows of the menu bar. */
15646 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
15648 struct glyph_row
*row
= it
.glyph_row
+ i
;
15649 clear_glyph_row (row
);
15650 row
->enabled_p
= 1;
15651 row
->full_width_p
= 1;
15654 /* Display all items of the menu bar. */
15655 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
15656 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
15658 Lisp_Object string
;
15660 /* Stop at nil string. */
15661 string
= AREF (items
, i
+ 1);
15665 /* Remember where item was displayed. */
15666 AREF (items
, i
+ 3) = make_number (it
.hpos
);
15668 /* Display the item, pad with one space. */
15669 if (it
.current_x
< it
.last_visible_x
)
15670 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
15671 SCHARS (string
) + 1, 0, 0, -1);
15674 /* Fill out the line with spaces. */
15675 if (it
.current_x
< it
.last_visible_x
)
15676 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
15678 /* Compute the total height of the lines. */
15679 compute_line_metrics (&it
);
15684 /***********************************************************************
15686 ***********************************************************************/
15688 /* Redisplay mode lines in the window tree whose root is WINDOW. If
15689 FORCE is non-zero, redisplay mode lines unconditionally.
15690 Otherwise, redisplay only mode lines that are garbaged. Value is
15691 the number of windows whose mode lines were redisplayed. */
15694 redisplay_mode_lines (window
, force
)
15695 Lisp_Object window
;
15700 while (!NILP (window
))
15702 struct window
*w
= XWINDOW (window
);
15704 if (WINDOWP (w
->hchild
))
15705 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
15706 else if (WINDOWP (w
->vchild
))
15707 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
15709 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
15710 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
15712 struct text_pos lpoint
;
15713 struct buffer
*old
= current_buffer
;
15715 /* Set the window's buffer for the mode line display. */
15716 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15717 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15719 /* Point refers normally to the selected window. For any
15720 other window, set up appropriate value. */
15721 if (!EQ (window
, selected_window
))
15723 struct text_pos pt
;
15725 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
15726 if (CHARPOS (pt
) < BEGV
)
15727 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
15728 else if (CHARPOS (pt
) > (ZV
- 1))
15729 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
15731 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
15734 /* Display mode lines. */
15735 clear_glyph_matrix (w
->desired_matrix
);
15736 if (display_mode_lines (w
))
15739 w
->must_be_updated_p
= 1;
15742 /* Restore old settings. */
15743 set_buffer_internal_1 (old
);
15744 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
15754 /* Display the mode and/or top line of window W. Value is the number
15755 of mode lines displayed. */
15758 display_mode_lines (w
)
15761 Lisp_Object old_selected_window
, old_selected_frame
;
15764 old_selected_frame
= selected_frame
;
15765 selected_frame
= w
->frame
;
15766 old_selected_window
= selected_window
;
15767 XSETWINDOW (selected_window
, w
);
15769 /* These will be set while the mode line specs are processed. */
15770 line_number_displayed
= 0;
15771 w
->column_number_displayed
= Qnil
;
15773 if (WINDOW_WANTS_MODELINE_P (w
))
15775 struct window
*sel_w
= XWINDOW (old_selected_window
);
15777 /* Select mode line face based on the real selected window. */
15778 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
15779 current_buffer
->mode_line_format
);
15783 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15785 display_mode_line (w
, HEADER_LINE_FACE_ID
,
15786 current_buffer
->header_line_format
);
15790 selected_frame
= old_selected_frame
;
15791 selected_window
= old_selected_window
;
15796 /* Display mode or top line of window W. FACE_ID specifies which line
15797 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
15798 FORMAT is the mode line format to display. Value is the pixel
15799 height of the mode line displayed. */
15802 display_mode_line (w
, face_id
, format
)
15804 enum face_id face_id
;
15805 Lisp_Object format
;
15809 int count
= SPECPDL_INDEX ();
15811 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
15812 prepare_desired_row (it
.glyph_row
);
15814 it
.glyph_row
->mode_line_p
= 1;
15816 if (! mode_line_inverse_video
)
15817 /* Force the mode-line to be displayed in the default face. */
15818 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
15820 record_unwind_protect (unwind_format_mode_line
,
15821 format_mode_line_unwind_data (NULL
));
15823 mode_line_target
= MODE_LINE_DISPLAY
;
15825 /* Temporarily make frame's keyboard the current kboard so that
15826 kboard-local variables in the mode_line_format will get the right
15828 push_frame_kboard (it
.f
);
15829 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
15830 pop_frame_kboard ();
15832 unbind_to (count
, Qnil
);
15834 /* Fill up with spaces. */
15835 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
15837 compute_line_metrics (&it
);
15838 it
.glyph_row
->full_width_p
= 1;
15839 it
.glyph_row
->continued_p
= 0;
15840 it
.glyph_row
->truncated_on_left_p
= 0;
15841 it
.glyph_row
->truncated_on_right_p
= 0;
15843 /* Make a 3D mode-line have a shadow at its right end. */
15844 face
= FACE_FROM_ID (it
.f
, face_id
);
15845 extend_face_to_end_of_line (&it
);
15846 if (face
->box
!= FACE_NO_BOX
)
15848 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
15849 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
15850 last
->right_box_line_p
= 1;
15853 return it
.glyph_row
->height
;
15856 /* Contribute ELT to the mode line for window IT->w. How it
15857 translates into text depends on its data type.
15859 IT describes the display environment in which we display, as usual.
15861 DEPTH is the depth in recursion. It is used to prevent
15862 infinite recursion here.
15864 FIELD_WIDTH is the number of characters the display of ELT should
15865 occupy in the mode line, and PRECISION is the maximum number of
15866 characters to display from ELT's representation. See
15867 display_string for details.
15869 Returns the hpos of the end of the text generated by ELT.
15871 PROPS is a property list to add to any string we encounter.
15873 If RISKY is nonzero, remove (disregard) any properties in any string
15874 we encounter, and ignore :eval and :propertize.
15876 The global variable `mode_line_target' determines whether the
15877 output is passed to `store_mode_line_noprop',
15878 `store_mode_line_string', or `display_string'. */
15881 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
15884 int field_width
, precision
;
15885 Lisp_Object elt
, props
;
15888 int n
= 0, field
, prec
;
15893 elt
= build_string ("*too-deep*");
15897 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
15901 /* A string: output it and check for %-constructs within it. */
15903 const unsigned char *this, *lisp_string
;
15905 if (!NILP (props
) || risky
)
15907 Lisp_Object oprops
, aelt
;
15908 oprops
= Ftext_properties_at (make_number (0), elt
);
15910 /* If the starting string's properties are not what
15911 we want, translate the string. Also, if the string
15912 is risky, do that anyway. */
15914 if (NILP (Fequal (props
, oprops
)) || risky
)
15916 /* If the starting string has properties,
15917 merge the specified ones onto the existing ones. */
15918 if (! NILP (oprops
) && !risky
)
15922 oprops
= Fcopy_sequence (oprops
);
15924 while (CONSP (tem
))
15926 oprops
= Fplist_put (oprops
, XCAR (tem
),
15927 XCAR (XCDR (tem
)));
15928 tem
= XCDR (XCDR (tem
));
15933 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
15934 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
15936 mode_line_proptrans_alist
15937 = Fcons (aelt
, Fdelq (aelt
, mode_line_proptrans_alist
));
15944 elt
= Fcopy_sequence (elt
);
15945 Fset_text_properties (make_number (0), Flength (elt
),
15947 /* Add this item to mode_line_proptrans_alist. */
15948 mode_line_proptrans_alist
15949 = Fcons (Fcons (elt
, props
),
15950 mode_line_proptrans_alist
);
15951 /* Truncate mode_line_proptrans_alist
15952 to at most 50 elements. */
15953 tem
= Fnthcdr (make_number (50),
15954 mode_line_proptrans_alist
);
15956 XSETCDR (tem
, Qnil
);
15961 this = SDATA (elt
);
15962 lisp_string
= this;
15966 prec
= precision
- n
;
15967 switch (mode_line_target
)
15969 case MODE_LINE_NOPROP
:
15970 case MODE_LINE_TITLE
:
15971 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
15973 case MODE_LINE_STRING
:
15974 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
15976 case MODE_LINE_DISPLAY
:
15977 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
15978 0, prec
, 0, STRING_MULTIBYTE (elt
));
15985 while ((precision
<= 0 || n
< precision
)
15987 && (mode_line_target
!= MODE_LINE_DISPLAY
15988 || it
->current_x
< it
->last_visible_x
))
15990 const unsigned char *last
= this;
15992 /* Advance to end of string or next format specifier. */
15993 while ((c
= *this++) != '\0' && c
!= '%')
15996 if (this - 1 != last
)
15998 int nchars
, nbytes
;
16000 /* Output to end of string or up to '%'. Field width
16001 is length of string. Don't output more than
16002 PRECISION allows us. */
16005 prec
= c_string_width (last
, this - last
, precision
- n
,
16008 switch (mode_line_target
)
16010 case MODE_LINE_NOPROP
:
16011 case MODE_LINE_TITLE
:
16012 n
+= store_mode_line_noprop (last
, 0, prec
);
16014 case MODE_LINE_STRING
:
16016 int bytepos
= last
- lisp_string
;
16017 int charpos
= string_byte_to_char (elt
, bytepos
);
16018 int endpos
= (precision
<= 0
16019 ? string_byte_to_char (elt
,
16020 this - lisp_string
)
16021 : charpos
+ nchars
);
16023 n
+= store_mode_line_string (NULL
,
16024 Fsubstring (elt
, make_number (charpos
),
16025 make_number (endpos
)),
16029 case MODE_LINE_DISPLAY
:
16031 int bytepos
= last
- lisp_string
;
16032 int charpos
= string_byte_to_char (elt
, bytepos
);
16033 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
16035 STRING_MULTIBYTE (elt
));
16040 else /* c == '%' */
16042 const unsigned char *percent_position
= this;
16044 /* Get the specified minimum width. Zero means
16047 while ((c
= *this++) >= '0' && c
<= '9')
16048 field
= field
* 10 + c
- '0';
16050 /* Don't pad beyond the total padding allowed. */
16051 if (field_width
- n
> 0 && field
> field_width
- n
)
16052 field
= field_width
- n
;
16054 /* Note that either PRECISION <= 0 or N < PRECISION. */
16055 prec
= precision
- n
;
16058 n
+= display_mode_element (it
, depth
, field
, prec
,
16059 Vglobal_mode_string
, props
,
16064 int bytepos
, charpos
;
16065 unsigned char *spec
;
16067 bytepos
= percent_position
- lisp_string
;
16068 charpos
= (STRING_MULTIBYTE (elt
)
16069 ? string_byte_to_char (elt
, bytepos
)
16073 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
16075 switch (mode_line_target
)
16077 case MODE_LINE_NOPROP
:
16078 case MODE_LINE_TITLE
:
16079 n
+= store_mode_line_noprop (spec
, field
, prec
);
16081 case MODE_LINE_STRING
:
16083 int len
= strlen (spec
);
16084 Lisp_Object tem
= make_string (spec
, len
);
16085 props
= Ftext_properties_at (make_number (charpos
), elt
);
16086 /* Should only keep face property in props */
16087 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
16090 case MODE_LINE_DISPLAY
:
16092 int nglyphs_before
, nwritten
;
16094 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
16095 nwritten
= display_string (spec
, Qnil
, elt
,
16100 /* Assign to the glyphs written above the
16101 string where the `%x' came from, position
16105 struct glyph
*glyph
16106 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
16110 for (i
= 0; i
< nwritten
; ++i
)
16112 glyph
[i
].object
= elt
;
16113 glyph
[i
].charpos
= charpos
;
16130 /* A symbol: process the value of the symbol recursively
16131 as if it appeared here directly. Avoid error if symbol void.
16132 Special case: if value of symbol is a string, output the string
16135 register Lisp_Object tem
;
16137 /* If the variable is not marked as risky to set
16138 then its contents are risky to use. */
16139 if (NILP (Fget (elt
, Qrisky_local_variable
)))
16142 tem
= Fboundp (elt
);
16145 tem
= Fsymbol_value (elt
);
16146 /* If value is a string, output that string literally:
16147 don't check for % within it. */
16151 if (!EQ (tem
, elt
))
16153 /* Give up right away for nil or t. */
16163 register Lisp_Object car
, tem
;
16165 /* A cons cell: five distinct cases.
16166 If first element is :eval or :propertize, do something special.
16167 If first element is a string or a cons, process all the elements
16168 and effectively concatenate them.
16169 If first element is a negative number, truncate displaying cdr to
16170 at most that many characters. If positive, pad (with spaces)
16171 to at least that many characters.
16172 If first element is a symbol, process the cadr or caddr recursively
16173 according to whether the symbol's value is non-nil or nil. */
16175 if (EQ (car
, QCeval
))
16177 /* An element of the form (:eval FORM) means evaluate FORM
16178 and use the result as mode line elements. */
16183 if (CONSP (XCDR (elt
)))
16186 spec
= safe_eval (XCAR (XCDR (elt
)));
16187 n
+= display_mode_element (it
, depth
, field_width
- n
,
16188 precision
- n
, spec
, props
,
16192 else if (EQ (car
, QCpropertize
))
16194 /* An element of the form (:propertize ELT PROPS...)
16195 means display ELT but applying properties PROPS. */
16200 if (CONSP (XCDR (elt
)))
16201 n
+= display_mode_element (it
, depth
, field_width
- n
,
16202 precision
- n
, XCAR (XCDR (elt
)),
16203 XCDR (XCDR (elt
)), risky
);
16205 else if (SYMBOLP (car
))
16207 tem
= Fboundp (car
);
16211 /* elt is now the cdr, and we know it is a cons cell.
16212 Use its car if CAR has a non-nil value. */
16215 tem
= Fsymbol_value (car
);
16222 /* Symbol's value is nil (or symbol is unbound)
16223 Get the cddr of the original list
16224 and if possible find the caddr and use that. */
16228 else if (!CONSP (elt
))
16233 else if (INTEGERP (car
))
16235 register int lim
= XINT (car
);
16239 /* Negative int means reduce maximum width. */
16240 if (precision
<= 0)
16243 precision
= min (precision
, -lim
);
16247 /* Padding specified. Don't let it be more than
16248 current maximum. */
16250 lim
= min (precision
, lim
);
16252 /* If that's more padding than already wanted, queue it.
16253 But don't reduce padding already specified even if
16254 that is beyond the current truncation point. */
16255 field_width
= max (lim
, field_width
);
16259 else if (STRINGP (car
) || CONSP (car
))
16261 register int limit
= 50;
16262 /* Limit is to protect against circular lists. */
16265 && (precision
<= 0 || n
< precision
))
16267 n
+= display_mode_element (it
, depth
,
16268 /* Do padding only after the last
16269 element in the list. */
16270 (! CONSP (XCDR (elt
))
16273 precision
- n
, XCAR (elt
),
16283 elt
= build_string ("*invalid*");
16287 /* Pad to FIELD_WIDTH. */
16288 if (field_width
> 0 && n
< field_width
)
16290 switch (mode_line_target
)
16292 case MODE_LINE_NOPROP
:
16293 case MODE_LINE_TITLE
:
16294 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
16296 case MODE_LINE_STRING
:
16297 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
16299 case MODE_LINE_DISPLAY
:
16300 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
16309 /* Store a mode-line string element in mode_line_string_list.
16311 If STRING is non-null, display that C string. Otherwise, the Lisp
16312 string LISP_STRING is displayed.
16314 FIELD_WIDTH is the minimum number of output glyphs to produce.
16315 If STRING has fewer characters than FIELD_WIDTH, pad to the right
16316 with spaces. FIELD_WIDTH <= 0 means don't pad.
16318 PRECISION is the maximum number of characters to output from
16319 STRING. PRECISION <= 0 means don't truncate the string.
16321 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
16322 properties to the string.
16324 PROPS are the properties to add to the string.
16325 The mode_line_string_face face property is always added to the string.
16329 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
16331 Lisp_Object lisp_string
;
16340 if (string
!= NULL
)
16342 len
= strlen (string
);
16343 if (precision
> 0 && len
> precision
)
16345 lisp_string
= make_string (string
, len
);
16347 props
= mode_line_string_face_prop
;
16348 else if (!NILP (mode_line_string_face
))
16350 Lisp_Object face
= Fplist_get (props
, Qface
);
16351 props
= Fcopy_sequence (props
);
16353 face
= mode_line_string_face
;
16355 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16356 props
= Fplist_put (props
, Qface
, face
);
16358 Fadd_text_properties (make_number (0), make_number (len
),
16359 props
, lisp_string
);
16363 len
= XFASTINT (Flength (lisp_string
));
16364 if (precision
> 0 && len
> precision
)
16367 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
16370 if (!NILP (mode_line_string_face
))
16374 props
= Ftext_properties_at (make_number (0), lisp_string
);
16375 face
= Fplist_get (props
, Qface
);
16377 face
= mode_line_string_face
;
16379 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
16380 props
= Fcons (Qface
, Fcons (face
, Qnil
));
16382 lisp_string
= Fcopy_sequence (lisp_string
);
16385 Fadd_text_properties (make_number (0), make_number (len
),
16386 props
, lisp_string
);
16391 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16395 if (field_width
> len
)
16397 field_width
-= len
;
16398 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
16400 Fadd_text_properties (make_number (0), make_number (field_width
),
16401 props
, lisp_string
);
16402 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
16410 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
16412 doc
: /* Format a string out of a mode line format specification.
16413 First arg FORMAT specifies the mode line format (see `mode-line-format'
16414 for details) to use.
16416 Optional second arg FACE specifies the face property to put
16417 on all characters for which no face is specified.
16418 t means whatever face the window's mode line currently uses
16419 \(either `mode-line' or `mode-line-inactive', depending).
16420 nil means the default is no face property.
16421 If FACE is an integer, the value string has no text properties.
16423 Optional third and fourth args WINDOW and BUFFER specify the window
16424 and buffer to use as the context for the formatting (defaults
16425 are the selected window and the window's buffer). */)
16426 (format
, face
, window
, buffer
)
16427 Lisp_Object format
, face
, window
, buffer
;
16432 struct buffer
*old_buffer
= NULL
;
16434 int no_props
= INTEGERP (face
);
16435 int count
= SPECPDL_INDEX ();
16437 int string_start
= 0;
16440 window
= selected_window
;
16441 CHECK_WINDOW (window
);
16442 w
= XWINDOW (window
);
16445 buffer
= w
->buffer
;
16446 CHECK_BUFFER (buffer
);
16449 return build_string ("");
16457 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
16458 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0, 0);
16462 face_id
= DEFAULT_FACE_ID
;
16464 if (XBUFFER (buffer
) != current_buffer
)
16465 old_buffer
= current_buffer
;
16467 record_unwind_protect (unwind_format_mode_line
,
16468 format_mode_line_unwind_data (old_buffer
));
16471 set_buffer_internal_1 (XBUFFER (buffer
));
16473 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
16477 mode_line_target
= MODE_LINE_NOPROP
;
16478 mode_line_string_face_prop
= Qnil
;
16479 mode_line_string_list
= Qnil
;
16480 string_start
= MODE_LINE_NOPROP_LEN (0);
16484 mode_line_target
= MODE_LINE_STRING
;
16485 mode_line_string_list
= Qnil
;
16486 mode_line_string_face
= face
;
16487 mode_line_string_face_prop
16488 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
16491 push_frame_kboard (it
.f
);
16492 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
16493 pop_frame_kboard ();
16497 len
= MODE_LINE_NOPROP_LEN (string_start
);
16498 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
16502 mode_line_string_list
= Fnreverse (mode_line_string_list
);
16503 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
16504 make_string ("", 0));
16507 unbind_to (count
, Qnil
);
16511 /* Write a null-terminated, right justified decimal representation of
16512 the positive integer D to BUF using a minimal field width WIDTH. */
16515 pint2str (buf
, width
, d
)
16516 register char *buf
;
16517 register int width
;
16520 register char *p
= buf
;
16528 *p
++ = d
% 10 + '0';
16533 for (width
-= (int) (p
- buf
); width
> 0; --width
)
16544 /* Write a null-terminated, right justified decimal and "human
16545 readable" representation of the nonnegative integer D to BUF using
16546 a minimal field width WIDTH. D should be smaller than 999.5e24. */
16548 static const char power_letter
[] =
16562 pint2hrstr (buf
, width
, d
)
16567 /* We aim to represent the nonnegative integer D as
16568 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
16571 /* -1 means: do not use TENTHS. */
16575 /* Length of QUOTIENT.TENTHS as a string. */
16581 if (1000 <= quotient
)
16583 /* Scale to the appropriate EXPONENT. */
16586 remainder
= quotient
% 1000;
16590 while (1000 <= quotient
);
16592 /* Round to nearest and decide whether to use TENTHS or not. */
16595 tenths
= remainder
/ 100;
16596 if (50 <= remainder
% 100)
16603 if (quotient
== 10)
16611 if (500 <= remainder
)
16613 if (quotient
< 999)
16624 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
16625 if (tenths
== -1 && quotient
<= 99)
16632 p
= psuffix
= buf
+ max (width
, length
);
16634 /* Print EXPONENT. */
16636 *psuffix
++ = power_letter
[exponent
];
16639 /* Print TENTHS. */
16642 *--p
= '0' + tenths
;
16646 /* Print QUOTIENT. */
16649 int digit
= quotient
% 10;
16650 *--p
= '0' + digit
;
16652 while ((quotient
/= 10) != 0);
16654 /* Print leading spaces. */
16659 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
16660 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
16661 type of CODING_SYSTEM. Return updated pointer into BUF. */
16663 static unsigned char invalid_eol_type
[] = "(*invalid*)";
16666 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
16667 Lisp_Object coding_system
;
16668 register char *buf
;
16672 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
16673 const unsigned char *eol_str
;
16675 /* The EOL conversion we are using. */
16676 Lisp_Object eoltype
;
16678 val
= Fget (coding_system
, Qcoding_system
);
16681 if (!VECTORP (val
)) /* Not yet decided. */
16686 eoltype
= eol_mnemonic_undecided
;
16687 /* Don't mention EOL conversion if it isn't decided. */
16691 Lisp_Object eolvalue
;
16693 eolvalue
= Fget (coding_system
, Qeol_type
);
16696 *buf
++ = XFASTINT (AREF (val
, 1));
16700 /* The EOL conversion that is normal on this system. */
16702 if (NILP (eolvalue
)) /* Not yet decided. */
16703 eoltype
= eol_mnemonic_undecided
;
16704 else if (VECTORP (eolvalue
)) /* Not yet decided. */
16705 eoltype
= eol_mnemonic_undecided
;
16706 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
16707 eoltype
= (XFASTINT (eolvalue
) == 0
16708 ? eol_mnemonic_unix
16709 : (XFASTINT (eolvalue
) == 1
16710 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
16716 /* Mention the EOL conversion if it is not the usual one. */
16717 if (STRINGP (eoltype
))
16719 eol_str
= SDATA (eoltype
);
16720 eol_str_len
= SBYTES (eoltype
);
16722 else if (INTEGERP (eoltype
)
16723 && CHAR_VALID_P (XINT (eoltype
), 0))
16725 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
16726 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
16731 eol_str
= invalid_eol_type
;
16732 eol_str_len
= sizeof (invalid_eol_type
) - 1;
16734 bcopy (eol_str
, buf
, eol_str_len
);
16735 buf
+= eol_str_len
;
16741 /* Return a string for the output of a mode line %-spec for window W,
16742 generated by character C. PRECISION >= 0 means don't return a
16743 string longer than that value. FIELD_WIDTH > 0 means pad the
16744 string returned with spaces to that value. Return 1 in *MULTIBYTE
16745 if the result is multibyte text.
16747 Note we operate on the current buffer for most purposes,
16748 the exception being w->base_line_pos. */
16750 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
16753 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
16756 int field_width
, precision
;
16760 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16761 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
16762 struct buffer
*b
= current_buffer
;
16770 if (!NILP (b
->read_only
))
16772 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16777 /* This differs from %* only for a modified read-only buffer. */
16778 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16780 if (!NILP (b
->read_only
))
16785 /* This differs from %* in ignoring read-only-ness. */
16786 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
16798 if (command_loop_level
> 5)
16800 p
= decode_mode_spec_buf
;
16801 for (i
= 0; i
< command_loop_level
; i
++)
16804 return decode_mode_spec_buf
;
16812 if (command_loop_level
> 5)
16814 p
= decode_mode_spec_buf
;
16815 for (i
= 0; i
< command_loop_level
; i
++)
16818 return decode_mode_spec_buf
;
16825 /* Let lots_of_dashes be a string of infinite length. */
16826 if (mode_line_target
== MODE_LINE_NOPROP
||
16827 mode_line_target
== MODE_LINE_STRING
)
16829 if (field_width
<= 0
16830 || field_width
> sizeof (lots_of_dashes
))
16832 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
16833 decode_mode_spec_buf
[i
] = '-';
16834 decode_mode_spec_buf
[i
] = '\0';
16835 return decode_mode_spec_buf
;
16838 return lots_of_dashes
;
16847 int col
= (int) current_column (); /* iftc */
16848 w
->column_number_displayed
= make_number (col
);
16849 pint2str (decode_mode_spec_buf
, field_width
, col
);
16850 return decode_mode_spec_buf
;
16854 /* %F displays the frame name. */
16855 if (!NILP (f
->title
))
16856 return (char *) SDATA (f
->title
);
16857 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
16858 return (char *) SDATA (f
->name
);
16867 int size
= ZV
- BEGV
;
16868 pint2str (decode_mode_spec_buf
, field_width
, size
);
16869 return decode_mode_spec_buf
;
16874 int size
= ZV
- BEGV
;
16875 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
16876 return decode_mode_spec_buf
;
16881 int startpos
= XMARKER (w
->start
)->charpos
;
16882 int startpos_byte
= marker_byte_position (w
->start
);
16883 int line
, linepos
, linepos_byte
, topline
;
16885 int height
= WINDOW_TOTAL_LINES (w
);
16887 /* If we decided that this buffer isn't suitable for line numbers,
16888 don't forget that too fast. */
16889 if (EQ (w
->base_line_pos
, w
->buffer
))
16891 /* But do forget it, if the window shows a different buffer now. */
16892 else if (BUFFERP (w
->base_line_pos
))
16893 w
->base_line_pos
= Qnil
;
16895 /* If the buffer is very big, don't waste time. */
16896 if (INTEGERP (Vline_number_display_limit
)
16897 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
16899 w
->base_line_pos
= Qnil
;
16900 w
->base_line_number
= Qnil
;
16904 if (!NILP (w
->base_line_number
)
16905 && !NILP (w
->base_line_pos
)
16906 && XFASTINT (w
->base_line_pos
) <= startpos
)
16908 line
= XFASTINT (w
->base_line_number
);
16909 linepos
= XFASTINT (w
->base_line_pos
);
16910 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
16915 linepos
= BUF_BEGV (b
);
16916 linepos_byte
= BUF_BEGV_BYTE (b
);
16919 /* Count lines from base line to window start position. */
16920 nlines
= display_count_lines (linepos
, linepos_byte
,
16924 topline
= nlines
+ line
;
16926 /* Determine a new base line, if the old one is too close
16927 or too far away, or if we did not have one.
16928 "Too close" means it's plausible a scroll-down would
16929 go back past it. */
16930 if (startpos
== BUF_BEGV (b
))
16932 w
->base_line_number
= make_number (topline
);
16933 w
->base_line_pos
= make_number (BUF_BEGV (b
));
16935 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
16936 || linepos
== BUF_BEGV (b
))
16938 int limit
= BUF_BEGV (b
);
16939 int limit_byte
= BUF_BEGV_BYTE (b
);
16941 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
16943 if (startpos
- distance
> limit
)
16945 limit
= startpos
- distance
;
16946 limit_byte
= CHAR_TO_BYTE (limit
);
16949 nlines
= display_count_lines (startpos
, startpos_byte
,
16951 - (height
* 2 + 30),
16953 /* If we couldn't find the lines we wanted within
16954 line_number_display_limit_width chars per line,
16955 give up on line numbers for this window. */
16956 if (position
== limit_byte
&& limit
== startpos
- distance
)
16958 w
->base_line_pos
= w
->buffer
;
16959 w
->base_line_number
= Qnil
;
16963 w
->base_line_number
= make_number (topline
- nlines
);
16964 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
16967 /* Now count lines from the start pos to point. */
16968 nlines
= display_count_lines (startpos
, startpos_byte
,
16969 PT_BYTE
, PT
, &junk
);
16971 /* Record that we did display the line number. */
16972 line_number_displayed
= 1;
16974 /* Make the string to show. */
16975 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
16976 return decode_mode_spec_buf
;
16979 char* p
= decode_mode_spec_buf
;
16980 int pad
= field_width
- 2;
16986 return decode_mode_spec_buf
;
16992 obj
= b
->mode_name
;
16996 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
17002 int pos
= marker_position (w
->start
);
17003 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17005 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
17007 if (pos
<= BUF_BEGV (b
))
17012 else if (pos
<= BUF_BEGV (b
))
17016 if (total
> 1000000)
17017 /* Do it differently for a large value, to avoid overflow. */
17018 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17020 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17021 /* We can't normally display a 3-digit number,
17022 so get us a 2-digit number that is close. */
17025 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17026 return decode_mode_spec_buf
;
17030 /* Display percentage of size above the bottom of the screen. */
17033 int toppos
= marker_position (w
->start
);
17034 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
17035 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
17037 if (botpos
>= BUF_ZV (b
))
17039 if (toppos
<= BUF_BEGV (b
))
17046 if (total
> 1000000)
17047 /* Do it differently for a large value, to avoid overflow. */
17048 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
17050 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
17051 /* We can't normally display a 3-digit number,
17052 so get us a 2-digit number that is close. */
17055 if (toppos
<= BUF_BEGV (b
))
17056 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
17058 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
17059 return decode_mode_spec_buf
;
17064 /* status of process */
17065 obj
= Fget_buffer_process (Fcurrent_buffer ());
17067 return "no process";
17068 #ifdef subprocesses
17069 obj
= Fsymbol_name (Fprocess_status (obj
));
17073 case 't': /* indicate TEXT or BINARY */
17074 #ifdef MODE_LINE_BINARY_TEXT
17075 return MODE_LINE_BINARY_TEXT (b
);
17081 /* coding-system (not including end-of-line format) */
17083 /* coding-system (including end-of-line type) */
17085 int eol_flag
= (c
== 'Z');
17086 char *p
= decode_mode_spec_buf
;
17088 if (! FRAME_WINDOW_P (f
))
17090 /* No need to mention EOL here--the terminal never needs
17091 to do EOL conversion. */
17092 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
17093 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
17095 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
17098 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
17099 #ifdef subprocesses
17100 obj
= Fget_buffer_process (Fcurrent_buffer ());
17101 if (PROCESSP (obj
))
17103 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
17105 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
17108 #endif /* subprocesses */
17111 return decode_mode_spec_buf
;
17117 *multibyte
= STRING_MULTIBYTE (obj
);
17118 return (char *) SDATA (obj
);
17125 /* Count up to COUNT lines starting from START / START_BYTE.
17126 But don't go beyond LIMIT_BYTE.
17127 Return the number of lines thus found (always nonnegative).
17129 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
17132 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
17133 int start
, start_byte
, limit_byte
, count
;
17136 register unsigned char *cursor
;
17137 unsigned char *base
;
17139 register int ceiling
;
17140 register unsigned char *ceiling_addr
;
17141 int orig_count
= count
;
17143 /* If we are not in selective display mode,
17144 check only for newlines. */
17145 int selective_display
= (!NILP (current_buffer
->selective_display
)
17146 && !INTEGERP (current_buffer
->selective_display
));
17150 while (start_byte
< limit_byte
)
17152 ceiling
= BUFFER_CEILING_OF (start_byte
);
17153 ceiling
= min (limit_byte
- 1, ceiling
);
17154 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
17155 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
17158 if (selective_display
)
17159 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
17162 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
17165 if (cursor
!= ceiling_addr
)
17169 start_byte
+= cursor
- base
+ 1;
17170 *byte_pos_ptr
= start_byte
;
17174 if (++cursor
== ceiling_addr
)
17180 start_byte
+= cursor
- base
;
17185 while (start_byte
> limit_byte
)
17187 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
17188 ceiling
= max (limit_byte
, ceiling
);
17189 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
17190 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
17193 if (selective_display
)
17194 while (--cursor
!= ceiling_addr
17195 && *cursor
!= '\n' && *cursor
!= 015)
17198 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
17201 if (cursor
!= ceiling_addr
)
17205 start_byte
+= cursor
- base
+ 1;
17206 *byte_pos_ptr
= start_byte
;
17207 /* When scanning backwards, we should
17208 not count the newline posterior to which we stop. */
17209 return - orig_count
- 1;
17215 /* Here we add 1 to compensate for the last decrement
17216 of CURSOR, which took it past the valid range. */
17217 start_byte
+= cursor
- base
+ 1;
17221 *byte_pos_ptr
= limit_byte
;
17224 return - orig_count
+ count
;
17225 return orig_count
- count
;
17231 /***********************************************************************
17233 ***********************************************************************/
17235 /* Display a NUL-terminated string, starting with index START.
17237 If STRING is non-null, display that C string. Otherwise, the Lisp
17238 string LISP_STRING is displayed.
17240 If FACE_STRING is not nil, FACE_STRING_POS is a position in
17241 FACE_STRING. Display STRING or LISP_STRING with the face at
17242 FACE_STRING_POS in FACE_STRING:
17244 Display the string in the environment given by IT, but use the
17245 standard display table, temporarily.
17247 FIELD_WIDTH is the minimum number of output glyphs to produce.
17248 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17249 with spaces. If STRING has more characters, more than FIELD_WIDTH
17250 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
17252 PRECISION is the maximum number of characters to output from
17253 STRING. PRECISION < 0 means don't truncate the string.
17255 This is roughly equivalent to printf format specifiers:
17257 FIELD_WIDTH PRECISION PRINTF
17258 ----------------------------------------
17264 MULTIBYTE zero means do not display multibyte chars, > 0 means do
17265 display them, and < 0 means obey the current buffer's value of
17266 enable_multibyte_characters.
17268 Value is the number of glyphs produced. */
17271 display_string (string
, lisp_string
, face_string
, face_string_pos
,
17272 start
, it
, field_width
, precision
, max_x
, multibyte
)
17273 unsigned char *string
;
17274 Lisp_Object lisp_string
;
17275 Lisp_Object face_string
;
17276 int face_string_pos
;
17279 int field_width
, precision
, max_x
;
17282 int hpos_at_start
= it
->hpos
;
17283 int saved_face_id
= it
->face_id
;
17284 struct glyph_row
*row
= it
->glyph_row
;
17286 /* Initialize the iterator IT for iteration over STRING beginning
17287 with index START. */
17288 reseat_to_string (it
, string
, lisp_string
, start
,
17289 precision
, field_width
, multibyte
);
17291 /* If displaying STRING, set up the face of the iterator
17292 from LISP_STRING, if that's given. */
17293 if (STRINGP (face_string
))
17299 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
17300 0, it
->region_beg_charpos
,
17301 it
->region_end_charpos
,
17302 &endptr
, it
->base_face_id
, 0);
17303 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
17304 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
17307 /* Set max_x to the maximum allowed X position. Don't let it go
17308 beyond the right edge of the window. */
17310 max_x
= it
->last_visible_x
;
17312 max_x
= min (max_x
, it
->last_visible_x
);
17314 /* Skip over display elements that are not visible. because IT->w is
17316 if (it
->current_x
< it
->first_visible_x
)
17317 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
17318 MOVE_TO_POS
| MOVE_TO_X
);
17320 row
->ascent
= it
->max_ascent
;
17321 row
->height
= it
->max_ascent
+ it
->max_descent
;
17322 row
->phys_ascent
= it
->max_phys_ascent
;
17323 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17324 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17326 /* This condition is for the case that we are called with current_x
17327 past last_visible_x. */
17328 while (it
->current_x
< max_x
)
17330 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
17332 /* Get the next display element. */
17333 if (!get_next_display_element (it
))
17336 /* Produce glyphs. */
17337 x_before
= it
->current_x
;
17338 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17339 PRODUCE_GLYPHS (it
);
17341 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
17344 while (i
< nglyphs
)
17346 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17348 if (!it
->truncate_lines_p
17349 && x
+ glyph
->pixel_width
> max_x
)
17351 /* End of continued line or max_x reached. */
17352 if (CHAR_GLYPH_PADDING_P (*glyph
))
17354 /* A wide character is unbreakable. */
17355 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
17356 it
->current_x
= x_before
;
17360 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17365 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
17367 /* Glyph is at least partially visible. */
17369 if (x
< it
->first_visible_x
)
17370 it
->glyph_row
->x
= x
- it
->first_visible_x
;
17374 /* Glyph is off the left margin of the display area.
17375 Should not happen. */
17379 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17380 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17381 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17382 row
->phys_height
= max (row
->phys_height
,
17383 it
->max_phys_ascent
+ it
->max_phys_descent
);
17384 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17385 it
->max_extra_line_spacing
);
17386 x
+= glyph
->pixel_width
;
17390 /* Stop if max_x reached. */
17394 /* Stop at line ends. */
17395 if (ITERATOR_AT_END_OF_LINE_P (it
))
17397 it
->continuation_lines_width
= 0;
17401 set_iterator_to_next (it
, 1);
17403 /* Stop if truncating at the right edge. */
17404 if (it
->truncate_lines_p
17405 && it
->current_x
>= it
->last_visible_x
)
17407 /* Add truncation mark, but don't do it if the line is
17408 truncated at a padding space. */
17409 if (IT_CHARPOS (*it
) < it
->string_nchars
)
17411 if (!FRAME_WINDOW_P (it
->f
))
17415 if (it
->current_x
> it
->last_visible_x
)
17417 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17418 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17420 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17422 row
->used
[TEXT_AREA
] = i
;
17423 produce_special_glyphs (it
, IT_TRUNCATION
);
17426 produce_special_glyphs (it
, IT_TRUNCATION
);
17428 it
->glyph_row
->truncated_on_right_p
= 1;
17434 /* Maybe insert a truncation at the left. */
17435 if (it
->first_visible_x
17436 && IT_CHARPOS (*it
) > 0)
17438 if (!FRAME_WINDOW_P (it
->f
))
17439 insert_left_trunc_glyphs (it
);
17440 it
->glyph_row
->truncated_on_left_p
= 1;
17443 it
->face_id
= saved_face_id
;
17445 /* Value is number of columns displayed. */
17446 return it
->hpos
- hpos_at_start
;
17451 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
17452 appears as an element of LIST or as the car of an element of LIST.
17453 If PROPVAL is a list, compare each element against LIST in that
17454 way, and return 1/2 if any element of PROPVAL is found in LIST.
17455 Otherwise return 0. This function cannot quit.
17456 The return value is 2 if the text is invisible but with an ellipsis
17457 and 1 if it's invisible and without an ellipsis. */
17460 invisible_p (propval
, list
)
17461 register Lisp_Object propval
;
17464 register Lisp_Object tail
, proptail
;
17466 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17468 register Lisp_Object tem
;
17470 if (EQ (propval
, tem
))
17472 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
17473 return NILP (XCDR (tem
)) ? 1 : 2;
17476 if (CONSP (propval
))
17478 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
17480 Lisp_Object propelt
;
17481 propelt
= XCAR (proptail
);
17482 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
17484 register Lisp_Object tem
;
17486 if (EQ (propelt
, tem
))
17488 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
17489 return NILP (XCDR (tem
)) ? 1 : 2;
17497 /* Calculate a width or height in pixels from a specification using
17498 the following elements:
17501 NUM - a (fractional) multiple of the default font width/height
17502 (NUM) - specifies exactly NUM pixels
17503 UNIT - a fixed number of pixels, see below.
17504 ELEMENT - size of a display element in pixels, see below.
17505 (NUM . SPEC) - equals NUM * SPEC
17506 (+ SPEC SPEC ...) - add pixel values
17507 (- SPEC SPEC ...) - subtract pixel values
17508 (- SPEC) - negate pixel value
17511 INT or FLOAT - a number constant
17512 SYMBOL - use symbol's (buffer local) variable binding.
17515 in - pixels per inch *)
17516 mm - pixels per 1/1000 meter *)
17517 cm - pixels per 1/100 meter *)
17518 width - width of current font in pixels.
17519 height - height of current font in pixels.
17521 *) using the ratio(s) defined in display-pixels-per-inch.
17525 left-fringe - left fringe width in pixels
17526 right-fringe - right fringe width in pixels
17528 left-margin - left margin width in pixels
17529 right-margin - right margin width in pixels
17531 scroll-bar - scroll-bar area width in pixels
17535 Pixels corresponding to 5 inches:
17538 Total width of non-text areas on left side of window (if scroll-bar is on left):
17539 '(space :width (+ left-fringe left-margin scroll-bar))
17541 Align to first text column (in header line):
17542 '(space :align-to 0)
17544 Align to middle of text area minus half the width of variable `my-image'
17545 containing a loaded image:
17546 '(space :align-to (0.5 . (- text my-image)))
17548 Width of left margin minus width of 1 character in the default font:
17549 '(space :width (- left-margin 1))
17551 Width of left margin minus width of 2 characters in the current font:
17552 '(space :width (- left-margin (2 . width)))
17554 Center 1 character over left-margin (in header line):
17555 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
17557 Different ways to express width of left fringe plus left margin minus one pixel:
17558 '(space :width (- (+ left-fringe left-margin) (1)))
17559 '(space :width (+ left-fringe left-margin (- (1))))
17560 '(space :width (+ left-fringe left-margin (-1)))
17564 #define NUMVAL(X) \
17565 ((INTEGERP (X) || FLOATP (X)) \
17570 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
17575 int width_p
, *align_to
;
17579 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
17580 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
17583 return OK_PIXELS (0);
17585 if (SYMBOLP (prop
))
17587 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
17589 char *unit
= SDATA (SYMBOL_NAME (prop
));
17591 if (unit
[0] == 'i' && unit
[1] == 'n')
17593 else if (unit
[0] == 'm' && unit
[1] == 'm')
17595 else if (unit
[0] == 'c' && unit
[1] == 'm')
17602 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
17603 || (CONSP (Vdisplay_pixels_per_inch
)
17605 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
17606 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
17608 return OK_PIXELS (ppi
/ pixels
);
17614 #ifdef HAVE_WINDOW_SYSTEM
17615 if (EQ (prop
, Qheight
))
17616 return OK_PIXELS (font
? FONT_HEIGHT ((XFontStruct
*)font
) : FRAME_LINE_HEIGHT (it
->f
));
17617 if (EQ (prop
, Qwidth
))
17618 return OK_PIXELS (font
? FONT_WIDTH ((XFontStruct
*)font
) : FRAME_COLUMN_WIDTH (it
->f
));
17620 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
17621 return OK_PIXELS (1);
17624 if (EQ (prop
, Qtext
))
17625 return OK_PIXELS (width_p
17626 ? window_box_width (it
->w
, TEXT_AREA
)
17627 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
17629 if (align_to
&& *align_to
< 0)
17632 if (EQ (prop
, Qleft
))
17633 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
17634 if (EQ (prop
, Qright
))
17635 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
17636 if (EQ (prop
, Qcenter
))
17637 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
17638 + window_box_width (it
->w
, TEXT_AREA
) / 2);
17639 if (EQ (prop
, Qleft_fringe
))
17640 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17641 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
17642 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
17643 if (EQ (prop
, Qright_fringe
))
17644 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17645 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17646 : window_box_right_offset (it
->w
, TEXT_AREA
));
17647 if (EQ (prop
, Qleft_margin
))
17648 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
17649 if (EQ (prop
, Qright_margin
))
17650 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
17651 if (EQ (prop
, Qscroll_bar
))
17652 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
17654 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
17655 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
17656 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
17661 if (EQ (prop
, Qleft_fringe
))
17662 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
17663 if (EQ (prop
, Qright_fringe
))
17664 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
17665 if (EQ (prop
, Qleft_margin
))
17666 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
17667 if (EQ (prop
, Qright_margin
))
17668 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
17669 if (EQ (prop
, Qscroll_bar
))
17670 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
17673 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
17676 if (INTEGERP (prop
) || FLOATP (prop
))
17678 int base_unit
= (width_p
17679 ? FRAME_COLUMN_WIDTH (it
->f
)
17680 : FRAME_LINE_HEIGHT (it
->f
));
17681 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
17686 Lisp_Object car
= XCAR (prop
);
17687 Lisp_Object cdr
= XCDR (prop
);
17691 #ifdef HAVE_WINDOW_SYSTEM
17692 if (valid_image_p (prop
))
17694 int id
= lookup_image (it
->f
, prop
);
17695 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
17697 return OK_PIXELS (width_p
? img
->width
: img
->height
);
17700 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
17706 while (CONSP (cdr
))
17708 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
17709 font
, width_p
, align_to
))
17712 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
17717 if (EQ (car
, Qminus
))
17719 return OK_PIXELS (pixels
);
17722 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
17725 if (INTEGERP (car
) || FLOATP (car
))
17728 pixels
= XFLOATINT (car
);
17730 return OK_PIXELS (pixels
);
17731 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
17732 font
, width_p
, align_to
))
17733 return OK_PIXELS (pixels
* fact
);
17744 /***********************************************************************
17746 ***********************************************************************/
17748 #ifdef HAVE_WINDOW_SYSTEM
17753 dump_glyph_string (s
)
17754 struct glyph_string
*s
;
17756 fprintf (stderr
, "glyph string\n");
17757 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
17758 s
->x
, s
->y
, s
->width
, s
->height
);
17759 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
17760 fprintf (stderr
, " hl = %d\n", s
->hl
);
17761 fprintf (stderr
, " left overhang = %d, right = %d\n",
17762 s
->left_overhang
, s
->right_overhang
);
17763 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
17764 fprintf (stderr
, " extends to end of line = %d\n",
17765 s
->extends_to_end_of_line_p
);
17766 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
17767 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
17770 #endif /* GLYPH_DEBUG */
17772 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
17773 of XChar2b structures for S; it can't be allocated in
17774 init_glyph_string because it must be allocated via `alloca'. W
17775 is the window on which S is drawn. ROW and AREA are the glyph row
17776 and area within the row from which S is constructed. START is the
17777 index of the first glyph structure covered by S. HL is a
17778 face-override for drawing S. */
17781 #define OPTIONAL_HDC(hdc) hdc,
17782 #define DECLARE_HDC(hdc) HDC hdc;
17783 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
17784 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
17787 #ifndef OPTIONAL_HDC
17788 #define OPTIONAL_HDC(hdc)
17789 #define DECLARE_HDC(hdc)
17790 #define ALLOCATE_HDC(hdc, f)
17791 #define RELEASE_HDC(hdc, f)
17795 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
17796 struct glyph_string
*s
;
17800 struct glyph_row
*row
;
17801 enum glyph_row_area area
;
17803 enum draw_glyphs_face hl
;
17805 bzero (s
, sizeof *s
);
17807 s
->f
= XFRAME (w
->frame
);
17811 s
->display
= FRAME_X_DISPLAY (s
->f
);
17812 s
->window
= FRAME_X_WINDOW (s
->f
);
17813 s
->char2b
= char2b
;
17817 s
->first_glyph
= row
->glyphs
[area
] + start
;
17818 s
->height
= row
->height
;
17819 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
17821 /* Display the internal border below the tool-bar window. */
17822 if (WINDOWP (s
->f
->tool_bar_window
)
17823 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
17824 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
17826 s
->ybase
= s
->y
+ row
->ascent
;
17830 /* Append the list of glyph strings with head H and tail T to the list
17831 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
17834 append_glyph_string_lists (head
, tail
, h
, t
)
17835 struct glyph_string
**head
, **tail
;
17836 struct glyph_string
*h
, *t
;
17850 /* Prepend the list of glyph strings with head H and tail T to the
17851 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
17855 prepend_glyph_string_lists (head
, tail
, h
, t
)
17856 struct glyph_string
**head
, **tail
;
17857 struct glyph_string
*h
, *t
;
17871 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
17872 Set *HEAD and *TAIL to the resulting list. */
17875 append_glyph_string (head
, tail
, s
)
17876 struct glyph_string
**head
, **tail
;
17877 struct glyph_string
*s
;
17879 s
->next
= s
->prev
= NULL
;
17880 append_glyph_string_lists (head
, tail
, s
, s
);
17884 /* Get face and two-byte form of character glyph GLYPH on frame F.
17885 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
17886 a pointer to a realized face that is ready for display. */
17888 static INLINE
struct face
*
17889 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
17891 struct glyph
*glyph
;
17897 xassert (glyph
->type
== CHAR_GLYPH
);
17898 face
= FACE_FROM_ID (f
, glyph
->face_id
);
17903 if (!glyph
->multibyte_p
)
17905 /* Unibyte case. We don't have to encode, but we have to make
17906 sure to use a face suitable for unibyte. */
17907 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17909 else if (glyph
->u
.ch
< 128
17910 && glyph
->face_id
< BASIC_FACE_ID_SENTINEL
)
17912 /* Case of ASCII in a face known to fit ASCII. */
17913 STORE_XCHAR2B (char2b
, 0, glyph
->u
.ch
);
17917 int c1
, c2
, charset
;
17919 /* Split characters into bytes. If c2 is -1 afterwards, C is
17920 really a one-byte character so that byte1 is zero. */
17921 SPLIT_CHAR (glyph
->u
.ch
, charset
, c1
, c2
);
17923 STORE_XCHAR2B (char2b
, c1
, c2
);
17925 STORE_XCHAR2B (char2b
, 0, c1
);
17927 /* Maybe encode the character in *CHAR2B. */
17928 if (charset
!= CHARSET_ASCII
)
17930 struct font_info
*font_info
17931 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
17934 = rif
->encode_char (glyph
->u
.ch
, char2b
, font_info
, two_byte_p
);
17938 /* Make sure X resources of the face are allocated. */
17939 xassert (face
!= NULL
);
17940 PREPARE_FACE_FOR_DISPLAY (f
, face
);
17945 /* Fill glyph string S with composition components specified by S->cmp.
17947 FACES is an array of faces for all components of this composition.
17948 S->gidx is the index of the first component for S.
17949 OVERLAPS_P non-zero means S should draw the foreground only, and
17950 use its physical height for clipping.
17952 Value is the index of a component not in S. */
17955 fill_composite_glyph_string (s
, faces
, overlaps_p
)
17956 struct glyph_string
*s
;
17957 struct face
**faces
;
17964 s
->for_overlaps_p
= overlaps_p
;
17966 s
->face
= faces
[s
->gidx
];
17967 s
->font
= s
->face
->font
;
17968 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
17970 /* For all glyphs of this composition, starting at the offset
17971 S->gidx, until we reach the end of the definition or encounter a
17972 glyph that requires the different face, add it to S. */
17974 for (i
= s
->gidx
+ 1; i
< s
->cmp
->glyph_len
&& faces
[i
] == s
->face
; ++i
)
17977 /* All glyph strings for the same composition has the same width,
17978 i.e. the width set for the first component of the composition. */
17980 s
->width
= s
->first_glyph
->pixel_width
;
17982 /* If the specified font could not be loaded, use the frame's
17983 default font, but record the fact that we couldn't load it in
17984 the glyph string so that we can draw rectangles for the
17985 characters of the glyph string. */
17986 if (s
->font
== NULL
)
17988 s
->font_not_found_p
= 1;
17989 s
->font
= FRAME_FONT (s
->f
);
17992 /* Adjust base line for subscript/superscript text. */
17993 s
->ybase
+= s
->first_glyph
->voffset
;
17995 xassert (s
->face
&& s
->face
->gc
);
17997 /* This glyph string must always be drawn with 16-bit functions. */
18000 return s
->gidx
+ s
->nchars
;
18004 /* Fill glyph string S from a sequence of character glyphs.
18006 FACE_ID is the face id of the string. START is the index of the
18007 first glyph to consider, END is the index of the last + 1.
18008 OVERLAPS_P non-zero means S should draw the foreground only, and
18009 use its physical height for clipping.
18011 Value is the index of the first glyph not in S. */
18014 fill_glyph_string (s
, face_id
, start
, end
, overlaps_p
)
18015 struct glyph_string
*s
;
18017 int start
, end
, overlaps_p
;
18019 struct glyph
*glyph
, *last
;
18021 int glyph_not_available_p
;
18023 xassert (s
->f
== XFRAME (s
->w
->frame
));
18024 xassert (s
->nchars
== 0);
18025 xassert (start
>= 0 && end
> start
);
18027 s
->for_overlaps_p
= overlaps_p
,
18028 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18029 last
= s
->row
->glyphs
[s
->area
] + end
;
18030 voffset
= glyph
->voffset
;
18032 glyph_not_available_p
= glyph
->glyph_not_available_p
;
18034 while (glyph
< last
18035 && glyph
->type
== CHAR_GLYPH
18036 && glyph
->voffset
== voffset
18037 /* Same face id implies same font, nowadays. */
18038 && glyph
->face_id
== face_id
18039 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
18043 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
18044 s
->char2b
+ s
->nchars
,
18046 s
->two_byte_p
= two_byte_p
;
18048 xassert (s
->nchars
<= end
- start
);
18049 s
->width
+= glyph
->pixel_width
;
18053 s
->font
= s
->face
->font
;
18054 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18056 /* If the specified font could not be loaded, use the frame's font,
18057 but record the fact that we couldn't load it in
18058 S->font_not_found_p so that we can draw rectangles for the
18059 characters of the glyph string. */
18060 if (s
->font
== NULL
|| glyph_not_available_p
)
18062 s
->font_not_found_p
= 1;
18063 s
->font
= FRAME_FONT (s
->f
);
18066 /* Adjust base line for subscript/superscript text. */
18067 s
->ybase
+= voffset
;
18069 xassert (s
->face
&& s
->face
->gc
);
18070 return glyph
- s
->row
->glyphs
[s
->area
];
18074 /* Fill glyph string S from image glyph S->first_glyph. */
18077 fill_image_glyph_string (s
)
18078 struct glyph_string
*s
;
18080 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
18081 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
18083 s
->slice
= s
->first_glyph
->slice
;
18084 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
18085 s
->font
= s
->face
->font
;
18086 s
->width
= s
->first_glyph
->pixel_width
;
18088 /* Adjust base line for subscript/superscript text. */
18089 s
->ybase
+= s
->first_glyph
->voffset
;
18093 /* Fill glyph string S from a sequence of stretch glyphs.
18095 ROW is the glyph row in which the glyphs are found, AREA is the
18096 area within the row. START is the index of the first glyph to
18097 consider, END is the index of the last + 1.
18099 Value is the index of the first glyph not in S. */
18102 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
18103 struct glyph_string
*s
;
18104 struct glyph_row
*row
;
18105 enum glyph_row_area area
;
18108 struct glyph
*glyph
, *last
;
18109 int voffset
, face_id
;
18111 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
18113 glyph
= s
->row
->glyphs
[s
->area
] + start
;
18114 last
= s
->row
->glyphs
[s
->area
] + end
;
18115 face_id
= glyph
->face_id
;
18116 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
18117 s
->font
= s
->face
->font
;
18118 s
->font_info
= FONT_INFO_FROM_ID (s
->f
, s
->face
->font_info_id
);
18119 s
->width
= glyph
->pixel_width
;
18120 voffset
= glyph
->voffset
;
18124 && glyph
->type
== STRETCH_GLYPH
18125 && glyph
->voffset
== voffset
18126 && glyph
->face_id
== face_id
);
18128 s
->width
+= glyph
->pixel_width
;
18130 /* Adjust base line for subscript/superscript text. */
18131 s
->ybase
+= voffset
;
18133 /* The case that face->gc == 0 is handled when drawing the glyph
18134 string by calling PREPARE_FACE_FOR_DISPLAY. */
18136 return glyph
- s
->row
->glyphs
[s
->area
];
18141 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
18142 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
18143 assumed to be zero. */
18146 x_get_glyph_overhangs (glyph
, f
, left
, right
)
18147 struct glyph
*glyph
;
18151 *left
= *right
= 0;
18153 if (glyph
->type
== CHAR_GLYPH
)
18157 struct font_info
*font_info
;
18161 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
18163 font_info
= FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18164 if (font
/* ++KFS: Should this be font_info ? */
18165 && (pcm
= rif
->per_char_metric (font
, &char2b
, glyph
->font_type
)))
18167 if (pcm
->rbearing
> pcm
->width
)
18168 *right
= pcm
->rbearing
- pcm
->width
;
18169 if (pcm
->lbearing
< 0)
18170 *left
= -pcm
->lbearing
;
18176 /* Return the index of the first glyph preceding glyph string S that
18177 is overwritten by S because of S's left overhang. Value is -1
18178 if no glyphs are overwritten. */
18181 left_overwritten (s
)
18182 struct glyph_string
*s
;
18186 if (s
->left_overhang
)
18189 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18190 int first
= s
->first_glyph
- glyphs
;
18192 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
18193 x
-= glyphs
[i
].pixel_width
;
18204 /* Return the index of the first glyph preceding glyph string S that
18205 is overwriting S because of its right overhang. Value is -1 if no
18206 glyph in front of S overwrites S. */
18209 left_overwriting (s
)
18210 struct glyph_string
*s
;
18213 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18214 int first
= s
->first_glyph
- glyphs
;
18218 for (i
= first
- 1; i
>= 0; --i
)
18221 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18224 x
-= glyphs
[i
].pixel_width
;
18231 /* Return the index of the last glyph following glyph string S that is
18232 not overwritten by S because of S's right overhang. Value is -1 if
18233 no such glyph is found. */
18236 right_overwritten (s
)
18237 struct glyph_string
*s
;
18241 if (s
->right_overhang
)
18244 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18245 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18246 int end
= s
->row
->used
[s
->area
];
18248 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
18249 x
+= glyphs
[i
].pixel_width
;
18258 /* Return the index of the last glyph following glyph string S that
18259 overwrites S because of its left overhang. Value is negative
18260 if no such glyph is found. */
18263 right_overwriting (s
)
18264 struct glyph_string
*s
;
18267 int end
= s
->row
->used
[s
->area
];
18268 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
18269 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
18273 for (i
= first
; i
< end
; ++i
)
18276 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
18279 x
+= glyphs
[i
].pixel_width
;
18286 /* Get face and two-byte form of character C in face FACE_ID on frame
18287 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
18288 means we want to display multibyte text. DISPLAY_P non-zero means
18289 make sure that X resources for the face returned are allocated.
18290 Value is a pointer to a realized face that is ready for display if
18291 DISPLAY_P is non-zero. */
18293 static INLINE
struct face
*
18294 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
18298 int multibyte_p
, display_p
;
18300 struct face
*face
= FACE_FROM_ID (f
, face_id
);
18304 /* Unibyte case. We don't have to encode, but we have to make
18305 sure to use a face suitable for unibyte. */
18306 STORE_XCHAR2B (char2b
, 0, c
);
18307 face_id
= FACE_FOR_CHAR (f
, face
, c
);
18308 face
= FACE_FROM_ID (f
, face_id
);
18310 else if (c
< 128 && face_id
< BASIC_FACE_ID_SENTINEL
)
18312 /* Case of ASCII in a face known to fit ASCII. */
18313 STORE_XCHAR2B (char2b
, 0, c
);
18317 int c1
, c2
, charset
;
18319 /* Split characters into bytes. If c2 is -1 afterwards, C is
18320 really a one-byte character so that byte1 is zero. */
18321 SPLIT_CHAR (c
, charset
, c1
, c2
);
18323 STORE_XCHAR2B (char2b
, c1
, c2
);
18325 STORE_XCHAR2B (char2b
, 0, c1
);
18327 /* Maybe encode the character in *CHAR2B. */
18328 if (face
->font
!= NULL
)
18330 struct font_info
*font_info
18331 = FONT_INFO_FROM_ID (f
, face
->font_info_id
);
18333 rif
->encode_char (c
, char2b
, font_info
, 0);
18337 /* Make sure X resources of the face are allocated. */
18338 #ifdef HAVE_X_WINDOWS
18342 xassert (face
!= NULL
);
18343 PREPARE_FACE_FOR_DISPLAY (f
, face
);
18350 /* Set background width of glyph string S. START is the index of the
18351 first glyph following S. LAST_X is the right-most x-position + 1
18352 in the drawing area. */
18355 set_glyph_string_background_width (s
, start
, last_x
)
18356 struct glyph_string
*s
;
18360 /* If the face of this glyph string has to be drawn to the end of
18361 the drawing area, set S->extends_to_end_of_line_p. */
18362 struct face
*default_face
= FACE_FROM_ID (s
->f
, DEFAULT_FACE_ID
);
18364 if (start
== s
->row
->used
[s
->area
]
18365 && s
->area
== TEXT_AREA
18366 && ((s
->hl
== DRAW_NORMAL_TEXT
18367 && (s
->row
->fill_line_p
18368 || s
->face
->background
!= default_face
->background
18369 || s
->face
->stipple
!= default_face
->stipple
18370 || s
->row
->mouse_face_p
))
18371 || s
->hl
== DRAW_MOUSE_FACE
18372 || ((s
->hl
== DRAW_IMAGE_RAISED
|| s
->hl
== DRAW_IMAGE_SUNKEN
)
18373 && s
->row
->fill_line_p
)))
18374 s
->extends_to_end_of_line_p
= 1;
18376 /* If S extends its face to the end of the line, set its
18377 background_width to the distance to the right edge of the drawing
18379 if (s
->extends_to_end_of_line_p
)
18380 s
->background_width
= last_x
- s
->x
+ 1;
18382 s
->background_width
= s
->width
;
18386 /* Compute overhangs and x-positions for glyph string S and its
18387 predecessors, or successors. X is the starting x-position for S.
18388 BACKWARD_P non-zero means process predecessors. */
18391 compute_overhangs_and_x (s
, x
, backward_p
)
18392 struct glyph_string
*s
;
18400 if (rif
->compute_glyph_string_overhangs
)
18401 rif
->compute_glyph_string_overhangs (s
);
18411 if (rif
->compute_glyph_string_overhangs
)
18412 rif
->compute_glyph_string_overhangs (s
);
18422 /* The following macros are only called from draw_glyphs below.
18423 They reference the following parameters of that function directly:
18424 `w', `row', `area', and `overlap_p'
18425 as well as the following local variables:
18426 `s', `f', and `hdc' (in W32) */
18429 /* On W32, silently add local `hdc' variable to argument list of
18430 init_glyph_string. */
18431 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18432 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
18434 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
18435 init_glyph_string (s, char2b, w, row, area, start, hl)
18438 /* Add a glyph string for a stretch glyph to the list of strings
18439 between HEAD and TAIL. START is the index of the stretch glyph in
18440 row area AREA of glyph row ROW. END is the index of the last glyph
18441 in that glyph row area. X is the current output position assigned
18442 to the new glyph string constructed. HL overrides that face of the
18443 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18444 is the right-most x-position of the drawing area. */
18446 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
18447 and below -- keep them on one line. */
18448 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18451 s = (struct glyph_string *) alloca (sizeof *s); \
18452 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18453 START = fill_stretch_glyph_string (s, row, area, START, END); \
18454 append_glyph_string (&HEAD, &TAIL, s); \
18460 /* Add a glyph string for an image glyph to the list of strings
18461 between HEAD and TAIL. START is the index of the image glyph in
18462 row area AREA of glyph row ROW. END is the index of the last glyph
18463 in that glyph row area. X is the current output position assigned
18464 to the new glyph string constructed. HL overrides that face of the
18465 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
18466 is the right-most x-position of the drawing area. */
18468 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18471 s = (struct glyph_string *) alloca (sizeof *s); \
18472 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
18473 fill_image_glyph_string (s); \
18474 append_glyph_string (&HEAD, &TAIL, s); \
18481 /* Add a glyph string for a sequence of character glyphs to the list
18482 of strings between HEAD and TAIL. START is the index of the first
18483 glyph in row area AREA of glyph row ROW that is part of the new
18484 glyph string. END is the index of the last glyph in that glyph row
18485 area. X is the current output position assigned to the new glyph
18486 string constructed. HL overrides that face of the glyph; e.g. it
18487 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
18488 right-most x-position of the drawing area. */
18490 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18496 c = (row)->glyphs[area][START].u.ch; \
18497 face_id = (row)->glyphs[area][START].face_id; \
18499 s = (struct glyph_string *) alloca (sizeof *s); \
18500 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
18501 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
18502 append_glyph_string (&HEAD, &TAIL, s); \
18504 START = fill_glyph_string (s, face_id, START, END, overlaps_p); \
18509 /* Add a glyph string for a composite sequence to the list of strings
18510 between HEAD and TAIL. START is the index of the first glyph in
18511 row area AREA of glyph row ROW that is part of the new glyph
18512 string. END is the index of the last glyph in that glyph row area.
18513 X is the current output position assigned to the new glyph string
18514 constructed. HL overrides that face of the glyph; e.g. it is
18515 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
18516 x-position of the drawing area. */
18518 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
18520 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
18521 int face_id = (row)->glyphs[area][START].face_id; \
18522 struct face *base_face = FACE_FROM_ID (f, face_id); \
18523 struct composition *cmp = composition_table[cmp_id]; \
18524 int glyph_len = cmp->glyph_len; \
18526 struct face **faces; \
18527 struct glyph_string *first_s = NULL; \
18530 base_face = base_face->ascii_face; \
18531 char2b = (XChar2b *) alloca ((sizeof *char2b) * glyph_len); \
18532 faces = (struct face **) alloca ((sizeof *faces) * glyph_len); \
18533 /* At first, fill in `char2b' and `faces'. */ \
18534 for (n = 0; n < glyph_len; n++) \
18536 int c = COMPOSITION_GLYPH (cmp, n); \
18537 int this_face_id = FACE_FOR_CHAR (f, base_face, c); \
18538 faces[n] = FACE_FROM_ID (f, this_face_id); \
18539 get_char_face_and_encoding (f, c, this_face_id, \
18540 char2b + n, 1, 1); \
18543 /* Make glyph_strings for each glyph sequence that is drawable by \
18544 the same face, and append them to HEAD/TAIL. */ \
18545 for (n = 0; n < cmp->glyph_len;) \
18547 s = (struct glyph_string *) alloca (sizeof *s); \
18548 INIT_GLYPH_STRING (s, char2b + n, w, row, area, START, HL); \
18549 append_glyph_string (&(HEAD), &(TAIL), s); \
18557 n = fill_composite_glyph_string (s, faces, overlaps_p); \
18565 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
18566 of AREA of glyph row ROW on window W between indices START and END.
18567 HL overrides the face for drawing glyph strings, e.g. it is
18568 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
18569 x-positions of the drawing area.
18571 This is an ugly monster macro construct because we must use alloca
18572 to allocate glyph strings (because draw_glyphs can be called
18573 asynchronously). */
18575 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
18578 HEAD = TAIL = NULL; \
18579 while (START < END) \
18581 struct glyph *first_glyph = (row)->glyphs[area] + START; \
18582 switch (first_glyph->type) \
18585 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
18589 case COMPOSITE_GLYPH: \
18590 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
18594 case STRETCH_GLYPH: \
18595 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
18599 case IMAGE_GLYPH: \
18600 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
18608 set_glyph_string_background_width (s, START, LAST_X); \
18615 /* Draw glyphs between START and END in AREA of ROW on window W,
18616 starting at x-position X. X is relative to AREA in W. HL is a
18617 face-override with the following meaning:
18619 DRAW_NORMAL_TEXT draw normally
18620 DRAW_CURSOR draw in cursor face
18621 DRAW_MOUSE_FACE draw in mouse face.
18622 DRAW_INVERSE_VIDEO draw in mode line face
18623 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
18624 DRAW_IMAGE_RAISED draw an image with a raised relief around it
18626 If OVERLAPS_P is non-zero, draw only the foreground of characters
18627 and clip to the physical height of ROW.
18629 Value is the x-position reached, relative to AREA of W. */
18632 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps_p
)
18635 struct glyph_row
*row
;
18636 enum glyph_row_area area
;
18638 enum draw_glyphs_face hl
;
18641 struct glyph_string
*head
, *tail
;
18642 struct glyph_string
*s
;
18643 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
18644 int last_x
, area_width
;
18647 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18650 ALLOCATE_HDC (hdc
, f
);
18652 /* Let's rather be paranoid than getting a SEGV. */
18653 end
= min (end
, row
->used
[area
]);
18654 start
= max (0, start
);
18655 start
= min (end
, start
);
18657 /* Translate X to frame coordinates. Set last_x to the right
18658 end of the drawing area. */
18659 if (row
->full_width_p
)
18661 /* X is relative to the left edge of W, without scroll bars
18663 x
+= WINDOW_LEFT_EDGE_X (w
);
18664 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
18668 int area_left
= window_box_left (w
, area
);
18670 area_width
= window_box_width (w
, area
);
18671 last_x
= area_left
+ area_width
;
18674 /* Build a doubly-linked list of glyph_string structures between
18675 head and tail from what we have to draw. Note that the macro
18676 BUILD_GLYPH_STRINGS will modify its start parameter. That's
18677 the reason we use a separate variable `i'. */
18679 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
18681 x_reached
= tail
->x
+ tail
->background_width
;
18685 /* If there are any glyphs with lbearing < 0 or rbearing > width in
18686 the row, redraw some glyphs in front or following the glyph
18687 strings built above. */
18688 if (head
&& !overlaps_p
&& row
->contains_overlapping_glyphs_p
)
18691 struct glyph_string
*h
, *t
;
18693 /* Compute overhangs for all glyph strings. */
18694 if (rif
->compute_glyph_string_overhangs
)
18695 for (s
= head
; s
; s
= s
->next
)
18696 rif
->compute_glyph_string_overhangs (s
);
18698 /* Prepend glyph strings for glyphs in front of the first glyph
18699 string that are overwritten because of the first glyph
18700 string's left overhang. The background of all strings
18701 prepended must be drawn because the first glyph string
18703 i
= left_overwritten (head
);
18707 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
18708 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18710 compute_overhangs_and_x (t
, head
->x
, 1);
18711 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18715 /* Prepend glyph strings for glyphs in front of the first glyph
18716 string that overwrite that glyph string because of their
18717 right overhang. For these strings, only the foreground must
18718 be drawn, because it draws over the glyph string at `head'.
18719 The background must not be drawn because this would overwrite
18720 right overhangs of preceding glyphs for which no glyph
18722 i
= left_overwriting (head
);
18726 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
18727 DRAW_NORMAL_TEXT
, dummy_x
, last_x
);
18728 for (s
= h
; s
; s
= s
->next
)
18729 s
->background_filled_p
= 1;
18730 compute_overhangs_and_x (t
, head
->x
, 1);
18731 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
18734 /* Append glyphs strings for glyphs following the last glyph
18735 string tail that are overwritten by tail. The background of
18736 these strings has to be drawn because tail's foreground draws
18738 i
= right_overwritten (tail
);
18741 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18742 DRAW_NORMAL_TEXT
, x
, last_x
);
18743 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18744 append_glyph_string_lists (&head
, &tail
, h
, t
);
18748 /* Append glyph strings for glyphs following the last glyph
18749 string tail that overwrite tail. The foreground of such
18750 glyphs has to be drawn because it writes into the background
18751 of tail. The background must not be drawn because it could
18752 paint over the foreground of following glyphs. */
18753 i
= right_overwriting (tail
);
18757 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
18758 DRAW_NORMAL_TEXT
, x
, last_x
);
18759 for (s
= h
; s
; s
= s
->next
)
18760 s
->background_filled_p
= 1;
18761 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
18762 append_glyph_string_lists (&head
, &tail
, h
, t
);
18764 if (clip_head
|| clip_tail
)
18765 for (s
= head
; s
; s
= s
->next
)
18767 s
->clip_head
= clip_head
;
18768 s
->clip_tail
= clip_tail
;
18772 /* Draw all strings. */
18773 for (s
= head
; s
; s
= s
->next
)
18774 rif
->draw_glyph_string (s
);
18776 if (area
== TEXT_AREA
18777 && !row
->full_width_p
18778 /* When drawing overlapping rows, only the glyph strings'
18779 foreground is drawn, which doesn't erase a cursor
18783 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
18784 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
18785 : (tail
? tail
->x
+ tail
->background_width
: x
));
18787 int text_left
= window_box_left (w
, TEXT_AREA
);
18791 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
18792 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
18795 /* Value is the x-position up to which drawn, relative to AREA of W.
18796 This doesn't include parts drawn because of overhangs. */
18797 if (row
->full_width_p
)
18798 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
18800 x_reached
-= window_box_left (w
, area
);
18802 RELEASE_HDC (hdc
, f
);
18807 /* Expand row matrix if too narrow. Don't expand if area
18810 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
18812 if (!fonts_changed_p \
18813 && (it->glyph_row->glyphs[area] \
18814 < it->glyph_row->glyphs[area + 1])) \
18816 it->w->ncols_scale_factor++; \
18817 fonts_changed_p = 1; \
18821 /* Store one glyph for IT->char_to_display in IT->glyph_row.
18822 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18828 struct glyph
*glyph
;
18829 enum glyph_row_area area
= it
->area
;
18831 xassert (it
->glyph_row
);
18832 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
18834 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18835 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18837 glyph
->charpos
= CHARPOS (it
->position
);
18838 glyph
->object
= it
->object
;
18839 glyph
->pixel_width
= it
->pixel_width
;
18840 glyph
->ascent
= it
->ascent
;
18841 glyph
->descent
= it
->descent
;
18842 glyph
->voffset
= it
->voffset
;
18843 glyph
->type
= CHAR_GLYPH
;
18844 glyph
->multibyte_p
= it
->multibyte_p
;
18845 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18846 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18847 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18848 || it
->phys_descent
> it
->descent
);
18849 glyph
->padding_p
= 0;
18850 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
18851 glyph
->face_id
= it
->face_id
;
18852 glyph
->u
.ch
= it
->char_to_display
;
18853 glyph
->slice
= null_glyph_slice
;
18854 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18855 ++it
->glyph_row
->used
[area
];
18858 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18861 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
18862 Called from x_produce_glyphs when IT->glyph_row is non-null. */
18865 append_composite_glyph (it
)
18868 struct glyph
*glyph
;
18869 enum glyph_row_area area
= it
->area
;
18871 xassert (it
->glyph_row
);
18873 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
18874 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
18876 glyph
->charpos
= CHARPOS (it
->position
);
18877 glyph
->object
= it
->object
;
18878 glyph
->pixel_width
= it
->pixel_width
;
18879 glyph
->ascent
= it
->ascent
;
18880 glyph
->descent
= it
->descent
;
18881 glyph
->voffset
= it
->voffset
;
18882 glyph
->type
= COMPOSITE_GLYPH
;
18883 glyph
->multibyte_p
= it
->multibyte_p
;
18884 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
18885 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
18886 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
18887 || it
->phys_descent
> it
->descent
);
18888 glyph
->padding_p
= 0;
18889 glyph
->glyph_not_available_p
= 0;
18890 glyph
->face_id
= it
->face_id
;
18891 glyph
->u
.cmp_id
= it
->cmp_id
;
18892 glyph
->slice
= null_glyph_slice
;
18893 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
18894 ++it
->glyph_row
->used
[area
];
18897 IT_EXPAND_MATRIX_WIDTH (it
, area
);
18901 /* Change IT->ascent and IT->height according to the setting of
18905 take_vertical_position_into_account (it
)
18910 if (it
->voffset
< 0)
18911 /* Increase the ascent so that we can display the text higher
18913 it
->ascent
-= it
->voffset
;
18915 /* Increase the descent so that we can display the text lower
18917 it
->descent
+= it
->voffset
;
18922 /* Produce glyphs/get display metrics for the image IT is loaded with.
18923 See the description of struct display_iterator in dispextern.h for
18924 an overview of struct display_iterator. */
18927 produce_image_glyph (it
)
18933 struct glyph_slice slice
;
18935 xassert (it
->what
== IT_IMAGE
);
18937 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18939 /* Make sure X resources of the face is loaded. */
18940 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
18942 if (it
->image_id
< 0)
18944 /* Fringe bitmap. */
18945 it
->ascent
= it
->phys_ascent
= 0;
18946 it
->descent
= it
->phys_descent
= 0;
18947 it
->pixel_width
= 0;
18952 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
18954 /* Make sure X resources of the image is loaded. */
18955 prepare_image_for_display (it
->f
, img
);
18957 slice
.x
= slice
.y
= 0;
18958 slice
.width
= img
->width
;
18959 slice
.height
= img
->height
;
18961 if (INTEGERP (it
->slice
.x
))
18962 slice
.x
= XINT (it
->slice
.x
);
18963 else if (FLOATP (it
->slice
.x
))
18964 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
18966 if (INTEGERP (it
->slice
.y
))
18967 slice
.y
= XINT (it
->slice
.y
);
18968 else if (FLOATP (it
->slice
.y
))
18969 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
18971 if (INTEGERP (it
->slice
.width
))
18972 slice
.width
= XINT (it
->slice
.width
);
18973 else if (FLOATP (it
->slice
.width
))
18974 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
18976 if (INTEGERP (it
->slice
.height
))
18977 slice
.height
= XINT (it
->slice
.height
);
18978 else if (FLOATP (it
->slice
.height
))
18979 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
18981 if (slice
.x
>= img
->width
)
18982 slice
.x
= img
->width
;
18983 if (slice
.y
>= img
->height
)
18984 slice
.y
= img
->height
;
18985 if (slice
.x
+ slice
.width
>= img
->width
)
18986 slice
.width
= img
->width
- slice
.x
;
18987 if (slice
.y
+ slice
.height
> img
->height
)
18988 slice
.height
= img
->height
- slice
.y
;
18990 if (slice
.width
== 0 || slice
.height
== 0)
18993 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
18995 it
->descent
= slice
.height
- glyph_ascent
;
18997 it
->descent
+= img
->vmargin
;
18998 if (slice
.y
+ slice
.height
== img
->height
)
18999 it
->descent
+= img
->vmargin
;
19000 it
->phys_descent
= it
->descent
;
19002 it
->pixel_width
= slice
.width
;
19004 it
->pixel_width
+= img
->hmargin
;
19005 if (slice
.x
+ slice
.width
== img
->width
)
19006 it
->pixel_width
+= img
->hmargin
;
19008 /* It's quite possible for images to have an ascent greater than
19009 their height, so don't get confused in that case. */
19010 if (it
->descent
< 0)
19013 #if 0 /* this breaks image tiling */
19014 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
19015 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
19016 if (face_ascent
> it
->ascent
)
19017 it
->ascent
= it
->phys_ascent
= face_ascent
;
19022 if (face
->box
!= FACE_NO_BOX
)
19024 if (face
->box_line_width
> 0)
19027 it
->ascent
+= face
->box_line_width
;
19028 if (slice
.y
+ slice
.height
== img
->height
)
19029 it
->descent
+= face
->box_line_width
;
19032 if (it
->start_of_box_run_p
&& slice
.x
== 0)
19033 it
->pixel_width
+= abs (face
->box_line_width
);
19034 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
19035 it
->pixel_width
+= abs (face
->box_line_width
);
19038 take_vertical_position_into_account (it
);
19042 struct glyph
*glyph
;
19043 enum glyph_row_area area
= it
->area
;
19045 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19046 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19048 glyph
->charpos
= CHARPOS (it
->position
);
19049 glyph
->object
= it
->object
;
19050 glyph
->pixel_width
= it
->pixel_width
;
19051 glyph
->ascent
= glyph_ascent
;
19052 glyph
->descent
= it
->descent
;
19053 glyph
->voffset
= it
->voffset
;
19054 glyph
->type
= IMAGE_GLYPH
;
19055 glyph
->multibyte_p
= it
->multibyte_p
;
19056 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19057 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19058 glyph
->overlaps_vertically_p
= 0;
19059 glyph
->padding_p
= 0;
19060 glyph
->glyph_not_available_p
= 0;
19061 glyph
->face_id
= it
->face_id
;
19062 glyph
->u
.img_id
= img
->id
;
19063 glyph
->slice
= slice
;
19064 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19065 ++it
->glyph_row
->used
[area
];
19068 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19073 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
19074 of the glyph, WIDTH and HEIGHT are the width and height of the
19075 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
19078 append_stretch_glyph (it
, object
, width
, height
, ascent
)
19080 Lisp_Object object
;
19084 struct glyph
*glyph
;
19085 enum glyph_row_area area
= it
->area
;
19087 xassert (ascent
>= 0 && ascent
<= height
);
19089 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
19090 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
19092 glyph
->charpos
= CHARPOS (it
->position
);
19093 glyph
->object
= object
;
19094 glyph
->pixel_width
= width
;
19095 glyph
->ascent
= ascent
;
19096 glyph
->descent
= height
- ascent
;
19097 glyph
->voffset
= it
->voffset
;
19098 glyph
->type
= STRETCH_GLYPH
;
19099 glyph
->multibyte_p
= it
->multibyte_p
;
19100 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
19101 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
19102 glyph
->overlaps_vertically_p
= 0;
19103 glyph
->padding_p
= 0;
19104 glyph
->glyph_not_available_p
= 0;
19105 glyph
->face_id
= it
->face_id
;
19106 glyph
->u
.stretch
.ascent
= ascent
;
19107 glyph
->u
.stretch
.height
= height
;
19108 glyph
->slice
= null_glyph_slice
;
19109 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
19110 ++it
->glyph_row
->used
[area
];
19113 IT_EXPAND_MATRIX_WIDTH (it
, area
);
19117 /* Produce a stretch glyph for iterator IT. IT->object is the value
19118 of the glyph property displayed. The value must be a list
19119 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
19122 1. `:width WIDTH' specifies that the space should be WIDTH *
19123 canonical char width wide. WIDTH may be an integer or floating
19126 2. `:relative-width FACTOR' specifies that the width of the stretch
19127 should be computed from the width of the first character having the
19128 `glyph' property, and should be FACTOR times that width.
19130 3. `:align-to HPOS' specifies that the space should be wide enough
19131 to reach HPOS, a value in canonical character units.
19133 Exactly one of the above pairs must be present.
19135 4. `:height HEIGHT' specifies that the height of the stretch produced
19136 should be HEIGHT, measured in canonical character units.
19138 5. `:relative-height FACTOR' specifies that the height of the
19139 stretch should be FACTOR times the height of the characters having
19140 the glyph property.
19142 Either none or exactly one of 4 or 5 must be present.
19144 6. `:ascent ASCENT' specifies that ASCENT percent of the height
19145 of the stretch should be used for the ascent of the stretch.
19146 ASCENT must be in the range 0 <= ASCENT <= 100. */
19149 produce_stretch_glyph (it
)
19152 /* (space :width WIDTH :height HEIGHT ...) */
19153 Lisp_Object prop
, plist
;
19154 int width
= 0, height
= 0, align_to
= -1;
19155 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
19158 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19159 XFontStruct
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19161 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
19163 /* List should start with `space'. */
19164 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
19165 plist
= XCDR (it
->object
);
19167 /* Compute the width of the stretch. */
19168 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
19169 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
19171 /* Absolute width `:width WIDTH' specified and valid. */
19172 zero_width_ok_p
= 1;
19175 else if (prop
= Fplist_get (plist
, QCrelative_width
),
19178 /* Relative width `:relative-width FACTOR' specified and valid.
19179 Compute the width of the characters having the `glyph'
19182 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
19185 if (it
->multibyte_p
)
19187 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
19188 - IT_BYTEPOS (*it
));
19189 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
19192 it2
.c
= *p
, it2
.len
= 1;
19194 it2
.glyph_row
= NULL
;
19195 it2
.what
= IT_CHARACTER
;
19196 x_produce_glyphs (&it2
);
19197 width
= NUMVAL (prop
) * it2
.pixel_width
;
19199 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
19200 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
19202 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
19203 align_to
= (align_to
< 0
19205 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
19206 else if (align_to
< 0)
19207 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
19208 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
19209 zero_width_ok_p
= 1;
19212 /* Nothing specified -> width defaults to canonical char width. */
19213 width
= FRAME_COLUMN_WIDTH (it
->f
);
19215 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
19218 /* Compute height. */
19219 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
19220 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19223 zero_height_ok_p
= 1;
19225 else if (prop
= Fplist_get (plist
, QCrelative_height
),
19227 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
19229 height
= FONT_HEIGHT (font
);
19231 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
19234 /* Compute percentage of height used for ascent. If
19235 `:ascent ASCENT' is present and valid, use that. Otherwise,
19236 derive the ascent from the font in use. */
19237 if (prop
= Fplist_get (plist
, QCascent
),
19238 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
19239 ascent
= height
* NUMVAL (prop
) / 100.0;
19240 else if (!NILP (prop
)
19241 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
19242 ascent
= min (max (0, (int)tem
), height
);
19244 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
19246 if (width
> 0 && height
> 0 && it
->glyph_row
)
19248 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
19249 if (!STRINGP (object
))
19250 object
= it
->w
->buffer
;
19251 append_stretch_glyph (it
, object
, width
, height
, ascent
);
19254 it
->pixel_width
= width
;
19255 it
->ascent
= it
->phys_ascent
= ascent
;
19256 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
19257 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
19259 if (width
> 0 && height
> 0 && face
->box
!= FACE_NO_BOX
)
19261 if (face
->box_line_width
> 0)
19263 it
->ascent
+= face
->box_line_width
;
19264 it
->descent
+= face
->box_line_width
;
19267 if (it
->start_of_box_run_p
)
19268 it
->pixel_width
+= abs (face
->box_line_width
);
19269 if (it
->end_of_box_run_p
)
19270 it
->pixel_width
+= abs (face
->box_line_width
);
19273 take_vertical_position_into_account (it
);
19276 /* Get line-height and line-spacing property at point.
19277 If line-height has format (HEIGHT TOTAL), return TOTAL
19278 in TOTAL_HEIGHT. */
19281 get_line_height_property (it
, prop
)
19285 Lisp_Object position
;
19287 if (STRINGP (it
->object
))
19288 position
= make_number (IT_STRING_CHARPOS (*it
));
19289 else if (BUFFERP (it
->object
))
19290 position
= make_number (IT_CHARPOS (*it
));
19294 return Fget_char_property (position
, prop
, it
->object
);
19297 /* Calculate line-height and line-spacing properties.
19298 An integer value specifies explicit pixel value.
19299 A float value specifies relative value to current face height.
19300 A cons (float . face-name) specifies relative value to
19301 height of specified face font.
19303 Returns height in pixels, or nil. */
19307 calc_line_height_property (it
, val
, font
, boff
, override
)
19311 int boff
, override
;
19313 Lisp_Object face_name
= Qnil
;
19314 int ascent
, descent
, height
;
19316 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
19321 face_name
= XCAR (val
);
19323 if (!NUMBERP (val
))
19324 val
= make_number (1);
19325 if (NILP (face_name
))
19327 height
= it
->ascent
+ it
->descent
;
19332 if (NILP (face_name
))
19334 font
= FRAME_FONT (it
->f
);
19335 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19337 else if (EQ (face_name
, Qt
))
19345 struct font_info
*font_info
;
19347 face_id
= lookup_named_face (it
->f
, face_name
, ' ', 0);
19349 return make_number (-1);
19351 face
= FACE_FROM_ID (it
->f
, face_id
);
19354 return make_number (-1);
19356 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19357 boff
= font_info
->baseline_offset
;
19358 if (font_info
->vertical_centering
)
19359 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19362 ascent
= FONT_BASE (font
) + boff
;
19363 descent
= FONT_DESCENT (font
) - boff
;
19367 it
->override_ascent
= ascent
;
19368 it
->override_descent
= descent
;
19369 it
->override_boff
= boff
;
19372 height
= ascent
+ descent
;
19376 height
= (int)(XFLOAT_DATA (val
) * height
);
19377 else if (INTEGERP (val
))
19378 height
*= XINT (val
);
19380 return make_number (height
);
19385 Produce glyphs/get display metrics for the display element IT is
19386 loaded with. See the description of struct display_iterator in
19387 dispextern.h for an overview of struct display_iterator. */
19390 x_produce_glyphs (it
)
19393 int extra_line_spacing
= it
->extra_line_spacing
;
19395 it
->glyph_not_available_p
= 0;
19397 if (it
->what
== IT_CHARACTER
)
19401 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19403 int font_not_found_p
;
19404 struct font_info
*font_info
;
19405 int boff
; /* baseline offset */
19406 /* We may change it->multibyte_p upon unibyte<->multibyte
19407 conversion. So, save the current value now and restore it
19410 Note: It seems that we don't have to record multibyte_p in
19411 struct glyph because the character code itself tells if or
19412 not the character is multibyte. Thus, in the future, we must
19413 consider eliminating the field `multibyte_p' in the struct
19415 int saved_multibyte_p
= it
->multibyte_p
;
19417 /* Maybe translate single-byte characters to multibyte, or the
19419 it
->char_to_display
= it
->c
;
19420 if (!ASCII_BYTE_P (it
->c
))
19422 if (unibyte_display_via_language_environment
19423 && SINGLE_BYTE_CHAR_P (it
->c
)
19425 || !NILP (Vnonascii_translation_table
)))
19427 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19428 it
->multibyte_p
= 1;
19429 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19430 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19432 else if (!SINGLE_BYTE_CHAR_P (it
->c
)
19433 && !it
->multibyte_p
)
19435 it
->multibyte_p
= 1;
19436 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19437 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19441 /* Get font to use. Encode IT->char_to_display. */
19442 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19443 &char2b
, it
->multibyte_p
, 0);
19446 /* When no suitable font found, use the default font. */
19447 font_not_found_p
= font
== NULL
;
19448 if (font_not_found_p
)
19450 font
= FRAME_FONT (it
->f
);
19451 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19456 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19457 boff
= font_info
->baseline_offset
;
19458 if (font_info
->vertical_centering
)
19459 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19462 if (it
->char_to_display
>= ' '
19463 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
19465 /* Either unibyte or ASCII. */
19470 pcm
= rif
->per_char_metric (font
, &char2b
,
19471 FONT_TYPE_FOR_UNIBYTE (font
, it
->char_to_display
));
19473 if (it
->override_ascent
>= 0)
19475 it
->ascent
= it
->override_ascent
;
19476 it
->descent
= it
->override_descent
;
19477 boff
= it
->override_boff
;
19481 it
->ascent
= FONT_BASE (font
) + boff
;
19482 it
->descent
= FONT_DESCENT (font
) - boff
;
19487 it
->phys_ascent
= pcm
->ascent
+ boff
;
19488 it
->phys_descent
= pcm
->descent
- boff
;
19489 it
->pixel_width
= pcm
->width
;
19493 it
->glyph_not_available_p
= 1;
19494 it
->phys_ascent
= it
->ascent
;
19495 it
->phys_descent
= it
->descent
;
19496 it
->pixel_width
= FONT_WIDTH (font
);
19499 if (it
->constrain_row_ascent_descent_p
)
19501 if (it
->descent
> it
->max_descent
)
19503 it
->ascent
+= it
->descent
- it
->max_descent
;
19504 it
->descent
= it
->max_descent
;
19506 if (it
->ascent
> it
->max_ascent
)
19508 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19509 it
->ascent
= it
->max_ascent
;
19511 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19512 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19513 extra_line_spacing
= 0;
19516 /* If this is a space inside a region of text with
19517 `space-width' property, change its width. */
19518 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
19520 it
->pixel_width
*= XFLOATINT (it
->space_width
);
19522 /* If face has a box, add the box thickness to the character
19523 height. If character has a box line to the left and/or
19524 right, add the box line width to the character's width. */
19525 if (face
->box
!= FACE_NO_BOX
)
19527 int thick
= face
->box_line_width
;
19531 it
->ascent
+= thick
;
19532 it
->descent
+= thick
;
19537 if (it
->start_of_box_run_p
)
19538 it
->pixel_width
+= thick
;
19539 if (it
->end_of_box_run_p
)
19540 it
->pixel_width
+= thick
;
19543 /* If face has an overline, add the height of the overline
19544 (1 pixel) and a 1 pixel margin to the character height. */
19545 if (face
->overline_p
)
19548 if (it
->constrain_row_ascent_descent_p
)
19550 if (it
->ascent
> it
->max_ascent
)
19551 it
->ascent
= it
->max_ascent
;
19552 if (it
->descent
> it
->max_descent
)
19553 it
->descent
= it
->max_descent
;
19556 take_vertical_position_into_account (it
);
19558 /* If we have to actually produce glyphs, do it. */
19563 /* Translate a space with a `space-width' property
19564 into a stretch glyph. */
19565 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
19566 / FONT_HEIGHT (font
));
19567 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19568 it
->ascent
+ it
->descent
, ascent
);
19573 /* If characters with lbearing or rbearing are displayed
19574 in this line, record that fact in a flag of the
19575 glyph row. This is used to optimize X output code. */
19576 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
19577 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19580 else if (it
->char_to_display
== '\n')
19582 /* A newline has no width but we need the height of the line.
19583 But if previous part of the line set a height, don't
19584 increase that height */
19586 Lisp_Object height
;
19587 Lisp_Object total_height
= Qnil
;
19589 it
->override_ascent
= -1;
19590 it
->pixel_width
= 0;
19593 height
= get_line_height_property(it
, Qline_height
);
19594 /* Split (line-height total-height) list */
19596 && CONSP (XCDR (height
))
19597 && NILP (XCDR (XCDR (height
))))
19599 total_height
= XCAR (XCDR (height
));
19600 height
= XCAR (height
);
19602 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
19604 if (it
->override_ascent
>= 0)
19606 it
->ascent
= it
->override_ascent
;
19607 it
->descent
= it
->override_descent
;
19608 boff
= it
->override_boff
;
19612 it
->ascent
= FONT_BASE (font
) + boff
;
19613 it
->descent
= FONT_DESCENT (font
) - boff
;
19616 if (EQ (height
, Qt
))
19618 if (it
->descent
> it
->max_descent
)
19620 it
->ascent
+= it
->descent
- it
->max_descent
;
19621 it
->descent
= it
->max_descent
;
19623 if (it
->ascent
> it
->max_ascent
)
19625 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
19626 it
->ascent
= it
->max_ascent
;
19628 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
19629 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
19630 it
->constrain_row_ascent_descent_p
= 1;
19631 extra_line_spacing
= 0;
19635 Lisp_Object spacing
;
19637 it
->phys_ascent
= it
->ascent
;
19638 it
->phys_descent
= it
->descent
;
19640 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
19641 && face
->box
!= FACE_NO_BOX
19642 && face
->box_line_width
> 0)
19644 it
->ascent
+= face
->box_line_width
;
19645 it
->descent
+= face
->box_line_width
;
19648 && XINT (height
) > it
->ascent
+ it
->descent
)
19649 it
->ascent
= XINT (height
) - it
->descent
;
19651 if (!NILP (total_height
))
19652 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
19655 spacing
= get_line_height_property(it
, Qline_spacing
);
19656 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
19658 if (INTEGERP (spacing
))
19660 extra_line_spacing
= XINT (spacing
);
19661 if (!NILP (total_height
))
19662 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19666 else if (it
->char_to_display
== '\t')
19668 int tab_width
= it
->tab_width
* FRAME_SPACE_WIDTH (it
->f
);
19669 int x
= it
->current_x
+ it
->continuation_lines_width
;
19670 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
19672 /* If the distance from the current position to the next tab
19673 stop is less than a space character width, use the
19674 tab stop after that. */
19675 if (next_tab_x
- x
< FRAME_SPACE_WIDTH (it
->f
))
19676 next_tab_x
+= tab_width
;
19678 it
->pixel_width
= next_tab_x
- x
;
19680 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
19681 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19685 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
19686 it
->ascent
+ it
->descent
, it
->ascent
);
19691 /* A multi-byte character. Assume that the display width of the
19692 character is the width of the character multiplied by the
19693 width of the font. */
19695 /* If we found a font, this font should give us the right
19696 metrics. If we didn't find a font, use the frame's
19697 default font and calculate the width of the character
19698 from the charset width; this is what old redisplay code
19701 pcm
= rif
->per_char_metric (font
, &char2b
,
19702 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
));
19704 if (font_not_found_p
|| !pcm
)
19706 int charset
= CHAR_CHARSET (it
->char_to_display
);
19708 it
->glyph_not_available_p
= 1;
19709 it
->pixel_width
= (FRAME_COLUMN_WIDTH (it
->f
)
19710 * CHARSET_WIDTH (charset
));
19711 it
->phys_ascent
= FONT_BASE (font
) + boff
;
19712 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
19716 it
->pixel_width
= pcm
->width
;
19717 it
->phys_ascent
= pcm
->ascent
+ boff
;
19718 it
->phys_descent
= pcm
->descent
- boff
;
19720 && (pcm
->lbearing
< 0
19721 || pcm
->rbearing
> pcm
->width
))
19722 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
19725 it
->ascent
= FONT_BASE (font
) + boff
;
19726 it
->descent
= FONT_DESCENT (font
) - boff
;
19727 if (face
->box
!= FACE_NO_BOX
)
19729 int thick
= face
->box_line_width
;
19733 it
->ascent
+= thick
;
19734 it
->descent
+= thick
;
19739 if (it
->start_of_box_run_p
)
19740 it
->pixel_width
+= thick
;
19741 if (it
->end_of_box_run_p
)
19742 it
->pixel_width
+= thick
;
19745 /* If face has an overline, add the height of the overline
19746 (1 pixel) and a 1 pixel margin to the character height. */
19747 if (face
->overline_p
)
19750 take_vertical_position_into_account (it
);
19755 it
->multibyte_p
= saved_multibyte_p
;
19757 else if (it
->what
== IT_COMPOSITION
)
19759 /* Note: A composition is represented as one glyph in the
19760 glyph matrix. There are no padding glyphs. */
19763 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19765 int font_not_found_p
;
19766 struct font_info
*font_info
;
19767 int boff
; /* baseline offset */
19768 struct composition
*cmp
= composition_table
[it
->cmp_id
];
19770 /* Maybe translate single-byte characters to multibyte. */
19771 it
->char_to_display
= it
->c
;
19772 if (unibyte_display_via_language_environment
19773 && SINGLE_BYTE_CHAR_P (it
->c
)
19776 && !NILP (Vnonascii_translation_table
))))
19778 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
19781 /* Get face and font to use. Encode IT->char_to_display. */
19782 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
);
19783 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19784 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
19785 &char2b
, it
->multibyte_p
, 0);
19788 /* When no suitable font found, use the default font. */
19789 font_not_found_p
= font
== NULL
;
19790 if (font_not_found_p
)
19792 font
= FRAME_FONT (it
->f
);
19793 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19798 font_info
= FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19799 boff
= font_info
->baseline_offset
;
19800 if (font_info
->vertical_centering
)
19801 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19804 /* There are no padding glyphs, so there is only one glyph to
19805 produce for the composition. Important is that pixel_width,
19806 ascent and descent are the values of what is drawn by
19807 draw_glyphs (i.e. the values of the overall glyphs composed). */
19810 /* If we have not yet calculated pixel size data of glyphs of
19811 the composition for the current face font, calculate them
19812 now. Theoretically, we have to check all fonts for the
19813 glyphs, but that requires much time and memory space. So,
19814 here we check only the font of the first glyph. This leads
19815 to incorrect display very rarely, and C-l (recenter) can
19816 correct the display anyway. */
19817 if (cmp
->font
!= (void *) font
)
19819 /* Ascent and descent of the font of the first character of
19820 this composition (adjusted by baseline offset). Ascent
19821 and descent of overall glyphs should not be less than
19822 them respectively. */
19823 int font_ascent
= FONT_BASE (font
) + boff
;
19824 int font_descent
= FONT_DESCENT (font
) - boff
;
19825 /* Bounding box of the overall glyphs. */
19826 int leftmost
, rightmost
, lowest
, highest
;
19827 int i
, width
, ascent
, descent
;
19829 cmp
->font
= (void *) font
;
19831 /* Initialize the bounding box. */
19833 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19834 FONT_TYPE_FOR_MULTIBYTE (font
, it
->c
))))
19836 width
= pcm
->width
;
19837 ascent
= pcm
->ascent
;
19838 descent
= pcm
->descent
;
19842 width
= FONT_WIDTH (font
);
19843 ascent
= FONT_BASE (font
);
19844 descent
= FONT_DESCENT (font
);
19848 lowest
= - descent
+ boff
;
19849 highest
= ascent
+ boff
;
19853 && font_info
->default_ascent
19854 && CHAR_TABLE_P (Vuse_default_ascent
)
19855 && !NILP (Faref (Vuse_default_ascent
,
19856 make_number (it
->char_to_display
))))
19857 highest
= font_info
->default_ascent
+ boff
;
19859 /* Draw the first glyph at the normal position. It may be
19860 shifted to right later if some other glyphs are drawn at
19862 cmp
->offsets
[0] = 0;
19863 cmp
->offsets
[1] = boff
;
19865 /* Set cmp->offsets for the remaining glyphs. */
19866 for (i
= 1; i
< cmp
->glyph_len
; i
++)
19868 int left
, right
, btm
, top
;
19869 int ch
= COMPOSITION_GLYPH (cmp
, i
);
19870 int face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
);
19872 face
= FACE_FROM_ID (it
->f
, face_id
);
19873 get_char_face_and_encoding (it
->f
, ch
, face
->id
,
19874 &char2b
, it
->multibyte_p
, 0);
19878 font
= FRAME_FONT (it
->f
);
19879 boff
= FRAME_BASELINE_OFFSET (it
->f
);
19885 = FONT_INFO_FROM_ID (it
->f
, face
->font_info_id
);
19886 boff
= font_info
->baseline_offset
;
19887 if (font_info
->vertical_centering
)
19888 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19892 && (pcm
= rif
->per_char_metric (font
, &char2b
,
19893 FONT_TYPE_FOR_MULTIBYTE (font
, ch
))))
19895 width
= pcm
->width
;
19896 ascent
= pcm
->ascent
;
19897 descent
= pcm
->descent
;
19901 width
= FONT_WIDTH (font
);
19906 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
19908 /* Relative composition with or without
19909 alternate chars. */
19910 left
= (leftmost
+ rightmost
- width
) / 2;
19911 btm
= - descent
+ boff
;
19912 if (font_info
&& font_info
->relative_compose
19913 && (! CHAR_TABLE_P (Vignore_relative_composition
)
19914 || NILP (Faref (Vignore_relative_composition
,
19915 make_number (ch
)))))
19918 if (- descent
>= font_info
->relative_compose
)
19919 /* One extra pixel between two glyphs. */
19921 else if (ascent
<= 0)
19922 /* One extra pixel between two glyphs. */
19923 btm
= lowest
- 1 - ascent
- descent
;
19928 /* A composition rule is specified by an integer
19929 value that encodes global and new reference
19930 points (GREF and NREF). GREF and NREF are
19931 specified by numbers as below:
19933 0---1---2 -- ascent
19937 9--10--11 -- center
19939 ---3---4---5--- baseline
19941 6---7---8 -- descent
19943 int rule
= COMPOSITION_RULE (cmp
, i
);
19944 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
;
19946 COMPOSITION_DECODE_RULE (rule
, gref
, nref
);
19947 grefx
= gref
% 3, nrefx
= nref
% 3;
19948 grefy
= gref
/ 3, nrefy
= nref
/ 3;
19951 + grefx
* (rightmost
- leftmost
) / 2
19952 - nrefx
* width
/ 2);
19953 btm
= ((grefy
== 0 ? highest
19955 : grefy
== 2 ? lowest
19956 : (highest
+ lowest
) / 2)
19957 - (nrefy
== 0 ? ascent
+ descent
19958 : nrefy
== 1 ? descent
- boff
19960 : (ascent
+ descent
) / 2));
19963 cmp
->offsets
[i
* 2] = left
;
19964 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
19966 /* Update the bounding box of the overall glyphs. */
19967 right
= left
+ width
;
19968 top
= btm
+ descent
+ ascent
;
19969 if (left
< leftmost
)
19971 if (right
> rightmost
)
19979 /* If there are glyphs whose x-offsets are negative,
19980 shift all glyphs to the right and make all x-offsets
19984 for (i
= 0; i
< cmp
->glyph_len
; i
++)
19985 cmp
->offsets
[i
* 2] -= leftmost
;
19986 rightmost
-= leftmost
;
19989 cmp
->pixel_width
= rightmost
;
19990 cmp
->ascent
= highest
;
19991 cmp
->descent
= - lowest
;
19992 if (cmp
->ascent
< font_ascent
)
19993 cmp
->ascent
= font_ascent
;
19994 if (cmp
->descent
< font_descent
)
19995 cmp
->descent
= font_descent
;
19998 it
->pixel_width
= cmp
->pixel_width
;
19999 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
20000 it
->descent
= it
->phys_descent
= cmp
->descent
;
20002 if (face
->box
!= FACE_NO_BOX
)
20004 int thick
= face
->box_line_width
;
20008 it
->ascent
+= thick
;
20009 it
->descent
+= thick
;
20014 if (it
->start_of_box_run_p
)
20015 it
->pixel_width
+= thick
;
20016 if (it
->end_of_box_run_p
)
20017 it
->pixel_width
+= thick
;
20020 /* If face has an overline, add the height of the overline
20021 (1 pixel) and a 1 pixel margin to the character height. */
20022 if (face
->overline_p
)
20025 take_vertical_position_into_account (it
);
20028 append_composite_glyph (it
);
20030 else if (it
->what
== IT_IMAGE
)
20031 produce_image_glyph (it
);
20032 else if (it
->what
== IT_STRETCH
)
20033 produce_stretch_glyph (it
);
20035 /* Accumulate dimensions. Note: can't assume that it->descent > 0
20036 because this isn't true for images with `:ascent 100'. */
20037 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
20038 if (it
->area
== TEXT_AREA
)
20039 it
->current_x
+= it
->pixel_width
;
20041 if (extra_line_spacing
> 0)
20043 it
->descent
+= extra_line_spacing
;
20044 if (extra_line_spacing
> it
->max_extra_line_spacing
)
20045 it
->max_extra_line_spacing
= extra_line_spacing
;
20048 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
20049 it
->max_descent
= max (it
->max_descent
, it
->descent
);
20050 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
20051 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
20055 Output LEN glyphs starting at START at the nominal cursor position.
20056 Advance the nominal cursor over the text. The global variable
20057 updated_window contains the window being updated, updated_row is
20058 the glyph row being updated, and updated_area is the area of that
20059 row being updated. */
20062 x_write_glyphs (start
, len
)
20063 struct glyph
*start
;
20068 xassert (updated_window
&& updated_row
);
20071 /* Write glyphs. */
20073 hpos
= start
- updated_row
->glyphs
[updated_area
];
20074 x
= draw_glyphs (updated_window
, output_cursor
.x
,
20075 updated_row
, updated_area
,
20077 DRAW_NORMAL_TEXT
, 0);
20079 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
20080 if (updated_area
== TEXT_AREA
20081 && updated_window
->phys_cursor_on_p
20082 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
20083 && updated_window
->phys_cursor
.hpos
>= hpos
20084 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
20085 updated_window
->phys_cursor_on_p
= 0;
20089 /* Advance the output cursor. */
20090 output_cursor
.hpos
+= len
;
20091 output_cursor
.x
= x
;
20096 Insert LEN glyphs from START at the nominal cursor position. */
20099 x_insert_glyphs (start
, len
)
20100 struct glyph
*start
;
20105 int line_height
, shift_by_width
, shifted_region_width
;
20106 struct glyph_row
*row
;
20107 struct glyph
*glyph
;
20108 int frame_x
, frame_y
, hpos
;
20110 xassert (updated_window
&& updated_row
);
20112 w
= updated_window
;
20113 f
= XFRAME (WINDOW_FRAME (w
));
20115 /* Get the height of the line we are in. */
20117 line_height
= row
->height
;
20119 /* Get the width of the glyphs to insert. */
20120 shift_by_width
= 0;
20121 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
20122 shift_by_width
+= glyph
->pixel_width
;
20124 /* Get the width of the region to shift right. */
20125 shifted_region_width
= (window_box_width (w
, updated_area
)
20130 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
20131 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
20133 rif
->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
20134 line_height
, shift_by_width
);
20136 /* Write the glyphs. */
20137 hpos
= start
- row
->glyphs
[updated_area
];
20138 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
20140 DRAW_NORMAL_TEXT
, 0);
20142 /* Advance the output cursor. */
20143 output_cursor
.hpos
+= len
;
20144 output_cursor
.x
+= shift_by_width
;
20150 Erase the current text line from the nominal cursor position
20151 (inclusive) to pixel column TO_X (exclusive). The idea is that
20152 everything from TO_X onward is already erased.
20154 TO_X is a pixel position relative to updated_area of
20155 updated_window. TO_X == -1 means clear to the end of this area. */
20158 x_clear_end_of_line (to_x
)
20162 struct window
*w
= updated_window
;
20163 int max_x
, min_y
, max_y
;
20164 int from_x
, from_y
, to_y
;
20166 xassert (updated_window
&& updated_row
);
20167 f
= XFRAME (w
->frame
);
20169 if (updated_row
->full_width_p
)
20170 max_x
= WINDOW_TOTAL_WIDTH (w
);
20172 max_x
= window_box_width (w
, updated_area
);
20173 max_y
= window_text_bottom_y (w
);
20175 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
20176 of window. For TO_X > 0, truncate to end of drawing area. */
20182 to_x
= min (to_x
, max_x
);
20184 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
20186 /* Notice if the cursor will be cleared by this operation. */
20187 if (!updated_row
->full_width_p
)
20188 notice_overwritten_cursor (w
, updated_area
,
20189 output_cursor
.x
, -1,
20191 MATRIX_ROW_BOTTOM_Y (updated_row
));
20193 from_x
= output_cursor
.x
;
20195 /* Translate to frame coordinates. */
20196 if (updated_row
->full_width_p
)
20198 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
20199 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
20203 int area_left
= window_box_left (w
, updated_area
);
20204 from_x
+= area_left
;
20208 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
20209 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
20210 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
20212 /* Prevent inadvertently clearing to end of the X window. */
20213 if (to_x
> from_x
&& to_y
> from_y
)
20216 rif
->clear_frame_area (f
, from_x
, from_y
,
20217 to_x
- from_x
, to_y
- from_y
);
20222 #endif /* HAVE_WINDOW_SYSTEM */
20226 /***********************************************************************
20228 ***********************************************************************/
20230 /* Value is the internal representation of the specified cursor type
20231 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
20232 of the bar cursor. */
20234 static enum text_cursor_kinds
20235 get_specified_cursor_type (arg
, width
)
20239 enum text_cursor_kinds type
;
20244 if (EQ (arg
, Qbox
))
20245 return FILLED_BOX_CURSOR
;
20247 if (EQ (arg
, Qhollow
))
20248 return HOLLOW_BOX_CURSOR
;
20250 if (EQ (arg
, Qbar
))
20257 && EQ (XCAR (arg
), Qbar
)
20258 && INTEGERP (XCDR (arg
))
20259 && XINT (XCDR (arg
)) >= 0)
20261 *width
= XINT (XCDR (arg
));
20265 if (EQ (arg
, Qhbar
))
20268 return HBAR_CURSOR
;
20272 && EQ (XCAR (arg
), Qhbar
)
20273 && INTEGERP (XCDR (arg
))
20274 && XINT (XCDR (arg
)) >= 0)
20276 *width
= XINT (XCDR (arg
));
20277 return HBAR_CURSOR
;
20280 /* Treat anything unknown as "hollow box cursor".
20281 It was bad to signal an error; people have trouble fixing
20282 .Xdefaults with Emacs, when it has something bad in it. */
20283 type
= HOLLOW_BOX_CURSOR
;
20288 /* Set the default cursor types for specified frame. */
20290 set_frame_cursor_types (f
, arg
)
20297 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
20298 FRAME_CURSOR_WIDTH (f
) = width
;
20300 /* By default, set up the blink-off state depending on the on-state. */
20302 tem
= Fassoc (arg
, Vblink_cursor_alist
);
20305 FRAME_BLINK_OFF_CURSOR (f
)
20306 = get_specified_cursor_type (XCDR (tem
), &width
);
20307 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
20310 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
20314 /* Return the cursor we want to be displayed in window W. Return
20315 width of bar/hbar cursor through WIDTH arg. Return with
20316 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
20317 (i.e. if the `system caret' should track this cursor).
20319 In a mini-buffer window, we want the cursor only to appear if we
20320 are reading input from this window. For the selected window, we
20321 want the cursor type given by the frame parameter or buffer local
20322 setting of cursor-type. If explicitly marked off, draw no cursor.
20323 In all other cases, we want a hollow box cursor. */
20325 static enum text_cursor_kinds
20326 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
20328 struct glyph
*glyph
;
20330 int *active_cursor
;
20332 struct frame
*f
= XFRAME (w
->frame
);
20333 struct buffer
*b
= XBUFFER (w
->buffer
);
20334 int cursor_type
= DEFAULT_CURSOR
;
20335 Lisp_Object alt_cursor
;
20336 int non_selected
= 0;
20338 *active_cursor
= 1;
20341 if (cursor_in_echo_area
20342 && FRAME_HAS_MINIBUF_P (f
)
20343 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
20345 if (w
== XWINDOW (echo_area_window
))
20347 *width
= FRAME_CURSOR_WIDTH (f
);
20348 return FRAME_DESIRED_CURSOR (f
);
20351 *active_cursor
= 0;
20355 /* Nonselected window or nonselected frame. */
20356 else if (w
!= XWINDOW (f
->selected_window
)
20357 #ifdef HAVE_WINDOW_SYSTEM
20358 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
20362 *active_cursor
= 0;
20364 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
20370 /* Never display a cursor in a window in which cursor-type is nil. */
20371 if (NILP (b
->cursor_type
))
20374 /* Use cursor-in-non-selected-windows for non-selected window or frame. */
20377 alt_cursor
= XBUFFER (w
->buffer
)->cursor_in_non_selected_windows
;
20378 return get_specified_cursor_type (alt_cursor
, width
);
20381 /* Get the normal cursor type for this window. */
20382 if (EQ (b
->cursor_type
, Qt
))
20384 cursor_type
= FRAME_DESIRED_CURSOR (f
);
20385 *width
= FRAME_CURSOR_WIDTH (f
);
20388 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
20390 /* Use normal cursor if not blinked off. */
20391 if (!w
->cursor_off_p
)
20393 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
) {
20394 if (cursor_type
== FILLED_BOX_CURSOR
)
20395 cursor_type
= HOLLOW_BOX_CURSOR
;
20397 return cursor_type
;
20400 /* Cursor is blinked off, so determine how to "toggle" it. */
20402 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
20403 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
20404 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
20406 /* Then see if frame has specified a specific blink off cursor type. */
20407 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
20409 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
20410 return FRAME_BLINK_OFF_CURSOR (f
);
20414 /* Some people liked having a permanently visible blinking cursor,
20415 while others had very strong opinions against it. So it was
20416 decided to remove it. KFS 2003-09-03 */
20418 /* Finally perform built-in cursor blinking:
20419 filled box <-> hollow box
20420 wide [h]bar <-> narrow [h]bar
20421 narrow [h]bar <-> no cursor
20422 other type <-> no cursor */
20424 if (cursor_type
== FILLED_BOX_CURSOR
)
20425 return HOLLOW_BOX_CURSOR
;
20427 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
20430 return cursor_type
;
20438 #ifdef HAVE_WINDOW_SYSTEM
20440 /* Notice when the text cursor of window W has been completely
20441 overwritten by a drawing operation that outputs glyphs in AREA
20442 starting at X0 and ending at X1 in the line starting at Y0 and
20443 ending at Y1. X coordinates are area-relative. X1 < 0 means all
20444 the rest of the line after X0 has been written. Y coordinates
20445 are window-relative. */
20448 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
20450 enum glyph_row_area area
;
20451 int x0
, y0
, x1
, y1
;
20453 int cx0
, cx1
, cy0
, cy1
;
20454 struct glyph_row
*row
;
20456 if (!w
->phys_cursor_on_p
)
20458 if (area
!= TEXT_AREA
)
20461 if (w
->phys_cursor
.vpos
< 0
20462 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
20463 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
20464 !(row
->enabled_p
&& row
->displays_text_p
)))
20467 if (row
->cursor_in_fringe_p
)
20469 row
->cursor_in_fringe_p
= 0;
20470 draw_fringe_bitmap (w
, row
, 0);
20471 w
->phys_cursor_on_p
= 0;
20475 cx0
= w
->phys_cursor
.x
;
20476 cx1
= cx0
+ w
->phys_cursor_width
;
20477 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
20480 /* The cursor image will be completely removed from the
20481 screen if the output area intersects the cursor area in
20482 y-direction. When we draw in [y0 y1[, and some part of
20483 the cursor is at y < y0, that part must have been drawn
20484 before. When scrolling, the cursor is erased before
20485 actually scrolling, so we don't come here. When not
20486 scrolling, the rows above the old cursor row must have
20487 changed, and in this case these rows must have written
20488 over the cursor image.
20490 Likewise if part of the cursor is below y1, with the
20491 exception of the cursor being in the first blank row at
20492 the buffer and window end because update_text_area
20493 doesn't draw that row. (Except when it does, but
20494 that's handled in update_text_area.) */
20496 cy0
= w
->phys_cursor
.y
;
20497 cy1
= cy0
+ w
->phys_cursor_height
;
20498 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
20501 w
->phys_cursor_on_p
= 0;
20504 #endif /* HAVE_WINDOW_SYSTEM */
20507 /************************************************************************
20509 ************************************************************************/
20511 #ifdef HAVE_WINDOW_SYSTEM
20514 Fix the display of area AREA of overlapping row ROW in window W. */
20517 x_fix_overlapping_area (w
, row
, area
)
20519 struct glyph_row
*row
;
20520 enum glyph_row_area area
;
20527 for (i
= 0; i
< row
->used
[area
];)
20529 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
20531 int start
= i
, start_x
= x
;
20535 x
+= row
->glyphs
[area
][i
].pixel_width
;
20538 while (i
< row
->used
[area
]
20539 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
20541 draw_glyphs (w
, start_x
, row
, area
,
20543 DRAW_NORMAL_TEXT
, 1);
20547 x
+= row
->glyphs
[area
][i
].pixel_width
;
20557 Draw the cursor glyph of window W in glyph row ROW. See the
20558 comment of draw_glyphs for the meaning of HL. */
20561 draw_phys_cursor_glyph (w
, row
, hl
)
20563 struct glyph_row
*row
;
20564 enum draw_glyphs_face hl
;
20566 /* If cursor hpos is out of bounds, don't draw garbage. This can
20567 happen in mini-buffer windows when switching between echo area
20568 glyphs and mini-buffer. */
20569 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
20571 int on_p
= w
->phys_cursor_on_p
;
20573 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
20574 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
20576 w
->phys_cursor_on_p
= on_p
;
20578 if (hl
== DRAW_CURSOR
)
20579 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
20580 /* When we erase the cursor, and ROW is overlapped by other
20581 rows, make sure that these overlapping parts of other rows
20583 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
20585 if (row
> w
->current_matrix
->rows
20586 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
20587 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
);
20589 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
20590 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
20591 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
);
20598 Erase the image of a cursor of window W from the screen. */
20601 erase_phys_cursor (w
)
20604 struct frame
*f
= XFRAME (w
->frame
);
20605 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20606 int hpos
= w
->phys_cursor
.hpos
;
20607 int vpos
= w
->phys_cursor
.vpos
;
20608 int mouse_face_here_p
= 0;
20609 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
20610 struct glyph_row
*cursor_row
;
20611 struct glyph
*cursor_glyph
;
20612 enum draw_glyphs_face hl
;
20614 /* No cursor displayed or row invalidated => nothing to do on the
20616 if (w
->phys_cursor_type
== NO_CURSOR
)
20617 goto mark_cursor_off
;
20619 /* VPOS >= active_glyphs->nrows means that window has been resized.
20620 Don't bother to erase the cursor. */
20621 if (vpos
>= active_glyphs
->nrows
)
20622 goto mark_cursor_off
;
20624 /* If row containing cursor is marked invalid, there is nothing we
20626 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
20627 if (!cursor_row
->enabled_p
)
20628 goto mark_cursor_off
;
20630 /* If line spacing is > 0, old cursor may only be partially visible in
20631 window after split-window. So adjust visible height. */
20632 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
20633 window_text_bottom_y (w
) - cursor_row
->y
);
20635 /* If row is completely invisible, don't attempt to delete a cursor which
20636 isn't there. This can happen if cursor is at top of a window, and
20637 we switch to a buffer with a header line in that window. */
20638 if (cursor_row
->visible_height
<= 0)
20639 goto mark_cursor_off
;
20641 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
20642 if (cursor_row
->cursor_in_fringe_p
)
20644 cursor_row
->cursor_in_fringe_p
= 0;
20645 draw_fringe_bitmap (w
, cursor_row
, 0);
20646 goto mark_cursor_off
;
20649 /* This can happen when the new row is shorter than the old one.
20650 In this case, either draw_glyphs or clear_end_of_line
20651 should have cleared the cursor. Note that we wouldn't be
20652 able to erase the cursor in this case because we don't have a
20653 cursor glyph at hand. */
20654 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
20655 goto mark_cursor_off
;
20657 /* If the cursor is in the mouse face area, redisplay that when
20658 we clear the cursor. */
20659 if (! NILP (dpyinfo
->mouse_face_window
)
20660 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
20661 && (vpos
> dpyinfo
->mouse_face_beg_row
20662 || (vpos
== dpyinfo
->mouse_face_beg_row
20663 && hpos
>= dpyinfo
->mouse_face_beg_col
))
20664 && (vpos
< dpyinfo
->mouse_face_end_row
20665 || (vpos
== dpyinfo
->mouse_face_end_row
20666 && hpos
< dpyinfo
->mouse_face_end_col
))
20667 /* Don't redraw the cursor's spot in mouse face if it is at the
20668 end of a line (on a newline). The cursor appears there, but
20669 mouse highlighting does not. */
20670 && cursor_row
->used
[TEXT_AREA
] > hpos
)
20671 mouse_face_here_p
= 1;
20673 /* Maybe clear the display under the cursor. */
20674 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
20677 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
20680 cursor_glyph
= get_phys_cursor_glyph (w
);
20681 if (cursor_glyph
== NULL
)
20682 goto mark_cursor_off
;
20684 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
20685 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
20686 width
= min (cursor_glyph
->pixel_width
,
20687 window_box_width (w
, TEXT_AREA
) - w
->phys_cursor
.x
);
20689 rif
->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
20692 /* Erase the cursor by redrawing the character underneath it. */
20693 if (mouse_face_here_p
)
20694 hl
= DRAW_MOUSE_FACE
;
20696 hl
= DRAW_NORMAL_TEXT
;
20697 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
20700 w
->phys_cursor_on_p
= 0;
20701 w
->phys_cursor_type
= NO_CURSOR
;
20706 Display or clear cursor of window W. If ON is zero, clear the
20707 cursor. If it is non-zero, display the cursor. If ON is nonzero,
20708 where to put the cursor is specified by HPOS, VPOS, X and Y. */
20711 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
20713 int on
, hpos
, vpos
, x
, y
;
20715 struct frame
*f
= XFRAME (w
->frame
);
20716 int new_cursor_type
;
20717 int new_cursor_width
;
20719 struct glyph_row
*glyph_row
;
20720 struct glyph
*glyph
;
20722 /* This is pointless on invisible frames, and dangerous on garbaged
20723 windows and frames; in the latter case, the frame or window may
20724 be in the midst of changing its size, and x and y may be off the
20726 if (! FRAME_VISIBLE_P (f
)
20727 || FRAME_GARBAGED_P (f
)
20728 || vpos
>= w
->current_matrix
->nrows
20729 || hpos
>= w
->current_matrix
->matrix_w
)
20732 /* If cursor is off and we want it off, return quickly. */
20733 if (!on
&& !w
->phys_cursor_on_p
)
20736 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
20737 /* If cursor row is not enabled, we don't really know where to
20738 display the cursor. */
20739 if (!glyph_row
->enabled_p
)
20741 w
->phys_cursor_on_p
= 0;
20746 if (!glyph_row
->exact_window_width_line_p
20747 || hpos
< glyph_row
->used
[TEXT_AREA
])
20748 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
20750 xassert (interrupt_input_blocked
);
20752 /* Set new_cursor_type to the cursor we want to be displayed. */
20753 new_cursor_type
= get_window_cursor_type (w
, glyph
,
20754 &new_cursor_width
, &active_cursor
);
20756 /* If cursor is currently being shown and we don't want it to be or
20757 it is in the wrong place, or the cursor type is not what we want,
20759 if (w
->phys_cursor_on_p
20761 || w
->phys_cursor
.x
!= x
20762 || w
->phys_cursor
.y
!= y
20763 || new_cursor_type
!= w
->phys_cursor_type
20764 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
20765 && new_cursor_width
!= w
->phys_cursor_width
)))
20766 erase_phys_cursor (w
);
20768 /* Don't check phys_cursor_on_p here because that flag is only set
20769 to zero in some cases where we know that the cursor has been
20770 completely erased, to avoid the extra work of erasing the cursor
20771 twice. In other words, phys_cursor_on_p can be 1 and the cursor
20772 still not be visible, or it has only been partly erased. */
20775 w
->phys_cursor_ascent
= glyph_row
->ascent
;
20776 w
->phys_cursor_height
= glyph_row
->height
;
20778 /* Set phys_cursor_.* before x_draw_.* is called because some
20779 of them may need the information. */
20780 w
->phys_cursor
.x
= x
;
20781 w
->phys_cursor
.y
= glyph_row
->y
;
20782 w
->phys_cursor
.hpos
= hpos
;
20783 w
->phys_cursor
.vpos
= vpos
;
20786 rif
->draw_window_cursor (w
, glyph_row
, x
, y
,
20787 new_cursor_type
, new_cursor_width
,
20788 on
, active_cursor
);
20792 /* Switch the display of W's cursor on or off, according to the value
20796 update_window_cursor (w
, on
)
20800 /* Don't update cursor in windows whose frame is in the process
20801 of being deleted. */
20802 if (w
->current_matrix
)
20805 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20806 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20812 /* Call update_window_cursor with parameter ON_P on all leaf windows
20813 in the window tree rooted at W. */
20816 update_cursor_in_window_tree (w
, on_p
)
20822 if (!NILP (w
->hchild
))
20823 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
20824 else if (!NILP (w
->vchild
))
20825 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
20827 update_window_cursor (w
, on_p
);
20829 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
20835 Display the cursor on window W, or clear it, according to ON_P.
20836 Don't change the cursor's position. */
20839 x_update_cursor (f
, on_p
)
20843 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
20848 Clear the cursor of window W to background color, and mark the
20849 cursor as not shown. This is used when the text where the cursor
20850 is is about to be rewritten. */
20856 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
20857 update_window_cursor (w
, 0);
20862 Display the active region described by mouse_face_* according to DRAW. */
20865 show_mouse_face (dpyinfo
, draw
)
20866 Display_Info
*dpyinfo
;
20867 enum draw_glyphs_face draw
;
20869 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
20870 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20872 if (/* If window is in the process of being destroyed, don't bother
20874 w
->current_matrix
!= NULL
20875 /* Don't update mouse highlight if hidden */
20876 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
20877 /* Recognize when we are called to operate on rows that don't exist
20878 anymore. This can happen when a window is split. */
20879 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
20881 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
20882 struct glyph_row
*row
, *first
, *last
;
20884 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20885 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20887 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
20889 int start_hpos
, end_hpos
, start_x
;
20891 /* For all but the first row, the highlight starts at column 0. */
20894 start_hpos
= dpyinfo
->mouse_face_beg_col
;
20895 start_x
= dpyinfo
->mouse_face_beg_x
;
20904 end_hpos
= dpyinfo
->mouse_face_end_col
;
20906 end_hpos
= row
->used
[TEXT_AREA
];
20908 if (end_hpos
> start_hpos
)
20910 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
20911 start_hpos
, end_hpos
,
20915 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
20919 /* When we've written over the cursor, arrange for it to
20920 be displayed again. */
20921 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
20924 display_and_set_cursor (w
, 1,
20925 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
20926 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
20931 /* Change the mouse cursor. */
20932 if (draw
== DRAW_NORMAL_TEXT
)
20933 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
20934 else if (draw
== DRAW_MOUSE_FACE
)
20935 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
20937 rif
->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
20941 Clear out the mouse-highlighted active region.
20942 Redraw it un-highlighted first. Value is non-zero if mouse
20943 face was actually drawn unhighlighted. */
20946 clear_mouse_face (dpyinfo
)
20947 Display_Info
*dpyinfo
;
20951 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
20953 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
20957 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
20958 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
20959 dpyinfo
->mouse_face_window
= Qnil
;
20960 dpyinfo
->mouse_face_overlay
= Qnil
;
20966 Non-zero if physical cursor of window W is within mouse face. */
20969 cursor_in_mouse_face_p (w
)
20972 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
20973 int in_mouse_face
= 0;
20975 if (WINDOWP (dpyinfo
->mouse_face_window
)
20976 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
20978 int hpos
= w
->phys_cursor
.hpos
;
20979 int vpos
= w
->phys_cursor
.vpos
;
20981 if (vpos
>= dpyinfo
->mouse_face_beg_row
20982 && vpos
<= dpyinfo
->mouse_face_end_row
20983 && (vpos
> dpyinfo
->mouse_face_beg_row
20984 || hpos
>= dpyinfo
->mouse_face_beg_col
)
20985 && (vpos
< dpyinfo
->mouse_face_end_row
20986 || hpos
< dpyinfo
->mouse_face_end_col
20987 || dpyinfo
->mouse_face_past_end
))
20991 return in_mouse_face
;
20997 /* Find the glyph matrix position of buffer position CHARPOS in window
20998 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
20999 current glyphs must be up to date. If CHARPOS is above window
21000 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
21001 of last line in W. In the row containing CHARPOS, stop before glyphs
21002 having STOP as object. */
21004 #if 1 /* This is a version of fast_find_position that's more correct
21005 in the presence of hscrolling, for example. I didn't install
21006 it right away because the problem fixed is minor, it failed
21007 in 20.x as well, and I think it's too risky to install
21008 so near the release of 21.1. 2001-09-25 gerd. */
21011 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
21014 int *hpos
, *vpos
, *x
, *y
;
21017 struct glyph_row
*row
, *first
;
21018 struct glyph
*glyph
, *end
;
21021 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21022 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
21027 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
21031 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
21034 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
21038 /* If whole rows or last part of a row came from a display overlay,
21039 row_containing_pos will skip over such rows because their end pos
21040 equals the start pos of the overlay or interval.
21042 Move back if we have a STOP object and previous row's
21043 end glyph came from STOP. */
21046 struct glyph_row
*prev
;
21047 while ((prev
= row
- 1, prev
>= first
)
21048 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
21049 && prev
->used
[TEXT_AREA
] > 0)
21051 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
21052 glyph
= beg
+ prev
->used
[TEXT_AREA
];
21053 while (--glyph
>= beg
21054 && INTEGERP (glyph
->object
));
21056 || !EQ (stop
, glyph
->object
))
21064 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21066 glyph
= row
->glyphs
[TEXT_AREA
];
21067 end
= glyph
+ row
->used
[TEXT_AREA
];
21069 /* Skip over glyphs not having an object at the start of the row.
21070 These are special glyphs like truncation marks on terminal
21072 if (row
->displays_text_p
)
21074 && INTEGERP (glyph
->object
)
21075 && !EQ (stop
, glyph
->object
)
21076 && glyph
->charpos
< 0)
21078 *x
+= glyph
->pixel_width
;
21083 && !INTEGERP (glyph
->object
)
21084 && !EQ (stop
, glyph
->object
)
21085 && (!BUFFERP (glyph
->object
)
21086 || glyph
->charpos
< charpos
))
21088 *x
+= glyph
->pixel_width
;
21092 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
21099 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
21102 int *hpos
, *vpos
, *x
, *y
;
21107 int maybe_next_line_p
= 0;
21108 int line_start_position
;
21109 int yb
= window_text_bottom_y (w
);
21110 struct glyph_row
*row
, *best_row
;
21111 int row_vpos
, best_row_vpos
;
21114 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21115 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
21117 while (row
->y
< yb
)
21119 if (row
->used
[TEXT_AREA
])
21120 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
21122 line_start_position
= 0;
21124 if (line_start_position
> pos
)
21126 /* If the position sought is the end of the buffer,
21127 don't include the blank lines at the bottom of the window. */
21128 else if (line_start_position
== pos
21129 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
21131 maybe_next_line_p
= 1;
21134 else if (line_start_position
> 0)
21137 best_row_vpos
= row_vpos
;
21140 if (row
->y
+ row
->height
>= yb
)
21147 /* Find the right column within BEST_ROW. */
21149 current_x
= best_row
->x
;
21150 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
21152 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
21153 int charpos
= glyph
->charpos
;
21155 if (BUFFERP (glyph
->object
))
21157 if (charpos
== pos
)
21160 *vpos
= best_row_vpos
;
21165 else if (charpos
> pos
)
21168 else if (EQ (glyph
->object
, stop
))
21173 current_x
+= glyph
->pixel_width
;
21176 /* If we're looking for the end of the buffer,
21177 and we didn't find it in the line we scanned,
21178 use the start of the following line. */
21179 if (maybe_next_line_p
)
21184 current_x
= best_row
->x
;
21187 *vpos
= best_row_vpos
;
21188 *hpos
= lastcol
+ 1;
21197 /* Find the position of the glyph for position POS in OBJECT in
21198 window W's current matrix, and return in *X, *Y the pixel
21199 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
21201 RIGHT_P non-zero means return the position of the right edge of the
21202 glyph, RIGHT_P zero means return the left edge position.
21204 If no glyph for POS exists in the matrix, return the position of
21205 the glyph with the next smaller position that is in the matrix, if
21206 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
21207 exists in the matrix, return the position of the glyph with the
21208 next larger position in OBJECT.
21210 Value is non-zero if a glyph was found. */
21213 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
21216 Lisp_Object object
;
21217 int *hpos
, *vpos
, *x
, *y
;
21220 int yb
= window_text_bottom_y (w
);
21221 struct glyph_row
*r
;
21222 struct glyph
*best_glyph
= NULL
;
21223 struct glyph_row
*best_row
= NULL
;
21226 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
21227 r
->enabled_p
&& r
->y
< yb
;
21230 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
21231 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
21234 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
21235 if (EQ (g
->object
, object
))
21237 if (g
->charpos
== pos
)
21244 else if (best_glyph
== NULL
21245 || ((abs (g
->charpos
- pos
)
21246 < abs (best_glyph
->charpos
- pos
))
21249 : g
->charpos
> pos
)))
21263 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
21267 *x
+= best_glyph
->pixel_width
;
21272 *vpos
= best_row
- w
->current_matrix
->rows
;
21275 return best_glyph
!= NULL
;
21279 /* See if position X, Y is within a hot-spot of an image. */
21282 on_hot_spot_p (hot_spot
, x
, y
)
21283 Lisp_Object hot_spot
;
21286 if (!CONSP (hot_spot
))
21289 if (EQ (XCAR (hot_spot
), Qrect
))
21291 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
21292 Lisp_Object rect
= XCDR (hot_spot
);
21296 if (!CONSP (XCAR (rect
)))
21298 if (!CONSP (XCDR (rect
)))
21300 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
21302 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
21304 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
21306 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
21310 else if (EQ (XCAR (hot_spot
), Qcircle
))
21312 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
21313 Lisp_Object circ
= XCDR (hot_spot
);
21314 Lisp_Object lr
, lx0
, ly0
;
21316 && CONSP (XCAR (circ
))
21317 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
21318 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
21319 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
21321 double r
= XFLOATINT (lr
);
21322 double dx
= XINT (lx0
) - x
;
21323 double dy
= XINT (ly0
) - y
;
21324 return (dx
* dx
+ dy
* dy
<= r
* r
);
21327 else if (EQ (XCAR (hot_spot
), Qpoly
))
21329 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
21330 if (VECTORP (XCDR (hot_spot
)))
21332 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
21333 Lisp_Object
*poly
= v
->contents
;
21337 Lisp_Object lx
, ly
;
21340 /* Need an even number of coordinates, and at least 3 edges. */
21341 if (n
< 6 || n
& 1)
21344 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
21345 If count is odd, we are inside polygon. Pixels on edges
21346 may or may not be included depending on actual geometry of the
21348 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
21349 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
21351 x0
= XINT (lx
), y0
= XINT (ly
);
21352 for (i
= 0; i
< n
; i
+= 2)
21354 int x1
= x0
, y1
= y0
;
21355 if ((lx
= poly
[i
], !INTEGERP (lx
))
21356 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
21358 x0
= XINT (lx
), y0
= XINT (ly
);
21360 /* Does this segment cross the X line? */
21368 if (y
> y0
&& y
> y1
)
21370 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
21376 /* If we don't understand the format, pretend we're not in the hot-spot. */
21381 find_hot_spot (map
, x
, y
)
21385 while (CONSP (map
))
21387 if (CONSP (XCAR (map
))
21388 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
21396 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
21398 doc
: /* Lookup in image map MAP coordinates X and Y.
21399 An image map is an alist where each element has the format (AREA ID PLIST).
21400 An AREA is specified as either a rectangle, a circle, or a polygon:
21401 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
21402 pixel coordinates of the upper left and bottom right corners.
21403 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
21404 and the radius of the circle; r may be a float or integer.
21405 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
21406 vector describes one corner in the polygon.
21407 Returns the alist element for the first matching AREA in MAP. */)
21418 return find_hot_spot (map
, XINT (x
), XINT (y
));
21422 /* Display frame CURSOR, optionally using shape defined by POINTER. */
21424 define_frame_cursor1 (f
, cursor
, pointer
)
21427 Lisp_Object pointer
;
21429 /* Do not change cursor shape while dragging mouse. */
21430 if (!NILP (do_mouse_tracking
))
21433 if (!NILP (pointer
))
21435 if (EQ (pointer
, Qarrow
))
21436 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21437 else if (EQ (pointer
, Qhand
))
21438 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
21439 else if (EQ (pointer
, Qtext
))
21440 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21441 else if (EQ (pointer
, intern ("hdrag")))
21442 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21443 #ifdef HAVE_X_WINDOWS
21444 else if (EQ (pointer
, intern ("vdrag")))
21445 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
21447 else if (EQ (pointer
, intern ("hourglass")))
21448 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
21449 else if (EQ (pointer
, Qmodeline
))
21450 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
21452 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21455 if (cursor
!= No_Cursor
)
21456 rif
->define_frame_cursor (f
, cursor
);
21459 /* Take proper action when mouse has moved to the mode or header line
21460 or marginal area AREA of window W, x-position X and y-position Y.
21461 X is relative to the start of the text display area of W, so the
21462 width of bitmap areas and scroll bars must be subtracted to get a
21463 position relative to the start of the mode line. */
21466 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
21467 Lisp_Object window
;
21469 enum window_part area
;
21471 struct window
*w
= XWINDOW (window
);
21472 struct frame
*f
= XFRAME (w
->frame
);
21473 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21474 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21475 Lisp_Object pointer
= Qnil
;
21476 int charpos
, dx
, dy
, width
, height
;
21477 Lisp_Object string
, object
= Qnil
;
21478 Lisp_Object pos
, help
;
21480 Lisp_Object mouse_face
;
21481 int original_x_pixel
= x
;
21482 struct glyph
* glyph
= NULL
;
21483 struct glyph_row
*row
;
21485 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
21490 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
21491 &object
, &dx
, &dy
, &width
, &height
);
21493 row
= (area
== ON_MODE_LINE
21494 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
21495 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
21498 if (row
->mode_line_p
&& row
->enabled_p
)
21500 glyph
= row
->glyphs
[TEXT_AREA
];
21501 end
= glyph
+ row
->used
[TEXT_AREA
];
21503 for (x0
= original_x_pixel
;
21504 glyph
< end
&& x0
>= glyph
->pixel_width
;
21506 x0
-= glyph
->pixel_width
;
21514 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
21515 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
21516 &object
, &dx
, &dy
, &width
, &height
);
21521 if (IMAGEP (object
))
21523 Lisp_Object image_map
, hotspot
;
21524 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
21526 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
21528 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21530 Lisp_Object area_id
, plist
;
21532 area_id
= XCAR (hotspot
);
21533 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21534 If so, we could look for mouse-enter, mouse-leave
21535 properties in PLIST (and do something...). */
21536 hotspot
= XCDR (hotspot
);
21537 if (CONSP (hotspot
)
21538 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21540 pointer
= Fplist_get (plist
, Qpointer
);
21541 if (NILP (pointer
))
21543 help
= Fplist_get (plist
, Qhelp_echo
);
21546 help_echo_string
= help
;
21547 /* Is this correct? ++kfs */
21548 XSETWINDOW (help_echo_window
, w
);
21549 help_echo_object
= w
->buffer
;
21550 help_echo_pos
= charpos
;
21554 if (NILP (pointer
))
21555 pointer
= Fplist_get (XCDR (object
), QCpointer
);
21558 if (STRINGP (string
))
21560 pos
= make_number (charpos
);
21561 /* If we're on a string with `help-echo' text property, arrange
21562 for the help to be displayed. This is done by setting the
21563 global variable help_echo_string to the help string. */
21566 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
21569 help_echo_string
= help
;
21570 XSETWINDOW (help_echo_window
, w
);
21571 help_echo_object
= string
;
21572 help_echo_pos
= charpos
;
21576 if (NILP (pointer
))
21577 pointer
= Fget_text_property (pos
, Qpointer
, string
);
21579 /* Change the mouse pointer according to what is under X/Y. */
21580 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
21583 map
= Fget_text_property (pos
, Qlocal_map
, string
);
21584 if (!KEYMAPP (map
))
21585 map
= Fget_text_property (pos
, Qkeymap
, string
);
21586 if (!KEYMAPP (map
))
21587 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
21590 /* Change the mouse face according to what is under X/Y. */
21591 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
21592 if (!NILP (mouse_face
)
21593 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21598 struct glyph
* tmp_glyph
;
21602 int total_pixel_width
;
21607 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
21608 Qmouse_face
, string
, Qnil
);
21610 b
= make_number (0);
21612 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
21614 e
= make_number (SCHARS (string
));
21616 /* Calculate the position(glyph position: GPOS) of GLYPH in
21617 displayed string. GPOS is different from CHARPOS.
21619 CHARPOS is the position of glyph in internal string
21620 object. A mode line string format has structures which
21621 is converted to a flatten by emacs lisp interpreter.
21622 The internal string is an element of the structures.
21623 The displayed string is the flatten string. */
21624 for (tmp_glyph
= glyph
- 1, gpos
= 0;
21625 tmp_glyph
->charpos
>= XINT (b
);
21626 tmp_glyph
--, gpos
++)
21628 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21632 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
21633 displayed string holding GLYPH.
21635 GSEQ_LENGTH is different from SCHARS (STRING).
21636 SCHARS (STRING) returns the length of the internal string. */
21637 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
21638 tmp_glyph
->charpos
< XINT (e
);
21639 tmp_glyph
++, gseq_length
++)
21641 if (!EQ (tmp_glyph
->object
, glyph
->object
))
21645 total_pixel_width
= 0;
21646 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
21647 total_pixel_width
+= tmp_glyph
->pixel_width
;
21649 /* Pre calculation of re-rendering position */
21651 hpos
= (area
== ON_MODE_LINE
21652 ? (w
->current_matrix
)->nrows
- 1
21655 /* If the re-rendering position is included in the last
21656 re-rendering area, we should do nothing. */
21657 if ( EQ (window
, dpyinfo
->mouse_face_window
)
21658 && dpyinfo
->mouse_face_beg_col
<= vpos
21659 && vpos
< dpyinfo
->mouse_face_end_col
21660 && dpyinfo
->mouse_face_beg_row
== hpos
)
21663 if (clear_mouse_face (dpyinfo
))
21664 cursor
= No_Cursor
;
21666 dpyinfo
->mouse_face_beg_col
= vpos
;
21667 dpyinfo
->mouse_face_beg_row
= hpos
;
21669 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
21670 dpyinfo
->mouse_face_beg_y
= 0;
21672 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
21673 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
21675 dpyinfo
->mouse_face_end_x
= 0;
21676 dpyinfo
->mouse_face_end_y
= 0;
21678 dpyinfo
->mouse_face_past_end
= 0;
21679 dpyinfo
->mouse_face_window
= window
;
21681 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
21684 glyph
->face_id
, 1);
21685 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21687 if (NILP (pointer
))
21690 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
21691 clear_mouse_face (dpyinfo
);
21693 define_frame_cursor1 (f
, cursor
, pointer
);
21698 Take proper action when the mouse has moved to position X, Y on
21699 frame F as regards highlighting characters that have mouse-face
21700 properties. Also de-highlighting chars where the mouse was before.
21701 X and Y can be negative or out of range. */
21704 note_mouse_highlight (f
, x
, y
)
21708 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21709 enum window_part part
;
21710 Lisp_Object window
;
21712 Cursor cursor
= No_Cursor
;
21713 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
21716 /* When a menu is active, don't highlight because this looks odd. */
21717 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NTGUI)
21718 if (popup_activated ())
21722 if (NILP (Vmouse_highlight
)
21723 || !f
->glyphs_initialized_p
)
21726 dpyinfo
->mouse_face_mouse_x
= x
;
21727 dpyinfo
->mouse_face_mouse_y
= y
;
21728 dpyinfo
->mouse_face_mouse_frame
= f
;
21730 if (dpyinfo
->mouse_face_defer
)
21733 if (gc_in_progress
)
21735 dpyinfo
->mouse_face_deferred_gc
= 1;
21739 /* Which window is that in? */
21740 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
21742 /* If we were displaying active text in another window, clear that.
21743 Also clear if we move out of text area in same window. */
21744 if (! EQ (window
, dpyinfo
->mouse_face_window
)
21745 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
21746 && !NILP (dpyinfo
->mouse_face_window
)))
21747 clear_mouse_face (dpyinfo
);
21749 /* Not on a window -> return. */
21750 if (!WINDOWP (window
))
21753 /* Reset help_echo_string. It will get recomputed below. */
21754 help_echo_string
= Qnil
;
21756 /* Convert to window-relative pixel coordinates. */
21757 w
= XWINDOW (window
);
21758 frame_to_window_pixel_xy (w
, &x
, &y
);
21760 /* Handle tool-bar window differently since it doesn't display a
21762 if (EQ (window
, f
->tool_bar_window
))
21764 note_tool_bar_highlight (f
, x
, y
);
21768 /* Mouse is on the mode, header line or margin? */
21769 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
21770 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
21772 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
21776 if (part
== ON_VERTICAL_BORDER
)
21777 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
21778 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
21779 || part
== ON_SCROLL_BAR
)
21780 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21782 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
21784 /* Are we in a window whose display is up to date?
21785 And verify the buffer's text has not changed. */
21786 b
= XBUFFER (w
->buffer
);
21787 if (part
== ON_TEXT
21788 && EQ (w
->window_end_valid
, w
->buffer
)
21789 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
21790 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
21792 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
21793 struct glyph
*glyph
;
21794 Lisp_Object object
;
21795 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
21796 Lisp_Object
*overlay_vec
= NULL
;
21798 struct buffer
*obuf
;
21799 int obegv
, ozv
, same_region
;
21801 /* Find the glyph under X/Y. */
21802 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
21804 /* Look for :pointer property on image. */
21805 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
21807 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
21808 if (img
!= NULL
&& IMAGEP (img
->spec
))
21810 Lisp_Object image_map
, hotspot
;
21811 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
21813 && (hotspot
= find_hot_spot (image_map
,
21814 glyph
->slice
.x
+ dx
,
21815 glyph
->slice
.y
+ dy
),
21817 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
21819 Lisp_Object area_id
, plist
;
21821 area_id
= XCAR (hotspot
);
21822 /* Could check AREA_ID to see if we enter/leave this hot-spot.
21823 If so, we could look for mouse-enter, mouse-leave
21824 properties in PLIST (and do something...). */
21825 hotspot
= XCDR (hotspot
);
21826 if (CONSP (hotspot
)
21827 && (plist
= XCAR (hotspot
), CONSP (plist
)))
21829 pointer
= Fplist_get (plist
, Qpointer
);
21830 if (NILP (pointer
))
21832 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
21833 if (!NILP (help_echo_string
))
21835 help_echo_window
= window
;
21836 help_echo_object
= glyph
->object
;
21837 help_echo_pos
= glyph
->charpos
;
21841 if (NILP (pointer
))
21842 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
21846 /* Clear mouse face if X/Y not over text. */
21848 || area
!= TEXT_AREA
21849 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
21851 if (clear_mouse_face (dpyinfo
))
21852 cursor
= No_Cursor
;
21853 if (NILP (pointer
))
21855 if (area
!= TEXT_AREA
)
21856 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
21858 pointer
= Vvoid_text_area_pointer
;
21863 pos
= glyph
->charpos
;
21864 object
= glyph
->object
;
21865 if (!STRINGP (object
) && !BUFFERP (object
))
21868 /* If we get an out-of-range value, return now; avoid an error. */
21869 if (BUFFERP (object
) && pos
> BUF_Z (b
))
21872 /* Make the window's buffer temporarily current for
21873 overlays_at and compute_char_face. */
21874 obuf
= current_buffer
;
21875 current_buffer
= b
;
21881 /* Is this char mouse-active or does it have help-echo? */
21882 position
= make_number (pos
);
21884 if (BUFFERP (object
))
21886 /* Put all the overlays we want in a vector in overlay_vec. */
21887 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
21888 /* Sort overlays into increasing priority order. */
21889 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
21894 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
21895 && vpos
>= dpyinfo
->mouse_face_beg_row
21896 && vpos
<= dpyinfo
->mouse_face_end_row
21897 && (vpos
> dpyinfo
->mouse_face_beg_row
21898 || hpos
>= dpyinfo
->mouse_face_beg_col
)
21899 && (vpos
< dpyinfo
->mouse_face_end_row
21900 || hpos
< dpyinfo
->mouse_face_end_col
21901 || dpyinfo
->mouse_face_past_end
));
21904 cursor
= No_Cursor
;
21906 /* Check mouse-face highlighting. */
21908 /* If there exists an overlay with mouse-face overlapping
21909 the one we are currently highlighting, we have to
21910 check if we enter the overlapping overlay, and then
21911 highlight only that. */
21912 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
21913 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
21915 /* Find the highest priority overlay that has a mouse-face
21918 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
21920 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
21921 if (!NILP (mouse_face
))
21922 overlay
= overlay_vec
[i
];
21925 /* If we're actually highlighting the same overlay as
21926 before, there's no need to do that again. */
21927 if (!NILP (overlay
)
21928 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
21929 goto check_help_echo
;
21931 dpyinfo
->mouse_face_overlay
= overlay
;
21933 /* Clear the display of the old active region, if any. */
21934 if (clear_mouse_face (dpyinfo
))
21935 cursor
= No_Cursor
;
21937 /* If no overlay applies, get a text property. */
21938 if (NILP (overlay
))
21939 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
21941 /* Handle the overlay case. */
21942 if (!NILP (overlay
))
21944 /* Find the range of text around this char that
21945 should be active. */
21946 Lisp_Object before
, after
;
21949 before
= Foverlay_start (overlay
);
21950 after
= Foverlay_end (overlay
);
21951 /* Record this as the current active region. */
21952 fast_find_position (w
, XFASTINT (before
),
21953 &dpyinfo
->mouse_face_beg_col
,
21954 &dpyinfo
->mouse_face_beg_row
,
21955 &dpyinfo
->mouse_face_beg_x
,
21956 &dpyinfo
->mouse_face_beg_y
, Qnil
);
21958 dpyinfo
->mouse_face_past_end
21959 = !fast_find_position (w
, XFASTINT (after
),
21960 &dpyinfo
->mouse_face_end_col
,
21961 &dpyinfo
->mouse_face_end_row
,
21962 &dpyinfo
->mouse_face_end_x
,
21963 &dpyinfo
->mouse_face_end_y
, Qnil
);
21964 dpyinfo
->mouse_face_window
= window
;
21966 dpyinfo
->mouse_face_face_id
21967 = face_at_buffer_position (w
, pos
, 0, 0,
21969 !dpyinfo
->mouse_face_hidden
);
21971 /* Display it as active. */
21972 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
21973 cursor
= No_Cursor
;
21975 /* Handle the text property case. */
21976 else if (!NILP (mouse_face
) && BUFFERP (object
))
21978 /* Find the range of text around this char that
21979 should be active. */
21980 Lisp_Object before
, after
, beginning
, end
;
21983 beginning
= Fmarker_position (w
->start
);
21984 end
= make_number (BUF_Z (XBUFFER (object
))
21985 - XFASTINT (w
->window_end_pos
));
21987 = Fprevious_single_property_change (make_number (pos
+ 1),
21989 object
, beginning
);
21991 = Fnext_single_property_change (position
, Qmouse_face
,
21994 /* Record this as the current active region. */
21995 fast_find_position (w
, XFASTINT (before
),
21996 &dpyinfo
->mouse_face_beg_col
,
21997 &dpyinfo
->mouse_face_beg_row
,
21998 &dpyinfo
->mouse_face_beg_x
,
21999 &dpyinfo
->mouse_face_beg_y
, Qnil
);
22000 dpyinfo
->mouse_face_past_end
22001 = !fast_find_position (w
, XFASTINT (after
),
22002 &dpyinfo
->mouse_face_end_col
,
22003 &dpyinfo
->mouse_face_end_row
,
22004 &dpyinfo
->mouse_face_end_x
,
22005 &dpyinfo
->mouse_face_end_y
, Qnil
);
22006 dpyinfo
->mouse_face_window
= window
;
22008 if (BUFFERP (object
))
22009 dpyinfo
->mouse_face_face_id
22010 = face_at_buffer_position (w
, pos
, 0, 0,
22012 !dpyinfo
->mouse_face_hidden
);
22014 /* Display it as active. */
22015 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22016 cursor
= No_Cursor
;
22018 else if (!NILP (mouse_face
) && STRINGP (object
))
22023 b
= Fprevious_single_property_change (make_number (pos
+ 1),
22026 e
= Fnext_single_property_change (position
, Qmouse_face
,
22029 b
= make_number (0);
22031 e
= make_number (SCHARS (object
) - 1);
22033 fast_find_string_pos (w
, XINT (b
), object
,
22034 &dpyinfo
->mouse_face_beg_col
,
22035 &dpyinfo
->mouse_face_beg_row
,
22036 &dpyinfo
->mouse_face_beg_x
,
22037 &dpyinfo
->mouse_face_beg_y
, 0);
22038 fast_find_string_pos (w
, XINT (e
), object
,
22039 &dpyinfo
->mouse_face_end_col
,
22040 &dpyinfo
->mouse_face_end_row
,
22041 &dpyinfo
->mouse_face_end_x
,
22042 &dpyinfo
->mouse_face_end_y
, 1);
22043 dpyinfo
->mouse_face_past_end
= 0;
22044 dpyinfo
->mouse_face_window
= window
;
22045 dpyinfo
->mouse_face_face_id
22046 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
22047 glyph
->face_id
, 1);
22048 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22049 cursor
= No_Cursor
;
22051 else if (STRINGP (object
) && NILP (mouse_face
))
22053 /* A string which doesn't have mouse-face, but
22054 the text ``under'' it might have. */
22055 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
22056 int start
= MATRIX_ROW_START_CHARPOS (r
);
22058 pos
= string_buffer_position (w
, object
, start
);
22060 mouse_face
= get_char_property_and_overlay (make_number (pos
),
22064 if (!NILP (mouse_face
) && !NILP (overlay
))
22066 Lisp_Object before
= Foverlay_start (overlay
);
22067 Lisp_Object after
= Foverlay_end (overlay
);
22070 /* Note that we might not be able to find position
22071 BEFORE in the glyph matrix if the overlay is
22072 entirely covered by a `display' property. In
22073 this case, we overshoot. So let's stop in
22074 the glyph matrix before glyphs for OBJECT. */
22075 fast_find_position (w
, XFASTINT (before
),
22076 &dpyinfo
->mouse_face_beg_col
,
22077 &dpyinfo
->mouse_face_beg_row
,
22078 &dpyinfo
->mouse_face_beg_x
,
22079 &dpyinfo
->mouse_face_beg_y
,
22082 dpyinfo
->mouse_face_past_end
22083 = !fast_find_position (w
, XFASTINT (after
),
22084 &dpyinfo
->mouse_face_end_col
,
22085 &dpyinfo
->mouse_face_end_row
,
22086 &dpyinfo
->mouse_face_end_x
,
22087 &dpyinfo
->mouse_face_end_y
,
22089 dpyinfo
->mouse_face_window
= window
;
22090 dpyinfo
->mouse_face_face_id
22091 = face_at_buffer_position (w
, pos
, 0, 0,
22093 !dpyinfo
->mouse_face_hidden
);
22095 /* Display it as active. */
22096 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
22097 cursor
= No_Cursor
;
22104 /* Look for a `help-echo' property. */
22105 if (NILP (help_echo_string
)) {
22106 Lisp_Object help
, overlay
;
22108 /* Check overlays first. */
22109 help
= overlay
= Qnil
;
22110 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
22112 overlay
= overlay_vec
[i
];
22113 help
= Foverlay_get (overlay
, Qhelp_echo
);
22118 help_echo_string
= help
;
22119 help_echo_window
= window
;
22120 help_echo_object
= overlay
;
22121 help_echo_pos
= pos
;
22125 Lisp_Object object
= glyph
->object
;
22126 int charpos
= glyph
->charpos
;
22128 /* Try text properties. */
22129 if (STRINGP (object
)
22131 && charpos
< SCHARS (object
))
22133 help
= Fget_text_property (make_number (charpos
),
22134 Qhelp_echo
, object
);
22137 /* If the string itself doesn't specify a help-echo,
22138 see if the buffer text ``under'' it does. */
22139 struct glyph_row
*r
22140 = MATRIX_ROW (w
->current_matrix
, vpos
);
22141 int start
= MATRIX_ROW_START_CHARPOS (r
);
22142 int pos
= string_buffer_position (w
, object
, start
);
22145 help
= Fget_char_property (make_number (pos
),
22146 Qhelp_echo
, w
->buffer
);
22150 object
= w
->buffer
;
22155 else if (BUFFERP (object
)
22158 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
22163 help_echo_string
= help
;
22164 help_echo_window
= window
;
22165 help_echo_object
= object
;
22166 help_echo_pos
= charpos
;
22171 /* Look for a `pointer' property. */
22172 if (NILP (pointer
))
22174 /* Check overlays first. */
22175 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
22176 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
22178 if (NILP (pointer
))
22180 Lisp_Object object
= glyph
->object
;
22181 int charpos
= glyph
->charpos
;
22183 /* Try text properties. */
22184 if (STRINGP (object
)
22186 && charpos
< SCHARS (object
))
22188 pointer
= Fget_text_property (make_number (charpos
),
22190 if (NILP (pointer
))
22192 /* If the string itself doesn't specify a pointer,
22193 see if the buffer text ``under'' it does. */
22194 struct glyph_row
*r
22195 = MATRIX_ROW (w
->current_matrix
, vpos
);
22196 int start
= MATRIX_ROW_START_CHARPOS (r
);
22197 int pos
= string_buffer_position (w
, object
, start
);
22199 pointer
= Fget_char_property (make_number (pos
),
22200 Qpointer
, w
->buffer
);
22203 else if (BUFFERP (object
)
22206 pointer
= Fget_text_property (make_number (charpos
),
22213 current_buffer
= obuf
;
22218 define_frame_cursor1 (f
, cursor
, pointer
);
22223 Clear any mouse-face on window W. This function is part of the
22224 redisplay interface, and is called from try_window_id and similar
22225 functions to ensure the mouse-highlight is off. */
22228 x_clear_window_mouse_face (w
)
22231 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22232 Lisp_Object window
;
22235 XSETWINDOW (window
, w
);
22236 if (EQ (window
, dpyinfo
->mouse_face_window
))
22237 clear_mouse_face (dpyinfo
);
22243 Just discard the mouse face information for frame F, if any.
22244 This is used when the size of F is changed. */
22247 cancel_mouse_face (f
)
22250 Lisp_Object window
;
22251 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22253 window
= dpyinfo
->mouse_face_window
;
22254 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
22256 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22257 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22258 dpyinfo
->mouse_face_window
= Qnil
;
22263 #endif /* HAVE_WINDOW_SYSTEM */
22266 /***********************************************************************
22268 ***********************************************************************/
22270 #ifdef HAVE_WINDOW_SYSTEM
22272 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
22273 which intersects rectangle R. R is in window-relative coordinates. */
22276 expose_area (w
, row
, r
, area
)
22278 struct glyph_row
*row
;
22280 enum glyph_row_area area
;
22282 struct glyph
*first
= row
->glyphs
[area
];
22283 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
22284 struct glyph
*last
;
22285 int first_x
, start_x
, x
;
22287 if (area
== TEXT_AREA
&& row
->fill_line_p
)
22288 /* If row extends face to end of line write the whole line. */
22289 draw_glyphs (w
, 0, row
, area
,
22290 0, row
->used
[area
],
22291 DRAW_NORMAL_TEXT
, 0);
22294 /* Set START_X to the window-relative start position for drawing glyphs of
22295 AREA. The first glyph of the text area can be partially visible.
22296 The first glyphs of other areas cannot. */
22297 start_x
= window_box_left_offset (w
, area
);
22299 if (area
== TEXT_AREA
)
22302 /* Find the first glyph that must be redrawn. */
22304 && x
+ first
->pixel_width
< r
->x
)
22306 x
+= first
->pixel_width
;
22310 /* Find the last one. */
22314 && x
< r
->x
+ r
->width
)
22316 x
+= last
->pixel_width
;
22322 draw_glyphs (w
, first_x
- start_x
, row
, area
,
22323 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
22324 DRAW_NORMAL_TEXT
, 0);
22329 /* Redraw the parts of the glyph row ROW on window W intersecting
22330 rectangle R. R is in window-relative coordinates. Value is
22331 non-zero if mouse-face was overwritten. */
22334 expose_line (w
, row
, r
)
22336 struct glyph_row
*row
;
22339 xassert (row
->enabled_p
);
22341 if (row
->mode_line_p
|| w
->pseudo_window_p
)
22342 draw_glyphs (w
, 0, row
, TEXT_AREA
,
22343 0, row
->used
[TEXT_AREA
],
22344 DRAW_NORMAL_TEXT
, 0);
22347 if (row
->used
[LEFT_MARGIN_AREA
])
22348 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
22349 if (row
->used
[TEXT_AREA
])
22350 expose_area (w
, row
, r
, TEXT_AREA
);
22351 if (row
->used
[RIGHT_MARGIN_AREA
])
22352 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
22353 draw_row_fringe_bitmaps (w
, row
);
22356 return row
->mouse_face_p
;
22360 /* Redraw those parts of glyphs rows during expose event handling that
22361 overlap other rows. Redrawing of an exposed line writes over parts
22362 of lines overlapping that exposed line; this function fixes that.
22364 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
22365 row in W's current matrix that is exposed and overlaps other rows.
22366 LAST_OVERLAPPING_ROW is the last such row. */
22369 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
)
22371 struct glyph_row
*first_overlapping_row
;
22372 struct glyph_row
*last_overlapping_row
;
22374 struct glyph_row
*row
;
22376 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
22377 if (row
->overlapping_p
)
22379 xassert (row
->enabled_p
&& !row
->mode_line_p
);
22381 if (row
->used
[LEFT_MARGIN_AREA
])
22382 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
);
22384 if (row
->used
[TEXT_AREA
])
22385 x_fix_overlapping_area (w
, row
, TEXT_AREA
);
22387 if (row
->used
[RIGHT_MARGIN_AREA
])
22388 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
);
22393 /* Return non-zero if W's cursor intersects rectangle R. */
22396 phys_cursor_in_rect_p (w
, r
)
22400 XRectangle cr
, result
;
22401 struct glyph
*cursor_glyph
;
22403 cursor_glyph
= get_phys_cursor_glyph (w
);
22406 /* r is relative to W's box, but w->phys_cursor.x is relative
22407 to left edge of W's TEXT area. Adjust it. */
22408 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
22409 cr
.y
= w
->phys_cursor
.y
;
22410 cr
.width
= cursor_glyph
->pixel_width
;
22411 cr
.height
= w
->phys_cursor_height
;
22412 /* ++KFS: W32 version used W32-specific IntersectRect here, but
22413 I assume the effect is the same -- and this is portable. */
22414 return x_intersect_rectangles (&cr
, r
, &result
);
22422 Draw a vertical window border to the right of window W if W doesn't
22423 have vertical scroll bars. */
22426 x_draw_vertical_border (w
)
22429 /* We could do better, if we knew what type of scroll-bar the adjacent
22430 windows (on either side) have... But we don't :-(
22431 However, I think this works ok. ++KFS 2003-04-25 */
22433 /* Redraw borders between horizontally adjacent windows. Don't
22434 do it for frames with vertical scroll bars because either the
22435 right scroll bar of a window, or the left scroll bar of its
22436 neighbor will suffice as a border. */
22437 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
22440 if (!WINDOW_RIGHTMOST_P (w
)
22441 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
22443 int x0
, x1
, y0
, y1
;
22445 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22448 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22451 rif
->draw_vertical_window_border (w
, x1
, y0
, y1
);
22453 else if (!WINDOW_LEFTMOST_P (w
)
22454 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
22456 int x0
, x1
, y0
, y1
;
22458 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
22461 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
22464 rif
->draw_vertical_window_border (w
, x0
, y0
, y1
);
22469 /* Redraw the part of window W intersection rectangle FR. Pixel
22470 coordinates in FR are frame-relative. Call this function with
22471 input blocked. Value is non-zero if the exposure overwrites
22475 expose_window (w
, fr
)
22479 struct frame
*f
= XFRAME (w
->frame
);
22481 int mouse_face_overwritten_p
= 0;
22483 /* If window is not yet fully initialized, do nothing. This can
22484 happen when toolkit scroll bars are used and a window is split.
22485 Reconfiguring the scroll bar will generate an expose for a newly
22487 if (w
->current_matrix
== NULL
)
22490 /* When we're currently updating the window, display and current
22491 matrix usually don't agree. Arrange for a thorough display
22493 if (w
== updated_window
)
22495 SET_FRAME_GARBAGED (f
);
22499 /* Frame-relative pixel rectangle of W. */
22500 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
22501 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
22502 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
22503 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
22505 if (x_intersect_rectangles (fr
, &wr
, &r
))
22507 int yb
= window_text_bottom_y (w
);
22508 struct glyph_row
*row
;
22509 int cursor_cleared_p
;
22510 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
22512 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
22513 r
.x
, r
.y
, r
.width
, r
.height
));
22515 /* Convert to window coordinates. */
22516 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
22517 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
22519 /* Turn off the cursor. */
22520 if (!w
->pseudo_window_p
22521 && phys_cursor_in_rect_p (w
, &r
))
22523 x_clear_cursor (w
);
22524 cursor_cleared_p
= 1;
22527 cursor_cleared_p
= 0;
22529 /* Update lines intersecting rectangle R. */
22530 first_overlapping_row
= last_overlapping_row
= NULL
;
22531 for (row
= w
->current_matrix
->rows
;
22536 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
22538 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
22539 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
22540 || (r
.y
>= y0
&& r
.y
< y1
)
22541 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
22543 /* A header line may be overlapping, but there is no need
22544 to fix overlapping areas for them. KFS 2005-02-12 */
22545 if (row
->overlapping_p
&& !row
->mode_line_p
)
22547 if (first_overlapping_row
== NULL
)
22548 first_overlapping_row
= row
;
22549 last_overlapping_row
= row
;
22552 if (expose_line (w
, row
, &r
))
22553 mouse_face_overwritten_p
= 1;
22560 /* Display the mode line if there is one. */
22561 if (WINDOW_WANTS_MODELINE_P (w
)
22562 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
22564 && row
->y
< r
.y
+ r
.height
)
22566 if (expose_line (w
, row
, &r
))
22567 mouse_face_overwritten_p
= 1;
22570 if (!w
->pseudo_window_p
)
22572 /* Fix the display of overlapping rows. */
22573 if (first_overlapping_row
)
22574 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
);
22576 /* Draw border between windows. */
22577 x_draw_vertical_border (w
);
22579 /* Turn the cursor on again. */
22580 if (cursor_cleared_p
)
22581 update_window_cursor (w
, 1);
22585 return mouse_face_overwritten_p
;
22590 /* Redraw (parts) of all windows in the window tree rooted at W that
22591 intersect R. R contains frame pixel coordinates. Value is
22592 non-zero if the exposure overwrites mouse-face. */
22595 expose_window_tree (w
, r
)
22599 struct frame
*f
= XFRAME (w
->frame
);
22600 int mouse_face_overwritten_p
= 0;
22602 while (w
&& !FRAME_GARBAGED_P (f
))
22604 if (!NILP (w
->hchild
))
22605 mouse_face_overwritten_p
22606 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
22607 else if (!NILP (w
->vchild
))
22608 mouse_face_overwritten_p
22609 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
22611 mouse_face_overwritten_p
|= expose_window (w
, r
);
22613 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
22616 return mouse_face_overwritten_p
;
22621 Redisplay an exposed area of frame F. X and Y are the upper-left
22622 corner of the exposed rectangle. W and H are width and height of
22623 the exposed area. All are pixel values. W or H zero means redraw
22624 the entire frame. */
22627 expose_frame (f
, x
, y
, w
, h
)
22632 int mouse_face_overwritten_p
= 0;
22634 TRACE ((stderr
, "expose_frame "));
22636 /* No need to redraw if frame will be redrawn soon. */
22637 if (FRAME_GARBAGED_P (f
))
22639 TRACE ((stderr
, " garbaged\n"));
22643 /* If basic faces haven't been realized yet, there is no point in
22644 trying to redraw anything. This can happen when we get an expose
22645 event while Emacs is starting, e.g. by moving another window. */
22646 if (FRAME_FACE_CACHE (f
) == NULL
22647 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
22649 TRACE ((stderr
, " no faces\n"));
22653 if (w
== 0 || h
== 0)
22656 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
22657 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
22667 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
22668 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
22670 if (WINDOWP (f
->tool_bar_window
))
22671 mouse_face_overwritten_p
22672 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
22674 #ifdef HAVE_X_WINDOWS
22676 #ifndef USE_X_TOOLKIT
22677 if (WINDOWP (f
->menu_bar_window
))
22678 mouse_face_overwritten_p
22679 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
22680 #endif /* not USE_X_TOOLKIT */
22684 /* Some window managers support a focus-follows-mouse style with
22685 delayed raising of frames. Imagine a partially obscured frame,
22686 and moving the mouse into partially obscured mouse-face on that
22687 frame. The visible part of the mouse-face will be highlighted,
22688 then the WM raises the obscured frame. With at least one WM, KDE
22689 2.1, Emacs is not getting any event for the raising of the frame
22690 (even tried with SubstructureRedirectMask), only Expose events.
22691 These expose events will draw text normally, i.e. not
22692 highlighted. Which means we must redo the highlight here.
22693 Subsume it under ``we love X''. --gerd 2001-08-15 */
22694 /* Included in Windows version because Windows most likely does not
22695 do the right thing if any third party tool offers
22696 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
22697 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
22699 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22700 if (f
== dpyinfo
->mouse_face_mouse_frame
)
22702 int x
= dpyinfo
->mouse_face_mouse_x
;
22703 int y
= dpyinfo
->mouse_face_mouse_y
;
22704 clear_mouse_face (dpyinfo
);
22705 note_mouse_highlight (f
, x
, y
);
22712 Determine the intersection of two rectangles R1 and R2. Return
22713 the intersection in *RESULT. Value is non-zero if RESULT is not
22717 x_intersect_rectangles (r1
, r2
, result
)
22718 XRectangle
*r1
, *r2
, *result
;
22720 XRectangle
*left
, *right
;
22721 XRectangle
*upper
, *lower
;
22722 int intersection_p
= 0;
22724 /* Rearrange so that R1 is the left-most rectangle. */
22726 left
= r1
, right
= r2
;
22728 left
= r2
, right
= r1
;
22730 /* X0 of the intersection is right.x0, if this is inside R1,
22731 otherwise there is no intersection. */
22732 if (right
->x
<= left
->x
+ left
->width
)
22734 result
->x
= right
->x
;
22736 /* The right end of the intersection is the minimum of the
22737 the right ends of left and right. */
22738 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
22741 /* Same game for Y. */
22743 upper
= r1
, lower
= r2
;
22745 upper
= r2
, lower
= r1
;
22747 /* The upper end of the intersection is lower.y0, if this is inside
22748 of upper. Otherwise, there is no intersection. */
22749 if (lower
->y
<= upper
->y
+ upper
->height
)
22751 result
->y
= lower
->y
;
22753 /* The lower end of the intersection is the minimum of the lower
22754 ends of upper and lower. */
22755 result
->height
= (min (lower
->y
+ lower
->height
,
22756 upper
->y
+ upper
->height
)
22758 intersection_p
= 1;
22762 return intersection_p
;
22765 #endif /* HAVE_WINDOW_SYSTEM */
22768 /***********************************************************************
22770 ***********************************************************************/
22775 Vwith_echo_area_save_vector
= Qnil
;
22776 staticpro (&Vwith_echo_area_save_vector
);
22778 Vmessage_stack
= Qnil
;
22779 staticpro (&Vmessage_stack
);
22781 Qinhibit_redisplay
= intern ("inhibit-redisplay");
22782 staticpro (&Qinhibit_redisplay
);
22784 message_dolog_marker1
= Fmake_marker ();
22785 staticpro (&message_dolog_marker1
);
22786 message_dolog_marker2
= Fmake_marker ();
22787 staticpro (&message_dolog_marker2
);
22788 message_dolog_marker3
= Fmake_marker ();
22789 staticpro (&message_dolog_marker3
);
22792 defsubr (&Sdump_frame_glyph_matrix
);
22793 defsubr (&Sdump_glyph_matrix
);
22794 defsubr (&Sdump_glyph_row
);
22795 defsubr (&Sdump_tool_bar_row
);
22796 defsubr (&Strace_redisplay
);
22797 defsubr (&Strace_to_stderr
);
22799 #ifdef HAVE_WINDOW_SYSTEM
22800 defsubr (&Stool_bar_lines_needed
);
22801 defsubr (&Slookup_image_map
);
22803 defsubr (&Sformat_mode_line
);
22805 staticpro (&Qmenu_bar_update_hook
);
22806 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
22808 staticpro (&Qoverriding_terminal_local_map
);
22809 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
22811 staticpro (&Qoverriding_local_map
);
22812 Qoverriding_local_map
= intern ("overriding-local-map");
22814 staticpro (&Qwindow_scroll_functions
);
22815 Qwindow_scroll_functions
= intern ("window-scroll-functions");
22817 staticpro (&Qredisplay_end_trigger_functions
);
22818 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
22820 staticpro (&Qinhibit_point_motion_hooks
);
22821 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
22823 QCdata
= intern (":data");
22824 staticpro (&QCdata
);
22825 Qdisplay
= intern ("display");
22826 staticpro (&Qdisplay
);
22827 Qspace_width
= intern ("space-width");
22828 staticpro (&Qspace_width
);
22829 Qraise
= intern ("raise");
22830 staticpro (&Qraise
);
22831 Qslice
= intern ("slice");
22832 staticpro (&Qslice
);
22833 Qspace
= intern ("space");
22834 staticpro (&Qspace
);
22835 Qmargin
= intern ("margin");
22836 staticpro (&Qmargin
);
22837 Qpointer
= intern ("pointer");
22838 staticpro (&Qpointer
);
22839 Qleft_margin
= intern ("left-margin");
22840 staticpro (&Qleft_margin
);
22841 Qright_margin
= intern ("right-margin");
22842 staticpro (&Qright_margin
);
22843 Qcenter
= intern ("center");
22844 staticpro (&Qcenter
);
22845 Qline_height
= intern ("line-height");
22846 staticpro (&Qline_height
);
22847 QCalign_to
= intern (":align-to");
22848 staticpro (&QCalign_to
);
22849 QCrelative_width
= intern (":relative-width");
22850 staticpro (&QCrelative_width
);
22851 QCrelative_height
= intern (":relative-height");
22852 staticpro (&QCrelative_height
);
22853 QCeval
= intern (":eval");
22854 staticpro (&QCeval
);
22855 QCpropertize
= intern (":propertize");
22856 staticpro (&QCpropertize
);
22857 QCfile
= intern (":file");
22858 staticpro (&QCfile
);
22859 Qfontified
= intern ("fontified");
22860 staticpro (&Qfontified
);
22861 Qfontification_functions
= intern ("fontification-functions");
22862 staticpro (&Qfontification_functions
);
22863 Qtrailing_whitespace
= intern ("trailing-whitespace");
22864 staticpro (&Qtrailing_whitespace
);
22865 Qescape_glyph
= intern ("escape-glyph");
22866 staticpro (&Qescape_glyph
);
22867 Qnobreak_space
= intern ("nobreak-space");
22868 staticpro (&Qnobreak_space
);
22869 Qimage
= intern ("image");
22870 staticpro (&Qimage
);
22871 QCmap
= intern (":map");
22872 staticpro (&QCmap
);
22873 QCpointer
= intern (":pointer");
22874 staticpro (&QCpointer
);
22875 Qrect
= intern ("rect");
22876 staticpro (&Qrect
);
22877 Qcircle
= intern ("circle");
22878 staticpro (&Qcircle
);
22879 Qpoly
= intern ("poly");
22880 staticpro (&Qpoly
);
22881 Qmessage_truncate_lines
= intern ("message-truncate-lines");
22882 staticpro (&Qmessage_truncate_lines
);
22883 Qgrow_only
= intern ("grow-only");
22884 staticpro (&Qgrow_only
);
22885 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
22886 staticpro (&Qinhibit_menubar_update
);
22887 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
22888 staticpro (&Qinhibit_eval_during_redisplay
);
22889 Qposition
= intern ("position");
22890 staticpro (&Qposition
);
22891 Qbuffer_position
= intern ("buffer-position");
22892 staticpro (&Qbuffer_position
);
22893 Qobject
= intern ("object");
22894 staticpro (&Qobject
);
22895 Qbar
= intern ("bar");
22897 Qhbar
= intern ("hbar");
22898 staticpro (&Qhbar
);
22899 Qbox
= intern ("box");
22901 Qhollow
= intern ("hollow");
22902 staticpro (&Qhollow
);
22903 Qhand
= intern ("hand");
22904 staticpro (&Qhand
);
22905 Qarrow
= intern ("arrow");
22906 staticpro (&Qarrow
);
22907 Qtext
= intern ("text");
22908 staticpro (&Qtext
);
22909 Qrisky_local_variable
= intern ("risky-local-variable");
22910 staticpro (&Qrisky_local_variable
);
22911 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
22912 staticpro (&Qinhibit_free_realized_faces
);
22914 list_of_error
= Fcons (Fcons (intern ("error"),
22915 Fcons (intern ("void-variable"), Qnil
)),
22917 staticpro (&list_of_error
);
22919 Qlast_arrow_position
= intern ("last-arrow-position");
22920 staticpro (&Qlast_arrow_position
);
22921 Qlast_arrow_string
= intern ("last-arrow-string");
22922 staticpro (&Qlast_arrow_string
);
22924 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
22925 staticpro (&Qoverlay_arrow_string
);
22926 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
22927 staticpro (&Qoverlay_arrow_bitmap
);
22929 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
22930 staticpro (&echo_buffer
[0]);
22931 staticpro (&echo_buffer
[1]);
22933 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
22934 staticpro (&echo_area_buffer
[0]);
22935 staticpro (&echo_area_buffer
[1]);
22937 Vmessages_buffer_name
= build_string ("*Messages*");
22938 staticpro (&Vmessages_buffer_name
);
22940 mode_line_proptrans_alist
= Qnil
;
22941 staticpro (&mode_line_proptrans_alist
);
22942 mode_line_string_list
= Qnil
;
22943 staticpro (&mode_line_string_list
);
22944 mode_line_string_face
= Qnil
;
22945 staticpro (&mode_line_string_face
);
22946 mode_line_string_face_prop
= Qnil
;
22947 staticpro (&mode_line_string_face_prop
);
22948 Vmode_line_unwind_vector
= Qnil
;
22949 staticpro (&Vmode_line_unwind_vector
);
22951 help_echo_string
= Qnil
;
22952 staticpro (&help_echo_string
);
22953 help_echo_object
= Qnil
;
22954 staticpro (&help_echo_object
);
22955 help_echo_window
= Qnil
;
22956 staticpro (&help_echo_window
);
22957 previous_help_echo_string
= Qnil
;
22958 staticpro (&previous_help_echo_string
);
22959 help_echo_pos
= -1;
22961 #ifdef HAVE_WINDOW_SYSTEM
22962 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
22963 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
22964 For example, if a block cursor is over a tab, it will be drawn as
22965 wide as that tab on the display. */);
22966 x_stretch_cursor_p
= 0;
22969 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
22970 doc
: /* *Non-nil means highlight trailing whitespace.
22971 The face used for trailing whitespace is `trailing-whitespace'. */);
22972 Vshow_trailing_whitespace
= Qnil
;
22974 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
22975 doc
: /* *Control highlighting of nobreak space and soft hyphen.
22976 A value of t means highlight the character itself (for nobreak space,
22977 use face `nobreak-space').
22978 A value of nil means no highlighting.
22979 Other values mean display the escape glyph followed by an ordinary
22980 space or ordinary hyphen. */);
22981 Vnobreak_char_display
= Qt
;
22983 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
22984 doc
: /* *The pointer shape to show in void text areas.
22985 A value of nil means to show the text pointer. Other options are `arrow',
22986 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
22987 Vvoid_text_area_pointer
= Qarrow
;
22989 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
22990 doc
: /* Non-nil means don't actually do any redisplay.
22991 This is used for internal purposes. */);
22992 Vinhibit_redisplay
= Qnil
;
22994 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
22995 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
22996 Vglobal_mode_string
= Qnil
;
22998 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
22999 doc
: /* Marker for where to display an arrow on top of the buffer text.
23000 This must be the beginning of a line in order to work.
23001 See also `overlay-arrow-string'. */);
23002 Voverlay_arrow_position
= Qnil
;
23004 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
23005 doc
: /* String to display as an arrow in non-window frames.
23006 See also `overlay-arrow-position'. */);
23007 Voverlay_arrow_string
= build_string ("=>");
23009 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
23010 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
23011 The symbols on this list are examined during redisplay to determine
23012 where to display overlay arrows. */);
23013 Voverlay_arrow_variable_list
23014 = Fcons (intern ("overlay-arrow-position"), Qnil
);
23016 DEFVAR_INT ("scroll-step", &scroll_step
,
23017 doc
: /* *The number of lines to try scrolling a window by when point moves out.
23018 If that fails to bring point back on frame, point is centered instead.
23019 If this is zero, point is always centered after it moves off frame.
23020 If you want scrolling to always be a line at a time, you should set
23021 `scroll-conservatively' to a large value rather than set this to 1. */);
23023 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
23024 doc
: /* *Scroll up to this many lines, to bring point back on screen.
23025 A value of zero means to scroll the text to center point vertically
23026 in the window. */);
23027 scroll_conservatively
= 0;
23029 DEFVAR_INT ("scroll-margin", &scroll_margin
,
23030 doc
: /* *Number of lines of margin at the top and bottom of a window.
23031 Recenter the window whenever point gets within this many lines
23032 of the top or bottom of the window. */);
23035 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
23036 doc
: /* Pixels per inch on current display.
23037 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
23038 Vdisplay_pixels_per_inch
= make_float (72.0);
23041 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
23044 DEFVAR_BOOL ("truncate-partial-width-windows",
23045 &truncate_partial_width_windows
,
23046 doc
: /* *Non-nil means truncate lines in all windows less than full frame wide. */);
23047 truncate_partial_width_windows
= 1;
23049 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
23050 doc
: /* nil means display the mode-line/header-line/menu-bar in the default face.
23051 Any other value means to use the appropriate face, `mode-line',
23052 `header-line', or `menu' respectively. */);
23053 mode_line_inverse_video
= 1;
23055 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
23056 doc
: /* *Maximum buffer size for which line number should be displayed.
23057 If the buffer is bigger than this, the line number does not appear
23058 in the mode line. A value of nil means no limit. */);
23059 Vline_number_display_limit
= Qnil
;
23061 DEFVAR_INT ("line-number-display-limit-width",
23062 &line_number_display_limit_width
,
23063 doc
: /* *Maximum line width (in characters) for line number display.
23064 If the average length of the lines near point is bigger than this, then the
23065 line number may be omitted from the mode line. */);
23066 line_number_display_limit_width
= 200;
23068 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
23069 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
23070 highlight_nonselected_windows
= 0;
23072 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
23073 doc
: /* Non-nil if more than one frame is visible on this display.
23074 Minibuffer-only frames don't count, but iconified frames do.
23075 This variable is not guaranteed to be accurate except while processing
23076 `frame-title-format' and `icon-title-format'. */);
23078 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
23079 doc
: /* Template for displaying the title bar of visible frames.
23080 \(Assuming the window manager supports this feature.)
23081 This variable has the same structure as `mode-line-format' (which see),
23082 and is used only on frames for which no explicit name has been set
23083 \(see `modify-frame-parameters'). */);
23085 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
23086 doc
: /* Template for displaying the title bar of an iconified frame.
23087 \(Assuming the window manager supports this feature.)
23088 This variable has the same structure as `mode-line-format' (which see),
23089 and is used only on frames for which no explicit name has been set
23090 \(see `modify-frame-parameters'). */);
23092 = Vframe_title_format
23093 = Fcons (intern ("multiple-frames"),
23094 Fcons (build_string ("%b"),
23095 Fcons (Fcons (empty_string
,
23096 Fcons (intern ("invocation-name"),
23097 Fcons (build_string ("@"),
23098 Fcons (intern ("system-name"),
23102 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
23103 doc
: /* Maximum number of lines to keep in the message log buffer.
23104 If nil, disable message logging. If t, log messages but don't truncate
23105 the buffer when it becomes large. */);
23106 Vmessage_log_max
= make_number (50);
23108 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
23109 doc
: /* Functions called before redisplay, if window sizes have changed.
23110 The value should be a list of functions that take one argument.
23111 Just before redisplay, for each frame, if any of its windows have changed
23112 size since the last redisplay, or have been split or deleted,
23113 all the functions in the list are called, with the frame as argument. */);
23114 Vwindow_size_change_functions
= Qnil
;
23116 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
23117 doc
: /* List of functions to call before redisplaying a window with scrolling.
23118 Each function is called with two arguments, the window
23119 and its new display-start position. Note that the value of `window-end'
23120 is not valid when these functions are called. */);
23121 Vwindow_scroll_functions
= Qnil
;
23123 DEFVAR_BOOL ("mouse-autoselect-window", &mouse_autoselect_window
,
23124 doc
: /* *Non-nil means autoselect window with mouse pointer. */);
23125 mouse_autoselect_window
= 0;
23127 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
23128 doc
: /* *Non-nil means automatically resize tool-bars.
23129 This increases a tool-bar's height if not all tool-bar items are visible.
23130 It decreases a tool-bar's height when it would display blank lines
23132 auto_resize_tool_bars_p
= 1;
23134 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
23135 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
23136 auto_raise_tool_bar_buttons_p
= 1;
23138 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
23139 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
23140 make_cursor_line_fully_visible_p
= 1;
23142 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
23143 doc
: /* *Margin around tool-bar buttons in pixels.
23144 If an integer, use that for both horizontal and vertical margins.
23145 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
23146 HORZ specifying the horizontal margin, and VERT specifying the
23147 vertical margin. */);
23148 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
23150 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
23151 doc
: /* *Relief thickness of tool-bar buttons. */);
23152 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
23154 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
23155 doc
: /* List of functions to call to fontify regions of text.
23156 Each function is called with one argument POS. Functions must
23157 fontify a region starting at POS in the current buffer, and give
23158 fontified regions the property `fontified'. */);
23159 Vfontification_functions
= Qnil
;
23160 Fmake_variable_buffer_local (Qfontification_functions
);
23162 DEFVAR_BOOL ("unibyte-display-via-language-environment",
23163 &unibyte_display_via_language_environment
,
23164 doc
: /* *Non-nil means display unibyte text according to language environment.
23165 Specifically this means that unibyte non-ASCII characters
23166 are displayed by converting them to the equivalent multibyte characters
23167 according to the current language environment. As a result, they are
23168 displayed according to the current fontset. */);
23169 unibyte_display_via_language_environment
= 0;
23171 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
23172 doc
: /* *Maximum height for resizing mini-windows.
23173 If a float, it specifies a fraction of the mini-window frame's height.
23174 If an integer, it specifies a number of lines. */);
23175 Vmax_mini_window_height
= make_float (0.25);
23177 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
23178 doc
: /* *How to resize mini-windows.
23179 A value of nil means don't automatically resize mini-windows.
23180 A value of t means resize them to fit the text displayed in them.
23181 A value of `grow-only', the default, means let mini-windows grow
23182 only, until their display becomes empty, at which point the windows
23183 go back to their normal size. */);
23184 Vresize_mini_windows
= Qgrow_only
;
23186 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
23187 doc
: /* Alist specifying how to blink the cursor off.
23188 Each element has the form (ON-STATE . OFF-STATE). Whenever the
23189 `cursor-type' frame-parameter or variable equals ON-STATE,
23190 comparing using `equal', Emacs uses OFF-STATE to specify
23191 how to blink it off. */);
23192 Vblink_cursor_alist
= Qnil
;
23194 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
23195 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
23196 automatic_hscrolling_p
= 1;
23198 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
23199 doc
: /* *How many columns away from the window edge point is allowed to get
23200 before automatic hscrolling will horizontally scroll the window. */);
23201 hscroll_margin
= 5;
23203 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
23204 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
23205 When point is less than `automatic-hscroll-margin' columns from the window
23206 edge, automatic hscrolling will scroll the window by the amount of columns
23207 determined by this variable. If its value is a positive integer, scroll that
23208 many columns. If it's a positive floating-point number, it specifies the
23209 fraction of the window's width to scroll. If it's nil or zero, point will be
23210 centered horizontally after the scroll. Any other value, including negative
23211 numbers, are treated as if the value were zero.
23213 Automatic hscrolling always moves point outside the scroll margin, so if
23214 point was more than scroll step columns inside the margin, the window will
23215 scroll more than the value given by the scroll step.
23217 Note that the lower bound for automatic hscrolling specified by `scroll-left'
23218 and `scroll-right' overrides this variable's effect. */);
23219 Vhscroll_step
= make_number (0);
23221 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
23222 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
23223 Bind this around calls to `message' to let it take effect. */);
23224 message_truncate_lines
= 0;
23226 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
23227 doc
: /* Normal hook run to update the menu bar definitions.
23228 Redisplay runs this hook before it redisplays the menu bar.
23229 This is used to update submenus such as Buffers,
23230 whose contents depend on various data. */);
23231 Vmenu_bar_update_hook
= Qnil
;
23233 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
23234 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
23235 inhibit_menubar_update
= 0;
23237 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
23238 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
23239 inhibit_eval_during_redisplay
= 0;
23241 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
23242 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
23243 inhibit_free_realized_faces
= 0;
23246 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
23247 doc
: /* Inhibit try_window_id display optimization. */);
23248 inhibit_try_window_id
= 0;
23250 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
23251 doc
: /* Inhibit try_window_reusing display optimization. */);
23252 inhibit_try_window_reusing
= 0;
23254 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
23255 doc
: /* Inhibit try_cursor_movement display optimization. */);
23256 inhibit_try_cursor_movement
= 0;
23257 #endif /* GLYPH_DEBUG */
23261 /* Initialize this module when Emacs starts. */
23266 Lisp_Object root_window
;
23267 struct window
*mini_w
;
23269 current_header_line_height
= current_mode_line_height
= -1;
23271 CHARPOS (this_line_start_pos
) = 0;
23273 mini_w
= XWINDOW (minibuf_window
);
23274 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
23276 if (!noninteractive
)
23278 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
23281 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
23282 set_window_height (root_window
,
23283 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
23285 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
23286 set_window_height (minibuf_window
, 1, 0);
23288 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
23289 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
23291 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
23292 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
23293 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
23295 /* The default ellipsis glyphs `...'. */
23296 for (i
= 0; i
< 3; ++i
)
23297 default_invis_vector
[i
] = make_number ('.');
23301 /* Allocate the buffer for frame titles.
23302 Also used for `format-mode-line'. */
23304 mode_line_noprop_buf
= (char *) xmalloc (size
);
23305 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
23306 mode_line_noprop_ptr
= mode_line_noprop_buf
;
23307 mode_line_target
= MODE_LINE_DISPLAY
;
23310 help_echo_showing_p
= 0;
23314 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
23315 (do not change this comment) */