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, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code.
37 The following diagram shows how redisplay code is invoked. As you
38 can see, Lisp calls redisplay and vice versa. Under window systems
39 like X, some portions of the redisplay code are also called
40 asynchronously during mouse movement or expose events. It is very
41 important that these code parts do NOT use the C library (malloc,
42 free) because many C libraries under Unix are not reentrant. They
43 may also NOT call functions of the Lisp interpreter which could
44 change the interpreter's state. If you don't follow these rules,
45 you will encounter bugs which are very hard to explain.
47 +--------------+ redisplay +----------------+
48 | Lisp machine |---------------->| Redisplay code |<--+
49 +--------------+ (xdisp.c) +----------------+ |
51 +----------------------------------+ |
52 Don't use this path when called |
55 expose_window (asynchronous) |
57 X expose events -----+
59 What does redisplay do? Obviously, it has to figure out somehow what
60 has been changed since the last time the display has been updated,
61 and to make these changes visible. Preferably it would do that in
62 a moderately intelligent way, i.e. fast.
64 Changes in buffer text can be deduced from window and buffer
65 structures, and from some global variables like `beg_unchanged' and
66 `end_unchanged'. The contents of the display are additionally
67 recorded in a `glyph matrix', a two-dimensional matrix of glyph
68 structures. Each row in such a matrix corresponds to a line on the
69 display, and each glyph in a row corresponds to a column displaying
70 a character, an image, or what else. This matrix is called the
71 `current glyph matrix' or `current matrix' in redisplay
74 For buffer parts that have been changed since the last update, a
75 second glyph matrix is constructed, the so called `desired glyph
76 matrix' or short `desired matrix'. Current and desired matrix are
77 then compared to find a cheap way to update the display, e.g. by
78 reusing part of the display by scrolling lines.
80 You will find a lot of redisplay optimizations when you start
81 looking at the innards of redisplay. The overall goal of all these
82 optimizations is to make redisplay fast because it is done
87 Desired matrices are always built per Emacs window. The function
88 `display_line' is the central function to look at if you are
89 interested. It constructs one row in a desired matrix given an
90 iterator structure containing both a buffer position and a
91 description of the environment in which the text is to be
92 displayed. But this is too early, read on.
94 Characters and pixmaps displayed for a range of buffer text depend
95 on various settings of buffers and windows, on overlays and text
96 properties, on display tables, on selective display. The good news
97 is that all this hairy stuff is hidden behind a small set of
98 interface functions taking an iterator structure (struct it)
101 Iteration over things to be displayed is then simple. It is
102 started by initializing an iterator with a call to init_iterator.
103 Calls to get_next_display_element fill the iterator structure with
104 relevant information about the next thing to display. Calls to
105 set_iterator_to_next move the iterator to the next thing.
107 Besides this, an iterator also contains information about the
108 display environment in which glyphs for display elements are to be
109 produced. It has fields for the width and height of the display,
110 the information whether long lines are truncated or continued, a
111 current X and Y position, and lots of other stuff you can better
114 Glyphs in a desired matrix are normally constructed in a loop
115 calling get_next_display_element and then produce_glyphs. The call
116 to produce_glyphs will fill the iterator structure with pixel
117 information about the element being displayed and at the same time
118 produce glyphs for it. If the display element fits on the line
119 being displayed, set_iterator_to_next is called next, otherwise the
120 glyphs produced are discarded.
125 That just couldn't be all, could it? What about terminal types not
126 supporting operations on sub-windows of the screen? To update the
127 display on such a terminal, window-based glyph matrices are not
128 well suited. To be able to reuse part of the display (scrolling
129 lines up and down), we must instead have a view of the whole
130 screen. This is what `frame matrices' are for. They are a trick.
132 Frames on terminals like above have a glyph pool. Windows on such
133 a frame sub-allocate their glyph memory from their frame's glyph
134 pool. The frame itself is given its own glyph matrices. By
135 coincidence---or maybe something else---rows in window glyph
136 matrices are slices of corresponding rows in frame matrices. Thus
137 writing to window matrices implicitly updates a frame matrix which
138 provides us with the view of the whole screen that we originally
139 wanted to have without having to move many bytes around. To be
140 honest, there is a little bit more done, but not much more. If you
141 plan to extend that code, take a look at dispnew.c. The function
142 build_frame_matrix is a good starting point. */
150 #include "keyboard.h"
153 #include "termchar.h"
154 #include "dispextern.h"
156 #include "character.h"
159 #include "commands.h"
163 #include "termhooks.h"
164 #include "intervals.h"
167 #include "region-cache.h"
170 #include "blockinput.h"
172 #ifdef HAVE_X_WINDOWS
187 #ifndef FRAME_X_OUTPUT
188 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
191 #define INFINITY 10000000
193 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
194 || defined(HAVE_NS) || defined (USE_GTK)
195 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
196 extern int pending_menu_activation
;
199 extern int interrupt_input
;
200 extern int command_loop_level
;
202 extern Lisp_Object do_mouse_tracking
;
204 extern int minibuffer_auto_raise
;
205 extern Lisp_Object Vminibuffer_list
;
207 extern Lisp_Object Qface
;
208 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
210 extern Lisp_Object Voverriding_local_map
;
211 extern Lisp_Object Voverriding_local_map_menu_flag
;
212 extern Lisp_Object Qmenu_item
;
213 extern Lisp_Object Qwhen
;
214 extern Lisp_Object Qhelp_echo
;
215 extern Lisp_Object Qbefore_string
, Qafter_string
;
217 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
218 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
219 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
220 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
221 Lisp_Object Qinhibit_point_motion_hooks
;
222 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
223 Lisp_Object Qfontified
;
224 Lisp_Object Qgrow_only
;
225 Lisp_Object Qinhibit_eval_during_redisplay
;
226 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
227 Lisp_Object Qright_to_left
, Qleft_to_right
;
230 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
233 Lisp_Object Qarrow
, Qhand
, Qtext
;
235 Lisp_Object Qrisky_local_variable
;
237 /* Holds the list (error). */
238 Lisp_Object list_of_error
;
240 /* Functions called to fontify regions of text. */
242 Lisp_Object Vfontification_functions
;
243 Lisp_Object Qfontification_functions
;
245 /* Non-nil means automatically select any window when the mouse
246 cursor moves into it. */
247 Lisp_Object Vmouse_autoselect_window
;
249 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
250 Lisp_Object Vline_prefix
, Qline_prefix
;
252 /* Non-zero means draw tool bar buttons raised when the mouse moves
255 int auto_raise_tool_bar_buttons_p
;
257 /* Non-zero means to reposition window if cursor line is only partially visible. */
259 int make_cursor_line_fully_visible_p
;
261 /* Margin below tool bar in pixels. 0 or nil means no margin.
262 If value is `internal-border-width' or `border-width',
263 the corresponding frame parameter is used. */
265 Lisp_Object Vtool_bar_border
;
267 /* Margin around tool bar buttons in pixels. */
269 Lisp_Object Vtool_bar_button_margin
;
271 /* Thickness of shadow to draw around tool bar buttons. */
273 EMACS_INT tool_bar_button_relief
;
275 /* Non-nil means automatically resize tool-bars so that all tool-bar
276 items are visible, and no blank lines remain.
278 If value is `grow-only', only make tool-bar bigger. */
280 Lisp_Object Vauto_resize_tool_bars
;
282 /* Non-zero means draw block and hollow cursor as wide as the glyph
283 under it. For example, if a block cursor is over a tab, it will be
284 drawn as wide as that tab on the display. */
286 int x_stretch_cursor_p
;
288 /* Non-nil means don't actually do any redisplay. */
290 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
292 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
294 int inhibit_eval_during_redisplay
;
296 /* Names of text properties relevant for redisplay. */
298 Lisp_Object Qdisplay
;
299 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
301 /* Symbols used in text property values. */
303 Lisp_Object Vdisplay_pixels_per_inch
;
304 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
305 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
308 Lisp_Object Qmargin
, Qpointer
;
309 Lisp_Object Qline_height
;
310 extern Lisp_Object Qheight
;
311 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
312 extern Lisp_Object Qscroll_bar
;
313 extern Lisp_Object Qcursor
;
315 /* Non-nil means highlight trailing whitespace. */
317 Lisp_Object Vshow_trailing_whitespace
;
319 /* Non-nil means escape non-break space and hyphens. */
321 Lisp_Object Vnobreak_char_display
;
323 #ifdef HAVE_WINDOW_SYSTEM
324 extern Lisp_Object Voverflow_newline_into_fringe
;
326 /* Test if overflow newline into fringe. Called with iterator IT
327 at or past right window margin, and with IT->current_x set. */
329 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
330 (!NILP (Voverflow_newline_into_fringe) \
331 && FRAME_WINDOW_P ((IT)->f) \
332 && ((IT)->bidi_it.paragraph_dir == R2L \
333 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
334 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
335 && (IT)->current_x == (IT)->last_visible_x \
336 && (IT)->line_wrap != WORD_WRAP)
338 #else /* !HAVE_WINDOW_SYSTEM */
339 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
340 #endif /* HAVE_WINDOW_SYSTEM */
342 /* Test if the display element loaded in IT is a space or tab
343 character. This is used to determine word wrapping. */
345 #define IT_DISPLAYING_WHITESPACE(it) \
346 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
348 /* Non-nil means show the text cursor in void text areas
349 i.e. in blank areas after eol and eob. This used to be
350 the default in 21.3. */
352 Lisp_Object Vvoid_text_area_pointer
;
354 /* Name of the face used to highlight trailing whitespace. */
356 Lisp_Object Qtrailing_whitespace
;
358 /* Name and number of the face used to highlight escape glyphs. */
360 Lisp_Object Qescape_glyph
;
362 /* Name and number of the face used to highlight non-breaking spaces. */
364 Lisp_Object Qnobreak_space
;
366 /* The symbol `image' which is the car of the lists used to represent
371 /* The image map types. */
372 Lisp_Object QCmap
, QCpointer
;
373 Lisp_Object Qrect
, Qcircle
, Qpoly
;
375 /* Non-zero means print newline to stdout before next mini-buffer
378 int noninteractive_need_newline
;
380 /* Non-zero means print newline to message log before next message. */
382 static int message_log_need_newline
;
384 /* Three markers that message_dolog uses.
385 It could allocate them itself, but that causes trouble
386 in handling memory-full errors. */
387 static Lisp_Object message_dolog_marker1
;
388 static Lisp_Object message_dolog_marker2
;
389 static Lisp_Object message_dolog_marker3
;
391 /* The buffer position of the first character appearing entirely or
392 partially on the line of the selected window which contains the
393 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
394 redisplay optimization in redisplay_internal. */
396 static struct text_pos this_line_start_pos
;
398 /* Number of characters past the end of the line above, including the
399 terminating newline. */
401 static struct text_pos this_line_end_pos
;
403 /* The vertical positions and the height of this line. */
405 static int this_line_vpos
;
406 static int this_line_y
;
407 static int this_line_pixel_height
;
409 /* X position at which this display line starts. Usually zero;
410 negative if first character is partially visible. */
412 static int this_line_start_x
;
414 /* Buffer that this_line_.* variables are referring to. */
416 static struct buffer
*this_line_buffer
;
418 /* Nonzero means truncate lines in all windows less wide than the
421 Lisp_Object Vtruncate_partial_width_windows
;
423 /* A flag to control how to display unibyte 8-bit character. */
425 int unibyte_display_via_language_environment
;
427 /* Nonzero means we have more than one non-mini-buffer-only frame.
428 Not guaranteed to be accurate except while parsing
429 frame-title-format. */
433 Lisp_Object Vglobal_mode_string
;
436 /* List of variables (symbols) which hold markers for overlay arrows.
437 The symbols on this list are examined during redisplay to determine
438 where to display overlay arrows. */
440 Lisp_Object Voverlay_arrow_variable_list
;
442 /* Marker for where to display an arrow on top of the buffer text. */
444 Lisp_Object Voverlay_arrow_position
;
446 /* String to display for the arrow. Only used on terminal frames. */
448 Lisp_Object Voverlay_arrow_string
;
450 /* Values of those variables at last redisplay are stored as
451 properties on `overlay-arrow-position' symbol. However, if
452 Voverlay_arrow_position is a marker, last-arrow-position is its
453 numerical position. */
455 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
457 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
458 properties on a symbol in overlay-arrow-variable-list. */
460 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
462 /* Like mode-line-format, but for the title bar on a visible frame. */
464 Lisp_Object Vframe_title_format
;
466 /* Like mode-line-format, but for the title bar on an iconified frame. */
468 Lisp_Object Vicon_title_format
;
470 /* List of functions to call when a window's size changes. These
471 functions get one arg, a frame on which one or more windows' sizes
474 static Lisp_Object Vwindow_size_change_functions
;
476 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
478 /* Nonzero if an overlay arrow has been displayed in this window. */
480 static int overlay_arrow_seen
;
482 /* Nonzero means highlight the region even in nonselected windows. */
484 int highlight_nonselected_windows
;
486 /* If cursor motion alone moves point off frame, try scrolling this
487 many lines up or down if that will bring it back. */
489 static EMACS_INT scroll_step
;
491 /* Nonzero means scroll just far enough to bring point back on the
492 screen, when appropriate. */
494 static EMACS_INT scroll_conservatively
;
496 /* Recenter the window whenever point gets within this many lines of
497 the top or bottom of the window. This value is translated into a
498 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
499 that there is really a fixed pixel height scroll margin. */
501 EMACS_INT scroll_margin
;
503 /* Number of windows showing the buffer of the selected window (or
504 another buffer with the same base buffer). keyboard.c refers to
509 /* Vector containing glyphs for an ellipsis `...'. */
511 static Lisp_Object default_invis_vector
[3];
513 /* Zero means display the mode-line/header-line/menu-bar in the default face
514 (this slightly odd definition is for compatibility with previous versions
515 of emacs), non-zero means display them using their respective faces.
517 This variable is deprecated. */
519 int mode_line_inverse_video
;
521 /* Prompt to display in front of the mini-buffer contents. */
523 Lisp_Object minibuf_prompt
;
525 /* Width of current mini-buffer prompt. Only set after display_line
526 of the line that contains the prompt. */
528 int minibuf_prompt_width
;
530 /* This is the window where the echo area message was displayed. It
531 is always a mini-buffer window, but it may not be the same window
532 currently active as a mini-buffer. */
534 Lisp_Object echo_area_window
;
536 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
537 pushes the current message and the value of
538 message_enable_multibyte on the stack, the function restore_message
539 pops the stack and displays MESSAGE again. */
541 Lisp_Object Vmessage_stack
;
543 /* Nonzero means multibyte characters were enabled when the echo area
544 message was specified. */
546 int message_enable_multibyte
;
548 /* Nonzero if we should redraw the mode lines on the next redisplay. */
550 int update_mode_lines
;
552 /* Nonzero if window sizes or contents have changed since last
553 redisplay that finished. */
555 int windows_or_buffers_changed
;
557 /* Nonzero means a frame's cursor type has been changed. */
559 int cursor_type_changed
;
561 /* Nonzero after display_mode_line if %l was used and it displayed a
564 int line_number_displayed
;
566 /* Maximum buffer size for which to display line numbers. */
568 Lisp_Object Vline_number_display_limit
;
570 /* Line width to consider when repositioning for line number display. */
572 static EMACS_INT line_number_display_limit_width
;
574 /* Number of lines to keep in the message log buffer. t means
575 infinite. nil means don't log at all. */
577 Lisp_Object Vmessage_log_max
;
579 /* The name of the *Messages* buffer, a string. */
581 static Lisp_Object Vmessages_buffer_name
;
583 /* Current, index 0, and last displayed echo area message. Either
584 buffers from echo_buffers, or nil to indicate no message. */
586 Lisp_Object echo_area_buffer
[2];
588 /* The buffers referenced from echo_area_buffer. */
590 static Lisp_Object echo_buffer
[2];
592 /* A vector saved used in with_area_buffer to reduce consing. */
594 static Lisp_Object Vwith_echo_area_save_vector
;
596 /* Non-zero means display_echo_area should display the last echo area
597 message again. Set by redisplay_preserve_echo_area. */
599 static int display_last_displayed_message_p
;
601 /* Nonzero if echo area is being used by print; zero if being used by
604 int message_buf_print
;
606 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
608 Lisp_Object Qinhibit_menubar_update
;
609 int inhibit_menubar_update
;
611 /* When evaluating expressions from menu bar items (enable conditions,
612 for instance), this is the frame they are being processed for. */
614 Lisp_Object Vmenu_updating_frame
;
616 /* Maximum height for resizing mini-windows. Either a float
617 specifying a fraction of the available height, or an integer
618 specifying a number of lines. */
620 Lisp_Object Vmax_mini_window_height
;
622 /* Non-zero means messages should be displayed with truncated
623 lines instead of being continued. */
625 int message_truncate_lines
;
626 Lisp_Object Qmessage_truncate_lines
;
628 /* Set to 1 in clear_message to make redisplay_internal aware
629 of an emptied echo area. */
631 static int message_cleared_p
;
633 /* How to blink the default frame cursor off. */
634 Lisp_Object Vblink_cursor_alist
;
636 /* A scratch glyph row with contents used for generating truncation
637 glyphs. Also used in direct_output_for_insert. */
639 #define MAX_SCRATCH_GLYPHS 100
640 struct glyph_row scratch_glyph_row
;
641 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
643 /* Ascent and height of the last line processed by move_it_to. */
645 static int last_max_ascent
, last_height
;
647 /* Non-zero if there's a help-echo in the echo area. */
649 int help_echo_showing_p
;
651 /* If >= 0, computed, exact values of mode-line and header-line height
652 to use in the macros CURRENT_MODE_LINE_HEIGHT and
653 CURRENT_HEADER_LINE_HEIGHT. */
655 int current_mode_line_height
, current_header_line_height
;
657 /* The maximum distance to look ahead for text properties. Values
658 that are too small let us call compute_char_face and similar
659 functions too often which is expensive. Values that are too large
660 let us call compute_char_face and alike too often because we
661 might not be interested in text properties that far away. */
663 #define TEXT_PROP_DISTANCE_LIMIT 100
667 /* Variables to turn off display optimizations from Lisp. */
669 int inhibit_try_window_id
, inhibit_try_window_reusing
;
670 int inhibit_try_cursor_movement
;
672 /* Non-zero means print traces of redisplay if compiled with
675 int trace_redisplay_p
;
677 #endif /* GLYPH_DEBUG */
679 #ifdef DEBUG_TRACE_MOVE
680 /* Non-zero means trace with TRACE_MOVE to stderr. */
683 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
685 #define TRACE_MOVE(x) (void) 0
688 /* Non-zero means automatically scroll windows horizontally to make
691 int automatic_hscrolling_p
;
692 Lisp_Object Qauto_hscroll_mode
;
694 /* How close to the margin can point get before the window is scrolled
696 EMACS_INT hscroll_margin
;
698 /* How much to scroll horizontally when point is inside the above margin. */
699 Lisp_Object Vhscroll_step
;
701 /* The variable `resize-mini-windows'. If nil, don't resize
702 mini-windows. If t, always resize them to fit the text they
703 display. If `grow-only', let mini-windows grow only until they
706 Lisp_Object Vresize_mini_windows
;
708 /* Buffer being redisplayed -- for redisplay_window_error. */
710 struct buffer
*displayed_buffer
;
712 /* Space between overline and text. */
714 EMACS_INT overline_margin
;
716 /* Require underline to be at least this many screen pixels below baseline
717 This to avoid underline "merging" with the base of letters at small
718 font sizes, particularly when x_use_underline_position_properties is on. */
720 EMACS_INT underline_minimum_offset
;
722 /* Value returned from text property handlers (see below). */
727 HANDLED_RECOMPUTE_PROPS
,
728 HANDLED_OVERLAY_STRING_CONSUMED
,
732 /* A description of text properties that redisplay is interested
737 /* The name of the property. */
740 /* A unique index for the property. */
743 /* A handler function called to set up iterator IT from the property
744 at IT's current position. Value is used to steer handle_stop. */
745 enum prop_handled (*handler
) P_ ((struct it
*it
));
748 static enum prop_handled handle_face_prop
P_ ((struct it
*));
749 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
750 static enum prop_handled handle_display_prop
P_ ((struct it
*));
751 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
752 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
753 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
755 /* Properties handled by iterators. */
757 static struct props it_props
[] =
759 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
760 /* Handle `face' before `display' because some sub-properties of
761 `display' need to know the face. */
762 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
763 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
764 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
765 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
769 /* Value is the position described by X. If X is a marker, value is
770 the marker_position of X. Otherwise, value is X. */
772 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
774 /* Enumeration returned by some move_it_.* functions internally. */
778 /* Not used. Undefined value. */
781 /* Move ended at the requested buffer position or ZV. */
782 MOVE_POS_MATCH_OR_ZV
,
784 /* Move ended at the requested X pixel position. */
787 /* Move within a line ended at the end of a line that must be
791 /* Move within a line ended at the end of a line that would
792 be displayed truncated. */
795 /* Move within a line ended at a line end. */
799 /* This counter is used to clear the face cache every once in a while
800 in redisplay_internal. It is incremented for each redisplay.
801 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
804 #define CLEAR_FACE_CACHE_COUNT 500
805 static int clear_face_cache_count
;
807 /* Similarly for the image cache. */
809 #ifdef HAVE_WINDOW_SYSTEM
810 #define CLEAR_IMAGE_CACHE_COUNT 101
811 static int clear_image_cache_count
;
814 /* Non-zero while redisplay_internal is in progress. */
818 /* Non-zero means don't free realized faces. Bound while freeing
819 realized faces is dangerous because glyph matrices might still
822 int inhibit_free_realized_faces
;
823 Lisp_Object Qinhibit_free_realized_faces
;
825 /* If a string, XTread_socket generates an event to display that string.
826 (The display is done in read_char.) */
828 Lisp_Object help_echo_string
;
829 Lisp_Object help_echo_window
;
830 Lisp_Object help_echo_object
;
833 /* Temporary variable for XTread_socket. */
835 Lisp_Object previous_help_echo_string
;
837 /* Null glyph slice */
839 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
841 /* Platform-independent portion of hourglass implementation. */
843 /* Non-zero means we're allowed to display a hourglass pointer. */
844 int display_hourglass_p
;
846 /* Non-zero means an hourglass cursor is currently shown. */
847 int hourglass_shown_p
;
849 /* If non-null, an asynchronous timer that, when it expires, displays
850 an hourglass cursor on all frames. */
851 struct atimer
*hourglass_atimer
;
853 /* Number of seconds to wait before displaying an hourglass cursor. */
854 Lisp_Object Vhourglass_delay
;
856 /* Default number of seconds to wait before displaying an hourglass
858 #define DEFAULT_HOURGLASS_DELAY 1
861 /* Function prototypes. */
863 static void setup_for_ellipsis
P_ ((struct it
*, int));
864 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
865 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
866 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
867 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
868 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
869 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
871 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
873 static void handle_line_prefix
P_ ((struct it
*));
875 static void pint2str
P_ ((char *, int, int));
876 static void pint2hrstr
P_ ((char *, int, int));
877 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
879 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
880 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
881 static void store_mode_line_noprop_char
P_ ((char));
882 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
883 static void x_consider_frame_title
P_ ((Lisp_Object
));
884 static void handle_stop
P_ ((struct it
*));
885 static void handle_stop_backwards
P_ ((struct it
*, EMACS_INT
));
886 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
887 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
888 static void ensure_echo_area_buffers
P_ ((void));
889 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
890 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
891 static int with_echo_area_buffer
P_ ((struct window
*, int,
892 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
893 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
894 static void clear_garbaged_frames
P_ ((void));
895 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
896 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
897 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
898 static int display_echo_area
P_ ((struct window
*));
899 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
900 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
901 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
902 static int string_char_and_length
P_ ((const unsigned char *, int *));
903 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
905 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
906 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
907 static void insert_left_trunc_glyphs
P_ ((struct it
*));
908 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
910 static void extend_face_to_end_of_line
P_ ((struct it
*));
911 static int append_space_for_newline
P_ ((struct it
*, int));
912 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
913 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
914 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
915 static int trailing_whitespace_p
P_ ((int));
916 static int message_log_check_duplicate
P_ ((int, int, int, int));
917 static void push_it
P_ ((struct it
*));
918 static void pop_it
P_ ((struct it
*));
919 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
920 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
921 static void redisplay_internal
P_ ((int));
922 static int echo_area_display
P_ ((int));
923 static void redisplay_windows
P_ ((Lisp_Object
));
924 static void redisplay_window
P_ ((Lisp_Object
, int));
925 static Lisp_Object
redisplay_window_error ();
926 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
927 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
928 static int update_menu_bar
P_ ((struct frame
*, int, int));
929 static int try_window_reusing_current_matrix
P_ ((struct window
*));
930 static int try_window_id
P_ ((struct window
*));
931 static int display_line
P_ ((struct it
*));
932 static int display_mode_lines
P_ ((struct window
*));
933 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
934 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
935 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
936 static char *decode_mode_spec
P_ ((struct window
*, int, int, int,
938 static void display_menu_bar
P_ ((struct window
*));
939 static int display_count_lines
P_ ((int, int, int, int, int *));
940 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
941 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
942 static void compute_line_metrics
P_ ((struct it
*));
943 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
944 static int get_overlay_strings
P_ ((struct it
*, int));
945 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
946 static void next_overlay_string
P_ ((struct it
*));
947 static void reseat
P_ ((struct it
*, struct text_pos
, int));
948 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
949 static void back_to_previous_visible_line_start
P_ ((struct it
*));
950 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
951 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
952 static int next_element_from_ellipsis
P_ ((struct it
*));
953 static int next_element_from_display_vector
P_ ((struct it
*));
954 static int next_element_from_string
P_ ((struct it
*));
955 static int next_element_from_c_string
P_ ((struct it
*));
956 static int next_element_from_buffer
P_ ((struct it
*));
957 static int next_element_from_composition
P_ ((struct it
*));
958 static int next_element_from_image
P_ ((struct it
*));
959 static int next_element_from_stretch
P_ ((struct it
*));
960 static void load_overlay_strings
P_ ((struct it
*, int));
961 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
962 struct display_pos
*));
963 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
964 Lisp_Object
, int, int, int, int));
965 static enum move_it_result
966 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
967 enum move_operation_enum
);
968 void move_it_vertically_backward
P_ ((struct it
*, int));
969 static void init_to_row_start
P_ ((struct it
*, struct window
*,
970 struct glyph_row
*));
971 static int init_to_row_end
P_ ((struct it
*, struct window
*,
972 struct glyph_row
*));
973 static void back_to_previous_line_start
P_ ((struct it
*));
974 static int forward_to_next_line_start
P_ ((struct it
*, int *));
975 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
977 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
978 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
979 static int number_of_chars
P_ ((unsigned char *, int));
980 static void compute_stop_pos
P_ ((struct it
*));
981 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
983 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
984 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
985 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
986 Lisp_Object
, Lisp_Object
,
987 struct text_pos
*, int));
988 static int underlying_face_id
P_ ((struct it
*));
989 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
992 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
993 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
995 #ifdef HAVE_WINDOW_SYSTEM
997 static void update_tool_bar
P_ ((struct frame
*, int));
998 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
999 static int redisplay_tool_bar
P_ ((struct frame
*));
1000 static void display_tool_bar_line
P_ ((struct it
*, int));
1001 static void notice_overwritten_cursor
P_ ((struct window
*,
1002 enum glyph_row_area
,
1003 int, int, int, int));
1004 static void append_stretch_glyph
P_ ((struct it
*, Lisp_Object
,
1009 #endif /* HAVE_WINDOW_SYSTEM */
1012 /***********************************************************************
1013 Window display dimensions
1014 ***********************************************************************/
1016 /* Return the bottom boundary y-position for text lines in window W.
1017 This is the first y position at which a line cannot start.
1018 It is relative to the top of the window.
1020 This is the height of W minus the height of a mode line, if any. */
1023 window_text_bottom_y (w
)
1026 int height
= WINDOW_TOTAL_HEIGHT (w
);
1028 if (WINDOW_WANTS_MODELINE_P (w
))
1029 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1033 /* Return the pixel width of display area AREA of window W. AREA < 0
1034 means return the total width of W, not including fringes to
1035 the left and right of the window. */
1038 window_box_width (w
, area
)
1042 int cols
= XFASTINT (w
->total_cols
);
1045 if (!w
->pseudo_window_p
)
1047 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1049 if (area
== TEXT_AREA
)
1051 if (INTEGERP (w
->left_margin_cols
))
1052 cols
-= XFASTINT (w
->left_margin_cols
);
1053 if (INTEGERP (w
->right_margin_cols
))
1054 cols
-= XFASTINT (w
->right_margin_cols
);
1055 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1057 else if (area
== LEFT_MARGIN_AREA
)
1059 cols
= (INTEGERP (w
->left_margin_cols
)
1060 ? XFASTINT (w
->left_margin_cols
) : 0);
1063 else if (area
== RIGHT_MARGIN_AREA
)
1065 cols
= (INTEGERP (w
->right_margin_cols
)
1066 ? XFASTINT (w
->right_margin_cols
) : 0);
1071 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1075 /* Return the pixel height of the display area of window W, not
1076 including mode lines of W, if any. */
1079 window_box_height (w
)
1082 struct frame
*f
= XFRAME (w
->frame
);
1083 int height
= WINDOW_TOTAL_HEIGHT (w
);
1085 xassert (height
>= 0);
1087 /* Note: the code below that determines the mode-line/header-line
1088 height is essentially the same as that contained in the macro
1089 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1090 the appropriate glyph row has its `mode_line_p' flag set,
1091 and if it doesn't, uses estimate_mode_line_height instead. */
1093 if (WINDOW_WANTS_MODELINE_P (w
))
1095 struct glyph_row
*ml_row
1096 = (w
->current_matrix
&& w
->current_matrix
->rows
1097 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1099 if (ml_row
&& ml_row
->mode_line_p
)
1100 height
-= ml_row
->height
;
1102 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1105 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1107 struct glyph_row
*hl_row
1108 = (w
->current_matrix
&& w
->current_matrix
->rows
1109 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1111 if (hl_row
&& hl_row
->mode_line_p
)
1112 height
-= hl_row
->height
;
1114 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1117 /* With a very small font and a mode-line that's taller than
1118 default, we might end up with a negative height. */
1119 return max (0, height
);
1122 /* Return the window-relative coordinate of the left edge of display
1123 area AREA of window W. AREA < 0 means return the left edge of the
1124 whole window, to the right of the left fringe of W. */
1127 window_box_left_offset (w
, area
)
1133 if (w
->pseudo_window_p
)
1136 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1138 if (area
== TEXT_AREA
)
1139 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1140 + window_box_width (w
, LEFT_MARGIN_AREA
));
1141 else if (area
== RIGHT_MARGIN_AREA
)
1142 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1143 + window_box_width (w
, LEFT_MARGIN_AREA
)
1144 + window_box_width (w
, TEXT_AREA
)
1145 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1147 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1148 else if (area
== LEFT_MARGIN_AREA
1149 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1150 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1156 /* Return the window-relative coordinate of the right edge of display
1157 area AREA of window W. AREA < 0 means return the left edge of the
1158 whole window, to the left of the right fringe of W. */
1161 window_box_right_offset (w
, area
)
1165 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1168 /* Return the frame-relative coordinate of the left edge of display
1169 area AREA of window W. AREA < 0 means return the left edge of the
1170 whole window, to the right of the left fringe of W. */
1173 window_box_left (w
, area
)
1177 struct frame
*f
= XFRAME (w
->frame
);
1180 if (w
->pseudo_window_p
)
1181 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1183 x
= (WINDOW_LEFT_EDGE_X (w
)
1184 + window_box_left_offset (w
, area
));
1190 /* Return the frame-relative coordinate of the right edge of display
1191 area AREA of window W. AREA < 0 means return the left edge of the
1192 whole window, to the left of the right fringe of W. */
1195 window_box_right (w
, area
)
1199 return window_box_left (w
, area
) + window_box_width (w
, area
);
1202 /* Get the bounding box of the display area AREA of window W, without
1203 mode lines, in frame-relative coordinates. AREA < 0 means the
1204 whole window, not including the left and right fringes of
1205 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1206 coordinates of the upper-left corner of the box. Return in
1207 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1210 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1213 int *box_x
, *box_y
, *box_width
, *box_height
;
1216 *box_width
= window_box_width (w
, area
);
1218 *box_height
= window_box_height (w
);
1220 *box_x
= window_box_left (w
, area
);
1223 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1224 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1225 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1230 /* Get the bounding box of the display area AREA of window W, without
1231 mode lines. AREA < 0 means the whole window, not including the
1232 left and right fringe of the window. Return in *TOP_LEFT_X
1233 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1234 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1235 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1239 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1240 bottom_right_x
, bottom_right_y
)
1243 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1245 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1247 *bottom_right_x
+= *top_left_x
;
1248 *bottom_right_y
+= *top_left_y
;
1253 /***********************************************************************
1255 ***********************************************************************/
1257 /* Return the bottom y-position of the line the iterator IT is in.
1258 This can modify IT's settings. */
1264 int line_height
= it
->max_ascent
+ it
->max_descent
;
1265 int line_top_y
= it
->current_y
;
1267 if (line_height
== 0)
1270 line_height
= last_height
;
1271 else if (IT_CHARPOS (*it
) < ZV
)
1273 move_it_by_lines (it
, 1, 1);
1274 line_height
= (it
->max_ascent
|| it
->max_descent
1275 ? it
->max_ascent
+ it
->max_descent
1280 struct glyph_row
*row
= it
->glyph_row
;
1282 /* Use the default character height. */
1283 it
->glyph_row
= NULL
;
1284 it
->what
= IT_CHARACTER
;
1287 PRODUCE_GLYPHS (it
);
1288 line_height
= it
->ascent
+ it
->descent
;
1289 it
->glyph_row
= row
;
1293 return line_top_y
+ line_height
;
1297 /* Return 1 if position CHARPOS is visible in window W.
1298 CHARPOS < 0 means return info about WINDOW_END position.
1299 If visible, set *X and *Y to pixel coordinates of top left corner.
1300 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1301 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1304 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1306 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1309 struct text_pos top
;
1311 struct buffer
*old_buffer
= NULL
;
1313 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1316 if (XBUFFER (w
->buffer
) != current_buffer
)
1318 old_buffer
= current_buffer
;
1319 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1322 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1324 /* Compute exact mode line heights. */
1325 if (WINDOW_WANTS_MODELINE_P (w
))
1326 current_mode_line_height
1327 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1328 current_buffer
->mode_line_format
);
1330 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1331 current_header_line_height
1332 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1333 current_buffer
->header_line_format
);
1335 start_display (&it
, w
, top
);
1336 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1337 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1339 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1341 /* We have reached CHARPOS, or passed it. How the call to
1342 move_it_to can overshoot: (i) If CHARPOS is on invisible
1343 text, move_it_to stops at the end of the invisible text,
1344 after CHARPOS. (ii) If CHARPOS is in a display vector,
1345 move_it_to stops on its last glyph. */
1346 int top_x
= it
.current_x
;
1347 int top_y
= it
.current_y
;
1348 enum it_method it_method
= it
.method
;
1349 /* Calling line_bottom_y may change it.method, it.position, etc. */
1350 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1351 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1353 if (top_y
< window_top_y
)
1354 visible_p
= bottom_y
> window_top_y
;
1355 else if (top_y
< it
.last_visible_y
)
1359 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1361 /* We stopped on the last glyph of a display vector.
1362 Try and recompute. Hack alert! */
1363 if (charpos
< 2 || top
.charpos
>= charpos
)
1364 top_x
= it
.glyph_row
->x
;
1368 start_display (&it2
, w
, top
);
1369 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1370 get_next_display_element (&it2
);
1371 PRODUCE_GLYPHS (&it2
);
1372 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1373 || it2
.current_x
> it2
.last_visible_x
)
1374 top_x
= it
.glyph_row
->x
;
1377 top_x
= it2
.current_x
;
1378 top_y
= it2
.current_y
;
1384 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1385 *rtop
= max (0, window_top_y
- top_y
);
1386 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1387 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1388 - max (top_y
, window_top_y
)));
1397 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1398 move_it_by_lines (&it
, 1, 0);
1399 if (charpos
< IT_CHARPOS (it
)
1400 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1403 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1405 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1406 *rtop
= max (0, -it2
.current_y
);
1407 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1408 - it
.last_visible_y
));
1409 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1411 - max (it2
.current_y
,
1412 WINDOW_HEADER_LINE_HEIGHT (w
))));
1418 set_buffer_internal_1 (old_buffer
);
1420 current_header_line_height
= current_mode_line_height
= -1;
1422 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1423 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1426 /* Debugging code. */
1428 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1429 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1431 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1438 /* Return the next character from STR which is MAXLEN bytes long.
1439 Return in *LEN the length of the character. This is like
1440 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1441 we find one, we return a `?', but with the length of the invalid
1445 string_char_and_length (str
, len
)
1446 const unsigned char *str
;
1451 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1452 if (!CHAR_VALID_P (c
, 1))
1453 /* We may not change the length here because other places in Emacs
1454 don't use this function, i.e. they silently accept invalid
1463 /* Given a position POS containing a valid character and byte position
1464 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1466 static struct text_pos
1467 string_pos_nchars_ahead (pos
, string
, nchars
)
1468 struct text_pos pos
;
1472 xassert (STRINGP (string
) && nchars
>= 0);
1474 if (STRING_MULTIBYTE (string
))
1476 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1477 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1482 string_char_and_length (p
, &len
);
1483 p
+= len
, rest
-= len
;
1484 xassert (rest
>= 0);
1486 BYTEPOS (pos
) += len
;
1490 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1496 /* Value is the text position, i.e. character and byte position,
1497 for character position CHARPOS in STRING. */
1499 static INLINE
struct text_pos
1500 string_pos (charpos
, string
)
1504 struct text_pos pos
;
1505 xassert (STRINGP (string
));
1506 xassert (charpos
>= 0);
1507 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1512 /* Value is a text position, i.e. character and byte position, for
1513 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1514 means recognize multibyte characters. */
1516 static struct text_pos
1517 c_string_pos (charpos
, s
, multibyte_p
)
1522 struct text_pos pos
;
1524 xassert (s
!= NULL
);
1525 xassert (charpos
>= 0);
1529 int rest
= strlen (s
), len
;
1531 SET_TEXT_POS (pos
, 0, 0);
1534 string_char_and_length (s
, &len
);
1535 s
+= len
, rest
-= len
;
1536 xassert (rest
>= 0);
1538 BYTEPOS (pos
) += len
;
1542 SET_TEXT_POS (pos
, charpos
, charpos
);
1548 /* Value is the number of characters in C string S. MULTIBYTE_P
1549 non-zero means recognize multibyte characters. */
1552 number_of_chars (s
, multibyte_p
)
1560 int rest
= strlen (s
), len
;
1561 unsigned char *p
= (unsigned char *) s
;
1563 for (nchars
= 0; rest
> 0; ++nchars
)
1565 string_char_and_length (p
, &len
);
1566 rest
-= len
, p
+= len
;
1570 nchars
= strlen (s
);
1576 /* Compute byte position NEWPOS->bytepos corresponding to
1577 NEWPOS->charpos. POS is a known position in string STRING.
1578 NEWPOS->charpos must be >= POS.charpos. */
1581 compute_string_pos (newpos
, pos
, string
)
1582 struct text_pos
*newpos
, pos
;
1585 xassert (STRINGP (string
));
1586 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1588 if (STRING_MULTIBYTE (string
))
1589 *newpos
= string_pos_nchars_ahead (pos
, string
,
1590 CHARPOS (*newpos
) - CHARPOS (pos
));
1592 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1596 Return an estimation of the pixel height of mode or header lines on
1597 frame F. FACE_ID specifies what line's height to estimate. */
1600 estimate_mode_line_height (f
, face_id
)
1602 enum face_id face_id
;
1604 #ifdef HAVE_WINDOW_SYSTEM
1605 if (FRAME_WINDOW_P (f
))
1607 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1609 /* This function is called so early when Emacs starts that the face
1610 cache and mode line face are not yet initialized. */
1611 if (FRAME_FACE_CACHE (f
))
1613 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1617 height
= FONT_HEIGHT (face
->font
);
1618 if (face
->box_line_width
> 0)
1619 height
+= 2 * face
->box_line_width
;
1630 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1631 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1632 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1633 not force the value into range. */
1636 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1638 register int pix_x
, pix_y
;
1640 NativeRectangle
*bounds
;
1644 #ifdef HAVE_WINDOW_SYSTEM
1645 if (FRAME_WINDOW_P (f
))
1647 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1648 even for negative values. */
1650 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1652 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1654 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1655 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1658 STORE_NATIVE_RECT (*bounds
,
1659 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1660 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1661 FRAME_COLUMN_WIDTH (f
) - 1,
1662 FRAME_LINE_HEIGHT (f
) - 1);
1668 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1669 pix_x
= FRAME_TOTAL_COLS (f
);
1673 else if (pix_y
> FRAME_LINES (f
))
1674 pix_y
= FRAME_LINES (f
);
1684 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1685 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1686 can't tell the positions because W's display is not up to date,
1690 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1693 int *frame_x
, *frame_y
;
1695 #ifdef HAVE_WINDOW_SYSTEM
1696 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1700 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1701 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1703 if (display_completed
)
1705 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1706 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1707 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1713 hpos
+= glyph
->pixel_width
;
1717 /* If first glyph is partially visible, its first visible position is still 0. */
1729 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1730 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1741 #ifdef HAVE_WINDOW_SYSTEM
1743 /* Find the glyph under window-relative coordinates X/Y in window W.
1744 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1745 strings. Return in *HPOS and *VPOS the row and column number of
1746 the glyph found. Return in *AREA the glyph area containing X.
1747 Value is a pointer to the glyph found or null if X/Y is not on
1748 text, or we can't tell because W's current matrix is not up to
1753 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1756 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1758 struct glyph
*glyph
, *end
;
1759 struct glyph_row
*row
= NULL
;
1762 /* Find row containing Y. Give up if some row is not enabled. */
1763 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1765 row
= MATRIX_ROW (w
->current_matrix
, i
);
1766 if (!row
->enabled_p
)
1768 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1775 /* Give up if Y is not in the window. */
1776 if (i
== w
->current_matrix
->nrows
)
1779 /* Get the glyph area containing X. */
1780 if (w
->pseudo_window_p
)
1787 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1789 *area
= LEFT_MARGIN_AREA
;
1790 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1792 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1795 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1799 *area
= RIGHT_MARGIN_AREA
;
1800 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1804 /* Find glyph containing X. */
1805 glyph
= row
->glyphs
[*area
];
1806 end
= glyph
+ row
->used
[*area
];
1808 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1810 x
-= glyph
->pixel_width
;
1820 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1823 *hpos
= glyph
- row
->glyphs
[*area
];
1829 Convert frame-relative x/y to coordinates relative to window W.
1830 Takes pseudo-windows into account. */
1833 frame_to_window_pixel_xy (w
, x
, y
)
1837 if (w
->pseudo_window_p
)
1839 /* A pseudo-window is always full-width, and starts at the
1840 left edge of the frame, plus a frame border. */
1841 struct frame
*f
= XFRAME (w
->frame
);
1842 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1843 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1847 *x
-= WINDOW_LEFT_EDGE_X (w
);
1848 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1853 Return in RECTS[] at most N clipping rectangles for glyph string S.
1854 Return the number of stored rectangles. */
1857 get_glyph_string_clip_rects (s
, rects
, n
)
1858 struct glyph_string
*s
;
1859 NativeRectangle
*rects
;
1867 if (s
->row
->full_width_p
)
1869 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1870 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1871 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1873 /* Unless displaying a mode or menu bar line, which are always
1874 fully visible, clip to the visible part of the row. */
1875 if (s
->w
->pseudo_window_p
)
1876 r
.height
= s
->row
->visible_height
;
1878 r
.height
= s
->height
;
1882 /* This is a text line that may be partially visible. */
1883 r
.x
= window_box_left (s
->w
, s
->area
);
1884 r
.width
= window_box_width (s
->w
, s
->area
);
1885 r
.height
= s
->row
->visible_height
;
1889 if (r
.x
< s
->clip_head
->x
)
1891 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1892 r
.width
-= s
->clip_head
->x
- r
.x
;
1895 r
.x
= s
->clip_head
->x
;
1898 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1900 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1901 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1906 /* If S draws overlapping rows, it's sufficient to use the top and
1907 bottom of the window for clipping because this glyph string
1908 intentionally draws over other lines. */
1909 if (s
->for_overlaps
)
1911 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1912 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1914 /* Alas, the above simple strategy does not work for the
1915 environments with anti-aliased text: if the same text is
1916 drawn onto the same place multiple times, it gets thicker.
1917 If the overlap we are processing is for the erased cursor, we
1918 take the intersection with the rectagle of the cursor. */
1919 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1921 XRectangle rc
, r_save
= r
;
1923 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1924 rc
.y
= s
->w
->phys_cursor
.y
;
1925 rc
.width
= s
->w
->phys_cursor_width
;
1926 rc
.height
= s
->w
->phys_cursor_height
;
1928 x_intersect_rectangles (&r_save
, &rc
, &r
);
1933 /* Don't use S->y for clipping because it doesn't take partially
1934 visible lines into account. For example, it can be negative for
1935 partially visible lines at the top of a window. */
1936 if (!s
->row
->full_width_p
1937 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1938 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1940 r
.y
= max (0, s
->row
->y
);
1943 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1945 /* If drawing the cursor, don't let glyph draw outside its
1946 advertised boundaries. Cleartype does this under some circumstances. */
1947 if (s
->hl
== DRAW_CURSOR
)
1949 struct glyph
*glyph
= s
->first_glyph
;
1954 r
.width
-= s
->x
- r
.x
;
1957 r
.width
= min (r
.width
, glyph
->pixel_width
);
1959 /* If r.y is below window bottom, ensure that we still see a cursor. */
1960 height
= min (glyph
->ascent
+ glyph
->descent
,
1961 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1962 max_y
= window_text_bottom_y (s
->w
) - height
;
1963 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1964 if (s
->ybase
- glyph
->ascent
> max_y
)
1971 /* Don't draw cursor glyph taller than our actual glyph. */
1972 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1973 if (height
< r
.height
)
1975 max_y
= r
.y
+ r
.height
;
1976 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1977 r
.height
= min (max_y
- r
.y
, height
);
1984 XRectangle r_save
= r
;
1986 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
1990 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
1991 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
1993 #ifdef CONVERT_FROM_XRECT
1994 CONVERT_FROM_XRECT (r
, *rects
);
2002 /* If we are processing overlapping and allowed to return
2003 multiple clipping rectangles, we exclude the row of the glyph
2004 string from the clipping rectangle. This is to avoid drawing
2005 the same text on the environment with anti-aliasing. */
2006 #ifdef CONVERT_FROM_XRECT
2009 XRectangle
*rs
= rects
;
2011 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2013 if (s
->for_overlaps
& OVERLAPS_PRED
)
2016 if (r
.y
+ r
.height
> row_y
)
2019 rs
[i
].height
= row_y
- r
.y
;
2025 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2028 if (r
.y
< row_y
+ s
->row
->visible_height
)
2030 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2032 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2033 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2042 #ifdef CONVERT_FROM_XRECT
2043 for (i
= 0; i
< n
; i
++)
2044 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2051 Return in *NR the clipping rectangle for glyph string S. */
2054 get_glyph_string_clip_rect (s
, nr
)
2055 struct glyph_string
*s
;
2056 NativeRectangle
*nr
;
2058 get_glyph_string_clip_rects (s
, nr
, 1);
2063 Return the position and height of the phys cursor in window W.
2064 Set w->phys_cursor_width to width of phys cursor.
2068 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2070 struct glyph_row
*row
;
2071 struct glyph
*glyph
;
2072 int *xp
, *yp
, *heightp
;
2074 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2075 int x
, y
, wd
, h
, h0
, y0
;
2077 /* Compute the width of the rectangle to draw. If on a stretch
2078 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2079 rectangle as wide as the glyph, but use a canonical character
2081 wd
= glyph
->pixel_width
- 1;
2082 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2086 x
= w
->phys_cursor
.x
;
2093 if (glyph
->type
== STRETCH_GLYPH
2094 && !x_stretch_cursor_p
)
2095 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2096 w
->phys_cursor_width
= wd
;
2098 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2100 /* If y is below window bottom, ensure that we still see a cursor. */
2101 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2103 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2104 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2106 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2109 h
= max (h
- (y0
- y
) + 1, h0
);
2114 y0
= window_text_bottom_y (w
) - h0
;
2122 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2123 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2128 * Remember which glyph the mouse is over.
2132 remember_mouse_glyph (f
, gx
, gy
, rect
)
2135 NativeRectangle
*rect
;
2139 struct glyph_row
*r
, *gr
, *end_row
;
2140 enum window_part part
;
2141 enum glyph_row_area area
;
2142 int x
, y
, width
, height
;
2144 /* Try to determine frame pixel position and size of the glyph under
2145 frame pixel coordinates X/Y on frame F. */
2147 if (!f
->glyphs_initialized_p
2148 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2151 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2152 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2156 w
= XWINDOW (window
);
2157 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2158 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2160 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2161 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2163 if (w
->pseudo_window_p
)
2166 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2172 case ON_LEFT_MARGIN
:
2173 area
= LEFT_MARGIN_AREA
;
2176 case ON_RIGHT_MARGIN
:
2177 area
= RIGHT_MARGIN_AREA
;
2180 case ON_HEADER_LINE
:
2182 gr
= (part
== ON_HEADER_LINE
2183 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2184 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2187 goto text_glyph_row_found
;
2194 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2195 if (r
->y
+ r
->height
> y
)
2201 text_glyph_row_found
:
2204 struct glyph
*g
= gr
->glyphs
[area
];
2205 struct glyph
*end
= g
+ gr
->used
[area
];
2207 height
= gr
->height
;
2208 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2209 if (gx
+ g
->pixel_width
> x
)
2214 if (g
->type
== IMAGE_GLYPH
)
2216 /* Don't remember when mouse is over image, as
2217 image may have hot-spots. */
2218 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2221 width
= g
->pixel_width
;
2225 /* Use nominal char spacing at end of line. */
2227 gx
+= (x
/ width
) * width
;
2230 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2231 gx
+= window_box_left_offset (w
, area
);
2235 /* Use nominal line height at end of window. */
2236 gx
= (x
/ width
) * width
;
2238 gy
+= (y
/ height
) * height
;
2242 case ON_LEFT_FRINGE
:
2243 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2244 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2245 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2246 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2249 case ON_RIGHT_FRINGE
:
2250 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2251 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2252 : window_box_right_offset (w
, TEXT_AREA
));
2253 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2257 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2259 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2260 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2261 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2263 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2267 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2268 if (r
->y
+ r
->height
> y
)
2275 height
= gr
->height
;
2278 /* Use nominal line height at end of window. */
2280 gy
+= (y
/ height
) * height
;
2287 /* If there is no glyph under the mouse, then we divide the screen
2288 into a grid of the smallest glyph in the frame, and use that
2291 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2292 round down even for negative values. */
2298 gx
= (gx
/ width
) * width
;
2299 gy
= (gy
/ height
) * height
;
2304 gx
+= WINDOW_LEFT_EDGE_X (w
);
2305 gy
+= WINDOW_TOP_EDGE_Y (w
);
2308 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2310 /* Visible feedback for debugging. */
2313 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2314 f
->output_data
.x
->normal_gc
,
2315 gx
, gy
, width
, height
);
2321 #endif /* HAVE_WINDOW_SYSTEM */
2324 /***********************************************************************
2325 Lisp form evaluation
2326 ***********************************************************************/
2328 /* Error handler for safe_eval and safe_call. */
2331 safe_eval_handler (arg
)
2334 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2339 /* Evaluate SEXPR and return the result, or nil if something went
2340 wrong. Prevent redisplay during the evaluation. */
2342 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2343 Return the result, or nil if something went wrong. Prevent
2344 redisplay during the evaluation. */
2347 safe_call (nargs
, args
)
2353 if (inhibit_eval_during_redisplay
)
2357 int count
= SPECPDL_INDEX ();
2358 struct gcpro gcpro1
;
2361 gcpro1
.nvars
= nargs
;
2362 specbind (Qinhibit_redisplay
, Qt
);
2363 /* Use Qt to ensure debugger does not run,
2364 so there is no possibility of wanting to redisplay. */
2365 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2368 val
= unbind_to (count
, val
);
2375 /* Call function FN with one argument ARG.
2376 Return the result, or nil if something went wrong. */
2379 safe_call1 (fn
, arg
)
2380 Lisp_Object fn
, arg
;
2382 Lisp_Object args
[2];
2385 return safe_call (2, args
);
2388 static Lisp_Object Qeval
;
2391 safe_eval (Lisp_Object sexpr
)
2393 return safe_call1 (Qeval
, sexpr
);
2396 /* Call function FN with one argument ARG.
2397 Return the result, or nil if something went wrong. */
2400 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2402 Lisp_Object args
[3];
2406 return safe_call (3, args
);
2411 /***********************************************************************
2413 ***********************************************************************/
2417 /* Define CHECK_IT to perform sanity checks on iterators.
2418 This is for debugging. It is too slow to do unconditionally. */
2424 if (it
->method
== GET_FROM_STRING
)
2426 xassert (STRINGP (it
->string
));
2427 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2431 xassert (IT_STRING_CHARPOS (*it
) < 0);
2432 if (it
->method
== GET_FROM_BUFFER
)
2434 /* Check that character and byte positions agree. */
2435 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2440 xassert (it
->current
.dpvec_index
>= 0);
2442 xassert (it
->current
.dpvec_index
< 0);
2445 #define CHECK_IT(IT) check_it ((IT))
2449 #define CHECK_IT(IT) (void) 0
2456 /* Check that the window end of window W is what we expect it
2457 to be---the last row in the current matrix displaying text. */
2460 check_window_end (w
)
2463 if (!MINI_WINDOW_P (w
)
2464 && !NILP (w
->window_end_valid
))
2466 struct glyph_row
*row
;
2467 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2468 XFASTINT (w
->window_end_vpos
)),
2470 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2471 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2475 #define CHECK_WINDOW_END(W) check_window_end ((W))
2477 #else /* not GLYPH_DEBUG */
2479 #define CHECK_WINDOW_END(W) (void) 0
2481 #endif /* not GLYPH_DEBUG */
2485 /***********************************************************************
2486 Iterator initialization
2487 ***********************************************************************/
2489 /* Initialize IT for displaying current_buffer in window W, starting
2490 at character position CHARPOS. CHARPOS < 0 means that no buffer
2491 position is specified which is useful when the iterator is assigned
2492 a position later. BYTEPOS is the byte position corresponding to
2493 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2495 If ROW is not null, calls to produce_glyphs with IT as parameter
2496 will produce glyphs in that row.
2498 BASE_FACE_ID is the id of a base face to use. It must be one of
2499 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2500 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2501 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2503 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2504 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2505 will be initialized to use the corresponding mode line glyph row of
2506 the desired matrix of W. */
2509 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2512 int charpos
, bytepos
;
2513 struct glyph_row
*row
;
2514 enum face_id base_face_id
;
2516 int highlight_region_p
;
2517 enum face_id remapped_base_face_id
= base_face_id
;
2519 /* Some precondition checks. */
2520 xassert (w
!= NULL
&& it
!= NULL
);
2521 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2524 /* If face attributes have been changed since the last redisplay,
2525 free realized faces now because they depend on face definitions
2526 that might have changed. Don't free faces while there might be
2527 desired matrices pending which reference these faces. */
2528 if (face_change_count
&& !inhibit_free_realized_faces
)
2530 face_change_count
= 0;
2531 free_all_realized_faces (Qnil
);
2534 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2535 if (! NILP (Vface_remapping_alist
))
2536 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2538 /* Use one of the mode line rows of W's desired matrix if
2542 if (base_face_id
== MODE_LINE_FACE_ID
2543 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2544 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2545 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2546 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2550 bzero (it
, sizeof *it
);
2551 it
->current
.overlay_string_index
= -1;
2552 it
->current
.dpvec_index
= -1;
2553 it
->base_face_id
= remapped_base_face_id
;
2555 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2557 /* The window in which we iterate over current_buffer: */
2558 XSETWINDOW (it
->window
, w
);
2560 it
->f
= XFRAME (w
->frame
);
2564 /* Extra space between lines (on window systems only). */
2565 if (base_face_id
== DEFAULT_FACE_ID
2566 && FRAME_WINDOW_P (it
->f
))
2568 if (NATNUMP (current_buffer
->extra_line_spacing
))
2569 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2570 else if (FLOATP (current_buffer
->extra_line_spacing
))
2571 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2572 * FRAME_LINE_HEIGHT (it
->f
));
2573 else if (it
->f
->extra_line_spacing
> 0)
2574 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2575 it
->max_extra_line_spacing
= 0;
2578 /* If realized faces have been removed, e.g. because of face
2579 attribute changes of named faces, recompute them. When running
2580 in batch mode, the face cache of the initial frame is null. If
2581 we happen to get called, make a dummy face cache. */
2582 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2583 init_frame_faces (it
->f
);
2584 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2585 recompute_basic_faces (it
->f
);
2587 /* Current value of the `slice', `space-width', and 'height' properties. */
2588 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2589 it
->space_width
= Qnil
;
2590 it
->font_height
= Qnil
;
2591 it
->override_ascent
= -1;
2593 /* Are control characters displayed as `^C'? */
2594 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2596 /* -1 means everything between a CR and the following line end
2597 is invisible. >0 means lines indented more than this value are
2599 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2600 ? XFASTINT (current_buffer
->selective_display
)
2601 : (!NILP (current_buffer
->selective_display
)
2603 it
->selective_display_ellipsis_p
2604 = !NILP (current_buffer
->selective_display_ellipses
);
2606 /* Display table to use. */
2607 it
->dp
= window_display_table (w
);
2609 /* Are multibyte characters enabled in current_buffer? */
2610 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2612 /* Do we need to reorder bidirectional text? */
2613 it
->bidi_p
= !NILP (current_buffer
->bidi_display_reordering
);
2615 /* Non-zero if we should highlight the region. */
2617 = (!NILP (Vtransient_mark_mode
)
2618 && !NILP (current_buffer
->mark_active
)
2619 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2621 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2622 start and end of a visible region in window IT->w. Set both to
2623 -1 to indicate no region. */
2624 if (highlight_region_p
2625 /* Maybe highlight only in selected window. */
2626 && (/* Either show region everywhere. */
2627 highlight_nonselected_windows
2628 /* Or show region in the selected window. */
2629 || w
== XWINDOW (selected_window
)
2630 /* Or show the region if we are in the mini-buffer and W is
2631 the window the mini-buffer refers to. */
2632 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2633 && WINDOWP (minibuf_selected_window
)
2634 && w
== XWINDOW (minibuf_selected_window
))))
2636 int charpos
= marker_position (current_buffer
->mark
);
2637 it
->region_beg_charpos
= min (PT
, charpos
);
2638 it
->region_end_charpos
= max (PT
, charpos
);
2641 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2643 /* Get the position at which the redisplay_end_trigger hook should
2644 be run, if it is to be run at all. */
2645 if (MARKERP (w
->redisplay_end_trigger
)
2646 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2647 it
->redisplay_end_trigger_charpos
2648 = marker_position (w
->redisplay_end_trigger
);
2649 else if (INTEGERP (w
->redisplay_end_trigger
))
2650 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2652 /* Correct bogus values of tab_width. */
2653 it
->tab_width
= XINT (current_buffer
->tab_width
);
2654 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2657 /* Are lines in the display truncated? */
2658 if (base_face_id
!= DEFAULT_FACE_ID
2659 || XINT (it
->w
->hscroll
)
2660 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2661 && ((!NILP (Vtruncate_partial_width_windows
)
2662 && !INTEGERP (Vtruncate_partial_width_windows
))
2663 || (INTEGERP (Vtruncate_partial_width_windows
)
2664 && (WINDOW_TOTAL_COLS (it
->w
)
2665 < XINT (Vtruncate_partial_width_windows
))))))
2666 it
->line_wrap
= TRUNCATE
;
2667 else if (NILP (current_buffer
->truncate_lines
))
2668 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2669 ? WINDOW_WRAP
: WORD_WRAP
;
2671 it
->line_wrap
= TRUNCATE
;
2673 /* Get dimensions of truncation and continuation glyphs. These are
2674 displayed as fringe bitmaps under X, so we don't need them for such
2676 if (!FRAME_WINDOW_P (it
->f
))
2678 if (it
->line_wrap
== TRUNCATE
)
2680 /* We will need the truncation glyph. */
2681 xassert (it
->glyph_row
== NULL
);
2682 produce_special_glyphs (it
, IT_TRUNCATION
);
2683 it
->truncation_pixel_width
= it
->pixel_width
;
2687 /* We will need the continuation glyph. */
2688 xassert (it
->glyph_row
== NULL
);
2689 produce_special_glyphs (it
, IT_CONTINUATION
);
2690 it
->continuation_pixel_width
= it
->pixel_width
;
2693 /* Reset these values to zero because the produce_special_glyphs
2694 above has changed them. */
2695 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2696 it
->phys_ascent
= it
->phys_descent
= 0;
2699 /* Set this after getting the dimensions of truncation and
2700 continuation glyphs, so that we don't produce glyphs when calling
2701 produce_special_glyphs, above. */
2702 it
->glyph_row
= row
;
2703 it
->area
= TEXT_AREA
;
2705 /* Forget any previous info about this row being reversed. */
2707 it
->glyph_row
->reversed_p
= 0;
2709 /* Get the dimensions of the display area. The display area
2710 consists of the visible window area plus a horizontally scrolled
2711 part to the left of the window. All x-values are relative to the
2712 start of this total display area. */
2713 if (base_face_id
!= DEFAULT_FACE_ID
)
2715 /* Mode lines, menu bar in terminal frames. */
2716 it
->first_visible_x
= 0;
2717 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2722 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2723 it
->last_visible_x
= (it
->first_visible_x
2724 + window_box_width (w
, TEXT_AREA
));
2726 /* If we truncate lines, leave room for the truncator glyph(s) at
2727 the right margin. Otherwise, leave room for the continuation
2728 glyph(s). Truncation and continuation glyphs are not inserted
2729 for window-based redisplay. */
2730 if (!FRAME_WINDOW_P (it
->f
))
2732 if (it
->line_wrap
== TRUNCATE
)
2733 it
->last_visible_x
-= it
->truncation_pixel_width
;
2735 it
->last_visible_x
-= it
->continuation_pixel_width
;
2738 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2739 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2742 /* Leave room for a border glyph. */
2743 if (!FRAME_WINDOW_P (it
->f
)
2744 && !WINDOW_RIGHTMOST_P (it
->w
))
2745 it
->last_visible_x
-= 1;
2747 it
->last_visible_y
= window_text_bottom_y (w
);
2749 /* For mode lines and alike, arrange for the first glyph having a
2750 left box line if the face specifies a box. */
2751 if (base_face_id
!= DEFAULT_FACE_ID
)
2755 it
->face_id
= remapped_base_face_id
;
2757 /* If we have a boxed mode line, make the first character appear
2758 with a left box line. */
2759 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2760 if (face
->box
!= FACE_NO_BOX
)
2761 it
->start_of_box_run_p
= 1;
2764 /* If we are to reorder bidirectional text, init the bidi
2768 /* Note the paragraph direction that this buffer wants to
2770 if (EQ (current_buffer
->bidi_paragraph_direction
, Qleft_to_right
))
2771 it
->paragraph_embedding
= L2R
;
2772 else if (EQ (current_buffer
->bidi_paragraph_direction
, Qright_to_left
))
2773 it
->paragraph_embedding
= R2L
;
2775 it
->paragraph_embedding
= NEUTRAL_DIR
;
2776 bidi_init_it (charpos
, bytepos
, &it
->bidi_it
);
2779 /* If a buffer position was specified, set the iterator there,
2780 getting overlays and face properties from that position. */
2781 if (charpos
>= BUF_BEG (current_buffer
))
2783 it
->end_charpos
= ZV
;
2785 IT_CHARPOS (*it
) = charpos
;
2787 /* Compute byte position if not specified. */
2788 if (bytepos
< charpos
)
2789 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2791 IT_BYTEPOS (*it
) = bytepos
;
2793 it
->start
= it
->current
;
2795 /* Compute faces etc. */
2796 reseat (it
, it
->current
.pos
, 1);
2803 /* Initialize IT for the display of window W with window start POS. */
2806 start_display (it
, w
, pos
)
2809 struct text_pos pos
;
2811 struct glyph_row
*row
;
2812 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2814 row
= w
->desired_matrix
->rows
+ first_vpos
;
2815 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2816 it
->first_vpos
= first_vpos
;
2818 /* Don't reseat to previous visible line start if current start
2819 position is in a string or image. */
2820 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2822 int start_at_line_beg_p
;
2823 int first_y
= it
->current_y
;
2825 /* If window start is not at a line start, skip forward to POS to
2826 get the correct continuation lines width. */
2827 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2828 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2829 if (!start_at_line_beg_p
)
2833 reseat_at_previous_visible_line_start (it
);
2834 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2836 new_x
= it
->current_x
+ it
->pixel_width
;
2838 /* If lines are continued, this line may end in the middle
2839 of a multi-glyph character (e.g. a control character
2840 displayed as \003, or in the middle of an overlay
2841 string). In this case move_it_to above will not have
2842 taken us to the start of the continuation line but to the
2843 end of the continued line. */
2844 if (it
->current_x
> 0
2845 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2846 && (/* And glyph doesn't fit on the line. */
2847 new_x
> it
->last_visible_x
2848 /* Or it fits exactly and we're on a window
2850 || (new_x
== it
->last_visible_x
2851 && FRAME_WINDOW_P (it
->f
))))
2853 if (it
->current
.dpvec_index
>= 0
2854 || it
->current
.overlay_string_index
>= 0)
2856 set_iterator_to_next (it
, 1);
2857 move_it_in_display_line_to (it
, -1, -1, 0);
2860 it
->continuation_lines_width
+= it
->current_x
;
2863 /* We're starting a new display line, not affected by the
2864 height of the continued line, so clear the appropriate
2865 fields in the iterator structure. */
2866 it
->max_ascent
= it
->max_descent
= 0;
2867 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2869 it
->current_y
= first_y
;
2871 it
->current_x
= it
->hpos
= 0;
2877 /* Return 1 if POS is a position in ellipses displayed for invisible
2878 text. W is the window we display, for text property lookup. */
2881 in_ellipses_for_invisible_text_p (pos
, w
)
2882 struct display_pos
*pos
;
2885 Lisp_Object prop
, window
;
2887 int charpos
= CHARPOS (pos
->pos
);
2889 /* If POS specifies a position in a display vector, this might
2890 be for an ellipsis displayed for invisible text. We won't
2891 get the iterator set up for delivering that ellipsis unless
2892 we make sure that it gets aware of the invisible text. */
2893 if (pos
->dpvec_index
>= 0
2894 && pos
->overlay_string_index
< 0
2895 && CHARPOS (pos
->string_pos
) < 0
2897 && (XSETWINDOW (window
, w
),
2898 prop
= Fget_char_property (make_number (charpos
),
2899 Qinvisible
, window
),
2900 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2902 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2904 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2911 /* Initialize IT for stepping through current_buffer in window W,
2912 starting at position POS that includes overlay string and display
2913 vector/ control character translation position information. Value
2914 is zero if there are overlay strings with newlines at POS. */
2917 init_from_display_pos (it
, w
, pos
)
2920 struct display_pos
*pos
;
2922 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2923 int i
, overlay_strings_with_newlines
= 0;
2925 /* If POS specifies a position in a display vector, this might
2926 be for an ellipsis displayed for invisible text. We won't
2927 get the iterator set up for delivering that ellipsis unless
2928 we make sure that it gets aware of the invisible text. */
2929 if (in_ellipses_for_invisible_text_p (pos
, w
))
2935 /* Keep in mind: the call to reseat in init_iterator skips invisible
2936 text, so we might end up at a position different from POS. This
2937 is only a problem when POS is a row start after a newline and an
2938 overlay starts there with an after-string, and the overlay has an
2939 invisible property. Since we don't skip invisible text in
2940 display_line and elsewhere immediately after consuming the
2941 newline before the row start, such a POS will not be in a string,
2942 but the call to init_iterator below will move us to the
2944 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2946 /* This only scans the current chunk -- it should scan all chunks.
2947 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2948 to 16 in 22.1 to make this a lesser problem. */
2949 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2951 const char *s
= SDATA (it
->overlay_strings
[i
]);
2952 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2954 while (s
< e
&& *s
!= '\n')
2959 overlay_strings_with_newlines
= 1;
2964 /* If position is within an overlay string, set up IT to the right
2966 if (pos
->overlay_string_index
>= 0)
2970 /* If the first overlay string happens to have a `display'
2971 property for an image, the iterator will be set up for that
2972 image, and we have to undo that setup first before we can
2973 correct the overlay string index. */
2974 if (it
->method
== GET_FROM_IMAGE
)
2977 /* We already have the first chunk of overlay strings in
2978 IT->overlay_strings. Load more until the one for
2979 pos->overlay_string_index is in IT->overlay_strings. */
2980 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2982 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2983 it
->current
.overlay_string_index
= 0;
2986 load_overlay_strings (it
, 0);
2987 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2991 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2992 relative_index
= (it
->current
.overlay_string_index
2993 % OVERLAY_STRING_CHUNK_SIZE
);
2994 it
->string
= it
->overlay_strings
[relative_index
];
2995 xassert (STRINGP (it
->string
));
2996 it
->current
.string_pos
= pos
->string_pos
;
2997 it
->method
= GET_FROM_STRING
;
3000 if (CHARPOS (pos
->string_pos
) >= 0)
3002 /* Recorded position is not in an overlay string, but in another
3003 string. This can only be a string from a `display' property.
3004 IT should already be filled with that string. */
3005 it
->current
.string_pos
= pos
->string_pos
;
3006 xassert (STRINGP (it
->string
));
3009 /* Restore position in display vector translations, control
3010 character translations or ellipses. */
3011 if (pos
->dpvec_index
>= 0)
3013 if (it
->dpvec
== NULL
)
3014 get_next_display_element (it
);
3015 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3016 it
->current
.dpvec_index
= pos
->dpvec_index
;
3020 return !overlay_strings_with_newlines
;
3024 /* Initialize IT for stepping through current_buffer in window W
3025 starting at ROW->start. */
3028 init_to_row_start (it
, w
, row
)
3031 struct glyph_row
*row
;
3033 init_from_display_pos (it
, w
, &row
->start
);
3034 it
->start
= row
->start
;
3035 it
->continuation_lines_width
= row
->continuation_lines_width
;
3040 /* Initialize IT for stepping through current_buffer in window W
3041 starting in the line following ROW, i.e. starting at ROW->end.
3042 Value is zero if there are overlay strings with newlines at ROW's
3046 init_to_row_end (it
, w
, row
)
3049 struct glyph_row
*row
;
3053 if (init_from_display_pos (it
, w
, &row
->end
))
3055 if (row
->continued_p
)
3056 it
->continuation_lines_width
3057 = row
->continuation_lines_width
+ row
->pixel_width
;
3068 /***********************************************************************
3070 ***********************************************************************/
3072 /* Called when IT reaches IT->stop_charpos. Handle text property and
3073 overlay changes. Set IT->stop_charpos to the next position where
3080 enum prop_handled handled
;
3081 int handle_overlay_change_p
;
3085 it
->current
.dpvec_index
= -1;
3086 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3087 it
->ignore_overlay_strings_at_pos_p
= 0;
3090 /* Use face of preceding text for ellipsis (if invisible) */
3091 if (it
->selective_display_ellipsis_p
)
3092 it
->saved_face_id
= it
->face_id
;
3096 handled
= HANDLED_NORMALLY
;
3098 /* Call text property handlers. */
3099 for (p
= it_props
; p
->handler
; ++p
)
3101 handled
= p
->handler (it
);
3103 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3105 else if (handled
== HANDLED_RETURN
)
3107 /* We still want to show before and after strings from
3108 overlays even if the actual buffer text is replaced. */
3109 if (!handle_overlay_change_p
3111 || !get_overlay_strings_1 (it
, 0, 0))
3114 setup_for_ellipsis (it
, 0);
3115 /* When handling a display spec, we might load an
3116 empty string. In that case, discard it here. We
3117 used to discard it in handle_single_display_spec,
3118 but that causes get_overlay_strings_1, above, to
3119 ignore overlay strings that we must check. */
3120 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3124 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3128 it
->ignore_overlay_strings_at_pos_p
= 1;
3129 it
->string_from_display_prop_p
= 0;
3130 handle_overlay_change_p
= 0;
3132 handled
= HANDLED_RECOMPUTE_PROPS
;
3135 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3136 handle_overlay_change_p
= 0;
3139 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3141 /* Don't check for overlay strings below when set to deliver
3142 characters from a display vector. */
3143 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3144 handle_overlay_change_p
= 0;
3146 /* Handle overlay changes.
3147 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3148 if it finds overlays. */
3149 if (handle_overlay_change_p
)
3150 handled
= handle_overlay_change (it
);
3155 setup_for_ellipsis (it
, 0);
3159 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3161 /* Determine where to stop next. */
3162 if (handled
== HANDLED_NORMALLY
)
3163 compute_stop_pos (it
);
3167 /* Compute IT->stop_charpos from text property and overlay change
3168 information for IT's current position. */
3171 compute_stop_pos (it
)
3174 register INTERVAL iv
, next_iv
;
3175 Lisp_Object object
, limit
, position
;
3176 EMACS_INT charpos
, bytepos
;
3178 /* If nowhere else, stop at the end. */
3179 it
->stop_charpos
= it
->end_charpos
;
3181 if (STRINGP (it
->string
))
3183 /* Strings are usually short, so don't limit the search for
3185 object
= it
->string
;
3187 charpos
= IT_STRING_CHARPOS (*it
);
3188 bytepos
= IT_STRING_BYTEPOS (*it
);
3194 /* If next overlay change is in front of the current stop pos
3195 (which is IT->end_charpos), stop there. Note: value of
3196 next_overlay_change is point-max if no overlay change
3198 charpos
= IT_CHARPOS (*it
);
3199 bytepos
= IT_BYTEPOS (*it
);
3200 pos
= next_overlay_change (charpos
);
3201 if (pos
< it
->stop_charpos
)
3202 it
->stop_charpos
= pos
;
3204 /* If showing the region, we have to stop at the region
3205 start or end because the face might change there. */
3206 if (it
->region_beg_charpos
> 0)
3208 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3209 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3210 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3211 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3214 /* Set up variables for computing the stop position from text
3215 property changes. */
3216 XSETBUFFER (object
, current_buffer
);
3217 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3220 /* Get the interval containing IT's position. Value is a null
3221 interval if there isn't such an interval. */
3222 position
= make_number (charpos
);
3223 iv
= validate_interval_range (object
, &position
, &position
, 0);
3224 if (!NULL_INTERVAL_P (iv
))
3226 Lisp_Object values_here
[LAST_PROP_IDX
];
3229 /* Get properties here. */
3230 for (p
= it_props
; p
->handler
; ++p
)
3231 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3233 /* Look for an interval following iv that has different
3235 for (next_iv
= next_interval (iv
);
3236 (!NULL_INTERVAL_P (next_iv
)
3238 || XFASTINT (limit
) > next_iv
->position
));
3239 next_iv
= next_interval (next_iv
))
3241 for (p
= it_props
; p
->handler
; ++p
)
3243 Lisp_Object new_value
;
3245 new_value
= textget (next_iv
->plist
, *p
->name
);
3246 if (!EQ (values_here
[p
->idx
], new_value
))
3254 if (!NULL_INTERVAL_P (next_iv
))
3256 if (INTEGERP (limit
)
3257 && next_iv
->position
>= XFASTINT (limit
))
3258 /* No text property change up to limit. */
3259 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3261 /* Text properties change in next_iv. */
3262 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3266 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3267 it
->stop_charpos
, it
->string
);
3269 xassert (STRINGP (it
->string
)
3270 || (it
->stop_charpos
>= BEGV
3271 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3275 /* Return the position of the next overlay change after POS in
3276 current_buffer. Value is point-max if no overlay change
3277 follows. This is like `next-overlay-change' but doesn't use
3281 next_overlay_change (pos
)
3286 Lisp_Object
*overlays
;
3289 /* Get all overlays at the given position. */
3290 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3292 /* If any of these overlays ends before endpos,
3293 use its ending point instead. */
3294 for (i
= 0; i
< noverlays
; ++i
)
3299 oend
= OVERLAY_END (overlays
[i
]);
3300 oendpos
= OVERLAY_POSITION (oend
);
3301 endpos
= min (endpos
, oendpos
);
3309 /***********************************************************************
3311 ***********************************************************************/
3313 /* Handle changes in the `fontified' property of the current buffer by
3314 calling hook functions from Qfontification_functions to fontify
3317 static enum prop_handled
3318 handle_fontified_prop (it
)
3321 Lisp_Object prop
, pos
;
3322 enum prop_handled handled
= HANDLED_NORMALLY
;
3324 if (!NILP (Vmemory_full
))
3327 /* Get the value of the `fontified' property at IT's current buffer
3328 position. (The `fontified' property doesn't have a special
3329 meaning in strings.) If the value is nil, call functions from
3330 Qfontification_functions. */
3331 if (!STRINGP (it
->string
)
3333 && !NILP (Vfontification_functions
)
3334 && !NILP (Vrun_hooks
)
3335 && (pos
= make_number (IT_CHARPOS (*it
)),
3336 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3337 /* Ignore the special cased nil value always present at EOB since
3338 no amount of fontifying will be able to change it. */
3339 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3341 int count
= SPECPDL_INDEX ();
3344 val
= Vfontification_functions
;
3345 specbind (Qfontification_functions
, Qnil
);
3347 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3348 safe_call1 (val
, pos
);
3351 Lisp_Object globals
, fn
;
3352 struct gcpro gcpro1
, gcpro2
;
3355 GCPRO2 (val
, globals
);
3357 for (; CONSP (val
); val
= XCDR (val
))
3363 /* A value of t indicates this hook has a local
3364 binding; it means to run the global binding too.
3365 In a global value, t should not occur. If it
3366 does, we must ignore it to avoid an endless
3368 for (globals
= Fdefault_value (Qfontification_functions
);
3370 globals
= XCDR (globals
))
3372 fn
= XCAR (globals
);
3374 safe_call1 (fn
, pos
);
3378 safe_call1 (fn
, pos
);
3384 unbind_to (count
, Qnil
);
3386 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3387 something. This avoids an endless loop if they failed to
3388 fontify the text for which reason ever. */
3389 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3390 handled
= HANDLED_RECOMPUTE_PROPS
;
3398 /***********************************************************************
3400 ***********************************************************************/
3402 /* Set up iterator IT from face properties at its current position.
3403 Called from handle_stop. */
3405 static enum prop_handled
3406 handle_face_prop (it
)
3410 EMACS_INT next_stop
;
3412 if (!STRINGP (it
->string
))
3415 = face_at_buffer_position (it
->w
,
3417 it
->region_beg_charpos
,
3418 it
->region_end_charpos
,
3421 + TEXT_PROP_DISTANCE_LIMIT
),
3422 0, it
->base_face_id
);
3424 /* Is this a start of a run of characters with box face?
3425 Caveat: this can be called for a freshly initialized
3426 iterator; face_id is -1 in this case. We know that the new
3427 face will not change until limit, i.e. if the new face has a
3428 box, all characters up to limit will have one. But, as
3429 usual, we don't know whether limit is really the end. */
3430 if (new_face_id
!= it
->face_id
)
3432 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3434 /* If new face has a box but old face has not, this is
3435 the start of a run of characters with box, i.e. it has
3436 a shadow on the left side. The value of face_id of the
3437 iterator will be -1 if this is the initial call that gets
3438 the face. In this case, we have to look in front of IT's
3439 position and see whether there is a face != new_face_id. */
3440 it
->start_of_box_run_p
3441 = (new_face
->box
!= FACE_NO_BOX
3442 && (it
->face_id
>= 0
3443 || IT_CHARPOS (*it
) == BEG
3444 || new_face_id
!= face_before_it_pos (it
)));
3445 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3450 int base_face_id
, bufpos
;
3452 Lisp_Object from_overlay
3453 = (it
->current
.overlay_string_index
>= 0
3454 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3457 /* See if we got to this string directly or indirectly from
3458 an overlay property. That includes the before-string or
3459 after-string of an overlay, strings in display properties
3460 provided by an overlay, their text properties, etc.
3462 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3463 if (! NILP (from_overlay
))
3464 for (i
= it
->sp
- 1; i
>= 0; i
--)
3466 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3468 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3469 else if (! NILP (it
->stack
[i
].from_overlay
))
3470 from_overlay
= it
->stack
[i
].from_overlay
;
3472 if (!NILP (from_overlay
))
3476 if (! NILP (from_overlay
))
3478 bufpos
= IT_CHARPOS (*it
);
3479 /* For a string from an overlay, the base face depends
3480 only on text properties and ignores overlays. */
3482 = face_for_overlay_string (it
->w
,
3484 it
->region_beg_charpos
,
3485 it
->region_end_charpos
,
3488 + TEXT_PROP_DISTANCE_LIMIT
),
3496 /* For strings from a `display' property, use the face at
3497 IT's current buffer position as the base face to merge
3498 with, so that overlay strings appear in the same face as
3499 surrounding text, unless they specify their own
3501 base_face_id
= underlying_face_id (it
);
3504 new_face_id
= face_at_string_position (it
->w
,
3506 IT_STRING_CHARPOS (*it
),
3508 it
->region_beg_charpos
,
3509 it
->region_end_charpos
,
3513 /* Is this a start of a run of characters with box? Caveat:
3514 this can be called for a freshly allocated iterator; face_id
3515 is -1 is this case. We know that the new face will not
3516 change until the next check pos, i.e. if the new face has a
3517 box, all characters up to that position will have a
3518 box. But, as usual, we don't know whether that position
3519 is really the end. */
3520 if (new_face_id
!= it
->face_id
)
3522 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3523 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3525 /* If new face has a box but old face hasn't, this is the
3526 start of a run of characters with box, i.e. it has a
3527 shadow on the left side. */
3528 it
->start_of_box_run_p
3529 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3530 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3534 it
->face_id
= new_face_id
;
3535 return HANDLED_NORMALLY
;
3539 /* Return the ID of the face ``underlying'' IT's current position,
3540 which is in a string. If the iterator is associated with a
3541 buffer, return the face at IT's current buffer position.
3542 Otherwise, use the iterator's base_face_id. */
3545 underlying_face_id (it
)
3548 int face_id
= it
->base_face_id
, i
;
3550 xassert (STRINGP (it
->string
));
3552 for (i
= it
->sp
- 1; i
>= 0; --i
)
3553 if (NILP (it
->stack
[i
].string
))
3554 face_id
= it
->stack
[i
].face_id
;
3560 /* Compute the face one character before or after the current position
3561 of IT. BEFORE_P non-zero means get the face in front of IT's
3562 position. Value is the id of the face. */
3565 face_before_or_after_it_pos (it
, before_p
)
3570 EMACS_INT next_check_charpos
;
3571 struct text_pos pos
;
3573 xassert (it
->s
== NULL
);
3575 if (STRINGP (it
->string
))
3577 int bufpos
, base_face_id
;
3579 /* No face change past the end of the string (for the case
3580 we are padding with spaces). No face change before the
3582 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3583 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3586 /* Set pos to the position before or after IT's current position. */
3588 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3590 /* For composition, we must check the character after the
3592 pos
= (it
->what
== IT_COMPOSITION
3593 ? string_pos (IT_STRING_CHARPOS (*it
)
3594 + it
->cmp_it
.nchars
, it
->string
)
3595 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3597 if (it
->current
.overlay_string_index
>= 0)
3598 bufpos
= IT_CHARPOS (*it
);
3602 base_face_id
= underlying_face_id (it
);
3604 /* Get the face for ASCII, or unibyte. */
3605 face_id
= face_at_string_position (it
->w
,
3609 it
->region_beg_charpos
,
3610 it
->region_end_charpos
,
3611 &next_check_charpos
,
3614 /* Correct the face for charsets different from ASCII. Do it
3615 for the multibyte case only. The face returned above is
3616 suitable for unibyte text if IT->string is unibyte. */
3617 if (STRING_MULTIBYTE (it
->string
))
3619 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3620 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3622 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3624 c
= string_char_and_length (p
, &len
);
3625 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3630 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3631 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3634 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3635 pos
= it
->current
.pos
;
3638 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3641 if (it
->what
== IT_COMPOSITION
)
3642 /* For composition, we must check the position after the
3644 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3646 INC_TEXT_POS (pos
, it
->multibyte_p
);
3649 /* Determine face for CHARSET_ASCII, or unibyte. */
3650 face_id
= face_at_buffer_position (it
->w
,
3652 it
->region_beg_charpos
,
3653 it
->region_end_charpos
,
3654 &next_check_charpos
,
3657 /* Correct the face for charsets different from ASCII. Do it
3658 for the multibyte case only. The face returned above is
3659 suitable for unibyte text if current_buffer is unibyte. */
3660 if (it
->multibyte_p
)
3662 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3663 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3664 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3673 /***********************************************************************
3675 ***********************************************************************/
3677 /* Set up iterator IT from invisible properties at its current
3678 position. Called from handle_stop. */
3680 static enum prop_handled
3681 handle_invisible_prop (it
)
3684 enum prop_handled handled
= HANDLED_NORMALLY
;
3686 if (STRINGP (it
->string
))
3688 extern Lisp_Object Qinvisible
;
3689 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3691 /* Get the value of the invisible text property at the
3692 current position. Value will be nil if there is no such
3694 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3695 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3698 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3700 handled
= HANDLED_RECOMPUTE_PROPS
;
3702 /* Get the position at which the next change of the
3703 invisible text property can be found in IT->string.
3704 Value will be nil if the property value is the same for
3705 all the rest of IT->string. */
3706 XSETINT (limit
, SCHARS (it
->string
));
3707 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3710 /* Text at current position is invisible. The next
3711 change in the property is at position end_charpos.
3712 Move IT's current position to that position. */
3713 if (INTEGERP (end_charpos
)
3714 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3716 struct text_pos old
;
3717 old
= it
->current
.string_pos
;
3718 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3719 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3723 /* The rest of the string is invisible. If this is an
3724 overlay string, proceed with the next overlay string
3725 or whatever comes and return a character from there. */
3726 if (it
->current
.overlay_string_index
>= 0)
3728 next_overlay_string (it
);
3729 /* Don't check for overlay strings when we just
3730 finished processing them. */
3731 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3735 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3736 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3744 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3745 Lisp_Object pos
, prop
, overlay
;
3747 /* First of all, is there invisible text at this position? */
3748 tem
= start_charpos
= IT_CHARPOS (*it
);
3749 pos
= make_number (tem
);
3750 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3752 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3754 /* If we are on invisible text, skip over it. */
3755 if (invis_p
&& start_charpos
< it
->end_charpos
)
3757 /* Record whether we have to display an ellipsis for the
3759 int display_ellipsis_p
= invis_p
== 2;
3761 handled
= HANDLED_RECOMPUTE_PROPS
;
3763 /* Loop skipping over invisible text. The loop is left at
3764 ZV or with IT on the first char being visible again. */
3767 /* Try to skip some invisible text. Return value is the
3768 position reached which can be equal to where we start
3769 if there is nothing invisible there. This skips both
3770 over invisible text properties and overlays with
3771 invisible property. */
3772 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3774 /* If we skipped nothing at all we weren't at invisible
3775 text in the first place. If everything to the end of
3776 the buffer was skipped, end the loop. */
3777 if (newpos
== tem
|| newpos
>= ZV
)
3781 /* We skipped some characters but not necessarily
3782 all there are. Check if we ended up on visible
3783 text. Fget_char_property returns the property of
3784 the char before the given position, i.e. if we
3785 get invis_p = 0, this means that the char at
3786 newpos is visible. */
3787 pos
= make_number (newpos
);
3788 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3789 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3792 /* If we ended up on invisible text, proceed to
3793 skip starting with next_stop. */
3797 /* If there are adjacent invisible texts, don't lose the
3798 second one's ellipsis. */
3800 display_ellipsis_p
= 1;
3804 /* The position newpos is now either ZV or on visible text. */
3805 if (it
->bidi_p
&& newpos
< ZV
)
3807 /* With bidi iteration, the region of invisible text
3808 could start and/or end in the middle of a non-base
3809 embedding level. Therefore, we need to skip
3810 invisible text using the bidi iterator, starting at
3811 IT's current position, until we find ourselves
3812 outside the invisible text. Skipping invisible text
3813 _after_ bidi iteration avoids affecting the visual
3814 order of the displayed text when invisible properties
3815 are added or removed. */
3816 if (it
->bidi_it
.first_elt
)
3818 /* If we were `reseat'ed to a new paragraph,
3819 determine the paragraph base direction. We need
3820 to do it now because next_element_from_buffer may
3821 not have a chance to do it, if we are going to
3822 skip any text at the beginning, which resets the
3824 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
3828 bidi_get_next_char_visually (&it
->bidi_it
);
3830 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3831 && it
->bidi_it
.charpos
< newpos
);
3832 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3833 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3834 /* If we overstepped NEWPOS, record its position in the
3835 iterator, so that we skip invisible text if later the
3836 bidi iteration lands us in the invisible region
3838 if (IT_CHARPOS (*it
) >= newpos
)
3839 it
->prev_stop
= newpos
;
3843 IT_CHARPOS (*it
) = newpos
;
3844 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3847 /* If there are before-strings at the start of invisible
3848 text, and the text is invisible because of a text
3849 property, arrange to show before-strings because 20.x did
3850 it that way. (If the text is invisible because of an
3851 overlay property instead of a text property, this is
3852 already handled in the overlay code.) */
3854 && get_overlay_strings (it
, it
->stop_charpos
))
3856 handled
= HANDLED_RECOMPUTE_PROPS
;
3857 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3859 else if (display_ellipsis_p
)
3861 /* Make sure that the glyphs of the ellipsis will get
3862 correct `charpos' values. If we would not update
3863 it->position here, the glyphs would belong to the
3864 last visible character _before_ the invisible
3865 text, which confuses `set_cursor_from_row'.
3867 We use the last invisible position instead of the
3868 first because this way the cursor is always drawn on
3869 the first "." of the ellipsis, whenever PT is inside
3870 the invisible text. Otherwise the cursor would be
3871 placed _after_ the ellipsis when the point is after the
3872 first invisible character. */
3873 if (!STRINGP (it
->object
))
3875 it
->position
.charpos
= newpos
- 1;
3876 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3879 /* Let the ellipsis display before
3880 considering any properties of the following char.
3881 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3882 handled
= HANDLED_RETURN
;
3891 /* Make iterator IT return `...' next.
3892 Replaces LEN characters from buffer. */
3895 setup_for_ellipsis (it
, len
)
3899 /* Use the display table definition for `...'. Invalid glyphs
3900 will be handled by the method returning elements from dpvec. */
3901 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3903 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3904 it
->dpvec
= v
->contents
;
3905 it
->dpend
= v
->contents
+ v
->size
;
3909 /* Default `...'. */
3910 it
->dpvec
= default_invis_vector
;
3911 it
->dpend
= default_invis_vector
+ 3;
3914 it
->dpvec_char_len
= len
;
3915 it
->current
.dpvec_index
= 0;
3916 it
->dpvec_face_id
= -1;
3918 /* Remember the current face id in case glyphs specify faces.
3919 IT's face is restored in set_iterator_to_next.
3920 saved_face_id was set to preceding char's face in handle_stop. */
3921 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3922 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3924 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3930 /***********************************************************************
3932 ***********************************************************************/
3934 /* Set up iterator IT from `display' property at its current position.
3935 Called from handle_stop.
3936 We return HANDLED_RETURN if some part of the display property
3937 overrides the display of the buffer text itself.
3938 Otherwise we return HANDLED_NORMALLY. */
3940 static enum prop_handled
3941 handle_display_prop (it
)
3944 Lisp_Object prop
, object
, overlay
;
3945 struct text_pos
*position
;
3946 /* Nonzero if some property replaces the display of the text itself. */
3947 int display_replaced_p
= 0;
3949 if (STRINGP (it
->string
))
3951 object
= it
->string
;
3952 position
= &it
->current
.string_pos
;
3956 XSETWINDOW (object
, it
->w
);
3957 position
= &it
->current
.pos
;
3960 /* Reset those iterator values set from display property values. */
3961 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3962 it
->space_width
= Qnil
;
3963 it
->font_height
= Qnil
;
3966 /* We don't support recursive `display' properties, i.e. string
3967 values that have a string `display' property, that have a string
3968 `display' property etc. */
3969 if (!it
->string_from_display_prop_p
)
3970 it
->area
= TEXT_AREA
;
3972 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3973 Qdisplay
, object
, &overlay
);
3975 return HANDLED_NORMALLY
;
3976 /* Now OVERLAY is the overlay that gave us this property, or nil
3977 if it was a text property. */
3979 if (!STRINGP (it
->string
))
3980 object
= it
->w
->buffer
;
3983 /* Simple properties. */
3984 && !EQ (XCAR (prop
), Qimage
)
3985 && !EQ (XCAR (prop
), Qspace
)
3986 && !EQ (XCAR (prop
), Qwhen
)
3987 && !EQ (XCAR (prop
), Qslice
)
3988 && !EQ (XCAR (prop
), Qspace_width
)
3989 && !EQ (XCAR (prop
), Qheight
)
3990 && !EQ (XCAR (prop
), Qraise
)
3991 /* Marginal area specifications. */
3992 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3993 && !EQ (XCAR (prop
), Qleft_fringe
)
3994 && !EQ (XCAR (prop
), Qright_fringe
)
3995 && !NILP (XCAR (prop
)))
3997 for (; CONSP (prop
); prop
= XCDR (prop
))
3999 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
4000 position
, display_replaced_p
))
4002 display_replaced_p
= 1;
4003 /* If some text in a string is replaced, `position' no
4004 longer points to the position of `object'. */
4005 if (STRINGP (object
))
4010 else if (VECTORP (prop
))
4013 for (i
= 0; i
< ASIZE (prop
); ++i
)
4014 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4015 position
, display_replaced_p
))
4017 display_replaced_p
= 1;
4018 /* If some text in a string is replaced, `position' no
4019 longer points to the position of `object'. */
4020 if (STRINGP (object
))
4026 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4028 display_replaced_p
= 1;
4031 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4035 /* Value is the position of the end of the `display' property starting
4036 at START_POS in OBJECT. */
4038 static struct text_pos
4039 display_prop_end (it
, object
, start_pos
)
4042 struct text_pos start_pos
;
4045 struct text_pos end_pos
;
4047 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4048 Qdisplay
, object
, Qnil
);
4049 CHARPOS (end_pos
) = XFASTINT (end
);
4050 if (STRINGP (object
))
4051 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4053 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4059 /* Set up IT from a single `display' specification PROP. OBJECT
4060 is the object in which the `display' property was found. *POSITION
4061 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4062 means that we previously saw a display specification which already
4063 replaced text display with something else, for example an image;
4064 we ignore such properties after the first one has been processed.
4066 OVERLAY is the overlay this `display' property came from,
4067 or nil if it was a text property.
4069 If PROP is a `space' or `image' specification, and in some other
4070 cases too, set *POSITION to the position where the `display'
4073 Value is non-zero if something was found which replaces the display
4074 of buffer or string text. */
4077 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4078 display_replaced_before_p
)
4082 Lisp_Object overlay
;
4083 struct text_pos
*position
;
4084 int display_replaced_before_p
;
4087 Lisp_Object location
, value
;
4088 struct text_pos start_pos
, save_pos
;
4091 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4092 If the result is non-nil, use VALUE instead of SPEC. */
4094 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4103 if (!NILP (form
) && !EQ (form
, Qt
))
4105 int count
= SPECPDL_INDEX ();
4106 struct gcpro gcpro1
;
4108 /* Bind `object' to the object having the `display' property, a
4109 buffer or string. Bind `position' to the position in the
4110 object where the property was found, and `buffer-position'
4111 to the current position in the buffer. */
4112 specbind (Qobject
, object
);
4113 specbind (Qposition
, make_number (CHARPOS (*position
)));
4114 specbind (Qbuffer_position
,
4115 make_number (STRINGP (object
)
4116 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4118 form
= safe_eval (form
);
4120 unbind_to (count
, Qnil
);
4126 /* Handle `(height HEIGHT)' specifications. */
4128 && EQ (XCAR (spec
), Qheight
)
4129 && CONSP (XCDR (spec
)))
4131 if (!FRAME_WINDOW_P (it
->f
))
4134 it
->font_height
= XCAR (XCDR (spec
));
4135 if (!NILP (it
->font_height
))
4137 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4138 int new_height
= -1;
4140 if (CONSP (it
->font_height
)
4141 && (EQ (XCAR (it
->font_height
), Qplus
)
4142 || EQ (XCAR (it
->font_height
), Qminus
))
4143 && CONSP (XCDR (it
->font_height
))
4144 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4146 /* `(+ N)' or `(- N)' where N is an integer. */
4147 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4148 if (EQ (XCAR (it
->font_height
), Qplus
))
4150 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4152 else if (FUNCTIONP (it
->font_height
))
4154 /* Call function with current height as argument.
4155 Value is the new height. */
4157 height
= safe_call1 (it
->font_height
,
4158 face
->lface
[LFACE_HEIGHT_INDEX
]);
4159 if (NUMBERP (height
))
4160 new_height
= XFLOATINT (height
);
4162 else if (NUMBERP (it
->font_height
))
4164 /* Value is a multiple of the canonical char height. */
4167 face
= FACE_FROM_ID (it
->f
,
4168 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4169 new_height
= (XFLOATINT (it
->font_height
)
4170 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4174 /* Evaluate IT->font_height with `height' bound to the
4175 current specified height to get the new height. */
4176 int count
= SPECPDL_INDEX ();
4178 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4179 value
= safe_eval (it
->font_height
);
4180 unbind_to (count
, Qnil
);
4182 if (NUMBERP (value
))
4183 new_height
= XFLOATINT (value
);
4187 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4193 /* Handle `(space-width WIDTH)'. */
4195 && EQ (XCAR (spec
), Qspace_width
)
4196 && CONSP (XCDR (spec
)))
4198 if (!FRAME_WINDOW_P (it
->f
))
4201 value
= XCAR (XCDR (spec
));
4202 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4203 it
->space_width
= value
;
4208 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4210 && EQ (XCAR (spec
), Qslice
))
4214 if (!FRAME_WINDOW_P (it
->f
))
4217 if (tem
= XCDR (spec
), CONSP (tem
))
4219 it
->slice
.x
= XCAR (tem
);
4220 if (tem
= XCDR (tem
), CONSP (tem
))
4222 it
->slice
.y
= XCAR (tem
);
4223 if (tem
= XCDR (tem
), CONSP (tem
))
4225 it
->slice
.width
= XCAR (tem
);
4226 if (tem
= XCDR (tem
), CONSP (tem
))
4227 it
->slice
.height
= XCAR (tem
);
4235 /* Handle `(raise FACTOR)'. */
4237 && EQ (XCAR (spec
), Qraise
)
4238 && CONSP (XCDR (spec
)))
4240 if (!FRAME_WINDOW_P (it
->f
))
4243 #ifdef HAVE_WINDOW_SYSTEM
4244 value
= XCAR (XCDR (spec
));
4245 if (NUMBERP (value
))
4247 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4248 it
->voffset
= - (XFLOATINT (value
)
4249 * (FONT_HEIGHT (face
->font
)));
4251 #endif /* HAVE_WINDOW_SYSTEM */
4256 /* Don't handle the other kinds of display specifications
4257 inside a string that we got from a `display' property. */
4258 if (it
->string_from_display_prop_p
)
4261 /* Characters having this form of property are not displayed, so
4262 we have to find the end of the property. */
4263 start_pos
= *position
;
4264 *position
= display_prop_end (it
, object
, start_pos
);
4267 /* Stop the scan at that end position--we assume that all
4268 text properties change there. */
4269 it
->stop_charpos
= position
->charpos
;
4271 /* Handle `(left-fringe BITMAP [FACE])'
4272 and `(right-fringe BITMAP [FACE])'. */
4274 && (EQ (XCAR (spec
), Qleft_fringe
)
4275 || EQ (XCAR (spec
), Qright_fringe
))
4276 && CONSP (XCDR (spec
)))
4278 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4281 if (!FRAME_WINDOW_P (it
->f
))
4282 /* If we return here, POSITION has been advanced
4283 across the text with this property. */
4286 #ifdef HAVE_WINDOW_SYSTEM
4287 value
= XCAR (XCDR (spec
));
4288 if (!SYMBOLP (value
)
4289 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4290 /* If we return here, POSITION has been advanced
4291 across the text with this property. */
4294 if (CONSP (XCDR (XCDR (spec
))))
4296 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4297 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4303 /* Save current settings of IT so that we can restore them
4304 when we are finished with the glyph property value. */
4306 save_pos
= it
->position
;
4307 it
->position
= *position
;
4309 it
->position
= save_pos
;
4311 it
->area
= TEXT_AREA
;
4312 it
->what
= IT_IMAGE
;
4313 it
->image_id
= -1; /* no image */
4314 it
->position
= start_pos
;
4315 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4316 it
->method
= GET_FROM_IMAGE
;
4317 it
->from_overlay
= Qnil
;
4318 it
->face_id
= face_id
;
4320 /* Say that we haven't consumed the characters with
4321 `display' property yet. The call to pop_it in
4322 set_iterator_to_next will clean this up. */
4323 *position
= start_pos
;
4325 if (EQ (XCAR (spec
), Qleft_fringe
))
4327 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4328 it
->left_user_fringe_face_id
= face_id
;
4332 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4333 it
->right_user_fringe_face_id
= face_id
;
4335 #endif /* HAVE_WINDOW_SYSTEM */
4339 /* Prepare to handle `((margin left-margin) ...)',
4340 `((margin right-margin) ...)' and `((margin nil) ...)'
4341 prefixes for display specifications. */
4342 location
= Qunbound
;
4343 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4347 value
= XCDR (spec
);
4349 value
= XCAR (value
);
4352 if (EQ (XCAR (tem
), Qmargin
)
4353 && (tem
= XCDR (tem
),
4354 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4356 || EQ (tem
, Qleft_margin
)
4357 || EQ (tem
, Qright_margin
))))
4361 if (EQ (location
, Qunbound
))
4367 /* After this point, VALUE is the property after any
4368 margin prefix has been stripped. It must be a string,
4369 an image specification, or `(space ...)'.
4371 LOCATION specifies where to display: `left-margin',
4372 `right-margin' or nil. */
4374 valid_p
= (STRINGP (value
)
4375 #ifdef HAVE_WINDOW_SYSTEM
4376 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4377 #endif /* not HAVE_WINDOW_SYSTEM */
4378 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4380 if (valid_p
&& !display_replaced_before_p
)
4382 /* Save current settings of IT so that we can restore them
4383 when we are finished with the glyph property value. */
4384 save_pos
= it
->position
;
4385 it
->position
= *position
;
4387 it
->position
= save_pos
;
4388 it
->from_overlay
= overlay
;
4390 if (NILP (location
))
4391 it
->area
= TEXT_AREA
;
4392 else if (EQ (location
, Qleft_margin
))
4393 it
->area
= LEFT_MARGIN_AREA
;
4395 it
->area
= RIGHT_MARGIN_AREA
;
4397 if (STRINGP (value
))
4400 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4401 it
->current
.overlay_string_index
= -1;
4402 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4403 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4404 it
->method
= GET_FROM_STRING
;
4405 it
->stop_charpos
= 0;
4406 it
->string_from_display_prop_p
= 1;
4407 /* Say that we haven't consumed the characters with
4408 `display' property yet. The call to pop_it in
4409 set_iterator_to_next will clean this up. */
4410 if (BUFFERP (object
))
4411 *position
= start_pos
;
4413 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4415 it
->method
= GET_FROM_STRETCH
;
4417 *position
= it
->position
= start_pos
;
4419 #ifdef HAVE_WINDOW_SYSTEM
4422 it
->what
= IT_IMAGE
;
4423 it
->image_id
= lookup_image (it
->f
, value
);
4424 it
->position
= start_pos
;
4425 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4426 it
->method
= GET_FROM_IMAGE
;
4428 /* Say that we haven't consumed the characters with
4429 `display' property yet. The call to pop_it in
4430 set_iterator_to_next will clean this up. */
4431 *position
= start_pos
;
4433 #endif /* HAVE_WINDOW_SYSTEM */
4438 /* Invalid property or property not supported. Restore
4439 POSITION to what it was before. */
4440 *position
= start_pos
;
4445 /* Check if SPEC is a display sub-property value whose text should be
4446 treated as intangible. */
4449 single_display_spec_intangible_p (prop
)
4452 /* Skip over `when FORM'. */
4453 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4467 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4468 we don't need to treat text as intangible. */
4469 if (EQ (XCAR (prop
), Qmargin
))
4477 || EQ (XCAR (prop
), Qleft_margin
)
4478 || EQ (XCAR (prop
), Qright_margin
))
4482 return (CONSP (prop
)
4483 && (EQ (XCAR (prop
), Qimage
)
4484 || EQ (XCAR (prop
), Qspace
)));
4488 /* Check if PROP is a display property value whose text should be
4489 treated as intangible. */
4492 display_prop_intangible_p (prop
)
4496 && CONSP (XCAR (prop
))
4497 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4499 /* A list of sub-properties. */
4500 while (CONSP (prop
))
4502 if (single_display_spec_intangible_p (XCAR (prop
)))
4507 else if (VECTORP (prop
))
4509 /* A vector of sub-properties. */
4511 for (i
= 0; i
< ASIZE (prop
); ++i
)
4512 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4516 return single_display_spec_intangible_p (prop
);
4522 /* Return 1 if PROP is a display sub-property value containing STRING. */
4525 single_display_spec_string_p (prop
, string
)
4526 Lisp_Object prop
, string
;
4528 if (EQ (string
, prop
))
4531 /* Skip over `when FORM'. */
4532 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4541 /* Skip over `margin LOCATION'. */
4542 if (EQ (XCAR (prop
), Qmargin
))
4553 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4557 /* Return 1 if STRING appears in the `display' property PROP. */
4560 display_prop_string_p (prop
, string
)
4561 Lisp_Object prop
, string
;
4564 && CONSP (XCAR (prop
))
4565 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4567 /* A list of sub-properties. */
4568 while (CONSP (prop
))
4570 if (single_display_spec_string_p (XCAR (prop
), string
))
4575 else if (VECTORP (prop
))
4577 /* A vector of sub-properties. */
4579 for (i
= 0; i
< ASIZE (prop
); ++i
)
4580 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4584 return single_display_spec_string_p (prop
, string
);
4589 /* Look for STRING in overlays and text properties in W's buffer,
4590 between character positions FROM and TO (excluding TO).
4591 BACK_P non-zero means look back (in this case, TO is supposed to be
4593 Value is the first character position where STRING was found, or
4594 zero if it wasn't found before hitting TO.
4596 W's buffer must be current.
4598 This function may only use code that doesn't eval because it is
4599 called asynchronously from note_mouse_highlight. */
4602 string_buffer_position_lim (w
, string
, from
, to
, back_p
)
4608 Lisp_Object limit
, prop
, pos
;
4611 pos
= make_number (from
);
4613 if (!back_p
) /* looking forward */
4615 limit
= make_number (min (to
, ZV
));
4616 while (!found
&& !EQ (pos
, limit
))
4618 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4619 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4622 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4626 else /* looking back */
4628 limit
= make_number (max (to
, BEGV
));
4629 while (!found
&& !EQ (pos
, limit
))
4631 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4632 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4635 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4640 return found
? XINT (pos
) : 0;
4643 /* Determine which buffer position in W's buffer STRING comes from.
4644 AROUND_CHARPOS is an approximate position where it could come from.
4645 Value is the buffer position or 0 if it couldn't be determined.
4647 W's buffer must be current.
4649 This function is necessary because we don't record buffer positions
4650 in glyphs generated from strings (to keep struct glyph small).
4651 This function may only use code that doesn't eval because it is
4652 called asynchronously from note_mouse_highlight. */
4655 string_buffer_position (w
, string
, around_charpos
)
4658 EMACS_INT around_charpos
;
4660 Lisp_Object limit
, prop
, pos
;
4661 const int MAX_DISTANCE
= 1000;
4662 EMACS_INT found
= string_buffer_position_lim (w
, string
, around_charpos
,
4663 around_charpos
+ MAX_DISTANCE
,
4667 found
= string_buffer_position_lim (w
, string
, around_charpos
,
4668 around_charpos
- MAX_DISTANCE
, 1);
4674 /***********************************************************************
4675 `composition' property
4676 ***********************************************************************/
4678 /* Set up iterator IT from `composition' property at its current
4679 position. Called from handle_stop. */
4681 static enum prop_handled
4682 handle_composition_prop (it
)
4685 Lisp_Object prop
, string
;
4686 EMACS_INT pos
, pos_byte
, start
, end
;
4688 if (STRINGP (it
->string
))
4692 pos
= IT_STRING_CHARPOS (*it
);
4693 pos_byte
= IT_STRING_BYTEPOS (*it
);
4694 string
= it
->string
;
4695 s
= SDATA (string
) + pos_byte
;
4696 it
->c
= STRING_CHAR (s
);
4700 pos
= IT_CHARPOS (*it
);
4701 pos_byte
= IT_BYTEPOS (*it
);
4703 it
->c
= FETCH_CHAR (pos_byte
);
4706 /* If there's a valid composition and point is not inside of the
4707 composition (in the case that the composition is from the current
4708 buffer), draw a glyph composed from the composition components. */
4709 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4710 && COMPOSITION_VALID_P (start
, end
, prop
)
4711 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4715 if (STRINGP (it
->string
))
4716 pos_byte
= string_char_to_byte (it
->string
, start
);
4718 pos_byte
= CHAR_TO_BYTE (start
);
4720 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4723 if (it
->cmp_it
.id
>= 0)
4726 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4727 it
->cmp_it
.nglyphs
= -1;
4731 return HANDLED_NORMALLY
;
4736 /***********************************************************************
4738 ***********************************************************************/
4740 /* The following structure is used to record overlay strings for
4741 later sorting in load_overlay_strings. */
4743 struct overlay_entry
4745 Lisp_Object overlay
;
4752 /* Set up iterator IT from overlay strings at its current position.
4753 Called from handle_stop. */
4755 static enum prop_handled
4756 handle_overlay_change (it
)
4759 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4760 return HANDLED_RECOMPUTE_PROPS
;
4762 return HANDLED_NORMALLY
;
4766 /* Set up the next overlay string for delivery by IT, if there is an
4767 overlay string to deliver. Called by set_iterator_to_next when the
4768 end of the current overlay string is reached. If there are more
4769 overlay strings to display, IT->string and
4770 IT->current.overlay_string_index are set appropriately here.
4771 Otherwise IT->string is set to nil. */
4774 next_overlay_string (it
)
4777 ++it
->current
.overlay_string_index
;
4778 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4780 /* No more overlay strings. Restore IT's settings to what
4781 they were before overlay strings were processed, and
4782 continue to deliver from current_buffer. */
4784 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4787 || (NILP (it
->string
)
4788 && it
->method
== GET_FROM_BUFFER
4789 && it
->stop_charpos
>= BEGV
4790 && it
->stop_charpos
<= it
->end_charpos
));
4791 it
->current
.overlay_string_index
= -1;
4792 it
->n_overlay_strings
= 0;
4794 /* If we're at the end of the buffer, record that we have
4795 processed the overlay strings there already, so that
4796 next_element_from_buffer doesn't try it again. */
4797 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4798 it
->overlay_strings_at_end_processed_p
= 1;
4802 /* There are more overlay strings to process. If
4803 IT->current.overlay_string_index has advanced to a position
4804 where we must load IT->overlay_strings with more strings, do
4806 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4808 if (it
->current
.overlay_string_index
&& i
== 0)
4809 load_overlay_strings (it
, 0);
4811 /* Initialize IT to deliver display elements from the overlay
4813 it
->string
= it
->overlay_strings
[i
];
4814 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4815 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4816 it
->method
= GET_FROM_STRING
;
4817 it
->stop_charpos
= 0;
4818 if (it
->cmp_it
.stop_pos
>= 0)
4819 it
->cmp_it
.stop_pos
= 0;
4826 /* Compare two overlay_entry structures E1 and E2. Used as a
4827 comparison function for qsort in load_overlay_strings. Overlay
4828 strings for the same position are sorted so that
4830 1. All after-strings come in front of before-strings, except
4831 when they come from the same overlay.
4833 2. Within after-strings, strings are sorted so that overlay strings
4834 from overlays with higher priorities come first.
4836 2. Within before-strings, strings are sorted so that overlay
4837 strings from overlays with higher priorities come last.
4839 Value is analogous to strcmp. */
4843 compare_overlay_entries (e1
, e2
)
4846 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4847 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4850 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4852 /* Let after-strings appear in front of before-strings if
4853 they come from different overlays. */
4854 if (EQ (entry1
->overlay
, entry2
->overlay
))
4855 result
= entry1
->after_string_p
? 1 : -1;
4857 result
= entry1
->after_string_p
? -1 : 1;
4859 else if (entry1
->after_string_p
)
4860 /* After-strings sorted in order of decreasing priority. */
4861 result
= entry2
->priority
- entry1
->priority
;
4863 /* Before-strings sorted in order of increasing priority. */
4864 result
= entry1
->priority
- entry2
->priority
;
4870 /* Load the vector IT->overlay_strings with overlay strings from IT's
4871 current buffer position, or from CHARPOS if that is > 0. Set
4872 IT->n_overlays to the total number of overlay strings found.
4874 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4875 a time. On entry into load_overlay_strings,
4876 IT->current.overlay_string_index gives the number of overlay
4877 strings that have already been loaded by previous calls to this
4880 IT->add_overlay_start contains an additional overlay start
4881 position to consider for taking overlay strings from, if non-zero.
4882 This position comes into play when the overlay has an `invisible'
4883 property, and both before and after-strings. When we've skipped to
4884 the end of the overlay, because of its `invisible' property, we
4885 nevertheless want its before-string to appear.
4886 IT->add_overlay_start will contain the overlay start position
4889 Overlay strings are sorted so that after-string strings come in
4890 front of before-string strings. Within before and after-strings,
4891 strings are sorted by overlay priority. See also function
4892 compare_overlay_entries. */
4895 load_overlay_strings (it
, charpos
)
4899 extern Lisp_Object Qwindow
, Qpriority
;
4900 Lisp_Object overlay
, window
, str
, invisible
;
4901 struct Lisp_Overlay
*ov
;
4904 int n
= 0, i
, j
, invis_p
;
4905 struct overlay_entry
*entries
4906 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4909 charpos
= IT_CHARPOS (*it
);
4911 /* Append the overlay string STRING of overlay OVERLAY to vector
4912 `entries' which has size `size' and currently contains `n'
4913 elements. AFTER_P non-zero means STRING is an after-string of
4915 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4918 Lisp_Object priority; \
4922 int new_size = 2 * size; \
4923 struct overlay_entry *old = entries; \
4925 (struct overlay_entry *) alloca (new_size \
4926 * sizeof *entries); \
4927 bcopy (old, entries, size * sizeof *entries); \
4931 entries[n].string = (STRING); \
4932 entries[n].overlay = (OVERLAY); \
4933 priority = Foverlay_get ((OVERLAY), Qpriority); \
4934 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4935 entries[n].after_string_p = (AFTER_P); \
4940 /* Process overlay before the overlay center. */
4941 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4943 XSETMISC (overlay
, ov
);
4944 xassert (OVERLAYP (overlay
));
4945 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4946 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4951 /* Skip this overlay if it doesn't start or end at IT's current
4953 if (end
!= charpos
&& start
!= charpos
)
4956 /* Skip this overlay if it doesn't apply to IT->w. */
4957 window
= Foverlay_get (overlay
, Qwindow
);
4958 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4961 /* If the text ``under'' the overlay is invisible, both before-
4962 and after-strings from this overlay are visible; start and
4963 end position are indistinguishable. */
4964 invisible
= Foverlay_get (overlay
, Qinvisible
);
4965 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4967 /* If overlay has a non-empty before-string, record it. */
4968 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4969 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4971 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4973 /* If overlay has a non-empty after-string, record it. */
4974 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4975 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4977 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4980 /* Process overlays after the overlay center. */
4981 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4983 XSETMISC (overlay
, ov
);
4984 xassert (OVERLAYP (overlay
));
4985 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4986 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4988 if (start
> charpos
)
4991 /* Skip this overlay if it doesn't start or end at IT's current
4993 if (end
!= charpos
&& start
!= charpos
)
4996 /* Skip this overlay if it doesn't apply to IT->w. */
4997 window
= Foverlay_get (overlay
, Qwindow
);
4998 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5001 /* If the text ``under'' the overlay is invisible, it has a zero
5002 dimension, and both before- and after-strings apply. */
5003 invisible
= Foverlay_get (overlay
, Qinvisible
);
5004 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5006 /* If overlay has a non-empty before-string, record it. */
5007 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5008 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5010 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5012 /* If overlay has a non-empty after-string, record it. */
5013 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5014 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5016 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5019 #undef RECORD_OVERLAY_STRING
5023 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5025 /* Record the total number of strings to process. */
5026 it
->n_overlay_strings
= n
;
5028 /* IT->current.overlay_string_index is the number of overlay strings
5029 that have already been consumed by IT. Copy some of the
5030 remaining overlay strings to IT->overlay_strings. */
5032 j
= it
->current
.overlay_string_index
;
5033 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5035 it
->overlay_strings
[i
] = entries
[j
].string
;
5036 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5043 /* Get the first chunk of overlay strings at IT's current buffer
5044 position, or at CHARPOS if that is > 0. Value is non-zero if at
5045 least one overlay string was found. */
5048 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5053 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5054 process. This fills IT->overlay_strings with strings, and sets
5055 IT->n_overlay_strings to the total number of strings to process.
5056 IT->pos.overlay_string_index has to be set temporarily to zero
5057 because load_overlay_strings needs this; it must be set to -1
5058 when no overlay strings are found because a zero value would
5059 indicate a position in the first overlay string. */
5060 it
->current
.overlay_string_index
= 0;
5061 load_overlay_strings (it
, charpos
);
5063 /* If we found overlay strings, set up IT to deliver display
5064 elements from the first one. Otherwise set up IT to deliver
5065 from current_buffer. */
5066 if (it
->n_overlay_strings
)
5068 /* Make sure we know settings in current_buffer, so that we can
5069 restore meaningful values when we're done with the overlay
5072 compute_stop_pos (it
);
5073 xassert (it
->face_id
>= 0);
5075 /* Save IT's settings. They are restored after all overlay
5076 strings have been processed. */
5077 xassert (!compute_stop_p
|| it
->sp
== 0);
5079 /* When called from handle_stop, there might be an empty display
5080 string loaded. In that case, don't bother saving it. */
5081 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5084 /* Set up IT to deliver display elements from the first overlay
5086 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5087 it
->string
= it
->overlay_strings
[0];
5088 it
->from_overlay
= Qnil
;
5089 it
->stop_charpos
= 0;
5090 xassert (STRINGP (it
->string
));
5091 it
->end_charpos
= SCHARS (it
->string
);
5092 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5093 it
->method
= GET_FROM_STRING
;
5097 it
->current
.overlay_string_index
= -1;
5102 get_overlay_strings (it
, charpos
)
5107 it
->method
= GET_FROM_BUFFER
;
5109 (void) get_overlay_strings_1 (it
, charpos
, 1);
5113 /* Value is non-zero if we found at least one overlay string. */
5114 return STRINGP (it
->string
);
5119 /***********************************************************************
5120 Saving and restoring state
5121 ***********************************************************************/
5123 /* Save current settings of IT on IT->stack. Called, for example,
5124 before setting up IT for an overlay string, to be able to restore
5125 IT's settings to what they were after the overlay string has been
5132 struct iterator_stack_entry
*p
;
5134 xassert (it
->sp
< IT_STACK_SIZE
);
5135 p
= it
->stack
+ it
->sp
;
5137 p
->stop_charpos
= it
->stop_charpos
;
5138 p
->prev_stop
= it
->prev_stop
;
5139 p
->base_level_stop
= it
->base_level_stop
;
5140 p
->cmp_it
= it
->cmp_it
;
5141 xassert (it
->face_id
>= 0);
5142 p
->face_id
= it
->face_id
;
5143 p
->string
= it
->string
;
5144 p
->method
= it
->method
;
5145 p
->from_overlay
= it
->from_overlay
;
5148 case GET_FROM_IMAGE
:
5149 p
->u
.image
.object
= it
->object
;
5150 p
->u
.image
.image_id
= it
->image_id
;
5151 p
->u
.image
.slice
= it
->slice
;
5153 case GET_FROM_STRETCH
:
5154 p
->u
.stretch
.object
= it
->object
;
5157 p
->position
= it
->position
;
5158 p
->current
= it
->current
;
5159 p
->end_charpos
= it
->end_charpos
;
5160 p
->string_nchars
= it
->string_nchars
;
5162 p
->multibyte_p
= it
->multibyte_p
;
5163 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5164 p
->space_width
= it
->space_width
;
5165 p
->font_height
= it
->font_height
;
5166 p
->voffset
= it
->voffset
;
5167 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5168 p
->display_ellipsis_p
= 0;
5169 p
->line_wrap
= it
->line_wrap
;
5174 /* Restore IT's settings from IT->stack. Called, for example, when no
5175 more overlay strings must be processed, and we return to delivering
5176 display elements from a buffer, or when the end of a string from a
5177 `display' property is reached and we return to delivering display
5178 elements from an overlay string, or from a buffer. */
5184 struct iterator_stack_entry
*p
;
5186 xassert (it
->sp
> 0);
5188 p
= it
->stack
+ it
->sp
;
5189 it
->stop_charpos
= p
->stop_charpos
;
5190 it
->prev_stop
= p
->prev_stop
;
5191 it
->base_level_stop
= p
->base_level_stop
;
5192 it
->cmp_it
= p
->cmp_it
;
5193 it
->face_id
= p
->face_id
;
5194 it
->current
= p
->current
;
5195 it
->position
= p
->position
;
5196 it
->string
= p
->string
;
5197 it
->from_overlay
= p
->from_overlay
;
5198 if (NILP (it
->string
))
5199 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5200 it
->method
= p
->method
;
5203 case GET_FROM_IMAGE
:
5204 it
->image_id
= p
->u
.image
.image_id
;
5205 it
->object
= p
->u
.image
.object
;
5206 it
->slice
= p
->u
.image
.slice
;
5208 case GET_FROM_STRETCH
:
5209 it
->object
= p
->u
.comp
.object
;
5211 case GET_FROM_BUFFER
:
5212 it
->object
= it
->w
->buffer
;
5214 case GET_FROM_STRING
:
5215 it
->object
= it
->string
;
5217 case GET_FROM_DISPLAY_VECTOR
:
5219 it
->method
= GET_FROM_C_STRING
;
5220 else if (STRINGP (it
->string
))
5221 it
->method
= GET_FROM_STRING
;
5224 it
->method
= GET_FROM_BUFFER
;
5225 it
->object
= it
->w
->buffer
;
5228 it
->end_charpos
= p
->end_charpos
;
5229 it
->string_nchars
= p
->string_nchars
;
5231 it
->multibyte_p
= p
->multibyte_p
;
5232 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5233 it
->space_width
= p
->space_width
;
5234 it
->font_height
= p
->font_height
;
5235 it
->voffset
= p
->voffset
;
5236 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5237 it
->line_wrap
= p
->line_wrap
;
5242 /***********************************************************************
5244 ***********************************************************************/
5246 /* Set IT's current position to the previous line start. */
5249 back_to_previous_line_start (it
)
5252 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5253 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5257 /* Move IT to the next line start.
5259 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5260 we skipped over part of the text (as opposed to moving the iterator
5261 continuously over the text). Otherwise, don't change the value
5264 Newlines may come from buffer text, overlay strings, or strings
5265 displayed via the `display' property. That's the reason we can't
5266 simply use find_next_newline_no_quit.
5268 Note that this function may not skip over invisible text that is so
5269 because of text properties and immediately follows a newline. If
5270 it would, function reseat_at_next_visible_line_start, when called
5271 from set_iterator_to_next, would effectively make invisible
5272 characters following a newline part of the wrong glyph row, which
5273 leads to wrong cursor motion. */
5276 forward_to_next_line_start (it
, skipped_p
)
5280 int old_selective
, newline_found_p
, n
;
5281 const int MAX_NEWLINE_DISTANCE
= 500;
5283 /* If already on a newline, just consume it to avoid unintended
5284 skipping over invisible text below. */
5285 if (it
->what
== IT_CHARACTER
5287 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5289 set_iterator_to_next (it
, 0);
5294 /* Don't handle selective display in the following. It's (a)
5295 unnecessary because it's done by the caller, and (b) leads to an
5296 infinite recursion because next_element_from_ellipsis indirectly
5297 calls this function. */
5298 old_selective
= it
->selective
;
5301 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5302 from buffer text. */
5303 for (n
= newline_found_p
= 0;
5304 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5305 n
+= STRINGP (it
->string
) ? 0 : 1)
5307 if (!get_next_display_element (it
))
5309 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5310 set_iterator_to_next (it
, 0);
5313 /* If we didn't find a newline near enough, see if we can use a
5315 if (!newline_found_p
)
5317 int start
= IT_CHARPOS (*it
);
5318 int limit
= find_next_newline_no_quit (start
, 1);
5321 xassert (!STRINGP (it
->string
));
5323 /* If there isn't any `display' property in sight, and no
5324 overlays, we can just use the position of the newline in
5326 if (it
->stop_charpos
>= limit
5327 || ((pos
= Fnext_single_property_change (make_number (start
),
5329 Qnil
, make_number (limit
)),
5331 && next_overlay_change (start
) == ZV
))
5333 IT_CHARPOS (*it
) = limit
;
5334 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5335 *skipped_p
= newline_found_p
= 1;
5339 while (get_next_display_element (it
)
5340 && !newline_found_p
)
5342 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5343 set_iterator_to_next (it
, 0);
5348 it
->selective
= old_selective
;
5349 return newline_found_p
;
5353 /* Set IT's current position to the previous visible line start. Skip
5354 invisible text that is so either due to text properties or due to
5355 selective display. Caution: this does not change IT->current_x and
5359 back_to_previous_visible_line_start (it
)
5362 while (IT_CHARPOS (*it
) > BEGV
)
5364 back_to_previous_line_start (it
);
5366 if (IT_CHARPOS (*it
) <= BEGV
)
5369 /* If selective > 0, then lines indented more than its value are
5371 if (it
->selective
> 0
5372 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5373 (double) it
->selective
)) /* iftc */
5376 /* Check the newline before point for invisibility. */
5379 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5380 Qinvisible
, it
->window
);
5381 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5385 if (IT_CHARPOS (*it
) <= BEGV
)
5392 Lisp_Object val
, overlay
;
5394 /* If newline is part of a composition, continue from start of composition */
5395 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5396 && beg
< IT_CHARPOS (*it
))
5399 /* If newline is replaced by a display property, find start of overlay
5400 or interval and continue search from that point. */
5402 pos
= --IT_CHARPOS (it2
);
5405 it2
.string_from_display_prop_p
= 0;
5406 if (handle_display_prop (&it2
) == HANDLED_RETURN
5407 && !NILP (val
= get_char_property_and_overlay
5408 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5409 && (OVERLAYP (overlay
)
5410 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5411 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5414 /* Newline is not replaced by anything -- so we are done. */
5420 IT_CHARPOS (*it
) = beg
;
5421 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5425 it
->continuation_lines_width
= 0;
5427 xassert (IT_CHARPOS (*it
) >= BEGV
);
5428 xassert (IT_CHARPOS (*it
) == BEGV
5429 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5434 /* Reseat iterator IT at the previous visible line start. Skip
5435 invisible text that is so either due to text properties or due to
5436 selective display. At the end, update IT's overlay information,
5437 face information etc. */
5440 reseat_at_previous_visible_line_start (it
)
5443 back_to_previous_visible_line_start (it
);
5444 reseat (it
, it
->current
.pos
, 1);
5449 /* Reseat iterator IT on the next visible line start in the current
5450 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5451 preceding the line start. Skip over invisible text that is so
5452 because of selective display. Compute faces, overlays etc at the
5453 new position. Note that this function does not skip over text that
5454 is invisible because of text properties. */
5457 reseat_at_next_visible_line_start (it
, on_newline_p
)
5461 int newline_found_p
, skipped_p
= 0;
5463 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5465 /* Skip over lines that are invisible because they are indented
5466 more than the value of IT->selective. */
5467 if (it
->selective
> 0)
5468 while (IT_CHARPOS (*it
) < ZV
5469 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5470 (double) it
->selective
)) /* iftc */
5472 xassert (IT_BYTEPOS (*it
) == BEGV
5473 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5474 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5477 /* Position on the newline if that's what's requested. */
5478 if (on_newline_p
&& newline_found_p
)
5480 if (STRINGP (it
->string
))
5482 if (IT_STRING_CHARPOS (*it
) > 0)
5484 --IT_STRING_CHARPOS (*it
);
5485 --IT_STRING_BYTEPOS (*it
);
5488 else if (IT_CHARPOS (*it
) > BEGV
)
5492 reseat (it
, it
->current
.pos
, 0);
5496 reseat (it
, it
->current
.pos
, 0);
5503 /***********************************************************************
5504 Changing an iterator's position
5505 ***********************************************************************/
5507 /* Change IT's current position to POS in current_buffer. If FORCE_P
5508 is non-zero, always check for text properties at the new position.
5509 Otherwise, text properties are only looked up if POS >=
5510 IT->check_charpos of a property. */
5513 reseat (it
, pos
, force_p
)
5515 struct text_pos pos
;
5518 int original_pos
= IT_CHARPOS (*it
);
5520 reseat_1 (it
, pos
, 0);
5522 /* Determine where to check text properties. Avoid doing it
5523 where possible because text property lookup is very expensive. */
5525 || CHARPOS (pos
) > it
->stop_charpos
5526 || CHARPOS (pos
) < original_pos
)
5530 /* For bidi iteration, we need to prime prev_stop and
5531 base_level_stop with our best estimations. */
5532 if (CHARPOS (pos
) < it
->prev_stop
)
5534 handle_stop_backwards (it
, BEGV
);
5535 if (CHARPOS (pos
) < it
->base_level_stop
)
5536 it
->base_level_stop
= 0;
5538 else if (CHARPOS (pos
) > it
->stop_charpos
5539 && it
->stop_charpos
>= BEGV
)
5540 handle_stop_backwards (it
, it
->stop_charpos
);
5547 it
->prev_stop
= it
->base_level_stop
= 0;
5556 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5557 IT->stop_pos to POS, also. */
5560 reseat_1 (it
, pos
, set_stop_p
)
5562 struct text_pos pos
;
5565 /* Don't call this function when scanning a C string. */
5566 xassert (it
->s
== NULL
);
5568 /* POS must be a reasonable value. */
5569 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5571 it
->current
.pos
= it
->position
= pos
;
5572 it
->end_charpos
= ZV
;
5574 it
->current
.dpvec_index
= -1;
5575 it
->current
.overlay_string_index
= -1;
5576 IT_STRING_CHARPOS (*it
) = -1;
5577 IT_STRING_BYTEPOS (*it
) = -1;
5579 it
->string_from_display_prop_p
= 0;
5580 it
->method
= GET_FROM_BUFFER
;
5581 it
->object
= it
->w
->buffer
;
5582 it
->area
= TEXT_AREA
;
5583 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5585 it
->string_from_display_prop_p
= 0;
5586 it
->face_before_selective_p
= 0;
5588 it
->bidi_it
.first_elt
= 1;
5592 it
->stop_charpos
= CHARPOS (pos
);
5593 it
->base_level_stop
= CHARPOS (pos
);
5598 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5599 If S is non-null, it is a C string to iterate over. Otherwise,
5600 STRING gives a Lisp string to iterate over.
5602 If PRECISION > 0, don't return more then PRECISION number of
5603 characters from the string.
5605 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5606 characters have been returned. FIELD_WIDTH < 0 means an infinite
5609 MULTIBYTE = 0 means disable processing of multibyte characters,
5610 MULTIBYTE > 0 means enable it,
5611 MULTIBYTE < 0 means use IT->multibyte_p.
5613 IT must be initialized via a prior call to init_iterator before
5614 calling this function. */
5617 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5622 int precision
, field_width
, multibyte
;
5624 /* No region in strings. */
5625 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5627 /* No text property checks performed by default, but see below. */
5628 it
->stop_charpos
= -1;
5630 /* Set iterator position and end position. */
5631 bzero (&it
->current
, sizeof it
->current
);
5632 it
->current
.overlay_string_index
= -1;
5633 it
->current
.dpvec_index
= -1;
5634 xassert (charpos
>= 0);
5636 /* If STRING is specified, use its multibyteness, otherwise use the
5637 setting of MULTIBYTE, if specified. */
5639 it
->multibyte_p
= multibyte
> 0;
5643 xassert (STRINGP (string
));
5644 it
->string
= string
;
5646 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5647 it
->method
= GET_FROM_STRING
;
5648 it
->current
.string_pos
= string_pos (charpos
, string
);
5655 /* Note that we use IT->current.pos, not it->current.string_pos,
5656 for displaying C strings. */
5657 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5658 if (it
->multibyte_p
)
5660 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5661 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5665 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5666 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5669 it
->method
= GET_FROM_C_STRING
;
5672 /* PRECISION > 0 means don't return more than PRECISION characters
5674 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5675 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5677 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5678 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5679 FIELD_WIDTH < 0 means infinite field width. This is useful for
5680 padding with `-' at the end of a mode line. */
5681 if (field_width
< 0)
5682 field_width
= INFINITY
;
5683 if (field_width
> it
->end_charpos
- charpos
)
5684 it
->end_charpos
= charpos
+ field_width
;
5686 /* Use the standard display table for displaying strings. */
5687 if (DISP_TABLE_P (Vstandard_display_table
))
5688 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5690 it
->stop_charpos
= charpos
;
5691 if (s
== NULL
&& it
->multibyte_p
)
5693 EMACS_INT endpos
= SCHARS (it
->string
);
5694 if (endpos
> it
->end_charpos
)
5695 endpos
= it
->end_charpos
;
5696 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5704 /***********************************************************************
5706 ***********************************************************************/
5708 /* Map enum it_method value to corresponding next_element_from_* function. */
5710 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5712 next_element_from_buffer
,
5713 next_element_from_display_vector
,
5714 next_element_from_string
,
5715 next_element_from_c_string
,
5716 next_element_from_image
,
5717 next_element_from_stretch
5720 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5723 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5724 (possibly with the following characters). */
5726 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5727 ((IT)->cmp_it.id >= 0 \
5728 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5729 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5730 END_CHARPOS, (IT)->w, \
5731 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5735 /* Load IT's display element fields with information about the next
5736 display element from the current position of IT. Value is zero if
5737 end of buffer (or C string) is reached. */
5739 static struct frame
*last_escape_glyph_frame
= NULL
;
5740 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5741 static int last_escape_glyph_merged_face_id
= 0;
5744 get_next_display_element (it
)
5747 /* Non-zero means that we found a display element. Zero means that
5748 we hit the end of what we iterate over. Performance note: the
5749 function pointer `method' used here turns out to be faster than
5750 using a sequence of if-statements. */
5754 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5756 if (it
->what
== IT_CHARACTER
)
5758 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5759 and only if (a) the resolved directionality of that character
5761 /* FIXME: Do we need an exception for characters from display
5763 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5764 it
->c
= bidi_mirror_char (it
->c
);
5765 /* Map via display table or translate control characters.
5766 IT->c, IT->len etc. have been set to the next character by
5767 the function call above. If we have a display table, and it
5768 contains an entry for IT->c, translate it. Don't do this if
5769 IT->c itself comes from a display table, otherwise we could
5770 end up in an infinite recursion. (An alternative could be to
5771 count the recursion depth of this function and signal an
5772 error when a certain maximum depth is reached.) Is it worth
5774 if (success_p
&& it
->dpvec
== NULL
)
5777 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5778 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5779 nbsp_or_shy
= char_is_other
;
5780 int decoded
= it
->c
;
5783 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5786 struct Lisp_Vector
*v
= XVECTOR (dv
);
5788 /* Return the first character from the display table
5789 entry, if not empty. If empty, don't display the
5790 current character. */
5793 it
->dpvec_char_len
= it
->len
;
5794 it
->dpvec
= v
->contents
;
5795 it
->dpend
= v
->contents
+ v
->size
;
5796 it
->current
.dpvec_index
= 0;
5797 it
->dpvec_face_id
= -1;
5798 it
->saved_face_id
= it
->face_id
;
5799 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5804 set_iterator_to_next (it
, 0);
5809 if (unibyte_display_via_language_environment
5810 && !ASCII_CHAR_P (it
->c
))
5811 decoded
= DECODE_CHAR (unibyte
, it
->c
);
5813 if (it
->c
>= 0x80 && ! NILP (Vnobreak_char_display
))
5815 if (it
->multibyte_p
)
5816 nbsp_or_shy
= (it
->c
== 0xA0 ? char_is_nbsp
5817 : it
->c
== 0xAD ? char_is_soft_hyphen
5819 else if (unibyte_display_via_language_environment
)
5820 nbsp_or_shy
= (decoded
== 0xA0 ? char_is_nbsp
5821 : decoded
== 0xAD ? char_is_soft_hyphen
5825 /* Translate control characters into `\003' or `^C' form.
5826 Control characters coming from a display table entry are
5827 currently not translated because we use IT->dpvec to hold
5828 the translation. This could easily be changed but I
5829 don't believe that it is worth doing.
5831 If it->multibyte_p is nonzero, non-printable non-ASCII
5832 characters are also translated to octal form.
5834 If it->multibyte_p is zero, eight-bit characters that
5835 don't have corresponding multibyte char code are also
5836 translated to octal form. */
5838 ? (it
->area
!= TEXT_AREA
5839 /* In mode line, treat \n, \t like other crl chars. */
5842 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5843 || (it
->c
!= '\n' && it
->c
!= '\t'))
5846 ? ! CHAR_PRINTABLE_P (it
->c
)
5847 : (! unibyte_display_via_language_environment
5849 : (decoded
>= 0x80 && decoded
< 0xA0))))))
5851 /* IT->c is a control character which must be displayed
5852 either as '\003' or as `^C' where the '\\' and '^'
5853 can be defined in the display table. Fill
5854 IT->ctl_chars with glyphs for what we have to
5855 display. Then, set IT->dpvec to these glyphs. */
5858 int face_id
, lface_id
= 0 ;
5861 /* Handle control characters with ^. */
5863 if (it
->c
< 128 && it
->ctl_arrow_p
)
5867 g
= '^'; /* default glyph for Control */
5868 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5870 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5871 && GLYPH_CODE_CHAR_VALID_P (gc
))
5873 g
= GLYPH_CODE_CHAR (gc
);
5874 lface_id
= GLYPH_CODE_FACE (gc
);
5878 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5880 else if (it
->f
== last_escape_glyph_frame
5881 && it
->face_id
== last_escape_glyph_face_id
)
5883 face_id
= last_escape_glyph_merged_face_id
;
5887 /* Merge the escape-glyph face into the current face. */
5888 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5890 last_escape_glyph_frame
= it
->f
;
5891 last_escape_glyph_face_id
= it
->face_id
;
5892 last_escape_glyph_merged_face_id
= face_id
;
5895 XSETINT (it
->ctl_chars
[0], g
);
5896 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5898 goto display_control
;
5901 /* Handle non-break space in the mode where it only gets
5904 if (EQ (Vnobreak_char_display
, Qt
)
5905 && nbsp_or_shy
== char_is_nbsp
)
5907 /* Merge the no-break-space face into the current face. */
5908 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5912 XSETINT (it
->ctl_chars
[0], ' ');
5914 goto display_control
;
5917 /* Handle sequences that start with the "escape glyph". */
5919 /* the default escape glyph is \. */
5920 escape_glyph
= '\\';
5923 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5924 && GLYPH_CODE_CHAR_VALID_P (gc
))
5926 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5927 lface_id
= GLYPH_CODE_FACE (gc
);
5931 /* The display table specified a face.
5932 Merge it into face_id and also into escape_glyph. */
5933 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5936 else if (it
->f
== last_escape_glyph_frame
5937 && it
->face_id
== last_escape_glyph_face_id
)
5939 face_id
= last_escape_glyph_merged_face_id
;
5943 /* Merge the escape-glyph face into the current face. */
5944 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5946 last_escape_glyph_frame
= it
->f
;
5947 last_escape_glyph_face_id
= it
->face_id
;
5948 last_escape_glyph_merged_face_id
= face_id
;
5951 /* Handle soft hyphens in the mode where they only get
5954 if (EQ (Vnobreak_char_display
, Qt
)
5955 && nbsp_or_shy
== char_is_soft_hyphen
)
5958 XSETINT (it
->ctl_chars
[0], '-');
5960 goto display_control
;
5963 /* Handle non-break space and soft hyphen
5964 with the escape glyph. */
5968 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5969 it
->c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5970 XSETINT (it
->ctl_chars
[1], it
->c
);
5972 goto display_control
;
5976 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5980 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5981 if (CHAR_BYTE8_P (it
->c
))
5983 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5986 else if (it
->c
< 256)
5993 /* It's an invalid character, which shouldn't
5994 happen actually, but due to bugs it may
5995 happen. Let's print the char as is, there's
5996 not much meaningful we can do with it. */
5998 str
[1] = it
->c
>> 8;
5999 str
[2] = it
->c
>> 16;
6000 str
[3] = it
->c
>> 24;
6004 for (i
= 0; i
< len
; i
++)
6007 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
6008 /* Insert three more glyphs into IT->ctl_chars for
6009 the octal display of the character. */
6010 g
= ((str
[i
] >> 6) & 7) + '0';
6011 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
6012 g
= ((str
[i
] >> 3) & 7) + '0';
6013 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
6014 g
= (str
[i
] & 7) + '0';
6015 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
6021 /* Set up IT->dpvec and return first character from it. */
6022 it
->dpvec_char_len
= it
->len
;
6023 it
->dpvec
= it
->ctl_chars
;
6024 it
->dpend
= it
->dpvec
+ ctl_len
;
6025 it
->current
.dpvec_index
= 0;
6026 it
->dpvec_face_id
= face_id
;
6027 it
->saved_face_id
= it
->face_id
;
6028 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6035 #ifdef HAVE_WINDOW_SYSTEM
6036 /* Adjust face id for a multibyte character. There are no multibyte
6037 character in unibyte text. */
6038 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6041 && FRAME_WINDOW_P (it
->f
))
6043 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6045 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6047 /* Automatic composition with glyph-string. */
6048 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6050 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6054 int pos
= (it
->s
? -1
6055 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6056 : IT_CHARPOS (*it
));
6058 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
6063 /* Is this character the last one of a run of characters with
6064 box? If yes, set IT->end_of_box_run_p to 1. */
6068 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6070 int face_id
= underlying_face_id (it
);
6071 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6075 if (face
->box
== FACE_NO_BOX
)
6077 /* If the box comes from face properties in a
6078 display string, check faces in that string. */
6079 int string_face_id
= face_after_it_pos (it
);
6080 it
->end_of_box_run_p
6081 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6084 /* Otherwise, the box comes from the underlying face.
6085 If this is the last string character displayed, check
6086 the next buffer location. */
6087 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6088 && (it
->current
.overlay_string_index
6089 == it
->n_overlay_strings
- 1))
6093 struct text_pos pos
= it
->current
.pos
;
6094 INC_TEXT_POS (pos
, it
->multibyte_p
);
6096 next_face_id
= face_at_buffer_position
6097 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6098 it
->region_end_charpos
, &ignore
,
6099 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6101 it
->end_of_box_run_p
6102 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6109 int face_id
= face_after_it_pos (it
);
6110 it
->end_of_box_run_p
6111 = (face_id
!= it
->face_id
6112 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6116 /* Value is 0 if end of buffer or string reached. */
6121 /* Move IT to the next display element.
6123 RESEAT_P non-zero means if called on a newline in buffer text,
6124 skip to the next visible line start.
6126 Functions get_next_display_element and set_iterator_to_next are
6127 separate because I find this arrangement easier to handle than a
6128 get_next_display_element function that also increments IT's
6129 position. The way it is we can first look at an iterator's current
6130 display element, decide whether it fits on a line, and if it does,
6131 increment the iterator position. The other way around we probably
6132 would either need a flag indicating whether the iterator has to be
6133 incremented the next time, or we would have to implement a
6134 decrement position function which would not be easy to write. */
6137 set_iterator_to_next (it
, reseat_p
)
6141 /* Reset flags indicating start and end of a sequence of characters
6142 with box. Reset them at the start of this function because
6143 moving the iterator to a new position might set them. */
6144 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6148 case GET_FROM_BUFFER
:
6149 /* The current display element of IT is a character from
6150 current_buffer. Advance in the buffer, and maybe skip over
6151 invisible lines that are so because of selective display. */
6152 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6153 reseat_at_next_visible_line_start (it
, 0);
6154 else if (it
->cmp_it
.id
>= 0)
6156 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6157 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6158 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6159 it
->cmp_it
.from
= it
->cmp_it
.to
;
6163 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6164 IT_BYTEPOS (*it
), it
->stop_charpos
,
6170 xassert (it
->len
!= 0);
6174 IT_BYTEPOS (*it
) += it
->len
;
6175 IT_CHARPOS (*it
) += 1;
6179 /* If this is a new paragraph, determine its base
6180 direction (a.k.a. its base embedding level). */
6181 if (it
->bidi_it
.new_paragraph
)
6182 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6183 bidi_get_next_char_visually (&it
->bidi_it
);
6184 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6185 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6187 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6191 case GET_FROM_C_STRING
:
6192 /* Current display element of IT is from a C string. */
6193 IT_BYTEPOS (*it
) += it
->len
;
6194 IT_CHARPOS (*it
) += 1;
6197 case GET_FROM_DISPLAY_VECTOR
:
6198 /* Current display element of IT is from a display table entry.
6199 Advance in the display table definition. Reset it to null if
6200 end reached, and continue with characters from buffers/
6202 ++it
->current
.dpvec_index
;
6204 /* Restore face of the iterator to what they were before the
6205 display vector entry (these entries may contain faces). */
6206 it
->face_id
= it
->saved_face_id
;
6208 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6210 int recheck_faces
= it
->ellipsis_p
;
6213 it
->method
= GET_FROM_C_STRING
;
6214 else if (STRINGP (it
->string
))
6215 it
->method
= GET_FROM_STRING
;
6218 it
->method
= GET_FROM_BUFFER
;
6219 it
->object
= it
->w
->buffer
;
6223 it
->current
.dpvec_index
= -1;
6225 /* Skip over characters which were displayed via IT->dpvec. */
6226 if (it
->dpvec_char_len
< 0)
6227 reseat_at_next_visible_line_start (it
, 1);
6228 else if (it
->dpvec_char_len
> 0)
6230 if (it
->method
== GET_FROM_STRING
6231 && it
->n_overlay_strings
> 0)
6232 it
->ignore_overlay_strings_at_pos_p
= 1;
6233 it
->len
= it
->dpvec_char_len
;
6234 set_iterator_to_next (it
, reseat_p
);
6237 /* Maybe recheck faces after display vector */
6239 it
->stop_charpos
= IT_CHARPOS (*it
);
6243 case GET_FROM_STRING
:
6244 /* Current display element is a character from a Lisp string. */
6245 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6246 if (it
->cmp_it
.id
>= 0)
6248 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6249 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6250 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6251 it
->cmp_it
.from
= it
->cmp_it
.to
;
6255 composition_compute_stop_pos (&it
->cmp_it
,
6256 IT_STRING_CHARPOS (*it
),
6257 IT_STRING_BYTEPOS (*it
),
6258 it
->stop_charpos
, it
->string
);
6263 IT_STRING_BYTEPOS (*it
) += it
->len
;
6264 IT_STRING_CHARPOS (*it
) += 1;
6267 consider_string_end
:
6269 if (it
->current
.overlay_string_index
>= 0)
6271 /* IT->string is an overlay string. Advance to the
6272 next, if there is one. */
6273 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6276 next_overlay_string (it
);
6278 setup_for_ellipsis (it
, 0);
6283 /* IT->string is not an overlay string. If we reached
6284 its end, and there is something on IT->stack, proceed
6285 with what is on the stack. This can be either another
6286 string, this time an overlay string, or a buffer. */
6287 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6291 if (it
->method
== GET_FROM_STRING
)
6292 goto consider_string_end
;
6297 case GET_FROM_IMAGE
:
6298 case GET_FROM_STRETCH
:
6299 /* The position etc with which we have to proceed are on
6300 the stack. The position may be at the end of a string,
6301 if the `display' property takes up the whole string. */
6302 xassert (it
->sp
> 0);
6304 if (it
->method
== GET_FROM_STRING
)
6305 goto consider_string_end
;
6309 /* There are no other methods defined, so this should be a bug. */
6313 xassert (it
->method
!= GET_FROM_STRING
6314 || (STRINGP (it
->string
)
6315 && IT_STRING_CHARPOS (*it
) >= 0));
6318 /* Load IT's display element fields with information about the next
6319 display element which comes from a display table entry or from the
6320 result of translating a control character to one of the forms `^C'
6323 IT->dpvec holds the glyphs to return as characters.
6324 IT->saved_face_id holds the face id before the display vector--it
6325 is restored into IT->face_id in set_iterator_to_next. */
6328 next_element_from_display_vector (it
)
6334 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6336 it
->face_id
= it
->saved_face_id
;
6338 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6339 That seemed totally bogus - so I changed it... */
6340 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6342 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6344 it
->c
= GLYPH_CODE_CHAR (gc
);
6345 it
->len
= CHAR_BYTES (it
->c
);
6347 /* The entry may contain a face id to use. Such a face id is
6348 the id of a Lisp face, not a realized face. A face id of
6349 zero means no face is specified. */
6350 if (it
->dpvec_face_id
>= 0)
6351 it
->face_id
= it
->dpvec_face_id
;
6354 int lface_id
= GLYPH_CODE_FACE (gc
);
6356 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6361 /* Display table entry is invalid. Return a space. */
6362 it
->c
= ' ', it
->len
= 1;
6364 /* Don't change position and object of the iterator here. They are
6365 still the values of the character that had this display table
6366 entry or was translated, and that's what we want. */
6367 it
->what
= IT_CHARACTER
;
6372 /* Load IT with the next display element from Lisp string IT->string.
6373 IT->current.string_pos is the current position within the string.
6374 If IT->current.overlay_string_index >= 0, the Lisp string is an
6378 next_element_from_string (it
)
6381 struct text_pos position
;
6383 xassert (STRINGP (it
->string
));
6384 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6385 position
= it
->current
.string_pos
;
6387 /* Time to check for invisible text? */
6388 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6389 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6393 /* Since a handler may have changed IT->method, we must
6395 return GET_NEXT_DISPLAY_ELEMENT (it
);
6398 if (it
->current
.overlay_string_index
>= 0)
6400 /* Get the next character from an overlay string. In overlay
6401 strings, There is no field width or padding with spaces to
6403 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6408 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6409 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6410 && next_element_from_composition (it
))
6414 else if (STRING_MULTIBYTE (it
->string
))
6416 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6417 const unsigned char *s
= (SDATA (it
->string
)
6418 + IT_STRING_BYTEPOS (*it
));
6419 it
->c
= string_char_and_length (s
, &it
->len
);
6423 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6429 /* Get the next character from a Lisp string that is not an
6430 overlay string. Such strings come from the mode line, for
6431 example. We may have to pad with spaces, or truncate the
6432 string. See also next_element_from_c_string. */
6433 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6438 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6440 /* Pad with spaces. */
6441 it
->c
= ' ', it
->len
= 1;
6442 CHARPOS (position
) = BYTEPOS (position
) = -1;
6444 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6445 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6446 && next_element_from_composition (it
))
6450 else if (STRING_MULTIBYTE (it
->string
))
6452 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6453 const unsigned char *s
= (SDATA (it
->string
)
6454 + IT_STRING_BYTEPOS (*it
));
6455 it
->c
= string_char_and_length (s
, &it
->len
);
6459 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6464 /* Record what we have and where it came from. */
6465 it
->what
= IT_CHARACTER
;
6466 it
->object
= it
->string
;
6467 it
->position
= position
;
6472 /* Load IT with next display element from C string IT->s.
6473 IT->string_nchars is the maximum number of characters to return
6474 from the string. IT->end_charpos may be greater than
6475 IT->string_nchars when this function is called, in which case we
6476 may have to return padding spaces. Value is zero if end of string
6477 reached, including padding spaces. */
6480 next_element_from_c_string (it
)
6486 it
->what
= IT_CHARACTER
;
6487 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6490 /* IT's position can be greater IT->string_nchars in case a field
6491 width or precision has been specified when the iterator was
6493 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6495 /* End of the game. */
6499 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6501 /* Pad with spaces. */
6502 it
->c
= ' ', it
->len
= 1;
6503 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6505 else if (it
->multibyte_p
)
6507 /* Implementation note: The calls to strlen apparently aren't a
6508 performance problem because there is no noticeable performance
6509 difference between Emacs running in unibyte or multibyte mode. */
6510 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6511 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6514 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6520 /* Set up IT to return characters from an ellipsis, if appropriate.
6521 The definition of the ellipsis glyphs may come from a display table
6522 entry. This function fills IT with the first glyph from the
6523 ellipsis if an ellipsis is to be displayed. */
6526 next_element_from_ellipsis (it
)
6529 if (it
->selective_display_ellipsis_p
)
6530 setup_for_ellipsis (it
, it
->len
);
6533 /* The face at the current position may be different from the
6534 face we find after the invisible text. Remember what it
6535 was in IT->saved_face_id, and signal that it's there by
6536 setting face_before_selective_p. */
6537 it
->saved_face_id
= it
->face_id
;
6538 it
->method
= GET_FROM_BUFFER
;
6539 it
->object
= it
->w
->buffer
;
6540 reseat_at_next_visible_line_start (it
, 1);
6541 it
->face_before_selective_p
= 1;
6544 return GET_NEXT_DISPLAY_ELEMENT (it
);
6548 /* Deliver an image display element. The iterator IT is already
6549 filled with image information (done in handle_display_prop). Value
6554 next_element_from_image (it
)
6557 it
->what
= IT_IMAGE
;
6562 /* Fill iterator IT with next display element from a stretch glyph
6563 property. IT->object is the value of the text property. Value is
6567 next_element_from_stretch (it
)
6570 it
->what
= IT_STRETCH
;
6574 /* Scan forward from CHARPOS in the current buffer, until we find a
6575 stop position > current IT's position. Then handle the stop
6576 position before that. This is called when we bump into a stop
6577 position while reordering bidirectional text. CHARPOS should be
6578 the last previously processed stop_pos (or BEGV, if none were
6579 processed yet) whose position is less that IT's current
6583 handle_stop_backwards (it
, charpos
)
6587 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6588 struct display_pos save_current
= it
->current
;
6589 struct text_pos save_position
= it
->position
;
6590 struct text_pos pos1
;
6591 EMACS_INT next_stop
;
6593 /* Scan in strict logical order. */
6597 it
->prev_stop
= charpos
;
6598 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6599 reseat_1 (it
, pos1
, 0);
6600 compute_stop_pos (it
);
6601 /* We must advance forward, right? */
6602 if (it
->stop_charpos
<= it
->prev_stop
)
6604 charpos
= it
->stop_charpos
;
6606 while (charpos
<= where_we_are
);
6608 next_stop
= it
->stop_charpos
;
6609 it
->stop_charpos
= it
->prev_stop
;
6611 it
->current
= save_current
;
6612 it
->position
= save_position
;
6614 it
->stop_charpos
= next_stop
;
6617 /* Load IT with the next display element from current_buffer. Value
6618 is zero if end of buffer reached. IT->stop_charpos is the next
6619 position at which to stop and check for text properties or buffer
6623 next_element_from_buffer (it
)
6628 xassert (IT_CHARPOS (*it
) >= BEGV
);
6630 /* With bidi reordering, the character to display might not be the
6631 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6632 we were reseat()ed to a new buffer position, which is potentially
6633 a different paragraph. */
6634 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6636 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6637 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6638 /* If we are at the beginning of a line, we can produce the next
6639 element right away. */
6640 if (it
->bidi_it
.bytepos
== BEGV_BYTE
6641 /* FIXME: Should support all Unicode line separators. */
6642 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6643 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6645 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6646 bidi_get_next_char_visually (&it
->bidi_it
);
6650 int orig_bytepos
= IT_BYTEPOS (*it
);
6652 /* We need to prime the bidi iterator starting at the line's
6653 beginning, before we will be able to produce the next
6655 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6656 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6657 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6658 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6659 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6662 /* Now return to buffer position where we were asked to
6663 get the next display element, and produce that. */
6664 bidi_get_next_char_visually (&it
->bidi_it
);
6666 while (it
->bidi_it
.bytepos
!= orig_bytepos
6667 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6670 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6671 /* Adjust IT's position information to where we ended up. */
6672 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6673 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6674 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6677 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6679 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6681 int overlay_strings_follow_p
;
6683 /* End of the game, except when overlay strings follow that
6684 haven't been returned yet. */
6685 if (it
->overlay_strings_at_end_processed_p
)
6686 overlay_strings_follow_p
= 0;
6689 it
->overlay_strings_at_end_processed_p
= 1;
6690 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6693 if (overlay_strings_follow_p
)
6694 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6698 it
->position
= it
->current
.pos
;
6702 else if (!(!it
->bidi_p
6703 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6704 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6706 /* With bidi non-linear iteration, we could find ourselves
6707 far beyond the last computed stop_charpos, with several
6708 other stop positions in between that we missed. Scan
6709 them all now, in buffer's logical order, until we find
6710 and handle the last stop_charpos that precedes our
6711 current position. */
6712 handle_stop_backwards (it
, it
->stop_charpos
);
6713 return GET_NEXT_DISPLAY_ELEMENT (it
);
6719 /* Take note of the stop position we just moved across,
6720 for when we will move back across it. */
6721 it
->prev_stop
= it
->stop_charpos
;
6722 /* If we are at base paragraph embedding level, take
6723 note of the last stop position seen at this
6725 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6726 it
->base_level_stop
= it
->stop_charpos
;
6729 return GET_NEXT_DISPLAY_ELEMENT (it
);
6733 /* We can sometimes back up for reasons that have nothing
6734 to do with bidi reordering. E.g., compositions. The
6735 code below is only needed when we are above the base
6736 embedding level, so test for that explicitly. */
6737 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6738 && IT_CHARPOS (*it
) < it
->prev_stop
)
6740 if (it
->base_level_stop
<= 0)
6741 it
->base_level_stop
= BEGV
;
6742 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6744 handle_stop_backwards (it
, it
->base_level_stop
);
6745 return GET_NEXT_DISPLAY_ELEMENT (it
);
6749 /* No face changes, overlays etc. in sight, so just return a
6750 character from current_buffer. */
6753 /* Maybe run the redisplay end trigger hook. Performance note:
6754 This doesn't seem to cost measurable time. */
6755 if (it
->redisplay_end_trigger_charpos
6757 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6758 run_redisplay_end_trigger_hook (it
);
6760 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6762 && next_element_from_composition (it
))
6767 /* Get the next character, maybe multibyte. */
6768 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6769 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6770 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6772 it
->c
= *p
, it
->len
= 1;
6774 /* Record what we have and where it came from. */
6775 it
->what
= IT_CHARACTER
;
6776 it
->object
= it
->w
->buffer
;
6777 it
->position
= it
->current
.pos
;
6779 /* Normally we return the character found above, except when we
6780 really want to return an ellipsis for selective display. */
6785 /* A value of selective > 0 means hide lines indented more
6786 than that number of columns. */
6787 if (it
->selective
> 0
6788 && IT_CHARPOS (*it
) + 1 < ZV
6789 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6790 IT_BYTEPOS (*it
) + 1,
6791 (double) it
->selective
)) /* iftc */
6793 success_p
= next_element_from_ellipsis (it
);
6794 it
->dpvec_char_len
= -1;
6797 else if (it
->c
== '\r' && it
->selective
== -1)
6799 /* A value of selective == -1 means that everything from the
6800 CR to the end of the line is invisible, with maybe an
6801 ellipsis displayed for it. */
6802 success_p
= next_element_from_ellipsis (it
);
6803 it
->dpvec_char_len
= -1;
6808 /* Value is zero if end of buffer reached. */
6809 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6814 /* Run the redisplay end trigger hook for IT. */
6817 run_redisplay_end_trigger_hook (it
)
6820 Lisp_Object args
[3];
6822 /* IT->glyph_row should be non-null, i.e. we should be actually
6823 displaying something, or otherwise we should not run the hook. */
6824 xassert (it
->glyph_row
);
6826 /* Set up hook arguments. */
6827 args
[0] = Qredisplay_end_trigger_functions
;
6828 args
[1] = it
->window
;
6829 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6830 it
->redisplay_end_trigger_charpos
= 0;
6832 /* Since we are *trying* to run these functions, don't try to run
6833 them again, even if they get an error. */
6834 it
->w
->redisplay_end_trigger
= Qnil
;
6835 Frun_hook_with_args (3, args
);
6837 /* Notice if it changed the face of the character we are on. */
6838 handle_face_prop (it
);
6842 /* Deliver a composition display element. Unlike the other
6843 next_element_from_XXX, this function is not registered in the array
6844 get_next_element[]. It is called from next_element_from_buffer and
6845 next_element_from_string when necessary. */
6848 next_element_from_composition (it
)
6851 it
->what
= IT_COMPOSITION
;
6852 it
->len
= it
->cmp_it
.nbytes
;
6853 if (STRINGP (it
->string
))
6857 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6858 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6861 it
->position
= it
->current
.string_pos
;
6862 it
->object
= it
->string
;
6863 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6864 IT_STRING_BYTEPOS (*it
), it
->string
);
6870 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6871 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6874 it
->position
= it
->current
.pos
;
6875 it
->object
= it
->w
->buffer
;
6876 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6877 IT_BYTEPOS (*it
), Qnil
);
6884 /***********************************************************************
6885 Moving an iterator without producing glyphs
6886 ***********************************************************************/
6888 /* Check if iterator is at a position corresponding to a valid buffer
6889 position after some move_it_ call. */
6891 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6892 ((it)->method == GET_FROM_STRING \
6893 ? IT_STRING_CHARPOS (*it) == 0 \
6897 /* Move iterator IT to a specified buffer or X position within one
6898 line on the display without producing glyphs.
6900 OP should be a bit mask including some or all of these bits:
6901 MOVE_TO_X: Stop upon reaching x-position TO_X.
6902 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
6903 Regardless of OP's value, stop upon reaching the end of the display line.
6905 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6906 This means, in particular, that TO_X includes window's horizontal
6909 The return value has several possible values that
6910 say what condition caused the scan to stop:
6912 MOVE_POS_MATCH_OR_ZV
6913 - when TO_POS or ZV was reached.
6916 -when TO_X was reached before TO_POS or ZV were reached.
6919 - when we reached the end of the display area and the line must
6923 - when we reached the end of the display area and the line is
6927 - when we stopped at a line end, i.e. a newline or a CR and selective
6930 static enum move_it_result
6931 move_it_in_display_line_to (struct it
*it
,
6932 EMACS_INT to_charpos
, int to_x
,
6933 enum move_operation_enum op
)
6935 enum move_it_result result
= MOVE_UNDEFINED
;
6936 struct glyph_row
*saved_glyph_row
;
6937 struct it wrap_it
, atpos_it
, atx_it
;
6939 enum it_method prev_method
= it
->method
;
6940 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
6942 /* Don't produce glyphs in produce_glyphs. */
6943 saved_glyph_row
= it
->glyph_row
;
6944 it
->glyph_row
= NULL
;
6946 /* Use wrap_it to save a copy of IT wherever a word wrap could
6947 occur. Use atpos_it to save a copy of IT at the desired buffer
6948 position, if found, so that we can scan ahead and check if the
6949 word later overshoots the window edge. Use atx_it similarly, for
6955 #define BUFFER_POS_REACHED_P() \
6956 ((op & MOVE_TO_POS) != 0 \
6957 && BUFFERP (it->object) \
6958 && (IT_CHARPOS (*it) == to_charpos \
6959 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
6960 && (it->method == GET_FROM_BUFFER \
6961 || (it->method == GET_FROM_DISPLAY_VECTOR \
6962 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6964 /* If there's a line-/wrap-prefix, handle it. */
6965 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6966 && it
->current_y
< it
->last_visible_y
)
6967 handle_line_prefix (it
);
6971 int x
, i
, ascent
= 0, descent
= 0;
6973 /* Utility macro to reset an iterator with x, ascent, and descent. */
6974 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6975 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6976 (IT)->max_descent = descent)
6978 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6980 if ((op
& MOVE_TO_POS
) != 0
6981 && BUFFERP (it
->object
)
6982 && it
->method
== GET_FROM_BUFFER
6983 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
6985 && (prev_method
== GET_FROM_IMAGE
6986 || prev_method
== GET_FROM_STRETCH
)
6987 /* Passed TO_CHARPOS from left to right. */
6988 && ((prev_pos
< to_charpos
6989 && IT_CHARPOS (*it
) > to_charpos
)
6990 /* Passed TO_CHARPOS from right to left. */
6991 || (prev_pos
> to_charpos
6992 && IT_CHARPOS (*it
) < to_charpos
)))))
6994 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6996 result
= MOVE_POS_MATCH_OR_ZV
;
6999 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7000 /* If wrap_it is valid, the current position might be in a
7001 word that is wrapped. So, save the iterator in
7002 atpos_it and continue to see if wrapping happens. */
7006 prev_method
= it
->method
;
7007 if (it
->method
== GET_FROM_BUFFER
)
7008 prev_pos
= IT_CHARPOS (*it
);
7009 /* Stop when ZV reached.
7010 We used to stop here when TO_CHARPOS reached as well, but that is
7011 too soon if this glyph does not fit on this line. So we handle it
7012 explicitly below. */
7013 if (!get_next_display_element (it
))
7015 result
= MOVE_POS_MATCH_OR_ZV
;
7019 if (it
->line_wrap
== TRUNCATE
)
7021 if (BUFFER_POS_REACHED_P ())
7023 result
= MOVE_POS_MATCH_OR_ZV
;
7029 if (it
->line_wrap
== WORD_WRAP
)
7031 if (IT_DISPLAYING_WHITESPACE (it
))
7035 /* We have reached a glyph that follows one or more
7036 whitespace characters. If the position is
7037 already found, we are done. */
7038 if (atpos_it
.sp
>= 0)
7041 result
= MOVE_POS_MATCH_OR_ZV
;
7047 result
= MOVE_X_REACHED
;
7050 /* Otherwise, we can wrap here. */
7057 /* Remember the line height for the current line, in case
7058 the next element doesn't fit on the line. */
7059 ascent
= it
->max_ascent
;
7060 descent
= it
->max_descent
;
7062 /* The call to produce_glyphs will get the metrics of the
7063 display element IT is loaded with. Record the x-position
7064 before this display element, in case it doesn't fit on the
7068 PRODUCE_GLYPHS (it
);
7070 if (it
->area
!= TEXT_AREA
)
7072 set_iterator_to_next (it
, 1);
7076 /* The number of glyphs we get back in IT->nglyphs will normally
7077 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7078 character on a terminal frame, or (iii) a line end. For the
7079 second case, IT->nglyphs - 1 padding glyphs will be present.
7080 (On X frames, there is only one glyph produced for a
7081 composite character.)
7083 The behavior implemented below means, for continuation lines,
7084 that as many spaces of a TAB as fit on the current line are
7085 displayed there. For terminal frames, as many glyphs of a
7086 multi-glyph character are displayed in the current line, too.
7087 This is what the old redisplay code did, and we keep it that
7088 way. Under X, the whole shape of a complex character must
7089 fit on the line or it will be completely displayed in the
7092 Note that both for tabs and padding glyphs, all glyphs have
7096 /* More than one glyph or glyph doesn't fit on line. All
7097 glyphs have the same width. */
7098 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7100 int x_before_this_char
= x
;
7101 int hpos_before_this_char
= it
->hpos
;
7103 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7105 new_x
= x
+ single_glyph_width
;
7107 /* We want to leave anything reaching TO_X to the caller. */
7108 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7110 if (BUFFER_POS_REACHED_P ())
7112 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7113 goto buffer_pos_reached
;
7114 if (atpos_it
.sp
< 0)
7117 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7122 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7125 result
= MOVE_X_REACHED
;
7131 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7136 if (/* Lines are continued. */
7137 it
->line_wrap
!= TRUNCATE
7138 && (/* And glyph doesn't fit on the line. */
7139 new_x
> it
->last_visible_x
7140 /* Or it fits exactly and we're on a window
7142 || (new_x
== it
->last_visible_x
7143 && FRAME_WINDOW_P (it
->f
))))
7145 if (/* IT->hpos == 0 means the very first glyph
7146 doesn't fit on the line, e.g. a wide image. */
7148 || (new_x
== it
->last_visible_x
7149 && FRAME_WINDOW_P (it
->f
)))
7152 it
->current_x
= new_x
;
7154 /* The character's last glyph just barely fits
7156 if (i
== it
->nglyphs
- 1)
7158 /* If this is the destination position,
7159 return a position *before* it in this row,
7160 now that we know it fits in this row. */
7161 if (BUFFER_POS_REACHED_P ())
7163 if (it
->line_wrap
!= WORD_WRAP
7166 it
->hpos
= hpos_before_this_char
;
7167 it
->current_x
= x_before_this_char
;
7168 result
= MOVE_POS_MATCH_OR_ZV
;
7171 if (it
->line_wrap
== WORD_WRAP
7175 atpos_it
.current_x
= x_before_this_char
;
7176 atpos_it
.hpos
= hpos_before_this_char
;
7180 set_iterator_to_next (it
, 1);
7181 /* On graphical terminals, newlines may
7182 "overflow" into the fringe if
7183 overflow-newline-into-fringe is non-nil.
7184 On text-only terminals, newlines may
7185 overflow into the last glyph on the
7187 if (!FRAME_WINDOW_P (it
->f
)
7188 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7190 if (!get_next_display_element (it
))
7192 result
= MOVE_POS_MATCH_OR_ZV
;
7195 if (BUFFER_POS_REACHED_P ())
7197 if (ITERATOR_AT_END_OF_LINE_P (it
))
7198 result
= MOVE_POS_MATCH_OR_ZV
;
7200 result
= MOVE_LINE_CONTINUED
;
7203 if (ITERATOR_AT_END_OF_LINE_P (it
))
7205 result
= MOVE_NEWLINE_OR_CR
;
7212 IT_RESET_X_ASCENT_DESCENT (it
);
7214 if (wrap_it
.sp
>= 0)
7221 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7223 result
= MOVE_LINE_CONTINUED
;
7227 if (BUFFER_POS_REACHED_P ())
7229 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7230 goto buffer_pos_reached
;
7231 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7234 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7238 if (new_x
> it
->first_visible_x
)
7240 /* Glyph is visible. Increment number of glyphs that
7241 would be displayed. */
7246 if (result
!= MOVE_UNDEFINED
)
7249 else if (BUFFER_POS_REACHED_P ())
7252 IT_RESET_X_ASCENT_DESCENT (it
);
7253 result
= MOVE_POS_MATCH_OR_ZV
;
7256 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7258 /* Stop when TO_X specified and reached. This check is
7259 necessary here because of lines consisting of a line end,
7260 only. The line end will not produce any glyphs and we
7261 would never get MOVE_X_REACHED. */
7262 xassert (it
->nglyphs
== 0);
7263 result
= MOVE_X_REACHED
;
7267 /* Is this a line end? If yes, we're done. */
7268 if (ITERATOR_AT_END_OF_LINE_P (it
))
7270 result
= MOVE_NEWLINE_OR_CR
;
7274 if (it
->method
== GET_FROM_BUFFER
)
7275 prev_pos
= IT_CHARPOS (*it
);
7276 /* The current display element has been consumed. Advance
7278 set_iterator_to_next (it
, 1);
7280 /* Stop if lines are truncated and IT's current x-position is
7281 past the right edge of the window now. */
7282 if (it
->line_wrap
== TRUNCATE
7283 && it
->current_x
>= it
->last_visible_x
)
7285 if (!FRAME_WINDOW_P (it
->f
)
7286 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7288 if (!get_next_display_element (it
)
7289 || BUFFER_POS_REACHED_P ())
7291 result
= MOVE_POS_MATCH_OR_ZV
;
7294 if (ITERATOR_AT_END_OF_LINE_P (it
))
7296 result
= MOVE_NEWLINE_OR_CR
;
7300 result
= MOVE_LINE_TRUNCATED
;
7303 #undef IT_RESET_X_ASCENT_DESCENT
7306 #undef BUFFER_POS_REACHED_P
7308 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7309 restore the saved iterator. */
7310 if (atpos_it
.sp
>= 0)
7312 else if (atx_it
.sp
>= 0)
7317 /* Restore the iterator settings altered at the beginning of this
7319 it
->glyph_row
= saved_glyph_row
;
7323 /* For external use. */
7325 move_it_in_display_line (struct it
*it
,
7326 EMACS_INT to_charpos
, int to_x
,
7327 enum move_operation_enum op
)
7329 if (it
->line_wrap
== WORD_WRAP
7330 && (op
& MOVE_TO_X
))
7332 struct it save_it
= *it
;
7333 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7334 /* When word-wrap is on, TO_X may lie past the end
7335 of a wrapped line. Then it->current is the
7336 character on the next line, so backtrack to the
7337 space before the wrap point. */
7338 if (skip
== MOVE_LINE_CONTINUED
)
7340 int prev_x
= max (it
->current_x
- 1, 0);
7342 move_it_in_display_line_to
7343 (it
, -1, prev_x
, MOVE_TO_X
);
7347 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7351 /* Move IT forward until it satisfies one or more of the criteria in
7352 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7354 OP is a bit-mask that specifies where to stop, and in particular,
7355 which of those four position arguments makes a difference. See the
7356 description of enum move_operation_enum.
7358 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7359 screen line, this function will set IT to the next position >
7363 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7365 int to_charpos
, to_x
, to_y
, to_vpos
;
7368 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7369 int line_height
, line_start_x
= 0, reached
= 0;
7373 if (op
& MOVE_TO_VPOS
)
7375 /* If no TO_CHARPOS and no TO_X specified, stop at the
7376 start of the line TO_VPOS. */
7377 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7379 if (it
->vpos
== to_vpos
)
7385 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7389 /* TO_VPOS >= 0 means stop at TO_X in the line at
7390 TO_VPOS, or at TO_POS, whichever comes first. */
7391 if (it
->vpos
== to_vpos
)
7397 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7399 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7404 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7406 /* We have reached TO_X but not in the line we want. */
7407 skip
= move_it_in_display_line_to (it
, to_charpos
,
7409 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7417 else if (op
& MOVE_TO_Y
)
7419 struct it it_backup
;
7421 if (it
->line_wrap
== WORD_WRAP
)
7424 /* TO_Y specified means stop at TO_X in the line containing
7425 TO_Y---or at TO_CHARPOS if this is reached first. The
7426 problem is that we can't really tell whether the line
7427 contains TO_Y before we have completely scanned it, and
7428 this may skip past TO_X. What we do is to first scan to
7431 If TO_X is not specified, use a TO_X of zero. The reason
7432 is to make the outcome of this function more predictable.
7433 If we didn't use TO_X == 0, we would stop at the end of
7434 the line which is probably not what a caller would expect
7436 skip
= move_it_in_display_line_to
7437 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7438 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7440 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7441 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7443 else if (skip
== MOVE_X_REACHED
)
7445 /* If TO_X was reached, we want to know whether TO_Y is
7446 in the line. We know this is the case if the already
7447 scanned glyphs make the line tall enough. Otherwise,
7448 we must check by scanning the rest of the line. */
7449 line_height
= it
->max_ascent
+ it
->max_descent
;
7450 if (to_y
>= it
->current_y
7451 && to_y
< it
->current_y
+ line_height
)
7457 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7458 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7460 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7461 line_height
= it
->max_ascent
+ it
->max_descent
;
7462 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7464 if (to_y
>= it
->current_y
7465 && to_y
< it
->current_y
+ line_height
)
7467 /* If TO_Y is in this line and TO_X was reached
7468 above, we scanned too far. We have to restore
7469 IT's settings to the ones before skipping. */
7476 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7482 /* Check whether TO_Y is in this line. */
7483 line_height
= it
->max_ascent
+ it
->max_descent
;
7484 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7486 if (to_y
>= it
->current_y
7487 && to_y
< it
->current_y
+ line_height
)
7489 /* When word-wrap is on, TO_X may lie past the end
7490 of a wrapped line. Then it->current is the
7491 character on the next line, so backtrack to the
7492 space before the wrap point. */
7493 if (skip
== MOVE_LINE_CONTINUED
7494 && it
->line_wrap
== WORD_WRAP
)
7496 int prev_x
= max (it
->current_x
- 1, 0);
7498 skip
= move_it_in_display_line_to
7499 (it
, -1, prev_x
, MOVE_TO_X
);
7508 else if (BUFFERP (it
->object
)
7509 && (it
->method
== GET_FROM_BUFFER
7510 || it
->method
== GET_FROM_STRETCH
)
7511 && IT_CHARPOS (*it
) >= to_charpos
)
7512 skip
= MOVE_POS_MATCH_OR_ZV
;
7514 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7518 case MOVE_POS_MATCH_OR_ZV
:
7522 case MOVE_NEWLINE_OR_CR
:
7523 set_iterator_to_next (it
, 1);
7524 it
->continuation_lines_width
= 0;
7527 case MOVE_LINE_TRUNCATED
:
7528 it
->continuation_lines_width
= 0;
7529 reseat_at_next_visible_line_start (it
, 0);
7530 if ((op
& MOVE_TO_POS
) != 0
7531 && IT_CHARPOS (*it
) > to_charpos
)
7538 case MOVE_LINE_CONTINUED
:
7539 /* For continued lines ending in a tab, some of the glyphs
7540 associated with the tab are displayed on the current
7541 line. Since it->current_x does not include these glyphs,
7542 we use it->last_visible_x instead. */
7545 it
->continuation_lines_width
+= it
->last_visible_x
;
7546 /* When moving by vpos, ensure that the iterator really
7547 advances to the next line (bug#847, bug#969). Fixme:
7548 do we need to do this in other circumstances? */
7549 if (it
->current_x
!= it
->last_visible_x
7550 && (op
& MOVE_TO_VPOS
)
7551 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7553 line_start_x
= it
->current_x
+ it
->pixel_width
7554 - it
->last_visible_x
;
7555 set_iterator_to_next (it
, 0);
7559 it
->continuation_lines_width
+= it
->current_x
;
7566 /* Reset/increment for the next run. */
7567 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7568 it
->current_x
= line_start_x
;
7571 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7573 last_height
= it
->max_ascent
+ it
->max_descent
;
7574 last_max_ascent
= it
->max_ascent
;
7575 it
->max_ascent
= it
->max_descent
= 0;
7580 /* On text terminals, we may stop at the end of a line in the middle
7581 of a multi-character glyph. If the glyph itself is continued,
7582 i.e. it is actually displayed on the next line, don't treat this
7583 stopping point as valid; move to the next line instead (unless
7584 that brings us offscreen). */
7585 if (!FRAME_WINDOW_P (it
->f
)
7587 && IT_CHARPOS (*it
) == to_charpos
7588 && it
->what
== IT_CHARACTER
7590 && it
->line_wrap
== WINDOW_WRAP
7591 && it
->current_x
== it
->last_visible_x
- 1
7594 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7596 it
->continuation_lines_width
+= it
->current_x
;
7597 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7598 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7600 last_height
= it
->max_ascent
+ it
->max_descent
;
7601 last_max_ascent
= it
->max_ascent
;
7604 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7608 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7610 If DY > 0, move IT backward at least that many pixels. DY = 0
7611 means move IT backward to the preceding line start or BEGV. This
7612 function may move over more than DY pixels if IT->current_y - DY
7613 ends up in the middle of a line; in this case IT->current_y will be
7614 set to the top of the line moved to. */
7617 move_it_vertically_backward (it
, dy
)
7628 start_pos
= IT_CHARPOS (*it
);
7630 /* Estimate how many newlines we must move back. */
7631 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7633 /* Set the iterator's position that many lines back. */
7634 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7635 back_to_previous_visible_line_start (it
);
7637 /* Reseat the iterator here. When moving backward, we don't want
7638 reseat to skip forward over invisible text, set up the iterator
7639 to deliver from overlay strings at the new position etc. So,
7640 use reseat_1 here. */
7641 reseat_1 (it
, it
->current
.pos
, 1);
7643 /* We are now surely at a line start. */
7644 it
->current_x
= it
->hpos
= 0;
7645 it
->continuation_lines_width
= 0;
7647 /* Move forward and see what y-distance we moved. First move to the
7648 start of the next line so that we get its height. We need this
7649 height to be able to tell whether we reached the specified
7652 it2
.max_ascent
= it2
.max_descent
= 0;
7655 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7656 MOVE_TO_POS
| MOVE_TO_VPOS
);
7658 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7659 xassert (IT_CHARPOS (*it
) >= BEGV
);
7662 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7663 xassert (IT_CHARPOS (*it
) >= BEGV
);
7664 /* H is the actual vertical distance from the position in *IT
7665 and the starting position. */
7666 h
= it2
.current_y
- it
->current_y
;
7667 /* NLINES is the distance in number of lines. */
7668 nlines
= it2
.vpos
- it
->vpos
;
7670 /* Correct IT's y and vpos position
7671 so that they are relative to the starting point. */
7677 /* DY == 0 means move to the start of the screen line. The
7678 value of nlines is > 0 if continuation lines were involved. */
7680 move_it_by_lines (it
, nlines
, 1);
7684 /* The y-position we try to reach, relative to *IT.
7685 Note that H has been subtracted in front of the if-statement. */
7686 int target_y
= it
->current_y
+ h
- dy
;
7687 int y0
= it3
.current_y
;
7688 int y1
= line_bottom_y (&it3
);
7689 int line_height
= y1
- y0
;
7691 /* If we did not reach target_y, try to move further backward if
7692 we can. If we moved too far backward, try to move forward. */
7693 if (target_y
< it
->current_y
7694 /* This is heuristic. In a window that's 3 lines high, with
7695 a line height of 13 pixels each, recentering with point
7696 on the bottom line will try to move -39/2 = 19 pixels
7697 backward. Try to avoid moving into the first line. */
7698 && (it
->current_y
- target_y
7699 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7700 && IT_CHARPOS (*it
) > BEGV
)
7702 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7703 target_y
- it
->current_y
));
7704 dy
= it
->current_y
- target_y
;
7705 goto move_further_back
;
7707 else if (target_y
>= it
->current_y
+ line_height
7708 && IT_CHARPOS (*it
) < ZV
)
7710 /* Should move forward by at least one line, maybe more.
7712 Note: Calling move_it_by_lines can be expensive on
7713 terminal frames, where compute_motion is used (via
7714 vmotion) to do the job, when there are very long lines
7715 and truncate-lines is nil. That's the reason for
7716 treating terminal frames specially here. */
7718 if (!FRAME_WINDOW_P (it
->f
))
7719 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7724 move_it_by_lines (it
, 1, 1);
7726 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7733 /* Move IT by a specified amount of pixel lines DY. DY negative means
7734 move backwards. DY = 0 means move to start of screen line. At the
7735 end, IT will be on the start of a screen line. */
7738 move_it_vertically (it
, dy
)
7743 move_it_vertically_backward (it
, -dy
);
7746 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7747 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7748 MOVE_TO_POS
| MOVE_TO_Y
);
7749 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7751 /* If buffer ends in ZV without a newline, move to the start of
7752 the line to satisfy the post-condition. */
7753 if (IT_CHARPOS (*it
) == ZV
7755 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7756 move_it_by_lines (it
, 0, 0);
7761 /* Move iterator IT past the end of the text line it is in. */
7764 move_it_past_eol (it
)
7767 enum move_it_result rc
;
7769 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7770 if (rc
== MOVE_NEWLINE_OR_CR
)
7771 set_iterator_to_next (it
, 0);
7775 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7776 negative means move up. DVPOS == 0 means move to the start of the
7777 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7778 NEED_Y_P is zero, IT->current_y will be left unchanged.
7780 Further optimization ideas: If we would know that IT->f doesn't use
7781 a face with proportional font, we could be faster for
7782 truncate-lines nil. */
7785 move_it_by_lines (it
, dvpos
, need_y_p
)
7787 int dvpos
, need_y_p
;
7789 struct position pos
;
7791 /* The commented-out optimization uses vmotion on terminals. This
7792 gives bad results, because elements like it->what, on which
7793 callers such as pos_visible_p rely, aren't updated. */
7794 /* if (!FRAME_WINDOW_P (it->f))
7796 struct text_pos textpos;
7798 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7799 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7800 reseat (it, textpos, 1);
7801 it->vpos += pos.vpos;
7802 it->current_y += pos.vpos;
7808 /* DVPOS == 0 means move to the start of the screen line. */
7809 move_it_vertically_backward (it
, 0);
7810 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7811 /* Let next call to line_bottom_y calculate real line height */
7816 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7817 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7818 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7823 int start_charpos
, i
;
7825 /* Start at the beginning of the screen line containing IT's
7826 position. This may actually move vertically backwards,
7827 in case of overlays, so adjust dvpos accordingly. */
7829 move_it_vertically_backward (it
, 0);
7832 /* Go back -DVPOS visible lines and reseat the iterator there. */
7833 start_charpos
= IT_CHARPOS (*it
);
7834 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7835 back_to_previous_visible_line_start (it
);
7836 reseat (it
, it
->current
.pos
, 1);
7838 /* Move further back if we end up in a string or an image. */
7839 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7841 /* First try to move to start of display line. */
7843 move_it_vertically_backward (it
, 0);
7845 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7847 /* If start of line is still in string or image,
7848 move further back. */
7849 back_to_previous_visible_line_start (it
);
7850 reseat (it
, it
->current
.pos
, 1);
7854 it
->current_x
= it
->hpos
= 0;
7856 /* Above call may have moved too far if continuation lines
7857 are involved. Scan forward and see if it did. */
7859 it2
.vpos
= it2
.current_y
= 0;
7860 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7861 it
->vpos
-= it2
.vpos
;
7862 it
->current_y
-= it2
.current_y
;
7863 it
->current_x
= it
->hpos
= 0;
7865 /* If we moved too far back, move IT some lines forward. */
7866 if (it2
.vpos
> -dvpos
)
7868 int delta
= it2
.vpos
+ dvpos
;
7870 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7871 /* Move back again if we got too far ahead. */
7872 if (IT_CHARPOS (*it
) >= start_charpos
)
7878 /* Return 1 if IT points into the middle of a display vector. */
7881 in_display_vector_p (it
)
7884 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7885 && it
->current
.dpvec_index
> 0
7886 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7890 /***********************************************************************
7892 ***********************************************************************/
7895 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7899 add_to_log (format
, arg1
, arg2
)
7901 Lisp_Object arg1
, arg2
;
7903 Lisp_Object args
[3];
7904 Lisp_Object msg
, fmt
;
7907 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7910 /* Do nothing if called asynchronously. Inserting text into
7911 a buffer may call after-change-functions and alike and
7912 that would means running Lisp asynchronously. */
7913 if (handling_signal
)
7917 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7919 args
[0] = fmt
= build_string (format
);
7922 msg
= Fformat (3, args
);
7924 len
= SBYTES (msg
) + 1;
7925 SAFE_ALLOCA (buffer
, char *, len
);
7926 bcopy (SDATA (msg
), buffer
, len
);
7928 message_dolog (buffer
, len
- 1, 1, 0);
7935 /* Output a newline in the *Messages* buffer if "needs" one. */
7938 message_log_maybe_newline ()
7940 if (message_log_need_newline
)
7941 message_dolog ("", 0, 1, 0);
7945 /* Add a string M of length NBYTES to the message log, optionally
7946 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7947 nonzero, means interpret the contents of M as multibyte. This
7948 function calls low-level routines in order to bypass text property
7949 hooks, etc. which might not be safe to run.
7951 This may GC (insert may run before/after change hooks),
7952 so the buffer M must NOT point to a Lisp string. */
7955 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7957 int nbytes
, nlflag
, multibyte
;
7959 if (!NILP (Vmemory_full
))
7962 if (!NILP (Vmessage_log_max
))
7964 struct buffer
*oldbuf
;
7965 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7966 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7967 int point_at_end
= 0;
7969 Lisp_Object old_deactivate_mark
, tem
;
7970 struct gcpro gcpro1
;
7972 old_deactivate_mark
= Vdeactivate_mark
;
7973 oldbuf
= current_buffer
;
7974 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7975 current_buffer
->undo_list
= Qt
;
7977 oldpoint
= message_dolog_marker1
;
7978 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7979 oldbegv
= message_dolog_marker2
;
7980 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7981 oldzv
= message_dolog_marker3
;
7982 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7983 GCPRO1 (old_deactivate_mark
);
7991 BEGV_BYTE
= BEG_BYTE
;
7994 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7996 /* Insert the string--maybe converting multibyte to single byte
7997 or vice versa, so that all the text fits the buffer. */
7999 && NILP (current_buffer
->enable_multibyte_characters
))
8001 int i
, c
, char_bytes
;
8002 unsigned char work
[1];
8004 /* Convert a multibyte string to single-byte
8005 for the *Message* buffer. */
8006 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8008 c
= string_char_and_length (m
+ i
, &char_bytes
);
8009 work
[0] = (ASCII_CHAR_P (c
)
8011 : multibyte_char_to_unibyte (c
, Qnil
));
8012 insert_1_both (work
, 1, 1, 1, 0, 0);
8015 else if (! multibyte
8016 && ! NILP (current_buffer
->enable_multibyte_characters
))
8018 int i
, c
, char_bytes
;
8019 unsigned char *msg
= (unsigned char *) m
;
8020 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8021 /* Convert a single-byte string to multibyte
8022 for the *Message* buffer. */
8023 for (i
= 0; i
< nbytes
; i
++)
8026 MAKE_CHAR_MULTIBYTE (c
);
8027 char_bytes
= CHAR_STRING (c
, str
);
8028 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
8032 insert_1 (m
, nbytes
, 1, 0, 0);
8036 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
8037 insert_1 ("\n", 1, 1, 0, 0);
8039 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8041 this_bol_byte
= PT_BYTE
;
8043 /* See if this line duplicates the previous one.
8044 If so, combine duplicates. */
8047 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8049 prev_bol_byte
= PT_BYTE
;
8051 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
8052 this_bol
, this_bol_byte
);
8055 del_range_both (prev_bol
, prev_bol_byte
,
8056 this_bol
, this_bol_byte
, 0);
8062 /* If you change this format, don't forget to also
8063 change message_log_check_duplicate. */
8064 sprintf (dupstr
, " [%d times]", dup
);
8065 duplen
= strlen (dupstr
);
8066 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8067 insert_1 (dupstr
, duplen
, 1, 0, 1);
8072 /* If we have more than the desired maximum number of lines
8073 in the *Messages* buffer now, delete the oldest ones.
8074 This is safe because we don't have undo in this buffer. */
8076 if (NATNUMP (Vmessage_log_max
))
8078 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8079 -XFASTINT (Vmessage_log_max
) - 1, 0);
8080 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8083 BEGV
= XMARKER (oldbegv
)->charpos
;
8084 BEGV_BYTE
= marker_byte_position (oldbegv
);
8093 ZV
= XMARKER (oldzv
)->charpos
;
8094 ZV_BYTE
= marker_byte_position (oldzv
);
8098 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8100 /* We can't do Fgoto_char (oldpoint) because it will run some
8102 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8103 XMARKER (oldpoint
)->bytepos
);
8106 unchain_marker (XMARKER (oldpoint
));
8107 unchain_marker (XMARKER (oldbegv
));
8108 unchain_marker (XMARKER (oldzv
));
8110 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8111 set_buffer_internal (oldbuf
);
8113 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8114 message_log_need_newline
= !nlflag
;
8115 Vdeactivate_mark
= old_deactivate_mark
;
8120 /* We are at the end of the buffer after just having inserted a newline.
8121 (Note: We depend on the fact we won't be crossing the gap.)
8122 Check to see if the most recent message looks a lot like the previous one.
8123 Return 0 if different, 1 if the new one should just replace it, or a
8124 value N > 1 if we should also append " [N times]". */
8127 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
8128 int prev_bol
, this_bol
;
8129 int prev_bol_byte
, this_bol_byte
;
8132 int len
= Z_BYTE
- 1 - this_bol_byte
;
8134 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8135 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8137 for (i
= 0; i
< len
; i
++)
8139 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8147 if (*p1
++ == ' ' && *p1
++ == '[')
8150 while (*p1
>= '0' && *p1
<= '9')
8151 n
= n
* 10 + *p1
++ - '0';
8152 if (strncmp (p1
, " times]\n", 8) == 0)
8159 /* Display an echo area message M with a specified length of NBYTES
8160 bytes. The string may include null characters. If M is 0, clear
8161 out any existing message, and let the mini-buffer text show
8164 This may GC, so the buffer M must NOT point to a Lisp string. */
8167 message2 (m
, nbytes
, multibyte
)
8172 /* First flush out any partial line written with print. */
8173 message_log_maybe_newline ();
8175 message_dolog (m
, nbytes
, 1, multibyte
);
8176 message2_nolog (m
, nbytes
, multibyte
);
8180 /* The non-logging counterpart of message2. */
8183 message2_nolog (m
, nbytes
, multibyte
)
8185 int nbytes
, multibyte
;
8187 struct frame
*sf
= SELECTED_FRAME ();
8188 message_enable_multibyte
= multibyte
;
8190 if (FRAME_INITIAL_P (sf
))
8192 if (noninteractive_need_newline
)
8193 putc ('\n', stderr
);
8194 noninteractive_need_newline
= 0;
8196 fwrite (m
, nbytes
, 1, stderr
);
8197 if (cursor_in_echo_area
== 0)
8198 fprintf (stderr
, "\n");
8201 /* A null message buffer means that the frame hasn't really been
8202 initialized yet. Error messages get reported properly by
8203 cmd_error, so this must be just an informative message; toss it. */
8204 else if (INTERACTIVE
8205 && sf
->glyphs_initialized_p
8206 && FRAME_MESSAGE_BUF (sf
))
8208 Lisp_Object mini_window
;
8211 /* Get the frame containing the mini-buffer
8212 that the selected frame is using. */
8213 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8214 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8216 FRAME_SAMPLE_VISIBILITY (f
);
8217 if (FRAME_VISIBLE_P (sf
)
8218 && ! FRAME_VISIBLE_P (f
))
8219 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8223 set_message (m
, Qnil
, nbytes
, multibyte
);
8224 if (minibuffer_auto_raise
)
8225 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8228 clear_message (1, 1);
8230 do_pending_window_change (0);
8231 echo_area_display (1);
8232 do_pending_window_change (0);
8233 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8234 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8239 /* Display an echo area message M with a specified length of NBYTES
8240 bytes. The string may include null characters. If M is not a
8241 string, clear out any existing message, and let the mini-buffer
8244 This function cancels echoing. */
8247 message3 (m
, nbytes
, multibyte
)
8252 struct gcpro gcpro1
;
8255 clear_message (1,1);
8258 /* First flush out any partial line written with print. */
8259 message_log_maybe_newline ();
8265 SAFE_ALLOCA (buffer
, char *, nbytes
);
8266 bcopy (SDATA (m
), buffer
, nbytes
);
8267 message_dolog (buffer
, nbytes
, 1, multibyte
);
8270 message3_nolog (m
, nbytes
, multibyte
);
8276 /* The non-logging version of message3.
8277 This does not cancel echoing, because it is used for echoing.
8278 Perhaps we need to make a separate function for echoing
8279 and make this cancel echoing. */
8282 message3_nolog (m
, nbytes
, multibyte
)
8284 int nbytes
, multibyte
;
8286 struct frame
*sf
= SELECTED_FRAME ();
8287 message_enable_multibyte
= multibyte
;
8289 if (FRAME_INITIAL_P (sf
))
8291 if (noninteractive_need_newline
)
8292 putc ('\n', stderr
);
8293 noninteractive_need_newline
= 0;
8295 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8296 if (cursor_in_echo_area
== 0)
8297 fprintf (stderr
, "\n");
8300 /* A null message buffer means that the frame hasn't really been
8301 initialized yet. Error messages get reported properly by
8302 cmd_error, so this must be just an informative message; toss it. */
8303 else if (INTERACTIVE
8304 && sf
->glyphs_initialized_p
8305 && FRAME_MESSAGE_BUF (sf
))
8307 Lisp_Object mini_window
;
8311 /* Get the frame containing the mini-buffer
8312 that the selected frame is using. */
8313 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8314 frame
= XWINDOW (mini_window
)->frame
;
8317 FRAME_SAMPLE_VISIBILITY (f
);
8318 if (FRAME_VISIBLE_P (sf
)
8319 && !FRAME_VISIBLE_P (f
))
8320 Fmake_frame_visible (frame
);
8322 if (STRINGP (m
) && SCHARS (m
) > 0)
8324 set_message (NULL
, m
, nbytes
, multibyte
);
8325 if (minibuffer_auto_raise
)
8326 Fraise_frame (frame
);
8327 /* Assume we are not echoing.
8328 (If we are, echo_now will override this.) */
8329 echo_message_buffer
= Qnil
;
8332 clear_message (1, 1);
8334 do_pending_window_change (0);
8335 echo_area_display (1);
8336 do_pending_window_change (0);
8337 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8338 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8343 /* Display a null-terminated echo area message M. If M is 0, clear
8344 out any existing message, and let the mini-buffer text show through.
8346 The buffer M must continue to exist until after the echo area gets
8347 cleared or some other message gets displayed there. Do not pass
8348 text that is stored in a Lisp string. Do not pass text in a buffer
8349 that was alloca'd. */
8355 message2 (m
, (m
? strlen (m
) : 0), 0);
8359 /* The non-logging counterpart of message1. */
8365 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8368 /* Display a message M which contains a single %s
8369 which gets replaced with STRING. */
8372 message_with_string (m
, string
, log
)
8377 CHECK_STRING (string
);
8383 if (noninteractive_need_newline
)
8384 putc ('\n', stderr
);
8385 noninteractive_need_newline
= 0;
8386 fprintf (stderr
, m
, SDATA (string
));
8387 if (!cursor_in_echo_area
)
8388 fprintf (stderr
, "\n");
8392 else if (INTERACTIVE
)
8394 /* The frame whose minibuffer we're going to display the message on.
8395 It may be larger than the selected frame, so we need
8396 to use its buffer, not the selected frame's buffer. */
8397 Lisp_Object mini_window
;
8398 struct frame
*f
, *sf
= SELECTED_FRAME ();
8400 /* Get the frame containing the minibuffer
8401 that the selected frame is using. */
8402 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8403 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8405 /* A null message buffer means that the frame hasn't really been
8406 initialized yet. Error messages get reported properly by
8407 cmd_error, so this must be just an informative message; toss it. */
8408 if (FRAME_MESSAGE_BUF (f
))
8410 Lisp_Object args
[2], message
;
8411 struct gcpro gcpro1
, gcpro2
;
8413 args
[0] = build_string (m
);
8414 args
[1] = message
= string
;
8415 GCPRO2 (args
[0], message
);
8418 message
= Fformat (2, args
);
8421 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8423 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8427 /* Print should start at the beginning of the message
8428 buffer next time. */
8429 message_buf_print
= 0;
8435 /* Dump an informative message to the minibuf. If M is 0, clear out
8436 any existing message, and let the mini-buffer text show through. */
8440 message (m
, a1
, a2
, a3
)
8442 EMACS_INT a1
, a2
, a3
;
8448 if (noninteractive_need_newline
)
8449 putc ('\n', stderr
);
8450 noninteractive_need_newline
= 0;
8451 fprintf (stderr
, m
, a1
, a2
, a3
);
8452 if (cursor_in_echo_area
== 0)
8453 fprintf (stderr
, "\n");
8457 else if (INTERACTIVE
)
8459 /* The frame whose mini-buffer we're going to display the message
8460 on. It may be larger than the selected frame, so we need to
8461 use its buffer, not the selected frame's buffer. */
8462 Lisp_Object mini_window
;
8463 struct frame
*f
, *sf
= SELECTED_FRAME ();
8465 /* Get the frame containing the mini-buffer
8466 that the selected frame is using. */
8467 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8468 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8470 /* A null message buffer means that the frame hasn't really been
8471 initialized yet. Error messages get reported properly by
8472 cmd_error, so this must be just an informative message; toss
8474 if (FRAME_MESSAGE_BUF (f
))
8485 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8486 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8488 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8489 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8491 #endif /* NO_ARG_ARRAY */
8493 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8498 /* Print should start at the beginning of the message
8499 buffer next time. */
8500 message_buf_print
= 0;
8506 /* The non-logging version of message. */
8509 message_nolog (m
, a1
, a2
, a3
)
8511 EMACS_INT a1
, a2
, a3
;
8513 Lisp_Object old_log_max
;
8514 old_log_max
= Vmessage_log_max
;
8515 Vmessage_log_max
= Qnil
;
8516 message (m
, a1
, a2
, a3
);
8517 Vmessage_log_max
= old_log_max
;
8521 /* Display the current message in the current mini-buffer. This is
8522 only called from error handlers in process.c, and is not time
8528 if (!NILP (echo_area_buffer
[0]))
8531 string
= Fcurrent_message ();
8532 message3 (string
, SBYTES (string
),
8533 !NILP (current_buffer
->enable_multibyte_characters
));
8538 /* Make sure echo area buffers in `echo_buffers' are live.
8539 If they aren't, make new ones. */
8542 ensure_echo_area_buffers ()
8546 for (i
= 0; i
< 2; ++i
)
8547 if (!BUFFERP (echo_buffer
[i
])
8548 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8551 Lisp_Object old_buffer
;
8554 old_buffer
= echo_buffer
[i
];
8555 sprintf (name
, " *Echo Area %d*", i
);
8556 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8557 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8558 /* to force word wrap in echo area -
8559 it was decided to postpone this*/
8560 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8562 for (j
= 0; j
< 2; ++j
)
8563 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8564 echo_area_buffer
[j
] = echo_buffer
[i
];
8569 /* Call FN with args A1..A4 with either the current or last displayed
8570 echo_area_buffer as current buffer.
8572 WHICH zero means use the current message buffer
8573 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8574 from echo_buffer[] and clear it.
8576 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8577 suitable buffer from echo_buffer[] and clear it.
8579 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8580 that the current message becomes the last displayed one, make
8581 choose a suitable buffer for echo_area_buffer[0], and clear it.
8583 Value is what FN returns. */
8586 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8589 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8595 int this_one
, the_other
, clear_buffer_p
, rc
;
8596 int count
= SPECPDL_INDEX ();
8598 /* If buffers aren't live, make new ones. */
8599 ensure_echo_area_buffers ();
8604 this_one
= 0, the_other
= 1;
8606 this_one
= 1, the_other
= 0;
8609 this_one
= 0, the_other
= 1;
8612 /* We need a fresh one in case the current echo buffer equals
8613 the one containing the last displayed echo area message. */
8614 if (!NILP (echo_area_buffer
[this_one
])
8615 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8616 echo_area_buffer
[this_one
] = Qnil
;
8619 /* Choose a suitable buffer from echo_buffer[] is we don't
8621 if (NILP (echo_area_buffer
[this_one
]))
8623 echo_area_buffer
[this_one
]
8624 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8625 ? echo_buffer
[the_other
]
8626 : echo_buffer
[this_one
]);
8630 buffer
= echo_area_buffer
[this_one
];
8632 /* Don't get confused by reusing the buffer used for echoing
8633 for a different purpose. */
8634 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8637 record_unwind_protect (unwind_with_echo_area_buffer
,
8638 with_echo_area_buffer_unwind_data (w
));
8640 /* Make the echo area buffer current. Note that for display
8641 purposes, it is not necessary that the displayed window's buffer
8642 == current_buffer, except for text property lookup. So, let's
8643 only set that buffer temporarily here without doing a full
8644 Fset_window_buffer. We must also change w->pointm, though,
8645 because otherwise an assertions in unshow_buffer fails, and Emacs
8647 set_buffer_internal_1 (XBUFFER (buffer
));
8651 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8654 current_buffer
->undo_list
= Qt
;
8655 current_buffer
->read_only
= Qnil
;
8656 specbind (Qinhibit_read_only
, Qt
);
8657 specbind (Qinhibit_modification_hooks
, Qt
);
8659 if (clear_buffer_p
&& Z
> BEG
)
8662 xassert (BEGV
>= BEG
);
8663 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8665 rc
= fn (a1
, a2
, a3
, a4
);
8667 xassert (BEGV
>= BEG
);
8668 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8670 unbind_to (count
, Qnil
);
8675 /* Save state that should be preserved around the call to the function
8676 FN called in with_echo_area_buffer. */
8679 with_echo_area_buffer_unwind_data (w
)
8683 Lisp_Object vector
, tmp
;
8685 /* Reduce consing by keeping one vector in
8686 Vwith_echo_area_save_vector. */
8687 vector
= Vwith_echo_area_save_vector
;
8688 Vwith_echo_area_save_vector
= Qnil
;
8691 vector
= Fmake_vector (make_number (7), Qnil
);
8693 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8694 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8695 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8699 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8700 ASET (vector
, i
, w
->buffer
); ++i
;
8701 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8702 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8707 for (; i
< end
; ++i
)
8708 ASET (vector
, i
, Qnil
);
8711 xassert (i
== ASIZE (vector
));
8716 /* Restore global state from VECTOR which was created by
8717 with_echo_area_buffer_unwind_data. */
8720 unwind_with_echo_area_buffer (vector
)
8723 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8724 Vdeactivate_mark
= AREF (vector
, 1);
8725 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8727 if (WINDOWP (AREF (vector
, 3)))
8730 Lisp_Object buffer
, charpos
, bytepos
;
8732 w
= XWINDOW (AREF (vector
, 3));
8733 buffer
= AREF (vector
, 4);
8734 charpos
= AREF (vector
, 5);
8735 bytepos
= AREF (vector
, 6);
8738 set_marker_both (w
->pointm
, buffer
,
8739 XFASTINT (charpos
), XFASTINT (bytepos
));
8742 Vwith_echo_area_save_vector
= vector
;
8747 /* Set up the echo area for use by print functions. MULTIBYTE_P
8748 non-zero means we will print multibyte. */
8751 setup_echo_area_for_printing (multibyte_p
)
8754 /* If we can't find an echo area any more, exit. */
8755 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8758 ensure_echo_area_buffers ();
8760 if (!message_buf_print
)
8762 /* A message has been output since the last time we printed.
8763 Choose a fresh echo area buffer. */
8764 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8765 echo_area_buffer
[0] = echo_buffer
[1];
8767 echo_area_buffer
[0] = echo_buffer
[0];
8769 /* Switch to that buffer and clear it. */
8770 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8771 current_buffer
->truncate_lines
= Qnil
;
8775 int count
= SPECPDL_INDEX ();
8776 specbind (Qinhibit_read_only
, Qt
);
8777 /* Note that undo recording is always disabled. */
8779 unbind_to (count
, Qnil
);
8781 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8783 /* Set up the buffer for the multibyteness we need. */
8785 != !NILP (current_buffer
->enable_multibyte_characters
))
8786 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8788 /* Raise the frame containing the echo area. */
8789 if (minibuffer_auto_raise
)
8791 struct frame
*sf
= SELECTED_FRAME ();
8792 Lisp_Object mini_window
;
8793 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8794 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8797 message_log_maybe_newline ();
8798 message_buf_print
= 1;
8802 if (NILP (echo_area_buffer
[0]))
8804 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8805 echo_area_buffer
[0] = echo_buffer
[1];
8807 echo_area_buffer
[0] = echo_buffer
[0];
8810 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8812 /* Someone switched buffers between print requests. */
8813 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8814 current_buffer
->truncate_lines
= Qnil
;
8820 /* Display an echo area message in window W. Value is non-zero if W's
8821 height is changed. If display_last_displayed_message_p is
8822 non-zero, display the message that was last displayed, otherwise
8823 display the current message. */
8826 display_echo_area (w
)
8829 int i
, no_message_p
, window_height_changed_p
, count
;
8831 /* Temporarily disable garbage collections while displaying the echo
8832 area. This is done because a GC can print a message itself.
8833 That message would modify the echo area buffer's contents while a
8834 redisplay of the buffer is going on, and seriously confuse
8836 count
= inhibit_garbage_collection ();
8838 /* If there is no message, we must call display_echo_area_1
8839 nevertheless because it resizes the window. But we will have to
8840 reset the echo_area_buffer in question to nil at the end because
8841 with_echo_area_buffer will sets it to an empty buffer. */
8842 i
= display_last_displayed_message_p
? 1 : 0;
8843 no_message_p
= NILP (echo_area_buffer
[i
]);
8845 window_height_changed_p
8846 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8847 display_echo_area_1
,
8848 (EMACS_INT
) w
, Qnil
, 0, 0);
8851 echo_area_buffer
[i
] = Qnil
;
8853 unbind_to (count
, Qnil
);
8854 return window_height_changed_p
;
8858 /* Helper for display_echo_area. Display the current buffer which
8859 contains the current echo area message in window W, a mini-window,
8860 a pointer to which is passed in A1. A2..A4 are currently not used.
8861 Change the height of W so that all of the message is displayed.
8862 Value is non-zero if height of W was changed. */
8865 display_echo_area_1 (a1
, a2
, a3
, a4
)
8870 struct window
*w
= (struct window
*) a1
;
8872 struct text_pos start
;
8873 int window_height_changed_p
= 0;
8875 /* Do this before displaying, so that we have a large enough glyph
8876 matrix for the display. If we can't get enough space for the
8877 whole text, display the last N lines. That works by setting w->start. */
8878 window_height_changed_p
= resize_mini_window (w
, 0);
8880 /* Use the starting position chosen by resize_mini_window. */
8881 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8884 clear_glyph_matrix (w
->desired_matrix
);
8885 XSETWINDOW (window
, w
);
8886 try_window (window
, start
, 0);
8888 return window_height_changed_p
;
8892 /* Resize the echo area window to exactly the size needed for the
8893 currently displayed message, if there is one. If a mini-buffer
8894 is active, don't shrink it. */
8897 resize_echo_area_exactly ()
8899 if (BUFFERP (echo_area_buffer
[0])
8900 && WINDOWP (echo_area_window
))
8902 struct window
*w
= XWINDOW (echo_area_window
);
8904 Lisp_Object resize_exactly
;
8906 if (minibuf_level
== 0)
8907 resize_exactly
= Qt
;
8909 resize_exactly
= Qnil
;
8911 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8912 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8915 ++windows_or_buffers_changed
;
8916 ++update_mode_lines
;
8917 redisplay_internal (0);
8923 /* Callback function for with_echo_area_buffer, when used from
8924 resize_echo_area_exactly. A1 contains a pointer to the window to
8925 resize, EXACTLY non-nil means resize the mini-window exactly to the
8926 size of the text displayed. A3 and A4 are not used. Value is what
8927 resize_mini_window returns. */
8930 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8932 Lisp_Object exactly
;
8935 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8939 /* Resize mini-window W to fit the size of its contents. EXACT_P
8940 means size the window exactly to the size needed. Otherwise, it's
8941 only enlarged until W's buffer is empty.
8943 Set W->start to the right place to begin display. If the whole
8944 contents fit, start at the beginning. Otherwise, start so as
8945 to make the end of the contents appear. This is particularly
8946 important for y-or-n-p, but seems desirable generally.
8948 Value is non-zero if the window height has been changed. */
8951 resize_mini_window (w
, exact_p
)
8955 struct frame
*f
= XFRAME (w
->frame
);
8956 int window_height_changed_p
= 0;
8958 xassert (MINI_WINDOW_P (w
));
8960 /* By default, start display at the beginning. */
8961 set_marker_both (w
->start
, w
->buffer
,
8962 BUF_BEGV (XBUFFER (w
->buffer
)),
8963 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8965 /* Don't resize windows while redisplaying a window; it would
8966 confuse redisplay functions when the size of the window they are
8967 displaying changes from under them. Such a resizing can happen,
8968 for instance, when which-func prints a long message while
8969 we are running fontification-functions. We're running these
8970 functions with safe_call which binds inhibit-redisplay to t. */
8971 if (!NILP (Vinhibit_redisplay
))
8974 /* Nil means don't try to resize. */
8975 if (NILP (Vresize_mini_windows
)
8976 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8979 if (!FRAME_MINIBUF_ONLY_P (f
))
8982 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8983 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8984 int height
, max_height
;
8985 int unit
= FRAME_LINE_HEIGHT (f
);
8986 struct text_pos start
;
8987 struct buffer
*old_current_buffer
= NULL
;
8989 if (current_buffer
!= XBUFFER (w
->buffer
))
8991 old_current_buffer
= current_buffer
;
8992 set_buffer_internal (XBUFFER (w
->buffer
));
8995 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8997 /* Compute the max. number of lines specified by the user. */
8998 if (FLOATP (Vmax_mini_window_height
))
8999 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9000 else if (INTEGERP (Vmax_mini_window_height
))
9001 max_height
= XINT (Vmax_mini_window_height
);
9003 max_height
= total_height
/ 4;
9005 /* Correct that max. height if it's bogus. */
9006 max_height
= max (1, max_height
);
9007 max_height
= min (total_height
, max_height
);
9009 /* Find out the height of the text in the window. */
9010 if (it
.line_wrap
== TRUNCATE
)
9015 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9016 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9017 height
= it
.current_y
+ last_height
;
9019 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9020 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9021 height
= (height
+ unit
- 1) / unit
;
9024 /* Compute a suitable window start. */
9025 if (height
> max_height
)
9027 height
= max_height
;
9028 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9029 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9030 start
= it
.current
.pos
;
9033 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9034 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9036 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9038 /* Let it grow only, until we display an empty message, in which
9039 case the window shrinks again. */
9040 if (height
> WINDOW_TOTAL_LINES (w
))
9042 int old_height
= WINDOW_TOTAL_LINES (w
);
9043 freeze_window_starts (f
, 1);
9044 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9045 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9047 else if (height
< WINDOW_TOTAL_LINES (w
)
9048 && (exact_p
|| BEGV
== ZV
))
9050 int old_height
= WINDOW_TOTAL_LINES (w
);
9051 freeze_window_starts (f
, 0);
9052 shrink_mini_window (w
);
9053 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9058 /* Always resize to exact size needed. */
9059 if (height
> WINDOW_TOTAL_LINES (w
))
9061 int old_height
= WINDOW_TOTAL_LINES (w
);
9062 freeze_window_starts (f
, 1);
9063 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9064 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9066 else if (height
< WINDOW_TOTAL_LINES (w
))
9068 int old_height
= WINDOW_TOTAL_LINES (w
);
9069 freeze_window_starts (f
, 0);
9070 shrink_mini_window (w
);
9074 freeze_window_starts (f
, 1);
9075 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9078 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9082 if (old_current_buffer
)
9083 set_buffer_internal (old_current_buffer
);
9086 return window_height_changed_p
;
9090 /* Value is the current message, a string, or nil if there is no
9098 if (!BUFFERP (echo_area_buffer
[0]))
9102 with_echo_area_buffer (0, 0, current_message_1
,
9103 (EMACS_INT
) &msg
, Qnil
, 0, 0);
9105 echo_area_buffer
[0] = Qnil
;
9113 current_message_1 (a1
, a2
, a3
, a4
)
9118 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
9121 *msg
= make_buffer_string (BEG
, Z
, 1);
9128 /* Push the current message on Vmessage_stack for later restauration
9129 by restore_message. Value is non-zero if the current message isn't
9130 empty. This is a relatively infrequent operation, so it's not
9131 worth optimizing. */
9137 msg
= current_message ();
9138 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9139 return STRINGP (msg
);
9143 /* Restore message display from the top of Vmessage_stack. */
9150 xassert (CONSP (Vmessage_stack
));
9151 msg
= XCAR (Vmessage_stack
);
9153 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9155 message3_nolog (msg
, 0, 0);
9159 /* Handler for record_unwind_protect calling pop_message. */
9162 pop_message_unwind (dummy
)
9169 /* Pop the top-most entry off Vmessage_stack. */
9174 xassert (CONSP (Vmessage_stack
));
9175 Vmessage_stack
= XCDR (Vmessage_stack
);
9179 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9180 exits. If the stack is not empty, we have a missing pop_message
9184 check_message_stack ()
9186 if (!NILP (Vmessage_stack
))
9191 /* Truncate to NCHARS what will be displayed in the echo area the next
9192 time we display it---but don't redisplay it now. */
9195 truncate_echo_area (nchars
)
9199 echo_area_buffer
[0] = Qnil
;
9200 /* A null message buffer means that the frame hasn't really been
9201 initialized yet. Error messages get reported properly by
9202 cmd_error, so this must be just an informative message; toss it. */
9203 else if (!noninteractive
9205 && !NILP (echo_area_buffer
[0]))
9207 struct frame
*sf
= SELECTED_FRAME ();
9208 if (FRAME_MESSAGE_BUF (sf
))
9209 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9214 /* Helper function for truncate_echo_area. Truncate the current
9215 message to at most NCHARS characters. */
9218 truncate_message_1 (nchars
, a2
, a3
, a4
)
9223 if (BEG
+ nchars
< Z
)
9224 del_range (BEG
+ nchars
, Z
);
9226 echo_area_buffer
[0] = Qnil
;
9231 /* Set the current message to a substring of S or STRING.
9233 If STRING is a Lisp string, set the message to the first NBYTES
9234 bytes from STRING. NBYTES zero means use the whole string. If
9235 STRING is multibyte, the message will be displayed multibyte.
9237 If S is not null, set the message to the first LEN bytes of S. LEN
9238 zero means use the whole string. MULTIBYTE_P non-zero means S is
9239 multibyte. Display the message multibyte in that case.
9241 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9242 to t before calling set_message_1 (which calls insert).
9246 set_message (s
, string
, nbytes
, multibyte_p
)
9249 int nbytes
, multibyte_p
;
9251 message_enable_multibyte
9252 = ((s
&& multibyte_p
)
9253 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9255 with_echo_area_buffer (0, -1, set_message_1
,
9256 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9257 message_buf_print
= 0;
9258 help_echo_showing_p
= 0;
9262 /* Helper function for set_message. Arguments have the same meaning
9263 as there, with A1 corresponding to S and A2 corresponding to STRING
9264 This function is called with the echo area buffer being
9268 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9271 EMACS_INT nbytes
, multibyte_p
;
9273 const char *s
= (const char *) a1
;
9274 Lisp_Object string
= a2
;
9276 /* Change multibyteness of the echo buffer appropriately. */
9277 if (message_enable_multibyte
9278 != !NILP (current_buffer
->enable_multibyte_characters
))
9279 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9281 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9283 /* Insert new message at BEG. */
9284 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9286 if (STRINGP (string
))
9291 nbytes
= SBYTES (string
);
9292 nchars
= string_byte_to_char (string
, nbytes
);
9294 /* This function takes care of single/multibyte conversion. We
9295 just have to ensure that the echo area buffer has the right
9296 setting of enable_multibyte_characters. */
9297 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9302 nbytes
= strlen (s
);
9304 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9306 /* Convert from multi-byte to single-byte. */
9308 unsigned char work
[1];
9310 /* Convert a multibyte string to single-byte. */
9311 for (i
= 0; i
< nbytes
; i
+= n
)
9313 c
= string_char_and_length (s
+ i
, &n
);
9314 work
[0] = (ASCII_CHAR_P (c
)
9316 : multibyte_char_to_unibyte (c
, Qnil
));
9317 insert_1_both (work
, 1, 1, 1, 0, 0);
9320 else if (!multibyte_p
9321 && !NILP (current_buffer
->enable_multibyte_characters
))
9323 /* Convert from single-byte to multi-byte. */
9325 const unsigned char *msg
= (const unsigned char *) s
;
9326 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9328 /* Convert a single-byte string to multibyte. */
9329 for (i
= 0; i
< nbytes
; i
++)
9332 MAKE_CHAR_MULTIBYTE (c
);
9333 n
= CHAR_STRING (c
, str
);
9334 insert_1_both (str
, 1, n
, 1, 0, 0);
9338 insert_1 (s
, nbytes
, 1, 0, 0);
9345 /* Clear messages. CURRENT_P non-zero means clear the current
9346 message. LAST_DISPLAYED_P non-zero means clear the message
9350 clear_message (current_p
, last_displayed_p
)
9351 int current_p
, last_displayed_p
;
9355 echo_area_buffer
[0] = Qnil
;
9356 message_cleared_p
= 1;
9359 if (last_displayed_p
)
9360 echo_area_buffer
[1] = Qnil
;
9362 message_buf_print
= 0;
9365 /* Clear garbaged frames.
9367 This function is used where the old redisplay called
9368 redraw_garbaged_frames which in turn called redraw_frame which in
9369 turn called clear_frame. The call to clear_frame was a source of
9370 flickering. I believe a clear_frame is not necessary. It should
9371 suffice in the new redisplay to invalidate all current matrices,
9372 and ensure a complete redisplay of all windows. */
9375 clear_garbaged_frames ()
9379 Lisp_Object tail
, frame
;
9380 int changed_count
= 0;
9382 FOR_EACH_FRAME (tail
, frame
)
9384 struct frame
*f
= XFRAME (frame
);
9386 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9390 Fredraw_frame (frame
);
9391 f
->force_flush_display_p
= 1;
9393 clear_current_matrices (f
);
9402 ++windows_or_buffers_changed
;
9407 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9408 is non-zero update selected_frame. Value is non-zero if the
9409 mini-windows height has been changed. */
9412 echo_area_display (update_frame_p
)
9415 Lisp_Object mini_window
;
9418 int window_height_changed_p
= 0;
9419 struct frame
*sf
= SELECTED_FRAME ();
9421 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9422 w
= XWINDOW (mini_window
);
9423 f
= XFRAME (WINDOW_FRAME (w
));
9425 /* Don't display if frame is invisible or not yet initialized. */
9426 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9429 #ifdef HAVE_WINDOW_SYSTEM
9430 /* When Emacs starts, selected_frame may be the initial terminal
9431 frame. If we let this through, a message would be displayed on
9433 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9435 #endif /* HAVE_WINDOW_SYSTEM */
9437 /* Redraw garbaged frames. */
9439 clear_garbaged_frames ();
9441 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9443 echo_area_window
= mini_window
;
9444 window_height_changed_p
= display_echo_area (w
);
9445 w
->must_be_updated_p
= 1;
9447 /* Update the display, unless called from redisplay_internal.
9448 Also don't update the screen during redisplay itself. The
9449 update will happen at the end of redisplay, and an update
9450 here could cause confusion. */
9451 if (update_frame_p
&& !redisplaying_p
)
9455 /* If the display update has been interrupted by pending
9456 input, update mode lines in the frame. Due to the
9457 pending input, it might have been that redisplay hasn't
9458 been called, so that mode lines above the echo area are
9459 garbaged. This looks odd, so we prevent it here. */
9460 if (!display_completed
)
9461 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9463 if (window_height_changed_p
9464 /* Don't do this if Emacs is shutting down. Redisplay
9465 needs to run hooks. */
9466 && !NILP (Vrun_hooks
))
9468 /* Must update other windows. Likewise as in other
9469 cases, don't let this update be interrupted by
9471 int count
= SPECPDL_INDEX ();
9472 specbind (Qredisplay_dont_pause
, Qt
);
9473 windows_or_buffers_changed
= 1;
9474 redisplay_internal (0);
9475 unbind_to (count
, Qnil
);
9477 else if (FRAME_WINDOW_P (f
) && n
== 0)
9479 /* Window configuration is the same as before.
9480 Can do with a display update of the echo area,
9481 unless we displayed some mode lines. */
9482 update_single_window (w
, 1);
9483 FRAME_RIF (f
)->flush_display (f
);
9486 update_frame (f
, 1, 1);
9488 /* If cursor is in the echo area, make sure that the next
9489 redisplay displays the minibuffer, so that the cursor will
9490 be replaced with what the minibuffer wants. */
9491 if (cursor_in_echo_area
)
9492 ++windows_or_buffers_changed
;
9495 else if (!EQ (mini_window
, selected_window
))
9496 windows_or_buffers_changed
++;
9498 /* Last displayed message is now the current message. */
9499 echo_area_buffer
[1] = echo_area_buffer
[0];
9500 /* Inform read_char that we're not echoing. */
9501 echo_message_buffer
= Qnil
;
9503 /* Prevent redisplay optimization in redisplay_internal by resetting
9504 this_line_start_pos. This is done because the mini-buffer now
9505 displays the message instead of its buffer text. */
9506 if (EQ (mini_window
, selected_window
))
9507 CHARPOS (this_line_start_pos
) = 0;
9509 return window_height_changed_p
;
9514 /***********************************************************************
9515 Mode Lines and Frame Titles
9516 ***********************************************************************/
9518 /* A buffer for constructing non-propertized mode-line strings and
9519 frame titles in it; allocated from the heap in init_xdisp and
9520 resized as needed in store_mode_line_noprop_char. */
9522 static char *mode_line_noprop_buf
;
9524 /* The buffer's end, and a current output position in it. */
9526 static char *mode_line_noprop_buf_end
;
9527 static char *mode_line_noprop_ptr
;
9529 #define MODE_LINE_NOPROP_LEN(start) \
9530 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9533 MODE_LINE_DISPLAY
= 0,
9539 /* Alist that caches the results of :propertize.
9540 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9541 static Lisp_Object mode_line_proptrans_alist
;
9543 /* List of strings making up the mode-line. */
9544 static Lisp_Object mode_line_string_list
;
9546 /* Base face property when building propertized mode line string. */
9547 static Lisp_Object mode_line_string_face
;
9548 static Lisp_Object mode_line_string_face_prop
;
9551 /* Unwind data for mode line strings */
9553 static Lisp_Object Vmode_line_unwind_vector
;
9556 format_mode_line_unwind_data (struct buffer
*obuf
,
9560 Lisp_Object vector
, tmp
;
9562 /* Reduce consing by keeping one vector in
9563 Vwith_echo_area_save_vector. */
9564 vector
= Vmode_line_unwind_vector
;
9565 Vmode_line_unwind_vector
= Qnil
;
9568 vector
= Fmake_vector (make_number (8), Qnil
);
9570 ASET (vector
, 0, make_number (mode_line_target
));
9571 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9572 ASET (vector
, 2, mode_line_string_list
);
9573 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9574 ASET (vector
, 4, mode_line_string_face
);
9575 ASET (vector
, 5, mode_line_string_face_prop
);
9578 XSETBUFFER (tmp
, obuf
);
9581 ASET (vector
, 6, tmp
);
9582 ASET (vector
, 7, owin
);
9588 unwind_format_mode_line (vector
)
9591 mode_line_target
= XINT (AREF (vector
, 0));
9592 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9593 mode_line_string_list
= AREF (vector
, 2);
9594 if (! EQ (AREF (vector
, 3), Qt
))
9595 mode_line_proptrans_alist
= AREF (vector
, 3);
9596 mode_line_string_face
= AREF (vector
, 4);
9597 mode_line_string_face_prop
= AREF (vector
, 5);
9599 if (!NILP (AREF (vector
, 7)))
9600 /* Select window before buffer, since it may change the buffer. */
9601 Fselect_window (AREF (vector
, 7), Qt
);
9603 if (!NILP (AREF (vector
, 6)))
9605 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9606 ASET (vector
, 6, Qnil
);
9609 Vmode_line_unwind_vector
= vector
;
9614 /* Store a single character C for the frame title in mode_line_noprop_buf.
9615 Re-allocate mode_line_noprop_buf if necessary. */
9619 store_mode_line_noprop_char (char c
)
9621 store_mode_line_noprop_char (c
)
9625 /* If output position has reached the end of the allocated buffer,
9626 double the buffer's size. */
9627 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9629 int len
= MODE_LINE_NOPROP_LEN (0);
9630 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9631 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9632 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9633 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9636 *mode_line_noprop_ptr
++ = c
;
9640 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9641 mode_line_noprop_ptr. STR is the string to store. Do not copy
9642 characters that yield more columns than PRECISION; PRECISION <= 0
9643 means copy the whole string. Pad with spaces until FIELD_WIDTH
9644 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9645 pad. Called from display_mode_element when it is used to build a
9649 store_mode_line_noprop (str
, field_width
, precision
)
9650 const unsigned char *str
;
9651 int field_width
, precision
;
9656 /* Copy at most PRECISION chars from STR. */
9657 nbytes
= strlen (str
);
9658 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9660 store_mode_line_noprop_char (*str
++);
9662 /* Fill up with spaces until FIELD_WIDTH reached. */
9663 while (field_width
> 0
9666 store_mode_line_noprop_char (' ');
9673 /***********************************************************************
9675 ***********************************************************************/
9677 #ifdef HAVE_WINDOW_SYSTEM
9679 /* Set the title of FRAME, if it has changed. The title format is
9680 Vicon_title_format if FRAME is iconified, otherwise it is
9681 frame_title_format. */
9684 x_consider_frame_title (frame
)
9687 struct frame
*f
= XFRAME (frame
);
9689 if (FRAME_WINDOW_P (f
)
9690 || FRAME_MINIBUF_ONLY_P (f
)
9691 || f
->explicit_name
)
9693 /* Do we have more than one visible frame on this X display? */
9700 int count
= SPECPDL_INDEX ();
9702 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9704 Lisp_Object other_frame
= XCAR (tail
);
9705 struct frame
*tf
= XFRAME (other_frame
);
9708 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9709 && !FRAME_MINIBUF_ONLY_P (tf
)
9710 && !EQ (other_frame
, tip_frame
)
9711 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9715 /* Set global variable indicating that multiple frames exist. */
9716 multiple_frames
= CONSP (tail
);
9718 /* Switch to the buffer of selected window of the frame. Set up
9719 mode_line_target so that display_mode_element will output into
9720 mode_line_noprop_buf; then display the title. */
9721 record_unwind_protect (unwind_format_mode_line
,
9722 format_mode_line_unwind_data
9723 (current_buffer
, selected_window
, 0));
9725 Fselect_window (f
->selected_window
, Qt
);
9726 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9727 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9729 mode_line_target
= MODE_LINE_TITLE
;
9730 title_start
= MODE_LINE_NOPROP_LEN (0);
9731 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9732 NULL
, DEFAULT_FACE_ID
);
9733 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9734 len
= MODE_LINE_NOPROP_LEN (title_start
);
9735 title
= mode_line_noprop_buf
+ title_start
;
9736 unbind_to (count
, Qnil
);
9738 /* Set the title only if it's changed. This avoids consing in
9739 the common case where it hasn't. (If it turns out that we've
9740 already wasted too much time by walking through the list with
9741 display_mode_element, then we might need to optimize at a
9742 higher level than this.) */
9743 if (! STRINGP (f
->name
)
9744 || SBYTES (f
->name
) != len
9745 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9746 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9750 #endif /* not HAVE_WINDOW_SYSTEM */
9755 /***********************************************************************
9757 ***********************************************************************/
9760 /* Prepare for redisplay by updating menu-bar item lists when
9761 appropriate. This can call eval. */
9764 prepare_menu_bars ()
9767 struct gcpro gcpro1
, gcpro2
;
9769 Lisp_Object tooltip_frame
;
9771 #ifdef HAVE_WINDOW_SYSTEM
9772 tooltip_frame
= tip_frame
;
9774 tooltip_frame
= Qnil
;
9777 /* Update all frame titles based on their buffer names, etc. We do
9778 this before the menu bars so that the buffer-menu will show the
9779 up-to-date frame titles. */
9780 #ifdef HAVE_WINDOW_SYSTEM
9781 if (windows_or_buffers_changed
|| update_mode_lines
)
9783 Lisp_Object tail
, frame
;
9785 FOR_EACH_FRAME (tail
, frame
)
9788 if (!EQ (frame
, tooltip_frame
)
9789 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9790 x_consider_frame_title (frame
);
9793 #endif /* HAVE_WINDOW_SYSTEM */
9795 /* Update the menu bar item lists, if appropriate. This has to be
9796 done before any actual redisplay or generation of display lines. */
9797 all_windows
= (update_mode_lines
9798 || buffer_shared
> 1
9799 || windows_or_buffers_changed
);
9802 Lisp_Object tail
, frame
;
9803 int count
= SPECPDL_INDEX ();
9804 /* 1 means that update_menu_bar has run its hooks
9805 so any further calls to update_menu_bar shouldn't do so again. */
9806 int menu_bar_hooks_run
= 0;
9808 record_unwind_save_match_data ();
9810 FOR_EACH_FRAME (tail
, frame
)
9814 /* Ignore tooltip frame. */
9815 if (EQ (frame
, tooltip_frame
))
9818 /* If a window on this frame changed size, report that to
9819 the user and clear the size-change flag. */
9820 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9822 Lisp_Object functions
;
9824 /* Clear flag first in case we get an error below. */
9825 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9826 functions
= Vwindow_size_change_functions
;
9827 GCPRO2 (tail
, functions
);
9829 while (CONSP (functions
))
9831 if (!EQ (XCAR (functions
), Qt
))
9832 call1 (XCAR (functions
), frame
);
9833 functions
= XCDR (functions
);
9839 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9840 #ifdef HAVE_WINDOW_SYSTEM
9841 update_tool_bar (f
, 0);
9844 if (windows_or_buffers_changed
)
9845 ns_set_doc_edited (f
, Fbuffer_modified_p
9846 (XWINDOW (f
->selected_window
)->buffer
));
9851 unbind_to (count
, Qnil
);
9855 struct frame
*sf
= SELECTED_FRAME ();
9856 update_menu_bar (sf
, 1, 0);
9857 #ifdef HAVE_WINDOW_SYSTEM
9858 update_tool_bar (sf
, 1);
9862 /* Motif needs this. See comment in xmenu.c. Turn it off when
9863 pending_menu_activation is not defined. */
9864 #ifdef USE_X_TOOLKIT
9865 pending_menu_activation
= 0;
9870 /* Update the menu bar item list for frame F. This has to be done
9871 before we start to fill in any display lines, because it can call
9874 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9876 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9877 already ran the menu bar hooks for this redisplay, so there
9878 is no need to run them again. The return value is the
9879 updated value of this flag, to pass to the next call. */
9882 update_menu_bar (f
, save_match_data
, hooks_run
)
9884 int save_match_data
;
9888 register struct window
*w
;
9890 /* If called recursively during a menu update, do nothing. This can
9891 happen when, for instance, an activate-menubar-hook causes a
9893 if (inhibit_menubar_update
)
9896 window
= FRAME_SELECTED_WINDOW (f
);
9897 w
= XWINDOW (window
);
9899 if (FRAME_WINDOW_P (f
)
9901 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9902 || defined (HAVE_NS) || defined (USE_GTK)
9903 FRAME_EXTERNAL_MENU_BAR (f
)
9905 FRAME_MENU_BAR_LINES (f
) > 0
9907 : FRAME_MENU_BAR_LINES (f
) > 0)
9909 /* If the user has switched buffers or windows, we need to
9910 recompute to reflect the new bindings. But we'll
9911 recompute when update_mode_lines is set too; that means
9912 that people can use force-mode-line-update to request
9913 that the menu bar be recomputed. The adverse effect on
9914 the rest of the redisplay algorithm is about the same as
9915 windows_or_buffers_changed anyway. */
9916 if (windows_or_buffers_changed
9917 /* This used to test w->update_mode_line, but we believe
9918 there is no need to recompute the menu in that case. */
9919 || update_mode_lines
9920 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9921 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9922 != !NILP (w
->last_had_star
))
9923 || ((!NILP (Vtransient_mark_mode
)
9924 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9925 != !NILP (w
->region_showing
)))
9927 struct buffer
*prev
= current_buffer
;
9928 int count
= SPECPDL_INDEX ();
9930 specbind (Qinhibit_menubar_update
, Qt
);
9932 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9933 if (save_match_data
)
9934 record_unwind_save_match_data ();
9935 if (NILP (Voverriding_local_map_menu_flag
))
9937 specbind (Qoverriding_terminal_local_map
, Qnil
);
9938 specbind (Qoverriding_local_map
, Qnil
);
9943 /* Run the Lucid hook. */
9944 safe_run_hooks (Qactivate_menubar_hook
);
9946 /* If it has changed current-menubar from previous value,
9947 really recompute the menu-bar from the value. */
9948 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9949 call0 (Qrecompute_lucid_menubar
);
9951 safe_run_hooks (Qmenu_bar_update_hook
);
9956 XSETFRAME (Vmenu_updating_frame
, f
);
9957 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9959 /* Redisplay the menu bar in case we changed it. */
9960 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9961 || defined (HAVE_NS) || defined (USE_GTK)
9962 if (FRAME_WINDOW_P (f
))
9964 #if defined (HAVE_NS)
9965 /* All frames on Mac OS share the same menubar. So only
9966 the selected frame should be allowed to set it. */
9967 if (f
== SELECTED_FRAME ())
9969 set_frame_menubar (f
, 0, 0);
9972 /* On a terminal screen, the menu bar is an ordinary screen
9973 line, and this makes it get updated. */
9974 w
->update_mode_line
= Qt
;
9975 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9976 /* In the non-toolkit version, the menu bar is an ordinary screen
9977 line, and this makes it get updated. */
9978 w
->update_mode_line
= Qt
;
9979 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9981 unbind_to (count
, Qnil
);
9982 set_buffer_internal_1 (prev
);
9991 /***********************************************************************
9993 ***********************************************************************/
9995 #ifdef HAVE_WINDOW_SYSTEM
9998 Nominal cursor position -- where to draw output.
9999 HPOS and VPOS are window relative glyph matrix coordinates.
10000 X and Y are window relative pixel coordinates. */
10002 struct cursor_pos output_cursor
;
10006 Set the global variable output_cursor to CURSOR. All cursor
10007 positions are relative to updated_window. */
10010 set_output_cursor (cursor
)
10011 struct cursor_pos
*cursor
;
10013 output_cursor
.hpos
= cursor
->hpos
;
10014 output_cursor
.vpos
= cursor
->vpos
;
10015 output_cursor
.x
= cursor
->x
;
10016 output_cursor
.y
= cursor
->y
;
10021 Set a nominal cursor position.
10023 HPOS and VPOS are column/row positions in a window glyph matrix. X
10024 and Y are window text area relative pixel positions.
10026 If this is done during an update, updated_window will contain the
10027 window that is being updated and the position is the future output
10028 cursor position for that window. If updated_window is null, use
10029 selected_window and display the cursor at the given position. */
10032 x_cursor_to (vpos
, hpos
, y
, x
)
10033 int vpos
, hpos
, y
, x
;
10037 /* If updated_window is not set, work on selected_window. */
10038 if (updated_window
)
10039 w
= updated_window
;
10041 w
= XWINDOW (selected_window
);
10043 /* Set the output cursor. */
10044 output_cursor
.hpos
= hpos
;
10045 output_cursor
.vpos
= vpos
;
10046 output_cursor
.x
= x
;
10047 output_cursor
.y
= y
;
10049 /* If not called as part of an update, really display the cursor.
10050 This will also set the cursor position of W. */
10051 if (updated_window
== NULL
)
10054 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10055 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10056 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10061 #endif /* HAVE_WINDOW_SYSTEM */
10064 /***********************************************************************
10066 ***********************************************************************/
10068 #ifdef HAVE_WINDOW_SYSTEM
10070 /* Where the mouse was last time we reported a mouse event. */
10072 FRAME_PTR last_mouse_frame
;
10074 /* Tool-bar item index of the item on which a mouse button was pressed
10077 int last_tool_bar_item
;
10081 update_tool_bar_unwind (frame
)
10084 selected_frame
= frame
;
10088 /* Update the tool-bar item list for frame F. This has to be done
10089 before we start to fill in any display lines. Called from
10090 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10091 and restore it here. */
10094 update_tool_bar (f
, save_match_data
)
10096 int save_match_data
;
10098 #if defined (USE_GTK) || defined (HAVE_NS)
10099 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10101 int do_update
= WINDOWP (f
->tool_bar_window
)
10102 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10107 Lisp_Object window
;
10110 window
= FRAME_SELECTED_WINDOW (f
);
10111 w
= XWINDOW (window
);
10113 /* If the user has switched buffers or windows, we need to
10114 recompute to reflect the new bindings. But we'll
10115 recompute when update_mode_lines is set too; that means
10116 that people can use force-mode-line-update to request
10117 that the menu bar be recomputed. The adverse effect on
10118 the rest of the redisplay algorithm is about the same as
10119 windows_or_buffers_changed anyway. */
10120 if (windows_or_buffers_changed
10121 || !NILP (w
->update_mode_line
)
10122 || update_mode_lines
10123 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10124 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10125 != !NILP (w
->last_had_star
))
10126 || ((!NILP (Vtransient_mark_mode
)
10127 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10128 != !NILP (w
->region_showing
)))
10130 struct buffer
*prev
= current_buffer
;
10131 int count
= SPECPDL_INDEX ();
10132 Lisp_Object frame
, new_tool_bar
;
10133 int new_n_tool_bar
;
10134 struct gcpro gcpro1
;
10136 /* Set current_buffer to the buffer of the selected
10137 window of the frame, so that we get the right local
10139 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10141 /* Save match data, if we must. */
10142 if (save_match_data
)
10143 record_unwind_save_match_data ();
10145 /* Make sure that we don't accidentally use bogus keymaps. */
10146 if (NILP (Voverriding_local_map_menu_flag
))
10148 specbind (Qoverriding_terminal_local_map
, Qnil
);
10149 specbind (Qoverriding_local_map
, Qnil
);
10152 GCPRO1 (new_tool_bar
);
10154 /* We must temporarily set the selected frame to this frame
10155 before calling tool_bar_items, because the calculation of
10156 the tool-bar keymap uses the selected frame (see
10157 `tool-bar-make-keymap' in tool-bar.el). */
10158 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10159 XSETFRAME (frame
, f
);
10160 selected_frame
= frame
;
10162 /* Build desired tool-bar items from keymaps. */
10163 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10166 /* Redisplay the tool-bar if we changed it. */
10167 if (new_n_tool_bar
!= f
->n_tool_bar_items
10168 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10170 /* Redisplay that happens asynchronously due to an expose event
10171 may access f->tool_bar_items. Make sure we update both
10172 variables within BLOCK_INPUT so no such event interrupts. */
10174 f
->tool_bar_items
= new_tool_bar
;
10175 f
->n_tool_bar_items
= new_n_tool_bar
;
10176 w
->update_mode_line
= Qt
;
10182 unbind_to (count
, Qnil
);
10183 set_buffer_internal_1 (prev
);
10189 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10190 F's desired tool-bar contents. F->tool_bar_items must have
10191 been set up previously by calling prepare_menu_bars. */
10194 build_desired_tool_bar_string (f
)
10197 int i
, size
, size_needed
;
10198 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10199 Lisp_Object image
, plist
, props
;
10201 image
= plist
= props
= Qnil
;
10202 GCPRO3 (image
, plist
, props
);
10204 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10205 Otherwise, make a new string. */
10207 /* The size of the string we might be able to reuse. */
10208 size
= (STRINGP (f
->desired_tool_bar_string
)
10209 ? SCHARS (f
->desired_tool_bar_string
)
10212 /* We need one space in the string for each image. */
10213 size_needed
= f
->n_tool_bar_items
;
10215 /* Reuse f->desired_tool_bar_string, if possible. */
10216 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10217 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10218 make_number (' '));
10221 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10222 Fremove_text_properties (make_number (0), make_number (size
),
10223 props
, f
->desired_tool_bar_string
);
10226 /* Put a `display' property on the string for the images to display,
10227 put a `menu_item' property on tool-bar items with a value that
10228 is the index of the item in F's tool-bar item vector. */
10229 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10231 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10233 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10234 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10235 int hmargin
, vmargin
, relief
, idx
, end
;
10236 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
10238 /* If image is a vector, choose the image according to the
10240 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10241 if (VECTORP (image
))
10245 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10246 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10249 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10250 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10252 xassert (ASIZE (image
) >= idx
);
10253 image
= AREF (image
, idx
);
10258 /* Ignore invalid image specifications. */
10259 if (!valid_image_p (image
))
10262 /* Display the tool-bar button pressed, or depressed. */
10263 plist
= Fcopy_sequence (XCDR (image
));
10265 /* Compute margin and relief to draw. */
10266 relief
= (tool_bar_button_relief
>= 0
10267 ? tool_bar_button_relief
10268 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10269 hmargin
= vmargin
= relief
;
10271 if (INTEGERP (Vtool_bar_button_margin
)
10272 && XINT (Vtool_bar_button_margin
) > 0)
10274 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10275 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10277 else if (CONSP (Vtool_bar_button_margin
))
10279 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10280 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10281 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10283 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10284 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10285 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10288 if (auto_raise_tool_bar_buttons_p
)
10290 /* Add a `:relief' property to the image spec if the item is
10294 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10301 /* If image is selected, display it pressed, i.e. with a
10302 negative relief. If it's not selected, display it with a
10304 plist
= Fplist_put (plist
, QCrelief
,
10306 ? make_number (-relief
)
10307 : make_number (relief
)));
10312 /* Put a margin around the image. */
10313 if (hmargin
|| vmargin
)
10315 if (hmargin
== vmargin
)
10316 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10318 plist
= Fplist_put (plist
, QCmargin
,
10319 Fcons (make_number (hmargin
),
10320 make_number (vmargin
)));
10323 /* If button is not enabled, and we don't have special images
10324 for the disabled state, make the image appear disabled by
10325 applying an appropriate algorithm to it. */
10326 if (!enabled_p
&& idx
< 0)
10327 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10329 /* Put a `display' text property on the string for the image to
10330 display. Put a `menu-item' property on the string that gives
10331 the start of this item's properties in the tool-bar items
10333 image
= Fcons (Qimage
, plist
);
10334 props
= list4 (Qdisplay
, image
,
10335 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10337 /* Let the last image hide all remaining spaces in the tool bar
10338 string. The string can be longer than needed when we reuse a
10339 previous string. */
10340 if (i
+ 1 == f
->n_tool_bar_items
)
10341 end
= SCHARS (f
->desired_tool_bar_string
);
10344 Fadd_text_properties (make_number (i
), make_number (end
),
10345 props
, f
->desired_tool_bar_string
);
10353 /* Display one line of the tool-bar of frame IT->f.
10355 HEIGHT specifies the desired height of the tool-bar line.
10356 If the actual height of the glyph row is less than HEIGHT, the
10357 row's height is increased to HEIGHT, and the icons are centered
10358 vertically in the new height.
10360 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10361 count a final empty row in case the tool-bar width exactly matches
10366 display_tool_bar_line (it
, height
)
10370 struct glyph_row
*row
= it
->glyph_row
;
10371 int max_x
= it
->last_visible_x
;
10372 struct glyph
*last
;
10374 prepare_desired_row (row
);
10375 row
->y
= it
->current_y
;
10377 /* Note that this isn't made use of if the face hasn't a box,
10378 so there's no need to check the face here. */
10379 it
->start_of_box_run_p
= 1;
10381 while (it
->current_x
< max_x
)
10383 int x
, n_glyphs_before
, i
, nglyphs
;
10384 struct it it_before
;
10386 /* Get the next display element. */
10387 if (!get_next_display_element (it
))
10389 /* Don't count empty row if we are counting needed tool-bar lines. */
10390 if (height
< 0 && !it
->hpos
)
10395 /* Produce glyphs. */
10396 n_glyphs_before
= row
->used
[TEXT_AREA
];
10399 PRODUCE_GLYPHS (it
);
10401 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10403 x
= it_before
.current_x
;
10404 while (i
< nglyphs
)
10406 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10408 if (x
+ glyph
->pixel_width
> max_x
)
10410 /* Glyph doesn't fit on line. Backtrack. */
10411 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10413 /* If this is the only glyph on this line, it will never fit on the
10414 toolbar, so skip it. But ensure there is at least one glyph,
10415 so we don't accidentally disable the tool-bar. */
10416 if (n_glyphs_before
== 0
10417 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10423 x
+= glyph
->pixel_width
;
10427 /* Stop at line ends. */
10428 if (ITERATOR_AT_END_OF_LINE_P (it
))
10431 set_iterator_to_next (it
, 1);
10436 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10438 /* Use default face for the border below the tool bar.
10440 FIXME: When auto-resize-tool-bars is grow-only, there is
10441 no additional border below the possibly empty tool-bar lines.
10442 So to make the extra empty lines look "normal", we have to
10443 use the tool-bar face for the border too. */
10444 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10445 it
->face_id
= DEFAULT_FACE_ID
;
10447 extend_face_to_end_of_line (it
);
10448 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10449 last
->right_box_line_p
= 1;
10450 if (last
== row
->glyphs
[TEXT_AREA
])
10451 last
->left_box_line_p
= 1;
10453 /* Make line the desired height and center it vertically. */
10454 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10456 /* Don't add more than one line height. */
10457 height
%= FRAME_LINE_HEIGHT (it
->f
);
10458 it
->max_ascent
+= height
/ 2;
10459 it
->max_descent
+= (height
+ 1) / 2;
10462 compute_line_metrics (it
);
10464 /* If line is empty, make it occupy the rest of the tool-bar. */
10465 if (!row
->displays_text_p
)
10467 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10468 row
->visible_height
= row
->height
;
10469 row
->ascent
= row
->phys_ascent
= 0;
10470 row
->extra_line_spacing
= 0;
10473 row
->full_width_p
= 1;
10474 row
->continued_p
= 0;
10475 row
->truncated_on_left_p
= 0;
10476 row
->truncated_on_right_p
= 0;
10478 it
->current_x
= it
->hpos
= 0;
10479 it
->current_y
+= row
->height
;
10485 /* Max tool-bar height. */
10487 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10488 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10490 /* Value is the number of screen lines needed to make all tool-bar
10491 items of frame F visible. The number of actual rows needed is
10492 returned in *N_ROWS if non-NULL. */
10495 tool_bar_lines_needed (f
, n_rows
)
10499 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10501 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10502 the desired matrix, so use (unused) mode-line row as temporary row to
10503 avoid destroying the first tool-bar row. */
10504 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10506 /* Initialize an iterator for iteration over
10507 F->desired_tool_bar_string in the tool-bar window of frame F. */
10508 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10509 it
.first_visible_x
= 0;
10510 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10511 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10513 while (!ITERATOR_AT_END_P (&it
))
10515 clear_glyph_row (temp_row
);
10516 it
.glyph_row
= temp_row
;
10517 display_tool_bar_line (&it
, -1);
10519 clear_glyph_row (temp_row
);
10521 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10523 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10525 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10529 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10531 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10540 frame
= selected_frame
;
10542 CHECK_FRAME (frame
);
10543 f
= XFRAME (frame
);
10545 if (WINDOWP (f
->tool_bar_window
)
10546 || (w
= XWINDOW (f
->tool_bar_window
),
10547 WINDOW_TOTAL_LINES (w
) > 0))
10549 update_tool_bar (f
, 1);
10550 if (f
->n_tool_bar_items
)
10552 build_desired_tool_bar_string (f
);
10553 nlines
= tool_bar_lines_needed (f
, NULL
);
10557 return make_number (nlines
);
10561 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10562 height should be changed. */
10565 redisplay_tool_bar (f
)
10570 struct glyph_row
*row
;
10572 #if defined (USE_GTK) || defined (HAVE_NS)
10573 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10574 update_frame_tool_bar (f
);
10578 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10579 do anything. This means you must start with tool-bar-lines
10580 non-zero to get the auto-sizing effect. Or in other words, you
10581 can turn off tool-bars by specifying tool-bar-lines zero. */
10582 if (!WINDOWP (f
->tool_bar_window
)
10583 || (w
= XWINDOW (f
->tool_bar_window
),
10584 WINDOW_TOTAL_LINES (w
) == 0))
10587 /* Set up an iterator for the tool-bar window. */
10588 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10589 it
.first_visible_x
= 0;
10590 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10591 row
= it
.glyph_row
;
10593 /* Build a string that represents the contents of the tool-bar. */
10594 build_desired_tool_bar_string (f
);
10595 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10597 if (f
->n_tool_bar_rows
== 0)
10601 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10602 nlines
!= WINDOW_TOTAL_LINES (w
)))
10604 extern Lisp_Object Qtool_bar_lines
;
10606 int old_height
= WINDOW_TOTAL_LINES (w
);
10608 XSETFRAME (frame
, f
);
10609 Fmodify_frame_parameters (frame
,
10610 Fcons (Fcons (Qtool_bar_lines
,
10611 make_number (nlines
)),
10613 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10615 clear_glyph_matrix (w
->desired_matrix
);
10616 fonts_changed_p
= 1;
10622 /* Display as many lines as needed to display all tool-bar items. */
10624 if (f
->n_tool_bar_rows
> 0)
10626 int border
, rows
, height
, extra
;
10628 if (INTEGERP (Vtool_bar_border
))
10629 border
= XINT (Vtool_bar_border
);
10630 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10631 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10632 else if (EQ (Vtool_bar_border
, Qborder_width
))
10633 border
= f
->border_width
;
10639 rows
= f
->n_tool_bar_rows
;
10640 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10641 extra
= it
.last_visible_y
- border
- height
* rows
;
10643 while (it
.current_y
< it
.last_visible_y
)
10646 if (extra
> 0 && rows
-- > 0)
10648 h
= (extra
+ rows
- 1) / rows
;
10651 display_tool_bar_line (&it
, height
+ h
);
10656 while (it
.current_y
< it
.last_visible_y
)
10657 display_tool_bar_line (&it
, 0);
10660 /* It doesn't make much sense to try scrolling in the tool-bar
10661 window, so don't do it. */
10662 w
->desired_matrix
->no_scrolling_p
= 1;
10663 w
->must_be_updated_p
= 1;
10665 if (!NILP (Vauto_resize_tool_bars
))
10667 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10668 int change_height_p
= 0;
10670 /* If we couldn't display everything, change the tool-bar's
10671 height if there is room for more. */
10672 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10673 && it
.current_y
< max_tool_bar_height
)
10674 change_height_p
= 1;
10676 row
= it
.glyph_row
- 1;
10678 /* If there are blank lines at the end, except for a partially
10679 visible blank line at the end that is smaller than
10680 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10681 if (!row
->displays_text_p
10682 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10683 change_height_p
= 1;
10685 /* If row displays tool-bar items, but is partially visible,
10686 change the tool-bar's height. */
10687 if (row
->displays_text_p
10688 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10689 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10690 change_height_p
= 1;
10692 /* Resize windows as needed by changing the `tool-bar-lines'
10693 frame parameter. */
10694 if (change_height_p
)
10696 extern Lisp_Object Qtool_bar_lines
;
10698 int old_height
= WINDOW_TOTAL_LINES (w
);
10700 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10702 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10703 && !f
->minimize_tool_bar_window_p
)
10704 ? (nlines
> old_height
)
10705 : (nlines
!= old_height
));
10706 f
->minimize_tool_bar_window_p
= 0;
10708 if (change_height_p
)
10710 XSETFRAME (frame
, f
);
10711 Fmodify_frame_parameters (frame
,
10712 Fcons (Fcons (Qtool_bar_lines
,
10713 make_number (nlines
)),
10715 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10717 clear_glyph_matrix (w
->desired_matrix
);
10718 f
->n_tool_bar_rows
= nrows
;
10719 fonts_changed_p
= 1;
10726 f
->minimize_tool_bar_window_p
= 0;
10731 /* Get information about the tool-bar item which is displayed in GLYPH
10732 on frame F. Return in *PROP_IDX the index where tool-bar item
10733 properties start in F->tool_bar_items. Value is zero if
10734 GLYPH doesn't display a tool-bar item. */
10737 tool_bar_item_info (f
, glyph
, prop_idx
)
10739 struct glyph
*glyph
;
10746 /* This function can be called asynchronously, which means we must
10747 exclude any possibility that Fget_text_property signals an
10749 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10750 charpos
= max (0, charpos
);
10752 /* Get the text property `menu-item' at pos. The value of that
10753 property is the start index of this item's properties in
10754 F->tool_bar_items. */
10755 prop
= Fget_text_property (make_number (charpos
),
10756 Qmenu_item
, f
->current_tool_bar_string
);
10757 if (INTEGERP (prop
))
10759 *prop_idx
= XINT (prop
);
10769 /* Get information about the tool-bar item at position X/Y on frame F.
10770 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10771 the current matrix of the tool-bar window of F, or NULL if not
10772 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10773 item in F->tool_bar_items. Value is
10775 -1 if X/Y is not on a tool-bar item
10776 0 if X/Y is on the same item that was highlighted before.
10780 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10783 struct glyph
**glyph
;
10784 int *hpos
, *vpos
, *prop_idx
;
10786 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10787 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10790 /* Find the glyph under X/Y. */
10791 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10792 if (*glyph
== NULL
)
10795 /* Get the start of this tool-bar item's properties in
10796 f->tool_bar_items. */
10797 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10800 /* Is mouse on the highlighted item? */
10801 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10802 && *vpos
>= dpyinfo
->mouse_face_beg_row
10803 && *vpos
<= dpyinfo
->mouse_face_end_row
10804 && (*vpos
> dpyinfo
->mouse_face_beg_row
10805 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10806 && (*vpos
< dpyinfo
->mouse_face_end_row
10807 || *hpos
< dpyinfo
->mouse_face_end_col
10808 || dpyinfo
->mouse_face_past_end
))
10816 Handle mouse button event on the tool-bar of frame F, at
10817 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10818 0 for button release. MODIFIERS is event modifiers for button
10822 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10825 unsigned int modifiers
;
10827 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10828 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10829 int hpos
, vpos
, prop_idx
;
10830 struct glyph
*glyph
;
10831 Lisp_Object enabled_p
;
10833 /* If not on the highlighted tool-bar item, return. */
10834 frame_to_window_pixel_xy (w
, &x
, &y
);
10835 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10838 /* If item is disabled, do nothing. */
10839 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10840 if (NILP (enabled_p
))
10845 /* Show item in pressed state. */
10846 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10847 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10848 last_tool_bar_item
= prop_idx
;
10852 Lisp_Object key
, frame
;
10853 struct input_event event
;
10854 EVENT_INIT (event
);
10856 /* Show item in released state. */
10857 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10858 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10860 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10862 XSETFRAME (frame
, f
);
10863 event
.kind
= TOOL_BAR_EVENT
;
10864 event
.frame_or_window
= frame
;
10866 kbd_buffer_store_event (&event
);
10868 event
.kind
= TOOL_BAR_EVENT
;
10869 event
.frame_or_window
= frame
;
10871 event
.modifiers
= modifiers
;
10872 kbd_buffer_store_event (&event
);
10873 last_tool_bar_item
= -1;
10878 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10879 tool-bar window-relative coordinates X/Y. Called from
10880 note_mouse_highlight. */
10883 note_tool_bar_highlight (f
, x
, y
)
10887 Lisp_Object window
= f
->tool_bar_window
;
10888 struct window
*w
= XWINDOW (window
);
10889 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10891 struct glyph
*glyph
;
10892 struct glyph_row
*row
;
10894 Lisp_Object enabled_p
;
10896 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10897 int mouse_down_p
, rc
;
10899 /* Function note_mouse_highlight is called with negative x(y
10900 values when mouse moves outside of the frame. */
10901 if (x
<= 0 || y
<= 0)
10903 clear_mouse_face (dpyinfo
);
10907 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10910 /* Not on tool-bar item. */
10911 clear_mouse_face (dpyinfo
);
10915 /* On same tool-bar item as before. */
10916 goto set_help_echo
;
10918 clear_mouse_face (dpyinfo
);
10920 /* Mouse is down, but on different tool-bar item? */
10921 mouse_down_p
= (dpyinfo
->grabbed
10922 && f
== last_mouse_frame
10923 && FRAME_LIVE_P (f
));
10925 && last_tool_bar_item
!= prop_idx
)
10928 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10929 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10931 /* If tool-bar item is not enabled, don't highlight it. */
10932 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10933 if (!NILP (enabled_p
))
10935 /* Compute the x-position of the glyph. In front and past the
10936 image is a space. We include this in the highlighted area. */
10937 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10938 for (i
= x
= 0; i
< hpos
; ++i
)
10939 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10941 /* Record this as the current active region. */
10942 dpyinfo
->mouse_face_beg_col
= hpos
;
10943 dpyinfo
->mouse_face_beg_row
= vpos
;
10944 dpyinfo
->mouse_face_beg_x
= x
;
10945 dpyinfo
->mouse_face_beg_y
= row
->y
;
10946 dpyinfo
->mouse_face_past_end
= 0;
10948 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10949 dpyinfo
->mouse_face_end_row
= vpos
;
10950 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10951 dpyinfo
->mouse_face_end_y
= row
->y
;
10952 dpyinfo
->mouse_face_window
= window
;
10953 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10955 /* Display it as active. */
10956 show_mouse_face (dpyinfo
, draw
);
10957 dpyinfo
->mouse_face_image_state
= draw
;
10962 /* Set help_echo_string to a help string to display for this tool-bar item.
10963 XTread_socket does the rest. */
10964 help_echo_object
= help_echo_window
= Qnil
;
10965 help_echo_pos
= -1;
10966 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10967 if (NILP (help_echo_string
))
10968 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10971 #endif /* HAVE_WINDOW_SYSTEM */
10975 /************************************************************************
10976 Horizontal scrolling
10977 ************************************************************************/
10979 static int hscroll_window_tree
P_ ((Lisp_Object
));
10980 static int hscroll_windows
P_ ((Lisp_Object
));
10982 /* For all leaf windows in the window tree rooted at WINDOW, set their
10983 hscroll value so that PT is (i) visible in the window, and (ii) so
10984 that it is not within a certain margin at the window's left and
10985 right border. Value is non-zero if any window's hscroll has been
10989 hscroll_window_tree (window
)
10990 Lisp_Object window
;
10992 int hscrolled_p
= 0;
10993 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10994 int hscroll_step_abs
= 0;
10995 double hscroll_step_rel
= 0;
10997 if (hscroll_relative_p
)
10999 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11000 if (hscroll_step_rel
< 0)
11002 hscroll_relative_p
= 0;
11003 hscroll_step_abs
= 0;
11006 else if (INTEGERP (Vhscroll_step
))
11008 hscroll_step_abs
= XINT (Vhscroll_step
);
11009 if (hscroll_step_abs
< 0)
11010 hscroll_step_abs
= 0;
11013 hscroll_step_abs
= 0;
11015 while (WINDOWP (window
))
11017 struct window
*w
= XWINDOW (window
);
11019 if (WINDOWP (w
->hchild
))
11020 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11021 else if (WINDOWP (w
->vchild
))
11022 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11023 else if (w
->cursor
.vpos
>= 0)
11026 int text_area_width
;
11027 struct glyph_row
*current_cursor_row
11028 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11029 struct glyph_row
*desired_cursor_row
11030 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11031 struct glyph_row
*cursor_row
11032 = (desired_cursor_row
->enabled_p
11033 ? desired_cursor_row
11034 : current_cursor_row
);
11036 text_area_width
= window_box_width (w
, TEXT_AREA
);
11038 /* Scroll when cursor is inside this scroll margin. */
11039 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11041 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11042 && ((XFASTINT (w
->hscroll
)
11043 && w
->cursor
.x
<= h_margin
)
11044 || (cursor_row
->enabled_p
11045 && cursor_row
->truncated_on_right_p
11046 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11050 struct buffer
*saved_current_buffer
;
11054 /* Find point in a display of infinite width. */
11055 saved_current_buffer
= current_buffer
;
11056 current_buffer
= XBUFFER (w
->buffer
);
11058 if (w
== XWINDOW (selected_window
))
11059 pt
= BUF_PT (current_buffer
);
11062 pt
= marker_position (w
->pointm
);
11063 pt
= max (BEGV
, pt
);
11067 /* Move iterator to pt starting at cursor_row->start in
11068 a line with infinite width. */
11069 init_to_row_start (&it
, w
, cursor_row
);
11070 it
.last_visible_x
= INFINITY
;
11071 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11072 current_buffer
= saved_current_buffer
;
11074 /* Position cursor in window. */
11075 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11076 hscroll
= max (0, (it
.current_x
11077 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11078 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11079 : (text_area_width
/ 2))))
11080 / FRAME_COLUMN_WIDTH (it
.f
);
11081 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11083 if (hscroll_relative_p
)
11084 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11087 wanted_x
= text_area_width
11088 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11091 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11095 if (hscroll_relative_p
)
11096 wanted_x
= text_area_width
* hscroll_step_rel
11099 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11102 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11104 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11106 /* Don't call Fset_window_hscroll if value hasn't
11107 changed because it will prevent redisplay
11109 if (XFASTINT (w
->hscroll
) != hscroll
)
11111 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11112 w
->hscroll
= make_number (hscroll
);
11121 /* Value is non-zero if hscroll of any leaf window has been changed. */
11122 return hscrolled_p
;
11126 /* Set hscroll so that cursor is visible and not inside horizontal
11127 scroll margins for all windows in the tree rooted at WINDOW. See
11128 also hscroll_window_tree above. Value is non-zero if any window's
11129 hscroll has been changed. If it has, desired matrices on the frame
11130 of WINDOW are cleared. */
11133 hscroll_windows (window
)
11134 Lisp_Object window
;
11136 int hscrolled_p
= hscroll_window_tree (window
);
11138 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11139 return hscrolled_p
;
11144 /************************************************************************
11146 ************************************************************************/
11148 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11149 to a non-zero value. This is sometimes handy to have in a debugger
11154 /* First and last unchanged row for try_window_id. */
11156 int debug_first_unchanged_at_end_vpos
;
11157 int debug_last_unchanged_at_beg_vpos
;
11159 /* Delta vpos and y. */
11161 int debug_dvpos
, debug_dy
;
11163 /* Delta in characters and bytes for try_window_id. */
11165 int debug_delta
, debug_delta_bytes
;
11167 /* Values of window_end_pos and window_end_vpos at the end of
11170 EMACS_INT debug_end_pos
, debug_end_vpos
;
11172 /* Append a string to W->desired_matrix->method. FMT is a printf
11173 format string. A1...A9 are a supplement for a variable-length
11174 argument list. If trace_redisplay_p is non-zero also printf the
11175 resulting string to stderr. */
11178 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11181 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11184 char *method
= w
->desired_matrix
->method
;
11185 int len
= strlen (method
);
11186 int size
= sizeof w
->desired_matrix
->method
;
11187 int remaining
= size
- len
- 1;
11189 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11190 if (len
&& remaining
)
11193 --remaining
, ++len
;
11196 strncpy (method
+ len
, buffer
, remaining
);
11198 if (trace_redisplay_p
)
11199 fprintf (stderr
, "%p (%s): %s\n",
11201 ((BUFFERP (w
->buffer
)
11202 && STRINGP (XBUFFER (w
->buffer
)->name
))
11203 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
11208 #endif /* GLYPH_DEBUG */
11211 /* Value is non-zero if all changes in window W, which displays
11212 current_buffer, are in the text between START and END. START is a
11213 buffer position, END is given as a distance from Z. Used in
11214 redisplay_internal for display optimization. */
11217 text_outside_line_unchanged_p (w
, start
, end
)
11221 int unchanged_p
= 1;
11223 /* If text or overlays have changed, see where. */
11224 if (XFASTINT (w
->last_modified
) < MODIFF
11225 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11227 /* Gap in the line? */
11228 if (GPT
< start
|| Z
- GPT
< end
)
11231 /* Changes start in front of the line, or end after it? */
11233 && (BEG_UNCHANGED
< start
- 1
11234 || END_UNCHANGED
< end
))
11237 /* If selective display, can't optimize if changes start at the
11238 beginning of the line. */
11240 && INTEGERP (current_buffer
->selective_display
)
11241 && XINT (current_buffer
->selective_display
) > 0
11242 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11245 /* If there are overlays at the start or end of the line, these
11246 may have overlay strings with newlines in them. A change at
11247 START, for instance, may actually concern the display of such
11248 overlay strings as well, and they are displayed on different
11249 lines. So, quickly rule out this case. (For the future, it
11250 might be desirable to implement something more telling than
11251 just BEG/END_UNCHANGED.) */
11254 if (BEG
+ BEG_UNCHANGED
== start
11255 && overlay_touches_p (start
))
11257 if (END_UNCHANGED
== end
11258 && overlay_touches_p (Z
- end
))
11262 /* Under bidi reordering, adding or deleting a character in the
11263 beginning of a paragraph, before the first strong directional
11264 character, can change the base direction of the paragraph (unless
11265 the buffer specifies a fixed paragraph direction), which will
11266 require to redisplay the whole paragraph. It might be worthwhile
11267 to find the paragraph limits and widen the range of redisplayed
11268 lines to that, but for now just give up this optimization. */
11269 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
11270 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
11274 return unchanged_p
;
11278 /* Do a frame update, taking possible shortcuts into account. This is
11279 the main external entry point for redisplay.
11281 If the last redisplay displayed an echo area message and that message
11282 is no longer requested, we clear the echo area or bring back the
11283 mini-buffer if that is in use. */
11288 redisplay_internal (0);
11293 overlay_arrow_string_or_property (var
)
11298 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11301 return Voverlay_arrow_string
;
11304 /* Return 1 if there are any overlay-arrows in current_buffer. */
11306 overlay_arrow_in_current_buffer_p ()
11310 for (vlist
= Voverlay_arrow_variable_list
;
11312 vlist
= XCDR (vlist
))
11314 Lisp_Object var
= XCAR (vlist
);
11317 if (!SYMBOLP (var
))
11319 val
= find_symbol_value (var
);
11321 && current_buffer
== XMARKER (val
)->buffer
)
11328 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11332 overlay_arrows_changed_p ()
11336 for (vlist
= Voverlay_arrow_variable_list
;
11338 vlist
= XCDR (vlist
))
11340 Lisp_Object var
= XCAR (vlist
);
11341 Lisp_Object val
, pstr
;
11343 if (!SYMBOLP (var
))
11345 val
= find_symbol_value (var
);
11346 if (!MARKERP (val
))
11348 if (! EQ (COERCE_MARKER (val
),
11349 Fget (var
, Qlast_arrow_position
))
11350 || ! (pstr
= overlay_arrow_string_or_property (var
),
11351 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11357 /* Mark overlay arrows to be updated on next redisplay. */
11360 update_overlay_arrows (up_to_date
)
11365 for (vlist
= Voverlay_arrow_variable_list
;
11367 vlist
= XCDR (vlist
))
11369 Lisp_Object var
= XCAR (vlist
);
11371 if (!SYMBOLP (var
))
11374 if (up_to_date
> 0)
11376 Lisp_Object val
= find_symbol_value (var
);
11377 Fput (var
, Qlast_arrow_position
,
11378 COERCE_MARKER (val
));
11379 Fput (var
, Qlast_arrow_string
,
11380 overlay_arrow_string_or_property (var
));
11382 else if (up_to_date
< 0
11383 || !NILP (Fget (var
, Qlast_arrow_position
)))
11385 Fput (var
, Qlast_arrow_position
, Qt
);
11386 Fput (var
, Qlast_arrow_string
, Qt
);
11392 /* Return overlay arrow string to display at row.
11393 Return integer (bitmap number) for arrow bitmap in left fringe.
11394 Return nil if no overlay arrow. */
11397 overlay_arrow_at_row (it
, row
)
11399 struct glyph_row
*row
;
11403 for (vlist
= Voverlay_arrow_variable_list
;
11405 vlist
= XCDR (vlist
))
11407 Lisp_Object var
= XCAR (vlist
);
11410 if (!SYMBOLP (var
))
11413 val
= find_symbol_value (var
);
11416 && current_buffer
== XMARKER (val
)->buffer
11417 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11419 if (FRAME_WINDOW_P (it
->f
)
11420 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11422 #ifdef HAVE_WINDOW_SYSTEM
11423 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11426 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11427 return make_number (fringe_bitmap
);
11430 return make_number (-1); /* Use default arrow bitmap */
11432 return overlay_arrow_string_or_property (var
);
11439 /* Return 1 if point moved out of or into a composition. Otherwise
11440 return 0. PREV_BUF and PREV_PT are the last point buffer and
11441 position. BUF and PT are the current point buffer and position. */
11444 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11445 struct buffer
*prev_buf
, *buf
;
11448 EMACS_INT start
, end
;
11450 Lisp_Object buffer
;
11452 XSETBUFFER (buffer
, buf
);
11453 /* Check a composition at the last point if point moved within the
11455 if (prev_buf
== buf
)
11458 /* Point didn't move. */
11461 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11462 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11463 && COMPOSITION_VALID_P (start
, end
, prop
)
11464 && start
< prev_pt
&& end
> prev_pt
)
11465 /* The last point was within the composition. Return 1 iff
11466 point moved out of the composition. */
11467 return (pt
<= start
|| pt
>= end
);
11470 /* Check a composition at the current point. */
11471 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11472 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11473 && COMPOSITION_VALID_P (start
, end
, prop
)
11474 && start
< pt
&& end
> pt
);
11478 /* Reconsider the setting of B->clip_changed which is displayed
11482 reconsider_clip_changes (w
, b
)
11486 if (b
->clip_changed
11487 && !NILP (w
->window_end_valid
)
11488 && w
->current_matrix
->buffer
== b
11489 && w
->current_matrix
->zv
== BUF_ZV (b
)
11490 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11491 b
->clip_changed
= 0;
11493 /* If display wasn't paused, and W is not a tool bar window, see if
11494 point has been moved into or out of a composition. In that case,
11495 we set b->clip_changed to 1 to force updating the screen. If
11496 b->clip_changed has already been set to 1, we can skip this
11498 if (!b
->clip_changed
11499 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11503 if (w
== XWINDOW (selected_window
))
11504 pt
= BUF_PT (current_buffer
);
11506 pt
= marker_position (w
->pointm
);
11508 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11509 || pt
!= XINT (w
->last_point
))
11510 && check_point_in_composition (w
->current_matrix
->buffer
,
11511 XINT (w
->last_point
),
11512 XBUFFER (w
->buffer
), pt
))
11513 b
->clip_changed
= 1;
11518 /* Select FRAME to forward the values of frame-local variables into C
11519 variables so that the redisplay routines can access those values
11523 select_frame_for_redisplay (frame
)
11526 Lisp_Object tail
, symbol
, val
;
11527 Lisp_Object old
= selected_frame
;
11528 struct Lisp_Symbol
*sym
;
11530 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11532 selected_frame
= frame
;
11536 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11537 if (CONSP (XCAR (tail
))
11538 && (symbol
= XCAR (XCAR (tail
)),
11540 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11542 (BUFFER_LOCAL_VALUEP (val
)))
11543 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11544 /* Use find_symbol_value rather than Fsymbol_value
11545 to avoid an error if it is void. */
11546 find_symbol_value (symbol
);
11547 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11551 #define STOP_POLLING \
11552 do { if (! polling_stopped_here) stop_polling (); \
11553 polling_stopped_here = 1; } while (0)
11555 #define RESUME_POLLING \
11556 do { if (polling_stopped_here) start_polling (); \
11557 polling_stopped_here = 0; } while (0)
11560 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11561 response to any user action; therefore, we should preserve the echo
11562 area. (Actually, our caller does that job.) Perhaps in the future
11563 avoid recentering windows if it is not necessary; currently that
11564 causes some problems. */
11567 redisplay_internal (preserve_echo_area
)
11568 int preserve_echo_area
;
11570 struct window
*w
= XWINDOW (selected_window
);
11573 int must_finish
= 0;
11574 struct text_pos tlbufpos
, tlendpos
;
11575 int number_of_visible_frames
;
11578 int polling_stopped_here
= 0;
11579 Lisp_Object old_frame
= selected_frame
;
11581 /* Non-zero means redisplay has to consider all windows on all
11582 frames. Zero means, only selected_window is considered. */
11583 int consider_all_windows_p
;
11585 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11587 /* No redisplay if running in batch mode or frame is not yet fully
11588 initialized, or redisplay is explicitly turned off by setting
11589 Vinhibit_redisplay. */
11590 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11591 || !NILP (Vinhibit_redisplay
))
11594 /* Don't examine these until after testing Vinhibit_redisplay.
11595 When Emacs is shutting down, perhaps because its connection to
11596 X has dropped, we should not look at them at all. */
11597 f
= XFRAME (w
->frame
);
11598 sf
= SELECTED_FRAME ();
11600 if (!f
->glyphs_initialized_p
)
11603 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11604 if (popup_activated ())
11608 /* I don't think this happens but let's be paranoid. */
11609 if (redisplaying_p
)
11612 /* Record a function that resets redisplaying_p to its old value
11613 when we leave this function. */
11614 count
= SPECPDL_INDEX ();
11615 record_unwind_protect (unwind_redisplay
,
11616 Fcons (make_number (redisplaying_p
), selected_frame
));
11618 specbind (Qinhibit_free_realized_faces
, Qnil
);
11621 Lisp_Object tail
, frame
;
11623 FOR_EACH_FRAME (tail
, frame
)
11625 struct frame
*f
= XFRAME (frame
);
11626 f
->already_hscrolled_p
= 0;
11631 if (!EQ (old_frame
, selected_frame
)
11632 && FRAME_LIVE_P (XFRAME (old_frame
)))
11633 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11634 selected_frame and selected_window to be temporarily out-of-sync so
11635 when we come back here via `goto retry', we need to resync because we
11636 may need to run Elisp code (via prepare_menu_bars). */
11637 select_frame_for_redisplay (old_frame
);
11640 reconsider_clip_changes (w
, current_buffer
);
11641 last_escape_glyph_frame
= NULL
;
11642 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11644 /* If new fonts have been loaded that make a glyph matrix adjustment
11645 necessary, do it. */
11646 if (fonts_changed_p
)
11648 adjust_glyphs (NULL
);
11649 ++windows_or_buffers_changed
;
11650 fonts_changed_p
= 0;
11653 /* If face_change_count is non-zero, init_iterator will free all
11654 realized faces, which includes the faces referenced from current
11655 matrices. So, we can't reuse current matrices in this case. */
11656 if (face_change_count
)
11657 ++windows_or_buffers_changed
;
11659 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11660 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11662 /* Since frames on a single ASCII terminal share the same
11663 display area, displaying a different frame means redisplay
11664 the whole thing. */
11665 windows_or_buffers_changed
++;
11666 SET_FRAME_GARBAGED (sf
);
11668 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11670 FRAME_TTY (sf
)->previous_frame
= sf
;
11673 /* Set the visible flags for all frames. Do this before checking
11674 for resized or garbaged frames; they want to know if their frames
11675 are visible. See the comment in frame.h for
11676 FRAME_SAMPLE_VISIBILITY. */
11678 Lisp_Object tail
, frame
;
11680 number_of_visible_frames
= 0;
11682 FOR_EACH_FRAME (tail
, frame
)
11684 struct frame
*f
= XFRAME (frame
);
11686 FRAME_SAMPLE_VISIBILITY (f
);
11687 if (FRAME_VISIBLE_P (f
))
11688 ++number_of_visible_frames
;
11689 clear_desired_matrices (f
);
11693 /* Notice any pending interrupt request to change frame size. */
11694 do_pending_window_change (1);
11696 /* Clear frames marked as garbaged. */
11697 if (frame_garbaged
)
11698 clear_garbaged_frames ();
11700 /* Build menubar and tool-bar items. */
11701 if (NILP (Vmemory_full
))
11702 prepare_menu_bars ();
11704 if (windows_or_buffers_changed
)
11705 update_mode_lines
++;
11707 /* Detect case that we need to write or remove a star in the mode line. */
11708 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11710 w
->update_mode_line
= Qt
;
11711 if (buffer_shared
> 1)
11712 update_mode_lines
++;
11715 /* Avoid invocation of point motion hooks by `current_column' below. */
11716 count1
= SPECPDL_INDEX ();
11717 specbind (Qinhibit_point_motion_hooks
, Qt
);
11719 /* If %c is in the mode line, update it if needed. */
11720 if (!NILP (w
->column_number_displayed
)
11721 /* This alternative quickly identifies a common case
11722 where no change is needed. */
11723 && !(PT
== XFASTINT (w
->last_point
)
11724 && XFASTINT (w
->last_modified
) >= MODIFF
11725 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11726 && (XFASTINT (w
->column_number_displayed
)
11727 != (int) current_column ())) /* iftc */
11728 w
->update_mode_line
= Qt
;
11730 unbind_to (count1
, Qnil
);
11732 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11734 /* The variable buffer_shared is set in redisplay_window and
11735 indicates that we redisplay a buffer in different windows. See
11737 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11738 || cursor_type_changed
);
11740 /* If specs for an arrow have changed, do thorough redisplay
11741 to ensure we remove any arrow that should no longer exist. */
11742 if (overlay_arrows_changed_p ())
11743 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11745 /* Normally the message* functions will have already displayed and
11746 updated the echo area, but the frame may have been trashed, or
11747 the update may have been preempted, so display the echo area
11748 again here. Checking message_cleared_p captures the case that
11749 the echo area should be cleared. */
11750 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11751 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11752 || (message_cleared_p
11753 && minibuf_level
== 0
11754 /* If the mini-window is currently selected, this means the
11755 echo-area doesn't show through. */
11756 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11758 int window_height_changed_p
= echo_area_display (0);
11761 /* If we don't display the current message, don't clear the
11762 message_cleared_p flag, because, if we did, we wouldn't clear
11763 the echo area in the next redisplay which doesn't preserve
11765 if (!display_last_displayed_message_p
)
11766 message_cleared_p
= 0;
11768 if (fonts_changed_p
)
11770 else if (window_height_changed_p
)
11772 consider_all_windows_p
= 1;
11773 ++update_mode_lines
;
11774 ++windows_or_buffers_changed
;
11776 /* If window configuration was changed, frames may have been
11777 marked garbaged. Clear them or we will experience
11778 surprises wrt scrolling. */
11779 if (frame_garbaged
)
11780 clear_garbaged_frames ();
11783 else if (EQ (selected_window
, minibuf_window
)
11784 && (current_buffer
->clip_changed
11785 || XFASTINT (w
->last_modified
) < MODIFF
11786 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11787 && resize_mini_window (w
, 0))
11789 /* Resized active mini-window to fit the size of what it is
11790 showing if its contents might have changed. */
11792 /* FIXME: this causes all frames to be updated, which seems unnecessary
11793 since only the current frame needs to be considered. This function needs
11794 to be rewritten with two variables, consider_all_windows and
11795 consider_all_frames. */
11796 consider_all_windows_p
= 1;
11797 ++windows_or_buffers_changed
;
11798 ++update_mode_lines
;
11800 /* If window configuration was changed, frames may have been
11801 marked garbaged. Clear them or we will experience
11802 surprises wrt scrolling. */
11803 if (frame_garbaged
)
11804 clear_garbaged_frames ();
11808 /* If showing the region, and mark has changed, we must redisplay
11809 the whole window. The assignment to this_line_start_pos prevents
11810 the optimization directly below this if-statement. */
11811 if (((!NILP (Vtransient_mark_mode
)
11812 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11813 != !NILP (w
->region_showing
))
11814 || (!NILP (w
->region_showing
)
11815 && !EQ (w
->region_showing
,
11816 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11817 CHARPOS (this_line_start_pos
) = 0;
11819 /* Optimize the case that only the line containing the cursor in the
11820 selected window has changed. Variables starting with this_ are
11821 set in display_line and record information about the line
11822 containing the cursor. */
11823 tlbufpos
= this_line_start_pos
;
11824 tlendpos
= this_line_end_pos
;
11825 if (!consider_all_windows_p
11826 && CHARPOS (tlbufpos
) > 0
11827 && NILP (w
->update_mode_line
)
11828 && !current_buffer
->clip_changed
11829 && !current_buffer
->prevent_redisplay_optimizations_p
11830 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11831 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11832 /* Make sure recorded data applies to current buffer, etc. */
11833 && this_line_buffer
== current_buffer
11834 && current_buffer
== XBUFFER (w
->buffer
)
11835 && NILP (w
->force_start
)
11836 && NILP (w
->optional_new_start
)
11837 /* Point must be on the line that we have info recorded about. */
11838 && PT
>= CHARPOS (tlbufpos
)
11839 && PT
<= Z
- CHARPOS (tlendpos
)
11840 /* All text outside that line, including its final newline,
11841 must be unchanged. */
11842 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11843 CHARPOS (tlendpos
)))
11845 if (CHARPOS (tlbufpos
) > BEGV
11846 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11847 && (CHARPOS (tlbufpos
) == ZV
11848 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11849 /* Former continuation line has disappeared by becoming empty. */
11851 else if (XFASTINT (w
->last_modified
) < MODIFF
11852 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11853 || MINI_WINDOW_P (w
))
11855 /* We have to handle the case of continuation around a
11856 wide-column character (see the comment in indent.c around
11859 For instance, in the following case:
11861 -------- Insert --------
11862 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11863 J_I_ ==> J_I_ `^^' are cursors.
11867 As we have to redraw the line above, we cannot use this
11871 int line_height_before
= this_line_pixel_height
;
11873 /* Note that start_display will handle the case that the
11874 line starting at tlbufpos is a continuation line. */
11875 start_display (&it
, w
, tlbufpos
);
11877 /* Implementation note: It this still necessary? */
11878 if (it
.current_x
!= this_line_start_x
)
11881 TRACE ((stderr
, "trying display optimization 1\n"));
11882 w
->cursor
.vpos
= -1;
11883 overlay_arrow_seen
= 0;
11884 it
.vpos
= this_line_vpos
;
11885 it
.current_y
= this_line_y
;
11886 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11887 display_line (&it
);
11889 /* If line contains point, is not continued,
11890 and ends at same distance from eob as before, we win. */
11891 if (w
->cursor
.vpos
>= 0
11892 /* Line is not continued, otherwise this_line_start_pos
11893 would have been set to 0 in display_line. */
11894 && CHARPOS (this_line_start_pos
)
11895 /* Line ends as before. */
11896 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11897 /* Line has same height as before. Otherwise other lines
11898 would have to be shifted up or down. */
11899 && this_line_pixel_height
== line_height_before
)
11901 /* If this is not the window's last line, we must adjust
11902 the charstarts of the lines below. */
11903 if (it
.current_y
< it
.last_visible_y
)
11905 struct glyph_row
*row
11906 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11907 int delta
, delta_bytes
;
11909 /* We used to distinguish between two cases here,
11910 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11911 when the line ends in a newline or the end of the
11912 buffer's accessible portion. But both cases did
11913 the same, so they were collapsed. */
11915 - CHARPOS (tlendpos
)
11916 - MATRIX_ROW_START_CHARPOS (row
));
11917 delta_bytes
= (Z_BYTE
11918 - BYTEPOS (tlendpos
)
11919 - MATRIX_ROW_START_BYTEPOS (row
));
11921 increment_matrix_positions (w
->current_matrix
,
11922 this_line_vpos
+ 1,
11923 w
->current_matrix
->nrows
,
11924 delta
, delta_bytes
);
11927 /* If this row displays text now but previously didn't,
11928 or vice versa, w->window_end_vpos may have to be
11930 if ((it
.glyph_row
- 1)->displays_text_p
)
11932 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11933 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11935 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11936 && this_line_vpos
> 0)
11937 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11938 w
->window_end_valid
= Qnil
;
11940 /* Update hint: No need to try to scroll in update_window. */
11941 w
->desired_matrix
->no_scrolling_p
= 1;
11944 *w
->desired_matrix
->method
= 0;
11945 debug_method_add (w
, "optimization 1");
11947 #ifdef HAVE_WINDOW_SYSTEM
11948 update_window_fringes (w
, 0);
11955 else if (/* Cursor position hasn't changed. */
11956 PT
== XFASTINT (w
->last_point
)
11957 /* Make sure the cursor was last displayed
11958 in this window. Otherwise we have to reposition it. */
11959 && 0 <= w
->cursor
.vpos
11960 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11964 do_pending_window_change (1);
11966 /* We used to always goto end_of_redisplay here, but this
11967 isn't enough if we have a blinking cursor. */
11968 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11969 goto end_of_redisplay
;
11973 /* If highlighting the region, or if the cursor is in the echo area,
11974 then we can't just move the cursor. */
11975 else if (! (!NILP (Vtransient_mark_mode
)
11976 && !NILP (current_buffer
->mark_active
))
11977 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11978 || highlight_nonselected_windows
)
11979 && NILP (w
->region_showing
)
11980 && NILP (Vshow_trailing_whitespace
)
11981 && !cursor_in_echo_area
)
11984 struct glyph_row
*row
;
11986 /* Skip from tlbufpos to PT and see where it is. Note that
11987 PT may be in invisible text. If so, we will end at the
11988 next visible position. */
11989 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11990 NULL
, DEFAULT_FACE_ID
);
11991 it
.current_x
= this_line_start_x
;
11992 it
.current_y
= this_line_y
;
11993 it
.vpos
= this_line_vpos
;
11995 /* The call to move_it_to stops in front of PT, but
11996 moves over before-strings. */
11997 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11999 if (it
.vpos
== this_line_vpos
12000 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12003 xassert (this_line_vpos
== it
.vpos
);
12004 xassert (this_line_y
== it
.current_y
);
12005 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12007 *w
->desired_matrix
->method
= 0;
12008 debug_method_add (w
, "optimization 3");
12017 /* Text changed drastically or point moved off of line. */
12018 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12021 CHARPOS (this_line_start_pos
) = 0;
12022 consider_all_windows_p
|= buffer_shared
> 1;
12023 ++clear_face_cache_count
;
12024 #ifdef HAVE_WINDOW_SYSTEM
12025 ++clear_image_cache_count
;
12028 /* Build desired matrices, and update the display. If
12029 consider_all_windows_p is non-zero, do it for all windows on all
12030 frames. Otherwise do it for selected_window, only. */
12032 if (consider_all_windows_p
)
12034 Lisp_Object tail
, frame
;
12036 FOR_EACH_FRAME (tail
, frame
)
12037 XFRAME (frame
)->updated_p
= 0;
12039 /* Recompute # windows showing selected buffer. This will be
12040 incremented each time such a window is displayed. */
12043 FOR_EACH_FRAME (tail
, frame
)
12045 struct frame
*f
= XFRAME (frame
);
12047 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12049 if (! EQ (frame
, selected_frame
))
12050 /* Select the frame, for the sake of frame-local
12052 select_frame_for_redisplay (frame
);
12054 /* Mark all the scroll bars to be removed; we'll redeem
12055 the ones we want when we redisplay their windows. */
12056 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12057 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12059 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12060 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12062 /* The X error handler may have deleted that frame. */
12063 if (!FRAME_LIVE_P (f
))
12066 /* Any scroll bars which redisplay_windows should have
12067 nuked should now go away. */
12068 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12069 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12071 /* If fonts changed, display again. */
12072 /* ??? rms: I suspect it is a mistake to jump all the way
12073 back to retry here. It should just retry this frame. */
12074 if (fonts_changed_p
)
12077 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12079 /* See if we have to hscroll. */
12080 if (!f
->already_hscrolled_p
)
12082 f
->already_hscrolled_p
= 1;
12083 if (hscroll_windows (f
->root_window
))
12087 /* Prevent various kinds of signals during display
12088 update. stdio is not robust about handling
12089 signals, which can cause an apparent I/O
12091 if (interrupt_input
)
12092 unrequest_sigio ();
12095 /* Update the display. */
12096 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12097 pause
|= update_frame (f
, 0, 0);
12103 if (!EQ (old_frame
, selected_frame
)
12104 && FRAME_LIVE_P (XFRAME (old_frame
)))
12105 /* We played a bit fast-and-loose above and allowed selected_frame
12106 and selected_window to be temporarily out-of-sync but let's make
12107 sure this stays contained. */
12108 select_frame_for_redisplay (old_frame
);
12109 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12113 /* Do the mark_window_display_accurate after all windows have
12114 been redisplayed because this call resets flags in buffers
12115 which are needed for proper redisplay. */
12116 FOR_EACH_FRAME (tail
, frame
)
12118 struct frame
*f
= XFRAME (frame
);
12121 mark_window_display_accurate (f
->root_window
, 1);
12122 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12123 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12128 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12130 Lisp_Object mini_window
;
12131 struct frame
*mini_frame
;
12133 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12134 /* Use list_of_error, not Qerror, so that
12135 we catch only errors and don't run the debugger. */
12136 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12138 redisplay_window_error
);
12140 /* Compare desired and current matrices, perform output. */
12143 /* If fonts changed, display again. */
12144 if (fonts_changed_p
)
12147 /* Prevent various kinds of signals during display update.
12148 stdio is not robust about handling signals,
12149 which can cause an apparent I/O error. */
12150 if (interrupt_input
)
12151 unrequest_sigio ();
12154 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12156 if (hscroll_windows (selected_window
))
12159 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12160 pause
= update_frame (sf
, 0, 0);
12163 /* We may have called echo_area_display at the top of this
12164 function. If the echo area is on another frame, that may
12165 have put text on a frame other than the selected one, so the
12166 above call to update_frame would not have caught it. Catch
12168 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12169 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12171 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12173 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12174 pause
|= update_frame (mini_frame
, 0, 0);
12175 if (!pause
&& hscroll_windows (mini_window
))
12180 /* If display was paused because of pending input, make sure we do a
12181 thorough update the next time. */
12184 /* Prevent the optimization at the beginning of
12185 redisplay_internal that tries a single-line update of the
12186 line containing the cursor in the selected window. */
12187 CHARPOS (this_line_start_pos
) = 0;
12189 /* Let the overlay arrow be updated the next time. */
12190 update_overlay_arrows (0);
12192 /* If we pause after scrolling, some rows in the current
12193 matrices of some windows are not valid. */
12194 if (!WINDOW_FULL_WIDTH_P (w
)
12195 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12196 update_mode_lines
= 1;
12200 if (!consider_all_windows_p
)
12202 /* This has already been done above if
12203 consider_all_windows_p is set. */
12204 mark_window_display_accurate_1 (w
, 1);
12206 /* Say overlay arrows are up to date. */
12207 update_overlay_arrows (1);
12209 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12210 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12213 update_mode_lines
= 0;
12214 windows_or_buffers_changed
= 0;
12215 cursor_type_changed
= 0;
12218 /* Start SIGIO interrupts coming again. Having them off during the
12219 code above makes it less likely one will discard output, but not
12220 impossible, since there might be stuff in the system buffer here.
12221 But it is much hairier to try to do anything about that. */
12222 if (interrupt_input
)
12226 /* If a frame has become visible which was not before, redisplay
12227 again, so that we display it. Expose events for such a frame
12228 (which it gets when becoming visible) don't call the parts of
12229 redisplay constructing glyphs, so simply exposing a frame won't
12230 display anything in this case. So, we have to display these
12231 frames here explicitly. */
12234 Lisp_Object tail
, frame
;
12237 FOR_EACH_FRAME (tail
, frame
)
12239 int this_is_visible
= 0;
12241 if (XFRAME (frame
)->visible
)
12242 this_is_visible
= 1;
12243 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12244 if (XFRAME (frame
)->visible
)
12245 this_is_visible
= 1;
12247 if (this_is_visible
)
12251 if (new_count
!= number_of_visible_frames
)
12252 windows_or_buffers_changed
++;
12255 /* Change frame size now if a change is pending. */
12256 do_pending_window_change (1);
12258 /* If we just did a pending size change, or have additional
12259 visible frames, redisplay again. */
12260 if (windows_or_buffers_changed
&& !pause
)
12263 /* Clear the face cache eventually. */
12264 if (consider_all_windows_p
)
12266 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12268 clear_face_cache (0);
12269 clear_face_cache_count
= 0;
12271 #ifdef HAVE_WINDOW_SYSTEM
12272 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12274 clear_image_caches (Qnil
);
12275 clear_image_cache_count
= 0;
12277 #endif /* HAVE_WINDOW_SYSTEM */
12281 unbind_to (count
, Qnil
);
12286 /* Redisplay, but leave alone any recent echo area message unless
12287 another message has been requested in its place.
12289 This is useful in situations where you need to redisplay but no
12290 user action has occurred, making it inappropriate for the message
12291 area to be cleared. See tracking_off and
12292 wait_reading_process_output for examples of these situations.
12294 FROM_WHERE is an integer saying from where this function was
12295 called. This is useful for debugging. */
12298 redisplay_preserve_echo_area (from_where
)
12301 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12303 if (!NILP (echo_area_buffer
[1]))
12305 /* We have a previously displayed message, but no current
12306 message. Redisplay the previous message. */
12307 display_last_displayed_message_p
= 1;
12308 redisplay_internal (1);
12309 display_last_displayed_message_p
= 0;
12312 redisplay_internal (1);
12314 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12315 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12316 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12320 /* Function registered with record_unwind_protect in
12321 redisplay_internal. Reset redisplaying_p to the value it had
12322 before redisplay_internal was called, and clear
12323 prevent_freeing_realized_faces_p. It also selects the previously
12324 selected frame, unless it has been deleted (by an X connection
12325 failure during redisplay, for example). */
12328 unwind_redisplay (val
)
12331 Lisp_Object old_redisplaying_p
, old_frame
;
12333 old_redisplaying_p
= XCAR (val
);
12334 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12335 old_frame
= XCDR (val
);
12336 if (! EQ (old_frame
, selected_frame
)
12337 && FRAME_LIVE_P (XFRAME (old_frame
)))
12338 select_frame_for_redisplay (old_frame
);
12343 /* Mark the display of window W as accurate or inaccurate. If
12344 ACCURATE_P is non-zero mark display of W as accurate. If
12345 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12346 redisplay_internal is called. */
12349 mark_window_display_accurate_1 (w
, accurate_p
)
12353 if (BUFFERP (w
->buffer
))
12355 struct buffer
*b
= XBUFFER (w
->buffer
);
12358 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12359 w
->last_overlay_modified
12360 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12362 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12366 b
->clip_changed
= 0;
12367 b
->prevent_redisplay_optimizations_p
= 0;
12369 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12370 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12371 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12372 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12374 w
->current_matrix
->buffer
= b
;
12375 w
->current_matrix
->begv
= BUF_BEGV (b
);
12376 w
->current_matrix
->zv
= BUF_ZV (b
);
12378 w
->last_cursor
= w
->cursor
;
12379 w
->last_cursor_off_p
= w
->cursor_off_p
;
12381 if (w
== XWINDOW (selected_window
))
12382 w
->last_point
= make_number (BUF_PT (b
));
12384 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12390 w
->window_end_valid
= w
->buffer
;
12391 w
->update_mode_line
= Qnil
;
12396 /* Mark the display of windows in the window tree rooted at WINDOW as
12397 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12398 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12399 be redisplayed the next time redisplay_internal is called. */
12402 mark_window_display_accurate (window
, accurate_p
)
12403 Lisp_Object window
;
12408 for (; !NILP (window
); window
= w
->next
)
12410 w
= XWINDOW (window
);
12411 mark_window_display_accurate_1 (w
, accurate_p
);
12413 if (!NILP (w
->vchild
))
12414 mark_window_display_accurate (w
->vchild
, accurate_p
);
12415 if (!NILP (w
->hchild
))
12416 mark_window_display_accurate (w
->hchild
, accurate_p
);
12421 update_overlay_arrows (1);
12425 /* Force a thorough redisplay the next time by setting
12426 last_arrow_position and last_arrow_string to t, which is
12427 unequal to any useful value of Voverlay_arrow_... */
12428 update_overlay_arrows (-1);
12433 /* Return value in display table DP (Lisp_Char_Table *) for character
12434 C. Since a display table doesn't have any parent, we don't have to
12435 follow parent. Do not call this function directly but use the
12436 macro DISP_CHAR_VECTOR. */
12439 disp_char_vector (dp
, c
)
12440 struct Lisp_Char_Table
*dp
;
12445 if (ASCII_CHAR_P (c
))
12448 if (SUB_CHAR_TABLE_P (val
))
12449 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12455 XSETCHAR_TABLE (table
, dp
);
12456 val
= char_table_ref (table
, c
);
12465 /***********************************************************************
12467 ***********************************************************************/
12469 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12472 redisplay_windows (window
)
12473 Lisp_Object window
;
12475 while (!NILP (window
))
12477 struct window
*w
= XWINDOW (window
);
12479 if (!NILP (w
->hchild
))
12480 redisplay_windows (w
->hchild
);
12481 else if (!NILP (w
->vchild
))
12482 redisplay_windows (w
->vchild
);
12483 else if (!NILP (w
->buffer
))
12485 displayed_buffer
= XBUFFER (w
->buffer
);
12486 /* Use list_of_error, not Qerror, so that
12487 we catch only errors and don't run the debugger. */
12488 internal_condition_case_1 (redisplay_window_0
, window
,
12490 redisplay_window_error
);
12498 redisplay_window_error ()
12500 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12505 redisplay_window_0 (window
)
12506 Lisp_Object window
;
12508 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12509 redisplay_window (window
, 0);
12514 redisplay_window_1 (window
)
12515 Lisp_Object window
;
12517 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12518 redisplay_window (window
, 1);
12523 /* Increment GLYPH until it reaches END or CONDITION fails while
12524 adding (GLYPH)->pixel_width to X. */
12526 #define SKIP_GLYPHS(glyph, end, x, condition) \
12529 (x) += (glyph)->pixel_width; \
12532 while ((glyph) < (end) && (condition))
12535 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12536 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12537 which positions recorded in ROW differ from current buffer
12540 Return 0 if cursor is not on this row, 1 otherwise. */
12543 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12545 struct glyph_row
*row
;
12546 struct glyph_matrix
*matrix
;
12547 int delta
, delta_bytes
, dy
, dvpos
;
12549 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12550 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12551 struct glyph
*cursor
= NULL
;
12552 /* The last known character position in row. */
12553 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12555 EMACS_INT pt_old
= PT
- delta
;
12556 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12557 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12558 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12559 /* A glyph beyond the edge of TEXT_AREA which we should never
12561 struct glyph
*glyphs_end
= end
;
12562 /* Non-zero means we've found a match for cursor position, but that
12563 glyph has the avoid_cursor_p flag set. */
12564 int match_with_avoid_cursor
= 0;
12565 /* Non-zero means we've seen at least one glyph that came from a
12567 int string_seen
= 0;
12568 /* Largest buffer position seen so far during scan of glyph row. */
12569 EMACS_INT bpos_max
= last_pos
;
12570 /* Last buffer position covered by an overlay string with an integer
12571 `cursor' property. */
12572 EMACS_INT bpos_covered
= 0;
12574 /* Skip over glyphs not having an object at the start and the end of
12575 the row. These are special glyphs like truncation marks on
12576 terminal frames. */
12577 if (row
->displays_text_p
)
12579 if (!row
->reversed_p
)
12582 && INTEGERP (glyph
->object
)
12583 && glyph
->charpos
< 0)
12585 x
+= glyph
->pixel_width
;
12589 && INTEGERP ((end
- 1)->object
)
12590 /* CHARPOS is zero for blanks inserted by
12591 extend_face_to_end_of_line. */
12592 && (end
- 1)->charpos
<= 0)
12594 glyph_before
= glyph
- 1;
12601 /* If the glyph row is reversed, we need to process it from back
12602 to front, so swap the edge pointers. */
12603 glyphs_end
= end
= glyph
- 1;
12604 glyph
+= row
->used
[TEXT_AREA
] - 1;
12606 while (glyph
> end
+ 1
12607 && INTEGERP (glyph
->object
)
12608 && glyph
->charpos
< 0)
12611 x
-= glyph
->pixel_width
;
12613 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12615 /* By default, in reversed rows we put the cursor on the
12616 rightmost (first in the reading order) glyph. */
12617 for (g
= end
+ 1; g
< glyph
; g
++)
12618 x
+= g
->pixel_width
;
12620 && INTEGERP ((end
+ 1)->object
)
12621 && (end
+ 1)->charpos
<= 0)
12623 glyph_before
= glyph
+ 1;
12627 else if (row
->reversed_p
)
12629 /* In R2L rows that don't display text, put the cursor on the
12630 rightmost glyph. Case in point: an empty last line that is
12631 part of an R2L paragraph. */
12633 x
= -1; /* will be computed below, at label compute_x */
12636 /* Step 1: Try to find the glyph whose character position
12637 corresponds to point. If that's not possible, find 2 glyphs
12638 whose character positions are the closest to point, one before
12639 point, the other after it. */
12640 if (!row
->reversed_p
)
12641 while (/* not marched to end of glyph row */
12643 /* glyph was not inserted by redisplay for internal purposes */
12644 && !INTEGERP (glyph
->object
))
12646 if (BUFFERP (glyph
->object
))
12648 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12650 if (glyph
->charpos
> bpos_max
)
12651 bpos_max
= glyph
->charpos
;
12652 if (!glyph
->avoid_cursor_p
)
12654 /* If we hit point, we've found the glyph on which to
12655 display the cursor. */
12658 match_with_avoid_cursor
= 0;
12661 /* See if we've found a better approximation to
12662 POS_BEFORE or to POS_AFTER. Note that we want the
12663 first (leftmost) glyph of all those that are the
12664 closest from below, and the last (rightmost) of all
12665 those from above. */
12666 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12668 pos_before
= glyph
->charpos
;
12669 glyph_before
= glyph
;
12671 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12673 pos_after
= glyph
->charpos
;
12674 glyph_after
= glyph
;
12677 else if (dpos
== 0)
12678 match_with_avoid_cursor
= 1;
12680 else if (STRINGP (glyph
->object
))
12682 Lisp_Object chprop
;
12683 int glyph_pos
= glyph
->charpos
;
12685 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12687 if (INTEGERP (chprop
))
12689 bpos_covered
= bpos_max
+ XINT (chprop
);
12690 /* If the `cursor' property covers buffer positions up
12691 to and including point, we should display cursor on
12692 this glyph. Note that overlays and text properties
12693 with string values stop bidi reordering, so every
12694 buffer position to the left of the string is always
12695 smaller than any position to the right of the
12696 string. Therefore, if a `cursor' property on one
12697 of the string's characters has an integer value, we
12698 will break out of the loop below _before_ we get to
12699 the position match above. IOW, integer values of
12700 the `cursor' property override the "exact match for
12701 point" strategy of positioning the cursor. */
12702 /* Implementation note: bpos_max == pt_old when, e.g.,
12703 we are in an empty line, where bpos_max is set to
12704 MATRIX_ROW_START_CHARPOS, see above. */
12705 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12714 x
+= glyph
->pixel_width
;
12717 else if (glyph
> end
) /* row is reversed */
12718 while (!INTEGERP (glyph
->object
))
12720 if (BUFFERP (glyph
->object
))
12722 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12724 if (glyph
->charpos
> bpos_max
)
12725 bpos_max
= glyph
->charpos
;
12726 if (!glyph
->avoid_cursor_p
)
12730 match_with_avoid_cursor
= 0;
12733 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12735 pos_before
= glyph
->charpos
;
12736 glyph_before
= glyph
;
12738 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12740 pos_after
= glyph
->charpos
;
12741 glyph_after
= glyph
;
12744 else if (dpos
== 0)
12745 match_with_avoid_cursor
= 1;
12747 else if (STRINGP (glyph
->object
))
12749 Lisp_Object chprop
;
12750 int glyph_pos
= glyph
->charpos
;
12752 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12754 if (INTEGERP (chprop
))
12756 bpos_covered
= bpos_max
+ XINT (chprop
);
12757 /* If the `cursor' property covers buffer positions up
12758 to and including point, we should display cursor on
12760 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12769 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
12771 x
--; /* can't use any pixel_width */
12774 x
-= glyph
->pixel_width
;
12777 /* Step 2: If we didn't find an exact match for point, we need to
12778 look for a proper place to put the cursor among glyphs between
12779 GLYPH_BEFORE and GLYPH_AFTER. */
12780 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
12781 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12782 && bpos_covered
< pt_old
)
12784 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12786 EMACS_INT ellipsis_pos
;
12788 /* Scan back over the ellipsis glyphs. */
12789 if (!row
->reversed_p
)
12791 ellipsis_pos
= (glyph
- 1)->charpos
;
12792 while (glyph
> row
->glyphs
[TEXT_AREA
]
12793 && (glyph
- 1)->charpos
== ellipsis_pos
)
12794 glyph
--, x
-= glyph
->pixel_width
;
12795 /* That loop always goes one position too far, including
12796 the glyph before the ellipsis. So scan forward over
12798 x
+= glyph
->pixel_width
;
12801 else /* row is reversed */
12803 ellipsis_pos
= (glyph
+ 1)->charpos
;
12804 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12805 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12806 glyph
++, x
+= glyph
->pixel_width
;
12807 x
-= glyph
->pixel_width
;
12811 else if (match_with_avoid_cursor
12812 /* zero-width characters produce no glyphs */
12813 || eabs (glyph_after
- glyph_before
) == 1)
12815 cursor
= glyph_after
;
12818 else if (string_seen
)
12820 int incr
= row
->reversed_p
? -1 : +1;
12822 /* Need to find the glyph that came out of a string which is
12823 present at point. That glyph is somewhere between
12824 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12825 positioned between POS_BEFORE and POS_AFTER in the
12827 struct glyph
*stop
= glyph_after
;
12828 EMACS_INT pos
= pos_before
;
12831 for (glyph
= glyph_before
+ incr
;
12832 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12835 /* Any glyphs that come from the buffer are here because
12836 of bidi reordering. Skip them, and only pay
12837 attention to glyphs that came from some string. */
12838 if (STRINGP (glyph
->object
))
12843 str
= glyph
->object
;
12844 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12845 if (tem
== 0 /* from overlay */
12848 /* If the string from which this glyph came is
12849 found in the buffer at point, then we've
12850 found the glyph we've been looking for. If
12851 it comes from an overlay (tem == 0), and it
12852 has the `cursor' property on one of its
12853 glyphs, record that glyph as a candidate for
12854 displaying the cursor. (As in the
12855 unidirectional version, we will display the
12856 cursor on the last candidate we find.) */
12857 if (tem
== 0 || tem
== pt_old
)
12859 /* The glyphs from this string could have
12860 been reordered. Find the one with the
12861 smallest string position. Or there could
12862 be a character in the string with the
12863 `cursor' property, which means display
12864 cursor on that character's glyph. */
12865 int strpos
= glyph
->charpos
;
12868 for (glyph
+= incr
;
12869 EQ (glyph
->object
, str
);
12873 int gpos
= glyph
->charpos
;
12875 cprop
= Fget_char_property (make_number (gpos
),
12883 if (glyph
->charpos
< strpos
)
12885 strpos
= glyph
->charpos
;
12894 pos
= tem
+ 1; /* don't find previous instances */
12896 /* This string is not what we want; skip all of the
12897 glyphs that came from it. */
12900 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12901 && EQ (glyph
->object
, str
));
12907 /* If we reached the end of the line, and END was from a string,
12908 the cursor is not on this line. */
12910 && STRINGP ((glyph
- incr
)->object
)
12911 && row
->continued_p
)
12917 if (cursor
!= NULL
)
12923 /* Need to compute x that corresponds to GLYPH. */
12924 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12926 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12928 x
+= g
->pixel_width
;
12932 /* ROW could be part of a continued line, which might have other
12933 rows whose start and end charpos occlude point. Only set
12934 w->cursor if we found a better approximation to the cursor
12935 position than we have from previously examined rows. */
12936 if (w
->cursor
.vpos
>= 0
12937 /* Make sure cursor.vpos specifies a row whose start and end
12938 charpos occlude point. This is because some callers of this
12939 function leave cursor.vpos at the row where the cursor was
12940 displayed during the last redisplay cycle. */
12941 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
12942 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
12945 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
12947 /* Don't consider glyphs that are outside TEXT_AREA. */
12948 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
12950 /* Keep the candidate whose buffer position is the closest to
12952 if (/* previous candidate is a glyph in TEXT_AREA of that row */
12953 w
->cursor
.hpos
>= 0
12954 && w
->cursor
.hpos
< MATRIX_ROW_USED(matrix
, w
->cursor
.vpos
)
12955 && BUFFERP (g1
->object
)
12956 && (g1
->charpos
== pt_old
/* an exact match always wins */
12957 || (BUFFERP (glyph
->object
)
12958 && eabs (g1
->charpos
- pt_old
)
12959 < eabs (glyph
->charpos
- pt_old
))))
12961 /* If this candidate gives an exact match, use that. */
12962 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12963 /* Otherwise, keep the candidate that comes from a row
12964 spanning less buffer positions. This may win when one or
12965 both candidate positions are on glyphs that came from
12966 display strings, for which we cannot compare buffer
12968 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12969 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12970 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
12973 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12975 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12976 w
->cursor
.y
= row
->y
+ dy
;
12978 if (w
== XWINDOW (selected_window
))
12980 if (!row
->continued_p
12981 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12984 this_line_buffer
= XBUFFER (w
->buffer
);
12986 CHARPOS (this_line_start_pos
)
12987 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12988 BYTEPOS (this_line_start_pos
)
12989 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12991 CHARPOS (this_line_end_pos
)
12992 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12993 BYTEPOS (this_line_end_pos
)
12994 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12996 this_line_y
= w
->cursor
.y
;
12997 this_line_pixel_height
= row
->height
;
12998 this_line_vpos
= w
->cursor
.vpos
;
12999 this_line_start_x
= row
->x
;
13002 CHARPOS (this_line_start_pos
) = 0;
13009 /* Run window scroll functions, if any, for WINDOW with new window
13010 start STARTP. Sets the window start of WINDOW to that position.
13012 We assume that the window's buffer is really current. */
13014 static INLINE
struct text_pos
13015 run_window_scroll_functions (window
, startp
)
13016 Lisp_Object window
;
13017 struct text_pos startp
;
13019 struct window
*w
= XWINDOW (window
);
13020 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13022 if (current_buffer
!= XBUFFER (w
->buffer
))
13025 if (!NILP (Vwindow_scroll_functions
))
13027 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13028 make_number (CHARPOS (startp
)));
13029 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13030 /* In case the hook functions switch buffers. */
13031 if (current_buffer
!= XBUFFER (w
->buffer
))
13032 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13039 /* Make sure the line containing the cursor is fully visible.
13040 A value of 1 means there is nothing to be done.
13041 (Either the line is fully visible, or it cannot be made so,
13042 or we cannot tell.)
13044 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13045 is higher than window.
13047 A value of 0 means the caller should do scrolling
13048 as if point had gone off the screen. */
13051 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
13054 int current_matrix_p
;
13056 struct glyph_matrix
*matrix
;
13057 struct glyph_row
*row
;
13060 if (!make_cursor_line_fully_visible_p
)
13063 /* It's not always possible to find the cursor, e.g, when a window
13064 is full of overlay strings. Don't do anything in that case. */
13065 if (w
->cursor
.vpos
< 0)
13068 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13069 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13071 /* If the cursor row is not partially visible, there's nothing to do. */
13072 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13075 /* If the row the cursor is in is taller than the window's height,
13076 it's not clear what to do, so do nothing. */
13077 window_height
= window_box_height (w
);
13078 if (row
->height
>= window_height
)
13080 if (!force_p
|| MINI_WINDOW_P (w
)
13081 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13088 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13089 non-zero means only WINDOW is redisplayed in redisplay_internal.
13090 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13091 in redisplay_window to bring a partially visible line into view in
13092 the case that only the cursor has moved.
13094 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13095 last screen line's vertical height extends past the end of the screen.
13099 1 if scrolling succeeded
13101 0 if scrolling didn't find point.
13103 -1 if new fonts have been loaded so that we must interrupt
13104 redisplay, adjust glyph matrices, and try again. */
13110 SCROLLING_NEED_LARGER_MATRICES
13114 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
13115 scroll_step
, temp_scroll_step
, last_line_misfit
)
13116 Lisp_Object window
;
13117 int just_this_one_p
;
13118 EMACS_INT scroll_conservatively
, scroll_step
;
13119 int temp_scroll_step
;
13120 int last_line_misfit
;
13122 struct window
*w
= XWINDOW (window
);
13123 struct frame
*f
= XFRAME (w
->frame
);
13124 struct text_pos pos
, startp
;
13126 int this_scroll_margin
, scroll_max
, rc
, height
;
13127 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13128 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13129 Lisp_Object aggressive
;
13130 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13133 debug_method_add (w
, "try_scrolling");
13136 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13138 /* Compute scroll margin height in pixels. We scroll when point is
13139 within this distance from the top or bottom of the window. */
13140 if (scroll_margin
> 0)
13141 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13142 * FRAME_LINE_HEIGHT (f
);
13144 this_scroll_margin
= 0;
13146 /* Force scroll_conservatively to have a reasonable value, to avoid
13147 overflow while computing how much to scroll. Note that the user
13148 can supply scroll-conservatively equal to `most-positive-fixnum',
13149 which can be larger than INT_MAX. */
13150 if (scroll_conservatively
> scroll_limit
)
13152 scroll_conservatively
= scroll_limit
;
13153 scroll_max
= INT_MAX
;
13155 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13156 /* Compute how much we should try to scroll maximally to bring
13157 point into view. */
13158 scroll_max
= (max (scroll_step
,
13159 max (scroll_conservatively
, temp_scroll_step
))
13160 * FRAME_LINE_HEIGHT (f
));
13161 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13162 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13163 /* We're trying to scroll because of aggressive scrolling but no
13164 scroll_step is set. Choose an arbitrary one. */
13165 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13171 /* Decide whether to scroll down. */
13172 if (PT
> CHARPOS (startp
))
13174 int scroll_margin_y
;
13176 /* Compute the pixel ypos of the scroll margin, then move it to
13177 either that ypos or PT, whichever comes first. */
13178 start_display (&it
, w
, startp
);
13179 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13180 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13181 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13182 (MOVE_TO_POS
| MOVE_TO_Y
));
13184 if (PT
> CHARPOS (it
.current
.pos
))
13186 int y0
= line_bottom_y (&it
);
13188 /* Compute the distance from the scroll margin to PT
13189 (including the height of the cursor line). Moving the
13190 iterator unconditionally to PT can be slow if PT is far
13191 away, so stop 10 lines past the window bottom (is there a
13192 way to do the right thing quickly?). */
13193 move_it_to (&it
, PT
, -1,
13194 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
13195 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13196 dy
= line_bottom_y (&it
) - y0
;
13198 if (dy
> scroll_max
)
13199 return SCROLLING_FAILED
;
13207 /* Point is in or below the bottom scroll margin, so move the
13208 window start down. If scrolling conservatively, move it just
13209 enough down to make point visible. If scroll_step is set,
13210 move it down by scroll_step. */
13211 if (scroll_conservatively
)
13213 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13214 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13215 else if (scroll_step
|| temp_scroll_step
)
13216 amount_to_scroll
= scroll_max
;
13219 aggressive
= current_buffer
->scroll_up_aggressively
;
13220 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13221 if (NUMBERP (aggressive
))
13223 double float_amount
= XFLOATINT (aggressive
) * height
;
13224 amount_to_scroll
= float_amount
;
13225 if (amount_to_scroll
== 0 && float_amount
> 0)
13226 amount_to_scroll
= 1;
13230 if (amount_to_scroll
<= 0)
13231 return SCROLLING_FAILED
;
13233 start_display (&it
, w
, startp
);
13234 move_it_vertically (&it
, amount_to_scroll
);
13236 /* If STARTP is unchanged, move it down another screen line. */
13237 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13238 move_it_by_lines (&it
, 1, 1);
13239 startp
= it
.current
.pos
;
13243 struct text_pos scroll_margin_pos
= startp
;
13245 /* See if point is inside the scroll margin at the top of the
13247 if (this_scroll_margin
)
13249 start_display (&it
, w
, startp
);
13250 move_it_vertically (&it
, this_scroll_margin
);
13251 scroll_margin_pos
= it
.current
.pos
;
13254 if (PT
< CHARPOS (scroll_margin_pos
))
13256 /* Point is in the scroll margin at the top of the window or
13257 above what is displayed in the window. */
13260 /* Compute the vertical distance from PT to the scroll
13261 margin position. Give up if distance is greater than
13263 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13264 start_display (&it
, w
, pos
);
13266 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13267 it
.last_visible_y
, -1,
13268 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13269 dy
= it
.current_y
- y0
;
13270 if (dy
> scroll_max
)
13271 return SCROLLING_FAILED
;
13273 /* Compute new window start. */
13274 start_display (&it
, w
, startp
);
13276 if (scroll_conservatively
)
13278 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13279 else if (scroll_step
|| temp_scroll_step
)
13280 amount_to_scroll
= scroll_max
;
13283 aggressive
= current_buffer
->scroll_down_aggressively
;
13284 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13285 if (NUMBERP (aggressive
))
13287 double float_amount
= XFLOATINT (aggressive
) * height
;
13288 amount_to_scroll
= float_amount
;
13289 if (amount_to_scroll
== 0 && float_amount
> 0)
13290 amount_to_scroll
= 1;
13294 if (amount_to_scroll
<= 0)
13295 return SCROLLING_FAILED
;
13297 move_it_vertically_backward (&it
, amount_to_scroll
);
13298 startp
= it
.current
.pos
;
13302 /* Run window scroll functions. */
13303 startp
= run_window_scroll_functions (window
, startp
);
13305 /* Display the window. Give up if new fonts are loaded, or if point
13307 if (!try_window (window
, startp
, 0))
13308 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13309 else if (w
->cursor
.vpos
< 0)
13311 clear_glyph_matrix (w
->desired_matrix
);
13312 rc
= SCROLLING_FAILED
;
13316 /* Maybe forget recorded base line for line number display. */
13317 if (!just_this_one_p
13318 || current_buffer
->clip_changed
13319 || BEG_UNCHANGED
< CHARPOS (startp
))
13320 w
->base_line_number
= Qnil
;
13322 /* If cursor ends up on a partially visible line,
13323 treat that as being off the bottom of the screen. */
13324 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13326 clear_glyph_matrix (w
->desired_matrix
);
13327 ++extra_scroll_margin_lines
;
13330 rc
= SCROLLING_SUCCESS
;
13337 /* Compute a suitable window start for window W if display of W starts
13338 on a continuation line. Value is non-zero if a new window start
13341 The new window start will be computed, based on W's width, starting
13342 from the start of the continued line. It is the start of the
13343 screen line with the minimum distance from the old start W->start. */
13346 compute_window_start_on_continuation_line (w
)
13349 struct text_pos pos
, start_pos
;
13350 int window_start_changed_p
= 0;
13352 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13354 /* If window start is on a continuation line... Window start may be
13355 < BEGV in case there's invisible text at the start of the
13356 buffer (M-x rmail, for example). */
13357 if (CHARPOS (start_pos
) > BEGV
13358 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13361 struct glyph_row
*row
;
13363 /* Handle the case that the window start is out of range. */
13364 if (CHARPOS (start_pos
) < BEGV
)
13365 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13366 else if (CHARPOS (start_pos
) > ZV
)
13367 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13369 /* Find the start of the continued line. This should be fast
13370 because scan_buffer is fast (newline cache). */
13371 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13372 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13373 row
, DEFAULT_FACE_ID
);
13374 reseat_at_previous_visible_line_start (&it
);
13376 /* If the line start is "too far" away from the window start,
13377 say it takes too much time to compute a new window start. */
13378 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13379 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13381 int min_distance
, distance
;
13383 /* Move forward by display lines to find the new window
13384 start. If window width was enlarged, the new start can
13385 be expected to be > the old start. If window width was
13386 decreased, the new window start will be < the old start.
13387 So, we're looking for the display line start with the
13388 minimum distance from the old window start. */
13389 pos
= it
.current
.pos
;
13390 min_distance
= INFINITY
;
13391 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13392 distance
< min_distance
)
13394 min_distance
= distance
;
13395 pos
= it
.current
.pos
;
13396 move_it_by_lines (&it
, 1, 0);
13399 /* Set the window start there. */
13400 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13401 window_start_changed_p
= 1;
13405 return window_start_changed_p
;
13409 /* Try cursor movement in case text has not changed in window WINDOW,
13410 with window start STARTP. Value is
13412 CURSOR_MOVEMENT_SUCCESS if successful
13414 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13416 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13417 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13418 we want to scroll as if scroll-step were set to 1. See the code.
13420 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13421 which case we have to abort this redisplay, and adjust matrices
13426 CURSOR_MOVEMENT_SUCCESS
,
13427 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13428 CURSOR_MOVEMENT_MUST_SCROLL
,
13429 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13433 try_cursor_movement (window
, startp
, scroll_step
)
13434 Lisp_Object window
;
13435 struct text_pos startp
;
13438 struct window
*w
= XWINDOW (window
);
13439 struct frame
*f
= XFRAME (w
->frame
);
13440 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13443 if (inhibit_try_cursor_movement
)
13447 /* Handle case where text has not changed, only point, and it has
13448 not moved off the frame. */
13449 if (/* Point may be in this window. */
13450 PT
>= CHARPOS (startp
)
13451 /* Selective display hasn't changed. */
13452 && !current_buffer
->clip_changed
13453 /* Function force-mode-line-update is used to force a thorough
13454 redisplay. It sets either windows_or_buffers_changed or
13455 update_mode_lines. So don't take a shortcut here for these
13457 && !update_mode_lines
13458 && !windows_or_buffers_changed
13459 && !cursor_type_changed
13460 /* Can't use this case if highlighting a region. When a
13461 region exists, cursor movement has to do more than just
13463 && !(!NILP (Vtransient_mark_mode
)
13464 && !NILP (current_buffer
->mark_active
))
13465 && NILP (w
->region_showing
)
13466 && NILP (Vshow_trailing_whitespace
)
13467 /* Right after splitting windows, last_point may be nil. */
13468 && INTEGERP (w
->last_point
)
13469 /* This code is not used for mini-buffer for the sake of the case
13470 of redisplaying to replace an echo area message; since in
13471 that case the mini-buffer contents per se are usually
13472 unchanged. This code is of no real use in the mini-buffer
13473 since the handling of this_line_start_pos, etc., in redisplay
13474 handles the same cases. */
13475 && !EQ (window
, minibuf_window
)
13476 /* When splitting windows or for new windows, it happens that
13477 redisplay is called with a nil window_end_vpos or one being
13478 larger than the window. This should really be fixed in
13479 window.c. I don't have this on my list, now, so we do
13480 approximately the same as the old redisplay code. --gerd. */
13481 && INTEGERP (w
->window_end_vpos
)
13482 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13483 && (FRAME_WINDOW_P (f
)
13484 || !overlay_arrow_in_current_buffer_p ()))
13486 int this_scroll_margin
, top_scroll_margin
;
13487 struct glyph_row
*row
= NULL
;
13490 debug_method_add (w
, "cursor movement");
13493 /* Scroll if point within this distance from the top or bottom
13494 of the window. This is a pixel value. */
13495 if (scroll_margin
> 0)
13497 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13498 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13501 this_scroll_margin
= 0;
13503 top_scroll_margin
= this_scroll_margin
;
13504 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13505 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13507 /* Start with the row the cursor was displayed during the last
13508 not paused redisplay. Give up if that row is not valid. */
13509 if (w
->last_cursor
.vpos
< 0
13510 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13511 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13514 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13515 if (row
->mode_line_p
)
13517 if (!row
->enabled_p
)
13518 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13519 /* If rows are bidi-reordered, back up until we find a row
13520 that does not belong to a continuation line. This is
13521 because we must consider all rows of a continued line as
13522 candidates for cursor positioning, since row start and
13523 end positions change non-linearly with vertical position
13525 /* FIXME: Revisit this when glyph ``spilling'' in
13526 continuation lines' rows is implemented for
13527 bidi-reordered rows. */
13528 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13530 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13532 xassert (row
->enabled_p
);
13534 /* If we hit the beginning of the displayed portion
13535 without finding the first row of a continued
13537 if (row
<= w
->current_matrix
->rows
)
13539 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13547 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13550 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13552 if (PT
> XFASTINT (w
->last_point
))
13554 /* Point has moved forward. */
13555 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13556 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13558 xassert (row
->enabled_p
);
13562 /* The end position of a row equals the start position
13563 of the next row. If PT is there, we would rather
13564 display it in the next line. */
13565 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13566 && MATRIX_ROW_END_CHARPOS (row
) == PT
13567 && !cursor_row_p (w
, row
))
13570 /* If within the scroll margin, scroll. Note that
13571 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13572 the next line would be drawn, and that
13573 this_scroll_margin can be zero. */
13574 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13575 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13576 /* Line is completely visible last line in window
13577 and PT is to be set in the next line. */
13578 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13579 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13580 && !row
->ends_at_zv_p
13581 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13584 else if (PT
< XFASTINT (w
->last_point
))
13586 /* Cursor has to be moved backward. Note that PT >=
13587 CHARPOS (startp) because of the outer if-statement. */
13588 while (!row
->mode_line_p
13589 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13590 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13591 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13592 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13593 row
> w
->current_matrix
->rows
13594 && (row
-1)->ends_in_newline_from_string_p
))))
13595 && (row
->y
> top_scroll_margin
13596 || CHARPOS (startp
) == BEGV
))
13598 xassert (row
->enabled_p
);
13602 /* Consider the following case: Window starts at BEGV,
13603 there is invisible, intangible text at BEGV, so that
13604 display starts at some point START > BEGV. It can
13605 happen that we are called with PT somewhere between
13606 BEGV and START. Try to handle that case. */
13607 if (row
< w
->current_matrix
->rows
13608 || row
->mode_line_p
)
13610 row
= w
->current_matrix
->rows
;
13611 if (row
->mode_line_p
)
13615 /* Due to newlines in overlay strings, we may have to
13616 skip forward over overlay strings. */
13617 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13618 && MATRIX_ROW_END_CHARPOS (row
) == PT
13619 && !cursor_row_p (w
, row
))
13622 /* If within the scroll margin, scroll. */
13623 if (row
->y
< top_scroll_margin
13624 && CHARPOS (startp
) != BEGV
)
13629 /* Cursor did not move. So don't scroll even if cursor line
13630 is partially visible, as it was so before. */
13631 rc
= CURSOR_MOVEMENT_SUCCESS
;
13634 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13635 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13637 /* if PT is not in the glyph row, give up. */
13638 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13640 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13641 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13642 && make_cursor_line_fully_visible_p
)
13644 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13645 && !row
->ends_at_zv_p
13646 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13647 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13648 else if (row
->height
> window_box_height (w
))
13650 /* If we end up in a partially visible line, let's
13651 make it fully visible, except when it's taller
13652 than the window, in which case we can't do much
13655 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13659 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13660 if (!cursor_row_fully_visible_p (w
, 0, 1))
13661 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13663 rc
= CURSOR_MOVEMENT_SUCCESS
;
13667 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13668 else if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13670 /* With bidi-reordered rows, there could be more than
13671 one candidate row whose start and end positions
13672 occlude point. We need to let set_cursor_from_row
13673 find the best candidate. */
13674 /* FIXME: Revisit this when glyph ``spilling'' in
13675 continuation lines' rows is implemented for
13676 bidi-reordered rows. */
13681 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13683 /* As soon as we've found the first suitable row
13684 whose ends_at_zv_p flag is set, we are done. */
13686 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13688 rc
= CURSOR_MOVEMENT_SUCCESS
;
13693 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13694 && MATRIX_ROW_START_CHARPOS (row
) <= PT
13695 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13696 && cursor_row_p (w
, row
));
13697 /* If we didn't find any candidate rows, or exited the
13698 loop before all the candidates were examined, signal
13699 to the caller that this method failed. */
13700 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13702 || (MATRIX_ROW_START_CHARPOS (row
) <= PT
13703 && PT
<= MATRIX_ROW_END_CHARPOS (row
))))
13704 rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13706 rc
= CURSOR_MOVEMENT_SUCCESS
;
13712 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13714 rc
= CURSOR_MOVEMENT_SUCCESS
;
13719 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13720 && MATRIX_ROW_START_CHARPOS (row
) == PT
13721 && cursor_row_p (w
, row
));
13730 set_vertical_scroll_bar (w
)
13733 int start
, end
, whole
;
13735 /* Calculate the start and end positions for the current window.
13736 At some point, it would be nice to choose between scrollbars
13737 which reflect the whole buffer size, with special markers
13738 indicating narrowing, and scrollbars which reflect only the
13741 Note that mini-buffers sometimes aren't displaying any text. */
13742 if (!MINI_WINDOW_P (w
)
13743 || (w
== XWINDOW (minibuf_window
)
13744 && NILP (echo_area_buffer
[0])))
13746 struct buffer
*buf
= XBUFFER (w
->buffer
);
13747 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13748 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13749 /* I don't think this is guaranteed to be right. For the
13750 moment, we'll pretend it is. */
13751 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13755 if (whole
< (end
- start
))
13756 whole
= end
- start
;
13759 start
= end
= whole
= 0;
13761 /* Indicate what this scroll bar ought to be displaying now. */
13762 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13763 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13764 (w
, end
- start
, whole
, start
);
13768 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13769 selected_window is redisplayed.
13771 We can return without actually redisplaying the window if
13772 fonts_changed_p is nonzero. In that case, redisplay_internal will
13776 redisplay_window (window
, just_this_one_p
)
13777 Lisp_Object window
;
13778 int just_this_one_p
;
13780 struct window
*w
= XWINDOW (window
);
13781 struct frame
*f
= XFRAME (w
->frame
);
13782 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13783 struct buffer
*old
= current_buffer
;
13784 struct text_pos lpoint
, opoint
, startp
;
13785 int update_mode_line
;
13788 /* Record it now because it's overwritten. */
13789 int current_matrix_up_to_date_p
= 0;
13790 int used_current_matrix_p
= 0;
13791 /* This is less strict than current_matrix_up_to_date_p.
13792 It indictes that the buffer contents and narrowing are unchanged. */
13793 int buffer_unchanged_p
= 0;
13794 int temp_scroll_step
= 0;
13795 int count
= SPECPDL_INDEX ();
13797 int centering_position
= -1;
13798 int last_line_misfit
= 0;
13799 int beg_unchanged
, end_unchanged
;
13801 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13804 /* W must be a leaf window here. */
13805 xassert (!NILP (w
->buffer
));
13807 *w
->desired_matrix
->method
= 0;
13811 reconsider_clip_changes (w
, buffer
);
13813 /* Has the mode line to be updated? */
13814 update_mode_line
= (!NILP (w
->update_mode_line
)
13815 || update_mode_lines
13816 || buffer
->clip_changed
13817 || buffer
->prevent_redisplay_optimizations_p
);
13819 if (MINI_WINDOW_P (w
))
13821 if (w
== XWINDOW (echo_area_window
)
13822 && !NILP (echo_area_buffer
[0]))
13824 if (update_mode_line
)
13825 /* We may have to update a tty frame's menu bar or a
13826 tool-bar. Example `M-x C-h C-h C-g'. */
13827 goto finish_menu_bars
;
13829 /* We've already displayed the echo area glyphs in this window. */
13830 goto finish_scroll_bars
;
13832 else if ((w
!= XWINDOW (minibuf_window
)
13833 || minibuf_level
== 0)
13834 /* When buffer is nonempty, redisplay window normally. */
13835 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13836 /* Quail displays non-mini buffers in minibuffer window.
13837 In that case, redisplay the window normally. */
13838 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13840 /* W is a mini-buffer window, but it's not active, so clear
13842 int yb
= window_text_bottom_y (w
);
13843 struct glyph_row
*row
;
13846 for (y
= 0, row
= w
->desired_matrix
->rows
;
13848 y
+= row
->height
, ++row
)
13849 blank_row (w
, row
, y
);
13850 goto finish_scroll_bars
;
13853 clear_glyph_matrix (w
->desired_matrix
);
13856 /* Otherwise set up data on this window; select its buffer and point
13858 /* Really select the buffer, for the sake of buffer-local
13860 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13862 current_matrix_up_to_date_p
13863 = (!NILP (w
->window_end_valid
)
13864 && !current_buffer
->clip_changed
13865 && !current_buffer
->prevent_redisplay_optimizations_p
13866 && XFASTINT (w
->last_modified
) >= MODIFF
13867 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13869 /* Run the window-bottom-change-functions
13870 if it is possible that the text on the screen has changed
13871 (either due to modification of the text, or any other reason). */
13872 if (!current_matrix_up_to_date_p
13873 && !NILP (Vwindow_text_change_functions
))
13875 safe_run_hooks (Qwindow_text_change_functions
);
13879 beg_unchanged
= BEG_UNCHANGED
;
13880 end_unchanged
= END_UNCHANGED
;
13882 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13884 specbind (Qinhibit_point_motion_hooks
, Qt
);
13887 = (!NILP (w
->window_end_valid
)
13888 && !current_buffer
->clip_changed
13889 && XFASTINT (w
->last_modified
) >= MODIFF
13890 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13892 /* When windows_or_buffers_changed is non-zero, we can't rely on
13893 the window end being valid, so set it to nil there. */
13894 if (windows_or_buffers_changed
)
13896 /* If window starts on a continuation line, maybe adjust the
13897 window start in case the window's width changed. */
13898 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13899 compute_window_start_on_continuation_line (w
);
13901 w
->window_end_valid
= Qnil
;
13904 /* Some sanity checks. */
13905 CHECK_WINDOW_END (w
);
13906 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13908 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13911 /* If %c is in mode line, update it if needed. */
13912 if (!NILP (w
->column_number_displayed
)
13913 /* This alternative quickly identifies a common case
13914 where no change is needed. */
13915 && !(PT
== XFASTINT (w
->last_point
)
13916 && XFASTINT (w
->last_modified
) >= MODIFF
13917 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13918 && (XFASTINT (w
->column_number_displayed
)
13919 != (int) current_column ())) /* iftc */
13920 update_mode_line
= 1;
13922 /* Count number of windows showing the selected buffer. An indirect
13923 buffer counts as its base buffer. */
13924 if (!just_this_one_p
)
13926 struct buffer
*current_base
, *window_base
;
13927 current_base
= current_buffer
;
13928 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13929 if (current_base
->base_buffer
)
13930 current_base
= current_base
->base_buffer
;
13931 if (window_base
->base_buffer
)
13932 window_base
= window_base
->base_buffer
;
13933 if (current_base
== window_base
)
13937 /* Point refers normally to the selected window. For any other
13938 window, set up appropriate value. */
13939 if (!EQ (window
, selected_window
))
13941 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13942 int new_pt_byte
= marker_byte_position (w
->pointm
);
13946 new_pt_byte
= BEGV_BYTE
;
13947 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13949 else if (new_pt
> (ZV
- 1))
13952 new_pt_byte
= ZV_BYTE
;
13953 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13956 /* We don't use SET_PT so that the point-motion hooks don't run. */
13957 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13960 /* If any of the character widths specified in the display table
13961 have changed, invalidate the width run cache. It's true that
13962 this may be a bit late to catch such changes, but the rest of
13963 redisplay goes (non-fatally) haywire when the display table is
13964 changed, so why should we worry about doing any better? */
13965 if (current_buffer
->width_run_cache
)
13967 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13969 if (! disptab_matches_widthtab (disptab
,
13970 XVECTOR (current_buffer
->width_table
)))
13972 invalidate_region_cache (current_buffer
,
13973 current_buffer
->width_run_cache
,
13975 recompute_width_table (current_buffer
, disptab
);
13979 /* If window-start is screwed up, choose a new one. */
13980 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13983 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13985 /* If someone specified a new starting point but did not insist,
13986 check whether it can be used. */
13987 if (!NILP (w
->optional_new_start
)
13988 && CHARPOS (startp
) >= BEGV
13989 && CHARPOS (startp
) <= ZV
)
13991 w
->optional_new_start
= Qnil
;
13992 start_display (&it
, w
, startp
);
13993 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13994 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13995 if (IT_CHARPOS (it
) == PT
)
13996 w
->force_start
= Qt
;
13997 /* IT may overshoot PT if text at PT is invisible. */
13998 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13999 w
->force_start
= Qt
;
14004 /* Handle case where place to start displaying has been specified,
14005 unless the specified location is outside the accessible range. */
14006 if (!NILP (w
->force_start
)
14007 || w
->frozen_window_start_p
)
14009 /* We set this later on if we have to adjust point. */
14012 w
->force_start
= Qnil
;
14014 w
->window_end_valid
= Qnil
;
14016 /* Forget any recorded base line for line number display. */
14017 if (!buffer_unchanged_p
)
14018 w
->base_line_number
= Qnil
;
14020 /* Redisplay the mode line. Select the buffer properly for that.
14021 Also, run the hook window-scroll-functions
14022 because we have scrolled. */
14023 /* Note, we do this after clearing force_start because
14024 if there's an error, it is better to forget about force_start
14025 than to get into an infinite loop calling the hook functions
14026 and having them get more errors. */
14027 if (!update_mode_line
14028 || ! NILP (Vwindow_scroll_functions
))
14030 update_mode_line
= 1;
14031 w
->update_mode_line
= Qt
;
14032 startp
= run_window_scroll_functions (window
, startp
);
14035 w
->last_modified
= make_number (0);
14036 w
->last_overlay_modified
= make_number (0);
14037 if (CHARPOS (startp
) < BEGV
)
14038 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14039 else if (CHARPOS (startp
) > ZV
)
14040 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14042 /* Redisplay, then check if cursor has been set during the
14043 redisplay. Give up if new fonts were loaded. */
14044 /* We used to issue a CHECK_MARGINS argument to try_window here,
14045 but this causes scrolling to fail when point begins inside
14046 the scroll margin (bug#148) -- cyd */
14047 if (!try_window (window
, startp
, 0))
14049 w
->force_start
= Qt
;
14050 clear_glyph_matrix (w
->desired_matrix
);
14051 goto need_larger_matrices
;
14054 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14056 /* If point does not appear, try to move point so it does
14057 appear. The desired matrix has been built above, so we
14058 can use it here. */
14059 new_vpos
= window_box_height (w
) / 2;
14062 if (!cursor_row_fully_visible_p (w
, 0, 0))
14064 /* Point does appear, but on a line partly visible at end of window.
14065 Move it back to a fully-visible line. */
14066 new_vpos
= window_box_height (w
);
14069 /* If we need to move point for either of the above reasons,
14070 now actually do it. */
14073 struct glyph_row
*row
;
14075 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14076 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14079 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14080 MATRIX_ROW_START_BYTEPOS (row
));
14082 if (w
!= XWINDOW (selected_window
))
14083 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14084 else if (current_buffer
== old
)
14085 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14087 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14089 /* If we are highlighting the region, then we just changed
14090 the region, so redisplay to show it. */
14091 if (!NILP (Vtransient_mark_mode
)
14092 && !NILP (current_buffer
->mark_active
))
14094 clear_glyph_matrix (w
->desired_matrix
);
14095 if (!try_window (window
, startp
, 0))
14096 goto need_larger_matrices
;
14101 debug_method_add (w
, "forced window start");
14106 /* Handle case where text has not changed, only point, and it has
14107 not moved off the frame, and we are not retrying after hscroll.
14108 (current_matrix_up_to_date_p is nonzero when retrying.) */
14109 if (current_matrix_up_to_date_p
14110 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14111 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14115 case CURSOR_MOVEMENT_SUCCESS
:
14116 used_current_matrix_p
= 1;
14119 case CURSOR_MOVEMENT_MUST_SCROLL
:
14120 goto try_to_scroll
;
14126 /* If current starting point was originally the beginning of a line
14127 but no longer is, find a new starting point. */
14128 else if (!NILP (w
->start_at_line_beg
)
14129 && !(CHARPOS (startp
) <= BEGV
14130 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14133 debug_method_add (w
, "recenter 1");
14138 /* Try scrolling with try_window_id. Value is > 0 if update has
14139 been done, it is -1 if we know that the same window start will
14140 not work. It is 0 if unsuccessful for some other reason. */
14141 else if ((tem
= try_window_id (w
)) != 0)
14144 debug_method_add (w
, "try_window_id %d", tem
);
14147 if (fonts_changed_p
)
14148 goto need_larger_matrices
;
14152 /* Otherwise try_window_id has returned -1 which means that we
14153 don't want the alternative below this comment to execute. */
14155 else if (CHARPOS (startp
) >= BEGV
14156 && CHARPOS (startp
) <= ZV
14157 && PT
>= CHARPOS (startp
)
14158 && (CHARPOS (startp
) < ZV
14159 /* Avoid starting at end of buffer. */
14160 || CHARPOS (startp
) == BEGV
14161 || (XFASTINT (w
->last_modified
) >= MODIFF
14162 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14165 /* If first window line is a continuation line, and window start
14166 is inside the modified region, but the first change is before
14167 current window start, we must select a new window start.
14169 However, if this is the result of a down-mouse event (e.g. by
14170 extending the mouse-drag-overlay), we don't want to select a
14171 new window start, since that would change the position under
14172 the mouse, resulting in an unwanted mouse-movement rather
14173 than a simple mouse-click. */
14174 if (NILP (w
->start_at_line_beg
)
14175 && NILP (do_mouse_tracking
)
14176 && CHARPOS (startp
) > BEGV
14177 && CHARPOS (startp
) > BEG
+ beg_unchanged
14178 && CHARPOS (startp
) <= Z
- end_unchanged
14179 /* Even if w->start_at_line_beg is nil, a new window may
14180 start at a line_beg, since that's how set_buffer_window
14181 sets it. So, we need to check the return value of
14182 compute_window_start_on_continuation_line. (See also
14184 && XMARKER (w
->start
)->buffer
== current_buffer
14185 && compute_window_start_on_continuation_line (w
))
14187 w
->force_start
= Qt
;
14188 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14193 debug_method_add (w
, "same window start");
14196 /* Try to redisplay starting at same place as before.
14197 If point has not moved off frame, accept the results. */
14198 if (!current_matrix_up_to_date_p
14199 /* Don't use try_window_reusing_current_matrix in this case
14200 because a window scroll function can have changed the
14202 || !NILP (Vwindow_scroll_functions
)
14203 || MINI_WINDOW_P (w
)
14204 || !(used_current_matrix_p
14205 = try_window_reusing_current_matrix (w
)))
14207 IF_DEBUG (debug_method_add (w
, "1"));
14208 if (try_window (window
, startp
, 1) < 0)
14209 /* -1 means we need to scroll.
14210 0 means we need new matrices, but fonts_changed_p
14211 is set in that case, so we will detect it below. */
14212 goto try_to_scroll
;
14215 if (fonts_changed_p
)
14216 goto need_larger_matrices
;
14218 if (w
->cursor
.vpos
>= 0)
14220 if (!just_this_one_p
14221 || current_buffer
->clip_changed
14222 || BEG_UNCHANGED
< CHARPOS (startp
))
14223 /* Forget any recorded base line for line number display. */
14224 w
->base_line_number
= Qnil
;
14226 if (!cursor_row_fully_visible_p (w
, 1, 0))
14228 clear_glyph_matrix (w
->desired_matrix
);
14229 last_line_misfit
= 1;
14231 /* Drop through and scroll. */
14236 clear_glyph_matrix (w
->desired_matrix
);
14241 w
->last_modified
= make_number (0);
14242 w
->last_overlay_modified
= make_number (0);
14244 /* Redisplay the mode line. Select the buffer properly for that. */
14245 if (!update_mode_line
)
14247 update_mode_line
= 1;
14248 w
->update_mode_line
= Qt
;
14251 /* Try to scroll by specified few lines. */
14252 if ((scroll_conservatively
14254 || temp_scroll_step
14255 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14256 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14257 && !current_buffer
->clip_changed
14258 && CHARPOS (startp
) >= BEGV
14259 && CHARPOS (startp
) <= ZV
)
14261 /* The function returns -1 if new fonts were loaded, 1 if
14262 successful, 0 if not successful. */
14263 int rc
= try_scrolling (window
, just_this_one_p
,
14264 scroll_conservatively
,
14266 temp_scroll_step
, last_line_misfit
);
14269 case SCROLLING_SUCCESS
:
14272 case SCROLLING_NEED_LARGER_MATRICES
:
14273 goto need_larger_matrices
;
14275 case SCROLLING_FAILED
:
14283 /* Finally, just choose place to start which centers point */
14286 if (centering_position
< 0)
14287 centering_position
= window_box_height (w
) / 2;
14290 debug_method_add (w
, "recenter");
14293 /* w->vscroll = 0; */
14295 /* Forget any previously recorded base line for line number display. */
14296 if (!buffer_unchanged_p
)
14297 w
->base_line_number
= Qnil
;
14299 /* Move backward half the height of the window. */
14300 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14301 it
.current_y
= it
.last_visible_y
;
14302 move_it_vertically_backward (&it
, centering_position
);
14303 xassert (IT_CHARPOS (it
) >= BEGV
);
14305 /* The function move_it_vertically_backward may move over more
14306 than the specified y-distance. If it->w is small, e.g. a
14307 mini-buffer window, we may end up in front of the window's
14308 display area. Start displaying at the start of the line
14309 containing PT in this case. */
14310 if (it
.current_y
<= 0)
14312 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14313 move_it_vertically_backward (&it
, 0);
14317 it
.current_x
= it
.hpos
= 0;
14319 /* Set startp here explicitly in case that helps avoid an infinite loop
14320 in case the window-scroll-functions functions get errors. */
14321 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14323 /* Run scroll hooks. */
14324 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14326 /* Redisplay the window. */
14327 if (!current_matrix_up_to_date_p
14328 || windows_or_buffers_changed
14329 || cursor_type_changed
14330 /* Don't use try_window_reusing_current_matrix in this case
14331 because it can have changed the buffer. */
14332 || !NILP (Vwindow_scroll_functions
)
14333 || !just_this_one_p
14334 || MINI_WINDOW_P (w
)
14335 || !(used_current_matrix_p
14336 = try_window_reusing_current_matrix (w
)))
14337 try_window (window
, startp
, 0);
14339 /* If new fonts have been loaded (due to fontsets), give up. We
14340 have to start a new redisplay since we need to re-adjust glyph
14342 if (fonts_changed_p
)
14343 goto need_larger_matrices
;
14345 /* If cursor did not appear assume that the middle of the window is
14346 in the first line of the window. Do it again with the next line.
14347 (Imagine a window of height 100, displaying two lines of height
14348 60. Moving back 50 from it->last_visible_y will end in the first
14350 if (w
->cursor
.vpos
< 0)
14352 if (!NILP (w
->window_end_valid
)
14353 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14355 clear_glyph_matrix (w
->desired_matrix
);
14356 move_it_by_lines (&it
, 1, 0);
14357 try_window (window
, it
.current
.pos
, 0);
14359 else if (PT
< IT_CHARPOS (it
))
14361 clear_glyph_matrix (w
->desired_matrix
);
14362 move_it_by_lines (&it
, -1, 0);
14363 try_window (window
, it
.current
.pos
, 0);
14367 /* Not much we can do about it. */
14371 /* Consider the following case: Window starts at BEGV, there is
14372 invisible, intangible text at BEGV, so that display starts at
14373 some point START > BEGV. It can happen that we are called with
14374 PT somewhere between BEGV and START. Try to handle that case. */
14375 if (w
->cursor
.vpos
< 0)
14377 struct glyph_row
*row
= w
->current_matrix
->rows
;
14378 if (row
->mode_line_p
)
14380 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14383 if (!cursor_row_fully_visible_p (w
, 0, 0))
14385 /* If vscroll is enabled, disable it and try again. */
14389 clear_glyph_matrix (w
->desired_matrix
);
14393 /* If centering point failed to make the whole line visible,
14394 put point at the top instead. That has to make the whole line
14395 visible, if it can be done. */
14396 if (centering_position
== 0)
14399 clear_glyph_matrix (w
->desired_matrix
);
14400 centering_position
= 0;
14406 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14407 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14408 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14411 /* Display the mode line, if we must. */
14412 if ((update_mode_line
14413 /* If window not full width, must redo its mode line
14414 if (a) the window to its side is being redone and
14415 (b) we do a frame-based redisplay. This is a consequence
14416 of how inverted lines are drawn in frame-based redisplay. */
14417 || (!just_this_one_p
14418 && !FRAME_WINDOW_P (f
)
14419 && !WINDOW_FULL_WIDTH_P (w
))
14420 /* Line number to display. */
14421 || INTEGERP (w
->base_line_pos
)
14422 /* Column number is displayed and different from the one displayed. */
14423 || (!NILP (w
->column_number_displayed
)
14424 && (XFASTINT (w
->column_number_displayed
)
14425 != (int) current_column ()))) /* iftc */
14426 /* This means that the window has a mode line. */
14427 && (WINDOW_WANTS_MODELINE_P (w
)
14428 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14430 display_mode_lines (w
);
14432 /* If mode line height has changed, arrange for a thorough
14433 immediate redisplay using the correct mode line height. */
14434 if (WINDOW_WANTS_MODELINE_P (w
)
14435 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14437 fonts_changed_p
= 1;
14438 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14439 = DESIRED_MODE_LINE_HEIGHT (w
);
14442 /* If header line height has changed, arrange for a thorough
14443 immediate redisplay using the correct header line height. */
14444 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14445 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14447 fonts_changed_p
= 1;
14448 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14449 = DESIRED_HEADER_LINE_HEIGHT (w
);
14452 if (fonts_changed_p
)
14453 goto need_larger_matrices
;
14456 if (!line_number_displayed
14457 && !BUFFERP (w
->base_line_pos
))
14459 w
->base_line_pos
= Qnil
;
14460 w
->base_line_number
= Qnil
;
14465 /* When we reach a frame's selected window, redo the frame's menu bar. */
14466 if (update_mode_line
14467 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14469 int redisplay_menu_p
= 0;
14470 int redisplay_tool_bar_p
= 0;
14472 if (FRAME_WINDOW_P (f
))
14474 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14475 || defined (HAVE_NS) || defined (USE_GTK)
14476 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14478 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14482 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14484 if (redisplay_menu_p
)
14485 display_menu_bar (w
);
14487 #ifdef HAVE_WINDOW_SYSTEM
14488 if (FRAME_WINDOW_P (f
))
14490 #if defined (USE_GTK) || defined (HAVE_NS)
14491 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14493 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14494 && (FRAME_TOOL_BAR_LINES (f
) > 0
14495 || !NILP (Vauto_resize_tool_bars
));
14498 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14500 extern int ignore_mouse_drag_p
;
14501 ignore_mouse_drag_p
= 1;
14507 #ifdef HAVE_WINDOW_SYSTEM
14508 if (FRAME_WINDOW_P (f
)
14509 && update_window_fringes (w
, (just_this_one_p
14510 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14511 || w
->pseudo_window_p
)))
14515 if (draw_window_fringes (w
, 1))
14516 x_draw_vertical_border (w
);
14520 #endif /* HAVE_WINDOW_SYSTEM */
14522 /* We go to this label, with fonts_changed_p nonzero,
14523 if it is necessary to try again using larger glyph matrices.
14524 We have to redeem the scroll bar even in this case,
14525 because the loop in redisplay_internal expects that. */
14526 need_larger_matrices
:
14528 finish_scroll_bars
:
14530 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14532 /* Set the thumb's position and size. */
14533 set_vertical_scroll_bar (w
);
14535 /* Note that we actually used the scroll bar attached to this
14536 window, so it shouldn't be deleted at the end of redisplay. */
14537 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14538 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14541 /* Restore current_buffer and value of point in it. */
14542 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14543 set_buffer_internal_1 (old
);
14544 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14545 shorter. This can be caused by log truncation in *Messages*. */
14546 if (CHARPOS (lpoint
) <= ZV
)
14547 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14549 unbind_to (count
, Qnil
);
14553 /* Build the complete desired matrix of WINDOW with a window start
14554 buffer position POS.
14556 Value is 1 if successful. It is zero if fonts were loaded during
14557 redisplay which makes re-adjusting glyph matrices necessary, and -1
14558 if point would appear in the scroll margins.
14559 (We check that only if CHECK_MARGINS is nonzero. */
14562 try_window (window
, pos
, check_margins
)
14563 Lisp_Object window
;
14564 struct text_pos pos
;
14567 struct window
*w
= XWINDOW (window
);
14569 struct glyph_row
*last_text_row
= NULL
;
14570 struct frame
*f
= XFRAME (w
->frame
);
14572 /* Make POS the new window start. */
14573 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14575 /* Mark cursor position as unknown. No overlay arrow seen. */
14576 w
->cursor
.vpos
= -1;
14577 overlay_arrow_seen
= 0;
14579 /* Initialize iterator and info to start at POS. */
14580 start_display (&it
, w
, pos
);
14582 /* Display all lines of W. */
14583 while (it
.current_y
< it
.last_visible_y
)
14585 if (display_line (&it
))
14586 last_text_row
= it
.glyph_row
- 1;
14587 if (fonts_changed_p
)
14591 /* Don't let the cursor end in the scroll margins. */
14593 && !MINI_WINDOW_P (w
))
14595 int this_scroll_margin
;
14597 if (scroll_margin
> 0)
14599 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14600 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14603 this_scroll_margin
= 0;
14605 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14606 && w
->cursor
.y
< this_scroll_margin
14607 && CHARPOS (pos
) > BEGV
14608 && IT_CHARPOS (it
) < ZV
)
14609 /* rms: considering make_cursor_line_fully_visible_p here
14610 seems to give wrong results. We don't want to recenter
14611 when the last line is partly visible, we want to allow
14612 that case to be handled in the usual way. */
14613 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14615 w
->cursor
.vpos
= -1;
14616 clear_glyph_matrix (w
->desired_matrix
);
14621 /* If bottom moved off end of frame, change mode line percentage. */
14622 if (XFASTINT (w
->window_end_pos
) <= 0
14623 && Z
!= IT_CHARPOS (it
))
14624 w
->update_mode_line
= Qt
;
14626 /* Set window_end_pos to the offset of the last character displayed
14627 on the window from the end of current_buffer. Set
14628 window_end_vpos to its row number. */
14631 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14632 w
->window_end_bytepos
14633 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14635 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14637 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14638 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14639 ->displays_text_p
);
14643 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14644 w
->window_end_pos
= make_number (Z
- ZV
);
14645 w
->window_end_vpos
= make_number (0);
14648 /* But that is not valid info until redisplay finishes. */
14649 w
->window_end_valid
= Qnil
;
14655 /************************************************************************
14656 Window redisplay reusing current matrix when buffer has not changed
14657 ************************************************************************/
14659 /* Try redisplay of window W showing an unchanged buffer with a
14660 different window start than the last time it was displayed by
14661 reusing its current matrix. Value is non-zero if successful.
14662 W->start is the new window start. */
14665 try_window_reusing_current_matrix (w
)
14668 struct frame
*f
= XFRAME (w
->frame
);
14669 struct glyph_row
*row
, *bottom_row
;
14672 struct text_pos start
, new_start
;
14673 int nrows_scrolled
, i
;
14674 struct glyph_row
*last_text_row
;
14675 struct glyph_row
*last_reused_text_row
;
14676 struct glyph_row
*start_row
;
14677 int start_vpos
, min_y
, max_y
;
14680 if (inhibit_try_window_reusing
)
14684 if (/* This function doesn't handle terminal frames. */
14685 !FRAME_WINDOW_P (f
)
14686 /* Don't try to reuse the display if windows have been split
14688 || windows_or_buffers_changed
14689 || cursor_type_changed
)
14692 /* Can't do this if region may have changed. */
14693 if ((!NILP (Vtransient_mark_mode
)
14694 && !NILP (current_buffer
->mark_active
))
14695 || !NILP (w
->region_showing
)
14696 || !NILP (Vshow_trailing_whitespace
))
14699 /* If top-line visibility has changed, give up. */
14700 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14701 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14704 /* Give up if old or new display is scrolled vertically. We could
14705 make this function handle this, but right now it doesn't. */
14706 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14707 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14710 /* The variable new_start now holds the new window start. The old
14711 start `start' can be determined from the current matrix. */
14712 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14713 start
= start_row
->start
.pos
;
14714 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14716 /* Clear the desired matrix for the display below. */
14717 clear_glyph_matrix (w
->desired_matrix
);
14719 if (CHARPOS (new_start
) <= CHARPOS (start
))
14723 /* Don't use this method if the display starts with an ellipsis
14724 displayed for invisible text. It's not easy to handle that case
14725 below, and it's certainly not worth the effort since this is
14726 not a frequent case. */
14727 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14730 IF_DEBUG (debug_method_add (w
, "twu1"));
14732 /* Display up to a row that can be reused. The variable
14733 last_text_row is set to the last row displayed that displays
14734 text. Note that it.vpos == 0 if or if not there is a
14735 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14736 start_display (&it
, w
, new_start
);
14737 first_row_y
= it
.current_y
;
14738 w
->cursor
.vpos
= -1;
14739 last_text_row
= last_reused_text_row
= NULL
;
14741 while (it
.current_y
< it
.last_visible_y
14742 && !fonts_changed_p
)
14744 /* If we have reached into the characters in the START row,
14745 that means the line boundaries have changed. So we
14746 can't start copying with the row START. Maybe it will
14747 work to start copying with the following row. */
14748 while (IT_CHARPOS (it
) > CHARPOS (start
))
14750 /* Advance to the next row as the "start". */
14752 start
= start_row
->start
.pos
;
14753 /* If there are no more rows to try, or just one, give up. */
14754 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14755 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14756 || CHARPOS (start
) == ZV
)
14758 clear_glyph_matrix (w
->desired_matrix
);
14762 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14764 /* If we have reached alignment,
14765 we can copy the rest of the rows. */
14766 if (IT_CHARPOS (it
) == CHARPOS (start
))
14769 if (display_line (&it
))
14770 last_text_row
= it
.glyph_row
- 1;
14773 /* A value of current_y < last_visible_y means that we stopped
14774 at the previous window start, which in turn means that we
14775 have at least one reusable row. */
14776 if (it
.current_y
< it
.last_visible_y
)
14778 /* IT.vpos always starts from 0; it counts text lines. */
14779 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14781 /* Find PT if not already found in the lines displayed. */
14782 if (w
->cursor
.vpos
< 0)
14784 int dy
= it
.current_y
- start_row
->y
;
14786 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14787 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14789 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14790 dy
, nrows_scrolled
);
14793 clear_glyph_matrix (w
->desired_matrix
);
14798 /* Scroll the display. Do it before the current matrix is
14799 changed. The problem here is that update has not yet
14800 run, i.e. part of the current matrix is not up to date.
14801 scroll_run_hook will clear the cursor, and use the
14802 current matrix to get the height of the row the cursor is
14804 run
.current_y
= start_row
->y
;
14805 run
.desired_y
= it
.current_y
;
14806 run
.height
= it
.last_visible_y
- it
.current_y
;
14808 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14811 FRAME_RIF (f
)->update_window_begin_hook (w
);
14812 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14813 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14814 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14818 /* Shift current matrix down by nrows_scrolled lines. */
14819 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14820 rotate_matrix (w
->current_matrix
,
14822 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14825 /* Disable lines that must be updated. */
14826 for (i
= 0; i
< nrows_scrolled
; ++i
)
14827 (start_row
+ i
)->enabled_p
= 0;
14829 /* Re-compute Y positions. */
14830 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14831 max_y
= it
.last_visible_y
;
14832 for (row
= start_row
+ nrows_scrolled
;
14836 row
->y
= it
.current_y
;
14837 row
->visible_height
= row
->height
;
14839 if (row
->y
< min_y
)
14840 row
->visible_height
-= min_y
- row
->y
;
14841 if (row
->y
+ row
->height
> max_y
)
14842 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14843 row
->redraw_fringe_bitmaps_p
= 1;
14845 it
.current_y
+= row
->height
;
14847 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14848 last_reused_text_row
= row
;
14849 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14853 /* Disable lines in the current matrix which are now
14854 below the window. */
14855 for (++row
; row
< bottom_row
; ++row
)
14856 row
->enabled_p
= row
->mode_line_p
= 0;
14859 /* Update window_end_pos etc.; last_reused_text_row is the last
14860 reused row from the current matrix containing text, if any.
14861 The value of last_text_row is the last displayed line
14862 containing text. */
14863 if (last_reused_text_row
)
14865 w
->window_end_bytepos
14866 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14868 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14870 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14871 w
->current_matrix
));
14873 else if (last_text_row
)
14875 w
->window_end_bytepos
14876 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14878 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14880 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14884 /* This window must be completely empty. */
14885 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14886 w
->window_end_pos
= make_number (Z
- ZV
);
14887 w
->window_end_vpos
= make_number (0);
14889 w
->window_end_valid
= Qnil
;
14891 /* Update hint: don't try scrolling again in update_window. */
14892 w
->desired_matrix
->no_scrolling_p
= 1;
14895 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14899 else if (CHARPOS (new_start
) > CHARPOS (start
))
14901 struct glyph_row
*pt_row
, *row
;
14902 struct glyph_row
*first_reusable_row
;
14903 struct glyph_row
*first_row_to_display
;
14905 int yb
= window_text_bottom_y (w
);
14907 /* Find the row starting at new_start, if there is one. Don't
14908 reuse a partially visible line at the end. */
14909 first_reusable_row
= start_row
;
14910 while (first_reusable_row
->enabled_p
14911 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14912 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14913 < CHARPOS (new_start
)))
14914 ++first_reusable_row
;
14916 /* Give up if there is no row to reuse. */
14917 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14918 || !first_reusable_row
->enabled_p
14919 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14920 != CHARPOS (new_start
)))
14923 /* We can reuse fully visible rows beginning with
14924 first_reusable_row to the end of the window. Set
14925 first_row_to_display to the first row that cannot be reused.
14926 Set pt_row to the row containing point, if there is any. */
14928 for (first_row_to_display
= first_reusable_row
;
14929 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14930 ++first_row_to_display
)
14932 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14933 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14934 pt_row
= first_row_to_display
;
14937 /* Start displaying at the start of first_row_to_display. */
14938 xassert (first_row_to_display
->y
< yb
);
14939 init_to_row_start (&it
, w
, first_row_to_display
);
14941 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14943 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14945 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14946 + WINDOW_HEADER_LINE_HEIGHT (w
));
14948 /* Display lines beginning with first_row_to_display in the
14949 desired matrix. Set last_text_row to the last row displayed
14950 that displays text. */
14951 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14952 if (pt_row
== NULL
)
14953 w
->cursor
.vpos
= -1;
14954 last_text_row
= NULL
;
14955 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14956 if (display_line (&it
))
14957 last_text_row
= it
.glyph_row
- 1;
14959 /* If point is in a reused row, adjust y and vpos of the cursor
14963 w
->cursor
.vpos
-= nrows_scrolled
;
14964 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14967 /* Give up if point isn't in a row displayed or reused. (This
14968 also handles the case where w->cursor.vpos < nrows_scrolled
14969 after the calls to display_line, which can happen with scroll
14970 margins. See bug#1295.) */
14971 if (w
->cursor
.vpos
< 0)
14973 clear_glyph_matrix (w
->desired_matrix
);
14977 /* Scroll the display. */
14978 run
.current_y
= first_reusable_row
->y
;
14979 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14980 run
.height
= it
.last_visible_y
- run
.current_y
;
14981 dy
= run
.current_y
- run
.desired_y
;
14986 FRAME_RIF (f
)->update_window_begin_hook (w
);
14987 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14988 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14989 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14993 /* Adjust Y positions of reused rows. */
14994 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14995 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14996 max_y
= it
.last_visible_y
;
14997 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15000 row
->visible_height
= row
->height
;
15001 if (row
->y
< min_y
)
15002 row
->visible_height
-= min_y
- row
->y
;
15003 if (row
->y
+ row
->height
> max_y
)
15004 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15005 row
->redraw_fringe_bitmaps_p
= 1;
15008 /* Scroll the current matrix. */
15009 xassert (nrows_scrolled
> 0);
15010 rotate_matrix (w
->current_matrix
,
15012 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15015 /* Disable rows not reused. */
15016 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15017 row
->enabled_p
= 0;
15019 /* Point may have moved to a different line, so we cannot assume that
15020 the previous cursor position is valid; locate the correct row. */
15023 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15024 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15028 w
->cursor
.y
= row
->y
;
15030 if (row
< bottom_row
)
15032 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15033 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15034 struct glyph
*orig_glyph
= glyph
;
15035 struct cursor_pos orig_cursor
= w
->cursor
;
15038 && (!BUFFERP (glyph
->object
)
15039 || glyph
->charpos
!= PT
);
15043 w
->cursor
.x
+= glyph
->pixel_width
;
15045 /* With bidi reordering, charpos changes non-linearly
15046 with hpos, so the right glyph could be to the
15048 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15049 && (!BUFFERP (glyph
->object
) || glyph
->charpos
!= PT
))
15051 struct glyph
*start_glyph
= row
->glyphs
[TEXT_AREA
];
15053 glyph
= orig_glyph
- 1;
15054 orig_cursor
.hpos
--;
15055 orig_cursor
.x
-= glyph
->pixel_width
;
15056 for (; glyph
>= start_glyph
15057 && (!BUFFERP (glyph
->object
)
15058 || glyph
->charpos
!= PT
);
15062 w
->cursor
.x
-= glyph
->pixel_width
;
15064 if (BUFFERP (glyph
->object
) && glyph
->charpos
== PT
)
15065 w
->cursor
= orig_cursor
;
15070 /* Adjust window end. A null value of last_text_row means that
15071 the window end is in reused rows which in turn means that
15072 only its vpos can have changed. */
15075 w
->window_end_bytepos
15076 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15078 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15080 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15085 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15088 w
->window_end_valid
= Qnil
;
15089 w
->desired_matrix
->no_scrolling_p
= 1;
15092 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15102 /************************************************************************
15103 Window redisplay reusing current matrix when buffer has changed
15104 ************************************************************************/
15106 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
15107 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
15109 static struct glyph_row
*
15110 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
15111 struct glyph_row
*));
15114 /* Return the last row in MATRIX displaying text. If row START is
15115 non-null, start searching with that row. IT gives the dimensions
15116 of the display. Value is null if matrix is empty; otherwise it is
15117 a pointer to the row found. */
15119 static struct glyph_row
*
15120 find_last_row_displaying_text (matrix
, it
, start
)
15121 struct glyph_matrix
*matrix
;
15123 struct glyph_row
*start
;
15125 struct glyph_row
*row
, *row_found
;
15127 /* Set row_found to the last row in IT->w's current matrix
15128 displaying text. The loop looks funny but think of partially
15131 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15132 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15134 xassert (row
->enabled_p
);
15136 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15145 /* Return the last row in the current matrix of W that is not affected
15146 by changes at the start of current_buffer that occurred since W's
15147 current matrix was built. Value is null if no such row exists.
15149 BEG_UNCHANGED us the number of characters unchanged at the start of
15150 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15151 first changed character in current_buffer. Characters at positions <
15152 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15153 when the current matrix was built. */
15155 static struct glyph_row
*
15156 find_last_unchanged_at_beg_row (w
)
15159 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15160 struct glyph_row
*row
;
15161 struct glyph_row
*row_found
= NULL
;
15162 int yb
= window_text_bottom_y (w
);
15164 /* Find the last row displaying unchanged text. */
15165 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15166 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15167 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15170 if (/* If row ends before first_changed_pos, it is unchanged,
15171 except in some case. */
15172 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15173 /* When row ends in ZV and we write at ZV it is not
15175 && !row
->ends_at_zv_p
15176 /* When first_changed_pos is the end of a continued line,
15177 row is not unchanged because it may be no longer
15179 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15180 && (row
->continued_p
15181 || row
->exact_window_width_line_p
)))
15184 /* Stop if last visible row. */
15185 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15193 /* Find the first glyph row in the current matrix of W that is not
15194 affected by changes at the end of current_buffer since the
15195 time W's current matrix was built.
15197 Return in *DELTA the number of chars by which buffer positions in
15198 unchanged text at the end of current_buffer must be adjusted.
15200 Return in *DELTA_BYTES the corresponding number of bytes.
15202 Value is null if no such row exists, i.e. all rows are affected by
15205 static struct glyph_row
*
15206 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
15208 int *delta
, *delta_bytes
;
15210 struct glyph_row
*row
;
15211 struct glyph_row
*row_found
= NULL
;
15213 *delta
= *delta_bytes
= 0;
15215 /* Display must not have been paused, otherwise the current matrix
15216 is not up to date. */
15217 eassert (!NILP (w
->window_end_valid
));
15219 /* A value of window_end_pos >= END_UNCHANGED means that the window
15220 end is in the range of changed text. If so, there is no
15221 unchanged row at the end of W's current matrix. */
15222 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15225 /* Set row to the last row in W's current matrix displaying text. */
15226 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15228 /* If matrix is entirely empty, no unchanged row exists. */
15229 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15231 /* The value of row is the last glyph row in the matrix having a
15232 meaningful buffer position in it. The end position of row
15233 corresponds to window_end_pos. This allows us to translate
15234 buffer positions in the current matrix to current buffer
15235 positions for characters not in changed text. */
15236 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15237 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15238 int last_unchanged_pos
, last_unchanged_pos_old
;
15239 struct glyph_row
*first_text_row
15240 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15242 *delta
= Z
- Z_old
;
15243 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15245 /* Set last_unchanged_pos to the buffer position of the last
15246 character in the buffer that has not been changed. Z is the
15247 index + 1 of the last character in current_buffer, i.e. by
15248 subtracting END_UNCHANGED we get the index of the last
15249 unchanged character, and we have to add BEG to get its buffer
15251 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15252 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15254 /* Search backward from ROW for a row displaying a line that
15255 starts at a minimum position >= last_unchanged_pos_old. */
15256 for (; row
> first_text_row
; --row
)
15258 /* This used to abort, but it can happen.
15259 It is ok to just stop the search instead here. KFS. */
15260 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15263 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15268 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15274 /* Make sure that glyph rows in the current matrix of window W
15275 reference the same glyph memory as corresponding rows in the
15276 frame's frame matrix. This function is called after scrolling W's
15277 current matrix on a terminal frame in try_window_id and
15278 try_window_reusing_current_matrix. */
15281 sync_frame_with_window_matrix_rows (w
)
15284 struct frame
*f
= XFRAME (w
->frame
);
15285 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15287 /* Preconditions: W must be a leaf window and full-width. Its frame
15288 must have a frame matrix. */
15289 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15290 xassert (WINDOW_FULL_WIDTH_P (w
));
15291 xassert (!FRAME_WINDOW_P (f
));
15293 /* If W is a full-width window, glyph pointers in W's current matrix
15294 have, by definition, to be the same as glyph pointers in the
15295 corresponding frame matrix. Note that frame matrices have no
15296 marginal areas (see build_frame_matrix). */
15297 window_row
= w
->current_matrix
->rows
;
15298 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15299 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15300 while (window_row
< window_row_end
)
15302 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15303 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15305 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15306 frame_row
->glyphs
[TEXT_AREA
] = start
;
15307 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15308 frame_row
->glyphs
[LAST_AREA
] = end
;
15310 /* Disable frame rows whose corresponding window rows have
15311 been disabled in try_window_id. */
15312 if (!window_row
->enabled_p
)
15313 frame_row
->enabled_p
= 0;
15315 ++window_row
, ++frame_row
;
15320 /* Find the glyph row in window W containing CHARPOS. Consider all
15321 rows between START and END (not inclusive). END null means search
15322 all rows to the end of the display area of W. Value is the row
15323 containing CHARPOS or null. */
15326 row_containing_pos (w
, charpos
, start
, end
, dy
)
15329 struct glyph_row
*start
, *end
;
15332 struct glyph_row
*row
= start
;
15333 struct glyph_row
*best_row
= NULL
;
15334 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15337 /* If we happen to start on a header-line, skip that. */
15338 if (row
->mode_line_p
)
15341 if ((end
&& row
>= end
) || !row
->enabled_p
)
15344 last_y
= window_text_bottom_y (w
) - dy
;
15348 /* Give up if we have gone too far. */
15349 if (end
&& row
>= end
)
15351 /* This formerly returned if they were equal.
15352 I think that both quantities are of a "last plus one" type;
15353 if so, when they are equal, the row is within the screen. -- rms. */
15354 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15357 /* If it is in this row, return this row. */
15358 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15359 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15360 /* The end position of a row equals the start
15361 position of the next row. If CHARPOS is there, we
15362 would rather display it in the next line, except
15363 when this line ends in ZV. */
15364 && !row
->ends_at_zv_p
15365 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15366 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15370 if (NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
15372 /* In bidi-reordered rows, there could be several rows
15373 occluding point. We need to find the one which fits
15374 CHARPOS the best. */
15375 for (g
= row
->glyphs
[TEXT_AREA
];
15376 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15379 if (!STRINGP (g
->object
))
15381 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15383 mindif
= eabs (g
->charpos
- charpos
);
15396 /* Try to redisplay window W by reusing its existing display. W's
15397 current matrix must be up to date when this function is called,
15398 i.e. window_end_valid must not be nil.
15402 1 if display has been updated
15403 0 if otherwise unsuccessful
15404 -1 if redisplay with same window start is known not to succeed
15406 The following steps are performed:
15408 1. Find the last row in the current matrix of W that is not
15409 affected by changes at the start of current_buffer. If no such row
15412 2. Find the first row in W's current matrix that is not affected by
15413 changes at the end of current_buffer. Maybe there is no such row.
15415 3. Display lines beginning with the row + 1 found in step 1 to the
15416 row found in step 2 or, if step 2 didn't find a row, to the end of
15419 4. If cursor is not known to appear on the window, give up.
15421 5. If display stopped at the row found in step 2, scroll the
15422 display and current matrix as needed.
15424 6. Maybe display some lines at the end of W, if we must. This can
15425 happen under various circumstances, like a partially visible line
15426 becoming fully visible, or because newly displayed lines are displayed
15427 in smaller font sizes.
15429 7. Update W's window end information. */
15435 struct frame
*f
= XFRAME (w
->frame
);
15436 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15437 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15438 struct glyph_row
*last_unchanged_at_beg_row
;
15439 struct glyph_row
*first_unchanged_at_end_row
;
15440 struct glyph_row
*row
;
15441 struct glyph_row
*bottom_row
;
15444 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
15445 struct text_pos start_pos
;
15447 int first_unchanged_at_end_vpos
= 0;
15448 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15449 struct text_pos start
;
15450 int first_changed_charpos
, last_changed_charpos
;
15453 if (inhibit_try_window_id
)
15457 /* This is handy for debugging. */
15459 #define GIVE_UP(X) \
15461 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15465 #define GIVE_UP(X) return 0
15468 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15470 /* Don't use this for mini-windows because these can show
15471 messages and mini-buffers, and we don't handle that here. */
15472 if (MINI_WINDOW_P (w
))
15475 /* This flag is used to prevent redisplay optimizations. */
15476 if (windows_or_buffers_changed
|| cursor_type_changed
)
15479 /* Verify that narrowing has not changed.
15480 Also verify that we were not told to prevent redisplay optimizations.
15481 It would be nice to further
15482 reduce the number of cases where this prevents try_window_id. */
15483 if (current_buffer
->clip_changed
15484 || current_buffer
->prevent_redisplay_optimizations_p
)
15487 /* Window must either use window-based redisplay or be full width. */
15488 if (!FRAME_WINDOW_P (f
)
15489 && (!FRAME_LINE_INS_DEL_OK (f
)
15490 || !WINDOW_FULL_WIDTH_P (w
)))
15493 /* Give up if point is known NOT to appear in W. */
15494 if (PT
< CHARPOS (start
))
15497 /* Another way to prevent redisplay optimizations. */
15498 if (XFASTINT (w
->last_modified
) == 0)
15501 /* Verify that window is not hscrolled. */
15502 if (XFASTINT (w
->hscroll
) != 0)
15505 /* Verify that display wasn't paused. */
15506 if (NILP (w
->window_end_valid
))
15509 /* Can't use this if highlighting a region because a cursor movement
15510 will do more than just set the cursor. */
15511 if (!NILP (Vtransient_mark_mode
)
15512 && !NILP (current_buffer
->mark_active
))
15515 /* Likewise if highlighting trailing whitespace. */
15516 if (!NILP (Vshow_trailing_whitespace
))
15519 /* Likewise if showing a region. */
15520 if (!NILP (w
->region_showing
))
15523 /* Can't use this if overlay arrow position and/or string have
15525 if (overlay_arrows_changed_p ())
15528 /* When word-wrap is on, adding a space to the first word of a
15529 wrapped line can change the wrap position, altering the line
15530 above it. It might be worthwhile to handle this more
15531 intelligently, but for now just redisplay from scratch. */
15532 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15535 /* Under bidi reordering, adding or deleting a character in the
15536 beginning of a paragraph, before the first strong directional
15537 character, can change the base direction of the paragraph (unless
15538 the buffer specifies a fixed paragraph direction), which will
15539 require to redisplay the whole paragraph. It might be worthwhile
15540 to find the paragraph limits and widen the range of redisplayed
15541 lines to that, but for now just give up this optimization and
15542 redisplay from scratch. */
15543 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15544 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15547 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15548 only if buffer has really changed. The reason is that the gap is
15549 initially at Z for freshly visited files. The code below would
15550 set end_unchanged to 0 in that case. */
15551 if (MODIFF
> SAVE_MODIFF
15552 /* This seems to happen sometimes after saving a buffer. */
15553 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15555 if (GPT
- BEG
< BEG_UNCHANGED
)
15556 BEG_UNCHANGED
= GPT
- BEG
;
15557 if (Z
- GPT
< END_UNCHANGED
)
15558 END_UNCHANGED
= Z
- GPT
;
15561 /* The position of the first and last character that has been changed. */
15562 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15563 last_changed_charpos
= Z
- END_UNCHANGED
;
15565 /* If window starts after a line end, and the last change is in
15566 front of that newline, then changes don't affect the display.
15567 This case happens with stealth-fontification. Note that although
15568 the display is unchanged, glyph positions in the matrix have to
15569 be adjusted, of course. */
15570 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15571 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15572 && ((last_changed_charpos
< CHARPOS (start
)
15573 && CHARPOS (start
) == BEGV
)
15574 || (last_changed_charpos
< CHARPOS (start
) - 1
15575 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15577 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15578 struct glyph_row
*r0
;
15580 /* Compute how many chars/bytes have been added to or removed
15581 from the buffer. */
15582 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15583 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15585 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15587 /* Give up if PT is not in the window. Note that it already has
15588 been checked at the start of try_window_id that PT is not in
15589 front of the window start. */
15590 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15593 /* If window start is unchanged, we can reuse the whole matrix
15594 as is, after adjusting glyph positions. No need to compute
15595 the window end again, since its offset from Z hasn't changed. */
15596 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15597 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15598 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15599 /* PT must not be in a partially visible line. */
15600 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15601 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15603 /* Adjust positions in the glyph matrix. */
15604 if (delta
|| delta_bytes
)
15606 struct glyph_row
*r1
15607 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15608 increment_matrix_positions (w
->current_matrix
,
15609 MATRIX_ROW_VPOS (r0
, current_matrix
),
15610 MATRIX_ROW_VPOS (r1
, current_matrix
),
15611 delta
, delta_bytes
);
15614 /* Set the cursor. */
15615 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15617 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15624 /* Handle the case that changes are all below what is displayed in
15625 the window, and that PT is in the window. This shortcut cannot
15626 be taken if ZV is visible in the window, and text has been added
15627 there that is visible in the window. */
15628 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15629 /* ZV is not visible in the window, or there are no
15630 changes at ZV, actually. */
15631 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15632 || first_changed_charpos
== last_changed_charpos
))
15634 struct glyph_row
*r0
;
15636 /* Give up if PT is not in the window. Note that it already has
15637 been checked at the start of try_window_id that PT is not in
15638 front of the window start. */
15639 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15642 /* If window start is unchanged, we can reuse the whole matrix
15643 as is, without changing glyph positions since no text has
15644 been added/removed in front of the window end. */
15645 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15646 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15647 /* PT must not be in a partially visible line. */
15648 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15649 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15651 /* We have to compute the window end anew since text
15652 can have been added/removed after it. */
15654 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15655 w
->window_end_bytepos
15656 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15658 /* Set the cursor. */
15659 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15661 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15668 /* Give up if window start is in the changed area.
15670 The condition used to read
15672 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15674 but why that was tested escapes me at the moment. */
15675 if (CHARPOS (start
) >= first_changed_charpos
15676 && CHARPOS (start
) <= last_changed_charpos
)
15679 /* Check that window start agrees with the start of the first glyph
15680 row in its current matrix. Check this after we know the window
15681 start is not in changed text, otherwise positions would not be
15683 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15684 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15687 /* Give up if the window ends in strings. Overlay strings
15688 at the end are difficult to handle, so don't try. */
15689 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15690 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15693 /* Compute the position at which we have to start displaying new
15694 lines. Some of the lines at the top of the window might be
15695 reusable because they are not displaying changed text. Find the
15696 last row in W's current matrix not affected by changes at the
15697 start of current_buffer. Value is null if changes start in the
15698 first line of window. */
15699 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15700 if (last_unchanged_at_beg_row
)
15702 /* Avoid starting to display in the moddle of a character, a TAB
15703 for instance. This is easier than to set up the iterator
15704 exactly, and it's not a frequent case, so the additional
15705 effort wouldn't really pay off. */
15706 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15707 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15708 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15709 --last_unchanged_at_beg_row
;
15711 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15714 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15716 start_pos
= it
.current
.pos
;
15718 /* Start displaying new lines in the desired matrix at the same
15719 vpos we would use in the current matrix, i.e. below
15720 last_unchanged_at_beg_row. */
15721 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15723 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15724 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15726 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15730 /* There are no reusable lines at the start of the window.
15731 Start displaying in the first text line. */
15732 start_display (&it
, w
, start
);
15733 it
.vpos
= it
.first_vpos
;
15734 start_pos
= it
.current
.pos
;
15737 /* Find the first row that is not affected by changes at the end of
15738 the buffer. Value will be null if there is no unchanged row, in
15739 which case we must redisplay to the end of the window. delta
15740 will be set to the value by which buffer positions beginning with
15741 first_unchanged_at_end_row have to be adjusted due to text
15743 first_unchanged_at_end_row
15744 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15745 IF_DEBUG (debug_delta
= delta
);
15746 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15748 /* Set stop_pos to the buffer position up to which we will have to
15749 display new lines. If first_unchanged_at_end_row != NULL, this
15750 is the buffer position of the start of the line displayed in that
15751 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15752 that we don't stop at a buffer position. */
15754 if (first_unchanged_at_end_row
)
15756 xassert (last_unchanged_at_beg_row
== NULL
15757 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15759 /* If this is a continuation line, move forward to the next one
15760 that isn't. Changes in lines above affect this line.
15761 Caution: this may move first_unchanged_at_end_row to a row
15762 not displaying text. */
15763 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15764 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15765 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15766 < it
.last_visible_y
))
15767 ++first_unchanged_at_end_row
;
15769 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15770 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15771 >= it
.last_visible_y
))
15772 first_unchanged_at_end_row
= NULL
;
15775 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15777 first_unchanged_at_end_vpos
15778 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15779 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15782 else if (last_unchanged_at_beg_row
== NULL
)
15788 /* Either there is no unchanged row at the end, or the one we have
15789 now displays text. This is a necessary condition for the window
15790 end pos calculation at the end of this function. */
15791 xassert (first_unchanged_at_end_row
== NULL
15792 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15794 debug_last_unchanged_at_beg_vpos
15795 = (last_unchanged_at_beg_row
15796 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15798 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15800 #endif /* GLYPH_DEBUG != 0 */
15803 /* Display new lines. Set last_text_row to the last new line
15804 displayed which has text on it, i.e. might end up as being the
15805 line where the window_end_vpos is. */
15806 w
->cursor
.vpos
= -1;
15807 last_text_row
= NULL
;
15808 overlay_arrow_seen
= 0;
15809 while (it
.current_y
< it
.last_visible_y
15810 && !fonts_changed_p
15811 && (first_unchanged_at_end_row
== NULL
15812 || IT_CHARPOS (it
) < stop_pos
))
15814 if (display_line (&it
))
15815 last_text_row
= it
.glyph_row
- 1;
15818 if (fonts_changed_p
)
15822 /* Compute differences in buffer positions, y-positions etc. for
15823 lines reused at the bottom of the window. Compute what we can
15825 if (first_unchanged_at_end_row
15826 /* No lines reused because we displayed everything up to the
15827 bottom of the window. */
15828 && it
.current_y
< it
.last_visible_y
)
15831 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15833 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15834 run
.current_y
= first_unchanged_at_end_row
->y
;
15835 run
.desired_y
= run
.current_y
+ dy
;
15836 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15840 delta
= delta_bytes
= dvpos
= dy
15841 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15842 first_unchanged_at_end_row
= NULL
;
15844 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15847 /* Find the cursor if not already found. We have to decide whether
15848 PT will appear on this window (it sometimes doesn't, but this is
15849 not a very frequent case.) This decision has to be made before
15850 the current matrix is altered. A value of cursor.vpos < 0 means
15851 that PT is either in one of the lines beginning at
15852 first_unchanged_at_end_row or below the window. Don't care for
15853 lines that might be displayed later at the window end; as
15854 mentioned, this is not a frequent case. */
15855 if (w
->cursor
.vpos
< 0)
15857 /* Cursor in unchanged rows at the top? */
15858 if (PT
< CHARPOS (start_pos
)
15859 && last_unchanged_at_beg_row
)
15861 row
= row_containing_pos (w
, PT
,
15862 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15863 last_unchanged_at_beg_row
+ 1, 0);
15865 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15868 /* Start from first_unchanged_at_end_row looking for PT. */
15869 else if (first_unchanged_at_end_row
)
15871 row
= row_containing_pos (w
, PT
- delta
,
15872 first_unchanged_at_end_row
, NULL
, 0);
15874 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15875 delta_bytes
, dy
, dvpos
);
15878 /* Give up if cursor was not found. */
15879 if (w
->cursor
.vpos
< 0)
15881 clear_glyph_matrix (w
->desired_matrix
);
15886 /* Don't let the cursor end in the scroll margins. */
15888 int this_scroll_margin
, cursor_height
;
15890 this_scroll_margin
= max (0, scroll_margin
);
15891 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15892 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15893 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15895 if ((w
->cursor
.y
< this_scroll_margin
15896 && CHARPOS (start
) > BEGV
)
15897 /* Old redisplay didn't take scroll margin into account at the bottom,
15898 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15899 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15900 ? cursor_height
+ this_scroll_margin
15901 : 1)) > it
.last_visible_y
)
15903 w
->cursor
.vpos
= -1;
15904 clear_glyph_matrix (w
->desired_matrix
);
15909 /* Scroll the display. Do it before changing the current matrix so
15910 that xterm.c doesn't get confused about where the cursor glyph is
15912 if (dy
&& run
.height
)
15916 if (FRAME_WINDOW_P (f
))
15918 FRAME_RIF (f
)->update_window_begin_hook (w
);
15919 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15920 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15921 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15925 /* Terminal frame. In this case, dvpos gives the number of
15926 lines to scroll by; dvpos < 0 means scroll up. */
15927 int first_unchanged_at_end_vpos
15928 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15929 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15930 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15931 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15932 + window_internal_height (w
));
15934 /* Perform the operation on the screen. */
15937 /* Scroll last_unchanged_at_beg_row to the end of the
15938 window down dvpos lines. */
15939 set_terminal_window (f
, end
);
15941 /* On dumb terminals delete dvpos lines at the end
15942 before inserting dvpos empty lines. */
15943 if (!FRAME_SCROLL_REGION_OK (f
))
15944 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15946 /* Insert dvpos empty lines in front of
15947 last_unchanged_at_beg_row. */
15948 ins_del_lines (f
, from
, dvpos
);
15950 else if (dvpos
< 0)
15952 /* Scroll up last_unchanged_at_beg_vpos to the end of
15953 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15954 set_terminal_window (f
, end
);
15956 /* Delete dvpos lines in front of
15957 last_unchanged_at_beg_vpos. ins_del_lines will set
15958 the cursor to the given vpos and emit |dvpos| delete
15960 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15962 /* On a dumb terminal insert dvpos empty lines at the
15964 if (!FRAME_SCROLL_REGION_OK (f
))
15965 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15968 set_terminal_window (f
, 0);
15974 /* Shift reused rows of the current matrix to the right position.
15975 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15977 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15978 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15981 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15982 bottom_vpos
, dvpos
);
15983 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15986 else if (dvpos
> 0)
15988 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15989 bottom_vpos
, dvpos
);
15990 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15991 first_unchanged_at_end_vpos
+ dvpos
, 0);
15994 /* For frame-based redisplay, make sure that current frame and window
15995 matrix are in sync with respect to glyph memory. */
15996 if (!FRAME_WINDOW_P (f
))
15997 sync_frame_with_window_matrix_rows (w
);
15999 /* Adjust buffer positions in reused rows. */
16000 if (delta
|| delta_bytes
)
16001 increment_matrix_positions (current_matrix
,
16002 first_unchanged_at_end_vpos
+ dvpos
,
16003 bottom_vpos
, delta
, delta_bytes
);
16005 /* Adjust Y positions. */
16007 shift_glyph_matrix (w
, current_matrix
,
16008 first_unchanged_at_end_vpos
+ dvpos
,
16011 if (first_unchanged_at_end_row
)
16013 first_unchanged_at_end_row
+= dvpos
;
16014 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16015 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16016 first_unchanged_at_end_row
= NULL
;
16019 /* If scrolling up, there may be some lines to display at the end of
16021 last_text_row_at_end
= NULL
;
16024 /* Scrolling up can leave for example a partially visible line
16025 at the end of the window to be redisplayed. */
16026 /* Set last_row to the glyph row in the current matrix where the
16027 window end line is found. It has been moved up or down in
16028 the matrix by dvpos. */
16029 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16030 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16032 /* If last_row is the window end line, it should display text. */
16033 xassert (last_row
->displays_text_p
);
16035 /* If window end line was partially visible before, begin
16036 displaying at that line. Otherwise begin displaying with the
16037 line following it. */
16038 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16040 init_to_row_start (&it
, w
, last_row
);
16041 it
.vpos
= last_vpos
;
16042 it
.current_y
= last_row
->y
;
16046 init_to_row_end (&it
, w
, last_row
);
16047 it
.vpos
= 1 + last_vpos
;
16048 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16052 /* We may start in a continuation line. If so, we have to
16053 get the right continuation_lines_width and current_x. */
16054 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16055 it
.hpos
= it
.current_x
= 0;
16057 /* Display the rest of the lines at the window end. */
16058 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16059 while (it
.current_y
< it
.last_visible_y
16060 && !fonts_changed_p
)
16062 /* Is it always sure that the display agrees with lines in
16063 the current matrix? I don't think so, so we mark rows
16064 displayed invalid in the current matrix by setting their
16065 enabled_p flag to zero. */
16066 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16067 if (display_line (&it
))
16068 last_text_row_at_end
= it
.glyph_row
- 1;
16072 /* Update window_end_pos and window_end_vpos. */
16073 if (first_unchanged_at_end_row
16074 && !last_text_row_at_end
)
16076 /* Window end line if one of the preserved rows from the current
16077 matrix. Set row to the last row displaying text in current
16078 matrix starting at first_unchanged_at_end_row, after
16080 xassert (first_unchanged_at_end_row
->displays_text_p
);
16081 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16082 first_unchanged_at_end_row
);
16083 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16085 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16086 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16088 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16089 xassert (w
->window_end_bytepos
>= 0);
16090 IF_DEBUG (debug_method_add (w
, "A"));
16092 else if (last_text_row_at_end
)
16095 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16096 w
->window_end_bytepos
16097 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16099 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16100 xassert (w
->window_end_bytepos
>= 0);
16101 IF_DEBUG (debug_method_add (w
, "B"));
16103 else if (last_text_row
)
16105 /* We have displayed either to the end of the window or at the
16106 end of the window, i.e. the last row with text is to be found
16107 in the desired matrix. */
16109 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16110 w
->window_end_bytepos
16111 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16113 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16114 xassert (w
->window_end_bytepos
>= 0);
16116 else if (first_unchanged_at_end_row
== NULL
16117 && last_text_row
== NULL
16118 && last_text_row_at_end
== NULL
)
16120 /* Displayed to end of window, but no line containing text was
16121 displayed. Lines were deleted at the end of the window. */
16122 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16123 int vpos
= XFASTINT (w
->window_end_vpos
);
16124 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16125 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16128 row
== NULL
&& vpos
>= first_vpos
;
16129 --vpos
, --current_row
, --desired_row
)
16131 if (desired_row
->enabled_p
)
16133 if (desired_row
->displays_text_p
)
16136 else if (current_row
->displays_text_p
)
16140 xassert (row
!= NULL
);
16141 w
->window_end_vpos
= make_number (vpos
+ 1);
16142 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16143 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16144 xassert (w
->window_end_bytepos
>= 0);
16145 IF_DEBUG (debug_method_add (w
, "C"));
16150 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16151 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16153 /* Record that display has not been completed. */
16154 w
->window_end_valid
= Qnil
;
16155 w
->desired_matrix
->no_scrolling_p
= 1;
16163 /***********************************************************************
16164 More debugging support
16165 ***********************************************************************/
16169 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
16170 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
16171 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
16174 /* Dump the contents of glyph matrix MATRIX on stderr.
16176 GLYPHS 0 means don't show glyph contents.
16177 GLYPHS 1 means show glyphs in short form
16178 GLYPHS > 1 means show glyphs in long form. */
16181 dump_glyph_matrix (matrix
, glyphs
)
16182 struct glyph_matrix
*matrix
;
16186 for (i
= 0; i
< matrix
->nrows
; ++i
)
16187 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16191 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16192 the glyph row and area where the glyph comes from. */
16195 dump_glyph (row
, glyph
, area
)
16196 struct glyph_row
*row
;
16197 struct glyph
*glyph
;
16200 if (glyph
->type
== CHAR_GLYPH
)
16203 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16204 glyph
- row
->glyphs
[TEXT_AREA
],
16207 (BUFFERP (glyph
->object
)
16209 : (STRINGP (glyph
->object
)
16212 glyph
->pixel_width
,
16214 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16218 glyph
->left_box_line_p
,
16219 glyph
->right_box_line_p
);
16221 else if (glyph
->type
== STRETCH_GLYPH
)
16224 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16225 glyph
- row
->glyphs
[TEXT_AREA
],
16228 (BUFFERP (glyph
->object
)
16230 : (STRINGP (glyph
->object
)
16233 glyph
->pixel_width
,
16237 glyph
->left_box_line_p
,
16238 glyph
->right_box_line_p
);
16240 else if (glyph
->type
== IMAGE_GLYPH
)
16243 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16244 glyph
- row
->glyphs
[TEXT_AREA
],
16247 (BUFFERP (glyph
->object
)
16249 : (STRINGP (glyph
->object
)
16252 glyph
->pixel_width
,
16256 glyph
->left_box_line_p
,
16257 glyph
->right_box_line_p
);
16259 else if (glyph
->type
== COMPOSITE_GLYPH
)
16262 " %5d %4c %6d %c %3d 0x%05x",
16263 glyph
- row
->glyphs
[TEXT_AREA
],
16266 (BUFFERP (glyph
->object
)
16268 : (STRINGP (glyph
->object
)
16271 glyph
->pixel_width
,
16273 if (glyph
->u
.cmp
.automatic
)
16276 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
16277 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16279 glyph
->left_box_line_p
,
16280 glyph
->right_box_line_p
);
16285 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16286 GLYPHS 0 means don't show glyph contents.
16287 GLYPHS 1 means show glyphs in short form
16288 GLYPHS > 1 means show glyphs in long form. */
16291 dump_glyph_row (row
, vpos
, glyphs
)
16292 struct glyph_row
*row
;
16297 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16298 fprintf (stderr
, "======================================================================\n");
16300 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16301 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16303 MATRIX_ROW_START_CHARPOS (row
),
16304 MATRIX_ROW_END_CHARPOS (row
),
16305 row
->used
[TEXT_AREA
],
16306 row
->contains_overlapping_glyphs_p
,
16308 row
->truncated_on_left_p
,
16309 row
->truncated_on_right_p
,
16311 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16312 row
->displays_text_p
,
16315 row
->ends_in_middle_of_char_p
,
16316 row
->starts_in_middle_of_char_p
,
16322 row
->visible_height
,
16325 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16326 row
->end
.overlay_string_index
,
16327 row
->continuation_lines_width
);
16328 fprintf (stderr
, "%9d %5d\n",
16329 CHARPOS (row
->start
.string_pos
),
16330 CHARPOS (row
->end
.string_pos
));
16331 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16332 row
->end
.dpvec_index
);
16339 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16341 struct glyph
*glyph
= row
->glyphs
[area
];
16342 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16344 /* Glyph for a line end in text. */
16345 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16348 if (glyph
< glyph_end
)
16349 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16351 for (; glyph
< glyph_end
; ++glyph
)
16352 dump_glyph (row
, glyph
, area
);
16355 else if (glyphs
== 1)
16359 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16361 char *s
= (char *) alloca (row
->used
[area
] + 1);
16364 for (i
= 0; i
< row
->used
[area
]; ++i
)
16366 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16367 if (glyph
->type
== CHAR_GLYPH
16368 && glyph
->u
.ch
< 0x80
16369 && glyph
->u
.ch
>= ' ')
16370 s
[i
] = glyph
->u
.ch
;
16376 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16382 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16383 Sdump_glyph_matrix
, 0, 1, "p",
16384 doc
: /* Dump the current matrix of the selected window to stderr.
16385 Shows contents of glyph row structures. With non-nil
16386 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16387 glyphs in short form, otherwise show glyphs in long form. */)
16389 Lisp_Object glyphs
;
16391 struct window
*w
= XWINDOW (selected_window
);
16392 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16394 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16395 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16396 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16397 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16398 fprintf (stderr
, "=============================================\n");
16399 dump_glyph_matrix (w
->current_matrix
,
16400 NILP (glyphs
) ? 0 : XINT (glyphs
));
16405 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16406 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16409 struct frame
*f
= XFRAME (selected_frame
);
16410 dump_glyph_matrix (f
->current_matrix
, 1);
16415 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16416 doc
: /* Dump glyph row ROW to stderr.
16417 GLYPH 0 means don't dump glyphs.
16418 GLYPH 1 means dump glyphs in short form.
16419 GLYPH > 1 or omitted means dump glyphs in long form. */)
16421 Lisp_Object row
, glyphs
;
16423 struct glyph_matrix
*matrix
;
16426 CHECK_NUMBER (row
);
16427 matrix
= XWINDOW (selected_window
)->current_matrix
;
16429 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16430 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16432 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16437 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16438 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16439 GLYPH 0 means don't dump glyphs.
16440 GLYPH 1 means dump glyphs in short form.
16441 GLYPH > 1 or omitted means dump glyphs in long form. */)
16443 Lisp_Object row
, glyphs
;
16445 struct frame
*sf
= SELECTED_FRAME ();
16446 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16449 CHECK_NUMBER (row
);
16451 if (vpos
>= 0 && vpos
< m
->nrows
)
16452 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16453 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16458 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16459 doc
: /* Toggle tracing of redisplay.
16460 With ARG, turn tracing on if and only if ARG is positive. */)
16465 trace_redisplay_p
= !trace_redisplay_p
;
16468 arg
= Fprefix_numeric_value (arg
);
16469 trace_redisplay_p
= XINT (arg
) > 0;
16476 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16477 doc
: /* Like `format', but print result to stderr.
16478 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16483 Lisp_Object s
= Fformat (nargs
, args
);
16484 fprintf (stderr
, "%s", SDATA (s
));
16488 #endif /* GLYPH_DEBUG */
16492 /***********************************************************************
16493 Building Desired Matrix Rows
16494 ***********************************************************************/
16496 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16497 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16499 static struct glyph_row
*
16500 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
16502 Lisp_Object overlay_arrow_string
;
16504 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16505 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16506 struct buffer
*old
= current_buffer
;
16507 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16508 int arrow_len
= SCHARS (overlay_arrow_string
);
16509 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16510 const unsigned char *p
;
16513 int n_glyphs_before
;
16515 set_buffer_temp (buffer
);
16516 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16517 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16518 SET_TEXT_POS (it
.position
, 0, 0);
16520 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16522 while (p
< arrow_end
)
16524 Lisp_Object face
, ilisp
;
16526 /* Get the next character. */
16528 it
.c
= string_char_and_length (p
, &it
.len
);
16530 it
.c
= *p
, it
.len
= 1;
16533 /* Get its face. */
16534 ilisp
= make_number (p
- arrow_string
);
16535 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16536 it
.face_id
= compute_char_face (f
, it
.c
, face
);
16538 /* Compute its width, get its glyphs. */
16539 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16540 SET_TEXT_POS (it
.position
, -1, -1);
16541 PRODUCE_GLYPHS (&it
);
16543 /* If this character doesn't fit any more in the line, we have
16544 to remove some glyphs. */
16545 if (it
.current_x
> it
.last_visible_x
)
16547 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16552 set_buffer_temp (old
);
16553 return it
.glyph_row
;
16557 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16558 glyphs are only inserted for terminal frames since we can't really
16559 win with truncation glyphs when partially visible glyphs are
16560 involved. Which glyphs to insert is determined by
16561 produce_special_glyphs. */
16564 insert_left_trunc_glyphs (it
)
16567 struct it truncate_it
;
16568 struct glyph
*from
, *end
, *to
, *toend
;
16570 xassert (!FRAME_WINDOW_P (it
->f
));
16572 /* Get the truncation glyphs. */
16574 truncate_it
.current_x
= 0;
16575 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16576 truncate_it
.glyph_row
= &scratch_glyph_row
;
16577 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16578 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16579 truncate_it
.object
= make_number (0);
16580 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16582 /* Overwrite glyphs from IT with truncation glyphs. */
16583 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16584 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16585 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16586 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16591 /* There may be padding glyphs left over. Overwrite them too. */
16592 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16594 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16600 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16604 /* Compute the pixel height and width of IT->glyph_row.
16606 Most of the time, ascent and height of a display line will be equal
16607 to the max_ascent and max_height values of the display iterator
16608 structure. This is not the case if
16610 1. We hit ZV without displaying anything. In this case, max_ascent
16611 and max_height will be zero.
16613 2. We have some glyphs that don't contribute to the line height.
16614 (The glyph row flag contributes_to_line_height_p is for future
16615 pixmap extensions).
16617 The first case is easily covered by using default values because in
16618 these cases, the line height does not really matter, except that it
16619 must not be zero. */
16622 compute_line_metrics (it
)
16625 struct glyph_row
*row
= it
->glyph_row
;
16628 if (FRAME_WINDOW_P (it
->f
))
16630 int i
, min_y
, max_y
;
16632 /* The line may consist of one space only, that was added to
16633 place the cursor on it. If so, the row's height hasn't been
16635 if (row
->height
== 0)
16637 if (it
->max_ascent
+ it
->max_descent
== 0)
16638 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16639 row
->ascent
= it
->max_ascent
;
16640 row
->height
= it
->max_ascent
+ it
->max_descent
;
16641 row
->phys_ascent
= it
->max_phys_ascent
;
16642 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16643 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16646 /* Compute the width of this line. */
16647 row
->pixel_width
= row
->x
;
16648 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16649 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16651 xassert (row
->pixel_width
>= 0);
16652 xassert (row
->ascent
>= 0 && row
->height
> 0);
16654 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16655 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16657 /* If first line's physical ascent is larger than its logical
16658 ascent, use the physical ascent, and make the row taller.
16659 This makes accented characters fully visible. */
16660 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16661 && row
->phys_ascent
> row
->ascent
)
16663 row
->height
+= row
->phys_ascent
- row
->ascent
;
16664 row
->ascent
= row
->phys_ascent
;
16667 /* Compute how much of the line is visible. */
16668 row
->visible_height
= row
->height
;
16670 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16671 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16673 if (row
->y
< min_y
)
16674 row
->visible_height
-= min_y
- row
->y
;
16675 if (row
->y
+ row
->height
> max_y
)
16676 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16680 row
->pixel_width
= row
->used
[TEXT_AREA
];
16681 if (row
->continued_p
)
16682 row
->pixel_width
-= it
->continuation_pixel_width
;
16683 else if (row
->truncated_on_right_p
)
16684 row
->pixel_width
-= it
->truncation_pixel_width
;
16685 row
->ascent
= row
->phys_ascent
= 0;
16686 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16687 row
->extra_line_spacing
= 0;
16690 /* Compute a hash code for this row. */
16692 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16693 for (i
= 0; i
< row
->used
[area
]; ++i
)
16694 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16695 + row
->glyphs
[area
][i
].u
.val
16696 + row
->glyphs
[area
][i
].face_id
16697 + row
->glyphs
[area
][i
].padding_p
16698 + (row
->glyphs
[area
][i
].type
<< 2));
16700 it
->max_ascent
= it
->max_descent
= 0;
16701 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16705 /* Append one space to the glyph row of iterator IT if doing a
16706 window-based redisplay. The space has the same face as
16707 IT->face_id. Value is non-zero if a space was added.
16709 This function is called to make sure that there is always one glyph
16710 at the end of a glyph row that the cursor can be set on under
16711 window-systems. (If there weren't such a glyph we would not know
16712 how wide and tall a box cursor should be displayed).
16714 At the same time this space let's a nicely handle clearing to the
16715 end of the line if the row ends in italic text. */
16718 append_space_for_newline (it
, default_face_p
)
16720 int default_face_p
;
16722 if (FRAME_WINDOW_P (it
->f
))
16724 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16726 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16727 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16729 /* Save some values that must not be changed.
16730 Must save IT->c and IT->len because otherwise
16731 ITERATOR_AT_END_P wouldn't work anymore after
16732 append_space_for_newline has been called. */
16733 enum display_element_type saved_what
= it
->what
;
16734 int saved_c
= it
->c
, saved_len
= it
->len
;
16735 int saved_x
= it
->current_x
;
16736 int saved_face_id
= it
->face_id
;
16737 struct text_pos saved_pos
;
16738 Lisp_Object saved_object
;
16741 saved_object
= it
->object
;
16742 saved_pos
= it
->position
;
16744 it
->what
= IT_CHARACTER
;
16745 bzero (&it
->position
, sizeof it
->position
);
16746 it
->object
= make_number (0);
16750 if (default_face_p
)
16751 it
->face_id
= DEFAULT_FACE_ID
;
16752 else if (it
->face_before_selective_p
)
16753 it
->face_id
= it
->saved_face_id
;
16754 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16755 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16757 PRODUCE_GLYPHS (it
);
16759 it
->override_ascent
= -1;
16760 it
->constrain_row_ascent_descent_p
= 0;
16761 it
->current_x
= saved_x
;
16762 it
->object
= saved_object
;
16763 it
->position
= saved_pos
;
16764 it
->what
= saved_what
;
16765 it
->face_id
= saved_face_id
;
16766 it
->len
= saved_len
;
16776 /* Extend the face of the last glyph in the text area of IT->glyph_row
16777 to the end of the display line. Called from display_line. If the
16778 glyph row is empty, add a space glyph to it so that we know the
16779 face to draw. Set the glyph row flag fill_line_p. If the glyph
16780 row is R2L, prepend a stretch glyph to cover the empty space to the
16781 left of the leftmost glyph. */
16784 extend_face_to_end_of_line (it
)
16788 struct frame
*f
= it
->f
;
16790 /* If line is already filled, do nothing. */
16791 if (it
->current_x
>= it
->last_visible_x
)
16794 /* Face extension extends the background and box of IT->face_id
16795 to the end of the line. If the background equals the background
16796 of the frame, we don't have to do anything. */
16797 if (it
->face_before_selective_p
)
16798 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
16800 face
= FACE_FROM_ID (f
, it
->face_id
);
16802 if (FRAME_WINDOW_P (f
)
16803 && it
->glyph_row
->displays_text_p
16804 && face
->box
== FACE_NO_BOX
16805 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16807 && !it
->glyph_row
->reversed_p
)
16810 /* Set the glyph row flag indicating that the face of the last glyph
16811 in the text area has to be drawn to the end of the text area. */
16812 it
->glyph_row
->fill_line_p
= 1;
16814 /* If current character of IT is not ASCII, make sure we have the
16815 ASCII face. This will be automatically undone the next time
16816 get_next_display_element returns a multibyte character. Note
16817 that the character will always be single byte in unibyte
16819 if (!ASCII_CHAR_P (it
->c
))
16821 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16824 if (FRAME_WINDOW_P (f
))
16826 /* If the row is empty, add a space with the current face of IT,
16827 so that we know which face to draw. */
16828 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16830 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16831 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16832 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16834 #ifdef HAVE_WINDOW_SYSTEM
16835 if (it
->glyph_row
->reversed_p
)
16837 /* Prepend a stretch glyph to the row, such that the
16838 rightmost glyph will be drawn flushed all the way to the
16839 right margin of the window. The stretch glyph that will
16840 occupy the empty space, if any, to the left of the
16842 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
16843 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16844 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
16846 int row_width
, stretch_ascent
, stretch_width
;
16847 struct text_pos saved_pos
;
16848 int saved_face_id
, saved_avoid_cursor
;
16850 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
16851 row_width
+= g
->pixel_width
;
16852 stretch_width
= WINDOW_BOX_RIGHT_EDGE_X(it
->w
)
16853 - WINDOW_BOX_LEFT_EDGE_X(it
->w
)
16854 - WINDOW_TOTAL_FRINGE_WIDTH(it
->w
)
16856 if (stretch_width
> 0)
16859 (((it
->ascent
+ it
->descent
)
16860 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
16861 saved_pos
= it
->position
;
16862 saved_avoid_cursor
= it
->avoid_cursor_p
;
16863 saved_face_id
= it
->face_id
;
16864 bzero (&it
->position
, sizeof it
->position
);
16865 it
->avoid_cursor_p
= 1;
16866 it
->face_id
= face
->id
;
16867 append_stretch_glyph (it
, make_number (0), stretch_width
,
16868 it
->ascent
+ it
->descent
, stretch_ascent
);
16869 it
->position
= saved_pos
;
16870 it
->avoid_cursor_p
= saved_avoid_cursor
;
16871 it
->face_id
= saved_face_id
;
16874 #endif /* HAVE_WINDOW_SYSTEM */
16878 /* Save some values that must not be changed. */
16879 int saved_x
= it
->current_x
;
16880 struct text_pos saved_pos
;
16881 Lisp_Object saved_object
;
16882 enum display_element_type saved_what
= it
->what
;
16883 int saved_face_id
= it
->face_id
;
16885 saved_object
= it
->object
;
16886 saved_pos
= it
->position
;
16888 it
->what
= IT_CHARACTER
;
16889 bzero (&it
->position
, sizeof it
->position
);
16890 it
->object
= make_number (0);
16893 it
->face_id
= face
->id
;
16895 PRODUCE_GLYPHS (it
);
16897 while (it
->current_x
<= it
->last_visible_x
)
16898 PRODUCE_GLYPHS (it
);
16900 /* Don't count these blanks really. It would let us insert a left
16901 truncation glyph below and make us set the cursor on them, maybe. */
16902 it
->current_x
= saved_x
;
16903 it
->object
= saved_object
;
16904 it
->position
= saved_pos
;
16905 it
->what
= saved_what
;
16906 it
->face_id
= saved_face_id
;
16911 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16912 trailing whitespace. */
16915 trailing_whitespace_p (charpos
)
16918 int bytepos
= CHAR_TO_BYTE (charpos
);
16921 while (bytepos
< ZV_BYTE
16922 && (c
= FETCH_CHAR (bytepos
),
16923 c
== ' ' || c
== '\t'))
16926 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16928 if (bytepos
!= PT_BYTE
)
16935 /* Highlight trailing whitespace, if any, in ROW. */
16938 highlight_trailing_whitespace (f
, row
)
16940 struct glyph_row
*row
;
16942 int used
= row
->used
[TEXT_AREA
];
16946 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16947 struct glyph
*glyph
= start
+ used
- 1;
16949 if (row
->reversed_p
)
16951 /* Right-to-left rows need to be processed in the opposite
16952 direction, so swap the edge pointers. */
16954 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
16957 /* Skip over glyphs inserted to display the cursor at the
16958 end of a line, for extending the face of the last glyph
16959 to the end of the line on terminals, and for truncation
16960 and continuation glyphs. */
16961 if (!row
->reversed_p
)
16963 while (glyph
>= start
16964 && glyph
->type
== CHAR_GLYPH
16965 && INTEGERP (glyph
->object
))
16970 while (glyph
<= start
16971 && glyph
->type
== CHAR_GLYPH
16972 && INTEGERP (glyph
->object
))
16976 /* If last glyph is a space or stretch, and it's trailing
16977 whitespace, set the face of all trailing whitespace glyphs in
16978 IT->glyph_row to `trailing-whitespace'. */
16979 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
16980 && BUFFERP (glyph
->object
)
16981 && (glyph
->type
== STRETCH_GLYPH
16982 || (glyph
->type
== CHAR_GLYPH
16983 && glyph
->u
.ch
== ' '))
16984 && trailing_whitespace_p (glyph
->charpos
))
16986 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16990 if (!row
->reversed_p
)
16992 while (glyph
>= start
16993 && BUFFERP (glyph
->object
)
16994 && (glyph
->type
== STRETCH_GLYPH
16995 || (glyph
->type
== CHAR_GLYPH
16996 && glyph
->u
.ch
== ' ')))
16997 (glyph
--)->face_id
= face_id
;
17001 while (glyph
<= start
17002 && BUFFERP (glyph
->object
)
17003 && (glyph
->type
== STRETCH_GLYPH
17004 || (glyph
->type
== CHAR_GLYPH
17005 && glyph
->u
.ch
== ' ')))
17006 (glyph
++)->face_id
= face_id
;
17013 /* Value is non-zero if glyph row ROW in window W should be
17014 used to hold the cursor. */
17017 cursor_row_p (w
, row
)
17019 struct glyph_row
*row
;
17021 int cursor_row_p
= 1;
17023 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
17025 /* Suppose the row ends on a string.
17026 Unless the row is continued, that means it ends on a newline
17027 in the string. If it's anything other than a display string
17028 (e.g. a before-string from an overlay), we don't want the
17029 cursor there. (This heuristic seems to give the optimal
17030 behavior for the various types of multi-line strings.) */
17031 if (CHARPOS (row
->end
.string_pos
) >= 0)
17033 if (row
->continued_p
)
17037 /* Check for `display' property. */
17038 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17039 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17040 struct glyph
*glyph
;
17043 for (glyph
= end
; glyph
>= beg
; --glyph
)
17044 if (STRINGP (glyph
->object
))
17047 = Fget_char_property (make_number (PT
),
17051 && display_prop_string_p (prop
, glyph
->object
));
17056 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17058 /* If the row ends in middle of a real character,
17059 and the line is continued, we want the cursor here.
17060 That's because MATRIX_ROW_END_CHARPOS would equal
17061 PT if PT is before the character. */
17062 if (!row
->ends_in_ellipsis_p
)
17063 cursor_row_p
= row
->continued_p
;
17065 /* If the row ends in an ellipsis, then
17066 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
17067 We want that position to be displayed after the ellipsis. */
17070 /* If the row ends at ZV, display the cursor at the end of that
17071 row instead of at the start of the row below. */
17072 else if (row
->ends_at_zv_p
)
17078 return cursor_row_p
;
17083 /* Push the display property PROP so that it will be rendered at the
17084 current position in IT. Return 1 if PROP was successfully pushed,
17088 push_display_prop (struct it
*it
, Lisp_Object prop
)
17092 if (STRINGP (prop
))
17094 if (SCHARS (prop
) == 0)
17101 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17102 it
->current
.overlay_string_index
= -1;
17103 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17104 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17105 it
->method
= GET_FROM_STRING
;
17106 it
->stop_charpos
= 0;
17108 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17110 it
->method
= GET_FROM_STRETCH
;
17113 #ifdef HAVE_WINDOW_SYSTEM
17114 else if (IMAGEP (prop
))
17116 it
->what
= IT_IMAGE
;
17117 it
->image_id
= lookup_image (it
->f
, prop
);
17118 it
->method
= GET_FROM_IMAGE
;
17120 #endif /* HAVE_WINDOW_SYSTEM */
17123 pop_it (it
); /* bogus display property, give up */
17130 /* Return the character-property PROP at the current position in IT. */
17133 get_it_property (it
, prop
)
17137 Lisp_Object position
;
17139 if (STRINGP (it
->object
))
17140 position
= make_number (IT_STRING_CHARPOS (*it
));
17141 else if (BUFFERP (it
->object
))
17142 position
= make_number (IT_CHARPOS (*it
));
17146 return Fget_char_property (position
, prop
, it
->object
);
17149 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17152 handle_line_prefix (struct it
*it
)
17154 Lisp_Object prefix
;
17155 if (it
->continuation_lines_width
> 0)
17157 prefix
= get_it_property (it
, Qwrap_prefix
);
17159 prefix
= Vwrap_prefix
;
17163 prefix
= get_it_property (it
, Qline_prefix
);
17165 prefix
= Vline_prefix
;
17167 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17169 /* If the prefix is wider than the window, and we try to wrap
17170 it, it would acquire its own wrap prefix, and so on till the
17171 iterator stack overflows. So, don't wrap the prefix. */
17172 it
->line_wrap
= TRUNCATE
;
17173 it
->avoid_cursor_p
= 1;
17179 /* Construct the glyph row IT->glyph_row in the desired matrix of
17180 IT->w from text at the current position of IT. See dispextern.h
17181 for an overview of struct it. Value is non-zero if
17182 IT->glyph_row displays text, as opposed to a line displaying ZV
17189 struct glyph_row
*row
= it
->glyph_row
;
17190 Lisp_Object overlay_arrow_string
;
17192 int may_wrap
= 0, wrap_x
;
17193 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
17194 int wrap_row_phys_ascent
, wrap_row_phys_height
;
17195 int wrap_row_extra_line_spacing
;
17196 struct display_pos row_end
;
17199 /* We always start displaying at hpos zero even if hscrolled. */
17200 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17202 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17203 >= it
->w
->desired_matrix
->nrows
)
17205 it
->w
->nrows_scale_factor
++;
17206 fonts_changed_p
= 1;
17210 /* Is IT->w showing the region? */
17211 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17213 /* Clear the result glyph row and enable it. */
17214 prepare_desired_row (row
);
17216 row
->y
= it
->current_y
;
17217 row
->start
= it
->start
;
17218 row
->continuation_lines_width
= it
->continuation_lines_width
;
17219 row
->displays_text_p
= 1;
17220 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17221 it
->starts_in_middle_of_char_p
= 0;
17223 /* Arrange the overlays nicely for our purposes. Usually, we call
17224 display_line on only one line at a time, in which case this
17225 can't really hurt too much, or we call it on lines which appear
17226 one after another in the buffer, in which case all calls to
17227 recenter_overlay_lists but the first will be pretty cheap. */
17228 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17230 /* Move over display elements that are not visible because we are
17231 hscrolled. This may stop at an x-position < IT->first_visible_x
17232 if the first glyph is partially visible or if we hit a line end. */
17233 if (it
->current_x
< it
->first_visible_x
)
17235 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17236 MOVE_TO_POS
| MOVE_TO_X
);
17240 /* We only do this when not calling `move_it_in_display_line_to'
17241 above, because move_it_in_display_line_to calls
17242 handle_line_prefix itself. */
17243 handle_line_prefix (it
);
17246 /* Get the initial row height. This is either the height of the
17247 text hscrolled, if there is any, or zero. */
17248 row
->ascent
= it
->max_ascent
;
17249 row
->height
= it
->max_ascent
+ it
->max_descent
;
17250 row
->phys_ascent
= it
->max_phys_ascent
;
17251 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17252 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17254 /* Loop generating characters. The loop is left with IT on the next
17255 character to display. */
17258 int n_glyphs_before
, hpos_before
, x_before
;
17260 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17262 /* Retrieve the next thing to display. Value is zero if end of
17264 if (!get_next_display_element (it
))
17266 /* Maybe add a space at the end of this line that is used to
17267 display the cursor there under X. Set the charpos of the
17268 first glyph of blank lines not corresponding to any text
17270 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17271 row
->exact_window_width_line_p
= 1;
17272 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17273 || row
->used
[TEXT_AREA
] == 0)
17275 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17276 row
->displays_text_p
= 0;
17278 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17279 && (!MINI_WINDOW_P (it
->w
)
17280 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17281 row
->indicate_empty_line_p
= 1;
17284 it
->continuation_lines_width
= 0;
17285 row
->ends_at_zv_p
= 1;
17286 /* A row that displays right-to-left text must always have
17287 its last face extended all the way to the end of line,
17288 even if this row ends in ZV. */
17289 if (row
->reversed_p
)
17290 extend_face_to_end_of_line (it
);
17294 /* Now, get the metrics of what we want to display. This also
17295 generates glyphs in `row' (which is IT->glyph_row). */
17296 n_glyphs_before
= row
->used
[TEXT_AREA
];
17299 /* Remember the line height so far in case the next element doesn't
17300 fit on the line. */
17301 if (it
->line_wrap
!= TRUNCATE
)
17303 ascent
= it
->max_ascent
;
17304 descent
= it
->max_descent
;
17305 phys_ascent
= it
->max_phys_ascent
;
17306 phys_descent
= it
->max_phys_descent
;
17308 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17310 if (IT_DISPLAYING_WHITESPACE (it
))
17316 wrap_row_used
= row
->used
[TEXT_AREA
];
17317 wrap_row_ascent
= row
->ascent
;
17318 wrap_row_height
= row
->height
;
17319 wrap_row_phys_ascent
= row
->phys_ascent
;
17320 wrap_row_phys_height
= row
->phys_height
;
17321 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17327 PRODUCE_GLYPHS (it
);
17329 /* If this display element was in marginal areas, continue with
17331 if (it
->area
!= TEXT_AREA
)
17333 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17334 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17335 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17336 row
->phys_height
= max (row
->phys_height
,
17337 it
->max_phys_ascent
+ it
->max_phys_descent
);
17338 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17339 it
->max_extra_line_spacing
);
17340 set_iterator_to_next (it
, 1);
17344 /* Does the display element fit on the line? If we truncate
17345 lines, we should draw past the right edge of the window. If
17346 we don't truncate, we want to stop so that we can display the
17347 continuation glyph before the right margin. If lines are
17348 continued, there are two possible strategies for characters
17349 resulting in more than 1 glyph (e.g. tabs): Display as many
17350 glyphs as possible in this line and leave the rest for the
17351 continuation line, or display the whole element in the next
17352 line. Original redisplay did the former, so we do it also. */
17353 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17354 hpos_before
= it
->hpos
;
17357 if (/* Not a newline. */
17359 /* Glyphs produced fit entirely in the line. */
17360 && it
->current_x
< it
->last_visible_x
)
17362 it
->hpos
+= nglyphs
;
17363 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17364 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17365 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17366 row
->phys_height
= max (row
->phys_height
,
17367 it
->max_phys_ascent
+ it
->max_phys_descent
);
17368 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17369 it
->max_extra_line_spacing
);
17370 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17371 row
->x
= x
- it
->first_visible_x
;
17376 struct glyph
*glyph
;
17378 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17380 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17381 new_x
= x
+ glyph
->pixel_width
;
17383 if (/* Lines are continued. */
17384 it
->line_wrap
!= TRUNCATE
17385 && (/* Glyph doesn't fit on the line. */
17386 new_x
> it
->last_visible_x
17387 /* Or it fits exactly on a window system frame. */
17388 || (new_x
== it
->last_visible_x
17389 && FRAME_WINDOW_P (it
->f
))))
17391 /* End of a continued line. */
17394 || (new_x
== it
->last_visible_x
17395 && FRAME_WINDOW_P (it
->f
)))
17397 /* Current glyph is the only one on the line or
17398 fits exactly on the line. We must continue
17399 the line because we can't draw the cursor
17400 after the glyph. */
17401 row
->continued_p
= 1;
17402 it
->current_x
= new_x
;
17403 it
->continuation_lines_width
+= new_x
;
17405 if (i
== nglyphs
- 1)
17407 /* If line-wrap is on, check if a previous
17408 wrap point was found. */
17409 if (wrap_row_used
> 0
17410 /* Even if there is a previous wrap
17411 point, continue the line here as
17412 usual, if (i) the previous character
17413 was a space or tab AND (ii) the
17414 current character is not. */
17416 || IT_DISPLAYING_WHITESPACE (it
)))
17419 set_iterator_to_next (it
, 1);
17420 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17422 if (!get_next_display_element (it
))
17424 row
->exact_window_width_line_p
= 1;
17425 it
->continuation_lines_width
= 0;
17426 row
->continued_p
= 0;
17427 row
->ends_at_zv_p
= 1;
17429 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17431 row
->continued_p
= 0;
17432 row
->exact_window_width_line_p
= 1;
17437 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17438 && !FRAME_WINDOW_P (it
->f
))
17440 /* A padding glyph that doesn't fit on this line.
17441 This means the whole character doesn't fit
17443 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17445 /* Fill the rest of the row with continuation
17446 glyphs like in 20.x. */
17447 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17448 < row
->glyphs
[1 + TEXT_AREA
])
17449 produce_special_glyphs (it
, IT_CONTINUATION
);
17451 row
->continued_p
= 1;
17452 it
->current_x
= x_before
;
17453 it
->continuation_lines_width
+= x_before
;
17455 /* Restore the height to what it was before the
17456 element not fitting on the line. */
17457 it
->max_ascent
= ascent
;
17458 it
->max_descent
= descent
;
17459 it
->max_phys_ascent
= phys_ascent
;
17460 it
->max_phys_descent
= phys_descent
;
17462 else if (wrap_row_used
> 0)
17466 it
->continuation_lines_width
+= wrap_x
;
17467 row
->used
[TEXT_AREA
] = wrap_row_used
;
17468 row
->ascent
= wrap_row_ascent
;
17469 row
->height
= wrap_row_height
;
17470 row
->phys_ascent
= wrap_row_phys_ascent
;
17471 row
->phys_height
= wrap_row_phys_height
;
17472 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17473 row
->continued_p
= 1;
17474 row
->ends_at_zv_p
= 0;
17475 row
->exact_window_width_line_p
= 0;
17476 it
->continuation_lines_width
+= x
;
17478 /* Make sure that a non-default face is extended
17479 up to the right margin of the window. */
17480 extend_face_to_end_of_line (it
);
17482 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17484 /* A TAB that extends past the right edge of the
17485 window. This produces a single glyph on
17486 window system frames. We leave the glyph in
17487 this row and let it fill the row, but don't
17488 consume the TAB. */
17489 it
->continuation_lines_width
+= it
->last_visible_x
;
17490 row
->ends_in_middle_of_char_p
= 1;
17491 row
->continued_p
= 1;
17492 glyph
->pixel_width
= it
->last_visible_x
- x
;
17493 it
->starts_in_middle_of_char_p
= 1;
17497 /* Something other than a TAB that draws past
17498 the right edge of the window. Restore
17499 positions to values before the element. */
17500 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17502 /* Display continuation glyphs. */
17503 if (!FRAME_WINDOW_P (it
->f
))
17504 produce_special_glyphs (it
, IT_CONTINUATION
);
17505 row
->continued_p
= 1;
17507 it
->current_x
= x_before
;
17508 it
->continuation_lines_width
+= x
;
17509 extend_face_to_end_of_line (it
);
17511 if (nglyphs
> 1 && i
> 0)
17513 row
->ends_in_middle_of_char_p
= 1;
17514 it
->starts_in_middle_of_char_p
= 1;
17517 /* Restore the height to what it was before the
17518 element not fitting on the line. */
17519 it
->max_ascent
= ascent
;
17520 it
->max_descent
= descent
;
17521 it
->max_phys_ascent
= phys_ascent
;
17522 it
->max_phys_descent
= phys_descent
;
17527 else if (new_x
> it
->first_visible_x
)
17529 /* Increment number of glyphs actually displayed. */
17532 if (x
< it
->first_visible_x
)
17533 /* Glyph is partially visible, i.e. row starts at
17534 negative X position. */
17535 row
->x
= x
- it
->first_visible_x
;
17539 /* Glyph is completely off the left margin of the
17540 window. This should not happen because of the
17541 move_it_in_display_line at the start of this
17542 function, unless the text display area of the
17543 window is empty. */
17544 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17548 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17549 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17550 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17551 row
->phys_height
= max (row
->phys_height
,
17552 it
->max_phys_ascent
+ it
->max_phys_descent
);
17553 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17554 it
->max_extra_line_spacing
);
17556 /* End of this display line if row is continued. */
17557 if (row
->continued_p
|| row
->ends_at_zv_p
)
17562 /* Is this a line end? If yes, we're also done, after making
17563 sure that a non-default face is extended up to the right
17564 margin of the window. */
17565 if (ITERATOR_AT_END_OF_LINE_P (it
))
17567 int used_before
= row
->used
[TEXT_AREA
];
17569 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17571 /* Add a space at the end of the line that is used to
17572 display the cursor there. */
17573 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17574 append_space_for_newline (it
, 0);
17576 /* Extend the face to the end of the line. */
17577 extend_face_to_end_of_line (it
);
17579 /* Make sure we have the position. */
17580 if (used_before
== 0)
17581 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17583 /* Consume the line end. This skips over invisible lines. */
17584 set_iterator_to_next (it
, 1);
17585 it
->continuation_lines_width
= 0;
17589 /* Proceed with next display element. Note that this skips
17590 over lines invisible because of selective display. */
17591 set_iterator_to_next (it
, 1);
17593 /* If we truncate lines, we are done when the last displayed
17594 glyphs reach past the right margin of the window. */
17595 if (it
->line_wrap
== TRUNCATE
17596 && (FRAME_WINDOW_P (it
->f
)
17597 ? (it
->current_x
>= it
->last_visible_x
)
17598 : (it
->current_x
> it
->last_visible_x
)))
17600 /* Maybe add truncation glyphs. */
17601 if (!FRAME_WINDOW_P (it
->f
))
17605 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17606 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17609 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17611 row
->used
[TEXT_AREA
] = i
;
17612 produce_special_glyphs (it
, IT_TRUNCATION
);
17615 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17617 /* Don't truncate if we can overflow newline into fringe. */
17618 if (!get_next_display_element (it
))
17620 it
->continuation_lines_width
= 0;
17621 row
->ends_at_zv_p
= 1;
17622 row
->exact_window_width_line_p
= 1;
17625 if (ITERATOR_AT_END_OF_LINE_P (it
))
17627 row
->exact_window_width_line_p
= 1;
17628 goto at_end_of_line
;
17632 row
->truncated_on_right_p
= 1;
17633 it
->continuation_lines_width
= 0;
17634 reseat_at_next_visible_line_start (it
, 0);
17635 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17636 it
->hpos
= hpos_before
;
17637 it
->current_x
= x_before
;
17642 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17643 at the left window margin. */
17644 if (it
->first_visible_x
17645 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
17647 if (!FRAME_WINDOW_P (it
->f
))
17648 insert_left_trunc_glyphs (it
);
17649 row
->truncated_on_left_p
= 1;
17652 /* If the start of this line is the overlay arrow-position, then
17653 mark this glyph row as the one containing the overlay arrow.
17654 This is clearly a mess with variable size fonts. It would be
17655 better to let it be displayed like cursors under X. */
17656 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17657 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17658 !NILP (overlay_arrow_string
)))
17660 /* Overlay arrow in window redisplay is a fringe bitmap. */
17661 if (STRINGP (overlay_arrow_string
))
17663 struct glyph_row
*arrow_row
17664 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17665 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17666 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17667 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17668 struct glyph
*p2
, *end
;
17670 /* Copy the arrow glyphs. */
17671 while (glyph
< arrow_end
)
17674 /* Throw away padding glyphs. */
17676 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17677 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17683 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17688 xassert (INTEGERP (overlay_arrow_string
));
17689 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17691 overlay_arrow_seen
= 1;
17694 /* Compute pixel dimensions of this line. */
17695 compute_line_metrics (it
);
17697 /* Remember the position at which this line ends. */
17698 row
->end
= row_end
= it
->current
;
17701 /* ROW->start and ROW->end must be the smallest and largest
17702 buffer positions in ROW. But if ROW was bidi-reordered,
17703 these two positions can be anywhere in the row, so we must
17704 rescan all of the ROW's glyphs to find them. */
17705 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17706 lines' rows is implemented for bidi-reordered rows. */
17707 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17710 struct text_pos tpos
;
17712 for (g
= row
->glyphs
[TEXT_AREA
];
17713 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17716 if (BUFFERP (g
->object
))
17718 if (g
->charpos
> 0 && g
->charpos
< min_pos
)
17719 min_pos
= g
->charpos
;
17720 if (g
->charpos
> max_pos
)
17721 max_pos
= g
->charpos
;
17724 /* Empty lines have a valid buffer position at their first
17725 glyph, but that glyph's OBJECT is zero, as if it didn't come
17726 from a buffer. If we didn't find any valid buffer positions
17727 in this row, maybe we have such an empty line. */
17728 if (min_pos
== ZV
+ 1 && row
->used
[TEXT_AREA
])
17730 for (g
= row
->glyphs
[TEXT_AREA
];
17731 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17734 if (INTEGERP (g
->object
))
17736 if (g
->charpos
> 0 && g
->charpos
< min_pos
)
17737 min_pos
= g
->charpos
;
17738 if (g
->charpos
> max_pos
)
17739 max_pos
= g
->charpos
;
17745 if (min_pos
!= row
->start
.pos
.charpos
)
17747 row
->start
.pos
.charpos
= min_pos
;
17748 row
->start
.pos
.bytepos
= CHAR_TO_BYTE (min_pos
);
17753 /* For ROW->end, we need the position that is _after_ max_pos,
17754 in the logical order, unless we are at ZV. */
17755 if (row
->ends_at_zv_p
)
17757 row_end
= row
->end
= it
->current
;
17758 if (!row
->used
[TEXT_AREA
])
17760 row
->start
.pos
.charpos
= row_end
.pos
.charpos
;
17761 row
->start
.pos
.bytepos
= row_end
.pos
.bytepos
;
17764 else if (row
->used
[TEXT_AREA
] && max_pos
)
17766 SET_TEXT_POS (tpos
, max_pos
+ 1, CHAR_TO_BYTE (max_pos
+ 1));
17767 row_end
= it
->current
;
17768 row_end
.pos
= tpos
;
17769 /* If the character at max_pos+1 is a newline, skip that as
17770 well. Note that this may skip some invisible text. */
17771 if (FETCH_CHAR (tpos
.bytepos
) == '\n'
17772 || (FETCH_CHAR (tpos
.bytepos
) == '\r' && it
->selective
))
17776 reseat_1 (it
, tpos
, 0);
17777 set_iterator_to_next (it
, 1);
17778 /* Record the position after the newline of a continued
17779 row. We will need that to set ROW->end of the last
17780 row produced for a continued line. */
17781 if (row
->continued_p
)
17783 save_it
.eol_pos
.charpos
= IT_CHARPOS (*it
);
17784 save_it
.eol_pos
.bytepos
= IT_BYTEPOS (*it
);
17788 row_end
= it
->current
;
17789 save_it
.eol_pos
.charpos
= save_it
.eol_pos
.bytepos
= 0;
17793 else if (!row
->continued_p
17794 && row
->continuation_lines_width
17795 && it
->eol_pos
.charpos
> 0)
17797 /* Last row of a continued line. Use the position
17798 recorded in ROW->eol_pos, to the effect that the
17799 newline belongs to this row, not to the row which
17800 displays the character with the largest buffer
17802 row_end
.pos
= it
->eol_pos
;
17803 it
->eol_pos
.charpos
= it
->eol_pos
.bytepos
= 0;
17805 row
->end
= row_end
;
17809 /* Record whether this row ends inside an ellipsis. */
17810 row
->ends_in_ellipsis_p
17811 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17812 && it
->ellipsis_p
);
17814 /* Save fringe bitmaps in this row. */
17815 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17816 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17817 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17818 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17820 it
->left_user_fringe_bitmap
= 0;
17821 it
->left_user_fringe_face_id
= 0;
17822 it
->right_user_fringe_bitmap
= 0;
17823 it
->right_user_fringe_face_id
= 0;
17825 /* Maybe set the cursor. */
17826 cvpos
= it
->w
->cursor
.vpos
;
17828 /* In bidi-reordered rows, keep checking for proper cursor
17829 position even if one has been found already, because buffer
17830 positions in such rows change non-linearly with ROW->VPOS,
17831 when a line is continued. One exception: when we are at ZV,
17832 display cursor on the first suitable glyph row, since all
17833 the empty rows after that also have their position set to ZV. */
17834 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17835 lines' rows is implemented for bidi-reordered rows. */
17837 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
17838 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17839 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17840 && cursor_row_p (it
->w
, row
))
17841 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17843 /* Highlight trailing whitespace. */
17844 if (!NILP (Vshow_trailing_whitespace
))
17845 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17847 /* Prepare for the next line. This line starts horizontally at (X
17848 HPOS) = (0 0). Vertical positions are incremented. As a
17849 convenience for the caller, IT->glyph_row is set to the next
17851 it
->current_x
= it
->hpos
= 0;
17852 it
->current_y
+= row
->height
;
17855 /* The next row should use same value of the reversed_p flag as this
17856 one. set_iterator_to_next decides when it's a new paragraph, and
17857 PRODUCE_GLYPHS recomputes the value of the flag accordingly. */
17858 it
->glyph_row
->reversed_p
= row
->reversed_p
;
17859 it
->start
= row_end
;
17860 return row
->displays_text_p
;
17865 /***********************************************************************
17867 ***********************************************************************/
17869 /* Redisplay the menu bar in the frame for window W.
17871 The menu bar of X frames that don't have X toolkit support is
17872 displayed in a special window W->frame->menu_bar_window.
17874 The menu bar of terminal frames is treated specially as far as
17875 glyph matrices are concerned. Menu bar lines are not part of
17876 windows, so the update is done directly on the frame matrix rows
17877 for the menu bar. */
17880 display_menu_bar (w
)
17883 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17888 /* Don't do all this for graphical frames. */
17890 if (FRAME_W32_P (f
))
17893 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17899 if (FRAME_NS_P (f
))
17901 #endif /* HAVE_NS */
17903 #ifdef USE_X_TOOLKIT
17904 xassert (!FRAME_WINDOW_P (f
));
17905 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17906 it
.first_visible_x
= 0;
17907 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17908 #else /* not USE_X_TOOLKIT */
17909 if (FRAME_WINDOW_P (f
))
17911 /* Menu bar lines are displayed in the desired matrix of the
17912 dummy window menu_bar_window. */
17913 struct window
*menu_w
;
17914 xassert (WINDOWP (f
->menu_bar_window
));
17915 menu_w
= XWINDOW (f
->menu_bar_window
);
17916 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17918 it
.first_visible_x
= 0;
17919 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17923 /* This is a TTY frame, i.e. character hpos/vpos are used as
17925 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17927 it
.first_visible_x
= 0;
17928 it
.last_visible_x
= FRAME_COLS (f
);
17930 #endif /* not USE_X_TOOLKIT */
17932 if (! mode_line_inverse_video
)
17933 /* Force the menu-bar to be displayed in the default face. */
17934 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17936 /* Clear all rows of the menu bar. */
17937 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17939 struct glyph_row
*row
= it
.glyph_row
+ i
;
17940 clear_glyph_row (row
);
17941 row
->enabled_p
= 1;
17942 row
->full_width_p
= 1;
17945 /* Display all items of the menu bar. */
17946 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17947 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17949 Lisp_Object string
;
17951 /* Stop at nil string. */
17952 string
= AREF (items
, i
+ 1);
17956 /* Remember where item was displayed. */
17957 ASET (items
, i
+ 3, make_number (it
.hpos
));
17959 /* Display the item, pad with one space. */
17960 if (it
.current_x
< it
.last_visible_x
)
17961 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17962 SCHARS (string
) + 1, 0, 0, -1);
17965 /* Fill out the line with spaces. */
17966 if (it
.current_x
< it
.last_visible_x
)
17967 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17969 /* Compute the total height of the lines. */
17970 compute_line_metrics (&it
);
17975 /***********************************************************************
17977 ***********************************************************************/
17979 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17980 FORCE is non-zero, redisplay mode lines unconditionally.
17981 Otherwise, redisplay only mode lines that are garbaged. Value is
17982 the number of windows whose mode lines were redisplayed. */
17985 redisplay_mode_lines (window
, force
)
17986 Lisp_Object window
;
17991 while (!NILP (window
))
17993 struct window
*w
= XWINDOW (window
);
17995 if (WINDOWP (w
->hchild
))
17996 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17997 else if (WINDOWP (w
->vchild
))
17998 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18000 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18001 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18003 struct text_pos lpoint
;
18004 struct buffer
*old
= current_buffer
;
18006 /* Set the window's buffer for the mode line display. */
18007 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18008 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18010 /* Point refers normally to the selected window. For any
18011 other window, set up appropriate value. */
18012 if (!EQ (window
, selected_window
))
18014 struct text_pos pt
;
18016 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18017 if (CHARPOS (pt
) < BEGV
)
18018 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18019 else if (CHARPOS (pt
) > (ZV
- 1))
18020 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18022 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18025 /* Display mode lines. */
18026 clear_glyph_matrix (w
->desired_matrix
);
18027 if (display_mode_lines (w
))
18030 w
->must_be_updated_p
= 1;
18033 /* Restore old settings. */
18034 set_buffer_internal_1 (old
);
18035 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18045 /* Display the mode and/or header line of window W. Value is the
18046 sum number of mode lines and header lines displayed. */
18049 display_mode_lines (w
)
18052 Lisp_Object old_selected_window
, old_selected_frame
;
18055 old_selected_frame
= selected_frame
;
18056 selected_frame
= w
->frame
;
18057 old_selected_window
= selected_window
;
18058 XSETWINDOW (selected_window
, w
);
18060 /* These will be set while the mode line specs are processed. */
18061 line_number_displayed
= 0;
18062 w
->column_number_displayed
= Qnil
;
18064 if (WINDOW_WANTS_MODELINE_P (w
))
18066 struct window
*sel_w
= XWINDOW (old_selected_window
);
18068 /* Select mode line face based on the real selected window. */
18069 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18070 current_buffer
->mode_line_format
);
18074 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18076 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18077 current_buffer
->header_line_format
);
18081 selected_frame
= old_selected_frame
;
18082 selected_window
= old_selected_window
;
18087 /* Display mode or header line of window W. FACE_ID specifies which
18088 line to display; it is either MODE_LINE_FACE_ID or
18089 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18090 display. Value is the pixel height of the mode/header line
18094 display_mode_line (w
, face_id
, format
)
18096 enum face_id face_id
;
18097 Lisp_Object format
;
18101 int count
= SPECPDL_INDEX ();
18103 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18104 /* Don't extend on a previously drawn mode-line.
18105 This may happen if called from pos_visible_p. */
18106 it
.glyph_row
->enabled_p
= 0;
18107 prepare_desired_row (it
.glyph_row
);
18109 it
.glyph_row
->mode_line_p
= 1;
18111 if (! mode_line_inverse_video
)
18112 /* Force the mode-line to be displayed in the default face. */
18113 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18115 record_unwind_protect (unwind_format_mode_line
,
18116 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18118 mode_line_target
= MODE_LINE_DISPLAY
;
18120 /* Temporarily make frame's keyboard the current kboard so that
18121 kboard-local variables in the mode_line_format will get the right
18123 push_kboard (FRAME_KBOARD (it
.f
));
18124 record_unwind_save_match_data ();
18125 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18128 unbind_to (count
, Qnil
);
18130 /* Fill up with spaces. */
18131 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18133 compute_line_metrics (&it
);
18134 it
.glyph_row
->full_width_p
= 1;
18135 it
.glyph_row
->continued_p
= 0;
18136 it
.glyph_row
->truncated_on_left_p
= 0;
18137 it
.glyph_row
->truncated_on_right_p
= 0;
18139 /* Make a 3D mode-line have a shadow at its right end. */
18140 face
= FACE_FROM_ID (it
.f
, face_id
);
18141 extend_face_to_end_of_line (&it
);
18142 if (face
->box
!= FACE_NO_BOX
)
18144 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18145 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18146 last
->right_box_line_p
= 1;
18149 return it
.glyph_row
->height
;
18152 /* Move element ELT in LIST to the front of LIST.
18153 Return the updated list. */
18156 move_elt_to_front (elt
, list
)
18157 Lisp_Object elt
, list
;
18159 register Lisp_Object tail
, prev
;
18160 register Lisp_Object tem
;
18164 while (CONSP (tail
))
18170 /* Splice out the link TAIL. */
18172 list
= XCDR (tail
);
18174 Fsetcdr (prev
, XCDR (tail
));
18176 /* Now make it the first. */
18177 Fsetcdr (tail
, list
);
18182 tail
= XCDR (tail
);
18186 /* Not found--return unchanged LIST. */
18190 /* Contribute ELT to the mode line for window IT->w. How it
18191 translates into text depends on its data type.
18193 IT describes the display environment in which we display, as usual.
18195 DEPTH is the depth in recursion. It is used to prevent
18196 infinite recursion here.
18198 FIELD_WIDTH is the number of characters the display of ELT should
18199 occupy in the mode line, and PRECISION is the maximum number of
18200 characters to display from ELT's representation. See
18201 display_string for details.
18203 Returns the hpos of the end of the text generated by ELT.
18205 PROPS is a property list to add to any string we encounter.
18207 If RISKY is nonzero, remove (disregard) any properties in any string
18208 we encounter, and ignore :eval and :propertize.
18210 The global variable `mode_line_target' determines whether the
18211 output is passed to `store_mode_line_noprop',
18212 `store_mode_line_string', or `display_string'. */
18215 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
18218 int field_width
, precision
;
18219 Lisp_Object elt
, props
;
18222 int n
= 0, field
, prec
;
18227 elt
= build_string ("*too-deep*");
18231 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18235 /* A string: output it and check for %-constructs within it. */
18239 if (SCHARS (elt
) > 0
18240 && (!NILP (props
) || risky
))
18242 Lisp_Object oprops
, aelt
;
18243 oprops
= Ftext_properties_at (make_number (0), elt
);
18245 /* If the starting string's properties are not what
18246 we want, translate the string. Also, if the string
18247 is risky, do that anyway. */
18249 if (NILP (Fequal (props
, oprops
)) || risky
)
18251 /* If the starting string has properties,
18252 merge the specified ones onto the existing ones. */
18253 if (! NILP (oprops
) && !risky
)
18257 oprops
= Fcopy_sequence (oprops
);
18259 while (CONSP (tem
))
18261 oprops
= Fplist_put (oprops
, XCAR (tem
),
18262 XCAR (XCDR (tem
)));
18263 tem
= XCDR (XCDR (tem
));
18268 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18269 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18271 /* AELT is what we want. Move it to the front
18272 without consing. */
18274 mode_line_proptrans_alist
18275 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18281 /* If AELT has the wrong props, it is useless.
18282 so get rid of it. */
18284 mode_line_proptrans_alist
18285 = Fdelq (aelt
, mode_line_proptrans_alist
);
18287 elt
= Fcopy_sequence (elt
);
18288 Fset_text_properties (make_number (0), Flength (elt
),
18290 /* Add this item to mode_line_proptrans_alist. */
18291 mode_line_proptrans_alist
18292 = Fcons (Fcons (elt
, props
),
18293 mode_line_proptrans_alist
);
18294 /* Truncate mode_line_proptrans_alist
18295 to at most 50 elements. */
18296 tem
= Fnthcdr (make_number (50),
18297 mode_line_proptrans_alist
);
18299 XSETCDR (tem
, Qnil
);
18308 prec
= precision
- n
;
18309 switch (mode_line_target
)
18311 case MODE_LINE_NOPROP
:
18312 case MODE_LINE_TITLE
:
18313 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
18315 case MODE_LINE_STRING
:
18316 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18318 case MODE_LINE_DISPLAY
:
18319 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18320 0, prec
, 0, STRING_MULTIBYTE (elt
));
18327 /* Handle the non-literal case. */
18329 while ((precision
<= 0 || n
< precision
)
18330 && SREF (elt
, offset
) != 0
18331 && (mode_line_target
!= MODE_LINE_DISPLAY
18332 || it
->current_x
< it
->last_visible_x
))
18334 int last_offset
= offset
;
18336 /* Advance to end of string or next format specifier. */
18337 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18340 if (offset
- 1 != last_offset
)
18342 int nchars
, nbytes
;
18344 /* Output to end of string or up to '%'. Field width
18345 is length of string. Don't output more than
18346 PRECISION allows us. */
18349 prec
= c_string_width (SDATA (elt
) + last_offset
,
18350 offset
- last_offset
, precision
- n
,
18353 switch (mode_line_target
)
18355 case MODE_LINE_NOPROP
:
18356 case MODE_LINE_TITLE
:
18357 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18359 case MODE_LINE_STRING
:
18361 int bytepos
= last_offset
;
18362 int charpos
= string_byte_to_char (elt
, bytepos
);
18363 int endpos
= (precision
<= 0
18364 ? string_byte_to_char (elt
, offset
)
18365 : charpos
+ nchars
);
18367 n
+= store_mode_line_string (NULL
,
18368 Fsubstring (elt
, make_number (charpos
),
18369 make_number (endpos
)),
18373 case MODE_LINE_DISPLAY
:
18375 int bytepos
= last_offset
;
18376 int charpos
= string_byte_to_char (elt
, bytepos
);
18378 if (precision
<= 0)
18379 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18380 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18382 STRING_MULTIBYTE (elt
));
18387 else /* c == '%' */
18389 int percent_position
= offset
;
18391 /* Get the specified minimum width. Zero means
18394 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18395 field
= field
* 10 + c
- '0';
18397 /* Don't pad beyond the total padding allowed. */
18398 if (field_width
- n
> 0 && field
> field_width
- n
)
18399 field
= field_width
- n
;
18401 /* Note that either PRECISION <= 0 or N < PRECISION. */
18402 prec
= precision
- n
;
18405 n
+= display_mode_element (it
, depth
, field
, prec
,
18406 Vglobal_mode_string
, props
,
18411 int bytepos
, charpos
;
18412 unsigned char *spec
;
18413 Lisp_Object string
;
18415 bytepos
= percent_position
;
18416 charpos
= (STRING_MULTIBYTE (elt
)
18417 ? string_byte_to_char (elt
, bytepos
)
18419 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
18420 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18422 switch (mode_line_target
)
18424 case MODE_LINE_NOPROP
:
18425 case MODE_LINE_TITLE
:
18426 n
+= store_mode_line_noprop (spec
, field
, prec
);
18428 case MODE_LINE_STRING
:
18430 int len
= strlen (spec
);
18431 Lisp_Object tem
= make_string (spec
, len
);
18432 props
= Ftext_properties_at (make_number (charpos
), elt
);
18433 /* Should only keep face property in props */
18434 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18437 case MODE_LINE_DISPLAY
:
18439 int nglyphs_before
, nwritten
;
18441 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18442 nwritten
= display_string (spec
, string
, elt
,
18447 /* Assign to the glyphs written above the
18448 string where the `%x' came from, position
18452 struct glyph
*glyph
18453 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18457 for (i
= 0; i
< nwritten
; ++i
)
18459 glyph
[i
].object
= elt
;
18460 glyph
[i
].charpos
= charpos
;
18477 /* A symbol: process the value of the symbol recursively
18478 as if it appeared here directly. Avoid error if symbol void.
18479 Special case: if value of symbol is a string, output the string
18482 register Lisp_Object tem
;
18484 /* If the variable is not marked as risky to set
18485 then its contents are risky to use. */
18486 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18489 tem
= Fboundp (elt
);
18492 tem
= Fsymbol_value (elt
);
18493 /* If value is a string, output that string literally:
18494 don't check for % within it. */
18498 if (!EQ (tem
, elt
))
18500 /* Give up right away for nil or t. */
18510 register Lisp_Object car
, tem
;
18512 /* A cons cell: five distinct cases.
18513 If first element is :eval or :propertize, do something special.
18514 If first element is a string or a cons, process all the elements
18515 and effectively concatenate them.
18516 If first element is a negative number, truncate displaying cdr to
18517 at most that many characters. If positive, pad (with spaces)
18518 to at least that many characters.
18519 If first element is a symbol, process the cadr or caddr recursively
18520 according to whether the symbol's value is non-nil or nil. */
18522 if (EQ (car
, QCeval
))
18524 /* An element of the form (:eval FORM) means evaluate FORM
18525 and use the result as mode line elements. */
18530 if (CONSP (XCDR (elt
)))
18533 spec
= safe_eval (XCAR (XCDR (elt
)));
18534 n
+= display_mode_element (it
, depth
, field_width
- n
,
18535 precision
- n
, spec
, props
,
18539 else if (EQ (car
, QCpropertize
))
18541 /* An element of the form (:propertize ELT PROPS...)
18542 means display ELT but applying properties PROPS. */
18547 if (CONSP (XCDR (elt
)))
18548 n
+= display_mode_element (it
, depth
, field_width
- n
,
18549 precision
- n
, XCAR (XCDR (elt
)),
18550 XCDR (XCDR (elt
)), risky
);
18552 else if (SYMBOLP (car
))
18554 tem
= Fboundp (car
);
18558 /* elt is now the cdr, and we know it is a cons cell.
18559 Use its car if CAR has a non-nil value. */
18562 tem
= Fsymbol_value (car
);
18569 /* Symbol's value is nil (or symbol is unbound)
18570 Get the cddr of the original list
18571 and if possible find the caddr and use that. */
18575 else if (!CONSP (elt
))
18580 else if (INTEGERP (car
))
18582 register int lim
= XINT (car
);
18586 /* Negative int means reduce maximum width. */
18587 if (precision
<= 0)
18590 precision
= min (precision
, -lim
);
18594 /* Padding specified. Don't let it be more than
18595 current maximum. */
18597 lim
= min (precision
, lim
);
18599 /* If that's more padding than already wanted, queue it.
18600 But don't reduce padding already specified even if
18601 that is beyond the current truncation point. */
18602 field_width
= max (lim
, field_width
);
18606 else if (STRINGP (car
) || CONSP (car
))
18608 Lisp_Object halftail
= elt
;
18612 && (precision
<= 0 || n
< precision
))
18614 n
+= display_mode_element (it
, depth
,
18615 /* Do padding only after the last
18616 element in the list. */
18617 (! CONSP (XCDR (elt
))
18620 precision
- n
, XCAR (elt
),
18624 if ((len
& 1) == 0)
18625 halftail
= XCDR (halftail
);
18626 /* Check for cycle. */
18627 if (EQ (halftail
, elt
))
18636 elt
= build_string ("*invalid*");
18640 /* Pad to FIELD_WIDTH. */
18641 if (field_width
> 0 && n
< field_width
)
18643 switch (mode_line_target
)
18645 case MODE_LINE_NOPROP
:
18646 case MODE_LINE_TITLE
:
18647 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18649 case MODE_LINE_STRING
:
18650 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18652 case MODE_LINE_DISPLAY
:
18653 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18662 /* Store a mode-line string element in mode_line_string_list.
18664 If STRING is non-null, display that C string. Otherwise, the Lisp
18665 string LISP_STRING is displayed.
18667 FIELD_WIDTH is the minimum number of output glyphs to produce.
18668 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18669 with spaces. FIELD_WIDTH <= 0 means don't pad.
18671 PRECISION is the maximum number of characters to output from
18672 STRING. PRECISION <= 0 means don't truncate the string.
18674 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18675 properties to the string.
18677 PROPS are the properties to add to the string.
18678 The mode_line_string_face face property is always added to the string.
18682 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
18684 Lisp_Object lisp_string
;
18693 if (string
!= NULL
)
18695 len
= strlen (string
);
18696 if (precision
> 0 && len
> precision
)
18698 lisp_string
= make_string (string
, len
);
18700 props
= mode_line_string_face_prop
;
18701 else if (!NILP (mode_line_string_face
))
18703 Lisp_Object face
= Fplist_get (props
, Qface
);
18704 props
= Fcopy_sequence (props
);
18706 face
= mode_line_string_face
;
18708 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18709 props
= Fplist_put (props
, Qface
, face
);
18711 Fadd_text_properties (make_number (0), make_number (len
),
18712 props
, lisp_string
);
18716 len
= XFASTINT (Flength (lisp_string
));
18717 if (precision
> 0 && len
> precision
)
18720 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
18723 if (!NILP (mode_line_string_face
))
18727 props
= Ftext_properties_at (make_number (0), lisp_string
);
18728 face
= Fplist_get (props
, Qface
);
18730 face
= mode_line_string_face
;
18732 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18733 props
= Fcons (Qface
, Fcons (face
, Qnil
));
18735 lisp_string
= Fcopy_sequence (lisp_string
);
18738 Fadd_text_properties (make_number (0), make_number (len
),
18739 props
, lisp_string
);
18744 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18748 if (field_width
> len
)
18750 field_width
-= len
;
18751 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
18753 Fadd_text_properties (make_number (0), make_number (field_width
),
18754 props
, lisp_string
);
18755 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18763 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
18765 doc
: /* Format a string out of a mode line format specification.
18766 First arg FORMAT specifies the mode line format (see `mode-line-format'
18767 for details) to use.
18769 Optional second arg FACE specifies the face property to put
18770 on all characters for which no face is specified.
18771 The value t means whatever face the window's mode line currently uses
18772 \(either `mode-line' or `mode-line-inactive', depending).
18773 A value of nil means the default is no face property.
18774 If FACE is an integer, the value string has no text properties.
18776 Optional third and fourth args WINDOW and BUFFER specify the window
18777 and buffer to use as the context for the formatting (defaults
18778 are the selected window and the window's buffer). */)
18779 (format
, face
, window
, buffer
)
18780 Lisp_Object format
, face
, window
, buffer
;
18785 struct buffer
*old_buffer
= NULL
;
18787 int no_props
= INTEGERP (face
);
18788 int count
= SPECPDL_INDEX ();
18790 int string_start
= 0;
18793 window
= selected_window
;
18794 CHECK_WINDOW (window
);
18795 w
= XWINDOW (window
);
18798 buffer
= w
->buffer
;
18799 CHECK_BUFFER (buffer
);
18801 /* Make formatting the modeline a non-op when noninteractive, otherwise
18802 there will be problems later caused by a partially initialized frame. */
18803 if (NILP (format
) || noninteractive
)
18804 return empty_unibyte_string
;
18812 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
18813 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
18817 face_id
= DEFAULT_FACE_ID
;
18819 if (XBUFFER (buffer
) != current_buffer
)
18820 old_buffer
= current_buffer
;
18822 /* Save things including mode_line_proptrans_alist,
18823 and set that to nil so that we don't alter the outer value. */
18824 record_unwind_protect (unwind_format_mode_line
,
18825 format_mode_line_unwind_data
18826 (old_buffer
, selected_window
, 1));
18827 mode_line_proptrans_alist
= Qnil
;
18829 Fselect_window (window
, Qt
);
18831 set_buffer_internal_1 (XBUFFER (buffer
));
18833 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18837 mode_line_target
= MODE_LINE_NOPROP
;
18838 mode_line_string_face_prop
= Qnil
;
18839 mode_line_string_list
= Qnil
;
18840 string_start
= MODE_LINE_NOPROP_LEN (0);
18844 mode_line_target
= MODE_LINE_STRING
;
18845 mode_line_string_list
= Qnil
;
18846 mode_line_string_face
= face
;
18847 mode_line_string_face_prop
18848 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18851 push_kboard (FRAME_KBOARD (it
.f
));
18852 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18857 len
= MODE_LINE_NOPROP_LEN (string_start
);
18858 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18862 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18863 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18864 empty_unibyte_string
);
18867 unbind_to (count
, Qnil
);
18871 /* Write a null-terminated, right justified decimal representation of
18872 the positive integer D to BUF using a minimal field width WIDTH. */
18875 pint2str (buf
, width
, d
)
18876 register char *buf
;
18877 register int width
;
18880 register char *p
= buf
;
18888 *p
++ = d
% 10 + '0';
18893 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18904 /* Write a null-terminated, right justified decimal and "human
18905 readable" representation of the nonnegative integer D to BUF using
18906 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18908 static const char power_letter
[] =
18922 pint2hrstr (buf
, width
, d
)
18927 /* We aim to represent the nonnegative integer D as
18928 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18931 /* -1 means: do not use TENTHS. */
18935 /* Length of QUOTIENT.TENTHS as a string. */
18941 if (1000 <= quotient
)
18943 /* Scale to the appropriate EXPONENT. */
18946 remainder
= quotient
% 1000;
18950 while (1000 <= quotient
);
18952 /* Round to nearest and decide whether to use TENTHS or not. */
18955 tenths
= remainder
/ 100;
18956 if (50 <= remainder
% 100)
18963 if (quotient
== 10)
18971 if (500 <= remainder
)
18973 if (quotient
< 999)
18984 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18985 if (tenths
== -1 && quotient
<= 99)
18992 p
= psuffix
= buf
+ max (width
, length
);
18994 /* Print EXPONENT. */
18996 *psuffix
++ = power_letter
[exponent
];
18999 /* Print TENTHS. */
19002 *--p
= '0' + tenths
;
19006 /* Print QUOTIENT. */
19009 int digit
= quotient
% 10;
19010 *--p
= '0' + digit
;
19012 while ((quotient
/= 10) != 0);
19014 /* Print leading spaces. */
19019 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19020 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19021 type of CODING_SYSTEM. Return updated pointer into BUF. */
19023 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19026 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
19027 Lisp_Object coding_system
;
19028 register char *buf
;
19032 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
19033 const unsigned char *eol_str
;
19035 /* The EOL conversion we are using. */
19036 Lisp_Object eoltype
;
19038 val
= CODING_SYSTEM_SPEC (coding_system
);
19041 if (!VECTORP (val
)) /* Not yet decided. */
19046 eoltype
= eol_mnemonic_undecided
;
19047 /* Don't mention EOL conversion if it isn't decided. */
19052 Lisp_Object eolvalue
;
19054 attrs
= AREF (val
, 0);
19055 eolvalue
= AREF (val
, 2);
19058 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19062 /* The EOL conversion that is normal on this system. */
19064 if (NILP (eolvalue
)) /* Not yet decided. */
19065 eoltype
= eol_mnemonic_undecided
;
19066 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19067 eoltype
= eol_mnemonic_undecided
;
19068 else /* eolvalue is Qunix, Qdos, or Qmac. */
19069 eoltype
= (EQ (eolvalue
, Qunix
)
19070 ? eol_mnemonic_unix
19071 : (EQ (eolvalue
, Qdos
) == 1
19072 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19078 /* Mention the EOL conversion if it is not the usual one. */
19079 if (STRINGP (eoltype
))
19081 eol_str
= SDATA (eoltype
);
19082 eol_str_len
= SBYTES (eoltype
);
19084 else if (CHARACTERP (eoltype
))
19086 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19087 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19092 eol_str
= invalid_eol_type
;
19093 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19095 bcopy (eol_str
, buf
, eol_str_len
);
19096 buf
+= eol_str_len
;
19102 /* Return a string for the output of a mode line %-spec for window W,
19103 generated by character C. PRECISION >= 0 means don't return a
19104 string longer than that value. FIELD_WIDTH > 0 means pad the
19105 string returned with spaces to that value. Return a Lisp string in
19106 *STRING if the resulting string is taken from that Lisp string.
19108 Note we operate on the current buffer for most purposes,
19109 the exception being w->base_line_pos. */
19111 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19114 decode_mode_spec (w
, c
, field_width
, precision
, string
)
19117 int field_width
, precision
;
19118 Lisp_Object
*string
;
19121 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19122 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19123 struct buffer
*b
= current_buffer
;
19131 if (!NILP (b
->read_only
))
19133 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19138 /* This differs from %* only for a modified read-only buffer. */
19139 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19141 if (!NILP (b
->read_only
))
19146 /* This differs from %* in ignoring read-only-ness. */
19147 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19159 if (command_loop_level
> 5)
19161 p
= decode_mode_spec_buf
;
19162 for (i
= 0; i
< command_loop_level
; i
++)
19165 return decode_mode_spec_buf
;
19173 if (command_loop_level
> 5)
19175 p
= decode_mode_spec_buf
;
19176 for (i
= 0; i
< command_loop_level
; i
++)
19179 return decode_mode_spec_buf
;
19186 /* Let lots_of_dashes be a string of infinite length. */
19187 if (mode_line_target
== MODE_LINE_NOPROP
||
19188 mode_line_target
== MODE_LINE_STRING
)
19190 if (field_width
<= 0
19191 || field_width
> sizeof (lots_of_dashes
))
19193 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19194 decode_mode_spec_buf
[i
] = '-';
19195 decode_mode_spec_buf
[i
] = '\0';
19196 return decode_mode_spec_buf
;
19199 return lots_of_dashes
;
19207 /* %c and %l are ignored in `frame-title-format'.
19208 (In redisplay_internal, the frame title is drawn _before_ the
19209 windows are updated, so the stuff which depends on actual
19210 window contents (such as %l) may fail to render properly, or
19211 even crash emacs.) */
19212 if (mode_line_target
== MODE_LINE_TITLE
)
19216 int col
= (int) current_column (); /* iftc */
19217 w
->column_number_displayed
= make_number (col
);
19218 pint2str (decode_mode_spec_buf
, field_width
, col
);
19219 return decode_mode_spec_buf
;
19223 #ifndef SYSTEM_MALLOC
19225 if (NILP (Vmemory_full
))
19228 return "!MEM FULL! ";
19235 /* %F displays the frame name. */
19236 if (!NILP (f
->title
))
19237 return (char *) SDATA (f
->title
);
19238 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19239 return (char *) SDATA (f
->name
);
19248 int size
= ZV
- BEGV
;
19249 pint2str (decode_mode_spec_buf
, field_width
, size
);
19250 return decode_mode_spec_buf
;
19255 int size
= ZV
- BEGV
;
19256 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19257 return decode_mode_spec_buf
;
19262 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19263 int topline
, nlines
, junk
, height
;
19265 /* %c and %l are ignored in `frame-title-format'. */
19266 if (mode_line_target
== MODE_LINE_TITLE
)
19269 startpos
= XMARKER (w
->start
)->charpos
;
19270 startpos_byte
= marker_byte_position (w
->start
);
19271 height
= WINDOW_TOTAL_LINES (w
);
19273 /* If we decided that this buffer isn't suitable for line numbers,
19274 don't forget that too fast. */
19275 if (EQ (w
->base_line_pos
, w
->buffer
))
19277 /* But do forget it, if the window shows a different buffer now. */
19278 else if (BUFFERP (w
->base_line_pos
))
19279 w
->base_line_pos
= Qnil
;
19281 /* If the buffer is very big, don't waste time. */
19282 if (INTEGERP (Vline_number_display_limit
)
19283 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19285 w
->base_line_pos
= Qnil
;
19286 w
->base_line_number
= Qnil
;
19290 if (INTEGERP (w
->base_line_number
)
19291 && INTEGERP (w
->base_line_pos
)
19292 && XFASTINT (w
->base_line_pos
) <= startpos
)
19294 line
= XFASTINT (w
->base_line_number
);
19295 linepos
= XFASTINT (w
->base_line_pos
);
19296 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19301 linepos
= BUF_BEGV (b
);
19302 linepos_byte
= BUF_BEGV_BYTE (b
);
19305 /* Count lines from base line to window start position. */
19306 nlines
= display_count_lines (linepos
, linepos_byte
,
19310 topline
= nlines
+ line
;
19312 /* Determine a new base line, if the old one is too close
19313 or too far away, or if we did not have one.
19314 "Too close" means it's plausible a scroll-down would
19315 go back past it. */
19316 if (startpos
== BUF_BEGV (b
))
19318 w
->base_line_number
= make_number (topline
);
19319 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19321 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19322 || linepos
== BUF_BEGV (b
))
19324 int limit
= BUF_BEGV (b
);
19325 int limit_byte
= BUF_BEGV_BYTE (b
);
19327 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
19329 if (startpos
- distance
> limit
)
19331 limit
= startpos
- distance
;
19332 limit_byte
= CHAR_TO_BYTE (limit
);
19335 nlines
= display_count_lines (startpos
, startpos_byte
,
19337 - (height
* 2 + 30),
19339 /* If we couldn't find the lines we wanted within
19340 line_number_display_limit_width chars per line,
19341 give up on line numbers for this window. */
19342 if (position
== limit_byte
&& limit
== startpos
- distance
)
19344 w
->base_line_pos
= w
->buffer
;
19345 w
->base_line_number
= Qnil
;
19349 w
->base_line_number
= make_number (topline
- nlines
);
19350 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19353 /* Now count lines from the start pos to point. */
19354 nlines
= display_count_lines (startpos
, startpos_byte
,
19355 PT_BYTE
, PT
, &junk
);
19357 /* Record that we did display the line number. */
19358 line_number_displayed
= 1;
19360 /* Make the string to show. */
19361 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19362 return decode_mode_spec_buf
;
19365 char* p
= decode_mode_spec_buf
;
19366 int pad
= field_width
- 2;
19372 return decode_mode_spec_buf
;
19378 obj
= b
->mode_name
;
19382 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19388 int pos
= marker_position (w
->start
);
19389 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19391 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19393 if (pos
<= BUF_BEGV (b
))
19398 else if (pos
<= BUF_BEGV (b
))
19402 if (total
> 1000000)
19403 /* Do it differently for a large value, to avoid overflow. */
19404 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19406 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19407 /* We can't normally display a 3-digit number,
19408 so get us a 2-digit number that is close. */
19411 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19412 return decode_mode_spec_buf
;
19416 /* Display percentage of size above the bottom of the screen. */
19419 int toppos
= marker_position (w
->start
);
19420 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19421 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19423 if (botpos
>= BUF_ZV (b
))
19425 if (toppos
<= BUF_BEGV (b
))
19432 if (total
> 1000000)
19433 /* Do it differently for a large value, to avoid overflow. */
19434 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19436 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19437 /* We can't normally display a 3-digit number,
19438 so get us a 2-digit number that is close. */
19441 if (toppos
<= BUF_BEGV (b
))
19442 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
19444 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19445 return decode_mode_spec_buf
;
19450 /* status of process */
19451 obj
= Fget_buffer_process (Fcurrent_buffer ());
19453 return "no process";
19454 #ifdef subprocesses
19455 obj
= Fsymbol_name (Fprocess_status (obj
));
19461 int count
= inhibit_garbage_collection ();
19462 Lisp_Object val
= call1 (intern ("file-remote-p"),
19463 current_buffer
->directory
);
19464 unbind_to (count
, Qnil
);
19472 case 't': /* indicate TEXT or BINARY */
19473 #ifdef MODE_LINE_BINARY_TEXT
19474 return MODE_LINE_BINARY_TEXT (b
);
19480 /* coding-system (not including end-of-line format) */
19482 /* coding-system (including end-of-line type) */
19484 int eol_flag
= (c
== 'Z');
19485 char *p
= decode_mode_spec_buf
;
19487 if (! FRAME_WINDOW_P (f
))
19489 /* No need to mention EOL here--the terminal never needs
19490 to do EOL conversion. */
19491 p
= decode_mode_spec_coding (CODING_ID_NAME
19492 (FRAME_KEYBOARD_CODING (f
)->id
),
19494 p
= decode_mode_spec_coding (CODING_ID_NAME
19495 (FRAME_TERMINAL_CODING (f
)->id
),
19498 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19501 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19502 #ifdef subprocesses
19503 obj
= Fget_buffer_process (Fcurrent_buffer ());
19504 if (PROCESSP (obj
))
19506 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19508 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19511 #endif /* subprocesses */
19514 return decode_mode_spec_buf
;
19521 return (char *) SDATA (obj
);
19528 /* Count up to COUNT lines starting from START / START_BYTE.
19529 But don't go beyond LIMIT_BYTE.
19530 Return the number of lines thus found (always nonnegative).
19532 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19535 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
19536 int start
, start_byte
, limit_byte
, count
;
19539 register unsigned char *cursor
;
19540 unsigned char *base
;
19542 register int ceiling
;
19543 register unsigned char *ceiling_addr
;
19544 int orig_count
= count
;
19546 /* If we are not in selective display mode,
19547 check only for newlines. */
19548 int selective_display
= (!NILP (current_buffer
->selective_display
)
19549 && !INTEGERP (current_buffer
->selective_display
));
19553 while (start_byte
< limit_byte
)
19555 ceiling
= BUFFER_CEILING_OF (start_byte
);
19556 ceiling
= min (limit_byte
- 1, ceiling
);
19557 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19558 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19561 if (selective_display
)
19562 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19565 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19568 if (cursor
!= ceiling_addr
)
19572 start_byte
+= cursor
- base
+ 1;
19573 *byte_pos_ptr
= start_byte
;
19577 if (++cursor
== ceiling_addr
)
19583 start_byte
+= cursor
- base
;
19588 while (start_byte
> limit_byte
)
19590 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19591 ceiling
= max (limit_byte
, ceiling
);
19592 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19593 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19596 if (selective_display
)
19597 while (--cursor
!= ceiling_addr
19598 && *cursor
!= '\n' && *cursor
!= 015)
19601 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19604 if (cursor
!= ceiling_addr
)
19608 start_byte
+= cursor
- base
+ 1;
19609 *byte_pos_ptr
= start_byte
;
19610 /* When scanning backwards, we should
19611 not count the newline posterior to which we stop. */
19612 return - orig_count
- 1;
19618 /* Here we add 1 to compensate for the last decrement
19619 of CURSOR, which took it past the valid range. */
19620 start_byte
+= cursor
- base
+ 1;
19624 *byte_pos_ptr
= limit_byte
;
19627 return - orig_count
+ count
;
19628 return orig_count
- count
;
19634 /***********************************************************************
19636 ***********************************************************************/
19638 /* Display a NUL-terminated string, starting with index START.
19640 If STRING is non-null, display that C string. Otherwise, the Lisp
19641 string LISP_STRING is displayed. There's a case that STRING is
19642 non-null and LISP_STRING is not nil. It means STRING is a string
19643 data of LISP_STRING. In that case, we display LISP_STRING while
19644 ignoring its text properties.
19646 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19647 FACE_STRING. Display STRING or LISP_STRING with the face at
19648 FACE_STRING_POS in FACE_STRING:
19650 Display the string in the environment given by IT, but use the
19651 standard display table, temporarily.
19653 FIELD_WIDTH is the minimum number of output glyphs to produce.
19654 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19655 with spaces. If STRING has more characters, more than FIELD_WIDTH
19656 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19658 PRECISION is the maximum number of characters to output from
19659 STRING. PRECISION < 0 means don't truncate the string.
19661 This is roughly equivalent to printf format specifiers:
19663 FIELD_WIDTH PRECISION PRINTF
19664 ----------------------------------------
19670 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19671 display them, and < 0 means obey the current buffer's value of
19672 enable_multibyte_characters.
19674 Value is the number of columns displayed. */
19677 display_string (string
, lisp_string
, face_string
, face_string_pos
,
19678 start
, it
, field_width
, precision
, max_x
, multibyte
)
19679 unsigned char *string
;
19680 Lisp_Object lisp_string
;
19681 Lisp_Object face_string
;
19682 EMACS_INT face_string_pos
;
19685 int field_width
, precision
, max_x
;
19688 int hpos_at_start
= it
->hpos
;
19689 int saved_face_id
= it
->face_id
;
19690 struct glyph_row
*row
= it
->glyph_row
;
19692 /* Initialize the iterator IT for iteration over STRING beginning
19693 with index START. */
19694 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19695 precision
, field_width
, multibyte
);
19696 if (string
&& STRINGP (lisp_string
))
19697 /* LISP_STRING is the one returned by decode_mode_spec. We should
19698 ignore its text properties. */
19699 it
->stop_charpos
= -1;
19701 /* If displaying STRING, set up the face of the iterator
19702 from LISP_STRING, if that's given. */
19703 if (STRINGP (face_string
))
19709 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19710 0, it
->region_beg_charpos
,
19711 it
->region_end_charpos
,
19712 &endptr
, it
->base_face_id
, 0);
19713 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19714 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19717 /* Set max_x to the maximum allowed X position. Don't let it go
19718 beyond the right edge of the window. */
19720 max_x
= it
->last_visible_x
;
19722 max_x
= min (max_x
, it
->last_visible_x
);
19724 /* Skip over display elements that are not visible. because IT->w is
19726 if (it
->current_x
< it
->first_visible_x
)
19727 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
19728 MOVE_TO_POS
| MOVE_TO_X
);
19730 row
->ascent
= it
->max_ascent
;
19731 row
->height
= it
->max_ascent
+ it
->max_descent
;
19732 row
->phys_ascent
= it
->max_phys_ascent
;
19733 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19734 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19736 /* This condition is for the case that we are called with current_x
19737 past last_visible_x. */
19738 while (it
->current_x
< max_x
)
19740 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
19742 /* Get the next display element. */
19743 if (!get_next_display_element (it
))
19746 /* Produce glyphs. */
19747 x_before
= it
->current_x
;
19748 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19749 PRODUCE_GLYPHS (it
);
19751 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
19754 while (i
< nglyphs
)
19756 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19758 if (it
->line_wrap
!= TRUNCATE
19759 && x
+ glyph
->pixel_width
> max_x
)
19761 /* End of continued line or max_x reached. */
19762 if (CHAR_GLYPH_PADDING_P (*glyph
))
19764 /* A wide character is unbreakable. */
19765 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19766 it
->current_x
= x_before
;
19770 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19775 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
19777 /* Glyph is at least partially visible. */
19779 if (x
< it
->first_visible_x
)
19780 it
->glyph_row
->x
= x
- it
->first_visible_x
;
19784 /* Glyph is off the left margin of the display area.
19785 Should not happen. */
19789 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19790 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19791 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19792 row
->phys_height
= max (row
->phys_height
,
19793 it
->max_phys_ascent
+ it
->max_phys_descent
);
19794 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19795 it
->max_extra_line_spacing
);
19796 x
+= glyph
->pixel_width
;
19800 /* Stop if max_x reached. */
19804 /* Stop at line ends. */
19805 if (ITERATOR_AT_END_OF_LINE_P (it
))
19807 it
->continuation_lines_width
= 0;
19811 set_iterator_to_next (it
, 1);
19813 /* Stop if truncating at the right edge. */
19814 if (it
->line_wrap
== TRUNCATE
19815 && it
->current_x
>= it
->last_visible_x
)
19817 /* Add truncation mark, but don't do it if the line is
19818 truncated at a padding space. */
19819 if (IT_CHARPOS (*it
) < it
->string_nchars
)
19821 if (!FRAME_WINDOW_P (it
->f
))
19825 if (it
->current_x
> it
->last_visible_x
)
19827 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19828 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19830 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19832 row
->used
[TEXT_AREA
] = i
;
19833 produce_special_glyphs (it
, IT_TRUNCATION
);
19836 produce_special_glyphs (it
, IT_TRUNCATION
);
19838 it
->glyph_row
->truncated_on_right_p
= 1;
19844 /* Maybe insert a truncation at the left. */
19845 if (it
->first_visible_x
19846 && IT_CHARPOS (*it
) > 0)
19848 if (!FRAME_WINDOW_P (it
->f
))
19849 insert_left_trunc_glyphs (it
);
19850 it
->glyph_row
->truncated_on_left_p
= 1;
19853 it
->face_id
= saved_face_id
;
19855 /* Value is number of columns displayed. */
19856 return it
->hpos
- hpos_at_start
;
19861 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19862 appears as an element of LIST or as the car of an element of LIST.
19863 If PROPVAL is a list, compare each element against LIST in that
19864 way, and return 1/2 if any element of PROPVAL is found in LIST.
19865 Otherwise return 0. This function cannot quit.
19866 The return value is 2 if the text is invisible but with an ellipsis
19867 and 1 if it's invisible and without an ellipsis. */
19870 invisible_p (propval
, list
)
19871 register Lisp_Object propval
;
19874 register Lisp_Object tail
, proptail
;
19876 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19878 register Lisp_Object tem
;
19880 if (EQ (propval
, tem
))
19882 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19883 return NILP (XCDR (tem
)) ? 1 : 2;
19886 if (CONSP (propval
))
19888 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19890 Lisp_Object propelt
;
19891 propelt
= XCAR (proptail
);
19892 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19894 register Lisp_Object tem
;
19896 if (EQ (propelt
, tem
))
19898 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19899 return NILP (XCDR (tem
)) ? 1 : 2;
19907 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19908 doc
: /* Non-nil if the property makes the text invisible.
19909 POS-OR-PROP can be a marker or number, in which case it is taken to be
19910 a position in the current buffer and the value of the `invisible' property
19911 is checked; or it can be some other value, which is then presumed to be the
19912 value of the `invisible' property of the text of interest.
19913 The non-nil value returned can be t for truly invisible text or something
19914 else if the text is replaced by an ellipsis. */)
19916 Lisp_Object pos_or_prop
;
19919 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19920 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19922 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19923 return (invis
== 0 ? Qnil
19925 : make_number (invis
));
19928 /* Calculate a width or height in pixels from a specification using
19929 the following elements:
19932 NUM - a (fractional) multiple of the default font width/height
19933 (NUM) - specifies exactly NUM pixels
19934 UNIT - a fixed number of pixels, see below.
19935 ELEMENT - size of a display element in pixels, see below.
19936 (NUM . SPEC) - equals NUM * SPEC
19937 (+ SPEC SPEC ...) - add pixel values
19938 (- SPEC SPEC ...) - subtract pixel values
19939 (- SPEC) - negate pixel value
19942 INT or FLOAT - a number constant
19943 SYMBOL - use symbol's (buffer local) variable binding.
19946 in - pixels per inch *)
19947 mm - pixels per 1/1000 meter *)
19948 cm - pixels per 1/100 meter *)
19949 width - width of current font in pixels.
19950 height - height of current font in pixels.
19952 *) using the ratio(s) defined in display-pixels-per-inch.
19956 left-fringe - left fringe width in pixels
19957 right-fringe - right fringe width in pixels
19959 left-margin - left margin width in pixels
19960 right-margin - right margin width in pixels
19962 scroll-bar - scroll-bar area width in pixels
19966 Pixels corresponding to 5 inches:
19969 Total width of non-text areas on left side of window (if scroll-bar is on left):
19970 '(space :width (+ left-fringe left-margin scroll-bar))
19972 Align to first text column (in header line):
19973 '(space :align-to 0)
19975 Align to middle of text area minus half the width of variable `my-image'
19976 containing a loaded image:
19977 '(space :align-to (0.5 . (- text my-image)))
19979 Width of left margin minus width of 1 character in the default font:
19980 '(space :width (- left-margin 1))
19982 Width of left margin minus width of 2 characters in the current font:
19983 '(space :width (- left-margin (2 . width)))
19985 Center 1 character over left-margin (in header line):
19986 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19988 Different ways to express width of left fringe plus left margin minus one pixel:
19989 '(space :width (- (+ left-fringe left-margin) (1)))
19990 '(space :width (+ left-fringe left-margin (- (1))))
19991 '(space :width (+ left-fringe left-margin (-1)))
19995 #define NUMVAL(X) \
19996 ((INTEGERP (X) || FLOATP (X)) \
20001 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
20006 int width_p
, *align_to
;
20010 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20011 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20014 return OK_PIXELS (0);
20016 xassert (FRAME_LIVE_P (it
->f
));
20018 if (SYMBOLP (prop
))
20020 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20022 char *unit
= SDATA (SYMBOL_NAME (prop
));
20024 if (unit
[0] == 'i' && unit
[1] == 'n')
20026 else if (unit
[0] == 'm' && unit
[1] == 'm')
20028 else if (unit
[0] == 'c' && unit
[1] == 'm')
20035 #ifdef HAVE_WINDOW_SYSTEM
20036 if (FRAME_WINDOW_P (it
->f
)
20038 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20039 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20041 return OK_PIXELS (ppi
/ pixels
);
20044 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20045 || (CONSP (Vdisplay_pixels_per_inch
)
20047 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20048 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20050 return OK_PIXELS (ppi
/ pixels
);
20056 #ifdef HAVE_WINDOW_SYSTEM
20057 if (EQ (prop
, Qheight
))
20058 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20059 if (EQ (prop
, Qwidth
))
20060 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20062 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20063 return OK_PIXELS (1);
20066 if (EQ (prop
, Qtext
))
20067 return OK_PIXELS (width_p
20068 ? window_box_width (it
->w
, TEXT_AREA
)
20069 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20071 if (align_to
&& *align_to
< 0)
20074 if (EQ (prop
, Qleft
))
20075 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20076 if (EQ (prop
, Qright
))
20077 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20078 if (EQ (prop
, Qcenter
))
20079 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20080 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20081 if (EQ (prop
, Qleft_fringe
))
20082 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20083 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20084 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20085 if (EQ (prop
, Qright_fringe
))
20086 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20087 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20088 : window_box_right_offset (it
->w
, TEXT_AREA
));
20089 if (EQ (prop
, Qleft_margin
))
20090 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20091 if (EQ (prop
, Qright_margin
))
20092 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20093 if (EQ (prop
, Qscroll_bar
))
20094 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20096 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20097 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20098 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20103 if (EQ (prop
, Qleft_fringe
))
20104 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20105 if (EQ (prop
, Qright_fringe
))
20106 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20107 if (EQ (prop
, Qleft_margin
))
20108 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20109 if (EQ (prop
, Qright_margin
))
20110 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20111 if (EQ (prop
, Qscroll_bar
))
20112 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20115 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20118 if (INTEGERP (prop
) || FLOATP (prop
))
20120 int base_unit
= (width_p
20121 ? FRAME_COLUMN_WIDTH (it
->f
)
20122 : FRAME_LINE_HEIGHT (it
->f
));
20123 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20128 Lisp_Object car
= XCAR (prop
);
20129 Lisp_Object cdr
= XCDR (prop
);
20133 #ifdef HAVE_WINDOW_SYSTEM
20134 if (FRAME_WINDOW_P (it
->f
)
20135 && valid_image_p (prop
))
20137 int id
= lookup_image (it
->f
, prop
);
20138 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20140 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20143 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20149 while (CONSP (cdr
))
20151 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20152 font
, width_p
, align_to
))
20155 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20160 if (EQ (car
, Qminus
))
20162 return OK_PIXELS (pixels
);
20165 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20168 if (INTEGERP (car
) || FLOATP (car
))
20171 pixels
= XFLOATINT (car
);
20173 return OK_PIXELS (pixels
);
20174 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20175 font
, width_p
, align_to
))
20176 return OK_PIXELS (pixels
* fact
);
20187 /***********************************************************************
20189 ***********************************************************************/
20191 #ifdef HAVE_WINDOW_SYSTEM
20196 dump_glyph_string (s
)
20197 struct glyph_string
*s
;
20199 fprintf (stderr
, "glyph string\n");
20200 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20201 s
->x
, s
->y
, s
->width
, s
->height
);
20202 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20203 fprintf (stderr
, " hl = %d\n", s
->hl
);
20204 fprintf (stderr
, " left overhang = %d, right = %d\n",
20205 s
->left_overhang
, s
->right_overhang
);
20206 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20207 fprintf (stderr
, " extends to end of line = %d\n",
20208 s
->extends_to_end_of_line_p
);
20209 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20210 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20213 #endif /* GLYPH_DEBUG */
20215 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20216 of XChar2b structures for S; it can't be allocated in
20217 init_glyph_string because it must be allocated via `alloca'. W
20218 is the window on which S is drawn. ROW and AREA are the glyph row
20219 and area within the row from which S is constructed. START is the
20220 index of the first glyph structure covered by S. HL is a
20221 face-override for drawing S. */
20224 #define OPTIONAL_HDC(hdc) hdc,
20225 #define DECLARE_HDC(hdc) HDC hdc;
20226 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20227 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20230 #ifndef OPTIONAL_HDC
20231 #define OPTIONAL_HDC(hdc)
20232 #define DECLARE_HDC(hdc)
20233 #define ALLOCATE_HDC(hdc, f)
20234 #define RELEASE_HDC(hdc, f)
20238 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
20239 struct glyph_string
*s
;
20243 struct glyph_row
*row
;
20244 enum glyph_row_area area
;
20246 enum draw_glyphs_face hl
;
20248 bzero (s
, sizeof *s
);
20250 s
->f
= XFRAME (w
->frame
);
20254 s
->display
= FRAME_X_DISPLAY (s
->f
);
20255 s
->window
= FRAME_X_WINDOW (s
->f
);
20256 s
->char2b
= char2b
;
20260 s
->first_glyph
= row
->glyphs
[area
] + start
;
20261 s
->height
= row
->height
;
20262 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20263 s
->ybase
= s
->y
+ row
->ascent
;
20267 /* Append the list of glyph strings with head H and tail T to the list
20268 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20271 append_glyph_string_lists (head
, tail
, h
, t
)
20272 struct glyph_string
**head
, **tail
;
20273 struct glyph_string
*h
, *t
;
20287 /* Prepend the list of glyph strings with head H and tail T to the
20288 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20292 prepend_glyph_string_lists (head
, tail
, h
, t
)
20293 struct glyph_string
**head
, **tail
;
20294 struct glyph_string
*h
, *t
;
20308 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20309 Set *HEAD and *TAIL to the resulting list. */
20312 append_glyph_string (head
, tail
, s
)
20313 struct glyph_string
**head
, **tail
;
20314 struct glyph_string
*s
;
20316 s
->next
= s
->prev
= NULL
;
20317 append_glyph_string_lists (head
, tail
, s
, s
);
20321 /* Get face and two-byte form of character C in face FACE_ID on frame
20322 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
20323 means we want to display multibyte text. DISPLAY_P non-zero means
20324 make sure that X resources for the face returned are allocated.
20325 Value is a pointer to a realized face that is ready for display if
20326 DISPLAY_P is non-zero. */
20328 static INLINE
struct face
*
20329 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
20333 int multibyte_p
, display_p
;
20335 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20339 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20341 if (code
!= FONT_INVALID_CODE
)
20342 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20344 STORE_XCHAR2B (char2b
, 0, 0);
20347 /* Make sure X resources of the face are allocated. */
20348 #ifdef HAVE_X_WINDOWS
20352 xassert (face
!= NULL
);
20353 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20360 /* Get face and two-byte form of character glyph GLYPH on frame F.
20361 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20362 a pointer to a realized face that is ready for display. */
20364 static INLINE
struct face
*
20365 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
20367 struct glyph
*glyph
;
20373 xassert (glyph
->type
== CHAR_GLYPH
);
20374 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20381 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20383 if (code
!= FONT_INVALID_CODE
)
20384 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20386 STORE_XCHAR2B (char2b
, 0, 0);
20389 /* Make sure X resources of the face are allocated. */
20390 xassert (face
!= NULL
);
20391 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20396 /* Fill glyph string S with composition components specified by S->cmp.
20398 BASE_FACE is the base face of the composition.
20399 S->cmp_from is the index of the first component for S.
20401 OVERLAPS non-zero means S should draw the foreground only, and use
20402 its physical height for clipping. See also draw_glyphs.
20404 Value is the index of a component not in S. */
20407 fill_composite_glyph_string (s
, base_face
, overlaps
)
20408 struct glyph_string
*s
;
20409 struct face
*base_face
;
20413 /* For all glyphs of this composition, starting at the offset
20414 S->cmp_from, until we reach the end of the definition or encounter a
20415 glyph that requires the different face, add it to S. */
20420 s
->for_overlaps
= overlaps
;
20423 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20425 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20429 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20432 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20433 s
->char2b
+ i
, 1, 1);
20439 s
->font
= s
->face
->font
;
20441 else if (s
->face
!= face
)
20449 /* All glyph strings for the same composition has the same width,
20450 i.e. the width set for the first component of the composition. */
20451 s
->width
= s
->first_glyph
->pixel_width
;
20453 /* If the specified font could not be loaded, use the frame's
20454 default font, but record the fact that we couldn't load it in
20455 the glyph string so that we can draw rectangles for the
20456 characters of the glyph string. */
20457 if (s
->font
== NULL
)
20459 s
->font_not_found_p
= 1;
20460 s
->font
= FRAME_FONT (s
->f
);
20463 /* Adjust base line for subscript/superscript text. */
20464 s
->ybase
+= s
->first_glyph
->voffset
;
20466 /* This glyph string must always be drawn with 16-bit functions. */
20473 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
20474 struct glyph_string
*s
;
20476 int start
, end
, overlaps
;
20478 struct glyph
*glyph
, *last
;
20479 Lisp_Object lgstring
;
20482 s
->for_overlaps
= overlaps
;
20483 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20484 last
= s
->row
->glyphs
[s
->area
] + end
;
20485 s
->cmp_id
= glyph
->u
.cmp
.id
;
20486 s
->cmp_from
= glyph
->u
.cmp
.from
;
20487 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
20488 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20489 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20490 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20492 while (glyph
< last
20493 && glyph
->u
.cmp
.automatic
20494 && glyph
->u
.cmp
.id
== s
->cmp_id
20495 && s
->cmp_to
== glyph
->u
.cmp
.from
)
20496 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
20498 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20500 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20501 unsigned code
= LGLYPH_CODE (lglyph
);
20503 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20505 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20506 return glyph
- s
->row
->glyphs
[s
->area
];
20510 /* Fill glyph string S from a sequence of character glyphs.
20512 FACE_ID is the face id of the string. START is the index of the
20513 first glyph to consider, END is the index of the last + 1.
20514 OVERLAPS non-zero means S should draw the foreground only, and use
20515 its physical height for clipping. See also draw_glyphs.
20517 Value is the index of the first glyph not in S. */
20520 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
20521 struct glyph_string
*s
;
20523 int start
, end
, overlaps
;
20525 struct glyph
*glyph
, *last
;
20527 int glyph_not_available_p
;
20529 xassert (s
->f
== XFRAME (s
->w
->frame
));
20530 xassert (s
->nchars
== 0);
20531 xassert (start
>= 0 && end
> start
);
20533 s
->for_overlaps
= overlaps
;
20534 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20535 last
= s
->row
->glyphs
[s
->area
] + end
;
20536 voffset
= glyph
->voffset
;
20537 s
->padding_p
= glyph
->padding_p
;
20538 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20540 while (glyph
< last
20541 && glyph
->type
== CHAR_GLYPH
20542 && glyph
->voffset
== voffset
20543 /* Same face id implies same font, nowadays. */
20544 && glyph
->face_id
== face_id
20545 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20549 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20550 s
->char2b
+ s
->nchars
,
20552 s
->two_byte_p
= two_byte_p
;
20554 xassert (s
->nchars
<= end
- start
);
20555 s
->width
+= glyph
->pixel_width
;
20556 if (glyph
++->padding_p
!= s
->padding_p
)
20560 s
->font
= s
->face
->font
;
20562 /* If the specified font could not be loaded, use the frame's font,
20563 but record the fact that we couldn't load it in
20564 S->font_not_found_p so that we can draw rectangles for the
20565 characters of the glyph string. */
20566 if (s
->font
== NULL
|| glyph_not_available_p
)
20568 s
->font_not_found_p
= 1;
20569 s
->font
= FRAME_FONT (s
->f
);
20572 /* Adjust base line for subscript/superscript text. */
20573 s
->ybase
+= voffset
;
20575 xassert (s
->face
&& s
->face
->gc
);
20576 return glyph
- s
->row
->glyphs
[s
->area
];
20580 /* Fill glyph string S from image glyph S->first_glyph. */
20583 fill_image_glyph_string (s
)
20584 struct glyph_string
*s
;
20586 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20587 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20589 s
->slice
= s
->first_glyph
->slice
;
20590 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20591 s
->font
= s
->face
->font
;
20592 s
->width
= s
->first_glyph
->pixel_width
;
20594 /* Adjust base line for subscript/superscript text. */
20595 s
->ybase
+= s
->first_glyph
->voffset
;
20599 /* Fill glyph string S from a sequence of stretch glyphs.
20601 ROW is the glyph row in which the glyphs are found, AREA is the
20602 area within the row. START is the index of the first glyph to
20603 consider, END is the index of the last + 1.
20605 Value is the index of the first glyph not in S. */
20608 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
20609 struct glyph_string
*s
;
20610 struct glyph_row
*row
;
20611 enum glyph_row_area area
;
20614 struct glyph
*glyph
, *last
;
20615 int voffset
, face_id
;
20617 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20619 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20620 last
= s
->row
->glyphs
[s
->area
] + end
;
20621 face_id
= glyph
->face_id
;
20622 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20623 s
->font
= s
->face
->font
;
20624 s
->width
= glyph
->pixel_width
;
20626 voffset
= glyph
->voffset
;
20630 && glyph
->type
== STRETCH_GLYPH
20631 && glyph
->voffset
== voffset
20632 && glyph
->face_id
== face_id
);
20634 s
->width
+= glyph
->pixel_width
;
20636 /* Adjust base line for subscript/superscript text. */
20637 s
->ybase
+= voffset
;
20639 /* The case that face->gc == 0 is handled when drawing the glyph
20640 string by calling PREPARE_FACE_FOR_DISPLAY. */
20642 return glyph
- s
->row
->glyphs
[s
->area
];
20645 static struct font_metrics
*
20646 get_per_char_metric (f
, font
, char2b
)
20651 static struct font_metrics metrics
;
20652 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20654 if (! font
|| code
== FONT_INVALID_CODE
)
20656 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20661 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20662 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20663 assumed to be zero. */
20666 x_get_glyph_overhangs (glyph
, f
, left
, right
)
20667 struct glyph
*glyph
;
20671 *left
= *right
= 0;
20673 if (glyph
->type
== CHAR_GLYPH
)
20677 struct font_metrics
*pcm
;
20679 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20680 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20682 if (pcm
->rbearing
> pcm
->width
)
20683 *right
= pcm
->rbearing
- pcm
->width
;
20684 if (pcm
->lbearing
< 0)
20685 *left
= -pcm
->lbearing
;
20688 else if (glyph
->type
== COMPOSITE_GLYPH
)
20690 if (! glyph
->u
.cmp
.automatic
)
20692 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20694 if (cmp
->rbearing
> cmp
->pixel_width
)
20695 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20696 if (cmp
->lbearing
< 0)
20697 *left
= - cmp
->lbearing
;
20701 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
20702 struct font_metrics metrics
;
20704 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
20705 glyph
->u
.cmp
.to
+ 1, &metrics
);
20706 if (metrics
.rbearing
> metrics
.width
)
20707 *right
= metrics
.rbearing
- metrics
.width
;
20708 if (metrics
.lbearing
< 0)
20709 *left
= - metrics
.lbearing
;
20715 /* Return the index of the first glyph preceding glyph string S that
20716 is overwritten by S because of S's left overhang. Value is -1
20717 if no glyphs are overwritten. */
20720 left_overwritten (s
)
20721 struct glyph_string
*s
;
20725 if (s
->left_overhang
)
20728 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20729 int first
= s
->first_glyph
- glyphs
;
20731 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
20732 x
-= glyphs
[i
].pixel_width
;
20743 /* Return the index of the first glyph preceding glyph string S that
20744 is overwriting S because of its right overhang. Value is -1 if no
20745 glyph in front of S overwrites S. */
20748 left_overwriting (s
)
20749 struct glyph_string
*s
;
20752 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20753 int first
= s
->first_glyph
- glyphs
;
20757 for (i
= first
- 1; i
>= 0; --i
)
20760 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20763 x
-= glyphs
[i
].pixel_width
;
20770 /* Return the index of the last glyph following glyph string S that is
20771 overwritten by S because of S's right overhang. Value is -1 if
20772 no such glyph is found. */
20775 right_overwritten (s
)
20776 struct glyph_string
*s
;
20780 if (s
->right_overhang
)
20783 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20784 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20785 int end
= s
->row
->used
[s
->area
];
20787 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
20788 x
+= glyphs
[i
].pixel_width
;
20797 /* Return the index of the last glyph following glyph string S that
20798 overwrites S because of its left overhang. Value is negative
20799 if no such glyph is found. */
20802 right_overwriting (s
)
20803 struct glyph_string
*s
;
20806 int end
= s
->row
->used
[s
->area
];
20807 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20808 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20812 for (i
= first
; i
< end
; ++i
)
20815 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20818 x
+= glyphs
[i
].pixel_width
;
20825 /* Set background width of glyph string S. START is the index of the
20826 first glyph following S. LAST_X is the right-most x-position + 1
20827 in the drawing area. */
20830 set_glyph_string_background_width (s
, start
, last_x
)
20831 struct glyph_string
*s
;
20835 /* If the face of this glyph string has to be drawn to the end of
20836 the drawing area, set S->extends_to_end_of_line_p. */
20838 if (start
== s
->row
->used
[s
->area
]
20839 && s
->area
== TEXT_AREA
20840 && ((s
->row
->fill_line_p
20841 && (s
->hl
== DRAW_NORMAL_TEXT
20842 || s
->hl
== DRAW_IMAGE_RAISED
20843 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20844 || s
->hl
== DRAW_MOUSE_FACE
))
20845 s
->extends_to_end_of_line_p
= 1;
20847 /* If S extends its face to the end of the line, set its
20848 background_width to the distance to the right edge of the drawing
20850 if (s
->extends_to_end_of_line_p
)
20851 s
->background_width
= last_x
- s
->x
+ 1;
20853 s
->background_width
= s
->width
;
20857 /* Compute overhangs and x-positions for glyph string S and its
20858 predecessors, or successors. X is the starting x-position for S.
20859 BACKWARD_P non-zero means process predecessors. */
20862 compute_overhangs_and_x (s
, x
, backward_p
)
20863 struct glyph_string
*s
;
20871 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20872 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20882 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20883 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20893 /* The following macros are only called from draw_glyphs below.
20894 They reference the following parameters of that function directly:
20895 `w', `row', `area', and `overlap_p'
20896 as well as the following local variables:
20897 `s', `f', and `hdc' (in W32) */
20900 /* On W32, silently add local `hdc' variable to argument list of
20901 init_glyph_string. */
20902 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20903 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20905 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20906 init_glyph_string (s, char2b, w, row, area, start, hl)
20909 /* Add a glyph string for a stretch glyph to the list of strings
20910 between HEAD and TAIL. START is the index of the stretch glyph in
20911 row area AREA of glyph row ROW. END is the index of the last glyph
20912 in that glyph row area. X is the current output position assigned
20913 to the new glyph string constructed. HL overrides that face of the
20914 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20915 is the right-most x-position of the drawing area. */
20917 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20918 and below -- keep them on one line. */
20919 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20922 s = (struct glyph_string *) alloca (sizeof *s); \
20923 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20924 START = fill_stretch_glyph_string (s, row, area, START, END); \
20925 append_glyph_string (&HEAD, &TAIL, s); \
20931 /* Add a glyph string for an image glyph to the list of strings
20932 between HEAD and TAIL. START is the index of the image glyph in
20933 row area AREA of glyph row ROW. END is the index of the last glyph
20934 in that glyph row area. X is the current output position assigned
20935 to the new glyph string constructed. HL overrides that face of the
20936 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20937 is the right-most x-position of the drawing area. */
20939 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20942 s = (struct glyph_string *) alloca (sizeof *s); \
20943 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20944 fill_image_glyph_string (s); \
20945 append_glyph_string (&HEAD, &TAIL, s); \
20952 /* Add a glyph string for a sequence of character glyphs to the list
20953 of strings between HEAD and TAIL. START is the index of the first
20954 glyph in row area AREA of glyph row ROW that is part of the new
20955 glyph string. END is the index of the last glyph in that glyph row
20956 area. X is the current output position assigned to the new glyph
20957 string constructed. HL overrides that face of the glyph; e.g. it
20958 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20959 right-most x-position of the drawing area. */
20961 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20967 face_id = (row)->glyphs[area][START].face_id; \
20969 s = (struct glyph_string *) alloca (sizeof *s); \
20970 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20971 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20972 append_glyph_string (&HEAD, &TAIL, s); \
20974 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20979 /* Add a glyph string for a composite sequence to the list of strings
20980 between HEAD and TAIL. START is the index of the first glyph in
20981 row area AREA of glyph row ROW that is part of the new glyph
20982 string. END is the index of the last glyph in that glyph row area.
20983 X is the current output position assigned to the new glyph string
20984 constructed. HL overrides that face of the glyph; e.g. it is
20985 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20986 x-position of the drawing area. */
20988 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20990 int face_id = (row)->glyphs[area][START].face_id; \
20991 struct face *base_face = FACE_FROM_ID (f, face_id); \
20992 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20993 struct composition *cmp = composition_table[cmp_id]; \
20995 struct glyph_string *first_s; \
20998 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21000 /* Make glyph_strings for each glyph sequence that is drawable by \
21001 the same face, and append them to HEAD/TAIL. */ \
21002 for (n = 0; n < cmp->glyph_len;) \
21004 s = (struct glyph_string *) alloca (sizeof *s); \
21005 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21006 append_glyph_string (&(HEAD), &(TAIL), s); \
21012 n = fill_composite_glyph_string (s, base_face, overlaps); \
21020 /* Add a glyph string for a glyph-string sequence to the list of strings
21021 between HEAD and TAIL. */
21023 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21027 Lisp_Object gstring; \
21029 face_id = (row)->glyphs[area][START].face_id; \
21030 gstring = (composition_gstring_from_id \
21031 ((row)->glyphs[area][START].u.cmp.id)); \
21032 s = (struct glyph_string *) alloca (sizeof *s); \
21033 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21034 * LGSTRING_GLYPH_LEN (gstring)); \
21035 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21036 append_glyph_string (&(HEAD), &(TAIL), s); \
21038 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21042 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21043 of AREA of glyph row ROW on window W between indices START and END.
21044 HL overrides the face for drawing glyph strings, e.g. it is
21045 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21046 x-positions of the drawing area.
21048 This is an ugly monster macro construct because we must use alloca
21049 to allocate glyph strings (because draw_glyphs can be called
21050 asynchronously). */
21052 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21055 HEAD = TAIL = NULL; \
21056 while (START < END) \
21058 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21059 switch (first_glyph->type) \
21062 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21066 case COMPOSITE_GLYPH: \
21067 if (first_glyph->u.cmp.automatic) \
21068 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21071 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21075 case STRETCH_GLYPH: \
21076 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21080 case IMAGE_GLYPH: \
21081 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21091 set_glyph_string_background_width (s, START, LAST_X); \
21098 /* Draw glyphs between START and END in AREA of ROW on window W,
21099 starting at x-position X. X is relative to AREA in W. HL is a
21100 face-override with the following meaning:
21102 DRAW_NORMAL_TEXT draw normally
21103 DRAW_CURSOR draw in cursor face
21104 DRAW_MOUSE_FACE draw in mouse face.
21105 DRAW_INVERSE_VIDEO draw in mode line face
21106 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21107 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21109 If OVERLAPS is non-zero, draw only the foreground of characters and
21110 clip to the physical height of ROW. Non-zero value also defines
21111 the overlapping part to be drawn:
21113 OVERLAPS_PRED overlap with preceding rows
21114 OVERLAPS_SUCC overlap with succeeding rows
21115 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21116 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21118 Value is the x-position reached, relative to AREA of W. */
21121 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
21124 struct glyph_row
*row
;
21125 enum glyph_row_area area
;
21126 EMACS_INT start
, end
;
21127 enum draw_glyphs_face hl
;
21130 struct glyph_string
*head
, *tail
;
21131 struct glyph_string
*s
;
21132 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21133 int i
, j
, x_reached
, last_x
, area_left
= 0;
21134 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21137 ALLOCATE_HDC (hdc
, f
);
21139 /* Let's rather be paranoid than getting a SEGV. */
21140 end
= min (end
, row
->used
[area
]);
21141 start
= max (0, start
);
21142 start
= min (end
, start
);
21144 /* Translate X to frame coordinates. Set last_x to the right
21145 end of the drawing area. */
21146 if (row
->full_width_p
)
21148 /* X is relative to the left edge of W, without scroll bars
21150 area_left
= WINDOW_LEFT_EDGE_X (w
);
21151 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21155 area_left
= window_box_left (w
, area
);
21156 last_x
= area_left
+ window_box_width (w
, area
);
21160 /* Build a doubly-linked list of glyph_string structures between
21161 head and tail from what we have to draw. Note that the macro
21162 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21163 the reason we use a separate variable `i'. */
21165 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21167 x_reached
= tail
->x
+ tail
->background_width
;
21171 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21172 the row, redraw some glyphs in front or following the glyph
21173 strings built above. */
21174 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21176 struct glyph_string
*h
, *t
;
21177 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21178 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
21181 /* If mouse highlighting is on, we may need to draw adjacent
21182 glyphs using mouse-face highlighting. */
21183 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21185 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21187 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21188 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21190 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21192 check_mouse_face
= 1;
21193 mouse_beg_col
= (row
== mouse_beg_row
)
21194 ? dpyinfo
->mouse_face_beg_col
: 0;
21195 mouse_end_col
= (row
== mouse_end_row
)
21196 ? dpyinfo
->mouse_face_end_col
21197 : row
->used
[TEXT_AREA
];
21201 /* Compute overhangs for all glyph strings. */
21202 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21203 for (s
= head
; s
; s
= s
->next
)
21204 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21206 /* Prepend glyph strings for glyphs in front of the first glyph
21207 string that are overwritten because of the first glyph
21208 string's left overhang. The background of all strings
21209 prepended must be drawn because the first glyph string
21211 i
= left_overwritten (head
);
21214 enum draw_glyphs_face overlap_hl
;
21216 /* If this row contains mouse highlighting, attempt to draw
21217 the overlapped glyphs with the correct highlight. This
21218 code fails if the overlap encompasses more than one glyph
21219 and mouse-highlight spans only some of these glyphs.
21220 However, making it work perfectly involves a lot more
21221 code, and I don't know if the pathological case occurs in
21222 practice, so we'll stick to this for now. --- cyd */
21223 if (check_mouse_face
21224 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21225 overlap_hl
= DRAW_MOUSE_FACE
;
21227 overlap_hl
= DRAW_NORMAL_TEXT
;
21230 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21231 overlap_hl
, dummy_x
, last_x
);
21233 compute_overhangs_and_x (t
, head
->x
, 1);
21234 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21238 /* Prepend glyph strings for glyphs in front of the first glyph
21239 string that overwrite that glyph string because of their
21240 right overhang. For these strings, only the foreground must
21241 be drawn, because it draws over the glyph string at `head'.
21242 The background must not be drawn because this would overwrite
21243 right overhangs of preceding glyphs for which no glyph
21245 i
= left_overwriting (head
);
21248 enum draw_glyphs_face overlap_hl
;
21250 if (check_mouse_face
21251 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21252 overlap_hl
= DRAW_MOUSE_FACE
;
21254 overlap_hl
= DRAW_NORMAL_TEXT
;
21257 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21258 overlap_hl
, dummy_x
, last_x
);
21259 for (s
= h
; s
; s
= s
->next
)
21260 s
->background_filled_p
= 1;
21261 compute_overhangs_and_x (t
, head
->x
, 1);
21262 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21265 /* Append glyphs strings for glyphs following the last glyph
21266 string tail that are overwritten by tail. The background of
21267 these strings has to be drawn because tail's foreground draws
21269 i
= right_overwritten (tail
);
21272 enum draw_glyphs_face overlap_hl
;
21274 if (check_mouse_face
21275 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21276 overlap_hl
= DRAW_MOUSE_FACE
;
21278 overlap_hl
= DRAW_NORMAL_TEXT
;
21280 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21281 overlap_hl
, x
, last_x
);
21282 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21283 we don't have `end = i;' here. */
21284 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21285 append_glyph_string_lists (&head
, &tail
, h
, t
);
21289 /* Append glyph strings for glyphs following the last glyph
21290 string tail that overwrite tail. The foreground of such
21291 glyphs has to be drawn because it writes into the background
21292 of tail. The background must not be drawn because it could
21293 paint over the foreground of following glyphs. */
21294 i
= right_overwriting (tail
);
21297 enum draw_glyphs_face overlap_hl
;
21298 if (check_mouse_face
21299 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21300 overlap_hl
= DRAW_MOUSE_FACE
;
21302 overlap_hl
= DRAW_NORMAL_TEXT
;
21305 i
++; /* We must include the Ith glyph. */
21306 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21307 overlap_hl
, x
, last_x
);
21308 for (s
= h
; s
; s
= s
->next
)
21309 s
->background_filled_p
= 1;
21310 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21311 append_glyph_string_lists (&head
, &tail
, h
, t
);
21313 if (clip_head
|| clip_tail
)
21314 for (s
= head
; s
; s
= s
->next
)
21316 s
->clip_head
= clip_head
;
21317 s
->clip_tail
= clip_tail
;
21321 /* Draw all strings. */
21322 for (s
= head
; s
; s
= s
->next
)
21323 FRAME_RIF (f
)->draw_glyph_string (s
);
21326 /* When focus a sole frame and move horizontally, this sets on_p to 0
21327 causing a failure to erase prev cursor position. */
21328 if (area
== TEXT_AREA
21329 && !row
->full_width_p
21330 /* When drawing overlapping rows, only the glyph strings'
21331 foreground is drawn, which doesn't erase a cursor
21335 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21336 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21337 : (tail
? tail
->x
+ tail
->background_width
: x
));
21341 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21342 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21346 /* Value is the x-position up to which drawn, relative to AREA of W.
21347 This doesn't include parts drawn because of overhangs. */
21348 if (row
->full_width_p
)
21349 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21351 x_reached
-= area_left
;
21353 RELEASE_HDC (hdc
, f
);
21358 /* Expand row matrix if too narrow. Don't expand if area
21361 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21363 if (!fonts_changed_p \
21364 && (it->glyph_row->glyphs[area] \
21365 < it->glyph_row->glyphs[area + 1])) \
21367 it->w->ncols_scale_factor++; \
21368 fonts_changed_p = 1; \
21372 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21373 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21379 struct glyph
*glyph
;
21380 enum glyph_row_area area
= it
->area
;
21382 xassert (it
->glyph_row
);
21383 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21385 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21386 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21388 /* If the glyph row is reversed, we need to prepend the glyph
21389 rather than append it. */
21390 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21394 /* Make room for the additional glyph. */
21395 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21397 glyph
= it
->glyph_row
->glyphs
[area
];
21399 glyph
->charpos
= CHARPOS (it
->position
);
21400 glyph
->object
= it
->object
;
21401 if (it
->pixel_width
> 0)
21403 glyph
->pixel_width
= it
->pixel_width
;
21404 glyph
->padding_p
= 0;
21408 /* Assure at least 1-pixel width. Otherwise, cursor can't
21409 be displayed correctly. */
21410 glyph
->pixel_width
= 1;
21411 glyph
->padding_p
= 1;
21413 glyph
->ascent
= it
->ascent
;
21414 glyph
->descent
= it
->descent
;
21415 glyph
->voffset
= it
->voffset
;
21416 glyph
->type
= CHAR_GLYPH
;
21417 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21418 glyph
->multibyte_p
= it
->multibyte_p
;
21419 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21420 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21421 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21422 || it
->phys_descent
> it
->descent
);
21423 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21424 glyph
->face_id
= it
->face_id
;
21425 glyph
->u
.ch
= it
->char_to_display
;
21426 glyph
->slice
= null_glyph_slice
;
21427 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21430 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21431 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21433 glyph
->bidi_type
= it
->bidi_it
.type
;
21437 glyph
->resolved_level
= 0;
21438 glyph
->bidi_type
= UNKNOWN_BT
;
21440 ++it
->glyph_row
->used
[area
];
21443 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21446 /* Store one glyph for the composition IT->cmp_it.id in
21447 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21451 append_composite_glyph (it
)
21454 struct glyph
*glyph
;
21455 enum glyph_row_area area
= it
->area
;
21457 xassert (it
->glyph_row
);
21459 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21460 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21462 glyph
->charpos
= CHARPOS (it
->position
);
21463 glyph
->object
= it
->object
;
21464 glyph
->pixel_width
= it
->pixel_width
;
21465 glyph
->ascent
= it
->ascent
;
21466 glyph
->descent
= it
->descent
;
21467 glyph
->voffset
= it
->voffset
;
21468 glyph
->type
= COMPOSITE_GLYPH
;
21469 if (it
->cmp_it
.ch
< 0)
21471 glyph
->u
.cmp
.automatic
= 0;
21472 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21476 glyph
->u
.cmp
.automatic
= 1;
21477 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21478 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
21479 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
21481 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21482 glyph
->multibyte_p
= it
->multibyte_p
;
21483 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21484 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21485 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21486 || it
->phys_descent
> it
->descent
);
21487 glyph
->padding_p
= 0;
21488 glyph
->glyph_not_available_p
= 0;
21489 glyph
->face_id
= it
->face_id
;
21490 glyph
->slice
= null_glyph_slice
;
21491 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21494 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21495 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21497 glyph
->bidi_type
= it
->bidi_it
.type
;
21499 ++it
->glyph_row
->used
[area
];
21502 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21506 /* Change IT->ascent and IT->height according to the setting of
21510 take_vertical_position_into_account (it
)
21515 if (it
->voffset
< 0)
21516 /* Increase the ascent so that we can display the text higher
21518 it
->ascent
-= it
->voffset
;
21520 /* Increase the descent so that we can display the text lower
21522 it
->descent
+= it
->voffset
;
21527 /* Produce glyphs/get display metrics for the image IT is loaded with.
21528 See the description of struct display_iterator in dispextern.h for
21529 an overview of struct display_iterator. */
21532 produce_image_glyph (it
)
21537 int glyph_ascent
, crop
;
21538 struct glyph_slice slice
;
21540 xassert (it
->what
== IT_IMAGE
);
21542 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21544 /* Make sure X resources of the face is loaded. */
21545 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21547 if (it
->image_id
< 0)
21549 /* Fringe bitmap. */
21550 it
->ascent
= it
->phys_ascent
= 0;
21551 it
->descent
= it
->phys_descent
= 0;
21552 it
->pixel_width
= 0;
21557 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21559 /* Make sure X resources of the image is loaded. */
21560 prepare_image_for_display (it
->f
, img
);
21562 slice
.x
= slice
.y
= 0;
21563 slice
.width
= img
->width
;
21564 slice
.height
= img
->height
;
21566 if (INTEGERP (it
->slice
.x
))
21567 slice
.x
= XINT (it
->slice
.x
);
21568 else if (FLOATP (it
->slice
.x
))
21569 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21571 if (INTEGERP (it
->slice
.y
))
21572 slice
.y
= XINT (it
->slice
.y
);
21573 else if (FLOATP (it
->slice
.y
))
21574 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21576 if (INTEGERP (it
->slice
.width
))
21577 slice
.width
= XINT (it
->slice
.width
);
21578 else if (FLOATP (it
->slice
.width
))
21579 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21581 if (INTEGERP (it
->slice
.height
))
21582 slice
.height
= XINT (it
->slice
.height
);
21583 else if (FLOATP (it
->slice
.height
))
21584 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21586 if (slice
.x
>= img
->width
)
21587 slice
.x
= img
->width
;
21588 if (slice
.y
>= img
->height
)
21589 slice
.y
= img
->height
;
21590 if (slice
.x
+ slice
.width
>= img
->width
)
21591 slice
.width
= img
->width
- slice
.x
;
21592 if (slice
.y
+ slice
.height
> img
->height
)
21593 slice
.height
= img
->height
- slice
.y
;
21595 if (slice
.width
== 0 || slice
.height
== 0)
21598 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21600 it
->descent
= slice
.height
- glyph_ascent
;
21602 it
->descent
+= img
->vmargin
;
21603 if (slice
.y
+ slice
.height
== img
->height
)
21604 it
->descent
+= img
->vmargin
;
21605 it
->phys_descent
= it
->descent
;
21607 it
->pixel_width
= slice
.width
;
21609 it
->pixel_width
+= img
->hmargin
;
21610 if (slice
.x
+ slice
.width
== img
->width
)
21611 it
->pixel_width
+= img
->hmargin
;
21613 /* It's quite possible for images to have an ascent greater than
21614 their height, so don't get confused in that case. */
21615 if (it
->descent
< 0)
21620 if (face
->box
!= FACE_NO_BOX
)
21622 if (face
->box_line_width
> 0)
21625 it
->ascent
+= face
->box_line_width
;
21626 if (slice
.y
+ slice
.height
== img
->height
)
21627 it
->descent
+= face
->box_line_width
;
21630 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21631 it
->pixel_width
+= eabs (face
->box_line_width
);
21632 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21633 it
->pixel_width
+= eabs (face
->box_line_width
);
21636 take_vertical_position_into_account (it
);
21638 /* Automatically crop wide image glyphs at right edge so we can
21639 draw the cursor on same display row. */
21640 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21641 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21643 it
->pixel_width
-= crop
;
21644 slice
.width
-= crop
;
21649 struct glyph
*glyph
;
21650 enum glyph_row_area area
= it
->area
;
21652 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21653 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21655 glyph
->charpos
= CHARPOS (it
->position
);
21656 glyph
->object
= it
->object
;
21657 glyph
->pixel_width
= it
->pixel_width
;
21658 glyph
->ascent
= glyph_ascent
;
21659 glyph
->descent
= it
->descent
;
21660 glyph
->voffset
= it
->voffset
;
21661 glyph
->type
= IMAGE_GLYPH
;
21662 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21663 glyph
->multibyte_p
= it
->multibyte_p
;
21664 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21665 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21666 glyph
->overlaps_vertically_p
= 0;
21667 glyph
->padding_p
= 0;
21668 glyph
->glyph_not_available_p
= 0;
21669 glyph
->face_id
= it
->face_id
;
21670 glyph
->u
.img_id
= img
->id
;
21671 glyph
->slice
= slice
;
21672 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21675 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21676 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21678 glyph
->bidi_type
= it
->bidi_it
.type
;
21680 ++it
->glyph_row
->used
[area
];
21683 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21688 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
21689 of the glyph, WIDTH and HEIGHT are the width and height of the
21690 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
21693 append_stretch_glyph (it
, object
, width
, height
, ascent
)
21695 Lisp_Object object
;
21699 struct glyph
*glyph
;
21700 enum glyph_row_area area
= it
->area
;
21702 xassert (ascent
>= 0 && ascent
<= height
);
21704 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21705 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21707 /* If the glyph row is reversed, we need to prepend the glyph
21708 rather than append it. */
21709 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21713 /* Make room for the additional glyph. */
21714 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21716 glyph
= it
->glyph_row
->glyphs
[area
];
21718 glyph
->charpos
= CHARPOS (it
->position
);
21719 glyph
->object
= object
;
21720 glyph
->pixel_width
= width
;
21721 glyph
->ascent
= ascent
;
21722 glyph
->descent
= height
- ascent
;
21723 glyph
->voffset
= it
->voffset
;
21724 glyph
->type
= STRETCH_GLYPH
;
21725 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21726 glyph
->multibyte_p
= it
->multibyte_p
;
21727 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21728 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21729 glyph
->overlaps_vertically_p
= 0;
21730 glyph
->padding_p
= 0;
21731 glyph
->glyph_not_available_p
= 0;
21732 glyph
->face_id
= it
->face_id
;
21733 glyph
->u
.stretch
.ascent
= ascent
;
21734 glyph
->u
.stretch
.height
= height
;
21735 glyph
->slice
= null_glyph_slice
;
21736 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21739 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21740 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21742 glyph
->bidi_type
= it
->bidi_it
.type
;
21746 glyph
->resolved_level
= 0;
21747 glyph
->bidi_type
= UNKNOWN_BT
;
21749 ++it
->glyph_row
->used
[area
];
21752 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21756 /* Produce a stretch glyph for iterator IT. IT->object is the value
21757 of the glyph property displayed. The value must be a list
21758 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
21761 1. `:width WIDTH' specifies that the space should be WIDTH *
21762 canonical char width wide. WIDTH may be an integer or floating
21765 2. `:relative-width FACTOR' specifies that the width of the stretch
21766 should be computed from the width of the first character having the
21767 `glyph' property, and should be FACTOR times that width.
21769 3. `:align-to HPOS' specifies that the space should be wide enough
21770 to reach HPOS, a value in canonical character units.
21772 Exactly one of the above pairs must be present.
21774 4. `:height HEIGHT' specifies that the height of the stretch produced
21775 should be HEIGHT, measured in canonical character units.
21777 5. `:relative-height FACTOR' specifies that the height of the
21778 stretch should be FACTOR times the height of the characters having
21779 the glyph property.
21781 Either none or exactly one of 4 or 5 must be present.
21783 6. `:ascent ASCENT' specifies that ASCENT percent of the height
21784 of the stretch should be used for the ascent of the stretch.
21785 ASCENT must be in the range 0 <= ASCENT <= 100. */
21788 produce_stretch_glyph (it
)
21791 /* (space :width WIDTH :height HEIGHT ...) */
21792 Lisp_Object prop
, plist
;
21793 int width
= 0, height
= 0, align_to
= -1;
21794 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
21797 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21798 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
21800 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21802 /* List should start with `space'. */
21803 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
21804 plist
= XCDR (it
->object
);
21806 /* Compute the width of the stretch. */
21807 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
21808 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
21810 /* Absolute width `:width WIDTH' specified and valid. */
21811 zero_width_ok_p
= 1;
21814 else if (prop
= Fplist_get (plist
, QCrelative_width
),
21817 /* Relative width `:relative-width FACTOR' specified and valid.
21818 Compute the width of the characters having the `glyph'
21821 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
21824 if (it
->multibyte_p
)
21826 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
21827 - IT_BYTEPOS (*it
));
21828 it2
.c
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
21831 it2
.c
= *p
, it2
.len
= 1;
21833 it2
.glyph_row
= NULL
;
21834 it2
.what
= IT_CHARACTER
;
21835 x_produce_glyphs (&it2
);
21836 width
= NUMVAL (prop
) * it2
.pixel_width
;
21838 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
21839 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
21841 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
21842 align_to
= (align_to
< 0
21844 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
21845 else if (align_to
< 0)
21846 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
21847 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
21848 zero_width_ok_p
= 1;
21851 /* Nothing specified -> width defaults to canonical char width. */
21852 width
= FRAME_COLUMN_WIDTH (it
->f
);
21854 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
21857 /* Compute height. */
21858 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
21859 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21862 zero_height_ok_p
= 1;
21864 else if (prop
= Fplist_get (plist
, QCrelative_height
),
21866 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
21868 height
= FONT_HEIGHT (font
);
21870 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
21873 /* Compute percentage of height used for ascent. If
21874 `:ascent ASCENT' is present and valid, use that. Otherwise,
21875 derive the ascent from the font in use. */
21876 if (prop
= Fplist_get (plist
, QCascent
),
21877 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
21878 ascent
= height
* NUMVAL (prop
) / 100.0;
21879 else if (!NILP (prop
)
21880 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21881 ascent
= min (max (0, (int)tem
), height
);
21883 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
21885 if (width
> 0 && it
->line_wrap
!= TRUNCATE
21886 && it
->current_x
+ width
> it
->last_visible_x
)
21887 width
= it
->last_visible_x
- it
->current_x
- 1;
21889 if (width
> 0 && height
> 0 && it
->glyph_row
)
21891 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
21892 if (!STRINGP (object
))
21893 object
= it
->w
->buffer
;
21894 append_stretch_glyph (it
, object
, width
, height
, ascent
);
21897 it
->pixel_width
= width
;
21898 it
->ascent
= it
->phys_ascent
= ascent
;
21899 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
21900 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21902 take_vertical_position_into_account (it
);
21905 /* Calculate line-height and line-spacing properties.
21906 An integer value specifies explicit pixel value.
21907 A float value specifies relative value to current face height.
21908 A cons (float . face-name) specifies relative value to
21909 height of specified face font.
21911 Returns height in pixels, or nil. */
21915 calc_line_height_property (it
, val
, font
, boff
, override
)
21919 int boff
, override
;
21921 Lisp_Object face_name
= Qnil
;
21922 int ascent
, descent
, height
;
21924 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21929 face_name
= XCAR (val
);
21931 if (!NUMBERP (val
))
21932 val
= make_number (1);
21933 if (NILP (face_name
))
21935 height
= it
->ascent
+ it
->descent
;
21940 if (NILP (face_name
))
21942 font
= FRAME_FONT (it
->f
);
21943 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21945 else if (EQ (face_name
, Qt
))
21954 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21956 return make_number (-1);
21958 face
= FACE_FROM_ID (it
->f
, face_id
);
21961 return make_number (-1);
21962 boff
= font
->baseline_offset
;
21963 if (font
->vertical_centering
)
21964 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21967 ascent
= FONT_BASE (font
) + boff
;
21968 descent
= FONT_DESCENT (font
) - boff
;
21972 it
->override_ascent
= ascent
;
21973 it
->override_descent
= descent
;
21974 it
->override_boff
= boff
;
21977 height
= ascent
+ descent
;
21981 height
= (int)(XFLOAT_DATA (val
) * height
);
21982 else if (INTEGERP (val
))
21983 height
*= XINT (val
);
21985 return make_number (height
);
21990 Produce glyphs/get display metrics for the display element IT is
21991 loaded with. See the description of struct it in dispextern.h
21992 for an overview of struct it. */
21995 x_produce_glyphs (it
)
21998 int extra_line_spacing
= it
->extra_line_spacing
;
22000 it
->glyph_not_available_p
= 0;
22002 if (it
->what
== IT_CHARACTER
)
22006 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22007 struct font_metrics
*pcm
;
22008 int font_not_found_p
;
22009 int boff
; /* baseline offset */
22010 /* We may change it->multibyte_p upon unibyte<->multibyte
22011 conversion. So, save the current value now and restore it
22014 Note: It seems that we don't have to record multibyte_p in
22015 struct glyph because the character code itself tells whether
22016 or not the character is multibyte. Thus, in the future, we
22017 must consider eliminating the field `multibyte_p' in the
22019 int saved_multibyte_p
= it
->multibyte_p
;
22021 /* Maybe translate single-byte characters to multibyte, or the
22023 it
->char_to_display
= it
->c
;
22024 if (!ASCII_BYTE_P (it
->c
)
22025 && ! it
->multibyte_p
)
22027 if (SINGLE_BYTE_CHAR_P (it
->c
)
22028 && unibyte_display_via_language_environment
)
22030 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
22032 /* get_next_display_element assures that this decoding
22034 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
22035 it
->multibyte_p
= 1;
22036 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
22038 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22042 /* Get font to use. Encode IT->char_to_display. */
22043 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
22044 &char2b
, it
->multibyte_p
, 0);
22047 font_not_found_p
= font
== NULL
;
22048 if (font_not_found_p
)
22050 /* When no suitable font found, display an empty box based
22051 on the metrics of the font of the default face (or what
22053 struct face
*no_font_face
22054 = FACE_FROM_ID (it
->f
,
22055 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
22056 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
22057 font
= no_font_face
->font
;
22058 boff
= font
->baseline_offset
;
22062 boff
= font
->baseline_offset
;
22063 if (font
->vertical_centering
)
22064 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22067 if (it
->char_to_display
>= ' '
22068 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
22070 /* Either unibyte or ASCII. */
22075 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22077 if (it
->override_ascent
>= 0)
22079 it
->ascent
= it
->override_ascent
;
22080 it
->descent
= it
->override_descent
;
22081 boff
= it
->override_boff
;
22085 it
->ascent
= FONT_BASE (font
) + boff
;
22086 it
->descent
= FONT_DESCENT (font
) - boff
;
22091 it
->phys_ascent
= pcm
->ascent
+ boff
;
22092 it
->phys_descent
= pcm
->descent
- boff
;
22093 it
->pixel_width
= pcm
->width
;
22097 it
->glyph_not_available_p
= 1;
22098 it
->phys_ascent
= it
->ascent
;
22099 it
->phys_descent
= it
->descent
;
22100 it
->pixel_width
= FONT_WIDTH (font
);
22103 if (it
->constrain_row_ascent_descent_p
)
22105 if (it
->descent
> it
->max_descent
)
22107 it
->ascent
+= it
->descent
- it
->max_descent
;
22108 it
->descent
= it
->max_descent
;
22110 if (it
->ascent
> it
->max_ascent
)
22112 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22113 it
->ascent
= it
->max_ascent
;
22115 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22116 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22117 extra_line_spacing
= 0;
22120 /* If this is a space inside a region of text with
22121 `space-width' property, change its width. */
22122 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22124 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22126 /* If face has a box, add the box thickness to the character
22127 height. If character has a box line to the left and/or
22128 right, add the box line width to the character's width. */
22129 if (face
->box
!= FACE_NO_BOX
)
22131 int thick
= face
->box_line_width
;
22135 it
->ascent
+= thick
;
22136 it
->descent
+= thick
;
22141 if (it
->start_of_box_run_p
)
22142 it
->pixel_width
+= thick
;
22143 if (it
->end_of_box_run_p
)
22144 it
->pixel_width
+= thick
;
22147 /* If face has an overline, add the height of the overline
22148 (1 pixel) and a 1 pixel margin to the character height. */
22149 if (face
->overline_p
)
22150 it
->ascent
+= overline_margin
;
22152 if (it
->constrain_row_ascent_descent_p
)
22154 if (it
->ascent
> it
->max_ascent
)
22155 it
->ascent
= it
->max_ascent
;
22156 if (it
->descent
> it
->max_descent
)
22157 it
->descent
= it
->max_descent
;
22160 take_vertical_position_into_account (it
);
22162 /* If we have to actually produce glyphs, do it. */
22167 /* Translate a space with a `space-width' property
22168 into a stretch glyph. */
22169 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22170 / FONT_HEIGHT (font
));
22171 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22172 it
->ascent
+ it
->descent
, ascent
);
22177 /* If characters with lbearing or rbearing are displayed
22178 in this line, record that fact in a flag of the
22179 glyph row. This is used to optimize X output code. */
22180 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22181 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22183 if (! stretched_p
&& it
->pixel_width
== 0)
22184 /* We assure that all visible glyphs have at least 1-pixel
22186 it
->pixel_width
= 1;
22188 else if (it
->char_to_display
== '\n')
22190 /* A newline has no width, but we need the height of the
22191 line. But if previous part of the line sets a height,
22192 don't increase that height */
22194 Lisp_Object height
;
22195 Lisp_Object total_height
= Qnil
;
22197 it
->override_ascent
= -1;
22198 it
->pixel_width
= 0;
22201 height
= get_it_property(it
, Qline_height
);
22202 /* Split (line-height total-height) list */
22204 && CONSP (XCDR (height
))
22205 && NILP (XCDR (XCDR (height
))))
22207 total_height
= XCAR (XCDR (height
));
22208 height
= XCAR (height
);
22210 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
22212 if (it
->override_ascent
>= 0)
22214 it
->ascent
= it
->override_ascent
;
22215 it
->descent
= it
->override_descent
;
22216 boff
= it
->override_boff
;
22220 it
->ascent
= FONT_BASE (font
) + boff
;
22221 it
->descent
= FONT_DESCENT (font
) - boff
;
22224 if (EQ (height
, Qt
))
22226 if (it
->descent
> it
->max_descent
)
22228 it
->ascent
+= it
->descent
- it
->max_descent
;
22229 it
->descent
= it
->max_descent
;
22231 if (it
->ascent
> it
->max_ascent
)
22233 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22234 it
->ascent
= it
->max_ascent
;
22236 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22237 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22238 it
->constrain_row_ascent_descent_p
= 1;
22239 extra_line_spacing
= 0;
22243 Lisp_Object spacing
;
22245 it
->phys_ascent
= it
->ascent
;
22246 it
->phys_descent
= it
->descent
;
22248 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22249 && face
->box
!= FACE_NO_BOX
22250 && face
->box_line_width
> 0)
22252 it
->ascent
+= face
->box_line_width
;
22253 it
->descent
+= face
->box_line_width
;
22256 && XINT (height
) > it
->ascent
+ it
->descent
)
22257 it
->ascent
= XINT (height
) - it
->descent
;
22259 if (!NILP (total_height
))
22260 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
22263 spacing
= get_it_property(it
, Qline_spacing
);
22264 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
22266 if (INTEGERP (spacing
))
22268 extra_line_spacing
= XINT (spacing
);
22269 if (!NILP (total_height
))
22270 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22274 else if (it
->char_to_display
== '\t')
22276 if (font
->space_width
> 0)
22278 int tab_width
= it
->tab_width
* font
->space_width
;
22279 int x
= it
->current_x
+ it
->continuation_lines_width
;
22280 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22282 /* If the distance from the current position to the next tab
22283 stop is less than a space character width, use the
22284 tab stop after that. */
22285 if (next_tab_x
- x
< font
->space_width
)
22286 next_tab_x
+= tab_width
;
22288 it
->pixel_width
= next_tab_x
- x
;
22290 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22291 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22295 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22296 it
->ascent
+ it
->descent
, it
->ascent
);
22301 it
->pixel_width
= 0;
22307 /* A multi-byte character. Assume that the display width of the
22308 character is the width of the character multiplied by the
22309 width of the font. */
22311 /* If we found a font, this font should give us the right
22312 metrics. If we didn't find a font, use the frame's
22313 default font and calculate the width of the character by
22314 multiplying the width of font by the width of the
22317 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22319 if (font_not_found_p
|| !pcm
)
22321 int char_width
= CHAR_WIDTH (it
->char_to_display
);
22323 if (char_width
== 0)
22324 /* This is a non spacing character. But, as we are
22325 going to display an empty box, the box must occupy
22326 at least one column. */
22328 it
->glyph_not_available_p
= 1;
22329 it
->pixel_width
= font
->space_width
* char_width
;
22330 it
->phys_ascent
= FONT_BASE (font
) + boff
;
22331 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22335 it
->pixel_width
= pcm
->width
;
22336 it
->phys_ascent
= pcm
->ascent
+ boff
;
22337 it
->phys_descent
= pcm
->descent
- boff
;
22339 && (pcm
->lbearing
< 0
22340 || pcm
->rbearing
> pcm
->width
))
22341 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22344 it
->ascent
= FONT_BASE (font
) + boff
;
22345 it
->descent
= FONT_DESCENT (font
) - boff
;
22346 if (face
->box
!= FACE_NO_BOX
)
22348 int thick
= face
->box_line_width
;
22352 it
->ascent
+= thick
;
22353 it
->descent
+= thick
;
22358 if (it
->start_of_box_run_p
)
22359 it
->pixel_width
+= thick
;
22360 if (it
->end_of_box_run_p
)
22361 it
->pixel_width
+= thick
;
22364 /* If face has an overline, add the height of the overline
22365 (1 pixel) and a 1 pixel margin to the character height. */
22366 if (face
->overline_p
)
22367 it
->ascent
+= overline_margin
;
22369 take_vertical_position_into_account (it
);
22371 if (it
->ascent
< 0)
22373 if (it
->descent
< 0)
22378 if (it
->pixel_width
== 0)
22379 /* We assure that all visible glyphs have at least 1-pixel
22381 it
->pixel_width
= 1;
22383 it
->multibyte_p
= saved_multibyte_p
;
22385 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22387 /* A static composition.
22389 Note: A composition is represented as one glyph in the
22390 glyph matrix. There are no padding glyphs.
22392 Important note: pixel_width, ascent, and descent are the
22393 values of what is drawn by draw_glyphs (i.e. the values of
22394 the overall glyphs composed). */
22395 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22396 int boff
; /* baseline offset */
22397 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22398 int glyph_len
= cmp
->glyph_len
;
22399 struct font
*font
= face
->font
;
22403 /* If we have not yet calculated pixel size data of glyphs of
22404 the composition for the current face font, calculate them
22405 now. Theoretically, we have to check all fonts for the
22406 glyphs, but that requires much time and memory space. So,
22407 here we check only the font of the first glyph. This may
22408 lead to incorrect display, but it's very rare, and C-l
22409 (recenter-top-bottom) can correct the display anyway. */
22410 if (! cmp
->font
|| cmp
->font
!= font
)
22412 /* Ascent and descent of the font of the first character
22413 of this composition (adjusted by baseline offset).
22414 Ascent and descent of overall glyphs should not be less
22415 than these, respectively. */
22416 int font_ascent
, font_descent
, font_height
;
22417 /* Bounding box of the overall glyphs. */
22418 int leftmost
, rightmost
, lowest
, highest
;
22419 int lbearing
, rbearing
;
22420 int i
, width
, ascent
, descent
;
22421 int left_padded
= 0, right_padded
= 0;
22424 struct font_metrics
*pcm
;
22425 int font_not_found_p
;
22428 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22429 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22431 if (glyph_len
< cmp
->glyph_len
)
22433 for (i
= 0; i
< glyph_len
; i
++)
22435 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22437 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22442 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22443 : IT_CHARPOS (*it
));
22444 /* If no suitable font is found, use the default font. */
22445 font_not_found_p
= font
== NULL
;
22446 if (font_not_found_p
)
22448 face
= face
->ascii_face
;
22451 boff
= font
->baseline_offset
;
22452 if (font
->vertical_centering
)
22453 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22454 font_ascent
= FONT_BASE (font
) + boff
;
22455 font_descent
= FONT_DESCENT (font
) - boff
;
22456 font_height
= FONT_HEIGHT (font
);
22458 cmp
->font
= (void *) font
;
22461 if (! font_not_found_p
)
22463 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22464 &char2b
, it
->multibyte_p
, 0);
22465 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22468 /* Initialize the bounding box. */
22471 width
= pcm
->width
;
22472 ascent
= pcm
->ascent
;
22473 descent
= pcm
->descent
;
22474 lbearing
= pcm
->lbearing
;
22475 rbearing
= pcm
->rbearing
;
22479 width
= FONT_WIDTH (font
);
22480 ascent
= FONT_BASE (font
);
22481 descent
= FONT_DESCENT (font
);
22488 lowest
= - descent
+ boff
;
22489 highest
= ascent
+ boff
;
22491 if (! font_not_found_p
22492 && font
->default_ascent
22493 && CHAR_TABLE_P (Vuse_default_ascent
)
22494 && !NILP (Faref (Vuse_default_ascent
,
22495 make_number (it
->char_to_display
))))
22496 highest
= font
->default_ascent
+ boff
;
22498 /* Draw the first glyph at the normal position. It may be
22499 shifted to right later if some other glyphs are drawn
22501 cmp
->offsets
[i
* 2] = 0;
22502 cmp
->offsets
[i
* 2 + 1] = boff
;
22503 cmp
->lbearing
= lbearing
;
22504 cmp
->rbearing
= rbearing
;
22506 /* Set cmp->offsets for the remaining glyphs. */
22507 for (i
++; i
< glyph_len
; i
++)
22509 int left
, right
, btm
, top
;
22510 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22512 struct face
*this_face
;
22517 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22518 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22519 font
= this_face
->font
;
22525 this_boff
= font
->baseline_offset
;
22526 if (font
->vertical_centering
)
22527 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22528 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22529 &char2b
, it
->multibyte_p
, 0);
22530 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22533 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22536 width
= pcm
->width
;
22537 ascent
= pcm
->ascent
;
22538 descent
= pcm
->descent
;
22539 lbearing
= pcm
->lbearing
;
22540 rbearing
= pcm
->rbearing
;
22541 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22543 /* Relative composition with or without
22544 alternate chars. */
22545 left
= (leftmost
+ rightmost
- width
) / 2;
22546 btm
= - descent
+ boff
;
22547 if (font
->relative_compose
22548 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22549 || NILP (Faref (Vignore_relative_composition
,
22550 make_number (ch
)))))
22553 if (- descent
>= font
->relative_compose
)
22554 /* One extra pixel between two glyphs. */
22556 else if (ascent
<= 0)
22557 /* One extra pixel between two glyphs. */
22558 btm
= lowest
- 1 - ascent
- descent
;
22563 /* A composition rule is specified by an integer
22564 value that encodes global and new reference
22565 points (GREF and NREF). GREF and NREF are
22566 specified by numbers as below:
22568 0---1---2 -- ascent
22572 9--10--11 -- center
22574 ---3---4---5--- baseline
22576 6---7---8 -- descent
22578 int rule
= COMPOSITION_RULE (cmp
, i
);
22579 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
22581 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
22582 grefx
= gref
% 3, nrefx
= nref
% 3;
22583 grefy
= gref
/ 3, nrefy
= nref
/ 3;
22585 xoff
= font_height
* (xoff
- 128) / 256;
22587 yoff
= font_height
* (yoff
- 128) / 256;
22590 + grefx
* (rightmost
- leftmost
) / 2
22591 - nrefx
* width
/ 2
22594 btm
= ((grefy
== 0 ? highest
22596 : grefy
== 2 ? lowest
22597 : (highest
+ lowest
) / 2)
22598 - (nrefy
== 0 ? ascent
+ descent
22599 : nrefy
== 1 ? descent
- boff
22601 : (ascent
+ descent
) / 2)
22605 cmp
->offsets
[i
* 2] = left
;
22606 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
22608 /* Update the bounding box of the overall glyphs. */
22611 right
= left
+ width
;
22612 if (left
< leftmost
)
22614 if (right
> rightmost
)
22617 top
= btm
+ descent
+ ascent
;
22623 if (cmp
->lbearing
> left
+ lbearing
)
22624 cmp
->lbearing
= left
+ lbearing
;
22625 if (cmp
->rbearing
< left
+ rbearing
)
22626 cmp
->rbearing
= left
+ rbearing
;
22630 /* If there are glyphs whose x-offsets are negative,
22631 shift all glyphs to the right and make all x-offsets
22635 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22636 cmp
->offsets
[i
* 2] -= leftmost
;
22637 rightmost
-= leftmost
;
22638 cmp
->lbearing
-= leftmost
;
22639 cmp
->rbearing
-= leftmost
;
22642 if (left_padded
&& cmp
->lbearing
< 0)
22644 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22645 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
22646 rightmost
-= cmp
->lbearing
;
22647 cmp
->rbearing
-= cmp
->lbearing
;
22650 if (right_padded
&& rightmost
< cmp
->rbearing
)
22652 rightmost
= cmp
->rbearing
;
22655 cmp
->pixel_width
= rightmost
;
22656 cmp
->ascent
= highest
;
22657 cmp
->descent
= - lowest
;
22658 if (cmp
->ascent
< font_ascent
)
22659 cmp
->ascent
= font_ascent
;
22660 if (cmp
->descent
< font_descent
)
22661 cmp
->descent
= font_descent
;
22665 && (cmp
->lbearing
< 0
22666 || cmp
->rbearing
> cmp
->pixel_width
))
22667 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22669 it
->pixel_width
= cmp
->pixel_width
;
22670 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
22671 it
->descent
= it
->phys_descent
= cmp
->descent
;
22672 if (face
->box
!= FACE_NO_BOX
)
22674 int thick
= face
->box_line_width
;
22678 it
->ascent
+= thick
;
22679 it
->descent
+= thick
;
22684 if (it
->start_of_box_run_p
)
22685 it
->pixel_width
+= thick
;
22686 if (it
->end_of_box_run_p
)
22687 it
->pixel_width
+= thick
;
22690 /* If face has an overline, add the height of the overline
22691 (1 pixel) and a 1 pixel margin to the character height. */
22692 if (face
->overline_p
)
22693 it
->ascent
+= overline_margin
;
22695 take_vertical_position_into_account (it
);
22696 if (it
->ascent
< 0)
22698 if (it
->descent
< 0)
22702 append_composite_glyph (it
);
22704 else if (it
->what
== IT_COMPOSITION
)
22706 /* A dynamic (automatic) composition. */
22707 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22708 Lisp_Object gstring
;
22709 struct font_metrics metrics
;
22711 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
22713 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
22716 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
22717 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22718 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
22719 it
->descent
= it
->phys_descent
= metrics
.descent
;
22720 if (face
->box
!= FACE_NO_BOX
)
22722 int thick
= face
->box_line_width
;
22726 it
->ascent
+= thick
;
22727 it
->descent
+= thick
;
22732 if (it
->start_of_box_run_p
)
22733 it
->pixel_width
+= thick
;
22734 if (it
->end_of_box_run_p
)
22735 it
->pixel_width
+= thick
;
22737 /* If face has an overline, add the height of the overline
22738 (1 pixel) and a 1 pixel margin to the character height. */
22739 if (face
->overline_p
)
22740 it
->ascent
+= overline_margin
;
22741 take_vertical_position_into_account (it
);
22742 if (it
->ascent
< 0)
22744 if (it
->descent
< 0)
22748 append_composite_glyph (it
);
22750 else if (it
->what
== IT_IMAGE
)
22751 produce_image_glyph (it
);
22752 else if (it
->what
== IT_STRETCH
)
22753 produce_stretch_glyph (it
);
22755 /* Accumulate dimensions. Note: can't assume that it->descent > 0
22756 because this isn't true for images with `:ascent 100'. */
22757 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
22758 if (it
->area
== TEXT_AREA
)
22759 it
->current_x
+= it
->pixel_width
;
22761 if (extra_line_spacing
> 0)
22763 it
->descent
+= extra_line_spacing
;
22764 if (extra_line_spacing
> it
->max_extra_line_spacing
)
22765 it
->max_extra_line_spacing
= extra_line_spacing
;
22768 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
22769 it
->max_descent
= max (it
->max_descent
, it
->descent
);
22770 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
22771 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
22775 Output LEN glyphs starting at START at the nominal cursor position.
22776 Advance the nominal cursor over the text. The global variable
22777 updated_window contains the window being updated, updated_row is
22778 the glyph row being updated, and updated_area is the area of that
22779 row being updated. */
22782 x_write_glyphs (start
, len
)
22783 struct glyph
*start
;
22788 xassert (updated_window
&& updated_row
);
22791 /* Write glyphs. */
22793 hpos
= start
- updated_row
->glyphs
[updated_area
];
22794 x
= draw_glyphs (updated_window
, output_cursor
.x
,
22795 updated_row
, updated_area
,
22797 DRAW_NORMAL_TEXT
, 0);
22799 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
22800 if (updated_area
== TEXT_AREA
22801 && updated_window
->phys_cursor_on_p
22802 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
22803 && updated_window
->phys_cursor
.hpos
>= hpos
22804 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
22805 updated_window
->phys_cursor_on_p
= 0;
22809 /* Advance the output cursor. */
22810 output_cursor
.hpos
+= len
;
22811 output_cursor
.x
= x
;
22816 Insert LEN glyphs from START at the nominal cursor position. */
22819 x_insert_glyphs (start
, len
)
22820 struct glyph
*start
;
22825 int line_height
, shift_by_width
, shifted_region_width
;
22826 struct glyph_row
*row
;
22827 struct glyph
*glyph
;
22828 int frame_x
, frame_y
;
22831 xassert (updated_window
&& updated_row
);
22833 w
= updated_window
;
22834 f
= XFRAME (WINDOW_FRAME (w
));
22836 /* Get the height of the line we are in. */
22838 line_height
= row
->height
;
22840 /* Get the width of the glyphs to insert. */
22841 shift_by_width
= 0;
22842 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
22843 shift_by_width
+= glyph
->pixel_width
;
22845 /* Get the width of the region to shift right. */
22846 shifted_region_width
= (window_box_width (w
, updated_area
)
22851 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
22852 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
22854 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
22855 line_height
, shift_by_width
);
22857 /* Write the glyphs. */
22858 hpos
= start
- row
->glyphs
[updated_area
];
22859 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
22861 DRAW_NORMAL_TEXT
, 0);
22863 /* Advance the output cursor. */
22864 output_cursor
.hpos
+= len
;
22865 output_cursor
.x
+= shift_by_width
;
22871 Erase the current text line from the nominal cursor position
22872 (inclusive) to pixel column TO_X (exclusive). The idea is that
22873 everything from TO_X onward is already erased.
22875 TO_X is a pixel position relative to updated_area of
22876 updated_window. TO_X == -1 means clear to the end of this area. */
22879 x_clear_end_of_line (to_x
)
22883 struct window
*w
= updated_window
;
22884 int max_x
, min_y
, max_y
;
22885 int from_x
, from_y
, to_y
;
22887 xassert (updated_window
&& updated_row
);
22888 f
= XFRAME (w
->frame
);
22890 if (updated_row
->full_width_p
)
22891 max_x
= WINDOW_TOTAL_WIDTH (w
);
22893 max_x
= window_box_width (w
, updated_area
);
22894 max_y
= window_text_bottom_y (w
);
22896 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
22897 of window. For TO_X > 0, truncate to end of drawing area. */
22903 to_x
= min (to_x
, max_x
);
22905 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
22907 /* Notice if the cursor will be cleared by this operation. */
22908 if (!updated_row
->full_width_p
)
22909 notice_overwritten_cursor (w
, updated_area
,
22910 output_cursor
.x
, -1,
22912 MATRIX_ROW_BOTTOM_Y (updated_row
));
22914 from_x
= output_cursor
.x
;
22916 /* Translate to frame coordinates. */
22917 if (updated_row
->full_width_p
)
22919 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
22920 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
22924 int area_left
= window_box_left (w
, updated_area
);
22925 from_x
+= area_left
;
22929 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22930 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22931 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22933 /* Prevent inadvertently clearing to end of the X window. */
22934 if (to_x
> from_x
&& to_y
> from_y
)
22937 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22938 to_x
- from_x
, to_y
- from_y
);
22943 #endif /* HAVE_WINDOW_SYSTEM */
22947 /***********************************************************************
22949 ***********************************************************************/
22951 /* Value is the internal representation of the specified cursor type
22952 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22953 of the bar cursor. */
22955 static enum text_cursor_kinds
22956 get_specified_cursor_type (arg
, width
)
22960 enum text_cursor_kinds type
;
22965 if (EQ (arg
, Qbox
))
22966 return FILLED_BOX_CURSOR
;
22968 if (EQ (arg
, Qhollow
))
22969 return HOLLOW_BOX_CURSOR
;
22971 if (EQ (arg
, Qbar
))
22978 && EQ (XCAR (arg
), Qbar
)
22979 && INTEGERP (XCDR (arg
))
22980 && XINT (XCDR (arg
)) >= 0)
22982 *width
= XINT (XCDR (arg
));
22986 if (EQ (arg
, Qhbar
))
22989 return HBAR_CURSOR
;
22993 && EQ (XCAR (arg
), Qhbar
)
22994 && INTEGERP (XCDR (arg
))
22995 && XINT (XCDR (arg
)) >= 0)
22997 *width
= XINT (XCDR (arg
));
22998 return HBAR_CURSOR
;
23001 /* Treat anything unknown as "hollow box cursor".
23002 It was bad to signal an error; people have trouble fixing
23003 .Xdefaults with Emacs, when it has something bad in it. */
23004 type
= HOLLOW_BOX_CURSOR
;
23009 /* Set the default cursor types for specified frame. */
23011 set_frame_cursor_types (f
, arg
)
23018 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23019 FRAME_CURSOR_WIDTH (f
) = width
;
23021 /* By default, set up the blink-off state depending on the on-state. */
23023 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23026 FRAME_BLINK_OFF_CURSOR (f
)
23027 = get_specified_cursor_type (XCDR (tem
), &width
);
23028 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23031 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23035 /* Return the cursor we want to be displayed in window W. Return
23036 width of bar/hbar cursor through WIDTH arg. Return with
23037 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23038 (i.e. if the `system caret' should track this cursor).
23040 In a mini-buffer window, we want the cursor only to appear if we
23041 are reading input from this window. For the selected window, we
23042 want the cursor type given by the frame parameter or buffer local
23043 setting of cursor-type. If explicitly marked off, draw no cursor.
23044 In all other cases, we want a hollow box cursor. */
23046 static enum text_cursor_kinds
23047 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
23049 struct glyph
*glyph
;
23051 int *active_cursor
;
23053 struct frame
*f
= XFRAME (w
->frame
);
23054 struct buffer
*b
= XBUFFER (w
->buffer
);
23055 int cursor_type
= DEFAULT_CURSOR
;
23056 Lisp_Object alt_cursor
;
23057 int non_selected
= 0;
23059 *active_cursor
= 1;
23062 if (cursor_in_echo_area
23063 && FRAME_HAS_MINIBUF_P (f
)
23064 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23066 if (w
== XWINDOW (echo_area_window
))
23068 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
23070 *width
= FRAME_CURSOR_WIDTH (f
);
23071 return FRAME_DESIRED_CURSOR (f
);
23074 return get_specified_cursor_type (b
->cursor_type
, width
);
23077 *active_cursor
= 0;
23081 /* Detect a nonselected window or nonselected frame. */
23082 else if (w
!= XWINDOW (f
->selected_window
)
23083 #ifdef HAVE_WINDOW_SYSTEM
23084 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
23088 *active_cursor
= 0;
23090 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23096 /* Never display a cursor in a window in which cursor-type is nil. */
23097 if (NILP (b
->cursor_type
))
23100 /* Get the normal cursor type for this window. */
23101 if (EQ (b
->cursor_type
, Qt
))
23103 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23104 *width
= FRAME_CURSOR_WIDTH (f
);
23107 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
23109 /* Use cursor-in-non-selected-windows instead
23110 for non-selected window or frame. */
23113 alt_cursor
= b
->cursor_in_non_selected_windows
;
23114 if (!EQ (Qt
, alt_cursor
))
23115 return get_specified_cursor_type (alt_cursor
, width
);
23116 /* t means modify the normal cursor type. */
23117 if (cursor_type
== FILLED_BOX_CURSOR
)
23118 cursor_type
= HOLLOW_BOX_CURSOR
;
23119 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23121 return cursor_type
;
23124 /* Use normal cursor if not blinked off. */
23125 if (!w
->cursor_off_p
)
23127 #ifdef HAVE_WINDOW_SYSTEM
23128 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23130 if (cursor_type
== FILLED_BOX_CURSOR
)
23132 /* Using a block cursor on large images can be very annoying.
23133 So use a hollow cursor for "large" images.
23134 If image is not transparent (no mask), also use hollow cursor. */
23135 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23136 if (img
!= NULL
&& IMAGEP (img
->spec
))
23138 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23139 where N = size of default frame font size.
23140 This should cover most of the "tiny" icons people may use. */
23142 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23143 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23144 cursor_type
= HOLLOW_BOX_CURSOR
;
23147 else if (cursor_type
!= NO_CURSOR
)
23149 /* Display current only supports BOX and HOLLOW cursors for images.
23150 So for now, unconditionally use a HOLLOW cursor when cursor is
23151 not a solid box cursor. */
23152 cursor_type
= HOLLOW_BOX_CURSOR
;
23156 return cursor_type
;
23159 /* Cursor is blinked off, so determine how to "toggle" it. */
23161 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23162 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
23163 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23165 /* Then see if frame has specified a specific blink off cursor type. */
23166 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23168 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23169 return FRAME_BLINK_OFF_CURSOR (f
);
23173 /* Some people liked having a permanently visible blinking cursor,
23174 while others had very strong opinions against it. So it was
23175 decided to remove it. KFS 2003-09-03 */
23177 /* Finally perform built-in cursor blinking:
23178 filled box <-> hollow box
23179 wide [h]bar <-> narrow [h]bar
23180 narrow [h]bar <-> no cursor
23181 other type <-> no cursor */
23183 if (cursor_type
== FILLED_BOX_CURSOR
)
23184 return HOLLOW_BOX_CURSOR
;
23186 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23189 return cursor_type
;
23197 #ifdef HAVE_WINDOW_SYSTEM
23199 /* Notice when the text cursor of window W has been completely
23200 overwritten by a drawing operation that outputs glyphs in AREA
23201 starting at X0 and ending at X1 in the line starting at Y0 and
23202 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23203 the rest of the line after X0 has been written. Y coordinates
23204 are window-relative. */
23207 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
23209 enum glyph_row_area area
;
23210 int x0
, y0
, x1
, y1
;
23212 int cx0
, cx1
, cy0
, cy1
;
23213 struct glyph_row
*row
;
23215 if (!w
->phys_cursor_on_p
)
23217 if (area
!= TEXT_AREA
)
23220 if (w
->phys_cursor
.vpos
< 0
23221 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23222 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23223 !(row
->enabled_p
&& row
->displays_text_p
)))
23226 if (row
->cursor_in_fringe_p
)
23228 row
->cursor_in_fringe_p
= 0;
23229 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
23230 w
->phys_cursor_on_p
= 0;
23234 cx0
= w
->phys_cursor
.x
;
23235 cx1
= cx0
+ w
->phys_cursor_width
;
23236 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23239 /* The cursor image will be completely removed from the
23240 screen if the output area intersects the cursor area in
23241 y-direction. When we draw in [y0 y1[, and some part of
23242 the cursor is at y < y0, that part must have been drawn
23243 before. When scrolling, the cursor is erased before
23244 actually scrolling, so we don't come here. When not
23245 scrolling, the rows above the old cursor row must have
23246 changed, and in this case these rows must have written
23247 over the cursor image.
23249 Likewise if part of the cursor is below y1, with the
23250 exception of the cursor being in the first blank row at
23251 the buffer and window end because update_text_area
23252 doesn't draw that row. (Except when it does, but
23253 that's handled in update_text_area.) */
23255 cy0
= w
->phys_cursor
.y
;
23256 cy1
= cy0
+ w
->phys_cursor_height
;
23257 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23260 w
->phys_cursor_on_p
= 0;
23263 #endif /* HAVE_WINDOW_SYSTEM */
23266 /************************************************************************
23268 ************************************************************************/
23270 #ifdef HAVE_WINDOW_SYSTEM
23273 Fix the display of area AREA of overlapping row ROW in window W
23274 with respect to the overlapping part OVERLAPS. */
23277 x_fix_overlapping_area (w
, row
, area
, overlaps
)
23279 struct glyph_row
*row
;
23280 enum glyph_row_area area
;
23288 for (i
= 0; i
< row
->used
[area
];)
23290 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23292 int start
= i
, start_x
= x
;
23296 x
+= row
->glyphs
[area
][i
].pixel_width
;
23299 while (i
< row
->used
[area
]
23300 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23302 draw_glyphs (w
, start_x
, row
, area
,
23304 DRAW_NORMAL_TEXT
, overlaps
);
23308 x
+= row
->glyphs
[area
][i
].pixel_width
;
23318 Draw the cursor glyph of window W in glyph row ROW. See the
23319 comment of draw_glyphs for the meaning of HL. */
23322 draw_phys_cursor_glyph (w
, row
, hl
)
23324 struct glyph_row
*row
;
23325 enum draw_glyphs_face hl
;
23327 /* If cursor hpos is out of bounds, don't draw garbage. This can
23328 happen in mini-buffer windows when switching between echo area
23329 glyphs and mini-buffer. */
23330 if ((row
->reversed_p
23331 ? (w
->phys_cursor
.hpos
>= 0)
23332 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
23334 int on_p
= w
->phys_cursor_on_p
;
23336 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23337 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23339 w
->phys_cursor_on_p
= on_p
;
23341 if (hl
== DRAW_CURSOR
)
23342 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23343 /* When we erase the cursor, and ROW is overlapped by other
23344 rows, make sure that these overlapping parts of other rows
23346 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23348 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23350 if (row
> w
->current_matrix
->rows
23351 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23352 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23353 OVERLAPS_ERASED_CURSOR
);
23355 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23356 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23357 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23358 OVERLAPS_ERASED_CURSOR
);
23365 Erase the image of a cursor of window W from the screen. */
23368 erase_phys_cursor (w
)
23371 struct frame
*f
= XFRAME (w
->frame
);
23372 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23373 int hpos
= w
->phys_cursor
.hpos
;
23374 int vpos
= w
->phys_cursor
.vpos
;
23375 int mouse_face_here_p
= 0;
23376 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23377 struct glyph_row
*cursor_row
;
23378 struct glyph
*cursor_glyph
;
23379 enum draw_glyphs_face hl
;
23381 /* No cursor displayed or row invalidated => nothing to do on the
23383 if (w
->phys_cursor_type
== NO_CURSOR
)
23384 goto mark_cursor_off
;
23386 /* VPOS >= active_glyphs->nrows means that window has been resized.
23387 Don't bother to erase the cursor. */
23388 if (vpos
>= active_glyphs
->nrows
)
23389 goto mark_cursor_off
;
23391 /* If row containing cursor is marked invalid, there is nothing we
23393 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23394 if (!cursor_row
->enabled_p
)
23395 goto mark_cursor_off
;
23397 /* If line spacing is > 0, old cursor may only be partially visible in
23398 window after split-window. So adjust visible height. */
23399 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23400 window_text_bottom_y (w
) - cursor_row
->y
);
23402 /* If row is completely invisible, don't attempt to delete a cursor which
23403 isn't there. This can happen if cursor is at top of a window, and
23404 we switch to a buffer with a header line in that window. */
23405 if (cursor_row
->visible_height
<= 0)
23406 goto mark_cursor_off
;
23408 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23409 if (cursor_row
->cursor_in_fringe_p
)
23411 cursor_row
->cursor_in_fringe_p
= 0;
23412 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
23413 goto mark_cursor_off
;
23416 /* This can happen when the new row is shorter than the old one.
23417 In this case, either draw_glyphs or clear_end_of_line
23418 should have cleared the cursor. Note that we wouldn't be
23419 able to erase the cursor in this case because we don't have a
23420 cursor glyph at hand. */
23421 if ((cursor_row
->reversed_p
23422 ? (w
->phys_cursor
.hpos
< 0)
23423 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
23424 goto mark_cursor_off
;
23426 /* If the cursor is in the mouse face area, redisplay that when
23427 we clear the cursor. */
23428 if (! NILP (dpyinfo
->mouse_face_window
)
23429 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
23430 && (vpos
> dpyinfo
->mouse_face_beg_row
23431 || (vpos
== dpyinfo
->mouse_face_beg_row
23432 && hpos
>= dpyinfo
->mouse_face_beg_col
))
23433 && (vpos
< dpyinfo
->mouse_face_end_row
23434 || (vpos
== dpyinfo
->mouse_face_end_row
23435 && hpos
< dpyinfo
->mouse_face_end_col
))
23436 /* Don't redraw the cursor's spot in mouse face if it is at the
23437 end of a line (on a newline). The cursor appears there, but
23438 mouse highlighting does not. */
23439 && cursor_row
->used
[TEXT_AREA
] > hpos
)
23440 mouse_face_here_p
= 1;
23442 /* Maybe clear the display under the cursor. */
23443 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23446 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23449 cursor_glyph
= get_phys_cursor_glyph (w
);
23450 if (cursor_glyph
== NULL
)
23451 goto mark_cursor_off
;
23453 width
= cursor_glyph
->pixel_width
;
23454 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23455 x
= w
->phys_cursor
.x
;
23457 width
-= left_x
- x
;
23458 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23459 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23460 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23463 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23466 /* Erase the cursor by redrawing the character underneath it. */
23467 if (mouse_face_here_p
)
23468 hl
= DRAW_MOUSE_FACE
;
23470 hl
= DRAW_NORMAL_TEXT
;
23471 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23474 w
->phys_cursor_on_p
= 0;
23475 w
->phys_cursor_type
= NO_CURSOR
;
23480 Display or clear cursor of window W. If ON is zero, clear the
23481 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23482 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23485 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
23487 int on
, hpos
, vpos
, x
, y
;
23489 struct frame
*f
= XFRAME (w
->frame
);
23490 int new_cursor_type
;
23491 int new_cursor_width
;
23493 struct glyph_row
*glyph_row
;
23494 struct glyph
*glyph
;
23496 /* This is pointless on invisible frames, and dangerous on garbaged
23497 windows and frames; in the latter case, the frame or window may
23498 be in the midst of changing its size, and x and y may be off the
23500 if (! FRAME_VISIBLE_P (f
)
23501 || FRAME_GARBAGED_P (f
)
23502 || vpos
>= w
->current_matrix
->nrows
23503 || hpos
>= w
->current_matrix
->matrix_w
)
23506 /* If cursor is off and we want it off, return quickly. */
23507 if (!on
&& !w
->phys_cursor_on_p
)
23510 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23511 /* If cursor row is not enabled, we don't really know where to
23512 display the cursor. */
23513 if (!glyph_row
->enabled_p
)
23515 w
->phys_cursor_on_p
= 0;
23520 if (!glyph_row
->exact_window_width_line_p
23521 || hpos
< glyph_row
->used
[TEXT_AREA
])
23522 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23524 xassert (interrupt_input_blocked
);
23526 /* Set new_cursor_type to the cursor we want to be displayed. */
23527 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23528 &new_cursor_width
, &active_cursor
);
23530 /* If cursor is currently being shown and we don't want it to be or
23531 it is in the wrong place, or the cursor type is not what we want,
23533 if (w
->phys_cursor_on_p
23535 || w
->phys_cursor
.x
!= x
23536 || w
->phys_cursor
.y
!= y
23537 || new_cursor_type
!= w
->phys_cursor_type
23538 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23539 && new_cursor_width
!= w
->phys_cursor_width
)))
23540 erase_phys_cursor (w
);
23542 /* Don't check phys_cursor_on_p here because that flag is only set
23543 to zero in some cases where we know that the cursor has been
23544 completely erased, to avoid the extra work of erasing the cursor
23545 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23546 still not be visible, or it has only been partly erased. */
23549 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23550 w
->phys_cursor_height
= glyph_row
->height
;
23552 /* Set phys_cursor_.* before x_draw_.* is called because some
23553 of them may need the information. */
23554 w
->phys_cursor
.x
= x
;
23555 w
->phys_cursor
.y
= glyph_row
->y
;
23556 w
->phys_cursor
.hpos
= hpos
;
23557 w
->phys_cursor
.vpos
= vpos
;
23560 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23561 new_cursor_type
, new_cursor_width
,
23562 on
, active_cursor
);
23566 /* Switch the display of W's cursor on or off, according to the value
23570 update_window_cursor (w
, on
)
23574 /* Don't update cursor in windows whose frame is in the process
23575 of being deleted. */
23576 if (w
->current_matrix
)
23579 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23580 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23586 /* Call update_window_cursor with parameter ON_P on all leaf windows
23587 in the window tree rooted at W. */
23590 update_cursor_in_window_tree (w
, on_p
)
23596 if (!NILP (w
->hchild
))
23597 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23598 else if (!NILP (w
->vchild
))
23599 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23601 update_window_cursor (w
, on_p
);
23603 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23609 Display the cursor on window W, or clear it, according to ON_P.
23610 Don't change the cursor's position. */
23613 x_update_cursor (f
, on_p
)
23617 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
23622 Clear the cursor of window W to background color, and mark the
23623 cursor as not shown. This is used when the text where the cursor
23624 is about to be rewritten. */
23630 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
23631 update_window_cursor (w
, 0);
23636 Display the active region described by mouse_face_* according to DRAW. */
23639 show_mouse_face (dpyinfo
, draw
)
23640 Display_Info
*dpyinfo
;
23641 enum draw_glyphs_face draw
;
23643 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
23644 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23646 if (/* If window is in the process of being destroyed, don't bother
23648 w
->current_matrix
!= NULL
23649 /* Don't update mouse highlight if hidden */
23650 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
23651 /* Recognize when we are called to operate on rows that don't exist
23652 anymore. This can happen when a window is split. */
23653 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
23655 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
23656 struct glyph_row
*row
, *first
, *last
;
23658 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
23659 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
23661 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
23663 int start_hpos
, end_hpos
, start_x
;
23665 /* For all but the first row, the highlight starts at column 0. */
23668 start_hpos
= dpyinfo
->mouse_face_beg_col
;
23669 start_x
= dpyinfo
->mouse_face_beg_x
;
23678 end_hpos
= dpyinfo
->mouse_face_end_col
;
23681 end_hpos
= row
->used
[TEXT_AREA
];
23682 if (draw
== DRAW_NORMAL_TEXT
)
23683 row
->fill_line_p
= 1; /* Clear to end of line */
23686 if (end_hpos
> start_hpos
)
23688 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
23689 start_hpos
, end_hpos
,
23693 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
23697 /* When we've written over the cursor, arrange for it to
23698 be displayed again. */
23699 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
23702 display_and_set_cursor (w
, 1,
23703 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23704 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23709 /* Change the mouse cursor. */
23710 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
23711 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
23712 else if (draw
== DRAW_MOUSE_FACE
)
23713 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
23715 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
23719 Clear out the mouse-highlighted active region.
23720 Redraw it un-highlighted first. Value is non-zero if mouse
23721 face was actually drawn unhighlighted. */
23724 clear_mouse_face (dpyinfo
)
23725 Display_Info
*dpyinfo
;
23729 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
23731 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
23735 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23736 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23737 dpyinfo
->mouse_face_window
= Qnil
;
23738 dpyinfo
->mouse_face_overlay
= Qnil
;
23744 Non-zero if physical cursor of window W is within mouse face. */
23747 cursor_in_mouse_face_p (w
)
23750 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23751 int in_mouse_face
= 0;
23753 if (WINDOWP (dpyinfo
->mouse_face_window
)
23754 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
23756 int hpos
= w
->phys_cursor
.hpos
;
23757 int vpos
= w
->phys_cursor
.vpos
;
23759 if (vpos
>= dpyinfo
->mouse_face_beg_row
23760 && vpos
<= dpyinfo
->mouse_face_end_row
23761 && (vpos
> dpyinfo
->mouse_face_beg_row
23762 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23763 && (vpos
< dpyinfo
->mouse_face_end_row
23764 || hpos
< dpyinfo
->mouse_face_end_col
23765 || dpyinfo
->mouse_face_past_end
))
23769 return in_mouse_face
;
23775 /* This function sets the mouse_face_* elements of DPYINFO, assuming
23776 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
23777 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
23778 for the overlay or run of text properties specifying the mouse
23779 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
23780 before-string and after-string that must also be highlighted.
23781 DISPLAY_STRING, if non-nil, is a display string that may cover some
23782 or all of the highlighted text. */
23785 mouse_face_from_buffer_pos (Lisp_Object window
,
23786 Display_Info
*dpyinfo
,
23787 EMACS_INT mouse_charpos
,
23788 EMACS_INT start_charpos
,
23789 EMACS_INT end_charpos
,
23790 Lisp_Object before_string
,
23791 Lisp_Object after_string
,
23792 Lisp_Object display_string
)
23794 struct window
*w
= XWINDOW (window
);
23795 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23796 struct glyph_row
*row
;
23797 struct glyph
*glyph
, *end
;
23801 xassert (NILP (display_string
) || STRINGP (display_string
));
23802 xassert (NILP (before_string
) || STRINGP (before_string
));
23803 xassert (NILP (after_string
) || STRINGP (after_string
));
23805 /* Find the first highlighted glyph. */
23806 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
23808 dpyinfo
->mouse_face_beg_col
= 0;
23809 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
23810 dpyinfo
->mouse_face_beg_x
= first
->x
;
23811 dpyinfo
->mouse_face_beg_y
= first
->y
;
23815 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
23817 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23819 /* If the before-string or display-string contains newlines,
23820 row_containing_pos skips to its last row. Move back. */
23821 if (!NILP (before_string
) || !NILP (display_string
))
23823 struct glyph_row
*prev
;
23824 while ((prev
= row
- 1, prev
>= first
)
23825 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
23826 && prev
->used
[TEXT_AREA
] > 0)
23828 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
23829 glyph
= beg
+ prev
->used
[TEXT_AREA
];
23830 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
23832 || !(EQ (glyph
->object
, before_string
)
23833 || EQ (glyph
->object
, display_string
)))
23839 glyph
= row
->glyphs
[TEXT_AREA
];
23840 end
= glyph
+ row
->used
[TEXT_AREA
];
23842 dpyinfo
->mouse_face_beg_y
= row
->y
;
23843 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23845 /* Skip truncation glyphs at the start of the glyph row. */
23846 if (row
->displays_text_p
)
23848 && INTEGERP (glyph
->object
)
23849 && glyph
->charpos
< 0;
23851 x
+= glyph
->pixel_width
;
23853 /* Scan the glyph row, stopping before BEFORE_STRING or
23854 DISPLAY_STRING or START_CHARPOS. */
23856 && !INTEGERP (glyph
->object
)
23857 && !EQ (glyph
->object
, before_string
)
23858 && !EQ (glyph
->object
, display_string
)
23859 && !(BUFFERP (glyph
->object
)
23860 && glyph
->charpos
>= start_charpos
);
23862 x
+= glyph
->pixel_width
;
23864 dpyinfo
->mouse_face_beg_x
= x
;
23865 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23868 /* Find the last highlighted glyph. */
23869 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
23872 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23873 dpyinfo
->mouse_face_past_end
= 1;
23875 else if (!NILP (after_string
))
23877 /* If the after-string has newlines, advance to its last row. */
23878 struct glyph_row
*next
;
23879 struct glyph_row
*last
23880 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23882 for (next
= row
+ 1;
23884 && next
->used
[TEXT_AREA
] > 0
23885 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
23890 glyph
= row
->glyphs
[TEXT_AREA
];
23891 end
= glyph
+ row
->used
[TEXT_AREA
];
23893 dpyinfo
->mouse_face_end_y
= row
->y
;
23894 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23896 /* Skip truncation glyphs at the start of the row. */
23897 if (row
->displays_text_p
)
23899 && INTEGERP (glyph
->object
)
23900 && glyph
->charpos
< 0;
23902 x
+= glyph
->pixel_width
;
23904 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
23907 && !INTEGERP (glyph
->object
)
23908 && !EQ (glyph
->object
, after_string
)
23909 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
23911 x
+= glyph
->pixel_width
;
23913 /* If we found AFTER_STRING, consume it and stop. */
23914 if (EQ (glyph
->object
, after_string
))
23916 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
23917 x
+= glyph
->pixel_width
;
23921 /* If there's no after-string, we must check if we overshot,
23922 which might be the case if we stopped after a string glyph.
23923 That glyph may belong to a before-string or display-string
23924 associated with the end position, which must not be
23926 Lisp_Object prev_object
;
23929 while (glyph
> row
->glyphs
[TEXT_AREA
])
23931 prev_object
= (glyph
- 1)->object
;
23932 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23935 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23936 if (pos
&& pos
< end_charpos
)
23939 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23940 && EQ ((glyph
- 1)->object
, prev_object
);
23942 x
-= (glyph
- 1)->pixel_width
;
23946 dpyinfo
->mouse_face_end_x
= x
;
23947 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23948 dpyinfo
->mouse_face_window
= window
;
23949 dpyinfo
->mouse_face_face_id
23950 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23952 !dpyinfo
->mouse_face_hidden
, -1);
23953 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23957 /* Find the position of the glyph for position POS in OBJECT in
23958 window W's current matrix, and return in *X, *Y the pixel
23959 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23961 RIGHT_P non-zero means return the position of the right edge of the
23962 glyph, RIGHT_P zero means return the left edge position.
23964 If no glyph for POS exists in the matrix, return the position of
23965 the glyph with the next smaller position that is in the matrix, if
23966 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23967 exists in the matrix, return the position of the glyph with the
23968 next larger position in OBJECT.
23970 Value is non-zero if a glyph was found. */
23973 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23976 Lisp_Object object
;
23977 int *hpos
, *vpos
, *x
, *y
;
23980 int yb
= window_text_bottom_y (w
);
23981 struct glyph_row
*r
;
23982 struct glyph
*best_glyph
= NULL
;
23983 struct glyph_row
*best_row
= NULL
;
23986 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23987 r
->enabled_p
&& r
->y
< yb
;
23990 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23991 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23994 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23995 if (EQ (g
->object
, object
))
23997 if (g
->charpos
== pos
)
24004 else if (best_glyph
== NULL
24005 || ((eabs (g
->charpos
- pos
)
24006 < eabs (best_glyph
->charpos
- pos
))
24009 : g
->charpos
> pos
)))
24023 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
24027 *x
+= best_glyph
->pixel_width
;
24032 *vpos
= best_row
- w
->current_matrix
->rows
;
24035 return best_glyph
!= NULL
;
24039 /* See if position X, Y is within a hot-spot of an image. */
24042 on_hot_spot_p (hot_spot
, x
, y
)
24043 Lisp_Object hot_spot
;
24046 if (!CONSP (hot_spot
))
24049 if (EQ (XCAR (hot_spot
), Qrect
))
24051 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
24052 Lisp_Object rect
= XCDR (hot_spot
);
24056 if (!CONSP (XCAR (rect
)))
24058 if (!CONSP (XCDR (rect
)))
24060 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
24062 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
24064 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
24066 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
24070 else if (EQ (XCAR (hot_spot
), Qcircle
))
24072 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
24073 Lisp_Object circ
= XCDR (hot_spot
);
24074 Lisp_Object lr
, lx0
, ly0
;
24076 && CONSP (XCAR (circ
))
24077 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
24078 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
24079 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
24081 double r
= XFLOATINT (lr
);
24082 double dx
= XINT (lx0
) - x
;
24083 double dy
= XINT (ly0
) - y
;
24084 return (dx
* dx
+ dy
* dy
<= r
* r
);
24087 else if (EQ (XCAR (hot_spot
), Qpoly
))
24089 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
24090 if (VECTORP (XCDR (hot_spot
)))
24092 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
24093 Lisp_Object
*poly
= v
->contents
;
24097 Lisp_Object lx
, ly
;
24100 /* Need an even number of coordinates, and at least 3 edges. */
24101 if (n
< 6 || n
& 1)
24104 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
24105 If count is odd, we are inside polygon. Pixels on edges
24106 may or may not be included depending on actual geometry of the
24108 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
24109 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
24111 x0
= XINT (lx
), y0
= XINT (ly
);
24112 for (i
= 0; i
< n
; i
+= 2)
24114 int x1
= x0
, y1
= y0
;
24115 if ((lx
= poly
[i
], !INTEGERP (lx
))
24116 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
24118 x0
= XINT (lx
), y0
= XINT (ly
);
24120 /* Does this segment cross the X line? */
24128 if (y
> y0
&& y
> y1
)
24130 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
24140 find_hot_spot (map
, x
, y
)
24144 while (CONSP (map
))
24146 if (CONSP (XCAR (map
))
24147 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
24155 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
24157 doc
: /* Lookup in image map MAP coordinates X and Y.
24158 An image map is an alist where each element has the format (AREA ID PLIST).
24159 An AREA is specified as either a rectangle, a circle, or a polygon:
24160 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
24161 pixel coordinates of the upper left and bottom right corners.
24162 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
24163 and the radius of the circle; r may be a float or integer.
24164 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
24165 vector describes one corner in the polygon.
24166 Returns the alist element for the first matching AREA in MAP. */)
24177 return find_hot_spot (map
, XINT (x
), XINT (y
));
24181 /* Display frame CURSOR, optionally using shape defined by POINTER. */
24183 define_frame_cursor1 (f
, cursor
, pointer
)
24186 Lisp_Object pointer
;
24188 /* Do not change cursor shape while dragging mouse. */
24189 if (!NILP (do_mouse_tracking
))
24192 if (!NILP (pointer
))
24194 if (EQ (pointer
, Qarrow
))
24195 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24196 else if (EQ (pointer
, Qhand
))
24197 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
24198 else if (EQ (pointer
, Qtext
))
24199 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24200 else if (EQ (pointer
, intern ("hdrag")))
24201 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24202 #ifdef HAVE_X_WINDOWS
24203 else if (EQ (pointer
, intern ("vdrag")))
24204 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
24206 else if (EQ (pointer
, intern ("hourglass")))
24207 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
24208 else if (EQ (pointer
, Qmodeline
))
24209 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
24211 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24214 if (cursor
!= No_Cursor
)
24215 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
24218 /* Take proper action when mouse has moved to the mode or header line
24219 or marginal area AREA of window W, x-position X and y-position Y.
24220 X is relative to the start of the text display area of W, so the
24221 width of bitmap areas and scroll bars must be subtracted to get a
24222 position relative to the start of the mode line. */
24225 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
24226 Lisp_Object window
;
24228 enum window_part area
;
24230 struct window
*w
= XWINDOW (window
);
24231 struct frame
*f
= XFRAME (w
->frame
);
24232 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24233 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24234 Lisp_Object pointer
= Qnil
;
24235 int charpos
, dx
, dy
, width
, height
;
24236 Lisp_Object string
, object
= Qnil
;
24237 Lisp_Object pos
, help
;
24239 Lisp_Object mouse_face
;
24240 int original_x_pixel
= x
;
24241 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
24242 struct glyph_row
*row
;
24244 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
24249 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
24250 &object
, &dx
, &dy
, &width
, &height
);
24252 row
= (area
== ON_MODE_LINE
24253 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
24254 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
24257 if (row
->mode_line_p
&& row
->enabled_p
)
24259 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
24260 end
= glyph
+ row
->used
[TEXT_AREA
];
24262 for (x0
= original_x_pixel
;
24263 glyph
< end
&& x0
>= glyph
->pixel_width
;
24265 x0
-= glyph
->pixel_width
;
24273 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
24274 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
24275 &object
, &dx
, &dy
, &width
, &height
);
24280 if (IMAGEP (object
))
24282 Lisp_Object image_map
, hotspot
;
24283 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
24285 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
24287 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24289 Lisp_Object area_id
, plist
;
24291 area_id
= XCAR (hotspot
);
24292 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24293 If so, we could look for mouse-enter, mouse-leave
24294 properties in PLIST (and do something...). */
24295 hotspot
= XCDR (hotspot
);
24296 if (CONSP (hotspot
)
24297 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24299 pointer
= Fplist_get (plist
, Qpointer
);
24300 if (NILP (pointer
))
24302 help
= Fplist_get (plist
, Qhelp_echo
);
24305 help_echo_string
= help
;
24306 /* Is this correct? ++kfs */
24307 XSETWINDOW (help_echo_window
, w
);
24308 help_echo_object
= w
->buffer
;
24309 help_echo_pos
= charpos
;
24313 if (NILP (pointer
))
24314 pointer
= Fplist_get (XCDR (object
), QCpointer
);
24317 if (STRINGP (string
))
24319 pos
= make_number (charpos
);
24320 /* If we're on a string with `help-echo' text property, arrange
24321 for the help to be displayed. This is done by setting the
24322 global variable help_echo_string to the help string. */
24325 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
24328 help_echo_string
= help
;
24329 XSETWINDOW (help_echo_window
, w
);
24330 help_echo_object
= string
;
24331 help_echo_pos
= charpos
;
24335 if (NILP (pointer
))
24336 pointer
= Fget_text_property (pos
, Qpointer
, string
);
24338 /* Change the mouse pointer according to what is under X/Y. */
24339 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
24342 map
= Fget_text_property (pos
, Qlocal_map
, string
);
24343 if (!KEYMAPP (map
))
24344 map
= Fget_text_property (pos
, Qkeymap
, string
);
24345 if (!KEYMAPP (map
))
24346 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
24349 /* Change the mouse face according to what is under X/Y. */
24350 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
24351 if (!NILP (mouse_face
)
24352 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24357 struct glyph
* tmp_glyph
;
24361 int total_pixel_width
;
24366 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
24367 Qmouse_face
, string
, Qnil
);
24369 b
= make_number (0);
24371 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
24373 e
= make_number (SCHARS (string
));
24375 /* Calculate the position(glyph position: GPOS) of GLYPH in
24376 displayed string. GPOS is different from CHARPOS.
24378 CHARPOS is the position of glyph in internal string
24379 object. A mode line string format has structures which
24380 is converted to a flatten by emacs lisp interpreter.
24381 The internal string is an element of the structures.
24382 The displayed string is the flatten string. */
24384 if (glyph
> row_start_glyph
)
24386 tmp_glyph
= glyph
- 1;
24387 while (tmp_glyph
>= row_start_glyph
24388 && tmp_glyph
->charpos
>= XINT (b
)
24389 && EQ (tmp_glyph
->object
, glyph
->object
))
24396 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
24397 displayed string holding GLYPH.
24399 GSEQ_LENGTH is different from SCHARS (STRING).
24400 SCHARS (STRING) returns the length of the internal string. */
24401 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
24402 tmp_glyph
->charpos
< XINT (e
);
24403 tmp_glyph
++, gseq_length
++)
24405 if (!EQ (tmp_glyph
->object
, glyph
->object
))
24409 total_pixel_width
= 0;
24410 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
24411 total_pixel_width
+= tmp_glyph
->pixel_width
;
24413 /* Pre calculation of re-rendering position */
24415 hpos
= (area
== ON_MODE_LINE
24416 ? (w
->current_matrix
)->nrows
- 1
24419 /* If the re-rendering position is included in the last
24420 re-rendering area, we should do nothing. */
24421 if ( EQ (window
, dpyinfo
->mouse_face_window
)
24422 && dpyinfo
->mouse_face_beg_col
<= vpos
24423 && vpos
< dpyinfo
->mouse_face_end_col
24424 && dpyinfo
->mouse_face_beg_row
== hpos
)
24427 if (clear_mouse_face (dpyinfo
))
24428 cursor
= No_Cursor
;
24430 dpyinfo
->mouse_face_beg_col
= vpos
;
24431 dpyinfo
->mouse_face_beg_row
= hpos
;
24433 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
24434 dpyinfo
->mouse_face_beg_y
= 0;
24436 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
24437 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
24439 dpyinfo
->mouse_face_end_x
= 0;
24440 dpyinfo
->mouse_face_end_y
= 0;
24442 dpyinfo
->mouse_face_past_end
= 0;
24443 dpyinfo
->mouse_face_window
= window
;
24445 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
24448 glyph
->face_id
, 1);
24449 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24451 if (NILP (pointer
))
24454 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24455 clear_mouse_face (dpyinfo
);
24457 define_frame_cursor1 (f
, cursor
, pointer
);
24462 Take proper action when the mouse has moved to position X, Y on
24463 frame F as regards highlighting characters that have mouse-face
24464 properties. Also de-highlighting chars where the mouse was before.
24465 X and Y can be negative or out of range. */
24468 note_mouse_highlight (f
, x
, y
)
24472 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24473 enum window_part part
;
24474 Lisp_Object window
;
24476 Cursor cursor
= No_Cursor
;
24477 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
24480 /* When a menu is active, don't highlight because this looks odd. */
24481 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
24482 if (popup_activated ())
24486 if (NILP (Vmouse_highlight
)
24487 || !f
->glyphs_initialized_p
24488 || f
->pointer_invisible
)
24491 dpyinfo
->mouse_face_mouse_x
= x
;
24492 dpyinfo
->mouse_face_mouse_y
= y
;
24493 dpyinfo
->mouse_face_mouse_frame
= f
;
24495 if (dpyinfo
->mouse_face_defer
)
24498 if (gc_in_progress
)
24500 dpyinfo
->mouse_face_deferred_gc
= 1;
24504 /* Which window is that in? */
24505 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
24507 /* If we were displaying active text in another window, clear that.
24508 Also clear if we move out of text area in same window. */
24509 if (! EQ (window
, dpyinfo
->mouse_face_window
)
24510 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
24511 && !NILP (dpyinfo
->mouse_face_window
)))
24512 clear_mouse_face (dpyinfo
);
24514 /* Not on a window -> return. */
24515 if (!WINDOWP (window
))
24518 /* Reset help_echo_string. It will get recomputed below. */
24519 help_echo_string
= Qnil
;
24521 /* Convert to window-relative pixel coordinates. */
24522 w
= XWINDOW (window
);
24523 frame_to_window_pixel_xy (w
, &x
, &y
);
24525 /* Handle tool-bar window differently since it doesn't display a
24527 if (EQ (window
, f
->tool_bar_window
))
24529 note_tool_bar_highlight (f
, x
, y
);
24533 /* Mouse is on the mode, header line or margin? */
24534 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
24535 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
24537 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
24541 if (part
== ON_VERTICAL_BORDER
)
24543 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24544 help_echo_string
= build_string ("drag-mouse-1: resize");
24546 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
24547 || part
== ON_SCROLL_BAR
)
24548 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24550 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24552 /* Are we in a window whose display is up to date?
24553 And verify the buffer's text has not changed. */
24554 b
= XBUFFER (w
->buffer
);
24555 if (part
== ON_TEXT
24556 && EQ (w
->window_end_valid
, w
->buffer
)
24557 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
24558 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
24560 int hpos
, vpos
, i
, dx
, dy
, area
;
24562 struct glyph
*glyph
;
24563 Lisp_Object object
;
24564 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
24565 Lisp_Object
*overlay_vec
= NULL
;
24567 struct buffer
*obuf
;
24568 int obegv
, ozv
, same_region
;
24570 /* Find the glyph under X/Y. */
24571 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
24573 /* Look for :pointer property on image. */
24574 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24576 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24577 if (img
!= NULL
&& IMAGEP (img
->spec
))
24579 Lisp_Object image_map
, hotspot
;
24580 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
24582 && (hotspot
= find_hot_spot (image_map
,
24583 glyph
->slice
.x
+ dx
,
24584 glyph
->slice
.y
+ dy
),
24586 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24588 Lisp_Object area_id
, plist
;
24590 area_id
= XCAR (hotspot
);
24591 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24592 If so, we could look for mouse-enter, mouse-leave
24593 properties in PLIST (and do something...). */
24594 hotspot
= XCDR (hotspot
);
24595 if (CONSP (hotspot
)
24596 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24598 pointer
= Fplist_get (plist
, Qpointer
);
24599 if (NILP (pointer
))
24601 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
24602 if (!NILP (help_echo_string
))
24604 help_echo_window
= window
;
24605 help_echo_object
= glyph
->object
;
24606 help_echo_pos
= glyph
->charpos
;
24610 if (NILP (pointer
))
24611 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
24615 /* Clear mouse face if X/Y not over text. */
24617 || area
!= TEXT_AREA
24618 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
24620 if (clear_mouse_face (dpyinfo
))
24621 cursor
= No_Cursor
;
24622 if (NILP (pointer
))
24624 if (area
!= TEXT_AREA
)
24625 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24627 pointer
= Vvoid_text_area_pointer
;
24632 pos
= glyph
->charpos
;
24633 object
= glyph
->object
;
24634 if (!STRINGP (object
) && !BUFFERP (object
))
24637 /* If we get an out-of-range value, return now; avoid an error. */
24638 if (BUFFERP (object
) && pos
> BUF_Z (b
))
24641 /* Make the window's buffer temporarily current for
24642 overlays_at and compute_char_face. */
24643 obuf
= current_buffer
;
24644 current_buffer
= b
;
24650 /* Is this char mouse-active or does it have help-echo? */
24651 position
= make_number (pos
);
24653 if (BUFFERP (object
))
24655 /* Put all the overlays we want in a vector in overlay_vec. */
24656 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
24657 /* Sort overlays into increasing priority order. */
24658 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
24663 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
24664 && vpos
>= dpyinfo
->mouse_face_beg_row
24665 && vpos
<= dpyinfo
->mouse_face_end_row
24666 && (vpos
> dpyinfo
->mouse_face_beg_row
24667 || hpos
>= dpyinfo
->mouse_face_beg_col
)
24668 && (vpos
< dpyinfo
->mouse_face_end_row
24669 || hpos
< dpyinfo
->mouse_face_end_col
24670 || dpyinfo
->mouse_face_past_end
));
24673 cursor
= No_Cursor
;
24675 /* Check mouse-face highlighting. */
24677 /* If there exists an overlay with mouse-face overlapping
24678 the one we are currently highlighting, we have to
24679 check if we enter the overlapping overlay, and then
24680 highlight only that. */
24681 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
24682 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
24684 /* Find the highest priority overlay with a mouse-face. */
24686 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
24688 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
24689 if (!NILP (mouse_face
))
24690 overlay
= overlay_vec
[i
];
24693 /* If we're highlighting the same overlay as before, there's
24694 no need to do that again. */
24695 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
24696 goto check_help_echo
;
24697 dpyinfo
->mouse_face_overlay
= overlay
;
24699 /* Clear the display of the old active region, if any. */
24700 if (clear_mouse_face (dpyinfo
))
24701 cursor
= No_Cursor
;
24703 /* If no overlay applies, get a text property. */
24704 if (NILP (overlay
))
24705 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
24707 /* Next, compute the bounds of the mouse highlighting and
24709 if (!NILP (mouse_face
) && STRINGP (object
))
24711 /* The mouse-highlighting comes from a display string
24712 with a mouse-face. */
24716 b
= Fprevious_single_property_change
24717 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
24718 e
= Fnext_single_property_change
24719 (position
, Qmouse_face
, object
, Qnil
);
24721 b
= make_number (0);
24723 e
= make_number (SCHARS (object
) - 1);
24725 fast_find_string_pos (w
, XINT (b
), object
,
24726 &dpyinfo
->mouse_face_beg_col
,
24727 &dpyinfo
->mouse_face_beg_row
,
24728 &dpyinfo
->mouse_face_beg_x
,
24729 &dpyinfo
->mouse_face_beg_y
, 0);
24730 fast_find_string_pos (w
, XINT (e
), object
,
24731 &dpyinfo
->mouse_face_end_col
,
24732 &dpyinfo
->mouse_face_end_row
,
24733 &dpyinfo
->mouse_face_end_x
,
24734 &dpyinfo
->mouse_face_end_y
, 1);
24735 dpyinfo
->mouse_face_past_end
= 0;
24736 dpyinfo
->mouse_face_window
= window
;
24737 dpyinfo
->mouse_face_face_id
24738 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
24739 glyph
->face_id
, 1);
24740 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24741 cursor
= No_Cursor
;
24745 /* The mouse-highlighting, if any, comes from an overlay
24746 or text property in the buffer. */
24747 Lisp_Object buffer
, display_string
;
24749 if (STRINGP (object
))
24751 /* If we are on a display string with no mouse-face,
24752 check if the text under it has one. */
24753 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
24754 int start
= MATRIX_ROW_START_CHARPOS (r
);
24755 pos
= string_buffer_position (w
, object
, start
);
24758 mouse_face
= get_char_property_and_overlay
24759 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
24760 buffer
= w
->buffer
;
24761 display_string
= object
;
24767 display_string
= Qnil
;
24770 if (!NILP (mouse_face
))
24772 Lisp_Object before
, after
;
24773 Lisp_Object before_string
, after_string
;
24775 if (NILP (overlay
))
24777 /* Handle the text property case. */
24778 before
= Fprevious_single_property_change
24779 (make_number (pos
+ 1), Qmouse_face
, buffer
,
24780 Fmarker_position (w
->start
));
24781 after
= Fnext_single_property_change
24782 (make_number (pos
), Qmouse_face
, buffer
,
24783 make_number (BUF_Z (XBUFFER (buffer
))
24784 - XFASTINT (w
->window_end_pos
)));
24785 before_string
= after_string
= Qnil
;
24789 /* Handle the overlay case. */
24790 before
= Foverlay_start (overlay
);
24791 after
= Foverlay_end (overlay
);
24792 before_string
= Foverlay_get (overlay
, Qbefore_string
);
24793 after_string
= Foverlay_get (overlay
, Qafter_string
);
24795 if (!STRINGP (before_string
)) before_string
= Qnil
;
24796 if (!STRINGP (after_string
)) after_string
= Qnil
;
24799 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
24802 before_string
, after_string
,
24804 cursor
= No_Cursor
;
24811 /* Look for a `help-echo' property. */
24812 if (NILP (help_echo_string
)) {
24813 Lisp_Object help
, overlay
;
24815 /* Check overlays first. */
24816 help
= overlay
= Qnil
;
24817 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
24819 overlay
= overlay_vec
[i
];
24820 help
= Foverlay_get (overlay
, Qhelp_echo
);
24825 help_echo_string
= help
;
24826 help_echo_window
= window
;
24827 help_echo_object
= overlay
;
24828 help_echo_pos
= pos
;
24832 Lisp_Object object
= glyph
->object
;
24833 int charpos
= glyph
->charpos
;
24835 /* Try text properties. */
24836 if (STRINGP (object
)
24838 && charpos
< SCHARS (object
))
24840 help
= Fget_text_property (make_number (charpos
),
24841 Qhelp_echo
, object
);
24844 /* If the string itself doesn't specify a help-echo,
24845 see if the buffer text ``under'' it does. */
24846 struct glyph_row
*r
24847 = MATRIX_ROW (w
->current_matrix
, vpos
);
24848 int start
= MATRIX_ROW_START_CHARPOS (r
);
24849 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
24852 help
= Fget_char_property (make_number (pos
),
24853 Qhelp_echo
, w
->buffer
);
24857 object
= w
->buffer
;
24862 else if (BUFFERP (object
)
24865 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
24870 help_echo_string
= help
;
24871 help_echo_window
= window
;
24872 help_echo_object
= object
;
24873 help_echo_pos
= charpos
;
24878 /* Look for a `pointer' property. */
24879 if (NILP (pointer
))
24881 /* Check overlays first. */
24882 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
24883 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
24885 if (NILP (pointer
))
24887 Lisp_Object object
= glyph
->object
;
24888 int charpos
= glyph
->charpos
;
24890 /* Try text properties. */
24891 if (STRINGP (object
)
24893 && charpos
< SCHARS (object
))
24895 pointer
= Fget_text_property (make_number (charpos
),
24897 if (NILP (pointer
))
24899 /* If the string itself doesn't specify a pointer,
24900 see if the buffer text ``under'' it does. */
24901 struct glyph_row
*r
24902 = MATRIX_ROW (w
->current_matrix
, vpos
);
24903 int start
= MATRIX_ROW_START_CHARPOS (r
);
24904 EMACS_INT pos
= string_buffer_position (w
, object
,
24907 pointer
= Fget_char_property (make_number (pos
),
24908 Qpointer
, w
->buffer
);
24911 else if (BUFFERP (object
)
24914 pointer
= Fget_text_property (make_number (charpos
),
24921 current_buffer
= obuf
;
24926 define_frame_cursor1 (f
, cursor
, pointer
);
24931 Clear any mouse-face on window W. This function is part of the
24932 redisplay interface, and is called from try_window_id and similar
24933 functions to ensure the mouse-highlight is off. */
24936 x_clear_window_mouse_face (w
)
24939 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24940 Lisp_Object window
;
24943 XSETWINDOW (window
, w
);
24944 if (EQ (window
, dpyinfo
->mouse_face_window
))
24945 clear_mouse_face (dpyinfo
);
24951 Just discard the mouse face information for frame F, if any.
24952 This is used when the size of F is changed. */
24955 cancel_mouse_face (f
)
24958 Lisp_Object window
;
24959 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24961 window
= dpyinfo
->mouse_face_window
;
24962 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24964 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24965 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24966 dpyinfo
->mouse_face_window
= Qnil
;
24971 #endif /* HAVE_WINDOW_SYSTEM */
24974 /***********************************************************************
24976 ***********************************************************************/
24978 #ifdef HAVE_WINDOW_SYSTEM
24980 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24981 which intersects rectangle R. R is in window-relative coordinates. */
24984 expose_area (w
, row
, r
, area
)
24986 struct glyph_row
*row
;
24988 enum glyph_row_area area
;
24990 struct glyph
*first
= row
->glyphs
[area
];
24991 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24992 struct glyph
*last
;
24993 int first_x
, start_x
, x
;
24995 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24996 /* If row extends face to end of line write the whole line. */
24997 draw_glyphs (w
, 0, row
, area
,
24998 0, row
->used
[area
],
24999 DRAW_NORMAL_TEXT
, 0);
25002 /* Set START_X to the window-relative start position for drawing glyphs of
25003 AREA. The first glyph of the text area can be partially visible.
25004 The first glyphs of other areas cannot. */
25005 start_x
= window_box_left_offset (w
, area
);
25007 if (area
== TEXT_AREA
)
25010 /* Find the first glyph that must be redrawn. */
25012 && x
+ first
->pixel_width
< r
->x
)
25014 x
+= first
->pixel_width
;
25018 /* Find the last one. */
25022 && x
< r
->x
+ r
->width
)
25024 x
+= last
->pixel_width
;
25030 draw_glyphs (w
, first_x
- start_x
, row
, area
,
25031 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
25032 DRAW_NORMAL_TEXT
, 0);
25037 /* Redraw the parts of the glyph row ROW on window W intersecting
25038 rectangle R. R is in window-relative coordinates. Value is
25039 non-zero if mouse-face was overwritten. */
25042 expose_line (w
, row
, r
)
25044 struct glyph_row
*row
;
25047 xassert (row
->enabled_p
);
25049 if (row
->mode_line_p
|| w
->pseudo_window_p
)
25050 draw_glyphs (w
, 0, row
, TEXT_AREA
,
25051 0, row
->used
[TEXT_AREA
],
25052 DRAW_NORMAL_TEXT
, 0);
25055 if (row
->used
[LEFT_MARGIN_AREA
])
25056 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
25057 if (row
->used
[TEXT_AREA
])
25058 expose_area (w
, row
, r
, TEXT_AREA
);
25059 if (row
->used
[RIGHT_MARGIN_AREA
])
25060 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
25061 draw_row_fringe_bitmaps (w
, row
);
25064 return row
->mouse_face_p
;
25068 /* Redraw those parts of glyphs rows during expose event handling that
25069 overlap other rows. Redrawing of an exposed line writes over parts
25070 of lines overlapping that exposed line; this function fixes that.
25072 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
25073 row in W's current matrix that is exposed and overlaps other rows.
25074 LAST_OVERLAPPING_ROW is the last such row. */
25077 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
25079 struct glyph_row
*first_overlapping_row
;
25080 struct glyph_row
*last_overlapping_row
;
25083 struct glyph_row
*row
;
25085 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
25086 if (row
->overlapping_p
)
25088 xassert (row
->enabled_p
&& !row
->mode_line_p
);
25091 if (row
->used
[LEFT_MARGIN_AREA
])
25092 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
25094 if (row
->used
[TEXT_AREA
])
25095 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
25097 if (row
->used
[RIGHT_MARGIN_AREA
])
25098 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
25104 /* Return non-zero if W's cursor intersects rectangle R. */
25107 phys_cursor_in_rect_p (w
, r
)
25111 XRectangle cr
, result
;
25112 struct glyph
*cursor_glyph
;
25113 struct glyph_row
*row
;
25115 if (w
->phys_cursor
.vpos
>= 0
25116 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
25117 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
25119 && row
->cursor_in_fringe_p
)
25121 /* Cursor is in the fringe. */
25122 cr
.x
= window_box_right_offset (w
,
25123 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
25124 ? RIGHT_MARGIN_AREA
25127 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
25128 cr
.height
= row
->height
;
25129 return x_intersect_rectangles (&cr
, r
, &result
);
25132 cursor_glyph
= get_phys_cursor_glyph (w
);
25135 /* r is relative to W's box, but w->phys_cursor.x is relative
25136 to left edge of W's TEXT area. Adjust it. */
25137 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
25138 cr
.y
= w
->phys_cursor
.y
;
25139 cr
.width
= cursor_glyph
->pixel_width
;
25140 cr
.height
= w
->phys_cursor_height
;
25141 /* ++KFS: W32 version used W32-specific IntersectRect here, but
25142 I assume the effect is the same -- and this is portable. */
25143 return x_intersect_rectangles (&cr
, r
, &result
);
25145 /* If we don't understand the format, pretend we're not in the hot-spot. */
25151 Draw a vertical window border to the right of window W if W doesn't
25152 have vertical scroll bars. */
25155 x_draw_vertical_border (w
)
25158 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25160 /* We could do better, if we knew what type of scroll-bar the adjacent
25161 windows (on either side) have... But we don't :-(
25162 However, I think this works ok. ++KFS 2003-04-25 */
25164 /* Redraw borders between horizontally adjacent windows. Don't
25165 do it for frames with vertical scroll bars because either the
25166 right scroll bar of a window, or the left scroll bar of its
25167 neighbor will suffice as a border. */
25168 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
25171 if (!WINDOW_RIGHTMOST_P (w
)
25172 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
25174 int x0
, x1
, y0
, y1
;
25176 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
25179 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
25182 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
25184 else if (!WINDOW_LEFTMOST_P (w
)
25185 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
25187 int x0
, x1
, y0
, y1
;
25189 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
25192 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
25195 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
25200 /* Redraw the part of window W intersection rectangle FR. Pixel
25201 coordinates in FR are frame-relative. Call this function with
25202 input blocked. Value is non-zero if the exposure overwrites
25206 expose_window (w
, fr
)
25210 struct frame
*f
= XFRAME (w
->frame
);
25212 int mouse_face_overwritten_p
= 0;
25214 /* If window is not yet fully initialized, do nothing. This can
25215 happen when toolkit scroll bars are used and a window is split.
25216 Reconfiguring the scroll bar will generate an expose for a newly
25218 if (w
->current_matrix
== NULL
)
25221 /* When we're currently updating the window, display and current
25222 matrix usually don't agree. Arrange for a thorough display
25224 if (w
== updated_window
)
25226 SET_FRAME_GARBAGED (f
);
25230 /* Frame-relative pixel rectangle of W. */
25231 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
25232 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
25233 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
25234 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
25236 if (x_intersect_rectangles (fr
, &wr
, &r
))
25238 int yb
= window_text_bottom_y (w
);
25239 struct glyph_row
*row
;
25240 int cursor_cleared_p
;
25241 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
25243 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
25244 r
.x
, r
.y
, r
.width
, r
.height
));
25246 /* Convert to window coordinates. */
25247 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
25248 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
25250 /* Turn off the cursor. */
25251 if (!w
->pseudo_window_p
25252 && phys_cursor_in_rect_p (w
, &r
))
25254 x_clear_cursor (w
);
25255 cursor_cleared_p
= 1;
25258 cursor_cleared_p
= 0;
25260 /* Update lines intersecting rectangle R. */
25261 first_overlapping_row
= last_overlapping_row
= NULL
;
25262 for (row
= w
->current_matrix
->rows
;
25267 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
25269 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
25270 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
25271 || (r
.y
>= y0
&& r
.y
< y1
)
25272 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
25274 /* A header line may be overlapping, but there is no need
25275 to fix overlapping areas for them. KFS 2005-02-12 */
25276 if (row
->overlapping_p
&& !row
->mode_line_p
)
25278 if (first_overlapping_row
== NULL
)
25279 first_overlapping_row
= row
;
25280 last_overlapping_row
= row
;
25284 if (expose_line (w
, row
, &r
))
25285 mouse_face_overwritten_p
= 1;
25288 else if (row
->overlapping_p
)
25290 /* We must redraw a row overlapping the exposed area. */
25292 ? y0
+ row
->phys_height
> r
.y
25293 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
25295 if (first_overlapping_row
== NULL
)
25296 first_overlapping_row
= row
;
25297 last_overlapping_row
= row
;
25305 /* Display the mode line if there is one. */
25306 if (WINDOW_WANTS_MODELINE_P (w
)
25307 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
25309 && row
->y
< r
.y
+ r
.height
)
25311 if (expose_line (w
, row
, &r
))
25312 mouse_face_overwritten_p
= 1;
25315 if (!w
->pseudo_window_p
)
25317 /* Fix the display of overlapping rows. */
25318 if (first_overlapping_row
)
25319 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
25322 /* Draw border between windows. */
25323 x_draw_vertical_border (w
);
25325 /* Turn the cursor on again. */
25326 if (cursor_cleared_p
)
25327 update_window_cursor (w
, 1);
25331 return mouse_face_overwritten_p
;
25336 /* Redraw (parts) of all windows in the window tree rooted at W that
25337 intersect R. R contains frame pixel coordinates. Value is
25338 non-zero if the exposure overwrites mouse-face. */
25341 expose_window_tree (w
, r
)
25345 struct frame
*f
= XFRAME (w
->frame
);
25346 int mouse_face_overwritten_p
= 0;
25348 while (w
&& !FRAME_GARBAGED_P (f
))
25350 if (!NILP (w
->hchild
))
25351 mouse_face_overwritten_p
25352 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
25353 else if (!NILP (w
->vchild
))
25354 mouse_face_overwritten_p
25355 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
25357 mouse_face_overwritten_p
|= expose_window (w
, r
);
25359 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
25362 return mouse_face_overwritten_p
;
25367 Redisplay an exposed area of frame F. X and Y are the upper-left
25368 corner of the exposed rectangle. W and H are width and height of
25369 the exposed area. All are pixel values. W or H zero means redraw
25370 the entire frame. */
25373 expose_frame (f
, x
, y
, w
, h
)
25378 int mouse_face_overwritten_p
= 0;
25380 TRACE ((stderr
, "expose_frame "));
25382 /* No need to redraw if frame will be redrawn soon. */
25383 if (FRAME_GARBAGED_P (f
))
25385 TRACE ((stderr
, " garbaged\n"));
25389 /* If basic faces haven't been realized yet, there is no point in
25390 trying to redraw anything. This can happen when we get an expose
25391 event while Emacs is starting, e.g. by moving another window. */
25392 if (FRAME_FACE_CACHE (f
) == NULL
25393 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
25395 TRACE ((stderr
, " no faces\n"));
25399 if (w
== 0 || h
== 0)
25402 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
25403 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
25413 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
25414 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
25416 if (WINDOWP (f
->tool_bar_window
))
25417 mouse_face_overwritten_p
25418 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
25420 #ifdef HAVE_X_WINDOWS
25422 #ifndef USE_X_TOOLKIT
25423 if (WINDOWP (f
->menu_bar_window
))
25424 mouse_face_overwritten_p
25425 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
25426 #endif /* not USE_X_TOOLKIT */
25430 /* Some window managers support a focus-follows-mouse style with
25431 delayed raising of frames. Imagine a partially obscured frame,
25432 and moving the mouse into partially obscured mouse-face on that
25433 frame. The visible part of the mouse-face will be highlighted,
25434 then the WM raises the obscured frame. With at least one WM, KDE
25435 2.1, Emacs is not getting any event for the raising of the frame
25436 (even tried with SubstructureRedirectMask), only Expose events.
25437 These expose events will draw text normally, i.e. not
25438 highlighted. Which means we must redo the highlight here.
25439 Subsume it under ``we love X''. --gerd 2001-08-15 */
25440 /* Included in Windows version because Windows most likely does not
25441 do the right thing if any third party tool offers
25442 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
25443 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
25445 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25446 if (f
== dpyinfo
->mouse_face_mouse_frame
)
25448 int x
= dpyinfo
->mouse_face_mouse_x
;
25449 int y
= dpyinfo
->mouse_face_mouse_y
;
25450 clear_mouse_face (dpyinfo
);
25451 note_mouse_highlight (f
, x
, y
);
25458 Determine the intersection of two rectangles R1 and R2. Return
25459 the intersection in *RESULT. Value is non-zero if RESULT is not
25463 x_intersect_rectangles (r1
, r2
, result
)
25464 XRectangle
*r1
, *r2
, *result
;
25466 XRectangle
*left
, *right
;
25467 XRectangle
*upper
, *lower
;
25468 int intersection_p
= 0;
25470 /* Rearrange so that R1 is the left-most rectangle. */
25472 left
= r1
, right
= r2
;
25474 left
= r2
, right
= r1
;
25476 /* X0 of the intersection is right.x0, if this is inside R1,
25477 otherwise there is no intersection. */
25478 if (right
->x
<= left
->x
+ left
->width
)
25480 result
->x
= right
->x
;
25482 /* The right end of the intersection is the minimum of the
25483 the right ends of left and right. */
25484 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
25487 /* Same game for Y. */
25489 upper
= r1
, lower
= r2
;
25491 upper
= r2
, lower
= r1
;
25493 /* The upper end of the intersection is lower.y0, if this is inside
25494 of upper. Otherwise, there is no intersection. */
25495 if (lower
->y
<= upper
->y
+ upper
->height
)
25497 result
->y
= lower
->y
;
25499 /* The lower end of the intersection is the minimum of the lower
25500 ends of upper and lower. */
25501 result
->height
= (min (lower
->y
+ lower
->height
,
25502 upper
->y
+ upper
->height
)
25504 intersection_p
= 1;
25508 return intersection_p
;
25511 #endif /* HAVE_WINDOW_SYSTEM */
25514 /***********************************************************************
25516 ***********************************************************************/
25521 Vwith_echo_area_save_vector
= Qnil
;
25522 staticpro (&Vwith_echo_area_save_vector
);
25524 Vmessage_stack
= Qnil
;
25525 staticpro (&Vmessage_stack
);
25527 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
25528 staticpro (&Qinhibit_redisplay
);
25530 message_dolog_marker1
= Fmake_marker ();
25531 staticpro (&message_dolog_marker1
);
25532 message_dolog_marker2
= Fmake_marker ();
25533 staticpro (&message_dolog_marker2
);
25534 message_dolog_marker3
= Fmake_marker ();
25535 staticpro (&message_dolog_marker3
);
25538 defsubr (&Sdump_frame_glyph_matrix
);
25539 defsubr (&Sdump_glyph_matrix
);
25540 defsubr (&Sdump_glyph_row
);
25541 defsubr (&Sdump_tool_bar_row
);
25542 defsubr (&Strace_redisplay
);
25543 defsubr (&Strace_to_stderr
);
25545 #ifdef HAVE_WINDOW_SYSTEM
25546 defsubr (&Stool_bar_lines_needed
);
25547 defsubr (&Slookup_image_map
);
25549 defsubr (&Sformat_mode_line
);
25550 defsubr (&Sinvisible_p
);
25552 staticpro (&Qmenu_bar_update_hook
);
25553 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
25555 staticpro (&Qoverriding_terminal_local_map
);
25556 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
25558 staticpro (&Qoverriding_local_map
);
25559 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
25561 staticpro (&Qwindow_scroll_functions
);
25562 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
25564 staticpro (&Qwindow_text_change_functions
);
25565 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
25567 staticpro (&Qredisplay_end_trigger_functions
);
25568 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
25570 staticpro (&Qinhibit_point_motion_hooks
);
25571 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
25573 Qeval
= intern_c_string ("eval");
25574 staticpro (&Qeval
);
25576 QCdata
= intern_c_string (":data");
25577 staticpro (&QCdata
);
25578 Qdisplay
= intern_c_string ("display");
25579 staticpro (&Qdisplay
);
25580 Qspace_width
= intern_c_string ("space-width");
25581 staticpro (&Qspace_width
);
25582 Qraise
= intern_c_string ("raise");
25583 staticpro (&Qraise
);
25584 Qslice
= intern_c_string ("slice");
25585 staticpro (&Qslice
);
25586 Qspace
= intern_c_string ("space");
25587 staticpro (&Qspace
);
25588 Qmargin
= intern_c_string ("margin");
25589 staticpro (&Qmargin
);
25590 Qpointer
= intern_c_string ("pointer");
25591 staticpro (&Qpointer
);
25592 Qleft_margin
= intern_c_string ("left-margin");
25593 staticpro (&Qleft_margin
);
25594 Qright_margin
= intern_c_string ("right-margin");
25595 staticpro (&Qright_margin
);
25596 Qcenter
= intern_c_string ("center");
25597 staticpro (&Qcenter
);
25598 Qline_height
= intern_c_string ("line-height");
25599 staticpro (&Qline_height
);
25600 QCalign_to
= intern_c_string (":align-to");
25601 staticpro (&QCalign_to
);
25602 QCrelative_width
= intern_c_string (":relative-width");
25603 staticpro (&QCrelative_width
);
25604 QCrelative_height
= intern_c_string (":relative-height");
25605 staticpro (&QCrelative_height
);
25606 QCeval
= intern_c_string (":eval");
25607 staticpro (&QCeval
);
25608 QCpropertize
= intern_c_string (":propertize");
25609 staticpro (&QCpropertize
);
25610 QCfile
= intern_c_string (":file");
25611 staticpro (&QCfile
);
25612 Qfontified
= intern_c_string ("fontified");
25613 staticpro (&Qfontified
);
25614 Qfontification_functions
= intern_c_string ("fontification-functions");
25615 staticpro (&Qfontification_functions
);
25616 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
25617 staticpro (&Qtrailing_whitespace
);
25618 Qescape_glyph
= intern_c_string ("escape-glyph");
25619 staticpro (&Qescape_glyph
);
25620 Qnobreak_space
= intern_c_string ("nobreak-space");
25621 staticpro (&Qnobreak_space
);
25622 Qimage
= intern_c_string ("image");
25623 staticpro (&Qimage
);
25624 QCmap
= intern_c_string (":map");
25625 staticpro (&QCmap
);
25626 QCpointer
= intern_c_string (":pointer");
25627 staticpro (&QCpointer
);
25628 Qrect
= intern_c_string ("rect");
25629 staticpro (&Qrect
);
25630 Qcircle
= intern_c_string ("circle");
25631 staticpro (&Qcircle
);
25632 Qpoly
= intern_c_string ("poly");
25633 staticpro (&Qpoly
);
25634 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
25635 staticpro (&Qmessage_truncate_lines
);
25636 Qgrow_only
= intern_c_string ("grow-only");
25637 staticpro (&Qgrow_only
);
25638 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
25639 staticpro (&Qinhibit_menubar_update
);
25640 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
25641 staticpro (&Qinhibit_eval_during_redisplay
);
25642 Qposition
= intern_c_string ("position");
25643 staticpro (&Qposition
);
25644 Qbuffer_position
= intern_c_string ("buffer-position");
25645 staticpro (&Qbuffer_position
);
25646 Qobject
= intern_c_string ("object");
25647 staticpro (&Qobject
);
25648 Qbar
= intern_c_string ("bar");
25650 Qhbar
= intern_c_string ("hbar");
25651 staticpro (&Qhbar
);
25652 Qbox
= intern_c_string ("box");
25654 Qhollow
= intern_c_string ("hollow");
25655 staticpro (&Qhollow
);
25656 Qhand
= intern_c_string ("hand");
25657 staticpro (&Qhand
);
25658 Qarrow
= intern_c_string ("arrow");
25659 staticpro (&Qarrow
);
25660 Qtext
= intern_c_string ("text");
25661 staticpro (&Qtext
);
25662 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
25663 staticpro (&Qrisky_local_variable
);
25664 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
25665 staticpro (&Qinhibit_free_realized_faces
);
25667 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
25668 Fcons (intern_c_string ("void-variable"), Qnil
)),
25670 staticpro (&list_of_error
);
25672 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
25673 staticpro (&Qlast_arrow_position
);
25674 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
25675 staticpro (&Qlast_arrow_string
);
25677 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
25678 staticpro (&Qoverlay_arrow_string
);
25679 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
25680 staticpro (&Qoverlay_arrow_bitmap
);
25682 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
25683 staticpro (&echo_buffer
[0]);
25684 staticpro (&echo_buffer
[1]);
25686 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
25687 staticpro (&echo_area_buffer
[0]);
25688 staticpro (&echo_area_buffer
[1]);
25690 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
25691 staticpro (&Vmessages_buffer_name
);
25693 mode_line_proptrans_alist
= Qnil
;
25694 staticpro (&mode_line_proptrans_alist
);
25695 mode_line_string_list
= Qnil
;
25696 staticpro (&mode_line_string_list
);
25697 mode_line_string_face
= Qnil
;
25698 staticpro (&mode_line_string_face
);
25699 mode_line_string_face_prop
= Qnil
;
25700 staticpro (&mode_line_string_face_prop
);
25701 Vmode_line_unwind_vector
= Qnil
;
25702 staticpro (&Vmode_line_unwind_vector
);
25704 help_echo_string
= Qnil
;
25705 staticpro (&help_echo_string
);
25706 help_echo_object
= Qnil
;
25707 staticpro (&help_echo_object
);
25708 help_echo_window
= Qnil
;
25709 staticpro (&help_echo_window
);
25710 previous_help_echo_string
= Qnil
;
25711 staticpro (&previous_help_echo_string
);
25712 help_echo_pos
= -1;
25714 Qright_to_left
= intern_c_string ("right-to-left");
25715 staticpro (&Qright_to_left
);
25716 Qleft_to_right
= intern_c_string ("left-to-right");
25717 staticpro (&Qleft_to_right
);
25719 #ifdef HAVE_WINDOW_SYSTEM
25720 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
25721 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
25722 For example, if a block cursor is over a tab, it will be drawn as
25723 wide as that tab on the display. */);
25724 x_stretch_cursor_p
= 0;
25727 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
25728 doc
: /* *Non-nil means highlight trailing whitespace.
25729 The face used for trailing whitespace is `trailing-whitespace'. */);
25730 Vshow_trailing_whitespace
= Qnil
;
25732 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
25733 doc
: /* *Control highlighting of nobreak space and soft hyphen.
25734 A value of t means highlight the character itself (for nobreak space,
25735 use face `nobreak-space').
25736 A value of nil means no highlighting.
25737 Other values mean display the escape glyph followed by an ordinary
25738 space or ordinary hyphen. */);
25739 Vnobreak_char_display
= Qt
;
25741 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
25742 doc
: /* *The pointer shape to show in void text areas.
25743 A value of nil means to show the text pointer. Other options are `arrow',
25744 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
25745 Vvoid_text_area_pointer
= Qarrow
;
25747 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
25748 doc
: /* Non-nil means don't actually do any redisplay.
25749 This is used for internal purposes. */);
25750 Vinhibit_redisplay
= Qnil
;
25752 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
25753 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
25754 Vglobal_mode_string
= Qnil
;
25756 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
25757 doc
: /* Marker for where to display an arrow on top of the buffer text.
25758 This must be the beginning of a line in order to work.
25759 See also `overlay-arrow-string'. */);
25760 Voverlay_arrow_position
= Qnil
;
25762 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
25763 doc
: /* String to display as an arrow in non-window frames.
25764 See also `overlay-arrow-position'. */);
25765 Voverlay_arrow_string
= make_pure_c_string ("=>");
25767 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
25768 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
25769 The symbols on this list are examined during redisplay to determine
25770 where to display overlay arrows. */);
25771 Voverlay_arrow_variable_list
25772 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
25774 DEFVAR_INT ("scroll-step", &scroll_step
,
25775 doc
: /* *The number of lines to try scrolling a window by when point moves out.
25776 If that fails to bring point back on frame, point is centered instead.
25777 If this is zero, point is always centered after it moves off frame.
25778 If you want scrolling to always be a line at a time, you should set
25779 `scroll-conservatively' to a large value rather than set this to 1. */);
25781 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
25782 doc
: /* *Scroll up to this many lines, to bring point back on screen.
25783 If point moves off-screen, redisplay will scroll by up to
25784 `scroll-conservatively' lines in order to bring point just barely
25785 onto the screen again. If that cannot be done, then redisplay
25786 recenters point as usual.
25788 A value of zero means always recenter point if it moves off screen. */);
25789 scroll_conservatively
= 0;
25791 DEFVAR_INT ("scroll-margin", &scroll_margin
,
25792 doc
: /* *Number of lines of margin at the top and bottom of a window.
25793 Recenter the window whenever point gets within this many lines
25794 of the top or bottom of the window. */);
25797 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
25798 doc
: /* Pixels per inch value for non-window system displays.
25799 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
25800 Vdisplay_pixels_per_inch
= make_float (72.0);
25803 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
25806 DEFVAR_LISP ("truncate-partial-width-windows",
25807 &Vtruncate_partial_width_windows
,
25808 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
25809 For an integer value, truncate lines in each window narrower than the
25810 full frame width, provided the window width is less than that integer;
25811 otherwise, respect the value of `truncate-lines'.
25813 For any other non-nil value, truncate lines in all windows that do
25814 not span the full frame width.
25816 A value of nil means to respect the value of `truncate-lines'.
25818 If `word-wrap' is enabled, you might want to reduce this. */);
25819 Vtruncate_partial_width_windows
= make_number (50);
25821 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
25822 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
25823 Any other value means to use the appropriate face, `mode-line',
25824 `header-line', or `menu' respectively. */);
25825 mode_line_inverse_video
= 1;
25827 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
25828 doc
: /* *Maximum buffer size for which line number should be displayed.
25829 If the buffer is bigger than this, the line number does not appear
25830 in the mode line. A value of nil means no limit. */);
25831 Vline_number_display_limit
= Qnil
;
25833 DEFVAR_INT ("line-number-display-limit-width",
25834 &line_number_display_limit_width
,
25835 doc
: /* *Maximum line width (in characters) for line number display.
25836 If the average length of the lines near point is bigger than this, then the
25837 line number may be omitted from the mode line. */);
25838 line_number_display_limit_width
= 200;
25840 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
25841 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
25842 highlight_nonselected_windows
= 0;
25844 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
25845 doc
: /* Non-nil if more than one frame is visible on this display.
25846 Minibuffer-only frames don't count, but iconified frames do.
25847 This variable is not guaranteed to be accurate except while processing
25848 `frame-title-format' and `icon-title-format'. */);
25850 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
25851 doc
: /* Template for displaying the title bar of visible frames.
25852 \(Assuming the window manager supports this feature.)
25854 This variable has the same structure as `mode-line-format', except that
25855 the %c and %l constructs are ignored. It is used only on frames for
25856 which no explicit name has been set \(see `modify-frame-parameters'). */);
25858 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
25859 doc
: /* Template for displaying the title bar of an iconified frame.
25860 \(Assuming the window manager supports this feature.)
25861 This variable has the same structure as `mode-line-format' (which see),
25862 and is used only on frames for which no explicit name has been set
25863 \(see `modify-frame-parameters'). */);
25865 = Vframe_title_format
25866 = pure_cons (intern_c_string ("multiple-frames"),
25867 pure_cons (make_pure_c_string ("%b"),
25868 pure_cons (pure_cons (empty_unibyte_string
,
25869 pure_cons (intern_c_string ("invocation-name"),
25870 pure_cons (make_pure_c_string ("@"),
25871 pure_cons (intern_c_string ("system-name"),
25875 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
25876 doc
: /* Maximum number of lines to keep in the message log buffer.
25877 If nil, disable message logging. If t, log messages but don't truncate
25878 the buffer when it becomes large. */);
25879 Vmessage_log_max
= make_number (100);
25881 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
25882 doc
: /* Functions called before redisplay, if window sizes have changed.
25883 The value should be a list of functions that take one argument.
25884 Just before redisplay, for each frame, if any of its windows have changed
25885 size since the last redisplay, or have been split or deleted,
25886 all the functions in the list are called, with the frame as argument. */);
25887 Vwindow_size_change_functions
= Qnil
;
25889 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
25890 doc
: /* List of functions to call before redisplaying a window with scrolling.
25891 Each function is called with two arguments, the window and its new
25892 display-start position. Note that these functions are also called by
25893 `set-window-buffer'. Also note that the value of `window-end' is not
25894 valid when these functions are called. */);
25895 Vwindow_scroll_functions
= Qnil
;
25897 DEFVAR_LISP ("window-text-change-functions",
25898 &Vwindow_text_change_functions
,
25899 doc
: /* Functions to call in redisplay when text in the window might change. */);
25900 Vwindow_text_change_functions
= Qnil
;
25902 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
25903 doc
: /* Functions called when redisplay of a window reaches the end trigger.
25904 Each function is called with two arguments, the window and the end trigger value.
25905 See `set-window-redisplay-end-trigger'. */);
25906 Vredisplay_end_trigger_functions
= Qnil
;
25908 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25909 doc
: /* *Non-nil means autoselect window with mouse pointer.
25910 If nil, do not autoselect windows.
25911 A positive number means delay autoselection by that many seconds: a
25912 window is autoselected only after the mouse has remained in that
25913 window for the duration of the delay.
25914 A negative number has a similar effect, but causes windows to be
25915 autoselected only after the mouse has stopped moving. \(Because of
25916 the way Emacs compares mouse events, you will occasionally wait twice
25917 that time before the window gets selected.\)
25918 Any other value means to autoselect window instantaneously when the
25919 mouse pointer enters it.
25921 Autoselection selects the minibuffer only if it is active, and never
25922 unselects the minibuffer if it is active.
25924 When customizing this variable make sure that the actual value of
25925 `focus-follows-mouse' matches the behavior of your window manager. */);
25926 Vmouse_autoselect_window
= Qnil
;
25928 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25929 doc
: /* *Non-nil means automatically resize tool-bars.
25930 This dynamically changes the tool-bar's height to the minimum height
25931 that is needed to make all tool-bar items visible.
25932 If value is `grow-only', the tool-bar's height is only increased
25933 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25934 Vauto_resize_tool_bars
= Qt
;
25936 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25937 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25938 auto_raise_tool_bar_buttons_p
= 1;
25940 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25941 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25942 make_cursor_line_fully_visible_p
= 1;
25944 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25945 doc
: /* *Border below tool-bar in pixels.
25946 If an integer, use it as the height of the border.
25947 If it is one of `internal-border-width' or `border-width', use the
25948 value of the corresponding frame parameter.
25949 Otherwise, no border is added below the tool-bar. */);
25950 Vtool_bar_border
= Qinternal_border_width
;
25952 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25953 doc
: /* *Margin around tool-bar buttons in pixels.
25954 If an integer, use that for both horizontal and vertical margins.
25955 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25956 HORZ specifying the horizontal margin, and VERT specifying the
25957 vertical margin. */);
25958 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25960 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25961 doc
: /* *Relief thickness of tool-bar buttons. */);
25962 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25964 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25965 doc
: /* List of functions to call to fontify regions of text.
25966 Each function is called with one argument POS. Functions must
25967 fontify a region starting at POS in the current buffer, and give
25968 fontified regions the property `fontified'. */);
25969 Vfontification_functions
= Qnil
;
25970 Fmake_variable_buffer_local (Qfontification_functions
);
25972 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25973 &unibyte_display_via_language_environment
,
25974 doc
: /* *Non-nil means display unibyte text according to language environment.
25975 Specifically, this means that raw bytes in the range 160-255 decimal
25976 are displayed by converting them to the equivalent multibyte characters
25977 according to the current language environment. As a result, they are
25978 displayed according to the current fontset.
25980 Note that this variable affects only how these bytes are displayed,
25981 but does not change the fact they are interpreted as raw bytes. */);
25982 unibyte_display_via_language_environment
= 0;
25984 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25985 doc
: /* *Maximum height for resizing mini-windows.
25986 If a float, it specifies a fraction of the mini-window frame's height.
25987 If an integer, it specifies a number of lines. */);
25988 Vmax_mini_window_height
= make_float (0.25);
25990 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25991 doc
: /* *How to resize mini-windows.
25992 A value of nil means don't automatically resize mini-windows.
25993 A value of t means resize them to fit the text displayed in them.
25994 A value of `grow-only', the default, means let mini-windows grow
25995 only, until their display becomes empty, at which point the windows
25996 go back to their normal size. */);
25997 Vresize_mini_windows
= Qgrow_only
;
25999 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
26000 doc
: /* Alist specifying how to blink the cursor off.
26001 Each element has the form (ON-STATE . OFF-STATE). Whenever the
26002 `cursor-type' frame-parameter or variable equals ON-STATE,
26003 comparing using `equal', Emacs uses OFF-STATE to specify
26004 how to blink it off. ON-STATE and OFF-STATE are values for
26005 the `cursor-type' frame parameter.
26007 If a frame's ON-STATE has no entry in this list,
26008 the frame's other specifications determine how to blink the cursor off. */);
26009 Vblink_cursor_alist
= Qnil
;
26011 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
26012 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
26013 automatic_hscrolling_p
= 1;
26014 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
26015 staticpro (&Qauto_hscroll_mode
);
26017 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
26018 doc
: /* *How many columns away from the window edge point is allowed to get
26019 before automatic hscrolling will horizontally scroll the window. */);
26020 hscroll_margin
= 5;
26022 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
26023 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
26024 When point is less than `hscroll-margin' columns from the window
26025 edge, automatic hscrolling will scroll the window by the amount of columns
26026 determined by this variable. If its value is a positive integer, scroll that
26027 many columns. If it's a positive floating-point number, it specifies the
26028 fraction of the window's width to scroll. If it's nil or zero, point will be
26029 centered horizontally after the scroll. Any other value, including negative
26030 numbers, are treated as if the value were zero.
26032 Automatic hscrolling always moves point outside the scroll margin, so if
26033 point was more than scroll step columns inside the margin, the window will
26034 scroll more than the value given by the scroll step.
26036 Note that the lower bound for automatic hscrolling specified by `scroll-left'
26037 and `scroll-right' overrides this variable's effect. */);
26038 Vhscroll_step
= make_number (0);
26040 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
26041 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
26042 Bind this around calls to `message' to let it take effect. */);
26043 message_truncate_lines
= 0;
26045 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
26046 doc
: /* Normal hook run to update the menu bar definitions.
26047 Redisplay runs this hook before it redisplays the menu bar.
26048 This is used to update submenus such as Buffers,
26049 whose contents depend on various data. */);
26050 Vmenu_bar_update_hook
= Qnil
;
26052 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
26053 doc
: /* Frame for which we are updating a menu.
26054 The enable predicate for a menu binding should check this variable. */);
26055 Vmenu_updating_frame
= Qnil
;
26057 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
26058 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
26059 inhibit_menubar_update
= 0;
26061 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
26062 doc
: /* Prefix prepended to all continuation lines at display time.
26063 The value may be a string, an image, or a stretch-glyph; it is
26064 interpreted in the same way as the value of a `display' text property.
26066 This variable is overridden by any `wrap-prefix' text or overlay
26069 To add a prefix to non-continuation lines, use `line-prefix'. */);
26070 Vwrap_prefix
= Qnil
;
26071 staticpro (&Qwrap_prefix
);
26072 Qwrap_prefix
= intern_c_string ("wrap-prefix");
26073 Fmake_variable_buffer_local (Qwrap_prefix
);
26075 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
26076 doc
: /* Prefix prepended to all non-continuation lines at display time.
26077 The value may be a string, an image, or a stretch-glyph; it is
26078 interpreted in the same way as the value of a `display' text property.
26080 This variable is overridden by any `line-prefix' text or overlay
26083 To add a prefix to continuation lines, use `wrap-prefix'. */);
26084 Vline_prefix
= Qnil
;
26085 staticpro (&Qline_prefix
);
26086 Qline_prefix
= intern_c_string ("line-prefix");
26087 Fmake_variable_buffer_local (Qline_prefix
);
26089 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
26090 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
26091 inhibit_eval_during_redisplay
= 0;
26093 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
26094 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
26095 inhibit_free_realized_faces
= 0;
26098 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
26099 doc
: /* Inhibit try_window_id display optimization. */);
26100 inhibit_try_window_id
= 0;
26102 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
26103 doc
: /* Inhibit try_window_reusing display optimization. */);
26104 inhibit_try_window_reusing
= 0;
26106 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
26107 doc
: /* Inhibit try_cursor_movement display optimization. */);
26108 inhibit_try_cursor_movement
= 0;
26109 #endif /* GLYPH_DEBUG */
26111 DEFVAR_INT ("overline-margin", &overline_margin
,
26112 doc
: /* *Space between overline and text, in pixels.
26113 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
26114 margin to the caracter height. */);
26115 overline_margin
= 2;
26117 DEFVAR_INT ("underline-minimum-offset",
26118 &underline_minimum_offset
,
26119 doc
: /* Minimum distance between baseline and underline.
26120 This can improve legibility of underlined text at small font sizes,
26121 particularly when using variable `x-use-underline-position-properties'
26122 with fonts that specify an UNDERLINE_POSITION relatively close to the
26123 baseline. The default value is 1. */);
26124 underline_minimum_offset
= 1;
26126 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
26127 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
26128 display_hourglass_p
= 1;
26130 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
26131 doc
: /* *Seconds to wait before displaying an hourglass pointer.
26132 Value must be an integer or float. */);
26133 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
26135 hourglass_atimer
= NULL
;
26136 hourglass_shown_p
= 0;
26140 /* Initialize this module when Emacs starts. */
26145 Lisp_Object root_window
;
26146 struct window
*mini_w
;
26148 current_header_line_height
= current_mode_line_height
= -1;
26150 CHARPOS (this_line_start_pos
) = 0;
26152 mini_w
= XWINDOW (minibuf_window
);
26153 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
26155 if (!noninteractive
)
26157 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
26160 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
26161 set_window_height (root_window
,
26162 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
26164 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
26165 set_window_height (minibuf_window
, 1, 0);
26167 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
26168 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
26170 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
26171 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
26172 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
26174 /* The default ellipsis glyphs `...'. */
26175 for (i
= 0; i
< 3; ++i
)
26176 default_invis_vector
[i
] = make_number ('.');
26180 /* Allocate the buffer for frame titles.
26181 Also used for `format-mode-line'. */
26183 mode_line_noprop_buf
= (char *) xmalloc (size
);
26184 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
26185 mode_line_noprop_ptr
= mode_line_noprop_buf
;
26186 mode_line_target
= MODE_LINE_DISPLAY
;
26189 help_echo_showing_p
= 0;
26192 /* Since w32 does not support atimers, it defines its own implementation of
26193 the following three functions in w32fns.c. */
26196 /* Platform-independent portion of hourglass implementation. */
26198 /* Return non-zero if houglass timer has been started or hourglass is shown. */
26200 hourglass_started ()
26202 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
26205 /* Cancel a currently active hourglass timer, and start a new one. */
26209 #if defined (HAVE_WINDOW_SYSTEM)
26211 int secs
, usecs
= 0;
26213 cancel_hourglass ();
26215 if (INTEGERP (Vhourglass_delay
)
26216 && XINT (Vhourglass_delay
) > 0)
26217 secs
= XFASTINT (Vhourglass_delay
);
26218 else if (FLOATP (Vhourglass_delay
)
26219 && XFLOAT_DATA (Vhourglass_delay
) > 0)
26222 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
26223 secs
= XFASTINT (tem
);
26224 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
26227 secs
= DEFAULT_HOURGLASS_DELAY
;
26229 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
26230 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
26231 show_hourglass
, NULL
);
26236 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
26239 cancel_hourglass ()
26241 #if defined (HAVE_WINDOW_SYSTEM)
26242 if (hourglass_atimer
)
26244 cancel_atimer (hourglass_atimer
);
26245 hourglass_atimer
= NULL
;
26248 if (hourglass_shown_p
)
26252 #endif /* ! WINDOWSNT */
26254 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
26255 (do not change this comment) */