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 and stretch glyphs
12591 inserted by 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 || ((row
->reversed_p
12814 ? glyph_after
> glyphs_end
12815 : glyph_after
< glyphs_end
)
12816 && eabs (glyph_after
- glyph_before
) == 1))
12818 cursor
= glyph_after
;
12821 else if (string_seen
)
12823 int incr
= row
->reversed_p
? -1 : +1;
12825 /* Need to find the glyph that came out of a string which is
12826 present at point. That glyph is somewhere between
12827 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12828 positioned between POS_BEFORE and POS_AFTER in the
12830 struct glyph
*stop
= glyph_after
;
12831 EMACS_INT pos
= pos_before
;
12834 for (glyph
= glyph_before
+ incr
;
12835 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12838 /* Any glyphs that come from the buffer are here because
12839 of bidi reordering. Skip them, and only pay
12840 attention to glyphs that came from some string. */
12841 if (STRINGP (glyph
->object
))
12846 str
= glyph
->object
;
12847 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12848 if (tem
== 0 /* from overlay */
12851 /* If the string from which this glyph came is
12852 found in the buffer at point, then we've
12853 found the glyph we've been looking for. If
12854 it comes from an overlay (tem == 0), and it
12855 has the `cursor' property on one of its
12856 glyphs, record that glyph as a candidate for
12857 displaying the cursor. (As in the
12858 unidirectional version, we will display the
12859 cursor on the last candidate we find.) */
12860 if (tem
== 0 || tem
== pt_old
)
12862 /* The glyphs from this string could have
12863 been reordered. Find the one with the
12864 smallest string position. Or there could
12865 be a character in the string with the
12866 `cursor' property, which means display
12867 cursor on that character's glyph. */
12868 int strpos
= glyph
->charpos
;
12871 for (glyph
+= incr
;
12872 EQ (glyph
->object
, str
);
12876 int gpos
= glyph
->charpos
;
12878 cprop
= Fget_char_property (make_number (gpos
),
12886 if (glyph
->charpos
< strpos
)
12888 strpos
= glyph
->charpos
;
12897 pos
= tem
+ 1; /* don't find previous instances */
12899 /* This string is not what we want; skip all of the
12900 glyphs that came from it. */
12903 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12904 && EQ (glyph
->object
, str
));
12910 /* If we reached the end of the line, and END was from a string,
12911 the cursor is not on this line. */
12913 && STRINGP ((glyph
- incr
)->object
)
12914 && row
->continued_p
)
12920 if (cursor
!= NULL
)
12926 /* Need to compute x that corresponds to GLYPH. */
12927 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12929 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12931 x
+= g
->pixel_width
;
12935 /* ROW could be part of a continued line, which, under bidi
12936 reordering, might have other rows whose start and end charpos
12937 occlude point. Only set w->cursor if we found a better
12938 approximation to the cursor position than we have from previously
12939 examined candidate rows belonging to the same continued line. */
12940 if (/* we already have a candidate row */
12941 w
->cursor
.vpos
>= 0
12942 /* that candidate is not the row we are processing */
12943 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
12944 /* the row we are processing is part of a continued line */
12945 && (row
->continued_p
|| row
->continuation_lines_width
)
12946 /* Make sure cursor.vpos specifies a row whose start and end
12947 charpos occlude point. This is because some callers of this
12948 function leave cursor.vpos at the row where the cursor was
12949 displayed during the last redisplay cycle. */
12950 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
12951 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
12954 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
12956 /* Don't consider glyphs that are outside TEXT_AREA. */
12957 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
12959 /* Keep the candidate whose buffer position is the closest to
12961 if (/* previous candidate is a glyph in TEXT_AREA of that row */
12962 w
->cursor
.hpos
>= 0
12963 && w
->cursor
.hpos
< MATRIX_ROW_USED(matrix
, w
->cursor
.vpos
)
12964 && BUFFERP (g1
->object
)
12965 && (g1
->charpos
== pt_old
/* an exact match always wins */
12966 || (BUFFERP (glyph
->object
)
12967 && eabs (g1
->charpos
- pt_old
)
12968 < eabs (glyph
->charpos
- pt_old
))))
12970 /* If this candidate gives an exact match, use that. */
12971 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12972 /* Otherwise, keep the candidate that comes from a row
12973 spanning less buffer positions. This may win when one or
12974 both candidate positions are on glyphs that came from
12975 display strings, for which we cannot compare buffer
12977 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12978 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12979 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
12982 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12984 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12985 w
->cursor
.y
= row
->y
+ dy
;
12987 if (w
== XWINDOW (selected_window
))
12989 if (!row
->continued_p
12990 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12993 this_line_buffer
= XBUFFER (w
->buffer
);
12995 CHARPOS (this_line_start_pos
)
12996 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12997 BYTEPOS (this_line_start_pos
)
12998 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13000 CHARPOS (this_line_end_pos
)
13001 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13002 BYTEPOS (this_line_end_pos
)
13003 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13005 this_line_y
= w
->cursor
.y
;
13006 this_line_pixel_height
= row
->height
;
13007 this_line_vpos
= w
->cursor
.vpos
;
13008 this_line_start_x
= row
->x
;
13011 CHARPOS (this_line_start_pos
) = 0;
13018 /* Run window scroll functions, if any, for WINDOW with new window
13019 start STARTP. Sets the window start of WINDOW to that position.
13021 We assume that the window's buffer is really current. */
13023 static INLINE
struct text_pos
13024 run_window_scroll_functions (window
, startp
)
13025 Lisp_Object window
;
13026 struct text_pos startp
;
13028 struct window
*w
= XWINDOW (window
);
13029 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13031 if (current_buffer
!= XBUFFER (w
->buffer
))
13034 if (!NILP (Vwindow_scroll_functions
))
13036 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13037 make_number (CHARPOS (startp
)));
13038 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13039 /* In case the hook functions switch buffers. */
13040 if (current_buffer
!= XBUFFER (w
->buffer
))
13041 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13048 /* Make sure the line containing the cursor is fully visible.
13049 A value of 1 means there is nothing to be done.
13050 (Either the line is fully visible, or it cannot be made so,
13051 or we cannot tell.)
13053 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13054 is higher than window.
13056 A value of 0 means the caller should do scrolling
13057 as if point had gone off the screen. */
13060 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
13063 int current_matrix_p
;
13065 struct glyph_matrix
*matrix
;
13066 struct glyph_row
*row
;
13069 if (!make_cursor_line_fully_visible_p
)
13072 /* It's not always possible to find the cursor, e.g, when a window
13073 is full of overlay strings. Don't do anything in that case. */
13074 if (w
->cursor
.vpos
< 0)
13077 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13078 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13080 /* If the cursor row is not partially visible, there's nothing to do. */
13081 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13084 /* If the row the cursor is in is taller than the window's height,
13085 it's not clear what to do, so do nothing. */
13086 window_height
= window_box_height (w
);
13087 if (row
->height
>= window_height
)
13089 if (!force_p
|| MINI_WINDOW_P (w
)
13090 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13097 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13098 non-zero means only WINDOW is redisplayed in redisplay_internal.
13099 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13100 in redisplay_window to bring a partially visible line into view in
13101 the case that only the cursor has moved.
13103 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13104 last screen line's vertical height extends past the end of the screen.
13108 1 if scrolling succeeded
13110 0 if scrolling didn't find point.
13112 -1 if new fonts have been loaded so that we must interrupt
13113 redisplay, adjust glyph matrices, and try again. */
13119 SCROLLING_NEED_LARGER_MATRICES
13123 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
13124 scroll_step
, temp_scroll_step
, last_line_misfit
)
13125 Lisp_Object window
;
13126 int just_this_one_p
;
13127 EMACS_INT scroll_conservatively
, scroll_step
;
13128 int temp_scroll_step
;
13129 int last_line_misfit
;
13131 struct window
*w
= XWINDOW (window
);
13132 struct frame
*f
= XFRAME (w
->frame
);
13133 struct text_pos pos
, startp
;
13135 int this_scroll_margin
, scroll_max
, rc
, height
;
13136 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13137 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13138 Lisp_Object aggressive
;
13139 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13142 debug_method_add (w
, "try_scrolling");
13145 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13147 /* Compute scroll margin height in pixels. We scroll when point is
13148 within this distance from the top or bottom of the window. */
13149 if (scroll_margin
> 0)
13150 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13151 * FRAME_LINE_HEIGHT (f
);
13153 this_scroll_margin
= 0;
13155 /* Force scroll_conservatively to have a reasonable value, to avoid
13156 overflow while computing how much to scroll. Note that the user
13157 can supply scroll-conservatively equal to `most-positive-fixnum',
13158 which can be larger than INT_MAX. */
13159 if (scroll_conservatively
> scroll_limit
)
13161 scroll_conservatively
= scroll_limit
;
13162 scroll_max
= INT_MAX
;
13164 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13165 /* Compute how much we should try to scroll maximally to bring
13166 point into view. */
13167 scroll_max
= (max (scroll_step
,
13168 max (scroll_conservatively
, temp_scroll_step
))
13169 * FRAME_LINE_HEIGHT (f
));
13170 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13171 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13172 /* We're trying to scroll because of aggressive scrolling but no
13173 scroll_step is set. Choose an arbitrary one. */
13174 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13180 /* Decide whether to scroll down. */
13181 if (PT
> CHARPOS (startp
))
13183 int scroll_margin_y
;
13185 /* Compute the pixel ypos of the scroll margin, then move it to
13186 either that ypos or PT, whichever comes first. */
13187 start_display (&it
, w
, startp
);
13188 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13189 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13190 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13191 (MOVE_TO_POS
| MOVE_TO_Y
));
13193 if (PT
> CHARPOS (it
.current
.pos
))
13195 int y0
= line_bottom_y (&it
);
13197 /* Compute the distance from the scroll margin to PT
13198 (including the height of the cursor line). Moving the
13199 iterator unconditionally to PT can be slow if PT is far
13200 away, so stop 10 lines past the window bottom (is there a
13201 way to do the right thing quickly?). */
13202 move_it_to (&it
, PT
, -1,
13203 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
13204 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13205 dy
= line_bottom_y (&it
) - y0
;
13207 if (dy
> scroll_max
)
13208 return SCROLLING_FAILED
;
13216 /* Point is in or below the bottom scroll margin, so move the
13217 window start down. If scrolling conservatively, move it just
13218 enough down to make point visible. If scroll_step is set,
13219 move it down by scroll_step. */
13220 if (scroll_conservatively
)
13222 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13223 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13224 else if (scroll_step
|| temp_scroll_step
)
13225 amount_to_scroll
= scroll_max
;
13228 aggressive
= current_buffer
->scroll_up_aggressively
;
13229 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13230 if (NUMBERP (aggressive
))
13232 double float_amount
= XFLOATINT (aggressive
) * height
;
13233 amount_to_scroll
= float_amount
;
13234 if (amount_to_scroll
== 0 && float_amount
> 0)
13235 amount_to_scroll
= 1;
13239 if (amount_to_scroll
<= 0)
13240 return SCROLLING_FAILED
;
13242 start_display (&it
, w
, startp
);
13243 move_it_vertically (&it
, amount_to_scroll
);
13245 /* If STARTP is unchanged, move it down another screen line. */
13246 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13247 move_it_by_lines (&it
, 1, 1);
13248 startp
= it
.current
.pos
;
13252 struct text_pos scroll_margin_pos
= startp
;
13254 /* See if point is inside the scroll margin at the top of the
13256 if (this_scroll_margin
)
13258 start_display (&it
, w
, startp
);
13259 move_it_vertically (&it
, this_scroll_margin
);
13260 scroll_margin_pos
= it
.current
.pos
;
13263 if (PT
< CHARPOS (scroll_margin_pos
))
13265 /* Point is in the scroll margin at the top of the window or
13266 above what is displayed in the window. */
13269 /* Compute the vertical distance from PT to the scroll
13270 margin position. Give up if distance is greater than
13272 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13273 start_display (&it
, w
, pos
);
13275 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13276 it
.last_visible_y
, -1,
13277 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13278 dy
= it
.current_y
- y0
;
13279 if (dy
> scroll_max
)
13280 return SCROLLING_FAILED
;
13282 /* Compute new window start. */
13283 start_display (&it
, w
, startp
);
13285 if (scroll_conservatively
)
13287 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13288 else if (scroll_step
|| temp_scroll_step
)
13289 amount_to_scroll
= scroll_max
;
13292 aggressive
= current_buffer
->scroll_down_aggressively
;
13293 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13294 if (NUMBERP (aggressive
))
13296 double float_amount
= XFLOATINT (aggressive
) * height
;
13297 amount_to_scroll
= float_amount
;
13298 if (amount_to_scroll
== 0 && float_amount
> 0)
13299 amount_to_scroll
= 1;
13303 if (amount_to_scroll
<= 0)
13304 return SCROLLING_FAILED
;
13306 move_it_vertically_backward (&it
, amount_to_scroll
);
13307 startp
= it
.current
.pos
;
13311 /* Run window scroll functions. */
13312 startp
= run_window_scroll_functions (window
, startp
);
13314 /* Display the window. Give up if new fonts are loaded, or if point
13316 if (!try_window (window
, startp
, 0))
13317 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13318 else if (w
->cursor
.vpos
< 0)
13320 clear_glyph_matrix (w
->desired_matrix
);
13321 rc
= SCROLLING_FAILED
;
13325 /* Maybe forget recorded base line for line number display. */
13326 if (!just_this_one_p
13327 || current_buffer
->clip_changed
13328 || BEG_UNCHANGED
< CHARPOS (startp
))
13329 w
->base_line_number
= Qnil
;
13331 /* If cursor ends up on a partially visible line,
13332 treat that as being off the bottom of the screen. */
13333 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13335 clear_glyph_matrix (w
->desired_matrix
);
13336 ++extra_scroll_margin_lines
;
13339 rc
= SCROLLING_SUCCESS
;
13346 /* Compute a suitable window start for window W if display of W starts
13347 on a continuation line. Value is non-zero if a new window start
13350 The new window start will be computed, based on W's width, starting
13351 from the start of the continued line. It is the start of the
13352 screen line with the minimum distance from the old start W->start. */
13355 compute_window_start_on_continuation_line (w
)
13358 struct text_pos pos
, start_pos
;
13359 int window_start_changed_p
= 0;
13361 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13363 /* If window start is on a continuation line... Window start may be
13364 < BEGV in case there's invisible text at the start of the
13365 buffer (M-x rmail, for example). */
13366 if (CHARPOS (start_pos
) > BEGV
13367 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13370 struct glyph_row
*row
;
13372 /* Handle the case that the window start is out of range. */
13373 if (CHARPOS (start_pos
) < BEGV
)
13374 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13375 else if (CHARPOS (start_pos
) > ZV
)
13376 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13378 /* Find the start of the continued line. This should be fast
13379 because scan_buffer is fast (newline cache). */
13380 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13381 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13382 row
, DEFAULT_FACE_ID
);
13383 reseat_at_previous_visible_line_start (&it
);
13385 /* If the line start is "too far" away from the window start,
13386 say it takes too much time to compute a new window start. */
13387 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13388 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13390 int min_distance
, distance
;
13392 /* Move forward by display lines to find the new window
13393 start. If window width was enlarged, the new start can
13394 be expected to be > the old start. If window width was
13395 decreased, the new window start will be < the old start.
13396 So, we're looking for the display line start with the
13397 minimum distance from the old window start. */
13398 pos
= it
.current
.pos
;
13399 min_distance
= INFINITY
;
13400 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13401 distance
< min_distance
)
13403 min_distance
= distance
;
13404 pos
= it
.current
.pos
;
13405 move_it_by_lines (&it
, 1, 0);
13408 /* Set the window start there. */
13409 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13410 window_start_changed_p
= 1;
13414 return window_start_changed_p
;
13418 /* Try cursor movement in case text has not changed in window WINDOW,
13419 with window start STARTP. Value is
13421 CURSOR_MOVEMENT_SUCCESS if successful
13423 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13425 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13426 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13427 we want to scroll as if scroll-step were set to 1. See the code.
13429 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13430 which case we have to abort this redisplay, and adjust matrices
13435 CURSOR_MOVEMENT_SUCCESS
,
13436 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13437 CURSOR_MOVEMENT_MUST_SCROLL
,
13438 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13442 try_cursor_movement (window
, startp
, scroll_step
)
13443 Lisp_Object window
;
13444 struct text_pos startp
;
13447 struct window
*w
= XWINDOW (window
);
13448 struct frame
*f
= XFRAME (w
->frame
);
13449 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13452 if (inhibit_try_cursor_movement
)
13456 /* Handle case where text has not changed, only point, and it has
13457 not moved off the frame. */
13458 if (/* Point may be in this window. */
13459 PT
>= CHARPOS (startp
)
13460 /* Selective display hasn't changed. */
13461 && !current_buffer
->clip_changed
13462 /* Function force-mode-line-update is used to force a thorough
13463 redisplay. It sets either windows_or_buffers_changed or
13464 update_mode_lines. So don't take a shortcut here for these
13466 && !update_mode_lines
13467 && !windows_or_buffers_changed
13468 && !cursor_type_changed
13469 /* Can't use this case if highlighting a region. When a
13470 region exists, cursor movement has to do more than just
13472 && !(!NILP (Vtransient_mark_mode
)
13473 && !NILP (current_buffer
->mark_active
))
13474 && NILP (w
->region_showing
)
13475 && NILP (Vshow_trailing_whitespace
)
13476 /* Right after splitting windows, last_point may be nil. */
13477 && INTEGERP (w
->last_point
)
13478 /* This code is not used for mini-buffer for the sake of the case
13479 of redisplaying to replace an echo area message; since in
13480 that case the mini-buffer contents per se are usually
13481 unchanged. This code is of no real use in the mini-buffer
13482 since the handling of this_line_start_pos, etc., in redisplay
13483 handles the same cases. */
13484 && !EQ (window
, minibuf_window
)
13485 /* When splitting windows or for new windows, it happens that
13486 redisplay is called with a nil window_end_vpos or one being
13487 larger than the window. This should really be fixed in
13488 window.c. I don't have this on my list, now, so we do
13489 approximately the same as the old redisplay code. --gerd. */
13490 && INTEGERP (w
->window_end_vpos
)
13491 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13492 && (FRAME_WINDOW_P (f
)
13493 || !overlay_arrow_in_current_buffer_p ()))
13495 int this_scroll_margin
, top_scroll_margin
;
13496 struct glyph_row
*row
= NULL
;
13499 debug_method_add (w
, "cursor movement");
13502 /* Scroll if point within this distance from the top or bottom
13503 of the window. This is a pixel value. */
13504 if (scroll_margin
> 0)
13506 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13507 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13510 this_scroll_margin
= 0;
13512 top_scroll_margin
= this_scroll_margin
;
13513 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13514 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13516 /* Start with the row the cursor was displayed during the last
13517 not paused redisplay. Give up if that row is not valid. */
13518 if (w
->last_cursor
.vpos
< 0
13519 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13520 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13523 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13524 if (row
->mode_line_p
)
13526 if (!row
->enabled_p
)
13527 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13528 /* If rows are bidi-reordered, back up until we find a row
13529 that does not belong to a continuation line. This is
13530 because we must consider all rows of a continued line as
13531 candidates for cursor positioning, since row start and
13532 end positions change non-linearly with vertical position
13534 /* FIXME: Revisit this when glyph ``spilling'' in
13535 continuation lines' rows is implemented for
13536 bidi-reordered rows. */
13537 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13539 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13541 xassert (row
->enabled_p
);
13543 /* If we hit the beginning of the displayed portion
13544 without finding the first row of a continued
13546 if (row
<= w
->current_matrix
->rows
)
13548 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13556 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13559 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13561 if (PT
> XFASTINT (w
->last_point
))
13563 /* Point has moved forward. */
13564 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13565 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13567 xassert (row
->enabled_p
);
13571 /* The end position of a row equals the start position
13572 of the next row. If PT is there, we would rather
13573 display it in the next line. */
13574 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13575 && MATRIX_ROW_END_CHARPOS (row
) == PT
13576 && !cursor_row_p (w
, row
))
13579 /* If within the scroll margin, scroll. Note that
13580 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13581 the next line would be drawn, and that
13582 this_scroll_margin can be zero. */
13583 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13584 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13585 /* Line is completely visible last line in window
13586 and PT is to be set in the next line. */
13587 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13588 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13589 && !row
->ends_at_zv_p
13590 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13593 else if (PT
< XFASTINT (w
->last_point
))
13595 /* Cursor has to be moved backward. Note that PT >=
13596 CHARPOS (startp) because of the outer if-statement. */
13597 while (!row
->mode_line_p
13598 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13599 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13600 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13601 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13602 row
> w
->current_matrix
->rows
13603 && (row
-1)->ends_in_newline_from_string_p
))))
13604 && (row
->y
> top_scroll_margin
13605 || CHARPOS (startp
) == BEGV
))
13607 xassert (row
->enabled_p
);
13611 /* Consider the following case: Window starts at BEGV,
13612 there is invisible, intangible text at BEGV, so that
13613 display starts at some point START > BEGV. It can
13614 happen that we are called with PT somewhere between
13615 BEGV and START. Try to handle that case. */
13616 if (row
< w
->current_matrix
->rows
13617 || row
->mode_line_p
)
13619 row
= w
->current_matrix
->rows
;
13620 if (row
->mode_line_p
)
13624 /* Due to newlines in overlay strings, we may have to
13625 skip forward over overlay strings. */
13626 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13627 && MATRIX_ROW_END_CHARPOS (row
) == PT
13628 && !cursor_row_p (w
, row
))
13631 /* If within the scroll margin, scroll. */
13632 if (row
->y
< top_scroll_margin
13633 && CHARPOS (startp
) != BEGV
)
13638 /* Cursor did not move. So don't scroll even if cursor line
13639 is partially visible, as it was so before. */
13640 rc
= CURSOR_MOVEMENT_SUCCESS
;
13643 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13644 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13646 /* if PT is not in the glyph row, give up. */
13647 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13649 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13650 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13651 && make_cursor_line_fully_visible_p
)
13653 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13654 && !row
->ends_at_zv_p
13655 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13656 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13657 else if (row
->height
> window_box_height (w
))
13659 /* If we end up in a partially visible line, let's
13660 make it fully visible, except when it's taller
13661 than the window, in which case we can't do much
13664 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13668 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13669 if (!cursor_row_fully_visible_p (w
, 0, 1))
13670 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13672 rc
= CURSOR_MOVEMENT_SUCCESS
;
13676 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13677 else if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13679 /* With bidi-reordered rows, there could be more than
13680 one candidate row whose start and end positions
13681 occlude point. We need to let set_cursor_from_row
13682 find the best candidate. */
13683 /* FIXME: Revisit this when glyph ``spilling'' in
13684 continuation lines' rows is implemented for
13685 bidi-reordered rows. */
13690 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13692 /* As soon as we've found the first suitable row
13693 whose ends_at_zv_p flag is set, we are done. */
13695 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13697 rc
= CURSOR_MOVEMENT_SUCCESS
;
13702 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13703 && MATRIX_ROW_START_CHARPOS (row
) <= PT
13704 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13705 && cursor_row_p (w
, row
));
13706 /* If we didn't find any candidate rows, or exited the
13707 loop before all the candidates were examined, signal
13708 to the caller that this method failed. */
13709 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13711 || (MATRIX_ROW_START_CHARPOS (row
) <= PT
13712 && PT
<= MATRIX_ROW_END_CHARPOS (row
))))
13713 rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13715 rc
= CURSOR_MOVEMENT_SUCCESS
;
13721 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13723 rc
= CURSOR_MOVEMENT_SUCCESS
;
13728 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13729 && MATRIX_ROW_START_CHARPOS (row
) == PT
13730 && cursor_row_p (w
, row
));
13739 set_vertical_scroll_bar (w
)
13742 int start
, end
, whole
;
13744 /* Calculate the start and end positions for the current window.
13745 At some point, it would be nice to choose between scrollbars
13746 which reflect the whole buffer size, with special markers
13747 indicating narrowing, and scrollbars which reflect only the
13750 Note that mini-buffers sometimes aren't displaying any text. */
13751 if (!MINI_WINDOW_P (w
)
13752 || (w
== XWINDOW (minibuf_window
)
13753 && NILP (echo_area_buffer
[0])))
13755 struct buffer
*buf
= XBUFFER (w
->buffer
);
13756 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13757 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13758 /* I don't think this is guaranteed to be right. For the
13759 moment, we'll pretend it is. */
13760 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13764 if (whole
< (end
- start
))
13765 whole
= end
- start
;
13768 start
= end
= whole
= 0;
13770 /* Indicate what this scroll bar ought to be displaying now. */
13771 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13772 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13773 (w
, end
- start
, whole
, start
);
13777 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13778 selected_window is redisplayed.
13780 We can return without actually redisplaying the window if
13781 fonts_changed_p is nonzero. In that case, redisplay_internal will
13785 redisplay_window (window
, just_this_one_p
)
13786 Lisp_Object window
;
13787 int just_this_one_p
;
13789 struct window
*w
= XWINDOW (window
);
13790 struct frame
*f
= XFRAME (w
->frame
);
13791 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13792 struct buffer
*old
= current_buffer
;
13793 struct text_pos lpoint
, opoint
, startp
;
13794 int update_mode_line
;
13797 /* Record it now because it's overwritten. */
13798 int current_matrix_up_to_date_p
= 0;
13799 int used_current_matrix_p
= 0;
13800 /* This is less strict than current_matrix_up_to_date_p.
13801 It indictes that the buffer contents and narrowing are unchanged. */
13802 int buffer_unchanged_p
= 0;
13803 int temp_scroll_step
= 0;
13804 int count
= SPECPDL_INDEX ();
13806 int centering_position
= -1;
13807 int last_line_misfit
= 0;
13808 int beg_unchanged
, end_unchanged
;
13810 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13813 /* W must be a leaf window here. */
13814 xassert (!NILP (w
->buffer
));
13816 *w
->desired_matrix
->method
= 0;
13820 reconsider_clip_changes (w
, buffer
);
13822 /* Has the mode line to be updated? */
13823 update_mode_line
= (!NILP (w
->update_mode_line
)
13824 || update_mode_lines
13825 || buffer
->clip_changed
13826 || buffer
->prevent_redisplay_optimizations_p
);
13828 if (MINI_WINDOW_P (w
))
13830 if (w
== XWINDOW (echo_area_window
)
13831 && !NILP (echo_area_buffer
[0]))
13833 if (update_mode_line
)
13834 /* We may have to update a tty frame's menu bar or a
13835 tool-bar. Example `M-x C-h C-h C-g'. */
13836 goto finish_menu_bars
;
13838 /* We've already displayed the echo area glyphs in this window. */
13839 goto finish_scroll_bars
;
13841 else if ((w
!= XWINDOW (minibuf_window
)
13842 || minibuf_level
== 0)
13843 /* When buffer is nonempty, redisplay window normally. */
13844 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13845 /* Quail displays non-mini buffers in minibuffer window.
13846 In that case, redisplay the window normally. */
13847 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13849 /* W is a mini-buffer window, but it's not active, so clear
13851 int yb
= window_text_bottom_y (w
);
13852 struct glyph_row
*row
;
13855 for (y
= 0, row
= w
->desired_matrix
->rows
;
13857 y
+= row
->height
, ++row
)
13858 blank_row (w
, row
, y
);
13859 goto finish_scroll_bars
;
13862 clear_glyph_matrix (w
->desired_matrix
);
13865 /* Otherwise set up data on this window; select its buffer and point
13867 /* Really select the buffer, for the sake of buffer-local
13869 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13871 current_matrix_up_to_date_p
13872 = (!NILP (w
->window_end_valid
)
13873 && !current_buffer
->clip_changed
13874 && !current_buffer
->prevent_redisplay_optimizations_p
13875 && XFASTINT (w
->last_modified
) >= MODIFF
13876 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13878 /* Run the window-bottom-change-functions
13879 if it is possible that the text on the screen has changed
13880 (either due to modification of the text, or any other reason). */
13881 if (!current_matrix_up_to_date_p
13882 && !NILP (Vwindow_text_change_functions
))
13884 safe_run_hooks (Qwindow_text_change_functions
);
13888 beg_unchanged
= BEG_UNCHANGED
;
13889 end_unchanged
= END_UNCHANGED
;
13891 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13893 specbind (Qinhibit_point_motion_hooks
, Qt
);
13896 = (!NILP (w
->window_end_valid
)
13897 && !current_buffer
->clip_changed
13898 && XFASTINT (w
->last_modified
) >= MODIFF
13899 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13901 /* When windows_or_buffers_changed is non-zero, we can't rely on
13902 the window end being valid, so set it to nil there. */
13903 if (windows_or_buffers_changed
)
13905 /* If window starts on a continuation line, maybe adjust the
13906 window start in case the window's width changed. */
13907 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13908 compute_window_start_on_continuation_line (w
);
13910 w
->window_end_valid
= Qnil
;
13913 /* Some sanity checks. */
13914 CHECK_WINDOW_END (w
);
13915 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13917 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13920 /* If %c is in mode line, update it if needed. */
13921 if (!NILP (w
->column_number_displayed
)
13922 /* This alternative quickly identifies a common case
13923 where no change is needed. */
13924 && !(PT
== XFASTINT (w
->last_point
)
13925 && XFASTINT (w
->last_modified
) >= MODIFF
13926 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13927 && (XFASTINT (w
->column_number_displayed
)
13928 != (int) current_column ())) /* iftc */
13929 update_mode_line
= 1;
13931 /* Count number of windows showing the selected buffer. An indirect
13932 buffer counts as its base buffer. */
13933 if (!just_this_one_p
)
13935 struct buffer
*current_base
, *window_base
;
13936 current_base
= current_buffer
;
13937 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13938 if (current_base
->base_buffer
)
13939 current_base
= current_base
->base_buffer
;
13940 if (window_base
->base_buffer
)
13941 window_base
= window_base
->base_buffer
;
13942 if (current_base
== window_base
)
13946 /* Point refers normally to the selected window. For any other
13947 window, set up appropriate value. */
13948 if (!EQ (window
, selected_window
))
13950 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13951 int new_pt_byte
= marker_byte_position (w
->pointm
);
13955 new_pt_byte
= BEGV_BYTE
;
13956 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13958 else if (new_pt
> (ZV
- 1))
13961 new_pt_byte
= ZV_BYTE
;
13962 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13965 /* We don't use SET_PT so that the point-motion hooks don't run. */
13966 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13969 /* If any of the character widths specified in the display table
13970 have changed, invalidate the width run cache. It's true that
13971 this may be a bit late to catch such changes, but the rest of
13972 redisplay goes (non-fatally) haywire when the display table is
13973 changed, so why should we worry about doing any better? */
13974 if (current_buffer
->width_run_cache
)
13976 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13978 if (! disptab_matches_widthtab (disptab
,
13979 XVECTOR (current_buffer
->width_table
)))
13981 invalidate_region_cache (current_buffer
,
13982 current_buffer
->width_run_cache
,
13984 recompute_width_table (current_buffer
, disptab
);
13988 /* If window-start is screwed up, choose a new one. */
13989 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13992 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13994 /* If someone specified a new starting point but did not insist,
13995 check whether it can be used. */
13996 if (!NILP (w
->optional_new_start
)
13997 && CHARPOS (startp
) >= BEGV
13998 && CHARPOS (startp
) <= ZV
)
14000 w
->optional_new_start
= Qnil
;
14001 start_display (&it
, w
, startp
);
14002 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14003 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14004 if (IT_CHARPOS (it
) == PT
)
14005 w
->force_start
= Qt
;
14006 /* IT may overshoot PT if text at PT is invisible. */
14007 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14008 w
->force_start
= Qt
;
14013 /* Handle case where place to start displaying has been specified,
14014 unless the specified location is outside the accessible range. */
14015 if (!NILP (w
->force_start
)
14016 || w
->frozen_window_start_p
)
14018 /* We set this later on if we have to adjust point. */
14021 w
->force_start
= Qnil
;
14023 w
->window_end_valid
= Qnil
;
14025 /* Forget any recorded base line for line number display. */
14026 if (!buffer_unchanged_p
)
14027 w
->base_line_number
= Qnil
;
14029 /* Redisplay the mode line. Select the buffer properly for that.
14030 Also, run the hook window-scroll-functions
14031 because we have scrolled. */
14032 /* Note, we do this after clearing force_start because
14033 if there's an error, it is better to forget about force_start
14034 than to get into an infinite loop calling the hook functions
14035 and having them get more errors. */
14036 if (!update_mode_line
14037 || ! NILP (Vwindow_scroll_functions
))
14039 update_mode_line
= 1;
14040 w
->update_mode_line
= Qt
;
14041 startp
= run_window_scroll_functions (window
, startp
);
14044 w
->last_modified
= make_number (0);
14045 w
->last_overlay_modified
= make_number (0);
14046 if (CHARPOS (startp
) < BEGV
)
14047 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14048 else if (CHARPOS (startp
) > ZV
)
14049 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14051 /* Redisplay, then check if cursor has been set during the
14052 redisplay. Give up if new fonts were loaded. */
14053 /* We used to issue a CHECK_MARGINS argument to try_window here,
14054 but this causes scrolling to fail when point begins inside
14055 the scroll margin (bug#148) -- cyd */
14056 if (!try_window (window
, startp
, 0))
14058 w
->force_start
= Qt
;
14059 clear_glyph_matrix (w
->desired_matrix
);
14060 goto need_larger_matrices
;
14063 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14065 /* If point does not appear, try to move point so it does
14066 appear. The desired matrix has been built above, so we
14067 can use it here. */
14068 new_vpos
= window_box_height (w
) / 2;
14071 if (!cursor_row_fully_visible_p (w
, 0, 0))
14073 /* Point does appear, but on a line partly visible at end of window.
14074 Move it back to a fully-visible line. */
14075 new_vpos
= window_box_height (w
);
14078 /* If we need to move point for either of the above reasons,
14079 now actually do it. */
14082 struct glyph_row
*row
;
14084 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14085 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14088 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14089 MATRIX_ROW_START_BYTEPOS (row
));
14091 if (w
!= XWINDOW (selected_window
))
14092 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14093 else if (current_buffer
== old
)
14094 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14096 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14098 /* If we are highlighting the region, then we just changed
14099 the region, so redisplay to show it. */
14100 if (!NILP (Vtransient_mark_mode
)
14101 && !NILP (current_buffer
->mark_active
))
14103 clear_glyph_matrix (w
->desired_matrix
);
14104 if (!try_window (window
, startp
, 0))
14105 goto need_larger_matrices
;
14110 debug_method_add (w
, "forced window start");
14115 /* Handle case where text has not changed, only point, and it has
14116 not moved off the frame, and we are not retrying after hscroll.
14117 (current_matrix_up_to_date_p is nonzero when retrying.) */
14118 if (current_matrix_up_to_date_p
14119 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14120 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14124 case CURSOR_MOVEMENT_SUCCESS
:
14125 used_current_matrix_p
= 1;
14128 case CURSOR_MOVEMENT_MUST_SCROLL
:
14129 goto try_to_scroll
;
14135 /* If current starting point was originally the beginning of a line
14136 but no longer is, find a new starting point. */
14137 else if (!NILP (w
->start_at_line_beg
)
14138 && !(CHARPOS (startp
) <= BEGV
14139 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14142 debug_method_add (w
, "recenter 1");
14147 /* Try scrolling with try_window_id. Value is > 0 if update has
14148 been done, it is -1 if we know that the same window start will
14149 not work. It is 0 if unsuccessful for some other reason. */
14150 else if ((tem
= try_window_id (w
)) != 0)
14153 debug_method_add (w
, "try_window_id %d", tem
);
14156 if (fonts_changed_p
)
14157 goto need_larger_matrices
;
14161 /* Otherwise try_window_id has returned -1 which means that we
14162 don't want the alternative below this comment to execute. */
14164 else if (CHARPOS (startp
) >= BEGV
14165 && CHARPOS (startp
) <= ZV
14166 && PT
>= CHARPOS (startp
)
14167 && (CHARPOS (startp
) < ZV
14168 /* Avoid starting at end of buffer. */
14169 || CHARPOS (startp
) == BEGV
14170 || (XFASTINT (w
->last_modified
) >= MODIFF
14171 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14174 /* If first window line is a continuation line, and window start
14175 is inside the modified region, but the first change is before
14176 current window start, we must select a new window start.
14178 However, if this is the result of a down-mouse event (e.g. by
14179 extending the mouse-drag-overlay), we don't want to select a
14180 new window start, since that would change the position under
14181 the mouse, resulting in an unwanted mouse-movement rather
14182 than a simple mouse-click. */
14183 if (NILP (w
->start_at_line_beg
)
14184 && NILP (do_mouse_tracking
)
14185 && CHARPOS (startp
) > BEGV
14186 && CHARPOS (startp
) > BEG
+ beg_unchanged
14187 && CHARPOS (startp
) <= Z
- end_unchanged
14188 /* Even if w->start_at_line_beg is nil, a new window may
14189 start at a line_beg, since that's how set_buffer_window
14190 sets it. So, we need to check the return value of
14191 compute_window_start_on_continuation_line. (See also
14193 && XMARKER (w
->start
)->buffer
== current_buffer
14194 && compute_window_start_on_continuation_line (w
))
14196 w
->force_start
= Qt
;
14197 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14202 debug_method_add (w
, "same window start");
14205 /* Try to redisplay starting at same place as before.
14206 If point has not moved off frame, accept the results. */
14207 if (!current_matrix_up_to_date_p
14208 /* Don't use try_window_reusing_current_matrix in this case
14209 because a window scroll function can have changed the
14211 || !NILP (Vwindow_scroll_functions
)
14212 || MINI_WINDOW_P (w
)
14213 || !(used_current_matrix_p
14214 = try_window_reusing_current_matrix (w
)))
14216 IF_DEBUG (debug_method_add (w
, "1"));
14217 if (try_window (window
, startp
, 1) < 0)
14218 /* -1 means we need to scroll.
14219 0 means we need new matrices, but fonts_changed_p
14220 is set in that case, so we will detect it below. */
14221 goto try_to_scroll
;
14224 if (fonts_changed_p
)
14225 goto need_larger_matrices
;
14227 if (w
->cursor
.vpos
>= 0)
14229 if (!just_this_one_p
14230 || current_buffer
->clip_changed
14231 || BEG_UNCHANGED
< CHARPOS (startp
))
14232 /* Forget any recorded base line for line number display. */
14233 w
->base_line_number
= Qnil
;
14235 if (!cursor_row_fully_visible_p (w
, 1, 0))
14237 clear_glyph_matrix (w
->desired_matrix
);
14238 last_line_misfit
= 1;
14240 /* Drop through and scroll. */
14245 clear_glyph_matrix (w
->desired_matrix
);
14250 w
->last_modified
= make_number (0);
14251 w
->last_overlay_modified
= make_number (0);
14253 /* Redisplay the mode line. Select the buffer properly for that. */
14254 if (!update_mode_line
)
14256 update_mode_line
= 1;
14257 w
->update_mode_line
= Qt
;
14260 /* Try to scroll by specified few lines. */
14261 if ((scroll_conservatively
14263 || temp_scroll_step
14264 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14265 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14266 && !current_buffer
->clip_changed
14267 && CHARPOS (startp
) >= BEGV
14268 && CHARPOS (startp
) <= ZV
)
14270 /* The function returns -1 if new fonts were loaded, 1 if
14271 successful, 0 if not successful. */
14272 int rc
= try_scrolling (window
, just_this_one_p
,
14273 scroll_conservatively
,
14275 temp_scroll_step
, last_line_misfit
);
14278 case SCROLLING_SUCCESS
:
14281 case SCROLLING_NEED_LARGER_MATRICES
:
14282 goto need_larger_matrices
;
14284 case SCROLLING_FAILED
:
14292 /* Finally, just choose place to start which centers point */
14295 if (centering_position
< 0)
14296 centering_position
= window_box_height (w
) / 2;
14299 debug_method_add (w
, "recenter");
14302 /* w->vscroll = 0; */
14304 /* Forget any previously recorded base line for line number display. */
14305 if (!buffer_unchanged_p
)
14306 w
->base_line_number
= Qnil
;
14308 /* Move backward half the height of the window. */
14309 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14310 it
.current_y
= it
.last_visible_y
;
14311 move_it_vertically_backward (&it
, centering_position
);
14312 xassert (IT_CHARPOS (it
) >= BEGV
);
14314 /* The function move_it_vertically_backward may move over more
14315 than the specified y-distance. If it->w is small, e.g. a
14316 mini-buffer window, we may end up in front of the window's
14317 display area. Start displaying at the start of the line
14318 containing PT in this case. */
14319 if (it
.current_y
<= 0)
14321 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14322 move_it_vertically_backward (&it
, 0);
14326 it
.current_x
= it
.hpos
= 0;
14328 /* Set startp here explicitly in case that helps avoid an infinite loop
14329 in case the window-scroll-functions functions get errors. */
14330 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14332 /* Run scroll hooks. */
14333 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14335 /* Redisplay the window. */
14336 if (!current_matrix_up_to_date_p
14337 || windows_or_buffers_changed
14338 || cursor_type_changed
14339 /* Don't use try_window_reusing_current_matrix in this case
14340 because it can have changed the buffer. */
14341 || !NILP (Vwindow_scroll_functions
)
14342 || !just_this_one_p
14343 || MINI_WINDOW_P (w
)
14344 || !(used_current_matrix_p
14345 = try_window_reusing_current_matrix (w
)))
14346 try_window (window
, startp
, 0);
14348 /* If new fonts have been loaded (due to fontsets), give up. We
14349 have to start a new redisplay since we need to re-adjust glyph
14351 if (fonts_changed_p
)
14352 goto need_larger_matrices
;
14354 /* If cursor did not appear assume that the middle of the window is
14355 in the first line of the window. Do it again with the next line.
14356 (Imagine a window of height 100, displaying two lines of height
14357 60. Moving back 50 from it->last_visible_y will end in the first
14359 if (w
->cursor
.vpos
< 0)
14361 if (!NILP (w
->window_end_valid
)
14362 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14364 clear_glyph_matrix (w
->desired_matrix
);
14365 move_it_by_lines (&it
, 1, 0);
14366 try_window (window
, it
.current
.pos
, 0);
14368 else if (PT
< IT_CHARPOS (it
))
14370 clear_glyph_matrix (w
->desired_matrix
);
14371 move_it_by_lines (&it
, -1, 0);
14372 try_window (window
, it
.current
.pos
, 0);
14376 /* Not much we can do about it. */
14380 /* Consider the following case: Window starts at BEGV, there is
14381 invisible, intangible text at BEGV, so that display starts at
14382 some point START > BEGV. It can happen that we are called with
14383 PT somewhere between BEGV and START. Try to handle that case. */
14384 if (w
->cursor
.vpos
< 0)
14386 struct glyph_row
*row
= w
->current_matrix
->rows
;
14387 if (row
->mode_line_p
)
14389 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14392 if (!cursor_row_fully_visible_p (w
, 0, 0))
14394 /* If vscroll is enabled, disable it and try again. */
14398 clear_glyph_matrix (w
->desired_matrix
);
14402 /* If centering point failed to make the whole line visible,
14403 put point at the top instead. That has to make the whole line
14404 visible, if it can be done. */
14405 if (centering_position
== 0)
14408 clear_glyph_matrix (w
->desired_matrix
);
14409 centering_position
= 0;
14415 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14416 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14417 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14420 /* Display the mode line, if we must. */
14421 if ((update_mode_line
14422 /* If window not full width, must redo its mode line
14423 if (a) the window to its side is being redone and
14424 (b) we do a frame-based redisplay. This is a consequence
14425 of how inverted lines are drawn in frame-based redisplay. */
14426 || (!just_this_one_p
14427 && !FRAME_WINDOW_P (f
)
14428 && !WINDOW_FULL_WIDTH_P (w
))
14429 /* Line number to display. */
14430 || INTEGERP (w
->base_line_pos
)
14431 /* Column number is displayed and different from the one displayed. */
14432 || (!NILP (w
->column_number_displayed
)
14433 && (XFASTINT (w
->column_number_displayed
)
14434 != (int) current_column ()))) /* iftc */
14435 /* This means that the window has a mode line. */
14436 && (WINDOW_WANTS_MODELINE_P (w
)
14437 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14439 display_mode_lines (w
);
14441 /* If mode line height has changed, arrange for a thorough
14442 immediate redisplay using the correct mode line height. */
14443 if (WINDOW_WANTS_MODELINE_P (w
)
14444 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14446 fonts_changed_p
= 1;
14447 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14448 = DESIRED_MODE_LINE_HEIGHT (w
);
14451 /* If header line height has changed, arrange for a thorough
14452 immediate redisplay using the correct header line height. */
14453 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14454 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14456 fonts_changed_p
= 1;
14457 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14458 = DESIRED_HEADER_LINE_HEIGHT (w
);
14461 if (fonts_changed_p
)
14462 goto need_larger_matrices
;
14465 if (!line_number_displayed
14466 && !BUFFERP (w
->base_line_pos
))
14468 w
->base_line_pos
= Qnil
;
14469 w
->base_line_number
= Qnil
;
14474 /* When we reach a frame's selected window, redo the frame's menu bar. */
14475 if (update_mode_line
14476 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14478 int redisplay_menu_p
= 0;
14479 int redisplay_tool_bar_p
= 0;
14481 if (FRAME_WINDOW_P (f
))
14483 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14484 || defined (HAVE_NS) || defined (USE_GTK)
14485 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14487 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14491 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14493 if (redisplay_menu_p
)
14494 display_menu_bar (w
);
14496 #ifdef HAVE_WINDOW_SYSTEM
14497 if (FRAME_WINDOW_P (f
))
14499 #if defined (USE_GTK) || defined (HAVE_NS)
14500 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14502 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14503 && (FRAME_TOOL_BAR_LINES (f
) > 0
14504 || !NILP (Vauto_resize_tool_bars
));
14507 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14509 extern int ignore_mouse_drag_p
;
14510 ignore_mouse_drag_p
= 1;
14516 #ifdef HAVE_WINDOW_SYSTEM
14517 if (FRAME_WINDOW_P (f
)
14518 && update_window_fringes (w
, (just_this_one_p
14519 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14520 || w
->pseudo_window_p
)))
14524 if (draw_window_fringes (w
, 1))
14525 x_draw_vertical_border (w
);
14529 #endif /* HAVE_WINDOW_SYSTEM */
14531 /* We go to this label, with fonts_changed_p nonzero,
14532 if it is necessary to try again using larger glyph matrices.
14533 We have to redeem the scroll bar even in this case,
14534 because the loop in redisplay_internal expects that. */
14535 need_larger_matrices
:
14537 finish_scroll_bars
:
14539 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14541 /* Set the thumb's position and size. */
14542 set_vertical_scroll_bar (w
);
14544 /* Note that we actually used the scroll bar attached to this
14545 window, so it shouldn't be deleted at the end of redisplay. */
14546 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14547 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14550 /* Restore current_buffer and value of point in it. */
14551 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14552 set_buffer_internal_1 (old
);
14553 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14554 shorter. This can be caused by log truncation in *Messages*. */
14555 if (CHARPOS (lpoint
) <= ZV
)
14556 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14558 unbind_to (count
, Qnil
);
14562 /* Build the complete desired matrix of WINDOW with a window start
14563 buffer position POS.
14565 Value is 1 if successful. It is zero if fonts were loaded during
14566 redisplay which makes re-adjusting glyph matrices necessary, and -1
14567 if point would appear in the scroll margins.
14568 (We check that only if CHECK_MARGINS is nonzero. */
14571 try_window (window
, pos
, check_margins
)
14572 Lisp_Object window
;
14573 struct text_pos pos
;
14576 struct window
*w
= XWINDOW (window
);
14578 struct glyph_row
*last_text_row
= NULL
;
14579 struct frame
*f
= XFRAME (w
->frame
);
14581 /* Make POS the new window start. */
14582 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14584 /* Mark cursor position as unknown. No overlay arrow seen. */
14585 w
->cursor
.vpos
= -1;
14586 overlay_arrow_seen
= 0;
14588 /* Initialize iterator and info to start at POS. */
14589 start_display (&it
, w
, pos
);
14591 /* Display all lines of W. */
14592 while (it
.current_y
< it
.last_visible_y
)
14594 if (display_line (&it
))
14595 last_text_row
= it
.glyph_row
- 1;
14596 if (fonts_changed_p
)
14600 /* Don't let the cursor end in the scroll margins. */
14602 && !MINI_WINDOW_P (w
))
14604 int this_scroll_margin
;
14606 if (scroll_margin
> 0)
14608 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14609 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14612 this_scroll_margin
= 0;
14614 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14615 && w
->cursor
.y
< this_scroll_margin
14616 && CHARPOS (pos
) > BEGV
14617 && IT_CHARPOS (it
) < ZV
)
14618 /* rms: considering make_cursor_line_fully_visible_p here
14619 seems to give wrong results. We don't want to recenter
14620 when the last line is partly visible, we want to allow
14621 that case to be handled in the usual way. */
14622 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14624 w
->cursor
.vpos
= -1;
14625 clear_glyph_matrix (w
->desired_matrix
);
14630 /* If bottom moved off end of frame, change mode line percentage. */
14631 if (XFASTINT (w
->window_end_pos
) <= 0
14632 && Z
!= IT_CHARPOS (it
))
14633 w
->update_mode_line
= Qt
;
14635 /* Set window_end_pos to the offset of the last character displayed
14636 on the window from the end of current_buffer. Set
14637 window_end_vpos to its row number. */
14640 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14641 w
->window_end_bytepos
14642 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14644 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14646 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14647 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14648 ->displays_text_p
);
14652 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14653 w
->window_end_pos
= make_number (Z
- ZV
);
14654 w
->window_end_vpos
= make_number (0);
14657 /* But that is not valid info until redisplay finishes. */
14658 w
->window_end_valid
= Qnil
;
14664 /************************************************************************
14665 Window redisplay reusing current matrix when buffer has not changed
14666 ************************************************************************/
14668 /* Try redisplay of window W showing an unchanged buffer with a
14669 different window start than the last time it was displayed by
14670 reusing its current matrix. Value is non-zero if successful.
14671 W->start is the new window start. */
14674 try_window_reusing_current_matrix (w
)
14677 struct frame
*f
= XFRAME (w
->frame
);
14678 struct glyph_row
*row
, *bottom_row
;
14681 struct text_pos start
, new_start
;
14682 int nrows_scrolled
, i
;
14683 struct glyph_row
*last_text_row
;
14684 struct glyph_row
*last_reused_text_row
;
14685 struct glyph_row
*start_row
;
14686 int start_vpos
, min_y
, max_y
;
14689 if (inhibit_try_window_reusing
)
14693 if (/* This function doesn't handle terminal frames. */
14694 !FRAME_WINDOW_P (f
)
14695 /* Don't try to reuse the display if windows have been split
14697 || windows_or_buffers_changed
14698 || cursor_type_changed
)
14701 /* Can't do this if region may have changed. */
14702 if ((!NILP (Vtransient_mark_mode
)
14703 && !NILP (current_buffer
->mark_active
))
14704 || !NILP (w
->region_showing
)
14705 || !NILP (Vshow_trailing_whitespace
))
14708 /* If top-line visibility has changed, give up. */
14709 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14710 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14713 /* Give up if old or new display is scrolled vertically. We could
14714 make this function handle this, but right now it doesn't. */
14715 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14716 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14719 /* The variable new_start now holds the new window start. The old
14720 start `start' can be determined from the current matrix. */
14721 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14722 start
= start_row
->start
.pos
;
14723 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14725 /* Clear the desired matrix for the display below. */
14726 clear_glyph_matrix (w
->desired_matrix
);
14728 if (CHARPOS (new_start
) <= CHARPOS (start
))
14732 /* Don't use this method if the display starts with an ellipsis
14733 displayed for invisible text. It's not easy to handle that case
14734 below, and it's certainly not worth the effort since this is
14735 not a frequent case. */
14736 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14739 IF_DEBUG (debug_method_add (w
, "twu1"));
14741 /* Display up to a row that can be reused. The variable
14742 last_text_row is set to the last row displayed that displays
14743 text. Note that it.vpos == 0 if or if not there is a
14744 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14745 start_display (&it
, w
, new_start
);
14746 first_row_y
= it
.current_y
;
14747 w
->cursor
.vpos
= -1;
14748 last_text_row
= last_reused_text_row
= NULL
;
14750 while (it
.current_y
< it
.last_visible_y
14751 && !fonts_changed_p
)
14753 /* If we have reached into the characters in the START row,
14754 that means the line boundaries have changed. So we
14755 can't start copying with the row START. Maybe it will
14756 work to start copying with the following row. */
14757 while (IT_CHARPOS (it
) > CHARPOS (start
))
14759 /* Advance to the next row as the "start". */
14761 start
= start_row
->start
.pos
;
14762 /* If there are no more rows to try, or just one, give up. */
14763 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14764 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14765 || CHARPOS (start
) == ZV
)
14767 clear_glyph_matrix (w
->desired_matrix
);
14771 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14773 /* If we have reached alignment,
14774 we can copy the rest of the rows. */
14775 if (IT_CHARPOS (it
) == CHARPOS (start
))
14778 if (display_line (&it
))
14779 last_text_row
= it
.glyph_row
- 1;
14782 /* A value of current_y < last_visible_y means that we stopped
14783 at the previous window start, which in turn means that we
14784 have at least one reusable row. */
14785 if (it
.current_y
< it
.last_visible_y
)
14787 /* IT.vpos always starts from 0; it counts text lines. */
14788 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14790 /* Find PT if not already found in the lines displayed. */
14791 if (w
->cursor
.vpos
< 0)
14793 int dy
= it
.current_y
- start_row
->y
;
14795 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14796 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14798 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14799 dy
, nrows_scrolled
);
14802 clear_glyph_matrix (w
->desired_matrix
);
14807 /* Scroll the display. Do it before the current matrix is
14808 changed. The problem here is that update has not yet
14809 run, i.e. part of the current matrix is not up to date.
14810 scroll_run_hook will clear the cursor, and use the
14811 current matrix to get the height of the row the cursor is
14813 run
.current_y
= start_row
->y
;
14814 run
.desired_y
= it
.current_y
;
14815 run
.height
= it
.last_visible_y
- it
.current_y
;
14817 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14820 FRAME_RIF (f
)->update_window_begin_hook (w
);
14821 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14822 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14823 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14827 /* Shift current matrix down by nrows_scrolled lines. */
14828 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14829 rotate_matrix (w
->current_matrix
,
14831 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14834 /* Disable lines that must be updated. */
14835 for (i
= 0; i
< nrows_scrolled
; ++i
)
14836 (start_row
+ i
)->enabled_p
= 0;
14838 /* Re-compute Y positions. */
14839 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14840 max_y
= it
.last_visible_y
;
14841 for (row
= start_row
+ nrows_scrolled
;
14845 row
->y
= it
.current_y
;
14846 row
->visible_height
= row
->height
;
14848 if (row
->y
< min_y
)
14849 row
->visible_height
-= min_y
- row
->y
;
14850 if (row
->y
+ row
->height
> max_y
)
14851 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14852 row
->redraw_fringe_bitmaps_p
= 1;
14854 it
.current_y
+= row
->height
;
14856 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14857 last_reused_text_row
= row
;
14858 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14862 /* Disable lines in the current matrix which are now
14863 below the window. */
14864 for (++row
; row
< bottom_row
; ++row
)
14865 row
->enabled_p
= row
->mode_line_p
= 0;
14868 /* Update window_end_pos etc.; last_reused_text_row is the last
14869 reused row from the current matrix containing text, if any.
14870 The value of last_text_row is the last displayed line
14871 containing text. */
14872 if (last_reused_text_row
)
14874 w
->window_end_bytepos
14875 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14877 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14879 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14880 w
->current_matrix
));
14882 else if (last_text_row
)
14884 w
->window_end_bytepos
14885 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14887 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14889 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14893 /* This window must be completely empty. */
14894 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14895 w
->window_end_pos
= make_number (Z
- ZV
);
14896 w
->window_end_vpos
= make_number (0);
14898 w
->window_end_valid
= Qnil
;
14900 /* Update hint: don't try scrolling again in update_window. */
14901 w
->desired_matrix
->no_scrolling_p
= 1;
14904 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14908 else if (CHARPOS (new_start
) > CHARPOS (start
))
14910 struct glyph_row
*pt_row
, *row
;
14911 struct glyph_row
*first_reusable_row
;
14912 struct glyph_row
*first_row_to_display
;
14914 int yb
= window_text_bottom_y (w
);
14916 /* Find the row starting at new_start, if there is one. Don't
14917 reuse a partially visible line at the end. */
14918 first_reusable_row
= start_row
;
14919 while (first_reusable_row
->enabled_p
14920 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14921 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14922 < CHARPOS (new_start
)))
14923 ++first_reusable_row
;
14925 /* Give up if there is no row to reuse. */
14926 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14927 || !first_reusable_row
->enabled_p
14928 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14929 != CHARPOS (new_start
)))
14932 /* We can reuse fully visible rows beginning with
14933 first_reusable_row to the end of the window. Set
14934 first_row_to_display to the first row that cannot be reused.
14935 Set pt_row to the row containing point, if there is any. */
14937 for (first_row_to_display
= first_reusable_row
;
14938 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14939 ++first_row_to_display
)
14941 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14942 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14943 pt_row
= first_row_to_display
;
14946 /* Start displaying at the start of first_row_to_display. */
14947 xassert (first_row_to_display
->y
< yb
);
14948 init_to_row_start (&it
, w
, first_row_to_display
);
14950 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14952 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14954 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14955 + WINDOW_HEADER_LINE_HEIGHT (w
));
14957 /* Display lines beginning with first_row_to_display in the
14958 desired matrix. Set last_text_row to the last row displayed
14959 that displays text. */
14960 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14961 if (pt_row
== NULL
)
14962 w
->cursor
.vpos
= -1;
14963 last_text_row
= NULL
;
14964 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14965 if (display_line (&it
))
14966 last_text_row
= it
.glyph_row
- 1;
14968 /* If point is in a reused row, adjust y and vpos of the cursor
14972 w
->cursor
.vpos
-= nrows_scrolled
;
14973 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14976 /* Give up if point isn't in a row displayed or reused. (This
14977 also handles the case where w->cursor.vpos < nrows_scrolled
14978 after the calls to display_line, which can happen with scroll
14979 margins. See bug#1295.) */
14980 if (w
->cursor
.vpos
< 0)
14982 clear_glyph_matrix (w
->desired_matrix
);
14986 /* Scroll the display. */
14987 run
.current_y
= first_reusable_row
->y
;
14988 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14989 run
.height
= it
.last_visible_y
- run
.current_y
;
14990 dy
= run
.current_y
- run
.desired_y
;
14995 FRAME_RIF (f
)->update_window_begin_hook (w
);
14996 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14997 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14998 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15002 /* Adjust Y positions of reused rows. */
15003 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15004 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15005 max_y
= it
.last_visible_y
;
15006 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15009 row
->visible_height
= row
->height
;
15010 if (row
->y
< min_y
)
15011 row
->visible_height
-= min_y
- row
->y
;
15012 if (row
->y
+ row
->height
> max_y
)
15013 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15014 row
->redraw_fringe_bitmaps_p
= 1;
15017 /* Scroll the current matrix. */
15018 xassert (nrows_scrolled
> 0);
15019 rotate_matrix (w
->current_matrix
,
15021 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15024 /* Disable rows not reused. */
15025 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15026 row
->enabled_p
= 0;
15028 /* Point may have moved to a different line, so we cannot assume that
15029 the previous cursor position is valid; locate the correct row. */
15032 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15033 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15037 w
->cursor
.y
= row
->y
;
15039 if (row
< bottom_row
)
15041 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15042 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15043 struct glyph
*orig_glyph
= glyph
;
15044 struct cursor_pos orig_cursor
= w
->cursor
;
15047 && (!BUFFERP (glyph
->object
)
15048 || glyph
->charpos
!= PT
);
15052 w
->cursor
.x
+= glyph
->pixel_width
;
15054 /* With bidi reordering, charpos changes non-linearly
15055 with hpos, so the right glyph could be to the
15057 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15058 && (!BUFFERP (glyph
->object
) || glyph
->charpos
!= PT
))
15060 struct glyph
*start_glyph
= row
->glyphs
[TEXT_AREA
];
15062 glyph
= orig_glyph
- 1;
15063 orig_cursor
.hpos
--;
15064 orig_cursor
.x
-= glyph
->pixel_width
;
15065 for (; glyph
>= start_glyph
15066 && (!BUFFERP (glyph
->object
)
15067 || glyph
->charpos
!= PT
);
15071 w
->cursor
.x
-= glyph
->pixel_width
;
15073 if (BUFFERP (glyph
->object
) && glyph
->charpos
== PT
)
15074 w
->cursor
= orig_cursor
;
15079 /* Adjust window end. A null value of last_text_row means that
15080 the window end is in reused rows which in turn means that
15081 only its vpos can have changed. */
15084 w
->window_end_bytepos
15085 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15087 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15089 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15094 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15097 w
->window_end_valid
= Qnil
;
15098 w
->desired_matrix
->no_scrolling_p
= 1;
15101 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15111 /************************************************************************
15112 Window redisplay reusing current matrix when buffer has changed
15113 ************************************************************************/
15115 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
15116 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
15118 static struct glyph_row
*
15119 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
15120 struct glyph_row
*));
15123 /* Return the last row in MATRIX displaying text. If row START is
15124 non-null, start searching with that row. IT gives the dimensions
15125 of the display. Value is null if matrix is empty; otherwise it is
15126 a pointer to the row found. */
15128 static struct glyph_row
*
15129 find_last_row_displaying_text (matrix
, it
, start
)
15130 struct glyph_matrix
*matrix
;
15132 struct glyph_row
*start
;
15134 struct glyph_row
*row
, *row_found
;
15136 /* Set row_found to the last row in IT->w's current matrix
15137 displaying text. The loop looks funny but think of partially
15140 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15141 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15143 xassert (row
->enabled_p
);
15145 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15154 /* Return the last row in the current matrix of W that is not affected
15155 by changes at the start of current_buffer that occurred since W's
15156 current matrix was built. Value is null if no such row exists.
15158 BEG_UNCHANGED us the number of characters unchanged at the start of
15159 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15160 first changed character in current_buffer. Characters at positions <
15161 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15162 when the current matrix was built. */
15164 static struct glyph_row
*
15165 find_last_unchanged_at_beg_row (w
)
15168 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15169 struct glyph_row
*row
;
15170 struct glyph_row
*row_found
= NULL
;
15171 int yb
= window_text_bottom_y (w
);
15173 /* Find the last row displaying unchanged text. */
15174 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15175 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15176 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15179 if (/* If row ends before first_changed_pos, it is unchanged,
15180 except in some case. */
15181 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15182 /* When row ends in ZV and we write at ZV it is not
15184 && !row
->ends_at_zv_p
15185 /* When first_changed_pos is the end of a continued line,
15186 row is not unchanged because it may be no longer
15188 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15189 && (row
->continued_p
15190 || row
->exact_window_width_line_p
)))
15193 /* Stop if last visible row. */
15194 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15202 /* Find the first glyph row in the current matrix of W that is not
15203 affected by changes at the end of current_buffer since the
15204 time W's current matrix was built.
15206 Return in *DELTA the number of chars by which buffer positions in
15207 unchanged text at the end of current_buffer must be adjusted.
15209 Return in *DELTA_BYTES the corresponding number of bytes.
15211 Value is null if no such row exists, i.e. all rows are affected by
15214 static struct glyph_row
*
15215 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
15217 int *delta
, *delta_bytes
;
15219 struct glyph_row
*row
;
15220 struct glyph_row
*row_found
= NULL
;
15222 *delta
= *delta_bytes
= 0;
15224 /* Display must not have been paused, otherwise the current matrix
15225 is not up to date. */
15226 eassert (!NILP (w
->window_end_valid
));
15228 /* A value of window_end_pos >= END_UNCHANGED means that the window
15229 end is in the range of changed text. If so, there is no
15230 unchanged row at the end of W's current matrix. */
15231 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15234 /* Set row to the last row in W's current matrix displaying text. */
15235 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15237 /* If matrix is entirely empty, no unchanged row exists. */
15238 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15240 /* The value of row is the last glyph row in the matrix having a
15241 meaningful buffer position in it. The end position of row
15242 corresponds to window_end_pos. This allows us to translate
15243 buffer positions in the current matrix to current buffer
15244 positions for characters not in changed text. */
15245 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15246 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15247 int last_unchanged_pos
, last_unchanged_pos_old
;
15248 struct glyph_row
*first_text_row
15249 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15251 *delta
= Z
- Z_old
;
15252 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15254 /* Set last_unchanged_pos to the buffer position of the last
15255 character in the buffer that has not been changed. Z is the
15256 index + 1 of the last character in current_buffer, i.e. by
15257 subtracting END_UNCHANGED we get the index of the last
15258 unchanged character, and we have to add BEG to get its buffer
15260 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15261 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15263 /* Search backward from ROW for a row displaying a line that
15264 starts at a minimum position >= last_unchanged_pos_old. */
15265 for (; row
> first_text_row
; --row
)
15267 /* This used to abort, but it can happen.
15268 It is ok to just stop the search instead here. KFS. */
15269 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15272 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15277 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15283 /* Make sure that glyph rows in the current matrix of window W
15284 reference the same glyph memory as corresponding rows in the
15285 frame's frame matrix. This function is called after scrolling W's
15286 current matrix on a terminal frame in try_window_id and
15287 try_window_reusing_current_matrix. */
15290 sync_frame_with_window_matrix_rows (w
)
15293 struct frame
*f
= XFRAME (w
->frame
);
15294 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15296 /* Preconditions: W must be a leaf window and full-width. Its frame
15297 must have a frame matrix. */
15298 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15299 xassert (WINDOW_FULL_WIDTH_P (w
));
15300 xassert (!FRAME_WINDOW_P (f
));
15302 /* If W is a full-width window, glyph pointers in W's current matrix
15303 have, by definition, to be the same as glyph pointers in the
15304 corresponding frame matrix. Note that frame matrices have no
15305 marginal areas (see build_frame_matrix). */
15306 window_row
= w
->current_matrix
->rows
;
15307 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15308 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15309 while (window_row
< window_row_end
)
15311 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15312 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15314 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15315 frame_row
->glyphs
[TEXT_AREA
] = start
;
15316 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15317 frame_row
->glyphs
[LAST_AREA
] = end
;
15319 /* Disable frame rows whose corresponding window rows have
15320 been disabled in try_window_id. */
15321 if (!window_row
->enabled_p
)
15322 frame_row
->enabled_p
= 0;
15324 ++window_row
, ++frame_row
;
15329 /* Find the glyph row in window W containing CHARPOS. Consider all
15330 rows between START and END (not inclusive). END null means search
15331 all rows to the end of the display area of W. Value is the row
15332 containing CHARPOS or null. */
15335 row_containing_pos (w
, charpos
, start
, end
, dy
)
15338 struct glyph_row
*start
, *end
;
15341 struct glyph_row
*row
= start
;
15342 struct glyph_row
*best_row
= NULL
;
15343 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15346 /* If we happen to start on a header-line, skip that. */
15347 if (row
->mode_line_p
)
15350 if ((end
&& row
>= end
) || !row
->enabled_p
)
15353 last_y
= window_text_bottom_y (w
) - dy
;
15357 /* Give up if we have gone too far. */
15358 if (end
&& row
>= end
)
15360 /* This formerly returned if they were equal.
15361 I think that both quantities are of a "last plus one" type;
15362 if so, when they are equal, the row is within the screen. -- rms. */
15363 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15366 /* If it is in this row, return this row. */
15367 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15368 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15369 /* The end position of a row equals the start
15370 position of the next row. If CHARPOS is there, we
15371 would rather display it in the next line, except
15372 when this line ends in ZV. */
15373 && !row
->ends_at_zv_p
15374 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15375 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15379 if (NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
15381 /* In bidi-reordered rows, there could be several rows
15382 occluding point. We need to find the one which fits
15383 CHARPOS the best. */
15384 for (g
= row
->glyphs
[TEXT_AREA
];
15385 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15388 if (!STRINGP (g
->object
))
15390 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15392 mindif
= eabs (g
->charpos
- charpos
);
15405 /* Try to redisplay window W by reusing its existing display. W's
15406 current matrix must be up to date when this function is called,
15407 i.e. window_end_valid must not be nil.
15411 1 if display has been updated
15412 0 if otherwise unsuccessful
15413 -1 if redisplay with same window start is known not to succeed
15415 The following steps are performed:
15417 1. Find the last row in the current matrix of W that is not
15418 affected by changes at the start of current_buffer. If no such row
15421 2. Find the first row in W's current matrix that is not affected by
15422 changes at the end of current_buffer. Maybe there is no such row.
15424 3. Display lines beginning with the row + 1 found in step 1 to the
15425 row found in step 2 or, if step 2 didn't find a row, to the end of
15428 4. If cursor is not known to appear on the window, give up.
15430 5. If display stopped at the row found in step 2, scroll the
15431 display and current matrix as needed.
15433 6. Maybe display some lines at the end of W, if we must. This can
15434 happen under various circumstances, like a partially visible line
15435 becoming fully visible, or because newly displayed lines are displayed
15436 in smaller font sizes.
15438 7. Update W's window end information. */
15444 struct frame
*f
= XFRAME (w
->frame
);
15445 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15446 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15447 struct glyph_row
*last_unchanged_at_beg_row
;
15448 struct glyph_row
*first_unchanged_at_end_row
;
15449 struct glyph_row
*row
;
15450 struct glyph_row
*bottom_row
;
15453 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
15454 struct text_pos start_pos
;
15456 int first_unchanged_at_end_vpos
= 0;
15457 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15458 struct text_pos start
;
15459 int first_changed_charpos
, last_changed_charpos
;
15462 if (inhibit_try_window_id
)
15466 /* This is handy for debugging. */
15468 #define GIVE_UP(X) \
15470 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15474 #define GIVE_UP(X) return 0
15477 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15479 /* Don't use this for mini-windows because these can show
15480 messages and mini-buffers, and we don't handle that here. */
15481 if (MINI_WINDOW_P (w
))
15484 /* This flag is used to prevent redisplay optimizations. */
15485 if (windows_or_buffers_changed
|| cursor_type_changed
)
15488 /* Verify that narrowing has not changed.
15489 Also verify that we were not told to prevent redisplay optimizations.
15490 It would be nice to further
15491 reduce the number of cases where this prevents try_window_id. */
15492 if (current_buffer
->clip_changed
15493 || current_buffer
->prevent_redisplay_optimizations_p
)
15496 /* Window must either use window-based redisplay or be full width. */
15497 if (!FRAME_WINDOW_P (f
)
15498 && (!FRAME_LINE_INS_DEL_OK (f
)
15499 || !WINDOW_FULL_WIDTH_P (w
)))
15502 /* Give up if point is known NOT to appear in W. */
15503 if (PT
< CHARPOS (start
))
15506 /* Another way to prevent redisplay optimizations. */
15507 if (XFASTINT (w
->last_modified
) == 0)
15510 /* Verify that window is not hscrolled. */
15511 if (XFASTINT (w
->hscroll
) != 0)
15514 /* Verify that display wasn't paused. */
15515 if (NILP (w
->window_end_valid
))
15518 /* Can't use this if highlighting a region because a cursor movement
15519 will do more than just set the cursor. */
15520 if (!NILP (Vtransient_mark_mode
)
15521 && !NILP (current_buffer
->mark_active
))
15524 /* Likewise if highlighting trailing whitespace. */
15525 if (!NILP (Vshow_trailing_whitespace
))
15528 /* Likewise if showing a region. */
15529 if (!NILP (w
->region_showing
))
15532 /* Can't use this if overlay arrow position and/or string have
15534 if (overlay_arrows_changed_p ())
15537 /* When word-wrap is on, adding a space to the first word of a
15538 wrapped line can change the wrap position, altering the line
15539 above it. It might be worthwhile to handle this more
15540 intelligently, but for now just redisplay from scratch. */
15541 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15544 /* Under bidi reordering, adding or deleting a character in the
15545 beginning of a paragraph, before the first strong directional
15546 character, can change the base direction of the paragraph (unless
15547 the buffer specifies a fixed paragraph direction), which will
15548 require to redisplay the whole paragraph. It might be worthwhile
15549 to find the paragraph limits and widen the range of redisplayed
15550 lines to that, but for now just give up this optimization and
15551 redisplay from scratch. */
15552 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15553 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15556 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15557 only if buffer has really changed. The reason is that the gap is
15558 initially at Z for freshly visited files. The code below would
15559 set end_unchanged to 0 in that case. */
15560 if (MODIFF
> SAVE_MODIFF
15561 /* This seems to happen sometimes after saving a buffer. */
15562 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15564 if (GPT
- BEG
< BEG_UNCHANGED
)
15565 BEG_UNCHANGED
= GPT
- BEG
;
15566 if (Z
- GPT
< END_UNCHANGED
)
15567 END_UNCHANGED
= Z
- GPT
;
15570 /* The position of the first and last character that has been changed. */
15571 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15572 last_changed_charpos
= Z
- END_UNCHANGED
;
15574 /* If window starts after a line end, and the last change is in
15575 front of that newline, then changes don't affect the display.
15576 This case happens with stealth-fontification. Note that although
15577 the display is unchanged, glyph positions in the matrix have to
15578 be adjusted, of course. */
15579 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15580 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15581 && ((last_changed_charpos
< CHARPOS (start
)
15582 && CHARPOS (start
) == BEGV
)
15583 || (last_changed_charpos
< CHARPOS (start
) - 1
15584 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15586 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15587 struct glyph_row
*r0
;
15589 /* Compute how many chars/bytes have been added to or removed
15590 from the buffer. */
15591 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15592 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15594 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15596 /* Give up if PT is not in the window. Note that it already has
15597 been checked at the start of try_window_id that PT is not in
15598 front of the window start. */
15599 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15602 /* If window start is unchanged, we can reuse the whole matrix
15603 as is, after adjusting glyph positions. No need to compute
15604 the window end again, since its offset from Z hasn't changed. */
15605 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15606 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15607 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15608 /* PT must not be in a partially visible line. */
15609 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15610 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15612 /* Adjust positions in the glyph matrix. */
15613 if (delta
|| delta_bytes
)
15615 struct glyph_row
*r1
15616 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15617 increment_matrix_positions (w
->current_matrix
,
15618 MATRIX_ROW_VPOS (r0
, current_matrix
),
15619 MATRIX_ROW_VPOS (r1
, current_matrix
),
15620 delta
, delta_bytes
);
15623 /* Set the cursor. */
15624 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15626 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15633 /* Handle the case that changes are all below what is displayed in
15634 the window, and that PT is in the window. This shortcut cannot
15635 be taken if ZV is visible in the window, and text has been added
15636 there that is visible in the window. */
15637 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15638 /* ZV is not visible in the window, or there are no
15639 changes at ZV, actually. */
15640 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15641 || first_changed_charpos
== last_changed_charpos
))
15643 struct glyph_row
*r0
;
15645 /* Give up if PT is not in the window. Note that it already has
15646 been checked at the start of try_window_id that PT is not in
15647 front of the window start. */
15648 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15651 /* If window start is unchanged, we can reuse the whole matrix
15652 as is, without changing glyph positions since no text has
15653 been added/removed in front of the window end. */
15654 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15655 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15656 /* PT must not be in a partially visible line. */
15657 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15658 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15660 /* We have to compute the window end anew since text
15661 can have been added/removed after it. */
15663 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15664 w
->window_end_bytepos
15665 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15667 /* Set the cursor. */
15668 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15670 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15677 /* Give up if window start is in the changed area.
15679 The condition used to read
15681 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15683 but why that was tested escapes me at the moment. */
15684 if (CHARPOS (start
) >= first_changed_charpos
15685 && CHARPOS (start
) <= last_changed_charpos
)
15688 /* Check that window start agrees with the start of the first glyph
15689 row in its current matrix. Check this after we know the window
15690 start is not in changed text, otherwise positions would not be
15692 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15693 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15696 /* Give up if the window ends in strings. Overlay strings
15697 at the end are difficult to handle, so don't try. */
15698 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15699 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15702 /* Compute the position at which we have to start displaying new
15703 lines. Some of the lines at the top of the window might be
15704 reusable because they are not displaying changed text. Find the
15705 last row in W's current matrix not affected by changes at the
15706 start of current_buffer. Value is null if changes start in the
15707 first line of window. */
15708 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15709 if (last_unchanged_at_beg_row
)
15711 /* Avoid starting to display in the moddle of a character, a TAB
15712 for instance. This is easier than to set up the iterator
15713 exactly, and it's not a frequent case, so the additional
15714 effort wouldn't really pay off. */
15715 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15716 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15717 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15718 --last_unchanged_at_beg_row
;
15720 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15723 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15725 start_pos
= it
.current
.pos
;
15727 /* Start displaying new lines in the desired matrix at the same
15728 vpos we would use in the current matrix, i.e. below
15729 last_unchanged_at_beg_row. */
15730 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15732 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15733 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15735 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15739 /* There are no reusable lines at the start of the window.
15740 Start displaying in the first text line. */
15741 start_display (&it
, w
, start
);
15742 it
.vpos
= it
.first_vpos
;
15743 start_pos
= it
.current
.pos
;
15746 /* Find the first row that is not affected by changes at the end of
15747 the buffer. Value will be null if there is no unchanged row, in
15748 which case we must redisplay to the end of the window. delta
15749 will be set to the value by which buffer positions beginning with
15750 first_unchanged_at_end_row have to be adjusted due to text
15752 first_unchanged_at_end_row
15753 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15754 IF_DEBUG (debug_delta
= delta
);
15755 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15757 /* Set stop_pos to the buffer position up to which we will have to
15758 display new lines. If first_unchanged_at_end_row != NULL, this
15759 is the buffer position of the start of the line displayed in that
15760 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15761 that we don't stop at a buffer position. */
15763 if (first_unchanged_at_end_row
)
15765 xassert (last_unchanged_at_beg_row
== NULL
15766 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15768 /* If this is a continuation line, move forward to the next one
15769 that isn't. Changes in lines above affect this line.
15770 Caution: this may move first_unchanged_at_end_row to a row
15771 not displaying text. */
15772 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15773 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15774 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15775 < it
.last_visible_y
))
15776 ++first_unchanged_at_end_row
;
15778 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15779 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15780 >= it
.last_visible_y
))
15781 first_unchanged_at_end_row
= NULL
;
15784 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15786 first_unchanged_at_end_vpos
15787 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15788 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15791 else if (last_unchanged_at_beg_row
== NULL
)
15797 /* Either there is no unchanged row at the end, or the one we have
15798 now displays text. This is a necessary condition for the window
15799 end pos calculation at the end of this function. */
15800 xassert (first_unchanged_at_end_row
== NULL
15801 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15803 debug_last_unchanged_at_beg_vpos
15804 = (last_unchanged_at_beg_row
15805 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15807 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15809 #endif /* GLYPH_DEBUG != 0 */
15812 /* Display new lines. Set last_text_row to the last new line
15813 displayed which has text on it, i.e. might end up as being the
15814 line where the window_end_vpos is. */
15815 w
->cursor
.vpos
= -1;
15816 last_text_row
= NULL
;
15817 overlay_arrow_seen
= 0;
15818 while (it
.current_y
< it
.last_visible_y
15819 && !fonts_changed_p
15820 && (first_unchanged_at_end_row
== NULL
15821 || IT_CHARPOS (it
) < stop_pos
))
15823 if (display_line (&it
))
15824 last_text_row
= it
.glyph_row
- 1;
15827 if (fonts_changed_p
)
15831 /* Compute differences in buffer positions, y-positions etc. for
15832 lines reused at the bottom of the window. Compute what we can
15834 if (first_unchanged_at_end_row
15835 /* No lines reused because we displayed everything up to the
15836 bottom of the window. */
15837 && it
.current_y
< it
.last_visible_y
)
15840 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15842 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15843 run
.current_y
= first_unchanged_at_end_row
->y
;
15844 run
.desired_y
= run
.current_y
+ dy
;
15845 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15849 delta
= delta_bytes
= dvpos
= dy
15850 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15851 first_unchanged_at_end_row
= NULL
;
15853 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15856 /* Find the cursor if not already found. We have to decide whether
15857 PT will appear on this window (it sometimes doesn't, but this is
15858 not a very frequent case.) This decision has to be made before
15859 the current matrix is altered. A value of cursor.vpos < 0 means
15860 that PT is either in one of the lines beginning at
15861 first_unchanged_at_end_row or below the window. Don't care for
15862 lines that might be displayed later at the window end; as
15863 mentioned, this is not a frequent case. */
15864 if (w
->cursor
.vpos
< 0)
15866 /* Cursor in unchanged rows at the top? */
15867 if (PT
< CHARPOS (start_pos
)
15868 && last_unchanged_at_beg_row
)
15870 row
= row_containing_pos (w
, PT
,
15871 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15872 last_unchanged_at_beg_row
+ 1, 0);
15874 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15877 /* Start from first_unchanged_at_end_row looking for PT. */
15878 else if (first_unchanged_at_end_row
)
15880 row
= row_containing_pos (w
, PT
- delta
,
15881 first_unchanged_at_end_row
, NULL
, 0);
15883 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15884 delta_bytes
, dy
, dvpos
);
15887 /* Give up if cursor was not found. */
15888 if (w
->cursor
.vpos
< 0)
15890 clear_glyph_matrix (w
->desired_matrix
);
15895 /* Don't let the cursor end in the scroll margins. */
15897 int this_scroll_margin
, cursor_height
;
15899 this_scroll_margin
= max (0, scroll_margin
);
15900 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15901 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15902 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15904 if ((w
->cursor
.y
< this_scroll_margin
15905 && CHARPOS (start
) > BEGV
)
15906 /* Old redisplay didn't take scroll margin into account at the bottom,
15907 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15908 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15909 ? cursor_height
+ this_scroll_margin
15910 : 1)) > it
.last_visible_y
)
15912 w
->cursor
.vpos
= -1;
15913 clear_glyph_matrix (w
->desired_matrix
);
15918 /* Scroll the display. Do it before changing the current matrix so
15919 that xterm.c doesn't get confused about where the cursor glyph is
15921 if (dy
&& run
.height
)
15925 if (FRAME_WINDOW_P (f
))
15927 FRAME_RIF (f
)->update_window_begin_hook (w
);
15928 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15929 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15930 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15934 /* Terminal frame. In this case, dvpos gives the number of
15935 lines to scroll by; dvpos < 0 means scroll up. */
15936 int first_unchanged_at_end_vpos
15937 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15938 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15939 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15940 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15941 + window_internal_height (w
));
15943 /* Perform the operation on the screen. */
15946 /* Scroll last_unchanged_at_beg_row to the end of the
15947 window down dvpos lines. */
15948 set_terminal_window (f
, end
);
15950 /* On dumb terminals delete dvpos lines at the end
15951 before inserting dvpos empty lines. */
15952 if (!FRAME_SCROLL_REGION_OK (f
))
15953 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15955 /* Insert dvpos empty lines in front of
15956 last_unchanged_at_beg_row. */
15957 ins_del_lines (f
, from
, dvpos
);
15959 else if (dvpos
< 0)
15961 /* Scroll up last_unchanged_at_beg_vpos to the end of
15962 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15963 set_terminal_window (f
, end
);
15965 /* Delete dvpos lines in front of
15966 last_unchanged_at_beg_vpos. ins_del_lines will set
15967 the cursor to the given vpos and emit |dvpos| delete
15969 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15971 /* On a dumb terminal insert dvpos empty lines at the
15973 if (!FRAME_SCROLL_REGION_OK (f
))
15974 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15977 set_terminal_window (f
, 0);
15983 /* Shift reused rows of the current matrix to the right position.
15984 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15986 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15987 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15990 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15991 bottom_vpos
, dvpos
);
15992 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15995 else if (dvpos
> 0)
15997 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15998 bottom_vpos
, dvpos
);
15999 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16000 first_unchanged_at_end_vpos
+ dvpos
, 0);
16003 /* For frame-based redisplay, make sure that current frame and window
16004 matrix are in sync with respect to glyph memory. */
16005 if (!FRAME_WINDOW_P (f
))
16006 sync_frame_with_window_matrix_rows (w
);
16008 /* Adjust buffer positions in reused rows. */
16009 if (delta
|| delta_bytes
)
16010 increment_matrix_positions (current_matrix
,
16011 first_unchanged_at_end_vpos
+ dvpos
,
16012 bottom_vpos
, delta
, delta_bytes
);
16014 /* Adjust Y positions. */
16016 shift_glyph_matrix (w
, current_matrix
,
16017 first_unchanged_at_end_vpos
+ dvpos
,
16020 if (first_unchanged_at_end_row
)
16022 first_unchanged_at_end_row
+= dvpos
;
16023 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16024 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16025 first_unchanged_at_end_row
= NULL
;
16028 /* If scrolling up, there may be some lines to display at the end of
16030 last_text_row_at_end
= NULL
;
16033 /* Scrolling up can leave for example a partially visible line
16034 at the end of the window to be redisplayed. */
16035 /* Set last_row to the glyph row in the current matrix where the
16036 window end line is found. It has been moved up or down in
16037 the matrix by dvpos. */
16038 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16039 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16041 /* If last_row is the window end line, it should display text. */
16042 xassert (last_row
->displays_text_p
);
16044 /* If window end line was partially visible before, begin
16045 displaying at that line. Otherwise begin displaying with the
16046 line following it. */
16047 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16049 init_to_row_start (&it
, w
, last_row
);
16050 it
.vpos
= last_vpos
;
16051 it
.current_y
= last_row
->y
;
16055 init_to_row_end (&it
, w
, last_row
);
16056 it
.vpos
= 1 + last_vpos
;
16057 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16061 /* We may start in a continuation line. If so, we have to
16062 get the right continuation_lines_width and current_x. */
16063 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16064 it
.hpos
= it
.current_x
= 0;
16066 /* Display the rest of the lines at the window end. */
16067 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16068 while (it
.current_y
< it
.last_visible_y
16069 && !fonts_changed_p
)
16071 /* Is it always sure that the display agrees with lines in
16072 the current matrix? I don't think so, so we mark rows
16073 displayed invalid in the current matrix by setting their
16074 enabled_p flag to zero. */
16075 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16076 if (display_line (&it
))
16077 last_text_row_at_end
= it
.glyph_row
- 1;
16081 /* Update window_end_pos and window_end_vpos. */
16082 if (first_unchanged_at_end_row
16083 && !last_text_row_at_end
)
16085 /* Window end line if one of the preserved rows from the current
16086 matrix. Set row to the last row displaying text in current
16087 matrix starting at first_unchanged_at_end_row, after
16089 xassert (first_unchanged_at_end_row
->displays_text_p
);
16090 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16091 first_unchanged_at_end_row
);
16092 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16094 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16095 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16097 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16098 xassert (w
->window_end_bytepos
>= 0);
16099 IF_DEBUG (debug_method_add (w
, "A"));
16101 else if (last_text_row_at_end
)
16104 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16105 w
->window_end_bytepos
16106 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16108 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16109 xassert (w
->window_end_bytepos
>= 0);
16110 IF_DEBUG (debug_method_add (w
, "B"));
16112 else if (last_text_row
)
16114 /* We have displayed either to the end of the window or at the
16115 end of the window, i.e. the last row with text is to be found
16116 in the desired matrix. */
16118 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16119 w
->window_end_bytepos
16120 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16122 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16123 xassert (w
->window_end_bytepos
>= 0);
16125 else if (first_unchanged_at_end_row
== NULL
16126 && last_text_row
== NULL
16127 && last_text_row_at_end
== NULL
)
16129 /* Displayed to end of window, but no line containing text was
16130 displayed. Lines were deleted at the end of the window. */
16131 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16132 int vpos
= XFASTINT (w
->window_end_vpos
);
16133 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16134 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16137 row
== NULL
&& vpos
>= first_vpos
;
16138 --vpos
, --current_row
, --desired_row
)
16140 if (desired_row
->enabled_p
)
16142 if (desired_row
->displays_text_p
)
16145 else if (current_row
->displays_text_p
)
16149 xassert (row
!= NULL
);
16150 w
->window_end_vpos
= make_number (vpos
+ 1);
16151 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16152 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16153 xassert (w
->window_end_bytepos
>= 0);
16154 IF_DEBUG (debug_method_add (w
, "C"));
16159 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16160 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16162 /* Record that display has not been completed. */
16163 w
->window_end_valid
= Qnil
;
16164 w
->desired_matrix
->no_scrolling_p
= 1;
16172 /***********************************************************************
16173 More debugging support
16174 ***********************************************************************/
16178 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
16179 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
16180 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
16183 /* Dump the contents of glyph matrix MATRIX on stderr.
16185 GLYPHS 0 means don't show glyph contents.
16186 GLYPHS 1 means show glyphs in short form
16187 GLYPHS > 1 means show glyphs in long form. */
16190 dump_glyph_matrix (matrix
, glyphs
)
16191 struct glyph_matrix
*matrix
;
16195 for (i
= 0; i
< matrix
->nrows
; ++i
)
16196 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16200 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16201 the glyph row and area where the glyph comes from. */
16204 dump_glyph (row
, glyph
, area
)
16205 struct glyph_row
*row
;
16206 struct glyph
*glyph
;
16209 if (glyph
->type
== CHAR_GLYPH
)
16212 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16213 glyph
- row
->glyphs
[TEXT_AREA
],
16216 (BUFFERP (glyph
->object
)
16218 : (STRINGP (glyph
->object
)
16221 glyph
->pixel_width
,
16223 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16227 glyph
->left_box_line_p
,
16228 glyph
->right_box_line_p
);
16230 else if (glyph
->type
== STRETCH_GLYPH
)
16233 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16234 glyph
- row
->glyphs
[TEXT_AREA
],
16237 (BUFFERP (glyph
->object
)
16239 : (STRINGP (glyph
->object
)
16242 glyph
->pixel_width
,
16246 glyph
->left_box_line_p
,
16247 glyph
->right_box_line_p
);
16249 else if (glyph
->type
== IMAGE_GLYPH
)
16252 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16253 glyph
- row
->glyphs
[TEXT_AREA
],
16256 (BUFFERP (glyph
->object
)
16258 : (STRINGP (glyph
->object
)
16261 glyph
->pixel_width
,
16265 glyph
->left_box_line_p
,
16266 glyph
->right_box_line_p
);
16268 else if (glyph
->type
== COMPOSITE_GLYPH
)
16271 " %5d %4c %6d %c %3d 0x%05x",
16272 glyph
- row
->glyphs
[TEXT_AREA
],
16275 (BUFFERP (glyph
->object
)
16277 : (STRINGP (glyph
->object
)
16280 glyph
->pixel_width
,
16282 if (glyph
->u
.cmp
.automatic
)
16285 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
16286 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16288 glyph
->left_box_line_p
,
16289 glyph
->right_box_line_p
);
16294 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16295 GLYPHS 0 means don't show glyph contents.
16296 GLYPHS 1 means show glyphs in short form
16297 GLYPHS > 1 means show glyphs in long form. */
16300 dump_glyph_row (row
, vpos
, glyphs
)
16301 struct glyph_row
*row
;
16306 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16307 fprintf (stderr
, "======================================================================\n");
16309 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16310 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16312 MATRIX_ROW_START_CHARPOS (row
),
16313 MATRIX_ROW_END_CHARPOS (row
),
16314 row
->used
[TEXT_AREA
],
16315 row
->contains_overlapping_glyphs_p
,
16317 row
->truncated_on_left_p
,
16318 row
->truncated_on_right_p
,
16320 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16321 row
->displays_text_p
,
16324 row
->ends_in_middle_of_char_p
,
16325 row
->starts_in_middle_of_char_p
,
16331 row
->visible_height
,
16334 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16335 row
->end
.overlay_string_index
,
16336 row
->continuation_lines_width
);
16337 fprintf (stderr
, "%9d %5d\n",
16338 CHARPOS (row
->start
.string_pos
),
16339 CHARPOS (row
->end
.string_pos
));
16340 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16341 row
->end
.dpvec_index
);
16348 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16350 struct glyph
*glyph
= row
->glyphs
[area
];
16351 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16353 /* Glyph for a line end in text. */
16354 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16357 if (glyph
< glyph_end
)
16358 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16360 for (; glyph
< glyph_end
; ++glyph
)
16361 dump_glyph (row
, glyph
, area
);
16364 else if (glyphs
== 1)
16368 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16370 char *s
= (char *) alloca (row
->used
[area
] + 1);
16373 for (i
= 0; i
< row
->used
[area
]; ++i
)
16375 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16376 if (glyph
->type
== CHAR_GLYPH
16377 && glyph
->u
.ch
< 0x80
16378 && glyph
->u
.ch
>= ' ')
16379 s
[i
] = glyph
->u
.ch
;
16385 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16391 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16392 Sdump_glyph_matrix
, 0, 1, "p",
16393 doc
: /* Dump the current matrix of the selected window to stderr.
16394 Shows contents of glyph row structures. With non-nil
16395 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16396 glyphs in short form, otherwise show glyphs in long form. */)
16398 Lisp_Object glyphs
;
16400 struct window
*w
= XWINDOW (selected_window
);
16401 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16403 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16404 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16405 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16406 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16407 fprintf (stderr
, "=============================================\n");
16408 dump_glyph_matrix (w
->current_matrix
,
16409 NILP (glyphs
) ? 0 : XINT (glyphs
));
16414 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16415 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16418 struct frame
*f
= XFRAME (selected_frame
);
16419 dump_glyph_matrix (f
->current_matrix
, 1);
16424 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16425 doc
: /* Dump glyph row ROW to stderr.
16426 GLYPH 0 means don't dump glyphs.
16427 GLYPH 1 means dump glyphs in short form.
16428 GLYPH > 1 or omitted means dump glyphs in long form. */)
16430 Lisp_Object row
, glyphs
;
16432 struct glyph_matrix
*matrix
;
16435 CHECK_NUMBER (row
);
16436 matrix
= XWINDOW (selected_window
)->current_matrix
;
16438 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16439 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16441 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16446 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16447 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16448 GLYPH 0 means don't dump glyphs.
16449 GLYPH 1 means dump glyphs in short form.
16450 GLYPH > 1 or omitted means dump glyphs in long form. */)
16452 Lisp_Object row
, glyphs
;
16454 struct frame
*sf
= SELECTED_FRAME ();
16455 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16458 CHECK_NUMBER (row
);
16460 if (vpos
>= 0 && vpos
< m
->nrows
)
16461 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16462 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16467 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16468 doc
: /* Toggle tracing of redisplay.
16469 With ARG, turn tracing on if and only if ARG is positive. */)
16474 trace_redisplay_p
= !trace_redisplay_p
;
16477 arg
= Fprefix_numeric_value (arg
);
16478 trace_redisplay_p
= XINT (arg
) > 0;
16485 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16486 doc
: /* Like `format', but print result to stderr.
16487 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16492 Lisp_Object s
= Fformat (nargs
, args
);
16493 fprintf (stderr
, "%s", SDATA (s
));
16497 #endif /* GLYPH_DEBUG */
16501 /***********************************************************************
16502 Building Desired Matrix Rows
16503 ***********************************************************************/
16505 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16506 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16508 static struct glyph_row
*
16509 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
16511 Lisp_Object overlay_arrow_string
;
16513 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16514 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16515 struct buffer
*old
= current_buffer
;
16516 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16517 int arrow_len
= SCHARS (overlay_arrow_string
);
16518 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16519 const unsigned char *p
;
16522 int n_glyphs_before
;
16524 set_buffer_temp (buffer
);
16525 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16526 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16527 SET_TEXT_POS (it
.position
, 0, 0);
16529 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16531 while (p
< arrow_end
)
16533 Lisp_Object face
, ilisp
;
16535 /* Get the next character. */
16537 it
.c
= string_char_and_length (p
, &it
.len
);
16539 it
.c
= *p
, it
.len
= 1;
16542 /* Get its face. */
16543 ilisp
= make_number (p
- arrow_string
);
16544 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16545 it
.face_id
= compute_char_face (f
, it
.c
, face
);
16547 /* Compute its width, get its glyphs. */
16548 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16549 SET_TEXT_POS (it
.position
, -1, -1);
16550 PRODUCE_GLYPHS (&it
);
16552 /* If this character doesn't fit any more in the line, we have
16553 to remove some glyphs. */
16554 if (it
.current_x
> it
.last_visible_x
)
16556 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16561 set_buffer_temp (old
);
16562 return it
.glyph_row
;
16566 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16567 glyphs are only inserted for terminal frames since we can't really
16568 win with truncation glyphs when partially visible glyphs are
16569 involved. Which glyphs to insert is determined by
16570 produce_special_glyphs. */
16573 insert_left_trunc_glyphs (it
)
16576 struct it truncate_it
;
16577 struct glyph
*from
, *end
, *to
, *toend
;
16579 xassert (!FRAME_WINDOW_P (it
->f
));
16581 /* Get the truncation glyphs. */
16583 truncate_it
.current_x
= 0;
16584 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16585 truncate_it
.glyph_row
= &scratch_glyph_row
;
16586 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16587 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16588 truncate_it
.object
= make_number (0);
16589 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16591 /* Overwrite glyphs from IT with truncation glyphs. */
16592 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16593 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16594 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16595 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16600 /* There may be padding glyphs left over. Overwrite them too. */
16601 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16603 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16609 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16613 /* Compute the pixel height and width of IT->glyph_row.
16615 Most of the time, ascent and height of a display line will be equal
16616 to the max_ascent and max_height values of the display iterator
16617 structure. This is not the case if
16619 1. We hit ZV without displaying anything. In this case, max_ascent
16620 and max_height will be zero.
16622 2. We have some glyphs that don't contribute to the line height.
16623 (The glyph row flag contributes_to_line_height_p is for future
16624 pixmap extensions).
16626 The first case is easily covered by using default values because in
16627 these cases, the line height does not really matter, except that it
16628 must not be zero. */
16631 compute_line_metrics (it
)
16634 struct glyph_row
*row
= it
->glyph_row
;
16637 if (FRAME_WINDOW_P (it
->f
))
16639 int i
, min_y
, max_y
;
16641 /* The line may consist of one space only, that was added to
16642 place the cursor on it. If so, the row's height hasn't been
16644 if (row
->height
== 0)
16646 if (it
->max_ascent
+ it
->max_descent
== 0)
16647 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16648 row
->ascent
= it
->max_ascent
;
16649 row
->height
= it
->max_ascent
+ it
->max_descent
;
16650 row
->phys_ascent
= it
->max_phys_ascent
;
16651 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16652 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16655 /* Compute the width of this line. */
16656 row
->pixel_width
= row
->x
;
16657 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16658 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16660 xassert (row
->pixel_width
>= 0);
16661 xassert (row
->ascent
>= 0 && row
->height
> 0);
16663 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16664 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16666 /* If first line's physical ascent is larger than its logical
16667 ascent, use the physical ascent, and make the row taller.
16668 This makes accented characters fully visible. */
16669 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16670 && row
->phys_ascent
> row
->ascent
)
16672 row
->height
+= row
->phys_ascent
- row
->ascent
;
16673 row
->ascent
= row
->phys_ascent
;
16676 /* Compute how much of the line is visible. */
16677 row
->visible_height
= row
->height
;
16679 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16680 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16682 if (row
->y
< min_y
)
16683 row
->visible_height
-= min_y
- row
->y
;
16684 if (row
->y
+ row
->height
> max_y
)
16685 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16689 row
->pixel_width
= row
->used
[TEXT_AREA
];
16690 if (row
->continued_p
)
16691 row
->pixel_width
-= it
->continuation_pixel_width
;
16692 else if (row
->truncated_on_right_p
)
16693 row
->pixel_width
-= it
->truncation_pixel_width
;
16694 row
->ascent
= row
->phys_ascent
= 0;
16695 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16696 row
->extra_line_spacing
= 0;
16699 /* Compute a hash code for this row. */
16701 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16702 for (i
= 0; i
< row
->used
[area
]; ++i
)
16703 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16704 + row
->glyphs
[area
][i
].u
.val
16705 + row
->glyphs
[area
][i
].face_id
16706 + row
->glyphs
[area
][i
].padding_p
16707 + (row
->glyphs
[area
][i
].type
<< 2));
16709 it
->max_ascent
= it
->max_descent
= 0;
16710 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16714 /* Append one space to the glyph row of iterator IT if doing a
16715 window-based redisplay. The space has the same face as
16716 IT->face_id. Value is non-zero if a space was added.
16718 This function is called to make sure that there is always one glyph
16719 at the end of a glyph row that the cursor can be set on under
16720 window-systems. (If there weren't such a glyph we would not know
16721 how wide and tall a box cursor should be displayed).
16723 At the same time this space let's a nicely handle clearing to the
16724 end of the line if the row ends in italic text. */
16727 append_space_for_newline (it
, default_face_p
)
16729 int default_face_p
;
16731 if (FRAME_WINDOW_P (it
->f
))
16733 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16735 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16736 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16738 /* Save some values that must not be changed.
16739 Must save IT->c and IT->len because otherwise
16740 ITERATOR_AT_END_P wouldn't work anymore after
16741 append_space_for_newline has been called. */
16742 enum display_element_type saved_what
= it
->what
;
16743 int saved_c
= it
->c
, saved_len
= it
->len
;
16744 int saved_x
= it
->current_x
;
16745 int saved_face_id
= it
->face_id
;
16746 struct text_pos saved_pos
;
16747 Lisp_Object saved_object
;
16750 saved_object
= it
->object
;
16751 saved_pos
= it
->position
;
16753 it
->what
= IT_CHARACTER
;
16754 bzero (&it
->position
, sizeof it
->position
);
16755 it
->object
= make_number (0);
16759 if (default_face_p
)
16760 it
->face_id
= DEFAULT_FACE_ID
;
16761 else if (it
->face_before_selective_p
)
16762 it
->face_id
= it
->saved_face_id
;
16763 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16764 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16766 PRODUCE_GLYPHS (it
);
16768 it
->override_ascent
= -1;
16769 it
->constrain_row_ascent_descent_p
= 0;
16770 it
->current_x
= saved_x
;
16771 it
->object
= saved_object
;
16772 it
->position
= saved_pos
;
16773 it
->what
= saved_what
;
16774 it
->face_id
= saved_face_id
;
16775 it
->len
= saved_len
;
16785 /* Extend the face of the last glyph in the text area of IT->glyph_row
16786 to the end of the display line. Called from display_line. If the
16787 glyph row is empty, add a space glyph to it so that we know the
16788 face to draw. Set the glyph row flag fill_line_p. If the glyph
16789 row is R2L, prepend a stretch glyph to cover the empty space to the
16790 left of the leftmost glyph. */
16793 extend_face_to_end_of_line (it
)
16797 struct frame
*f
= it
->f
;
16799 /* If line is already filled, do nothing. */
16800 if (it
->current_x
>= it
->last_visible_x
)
16803 /* Face extension extends the background and box of IT->face_id
16804 to the end of the line. If the background equals the background
16805 of the frame, we don't have to do anything. */
16806 if (it
->face_before_selective_p
)
16807 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
16809 face
= FACE_FROM_ID (f
, it
->face_id
);
16811 if (FRAME_WINDOW_P (f
)
16812 && it
->glyph_row
->displays_text_p
16813 && face
->box
== FACE_NO_BOX
16814 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16816 && !it
->glyph_row
->reversed_p
)
16819 /* Set the glyph row flag indicating that the face of the last glyph
16820 in the text area has to be drawn to the end of the text area. */
16821 it
->glyph_row
->fill_line_p
= 1;
16823 /* If current character of IT is not ASCII, make sure we have the
16824 ASCII face. This will be automatically undone the next time
16825 get_next_display_element returns a multibyte character. Note
16826 that the character will always be single byte in unibyte
16828 if (!ASCII_CHAR_P (it
->c
))
16830 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16833 if (FRAME_WINDOW_P (f
))
16835 /* If the row is empty, add a space with the current face of IT,
16836 so that we know which face to draw. */
16837 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16839 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16840 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16841 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16843 #ifdef HAVE_WINDOW_SYSTEM
16844 if (it
->glyph_row
->reversed_p
)
16846 /* Prepend a stretch glyph to the row, such that the
16847 rightmost glyph will be drawn flushed all the way to the
16848 right margin of the window. The stretch glyph that will
16849 occupy the empty space, if any, to the left of the
16851 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
16852 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16853 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
16855 int row_width
, stretch_ascent
, stretch_width
;
16856 struct text_pos saved_pos
;
16857 int saved_face_id
, saved_avoid_cursor
;
16859 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
16860 row_width
+= g
->pixel_width
;
16861 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
16862 if (stretch_width
> 0)
16865 (((it
->ascent
+ it
->descent
)
16866 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
16867 saved_pos
= it
->position
;
16868 bzero (&it
->position
, sizeof it
->position
);
16869 saved_avoid_cursor
= it
->avoid_cursor_p
;
16870 it
->avoid_cursor_p
= 1;
16871 saved_face_id
= it
->face_id
;
16872 /* The last row should get the default face, to avoid
16873 painting the rest of the window with the region face,
16874 if the region ends at ZV. */
16875 if (it
->glyph_row
->ends_at_zv_p
)
16876 it
->face_id
= DEFAULT_FACE_ID
;
16878 it
->face_id
= face
->id
;
16879 append_stretch_glyph (it
, make_number (0), stretch_width
,
16880 it
->ascent
+ it
->descent
, stretch_ascent
);
16881 it
->position
= saved_pos
;
16882 it
->avoid_cursor_p
= saved_avoid_cursor
;
16883 it
->face_id
= saved_face_id
;
16886 #endif /* HAVE_WINDOW_SYSTEM */
16890 /* Save some values that must not be changed. */
16891 int saved_x
= it
->current_x
;
16892 struct text_pos saved_pos
;
16893 Lisp_Object saved_object
;
16894 enum display_element_type saved_what
= it
->what
;
16895 int saved_face_id
= it
->face_id
;
16897 saved_object
= it
->object
;
16898 saved_pos
= it
->position
;
16900 it
->what
= IT_CHARACTER
;
16901 bzero (&it
->position
, sizeof it
->position
);
16902 it
->object
= make_number (0);
16905 it
->face_id
= face
->id
;
16907 PRODUCE_GLYPHS (it
);
16909 while (it
->current_x
<= it
->last_visible_x
)
16910 PRODUCE_GLYPHS (it
);
16912 /* Don't count these blanks really. It would let us insert a left
16913 truncation glyph below and make us set the cursor on them, maybe. */
16914 it
->current_x
= saved_x
;
16915 it
->object
= saved_object
;
16916 it
->position
= saved_pos
;
16917 it
->what
= saved_what
;
16918 it
->face_id
= saved_face_id
;
16923 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16924 trailing whitespace. */
16927 trailing_whitespace_p (charpos
)
16930 int bytepos
= CHAR_TO_BYTE (charpos
);
16933 while (bytepos
< ZV_BYTE
16934 && (c
= FETCH_CHAR (bytepos
),
16935 c
== ' ' || c
== '\t'))
16938 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16940 if (bytepos
!= PT_BYTE
)
16947 /* Highlight trailing whitespace, if any, in ROW. */
16950 highlight_trailing_whitespace (f
, row
)
16952 struct glyph_row
*row
;
16954 int used
= row
->used
[TEXT_AREA
];
16958 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16959 struct glyph
*glyph
= start
+ used
- 1;
16961 if (row
->reversed_p
)
16963 /* Right-to-left rows need to be processed in the opposite
16964 direction, so swap the edge pointers. */
16966 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
16969 /* Skip over glyphs inserted to display the cursor at the
16970 end of a line, for extending the face of the last glyph
16971 to the end of the line on terminals, and for truncation
16972 and continuation glyphs. */
16973 if (!row
->reversed_p
)
16975 while (glyph
>= start
16976 && glyph
->type
== CHAR_GLYPH
16977 && INTEGERP (glyph
->object
))
16982 while (glyph
<= start
16983 && glyph
->type
== CHAR_GLYPH
16984 && INTEGERP (glyph
->object
))
16988 /* If last glyph is a space or stretch, and it's trailing
16989 whitespace, set the face of all trailing whitespace glyphs in
16990 IT->glyph_row to `trailing-whitespace'. */
16991 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
16992 && BUFFERP (glyph
->object
)
16993 && (glyph
->type
== STRETCH_GLYPH
16994 || (glyph
->type
== CHAR_GLYPH
16995 && glyph
->u
.ch
== ' '))
16996 && trailing_whitespace_p (glyph
->charpos
))
16998 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17002 if (!row
->reversed_p
)
17004 while (glyph
>= start
17005 && BUFFERP (glyph
->object
)
17006 && (glyph
->type
== STRETCH_GLYPH
17007 || (glyph
->type
== CHAR_GLYPH
17008 && glyph
->u
.ch
== ' ')))
17009 (glyph
--)->face_id
= face_id
;
17013 while (glyph
<= start
17014 && BUFFERP (glyph
->object
)
17015 && (glyph
->type
== STRETCH_GLYPH
17016 || (glyph
->type
== CHAR_GLYPH
17017 && glyph
->u
.ch
== ' ')))
17018 (glyph
++)->face_id
= face_id
;
17025 /* Value is non-zero if glyph row ROW in window W should be
17026 used to hold the cursor. */
17029 cursor_row_p (w
, row
)
17031 struct glyph_row
*row
;
17033 int cursor_row_p
= 1;
17035 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
17037 /* Suppose the row ends on a string.
17038 Unless the row is continued, that means it ends on a newline
17039 in the string. If it's anything other than a display string
17040 (e.g. a before-string from an overlay), we don't want the
17041 cursor there. (This heuristic seems to give the optimal
17042 behavior for the various types of multi-line strings.) */
17043 if (CHARPOS (row
->end
.string_pos
) >= 0)
17045 if (row
->continued_p
)
17049 /* Check for `display' property. */
17050 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17051 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17052 struct glyph
*glyph
;
17055 for (glyph
= end
; glyph
>= beg
; --glyph
)
17056 if (STRINGP (glyph
->object
))
17059 = Fget_char_property (make_number (PT
),
17063 && display_prop_string_p (prop
, glyph
->object
));
17068 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17070 /* If the row ends in middle of a real character,
17071 and the line is continued, we want the cursor here.
17072 That's because MATRIX_ROW_END_CHARPOS would equal
17073 PT if PT is before the character. */
17074 if (!row
->ends_in_ellipsis_p
)
17075 cursor_row_p
= row
->continued_p
;
17077 /* If the row ends in an ellipsis, then
17078 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
17079 We want that position to be displayed after the ellipsis. */
17082 /* If the row ends at ZV, display the cursor at the end of that
17083 row instead of at the start of the row below. */
17084 else if (row
->ends_at_zv_p
)
17090 return cursor_row_p
;
17095 /* Push the display property PROP so that it will be rendered at the
17096 current position in IT. Return 1 if PROP was successfully pushed,
17100 push_display_prop (struct it
*it
, Lisp_Object prop
)
17104 if (STRINGP (prop
))
17106 if (SCHARS (prop
) == 0)
17113 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17114 it
->current
.overlay_string_index
= -1;
17115 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17116 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17117 it
->method
= GET_FROM_STRING
;
17118 it
->stop_charpos
= 0;
17120 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17122 it
->method
= GET_FROM_STRETCH
;
17125 #ifdef HAVE_WINDOW_SYSTEM
17126 else if (IMAGEP (prop
))
17128 it
->what
= IT_IMAGE
;
17129 it
->image_id
= lookup_image (it
->f
, prop
);
17130 it
->method
= GET_FROM_IMAGE
;
17132 #endif /* HAVE_WINDOW_SYSTEM */
17135 pop_it (it
); /* bogus display property, give up */
17142 /* Return the character-property PROP at the current position in IT. */
17145 get_it_property (it
, prop
)
17149 Lisp_Object position
;
17151 if (STRINGP (it
->object
))
17152 position
= make_number (IT_STRING_CHARPOS (*it
));
17153 else if (BUFFERP (it
->object
))
17154 position
= make_number (IT_CHARPOS (*it
));
17158 return Fget_char_property (position
, prop
, it
->object
);
17161 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17164 handle_line_prefix (struct it
*it
)
17166 Lisp_Object prefix
;
17167 if (it
->continuation_lines_width
> 0)
17169 prefix
= get_it_property (it
, Qwrap_prefix
);
17171 prefix
= Vwrap_prefix
;
17175 prefix
= get_it_property (it
, Qline_prefix
);
17177 prefix
= Vline_prefix
;
17179 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17181 /* If the prefix is wider than the window, and we try to wrap
17182 it, it would acquire its own wrap prefix, and so on till the
17183 iterator stack overflows. So, don't wrap the prefix. */
17184 it
->line_wrap
= TRUNCATE
;
17185 it
->avoid_cursor_p
= 1;
17191 /* Construct the glyph row IT->glyph_row in the desired matrix of
17192 IT->w from text at the current position of IT. See dispextern.h
17193 for an overview of struct it. Value is non-zero if
17194 IT->glyph_row displays text, as opposed to a line displaying ZV
17201 struct glyph_row
*row
= it
->glyph_row
;
17202 Lisp_Object overlay_arrow_string
;
17204 int may_wrap
= 0, wrap_x
;
17205 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
17206 int wrap_row_phys_ascent
, wrap_row_phys_height
;
17207 int wrap_row_extra_line_spacing
;
17208 struct display_pos row_end
;
17211 /* We always start displaying at hpos zero even if hscrolled. */
17212 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17214 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17215 >= it
->w
->desired_matrix
->nrows
)
17217 it
->w
->nrows_scale_factor
++;
17218 fonts_changed_p
= 1;
17222 /* Is IT->w showing the region? */
17223 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17225 /* Clear the result glyph row and enable it. */
17226 prepare_desired_row (row
);
17228 row
->y
= it
->current_y
;
17229 row
->start
= it
->start
;
17230 row
->continuation_lines_width
= it
->continuation_lines_width
;
17231 row
->displays_text_p
= 1;
17232 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17233 it
->starts_in_middle_of_char_p
= 0;
17235 /* Arrange the overlays nicely for our purposes. Usually, we call
17236 display_line on only one line at a time, in which case this
17237 can't really hurt too much, or we call it on lines which appear
17238 one after another in the buffer, in which case all calls to
17239 recenter_overlay_lists but the first will be pretty cheap. */
17240 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17242 /* Move over display elements that are not visible because we are
17243 hscrolled. This may stop at an x-position < IT->first_visible_x
17244 if the first glyph is partially visible or if we hit a line end. */
17245 if (it
->current_x
< it
->first_visible_x
)
17247 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17248 MOVE_TO_POS
| MOVE_TO_X
);
17252 /* We only do this when not calling `move_it_in_display_line_to'
17253 above, because move_it_in_display_line_to calls
17254 handle_line_prefix itself. */
17255 handle_line_prefix (it
);
17258 /* Get the initial row height. This is either the height of the
17259 text hscrolled, if there is any, or zero. */
17260 row
->ascent
= it
->max_ascent
;
17261 row
->height
= it
->max_ascent
+ it
->max_descent
;
17262 row
->phys_ascent
= it
->max_phys_ascent
;
17263 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17264 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17266 /* Loop generating characters. The loop is left with IT on the next
17267 character to display. */
17270 int n_glyphs_before
, hpos_before
, x_before
;
17272 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17274 /* Retrieve the next thing to display. Value is zero if end of
17276 if (!get_next_display_element (it
))
17278 /* Maybe add a space at the end of this line that is used to
17279 display the cursor there under X. Set the charpos of the
17280 first glyph of blank lines not corresponding to any text
17282 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17283 row
->exact_window_width_line_p
= 1;
17284 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17285 || row
->used
[TEXT_AREA
] == 0)
17287 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17288 row
->displays_text_p
= 0;
17290 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17291 && (!MINI_WINDOW_P (it
->w
)
17292 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17293 row
->indicate_empty_line_p
= 1;
17296 it
->continuation_lines_width
= 0;
17297 row
->ends_at_zv_p
= 1;
17298 /* A row that displays right-to-left text must always have
17299 its last face extended all the way to the end of line,
17300 even if this row ends in ZV. */
17301 if (row
->reversed_p
)
17302 extend_face_to_end_of_line (it
);
17306 /* Now, get the metrics of what we want to display. This also
17307 generates glyphs in `row' (which is IT->glyph_row). */
17308 n_glyphs_before
= row
->used
[TEXT_AREA
];
17311 /* Remember the line height so far in case the next element doesn't
17312 fit on the line. */
17313 if (it
->line_wrap
!= TRUNCATE
)
17315 ascent
= it
->max_ascent
;
17316 descent
= it
->max_descent
;
17317 phys_ascent
= it
->max_phys_ascent
;
17318 phys_descent
= it
->max_phys_descent
;
17320 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17322 if (IT_DISPLAYING_WHITESPACE (it
))
17328 wrap_row_used
= row
->used
[TEXT_AREA
];
17329 wrap_row_ascent
= row
->ascent
;
17330 wrap_row_height
= row
->height
;
17331 wrap_row_phys_ascent
= row
->phys_ascent
;
17332 wrap_row_phys_height
= row
->phys_height
;
17333 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17339 PRODUCE_GLYPHS (it
);
17341 /* If this display element was in marginal areas, continue with
17343 if (it
->area
!= TEXT_AREA
)
17345 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17346 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17347 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17348 row
->phys_height
= max (row
->phys_height
,
17349 it
->max_phys_ascent
+ it
->max_phys_descent
);
17350 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17351 it
->max_extra_line_spacing
);
17352 set_iterator_to_next (it
, 1);
17356 /* Does the display element fit on the line? If we truncate
17357 lines, we should draw past the right edge of the window. If
17358 we don't truncate, we want to stop so that we can display the
17359 continuation glyph before the right margin. If lines are
17360 continued, there are two possible strategies for characters
17361 resulting in more than 1 glyph (e.g. tabs): Display as many
17362 glyphs as possible in this line and leave the rest for the
17363 continuation line, or display the whole element in the next
17364 line. Original redisplay did the former, so we do it also. */
17365 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17366 hpos_before
= it
->hpos
;
17369 if (/* Not a newline. */
17371 /* Glyphs produced fit entirely in the line. */
17372 && it
->current_x
< it
->last_visible_x
)
17374 it
->hpos
+= nglyphs
;
17375 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17376 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17377 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17378 row
->phys_height
= max (row
->phys_height
,
17379 it
->max_phys_ascent
+ it
->max_phys_descent
);
17380 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17381 it
->max_extra_line_spacing
);
17382 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17383 row
->x
= x
- it
->first_visible_x
;
17388 struct glyph
*glyph
;
17390 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17392 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17393 new_x
= x
+ glyph
->pixel_width
;
17395 if (/* Lines are continued. */
17396 it
->line_wrap
!= TRUNCATE
17397 && (/* Glyph doesn't fit on the line. */
17398 new_x
> it
->last_visible_x
17399 /* Or it fits exactly on a window system frame. */
17400 || (new_x
== it
->last_visible_x
17401 && FRAME_WINDOW_P (it
->f
))))
17403 /* End of a continued line. */
17406 || (new_x
== it
->last_visible_x
17407 && FRAME_WINDOW_P (it
->f
)))
17409 /* Current glyph is the only one on the line or
17410 fits exactly on the line. We must continue
17411 the line because we can't draw the cursor
17412 after the glyph. */
17413 row
->continued_p
= 1;
17414 it
->current_x
= new_x
;
17415 it
->continuation_lines_width
+= new_x
;
17417 if (i
== nglyphs
- 1)
17419 /* If line-wrap is on, check if a previous
17420 wrap point was found. */
17421 if (wrap_row_used
> 0
17422 /* Even if there is a previous wrap
17423 point, continue the line here as
17424 usual, if (i) the previous character
17425 was a space or tab AND (ii) the
17426 current character is not. */
17428 || IT_DISPLAYING_WHITESPACE (it
)))
17431 set_iterator_to_next (it
, 1);
17432 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17434 if (!get_next_display_element (it
))
17436 row
->exact_window_width_line_p
= 1;
17437 it
->continuation_lines_width
= 0;
17438 row
->continued_p
= 0;
17439 row
->ends_at_zv_p
= 1;
17441 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17443 row
->continued_p
= 0;
17444 row
->exact_window_width_line_p
= 1;
17449 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17450 && !FRAME_WINDOW_P (it
->f
))
17452 /* A padding glyph that doesn't fit on this line.
17453 This means the whole character doesn't fit
17455 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17457 /* Fill the rest of the row with continuation
17458 glyphs like in 20.x. */
17459 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17460 < row
->glyphs
[1 + TEXT_AREA
])
17461 produce_special_glyphs (it
, IT_CONTINUATION
);
17463 row
->continued_p
= 1;
17464 it
->current_x
= x_before
;
17465 it
->continuation_lines_width
+= x_before
;
17467 /* Restore the height to what it was before the
17468 element not fitting on the line. */
17469 it
->max_ascent
= ascent
;
17470 it
->max_descent
= descent
;
17471 it
->max_phys_ascent
= phys_ascent
;
17472 it
->max_phys_descent
= phys_descent
;
17474 else if (wrap_row_used
> 0)
17478 it
->continuation_lines_width
+= wrap_x
;
17479 row
->used
[TEXT_AREA
] = wrap_row_used
;
17480 row
->ascent
= wrap_row_ascent
;
17481 row
->height
= wrap_row_height
;
17482 row
->phys_ascent
= wrap_row_phys_ascent
;
17483 row
->phys_height
= wrap_row_phys_height
;
17484 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17485 row
->continued_p
= 1;
17486 row
->ends_at_zv_p
= 0;
17487 row
->exact_window_width_line_p
= 0;
17488 it
->continuation_lines_width
+= x
;
17490 /* Make sure that a non-default face is extended
17491 up to the right margin of the window. */
17492 extend_face_to_end_of_line (it
);
17494 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17496 /* A TAB that extends past the right edge of the
17497 window. This produces a single glyph on
17498 window system frames. We leave the glyph in
17499 this row and let it fill the row, but don't
17500 consume the TAB. */
17501 it
->continuation_lines_width
+= it
->last_visible_x
;
17502 row
->ends_in_middle_of_char_p
= 1;
17503 row
->continued_p
= 1;
17504 glyph
->pixel_width
= it
->last_visible_x
- x
;
17505 it
->starts_in_middle_of_char_p
= 1;
17509 /* Something other than a TAB that draws past
17510 the right edge of the window. Restore
17511 positions to values before the element. */
17512 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17514 /* Display continuation glyphs. */
17515 if (!FRAME_WINDOW_P (it
->f
))
17516 produce_special_glyphs (it
, IT_CONTINUATION
);
17517 row
->continued_p
= 1;
17519 it
->current_x
= x_before
;
17520 it
->continuation_lines_width
+= x
;
17521 extend_face_to_end_of_line (it
);
17523 if (nglyphs
> 1 && i
> 0)
17525 row
->ends_in_middle_of_char_p
= 1;
17526 it
->starts_in_middle_of_char_p
= 1;
17529 /* Restore the height to what it was before the
17530 element not fitting on the line. */
17531 it
->max_ascent
= ascent
;
17532 it
->max_descent
= descent
;
17533 it
->max_phys_ascent
= phys_ascent
;
17534 it
->max_phys_descent
= phys_descent
;
17539 else if (new_x
> it
->first_visible_x
)
17541 /* Increment number of glyphs actually displayed. */
17544 if (x
< it
->first_visible_x
)
17545 /* Glyph is partially visible, i.e. row starts at
17546 negative X position. */
17547 row
->x
= x
- it
->first_visible_x
;
17551 /* Glyph is completely off the left margin of the
17552 window. This should not happen because of the
17553 move_it_in_display_line at the start of this
17554 function, unless the text display area of the
17555 window is empty. */
17556 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17560 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17561 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17562 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17563 row
->phys_height
= max (row
->phys_height
,
17564 it
->max_phys_ascent
+ it
->max_phys_descent
);
17565 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17566 it
->max_extra_line_spacing
);
17568 /* End of this display line if row is continued. */
17569 if (row
->continued_p
|| row
->ends_at_zv_p
)
17574 /* Is this a line end? If yes, we're also done, after making
17575 sure that a non-default face is extended up to the right
17576 margin of the window. */
17577 if (ITERATOR_AT_END_OF_LINE_P (it
))
17579 int used_before
= row
->used
[TEXT_AREA
];
17581 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17583 /* Add a space at the end of the line that is used to
17584 display the cursor there. */
17585 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17586 append_space_for_newline (it
, 0);
17588 /* Extend the face to the end of the line. */
17589 extend_face_to_end_of_line (it
);
17591 /* Make sure we have the position. */
17592 if (used_before
== 0)
17593 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17595 /* Consume the line end. This skips over invisible lines. */
17596 set_iterator_to_next (it
, 1);
17597 it
->continuation_lines_width
= 0;
17601 /* Proceed with next display element. Note that this skips
17602 over lines invisible because of selective display. */
17603 set_iterator_to_next (it
, 1);
17605 /* If we truncate lines, we are done when the last displayed
17606 glyphs reach past the right margin of the window. */
17607 if (it
->line_wrap
== TRUNCATE
17608 && (FRAME_WINDOW_P (it
->f
)
17609 ? (it
->current_x
>= it
->last_visible_x
)
17610 : (it
->current_x
> it
->last_visible_x
)))
17612 /* Maybe add truncation glyphs. */
17613 if (!FRAME_WINDOW_P (it
->f
))
17617 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17618 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17621 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17623 row
->used
[TEXT_AREA
] = i
;
17624 produce_special_glyphs (it
, IT_TRUNCATION
);
17627 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17629 /* Don't truncate if we can overflow newline into fringe. */
17630 if (!get_next_display_element (it
))
17632 it
->continuation_lines_width
= 0;
17633 row
->ends_at_zv_p
= 1;
17634 row
->exact_window_width_line_p
= 1;
17637 if (ITERATOR_AT_END_OF_LINE_P (it
))
17639 row
->exact_window_width_line_p
= 1;
17640 goto at_end_of_line
;
17644 row
->truncated_on_right_p
= 1;
17645 it
->continuation_lines_width
= 0;
17646 reseat_at_next_visible_line_start (it
, 0);
17647 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17648 it
->hpos
= hpos_before
;
17649 it
->current_x
= x_before
;
17654 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17655 at the left window margin. */
17656 if (it
->first_visible_x
17657 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
17659 if (!FRAME_WINDOW_P (it
->f
))
17660 insert_left_trunc_glyphs (it
);
17661 row
->truncated_on_left_p
= 1;
17664 /* If the start of this line is the overlay arrow-position, then
17665 mark this glyph row as the one containing the overlay arrow.
17666 This is clearly a mess with variable size fonts. It would be
17667 better to let it be displayed like cursors under X. */
17668 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17669 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17670 !NILP (overlay_arrow_string
)))
17672 /* Overlay arrow in window redisplay is a fringe bitmap. */
17673 if (STRINGP (overlay_arrow_string
))
17675 struct glyph_row
*arrow_row
17676 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17677 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17678 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17679 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17680 struct glyph
*p2
, *end
;
17682 /* Copy the arrow glyphs. */
17683 while (glyph
< arrow_end
)
17686 /* Throw away padding glyphs. */
17688 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17689 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17695 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17700 xassert (INTEGERP (overlay_arrow_string
));
17701 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17703 overlay_arrow_seen
= 1;
17706 /* Compute pixel dimensions of this line. */
17707 compute_line_metrics (it
);
17709 /* Remember the position at which this line ends. */
17710 row
->end
= row_end
= it
->current
;
17713 /* ROW->start and ROW->end must be the smallest and largest
17714 buffer positions in ROW. But if ROW was bidi-reordered,
17715 these two positions can be anywhere in the row, so we must
17716 rescan all of the ROW's glyphs to find them. */
17717 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17718 lines' rows is implemented for bidi-reordered rows. */
17719 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17722 struct text_pos tpos
;
17724 for (g
= row
->glyphs
[TEXT_AREA
];
17725 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17728 if (BUFFERP (g
->object
))
17730 if (g
->charpos
> 0 && g
->charpos
< min_pos
)
17731 min_pos
= g
->charpos
;
17732 if (g
->charpos
> max_pos
)
17733 max_pos
= g
->charpos
;
17736 /* Empty lines have a valid buffer position at their first
17737 glyph, but that glyph's OBJECT is zero, as if it didn't come
17738 from a buffer. If we didn't find any valid buffer positions
17739 in this row, maybe we have such an empty line. */
17740 if (min_pos
== ZV
+ 1 && row
->used
[TEXT_AREA
])
17742 for (g
= row
->glyphs
[TEXT_AREA
];
17743 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17746 if (INTEGERP (g
->object
))
17748 if (g
->charpos
> 0 && g
->charpos
< min_pos
)
17749 min_pos
= g
->charpos
;
17750 if (g
->charpos
> max_pos
)
17751 max_pos
= g
->charpos
;
17757 if (min_pos
!= row
->start
.pos
.charpos
)
17759 row
->start
.pos
.charpos
= min_pos
;
17760 row
->start
.pos
.bytepos
= CHAR_TO_BYTE (min_pos
);
17765 /* For ROW->end, we need the position that is _after_ max_pos,
17766 in the logical order, unless we are at ZV. */
17767 if (row
->ends_at_zv_p
)
17769 row_end
= row
->end
= it
->current
;
17770 if (!row
->used
[TEXT_AREA
])
17772 row
->start
.pos
.charpos
= row_end
.pos
.charpos
;
17773 row
->start
.pos
.bytepos
= row_end
.pos
.bytepos
;
17776 else if (row
->used
[TEXT_AREA
] && max_pos
)
17778 SET_TEXT_POS (tpos
, max_pos
+ 1, CHAR_TO_BYTE (max_pos
+ 1));
17779 row_end
= it
->current
;
17780 row_end
.pos
= tpos
;
17781 /* If the character at max_pos+1 is a newline, skip that as
17782 well. Note that this may skip some invisible text. */
17783 if (FETCH_CHAR (tpos
.bytepos
) == '\n'
17784 || (FETCH_CHAR (tpos
.bytepos
) == '\r' && it
->selective
))
17788 reseat_1 (it
, tpos
, 0);
17789 set_iterator_to_next (it
, 1);
17790 /* Record the position after the newline of a continued
17791 row. We will need that to set ROW->end of the last
17792 row produced for a continued line. */
17793 if (row
->continued_p
)
17795 save_it
.eol_pos
.charpos
= IT_CHARPOS (*it
);
17796 save_it
.eol_pos
.bytepos
= IT_BYTEPOS (*it
);
17800 row_end
= it
->current
;
17801 save_it
.eol_pos
.charpos
= save_it
.eol_pos
.bytepos
= 0;
17805 else if (!row
->continued_p
17806 && row
->continuation_lines_width
17807 && it
->eol_pos
.charpos
> 0)
17809 /* Last row of a continued line. Use the position
17810 recorded in ROW->eol_pos, to the effect that the
17811 newline belongs to this row, not to the row which
17812 displays the character with the largest buffer
17814 row_end
.pos
= it
->eol_pos
;
17815 it
->eol_pos
.charpos
= it
->eol_pos
.bytepos
= 0;
17817 row
->end
= row_end
;
17821 /* Record whether this row ends inside an ellipsis. */
17822 row
->ends_in_ellipsis_p
17823 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17824 && it
->ellipsis_p
);
17826 /* Save fringe bitmaps in this row. */
17827 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17828 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17829 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17830 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17832 it
->left_user_fringe_bitmap
= 0;
17833 it
->left_user_fringe_face_id
= 0;
17834 it
->right_user_fringe_bitmap
= 0;
17835 it
->right_user_fringe_face_id
= 0;
17837 /* Maybe set the cursor. */
17838 cvpos
= it
->w
->cursor
.vpos
;
17840 /* In bidi-reordered rows, keep checking for proper cursor
17841 position even if one has been found already, because buffer
17842 positions in such rows change non-linearly with ROW->VPOS,
17843 when a line is continued. One exception: when we are at ZV,
17844 display cursor on the first suitable glyph row, since all
17845 the empty rows after that also have their position set to ZV. */
17846 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17847 lines' rows is implemented for bidi-reordered rows. */
17849 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
17850 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17851 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17852 && cursor_row_p (it
->w
, row
))
17853 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17855 /* Highlight trailing whitespace. */
17856 if (!NILP (Vshow_trailing_whitespace
))
17857 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17859 /* Prepare for the next line. This line starts horizontally at (X
17860 HPOS) = (0 0). Vertical positions are incremented. As a
17861 convenience for the caller, IT->glyph_row is set to the next
17863 it
->current_x
= it
->hpos
= 0;
17864 it
->current_y
+= row
->height
;
17867 /* The next row should use same value of the reversed_p flag as this
17868 one. set_iterator_to_next decides when it's a new paragraph, and
17869 PRODUCE_GLYPHS recomputes the value of the flag accordingly. */
17870 it
->glyph_row
->reversed_p
= row
->reversed_p
;
17871 it
->start
= row_end
;
17872 return row
->displays_text_p
;
17877 /***********************************************************************
17879 ***********************************************************************/
17881 /* Redisplay the menu bar in the frame for window W.
17883 The menu bar of X frames that don't have X toolkit support is
17884 displayed in a special window W->frame->menu_bar_window.
17886 The menu bar of terminal frames is treated specially as far as
17887 glyph matrices are concerned. Menu bar lines are not part of
17888 windows, so the update is done directly on the frame matrix rows
17889 for the menu bar. */
17892 display_menu_bar (w
)
17895 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17900 /* Don't do all this for graphical frames. */
17902 if (FRAME_W32_P (f
))
17905 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17911 if (FRAME_NS_P (f
))
17913 #endif /* HAVE_NS */
17915 #ifdef USE_X_TOOLKIT
17916 xassert (!FRAME_WINDOW_P (f
));
17917 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17918 it
.first_visible_x
= 0;
17919 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17920 #else /* not USE_X_TOOLKIT */
17921 if (FRAME_WINDOW_P (f
))
17923 /* Menu bar lines are displayed in the desired matrix of the
17924 dummy window menu_bar_window. */
17925 struct window
*menu_w
;
17926 xassert (WINDOWP (f
->menu_bar_window
));
17927 menu_w
= XWINDOW (f
->menu_bar_window
);
17928 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17930 it
.first_visible_x
= 0;
17931 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17935 /* This is a TTY frame, i.e. character hpos/vpos are used as
17937 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17939 it
.first_visible_x
= 0;
17940 it
.last_visible_x
= FRAME_COLS (f
);
17942 #endif /* not USE_X_TOOLKIT */
17944 if (! mode_line_inverse_video
)
17945 /* Force the menu-bar to be displayed in the default face. */
17946 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17948 /* Clear all rows of the menu bar. */
17949 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17951 struct glyph_row
*row
= it
.glyph_row
+ i
;
17952 clear_glyph_row (row
);
17953 row
->enabled_p
= 1;
17954 row
->full_width_p
= 1;
17957 /* Display all items of the menu bar. */
17958 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17959 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17961 Lisp_Object string
;
17963 /* Stop at nil string. */
17964 string
= AREF (items
, i
+ 1);
17968 /* Remember where item was displayed. */
17969 ASET (items
, i
+ 3, make_number (it
.hpos
));
17971 /* Display the item, pad with one space. */
17972 if (it
.current_x
< it
.last_visible_x
)
17973 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17974 SCHARS (string
) + 1, 0, 0, -1);
17977 /* Fill out the line with spaces. */
17978 if (it
.current_x
< it
.last_visible_x
)
17979 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17981 /* Compute the total height of the lines. */
17982 compute_line_metrics (&it
);
17987 /***********************************************************************
17989 ***********************************************************************/
17991 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17992 FORCE is non-zero, redisplay mode lines unconditionally.
17993 Otherwise, redisplay only mode lines that are garbaged. Value is
17994 the number of windows whose mode lines were redisplayed. */
17997 redisplay_mode_lines (window
, force
)
17998 Lisp_Object window
;
18003 while (!NILP (window
))
18005 struct window
*w
= XWINDOW (window
);
18007 if (WINDOWP (w
->hchild
))
18008 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18009 else if (WINDOWP (w
->vchild
))
18010 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18012 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18013 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18015 struct text_pos lpoint
;
18016 struct buffer
*old
= current_buffer
;
18018 /* Set the window's buffer for the mode line display. */
18019 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18020 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18022 /* Point refers normally to the selected window. For any
18023 other window, set up appropriate value. */
18024 if (!EQ (window
, selected_window
))
18026 struct text_pos pt
;
18028 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18029 if (CHARPOS (pt
) < BEGV
)
18030 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18031 else if (CHARPOS (pt
) > (ZV
- 1))
18032 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18034 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18037 /* Display mode lines. */
18038 clear_glyph_matrix (w
->desired_matrix
);
18039 if (display_mode_lines (w
))
18042 w
->must_be_updated_p
= 1;
18045 /* Restore old settings. */
18046 set_buffer_internal_1 (old
);
18047 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18057 /* Display the mode and/or header line of window W. Value is the
18058 sum number of mode lines and header lines displayed. */
18061 display_mode_lines (w
)
18064 Lisp_Object old_selected_window
, old_selected_frame
;
18067 old_selected_frame
= selected_frame
;
18068 selected_frame
= w
->frame
;
18069 old_selected_window
= selected_window
;
18070 XSETWINDOW (selected_window
, w
);
18072 /* These will be set while the mode line specs are processed. */
18073 line_number_displayed
= 0;
18074 w
->column_number_displayed
= Qnil
;
18076 if (WINDOW_WANTS_MODELINE_P (w
))
18078 struct window
*sel_w
= XWINDOW (old_selected_window
);
18080 /* Select mode line face based on the real selected window. */
18081 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18082 current_buffer
->mode_line_format
);
18086 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18088 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18089 current_buffer
->header_line_format
);
18093 selected_frame
= old_selected_frame
;
18094 selected_window
= old_selected_window
;
18099 /* Display mode or header line of window W. FACE_ID specifies which
18100 line to display; it is either MODE_LINE_FACE_ID or
18101 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18102 display. Value is the pixel height of the mode/header line
18106 display_mode_line (w
, face_id
, format
)
18108 enum face_id face_id
;
18109 Lisp_Object format
;
18113 int count
= SPECPDL_INDEX ();
18115 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18116 /* Don't extend on a previously drawn mode-line.
18117 This may happen if called from pos_visible_p. */
18118 it
.glyph_row
->enabled_p
= 0;
18119 prepare_desired_row (it
.glyph_row
);
18121 it
.glyph_row
->mode_line_p
= 1;
18123 if (! mode_line_inverse_video
)
18124 /* Force the mode-line to be displayed in the default face. */
18125 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18127 record_unwind_protect (unwind_format_mode_line
,
18128 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18130 mode_line_target
= MODE_LINE_DISPLAY
;
18132 /* Temporarily make frame's keyboard the current kboard so that
18133 kboard-local variables in the mode_line_format will get the right
18135 push_kboard (FRAME_KBOARD (it
.f
));
18136 record_unwind_save_match_data ();
18137 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18140 unbind_to (count
, Qnil
);
18142 /* Fill up with spaces. */
18143 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18145 compute_line_metrics (&it
);
18146 it
.glyph_row
->full_width_p
= 1;
18147 it
.glyph_row
->continued_p
= 0;
18148 it
.glyph_row
->truncated_on_left_p
= 0;
18149 it
.glyph_row
->truncated_on_right_p
= 0;
18151 /* Make a 3D mode-line have a shadow at its right end. */
18152 face
= FACE_FROM_ID (it
.f
, face_id
);
18153 extend_face_to_end_of_line (&it
);
18154 if (face
->box
!= FACE_NO_BOX
)
18156 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18157 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18158 last
->right_box_line_p
= 1;
18161 return it
.glyph_row
->height
;
18164 /* Move element ELT in LIST to the front of LIST.
18165 Return the updated list. */
18168 move_elt_to_front (elt
, list
)
18169 Lisp_Object elt
, list
;
18171 register Lisp_Object tail
, prev
;
18172 register Lisp_Object tem
;
18176 while (CONSP (tail
))
18182 /* Splice out the link TAIL. */
18184 list
= XCDR (tail
);
18186 Fsetcdr (prev
, XCDR (tail
));
18188 /* Now make it the first. */
18189 Fsetcdr (tail
, list
);
18194 tail
= XCDR (tail
);
18198 /* Not found--return unchanged LIST. */
18202 /* Contribute ELT to the mode line for window IT->w. How it
18203 translates into text depends on its data type.
18205 IT describes the display environment in which we display, as usual.
18207 DEPTH is the depth in recursion. It is used to prevent
18208 infinite recursion here.
18210 FIELD_WIDTH is the number of characters the display of ELT should
18211 occupy in the mode line, and PRECISION is the maximum number of
18212 characters to display from ELT's representation. See
18213 display_string for details.
18215 Returns the hpos of the end of the text generated by ELT.
18217 PROPS is a property list to add to any string we encounter.
18219 If RISKY is nonzero, remove (disregard) any properties in any string
18220 we encounter, and ignore :eval and :propertize.
18222 The global variable `mode_line_target' determines whether the
18223 output is passed to `store_mode_line_noprop',
18224 `store_mode_line_string', or `display_string'. */
18227 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
18230 int field_width
, precision
;
18231 Lisp_Object elt
, props
;
18234 int n
= 0, field
, prec
;
18239 elt
= build_string ("*too-deep*");
18243 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18247 /* A string: output it and check for %-constructs within it. */
18251 if (SCHARS (elt
) > 0
18252 && (!NILP (props
) || risky
))
18254 Lisp_Object oprops
, aelt
;
18255 oprops
= Ftext_properties_at (make_number (0), elt
);
18257 /* If the starting string's properties are not what
18258 we want, translate the string. Also, if the string
18259 is risky, do that anyway. */
18261 if (NILP (Fequal (props
, oprops
)) || risky
)
18263 /* If the starting string has properties,
18264 merge the specified ones onto the existing ones. */
18265 if (! NILP (oprops
) && !risky
)
18269 oprops
= Fcopy_sequence (oprops
);
18271 while (CONSP (tem
))
18273 oprops
= Fplist_put (oprops
, XCAR (tem
),
18274 XCAR (XCDR (tem
)));
18275 tem
= XCDR (XCDR (tem
));
18280 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18281 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18283 /* AELT is what we want. Move it to the front
18284 without consing. */
18286 mode_line_proptrans_alist
18287 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18293 /* If AELT has the wrong props, it is useless.
18294 so get rid of it. */
18296 mode_line_proptrans_alist
18297 = Fdelq (aelt
, mode_line_proptrans_alist
);
18299 elt
= Fcopy_sequence (elt
);
18300 Fset_text_properties (make_number (0), Flength (elt
),
18302 /* Add this item to mode_line_proptrans_alist. */
18303 mode_line_proptrans_alist
18304 = Fcons (Fcons (elt
, props
),
18305 mode_line_proptrans_alist
);
18306 /* Truncate mode_line_proptrans_alist
18307 to at most 50 elements. */
18308 tem
= Fnthcdr (make_number (50),
18309 mode_line_proptrans_alist
);
18311 XSETCDR (tem
, Qnil
);
18320 prec
= precision
- n
;
18321 switch (mode_line_target
)
18323 case MODE_LINE_NOPROP
:
18324 case MODE_LINE_TITLE
:
18325 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
18327 case MODE_LINE_STRING
:
18328 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18330 case MODE_LINE_DISPLAY
:
18331 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18332 0, prec
, 0, STRING_MULTIBYTE (elt
));
18339 /* Handle the non-literal case. */
18341 while ((precision
<= 0 || n
< precision
)
18342 && SREF (elt
, offset
) != 0
18343 && (mode_line_target
!= MODE_LINE_DISPLAY
18344 || it
->current_x
< it
->last_visible_x
))
18346 int last_offset
= offset
;
18348 /* Advance to end of string or next format specifier. */
18349 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18352 if (offset
- 1 != last_offset
)
18354 int nchars
, nbytes
;
18356 /* Output to end of string or up to '%'. Field width
18357 is length of string. Don't output more than
18358 PRECISION allows us. */
18361 prec
= c_string_width (SDATA (elt
) + last_offset
,
18362 offset
- last_offset
, precision
- n
,
18365 switch (mode_line_target
)
18367 case MODE_LINE_NOPROP
:
18368 case MODE_LINE_TITLE
:
18369 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18371 case MODE_LINE_STRING
:
18373 int bytepos
= last_offset
;
18374 int charpos
= string_byte_to_char (elt
, bytepos
);
18375 int endpos
= (precision
<= 0
18376 ? string_byte_to_char (elt
, offset
)
18377 : charpos
+ nchars
);
18379 n
+= store_mode_line_string (NULL
,
18380 Fsubstring (elt
, make_number (charpos
),
18381 make_number (endpos
)),
18385 case MODE_LINE_DISPLAY
:
18387 int bytepos
= last_offset
;
18388 int charpos
= string_byte_to_char (elt
, bytepos
);
18390 if (precision
<= 0)
18391 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18392 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18394 STRING_MULTIBYTE (elt
));
18399 else /* c == '%' */
18401 int percent_position
= offset
;
18403 /* Get the specified minimum width. Zero means
18406 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18407 field
= field
* 10 + c
- '0';
18409 /* Don't pad beyond the total padding allowed. */
18410 if (field_width
- n
> 0 && field
> field_width
- n
)
18411 field
= field_width
- n
;
18413 /* Note that either PRECISION <= 0 or N < PRECISION. */
18414 prec
= precision
- n
;
18417 n
+= display_mode_element (it
, depth
, field
, prec
,
18418 Vglobal_mode_string
, props
,
18423 int bytepos
, charpos
;
18424 unsigned char *spec
;
18425 Lisp_Object string
;
18427 bytepos
= percent_position
;
18428 charpos
= (STRING_MULTIBYTE (elt
)
18429 ? string_byte_to_char (elt
, bytepos
)
18431 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
18432 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18434 switch (mode_line_target
)
18436 case MODE_LINE_NOPROP
:
18437 case MODE_LINE_TITLE
:
18438 n
+= store_mode_line_noprop (spec
, field
, prec
);
18440 case MODE_LINE_STRING
:
18442 int len
= strlen (spec
);
18443 Lisp_Object tem
= make_string (spec
, len
);
18444 props
= Ftext_properties_at (make_number (charpos
), elt
);
18445 /* Should only keep face property in props */
18446 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18449 case MODE_LINE_DISPLAY
:
18451 int nglyphs_before
, nwritten
;
18453 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18454 nwritten
= display_string (spec
, string
, elt
,
18459 /* Assign to the glyphs written above the
18460 string where the `%x' came from, position
18464 struct glyph
*glyph
18465 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18469 for (i
= 0; i
< nwritten
; ++i
)
18471 glyph
[i
].object
= elt
;
18472 glyph
[i
].charpos
= charpos
;
18489 /* A symbol: process the value of the symbol recursively
18490 as if it appeared here directly. Avoid error if symbol void.
18491 Special case: if value of symbol is a string, output the string
18494 register Lisp_Object tem
;
18496 /* If the variable is not marked as risky to set
18497 then its contents are risky to use. */
18498 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18501 tem
= Fboundp (elt
);
18504 tem
= Fsymbol_value (elt
);
18505 /* If value is a string, output that string literally:
18506 don't check for % within it. */
18510 if (!EQ (tem
, elt
))
18512 /* Give up right away for nil or t. */
18522 register Lisp_Object car
, tem
;
18524 /* A cons cell: five distinct cases.
18525 If first element is :eval or :propertize, do something special.
18526 If first element is a string or a cons, process all the elements
18527 and effectively concatenate them.
18528 If first element is a negative number, truncate displaying cdr to
18529 at most that many characters. If positive, pad (with spaces)
18530 to at least that many characters.
18531 If first element is a symbol, process the cadr or caddr recursively
18532 according to whether the symbol's value is non-nil or nil. */
18534 if (EQ (car
, QCeval
))
18536 /* An element of the form (:eval FORM) means evaluate FORM
18537 and use the result as mode line elements. */
18542 if (CONSP (XCDR (elt
)))
18545 spec
= safe_eval (XCAR (XCDR (elt
)));
18546 n
+= display_mode_element (it
, depth
, field_width
- n
,
18547 precision
- n
, spec
, props
,
18551 else if (EQ (car
, QCpropertize
))
18553 /* An element of the form (:propertize ELT PROPS...)
18554 means display ELT but applying properties PROPS. */
18559 if (CONSP (XCDR (elt
)))
18560 n
+= display_mode_element (it
, depth
, field_width
- n
,
18561 precision
- n
, XCAR (XCDR (elt
)),
18562 XCDR (XCDR (elt
)), risky
);
18564 else if (SYMBOLP (car
))
18566 tem
= Fboundp (car
);
18570 /* elt is now the cdr, and we know it is a cons cell.
18571 Use its car if CAR has a non-nil value. */
18574 tem
= Fsymbol_value (car
);
18581 /* Symbol's value is nil (or symbol is unbound)
18582 Get the cddr of the original list
18583 and if possible find the caddr and use that. */
18587 else if (!CONSP (elt
))
18592 else if (INTEGERP (car
))
18594 register int lim
= XINT (car
);
18598 /* Negative int means reduce maximum width. */
18599 if (precision
<= 0)
18602 precision
= min (precision
, -lim
);
18606 /* Padding specified. Don't let it be more than
18607 current maximum. */
18609 lim
= min (precision
, lim
);
18611 /* If that's more padding than already wanted, queue it.
18612 But don't reduce padding already specified even if
18613 that is beyond the current truncation point. */
18614 field_width
= max (lim
, field_width
);
18618 else if (STRINGP (car
) || CONSP (car
))
18620 Lisp_Object halftail
= elt
;
18624 && (precision
<= 0 || n
< precision
))
18626 n
+= display_mode_element (it
, depth
,
18627 /* Do padding only after the last
18628 element in the list. */
18629 (! CONSP (XCDR (elt
))
18632 precision
- n
, XCAR (elt
),
18636 if ((len
& 1) == 0)
18637 halftail
= XCDR (halftail
);
18638 /* Check for cycle. */
18639 if (EQ (halftail
, elt
))
18648 elt
= build_string ("*invalid*");
18652 /* Pad to FIELD_WIDTH. */
18653 if (field_width
> 0 && n
< field_width
)
18655 switch (mode_line_target
)
18657 case MODE_LINE_NOPROP
:
18658 case MODE_LINE_TITLE
:
18659 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18661 case MODE_LINE_STRING
:
18662 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18664 case MODE_LINE_DISPLAY
:
18665 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18674 /* Store a mode-line string element in mode_line_string_list.
18676 If STRING is non-null, display that C string. Otherwise, the Lisp
18677 string LISP_STRING is displayed.
18679 FIELD_WIDTH is the minimum number of output glyphs to produce.
18680 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18681 with spaces. FIELD_WIDTH <= 0 means don't pad.
18683 PRECISION is the maximum number of characters to output from
18684 STRING. PRECISION <= 0 means don't truncate the string.
18686 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18687 properties to the string.
18689 PROPS are the properties to add to the string.
18690 The mode_line_string_face face property is always added to the string.
18694 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
18696 Lisp_Object lisp_string
;
18705 if (string
!= NULL
)
18707 len
= strlen (string
);
18708 if (precision
> 0 && len
> precision
)
18710 lisp_string
= make_string (string
, len
);
18712 props
= mode_line_string_face_prop
;
18713 else if (!NILP (mode_line_string_face
))
18715 Lisp_Object face
= Fplist_get (props
, Qface
);
18716 props
= Fcopy_sequence (props
);
18718 face
= mode_line_string_face
;
18720 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18721 props
= Fplist_put (props
, Qface
, face
);
18723 Fadd_text_properties (make_number (0), make_number (len
),
18724 props
, lisp_string
);
18728 len
= XFASTINT (Flength (lisp_string
));
18729 if (precision
> 0 && len
> precision
)
18732 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
18735 if (!NILP (mode_line_string_face
))
18739 props
= Ftext_properties_at (make_number (0), lisp_string
);
18740 face
= Fplist_get (props
, Qface
);
18742 face
= mode_line_string_face
;
18744 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18745 props
= Fcons (Qface
, Fcons (face
, Qnil
));
18747 lisp_string
= Fcopy_sequence (lisp_string
);
18750 Fadd_text_properties (make_number (0), make_number (len
),
18751 props
, lisp_string
);
18756 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18760 if (field_width
> len
)
18762 field_width
-= len
;
18763 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
18765 Fadd_text_properties (make_number (0), make_number (field_width
),
18766 props
, lisp_string
);
18767 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18775 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
18777 doc
: /* Format a string out of a mode line format specification.
18778 First arg FORMAT specifies the mode line format (see `mode-line-format'
18779 for details) to use.
18781 Optional second arg FACE specifies the face property to put
18782 on all characters for which no face is specified.
18783 The value t means whatever face the window's mode line currently uses
18784 \(either `mode-line' or `mode-line-inactive', depending).
18785 A value of nil means the default is no face property.
18786 If FACE is an integer, the value string has no text properties.
18788 Optional third and fourth args WINDOW and BUFFER specify the window
18789 and buffer to use as the context for the formatting (defaults
18790 are the selected window and the window's buffer). */)
18791 (format
, face
, window
, buffer
)
18792 Lisp_Object format
, face
, window
, buffer
;
18797 struct buffer
*old_buffer
= NULL
;
18799 int no_props
= INTEGERP (face
);
18800 int count
= SPECPDL_INDEX ();
18802 int string_start
= 0;
18805 window
= selected_window
;
18806 CHECK_WINDOW (window
);
18807 w
= XWINDOW (window
);
18810 buffer
= w
->buffer
;
18811 CHECK_BUFFER (buffer
);
18813 /* Make formatting the modeline a non-op when noninteractive, otherwise
18814 there will be problems later caused by a partially initialized frame. */
18815 if (NILP (format
) || noninteractive
)
18816 return empty_unibyte_string
;
18824 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
18825 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
18829 face_id
= DEFAULT_FACE_ID
;
18831 if (XBUFFER (buffer
) != current_buffer
)
18832 old_buffer
= current_buffer
;
18834 /* Save things including mode_line_proptrans_alist,
18835 and set that to nil so that we don't alter the outer value. */
18836 record_unwind_protect (unwind_format_mode_line
,
18837 format_mode_line_unwind_data
18838 (old_buffer
, selected_window
, 1));
18839 mode_line_proptrans_alist
= Qnil
;
18841 Fselect_window (window
, Qt
);
18843 set_buffer_internal_1 (XBUFFER (buffer
));
18845 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18849 mode_line_target
= MODE_LINE_NOPROP
;
18850 mode_line_string_face_prop
= Qnil
;
18851 mode_line_string_list
= Qnil
;
18852 string_start
= MODE_LINE_NOPROP_LEN (0);
18856 mode_line_target
= MODE_LINE_STRING
;
18857 mode_line_string_list
= Qnil
;
18858 mode_line_string_face
= face
;
18859 mode_line_string_face_prop
18860 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18863 push_kboard (FRAME_KBOARD (it
.f
));
18864 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18869 len
= MODE_LINE_NOPROP_LEN (string_start
);
18870 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18874 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18875 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18876 empty_unibyte_string
);
18879 unbind_to (count
, Qnil
);
18883 /* Write a null-terminated, right justified decimal representation of
18884 the positive integer D to BUF using a minimal field width WIDTH. */
18887 pint2str (buf
, width
, d
)
18888 register char *buf
;
18889 register int width
;
18892 register char *p
= buf
;
18900 *p
++ = d
% 10 + '0';
18905 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18916 /* Write a null-terminated, right justified decimal and "human
18917 readable" representation of the nonnegative integer D to BUF using
18918 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18920 static const char power_letter
[] =
18934 pint2hrstr (buf
, width
, d
)
18939 /* We aim to represent the nonnegative integer D as
18940 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18943 /* -1 means: do not use TENTHS. */
18947 /* Length of QUOTIENT.TENTHS as a string. */
18953 if (1000 <= quotient
)
18955 /* Scale to the appropriate EXPONENT. */
18958 remainder
= quotient
% 1000;
18962 while (1000 <= quotient
);
18964 /* Round to nearest and decide whether to use TENTHS or not. */
18967 tenths
= remainder
/ 100;
18968 if (50 <= remainder
% 100)
18975 if (quotient
== 10)
18983 if (500 <= remainder
)
18985 if (quotient
< 999)
18996 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18997 if (tenths
== -1 && quotient
<= 99)
19004 p
= psuffix
= buf
+ max (width
, length
);
19006 /* Print EXPONENT. */
19008 *psuffix
++ = power_letter
[exponent
];
19011 /* Print TENTHS. */
19014 *--p
= '0' + tenths
;
19018 /* Print QUOTIENT. */
19021 int digit
= quotient
% 10;
19022 *--p
= '0' + digit
;
19024 while ((quotient
/= 10) != 0);
19026 /* Print leading spaces. */
19031 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19032 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19033 type of CODING_SYSTEM. Return updated pointer into BUF. */
19035 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19038 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
19039 Lisp_Object coding_system
;
19040 register char *buf
;
19044 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
19045 const unsigned char *eol_str
;
19047 /* The EOL conversion we are using. */
19048 Lisp_Object eoltype
;
19050 val
= CODING_SYSTEM_SPEC (coding_system
);
19053 if (!VECTORP (val
)) /* Not yet decided. */
19058 eoltype
= eol_mnemonic_undecided
;
19059 /* Don't mention EOL conversion if it isn't decided. */
19064 Lisp_Object eolvalue
;
19066 attrs
= AREF (val
, 0);
19067 eolvalue
= AREF (val
, 2);
19070 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19074 /* The EOL conversion that is normal on this system. */
19076 if (NILP (eolvalue
)) /* Not yet decided. */
19077 eoltype
= eol_mnemonic_undecided
;
19078 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19079 eoltype
= eol_mnemonic_undecided
;
19080 else /* eolvalue is Qunix, Qdos, or Qmac. */
19081 eoltype
= (EQ (eolvalue
, Qunix
)
19082 ? eol_mnemonic_unix
19083 : (EQ (eolvalue
, Qdos
) == 1
19084 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19090 /* Mention the EOL conversion if it is not the usual one. */
19091 if (STRINGP (eoltype
))
19093 eol_str
= SDATA (eoltype
);
19094 eol_str_len
= SBYTES (eoltype
);
19096 else if (CHARACTERP (eoltype
))
19098 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19099 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19104 eol_str
= invalid_eol_type
;
19105 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19107 bcopy (eol_str
, buf
, eol_str_len
);
19108 buf
+= eol_str_len
;
19114 /* Return a string for the output of a mode line %-spec for window W,
19115 generated by character C. PRECISION >= 0 means don't return a
19116 string longer than that value. FIELD_WIDTH > 0 means pad the
19117 string returned with spaces to that value. Return a Lisp string in
19118 *STRING if the resulting string is taken from that Lisp string.
19120 Note we operate on the current buffer for most purposes,
19121 the exception being w->base_line_pos. */
19123 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19126 decode_mode_spec (w
, c
, field_width
, precision
, string
)
19129 int field_width
, precision
;
19130 Lisp_Object
*string
;
19133 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19134 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19135 struct buffer
*b
= current_buffer
;
19143 if (!NILP (b
->read_only
))
19145 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19150 /* This differs from %* only for a modified read-only buffer. */
19151 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19153 if (!NILP (b
->read_only
))
19158 /* This differs from %* in ignoring read-only-ness. */
19159 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19171 if (command_loop_level
> 5)
19173 p
= decode_mode_spec_buf
;
19174 for (i
= 0; i
< command_loop_level
; i
++)
19177 return decode_mode_spec_buf
;
19185 if (command_loop_level
> 5)
19187 p
= decode_mode_spec_buf
;
19188 for (i
= 0; i
< command_loop_level
; i
++)
19191 return decode_mode_spec_buf
;
19198 /* Let lots_of_dashes be a string of infinite length. */
19199 if (mode_line_target
== MODE_LINE_NOPROP
||
19200 mode_line_target
== MODE_LINE_STRING
)
19202 if (field_width
<= 0
19203 || field_width
> sizeof (lots_of_dashes
))
19205 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19206 decode_mode_spec_buf
[i
] = '-';
19207 decode_mode_spec_buf
[i
] = '\0';
19208 return decode_mode_spec_buf
;
19211 return lots_of_dashes
;
19219 /* %c and %l are ignored in `frame-title-format'.
19220 (In redisplay_internal, the frame title is drawn _before_ the
19221 windows are updated, so the stuff which depends on actual
19222 window contents (such as %l) may fail to render properly, or
19223 even crash emacs.) */
19224 if (mode_line_target
== MODE_LINE_TITLE
)
19228 int col
= (int) current_column (); /* iftc */
19229 w
->column_number_displayed
= make_number (col
);
19230 pint2str (decode_mode_spec_buf
, field_width
, col
);
19231 return decode_mode_spec_buf
;
19235 #ifndef SYSTEM_MALLOC
19237 if (NILP (Vmemory_full
))
19240 return "!MEM FULL! ";
19247 /* %F displays the frame name. */
19248 if (!NILP (f
->title
))
19249 return (char *) SDATA (f
->title
);
19250 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19251 return (char *) SDATA (f
->name
);
19260 int size
= ZV
- BEGV
;
19261 pint2str (decode_mode_spec_buf
, field_width
, size
);
19262 return decode_mode_spec_buf
;
19267 int size
= ZV
- BEGV
;
19268 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19269 return decode_mode_spec_buf
;
19274 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19275 int topline
, nlines
, junk
, height
;
19277 /* %c and %l are ignored in `frame-title-format'. */
19278 if (mode_line_target
== MODE_LINE_TITLE
)
19281 startpos
= XMARKER (w
->start
)->charpos
;
19282 startpos_byte
= marker_byte_position (w
->start
);
19283 height
= WINDOW_TOTAL_LINES (w
);
19285 /* If we decided that this buffer isn't suitable for line numbers,
19286 don't forget that too fast. */
19287 if (EQ (w
->base_line_pos
, w
->buffer
))
19289 /* But do forget it, if the window shows a different buffer now. */
19290 else if (BUFFERP (w
->base_line_pos
))
19291 w
->base_line_pos
= Qnil
;
19293 /* If the buffer is very big, don't waste time. */
19294 if (INTEGERP (Vline_number_display_limit
)
19295 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19297 w
->base_line_pos
= Qnil
;
19298 w
->base_line_number
= Qnil
;
19302 if (INTEGERP (w
->base_line_number
)
19303 && INTEGERP (w
->base_line_pos
)
19304 && XFASTINT (w
->base_line_pos
) <= startpos
)
19306 line
= XFASTINT (w
->base_line_number
);
19307 linepos
= XFASTINT (w
->base_line_pos
);
19308 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19313 linepos
= BUF_BEGV (b
);
19314 linepos_byte
= BUF_BEGV_BYTE (b
);
19317 /* Count lines from base line to window start position. */
19318 nlines
= display_count_lines (linepos
, linepos_byte
,
19322 topline
= nlines
+ line
;
19324 /* Determine a new base line, if the old one is too close
19325 or too far away, or if we did not have one.
19326 "Too close" means it's plausible a scroll-down would
19327 go back past it. */
19328 if (startpos
== BUF_BEGV (b
))
19330 w
->base_line_number
= make_number (topline
);
19331 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19333 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19334 || linepos
== BUF_BEGV (b
))
19336 int limit
= BUF_BEGV (b
);
19337 int limit_byte
= BUF_BEGV_BYTE (b
);
19339 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
19341 if (startpos
- distance
> limit
)
19343 limit
= startpos
- distance
;
19344 limit_byte
= CHAR_TO_BYTE (limit
);
19347 nlines
= display_count_lines (startpos
, startpos_byte
,
19349 - (height
* 2 + 30),
19351 /* If we couldn't find the lines we wanted within
19352 line_number_display_limit_width chars per line,
19353 give up on line numbers for this window. */
19354 if (position
== limit_byte
&& limit
== startpos
- distance
)
19356 w
->base_line_pos
= w
->buffer
;
19357 w
->base_line_number
= Qnil
;
19361 w
->base_line_number
= make_number (topline
- nlines
);
19362 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19365 /* Now count lines from the start pos to point. */
19366 nlines
= display_count_lines (startpos
, startpos_byte
,
19367 PT_BYTE
, PT
, &junk
);
19369 /* Record that we did display the line number. */
19370 line_number_displayed
= 1;
19372 /* Make the string to show. */
19373 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19374 return decode_mode_spec_buf
;
19377 char* p
= decode_mode_spec_buf
;
19378 int pad
= field_width
- 2;
19384 return decode_mode_spec_buf
;
19390 obj
= b
->mode_name
;
19394 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19400 int pos
= marker_position (w
->start
);
19401 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19403 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19405 if (pos
<= BUF_BEGV (b
))
19410 else if (pos
<= BUF_BEGV (b
))
19414 if (total
> 1000000)
19415 /* Do it differently for a large value, to avoid overflow. */
19416 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19418 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19419 /* We can't normally display a 3-digit number,
19420 so get us a 2-digit number that is close. */
19423 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19424 return decode_mode_spec_buf
;
19428 /* Display percentage of size above the bottom of the screen. */
19431 int toppos
= marker_position (w
->start
);
19432 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19433 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19435 if (botpos
>= BUF_ZV (b
))
19437 if (toppos
<= BUF_BEGV (b
))
19444 if (total
> 1000000)
19445 /* Do it differently for a large value, to avoid overflow. */
19446 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19448 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19449 /* We can't normally display a 3-digit number,
19450 so get us a 2-digit number that is close. */
19453 if (toppos
<= BUF_BEGV (b
))
19454 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
19456 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19457 return decode_mode_spec_buf
;
19462 /* status of process */
19463 obj
= Fget_buffer_process (Fcurrent_buffer ());
19465 return "no process";
19466 #ifdef subprocesses
19467 obj
= Fsymbol_name (Fprocess_status (obj
));
19473 int count
= inhibit_garbage_collection ();
19474 Lisp_Object val
= call1 (intern ("file-remote-p"),
19475 current_buffer
->directory
);
19476 unbind_to (count
, Qnil
);
19484 case 't': /* indicate TEXT or BINARY */
19485 #ifdef MODE_LINE_BINARY_TEXT
19486 return MODE_LINE_BINARY_TEXT (b
);
19492 /* coding-system (not including end-of-line format) */
19494 /* coding-system (including end-of-line type) */
19496 int eol_flag
= (c
== 'Z');
19497 char *p
= decode_mode_spec_buf
;
19499 if (! FRAME_WINDOW_P (f
))
19501 /* No need to mention EOL here--the terminal never needs
19502 to do EOL conversion. */
19503 p
= decode_mode_spec_coding (CODING_ID_NAME
19504 (FRAME_KEYBOARD_CODING (f
)->id
),
19506 p
= decode_mode_spec_coding (CODING_ID_NAME
19507 (FRAME_TERMINAL_CODING (f
)->id
),
19510 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19513 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19514 #ifdef subprocesses
19515 obj
= Fget_buffer_process (Fcurrent_buffer ());
19516 if (PROCESSP (obj
))
19518 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19520 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19523 #endif /* subprocesses */
19526 return decode_mode_spec_buf
;
19533 return (char *) SDATA (obj
);
19540 /* Count up to COUNT lines starting from START / START_BYTE.
19541 But don't go beyond LIMIT_BYTE.
19542 Return the number of lines thus found (always nonnegative).
19544 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19547 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
19548 int start
, start_byte
, limit_byte
, count
;
19551 register unsigned char *cursor
;
19552 unsigned char *base
;
19554 register int ceiling
;
19555 register unsigned char *ceiling_addr
;
19556 int orig_count
= count
;
19558 /* If we are not in selective display mode,
19559 check only for newlines. */
19560 int selective_display
= (!NILP (current_buffer
->selective_display
)
19561 && !INTEGERP (current_buffer
->selective_display
));
19565 while (start_byte
< limit_byte
)
19567 ceiling
= BUFFER_CEILING_OF (start_byte
);
19568 ceiling
= min (limit_byte
- 1, ceiling
);
19569 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19570 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19573 if (selective_display
)
19574 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19577 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19580 if (cursor
!= ceiling_addr
)
19584 start_byte
+= cursor
- base
+ 1;
19585 *byte_pos_ptr
= start_byte
;
19589 if (++cursor
== ceiling_addr
)
19595 start_byte
+= cursor
- base
;
19600 while (start_byte
> limit_byte
)
19602 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19603 ceiling
= max (limit_byte
, ceiling
);
19604 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19605 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19608 if (selective_display
)
19609 while (--cursor
!= ceiling_addr
19610 && *cursor
!= '\n' && *cursor
!= 015)
19613 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19616 if (cursor
!= ceiling_addr
)
19620 start_byte
+= cursor
- base
+ 1;
19621 *byte_pos_ptr
= start_byte
;
19622 /* When scanning backwards, we should
19623 not count the newline posterior to which we stop. */
19624 return - orig_count
- 1;
19630 /* Here we add 1 to compensate for the last decrement
19631 of CURSOR, which took it past the valid range. */
19632 start_byte
+= cursor
- base
+ 1;
19636 *byte_pos_ptr
= limit_byte
;
19639 return - orig_count
+ count
;
19640 return orig_count
- count
;
19646 /***********************************************************************
19648 ***********************************************************************/
19650 /* Display a NUL-terminated string, starting with index START.
19652 If STRING is non-null, display that C string. Otherwise, the Lisp
19653 string LISP_STRING is displayed. There's a case that STRING is
19654 non-null and LISP_STRING is not nil. It means STRING is a string
19655 data of LISP_STRING. In that case, we display LISP_STRING while
19656 ignoring its text properties.
19658 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19659 FACE_STRING. Display STRING or LISP_STRING with the face at
19660 FACE_STRING_POS in FACE_STRING:
19662 Display the string in the environment given by IT, but use the
19663 standard display table, temporarily.
19665 FIELD_WIDTH is the minimum number of output glyphs to produce.
19666 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19667 with spaces. If STRING has more characters, more than FIELD_WIDTH
19668 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19670 PRECISION is the maximum number of characters to output from
19671 STRING. PRECISION < 0 means don't truncate the string.
19673 This is roughly equivalent to printf format specifiers:
19675 FIELD_WIDTH PRECISION PRINTF
19676 ----------------------------------------
19682 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19683 display them, and < 0 means obey the current buffer's value of
19684 enable_multibyte_characters.
19686 Value is the number of columns displayed. */
19689 display_string (string
, lisp_string
, face_string
, face_string_pos
,
19690 start
, it
, field_width
, precision
, max_x
, multibyte
)
19691 unsigned char *string
;
19692 Lisp_Object lisp_string
;
19693 Lisp_Object face_string
;
19694 EMACS_INT face_string_pos
;
19697 int field_width
, precision
, max_x
;
19700 int hpos_at_start
= it
->hpos
;
19701 int saved_face_id
= it
->face_id
;
19702 struct glyph_row
*row
= it
->glyph_row
;
19704 /* Initialize the iterator IT for iteration over STRING beginning
19705 with index START. */
19706 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19707 precision
, field_width
, multibyte
);
19708 if (string
&& STRINGP (lisp_string
))
19709 /* LISP_STRING is the one returned by decode_mode_spec. We should
19710 ignore its text properties. */
19711 it
->stop_charpos
= -1;
19713 /* If displaying STRING, set up the face of the iterator
19714 from LISP_STRING, if that's given. */
19715 if (STRINGP (face_string
))
19721 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19722 0, it
->region_beg_charpos
,
19723 it
->region_end_charpos
,
19724 &endptr
, it
->base_face_id
, 0);
19725 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19726 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19729 /* Set max_x to the maximum allowed X position. Don't let it go
19730 beyond the right edge of the window. */
19732 max_x
= it
->last_visible_x
;
19734 max_x
= min (max_x
, it
->last_visible_x
);
19736 /* Skip over display elements that are not visible. because IT->w is
19738 if (it
->current_x
< it
->first_visible_x
)
19739 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
19740 MOVE_TO_POS
| MOVE_TO_X
);
19742 row
->ascent
= it
->max_ascent
;
19743 row
->height
= it
->max_ascent
+ it
->max_descent
;
19744 row
->phys_ascent
= it
->max_phys_ascent
;
19745 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19746 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19748 /* This condition is for the case that we are called with current_x
19749 past last_visible_x. */
19750 while (it
->current_x
< max_x
)
19752 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
19754 /* Get the next display element. */
19755 if (!get_next_display_element (it
))
19758 /* Produce glyphs. */
19759 x_before
= it
->current_x
;
19760 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19761 PRODUCE_GLYPHS (it
);
19763 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
19766 while (i
< nglyphs
)
19768 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19770 if (it
->line_wrap
!= TRUNCATE
19771 && x
+ glyph
->pixel_width
> max_x
)
19773 /* End of continued line or max_x reached. */
19774 if (CHAR_GLYPH_PADDING_P (*glyph
))
19776 /* A wide character is unbreakable. */
19777 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19778 it
->current_x
= x_before
;
19782 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19787 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
19789 /* Glyph is at least partially visible. */
19791 if (x
< it
->first_visible_x
)
19792 it
->glyph_row
->x
= x
- it
->first_visible_x
;
19796 /* Glyph is off the left margin of the display area.
19797 Should not happen. */
19801 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19802 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19803 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19804 row
->phys_height
= max (row
->phys_height
,
19805 it
->max_phys_ascent
+ it
->max_phys_descent
);
19806 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19807 it
->max_extra_line_spacing
);
19808 x
+= glyph
->pixel_width
;
19812 /* Stop if max_x reached. */
19816 /* Stop at line ends. */
19817 if (ITERATOR_AT_END_OF_LINE_P (it
))
19819 it
->continuation_lines_width
= 0;
19823 set_iterator_to_next (it
, 1);
19825 /* Stop if truncating at the right edge. */
19826 if (it
->line_wrap
== TRUNCATE
19827 && it
->current_x
>= it
->last_visible_x
)
19829 /* Add truncation mark, but don't do it if the line is
19830 truncated at a padding space. */
19831 if (IT_CHARPOS (*it
) < it
->string_nchars
)
19833 if (!FRAME_WINDOW_P (it
->f
))
19837 if (it
->current_x
> it
->last_visible_x
)
19839 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19840 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19842 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19844 row
->used
[TEXT_AREA
] = i
;
19845 produce_special_glyphs (it
, IT_TRUNCATION
);
19848 produce_special_glyphs (it
, IT_TRUNCATION
);
19850 it
->glyph_row
->truncated_on_right_p
= 1;
19856 /* Maybe insert a truncation at the left. */
19857 if (it
->first_visible_x
19858 && IT_CHARPOS (*it
) > 0)
19860 if (!FRAME_WINDOW_P (it
->f
))
19861 insert_left_trunc_glyphs (it
);
19862 it
->glyph_row
->truncated_on_left_p
= 1;
19865 it
->face_id
= saved_face_id
;
19867 /* Value is number of columns displayed. */
19868 return it
->hpos
- hpos_at_start
;
19873 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19874 appears as an element of LIST or as the car of an element of LIST.
19875 If PROPVAL is a list, compare each element against LIST in that
19876 way, and return 1/2 if any element of PROPVAL is found in LIST.
19877 Otherwise return 0. This function cannot quit.
19878 The return value is 2 if the text is invisible but with an ellipsis
19879 and 1 if it's invisible and without an ellipsis. */
19882 invisible_p (propval
, list
)
19883 register Lisp_Object propval
;
19886 register Lisp_Object tail
, proptail
;
19888 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19890 register Lisp_Object tem
;
19892 if (EQ (propval
, tem
))
19894 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19895 return NILP (XCDR (tem
)) ? 1 : 2;
19898 if (CONSP (propval
))
19900 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19902 Lisp_Object propelt
;
19903 propelt
= XCAR (proptail
);
19904 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19906 register Lisp_Object tem
;
19908 if (EQ (propelt
, tem
))
19910 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19911 return NILP (XCDR (tem
)) ? 1 : 2;
19919 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19920 doc
: /* Non-nil if the property makes the text invisible.
19921 POS-OR-PROP can be a marker or number, in which case it is taken to be
19922 a position in the current buffer and the value of the `invisible' property
19923 is checked; or it can be some other value, which is then presumed to be the
19924 value of the `invisible' property of the text of interest.
19925 The non-nil value returned can be t for truly invisible text or something
19926 else if the text is replaced by an ellipsis. */)
19928 Lisp_Object pos_or_prop
;
19931 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19932 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19934 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19935 return (invis
== 0 ? Qnil
19937 : make_number (invis
));
19940 /* Calculate a width or height in pixels from a specification using
19941 the following elements:
19944 NUM - a (fractional) multiple of the default font width/height
19945 (NUM) - specifies exactly NUM pixels
19946 UNIT - a fixed number of pixels, see below.
19947 ELEMENT - size of a display element in pixels, see below.
19948 (NUM . SPEC) - equals NUM * SPEC
19949 (+ SPEC SPEC ...) - add pixel values
19950 (- SPEC SPEC ...) - subtract pixel values
19951 (- SPEC) - negate pixel value
19954 INT or FLOAT - a number constant
19955 SYMBOL - use symbol's (buffer local) variable binding.
19958 in - pixels per inch *)
19959 mm - pixels per 1/1000 meter *)
19960 cm - pixels per 1/100 meter *)
19961 width - width of current font in pixels.
19962 height - height of current font in pixels.
19964 *) using the ratio(s) defined in display-pixels-per-inch.
19968 left-fringe - left fringe width in pixels
19969 right-fringe - right fringe width in pixels
19971 left-margin - left margin width in pixels
19972 right-margin - right margin width in pixels
19974 scroll-bar - scroll-bar area width in pixels
19978 Pixels corresponding to 5 inches:
19981 Total width of non-text areas on left side of window (if scroll-bar is on left):
19982 '(space :width (+ left-fringe left-margin scroll-bar))
19984 Align to first text column (in header line):
19985 '(space :align-to 0)
19987 Align to middle of text area minus half the width of variable `my-image'
19988 containing a loaded image:
19989 '(space :align-to (0.5 . (- text my-image)))
19991 Width of left margin minus width of 1 character in the default font:
19992 '(space :width (- left-margin 1))
19994 Width of left margin minus width of 2 characters in the current font:
19995 '(space :width (- left-margin (2 . width)))
19997 Center 1 character over left-margin (in header line):
19998 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
20000 Different ways to express width of left fringe plus left margin minus one pixel:
20001 '(space :width (- (+ left-fringe left-margin) (1)))
20002 '(space :width (+ left-fringe left-margin (- (1))))
20003 '(space :width (+ left-fringe left-margin (-1)))
20007 #define NUMVAL(X) \
20008 ((INTEGERP (X) || FLOATP (X)) \
20013 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
20018 int width_p
, *align_to
;
20022 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20023 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20026 return OK_PIXELS (0);
20028 xassert (FRAME_LIVE_P (it
->f
));
20030 if (SYMBOLP (prop
))
20032 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20034 char *unit
= SDATA (SYMBOL_NAME (prop
));
20036 if (unit
[0] == 'i' && unit
[1] == 'n')
20038 else if (unit
[0] == 'm' && unit
[1] == 'm')
20040 else if (unit
[0] == 'c' && unit
[1] == 'm')
20047 #ifdef HAVE_WINDOW_SYSTEM
20048 if (FRAME_WINDOW_P (it
->f
)
20050 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20051 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20053 return OK_PIXELS (ppi
/ pixels
);
20056 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20057 || (CONSP (Vdisplay_pixels_per_inch
)
20059 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20060 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20062 return OK_PIXELS (ppi
/ pixels
);
20068 #ifdef HAVE_WINDOW_SYSTEM
20069 if (EQ (prop
, Qheight
))
20070 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20071 if (EQ (prop
, Qwidth
))
20072 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20074 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20075 return OK_PIXELS (1);
20078 if (EQ (prop
, Qtext
))
20079 return OK_PIXELS (width_p
20080 ? window_box_width (it
->w
, TEXT_AREA
)
20081 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20083 if (align_to
&& *align_to
< 0)
20086 if (EQ (prop
, Qleft
))
20087 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20088 if (EQ (prop
, Qright
))
20089 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20090 if (EQ (prop
, Qcenter
))
20091 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20092 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20093 if (EQ (prop
, Qleft_fringe
))
20094 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20095 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20096 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20097 if (EQ (prop
, Qright_fringe
))
20098 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20099 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20100 : window_box_right_offset (it
->w
, TEXT_AREA
));
20101 if (EQ (prop
, Qleft_margin
))
20102 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20103 if (EQ (prop
, Qright_margin
))
20104 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20105 if (EQ (prop
, Qscroll_bar
))
20106 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20108 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20109 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20110 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20115 if (EQ (prop
, Qleft_fringe
))
20116 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20117 if (EQ (prop
, Qright_fringe
))
20118 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20119 if (EQ (prop
, Qleft_margin
))
20120 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20121 if (EQ (prop
, Qright_margin
))
20122 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20123 if (EQ (prop
, Qscroll_bar
))
20124 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20127 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20130 if (INTEGERP (prop
) || FLOATP (prop
))
20132 int base_unit
= (width_p
20133 ? FRAME_COLUMN_WIDTH (it
->f
)
20134 : FRAME_LINE_HEIGHT (it
->f
));
20135 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20140 Lisp_Object car
= XCAR (prop
);
20141 Lisp_Object cdr
= XCDR (prop
);
20145 #ifdef HAVE_WINDOW_SYSTEM
20146 if (FRAME_WINDOW_P (it
->f
)
20147 && valid_image_p (prop
))
20149 int id
= lookup_image (it
->f
, prop
);
20150 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20152 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20155 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20161 while (CONSP (cdr
))
20163 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20164 font
, width_p
, align_to
))
20167 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20172 if (EQ (car
, Qminus
))
20174 return OK_PIXELS (pixels
);
20177 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20180 if (INTEGERP (car
) || FLOATP (car
))
20183 pixels
= XFLOATINT (car
);
20185 return OK_PIXELS (pixels
);
20186 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20187 font
, width_p
, align_to
))
20188 return OK_PIXELS (pixels
* fact
);
20199 /***********************************************************************
20201 ***********************************************************************/
20203 #ifdef HAVE_WINDOW_SYSTEM
20208 dump_glyph_string (s
)
20209 struct glyph_string
*s
;
20211 fprintf (stderr
, "glyph string\n");
20212 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20213 s
->x
, s
->y
, s
->width
, s
->height
);
20214 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20215 fprintf (stderr
, " hl = %d\n", s
->hl
);
20216 fprintf (stderr
, " left overhang = %d, right = %d\n",
20217 s
->left_overhang
, s
->right_overhang
);
20218 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20219 fprintf (stderr
, " extends to end of line = %d\n",
20220 s
->extends_to_end_of_line_p
);
20221 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20222 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20225 #endif /* GLYPH_DEBUG */
20227 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20228 of XChar2b structures for S; it can't be allocated in
20229 init_glyph_string because it must be allocated via `alloca'. W
20230 is the window on which S is drawn. ROW and AREA are the glyph row
20231 and area within the row from which S is constructed. START is the
20232 index of the first glyph structure covered by S. HL is a
20233 face-override for drawing S. */
20236 #define OPTIONAL_HDC(hdc) hdc,
20237 #define DECLARE_HDC(hdc) HDC hdc;
20238 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20239 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20242 #ifndef OPTIONAL_HDC
20243 #define OPTIONAL_HDC(hdc)
20244 #define DECLARE_HDC(hdc)
20245 #define ALLOCATE_HDC(hdc, f)
20246 #define RELEASE_HDC(hdc, f)
20250 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
20251 struct glyph_string
*s
;
20255 struct glyph_row
*row
;
20256 enum glyph_row_area area
;
20258 enum draw_glyphs_face hl
;
20260 bzero (s
, sizeof *s
);
20262 s
->f
= XFRAME (w
->frame
);
20266 s
->display
= FRAME_X_DISPLAY (s
->f
);
20267 s
->window
= FRAME_X_WINDOW (s
->f
);
20268 s
->char2b
= char2b
;
20272 s
->first_glyph
= row
->glyphs
[area
] + start
;
20273 s
->height
= row
->height
;
20274 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20275 s
->ybase
= s
->y
+ row
->ascent
;
20279 /* Append the list of glyph strings with head H and tail T to the list
20280 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20283 append_glyph_string_lists (head
, tail
, h
, t
)
20284 struct glyph_string
**head
, **tail
;
20285 struct glyph_string
*h
, *t
;
20299 /* Prepend the list of glyph strings with head H and tail T to the
20300 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20304 prepend_glyph_string_lists (head
, tail
, h
, t
)
20305 struct glyph_string
**head
, **tail
;
20306 struct glyph_string
*h
, *t
;
20320 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20321 Set *HEAD and *TAIL to the resulting list. */
20324 append_glyph_string (head
, tail
, s
)
20325 struct glyph_string
**head
, **tail
;
20326 struct glyph_string
*s
;
20328 s
->next
= s
->prev
= NULL
;
20329 append_glyph_string_lists (head
, tail
, s
, s
);
20333 /* Get face and two-byte form of character C in face FACE_ID on frame
20334 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
20335 means we want to display multibyte text. DISPLAY_P non-zero means
20336 make sure that X resources for the face returned are allocated.
20337 Value is a pointer to a realized face that is ready for display if
20338 DISPLAY_P is non-zero. */
20340 static INLINE
struct face
*
20341 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
20345 int multibyte_p
, display_p
;
20347 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20351 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20353 if (code
!= FONT_INVALID_CODE
)
20354 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20356 STORE_XCHAR2B (char2b
, 0, 0);
20359 /* Make sure X resources of the face are allocated. */
20360 #ifdef HAVE_X_WINDOWS
20364 xassert (face
!= NULL
);
20365 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20372 /* Get face and two-byte form of character glyph GLYPH on frame F.
20373 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20374 a pointer to a realized face that is ready for display. */
20376 static INLINE
struct face
*
20377 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
20379 struct glyph
*glyph
;
20385 xassert (glyph
->type
== CHAR_GLYPH
);
20386 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20393 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20395 if (code
!= FONT_INVALID_CODE
)
20396 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20398 STORE_XCHAR2B (char2b
, 0, 0);
20401 /* Make sure X resources of the face are allocated. */
20402 xassert (face
!= NULL
);
20403 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20408 /* Fill glyph string S with composition components specified by S->cmp.
20410 BASE_FACE is the base face of the composition.
20411 S->cmp_from is the index of the first component for S.
20413 OVERLAPS non-zero means S should draw the foreground only, and use
20414 its physical height for clipping. See also draw_glyphs.
20416 Value is the index of a component not in S. */
20419 fill_composite_glyph_string (s
, base_face
, overlaps
)
20420 struct glyph_string
*s
;
20421 struct face
*base_face
;
20425 /* For all glyphs of this composition, starting at the offset
20426 S->cmp_from, until we reach the end of the definition or encounter a
20427 glyph that requires the different face, add it to S. */
20432 s
->for_overlaps
= overlaps
;
20435 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20437 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20441 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20444 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20445 s
->char2b
+ i
, 1, 1);
20451 s
->font
= s
->face
->font
;
20453 else if (s
->face
!= face
)
20461 /* All glyph strings for the same composition has the same width,
20462 i.e. the width set for the first component of the composition. */
20463 s
->width
= s
->first_glyph
->pixel_width
;
20465 /* If the specified font could not be loaded, use the frame's
20466 default font, but record the fact that we couldn't load it in
20467 the glyph string so that we can draw rectangles for the
20468 characters of the glyph string. */
20469 if (s
->font
== NULL
)
20471 s
->font_not_found_p
= 1;
20472 s
->font
= FRAME_FONT (s
->f
);
20475 /* Adjust base line for subscript/superscript text. */
20476 s
->ybase
+= s
->first_glyph
->voffset
;
20478 /* This glyph string must always be drawn with 16-bit functions. */
20485 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
20486 struct glyph_string
*s
;
20488 int start
, end
, overlaps
;
20490 struct glyph
*glyph
, *last
;
20491 Lisp_Object lgstring
;
20494 s
->for_overlaps
= overlaps
;
20495 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20496 last
= s
->row
->glyphs
[s
->area
] + end
;
20497 s
->cmp_id
= glyph
->u
.cmp
.id
;
20498 s
->cmp_from
= glyph
->u
.cmp
.from
;
20499 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
20500 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20501 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20502 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20504 while (glyph
< last
20505 && glyph
->u
.cmp
.automatic
20506 && glyph
->u
.cmp
.id
== s
->cmp_id
20507 && s
->cmp_to
== glyph
->u
.cmp
.from
)
20508 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
20510 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20512 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20513 unsigned code
= LGLYPH_CODE (lglyph
);
20515 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20517 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20518 return glyph
- s
->row
->glyphs
[s
->area
];
20522 /* Fill glyph string S from a sequence of character glyphs.
20524 FACE_ID is the face id of the string. START is the index of the
20525 first glyph to consider, END is the index of the last + 1.
20526 OVERLAPS non-zero means S should draw the foreground only, and use
20527 its physical height for clipping. See also draw_glyphs.
20529 Value is the index of the first glyph not in S. */
20532 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
20533 struct glyph_string
*s
;
20535 int start
, end
, overlaps
;
20537 struct glyph
*glyph
, *last
;
20539 int glyph_not_available_p
;
20541 xassert (s
->f
== XFRAME (s
->w
->frame
));
20542 xassert (s
->nchars
== 0);
20543 xassert (start
>= 0 && end
> start
);
20545 s
->for_overlaps
= overlaps
;
20546 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20547 last
= s
->row
->glyphs
[s
->area
] + end
;
20548 voffset
= glyph
->voffset
;
20549 s
->padding_p
= glyph
->padding_p
;
20550 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20552 while (glyph
< last
20553 && glyph
->type
== CHAR_GLYPH
20554 && glyph
->voffset
== voffset
20555 /* Same face id implies same font, nowadays. */
20556 && glyph
->face_id
== face_id
20557 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20561 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20562 s
->char2b
+ s
->nchars
,
20564 s
->two_byte_p
= two_byte_p
;
20566 xassert (s
->nchars
<= end
- start
);
20567 s
->width
+= glyph
->pixel_width
;
20568 if (glyph
++->padding_p
!= s
->padding_p
)
20572 s
->font
= s
->face
->font
;
20574 /* If the specified font could not be loaded, use the frame's font,
20575 but record the fact that we couldn't load it in
20576 S->font_not_found_p so that we can draw rectangles for the
20577 characters of the glyph string. */
20578 if (s
->font
== NULL
|| glyph_not_available_p
)
20580 s
->font_not_found_p
= 1;
20581 s
->font
= FRAME_FONT (s
->f
);
20584 /* Adjust base line for subscript/superscript text. */
20585 s
->ybase
+= voffset
;
20587 xassert (s
->face
&& s
->face
->gc
);
20588 return glyph
- s
->row
->glyphs
[s
->area
];
20592 /* Fill glyph string S from image glyph S->first_glyph. */
20595 fill_image_glyph_string (s
)
20596 struct glyph_string
*s
;
20598 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20599 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20601 s
->slice
= s
->first_glyph
->slice
;
20602 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20603 s
->font
= s
->face
->font
;
20604 s
->width
= s
->first_glyph
->pixel_width
;
20606 /* Adjust base line for subscript/superscript text. */
20607 s
->ybase
+= s
->first_glyph
->voffset
;
20611 /* Fill glyph string S from a sequence of stretch glyphs.
20613 ROW is the glyph row in which the glyphs are found, AREA is the
20614 area within the row. START is the index of the first glyph to
20615 consider, END is the index of the last + 1.
20617 Value is the index of the first glyph not in S. */
20620 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
20621 struct glyph_string
*s
;
20622 struct glyph_row
*row
;
20623 enum glyph_row_area area
;
20626 struct glyph
*glyph
, *last
;
20627 int voffset
, face_id
;
20629 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20631 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20632 last
= s
->row
->glyphs
[s
->area
] + end
;
20633 face_id
= glyph
->face_id
;
20634 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20635 s
->font
= s
->face
->font
;
20636 s
->width
= glyph
->pixel_width
;
20638 voffset
= glyph
->voffset
;
20642 && glyph
->type
== STRETCH_GLYPH
20643 && glyph
->voffset
== voffset
20644 && glyph
->face_id
== face_id
);
20646 s
->width
+= glyph
->pixel_width
;
20648 /* Adjust base line for subscript/superscript text. */
20649 s
->ybase
+= voffset
;
20651 /* The case that face->gc == 0 is handled when drawing the glyph
20652 string by calling PREPARE_FACE_FOR_DISPLAY. */
20654 return glyph
- s
->row
->glyphs
[s
->area
];
20657 static struct font_metrics
*
20658 get_per_char_metric (f
, font
, char2b
)
20663 static struct font_metrics metrics
;
20664 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20666 if (! font
|| code
== FONT_INVALID_CODE
)
20668 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20673 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20674 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20675 assumed to be zero. */
20678 x_get_glyph_overhangs (glyph
, f
, left
, right
)
20679 struct glyph
*glyph
;
20683 *left
= *right
= 0;
20685 if (glyph
->type
== CHAR_GLYPH
)
20689 struct font_metrics
*pcm
;
20691 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20692 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20694 if (pcm
->rbearing
> pcm
->width
)
20695 *right
= pcm
->rbearing
- pcm
->width
;
20696 if (pcm
->lbearing
< 0)
20697 *left
= -pcm
->lbearing
;
20700 else if (glyph
->type
== COMPOSITE_GLYPH
)
20702 if (! glyph
->u
.cmp
.automatic
)
20704 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20706 if (cmp
->rbearing
> cmp
->pixel_width
)
20707 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20708 if (cmp
->lbearing
< 0)
20709 *left
= - cmp
->lbearing
;
20713 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
20714 struct font_metrics metrics
;
20716 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
20717 glyph
->u
.cmp
.to
+ 1, &metrics
);
20718 if (metrics
.rbearing
> metrics
.width
)
20719 *right
= metrics
.rbearing
- metrics
.width
;
20720 if (metrics
.lbearing
< 0)
20721 *left
= - metrics
.lbearing
;
20727 /* Return the index of the first glyph preceding glyph string S that
20728 is overwritten by S because of S's left overhang. Value is -1
20729 if no glyphs are overwritten. */
20732 left_overwritten (s
)
20733 struct glyph_string
*s
;
20737 if (s
->left_overhang
)
20740 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20741 int first
= s
->first_glyph
- glyphs
;
20743 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
20744 x
-= glyphs
[i
].pixel_width
;
20755 /* Return the index of the first glyph preceding glyph string S that
20756 is overwriting S because of its right overhang. Value is -1 if no
20757 glyph in front of S overwrites S. */
20760 left_overwriting (s
)
20761 struct glyph_string
*s
;
20764 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20765 int first
= s
->first_glyph
- glyphs
;
20769 for (i
= first
- 1; i
>= 0; --i
)
20772 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20775 x
-= glyphs
[i
].pixel_width
;
20782 /* Return the index of the last glyph following glyph string S that is
20783 overwritten by S because of S's right overhang. Value is -1 if
20784 no such glyph is found. */
20787 right_overwritten (s
)
20788 struct glyph_string
*s
;
20792 if (s
->right_overhang
)
20795 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20796 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20797 int end
= s
->row
->used
[s
->area
];
20799 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
20800 x
+= glyphs
[i
].pixel_width
;
20809 /* Return the index of the last glyph following glyph string S that
20810 overwrites S because of its left overhang. Value is negative
20811 if no such glyph is found. */
20814 right_overwriting (s
)
20815 struct glyph_string
*s
;
20818 int end
= s
->row
->used
[s
->area
];
20819 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20820 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20824 for (i
= first
; i
< end
; ++i
)
20827 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20830 x
+= glyphs
[i
].pixel_width
;
20837 /* Set background width of glyph string S. START is the index of the
20838 first glyph following S. LAST_X is the right-most x-position + 1
20839 in the drawing area. */
20842 set_glyph_string_background_width (s
, start
, last_x
)
20843 struct glyph_string
*s
;
20847 /* If the face of this glyph string has to be drawn to the end of
20848 the drawing area, set S->extends_to_end_of_line_p. */
20850 if (start
== s
->row
->used
[s
->area
]
20851 && s
->area
== TEXT_AREA
20852 && ((s
->row
->fill_line_p
20853 && (s
->hl
== DRAW_NORMAL_TEXT
20854 || s
->hl
== DRAW_IMAGE_RAISED
20855 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20856 || s
->hl
== DRAW_MOUSE_FACE
))
20857 s
->extends_to_end_of_line_p
= 1;
20859 /* If S extends its face to the end of the line, set its
20860 background_width to the distance to the right edge of the drawing
20862 if (s
->extends_to_end_of_line_p
)
20863 s
->background_width
= last_x
- s
->x
+ 1;
20865 s
->background_width
= s
->width
;
20869 /* Compute overhangs and x-positions for glyph string S and its
20870 predecessors, or successors. X is the starting x-position for S.
20871 BACKWARD_P non-zero means process predecessors. */
20874 compute_overhangs_and_x (s
, x
, backward_p
)
20875 struct glyph_string
*s
;
20883 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20884 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20894 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20895 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20905 /* The following macros are only called from draw_glyphs below.
20906 They reference the following parameters of that function directly:
20907 `w', `row', `area', and `overlap_p'
20908 as well as the following local variables:
20909 `s', `f', and `hdc' (in W32) */
20912 /* On W32, silently add local `hdc' variable to argument list of
20913 init_glyph_string. */
20914 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20915 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20917 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20918 init_glyph_string (s, char2b, w, row, area, start, hl)
20921 /* Add a glyph string for a stretch glyph to the list of strings
20922 between HEAD and TAIL. START is the index of the stretch glyph in
20923 row area AREA of glyph row ROW. END is the index of the last glyph
20924 in that glyph row area. X is the current output position assigned
20925 to the new glyph string constructed. HL overrides that face of the
20926 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20927 is the right-most x-position of the drawing area. */
20929 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20930 and below -- keep them on one line. */
20931 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20934 s = (struct glyph_string *) alloca (sizeof *s); \
20935 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20936 START = fill_stretch_glyph_string (s, row, area, START, END); \
20937 append_glyph_string (&HEAD, &TAIL, s); \
20943 /* Add a glyph string for an image glyph to the list of strings
20944 between HEAD and TAIL. START is the index of the image glyph in
20945 row area AREA of glyph row ROW. END is the index of the last glyph
20946 in that glyph row area. X is the current output position assigned
20947 to the new glyph string constructed. HL overrides that face of the
20948 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20949 is the right-most x-position of the drawing area. */
20951 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20954 s = (struct glyph_string *) alloca (sizeof *s); \
20955 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20956 fill_image_glyph_string (s); \
20957 append_glyph_string (&HEAD, &TAIL, s); \
20964 /* Add a glyph string for a sequence of character glyphs to the list
20965 of strings between HEAD and TAIL. START is the index of the first
20966 glyph in row area AREA of glyph row ROW that is part of the new
20967 glyph string. END is the index of the last glyph in that glyph row
20968 area. X is the current output position assigned to the new glyph
20969 string constructed. HL overrides that face of the glyph; e.g. it
20970 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20971 right-most x-position of the drawing area. */
20973 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20979 face_id = (row)->glyphs[area][START].face_id; \
20981 s = (struct glyph_string *) alloca (sizeof *s); \
20982 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20983 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20984 append_glyph_string (&HEAD, &TAIL, s); \
20986 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20991 /* Add a glyph string for a composite sequence to the list of strings
20992 between HEAD and TAIL. START is the index of the first glyph in
20993 row area AREA of glyph row ROW that is part of the new glyph
20994 string. END is the index of the last glyph in that glyph row area.
20995 X is the current output position assigned to the new glyph string
20996 constructed. HL overrides that face of the glyph; e.g. it is
20997 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20998 x-position of the drawing area. */
21000 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21002 int face_id = (row)->glyphs[area][START].face_id; \
21003 struct face *base_face = FACE_FROM_ID (f, face_id); \
21004 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
21005 struct composition *cmp = composition_table[cmp_id]; \
21007 struct glyph_string *first_s; \
21010 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21012 /* Make glyph_strings for each glyph sequence that is drawable by \
21013 the same face, and append them to HEAD/TAIL. */ \
21014 for (n = 0; n < cmp->glyph_len;) \
21016 s = (struct glyph_string *) alloca (sizeof *s); \
21017 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21018 append_glyph_string (&(HEAD), &(TAIL), s); \
21024 n = fill_composite_glyph_string (s, base_face, overlaps); \
21032 /* Add a glyph string for a glyph-string sequence to the list of strings
21033 between HEAD and TAIL. */
21035 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21039 Lisp_Object gstring; \
21041 face_id = (row)->glyphs[area][START].face_id; \
21042 gstring = (composition_gstring_from_id \
21043 ((row)->glyphs[area][START].u.cmp.id)); \
21044 s = (struct glyph_string *) alloca (sizeof *s); \
21045 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21046 * LGSTRING_GLYPH_LEN (gstring)); \
21047 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21048 append_glyph_string (&(HEAD), &(TAIL), s); \
21050 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21054 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21055 of AREA of glyph row ROW on window W between indices START and END.
21056 HL overrides the face for drawing glyph strings, e.g. it is
21057 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21058 x-positions of the drawing area.
21060 This is an ugly monster macro construct because we must use alloca
21061 to allocate glyph strings (because draw_glyphs can be called
21062 asynchronously). */
21064 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21067 HEAD = TAIL = NULL; \
21068 while (START < END) \
21070 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21071 switch (first_glyph->type) \
21074 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21078 case COMPOSITE_GLYPH: \
21079 if (first_glyph->u.cmp.automatic) \
21080 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21083 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21087 case STRETCH_GLYPH: \
21088 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21092 case IMAGE_GLYPH: \
21093 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21103 set_glyph_string_background_width (s, START, LAST_X); \
21110 /* Draw glyphs between START and END in AREA of ROW on window W,
21111 starting at x-position X. X is relative to AREA in W. HL is a
21112 face-override with the following meaning:
21114 DRAW_NORMAL_TEXT draw normally
21115 DRAW_CURSOR draw in cursor face
21116 DRAW_MOUSE_FACE draw in mouse face.
21117 DRAW_INVERSE_VIDEO draw in mode line face
21118 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21119 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21121 If OVERLAPS is non-zero, draw only the foreground of characters and
21122 clip to the physical height of ROW. Non-zero value also defines
21123 the overlapping part to be drawn:
21125 OVERLAPS_PRED overlap with preceding rows
21126 OVERLAPS_SUCC overlap with succeeding rows
21127 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21128 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21130 Value is the x-position reached, relative to AREA of W. */
21133 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
21136 struct glyph_row
*row
;
21137 enum glyph_row_area area
;
21138 EMACS_INT start
, end
;
21139 enum draw_glyphs_face hl
;
21142 struct glyph_string
*head
, *tail
;
21143 struct glyph_string
*s
;
21144 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21145 int i
, j
, x_reached
, last_x
, area_left
= 0;
21146 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21149 ALLOCATE_HDC (hdc
, f
);
21151 /* Let's rather be paranoid than getting a SEGV. */
21152 end
= min (end
, row
->used
[area
]);
21153 start
= max (0, start
);
21154 start
= min (end
, start
);
21156 /* Translate X to frame coordinates. Set last_x to the right
21157 end of the drawing area. */
21158 if (row
->full_width_p
)
21160 /* X is relative to the left edge of W, without scroll bars
21162 area_left
= WINDOW_LEFT_EDGE_X (w
);
21163 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21167 area_left
= window_box_left (w
, area
);
21168 last_x
= area_left
+ window_box_width (w
, area
);
21172 /* Build a doubly-linked list of glyph_string structures between
21173 head and tail from what we have to draw. Note that the macro
21174 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21175 the reason we use a separate variable `i'. */
21177 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21179 x_reached
= tail
->x
+ tail
->background_width
;
21183 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21184 the row, redraw some glyphs in front or following the glyph
21185 strings built above. */
21186 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21188 struct glyph_string
*h
, *t
;
21189 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21190 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
21193 /* If mouse highlighting is on, we may need to draw adjacent
21194 glyphs using mouse-face highlighting. */
21195 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21197 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21199 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21200 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21202 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21204 check_mouse_face
= 1;
21205 mouse_beg_col
= (row
== mouse_beg_row
)
21206 ? dpyinfo
->mouse_face_beg_col
: 0;
21207 mouse_end_col
= (row
== mouse_end_row
)
21208 ? dpyinfo
->mouse_face_end_col
21209 : row
->used
[TEXT_AREA
];
21213 /* Compute overhangs for all glyph strings. */
21214 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21215 for (s
= head
; s
; s
= s
->next
)
21216 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21218 /* Prepend glyph strings for glyphs in front of the first glyph
21219 string that are overwritten because of the first glyph
21220 string's left overhang. The background of all strings
21221 prepended must be drawn because the first glyph string
21223 i
= left_overwritten (head
);
21226 enum draw_glyphs_face overlap_hl
;
21228 /* If this row contains mouse highlighting, attempt to draw
21229 the overlapped glyphs with the correct highlight. This
21230 code fails if the overlap encompasses more than one glyph
21231 and mouse-highlight spans only some of these glyphs.
21232 However, making it work perfectly involves a lot more
21233 code, and I don't know if the pathological case occurs in
21234 practice, so we'll stick to this for now. --- cyd */
21235 if (check_mouse_face
21236 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21237 overlap_hl
= DRAW_MOUSE_FACE
;
21239 overlap_hl
= DRAW_NORMAL_TEXT
;
21242 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21243 overlap_hl
, dummy_x
, last_x
);
21245 compute_overhangs_and_x (t
, head
->x
, 1);
21246 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21250 /* Prepend glyph strings for glyphs in front of the first glyph
21251 string that overwrite that glyph string because of their
21252 right overhang. For these strings, only the foreground must
21253 be drawn, because it draws over the glyph string at `head'.
21254 The background must not be drawn because this would overwrite
21255 right overhangs of preceding glyphs for which no glyph
21257 i
= left_overwriting (head
);
21260 enum draw_glyphs_face overlap_hl
;
21262 if (check_mouse_face
21263 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21264 overlap_hl
= DRAW_MOUSE_FACE
;
21266 overlap_hl
= DRAW_NORMAL_TEXT
;
21269 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21270 overlap_hl
, dummy_x
, last_x
);
21271 for (s
= h
; s
; s
= s
->next
)
21272 s
->background_filled_p
= 1;
21273 compute_overhangs_and_x (t
, head
->x
, 1);
21274 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21277 /* Append glyphs strings for glyphs following the last glyph
21278 string tail that are overwritten by tail. The background of
21279 these strings has to be drawn because tail's foreground draws
21281 i
= right_overwritten (tail
);
21284 enum draw_glyphs_face overlap_hl
;
21286 if (check_mouse_face
21287 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21288 overlap_hl
= DRAW_MOUSE_FACE
;
21290 overlap_hl
= DRAW_NORMAL_TEXT
;
21292 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21293 overlap_hl
, x
, last_x
);
21294 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21295 we don't have `end = i;' here. */
21296 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21297 append_glyph_string_lists (&head
, &tail
, h
, t
);
21301 /* Append glyph strings for glyphs following the last glyph
21302 string tail that overwrite tail. The foreground of such
21303 glyphs has to be drawn because it writes into the background
21304 of tail. The background must not be drawn because it could
21305 paint over the foreground of following glyphs. */
21306 i
= right_overwriting (tail
);
21309 enum draw_glyphs_face overlap_hl
;
21310 if (check_mouse_face
21311 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21312 overlap_hl
= DRAW_MOUSE_FACE
;
21314 overlap_hl
= DRAW_NORMAL_TEXT
;
21317 i
++; /* We must include the Ith glyph. */
21318 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21319 overlap_hl
, x
, last_x
);
21320 for (s
= h
; s
; s
= s
->next
)
21321 s
->background_filled_p
= 1;
21322 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21323 append_glyph_string_lists (&head
, &tail
, h
, t
);
21325 if (clip_head
|| clip_tail
)
21326 for (s
= head
; s
; s
= s
->next
)
21328 s
->clip_head
= clip_head
;
21329 s
->clip_tail
= clip_tail
;
21333 /* Draw all strings. */
21334 for (s
= head
; s
; s
= s
->next
)
21335 FRAME_RIF (f
)->draw_glyph_string (s
);
21338 /* When focus a sole frame and move horizontally, this sets on_p to 0
21339 causing a failure to erase prev cursor position. */
21340 if (area
== TEXT_AREA
21341 && !row
->full_width_p
21342 /* When drawing overlapping rows, only the glyph strings'
21343 foreground is drawn, which doesn't erase a cursor
21347 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21348 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21349 : (tail
? tail
->x
+ tail
->background_width
: x
));
21353 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21354 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21358 /* Value is the x-position up to which drawn, relative to AREA of W.
21359 This doesn't include parts drawn because of overhangs. */
21360 if (row
->full_width_p
)
21361 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21363 x_reached
-= area_left
;
21365 RELEASE_HDC (hdc
, f
);
21370 /* Expand row matrix if too narrow. Don't expand if area
21373 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21375 if (!fonts_changed_p \
21376 && (it->glyph_row->glyphs[area] \
21377 < it->glyph_row->glyphs[area + 1])) \
21379 it->w->ncols_scale_factor++; \
21380 fonts_changed_p = 1; \
21384 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21385 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21391 struct glyph
*glyph
;
21392 enum glyph_row_area area
= it
->area
;
21394 xassert (it
->glyph_row
);
21395 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21397 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21398 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21400 /* If the glyph row is reversed, we need to prepend the glyph
21401 rather than append it. */
21402 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21406 /* Make room for the additional glyph. */
21407 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21409 glyph
= it
->glyph_row
->glyphs
[area
];
21411 glyph
->charpos
= CHARPOS (it
->position
);
21412 glyph
->object
= it
->object
;
21413 if (it
->pixel_width
> 0)
21415 glyph
->pixel_width
= it
->pixel_width
;
21416 glyph
->padding_p
= 0;
21420 /* Assure at least 1-pixel width. Otherwise, cursor can't
21421 be displayed correctly. */
21422 glyph
->pixel_width
= 1;
21423 glyph
->padding_p
= 1;
21425 glyph
->ascent
= it
->ascent
;
21426 glyph
->descent
= it
->descent
;
21427 glyph
->voffset
= it
->voffset
;
21428 glyph
->type
= CHAR_GLYPH
;
21429 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21430 glyph
->multibyte_p
= it
->multibyte_p
;
21431 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21432 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21433 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21434 || it
->phys_descent
> it
->descent
);
21435 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21436 glyph
->face_id
= it
->face_id
;
21437 glyph
->u
.ch
= it
->char_to_display
;
21438 glyph
->slice
= null_glyph_slice
;
21439 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21442 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21443 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21445 glyph
->bidi_type
= it
->bidi_it
.type
;
21449 glyph
->resolved_level
= 0;
21450 glyph
->bidi_type
= UNKNOWN_BT
;
21452 ++it
->glyph_row
->used
[area
];
21455 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21458 /* Store one glyph for the composition IT->cmp_it.id in
21459 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21463 append_composite_glyph (it
)
21466 struct glyph
*glyph
;
21467 enum glyph_row_area area
= it
->area
;
21469 xassert (it
->glyph_row
);
21471 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21472 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21474 glyph
->charpos
= CHARPOS (it
->position
);
21475 glyph
->object
= it
->object
;
21476 glyph
->pixel_width
= it
->pixel_width
;
21477 glyph
->ascent
= it
->ascent
;
21478 glyph
->descent
= it
->descent
;
21479 glyph
->voffset
= it
->voffset
;
21480 glyph
->type
= COMPOSITE_GLYPH
;
21481 if (it
->cmp_it
.ch
< 0)
21483 glyph
->u
.cmp
.automatic
= 0;
21484 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21488 glyph
->u
.cmp
.automatic
= 1;
21489 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21490 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
21491 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
21493 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21494 glyph
->multibyte_p
= it
->multibyte_p
;
21495 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21496 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21497 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21498 || it
->phys_descent
> it
->descent
);
21499 glyph
->padding_p
= 0;
21500 glyph
->glyph_not_available_p
= 0;
21501 glyph
->face_id
= it
->face_id
;
21502 glyph
->slice
= null_glyph_slice
;
21503 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21506 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21507 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21509 glyph
->bidi_type
= it
->bidi_it
.type
;
21511 ++it
->glyph_row
->used
[area
];
21514 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21518 /* Change IT->ascent and IT->height according to the setting of
21522 take_vertical_position_into_account (it
)
21527 if (it
->voffset
< 0)
21528 /* Increase the ascent so that we can display the text higher
21530 it
->ascent
-= it
->voffset
;
21532 /* Increase the descent so that we can display the text lower
21534 it
->descent
+= it
->voffset
;
21539 /* Produce glyphs/get display metrics for the image IT is loaded with.
21540 See the description of struct display_iterator in dispextern.h for
21541 an overview of struct display_iterator. */
21544 produce_image_glyph (it
)
21549 int glyph_ascent
, crop
;
21550 struct glyph_slice slice
;
21552 xassert (it
->what
== IT_IMAGE
);
21554 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21556 /* Make sure X resources of the face is loaded. */
21557 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21559 if (it
->image_id
< 0)
21561 /* Fringe bitmap. */
21562 it
->ascent
= it
->phys_ascent
= 0;
21563 it
->descent
= it
->phys_descent
= 0;
21564 it
->pixel_width
= 0;
21569 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21571 /* Make sure X resources of the image is loaded. */
21572 prepare_image_for_display (it
->f
, img
);
21574 slice
.x
= slice
.y
= 0;
21575 slice
.width
= img
->width
;
21576 slice
.height
= img
->height
;
21578 if (INTEGERP (it
->slice
.x
))
21579 slice
.x
= XINT (it
->slice
.x
);
21580 else if (FLOATP (it
->slice
.x
))
21581 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21583 if (INTEGERP (it
->slice
.y
))
21584 slice
.y
= XINT (it
->slice
.y
);
21585 else if (FLOATP (it
->slice
.y
))
21586 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21588 if (INTEGERP (it
->slice
.width
))
21589 slice
.width
= XINT (it
->slice
.width
);
21590 else if (FLOATP (it
->slice
.width
))
21591 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21593 if (INTEGERP (it
->slice
.height
))
21594 slice
.height
= XINT (it
->slice
.height
);
21595 else if (FLOATP (it
->slice
.height
))
21596 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21598 if (slice
.x
>= img
->width
)
21599 slice
.x
= img
->width
;
21600 if (slice
.y
>= img
->height
)
21601 slice
.y
= img
->height
;
21602 if (slice
.x
+ slice
.width
>= img
->width
)
21603 slice
.width
= img
->width
- slice
.x
;
21604 if (slice
.y
+ slice
.height
> img
->height
)
21605 slice
.height
= img
->height
- slice
.y
;
21607 if (slice
.width
== 0 || slice
.height
== 0)
21610 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21612 it
->descent
= slice
.height
- glyph_ascent
;
21614 it
->descent
+= img
->vmargin
;
21615 if (slice
.y
+ slice
.height
== img
->height
)
21616 it
->descent
+= img
->vmargin
;
21617 it
->phys_descent
= it
->descent
;
21619 it
->pixel_width
= slice
.width
;
21621 it
->pixel_width
+= img
->hmargin
;
21622 if (slice
.x
+ slice
.width
== img
->width
)
21623 it
->pixel_width
+= img
->hmargin
;
21625 /* It's quite possible for images to have an ascent greater than
21626 their height, so don't get confused in that case. */
21627 if (it
->descent
< 0)
21632 if (face
->box
!= FACE_NO_BOX
)
21634 if (face
->box_line_width
> 0)
21637 it
->ascent
+= face
->box_line_width
;
21638 if (slice
.y
+ slice
.height
== img
->height
)
21639 it
->descent
+= face
->box_line_width
;
21642 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21643 it
->pixel_width
+= eabs (face
->box_line_width
);
21644 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21645 it
->pixel_width
+= eabs (face
->box_line_width
);
21648 take_vertical_position_into_account (it
);
21650 /* Automatically crop wide image glyphs at right edge so we can
21651 draw the cursor on same display row. */
21652 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21653 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21655 it
->pixel_width
-= crop
;
21656 slice
.width
-= crop
;
21661 struct glyph
*glyph
;
21662 enum glyph_row_area area
= it
->area
;
21664 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21665 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21667 glyph
->charpos
= CHARPOS (it
->position
);
21668 glyph
->object
= it
->object
;
21669 glyph
->pixel_width
= it
->pixel_width
;
21670 glyph
->ascent
= glyph_ascent
;
21671 glyph
->descent
= it
->descent
;
21672 glyph
->voffset
= it
->voffset
;
21673 glyph
->type
= IMAGE_GLYPH
;
21674 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21675 glyph
->multibyte_p
= it
->multibyte_p
;
21676 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21677 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21678 glyph
->overlaps_vertically_p
= 0;
21679 glyph
->padding_p
= 0;
21680 glyph
->glyph_not_available_p
= 0;
21681 glyph
->face_id
= it
->face_id
;
21682 glyph
->u
.img_id
= img
->id
;
21683 glyph
->slice
= slice
;
21684 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21687 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21688 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21690 glyph
->bidi_type
= it
->bidi_it
.type
;
21692 ++it
->glyph_row
->used
[area
];
21695 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21700 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
21701 of the glyph, WIDTH and HEIGHT are the width and height of the
21702 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
21705 append_stretch_glyph (it
, object
, width
, height
, ascent
)
21707 Lisp_Object object
;
21711 struct glyph
*glyph
;
21712 enum glyph_row_area area
= it
->area
;
21714 xassert (ascent
>= 0 && ascent
<= height
);
21716 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21717 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21719 /* If the glyph row is reversed, we need to prepend the glyph
21720 rather than append it. */
21721 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21725 /* Make room for the additional glyph. */
21726 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21728 glyph
= it
->glyph_row
->glyphs
[area
];
21730 glyph
->charpos
= CHARPOS (it
->position
);
21731 glyph
->object
= object
;
21732 glyph
->pixel_width
= width
;
21733 glyph
->ascent
= ascent
;
21734 glyph
->descent
= height
- ascent
;
21735 glyph
->voffset
= it
->voffset
;
21736 glyph
->type
= STRETCH_GLYPH
;
21737 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21738 glyph
->multibyte_p
= it
->multibyte_p
;
21739 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21740 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21741 glyph
->overlaps_vertically_p
= 0;
21742 glyph
->padding_p
= 0;
21743 glyph
->glyph_not_available_p
= 0;
21744 glyph
->face_id
= it
->face_id
;
21745 glyph
->u
.stretch
.ascent
= ascent
;
21746 glyph
->u
.stretch
.height
= height
;
21747 glyph
->slice
= null_glyph_slice
;
21748 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21751 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21752 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21754 glyph
->bidi_type
= it
->bidi_it
.type
;
21758 glyph
->resolved_level
= 0;
21759 glyph
->bidi_type
= UNKNOWN_BT
;
21761 ++it
->glyph_row
->used
[area
];
21764 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21768 /* Produce a stretch glyph for iterator IT. IT->object is the value
21769 of the glyph property displayed. The value must be a list
21770 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
21773 1. `:width WIDTH' specifies that the space should be WIDTH *
21774 canonical char width wide. WIDTH may be an integer or floating
21777 2. `:relative-width FACTOR' specifies that the width of the stretch
21778 should be computed from the width of the first character having the
21779 `glyph' property, and should be FACTOR times that width.
21781 3. `:align-to HPOS' specifies that the space should be wide enough
21782 to reach HPOS, a value in canonical character units.
21784 Exactly one of the above pairs must be present.
21786 4. `:height HEIGHT' specifies that the height of the stretch produced
21787 should be HEIGHT, measured in canonical character units.
21789 5. `:relative-height FACTOR' specifies that the height of the
21790 stretch should be FACTOR times the height of the characters having
21791 the glyph property.
21793 Either none or exactly one of 4 or 5 must be present.
21795 6. `:ascent ASCENT' specifies that ASCENT percent of the height
21796 of the stretch should be used for the ascent of the stretch.
21797 ASCENT must be in the range 0 <= ASCENT <= 100. */
21800 produce_stretch_glyph (it
)
21803 /* (space :width WIDTH :height HEIGHT ...) */
21804 Lisp_Object prop
, plist
;
21805 int width
= 0, height
= 0, align_to
= -1;
21806 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
21809 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21810 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
21812 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21814 /* List should start with `space'. */
21815 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
21816 plist
= XCDR (it
->object
);
21818 /* Compute the width of the stretch. */
21819 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
21820 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
21822 /* Absolute width `:width WIDTH' specified and valid. */
21823 zero_width_ok_p
= 1;
21826 else if (prop
= Fplist_get (plist
, QCrelative_width
),
21829 /* Relative width `:relative-width FACTOR' specified and valid.
21830 Compute the width of the characters having the `glyph'
21833 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
21836 if (it
->multibyte_p
)
21838 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
21839 - IT_BYTEPOS (*it
));
21840 it2
.c
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
21843 it2
.c
= *p
, it2
.len
= 1;
21845 it2
.glyph_row
= NULL
;
21846 it2
.what
= IT_CHARACTER
;
21847 x_produce_glyphs (&it2
);
21848 width
= NUMVAL (prop
) * it2
.pixel_width
;
21850 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
21851 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
21853 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
21854 align_to
= (align_to
< 0
21856 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
21857 else if (align_to
< 0)
21858 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
21859 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
21860 zero_width_ok_p
= 1;
21863 /* Nothing specified -> width defaults to canonical char width. */
21864 width
= FRAME_COLUMN_WIDTH (it
->f
);
21866 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
21869 /* Compute height. */
21870 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
21871 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21874 zero_height_ok_p
= 1;
21876 else if (prop
= Fplist_get (plist
, QCrelative_height
),
21878 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
21880 height
= FONT_HEIGHT (font
);
21882 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
21885 /* Compute percentage of height used for ascent. If
21886 `:ascent ASCENT' is present and valid, use that. Otherwise,
21887 derive the ascent from the font in use. */
21888 if (prop
= Fplist_get (plist
, QCascent
),
21889 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
21890 ascent
= height
* NUMVAL (prop
) / 100.0;
21891 else if (!NILP (prop
)
21892 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21893 ascent
= min (max (0, (int)tem
), height
);
21895 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
21897 if (width
> 0 && it
->line_wrap
!= TRUNCATE
21898 && it
->current_x
+ width
> it
->last_visible_x
)
21899 width
= it
->last_visible_x
- it
->current_x
- 1;
21901 if (width
> 0 && height
> 0 && it
->glyph_row
)
21903 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
21904 if (!STRINGP (object
))
21905 object
= it
->w
->buffer
;
21906 append_stretch_glyph (it
, object
, width
, height
, ascent
);
21909 it
->pixel_width
= width
;
21910 it
->ascent
= it
->phys_ascent
= ascent
;
21911 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
21912 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21914 take_vertical_position_into_account (it
);
21917 /* Calculate line-height and line-spacing properties.
21918 An integer value specifies explicit pixel value.
21919 A float value specifies relative value to current face height.
21920 A cons (float . face-name) specifies relative value to
21921 height of specified face font.
21923 Returns height in pixels, or nil. */
21927 calc_line_height_property (it
, val
, font
, boff
, override
)
21931 int boff
, override
;
21933 Lisp_Object face_name
= Qnil
;
21934 int ascent
, descent
, height
;
21936 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21941 face_name
= XCAR (val
);
21943 if (!NUMBERP (val
))
21944 val
= make_number (1);
21945 if (NILP (face_name
))
21947 height
= it
->ascent
+ it
->descent
;
21952 if (NILP (face_name
))
21954 font
= FRAME_FONT (it
->f
);
21955 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21957 else if (EQ (face_name
, Qt
))
21966 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21968 return make_number (-1);
21970 face
= FACE_FROM_ID (it
->f
, face_id
);
21973 return make_number (-1);
21974 boff
= font
->baseline_offset
;
21975 if (font
->vertical_centering
)
21976 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21979 ascent
= FONT_BASE (font
) + boff
;
21980 descent
= FONT_DESCENT (font
) - boff
;
21984 it
->override_ascent
= ascent
;
21985 it
->override_descent
= descent
;
21986 it
->override_boff
= boff
;
21989 height
= ascent
+ descent
;
21993 height
= (int)(XFLOAT_DATA (val
) * height
);
21994 else if (INTEGERP (val
))
21995 height
*= XINT (val
);
21997 return make_number (height
);
22002 Produce glyphs/get display metrics for the display element IT is
22003 loaded with. See the description of struct it in dispextern.h
22004 for an overview of struct it. */
22007 x_produce_glyphs (it
)
22010 int extra_line_spacing
= it
->extra_line_spacing
;
22012 it
->glyph_not_available_p
= 0;
22014 if (it
->what
== IT_CHARACTER
)
22018 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22019 struct font_metrics
*pcm
;
22020 int font_not_found_p
;
22021 int boff
; /* baseline offset */
22022 /* We may change it->multibyte_p upon unibyte<->multibyte
22023 conversion. So, save the current value now and restore it
22026 Note: It seems that we don't have to record multibyte_p in
22027 struct glyph because the character code itself tells whether
22028 or not the character is multibyte. Thus, in the future, we
22029 must consider eliminating the field `multibyte_p' in the
22031 int saved_multibyte_p
= it
->multibyte_p
;
22033 /* Maybe translate single-byte characters to multibyte, or the
22035 it
->char_to_display
= it
->c
;
22036 if (!ASCII_BYTE_P (it
->c
)
22037 && ! it
->multibyte_p
)
22039 if (SINGLE_BYTE_CHAR_P (it
->c
)
22040 && unibyte_display_via_language_environment
)
22042 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
22044 /* get_next_display_element assures that this decoding
22046 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
22047 it
->multibyte_p
= 1;
22048 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
22050 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22054 /* Get font to use. Encode IT->char_to_display. */
22055 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
22056 &char2b
, it
->multibyte_p
, 0);
22059 font_not_found_p
= font
== NULL
;
22060 if (font_not_found_p
)
22062 /* When no suitable font found, display an empty box based
22063 on the metrics of the font of the default face (or what
22065 struct face
*no_font_face
22066 = FACE_FROM_ID (it
->f
,
22067 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
22068 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
22069 font
= no_font_face
->font
;
22070 boff
= font
->baseline_offset
;
22074 boff
= font
->baseline_offset
;
22075 if (font
->vertical_centering
)
22076 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22079 if (it
->char_to_display
>= ' '
22080 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
22082 /* Either unibyte or ASCII. */
22087 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22089 if (it
->override_ascent
>= 0)
22091 it
->ascent
= it
->override_ascent
;
22092 it
->descent
= it
->override_descent
;
22093 boff
= it
->override_boff
;
22097 it
->ascent
= FONT_BASE (font
) + boff
;
22098 it
->descent
= FONT_DESCENT (font
) - boff
;
22103 it
->phys_ascent
= pcm
->ascent
+ boff
;
22104 it
->phys_descent
= pcm
->descent
- boff
;
22105 it
->pixel_width
= pcm
->width
;
22109 it
->glyph_not_available_p
= 1;
22110 it
->phys_ascent
= it
->ascent
;
22111 it
->phys_descent
= it
->descent
;
22112 it
->pixel_width
= FONT_WIDTH (font
);
22115 if (it
->constrain_row_ascent_descent_p
)
22117 if (it
->descent
> it
->max_descent
)
22119 it
->ascent
+= it
->descent
- it
->max_descent
;
22120 it
->descent
= it
->max_descent
;
22122 if (it
->ascent
> it
->max_ascent
)
22124 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22125 it
->ascent
= it
->max_ascent
;
22127 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22128 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22129 extra_line_spacing
= 0;
22132 /* If this is a space inside a region of text with
22133 `space-width' property, change its width. */
22134 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22136 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22138 /* If face has a box, add the box thickness to the character
22139 height. If character has a box line to the left and/or
22140 right, add the box line width to the character's width. */
22141 if (face
->box
!= FACE_NO_BOX
)
22143 int thick
= face
->box_line_width
;
22147 it
->ascent
+= thick
;
22148 it
->descent
+= thick
;
22153 if (it
->start_of_box_run_p
)
22154 it
->pixel_width
+= thick
;
22155 if (it
->end_of_box_run_p
)
22156 it
->pixel_width
+= thick
;
22159 /* If face has an overline, add the height of the overline
22160 (1 pixel) and a 1 pixel margin to the character height. */
22161 if (face
->overline_p
)
22162 it
->ascent
+= overline_margin
;
22164 if (it
->constrain_row_ascent_descent_p
)
22166 if (it
->ascent
> it
->max_ascent
)
22167 it
->ascent
= it
->max_ascent
;
22168 if (it
->descent
> it
->max_descent
)
22169 it
->descent
= it
->max_descent
;
22172 take_vertical_position_into_account (it
);
22174 /* If we have to actually produce glyphs, do it. */
22179 /* Translate a space with a `space-width' property
22180 into a stretch glyph. */
22181 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22182 / FONT_HEIGHT (font
));
22183 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22184 it
->ascent
+ it
->descent
, ascent
);
22189 /* If characters with lbearing or rbearing are displayed
22190 in this line, record that fact in a flag of the
22191 glyph row. This is used to optimize X output code. */
22192 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22193 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22195 if (! stretched_p
&& it
->pixel_width
== 0)
22196 /* We assure that all visible glyphs have at least 1-pixel
22198 it
->pixel_width
= 1;
22200 else if (it
->char_to_display
== '\n')
22202 /* A newline has no width, but we need the height of the
22203 line. But if previous part of the line sets a height,
22204 don't increase that height */
22206 Lisp_Object height
;
22207 Lisp_Object total_height
= Qnil
;
22209 it
->override_ascent
= -1;
22210 it
->pixel_width
= 0;
22213 height
= get_it_property(it
, Qline_height
);
22214 /* Split (line-height total-height) list */
22216 && CONSP (XCDR (height
))
22217 && NILP (XCDR (XCDR (height
))))
22219 total_height
= XCAR (XCDR (height
));
22220 height
= XCAR (height
);
22222 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
22224 if (it
->override_ascent
>= 0)
22226 it
->ascent
= it
->override_ascent
;
22227 it
->descent
= it
->override_descent
;
22228 boff
= it
->override_boff
;
22232 it
->ascent
= FONT_BASE (font
) + boff
;
22233 it
->descent
= FONT_DESCENT (font
) - boff
;
22236 if (EQ (height
, Qt
))
22238 if (it
->descent
> it
->max_descent
)
22240 it
->ascent
+= it
->descent
- it
->max_descent
;
22241 it
->descent
= it
->max_descent
;
22243 if (it
->ascent
> it
->max_ascent
)
22245 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22246 it
->ascent
= it
->max_ascent
;
22248 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22249 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22250 it
->constrain_row_ascent_descent_p
= 1;
22251 extra_line_spacing
= 0;
22255 Lisp_Object spacing
;
22257 it
->phys_ascent
= it
->ascent
;
22258 it
->phys_descent
= it
->descent
;
22260 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22261 && face
->box
!= FACE_NO_BOX
22262 && face
->box_line_width
> 0)
22264 it
->ascent
+= face
->box_line_width
;
22265 it
->descent
+= face
->box_line_width
;
22268 && XINT (height
) > it
->ascent
+ it
->descent
)
22269 it
->ascent
= XINT (height
) - it
->descent
;
22271 if (!NILP (total_height
))
22272 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
22275 spacing
= get_it_property(it
, Qline_spacing
);
22276 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
22278 if (INTEGERP (spacing
))
22280 extra_line_spacing
= XINT (spacing
);
22281 if (!NILP (total_height
))
22282 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22286 else if (it
->char_to_display
== '\t')
22288 if (font
->space_width
> 0)
22290 int tab_width
= it
->tab_width
* font
->space_width
;
22291 int x
= it
->current_x
+ it
->continuation_lines_width
;
22292 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22294 /* If the distance from the current position to the next tab
22295 stop is less than a space character width, use the
22296 tab stop after that. */
22297 if (next_tab_x
- x
< font
->space_width
)
22298 next_tab_x
+= tab_width
;
22300 it
->pixel_width
= next_tab_x
- x
;
22302 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22303 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22307 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22308 it
->ascent
+ it
->descent
, it
->ascent
);
22313 it
->pixel_width
= 0;
22319 /* A multi-byte character. Assume that the display width of the
22320 character is the width of the character multiplied by the
22321 width of the font. */
22323 /* If we found a font, this font should give us the right
22324 metrics. If we didn't find a font, use the frame's
22325 default font and calculate the width of the character by
22326 multiplying the width of font by the width of the
22329 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22331 if (font_not_found_p
|| !pcm
)
22333 int char_width
= CHAR_WIDTH (it
->char_to_display
);
22335 if (char_width
== 0)
22336 /* This is a non spacing character. But, as we are
22337 going to display an empty box, the box must occupy
22338 at least one column. */
22340 it
->glyph_not_available_p
= 1;
22341 it
->pixel_width
= font
->space_width
* char_width
;
22342 it
->phys_ascent
= FONT_BASE (font
) + boff
;
22343 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22347 it
->pixel_width
= pcm
->width
;
22348 it
->phys_ascent
= pcm
->ascent
+ boff
;
22349 it
->phys_descent
= pcm
->descent
- boff
;
22351 && (pcm
->lbearing
< 0
22352 || pcm
->rbearing
> pcm
->width
))
22353 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22356 it
->ascent
= FONT_BASE (font
) + boff
;
22357 it
->descent
= FONT_DESCENT (font
) - boff
;
22358 if (face
->box
!= FACE_NO_BOX
)
22360 int thick
= face
->box_line_width
;
22364 it
->ascent
+= thick
;
22365 it
->descent
+= thick
;
22370 if (it
->start_of_box_run_p
)
22371 it
->pixel_width
+= thick
;
22372 if (it
->end_of_box_run_p
)
22373 it
->pixel_width
+= thick
;
22376 /* If face has an overline, add the height of the overline
22377 (1 pixel) and a 1 pixel margin to the character height. */
22378 if (face
->overline_p
)
22379 it
->ascent
+= overline_margin
;
22381 take_vertical_position_into_account (it
);
22383 if (it
->ascent
< 0)
22385 if (it
->descent
< 0)
22390 if (it
->pixel_width
== 0)
22391 /* We assure that all visible glyphs have at least 1-pixel
22393 it
->pixel_width
= 1;
22395 it
->multibyte_p
= saved_multibyte_p
;
22397 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22399 /* A static composition.
22401 Note: A composition is represented as one glyph in the
22402 glyph matrix. There are no padding glyphs.
22404 Important note: pixel_width, ascent, and descent are the
22405 values of what is drawn by draw_glyphs (i.e. the values of
22406 the overall glyphs composed). */
22407 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22408 int boff
; /* baseline offset */
22409 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22410 int glyph_len
= cmp
->glyph_len
;
22411 struct font
*font
= face
->font
;
22415 /* If we have not yet calculated pixel size data of glyphs of
22416 the composition for the current face font, calculate them
22417 now. Theoretically, we have to check all fonts for the
22418 glyphs, but that requires much time and memory space. So,
22419 here we check only the font of the first glyph. This may
22420 lead to incorrect display, but it's very rare, and C-l
22421 (recenter-top-bottom) can correct the display anyway. */
22422 if (! cmp
->font
|| cmp
->font
!= font
)
22424 /* Ascent and descent of the font of the first character
22425 of this composition (adjusted by baseline offset).
22426 Ascent and descent of overall glyphs should not be less
22427 than these, respectively. */
22428 int font_ascent
, font_descent
, font_height
;
22429 /* Bounding box of the overall glyphs. */
22430 int leftmost
, rightmost
, lowest
, highest
;
22431 int lbearing
, rbearing
;
22432 int i
, width
, ascent
, descent
;
22433 int left_padded
= 0, right_padded
= 0;
22436 struct font_metrics
*pcm
;
22437 int font_not_found_p
;
22440 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22441 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22443 if (glyph_len
< cmp
->glyph_len
)
22445 for (i
= 0; i
< glyph_len
; i
++)
22447 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22449 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22454 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22455 : IT_CHARPOS (*it
));
22456 /* If no suitable font is found, use the default font. */
22457 font_not_found_p
= font
== NULL
;
22458 if (font_not_found_p
)
22460 face
= face
->ascii_face
;
22463 boff
= font
->baseline_offset
;
22464 if (font
->vertical_centering
)
22465 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22466 font_ascent
= FONT_BASE (font
) + boff
;
22467 font_descent
= FONT_DESCENT (font
) - boff
;
22468 font_height
= FONT_HEIGHT (font
);
22470 cmp
->font
= (void *) font
;
22473 if (! font_not_found_p
)
22475 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22476 &char2b
, it
->multibyte_p
, 0);
22477 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22480 /* Initialize the bounding box. */
22483 width
= pcm
->width
;
22484 ascent
= pcm
->ascent
;
22485 descent
= pcm
->descent
;
22486 lbearing
= pcm
->lbearing
;
22487 rbearing
= pcm
->rbearing
;
22491 width
= FONT_WIDTH (font
);
22492 ascent
= FONT_BASE (font
);
22493 descent
= FONT_DESCENT (font
);
22500 lowest
= - descent
+ boff
;
22501 highest
= ascent
+ boff
;
22503 if (! font_not_found_p
22504 && font
->default_ascent
22505 && CHAR_TABLE_P (Vuse_default_ascent
)
22506 && !NILP (Faref (Vuse_default_ascent
,
22507 make_number (it
->char_to_display
))))
22508 highest
= font
->default_ascent
+ boff
;
22510 /* Draw the first glyph at the normal position. It may be
22511 shifted to right later if some other glyphs are drawn
22513 cmp
->offsets
[i
* 2] = 0;
22514 cmp
->offsets
[i
* 2 + 1] = boff
;
22515 cmp
->lbearing
= lbearing
;
22516 cmp
->rbearing
= rbearing
;
22518 /* Set cmp->offsets for the remaining glyphs. */
22519 for (i
++; i
< glyph_len
; i
++)
22521 int left
, right
, btm
, top
;
22522 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22524 struct face
*this_face
;
22529 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22530 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22531 font
= this_face
->font
;
22537 this_boff
= font
->baseline_offset
;
22538 if (font
->vertical_centering
)
22539 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22540 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22541 &char2b
, it
->multibyte_p
, 0);
22542 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22545 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22548 width
= pcm
->width
;
22549 ascent
= pcm
->ascent
;
22550 descent
= pcm
->descent
;
22551 lbearing
= pcm
->lbearing
;
22552 rbearing
= pcm
->rbearing
;
22553 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22555 /* Relative composition with or without
22556 alternate chars. */
22557 left
= (leftmost
+ rightmost
- width
) / 2;
22558 btm
= - descent
+ boff
;
22559 if (font
->relative_compose
22560 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22561 || NILP (Faref (Vignore_relative_composition
,
22562 make_number (ch
)))))
22565 if (- descent
>= font
->relative_compose
)
22566 /* One extra pixel between two glyphs. */
22568 else if (ascent
<= 0)
22569 /* One extra pixel between two glyphs. */
22570 btm
= lowest
- 1 - ascent
- descent
;
22575 /* A composition rule is specified by an integer
22576 value that encodes global and new reference
22577 points (GREF and NREF). GREF and NREF are
22578 specified by numbers as below:
22580 0---1---2 -- ascent
22584 9--10--11 -- center
22586 ---3---4---5--- baseline
22588 6---7---8 -- descent
22590 int rule
= COMPOSITION_RULE (cmp
, i
);
22591 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
22593 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
22594 grefx
= gref
% 3, nrefx
= nref
% 3;
22595 grefy
= gref
/ 3, nrefy
= nref
/ 3;
22597 xoff
= font_height
* (xoff
- 128) / 256;
22599 yoff
= font_height
* (yoff
- 128) / 256;
22602 + grefx
* (rightmost
- leftmost
) / 2
22603 - nrefx
* width
/ 2
22606 btm
= ((grefy
== 0 ? highest
22608 : grefy
== 2 ? lowest
22609 : (highest
+ lowest
) / 2)
22610 - (nrefy
== 0 ? ascent
+ descent
22611 : nrefy
== 1 ? descent
- boff
22613 : (ascent
+ descent
) / 2)
22617 cmp
->offsets
[i
* 2] = left
;
22618 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
22620 /* Update the bounding box of the overall glyphs. */
22623 right
= left
+ width
;
22624 if (left
< leftmost
)
22626 if (right
> rightmost
)
22629 top
= btm
+ descent
+ ascent
;
22635 if (cmp
->lbearing
> left
+ lbearing
)
22636 cmp
->lbearing
= left
+ lbearing
;
22637 if (cmp
->rbearing
< left
+ rbearing
)
22638 cmp
->rbearing
= left
+ rbearing
;
22642 /* If there are glyphs whose x-offsets are negative,
22643 shift all glyphs to the right and make all x-offsets
22647 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22648 cmp
->offsets
[i
* 2] -= leftmost
;
22649 rightmost
-= leftmost
;
22650 cmp
->lbearing
-= leftmost
;
22651 cmp
->rbearing
-= leftmost
;
22654 if (left_padded
&& cmp
->lbearing
< 0)
22656 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22657 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
22658 rightmost
-= cmp
->lbearing
;
22659 cmp
->rbearing
-= cmp
->lbearing
;
22662 if (right_padded
&& rightmost
< cmp
->rbearing
)
22664 rightmost
= cmp
->rbearing
;
22667 cmp
->pixel_width
= rightmost
;
22668 cmp
->ascent
= highest
;
22669 cmp
->descent
= - lowest
;
22670 if (cmp
->ascent
< font_ascent
)
22671 cmp
->ascent
= font_ascent
;
22672 if (cmp
->descent
< font_descent
)
22673 cmp
->descent
= font_descent
;
22677 && (cmp
->lbearing
< 0
22678 || cmp
->rbearing
> cmp
->pixel_width
))
22679 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22681 it
->pixel_width
= cmp
->pixel_width
;
22682 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
22683 it
->descent
= it
->phys_descent
= cmp
->descent
;
22684 if (face
->box
!= FACE_NO_BOX
)
22686 int thick
= face
->box_line_width
;
22690 it
->ascent
+= thick
;
22691 it
->descent
+= thick
;
22696 if (it
->start_of_box_run_p
)
22697 it
->pixel_width
+= thick
;
22698 if (it
->end_of_box_run_p
)
22699 it
->pixel_width
+= thick
;
22702 /* If face has an overline, add the height of the overline
22703 (1 pixel) and a 1 pixel margin to the character height. */
22704 if (face
->overline_p
)
22705 it
->ascent
+= overline_margin
;
22707 take_vertical_position_into_account (it
);
22708 if (it
->ascent
< 0)
22710 if (it
->descent
< 0)
22714 append_composite_glyph (it
);
22716 else if (it
->what
== IT_COMPOSITION
)
22718 /* A dynamic (automatic) composition. */
22719 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22720 Lisp_Object gstring
;
22721 struct font_metrics metrics
;
22723 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
22725 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
22728 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
22729 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22730 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
22731 it
->descent
= it
->phys_descent
= metrics
.descent
;
22732 if (face
->box
!= FACE_NO_BOX
)
22734 int thick
= face
->box_line_width
;
22738 it
->ascent
+= thick
;
22739 it
->descent
+= thick
;
22744 if (it
->start_of_box_run_p
)
22745 it
->pixel_width
+= thick
;
22746 if (it
->end_of_box_run_p
)
22747 it
->pixel_width
+= thick
;
22749 /* If face has an overline, add the height of the overline
22750 (1 pixel) and a 1 pixel margin to the character height. */
22751 if (face
->overline_p
)
22752 it
->ascent
+= overline_margin
;
22753 take_vertical_position_into_account (it
);
22754 if (it
->ascent
< 0)
22756 if (it
->descent
< 0)
22760 append_composite_glyph (it
);
22762 else if (it
->what
== IT_IMAGE
)
22763 produce_image_glyph (it
);
22764 else if (it
->what
== IT_STRETCH
)
22765 produce_stretch_glyph (it
);
22767 /* Accumulate dimensions. Note: can't assume that it->descent > 0
22768 because this isn't true for images with `:ascent 100'. */
22769 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
22770 if (it
->area
== TEXT_AREA
)
22771 it
->current_x
+= it
->pixel_width
;
22773 if (extra_line_spacing
> 0)
22775 it
->descent
+= extra_line_spacing
;
22776 if (extra_line_spacing
> it
->max_extra_line_spacing
)
22777 it
->max_extra_line_spacing
= extra_line_spacing
;
22780 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
22781 it
->max_descent
= max (it
->max_descent
, it
->descent
);
22782 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
22783 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
22787 Output LEN glyphs starting at START at the nominal cursor position.
22788 Advance the nominal cursor over the text. The global variable
22789 updated_window contains the window being updated, updated_row is
22790 the glyph row being updated, and updated_area is the area of that
22791 row being updated. */
22794 x_write_glyphs (start
, len
)
22795 struct glyph
*start
;
22800 xassert (updated_window
&& updated_row
);
22803 /* Write glyphs. */
22805 hpos
= start
- updated_row
->glyphs
[updated_area
];
22806 x
= draw_glyphs (updated_window
, output_cursor
.x
,
22807 updated_row
, updated_area
,
22809 DRAW_NORMAL_TEXT
, 0);
22811 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
22812 if (updated_area
== TEXT_AREA
22813 && updated_window
->phys_cursor_on_p
22814 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
22815 && updated_window
->phys_cursor
.hpos
>= hpos
22816 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
22817 updated_window
->phys_cursor_on_p
= 0;
22821 /* Advance the output cursor. */
22822 output_cursor
.hpos
+= len
;
22823 output_cursor
.x
= x
;
22828 Insert LEN glyphs from START at the nominal cursor position. */
22831 x_insert_glyphs (start
, len
)
22832 struct glyph
*start
;
22837 int line_height
, shift_by_width
, shifted_region_width
;
22838 struct glyph_row
*row
;
22839 struct glyph
*glyph
;
22840 int frame_x
, frame_y
;
22843 xassert (updated_window
&& updated_row
);
22845 w
= updated_window
;
22846 f
= XFRAME (WINDOW_FRAME (w
));
22848 /* Get the height of the line we are in. */
22850 line_height
= row
->height
;
22852 /* Get the width of the glyphs to insert. */
22853 shift_by_width
= 0;
22854 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
22855 shift_by_width
+= glyph
->pixel_width
;
22857 /* Get the width of the region to shift right. */
22858 shifted_region_width
= (window_box_width (w
, updated_area
)
22863 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
22864 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
22866 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
22867 line_height
, shift_by_width
);
22869 /* Write the glyphs. */
22870 hpos
= start
- row
->glyphs
[updated_area
];
22871 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
22873 DRAW_NORMAL_TEXT
, 0);
22875 /* Advance the output cursor. */
22876 output_cursor
.hpos
+= len
;
22877 output_cursor
.x
+= shift_by_width
;
22883 Erase the current text line from the nominal cursor position
22884 (inclusive) to pixel column TO_X (exclusive). The idea is that
22885 everything from TO_X onward is already erased.
22887 TO_X is a pixel position relative to updated_area of
22888 updated_window. TO_X == -1 means clear to the end of this area. */
22891 x_clear_end_of_line (to_x
)
22895 struct window
*w
= updated_window
;
22896 int max_x
, min_y
, max_y
;
22897 int from_x
, from_y
, to_y
;
22899 xassert (updated_window
&& updated_row
);
22900 f
= XFRAME (w
->frame
);
22902 if (updated_row
->full_width_p
)
22903 max_x
= WINDOW_TOTAL_WIDTH (w
);
22905 max_x
= window_box_width (w
, updated_area
);
22906 max_y
= window_text_bottom_y (w
);
22908 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
22909 of window. For TO_X > 0, truncate to end of drawing area. */
22915 to_x
= min (to_x
, max_x
);
22917 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
22919 /* Notice if the cursor will be cleared by this operation. */
22920 if (!updated_row
->full_width_p
)
22921 notice_overwritten_cursor (w
, updated_area
,
22922 output_cursor
.x
, -1,
22924 MATRIX_ROW_BOTTOM_Y (updated_row
));
22926 from_x
= output_cursor
.x
;
22928 /* Translate to frame coordinates. */
22929 if (updated_row
->full_width_p
)
22931 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
22932 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
22936 int area_left
= window_box_left (w
, updated_area
);
22937 from_x
+= area_left
;
22941 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22942 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22943 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22945 /* Prevent inadvertently clearing to end of the X window. */
22946 if (to_x
> from_x
&& to_y
> from_y
)
22949 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22950 to_x
- from_x
, to_y
- from_y
);
22955 #endif /* HAVE_WINDOW_SYSTEM */
22959 /***********************************************************************
22961 ***********************************************************************/
22963 /* Value is the internal representation of the specified cursor type
22964 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22965 of the bar cursor. */
22967 static enum text_cursor_kinds
22968 get_specified_cursor_type (arg
, width
)
22972 enum text_cursor_kinds type
;
22977 if (EQ (arg
, Qbox
))
22978 return FILLED_BOX_CURSOR
;
22980 if (EQ (arg
, Qhollow
))
22981 return HOLLOW_BOX_CURSOR
;
22983 if (EQ (arg
, Qbar
))
22990 && EQ (XCAR (arg
), Qbar
)
22991 && INTEGERP (XCDR (arg
))
22992 && XINT (XCDR (arg
)) >= 0)
22994 *width
= XINT (XCDR (arg
));
22998 if (EQ (arg
, Qhbar
))
23001 return HBAR_CURSOR
;
23005 && EQ (XCAR (arg
), Qhbar
)
23006 && INTEGERP (XCDR (arg
))
23007 && XINT (XCDR (arg
)) >= 0)
23009 *width
= XINT (XCDR (arg
));
23010 return HBAR_CURSOR
;
23013 /* Treat anything unknown as "hollow box cursor".
23014 It was bad to signal an error; people have trouble fixing
23015 .Xdefaults with Emacs, when it has something bad in it. */
23016 type
= HOLLOW_BOX_CURSOR
;
23021 /* Set the default cursor types for specified frame. */
23023 set_frame_cursor_types (f
, arg
)
23030 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
23031 FRAME_CURSOR_WIDTH (f
) = width
;
23033 /* By default, set up the blink-off state depending on the on-state. */
23035 tem
= Fassoc (arg
, Vblink_cursor_alist
);
23038 FRAME_BLINK_OFF_CURSOR (f
)
23039 = get_specified_cursor_type (XCDR (tem
), &width
);
23040 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23043 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23047 /* Return the cursor we want to be displayed in window W. Return
23048 width of bar/hbar cursor through WIDTH arg. Return with
23049 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23050 (i.e. if the `system caret' should track this cursor).
23052 In a mini-buffer window, we want the cursor only to appear if we
23053 are reading input from this window. For the selected window, we
23054 want the cursor type given by the frame parameter or buffer local
23055 setting of cursor-type. If explicitly marked off, draw no cursor.
23056 In all other cases, we want a hollow box cursor. */
23058 static enum text_cursor_kinds
23059 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
23061 struct glyph
*glyph
;
23063 int *active_cursor
;
23065 struct frame
*f
= XFRAME (w
->frame
);
23066 struct buffer
*b
= XBUFFER (w
->buffer
);
23067 int cursor_type
= DEFAULT_CURSOR
;
23068 Lisp_Object alt_cursor
;
23069 int non_selected
= 0;
23071 *active_cursor
= 1;
23074 if (cursor_in_echo_area
23075 && FRAME_HAS_MINIBUF_P (f
)
23076 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23078 if (w
== XWINDOW (echo_area_window
))
23080 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
23082 *width
= FRAME_CURSOR_WIDTH (f
);
23083 return FRAME_DESIRED_CURSOR (f
);
23086 return get_specified_cursor_type (b
->cursor_type
, width
);
23089 *active_cursor
= 0;
23093 /* Detect a nonselected window or nonselected frame. */
23094 else if (w
!= XWINDOW (f
->selected_window
)
23095 #ifdef HAVE_WINDOW_SYSTEM
23096 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
23100 *active_cursor
= 0;
23102 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23108 /* Never display a cursor in a window in which cursor-type is nil. */
23109 if (NILP (b
->cursor_type
))
23112 /* Get the normal cursor type for this window. */
23113 if (EQ (b
->cursor_type
, Qt
))
23115 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23116 *width
= FRAME_CURSOR_WIDTH (f
);
23119 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
23121 /* Use cursor-in-non-selected-windows instead
23122 for non-selected window or frame. */
23125 alt_cursor
= b
->cursor_in_non_selected_windows
;
23126 if (!EQ (Qt
, alt_cursor
))
23127 return get_specified_cursor_type (alt_cursor
, width
);
23128 /* t means modify the normal cursor type. */
23129 if (cursor_type
== FILLED_BOX_CURSOR
)
23130 cursor_type
= HOLLOW_BOX_CURSOR
;
23131 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23133 return cursor_type
;
23136 /* Use normal cursor if not blinked off. */
23137 if (!w
->cursor_off_p
)
23139 #ifdef HAVE_WINDOW_SYSTEM
23140 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23142 if (cursor_type
== FILLED_BOX_CURSOR
)
23144 /* Using a block cursor on large images can be very annoying.
23145 So use a hollow cursor for "large" images.
23146 If image is not transparent (no mask), also use hollow cursor. */
23147 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23148 if (img
!= NULL
&& IMAGEP (img
->spec
))
23150 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23151 where N = size of default frame font size.
23152 This should cover most of the "tiny" icons people may use. */
23154 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23155 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23156 cursor_type
= HOLLOW_BOX_CURSOR
;
23159 else if (cursor_type
!= NO_CURSOR
)
23161 /* Display current only supports BOX and HOLLOW cursors for images.
23162 So for now, unconditionally use a HOLLOW cursor when cursor is
23163 not a solid box cursor. */
23164 cursor_type
= HOLLOW_BOX_CURSOR
;
23168 return cursor_type
;
23171 /* Cursor is blinked off, so determine how to "toggle" it. */
23173 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23174 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
23175 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23177 /* Then see if frame has specified a specific blink off cursor type. */
23178 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23180 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23181 return FRAME_BLINK_OFF_CURSOR (f
);
23185 /* Some people liked having a permanently visible blinking cursor,
23186 while others had very strong opinions against it. So it was
23187 decided to remove it. KFS 2003-09-03 */
23189 /* Finally perform built-in cursor blinking:
23190 filled box <-> hollow box
23191 wide [h]bar <-> narrow [h]bar
23192 narrow [h]bar <-> no cursor
23193 other type <-> no cursor */
23195 if (cursor_type
== FILLED_BOX_CURSOR
)
23196 return HOLLOW_BOX_CURSOR
;
23198 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23201 return cursor_type
;
23209 #ifdef HAVE_WINDOW_SYSTEM
23211 /* Notice when the text cursor of window W has been completely
23212 overwritten by a drawing operation that outputs glyphs in AREA
23213 starting at X0 and ending at X1 in the line starting at Y0 and
23214 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23215 the rest of the line after X0 has been written. Y coordinates
23216 are window-relative. */
23219 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
23221 enum glyph_row_area area
;
23222 int x0
, y0
, x1
, y1
;
23224 int cx0
, cx1
, cy0
, cy1
;
23225 struct glyph_row
*row
;
23227 if (!w
->phys_cursor_on_p
)
23229 if (area
!= TEXT_AREA
)
23232 if (w
->phys_cursor
.vpos
< 0
23233 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23234 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23235 !(row
->enabled_p
&& row
->displays_text_p
)))
23238 if (row
->cursor_in_fringe_p
)
23240 row
->cursor_in_fringe_p
= 0;
23241 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
23242 w
->phys_cursor_on_p
= 0;
23246 cx0
= w
->phys_cursor
.x
;
23247 cx1
= cx0
+ w
->phys_cursor_width
;
23248 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23251 /* The cursor image will be completely removed from the
23252 screen if the output area intersects the cursor area in
23253 y-direction. When we draw in [y0 y1[, and some part of
23254 the cursor is at y < y0, that part must have been drawn
23255 before. When scrolling, the cursor is erased before
23256 actually scrolling, so we don't come here. When not
23257 scrolling, the rows above the old cursor row must have
23258 changed, and in this case these rows must have written
23259 over the cursor image.
23261 Likewise if part of the cursor is below y1, with the
23262 exception of the cursor being in the first blank row at
23263 the buffer and window end because update_text_area
23264 doesn't draw that row. (Except when it does, but
23265 that's handled in update_text_area.) */
23267 cy0
= w
->phys_cursor
.y
;
23268 cy1
= cy0
+ w
->phys_cursor_height
;
23269 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23272 w
->phys_cursor_on_p
= 0;
23275 #endif /* HAVE_WINDOW_SYSTEM */
23278 /************************************************************************
23280 ************************************************************************/
23282 #ifdef HAVE_WINDOW_SYSTEM
23285 Fix the display of area AREA of overlapping row ROW in window W
23286 with respect to the overlapping part OVERLAPS. */
23289 x_fix_overlapping_area (w
, row
, area
, overlaps
)
23291 struct glyph_row
*row
;
23292 enum glyph_row_area area
;
23300 for (i
= 0; i
< row
->used
[area
];)
23302 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23304 int start
= i
, start_x
= x
;
23308 x
+= row
->glyphs
[area
][i
].pixel_width
;
23311 while (i
< row
->used
[area
]
23312 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23314 draw_glyphs (w
, start_x
, row
, area
,
23316 DRAW_NORMAL_TEXT
, overlaps
);
23320 x
+= row
->glyphs
[area
][i
].pixel_width
;
23330 Draw the cursor glyph of window W in glyph row ROW. See the
23331 comment of draw_glyphs for the meaning of HL. */
23334 draw_phys_cursor_glyph (w
, row
, hl
)
23336 struct glyph_row
*row
;
23337 enum draw_glyphs_face hl
;
23339 /* If cursor hpos is out of bounds, don't draw garbage. This can
23340 happen in mini-buffer windows when switching between echo area
23341 glyphs and mini-buffer. */
23342 if ((row
->reversed_p
23343 ? (w
->phys_cursor
.hpos
>= 0)
23344 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
23346 int on_p
= w
->phys_cursor_on_p
;
23348 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23349 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23351 w
->phys_cursor_on_p
= on_p
;
23353 if (hl
== DRAW_CURSOR
)
23354 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23355 /* When we erase the cursor, and ROW is overlapped by other
23356 rows, make sure that these overlapping parts of other rows
23358 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23360 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23362 if (row
> w
->current_matrix
->rows
23363 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23364 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23365 OVERLAPS_ERASED_CURSOR
);
23367 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23368 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23369 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23370 OVERLAPS_ERASED_CURSOR
);
23377 Erase the image of a cursor of window W from the screen. */
23380 erase_phys_cursor (w
)
23383 struct frame
*f
= XFRAME (w
->frame
);
23384 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23385 int hpos
= w
->phys_cursor
.hpos
;
23386 int vpos
= w
->phys_cursor
.vpos
;
23387 int mouse_face_here_p
= 0;
23388 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23389 struct glyph_row
*cursor_row
;
23390 struct glyph
*cursor_glyph
;
23391 enum draw_glyphs_face hl
;
23393 /* No cursor displayed or row invalidated => nothing to do on the
23395 if (w
->phys_cursor_type
== NO_CURSOR
)
23396 goto mark_cursor_off
;
23398 /* VPOS >= active_glyphs->nrows means that window has been resized.
23399 Don't bother to erase the cursor. */
23400 if (vpos
>= active_glyphs
->nrows
)
23401 goto mark_cursor_off
;
23403 /* If row containing cursor is marked invalid, there is nothing we
23405 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23406 if (!cursor_row
->enabled_p
)
23407 goto mark_cursor_off
;
23409 /* If line spacing is > 0, old cursor may only be partially visible in
23410 window after split-window. So adjust visible height. */
23411 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23412 window_text_bottom_y (w
) - cursor_row
->y
);
23414 /* If row is completely invisible, don't attempt to delete a cursor which
23415 isn't there. This can happen if cursor is at top of a window, and
23416 we switch to a buffer with a header line in that window. */
23417 if (cursor_row
->visible_height
<= 0)
23418 goto mark_cursor_off
;
23420 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23421 if (cursor_row
->cursor_in_fringe_p
)
23423 cursor_row
->cursor_in_fringe_p
= 0;
23424 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
23425 goto mark_cursor_off
;
23428 /* This can happen when the new row is shorter than the old one.
23429 In this case, either draw_glyphs or clear_end_of_line
23430 should have cleared the cursor. Note that we wouldn't be
23431 able to erase the cursor in this case because we don't have a
23432 cursor glyph at hand. */
23433 if ((cursor_row
->reversed_p
23434 ? (w
->phys_cursor
.hpos
< 0)
23435 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
23436 goto mark_cursor_off
;
23438 /* If the cursor is in the mouse face area, redisplay that when
23439 we clear the cursor. */
23440 if (! NILP (dpyinfo
->mouse_face_window
)
23441 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
23442 && (vpos
> dpyinfo
->mouse_face_beg_row
23443 || (vpos
== dpyinfo
->mouse_face_beg_row
23444 && hpos
>= dpyinfo
->mouse_face_beg_col
))
23445 && (vpos
< dpyinfo
->mouse_face_end_row
23446 || (vpos
== dpyinfo
->mouse_face_end_row
23447 && hpos
< dpyinfo
->mouse_face_end_col
))
23448 /* Don't redraw the cursor's spot in mouse face if it is at the
23449 end of a line (on a newline). The cursor appears there, but
23450 mouse highlighting does not. */
23451 && cursor_row
->used
[TEXT_AREA
] > hpos
)
23452 mouse_face_here_p
= 1;
23454 /* Maybe clear the display under the cursor. */
23455 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23458 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23461 cursor_glyph
= get_phys_cursor_glyph (w
);
23462 if (cursor_glyph
== NULL
)
23463 goto mark_cursor_off
;
23465 width
= cursor_glyph
->pixel_width
;
23466 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23467 x
= w
->phys_cursor
.x
;
23469 width
-= left_x
- x
;
23470 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23471 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23472 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23475 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23478 /* Erase the cursor by redrawing the character underneath it. */
23479 if (mouse_face_here_p
)
23480 hl
= DRAW_MOUSE_FACE
;
23482 hl
= DRAW_NORMAL_TEXT
;
23483 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23486 w
->phys_cursor_on_p
= 0;
23487 w
->phys_cursor_type
= NO_CURSOR
;
23492 Display or clear cursor of window W. If ON is zero, clear the
23493 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23494 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23497 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
23499 int on
, hpos
, vpos
, x
, y
;
23501 struct frame
*f
= XFRAME (w
->frame
);
23502 int new_cursor_type
;
23503 int new_cursor_width
;
23505 struct glyph_row
*glyph_row
;
23506 struct glyph
*glyph
;
23508 /* This is pointless on invisible frames, and dangerous on garbaged
23509 windows and frames; in the latter case, the frame or window may
23510 be in the midst of changing its size, and x and y may be off the
23512 if (! FRAME_VISIBLE_P (f
)
23513 || FRAME_GARBAGED_P (f
)
23514 || vpos
>= w
->current_matrix
->nrows
23515 || hpos
>= w
->current_matrix
->matrix_w
)
23518 /* If cursor is off and we want it off, return quickly. */
23519 if (!on
&& !w
->phys_cursor_on_p
)
23522 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23523 /* If cursor row is not enabled, we don't really know where to
23524 display the cursor. */
23525 if (!glyph_row
->enabled_p
)
23527 w
->phys_cursor_on_p
= 0;
23532 if (!glyph_row
->exact_window_width_line_p
23533 || hpos
< glyph_row
->used
[TEXT_AREA
])
23534 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23536 xassert (interrupt_input_blocked
);
23538 /* Set new_cursor_type to the cursor we want to be displayed. */
23539 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23540 &new_cursor_width
, &active_cursor
);
23542 /* If cursor is currently being shown and we don't want it to be or
23543 it is in the wrong place, or the cursor type is not what we want,
23545 if (w
->phys_cursor_on_p
23547 || w
->phys_cursor
.x
!= x
23548 || w
->phys_cursor
.y
!= y
23549 || new_cursor_type
!= w
->phys_cursor_type
23550 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23551 && new_cursor_width
!= w
->phys_cursor_width
)))
23552 erase_phys_cursor (w
);
23554 /* Don't check phys_cursor_on_p here because that flag is only set
23555 to zero in some cases where we know that the cursor has been
23556 completely erased, to avoid the extra work of erasing the cursor
23557 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23558 still not be visible, or it has only been partly erased. */
23561 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23562 w
->phys_cursor_height
= glyph_row
->height
;
23564 /* Set phys_cursor_.* before x_draw_.* is called because some
23565 of them may need the information. */
23566 w
->phys_cursor
.x
= x
;
23567 w
->phys_cursor
.y
= glyph_row
->y
;
23568 w
->phys_cursor
.hpos
= hpos
;
23569 w
->phys_cursor
.vpos
= vpos
;
23572 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23573 new_cursor_type
, new_cursor_width
,
23574 on
, active_cursor
);
23578 /* Switch the display of W's cursor on or off, according to the value
23582 update_window_cursor (w
, on
)
23586 /* Don't update cursor in windows whose frame is in the process
23587 of being deleted. */
23588 if (w
->current_matrix
)
23591 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23592 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23598 /* Call update_window_cursor with parameter ON_P on all leaf windows
23599 in the window tree rooted at W. */
23602 update_cursor_in_window_tree (w
, on_p
)
23608 if (!NILP (w
->hchild
))
23609 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23610 else if (!NILP (w
->vchild
))
23611 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23613 update_window_cursor (w
, on_p
);
23615 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23621 Display the cursor on window W, or clear it, according to ON_P.
23622 Don't change the cursor's position. */
23625 x_update_cursor (f
, on_p
)
23629 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
23634 Clear the cursor of window W to background color, and mark the
23635 cursor as not shown. This is used when the text where the cursor
23636 is about to be rewritten. */
23642 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
23643 update_window_cursor (w
, 0);
23648 Display the active region described by mouse_face_* according to DRAW. */
23651 show_mouse_face (dpyinfo
, draw
)
23652 Display_Info
*dpyinfo
;
23653 enum draw_glyphs_face draw
;
23655 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
23656 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23658 if (/* If window is in the process of being destroyed, don't bother
23660 w
->current_matrix
!= NULL
23661 /* Don't update mouse highlight if hidden */
23662 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
23663 /* Recognize when we are called to operate on rows that don't exist
23664 anymore. This can happen when a window is split. */
23665 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
23667 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
23668 struct glyph_row
*row
, *first
, *last
;
23670 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
23671 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
23673 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
23675 int start_hpos
, end_hpos
, start_x
;
23677 /* For all but the first row, the highlight starts at column 0. */
23680 start_hpos
= dpyinfo
->mouse_face_beg_col
;
23681 start_x
= dpyinfo
->mouse_face_beg_x
;
23690 end_hpos
= dpyinfo
->mouse_face_end_col
;
23693 end_hpos
= row
->used
[TEXT_AREA
];
23694 if (draw
== DRAW_NORMAL_TEXT
)
23695 row
->fill_line_p
= 1; /* Clear to end of line */
23698 if (end_hpos
> start_hpos
)
23700 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
23701 start_hpos
, end_hpos
,
23705 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
23709 /* When we've written over the cursor, arrange for it to
23710 be displayed again. */
23711 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
23714 display_and_set_cursor (w
, 1,
23715 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23716 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23721 /* Change the mouse cursor. */
23722 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
23723 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
23724 else if (draw
== DRAW_MOUSE_FACE
)
23725 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
23727 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
23731 Clear out the mouse-highlighted active region.
23732 Redraw it un-highlighted first. Value is non-zero if mouse
23733 face was actually drawn unhighlighted. */
23736 clear_mouse_face (dpyinfo
)
23737 Display_Info
*dpyinfo
;
23741 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
23743 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
23747 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23748 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23749 dpyinfo
->mouse_face_window
= Qnil
;
23750 dpyinfo
->mouse_face_overlay
= Qnil
;
23756 Non-zero if physical cursor of window W is within mouse face. */
23759 cursor_in_mouse_face_p (w
)
23762 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23763 int in_mouse_face
= 0;
23765 if (WINDOWP (dpyinfo
->mouse_face_window
)
23766 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
23768 int hpos
= w
->phys_cursor
.hpos
;
23769 int vpos
= w
->phys_cursor
.vpos
;
23771 if (vpos
>= dpyinfo
->mouse_face_beg_row
23772 && vpos
<= dpyinfo
->mouse_face_end_row
23773 && (vpos
> dpyinfo
->mouse_face_beg_row
23774 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23775 && (vpos
< dpyinfo
->mouse_face_end_row
23776 || hpos
< dpyinfo
->mouse_face_end_col
23777 || dpyinfo
->mouse_face_past_end
))
23781 return in_mouse_face
;
23787 /* This function sets the mouse_face_* elements of DPYINFO, assuming
23788 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
23789 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
23790 for the overlay or run of text properties specifying the mouse
23791 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
23792 before-string and after-string that must also be highlighted.
23793 DISPLAY_STRING, if non-nil, is a display string that may cover some
23794 or all of the highlighted text. */
23797 mouse_face_from_buffer_pos (Lisp_Object window
,
23798 Display_Info
*dpyinfo
,
23799 EMACS_INT mouse_charpos
,
23800 EMACS_INT start_charpos
,
23801 EMACS_INT end_charpos
,
23802 Lisp_Object before_string
,
23803 Lisp_Object after_string
,
23804 Lisp_Object display_string
)
23806 struct window
*w
= XWINDOW (window
);
23807 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23808 struct glyph_row
*row
;
23809 struct glyph
*glyph
, *end
;
23813 xassert (NILP (display_string
) || STRINGP (display_string
));
23814 xassert (NILP (before_string
) || STRINGP (before_string
));
23815 xassert (NILP (after_string
) || STRINGP (after_string
));
23817 /* Find the first highlighted glyph. */
23818 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
23820 dpyinfo
->mouse_face_beg_col
= 0;
23821 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
23822 dpyinfo
->mouse_face_beg_x
= first
->x
;
23823 dpyinfo
->mouse_face_beg_y
= first
->y
;
23827 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
23829 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23831 /* If the before-string or display-string contains newlines,
23832 row_containing_pos skips to its last row. Move back. */
23833 if (!NILP (before_string
) || !NILP (display_string
))
23835 struct glyph_row
*prev
;
23836 while ((prev
= row
- 1, prev
>= first
)
23837 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
23838 && prev
->used
[TEXT_AREA
] > 0)
23840 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
23841 glyph
= beg
+ prev
->used
[TEXT_AREA
];
23842 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
23844 || !(EQ (glyph
->object
, before_string
)
23845 || EQ (glyph
->object
, display_string
)))
23851 glyph
= row
->glyphs
[TEXT_AREA
];
23852 end
= glyph
+ row
->used
[TEXT_AREA
];
23854 dpyinfo
->mouse_face_beg_y
= row
->y
;
23855 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23857 /* Skip truncation glyphs at the start of the glyph row. */
23858 if (row
->displays_text_p
)
23860 && INTEGERP (glyph
->object
)
23861 && glyph
->charpos
< 0;
23863 x
+= glyph
->pixel_width
;
23865 /* Scan the glyph row, stopping before BEFORE_STRING or
23866 DISPLAY_STRING or START_CHARPOS. */
23868 && !INTEGERP (glyph
->object
)
23869 && !EQ (glyph
->object
, before_string
)
23870 && !EQ (glyph
->object
, display_string
)
23871 && !(BUFFERP (glyph
->object
)
23872 && glyph
->charpos
>= start_charpos
);
23874 x
+= glyph
->pixel_width
;
23876 dpyinfo
->mouse_face_beg_x
= x
;
23877 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23880 /* Find the last highlighted glyph. */
23881 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
23884 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23885 dpyinfo
->mouse_face_past_end
= 1;
23887 else if (!NILP (after_string
))
23889 /* If the after-string has newlines, advance to its last row. */
23890 struct glyph_row
*next
;
23891 struct glyph_row
*last
23892 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23894 for (next
= row
+ 1;
23896 && next
->used
[TEXT_AREA
] > 0
23897 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
23902 glyph
= row
->glyphs
[TEXT_AREA
];
23903 end
= glyph
+ row
->used
[TEXT_AREA
];
23905 dpyinfo
->mouse_face_end_y
= row
->y
;
23906 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23908 /* Skip truncation glyphs at the start of the row. */
23909 if (row
->displays_text_p
)
23911 && INTEGERP (glyph
->object
)
23912 && glyph
->charpos
< 0;
23914 x
+= glyph
->pixel_width
;
23916 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
23919 && !INTEGERP (glyph
->object
)
23920 && !EQ (glyph
->object
, after_string
)
23921 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
23923 x
+= glyph
->pixel_width
;
23925 /* If we found AFTER_STRING, consume it and stop. */
23926 if (EQ (glyph
->object
, after_string
))
23928 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
23929 x
+= glyph
->pixel_width
;
23933 /* If there's no after-string, we must check if we overshot,
23934 which might be the case if we stopped after a string glyph.
23935 That glyph may belong to a before-string or display-string
23936 associated with the end position, which must not be
23938 Lisp_Object prev_object
;
23941 while (glyph
> row
->glyphs
[TEXT_AREA
])
23943 prev_object
= (glyph
- 1)->object
;
23944 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23947 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23948 if (pos
&& pos
< end_charpos
)
23951 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23952 && EQ ((glyph
- 1)->object
, prev_object
);
23954 x
-= (glyph
- 1)->pixel_width
;
23958 dpyinfo
->mouse_face_end_x
= x
;
23959 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23960 dpyinfo
->mouse_face_window
= window
;
23961 dpyinfo
->mouse_face_face_id
23962 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23964 !dpyinfo
->mouse_face_hidden
, -1);
23965 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23969 /* Find the position of the glyph for position POS in OBJECT in
23970 window W's current matrix, and return in *X, *Y the pixel
23971 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23973 RIGHT_P non-zero means return the position of the right edge of the
23974 glyph, RIGHT_P zero means return the left edge position.
23976 If no glyph for POS exists in the matrix, return the position of
23977 the glyph with the next smaller position that is in the matrix, if
23978 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23979 exists in the matrix, return the position of the glyph with the
23980 next larger position in OBJECT.
23982 Value is non-zero if a glyph was found. */
23985 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23988 Lisp_Object object
;
23989 int *hpos
, *vpos
, *x
, *y
;
23992 int yb
= window_text_bottom_y (w
);
23993 struct glyph_row
*r
;
23994 struct glyph
*best_glyph
= NULL
;
23995 struct glyph_row
*best_row
= NULL
;
23998 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23999 r
->enabled_p
&& r
->y
< yb
;
24002 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
24003 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
24006 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
24007 if (EQ (g
->object
, object
))
24009 if (g
->charpos
== pos
)
24016 else if (best_glyph
== NULL
24017 || ((eabs (g
->charpos
- pos
)
24018 < eabs (best_glyph
->charpos
- pos
))
24021 : g
->charpos
> pos
)))
24035 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
24039 *x
+= best_glyph
->pixel_width
;
24044 *vpos
= best_row
- w
->current_matrix
->rows
;
24047 return best_glyph
!= NULL
;
24051 /* See if position X, Y is within a hot-spot of an image. */
24054 on_hot_spot_p (hot_spot
, x
, y
)
24055 Lisp_Object hot_spot
;
24058 if (!CONSP (hot_spot
))
24061 if (EQ (XCAR (hot_spot
), Qrect
))
24063 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
24064 Lisp_Object rect
= XCDR (hot_spot
);
24068 if (!CONSP (XCAR (rect
)))
24070 if (!CONSP (XCDR (rect
)))
24072 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
24074 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
24076 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
24078 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
24082 else if (EQ (XCAR (hot_spot
), Qcircle
))
24084 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
24085 Lisp_Object circ
= XCDR (hot_spot
);
24086 Lisp_Object lr
, lx0
, ly0
;
24088 && CONSP (XCAR (circ
))
24089 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
24090 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
24091 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
24093 double r
= XFLOATINT (lr
);
24094 double dx
= XINT (lx0
) - x
;
24095 double dy
= XINT (ly0
) - y
;
24096 return (dx
* dx
+ dy
* dy
<= r
* r
);
24099 else if (EQ (XCAR (hot_spot
), Qpoly
))
24101 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
24102 if (VECTORP (XCDR (hot_spot
)))
24104 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
24105 Lisp_Object
*poly
= v
->contents
;
24109 Lisp_Object lx
, ly
;
24112 /* Need an even number of coordinates, and at least 3 edges. */
24113 if (n
< 6 || n
& 1)
24116 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
24117 If count is odd, we are inside polygon. Pixels on edges
24118 may or may not be included depending on actual geometry of the
24120 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
24121 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
24123 x0
= XINT (lx
), y0
= XINT (ly
);
24124 for (i
= 0; i
< n
; i
+= 2)
24126 int x1
= x0
, y1
= y0
;
24127 if ((lx
= poly
[i
], !INTEGERP (lx
))
24128 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
24130 x0
= XINT (lx
), y0
= XINT (ly
);
24132 /* Does this segment cross the X line? */
24140 if (y
> y0
&& y
> y1
)
24142 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
24152 find_hot_spot (map
, x
, y
)
24156 while (CONSP (map
))
24158 if (CONSP (XCAR (map
))
24159 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
24167 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
24169 doc
: /* Lookup in image map MAP coordinates X and Y.
24170 An image map is an alist where each element has the format (AREA ID PLIST).
24171 An AREA is specified as either a rectangle, a circle, or a polygon:
24172 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
24173 pixel coordinates of the upper left and bottom right corners.
24174 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
24175 and the radius of the circle; r may be a float or integer.
24176 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
24177 vector describes one corner in the polygon.
24178 Returns the alist element for the first matching AREA in MAP. */)
24189 return find_hot_spot (map
, XINT (x
), XINT (y
));
24193 /* Display frame CURSOR, optionally using shape defined by POINTER. */
24195 define_frame_cursor1 (f
, cursor
, pointer
)
24198 Lisp_Object pointer
;
24200 /* Do not change cursor shape while dragging mouse. */
24201 if (!NILP (do_mouse_tracking
))
24204 if (!NILP (pointer
))
24206 if (EQ (pointer
, Qarrow
))
24207 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24208 else if (EQ (pointer
, Qhand
))
24209 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
24210 else if (EQ (pointer
, Qtext
))
24211 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24212 else if (EQ (pointer
, intern ("hdrag")))
24213 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24214 #ifdef HAVE_X_WINDOWS
24215 else if (EQ (pointer
, intern ("vdrag")))
24216 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
24218 else if (EQ (pointer
, intern ("hourglass")))
24219 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
24220 else if (EQ (pointer
, Qmodeline
))
24221 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
24223 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24226 if (cursor
!= No_Cursor
)
24227 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
24230 /* Take proper action when mouse has moved to the mode or header line
24231 or marginal area AREA of window W, x-position X and y-position Y.
24232 X is relative to the start of the text display area of W, so the
24233 width of bitmap areas and scroll bars must be subtracted to get a
24234 position relative to the start of the mode line. */
24237 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
24238 Lisp_Object window
;
24240 enum window_part area
;
24242 struct window
*w
= XWINDOW (window
);
24243 struct frame
*f
= XFRAME (w
->frame
);
24244 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24245 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24246 Lisp_Object pointer
= Qnil
;
24247 int charpos
, dx
, dy
, width
, height
;
24248 Lisp_Object string
, object
= Qnil
;
24249 Lisp_Object pos
, help
;
24251 Lisp_Object mouse_face
;
24252 int original_x_pixel
= x
;
24253 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
24254 struct glyph_row
*row
;
24256 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
24261 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
24262 &object
, &dx
, &dy
, &width
, &height
);
24264 row
= (area
== ON_MODE_LINE
24265 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
24266 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
24269 if (row
->mode_line_p
&& row
->enabled_p
)
24271 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
24272 end
= glyph
+ row
->used
[TEXT_AREA
];
24274 for (x0
= original_x_pixel
;
24275 glyph
< end
&& x0
>= glyph
->pixel_width
;
24277 x0
-= glyph
->pixel_width
;
24285 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
24286 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
24287 &object
, &dx
, &dy
, &width
, &height
);
24292 if (IMAGEP (object
))
24294 Lisp_Object image_map
, hotspot
;
24295 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
24297 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
24299 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24301 Lisp_Object area_id
, plist
;
24303 area_id
= XCAR (hotspot
);
24304 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24305 If so, we could look for mouse-enter, mouse-leave
24306 properties in PLIST (and do something...). */
24307 hotspot
= XCDR (hotspot
);
24308 if (CONSP (hotspot
)
24309 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24311 pointer
= Fplist_get (plist
, Qpointer
);
24312 if (NILP (pointer
))
24314 help
= Fplist_get (plist
, Qhelp_echo
);
24317 help_echo_string
= help
;
24318 /* Is this correct? ++kfs */
24319 XSETWINDOW (help_echo_window
, w
);
24320 help_echo_object
= w
->buffer
;
24321 help_echo_pos
= charpos
;
24325 if (NILP (pointer
))
24326 pointer
= Fplist_get (XCDR (object
), QCpointer
);
24329 if (STRINGP (string
))
24331 pos
= make_number (charpos
);
24332 /* If we're on a string with `help-echo' text property, arrange
24333 for the help to be displayed. This is done by setting the
24334 global variable help_echo_string to the help string. */
24337 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
24340 help_echo_string
= help
;
24341 XSETWINDOW (help_echo_window
, w
);
24342 help_echo_object
= string
;
24343 help_echo_pos
= charpos
;
24347 if (NILP (pointer
))
24348 pointer
= Fget_text_property (pos
, Qpointer
, string
);
24350 /* Change the mouse pointer according to what is under X/Y. */
24351 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
24354 map
= Fget_text_property (pos
, Qlocal_map
, string
);
24355 if (!KEYMAPP (map
))
24356 map
= Fget_text_property (pos
, Qkeymap
, string
);
24357 if (!KEYMAPP (map
))
24358 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
24361 /* Change the mouse face according to what is under X/Y. */
24362 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
24363 if (!NILP (mouse_face
)
24364 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24369 struct glyph
* tmp_glyph
;
24373 int total_pixel_width
;
24378 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
24379 Qmouse_face
, string
, Qnil
);
24381 b
= make_number (0);
24383 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
24385 e
= make_number (SCHARS (string
));
24387 /* Calculate the position(glyph position: GPOS) of GLYPH in
24388 displayed string. GPOS is different from CHARPOS.
24390 CHARPOS is the position of glyph in internal string
24391 object. A mode line string format has structures which
24392 is converted to a flatten by emacs lisp interpreter.
24393 The internal string is an element of the structures.
24394 The displayed string is the flatten string. */
24396 if (glyph
> row_start_glyph
)
24398 tmp_glyph
= glyph
- 1;
24399 while (tmp_glyph
>= row_start_glyph
24400 && tmp_glyph
->charpos
>= XINT (b
)
24401 && EQ (tmp_glyph
->object
, glyph
->object
))
24408 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
24409 displayed string holding GLYPH.
24411 GSEQ_LENGTH is different from SCHARS (STRING).
24412 SCHARS (STRING) returns the length of the internal string. */
24413 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
24414 tmp_glyph
->charpos
< XINT (e
);
24415 tmp_glyph
++, gseq_length
++)
24417 if (!EQ (tmp_glyph
->object
, glyph
->object
))
24421 total_pixel_width
= 0;
24422 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
24423 total_pixel_width
+= tmp_glyph
->pixel_width
;
24425 /* Pre calculation of re-rendering position */
24427 hpos
= (area
== ON_MODE_LINE
24428 ? (w
->current_matrix
)->nrows
- 1
24431 /* If the re-rendering position is included in the last
24432 re-rendering area, we should do nothing. */
24433 if ( EQ (window
, dpyinfo
->mouse_face_window
)
24434 && dpyinfo
->mouse_face_beg_col
<= vpos
24435 && vpos
< dpyinfo
->mouse_face_end_col
24436 && dpyinfo
->mouse_face_beg_row
== hpos
)
24439 if (clear_mouse_face (dpyinfo
))
24440 cursor
= No_Cursor
;
24442 dpyinfo
->mouse_face_beg_col
= vpos
;
24443 dpyinfo
->mouse_face_beg_row
= hpos
;
24445 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
24446 dpyinfo
->mouse_face_beg_y
= 0;
24448 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
24449 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
24451 dpyinfo
->mouse_face_end_x
= 0;
24452 dpyinfo
->mouse_face_end_y
= 0;
24454 dpyinfo
->mouse_face_past_end
= 0;
24455 dpyinfo
->mouse_face_window
= window
;
24457 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
24460 glyph
->face_id
, 1);
24461 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24463 if (NILP (pointer
))
24466 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24467 clear_mouse_face (dpyinfo
);
24469 define_frame_cursor1 (f
, cursor
, pointer
);
24474 Take proper action when the mouse has moved to position X, Y on
24475 frame F as regards highlighting characters that have mouse-face
24476 properties. Also de-highlighting chars where the mouse was before.
24477 X and Y can be negative or out of range. */
24480 note_mouse_highlight (f
, x
, y
)
24484 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24485 enum window_part part
;
24486 Lisp_Object window
;
24488 Cursor cursor
= No_Cursor
;
24489 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
24492 /* When a menu is active, don't highlight because this looks odd. */
24493 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
24494 if (popup_activated ())
24498 if (NILP (Vmouse_highlight
)
24499 || !f
->glyphs_initialized_p
24500 || f
->pointer_invisible
)
24503 dpyinfo
->mouse_face_mouse_x
= x
;
24504 dpyinfo
->mouse_face_mouse_y
= y
;
24505 dpyinfo
->mouse_face_mouse_frame
= f
;
24507 if (dpyinfo
->mouse_face_defer
)
24510 if (gc_in_progress
)
24512 dpyinfo
->mouse_face_deferred_gc
= 1;
24516 /* Which window is that in? */
24517 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
24519 /* If we were displaying active text in another window, clear that.
24520 Also clear if we move out of text area in same window. */
24521 if (! EQ (window
, dpyinfo
->mouse_face_window
)
24522 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
24523 && !NILP (dpyinfo
->mouse_face_window
)))
24524 clear_mouse_face (dpyinfo
);
24526 /* Not on a window -> return. */
24527 if (!WINDOWP (window
))
24530 /* Reset help_echo_string. It will get recomputed below. */
24531 help_echo_string
= Qnil
;
24533 /* Convert to window-relative pixel coordinates. */
24534 w
= XWINDOW (window
);
24535 frame_to_window_pixel_xy (w
, &x
, &y
);
24537 /* Handle tool-bar window differently since it doesn't display a
24539 if (EQ (window
, f
->tool_bar_window
))
24541 note_tool_bar_highlight (f
, x
, y
);
24545 /* Mouse is on the mode, header line or margin? */
24546 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
24547 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
24549 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
24553 if (part
== ON_VERTICAL_BORDER
)
24555 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24556 help_echo_string
= build_string ("drag-mouse-1: resize");
24558 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
24559 || part
== ON_SCROLL_BAR
)
24560 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24562 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24564 /* Are we in a window whose display is up to date?
24565 And verify the buffer's text has not changed. */
24566 b
= XBUFFER (w
->buffer
);
24567 if (part
== ON_TEXT
24568 && EQ (w
->window_end_valid
, w
->buffer
)
24569 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
24570 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
24572 int hpos
, vpos
, i
, dx
, dy
, area
;
24574 struct glyph
*glyph
;
24575 Lisp_Object object
;
24576 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
24577 Lisp_Object
*overlay_vec
= NULL
;
24579 struct buffer
*obuf
;
24580 int obegv
, ozv
, same_region
;
24582 /* Find the glyph under X/Y. */
24583 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
24585 /* Look for :pointer property on image. */
24586 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24588 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24589 if (img
!= NULL
&& IMAGEP (img
->spec
))
24591 Lisp_Object image_map
, hotspot
;
24592 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
24594 && (hotspot
= find_hot_spot (image_map
,
24595 glyph
->slice
.x
+ dx
,
24596 glyph
->slice
.y
+ dy
),
24598 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24600 Lisp_Object area_id
, plist
;
24602 area_id
= XCAR (hotspot
);
24603 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24604 If so, we could look for mouse-enter, mouse-leave
24605 properties in PLIST (and do something...). */
24606 hotspot
= XCDR (hotspot
);
24607 if (CONSP (hotspot
)
24608 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24610 pointer
= Fplist_get (plist
, Qpointer
);
24611 if (NILP (pointer
))
24613 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
24614 if (!NILP (help_echo_string
))
24616 help_echo_window
= window
;
24617 help_echo_object
= glyph
->object
;
24618 help_echo_pos
= glyph
->charpos
;
24622 if (NILP (pointer
))
24623 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
24627 /* Clear mouse face if X/Y not over text. */
24629 || area
!= TEXT_AREA
24630 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
24632 if (clear_mouse_face (dpyinfo
))
24633 cursor
= No_Cursor
;
24634 if (NILP (pointer
))
24636 if (area
!= TEXT_AREA
)
24637 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24639 pointer
= Vvoid_text_area_pointer
;
24644 pos
= glyph
->charpos
;
24645 object
= glyph
->object
;
24646 if (!STRINGP (object
) && !BUFFERP (object
))
24649 /* If we get an out-of-range value, return now; avoid an error. */
24650 if (BUFFERP (object
) && pos
> BUF_Z (b
))
24653 /* Make the window's buffer temporarily current for
24654 overlays_at and compute_char_face. */
24655 obuf
= current_buffer
;
24656 current_buffer
= b
;
24662 /* Is this char mouse-active or does it have help-echo? */
24663 position
= make_number (pos
);
24665 if (BUFFERP (object
))
24667 /* Put all the overlays we want in a vector in overlay_vec. */
24668 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
24669 /* Sort overlays into increasing priority order. */
24670 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
24675 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
24676 && vpos
>= dpyinfo
->mouse_face_beg_row
24677 && vpos
<= dpyinfo
->mouse_face_end_row
24678 && (vpos
> dpyinfo
->mouse_face_beg_row
24679 || hpos
>= dpyinfo
->mouse_face_beg_col
)
24680 && (vpos
< dpyinfo
->mouse_face_end_row
24681 || hpos
< dpyinfo
->mouse_face_end_col
24682 || dpyinfo
->mouse_face_past_end
));
24685 cursor
= No_Cursor
;
24687 /* Check mouse-face highlighting. */
24689 /* If there exists an overlay with mouse-face overlapping
24690 the one we are currently highlighting, we have to
24691 check if we enter the overlapping overlay, and then
24692 highlight only that. */
24693 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
24694 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
24696 /* Find the highest priority overlay with a mouse-face. */
24698 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
24700 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
24701 if (!NILP (mouse_face
))
24702 overlay
= overlay_vec
[i
];
24705 /* If we're highlighting the same overlay as before, there's
24706 no need to do that again. */
24707 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
24708 goto check_help_echo
;
24709 dpyinfo
->mouse_face_overlay
= overlay
;
24711 /* Clear the display of the old active region, if any. */
24712 if (clear_mouse_face (dpyinfo
))
24713 cursor
= No_Cursor
;
24715 /* If no overlay applies, get a text property. */
24716 if (NILP (overlay
))
24717 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
24719 /* Next, compute the bounds of the mouse highlighting and
24721 if (!NILP (mouse_face
) && STRINGP (object
))
24723 /* The mouse-highlighting comes from a display string
24724 with a mouse-face. */
24728 b
= Fprevious_single_property_change
24729 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
24730 e
= Fnext_single_property_change
24731 (position
, Qmouse_face
, object
, Qnil
);
24733 b
= make_number (0);
24735 e
= make_number (SCHARS (object
) - 1);
24737 fast_find_string_pos (w
, XINT (b
), object
,
24738 &dpyinfo
->mouse_face_beg_col
,
24739 &dpyinfo
->mouse_face_beg_row
,
24740 &dpyinfo
->mouse_face_beg_x
,
24741 &dpyinfo
->mouse_face_beg_y
, 0);
24742 fast_find_string_pos (w
, XINT (e
), object
,
24743 &dpyinfo
->mouse_face_end_col
,
24744 &dpyinfo
->mouse_face_end_row
,
24745 &dpyinfo
->mouse_face_end_x
,
24746 &dpyinfo
->mouse_face_end_y
, 1);
24747 dpyinfo
->mouse_face_past_end
= 0;
24748 dpyinfo
->mouse_face_window
= window
;
24749 dpyinfo
->mouse_face_face_id
24750 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
24751 glyph
->face_id
, 1);
24752 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24753 cursor
= No_Cursor
;
24757 /* The mouse-highlighting, if any, comes from an overlay
24758 or text property in the buffer. */
24759 Lisp_Object buffer
, display_string
;
24761 if (STRINGP (object
))
24763 /* If we are on a display string with no mouse-face,
24764 check if the text under it has one. */
24765 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
24766 int start
= MATRIX_ROW_START_CHARPOS (r
);
24767 pos
= string_buffer_position (w
, object
, start
);
24770 mouse_face
= get_char_property_and_overlay
24771 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
24772 buffer
= w
->buffer
;
24773 display_string
= object
;
24779 display_string
= Qnil
;
24782 if (!NILP (mouse_face
))
24784 Lisp_Object before
, after
;
24785 Lisp_Object before_string
, after_string
;
24787 if (NILP (overlay
))
24789 /* Handle the text property case. */
24790 before
= Fprevious_single_property_change
24791 (make_number (pos
+ 1), Qmouse_face
, buffer
,
24792 Fmarker_position (w
->start
));
24793 after
= Fnext_single_property_change
24794 (make_number (pos
), Qmouse_face
, buffer
,
24795 make_number (BUF_Z (XBUFFER (buffer
))
24796 - XFASTINT (w
->window_end_pos
)));
24797 before_string
= after_string
= Qnil
;
24801 /* Handle the overlay case. */
24802 before
= Foverlay_start (overlay
);
24803 after
= Foverlay_end (overlay
);
24804 before_string
= Foverlay_get (overlay
, Qbefore_string
);
24805 after_string
= Foverlay_get (overlay
, Qafter_string
);
24807 if (!STRINGP (before_string
)) before_string
= Qnil
;
24808 if (!STRINGP (after_string
)) after_string
= Qnil
;
24811 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
24814 before_string
, after_string
,
24816 cursor
= No_Cursor
;
24823 /* Look for a `help-echo' property. */
24824 if (NILP (help_echo_string
)) {
24825 Lisp_Object help
, overlay
;
24827 /* Check overlays first. */
24828 help
= overlay
= Qnil
;
24829 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
24831 overlay
= overlay_vec
[i
];
24832 help
= Foverlay_get (overlay
, Qhelp_echo
);
24837 help_echo_string
= help
;
24838 help_echo_window
= window
;
24839 help_echo_object
= overlay
;
24840 help_echo_pos
= pos
;
24844 Lisp_Object object
= glyph
->object
;
24845 int charpos
= glyph
->charpos
;
24847 /* Try text properties. */
24848 if (STRINGP (object
)
24850 && charpos
< SCHARS (object
))
24852 help
= Fget_text_property (make_number (charpos
),
24853 Qhelp_echo
, object
);
24856 /* If the string itself doesn't specify a help-echo,
24857 see if the buffer text ``under'' it does. */
24858 struct glyph_row
*r
24859 = MATRIX_ROW (w
->current_matrix
, vpos
);
24860 int start
= MATRIX_ROW_START_CHARPOS (r
);
24861 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
24864 help
= Fget_char_property (make_number (pos
),
24865 Qhelp_echo
, w
->buffer
);
24869 object
= w
->buffer
;
24874 else if (BUFFERP (object
)
24877 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
24882 help_echo_string
= help
;
24883 help_echo_window
= window
;
24884 help_echo_object
= object
;
24885 help_echo_pos
= charpos
;
24890 /* Look for a `pointer' property. */
24891 if (NILP (pointer
))
24893 /* Check overlays first. */
24894 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
24895 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
24897 if (NILP (pointer
))
24899 Lisp_Object object
= glyph
->object
;
24900 int charpos
= glyph
->charpos
;
24902 /* Try text properties. */
24903 if (STRINGP (object
)
24905 && charpos
< SCHARS (object
))
24907 pointer
= Fget_text_property (make_number (charpos
),
24909 if (NILP (pointer
))
24911 /* If the string itself doesn't specify a pointer,
24912 see if the buffer text ``under'' it does. */
24913 struct glyph_row
*r
24914 = MATRIX_ROW (w
->current_matrix
, vpos
);
24915 int start
= MATRIX_ROW_START_CHARPOS (r
);
24916 EMACS_INT pos
= string_buffer_position (w
, object
,
24919 pointer
= Fget_char_property (make_number (pos
),
24920 Qpointer
, w
->buffer
);
24923 else if (BUFFERP (object
)
24926 pointer
= Fget_text_property (make_number (charpos
),
24933 current_buffer
= obuf
;
24938 define_frame_cursor1 (f
, cursor
, pointer
);
24943 Clear any mouse-face on window W. This function is part of the
24944 redisplay interface, and is called from try_window_id and similar
24945 functions to ensure the mouse-highlight is off. */
24948 x_clear_window_mouse_face (w
)
24951 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24952 Lisp_Object window
;
24955 XSETWINDOW (window
, w
);
24956 if (EQ (window
, dpyinfo
->mouse_face_window
))
24957 clear_mouse_face (dpyinfo
);
24963 Just discard the mouse face information for frame F, if any.
24964 This is used when the size of F is changed. */
24967 cancel_mouse_face (f
)
24970 Lisp_Object window
;
24971 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24973 window
= dpyinfo
->mouse_face_window
;
24974 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24976 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24977 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24978 dpyinfo
->mouse_face_window
= Qnil
;
24983 #endif /* HAVE_WINDOW_SYSTEM */
24986 /***********************************************************************
24988 ***********************************************************************/
24990 #ifdef HAVE_WINDOW_SYSTEM
24992 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24993 which intersects rectangle R. R is in window-relative coordinates. */
24996 expose_area (w
, row
, r
, area
)
24998 struct glyph_row
*row
;
25000 enum glyph_row_area area
;
25002 struct glyph
*first
= row
->glyphs
[area
];
25003 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
25004 struct glyph
*last
;
25005 int first_x
, start_x
, x
;
25007 if (area
== TEXT_AREA
&& row
->fill_line_p
)
25008 /* If row extends face to end of line write the whole line. */
25009 draw_glyphs (w
, 0, row
, area
,
25010 0, row
->used
[area
],
25011 DRAW_NORMAL_TEXT
, 0);
25014 /* Set START_X to the window-relative start position for drawing glyphs of
25015 AREA. The first glyph of the text area can be partially visible.
25016 The first glyphs of other areas cannot. */
25017 start_x
= window_box_left_offset (w
, area
);
25019 if (area
== TEXT_AREA
)
25022 /* Find the first glyph that must be redrawn. */
25024 && x
+ first
->pixel_width
< r
->x
)
25026 x
+= first
->pixel_width
;
25030 /* Find the last one. */
25034 && x
< r
->x
+ r
->width
)
25036 x
+= last
->pixel_width
;
25042 draw_glyphs (w
, first_x
- start_x
, row
, area
,
25043 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
25044 DRAW_NORMAL_TEXT
, 0);
25049 /* Redraw the parts of the glyph row ROW on window W intersecting
25050 rectangle R. R is in window-relative coordinates. Value is
25051 non-zero if mouse-face was overwritten. */
25054 expose_line (w
, row
, r
)
25056 struct glyph_row
*row
;
25059 xassert (row
->enabled_p
);
25061 if (row
->mode_line_p
|| w
->pseudo_window_p
)
25062 draw_glyphs (w
, 0, row
, TEXT_AREA
,
25063 0, row
->used
[TEXT_AREA
],
25064 DRAW_NORMAL_TEXT
, 0);
25067 if (row
->used
[LEFT_MARGIN_AREA
])
25068 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
25069 if (row
->used
[TEXT_AREA
])
25070 expose_area (w
, row
, r
, TEXT_AREA
);
25071 if (row
->used
[RIGHT_MARGIN_AREA
])
25072 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
25073 draw_row_fringe_bitmaps (w
, row
);
25076 return row
->mouse_face_p
;
25080 /* Redraw those parts of glyphs rows during expose event handling that
25081 overlap other rows. Redrawing of an exposed line writes over parts
25082 of lines overlapping that exposed line; this function fixes that.
25084 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
25085 row in W's current matrix that is exposed and overlaps other rows.
25086 LAST_OVERLAPPING_ROW is the last such row. */
25089 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
25091 struct glyph_row
*first_overlapping_row
;
25092 struct glyph_row
*last_overlapping_row
;
25095 struct glyph_row
*row
;
25097 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
25098 if (row
->overlapping_p
)
25100 xassert (row
->enabled_p
&& !row
->mode_line_p
);
25103 if (row
->used
[LEFT_MARGIN_AREA
])
25104 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
25106 if (row
->used
[TEXT_AREA
])
25107 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
25109 if (row
->used
[RIGHT_MARGIN_AREA
])
25110 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
25116 /* Return non-zero if W's cursor intersects rectangle R. */
25119 phys_cursor_in_rect_p (w
, r
)
25123 XRectangle cr
, result
;
25124 struct glyph
*cursor_glyph
;
25125 struct glyph_row
*row
;
25127 if (w
->phys_cursor
.vpos
>= 0
25128 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
25129 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
25131 && row
->cursor_in_fringe_p
)
25133 /* Cursor is in the fringe. */
25134 cr
.x
= window_box_right_offset (w
,
25135 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
25136 ? RIGHT_MARGIN_AREA
25139 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
25140 cr
.height
= row
->height
;
25141 return x_intersect_rectangles (&cr
, r
, &result
);
25144 cursor_glyph
= get_phys_cursor_glyph (w
);
25147 /* r is relative to W's box, but w->phys_cursor.x is relative
25148 to left edge of W's TEXT area. Adjust it. */
25149 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
25150 cr
.y
= w
->phys_cursor
.y
;
25151 cr
.width
= cursor_glyph
->pixel_width
;
25152 cr
.height
= w
->phys_cursor_height
;
25153 /* ++KFS: W32 version used W32-specific IntersectRect here, but
25154 I assume the effect is the same -- and this is portable. */
25155 return x_intersect_rectangles (&cr
, r
, &result
);
25157 /* If we don't understand the format, pretend we're not in the hot-spot. */
25163 Draw a vertical window border to the right of window W if W doesn't
25164 have vertical scroll bars. */
25167 x_draw_vertical_border (w
)
25170 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25172 /* We could do better, if we knew what type of scroll-bar the adjacent
25173 windows (on either side) have... But we don't :-(
25174 However, I think this works ok. ++KFS 2003-04-25 */
25176 /* Redraw borders between horizontally adjacent windows. Don't
25177 do it for frames with vertical scroll bars because either the
25178 right scroll bar of a window, or the left scroll bar of its
25179 neighbor will suffice as a border. */
25180 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
25183 if (!WINDOW_RIGHTMOST_P (w
)
25184 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
25186 int x0
, x1
, y0
, y1
;
25188 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
25191 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
25194 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
25196 else if (!WINDOW_LEFTMOST_P (w
)
25197 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
25199 int x0
, x1
, y0
, y1
;
25201 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
25204 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
25207 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
25212 /* Redraw the part of window W intersection rectangle FR. Pixel
25213 coordinates in FR are frame-relative. Call this function with
25214 input blocked. Value is non-zero if the exposure overwrites
25218 expose_window (w
, fr
)
25222 struct frame
*f
= XFRAME (w
->frame
);
25224 int mouse_face_overwritten_p
= 0;
25226 /* If window is not yet fully initialized, do nothing. This can
25227 happen when toolkit scroll bars are used and a window is split.
25228 Reconfiguring the scroll bar will generate an expose for a newly
25230 if (w
->current_matrix
== NULL
)
25233 /* When we're currently updating the window, display and current
25234 matrix usually don't agree. Arrange for a thorough display
25236 if (w
== updated_window
)
25238 SET_FRAME_GARBAGED (f
);
25242 /* Frame-relative pixel rectangle of W. */
25243 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
25244 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
25245 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
25246 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
25248 if (x_intersect_rectangles (fr
, &wr
, &r
))
25250 int yb
= window_text_bottom_y (w
);
25251 struct glyph_row
*row
;
25252 int cursor_cleared_p
;
25253 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
25255 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
25256 r
.x
, r
.y
, r
.width
, r
.height
));
25258 /* Convert to window coordinates. */
25259 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
25260 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
25262 /* Turn off the cursor. */
25263 if (!w
->pseudo_window_p
25264 && phys_cursor_in_rect_p (w
, &r
))
25266 x_clear_cursor (w
);
25267 cursor_cleared_p
= 1;
25270 cursor_cleared_p
= 0;
25272 /* Update lines intersecting rectangle R. */
25273 first_overlapping_row
= last_overlapping_row
= NULL
;
25274 for (row
= w
->current_matrix
->rows
;
25279 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
25281 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
25282 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
25283 || (r
.y
>= y0
&& r
.y
< y1
)
25284 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
25286 /* A header line may be overlapping, but there is no need
25287 to fix overlapping areas for them. KFS 2005-02-12 */
25288 if (row
->overlapping_p
&& !row
->mode_line_p
)
25290 if (first_overlapping_row
== NULL
)
25291 first_overlapping_row
= row
;
25292 last_overlapping_row
= row
;
25296 if (expose_line (w
, row
, &r
))
25297 mouse_face_overwritten_p
= 1;
25300 else if (row
->overlapping_p
)
25302 /* We must redraw a row overlapping the exposed area. */
25304 ? y0
+ row
->phys_height
> r
.y
25305 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
25307 if (first_overlapping_row
== NULL
)
25308 first_overlapping_row
= row
;
25309 last_overlapping_row
= row
;
25317 /* Display the mode line if there is one. */
25318 if (WINDOW_WANTS_MODELINE_P (w
)
25319 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
25321 && row
->y
< r
.y
+ r
.height
)
25323 if (expose_line (w
, row
, &r
))
25324 mouse_face_overwritten_p
= 1;
25327 if (!w
->pseudo_window_p
)
25329 /* Fix the display of overlapping rows. */
25330 if (first_overlapping_row
)
25331 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
25334 /* Draw border between windows. */
25335 x_draw_vertical_border (w
);
25337 /* Turn the cursor on again. */
25338 if (cursor_cleared_p
)
25339 update_window_cursor (w
, 1);
25343 return mouse_face_overwritten_p
;
25348 /* Redraw (parts) of all windows in the window tree rooted at W that
25349 intersect R. R contains frame pixel coordinates. Value is
25350 non-zero if the exposure overwrites mouse-face. */
25353 expose_window_tree (w
, r
)
25357 struct frame
*f
= XFRAME (w
->frame
);
25358 int mouse_face_overwritten_p
= 0;
25360 while (w
&& !FRAME_GARBAGED_P (f
))
25362 if (!NILP (w
->hchild
))
25363 mouse_face_overwritten_p
25364 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
25365 else if (!NILP (w
->vchild
))
25366 mouse_face_overwritten_p
25367 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
25369 mouse_face_overwritten_p
|= expose_window (w
, r
);
25371 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
25374 return mouse_face_overwritten_p
;
25379 Redisplay an exposed area of frame F. X and Y are the upper-left
25380 corner of the exposed rectangle. W and H are width and height of
25381 the exposed area. All are pixel values. W or H zero means redraw
25382 the entire frame. */
25385 expose_frame (f
, x
, y
, w
, h
)
25390 int mouse_face_overwritten_p
= 0;
25392 TRACE ((stderr
, "expose_frame "));
25394 /* No need to redraw if frame will be redrawn soon. */
25395 if (FRAME_GARBAGED_P (f
))
25397 TRACE ((stderr
, " garbaged\n"));
25401 /* If basic faces haven't been realized yet, there is no point in
25402 trying to redraw anything. This can happen when we get an expose
25403 event while Emacs is starting, e.g. by moving another window. */
25404 if (FRAME_FACE_CACHE (f
) == NULL
25405 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
25407 TRACE ((stderr
, " no faces\n"));
25411 if (w
== 0 || h
== 0)
25414 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
25415 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
25425 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
25426 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
25428 if (WINDOWP (f
->tool_bar_window
))
25429 mouse_face_overwritten_p
25430 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
25432 #ifdef HAVE_X_WINDOWS
25434 #ifndef USE_X_TOOLKIT
25435 if (WINDOWP (f
->menu_bar_window
))
25436 mouse_face_overwritten_p
25437 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
25438 #endif /* not USE_X_TOOLKIT */
25442 /* Some window managers support a focus-follows-mouse style with
25443 delayed raising of frames. Imagine a partially obscured frame,
25444 and moving the mouse into partially obscured mouse-face on that
25445 frame. The visible part of the mouse-face will be highlighted,
25446 then the WM raises the obscured frame. With at least one WM, KDE
25447 2.1, Emacs is not getting any event for the raising of the frame
25448 (even tried with SubstructureRedirectMask), only Expose events.
25449 These expose events will draw text normally, i.e. not
25450 highlighted. Which means we must redo the highlight here.
25451 Subsume it under ``we love X''. --gerd 2001-08-15 */
25452 /* Included in Windows version because Windows most likely does not
25453 do the right thing if any third party tool offers
25454 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
25455 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
25457 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25458 if (f
== dpyinfo
->mouse_face_mouse_frame
)
25460 int x
= dpyinfo
->mouse_face_mouse_x
;
25461 int y
= dpyinfo
->mouse_face_mouse_y
;
25462 clear_mouse_face (dpyinfo
);
25463 note_mouse_highlight (f
, x
, y
);
25470 Determine the intersection of two rectangles R1 and R2. Return
25471 the intersection in *RESULT. Value is non-zero if RESULT is not
25475 x_intersect_rectangles (r1
, r2
, result
)
25476 XRectangle
*r1
, *r2
, *result
;
25478 XRectangle
*left
, *right
;
25479 XRectangle
*upper
, *lower
;
25480 int intersection_p
= 0;
25482 /* Rearrange so that R1 is the left-most rectangle. */
25484 left
= r1
, right
= r2
;
25486 left
= r2
, right
= r1
;
25488 /* X0 of the intersection is right.x0, if this is inside R1,
25489 otherwise there is no intersection. */
25490 if (right
->x
<= left
->x
+ left
->width
)
25492 result
->x
= right
->x
;
25494 /* The right end of the intersection is the minimum of the
25495 the right ends of left and right. */
25496 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
25499 /* Same game for Y. */
25501 upper
= r1
, lower
= r2
;
25503 upper
= r2
, lower
= r1
;
25505 /* The upper end of the intersection is lower.y0, if this is inside
25506 of upper. Otherwise, there is no intersection. */
25507 if (lower
->y
<= upper
->y
+ upper
->height
)
25509 result
->y
= lower
->y
;
25511 /* The lower end of the intersection is the minimum of the lower
25512 ends of upper and lower. */
25513 result
->height
= (min (lower
->y
+ lower
->height
,
25514 upper
->y
+ upper
->height
)
25516 intersection_p
= 1;
25520 return intersection_p
;
25523 #endif /* HAVE_WINDOW_SYSTEM */
25526 /***********************************************************************
25528 ***********************************************************************/
25533 Vwith_echo_area_save_vector
= Qnil
;
25534 staticpro (&Vwith_echo_area_save_vector
);
25536 Vmessage_stack
= Qnil
;
25537 staticpro (&Vmessage_stack
);
25539 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
25540 staticpro (&Qinhibit_redisplay
);
25542 message_dolog_marker1
= Fmake_marker ();
25543 staticpro (&message_dolog_marker1
);
25544 message_dolog_marker2
= Fmake_marker ();
25545 staticpro (&message_dolog_marker2
);
25546 message_dolog_marker3
= Fmake_marker ();
25547 staticpro (&message_dolog_marker3
);
25550 defsubr (&Sdump_frame_glyph_matrix
);
25551 defsubr (&Sdump_glyph_matrix
);
25552 defsubr (&Sdump_glyph_row
);
25553 defsubr (&Sdump_tool_bar_row
);
25554 defsubr (&Strace_redisplay
);
25555 defsubr (&Strace_to_stderr
);
25557 #ifdef HAVE_WINDOW_SYSTEM
25558 defsubr (&Stool_bar_lines_needed
);
25559 defsubr (&Slookup_image_map
);
25561 defsubr (&Sformat_mode_line
);
25562 defsubr (&Sinvisible_p
);
25564 staticpro (&Qmenu_bar_update_hook
);
25565 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
25567 staticpro (&Qoverriding_terminal_local_map
);
25568 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
25570 staticpro (&Qoverriding_local_map
);
25571 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
25573 staticpro (&Qwindow_scroll_functions
);
25574 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
25576 staticpro (&Qwindow_text_change_functions
);
25577 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
25579 staticpro (&Qredisplay_end_trigger_functions
);
25580 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
25582 staticpro (&Qinhibit_point_motion_hooks
);
25583 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
25585 Qeval
= intern_c_string ("eval");
25586 staticpro (&Qeval
);
25588 QCdata
= intern_c_string (":data");
25589 staticpro (&QCdata
);
25590 Qdisplay
= intern_c_string ("display");
25591 staticpro (&Qdisplay
);
25592 Qspace_width
= intern_c_string ("space-width");
25593 staticpro (&Qspace_width
);
25594 Qraise
= intern_c_string ("raise");
25595 staticpro (&Qraise
);
25596 Qslice
= intern_c_string ("slice");
25597 staticpro (&Qslice
);
25598 Qspace
= intern_c_string ("space");
25599 staticpro (&Qspace
);
25600 Qmargin
= intern_c_string ("margin");
25601 staticpro (&Qmargin
);
25602 Qpointer
= intern_c_string ("pointer");
25603 staticpro (&Qpointer
);
25604 Qleft_margin
= intern_c_string ("left-margin");
25605 staticpro (&Qleft_margin
);
25606 Qright_margin
= intern_c_string ("right-margin");
25607 staticpro (&Qright_margin
);
25608 Qcenter
= intern_c_string ("center");
25609 staticpro (&Qcenter
);
25610 Qline_height
= intern_c_string ("line-height");
25611 staticpro (&Qline_height
);
25612 QCalign_to
= intern_c_string (":align-to");
25613 staticpro (&QCalign_to
);
25614 QCrelative_width
= intern_c_string (":relative-width");
25615 staticpro (&QCrelative_width
);
25616 QCrelative_height
= intern_c_string (":relative-height");
25617 staticpro (&QCrelative_height
);
25618 QCeval
= intern_c_string (":eval");
25619 staticpro (&QCeval
);
25620 QCpropertize
= intern_c_string (":propertize");
25621 staticpro (&QCpropertize
);
25622 QCfile
= intern_c_string (":file");
25623 staticpro (&QCfile
);
25624 Qfontified
= intern_c_string ("fontified");
25625 staticpro (&Qfontified
);
25626 Qfontification_functions
= intern_c_string ("fontification-functions");
25627 staticpro (&Qfontification_functions
);
25628 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
25629 staticpro (&Qtrailing_whitespace
);
25630 Qescape_glyph
= intern_c_string ("escape-glyph");
25631 staticpro (&Qescape_glyph
);
25632 Qnobreak_space
= intern_c_string ("nobreak-space");
25633 staticpro (&Qnobreak_space
);
25634 Qimage
= intern_c_string ("image");
25635 staticpro (&Qimage
);
25636 QCmap
= intern_c_string (":map");
25637 staticpro (&QCmap
);
25638 QCpointer
= intern_c_string (":pointer");
25639 staticpro (&QCpointer
);
25640 Qrect
= intern_c_string ("rect");
25641 staticpro (&Qrect
);
25642 Qcircle
= intern_c_string ("circle");
25643 staticpro (&Qcircle
);
25644 Qpoly
= intern_c_string ("poly");
25645 staticpro (&Qpoly
);
25646 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
25647 staticpro (&Qmessage_truncate_lines
);
25648 Qgrow_only
= intern_c_string ("grow-only");
25649 staticpro (&Qgrow_only
);
25650 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
25651 staticpro (&Qinhibit_menubar_update
);
25652 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
25653 staticpro (&Qinhibit_eval_during_redisplay
);
25654 Qposition
= intern_c_string ("position");
25655 staticpro (&Qposition
);
25656 Qbuffer_position
= intern_c_string ("buffer-position");
25657 staticpro (&Qbuffer_position
);
25658 Qobject
= intern_c_string ("object");
25659 staticpro (&Qobject
);
25660 Qbar
= intern_c_string ("bar");
25662 Qhbar
= intern_c_string ("hbar");
25663 staticpro (&Qhbar
);
25664 Qbox
= intern_c_string ("box");
25666 Qhollow
= intern_c_string ("hollow");
25667 staticpro (&Qhollow
);
25668 Qhand
= intern_c_string ("hand");
25669 staticpro (&Qhand
);
25670 Qarrow
= intern_c_string ("arrow");
25671 staticpro (&Qarrow
);
25672 Qtext
= intern_c_string ("text");
25673 staticpro (&Qtext
);
25674 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
25675 staticpro (&Qrisky_local_variable
);
25676 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
25677 staticpro (&Qinhibit_free_realized_faces
);
25679 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
25680 Fcons (intern_c_string ("void-variable"), Qnil
)),
25682 staticpro (&list_of_error
);
25684 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
25685 staticpro (&Qlast_arrow_position
);
25686 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
25687 staticpro (&Qlast_arrow_string
);
25689 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
25690 staticpro (&Qoverlay_arrow_string
);
25691 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
25692 staticpro (&Qoverlay_arrow_bitmap
);
25694 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
25695 staticpro (&echo_buffer
[0]);
25696 staticpro (&echo_buffer
[1]);
25698 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
25699 staticpro (&echo_area_buffer
[0]);
25700 staticpro (&echo_area_buffer
[1]);
25702 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
25703 staticpro (&Vmessages_buffer_name
);
25705 mode_line_proptrans_alist
= Qnil
;
25706 staticpro (&mode_line_proptrans_alist
);
25707 mode_line_string_list
= Qnil
;
25708 staticpro (&mode_line_string_list
);
25709 mode_line_string_face
= Qnil
;
25710 staticpro (&mode_line_string_face
);
25711 mode_line_string_face_prop
= Qnil
;
25712 staticpro (&mode_line_string_face_prop
);
25713 Vmode_line_unwind_vector
= Qnil
;
25714 staticpro (&Vmode_line_unwind_vector
);
25716 help_echo_string
= Qnil
;
25717 staticpro (&help_echo_string
);
25718 help_echo_object
= Qnil
;
25719 staticpro (&help_echo_object
);
25720 help_echo_window
= Qnil
;
25721 staticpro (&help_echo_window
);
25722 previous_help_echo_string
= Qnil
;
25723 staticpro (&previous_help_echo_string
);
25724 help_echo_pos
= -1;
25726 Qright_to_left
= intern_c_string ("right-to-left");
25727 staticpro (&Qright_to_left
);
25728 Qleft_to_right
= intern_c_string ("left-to-right");
25729 staticpro (&Qleft_to_right
);
25731 #ifdef HAVE_WINDOW_SYSTEM
25732 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
25733 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
25734 For example, if a block cursor is over a tab, it will be drawn as
25735 wide as that tab on the display. */);
25736 x_stretch_cursor_p
= 0;
25739 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
25740 doc
: /* *Non-nil means highlight trailing whitespace.
25741 The face used for trailing whitespace is `trailing-whitespace'. */);
25742 Vshow_trailing_whitespace
= Qnil
;
25744 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
25745 doc
: /* *Control highlighting of nobreak space and soft hyphen.
25746 A value of t means highlight the character itself (for nobreak space,
25747 use face `nobreak-space').
25748 A value of nil means no highlighting.
25749 Other values mean display the escape glyph followed by an ordinary
25750 space or ordinary hyphen. */);
25751 Vnobreak_char_display
= Qt
;
25753 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
25754 doc
: /* *The pointer shape to show in void text areas.
25755 A value of nil means to show the text pointer. Other options are `arrow',
25756 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
25757 Vvoid_text_area_pointer
= Qarrow
;
25759 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
25760 doc
: /* Non-nil means don't actually do any redisplay.
25761 This is used for internal purposes. */);
25762 Vinhibit_redisplay
= Qnil
;
25764 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
25765 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
25766 Vglobal_mode_string
= Qnil
;
25768 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
25769 doc
: /* Marker for where to display an arrow on top of the buffer text.
25770 This must be the beginning of a line in order to work.
25771 See also `overlay-arrow-string'. */);
25772 Voverlay_arrow_position
= Qnil
;
25774 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
25775 doc
: /* String to display as an arrow in non-window frames.
25776 See also `overlay-arrow-position'. */);
25777 Voverlay_arrow_string
= make_pure_c_string ("=>");
25779 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
25780 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
25781 The symbols on this list are examined during redisplay to determine
25782 where to display overlay arrows. */);
25783 Voverlay_arrow_variable_list
25784 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
25786 DEFVAR_INT ("scroll-step", &scroll_step
,
25787 doc
: /* *The number of lines to try scrolling a window by when point moves out.
25788 If that fails to bring point back on frame, point is centered instead.
25789 If this is zero, point is always centered after it moves off frame.
25790 If you want scrolling to always be a line at a time, you should set
25791 `scroll-conservatively' to a large value rather than set this to 1. */);
25793 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
25794 doc
: /* *Scroll up to this many lines, to bring point back on screen.
25795 If point moves off-screen, redisplay will scroll by up to
25796 `scroll-conservatively' lines in order to bring point just barely
25797 onto the screen again. If that cannot be done, then redisplay
25798 recenters point as usual.
25800 A value of zero means always recenter point if it moves off screen. */);
25801 scroll_conservatively
= 0;
25803 DEFVAR_INT ("scroll-margin", &scroll_margin
,
25804 doc
: /* *Number of lines of margin at the top and bottom of a window.
25805 Recenter the window whenever point gets within this many lines
25806 of the top or bottom of the window. */);
25809 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
25810 doc
: /* Pixels per inch value for non-window system displays.
25811 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
25812 Vdisplay_pixels_per_inch
= make_float (72.0);
25815 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
25818 DEFVAR_LISP ("truncate-partial-width-windows",
25819 &Vtruncate_partial_width_windows
,
25820 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
25821 For an integer value, truncate lines in each window narrower than the
25822 full frame width, provided the window width is less than that integer;
25823 otherwise, respect the value of `truncate-lines'.
25825 For any other non-nil value, truncate lines in all windows that do
25826 not span the full frame width.
25828 A value of nil means to respect the value of `truncate-lines'.
25830 If `word-wrap' is enabled, you might want to reduce this. */);
25831 Vtruncate_partial_width_windows
= make_number (50);
25833 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
25834 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
25835 Any other value means to use the appropriate face, `mode-line',
25836 `header-line', or `menu' respectively. */);
25837 mode_line_inverse_video
= 1;
25839 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
25840 doc
: /* *Maximum buffer size for which line number should be displayed.
25841 If the buffer is bigger than this, the line number does not appear
25842 in the mode line. A value of nil means no limit. */);
25843 Vline_number_display_limit
= Qnil
;
25845 DEFVAR_INT ("line-number-display-limit-width",
25846 &line_number_display_limit_width
,
25847 doc
: /* *Maximum line width (in characters) for line number display.
25848 If the average length of the lines near point is bigger than this, then the
25849 line number may be omitted from the mode line. */);
25850 line_number_display_limit_width
= 200;
25852 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
25853 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
25854 highlight_nonselected_windows
= 0;
25856 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
25857 doc
: /* Non-nil if more than one frame is visible on this display.
25858 Minibuffer-only frames don't count, but iconified frames do.
25859 This variable is not guaranteed to be accurate except while processing
25860 `frame-title-format' and `icon-title-format'. */);
25862 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
25863 doc
: /* Template for displaying the title bar of visible frames.
25864 \(Assuming the window manager supports this feature.)
25866 This variable has the same structure as `mode-line-format', except that
25867 the %c and %l constructs are ignored. It is used only on frames for
25868 which no explicit name has been set \(see `modify-frame-parameters'). */);
25870 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
25871 doc
: /* Template for displaying the title bar of an iconified frame.
25872 \(Assuming the window manager supports this feature.)
25873 This variable has the same structure as `mode-line-format' (which see),
25874 and is used only on frames for which no explicit name has been set
25875 \(see `modify-frame-parameters'). */);
25877 = Vframe_title_format
25878 = pure_cons (intern_c_string ("multiple-frames"),
25879 pure_cons (make_pure_c_string ("%b"),
25880 pure_cons (pure_cons (empty_unibyte_string
,
25881 pure_cons (intern_c_string ("invocation-name"),
25882 pure_cons (make_pure_c_string ("@"),
25883 pure_cons (intern_c_string ("system-name"),
25887 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
25888 doc
: /* Maximum number of lines to keep in the message log buffer.
25889 If nil, disable message logging. If t, log messages but don't truncate
25890 the buffer when it becomes large. */);
25891 Vmessage_log_max
= make_number (100);
25893 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
25894 doc
: /* Functions called before redisplay, if window sizes have changed.
25895 The value should be a list of functions that take one argument.
25896 Just before redisplay, for each frame, if any of its windows have changed
25897 size since the last redisplay, or have been split or deleted,
25898 all the functions in the list are called, with the frame as argument. */);
25899 Vwindow_size_change_functions
= Qnil
;
25901 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
25902 doc
: /* List of functions to call before redisplaying a window with scrolling.
25903 Each function is called with two arguments, the window and its new
25904 display-start position. Note that these functions are also called by
25905 `set-window-buffer'. Also note that the value of `window-end' is not
25906 valid when these functions are called. */);
25907 Vwindow_scroll_functions
= Qnil
;
25909 DEFVAR_LISP ("window-text-change-functions",
25910 &Vwindow_text_change_functions
,
25911 doc
: /* Functions to call in redisplay when text in the window might change. */);
25912 Vwindow_text_change_functions
= Qnil
;
25914 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
25915 doc
: /* Functions called when redisplay of a window reaches the end trigger.
25916 Each function is called with two arguments, the window and the end trigger value.
25917 See `set-window-redisplay-end-trigger'. */);
25918 Vredisplay_end_trigger_functions
= Qnil
;
25920 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25921 doc
: /* *Non-nil means autoselect window with mouse pointer.
25922 If nil, do not autoselect windows.
25923 A positive number means delay autoselection by that many seconds: a
25924 window is autoselected only after the mouse has remained in that
25925 window for the duration of the delay.
25926 A negative number has a similar effect, but causes windows to be
25927 autoselected only after the mouse has stopped moving. \(Because of
25928 the way Emacs compares mouse events, you will occasionally wait twice
25929 that time before the window gets selected.\)
25930 Any other value means to autoselect window instantaneously when the
25931 mouse pointer enters it.
25933 Autoselection selects the minibuffer only if it is active, and never
25934 unselects the minibuffer if it is active.
25936 When customizing this variable make sure that the actual value of
25937 `focus-follows-mouse' matches the behavior of your window manager. */);
25938 Vmouse_autoselect_window
= Qnil
;
25940 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25941 doc
: /* *Non-nil means automatically resize tool-bars.
25942 This dynamically changes the tool-bar's height to the minimum height
25943 that is needed to make all tool-bar items visible.
25944 If value is `grow-only', the tool-bar's height is only increased
25945 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25946 Vauto_resize_tool_bars
= Qt
;
25948 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25949 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25950 auto_raise_tool_bar_buttons_p
= 1;
25952 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25953 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25954 make_cursor_line_fully_visible_p
= 1;
25956 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25957 doc
: /* *Border below tool-bar in pixels.
25958 If an integer, use it as the height of the border.
25959 If it is one of `internal-border-width' or `border-width', use the
25960 value of the corresponding frame parameter.
25961 Otherwise, no border is added below the tool-bar. */);
25962 Vtool_bar_border
= Qinternal_border_width
;
25964 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25965 doc
: /* *Margin around tool-bar buttons in pixels.
25966 If an integer, use that for both horizontal and vertical margins.
25967 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25968 HORZ specifying the horizontal margin, and VERT specifying the
25969 vertical margin. */);
25970 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25972 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25973 doc
: /* *Relief thickness of tool-bar buttons. */);
25974 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25976 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25977 doc
: /* List of functions to call to fontify regions of text.
25978 Each function is called with one argument POS. Functions must
25979 fontify a region starting at POS in the current buffer, and give
25980 fontified regions the property `fontified'. */);
25981 Vfontification_functions
= Qnil
;
25982 Fmake_variable_buffer_local (Qfontification_functions
);
25984 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25985 &unibyte_display_via_language_environment
,
25986 doc
: /* *Non-nil means display unibyte text according to language environment.
25987 Specifically, this means that raw bytes in the range 160-255 decimal
25988 are displayed by converting them to the equivalent multibyte characters
25989 according to the current language environment. As a result, they are
25990 displayed according to the current fontset.
25992 Note that this variable affects only how these bytes are displayed,
25993 but does not change the fact they are interpreted as raw bytes. */);
25994 unibyte_display_via_language_environment
= 0;
25996 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25997 doc
: /* *Maximum height for resizing mini-windows.
25998 If a float, it specifies a fraction of the mini-window frame's height.
25999 If an integer, it specifies a number of lines. */);
26000 Vmax_mini_window_height
= make_float (0.25);
26002 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
26003 doc
: /* *How to resize mini-windows.
26004 A value of nil means don't automatically resize mini-windows.
26005 A value of t means resize them to fit the text displayed in them.
26006 A value of `grow-only', the default, means let mini-windows grow
26007 only, until their display becomes empty, at which point the windows
26008 go back to their normal size. */);
26009 Vresize_mini_windows
= Qgrow_only
;
26011 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
26012 doc
: /* Alist specifying how to blink the cursor off.
26013 Each element has the form (ON-STATE . OFF-STATE). Whenever the
26014 `cursor-type' frame-parameter or variable equals ON-STATE,
26015 comparing using `equal', Emacs uses OFF-STATE to specify
26016 how to blink it off. ON-STATE and OFF-STATE are values for
26017 the `cursor-type' frame parameter.
26019 If a frame's ON-STATE has no entry in this list,
26020 the frame's other specifications determine how to blink the cursor off. */);
26021 Vblink_cursor_alist
= Qnil
;
26023 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
26024 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
26025 automatic_hscrolling_p
= 1;
26026 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
26027 staticpro (&Qauto_hscroll_mode
);
26029 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
26030 doc
: /* *How many columns away from the window edge point is allowed to get
26031 before automatic hscrolling will horizontally scroll the window. */);
26032 hscroll_margin
= 5;
26034 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
26035 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
26036 When point is less than `hscroll-margin' columns from the window
26037 edge, automatic hscrolling will scroll the window by the amount of columns
26038 determined by this variable. If its value is a positive integer, scroll that
26039 many columns. If it's a positive floating-point number, it specifies the
26040 fraction of the window's width to scroll. If it's nil or zero, point will be
26041 centered horizontally after the scroll. Any other value, including negative
26042 numbers, are treated as if the value were zero.
26044 Automatic hscrolling always moves point outside the scroll margin, so if
26045 point was more than scroll step columns inside the margin, the window will
26046 scroll more than the value given by the scroll step.
26048 Note that the lower bound for automatic hscrolling specified by `scroll-left'
26049 and `scroll-right' overrides this variable's effect. */);
26050 Vhscroll_step
= make_number (0);
26052 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
26053 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
26054 Bind this around calls to `message' to let it take effect. */);
26055 message_truncate_lines
= 0;
26057 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
26058 doc
: /* Normal hook run to update the menu bar definitions.
26059 Redisplay runs this hook before it redisplays the menu bar.
26060 This is used to update submenus such as Buffers,
26061 whose contents depend on various data. */);
26062 Vmenu_bar_update_hook
= Qnil
;
26064 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
26065 doc
: /* Frame for which we are updating a menu.
26066 The enable predicate for a menu binding should check this variable. */);
26067 Vmenu_updating_frame
= Qnil
;
26069 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
26070 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
26071 inhibit_menubar_update
= 0;
26073 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
26074 doc
: /* Prefix prepended to all continuation lines at display time.
26075 The value may be a string, an image, or a stretch-glyph; it is
26076 interpreted in the same way as the value of a `display' text property.
26078 This variable is overridden by any `wrap-prefix' text or overlay
26081 To add a prefix to non-continuation lines, use `line-prefix'. */);
26082 Vwrap_prefix
= Qnil
;
26083 staticpro (&Qwrap_prefix
);
26084 Qwrap_prefix
= intern_c_string ("wrap-prefix");
26085 Fmake_variable_buffer_local (Qwrap_prefix
);
26087 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
26088 doc
: /* Prefix prepended to all non-continuation lines at display time.
26089 The value may be a string, an image, or a stretch-glyph; it is
26090 interpreted in the same way as the value of a `display' text property.
26092 This variable is overridden by any `line-prefix' text or overlay
26095 To add a prefix to continuation lines, use `wrap-prefix'. */);
26096 Vline_prefix
= Qnil
;
26097 staticpro (&Qline_prefix
);
26098 Qline_prefix
= intern_c_string ("line-prefix");
26099 Fmake_variable_buffer_local (Qline_prefix
);
26101 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
26102 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
26103 inhibit_eval_during_redisplay
= 0;
26105 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
26106 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
26107 inhibit_free_realized_faces
= 0;
26110 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
26111 doc
: /* Inhibit try_window_id display optimization. */);
26112 inhibit_try_window_id
= 0;
26114 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
26115 doc
: /* Inhibit try_window_reusing display optimization. */);
26116 inhibit_try_window_reusing
= 0;
26118 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
26119 doc
: /* Inhibit try_cursor_movement display optimization. */);
26120 inhibit_try_cursor_movement
= 0;
26121 #endif /* GLYPH_DEBUG */
26123 DEFVAR_INT ("overline-margin", &overline_margin
,
26124 doc
: /* *Space between overline and text, in pixels.
26125 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
26126 margin to the caracter height. */);
26127 overline_margin
= 2;
26129 DEFVAR_INT ("underline-minimum-offset",
26130 &underline_minimum_offset
,
26131 doc
: /* Minimum distance between baseline and underline.
26132 This can improve legibility of underlined text at small font sizes,
26133 particularly when using variable `x-use-underline-position-properties'
26134 with fonts that specify an UNDERLINE_POSITION relatively close to the
26135 baseline. The default value is 1. */);
26136 underline_minimum_offset
= 1;
26138 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
26139 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
26140 display_hourglass_p
= 1;
26142 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
26143 doc
: /* *Seconds to wait before displaying an hourglass pointer.
26144 Value must be an integer or float. */);
26145 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
26147 hourglass_atimer
= NULL
;
26148 hourglass_shown_p
= 0;
26152 /* Initialize this module when Emacs starts. */
26157 Lisp_Object root_window
;
26158 struct window
*mini_w
;
26160 current_header_line_height
= current_mode_line_height
= -1;
26162 CHARPOS (this_line_start_pos
) = 0;
26164 mini_w
= XWINDOW (minibuf_window
);
26165 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
26167 if (!noninteractive
)
26169 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
26172 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
26173 set_window_height (root_window
,
26174 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
26176 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
26177 set_window_height (minibuf_window
, 1, 0);
26179 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
26180 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
26182 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
26183 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
26184 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
26186 /* The default ellipsis glyphs `...'. */
26187 for (i
= 0; i
< 3; ++i
)
26188 default_invis_vector
[i
] = make_number ('.');
26192 /* Allocate the buffer for frame titles.
26193 Also used for `format-mode-line'. */
26195 mode_line_noprop_buf
= (char *) xmalloc (size
);
26196 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
26197 mode_line_noprop_ptr
= mode_line_noprop_buf
;
26198 mode_line_target
= MODE_LINE_DISPLAY
;
26201 help_echo_showing_p
= 0;
26204 /* Since w32 does not support atimers, it defines its own implementation of
26205 the following three functions in w32fns.c. */
26208 /* Platform-independent portion of hourglass implementation. */
26210 /* Return non-zero if houglass timer has been started or hourglass is shown. */
26212 hourglass_started ()
26214 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
26217 /* Cancel a currently active hourglass timer, and start a new one. */
26221 #if defined (HAVE_WINDOW_SYSTEM)
26223 int secs
, usecs
= 0;
26225 cancel_hourglass ();
26227 if (INTEGERP (Vhourglass_delay
)
26228 && XINT (Vhourglass_delay
) > 0)
26229 secs
= XFASTINT (Vhourglass_delay
);
26230 else if (FLOATP (Vhourglass_delay
)
26231 && XFLOAT_DATA (Vhourglass_delay
) > 0)
26234 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
26235 secs
= XFASTINT (tem
);
26236 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
26239 secs
= DEFAULT_HOURGLASS_DELAY
;
26241 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
26242 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
26243 show_hourglass
, NULL
);
26248 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
26251 cancel_hourglass ()
26253 #if defined (HAVE_WINDOW_SYSTEM)
26254 if (hourglass_atimer
)
26256 cancel_atimer (hourglass_atimer
);
26257 hourglass_atimer
= NULL
;
26260 if (hourglass_shown_p
)
26264 #endif /* ! WINDOWSNT */
26266 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
26267 (do not change this comment) */