1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code. (Or,
35 let's say almost---see the description of direct update
38 The following diagram shows how redisplay code is invoked. As you
39 can see, Lisp calls redisplay and vice versa. Under window systems
40 like X, some portions of the redisplay code are also called
41 asynchronously during mouse movement or expose events. It is very
42 important that these code parts do NOT use the C library (malloc,
43 free) because many C libraries under Unix are not reentrant. They
44 may also NOT call functions of the Lisp interpreter which could
45 change the interpreter's state. If you don't follow these rules,
46 you will encounter bugs which are very hard to explain.
48 (Direct functions, see below)
49 direct_output_for_insert,
50 direct_forward_char (dispnew.c)
51 +---------------------------------+
54 +--------------+ redisplay +----------------+
55 | Lisp machine |---------------->| Redisplay code |<--+
56 +--------------+ (xdisp.c) +----------------+ |
58 +----------------------------------+ |
59 Don't use this path when called |
62 expose_window (asynchronous) |
64 X expose events -----+
66 What does redisplay do? Obviously, it has to figure out somehow what
67 has been changed since the last time the display has been updated,
68 and to make these changes visible. Preferably it would do that in
69 a moderately intelligent way, i.e. fast.
71 Changes in buffer text can be deduced from window and buffer
72 structures, and from some global variables like `beg_unchanged' and
73 `end_unchanged'. The contents of the display are additionally
74 recorded in a `glyph matrix', a two-dimensional matrix of glyph
75 structures. Each row in such a matrix corresponds to a line on the
76 display, and each glyph in a row corresponds to a column displaying
77 a character, an image, or what else. This matrix is called the
78 `current glyph matrix' or `current matrix' in redisplay
81 For buffer parts that have been changed since the last update, a
82 second glyph matrix is constructed, the so called `desired glyph
83 matrix' or short `desired matrix'. Current and desired matrix are
84 then compared to find a cheap way to update the display, e.g. by
85 reusing part of the display by scrolling lines.
90 You will find a lot of redisplay optimizations when you start
91 looking at the innards of redisplay. The overall goal of all these
92 optimizations is to make redisplay fast because it is done
95 Two optimizations are not found in xdisp.c. These are the direct
96 operations mentioned above. As the name suggests they follow a
97 different principle than the rest of redisplay. Instead of
98 building a desired matrix and then comparing it with the current
99 display, they perform their actions directly on the display and on
102 One direct operation updates the display after one character has
103 been entered. The other one moves the cursor by one position
104 forward or backward. You find these functions under the names
105 `direct_output_for_insert' and `direct_output_forward_char' in
111 Desired matrices are always built per Emacs window. The function
112 `display_line' is the central function to look at if you are
113 interested. It constructs one row in a desired matrix given an
114 iterator structure containing both a buffer position and a
115 description of the environment in which the text is to be
116 displayed. But this is too early, read on.
118 Characters and pixmaps displayed for a range of buffer text depend
119 on various settings of buffers and windows, on overlays and text
120 properties, on display tables, on selective display. The good news
121 is that all this hairy stuff is hidden behind a small set of
122 interface functions taking an iterator structure (struct it)
125 Iteration over things to be displayed is then simple. It is
126 started by initializing an iterator with a call to init_iterator.
127 Calls to get_next_display_element fill the iterator structure with
128 relevant information about the next thing to display. Calls to
129 set_iterator_to_next move the iterator to the next thing.
131 Besides this, an iterator also contains information about the
132 display environment in which glyphs for display elements are to be
133 produced. It has fields for the width and height of the display,
134 the information whether long lines are truncated or continued, a
135 current X and Y position, and lots of other stuff you can better
138 Glyphs in a desired matrix are normally constructed in a loop
139 calling get_next_display_element and then produce_glyphs. The call
140 to produce_glyphs will fill the iterator structure with pixel
141 information about the element being displayed and at the same time
142 produce glyphs for it. If the display element fits on the line
143 being displayed, set_iterator_to_next is called next, otherwise the
144 glyphs produced are discarded.
149 That just couldn't be all, could it? What about terminal types not
150 supporting operations on sub-windows of the screen? To update the
151 display on such a terminal, window-based glyph matrices are not
152 well suited. To be able to reuse part of the display (scrolling
153 lines up and down), we must instead have a view of the whole
154 screen. This is what `frame matrices' are for. They are a trick.
156 Frames on terminals like above have a glyph pool. Windows on such
157 a frame sub-allocate their glyph memory from their frame's glyph
158 pool. The frame itself is given its own glyph matrices. By
159 coincidence---or maybe something else---rows in window glyph
160 matrices are slices of corresponding rows in frame matrices. Thus
161 writing to window matrices implicitly updates a frame matrix which
162 provides us with the view of the whole screen that we originally
163 wanted to have without having to move many bytes around. To be
164 honest, there is a little bit more done, but not much more. If you
165 plan to extend that code, take a look at dispnew.c. The function
166 build_frame_matrix is a good starting point. */
173 #include "keyboard.h"
176 #include "termchar.h"
177 #include "dispextern.h"
179 #include "character.h"
182 #include "commands.h"
186 #include "termhooks.h"
187 #include "intervals.h"
190 #include "region-cache.h"
192 #include "blockinput.h"
194 #ifdef HAVE_X_WINDOWS
209 #ifndef FRAME_X_OUTPUT
210 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
213 #define INFINITY 10000000
215 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
216 || defined(HAVE_NS) || defined (USE_GTK)
217 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
218 extern int pending_menu_activation
;
221 extern int interrupt_input
;
222 extern int command_loop_level
;
224 extern Lisp_Object do_mouse_tracking
;
226 extern int minibuffer_auto_raise
;
227 extern Lisp_Object Vminibuffer_list
;
229 extern Lisp_Object Qface
;
230 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
232 extern Lisp_Object Voverriding_local_map
;
233 extern Lisp_Object Voverriding_local_map_menu_flag
;
234 extern Lisp_Object Qmenu_item
;
235 extern Lisp_Object Qwhen
;
236 extern Lisp_Object Qhelp_echo
;
238 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
239 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
240 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
241 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
242 Lisp_Object Qinhibit_point_motion_hooks
;
243 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
244 Lisp_Object Qfontified
;
245 Lisp_Object Qgrow_only
;
246 Lisp_Object Qinhibit_eval_during_redisplay
;
247 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
250 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
253 Lisp_Object Qarrow
, Qhand
, Qtext
;
255 Lisp_Object Qrisky_local_variable
;
257 /* Holds the list (error). */
258 Lisp_Object list_of_error
;
260 /* Functions called to fontify regions of text. */
262 Lisp_Object Vfontification_functions
;
263 Lisp_Object Qfontification_functions
;
265 /* Non-nil means automatically select any window when the mouse
266 cursor moves into it. */
267 Lisp_Object Vmouse_autoselect_window
;
269 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
270 Lisp_Object Vline_prefix
, Qline_prefix
;
272 /* Non-zero means draw tool bar buttons raised when the mouse moves
275 int auto_raise_tool_bar_buttons_p
;
277 /* Non-zero means to reposition window if cursor line is only partially visible. */
279 int make_cursor_line_fully_visible_p
;
281 /* Margin below tool bar in pixels. 0 or nil means no margin.
282 If value is `internal-border-width' or `border-width',
283 the corresponding frame parameter is used. */
285 Lisp_Object Vtool_bar_border
;
287 /* Margin around tool bar buttons in pixels. */
289 Lisp_Object Vtool_bar_button_margin
;
291 /* Thickness of shadow to draw around tool bar buttons. */
293 EMACS_INT tool_bar_button_relief
;
295 /* Non-nil means automatically resize tool-bars so that all tool-bar
296 items are visible, and no blank lines remain.
298 If value is `grow-only', only make tool-bar bigger. */
300 Lisp_Object Vauto_resize_tool_bars
;
302 /* Non-zero means draw block and hollow cursor as wide as the glyph
303 under it. For example, if a block cursor is over a tab, it will be
304 drawn as wide as that tab on the display. */
306 int x_stretch_cursor_p
;
308 /* Non-nil means don't actually do any redisplay. */
310 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
312 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
314 int inhibit_eval_during_redisplay
;
316 /* Names of text properties relevant for redisplay. */
318 Lisp_Object Qdisplay
;
319 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
321 /* Symbols used in text property values. */
323 Lisp_Object Vdisplay_pixels_per_inch
;
324 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
325 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
328 Lisp_Object Qmargin
, Qpointer
;
329 Lisp_Object Qline_height
;
330 extern Lisp_Object Qheight
;
331 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
332 extern Lisp_Object Qscroll_bar
;
333 extern Lisp_Object Qcursor
;
335 /* Non-nil means highlight trailing whitespace. */
337 Lisp_Object Vshow_trailing_whitespace
;
339 /* Non-nil means escape non-break space and hyphens. */
341 Lisp_Object Vnobreak_char_display
;
343 #ifdef HAVE_WINDOW_SYSTEM
344 extern Lisp_Object Voverflow_newline_into_fringe
;
346 /* Test if overflow newline into fringe. Called with iterator IT
347 at or past right window margin, and with IT->current_x set. */
349 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
350 (!NILP (Voverflow_newline_into_fringe) \
351 && FRAME_WINDOW_P (it->f) \
352 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
353 && it->current_x == it->last_visible_x \
354 && it->line_wrap != WORD_WRAP)
356 #endif /* HAVE_WINDOW_SYSTEM */
358 /* Test if the display element loaded in IT is a space or tab
359 character. This is used to determine word wrapping. */
361 #define IT_DISPLAYING_WHITESPACE(it) \
362 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
364 /* Non-nil means show the text cursor in void text areas
365 i.e. in blank areas after eol and eob. This used to be
366 the default in 21.3. */
368 Lisp_Object Vvoid_text_area_pointer
;
370 /* Name of the face used to highlight trailing whitespace. */
372 Lisp_Object Qtrailing_whitespace
;
374 /* Name and number of the face used to highlight escape glyphs. */
376 Lisp_Object Qescape_glyph
;
378 /* Name and number of the face used to highlight non-breaking spaces. */
380 Lisp_Object Qnobreak_space
;
382 /* The symbol `image' which is the car of the lists used to represent
387 /* The image map types. */
388 Lisp_Object QCmap
, QCpointer
;
389 Lisp_Object Qrect
, Qcircle
, Qpoly
;
391 /* Non-zero means print newline to stdout before next mini-buffer
394 int noninteractive_need_newline
;
396 /* Non-zero means print newline to message log before next message. */
398 static int message_log_need_newline
;
400 /* Three markers that message_dolog uses.
401 It could allocate them itself, but that causes trouble
402 in handling memory-full errors. */
403 static Lisp_Object message_dolog_marker1
;
404 static Lisp_Object message_dolog_marker2
;
405 static Lisp_Object message_dolog_marker3
;
407 /* The buffer position of the first character appearing entirely or
408 partially on the line of the selected window which contains the
409 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
410 redisplay optimization in redisplay_internal. */
412 static struct text_pos this_line_start_pos
;
414 /* Number of characters past the end of the line above, including the
415 terminating newline. */
417 static struct text_pos this_line_end_pos
;
419 /* The vertical positions and the height of this line. */
421 static int this_line_vpos
;
422 static int this_line_y
;
423 static int this_line_pixel_height
;
425 /* X position at which this display line starts. Usually zero;
426 negative if first character is partially visible. */
428 static int this_line_start_x
;
430 /* Buffer that this_line_.* variables are referring to. */
432 static struct buffer
*this_line_buffer
;
434 /* Nonzero means truncate lines in all windows less wide than the
437 Lisp_Object Vtruncate_partial_width_windows
;
439 /* A flag to control how to display unibyte 8-bit character. */
441 int unibyte_display_via_language_environment
;
443 /* Nonzero means we have more than one non-mini-buffer-only frame.
444 Not guaranteed to be accurate except while parsing
445 frame-title-format. */
449 Lisp_Object Vglobal_mode_string
;
452 /* List of variables (symbols) which hold markers for overlay arrows.
453 The symbols on this list are examined during redisplay to determine
454 where to display overlay arrows. */
456 Lisp_Object Voverlay_arrow_variable_list
;
458 /* Marker for where to display an arrow on top of the buffer text. */
460 Lisp_Object Voverlay_arrow_position
;
462 /* String to display for the arrow. Only used on terminal frames. */
464 Lisp_Object Voverlay_arrow_string
;
466 /* Values of those variables at last redisplay are stored as
467 properties on `overlay-arrow-position' symbol. However, if
468 Voverlay_arrow_position is a marker, last-arrow-position is its
469 numerical position. */
471 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
473 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
474 properties on a symbol in overlay-arrow-variable-list. */
476 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
478 /* Like mode-line-format, but for the title bar on a visible frame. */
480 Lisp_Object Vframe_title_format
;
482 /* Like mode-line-format, but for the title bar on an iconified frame. */
484 Lisp_Object Vicon_title_format
;
486 /* List of functions to call when a window's size changes. These
487 functions get one arg, a frame on which one or more windows' sizes
490 static Lisp_Object Vwindow_size_change_functions
;
492 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
494 /* Nonzero if an overlay arrow has been displayed in this window. */
496 static int overlay_arrow_seen
;
498 /* Nonzero means highlight the region even in nonselected windows. */
500 int highlight_nonselected_windows
;
502 /* If cursor motion alone moves point off frame, try scrolling this
503 many lines up or down if that will bring it back. */
505 static EMACS_INT scroll_step
;
507 /* Nonzero means scroll just far enough to bring point back on the
508 screen, when appropriate. */
510 static EMACS_INT scroll_conservatively
;
512 /* Recenter the window whenever point gets within this many lines of
513 the top or bottom of the window. This value is translated into a
514 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
515 that there is really a fixed pixel height scroll margin. */
517 EMACS_INT scroll_margin
;
519 /* Number of windows showing the buffer of the selected window (or
520 another buffer with the same base buffer). keyboard.c refers to
525 /* Vector containing glyphs for an ellipsis `...'. */
527 static Lisp_Object default_invis_vector
[3];
529 /* Zero means display the mode-line/header-line/menu-bar in the default face
530 (this slightly odd definition is for compatibility with previous versions
531 of emacs), non-zero means display them using their respective faces.
533 This variable is deprecated. */
535 int mode_line_inverse_video
;
537 /* Prompt to display in front of the mini-buffer contents. */
539 Lisp_Object minibuf_prompt
;
541 /* Width of current mini-buffer prompt. Only set after display_line
542 of the line that contains the prompt. */
544 int minibuf_prompt_width
;
546 /* This is the window where the echo area message was displayed. It
547 is always a mini-buffer window, but it may not be the same window
548 currently active as a mini-buffer. */
550 Lisp_Object echo_area_window
;
552 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
553 pushes the current message and the value of
554 message_enable_multibyte on the stack, the function restore_message
555 pops the stack and displays MESSAGE again. */
557 Lisp_Object Vmessage_stack
;
559 /* Nonzero means multibyte characters were enabled when the echo area
560 message was specified. */
562 int message_enable_multibyte
;
564 /* Nonzero if we should redraw the mode lines on the next redisplay. */
566 int update_mode_lines
;
568 /* Nonzero if window sizes or contents have changed since last
569 redisplay that finished. */
571 int windows_or_buffers_changed
;
573 /* Nonzero means a frame's cursor type has been changed. */
575 int cursor_type_changed
;
577 /* Nonzero after display_mode_line if %l was used and it displayed a
580 int line_number_displayed
;
582 /* Maximum buffer size for which to display line numbers. */
584 Lisp_Object Vline_number_display_limit
;
586 /* Line width to consider when repositioning for line number display. */
588 static EMACS_INT line_number_display_limit_width
;
590 /* Number of lines to keep in the message log buffer. t means
591 infinite. nil means don't log at all. */
593 Lisp_Object Vmessage_log_max
;
595 /* The name of the *Messages* buffer, a string. */
597 static Lisp_Object Vmessages_buffer_name
;
599 /* Current, index 0, and last displayed echo area message. Either
600 buffers from echo_buffers, or nil to indicate no message. */
602 Lisp_Object echo_area_buffer
[2];
604 /* The buffers referenced from echo_area_buffer. */
606 static Lisp_Object echo_buffer
[2];
608 /* A vector saved used in with_area_buffer to reduce consing. */
610 static Lisp_Object Vwith_echo_area_save_vector
;
612 /* Non-zero means display_echo_area should display the last echo area
613 message again. Set by redisplay_preserve_echo_area. */
615 static int display_last_displayed_message_p
;
617 /* Nonzero if echo area is being used by print; zero if being used by
620 int message_buf_print
;
622 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
624 Lisp_Object Qinhibit_menubar_update
;
625 int inhibit_menubar_update
;
627 /* When evaluating expressions from menu bar items (enable conditions,
628 for instance), this is the frame they are being processed for. */
630 Lisp_Object Vmenu_updating_frame
;
632 /* Maximum height for resizing mini-windows. Either a float
633 specifying a fraction of the available height, or an integer
634 specifying a number of lines. */
636 Lisp_Object Vmax_mini_window_height
;
638 /* Non-zero means messages should be displayed with truncated
639 lines instead of being continued. */
641 int message_truncate_lines
;
642 Lisp_Object Qmessage_truncate_lines
;
644 /* Set to 1 in clear_message to make redisplay_internal aware
645 of an emptied echo area. */
647 static int message_cleared_p
;
649 /* How to blink the default frame cursor off. */
650 Lisp_Object Vblink_cursor_alist
;
652 /* A scratch glyph row with contents used for generating truncation
653 glyphs. Also used in direct_output_for_insert. */
655 #define MAX_SCRATCH_GLYPHS 100
656 struct glyph_row scratch_glyph_row
;
657 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
659 /* Ascent and height of the last line processed by move_it_to. */
661 static int last_max_ascent
, last_height
;
663 /* Non-zero if there's a help-echo in the echo area. */
665 int help_echo_showing_p
;
667 /* If >= 0, computed, exact values of mode-line and header-line height
668 to use in the macros CURRENT_MODE_LINE_HEIGHT and
669 CURRENT_HEADER_LINE_HEIGHT. */
671 int current_mode_line_height
, current_header_line_height
;
673 /* The maximum distance to look ahead for text properties. Values
674 that are too small let us call compute_char_face and similar
675 functions too often which is expensive. Values that are too large
676 let us call compute_char_face and alike too often because we
677 might not be interested in text properties that far away. */
679 #define TEXT_PROP_DISTANCE_LIMIT 100
683 /* Variables to turn off display optimizations from Lisp. */
685 int inhibit_try_window_id
, inhibit_try_window_reusing
;
686 int inhibit_try_cursor_movement
;
688 /* Non-zero means print traces of redisplay if compiled with
691 int trace_redisplay_p
;
693 #endif /* GLYPH_DEBUG */
695 #ifdef DEBUG_TRACE_MOVE
696 /* Non-zero means trace with TRACE_MOVE to stderr. */
699 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
701 #define TRACE_MOVE(x) (void) 0
704 /* Non-zero means automatically scroll windows horizontally to make
707 int automatic_hscrolling_p
;
708 Lisp_Object Qauto_hscroll_mode
;
710 /* How close to the margin can point get before the window is scrolled
712 EMACS_INT hscroll_margin
;
714 /* How much to scroll horizontally when point is inside the above margin. */
715 Lisp_Object Vhscroll_step
;
717 /* The variable `resize-mini-windows'. If nil, don't resize
718 mini-windows. If t, always resize them to fit the text they
719 display. If `grow-only', let mini-windows grow only until they
722 Lisp_Object Vresize_mini_windows
;
724 /* Buffer being redisplayed -- for redisplay_window_error. */
726 struct buffer
*displayed_buffer
;
728 /* Space between overline and text. */
730 EMACS_INT overline_margin
;
732 /* Require underline to be at least this many screen pixels below baseline
733 This to avoid underline "merging" with the base of letters at small
734 font sizes, particularly when x_use_underline_position_properties is on. */
736 EMACS_INT underline_minimum_offset
;
738 /* Value returned from text property handlers (see below). */
743 HANDLED_RECOMPUTE_PROPS
,
744 HANDLED_OVERLAY_STRING_CONSUMED
,
748 /* A description of text properties that redisplay is interested
753 /* The name of the property. */
756 /* A unique index for the property. */
759 /* A handler function called to set up iterator IT from the property
760 at IT's current position. Value is used to steer handle_stop. */
761 enum prop_handled (*handler
) P_ ((struct it
*it
));
764 static enum prop_handled handle_face_prop
P_ ((struct it
*));
765 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
766 static enum prop_handled handle_display_prop
P_ ((struct it
*));
767 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
768 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
769 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
770 static enum prop_handled handle_auto_composed_prop
P_ ((struct it
*));
772 /* Properties handled by iterators. */
774 static struct props it_props
[] =
776 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
777 /* Handle `face' before `display' because some sub-properties of
778 `display' need to know the face. */
779 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
780 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
781 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
782 {&Qauto_composed
, AUTO_COMPOSED_PROP_IDX
, handle_auto_composed_prop
},
783 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
787 /* Value is the position described by X. If X is a marker, value is
788 the marker_position of X. Otherwise, value is X. */
790 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
792 /* Enumeration returned by some move_it_.* functions internally. */
796 /* Not used. Undefined value. */
799 /* Move ended at the requested buffer position or ZV. */
800 MOVE_POS_MATCH_OR_ZV
,
802 /* Move ended at the requested X pixel position. */
805 /* Move within a line ended at the end of a line that must be
809 /* Move within a line ended at the end of a line that would
810 be displayed truncated. */
813 /* Move within a line ended at a line end. */
817 /* This counter is used to clear the face cache every once in a while
818 in redisplay_internal. It is incremented for each redisplay.
819 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
822 #define CLEAR_FACE_CACHE_COUNT 500
823 static int clear_face_cache_count
;
825 /* Similarly for the image cache. */
827 #ifdef HAVE_WINDOW_SYSTEM
828 #define CLEAR_IMAGE_CACHE_COUNT 101
829 static int clear_image_cache_count
;
832 /* Non-zero while redisplay_internal is in progress. */
836 /* Non-zero means don't free realized faces. Bound while freeing
837 realized faces is dangerous because glyph matrices might still
840 int inhibit_free_realized_faces
;
841 Lisp_Object Qinhibit_free_realized_faces
;
843 /* If a string, XTread_socket generates an event to display that string.
844 (The display is done in read_char.) */
846 Lisp_Object help_echo_string
;
847 Lisp_Object help_echo_window
;
848 Lisp_Object help_echo_object
;
851 /* Temporary variable for XTread_socket. */
853 Lisp_Object previous_help_echo_string
;
855 /* Null glyph slice */
857 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
859 /* Platform-independent portion of hourglass implementation. */
861 /* Non-zero means we're allowed to display a hourglass pointer. */
862 int display_hourglass_p
;
864 /* Non-zero means an hourglass cursor is currently shown. */
865 int hourglass_shown_p
;
867 /* If non-null, an asynchronous timer that, when it expires, displays
868 an hourglass cursor on all frames. */
869 struct atimer
*hourglass_atimer
;
871 /* Number of seconds to wait before displaying an hourglass cursor. */
872 Lisp_Object Vhourglass_delay
;
874 /* Default number of seconds to wait before displaying an hourglass
876 #define DEFAULT_HOURGLASS_DELAY 1
879 /* Function prototypes. */
881 static void setup_for_ellipsis
P_ ((struct it
*, int));
882 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
883 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
884 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
885 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
886 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
887 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
889 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
891 static void handle_line_prefix
P_ ((struct it
*));
893 static void pint2str
P_ ((char *, int, int));
894 static void pint2hrstr
P_ ((char *, int, int));
895 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
897 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
898 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
899 static void store_mode_line_noprop_char
P_ ((char));
900 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
901 static void x_consider_frame_title
P_ ((Lisp_Object
));
902 static void handle_stop
P_ ((struct it
*));
903 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
904 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
905 static void ensure_echo_area_buffers
P_ ((void));
906 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
907 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
908 static int with_echo_area_buffer
P_ ((struct window
*, int,
909 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
910 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
911 static void clear_garbaged_frames
P_ ((void));
912 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
913 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
914 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
915 static int display_echo_area
P_ ((struct window
*));
916 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
918 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
919 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
920 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
922 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
923 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
924 static void insert_left_trunc_glyphs
P_ ((struct it
*));
925 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
927 static void extend_face_to_end_of_line
P_ ((struct it
*));
928 static int append_space_for_newline
P_ ((struct it
*, int));
929 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
930 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
931 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
932 static int trailing_whitespace_p
P_ ((int));
933 static int message_log_check_duplicate
P_ ((int, int, int, int));
934 static void push_it
P_ ((struct it
*));
935 static void pop_it
P_ ((struct it
*));
936 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
937 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
938 static void redisplay_internal
P_ ((int));
939 static int echo_area_display
P_ ((int));
940 static void redisplay_windows
P_ ((Lisp_Object
));
941 static void redisplay_window
P_ ((Lisp_Object
, int));
942 static Lisp_Object
redisplay_window_error ();
943 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
944 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
945 static int update_menu_bar
P_ ((struct frame
*, int, int));
946 static int try_window_reusing_current_matrix
P_ ((struct window
*));
947 static int try_window_id
P_ ((struct window
*));
948 static int display_line
P_ ((struct it
*));
949 static int display_mode_lines
P_ ((struct window
*));
950 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
951 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
952 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
953 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
954 static void display_menu_bar
P_ ((struct window
*));
955 static int display_count_lines
P_ ((int, int, int, int, int *));
956 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
957 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
958 static void compute_line_metrics
P_ ((struct it
*));
959 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
960 static int get_overlay_strings
P_ ((struct it
*, int));
961 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
962 static void next_overlay_string
P_ ((struct it
*));
963 static void reseat
P_ ((struct it
*, struct text_pos
, int));
964 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
965 static void back_to_previous_visible_line_start
P_ ((struct it
*));
966 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
967 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
968 static int next_element_from_ellipsis
P_ ((struct it
*));
969 static int next_element_from_display_vector
P_ ((struct it
*));
970 static int next_element_from_string
P_ ((struct it
*));
971 static int next_element_from_c_string
P_ ((struct it
*));
972 static int next_element_from_buffer
P_ ((struct it
*));
973 static int next_element_from_composition
P_ ((struct it
*));
974 static int next_element_from_image
P_ ((struct it
*));
975 static int next_element_from_stretch
P_ ((struct it
*));
976 static void load_overlay_strings
P_ ((struct it
*, int));
977 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
978 struct display_pos
*));
979 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
980 Lisp_Object
, int, int, int, int));
981 static enum move_it_result
982 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
983 enum move_operation_enum
);
984 void move_it_vertically_backward
P_ ((struct it
*, int));
985 static void init_to_row_start
P_ ((struct it
*, struct window
*,
986 struct glyph_row
*));
987 static int init_to_row_end
P_ ((struct it
*, struct window
*,
988 struct glyph_row
*));
989 static void back_to_previous_line_start
P_ ((struct it
*));
990 static int forward_to_next_line_start
P_ ((struct it
*, int *));
991 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
993 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
994 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
995 static int number_of_chars
P_ ((unsigned char *, int));
996 static void compute_stop_pos
P_ ((struct it
*));
997 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
999 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1000 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1001 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1002 Lisp_Object
, Lisp_Object
,
1003 struct text_pos
*, int));
1004 static int underlying_face_id
P_ ((struct it
*));
1005 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1008 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1009 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1011 #ifdef HAVE_WINDOW_SYSTEM
1013 static void update_tool_bar
P_ ((struct frame
*, int));
1014 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1015 static int redisplay_tool_bar
P_ ((struct frame
*));
1016 static void display_tool_bar_line
P_ ((struct it
*, int));
1017 static void notice_overwritten_cursor
P_ ((struct window
*,
1018 enum glyph_row_area
,
1019 int, int, int, int));
1023 #endif /* HAVE_WINDOW_SYSTEM */
1026 /***********************************************************************
1027 Window display dimensions
1028 ***********************************************************************/
1030 /* Return the bottom boundary y-position for text lines in window W.
1031 This is the first y position at which a line cannot start.
1032 It is relative to the top of the window.
1034 This is the height of W minus the height of a mode line, if any. */
1037 window_text_bottom_y (w
)
1040 int height
= WINDOW_TOTAL_HEIGHT (w
);
1042 if (WINDOW_WANTS_MODELINE_P (w
))
1043 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1047 /* Return the pixel width of display area AREA of window W. AREA < 0
1048 means return the total width of W, not including fringes to
1049 the left and right of the window. */
1052 window_box_width (w
, area
)
1056 int cols
= XFASTINT (w
->total_cols
);
1059 if (!w
->pseudo_window_p
)
1061 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1063 if (area
== TEXT_AREA
)
1065 if (INTEGERP (w
->left_margin_cols
))
1066 cols
-= XFASTINT (w
->left_margin_cols
);
1067 if (INTEGERP (w
->right_margin_cols
))
1068 cols
-= XFASTINT (w
->right_margin_cols
);
1069 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1071 else if (area
== LEFT_MARGIN_AREA
)
1073 cols
= (INTEGERP (w
->left_margin_cols
)
1074 ? XFASTINT (w
->left_margin_cols
) : 0);
1077 else if (area
== RIGHT_MARGIN_AREA
)
1079 cols
= (INTEGERP (w
->right_margin_cols
)
1080 ? XFASTINT (w
->right_margin_cols
) : 0);
1085 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1089 /* Return the pixel height of the display area of window W, not
1090 including mode lines of W, if any. */
1093 window_box_height (w
)
1096 struct frame
*f
= XFRAME (w
->frame
);
1097 int height
= WINDOW_TOTAL_HEIGHT (w
);
1099 xassert (height
>= 0);
1101 /* Note: the code below that determines the mode-line/header-line
1102 height is essentially the same as that contained in the macro
1103 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1104 the appropriate glyph row has its `mode_line_p' flag set,
1105 and if it doesn't, uses estimate_mode_line_height instead. */
1107 if (WINDOW_WANTS_MODELINE_P (w
))
1109 struct glyph_row
*ml_row
1110 = (w
->current_matrix
&& w
->current_matrix
->rows
1111 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1113 if (ml_row
&& ml_row
->mode_line_p
)
1114 height
-= ml_row
->height
;
1116 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1119 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1121 struct glyph_row
*hl_row
1122 = (w
->current_matrix
&& w
->current_matrix
->rows
1123 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1125 if (hl_row
&& hl_row
->mode_line_p
)
1126 height
-= hl_row
->height
;
1128 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1131 /* With a very small font and a mode-line that's taller than
1132 default, we might end up with a negative height. */
1133 return max (0, height
);
1136 /* Return the window-relative coordinate of the left edge of display
1137 area AREA of window W. AREA < 0 means return the left edge of the
1138 whole window, to the right of the left fringe of W. */
1141 window_box_left_offset (w
, area
)
1147 if (w
->pseudo_window_p
)
1150 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1152 if (area
== TEXT_AREA
)
1153 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1154 + window_box_width (w
, LEFT_MARGIN_AREA
));
1155 else if (area
== RIGHT_MARGIN_AREA
)
1156 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1157 + window_box_width (w
, LEFT_MARGIN_AREA
)
1158 + window_box_width (w
, TEXT_AREA
)
1159 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1161 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1162 else if (area
== LEFT_MARGIN_AREA
1163 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1164 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1170 /* Return the window-relative coordinate of the right edge of display
1171 area AREA of window W. AREA < 0 means return the left edge of the
1172 whole window, to the left of the right fringe of W. */
1175 window_box_right_offset (w
, area
)
1179 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1182 /* Return the frame-relative coordinate of the left edge of display
1183 area AREA of window W. AREA < 0 means return the left edge of the
1184 whole window, to the right of the left fringe of W. */
1187 window_box_left (w
, area
)
1191 struct frame
*f
= XFRAME (w
->frame
);
1194 if (w
->pseudo_window_p
)
1195 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1197 x
= (WINDOW_LEFT_EDGE_X (w
)
1198 + window_box_left_offset (w
, area
));
1204 /* Return the frame-relative coordinate of the right edge of display
1205 area AREA of window W. AREA < 0 means return the left edge of the
1206 whole window, to the left of the right fringe of W. */
1209 window_box_right (w
, area
)
1213 return window_box_left (w
, area
) + window_box_width (w
, area
);
1216 /* Get the bounding box of the display area AREA of window W, without
1217 mode lines, in frame-relative coordinates. AREA < 0 means the
1218 whole window, not including the left and right fringes of
1219 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1220 coordinates of the upper-left corner of the box. Return in
1221 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1224 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1227 int *box_x
, *box_y
, *box_width
, *box_height
;
1230 *box_width
= window_box_width (w
, area
);
1232 *box_height
= window_box_height (w
);
1234 *box_x
= window_box_left (w
, area
);
1237 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1238 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1239 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1244 /* Get the bounding box of the display area AREA of window W, without
1245 mode lines. AREA < 0 means the whole window, not including the
1246 left and right fringe of the window. Return in *TOP_LEFT_X
1247 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1248 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1249 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1253 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1254 bottom_right_x
, bottom_right_y
)
1257 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1259 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1261 *bottom_right_x
+= *top_left_x
;
1262 *bottom_right_y
+= *top_left_y
;
1267 /***********************************************************************
1269 ***********************************************************************/
1271 /* Return the bottom y-position of the line the iterator IT is in.
1272 This can modify IT's settings. */
1278 int line_height
= it
->max_ascent
+ it
->max_descent
;
1279 int line_top_y
= it
->current_y
;
1281 if (line_height
== 0)
1284 line_height
= last_height
;
1285 else if (IT_CHARPOS (*it
) < ZV
)
1287 move_it_by_lines (it
, 1, 1);
1288 line_height
= (it
->max_ascent
|| it
->max_descent
1289 ? it
->max_ascent
+ it
->max_descent
1294 struct glyph_row
*row
= it
->glyph_row
;
1296 /* Use the default character height. */
1297 it
->glyph_row
= NULL
;
1298 it
->what
= IT_CHARACTER
;
1301 PRODUCE_GLYPHS (it
);
1302 line_height
= it
->ascent
+ it
->descent
;
1303 it
->glyph_row
= row
;
1307 return line_top_y
+ line_height
;
1311 /* Return 1 if position CHARPOS is visible in window W.
1312 CHARPOS < 0 means return info about WINDOW_END position.
1313 If visible, set *X and *Y to pixel coordinates of top left corner.
1314 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1315 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1318 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1320 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1323 struct text_pos top
;
1325 struct buffer
*old_buffer
= NULL
;
1330 if (XBUFFER (w
->buffer
) != current_buffer
)
1332 old_buffer
= current_buffer
;
1333 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1336 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1338 /* Compute exact mode line heights. */
1339 if (WINDOW_WANTS_MODELINE_P (w
))
1340 current_mode_line_height
1341 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1342 current_buffer
->mode_line_format
);
1344 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1345 current_header_line_height
1346 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1347 current_buffer
->header_line_format
);
1349 start_display (&it
, w
, top
);
1350 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1351 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1353 /* Note that we may overshoot because of invisible text. */
1354 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1356 int top_x
= it
.current_x
;
1357 int top_y
= it
.current_y
;
1358 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1359 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1361 if (top_y
< window_top_y
)
1362 visible_p
= bottom_y
> window_top_y
;
1363 else if (top_y
< it
.last_visible_y
)
1367 if (it
.method
== GET_FROM_BUFFER
)
1369 Lisp_Object window
, prop
;
1371 XSETWINDOW (window
, w
);
1372 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1373 Qinvisible
, window
);
1375 /* If charpos coincides with invisible text covered with an
1376 ellipsis, use the first glyph of the ellipsis to compute
1377 the pixel positions. */
1378 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1380 struct glyph_row
*row
= it
.glyph_row
;
1381 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1382 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1385 for (; glyph
< end
&& glyph
->charpos
< charpos
; glyph
++)
1386 x
+= glyph
->pixel_width
;
1393 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1394 *rtop
= max (0, window_top_y
- top_y
);
1395 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1396 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1397 - max (top_y
, window_top_y
)));
1406 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1407 move_it_by_lines (&it
, 1, 0);
1408 if (charpos
< IT_CHARPOS (it
)
1409 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1412 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1414 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1415 *rtop
= max (0, -it2
.current_y
);
1416 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1417 - it
.last_visible_y
));
1418 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1420 - max (it2
.current_y
,
1421 WINDOW_HEADER_LINE_HEIGHT (w
))));
1427 set_buffer_internal_1 (old_buffer
);
1429 current_header_line_height
= current_mode_line_height
= -1;
1431 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1432 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1435 /* Debugging code. */
1437 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1438 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1440 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1447 /* Return the next character from STR which is MAXLEN bytes long.
1448 Return in *LEN the length of the character. This is like
1449 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1450 we find one, we return a `?', but with the length of the invalid
1454 string_char_and_length (str
, maxlen
, len
)
1455 const unsigned char *str
;
1460 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1461 if (!CHAR_VALID_P (c
, 1))
1462 /* We may not change the length here because other places in Emacs
1463 don't use this function, i.e. they silently accept invalid
1472 /* Given a position POS containing a valid character and byte position
1473 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1475 static struct text_pos
1476 string_pos_nchars_ahead (pos
, string
, nchars
)
1477 struct text_pos pos
;
1481 xassert (STRINGP (string
) && nchars
>= 0);
1483 if (STRING_MULTIBYTE (string
))
1485 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1486 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1491 string_char_and_length (p
, rest
, &len
);
1492 p
+= len
, rest
-= len
;
1493 xassert (rest
>= 0);
1495 BYTEPOS (pos
) += len
;
1499 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1505 /* Value is the text position, i.e. character and byte position,
1506 for character position CHARPOS in STRING. */
1508 static INLINE
struct text_pos
1509 string_pos (charpos
, string
)
1513 struct text_pos pos
;
1514 xassert (STRINGP (string
));
1515 xassert (charpos
>= 0);
1516 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1521 /* Value is a text position, i.e. character and byte position, for
1522 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1523 means recognize multibyte characters. */
1525 static struct text_pos
1526 c_string_pos (charpos
, s
, multibyte_p
)
1531 struct text_pos pos
;
1533 xassert (s
!= NULL
);
1534 xassert (charpos
>= 0);
1538 int rest
= strlen (s
), len
;
1540 SET_TEXT_POS (pos
, 0, 0);
1543 string_char_and_length (s
, rest
, &len
);
1544 s
+= len
, rest
-= len
;
1545 xassert (rest
>= 0);
1547 BYTEPOS (pos
) += len
;
1551 SET_TEXT_POS (pos
, charpos
, charpos
);
1557 /* Value is the number of characters in C string S. MULTIBYTE_P
1558 non-zero means recognize multibyte characters. */
1561 number_of_chars (s
, multibyte_p
)
1569 int rest
= strlen (s
), len
;
1570 unsigned char *p
= (unsigned char *) s
;
1572 for (nchars
= 0; rest
> 0; ++nchars
)
1574 string_char_and_length (p
, rest
, &len
);
1575 rest
-= len
, p
+= len
;
1579 nchars
= strlen (s
);
1585 /* Compute byte position NEWPOS->bytepos corresponding to
1586 NEWPOS->charpos. POS is a known position in string STRING.
1587 NEWPOS->charpos must be >= POS.charpos. */
1590 compute_string_pos (newpos
, pos
, string
)
1591 struct text_pos
*newpos
, pos
;
1594 xassert (STRINGP (string
));
1595 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1597 if (STRING_MULTIBYTE (string
))
1598 *newpos
= string_pos_nchars_ahead (pos
, string
,
1599 CHARPOS (*newpos
) - CHARPOS (pos
));
1601 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1605 Return an estimation of the pixel height of mode or top lines on
1606 frame F. FACE_ID specifies what line's height to estimate. */
1609 estimate_mode_line_height (f
, face_id
)
1611 enum face_id face_id
;
1613 #ifdef HAVE_WINDOW_SYSTEM
1614 if (FRAME_WINDOW_P (f
))
1616 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1618 /* This function is called so early when Emacs starts that the face
1619 cache and mode line face are not yet initialized. */
1620 if (FRAME_FACE_CACHE (f
))
1622 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1626 height
= FONT_HEIGHT (face
->font
);
1627 if (face
->box_line_width
> 0)
1628 height
+= 2 * face
->box_line_width
;
1639 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1640 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1641 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1642 not force the value into range. */
1645 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1647 register int pix_x
, pix_y
;
1649 NativeRectangle
*bounds
;
1653 #ifdef HAVE_WINDOW_SYSTEM
1654 if (FRAME_WINDOW_P (f
))
1656 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1657 even for negative values. */
1659 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1661 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1663 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1664 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1667 STORE_NATIVE_RECT (*bounds
,
1668 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1669 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1670 FRAME_COLUMN_WIDTH (f
) - 1,
1671 FRAME_LINE_HEIGHT (f
) - 1);
1677 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1678 pix_x
= FRAME_TOTAL_COLS (f
);
1682 else if (pix_y
> FRAME_LINES (f
))
1683 pix_y
= FRAME_LINES (f
);
1693 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1694 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1695 can't tell the positions because W's display is not up to date,
1699 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1702 int *frame_x
, *frame_y
;
1704 #ifdef HAVE_WINDOW_SYSTEM
1705 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1709 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1710 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1712 if (display_completed
)
1714 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1715 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1716 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1722 hpos
+= glyph
->pixel_width
;
1726 /* If first glyph is partially visible, its first visible position is still 0. */
1738 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1739 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1750 #ifdef HAVE_WINDOW_SYSTEM
1752 /* Find the glyph under window-relative coordinates X/Y in window W.
1753 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1754 strings. Return in *HPOS and *VPOS the row and column number of
1755 the glyph found. Return in *AREA the glyph area containing X.
1756 Value is a pointer to the glyph found or null if X/Y is not on
1757 text, or we can't tell because W's current matrix is not up to
1762 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1765 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1767 struct glyph
*glyph
, *end
;
1768 struct glyph_row
*row
= NULL
;
1771 /* Find row containing Y. Give up if some row is not enabled. */
1772 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1774 row
= MATRIX_ROW (w
->current_matrix
, i
);
1775 if (!row
->enabled_p
)
1777 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1784 /* Give up if Y is not in the window. */
1785 if (i
== w
->current_matrix
->nrows
)
1788 /* Get the glyph area containing X. */
1789 if (w
->pseudo_window_p
)
1796 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1798 *area
= LEFT_MARGIN_AREA
;
1799 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1801 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1804 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1808 *area
= RIGHT_MARGIN_AREA
;
1809 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1813 /* Find glyph containing X. */
1814 glyph
= row
->glyphs
[*area
];
1815 end
= glyph
+ row
->used
[*area
];
1817 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1819 x
-= glyph
->pixel_width
;
1829 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1832 *hpos
= glyph
- row
->glyphs
[*area
];
1838 Convert frame-relative x/y to coordinates relative to window W.
1839 Takes pseudo-windows into account. */
1842 frame_to_window_pixel_xy (w
, x
, y
)
1846 if (w
->pseudo_window_p
)
1848 /* A pseudo-window is always full-width, and starts at the
1849 left edge of the frame, plus a frame border. */
1850 struct frame
*f
= XFRAME (w
->frame
);
1851 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1852 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1856 *x
-= WINDOW_LEFT_EDGE_X (w
);
1857 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1862 Return in RECTS[] at most N clipping rectangles for glyph string S.
1863 Return the number of stored rectangles. */
1866 get_glyph_string_clip_rects (s
, rects
, n
)
1867 struct glyph_string
*s
;
1868 NativeRectangle
*rects
;
1876 if (s
->row
->full_width_p
)
1878 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1879 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1880 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1882 /* Unless displaying a mode or menu bar line, which are always
1883 fully visible, clip to the visible part of the row. */
1884 if (s
->w
->pseudo_window_p
)
1885 r
.height
= s
->row
->visible_height
;
1887 r
.height
= s
->height
;
1891 /* This is a text line that may be partially visible. */
1892 r
.x
= window_box_left (s
->w
, s
->area
);
1893 r
.width
= window_box_width (s
->w
, s
->area
);
1894 r
.height
= s
->row
->visible_height
;
1898 if (r
.x
< s
->clip_head
->x
)
1900 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1901 r
.width
-= s
->clip_head
->x
- r
.x
;
1904 r
.x
= s
->clip_head
->x
;
1907 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1909 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1910 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1915 /* If S draws overlapping rows, it's sufficient to use the top and
1916 bottom of the window for clipping because this glyph string
1917 intentionally draws over other lines. */
1918 if (s
->for_overlaps
)
1920 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1921 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1923 /* Alas, the above simple strategy does not work for the
1924 environments with anti-aliased text: if the same text is
1925 drawn onto the same place multiple times, it gets thicker.
1926 If the overlap we are processing is for the erased cursor, we
1927 take the intersection with the rectagle of the cursor. */
1928 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1930 XRectangle rc
, r_save
= r
;
1932 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1933 rc
.y
= s
->w
->phys_cursor
.y
;
1934 rc
.width
= s
->w
->phys_cursor_width
;
1935 rc
.height
= s
->w
->phys_cursor_height
;
1937 x_intersect_rectangles (&r_save
, &rc
, &r
);
1942 /* Don't use S->y for clipping because it doesn't take partially
1943 visible lines into account. For example, it can be negative for
1944 partially visible lines at the top of a window. */
1945 if (!s
->row
->full_width_p
1946 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1947 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1949 r
.y
= max (0, s
->row
->y
);
1951 /* If drawing a tool-bar window, draw it over the internal border
1952 at the top of the window. */
1953 if (WINDOWP (s
->f
->tool_bar_window
)
1954 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1955 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1958 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1960 /* If drawing the cursor, don't let glyph draw outside its
1961 advertised boundaries. Cleartype does this under some circumstances. */
1962 if (s
->hl
== DRAW_CURSOR
)
1964 struct glyph
*glyph
= s
->first_glyph
;
1969 r
.width
-= s
->x
- r
.x
;
1972 r
.width
= min (r
.width
, glyph
->pixel_width
);
1974 /* If r.y is below window bottom, ensure that we still see a cursor. */
1975 height
= min (glyph
->ascent
+ glyph
->descent
,
1976 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1977 max_y
= window_text_bottom_y (s
->w
) - height
;
1978 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1979 if (s
->ybase
- glyph
->ascent
> max_y
)
1986 /* Don't draw cursor glyph taller than our actual glyph. */
1987 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1988 if (height
< r
.height
)
1990 max_y
= r
.y
+ r
.height
;
1991 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1992 r
.height
= min (max_y
- r
.y
, height
);
1999 XRectangle r_save
= r
;
2001 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2005 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2006 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2008 #ifdef CONVERT_FROM_XRECT
2009 CONVERT_FROM_XRECT (r
, *rects
);
2017 /* If we are processing overlapping and allowed to return
2018 multiple clipping rectangles, we exclude the row of the glyph
2019 string from the clipping rectangle. This is to avoid drawing
2020 the same text on the environment with anti-aliasing. */
2021 #ifdef CONVERT_FROM_XRECT
2024 XRectangle
*rs
= rects
;
2026 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2028 if (s
->for_overlaps
& OVERLAPS_PRED
)
2031 if (r
.y
+ r
.height
> row_y
)
2034 rs
[i
].height
= row_y
- r
.y
;
2040 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2043 if (r
.y
< row_y
+ s
->row
->visible_height
)
2045 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2047 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2048 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2057 #ifdef CONVERT_FROM_XRECT
2058 for (i
= 0; i
< n
; i
++)
2059 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2066 Return in *NR the clipping rectangle for glyph string S. */
2069 get_glyph_string_clip_rect (s
, nr
)
2070 struct glyph_string
*s
;
2071 NativeRectangle
*nr
;
2073 get_glyph_string_clip_rects (s
, nr
, 1);
2078 Return the position and height of the phys cursor in window W.
2079 Set w->phys_cursor_width to width of phys cursor.
2083 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2085 struct glyph_row
*row
;
2086 struct glyph
*glyph
;
2087 int *xp
, *yp
, *heightp
;
2089 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2090 int x
, y
, wd
, h
, h0
, y0
;
2092 /* Compute the width of the rectangle to draw. If on a stretch
2093 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2094 rectangle as wide as the glyph, but use a canonical character
2096 wd
= glyph
->pixel_width
- 1;
2097 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2101 x
= w
->phys_cursor
.x
;
2108 if (glyph
->type
== STRETCH_GLYPH
2109 && !x_stretch_cursor_p
)
2110 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2111 w
->phys_cursor_width
= wd
;
2113 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2115 /* If y is below window bottom, ensure that we still see a cursor. */
2116 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2118 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2119 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2121 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2124 h
= max (h
- (y0
- y
) + 1, h0
);
2129 y0
= window_text_bottom_y (w
) - h0
;
2137 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2138 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2143 * Remember which glyph the mouse is over.
2147 remember_mouse_glyph (f
, gx
, gy
, rect
)
2150 NativeRectangle
*rect
;
2154 struct glyph_row
*r
, *gr
, *end_row
;
2155 enum window_part part
;
2156 enum glyph_row_area area
;
2157 int x
, y
, width
, height
;
2159 /* Try to determine frame pixel position and size of the glyph under
2160 frame pixel coordinates X/Y on frame F. */
2162 if (!f
->glyphs_initialized_p
2163 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2166 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2167 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2171 w
= XWINDOW (window
);
2172 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2173 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2175 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2176 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2178 if (w
->pseudo_window_p
)
2181 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2187 case ON_LEFT_MARGIN
:
2188 area
= LEFT_MARGIN_AREA
;
2191 case ON_RIGHT_MARGIN
:
2192 area
= RIGHT_MARGIN_AREA
;
2195 case ON_HEADER_LINE
:
2197 gr
= (part
== ON_HEADER_LINE
2198 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2199 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2202 goto text_glyph_row_found
;
2209 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2210 if (r
->y
+ r
->height
> y
)
2216 text_glyph_row_found
:
2219 struct glyph
*g
= gr
->glyphs
[area
];
2220 struct glyph
*end
= g
+ gr
->used
[area
];
2222 height
= gr
->height
;
2223 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2224 if (gx
+ g
->pixel_width
> x
)
2229 if (g
->type
== IMAGE_GLYPH
)
2231 /* Don't remember when mouse is over image, as
2232 image may have hot-spots. */
2233 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2236 width
= g
->pixel_width
;
2240 /* Use nominal char spacing at end of line. */
2242 gx
+= (x
/ width
) * width
;
2245 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2246 gx
+= window_box_left_offset (w
, area
);
2250 /* Use nominal line height at end of window. */
2251 gx
= (x
/ width
) * width
;
2253 gy
+= (y
/ height
) * height
;
2257 case ON_LEFT_FRINGE
:
2258 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2259 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2260 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2261 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2264 case ON_RIGHT_FRINGE
:
2265 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2266 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2267 : window_box_right_offset (w
, TEXT_AREA
));
2268 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2272 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2274 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2275 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2276 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2278 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2282 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2283 if (r
->y
+ r
->height
> y
)
2290 height
= gr
->height
;
2293 /* Use nominal line height at end of window. */
2295 gy
+= (y
/ height
) * height
;
2302 /* If there is no glyph under the mouse, then we divide the screen
2303 into a grid of the smallest glyph in the frame, and use that
2306 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2307 round down even for negative values. */
2313 gx
= (gx
/ width
) * width
;
2314 gy
= (gy
/ height
) * height
;
2319 gx
+= WINDOW_LEFT_EDGE_X (w
);
2320 gy
+= WINDOW_TOP_EDGE_Y (w
);
2323 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2325 /* Visible feedback for debugging. */
2328 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2329 f
->output_data
.x
->normal_gc
,
2330 gx
, gy
, width
, height
);
2336 #endif /* HAVE_WINDOW_SYSTEM */
2339 /***********************************************************************
2340 Lisp form evaluation
2341 ***********************************************************************/
2343 /* Error handler for safe_eval and safe_call. */
2346 safe_eval_handler (arg
)
2349 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2354 /* Evaluate SEXPR and return the result, or nil if something went
2355 wrong. Prevent redisplay during the evaluation. */
2357 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2358 Return the result, or nil if something went wrong. Prevent
2359 redisplay during the evaluation. */
2362 safe_call (nargs
, args
)
2368 if (inhibit_eval_during_redisplay
)
2372 int count
= SPECPDL_INDEX ();
2373 struct gcpro gcpro1
;
2376 gcpro1
.nvars
= nargs
;
2377 specbind (Qinhibit_redisplay
, Qt
);
2378 /* Use Qt to ensure debugger does not run,
2379 so there is no possibility of wanting to redisplay. */
2380 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2383 val
= unbind_to (count
, val
);
2390 /* Call function FN with one argument ARG.
2391 Return the result, or nil if something went wrong. */
2394 safe_call1 (fn
, arg
)
2395 Lisp_Object fn
, arg
;
2397 Lisp_Object args
[2];
2400 return safe_call (2, args
);
2403 static Lisp_Object Qeval
;
2406 safe_eval (Lisp_Object sexpr
)
2408 return safe_call1 (Qeval
, sexpr
);
2411 /* Call function FN with one argument ARG.
2412 Return the result, or nil if something went wrong. */
2415 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2417 Lisp_Object args
[3];
2421 return safe_call (3, args
);
2426 /***********************************************************************
2428 ***********************************************************************/
2432 /* Define CHECK_IT to perform sanity checks on iterators.
2433 This is for debugging. It is too slow to do unconditionally. */
2439 if (it
->method
== GET_FROM_STRING
)
2441 xassert (STRINGP (it
->string
));
2442 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2446 xassert (IT_STRING_CHARPOS (*it
) < 0);
2447 if (it
->method
== GET_FROM_BUFFER
)
2449 /* Check that character and byte positions agree. */
2450 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2455 xassert (it
->current
.dpvec_index
>= 0);
2457 xassert (it
->current
.dpvec_index
< 0);
2460 #define CHECK_IT(IT) check_it ((IT))
2464 #define CHECK_IT(IT) (void) 0
2471 /* Check that the window end of window W is what we expect it
2472 to be---the last row in the current matrix displaying text. */
2475 check_window_end (w
)
2478 if (!MINI_WINDOW_P (w
)
2479 && !NILP (w
->window_end_valid
))
2481 struct glyph_row
*row
;
2482 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2483 XFASTINT (w
->window_end_vpos
)),
2485 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2486 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2490 #define CHECK_WINDOW_END(W) check_window_end ((W))
2492 #else /* not GLYPH_DEBUG */
2494 #define CHECK_WINDOW_END(W) (void) 0
2496 #endif /* not GLYPH_DEBUG */
2500 /***********************************************************************
2501 Iterator initialization
2502 ***********************************************************************/
2504 /* Initialize IT for displaying current_buffer in window W, starting
2505 at character position CHARPOS. CHARPOS < 0 means that no buffer
2506 position is specified which is useful when the iterator is assigned
2507 a position later. BYTEPOS is the byte position corresponding to
2508 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2510 If ROW is not null, calls to produce_glyphs with IT as parameter
2511 will produce glyphs in that row.
2513 BASE_FACE_ID is the id of a base face to use. It must be one of
2514 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2515 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2516 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2518 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2519 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2520 will be initialized to use the corresponding mode line glyph row of
2521 the desired matrix of W. */
2524 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2527 int charpos
, bytepos
;
2528 struct glyph_row
*row
;
2529 enum face_id base_face_id
;
2531 int highlight_region_p
;
2532 enum face_id remapped_base_face_id
= base_face_id
;
2534 /* Some precondition checks. */
2535 xassert (w
!= NULL
&& it
!= NULL
);
2536 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2539 /* If face attributes have been changed since the last redisplay,
2540 free realized faces now because they depend on face definitions
2541 that might have changed. Don't free faces while there might be
2542 desired matrices pending which reference these faces. */
2543 if (face_change_count
&& !inhibit_free_realized_faces
)
2545 face_change_count
= 0;
2546 free_all_realized_faces (Qnil
);
2549 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2550 if (! NILP (Vface_remapping_alist
))
2551 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2553 /* Use one of the mode line rows of W's desired matrix if
2557 if (base_face_id
== MODE_LINE_FACE_ID
2558 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2559 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2560 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2561 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2565 bzero (it
, sizeof *it
);
2566 it
->current
.overlay_string_index
= -1;
2567 it
->current
.dpvec_index
= -1;
2568 it
->base_face_id
= remapped_base_face_id
;
2570 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2572 /* The window in which we iterate over current_buffer: */
2573 XSETWINDOW (it
->window
, w
);
2575 it
->f
= XFRAME (w
->frame
);
2577 /* Extra space between lines (on window systems only). */
2578 if (base_face_id
== DEFAULT_FACE_ID
2579 && FRAME_WINDOW_P (it
->f
))
2581 if (NATNUMP (current_buffer
->extra_line_spacing
))
2582 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2583 else if (FLOATP (current_buffer
->extra_line_spacing
))
2584 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2585 * FRAME_LINE_HEIGHT (it
->f
));
2586 else if (it
->f
->extra_line_spacing
> 0)
2587 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2588 it
->max_extra_line_spacing
= 0;
2591 /* If realized faces have been removed, e.g. because of face
2592 attribute changes of named faces, recompute them. When running
2593 in batch mode, the face cache of the initial frame is null. If
2594 we happen to get called, make a dummy face cache. */
2595 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2596 init_frame_faces (it
->f
);
2597 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2598 recompute_basic_faces (it
->f
);
2600 /* Current value of the `slice', `space-width', and 'height' properties. */
2601 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2602 it
->space_width
= Qnil
;
2603 it
->font_height
= Qnil
;
2604 it
->override_ascent
= -1;
2606 /* Are control characters displayed as `^C'? */
2607 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2609 /* -1 means everything between a CR and the following line end
2610 is invisible. >0 means lines indented more than this value are
2612 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2613 ? XFASTINT (current_buffer
->selective_display
)
2614 : (!NILP (current_buffer
->selective_display
)
2616 it
->selective_display_ellipsis_p
2617 = !NILP (current_buffer
->selective_display_ellipses
);
2619 /* Display table to use. */
2620 it
->dp
= window_display_table (w
);
2622 /* Are multibyte characters enabled in current_buffer? */
2623 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2625 /* Non-zero if we should highlight the region. */
2627 = (!NILP (Vtransient_mark_mode
)
2628 && !NILP (current_buffer
->mark_active
)
2629 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2631 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2632 start and end of a visible region in window IT->w. Set both to
2633 -1 to indicate no region. */
2634 if (highlight_region_p
2635 /* Maybe highlight only in selected window. */
2636 && (/* Either show region everywhere. */
2637 highlight_nonselected_windows
2638 /* Or show region in the selected window. */
2639 || w
== XWINDOW (selected_window
)
2640 /* Or show the region if we are in the mini-buffer and W is
2641 the window the mini-buffer refers to. */
2642 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2643 && WINDOWP (minibuf_selected_window
)
2644 && w
== XWINDOW (minibuf_selected_window
))))
2646 int charpos
= marker_position (current_buffer
->mark
);
2647 it
->region_beg_charpos
= min (PT
, charpos
);
2648 it
->region_end_charpos
= max (PT
, charpos
);
2651 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2653 /* Get the position at which the redisplay_end_trigger hook should
2654 be run, if it is to be run at all. */
2655 if (MARKERP (w
->redisplay_end_trigger
)
2656 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2657 it
->redisplay_end_trigger_charpos
2658 = marker_position (w
->redisplay_end_trigger
);
2659 else if (INTEGERP (w
->redisplay_end_trigger
))
2660 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2662 /* Correct bogus values of tab_width. */
2663 it
->tab_width
= XINT (current_buffer
->tab_width
);
2664 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2667 /* Are lines in the display truncated? */
2668 if (base_face_id
!= DEFAULT_FACE_ID
2669 || XINT (it
->w
->hscroll
)
2670 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2671 && ((!NILP (Vtruncate_partial_width_windows
)
2672 && !INTEGERP (Vtruncate_partial_width_windows
))
2673 || (INTEGERP (Vtruncate_partial_width_windows
)
2674 && (WINDOW_TOTAL_COLS (it
->w
)
2675 < XINT (Vtruncate_partial_width_windows
))))))
2676 it
->line_wrap
= TRUNCATE
;
2677 else if (NILP (current_buffer
->truncate_lines
))
2678 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2679 ? WINDOW_WRAP
: WORD_WRAP
;
2681 it
->line_wrap
= TRUNCATE
;
2683 /* Get dimensions of truncation and continuation glyphs. These are
2684 displayed as fringe bitmaps under X, so we don't need them for such
2686 if (!FRAME_WINDOW_P (it
->f
))
2688 if (it
->line_wrap
== TRUNCATE
)
2690 /* We will need the truncation glyph. */
2691 xassert (it
->glyph_row
== NULL
);
2692 produce_special_glyphs (it
, IT_TRUNCATION
);
2693 it
->truncation_pixel_width
= it
->pixel_width
;
2697 /* We will need the continuation glyph. */
2698 xassert (it
->glyph_row
== NULL
);
2699 produce_special_glyphs (it
, IT_CONTINUATION
);
2700 it
->continuation_pixel_width
= it
->pixel_width
;
2703 /* Reset these values to zero because the produce_special_glyphs
2704 above has changed them. */
2705 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2706 it
->phys_ascent
= it
->phys_descent
= 0;
2709 /* Set this after getting the dimensions of truncation and
2710 continuation glyphs, so that we don't produce glyphs when calling
2711 produce_special_glyphs, above. */
2712 it
->glyph_row
= row
;
2713 it
->area
= TEXT_AREA
;
2715 /* Get the dimensions of the display area. The display area
2716 consists of the visible window area plus a horizontally scrolled
2717 part to the left of the window. All x-values are relative to the
2718 start of this total display area. */
2719 if (base_face_id
!= DEFAULT_FACE_ID
)
2721 /* Mode lines, menu bar in terminal frames. */
2722 it
->first_visible_x
= 0;
2723 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2728 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2729 it
->last_visible_x
= (it
->first_visible_x
2730 + window_box_width (w
, TEXT_AREA
));
2732 /* If we truncate lines, leave room for the truncator glyph(s) at
2733 the right margin. Otherwise, leave room for the continuation
2734 glyph(s). Truncation and continuation glyphs are not inserted
2735 for window-based redisplay. */
2736 if (!FRAME_WINDOW_P (it
->f
))
2738 if (it
->line_wrap
== TRUNCATE
)
2739 it
->last_visible_x
-= it
->truncation_pixel_width
;
2741 it
->last_visible_x
-= it
->continuation_pixel_width
;
2744 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2745 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2748 /* Leave room for a border glyph. */
2749 if (!FRAME_WINDOW_P (it
->f
)
2750 && !WINDOW_RIGHTMOST_P (it
->w
))
2751 it
->last_visible_x
-= 1;
2753 it
->last_visible_y
= window_text_bottom_y (w
);
2755 /* For mode lines and alike, arrange for the first glyph having a
2756 left box line if the face specifies a box. */
2757 if (base_face_id
!= DEFAULT_FACE_ID
)
2761 it
->face_id
= remapped_base_face_id
;
2763 /* If we have a boxed mode line, make the first character appear
2764 with a left box line. */
2765 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2766 if (face
->box
!= FACE_NO_BOX
)
2767 it
->start_of_box_run_p
= 1;
2770 /* If a buffer position was specified, set the iterator there,
2771 getting overlays and face properties from that position. */
2772 if (charpos
>= BUF_BEG (current_buffer
))
2774 it
->end_charpos
= ZV
;
2776 IT_CHARPOS (*it
) = charpos
;
2778 /* Compute byte position if not specified. */
2779 if (bytepos
< charpos
)
2780 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2782 IT_BYTEPOS (*it
) = bytepos
;
2784 it
->start
= it
->current
;
2786 /* Compute faces etc. */
2787 reseat (it
, it
->current
.pos
, 1);
2794 /* Initialize IT for the display of window W with window start POS. */
2797 start_display (it
, w
, pos
)
2800 struct text_pos pos
;
2802 struct glyph_row
*row
;
2803 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2805 row
= w
->desired_matrix
->rows
+ first_vpos
;
2806 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2807 it
->first_vpos
= first_vpos
;
2809 /* Don't reseat to previous visible line start if current start
2810 position is in a string or image. */
2811 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2813 int start_at_line_beg_p
;
2814 int first_y
= it
->current_y
;
2816 /* If window start is not at a line start, skip forward to POS to
2817 get the correct continuation lines width. */
2818 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2819 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2820 if (!start_at_line_beg_p
)
2824 reseat_at_previous_visible_line_start (it
);
2825 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2827 new_x
= it
->current_x
+ it
->pixel_width
;
2829 /* If lines are continued, this line may end in the middle
2830 of a multi-glyph character (e.g. a control character
2831 displayed as \003, or in the middle of an overlay
2832 string). In this case move_it_to above will not have
2833 taken us to the start of the continuation line but to the
2834 end of the continued line. */
2835 if (it
->current_x
> 0
2836 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2837 && (/* And glyph doesn't fit on the line. */
2838 new_x
> it
->last_visible_x
2839 /* Or it fits exactly and we're on a window
2841 || (new_x
== it
->last_visible_x
2842 && FRAME_WINDOW_P (it
->f
))))
2844 if (it
->current
.dpvec_index
>= 0
2845 || it
->current
.overlay_string_index
>= 0)
2847 set_iterator_to_next (it
, 1);
2848 move_it_in_display_line_to (it
, -1, -1, 0);
2851 it
->continuation_lines_width
+= it
->current_x
;
2854 /* We're starting a new display line, not affected by the
2855 height of the continued line, so clear the appropriate
2856 fields in the iterator structure. */
2857 it
->max_ascent
= it
->max_descent
= 0;
2858 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2860 it
->current_y
= first_y
;
2862 it
->current_x
= it
->hpos
= 0;
2866 #if 0 /* Don't assert the following because start_display is sometimes
2867 called intentionally with a window start that is not at a
2868 line start. Please leave this code in as a comment. */
2870 /* Window start should be on a line start, now. */
2871 xassert (it
->continuation_lines_width
2872 || IT_CHARPOS (it
) == BEGV
2873 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2878 /* Return 1 if POS is a position in ellipses displayed for invisible
2879 text. W is the window we display, for text property lookup. */
2882 in_ellipses_for_invisible_text_p (pos
, w
)
2883 struct display_pos
*pos
;
2886 Lisp_Object prop
, window
;
2888 int charpos
= CHARPOS (pos
->pos
);
2890 /* If POS specifies a position in a display vector, this might
2891 be for an ellipsis displayed for invisible text. We won't
2892 get the iterator set up for delivering that ellipsis unless
2893 we make sure that it gets aware of the invisible text. */
2894 if (pos
->dpvec_index
>= 0
2895 && pos
->overlay_string_index
< 0
2896 && CHARPOS (pos
->string_pos
) < 0
2898 && (XSETWINDOW (window
, w
),
2899 prop
= Fget_char_property (make_number (charpos
),
2900 Qinvisible
, window
),
2901 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2903 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2905 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2912 /* Initialize IT for stepping through current_buffer in window W,
2913 starting at position POS that includes overlay string and display
2914 vector/ control character translation position information. Value
2915 is zero if there are overlay strings with newlines at POS. */
2918 init_from_display_pos (it
, w
, pos
)
2921 struct display_pos
*pos
;
2923 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2924 int i
, overlay_strings_with_newlines
= 0;
2926 /* If POS specifies a position in a display vector, this might
2927 be for an ellipsis displayed for invisible text. We won't
2928 get the iterator set up for delivering that ellipsis unless
2929 we make sure that it gets aware of the invisible text. */
2930 if (in_ellipses_for_invisible_text_p (pos
, w
))
2936 /* Keep in mind: the call to reseat in init_iterator skips invisible
2937 text, so we might end up at a position different from POS. This
2938 is only a problem when POS is a row start after a newline and an
2939 overlay starts there with an after-string, and the overlay has an
2940 invisible property. Since we don't skip invisible text in
2941 display_line and elsewhere immediately after consuming the
2942 newline before the row start, such a POS will not be in a string,
2943 but the call to init_iterator below will move us to the
2945 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2947 /* This only scans the current chunk -- it should scan all chunks.
2948 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2949 to 16 in 22.1 to make this a lesser problem. */
2950 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2952 const char *s
= SDATA (it
->overlay_strings
[i
]);
2953 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2955 while (s
< e
&& *s
!= '\n')
2960 overlay_strings_with_newlines
= 1;
2965 /* If position is within an overlay string, set up IT to the right
2967 if (pos
->overlay_string_index
>= 0)
2971 /* If the first overlay string happens to have a `display'
2972 property for an image, the iterator will be set up for that
2973 image, and we have to undo that setup first before we can
2974 correct the overlay string index. */
2975 if (it
->method
== GET_FROM_IMAGE
)
2978 /* We already have the first chunk of overlay strings in
2979 IT->overlay_strings. Load more until the one for
2980 pos->overlay_string_index is in IT->overlay_strings. */
2981 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2983 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2984 it
->current
.overlay_string_index
= 0;
2987 load_overlay_strings (it
, 0);
2988 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2992 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2993 relative_index
= (it
->current
.overlay_string_index
2994 % OVERLAY_STRING_CHUNK_SIZE
);
2995 it
->string
= it
->overlay_strings
[relative_index
];
2996 xassert (STRINGP (it
->string
));
2997 it
->current
.string_pos
= pos
->string_pos
;
2998 it
->method
= GET_FROM_STRING
;
3001 #if 0 /* This is bogus because POS not having an overlay string
3002 position does not mean it's after the string. Example: A
3003 line starting with a before-string and initialization of IT
3004 to the previous row's end position. */
3005 else if (it
->current
.overlay_string_index
>= 0)
3007 /* If POS says we're already after an overlay string ending at
3008 POS, make sure to pop the iterator because it will be in
3009 front of that overlay string. When POS is ZV, we've thereby
3010 also ``processed'' overlay strings at ZV. */
3013 xassert (it
->current
.overlay_string_index
== -1);
3014 xassert (it
->method
== GET_FROM_BUFFER
);
3015 if (CHARPOS (pos
->pos
) == ZV
)
3016 it
->overlay_strings_at_end_processed_p
= 1;
3020 if (CHARPOS (pos
->string_pos
) >= 0)
3022 /* Recorded position is not in an overlay string, but in another
3023 string. This can only be a string from a `display' property.
3024 IT should already be filled with that string. */
3025 it
->current
.string_pos
= pos
->string_pos
;
3026 xassert (STRINGP (it
->string
));
3029 /* Restore position in display vector translations, control
3030 character translations or ellipses. */
3031 if (pos
->dpvec_index
>= 0)
3033 if (it
->dpvec
== NULL
)
3034 get_next_display_element (it
);
3035 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3036 it
->current
.dpvec_index
= pos
->dpvec_index
;
3040 return !overlay_strings_with_newlines
;
3044 /* Initialize IT for stepping through current_buffer in window W
3045 starting at ROW->start. */
3048 init_to_row_start (it
, w
, row
)
3051 struct glyph_row
*row
;
3053 init_from_display_pos (it
, w
, &row
->start
);
3054 it
->start
= row
->start
;
3055 it
->continuation_lines_width
= row
->continuation_lines_width
;
3060 /* Initialize IT for stepping through current_buffer in window W
3061 starting in the line following ROW, i.e. starting at ROW->end.
3062 Value is zero if there are overlay strings with newlines at ROW's
3066 init_to_row_end (it
, w
, row
)
3069 struct glyph_row
*row
;
3073 if (init_from_display_pos (it
, w
, &row
->end
))
3075 if (row
->continued_p
)
3076 it
->continuation_lines_width
3077 = row
->continuation_lines_width
+ row
->pixel_width
;
3088 /***********************************************************************
3090 ***********************************************************************/
3092 /* Called when IT reaches IT->stop_charpos. Handle text property and
3093 overlay changes. Set IT->stop_charpos to the next position where
3100 enum prop_handled handled
;
3101 int handle_overlay_change_p
;
3105 it
->current
.dpvec_index
= -1;
3106 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3107 it
->ignore_overlay_strings_at_pos_p
= 0;
3110 /* Use face of preceding text for ellipsis (if invisible) */
3111 if (it
->selective_display_ellipsis_p
)
3112 it
->saved_face_id
= it
->face_id
;
3116 handled
= HANDLED_NORMALLY
;
3118 /* Call text property handlers. */
3119 for (p
= it_props
; p
->handler
; ++p
)
3121 handled
= p
->handler (it
);
3123 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3125 else if (handled
== HANDLED_RETURN
)
3127 /* We still want to show before and after strings from
3128 overlays even if the actual buffer text is replaced. */
3129 if (!handle_overlay_change_p
3131 || !get_overlay_strings_1 (it
, 0, 0))
3134 setup_for_ellipsis (it
, 0);
3137 it
->ignore_overlay_strings_at_pos_p
= 1;
3138 it
->string_from_display_prop_p
= 0;
3139 handle_overlay_change_p
= 0;
3140 handled
= HANDLED_RECOMPUTE_PROPS
;
3143 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3144 handle_overlay_change_p
= 0;
3147 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3149 /* Don't check for overlay strings below when set to deliver
3150 characters from a display vector. */
3151 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3152 handle_overlay_change_p
= 0;
3154 /* Handle overlay changes.
3155 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3156 if it finds overlays. */
3157 if (handle_overlay_change_p
)
3158 handled
= handle_overlay_change (it
);
3163 setup_for_ellipsis (it
, 0);
3167 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3169 /* Determine where to stop next. */
3170 if (handled
== HANDLED_NORMALLY
)
3171 compute_stop_pos (it
);
3175 /* Compute IT->stop_charpos from text property and overlay change
3176 information for IT's current position. */
3179 compute_stop_pos (it
)
3182 register INTERVAL iv
, next_iv
;
3183 Lisp_Object object
, limit
, position
;
3185 /* If nowhere else, stop at the end. */
3186 it
->stop_charpos
= it
->end_charpos
;
3188 if (STRINGP (it
->string
))
3190 /* Strings are usually short, so don't limit the search for
3192 object
= it
->string
;
3194 position
= make_number (IT_STRING_CHARPOS (*it
));
3200 /* If next overlay change is in front of the current stop pos
3201 (which is IT->end_charpos), stop there. Note: value of
3202 next_overlay_change is point-max if no overlay change
3204 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3205 if (charpos
< it
->stop_charpos
)
3206 it
->stop_charpos
= charpos
;
3208 /* If showing the region, we have to stop at the region
3209 start or end because the face might change there. */
3210 if (it
->region_beg_charpos
> 0)
3212 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3213 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3214 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3215 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3218 /* Set up variables for computing the stop position from text
3219 property changes. */
3220 XSETBUFFER (object
, current_buffer
);
3221 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3222 position
= make_number (IT_CHARPOS (*it
));
3226 /* Get the interval containing IT's position. Value is a null
3227 interval if there isn't such an interval. */
3228 iv
= validate_interval_range (object
, &position
, &position
, 0);
3229 if (!NULL_INTERVAL_P (iv
))
3231 Lisp_Object values_here
[LAST_PROP_IDX
];
3234 /* Get properties here. */
3235 for (p
= it_props
; p
->handler
; ++p
)
3236 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3238 /* Look for an interval following iv that has different
3240 for (next_iv
= next_interval (iv
);
3241 (!NULL_INTERVAL_P (next_iv
)
3243 || XFASTINT (limit
) > next_iv
->position
));
3244 next_iv
= next_interval (next_iv
))
3246 for (p
= it_props
; p
->handler
; ++p
)
3248 Lisp_Object new_value
;
3250 new_value
= textget (next_iv
->plist
, *p
->name
);
3251 if (!EQ (values_here
[p
->idx
], new_value
))
3259 if (!NULL_INTERVAL_P (next_iv
))
3261 if (INTEGERP (limit
)
3262 && next_iv
->position
>= XFASTINT (limit
))
3263 /* No text property change up to limit. */
3264 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3266 /* Text properties change in next_iv. */
3267 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3271 xassert (STRINGP (it
->string
)
3272 || (it
->stop_charpos
>= BEGV
3273 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3277 /* Return the position of the next overlay change after POS in
3278 current_buffer. Value is point-max if no overlay change
3279 follows. This is like `next-overlay-change' but doesn't use
3283 next_overlay_change (pos
)
3288 Lisp_Object
*overlays
;
3291 /* Get all overlays at the given position. */
3292 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3294 /* If any of these overlays ends before endpos,
3295 use its ending point instead. */
3296 for (i
= 0; i
< noverlays
; ++i
)
3301 oend
= OVERLAY_END (overlays
[i
]);
3302 oendpos
= OVERLAY_POSITION (oend
);
3303 endpos
= min (endpos
, oendpos
);
3311 /***********************************************************************
3313 ***********************************************************************/
3315 /* Handle changes in the `fontified' property of the current buffer by
3316 calling hook functions from Qfontification_functions to fontify
3319 static enum prop_handled
3320 handle_fontified_prop (it
)
3323 Lisp_Object prop
, pos
;
3324 enum prop_handled handled
= HANDLED_NORMALLY
;
3326 if (!NILP (Vmemory_full
))
3329 /* Get the value of the `fontified' property at IT's current buffer
3330 position. (The `fontified' property doesn't have a special
3331 meaning in strings.) If the value is nil, call functions from
3332 Qfontification_functions. */
3333 if (!STRINGP (it
->string
)
3335 && !NILP (Vfontification_functions
)
3336 && !NILP (Vrun_hooks
)
3337 && (pos
= make_number (IT_CHARPOS (*it
)),
3338 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3339 /* Ignore the special cased nil value always present at EOB since
3340 no amount of fontifying will be able to change it. */
3341 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3343 int count
= SPECPDL_INDEX ();
3346 val
= Vfontification_functions
;
3347 specbind (Qfontification_functions
, Qnil
);
3349 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3350 safe_call1 (val
, pos
);
3353 Lisp_Object globals
, fn
;
3354 struct gcpro gcpro1
, gcpro2
;
3357 GCPRO2 (val
, globals
);
3359 for (; CONSP (val
); val
= XCDR (val
))
3365 /* A value of t indicates this hook has a local
3366 binding; it means to run the global binding too.
3367 In a global value, t should not occur. If it
3368 does, we must ignore it to avoid an endless
3370 for (globals
= Fdefault_value (Qfontification_functions
);
3372 globals
= XCDR (globals
))
3374 fn
= XCAR (globals
);
3376 safe_call1 (fn
, pos
);
3380 safe_call1 (fn
, pos
);
3386 unbind_to (count
, Qnil
);
3388 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3389 something. This avoids an endless loop if they failed to
3390 fontify the text for which reason ever. */
3391 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3392 handled
= HANDLED_RECOMPUTE_PROPS
;
3400 /***********************************************************************
3402 ***********************************************************************/
3404 /* Set up iterator IT from face properties at its current position.
3405 Called from handle_stop. */
3407 static enum prop_handled
3408 handle_face_prop (it
)
3412 EMACS_INT next_stop
;
3414 if (!STRINGP (it
->string
))
3417 = face_at_buffer_position (it
->w
,
3419 it
->region_beg_charpos
,
3420 it
->region_end_charpos
,
3423 + TEXT_PROP_DISTANCE_LIMIT
),
3426 /* Is this a start of a run of characters with box face?
3427 Caveat: this can be called for a freshly initialized
3428 iterator; face_id is -1 in this case. We know that the new
3429 face will not change until limit, i.e. if the new face has a
3430 box, all characters up to limit will have one. But, as
3431 usual, we don't know whether limit is really the end. */
3432 if (new_face_id
!= it
->face_id
)
3434 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3436 /* If new face has a box but old face has not, this is
3437 the start of a run of characters with box, i.e. it has
3438 a shadow on the left side. The value of face_id of the
3439 iterator will be -1 if this is the initial call that gets
3440 the face. In this case, we have to look in front of IT's
3441 position and see whether there is a face != new_face_id. */
3442 it
->start_of_box_run_p
3443 = (new_face
->box
!= FACE_NO_BOX
3444 && (it
->face_id
>= 0
3445 || IT_CHARPOS (*it
) == BEG
3446 || new_face_id
!= face_before_it_pos (it
)));
3447 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3452 int base_face_id
, bufpos
;
3454 Lisp_Object from_overlay
3455 = (it
->current
.overlay_string_index
>= 0
3456 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3459 /* See if we got to this string directly or indirectly from
3460 an overlay property. That includes the before-string or
3461 after-string of an overlay, strings in display properties
3462 provided by an overlay, their text properties, etc.
3464 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3465 if (! NILP (from_overlay
))
3466 for (i
= it
->sp
- 1; i
>= 0; i
--)
3468 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3470 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3471 else if (! NILP (it
->stack
[i
].from_overlay
))
3472 from_overlay
= it
->stack
[i
].from_overlay
;
3474 if (!NILP (from_overlay
))
3478 if (! NILP (from_overlay
))
3480 bufpos
= IT_CHARPOS (*it
);
3481 /* For a string from an overlay, the base face depends
3482 only on text properties and ignores overlays. */
3484 = face_for_overlay_string (it
->w
,
3486 it
->region_beg_charpos
,
3487 it
->region_end_charpos
,
3490 + TEXT_PROP_DISTANCE_LIMIT
),
3498 /* For strings from a `display' property, use the face at
3499 IT's current buffer position as the base face to merge
3500 with, so that overlay strings appear in the same face as
3501 surrounding text, unless they specify their own
3503 base_face_id
= underlying_face_id (it
);
3506 new_face_id
= face_at_string_position (it
->w
,
3508 IT_STRING_CHARPOS (*it
),
3510 it
->region_beg_charpos
,
3511 it
->region_end_charpos
,
3515 #if 0 /* This shouldn't be neccessary. Let's check it. */
3516 /* If IT is used to display a mode line we would really like to
3517 use the mode line face instead of the frame's default face. */
3518 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3519 && new_face_id
== DEFAULT_FACE_ID
)
3520 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3523 /* Is this a start of a run of characters with box? Caveat:
3524 this can be called for a freshly allocated iterator; face_id
3525 is -1 is this case. We know that the new face will not
3526 change until the next check pos, i.e. if the new face has a
3527 box, all characters up to that position will have a
3528 box. But, as usual, we don't know whether that position
3529 is really the end. */
3530 if (new_face_id
!= it
->face_id
)
3532 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3533 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3535 /* If new face has a box but old face hasn't, this is the
3536 start of a run of characters with box, i.e. it has a
3537 shadow on the left side. */
3538 it
->start_of_box_run_p
3539 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3540 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3544 it
->face_id
= new_face_id
;
3545 return HANDLED_NORMALLY
;
3549 /* Return the ID of the face ``underlying'' IT's current position,
3550 which is in a string. If the iterator is associated with a
3551 buffer, return the face at IT's current buffer position.
3552 Otherwise, use the iterator's base_face_id. */
3555 underlying_face_id (it
)
3558 int face_id
= it
->base_face_id
, i
;
3560 xassert (STRINGP (it
->string
));
3562 for (i
= it
->sp
- 1; i
>= 0; --i
)
3563 if (NILP (it
->stack
[i
].string
))
3564 face_id
= it
->stack
[i
].face_id
;
3570 /* Compute the face one character before or after the current position
3571 of IT. BEFORE_P non-zero means get the face in front of IT's
3572 position. Value is the id of the face. */
3575 face_before_or_after_it_pos (it
, before_p
)
3580 EMACS_INT next_check_charpos
;
3581 struct text_pos pos
;
3583 xassert (it
->s
== NULL
);
3585 if (STRINGP (it
->string
))
3587 int bufpos
, base_face_id
;
3589 /* No face change past the end of the string (for the case
3590 we are padding with spaces). No face change before the
3592 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3593 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3596 /* Set pos to the position before or after IT's current position. */
3598 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3600 /* For composition, we must check the character after the
3602 pos
= (it
->what
== IT_COMPOSITION
3603 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3604 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3606 if (it
->current
.overlay_string_index
>= 0)
3607 bufpos
= IT_CHARPOS (*it
);
3611 base_face_id
= underlying_face_id (it
);
3613 /* Get the face for ASCII, or unibyte. */
3614 face_id
= face_at_string_position (it
->w
,
3618 it
->region_beg_charpos
,
3619 it
->region_end_charpos
,
3620 &next_check_charpos
,
3623 /* Correct the face for charsets different from ASCII. Do it
3624 for the multibyte case only. The face returned above is
3625 suitable for unibyte text if IT->string is unibyte. */
3626 if (STRING_MULTIBYTE (it
->string
))
3628 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3629 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3631 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3633 c
= string_char_and_length (p
, rest
, &len
);
3634 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3639 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3640 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3643 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3644 pos
= it
->current
.pos
;
3647 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3650 if (it
->what
== IT_COMPOSITION
)
3651 /* For composition, we must check the position after the
3653 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3655 INC_TEXT_POS (pos
, it
->multibyte_p
);
3658 /* Determine face for CHARSET_ASCII, or unibyte. */
3659 face_id
= face_at_buffer_position (it
->w
,
3661 it
->region_beg_charpos
,
3662 it
->region_end_charpos
,
3663 &next_check_charpos
,
3666 /* Correct the face for charsets different from ASCII. Do it
3667 for the multibyte case only. The face returned above is
3668 suitable for unibyte text if current_buffer is unibyte. */
3669 if (it
->multibyte_p
)
3671 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3672 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3673 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3682 /***********************************************************************
3684 ***********************************************************************/
3686 /* Set up iterator IT from invisible properties at its current
3687 position. Called from handle_stop. */
3689 static enum prop_handled
3690 handle_invisible_prop (it
)
3693 enum prop_handled handled
= HANDLED_NORMALLY
;
3695 if (STRINGP (it
->string
))
3697 extern Lisp_Object Qinvisible
;
3698 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3700 /* Get the value of the invisible text property at the
3701 current position. Value will be nil if there is no such
3703 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3704 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3707 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3709 handled
= HANDLED_RECOMPUTE_PROPS
;
3711 /* Get the position at which the next change of the
3712 invisible text property can be found in IT->string.
3713 Value will be nil if the property value is the same for
3714 all the rest of IT->string. */
3715 XSETINT (limit
, SCHARS (it
->string
));
3716 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3719 /* Text at current position is invisible. The next
3720 change in the property is at position end_charpos.
3721 Move IT's current position to that position. */
3722 if (INTEGERP (end_charpos
)
3723 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3725 struct text_pos old
;
3726 old
= it
->current
.string_pos
;
3727 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3728 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3732 /* The rest of the string is invisible. If this is an
3733 overlay string, proceed with the next overlay string
3734 or whatever comes and return a character from there. */
3735 if (it
->current
.overlay_string_index
>= 0)
3737 next_overlay_string (it
);
3738 /* Don't check for overlay strings when we just
3739 finished processing them. */
3740 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3744 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3745 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3753 EMACS_INT newpos
, next_stop
, start_charpos
;
3754 Lisp_Object pos
, prop
, overlay
;
3756 /* First of all, is there invisible text at this position? */
3757 start_charpos
= IT_CHARPOS (*it
);
3758 pos
= make_number (IT_CHARPOS (*it
));
3759 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3761 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3763 /* If we are on invisible text, skip over it. */
3764 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3766 /* Record whether we have to display an ellipsis for the
3768 int display_ellipsis_p
= invis_p
== 2;
3770 handled
= HANDLED_RECOMPUTE_PROPS
;
3772 /* Loop skipping over invisible text. The loop is left at
3773 ZV or with IT on the first char being visible again. */
3776 /* Try to skip some invisible text. Return value is the
3777 position reached which can be equal to IT's position
3778 if there is nothing invisible here. This skips both
3779 over invisible text properties and overlays with
3780 invisible property. */
3781 newpos
= skip_invisible (IT_CHARPOS (*it
),
3782 &next_stop
, ZV
, it
->window
);
3784 /* If we skipped nothing at all we weren't at invisible
3785 text in the first place. If everything to the end of
3786 the buffer was skipped, end the loop. */
3787 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3791 /* We skipped some characters but not necessarily
3792 all there are. Check if we ended up on visible
3793 text. Fget_char_property returns the property of
3794 the char before the given position, i.e. if we
3795 get invis_p = 0, this means that the char at
3796 newpos is visible. */
3797 pos
= make_number (newpos
);
3798 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3799 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3802 /* If we ended up on invisible text, proceed to
3803 skip starting with next_stop. */
3805 IT_CHARPOS (*it
) = next_stop
;
3807 /* If there are adjacent invisible texts, don't lose the
3808 second one's ellipsis. */
3810 display_ellipsis_p
= 1;
3814 /* The position newpos is now either ZV or on visible text. */
3815 IT_CHARPOS (*it
) = newpos
;
3816 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3818 /* If there are before-strings at the start of invisible
3819 text, and the text is invisible because of a text
3820 property, arrange to show before-strings because 20.x did
3821 it that way. (If the text is invisible because of an
3822 overlay property instead of a text property, this is
3823 already handled in the overlay code.) */
3825 && get_overlay_strings (it
, start_charpos
))
3827 handled
= HANDLED_RECOMPUTE_PROPS
;
3828 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3830 else if (display_ellipsis_p
)
3832 /* Make sure that the glyphs of the ellipsis will get
3833 correct `charpos' values. If we would not update
3834 it->position here, the glyphs would belong to the
3835 last visible character _before_ the invisible
3836 text, which confuses `set_cursor_from_row'.
3838 We use the last invisible position instead of the
3839 first because this way the cursor is always drawn on
3840 the first "." of the ellipsis, whenever PT is inside
3841 the invisible text. Otherwise the cursor would be
3842 placed _after_ the ellipsis when the point is after the
3843 first invisible character. */
3844 if (!STRINGP (it
->object
))
3846 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3847 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3850 /* Let the ellipsis display before
3851 considering any properties of the following char.
3852 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3853 handled
= HANDLED_RETURN
;
3862 /* Make iterator IT return `...' next.
3863 Replaces LEN characters from buffer. */
3866 setup_for_ellipsis (it
, len
)
3870 /* Use the display table definition for `...'. Invalid glyphs
3871 will be handled by the method returning elements from dpvec. */
3872 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3874 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3875 it
->dpvec
= v
->contents
;
3876 it
->dpend
= v
->contents
+ v
->size
;
3880 /* Default `...'. */
3881 it
->dpvec
= default_invis_vector
;
3882 it
->dpend
= default_invis_vector
+ 3;
3885 it
->dpvec_char_len
= len
;
3886 it
->current
.dpvec_index
= 0;
3887 it
->dpvec_face_id
= -1;
3889 /* Remember the current face id in case glyphs specify faces.
3890 IT's face is restored in set_iterator_to_next.
3891 saved_face_id was set to preceding char's face in handle_stop. */
3892 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3893 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3895 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3901 /***********************************************************************
3903 ***********************************************************************/
3905 /* Set up iterator IT from `display' property at its current position.
3906 Called from handle_stop.
3907 We return HANDLED_RETURN if some part of the display property
3908 overrides the display of the buffer text itself.
3909 Otherwise we return HANDLED_NORMALLY. */
3911 static enum prop_handled
3912 handle_display_prop (it
)
3915 Lisp_Object prop
, object
, overlay
;
3916 struct text_pos
*position
;
3917 /* Nonzero if some property replaces the display of the text itself. */
3918 int display_replaced_p
= 0;
3920 if (STRINGP (it
->string
))
3922 object
= it
->string
;
3923 position
= &it
->current
.string_pos
;
3927 XSETWINDOW (object
, it
->w
);
3928 position
= &it
->current
.pos
;
3931 /* Reset those iterator values set from display property values. */
3932 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3933 it
->space_width
= Qnil
;
3934 it
->font_height
= Qnil
;
3937 /* We don't support recursive `display' properties, i.e. string
3938 values that have a string `display' property, that have a string
3939 `display' property etc. */
3940 if (!it
->string_from_display_prop_p
)
3941 it
->area
= TEXT_AREA
;
3943 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3944 Qdisplay
, object
, &overlay
);
3946 return HANDLED_NORMALLY
;
3947 /* Now OVERLAY is the overlay that gave us this property, or nil
3948 if it was a text property. */
3950 if (!STRINGP (it
->string
))
3951 object
= it
->w
->buffer
;
3954 /* Simple properties. */
3955 && !EQ (XCAR (prop
), Qimage
)
3956 && !EQ (XCAR (prop
), Qspace
)
3957 && !EQ (XCAR (prop
), Qwhen
)
3958 && !EQ (XCAR (prop
), Qslice
)
3959 && !EQ (XCAR (prop
), Qspace_width
)
3960 && !EQ (XCAR (prop
), Qheight
)
3961 && !EQ (XCAR (prop
), Qraise
)
3962 /* Marginal area specifications. */
3963 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3964 && !EQ (XCAR (prop
), Qleft_fringe
)
3965 && !EQ (XCAR (prop
), Qright_fringe
)
3966 && !NILP (XCAR (prop
)))
3968 for (; CONSP (prop
); prop
= XCDR (prop
))
3970 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3971 position
, display_replaced_p
))
3973 display_replaced_p
= 1;
3974 /* If some text in a string is replaced, `position' no
3975 longer points to the position of `object'. */
3976 if (STRINGP (object
))
3981 else if (VECTORP (prop
))
3984 for (i
= 0; i
< ASIZE (prop
); ++i
)
3985 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3986 position
, display_replaced_p
))
3988 display_replaced_p
= 1;
3989 /* If some text in a string is replaced, `position' no
3990 longer points to the position of `object'. */
3991 if (STRINGP (object
))
3997 int ret
= handle_single_display_spec (it
, prop
, object
, overlay
,
3999 if (ret
< 0) /* Replaced by "", i.e. nothing. */
4000 return HANDLED_RECOMPUTE_PROPS
;
4002 display_replaced_p
= 1;
4005 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4009 /* Value is the position of the end of the `display' property starting
4010 at START_POS in OBJECT. */
4012 static struct text_pos
4013 display_prop_end (it
, object
, start_pos
)
4016 struct text_pos start_pos
;
4019 struct text_pos end_pos
;
4021 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4022 Qdisplay
, object
, Qnil
);
4023 CHARPOS (end_pos
) = XFASTINT (end
);
4024 if (STRINGP (object
))
4025 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4027 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4033 /* Set up IT from a single `display' specification PROP. OBJECT
4034 is the object in which the `display' property was found. *POSITION
4035 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4036 means that we previously saw a display specification which already
4037 replaced text display with something else, for example an image;
4038 we ignore such properties after the first one has been processed.
4040 OVERLAY is the overlay this `display' property came from,
4041 or nil if it was a text property.
4043 If PROP is a `space' or `image' specification, and in some other
4044 cases too, set *POSITION to the position where the `display'
4047 Value is non-zero if something was found which replaces the display
4048 of buffer or string text. Specifically, the value is -1 if that
4049 "something" is "nothing". */
4052 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4053 display_replaced_before_p
)
4057 Lisp_Object overlay
;
4058 struct text_pos
*position
;
4059 int display_replaced_before_p
;
4062 Lisp_Object location
, value
;
4063 struct text_pos start_pos
, save_pos
;
4066 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4067 If the result is non-nil, use VALUE instead of SPEC. */
4069 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4078 if (!NILP (form
) && !EQ (form
, Qt
))
4080 int count
= SPECPDL_INDEX ();
4081 struct gcpro gcpro1
;
4083 /* Bind `object' to the object having the `display' property, a
4084 buffer or string. Bind `position' to the position in the
4085 object where the property was found, and `buffer-position'
4086 to the current position in the buffer. */
4087 specbind (Qobject
, object
);
4088 specbind (Qposition
, make_number (CHARPOS (*position
)));
4089 specbind (Qbuffer_position
,
4090 make_number (STRINGP (object
)
4091 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4093 form
= safe_eval (form
);
4095 unbind_to (count
, Qnil
);
4101 /* Handle `(height HEIGHT)' specifications. */
4103 && EQ (XCAR (spec
), Qheight
)
4104 && CONSP (XCDR (spec
)))
4106 if (!FRAME_WINDOW_P (it
->f
))
4109 it
->font_height
= XCAR (XCDR (spec
));
4110 if (!NILP (it
->font_height
))
4112 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4113 int new_height
= -1;
4115 if (CONSP (it
->font_height
)
4116 && (EQ (XCAR (it
->font_height
), Qplus
)
4117 || EQ (XCAR (it
->font_height
), Qminus
))
4118 && CONSP (XCDR (it
->font_height
))
4119 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4121 /* `(+ N)' or `(- N)' where N is an integer. */
4122 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4123 if (EQ (XCAR (it
->font_height
), Qplus
))
4125 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4127 else if (FUNCTIONP (it
->font_height
))
4129 /* Call function with current height as argument.
4130 Value is the new height. */
4132 height
= safe_call1 (it
->font_height
,
4133 face
->lface
[LFACE_HEIGHT_INDEX
]);
4134 if (NUMBERP (height
))
4135 new_height
= XFLOATINT (height
);
4137 else if (NUMBERP (it
->font_height
))
4139 /* Value is a multiple of the canonical char height. */
4142 face
= FACE_FROM_ID (it
->f
,
4143 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4144 new_height
= (XFLOATINT (it
->font_height
)
4145 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4149 /* Evaluate IT->font_height with `height' bound to the
4150 current specified height to get the new height. */
4151 int count
= SPECPDL_INDEX ();
4153 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4154 value
= safe_eval (it
->font_height
);
4155 unbind_to (count
, Qnil
);
4157 if (NUMBERP (value
))
4158 new_height
= XFLOATINT (value
);
4162 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4168 /* Handle `(space-width WIDTH)'. */
4170 && EQ (XCAR (spec
), Qspace_width
)
4171 && CONSP (XCDR (spec
)))
4173 if (!FRAME_WINDOW_P (it
->f
))
4176 value
= XCAR (XCDR (spec
));
4177 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4178 it
->space_width
= value
;
4183 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4185 && EQ (XCAR (spec
), Qslice
))
4189 if (!FRAME_WINDOW_P (it
->f
))
4192 if (tem
= XCDR (spec
), CONSP (tem
))
4194 it
->slice
.x
= XCAR (tem
);
4195 if (tem
= XCDR (tem
), CONSP (tem
))
4197 it
->slice
.y
= XCAR (tem
);
4198 if (tem
= XCDR (tem
), CONSP (tem
))
4200 it
->slice
.width
= XCAR (tem
);
4201 if (tem
= XCDR (tem
), CONSP (tem
))
4202 it
->slice
.height
= XCAR (tem
);
4210 /* Handle `(raise FACTOR)'. */
4212 && EQ (XCAR (spec
), Qraise
)
4213 && CONSP (XCDR (spec
)))
4215 if (!FRAME_WINDOW_P (it
->f
))
4218 #ifdef HAVE_WINDOW_SYSTEM
4219 value
= XCAR (XCDR (spec
));
4220 if (NUMBERP (value
))
4222 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4223 it
->voffset
= - (XFLOATINT (value
)
4224 * (FONT_HEIGHT (face
->font
)));
4226 #endif /* HAVE_WINDOW_SYSTEM */
4231 /* Don't handle the other kinds of display specifications
4232 inside a string that we got from a `display' property. */
4233 if (it
->string_from_display_prop_p
)
4236 /* Characters having this form of property are not displayed, so
4237 we have to find the end of the property. */
4238 start_pos
= *position
;
4239 *position
= display_prop_end (it
, object
, start_pos
);
4242 /* Stop the scan at that end position--we assume that all
4243 text properties change there. */
4244 it
->stop_charpos
= position
->charpos
;
4246 /* Handle `(left-fringe BITMAP [FACE])'
4247 and `(right-fringe BITMAP [FACE])'. */
4249 && (EQ (XCAR (spec
), Qleft_fringe
)
4250 || EQ (XCAR (spec
), Qright_fringe
))
4251 && CONSP (XCDR (spec
)))
4253 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4256 if (!FRAME_WINDOW_P (it
->f
))
4257 /* If we return here, POSITION has been advanced
4258 across the text with this property. */
4261 #ifdef HAVE_WINDOW_SYSTEM
4262 value
= XCAR (XCDR (spec
));
4263 if (!SYMBOLP (value
)
4264 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4265 /* If we return here, POSITION has been advanced
4266 across the text with this property. */
4269 if (CONSP (XCDR (XCDR (spec
))))
4271 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4272 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4278 /* Save current settings of IT so that we can restore them
4279 when we are finished with the glyph property value. */
4281 save_pos
= it
->position
;
4282 it
->position
= *position
;
4284 it
->position
= save_pos
;
4286 it
->area
= TEXT_AREA
;
4287 it
->what
= IT_IMAGE
;
4288 it
->image_id
= -1; /* no image */
4289 it
->position
= start_pos
;
4290 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4291 it
->method
= GET_FROM_IMAGE
;
4292 it
->from_overlay
= Qnil
;
4293 it
->face_id
= face_id
;
4295 /* Say that we haven't consumed the characters with
4296 `display' property yet. The call to pop_it in
4297 set_iterator_to_next will clean this up. */
4298 *position
= start_pos
;
4300 if (EQ (XCAR (spec
), Qleft_fringe
))
4302 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4303 it
->left_user_fringe_face_id
= face_id
;
4307 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4308 it
->right_user_fringe_face_id
= face_id
;
4310 #endif /* HAVE_WINDOW_SYSTEM */
4314 /* Prepare to handle `((margin left-margin) ...)',
4315 `((margin right-margin) ...)' and `((margin nil) ...)'
4316 prefixes for display specifications. */
4317 location
= Qunbound
;
4318 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4322 value
= XCDR (spec
);
4324 value
= XCAR (value
);
4327 if (EQ (XCAR (tem
), Qmargin
)
4328 && (tem
= XCDR (tem
),
4329 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4331 || EQ (tem
, Qleft_margin
)
4332 || EQ (tem
, Qright_margin
))))
4336 if (EQ (location
, Qunbound
))
4342 /* After this point, VALUE is the property after any
4343 margin prefix has been stripped. It must be a string,
4344 an image specification, or `(space ...)'.
4346 LOCATION specifies where to display: `left-margin',
4347 `right-margin' or nil. */
4349 valid_p
= (STRINGP (value
)
4350 #ifdef HAVE_WINDOW_SYSTEM
4351 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4352 #endif /* not HAVE_WINDOW_SYSTEM */
4353 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4355 if (valid_p
&& !display_replaced_before_p
)
4357 /* Save current settings of IT so that we can restore them
4358 when we are finished with the glyph property value. */
4359 save_pos
= it
->position
;
4360 it
->position
= *position
;
4362 it
->position
= save_pos
;
4363 it
->from_overlay
= overlay
;
4365 if (NILP (location
))
4366 it
->area
= TEXT_AREA
;
4367 else if (EQ (location
, Qleft_margin
))
4368 it
->area
= LEFT_MARGIN_AREA
;
4370 it
->area
= RIGHT_MARGIN_AREA
;
4372 if (STRINGP (value
))
4374 if (SCHARS (value
) == 0)
4377 return -1; /* Replaced by "", i.e. nothing. */
4380 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4381 it
->current
.overlay_string_index
= -1;
4382 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4383 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4384 it
->method
= GET_FROM_STRING
;
4385 it
->stop_charpos
= 0;
4386 it
->string_from_display_prop_p
= 1;
4387 /* Say that we haven't consumed the characters with
4388 `display' property yet. The call to pop_it in
4389 set_iterator_to_next will clean this up. */
4390 if (BUFFERP (object
))
4391 *position
= start_pos
;
4393 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4395 it
->method
= GET_FROM_STRETCH
;
4397 *position
= it
->position
= start_pos
;
4399 #ifdef HAVE_WINDOW_SYSTEM
4402 it
->what
= IT_IMAGE
;
4403 it
->image_id
= lookup_image (it
->f
, value
);
4404 it
->position
= start_pos
;
4405 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4406 it
->method
= GET_FROM_IMAGE
;
4408 /* Say that we haven't consumed the characters with
4409 `display' property yet. The call to pop_it in
4410 set_iterator_to_next will clean this up. */
4411 *position
= start_pos
;
4413 #endif /* HAVE_WINDOW_SYSTEM */
4418 /* Invalid property or property not supported. Restore
4419 POSITION to what it was before. */
4420 *position
= start_pos
;
4425 /* Check if SPEC is a display sub-property value whose text should be
4426 treated as intangible. */
4429 single_display_spec_intangible_p (prop
)
4432 /* Skip over `when FORM'. */
4433 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4447 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4448 we don't need to treat text as intangible. */
4449 if (EQ (XCAR (prop
), Qmargin
))
4457 || EQ (XCAR (prop
), Qleft_margin
)
4458 || EQ (XCAR (prop
), Qright_margin
))
4462 return (CONSP (prop
)
4463 && (EQ (XCAR (prop
), Qimage
)
4464 || EQ (XCAR (prop
), Qspace
)));
4468 /* Check if PROP is a display property value whose text should be
4469 treated as intangible. */
4472 display_prop_intangible_p (prop
)
4476 && CONSP (XCAR (prop
))
4477 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4479 /* A list of sub-properties. */
4480 while (CONSP (prop
))
4482 if (single_display_spec_intangible_p (XCAR (prop
)))
4487 else if (VECTORP (prop
))
4489 /* A vector of sub-properties. */
4491 for (i
= 0; i
< ASIZE (prop
); ++i
)
4492 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4496 return single_display_spec_intangible_p (prop
);
4502 /* Return 1 if PROP is a display sub-property value containing STRING. */
4505 single_display_spec_string_p (prop
, string
)
4506 Lisp_Object prop
, string
;
4508 if (EQ (string
, prop
))
4511 /* Skip over `when FORM'. */
4512 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4521 /* Skip over `margin LOCATION'. */
4522 if (EQ (XCAR (prop
), Qmargin
))
4533 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4537 /* Return 1 if STRING appears in the `display' property PROP. */
4540 display_prop_string_p (prop
, string
)
4541 Lisp_Object prop
, string
;
4544 && CONSP (XCAR (prop
))
4545 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4547 /* A list of sub-properties. */
4548 while (CONSP (prop
))
4550 if (single_display_spec_string_p (XCAR (prop
), string
))
4555 else if (VECTORP (prop
))
4557 /* A vector of sub-properties. */
4559 for (i
= 0; i
< ASIZE (prop
); ++i
)
4560 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4564 return single_display_spec_string_p (prop
, string
);
4570 /* Determine from which buffer position in W's buffer STRING comes
4571 from. AROUND_CHARPOS is an approximate position where it could
4572 be from. Value is the buffer position or 0 if it couldn't be
4575 W's buffer must be current.
4577 This function is necessary because we don't record buffer positions
4578 in glyphs generated from strings (to keep struct glyph small).
4579 This function may only use code that doesn't eval because it is
4580 called asynchronously from note_mouse_highlight. */
4583 string_buffer_position (w
, string
, around_charpos
)
4588 Lisp_Object limit
, prop
, pos
;
4589 const int MAX_DISTANCE
= 1000;
4592 pos
= make_number (around_charpos
);
4593 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4594 while (!found
&& !EQ (pos
, limit
))
4596 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4597 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4600 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4605 pos
= make_number (around_charpos
);
4606 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4607 while (!found
&& !EQ (pos
, limit
))
4609 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4610 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4613 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4618 return found
? XINT (pos
) : 0;
4623 /***********************************************************************
4624 `composition' property
4625 ***********************************************************************/
4627 static enum prop_handled
4628 handle_auto_composed_prop (it
)
4631 enum prop_handled handled
= HANDLED_NORMALLY
;
4633 if (FUNCTIONP (Vauto_composition_function
))
4635 Lisp_Object val
= Qnil
;
4636 EMACS_INT pos
, limit
= -1;
4638 if (STRINGP (it
->string
))
4639 pos
= IT_STRING_CHARPOS (*it
);
4641 pos
= IT_CHARPOS (*it
);
4643 val
= Fget_text_property (make_number (pos
), Qauto_composed
, it
->string
);
4646 Lisp_Object cmp_prop
;
4647 EMACS_INT cmp_start
, cmp_end
;
4649 if (get_property_and_range (pos
, Qcomposition
, &cmp_prop
,
4650 &cmp_start
, &cmp_end
, it
->string
)
4652 && COMPOSITION_METHOD (cmp_prop
) == COMPOSITION_WITH_GLYPH_STRING
)
4654 Lisp_Object gstring
= COMPOSITION_COMPONENTS (cmp_prop
);
4655 Lisp_Object font_object
= LGSTRING_FONT (gstring
);
4657 if (! EQ (font_object
,
4658 font_at (-1, pos
, FACE_FROM_ID (it
->f
, it
->face_id
),
4659 it
->w
, it
->string
)))
4660 /* We must re-compute the composition for the
4669 /* As Fnext_single_char_property_change is very slow, we
4670 limit the search to the current line. */
4671 if (STRINGP (it
->string
))
4672 limit
= SCHARS (it
->string
);
4674 limit
= find_next_newline_no_quit (pos
, 1);
4675 end
= Fnext_single_char_property_change (make_number (pos
),
4678 make_number (limit
));
4680 if (XINT (end
) < limit
)
4681 /* The current point is auto-composed, but there exist
4682 characters not yet composed beyond the
4683 auto-composed region. There's a possiblity that
4684 the last characters in the region may be newly
4689 if (NILP (val
) && ! STRINGP (it
->string
))
4692 limit
= (STRINGP (it
->string
) ? SCHARS (it
->string
)
4693 : find_next_newline_no_quit (pos
, 1));
4696 int count
= SPECPDL_INDEX ();
4697 Lisp_Object args
[5];
4699 if (FRAME_WINDOW_P (it
->f
))
4700 limit
= font_range (pos
, limit
,
4701 FACE_FROM_ID (it
->f
, it
->face_id
),
4703 args
[0] = Vauto_composition_function
;
4704 specbind (Qauto_composition_function
, Qnil
);
4705 args
[1] = make_number (pos
);
4706 args
[2] = make_number (limit
);
4707 args
[3] = it
->window
;
4708 args
[4] = it
->string
;
4709 safe_call (5, args
);
4710 unbind_to (count
, Qnil
);
4718 /* Set up iterator IT from `composition' property at its current
4719 position. Called from handle_stop. */
4721 static enum prop_handled
4722 handle_composition_prop (it
)
4725 Lisp_Object prop
, string
;
4726 EMACS_INT pos
, pos_byte
, start
, end
;
4727 enum prop_handled handled
= HANDLED_NORMALLY
;
4729 if (STRINGP (it
->string
))
4733 pos
= IT_STRING_CHARPOS (*it
);
4734 pos_byte
= IT_STRING_BYTEPOS (*it
);
4735 string
= it
->string
;
4736 s
= SDATA (string
) + pos_byte
;
4737 it
->c
= STRING_CHAR (s
, 0);
4741 pos
= IT_CHARPOS (*it
);
4742 pos_byte
= IT_BYTEPOS (*it
);
4744 it
->c
= FETCH_CHAR (pos_byte
);
4747 /* If there's a valid composition and point is not inside of the
4748 composition (in the case that the composition is from the current
4749 buffer), draw a glyph composed from the composition components. */
4750 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4751 && COMPOSITION_VALID_P (start
, end
, prop
)
4752 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4758 if (STRINGP (it
->string
))
4759 pos_byte
= string_char_to_byte (it
->string
, start
);
4761 pos_byte
= CHAR_TO_BYTE (start
);
4763 id
= get_composition_id (start
, pos_byte
, end
- start
, prop
, string
);
4767 struct composition
*cmp
= composition_table
[id
];
4769 if (cmp
->glyph_len
== 0)
4772 if (STRINGP (it
->string
))
4774 IT_STRING_CHARPOS (*it
) = end
;
4775 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4780 IT_CHARPOS (*it
) = end
;
4781 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4783 return HANDLED_RECOMPUTE_PROPS
;
4786 it
->stop_charpos
= end
;
4789 it
->method
= GET_FROM_COMPOSITION
;
4791 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4792 /* For a terminal, draw only the first (non-TAB) character
4793 of the components. */
4794 if (composition_table
[id
]->method
== COMPOSITION_WITH_GLYPH_STRING
)
4796 /* FIXME: This doesn't do anything!?! */
4797 Lisp_Object lgstring
= AREF (XHASH_TABLE (composition_hash_table
)
4799 cmp
->hash_index
* 2);
4805 for (i
= 0; i
< cmp
->glyph_len
; i
++)
4806 if ((it
->c
= COMPOSITION_GLYPH (composition_table
[id
], i
))
4812 it
->len
= (STRINGP (it
->string
)
4813 ? string_char_to_byte (it
->string
, end
)
4814 : CHAR_TO_BYTE (end
)) - pos_byte
;
4815 handled
= HANDLED_RETURN
;
4824 /***********************************************************************
4826 ***********************************************************************/
4828 /* The following structure is used to record overlay strings for
4829 later sorting in load_overlay_strings. */
4831 struct overlay_entry
4833 Lisp_Object overlay
;
4840 /* Set up iterator IT from overlay strings at its current position.
4841 Called from handle_stop. */
4843 static enum prop_handled
4844 handle_overlay_change (it
)
4847 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4848 return HANDLED_RECOMPUTE_PROPS
;
4850 return HANDLED_NORMALLY
;
4854 /* Set up the next overlay string for delivery by IT, if there is an
4855 overlay string to deliver. Called by set_iterator_to_next when the
4856 end of the current overlay string is reached. If there are more
4857 overlay strings to display, IT->string and
4858 IT->current.overlay_string_index are set appropriately here.
4859 Otherwise IT->string is set to nil. */
4862 next_overlay_string (it
)
4865 ++it
->current
.overlay_string_index
;
4866 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4868 /* No more overlay strings. Restore IT's settings to what
4869 they were before overlay strings were processed, and
4870 continue to deliver from current_buffer. */
4872 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4875 || it
->method
== GET_FROM_COMPOSITION
4876 || (NILP (it
->string
)
4877 && it
->method
== GET_FROM_BUFFER
4878 && it
->stop_charpos
>= BEGV
4879 && it
->stop_charpos
<= it
->end_charpos
));
4880 it
->current
.overlay_string_index
= -1;
4881 it
->n_overlay_strings
= 0;
4883 /* If we're at the end of the buffer, record that we have
4884 processed the overlay strings there already, so that
4885 next_element_from_buffer doesn't try it again. */
4886 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4887 it
->overlay_strings_at_end_processed_p
= 1;
4891 /* There are more overlay strings to process. If
4892 IT->current.overlay_string_index has advanced to a position
4893 where we must load IT->overlay_strings with more strings, do
4895 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4897 if (it
->current
.overlay_string_index
&& i
== 0)
4898 load_overlay_strings (it
, 0);
4900 /* Initialize IT to deliver display elements from the overlay
4902 it
->string
= it
->overlay_strings
[i
];
4903 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4904 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4905 it
->method
= GET_FROM_STRING
;
4906 it
->stop_charpos
= 0;
4913 /* Compare two overlay_entry structures E1 and E2. Used as a
4914 comparison function for qsort in load_overlay_strings. Overlay
4915 strings for the same position are sorted so that
4917 1. All after-strings come in front of before-strings, except
4918 when they come from the same overlay.
4920 2. Within after-strings, strings are sorted so that overlay strings
4921 from overlays with higher priorities come first.
4923 2. Within before-strings, strings are sorted so that overlay
4924 strings from overlays with higher priorities come last.
4926 Value is analogous to strcmp. */
4930 compare_overlay_entries (e1
, e2
)
4933 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4934 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4937 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4939 /* Let after-strings appear in front of before-strings if
4940 they come from different overlays. */
4941 if (EQ (entry1
->overlay
, entry2
->overlay
))
4942 result
= entry1
->after_string_p
? 1 : -1;
4944 result
= entry1
->after_string_p
? -1 : 1;
4946 else if (entry1
->after_string_p
)
4947 /* After-strings sorted in order of decreasing priority. */
4948 result
= entry2
->priority
- entry1
->priority
;
4950 /* Before-strings sorted in order of increasing priority. */
4951 result
= entry1
->priority
- entry2
->priority
;
4957 /* Load the vector IT->overlay_strings with overlay strings from IT's
4958 current buffer position, or from CHARPOS if that is > 0. Set
4959 IT->n_overlays to the total number of overlay strings found.
4961 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4962 a time. On entry into load_overlay_strings,
4963 IT->current.overlay_string_index gives the number of overlay
4964 strings that have already been loaded by previous calls to this
4967 IT->add_overlay_start contains an additional overlay start
4968 position to consider for taking overlay strings from, if non-zero.
4969 This position comes into play when the overlay has an `invisible'
4970 property, and both before and after-strings. When we've skipped to
4971 the end of the overlay, because of its `invisible' property, we
4972 nevertheless want its before-string to appear.
4973 IT->add_overlay_start will contain the overlay start position
4976 Overlay strings are sorted so that after-string strings come in
4977 front of before-string strings. Within before and after-strings,
4978 strings are sorted by overlay priority. See also function
4979 compare_overlay_entries. */
4982 load_overlay_strings (it
, charpos
)
4986 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4987 Lisp_Object overlay
, window
, str
, invisible
;
4988 struct Lisp_Overlay
*ov
;
4991 int n
= 0, i
, j
, invis_p
;
4992 struct overlay_entry
*entries
4993 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4996 charpos
= IT_CHARPOS (*it
);
4998 /* Append the overlay string STRING of overlay OVERLAY to vector
4999 `entries' which has size `size' and currently contains `n'
5000 elements. AFTER_P non-zero means STRING is an after-string of
5002 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5005 Lisp_Object priority; \
5009 int new_size = 2 * size; \
5010 struct overlay_entry *old = entries; \
5012 (struct overlay_entry *) alloca (new_size \
5013 * sizeof *entries); \
5014 bcopy (old, entries, size * sizeof *entries); \
5018 entries[n].string = (STRING); \
5019 entries[n].overlay = (OVERLAY); \
5020 priority = Foverlay_get ((OVERLAY), Qpriority); \
5021 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5022 entries[n].after_string_p = (AFTER_P); \
5027 /* Process overlay before the overlay center. */
5028 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5030 XSETMISC (overlay
, ov
);
5031 xassert (OVERLAYP (overlay
));
5032 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5033 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5038 /* Skip this overlay if it doesn't start or end at IT's current
5040 if (end
!= charpos
&& start
!= charpos
)
5043 /* Skip this overlay if it doesn't apply to IT->w. */
5044 window
= Foverlay_get (overlay
, Qwindow
);
5045 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5048 /* If the text ``under'' the overlay is invisible, both before-
5049 and after-strings from this overlay are visible; start and
5050 end position are indistinguishable. */
5051 invisible
= Foverlay_get (overlay
, Qinvisible
);
5052 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5054 /* If overlay has a non-empty before-string, record it. */
5055 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5056 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5058 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5060 /* If overlay has a non-empty after-string, record it. */
5061 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5062 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5064 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5067 /* Process overlays after the overlay center. */
5068 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5070 XSETMISC (overlay
, ov
);
5071 xassert (OVERLAYP (overlay
));
5072 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5073 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5075 if (start
> charpos
)
5078 /* Skip this overlay if it doesn't start or end at IT's current
5080 if (end
!= charpos
&& start
!= charpos
)
5083 /* Skip this overlay if it doesn't apply to IT->w. */
5084 window
= Foverlay_get (overlay
, Qwindow
);
5085 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5088 /* If the text ``under'' the overlay is invisible, it has a zero
5089 dimension, and both before- and after-strings apply. */
5090 invisible
= Foverlay_get (overlay
, Qinvisible
);
5091 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5093 /* If overlay has a non-empty before-string, record it. */
5094 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5095 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5097 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5099 /* If overlay has a non-empty after-string, record it. */
5100 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5101 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5103 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5106 #undef RECORD_OVERLAY_STRING
5110 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5112 /* Record the total number of strings to process. */
5113 it
->n_overlay_strings
= n
;
5115 /* IT->current.overlay_string_index is the number of overlay strings
5116 that have already been consumed by IT. Copy some of the
5117 remaining overlay strings to IT->overlay_strings. */
5119 j
= it
->current
.overlay_string_index
;
5120 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5122 it
->overlay_strings
[i
] = entries
[j
].string
;
5123 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5130 /* Get the first chunk of overlay strings at IT's current buffer
5131 position, or at CHARPOS if that is > 0. Value is non-zero if at
5132 least one overlay string was found. */
5135 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5140 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5141 process. This fills IT->overlay_strings with strings, and sets
5142 IT->n_overlay_strings to the total number of strings to process.
5143 IT->pos.overlay_string_index has to be set temporarily to zero
5144 because load_overlay_strings needs this; it must be set to -1
5145 when no overlay strings are found because a zero value would
5146 indicate a position in the first overlay string. */
5147 it
->current
.overlay_string_index
= 0;
5148 load_overlay_strings (it
, charpos
);
5150 /* If we found overlay strings, set up IT to deliver display
5151 elements from the first one. Otherwise set up IT to deliver
5152 from current_buffer. */
5153 if (it
->n_overlay_strings
)
5155 /* Make sure we know settings in current_buffer, so that we can
5156 restore meaningful values when we're done with the overlay
5159 compute_stop_pos (it
);
5160 xassert (it
->face_id
>= 0);
5162 /* Save IT's settings. They are restored after all overlay
5163 strings have been processed. */
5164 xassert (!compute_stop_p
|| it
->sp
== 0);
5167 /* Set up IT to deliver display elements from the first overlay
5169 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5170 it
->string
= it
->overlay_strings
[0];
5171 it
->from_overlay
= Qnil
;
5172 it
->stop_charpos
= 0;
5173 xassert (STRINGP (it
->string
));
5174 it
->end_charpos
= SCHARS (it
->string
);
5175 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5176 it
->method
= GET_FROM_STRING
;
5180 it
->current
.overlay_string_index
= -1;
5185 get_overlay_strings (it
, charpos
)
5190 it
->method
= GET_FROM_BUFFER
;
5192 (void) get_overlay_strings_1 (it
, charpos
, 1);
5196 /* Value is non-zero if we found at least one overlay string. */
5197 return STRINGP (it
->string
);
5202 /***********************************************************************
5203 Saving and restoring state
5204 ***********************************************************************/
5206 /* Save current settings of IT on IT->stack. Called, for example,
5207 before setting up IT for an overlay string, to be able to restore
5208 IT's settings to what they were after the overlay string has been
5215 struct iterator_stack_entry
*p
;
5217 xassert (it
->sp
< IT_STACK_SIZE
);
5218 p
= it
->stack
+ it
->sp
;
5220 p
->stop_charpos
= it
->stop_charpos
;
5221 xassert (it
->face_id
>= 0);
5222 p
->face_id
= it
->face_id
;
5223 p
->string
= it
->string
;
5224 p
->method
= it
->method
;
5225 p
->from_overlay
= it
->from_overlay
;
5228 case GET_FROM_IMAGE
:
5229 p
->u
.image
.object
= it
->object
;
5230 p
->u
.image
.image_id
= it
->image_id
;
5231 p
->u
.image
.slice
= it
->slice
;
5233 case GET_FROM_COMPOSITION
:
5234 p
->u
.comp
.object
= it
->object
;
5235 p
->u
.comp
.c
= it
->c
;
5236 p
->u
.comp
.len
= it
->len
;
5237 p
->u
.comp
.cmp_id
= it
->cmp_id
;
5238 p
->u
.comp
.cmp_len
= it
->cmp_len
;
5240 case GET_FROM_STRETCH
:
5241 p
->u
.stretch
.object
= it
->object
;
5244 p
->position
= it
->position
;
5245 p
->current
= it
->current
;
5246 p
->end_charpos
= it
->end_charpos
;
5247 p
->string_nchars
= it
->string_nchars
;
5249 p
->multibyte_p
= it
->multibyte_p
;
5250 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5251 p
->space_width
= it
->space_width
;
5252 p
->font_height
= it
->font_height
;
5253 p
->voffset
= it
->voffset
;
5254 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5255 p
->display_ellipsis_p
= 0;
5260 /* Restore IT's settings from IT->stack. Called, for example, when no
5261 more overlay strings must be processed, and we return to delivering
5262 display elements from a buffer, or when the end of a string from a
5263 `display' property is reached and we return to delivering display
5264 elements from an overlay string, or from a buffer. */
5270 struct iterator_stack_entry
*p
;
5272 xassert (it
->sp
> 0);
5274 p
= it
->stack
+ it
->sp
;
5275 it
->stop_charpos
= p
->stop_charpos
;
5276 it
->face_id
= p
->face_id
;
5277 it
->current
= p
->current
;
5278 it
->position
= p
->position
;
5279 it
->string
= p
->string
;
5280 it
->from_overlay
= p
->from_overlay
;
5281 if (NILP (it
->string
))
5282 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5283 it
->method
= p
->method
;
5286 case GET_FROM_IMAGE
:
5287 it
->image_id
= p
->u
.image
.image_id
;
5288 it
->object
= p
->u
.image
.object
;
5289 it
->slice
= p
->u
.image
.slice
;
5291 case GET_FROM_COMPOSITION
:
5292 it
->object
= p
->u
.comp
.object
;
5293 it
->c
= p
->u
.comp
.c
;
5294 it
->len
= p
->u
.comp
.len
;
5295 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5296 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5298 case GET_FROM_STRETCH
:
5299 it
->object
= p
->u
.comp
.object
;
5301 case GET_FROM_BUFFER
:
5302 it
->object
= it
->w
->buffer
;
5304 case GET_FROM_STRING
:
5305 it
->object
= it
->string
;
5308 it
->end_charpos
= p
->end_charpos
;
5309 it
->string_nchars
= p
->string_nchars
;
5311 it
->multibyte_p
= p
->multibyte_p
;
5312 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5313 it
->space_width
= p
->space_width
;
5314 it
->font_height
= p
->font_height
;
5315 it
->voffset
= p
->voffset
;
5316 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5321 /***********************************************************************
5323 ***********************************************************************/
5325 /* Set IT's current position to the previous line start. */
5328 back_to_previous_line_start (it
)
5331 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5332 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5336 /* Move IT to the next line start.
5338 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5339 we skipped over part of the text (as opposed to moving the iterator
5340 continuously over the text). Otherwise, don't change the value
5343 Newlines may come from buffer text, overlay strings, or strings
5344 displayed via the `display' property. That's the reason we can't
5345 simply use find_next_newline_no_quit.
5347 Note that this function may not skip over invisible text that is so
5348 because of text properties and immediately follows a newline. If
5349 it would, function reseat_at_next_visible_line_start, when called
5350 from set_iterator_to_next, would effectively make invisible
5351 characters following a newline part of the wrong glyph row, which
5352 leads to wrong cursor motion. */
5355 forward_to_next_line_start (it
, skipped_p
)
5359 int old_selective
, newline_found_p
, n
;
5360 const int MAX_NEWLINE_DISTANCE
= 500;
5362 /* If already on a newline, just consume it to avoid unintended
5363 skipping over invisible text below. */
5364 if (it
->what
== IT_CHARACTER
5366 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5368 set_iterator_to_next (it
, 0);
5373 /* Don't handle selective display in the following. It's (a)
5374 unnecessary because it's done by the caller, and (b) leads to an
5375 infinite recursion because next_element_from_ellipsis indirectly
5376 calls this function. */
5377 old_selective
= it
->selective
;
5380 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5381 from buffer text. */
5382 for (n
= newline_found_p
= 0;
5383 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5384 n
+= STRINGP (it
->string
) ? 0 : 1)
5386 if (!get_next_display_element (it
))
5388 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5389 set_iterator_to_next (it
, 0);
5392 /* If we didn't find a newline near enough, see if we can use a
5394 if (!newline_found_p
)
5396 int start
= IT_CHARPOS (*it
);
5397 int limit
= find_next_newline_no_quit (start
, 1);
5400 xassert (!STRINGP (it
->string
));
5402 /* If there isn't any `display' property in sight, and no
5403 overlays, we can just use the position of the newline in
5405 if (it
->stop_charpos
>= limit
5406 || ((pos
= Fnext_single_property_change (make_number (start
),
5408 Qnil
, make_number (limit
)),
5410 && next_overlay_change (start
) == ZV
))
5412 IT_CHARPOS (*it
) = limit
;
5413 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5414 *skipped_p
= newline_found_p
= 1;
5418 while (get_next_display_element (it
)
5419 && !newline_found_p
)
5421 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5422 set_iterator_to_next (it
, 0);
5427 it
->selective
= old_selective
;
5428 return newline_found_p
;
5432 /* Set IT's current position to the previous visible line start. Skip
5433 invisible text that is so either due to text properties or due to
5434 selective display. Caution: this does not change IT->current_x and
5438 back_to_previous_visible_line_start (it
)
5441 while (IT_CHARPOS (*it
) > BEGV
)
5443 back_to_previous_line_start (it
);
5445 if (IT_CHARPOS (*it
) <= BEGV
)
5448 /* If selective > 0, then lines indented more than that values
5450 if (it
->selective
> 0
5451 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5452 (double) it
->selective
)) /* iftc */
5455 /* Check the newline before point for invisibility. */
5458 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5459 Qinvisible
, it
->window
);
5460 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5464 if (IT_CHARPOS (*it
) <= BEGV
)
5471 Lisp_Object val
, overlay
;
5473 /* If newline is part of a composition, continue from start of composition */
5474 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5475 && beg
< IT_CHARPOS (*it
))
5478 /* If newline is replaced by a display property, find start of overlay
5479 or interval and continue search from that point. */
5481 pos
= --IT_CHARPOS (it2
);
5484 it2
.string_from_display_prop_p
= 0;
5485 if (handle_display_prop (&it2
) == HANDLED_RETURN
5486 && !NILP (val
= get_char_property_and_overlay
5487 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5488 && (OVERLAYP (overlay
)
5489 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5490 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5493 /* Newline is not replaced by anything -- so we are done. */
5499 IT_CHARPOS (*it
) = beg
;
5500 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5504 it
->continuation_lines_width
= 0;
5506 xassert (IT_CHARPOS (*it
) >= BEGV
);
5507 xassert (IT_CHARPOS (*it
) == BEGV
5508 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5513 /* Reseat iterator IT at the previous visible line start. Skip
5514 invisible text that is so either due to text properties or due to
5515 selective display. At the end, update IT's overlay information,
5516 face information etc. */
5519 reseat_at_previous_visible_line_start (it
)
5522 back_to_previous_visible_line_start (it
);
5523 reseat (it
, it
->current
.pos
, 1);
5528 /* Reseat iterator IT on the next visible line start in the current
5529 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5530 preceding the line start. Skip over invisible text that is so
5531 because of selective display. Compute faces, overlays etc at the
5532 new position. Note that this function does not skip over text that
5533 is invisible because of text properties. */
5536 reseat_at_next_visible_line_start (it
, on_newline_p
)
5540 int newline_found_p
, skipped_p
= 0;
5542 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5544 /* Skip over lines that are invisible because they are indented
5545 more than the value of IT->selective. */
5546 if (it
->selective
> 0)
5547 while (IT_CHARPOS (*it
) < ZV
5548 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5549 (double) it
->selective
)) /* iftc */
5551 xassert (IT_BYTEPOS (*it
) == BEGV
5552 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5553 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5556 /* Position on the newline if that's what's requested. */
5557 if (on_newline_p
&& newline_found_p
)
5559 if (STRINGP (it
->string
))
5561 if (IT_STRING_CHARPOS (*it
) > 0)
5563 --IT_STRING_CHARPOS (*it
);
5564 --IT_STRING_BYTEPOS (*it
);
5567 else if (IT_CHARPOS (*it
) > BEGV
)
5571 reseat (it
, it
->current
.pos
, 0);
5575 reseat (it
, it
->current
.pos
, 0);
5582 /***********************************************************************
5583 Changing an iterator's position
5584 ***********************************************************************/
5586 /* Change IT's current position to POS in current_buffer. If FORCE_P
5587 is non-zero, always check for text properties at the new position.
5588 Otherwise, text properties are only looked up if POS >=
5589 IT->check_charpos of a property. */
5592 reseat (it
, pos
, force_p
)
5594 struct text_pos pos
;
5597 int original_pos
= IT_CHARPOS (*it
);
5599 reseat_1 (it
, pos
, 0);
5601 /* Determine where to check text properties. Avoid doing it
5602 where possible because text property lookup is very expensive. */
5604 || CHARPOS (pos
) > it
->stop_charpos
5605 || CHARPOS (pos
) < original_pos
)
5612 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5613 IT->stop_pos to POS, also. */
5616 reseat_1 (it
, pos
, set_stop_p
)
5618 struct text_pos pos
;
5621 /* Don't call this function when scanning a C string. */
5622 xassert (it
->s
== NULL
);
5624 /* POS must be a reasonable value. */
5625 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5627 it
->current
.pos
= it
->position
= pos
;
5628 it
->end_charpos
= ZV
;
5630 it
->current
.dpvec_index
= -1;
5631 it
->current
.overlay_string_index
= -1;
5632 IT_STRING_CHARPOS (*it
) = -1;
5633 IT_STRING_BYTEPOS (*it
) = -1;
5635 it
->string_from_display_prop_p
= 0;
5636 it
->method
= GET_FROM_BUFFER
;
5637 it
->object
= it
->w
->buffer
;
5638 it
->area
= TEXT_AREA
;
5639 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5641 it
->string_from_display_prop_p
= 0;
5642 it
->face_before_selective_p
= 0;
5645 it
->stop_charpos
= CHARPOS (pos
);
5649 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5650 If S is non-null, it is a C string to iterate over. Otherwise,
5651 STRING gives a Lisp string to iterate over.
5653 If PRECISION > 0, don't return more then PRECISION number of
5654 characters from the string.
5656 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5657 characters have been returned. FIELD_WIDTH < 0 means an infinite
5660 MULTIBYTE = 0 means disable processing of multibyte characters,
5661 MULTIBYTE > 0 means enable it,
5662 MULTIBYTE < 0 means use IT->multibyte_p.
5664 IT must be initialized via a prior call to init_iterator before
5665 calling this function. */
5668 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5673 int precision
, field_width
, multibyte
;
5675 /* No region in strings. */
5676 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5678 /* No text property checks performed by default, but see below. */
5679 it
->stop_charpos
= -1;
5681 /* Set iterator position and end position. */
5682 bzero (&it
->current
, sizeof it
->current
);
5683 it
->current
.overlay_string_index
= -1;
5684 it
->current
.dpvec_index
= -1;
5685 xassert (charpos
>= 0);
5687 /* If STRING is specified, use its multibyteness, otherwise use the
5688 setting of MULTIBYTE, if specified. */
5690 it
->multibyte_p
= multibyte
> 0;
5694 xassert (STRINGP (string
));
5695 it
->string
= string
;
5697 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5698 it
->method
= GET_FROM_STRING
;
5699 it
->current
.string_pos
= string_pos (charpos
, string
);
5706 /* Note that we use IT->current.pos, not it->current.string_pos,
5707 for displaying C strings. */
5708 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5709 if (it
->multibyte_p
)
5711 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5712 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5716 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5717 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5720 it
->method
= GET_FROM_C_STRING
;
5723 /* PRECISION > 0 means don't return more than PRECISION characters
5725 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5726 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5728 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5729 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5730 FIELD_WIDTH < 0 means infinite field width. This is useful for
5731 padding with `-' at the end of a mode line. */
5732 if (field_width
< 0)
5733 field_width
= INFINITY
;
5734 if (field_width
> it
->end_charpos
- charpos
)
5735 it
->end_charpos
= charpos
+ field_width
;
5737 /* Use the standard display table for displaying strings. */
5738 if (DISP_TABLE_P (Vstandard_display_table
))
5739 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5741 it
->stop_charpos
= charpos
;
5747 /***********************************************************************
5749 ***********************************************************************/
5751 /* Map enum it_method value to corresponding next_element_from_* function. */
5753 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5755 next_element_from_buffer
,
5756 next_element_from_display_vector
,
5757 next_element_from_composition
,
5758 next_element_from_string
,
5759 next_element_from_c_string
,
5760 next_element_from_image
,
5761 next_element_from_stretch
5764 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5766 /* Load IT's display element fields with information about the next
5767 display element from the current position of IT. Value is zero if
5768 end of buffer (or C string) is reached. */
5770 static struct frame
*last_escape_glyph_frame
= NULL
;
5771 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5772 static int last_escape_glyph_merged_face_id
= 0;
5775 get_next_display_element (it
)
5778 /* Non-zero means that we found a display element. Zero means that
5779 we hit the end of what we iterate over. Performance note: the
5780 function pointer `method' used here turns out to be faster than
5781 using a sequence of if-statements. */
5785 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5787 if (it
->what
== IT_CHARACTER
)
5789 /* Map via display table or translate control characters.
5790 IT->c, IT->len etc. have been set to the next character by
5791 the function call above. If we have a display table, and it
5792 contains an entry for IT->c, translate it. Don't do this if
5793 IT->c itself comes from a display table, otherwise we could
5794 end up in an infinite recursion. (An alternative could be to
5795 count the recursion depth of this function and signal an
5796 error when a certain maximum depth is reached.) Is it worth
5798 if (success_p
&& it
->dpvec
== NULL
)
5803 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5806 struct Lisp_Vector
*v
= XVECTOR (dv
);
5808 /* Return the first character from the display table
5809 entry, if not empty. If empty, don't display the
5810 current character. */
5813 it
->dpvec_char_len
= it
->len
;
5814 it
->dpvec
= v
->contents
;
5815 it
->dpend
= v
->contents
+ v
->size
;
5816 it
->current
.dpvec_index
= 0;
5817 it
->dpvec_face_id
= -1;
5818 it
->saved_face_id
= it
->face_id
;
5819 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5824 set_iterator_to_next (it
, 0);
5829 /* Translate control characters into `\003' or `^C' form.
5830 Control characters coming from a display table entry are
5831 currently not translated because we use IT->dpvec to hold
5832 the translation. This could easily be changed but I
5833 don't believe that it is worth doing.
5835 If it->multibyte_p is nonzero, non-printable non-ASCII
5836 characters are also translated to octal form.
5838 If it->multibyte_p is zero, eight-bit characters that
5839 don't have corresponding multibyte char code are also
5840 translated to octal form. */
5841 else if ((it
->c
< ' '
5842 ? (it
->area
!= TEXT_AREA
5843 /* In mode line, treat \n, \t like other crl chars. */
5845 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5846 || (it
->c
!= '\n' && it
->c
!= '\t'))
5848 ? (!CHAR_PRINTABLE_P (it
->c
)
5849 || (!NILP (Vnobreak_char_display
)
5850 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5851 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5853 && (! unibyte_display_via_language_environment
5854 || (UNIBYTE_CHAR_HAS_MULTIBYTE_P (it
->c
)))))))
5856 /* IT->c is a control character which must be displayed
5857 either as '\003' or as `^C' where the '\\' and '^'
5858 can be defined in the display table. Fill
5859 IT->ctl_chars with glyphs for what we have to
5860 display. Then, set IT->dpvec to these glyphs. */
5863 int face_id
, lface_id
= 0 ;
5866 /* Handle control characters with ^. */
5868 if (it
->c
< 128 && it
->ctl_arrow_p
)
5872 g
= '^'; /* default glyph for Control */
5873 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5875 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5876 && GLYPH_CODE_CHAR_VALID_P (gc
))
5878 g
= GLYPH_CODE_CHAR (gc
);
5879 lface_id
= GLYPH_CODE_FACE (gc
);
5883 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5885 else if (it
->f
== last_escape_glyph_frame
5886 && it
->face_id
== last_escape_glyph_face_id
)
5888 face_id
= last_escape_glyph_merged_face_id
;
5892 /* Merge the escape-glyph face into the current face. */
5893 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5895 last_escape_glyph_frame
= it
->f
;
5896 last_escape_glyph_face_id
= it
->face_id
;
5897 last_escape_glyph_merged_face_id
= face_id
;
5900 XSETINT (it
->ctl_chars
[0], g
);
5901 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5903 goto display_control
;
5906 /* Handle non-break space in the mode where it only gets
5909 if (EQ (Vnobreak_char_display
, Qt
)
5912 /* Merge the no-break-space face into the current face. */
5913 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5917 XSETINT (it
->ctl_chars
[0], ' ');
5919 goto display_control
;
5922 /* Handle sequences that start with the "escape glyph". */
5924 /* the default escape glyph is \. */
5925 escape_glyph
= '\\';
5928 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5929 && GLYPH_CODE_CHAR_VALID_P (gc
))
5931 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5932 lface_id
= GLYPH_CODE_FACE (gc
);
5936 /* The display table specified a face.
5937 Merge it into face_id and also into escape_glyph. */
5938 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5941 else if (it
->f
== last_escape_glyph_frame
5942 && it
->face_id
== last_escape_glyph_face_id
)
5944 face_id
= last_escape_glyph_merged_face_id
;
5948 /* Merge the escape-glyph face into the current face. */
5949 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5951 last_escape_glyph_frame
= it
->f
;
5952 last_escape_glyph_face_id
= it
->face_id
;
5953 last_escape_glyph_merged_face_id
= face_id
;
5956 /* Handle soft hyphens in the mode where they only get
5959 if (EQ (Vnobreak_char_display
, Qt
)
5963 XSETINT (it
->ctl_chars
[0], '-');
5965 goto display_control
;
5968 /* Handle non-break space and soft hyphen
5969 with the escape glyph. */
5971 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5973 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5974 it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5975 XSETINT (it
->ctl_chars
[1], it
->c
);
5977 goto display_control
;
5981 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5985 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5986 if (CHAR_BYTE8_P (it
->c
))
5988 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5991 else if (it
->c
< 256)
5998 /* It's an invalid character, which shouldn't
5999 happen actually, but due to bugs it may
6000 happen. Let's print the char as is, there's
6001 not much meaningful we can do with it. */
6003 str
[1] = it
->c
>> 8;
6004 str
[2] = it
->c
>> 16;
6005 str
[3] = it
->c
>> 24;
6009 for (i
= 0; i
< len
; i
++)
6012 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
6013 /* Insert three more glyphs into IT->ctl_chars for
6014 the octal display of the character. */
6015 g
= ((str
[i
] >> 6) & 7) + '0';
6016 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
6017 g
= ((str
[i
] >> 3) & 7) + '0';
6018 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
6019 g
= (str
[i
] & 7) + '0';
6020 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
6026 /* Set up IT->dpvec and return first character from it. */
6027 it
->dpvec_char_len
= it
->len
;
6028 it
->dpvec
= it
->ctl_chars
;
6029 it
->dpend
= it
->dpvec
+ ctl_len
;
6030 it
->current
.dpvec_index
= 0;
6031 it
->dpvec_face_id
= face_id
;
6032 it
->saved_face_id
= it
->face_id
;
6033 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6040 /* Adjust face id for a multibyte character. There are no multibyte
6041 character in unibyte text. */
6042 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6045 && FRAME_WINDOW_P (it
->f
))
6047 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6048 int pos
= (it
->s
? -1
6049 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6050 : IT_CHARPOS (*it
));
6052 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
6055 /* Is this character the last one of a run of characters with
6056 box? If yes, set IT->end_of_box_run_p to 1. */
6063 it
->end_of_box_run_p
6064 = ((face_id
= face_after_it_pos (it
),
6065 face_id
!= it
->face_id
)
6066 && (face
= FACE_FROM_ID (it
->f
, face_id
),
6067 face
->box
== FACE_NO_BOX
));
6070 /* Value is 0 if end of buffer or string reached. */
6075 /* Move IT to the next display element.
6077 RESEAT_P non-zero means if called on a newline in buffer text,
6078 skip to the next visible line start.
6080 Functions get_next_display_element and set_iterator_to_next are
6081 separate because I find this arrangement easier to handle than a
6082 get_next_display_element function that also increments IT's
6083 position. The way it is we can first look at an iterator's current
6084 display element, decide whether it fits on a line, and if it does,
6085 increment the iterator position. The other way around we probably
6086 would either need a flag indicating whether the iterator has to be
6087 incremented the next time, or we would have to implement a
6088 decrement position function which would not be easy to write. */
6091 set_iterator_to_next (it
, reseat_p
)
6095 /* Reset flags indicating start and end of a sequence of characters
6096 with box. Reset them at the start of this function because
6097 moving the iterator to a new position might set them. */
6098 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6102 case GET_FROM_BUFFER
:
6103 /* The current display element of IT is a character from
6104 current_buffer. Advance in the buffer, and maybe skip over
6105 invisible lines that are so because of selective display. */
6106 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6107 reseat_at_next_visible_line_start (it
, 0);
6110 xassert (it
->len
!= 0);
6111 IT_BYTEPOS (*it
) += it
->len
;
6112 IT_CHARPOS (*it
) += 1;
6113 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6117 case GET_FROM_COMPOSITION
:
6118 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
6119 xassert (it
->sp
> 0);
6121 if (it
->method
== GET_FROM_STRING
)
6123 IT_STRING_BYTEPOS (*it
) += it
->len
;
6124 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
6125 goto consider_string_end
;
6127 else if (it
->method
== GET_FROM_BUFFER
)
6129 IT_BYTEPOS (*it
) += it
->len
;
6130 IT_CHARPOS (*it
) += it
->cmp_len
;
6134 case GET_FROM_C_STRING
:
6135 /* Current display element of IT is from a C string. */
6136 IT_BYTEPOS (*it
) += it
->len
;
6137 IT_CHARPOS (*it
) += 1;
6140 case GET_FROM_DISPLAY_VECTOR
:
6141 /* Current display element of IT is from a display table entry.
6142 Advance in the display table definition. Reset it to null if
6143 end reached, and continue with characters from buffers/
6145 ++it
->current
.dpvec_index
;
6147 /* Restore face of the iterator to what they were before the
6148 display vector entry (these entries may contain faces). */
6149 it
->face_id
= it
->saved_face_id
;
6151 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6153 int recheck_faces
= it
->ellipsis_p
;
6156 it
->method
= GET_FROM_C_STRING
;
6157 else if (STRINGP (it
->string
))
6158 it
->method
= GET_FROM_STRING
;
6161 it
->method
= GET_FROM_BUFFER
;
6162 it
->object
= it
->w
->buffer
;
6166 it
->current
.dpvec_index
= -1;
6168 /* Skip over characters which were displayed via IT->dpvec. */
6169 if (it
->dpvec_char_len
< 0)
6170 reseat_at_next_visible_line_start (it
, 1);
6171 else if (it
->dpvec_char_len
> 0)
6173 if (it
->method
== GET_FROM_STRING
6174 && it
->n_overlay_strings
> 0)
6175 it
->ignore_overlay_strings_at_pos_p
= 1;
6176 it
->len
= it
->dpvec_char_len
;
6177 set_iterator_to_next (it
, reseat_p
);
6180 /* Maybe recheck faces after display vector */
6182 it
->stop_charpos
= IT_CHARPOS (*it
);
6186 case GET_FROM_STRING
:
6187 /* Current display element is a character from a Lisp string. */
6188 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6189 IT_STRING_BYTEPOS (*it
) += it
->len
;
6190 IT_STRING_CHARPOS (*it
) += 1;
6192 consider_string_end
:
6194 if (it
->current
.overlay_string_index
>= 0)
6196 /* IT->string is an overlay string. Advance to the
6197 next, if there is one. */
6198 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6201 next_overlay_string (it
);
6203 setup_for_ellipsis (it
, 0);
6208 /* IT->string is not an overlay string. If we reached
6209 its end, and there is something on IT->stack, proceed
6210 with what is on the stack. This can be either another
6211 string, this time an overlay string, or a buffer. */
6212 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6216 if (it
->method
== GET_FROM_STRING
)
6217 goto consider_string_end
;
6222 case GET_FROM_IMAGE
:
6223 case GET_FROM_STRETCH
:
6224 /* The position etc with which we have to proceed are on
6225 the stack. The position may be at the end of a string,
6226 if the `display' property takes up the whole string. */
6227 xassert (it
->sp
> 0);
6229 if (it
->method
== GET_FROM_STRING
)
6230 goto consider_string_end
;
6234 /* There are no other methods defined, so this should be a bug. */
6238 xassert (it
->method
!= GET_FROM_STRING
6239 || (STRINGP (it
->string
)
6240 && IT_STRING_CHARPOS (*it
) >= 0));
6243 /* Load IT's display element fields with information about the next
6244 display element which comes from a display table entry or from the
6245 result of translating a control character to one of the forms `^C'
6248 IT->dpvec holds the glyphs to return as characters.
6249 IT->saved_face_id holds the face id before the display vector--
6250 it is restored into IT->face_idin set_iterator_to_next. */
6253 next_element_from_display_vector (it
)
6259 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6261 it
->face_id
= it
->saved_face_id
;
6263 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6264 That seemed totally bogus - so I changed it... */
6265 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6267 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6269 it
->c
= GLYPH_CODE_CHAR (gc
);
6270 it
->len
= CHAR_BYTES (it
->c
);
6272 /* The entry may contain a face id to use. Such a face id is
6273 the id of a Lisp face, not a realized face. A face id of
6274 zero means no face is specified. */
6275 if (it
->dpvec_face_id
>= 0)
6276 it
->face_id
= it
->dpvec_face_id
;
6279 int lface_id
= GLYPH_CODE_FACE (gc
);
6281 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6286 /* Display table entry is invalid. Return a space. */
6287 it
->c
= ' ', it
->len
= 1;
6289 /* Don't change position and object of the iterator here. They are
6290 still the values of the character that had this display table
6291 entry or was translated, and that's what we want. */
6292 it
->what
= IT_CHARACTER
;
6297 /* Load IT with the next display element from Lisp string IT->string.
6298 IT->current.string_pos is the current position within the string.
6299 If IT->current.overlay_string_index >= 0, the Lisp string is an
6303 next_element_from_string (it
)
6306 struct text_pos position
;
6308 xassert (STRINGP (it
->string
));
6309 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6310 position
= it
->current
.string_pos
;
6312 /* Time to check for invisible text? */
6313 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6314 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6318 /* Since a handler may have changed IT->method, we must
6320 return GET_NEXT_DISPLAY_ELEMENT (it
);
6323 if (it
->current
.overlay_string_index
>= 0)
6325 /* Get the next character from an overlay string. In overlay
6326 strings, There is no field width or padding with spaces to
6328 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6333 else if (STRING_MULTIBYTE (it
->string
))
6335 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6336 const unsigned char *s
= (SDATA (it
->string
)
6337 + IT_STRING_BYTEPOS (*it
));
6338 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6342 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6348 /* Get the next character from a Lisp string that is not an
6349 overlay string. Such strings come from the mode line, for
6350 example. We may have to pad with spaces, or truncate the
6351 string. See also next_element_from_c_string. */
6352 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6357 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6359 /* Pad with spaces. */
6360 it
->c
= ' ', it
->len
= 1;
6361 CHARPOS (position
) = BYTEPOS (position
) = -1;
6363 else if (STRING_MULTIBYTE (it
->string
))
6365 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6366 const unsigned char *s
= (SDATA (it
->string
)
6367 + IT_STRING_BYTEPOS (*it
));
6368 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6372 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6377 /* Record what we have and where it came from. */
6378 it
->what
= IT_CHARACTER
;
6379 it
->object
= it
->string
;
6380 it
->position
= position
;
6385 /* Load IT with next display element from C string IT->s.
6386 IT->string_nchars is the maximum number of characters to return
6387 from the string. IT->end_charpos may be greater than
6388 IT->string_nchars when this function is called, in which case we
6389 may have to return padding spaces. Value is zero if end of string
6390 reached, including padding spaces. */
6393 next_element_from_c_string (it
)
6399 it
->what
= IT_CHARACTER
;
6400 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6403 /* IT's position can be greater IT->string_nchars in case a field
6404 width or precision has been specified when the iterator was
6406 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6408 /* End of the game. */
6412 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6414 /* Pad with spaces. */
6415 it
->c
= ' ', it
->len
= 1;
6416 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6418 else if (it
->multibyte_p
)
6420 /* Implementation note: The calls to strlen apparently aren't a
6421 performance problem because there is no noticeable performance
6422 difference between Emacs running in unibyte or multibyte mode. */
6423 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6424 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6428 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6434 /* Set up IT to return characters from an ellipsis, if appropriate.
6435 The definition of the ellipsis glyphs may come from a display table
6436 entry. This function Fills IT with the first glyph from the
6437 ellipsis if an ellipsis is to be displayed. */
6440 next_element_from_ellipsis (it
)
6443 if (it
->selective_display_ellipsis_p
)
6444 setup_for_ellipsis (it
, it
->len
);
6447 /* The face at the current position may be different from the
6448 face we find after the invisible text. Remember what it
6449 was in IT->saved_face_id, and signal that it's there by
6450 setting face_before_selective_p. */
6451 it
->saved_face_id
= it
->face_id
;
6452 it
->method
= GET_FROM_BUFFER
;
6453 it
->object
= it
->w
->buffer
;
6454 reseat_at_next_visible_line_start (it
, 1);
6455 it
->face_before_selective_p
= 1;
6458 return GET_NEXT_DISPLAY_ELEMENT (it
);
6462 /* Deliver an image display element. The iterator IT is already
6463 filled with image information (done in handle_display_prop). Value
6468 next_element_from_image (it
)
6471 it
->what
= IT_IMAGE
;
6476 /* Fill iterator IT with next display element from a stretch glyph
6477 property. IT->object is the value of the text property. Value is
6481 next_element_from_stretch (it
)
6484 it
->what
= IT_STRETCH
;
6489 /* Load IT with the next display element from current_buffer. Value
6490 is zero if end of buffer reached. IT->stop_charpos is the next
6491 position at which to stop and check for text properties or buffer
6495 next_element_from_buffer (it
)
6500 /* Check this assumption, otherwise, we would never enter the
6501 if-statement, below. */
6502 xassert (IT_CHARPOS (*it
) >= BEGV
6503 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6505 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6507 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6509 int overlay_strings_follow_p
;
6511 /* End of the game, except when overlay strings follow that
6512 haven't been returned yet. */
6513 if (it
->overlay_strings_at_end_processed_p
)
6514 overlay_strings_follow_p
= 0;
6517 it
->overlay_strings_at_end_processed_p
= 1;
6518 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6521 if (overlay_strings_follow_p
)
6522 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6526 it
->position
= it
->current
.pos
;
6533 return GET_NEXT_DISPLAY_ELEMENT (it
);
6538 /* No face changes, overlays etc. in sight, so just return a
6539 character from current_buffer. */
6542 /* Maybe run the redisplay end trigger hook. Performance note:
6543 This doesn't seem to cost measurable time. */
6544 if (it
->redisplay_end_trigger_charpos
6546 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6547 run_redisplay_end_trigger_hook (it
);
6549 /* Get the next character, maybe multibyte. */
6550 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6551 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6553 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6554 - IT_BYTEPOS (*it
));
6555 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6558 it
->c
= *p
, it
->len
= 1;
6560 /* Record what we have and where it came from. */
6561 it
->what
= IT_CHARACTER
;
6562 it
->object
= it
->w
->buffer
;
6563 it
->position
= it
->current
.pos
;
6565 /* Normally we return the character found above, except when we
6566 really want to return an ellipsis for selective display. */
6571 /* A value of selective > 0 means hide lines indented more
6572 than that number of columns. */
6573 if (it
->selective
> 0
6574 && IT_CHARPOS (*it
) + 1 < ZV
6575 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6576 IT_BYTEPOS (*it
) + 1,
6577 (double) it
->selective
)) /* iftc */
6579 success_p
= next_element_from_ellipsis (it
);
6580 it
->dpvec_char_len
= -1;
6583 else if (it
->c
== '\r' && it
->selective
== -1)
6585 /* A value of selective == -1 means that everything from the
6586 CR to the end of the line is invisible, with maybe an
6587 ellipsis displayed for it. */
6588 success_p
= next_element_from_ellipsis (it
);
6589 it
->dpvec_char_len
= -1;
6594 /* Value is zero if end of buffer reached. */
6595 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6600 /* Run the redisplay end trigger hook for IT. */
6603 run_redisplay_end_trigger_hook (it
)
6606 Lisp_Object args
[3];
6608 /* IT->glyph_row should be non-null, i.e. we should be actually
6609 displaying something, or otherwise we should not run the hook. */
6610 xassert (it
->glyph_row
);
6612 /* Set up hook arguments. */
6613 args
[0] = Qredisplay_end_trigger_functions
;
6614 args
[1] = it
->window
;
6615 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6616 it
->redisplay_end_trigger_charpos
= 0;
6618 /* Since we are *trying* to run these functions, don't try to run
6619 them again, even if they get an error. */
6620 it
->w
->redisplay_end_trigger
= Qnil
;
6621 Frun_hook_with_args (3, args
);
6623 /* Notice if it changed the face of the character we are on. */
6624 handle_face_prop (it
);
6628 /* Deliver a composition display element. The iterator IT is already
6629 filled with composition information (done in
6630 handle_composition_prop). Value is always 1. */
6633 next_element_from_composition (it
)
6636 it
->what
= IT_COMPOSITION
;
6637 it
->position
= (STRINGP (it
->string
)
6638 ? it
->current
.string_pos
6640 if (STRINGP (it
->string
))
6641 it
->object
= it
->string
;
6643 it
->object
= it
->w
->buffer
;
6649 /***********************************************************************
6650 Moving an iterator without producing glyphs
6651 ***********************************************************************/
6653 /* Check if iterator is at a position corresponding to a valid buffer
6654 position after some move_it_ call. */
6656 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6657 ((it)->method == GET_FROM_STRING \
6658 ? IT_STRING_CHARPOS (*it) == 0 \
6662 /* Move iterator IT to a specified buffer or X position within one
6663 line on the display without producing glyphs.
6665 OP should be a bit mask including some or all of these bits:
6666 MOVE_TO_X: Stop on reaching x-position TO_X.
6667 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6668 Regardless of OP's value, stop in reaching the end of the display line.
6670 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6671 This means, in particular, that TO_X includes window's horizontal
6674 The return value has several possible values that
6675 say what condition caused the scan to stop:
6677 MOVE_POS_MATCH_OR_ZV
6678 - when TO_POS or ZV was reached.
6681 -when TO_X was reached before TO_POS or ZV were reached.
6684 - when we reached the end of the display area and the line must
6688 - when we reached the end of the display area and the line is
6692 - when we stopped at a line end, i.e. a newline or a CR and selective
6695 static enum move_it_result
6696 move_it_in_display_line_to (struct it
*it
,
6697 EMACS_INT to_charpos
, int to_x
,
6698 enum move_operation_enum op
)
6700 enum move_it_result result
= MOVE_UNDEFINED
;
6701 struct glyph_row
*saved_glyph_row
;
6702 struct it wrap_it
, atpos_it
, atx_it
;
6705 /* Don't produce glyphs in produce_glyphs. */
6706 saved_glyph_row
= it
->glyph_row
;
6707 it
->glyph_row
= NULL
;
6709 /* Use wrap_it to save a copy of IT wherever a word wrap could
6710 occur. Use atpos_it to save a copy of IT at the desired buffer
6711 position, if found, so that we can scan ahead and check if the
6712 word later overshoots the window edge. Use atx_it similarly, for
6718 #define BUFFER_POS_REACHED_P() \
6719 ((op & MOVE_TO_POS) != 0 \
6720 && BUFFERP (it->object) \
6721 && IT_CHARPOS (*it) >= to_charpos \
6722 && (it->method == GET_FROM_BUFFER \
6723 || (it->method == GET_FROM_DISPLAY_VECTOR \
6724 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6726 /* If there's a line-/wrap-prefix, handle it. */
6727 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6728 && it
->current_y
< it
->last_visible_y
)
6729 handle_line_prefix (it
);
6733 int x
, i
, ascent
= 0, descent
= 0;
6735 /* Utility macro to reset an iterator with x, ascent, and descent. */
6736 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6737 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6738 (IT)->max_descent = descent)
6740 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6742 if ((op
& MOVE_TO_POS
) != 0
6743 && BUFFERP (it
->object
)
6744 && it
->method
== GET_FROM_BUFFER
6745 && IT_CHARPOS (*it
) > to_charpos
)
6747 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6749 result
= MOVE_POS_MATCH_OR_ZV
;
6752 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6753 /* If wrap_it is valid, the current position might be in a
6754 word that is wrapped. So, save the iterator in
6755 atpos_it and continue to see if wrapping happens. */
6759 /* Stop when ZV reached.
6760 We used to stop here when TO_CHARPOS reached as well, but that is
6761 too soon if this glyph does not fit on this line. So we handle it
6762 explicitly below. */
6763 if (!get_next_display_element (it
))
6765 result
= MOVE_POS_MATCH_OR_ZV
;
6769 if (it
->line_wrap
== TRUNCATE
)
6771 if (BUFFER_POS_REACHED_P ())
6773 result
= MOVE_POS_MATCH_OR_ZV
;
6779 if (it
->line_wrap
== WORD_WRAP
)
6781 if (IT_DISPLAYING_WHITESPACE (it
))
6785 /* We have reached a glyph that follows one or more
6786 whitespace characters. If the position is
6787 already found, we are done. */
6788 if (atpos_it
.sp
>= 0)
6791 result
= MOVE_POS_MATCH_OR_ZV
;
6797 result
= MOVE_X_REACHED
;
6800 /* Otherwise, we can wrap here. */
6807 /* Remember the line height for the current line, in case
6808 the next element doesn't fit on the line. */
6809 ascent
= it
->max_ascent
;
6810 descent
= it
->max_descent
;
6812 /* The call to produce_glyphs will get the metrics of the
6813 display element IT is loaded with. Record the x-position
6814 before this display element, in case it doesn't fit on the
6818 PRODUCE_GLYPHS (it
);
6820 if (it
->area
!= TEXT_AREA
)
6822 set_iterator_to_next (it
, 1);
6826 /* The number of glyphs we get back in IT->nglyphs will normally
6827 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6828 character on a terminal frame, or (iii) a line end. For the
6829 second case, IT->nglyphs - 1 padding glyphs will be present
6830 (on X frames, there is only one glyph produced for a
6831 composite character.
6833 The behavior implemented below means, for continuation lines,
6834 that as many spaces of a TAB as fit on the current line are
6835 displayed there. For terminal frames, as many glyphs of a
6836 multi-glyph character are displayed in the current line, too.
6837 This is what the old redisplay code did, and we keep it that
6838 way. Under X, the whole shape of a complex character must
6839 fit on the line or it will be completely displayed in the
6842 Note that both for tabs and padding glyphs, all glyphs have
6846 /* More than one glyph or glyph doesn't fit on line. All
6847 glyphs have the same width. */
6848 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6850 int x_before_this_char
= x
;
6851 int hpos_before_this_char
= it
->hpos
;
6853 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6855 new_x
= x
+ single_glyph_width
;
6857 /* We want to leave anything reaching TO_X to the caller. */
6858 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6860 if (BUFFER_POS_REACHED_P ())
6862 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6863 goto buffer_pos_reached
;
6864 if (atpos_it
.sp
< 0)
6867 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6872 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6875 result
= MOVE_X_REACHED
;
6881 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6886 if (/* Lines are continued. */
6887 it
->line_wrap
!= TRUNCATE
6888 && (/* And glyph doesn't fit on the line. */
6889 new_x
> it
->last_visible_x
6890 /* Or it fits exactly and we're on a window
6892 || (new_x
== it
->last_visible_x
6893 && FRAME_WINDOW_P (it
->f
))))
6895 if (/* IT->hpos == 0 means the very first glyph
6896 doesn't fit on the line, e.g. a wide image. */
6898 || (new_x
== it
->last_visible_x
6899 && FRAME_WINDOW_P (it
->f
)))
6902 it
->current_x
= new_x
;
6904 /* The character's last glyph just barely fits
6906 if (i
== it
->nglyphs
- 1)
6908 /* If this is the destination position,
6909 return a position *before* it in this row,
6910 now that we know it fits in this row. */
6911 if (BUFFER_POS_REACHED_P ())
6913 if (it
->line_wrap
!= WORD_WRAP
6916 it
->hpos
= hpos_before_this_char
;
6917 it
->current_x
= x_before_this_char
;
6918 result
= MOVE_POS_MATCH_OR_ZV
;
6921 if (it
->line_wrap
== WORD_WRAP
6925 atpos_it
.current_x
= x_before_this_char
;
6926 atpos_it
.hpos
= hpos_before_this_char
;
6930 set_iterator_to_next (it
, 1);
6931 #ifdef HAVE_WINDOW_SYSTEM
6932 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6934 if (!get_next_display_element (it
))
6936 result
= MOVE_POS_MATCH_OR_ZV
;
6939 if (BUFFER_POS_REACHED_P ())
6941 if (ITERATOR_AT_END_OF_LINE_P (it
))
6942 result
= MOVE_POS_MATCH_OR_ZV
;
6944 result
= MOVE_LINE_CONTINUED
;
6947 if (ITERATOR_AT_END_OF_LINE_P (it
))
6949 result
= MOVE_NEWLINE_OR_CR
;
6953 #endif /* HAVE_WINDOW_SYSTEM */
6957 IT_RESET_X_ASCENT_DESCENT (it
);
6959 if (wrap_it
.sp
>= 0)
6966 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6968 result
= MOVE_LINE_CONTINUED
;
6972 if (BUFFER_POS_REACHED_P ())
6974 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6975 goto buffer_pos_reached
;
6976 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6979 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6983 if (new_x
> it
->first_visible_x
)
6985 /* Glyph is visible. Increment number of glyphs that
6986 would be displayed. */
6991 if (result
!= MOVE_UNDEFINED
)
6994 else if (BUFFER_POS_REACHED_P ())
6997 IT_RESET_X_ASCENT_DESCENT (it
);
6998 result
= MOVE_POS_MATCH_OR_ZV
;
7001 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7003 /* Stop when TO_X specified and reached. This check is
7004 necessary here because of lines consisting of a line end,
7005 only. The line end will not produce any glyphs and we
7006 would never get MOVE_X_REACHED. */
7007 xassert (it
->nglyphs
== 0);
7008 result
= MOVE_X_REACHED
;
7012 /* Is this a line end? If yes, we're done. */
7013 if (ITERATOR_AT_END_OF_LINE_P (it
))
7015 result
= MOVE_NEWLINE_OR_CR
;
7019 /* The current display element has been consumed. Advance
7021 set_iterator_to_next (it
, 1);
7023 /* Stop if lines are truncated and IT's current x-position is
7024 past the right edge of the window now. */
7025 if (it
->line_wrap
== TRUNCATE
7026 && it
->current_x
>= it
->last_visible_x
)
7028 #ifdef HAVE_WINDOW_SYSTEM
7029 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7031 if (!get_next_display_element (it
)
7032 || BUFFER_POS_REACHED_P ())
7034 result
= MOVE_POS_MATCH_OR_ZV
;
7037 if (ITERATOR_AT_END_OF_LINE_P (it
))
7039 result
= MOVE_NEWLINE_OR_CR
;
7043 #endif /* HAVE_WINDOW_SYSTEM */
7044 result
= MOVE_LINE_TRUNCATED
;
7047 #undef IT_RESET_X_ASCENT_DESCENT
7050 #undef BUFFER_POS_REACHED_P
7052 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7053 restore the saved iterator. */
7054 if (atpos_it
.sp
>= 0)
7056 else if (atx_it
.sp
>= 0)
7061 /* Restore the iterator settings altered at the beginning of this
7063 it
->glyph_row
= saved_glyph_row
;
7067 /* For external use. */
7069 move_it_in_display_line (struct it
*it
,
7070 EMACS_INT to_charpos
, int to_x
,
7071 enum move_operation_enum op
)
7073 if (it
->line_wrap
== WORD_WRAP
7074 && (op
& MOVE_TO_X
))
7076 struct it save_it
= *it
;
7077 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7078 /* When word-wrap is on, TO_X may lie past the end
7079 of a wrapped line. Then it->current is the
7080 character on the next line, so backtrack to the
7081 space before the wrap point. */
7082 if (skip
== MOVE_LINE_CONTINUED
)
7084 int prev_x
= max (it
->current_x
- 1, 0);
7086 move_it_in_display_line_to
7087 (it
, -1, prev_x
, MOVE_TO_X
);
7091 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7095 /* Move IT forward until it satisfies one or more of the criteria in
7096 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7098 OP is a bit-mask that specifies where to stop, and in particular,
7099 which of those four position arguments makes a difference. See the
7100 description of enum move_operation_enum.
7102 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7103 screen line, this function will set IT to the next position >
7107 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7109 int to_charpos
, to_x
, to_y
, to_vpos
;
7112 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7118 if (op
& MOVE_TO_VPOS
)
7120 /* If no TO_CHARPOS and no TO_X specified, stop at the
7121 start of the line TO_VPOS. */
7122 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7124 if (it
->vpos
== to_vpos
)
7130 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7134 /* TO_VPOS >= 0 means stop at TO_X in the line at
7135 TO_VPOS, or at TO_POS, whichever comes first. */
7136 if (it
->vpos
== to_vpos
)
7142 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7144 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7149 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7151 /* We have reached TO_X but not in the line we want. */
7152 skip
= move_it_in_display_line_to (it
, to_charpos
,
7154 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7162 else if (op
& MOVE_TO_Y
)
7164 struct it it_backup
;
7166 if (it
->line_wrap
== WORD_WRAP
)
7169 /* TO_Y specified means stop at TO_X in the line containing
7170 TO_Y---or at TO_CHARPOS if this is reached first. The
7171 problem is that we can't really tell whether the line
7172 contains TO_Y before we have completely scanned it, and
7173 this may skip past TO_X. What we do is to first scan to
7176 If TO_X is not specified, use a TO_X of zero. The reason
7177 is to make the outcome of this function more predictable.
7178 If we didn't use TO_X == 0, we would stop at the end of
7179 the line which is probably not what a caller would expect
7181 skip
= move_it_in_display_line_to
7182 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7183 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7185 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7186 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7188 else if (skip
== MOVE_X_REACHED
)
7190 /* If TO_X was reached, we want to know whether TO_Y is
7191 in the line. We know this is the case if the already
7192 scanned glyphs make the line tall enough. Otherwise,
7193 we must check by scanning the rest of the line. */
7194 line_height
= it
->max_ascent
+ it
->max_descent
;
7195 if (to_y
>= it
->current_y
7196 && to_y
< it
->current_y
+ line_height
)
7202 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7203 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7205 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7206 line_height
= it
->max_ascent
+ it
->max_descent
;
7207 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7209 if (to_y
>= it
->current_y
7210 && to_y
< it
->current_y
+ line_height
)
7212 /* If TO_Y is in this line and TO_X was reached
7213 above, we scanned too far. We have to restore
7214 IT's settings to the ones before skipping. */
7221 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7227 /* Check whether TO_Y is in this line. */
7228 line_height
= it
->max_ascent
+ it
->max_descent
;
7229 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7231 if (to_y
>= it
->current_y
7232 && to_y
< it
->current_y
+ line_height
)
7234 /* When word-wrap is on, TO_X may lie past the end
7235 of a wrapped line. Then it->current is the
7236 character on the next line, so backtrack to the
7237 space before the wrap point. */
7238 if (skip
== MOVE_LINE_CONTINUED
7239 && it
->line_wrap
== WORD_WRAP
)
7241 int prev_x
= max (it
->current_x
- 1, 0);
7243 skip
= move_it_in_display_line_to
7244 (it
, -1, prev_x
, MOVE_TO_X
);
7253 else if (BUFFERP (it
->object
)
7254 && it
->method
== GET_FROM_BUFFER
7255 && IT_CHARPOS (*it
) >= to_charpos
)
7256 skip
= MOVE_POS_MATCH_OR_ZV
;
7258 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7262 case MOVE_POS_MATCH_OR_ZV
:
7266 case MOVE_NEWLINE_OR_CR
:
7267 set_iterator_to_next (it
, 1);
7268 it
->continuation_lines_width
= 0;
7271 case MOVE_LINE_TRUNCATED
:
7272 it
->continuation_lines_width
= 0;
7273 reseat_at_next_visible_line_start (it
, 0);
7274 if ((op
& MOVE_TO_POS
) != 0
7275 && IT_CHARPOS (*it
) > to_charpos
)
7282 case MOVE_LINE_CONTINUED
:
7283 /* For continued lines ending in a tab, some of the glyphs
7284 associated with the tab are displayed on the current
7285 line. Since it->current_x does not include these glyphs,
7286 we use it->last_visible_x instead. */
7287 it
->continuation_lines_width
+=
7288 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
7295 /* Reset/increment for the next run. */
7296 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7297 it
->current_x
= it
->hpos
= 0;
7298 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7300 last_height
= it
->max_ascent
+ it
->max_descent
;
7301 last_max_ascent
= it
->max_ascent
;
7302 it
->max_ascent
= it
->max_descent
= 0;
7307 /* On text terminals, we may stop at the end of a line in the middle
7308 of a multi-character glyph. If the glyph itself is continued,
7309 i.e. it is actually displayed on the next line, don't treat this
7310 stopping point as valid; move to the next line instead (unless
7311 that brings us offscreen). */
7312 if (!FRAME_WINDOW_P (it
->f
)
7314 && IT_CHARPOS (*it
) == to_charpos
7315 && it
->what
== IT_CHARACTER
7317 && it
->line_wrap
== WINDOW_WRAP
7318 && it
->current_x
== it
->last_visible_x
- 1
7321 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7323 it
->continuation_lines_width
+= it
->current_x
;
7324 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7325 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7327 last_height
= it
->max_ascent
+ it
->max_descent
;
7328 last_max_ascent
= it
->max_ascent
;
7331 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7335 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7337 If DY > 0, move IT backward at least that many pixels. DY = 0
7338 means move IT backward to the preceding line start or BEGV. This
7339 function may move over more than DY pixels if IT->current_y - DY
7340 ends up in the middle of a line; in this case IT->current_y will be
7341 set to the top of the line moved to. */
7344 move_it_vertically_backward (it
, dy
)
7355 start_pos
= IT_CHARPOS (*it
);
7357 /* Estimate how many newlines we must move back. */
7358 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7360 /* Set the iterator's position that many lines back. */
7361 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7362 back_to_previous_visible_line_start (it
);
7364 /* Reseat the iterator here. When moving backward, we don't want
7365 reseat to skip forward over invisible text, set up the iterator
7366 to deliver from overlay strings at the new position etc. So,
7367 use reseat_1 here. */
7368 reseat_1 (it
, it
->current
.pos
, 1);
7370 /* We are now surely at a line start. */
7371 it
->current_x
= it
->hpos
= 0;
7372 it
->continuation_lines_width
= 0;
7374 /* Move forward and see what y-distance we moved. First move to the
7375 start of the next line so that we get its height. We need this
7376 height to be able to tell whether we reached the specified
7379 it2
.max_ascent
= it2
.max_descent
= 0;
7382 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7383 MOVE_TO_POS
| MOVE_TO_VPOS
);
7385 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7386 xassert (IT_CHARPOS (*it
) >= BEGV
);
7389 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7390 xassert (IT_CHARPOS (*it
) >= BEGV
);
7391 /* H is the actual vertical distance from the position in *IT
7392 and the starting position. */
7393 h
= it2
.current_y
- it
->current_y
;
7394 /* NLINES is the distance in number of lines. */
7395 nlines
= it2
.vpos
- it
->vpos
;
7397 /* Correct IT's y and vpos position
7398 so that they are relative to the starting point. */
7404 /* DY == 0 means move to the start of the screen line. The
7405 value of nlines is > 0 if continuation lines were involved. */
7407 move_it_by_lines (it
, nlines
, 1);
7409 /* I think this assert is bogus if buffer contains
7410 invisible text or images. KFS. */
7411 xassert (IT_CHARPOS (*it
) <= start_pos
);
7416 /* The y-position we try to reach, relative to *IT.
7417 Note that H has been subtracted in front of the if-statement. */
7418 int target_y
= it
->current_y
+ h
- dy
;
7419 int y0
= it3
.current_y
;
7420 int y1
= line_bottom_y (&it3
);
7421 int line_height
= y1
- y0
;
7423 /* If we did not reach target_y, try to move further backward if
7424 we can. If we moved too far backward, try to move forward. */
7425 if (target_y
< it
->current_y
7426 /* This is heuristic. In a window that's 3 lines high, with
7427 a line height of 13 pixels each, recentering with point
7428 on the bottom line will try to move -39/2 = 19 pixels
7429 backward. Try to avoid moving into the first line. */
7430 && (it
->current_y
- target_y
7431 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7432 && IT_CHARPOS (*it
) > BEGV
)
7434 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7435 target_y
- it
->current_y
));
7436 dy
= it
->current_y
- target_y
;
7437 goto move_further_back
;
7439 else if (target_y
>= it
->current_y
+ line_height
7440 && IT_CHARPOS (*it
) < ZV
)
7442 /* Should move forward by at least one line, maybe more.
7444 Note: Calling move_it_by_lines can be expensive on
7445 terminal frames, where compute_motion is used (via
7446 vmotion) to do the job, when there are very long lines
7447 and truncate-lines is nil. That's the reason for
7448 treating terminal frames specially here. */
7450 if (!FRAME_WINDOW_P (it
->f
))
7451 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7456 move_it_by_lines (it
, 1, 1);
7458 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7462 /* I think this assert is bogus if buffer contains
7463 invisible text or images. KFS. */
7464 xassert (IT_CHARPOS (*it
) >= BEGV
);
7471 /* Move IT by a specified amount of pixel lines DY. DY negative means
7472 move backwards. DY = 0 means move to start of screen line. At the
7473 end, IT will be on the start of a screen line. */
7476 move_it_vertically (it
, dy
)
7481 move_it_vertically_backward (it
, -dy
);
7484 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7485 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7486 MOVE_TO_POS
| MOVE_TO_Y
);
7487 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7489 /* If buffer ends in ZV without a newline, move to the start of
7490 the line to satisfy the post-condition. */
7491 if (IT_CHARPOS (*it
) == ZV
7493 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7494 move_it_by_lines (it
, 0, 0);
7499 /* Move iterator IT past the end of the text line it is in. */
7502 move_it_past_eol (it
)
7505 enum move_it_result rc
;
7507 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7508 if (rc
== MOVE_NEWLINE_OR_CR
)
7509 set_iterator_to_next (it
, 0);
7513 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7514 negative means move up. DVPOS == 0 means move to the start of the
7515 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7516 NEED_Y_P is zero, IT->current_y will be left unchanged.
7518 Further optimization ideas: If we would know that IT->f doesn't use
7519 a face with proportional font, we could be faster for
7520 truncate-lines nil. */
7523 move_it_by_lines (it
, dvpos
, need_y_p
)
7525 int dvpos
, need_y_p
;
7527 struct position pos
;
7529 /* The commented-out optimization uses vmotion on terminals. This
7530 gives bad results, because elements like it->what, on which
7531 callers such as pos_visible_p rely, aren't updated. */
7532 /* if (!FRAME_WINDOW_P (it->f))
7534 struct text_pos textpos;
7536 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7537 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7538 reseat (it, textpos, 1);
7539 it->vpos += pos.vpos;
7540 it->current_y += pos.vpos;
7546 /* DVPOS == 0 means move to the start of the screen line. */
7547 move_it_vertically_backward (it
, 0);
7548 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7549 /* Let next call to line_bottom_y calculate real line height */
7554 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7555 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7556 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7561 int start_charpos
, i
;
7563 /* Start at the beginning of the screen line containing IT's
7564 position. This may actually move vertically backwards,
7565 in case of overlays, so adjust dvpos accordingly. */
7567 move_it_vertically_backward (it
, 0);
7570 /* Go back -DVPOS visible lines and reseat the iterator there. */
7571 start_charpos
= IT_CHARPOS (*it
);
7572 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7573 back_to_previous_visible_line_start (it
);
7574 reseat (it
, it
->current
.pos
, 1);
7576 /* Move further back if we end up in a string or an image. */
7577 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7579 /* First try to move to start of display line. */
7581 move_it_vertically_backward (it
, 0);
7583 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7585 /* If start of line is still in string or image,
7586 move further back. */
7587 back_to_previous_visible_line_start (it
);
7588 reseat (it
, it
->current
.pos
, 1);
7592 it
->current_x
= it
->hpos
= 0;
7594 /* Above call may have moved too far if continuation lines
7595 are involved. Scan forward and see if it did. */
7597 it2
.vpos
= it2
.current_y
= 0;
7598 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7599 it
->vpos
-= it2
.vpos
;
7600 it
->current_y
-= it2
.current_y
;
7601 it
->current_x
= it
->hpos
= 0;
7603 /* If we moved too far back, move IT some lines forward. */
7604 if (it2
.vpos
> -dvpos
)
7606 int delta
= it2
.vpos
+ dvpos
;
7608 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7609 /* Move back again if we got too far ahead. */
7610 if (IT_CHARPOS (*it
) >= start_charpos
)
7616 /* Return 1 if IT points into the middle of a display vector. */
7619 in_display_vector_p (it
)
7622 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7623 && it
->current
.dpvec_index
> 0
7624 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7628 /***********************************************************************
7630 ***********************************************************************/
7633 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7637 add_to_log (format
, arg1
, arg2
)
7639 Lisp_Object arg1
, arg2
;
7641 Lisp_Object args
[3];
7642 Lisp_Object msg
, fmt
;
7645 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7648 /* Do nothing if called asynchronously. Inserting text into
7649 a buffer may call after-change-functions and alike and
7650 that would means running Lisp asynchronously. */
7651 if (handling_signal
)
7655 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7657 args
[0] = fmt
= build_string (format
);
7660 msg
= Fformat (3, args
);
7662 len
= SBYTES (msg
) + 1;
7663 SAFE_ALLOCA (buffer
, char *, len
);
7664 bcopy (SDATA (msg
), buffer
, len
);
7666 message_dolog (buffer
, len
- 1, 1, 0);
7673 /* Output a newline in the *Messages* buffer if "needs" one. */
7676 message_log_maybe_newline ()
7678 if (message_log_need_newline
)
7679 message_dolog ("", 0, 1, 0);
7683 /* Add a string M of length NBYTES to the message log, optionally
7684 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7685 nonzero, means interpret the contents of M as multibyte. This
7686 function calls low-level routines in order to bypass text property
7687 hooks, etc. which might not be safe to run.
7689 This may GC (insert may run before/after change hooks),
7690 so the buffer M must NOT point to a Lisp string. */
7693 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7695 int nbytes
, nlflag
, multibyte
;
7697 if (!NILP (Vmemory_full
))
7700 if (!NILP (Vmessage_log_max
))
7702 struct buffer
*oldbuf
;
7703 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7704 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7705 int point_at_end
= 0;
7707 Lisp_Object old_deactivate_mark
, tem
;
7708 struct gcpro gcpro1
;
7710 old_deactivate_mark
= Vdeactivate_mark
;
7711 oldbuf
= current_buffer
;
7712 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7713 current_buffer
->undo_list
= Qt
;
7715 oldpoint
= message_dolog_marker1
;
7716 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7717 oldbegv
= message_dolog_marker2
;
7718 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7719 oldzv
= message_dolog_marker3
;
7720 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7721 GCPRO1 (old_deactivate_mark
);
7729 BEGV_BYTE
= BEG_BYTE
;
7732 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7734 /* Insert the string--maybe converting multibyte to single byte
7735 or vice versa, so that all the text fits the buffer. */
7737 && NILP (current_buffer
->enable_multibyte_characters
))
7739 int i
, c
, char_bytes
;
7740 unsigned char work
[1];
7742 /* Convert a multibyte string to single-byte
7743 for the *Message* buffer. */
7744 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7746 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7747 work
[0] = (ASCII_CHAR_P (c
)
7749 : multibyte_char_to_unibyte (c
, Qnil
));
7750 insert_1_both (work
, 1, 1, 1, 0, 0);
7753 else if (! multibyte
7754 && ! NILP (current_buffer
->enable_multibyte_characters
))
7756 int i
, c
, char_bytes
;
7757 unsigned char *msg
= (unsigned char *) m
;
7758 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7759 /* Convert a single-byte string to multibyte
7760 for the *Message* buffer. */
7761 for (i
= 0; i
< nbytes
; i
++)
7764 c
= unibyte_char_to_multibyte (c
);
7765 char_bytes
= CHAR_STRING (c
, str
);
7766 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7770 insert_1 (m
, nbytes
, 1, 0, 0);
7774 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7775 insert_1 ("\n", 1, 1, 0, 0);
7777 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7779 this_bol_byte
= PT_BYTE
;
7781 /* See if this line duplicates the previous one.
7782 If so, combine duplicates. */
7785 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7787 prev_bol_byte
= PT_BYTE
;
7789 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7790 this_bol
, this_bol_byte
);
7793 del_range_both (prev_bol
, prev_bol_byte
,
7794 this_bol
, this_bol_byte
, 0);
7800 /* If you change this format, don't forget to also
7801 change message_log_check_duplicate. */
7802 sprintf (dupstr
, " [%d times]", dup
);
7803 duplen
= strlen (dupstr
);
7804 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7805 insert_1 (dupstr
, duplen
, 1, 0, 1);
7810 /* If we have more than the desired maximum number of lines
7811 in the *Messages* buffer now, delete the oldest ones.
7812 This is safe because we don't have undo in this buffer. */
7814 if (NATNUMP (Vmessage_log_max
))
7816 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7817 -XFASTINT (Vmessage_log_max
) - 1, 0);
7818 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7821 BEGV
= XMARKER (oldbegv
)->charpos
;
7822 BEGV_BYTE
= marker_byte_position (oldbegv
);
7831 ZV
= XMARKER (oldzv
)->charpos
;
7832 ZV_BYTE
= marker_byte_position (oldzv
);
7836 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7838 /* We can't do Fgoto_char (oldpoint) because it will run some
7840 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7841 XMARKER (oldpoint
)->bytepos
);
7844 unchain_marker (XMARKER (oldpoint
));
7845 unchain_marker (XMARKER (oldbegv
));
7846 unchain_marker (XMARKER (oldzv
));
7848 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7849 set_buffer_internal (oldbuf
);
7851 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7852 message_log_need_newline
= !nlflag
;
7853 Vdeactivate_mark
= old_deactivate_mark
;
7858 /* We are at the end of the buffer after just having inserted a newline.
7859 (Note: We depend on the fact we won't be crossing the gap.)
7860 Check to see if the most recent message looks a lot like the previous one.
7861 Return 0 if different, 1 if the new one should just replace it, or a
7862 value N > 1 if we should also append " [N times]". */
7865 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7866 int prev_bol
, this_bol
;
7867 int prev_bol_byte
, this_bol_byte
;
7870 int len
= Z_BYTE
- 1 - this_bol_byte
;
7872 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7873 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7875 for (i
= 0; i
< len
; i
++)
7877 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7885 if (*p1
++ == ' ' && *p1
++ == '[')
7888 while (*p1
>= '0' && *p1
<= '9')
7889 n
= n
* 10 + *p1
++ - '0';
7890 if (strncmp (p1
, " times]\n", 8) == 0)
7897 /* Display an echo area message M with a specified length of NBYTES
7898 bytes. The string may include null characters. If M is 0, clear
7899 out any existing message, and let the mini-buffer text show
7902 This may GC, so the buffer M must NOT point to a Lisp string. */
7905 message2 (m
, nbytes
, multibyte
)
7910 /* First flush out any partial line written with print. */
7911 message_log_maybe_newline ();
7913 message_dolog (m
, nbytes
, 1, multibyte
);
7914 message2_nolog (m
, nbytes
, multibyte
);
7918 /* The non-logging counterpart of message2. */
7921 message2_nolog (m
, nbytes
, multibyte
)
7923 int nbytes
, multibyte
;
7925 struct frame
*sf
= SELECTED_FRAME ();
7926 message_enable_multibyte
= multibyte
;
7930 if (noninteractive_need_newline
)
7931 putc ('\n', stderr
);
7932 noninteractive_need_newline
= 0;
7934 fwrite (m
, nbytes
, 1, stderr
);
7935 if (cursor_in_echo_area
== 0)
7936 fprintf (stderr
, "\n");
7939 /* A null message buffer means that the frame hasn't really been
7940 initialized yet. Error messages get reported properly by
7941 cmd_error, so this must be just an informative message; toss it. */
7942 else if (INTERACTIVE
7943 && sf
->glyphs_initialized_p
7944 && FRAME_MESSAGE_BUF (sf
))
7946 Lisp_Object mini_window
;
7949 /* Get the frame containing the mini-buffer
7950 that the selected frame is using. */
7951 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7952 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7954 FRAME_SAMPLE_VISIBILITY (f
);
7955 if (FRAME_VISIBLE_P (sf
)
7956 && ! FRAME_VISIBLE_P (f
))
7957 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7961 set_message (m
, Qnil
, nbytes
, multibyte
);
7962 if (minibuffer_auto_raise
)
7963 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7966 clear_message (1, 1);
7968 do_pending_window_change (0);
7969 echo_area_display (1);
7970 do_pending_window_change (0);
7971 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7972 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7977 /* Display an echo area message M with a specified length of NBYTES
7978 bytes. The string may include null characters. If M is not a
7979 string, clear out any existing message, and let the mini-buffer
7982 This function cancels echoing. */
7985 message3 (m
, nbytes
, multibyte
)
7990 struct gcpro gcpro1
;
7993 clear_message (1,1);
7996 /* First flush out any partial line written with print. */
7997 message_log_maybe_newline ();
8003 SAFE_ALLOCA (buffer
, char *, nbytes
);
8004 bcopy (SDATA (m
), buffer
, nbytes
);
8005 message_dolog (buffer
, nbytes
, 1, multibyte
);
8008 message3_nolog (m
, nbytes
, multibyte
);
8014 /* The non-logging version of message3.
8015 This does not cancel echoing, because it is used for echoing.
8016 Perhaps we need to make a separate function for echoing
8017 and make this cancel echoing. */
8020 message3_nolog (m
, nbytes
, multibyte
)
8022 int nbytes
, multibyte
;
8024 struct frame
*sf
= SELECTED_FRAME ();
8025 message_enable_multibyte
= multibyte
;
8029 if (noninteractive_need_newline
)
8030 putc ('\n', stderr
);
8031 noninteractive_need_newline
= 0;
8033 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8034 if (cursor_in_echo_area
== 0)
8035 fprintf (stderr
, "\n");
8038 /* A null message buffer means that the frame hasn't really been
8039 initialized yet. Error messages get reported properly by
8040 cmd_error, so this must be just an informative message; toss it. */
8041 else if (INTERACTIVE
8042 && sf
->glyphs_initialized_p
8043 && FRAME_MESSAGE_BUF (sf
))
8045 Lisp_Object mini_window
;
8049 /* Get the frame containing the mini-buffer
8050 that the selected frame is using. */
8051 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8052 frame
= XWINDOW (mini_window
)->frame
;
8055 FRAME_SAMPLE_VISIBILITY (f
);
8056 if (FRAME_VISIBLE_P (sf
)
8057 && !FRAME_VISIBLE_P (f
))
8058 Fmake_frame_visible (frame
);
8060 if (STRINGP (m
) && SCHARS (m
) > 0)
8062 set_message (NULL
, m
, nbytes
, multibyte
);
8063 if (minibuffer_auto_raise
)
8064 Fraise_frame (frame
);
8065 /* Assume we are not echoing.
8066 (If we are, echo_now will override this.) */
8067 echo_message_buffer
= Qnil
;
8070 clear_message (1, 1);
8072 do_pending_window_change (0);
8073 echo_area_display (1);
8074 do_pending_window_change (0);
8075 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8076 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8081 /* Display a null-terminated echo area message M. If M is 0, clear
8082 out any existing message, and let the mini-buffer text show through.
8084 The buffer M must continue to exist until after the echo area gets
8085 cleared or some other message gets displayed there. Do not pass
8086 text that is stored in a Lisp string. Do not pass text in a buffer
8087 that was alloca'd. */
8093 message2 (m
, (m
? strlen (m
) : 0), 0);
8097 /* The non-logging counterpart of message1. */
8103 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8106 /* Display a message M which contains a single %s
8107 which gets replaced with STRING. */
8110 message_with_string (m
, string
, log
)
8115 CHECK_STRING (string
);
8121 if (noninteractive_need_newline
)
8122 putc ('\n', stderr
);
8123 noninteractive_need_newline
= 0;
8124 fprintf (stderr
, m
, SDATA (string
));
8125 if (cursor_in_echo_area
== 0)
8126 fprintf (stderr
, "\n");
8130 else if (INTERACTIVE
)
8132 /* The frame whose minibuffer we're going to display the message on.
8133 It may be larger than the selected frame, so we need
8134 to use its buffer, not the selected frame's buffer. */
8135 Lisp_Object mini_window
;
8136 struct frame
*f
, *sf
= SELECTED_FRAME ();
8138 /* Get the frame containing the minibuffer
8139 that the selected frame is using. */
8140 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8141 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8143 /* A null message buffer means that the frame hasn't really been
8144 initialized yet. Error messages get reported properly by
8145 cmd_error, so this must be just an informative message; toss it. */
8146 if (FRAME_MESSAGE_BUF (f
))
8148 Lisp_Object args
[2], message
;
8149 struct gcpro gcpro1
, gcpro2
;
8151 args
[0] = build_string (m
);
8152 args
[1] = message
= string
;
8153 GCPRO2 (args
[0], message
);
8156 message
= Fformat (2, args
);
8159 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8161 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8165 /* Print should start at the beginning of the message
8166 buffer next time. */
8167 message_buf_print
= 0;
8173 /* Dump an informative message to the minibuf. If M is 0, clear out
8174 any existing message, and let the mini-buffer text show through. */
8178 message (m
, a1
, a2
, a3
)
8180 EMACS_INT a1
, a2
, a3
;
8186 if (noninteractive_need_newline
)
8187 putc ('\n', stderr
);
8188 noninteractive_need_newline
= 0;
8189 fprintf (stderr
, m
, a1
, a2
, a3
);
8190 if (cursor_in_echo_area
== 0)
8191 fprintf (stderr
, "\n");
8195 else if (INTERACTIVE
)
8197 /* The frame whose mini-buffer we're going to display the message
8198 on. It may be larger than the selected frame, so we need to
8199 use its buffer, not the selected frame's buffer. */
8200 Lisp_Object mini_window
;
8201 struct frame
*f
, *sf
= SELECTED_FRAME ();
8203 /* Get the frame containing the mini-buffer
8204 that the selected frame is using. */
8205 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8206 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8208 /* A null message buffer means that the frame hasn't really been
8209 initialized yet. Error messages get reported properly by
8210 cmd_error, so this must be just an informative message; toss
8212 if (FRAME_MESSAGE_BUF (f
))
8223 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8224 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8226 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8227 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8229 #endif /* NO_ARG_ARRAY */
8231 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8236 /* Print should start at the beginning of the message
8237 buffer next time. */
8238 message_buf_print
= 0;
8244 /* The non-logging version of message. */
8247 message_nolog (m
, a1
, a2
, a3
)
8249 EMACS_INT a1
, a2
, a3
;
8251 Lisp_Object old_log_max
;
8252 old_log_max
= Vmessage_log_max
;
8253 Vmessage_log_max
= Qnil
;
8254 message (m
, a1
, a2
, a3
);
8255 Vmessage_log_max
= old_log_max
;
8259 /* Display the current message in the current mini-buffer. This is
8260 only called from error handlers in process.c, and is not time
8266 if (!NILP (echo_area_buffer
[0]))
8269 string
= Fcurrent_message ();
8270 message3 (string
, SBYTES (string
),
8271 !NILP (current_buffer
->enable_multibyte_characters
));
8276 /* Make sure echo area buffers in `echo_buffers' are live.
8277 If they aren't, make new ones. */
8280 ensure_echo_area_buffers ()
8284 for (i
= 0; i
< 2; ++i
)
8285 if (!BUFFERP (echo_buffer
[i
])
8286 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8289 Lisp_Object old_buffer
;
8292 old_buffer
= echo_buffer
[i
];
8293 sprintf (name
, " *Echo Area %d*", i
);
8294 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8295 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8296 /* to force word wrap in echo area -
8297 it was decided to postpone this*/
8298 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8300 for (j
= 0; j
< 2; ++j
)
8301 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8302 echo_area_buffer
[j
] = echo_buffer
[i
];
8307 /* Call FN with args A1..A4 with either the current or last displayed
8308 echo_area_buffer as current buffer.
8310 WHICH zero means use the current message buffer
8311 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8312 from echo_buffer[] and clear it.
8314 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8315 suitable buffer from echo_buffer[] and clear it.
8317 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8318 that the current message becomes the last displayed one, make
8319 choose a suitable buffer for echo_area_buffer[0], and clear it.
8321 Value is what FN returns. */
8324 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8327 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8333 int this_one
, the_other
, clear_buffer_p
, rc
;
8334 int count
= SPECPDL_INDEX ();
8336 /* If buffers aren't live, make new ones. */
8337 ensure_echo_area_buffers ();
8342 this_one
= 0, the_other
= 1;
8344 this_one
= 1, the_other
= 0;
8347 this_one
= 0, the_other
= 1;
8350 /* We need a fresh one in case the current echo buffer equals
8351 the one containing the last displayed echo area message. */
8352 if (!NILP (echo_area_buffer
[this_one
])
8353 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8354 echo_area_buffer
[this_one
] = Qnil
;
8357 /* Choose a suitable buffer from echo_buffer[] is we don't
8359 if (NILP (echo_area_buffer
[this_one
]))
8361 echo_area_buffer
[this_one
]
8362 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8363 ? echo_buffer
[the_other
]
8364 : echo_buffer
[this_one
]);
8368 buffer
= echo_area_buffer
[this_one
];
8370 /* Don't get confused by reusing the buffer used for echoing
8371 for a different purpose. */
8372 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8375 record_unwind_protect (unwind_with_echo_area_buffer
,
8376 with_echo_area_buffer_unwind_data (w
));
8378 /* Make the echo area buffer current. Note that for display
8379 purposes, it is not necessary that the displayed window's buffer
8380 == current_buffer, except for text property lookup. So, let's
8381 only set that buffer temporarily here without doing a full
8382 Fset_window_buffer. We must also change w->pointm, though,
8383 because otherwise an assertions in unshow_buffer fails, and Emacs
8385 set_buffer_internal_1 (XBUFFER (buffer
));
8389 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8392 current_buffer
->undo_list
= Qt
;
8393 current_buffer
->read_only
= Qnil
;
8394 specbind (Qinhibit_read_only
, Qt
);
8395 specbind (Qinhibit_modification_hooks
, Qt
);
8397 if (clear_buffer_p
&& Z
> BEG
)
8400 xassert (BEGV
>= BEG
);
8401 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8403 rc
= fn (a1
, a2
, a3
, a4
);
8405 xassert (BEGV
>= BEG
);
8406 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8408 unbind_to (count
, Qnil
);
8413 /* Save state that should be preserved around the call to the function
8414 FN called in with_echo_area_buffer. */
8417 with_echo_area_buffer_unwind_data (w
)
8421 Lisp_Object vector
, tmp
;
8423 /* Reduce consing by keeping one vector in
8424 Vwith_echo_area_save_vector. */
8425 vector
= Vwith_echo_area_save_vector
;
8426 Vwith_echo_area_save_vector
= Qnil
;
8429 vector
= Fmake_vector (make_number (7), Qnil
);
8431 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8432 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8433 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8437 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8438 ASET (vector
, i
, w
->buffer
); ++i
;
8439 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8440 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8445 for (; i
< end
; ++i
)
8446 ASET (vector
, i
, Qnil
);
8449 xassert (i
== ASIZE (vector
));
8454 /* Restore global state from VECTOR which was created by
8455 with_echo_area_buffer_unwind_data. */
8458 unwind_with_echo_area_buffer (vector
)
8461 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8462 Vdeactivate_mark
= AREF (vector
, 1);
8463 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8465 if (WINDOWP (AREF (vector
, 3)))
8468 Lisp_Object buffer
, charpos
, bytepos
;
8470 w
= XWINDOW (AREF (vector
, 3));
8471 buffer
= AREF (vector
, 4);
8472 charpos
= AREF (vector
, 5);
8473 bytepos
= AREF (vector
, 6);
8476 set_marker_both (w
->pointm
, buffer
,
8477 XFASTINT (charpos
), XFASTINT (bytepos
));
8480 Vwith_echo_area_save_vector
= vector
;
8485 /* Set up the echo area for use by print functions. MULTIBYTE_P
8486 non-zero means we will print multibyte. */
8489 setup_echo_area_for_printing (multibyte_p
)
8492 /* If we can't find an echo area any more, exit. */
8493 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8496 ensure_echo_area_buffers ();
8498 if (!message_buf_print
)
8500 /* A message has been output since the last time we printed.
8501 Choose a fresh echo area buffer. */
8502 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8503 echo_area_buffer
[0] = echo_buffer
[1];
8505 echo_area_buffer
[0] = echo_buffer
[0];
8507 /* Switch to that buffer and clear it. */
8508 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8509 current_buffer
->truncate_lines
= Qnil
;
8513 int count
= SPECPDL_INDEX ();
8514 specbind (Qinhibit_read_only
, Qt
);
8515 /* Note that undo recording is always disabled. */
8517 unbind_to (count
, Qnil
);
8519 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8521 /* Set up the buffer for the multibyteness we need. */
8523 != !NILP (current_buffer
->enable_multibyte_characters
))
8524 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8526 /* Raise the frame containing the echo area. */
8527 if (minibuffer_auto_raise
)
8529 struct frame
*sf
= SELECTED_FRAME ();
8530 Lisp_Object mini_window
;
8531 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8532 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8535 message_log_maybe_newline ();
8536 message_buf_print
= 1;
8540 if (NILP (echo_area_buffer
[0]))
8542 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8543 echo_area_buffer
[0] = echo_buffer
[1];
8545 echo_area_buffer
[0] = echo_buffer
[0];
8548 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8550 /* Someone switched buffers between print requests. */
8551 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8552 current_buffer
->truncate_lines
= Qnil
;
8558 /* Display an echo area message in window W. Value is non-zero if W's
8559 height is changed. If display_last_displayed_message_p is
8560 non-zero, display the message that was last displayed, otherwise
8561 display the current message. */
8564 display_echo_area (w
)
8567 int i
, no_message_p
, window_height_changed_p
, count
;
8569 /* Temporarily disable garbage collections while displaying the echo
8570 area. This is done because a GC can print a message itself.
8571 That message would modify the echo area buffer's contents while a
8572 redisplay of the buffer is going on, and seriously confuse
8574 count
= inhibit_garbage_collection ();
8576 /* If there is no message, we must call display_echo_area_1
8577 nevertheless because it resizes the window. But we will have to
8578 reset the echo_area_buffer in question to nil at the end because
8579 with_echo_area_buffer will sets it to an empty buffer. */
8580 i
= display_last_displayed_message_p
? 1 : 0;
8581 no_message_p
= NILP (echo_area_buffer
[i
]);
8583 window_height_changed_p
8584 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8585 display_echo_area_1
,
8586 (EMACS_INT
) w
, Qnil
, 0, 0);
8589 echo_area_buffer
[i
] = Qnil
;
8591 unbind_to (count
, Qnil
);
8592 return window_height_changed_p
;
8596 /* Helper for display_echo_area. Display the current buffer which
8597 contains the current echo area message in window W, a mini-window,
8598 a pointer to which is passed in A1. A2..A4 are currently not used.
8599 Change the height of W so that all of the message is displayed.
8600 Value is non-zero if height of W was changed. */
8603 display_echo_area_1 (a1
, a2
, a3
, a4
)
8608 struct window
*w
= (struct window
*) a1
;
8610 struct text_pos start
;
8611 int window_height_changed_p
= 0;
8613 /* Do this before displaying, so that we have a large enough glyph
8614 matrix for the display. If we can't get enough space for the
8615 whole text, display the last N lines. That works by setting w->start. */
8616 window_height_changed_p
= resize_mini_window (w
, 0);
8618 /* Use the starting position chosen by resize_mini_window. */
8619 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8622 clear_glyph_matrix (w
->desired_matrix
);
8623 XSETWINDOW (window
, w
);
8624 try_window (window
, start
, 0);
8626 return window_height_changed_p
;
8630 /* Resize the echo area window to exactly the size needed for the
8631 currently displayed message, if there is one. If a mini-buffer
8632 is active, don't shrink it. */
8635 resize_echo_area_exactly ()
8637 if (BUFFERP (echo_area_buffer
[0])
8638 && WINDOWP (echo_area_window
))
8640 struct window
*w
= XWINDOW (echo_area_window
);
8642 Lisp_Object resize_exactly
;
8644 if (minibuf_level
== 0)
8645 resize_exactly
= Qt
;
8647 resize_exactly
= Qnil
;
8649 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8650 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8653 ++windows_or_buffers_changed
;
8654 ++update_mode_lines
;
8655 redisplay_internal (0);
8661 /* Callback function for with_echo_area_buffer, when used from
8662 resize_echo_area_exactly. A1 contains a pointer to the window to
8663 resize, EXACTLY non-nil means resize the mini-window exactly to the
8664 size of the text displayed. A3 and A4 are not used. Value is what
8665 resize_mini_window returns. */
8668 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8670 Lisp_Object exactly
;
8673 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8677 /* Resize mini-window W to fit the size of its contents. EXACT_P
8678 means size the window exactly to the size needed. Otherwise, it's
8679 only enlarged until W's buffer is empty.
8681 Set W->start to the right place to begin display. If the whole
8682 contents fit, start at the beginning. Otherwise, start so as
8683 to make the end of the contents appear. This is particularly
8684 important for y-or-n-p, but seems desirable generally.
8686 Value is non-zero if the window height has been changed. */
8689 resize_mini_window (w
, exact_p
)
8693 struct frame
*f
= XFRAME (w
->frame
);
8694 int window_height_changed_p
= 0;
8696 xassert (MINI_WINDOW_P (w
));
8698 /* By default, start display at the beginning. */
8699 set_marker_both (w
->start
, w
->buffer
,
8700 BUF_BEGV (XBUFFER (w
->buffer
)),
8701 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8703 /* Don't resize windows while redisplaying a window; it would
8704 confuse redisplay functions when the size of the window they are
8705 displaying changes from under them. Such a resizing can happen,
8706 for instance, when which-func prints a long message while
8707 we are running fontification-functions. We're running these
8708 functions with safe_call which binds inhibit-redisplay to t. */
8709 if (!NILP (Vinhibit_redisplay
))
8712 /* Nil means don't try to resize. */
8713 if (NILP (Vresize_mini_windows
)
8714 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8717 if (!FRAME_MINIBUF_ONLY_P (f
))
8720 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8721 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8722 int height
, max_height
;
8723 int unit
= FRAME_LINE_HEIGHT (f
);
8724 struct text_pos start
;
8725 struct buffer
*old_current_buffer
= NULL
;
8727 if (current_buffer
!= XBUFFER (w
->buffer
))
8729 old_current_buffer
= current_buffer
;
8730 set_buffer_internal (XBUFFER (w
->buffer
));
8733 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8735 /* Compute the max. number of lines specified by the user. */
8736 if (FLOATP (Vmax_mini_window_height
))
8737 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8738 else if (INTEGERP (Vmax_mini_window_height
))
8739 max_height
= XINT (Vmax_mini_window_height
);
8741 max_height
= total_height
/ 4;
8743 /* Correct that max. height if it's bogus. */
8744 max_height
= max (1, max_height
);
8745 max_height
= min (total_height
, max_height
);
8747 /* Find out the height of the text in the window. */
8748 if (it
.line_wrap
== TRUNCATE
)
8753 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8754 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8755 height
= it
.current_y
+ last_height
;
8757 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8758 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8759 height
= (height
+ unit
- 1) / unit
;
8762 /* Compute a suitable window start. */
8763 if (height
> max_height
)
8765 height
= max_height
;
8766 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8767 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8768 start
= it
.current
.pos
;
8771 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8772 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8774 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8776 /* Let it grow only, until we display an empty message, in which
8777 case the window shrinks again. */
8778 if (height
> WINDOW_TOTAL_LINES (w
))
8780 int old_height
= WINDOW_TOTAL_LINES (w
);
8781 freeze_window_starts (f
, 1);
8782 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8783 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8785 else if (height
< WINDOW_TOTAL_LINES (w
)
8786 && (exact_p
|| BEGV
== ZV
))
8788 int old_height
= WINDOW_TOTAL_LINES (w
);
8789 freeze_window_starts (f
, 0);
8790 shrink_mini_window (w
);
8791 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8796 /* Always resize to exact size needed. */
8797 if (height
> WINDOW_TOTAL_LINES (w
))
8799 int old_height
= WINDOW_TOTAL_LINES (w
);
8800 freeze_window_starts (f
, 1);
8801 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8802 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8804 else if (height
< WINDOW_TOTAL_LINES (w
))
8806 int old_height
= WINDOW_TOTAL_LINES (w
);
8807 freeze_window_starts (f
, 0);
8808 shrink_mini_window (w
);
8812 freeze_window_starts (f
, 1);
8813 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8816 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8820 if (old_current_buffer
)
8821 set_buffer_internal (old_current_buffer
);
8824 return window_height_changed_p
;
8828 /* Value is the current message, a string, or nil if there is no
8836 if (!BUFFERP (echo_area_buffer
[0]))
8840 with_echo_area_buffer (0, 0, current_message_1
,
8841 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8843 echo_area_buffer
[0] = Qnil
;
8851 current_message_1 (a1
, a2
, a3
, a4
)
8856 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8859 *msg
= make_buffer_string (BEG
, Z
, 1);
8866 /* Push the current message on Vmessage_stack for later restauration
8867 by restore_message. Value is non-zero if the current message isn't
8868 empty. This is a relatively infrequent operation, so it's not
8869 worth optimizing. */
8875 msg
= current_message ();
8876 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8877 return STRINGP (msg
);
8881 /* Restore message display from the top of Vmessage_stack. */
8888 xassert (CONSP (Vmessage_stack
));
8889 msg
= XCAR (Vmessage_stack
);
8891 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8893 message3_nolog (msg
, 0, 0);
8897 /* Handler for record_unwind_protect calling pop_message. */
8900 pop_message_unwind (dummy
)
8907 /* Pop the top-most entry off Vmessage_stack. */
8912 xassert (CONSP (Vmessage_stack
));
8913 Vmessage_stack
= XCDR (Vmessage_stack
);
8917 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8918 exits. If the stack is not empty, we have a missing pop_message
8922 check_message_stack ()
8924 if (!NILP (Vmessage_stack
))
8929 /* Truncate to NCHARS what will be displayed in the echo area the next
8930 time we display it---but don't redisplay it now. */
8933 truncate_echo_area (nchars
)
8937 echo_area_buffer
[0] = Qnil
;
8938 /* A null message buffer means that the frame hasn't really been
8939 initialized yet. Error messages get reported properly by
8940 cmd_error, so this must be just an informative message; toss it. */
8941 else if (!noninteractive
8943 && !NILP (echo_area_buffer
[0]))
8945 struct frame
*sf
= SELECTED_FRAME ();
8946 if (FRAME_MESSAGE_BUF (sf
))
8947 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8952 /* Helper function for truncate_echo_area. Truncate the current
8953 message to at most NCHARS characters. */
8956 truncate_message_1 (nchars
, a2
, a3
, a4
)
8961 if (BEG
+ nchars
< Z
)
8962 del_range (BEG
+ nchars
, Z
);
8964 echo_area_buffer
[0] = Qnil
;
8969 /* Set the current message to a substring of S or STRING.
8971 If STRING is a Lisp string, set the message to the first NBYTES
8972 bytes from STRING. NBYTES zero means use the whole string. If
8973 STRING is multibyte, the message will be displayed multibyte.
8975 If S is not null, set the message to the first LEN bytes of S. LEN
8976 zero means use the whole string. MULTIBYTE_P non-zero means S is
8977 multibyte. Display the message multibyte in that case.
8979 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8980 to t before calling set_message_1 (which calls insert).
8984 set_message (s
, string
, nbytes
, multibyte_p
)
8987 int nbytes
, multibyte_p
;
8989 message_enable_multibyte
8990 = ((s
&& multibyte_p
)
8991 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8993 with_echo_area_buffer (0, -1, set_message_1
,
8994 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8995 message_buf_print
= 0;
8996 help_echo_showing_p
= 0;
9000 /* Helper function for set_message. Arguments have the same meaning
9001 as there, with A1 corresponding to S and A2 corresponding to STRING
9002 This function is called with the echo area buffer being
9006 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9009 EMACS_INT nbytes
, multibyte_p
;
9011 const char *s
= (const char *) a1
;
9012 Lisp_Object string
= a2
;
9014 /* Change multibyteness of the echo buffer appropriately. */
9015 if (message_enable_multibyte
9016 != !NILP (current_buffer
->enable_multibyte_characters
))
9017 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9019 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9021 /* Insert new message at BEG. */
9022 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9024 if (STRINGP (string
))
9029 nbytes
= SBYTES (string
);
9030 nchars
= string_byte_to_char (string
, nbytes
);
9032 /* This function takes care of single/multibyte conversion. We
9033 just have to ensure that the echo area buffer has the right
9034 setting of enable_multibyte_characters. */
9035 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9040 nbytes
= strlen (s
);
9042 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9044 /* Convert from multi-byte to single-byte. */
9046 unsigned char work
[1];
9048 /* Convert a multibyte string to single-byte. */
9049 for (i
= 0; i
< nbytes
; i
+= n
)
9051 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
9052 work
[0] = (ASCII_CHAR_P (c
)
9054 : multibyte_char_to_unibyte (c
, Qnil
));
9055 insert_1_both (work
, 1, 1, 1, 0, 0);
9058 else if (!multibyte_p
9059 && !NILP (current_buffer
->enable_multibyte_characters
))
9061 /* Convert from single-byte to multi-byte. */
9063 const unsigned char *msg
= (const unsigned char *) s
;
9064 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9066 /* Convert a single-byte string to multibyte. */
9067 for (i
= 0; i
< nbytes
; i
++)
9070 c
= unibyte_char_to_multibyte (c
);
9071 n
= CHAR_STRING (c
, str
);
9072 insert_1_both (str
, 1, n
, 1, 0, 0);
9076 insert_1 (s
, nbytes
, 1, 0, 0);
9083 /* Clear messages. CURRENT_P non-zero means clear the current
9084 message. LAST_DISPLAYED_P non-zero means clear the message
9088 clear_message (current_p
, last_displayed_p
)
9089 int current_p
, last_displayed_p
;
9093 echo_area_buffer
[0] = Qnil
;
9094 message_cleared_p
= 1;
9097 if (last_displayed_p
)
9098 echo_area_buffer
[1] = Qnil
;
9100 message_buf_print
= 0;
9103 /* Clear garbaged frames.
9105 This function is used where the old redisplay called
9106 redraw_garbaged_frames which in turn called redraw_frame which in
9107 turn called clear_frame. The call to clear_frame was a source of
9108 flickering. I believe a clear_frame is not necessary. It should
9109 suffice in the new redisplay to invalidate all current matrices,
9110 and ensure a complete redisplay of all windows. */
9113 clear_garbaged_frames ()
9117 Lisp_Object tail
, frame
;
9118 int changed_count
= 0;
9120 FOR_EACH_FRAME (tail
, frame
)
9122 struct frame
*f
= XFRAME (frame
);
9124 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9128 Fredraw_frame (frame
);
9129 f
->force_flush_display_p
= 1;
9131 clear_current_matrices (f
);
9140 ++windows_or_buffers_changed
;
9145 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9146 is non-zero update selected_frame. Value is non-zero if the
9147 mini-windows height has been changed. */
9150 echo_area_display (update_frame_p
)
9153 Lisp_Object mini_window
;
9156 int window_height_changed_p
= 0;
9157 struct frame
*sf
= SELECTED_FRAME ();
9159 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9160 w
= XWINDOW (mini_window
);
9161 f
= XFRAME (WINDOW_FRAME (w
));
9163 /* Don't display if frame is invisible or not yet initialized. */
9164 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9167 #ifdef HAVE_WINDOW_SYSTEM
9168 /* When Emacs starts, selected_frame may be the initial terminal
9169 frame. If we let this through, a message would be displayed on
9171 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9173 #endif /* HAVE_WINDOW_SYSTEM */
9175 /* Redraw garbaged frames. */
9177 clear_garbaged_frames ();
9179 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9181 echo_area_window
= mini_window
;
9182 window_height_changed_p
= display_echo_area (w
);
9183 w
->must_be_updated_p
= 1;
9185 /* Update the display, unless called from redisplay_internal.
9186 Also don't update the screen during redisplay itself. The
9187 update will happen at the end of redisplay, and an update
9188 here could cause confusion. */
9189 if (update_frame_p
&& !redisplaying_p
)
9193 /* If the display update has been interrupted by pending
9194 input, update mode lines in the frame. Due to the
9195 pending input, it might have been that redisplay hasn't
9196 been called, so that mode lines above the echo area are
9197 garbaged. This looks odd, so we prevent it here. */
9198 if (!display_completed
)
9199 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9201 if (window_height_changed_p
9202 /* Don't do this if Emacs is shutting down. Redisplay
9203 needs to run hooks. */
9204 && !NILP (Vrun_hooks
))
9206 /* Must update other windows. Likewise as in other
9207 cases, don't let this update be interrupted by
9209 int count
= SPECPDL_INDEX ();
9210 specbind (Qredisplay_dont_pause
, Qt
);
9211 windows_or_buffers_changed
= 1;
9212 redisplay_internal (0);
9213 unbind_to (count
, Qnil
);
9215 else if (FRAME_WINDOW_P (f
) && n
== 0)
9217 /* Window configuration is the same as before.
9218 Can do with a display update of the echo area,
9219 unless we displayed some mode lines. */
9220 update_single_window (w
, 1);
9221 FRAME_RIF (f
)->flush_display (f
);
9224 update_frame (f
, 1, 1);
9226 /* If cursor is in the echo area, make sure that the next
9227 redisplay displays the minibuffer, so that the cursor will
9228 be replaced with what the minibuffer wants. */
9229 if (cursor_in_echo_area
)
9230 ++windows_or_buffers_changed
;
9233 else if (!EQ (mini_window
, selected_window
))
9234 windows_or_buffers_changed
++;
9236 /* Last displayed message is now the current message. */
9237 echo_area_buffer
[1] = echo_area_buffer
[0];
9238 /* Inform read_char that we're not echoing. */
9239 echo_message_buffer
= Qnil
;
9241 /* Prevent redisplay optimization in redisplay_internal by resetting
9242 this_line_start_pos. This is done because the mini-buffer now
9243 displays the message instead of its buffer text. */
9244 if (EQ (mini_window
, selected_window
))
9245 CHARPOS (this_line_start_pos
) = 0;
9247 return window_height_changed_p
;
9252 /***********************************************************************
9253 Mode Lines and Frame Titles
9254 ***********************************************************************/
9256 /* A buffer for constructing non-propertized mode-line strings and
9257 frame titles in it; allocated from the heap in init_xdisp and
9258 resized as needed in store_mode_line_noprop_char. */
9260 static char *mode_line_noprop_buf
;
9262 /* The buffer's end, and a current output position in it. */
9264 static char *mode_line_noprop_buf_end
;
9265 static char *mode_line_noprop_ptr
;
9267 #define MODE_LINE_NOPROP_LEN(start) \
9268 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9271 MODE_LINE_DISPLAY
= 0,
9277 /* Alist that caches the results of :propertize.
9278 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9279 static Lisp_Object mode_line_proptrans_alist
;
9281 /* List of strings making up the mode-line. */
9282 static Lisp_Object mode_line_string_list
;
9284 /* Base face property when building propertized mode line string. */
9285 static Lisp_Object mode_line_string_face
;
9286 static Lisp_Object mode_line_string_face_prop
;
9289 /* Unwind data for mode line strings */
9291 static Lisp_Object Vmode_line_unwind_vector
;
9294 format_mode_line_unwind_data (struct buffer
*obuf
,
9298 Lisp_Object vector
, tmp
;
9300 /* Reduce consing by keeping one vector in
9301 Vwith_echo_area_save_vector. */
9302 vector
= Vmode_line_unwind_vector
;
9303 Vmode_line_unwind_vector
= Qnil
;
9306 vector
= Fmake_vector (make_number (8), Qnil
);
9308 ASET (vector
, 0, make_number (mode_line_target
));
9309 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9310 ASET (vector
, 2, mode_line_string_list
);
9311 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9312 ASET (vector
, 4, mode_line_string_face
);
9313 ASET (vector
, 5, mode_line_string_face_prop
);
9316 XSETBUFFER (tmp
, obuf
);
9319 ASET (vector
, 6, tmp
);
9320 ASET (vector
, 7, owin
);
9326 unwind_format_mode_line (vector
)
9329 mode_line_target
= XINT (AREF (vector
, 0));
9330 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9331 mode_line_string_list
= AREF (vector
, 2);
9332 if (! EQ (AREF (vector
, 3), Qt
))
9333 mode_line_proptrans_alist
= AREF (vector
, 3);
9334 mode_line_string_face
= AREF (vector
, 4);
9335 mode_line_string_face_prop
= AREF (vector
, 5);
9337 if (!NILP (AREF (vector
, 7)))
9338 /* Select window before buffer, since it may change the buffer. */
9339 Fselect_window (AREF (vector
, 7), Qt
);
9341 if (!NILP (AREF (vector
, 6)))
9343 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9344 ASET (vector
, 6, Qnil
);
9347 Vmode_line_unwind_vector
= vector
;
9352 /* Store a single character C for the frame title in mode_line_noprop_buf.
9353 Re-allocate mode_line_noprop_buf if necessary. */
9357 store_mode_line_noprop_char (char c
)
9359 store_mode_line_noprop_char (c
)
9363 /* If output position has reached the end of the allocated buffer,
9364 double the buffer's size. */
9365 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9367 int len
= MODE_LINE_NOPROP_LEN (0);
9368 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9369 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9370 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9371 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9374 *mode_line_noprop_ptr
++ = c
;
9378 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9379 mode_line_noprop_ptr. STR is the string to store. Do not copy
9380 characters that yield more columns than PRECISION; PRECISION <= 0
9381 means copy the whole string. Pad with spaces until FIELD_WIDTH
9382 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9383 pad. Called from display_mode_element when it is used to build a
9387 store_mode_line_noprop (str
, field_width
, precision
)
9388 const unsigned char *str
;
9389 int field_width
, precision
;
9394 /* Copy at most PRECISION chars from STR. */
9395 nbytes
= strlen (str
);
9396 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9398 store_mode_line_noprop_char (*str
++);
9400 /* Fill up with spaces until FIELD_WIDTH reached. */
9401 while (field_width
> 0
9404 store_mode_line_noprop_char (' ');
9411 /***********************************************************************
9413 ***********************************************************************/
9415 #ifdef HAVE_WINDOW_SYSTEM
9417 /* Set the title of FRAME, if it has changed. The title format is
9418 Vicon_title_format if FRAME is iconified, otherwise it is
9419 frame_title_format. */
9422 x_consider_frame_title (frame
)
9425 struct frame
*f
= XFRAME (frame
);
9427 if (FRAME_WINDOW_P (f
)
9428 || FRAME_MINIBUF_ONLY_P (f
)
9429 || f
->explicit_name
)
9431 /* Do we have more than one visible frame on this X display? */
9438 int count
= SPECPDL_INDEX ();
9440 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9442 Lisp_Object other_frame
= XCAR (tail
);
9443 struct frame
*tf
= XFRAME (other_frame
);
9446 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9447 && !FRAME_MINIBUF_ONLY_P (tf
)
9448 && !EQ (other_frame
, tip_frame
)
9449 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9453 /* Set global variable indicating that multiple frames exist. */
9454 multiple_frames
= CONSP (tail
);
9456 /* Switch to the buffer of selected window of the frame. Set up
9457 mode_line_target so that display_mode_element will output into
9458 mode_line_noprop_buf; then display the title. */
9459 record_unwind_protect (unwind_format_mode_line
,
9460 format_mode_line_unwind_data
9461 (current_buffer
, selected_window
, 0));
9463 Fselect_window (f
->selected_window
, Qt
);
9464 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9465 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9467 mode_line_target
= MODE_LINE_TITLE
;
9468 title_start
= MODE_LINE_NOPROP_LEN (0);
9469 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9470 NULL
, DEFAULT_FACE_ID
);
9471 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9472 len
= MODE_LINE_NOPROP_LEN (title_start
);
9473 title
= mode_line_noprop_buf
+ title_start
;
9474 unbind_to (count
, Qnil
);
9476 /* Set the title only if it's changed. This avoids consing in
9477 the common case where it hasn't. (If it turns out that we've
9478 already wasted too much time by walking through the list with
9479 display_mode_element, then we might need to optimize at a
9480 higher level than this.) */
9481 if (! STRINGP (f
->name
)
9482 || SBYTES (f
->name
) != len
9483 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9488 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9491 ns_set_name_as_filename (f
);
9493 x_implicitly_set_name (f
, make_string(title
, len
),
9499 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9504 /* do this also for frames with explicit names */
9505 ns_implicitly_set_icon_type(f
);
9506 ns_set_doc_edited(f
, Fbuffer_modified_p
9507 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9513 #endif /* not HAVE_WINDOW_SYSTEM */
9518 /***********************************************************************
9520 ***********************************************************************/
9523 /* Prepare for redisplay by updating menu-bar item lists when
9524 appropriate. This can call eval. */
9527 prepare_menu_bars ()
9530 struct gcpro gcpro1
, gcpro2
;
9532 Lisp_Object tooltip_frame
;
9534 #ifdef HAVE_WINDOW_SYSTEM
9535 tooltip_frame
= tip_frame
;
9537 tooltip_frame
= Qnil
;
9540 /* Update all frame titles based on their buffer names, etc. We do
9541 this before the menu bars so that the buffer-menu will show the
9542 up-to-date frame titles. */
9543 #ifdef HAVE_WINDOW_SYSTEM
9544 if (windows_or_buffers_changed
|| update_mode_lines
)
9546 Lisp_Object tail
, frame
;
9548 FOR_EACH_FRAME (tail
, frame
)
9551 if (!EQ (frame
, tooltip_frame
)
9552 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9553 x_consider_frame_title (frame
);
9556 #endif /* HAVE_WINDOW_SYSTEM */
9558 /* Update the menu bar item lists, if appropriate. This has to be
9559 done before any actual redisplay or generation of display lines. */
9560 all_windows
= (update_mode_lines
9561 || buffer_shared
> 1
9562 || windows_or_buffers_changed
);
9565 Lisp_Object tail
, frame
;
9566 int count
= SPECPDL_INDEX ();
9567 /* 1 means that update_menu_bar has run its hooks
9568 so any further calls to update_menu_bar shouldn't do so again. */
9569 int menu_bar_hooks_run
= 0;
9571 record_unwind_save_match_data ();
9573 FOR_EACH_FRAME (tail
, frame
)
9577 /* Ignore tooltip frame. */
9578 if (EQ (frame
, tooltip_frame
))
9581 /* If a window on this frame changed size, report that to
9582 the user and clear the size-change flag. */
9583 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9585 Lisp_Object functions
;
9587 /* Clear flag first in case we get an error below. */
9588 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9589 functions
= Vwindow_size_change_functions
;
9590 GCPRO2 (tail
, functions
);
9592 while (CONSP (functions
))
9594 call1 (XCAR (functions
), frame
);
9595 functions
= XCDR (functions
);
9601 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9602 #ifdef HAVE_WINDOW_SYSTEM
9603 update_tool_bar (f
, 0);
9608 unbind_to (count
, Qnil
);
9612 struct frame
*sf
= SELECTED_FRAME ();
9613 update_menu_bar (sf
, 1, 0);
9614 #ifdef HAVE_WINDOW_SYSTEM
9615 update_tool_bar (sf
, 1);
9619 /* Motif needs this. See comment in xmenu.c. Turn it off when
9620 pending_menu_activation is not defined. */
9621 #ifdef USE_X_TOOLKIT
9622 pending_menu_activation
= 0;
9627 /* Update the menu bar item list for frame F. This has to be done
9628 before we start to fill in any display lines, because it can call
9631 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9633 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9634 already ran the menu bar hooks for this redisplay, so there
9635 is no need to run them again. The return value is the
9636 updated value of this flag, to pass to the next call. */
9639 update_menu_bar (f
, save_match_data
, hooks_run
)
9641 int save_match_data
;
9645 register struct window
*w
;
9647 /* If called recursively during a menu update, do nothing. This can
9648 happen when, for instance, an activate-menubar-hook causes a
9650 if (inhibit_menubar_update
)
9653 window
= FRAME_SELECTED_WINDOW (f
);
9654 w
= XWINDOW (window
);
9656 if (FRAME_WINDOW_P (f
)
9658 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9659 || defined (HAVE_NS) || defined (USE_GTK)
9660 FRAME_EXTERNAL_MENU_BAR (f
)
9662 FRAME_MENU_BAR_LINES (f
) > 0
9664 : FRAME_MENU_BAR_LINES (f
) > 0)
9666 /* If the user has switched buffers or windows, we need to
9667 recompute to reflect the new bindings. But we'll
9668 recompute when update_mode_lines is set too; that means
9669 that people can use force-mode-line-update to request
9670 that the menu bar be recomputed. The adverse effect on
9671 the rest of the redisplay algorithm is about the same as
9672 windows_or_buffers_changed anyway. */
9673 if (windows_or_buffers_changed
9674 /* This used to test w->update_mode_line, but we believe
9675 there is no need to recompute the menu in that case. */
9676 || update_mode_lines
9677 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9678 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9679 != !NILP (w
->last_had_star
))
9680 || ((!NILP (Vtransient_mark_mode
)
9681 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9682 != !NILP (w
->region_showing
)))
9684 struct buffer
*prev
= current_buffer
;
9685 int count
= SPECPDL_INDEX ();
9687 specbind (Qinhibit_menubar_update
, Qt
);
9689 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9690 if (save_match_data
)
9691 record_unwind_save_match_data ();
9692 if (NILP (Voverriding_local_map_menu_flag
))
9694 specbind (Qoverriding_terminal_local_map
, Qnil
);
9695 specbind (Qoverriding_local_map
, Qnil
);
9700 /* Run the Lucid hook. */
9701 safe_run_hooks (Qactivate_menubar_hook
);
9703 /* If it has changed current-menubar from previous value,
9704 really recompute the menu-bar from the value. */
9705 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9706 call0 (Qrecompute_lucid_menubar
);
9708 safe_run_hooks (Qmenu_bar_update_hook
);
9713 XSETFRAME (Vmenu_updating_frame
, f
);
9714 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9716 /* Redisplay the menu bar in case we changed it. */
9717 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9718 || defined (HAVE_NS) || defined (USE_GTK)
9719 if (FRAME_WINDOW_P (f
))
9721 #if defined (HAVE_NS)
9722 /* All frames on Mac OS share the same menubar. So only
9723 the selected frame should be allowed to set it. */
9724 if (f
== SELECTED_FRAME ())
9726 set_frame_menubar (f
, 0, 0);
9729 /* On a terminal screen, the menu bar is an ordinary screen
9730 line, and this makes it get updated. */
9731 w
->update_mode_line
= Qt
;
9732 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9733 /* In the non-toolkit version, the menu bar is an ordinary screen
9734 line, and this makes it get updated. */
9735 w
->update_mode_line
= Qt
;
9736 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9738 unbind_to (count
, Qnil
);
9739 set_buffer_internal_1 (prev
);
9748 /***********************************************************************
9750 ***********************************************************************/
9752 #ifdef HAVE_WINDOW_SYSTEM
9755 Nominal cursor position -- where to draw output.
9756 HPOS and VPOS are window relative glyph matrix coordinates.
9757 X and Y are window relative pixel coordinates. */
9759 struct cursor_pos output_cursor
;
9763 Set the global variable output_cursor to CURSOR. All cursor
9764 positions are relative to updated_window. */
9767 set_output_cursor (cursor
)
9768 struct cursor_pos
*cursor
;
9770 output_cursor
.hpos
= cursor
->hpos
;
9771 output_cursor
.vpos
= cursor
->vpos
;
9772 output_cursor
.x
= cursor
->x
;
9773 output_cursor
.y
= cursor
->y
;
9778 Set a nominal cursor position.
9780 HPOS and VPOS are column/row positions in a window glyph matrix. X
9781 and Y are window text area relative pixel positions.
9783 If this is done during an update, updated_window will contain the
9784 window that is being updated and the position is the future output
9785 cursor position for that window. If updated_window is null, use
9786 selected_window and display the cursor at the given position. */
9789 x_cursor_to (vpos
, hpos
, y
, x
)
9790 int vpos
, hpos
, y
, x
;
9794 /* If updated_window is not set, work on selected_window. */
9798 w
= XWINDOW (selected_window
);
9800 /* Set the output cursor. */
9801 output_cursor
.hpos
= hpos
;
9802 output_cursor
.vpos
= vpos
;
9803 output_cursor
.x
= x
;
9804 output_cursor
.y
= y
;
9806 /* If not called as part of an update, really display the cursor.
9807 This will also set the cursor position of W. */
9808 if (updated_window
== NULL
)
9811 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9812 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9813 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9818 #endif /* HAVE_WINDOW_SYSTEM */
9821 /***********************************************************************
9823 ***********************************************************************/
9825 #ifdef HAVE_WINDOW_SYSTEM
9827 /* Where the mouse was last time we reported a mouse event. */
9829 FRAME_PTR last_mouse_frame
;
9831 /* Tool-bar item index of the item on which a mouse button was pressed
9834 int last_tool_bar_item
;
9838 update_tool_bar_unwind (frame
)
9841 selected_frame
= frame
;
9845 /* Update the tool-bar item list for frame F. This has to be done
9846 before we start to fill in any display lines. Called from
9847 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9848 and restore it here. */
9851 update_tool_bar (f
, save_match_data
)
9853 int save_match_data
;
9855 #if defined (USE_GTK) || defined (HAVE_NS) || USE_MAC_TOOLBAR
9856 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9858 int do_update
= WINDOWP (f
->tool_bar_window
)
9859 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9867 window
= FRAME_SELECTED_WINDOW (f
);
9868 w
= XWINDOW (window
);
9870 /* If the user has switched buffers or windows, we need to
9871 recompute to reflect the new bindings. But we'll
9872 recompute when update_mode_lines is set too; that means
9873 that people can use force-mode-line-update to request
9874 that the menu bar be recomputed. The adverse effect on
9875 the rest of the redisplay algorithm is about the same as
9876 windows_or_buffers_changed anyway. */
9877 if (windows_or_buffers_changed
9878 || !NILP (w
->update_mode_line
)
9879 || update_mode_lines
9880 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9881 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9882 != !NILP (w
->last_had_star
))
9883 || ((!NILP (Vtransient_mark_mode
)
9884 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9885 != !NILP (w
->region_showing
)))
9887 struct buffer
*prev
= current_buffer
;
9888 int count
= SPECPDL_INDEX ();
9889 Lisp_Object frame
, new_tool_bar
;
9891 struct gcpro gcpro1
;
9893 /* Set current_buffer to the buffer of the selected
9894 window of the frame, so that we get the right local
9896 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9898 /* Save match data, if we must. */
9899 if (save_match_data
)
9900 record_unwind_save_match_data ();
9902 /* Make sure that we don't accidentally use bogus keymaps. */
9903 if (NILP (Voverriding_local_map_menu_flag
))
9905 specbind (Qoverriding_terminal_local_map
, Qnil
);
9906 specbind (Qoverriding_local_map
, Qnil
);
9909 GCPRO1 (new_tool_bar
);
9911 /* We must temporarily set the selected frame to this frame
9912 before calling tool_bar_items, because the calculation of
9913 the tool-bar keymap uses the selected frame (see
9914 `tool-bar-make-keymap' in tool-bar.el). */
9915 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
9916 XSETFRAME (frame
, f
);
9917 selected_frame
= frame
;
9919 /* Build desired tool-bar items from keymaps. */
9920 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9923 /* Redisplay the tool-bar if we changed it. */
9924 if (new_n_tool_bar
!= f
->n_tool_bar_items
9925 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9927 /* Redisplay that happens asynchronously due to an expose event
9928 may access f->tool_bar_items. Make sure we update both
9929 variables within BLOCK_INPUT so no such event interrupts. */
9931 f
->tool_bar_items
= new_tool_bar
;
9932 f
->n_tool_bar_items
= new_n_tool_bar
;
9933 w
->update_mode_line
= Qt
;
9939 unbind_to (count
, Qnil
);
9940 set_buffer_internal_1 (prev
);
9946 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9947 F's desired tool-bar contents. F->tool_bar_items must have
9948 been set up previously by calling prepare_menu_bars. */
9951 build_desired_tool_bar_string (f
)
9954 int i
, size
, size_needed
;
9955 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9956 Lisp_Object image
, plist
, props
;
9958 image
= plist
= props
= Qnil
;
9959 GCPRO3 (image
, plist
, props
);
9961 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9962 Otherwise, make a new string. */
9964 /* The size of the string we might be able to reuse. */
9965 size
= (STRINGP (f
->desired_tool_bar_string
)
9966 ? SCHARS (f
->desired_tool_bar_string
)
9969 /* We need one space in the string for each image. */
9970 size_needed
= f
->n_tool_bar_items
;
9972 /* Reuse f->desired_tool_bar_string, if possible. */
9973 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9974 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9978 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9979 Fremove_text_properties (make_number (0), make_number (size
),
9980 props
, f
->desired_tool_bar_string
);
9983 /* Put a `display' property on the string for the images to display,
9984 put a `menu_item' property on tool-bar items with a value that
9985 is the index of the item in F's tool-bar item vector. */
9986 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9988 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9990 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9991 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9992 int hmargin
, vmargin
, relief
, idx
, end
;
9993 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9995 /* If image is a vector, choose the image according to the
9997 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9998 if (VECTORP (image
))
10002 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10003 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10006 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10007 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10009 xassert (ASIZE (image
) >= idx
);
10010 image
= AREF (image
, idx
);
10015 /* Ignore invalid image specifications. */
10016 if (!valid_image_p (image
))
10019 /* Display the tool-bar button pressed, or depressed. */
10020 plist
= Fcopy_sequence (XCDR (image
));
10022 /* Compute margin and relief to draw. */
10023 relief
= (tool_bar_button_relief
>= 0
10024 ? tool_bar_button_relief
10025 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10026 hmargin
= vmargin
= relief
;
10028 if (INTEGERP (Vtool_bar_button_margin
)
10029 && XINT (Vtool_bar_button_margin
) > 0)
10031 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10032 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10034 else if (CONSP (Vtool_bar_button_margin
))
10036 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10037 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10038 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10040 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10041 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10042 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10045 if (auto_raise_tool_bar_buttons_p
)
10047 /* Add a `:relief' property to the image spec if the item is
10051 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10058 /* If image is selected, display it pressed, i.e. with a
10059 negative relief. If it's not selected, display it with a
10061 plist
= Fplist_put (plist
, QCrelief
,
10063 ? make_number (-relief
)
10064 : make_number (relief
)));
10069 /* Put a margin around the image. */
10070 if (hmargin
|| vmargin
)
10072 if (hmargin
== vmargin
)
10073 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10075 plist
= Fplist_put (plist
, QCmargin
,
10076 Fcons (make_number (hmargin
),
10077 make_number (vmargin
)));
10080 /* If button is not enabled, and we don't have special images
10081 for the disabled state, make the image appear disabled by
10082 applying an appropriate algorithm to it. */
10083 if (!enabled_p
&& idx
< 0)
10084 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10086 /* Put a `display' text property on the string for the image to
10087 display. Put a `menu-item' property on the string that gives
10088 the start of this item's properties in the tool-bar items
10090 image
= Fcons (Qimage
, plist
);
10091 props
= list4 (Qdisplay
, image
,
10092 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10094 /* Let the last image hide all remaining spaces in the tool bar
10095 string. The string can be longer than needed when we reuse a
10096 previous string. */
10097 if (i
+ 1 == f
->n_tool_bar_items
)
10098 end
= SCHARS (f
->desired_tool_bar_string
);
10101 Fadd_text_properties (make_number (i
), make_number (end
),
10102 props
, f
->desired_tool_bar_string
);
10110 /* Display one line of the tool-bar of frame IT->f.
10112 HEIGHT specifies the desired height of the tool-bar line.
10113 If the actual height of the glyph row is less than HEIGHT, the
10114 row's height is increased to HEIGHT, and the icons are centered
10115 vertically in the new height.
10117 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10118 count a final empty row in case the tool-bar width exactly matches
10123 display_tool_bar_line (it
, height
)
10127 struct glyph_row
*row
= it
->glyph_row
;
10128 int max_x
= it
->last_visible_x
;
10129 struct glyph
*last
;
10131 prepare_desired_row (row
);
10132 row
->y
= it
->current_y
;
10134 /* Note that this isn't made use of if the face hasn't a box,
10135 so there's no need to check the face here. */
10136 it
->start_of_box_run_p
= 1;
10138 while (it
->current_x
< max_x
)
10140 int x
, n_glyphs_before
, i
, nglyphs
;
10141 struct it it_before
;
10143 /* Get the next display element. */
10144 if (!get_next_display_element (it
))
10146 /* Don't count empty row if we are counting needed tool-bar lines. */
10147 if (height
< 0 && !it
->hpos
)
10152 /* Produce glyphs. */
10153 n_glyphs_before
= row
->used
[TEXT_AREA
];
10156 PRODUCE_GLYPHS (it
);
10158 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10160 x
= it_before
.current_x
;
10161 while (i
< nglyphs
)
10163 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10165 if (x
+ glyph
->pixel_width
> max_x
)
10167 /* Glyph doesn't fit on line. Backtrack. */
10168 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10170 /* If this is the only glyph on this line, it will never fit on the
10171 toolbar, so skip it. But ensure there is at least one glyph,
10172 so we don't accidentally disable the tool-bar. */
10173 if (n_glyphs_before
== 0
10174 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10180 x
+= glyph
->pixel_width
;
10184 /* Stop at line ends. */
10185 if (ITERATOR_AT_END_OF_LINE_P (it
))
10188 set_iterator_to_next (it
, 1);
10193 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10195 /* Use default face for the border below the tool bar.
10197 FIXME: When auto-resize-tool-bars is grow-only, there is
10198 no additional border below the possibly empty tool-bar lines.
10199 So to make the extra empty lines look "normal", we have to
10200 use the tool-bar face for the border too. */
10201 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10202 it
->face_id
= DEFAULT_FACE_ID
;
10204 extend_face_to_end_of_line (it
);
10205 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10206 last
->right_box_line_p
= 1;
10207 if (last
== row
->glyphs
[TEXT_AREA
])
10208 last
->left_box_line_p
= 1;
10210 /* Make line the desired height and center it vertically. */
10211 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10213 /* Don't add more than one line height. */
10214 height
%= FRAME_LINE_HEIGHT (it
->f
);
10215 it
->max_ascent
+= height
/ 2;
10216 it
->max_descent
+= (height
+ 1) / 2;
10219 compute_line_metrics (it
);
10221 /* If line is empty, make it occupy the rest of the tool-bar. */
10222 if (!row
->displays_text_p
)
10224 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10225 row
->visible_height
= row
->height
;
10226 row
->ascent
= row
->phys_ascent
= 0;
10227 row
->extra_line_spacing
= 0;
10230 row
->full_width_p
= 1;
10231 row
->continued_p
= 0;
10232 row
->truncated_on_left_p
= 0;
10233 row
->truncated_on_right_p
= 0;
10235 it
->current_x
= it
->hpos
= 0;
10236 it
->current_y
+= row
->height
;
10242 /* Max tool-bar height. */
10244 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10245 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10247 /* Value is the number of screen lines needed to make all tool-bar
10248 items of frame F visible. The number of actual rows needed is
10249 returned in *N_ROWS if non-NULL. */
10252 tool_bar_lines_needed (f
, n_rows
)
10256 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10258 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10259 the desired matrix, so use (unused) mode-line row as temporary row to
10260 avoid destroying the first tool-bar row. */
10261 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10263 /* Initialize an iterator for iteration over
10264 F->desired_tool_bar_string in the tool-bar window of frame F. */
10265 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10266 it
.first_visible_x
= 0;
10267 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10268 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10270 while (!ITERATOR_AT_END_P (&it
))
10272 clear_glyph_row (temp_row
);
10273 it
.glyph_row
= temp_row
;
10274 display_tool_bar_line (&it
, -1);
10276 clear_glyph_row (temp_row
);
10278 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10280 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10282 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10286 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10288 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10297 frame
= selected_frame
;
10299 CHECK_FRAME (frame
);
10300 f
= XFRAME (frame
);
10302 if (WINDOWP (f
->tool_bar_window
)
10303 || (w
= XWINDOW (f
->tool_bar_window
),
10304 WINDOW_TOTAL_LINES (w
) > 0))
10306 update_tool_bar (f
, 1);
10307 if (f
->n_tool_bar_items
)
10309 build_desired_tool_bar_string (f
);
10310 nlines
= tool_bar_lines_needed (f
, NULL
);
10314 return make_number (nlines
);
10318 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10319 height should be changed. */
10322 redisplay_tool_bar (f
)
10327 struct glyph_row
*row
;
10329 #if defined (USE_GTK) || defined (HAVE_NS) || USE_MAC_TOOLBAR
10330 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10331 update_frame_tool_bar (f
);
10335 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10336 do anything. This means you must start with tool-bar-lines
10337 non-zero to get the auto-sizing effect. Or in other words, you
10338 can turn off tool-bars by specifying tool-bar-lines zero. */
10339 if (!WINDOWP (f
->tool_bar_window
)
10340 || (w
= XWINDOW (f
->tool_bar_window
),
10341 WINDOW_TOTAL_LINES (w
) == 0))
10344 /* Set up an iterator for the tool-bar window. */
10345 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10346 it
.first_visible_x
= 0;
10347 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10348 row
= it
.glyph_row
;
10350 /* Build a string that represents the contents of the tool-bar. */
10351 build_desired_tool_bar_string (f
);
10352 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10354 if (f
->n_tool_bar_rows
== 0)
10358 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10359 nlines
!= WINDOW_TOTAL_LINES (w
)))
10361 extern Lisp_Object Qtool_bar_lines
;
10363 int old_height
= WINDOW_TOTAL_LINES (w
);
10365 XSETFRAME (frame
, f
);
10366 Fmodify_frame_parameters (frame
,
10367 Fcons (Fcons (Qtool_bar_lines
,
10368 make_number (nlines
)),
10370 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10372 clear_glyph_matrix (w
->desired_matrix
);
10373 fonts_changed_p
= 1;
10379 /* Display as many lines as needed to display all tool-bar items. */
10381 if (f
->n_tool_bar_rows
> 0)
10383 int border
, rows
, height
, extra
;
10385 if (INTEGERP (Vtool_bar_border
))
10386 border
= XINT (Vtool_bar_border
);
10387 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10388 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10389 else if (EQ (Vtool_bar_border
, Qborder_width
))
10390 border
= f
->border_width
;
10396 rows
= f
->n_tool_bar_rows
;
10397 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10398 extra
= it
.last_visible_y
- border
- height
* rows
;
10400 while (it
.current_y
< it
.last_visible_y
)
10403 if (extra
> 0 && rows
-- > 0)
10405 h
= (extra
+ rows
- 1) / rows
;
10408 display_tool_bar_line (&it
, height
+ h
);
10413 while (it
.current_y
< it
.last_visible_y
)
10414 display_tool_bar_line (&it
, 0);
10417 /* It doesn't make much sense to try scrolling in the tool-bar
10418 window, so don't do it. */
10419 w
->desired_matrix
->no_scrolling_p
= 1;
10420 w
->must_be_updated_p
= 1;
10422 if (!NILP (Vauto_resize_tool_bars
))
10424 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10425 int change_height_p
= 0;
10427 /* If we couldn't display everything, change the tool-bar's
10428 height if there is room for more. */
10429 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10430 && it
.current_y
< max_tool_bar_height
)
10431 change_height_p
= 1;
10433 row
= it
.glyph_row
- 1;
10435 /* If there are blank lines at the end, except for a partially
10436 visible blank line at the end that is smaller than
10437 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10438 if (!row
->displays_text_p
10439 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10440 change_height_p
= 1;
10442 /* If row displays tool-bar items, but is partially visible,
10443 change the tool-bar's height. */
10444 if (row
->displays_text_p
10445 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10446 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10447 change_height_p
= 1;
10449 /* Resize windows as needed by changing the `tool-bar-lines'
10450 frame parameter. */
10451 if (change_height_p
)
10453 extern Lisp_Object Qtool_bar_lines
;
10455 int old_height
= WINDOW_TOTAL_LINES (w
);
10457 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10459 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10460 && !f
->minimize_tool_bar_window_p
)
10461 ? (nlines
> old_height
)
10462 : (nlines
!= old_height
));
10463 f
->minimize_tool_bar_window_p
= 0;
10465 if (change_height_p
)
10467 XSETFRAME (frame
, f
);
10468 Fmodify_frame_parameters (frame
,
10469 Fcons (Fcons (Qtool_bar_lines
,
10470 make_number (nlines
)),
10472 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10474 clear_glyph_matrix (w
->desired_matrix
);
10475 f
->n_tool_bar_rows
= nrows
;
10476 fonts_changed_p
= 1;
10483 f
->minimize_tool_bar_window_p
= 0;
10488 /* Get information about the tool-bar item which is displayed in GLYPH
10489 on frame F. Return in *PROP_IDX the index where tool-bar item
10490 properties start in F->tool_bar_items. Value is zero if
10491 GLYPH doesn't display a tool-bar item. */
10494 tool_bar_item_info (f
, glyph
, prop_idx
)
10496 struct glyph
*glyph
;
10503 /* This function can be called asynchronously, which means we must
10504 exclude any possibility that Fget_text_property signals an
10506 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10507 charpos
= max (0, charpos
);
10509 /* Get the text property `menu-item' at pos. The value of that
10510 property is the start index of this item's properties in
10511 F->tool_bar_items. */
10512 prop
= Fget_text_property (make_number (charpos
),
10513 Qmenu_item
, f
->current_tool_bar_string
);
10514 if (INTEGERP (prop
))
10516 *prop_idx
= XINT (prop
);
10526 /* Get information about the tool-bar item at position X/Y on frame F.
10527 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10528 the current matrix of the tool-bar window of F, or NULL if not
10529 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10530 item in F->tool_bar_items. Value is
10532 -1 if X/Y is not on a tool-bar item
10533 0 if X/Y is on the same item that was highlighted before.
10537 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10540 struct glyph
**glyph
;
10541 int *hpos
, *vpos
, *prop_idx
;
10543 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10544 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10547 /* Find the glyph under X/Y. */
10548 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10549 if (*glyph
== NULL
)
10552 /* Get the start of this tool-bar item's properties in
10553 f->tool_bar_items. */
10554 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10557 /* Is mouse on the highlighted item? */
10558 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10559 && *vpos
>= dpyinfo
->mouse_face_beg_row
10560 && *vpos
<= dpyinfo
->mouse_face_end_row
10561 && (*vpos
> dpyinfo
->mouse_face_beg_row
10562 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10563 && (*vpos
< dpyinfo
->mouse_face_end_row
10564 || *hpos
< dpyinfo
->mouse_face_end_col
10565 || dpyinfo
->mouse_face_past_end
))
10573 Handle mouse button event on the tool-bar of frame F, at
10574 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10575 0 for button release. MODIFIERS is event modifiers for button
10579 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10582 unsigned int modifiers
;
10584 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10585 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10586 int hpos
, vpos
, prop_idx
;
10587 struct glyph
*glyph
;
10588 Lisp_Object enabled_p
;
10590 /* If not on the highlighted tool-bar item, return. */
10591 frame_to_window_pixel_xy (w
, &x
, &y
);
10592 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10595 /* If item is disabled, do nothing. */
10596 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10597 if (NILP (enabled_p
))
10602 /* Show item in pressed state. */
10603 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10604 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10605 last_tool_bar_item
= prop_idx
;
10609 Lisp_Object key
, frame
;
10610 struct input_event event
;
10611 EVENT_INIT (event
);
10613 /* Show item in released state. */
10614 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10615 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10617 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10619 XSETFRAME (frame
, f
);
10620 event
.kind
= TOOL_BAR_EVENT
;
10621 event
.frame_or_window
= frame
;
10623 kbd_buffer_store_event (&event
);
10625 event
.kind
= TOOL_BAR_EVENT
;
10626 event
.frame_or_window
= frame
;
10628 event
.modifiers
= modifiers
;
10629 kbd_buffer_store_event (&event
);
10630 last_tool_bar_item
= -1;
10635 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10636 tool-bar window-relative coordinates X/Y. Called from
10637 note_mouse_highlight. */
10640 note_tool_bar_highlight (f
, x
, y
)
10644 Lisp_Object window
= f
->tool_bar_window
;
10645 struct window
*w
= XWINDOW (window
);
10646 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10648 struct glyph
*glyph
;
10649 struct glyph_row
*row
;
10651 Lisp_Object enabled_p
;
10653 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10654 int mouse_down_p
, rc
;
10656 /* Function note_mouse_highlight is called with negative x(y
10657 values when mouse moves outside of the frame. */
10658 if (x
<= 0 || y
<= 0)
10660 clear_mouse_face (dpyinfo
);
10664 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10667 /* Not on tool-bar item. */
10668 clear_mouse_face (dpyinfo
);
10672 /* On same tool-bar item as before. */
10673 goto set_help_echo
;
10675 clear_mouse_face (dpyinfo
);
10677 /* Mouse is down, but on different tool-bar item? */
10678 mouse_down_p
= (dpyinfo
->grabbed
10679 && f
== last_mouse_frame
10680 && FRAME_LIVE_P (f
));
10682 && last_tool_bar_item
!= prop_idx
)
10685 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10686 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10688 /* If tool-bar item is not enabled, don't highlight it. */
10689 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10690 if (!NILP (enabled_p
))
10692 /* Compute the x-position of the glyph. In front and past the
10693 image is a space. We include this in the highlighted area. */
10694 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10695 for (i
= x
= 0; i
< hpos
; ++i
)
10696 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10698 /* Record this as the current active region. */
10699 dpyinfo
->mouse_face_beg_col
= hpos
;
10700 dpyinfo
->mouse_face_beg_row
= vpos
;
10701 dpyinfo
->mouse_face_beg_x
= x
;
10702 dpyinfo
->mouse_face_beg_y
= row
->y
;
10703 dpyinfo
->mouse_face_past_end
= 0;
10705 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10706 dpyinfo
->mouse_face_end_row
= vpos
;
10707 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10708 dpyinfo
->mouse_face_end_y
= row
->y
;
10709 dpyinfo
->mouse_face_window
= window
;
10710 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10712 /* Display it as active. */
10713 show_mouse_face (dpyinfo
, draw
);
10714 dpyinfo
->mouse_face_image_state
= draw
;
10719 /* Set help_echo_string to a help string to display for this tool-bar item.
10720 XTread_socket does the rest. */
10721 help_echo_object
= help_echo_window
= Qnil
;
10722 help_echo_pos
= -1;
10723 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10724 if (NILP (help_echo_string
))
10725 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10728 #endif /* HAVE_WINDOW_SYSTEM */
10732 /************************************************************************
10733 Horizontal scrolling
10734 ************************************************************************/
10736 static int hscroll_window_tree
P_ ((Lisp_Object
));
10737 static int hscroll_windows
P_ ((Lisp_Object
));
10739 /* For all leaf windows in the window tree rooted at WINDOW, set their
10740 hscroll value so that PT is (i) visible in the window, and (ii) so
10741 that it is not within a certain margin at the window's left and
10742 right border. Value is non-zero if any window's hscroll has been
10746 hscroll_window_tree (window
)
10747 Lisp_Object window
;
10749 int hscrolled_p
= 0;
10750 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10751 int hscroll_step_abs
= 0;
10752 double hscroll_step_rel
= 0;
10754 if (hscroll_relative_p
)
10756 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10757 if (hscroll_step_rel
< 0)
10759 hscroll_relative_p
= 0;
10760 hscroll_step_abs
= 0;
10763 else if (INTEGERP (Vhscroll_step
))
10765 hscroll_step_abs
= XINT (Vhscroll_step
);
10766 if (hscroll_step_abs
< 0)
10767 hscroll_step_abs
= 0;
10770 hscroll_step_abs
= 0;
10772 while (WINDOWP (window
))
10774 struct window
*w
= XWINDOW (window
);
10776 if (WINDOWP (w
->hchild
))
10777 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10778 else if (WINDOWP (w
->vchild
))
10779 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10780 else if (w
->cursor
.vpos
>= 0)
10783 int text_area_width
;
10784 struct glyph_row
*current_cursor_row
10785 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10786 struct glyph_row
*desired_cursor_row
10787 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10788 struct glyph_row
*cursor_row
10789 = (desired_cursor_row
->enabled_p
10790 ? desired_cursor_row
10791 : current_cursor_row
);
10793 text_area_width
= window_box_width (w
, TEXT_AREA
);
10795 /* Scroll when cursor is inside this scroll margin. */
10796 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10798 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10799 && ((XFASTINT (w
->hscroll
)
10800 && w
->cursor
.x
<= h_margin
)
10801 || (cursor_row
->enabled_p
10802 && cursor_row
->truncated_on_right_p
10803 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10807 struct buffer
*saved_current_buffer
;
10811 /* Find point in a display of infinite width. */
10812 saved_current_buffer
= current_buffer
;
10813 current_buffer
= XBUFFER (w
->buffer
);
10815 if (w
== XWINDOW (selected_window
))
10816 pt
= BUF_PT (current_buffer
);
10819 pt
= marker_position (w
->pointm
);
10820 pt
= max (BEGV
, pt
);
10824 /* Move iterator to pt starting at cursor_row->start in
10825 a line with infinite width. */
10826 init_to_row_start (&it
, w
, cursor_row
);
10827 it
.last_visible_x
= INFINITY
;
10828 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10829 current_buffer
= saved_current_buffer
;
10831 /* Position cursor in window. */
10832 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10833 hscroll
= max (0, (it
.current_x
10834 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10835 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10836 : (text_area_width
/ 2))))
10837 / FRAME_COLUMN_WIDTH (it
.f
);
10838 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10840 if (hscroll_relative_p
)
10841 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10844 wanted_x
= text_area_width
10845 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10848 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10852 if (hscroll_relative_p
)
10853 wanted_x
= text_area_width
* hscroll_step_rel
10856 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10859 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10861 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10863 /* Don't call Fset_window_hscroll if value hasn't
10864 changed because it will prevent redisplay
10866 if (XFASTINT (w
->hscroll
) != hscroll
)
10868 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10869 w
->hscroll
= make_number (hscroll
);
10878 /* Value is non-zero if hscroll of any leaf window has been changed. */
10879 return hscrolled_p
;
10883 /* Set hscroll so that cursor is visible and not inside horizontal
10884 scroll margins for all windows in the tree rooted at WINDOW. See
10885 also hscroll_window_tree above. Value is non-zero if any window's
10886 hscroll has been changed. If it has, desired matrices on the frame
10887 of WINDOW are cleared. */
10890 hscroll_windows (window
)
10891 Lisp_Object window
;
10893 int hscrolled_p
= hscroll_window_tree (window
);
10895 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10896 return hscrolled_p
;
10901 /************************************************************************
10903 ************************************************************************/
10905 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10906 to a non-zero value. This is sometimes handy to have in a debugger
10911 /* First and last unchanged row for try_window_id. */
10913 int debug_first_unchanged_at_end_vpos
;
10914 int debug_last_unchanged_at_beg_vpos
;
10916 /* Delta vpos and y. */
10918 int debug_dvpos
, debug_dy
;
10920 /* Delta in characters and bytes for try_window_id. */
10922 int debug_delta
, debug_delta_bytes
;
10924 /* Values of window_end_pos and window_end_vpos at the end of
10927 EMACS_INT debug_end_pos
, debug_end_vpos
;
10929 /* Append a string to W->desired_matrix->method. FMT is a printf
10930 format string. A1...A9 are a supplement for a variable-length
10931 argument list. If trace_redisplay_p is non-zero also printf the
10932 resulting string to stderr. */
10935 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10938 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10941 char *method
= w
->desired_matrix
->method
;
10942 int len
= strlen (method
);
10943 int size
= sizeof w
->desired_matrix
->method
;
10944 int remaining
= size
- len
- 1;
10946 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10947 if (len
&& remaining
)
10950 --remaining
, ++len
;
10953 strncpy (method
+ len
, buffer
, remaining
);
10955 if (trace_redisplay_p
)
10956 fprintf (stderr
, "%p (%s): %s\n",
10958 ((BUFFERP (w
->buffer
)
10959 && STRINGP (XBUFFER (w
->buffer
)->name
))
10960 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10965 #endif /* GLYPH_DEBUG */
10968 /* Value is non-zero if all changes in window W, which displays
10969 current_buffer, are in the text between START and END. START is a
10970 buffer position, END is given as a distance from Z. Used in
10971 redisplay_internal for display optimization. */
10974 text_outside_line_unchanged_p (w
, start
, end
)
10978 int unchanged_p
= 1;
10980 /* If text or overlays have changed, see where. */
10981 if (XFASTINT (w
->last_modified
) < MODIFF
10982 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10984 /* Gap in the line? */
10985 if (GPT
< start
|| Z
- GPT
< end
)
10988 /* Changes start in front of the line, or end after it? */
10990 && (BEG_UNCHANGED
< start
- 1
10991 || END_UNCHANGED
< end
))
10994 /* If selective display, can't optimize if changes start at the
10995 beginning of the line. */
10997 && INTEGERP (current_buffer
->selective_display
)
10998 && XINT (current_buffer
->selective_display
) > 0
10999 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11002 /* If there are overlays at the start or end of the line, these
11003 may have overlay strings with newlines in them. A change at
11004 START, for instance, may actually concern the display of such
11005 overlay strings as well, and they are displayed on different
11006 lines. So, quickly rule out this case. (For the future, it
11007 might be desirable to implement something more telling than
11008 just BEG/END_UNCHANGED.) */
11011 if (BEG
+ BEG_UNCHANGED
== start
11012 && overlay_touches_p (start
))
11014 if (END_UNCHANGED
== end
11015 && overlay_touches_p (Z
- end
))
11020 return unchanged_p
;
11024 /* Do a frame update, taking possible shortcuts into account. This is
11025 the main external entry point for redisplay.
11027 If the last redisplay displayed an echo area message and that message
11028 is no longer requested, we clear the echo area or bring back the
11029 mini-buffer if that is in use. */
11034 redisplay_internal (0);
11039 overlay_arrow_string_or_property (var
)
11044 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11047 return Voverlay_arrow_string
;
11050 /* Return 1 if there are any overlay-arrows in current_buffer. */
11052 overlay_arrow_in_current_buffer_p ()
11056 for (vlist
= Voverlay_arrow_variable_list
;
11058 vlist
= XCDR (vlist
))
11060 Lisp_Object var
= XCAR (vlist
);
11063 if (!SYMBOLP (var
))
11065 val
= find_symbol_value (var
);
11067 && current_buffer
== XMARKER (val
)->buffer
)
11074 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11078 overlay_arrows_changed_p ()
11082 for (vlist
= Voverlay_arrow_variable_list
;
11084 vlist
= XCDR (vlist
))
11086 Lisp_Object var
= XCAR (vlist
);
11087 Lisp_Object val
, pstr
;
11089 if (!SYMBOLP (var
))
11091 val
= find_symbol_value (var
);
11092 if (!MARKERP (val
))
11094 if (! EQ (COERCE_MARKER (val
),
11095 Fget (var
, Qlast_arrow_position
))
11096 || ! (pstr
= overlay_arrow_string_or_property (var
),
11097 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11103 /* Mark overlay arrows to be updated on next redisplay. */
11106 update_overlay_arrows (up_to_date
)
11111 for (vlist
= Voverlay_arrow_variable_list
;
11113 vlist
= XCDR (vlist
))
11115 Lisp_Object var
= XCAR (vlist
);
11117 if (!SYMBOLP (var
))
11120 if (up_to_date
> 0)
11122 Lisp_Object val
= find_symbol_value (var
);
11123 Fput (var
, Qlast_arrow_position
,
11124 COERCE_MARKER (val
));
11125 Fput (var
, Qlast_arrow_string
,
11126 overlay_arrow_string_or_property (var
));
11128 else if (up_to_date
< 0
11129 || !NILP (Fget (var
, Qlast_arrow_position
)))
11131 Fput (var
, Qlast_arrow_position
, Qt
);
11132 Fput (var
, Qlast_arrow_string
, Qt
);
11138 /* Return overlay arrow string to display at row.
11139 Return integer (bitmap number) for arrow bitmap in left fringe.
11140 Return nil if no overlay arrow. */
11143 overlay_arrow_at_row (it
, row
)
11145 struct glyph_row
*row
;
11149 for (vlist
= Voverlay_arrow_variable_list
;
11151 vlist
= XCDR (vlist
))
11153 Lisp_Object var
= XCAR (vlist
);
11156 if (!SYMBOLP (var
))
11159 val
= find_symbol_value (var
);
11162 && current_buffer
== XMARKER (val
)->buffer
11163 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11165 if (FRAME_WINDOW_P (it
->f
)
11166 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11168 #ifdef HAVE_WINDOW_SYSTEM
11169 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11172 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11173 return make_number (fringe_bitmap
);
11176 return make_number (-1); /* Use default arrow bitmap */
11178 return overlay_arrow_string_or_property (var
);
11185 /* Return 1 if point moved out of or into a composition. Otherwise
11186 return 0. PREV_BUF and PREV_PT are the last point buffer and
11187 position. BUF and PT are the current point buffer and position. */
11190 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11191 struct buffer
*prev_buf
, *buf
;
11194 EMACS_INT start
, end
;
11196 Lisp_Object buffer
;
11198 XSETBUFFER (buffer
, buf
);
11199 /* Check a composition at the last point if point moved within the
11201 if (prev_buf
== buf
)
11204 /* Point didn't move. */
11207 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11208 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11209 && COMPOSITION_VALID_P (start
, end
, prop
)
11210 && start
< prev_pt
&& end
> prev_pt
)
11211 /* The last point was within the composition. Return 1 iff
11212 point moved out of the composition. */
11213 return (pt
<= start
|| pt
>= end
);
11216 /* Check a composition at the current point. */
11217 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11218 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11219 && COMPOSITION_VALID_P (start
, end
, prop
)
11220 && start
< pt
&& end
> pt
);
11224 /* Reconsider the setting of B->clip_changed which is displayed
11228 reconsider_clip_changes (w
, b
)
11232 if (b
->clip_changed
11233 && !NILP (w
->window_end_valid
)
11234 && w
->current_matrix
->buffer
== b
11235 && w
->current_matrix
->zv
== BUF_ZV (b
)
11236 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11237 b
->clip_changed
= 0;
11239 /* If display wasn't paused, and W is not a tool bar window, see if
11240 point has been moved into or out of a composition. In that case,
11241 we set b->clip_changed to 1 to force updating the screen. If
11242 b->clip_changed has already been set to 1, we can skip this
11244 if (!b
->clip_changed
11245 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11249 if (w
== XWINDOW (selected_window
))
11250 pt
= BUF_PT (current_buffer
);
11252 pt
= marker_position (w
->pointm
);
11254 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11255 || pt
!= XINT (w
->last_point
))
11256 && check_point_in_composition (w
->current_matrix
->buffer
,
11257 XINT (w
->last_point
),
11258 XBUFFER (w
->buffer
), pt
))
11259 b
->clip_changed
= 1;
11264 /* Select FRAME to forward the values of frame-local variables into C
11265 variables so that the redisplay routines can access those values
11269 select_frame_for_redisplay (frame
)
11272 Lisp_Object tail
, symbol
, val
;
11273 Lisp_Object old
= selected_frame
;
11274 struct Lisp_Symbol
*sym
;
11276 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11278 selected_frame
= frame
;
11282 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11283 if (CONSP (XCAR (tail
))
11284 && (symbol
= XCAR (XCAR (tail
)),
11286 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11288 (BUFFER_LOCAL_VALUEP (val
)))
11289 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11290 /* Use find_symbol_value rather than Fsymbol_value
11291 to avoid an error if it is void. */
11292 find_symbol_value (symbol
);
11293 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11297 #define STOP_POLLING \
11298 do { if (! polling_stopped_here) stop_polling (); \
11299 polling_stopped_here = 1; } while (0)
11301 #define RESUME_POLLING \
11302 do { if (polling_stopped_here) start_polling (); \
11303 polling_stopped_here = 0; } while (0)
11306 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11307 response to any user action; therefore, we should preserve the echo
11308 area. (Actually, our caller does that job.) Perhaps in the future
11309 avoid recentering windows if it is not necessary; currently that
11310 causes some problems. */
11313 redisplay_internal (preserve_echo_area
)
11314 int preserve_echo_area
;
11316 struct window
*w
= XWINDOW (selected_window
);
11319 int must_finish
= 0;
11320 struct text_pos tlbufpos
, tlendpos
;
11321 int number_of_visible_frames
;
11324 int polling_stopped_here
= 0;
11325 Lisp_Object old_frame
= selected_frame
;
11327 /* Non-zero means redisplay has to consider all windows on all
11328 frames. Zero means, only selected_window is considered. */
11329 int consider_all_windows_p
;
11331 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11333 /* No redisplay if running in batch mode or frame is not yet fully
11334 initialized, or redisplay is explicitly turned off by setting
11335 Vinhibit_redisplay. */
11337 || !NILP (Vinhibit_redisplay
))
11340 /* Don't examine these until after testing Vinhibit_redisplay.
11341 When Emacs is shutting down, perhaps because its connection to
11342 X has dropped, we should not look at them at all. */
11343 f
= XFRAME (w
->frame
);
11344 sf
= SELECTED_FRAME ();
11346 if (!f
->glyphs_initialized_p
)
11349 /* The flag redisplay_performed_directly_p is set by
11350 direct_output_for_insert when it already did the whole screen
11351 update necessary. */
11352 if (redisplay_performed_directly_p
)
11354 redisplay_performed_directly_p
= 0;
11355 if (!hscroll_windows (selected_window
))
11359 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11360 if (popup_activated ())
11364 /* I don't think this happens but let's be paranoid. */
11365 if (redisplaying_p
)
11368 /* Record a function that resets redisplaying_p to its old value
11369 when we leave this function. */
11370 count
= SPECPDL_INDEX ();
11371 record_unwind_protect (unwind_redisplay
,
11372 Fcons (make_number (redisplaying_p
), selected_frame
));
11374 specbind (Qinhibit_free_realized_faces
, Qnil
);
11377 Lisp_Object tail
, frame
;
11379 FOR_EACH_FRAME (tail
, frame
)
11381 struct frame
*f
= XFRAME (frame
);
11382 f
->already_hscrolled_p
= 0;
11387 if (!EQ (old_frame
, selected_frame
)
11388 && FRAME_LIVE_P (XFRAME (old_frame
)))
11389 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11390 selected_frame and selected_window to be temporarily out-of-sync so
11391 when we come back here via `goto retry', we need to resync because we
11392 may need to run Elisp code (via prepare_menu_bars). */
11393 select_frame_for_redisplay (old_frame
);
11396 reconsider_clip_changes (w
, current_buffer
);
11397 last_escape_glyph_frame
= NULL
;
11398 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11400 /* If new fonts have been loaded that make a glyph matrix adjustment
11401 necessary, do it. */
11402 if (fonts_changed_p
)
11404 adjust_glyphs (NULL
);
11405 ++windows_or_buffers_changed
;
11406 fonts_changed_p
= 0;
11409 /* If face_change_count is non-zero, init_iterator will free all
11410 realized faces, which includes the faces referenced from current
11411 matrices. So, we can't reuse current matrices in this case. */
11412 if (face_change_count
)
11413 ++windows_or_buffers_changed
;
11415 if (FRAME_TERMCAP_P (sf
)
11416 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11418 /* Since frames on a single ASCII terminal share the same
11419 display area, displaying a different frame means redisplay
11420 the whole thing. */
11421 windows_or_buffers_changed
++;
11422 SET_FRAME_GARBAGED (sf
);
11424 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11426 FRAME_TTY (sf
)->previous_frame
= sf
;
11429 /* Set the visible flags for all frames. Do this before checking
11430 for resized or garbaged frames; they want to know if their frames
11431 are visible. See the comment in frame.h for
11432 FRAME_SAMPLE_VISIBILITY. */
11434 Lisp_Object tail
, frame
;
11436 number_of_visible_frames
= 0;
11438 FOR_EACH_FRAME (tail
, frame
)
11440 struct frame
*f
= XFRAME (frame
);
11442 FRAME_SAMPLE_VISIBILITY (f
);
11443 if (FRAME_VISIBLE_P (f
))
11444 ++number_of_visible_frames
;
11445 clear_desired_matrices (f
);
11450 /* Notice any pending interrupt request to change frame size. */
11451 do_pending_window_change (1);
11453 /* Clear frames marked as garbaged. */
11454 if (frame_garbaged
)
11455 clear_garbaged_frames ();
11457 /* Build menubar and tool-bar items. */
11458 if (NILP (Vmemory_full
))
11459 prepare_menu_bars ();
11461 if (windows_or_buffers_changed
)
11462 update_mode_lines
++;
11464 /* Detect case that we need to write or remove a star in the mode line. */
11465 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11467 w
->update_mode_line
= Qt
;
11468 if (buffer_shared
> 1)
11469 update_mode_lines
++;
11472 /* Avoid invocation of point motion hooks by `current_column' below. */
11473 count1
= SPECPDL_INDEX ();
11474 specbind (Qinhibit_point_motion_hooks
, Qt
);
11476 /* If %c is in the mode line, update it if needed. */
11477 if (!NILP (w
->column_number_displayed
)
11478 /* This alternative quickly identifies a common case
11479 where no change is needed. */
11480 && !(PT
== XFASTINT (w
->last_point
)
11481 && XFASTINT (w
->last_modified
) >= MODIFF
11482 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11483 && (XFASTINT (w
->column_number_displayed
)
11484 != (int) current_column ())) /* iftc */
11485 w
->update_mode_line
= Qt
;
11487 unbind_to (count1
, Qnil
);
11489 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11491 /* The variable buffer_shared is set in redisplay_window and
11492 indicates that we redisplay a buffer in different windows. See
11494 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11495 || cursor_type_changed
);
11497 /* If specs for an arrow have changed, do thorough redisplay
11498 to ensure we remove any arrow that should no longer exist. */
11499 if (overlay_arrows_changed_p ())
11500 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11502 /* Normally the message* functions will have already displayed and
11503 updated the echo area, but the frame may have been trashed, or
11504 the update may have been preempted, so display the echo area
11505 again here. Checking message_cleared_p captures the case that
11506 the echo area should be cleared. */
11507 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11508 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11509 || (message_cleared_p
11510 && minibuf_level
== 0
11511 /* If the mini-window is currently selected, this means the
11512 echo-area doesn't show through. */
11513 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11515 int window_height_changed_p
= echo_area_display (0);
11518 /* If we don't display the current message, don't clear the
11519 message_cleared_p flag, because, if we did, we wouldn't clear
11520 the echo area in the next redisplay which doesn't preserve
11522 if (!display_last_displayed_message_p
)
11523 message_cleared_p
= 0;
11525 if (fonts_changed_p
)
11527 else if (window_height_changed_p
)
11529 consider_all_windows_p
= 1;
11530 ++update_mode_lines
;
11531 ++windows_or_buffers_changed
;
11533 /* If window configuration was changed, frames may have been
11534 marked garbaged. Clear them or we will experience
11535 surprises wrt scrolling. */
11536 if (frame_garbaged
)
11537 clear_garbaged_frames ();
11540 else if (EQ (selected_window
, minibuf_window
)
11541 && (current_buffer
->clip_changed
11542 || XFASTINT (w
->last_modified
) < MODIFF
11543 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11544 && resize_mini_window (w
, 0))
11546 /* Resized active mini-window to fit the size of what it is
11547 showing if its contents might have changed. */
11549 /* FIXME: this causes all frames to be updated, which seems unnecessary
11550 since only the current frame needs to be considered. This function needs
11551 to be rewritten with two variables, consider_all_windows and
11552 consider_all_frames. */
11553 consider_all_windows_p
= 1;
11554 ++windows_or_buffers_changed
;
11555 ++update_mode_lines
;
11557 /* If window configuration was changed, frames may have been
11558 marked garbaged. Clear them or we will experience
11559 surprises wrt scrolling. */
11560 if (frame_garbaged
)
11561 clear_garbaged_frames ();
11565 /* If showing the region, and mark has changed, we must redisplay
11566 the whole window. The assignment to this_line_start_pos prevents
11567 the optimization directly below this if-statement. */
11568 if (((!NILP (Vtransient_mark_mode
)
11569 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11570 != !NILP (w
->region_showing
))
11571 || (!NILP (w
->region_showing
)
11572 && !EQ (w
->region_showing
,
11573 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11574 CHARPOS (this_line_start_pos
) = 0;
11576 /* Optimize the case that only the line containing the cursor in the
11577 selected window has changed. Variables starting with this_ are
11578 set in display_line and record information about the line
11579 containing the cursor. */
11580 tlbufpos
= this_line_start_pos
;
11581 tlendpos
= this_line_end_pos
;
11582 if (!consider_all_windows_p
11583 && CHARPOS (tlbufpos
) > 0
11584 && NILP (w
->update_mode_line
)
11585 && !current_buffer
->clip_changed
11586 && !current_buffer
->prevent_redisplay_optimizations_p
11587 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11588 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11589 /* Make sure recorded data applies to current buffer, etc. */
11590 && this_line_buffer
== current_buffer
11591 && current_buffer
== XBUFFER (w
->buffer
)
11592 && NILP (w
->force_start
)
11593 && NILP (w
->optional_new_start
)
11594 /* Point must be on the line that we have info recorded about. */
11595 && PT
>= CHARPOS (tlbufpos
)
11596 && PT
<= Z
- CHARPOS (tlendpos
)
11597 /* All text outside that line, including its final newline,
11598 must be unchanged */
11599 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11600 CHARPOS (tlendpos
)))
11602 if (CHARPOS (tlbufpos
) > BEGV
11603 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11604 && (CHARPOS (tlbufpos
) == ZV
11605 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11606 /* Former continuation line has disappeared by becoming empty */
11608 else if (XFASTINT (w
->last_modified
) < MODIFF
11609 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11610 || MINI_WINDOW_P (w
))
11612 /* We have to handle the case of continuation around a
11613 wide-column character (See the comment in indent.c around
11616 For instance, in the following case:
11618 -------- Insert --------
11619 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11620 J_I_ ==> J_I_ `^^' are cursors.
11624 As we have to redraw the line above, we should goto cancel. */
11627 int line_height_before
= this_line_pixel_height
;
11629 /* Note that start_display will handle the case that the
11630 line starting at tlbufpos is a continuation lines. */
11631 start_display (&it
, w
, tlbufpos
);
11633 /* Implementation note: It this still necessary? */
11634 if (it
.current_x
!= this_line_start_x
)
11637 TRACE ((stderr
, "trying display optimization 1\n"));
11638 w
->cursor
.vpos
= -1;
11639 overlay_arrow_seen
= 0;
11640 it
.vpos
= this_line_vpos
;
11641 it
.current_y
= this_line_y
;
11642 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11643 display_line (&it
);
11645 /* If line contains point, is not continued,
11646 and ends at same distance from eob as before, we win */
11647 if (w
->cursor
.vpos
>= 0
11648 /* Line is not continued, otherwise this_line_start_pos
11649 would have been set to 0 in display_line. */
11650 && CHARPOS (this_line_start_pos
)
11651 /* Line ends as before. */
11652 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11653 /* Line has same height as before. Otherwise other lines
11654 would have to be shifted up or down. */
11655 && this_line_pixel_height
== line_height_before
)
11657 /* If this is not the window's last line, we must adjust
11658 the charstarts of the lines below. */
11659 if (it
.current_y
< it
.last_visible_y
)
11661 struct glyph_row
*row
11662 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11663 int delta
, delta_bytes
;
11665 if (Z
- CHARPOS (tlendpos
) == ZV
)
11667 /* This line ends at end of (accessible part of)
11668 buffer. There is no newline to count. */
11670 - CHARPOS (tlendpos
)
11671 - MATRIX_ROW_START_CHARPOS (row
));
11672 delta_bytes
= (Z_BYTE
11673 - BYTEPOS (tlendpos
)
11674 - MATRIX_ROW_START_BYTEPOS (row
));
11678 /* This line ends in a newline. Must take
11679 account of the newline and the rest of the
11680 text that follows. */
11682 - CHARPOS (tlendpos
)
11683 - MATRIX_ROW_START_CHARPOS (row
));
11684 delta_bytes
= (Z_BYTE
11685 - BYTEPOS (tlendpos
)
11686 - MATRIX_ROW_START_BYTEPOS (row
));
11689 increment_matrix_positions (w
->current_matrix
,
11690 this_line_vpos
+ 1,
11691 w
->current_matrix
->nrows
,
11692 delta
, delta_bytes
);
11695 /* If this row displays text now but previously didn't,
11696 or vice versa, w->window_end_vpos may have to be
11698 if ((it
.glyph_row
- 1)->displays_text_p
)
11700 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11701 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11703 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11704 && this_line_vpos
> 0)
11705 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11706 w
->window_end_valid
= Qnil
;
11708 /* Update hint: No need to try to scroll in update_window. */
11709 w
->desired_matrix
->no_scrolling_p
= 1;
11712 *w
->desired_matrix
->method
= 0;
11713 debug_method_add (w
, "optimization 1");
11715 #ifdef HAVE_WINDOW_SYSTEM
11716 update_window_fringes (w
, 0);
11723 else if (/* Cursor position hasn't changed. */
11724 PT
== XFASTINT (w
->last_point
)
11725 /* Make sure the cursor was last displayed
11726 in this window. Otherwise we have to reposition it. */
11727 && 0 <= w
->cursor
.vpos
11728 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11732 do_pending_window_change (1);
11734 /* We used to always goto end_of_redisplay here, but this
11735 isn't enough if we have a blinking cursor. */
11736 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11737 goto end_of_redisplay
;
11741 /* If highlighting the region, or if the cursor is in the echo area,
11742 then we can't just move the cursor. */
11743 else if (! (!NILP (Vtransient_mark_mode
)
11744 && !NILP (current_buffer
->mark_active
))
11745 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11746 || highlight_nonselected_windows
)
11747 && NILP (w
->region_showing
)
11748 && NILP (Vshow_trailing_whitespace
)
11749 && !cursor_in_echo_area
)
11752 struct glyph_row
*row
;
11754 /* Skip from tlbufpos to PT and see where it is. Note that
11755 PT may be in invisible text. If so, we will end at the
11756 next visible position. */
11757 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11758 NULL
, DEFAULT_FACE_ID
);
11759 it
.current_x
= this_line_start_x
;
11760 it
.current_y
= this_line_y
;
11761 it
.vpos
= this_line_vpos
;
11763 /* The call to move_it_to stops in front of PT, but
11764 moves over before-strings. */
11765 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11767 if (it
.vpos
== this_line_vpos
11768 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11771 xassert (this_line_vpos
== it
.vpos
);
11772 xassert (this_line_y
== it
.current_y
);
11773 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11775 *w
->desired_matrix
->method
= 0;
11776 debug_method_add (w
, "optimization 3");
11785 /* Text changed drastically or point moved off of line. */
11786 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11789 CHARPOS (this_line_start_pos
) = 0;
11790 consider_all_windows_p
|= buffer_shared
> 1;
11791 ++clear_face_cache_count
;
11792 #ifdef HAVE_WINDOW_SYSTEM
11793 ++clear_image_cache_count
;
11796 /* Build desired matrices, and update the display. If
11797 consider_all_windows_p is non-zero, do it for all windows on all
11798 frames. Otherwise do it for selected_window, only. */
11800 if (consider_all_windows_p
)
11802 Lisp_Object tail
, frame
;
11804 FOR_EACH_FRAME (tail
, frame
)
11805 XFRAME (frame
)->updated_p
= 0;
11807 /* Recompute # windows showing selected buffer. This will be
11808 incremented each time such a window is displayed. */
11811 FOR_EACH_FRAME (tail
, frame
)
11813 struct frame
*f
= XFRAME (frame
);
11815 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11817 if (! EQ (frame
, selected_frame
))
11818 /* Select the frame, for the sake of frame-local
11820 select_frame_for_redisplay (frame
);
11822 /* Mark all the scroll bars to be removed; we'll redeem
11823 the ones we want when we redisplay their windows. */
11824 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11825 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11827 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11828 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11830 /* Any scroll bars which redisplay_windows should have
11831 nuked should now go away. */
11832 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11833 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11835 /* If fonts changed, display again. */
11836 /* ??? rms: I suspect it is a mistake to jump all the way
11837 back to retry here. It should just retry this frame. */
11838 if (fonts_changed_p
)
11841 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11843 /* See if we have to hscroll. */
11844 if (!f
->already_hscrolled_p
)
11846 f
->already_hscrolled_p
= 1;
11847 if (hscroll_windows (f
->root_window
))
11851 /* Prevent various kinds of signals during display
11852 update. stdio is not robust about handling
11853 signals, which can cause an apparent I/O
11855 if (interrupt_input
)
11856 unrequest_sigio ();
11859 /* Update the display. */
11860 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11861 pause
|= update_frame (f
, 0, 0);
11867 if (!EQ (old_frame
, selected_frame
)
11868 && FRAME_LIVE_P (XFRAME (old_frame
)))
11869 /* We played a bit fast-and-loose above and allowed selected_frame
11870 and selected_window to be temporarily out-of-sync but let's make
11871 sure this stays contained. */
11872 select_frame_for_redisplay (old_frame
);
11873 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11877 /* Do the mark_window_display_accurate after all windows have
11878 been redisplayed because this call resets flags in buffers
11879 which are needed for proper redisplay. */
11880 FOR_EACH_FRAME (tail
, frame
)
11882 struct frame
*f
= XFRAME (frame
);
11885 mark_window_display_accurate (f
->root_window
, 1);
11886 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11887 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11892 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11894 Lisp_Object mini_window
;
11895 struct frame
*mini_frame
;
11897 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11898 /* Use list_of_error, not Qerror, so that
11899 we catch only errors and don't run the debugger. */
11900 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11902 redisplay_window_error
);
11904 /* Compare desired and current matrices, perform output. */
11907 /* If fonts changed, display again. */
11908 if (fonts_changed_p
)
11911 /* Prevent various kinds of signals during display update.
11912 stdio is not robust about handling signals,
11913 which can cause an apparent I/O error. */
11914 if (interrupt_input
)
11915 unrequest_sigio ();
11918 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11920 if (hscroll_windows (selected_window
))
11923 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11924 pause
= update_frame (sf
, 0, 0);
11927 /* We may have called echo_area_display at the top of this
11928 function. If the echo area is on another frame, that may
11929 have put text on a frame other than the selected one, so the
11930 above call to update_frame would not have caught it. Catch
11932 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11933 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11935 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11937 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11938 pause
|= update_frame (mini_frame
, 0, 0);
11939 if (!pause
&& hscroll_windows (mini_window
))
11944 /* If display was paused because of pending input, make sure we do a
11945 thorough update the next time. */
11948 /* Prevent the optimization at the beginning of
11949 redisplay_internal that tries a single-line update of the
11950 line containing the cursor in the selected window. */
11951 CHARPOS (this_line_start_pos
) = 0;
11953 /* Let the overlay arrow be updated the next time. */
11954 update_overlay_arrows (0);
11956 /* If we pause after scrolling, some rows in the current
11957 matrices of some windows are not valid. */
11958 if (!WINDOW_FULL_WIDTH_P (w
)
11959 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11960 update_mode_lines
= 1;
11964 if (!consider_all_windows_p
)
11966 /* This has already been done above if
11967 consider_all_windows_p is set. */
11968 mark_window_display_accurate_1 (w
, 1);
11970 /* Say overlay arrows are up to date. */
11971 update_overlay_arrows (1);
11973 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11974 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11977 update_mode_lines
= 0;
11978 windows_or_buffers_changed
= 0;
11979 cursor_type_changed
= 0;
11982 /* Start SIGIO interrupts coming again. Having them off during the
11983 code above makes it less likely one will discard output, but not
11984 impossible, since there might be stuff in the system buffer here.
11985 But it is much hairier to try to do anything about that. */
11986 if (interrupt_input
)
11990 /* If a frame has become visible which was not before, redisplay
11991 again, so that we display it. Expose events for such a frame
11992 (which it gets when becoming visible) don't call the parts of
11993 redisplay constructing glyphs, so simply exposing a frame won't
11994 display anything in this case. So, we have to display these
11995 frames here explicitly. */
11998 Lisp_Object tail
, frame
;
12001 FOR_EACH_FRAME (tail
, frame
)
12003 int this_is_visible
= 0;
12005 if (XFRAME (frame
)->visible
)
12006 this_is_visible
= 1;
12007 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12008 if (XFRAME (frame
)->visible
)
12009 this_is_visible
= 1;
12011 if (this_is_visible
)
12015 if (new_count
!= number_of_visible_frames
)
12016 windows_or_buffers_changed
++;
12019 /* Change frame size now if a change is pending. */
12020 do_pending_window_change (1);
12022 /* If we just did a pending size change, or have additional
12023 visible frames, redisplay again. */
12024 if (windows_or_buffers_changed
&& !pause
)
12027 /* Clear the face cache eventually. */
12028 if (consider_all_windows_p
)
12030 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12032 clear_face_cache (0);
12033 clear_face_cache_count
= 0;
12035 #ifdef HAVE_WINDOW_SYSTEM
12036 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12038 clear_image_caches (Qnil
);
12039 clear_image_cache_count
= 0;
12041 #endif /* HAVE_WINDOW_SYSTEM */
12045 unbind_to (count
, Qnil
);
12050 /* Redisplay, but leave alone any recent echo area message unless
12051 another message has been requested in its place.
12053 This is useful in situations where you need to redisplay but no
12054 user action has occurred, making it inappropriate for the message
12055 area to be cleared. See tracking_off and
12056 wait_reading_process_output for examples of these situations.
12058 FROM_WHERE is an integer saying from where this function was
12059 called. This is useful for debugging. */
12062 redisplay_preserve_echo_area (from_where
)
12065 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12067 if (!NILP (echo_area_buffer
[1]))
12069 /* We have a previously displayed message, but no current
12070 message. Redisplay the previous message. */
12071 display_last_displayed_message_p
= 1;
12072 redisplay_internal (1);
12073 display_last_displayed_message_p
= 0;
12076 redisplay_internal (1);
12078 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12079 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12080 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12084 /* Function registered with record_unwind_protect in
12085 redisplay_internal. Reset redisplaying_p to the value it had
12086 before redisplay_internal was called, and clear
12087 prevent_freeing_realized_faces_p. It also selects the previously
12088 selected frame, unless it has been deleted (by an X connection
12089 failure during redisplay, for example). */
12092 unwind_redisplay (val
)
12095 Lisp_Object old_redisplaying_p
, old_frame
;
12097 old_redisplaying_p
= XCAR (val
);
12098 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12099 old_frame
= XCDR (val
);
12100 if (! EQ (old_frame
, selected_frame
)
12101 && FRAME_LIVE_P (XFRAME (old_frame
)))
12102 select_frame_for_redisplay (old_frame
);
12107 /* Mark the display of window W as accurate or inaccurate. If
12108 ACCURATE_P is non-zero mark display of W as accurate. If
12109 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12110 redisplay_internal is called. */
12113 mark_window_display_accurate_1 (w
, accurate_p
)
12117 if (BUFFERP (w
->buffer
))
12119 struct buffer
*b
= XBUFFER (w
->buffer
);
12122 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12123 w
->last_overlay_modified
12124 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12126 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12130 b
->clip_changed
= 0;
12131 b
->prevent_redisplay_optimizations_p
= 0;
12133 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12134 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12135 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12136 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12138 w
->current_matrix
->buffer
= b
;
12139 w
->current_matrix
->begv
= BUF_BEGV (b
);
12140 w
->current_matrix
->zv
= BUF_ZV (b
);
12142 w
->last_cursor
= w
->cursor
;
12143 w
->last_cursor_off_p
= w
->cursor_off_p
;
12145 if (w
== XWINDOW (selected_window
))
12146 w
->last_point
= make_number (BUF_PT (b
));
12148 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12154 w
->window_end_valid
= w
->buffer
;
12155 w
->update_mode_line
= Qnil
;
12160 /* Mark the display of windows in the window tree rooted at WINDOW as
12161 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12162 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12163 be redisplayed the next time redisplay_internal is called. */
12166 mark_window_display_accurate (window
, accurate_p
)
12167 Lisp_Object window
;
12172 for (; !NILP (window
); window
= w
->next
)
12174 w
= XWINDOW (window
);
12175 mark_window_display_accurate_1 (w
, accurate_p
);
12177 if (!NILP (w
->vchild
))
12178 mark_window_display_accurate (w
->vchild
, accurate_p
);
12179 if (!NILP (w
->hchild
))
12180 mark_window_display_accurate (w
->hchild
, accurate_p
);
12185 update_overlay_arrows (1);
12189 /* Force a thorough redisplay the next time by setting
12190 last_arrow_position and last_arrow_string to t, which is
12191 unequal to any useful value of Voverlay_arrow_... */
12192 update_overlay_arrows (-1);
12197 /* Return value in display table DP (Lisp_Char_Table *) for character
12198 C. Since a display table doesn't have any parent, we don't have to
12199 follow parent. Do not call this function directly but use the
12200 macro DISP_CHAR_VECTOR. */
12203 disp_char_vector (dp
, c
)
12204 struct Lisp_Char_Table
*dp
;
12209 if (ASCII_CHAR_P (c
))
12212 if (SUB_CHAR_TABLE_P (val
))
12213 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12219 XSETCHAR_TABLE (table
, dp
);
12220 val
= char_table_ref (table
, c
);
12229 /***********************************************************************
12231 ***********************************************************************/
12233 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12236 redisplay_windows (window
)
12237 Lisp_Object window
;
12239 while (!NILP (window
))
12241 struct window
*w
= XWINDOW (window
);
12243 if (!NILP (w
->hchild
))
12244 redisplay_windows (w
->hchild
);
12245 else if (!NILP (w
->vchild
))
12246 redisplay_windows (w
->vchild
);
12249 displayed_buffer
= XBUFFER (w
->buffer
);
12250 /* Use list_of_error, not Qerror, so that
12251 we catch only errors and don't run the debugger. */
12252 internal_condition_case_1 (redisplay_window_0
, window
,
12254 redisplay_window_error
);
12262 redisplay_window_error ()
12264 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12269 redisplay_window_0 (window
)
12270 Lisp_Object window
;
12272 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12273 redisplay_window (window
, 0);
12278 redisplay_window_1 (window
)
12279 Lisp_Object window
;
12281 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12282 redisplay_window (window
, 1);
12287 /* Increment GLYPH until it reaches END or CONDITION fails while
12288 adding (GLYPH)->pixel_width to X. */
12290 #define SKIP_GLYPHS(glyph, end, x, condition) \
12293 (x) += (glyph)->pixel_width; \
12296 while ((glyph) < (end) && (condition))
12299 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12300 DELTA is the number of bytes by which positions recorded in ROW
12301 differ from current buffer positions.
12303 Return 0 if cursor is not on this row. 1 otherwise. */
12306 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12308 struct glyph_row
*row
;
12309 struct glyph_matrix
*matrix
;
12310 int delta
, delta_bytes
, dy
, dvpos
;
12312 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12313 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12314 struct glyph
*cursor
= NULL
;
12315 /* The first glyph that starts a sequence of glyphs from string. */
12316 struct glyph
*string_start
;
12317 /* The X coordinate of string_start. */
12318 int string_start_x
;
12319 /* The last known character position. */
12320 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12321 /* The last known character position before string_start. */
12322 int string_before_pos
;
12325 int cursor_from_overlay_pos
= 0;
12326 int pt_old
= PT
- delta
;
12328 /* Skip over glyphs not having an object at the start of the row.
12329 These are special glyphs like truncation marks on terminal
12331 if (row
->displays_text_p
)
12333 && INTEGERP (glyph
->object
)
12334 && glyph
->charpos
< 0)
12336 x
+= glyph
->pixel_width
;
12340 string_start
= NULL
;
12342 && !INTEGERP (glyph
->object
)
12343 && (!BUFFERP (glyph
->object
)
12344 || (last_pos
= glyph
->charpos
) < pt_old
12345 || glyph
->avoid_cursor_p
))
12347 if (! STRINGP (glyph
->object
))
12349 string_start
= NULL
;
12350 x
+= glyph
->pixel_width
;
12352 if (cursor_from_overlay_pos
12353 && last_pos
>= cursor_from_overlay_pos
)
12355 cursor_from_overlay_pos
= 0;
12361 if (string_start
== NULL
)
12363 string_before_pos
= last_pos
;
12364 string_start
= glyph
;
12365 string_start_x
= x
;
12367 /* Skip all glyphs from string. */
12372 if ((cursor
== NULL
|| glyph
> cursor
)
12373 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12374 Qcursor
, (glyph
)->object
),
12376 && (pos
= string_buffer_position (w
, glyph
->object
,
12377 string_before_pos
),
12378 (pos
== 0 /* From overlay */
12379 || pos
== pt_old
)))
12381 /* Estimate overlay buffer position from the buffer
12382 positions of the glyphs before and after the overlay.
12383 Add 1 to last_pos so that if point corresponds to the
12384 glyph right after the overlay, we still use a 'cursor'
12385 property found in that overlay. */
12386 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12387 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12391 x
+= glyph
->pixel_width
;
12394 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12398 if (cursor
!= NULL
)
12403 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12405 /* Scan back over the ellipsis glyphs, decrementing positions. */
12406 while (glyph
> row
->glyphs
[TEXT_AREA
]
12407 && (glyph
- 1)->charpos
== last_pos
)
12408 glyph
--, x
-= glyph
->pixel_width
;
12409 /* That loop always goes one position too far,
12410 including the glyph before the ellipsis.
12411 So scan forward over that one. */
12412 x
+= glyph
->pixel_width
;
12415 else if (string_start
12416 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12418 /* We may have skipped over point because the previous glyphs
12419 are from string. As there's no easy way to know the
12420 character position of the current glyph, find the correct
12421 glyph on point by scanning from string_start again. */
12423 Lisp_Object string
;
12424 struct glyph
*stop
= glyph
;
12427 limit
= make_number (pt_old
+ 1);
12428 glyph
= string_start
;
12429 x
= string_start_x
;
12430 string
= glyph
->object
;
12431 pos
= string_buffer_position (w
, string
, string_before_pos
);
12432 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12433 because we always put cursor after overlay strings. */
12434 while (pos
== 0 && glyph
< stop
)
12436 string
= glyph
->object
;
12437 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12439 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12442 while (glyph
< stop
)
12444 pos
= XINT (Fnext_single_char_property_change
12445 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12448 /* Skip glyphs from the same string. */
12449 string
= glyph
->object
;
12450 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12451 /* Skip glyphs from an overlay. */
12452 while (glyph
< stop
12453 && ! string_buffer_position (w
, glyph
->object
, pos
))
12455 string
= glyph
->object
;
12456 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12460 /* If we reached the end of the line, and end was from a string,
12461 cursor is not on this line. */
12462 if (glyph
== end
&& row
->continued_p
)
12466 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12468 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12469 w
->cursor
.y
= row
->y
+ dy
;
12471 if (w
== XWINDOW (selected_window
))
12473 if (!row
->continued_p
12474 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12477 this_line_buffer
= XBUFFER (w
->buffer
);
12479 CHARPOS (this_line_start_pos
)
12480 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12481 BYTEPOS (this_line_start_pos
)
12482 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12484 CHARPOS (this_line_end_pos
)
12485 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12486 BYTEPOS (this_line_end_pos
)
12487 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12489 this_line_y
= w
->cursor
.y
;
12490 this_line_pixel_height
= row
->height
;
12491 this_line_vpos
= w
->cursor
.vpos
;
12492 this_line_start_x
= row
->x
;
12495 CHARPOS (this_line_start_pos
) = 0;
12502 /* Run window scroll functions, if any, for WINDOW with new window
12503 start STARTP. Sets the window start of WINDOW to that position.
12505 We assume that the window's buffer is really current. */
12507 static INLINE
struct text_pos
12508 run_window_scroll_functions (window
, startp
)
12509 Lisp_Object window
;
12510 struct text_pos startp
;
12512 struct window
*w
= XWINDOW (window
);
12513 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12515 if (current_buffer
!= XBUFFER (w
->buffer
))
12518 if (!NILP (Vwindow_scroll_functions
))
12520 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12521 make_number (CHARPOS (startp
)));
12522 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12523 /* In case the hook functions switch buffers. */
12524 if (current_buffer
!= XBUFFER (w
->buffer
))
12525 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12532 /* Make sure the line containing the cursor is fully visible.
12533 A value of 1 means there is nothing to be done.
12534 (Either the line is fully visible, or it cannot be made so,
12535 or we cannot tell.)
12537 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12538 is higher than window.
12540 A value of 0 means the caller should do scrolling
12541 as if point had gone off the screen. */
12544 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12547 int current_matrix_p
;
12549 struct glyph_matrix
*matrix
;
12550 struct glyph_row
*row
;
12553 if (!make_cursor_line_fully_visible_p
)
12556 /* It's not always possible to find the cursor, e.g, when a window
12557 is full of overlay strings. Don't do anything in that case. */
12558 if (w
->cursor
.vpos
< 0)
12561 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12562 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12564 /* If the cursor row is not partially visible, there's nothing to do. */
12565 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12568 /* If the row the cursor is in is taller than the window's height,
12569 it's not clear what to do, so do nothing. */
12570 window_height
= window_box_height (w
);
12571 if (row
->height
>= window_height
)
12573 if (!force_p
|| MINI_WINDOW_P (w
)
12574 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12580 /* This code used to try to scroll the window just enough to make
12581 the line visible. It returned 0 to say that the caller should
12582 allocate larger glyph matrices. */
12584 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12586 int dy
= row
->height
- row
->visible_height
;
12589 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12591 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12593 int dy
= - (row
->height
- row
->visible_height
);
12596 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12599 /* When we change the cursor y-position of the selected window,
12600 change this_line_y as well so that the display optimization for
12601 the cursor line of the selected window in redisplay_internal uses
12602 the correct y-position. */
12603 if (w
== XWINDOW (selected_window
))
12604 this_line_y
= w
->cursor
.y
;
12606 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12607 redisplay with larger matrices. */
12608 if (matrix
->nrows
< required_matrix_height (w
))
12610 fonts_changed_p
= 1;
12619 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12620 non-zero means only WINDOW is redisplayed in redisplay_internal.
12621 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12622 in redisplay_window to bring a partially visible line into view in
12623 the case that only the cursor has moved.
12625 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12626 last screen line's vertical height extends past the end of the screen.
12630 1 if scrolling succeeded
12632 0 if scrolling didn't find point.
12634 -1 if new fonts have been loaded so that we must interrupt
12635 redisplay, adjust glyph matrices, and try again. */
12641 SCROLLING_NEED_LARGER_MATRICES
12645 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12646 scroll_step
, temp_scroll_step
, last_line_misfit
)
12647 Lisp_Object window
;
12648 int just_this_one_p
;
12649 EMACS_INT scroll_conservatively
, scroll_step
;
12650 int temp_scroll_step
;
12651 int last_line_misfit
;
12653 struct window
*w
= XWINDOW (window
);
12654 struct frame
*f
= XFRAME (w
->frame
);
12655 struct text_pos pos
, startp
;
12657 int this_scroll_margin
, scroll_max
, rc
, height
;
12658 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
12659 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12660 Lisp_Object aggressive
;
12661 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
12664 debug_method_add (w
, "try_scrolling");
12667 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12669 /* Compute scroll margin height in pixels. We scroll when point is
12670 within this distance from the top or bottom of the window. */
12671 if (scroll_margin
> 0)
12673 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12674 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12677 this_scroll_margin
= 0;
12679 /* Force scroll_conservatively to have a reasonable value, to avoid
12680 overflow while computing how much to scroll. Note that it's
12681 fairly common for users to supply scroll-conservatively equal to
12682 `most-positive-fixnum', which can be larger than INT_MAX. */
12683 if (scroll_conservatively
> scroll_limit
)
12685 scroll_conservatively
= scroll_limit
;
12686 scroll_max
= INT_MAX
;
12688 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12689 /* Compute how much we should try to scroll maximally to bring
12690 point into view. */
12691 scroll_max
= (max (scroll_step
,
12692 max (scroll_conservatively
, temp_scroll_step
))
12693 * FRAME_LINE_HEIGHT (f
));
12694 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12695 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12696 /* We're trying to scroll because of aggressive scrolling but no
12697 scroll_step is set. Choose an arbitrary one. */
12698 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
12704 /* Decide whether we have to scroll down. */
12705 if (PT
> CHARPOS (startp
))
12707 int scroll_margin_y
;
12709 /* Compute the pixel ypos of the scroll margin, then move it to
12710 either that ypos or PT, whichever comes first. */
12711 start_display (&it
, w
, startp
);
12712 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
12713 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
12714 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
12715 (MOVE_TO_POS
| MOVE_TO_Y
));
12717 if (PT
> CHARPOS (it
.current
.pos
))
12719 /* Point is in the scroll margin at the bottom of the
12720 window, or below. Compute the distance from the scroll
12721 margin to PT, and give up if the distance is greater than
12723 move_it_to (&it
, PT
, -1, it
.last_visible_y
- 1, -1,
12724 MOVE_TO_POS
| MOVE_TO_Y
);
12726 /* To make point visible, we must move the window start down
12727 so that the cursor line is visible, which means we have
12728 to add in the height of the cursor line. */
12729 dy
= line_bottom_y (&it
) - scroll_margin_y
;
12731 if (dy
> scroll_max
)
12732 return SCROLLING_FAILED
;
12740 /* Move the window start down. If scrolling conservatively,
12741 move it just enough down to make point visible. If
12742 scroll_step is set, move it down by scroll_step. */
12743 start_display (&it
, w
, startp
);
12745 if (scroll_conservatively
)
12746 /* Set AMOUNT_TO_SCROLL to at least one line,
12747 and at most scroll_conservatively lines. */
12749 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12750 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12751 else if (scroll_step
|| temp_scroll_step
)
12752 amount_to_scroll
= scroll_max
;
12755 aggressive
= current_buffer
->scroll_up_aggressively
;
12756 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12757 if (NUMBERP (aggressive
))
12759 double float_amount
= XFLOATINT (aggressive
) * height
;
12760 amount_to_scroll
= float_amount
;
12761 if (amount_to_scroll
== 0 && float_amount
> 0)
12762 amount_to_scroll
= 1;
12766 if (amount_to_scroll
<= 0)
12767 return SCROLLING_FAILED
;
12769 /* If moving by amount_to_scroll leaves STARTP unchanged,
12770 move it down one screen line. */
12772 move_it_vertically (&it
, amount_to_scroll
);
12773 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12774 move_it_by_lines (&it
, 1, 1);
12775 startp
= it
.current
.pos
;
12779 struct text_pos scroll_margin_pos
= startp
;
12781 /* See if point is inside the scroll margin at the top of the
12783 if (this_scroll_margin
)
12785 start_display (&it
, w
, startp
);
12786 move_it_vertically (&it
, this_scroll_margin
);
12787 scroll_margin_pos
= it
.current
.pos
;
12790 if (PT
< CHARPOS (scroll_margin_pos
))
12792 /* Point is in the scroll margin at the top of the window or
12793 above what is displayed in the window. */
12796 /* Compute the vertical distance from PT to the scroll
12797 margin position. Give up if distance is greater than
12799 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12800 start_display (&it
, w
, pos
);
12802 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12803 it
.last_visible_y
, -1,
12804 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12805 dy
= it
.current_y
- y0
;
12806 if (dy
> scroll_max
)
12807 return SCROLLING_FAILED
;
12809 /* Compute new window start. */
12810 start_display (&it
, w
, startp
);
12812 if (scroll_conservatively
)
12814 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12815 else if (scroll_step
|| temp_scroll_step
)
12816 amount_to_scroll
= scroll_max
;
12819 aggressive
= current_buffer
->scroll_down_aggressively
;
12820 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12821 if (NUMBERP (aggressive
))
12823 double float_amount
= XFLOATINT (aggressive
) * height
;
12824 amount_to_scroll
= float_amount
;
12825 if (amount_to_scroll
== 0 && float_amount
> 0)
12826 amount_to_scroll
= 1;
12830 if (amount_to_scroll
<= 0)
12831 return SCROLLING_FAILED
;
12833 move_it_vertically_backward (&it
, amount_to_scroll
);
12834 startp
= it
.current
.pos
;
12838 /* Run window scroll functions. */
12839 startp
= run_window_scroll_functions (window
, startp
);
12841 /* Display the window. Give up if new fonts are loaded, or if point
12843 if (!try_window (window
, startp
, 0))
12844 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12845 else if (w
->cursor
.vpos
< 0)
12847 clear_glyph_matrix (w
->desired_matrix
);
12848 rc
= SCROLLING_FAILED
;
12852 /* Maybe forget recorded base line for line number display. */
12853 if (!just_this_one_p
12854 || current_buffer
->clip_changed
12855 || BEG_UNCHANGED
< CHARPOS (startp
))
12856 w
->base_line_number
= Qnil
;
12858 /* If cursor ends up on a partially visible line,
12859 treat that as being off the bottom of the screen. */
12860 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12862 clear_glyph_matrix (w
->desired_matrix
);
12863 ++extra_scroll_margin_lines
;
12866 rc
= SCROLLING_SUCCESS
;
12873 /* Compute a suitable window start for window W if display of W starts
12874 on a continuation line. Value is non-zero if a new window start
12877 The new window start will be computed, based on W's width, starting
12878 from the start of the continued line. It is the start of the
12879 screen line with the minimum distance from the old start W->start. */
12882 compute_window_start_on_continuation_line (w
)
12885 struct text_pos pos
, start_pos
;
12886 int window_start_changed_p
= 0;
12888 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12890 /* If window start is on a continuation line... Window start may be
12891 < BEGV in case there's invisible text at the start of the
12892 buffer (M-x rmail, for example). */
12893 if (CHARPOS (start_pos
) > BEGV
12894 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12897 struct glyph_row
*row
;
12899 /* Handle the case that the window start is out of range. */
12900 if (CHARPOS (start_pos
) < BEGV
)
12901 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12902 else if (CHARPOS (start_pos
) > ZV
)
12903 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12905 /* Find the start of the continued line. This should be fast
12906 because scan_buffer is fast (newline cache). */
12907 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12908 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12909 row
, DEFAULT_FACE_ID
);
12910 reseat_at_previous_visible_line_start (&it
);
12912 /* If the line start is "too far" away from the window start,
12913 say it takes too much time to compute a new window start. */
12914 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12915 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12917 int min_distance
, distance
;
12919 /* Move forward by display lines to find the new window
12920 start. If window width was enlarged, the new start can
12921 be expected to be > the old start. If window width was
12922 decreased, the new window start will be < the old start.
12923 So, we're looking for the display line start with the
12924 minimum distance from the old window start. */
12925 pos
= it
.current
.pos
;
12926 min_distance
= INFINITY
;
12927 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12928 distance
< min_distance
)
12930 min_distance
= distance
;
12931 pos
= it
.current
.pos
;
12932 move_it_by_lines (&it
, 1, 0);
12935 /* Set the window start there. */
12936 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12937 window_start_changed_p
= 1;
12941 return window_start_changed_p
;
12945 /* Try cursor movement in case text has not changed in window WINDOW,
12946 with window start STARTP. Value is
12948 CURSOR_MOVEMENT_SUCCESS if successful
12950 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12952 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12953 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12954 we want to scroll as if scroll-step were set to 1. See the code.
12956 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12957 which case we have to abort this redisplay, and adjust matrices
12962 CURSOR_MOVEMENT_SUCCESS
,
12963 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12964 CURSOR_MOVEMENT_MUST_SCROLL
,
12965 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12969 try_cursor_movement (window
, startp
, scroll_step
)
12970 Lisp_Object window
;
12971 struct text_pos startp
;
12974 struct window
*w
= XWINDOW (window
);
12975 struct frame
*f
= XFRAME (w
->frame
);
12976 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12979 if (inhibit_try_cursor_movement
)
12983 /* Handle case where text has not changed, only point, and it has
12984 not moved off the frame. */
12985 if (/* Point may be in this window. */
12986 PT
>= CHARPOS (startp
)
12987 /* Selective display hasn't changed. */
12988 && !current_buffer
->clip_changed
12989 /* Function force-mode-line-update is used to force a thorough
12990 redisplay. It sets either windows_or_buffers_changed or
12991 update_mode_lines. So don't take a shortcut here for these
12993 && !update_mode_lines
12994 && !windows_or_buffers_changed
12995 && !cursor_type_changed
12996 /* Can't use this case if highlighting a region. When a
12997 region exists, cursor movement has to do more than just
12999 && !(!NILP (Vtransient_mark_mode
)
13000 && !NILP (current_buffer
->mark_active
))
13001 && NILP (w
->region_showing
)
13002 && NILP (Vshow_trailing_whitespace
)
13003 /* Right after splitting windows, last_point may be nil. */
13004 && INTEGERP (w
->last_point
)
13005 /* This code is not used for mini-buffer for the sake of the case
13006 of redisplaying to replace an echo area message; since in
13007 that case the mini-buffer contents per se are usually
13008 unchanged. This code is of no real use in the mini-buffer
13009 since the handling of this_line_start_pos, etc., in redisplay
13010 handles the same cases. */
13011 && !EQ (window
, minibuf_window
)
13012 /* When splitting windows or for new windows, it happens that
13013 redisplay is called with a nil window_end_vpos or one being
13014 larger than the window. This should really be fixed in
13015 window.c. I don't have this on my list, now, so we do
13016 approximately the same as the old redisplay code. --gerd. */
13017 && INTEGERP (w
->window_end_vpos
)
13018 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13019 && (FRAME_WINDOW_P (f
)
13020 || !overlay_arrow_in_current_buffer_p ()))
13022 int this_scroll_margin
, top_scroll_margin
;
13023 struct glyph_row
*row
= NULL
;
13026 debug_method_add (w
, "cursor movement");
13029 /* Scroll if point within this distance from the top or bottom
13030 of the window. This is a pixel value. */
13031 if (scroll_margin
> 0)
13033 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13034 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13037 this_scroll_margin
= 0;
13039 top_scroll_margin
= this_scroll_margin
;
13040 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13041 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13043 /* Start with the row the cursor was displayed during the last
13044 not paused redisplay. Give up if that row is not valid. */
13045 if (w
->last_cursor
.vpos
< 0
13046 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13047 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13050 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13051 if (row
->mode_line_p
)
13053 if (!row
->enabled_p
)
13054 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13057 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13060 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13062 if (PT
> XFASTINT (w
->last_point
))
13064 /* Point has moved forward. */
13065 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13066 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13068 xassert (row
->enabled_p
);
13072 /* The end position of a row equals the start position
13073 of the next row. If PT is there, we would rather
13074 display it in the next line. */
13075 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13076 && MATRIX_ROW_END_CHARPOS (row
) == PT
13077 && !cursor_row_p (w
, row
))
13080 /* If within the scroll margin, scroll. Note that
13081 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13082 the next line would be drawn, and that
13083 this_scroll_margin can be zero. */
13084 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13085 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13086 /* Line is completely visible last line in window
13087 and PT is to be set in the next line. */
13088 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13089 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13090 && !row
->ends_at_zv_p
13091 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13094 else if (PT
< XFASTINT (w
->last_point
))
13096 /* Cursor has to be moved backward. Note that PT >=
13097 CHARPOS (startp) because of the outer if-statement. */
13098 while (!row
->mode_line_p
13099 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13100 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13101 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13102 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13103 row
> w
->current_matrix
->rows
13104 && (row
-1)->ends_in_newline_from_string_p
))))
13105 && (row
->y
> top_scroll_margin
13106 || CHARPOS (startp
) == BEGV
))
13108 xassert (row
->enabled_p
);
13112 /* Consider the following case: Window starts at BEGV,
13113 there is invisible, intangible text at BEGV, so that
13114 display starts at some point START > BEGV. It can
13115 happen that we are called with PT somewhere between
13116 BEGV and START. Try to handle that case. */
13117 if (row
< w
->current_matrix
->rows
13118 || row
->mode_line_p
)
13120 row
= w
->current_matrix
->rows
;
13121 if (row
->mode_line_p
)
13125 /* Due to newlines in overlay strings, we may have to
13126 skip forward over overlay strings. */
13127 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13128 && MATRIX_ROW_END_CHARPOS (row
) == PT
13129 && !cursor_row_p (w
, row
))
13132 /* If within the scroll margin, scroll. */
13133 if (row
->y
< top_scroll_margin
13134 && CHARPOS (startp
) != BEGV
)
13139 /* Cursor did not move. So don't scroll even if cursor line
13140 is partially visible, as it was so before. */
13141 rc
= CURSOR_MOVEMENT_SUCCESS
;
13144 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13145 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13147 /* if PT is not in the glyph row, give up. */
13148 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13150 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13151 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13152 && make_cursor_line_fully_visible_p
)
13154 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13155 && !row
->ends_at_zv_p
13156 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13157 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13158 else if (row
->height
> window_box_height (w
))
13160 /* If we end up in a partially visible line, let's
13161 make it fully visible, except when it's taller
13162 than the window, in which case we can't do much
13165 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13169 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13170 if (!cursor_row_fully_visible_p (w
, 0, 1))
13171 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13173 rc
= CURSOR_MOVEMENT_SUCCESS
;
13177 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13182 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13184 rc
= CURSOR_MOVEMENT_SUCCESS
;
13189 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13190 && MATRIX_ROW_START_CHARPOS (row
) == PT
13191 && cursor_row_p (w
, row
));
13200 set_vertical_scroll_bar (w
)
13203 int start
, end
, whole
;
13205 /* Calculate the start and end positions for the current window.
13206 At some point, it would be nice to choose between scrollbars
13207 which reflect the whole buffer size, with special markers
13208 indicating narrowing, and scrollbars which reflect only the
13211 Note that mini-buffers sometimes aren't displaying any text. */
13212 if (!MINI_WINDOW_P (w
)
13213 || (w
== XWINDOW (minibuf_window
)
13214 && NILP (echo_area_buffer
[0])))
13216 struct buffer
*buf
= XBUFFER (w
->buffer
);
13217 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13218 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13219 /* I don't think this is guaranteed to be right. For the
13220 moment, we'll pretend it is. */
13221 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13225 if (whole
< (end
- start
))
13226 whole
= end
- start
;
13229 start
= end
= whole
= 0;
13231 /* Indicate what this scroll bar ought to be displaying now. */
13232 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13233 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13234 (w
, end
- start
, whole
, start
);
13238 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13239 selected_window is redisplayed.
13241 We can return without actually redisplaying the window if
13242 fonts_changed_p is nonzero. In that case, redisplay_internal will
13246 redisplay_window (window
, just_this_one_p
)
13247 Lisp_Object window
;
13248 int just_this_one_p
;
13250 struct window
*w
= XWINDOW (window
);
13251 struct frame
*f
= XFRAME (w
->frame
);
13252 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13253 struct buffer
*old
= current_buffer
;
13254 struct text_pos lpoint
, opoint
, startp
;
13255 int update_mode_line
;
13258 /* Record it now because it's overwritten. */
13259 int current_matrix_up_to_date_p
= 0;
13260 int used_current_matrix_p
= 0;
13261 /* This is less strict than current_matrix_up_to_date_p.
13262 It indictes that the buffer contents and narrowing are unchanged. */
13263 int buffer_unchanged_p
= 0;
13264 int temp_scroll_step
= 0;
13265 int count
= SPECPDL_INDEX ();
13267 int centering_position
= -1;
13268 int last_line_misfit
= 0;
13269 int beg_unchanged
, end_unchanged
;
13271 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13274 /* W must be a leaf window here. */
13275 xassert (!NILP (w
->buffer
));
13277 *w
->desired_matrix
->method
= 0;
13281 reconsider_clip_changes (w
, buffer
);
13283 /* Has the mode line to be updated? */
13284 update_mode_line
= (!NILP (w
->update_mode_line
)
13285 || update_mode_lines
13286 || buffer
->clip_changed
13287 || buffer
->prevent_redisplay_optimizations_p
);
13289 if (MINI_WINDOW_P (w
))
13291 if (w
== XWINDOW (echo_area_window
)
13292 && !NILP (echo_area_buffer
[0]))
13294 if (update_mode_line
)
13295 /* We may have to update a tty frame's menu bar or a
13296 tool-bar. Example `M-x C-h C-h C-g'. */
13297 goto finish_menu_bars
;
13299 /* We've already displayed the echo area glyphs in this window. */
13300 goto finish_scroll_bars
;
13302 else if ((w
!= XWINDOW (minibuf_window
)
13303 || minibuf_level
== 0)
13304 /* When buffer is nonempty, redisplay window normally. */
13305 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13306 /* Quail displays non-mini buffers in minibuffer window.
13307 In that case, redisplay the window normally. */
13308 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13310 /* W is a mini-buffer window, but it's not active, so clear
13312 int yb
= window_text_bottom_y (w
);
13313 struct glyph_row
*row
;
13316 for (y
= 0, row
= w
->desired_matrix
->rows
;
13318 y
+= row
->height
, ++row
)
13319 blank_row (w
, row
, y
);
13320 goto finish_scroll_bars
;
13323 clear_glyph_matrix (w
->desired_matrix
);
13326 /* Otherwise set up data on this window; select its buffer and point
13328 /* Really select the buffer, for the sake of buffer-local
13330 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13332 current_matrix_up_to_date_p
13333 = (!NILP (w
->window_end_valid
)
13334 && !current_buffer
->clip_changed
13335 && !current_buffer
->prevent_redisplay_optimizations_p
13336 && XFASTINT (w
->last_modified
) >= MODIFF
13337 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13339 /* Run the window-bottom-change-functions
13340 if it is possible that the text on the screen has changed
13341 (either due to modification of the text, or any other reason). */
13342 if (!current_matrix_up_to_date_p
13343 && !NILP (Vwindow_text_change_functions
))
13345 safe_run_hooks (Qwindow_text_change_functions
);
13349 beg_unchanged
= BEG_UNCHANGED
;
13350 end_unchanged
= END_UNCHANGED
;
13352 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13354 specbind (Qinhibit_point_motion_hooks
, Qt
);
13357 = (!NILP (w
->window_end_valid
)
13358 && !current_buffer
->clip_changed
13359 && XFASTINT (w
->last_modified
) >= MODIFF
13360 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13362 /* When windows_or_buffers_changed is non-zero, we can't rely on
13363 the window end being valid, so set it to nil there. */
13364 if (windows_or_buffers_changed
)
13366 /* If window starts on a continuation line, maybe adjust the
13367 window start in case the window's width changed. */
13368 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13369 compute_window_start_on_continuation_line (w
);
13371 w
->window_end_valid
= Qnil
;
13374 /* Some sanity checks. */
13375 CHECK_WINDOW_END (w
);
13376 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13378 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13381 /* If %c is in mode line, update it if needed. */
13382 if (!NILP (w
->column_number_displayed
)
13383 /* This alternative quickly identifies a common case
13384 where no change is needed. */
13385 && !(PT
== XFASTINT (w
->last_point
)
13386 && XFASTINT (w
->last_modified
) >= MODIFF
13387 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13388 && (XFASTINT (w
->column_number_displayed
)
13389 != (int) current_column ())) /* iftc */
13390 update_mode_line
= 1;
13392 /* Count number of windows showing the selected buffer. An indirect
13393 buffer counts as its base buffer. */
13394 if (!just_this_one_p
)
13396 struct buffer
*current_base
, *window_base
;
13397 current_base
= current_buffer
;
13398 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13399 if (current_base
->base_buffer
)
13400 current_base
= current_base
->base_buffer
;
13401 if (window_base
->base_buffer
)
13402 window_base
= window_base
->base_buffer
;
13403 if (current_base
== window_base
)
13407 /* Point refers normally to the selected window. For any other
13408 window, set up appropriate value. */
13409 if (!EQ (window
, selected_window
))
13411 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13412 int new_pt_byte
= marker_byte_position (w
->pointm
);
13416 new_pt_byte
= BEGV_BYTE
;
13417 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13419 else if (new_pt
> (ZV
- 1))
13422 new_pt_byte
= ZV_BYTE
;
13423 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13426 /* We don't use SET_PT so that the point-motion hooks don't run. */
13427 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13430 /* If any of the character widths specified in the display table
13431 have changed, invalidate the width run cache. It's true that
13432 this may be a bit late to catch such changes, but the rest of
13433 redisplay goes (non-fatally) haywire when the display table is
13434 changed, so why should we worry about doing any better? */
13435 if (current_buffer
->width_run_cache
)
13437 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13439 if (! disptab_matches_widthtab (disptab
,
13440 XVECTOR (current_buffer
->width_table
)))
13442 invalidate_region_cache (current_buffer
,
13443 current_buffer
->width_run_cache
,
13445 recompute_width_table (current_buffer
, disptab
);
13449 /* If window-start is screwed up, choose a new one. */
13450 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13453 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13455 /* If someone specified a new starting point but did not insist,
13456 check whether it can be used. */
13457 if (!NILP (w
->optional_new_start
)
13458 && CHARPOS (startp
) >= BEGV
13459 && CHARPOS (startp
) <= ZV
)
13461 w
->optional_new_start
= Qnil
;
13462 start_display (&it
, w
, startp
);
13463 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13464 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13465 if (IT_CHARPOS (it
) == PT
)
13466 w
->force_start
= Qt
;
13467 /* IT may overshoot PT if text at PT is invisible. */
13468 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13469 w
->force_start
= Qt
;
13474 /* Handle case where place to start displaying has been specified,
13475 unless the specified location is outside the accessible range. */
13476 if (!NILP (w
->force_start
)
13477 || w
->frozen_window_start_p
)
13479 /* We set this later on if we have to adjust point. */
13482 w
->force_start
= Qnil
;
13484 w
->window_end_valid
= Qnil
;
13486 /* Forget any recorded base line for line number display. */
13487 if (!buffer_unchanged_p
)
13488 w
->base_line_number
= Qnil
;
13490 /* Redisplay the mode line. Select the buffer properly for that.
13491 Also, run the hook window-scroll-functions
13492 because we have scrolled. */
13493 /* Note, we do this after clearing force_start because
13494 if there's an error, it is better to forget about force_start
13495 than to get into an infinite loop calling the hook functions
13496 and having them get more errors. */
13497 if (!update_mode_line
13498 || ! NILP (Vwindow_scroll_functions
))
13500 update_mode_line
= 1;
13501 w
->update_mode_line
= Qt
;
13502 startp
= run_window_scroll_functions (window
, startp
);
13505 w
->last_modified
= make_number (0);
13506 w
->last_overlay_modified
= make_number (0);
13507 if (CHARPOS (startp
) < BEGV
)
13508 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13509 else if (CHARPOS (startp
) > ZV
)
13510 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13512 /* Redisplay, then check if cursor has been set during the
13513 redisplay. Give up if new fonts were loaded. */
13514 /* We used to issue a CHECK_MARGINS argument to try_window here,
13515 but this causes scrolling to fail when point begins inside
13516 the scroll margin (bug#148) -- cyd */
13517 if (!try_window (window
, startp
, 0))
13519 w
->force_start
= Qt
;
13520 clear_glyph_matrix (w
->desired_matrix
);
13521 goto need_larger_matrices
;
13524 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13526 /* If point does not appear, try to move point so it does
13527 appear. The desired matrix has been built above, so we
13528 can use it here. */
13529 new_vpos
= window_box_height (w
) / 2;
13532 if (!cursor_row_fully_visible_p (w
, 0, 0))
13534 /* Point does appear, but on a line partly visible at end of window.
13535 Move it back to a fully-visible line. */
13536 new_vpos
= window_box_height (w
);
13539 /* If we need to move point for either of the above reasons,
13540 now actually do it. */
13543 struct glyph_row
*row
;
13545 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13546 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13549 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13550 MATRIX_ROW_START_BYTEPOS (row
));
13552 if (w
!= XWINDOW (selected_window
))
13553 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13554 else if (current_buffer
== old
)
13555 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13557 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13559 /* If we are highlighting the region, then we just changed
13560 the region, so redisplay to show it. */
13561 if (!NILP (Vtransient_mark_mode
)
13562 && !NILP (current_buffer
->mark_active
))
13564 clear_glyph_matrix (w
->desired_matrix
);
13565 if (!try_window (window
, startp
, 0))
13566 goto need_larger_matrices
;
13571 debug_method_add (w
, "forced window start");
13576 /* Handle case where text has not changed, only point, and it has
13577 not moved off the frame, and we are not retrying after hscroll.
13578 (current_matrix_up_to_date_p is nonzero when retrying.) */
13579 if (current_matrix_up_to_date_p
13580 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13581 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13585 case CURSOR_MOVEMENT_SUCCESS
:
13586 used_current_matrix_p
= 1;
13589 #if 0 /* try_cursor_movement never returns this value. */
13590 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13591 goto need_larger_matrices
;
13594 case CURSOR_MOVEMENT_MUST_SCROLL
:
13595 goto try_to_scroll
;
13601 /* If current starting point was originally the beginning of a line
13602 but no longer is, find a new starting point. */
13603 else if (!NILP (w
->start_at_line_beg
)
13604 && !(CHARPOS (startp
) <= BEGV
13605 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13608 debug_method_add (w
, "recenter 1");
13613 /* Try scrolling with try_window_id. Value is > 0 if update has
13614 been done, it is -1 if we know that the same window start will
13615 not work. It is 0 if unsuccessful for some other reason. */
13616 else if ((tem
= try_window_id (w
)) != 0)
13619 debug_method_add (w
, "try_window_id %d", tem
);
13622 if (fonts_changed_p
)
13623 goto need_larger_matrices
;
13627 /* Otherwise try_window_id has returned -1 which means that we
13628 don't want the alternative below this comment to execute. */
13630 else if (CHARPOS (startp
) >= BEGV
13631 && CHARPOS (startp
) <= ZV
13632 && PT
>= CHARPOS (startp
)
13633 && (CHARPOS (startp
) < ZV
13634 /* Avoid starting at end of buffer. */
13635 || CHARPOS (startp
) == BEGV
13636 || (XFASTINT (w
->last_modified
) >= MODIFF
13637 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13640 /* If first window line is a continuation line, and window start
13641 is inside the modified region, but the first change is before
13642 current window start, we must select a new window start.
13644 However, if this is the result of a down-mouse event (e.g. by
13645 extending the mouse-drag-overlay), we don't want to select a
13646 new window start, since that would change the position under
13647 the mouse, resulting in an unwanted mouse-movement rather
13648 than a simple mouse-click. */
13649 if (NILP (w
->start_at_line_beg
)
13650 && NILP (do_mouse_tracking
)
13651 && CHARPOS (startp
) > BEGV
13652 && CHARPOS (startp
) > BEG
+ beg_unchanged
13653 && CHARPOS (startp
) <= Z
- end_unchanged
13654 /* Even if w->start_at_line_beg is nil, a new window may
13655 start at a line_beg, since that's how set_buffer_window
13656 sets it. So, we need to check the return value of
13657 compute_window_start_on_continuation_line. (See also
13659 && XMARKER (w
->start
)->buffer
== current_buffer
13660 && compute_window_start_on_continuation_line (w
))
13662 w
->force_start
= Qt
;
13663 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13668 debug_method_add (w
, "same window start");
13671 /* Try to redisplay starting at same place as before.
13672 If point has not moved off frame, accept the results. */
13673 if (!current_matrix_up_to_date_p
13674 /* Don't use try_window_reusing_current_matrix in this case
13675 because a window scroll function can have changed the
13677 || !NILP (Vwindow_scroll_functions
)
13678 || MINI_WINDOW_P (w
)
13679 || !(used_current_matrix_p
13680 = try_window_reusing_current_matrix (w
)))
13682 IF_DEBUG (debug_method_add (w
, "1"));
13683 if (try_window (window
, startp
, 1) < 0)
13684 /* -1 means we need to scroll.
13685 0 means we need new matrices, but fonts_changed_p
13686 is set in that case, so we will detect it below. */
13687 goto try_to_scroll
;
13690 if (fonts_changed_p
)
13691 goto need_larger_matrices
;
13693 if (w
->cursor
.vpos
>= 0)
13695 if (!just_this_one_p
13696 || current_buffer
->clip_changed
13697 || BEG_UNCHANGED
< CHARPOS (startp
))
13698 /* Forget any recorded base line for line number display. */
13699 w
->base_line_number
= Qnil
;
13701 if (!cursor_row_fully_visible_p (w
, 1, 0))
13703 clear_glyph_matrix (w
->desired_matrix
);
13704 last_line_misfit
= 1;
13706 /* Drop through and scroll. */
13711 clear_glyph_matrix (w
->desired_matrix
);
13716 w
->last_modified
= make_number (0);
13717 w
->last_overlay_modified
= make_number (0);
13719 /* Redisplay the mode line. Select the buffer properly for that. */
13720 if (!update_mode_line
)
13722 update_mode_line
= 1;
13723 w
->update_mode_line
= Qt
;
13726 /* Try to scroll by specified few lines. */
13727 if ((scroll_conservatively
13729 || temp_scroll_step
13730 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13731 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13732 && !current_buffer
->clip_changed
13733 && CHARPOS (startp
) >= BEGV
13734 && CHARPOS (startp
) <= ZV
)
13736 /* The function returns -1 if new fonts were loaded, 1 if
13737 successful, 0 if not successful. */
13738 int rc
= try_scrolling (window
, just_this_one_p
,
13739 scroll_conservatively
,
13741 temp_scroll_step
, last_line_misfit
);
13744 case SCROLLING_SUCCESS
:
13747 case SCROLLING_NEED_LARGER_MATRICES
:
13748 goto need_larger_matrices
;
13750 case SCROLLING_FAILED
:
13758 /* Finally, just choose place to start which centers point */
13761 if (centering_position
< 0)
13762 centering_position
= window_box_height (w
) / 2;
13765 debug_method_add (w
, "recenter");
13768 /* w->vscroll = 0; */
13770 /* Forget any previously recorded base line for line number display. */
13771 if (!buffer_unchanged_p
)
13772 w
->base_line_number
= Qnil
;
13774 /* Move backward half the height of the window. */
13775 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13776 it
.current_y
= it
.last_visible_y
;
13777 move_it_vertically_backward (&it
, centering_position
);
13778 xassert (IT_CHARPOS (it
) >= BEGV
);
13780 /* The function move_it_vertically_backward may move over more
13781 than the specified y-distance. If it->w is small, e.g. a
13782 mini-buffer window, we may end up in front of the window's
13783 display area. Start displaying at the start of the line
13784 containing PT in this case. */
13785 if (it
.current_y
<= 0)
13787 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13788 move_it_vertically_backward (&it
, 0);
13792 it
.current_x
= it
.hpos
= 0;
13794 /* Set startp here explicitly in case that helps avoid an infinite loop
13795 in case the window-scroll-functions functions get errors. */
13796 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13798 /* Run scroll hooks. */
13799 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13801 /* Redisplay the window. */
13802 if (!current_matrix_up_to_date_p
13803 || windows_or_buffers_changed
13804 || cursor_type_changed
13805 /* Don't use try_window_reusing_current_matrix in this case
13806 because it can have changed the buffer. */
13807 || !NILP (Vwindow_scroll_functions
)
13808 || !just_this_one_p
13809 || MINI_WINDOW_P (w
)
13810 || !(used_current_matrix_p
13811 = try_window_reusing_current_matrix (w
)))
13812 try_window (window
, startp
, 0);
13814 /* If new fonts have been loaded (due to fontsets), give up. We
13815 have to start a new redisplay since we need to re-adjust glyph
13817 if (fonts_changed_p
)
13818 goto need_larger_matrices
;
13820 /* If cursor did not appear assume that the middle of the window is
13821 in the first line of the window. Do it again with the next line.
13822 (Imagine a window of height 100, displaying two lines of height
13823 60. Moving back 50 from it->last_visible_y will end in the first
13825 if (w
->cursor
.vpos
< 0)
13827 if (!NILP (w
->window_end_valid
)
13828 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13830 clear_glyph_matrix (w
->desired_matrix
);
13831 move_it_by_lines (&it
, 1, 0);
13832 try_window (window
, it
.current
.pos
, 0);
13834 else if (PT
< IT_CHARPOS (it
))
13836 clear_glyph_matrix (w
->desired_matrix
);
13837 move_it_by_lines (&it
, -1, 0);
13838 try_window (window
, it
.current
.pos
, 0);
13842 /* Not much we can do about it. */
13846 /* Consider the following case: Window starts at BEGV, there is
13847 invisible, intangible text at BEGV, so that display starts at
13848 some point START > BEGV. It can happen that we are called with
13849 PT somewhere between BEGV and START. Try to handle that case. */
13850 if (w
->cursor
.vpos
< 0)
13852 struct glyph_row
*row
= w
->current_matrix
->rows
;
13853 if (row
->mode_line_p
)
13855 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13858 if (!cursor_row_fully_visible_p (w
, 0, 0))
13860 /* If vscroll is enabled, disable it and try again. */
13864 clear_glyph_matrix (w
->desired_matrix
);
13868 /* If centering point failed to make the whole line visible,
13869 put point at the top instead. That has to make the whole line
13870 visible, if it can be done. */
13871 if (centering_position
== 0)
13874 clear_glyph_matrix (w
->desired_matrix
);
13875 centering_position
= 0;
13881 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13882 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13883 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13886 /* Display the mode line, if we must. */
13887 if ((update_mode_line
13888 /* If window not full width, must redo its mode line
13889 if (a) the window to its side is being redone and
13890 (b) we do a frame-based redisplay. This is a consequence
13891 of how inverted lines are drawn in frame-based redisplay. */
13892 || (!just_this_one_p
13893 && !FRAME_WINDOW_P (f
)
13894 && !WINDOW_FULL_WIDTH_P (w
))
13895 /* Line number to display. */
13896 || INTEGERP (w
->base_line_pos
)
13897 /* Column number is displayed and different from the one displayed. */
13898 || (!NILP (w
->column_number_displayed
)
13899 && (XFASTINT (w
->column_number_displayed
)
13900 != (int) current_column ()))) /* iftc */
13901 /* This means that the window has a mode line. */
13902 && (WINDOW_WANTS_MODELINE_P (w
)
13903 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13905 display_mode_lines (w
);
13907 /* If mode line height has changed, arrange for a thorough
13908 immediate redisplay using the correct mode line height. */
13909 if (WINDOW_WANTS_MODELINE_P (w
)
13910 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13912 fonts_changed_p
= 1;
13913 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13914 = DESIRED_MODE_LINE_HEIGHT (w
);
13917 /* If top line height has changed, arrange for a thorough
13918 immediate redisplay using the correct mode line height. */
13919 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13920 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13922 fonts_changed_p
= 1;
13923 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13924 = DESIRED_HEADER_LINE_HEIGHT (w
);
13927 if (fonts_changed_p
)
13928 goto need_larger_matrices
;
13931 if (!line_number_displayed
13932 && !BUFFERP (w
->base_line_pos
))
13934 w
->base_line_pos
= Qnil
;
13935 w
->base_line_number
= Qnil
;
13940 /* When we reach a frame's selected window, redo the frame's menu bar. */
13941 if (update_mode_line
13942 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13944 int redisplay_menu_p
= 0;
13945 int redisplay_tool_bar_p
= 0;
13947 if (FRAME_WINDOW_P (f
))
13949 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
13950 || defined (HAVE_NS) || defined (USE_GTK)
13951 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13953 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13957 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13959 if (redisplay_menu_p
)
13960 display_menu_bar (w
);
13962 #ifdef HAVE_WINDOW_SYSTEM
13963 if (FRAME_WINDOW_P (f
))
13965 #if defined (USE_GTK) || defined (HAVE_NS) || USE_MAC_TOOLBAR
13966 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13968 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13969 && (FRAME_TOOL_BAR_LINES (f
) > 0
13970 || !NILP (Vauto_resize_tool_bars
));
13973 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13975 extern int ignore_mouse_drag_p
;
13976 ignore_mouse_drag_p
= 1;
13982 #ifdef HAVE_WINDOW_SYSTEM
13983 if (FRAME_WINDOW_P (f
)
13984 && update_window_fringes (w
, (just_this_one_p
13985 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13986 || w
->pseudo_window_p
)))
13990 if (draw_window_fringes (w
, 1))
13991 x_draw_vertical_border (w
);
13995 #endif /* HAVE_WINDOW_SYSTEM */
13997 /* We go to this label, with fonts_changed_p nonzero,
13998 if it is necessary to try again using larger glyph matrices.
13999 We have to redeem the scroll bar even in this case,
14000 because the loop in redisplay_internal expects that. */
14001 need_larger_matrices
:
14003 finish_scroll_bars
:
14005 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14007 /* Set the thumb's position and size. */
14008 set_vertical_scroll_bar (w
);
14010 /* Note that we actually used the scroll bar attached to this
14011 window, so it shouldn't be deleted at the end of redisplay. */
14012 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14013 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14016 /* Restore current_buffer and value of point in it. */
14017 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14018 set_buffer_internal_1 (old
);
14019 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14020 shorter. This can be caused by log truncation in *Messages*. */
14021 if (CHARPOS (lpoint
) <= ZV
)
14022 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14024 unbind_to (count
, Qnil
);
14028 /* Build the complete desired matrix of WINDOW with a window start
14029 buffer position POS.
14031 Value is 1 if successful. It is zero if fonts were loaded during
14032 redisplay which makes re-adjusting glyph matrices necessary, and -1
14033 if point would appear in the scroll margins.
14034 (We check that only if CHECK_MARGINS is nonzero. */
14037 try_window (window
, pos
, check_margins
)
14038 Lisp_Object window
;
14039 struct text_pos pos
;
14042 struct window
*w
= XWINDOW (window
);
14044 struct glyph_row
*last_text_row
= NULL
;
14045 struct frame
*f
= XFRAME (w
->frame
);
14047 /* Make POS the new window start. */
14048 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14050 /* Mark cursor position as unknown. No overlay arrow seen. */
14051 w
->cursor
.vpos
= -1;
14052 overlay_arrow_seen
= 0;
14054 /* Initialize iterator and info to start at POS. */
14055 start_display (&it
, w
, pos
);
14057 /* Display all lines of W. */
14058 while (it
.current_y
< it
.last_visible_y
)
14060 if (display_line (&it
))
14061 last_text_row
= it
.glyph_row
- 1;
14062 if (fonts_changed_p
)
14066 /* Don't let the cursor end in the scroll margins. */
14068 && !MINI_WINDOW_P (w
))
14070 int this_scroll_margin
;
14072 if (scroll_margin
> 0)
14074 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14075 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14078 this_scroll_margin
= 0;
14080 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14081 && w
->cursor
.y
< this_scroll_margin
14082 && CHARPOS (pos
) > BEGV
14083 && IT_CHARPOS (it
) < ZV
)
14084 /* rms: considering make_cursor_line_fully_visible_p here
14085 seems to give wrong results. We don't want to recenter
14086 when the last line is partly visible, we want to allow
14087 that case to be handled in the usual way. */
14088 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14090 w
->cursor
.vpos
= -1;
14091 clear_glyph_matrix (w
->desired_matrix
);
14096 /* If bottom moved off end of frame, change mode line percentage. */
14097 if (XFASTINT (w
->window_end_pos
) <= 0
14098 && Z
!= IT_CHARPOS (it
))
14099 w
->update_mode_line
= Qt
;
14101 /* Set window_end_pos to the offset of the last character displayed
14102 on the window from the end of current_buffer. Set
14103 window_end_vpos to its row number. */
14106 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14107 w
->window_end_bytepos
14108 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14110 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14112 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14113 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14114 ->displays_text_p
);
14118 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14119 w
->window_end_pos
= make_number (Z
- ZV
);
14120 w
->window_end_vpos
= make_number (0);
14123 /* But that is not valid info until redisplay finishes. */
14124 w
->window_end_valid
= Qnil
;
14130 /************************************************************************
14131 Window redisplay reusing current matrix when buffer has not changed
14132 ************************************************************************/
14134 /* Try redisplay of window W showing an unchanged buffer with a
14135 different window start than the last time it was displayed by
14136 reusing its current matrix. Value is non-zero if successful.
14137 W->start is the new window start. */
14140 try_window_reusing_current_matrix (w
)
14143 struct frame
*f
= XFRAME (w
->frame
);
14144 struct glyph_row
*row
, *bottom_row
;
14147 struct text_pos start
, new_start
;
14148 int nrows_scrolled
, i
;
14149 struct glyph_row
*last_text_row
;
14150 struct glyph_row
*last_reused_text_row
;
14151 struct glyph_row
*start_row
;
14152 int start_vpos
, min_y
, max_y
;
14155 if (inhibit_try_window_reusing
)
14159 if (/* This function doesn't handle terminal frames. */
14160 !FRAME_WINDOW_P (f
)
14161 /* Don't try to reuse the display if windows have been split
14163 || windows_or_buffers_changed
14164 || cursor_type_changed
)
14167 /* Can't do this if region may have changed. */
14168 if ((!NILP (Vtransient_mark_mode
)
14169 && !NILP (current_buffer
->mark_active
))
14170 || !NILP (w
->region_showing
)
14171 || !NILP (Vshow_trailing_whitespace
))
14174 /* If top-line visibility has changed, give up. */
14175 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14176 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14179 /* Give up if old or new display is scrolled vertically. We could
14180 make this function handle this, but right now it doesn't. */
14181 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14182 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14185 /* The variable new_start now holds the new window start. The old
14186 start `start' can be determined from the current matrix. */
14187 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14188 start
= start_row
->start
.pos
;
14189 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14191 /* Clear the desired matrix for the display below. */
14192 clear_glyph_matrix (w
->desired_matrix
);
14194 if (CHARPOS (new_start
) <= CHARPOS (start
))
14198 /* Don't use this method if the display starts with an ellipsis
14199 displayed for invisible text. It's not easy to handle that case
14200 below, and it's certainly not worth the effort since this is
14201 not a frequent case. */
14202 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14205 IF_DEBUG (debug_method_add (w
, "twu1"));
14207 /* Display up to a row that can be reused. The variable
14208 last_text_row is set to the last row displayed that displays
14209 text. Note that it.vpos == 0 if or if not there is a
14210 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14211 start_display (&it
, w
, new_start
);
14212 first_row_y
= it
.current_y
;
14213 w
->cursor
.vpos
= -1;
14214 last_text_row
= last_reused_text_row
= NULL
;
14216 while (it
.current_y
< it
.last_visible_y
14217 && !fonts_changed_p
)
14219 /* If we have reached into the characters in the START row,
14220 that means the line boundaries have changed. So we
14221 can't start copying with the row START. Maybe it will
14222 work to start copying with the following row. */
14223 while (IT_CHARPOS (it
) > CHARPOS (start
))
14225 /* Advance to the next row as the "start". */
14227 start
= start_row
->start
.pos
;
14228 /* If there are no more rows to try, or just one, give up. */
14229 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14230 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14231 || CHARPOS (start
) == ZV
)
14233 clear_glyph_matrix (w
->desired_matrix
);
14237 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14239 /* If we have reached alignment,
14240 we can copy the rest of the rows. */
14241 if (IT_CHARPOS (it
) == CHARPOS (start
))
14244 if (display_line (&it
))
14245 last_text_row
= it
.glyph_row
- 1;
14248 /* A value of current_y < last_visible_y means that we stopped
14249 at the previous window start, which in turn means that we
14250 have at least one reusable row. */
14251 if (it
.current_y
< it
.last_visible_y
)
14253 /* IT.vpos always starts from 0; it counts text lines. */
14254 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14256 /* Find PT if not already found in the lines displayed. */
14257 if (w
->cursor
.vpos
< 0)
14259 int dy
= it
.current_y
- start_row
->y
;
14261 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14262 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14264 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14265 dy
, nrows_scrolled
);
14268 clear_glyph_matrix (w
->desired_matrix
);
14273 /* Scroll the display. Do it before the current matrix is
14274 changed. The problem here is that update has not yet
14275 run, i.e. part of the current matrix is not up to date.
14276 scroll_run_hook will clear the cursor, and use the
14277 current matrix to get the height of the row the cursor is
14279 run
.current_y
= start_row
->y
;
14280 run
.desired_y
= it
.current_y
;
14281 run
.height
= it
.last_visible_y
- it
.current_y
;
14283 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14286 FRAME_RIF (f
)->update_window_begin_hook (w
);
14287 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14288 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14289 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14293 /* Shift current matrix down by nrows_scrolled lines. */
14294 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14295 rotate_matrix (w
->current_matrix
,
14297 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14300 /* Disable lines that must be updated. */
14301 for (i
= 0; i
< nrows_scrolled
; ++i
)
14302 (start_row
+ i
)->enabled_p
= 0;
14304 /* Re-compute Y positions. */
14305 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14306 max_y
= it
.last_visible_y
;
14307 for (row
= start_row
+ nrows_scrolled
;
14311 row
->y
= it
.current_y
;
14312 row
->visible_height
= row
->height
;
14314 if (row
->y
< min_y
)
14315 row
->visible_height
-= min_y
- row
->y
;
14316 if (row
->y
+ row
->height
> max_y
)
14317 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14318 row
->redraw_fringe_bitmaps_p
= 1;
14320 it
.current_y
+= row
->height
;
14322 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14323 last_reused_text_row
= row
;
14324 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14328 /* Disable lines in the current matrix which are now
14329 below the window. */
14330 for (++row
; row
< bottom_row
; ++row
)
14331 row
->enabled_p
= row
->mode_line_p
= 0;
14334 /* Update window_end_pos etc.; last_reused_text_row is the last
14335 reused row from the current matrix containing text, if any.
14336 The value of last_text_row is the last displayed line
14337 containing text. */
14338 if (last_reused_text_row
)
14340 w
->window_end_bytepos
14341 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14343 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14345 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14346 w
->current_matrix
));
14348 else if (last_text_row
)
14350 w
->window_end_bytepos
14351 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14353 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14355 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14359 /* This window must be completely empty. */
14360 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14361 w
->window_end_pos
= make_number (Z
- ZV
);
14362 w
->window_end_vpos
= make_number (0);
14364 w
->window_end_valid
= Qnil
;
14366 /* Update hint: don't try scrolling again in update_window. */
14367 w
->desired_matrix
->no_scrolling_p
= 1;
14370 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14374 else if (CHARPOS (new_start
) > CHARPOS (start
))
14376 struct glyph_row
*pt_row
, *row
;
14377 struct glyph_row
*first_reusable_row
;
14378 struct glyph_row
*first_row_to_display
;
14380 int yb
= window_text_bottom_y (w
);
14382 /* Find the row starting at new_start, if there is one. Don't
14383 reuse a partially visible line at the end. */
14384 first_reusable_row
= start_row
;
14385 while (first_reusable_row
->enabled_p
14386 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14387 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14388 < CHARPOS (new_start
)))
14389 ++first_reusable_row
;
14391 /* Give up if there is no row to reuse. */
14392 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14393 || !first_reusable_row
->enabled_p
14394 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14395 != CHARPOS (new_start
)))
14398 /* We can reuse fully visible rows beginning with
14399 first_reusable_row to the end of the window. Set
14400 first_row_to_display to the first row that cannot be reused.
14401 Set pt_row to the row containing point, if there is any. */
14403 for (first_row_to_display
= first_reusable_row
;
14404 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14405 ++first_row_to_display
)
14407 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14408 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14409 pt_row
= first_row_to_display
;
14412 /* Start displaying at the start of first_row_to_display. */
14413 xassert (first_row_to_display
->y
< yb
);
14414 init_to_row_start (&it
, w
, first_row_to_display
);
14416 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14418 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14420 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14421 + WINDOW_HEADER_LINE_HEIGHT (w
));
14423 /* Display lines beginning with first_row_to_display in the
14424 desired matrix. Set last_text_row to the last row displayed
14425 that displays text. */
14426 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14427 if (pt_row
== NULL
)
14428 w
->cursor
.vpos
= -1;
14429 last_text_row
= NULL
;
14430 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14431 if (display_line (&it
))
14432 last_text_row
= it
.glyph_row
- 1;
14434 /* Give up If point isn't in a row displayed or reused. */
14435 if (w
->cursor
.vpos
< 0)
14437 clear_glyph_matrix (w
->desired_matrix
);
14441 /* If point is in a reused row, adjust y and vpos of the cursor
14445 w
->cursor
.vpos
-= nrows_scrolled
;
14446 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14449 /* Scroll the display. */
14450 run
.current_y
= first_reusable_row
->y
;
14451 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14452 run
.height
= it
.last_visible_y
- run
.current_y
;
14453 dy
= run
.current_y
- run
.desired_y
;
14458 FRAME_RIF (f
)->update_window_begin_hook (w
);
14459 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14460 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14461 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14465 /* Adjust Y positions of reused rows. */
14466 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14467 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14468 max_y
= it
.last_visible_y
;
14469 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14472 row
->visible_height
= row
->height
;
14473 if (row
->y
< min_y
)
14474 row
->visible_height
-= min_y
- row
->y
;
14475 if (row
->y
+ row
->height
> max_y
)
14476 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14477 row
->redraw_fringe_bitmaps_p
= 1;
14480 /* Scroll the current matrix. */
14481 xassert (nrows_scrolled
> 0);
14482 rotate_matrix (w
->current_matrix
,
14484 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14487 /* Disable rows not reused. */
14488 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14489 row
->enabled_p
= 0;
14491 /* Point may have moved to a different line, so we cannot assume that
14492 the previous cursor position is valid; locate the correct row. */
14495 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14496 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14500 w
->cursor
.y
= row
->y
;
14502 if (row
< bottom_row
)
14504 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14505 while (glyph
->charpos
< PT
)
14508 w
->cursor
.x
+= glyph
->pixel_width
;
14514 /* Adjust window end. A null value of last_text_row means that
14515 the window end is in reused rows which in turn means that
14516 only its vpos can have changed. */
14519 w
->window_end_bytepos
14520 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14522 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14524 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14529 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14532 w
->window_end_valid
= Qnil
;
14533 w
->desired_matrix
->no_scrolling_p
= 1;
14536 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14546 /************************************************************************
14547 Window redisplay reusing current matrix when buffer has changed
14548 ************************************************************************/
14550 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14551 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14553 static struct glyph_row
*
14554 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14555 struct glyph_row
*));
14558 /* Return the last row in MATRIX displaying text. If row START is
14559 non-null, start searching with that row. IT gives the dimensions
14560 of the display. Value is null if matrix is empty; otherwise it is
14561 a pointer to the row found. */
14563 static struct glyph_row
*
14564 find_last_row_displaying_text (matrix
, it
, start
)
14565 struct glyph_matrix
*matrix
;
14567 struct glyph_row
*start
;
14569 struct glyph_row
*row
, *row_found
;
14571 /* Set row_found to the last row in IT->w's current matrix
14572 displaying text. The loop looks funny but think of partially
14575 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14576 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14578 xassert (row
->enabled_p
);
14580 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14589 /* Return the last row in the current matrix of W that is not affected
14590 by changes at the start of current_buffer that occurred since W's
14591 current matrix was built. Value is null if no such row exists.
14593 BEG_UNCHANGED us the number of characters unchanged at the start of
14594 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14595 first changed character in current_buffer. Characters at positions <
14596 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14597 when the current matrix was built. */
14599 static struct glyph_row
*
14600 find_last_unchanged_at_beg_row (w
)
14603 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14604 struct glyph_row
*row
;
14605 struct glyph_row
*row_found
= NULL
;
14606 int yb
= window_text_bottom_y (w
);
14608 /* Find the last row displaying unchanged text. */
14609 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14610 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14611 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14614 if (/* If row ends before first_changed_pos, it is unchanged,
14615 except in some case. */
14616 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14617 /* When row ends in ZV and we write at ZV it is not
14619 && !row
->ends_at_zv_p
14620 /* When first_changed_pos is the end of a continued line,
14621 row is not unchanged because it may be no longer
14623 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14624 && (row
->continued_p
14625 || row
->exact_window_width_line_p
)))
14628 /* Stop if last visible row. */
14629 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14637 /* Find the first glyph row in the current matrix of W that is not
14638 affected by changes at the end of current_buffer since the
14639 time W's current matrix was built.
14641 Return in *DELTA the number of chars by which buffer positions in
14642 unchanged text at the end of current_buffer must be adjusted.
14644 Return in *DELTA_BYTES the corresponding number of bytes.
14646 Value is null if no such row exists, i.e. all rows are affected by
14649 static struct glyph_row
*
14650 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14652 int *delta
, *delta_bytes
;
14654 struct glyph_row
*row
;
14655 struct glyph_row
*row_found
= NULL
;
14657 *delta
= *delta_bytes
= 0;
14659 /* Display must not have been paused, otherwise the current matrix
14660 is not up to date. */
14661 eassert (!NILP (w
->window_end_valid
));
14663 /* A value of window_end_pos >= END_UNCHANGED means that the window
14664 end is in the range of changed text. If so, there is no
14665 unchanged row at the end of W's current matrix. */
14666 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14669 /* Set row to the last row in W's current matrix displaying text. */
14670 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14672 /* If matrix is entirely empty, no unchanged row exists. */
14673 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14675 /* The value of row is the last glyph row in the matrix having a
14676 meaningful buffer position in it. The end position of row
14677 corresponds to window_end_pos. This allows us to translate
14678 buffer positions in the current matrix to current buffer
14679 positions for characters not in changed text. */
14680 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14681 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14682 int last_unchanged_pos
, last_unchanged_pos_old
;
14683 struct glyph_row
*first_text_row
14684 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14686 *delta
= Z
- Z_old
;
14687 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14689 /* Set last_unchanged_pos to the buffer position of the last
14690 character in the buffer that has not been changed. Z is the
14691 index + 1 of the last character in current_buffer, i.e. by
14692 subtracting END_UNCHANGED we get the index of the last
14693 unchanged character, and we have to add BEG to get its buffer
14695 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14696 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14698 /* Search backward from ROW for a row displaying a line that
14699 starts at a minimum position >= last_unchanged_pos_old. */
14700 for (; row
> first_text_row
; --row
)
14702 /* This used to abort, but it can happen.
14703 It is ok to just stop the search instead here. KFS. */
14704 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14707 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14712 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14718 /* Make sure that glyph rows in the current matrix of window W
14719 reference the same glyph memory as corresponding rows in the
14720 frame's frame matrix. This function is called after scrolling W's
14721 current matrix on a terminal frame in try_window_id and
14722 try_window_reusing_current_matrix. */
14725 sync_frame_with_window_matrix_rows (w
)
14728 struct frame
*f
= XFRAME (w
->frame
);
14729 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14731 /* Preconditions: W must be a leaf window and full-width. Its frame
14732 must have a frame matrix. */
14733 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14734 xassert (WINDOW_FULL_WIDTH_P (w
));
14735 xassert (!FRAME_WINDOW_P (f
));
14737 /* If W is a full-width window, glyph pointers in W's current matrix
14738 have, by definition, to be the same as glyph pointers in the
14739 corresponding frame matrix. Note that frame matrices have no
14740 marginal areas (see build_frame_matrix). */
14741 window_row
= w
->current_matrix
->rows
;
14742 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14743 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14744 while (window_row
< window_row_end
)
14746 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14747 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14749 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14750 frame_row
->glyphs
[TEXT_AREA
] = start
;
14751 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14752 frame_row
->glyphs
[LAST_AREA
] = end
;
14754 /* Disable frame rows whose corresponding window rows have
14755 been disabled in try_window_id. */
14756 if (!window_row
->enabled_p
)
14757 frame_row
->enabled_p
= 0;
14759 ++window_row
, ++frame_row
;
14764 /* Find the glyph row in window W containing CHARPOS. Consider all
14765 rows between START and END (not inclusive). END null means search
14766 all rows to the end of the display area of W. Value is the row
14767 containing CHARPOS or null. */
14770 row_containing_pos (w
, charpos
, start
, end
, dy
)
14773 struct glyph_row
*start
, *end
;
14776 struct glyph_row
*row
= start
;
14779 /* If we happen to start on a header-line, skip that. */
14780 if (row
->mode_line_p
)
14783 if ((end
&& row
>= end
) || !row
->enabled_p
)
14786 last_y
= window_text_bottom_y (w
) - dy
;
14790 /* Give up if we have gone too far. */
14791 if (end
&& row
>= end
)
14793 /* This formerly returned if they were equal.
14794 I think that both quantities are of a "last plus one" type;
14795 if so, when they are equal, the row is within the screen. -- rms. */
14796 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14799 /* If it is in this row, return this row. */
14800 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14801 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14802 /* The end position of a row equals the start
14803 position of the next row. If CHARPOS is there, we
14804 would rather display it in the next line, except
14805 when this line ends in ZV. */
14806 && !row
->ends_at_zv_p
14807 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14808 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14815 /* Try to redisplay window W by reusing its existing display. W's
14816 current matrix must be up to date when this function is called,
14817 i.e. window_end_valid must not be nil.
14821 1 if display has been updated
14822 0 if otherwise unsuccessful
14823 -1 if redisplay with same window start is known not to succeed
14825 The following steps are performed:
14827 1. Find the last row in the current matrix of W that is not
14828 affected by changes at the start of current_buffer. If no such row
14831 2. Find the first row in W's current matrix that is not affected by
14832 changes at the end of current_buffer. Maybe there is no such row.
14834 3. Display lines beginning with the row + 1 found in step 1 to the
14835 row found in step 2 or, if step 2 didn't find a row, to the end of
14838 4. If cursor is not known to appear on the window, give up.
14840 5. If display stopped at the row found in step 2, scroll the
14841 display and current matrix as needed.
14843 6. Maybe display some lines at the end of W, if we must. This can
14844 happen under various circumstances, like a partially visible line
14845 becoming fully visible, or because newly displayed lines are displayed
14846 in smaller font sizes.
14848 7. Update W's window end information. */
14854 struct frame
*f
= XFRAME (w
->frame
);
14855 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14856 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14857 struct glyph_row
*last_unchanged_at_beg_row
;
14858 struct glyph_row
*first_unchanged_at_end_row
;
14859 struct glyph_row
*row
;
14860 struct glyph_row
*bottom_row
;
14863 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14864 struct text_pos start_pos
;
14866 int first_unchanged_at_end_vpos
= 0;
14867 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14868 struct text_pos start
;
14869 int first_changed_charpos
, last_changed_charpos
;
14872 if (inhibit_try_window_id
)
14876 /* This is handy for debugging. */
14878 #define GIVE_UP(X) \
14880 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14884 #define GIVE_UP(X) return 0
14887 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14889 /* Don't use this for mini-windows because these can show
14890 messages and mini-buffers, and we don't handle that here. */
14891 if (MINI_WINDOW_P (w
))
14894 /* This flag is used to prevent redisplay optimizations. */
14895 if (windows_or_buffers_changed
|| cursor_type_changed
)
14898 /* Verify that narrowing has not changed.
14899 Also verify that we were not told to prevent redisplay optimizations.
14900 It would be nice to further
14901 reduce the number of cases where this prevents try_window_id. */
14902 if (current_buffer
->clip_changed
14903 || current_buffer
->prevent_redisplay_optimizations_p
)
14906 /* Window must either use window-based redisplay or be full width. */
14907 if (!FRAME_WINDOW_P (f
)
14908 && (!FRAME_LINE_INS_DEL_OK (f
)
14909 || !WINDOW_FULL_WIDTH_P (w
)))
14912 /* Give up if point is not known NOT to appear in W. */
14913 if (PT
< CHARPOS (start
))
14916 /* Another way to prevent redisplay optimizations. */
14917 if (XFASTINT (w
->last_modified
) == 0)
14920 /* Verify that window is not hscrolled. */
14921 if (XFASTINT (w
->hscroll
) != 0)
14924 /* Verify that display wasn't paused. */
14925 if (NILP (w
->window_end_valid
))
14928 /* Can't use this if highlighting a region because a cursor movement
14929 will do more than just set the cursor. */
14930 if (!NILP (Vtransient_mark_mode
)
14931 && !NILP (current_buffer
->mark_active
))
14934 /* Likewise if highlighting trailing whitespace. */
14935 if (!NILP (Vshow_trailing_whitespace
))
14938 /* Likewise if showing a region. */
14939 if (!NILP (w
->region_showing
))
14942 /* Can use this if overlay arrow position and or string have changed. */
14943 if (overlay_arrows_changed_p ())
14946 /* When word-wrap is on, adding a space to the first word of a
14947 wrapped line can change the wrap position, altering the line
14948 above it. It might be worthwhile to handle this more
14949 intelligently, but for now just redisplay from scratch. */
14950 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14953 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14954 only if buffer has really changed. The reason is that the gap is
14955 initially at Z for freshly visited files. The code below would
14956 set end_unchanged to 0 in that case. */
14957 if (MODIFF
> SAVE_MODIFF
14958 /* This seems to happen sometimes after saving a buffer. */
14959 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14961 if (GPT
- BEG
< BEG_UNCHANGED
)
14962 BEG_UNCHANGED
= GPT
- BEG
;
14963 if (Z
- GPT
< END_UNCHANGED
)
14964 END_UNCHANGED
= Z
- GPT
;
14967 /* The position of the first and last character that has been changed. */
14968 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14969 last_changed_charpos
= Z
- END_UNCHANGED
;
14971 /* If window starts after a line end, and the last change is in
14972 front of that newline, then changes don't affect the display.
14973 This case happens with stealth-fontification. Note that although
14974 the display is unchanged, glyph positions in the matrix have to
14975 be adjusted, of course. */
14976 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14977 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14978 && ((last_changed_charpos
< CHARPOS (start
)
14979 && CHARPOS (start
) == BEGV
)
14980 || (last_changed_charpos
< CHARPOS (start
) - 1
14981 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14983 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14984 struct glyph_row
*r0
;
14986 /* Compute how many chars/bytes have been added to or removed
14987 from the buffer. */
14988 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14989 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14991 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14993 /* Give up if PT is not in the window. Note that it already has
14994 been checked at the start of try_window_id that PT is not in
14995 front of the window start. */
14996 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14999 /* If window start is unchanged, we can reuse the whole matrix
15000 as is, after adjusting glyph positions. No need to compute
15001 the window end again, since its offset from Z hasn't changed. */
15002 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15003 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15004 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15005 /* PT must not be in a partially visible line. */
15006 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15007 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15009 /* Adjust positions in the glyph matrix. */
15010 if (delta
|| delta_bytes
)
15012 struct glyph_row
*r1
15013 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15014 increment_matrix_positions (w
->current_matrix
,
15015 MATRIX_ROW_VPOS (r0
, current_matrix
),
15016 MATRIX_ROW_VPOS (r1
, current_matrix
),
15017 delta
, delta_bytes
);
15020 /* Set the cursor. */
15021 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15023 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15030 /* Handle the case that changes are all below what is displayed in
15031 the window, and that PT is in the window. This shortcut cannot
15032 be taken if ZV is visible in the window, and text has been added
15033 there that is visible in the window. */
15034 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15035 /* ZV is not visible in the window, or there are no
15036 changes at ZV, actually. */
15037 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15038 || first_changed_charpos
== last_changed_charpos
))
15040 struct glyph_row
*r0
;
15042 /* Give up if PT is not in the window. Note that it already has
15043 been checked at the start of try_window_id that PT is not in
15044 front of the window start. */
15045 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15048 /* If window start is unchanged, we can reuse the whole matrix
15049 as is, without changing glyph positions since no text has
15050 been added/removed in front of the window end. */
15051 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15052 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15053 /* PT must not be in a partially visible line. */
15054 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15055 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15057 /* We have to compute the window end anew since text
15058 can have been added/removed after it. */
15060 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15061 w
->window_end_bytepos
15062 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15064 /* Set the cursor. */
15065 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15067 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15074 /* Give up if window start is in the changed area.
15076 The condition used to read
15078 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15080 but why that was tested escapes me at the moment. */
15081 if (CHARPOS (start
) >= first_changed_charpos
15082 && CHARPOS (start
) <= last_changed_charpos
)
15085 /* Check that window start agrees with the start of the first glyph
15086 row in its current matrix. Check this after we know the window
15087 start is not in changed text, otherwise positions would not be
15089 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15090 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15093 /* Give up if the window ends in strings. Overlay strings
15094 at the end are difficult to handle, so don't try. */
15095 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15096 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15099 /* Compute the position at which we have to start displaying new
15100 lines. Some of the lines at the top of the window might be
15101 reusable because they are not displaying changed text. Find the
15102 last row in W's current matrix not affected by changes at the
15103 start of current_buffer. Value is null if changes start in the
15104 first line of window. */
15105 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15106 if (last_unchanged_at_beg_row
)
15108 /* Avoid starting to display in the moddle of a character, a TAB
15109 for instance. This is easier than to set up the iterator
15110 exactly, and it's not a frequent case, so the additional
15111 effort wouldn't really pay off. */
15112 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15113 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15114 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15115 --last_unchanged_at_beg_row
;
15117 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15120 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15122 start_pos
= it
.current
.pos
;
15124 /* Start displaying new lines in the desired matrix at the same
15125 vpos we would use in the current matrix, i.e. below
15126 last_unchanged_at_beg_row. */
15127 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15129 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15130 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15132 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15136 /* There are no reusable lines at the start of the window.
15137 Start displaying in the first text line. */
15138 start_display (&it
, w
, start
);
15139 it
.vpos
= it
.first_vpos
;
15140 start_pos
= it
.current
.pos
;
15143 /* Find the first row that is not affected by changes at the end of
15144 the buffer. Value will be null if there is no unchanged row, in
15145 which case we must redisplay to the end of the window. delta
15146 will be set to the value by which buffer positions beginning with
15147 first_unchanged_at_end_row have to be adjusted due to text
15149 first_unchanged_at_end_row
15150 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15151 IF_DEBUG (debug_delta
= delta
);
15152 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15154 /* Set stop_pos to the buffer position up to which we will have to
15155 display new lines. If first_unchanged_at_end_row != NULL, this
15156 is the buffer position of the start of the line displayed in that
15157 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15158 that we don't stop at a buffer position. */
15160 if (first_unchanged_at_end_row
)
15162 xassert (last_unchanged_at_beg_row
== NULL
15163 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15165 /* If this is a continuation line, move forward to the next one
15166 that isn't. Changes in lines above affect this line.
15167 Caution: this may move first_unchanged_at_end_row to a row
15168 not displaying text. */
15169 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15170 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15171 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15172 < it
.last_visible_y
))
15173 ++first_unchanged_at_end_row
;
15175 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15176 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15177 >= it
.last_visible_y
))
15178 first_unchanged_at_end_row
= NULL
;
15181 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15183 first_unchanged_at_end_vpos
15184 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15185 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15188 else if (last_unchanged_at_beg_row
== NULL
)
15194 /* Either there is no unchanged row at the end, or the one we have
15195 now displays text. This is a necessary condition for the window
15196 end pos calculation at the end of this function. */
15197 xassert (first_unchanged_at_end_row
== NULL
15198 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15200 debug_last_unchanged_at_beg_vpos
15201 = (last_unchanged_at_beg_row
15202 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15204 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15206 #endif /* GLYPH_DEBUG != 0 */
15209 /* Display new lines. Set last_text_row to the last new line
15210 displayed which has text on it, i.e. might end up as being the
15211 line where the window_end_vpos is. */
15212 w
->cursor
.vpos
= -1;
15213 last_text_row
= NULL
;
15214 overlay_arrow_seen
= 0;
15215 while (it
.current_y
< it
.last_visible_y
15216 && !fonts_changed_p
15217 && (first_unchanged_at_end_row
== NULL
15218 || IT_CHARPOS (it
) < stop_pos
))
15220 if (display_line (&it
))
15221 last_text_row
= it
.glyph_row
- 1;
15224 if (fonts_changed_p
)
15228 /* Compute differences in buffer positions, y-positions etc. for
15229 lines reused at the bottom of the window. Compute what we can
15231 if (first_unchanged_at_end_row
15232 /* No lines reused because we displayed everything up to the
15233 bottom of the window. */
15234 && it
.current_y
< it
.last_visible_y
)
15237 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15239 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15240 run
.current_y
= first_unchanged_at_end_row
->y
;
15241 run
.desired_y
= run
.current_y
+ dy
;
15242 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15246 delta
= delta_bytes
= dvpos
= dy
15247 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15248 first_unchanged_at_end_row
= NULL
;
15250 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15253 /* Find the cursor if not already found. We have to decide whether
15254 PT will appear on this window (it sometimes doesn't, but this is
15255 not a very frequent case.) This decision has to be made before
15256 the current matrix is altered. A value of cursor.vpos < 0 means
15257 that PT is either in one of the lines beginning at
15258 first_unchanged_at_end_row or below the window. Don't care for
15259 lines that might be displayed later at the window end; as
15260 mentioned, this is not a frequent case. */
15261 if (w
->cursor
.vpos
< 0)
15263 /* Cursor in unchanged rows at the top? */
15264 if (PT
< CHARPOS (start_pos
)
15265 && last_unchanged_at_beg_row
)
15267 row
= row_containing_pos (w
, PT
,
15268 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15269 last_unchanged_at_beg_row
+ 1, 0);
15271 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15274 /* Start from first_unchanged_at_end_row looking for PT. */
15275 else if (first_unchanged_at_end_row
)
15277 row
= row_containing_pos (w
, PT
- delta
,
15278 first_unchanged_at_end_row
, NULL
, 0);
15280 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15281 delta_bytes
, dy
, dvpos
);
15284 /* Give up if cursor was not found. */
15285 if (w
->cursor
.vpos
< 0)
15287 clear_glyph_matrix (w
->desired_matrix
);
15292 /* Don't let the cursor end in the scroll margins. */
15294 int this_scroll_margin
, cursor_height
;
15296 this_scroll_margin
= max (0, scroll_margin
);
15297 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15298 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15299 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15301 if ((w
->cursor
.y
< this_scroll_margin
15302 && CHARPOS (start
) > BEGV
)
15303 /* Old redisplay didn't take scroll margin into account at the bottom,
15304 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15305 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15306 ? cursor_height
+ this_scroll_margin
15307 : 1)) > it
.last_visible_y
)
15309 w
->cursor
.vpos
= -1;
15310 clear_glyph_matrix (w
->desired_matrix
);
15315 /* Scroll the display. Do it before changing the current matrix so
15316 that xterm.c doesn't get confused about where the cursor glyph is
15318 if (dy
&& run
.height
)
15322 if (FRAME_WINDOW_P (f
))
15324 FRAME_RIF (f
)->update_window_begin_hook (w
);
15325 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15326 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15327 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15331 /* Terminal frame. In this case, dvpos gives the number of
15332 lines to scroll by; dvpos < 0 means scroll up. */
15333 int first_unchanged_at_end_vpos
15334 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15335 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15336 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15337 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15338 + window_internal_height (w
));
15340 /* Perform the operation on the screen. */
15343 /* Scroll last_unchanged_at_beg_row to the end of the
15344 window down dvpos lines. */
15345 set_terminal_window (f
, end
);
15347 /* On dumb terminals delete dvpos lines at the end
15348 before inserting dvpos empty lines. */
15349 if (!FRAME_SCROLL_REGION_OK (f
))
15350 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15352 /* Insert dvpos empty lines in front of
15353 last_unchanged_at_beg_row. */
15354 ins_del_lines (f
, from
, dvpos
);
15356 else if (dvpos
< 0)
15358 /* Scroll up last_unchanged_at_beg_vpos to the end of
15359 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15360 set_terminal_window (f
, end
);
15362 /* Delete dvpos lines in front of
15363 last_unchanged_at_beg_vpos. ins_del_lines will set
15364 the cursor to the given vpos and emit |dvpos| delete
15366 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15368 /* On a dumb terminal insert dvpos empty lines at the
15370 if (!FRAME_SCROLL_REGION_OK (f
))
15371 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15374 set_terminal_window (f
, 0);
15380 /* Shift reused rows of the current matrix to the right position.
15381 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15383 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15384 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15387 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15388 bottom_vpos
, dvpos
);
15389 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15392 else if (dvpos
> 0)
15394 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15395 bottom_vpos
, dvpos
);
15396 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15397 first_unchanged_at_end_vpos
+ dvpos
, 0);
15400 /* For frame-based redisplay, make sure that current frame and window
15401 matrix are in sync with respect to glyph memory. */
15402 if (!FRAME_WINDOW_P (f
))
15403 sync_frame_with_window_matrix_rows (w
);
15405 /* Adjust buffer positions in reused rows. */
15406 if (delta
|| delta_bytes
)
15407 increment_matrix_positions (current_matrix
,
15408 first_unchanged_at_end_vpos
+ dvpos
,
15409 bottom_vpos
, delta
, delta_bytes
);
15411 /* Adjust Y positions. */
15413 shift_glyph_matrix (w
, current_matrix
,
15414 first_unchanged_at_end_vpos
+ dvpos
,
15417 if (first_unchanged_at_end_row
)
15419 first_unchanged_at_end_row
+= dvpos
;
15420 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15421 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15422 first_unchanged_at_end_row
= NULL
;
15425 /* If scrolling up, there may be some lines to display at the end of
15427 last_text_row_at_end
= NULL
;
15430 /* Scrolling up can leave for example a partially visible line
15431 at the end of the window to be redisplayed. */
15432 /* Set last_row to the glyph row in the current matrix where the
15433 window end line is found. It has been moved up or down in
15434 the matrix by dvpos. */
15435 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15436 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15438 /* If last_row is the window end line, it should display text. */
15439 xassert (last_row
->displays_text_p
);
15441 /* If window end line was partially visible before, begin
15442 displaying at that line. Otherwise begin displaying with the
15443 line following it. */
15444 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15446 init_to_row_start (&it
, w
, last_row
);
15447 it
.vpos
= last_vpos
;
15448 it
.current_y
= last_row
->y
;
15452 init_to_row_end (&it
, w
, last_row
);
15453 it
.vpos
= 1 + last_vpos
;
15454 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15458 /* We may start in a continuation line. If so, we have to
15459 get the right continuation_lines_width and current_x. */
15460 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15461 it
.hpos
= it
.current_x
= 0;
15463 /* Display the rest of the lines at the window end. */
15464 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15465 while (it
.current_y
< it
.last_visible_y
15466 && !fonts_changed_p
)
15468 /* Is it always sure that the display agrees with lines in
15469 the current matrix? I don't think so, so we mark rows
15470 displayed invalid in the current matrix by setting their
15471 enabled_p flag to zero. */
15472 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15473 if (display_line (&it
))
15474 last_text_row_at_end
= it
.glyph_row
- 1;
15478 /* Update window_end_pos and window_end_vpos. */
15479 if (first_unchanged_at_end_row
15480 && !last_text_row_at_end
)
15482 /* Window end line if one of the preserved rows from the current
15483 matrix. Set row to the last row displaying text in current
15484 matrix starting at first_unchanged_at_end_row, after
15486 xassert (first_unchanged_at_end_row
->displays_text_p
);
15487 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15488 first_unchanged_at_end_row
);
15489 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15491 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15492 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15494 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15495 xassert (w
->window_end_bytepos
>= 0);
15496 IF_DEBUG (debug_method_add (w
, "A"));
15498 else if (last_text_row_at_end
)
15501 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15502 w
->window_end_bytepos
15503 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15505 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15506 xassert (w
->window_end_bytepos
>= 0);
15507 IF_DEBUG (debug_method_add (w
, "B"));
15509 else if (last_text_row
)
15511 /* We have displayed either to the end of the window or at the
15512 end of the window, i.e. the last row with text is to be found
15513 in the desired matrix. */
15515 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15516 w
->window_end_bytepos
15517 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15519 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15520 xassert (w
->window_end_bytepos
>= 0);
15522 else if (first_unchanged_at_end_row
== NULL
15523 && last_text_row
== NULL
15524 && last_text_row_at_end
== NULL
)
15526 /* Displayed to end of window, but no line containing text was
15527 displayed. Lines were deleted at the end of the window. */
15528 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15529 int vpos
= XFASTINT (w
->window_end_vpos
);
15530 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15531 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15534 row
== NULL
&& vpos
>= first_vpos
;
15535 --vpos
, --current_row
, --desired_row
)
15537 if (desired_row
->enabled_p
)
15539 if (desired_row
->displays_text_p
)
15542 else if (current_row
->displays_text_p
)
15546 xassert (row
!= NULL
);
15547 w
->window_end_vpos
= make_number (vpos
+ 1);
15548 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15549 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15550 xassert (w
->window_end_bytepos
>= 0);
15551 IF_DEBUG (debug_method_add (w
, "C"));
15556 #if 0 /* This leads to problems, for instance when the cursor is
15557 at ZV, and the cursor line displays no text. */
15558 /* Disable rows below what's displayed in the window. This makes
15559 debugging easier. */
15560 enable_glyph_matrix_rows (current_matrix
,
15561 XFASTINT (w
->window_end_vpos
) + 1,
15565 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15566 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15568 /* Record that display has not been completed. */
15569 w
->window_end_valid
= Qnil
;
15570 w
->desired_matrix
->no_scrolling_p
= 1;
15578 /***********************************************************************
15579 More debugging support
15580 ***********************************************************************/
15584 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15585 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15586 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15589 /* Dump the contents of glyph matrix MATRIX on stderr.
15591 GLYPHS 0 means don't show glyph contents.
15592 GLYPHS 1 means show glyphs in short form
15593 GLYPHS > 1 means show glyphs in long form. */
15596 dump_glyph_matrix (matrix
, glyphs
)
15597 struct glyph_matrix
*matrix
;
15601 for (i
= 0; i
< matrix
->nrows
; ++i
)
15602 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15606 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15607 the glyph row and area where the glyph comes from. */
15610 dump_glyph (row
, glyph
, area
)
15611 struct glyph_row
*row
;
15612 struct glyph
*glyph
;
15615 if (glyph
->type
== CHAR_GLYPH
)
15618 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15619 glyph
- row
->glyphs
[TEXT_AREA
],
15622 (BUFFERP (glyph
->object
)
15624 : (STRINGP (glyph
->object
)
15627 glyph
->pixel_width
,
15629 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15633 glyph
->left_box_line_p
,
15634 glyph
->right_box_line_p
);
15636 else if (glyph
->type
== STRETCH_GLYPH
)
15639 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15640 glyph
- row
->glyphs
[TEXT_AREA
],
15643 (BUFFERP (glyph
->object
)
15645 : (STRINGP (glyph
->object
)
15648 glyph
->pixel_width
,
15652 glyph
->left_box_line_p
,
15653 glyph
->right_box_line_p
);
15655 else if (glyph
->type
== IMAGE_GLYPH
)
15658 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15659 glyph
- row
->glyphs
[TEXT_AREA
],
15662 (BUFFERP (glyph
->object
)
15664 : (STRINGP (glyph
->object
)
15667 glyph
->pixel_width
,
15671 glyph
->left_box_line_p
,
15672 glyph
->right_box_line_p
);
15674 else if (glyph
->type
== COMPOSITE_GLYPH
)
15677 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15678 glyph
- row
->glyphs
[TEXT_AREA
],
15681 (BUFFERP (glyph
->object
)
15683 : (STRINGP (glyph
->object
)
15686 glyph
->pixel_width
,
15690 glyph
->left_box_line_p
,
15691 glyph
->right_box_line_p
);
15696 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15697 GLYPHS 0 means don't show glyph contents.
15698 GLYPHS 1 means show glyphs in short form
15699 GLYPHS > 1 means show glyphs in long form. */
15702 dump_glyph_row (row
, vpos
, glyphs
)
15703 struct glyph_row
*row
;
15708 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15709 fprintf (stderr
, "======================================================================\n");
15711 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15712 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15714 MATRIX_ROW_START_CHARPOS (row
),
15715 MATRIX_ROW_END_CHARPOS (row
),
15716 row
->used
[TEXT_AREA
],
15717 row
->contains_overlapping_glyphs_p
,
15719 row
->truncated_on_left_p
,
15720 row
->truncated_on_right_p
,
15722 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15723 row
->displays_text_p
,
15726 row
->ends_in_middle_of_char_p
,
15727 row
->starts_in_middle_of_char_p
,
15733 row
->visible_height
,
15736 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15737 row
->end
.overlay_string_index
,
15738 row
->continuation_lines_width
);
15739 fprintf (stderr
, "%9d %5d\n",
15740 CHARPOS (row
->start
.string_pos
),
15741 CHARPOS (row
->end
.string_pos
));
15742 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15743 row
->end
.dpvec_index
);
15750 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15752 struct glyph
*glyph
= row
->glyphs
[area
];
15753 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15755 /* Glyph for a line end in text. */
15756 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15759 if (glyph
< glyph_end
)
15760 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15762 for (; glyph
< glyph_end
; ++glyph
)
15763 dump_glyph (row
, glyph
, area
);
15766 else if (glyphs
== 1)
15770 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15772 char *s
= (char *) alloca (row
->used
[area
] + 1);
15775 for (i
= 0; i
< row
->used
[area
]; ++i
)
15777 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15778 if (glyph
->type
== CHAR_GLYPH
15779 && glyph
->u
.ch
< 0x80
15780 && glyph
->u
.ch
>= ' ')
15781 s
[i
] = glyph
->u
.ch
;
15787 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15793 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15794 Sdump_glyph_matrix
, 0, 1, "p",
15795 doc
: /* Dump the current matrix of the selected window to stderr.
15796 Shows contents of glyph row structures. With non-nil
15797 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15798 glyphs in short form, otherwise show glyphs in long form. */)
15800 Lisp_Object glyphs
;
15802 struct window
*w
= XWINDOW (selected_window
);
15803 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15805 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15806 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15807 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15808 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15809 fprintf (stderr
, "=============================================\n");
15810 dump_glyph_matrix (w
->current_matrix
,
15811 NILP (glyphs
) ? 0 : XINT (glyphs
));
15816 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15817 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15820 struct frame
*f
= XFRAME (selected_frame
);
15821 dump_glyph_matrix (f
->current_matrix
, 1);
15826 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15827 doc
: /* Dump glyph row ROW to stderr.
15828 GLYPH 0 means don't dump glyphs.
15829 GLYPH 1 means dump glyphs in short form.
15830 GLYPH > 1 or omitted means dump glyphs in long form. */)
15832 Lisp_Object row
, glyphs
;
15834 struct glyph_matrix
*matrix
;
15837 CHECK_NUMBER (row
);
15838 matrix
= XWINDOW (selected_window
)->current_matrix
;
15840 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15841 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15843 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15848 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15849 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15850 GLYPH 0 means don't dump glyphs.
15851 GLYPH 1 means dump glyphs in short form.
15852 GLYPH > 1 or omitted means dump glyphs in long form. */)
15854 Lisp_Object row
, glyphs
;
15856 struct frame
*sf
= SELECTED_FRAME ();
15857 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15860 CHECK_NUMBER (row
);
15862 if (vpos
>= 0 && vpos
< m
->nrows
)
15863 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15864 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15869 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15870 doc
: /* Toggle tracing of redisplay.
15871 With ARG, turn tracing on if and only if ARG is positive. */)
15876 trace_redisplay_p
= !trace_redisplay_p
;
15879 arg
= Fprefix_numeric_value (arg
);
15880 trace_redisplay_p
= XINT (arg
) > 0;
15887 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15888 doc
: /* Like `format', but print result to stderr.
15889 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15894 Lisp_Object s
= Fformat (nargs
, args
);
15895 fprintf (stderr
, "%s", SDATA (s
));
15899 #endif /* GLYPH_DEBUG */
15903 /***********************************************************************
15904 Building Desired Matrix Rows
15905 ***********************************************************************/
15907 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15908 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15910 static struct glyph_row
*
15911 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15913 Lisp_Object overlay_arrow_string
;
15915 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15916 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15917 struct buffer
*old
= current_buffer
;
15918 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15919 int arrow_len
= SCHARS (overlay_arrow_string
);
15920 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15921 const unsigned char *p
;
15924 int n_glyphs_before
;
15926 set_buffer_temp (buffer
);
15927 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15928 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15929 SET_TEXT_POS (it
.position
, 0, 0);
15931 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15933 while (p
< arrow_end
)
15935 Lisp_Object face
, ilisp
;
15937 /* Get the next character. */
15939 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15941 it
.c
= *p
, it
.len
= 1;
15944 /* Get its face. */
15945 ilisp
= make_number (p
- arrow_string
);
15946 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15947 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15949 /* Compute its width, get its glyphs. */
15950 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15951 SET_TEXT_POS (it
.position
, -1, -1);
15952 PRODUCE_GLYPHS (&it
);
15954 /* If this character doesn't fit any more in the line, we have
15955 to remove some glyphs. */
15956 if (it
.current_x
> it
.last_visible_x
)
15958 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15963 set_buffer_temp (old
);
15964 return it
.glyph_row
;
15968 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15969 glyphs are only inserted for terminal frames since we can't really
15970 win with truncation glyphs when partially visible glyphs are
15971 involved. Which glyphs to insert is determined by
15972 produce_special_glyphs. */
15975 insert_left_trunc_glyphs (it
)
15978 struct it truncate_it
;
15979 struct glyph
*from
, *end
, *to
, *toend
;
15981 xassert (!FRAME_WINDOW_P (it
->f
));
15983 /* Get the truncation glyphs. */
15985 truncate_it
.current_x
= 0;
15986 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15987 truncate_it
.glyph_row
= &scratch_glyph_row
;
15988 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15989 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15990 truncate_it
.object
= make_number (0);
15991 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15993 /* Overwrite glyphs from IT with truncation glyphs. */
15994 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15995 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15996 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15997 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16002 /* There may be padding glyphs left over. Overwrite them too. */
16003 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16005 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16011 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16015 /* Compute the pixel height and width of IT->glyph_row.
16017 Most of the time, ascent and height of a display line will be equal
16018 to the max_ascent and max_height values of the display iterator
16019 structure. This is not the case if
16021 1. We hit ZV without displaying anything. In this case, max_ascent
16022 and max_height will be zero.
16024 2. We have some glyphs that don't contribute to the line height.
16025 (The glyph row flag contributes_to_line_height_p is for future
16026 pixmap extensions).
16028 The first case is easily covered by using default values because in
16029 these cases, the line height does not really matter, except that it
16030 must not be zero. */
16033 compute_line_metrics (it
)
16036 struct glyph_row
*row
= it
->glyph_row
;
16039 if (FRAME_WINDOW_P (it
->f
))
16041 int i
, min_y
, max_y
;
16043 /* The line may consist of one space only, that was added to
16044 place the cursor on it. If so, the row's height hasn't been
16046 if (row
->height
== 0)
16048 if (it
->max_ascent
+ it
->max_descent
== 0)
16049 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16050 row
->ascent
= it
->max_ascent
;
16051 row
->height
= it
->max_ascent
+ it
->max_descent
;
16052 row
->phys_ascent
= it
->max_phys_ascent
;
16053 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16054 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16057 /* Compute the width of this line. */
16058 row
->pixel_width
= row
->x
;
16059 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16060 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16062 xassert (row
->pixel_width
>= 0);
16063 xassert (row
->ascent
>= 0 && row
->height
> 0);
16065 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16066 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16068 /* If first line's physical ascent is larger than its logical
16069 ascent, use the physical ascent, and make the row taller.
16070 This makes accented characters fully visible. */
16071 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16072 && row
->phys_ascent
> row
->ascent
)
16074 row
->height
+= row
->phys_ascent
- row
->ascent
;
16075 row
->ascent
= row
->phys_ascent
;
16078 /* Compute how much of the line is visible. */
16079 row
->visible_height
= row
->height
;
16081 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16082 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16084 if (row
->y
< min_y
)
16085 row
->visible_height
-= min_y
- row
->y
;
16086 if (row
->y
+ row
->height
> max_y
)
16087 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16091 row
->pixel_width
= row
->used
[TEXT_AREA
];
16092 if (row
->continued_p
)
16093 row
->pixel_width
-= it
->continuation_pixel_width
;
16094 else if (row
->truncated_on_right_p
)
16095 row
->pixel_width
-= it
->truncation_pixel_width
;
16096 row
->ascent
= row
->phys_ascent
= 0;
16097 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16098 row
->extra_line_spacing
= 0;
16101 /* Compute a hash code for this row. */
16103 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16104 for (i
= 0; i
< row
->used
[area
]; ++i
)
16105 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16106 + row
->glyphs
[area
][i
].u
.val
16107 + row
->glyphs
[area
][i
].face_id
16108 + row
->glyphs
[area
][i
].padding_p
16109 + (row
->glyphs
[area
][i
].type
<< 2));
16111 it
->max_ascent
= it
->max_descent
= 0;
16112 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16116 /* Append one space to the glyph row of iterator IT if doing a
16117 window-based redisplay. The space has the same face as
16118 IT->face_id. Value is non-zero if a space was added.
16120 This function is called to make sure that there is always one glyph
16121 at the end of a glyph row that the cursor can be set on under
16122 window-systems. (If there weren't such a glyph we would not know
16123 how wide and tall a box cursor should be displayed).
16125 At the same time this space let's a nicely handle clearing to the
16126 end of the line if the row ends in italic text. */
16129 append_space_for_newline (it
, default_face_p
)
16131 int default_face_p
;
16133 if (FRAME_WINDOW_P (it
->f
))
16135 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16137 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16138 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16140 /* Save some values that must not be changed.
16141 Must save IT->c and IT->len because otherwise
16142 ITERATOR_AT_END_P wouldn't work anymore after
16143 append_space_for_newline has been called. */
16144 enum display_element_type saved_what
= it
->what
;
16145 int saved_c
= it
->c
, saved_len
= it
->len
;
16146 int saved_x
= it
->current_x
;
16147 int saved_face_id
= it
->face_id
;
16148 struct text_pos saved_pos
;
16149 Lisp_Object saved_object
;
16152 saved_object
= it
->object
;
16153 saved_pos
= it
->position
;
16155 it
->what
= IT_CHARACTER
;
16156 bzero (&it
->position
, sizeof it
->position
);
16157 it
->object
= make_number (0);
16161 if (default_face_p
)
16162 it
->face_id
= DEFAULT_FACE_ID
;
16163 else if (it
->face_before_selective_p
)
16164 it
->face_id
= it
->saved_face_id
;
16165 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16166 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16168 PRODUCE_GLYPHS (it
);
16170 it
->override_ascent
= -1;
16171 it
->constrain_row_ascent_descent_p
= 0;
16172 it
->current_x
= saved_x
;
16173 it
->object
= saved_object
;
16174 it
->position
= saved_pos
;
16175 it
->what
= saved_what
;
16176 it
->face_id
= saved_face_id
;
16177 it
->len
= saved_len
;
16187 /* Extend the face of the last glyph in the text area of IT->glyph_row
16188 to the end of the display line. Called from display_line.
16189 If the glyph row is empty, add a space glyph to it so that we
16190 know the face to draw. Set the glyph row flag fill_line_p. */
16193 extend_face_to_end_of_line (it
)
16197 struct frame
*f
= it
->f
;
16199 /* If line is already filled, do nothing. */
16200 if (it
->current_x
>= it
->last_visible_x
)
16203 /* Face extension extends the background and box of IT->face_id
16204 to the end of the line. If the background equals the background
16205 of the frame, we don't have to do anything. */
16206 if (it
->face_before_selective_p
)
16207 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16209 face
= FACE_FROM_ID (f
, it
->face_id
);
16211 if (FRAME_WINDOW_P (f
)
16212 && it
->glyph_row
->displays_text_p
16213 && face
->box
== FACE_NO_BOX
16214 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16218 /* Set the glyph row flag indicating that the face of the last glyph
16219 in the text area has to be drawn to the end of the text area. */
16220 it
->glyph_row
->fill_line_p
= 1;
16222 /* If current character of IT is not ASCII, make sure we have the
16223 ASCII face. This will be automatically undone the next time
16224 get_next_display_element returns a multibyte character. Note
16225 that the character will always be single byte in unibyte text. */
16226 if (!ASCII_CHAR_P (it
->c
))
16228 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16231 if (FRAME_WINDOW_P (f
))
16233 /* If the row is empty, add a space with the current face of IT,
16234 so that we know which face to draw. */
16235 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16237 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16238 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16239 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16244 /* Save some values that must not be changed. */
16245 int saved_x
= it
->current_x
;
16246 struct text_pos saved_pos
;
16247 Lisp_Object saved_object
;
16248 enum display_element_type saved_what
= it
->what
;
16249 int saved_face_id
= it
->face_id
;
16251 saved_object
= it
->object
;
16252 saved_pos
= it
->position
;
16254 it
->what
= IT_CHARACTER
;
16255 bzero (&it
->position
, sizeof it
->position
);
16256 it
->object
= make_number (0);
16259 it
->face_id
= face
->id
;
16261 PRODUCE_GLYPHS (it
);
16263 while (it
->current_x
<= it
->last_visible_x
)
16264 PRODUCE_GLYPHS (it
);
16266 /* Don't count these blanks really. It would let us insert a left
16267 truncation glyph below and make us set the cursor on them, maybe. */
16268 it
->current_x
= saved_x
;
16269 it
->object
= saved_object
;
16270 it
->position
= saved_pos
;
16271 it
->what
= saved_what
;
16272 it
->face_id
= saved_face_id
;
16277 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16278 trailing whitespace. */
16281 trailing_whitespace_p (charpos
)
16284 int bytepos
= CHAR_TO_BYTE (charpos
);
16287 while (bytepos
< ZV_BYTE
16288 && (c
= FETCH_CHAR (bytepos
),
16289 c
== ' ' || c
== '\t'))
16292 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16294 if (bytepos
!= PT_BYTE
)
16301 /* Highlight trailing whitespace, if any, in ROW. */
16304 highlight_trailing_whitespace (f
, row
)
16306 struct glyph_row
*row
;
16308 int used
= row
->used
[TEXT_AREA
];
16312 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16313 struct glyph
*glyph
= start
+ used
- 1;
16315 /* Skip over glyphs inserted to display the cursor at the
16316 end of a line, for extending the face of the last glyph
16317 to the end of the line on terminals, and for truncation
16318 and continuation glyphs. */
16319 while (glyph
>= start
16320 && glyph
->type
== CHAR_GLYPH
16321 && INTEGERP (glyph
->object
))
16324 /* If last glyph is a space or stretch, and it's trailing
16325 whitespace, set the face of all trailing whitespace glyphs in
16326 IT->glyph_row to `trailing-whitespace'. */
16328 && BUFFERP (glyph
->object
)
16329 && (glyph
->type
== STRETCH_GLYPH
16330 || (glyph
->type
== CHAR_GLYPH
16331 && glyph
->u
.ch
== ' '))
16332 && trailing_whitespace_p (glyph
->charpos
))
16334 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16338 while (glyph
>= start
16339 && BUFFERP (glyph
->object
)
16340 && (glyph
->type
== STRETCH_GLYPH
16341 || (glyph
->type
== CHAR_GLYPH
16342 && glyph
->u
.ch
== ' ')))
16343 (glyph
--)->face_id
= face_id
;
16349 /* Value is non-zero if glyph row ROW in window W should be
16350 used to hold the cursor. */
16353 cursor_row_p (w
, row
)
16355 struct glyph_row
*row
;
16357 int cursor_row_p
= 1;
16359 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16361 /* Suppose the row ends on a string.
16362 Unless the row is continued, that means it ends on a newline
16363 in the string. If it's anything other than a display string
16364 (e.g. a before-string from an overlay), we don't want the
16365 cursor there. (This heuristic seems to give the optimal
16366 behavior for the various types of multi-line strings.) */
16367 if (CHARPOS (row
->end
.string_pos
) >= 0)
16369 if (row
->continued_p
)
16373 /* Check for `display' property. */
16374 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16375 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16376 struct glyph
*glyph
;
16379 for (glyph
= end
; glyph
>= beg
; --glyph
)
16380 if (STRINGP (glyph
->object
))
16383 = Fget_char_property (make_number (PT
),
16387 && display_prop_string_p (prop
, glyph
->object
));
16392 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16394 /* If the row ends in middle of a real character,
16395 and the line is continued, we want the cursor here.
16396 That's because MATRIX_ROW_END_CHARPOS would equal
16397 PT if PT is before the character. */
16398 if (!row
->ends_in_ellipsis_p
)
16399 cursor_row_p
= row
->continued_p
;
16401 /* If the row ends in an ellipsis, then
16402 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16403 We want that position to be displayed after the ellipsis. */
16406 /* If the row ends at ZV, display the cursor at the end of that
16407 row instead of at the start of the row below. */
16408 else if (row
->ends_at_zv_p
)
16414 return cursor_row_p
;
16419 /* Push the display property PROP so that it will be rendered at the
16420 current position in IT. */
16423 push_display_prop (struct it
*it
, Lisp_Object prop
)
16427 /* Never display a cursor on the prefix. */
16428 it
->avoid_cursor_p
= 1;
16430 if (STRINGP (prop
))
16432 if (SCHARS (prop
) == 0)
16439 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16440 it
->current
.overlay_string_index
= -1;
16441 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16442 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16443 it
->method
= GET_FROM_STRING
;
16444 it
->stop_charpos
= 0;
16446 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16448 it
->method
= GET_FROM_STRETCH
;
16451 #ifdef HAVE_WINDOW_SYSTEM
16452 else if (IMAGEP (prop
))
16454 it
->what
= IT_IMAGE
;
16455 it
->image_id
= lookup_image (it
->f
, prop
);
16456 it
->method
= GET_FROM_IMAGE
;
16458 #endif /* HAVE_WINDOW_SYSTEM */
16461 pop_it (it
); /* bogus display property, give up */
16466 /* Return the character-property PROP at the current position in IT. */
16469 get_it_property (it
, prop
)
16473 Lisp_Object position
;
16475 if (STRINGP (it
->object
))
16476 position
= make_number (IT_STRING_CHARPOS (*it
));
16477 else if (BUFFERP (it
->object
))
16478 position
= make_number (IT_CHARPOS (*it
));
16482 return Fget_char_property (position
, prop
, it
->object
);
16485 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16488 handle_line_prefix (struct it
*it
)
16490 Lisp_Object prefix
;
16491 if (it
->continuation_lines_width
> 0)
16493 prefix
= get_it_property (it
, Qwrap_prefix
);
16495 prefix
= Vwrap_prefix
;
16499 prefix
= get_it_property (it
, Qline_prefix
);
16501 prefix
= Vline_prefix
;
16503 if (! NILP (prefix
))
16504 push_display_prop (it
, prefix
);
16509 /* Construct the glyph row IT->glyph_row in the desired matrix of
16510 IT->w from text at the current position of IT. See dispextern.h
16511 for an overview of struct it. Value is non-zero if
16512 IT->glyph_row displays text, as opposed to a line displaying ZV
16519 struct glyph_row
*row
= it
->glyph_row
;
16520 Lisp_Object overlay_arrow_string
;
16522 int may_wrap
= 0, wrap_x
;
16523 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16524 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16525 int wrap_row_extra_line_spacing
;
16527 /* We always start displaying at hpos zero even if hscrolled. */
16528 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16530 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16531 >= it
->w
->desired_matrix
->nrows
)
16533 it
->w
->nrows_scale_factor
++;
16534 fonts_changed_p
= 1;
16538 /* Is IT->w showing the region? */
16539 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16541 /* Clear the result glyph row and enable it. */
16542 prepare_desired_row (row
);
16544 row
->y
= it
->current_y
;
16545 row
->start
= it
->start
;
16546 row
->continuation_lines_width
= it
->continuation_lines_width
;
16547 row
->displays_text_p
= 1;
16548 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16549 it
->starts_in_middle_of_char_p
= 0;
16551 /* Arrange the overlays nicely for our purposes. Usually, we call
16552 display_line on only one line at a time, in which case this
16553 can't really hurt too much, or we call it on lines which appear
16554 one after another in the buffer, in which case all calls to
16555 recenter_overlay_lists but the first will be pretty cheap. */
16556 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16558 /* Move over display elements that are not visible because we are
16559 hscrolled. This may stop at an x-position < IT->first_visible_x
16560 if the first glyph is partially visible or if we hit a line end. */
16561 if (it
->current_x
< it
->first_visible_x
)
16563 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16564 MOVE_TO_POS
| MOVE_TO_X
);
16568 /* We only do this when not calling `move_it_in_display_line_to'
16569 above, because move_it_in_display_line_to calls
16570 handle_line_prefix itself. */
16571 handle_line_prefix (it
);
16574 /* Get the initial row height. This is either the height of the
16575 text hscrolled, if there is any, or zero. */
16576 row
->ascent
= it
->max_ascent
;
16577 row
->height
= it
->max_ascent
+ it
->max_descent
;
16578 row
->phys_ascent
= it
->max_phys_ascent
;
16579 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16580 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16582 /* Loop generating characters. The loop is left with IT on the next
16583 character to display. */
16586 int n_glyphs_before
, hpos_before
, x_before
;
16588 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16590 /* Retrieve the next thing to display. Value is zero if end of
16592 if (!get_next_display_element (it
))
16594 /* Maybe add a space at the end of this line that is used to
16595 display the cursor there under X. Set the charpos of the
16596 first glyph of blank lines not corresponding to any text
16598 #ifdef HAVE_WINDOW_SYSTEM
16599 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16600 row
->exact_window_width_line_p
= 1;
16602 #endif /* HAVE_WINDOW_SYSTEM */
16603 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16604 || row
->used
[TEXT_AREA
] == 0)
16606 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16607 row
->displays_text_p
= 0;
16609 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16610 && (!MINI_WINDOW_P (it
->w
)
16611 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16612 row
->indicate_empty_line_p
= 1;
16615 it
->continuation_lines_width
= 0;
16616 row
->ends_at_zv_p
= 1;
16620 /* Now, get the metrics of what we want to display. This also
16621 generates glyphs in `row' (which is IT->glyph_row). */
16622 n_glyphs_before
= row
->used
[TEXT_AREA
];
16625 /* Remember the line height so far in case the next element doesn't
16626 fit on the line. */
16627 if (it
->line_wrap
!= TRUNCATE
)
16629 ascent
= it
->max_ascent
;
16630 descent
= it
->max_descent
;
16631 phys_ascent
= it
->max_phys_ascent
;
16632 phys_descent
= it
->max_phys_descent
;
16634 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16636 if (IT_DISPLAYING_WHITESPACE (it
))
16642 wrap_row_used
= row
->used
[TEXT_AREA
];
16643 wrap_row_ascent
= row
->ascent
;
16644 wrap_row_height
= row
->height
;
16645 wrap_row_phys_ascent
= row
->phys_ascent
;
16646 wrap_row_phys_height
= row
->phys_height
;
16647 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16653 PRODUCE_GLYPHS (it
);
16655 /* If this display element was in marginal areas, continue with
16657 if (it
->area
!= TEXT_AREA
)
16659 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16660 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16661 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16662 row
->phys_height
= max (row
->phys_height
,
16663 it
->max_phys_ascent
+ it
->max_phys_descent
);
16664 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16665 it
->max_extra_line_spacing
);
16666 set_iterator_to_next (it
, 1);
16670 /* Does the display element fit on the line? If we truncate
16671 lines, we should draw past the right edge of the window. If
16672 we don't truncate, we want to stop so that we can display the
16673 continuation glyph before the right margin. If lines are
16674 continued, there are two possible strategies for characters
16675 resulting in more than 1 glyph (e.g. tabs): Display as many
16676 glyphs as possible in this line and leave the rest for the
16677 continuation line, or display the whole element in the next
16678 line. Original redisplay did the former, so we do it also. */
16679 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16680 hpos_before
= it
->hpos
;
16683 if (/* Not a newline. */
16685 /* Glyphs produced fit entirely in the line. */
16686 && it
->current_x
< it
->last_visible_x
)
16688 it
->hpos
+= nglyphs
;
16689 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16690 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16691 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16692 row
->phys_height
= max (row
->phys_height
,
16693 it
->max_phys_ascent
+ it
->max_phys_descent
);
16694 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16695 it
->max_extra_line_spacing
);
16696 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16697 row
->x
= x
- it
->first_visible_x
;
16702 struct glyph
*glyph
;
16704 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16706 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16707 new_x
= x
+ glyph
->pixel_width
;
16709 if (/* Lines are continued. */
16710 it
->line_wrap
!= TRUNCATE
16711 && (/* Glyph doesn't fit on the line. */
16712 new_x
> it
->last_visible_x
16713 /* Or it fits exactly on a window system frame. */
16714 || (new_x
== it
->last_visible_x
16715 && FRAME_WINDOW_P (it
->f
))))
16717 /* End of a continued line. */
16720 || (new_x
== it
->last_visible_x
16721 && FRAME_WINDOW_P (it
->f
)))
16723 /* Current glyph is the only one on the line or
16724 fits exactly on the line. We must continue
16725 the line because we can't draw the cursor
16726 after the glyph. */
16727 row
->continued_p
= 1;
16728 it
->current_x
= new_x
;
16729 it
->continuation_lines_width
+= new_x
;
16731 if (i
== nglyphs
- 1)
16733 /* If line-wrap is on, check if a previous
16734 wrap point was found. */
16735 if (wrap_row_used
> 0
16736 /* Even if there is a previous wrap
16737 point, continue the line here as
16738 usual, if (i) the previous character
16739 was a space or tab AND (ii) the
16740 current character is not. */
16742 || IT_DISPLAYING_WHITESPACE (it
)))
16745 set_iterator_to_next (it
, 1);
16746 #ifdef HAVE_WINDOW_SYSTEM
16747 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16749 if (!get_next_display_element (it
))
16751 row
->exact_window_width_line_p
= 1;
16752 it
->continuation_lines_width
= 0;
16753 row
->continued_p
= 0;
16754 row
->ends_at_zv_p
= 1;
16756 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16758 row
->continued_p
= 0;
16759 row
->exact_window_width_line_p
= 1;
16762 #endif /* HAVE_WINDOW_SYSTEM */
16765 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16766 && !FRAME_WINDOW_P (it
->f
))
16768 /* A padding glyph that doesn't fit on this line.
16769 This means the whole character doesn't fit
16771 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16773 /* Fill the rest of the row with continuation
16774 glyphs like in 20.x. */
16775 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16776 < row
->glyphs
[1 + TEXT_AREA
])
16777 produce_special_glyphs (it
, IT_CONTINUATION
);
16779 row
->continued_p
= 1;
16780 it
->current_x
= x_before
;
16781 it
->continuation_lines_width
+= x_before
;
16783 /* Restore the height to what it was before the
16784 element not fitting on the line. */
16785 it
->max_ascent
= ascent
;
16786 it
->max_descent
= descent
;
16787 it
->max_phys_ascent
= phys_ascent
;
16788 it
->max_phys_descent
= phys_descent
;
16790 else if (wrap_row_used
> 0)
16794 it
->continuation_lines_width
+= wrap_x
;
16795 row
->used
[TEXT_AREA
] = wrap_row_used
;
16796 row
->ascent
= wrap_row_ascent
;
16797 row
->height
= wrap_row_height
;
16798 row
->phys_ascent
= wrap_row_phys_ascent
;
16799 row
->phys_height
= wrap_row_phys_height
;
16800 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16801 row
->continued_p
= 1;
16802 row
->ends_at_zv_p
= 0;
16803 row
->exact_window_width_line_p
= 0;
16804 it
->continuation_lines_width
+= x
;
16806 /* Make sure that a non-default face is extended
16807 up to the right margin of the window. */
16808 extend_face_to_end_of_line (it
);
16810 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16812 /* A TAB that extends past the right edge of the
16813 window. This produces a single glyph on
16814 window system frames. We leave the glyph in
16815 this row and let it fill the row, but don't
16816 consume the TAB. */
16817 it
->continuation_lines_width
+= it
->last_visible_x
;
16818 row
->ends_in_middle_of_char_p
= 1;
16819 row
->continued_p
= 1;
16820 glyph
->pixel_width
= it
->last_visible_x
- x
;
16821 it
->starts_in_middle_of_char_p
= 1;
16825 /* Something other than a TAB that draws past
16826 the right edge of the window. Restore
16827 positions to values before the element. */
16828 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16830 /* Display continuation glyphs. */
16831 if (!FRAME_WINDOW_P (it
->f
))
16832 produce_special_glyphs (it
, IT_CONTINUATION
);
16833 row
->continued_p
= 1;
16835 it
->current_x
= x_before
;
16836 it
->continuation_lines_width
+= x
;
16837 extend_face_to_end_of_line (it
);
16839 if (nglyphs
> 1 && i
> 0)
16841 row
->ends_in_middle_of_char_p
= 1;
16842 it
->starts_in_middle_of_char_p
= 1;
16845 /* Restore the height to what it was before the
16846 element not fitting on the line. */
16847 it
->max_ascent
= ascent
;
16848 it
->max_descent
= descent
;
16849 it
->max_phys_ascent
= phys_ascent
;
16850 it
->max_phys_descent
= phys_descent
;
16855 else if (new_x
> it
->first_visible_x
)
16857 /* Increment number of glyphs actually displayed. */
16860 if (x
< it
->first_visible_x
)
16861 /* Glyph is partially visible, i.e. row starts at
16862 negative X position. */
16863 row
->x
= x
- it
->first_visible_x
;
16867 /* Glyph is completely off the left margin of the
16868 window. This should not happen because of the
16869 move_it_in_display_line at the start of this
16870 function, unless the text display area of the
16871 window is empty. */
16872 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16876 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16877 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16878 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16879 row
->phys_height
= max (row
->phys_height
,
16880 it
->max_phys_ascent
+ it
->max_phys_descent
);
16881 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16882 it
->max_extra_line_spacing
);
16884 /* End of this display line if row is continued. */
16885 if (row
->continued_p
|| row
->ends_at_zv_p
)
16890 /* Is this a line end? If yes, we're also done, after making
16891 sure that a non-default face is extended up to the right
16892 margin of the window. */
16893 if (ITERATOR_AT_END_OF_LINE_P (it
))
16895 int used_before
= row
->used
[TEXT_AREA
];
16897 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16899 #ifdef HAVE_WINDOW_SYSTEM
16900 /* Add a space at the end of the line that is used to
16901 display the cursor there. */
16902 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16903 append_space_for_newline (it
, 0);
16904 #endif /* HAVE_WINDOW_SYSTEM */
16906 /* Extend the face to the end of the line. */
16907 extend_face_to_end_of_line (it
);
16909 /* Make sure we have the position. */
16910 if (used_before
== 0)
16911 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16913 /* Consume the line end. This skips over invisible lines. */
16914 set_iterator_to_next (it
, 1);
16915 it
->continuation_lines_width
= 0;
16919 /* Proceed with next display element. Note that this skips
16920 over lines invisible because of selective display. */
16921 set_iterator_to_next (it
, 1);
16923 /* If we truncate lines, we are done when the last displayed
16924 glyphs reach past the right margin of the window. */
16925 if (it
->line_wrap
== TRUNCATE
16926 && (FRAME_WINDOW_P (it
->f
)
16927 ? (it
->current_x
>= it
->last_visible_x
)
16928 : (it
->current_x
> it
->last_visible_x
)))
16930 /* Maybe add truncation glyphs. */
16931 if (!FRAME_WINDOW_P (it
->f
))
16935 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16936 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16939 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16941 row
->used
[TEXT_AREA
] = i
;
16942 produce_special_glyphs (it
, IT_TRUNCATION
);
16945 #ifdef HAVE_WINDOW_SYSTEM
16948 /* Don't truncate if we can overflow newline into fringe. */
16949 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16951 if (!get_next_display_element (it
))
16953 it
->continuation_lines_width
= 0;
16954 row
->ends_at_zv_p
= 1;
16955 row
->exact_window_width_line_p
= 1;
16958 if (ITERATOR_AT_END_OF_LINE_P (it
))
16960 row
->exact_window_width_line_p
= 1;
16961 goto at_end_of_line
;
16965 #endif /* HAVE_WINDOW_SYSTEM */
16967 row
->truncated_on_right_p
= 1;
16968 it
->continuation_lines_width
= 0;
16969 reseat_at_next_visible_line_start (it
, 0);
16970 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16971 it
->hpos
= hpos_before
;
16972 it
->current_x
= x_before
;
16977 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16978 at the left window margin. */
16979 if (it
->first_visible_x
16980 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16982 if (!FRAME_WINDOW_P (it
->f
))
16983 insert_left_trunc_glyphs (it
);
16984 row
->truncated_on_left_p
= 1;
16987 /* If the start of this line is the overlay arrow-position, then
16988 mark this glyph row as the one containing the overlay arrow.
16989 This is clearly a mess with variable size fonts. It would be
16990 better to let it be displayed like cursors under X. */
16991 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16992 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16993 !NILP (overlay_arrow_string
)))
16995 /* Overlay arrow in window redisplay is a fringe bitmap. */
16996 if (STRINGP (overlay_arrow_string
))
16998 struct glyph_row
*arrow_row
16999 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17000 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17001 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17002 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17003 struct glyph
*p2
, *end
;
17005 /* Copy the arrow glyphs. */
17006 while (glyph
< arrow_end
)
17009 /* Throw away padding glyphs. */
17011 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17012 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17018 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17023 xassert (INTEGERP (overlay_arrow_string
));
17024 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17026 overlay_arrow_seen
= 1;
17029 /* Compute pixel dimensions of this line. */
17030 compute_line_metrics (it
);
17032 /* Remember the position at which this line ends. */
17033 row
->end
= it
->current
;
17035 /* Record whether this row ends inside an ellipsis. */
17036 row
->ends_in_ellipsis_p
17037 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17038 && it
->ellipsis_p
);
17040 /* Save fringe bitmaps in this row. */
17041 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17042 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17043 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17044 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17046 it
->left_user_fringe_bitmap
= 0;
17047 it
->left_user_fringe_face_id
= 0;
17048 it
->right_user_fringe_bitmap
= 0;
17049 it
->right_user_fringe_face_id
= 0;
17051 /* Maybe set the cursor. */
17052 if (it
->w
->cursor
.vpos
< 0
17053 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17054 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17055 && cursor_row_p (it
->w
, row
))
17056 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17058 /* Highlight trailing whitespace. */
17059 if (!NILP (Vshow_trailing_whitespace
))
17060 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17062 /* Prepare for the next line. This line starts horizontally at (X
17063 HPOS) = (0 0). Vertical positions are incremented. As a
17064 convenience for the caller, IT->glyph_row is set to the next
17066 it
->current_x
= it
->hpos
= 0;
17067 it
->current_y
+= row
->height
;
17070 it
->start
= it
->current
;
17071 return row
->displays_text_p
;
17076 /***********************************************************************
17078 ***********************************************************************/
17080 /* Redisplay the menu bar in the frame for window W.
17082 The menu bar of X frames that don't have X toolkit support is
17083 displayed in a special window W->frame->menu_bar_window.
17085 The menu bar of terminal frames is treated specially as far as
17086 glyph matrices are concerned. Menu bar lines are not part of
17087 windows, so the update is done directly on the frame matrix rows
17088 for the menu bar. */
17091 display_menu_bar (w
)
17094 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17099 /* Don't do all this for graphical frames. */
17101 if (FRAME_W32_P (f
))
17104 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17110 if (FRAME_NS_P (f
))
17112 #endif /* HAVE_NS */
17114 #ifdef USE_X_TOOLKIT
17115 xassert (!FRAME_WINDOW_P (f
));
17116 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17117 it
.first_visible_x
= 0;
17118 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17119 #else /* not USE_X_TOOLKIT */
17120 if (FRAME_WINDOW_P (f
))
17122 /* Menu bar lines are displayed in the desired matrix of the
17123 dummy window menu_bar_window. */
17124 struct window
*menu_w
;
17125 xassert (WINDOWP (f
->menu_bar_window
));
17126 menu_w
= XWINDOW (f
->menu_bar_window
);
17127 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17129 it
.first_visible_x
= 0;
17130 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17134 /* This is a TTY frame, i.e. character hpos/vpos are used as
17136 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17138 it
.first_visible_x
= 0;
17139 it
.last_visible_x
= FRAME_COLS (f
);
17141 #endif /* not USE_X_TOOLKIT */
17143 if (! mode_line_inverse_video
)
17144 /* Force the menu-bar to be displayed in the default face. */
17145 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17147 /* Clear all rows of the menu bar. */
17148 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17150 struct glyph_row
*row
= it
.glyph_row
+ i
;
17151 clear_glyph_row (row
);
17152 row
->enabled_p
= 1;
17153 row
->full_width_p
= 1;
17156 /* Display all items of the menu bar. */
17157 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17158 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17160 Lisp_Object string
;
17162 /* Stop at nil string. */
17163 string
= AREF (items
, i
+ 1);
17167 /* Remember where item was displayed. */
17168 ASET (items
, i
+ 3, make_number (it
.hpos
));
17170 /* Display the item, pad with one space. */
17171 if (it
.current_x
< it
.last_visible_x
)
17172 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17173 SCHARS (string
) + 1, 0, 0, -1);
17176 /* Fill out the line with spaces. */
17177 if (it
.current_x
< it
.last_visible_x
)
17178 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17180 /* Compute the total height of the lines. */
17181 compute_line_metrics (&it
);
17186 /***********************************************************************
17188 ***********************************************************************/
17190 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17191 FORCE is non-zero, redisplay mode lines unconditionally.
17192 Otherwise, redisplay only mode lines that are garbaged. Value is
17193 the number of windows whose mode lines were redisplayed. */
17196 redisplay_mode_lines (window
, force
)
17197 Lisp_Object window
;
17202 while (!NILP (window
))
17204 struct window
*w
= XWINDOW (window
);
17206 if (WINDOWP (w
->hchild
))
17207 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17208 else if (WINDOWP (w
->vchild
))
17209 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17211 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17212 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17214 struct text_pos lpoint
;
17215 struct buffer
*old
= current_buffer
;
17217 /* Set the window's buffer for the mode line display. */
17218 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17219 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17221 /* Point refers normally to the selected window. For any
17222 other window, set up appropriate value. */
17223 if (!EQ (window
, selected_window
))
17225 struct text_pos pt
;
17227 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17228 if (CHARPOS (pt
) < BEGV
)
17229 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17230 else if (CHARPOS (pt
) > (ZV
- 1))
17231 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17233 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17236 /* Display mode lines. */
17237 clear_glyph_matrix (w
->desired_matrix
);
17238 if (display_mode_lines (w
))
17241 w
->must_be_updated_p
= 1;
17244 /* Restore old settings. */
17245 set_buffer_internal_1 (old
);
17246 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17256 /* Display the mode and/or top line of window W. Value is the number
17257 of mode lines displayed. */
17260 display_mode_lines (w
)
17263 Lisp_Object old_selected_window
, old_selected_frame
;
17266 old_selected_frame
= selected_frame
;
17267 selected_frame
= w
->frame
;
17268 old_selected_window
= selected_window
;
17269 XSETWINDOW (selected_window
, w
);
17271 /* These will be set while the mode line specs are processed. */
17272 line_number_displayed
= 0;
17273 w
->column_number_displayed
= Qnil
;
17275 if (WINDOW_WANTS_MODELINE_P (w
))
17277 struct window
*sel_w
= XWINDOW (old_selected_window
);
17279 /* Select mode line face based on the real selected window. */
17280 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17281 current_buffer
->mode_line_format
);
17285 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17287 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17288 current_buffer
->header_line_format
);
17292 selected_frame
= old_selected_frame
;
17293 selected_window
= old_selected_window
;
17298 /* Display mode or top line of window W. FACE_ID specifies which line
17299 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
17300 FORMAT is the mode line format to display. Value is the pixel
17301 height of the mode line displayed. */
17304 display_mode_line (w
, face_id
, format
)
17306 enum face_id face_id
;
17307 Lisp_Object format
;
17311 int count
= SPECPDL_INDEX ();
17313 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17314 /* Don't extend on a previously drawn mode-line.
17315 This may happen if called from pos_visible_p. */
17316 it
.glyph_row
->enabled_p
= 0;
17317 prepare_desired_row (it
.glyph_row
);
17319 it
.glyph_row
->mode_line_p
= 1;
17321 if (! mode_line_inverse_video
)
17322 /* Force the mode-line to be displayed in the default face. */
17323 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17325 record_unwind_protect (unwind_format_mode_line
,
17326 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17328 mode_line_target
= MODE_LINE_DISPLAY
;
17330 /* Temporarily make frame's keyboard the current kboard so that
17331 kboard-local variables in the mode_line_format will get the right
17333 push_kboard (FRAME_KBOARD (it
.f
));
17334 record_unwind_save_match_data ();
17335 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17338 unbind_to (count
, Qnil
);
17340 /* Fill up with spaces. */
17341 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17343 compute_line_metrics (&it
);
17344 it
.glyph_row
->full_width_p
= 1;
17345 it
.glyph_row
->continued_p
= 0;
17346 it
.glyph_row
->truncated_on_left_p
= 0;
17347 it
.glyph_row
->truncated_on_right_p
= 0;
17349 /* Make a 3D mode-line have a shadow at its right end. */
17350 face
= FACE_FROM_ID (it
.f
, face_id
);
17351 extend_face_to_end_of_line (&it
);
17352 if (face
->box
!= FACE_NO_BOX
)
17354 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17355 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17356 last
->right_box_line_p
= 1;
17359 return it
.glyph_row
->height
;
17362 /* Move element ELT in LIST to the front of LIST.
17363 Return the updated list. */
17366 move_elt_to_front (elt
, list
)
17367 Lisp_Object elt
, list
;
17369 register Lisp_Object tail
, prev
;
17370 register Lisp_Object tem
;
17374 while (CONSP (tail
))
17380 /* Splice out the link TAIL. */
17382 list
= XCDR (tail
);
17384 Fsetcdr (prev
, XCDR (tail
));
17386 /* Now make it the first. */
17387 Fsetcdr (tail
, list
);
17392 tail
= XCDR (tail
);
17396 /* Not found--return unchanged LIST. */
17400 /* Contribute ELT to the mode line for window IT->w. How it
17401 translates into text depends on its data type.
17403 IT describes the display environment in which we display, as usual.
17405 DEPTH is the depth in recursion. It is used to prevent
17406 infinite recursion here.
17408 FIELD_WIDTH is the number of characters the display of ELT should
17409 occupy in the mode line, and PRECISION is the maximum number of
17410 characters to display from ELT's representation. See
17411 display_string for details.
17413 Returns the hpos of the end of the text generated by ELT.
17415 PROPS is a property list to add to any string we encounter.
17417 If RISKY is nonzero, remove (disregard) any properties in any string
17418 we encounter, and ignore :eval and :propertize.
17420 The global variable `mode_line_target' determines whether the
17421 output is passed to `store_mode_line_noprop',
17422 `store_mode_line_string', or `display_string'. */
17425 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17428 int field_width
, precision
;
17429 Lisp_Object elt
, props
;
17432 int n
= 0, field
, prec
;
17437 elt
= build_string ("*too-deep*");
17441 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17445 /* A string: output it and check for %-constructs within it. */
17449 if (SCHARS (elt
) > 0
17450 && (!NILP (props
) || risky
))
17452 Lisp_Object oprops
, aelt
;
17453 oprops
= Ftext_properties_at (make_number (0), elt
);
17455 /* If the starting string's properties are not what
17456 we want, translate the string. Also, if the string
17457 is risky, do that anyway. */
17459 if (NILP (Fequal (props
, oprops
)) || risky
)
17461 /* If the starting string has properties,
17462 merge the specified ones onto the existing ones. */
17463 if (! NILP (oprops
) && !risky
)
17467 oprops
= Fcopy_sequence (oprops
);
17469 while (CONSP (tem
))
17471 oprops
= Fplist_put (oprops
, XCAR (tem
),
17472 XCAR (XCDR (tem
)));
17473 tem
= XCDR (XCDR (tem
));
17478 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17479 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17481 /* AELT is what we want. Move it to the front
17482 without consing. */
17484 mode_line_proptrans_alist
17485 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17491 /* If AELT has the wrong props, it is useless.
17492 so get rid of it. */
17494 mode_line_proptrans_alist
17495 = Fdelq (aelt
, mode_line_proptrans_alist
);
17497 elt
= Fcopy_sequence (elt
);
17498 Fset_text_properties (make_number (0), Flength (elt
),
17500 /* Add this item to mode_line_proptrans_alist. */
17501 mode_line_proptrans_alist
17502 = Fcons (Fcons (elt
, props
),
17503 mode_line_proptrans_alist
);
17504 /* Truncate mode_line_proptrans_alist
17505 to at most 50 elements. */
17506 tem
= Fnthcdr (make_number (50),
17507 mode_line_proptrans_alist
);
17509 XSETCDR (tem
, Qnil
);
17518 prec
= precision
- n
;
17519 switch (mode_line_target
)
17521 case MODE_LINE_NOPROP
:
17522 case MODE_LINE_TITLE
:
17523 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17525 case MODE_LINE_STRING
:
17526 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17528 case MODE_LINE_DISPLAY
:
17529 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17530 0, prec
, 0, STRING_MULTIBYTE (elt
));
17537 /* Handle the non-literal case. */
17539 while ((precision
<= 0 || n
< precision
)
17540 && SREF (elt
, offset
) != 0
17541 && (mode_line_target
!= MODE_LINE_DISPLAY
17542 || it
->current_x
< it
->last_visible_x
))
17544 int last_offset
= offset
;
17546 /* Advance to end of string or next format specifier. */
17547 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17550 if (offset
- 1 != last_offset
)
17552 int nchars
, nbytes
;
17554 /* Output to end of string or up to '%'. Field width
17555 is length of string. Don't output more than
17556 PRECISION allows us. */
17559 prec
= c_string_width (SDATA (elt
) + last_offset
,
17560 offset
- last_offset
, precision
- n
,
17563 switch (mode_line_target
)
17565 case MODE_LINE_NOPROP
:
17566 case MODE_LINE_TITLE
:
17567 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17569 case MODE_LINE_STRING
:
17571 int bytepos
= last_offset
;
17572 int charpos
= string_byte_to_char (elt
, bytepos
);
17573 int endpos
= (precision
<= 0
17574 ? string_byte_to_char (elt
, offset
)
17575 : charpos
+ nchars
);
17577 n
+= store_mode_line_string (NULL
,
17578 Fsubstring (elt
, make_number (charpos
),
17579 make_number (endpos
)),
17583 case MODE_LINE_DISPLAY
:
17585 int bytepos
= last_offset
;
17586 int charpos
= string_byte_to_char (elt
, bytepos
);
17588 if (precision
<= 0)
17589 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17590 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17592 STRING_MULTIBYTE (elt
));
17597 else /* c == '%' */
17599 int percent_position
= offset
;
17601 /* Get the specified minimum width. Zero means
17604 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17605 field
= field
* 10 + c
- '0';
17607 /* Don't pad beyond the total padding allowed. */
17608 if (field_width
- n
> 0 && field
> field_width
- n
)
17609 field
= field_width
- n
;
17611 /* Note that either PRECISION <= 0 or N < PRECISION. */
17612 prec
= precision
- n
;
17615 n
+= display_mode_element (it
, depth
, field
, prec
,
17616 Vglobal_mode_string
, props
,
17621 int bytepos
, charpos
;
17622 unsigned char *spec
;
17624 bytepos
= percent_position
;
17625 charpos
= (STRING_MULTIBYTE (elt
)
17626 ? string_byte_to_char (elt
, bytepos
)
17629 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17631 switch (mode_line_target
)
17633 case MODE_LINE_NOPROP
:
17634 case MODE_LINE_TITLE
:
17635 n
+= store_mode_line_noprop (spec
, field
, prec
);
17637 case MODE_LINE_STRING
:
17639 int len
= strlen (spec
);
17640 Lisp_Object tem
= make_string (spec
, len
);
17641 props
= Ftext_properties_at (make_number (charpos
), elt
);
17642 /* Should only keep face property in props */
17643 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17646 case MODE_LINE_DISPLAY
:
17648 int nglyphs_before
, nwritten
;
17650 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17651 nwritten
= display_string (spec
, Qnil
, elt
,
17656 /* Assign to the glyphs written above the
17657 string where the `%x' came from, position
17661 struct glyph
*glyph
17662 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17666 for (i
= 0; i
< nwritten
; ++i
)
17668 glyph
[i
].object
= elt
;
17669 glyph
[i
].charpos
= charpos
;
17686 /* A symbol: process the value of the symbol recursively
17687 as if it appeared here directly. Avoid error if symbol void.
17688 Special case: if value of symbol is a string, output the string
17691 register Lisp_Object tem
;
17693 /* If the variable is not marked as risky to set
17694 then its contents are risky to use. */
17695 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17698 tem
= Fboundp (elt
);
17701 tem
= Fsymbol_value (elt
);
17702 /* If value is a string, output that string literally:
17703 don't check for % within it. */
17707 if (!EQ (tem
, elt
))
17709 /* Give up right away for nil or t. */
17719 register Lisp_Object car
, tem
;
17721 /* A cons cell: five distinct cases.
17722 If first element is :eval or :propertize, do something special.
17723 If first element is a string or a cons, process all the elements
17724 and effectively concatenate them.
17725 If first element is a negative number, truncate displaying cdr to
17726 at most that many characters. If positive, pad (with spaces)
17727 to at least that many characters.
17728 If first element is a symbol, process the cadr or caddr recursively
17729 according to whether the symbol's value is non-nil or nil. */
17731 if (EQ (car
, QCeval
))
17733 /* An element of the form (:eval FORM) means evaluate FORM
17734 and use the result as mode line elements. */
17739 if (CONSP (XCDR (elt
)))
17742 spec
= safe_eval (XCAR (XCDR (elt
)));
17743 n
+= display_mode_element (it
, depth
, field_width
- n
,
17744 precision
- n
, spec
, props
,
17748 else if (EQ (car
, QCpropertize
))
17750 /* An element of the form (:propertize ELT PROPS...)
17751 means display ELT but applying properties PROPS. */
17756 if (CONSP (XCDR (elt
)))
17757 n
+= display_mode_element (it
, depth
, field_width
- n
,
17758 precision
- n
, XCAR (XCDR (elt
)),
17759 XCDR (XCDR (elt
)), risky
);
17761 else if (SYMBOLP (car
))
17763 tem
= Fboundp (car
);
17767 /* elt is now the cdr, and we know it is a cons cell.
17768 Use its car if CAR has a non-nil value. */
17771 tem
= Fsymbol_value (car
);
17778 /* Symbol's value is nil (or symbol is unbound)
17779 Get the cddr of the original list
17780 and if possible find the caddr and use that. */
17784 else if (!CONSP (elt
))
17789 else if (INTEGERP (car
))
17791 register int lim
= XINT (car
);
17795 /* Negative int means reduce maximum width. */
17796 if (precision
<= 0)
17799 precision
= min (precision
, -lim
);
17803 /* Padding specified. Don't let it be more than
17804 current maximum. */
17806 lim
= min (precision
, lim
);
17808 /* If that's more padding than already wanted, queue it.
17809 But don't reduce padding already specified even if
17810 that is beyond the current truncation point. */
17811 field_width
= max (lim
, field_width
);
17815 else if (STRINGP (car
) || CONSP (car
))
17817 register int limit
= 50;
17818 /* Limit is to protect against circular lists. */
17821 && (precision
<= 0 || n
< precision
))
17823 n
+= display_mode_element (it
, depth
,
17824 /* Do padding only after the last
17825 element in the list. */
17826 (! CONSP (XCDR (elt
))
17829 precision
- n
, XCAR (elt
),
17839 elt
= build_string ("*invalid*");
17843 /* Pad to FIELD_WIDTH. */
17844 if (field_width
> 0 && n
< field_width
)
17846 switch (mode_line_target
)
17848 case MODE_LINE_NOPROP
:
17849 case MODE_LINE_TITLE
:
17850 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17852 case MODE_LINE_STRING
:
17853 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17855 case MODE_LINE_DISPLAY
:
17856 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17865 /* Store a mode-line string element in mode_line_string_list.
17867 If STRING is non-null, display that C string. Otherwise, the Lisp
17868 string LISP_STRING is displayed.
17870 FIELD_WIDTH is the minimum number of output glyphs to produce.
17871 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17872 with spaces. FIELD_WIDTH <= 0 means don't pad.
17874 PRECISION is the maximum number of characters to output from
17875 STRING. PRECISION <= 0 means don't truncate the string.
17877 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17878 properties to the string.
17880 PROPS are the properties to add to the string.
17881 The mode_line_string_face face property is always added to the string.
17885 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17887 Lisp_Object lisp_string
;
17896 if (string
!= NULL
)
17898 len
= strlen (string
);
17899 if (precision
> 0 && len
> precision
)
17901 lisp_string
= make_string (string
, len
);
17903 props
= mode_line_string_face_prop
;
17904 else if (!NILP (mode_line_string_face
))
17906 Lisp_Object face
= Fplist_get (props
, Qface
);
17907 props
= Fcopy_sequence (props
);
17909 face
= mode_line_string_face
;
17911 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17912 props
= Fplist_put (props
, Qface
, face
);
17914 Fadd_text_properties (make_number (0), make_number (len
),
17915 props
, lisp_string
);
17919 len
= XFASTINT (Flength (lisp_string
));
17920 if (precision
> 0 && len
> precision
)
17923 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17926 if (!NILP (mode_line_string_face
))
17930 props
= Ftext_properties_at (make_number (0), lisp_string
);
17931 face
= Fplist_get (props
, Qface
);
17933 face
= mode_line_string_face
;
17935 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17936 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17938 lisp_string
= Fcopy_sequence (lisp_string
);
17941 Fadd_text_properties (make_number (0), make_number (len
),
17942 props
, lisp_string
);
17947 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17951 if (field_width
> len
)
17953 field_width
-= len
;
17954 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17956 Fadd_text_properties (make_number (0), make_number (field_width
),
17957 props
, lisp_string
);
17958 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17966 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17968 doc
: /* Format a string out of a mode line format specification.
17969 First arg FORMAT specifies the mode line format (see `mode-line-format'
17970 for details) to use.
17972 Optional second arg FACE specifies the face property to put
17973 on all characters for which no face is specified.
17974 The value t means whatever face the window's mode line currently uses
17975 \(either `mode-line' or `mode-line-inactive', depending).
17976 A value of nil means the default is no face property.
17977 If FACE is an integer, the value string has no text properties.
17979 Optional third and fourth args WINDOW and BUFFER specify the window
17980 and buffer to use as the context for the formatting (defaults
17981 are the selected window and the window's buffer). */)
17982 (format
, face
, window
, buffer
)
17983 Lisp_Object format
, face
, window
, buffer
;
17988 struct buffer
*old_buffer
= NULL
;
17990 int no_props
= INTEGERP (face
);
17991 int count
= SPECPDL_INDEX ();
17993 int string_start
= 0;
17996 window
= selected_window
;
17997 CHECK_WINDOW (window
);
17998 w
= XWINDOW (window
);
18001 buffer
= w
->buffer
;
18002 CHECK_BUFFER (buffer
);
18004 /* Make formatting the modeline a non-op when noninteractive, otherwise
18005 there will be problems later caused by a partially initialized frame. */
18006 if (NILP (format
) || noninteractive
)
18007 return empty_unibyte_string
;
18015 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
18016 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
18020 face_id
= DEFAULT_FACE_ID
;
18022 if (XBUFFER (buffer
) != current_buffer
)
18023 old_buffer
= current_buffer
;
18025 /* Save things including mode_line_proptrans_alist,
18026 and set that to nil so that we don't alter the outer value. */
18027 record_unwind_protect (unwind_format_mode_line
,
18028 format_mode_line_unwind_data
18029 (old_buffer
, selected_window
, 1));
18030 mode_line_proptrans_alist
= Qnil
;
18032 Fselect_window (window
, Qt
);
18034 set_buffer_internal_1 (XBUFFER (buffer
));
18036 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18040 mode_line_target
= MODE_LINE_NOPROP
;
18041 mode_line_string_face_prop
= Qnil
;
18042 mode_line_string_list
= Qnil
;
18043 string_start
= MODE_LINE_NOPROP_LEN (0);
18047 mode_line_target
= MODE_LINE_STRING
;
18048 mode_line_string_list
= Qnil
;
18049 mode_line_string_face
= face
;
18050 mode_line_string_face_prop
18051 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18054 push_kboard (FRAME_KBOARD (it
.f
));
18055 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18060 len
= MODE_LINE_NOPROP_LEN (string_start
);
18061 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18065 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18066 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18067 empty_unibyte_string
);
18070 unbind_to (count
, Qnil
);
18074 /* Write a null-terminated, right justified decimal representation of
18075 the positive integer D to BUF using a minimal field width WIDTH. */
18078 pint2str (buf
, width
, d
)
18079 register char *buf
;
18080 register int width
;
18083 register char *p
= buf
;
18091 *p
++ = d
% 10 + '0';
18096 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18107 /* Write a null-terminated, right justified decimal and "human
18108 readable" representation of the nonnegative integer D to BUF using
18109 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18111 static const char power_letter
[] =
18125 pint2hrstr (buf
, width
, d
)
18130 /* We aim to represent the nonnegative integer D as
18131 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18134 /* -1 means: do not use TENTHS. */
18138 /* Length of QUOTIENT.TENTHS as a string. */
18144 if (1000 <= quotient
)
18146 /* Scale to the appropriate EXPONENT. */
18149 remainder
= quotient
% 1000;
18153 while (1000 <= quotient
);
18155 /* Round to nearest and decide whether to use TENTHS or not. */
18158 tenths
= remainder
/ 100;
18159 if (50 <= remainder
% 100)
18166 if (quotient
== 10)
18174 if (500 <= remainder
)
18176 if (quotient
< 999)
18187 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18188 if (tenths
== -1 && quotient
<= 99)
18195 p
= psuffix
= buf
+ max (width
, length
);
18197 /* Print EXPONENT. */
18199 *psuffix
++ = power_letter
[exponent
];
18202 /* Print TENTHS. */
18205 *--p
= '0' + tenths
;
18209 /* Print QUOTIENT. */
18212 int digit
= quotient
% 10;
18213 *--p
= '0' + digit
;
18215 while ((quotient
/= 10) != 0);
18217 /* Print leading spaces. */
18222 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18223 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18224 type of CODING_SYSTEM. Return updated pointer into BUF. */
18226 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18229 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18230 Lisp_Object coding_system
;
18231 register char *buf
;
18235 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18236 const unsigned char *eol_str
;
18238 /* The EOL conversion we are using. */
18239 Lisp_Object eoltype
;
18241 val
= CODING_SYSTEM_SPEC (coding_system
);
18244 if (!VECTORP (val
)) /* Not yet decided. */
18249 eoltype
= eol_mnemonic_undecided
;
18250 /* Don't mention EOL conversion if it isn't decided. */
18255 Lisp_Object eolvalue
;
18257 attrs
= AREF (val
, 0);
18258 eolvalue
= AREF (val
, 2);
18261 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18265 /* The EOL conversion that is normal on this system. */
18267 if (NILP (eolvalue
)) /* Not yet decided. */
18268 eoltype
= eol_mnemonic_undecided
;
18269 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18270 eoltype
= eol_mnemonic_undecided
;
18271 else /* eolvalue is Qunix, Qdos, or Qmac. */
18272 eoltype
= (EQ (eolvalue
, Qunix
)
18273 ? eol_mnemonic_unix
18274 : (EQ (eolvalue
, Qdos
) == 1
18275 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18281 /* Mention the EOL conversion if it is not the usual one. */
18282 if (STRINGP (eoltype
))
18284 eol_str
= SDATA (eoltype
);
18285 eol_str_len
= SBYTES (eoltype
);
18287 else if (CHARACTERP (eoltype
))
18289 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18290 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18295 eol_str
= invalid_eol_type
;
18296 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18298 bcopy (eol_str
, buf
, eol_str_len
);
18299 buf
+= eol_str_len
;
18305 /* Return a string for the output of a mode line %-spec for window W,
18306 generated by character C. PRECISION >= 0 means don't return a
18307 string longer than that value. FIELD_WIDTH > 0 means pad the
18308 string returned with spaces to that value. Return 1 in *MULTIBYTE
18309 if the result is multibyte text.
18311 Note we operate on the current buffer for most purposes,
18312 the exception being w->base_line_pos. */
18314 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18317 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
18320 int field_width
, precision
;
18324 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18325 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18326 struct buffer
*b
= current_buffer
;
18334 if (!NILP (b
->read_only
))
18336 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18341 /* This differs from %* only for a modified read-only buffer. */
18342 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18344 if (!NILP (b
->read_only
))
18349 /* This differs from %* in ignoring read-only-ness. */
18350 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18362 if (command_loop_level
> 5)
18364 p
= decode_mode_spec_buf
;
18365 for (i
= 0; i
< command_loop_level
; i
++)
18368 return decode_mode_spec_buf
;
18376 if (command_loop_level
> 5)
18378 p
= decode_mode_spec_buf
;
18379 for (i
= 0; i
< command_loop_level
; i
++)
18382 return decode_mode_spec_buf
;
18389 /* Let lots_of_dashes be a string of infinite length. */
18390 if (mode_line_target
== MODE_LINE_NOPROP
||
18391 mode_line_target
== MODE_LINE_STRING
)
18393 if (field_width
<= 0
18394 || field_width
> sizeof (lots_of_dashes
))
18396 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18397 decode_mode_spec_buf
[i
] = '-';
18398 decode_mode_spec_buf
[i
] = '\0';
18399 return decode_mode_spec_buf
;
18402 return lots_of_dashes
;
18410 /* %c and %l are ignored in `frame-title-format'.
18411 (In redisplay_internal, the frame title is drawn _before_ the
18412 windows are updated, so the stuff which depends on actual
18413 window contents (such as %l) may fail to render properly, or
18414 even crash emacs.) */
18415 if (mode_line_target
== MODE_LINE_TITLE
)
18419 int col
= (int) current_column (); /* iftc */
18420 w
->column_number_displayed
= make_number (col
);
18421 pint2str (decode_mode_spec_buf
, field_width
, col
);
18422 return decode_mode_spec_buf
;
18426 #ifndef SYSTEM_MALLOC
18428 if (NILP (Vmemory_full
))
18431 return "!MEM FULL! ";
18438 /* %F displays the frame name. */
18439 if (!NILP (f
->title
))
18440 return (char *) SDATA (f
->title
);
18441 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18442 return (char *) SDATA (f
->name
);
18451 int size
= ZV
- BEGV
;
18452 pint2str (decode_mode_spec_buf
, field_width
, size
);
18453 return decode_mode_spec_buf
;
18458 int size
= ZV
- BEGV
;
18459 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18460 return decode_mode_spec_buf
;
18465 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18466 int topline
, nlines
, junk
, height
;
18468 /* %c and %l are ignored in `frame-title-format'. */
18469 if (mode_line_target
== MODE_LINE_TITLE
)
18472 startpos
= XMARKER (w
->start
)->charpos
;
18473 startpos_byte
= marker_byte_position (w
->start
);
18474 height
= WINDOW_TOTAL_LINES (w
);
18476 /* If we decided that this buffer isn't suitable for line numbers,
18477 don't forget that too fast. */
18478 if (EQ (w
->base_line_pos
, w
->buffer
))
18480 /* But do forget it, if the window shows a different buffer now. */
18481 else if (BUFFERP (w
->base_line_pos
))
18482 w
->base_line_pos
= Qnil
;
18484 /* If the buffer is very big, don't waste time. */
18485 if (INTEGERP (Vline_number_display_limit
)
18486 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18488 w
->base_line_pos
= Qnil
;
18489 w
->base_line_number
= Qnil
;
18493 if (INTEGERP (w
->base_line_number
)
18494 && INTEGERP (w
->base_line_pos
)
18495 && XFASTINT (w
->base_line_pos
) <= startpos
)
18497 line
= XFASTINT (w
->base_line_number
);
18498 linepos
= XFASTINT (w
->base_line_pos
);
18499 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18504 linepos
= BUF_BEGV (b
);
18505 linepos_byte
= BUF_BEGV_BYTE (b
);
18508 /* Count lines from base line to window start position. */
18509 nlines
= display_count_lines (linepos
, linepos_byte
,
18513 topline
= nlines
+ line
;
18515 /* Determine a new base line, if the old one is too close
18516 or too far away, or if we did not have one.
18517 "Too close" means it's plausible a scroll-down would
18518 go back past it. */
18519 if (startpos
== BUF_BEGV (b
))
18521 w
->base_line_number
= make_number (topline
);
18522 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18524 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18525 || linepos
== BUF_BEGV (b
))
18527 int limit
= BUF_BEGV (b
);
18528 int limit_byte
= BUF_BEGV_BYTE (b
);
18530 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18532 if (startpos
- distance
> limit
)
18534 limit
= startpos
- distance
;
18535 limit_byte
= CHAR_TO_BYTE (limit
);
18538 nlines
= display_count_lines (startpos
, startpos_byte
,
18540 - (height
* 2 + 30),
18542 /* If we couldn't find the lines we wanted within
18543 line_number_display_limit_width chars per line,
18544 give up on line numbers for this window. */
18545 if (position
== limit_byte
&& limit
== startpos
- distance
)
18547 w
->base_line_pos
= w
->buffer
;
18548 w
->base_line_number
= Qnil
;
18552 w
->base_line_number
= make_number (topline
- nlines
);
18553 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18556 /* Now count lines from the start pos to point. */
18557 nlines
= display_count_lines (startpos
, startpos_byte
,
18558 PT_BYTE
, PT
, &junk
);
18560 /* Record that we did display the line number. */
18561 line_number_displayed
= 1;
18563 /* Make the string to show. */
18564 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18565 return decode_mode_spec_buf
;
18568 char* p
= decode_mode_spec_buf
;
18569 int pad
= field_width
- 2;
18575 return decode_mode_spec_buf
;
18581 obj
= b
->mode_name
;
18585 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18591 int pos
= marker_position (w
->start
);
18592 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18594 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18596 if (pos
<= BUF_BEGV (b
))
18601 else if (pos
<= BUF_BEGV (b
))
18605 if (total
> 1000000)
18606 /* Do it differently for a large value, to avoid overflow. */
18607 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18609 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18610 /* We can't normally display a 3-digit number,
18611 so get us a 2-digit number that is close. */
18614 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18615 return decode_mode_spec_buf
;
18619 /* Display percentage of size above the bottom of the screen. */
18622 int toppos
= marker_position (w
->start
);
18623 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18624 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18626 if (botpos
>= BUF_ZV (b
))
18628 if (toppos
<= BUF_BEGV (b
))
18635 if (total
> 1000000)
18636 /* Do it differently for a large value, to avoid overflow. */
18637 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18639 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18640 /* We can't normally display a 3-digit number,
18641 so get us a 2-digit number that is close. */
18644 if (toppos
<= BUF_BEGV (b
))
18645 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18647 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18648 return decode_mode_spec_buf
;
18653 /* status of process */
18654 obj
= Fget_buffer_process (Fcurrent_buffer ());
18656 return "no process";
18657 #ifdef subprocesses
18658 obj
= Fsymbol_name (Fprocess_status (obj
));
18665 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18672 case 't': /* indicate TEXT or BINARY */
18673 #ifdef MODE_LINE_BINARY_TEXT
18674 return MODE_LINE_BINARY_TEXT (b
);
18680 /* coding-system (not including end-of-line format) */
18682 /* coding-system (including end-of-line type) */
18684 int eol_flag
= (c
== 'Z');
18685 char *p
= decode_mode_spec_buf
;
18687 if (! FRAME_WINDOW_P (f
))
18689 /* No need to mention EOL here--the terminal never needs
18690 to do EOL conversion. */
18691 p
= decode_mode_spec_coding (CODING_ID_NAME
18692 (FRAME_KEYBOARD_CODING (f
)->id
),
18694 p
= decode_mode_spec_coding (CODING_ID_NAME
18695 (FRAME_TERMINAL_CODING (f
)->id
),
18698 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18701 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18702 #ifdef subprocesses
18703 obj
= Fget_buffer_process (Fcurrent_buffer ());
18704 if (PROCESSP (obj
))
18706 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18708 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18711 #endif /* subprocesses */
18714 return decode_mode_spec_buf
;
18720 *multibyte
= STRING_MULTIBYTE (obj
);
18721 return (char *) SDATA (obj
);
18728 /* Count up to COUNT lines starting from START / START_BYTE.
18729 But don't go beyond LIMIT_BYTE.
18730 Return the number of lines thus found (always nonnegative).
18732 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18735 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18736 int start
, start_byte
, limit_byte
, count
;
18739 register unsigned char *cursor
;
18740 unsigned char *base
;
18742 register int ceiling
;
18743 register unsigned char *ceiling_addr
;
18744 int orig_count
= count
;
18746 /* If we are not in selective display mode,
18747 check only for newlines. */
18748 int selective_display
= (!NILP (current_buffer
->selective_display
)
18749 && !INTEGERP (current_buffer
->selective_display
));
18753 while (start_byte
< limit_byte
)
18755 ceiling
= BUFFER_CEILING_OF (start_byte
);
18756 ceiling
= min (limit_byte
- 1, ceiling
);
18757 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18758 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18761 if (selective_display
)
18762 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18765 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18768 if (cursor
!= ceiling_addr
)
18772 start_byte
+= cursor
- base
+ 1;
18773 *byte_pos_ptr
= start_byte
;
18777 if (++cursor
== ceiling_addr
)
18783 start_byte
+= cursor
- base
;
18788 while (start_byte
> limit_byte
)
18790 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18791 ceiling
= max (limit_byte
, ceiling
);
18792 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18793 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18796 if (selective_display
)
18797 while (--cursor
!= ceiling_addr
18798 && *cursor
!= '\n' && *cursor
!= 015)
18801 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18804 if (cursor
!= ceiling_addr
)
18808 start_byte
+= cursor
- base
+ 1;
18809 *byte_pos_ptr
= start_byte
;
18810 /* When scanning backwards, we should
18811 not count the newline posterior to which we stop. */
18812 return - orig_count
- 1;
18818 /* Here we add 1 to compensate for the last decrement
18819 of CURSOR, which took it past the valid range. */
18820 start_byte
+= cursor
- base
+ 1;
18824 *byte_pos_ptr
= limit_byte
;
18827 return - orig_count
+ count
;
18828 return orig_count
- count
;
18834 /***********************************************************************
18836 ***********************************************************************/
18838 /* Display a NUL-terminated string, starting with index START.
18840 If STRING is non-null, display that C string. Otherwise, the Lisp
18841 string LISP_STRING is displayed.
18843 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18844 FACE_STRING. Display STRING or LISP_STRING with the face at
18845 FACE_STRING_POS in FACE_STRING:
18847 Display the string in the environment given by IT, but use the
18848 standard display table, temporarily.
18850 FIELD_WIDTH is the minimum number of output glyphs to produce.
18851 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18852 with spaces. If STRING has more characters, more than FIELD_WIDTH
18853 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18855 PRECISION is the maximum number of characters to output from
18856 STRING. PRECISION < 0 means don't truncate the string.
18858 This is roughly equivalent to printf format specifiers:
18860 FIELD_WIDTH PRECISION PRINTF
18861 ----------------------------------------
18867 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18868 display them, and < 0 means obey the current buffer's value of
18869 enable_multibyte_characters.
18871 Value is the number of columns displayed. */
18874 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18875 start
, it
, field_width
, precision
, max_x
, multibyte
)
18876 unsigned char *string
;
18877 Lisp_Object lisp_string
;
18878 Lisp_Object face_string
;
18879 EMACS_INT face_string_pos
;
18882 int field_width
, precision
, max_x
;
18885 int hpos_at_start
= it
->hpos
;
18886 int saved_face_id
= it
->face_id
;
18887 struct glyph_row
*row
= it
->glyph_row
;
18889 /* Initialize the iterator IT for iteration over STRING beginning
18890 with index START. */
18891 reseat_to_string (it
, string
, lisp_string
, start
,
18892 precision
, field_width
, multibyte
);
18894 /* If displaying STRING, set up the face of the iterator
18895 from LISP_STRING, if that's given. */
18896 if (STRINGP (face_string
))
18902 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18903 0, it
->region_beg_charpos
,
18904 it
->region_end_charpos
,
18905 &endptr
, it
->base_face_id
, 0);
18906 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18907 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18910 /* Set max_x to the maximum allowed X position. Don't let it go
18911 beyond the right edge of the window. */
18913 max_x
= it
->last_visible_x
;
18915 max_x
= min (max_x
, it
->last_visible_x
);
18917 /* Skip over display elements that are not visible. because IT->w is
18919 if (it
->current_x
< it
->first_visible_x
)
18920 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18921 MOVE_TO_POS
| MOVE_TO_X
);
18923 row
->ascent
= it
->max_ascent
;
18924 row
->height
= it
->max_ascent
+ it
->max_descent
;
18925 row
->phys_ascent
= it
->max_phys_ascent
;
18926 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18927 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18929 /* This condition is for the case that we are called with current_x
18930 past last_visible_x. */
18931 while (it
->current_x
< max_x
)
18933 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18935 /* Get the next display element. */
18936 if (!get_next_display_element (it
))
18939 /* Produce glyphs. */
18940 x_before
= it
->current_x
;
18941 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18942 PRODUCE_GLYPHS (it
);
18944 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18947 while (i
< nglyphs
)
18949 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18951 if (it
->line_wrap
!= TRUNCATE
18952 && x
+ glyph
->pixel_width
> max_x
)
18954 /* End of continued line or max_x reached. */
18955 if (CHAR_GLYPH_PADDING_P (*glyph
))
18957 /* A wide character is unbreakable. */
18958 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18959 it
->current_x
= x_before
;
18963 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18968 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18970 /* Glyph is at least partially visible. */
18972 if (x
< it
->first_visible_x
)
18973 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18977 /* Glyph is off the left margin of the display area.
18978 Should not happen. */
18982 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18983 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18984 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18985 row
->phys_height
= max (row
->phys_height
,
18986 it
->max_phys_ascent
+ it
->max_phys_descent
);
18987 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18988 it
->max_extra_line_spacing
);
18989 x
+= glyph
->pixel_width
;
18993 /* Stop if max_x reached. */
18997 /* Stop at line ends. */
18998 if (ITERATOR_AT_END_OF_LINE_P (it
))
19000 it
->continuation_lines_width
= 0;
19004 set_iterator_to_next (it
, 1);
19006 /* Stop if truncating at the right edge. */
19007 if (it
->line_wrap
== TRUNCATE
19008 && it
->current_x
>= it
->last_visible_x
)
19010 /* Add truncation mark, but don't do it if the line is
19011 truncated at a padding space. */
19012 if (IT_CHARPOS (*it
) < it
->string_nchars
)
19014 if (!FRAME_WINDOW_P (it
->f
))
19018 if (it
->current_x
> it
->last_visible_x
)
19020 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19021 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19023 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19025 row
->used
[TEXT_AREA
] = i
;
19026 produce_special_glyphs (it
, IT_TRUNCATION
);
19029 produce_special_glyphs (it
, IT_TRUNCATION
);
19031 it
->glyph_row
->truncated_on_right_p
= 1;
19037 /* Maybe insert a truncation at the left. */
19038 if (it
->first_visible_x
19039 && IT_CHARPOS (*it
) > 0)
19041 if (!FRAME_WINDOW_P (it
->f
))
19042 insert_left_trunc_glyphs (it
);
19043 it
->glyph_row
->truncated_on_left_p
= 1;
19046 it
->face_id
= saved_face_id
;
19048 /* Value is number of columns displayed. */
19049 return it
->hpos
- hpos_at_start
;
19054 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19055 appears as an element of LIST or as the car of an element of LIST.
19056 If PROPVAL is a list, compare each element against LIST in that
19057 way, and return 1/2 if any element of PROPVAL is found in LIST.
19058 Otherwise return 0. This function cannot quit.
19059 The return value is 2 if the text is invisible but with an ellipsis
19060 and 1 if it's invisible and without an ellipsis. */
19063 invisible_p (propval
, list
)
19064 register Lisp_Object propval
;
19067 register Lisp_Object tail
, proptail
;
19069 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19071 register Lisp_Object tem
;
19073 if (EQ (propval
, tem
))
19075 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19076 return NILP (XCDR (tem
)) ? 1 : 2;
19079 if (CONSP (propval
))
19081 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19083 Lisp_Object propelt
;
19084 propelt
= XCAR (proptail
);
19085 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19087 register Lisp_Object tem
;
19089 if (EQ (propelt
, tem
))
19091 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19092 return NILP (XCDR (tem
)) ? 1 : 2;
19100 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19101 doc
: /* Non-nil if the property makes the text invisible.
19102 POS-OR-PROP can be a marker or number, in which case it is taken to be
19103 a position in the current buffer and the value of the `invisible' property
19104 is checked; or it can be some other value, which is then presumed to be the
19105 value of the `invisible' property of the text of interest.
19106 The non-nil value returned can be t for truly invisible text or something
19107 else if the text is replaced by an ellipsis. */)
19109 Lisp_Object pos_or_prop
;
19112 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19113 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19115 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19116 return (invis
== 0 ? Qnil
19118 : make_number (invis
));
19121 /* Calculate a width or height in pixels from a specification using
19122 the following elements:
19125 NUM - a (fractional) multiple of the default font width/height
19126 (NUM) - specifies exactly NUM pixels
19127 UNIT - a fixed number of pixels, see below.
19128 ELEMENT - size of a display element in pixels, see below.
19129 (NUM . SPEC) - equals NUM * SPEC
19130 (+ SPEC SPEC ...) - add pixel values
19131 (- SPEC SPEC ...) - subtract pixel values
19132 (- SPEC) - negate pixel value
19135 INT or FLOAT - a number constant
19136 SYMBOL - use symbol's (buffer local) variable binding.
19139 in - pixels per inch *)
19140 mm - pixels per 1/1000 meter *)
19141 cm - pixels per 1/100 meter *)
19142 width - width of current font in pixels.
19143 height - height of current font in pixels.
19145 *) using the ratio(s) defined in display-pixels-per-inch.
19149 left-fringe - left fringe width in pixels
19150 right-fringe - right fringe width in pixels
19152 left-margin - left margin width in pixels
19153 right-margin - right margin width in pixels
19155 scroll-bar - scroll-bar area width in pixels
19159 Pixels corresponding to 5 inches:
19162 Total width of non-text areas on left side of window (if scroll-bar is on left):
19163 '(space :width (+ left-fringe left-margin scroll-bar))
19165 Align to first text column (in header line):
19166 '(space :align-to 0)
19168 Align to middle of text area minus half the width of variable `my-image'
19169 containing a loaded image:
19170 '(space :align-to (0.5 . (- text my-image)))
19172 Width of left margin minus width of 1 character in the default font:
19173 '(space :width (- left-margin 1))
19175 Width of left margin minus width of 2 characters in the current font:
19176 '(space :width (- left-margin (2 . width)))
19178 Center 1 character over left-margin (in header line):
19179 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19181 Different ways to express width of left fringe plus left margin minus one pixel:
19182 '(space :width (- (+ left-fringe left-margin) (1)))
19183 '(space :width (+ left-fringe left-margin (- (1))))
19184 '(space :width (+ left-fringe left-margin (-1)))
19188 #define NUMVAL(X) \
19189 ((INTEGERP (X) || FLOATP (X)) \
19194 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19199 int width_p
, *align_to
;
19203 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19204 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19207 return OK_PIXELS (0);
19209 xassert (FRAME_LIVE_P (it
->f
));
19211 if (SYMBOLP (prop
))
19213 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19215 char *unit
= SDATA (SYMBOL_NAME (prop
));
19217 if (unit
[0] == 'i' && unit
[1] == 'n')
19219 else if (unit
[0] == 'm' && unit
[1] == 'm')
19221 else if (unit
[0] == 'c' && unit
[1] == 'm')
19228 #ifdef HAVE_WINDOW_SYSTEM
19229 if (FRAME_WINDOW_P (it
->f
)
19231 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19232 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19234 return OK_PIXELS (ppi
/ pixels
);
19237 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19238 || (CONSP (Vdisplay_pixels_per_inch
)
19240 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19241 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19243 return OK_PIXELS (ppi
/ pixels
);
19249 #ifdef HAVE_WINDOW_SYSTEM
19250 if (EQ (prop
, Qheight
))
19251 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19252 if (EQ (prop
, Qwidth
))
19253 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19255 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19256 return OK_PIXELS (1);
19259 if (EQ (prop
, Qtext
))
19260 return OK_PIXELS (width_p
19261 ? window_box_width (it
->w
, TEXT_AREA
)
19262 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19264 if (align_to
&& *align_to
< 0)
19267 if (EQ (prop
, Qleft
))
19268 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19269 if (EQ (prop
, Qright
))
19270 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19271 if (EQ (prop
, Qcenter
))
19272 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19273 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19274 if (EQ (prop
, Qleft_fringe
))
19275 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19276 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19277 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19278 if (EQ (prop
, Qright_fringe
))
19279 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19280 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19281 : window_box_right_offset (it
->w
, TEXT_AREA
));
19282 if (EQ (prop
, Qleft_margin
))
19283 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19284 if (EQ (prop
, Qright_margin
))
19285 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19286 if (EQ (prop
, Qscroll_bar
))
19287 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19289 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19290 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19291 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19296 if (EQ (prop
, Qleft_fringe
))
19297 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19298 if (EQ (prop
, Qright_fringe
))
19299 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19300 if (EQ (prop
, Qleft_margin
))
19301 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19302 if (EQ (prop
, Qright_margin
))
19303 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19304 if (EQ (prop
, Qscroll_bar
))
19305 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19308 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19311 if (INTEGERP (prop
) || FLOATP (prop
))
19313 int base_unit
= (width_p
19314 ? FRAME_COLUMN_WIDTH (it
->f
)
19315 : FRAME_LINE_HEIGHT (it
->f
));
19316 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19321 Lisp_Object car
= XCAR (prop
);
19322 Lisp_Object cdr
= XCDR (prop
);
19326 #ifdef HAVE_WINDOW_SYSTEM
19327 if (FRAME_WINDOW_P (it
->f
)
19328 && valid_image_p (prop
))
19330 int id
= lookup_image (it
->f
, prop
);
19331 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19333 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19336 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19342 while (CONSP (cdr
))
19344 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19345 font
, width_p
, align_to
))
19348 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19353 if (EQ (car
, Qminus
))
19355 return OK_PIXELS (pixels
);
19358 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19361 if (INTEGERP (car
) || FLOATP (car
))
19364 pixels
= XFLOATINT (car
);
19366 return OK_PIXELS (pixels
);
19367 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19368 font
, width_p
, align_to
))
19369 return OK_PIXELS (pixels
* fact
);
19380 /***********************************************************************
19382 ***********************************************************************/
19384 #ifdef HAVE_WINDOW_SYSTEM
19389 dump_glyph_string (s
)
19390 struct glyph_string
*s
;
19392 fprintf (stderr
, "glyph string\n");
19393 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19394 s
->x
, s
->y
, s
->width
, s
->height
);
19395 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19396 fprintf (stderr
, " hl = %d\n", s
->hl
);
19397 fprintf (stderr
, " left overhang = %d, right = %d\n",
19398 s
->left_overhang
, s
->right_overhang
);
19399 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19400 fprintf (stderr
, " extends to end of line = %d\n",
19401 s
->extends_to_end_of_line_p
);
19402 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19403 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19406 #endif /* GLYPH_DEBUG */
19408 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19409 of XChar2b structures for S; it can't be allocated in
19410 init_glyph_string because it must be allocated via `alloca'. W
19411 is the window on which S is drawn. ROW and AREA are the glyph row
19412 and area within the row from which S is constructed. START is the
19413 index of the first glyph structure covered by S. HL is a
19414 face-override for drawing S. */
19417 #define OPTIONAL_HDC(hdc) hdc,
19418 #define DECLARE_HDC(hdc) HDC hdc;
19419 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19420 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19423 #ifndef OPTIONAL_HDC
19424 #define OPTIONAL_HDC(hdc)
19425 #define DECLARE_HDC(hdc)
19426 #define ALLOCATE_HDC(hdc, f)
19427 #define RELEASE_HDC(hdc, f)
19431 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19432 struct glyph_string
*s
;
19436 struct glyph_row
*row
;
19437 enum glyph_row_area area
;
19439 enum draw_glyphs_face hl
;
19441 bzero (s
, sizeof *s
);
19443 s
->f
= XFRAME (w
->frame
);
19447 s
->display
= FRAME_X_DISPLAY (s
->f
);
19448 s
->window
= FRAME_X_WINDOW (s
->f
);
19449 s
->char2b
= char2b
;
19453 s
->first_glyph
= row
->glyphs
[area
] + start
;
19454 s
->height
= row
->height
;
19455 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19457 /* Display the internal border below the tool-bar window. */
19458 if (WINDOWP (s
->f
->tool_bar_window
)
19459 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19460 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19462 s
->ybase
= s
->y
+ row
->ascent
;
19466 /* Append the list of glyph strings with head H and tail T to the list
19467 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19470 append_glyph_string_lists (head
, tail
, h
, t
)
19471 struct glyph_string
**head
, **tail
;
19472 struct glyph_string
*h
, *t
;
19486 /* Prepend the list of glyph strings with head H and tail T to the
19487 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19491 prepend_glyph_string_lists (head
, tail
, h
, t
)
19492 struct glyph_string
**head
, **tail
;
19493 struct glyph_string
*h
, *t
;
19507 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19508 Set *HEAD and *TAIL to the resulting list. */
19511 append_glyph_string (head
, tail
, s
)
19512 struct glyph_string
**head
, **tail
;
19513 struct glyph_string
*s
;
19515 s
->next
= s
->prev
= NULL
;
19516 append_glyph_string_lists (head
, tail
, s
, s
);
19520 /* Get face and two-byte form of character C in face FACE_ID on frame
19521 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19522 means we want to display multibyte text. DISPLAY_P non-zero means
19523 make sure that X resources for the face returned are allocated.
19524 Value is a pointer to a realized face that is ready for display if
19525 DISPLAY_P is non-zero. */
19527 static INLINE
struct face
*
19528 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19532 int multibyte_p
, display_p
;
19534 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19538 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19540 if (code
!= FONT_INVALID_CODE
)
19541 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19543 STORE_XCHAR2B (char2b
, 0, 0);
19546 /* Make sure X resources of the face are allocated. */
19547 #ifdef HAVE_X_WINDOWS
19551 xassert (face
!= NULL
);
19552 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19559 /* Get face and two-byte form of character glyph GLYPH on frame F.
19560 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19561 a pointer to a realized face that is ready for display. */
19563 static INLINE
struct face
*
19564 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19566 struct glyph
*glyph
;
19572 xassert (glyph
->type
== CHAR_GLYPH
);
19573 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19580 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19582 if (code
!= FONT_INVALID_CODE
)
19583 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19585 STORE_XCHAR2B (char2b
, 0, 0);
19588 /* Make sure X resources of the face are allocated. */
19589 xassert (face
!= NULL
);
19590 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19595 /* Fill glyph string S with composition components specified by S->cmp.
19597 BASE_FACE is the base face of the composition.
19598 S->gidx is the index of the first component for S.
19600 OVERLAPS non-zero means S should draw the foreground only, and use
19601 its physical height for clipping. See also draw_glyphs.
19603 Value is the index of a component not in S. */
19606 fill_composite_glyph_string (s
, base_face
, overlaps
)
19607 struct glyph_string
*s
;
19608 struct face
*base_face
;
19615 s
->for_overlaps
= overlaps
;
19617 if (s
->cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
19619 Lisp_Object gstring
19620 = AREF (XHASH_TABLE (composition_hash_table
)->key_and_value
,
19621 s
->cmp
->hash_index
* 2);
19623 s
->face
= base_face
;
19624 s
->font
= base_face
->font
;
19625 for (i
= 0, s
->nchars
= 0; i
< s
->cmp
->glyph_len
; i
++, s
->nchars
++)
19627 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
19629 XChar2b
* store_pos
;
19632 code
= LGLYPH_CODE (g
);
19633 store_pos
= s
->char2b
+ i
;
19634 STORE_XCHAR2B (store_pos
, code
>> 8, code
& 0xFF);
19636 s
->width
= s
->cmp
->pixel_width
;
19640 /* For all glyphs of this composition, starting at the offset
19641 S->gidx, until we reach the end of the definition or encounter a
19642 glyph that requires the different face, add it to S. */
19647 for (i
= s
->gidx
; i
< s
->cmp
->glyph_len
; i
++)
19649 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19653 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19656 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19657 s
->char2b
+ i
, 1, 1);
19663 s
->font
= s
->face
->font
;
19665 else if (s
->face
!= face
)
19672 /* All glyph strings for the same composition has the same width,
19673 i.e. the width set for the first component of the composition. */
19674 s
->width
= s
->first_glyph
->pixel_width
;
19677 /* If the specified font could not be loaded, use the frame's
19678 default font, but record the fact that we couldn't load it in
19679 the glyph string so that we can draw rectangles for the
19680 characters of the glyph string. */
19681 if (s
->font
== NULL
)
19683 s
->font_not_found_p
= 1;
19684 s
->font
= FRAME_FONT (s
->f
);
19687 /* Adjust base line for subscript/superscript text. */
19688 s
->ybase
+= s
->first_glyph
->voffset
;
19690 /* This glyph string must always be drawn with 16-bit functions. */
19693 return s
->gidx
+ s
->nchars
;
19697 /* Fill glyph string S from a sequence of character glyphs.
19699 FACE_ID is the face id of the string. START is the index of the
19700 first glyph to consider, END is the index of the last + 1.
19701 OVERLAPS non-zero means S should draw the foreground only, and use
19702 its physical height for clipping. See also draw_glyphs.
19704 Value is the index of the first glyph not in S. */
19707 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19708 struct glyph_string
*s
;
19710 int start
, end
, overlaps
;
19712 struct glyph
*glyph
, *last
;
19714 int glyph_not_available_p
;
19716 xassert (s
->f
== XFRAME (s
->w
->frame
));
19717 xassert (s
->nchars
== 0);
19718 xassert (start
>= 0 && end
> start
);
19720 s
->for_overlaps
= overlaps
,
19721 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19722 last
= s
->row
->glyphs
[s
->area
] + end
;
19723 voffset
= glyph
->voffset
;
19724 s
->padding_p
= glyph
->padding_p
;
19725 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19727 while (glyph
< last
19728 && glyph
->type
== CHAR_GLYPH
19729 && glyph
->voffset
== voffset
19730 /* Same face id implies same font, nowadays. */
19731 && glyph
->face_id
== face_id
19732 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19736 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19737 s
->char2b
+ s
->nchars
,
19739 s
->two_byte_p
= two_byte_p
;
19741 xassert (s
->nchars
<= end
- start
);
19742 s
->width
+= glyph
->pixel_width
;
19743 if (glyph
++->padding_p
!= s
->padding_p
)
19747 s
->font
= s
->face
->font
;
19749 /* If the specified font could not be loaded, use the frame's font,
19750 but record the fact that we couldn't load it in
19751 S->font_not_found_p so that we can draw rectangles for the
19752 characters of the glyph string. */
19753 if (s
->font
== NULL
|| glyph_not_available_p
)
19755 s
->font_not_found_p
= 1;
19756 s
->font
= FRAME_FONT (s
->f
);
19759 /* Adjust base line for subscript/superscript text. */
19760 s
->ybase
+= voffset
;
19762 xassert (s
->face
&& s
->face
->gc
);
19763 return glyph
- s
->row
->glyphs
[s
->area
];
19767 /* Fill glyph string S from image glyph S->first_glyph. */
19770 fill_image_glyph_string (s
)
19771 struct glyph_string
*s
;
19773 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19774 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19776 s
->slice
= s
->first_glyph
->slice
;
19777 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19778 s
->font
= s
->face
->font
;
19779 s
->width
= s
->first_glyph
->pixel_width
;
19781 /* Adjust base line for subscript/superscript text. */
19782 s
->ybase
+= s
->first_glyph
->voffset
;
19786 /* Fill glyph string S from a sequence of stretch glyphs.
19788 ROW is the glyph row in which the glyphs are found, AREA is the
19789 area within the row. START is the index of the first glyph to
19790 consider, END is the index of the last + 1.
19792 Value is the index of the first glyph not in S. */
19795 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19796 struct glyph_string
*s
;
19797 struct glyph_row
*row
;
19798 enum glyph_row_area area
;
19801 struct glyph
*glyph
, *last
;
19802 int voffset
, face_id
;
19804 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19806 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19807 last
= s
->row
->glyphs
[s
->area
] + end
;
19808 face_id
= glyph
->face_id
;
19809 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19810 s
->font
= s
->face
->font
;
19811 s
->width
= glyph
->pixel_width
;
19813 voffset
= glyph
->voffset
;
19817 && glyph
->type
== STRETCH_GLYPH
19818 && glyph
->voffset
== voffset
19819 && glyph
->face_id
== face_id
);
19821 s
->width
+= glyph
->pixel_width
;
19823 /* Adjust base line for subscript/superscript text. */
19824 s
->ybase
+= voffset
;
19826 /* The case that face->gc == 0 is handled when drawing the glyph
19827 string by calling PREPARE_FACE_FOR_DISPLAY. */
19829 return glyph
- s
->row
->glyphs
[s
->area
];
19832 static struct font_metrics
*
19833 get_per_char_metric (f
, font
, char2b
)
19838 static struct font_metrics metrics
;
19839 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19840 struct font
*fontp
;
19842 if (! font
|| code
== FONT_INVALID_CODE
)
19844 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19849 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19850 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19851 assumed to be zero. */
19854 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19855 struct glyph
*glyph
;
19859 *left
= *right
= 0;
19861 if (glyph
->type
== CHAR_GLYPH
)
19865 struct font_metrics
*pcm
;
19867 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19868 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19870 if (pcm
->rbearing
> pcm
->width
)
19871 *right
= pcm
->rbearing
- pcm
->width
;
19872 if (pcm
->lbearing
< 0)
19873 *left
= -pcm
->lbearing
;
19876 else if (glyph
->type
== COMPOSITE_GLYPH
)
19878 struct composition
*cmp
= composition_table
[glyph
->u
.cmp_id
];
19880 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19881 *left
= - cmp
->lbearing
;
19886 /* Return the index of the first glyph preceding glyph string S that
19887 is overwritten by S because of S's left overhang. Value is -1
19888 if no glyphs are overwritten. */
19891 left_overwritten (s
)
19892 struct glyph_string
*s
;
19896 if (s
->left_overhang
)
19899 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19900 int first
= s
->first_glyph
- glyphs
;
19902 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19903 x
-= glyphs
[i
].pixel_width
;
19914 /* Return the index of the first glyph preceding glyph string S that
19915 is overwriting S because of its right overhang. Value is -1 if no
19916 glyph in front of S overwrites S. */
19919 left_overwriting (s
)
19920 struct glyph_string
*s
;
19923 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19924 int first
= s
->first_glyph
- glyphs
;
19928 for (i
= first
- 1; i
>= 0; --i
)
19931 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19934 x
-= glyphs
[i
].pixel_width
;
19941 /* Return the index of the last glyph following glyph string S that is
19942 overwritten by S because of S's right overhang. Value is -1 if
19943 no such glyph is found. */
19946 right_overwritten (s
)
19947 struct glyph_string
*s
;
19951 if (s
->right_overhang
)
19954 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19955 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19956 int end
= s
->row
->used
[s
->area
];
19958 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19959 x
+= glyphs
[i
].pixel_width
;
19968 /* Return the index of the last glyph following glyph string S that
19969 overwrites S because of its left overhang. Value is negative
19970 if no such glyph is found. */
19973 right_overwriting (s
)
19974 struct glyph_string
*s
;
19977 int end
= s
->row
->used
[s
->area
];
19978 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19979 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19983 for (i
= first
; i
< end
; ++i
)
19986 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19989 x
+= glyphs
[i
].pixel_width
;
19996 /* Set background width of glyph string S. START is the index of the
19997 first glyph following S. LAST_X is the right-most x-position + 1
19998 in the drawing area. */
20001 set_glyph_string_background_width (s
, start
, last_x
)
20002 struct glyph_string
*s
;
20006 /* If the face of this glyph string has to be drawn to the end of
20007 the drawing area, set S->extends_to_end_of_line_p. */
20009 if (start
== s
->row
->used
[s
->area
]
20010 && s
->area
== TEXT_AREA
20011 && ((s
->row
->fill_line_p
20012 && (s
->hl
== DRAW_NORMAL_TEXT
20013 || s
->hl
== DRAW_IMAGE_RAISED
20014 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20015 || s
->hl
== DRAW_MOUSE_FACE
))
20016 s
->extends_to_end_of_line_p
= 1;
20018 /* If S extends its face to the end of the line, set its
20019 background_width to the distance to the right edge of the drawing
20021 if (s
->extends_to_end_of_line_p
)
20022 s
->background_width
= last_x
- s
->x
+ 1;
20024 s
->background_width
= s
->width
;
20028 /* Compute overhangs and x-positions for glyph string S and its
20029 predecessors, or successors. X is the starting x-position for S.
20030 BACKWARD_P non-zero means process predecessors. */
20033 compute_overhangs_and_x (s
, x
, backward_p
)
20034 struct glyph_string
*s
;
20042 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20043 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20053 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20054 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20064 /* The following macros are only called from draw_glyphs below.
20065 They reference the following parameters of that function directly:
20066 `w', `row', `area', and `overlap_p'
20067 as well as the following local variables:
20068 `s', `f', and `hdc' (in W32) */
20071 /* On W32, silently add local `hdc' variable to argument list of
20072 init_glyph_string. */
20073 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20074 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20076 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20077 init_glyph_string (s, char2b, w, row, area, start, hl)
20080 /* Add a glyph string for a stretch glyph to the list of strings
20081 between HEAD and TAIL. START is the index of the stretch glyph in
20082 row area AREA of glyph row ROW. END is the index of the last glyph
20083 in that glyph row area. X is the current output position assigned
20084 to the new glyph string constructed. HL overrides that face of the
20085 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20086 is the right-most x-position of the drawing area. */
20088 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20089 and below -- keep them on one line. */
20090 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20093 s = (struct glyph_string *) alloca (sizeof *s); \
20094 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20095 START = fill_stretch_glyph_string (s, row, area, START, END); \
20096 append_glyph_string (&HEAD, &TAIL, s); \
20102 /* Add a glyph string for an image glyph to the list of strings
20103 between HEAD and TAIL. START is the index of the image glyph in
20104 row area AREA of glyph row ROW. END is the index of the last glyph
20105 in that glyph row area. X is the current output position assigned
20106 to the new glyph string constructed. HL overrides that face of the
20107 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20108 is the right-most x-position of the drawing area. */
20110 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20113 s = (struct glyph_string *) alloca (sizeof *s); \
20114 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20115 fill_image_glyph_string (s); \
20116 append_glyph_string (&HEAD, &TAIL, s); \
20123 /* Add a glyph string for a sequence of character glyphs to the list
20124 of strings between HEAD and TAIL. START is the index of the first
20125 glyph in row area AREA of glyph row ROW that is part of the new
20126 glyph string. END is the index of the last glyph in that glyph row
20127 area. X is the current output position assigned to the new glyph
20128 string constructed. HL overrides that face of the glyph; e.g. it
20129 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20130 right-most x-position of the drawing area. */
20132 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20138 face_id = (row)->glyphs[area][START].face_id; \
20140 s = (struct glyph_string *) alloca (sizeof *s); \
20141 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20142 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20143 append_glyph_string (&HEAD, &TAIL, s); \
20145 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20150 /* Add a glyph string for a composite sequence to the list of strings
20151 between HEAD and TAIL. START is the index of the first glyph in
20152 row area AREA of glyph row ROW that is part of the new glyph
20153 string. END is the index of the last glyph in that glyph row area.
20154 X is the current output position assigned to the new glyph string
20155 constructed. HL overrides that face of the glyph; e.g. it is
20156 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20157 x-position of the drawing area. */
20159 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20161 int face_id = (row)->glyphs[area][START].face_id; \
20162 struct face *base_face = FACE_FROM_ID (f, face_id); \
20163 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
20164 struct composition *cmp = composition_table[cmp_id]; \
20166 struct glyph_string *first_s; \
20169 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20171 /* Make glyph_strings for each glyph sequence that is drawable by \
20172 the same face, and append them to HEAD/TAIL. */ \
20173 for (n = 0; n < cmp->glyph_len;) \
20175 s = (struct glyph_string *) alloca (sizeof *s); \
20176 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20177 append_glyph_string (&(HEAD), &(TAIL), s); \
20183 n = fill_composite_glyph_string (s, base_face, overlaps); \
20191 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20192 of AREA of glyph row ROW on window W between indices START and END.
20193 HL overrides the face for drawing glyph strings, e.g. it is
20194 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20195 x-positions of the drawing area.
20197 This is an ugly monster macro construct because we must use alloca
20198 to allocate glyph strings (because draw_glyphs can be called
20199 asynchronously). */
20201 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20204 HEAD = TAIL = NULL; \
20205 while (START < END) \
20207 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20208 switch (first_glyph->type) \
20211 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20215 case COMPOSITE_GLYPH: \
20216 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20220 case STRETCH_GLYPH: \
20221 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20225 case IMAGE_GLYPH: \
20226 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20236 set_glyph_string_background_width (s, START, LAST_X); \
20244 /* Draw glyphs between START and END in AREA of ROW on window W,
20245 starting at x-position X. X is relative to AREA in W. HL is a
20246 face-override with the following meaning:
20248 DRAW_NORMAL_TEXT draw normally
20249 DRAW_CURSOR draw in cursor face
20250 DRAW_MOUSE_FACE draw in mouse face.
20251 DRAW_INVERSE_VIDEO draw in mode line face
20252 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20253 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20255 If OVERLAPS is non-zero, draw only the foreground of characters and
20256 clip to the physical height of ROW. Non-zero value also defines
20257 the overlapping part to be drawn:
20259 OVERLAPS_PRED overlap with preceding rows
20260 OVERLAPS_SUCC overlap with succeeding rows
20261 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20262 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20264 Value is the x-position reached, relative to AREA of W. */
20267 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20270 struct glyph_row
*row
;
20271 enum glyph_row_area area
;
20272 EMACS_INT start
, end
;
20273 enum draw_glyphs_face hl
;
20276 struct glyph_string
*head
, *tail
;
20277 struct glyph_string
*s
;
20278 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20279 int i
, j
, x_reached
, last_x
, area_left
= 0;
20280 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20283 ALLOCATE_HDC (hdc
, f
);
20285 /* Let's rather be paranoid than getting a SEGV. */
20286 end
= min (end
, row
->used
[area
]);
20287 start
= max (0, start
);
20288 start
= min (end
, start
);
20290 /* Translate X to frame coordinates. Set last_x to the right
20291 end of the drawing area. */
20292 if (row
->full_width_p
)
20294 /* X is relative to the left edge of W, without scroll bars
20296 area_left
= WINDOW_LEFT_EDGE_X (w
);
20297 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20301 area_left
= window_box_left (w
, area
);
20302 last_x
= area_left
+ window_box_width (w
, area
);
20306 /* Build a doubly-linked list of glyph_string structures between
20307 head and tail from what we have to draw. Note that the macro
20308 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20309 the reason we use a separate variable `i'. */
20311 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20313 x_reached
= tail
->x
+ tail
->background_width
;
20317 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20318 the row, redraw some glyphs in front or following the glyph
20319 strings built above. */
20320 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20322 struct glyph_string
*h
, *t
;
20323 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20324 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20327 /* If mouse highlighting is on, we may need to draw adjacent
20328 glyphs using mouse-face highlighting. */
20329 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20331 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20333 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20334 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20336 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20338 check_mouse_face
= 1;
20339 mouse_beg_col
= (row
== mouse_beg_row
)
20340 ? dpyinfo
->mouse_face_beg_col
: 0;
20341 mouse_end_col
= (row
== mouse_end_row
)
20342 ? dpyinfo
->mouse_face_end_col
20343 : row
->used
[TEXT_AREA
];
20347 /* Compute overhangs for all glyph strings. */
20348 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20349 for (s
= head
; s
; s
= s
->next
)
20350 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20352 /* Prepend glyph strings for glyphs in front of the first glyph
20353 string that are overwritten because of the first glyph
20354 string's left overhang. The background of all strings
20355 prepended must be drawn because the first glyph string
20357 i
= left_overwritten (head
);
20360 enum draw_glyphs_face overlap_hl
;
20362 /* If this row contains mouse highlighting, attempt to draw
20363 the overlapped glyphs with the correct highlight. This
20364 code fails if the overlap encompasses more than one glyph
20365 and mouse-highlight spans only some of these glyphs.
20366 However, making it work perfectly involves a lot more
20367 code, and I don't know if the pathological case occurs in
20368 practice, so we'll stick to this for now. --- cyd */
20369 if (check_mouse_face
20370 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20371 overlap_hl
= DRAW_MOUSE_FACE
;
20373 overlap_hl
= DRAW_NORMAL_TEXT
;
20376 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20377 overlap_hl
, dummy_x
, last_x
);
20378 compute_overhangs_and_x (t
, head
->x
, 1);
20379 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20383 /* Prepend glyph strings for glyphs in front of the first glyph
20384 string that overwrite that glyph string because of their
20385 right overhang. For these strings, only the foreground must
20386 be drawn, because it draws over the glyph string at `head'.
20387 The background must not be drawn because this would overwrite
20388 right overhangs of preceding glyphs for which no glyph
20390 i
= left_overwriting (head
);
20393 enum draw_glyphs_face overlap_hl
;
20395 if (check_mouse_face
20396 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20397 overlap_hl
= DRAW_MOUSE_FACE
;
20399 overlap_hl
= DRAW_NORMAL_TEXT
;
20402 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20403 overlap_hl
, dummy_x
, last_x
);
20404 for (s
= h
; s
; s
= s
->next
)
20405 s
->background_filled_p
= 1;
20406 compute_overhangs_and_x (t
, head
->x
, 1);
20407 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20410 /* Append glyphs strings for glyphs following the last glyph
20411 string tail that are overwritten by tail. The background of
20412 these strings has to be drawn because tail's foreground draws
20414 i
= right_overwritten (tail
);
20417 enum draw_glyphs_face overlap_hl
;
20419 if (check_mouse_face
20420 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20421 overlap_hl
= DRAW_MOUSE_FACE
;
20423 overlap_hl
= DRAW_NORMAL_TEXT
;
20425 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20426 overlap_hl
, x
, last_x
);
20427 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20428 append_glyph_string_lists (&head
, &tail
, h
, t
);
20432 /* Append glyph strings for glyphs following the last glyph
20433 string tail that overwrite tail. The foreground of such
20434 glyphs has to be drawn because it writes into the background
20435 of tail. The background must not be drawn because it could
20436 paint over the foreground of following glyphs. */
20437 i
= right_overwriting (tail
);
20440 enum draw_glyphs_face overlap_hl
;
20441 if (check_mouse_face
20442 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20443 overlap_hl
= DRAW_MOUSE_FACE
;
20445 overlap_hl
= DRAW_NORMAL_TEXT
;
20448 i
++; /* We must include the Ith glyph. */
20449 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20450 overlap_hl
, x
, last_x
);
20451 for (s
= h
; s
; s
= s
->next
)
20452 s
->background_filled_p
= 1;
20453 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20454 append_glyph_string_lists (&head
, &tail
, h
, t
);
20456 if (clip_head
|| clip_tail
)
20457 for (s
= head
; s
; s
= s
->next
)
20459 s
->clip_head
= clip_head
;
20460 s
->clip_tail
= clip_tail
;
20464 /* Draw all strings. */
20465 for (s
= head
; s
; s
= s
->next
)
20466 FRAME_RIF (f
)->draw_glyph_string (s
);
20468 if (area
== TEXT_AREA
20469 && !row
->full_width_p
20470 /* When drawing overlapping rows, only the glyph strings'
20471 foreground is drawn, which doesn't erase a cursor
20475 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20476 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20477 : (tail
? tail
->x
+ tail
->background_width
: x
));
20481 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20482 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20485 /* Value is the x-position up to which drawn, relative to AREA of W.
20486 This doesn't include parts drawn because of overhangs. */
20487 if (row
->full_width_p
)
20488 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20490 x_reached
-= area_left
;
20492 RELEASE_HDC (hdc
, f
);
20497 /* Expand row matrix if too narrow. Don't expand if area
20500 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20502 if (!fonts_changed_p \
20503 && (it->glyph_row->glyphs[area] \
20504 < it->glyph_row->glyphs[area + 1])) \
20506 it->w->ncols_scale_factor++; \
20507 fonts_changed_p = 1; \
20511 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20512 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20518 struct glyph
*glyph
;
20519 enum glyph_row_area area
= it
->area
;
20521 xassert (it
->glyph_row
);
20522 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20524 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20525 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20527 glyph
->charpos
= CHARPOS (it
->position
);
20528 glyph
->object
= it
->object
;
20529 if (it
->pixel_width
> 0)
20531 glyph
->pixel_width
= it
->pixel_width
;
20532 glyph
->padding_p
= 0;
20536 /* Assure at least 1-pixel width. Otherwise, cursor can't
20537 be displayed correctly. */
20538 glyph
->pixel_width
= 1;
20539 glyph
->padding_p
= 1;
20541 glyph
->ascent
= it
->ascent
;
20542 glyph
->descent
= it
->descent
;
20543 glyph
->voffset
= it
->voffset
;
20544 glyph
->type
= CHAR_GLYPH
;
20545 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20546 glyph
->multibyte_p
= it
->multibyte_p
;
20547 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20548 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20549 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20550 || it
->phys_descent
> it
->descent
);
20551 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20552 glyph
->face_id
= it
->face_id
;
20553 glyph
->u
.ch
= it
->char_to_display
;
20554 glyph
->slice
= null_glyph_slice
;
20555 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20556 ++it
->glyph_row
->used
[area
];
20559 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20562 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
20563 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20566 append_composite_glyph (it
)
20569 struct glyph
*glyph
;
20570 enum glyph_row_area area
= it
->area
;
20572 xassert (it
->glyph_row
);
20574 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20575 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20577 glyph
->charpos
= CHARPOS (it
->position
);
20578 glyph
->object
= it
->object
;
20579 glyph
->pixel_width
= it
->pixel_width
;
20580 glyph
->ascent
= it
->ascent
;
20581 glyph
->descent
= it
->descent
;
20582 glyph
->voffset
= it
->voffset
;
20583 glyph
->type
= COMPOSITE_GLYPH
;
20584 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20585 glyph
->multibyte_p
= it
->multibyte_p
;
20586 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20587 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20588 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20589 || it
->phys_descent
> it
->descent
);
20590 glyph
->padding_p
= 0;
20591 glyph
->glyph_not_available_p
= 0;
20592 glyph
->face_id
= it
->face_id
;
20593 glyph
->u
.cmp_id
= it
->cmp_id
;
20594 glyph
->slice
= null_glyph_slice
;
20595 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20596 ++it
->glyph_row
->used
[area
];
20599 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20603 /* Change IT->ascent and IT->height according to the setting of
20607 take_vertical_position_into_account (it
)
20612 if (it
->voffset
< 0)
20613 /* Increase the ascent so that we can display the text higher
20615 it
->ascent
-= it
->voffset
;
20617 /* Increase the descent so that we can display the text lower
20619 it
->descent
+= it
->voffset
;
20624 /* Produce glyphs/get display metrics for the image IT is loaded with.
20625 See the description of struct display_iterator in dispextern.h for
20626 an overview of struct display_iterator. */
20629 produce_image_glyph (it
)
20634 int glyph_ascent
, crop
;
20635 struct glyph_slice slice
;
20637 xassert (it
->what
== IT_IMAGE
);
20639 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20641 /* Make sure X resources of the face is loaded. */
20642 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20644 if (it
->image_id
< 0)
20646 /* Fringe bitmap. */
20647 it
->ascent
= it
->phys_ascent
= 0;
20648 it
->descent
= it
->phys_descent
= 0;
20649 it
->pixel_width
= 0;
20654 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20656 /* Make sure X resources of the image is loaded. */
20657 prepare_image_for_display (it
->f
, img
);
20659 slice
.x
= slice
.y
= 0;
20660 slice
.width
= img
->width
;
20661 slice
.height
= img
->height
;
20663 if (INTEGERP (it
->slice
.x
))
20664 slice
.x
= XINT (it
->slice
.x
);
20665 else if (FLOATP (it
->slice
.x
))
20666 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20668 if (INTEGERP (it
->slice
.y
))
20669 slice
.y
= XINT (it
->slice
.y
);
20670 else if (FLOATP (it
->slice
.y
))
20671 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20673 if (INTEGERP (it
->slice
.width
))
20674 slice
.width
= XINT (it
->slice
.width
);
20675 else if (FLOATP (it
->slice
.width
))
20676 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20678 if (INTEGERP (it
->slice
.height
))
20679 slice
.height
= XINT (it
->slice
.height
);
20680 else if (FLOATP (it
->slice
.height
))
20681 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20683 if (slice
.x
>= img
->width
)
20684 slice
.x
= img
->width
;
20685 if (slice
.y
>= img
->height
)
20686 slice
.y
= img
->height
;
20687 if (slice
.x
+ slice
.width
>= img
->width
)
20688 slice
.width
= img
->width
- slice
.x
;
20689 if (slice
.y
+ slice
.height
> img
->height
)
20690 slice
.height
= img
->height
- slice
.y
;
20692 if (slice
.width
== 0 || slice
.height
== 0)
20695 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20697 it
->descent
= slice
.height
- glyph_ascent
;
20699 it
->descent
+= img
->vmargin
;
20700 if (slice
.y
+ slice
.height
== img
->height
)
20701 it
->descent
+= img
->vmargin
;
20702 it
->phys_descent
= it
->descent
;
20704 it
->pixel_width
= slice
.width
;
20706 it
->pixel_width
+= img
->hmargin
;
20707 if (slice
.x
+ slice
.width
== img
->width
)
20708 it
->pixel_width
+= img
->hmargin
;
20710 /* It's quite possible for images to have an ascent greater than
20711 their height, so don't get confused in that case. */
20712 if (it
->descent
< 0)
20715 #if 0 /* this breaks image tiling */
20716 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
20717 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
20718 if (face_ascent
> it
->ascent
)
20719 it
->ascent
= it
->phys_ascent
= face_ascent
;
20724 if (face
->box
!= FACE_NO_BOX
)
20726 if (face
->box_line_width
> 0)
20729 it
->ascent
+= face
->box_line_width
;
20730 if (slice
.y
+ slice
.height
== img
->height
)
20731 it
->descent
+= face
->box_line_width
;
20734 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20735 it
->pixel_width
+= eabs (face
->box_line_width
);
20736 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20737 it
->pixel_width
+= eabs (face
->box_line_width
);
20740 take_vertical_position_into_account (it
);
20742 /* Automatically crop wide image glyphs at right edge so we can
20743 draw the cursor on same display row. */
20744 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20745 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20747 it
->pixel_width
-= crop
;
20748 slice
.width
-= crop
;
20753 struct glyph
*glyph
;
20754 enum glyph_row_area area
= it
->area
;
20756 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20757 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20759 glyph
->charpos
= CHARPOS (it
->position
);
20760 glyph
->object
= it
->object
;
20761 glyph
->pixel_width
= it
->pixel_width
;
20762 glyph
->ascent
= glyph_ascent
;
20763 glyph
->descent
= it
->descent
;
20764 glyph
->voffset
= it
->voffset
;
20765 glyph
->type
= IMAGE_GLYPH
;
20766 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20767 glyph
->multibyte_p
= it
->multibyte_p
;
20768 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20769 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20770 glyph
->overlaps_vertically_p
= 0;
20771 glyph
->padding_p
= 0;
20772 glyph
->glyph_not_available_p
= 0;
20773 glyph
->face_id
= it
->face_id
;
20774 glyph
->u
.img_id
= img
->id
;
20775 glyph
->slice
= slice
;
20776 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20777 ++it
->glyph_row
->used
[area
];
20780 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20785 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20786 of the glyph, WIDTH and HEIGHT are the width and height of the
20787 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20790 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20792 Lisp_Object object
;
20796 struct glyph
*glyph
;
20797 enum glyph_row_area area
= it
->area
;
20799 xassert (ascent
>= 0 && ascent
<= height
);
20801 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20802 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20804 glyph
->charpos
= CHARPOS (it
->position
);
20805 glyph
->object
= object
;
20806 glyph
->pixel_width
= width
;
20807 glyph
->ascent
= ascent
;
20808 glyph
->descent
= height
- ascent
;
20809 glyph
->voffset
= it
->voffset
;
20810 glyph
->type
= STRETCH_GLYPH
;
20811 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20812 glyph
->multibyte_p
= it
->multibyte_p
;
20813 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20814 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20815 glyph
->overlaps_vertically_p
= 0;
20816 glyph
->padding_p
= 0;
20817 glyph
->glyph_not_available_p
= 0;
20818 glyph
->face_id
= it
->face_id
;
20819 glyph
->u
.stretch
.ascent
= ascent
;
20820 glyph
->u
.stretch
.height
= height
;
20821 glyph
->slice
= null_glyph_slice
;
20822 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20823 ++it
->glyph_row
->used
[area
];
20826 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20830 /* Produce a stretch glyph for iterator IT. IT->object is the value
20831 of the glyph property displayed. The value must be a list
20832 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20835 1. `:width WIDTH' specifies that the space should be WIDTH *
20836 canonical char width wide. WIDTH may be an integer or floating
20839 2. `:relative-width FACTOR' specifies that the width of the stretch
20840 should be computed from the width of the first character having the
20841 `glyph' property, and should be FACTOR times that width.
20843 3. `:align-to HPOS' specifies that the space should be wide enough
20844 to reach HPOS, a value in canonical character units.
20846 Exactly one of the above pairs must be present.
20848 4. `:height HEIGHT' specifies that the height of the stretch produced
20849 should be HEIGHT, measured in canonical character units.
20851 5. `:relative-height FACTOR' specifies that the height of the
20852 stretch should be FACTOR times the height of the characters having
20853 the glyph property.
20855 Either none or exactly one of 4 or 5 must be present.
20857 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20858 of the stretch should be used for the ascent of the stretch.
20859 ASCENT must be in the range 0 <= ASCENT <= 100. */
20862 produce_stretch_glyph (it
)
20865 /* (space :width WIDTH :height HEIGHT ...) */
20866 Lisp_Object prop
, plist
;
20867 int width
= 0, height
= 0, align_to
= -1;
20868 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20871 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20872 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20874 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20876 /* List should start with `space'. */
20877 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20878 plist
= XCDR (it
->object
);
20880 /* Compute the width of the stretch. */
20881 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20882 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20884 /* Absolute width `:width WIDTH' specified and valid. */
20885 zero_width_ok_p
= 1;
20888 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20891 /* Relative width `:relative-width FACTOR' specified and valid.
20892 Compute the width of the characters having the `glyph'
20895 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20898 if (it
->multibyte_p
)
20900 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20901 - IT_BYTEPOS (*it
));
20902 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20905 it2
.c
= *p
, it2
.len
= 1;
20907 it2
.glyph_row
= NULL
;
20908 it2
.what
= IT_CHARACTER
;
20909 x_produce_glyphs (&it2
);
20910 width
= NUMVAL (prop
) * it2
.pixel_width
;
20912 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20913 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20915 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20916 align_to
= (align_to
< 0
20918 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20919 else if (align_to
< 0)
20920 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20921 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20922 zero_width_ok_p
= 1;
20925 /* Nothing specified -> width defaults to canonical char width. */
20926 width
= FRAME_COLUMN_WIDTH (it
->f
);
20928 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20931 /* Compute height. */
20932 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20933 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20936 zero_height_ok_p
= 1;
20938 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20940 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20942 height
= FONT_HEIGHT (font
);
20944 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20947 /* Compute percentage of height used for ascent. If
20948 `:ascent ASCENT' is present and valid, use that. Otherwise,
20949 derive the ascent from the font in use. */
20950 if (prop
= Fplist_get (plist
, QCascent
),
20951 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20952 ascent
= height
* NUMVAL (prop
) / 100.0;
20953 else if (!NILP (prop
)
20954 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20955 ascent
= min (max (0, (int)tem
), height
);
20957 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20959 if (width
> 0 && it
->line_wrap
!= TRUNCATE
20960 && it
->current_x
+ width
> it
->last_visible_x
)
20961 width
= it
->last_visible_x
- it
->current_x
- 1;
20963 if (width
> 0 && height
> 0 && it
->glyph_row
)
20965 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20966 if (!STRINGP (object
))
20967 object
= it
->w
->buffer
;
20968 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20971 it
->pixel_width
= width
;
20972 it
->ascent
= it
->phys_ascent
= ascent
;
20973 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20974 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20976 take_vertical_position_into_account (it
);
20979 /* Calculate line-height and line-spacing properties.
20980 An integer value specifies explicit pixel value.
20981 A float value specifies relative value to current face height.
20982 A cons (float . face-name) specifies relative value to
20983 height of specified face font.
20985 Returns height in pixels, or nil. */
20989 calc_line_height_property (it
, val
, font
, boff
, override
)
20993 int boff
, override
;
20995 Lisp_Object face_name
= Qnil
;
20996 int ascent
, descent
, height
;
20998 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21003 face_name
= XCAR (val
);
21005 if (!NUMBERP (val
))
21006 val
= make_number (1);
21007 if (NILP (face_name
))
21009 height
= it
->ascent
+ it
->descent
;
21014 if (NILP (face_name
))
21016 font
= FRAME_FONT (it
->f
);
21017 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21019 else if (EQ (face_name
, Qt
))
21028 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21030 return make_number (-1);
21032 face
= FACE_FROM_ID (it
->f
, face_id
);
21035 return make_number (-1);
21036 boff
= font
->baseline_offset
;
21037 if (font
->vertical_centering
)
21038 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21041 ascent
= FONT_BASE (font
) + boff
;
21042 descent
= FONT_DESCENT (font
) - boff
;
21046 it
->override_ascent
= ascent
;
21047 it
->override_descent
= descent
;
21048 it
->override_boff
= boff
;
21051 height
= ascent
+ descent
;
21055 height
= (int)(XFLOAT_DATA (val
) * height
);
21056 else if (INTEGERP (val
))
21057 height
*= XINT (val
);
21059 return make_number (height
);
21064 Produce glyphs/get display metrics for the display element IT is
21065 loaded with. See the description of struct it in dispextern.h
21066 for an overview of struct it. */
21069 x_produce_glyphs (it
)
21072 int extra_line_spacing
= it
->extra_line_spacing
;
21074 it
->glyph_not_available_p
= 0;
21076 if (it
->what
== IT_CHARACTER
)
21080 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21081 struct font_metrics
*pcm
;
21082 int font_not_found_p
;
21083 int boff
; /* baseline offset */
21084 /* We may change it->multibyte_p upon unibyte<->multibyte
21085 conversion. So, save the current value now and restore it
21088 Note: It seems that we don't have to record multibyte_p in
21089 struct glyph because the character code itself tells if or
21090 not the character is multibyte. Thus, in the future, we must
21091 consider eliminating the field `multibyte_p' in the struct
21093 int saved_multibyte_p
= it
->multibyte_p
;
21095 /* Maybe translate single-byte characters to multibyte, or the
21097 it
->char_to_display
= it
->c
;
21098 if (!ASCII_BYTE_P (it
->c
)
21099 && ! it
->multibyte_p
)
21101 if (SINGLE_BYTE_CHAR_P (it
->c
)
21102 && unibyte_display_via_language_environment
)
21103 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
21104 if (! SINGLE_BYTE_CHAR_P (it
->char_to_display
))
21106 it
->multibyte_p
= 1;
21107 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21109 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21113 /* Get font to use. Encode IT->char_to_display. */
21114 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21115 &char2b
, it
->multibyte_p
, 0);
21118 /* When no suitable font found, use the default font. */
21119 font_not_found_p
= font
== NULL
;
21120 if (font_not_found_p
)
21122 font
= FRAME_FONT (it
->f
);
21123 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21127 boff
= font
->baseline_offset
;
21128 if (font
->vertical_centering
)
21129 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21132 if (it
->char_to_display
>= ' '
21133 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21135 /* Either unibyte or ASCII. */
21140 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21142 if (it
->override_ascent
>= 0)
21144 it
->ascent
= it
->override_ascent
;
21145 it
->descent
= it
->override_descent
;
21146 boff
= it
->override_boff
;
21150 it
->ascent
= FONT_BASE (font
) + boff
;
21151 it
->descent
= FONT_DESCENT (font
) - boff
;
21156 it
->phys_ascent
= pcm
->ascent
+ boff
;
21157 it
->phys_descent
= pcm
->descent
- boff
;
21158 it
->pixel_width
= pcm
->width
;
21162 it
->glyph_not_available_p
= 1;
21163 it
->phys_ascent
= it
->ascent
;
21164 it
->phys_descent
= it
->descent
;
21165 it
->pixel_width
= FONT_WIDTH (font
);
21168 if (it
->constrain_row_ascent_descent_p
)
21170 if (it
->descent
> it
->max_descent
)
21172 it
->ascent
+= it
->descent
- it
->max_descent
;
21173 it
->descent
= it
->max_descent
;
21175 if (it
->ascent
> it
->max_ascent
)
21177 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21178 it
->ascent
= it
->max_ascent
;
21180 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21181 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21182 extra_line_spacing
= 0;
21185 /* If this is a space inside a region of text with
21186 `space-width' property, change its width. */
21187 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21189 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21191 /* If face has a box, add the box thickness to the character
21192 height. If character has a box line to the left and/or
21193 right, add the box line width to the character's width. */
21194 if (face
->box
!= FACE_NO_BOX
)
21196 int thick
= face
->box_line_width
;
21200 it
->ascent
+= thick
;
21201 it
->descent
+= thick
;
21206 if (it
->start_of_box_run_p
)
21207 it
->pixel_width
+= thick
;
21208 if (it
->end_of_box_run_p
)
21209 it
->pixel_width
+= thick
;
21212 /* If face has an overline, add the height of the overline
21213 (1 pixel) and a 1 pixel margin to the character height. */
21214 if (face
->overline_p
)
21215 it
->ascent
+= overline_margin
;
21217 if (it
->constrain_row_ascent_descent_p
)
21219 if (it
->ascent
> it
->max_ascent
)
21220 it
->ascent
= it
->max_ascent
;
21221 if (it
->descent
> it
->max_descent
)
21222 it
->descent
= it
->max_descent
;
21225 take_vertical_position_into_account (it
);
21227 /* If we have to actually produce glyphs, do it. */
21232 /* Translate a space with a `space-width' property
21233 into a stretch glyph. */
21234 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21235 / FONT_HEIGHT (font
));
21236 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21237 it
->ascent
+ it
->descent
, ascent
);
21242 /* If characters with lbearing or rbearing are displayed
21243 in this line, record that fact in a flag of the
21244 glyph row. This is used to optimize X output code. */
21245 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21246 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21248 if (! stretched_p
&& it
->pixel_width
== 0)
21249 /* We assure that all visible glyphs have at least 1-pixel
21251 it
->pixel_width
= 1;
21253 else if (it
->char_to_display
== '\n')
21255 /* A newline has no width but we need the height of the line.
21256 But if previous part of the line set a height, don't
21257 increase that height */
21259 Lisp_Object height
;
21260 Lisp_Object total_height
= Qnil
;
21262 it
->override_ascent
= -1;
21263 it
->pixel_width
= 0;
21266 height
= get_it_property(it
, Qline_height
);
21267 /* Split (line-height total-height) list */
21269 && CONSP (XCDR (height
))
21270 && NILP (XCDR (XCDR (height
))))
21272 total_height
= XCAR (XCDR (height
));
21273 height
= XCAR (height
);
21275 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21277 if (it
->override_ascent
>= 0)
21279 it
->ascent
= it
->override_ascent
;
21280 it
->descent
= it
->override_descent
;
21281 boff
= it
->override_boff
;
21285 it
->ascent
= FONT_BASE (font
) + boff
;
21286 it
->descent
= FONT_DESCENT (font
) - boff
;
21289 if (EQ (height
, Qt
))
21291 if (it
->descent
> it
->max_descent
)
21293 it
->ascent
+= it
->descent
- it
->max_descent
;
21294 it
->descent
= it
->max_descent
;
21296 if (it
->ascent
> it
->max_ascent
)
21298 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21299 it
->ascent
= it
->max_ascent
;
21301 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21302 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21303 it
->constrain_row_ascent_descent_p
= 1;
21304 extra_line_spacing
= 0;
21308 Lisp_Object spacing
;
21310 it
->phys_ascent
= it
->ascent
;
21311 it
->phys_descent
= it
->descent
;
21313 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21314 && face
->box
!= FACE_NO_BOX
21315 && face
->box_line_width
> 0)
21317 it
->ascent
+= face
->box_line_width
;
21318 it
->descent
+= face
->box_line_width
;
21321 && XINT (height
) > it
->ascent
+ it
->descent
)
21322 it
->ascent
= XINT (height
) - it
->descent
;
21324 if (!NILP (total_height
))
21325 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21328 spacing
= get_it_property(it
, Qline_spacing
);
21329 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21331 if (INTEGERP (spacing
))
21333 extra_line_spacing
= XINT (spacing
);
21334 if (!NILP (total_height
))
21335 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21339 else if (it
->char_to_display
== '\t')
21341 if (font
->space_width
> 0)
21343 int tab_width
= it
->tab_width
* font
->space_width
;
21344 int x
= it
->current_x
+ it
->continuation_lines_width
;
21345 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21347 /* If the distance from the current position to the next tab
21348 stop is less than a space character width, use the
21349 tab stop after that. */
21350 if (next_tab_x
- x
< font
->space_width
)
21351 next_tab_x
+= tab_width
;
21353 it
->pixel_width
= next_tab_x
- x
;
21355 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21356 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21360 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21361 it
->ascent
+ it
->descent
, it
->ascent
);
21366 it
->pixel_width
= 0;
21372 /* A multi-byte character. Assume that the display width of the
21373 character is the width of the character multiplied by the
21374 width of the font. */
21376 /* If we found a font, this font should give us the right
21377 metrics. If we didn't find a font, use the frame's
21378 default font and calculate the width of the character by
21379 multiplying the width of font by the width of the
21382 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21384 if (font_not_found_p
|| !pcm
)
21386 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21388 if (char_width
== 0)
21389 /* This is a non spacing character. But, as we are
21390 going to display an empty box, the box must occupy
21391 at least one column. */
21393 it
->glyph_not_available_p
= 1;
21394 it
->pixel_width
= FRAME_COLUMN_WIDTH (it
->f
) * char_width
;
21395 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21396 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21400 it
->pixel_width
= pcm
->width
;
21401 it
->phys_ascent
= pcm
->ascent
+ boff
;
21402 it
->phys_descent
= pcm
->descent
- boff
;
21404 && (pcm
->lbearing
< 0
21405 || pcm
->rbearing
> pcm
->width
))
21406 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21409 it
->ascent
= FONT_BASE (font
) + boff
;
21410 it
->descent
= FONT_DESCENT (font
) - boff
;
21411 if (face
->box
!= FACE_NO_BOX
)
21413 int thick
= face
->box_line_width
;
21417 it
->ascent
+= thick
;
21418 it
->descent
+= thick
;
21423 if (it
->start_of_box_run_p
)
21424 it
->pixel_width
+= thick
;
21425 if (it
->end_of_box_run_p
)
21426 it
->pixel_width
+= thick
;
21429 /* If face has an overline, add the height of the overline
21430 (1 pixel) and a 1 pixel margin to the character height. */
21431 if (face
->overline_p
)
21432 it
->ascent
+= overline_margin
;
21434 take_vertical_position_into_account (it
);
21436 if (it
->ascent
< 0)
21438 if (it
->descent
< 0)
21443 if (it
->pixel_width
== 0)
21444 /* We assure that all visible glyphs have at least 1-pixel
21446 it
->pixel_width
= 1;
21448 it
->multibyte_p
= saved_multibyte_p
;
21450 else if (it
->what
== IT_COMPOSITION
)
21452 /* Note: A composition is represented as one glyph in the
21453 glyph matrix. There are no padding glyphs.
21455 Important is that pixel_width, ascent, and descent are the
21456 values of what is drawn by draw_glyphs (i.e. the values of
21457 the overall glyphs composed). */
21458 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21459 int boff
; /* baseline offset */
21460 struct composition
*cmp
= composition_table
[it
->cmp_id
];
21461 int glyph_len
= cmp
->glyph_len
;
21462 struct font
*font
= face
->font
;
21466 if (cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
21468 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21469 font_prepare_composition (cmp
, it
->f
);
21472 /* If we have not yet calculated pixel size data of glyphs of
21473 the composition for the current face font, calculate them
21474 now. Theoretically, we have to check all fonts for the
21475 glyphs, but that requires much time and memory space. So,
21476 here we check only the font of the first glyph. This leads
21477 to incorrect display, but it's very rare, and C-l (recenter)
21478 can correct the display anyway. */
21479 if (! cmp
->font
|| cmp
->font
!= font
)
21481 /* Ascent and descent of the font of the first character
21482 of this composition (adjusted by baseline offset).
21483 Ascent and descent of overall glyphs should not be less
21484 than them respectively. */
21485 int font_ascent
, font_descent
, font_height
;
21486 /* Bounding box of the overall glyphs. */
21487 int leftmost
, rightmost
, lowest
, highest
;
21488 int lbearing
, rbearing
;
21489 int i
, width
, ascent
, descent
;
21490 int left_padded
= 0, right_padded
= 0;
21494 struct font_metrics
*pcm
;
21495 int font_not_found_p
;
21498 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21499 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21501 if (glyph_len
< cmp
->glyph_len
)
21503 for (i
= 0; i
< glyph_len
; i
++)
21505 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21507 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21512 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21513 : IT_CHARPOS (*it
));
21514 /* When no suitable font found, use the default font. */
21515 font_not_found_p
= font
== NULL
;
21516 if (font_not_found_p
)
21518 face
= face
->ascii_face
;
21521 boff
= font
->baseline_offset
;
21522 if (font
->vertical_centering
)
21523 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21524 font_ascent
= FONT_BASE (font
) + boff
;
21525 font_descent
= FONT_DESCENT (font
) - boff
;
21526 font_height
= FONT_HEIGHT (font
);
21528 cmp
->font
= (void *) font
;
21531 if (! font_not_found_p
)
21533 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21534 &char2b
, it
->multibyte_p
, 0);
21535 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21538 /* Initialize the bounding box. */
21541 width
= pcm
->width
;
21542 ascent
= pcm
->ascent
;
21543 descent
= pcm
->descent
;
21544 lbearing
= pcm
->lbearing
;
21545 rbearing
= pcm
->rbearing
;
21549 width
= FONT_WIDTH (font
);
21550 ascent
= FONT_BASE (font
);
21551 descent
= FONT_DESCENT (font
);
21558 lowest
= - descent
+ boff
;
21559 highest
= ascent
+ boff
;
21561 if (! font_not_found_p
21562 && font
->default_ascent
21563 && CHAR_TABLE_P (Vuse_default_ascent
)
21564 && !NILP (Faref (Vuse_default_ascent
,
21565 make_number (it
->char_to_display
))))
21566 highest
= font
->default_ascent
+ boff
;
21568 /* Draw the first glyph at the normal position. It may be
21569 shifted to right later if some other glyphs are drawn
21571 cmp
->offsets
[i
* 2] = 0;
21572 cmp
->offsets
[i
* 2 + 1] = boff
;
21573 cmp
->lbearing
= lbearing
;
21574 cmp
->rbearing
= rbearing
;
21576 /* Set cmp->offsets for the remaining glyphs. */
21577 for (i
++; i
< glyph_len
; i
++)
21579 int left
, right
, btm
, top
;
21580 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21582 struct face
*this_face
;
21587 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21588 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21589 font
= this_face
->font
;
21595 this_boff
= font
->baseline_offset
;
21596 if (font
->vertical_centering
)
21597 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21598 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21599 &char2b
, it
->multibyte_p
, 0);
21600 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21603 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21606 width
= pcm
->width
;
21607 ascent
= pcm
->ascent
;
21608 descent
= pcm
->descent
;
21609 lbearing
= pcm
->lbearing
;
21610 rbearing
= pcm
->rbearing
;
21611 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21613 /* Relative composition with or without
21614 alternate chars. */
21615 left
= (leftmost
+ rightmost
- width
) / 2;
21616 btm
= - descent
+ boff
;
21617 if (font
->relative_compose
21618 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21619 || NILP (Faref (Vignore_relative_composition
,
21620 make_number (ch
)))))
21623 if (- descent
>= font
->relative_compose
)
21624 /* One extra pixel between two glyphs. */
21626 else if (ascent
<= 0)
21627 /* One extra pixel between two glyphs. */
21628 btm
= lowest
- 1 - ascent
- descent
;
21633 /* A composition rule is specified by an integer
21634 value that encodes global and new reference
21635 points (GREF and NREF). GREF and NREF are
21636 specified by numbers as below:
21638 0---1---2 -- ascent
21642 9--10--11 -- center
21644 ---3---4---5--- baseline
21646 6---7---8 -- descent
21648 int rule
= COMPOSITION_RULE (cmp
, i
);
21649 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21651 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21652 grefx
= gref
% 3, nrefx
= nref
% 3;
21653 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21655 xoff
= font_height
* (xoff
- 128) / 256;
21657 yoff
= font_height
* (yoff
- 128) / 256;
21660 + grefx
* (rightmost
- leftmost
) / 2
21661 - nrefx
* width
/ 2
21664 btm
= ((grefy
== 0 ? highest
21666 : grefy
== 2 ? lowest
21667 : (highest
+ lowest
) / 2)
21668 - (nrefy
== 0 ? ascent
+ descent
21669 : nrefy
== 1 ? descent
- boff
21671 : (ascent
+ descent
) / 2)
21675 cmp
->offsets
[i
* 2] = left
;
21676 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21678 /* Update the bounding box of the overall glyphs. */
21681 right
= left
+ width
;
21682 if (left
< leftmost
)
21684 if (right
> rightmost
)
21687 top
= btm
+ descent
+ ascent
;
21693 if (cmp
->lbearing
> left
+ lbearing
)
21694 cmp
->lbearing
= left
+ lbearing
;
21695 if (cmp
->rbearing
< left
+ rbearing
)
21696 cmp
->rbearing
= left
+ rbearing
;
21700 /* If there are glyphs whose x-offsets are negative,
21701 shift all glyphs to the right and make all x-offsets
21705 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21706 cmp
->offsets
[i
* 2] -= leftmost
;
21707 rightmost
-= leftmost
;
21708 cmp
->lbearing
-= leftmost
;
21709 cmp
->rbearing
-= leftmost
;
21712 if (left_padded
&& cmp
->lbearing
< 0)
21714 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21715 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21716 rightmost
-= cmp
->lbearing
;
21717 cmp
->rbearing
-= cmp
->lbearing
;
21720 if (right_padded
&& rightmost
< cmp
->rbearing
)
21722 rightmost
= cmp
->rbearing
;
21725 cmp
->pixel_width
= rightmost
;
21726 cmp
->ascent
= highest
;
21727 cmp
->descent
= - lowest
;
21728 if (cmp
->ascent
< font_ascent
)
21729 cmp
->ascent
= font_ascent
;
21730 if (cmp
->descent
< font_descent
)
21731 cmp
->descent
= font_descent
;
21735 && (cmp
->lbearing
< 0
21736 || cmp
->rbearing
> cmp
->pixel_width
))
21737 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21739 it
->pixel_width
= cmp
->pixel_width
;
21740 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21741 it
->descent
= it
->phys_descent
= cmp
->descent
;
21742 if (face
->box
!= FACE_NO_BOX
)
21744 int thick
= face
->box_line_width
;
21748 it
->ascent
+= thick
;
21749 it
->descent
+= thick
;
21754 if (it
->start_of_box_run_p
)
21755 it
->pixel_width
+= thick
;
21756 if (it
->end_of_box_run_p
)
21757 it
->pixel_width
+= thick
;
21760 /* If face has an overline, add the height of the overline
21761 (1 pixel) and a 1 pixel margin to the character height. */
21762 if (face
->overline_p
)
21763 it
->ascent
+= overline_margin
;
21765 take_vertical_position_into_account (it
);
21766 if (it
->ascent
< 0)
21768 if (it
->descent
< 0)
21772 append_composite_glyph (it
);
21774 else if (it
->what
== IT_IMAGE
)
21775 produce_image_glyph (it
);
21776 else if (it
->what
== IT_STRETCH
)
21777 produce_stretch_glyph (it
);
21779 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21780 because this isn't true for images with `:ascent 100'. */
21781 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21782 if (it
->area
== TEXT_AREA
)
21783 it
->current_x
+= it
->pixel_width
;
21785 if (extra_line_spacing
> 0)
21787 it
->descent
+= extra_line_spacing
;
21788 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21789 it
->max_extra_line_spacing
= extra_line_spacing
;
21792 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21793 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21794 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21795 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21799 Output LEN glyphs starting at START at the nominal cursor position.
21800 Advance the nominal cursor over the text. The global variable
21801 updated_window contains the window being updated, updated_row is
21802 the glyph row being updated, and updated_area is the area of that
21803 row being updated. */
21806 x_write_glyphs (start
, len
)
21807 struct glyph
*start
;
21812 xassert (updated_window
&& updated_row
);
21815 /* Write glyphs. */
21817 hpos
= start
- updated_row
->glyphs
[updated_area
];
21818 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21819 updated_row
, updated_area
,
21821 DRAW_NORMAL_TEXT
, 0);
21823 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21824 if (updated_area
== TEXT_AREA
21825 && updated_window
->phys_cursor_on_p
21826 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21827 && updated_window
->phys_cursor
.hpos
>= hpos
21828 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21829 updated_window
->phys_cursor_on_p
= 0;
21833 /* Advance the output cursor. */
21834 output_cursor
.hpos
+= len
;
21835 output_cursor
.x
= x
;
21840 Insert LEN glyphs from START at the nominal cursor position. */
21843 x_insert_glyphs (start
, len
)
21844 struct glyph
*start
;
21849 int line_height
, shift_by_width
, shifted_region_width
;
21850 struct glyph_row
*row
;
21851 struct glyph
*glyph
;
21852 int frame_x
, frame_y
;
21855 xassert (updated_window
&& updated_row
);
21857 w
= updated_window
;
21858 f
= XFRAME (WINDOW_FRAME (w
));
21860 /* Get the height of the line we are in. */
21862 line_height
= row
->height
;
21864 /* Get the width of the glyphs to insert. */
21865 shift_by_width
= 0;
21866 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21867 shift_by_width
+= glyph
->pixel_width
;
21869 /* Get the width of the region to shift right. */
21870 shifted_region_width
= (window_box_width (w
, updated_area
)
21875 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21876 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21878 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21879 line_height
, shift_by_width
);
21881 /* Write the glyphs. */
21882 hpos
= start
- row
->glyphs
[updated_area
];
21883 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21885 DRAW_NORMAL_TEXT
, 0);
21887 /* Advance the output cursor. */
21888 output_cursor
.hpos
+= len
;
21889 output_cursor
.x
+= shift_by_width
;
21895 Erase the current text line from the nominal cursor position
21896 (inclusive) to pixel column TO_X (exclusive). The idea is that
21897 everything from TO_X onward is already erased.
21899 TO_X is a pixel position relative to updated_area of
21900 updated_window. TO_X == -1 means clear to the end of this area. */
21903 x_clear_end_of_line (to_x
)
21907 struct window
*w
= updated_window
;
21908 int max_x
, min_y
, max_y
;
21909 int from_x
, from_y
, to_y
;
21911 xassert (updated_window
&& updated_row
);
21912 f
= XFRAME (w
->frame
);
21914 if (updated_row
->full_width_p
)
21915 max_x
= WINDOW_TOTAL_WIDTH (w
);
21917 max_x
= window_box_width (w
, updated_area
);
21918 max_y
= window_text_bottom_y (w
);
21920 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21921 of window. For TO_X > 0, truncate to end of drawing area. */
21927 to_x
= min (to_x
, max_x
);
21929 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21931 /* Notice if the cursor will be cleared by this operation. */
21932 if (!updated_row
->full_width_p
)
21933 notice_overwritten_cursor (w
, updated_area
,
21934 output_cursor
.x
, -1,
21936 MATRIX_ROW_BOTTOM_Y (updated_row
));
21938 from_x
= output_cursor
.x
;
21940 /* Translate to frame coordinates. */
21941 if (updated_row
->full_width_p
)
21943 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21944 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21948 int area_left
= window_box_left (w
, updated_area
);
21949 from_x
+= area_left
;
21953 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21954 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21955 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21957 /* Prevent inadvertently clearing to end of the X window. */
21958 if (to_x
> from_x
&& to_y
> from_y
)
21961 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21962 to_x
- from_x
, to_y
- from_y
);
21967 #endif /* HAVE_WINDOW_SYSTEM */
21971 /***********************************************************************
21973 ***********************************************************************/
21975 /* Value is the internal representation of the specified cursor type
21976 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21977 of the bar cursor. */
21979 static enum text_cursor_kinds
21980 get_specified_cursor_type (arg
, width
)
21984 enum text_cursor_kinds type
;
21989 if (EQ (arg
, Qbox
))
21990 return FILLED_BOX_CURSOR
;
21992 if (EQ (arg
, Qhollow
))
21993 return HOLLOW_BOX_CURSOR
;
21995 if (EQ (arg
, Qbar
))
22002 && EQ (XCAR (arg
), Qbar
)
22003 && INTEGERP (XCDR (arg
))
22004 && XINT (XCDR (arg
)) >= 0)
22006 *width
= XINT (XCDR (arg
));
22010 if (EQ (arg
, Qhbar
))
22013 return HBAR_CURSOR
;
22017 && EQ (XCAR (arg
), Qhbar
)
22018 && INTEGERP (XCDR (arg
))
22019 && XINT (XCDR (arg
)) >= 0)
22021 *width
= XINT (XCDR (arg
));
22022 return HBAR_CURSOR
;
22025 /* Treat anything unknown as "hollow box cursor".
22026 It was bad to signal an error; people have trouble fixing
22027 .Xdefaults with Emacs, when it has something bad in it. */
22028 type
= HOLLOW_BOX_CURSOR
;
22033 /* Set the default cursor types for specified frame. */
22035 set_frame_cursor_types (f
, arg
)
22042 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22043 FRAME_CURSOR_WIDTH (f
) = width
;
22045 /* By default, set up the blink-off state depending on the on-state. */
22047 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22050 FRAME_BLINK_OFF_CURSOR (f
)
22051 = get_specified_cursor_type (XCDR (tem
), &width
);
22052 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22055 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22059 /* Return the cursor we want to be displayed in window W. Return
22060 width of bar/hbar cursor through WIDTH arg. Return with
22061 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22062 (i.e. if the `system caret' should track this cursor).
22064 In a mini-buffer window, we want the cursor only to appear if we
22065 are reading input from this window. For the selected window, we
22066 want the cursor type given by the frame parameter or buffer local
22067 setting of cursor-type. If explicitly marked off, draw no cursor.
22068 In all other cases, we want a hollow box cursor. */
22070 static enum text_cursor_kinds
22071 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22073 struct glyph
*glyph
;
22075 int *active_cursor
;
22077 struct frame
*f
= XFRAME (w
->frame
);
22078 struct buffer
*b
= XBUFFER (w
->buffer
);
22079 int cursor_type
= DEFAULT_CURSOR
;
22080 Lisp_Object alt_cursor
;
22081 int non_selected
= 0;
22083 *active_cursor
= 1;
22086 if (cursor_in_echo_area
22087 && FRAME_HAS_MINIBUF_P (f
)
22088 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22090 if (w
== XWINDOW (echo_area_window
))
22092 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22094 *width
= FRAME_CURSOR_WIDTH (f
);
22095 return FRAME_DESIRED_CURSOR (f
);
22098 return get_specified_cursor_type (b
->cursor_type
, width
);
22101 *active_cursor
= 0;
22105 /* Detect a nonselected window or nonselected frame. */
22106 else if (w
!= XWINDOW (f
->selected_window
)
22107 #ifdef HAVE_WINDOW_SYSTEM
22108 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22112 *active_cursor
= 0;
22114 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22120 /* Never display a cursor in a window in which cursor-type is nil. */
22121 if (NILP (b
->cursor_type
))
22124 /* Get the normal cursor type for this window. */
22125 if (EQ (b
->cursor_type
, Qt
))
22127 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22128 *width
= FRAME_CURSOR_WIDTH (f
);
22131 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22133 /* Use cursor-in-non-selected-windows instead
22134 for non-selected window or frame. */
22137 alt_cursor
= b
->cursor_in_non_selected_windows
;
22138 if (!EQ (Qt
, alt_cursor
))
22139 return get_specified_cursor_type (alt_cursor
, width
);
22140 /* t means modify the normal cursor type. */
22141 if (cursor_type
== FILLED_BOX_CURSOR
)
22142 cursor_type
= HOLLOW_BOX_CURSOR
;
22143 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22145 return cursor_type
;
22148 /* Use normal cursor if not blinked off. */
22149 if (!w
->cursor_off_p
)
22151 #ifdef HAVE_WINDOW_SYSTEM
22152 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22154 if (cursor_type
== FILLED_BOX_CURSOR
)
22156 /* Using a block cursor on large images can be very annoying.
22157 So use a hollow cursor for "large" images.
22158 If image is not transparent (no mask), also use hollow cursor. */
22159 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22160 if (img
!= NULL
&& IMAGEP (img
->spec
))
22162 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22163 where N = size of default frame font size.
22164 This should cover most of the "tiny" icons people may use. */
22166 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22167 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22168 cursor_type
= HOLLOW_BOX_CURSOR
;
22171 else if (cursor_type
!= NO_CURSOR
)
22173 /* Display current only supports BOX and HOLLOW cursors for images.
22174 So for now, unconditionally use a HOLLOW cursor when cursor is
22175 not a solid box cursor. */
22176 cursor_type
= HOLLOW_BOX_CURSOR
;
22180 return cursor_type
;
22183 /* Cursor is blinked off, so determine how to "toggle" it. */
22185 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22186 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22187 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22189 /* Then see if frame has specified a specific blink off cursor type. */
22190 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22192 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22193 return FRAME_BLINK_OFF_CURSOR (f
);
22197 /* Some people liked having a permanently visible blinking cursor,
22198 while others had very strong opinions against it. So it was
22199 decided to remove it. KFS 2003-09-03 */
22201 /* Finally perform built-in cursor blinking:
22202 filled box <-> hollow box
22203 wide [h]bar <-> narrow [h]bar
22204 narrow [h]bar <-> no cursor
22205 other type <-> no cursor */
22207 if (cursor_type
== FILLED_BOX_CURSOR
)
22208 return HOLLOW_BOX_CURSOR
;
22210 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22213 return cursor_type
;
22221 #ifdef HAVE_WINDOW_SYSTEM
22223 /* Notice when the text cursor of window W has been completely
22224 overwritten by a drawing operation that outputs glyphs in AREA
22225 starting at X0 and ending at X1 in the line starting at Y0 and
22226 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22227 the rest of the line after X0 has been written. Y coordinates
22228 are window-relative. */
22231 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22233 enum glyph_row_area area
;
22234 int x0
, y0
, x1
, y1
;
22236 int cx0
, cx1
, cy0
, cy1
;
22237 struct glyph_row
*row
;
22239 if (!w
->phys_cursor_on_p
)
22241 if (area
!= TEXT_AREA
)
22244 if (w
->phys_cursor
.vpos
< 0
22245 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22246 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22247 !(row
->enabled_p
&& row
->displays_text_p
)))
22250 if (row
->cursor_in_fringe_p
)
22252 row
->cursor_in_fringe_p
= 0;
22253 draw_fringe_bitmap (w
, row
, 0);
22254 w
->phys_cursor_on_p
= 0;
22258 cx0
= w
->phys_cursor
.x
;
22259 cx1
= cx0
+ w
->phys_cursor_width
;
22260 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22263 /* The cursor image will be completely removed from the
22264 screen if the output area intersects the cursor area in
22265 y-direction. When we draw in [y0 y1[, and some part of
22266 the cursor is at y < y0, that part must have been drawn
22267 before. When scrolling, the cursor is erased before
22268 actually scrolling, so we don't come here. When not
22269 scrolling, the rows above the old cursor row must have
22270 changed, and in this case these rows must have written
22271 over the cursor image.
22273 Likewise if part of the cursor is below y1, with the
22274 exception of the cursor being in the first blank row at
22275 the buffer and window end because update_text_area
22276 doesn't draw that row. (Except when it does, but
22277 that's handled in update_text_area.) */
22279 cy0
= w
->phys_cursor
.y
;
22280 cy1
= cy0
+ w
->phys_cursor_height
;
22281 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22284 w
->phys_cursor_on_p
= 0;
22287 #endif /* HAVE_WINDOW_SYSTEM */
22290 /************************************************************************
22292 ************************************************************************/
22294 #ifdef HAVE_WINDOW_SYSTEM
22297 Fix the display of area AREA of overlapping row ROW in window W
22298 with respect to the overlapping part OVERLAPS. */
22301 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22303 struct glyph_row
*row
;
22304 enum glyph_row_area area
;
22312 for (i
= 0; i
< row
->used
[area
];)
22314 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22316 int start
= i
, start_x
= x
;
22320 x
+= row
->glyphs
[area
][i
].pixel_width
;
22323 while (i
< row
->used
[area
]
22324 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22326 draw_glyphs (w
, start_x
, row
, area
,
22328 DRAW_NORMAL_TEXT
, overlaps
);
22332 x
+= row
->glyphs
[area
][i
].pixel_width
;
22342 Draw the cursor glyph of window W in glyph row ROW. See the
22343 comment of draw_glyphs for the meaning of HL. */
22346 draw_phys_cursor_glyph (w
, row
, hl
)
22348 struct glyph_row
*row
;
22349 enum draw_glyphs_face hl
;
22351 /* If cursor hpos is out of bounds, don't draw garbage. This can
22352 happen in mini-buffer windows when switching between echo area
22353 glyphs and mini-buffer. */
22354 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22356 int on_p
= w
->phys_cursor_on_p
;
22358 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22359 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22361 w
->phys_cursor_on_p
= on_p
;
22363 if (hl
== DRAW_CURSOR
)
22364 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22365 /* When we erase the cursor, and ROW is overlapped by other
22366 rows, make sure that these overlapping parts of other rows
22368 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22370 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22372 if (row
> w
->current_matrix
->rows
22373 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22374 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22375 OVERLAPS_ERASED_CURSOR
);
22377 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22378 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22379 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22380 OVERLAPS_ERASED_CURSOR
);
22387 Erase the image of a cursor of window W from the screen. */
22390 erase_phys_cursor (w
)
22393 struct frame
*f
= XFRAME (w
->frame
);
22394 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22395 int hpos
= w
->phys_cursor
.hpos
;
22396 int vpos
= w
->phys_cursor
.vpos
;
22397 int mouse_face_here_p
= 0;
22398 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22399 struct glyph_row
*cursor_row
;
22400 struct glyph
*cursor_glyph
;
22401 enum draw_glyphs_face hl
;
22403 /* No cursor displayed or row invalidated => nothing to do on the
22405 if (w
->phys_cursor_type
== NO_CURSOR
)
22406 goto mark_cursor_off
;
22408 /* VPOS >= active_glyphs->nrows means that window has been resized.
22409 Don't bother to erase the cursor. */
22410 if (vpos
>= active_glyphs
->nrows
)
22411 goto mark_cursor_off
;
22413 /* If row containing cursor is marked invalid, there is nothing we
22415 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22416 if (!cursor_row
->enabled_p
)
22417 goto mark_cursor_off
;
22419 /* If line spacing is > 0, old cursor may only be partially visible in
22420 window after split-window. So adjust visible height. */
22421 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22422 window_text_bottom_y (w
) - cursor_row
->y
);
22424 /* If row is completely invisible, don't attempt to delete a cursor which
22425 isn't there. This can happen if cursor is at top of a window, and
22426 we switch to a buffer with a header line in that window. */
22427 if (cursor_row
->visible_height
<= 0)
22428 goto mark_cursor_off
;
22430 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22431 if (cursor_row
->cursor_in_fringe_p
)
22433 cursor_row
->cursor_in_fringe_p
= 0;
22434 draw_fringe_bitmap (w
, cursor_row
, 0);
22435 goto mark_cursor_off
;
22438 /* This can happen when the new row is shorter than the old one.
22439 In this case, either draw_glyphs or clear_end_of_line
22440 should have cleared the cursor. Note that we wouldn't be
22441 able to erase the cursor in this case because we don't have a
22442 cursor glyph at hand. */
22443 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22444 goto mark_cursor_off
;
22446 /* If the cursor is in the mouse face area, redisplay that when
22447 we clear the cursor. */
22448 if (! NILP (dpyinfo
->mouse_face_window
)
22449 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22450 && (vpos
> dpyinfo
->mouse_face_beg_row
22451 || (vpos
== dpyinfo
->mouse_face_beg_row
22452 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22453 && (vpos
< dpyinfo
->mouse_face_end_row
22454 || (vpos
== dpyinfo
->mouse_face_end_row
22455 && hpos
< dpyinfo
->mouse_face_end_col
))
22456 /* Don't redraw the cursor's spot in mouse face if it is at the
22457 end of a line (on a newline). The cursor appears there, but
22458 mouse highlighting does not. */
22459 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22460 mouse_face_here_p
= 1;
22462 /* Maybe clear the display under the cursor. */
22463 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22466 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22469 cursor_glyph
= get_phys_cursor_glyph (w
);
22470 if (cursor_glyph
== NULL
)
22471 goto mark_cursor_off
;
22473 width
= cursor_glyph
->pixel_width
;
22474 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22475 x
= w
->phys_cursor
.x
;
22477 width
-= left_x
- x
;
22478 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22479 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22480 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22483 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22486 /* Erase the cursor by redrawing the character underneath it. */
22487 if (mouse_face_here_p
)
22488 hl
= DRAW_MOUSE_FACE
;
22490 hl
= DRAW_NORMAL_TEXT
;
22491 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22494 w
->phys_cursor_on_p
= 0;
22495 w
->phys_cursor_type
= NO_CURSOR
;
22500 Display or clear cursor of window W. If ON is zero, clear the
22501 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22502 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22505 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22507 int on
, hpos
, vpos
, x
, y
;
22509 struct frame
*f
= XFRAME (w
->frame
);
22510 int new_cursor_type
;
22511 int new_cursor_width
;
22513 struct glyph_row
*glyph_row
;
22514 struct glyph
*glyph
;
22516 /* This is pointless on invisible frames, and dangerous on garbaged
22517 windows and frames; in the latter case, the frame or window may
22518 be in the midst of changing its size, and x and y may be off the
22520 if (! FRAME_VISIBLE_P (f
)
22521 || FRAME_GARBAGED_P (f
)
22522 || vpos
>= w
->current_matrix
->nrows
22523 || hpos
>= w
->current_matrix
->matrix_w
)
22526 /* If cursor is off and we want it off, return quickly. */
22527 if (!on
&& !w
->phys_cursor_on_p
)
22530 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22531 /* If cursor row is not enabled, we don't really know where to
22532 display the cursor. */
22533 if (!glyph_row
->enabled_p
)
22535 w
->phys_cursor_on_p
= 0;
22540 if (!glyph_row
->exact_window_width_line_p
22541 || hpos
< glyph_row
->used
[TEXT_AREA
])
22542 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22544 xassert (interrupt_input_blocked
);
22546 /* Set new_cursor_type to the cursor we want to be displayed. */
22547 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22548 &new_cursor_width
, &active_cursor
);
22550 /* If cursor is currently being shown and we don't want it to be or
22551 it is in the wrong place, or the cursor type is not what we want,
22553 if (w
->phys_cursor_on_p
22555 || w
->phys_cursor
.x
!= x
22556 || w
->phys_cursor
.y
!= y
22557 || new_cursor_type
!= w
->phys_cursor_type
22558 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22559 && new_cursor_width
!= w
->phys_cursor_width
)))
22560 erase_phys_cursor (w
);
22562 /* Don't check phys_cursor_on_p here because that flag is only set
22563 to zero in some cases where we know that the cursor has been
22564 completely erased, to avoid the extra work of erasing the cursor
22565 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22566 still not be visible, or it has only been partly erased. */
22569 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22570 w
->phys_cursor_height
= glyph_row
->height
;
22572 /* Set phys_cursor_.* before x_draw_.* is called because some
22573 of them may need the information. */
22574 w
->phys_cursor
.x
= x
;
22575 w
->phys_cursor
.y
= glyph_row
->y
;
22576 w
->phys_cursor
.hpos
= hpos
;
22577 w
->phys_cursor
.vpos
= vpos
;
22580 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22581 new_cursor_type
, new_cursor_width
,
22582 on
, active_cursor
);
22586 /* Switch the display of W's cursor on or off, according to the value
22593 update_window_cursor (w
, on
)
22597 /* Don't update cursor in windows whose frame is in the process
22598 of being deleted. */
22599 if (w
->current_matrix
)
22602 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22603 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22609 /* Call update_window_cursor with parameter ON_P on all leaf windows
22610 in the window tree rooted at W. */
22613 update_cursor_in_window_tree (w
, on_p
)
22619 if (!NILP (w
->hchild
))
22620 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22621 else if (!NILP (w
->vchild
))
22622 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22624 update_window_cursor (w
, on_p
);
22626 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22632 Display the cursor on window W, or clear it, according to ON_P.
22633 Don't change the cursor's position. */
22636 x_update_cursor (f
, on_p
)
22640 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22645 Clear the cursor of window W to background color, and mark the
22646 cursor as not shown. This is used when the text where the cursor
22647 is is about to be rewritten. */
22653 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22654 update_window_cursor (w
, 0);
22659 Display the active region described by mouse_face_* according to DRAW. */
22662 show_mouse_face (dpyinfo
, draw
)
22663 Display_Info
*dpyinfo
;
22664 enum draw_glyphs_face draw
;
22666 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22667 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22669 if (/* If window is in the process of being destroyed, don't bother
22671 w
->current_matrix
!= NULL
22672 /* Don't update mouse highlight if hidden */
22673 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22674 /* Recognize when we are called to operate on rows that don't exist
22675 anymore. This can happen when a window is split. */
22676 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22678 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22679 struct glyph_row
*row
, *first
, *last
;
22681 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22682 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22684 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22686 int start_hpos
, end_hpos
, start_x
;
22688 /* For all but the first row, the highlight starts at column 0. */
22691 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22692 start_x
= dpyinfo
->mouse_face_beg_x
;
22701 end_hpos
= dpyinfo
->mouse_face_end_col
;
22704 end_hpos
= row
->used
[TEXT_AREA
];
22705 if (draw
== DRAW_NORMAL_TEXT
)
22706 row
->fill_line_p
= 1; /* Clear to end of line */
22709 if (end_hpos
> start_hpos
)
22711 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22712 start_hpos
, end_hpos
,
22716 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22720 /* When we've written over the cursor, arrange for it to
22721 be displayed again. */
22722 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22725 display_and_set_cursor (w
, 1,
22726 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22727 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22732 /* Change the mouse cursor. */
22733 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22734 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22735 else if (draw
== DRAW_MOUSE_FACE
)
22736 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22738 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22742 Clear out the mouse-highlighted active region.
22743 Redraw it un-highlighted first. Value is non-zero if mouse
22744 face was actually drawn unhighlighted. */
22747 clear_mouse_face (dpyinfo
)
22748 Display_Info
*dpyinfo
;
22752 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22754 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22758 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22759 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22760 dpyinfo
->mouse_face_window
= Qnil
;
22761 dpyinfo
->mouse_face_overlay
= Qnil
;
22767 Non-zero if physical cursor of window W is within mouse face. */
22770 cursor_in_mouse_face_p (w
)
22773 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22774 int in_mouse_face
= 0;
22776 if (WINDOWP (dpyinfo
->mouse_face_window
)
22777 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22779 int hpos
= w
->phys_cursor
.hpos
;
22780 int vpos
= w
->phys_cursor
.vpos
;
22782 if (vpos
>= dpyinfo
->mouse_face_beg_row
22783 && vpos
<= dpyinfo
->mouse_face_end_row
22784 && (vpos
> dpyinfo
->mouse_face_beg_row
22785 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22786 && (vpos
< dpyinfo
->mouse_face_end_row
22787 || hpos
< dpyinfo
->mouse_face_end_col
22788 || dpyinfo
->mouse_face_past_end
))
22792 return in_mouse_face
;
22798 /* Find the glyph matrix position of buffer position CHARPOS in window
22799 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
22800 current glyphs must be up to date. If CHARPOS is above window
22801 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22802 of last line in W. In the row containing CHARPOS, stop before glyphs
22803 having STOP as object. */
22805 #if 1 /* This is a version of fast_find_position that's more correct
22806 in the presence of hscrolling, for example. I didn't install
22807 it right away because the problem fixed is minor, it failed
22808 in 20.x as well, and I think it's too risky to install
22809 so near the release of 21.1. 2001-09-25 gerd. */
22813 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22816 int *hpos
, *vpos
, *x
, *y
;
22819 struct glyph_row
*row
, *first
;
22820 struct glyph
*glyph
, *end
;
22823 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22824 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22829 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22833 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22836 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22840 /* If whole rows or last part of a row came from a display overlay,
22841 row_containing_pos will skip over such rows because their end pos
22842 equals the start pos of the overlay or interval.
22844 Move back if we have a STOP object and previous row's
22845 end glyph came from STOP. */
22848 struct glyph_row
*prev
;
22849 while ((prev
= row
- 1, prev
>= first
)
22850 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22851 && prev
->used
[TEXT_AREA
] > 0)
22853 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22854 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22855 while (--glyph
>= beg
22856 && INTEGERP (glyph
->object
));
22858 || !EQ (stop
, glyph
->object
))
22866 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22868 glyph
= row
->glyphs
[TEXT_AREA
];
22869 end
= glyph
+ row
->used
[TEXT_AREA
];
22871 /* Skip over glyphs not having an object at the start of the row.
22872 These are special glyphs like truncation marks on terminal
22874 if (row
->displays_text_p
)
22876 && INTEGERP (glyph
->object
)
22877 && !EQ (stop
, glyph
->object
)
22878 && glyph
->charpos
< 0)
22880 *x
+= glyph
->pixel_width
;
22885 && !INTEGERP (glyph
->object
)
22886 && !EQ (stop
, glyph
->object
)
22887 && (!BUFFERP (glyph
->object
)
22888 || glyph
->charpos
< charpos
))
22890 *x
+= glyph
->pixel_width
;
22894 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22901 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22904 int *hpos
, *vpos
, *x
, *y
;
22909 int maybe_next_line_p
= 0;
22910 int line_start_position
;
22911 int yb
= window_text_bottom_y (w
);
22912 struct glyph_row
*row
, *best_row
;
22913 int row_vpos
, best_row_vpos
;
22916 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22917 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22919 while (row
->y
< yb
)
22921 if (row
->used
[TEXT_AREA
])
22922 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22924 line_start_position
= 0;
22926 if (line_start_position
> pos
)
22928 /* If the position sought is the end of the buffer,
22929 don't include the blank lines at the bottom of the window. */
22930 else if (line_start_position
== pos
22931 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22933 maybe_next_line_p
= 1;
22936 else if (line_start_position
> 0)
22939 best_row_vpos
= row_vpos
;
22942 if (row
->y
+ row
->height
>= yb
)
22949 /* Find the right column within BEST_ROW. */
22951 current_x
= best_row
->x
;
22952 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22954 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22955 int charpos
= glyph
->charpos
;
22957 if (BUFFERP (glyph
->object
))
22959 if (charpos
== pos
)
22962 *vpos
= best_row_vpos
;
22967 else if (charpos
> pos
)
22970 else if (EQ (glyph
->object
, stop
))
22975 current_x
+= glyph
->pixel_width
;
22978 /* If we're looking for the end of the buffer,
22979 and we didn't find it in the line we scanned,
22980 use the start of the following line. */
22981 if (maybe_next_line_p
)
22986 current_x
= best_row
->x
;
22989 *vpos
= best_row_vpos
;
22990 *hpos
= lastcol
+ 1;
22999 /* Find the position of the glyph for position POS in OBJECT in
23000 window W's current matrix, and return in *X, *Y the pixel
23001 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23003 RIGHT_P non-zero means return the position of the right edge of the
23004 glyph, RIGHT_P zero means return the left edge position.
23006 If no glyph for POS exists in the matrix, return the position of
23007 the glyph with the next smaller position that is in the matrix, if
23008 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23009 exists in the matrix, return the position of the glyph with the
23010 next larger position in OBJECT.
23012 Value is non-zero if a glyph was found. */
23015 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23018 Lisp_Object object
;
23019 int *hpos
, *vpos
, *x
, *y
;
23022 int yb
= window_text_bottom_y (w
);
23023 struct glyph_row
*r
;
23024 struct glyph
*best_glyph
= NULL
;
23025 struct glyph_row
*best_row
= NULL
;
23028 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23029 r
->enabled_p
&& r
->y
< yb
;
23032 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23033 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23036 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23037 if (EQ (g
->object
, object
))
23039 if (g
->charpos
== pos
)
23046 else if (best_glyph
== NULL
23047 || ((eabs (g
->charpos
- pos
)
23048 < eabs (best_glyph
->charpos
- pos
))
23051 : g
->charpos
> pos
)))
23065 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23069 *x
+= best_glyph
->pixel_width
;
23074 *vpos
= best_row
- w
->current_matrix
->rows
;
23077 return best_glyph
!= NULL
;
23081 /* See if position X, Y is within a hot-spot of an image. */
23084 on_hot_spot_p (hot_spot
, x
, y
)
23085 Lisp_Object hot_spot
;
23088 if (!CONSP (hot_spot
))
23091 if (EQ (XCAR (hot_spot
), Qrect
))
23093 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23094 Lisp_Object rect
= XCDR (hot_spot
);
23098 if (!CONSP (XCAR (rect
)))
23100 if (!CONSP (XCDR (rect
)))
23102 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23104 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23106 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23108 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23112 else if (EQ (XCAR (hot_spot
), Qcircle
))
23114 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23115 Lisp_Object circ
= XCDR (hot_spot
);
23116 Lisp_Object lr
, lx0
, ly0
;
23118 && CONSP (XCAR (circ
))
23119 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23120 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23121 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23123 double r
= XFLOATINT (lr
);
23124 double dx
= XINT (lx0
) - x
;
23125 double dy
= XINT (ly0
) - y
;
23126 return (dx
* dx
+ dy
* dy
<= r
* r
);
23129 else if (EQ (XCAR (hot_spot
), Qpoly
))
23131 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23132 if (VECTORP (XCDR (hot_spot
)))
23134 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23135 Lisp_Object
*poly
= v
->contents
;
23139 Lisp_Object lx
, ly
;
23142 /* Need an even number of coordinates, and at least 3 edges. */
23143 if (n
< 6 || n
& 1)
23146 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23147 If count is odd, we are inside polygon. Pixels on edges
23148 may or may not be included depending on actual geometry of the
23150 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23151 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23153 x0
= XINT (lx
), y0
= XINT (ly
);
23154 for (i
= 0; i
< n
; i
+= 2)
23156 int x1
= x0
, y1
= y0
;
23157 if ((lx
= poly
[i
], !INTEGERP (lx
))
23158 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23160 x0
= XINT (lx
), y0
= XINT (ly
);
23162 /* Does this segment cross the X line? */
23170 if (y
> y0
&& y
> y1
)
23172 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23182 find_hot_spot (map
, x
, y
)
23186 while (CONSP (map
))
23188 if (CONSP (XCAR (map
))
23189 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23197 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23199 doc
: /* Lookup in image map MAP coordinates X and Y.
23200 An image map is an alist where each element has the format (AREA ID PLIST).
23201 An AREA is specified as either a rectangle, a circle, or a polygon:
23202 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23203 pixel coordinates of the upper left and bottom right corners.
23204 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23205 and the radius of the circle; r may be a float or integer.
23206 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23207 vector describes one corner in the polygon.
23208 Returns the alist element for the first matching AREA in MAP. */)
23219 return find_hot_spot (map
, XINT (x
), XINT (y
));
23223 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23225 define_frame_cursor1 (f
, cursor
, pointer
)
23228 Lisp_Object pointer
;
23230 /* Do not change cursor shape while dragging mouse. */
23231 if (!NILP (do_mouse_tracking
))
23234 if (!NILP (pointer
))
23236 if (EQ (pointer
, Qarrow
))
23237 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23238 else if (EQ (pointer
, Qhand
))
23239 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23240 else if (EQ (pointer
, Qtext
))
23241 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23242 else if (EQ (pointer
, intern ("hdrag")))
23243 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23244 #ifdef HAVE_X_WINDOWS
23245 else if (EQ (pointer
, intern ("vdrag")))
23246 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23248 else if (EQ (pointer
, intern ("hourglass")))
23249 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23250 else if (EQ (pointer
, Qmodeline
))
23251 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23253 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23256 if (cursor
!= No_Cursor
)
23257 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23260 /* Take proper action when mouse has moved to the mode or header line
23261 or marginal area AREA of window W, x-position X and y-position Y.
23262 X is relative to the start of the text display area of W, so the
23263 width of bitmap areas and scroll bars must be subtracted to get a
23264 position relative to the start of the mode line. */
23267 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23268 Lisp_Object window
;
23270 enum window_part area
;
23272 struct window
*w
= XWINDOW (window
);
23273 struct frame
*f
= XFRAME (w
->frame
);
23274 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23275 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23276 Lisp_Object pointer
= Qnil
;
23277 int charpos
, dx
, dy
, width
, height
;
23278 Lisp_Object string
, object
= Qnil
;
23279 Lisp_Object pos
, help
;
23281 Lisp_Object mouse_face
;
23282 int original_x_pixel
= x
;
23283 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23284 struct glyph_row
*row
;
23286 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23291 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23292 &object
, &dx
, &dy
, &width
, &height
);
23294 row
= (area
== ON_MODE_LINE
23295 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23296 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23299 if (row
->mode_line_p
&& row
->enabled_p
)
23301 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23302 end
= glyph
+ row
->used
[TEXT_AREA
];
23304 for (x0
= original_x_pixel
;
23305 glyph
< end
&& x0
>= glyph
->pixel_width
;
23307 x0
-= glyph
->pixel_width
;
23315 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23316 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23317 &object
, &dx
, &dy
, &width
, &height
);
23322 if (IMAGEP (object
))
23324 Lisp_Object image_map
, hotspot
;
23325 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23327 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23329 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23331 Lisp_Object area_id
, plist
;
23333 area_id
= XCAR (hotspot
);
23334 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23335 If so, we could look for mouse-enter, mouse-leave
23336 properties in PLIST (and do something...). */
23337 hotspot
= XCDR (hotspot
);
23338 if (CONSP (hotspot
)
23339 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23341 pointer
= Fplist_get (plist
, Qpointer
);
23342 if (NILP (pointer
))
23344 help
= Fplist_get (plist
, Qhelp_echo
);
23347 help_echo_string
= help
;
23348 /* Is this correct? ++kfs */
23349 XSETWINDOW (help_echo_window
, w
);
23350 help_echo_object
= w
->buffer
;
23351 help_echo_pos
= charpos
;
23355 if (NILP (pointer
))
23356 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23359 if (STRINGP (string
))
23361 pos
= make_number (charpos
);
23362 /* If we're on a string with `help-echo' text property, arrange
23363 for the help to be displayed. This is done by setting the
23364 global variable help_echo_string to the help string. */
23367 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23370 help_echo_string
= help
;
23371 XSETWINDOW (help_echo_window
, w
);
23372 help_echo_object
= string
;
23373 help_echo_pos
= charpos
;
23377 if (NILP (pointer
))
23378 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23380 /* Change the mouse pointer according to what is under X/Y. */
23381 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23384 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23385 if (!KEYMAPP (map
))
23386 map
= Fget_text_property (pos
, Qkeymap
, string
);
23387 if (!KEYMAPP (map
))
23388 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23391 /* Change the mouse face according to what is under X/Y. */
23392 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23393 if (!NILP (mouse_face
)
23394 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23399 struct glyph
* tmp_glyph
;
23403 int total_pixel_width
;
23408 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23409 Qmouse_face
, string
, Qnil
);
23411 b
= make_number (0);
23413 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23415 e
= make_number (SCHARS (string
));
23417 /* Calculate the position(glyph position: GPOS) of GLYPH in
23418 displayed string. GPOS is different from CHARPOS.
23420 CHARPOS is the position of glyph in internal string
23421 object. A mode line string format has structures which
23422 is converted to a flatten by emacs lisp interpreter.
23423 The internal string is an element of the structures.
23424 The displayed string is the flatten string. */
23426 if (glyph
> row_start_glyph
)
23428 tmp_glyph
= glyph
- 1;
23429 while (tmp_glyph
>= row_start_glyph
23430 && tmp_glyph
->charpos
>= XINT (b
)
23431 && EQ (tmp_glyph
->object
, glyph
->object
))
23438 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23439 displayed string holding GLYPH.
23441 GSEQ_LENGTH is different from SCHARS (STRING).
23442 SCHARS (STRING) returns the length of the internal string. */
23443 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23444 tmp_glyph
->charpos
< XINT (e
);
23445 tmp_glyph
++, gseq_length
++)
23447 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23451 total_pixel_width
= 0;
23452 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23453 total_pixel_width
+= tmp_glyph
->pixel_width
;
23455 /* Pre calculation of re-rendering position */
23457 hpos
= (area
== ON_MODE_LINE
23458 ? (w
->current_matrix
)->nrows
- 1
23461 /* If the re-rendering position is included in the last
23462 re-rendering area, we should do nothing. */
23463 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23464 && dpyinfo
->mouse_face_beg_col
<= vpos
23465 && vpos
< dpyinfo
->mouse_face_end_col
23466 && dpyinfo
->mouse_face_beg_row
== hpos
)
23469 if (clear_mouse_face (dpyinfo
))
23470 cursor
= No_Cursor
;
23472 dpyinfo
->mouse_face_beg_col
= vpos
;
23473 dpyinfo
->mouse_face_beg_row
= hpos
;
23475 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23476 dpyinfo
->mouse_face_beg_y
= 0;
23478 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23479 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23481 dpyinfo
->mouse_face_end_x
= 0;
23482 dpyinfo
->mouse_face_end_y
= 0;
23484 dpyinfo
->mouse_face_past_end
= 0;
23485 dpyinfo
->mouse_face_window
= window
;
23487 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23490 glyph
->face_id
, 1);
23491 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23493 if (NILP (pointer
))
23496 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23497 clear_mouse_face (dpyinfo
);
23499 define_frame_cursor1 (f
, cursor
, pointer
);
23504 Take proper action when the mouse has moved to position X, Y on
23505 frame F as regards highlighting characters that have mouse-face
23506 properties. Also de-highlighting chars where the mouse was before.
23507 X and Y can be negative or out of range. */
23510 note_mouse_highlight (f
, x
, y
)
23514 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23515 enum window_part part
;
23516 Lisp_Object window
;
23518 Cursor cursor
= No_Cursor
;
23519 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23522 /* When a menu is active, don't highlight because this looks odd. */
23523 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
23524 if (popup_activated ())
23528 if (NILP (Vmouse_highlight
)
23529 || !f
->glyphs_initialized_p
)
23532 dpyinfo
->mouse_face_mouse_x
= x
;
23533 dpyinfo
->mouse_face_mouse_y
= y
;
23534 dpyinfo
->mouse_face_mouse_frame
= f
;
23536 if (dpyinfo
->mouse_face_defer
)
23539 if (gc_in_progress
)
23541 dpyinfo
->mouse_face_deferred_gc
= 1;
23545 /* Which window is that in? */
23546 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23548 /* If we were displaying active text in another window, clear that.
23549 Also clear if we move out of text area in same window. */
23550 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23551 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23552 && !NILP (dpyinfo
->mouse_face_window
)))
23553 clear_mouse_face (dpyinfo
);
23555 /* Not on a window -> return. */
23556 if (!WINDOWP (window
))
23559 /* Reset help_echo_string. It will get recomputed below. */
23560 help_echo_string
= Qnil
;
23562 /* Convert to window-relative pixel coordinates. */
23563 w
= XWINDOW (window
);
23564 frame_to_window_pixel_xy (w
, &x
, &y
);
23566 /* Handle tool-bar window differently since it doesn't display a
23568 if (EQ (window
, f
->tool_bar_window
))
23570 note_tool_bar_highlight (f
, x
, y
);
23574 /* Mouse is on the mode, header line or margin? */
23575 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23576 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23578 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23582 if (part
== ON_VERTICAL_BORDER
)
23584 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23585 help_echo_string
= build_string ("drag-mouse-1: resize");
23587 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23588 || part
== ON_SCROLL_BAR
)
23589 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23591 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23593 /* Are we in a window whose display is up to date?
23594 And verify the buffer's text has not changed. */
23595 b
= XBUFFER (w
->buffer
);
23596 if (part
== ON_TEXT
23597 && EQ (w
->window_end_valid
, w
->buffer
)
23598 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23599 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23601 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23602 struct glyph
*glyph
;
23603 Lisp_Object object
;
23604 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23605 Lisp_Object
*overlay_vec
= NULL
;
23607 struct buffer
*obuf
;
23608 int obegv
, ozv
, same_region
;
23610 /* Find the glyph under X/Y. */
23611 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23613 /* Look for :pointer property on image. */
23614 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23616 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23617 if (img
!= NULL
&& IMAGEP (img
->spec
))
23619 Lisp_Object image_map
, hotspot
;
23620 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23622 && (hotspot
= find_hot_spot (image_map
,
23623 glyph
->slice
.x
+ dx
,
23624 glyph
->slice
.y
+ dy
),
23626 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23628 Lisp_Object area_id
, plist
;
23630 area_id
= XCAR (hotspot
);
23631 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23632 If so, we could look for mouse-enter, mouse-leave
23633 properties in PLIST (and do something...). */
23634 hotspot
= XCDR (hotspot
);
23635 if (CONSP (hotspot
)
23636 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23638 pointer
= Fplist_get (plist
, Qpointer
);
23639 if (NILP (pointer
))
23641 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23642 if (!NILP (help_echo_string
))
23644 help_echo_window
= window
;
23645 help_echo_object
= glyph
->object
;
23646 help_echo_pos
= glyph
->charpos
;
23650 if (NILP (pointer
))
23651 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23655 /* Clear mouse face if X/Y not over text. */
23657 || area
!= TEXT_AREA
23658 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23660 if (clear_mouse_face (dpyinfo
))
23661 cursor
= No_Cursor
;
23662 if (NILP (pointer
))
23664 if (area
!= TEXT_AREA
)
23665 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23667 pointer
= Vvoid_text_area_pointer
;
23672 pos
= glyph
->charpos
;
23673 object
= glyph
->object
;
23674 if (!STRINGP (object
) && !BUFFERP (object
))
23677 /* If we get an out-of-range value, return now; avoid an error. */
23678 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23681 /* Make the window's buffer temporarily current for
23682 overlays_at and compute_char_face. */
23683 obuf
= current_buffer
;
23684 current_buffer
= b
;
23690 /* Is this char mouse-active or does it have help-echo? */
23691 position
= make_number (pos
);
23693 if (BUFFERP (object
))
23695 /* Put all the overlays we want in a vector in overlay_vec. */
23696 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23697 /* Sort overlays into increasing priority order. */
23698 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23703 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23704 && vpos
>= dpyinfo
->mouse_face_beg_row
23705 && vpos
<= dpyinfo
->mouse_face_end_row
23706 && (vpos
> dpyinfo
->mouse_face_beg_row
23707 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23708 && (vpos
< dpyinfo
->mouse_face_end_row
23709 || hpos
< dpyinfo
->mouse_face_end_col
23710 || dpyinfo
->mouse_face_past_end
));
23713 cursor
= No_Cursor
;
23715 /* Check mouse-face highlighting. */
23717 /* If there exists an overlay with mouse-face overlapping
23718 the one we are currently highlighting, we have to
23719 check if we enter the overlapping overlay, and then
23720 highlight only that. */
23721 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23722 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23724 /* Find the highest priority overlay that has a mouse-face
23727 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23729 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23730 if (!NILP (mouse_face
))
23731 overlay
= overlay_vec
[i
];
23734 /* If we're actually highlighting the same overlay as
23735 before, there's no need to do that again. */
23736 if (!NILP (overlay
)
23737 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23738 goto check_help_echo
;
23740 dpyinfo
->mouse_face_overlay
= overlay
;
23742 /* Clear the display of the old active region, if any. */
23743 if (clear_mouse_face (dpyinfo
))
23744 cursor
= No_Cursor
;
23746 /* If no overlay applies, get a text property. */
23747 if (NILP (overlay
))
23748 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23750 /* Handle the overlay case. */
23751 if (!NILP (overlay
))
23753 /* Find the range of text around this char that
23754 should be active. */
23755 Lisp_Object before
, after
;
23758 before
= Foverlay_start (overlay
);
23759 after
= Foverlay_end (overlay
);
23760 /* Record this as the current active region. */
23761 fast_find_position (w
, XFASTINT (before
),
23762 &dpyinfo
->mouse_face_beg_col
,
23763 &dpyinfo
->mouse_face_beg_row
,
23764 &dpyinfo
->mouse_face_beg_x
,
23765 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23767 dpyinfo
->mouse_face_past_end
23768 = !fast_find_position (w
, XFASTINT (after
),
23769 &dpyinfo
->mouse_face_end_col
,
23770 &dpyinfo
->mouse_face_end_row
,
23771 &dpyinfo
->mouse_face_end_x
,
23772 &dpyinfo
->mouse_face_end_y
, Qnil
);
23773 dpyinfo
->mouse_face_window
= window
;
23775 dpyinfo
->mouse_face_face_id
23776 = face_at_buffer_position (w
, pos
, 0, 0,
23778 !dpyinfo
->mouse_face_hidden
);
23780 /* Display it as active. */
23781 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23782 cursor
= No_Cursor
;
23784 /* Handle the text property case. */
23785 else if (!NILP (mouse_face
) && BUFFERP (object
))
23787 /* Find the range of text around this char that
23788 should be active. */
23789 Lisp_Object before
, after
, beginning
, end
;
23792 beginning
= Fmarker_position (w
->start
);
23793 end
= make_number (BUF_Z (XBUFFER (object
))
23794 - XFASTINT (w
->window_end_pos
));
23796 = Fprevious_single_property_change (make_number (pos
+ 1),
23798 object
, beginning
);
23800 = Fnext_single_property_change (position
, Qmouse_face
,
23803 /* Record this as the current active region. */
23804 fast_find_position (w
, XFASTINT (before
),
23805 &dpyinfo
->mouse_face_beg_col
,
23806 &dpyinfo
->mouse_face_beg_row
,
23807 &dpyinfo
->mouse_face_beg_x
,
23808 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23809 dpyinfo
->mouse_face_past_end
23810 = !fast_find_position (w
, XFASTINT (after
),
23811 &dpyinfo
->mouse_face_end_col
,
23812 &dpyinfo
->mouse_face_end_row
,
23813 &dpyinfo
->mouse_face_end_x
,
23814 &dpyinfo
->mouse_face_end_y
, Qnil
);
23815 dpyinfo
->mouse_face_window
= window
;
23817 if (BUFFERP (object
))
23818 dpyinfo
->mouse_face_face_id
23819 = face_at_buffer_position (w
, pos
, 0, 0,
23821 !dpyinfo
->mouse_face_hidden
);
23823 /* Display it as active. */
23824 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23825 cursor
= No_Cursor
;
23827 else if (!NILP (mouse_face
) && STRINGP (object
))
23832 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23835 e
= Fnext_single_property_change (position
, Qmouse_face
,
23838 b
= make_number (0);
23840 e
= make_number (SCHARS (object
) - 1);
23842 fast_find_string_pos (w
, XINT (b
), object
,
23843 &dpyinfo
->mouse_face_beg_col
,
23844 &dpyinfo
->mouse_face_beg_row
,
23845 &dpyinfo
->mouse_face_beg_x
,
23846 &dpyinfo
->mouse_face_beg_y
, 0);
23847 fast_find_string_pos (w
, XINT (e
), object
,
23848 &dpyinfo
->mouse_face_end_col
,
23849 &dpyinfo
->mouse_face_end_row
,
23850 &dpyinfo
->mouse_face_end_x
,
23851 &dpyinfo
->mouse_face_end_y
, 1);
23852 dpyinfo
->mouse_face_past_end
= 0;
23853 dpyinfo
->mouse_face_window
= window
;
23854 dpyinfo
->mouse_face_face_id
23855 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23856 glyph
->face_id
, 1);
23857 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23858 cursor
= No_Cursor
;
23860 else if (STRINGP (object
) && NILP (mouse_face
))
23862 /* A string which doesn't have mouse-face, but
23863 the text ``under'' it might have. */
23864 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23865 int start
= MATRIX_ROW_START_CHARPOS (r
);
23867 pos
= string_buffer_position (w
, object
, start
);
23869 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23873 if (!NILP (mouse_face
) && !NILP (overlay
))
23875 Lisp_Object before
= Foverlay_start (overlay
);
23876 Lisp_Object after
= Foverlay_end (overlay
);
23879 /* Note that we might not be able to find position
23880 BEFORE in the glyph matrix if the overlay is
23881 entirely covered by a `display' property. In
23882 this case, we overshoot. So let's stop in
23883 the glyph matrix before glyphs for OBJECT. */
23884 fast_find_position (w
, XFASTINT (before
),
23885 &dpyinfo
->mouse_face_beg_col
,
23886 &dpyinfo
->mouse_face_beg_row
,
23887 &dpyinfo
->mouse_face_beg_x
,
23888 &dpyinfo
->mouse_face_beg_y
,
23891 dpyinfo
->mouse_face_past_end
23892 = !fast_find_position (w
, XFASTINT (after
),
23893 &dpyinfo
->mouse_face_end_col
,
23894 &dpyinfo
->mouse_face_end_row
,
23895 &dpyinfo
->mouse_face_end_x
,
23896 &dpyinfo
->mouse_face_end_y
,
23898 dpyinfo
->mouse_face_window
= window
;
23899 dpyinfo
->mouse_face_face_id
23900 = face_at_buffer_position (w
, pos
, 0, 0,
23902 !dpyinfo
->mouse_face_hidden
);
23904 /* Display it as active. */
23905 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23906 cursor
= No_Cursor
;
23913 /* Look for a `help-echo' property. */
23914 if (NILP (help_echo_string
)) {
23915 Lisp_Object help
, overlay
;
23917 /* Check overlays first. */
23918 help
= overlay
= Qnil
;
23919 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23921 overlay
= overlay_vec
[i
];
23922 help
= Foverlay_get (overlay
, Qhelp_echo
);
23927 help_echo_string
= help
;
23928 help_echo_window
= window
;
23929 help_echo_object
= overlay
;
23930 help_echo_pos
= pos
;
23934 Lisp_Object object
= glyph
->object
;
23935 int charpos
= glyph
->charpos
;
23937 /* Try text properties. */
23938 if (STRINGP (object
)
23940 && charpos
< SCHARS (object
))
23942 help
= Fget_text_property (make_number (charpos
),
23943 Qhelp_echo
, object
);
23946 /* If the string itself doesn't specify a help-echo,
23947 see if the buffer text ``under'' it does. */
23948 struct glyph_row
*r
23949 = MATRIX_ROW (w
->current_matrix
, vpos
);
23950 int start
= MATRIX_ROW_START_CHARPOS (r
);
23951 int pos
= string_buffer_position (w
, object
, start
);
23954 help
= Fget_char_property (make_number (pos
),
23955 Qhelp_echo
, w
->buffer
);
23959 object
= w
->buffer
;
23964 else if (BUFFERP (object
)
23967 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23972 help_echo_string
= help
;
23973 help_echo_window
= window
;
23974 help_echo_object
= object
;
23975 help_echo_pos
= charpos
;
23980 /* Look for a `pointer' property. */
23981 if (NILP (pointer
))
23983 /* Check overlays first. */
23984 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23985 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23987 if (NILP (pointer
))
23989 Lisp_Object object
= glyph
->object
;
23990 int charpos
= glyph
->charpos
;
23992 /* Try text properties. */
23993 if (STRINGP (object
)
23995 && charpos
< SCHARS (object
))
23997 pointer
= Fget_text_property (make_number (charpos
),
23999 if (NILP (pointer
))
24001 /* If the string itself doesn't specify a pointer,
24002 see if the buffer text ``under'' it does. */
24003 struct glyph_row
*r
24004 = MATRIX_ROW (w
->current_matrix
, vpos
);
24005 int start
= MATRIX_ROW_START_CHARPOS (r
);
24006 int pos
= string_buffer_position (w
, object
, start
);
24008 pointer
= Fget_char_property (make_number (pos
),
24009 Qpointer
, w
->buffer
);
24012 else if (BUFFERP (object
)
24015 pointer
= Fget_text_property (make_number (charpos
),
24022 current_buffer
= obuf
;
24027 define_frame_cursor1 (f
, cursor
, pointer
);
24032 Clear any mouse-face on window W. This function is part of the
24033 redisplay interface, and is called from try_window_id and similar
24034 functions to ensure the mouse-highlight is off. */
24037 x_clear_window_mouse_face (w
)
24040 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24041 Lisp_Object window
;
24044 XSETWINDOW (window
, w
);
24045 if (EQ (window
, dpyinfo
->mouse_face_window
))
24046 clear_mouse_face (dpyinfo
);
24052 Just discard the mouse face information for frame F, if any.
24053 This is used when the size of F is changed. */
24056 cancel_mouse_face (f
)
24059 Lisp_Object window
;
24060 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24062 window
= dpyinfo
->mouse_face_window
;
24063 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24065 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24066 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24067 dpyinfo
->mouse_face_window
= Qnil
;
24072 #endif /* HAVE_WINDOW_SYSTEM */
24075 /***********************************************************************
24077 ***********************************************************************/
24079 #ifdef HAVE_WINDOW_SYSTEM
24081 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24082 which intersects rectangle R. R is in window-relative coordinates. */
24085 expose_area (w
, row
, r
, area
)
24087 struct glyph_row
*row
;
24089 enum glyph_row_area area
;
24091 struct glyph
*first
= row
->glyphs
[area
];
24092 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24093 struct glyph
*last
;
24094 int first_x
, start_x
, x
;
24096 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24097 /* If row extends face to end of line write the whole line. */
24098 draw_glyphs (w
, 0, row
, area
,
24099 0, row
->used
[area
],
24100 DRAW_NORMAL_TEXT
, 0);
24103 /* Set START_X to the window-relative start position for drawing glyphs of
24104 AREA. The first glyph of the text area can be partially visible.
24105 The first glyphs of other areas cannot. */
24106 start_x
= window_box_left_offset (w
, area
);
24108 if (area
== TEXT_AREA
)
24111 /* Find the first glyph that must be redrawn. */
24113 && x
+ first
->pixel_width
< r
->x
)
24115 x
+= first
->pixel_width
;
24119 /* Find the last one. */
24123 && x
< r
->x
+ r
->width
)
24125 x
+= last
->pixel_width
;
24131 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24132 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24133 DRAW_NORMAL_TEXT
, 0);
24138 /* Redraw the parts of the glyph row ROW on window W intersecting
24139 rectangle R. R is in window-relative coordinates. Value is
24140 non-zero if mouse-face was overwritten. */
24143 expose_line (w
, row
, r
)
24145 struct glyph_row
*row
;
24148 xassert (row
->enabled_p
);
24150 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24151 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24152 0, row
->used
[TEXT_AREA
],
24153 DRAW_NORMAL_TEXT
, 0);
24156 if (row
->used
[LEFT_MARGIN_AREA
])
24157 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24158 if (row
->used
[TEXT_AREA
])
24159 expose_area (w
, row
, r
, TEXT_AREA
);
24160 if (row
->used
[RIGHT_MARGIN_AREA
])
24161 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24162 draw_row_fringe_bitmaps (w
, row
);
24165 return row
->mouse_face_p
;
24169 /* Redraw those parts of glyphs rows during expose event handling that
24170 overlap other rows. Redrawing of an exposed line writes over parts
24171 of lines overlapping that exposed line; this function fixes that.
24173 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24174 row in W's current matrix that is exposed and overlaps other rows.
24175 LAST_OVERLAPPING_ROW is the last such row. */
24178 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24180 struct glyph_row
*first_overlapping_row
;
24181 struct glyph_row
*last_overlapping_row
;
24184 struct glyph_row
*row
;
24186 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24187 if (row
->overlapping_p
)
24189 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24192 if (row
->used
[LEFT_MARGIN_AREA
])
24193 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24195 if (row
->used
[TEXT_AREA
])
24196 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24198 if (row
->used
[RIGHT_MARGIN_AREA
])
24199 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24205 /* Return non-zero if W's cursor intersects rectangle R. */
24208 phys_cursor_in_rect_p (w
, r
)
24212 XRectangle cr
, result
;
24213 struct glyph
*cursor_glyph
;
24214 struct glyph_row
*row
;
24216 if (w
->phys_cursor
.vpos
>= 0
24217 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24218 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24220 && row
->cursor_in_fringe_p
)
24222 /* Cursor is in the fringe. */
24223 cr
.x
= window_box_right_offset (w
,
24224 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24225 ? RIGHT_MARGIN_AREA
24228 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24229 cr
.height
= row
->height
;
24230 return x_intersect_rectangles (&cr
, r
, &result
);
24233 cursor_glyph
= get_phys_cursor_glyph (w
);
24236 /* r is relative to W's box, but w->phys_cursor.x is relative
24237 to left edge of W's TEXT area. Adjust it. */
24238 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24239 cr
.y
= w
->phys_cursor
.y
;
24240 cr
.width
= cursor_glyph
->pixel_width
;
24241 cr
.height
= w
->phys_cursor_height
;
24242 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24243 I assume the effect is the same -- and this is portable. */
24244 return x_intersect_rectangles (&cr
, r
, &result
);
24246 /* If we don't understand the format, pretend we're not in the hot-spot. */
24252 Draw a vertical window border to the right of window W if W doesn't
24253 have vertical scroll bars. */
24256 x_draw_vertical_border (w
)
24259 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24261 /* We could do better, if we knew what type of scroll-bar the adjacent
24262 windows (on either side) have... But we don't :-(
24263 However, I think this works ok. ++KFS 2003-04-25 */
24265 /* Redraw borders between horizontally adjacent windows. Don't
24266 do it for frames with vertical scroll bars because either the
24267 right scroll bar of a window, or the left scroll bar of its
24268 neighbor will suffice as a border. */
24269 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24272 if (!WINDOW_RIGHTMOST_P (w
)
24273 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24275 int x0
, x1
, y0
, y1
;
24277 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24280 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24283 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24285 else if (!WINDOW_LEFTMOST_P (w
)
24286 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24288 int x0
, x1
, y0
, y1
;
24290 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24293 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24296 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24301 /* Redraw the part of window W intersection rectangle FR. Pixel
24302 coordinates in FR are frame-relative. Call this function with
24303 input blocked. Value is non-zero if the exposure overwrites
24307 expose_window (w
, fr
)
24311 struct frame
*f
= XFRAME (w
->frame
);
24313 int mouse_face_overwritten_p
= 0;
24315 /* If window is not yet fully initialized, do nothing. This can
24316 happen when toolkit scroll bars are used and a window is split.
24317 Reconfiguring the scroll bar will generate an expose for a newly
24319 if (w
->current_matrix
== NULL
)
24322 /* When we're currently updating the window, display and current
24323 matrix usually don't agree. Arrange for a thorough display
24325 if (w
== updated_window
)
24327 SET_FRAME_GARBAGED (f
);
24331 /* Frame-relative pixel rectangle of W. */
24332 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24333 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24334 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24335 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24337 if (x_intersect_rectangles (fr
, &wr
, &r
))
24339 int yb
= window_text_bottom_y (w
);
24340 struct glyph_row
*row
;
24341 int cursor_cleared_p
;
24342 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24344 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24345 r
.x
, r
.y
, r
.width
, r
.height
));
24347 /* Convert to window coordinates. */
24348 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24349 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24351 /* Turn off the cursor. */
24352 if (!w
->pseudo_window_p
24353 && phys_cursor_in_rect_p (w
, &r
))
24355 x_clear_cursor (w
);
24356 cursor_cleared_p
= 1;
24359 cursor_cleared_p
= 0;
24361 /* Update lines intersecting rectangle R. */
24362 first_overlapping_row
= last_overlapping_row
= NULL
;
24363 for (row
= w
->current_matrix
->rows
;
24368 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24370 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24371 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24372 || (r
.y
>= y0
&& r
.y
< y1
)
24373 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24375 /* A header line may be overlapping, but there is no need
24376 to fix overlapping areas for them. KFS 2005-02-12 */
24377 if (row
->overlapping_p
&& !row
->mode_line_p
)
24379 if (first_overlapping_row
== NULL
)
24380 first_overlapping_row
= row
;
24381 last_overlapping_row
= row
;
24385 if (expose_line (w
, row
, &r
))
24386 mouse_face_overwritten_p
= 1;
24389 else if (row
->overlapping_p
)
24391 /* We must redraw a row overlapping the exposed area. */
24393 ? y0
+ row
->phys_height
> r
.y
24394 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24396 if (first_overlapping_row
== NULL
)
24397 first_overlapping_row
= row
;
24398 last_overlapping_row
= row
;
24406 /* Display the mode line if there is one. */
24407 if (WINDOW_WANTS_MODELINE_P (w
)
24408 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24410 && row
->y
< r
.y
+ r
.height
)
24412 if (expose_line (w
, row
, &r
))
24413 mouse_face_overwritten_p
= 1;
24416 if (!w
->pseudo_window_p
)
24418 /* Fix the display of overlapping rows. */
24419 if (first_overlapping_row
)
24420 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24423 /* Draw border between windows. */
24424 x_draw_vertical_border (w
);
24426 /* Turn the cursor on again. */
24427 if (cursor_cleared_p
)
24428 update_window_cursor (w
, 1);
24432 return mouse_face_overwritten_p
;
24437 /* Redraw (parts) of all windows in the window tree rooted at W that
24438 intersect R. R contains frame pixel coordinates. Value is
24439 non-zero if the exposure overwrites mouse-face. */
24442 expose_window_tree (w
, r
)
24446 struct frame
*f
= XFRAME (w
->frame
);
24447 int mouse_face_overwritten_p
= 0;
24449 while (w
&& !FRAME_GARBAGED_P (f
))
24451 if (!NILP (w
->hchild
))
24452 mouse_face_overwritten_p
24453 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24454 else if (!NILP (w
->vchild
))
24455 mouse_face_overwritten_p
24456 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24458 mouse_face_overwritten_p
|= expose_window (w
, r
);
24460 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24463 return mouse_face_overwritten_p
;
24468 Redisplay an exposed area of frame F. X and Y are the upper-left
24469 corner of the exposed rectangle. W and H are width and height of
24470 the exposed area. All are pixel values. W or H zero means redraw
24471 the entire frame. */
24474 expose_frame (f
, x
, y
, w
, h
)
24479 int mouse_face_overwritten_p
= 0;
24481 TRACE ((stderr
, "expose_frame "));
24483 /* No need to redraw if frame will be redrawn soon. */
24484 if (FRAME_GARBAGED_P (f
))
24486 TRACE ((stderr
, " garbaged\n"));
24490 /* If basic faces haven't been realized yet, there is no point in
24491 trying to redraw anything. This can happen when we get an expose
24492 event while Emacs is starting, e.g. by moving another window. */
24493 if (FRAME_FACE_CACHE (f
) == NULL
24494 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24496 TRACE ((stderr
, " no faces\n"));
24500 if (w
== 0 || h
== 0)
24503 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24504 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24514 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24515 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24517 if (WINDOWP (f
->tool_bar_window
))
24518 mouse_face_overwritten_p
24519 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24521 #ifdef HAVE_X_WINDOWS
24523 #ifndef USE_X_TOOLKIT
24524 if (WINDOWP (f
->menu_bar_window
))
24525 mouse_face_overwritten_p
24526 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24527 #endif /* not USE_X_TOOLKIT */
24531 /* Some window managers support a focus-follows-mouse style with
24532 delayed raising of frames. Imagine a partially obscured frame,
24533 and moving the mouse into partially obscured mouse-face on that
24534 frame. The visible part of the mouse-face will be highlighted,
24535 then the WM raises the obscured frame. With at least one WM, KDE
24536 2.1, Emacs is not getting any event for the raising of the frame
24537 (even tried with SubstructureRedirectMask), only Expose events.
24538 These expose events will draw text normally, i.e. not
24539 highlighted. Which means we must redo the highlight here.
24540 Subsume it under ``we love X''. --gerd 2001-08-15 */
24541 /* Included in Windows version because Windows most likely does not
24542 do the right thing if any third party tool offers
24543 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24544 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24546 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24547 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24549 int x
= dpyinfo
->mouse_face_mouse_x
;
24550 int y
= dpyinfo
->mouse_face_mouse_y
;
24551 clear_mouse_face (dpyinfo
);
24552 note_mouse_highlight (f
, x
, y
);
24559 Determine the intersection of two rectangles R1 and R2. Return
24560 the intersection in *RESULT. Value is non-zero if RESULT is not
24564 x_intersect_rectangles (r1
, r2
, result
)
24565 XRectangle
*r1
, *r2
, *result
;
24567 XRectangle
*left
, *right
;
24568 XRectangle
*upper
, *lower
;
24569 int intersection_p
= 0;
24571 /* Rearrange so that R1 is the left-most rectangle. */
24573 left
= r1
, right
= r2
;
24575 left
= r2
, right
= r1
;
24577 /* X0 of the intersection is right.x0, if this is inside R1,
24578 otherwise there is no intersection. */
24579 if (right
->x
<= left
->x
+ left
->width
)
24581 result
->x
= right
->x
;
24583 /* The right end of the intersection is the minimum of the
24584 the right ends of left and right. */
24585 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24588 /* Same game for Y. */
24590 upper
= r1
, lower
= r2
;
24592 upper
= r2
, lower
= r1
;
24594 /* The upper end of the intersection is lower.y0, if this is inside
24595 of upper. Otherwise, there is no intersection. */
24596 if (lower
->y
<= upper
->y
+ upper
->height
)
24598 result
->y
= lower
->y
;
24600 /* The lower end of the intersection is the minimum of the lower
24601 ends of upper and lower. */
24602 result
->height
= (min (lower
->y
+ lower
->height
,
24603 upper
->y
+ upper
->height
)
24605 intersection_p
= 1;
24609 return intersection_p
;
24612 #endif /* HAVE_WINDOW_SYSTEM */
24615 /***********************************************************************
24617 ***********************************************************************/
24622 Vwith_echo_area_save_vector
= Qnil
;
24623 staticpro (&Vwith_echo_area_save_vector
);
24625 Vmessage_stack
= Qnil
;
24626 staticpro (&Vmessage_stack
);
24628 Qinhibit_redisplay
= intern ("inhibit-redisplay");
24629 staticpro (&Qinhibit_redisplay
);
24631 message_dolog_marker1
= Fmake_marker ();
24632 staticpro (&message_dolog_marker1
);
24633 message_dolog_marker2
= Fmake_marker ();
24634 staticpro (&message_dolog_marker2
);
24635 message_dolog_marker3
= Fmake_marker ();
24636 staticpro (&message_dolog_marker3
);
24639 defsubr (&Sdump_frame_glyph_matrix
);
24640 defsubr (&Sdump_glyph_matrix
);
24641 defsubr (&Sdump_glyph_row
);
24642 defsubr (&Sdump_tool_bar_row
);
24643 defsubr (&Strace_redisplay
);
24644 defsubr (&Strace_to_stderr
);
24646 #ifdef HAVE_WINDOW_SYSTEM
24647 defsubr (&Stool_bar_lines_needed
);
24648 defsubr (&Slookup_image_map
);
24650 defsubr (&Sformat_mode_line
);
24651 defsubr (&Sinvisible_p
);
24653 staticpro (&Qmenu_bar_update_hook
);
24654 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
24656 staticpro (&Qoverriding_terminal_local_map
);
24657 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
24659 staticpro (&Qoverriding_local_map
);
24660 Qoverriding_local_map
= intern ("overriding-local-map");
24662 staticpro (&Qwindow_scroll_functions
);
24663 Qwindow_scroll_functions
= intern ("window-scroll-functions");
24665 staticpro (&Qwindow_text_change_functions
);
24666 Qwindow_text_change_functions
= intern ("window-text-change-functions");
24668 staticpro (&Qredisplay_end_trigger_functions
);
24669 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
24671 staticpro (&Qinhibit_point_motion_hooks
);
24672 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
24674 Qeval
= intern ("eval");
24675 staticpro (&Qeval
);
24677 QCdata
= intern (":data");
24678 staticpro (&QCdata
);
24679 Qdisplay
= intern ("display");
24680 staticpro (&Qdisplay
);
24681 Qspace_width
= intern ("space-width");
24682 staticpro (&Qspace_width
);
24683 Qraise
= intern ("raise");
24684 staticpro (&Qraise
);
24685 Qslice
= intern ("slice");
24686 staticpro (&Qslice
);
24687 Qspace
= intern ("space");
24688 staticpro (&Qspace
);
24689 Qmargin
= intern ("margin");
24690 staticpro (&Qmargin
);
24691 Qpointer
= intern ("pointer");
24692 staticpro (&Qpointer
);
24693 Qleft_margin
= intern ("left-margin");
24694 staticpro (&Qleft_margin
);
24695 Qright_margin
= intern ("right-margin");
24696 staticpro (&Qright_margin
);
24697 Qcenter
= intern ("center");
24698 staticpro (&Qcenter
);
24699 Qline_height
= intern ("line-height");
24700 staticpro (&Qline_height
);
24701 QCalign_to
= intern (":align-to");
24702 staticpro (&QCalign_to
);
24703 QCrelative_width
= intern (":relative-width");
24704 staticpro (&QCrelative_width
);
24705 QCrelative_height
= intern (":relative-height");
24706 staticpro (&QCrelative_height
);
24707 QCeval
= intern (":eval");
24708 staticpro (&QCeval
);
24709 QCpropertize
= intern (":propertize");
24710 staticpro (&QCpropertize
);
24711 QCfile
= intern (":file");
24712 staticpro (&QCfile
);
24713 Qfontified
= intern ("fontified");
24714 staticpro (&Qfontified
);
24715 Qfontification_functions
= intern ("fontification-functions");
24716 staticpro (&Qfontification_functions
);
24717 Qtrailing_whitespace
= intern ("trailing-whitespace");
24718 staticpro (&Qtrailing_whitespace
);
24719 Qescape_glyph
= intern ("escape-glyph");
24720 staticpro (&Qescape_glyph
);
24721 Qnobreak_space
= intern ("nobreak-space");
24722 staticpro (&Qnobreak_space
);
24723 Qimage
= intern ("image");
24724 staticpro (&Qimage
);
24725 QCmap
= intern (":map");
24726 staticpro (&QCmap
);
24727 QCpointer
= intern (":pointer");
24728 staticpro (&QCpointer
);
24729 Qrect
= intern ("rect");
24730 staticpro (&Qrect
);
24731 Qcircle
= intern ("circle");
24732 staticpro (&Qcircle
);
24733 Qpoly
= intern ("poly");
24734 staticpro (&Qpoly
);
24735 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24736 staticpro (&Qmessage_truncate_lines
);
24737 Qgrow_only
= intern ("grow-only");
24738 staticpro (&Qgrow_only
);
24739 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24740 staticpro (&Qinhibit_menubar_update
);
24741 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24742 staticpro (&Qinhibit_eval_during_redisplay
);
24743 Qposition
= intern ("position");
24744 staticpro (&Qposition
);
24745 Qbuffer_position
= intern ("buffer-position");
24746 staticpro (&Qbuffer_position
);
24747 Qobject
= intern ("object");
24748 staticpro (&Qobject
);
24749 Qbar
= intern ("bar");
24751 Qhbar
= intern ("hbar");
24752 staticpro (&Qhbar
);
24753 Qbox
= intern ("box");
24755 Qhollow
= intern ("hollow");
24756 staticpro (&Qhollow
);
24757 Qhand
= intern ("hand");
24758 staticpro (&Qhand
);
24759 Qarrow
= intern ("arrow");
24760 staticpro (&Qarrow
);
24761 Qtext
= intern ("text");
24762 staticpro (&Qtext
);
24763 Qrisky_local_variable
= intern ("risky-local-variable");
24764 staticpro (&Qrisky_local_variable
);
24765 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24766 staticpro (&Qinhibit_free_realized_faces
);
24768 list_of_error
= Fcons (Fcons (intern ("error"),
24769 Fcons (intern ("void-variable"), Qnil
)),
24771 staticpro (&list_of_error
);
24773 Qlast_arrow_position
= intern ("last-arrow-position");
24774 staticpro (&Qlast_arrow_position
);
24775 Qlast_arrow_string
= intern ("last-arrow-string");
24776 staticpro (&Qlast_arrow_string
);
24778 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24779 staticpro (&Qoverlay_arrow_string
);
24780 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24781 staticpro (&Qoverlay_arrow_bitmap
);
24783 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24784 staticpro (&echo_buffer
[0]);
24785 staticpro (&echo_buffer
[1]);
24787 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24788 staticpro (&echo_area_buffer
[0]);
24789 staticpro (&echo_area_buffer
[1]);
24791 Vmessages_buffer_name
= build_string ("*Messages*");
24792 staticpro (&Vmessages_buffer_name
);
24794 mode_line_proptrans_alist
= Qnil
;
24795 staticpro (&mode_line_proptrans_alist
);
24796 mode_line_string_list
= Qnil
;
24797 staticpro (&mode_line_string_list
);
24798 mode_line_string_face
= Qnil
;
24799 staticpro (&mode_line_string_face
);
24800 mode_line_string_face_prop
= Qnil
;
24801 staticpro (&mode_line_string_face_prop
);
24802 Vmode_line_unwind_vector
= Qnil
;
24803 staticpro (&Vmode_line_unwind_vector
);
24805 help_echo_string
= Qnil
;
24806 staticpro (&help_echo_string
);
24807 help_echo_object
= Qnil
;
24808 staticpro (&help_echo_object
);
24809 help_echo_window
= Qnil
;
24810 staticpro (&help_echo_window
);
24811 previous_help_echo_string
= Qnil
;
24812 staticpro (&previous_help_echo_string
);
24813 help_echo_pos
= -1;
24815 #ifdef HAVE_WINDOW_SYSTEM
24816 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24817 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24818 For example, if a block cursor is over a tab, it will be drawn as
24819 wide as that tab on the display. */);
24820 x_stretch_cursor_p
= 0;
24823 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24824 doc
: /* *Non-nil means highlight trailing whitespace.
24825 The face used for trailing whitespace is `trailing-whitespace'. */);
24826 Vshow_trailing_whitespace
= Qnil
;
24828 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24829 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24830 A value of t means highlight the character itself (for nobreak space,
24831 use face `nobreak-space').
24832 A value of nil means no highlighting.
24833 Other values mean display the escape glyph followed by an ordinary
24834 space or ordinary hyphen. */);
24835 Vnobreak_char_display
= Qt
;
24837 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24838 doc
: /* *The pointer shape to show in void text areas.
24839 A value of nil means to show the text pointer. Other options are `arrow',
24840 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24841 Vvoid_text_area_pointer
= Qarrow
;
24843 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24844 doc
: /* Non-nil means don't actually do any redisplay.
24845 This is used for internal purposes. */);
24846 Vinhibit_redisplay
= Qnil
;
24848 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24849 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24850 Vglobal_mode_string
= Qnil
;
24852 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24853 doc
: /* Marker for where to display an arrow on top of the buffer text.
24854 This must be the beginning of a line in order to work.
24855 See also `overlay-arrow-string'. */);
24856 Voverlay_arrow_position
= Qnil
;
24858 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24859 doc
: /* String to display as an arrow in non-window frames.
24860 See also `overlay-arrow-position'. */);
24861 Voverlay_arrow_string
= build_string ("=>");
24863 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24864 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24865 The symbols on this list are examined during redisplay to determine
24866 where to display overlay arrows. */);
24867 Voverlay_arrow_variable_list
24868 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24870 DEFVAR_INT ("scroll-step", &scroll_step
,
24871 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24872 If that fails to bring point back on frame, point is centered instead.
24873 If this is zero, point is always centered after it moves off frame.
24874 If you want scrolling to always be a line at a time, you should set
24875 `scroll-conservatively' to a large value rather than set this to 1. */);
24877 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24878 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24879 If point moves off-screen, redisplay will scroll by up to
24880 `scroll-conservatively' lines in order to bring point just barely
24881 onto the screen again. If that cannot be done, then redisplay
24882 recenters point as usual.
24884 A value of zero means always recenter point if it moves off screen. */);
24885 scroll_conservatively
= 0;
24887 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24888 doc
: /* *Number of lines of margin at the top and bottom of a window.
24889 Recenter the window whenever point gets within this many lines
24890 of the top or bottom of the window. */);
24893 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24894 doc
: /* Pixels per inch value for non-window system displays.
24895 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24896 Vdisplay_pixels_per_inch
= make_float (72.0);
24899 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24902 DEFVAR_LISP ("truncate-partial-width-windows",
24903 &Vtruncate_partial_width_windows
,
24904 doc
: /* Non-nil means truncate lines in windows with less than the frame width.
24905 For an integer value, truncate lines in each window with less than the
24906 full frame width, provided the window width is less than that integer;
24907 otherwise, respect the value of `truncate-lines'.
24909 For any other non-nil value, truncate lines in all windows with
24910 less than the full frame width.
24912 A value of nil means to respect the value of `truncate-lines'. */);
24913 Vtruncate_partial_width_windows
= make_number (30);
24915 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24916 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24917 Any other value means to use the appropriate face, `mode-line',
24918 `header-line', or `menu' respectively. */);
24919 mode_line_inverse_video
= 1;
24921 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24922 doc
: /* *Maximum buffer size for which line number should be displayed.
24923 If the buffer is bigger than this, the line number does not appear
24924 in the mode line. A value of nil means no limit. */);
24925 Vline_number_display_limit
= Qnil
;
24927 DEFVAR_INT ("line-number-display-limit-width",
24928 &line_number_display_limit_width
,
24929 doc
: /* *Maximum line width (in characters) for line number display.
24930 If the average length of the lines near point is bigger than this, then the
24931 line number may be omitted from the mode line. */);
24932 line_number_display_limit_width
= 200;
24934 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24935 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24936 highlight_nonselected_windows
= 0;
24938 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24939 doc
: /* Non-nil if more than one frame is visible on this display.
24940 Minibuffer-only frames don't count, but iconified frames do.
24941 This variable is not guaranteed to be accurate except while processing
24942 `frame-title-format' and `icon-title-format'. */);
24944 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24945 doc
: /* Template for displaying the title bar of visible frames.
24946 \(Assuming the window manager supports this feature.)
24948 This variable has the same structure as `mode-line-format', except that
24949 the %c and %l constructs are ignored. It is used only on frames for
24950 which no explicit name has been set \(see `modify-frame-parameters'). */);
24952 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24953 doc
: /* Template for displaying the title bar of an iconified frame.
24954 \(Assuming the window manager supports this feature.)
24955 This variable has the same structure as `mode-line-format' (which see),
24956 and is used only on frames for which no explicit name has been set
24957 \(see `modify-frame-parameters'). */);
24959 = Vframe_title_format
24960 = Fcons (intern ("multiple-frames"),
24961 Fcons (build_string ("%b"),
24962 Fcons (Fcons (empty_unibyte_string
,
24963 Fcons (intern ("invocation-name"),
24964 Fcons (build_string ("@"),
24965 Fcons (intern ("system-name"),
24969 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24970 doc
: /* Maximum number of lines to keep in the message log buffer.
24971 If nil, disable message logging. If t, log messages but don't truncate
24972 the buffer when it becomes large. */);
24973 Vmessage_log_max
= make_number (100);
24975 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24976 doc
: /* Functions called before redisplay, if window sizes have changed.
24977 The value should be a list of functions that take one argument.
24978 Just before redisplay, for each frame, if any of its windows have changed
24979 size since the last redisplay, or have been split or deleted,
24980 all the functions in the list are called, with the frame as argument. */);
24981 Vwindow_size_change_functions
= Qnil
;
24983 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24984 doc
: /* List of functions to call before redisplaying a window with scrolling.
24985 Each function is called with two arguments, the window
24986 and its new display-start position. Note that the value of `window-end'
24987 is not valid when these functions are called. */);
24988 Vwindow_scroll_functions
= Qnil
;
24990 DEFVAR_LISP ("window-text-change-functions",
24991 &Vwindow_text_change_functions
,
24992 doc
: /* Functions to call in redisplay when text in the window might change. */);
24993 Vwindow_text_change_functions
= Qnil
;
24995 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24996 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24997 Each function is called with two arguments, the window and the end trigger value.
24998 See `set-window-redisplay-end-trigger'. */);
24999 Vredisplay_end_trigger_functions
= Qnil
;
25001 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25002 doc
: /* *Non-nil means autoselect window with mouse pointer.
25003 If nil, do not autoselect windows.
25004 A positive number means delay autoselection by that many seconds: a
25005 window is autoselected only after the mouse has remained in that
25006 window for the duration of the delay.
25007 A negative number has a similar effect, but causes windows to be
25008 autoselected only after the mouse has stopped moving. \(Because of
25009 the way Emacs compares mouse events, you will occasionally wait twice
25010 that time before the window gets selected.\)
25011 Any other value means to autoselect window instantaneously when the
25012 mouse pointer enters it.
25014 Autoselection selects the minibuffer only if it is active, and never
25015 unselects the minibuffer if it is active.
25017 When customizing this variable make sure that the actual value of
25018 `focus-follows-mouse' matches the behavior of your window manager. */);
25019 Vmouse_autoselect_window
= Qnil
;
25021 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25022 doc
: /* *Non-nil means automatically resize tool-bars.
25023 This dynamically changes the tool-bar's height to the minimum height
25024 that is needed to make all tool-bar items visible.
25025 If value is `grow-only', the tool-bar's height is only increased
25026 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25027 Vauto_resize_tool_bars
= Qt
;
25029 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25030 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25031 auto_raise_tool_bar_buttons_p
= 1;
25033 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25034 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25035 make_cursor_line_fully_visible_p
= 1;
25037 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25038 doc
: /* *Border below tool-bar in pixels.
25039 If an integer, use it as the height of the border.
25040 If it is one of `internal-border-width' or `border-width', use the
25041 value of the corresponding frame parameter.
25042 Otherwise, no border is added below the tool-bar. */);
25043 Vtool_bar_border
= Qinternal_border_width
;
25045 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25046 doc
: /* *Margin around tool-bar buttons in pixels.
25047 If an integer, use that for both horizontal and vertical margins.
25048 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25049 HORZ specifying the horizontal margin, and VERT specifying the
25050 vertical margin. */);
25051 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25053 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25054 doc
: /* *Relief thickness of tool-bar buttons. */);
25055 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25057 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25058 doc
: /* List of functions to call to fontify regions of text.
25059 Each function is called with one argument POS. Functions must
25060 fontify a region starting at POS in the current buffer, and give
25061 fontified regions the property `fontified'. */);
25062 Vfontification_functions
= Qnil
;
25063 Fmake_variable_buffer_local (Qfontification_functions
);
25065 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25066 &unibyte_display_via_language_environment
,
25067 doc
: /* *Non-nil means display unibyte text according to language environment.
25068 Specifically this means that unibyte non-ASCII characters
25069 are displayed by converting them to the equivalent multibyte characters
25070 according to the current language environment. As a result, they are
25071 displayed according to the current fontset. */);
25072 unibyte_display_via_language_environment
= 0;
25074 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25075 doc
: /* *Maximum height for resizing mini-windows.
25076 If a float, it specifies a fraction of the mini-window frame's height.
25077 If an integer, it specifies a number of lines. */);
25078 Vmax_mini_window_height
= make_float (0.25);
25080 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25081 doc
: /* *How to resize mini-windows.
25082 A value of nil means don't automatically resize mini-windows.
25083 A value of t means resize them to fit the text displayed in them.
25084 A value of `grow-only', the default, means let mini-windows grow
25085 only, until their display becomes empty, at which point the windows
25086 go back to their normal size. */);
25087 Vresize_mini_windows
= Qgrow_only
;
25089 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25090 doc
: /* Alist specifying how to blink the cursor off.
25091 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25092 `cursor-type' frame-parameter or variable equals ON-STATE,
25093 comparing using `equal', Emacs uses OFF-STATE to specify
25094 how to blink it off. ON-STATE and OFF-STATE are values for
25095 the `cursor-type' frame parameter.
25097 If a frame's ON-STATE has no entry in this list,
25098 the frame's other specifications determine how to blink the cursor off. */);
25099 Vblink_cursor_alist
= Qnil
;
25101 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25102 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25103 automatic_hscrolling_p
= 1;
25104 Qauto_hscroll_mode
= intern ("auto-hscroll-mode");
25105 staticpro (&Qauto_hscroll_mode
);
25107 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25108 doc
: /* *How many columns away from the window edge point is allowed to get
25109 before automatic hscrolling will horizontally scroll the window. */);
25110 hscroll_margin
= 5;
25112 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25113 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25114 When point is less than `hscroll-margin' columns from the window
25115 edge, automatic hscrolling will scroll the window by the amount of columns
25116 determined by this variable. If its value is a positive integer, scroll that
25117 many columns. If it's a positive floating-point number, it specifies the
25118 fraction of the window's width to scroll. If it's nil or zero, point will be
25119 centered horizontally after the scroll. Any other value, including negative
25120 numbers, are treated as if the value were zero.
25122 Automatic hscrolling always moves point outside the scroll margin, so if
25123 point was more than scroll step columns inside the margin, the window will
25124 scroll more than the value given by the scroll step.
25126 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25127 and `scroll-right' overrides this variable's effect. */);
25128 Vhscroll_step
= make_number (0);
25130 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25131 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25132 Bind this around calls to `message' to let it take effect. */);
25133 message_truncate_lines
= 0;
25135 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25136 doc
: /* Normal hook run to update the menu bar definitions.
25137 Redisplay runs this hook before it redisplays the menu bar.
25138 This is used to update submenus such as Buffers,
25139 whose contents depend on various data. */);
25140 Vmenu_bar_update_hook
= Qnil
;
25142 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25143 doc
: /* Frame for which we are updating a menu.
25144 The enable predicate for a menu binding should check this variable. */);
25145 Vmenu_updating_frame
= Qnil
;
25147 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25148 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25149 inhibit_menubar_update
= 0;
25151 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25152 doc
: /* Prefix added to the beginning of all continuation lines at display-time.
25153 May be a string, an image, or a stretch-glyph such as used by the
25154 `display' text-property.
25156 This variable is overridden by any `wrap-prefix' text-property.
25158 To add a prefix to non-continuation lines, use the `line-prefix' variable. */);
25159 Vwrap_prefix
= Qnil
;
25160 staticpro (&Qwrap_prefix
);
25161 Qwrap_prefix
= intern ("wrap-prefix");
25162 Fmake_variable_buffer_local (Qwrap_prefix
);
25164 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25165 doc
: /* Prefix added to the beginning of all non-continuation lines at display-time.
25166 May be a string, an image, or a stretch-glyph such as used by the
25167 `display' text-property.
25169 This variable is overridden by any `line-prefix' text-property.
25171 To add a prefix to continuation lines, use the `wrap-prefix' variable. */);
25172 Vline_prefix
= Qnil
;
25173 staticpro (&Qline_prefix
);
25174 Qline_prefix
= intern ("line-prefix");
25175 Fmake_variable_buffer_local (Qline_prefix
);
25177 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25178 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25179 inhibit_eval_during_redisplay
= 0;
25181 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25182 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25183 inhibit_free_realized_faces
= 0;
25186 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25187 doc
: /* Inhibit try_window_id display optimization. */);
25188 inhibit_try_window_id
= 0;
25190 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25191 doc
: /* Inhibit try_window_reusing display optimization. */);
25192 inhibit_try_window_reusing
= 0;
25194 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25195 doc
: /* Inhibit try_cursor_movement display optimization. */);
25196 inhibit_try_cursor_movement
= 0;
25197 #endif /* GLYPH_DEBUG */
25199 DEFVAR_INT ("overline-margin", &overline_margin
,
25200 doc
: /* *Space between overline and text, in pixels.
25201 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25202 margin to the caracter height. */);
25203 overline_margin
= 2;
25205 DEFVAR_INT ("underline-minimum-offset",
25206 &underline_minimum_offset
,
25207 doc
: /* Minimum distance between baseline and underline.
25208 This can improve legibility of underlined text at small font sizes,
25209 particularly when using variable `x-use-underline-position-properties'
25210 with fonts that specify an UNDERLINE_POSITION relatively close to the
25211 baseline. The default value is 1. */);
25212 underline_minimum_offset
= 1;
25214 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25215 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25216 display_hourglass_p
= 1;
25218 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25219 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25220 Value must be an integer or float. */);
25221 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25223 hourglass_atimer
= NULL
;
25224 hourglass_shown_p
= 0;
25228 /* Initialize this module when Emacs starts. */
25233 Lisp_Object root_window
;
25234 struct window
*mini_w
;
25236 current_header_line_height
= current_mode_line_height
= -1;
25238 CHARPOS (this_line_start_pos
) = 0;
25240 mini_w
= XWINDOW (minibuf_window
);
25241 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25243 if (!noninteractive
)
25245 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25248 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25249 set_window_height (root_window
,
25250 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25252 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25253 set_window_height (minibuf_window
, 1, 0);
25255 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25256 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25258 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25259 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25260 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25262 /* The default ellipsis glyphs `...'. */
25263 for (i
= 0; i
< 3; ++i
)
25264 default_invis_vector
[i
] = make_number ('.');
25268 /* Allocate the buffer for frame titles.
25269 Also used for `format-mode-line'. */
25271 mode_line_noprop_buf
= (char *) xmalloc (size
);
25272 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25273 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25274 mode_line_target
= MODE_LINE_DISPLAY
;
25277 help_echo_showing_p
= 0;
25280 /* Since w32 does not support atimers, it defines its own implementation of
25281 the following three functions in w32fns.c. */
25284 /* Platform-independent portion of hourglass implementation. */
25286 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25288 hourglass_started ()
25290 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25293 /* Cancel a currently active hourglass timer, and start a new one. */
25297 #if defined (HAVE_WINDOW_SYSTEM)
25299 int secs
, usecs
= 0;
25301 cancel_hourglass ();
25303 if (INTEGERP (Vhourglass_delay
)
25304 && XINT (Vhourglass_delay
) > 0)
25305 secs
= XFASTINT (Vhourglass_delay
);
25306 else if (FLOATP (Vhourglass_delay
)
25307 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25310 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25311 secs
= XFASTINT (tem
);
25312 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25315 secs
= DEFAULT_HOURGLASS_DELAY
;
25317 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25318 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25319 show_hourglass
, NULL
);
25324 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25327 cancel_hourglass ()
25329 #if defined (HAVE_WINDOW_SYSTEM)
25330 if (hourglass_atimer
)
25332 cancel_atimer (hourglass_atimer
);
25333 hourglass_atimer
= NULL
;
25336 if (hourglass_shown_p
)
25340 #endif /* ! WINDOWSNT */
25342 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25343 (do not change this comment) */