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. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
175 #include "keyboard.h"
178 #include "termchar.h"
179 #include "dispextern.h"
181 #include "character.h"
184 #include "commands.h"
188 #include "termhooks.h"
189 #include "intervals.h"
192 #include "region-cache.h"
195 #include "blockinput.h"
197 #ifdef HAVE_X_WINDOWS
212 #ifndef FRAME_X_OUTPUT
213 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
216 #define INFINITY 10000000
218 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
219 || defined(HAVE_NS) || defined (USE_GTK)
220 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
221 extern int pending_menu_activation
;
224 extern int interrupt_input
;
225 extern int command_loop_level
;
227 extern Lisp_Object do_mouse_tracking
;
229 extern int minibuffer_auto_raise
;
230 extern Lisp_Object Vminibuffer_list
;
232 extern Lisp_Object Qface
;
233 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
235 extern Lisp_Object Voverriding_local_map
;
236 extern Lisp_Object Voverriding_local_map_menu_flag
;
237 extern Lisp_Object Qmenu_item
;
238 extern Lisp_Object Qwhen
;
239 extern Lisp_Object Qhelp_echo
;
240 extern Lisp_Object Qbefore_string
, Qafter_string
;
242 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
243 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
244 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
245 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
246 Lisp_Object Qinhibit_point_motion_hooks
;
247 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
248 Lisp_Object Qfontified
;
249 Lisp_Object Qgrow_only
;
250 Lisp_Object Qinhibit_eval_during_redisplay
;
251 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
252 Lisp_Object Qright_to_left
, Qleft_to_right
;
255 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
258 Lisp_Object Qarrow
, Qhand
, Qtext
;
260 Lisp_Object Qrisky_local_variable
;
262 /* Holds the list (error). */
263 Lisp_Object list_of_error
;
265 /* Functions called to fontify regions of text. */
267 Lisp_Object Vfontification_functions
;
268 Lisp_Object Qfontification_functions
;
270 /* Non-nil means automatically select any window when the mouse
271 cursor moves into it. */
272 Lisp_Object Vmouse_autoselect_window
;
274 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
275 Lisp_Object Vline_prefix
, Qline_prefix
;
277 /* Non-zero means draw tool bar buttons raised when the mouse moves
280 int auto_raise_tool_bar_buttons_p
;
282 /* Non-zero means to reposition window if cursor line is only partially visible. */
284 int make_cursor_line_fully_visible_p
;
286 /* Margin below tool bar in pixels. 0 or nil means no margin.
287 If value is `internal-border-width' or `border-width',
288 the corresponding frame parameter is used. */
290 Lisp_Object Vtool_bar_border
;
292 /* Margin around tool bar buttons in pixels. */
294 Lisp_Object Vtool_bar_button_margin
;
296 /* Thickness of shadow to draw around tool bar buttons. */
298 EMACS_INT tool_bar_button_relief
;
300 /* Non-nil means automatically resize tool-bars so that all tool-bar
301 items are visible, and no blank lines remain.
303 If value is `grow-only', only make tool-bar bigger. */
305 Lisp_Object Vauto_resize_tool_bars
;
307 /* Non-zero means draw block and hollow cursor as wide as the glyph
308 under it. For example, if a block cursor is over a tab, it will be
309 drawn as wide as that tab on the display. */
311 int x_stretch_cursor_p
;
313 /* Non-nil means don't actually do any redisplay. */
315 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
317 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
319 int inhibit_eval_during_redisplay
;
321 /* Names of text properties relevant for redisplay. */
323 Lisp_Object Qdisplay
;
324 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
326 /* Symbols used in text property values. */
328 Lisp_Object Vdisplay_pixels_per_inch
;
329 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
330 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
333 Lisp_Object Qmargin
, Qpointer
;
334 Lisp_Object Qline_height
;
335 extern Lisp_Object Qheight
;
336 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
337 extern Lisp_Object Qscroll_bar
;
338 extern Lisp_Object Qcursor
;
340 /* Non-nil means highlight trailing whitespace. */
342 Lisp_Object Vshow_trailing_whitespace
;
344 /* Non-nil means escape non-break space and hyphens. */
346 Lisp_Object Vnobreak_char_display
;
348 #ifdef HAVE_WINDOW_SYSTEM
349 extern Lisp_Object Voverflow_newline_into_fringe
;
351 /* Test if overflow newline into fringe. Called with iterator IT
352 at or past right window margin, and with IT->current_x set. */
354 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
355 (!NILP (Voverflow_newline_into_fringe) \
356 && FRAME_WINDOW_P (it->f) \
357 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
358 && it->current_x == it->last_visible_x \
359 && it->line_wrap != WORD_WRAP)
361 #else /* !HAVE_WINDOW_SYSTEM */
362 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
363 #endif /* HAVE_WINDOW_SYSTEM */
365 /* Test if the display element loaded in IT is a space or tab
366 character. This is used to determine word wrapping. */
368 #define IT_DISPLAYING_WHITESPACE(it) \
369 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
371 /* Non-nil means show the text cursor in void text areas
372 i.e. in blank areas after eol and eob. This used to be
373 the default in 21.3. */
375 Lisp_Object Vvoid_text_area_pointer
;
377 /* Name of the face used to highlight trailing whitespace. */
379 Lisp_Object Qtrailing_whitespace
;
381 /* Name and number of the face used to highlight escape glyphs. */
383 Lisp_Object Qescape_glyph
;
385 /* Name and number of the face used to highlight non-breaking spaces. */
387 Lisp_Object Qnobreak_space
;
389 /* The symbol `image' which is the car of the lists used to represent
394 /* The image map types. */
395 Lisp_Object QCmap
, QCpointer
;
396 Lisp_Object Qrect
, Qcircle
, Qpoly
;
398 /* Non-zero means print newline to stdout before next mini-buffer
401 int noninteractive_need_newline
;
403 /* Non-zero means print newline to message log before next message. */
405 static int message_log_need_newline
;
407 /* Three markers that message_dolog uses.
408 It could allocate them itself, but that causes trouble
409 in handling memory-full errors. */
410 static Lisp_Object message_dolog_marker1
;
411 static Lisp_Object message_dolog_marker2
;
412 static Lisp_Object message_dolog_marker3
;
414 /* The buffer position of the first character appearing entirely or
415 partially on the line of the selected window which contains the
416 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
417 redisplay optimization in redisplay_internal. */
419 static struct text_pos this_line_start_pos
;
421 /* Number of characters past the end of the line above, including the
422 terminating newline. */
424 static struct text_pos this_line_end_pos
;
426 /* The vertical positions and the height of this line. */
428 static int this_line_vpos
;
429 static int this_line_y
;
430 static int this_line_pixel_height
;
432 /* X position at which this display line starts. Usually zero;
433 negative if first character is partially visible. */
435 static int this_line_start_x
;
437 /* Buffer that this_line_.* variables are referring to. */
439 static struct buffer
*this_line_buffer
;
441 /* Nonzero means truncate lines in all windows less wide than the
444 Lisp_Object Vtruncate_partial_width_windows
;
446 /* A flag to control how to display unibyte 8-bit character. */
448 int unibyte_display_via_language_environment
;
450 /* Nonzero means we have more than one non-mini-buffer-only frame.
451 Not guaranteed to be accurate except while parsing
452 frame-title-format. */
456 Lisp_Object Vglobal_mode_string
;
459 /* List of variables (symbols) which hold markers for overlay arrows.
460 The symbols on this list are examined during redisplay to determine
461 where to display overlay arrows. */
463 Lisp_Object Voverlay_arrow_variable_list
;
465 /* Marker for where to display an arrow on top of the buffer text. */
467 Lisp_Object Voverlay_arrow_position
;
469 /* String to display for the arrow. Only used on terminal frames. */
471 Lisp_Object Voverlay_arrow_string
;
473 /* Values of those variables at last redisplay are stored as
474 properties on `overlay-arrow-position' symbol. However, if
475 Voverlay_arrow_position is a marker, last-arrow-position is its
476 numerical position. */
478 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
480 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
481 properties on a symbol in overlay-arrow-variable-list. */
483 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
485 /* Like mode-line-format, but for the title bar on a visible frame. */
487 Lisp_Object Vframe_title_format
;
489 /* Like mode-line-format, but for the title bar on an iconified frame. */
491 Lisp_Object Vicon_title_format
;
493 /* List of functions to call when a window's size changes. These
494 functions get one arg, a frame on which one or more windows' sizes
497 static Lisp_Object Vwindow_size_change_functions
;
499 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
501 /* Nonzero if an overlay arrow has been displayed in this window. */
503 static int overlay_arrow_seen
;
505 /* Nonzero means highlight the region even in nonselected windows. */
507 int highlight_nonselected_windows
;
509 /* If cursor motion alone moves point off frame, try scrolling this
510 many lines up or down if that will bring it back. */
512 static EMACS_INT scroll_step
;
514 /* Nonzero means scroll just far enough to bring point back on the
515 screen, when appropriate. */
517 static EMACS_INT scroll_conservatively
;
519 /* Recenter the window whenever point gets within this many lines of
520 the top or bottom of the window. This value is translated into a
521 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
522 that there is really a fixed pixel height scroll margin. */
524 EMACS_INT scroll_margin
;
526 /* Number of windows showing the buffer of the selected window (or
527 another buffer with the same base buffer). keyboard.c refers to
532 /* Vector containing glyphs for an ellipsis `...'. */
534 static Lisp_Object default_invis_vector
[3];
536 /* Zero means display the mode-line/header-line/menu-bar in the default face
537 (this slightly odd definition is for compatibility with previous versions
538 of emacs), non-zero means display them using their respective faces.
540 This variable is deprecated. */
542 int mode_line_inverse_video
;
544 /* Prompt to display in front of the mini-buffer contents. */
546 Lisp_Object minibuf_prompt
;
548 /* Width of current mini-buffer prompt. Only set after display_line
549 of the line that contains the prompt. */
551 int minibuf_prompt_width
;
553 /* This is the window where the echo area message was displayed. It
554 is always a mini-buffer window, but it may not be the same window
555 currently active as a mini-buffer. */
557 Lisp_Object echo_area_window
;
559 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
560 pushes the current message and the value of
561 message_enable_multibyte on the stack, the function restore_message
562 pops the stack and displays MESSAGE again. */
564 Lisp_Object Vmessage_stack
;
566 /* Nonzero means multibyte characters were enabled when the echo area
567 message was specified. */
569 int message_enable_multibyte
;
571 /* Nonzero if we should redraw the mode lines on the next redisplay. */
573 int update_mode_lines
;
575 /* Nonzero if window sizes or contents have changed since last
576 redisplay that finished. */
578 int windows_or_buffers_changed
;
580 /* Nonzero means a frame's cursor type has been changed. */
582 int cursor_type_changed
;
584 /* Nonzero after display_mode_line if %l was used and it displayed a
587 int line_number_displayed
;
589 /* Maximum buffer size for which to display line numbers. */
591 Lisp_Object Vline_number_display_limit
;
593 /* Line width to consider when repositioning for line number display. */
595 static EMACS_INT line_number_display_limit_width
;
597 /* Number of lines to keep in the message log buffer. t means
598 infinite. nil means don't log at all. */
600 Lisp_Object Vmessage_log_max
;
602 /* The name of the *Messages* buffer, a string. */
604 static Lisp_Object Vmessages_buffer_name
;
606 /* Current, index 0, and last displayed echo area message. Either
607 buffers from echo_buffers, or nil to indicate no message. */
609 Lisp_Object echo_area_buffer
[2];
611 /* The buffers referenced from echo_area_buffer. */
613 static Lisp_Object echo_buffer
[2];
615 /* A vector saved used in with_area_buffer to reduce consing. */
617 static Lisp_Object Vwith_echo_area_save_vector
;
619 /* Non-zero means display_echo_area should display the last echo area
620 message again. Set by redisplay_preserve_echo_area. */
622 static int display_last_displayed_message_p
;
624 /* Nonzero if echo area is being used by print; zero if being used by
627 int message_buf_print
;
629 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
631 Lisp_Object Qinhibit_menubar_update
;
632 int inhibit_menubar_update
;
634 /* When evaluating expressions from menu bar items (enable conditions,
635 for instance), this is the frame they are being processed for. */
637 Lisp_Object Vmenu_updating_frame
;
639 /* Maximum height for resizing mini-windows. Either a float
640 specifying a fraction of the available height, or an integer
641 specifying a number of lines. */
643 Lisp_Object Vmax_mini_window_height
;
645 /* Non-zero means messages should be displayed with truncated
646 lines instead of being continued. */
648 int message_truncate_lines
;
649 Lisp_Object Qmessage_truncate_lines
;
651 /* Set to 1 in clear_message to make redisplay_internal aware
652 of an emptied echo area. */
654 static int message_cleared_p
;
656 /* How to blink the default frame cursor off. */
657 Lisp_Object Vblink_cursor_alist
;
659 /* A scratch glyph row with contents used for generating truncation
660 glyphs. Also used in direct_output_for_insert. */
662 #define MAX_SCRATCH_GLYPHS 100
663 struct glyph_row scratch_glyph_row
;
664 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
666 /* Ascent and height of the last line processed by move_it_to. */
668 static int last_max_ascent
, last_height
;
670 /* Non-zero if there's a help-echo in the echo area. */
672 int help_echo_showing_p
;
674 /* If >= 0, computed, exact values of mode-line and header-line height
675 to use in the macros CURRENT_MODE_LINE_HEIGHT and
676 CURRENT_HEADER_LINE_HEIGHT. */
678 int current_mode_line_height
, current_header_line_height
;
680 /* The maximum distance to look ahead for text properties. Values
681 that are too small let us call compute_char_face and similar
682 functions too often which is expensive. Values that are too large
683 let us call compute_char_face and alike too often because we
684 might not be interested in text properties that far away. */
686 #define TEXT_PROP_DISTANCE_LIMIT 100
690 /* Variables to turn off display optimizations from Lisp. */
692 int inhibit_try_window_id
, inhibit_try_window_reusing
;
693 int inhibit_try_cursor_movement
;
695 /* Non-zero means print traces of redisplay if compiled with
698 int trace_redisplay_p
;
700 #endif /* GLYPH_DEBUG */
702 #ifdef DEBUG_TRACE_MOVE
703 /* Non-zero means trace with TRACE_MOVE to stderr. */
706 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
708 #define TRACE_MOVE(x) (void) 0
711 /* Non-zero means automatically scroll windows horizontally to make
714 int automatic_hscrolling_p
;
715 Lisp_Object Qauto_hscroll_mode
;
717 /* How close to the margin can point get before the window is scrolled
719 EMACS_INT hscroll_margin
;
721 /* How much to scroll horizontally when point is inside the above margin. */
722 Lisp_Object Vhscroll_step
;
724 /* The variable `resize-mini-windows'. If nil, don't resize
725 mini-windows. If t, always resize them to fit the text they
726 display. If `grow-only', let mini-windows grow only until they
729 Lisp_Object Vresize_mini_windows
;
731 /* Buffer being redisplayed -- for redisplay_window_error. */
733 struct buffer
*displayed_buffer
;
735 /* Space between overline and text. */
737 EMACS_INT overline_margin
;
739 /* Require underline to be at least this many screen pixels below baseline
740 This to avoid underline "merging" with the base of letters at small
741 font sizes, particularly when x_use_underline_position_properties is on. */
743 EMACS_INT underline_minimum_offset
;
745 /* Value returned from text property handlers (see below). */
750 HANDLED_RECOMPUTE_PROPS
,
751 HANDLED_OVERLAY_STRING_CONSUMED
,
755 /* A description of text properties that redisplay is interested
760 /* The name of the property. */
763 /* A unique index for the property. */
766 /* A handler function called to set up iterator IT from the property
767 at IT's current position. Value is used to steer handle_stop. */
768 enum prop_handled (*handler
) P_ ((struct it
*it
));
771 static enum prop_handled handle_face_prop
P_ ((struct it
*));
772 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
773 static enum prop_handled handle_display_prop
P_ ((struct it
*));
774 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
775 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
776 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
778 /* Properties handled by iterators. */
780 static struct props it_props
[] =
782 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
783 /* Handle `face' before `display' because some sub-properties of
784 `display' need to know the face. */
785 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
786 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
787 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
788 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
792 /* Value is the position described by X. If X is a marker, value is
793 the marker_position of X. Otherwise, value is X. */
795 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
797 /* Enumeration returned by some move_it_.* functions internally. */
801 /* Not used. Undefined value. */
804 /* Move ended at the requested buffer position or ZV. */
805 MOVE_POS_MATCH_OR_ZV
,
807 /* Move ended at the requested X pixel position. */
810 /* Move within a line ended at the end of a line that must be
814 /* Move within a line ended at the end of a line that would
815 be displayed truncated. */
818 /* Move within a line ended at a line end. */
822 /* This counter is used to clear the face cache every once in a while
823 in redisplay_internal. It is incremented for each redisplay.
824 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
827 #define CLEAR_FACE_CACHE_COUNT 500
828 static int clear_face_cache_count
;
830 /* Similarly for the image cache. */
832 #ifdef HAVE_WINDOW_SYSTEM
833 #define CLEAR_IMAGE_CACHE_COUNT 101
834 static int clear_image_cache_count
;
837 /* Non-zero while redisplay_internal is in progress. */
841 /* Non-zero means don't free realized faces. Bound while freeing
842 realized faces is dangerous because glyph matrices might still
845 int inhibit_free_realized_faces
;
846 Lisp_Object Qinhibit_free_realized_faces
;
848 /* If a string, XTread_socket generates an event to display that string.
849 (The display is done in read_char.) */
851 Lisp_Object help_echo_string
;
852 Lisp_Object help_echo_window
;
853 Lisp_Object help_echo_object
;
856 /* Temporary variable for XTread_socket. */
858 Lisp_Object previous_help_echo_string
;
860 /* Null glyph slice */
862 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
864 /* Platform-independent portion of hourglass implementation. */
866 /* Non-zero means we're allowed to display a hourglass pointer. */
867 int display_hourglass_p
;
869 /* Non-zero means an hourglass cursor is currently shown. */
870 int hourglass_shown_p
;
872 /* If non-null, an asynchronous timer that, when it expires, displays
873 an hourglass cursor on all frames. */
874 struct atimer
*hourglass_atimer
;
876 /* Number of seconds to wait before displaying an hourglass cursor. */
877 Lisp_Object Vhourglass_delay
;
879 /* Default number of seconds to wait before displaying an hourglass
881 #define DEFAULT_HOURGLASS_DELAY 1
884 /* Function prototypes. */
886 static void setup_for_ellipsis
P_ ((struct it
*, int));
887 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
888 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
889 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
890 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
891 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
892 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
894 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
896 static void handle_line_prefix
P_ ((struct it
*));
898 static void pint2str
P_ ((char *, int, int));
899 static void pint2hrstr
P_ ((char *, int, int));
900 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
902 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
903 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
904 static void store_mode_line_noprop_char
P_ ((char));
905 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
906 static void x_consider_frame_title
P_ ((Lisp_Object
));
907 static void handle_stop
P_ ((struct it
*));
908 static void handle_stop_backwards
P_ ((struct it
*, EMACS_INT
));
909 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
910 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
911 static void ensure_echo_area_buffers
P_ ((void));
912 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
913 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
914 static int with_echo_area_buffer
P_ ((struct window
*, int,
915 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
916 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static void clear_garbaged_frames
P_ ((void));
918 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
919 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
920 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
921 static int display_echo_area
P_ ((struct window
*));
922 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
923 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
924 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
925 static int string_char_and_length
P_ ((const unsigned char *, int *));
926 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
928 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
929 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
930 static void insert_left_trunc_glyphs
P_ ((struct it
*));
931 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
933 static void extend_face_to_end_of_line
P_ ((struct it
*));
934 static int append_space_for_newline
P_ ((struct it
*, int));
935 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
936 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
937 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
938 static int trailing_whitespace_p
P_ ((int));
939 static int message_log_check_duplicate
P_ ((int, int, int, int));
940 static void push_it
P_ ((struct it
*));
941 static void pop_it
P_ ((struct it
*));
942 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
943 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
944 static void redisplay_internal
P_ ((int));
945 static int echo_area_display
P_ ((int));
946 static void redisplay_windows
P_ ((Lisp_Object
));
947 static void redisplay_window
P_ ((Lisp_Object
, int));
948 static Lisp_Object
redisplay_window_error ();
949 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
950 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
951 static int update_menu_bar
P_ ((struct frame
*, int, int));
952 static int try_window_reusing_current_matrix
P_ ((struct window
*));
953 static int try_window_id
P_ ((struct window
*));
954 static int display_line
P_ ((struct it
*));
955 static int display_mode_lines
P_ ((struct window
*));
956 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
957 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
958 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
959 static char *decode_mode_spec
P_ ((struct window
*, int, int, int,
961 static void display_menu_bar
P_ ((struct window
*));
962 static int display_count_lines
P_ ((int, int, int, int, int *));
963 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
964 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
965 static void compute_line_metrics
P_ ((struct it
*));
966 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
967 static int get_overlay_strings
P_ ((struct it
*, int));
968 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
969 static void next_overlay_string
P_ ((struct it
*));
970 static void reseat
P_ ((struct it
*, struct text_pos
, int));
971 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
972 static void back_to_previous_visible_line_start
P_ ((struct it
*));
973 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
974 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
975 static int next_element_from_ellipsis
P_ ((struct it
*));
976 static int next_element_from_display_vector
P_ ((struct it
*));
977 static int next_element_from_string
P_ ((struct it
*));
978 static int next_element_from_c_string
P_ ((struct it
*));
979 static int next_element_from_buffer
P_ ((struct it
*));
980 static int next_element_from_composition
P_ ((struct it
*));
981 static int next_element_from_image
P_ ((struct it
*));
982 static int next_element_from_stretch
P_ ((struct it
*));
983 static void load_overlay_strings
P_ ((struct it
*, int));
984 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
985 struct display_pos
*));
986 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
987 Lisp_Object
, int, int, int, int));
988 static enum move_it_result
989 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
990 enum move_operation_enum
);
991 void move_it_vertically_backward
P_ ((struct it
*, int));
992 static void init_to_row_start
P_ ((struct it
*, struct window
*,
993 struct glyph_row
*));
994 static int init_to_row_end
P_ ((struct it
*, struct window
*,
995 struct glyph_row
*));
996 static void back_to_previous_line_start
P_ ((struct it
*));
997 static int forward_to_next_line_start
P_ ((struct it
*, int *));
998 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
1000 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
1001 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
1002 static int number_of_chars
P_ ((unsigned char *, int));
1003 static void compute_stop_pos
P_ ((struct it
*));
1004 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1006 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1007 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1008 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1009 Lisp_Object
, Lisp_Object
,
1010 struct text_pos
*, int));
1011 static int underlying_face_id
P_ ((struct it
*));
1012 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1015 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1016 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1018 #ifdef HAVE_WINDOW_SYSTEM
1020 static void update_tool_bar
P_ ((struct frame
*, int));
1021 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1022 static int redisplay_tool_bar
P_ ((struct frame
*));
1023 static void display_tool_bar_line
P_ ((struct it
*, int));
1024 static void notice_overwritten_cursor
P_ ((struct window
*,
1025 enum glyph_row_area
,
1026 int, int, int, int));
1030 #endif /* HAVE_WINDOW_SYSTEM */
1033 /***********************************************************************
1034 Window display dimensions
1035 ***********************************************************************/
1037 /* Return the bottom boundary y-position for text lines in window W.
1038 This is the first y position at which a line cannot start.
1039 It is relative to the top of the window.
1041 This is the height of W minus the height of a mode line, if any. */
1044 window_text_bottom_y (w
)
1047 int height
= WINDOW_TOTAL_HEIGHT (w
);
1049 if (WINDOW_WANTS_MODELINE_P (w
))
1050 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1054 /* Return the pixel width of display area AREA of window W. AREA < 0
1055 means return the total width of W, not including fringes to
1056 the left and right of the window. */
1059 window_box_width (w
, area
)
1063 int cols
= XFASTINT (w
->total_cols
);
1066 if (!w
->pseudo_window_p
)
1068 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1070 if (area
== TEXT_AREA
)
1072 if (INTEGERP (w
->left_margin_cols
))
1073 cols
-= XFASTINT (w
->left_margin_cols
);
1074 if (INTEGERP (w
->right_margin_cols
))
1075 cols
-= XFASTINT (w
->right_margin_cols
);
1076 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1078 else if (area
== LEFT_MARGIN_AREA
)
1080 cols
= (INTEGERP (w
->left_margin_cols
)
1081 ? XFASTINT (w
->left_margin_cols
) : 0);
1084 else if (area
== RIGHT_MARGIN_AREA
)
1086 cols
= (INTEGERP (w
->right_margin_cols
)
1087 ? XFASTINT (w
->right_margin_cols
) : 0);
1092 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1096 /* Return the pixel height of the display area of window W, not
1097 including mode lines of W, if any. */
1100 window_box_height (w
)
1103 struct frame
*f
= XFRAME (w
->frame
);
1104 int height
= WINDOW_TOTAL_HEIGHT (w
);
1106 xassert (height
>= 0);
1108 /* Note: the code below that determines the mode-line/header-line
1109 height is essentially the same as that contained in the macro
1110 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1111 the appropriate glyph row has its `mode_line_p' flag set,
1112 and if it doesn't, uses estimate_mode_line_height instead. */
1114 if (WINDOW_WANTS_MODELINE_P (w
))
1116 struct glyph_row
*ml_row
1117 = (w
->current_matrix
&& w
->current_matrix
->rows
1118 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1120 if (ml_row
&& ml_row
->mode_line_p
)
1121 height
-= ml_row
->height
;
1123 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1126 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1128 struct glyph_row
*hl_row
1129 = (w
->current_matrix
&& w
->current_matrix
->rows
1130 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1132 if (hl_row
&& hl_row
->mode_line_p
)
1133 height
-= hl_row
->height
;
1135 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1138 /* With a very small font and a mode-line that's taller than
1139 default, we might end up with a negative height. */
1140 return max (0, height
);
1143 /* Return the window-relative coordinate of the left edge of display
1144 area AREA of window W. AREA < 0 means return the left edge of the
1145 whole window, to the right of the left fringe of W. */
1148 window_box_left_offset (w
, area
)
1154 if (w
->pseudo_window_p
)
1157 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1159 if (area
== TEXT_AREA
)
1160 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1161 + window_box_width (w
, LEFT_MARGIN_AREA
));
1162 else if (area
== RIGHT_MARGIN_AREA
)
1163 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1164 + window_box_width (w
, LEFT_MARGIN_AREA
)
1165 + window_box_width (w
, TEXT_AREA
)
1166 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1168 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1169 else if (area
== LEFT_MARGIN_AREA
1170 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1171 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1177 /* Return the window-relative coordinate of the right edge of display
1178 area AREA of window W. AREA < 0 means return the left edge of the
1179 whole window, to the left of the right fringe of W. */
1182 window_box_right_offset (w
, area
)
1186 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1189 /* Return the frame-relative coordinate of the left edge of display
1190 area AREA of window W. AREA < 0 means return the left edge of the
1191 whole window, to the right of the left fringe of W. */
1194 window_box_left (w
, area
)
1198 struct frame
*f
= XFRAME (w
->frame
);
1201 if (w
->pseudo_window_p
)
1202 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1204 x
= (WINDOW_LEFT_EDGE_X (w
)
1205 + window_box_left_offset (w
, area
));
1211 /* Return the frame-relative coordinate of the right edge of display
1212 area AREA of window W. AREA < 0 means return the left edge of the
1213 whole window, to the left of the right fringe of W. */
1216 window_box_right (w
, area
)
1220 return window_box_left (w
, area
) + window_box_width (w
, area
);
1223 /* Get the bounding box of the display area AREA of window W, without
1224 mode lines, in frame-relative coordinates. AREA < 0 means the
1225 whole window, not including the left and right fringes of
1226 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1227 coordinates of the upper-left corner of the box. Return in
1228 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1231 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1234 int *box_x
, *box_y
, *box_width
, *box_height
;
1237 *box_width
= window_box_width (w
, area
);
1239 *box_height
= window_box_height (w
);
1241 *box_x
= window_box_left (w
, area
);
1244 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1245 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1246 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1251 /* Get the bounding box of the display area AREA of window W, without
1252 mode lines. AREA < 0 means the whole window, not including the
1253 left and right fringe of the window. Return in *TOP_LEFT_X
1254 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1255 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1256 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1260 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1261 bottom_right_x
, bottom_right_y
)
1264 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1266 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1268 *bottom_right_x
+= *top_left_x
;
1269 *bottom_right_y
+= *top_left_y
;
1274 /***********************************************************************
1276 ***********************************************************************/
1278 /* Return the bottom y-position of the line the iterator IT is in.
1279 This can modify IT's settings. */
1285 int line_height
= it
->max_ascent
+ it
->max_descent
;
1286 int line_top_y
= it
->current_y
;
1288 if (line_height
== 0)
1291 line_height
= last_height
;
1292 else if (IT_CHARPOS (*it
) < ZV
)
1294 move_it_by_lines (it
, 1, 1);
1295 line_height
= (it
->max_ascent
|| it
->max_descent
1296 ? it
->max_ascent
+ it
->max_descent
1301 struct glyph_row
*row
= it
->glyph_row
;
1303 /* Use the default character height. */
1304 it
->glyph_row
= NULL
;
1305 it
->what
= IT_CHARACTER
;
1308 PRODUCE_GLYPHS (it
);
1309 line_height
= it
->ascent
+ it
->descent
;
1310 it
->glyph_row
= row
;
1314 return line_top_y
+ line_height
;
1318 /* Return 1 if position CHARPOS is visible in window W.
1319 CHARPOS < 0 means return info about WINDOW_END position.
1320 If visible, set *X and *Y to pixel coordinates of top left corner.
1321 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1322 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1325 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1327 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1330 struct text_pos top
;
1332 struct buffer
*old_buffer
= NULL
;
1334 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1337 if (XBUFFER (w
->buffer
) != current_buffer
)
1339 old_buffer
= current_buffer
;
1340 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1343 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1345 /* Compute exact mode line heights. */
1346 if (WINDOW_WANTS_MODELINE_P (w
))
1347 current_mode_line_height
1348 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1349 current_buffer
->mode_line_format
);
1351 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1352 current_header_line_height
1353 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1354 current_buffer
->header_line_format
);
1356 start_display (&it
, w
, top
);
1357 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1358 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1360 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1362 /* We have reached CHARPOS, or passed it. How the call to
1363 move_it_to can overshoot: (i) If CHARPOS is on invisible
1364 text, move_it_to stops at the end of the invisible text,
1365 after CHARPOS. (ii) If CHARPOS is in a display vector,
1366 move_it_to stops on its last glyph. */
1367 int top_x
= it
.current_x
;
1368 int top_y
= it
.current_y
;
1369 enum it_method it_method
= it
.method
;
1370 /* Calling line_bottom_y may change it.method, it.position, etc. */
1371 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1372 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1374 if (top_y
< window_top_y
)
1375 visible_p
= bottom_y
> window_top_y
;
1376 else if (top_y
< it
.last_visible_y
)
1380 if (it_method
== GET_FROM_BUFFER
)
1382 Lisp_Object window
, prop
;
1384 XSETWINDOW (window
, w
);
1385 prop
= Fget_char_property (make_number (charpos
),
1386 Qinvisible
, window
);
1388 /* If charpos coincides with invisible text covered with an
1389 ellipsis, use the first glyph of the ellipsis to compute
1390 the pixel positions. */
1391 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1393 struct glyph_row
*row
= it
.glyph_row
;
1394 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1395 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1399 && (!BUFFERP (glyph
->object
)
1400 || glyph
->charpos
< charpos
);
1402 x
+= glyph
->pixel_width
;
1406 else if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1408 /* We stopped on the last glyph of a display vector.
1409 Try and recompute. Hack alert! */
1410 if (charpos
< 2 || top
.charpos
>= charpos
)
1411 top_x
= it
.glyph_row
->x
;
1415 start_display (&it2
, w
, top
);
1416 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1417 get_next_display_element (&it2
);
1418 PRODUCE_GLYPHS (&it2
);
1419 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1420 || it2
.current_x
> it2
.last_visible_x
)
1421 top_x
= it
.glyph_row
->x
;
1424 top_x
= it2
.current_x
;
1425 top_y
= it2
.current_y
;
1431 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1432 *rtop
= max (0, window_top_y
- top_y
);
1433 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1434 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1435 - max (top_y
, window_top_y
)));
1444 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1445 move_it_by_lines (&it
, 1, 0);
1446 if (charpos
< IT_CHARPOS (it
)
1447 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1450 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1452 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1453 *rtop
= max (0, -it2
.current_y
);
1454 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1455 - it
.last_visible_y
));
1456 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1458 - max (it2
.current_y
,
1459 WINDOW_HEADER_LINE_HEIGHT (w
))));
1465 set_buffer_internal_1 (old_buffer
);
1467 current_header_line_height
= current_mode_line_height
= -1;
1469 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1470 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1473 /* Debugging code. */
1475 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1476 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1478 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1485 /* Return the next character from STR which is MAXLEN bytes long.
1486 Return in *LEN the length of the character. This is like
1487 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1488 we find one, we return a `?', but with the length of the invalid
1492 string_char_and_length (str
, len
)
1493 const unsigned char *str
;
1498 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1499 if (!CHAR_VALID_P (c
, 1))
1500 /* We may not change the length here because other places in Emacs
1501 don't use this function, i.e. they silently accept invalid
1510 /* Given a position POS containing a valid character and byte position
1511 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1513 static struct text_pos
1514 string_pos_nchars_ahead (pos
, string
, nchars
)
1515 struct text_pos pos
;
1519 xassert (STRINGP (string
) && nchars
>= 0);
1521 if (STRING_MULTIBYTE (string
))
1523 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1524 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1529 string_char_and_length (p
, &len
);
1530 p
+= len
, rest
-= len
;
1531 xassert (rest
>= 0);
1533 BYTEPOS (pos
) += len
;
1537 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1543 /* Value is the text position, i.e. character and byte position,
1544 for character position CHARPOS in STRING. */
1546 static INLINE
struct text_pos
1547 string_pos (charpos
, string
)
1551 struct text_pos pos
;
1552 xassert (STRINGP (string
));
1553 xassert (charpos
>= 0);
1554 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1559 /* Value is a text position, i.e. character and byte position, for
1560 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1561 means recognize multibyte characters. */
1563 static struct text_pos
1564 c_string_pos (charpos
, s
, multibyte_p
)
1569 struct text_pos pos
;
1571 xassert (s
!= NULL
);
1572 xassert (charpos
>= 0);
1576 int rest
= strlen (s
), len
;
1578 SET_TEXT_POS (pos
, 0, 0);
1581 string_char_and_length (s
, &len
);
1582 s
+= len
, rest
-= len
;
1583 xassert (rest
>= 0);
1585 BYTEPOS (pos
) += len
;
1589 SET_TEXT_POS (pos
, charpos
, charpos
);
1595 /* Value is the number of characters in C string S. MULTIBYTE_P
1596 non-zero means recognize multibyte characters. */
1599 number_of_chars (s
, multibyte_p
)
1607 int rest
= strlen (s
), len
;
1608 unsigned char *p
= (unsigned char *) s
;
1610 for (nchars
= 0; rest
> 0; ++nchars
)
1612 string_char_and_length (p
, &len
);
1613 rest
-= len
, p
+= len
;
1617 nchars
= strlen (s
);
1623 /* Compute byte position NEWPOS->bytepos corresponding to
1624 NEWPOS->charpos. POS is a known position in string STRING.
1625 NEWPOS->charpos must be >= POS.charpos. */
1628 compute_string_pos (newpos
, pos
, string
)
1629 struct text_pos
*newpos
, pos
;
1632 xassert (STRINGP (string
));
1633 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1635 if (STRING_MULTIBYTE (string
))
1636 *newpos
= string_pos_nchars_ahead (pos
, string
,
1637 CHARPOS (*newpos
) - CHARPOS (pos
));
1639 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1643 Return an estimation of the pixel height of mode or header lines on
1644 frame F. FACE_ID specifies what line's height to estimate. */
1647 estimate_mode_line_height (f
, face_id
)
1649 enum face_id face_id
;
1651 #ifdef HAVE_WINDOW_SYSTEM
1652 if (FRAME_WINDOW_P (f
))
1654 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1656 /* This function is called so early when Emacs starts that the face
1657 cache and mode line face are not yet initialized. */
1658 if (FRAME_FACE_CACHE (f
))
1660 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1664 height
= FONT_HEIGHT (face
->font
);
1665 if (face
->box_line_width
> 0)
1666 height
+= 2 * face
->box_line_width
;
1677 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1678 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1679 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1680 not force the value into range. */
1683 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1685 register int pix_x
, pix_y
;
1687 NativeRectangle
*bounds
;
1691 #ifdef HAVE_WINDOW_SYSTEM
1692 if (FRAME_WINDOW_P (f
))
1694 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1695 even for negative values. */
1697 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1699 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1701 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1702 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1705 STORE_NATIVE_RECT (*bounds
,
1706 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1707 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1708 FRAME_COLUMN_WIDTH (f
) - 1,
1709 FRAME_LINE_HEIGHT (f
) - 1);
1715 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1716 pix_x
= FRAME_TOTAL_COLS (f
);
1720 else if (pix_y
> FRAME_LINES (f
))
1721 pix_y
= FRAME_LINES (f
);
1731 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1732 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1733 can't tell the positions because W's display is not up to date,
1737 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1740 int *frame_x
, *frame_y
;
1742 #ifdef HAVE_WINDOW_SYSTEM
1743 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1747 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1748 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1750 if (display_completed
)
1752 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1753 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1754 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1760 hpos
+= glyph
->pixel_width
;
1764 /* If first glyph is partially visible, its first visible position is still 0. */
1776 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1777 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1788 #ifdef HAVE_WINDOW_SYSTEM
1790 /* Find the glyph under window-relative coordinates X/Y in window W.
1791 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1792 strings. Return in *HPOS and *VPOS the row and column number of
1793 the glyph found. Return in *AREA the glyph area containing X.
1794 Value is a pointer to the glyph found or null if X/Y is not on
1795 text, or we can't tell because W's current matrix is not up to
1800 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1803 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1805 struct glyph
*glyph
, *end
;
1806 struct glyph_row
*row
= NULL
;
1809 /* Find row containing Y. Give up if some row is not enabled. */
1810 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1812 row
= MATRIX_ROW (w
->current_matrix
, i
);
1813 if (!row
->enabled_p
)
1815 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1822 /* Give up if Y is not in the window. */
1823 if (i
== w
->current_matrix
->nrows
)
1826 /* Get the glyph area containing X. */
1827 if (w
->pseudo_window_p
)
1834 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1836 *area
= LEFT_MARGIN_AREA
;
1837 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1839 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1842 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1846 *area
= RIGHT_MARGIN_AREA
;
1847 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1851 /* Find glyph containing X. */
1852 glyph
= row
->glyphs
[*area
];
1853 end
= glyph
+ row
->used
[*area
];
1855 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1857 x
-= glyph
->pixel_width
;
1867 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1870 *hpos
= glyph
- row
->glyphs
[*area
];
1876 Convert frame-relative x/y to coordinates relative to window W.
1877 Takes pseudo-windows into account. */
1880 frame_to_window_pixel_xy (w
, x
, y
)
1884 if (w
->pseudo_window_p
)
1886 /* A pseudo-window is always full-width, and starts at the
1887 left edge of the frame, plus a frame border. */
1888 struct frame
*f
= XFRAME (w
->frame
);
1889 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1890 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1894 *x
-= WINDOW_LEFT_EDGE_X (w
);
1895 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1900 Return in RECTS[] at most N clipping rectangles for glyph string S.
1901 Return the number of stored rectangles. */
1904 get_glyph_string_clip_rects (s
, rects
, n
)
1905 struct glyph_string
*s
;
1906 NativeRectangle
*rects
;
1914 if (s
->row
->full_width_p
)
1916 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1917 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1918 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1920 /* Unless displaying a mode or menu bar line, which are always
1921 fully visible, clip to the visible part of the row. */
1922 if (s
->w
->pseudo_window_p
)
1923 r
.height
= s
->row
->visible_height
;
1925 r
.height
= s
->height
;
1929 /* This is a text line that may be partially visible. */
1930 r
.x
= window_box_left (s
->w
, s
->area
);
1931 r
.width
= window_box_width (s
->w
, s
->area
);
1932 r
.height
= s
->row
->visible_height
;
1936 if (r
.x
< s
->clip_head
->x
)
1938 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1939 r
.width
-= s
->clip_head
->x
- r
.x
;
1942 r
.x
= s
->clip_head
->x
;
1945 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1947 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1948 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1953 /* If S draws overlapping rows, it's sufficient to use the top and
1954 bottom of the window for clipping because this glyph string
1955 intentionally draws over other lines. */
1956 if (s
->for_overlaps
)
1958 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1959 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1961 /* Alas, the above simple strategy does not work for the
1962 environments with anti-aliased text: if the same text is
1963 drawn onto the same place multiple times, it gets thicker.
1964 If the overlap we are processing is for the erased cursor, we
1965 take the intersection with the rectagle of the cursor. */
1966 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1968 XRectangle rc
, r_save
= r
;
1970 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1971 rc
.y
= s
->w
->phys_cursor
.y
;
1972 rc
.width
= s
->w
->phys_cursor_width
;
1973 rc
.height
= s
->w
->phys_cursor_height
;
1975 x_intersect_rectangles (&r_save
, &rc
, &r
);
1980 /* Don't use S->y for clipping because it doesn't take partially
1981 visible lines into account. For example, it can be negative for
1982 partially visible lines at the top of a window. */
1983 if (!s
->row
->full_width_p
1984 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1985 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1987 r
.y
= max (0, s
->row
->y
);
1990 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1992 /* If drawing the cursor, don't let glyph draw outside its
1993 advertised boundaries. Cleartype does this under some circumstances. */
1994 if (s
->hl
== DRAW_CURSOR
)
1996 struct glyph
*glyph
= s
->first_glyph
;
2001 r
.width
-= s
->x
- r
.x
;
2004 r
.width
= min (r
.width
, glyph
->pixel_width
);
2006 /* If r.y is below window bottom, ensure that we still see a cursor. */
2007 height
= min (glyph
->ascent
+ glyph
->descent
,
2008 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2009 max_y
= window_text_bottom_y (s
->w
) - height
;
2010 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2011 if (s
->ybase
- glyph
->ascent
> max_y
)
2018 /* Don't draw cursor glyph taller than our actual glyph. */
2019 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2020 if (height
< r
.height
)
2022 max_y
= r
.y
+ r
.height
;
2023 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2024 r
.height
= min (max_y
- r
.y
, height
);
2031 XRectangle r_save
= r
;
2033 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2037 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2038 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2040 #ifdef CONVERT_FROM_XRECT
2041 CONVERT_FROM_XRECT (r
, *rects
);
2049 /* If we are processing overlapping and allowed to return
2050 multiple clipping rectangles, we exclude the row of the glyph
2051 string from the clipping rectangle. This is to avoid drawing
2052 the same text on the environment with anti-aliasing. */
2053 #ifdef CONVERT_FROM_XRECT
2056 XRectangle
*rs
= rects
;
2058 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2060 if (s
->for_overlaps
& OVERLAPS_PRED
)
2063 if (r
.y
+ r
.height
> row_y
)
2066 rs
[i
].height
= row_y
- r
.y
;
2072 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2075 if (r
.y
< row_y
+ s
->row
->visible_height
)
2077 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2079 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2080 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2089 #ifdef CONVERT_FROM_XRECT
2090 for (i
= 0; i
< n
; i
++)
2091 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2098 Return in *NR the clipping rectangle for glyph string S. */
2101 get_glyph_string_clip_rect (s
, nr
)
2102 struct glyph_string
*s
;
2103 NativeRectangle
*nr
;
2105 get_glyph_string_clip_rects (s
, nr
, 1);
2110 Return the position and height of the phys cursor in window W.
2111 Set w->phys_cursor_width to width of phys cursor.
2115 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2117 struct glyph_row
*row
;
2118 struct glyph
*glyph
;
2119 int *xp
, *yp
, *heightp
;
2121 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2122 int x
, y
, wd
, h
, h0
, y0
;
2124 /* Compute the width of the rectangle to draw. If on a stretch
2125 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2126 rectangle as wide as the glyph, but use a canonical character
2128 wd
= glyph
->pixel_width
- 1;
2129 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2133 x
= w
->phys_cursor
.x
;
2140 if (glyph
->type
== STRETCH_GLYPH
2141 && !x_stretch_cursor_p
)
2142 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2143 w
->phys_cursor_width
= wd
;
2145 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2147 /* If y is below window bottom, ensure that we still see a cursor. */
2148 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2150 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2151 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2153 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2156 h
= max (h
- (y0
- y
) + 1, h0
);
2161 y0
= window_text_bottom_y (w
) - h0
;
2169 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2170 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2175 * Remember which glyph the mouse is over.
2179 remember_mouse_glyph (f
, gx
, gy
, rect
)
2182 NativeRectangle
*rect
;
2186 struct glyph_row
*r
, *gr
, *end_row
;
2187 enum window_part part
;
2188 enum glyph_row_area area
;
2189 int x
, y
, width
, height
;
2191 /* Try to determine frame pixel position and size of the glyph under
2192 frame pixel coordinates X/Y on frame F. */
2194 if (!f
->glyphs_initialized_p
2195 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2198 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2199 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2203 w
= XWINDOW (window
);
2204 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2205 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2207 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2208 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2210 if (w
->pseudo_window_p
)
2213 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2219 case ON_LEFT_MARGIN
:
2220 area
= LEFT_MARGIN_AREA
;
2223 case ON_RIGHT_MARGIN
:
2224 area
= RIGHT_MARGIN_AREA
;
2227 case ON_HEADER_LINE
:
2229 gr
= (part
== ON_HEADER_LINE
2230 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2231 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2234 goto text_glyph_row_found
;
2241 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2242 if (r
->y
+ r
->height
> y
)
2248 text_glyph_row_found
:
2251 struct glyph
*g
= gr
->glyphs
[area
];
2252 struct glyph
*end
= g
+ gr
->used
[area
];
2254 height
= gr
->height
;
2255 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2256 if (gx
+ g
->pixel_width
> x
)
2261 if (g
->type
== IMAGE_GLYPH
)
2263 /* Don't remember when mouse is over image, as
2264 image may have hot-spots. */
2265 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2268 width
= g
->pixel_width
;
2272 /* Use nominal char spacing at end of line. */
2274 gx
+= (x
/ width
) * width
;
2277 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2278 gx
+= window_box_left_offset (w
, area
);
2282 /* Use nominal line height at end of window. */
2283 gx
= (x
/ width
) * width
;
2285 gy
+= (y
/ height
) * height
;
2289 case ON_LEFT_FRINGE
:
2290 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2291 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2292 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2293 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2296 case ON_RIGHT_FRINGE
:
2297 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2298 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2299 : window_box_right_offset (w
, TEXT_AREA
));
2300 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2304 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2306 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2307 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2308 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2310 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2314 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2315 if (r
->y
+ r
->height
> y
)
2322 height
= gr
->height
;
2325 /* Use nominal line height at end of window. */
2327 gy
+= (y
/ height
) * height
;
2334 /* If there is no glyph under the mouse, then we divide the screen
2335 into a grid of the smallest glyph in the frame, and use that
2338 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2339 round down even for negative values. */
2345 gx
= (gx
/ width
) * width
;
2346 gy
= (gy
/ height
) * height
;
2351 gx
+= WINDOW_LEFT_EDGE_X (w
);
2352 gy
+= WINDOW_TOP_EDGE_Y (w
);
2355 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2357 /* Visible feedback for debugging. */
2360 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2361 f
->output_data
.x
->normal_gc
,
2362 gx
, gy
, width
, height
);
2368 #endif /* HAVE_WINDOW_SYSTEM */
2371 /***********************************************************************
2372 Lisp form evaluation
2373 ***********************************************************************/
2375 /* Error handler for safe_eval and safe_call. */
2378 safe_eval_handler (arg
)
2381 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2386 /* Evaluate SEXPR and return the result, or nil if something went
2387 wrong. Prevent redisplay during the evaluation. */
2389 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2390 Return the result, or nil if something went wrong. Prevent
2391 redisplay during the evaluation. */
2394 safe_call (nargs
, args
)
2400 if (inhibit_eval_during_redisplay
)
2404 int count
= SPECPDL_INDEX ();
2405 struct gcpro gcpro1
;
2408 gcpro1
.nvars
= nargs
;
2409 specbind (Qinhibit_redisplay
, Qt
);
2410 /* Use Qt to ensure debugger does not run,
2411 so there is no possibility of wanting to redisplay. */
2412 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2415 val
= unbind_to (count
, val
);
2422 /* Call function FN with one argument ARG.
2423 Return the result, or nil if something went wrong. */
2426 safe_call1 (fn
, arg
)
2427 Lisp_Object fn
, arg
;
2429 Lisp_Object args
[2];
2432 return safe_call (2, args
);
2435 static Lisp_Object Qeval
;
2438 safe_eval (Lisp_Object sexpr
)
2440 return safe_call1 (Qeval
, sexpr
);
2443 /* Call function FN with one argument ARG.
2444 Return the result, or nil if something went wrong. */
2447 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2449 Lisp_Object args
[3];
2453 return safe_call (3, args
);
2458 /***********************************************************************
2460 ***********************************************************************/
2464 /* Define CHECK_IT to perform sanity checks on iterators.
2465 This is for debugging. It is too slow to do unconditionally. */
2471 if (it
->method
== GET_FROM_STRING
)
2473 xassert (STRINGP (it
->string
));
2474 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2478 xassert (IT_STRING_CHARPOS (*it
) < 0);
2479 if (it
->method
== GET_FROM_BUFFER
)
2481 /* Check that character and byte positions agree. */
2482 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2487 xassert (it
->current
.dpvec_index
>= 0);
2489 xassert (it
->current
.dpvec_index
< 0);
2492 #define CHECK_IT(IT) check_it ((IT))
2496 #define CHECK_IT(IT) (void) 0
2503 /* Check that the window end of window W is what we expect it
2504 to be---the last row in the current matrix displaying text. */
2507 check_window_end (w
)
2510 if (!MINI_WINDOW_P (w
)
2511 && !NILP (w
->window_end_valid
))
2513 struct glyph_row
*row
;
2514 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2515 XFASTINT (w
->window_end_vpos
)),
2517 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2518 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2522 #define CHECK_WINDOW_END(W) check_window_end ((W))
2524 #else /* not GLYPH_DEBUG */
2526 #define CHECK_WINDOW_END(W) (void) 0
2528 #endif /* not GLYPH_DEBUG */
2532 /***********************************************************************
2533 Iterator initialization
2534 ***********************************************************************/
2536 /* Initialize IT for displaying current_buffer in window W, starting
2537 at character position CHARPOS. CHARPOS < 0 means that no buffer
2538 position is specified which is useful when the iterator is assigned
2539 a position later. BYTEPOS is the byte position corresponding to
2540 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2542 If ROW is not null, calls to produce_glyphs with IT as parameter
2543 will produce glyphs in that row.
2545 BASE_FACE_ID is the id of a base face to use. It must be one of
2546 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2547 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2548 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2550 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2551 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2552 will be initialized to use the corresponding mode line glyph row of
2553 the desired matrix of W. */
2556 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2559 int charpos
, bytepos
;
2560 struct glyph_row
*row
;
2561 enum face_id base_face_id
;
2563 int highlight_region_p
;
2564 enum face_id remapped_base_face_id
= base_face_id
;
2566 /* Some precondition checks. */
2567 xassert (w
!= NULL
&& it
!= NULL
);
2568 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2571 /* If face attributes have been changed since the last redisplay,
2572 free realized faces now because they depend on face definitions
2573 that might have changed. Don't free faces while there might be
2574 desired matrices pending which reference these faces. */
2575 if (face_change_count
&& !inhibit_free_realized_faces
)
2577 face_change_count
= 0;
2578 free_all_realized_faces (Qnil
);
2581 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2582 if (! NILP (Vface_remapping_alist
))
2583 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2585 /* Use one of the mode line rows of W's desired matrix if
2589 if (base_face_id
== MODE_LINE_FACE_ID
2590 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2591 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2592 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2593 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2597 bzero (it
, sizeof *it
);
2598 it
->current
.overlay_string_index
= -1;
2599 it
->current
.dpvec_index
= -1;
2600 it
->base_face_id
= remapped_base_face_id
;
2602 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2604 /* The window in which we iterate over current_buffer: */
2605 XSETWINDOW (it
->window
, w
);
2607 it
->f
= XFRAME (w
->frame
);
2611 /* Extra space between lines (on window systems only). */
2612 if (base_face_id
== DEFAULT_FACE_ID
2613 && FRAME_WINDOW_P (it
->f
))
2615 if (NATNUMP (current_buffer
->extra_line_spacing
))
2616 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2617 else if (FLOATP (current_buffer
->extra_line_spacing
))
2618 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2619 * FRAME_LINE_HEIGHT (it
->f
));
2620 else if (it
->f
->extra_line_spacing
> 0)
2621 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2622 it
->max_extra_line_spacing
= 0;
2625 /* If realized faces have been removed, e.g. because of face
2626 attribute changes of named faces, recompute them. When running
2627 in batch mode, the face cache of the initial frame is null. If
2628 we happen to get called, make a dummy face cache. */
2629 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2630 init_frame_faces (it
->f
);
2631 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2632 recompute_basic_faces (it
->f
);
2634 /* Current value of the `slice', `space-width', and 'height' properties. */
2635 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2636 it
->space_width
= Qnil
;
2637 it
->font_height
= Qnil
;
2638 it
->override_ascent
= -1;
2640 /* Are control characters displayed as `^C'? */
2641 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2643 /* -1 means everything between a CR and the following line end
2644 is invisible. >0 means lines indented more than this value are
2646 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2647 ? XFASTINT (current_buffer
->selective_display
)
2648 : (!NILP (current_buffer
->selective_display
)
2650 it
->selective_display_ellipsis_p
2651 = !NILP (current_buffer
->selective_display_ellipses
);
2653 /* Display table to use. */
2654 it
->dp
= window_display_table (w
);
2656 /* Are multibyte characters enabled in current_buffer? */
2657 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2659 /* Do we need to reorder bidirectional text? */
2660 it
->bidi_p
= !NILP (current_buffer
->bidi_display_reordering
);
2662 /* Non-zero if we should highlight the region. */
2664 = (!NILP (Vtransient_mark_mode
)
2665 && !NILP (current_buffer
->mark_active
)
2666 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2668 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2669 start and end of a visible region in window IT->w. Set both to
2670 -1 to indicate no region. */
2671 if (highlight_region_p
2672 /* Maybe highlight only in selected window. */
2673 && (/* Either show region everywhere. */
2674 highlight_nonselected_windows
2675 /* Or show region in the selected window. */
2676 || w
== XWINDOW (selected_window
)
2677 /* Or show the region if we are in the mini-buffer and W is
2678 the window the mini-buffer refers to. */
2679 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2680 && WINDOWP (minibuf_selected_window
)
2681 && w
== XWINDOW (minibuf_selected_window
))))
2683 int charpos
= marker_position (current_buffer
->mark
);
2684 it
->region_beg_charpos
= min (PT
, charpos
);
2685 it
->region_end_charpos
= max (PT
, charpos
);
2688 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2690 /* Get the position at which the redisplay_end_trigger hook should
2691 be run, if it is to be run at all. */
2692 if (MARKERP (w
->redisplay_end_trigger
)
2693 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2694 it
->redisplay_end_trigger_charpos
2695 = marker_position (w
->redisplay_end_trigger
);
2696 else if (INTEGERP (w
->redisplay_end_trigger
))
2697 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2699 /* Correct bogus values of tab_width. */
2700 it
->tab_width
= XINT (current_buffer
->tab_width
);
2701 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2704 /* Are lines in the display truncated? */
2705 if (base_face_id
!= DEFAULT_FACE_ID
2706 || XINT (it
->w
->hscroll
)
2707 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2708 && ((!NILP (Vtruncate_partial_width_windows
)
2709 && !INTEGERP (Vtruncate_partial_width_windows
))
2710 || (INTEGERP (Vtruncate_partial_width_windows
)
2711 && (WINDOW_TOTAL_COLS (it
->w
)
2712 < XINT (Vtruncate_partial_width_windows
))))))
2713 it
->line_wrap
= TRUNCATE
;
2714 else if (NILP (current_buffer
->truncate_lines
))
2715 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2716 ? WINDOW_WRAP
: WORD_WRAP
;
2718 it
->line_wrap
= TRUNCATE
;
2720 /* Get dimensions of truncation and continuation glyphs. These are
2721 displayed as fringe bitmaps under X, so we don't need them for such
2723 if (!FRAME_WINDOW_P (it
->f
))
2725 if (it
->line_wrap
== TRUNCATE
)
2727 /* We will need the truncation glyph. */
2728 xassert (it
->glyph_row
== NULL
);
2729 produce_special_glyphs (it
, IT_TRUNCATION
);
2730 it
->truncation_pixel_width
= it
->pixel_width
;
2734 /* We will need the continuation glyph. */
2735 xassert (it
->glyph_row
== NULL
);
2736 produce_special_glyphs (it
, IT_CONTINUATION
);
2737 it
->continuation_pixel_width
= it
->pixel_width
;
2740 /* Reset these values to zero because the produce_special_glyphs
2741 above has changed them. */
2742 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2743 it
->phys_ascent
= it
->phys_descent
= 0;
2746 /* Set this after getting the dimensions of truncation and
2747 continuation glyphs, so that we don't produce glyphs when calling
2748 produce_special_glyphs, above. */
2749 it
->glyph_row
= row
;
2750 it
->area
= TEXT_AREA
;
2752 /* Get the dimensions of the display area. The display area
2753 consists of the visible window area plus a horizontally scrolled
2754 part to the left of the window. All x-values are relative to the
2755 start of this total display area. */
2756 if (base_face_id
!= DEFAULT_FACE_ID
)
2758 /* Mode lines, menu bar in terminal frames. */
2759 it
->first_visible_x
= 0;
2760 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2765 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2766 it
->last_visible_x
= (it
->first_visible_x
2767 + window_box_width (w
, TEXT_AREA
));
2769 /* If we truncate lines, leave room for the truncator glyph(s) at
2770 the right margin. Otherwise, leave room for the continuation
2771 glyph(s). Truncation and continuation glyphs are not inserted
2772 for window-based redisplay. */
2773 if (!FRAME_WINDOW_P (it
->f
))
2775 if (it
->line_wrap
== TRUNCATE
)
2776 it
->last_visible_x
-= it
->truncation_pixel_width
;
2778 it
->last_visible_x
-= it
->continuation_pixel_width
;
2781 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2782 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2785 /* Leave room for a border glyph. */
2786 if (!FRAME_WINDOW_P (it
->f
)
2787 && !WINDOW_RIGHTMOST_P (it
->w
))
2788 it
->last_visible_x
-= 1;
2790 it
->last_visible_y
= window_text_bottom_y (w
);
2792 /* For mode lines and alike, arrange for the first glyph having a
2793 left box line if the face specifies a box. */
2794 if (base_face_id
!= DEFAULT_FACE_ID
)
2798 it
->face_id
= remapped_base_face_id
;
2800 /* If we have a boxed mode line, make the first character appear
2801 with a left box line. */
2802 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2803 if (face
->box
!= FACE_NO_BOX
)
2804 it
->start_of_box_run_p
= 1;
2807 /* If we are to reorder bidirectional text, init the bidi
2811 /* Note the paragraph direction that this buffer wants to
2813 if (EQ (current_buffer
->bidi_paragraph_direction
, Qleft_to_right
))
2814 it
->paragraph_embedding
= L2R
;
2815 else if (EQ (current_buffer
->bidi_paragraph_direction
, Qright_to_left
))
2816 it
->paragraph_embedding
= R2L
;
2818 it
->paragraph_embedding
= NEUTRAL_DIR
;
2819 bidi_init_it (charpos
, bytepos
, &it
->bidi_it
);
2822 /* If a buffer position was specified, set the iterator there,
2823 getting overlays and face properties from that position. */
2824 if (charpos
>= BUF_BEG (current_buffer
))
2826 it
->end_charpos
= ZV
;
2828 IT_CHARPOS (*it
) = charpos
;
2830 /* Compute byte position if not specified. */
2831 if (bytepos
< charpos
)
2832 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2834 IT_BYTEPOS (*it
) = bytepos
;
2836 it
->start
= it
->current
;
2838 /* Compute faces etc. */
2839 reseat (it
, it
->current
.pos
, 1);
2846 /* Initialize IT for the display of window W with window start POS. */
2849 start_display (it
, w
, pos
)
2852 struct text_pos pos
;
2854 struct glyph_row
*row
;
2855 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2857 row
= w
->desired_matrix
->rows
+ first_vpos
;
2858 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2859 it
->first_vpos
= first_vpos
;
2861 /* Don't reseat to previous visible line start if current start
2862 position is in a string or image. */
2863 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2865 int start_at_line_beg_p
;
2866 int first_y
= it
->current_y
;
2868 /* If window start is not at a line start, skip forward to POS to
2869 get the correct continuation lines width. */
2870 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2871 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2872 if (!start_at_line_beg_p
)
2876 reseat_at_previous_visible_line_start (it
);
2877 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2879 new_x
= it
->current_x
+ it
->pixel_width
;
2881 /* If lines are continued, this line may end in the middle
2882 of a multi-glyph character (e.g. a control character
2883 displayed as \003, or in the middle of an overlay
2884 string). In this case move_it_to above will not have
2885 taken us to the start of the continuation line but to the
2886 end of the continued line. */
2887 if (it
->current_x
> 0
2888 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2889 && (/* And glyph doesn't fit on the line. */
2890 new_x
> it
->last_visible_x
2891 /* Or it fits exactly and we're on a window
2893 || (new_x
== it
->last_visible_x
2894 && FRAME_WINDOW_P (it
->f
))))
2896 if (it
->current
.dpvec_index
>= 0
2897 || it
->current
.overlay_string_index
>= 0)
2899 set_iterator_to_next (it
, 1);
2900 move_it_in_display_line_to (it
, -1, -1, 0);
2903 it
->continuation_lines_width
+= it
->current_x
;
2906 /* We're starting a new display line, not affected by the
2907 height of the continued line, so clear the appropriate
2908 fields in the iterator structure. */
2909 it
->max_ascent
= it
->max_descent
= 0;
2910 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2912 it
->current_y
= first_y
;
2914 it
->current_x
= it
->hpos
= 0;
2920 /* Return 1 if POS is a position in ellipses displayed for invisible
2921 text. W is the window we display, for text property lookup. */
2924 in_ellipses_for_invisible_text_p (pos
, w
)
2925 struct display_pos
*pos
;
2928 Lisp_Object prop
, window
;
2930 int charpos
= CHARPOS (pos
->pos
);
2932 /* If POS specifies a position in a display vector, this might
2933 be for an ellipsis displayed for invisible text. We won't
2934 get the iterator set up for delivering that ellipsis unless
2935 we make sure that it gets aware of the invisible text. */
2936 if (pos
->dpvec_index
>= 0
2937 && pos
->overlay_string_index
< 0
2938 && CHARPOS (pos
->string_pos
) < 0
2940 && (XSETWINDOW (window
, w
),
2941 prop
= Fget_char_property (make_number (charpos
),
2942 Qinvisible
, window
),
2943 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2945 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2947 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2954 /* Initialize IT for stepping through current_buffer in window W,
2955 starting at position POS that includes overlay string and display
2956 vector/ control character translation position information. Value
2957 is zero if there are overlay strings with newlines at POS. */
2960 init_from_display_pos (it
, w
, pos
)
2963 struct display_pos
*pos
;
2965 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2966 int i
, overlay_strings_with_newlines
= 0;
2968 /* If POS specifies a position in a display vector, this might
2969 be for an ellipsis displayed for invisible text. We won't
2970 get the iterator set up for delivering that ellipsis unless
2971 we make sure that it gets aware of the invisible text. */
2972 if (in_ellipses_for_invisible_text_p (pos
, w
))
2978 /* Keep in mind: the call to reseat in init_iterator skips invisible
2979 text, so we might end up at a position different from POS. This
2980 is only a problem when POS is a row start after a newline and an
2981 overlay starts there with an after-string, and the overlay has an
2982 invisible property. Since we don't skip invisible text in
2983 display_line and elsewhere immediately after consuming the
2984 newline before the row start, such a POS will not be in a string,
2985 but the call to init_iterator below will move us to the
2987 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2989 /* This only scans the current chunk -- it should scan all chunks.
2990 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2991 to 16 in 22.1 to make this a lesser problem. */
2992 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2994 const char *s
= SDATA (it
->overlay_strings
[i
]);
2995 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2997 while (s
< e
&& *s
!= '\n')
3002 overlay_strings_with_newlines
= 1;
3007 /* If position is within an overlay string, set up IT to the right
3009 if (pos
->overlay_string_index
>= 0)
3013 /* If the first overlay string happens to have a `display'
3014 property for an image, the iterator will be set up for that
3015 image, and we have to undo that setup first before we can
3016 correct the overlay string index. */
3017 if (it
->method
== GET_FROM_IMAGE
)
3020 /* We already have the first chunk of overlay strings in
3021 IT->overlay_strings. Load more until the one for
3022 pos->overlay_string_index is in IT->overlay_strings. */
3023 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3025 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3026 it
->current
.overlay_string_index
= 0;
3029 load_overlay_strings (it
, 0);
3030 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3034 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3035 relative_index
= (it
->current
.overlay_string_index
3036 % OVERLAY_STRING_CHUNK_SIZE
);
3037 it
->string
= it
->overlay_strings
[relative_index
];
3038 xassert (STRINGP (it
->string
));
3039 it
->current
.string_pos
= pos
->string_pos
;
3040 it
->method
= GET_FROM_STRING
;
3043 if (CHARPOS (pos
->string_pos
) >= 0)
3045 /* Recorded position is not in an overlay string, but in another
3046 string. This can only be a string from a `display' property.
3047 IT should already be filled with that string. */
3048 it
->current
.string_pos
= pos
->string_pos
;
3049 xassert (STRINGP (it
->string
));
3052 /* Restore position in display vector translations, control
3053 character translations or ellipses. */
3054 if (pos
->dpvec_index
>= 0)
3056 if (it
->dpvec
== NULL
)
3057 get_next_display_element (it
);
3058 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3059 it
->current
.dpvec_index
= pos
->dpvec_index
;
3063 return !overlay_strings_with_newlines
;
3067 /* Initialize IT for stepping through current_buffer in window W
3068 starting at ROW->start. */
3071 init_to_row_start (it
, w
, row
)
3074 struct glyph_row
*row
;
3076 init_from_display_pos (it
, w
, &row
->start
);
3077 it
->start
= row
->start
;
3078 it
->continuation_lines_width
= row
->continuation_lines_width
;
3083 /* Initialize IT for stepping through current_buffer in window W
3084 starting in the line following ROW, i.e. starting at ROW->end.
3085 Value is zero if there are overlay strings with newlines at ROW's
3089 init_to_row_end (it
, w
, row
)
3092 struct glyph_row
*row
;
3096 if (init_from_display_pos (it
, w
, &row
->end
))
3098 if (row
->continued_p
)
3099 it
->continuation_lines_width
3100 = row
->continuation_lines_width
+ row
->pixel_width
;
3111 /***********************************************************************
3113 ***********************************************************************/
3115 /* Called when IT reaches IT->stop_charpos. Handle text property and
3116 overlay changes. Set IT->stop_charpos to the next position where
3123 enum prop_handled handled
;
3124 int handle_overlay_change_p
;
3128 it
->current
.dpvec_index
= -1;
3129 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3130 it
->ignore_overlay_strings_at_pos_p
= 0;
3133 /* Use face of preceding text for ellipsis (if invisible) */
3134 if (it
->selective_display_ellipsis_p
)
3135 it
->saved_face_id
= it
->face_id
;
3139 handled
= HANDLED_NORMALLY
;
3141 /* Call text property handlers. */
3142 for (p
= it_props
; p
->handler
; ++p
)
3144 handled
= p
->handler (it
);
3146 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3148 else if (handled
== HANDLED_RETURN
)
3150 /* We still want to show before and after strings from
3151 overlays even if the actual buffer text is replaced. */
3152 if (!handle_overlay_change_p
3154 || !get_overlay_strings_1 (it
, 0, 0))
3157 setup_for_ellipsis (it
, 0);
3158 /* When handling a display spec, we might load an
3159 empty string. In that case, discard it here. We
3160 used to discard it in handle_single_display_spec,
3161 but that causes get_overlay_strings_1, above, to
3162 ignore overlay strings that we must check. */
3163 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3167 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3171 it
->ignore_overlay_strings_at_pos_p
= 1;
3172 it
->string_from_display_prop_p
= 0;
3173 handle_overlay_change_p
= 0;
3175 handled
= HANDLED_RECOMPUTE_PROPS
;
3178 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3179 handle_overlay_change_p
= 0;
3182 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3184 /* Don't check for overlay strings below when set to deliver
3185 characters from a display vector. */
3186 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3187 handle_overlay_change_p
= 0;
3189 /* Handle overlay changes.
3190 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3191 if it finds overlays. */
3192 if (handle_overlay_change_p
)
3193 handled
= handle_overlay_change (it
);
3198 setup_for_ellipsis (it
, 0);
3202 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3204 /* Determine where to stop next. */
3205 if (handled
== HANDLED_NORMALLY
)
3206 compute_stop_pos (it
);
3210 /* Compute IT->stop_charpos from text property and overlay change
3211 information for IT's current position. */
3214 compute_stop_pos (it
)
3217 register INTERVAL iv
, next_iv
;
3218 Lisp_Object object
, limit
, position
;
3219 EMACS_INT charpos
, bytepos
;
3221 /* If nowhere else, stop at the end. */
3222 it
->stop_charpos
= it
->end_charpos
;
3224 if (STRINGP (it
->string
))
3226 /* Strings are usually short, so don't limit the search for
3228 object
= it
->string
;
3230 charpos
= IT_STRING_CHARPOS (*it
);
3231 bytepos
= IT_STRING_BYTEPOS (*it
);
3237 /* If next overlay change is in front of the current stop pos
3238 (which is IT->end_charpos), stop there. Note: value of
3239 next_overlay_change is point-max if no overlay change
3241 charpos
= IT_CHARPOS (*it
);
3242 bytepos
= IT_BYTEPOS (*it
);
3243 pos
= next_overlay_change (charpos
);
3244 if (pos
< it
->stop_charpos
)
3245 it
->stop_charpos
= pos
;
3247 /* If showing the region, we have to stop at the region
3248 start or end because the face might change there. */
3249 if (it
->region_beg_charpos
> 0)
3251 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3252 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3253 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3254 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3257 /* Set up variables for computing the stop position from text
3258 property changes. */
3259 XSETBUFFER (object
, current_buffer
);
3260 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3263 /* Get the interval containing IT's position. Value is a null
3264 interval if there isn't such an interval. */
3265 position
= make_number (charpos
);
3266 iv
= validate_interval_range (object
, &position
, &position
, 0);
3267 if (!NULL_INTERVAL_P (iv
))
3269 Lisp_Object values_here
[LAST_PROP_IDX
];
3272 /* Get properties here. */
3273 for (p
= it_props
; p
->handler
; ++p
)
3274 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3276 /* Look for an interval following iv that has different
3278 for (next_iv
= next_interval (iv
);
3279 (!NULL_INTERVAL_P (next_iv
)
3281 || XFASTINT (limit
) > next_iv
->position
));
3282 next_iv
= next_interval (next_iv
))
3284 for (p
= it_props
; p
->handler
; ++p
)
3286 Lisp_Object new_value
;
3288 new_value
= textget (next_iv
->plist
, *p
->name
);
3289 if (!EQ (values_here
[p
->idx
], new_value
))
3297 if (!NULL_INTERVAL_P (next_iv
))
3299 if (INTEGERP (limit
)
3300 && next_iv
->position
>= XFASTINT (limit
))
3301 /* No text property change up to limit. */
3302 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3304 /* Text properties change in next_iv. */
3305 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3309 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3310 it
->stop_charpos
, it
->string
);
3312 xassert (STRINGP (it
->string
)
3313 || (it
->stop_charpos
>= BEGV
3314 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3318 /* Return the position of the next overlay change after POS in
3319 current_buffer. Value is point-max if no overlay change
3320 follows. This is like `next-overlay-change' but doesn't use
3324 next_overlay_change (pos
)
3329 Lisp_Object
*overlays
;
3332 /* Get all overlays at the given position. */
3333 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3335 /* If any of these overlays ends before endpos,
3336 use its ending point instead. */
3337 for (i
= 0; i
< noverlays
; ++i
)
3342 oend
= OVERLAY_END (overlays
[i
]);
3343 oendpos
= OVERLAY_POSITION (oend
);
3344 endpos
= min (endpos
, oendpos
);
3352 /***********************************************************************
3354 ***********************************************************************/
3356 /* Handle changes in the `fontified' property of the current buffer by
3357 calling hook functions from Qfontification_functions to fontify
3360 static enum prop_handled
3361 handle_fontified_prop (it
)
3364 Lisp_Object prop
, pos
;
3365 enum prop_handled handled
= HANDLED_NORMALLY
;
3367 if (!NILP (Vmemory_full
))
3370 /* Get the value of the `fontified' property at IT's current buffer
3371 position. (The `fontified' property doesn't have a special
3372 meaning in strings.) If the value is nil, call functions from
3373 Qfontification_functions. */
3374 if (!STRINGP (it
->string
)
3376 && !NILP (Vfontification_functions
)
3377 && !NILP (Vrun_hooks
)
3378 && (pos
= make_number (IT_CHARPOS (*it
)),
3379 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3380 /* Ignore the special cased nil value always present at EOB since
3381 no amount of fontifying will be able to change it. */
3382 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3384 int count
= SPECPDL_INDEX ();
3387 val
= Vfontification_functions
;
3388 specbind (Qfontification_functions
, Qnil
);
3390 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3391 safe_call1 (val
, pos
);
3394 Lisp_Object globals
, fn
;
3395 struct gcpro gcpro1
, gcpro2
;
3398 GCPRO2 (val
, globals
);
3400 for (; CONSP (val
); val
= XCDR (val
))
3406 /* A value of t indicates this hook has a local
3407 binding; it means to run the global binding too.
3408 In a global value, t should not occur. If it
3409 does, we must ignore it to avoid an endless
3411 for (globals
= Fdefault_value (Qfontification_functions
);
3413 globals
= XCDR (globals
))
3415 fn
= XCAR (globals
);
3417 safe_call1 (fn
, pos
);
3421 safe_call1 (fn
, pos
);
3427 unbind_to (count
, Qnil
);
3429 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3430 something. This avoids an endless loop if they failed to
3431 fontify the text for which reason ever. */
3432 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3433 handled
= HANDLED_RECOMPUTE_PROPS
;
3441 /***********************************************************************
3443 ***********************************************************************/
3445 /* Set up iterator IT from face properties at its current position.
3446 Called from handle_stop. */
3448 static enum prop_handled
3449 handle_face_prop (it
)
3453 EMACS_INT next_stop
;
3455 if (!STRINGP (it
->string
))
3458 = face_at_buffer_position (it
->w
,
3460 it
->region_beg_charpos
,
3461 it
->region_end_charpos
,
3464 + TEXT_PROP_DISTANCE_LIMIT
),
3465 0, it
->base_face_id
);
3467 /* Is this a start of a run of characters with box face?
3468 Caveat: this can be called for a freshly initialized
3469 iterator; face_id is -1 in this case. We know that the new
3470 face will not change until limit, i.e. if the new face has a
3471 box, all characters up to limit will have one. But, as
3472 usual, we don't know whether limit is really the end. */
3473 if (new_face_id
!= it
->face_id
)
3475 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3477 /* If new face has a box but old face has not, this is
3478 the start of a run of characters with box, i.e. it has
3479 a shadow on the left side. The value of face_id of the
3480 iterator will be -1 if this is the initial call that gets
3481 the face. In this case, we have to look in front of IT's
3482 position and see whether there is a face != new_face_id. */
3483 it
->start_of_box_run_p
3484 = (new_face
->box
!= FACE_NO_BOX
3485 && (it
->face_id
>= 0
3486 || IT_CHARPOS (*it
) == BEG
3487 || new_face_id
!= face_before_it_pos (it
)));
3488 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3493 int base_face_id
, bufpos
;
3495 Lisp_Object from_overlay
3496 = (it
->current
.overlay_string_index
>= 0
3497 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3500 /* See if we got to this string directly or indirectly from
3501 an overlay property. That includes the before-string or
3502 after-string of an overlay, strings in display properties
3503 provided by an overlay, their text properties, etc.
3505 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3506 if (! NILP (from_overlay
))
3507 for (i
= it
->sp
- 1; i
>= 0; i
--)
3509 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3511 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3512 else if (! NILP (it
->stack
[i
].from_overlay
))
3513 from_overlay
= it
->stack
[i
].from_overlay
;
3515 if (!NILP (from_overlay
))
3519 if (! NILP (from_overlay
))
3521 bufpos
= IT_CHARPOS (*it
);
3522 /* For a string from an overlay, the base face depends
3523 only on text properties and ignores overlays. */
3525 = face_for_overlay_string (it
->w
,
3527 it
->region_beg_charpos
,
3528 it
->region_end_charpos
,
3531 + TEXT_PROP_DISTANCE_LIMIT
),
3539 /* For strings from a `display' property, use the face at
3540 IT's current buffer position as the base face to merge
3541 with, so that overlay strings appear in the same face as
3542 surrounding text, unless they specify their own
3544 base_face_id
= underlying_face_id (it
);
3547 new_face_id
= face_at_string_position (it
->w
,
3549 IT_STRING_CHARPOS (*it
),
3551 it
->region_beg_charpos
,
3552 it
->region_end_charpos
,
3556 /* Is this a start of a run of characters with box? Caveat:
3557 this can be called for a freshly allocated iterator; face_id
3558 is -1 is this case. We know that the new face will not
3559 change until the next check pos, i.e. if the new face has a
3560 box, all characters up to that position will have a
3561 box. But, as usual, we don't know whether that position
3562 is really the end. */
3563 if (new_face_id
!= it
->face_id
)
3565 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3566 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3568 /* If new face has a box but old face hasn't, this is the
3569 start of a run of characters with box, i.e. it has a
3570 shadow on the left side. */
3571 it
->start_of_box_run_p
3572 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3573 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3577 it
->face_id
= new_face_id
;
3578 return HANDLED_NORMALLY
;
3582 /* Return the ID of the face ``underlying'' IT's current position,
3583 which is in a string. If the iterator is associated with a
3584 buffer, return the face at IT's current buffer position.
3585 Otherwise, use the iterator's base_face_id. */
3588 underlying_face_id (it
)
3591 int face_id
= it
->base_face_id
, i
;
3593 xassert (STRINGP (it
->string
));
3595 for (i
= it
->sp
- 1; i
>= 0; --i
)
3596 if (NILP (it
->stack
[i
].string
))
3597 face_id
= it
->stack
[i
].face_id
;
3603 /* Compute the face one character before or after the current position
3604 of IT. BEFORE_P non-zero means get the face in front of IT's
3605 position. Value is the id of the face. */
3608 face_before_or_after_it_pos (it
, before_p
)
3613 EMACS_INT next_check_charpos
;
3614 struct text_pos pos
;
3616 xassert (it
->s
== NULL
);
3618 if (STRINGP (it
->string
))
3620 int bufpos
, base_face_id
;
3622 /* No face change past the end of the string (for the case
3623 we are padding with spaces). No face change before the
3625 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3626 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3629 /* Set pos to the position before or after IT's current position. */
3631 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3633 /* For composition, we must check the character after the
3635 pos
= (it
->what
== IT_COMPOSITION
3636 ? string_pos (IT_STRING_CHARPOS (*it
)
3637 + it
->cmp_it
.nchars
, it
->string
)
3638 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3640 if (it
->current
.overlay_string_index
>= 0)
3641 bufpos
= IT_CHARPOS (*it
);
3645 base_face_id
= underlying_face_id (it
);
3647 /* Get the face for ASCII, or unibyte. */
3648 face_id
= face_at_string_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 IT->string is unibyte. */
3660 if (STRING_MULTIBYTE (it
->string
))
3662 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3663 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3665 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3667 c
= string_char_and_length (p
, &len
);
3668 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3673 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3674 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3677 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3678 pos
= it
->current
.pos
;
3681 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3684 if (it
->what
== IT_COMPOSITION
)
3685 /* For composition, we must check the position after the
3687 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3689 INC_TEXT_POS (pos
, it
->multibyte_p
);
3692 /* Determine face for CHARSET_ASCII, or unibyte. */
3693 face_id
= face_at_buffer_position (it
->w
,
3695 it
->region_beg_charpos
,
3696 it
->region_end_charpos
,
3697 &next_check_charpos
,
3700 /* Correct the face for charsets different from ASCII. Do it
3701 for the multibyte case only. The face returned above is
3702 suitable for unibyte text if current_buffer is unibyte. */
3703 if (it
->multibyte_p
)
3705 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3706 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3707 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3716 /***********************************************************************
3718 ***********************************************************************/
3720 /* Set up iterator IT from invisible properties at its current
3721 position. Called from handle_stop. */
3723 static enum prop_handled
3724 handle_invisible_prop (it
)
3727 enum prop_handled handled
= HANDLED_NORMALLY
;
3729 if (STRINGP (it
->string
))
3731 extern Lisp_Object Qinvisible
;
3732 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3734 /* Get the value of the invisible text property at the
3735 current position. Value will be nil if there is no such
3737 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3738 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3741 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3743 handled
= HANDLED_RECOMPUTE_PROPS
;
3745 /* Get the position at which the next change of the
3746 invisible text property can be found in IT->string.
3747 Value will be nil if the property value is the same for
3748 all the rest of IT->string. */
3749 XSETINT (limit
, SCHARS (it
->string
));
3750 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3753 /* Text at current position is invisible. The next
3754 change in the property is at position end_charpos.
3755 Move IT's current position to that position. */
3756 if (INTEGERP (end_charpos
)
3757 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3759 struct text_pos old
;
3760 old
= it
->current
.string_pos
;
3761 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3762 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3766 /* The rest of the string is invisible. If this is an
3767 overlay string, proceed with the next overlay string
3768 or whatever comes and return a character from there. */
3769 if (it
->current
.overlay_string_index
>= 0)
3771 next_overlay_string (it
);
3772 /* Don't check for overlay strings when we just
3773 finished processing them. */
3774 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3778 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3779 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3787 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3788 Lisp_Object pos
, prop
, overlay
;
3790 /* First of all, is there invisible text at this position? */
3791 tem
= start_charpos
= IT_CHARPOS (*it
);
3792 pos
= make_number (IT_CHARPOS (*it
));
3793 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3795 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3797 /* If we are on invisible text, skip over it. */
3798 if (invis_p
&& start_charpos
< it
->end_charpos
)
3800 /* Record whether we have to display an ellipsis for the
3802 int display_ellipsis_p
= invis_p
== 2;
3804 handled
= HANDLED_RECOMPUTE_PROPS
;
3806 /* Loop skipping over invisible text. The loop is left at
3807 ZV or with IT on the first char being visible again. */
3810 /* Try to skip some invisible text. Return value is the
3811 position reached which can be equal to where we start
3812 if there is nothing invisible there. This skips both
3813 over invisible text properties and overlays with
3814 invisible property. */
3815 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3817 /* If we skipped nothing at all we weren't at invisible
3818 text in the first place. If everything to the end of
3819 the buffer was skipped, end the loop. */
3820 if (newpos
== tem
|| newpos
>= ZV
)
3824 /* We skipped some characters but not necessarily
3825 all there are. Check if we ended up on visible
3826 text. Fget_char_property returns the property of
3827 the char before the given position, i.e. if we
3828 get invis_p = 0, this means that the char at
3829 newpos is visible. */
3830 pos
= make_number (newpos
);
3831 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3832 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3835 /* If we ended up on invisible text, proceed to
3836 skip starting with next_stop. */
3840 /* If there are adjacent invisible texts, don't lose the
3841 second one's ellipsis. */
3843 display_ellipsis_p
= 1;
3847 /* The position newpos is now either ZV or on visible text. */
3848 if (it
->bidi_p
&& newpos
< ZV
)
3850 /* With bidi iteration, the region of invisible text
3851 could start and/or end in the middle of a non-base
3852 embedding level. Therefore, we need to skip
3853 invisible text using the bidi iterator, starting at
3854 IT's current position, until we find ourselves
3855 outside the invisible text. This avoids affecting
3856 the visual order of the displayed text when invisible
3857 properties are added or removed. */
3860 bidi_get_next_char_visually (&it
->bidi_it
);
3862 while (start_charpos
<= it
->bidi_it
.charpos
3863 && it
->bidi_it
.charpos
< newpos
);
3864 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3865 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3869 IT_CHARPOS (*it
) = newpos
;
3870 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3873 /* If there are before-strings at the start of invisible
3874 text, and the text is invisible because of a text
3875 property, arrange to show before-strings because 20.x did
3876 it that way. (If the text is invisible because of an
3877 overlay property instead of a text property, this is
3878 already handled in the overlay code.) */
3880 && get_overlay_strings (it
, start_charpos
))
3882 handled
= HANDLED_RECOMPUTE_PROPS
;
3883 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3885 else if (display_ellipsis_p
)
3887 /* Make sure that the glyphs of the ellipsis will get
3888 correct `charpos' values. If we would not update
3889 it->position here, the glyphs would belong to the
3890 last visible character _before_ the invisible
3891 text, which confuses `set_cursor_from_row'.
3893 We use the last invisible position instead of the
3894 first because this way the cursor is always drawn on
3895 the first "." of the ellipsis, whenever PT is inside
3896 the invisible text. Otherwise the cursor would be
3897 placed _after_ the ellipsis when the point is after the
3898 first invisible character. */
3899 if (!STRINGP (it
->object
))
3901 it
->position
.charpos
= newpos
- 1;
3902 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3905 /* Let the ellipsis display before
3906 considering any properties of the following char.
3907 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3908 handled
= HANDLED_RETURN
;
3917 /* Make iterator IT return `...' next.
3918 Replaces LEN characters from buffer. */
3921 setup_for_ellipsis (it
, len
)
3925 /* Use the display table definition for `...'. Invalid glyphs
3926 will be handled by the method returning elements from dpvec. */
3927 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3929 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3930 it
->dpvec
= v
->contents
;
3931 it
->dpend
= v
->contents
+ v
->size
;
3935 /* Default `...'. */
3936 it
->dpvec
= default_invis_vector
;
3937 it
->dpend
= default_invis_vector
+ 3;
3940 it
->dpvec_char_len
= len
;
3941 it
->current
.dpvec_index
= 0;
3942 it
->dpvec_face_id
= -1;
3944 /* Remember the current face id in case glyphs specify faces.
3945 IT's face is restored in set_iterator_to_next.
3946 saved_face_id was set to preceding char's face in handle_stop. */
3947 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3948 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3950 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3956 /***********************************************************************
3958 ***********************************************************************/
3960 /* Set up iterator IT from `display' property at its current position.
3961 Called from handle_stop.
3962 We return HANDLED_RETURN if some part of the display property
3963 overrides the display of the buffer text itself.
3964 Otherwise we return HANDLED_NORMALLY. */
3966 static enum prop_handled
3967 handle_display_prop (it
)
3970 Lisp_Object prop
, object
, overlay
;
3971 struct text_pos
*position
;
3972 /* Nonzero if some property replaces the display of the text itself. */
3973 int display_replaced_p
= 0;
3975 if (STRINGP (it
->string
))
3977 object
= it
->string
;
3978 position
= &it
->current
.string_pos
;
3982 XSETWINDOW (object
, it
->w
);
3983 position
= &it
->current
.pos
;
3986 /* Reset those iterator values set from display property values. */
3987 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3988 it
->space_width
= Qnil
;
3989 it
->font_height
= Qnil
;
3992 /* We don't support recursive `display' properties, i.e. string
3993 values that have a string `display' property, that have a string
3994 `display' property etc. */
3995 if (!it
->string_from_display_prop_p
)
3996 it
->area
= TEXT_AREA
;
3998 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3999 Qdisplay
, object
, &overlay
);
4001 return HANDLED_NORMALLY
;
4002 /* Now OVERLAY is the overlay that gave us this property, or nil
4003 if it was a text property. */
4005 if (!STRINGP (it
->string
))
4006 object
= it
->w
->buffer
;
4009 /* Simple properties. */
4010 && !EQ (XCAR (prop
), Qimage
)
4011 && !EQ (XCAR (prop
), Qspace
)
4012 && !EQ (XCAR (prop
), Qwhen
)
4013 && !EQ (XCAR (prop
), Qslice
)
4014 && !EQ (XCAR (prop
), Qspace_width
)
4015 && !EQ (XCAR (prop
), Qheight
)
4016 && !EQ (XCAR (prop
), Qraise
)
4017 /* Marginal area specifications. */
4018 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
4019 && !EQ (XCAR (prop
), Qleft_fringe
)
4020 && !EQ (XCAR (prop
), Qright_fringe
)
4021 && !NILP (XCAR (prop
)))
4023 for (; CONSP (prop
); prop
= XCDR (prop
))
4025 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
4026 position
, display_replaced_p
))
4028 display_replaced_p
= 1;
4029 /* If some text in a string is replaced, `position' no
4030 longer points to the position of `object'. */
4031 if (STRINGP (object
))
4036 else if (VECTORP (prop
))
4039 for (i
= 0; i
< ASIZE (prop
); ++i
)
4040 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4041 position
, display_replaced_p
))
4043 display_replaced_p
= 1;
4044 /* If some text in a string is replaced, `position' no
4045 longer points to the position of `object'. */
4046 if (STRINGP (object
))
4052 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4054 display_replaced_p
= 1;
4057 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4061 /* Value is the position of the end of the `display' property starting
4062 at START_POS in OBJECT. */
4064 static struct text_pos
4065 display_prop_end (it
, object
, start_pos
)
4068 struct text_pos start_pos
;
4071 struct text_pos end_pos
;
4073 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4074 Qdisplay
, object
, Qnil
);
4075 CHARPOS (end_pos
) = XFASTINT (end
);
4076 if (STRINGP (object
))
4077 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4079 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4085 /* Set up IT from a single `display' specification PROP. OBJECT
4086 is the object in which the `display' property was found. *POSITION
4087 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4088 means that we previously saw a display specification which already
4089 replaced text display with something else, for example an image;
4090 we ignore such properties after the first one has been processed.
4092 OVERLAY is the overlay this `display' property came from,
4093 or nil if it was a text property.
4095 If PROP is a `space' or `image' specification, and in some other
4096 cases too, set *POSITION to the position where the `display'
4099 Value is non-zero if something was found which replaces the display
4100 of buffer or string text. */
4103 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4104 display_replaced_before_p
)
4108 Lisp_Object overlay
;
4109 struct text_pos
*position
;
4110 int display_replaced_before_p
;
4113 Lisp_Object location
, value
;
4114 struct text_pos start_pos
, save_pos
;
4117 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4118 If the result is non-nil, use VALUE instead of SPEC. */
4120 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4129 if (!NILP (form
) && !EQ (form
, Qt
))
4131 int count
= SPECPDL_INDEX ();
4132 struct gcpro gcpro1
;
4134 /* Bind `object' to the object having the `display' property, a
4135 buffer or string. Bind `position' to the position in the
4136 object where the property was found, and `buffer-position'
4137 to the current position in the buffer. */
4138 specbind (Qobject
, object
);
4139 specbind (Qposition
, make_number (CHARPOS (*position
)));
4140 specbind (Qbuffer_position
,
4141 make_number (STRINGP (object
)
4142 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4144 form
= safe_eval (form
);
4146 unbind_to (count
, Qnil
);
4152 /* Handle `(height HEIGHT)' specifications. */
4154 && EQ (XCAR (spec
), Qheight
)
4155 && CONSP (XCDR (spec
)))
4157 if (!FRAME_WINDOW_P (it
->f
))
4160 it
->font_height
= XCAR (XCDR (spec
));
4161 if (!NILP (it
->font_height
))
4163 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4164 int new_height
= -1;
4166 if (CONSP (it
->font_height
)
4167 && (EQ (XCAR (it
->font_height
), Qplus
)
4168 || EQ (XCAR (it
->font_height
), Qminus
))
4169 && CONSP (XCDR (it
->font_height
))
4170 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4172 /* `(+ N)' or `(- N)' where N is an integer. */
4173 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4174 if (EQ (XCAR (it
->font_height
), Qplus
))
4176 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4178 else if (FUNCTIONP (it
->font_height
))
4180 /* Call function with current height as argument.
4181 Value is the new height. */
4183 height
= safe_call1 (it
->font_height
,
4184 face
->lface
[LFACE_HEIGHT_INDEX
]);
4185 if (NUMBERP (height
))
4186 new_height
= XFLOATINT (height
);
4188 else if (NUMBERP (it
->font_height
))
4190 /* Value is a multiple of the canonical char height. */
4193 face
= FACE_FROM_ID (it
->f
,
4194 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4195 new_height
= (XFLOATINT (it
->font_height
)
4196 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4200 /* Evaluate IT->font_height with `height' bound to the
4201 current specified height to get the new height. */
4202 int count
= SPECPDL_INDEX ();
4204 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4205 value
= safe_eval (it
->font_height
);
4206 unbind_to (count
, Qnil
);
4208 if (NUMBERP (value
))
4209 new_height
= XFLOATINT (value
);
4213 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4219 /* Handle `(space-width WIDTH)'. */
4221 && EQ (XCAR (spec
), Qspace_width
)
4222 && CONSP (XCDR (spec
)))
4224 if (!FRAME_WINDOW_P (it
->f
))
4227 value
= XCAR (XCDR (spec
));
4228 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4229 it
->space_width
= value
;
4234 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4236 && EQ (XCAR (spec
), Qslice
))
4240 if (!FRAME_WINDOW_P (it
->f
))
4243 if (tem
= XCDR (spec
), CONSP (tem
))
4245 it
->slice
.x
= XCAR (tem
);
4246 if (tem
= XCDR (tem
), CONSP (tem
))
4248 it
->slice
.y
= XCAR (tem
);
4249 if (tem
= XCDR (tem
), CONSP (tem
))
4251 it
->slice
.width
= XCAR (tem
);
4252 if (tem
= XCDR (tem
), CONSP (tem
))
4253 it
->slice
.height
= XCAR (tem
);
4261 /* Handle `(raise FACTOR)'. */
4263 && EQ (XCAR (spec
), Qraise
)
4264 && CONSP (XCDR (spec
)))
4266 if (!FRAME_WINDOW_P (it
->f
))
4269 #ifdef HAVE_WINDOW_SYSTEM
4270 value
= XCAR (XCDR (spec
));
4271 if (NUMBERP (value
))
4273 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4274 it
->voffset
= - (XFLOATINT (value
)
4275 * (FONT_HEIGHT (face
->font
)));
4277 #endif /* HAVE_WINDOW_SYSTEM */
4282 /* Don't handle the other kinds of display specifications
4283 inside a string that we got from a `display' property. */
4284 if (it
->string_from_display_prop_p
)
4287 /* Characters having this form of property are not displayed, so
4288 we have to find the end of the property. */
4289 start_pos
= *position
;
4290 *position
= display_prop_end (it
, object
, start_pos
);
4293 /* Stop the scan at that end position--we assume that all
4294 text properties change there. */
4295 it
->stop_charpos
= position
->charpos
;
4297 /* Handle `(left-fringe BITMAP [FACE])'
4298 and `(right-fringe BITMAP [FACE])'. */
4300 && (EQ (XCAR (spec
), Qleft_fringe
)
4301 || EQ (XCAR (spec
), Qright_fringe
))
4302 && CONSP (XCDR (spec
)))
4304 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4307 if (!FRAME_WINDOW_P (it
->f
))
4308 /* If we return here, POSITION has been advanced
4309 across the text with this property. */
4312 #ifdef HAVE_WINDOW_SYSTEM
4313 value
= XCAR (XCDR (spec
));
4314 if (!SYMBOLP (value
)
4315 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4316 /* If we return here, POSITION has been advanced
4317 across the text with this property. */
4320 if (CONSP (XCDR (XCDR (spec
))))
4322 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4323 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4329 /* Save current settings of IT so that we can restore them
4330 when we are finished with the glyph property value. */
4332 save_pos
= it
->position
;
4333 it
->position
= *position
;
4335 it
->position
= save_pos
;
4337 it
->area
= TEXT_AREA
;
4338 it
->what
= IT_IMAGE
;
4339 it
->image_id
= -1; /* no image */
4340 it
->position
= start_pos
;
4341 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4342 it
->method
= GET_FROM_IMAGE
;
4343 it
->from_overlay
= Qnil
;
4344 it
->face_id
= face_id
;
4346 /* Say that we haven't consumed the characters with
4347 `display' property yet. The call to pop_it in
4348 set_iterator_to_next will clean this up. */
4349 *position
= start_pos
;
4351 if (EQ (XCAR (spec
), Qleft_fringe
))
4353 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4354 it
->left_user_fringe_face_id
= face_id
;
4358 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4359 it
->right_user_fringe_face_id
= face_id
;
4361 #endif /* HAVE_WINDOW_SYSTEM */
4365 /* Prepare to handle `((margin left-margin) ...)',
4366 `((margin right-margin) ...)' and `((margin nil) ...)'
4367 prefixes for display specifications. */
4368 location
= Qunbound
;
4369 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4373 value
= XCDR (spec
);
4375 value
= XCAR (value
);
4378 if (EQ (XCAR (tem
), Qmargin
)
4379 && (tem
= XCDR (tem
),
4380 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4382 || EQ (tem
, Qleft_margin
)
4383 || EQ (tem
, Qright_margin
))))
4387 if (EQ (location
, Qunbound
))
4393 /* After this point, VALUE is the property after any
4394 margin prefix has been stripped. It must be a string,
4395 an image specification, or `(space ...)'.
4397 LOCATION specifies where to display: `left-margin',
4398 `right-margin' or nil. */
4400 valid_p
= (STRINGP (value
)
4401 #ifdef HAVE_WINDOW_SYSTEM
4402 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4403 #endif /* not HAVE_WINDOW_SYSTEM */
4404 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4406 if (valid_p
&& !display_replaced_before_p
)
4408 /* Save current settings of IT so that we can restore them
4409 when we are finished with the glyph property value. */
4410 save_pos
= it
->position
;
4411 it
->position
= *position
;
4413 it
->position
= save_pos
;
4414 it
->from_overlay
= overlay
;
4416 if (NILP (location
))
4417 it
->area
= TEXT_AREA
;
4418 else if (EQ (location
, Qleft_margin
))
4419 it
->area
= LEFT_MARGIN_AREA
;
4421 it
->area
= RIGHT_MARGIN_AREA
;
4423 if (STRINGP (value
))
4426 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4427 it
->current
.overlay_string_index
= -1;
4428 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4429 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4430 it
->method
= GET_FROM_STRING
;
4431 it
->stop_charpos
= 0;
4432 it
->string_from_display_prop_p
= 1;
4433 /* Say that we haven't consumed the characters with
4434 `display' property yet. The call to pop_it in
4435 set_iterator_to_next will clean this up. */
4436 if (BUFFERP (object
))
4437 *position
= start_pos
;
4439 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4441 it
->method
= GET_FROM_STRETCH
;
4443 *position
= it
->position
= start_pos
;
4445 #ifdef HAVE_WINDOW_SYSTEM
4448 it
->what
= IT_IMAGE
;
4449 it
->image_id
= lookup_image (it
->f
, value
);
4450 it
->position
= start_pos
;
4451 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4452 it
->method
= GET_FROM_IMAGE
;
4454 /* Say that we haven't consumed the characters with
4455 `display' property yet. The call to pop_it in
4456 set_iterator_to_next will clean this up. */
4457 *position
= start_pos
;
4459 #endif /* HAVE_WINDOW_SYSTEM */
4464 /* Invalid property or property not supported. Restore
4465 POSITION to what it was before. */
4466 *position
= start_pos
;
4471 /* Check if SPEC is a display sub-property value whose text should be
4472 treated as intangible. */
4475 single_display_spec_intangible_p (prop
)
4478 /* Skip over `when FORM'. */
4479 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4493 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4494 we don't need to treat text as intangible. */
4495 if (EQ (XCAR (prop
), Qmargin
))
4503 || EQ (XCAR (prop
), Qleft_margin
)
4504 || EQ (XCAR (prop
), Qright_margin
))
4508 return (CONSP (prop
)
4509 && (EQ (XCAR (prop
), Qimage
)
4510 || EQ (XCAR (prop
), Qspace
)));
4514 /* Check if PROP is a display property value whose text should be
4515 treated as intangible. */
4518 display_prop_intangible_p (prop
)
4522 && CONSP (XCAR (prop
))
4523 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4525 /* A list of sub-properties. */
4526 while (CONSP (prop
))
4528 if (single_display_spec_intangible_p (XCAR (prop
)))
4533 else if (VECTORP (prop
))
4535 /* A vector of sub-properties. */
4537 for (i
= 0; i
< ASIZE (prop
); ++i
)
4538 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4542 return single_display_spec_intangible_p (prop
);
4548 /* Return 1 if PROP is a display sub-property value containing STRING. */
4551 single_display_spec_string_p (prop
, string
)
4552 Lisp_Object prop
, string
;
4554 if (EQ (string
, prop
))
4557 /* Skip over `when FORM'. */
4558 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4567 /* Skip over `margin LOCATION'. */
4568 if (EQ (XCAR (prop
), Qmargin
))
4579 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4583 /* Return 1 if STRING appears in the `display' property PROP. */
4586 display_prop_string_p (prop
, string
)
4587 Lisp_Object prop
, string
;
4590 && CONSP (XCAR (prop
))
4591 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4593 /* A list of sub-properties. */
4594 while (CONSP (prop
))
4596 if (single_display_spec_string_p (XCAR (prop
), string
))
4601 else if (VECTORP (prop
))
4603 /* A vector of sub-properties. */
4605 for (i
= 0; i
< ASIZE (prop
); ++i
)
4606 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4610 return single_display_spec_string_p (prop
, string
);
4615 /* Look for STRING in overlays and text properties in W's buffer,
4616 between character positions FROM and TO (excluding TO).
4617 BACK_P non-zero means look back (in this case, TO is supposed to be
4619 Value is the first character position where STRING was found, or
4620 zero if it wasn't found before hitting TO.
4622 W's buffer must be current.
4624 This function may only use code that doesn't eval because it is
4625 called asynchronously from note_mouse_highlight. */
4628 string_buffer_position_lim (w
, string
, from
, to
, back_p
)
4634 Lisp_Object limit
, prop
, pos
;
4637 pos
= make_number (from
);
4639 if (!back_p
) /* looking forward */
4641 limit
= make_number (min (to
, ZV
));
4642 while (!found
&& !EQ (pos
, limit
))
4644 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4645 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4648 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4652 else /* looking back */
4654 limit
= make_number (max (to
, BEGV
));
4655 while (!found
&& !EQ (pos
, limit
))
4657 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4658 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4661 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4666 return found
? XINT (pos
) : 0;
4669 /* Determine which buffer position in W's buffer STRING comes from.
4670 AROUND_CHARPOS is an approximate position where it could come from.
4671 Value is the buffer position or 0 if it couldn't be determined.
4673 W's buffer must be current.
4675 This function is necessary because we don't record buffer positions
4676 in glyphs generated from strings (to keep struct glyph small).
4677 This function may only use code that doesn't eval because it is
4678 called asynchronously from note_mouse_highlight. */
4681 string_buffer_position (w
, string
, around_charpos
)
4684 EMACS_INT around_charpos
;
4686 Lisp_Object limit
, prop
, pos
;
4687 const int MAX_DISTANCE
= 1000;
4688 EMACS_INT found
= string_buffer_position_lim (w
, string
, around_charpos
,
4689 around_charpos
+ MAX_DISTANCE
,
4693 found
= string_buffer_position_lim (w
, string
, around_charpos
,
4694 around_charpos
- MAX_DISTANCE
, 1);
4700 /***********************************************************************
4701 `composition' property
4702 ***********************************************************************/
4704 /* Set up iterator IT from `composition' property at its current
4705 position. Called from handle_stop. */
4707 static enum prop_handled
4708 handle_composition_prop (it
)
4711 Lisp_Object prop
, string
;
4712 EMACS_INT pos
, pos_byte
, start
, end
;
4714 if (STRINGP (it
->string
))
4718 pos
= IT_STRING_CHARPOS (*it
);
4719 pos_byte
= IT_STRING_BYTEPOS (*it
);
4720 string
= it
->string
;
4721 s
= SDATA (string
) + pos_byte
;
4722 it
->c
= STRING_CHAR (s
);
4726 pos
= IT_CHARPOS (*it
);
4727 pos_byte
= IT_BYTEPOS (*it
);
4729 it
->c
= FETCH_CHAR (pos_byte
);
4732 /* If there's a valid composition and point is not inside of the
4733 composition (in the case that the composition is from the current
4734 buffer), draw a glyph composed from the composition components. */
4735 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4736 && COMPOSITION_VALID_P (start
, end
, prop
)
4737 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4741 if (STRINGP (it
->string
))
4742 pos_byte
= string_char_to_byte (it
->string
, start
);
4744 pos_byte
= CHAR_TO_BYTE (start
);
4746 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4749 if (it
->cmp_it
.id
>= 0)
4752 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4753 it
->cmp_it
.nglyphs
= -1;
4757 return HANDLED_NORMALLY
;
4762 /***********************************************************************
4764 ***********************************************************************/
4766 /* The following structure is used to record overlay strings for
4767 later sorting in load_overlay_strings. */
4769 struct overlay_entry
4771 Lisp_Object overlay
;
4778 /* Set up iterator IT from overlay strings at its current position.
4779 Called from handle_stop. */
4781 static enum prop_handled
4782 handle_overlay_change (it
)
4785 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4786 return HANDLED_RECOMPUTE_PROPS
;
4788 return HANDLED_NORMALLY
;
4792 /* Set up the next overlay string for delivery by IT, if there is an
4793 overlay string to deliver. Called by set_iterator_to_next when the
4794 end of the current overlay string is reached. If there are more
4795 overlay strings to display, IT->string and
4796 IT->current.overlay_string_index are set appropriately here.
4797 Otherwise IT->string is set to nil. */
4800 next_overlay_string (it
)
4803 ++it
->current
.overlay_string_index
;
4804 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4806 /* No more overlay strings. Restore IT's settings to what
4807 they were before overlay strings were processed, and
4808 continue to deliver from current_buffer. */
4810 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4813 || (NILP (it
->string
)
4814 && it
->method
== GET_FROM_BUFFER
4815 && it
->stop_charpos
>= BEGV
4816 && it
->stop_charpos
<= it
->end_charpos
));
4817 it
->current
.overlay_string_index
= -1;
4818 it
->n_overlay_strings
= 0;
4820 /* If we're at the end of the buffer, record that we have
4821 processed the overlay strings there already, so that
4822 next_element_from_buffer doesn't try it again. */
4823 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4824 it
->overlay_strings_at_end_processed_p
= 1;
4828 /* There are more overlay strings to process. If
4829 IT->current.overlay_string_index has advanced to a position
4830 where we must load IT->overlay_strings with more strings, do
4832 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4834 if (it
->current
.overlay_string_index
&& i
== 0)
4835 load_overlay_strings (it
, 0);
4837 /* Initialize IT to deliver display elements from the overlay
4839 it
->string
= it
->overlay_strings
[i
];
4840 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4841 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4842 it
->method
= GET_FROM_STRING
;
4843 it
->stop_charpos
= 0;
4844 if (it
->cmp_it
.stop_pos
>= 0)
4845 it
->cmp_it
.stop_pos
= 0;
4852 /* Compare two overlay_entry structures E1 and E2. Used as a
4853 comparison function for qsort in load_overlay_strings. Overlay
4854 strings for the same position are sorted so that
4856 1. All after-strings come in front of before-strings, except
4857 when they come from the same overlay.
4859 2. Within after-strings, strings are sorted so that overlay strings
4860 from overlays with higher priorities come first.
4862 2. Within before-strings, strings are sorted so that overlay
4863 strings from overlays with higher priorities come last.
4865 Value is analogous to strcmp. */
4869 compare_overlay_entries (e1
, e2
)
4872 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4873 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4876 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4878 /* Let after-strings appear in front of before-strings if
4879 they come from different overlays. */
4880 if (EQ (entry1
->overlay
, entry2
->overlay
))
4881 result
= entry1
->after_string_p
? 1 : -1;
4883 result
= entry1
->after_string_p
? -1 : 1;
4885 else if (entry1
->after_string_p
)
4886 /* After-strings sorted in order of decreasing priority. */
4887 result
= entry2
->priority
- entry1
->priority
;
4889 /* Before-strings sorted in order of increasing priority. */
4890 result
= entry1
->priority
- entry2
->priority
;
4896 /* Load the vector IT->overlay_strings with overlay strings from IT's
4897 current buffer position, or from CHARPOS if that is > 0. Set
4898 IT->n_overlays to the total number of overlay strings found.
4900 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4901 a time. On entry into load_overlay_strings,
4902 IT->current.overlay_string_index gives the number of overlay
4903 strings that have already been loaded by previous calls to this
4906 IT->add_overlay_start contains an additional overlay start
4907 position to consider for taking overlay strings from, if non-zero.
4908 This position comes into play when the overlay has an `invisible'
4909 property, and both before and after-strings. When we've skipped to
4910 the end of the overlay, because of its `invisible' property, we
4911 nevertheless want its before-string to appear.
4912 IT->add_overlay_start will contain the overlay start position
4915 Overlay strings are sorted so that after-string strings come in
4916 front of before-string strings. Within before and after-strings,
4917 strings are sorted by overlay priority. See also function
4918 compare_overlay_entries. */
4921 load_overlay_strings (it
, charpos
)
4925 extern Lisp_Object Qwindow
, Qpriority
;
4926 Lisp_Object overlay
, window
, str
, invisible
;
4927 struct Lisp_Overlay
*ov
;
4930 int n
= 0, i
, j
, invis_p
;
4931 struct overlay_entry
*entries
4932 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4935 charpos
= IT_CHARPOS (*it
);
4937 /* Append the overlay string STRING of overlay OVERLAY to vector
4938 `entries' which has size `size' and currently contains `n'
4939 elements. AFTER_P non-zero means STRING is an after-string of
4941 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4944 Lisp_Object priority; \
4948 int new_size = 2 * size; \
4949 struct overlay_entry *old = entries; \
4951 (struct overlay_entry *) alloca (new_size \
4952 * sizeof *entries); \
4953 bcopy (old, entries, size * sizeof *entries); \
4957 entries[n].string = (STRING); \
4958 entries[n].overlay = (OVERLAY); \
4959 priority = Foverlay_get ((OVERLAY), Qpriority); \
4960 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4961 entries[n].after_string_p = (AFTER_P); \
4966 /* Process overlay before the overlay center. */
4967 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4969 XSETMISC (overlay
, ov
);
4970 xassert (OVERLAYP (overlay
));
4971 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4972 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4977 /* Skip this overlay if it doesn't start or end at IT's current
4979 if (end
!= charpos
&& start
!= charpos
)
4982 /* Skip this overlay if it doesn't apply to IT->w. */
4983 window
= Foverlay_get (overlay
, Qwindow
);
4984 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4987 /* If the text ``under'' the overlay is invisible, both before-
4988 and after-strings from this overlay are visible; start and
4989 end position are indistinguishable. */
4990 invisible
= Foverlay_get (overlay
, Qinvisible
);
4991 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4993 /* If overlay has a non-empty before-string, record it. */
4994 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4995 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4997 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4999 /* If overlay has a non-empty after-string, record it. */
5000 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5001 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5003 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5006 /* Process overlays after the overlay center. */
5007 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5009 XSETMISC (overlay
, ov
);
5010 xassert (OVERLAYP (overlay
));
5011 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5012 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5014 if (start
> charpos
)
5017 /* Skip this overlay if it doesn't start or end at IT's current
5019 if (end
!= charpos
&& start
!= charpos
)
5022 /* Skip this overlay if it doesn't apply to IT->w. */
5023 window
= Foverlay_get (overlay
, Qwindow
);
5024 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5027 /* If the text ``under'' the overlay is invisible, it has a zero
5028 dimension, and both before- and after-strings apply. */
5029 invisible
= Foverlay_get (overlay
, Qinvisible
);
5030 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5032 /* If overlay has a non-empty before-string, record it. */
5033 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5034 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5036 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5038 /* If overlay has a non-empty after-string, record it. */
5039 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5040 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5042 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5045 #undef RECORD_OVERLAY_STRING
5049 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5051 /* Record the total number of strings to process. */
5052 it
->n_overlay_strings
= n
;
5054 /* IT->current.overlay_string_index is the number of overlay strings
5055 that have already been consumed by IT. Copy some of the
5056 remaining overlay strings to IT->overlay_strings. */
5058 j
= it
->current
.overlay_string_index
;
5059 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5061 it
->overlay_strings
[i
] = entries
[j
].string
;
5062 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5069 /* Get the first chunk of overlay strings at IT's current buffer
5070 position, or at CHARPOS if that is > 0. Value is non-zero if at
5071 least one overlay string was found. */
5074 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5079 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5080 process. This fills IT->overlay_strings with strings, and sets
5081 IT->n_overlay_strings to the total number of strings to process.
5082 IT->pos.overlay_string_index has to be set temporarily to zero
5083 because load_overlay_strings needs this; it must be set to -1
5084 when no overlay strings are found because a zero value would
5085 indicate a position in the first overlay string. */
5086 it
->current
.overlay_string_index
= 0;
5087 load_overlay_strings (it
, charpos
);
5089 /* If we found overlay strings, set up IT to deliver display
5090 elements from the first one. Otherwise set up IT to deliver
5091 from current_buffer. */
5092 if (it
->n_overlay_strings
)
5094 /* Make sure we know settings in current_buffer, so that we can
5095 restore meaningful values when we're done with the overlay
5098 compute_stop_pos (it
);
5099 xassert (it
->face_id
>= 0);
5101 /* Save IT's settings. They are restored after all overlay
5102 strings have been processed. */
5103 xassert (!compute_stop_p
|| it
->sp
== 0);
5105 /* When called from handle_stop, there might be an empty display
5106 string loaded. In that case, don't bother saving it. */
5107 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5110 /* Set up IT to deliver display elements from the first overlay
5112 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5113 it
->string
= it
->overlay_strings
[0];
5114 it
->from_overlay
= Qnil
;
5115 it
->stop_charpos
= 0;
5116 xassert (STRINGP (it
->string
));
5117 it
->end_charpos
= SCHARS (it
->string
);
5118 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5119 it
->method
= GET_FROM_STRING
;
5123 it
->current
.overlay_string_index
= -1;
5128 get_overlay_strings (it
, charpos
)
5133 it
->method
= GET_FROM_BUFFER
;
5135 (void) get_overlay_strings_1 (it
, charpos
, 1);
5139 /* Value is non-zero if we found at least one overlay string. */
5140 return STRINGP (it
->string
);
5145 /***********************************************************************
5146 Saving and restoring state
5147 ***********************************************************************/
5149 /* Save current settings of IT on IT->stack. Called, for example,
5150 before setting up IT for an overlay string, to be able to restore
5151 IT's settings to what they were after the overlay string has been
5158 struct iterator_stack_entry
*p
;
5160 xassert (it
->sp
< IT_STACK_SIZE
);
5161 p
= it
->stack
+ it
->sp
;
5163 p
->stop_charpos
= it
->stop_charpos
;
5164 p
->prev_stop
= it
->prev_stop
;
5165 p
->base_level_stop
= it
->base_level_stop
;
5166 p
->cmp_it
= it
->cmp_it
;
5167 xassert (it
->face_id
>= 0);
5168 p
->face_id
= it
->face_id
;
5169 p
->string
= it
->string
;
5170 p
->method
= it
->method
;
5171 p
->from_overlay
= it
->from_overlay
;
5174 case GET_FROM_IMAGE
:
5175 p
->u
.image
.object
= it
->object
;
5176 p
->u
.image
.image_id
= it
->image_id
;
5177 p
->u
.image
.slice
= it
->slice
;
5179 case GET_FROM_STRETCH
:
5180 p
->u
.stretch
.object
= it
->object
;
5183 p
->position
= it
->position
;
5184 p
->current
= it
->current
;
5185 p
->end_charpos
= it
->end_charpos
;
5186 p
->string_nchars
= it
->string_nchars
;
5188 p
->multibyte_p
= it
->multibyte_p
;
5189 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5190 p
->space_width
= it
->space_width
;
5191 p
->font_height
= it
->font_height
;
5192 p
->voffset
= it
->voffset
;
5193 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5194 p
->display_ellipsis_p
= 0;
5195 p
->line_wrap
= it
->line_wrap
;
5200 /* Restore IT's settings from IT->stack. Called, for example, when no
5201 more overlay strings must be processed, and we return to delivering
5202 display elements from a buffer, or when the end of a string from a
5203 `display' property is reached and we return to delivering display
5204 elements from an overlay string, or from a buffer. */
5210 struct iterator_stack_entry
*p
;
5212 xassert (it
->sp
> 0);
5214 p
= it
->stack
+ it
->sp
;
5215 it
->stop_charpos
= p
->stop_charpos
;
5216 it
->prev_stop
= p
->prev_stop
;
5217 it
->base_level_stop
= p
->base_level_stop
;
5218 it
->cmp_it
= p
->cmp_it
;
5219 it
->face_id
= p
->face_id
;
5220 it
->current
= p
->current
;
5221 it
->position
= p
->position
;
5222 it
->string
= p
->string
;
5223 it
->from_overlay
= p
->from_overlay
;
5224 if (NILP (it
->string
))
5225 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5226 it
->method
= p
->method
;
5229 case GET_FROM_IMAGE
:
5230 it
->image_id
= p
->u
.image
.image_id
;
5231 it
->object
= p
->u
.image
.object
;
5232 it
->slice
= p
->u
.image
.slice
;
5234 case GET_FROM_STRETCH
:
5235 it
->object
= p
->u
.comp
.object
;
5237 case GET_FROM_BUFFER
:
5238 it
->object
= it
->w
->buffer
;
5240 case GET_FROM_STRING
:
5241 it
->object
= it
->string
;
5243 case GET_FROM_DISPLAY_VECTOR
:
5245 it
->method
= GET_FROM_C_STRING
;
5246 else if (STRINGP (it
->string
))
5247 it
->method
= GET_FROM_STRING
;
5250 it
->method
= GET_FROM_BUFFER
;
5251 it
->object
= it
->w
->buffer
;
5254 it
->end_charpos
= p
->end_charpos
;
5255 it
->string_nchars
= p
->string_nchars
;
5257 it
->multibyte_p
= p
->multibyte_p
;
5258 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5259 it
->space_width
= p
->space_width
;
5260 it
->font_height
= p
->font_height
;
5261 it
->voffset
= p
->voffset
;
5262 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5263 it
->line_wrap
= p
->line_wrap
;
5268 /***********************************************************************
5270 ***********************************************************************/
5272 /* Set IT's current position to the previous line start. */
5275 back_to_previous_line_start (it
)
5278 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5279 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5283 /* Move IT to the next line start.
5285 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5286 we skipped over part of the text (as opposed to moving the iterator
5287 continuously over the text). Otherwise, don't change the value
5290 Newlines may come from buffer text, overlay strings, or strings
5291 displayed via the `display' property. That's the reason we can't
5292 simply use find_next_newline_no_quit.
5294 Note that this function may not skip over invisible text that is so
5295 because of text properties and immediately follows a newline. If
5296 it would, function reseat_at_next_visible_line_start, when called
5297 from set_iterator_to_next, would effectively make invisible
5298 characters following a newline part of the wrong glyph row, which
5299 leads to wrong cursor motion. */
5302 forward_to_next_line_start (it
, skipped_p
)
5306 int old_selective
, newline_found_p
, n
;
5307 const int MAX_NEWLINE_DISTANCE
= 500;
5309 /* If already on a newline, just consume it to avoid unintended
5310 skipping over invisible text below. */
5311 if (it
->what
== IT_CHARACTER
5313 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5315 set_iterator_to_next (it
, 0);
5320 /* Don't handle selective display in the following. It's (a)
5321 unnecessary because it's done by the caller, and (b) leads to an
5322 infinite recursion because next_element_from_ellipsis indirectly
5323 calls this function. */
5324 old_selective
= it
->selective
;
5327 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5328 from buffer text. */
5329 for (n
= newline_found_p
= 0;
5330 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5331 n
+= STRINGP (it
->string
) ? 0 : 1)
5333 if (!get_next_display_element (it
))
5335 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5336 set_iterator_to_next (it
, 0);
5339 /* If we didn't find a newline near enough, see if we can use a
5341 if (!newline_found_p
)
5343 int start
= IT_CHARPOS (*it
);
5344 int limit
= find_next_newline_no_quit (start
, 1);
5347 xassert (!STRINGP (it
->string
));
5349 /* If there isn't any `display' property in sight, and no
5350 overlays, we can just use the position of the newline in
5352 if (it
->stop_charpos
>= limit
5353 || ((pos
= Fnext_single_property_change (make_number (start
),
5355 Qnil
, make_number (limit
)),
5357 && next_overlay_change (start
) == ZV
))
5359 IT_CHARPOS (*it
) = limit
;
5360 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5361 *skipped_p
= newline_found_p
= 1;
5365 while (get_next_display_element (it
)
5366 && !newline_found_p
)
5368 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5369 set_iterator_to_next (it
, 0);
5374 it
->selective
= old_selective
;
5375 return newline_found_p
;
5379 /* Set IT's current position to the previous visible line start. Skip
5380 invisible text that is so either due to text properties or due to
5381 selective display. Caution: this does not change IT->current_x and
5385 back_to_previous_visible_line_start (it
)
5388 while (IT_CHARPOS (*it
) > BEGV
)
5390 back_to_previous_line_start (it
);
5392 if (IT_CHARPOS (*it
) <= BEGV
)
5395 /* If selective > 0, then lines indented more than its value are
5397 if (it
->selective
> 0
5398 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5399 (double) it
->selective
)) /* iftc */
5402 /* Check the newline before point for invisibility. */
5405 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5406 Qinvisible
, it
->window
);
5407 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5411 if (IT_CHARPOS (*it
) <= BEGV
)
5418 Lisp_Object val
, overlay
;
5420 /* If newline is part of a composition, continue from start of composition */
5421 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5422 && beg
< IT_CHARPOS (*it
))
5425 /* If newline is replaced by a display property, find start of overlay
5426 or interval and continue search from that point. */
5428 pos
= --IT_CHARPOS (it2
);
5431 it2
.string_from_display_prop_p
= 0;
5432 if (handle_display_prop (&it2
) == HANDLED_RETURN
5433 && !NILP (val
= get_char_property_and_overlay
5434 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5435 && (OVERLAYP (overlay
)
5436 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5437 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5440 /* Newline is not replaced by anything -- so we are done. */
5446 IT_CHARPOS (*it
) = beg
;
5447 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5451 it
->continuation_lines_width
= 0;
5453 xassert (IT_CHARPOS (*it
) >= BEGV
);
5454 xassert (IT_CHARPOS (*it
) == BEGV
5455 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5460 /* Reseat iterator IT at the previous visible line start. Skip
5461 invisible text that is so either due to text properties or due to
5462 selective display. At the end, update IT's overlay information,
5463 face information etc. */
5466 reseat_at_previous_visible_line_start (it
)
5469 back_to_previous_visible_line_start (it
);
5470 reseat (it
, it
->current
.pos
, 1);
5475 /* Reseat iterator IT on the next visible line start in the current
5476 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5477 preceding the line start. Skip over invisible text that is so
5478 because of selective display. Compute faces, overlays etc at the
5479 new position. Note that this function does not skip over text that
5480 is invisible because of text properties. */
5483 reseat_at_next_visible_line_start (it
, on_newline_p
)
5487 int newline_found_p
, skipped_p
= 0;
5489 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5491 /* Skip over lines that are invisible because they are indented
5492 more than the value of IT->selective. */
5493 if (it
->selective
> 0)
5494 while (IT_CHARPOS (*it
) < ZV
5495 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5496 (double) it
->selective
)) /* iftc */
5498 xassert (IT_BYTEPOS (*it
) == BEGV
5499 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5500 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5503 /* Position on the newline if that's what's requested. */
5504 if (on_newline_p
&& newline_found_p
)
5506 if (STRINGP (it
->string
))
5508 if (IT_STRING_CHARPOS (*it
) > 0)
5510 --IT_STRING_CHARPOS (*it
);
5511 --IT_STRING_BYTEPOS (*it
);
5514 else if (IT_CHARPOS (*it
) > BEGV
)
5518 reseat (it
, it
->current
.pos
, 0);
5522 reseat (it
, it
->current
.pos
, 0);
5529 /***********************************************************************
5530 Changing an iterator's position
5531 ***********************************************************************/
5533 /* Change IT's current position to POS in current_buffer. If FORCE_P
5534 is non-zero, always check for text properties at the new position.
5535 Otherwise, text properties are only looked up if POS >=
5536 IT->check_charpos of a property. */
5539 reseat (it
, pos
, force_p
)
5541 struct text_pos pos
;
5544 int original_pos
= IT_CHARPOS (*it
);
5546 reseat_1 (it
, pos
, 0);
5548 /* Determine where to check text properties. Avoid doing it
5549 where possible because text property lookup is very expensive. */
5551 || CHARPOS (pos
) > it
->stop_charpos
5552 || CHARPOS (pos
) < original_pos
)
5556 /* For bidi iteration, we need to prime prev_stop and
5557 base_level_stop with our best estimations. */
5558 if (CHARPOS (pos
) < it
->prev_stop
)
5560 handle_stop_backwards (it
, BEGV
);
5561 if (CHARPOS (pos
) < it
->base_level_stop
)
5562 it
->base_level_stop
= 0;
5564 else if (CHARPOS (pos
) > it
->stop_charpos
5565 && it
->stop_charpos
>= BEGV
)
5566 handle_stop_backwards (it
, it
->stop_charpos
);
5573 it
->prev_stop
= it
->base_level_stop
= 0;
5582 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5583 IT->stop_pos to POS, also. */
5586 reseat_1 (it
, pos
, set_stop_p
)
5588 struct text_pos pos
;
5591 /* Don't call this function when scanning a C string. */
5592 xassert (it
->s
== NULL
);
5594 /* POS must be a reasonable value. */
5595 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5597 it
->current
.pos
= it
->position
= pos
;
5598 it
->end_charpos
= ZV
;
5600 it
->current
.dpvec_index
= -1;
5601 it
->current
.overlay_string_index
= -1;
5602 IT_STRING_CHARPOS (*it
) = -1;
5603 IT_STRING_BYTEPOS (*it
) = -1;
5605 it
->string_from_display_prop_p
= 0;
5606 it
->method
= GET_FROM_BUFFER
;
5607 it
->object
= it
->w
->buffer
;
5608 it
->area
= TEXT_AREA
;
5609 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5611 it
->string_from_display_prop_p
= 0;
5612 it
->face_before_selective_p
= 0;
5614 it
->bidi_it
.first_elt
= 1;
5618 it
->stop_charpos
= CHARPOS (pos
);
5619 it
->base_level_stop
= CHARPOS (pos
);
5624 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5625 If S is non-null, it is a C string to iterate over. Otherwise,
5626 STRING gives a Lisp string to iterate over.
5628 If PRECISION > 0, don't return more then PRECISION number of
5629 characters from the string.
5631 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5632 characters have been returned. FIELD_WIDTH < 0 means an infinite
5635 MULTIBYTE = 0 means disable processing of multibyte characters,
5636 MULTIBYTE > 0 means enable it,
5637 MULTIBYTE < 0 means use IT->multibyte_p.
5639 IT must be initialized via a prior call to init_iterator before
5640 calling this function. */
5643 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5648 int precision
, field_width
, multibyte
;
5650 /* No region in strings. */
5651 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5653 /* No text property checks performed by default, but see below. */
5654 it
->stop_charpos
= -1;
5656 /* Set iterator position and end position. */
5657 bzero (&it
->current
, sizeof it
->current
);
5658 it
->current
.overlay_string_index
= -1;
5659 it
->current
.dpvec_index
= -1;
5660 xassert (charpos
>= 0);
5662 /* If STRING is specified, use its multibyteness, otherwise use the
5663 setting of MULTIBYTE, if specified. */
5665 it
->multibyte_p
= multibyte
> 0;
5669 xassert (STRINGP (string
));
5670 it
->string
= string
;
5672 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5673 it
->method
= GET_FROM_STRING
;
5674 it
->current
.string_pos
= string_pos (charpos
, string
);
5681 /* Note that we use IT->current.pos, not it->current.string_pos,
5682 for displaying C strings. */
5683 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5684 if (it
->multibyte_p
)
5686 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5687 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5691 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5692 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5695 it
->method
= GET_FROM_C_STRING
;
5698 /* PRECISION > 0 means don't return more than PRECISION characters
5700 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5701 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5703 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5704 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5705 FIELD_WIDTH < 0 means infinite field width. This is useful for
5706 padding with `-' at the end of a mode line. */
5707 if (field_width
< 0)
5708 field_width
= INFINITY
;
5709 if (field_width
> it
->end_charpos
- charpos
)
5710 it
->end_charpos
= charpos
+ field_width
;
5712 /* Use the standard display table for displaying strings. */
5713 if (DISP_TABLE_P (Vstandard_display_table
))
5714 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5716 it
->stop_charpos
= charpos
;
5717 if (s
== NULL
&& it
->multibyte_p
)
5718 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, it
->end_charpos
,
5725 /***********************************************************************
5727 ***********************************************************************/
5729 /* Map enum it_method value to corresponding next_element_from_* function. */
5731 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5733 next_element_from_buffer
,
5734 next_element_from_display_vector
,
5735 next_element_from_string
,
5736 next_element_from_c_string
,
5737 next_element_from_image
,
5738 next_element_from_stretch
5741 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5744 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5745 (possibly with the following characters). */
5747 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5748 ((IT)->cmp_it.id >= 0 \
5749 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5750 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5751 END_CHARPOS, (IT)->w, \
5752 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5756 /* Load IT's display element fields with information about the next
5757 display element from the current position of IT. Value is zero if
5758 end of buffer (or C string) is reached. */
5760 static struct frame
*last_escape_glyph_frame
= NULL
;
5761 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5762 static int last_escape_glyph_merged_face_id
= 0;
5765 get_next_display_element (it
)
5768 /* Non-zero means that we found a display element. Zero means that
5769 we hit the end of what we iterate over. Performance note: the
5770 function pointer `method' used here turns out to be faster than
5771 using a sequence of if-statements. */
5775 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5777 if (it
->what
== IT_CHARACTER
)
5779 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5780 and only if (a) the resolved directionality of that character
5782 /* FIXME: Do we need an exception for characters from display
5784 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5785 it
->c
= bidi_mirror_char (it
->c
);
5786 /* Map via display table or translate control characters.
5787 IT->c, IT->len etc. have been set to the next character by
5788 the function call above. If we have a display table, and it
5789 contains an entry for IT->c, translate it. Don't do this if
5790 IT->c itself comes from a display table, otherwise we could
5791 end up in an infinite recursion. (An alternative could be to
5792 count the recursion depth of this function and signal an
5793 error when a certain maximum depth is reached.) Is it worth
5795 if (success_p
&& it
->dpvec
== NULL
)
5798 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5799 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5800 nbsp_or_shy
= char_is_other
;
5801 int decoded
= it
->c
;
5804 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5807 struct Lisp_Vector
*v
= XVECTOR (dv
);
5809 /* Return the first character from the display table
5810 entry, if not empty. If empty, don't display the
5811 current character. */
5814 it
->dpvec_char_len
= it
->len
;
5815 it
->dpvec
= v
->contents
;
5816 it
->dpend
= v
->contents
+ v
->size
;
5817 it
->current
.dpvec_index
= 0;
5818 it
->dpvec_face_id
= -1;
5819 it
->saved_face_id
= it
->face_id
;
5820 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5825 set_iterator_to_next (it
, 0);
5830 if (unibyte_display_via_language_environment
5831 && !ASCII_CHAR_P (it
->c
))
5832 decoded
= DECODE_CHAR (unibyte
, it
->c
);
5834 if (it
->c
>= 0x80 && ! NILP (Vnobreak_char_display
))
5836 if (it
->multibyte_p
)
5837 nbsp_or_shy
= (it
->c
== 0xA0 ? char_is_nbsp
5838 : it
->c
== 0xAD ? char_is_soft_hyphen
5840 else if (unibyte_display_via_language_environment
)
5841 nbsp_or_shy
= (decoded
== 0xA0 ? char_is_nbsp
5842 : decoded
== 0xAD ? char_is_soft_hyphen
5846 /* Translate control characters into `\003' or `^C' form.
5847 Control characters coming from a display table entry are
5848 currently not translated because we use IT->dpvec to hold
5849 the translation. This could easily be changed but I
5850 don't believe that it is worth doing.
5852 If it->multibyte_p is nonzero, non-printable non-ASCII
5853 characters are also translated to octal form.
5855 If it->multibyte_p is zero, eight-bit characters that
5856 don't have corresponding multibyte char code are also
5857 translated to octal form. */
5859 ? (it
->area
!= TEXT_AREA
5860 /* In mode line, treat \n, \t like other crl chars. */
5863 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5864 || (it
->c
!= '\n' && it
->c
!= '\t'))
5867 ? ! CHAR_PRINTABLE_P (it
->c
)
5868 : (! unibyte_display_via_language_environment
5870 : (decoded
>= 0x80 && decoded
< 0xA0))))))
5872 /* IT->c is a control character which must be displayed
5873 either as '\003' or as `^C' where the '\\' and '^'
5874 can be defined in the display table. Fill
5875 IT->ctl_chars with glyphs for what we have to
5876 display. Then, set IT->dpvec to these glyphs. */
5879 int face_id
, lface_id
= 0 ;
5882 /* Handle control characters with ^. */
5884 if (it
->c
< 128 && it
->ctl_arrow_p
)
5888 g
= '^'; /* default glyph for Control */
5889 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5891 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5892 && GLYPH_CODE_CHAR_VALID_P (gc
))
5894 g
= GLYPH_CODE_CHAR (gc
);
5895 lface_id
= GLYPH_CODE_FACE (gc
);
5899 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5901 else if (it
->f
== last_escape_glyph_frame
5902 && it
->face_id
== last_escape_glyph_face_id
)
5904 face_id
= last_escape_glyph_merged_face_id
;
5908 /* Merge the escape-glyph face into the current face. */
5909 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5911 last_escape_glyph_frame
= it
->f
;
5912 last_escape_glyph_face_id
= it
->face_id
;
5913 last_escape_glyph_merged_face_id
= face_id
;
5916 XSETINT (it
->ctl_chars
[0], g
);
5917 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5919 goto display_control
;
5922 /* Handle non-break space in the mode where it only gets
5925 if (EQ (Vnobreak_char_display
, Qt
)
5926 && nbsp_or_shy
== char_is_nbsp
)
5928 /* Merge the no-break-space face into the current face. */
5929 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5933 XSETINT (it
->ctl_chars
[0], ' ');
5935 goto display_control
;
5938 /* Handle sequences that start with the "escape glyph". */
5940 /* the default escape glyph is \. */
5941 escape_glyph
= '\\';
5944 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5945 && GLYPH_CODE_CHAR_VALID_P (gc
))
5947 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5948 lface_id
= GLYPH_CODE_FACE (gc
);
5952 /* The display table specified a face.
5953 Merge it into face_id and also into escape_glyph. */
5954 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5957 else if (it
->f
== last_escape_glyph_frame
5958 && it
->face_id
== last_escape_glyph_face_id
)
5960 face_id
= last_escape_glyph_merged_face_id
;
5964 /* Merge the escape-glyph face into the current face. */
5965 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5967 last_escape_glyph_frame
= it
->f
;
5968 last_escape_glyph_face_id
= it
->face_id
;
5969 last_escape_glyph_merged_face_id
= face_id
;
5972 /* Handle soft hyphens in the mode where they only get
5975 if (EQ (Vnobreak_char_display
, Qt
)
5976 && nbsp_or_shy
== char_is_soft_hyphen
)
5979 XSETINT (it
->ctl_chars
[0], '-');
5981 goto display_control
;
5984 /* Handle non-break space and soft hyphen
5985 with the escape glyph. */
5989 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5990 it
->c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5991 XSETINT (it
->ctl_chars
[1], it
->c
);
5993 goto display_control
;
5997 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6001 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
6002 if (CHAR_BYTE8_P (it
->c
))
6004 str
[0] = CHAR_TO_BYTE8 (it
->c
);
6007 else if (it
->c
< 256)
6014 /* It's an invalid character, which shouldn't
6015 happen actually, but due to bugs it may
6016 happen. Let's print the char as is, there's
6017 not much meaningful we can do with it. */
6019 str
[1] = it
->c
>> 8;
6020 str
[2] = it
->c
>> 16;
6021 str
[3] = it
->c
>> 24;
6025 for (i
= 0; i
< len
; i
++)
6028 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
6029 /* Insert three more glyphs into IT->ctl_chars for
6030 the octal display of the character. */
6031 g
= ((str
[i
] >> 6) & 7) + '0';
6032 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
6033 g
= ((str
[i
] >> 3) & 7) + '0';
6034 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
6035 g
= (str
[i
] & 7) + '0';
6036 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
6042 /* Set up IT->dpvec and return first character from it. */
6043 it
->dpvec_char_len
= it
->len
;
6044 it
->dpvec
= it
->ctl_chars
;
6045 it
->dpend
= it
->dpvec
+ ctl_len
;
6046 it
->current
.dpvec_index
= 0;
6047 it
->dpvec_face_id
= face_id
;
6048 it
->saved_face_id
= it
->face_id
;
6049 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6056 #ifdef HAVE_WINDOW_SYSTEM
6057 /* Adjust face id for a multibyte character. There are no multibyte
6058 character in unibyte text. */
6059 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6062 && FRAME_WINDOW_P (it
->f
))
6064 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6066 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6068 /* Automatic composition with glyph-string. */
6069 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6071 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6075 int pos
= (it
->s
? -1
6076 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6077 : IT_CHARPOS (*it
));
6079 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
6084 /* Is this character the last one of a run of characters with
6085 box? If yes, set IT->end_of_box_run_p to 1. */
6089 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6091 int face_id
= underlying_face_id (it
);
6092 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6096 if (face
->box
== FACE_NO_BOX
)
6098 /* If the box comes from face properties in a
6099 display string, check faces in that string. */
6100 int string_face_id
= face_after_it_pos (it
);
6101 it
->end_of_box_run_p
6102 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6105 /* Otherwise, the box comes from the underlying face.
6106 If this is the last string character displayed, check
6107 the next buffer location. */
6108 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6109 && (it
->current
.overlay_string_index
6110 == it
->n_overlay_strings
- 1))
6114 struct text_pos pos
= it
->current
.pos
;
6115 INC_TEXT_POS (pos
, it
->multibyte_p
);
6117 next_face_id
= face_at_buffer_position
6118 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6119 it
->region_end_charpos
, &ignore
,
6120 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6122 it
->end_of_box_run_p
6123 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6130 int face_id
= face_after_it_pos (it
);
6131 it
->end_of_box_run_p
6132 = (face_id
!= it
->face_id
6133 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6137 /* Value is 0 if end of buffer or string reached. */
6142 /* Move IT to the next display element.
6144 RESEAT_P non-zero means if called on a newline in buffer text,
6145 skip to the next visible line start.
6147 Functions get_next_display_element and set_iterator_to_next are
6148 separate because I find this arrangement easier to handle than a
6149 get_next_display_element function that also increments IT's
6150 position. The way it is we can first look at an iterator's current
6151 display element, decide whether it fits on a line, and if it does,
6152 increment the iterator position. The other way around we probably
6153 would either need a flag indicating whether the iterator has to be
6154 incremented the next time, or we would have to implement a
6155 decrement position function which would not be easy to write. */
6158 set_iterator_to_next (it
, reseat_p
)
6162 /* Reset flags indicating start and end of a sequence of characters
6163 with box. Reset them at the start of this function because
6164 moving the iterator to a new position might set them. */
6165 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6169 case GET_FROM_BUFFER
:
6170 /* The current display element of IT is a character from
6171 current_buffer. Advance in the buffer, and maybe skip over
6172 invisible lines that are so because of selective display. */
6173 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6174 reseat_at_next_visible_line_start (it
, 0);
6175 else if (it
->cmp_it
.id
>= 0)
6177 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6178 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6179 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6180 it
->cmp_it
.from
= it
->cmp_it
.to
;
6184 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6185 IT_BYTEPOS (*it
), it
->stop_charpos
,
6191 xassert (it
->len
!= 0);
6195 IT_BYTEPOS (*it
) += it
->len
;
6196 IT_CHARPOS (*it
) += 1;
6200 /* If this is a new paragraph, determine its base
6201 direction (a.k.a. its base embedding level). */
6202 if (it
->bidi_it
.new_paragraph
)
6203 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6204 bidi_get_next_char_visually (&it
->bidi_it
);
6205 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6206 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6208 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6212 case GET_FROM_C_STRING
:
6213 /* Current display element of IT is from a C string. */
6214 IT_BYTEPOS (*it
) += it
->len
;
6215 IT_CHARPOS (*it
) += 1;
6218 case GET_FROM_DISPLAY_VECTOR
:
6219 /* Current display element of IT is from a display table entry.
6220 Advance in the display table definition. Reset it to null if
6221 end reached, and continue with characters from buffers/
6223 ++it
->current
.dpvec_index
;
6225 /* Restore face of the iterator to what they were before the
6226 display vector entry (these entries may contain faces). */
6227 it
->face_id
= it
->saved_face_id
;
6229 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6231 int recheck_faces
= it
->ellipsis_p
;
6234 it
->method
= GET_FROM_C_STRING
;
6235 else if (STRINGP (it
->string
))
6236 it
->method
= GET_FROM_STRING
;
6239 it
->method
= GET_FROM_BUFFER
;
6240 it
->object
= it
->w
->buffer
;
6244 it
->current
.dpvec_index
= -1;
6246 /* Skip over characters which were displayed via IT->dpvec. */
6247 if (it
->dpvec_char_len
< 0)
6248 reseat_at_next_visible_line_start (it
, 1);
6249 else if (it
->dpvec_char_len
> 0)
6251 if (it
->method
== GET_FROM_STRING
6252 && it
->n_overlay_strings
> 0)
6253 it
->ignore_overlay_strings_at_pos_p
= 1;
6254 it
->len
= it
->dpvec_char_len
;
6255 set_iterator_to_next (it
, reseat_p
);
6258 /* Maybe recheck faces after display vector */
6260 it
->stop_charpos
= IT_CHARPOS (*it
);
6264 case GET_FROM_STRING
:
6265 /* Current display element is a character from a Lisp string. */
6266 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6267 if (it
->cmp_it
.id
>= 0)
6269 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6270 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6271 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6272 it
->cmp_it
.from
= it
->cmp_it
.to
;
6276 composition_compute_stop_pos (&it
->cmp_it
,
6277 IT_STRING_CHARPOS (*it
),
6278 IT_STRING_BYTEPOS (*it
),
6279 it
->stop_charpos
, it
->string
);
6284 IT_STRING_BYTEPOS (*it
) += it
->len
;
6285 IT_STRING_CHARPOS (*it
) += 1;
6288 consider_string_end
:
6290 if (it
->current
.overlay_string_index
>= 0)
6292 /* IT->string is an overlay string. Advance to the
6293 next, if there is one. */
6294 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6297 next_overlay_string (it
);
6299 setup_for_ellipsis (it
, 0);
6304 /* IT->string is not an overlay string. If we reached
6305 its end, and there is something on IT->stack, proceed
6306 with what is on the stack. This can be either another
6307 string, this time an overlay string, or a buffer. */
6308 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6312 if (it
->method
== GET_FROM_STRING
)
6313 goto consider_string_end
;
6318 case GET_FROM_IMAGE
:
6319 case GET_FROM_STRETCH
:
6320 /* The position etc with which we have to proceed are on
6321 the stack. The position may be at the end of a string,
6322 if the `display' property takes up the whole string. */
6323 xassert (it
->sp
> 0);
6325 if (it
->method
== GET_FROM_STRING
)
6326 goto consider_string_end
;
6330 /* There are no other methods defined, so this should be a bug. */
6334 xassert (it
->method
!= GET_FROM_STRING
6335 || (STRINGP (it
->string
)
6336 && IT_STRING_CHARPOS (*it
) >= 0));
6339 /* Load IT's display element fields with information about the next
6340 display element which comes from a display table entry or from the
6341 result of translating a control character to one of the forms `^C'
6344 IT->dpvec holds the glyphs to return as characters.
6345 IT->saved_face_id holds the face id before the display vector--it
6346 is restored into IT->face_id in set_iterator_to_next. */
6349 next_element_from_display_vector (it
)
6355 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6357 it
->face_id
= it
->saved_face_id
;
6359 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6360 That seemed totally bogus - so I changed it... */
6361 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6363 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6365 it
->c
= GLYPH_CODE_CHAR (gc
);
6366 it
->len
= CHAR_BYTES (it
->c
);
6368 /* The entry may contain a face id to use. Such a face id is
6369 the id of a Lisp face, not a realized face. A face id of
6370 zero means no face is specified. */
6371 if (it
->dpvec_face_id
>= 0)
6372 it
->face_id
= it
->dpvec_face_id
;
6375 int lface_id
= GLYPH_CODE_FACE (gc
);
6377 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6382 /* Display table entry is invalid. Return a space. */
6383 it
->c
= ' ', it
->len
= 1;
6385 /* Don't change position and object of the iterator here. They are
6386 still the values of the character that had this display table
6387 entry or was translated, and that's what we want. */
6388 it
->what
= IT_CHARACTER
;
6393 /* Load IT with the next display element from Lisp string IT->string.
6394 IT->current.string_pos is the current position within the string.
6395 If IT->current.overlay_string_index >= 0, the Lisp string is an
6399 next_element_from_string (it
)
6402 struct text_pos position
;
6404 xassert (STRINGP (it
->string
));
6405 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6406 position
= it
->current
.string_pos
;
6408 /* Time to check for invisible text? */
6409 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6410 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6414 /* Since a handler may have changed IT->method, we must
6416 return GET_NEXT_DISPLAY_ELEMENT (it
);
6419 if (it
->current
.overlay_string_index
>= 0)
6421 /* Get the next character from an overlay string. In overlay
6422 strings, There is no field width or padding with spaces to
6424 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6429 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6430 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6431 && next_element_from_composition (it
))
6435 else if (STRING_MULTIBYTE (it
->string
))
6437 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6438 const unsigned char *s
= (SDATA (it
->string
)
6439 + IT_STRING_BYTEPOS (*it
));
6440 it
->c
= string_char_and_length (s
, &it
->len
);
6444 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6450 /* Get the next character from a Lisp string that is not an
6451 overlay string. Such strings come from the mode line, for
6452 example. We may have to pad with spaces, or truncate the
6453 string. See also next_element_from_c_string. */
6454 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6459 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6461 /* Pad with spaces. */
6462 it
->c
= ' ', it
->len
= 1;
6463 CHARPOS (position
) = BYTEPOS (position
) = -1;
6465 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6466 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6467 && next_element_from_composition (it
))
6471 else if (STRING_MULTIBYTE (it
->string
))
6473 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6474 const unsigned char *s
= (SDATA (it
->string
)
6475 + IT_STRING_BYTEPOS (*it
));
6476 it
->c
= string_char_and_length (s
, &it
->len
);
6480 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6485 /* Record what we have and where it came from. */
6486 it
->what
= IT_CHARACTER
;
6487 it
->object
= it
->string
;
6488 it
->position
= position
;
6493 /* Load IT with next display element from C string IT->s.
6494 IT->string_nchars is the maximum number of characters to return
6495 from the string. IT->end_charpos may be greater than
6496 IT->string_nchars when this function is called, in which case we
6497 may have to return padding spaces. Value is zero if end of string
6498 reached, including padding spaces. */
6501 next_element_from_c_string (it
)
6507 it
->what
= IT_CHARACTER
;
6508 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6511 /* IT's position can be greater IT->string_nchars in case a field
6512 width or precision has been specified when the iterator was
6514 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6516 /* End of the game. */
6520 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6522 /* Pad with spaces. */
6523 it
->c
= ' ', it
->len
= 1;
6524 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6526 else if (it
->multibyte_p
)
6528 /* Implementation note: The calls to strlen apparently aren't a
6529 performance problem because there is no noticeable performance
6530 difference between Emacs running in unibyte or multibyte mode. */
6531 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6532 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6535 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6541 /* Set up IT to return characters from an ellipsis, if appropriate.
6542 The definition of the ellipsis glyphs may come from a display table
6543 entry. This function fills IT with the first glyph from the
6544 ellipsis if an ellipsis is to be displayed. */
6547 next_element_from_ellipsis (it
)
6550 if (it
->selective_display_ellipsis_p
)
6551 setup_for_ellipsis (it
, it
->len
);
6554 /* The face at the current position may be different from the
6555 face we find after the invisible text. Remember what it
6556 was in IT->saved_face_id, and signal that it's there by
6557 setting face_before_selective_p. */
6558 it
->saved_face_id
= it
->face_id
;
6559 it
->method
= GET_FROM_BUFFER
;
6560 it
->object
= it
->w
->buffer
;
6561 reseat_at_next_visible_line_start (it
, 1);
6562 it
->face_before_selective_p
= 1;
6565 return GET_NEXT_DISPLAY_ELEMENT (it
);
6569 /* Deliver an image display element. The iterator IT is already
6570 filled with image information (done in handle_display_prop). Value
6575 next_element_from_image (it
)
6578 it
->what
= IT_IMAGE
;
6583 /* Fill iterator IT with next display element from a stretch glyph
6584 property. IT->object is the value of the text property. Value is
6588 next_element_from_stretch (it
)
6591 it
->what
= IT_STRETCH
;
6595 /* Scan forward from CHARPOS in the current buffer, until we find a
6596 stop position > current IT's position. Then handle the stop
6597 position before that. This is called when we bump into a stop
6598 position while reordering bidirectional text. */
6601 handle_stop_backwards (it
, charpos
)
6605 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6606 struct display_pos save_current
= it
->current
;
6607 struct text_pos save_position
= it
->position
;
6608 struct text_pos pos1
;
6609 EMACS_INT next_stop
;
6611 /* Scan in strict logical order. */
6615 it
->prev_stop
= charpos
;
6616 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6617 reseat_1 (it
, pos1
, 0);
6618 compute_stop_pos (it
);
6619 /* We must advance forward, right? */
6620 if (it
->stop_charpos
<= it
->prev_stop
)
6622 charpos
= it
->stop_charpos
;
6624 while (charpos
<= where_we_are
);
6626 next_stop
= it
->stop_charpos
;
6627 it
->stop_charpos
= it
->prev_stop
;
6629 it
->current
= save_current
;
6630 it
->position
= save_position
;
6632 it
->stop_charpos
= next_stop
;
6635 /* Load IT with the next display element from current_buffer. Value
6636 is zero if end of buffer reached. IT->stop_charpos is the next
6637 position at which to stop and check for text properties or buffer
6641 next_element_from_buffer (it
)
6646 xassert (IT_CHARPOS (*it
) >= BEGV
);
6648 /* With bidi reordering, the character to display might not be the
6649 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6650 we were reseat()ed to a new buffer position, which is potentially
6651 a different paragraph. */
6652 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6654 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6655 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6656 /* If we are at the beginning of a line, we can produce the next
6657 element right away. */
6658 if (it
->bidi_it
.bytepos
== BEGV_BYTE
6659 /* FIXME: Should support all Unicode line separators. */
6660 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6661 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6663 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6664 /* If the paragraph base direction is R2L, its glyphs should
6666 if (it
->glyph_row
&& (it
->bidi_it
.level_stack
[0].level
& 1) != 0)
6667 it
->glyph_row
->reversed_p
= 1;
6668 bidi_get_next_char_visually (&it
->bidi_it
);
6672 int orig_bytepos
= IT_BYTEPOS (*it
);
6674 /* We need to prime the bidi iterator starting at the line's
6675 beginning, before we will be able to produce the next
6677 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6678 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6679 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6680 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6681 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6682 if (it
->glyph_row
&& (it
->bidi_it
.level_stack
[0].level
& 1) != 0)
6683 it
->glyph_row
->reversed_p
= 1;
6686 /* Now return to buffer position where we were asked to
6687 get the next display element, and produce that. */
6688 bidi_get_next_char_visually (&it
->bidi_it
);
6690 while (it
->bidi_it
.bytepos
!= orig_bytepos
6691 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6694 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6695 /* Adjust IT's position information to where we ended up. */
6696 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6697 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6698 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6701 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6703 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6705 int overlay_strings_follow_p
;
6707 /* End of the game, except when overlay strings follow that
6708 haven't been returned yet. */
6709 if (it
->overlay_strings_at_end_processed_p
)
6710 overlay_strings_follow_p
= 0;
6713 it
->overlay_strings_at_end_processed_p
= 1;
6714 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6717 if (overlay_strings_follow_p
)
6718 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6722 it
->position
= it
->current
.pos
;
6726 else if (!(!it
->bidi_p
6727 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6728 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6730 /* With bidi non-linear iteration, we could find ourselves
6731 far beyond the last computed stop_charpos, with several
6732 other stop positions in between that we missed. Scan
6733 them all now, in buffer's logical order, until we find
6734 and handle the last stop_charpos that precedes our
6735 current position. */
6736 handle_stop_backwards (it
, it
->stop_charpos
);
6737 return GET_NEXT_DISPLAY_ELEMENT (it
);
6743 /* Take note of the stop position we just moved across,
6744 for when we will move back across it. */
6745 it
->prev_stop
= it
->stop_charpos
;
6746 /* If we are at base paragraph embedding level, take
6747 note of the last stop position seen at this
6749 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6750 it
->base_level_stop
= it
->stop_charpos
;
6753 return GET_NEXT_DISPLAY_ELEMENT (it
);
6757 /* We can sometimes back up for reasons that have nothing
6758 to do with bidi reordering. E.g., compositions. The
6759 code below is only needed when we are above the base
6760 embedding level, so test for that explicitly. */
6761 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6762 && IT_CHARPOS (*it
) < it
->prev_stop
)
6764 if (it
->base_level_stop
<= 0)
6765 it
->base_level_stop
= BEGV
;
6766 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6768 handle_stop_backwards (it
, it
->base_level_stop
);
6769 return GET_NEXT_DISPLAY_ELEMENT (it
);
6773 /* No face changes, overlays etc. in sight, so just return a
6774 character from current_buffer. */
6777 /* Maybe run the redisplay end trigger hook. Performance note:
6778 This doesn't seem to cost measurable time. */
6779 if (it
->redisplay_end_trigger_charpos
6781 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6782 run_redisplay_end_trigger_hook (it
);
6784 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6786 && next_element_from_composition (it
))
6791 /* Get the next character, maybe multibyte. */
6792 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6793 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6794 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6796 it
->c
= *p
, it
->len
= 1;
6798 /* Record what we have and where it came from. */
6799 it
->what
= IT_CHARACTER
;
6800 it
->object
= it
->w
->buffer
;
6801 it
->position
= it
->current
.pos
;
6803 /* Normally we return the character found above, except when we
6804 really want to return an ellipsis for selective display. */
6809 /* A value of selective > 0 means hide lines indented more
6810 than that number of columns. */
6811 if (it
->selective
> 0
6812 && IT_CHARPOS (*it
) + 1 < ZV
6813 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6814 IT_BYTEPOS (*it
) + 1,
6815 (double) it
->selective
)) /* iftc */
6817 success_p
= next_element_from_ellipsis (it
);
6818 it
->dpvec_char_len
= -1;
6821 else if (it
->c
== '\r' && it
->selective
== -1)
6823 /* A value of selective == -1 means that everything from the
6824 CR to the end of the line is invisible, with maybe an
6825 ellipsis displayed for it. */
6826 success_p
= next_element_from_ellipsis (it
);
6827 it
->dpvec_char_len
= -1;
6832 /* Value is zero if end of buffer reached. */
6833 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6838 /* Run the redisplay end trigger hook for IT. */
6841 run_redisplay_end_trigger_hook (it
)
6844 Lisp_Object args
[3];
6846 /* IT->glyph_row should be non-null, i.e. we should be actually
6847 displaying something, or otherwise we should not run the hook. */
6848 xassert (it
->glyph_row
);
6850 /* Set up hook arguments. */
6851 args
[0] = Qredisplay_end_trigger_functions
;
6852 args
[1] = it
->window
;
6853 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6854 it
->redisplay_end_trigger_charpos
= 0;
6856 /* Since we are *trying* to run these functions, don't try to run
6857 them again, even if they get an error. */
6858 it
->w
->redisplay_end_trigger
= Qnil
;
6859 Frun_hook_with_args (3, args
);
6861 /* Notice if it changed the face of the character we are on. */
6862 handle_face_prop (it
);
6866 /* Deliver a composition display element. Unlike the other
6867 next_element_from_XXX, this function is not registered in the array
6868 get_next_element[]. It is called from next_element_from_buffer and
6869 next_element_from_string when necessary. */
6872 next_element_from_composition (it
)
6875 it
->what
= IT_COMPOSITION
;
6876 it
->len
= it
->cmp_it
.nbytes
;
6877 if (STRINGP (it
->string
))
6881 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6882 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6885 it
->position
= it
->current
.string_pos
;
6886 it
->object
= it
->string
;
6887 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6888 IT_STRING_BYTEPOS (*it
), it
->string
);
6894 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6895 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6898 it
->position
= it
->current
.pos
;
6899 it
->object
= it
->w
->buffer
;
6900 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6901 IT_BYTEPOS (*it
), Qnil
);
6908 /***********************************************************************
6909 Moving an iterator without producing glyphs
6910 ***********************************************************************/
6912 /* Check if iterator is at a position corresponding to a valid buffer
6913 position after some move_it_ call. */
6915 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6916 ((it)->method == GET_FROM_STRING \
6917 ? IT_STRING_CHARPOS (*it) == 0 \
6921 /* Move iterator IT to a specified buffer or X position within one
6922 line on the display without producing glyphs.
6924 OP should be a bit mask including some or all of these bits:
6925 MOVE_TO_X: Stop upon reaching x-position TO_X.
6926 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
6927 Regardless of OP's value, stop upon reaching the end of the display line.
6929 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6930 This means, in particular, that TO_X includes window's horizontal
6933 The return value has several possible values that
6934 say what condition caused the scan to stop:
6936 MOVE_POS_MATCH_OR_ZV
6937 - when TO_POS or ZV was reached.
6940 -when TO_X was reached before TO_POS or ZV were reached.
6943 - when we reached the end of the display area and the line must
6947 - when we reached the end of the display area and the line is
6951 - when we stopped at a line end, i.e. a newline or a CR and selective
6954 static enum move_it_result
6955 move_it_in_display_line_to (struct it
*it
,
6956 EMACS_INT to_charpos
, int to_x
,
6957 enum move_operation_enum op
)
6959 enum move_it_result result
= MOVE_UNDEFINED
;
6960 struct glyph_row
*saved_glyph_row
;
6961 struct it wrap_it
, atpos_it
, atx_it
;
6964 /* Don't produce glyphs in produce_glyphs. */
6965 saved_glyph_row
= it
->glyph_row
;
6966 it
->glyph_row
= NULL
;
6968 /* Use wrap_it to save a copy of IT wherever a word wrap could
6969 occur. Use atpos_it to save a copy of IT at the desired buffer
6970 position, if found, so that we can scan ahead and check if the
6971 word later overshoots the window edge. Use atx_it similarly, for
6977 #define BUFFER_POS_REACHED_P() \
6978 ((op & MOVE_TO_POS) != 0 \
6979 && BUFFERP (it->object) \
6980 && IT_CHARPOS (*it) >= to_charpos \
6981 && (it->method == GET_FROM_BUFFER \
6982 || (it->method == GET_FROM_DISPLAY_VECTOR \
6983 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6985 /* If there's a line-/wrap-prefix, handle it. */
6986 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6987 && it
->current_y
< it
->last_visible_y
)
6988 handle_line_prefix (it
);
6992 int x
, i
, ascent
= 0, descent
= 0;
6994 /* Utility macro to reset an iterator with x, ascent, and descent. */
6995 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6996 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6997 (IT)->max_descent = descent)
6999 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7001 if ((op
& MOVE_TO_POS
) != 0
7002 && BUFFERP (it
->object
)
7003 && it
->method
== GET_FROM_BUFFER
7004 && IT_CHARPOS (*it
) > to_charpos
)
7006 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7008 result
= MOVE_POS_MATCH_OR_ZV
;
7011 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7012 /* If wrap_it is valid, the current position might be in a
7013 word that is wrapped. So, save the iterator in
7014 atpos_it and continue to see if wrapping happens. */
7018 /* Stop when ZV reached.
7019 We used to stop here when TO_CHARPOS reached as well, but that is
7020 too soon if this glyph does not fit on this line. So we handle it
7021 explicitly below. */
7022 if (!get_next_display_element (it
))
7024 result
= MOVE_POS_MATCH_OR_ZV
;
7028 if (it
->line_wrap
== TRUNCATE
)
7030 if (BUFFER_POS_REACHED_P ())
7032 result
= MOVE_POS_MATCH_OR_ZV
;
7038 if (it
->line_wrap
== WORD_WRAP
)
7040 if (IT_DISPLAYING_WHITESPACE (it
))
7044 /* We have reached a glyph that follows one or more
7045 whitespace characters. If the position is
7046 already found, we are done. */
7047 if (atpos_it
.sp
>= 0)
7050 result
= MOVE_POS_MATCH_OR_ZV
;
7056 result
= MOVE_X_REACHED
;
7059 /* Otherwise, we can wrap here. */
7066 /* Remember the line height for the current line, in case
7067 the next element doesn't fit on the line. */
7068 ascent
= it
->max_ascent
;
7069 descent
= it
->max_descent
;
7071 /* The call to produce_glyphs will get the metrics of the
7072 display element IT is loaded with. Record the x-position
7073 before this display element, in case it doesn't fit on the
7077 PRODUCE_GLYPHS (it
);
7079 if (it
->area
!= TEXT_AREA
)
7081 set_iterator_to_next (it
, 1);
7085 /* The number of glyphs we get back in IT->nglyphs will normally
7086 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7087 character on a terminal frame, or (iii) a line end. For the
7088 second case, IT->nglyphs - 1 padding glyphs will be present.
7089 (On X frames, there is only one glyph produced for a
7090 composite character.)
7092 The behavior implemented below means, for continuation lines,
7093 that as many spaces of a TAB as fit on the current line are
7094 displayed there. For terminal frames, as many glyphs of a
7095 multi-glyph character are displayed in the current line, too.
7096 This is what the old redisplay code did, and we keep it that
7097 way. Under X, the whole shape of a complex character must
7098 fit on the line or it will be completely displayed in the
7101 Note that both for tabs and padding glyphs, all glyphs have
7105 /* More than one glyph or glyph doesn't fit on line. All
7106 glyphs have the same width. */
7107 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7109 int x_before_this_char
= x
;
7110 int hpos_before_this_char
= it
->hpos
;
7112 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7114 new_x
= x
+ single_glyph_width
;
7116 /* We want to leave anything reaching TO_X to the caller. */
7117 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7119 if (BUFFER_POS_REACHED_P ())
7121 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7122 goto buffer_pos_reached
;
7123 if (atpos_it
.sp
< 0)
7126 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7131 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7134 result
= MOVE_X_REACHED
;
7140 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7145 if (/* Lines are continued. */
7146 it
->line_wrap
!= TRUNCATE
7147 && (/* And glyph doesn't fit on the line. */
7148 new_x
> it
->last_visible_x
7149 /* Or it fits exactly and we're on a window
7151 || (new_x
== it
->last_visible_x
7152 && FRAME_WINDOW_P (it
->f
))))
7154 if (/* IT->hpos == 0 means the very first glyph
7155 doesn't fit on the line, e.g. a wide image. */
7157 || (new_x
== it
->last_visible_x
7158 && FRAME_WINDOW_P (it
->f
)))
7161 it
->current_x
= new_x
;
7163 /* The character's last glyph just barely fits
7165 if (i
== it
->nglyphs
- 1)
7167 /* If this is the destination position,
7168 return a position *before* it in this row,
7169 now that we know it fits in this row. */
7170 if (BUFFER_POS_REACHED_P ())
7172 if (it
->line_wrap
!= WORD_WRAP
7175 it
->hpos
= hpos_before_this_char
;
7176 it
->current_x
= x_before_this_char
;
7177 result
= MOVE_POS_MATCH_OR_ZV
;
7180 if (it
->line_wrap
== WORD_WRAP
7184 atpos_it
.current_x
= x_before_this_char
;
7185 atpos_it
.hpos
= hpos_before_this_char
;
7189 set_iterator_to_next (it
, 1);
7190 /* On graphical terminals, newlines may
7191 "overflow" into the fringe if
7192 overflow-newline-into-fringe is non-nil.
7193 On text-only terminals, newlines may
7194 overflow into the last glyph on the
7196 if (!FRAME_WINDOW_P (it
->f
)
7197 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7199 if (!get_next_display_element (it
))
7201 result
= MOVE_POS_MATCH_OR_ZV
;
7204 if (BUFFER_POS_REACHED_P ())
7206 if (ITERATOR_AT_END_OF_LINE_P (it
))
7207 result
= MOVE_POS_MATCH_OR_ZV
;
7209 result
= MOVE_LINE_CONTINUED
;
7212 if (ITERATOR_AT_END_OF_LINE_P (it
))
7214 result
= MOVE_NEWLINE_OR_CR
;
7221 IT_RESET_X_ASCENT_DESCENT (it
);
7223 if (wrap_it
.sp
>= 0)
7230 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7232 result
= MOVE_LINE_CONTINUED
;
7236 if (BUFFER_POS_REACHED_P ())
7238 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7239 goto buffer_pos_reached
;
7240 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7243 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7247 if (new_x
> it
->first_visible_x
)
7249 /* Glyph is visible. Increment number of glyphs that
7250 would be displayed. */
7255 if (result
!= MOVE_UNDEFINED
)
7258 else if (BUFFER_POS_REACHED_P ())
7261 IT_RESET_X_ASCENT_DESCENT (it
);
7262 result
= MOVE_POS_MATCH_OR_ZV
;
7265 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7267 /* Stop when TO_X specified and reached. This check is
7268 necessary here because of lines consisting of a line end,
7269 only. The line end will not produce any glyphs and we
7270 would never get MOVE_X_REACHED. */
7271 xassert (it
->nglyphs
== 0);
7272 result
= MOVE_X_REACHED
;
7276 /* Is this a line end? If yes, we're done. */
7277 if (ITERATOR_AT_END_OF_LINE_P (it
))
7279 result
= MOVE_NEWLINE_OR_CR
;
7283 /* The current display element has been consumed. Advance
7285 set_iterator_to_next (it
, 1);
7287 /* Stop if lines are truncated and IT's current x-position is
7288 past the right edge of the window now. */
7289 if (it
->line_wrap
== TRUNCATE
7290 && it
->current_x
>= it
->last_visible_x
)
7292 if (!FRAME_WINDOW_P (it
->f
)
7293 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7295 if (!get_next_display_element (it
)
7296 || BUFFER_POS_REACHED_P ())
7298 result
= MOVE_POS_MATCH_OR_ZV
;
7301 if (ITERATOR_AT_END_OF_LINE_P (it
))
7303 result
= MOVE_NEWLINE_OR_CR
;
7307 result
= MOVE_LINE_TRUNCATED
;
7310 #undef IT_RESET_X_ASCENT_DESCENT
7313 #undef BUFFER_POS_REACHED_P
7315 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7316 restore the saved iterator. */
7317 if (atpos_it
.sp
>= 0)
7319 else if (atx_it
.sp
>= 0)
7324 /* Restore the iterator settings altered at the beginning of this
7326 it
->glyph_row
= saved_glyph_row
;
7330 /* For external use. */
7332 move_it_in_display_line (struct it
*it
,
7333 EMACS_INT to_charpos
, int to_x
,
7334 enum move_operation_enum op
)
7336 if (it
->line_wrap
== WORD_WRAP
7337 && (op
& MOVE_TO_X
))
7339 struct it save_it
= *it
;
7340 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7341 /* When word-wrap is on, TO_X may lie past the end
7342 of a wrapped line. Then it->current is the
7343 character on the next line, so backtrack to the
7344 space before the wrap point. */
7345 if (skip
== MOVE_LINE_CONTINUED
)
7347 int prev_x
= max (it
->current_x
- 1, 0);
7349 move_it_in_display_line_to
7350 (it
, -1, prev_x
, MOVE_TO_X
);
7354 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7358 /* Move IT forward until it satisfies one or more of the criteria in
7359 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7361 OP is a bit-mask that specifies where to stop, and in particular,
7362 which of those four position arguments makes a difference. See the
7363 description of enum move_operation_enum.
7365 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7366 screen line, this function will set IT to the next position >
7370 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7372 int to_charpos
, to_x
, to_y
, to_vpos
;
7375 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7376 int line_height
, line_start_x
= 0, reached
= 0;
7380 if (op
& MOVE_TO_VPOS
)
7382 /* If no TO_CHARPOS and no TO_X specified, stop at the
7383 start of the line TO_VPOS. */
7384 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7386 if (it
->vpos
== to_vpos
)
7392 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7396 /* TO_VPOS >= 0 means stop at TO_X in the line at
7397 TO_VPOS, or at TO_POS, whichever comes first. */
7398 if (it
->vpos
== to_vpos
)
7404 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7406 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7411 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7413 /* We have reached TO_X but not in the line we want. */
7414 skip
= move_it_in_display_line_to (it
, to_charpos
,
7416 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7424 else if (op
& MOVE_TO_Y
)
7426 struct it it_backup
;
7428 if (it
->line_wrap
== WORD_WRAP
)
7431 /* TO_Y specified means stop at TO_X in the line containing
7432 TO_Y---or at TO_CHARPOS if this is reached first. The
7433 problem is that we can't really tell whether the line
7434 contains TO_Y before we have completely scanned it, and
7435 this may skip past TO_X. What we do is to first scan to
7438 If TO_X is not specified, use a TO_X of zero. The reason
7439 is to make the outcome of this function more predictable.
7440 If we didn't use TO_X == 0, we would stop at the end of
7441 the line which is probably not what a caller would expect
7443 skip
= move_it_in_display_line_to
7444 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7445 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7447 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7448 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7450 else if (skip
== MOVE_X_REACHED
)
7452 /* If TO_X was reached, we want to know whether TO_Y is
7453 in the line. We know this is the case if the already
7454 scanned glyphs make the line tall enough. Otherwise,
7455 we must check by scanning the rest of the line. */
7456 line_height
= it
->max_ascent
+ it
->max_descent
;
7457 if (to_y
>= it
->current_y
7458 && to_y
< it
->current_y
+ line_height
)
7464 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7465 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7467 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7468 line_height
= it
->max_ascent
+ it
->max_descent
;
7469 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7471 if (to_y
>= it
->current_y
7472 && to_y
< it
->current_y
+ line_height
)
7474 /* If TO_Y is in this line and TO_X was reached
7475 above, we scanned too far. We have to restore
7476 IT's settings to the ones before skipping. */
7483 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7489 /* Check whether TO_Y is in this line. */
7490 line_height
= it
->max_ascent
+ it
->max_descent
;
7491 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7493 if (to_y
>= it
->current_y
7494 && to_y
< it
->current_y
+ line_height
)
7496 /* When word-wrap is on, TO_X may lie past the end
7497 of a wrapped line. Then it->current is the
7498 character on the next line, so backtrack to the
7499 space before the wrap point. */
7500 if (skip
== MOVE_LINE_CONTINUED
7501 && it
->line_wrap
== WORD_WRAP
)
7503 int prev_x
= max (it
->current_x
- 1, 0);
7505 skip
= move_it_in_display_line_to
7506 (it
, -1, prev_x
, MOVE_TO_X
);
7515 else if (BUFFERP (it
->object
)
7516 && (it
->method
== GET_FROM_BUFFER
7517 || it
->method
== GET_FROM_STRETCH
)
7518 && IT_CHARPOS (*it
) >= to_charpos
)
7519 skip
= MOVE_POS_MATCH_OR_ZV
;
7521 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7525 case MOVE_POS_MATCH_OR_ZV
:
7529 case MOVE_NEWLINE_OR_CR
:
7530 set_iterator_to_next (it
, 1);
7531 it
->continuation_lines_width
= 0;
7534 case MOVE_LINE_TRUNCATED
:
7535 it
->continuation_lines_width
= 0;
7536 reseat_at_next_visible_line_start (it
, 0);
7537 if ((op
& MOVE_TO_POS
) != 0
7538 && IT_CHARPOS (*it
) > to_charpos
)
7545 case MOVE_LINE_CONTINUED
:
7546 /* For continued lines ending in a tab, some of the glyphs
7547 associated with the tab are displayed on the current
7548 line. Since it->current_x does not include these glyphs,
7549 we use it->last_visible_x instead. */
7552 it
->continuation_lines_width
+= it
->last_visible_x
;
7553 /* When moving by vpos, ensure that the iterator really
7554 advances to the next line (bug#847, bug#969). Fixme:
7555 do we need to do this in other circumstances? */
7556 if (it
->current_x
!= it
->last_visible_x
7557 && (op
& MOVE_TO_VPOS
)
7558 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7560 line_start_x
= it
->current_x
+ it
->pixel_width
7561 - it
->last_visible_x
;
7562 set_iterator_to_next (it
, 0);
7566 it
->continuation_lines_width
+= it
->current_x
;
7573 /* Reset/increment for the next run. */
7574 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7575 it
->current_x
= line_start_x
;
7578 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7580 last_height
= it
->max_ascent
+ it
->max_descent
;
7581 last_max_ascent
= it
->max_ascent
;
7582 it
->max_ascent
= it
->max_descent
= 0;
7587 /* On text terminals, we may stop at the end of a line in the middle
7588 of a multi-character glyph. If the glyph itself is continued,
7589 i.e. it is actually displayed on the next line, don't treat this
7590 stopping point as valid; move to the next line instead (unless
7591 that brings us offscreen). */
7592 if (!FRAME_WINDOW_P (it
->f
)
7594 && IT_CHARPOS (*it
) == to_charpos
7595 && it
->what
== IT_CHARACTER
7597 && it
->line_wrap
== WINDOW_WRAP
7598 && it
->current_x
== it
->last_visible_x
- 1
7601 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7603 it
->continuation_lines_width
+= it
->current_x
;
7604 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7605 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7607 last_height
= it
->max_ascent
+ it
->max_descent
;
7608 last_max_ascent
= it
->max_ascent
;
7611 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7615 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7617 If DY > 0, move IT backward at least that many pixels. DY = 0
7618 means move IT backward to the preceding line start or BEGV. This
7619 function may move over more than DY pixels if IT->current_y - DY
7620 ends up in the middle of a line; in this case IT->current_y will be
7621 set to the top of the line moved to. */
7624 move_it_vertically_backward (it
, dy
)
7635 start_pos
= IT_CHARPOS (*it
);
7637 /* Estimate how many newlines we must move back. */
7638 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7640 /* Set the iterator's position that many lines back. */
7641 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7642 back_to_previous_visible_line_start (it
);
7644 /* Reseat the iterator here. When moving backward, we don't want
7645 reseat to skip forward over invisible text, set up the iterator
7646 to deliver from overlay strings at the new position etc. So,
7647 use reseat_1 here. */
7648 reseat_1 (it
, it
->current
.pos
, 1);
7650 /* We are now surely at a line start. */
7651 it
->current_x
= it
->hpos
= 0;
7652 it
->continuation_lines_width
= 0;
7654 /* Move forward and see what y-distance we moved. First move to the
7655 start of the next line so that we get its height. We need this
7656 height to be able to tell whether we reached the specified
7659 it2
.max_ascent
= it2
.max_descent
= 0;
7662 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7663 MOVE_TO_POS
| MOVE_TO_VPOS
);
7665 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7666 xassert (IT_CHARPOS (*it
) >= BEGV
);
7669 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7670 xassert (IT_CHARPOS (*it
) >= BEGV
);
7671 /* H is the actual vertical distance from the position in *IT
7672 and the starting position. */
7673 h
= it2
.current_y
- it
->current_y
;
7674 /* NLINES is the distance in number of lines. */
7675 nlines
= it2
.vpos
- it
->vpos
;
7677 /* Correct IT's y and vpos position
7678 so that they are relative to the starting point. */
7684 /* DY == 0 means move to the start of the screen line. The
7685 value of nlines is > 0 if continuation lines were involved. */
7687 move_it_by_lines (it
, nlines
, 1);
7691 /* The y-position we try to reach, relative to *IT.
7692 Note that H has been subtracted in front of the if-statement. */
7693 int target_y
= it
->current_y
+ h
- dy
;
7694 int y0
= it3
.current_y
;
7695 int y1
= line_bottom_y (&it3
);
7696 int line_height
= y1
- y0
;
7698 /* If we did not reach target_y, try to move further backward if
7699 we can. If we moved too far backward, try to move forward. */
7700 if (target_y
< it
->current_y
7701 /* This is heuristic. In a window that's 3 lines high, with
7702 a line height of 13 pixels each, recentering with point
7703 on the bottom line will try to move -39/2 = 19 pixels
7704 backward. Try to avoid moving into the first line. */
7705 && (it
->current_y
- target_y
7706 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7707 && IT_CHARPOS (*it
) > BEGV
)
7709 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7710 target_y
- it
->current_y
));
7711 dy
= it
->current_y
- target_y
;
7712 goto move_further_back
;
7714 else if (target_y
>= it
->current_y
+ line_height
7715 && IT_CHARPOS (*it
) < ZV
)
7717 /* Should move forward by at least one line, maybe more.
7719 Note: Calling move_it_by_lines can be expensive on
7720 terminal frames, where compute_motion is used (via
7721 vmotion) to do the job, when there are very long lines
7722 and truncate-lines is nil. That's the reason for
7723 treating terminal frames specially here. */
7725 if (!FRAME_WINDOW_P (it
->f
))
7726 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7731 move_it_by_lines (it
, 1, 1);
7733 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7740 /* Move IT by a specified amount of pixel lines DY. DY negative means
7741 move backwards. DY = 0 means move to start of screen line. At the
7742 end, IT will be on the start of a screen line. */
7745 move_it_vertically (it
, dy
)
7750 move_it_vertically_backward (it
, -dy
);
7753 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7754 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7755 MOVE_TO_POS
| MOVE_TO_Y
);
7756 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7758 /* If buffer ends in ZV without a newline, move to the start of
7759 the line to satisfy the post-condition. */
7760 if (IT_CHARPOS (*it
) == ZV
7762 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7763 move_it_by_lines (it
, 0, 0);
7768 /* Move iterator IT past the end of the text line it is in. */
7771 move_it_past_eol (it
)
7774 enum move_it_result rc
;
7776 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7777 if (rc
== MOVE_NEWLINE_OR_CR
)
7778 set_iterator_to_next (it
, 0);
7782 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7783 negative means move up. DVPOS == 0 means move to the start of the
7784 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7785 NEED_Y_P is zero, IT->current_y will be left unchanged.
7787 Further optimization ideas: If we would know that IT->f doesn't use
7788 a face with proportional font, we could be faster for
7789 truncate-lines nil. */
7792 move_it_by_lines (it
, dvpos
, need_y_p
)
7794 int dvpos
, need_y_p
;
7796 struct position pos
;
7798 /* The commented-out optimization uses vmotion on terminals. This
7799 gives bad results, because elements like it->what, on which
7800 callers such as pos_visible_p rely, aren't updated. */
7801 /* if (!FRAME_WINDOW_P (it->f))
7803 struct text_pos textpos;
7805 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7806 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7807 reseat (it, textpos, 1);
7808 it->vpos += pos.vpos;
7809 it->current_y += pos.vpos;
7815 /* DVPOS == 0 means move to the start of the screen line. */
7816 move_it_vertically_backward (it
, 0);
7817 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7818 /* Let next call to line_bottom_y calculate real line height */
7823 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7824 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7825 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7830 int start_charpos
, i
;
7832 /* Start at the beginning of the screen line containing IT's
7833 position. This may actually move vertically backwards,
7834 in case of overlays, so adjust dvpos accordingly. */
7836 move_it_vertically_backward (it
, 0);
7839 /* Go back -DVPOS visible lines and reseat the iterator there. */
7840 start_charpos
= IT_CHARPOS (*it
);
7841 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7842 back_to_previous_visible_line_start (it
);
7843 reseat (it
, it
->current
.pos
, 1);
7845 /* Move further back if we end up in a string or an image. */
7846 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7848 /* First try to move to start of display line. */
7850 move_it_vertically_backward (it
, 0);
7852 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7854 /* If start of line is still in string or image,
7855 move further back. */
7856 back_to_previous_visible_line_start (it
);
7857 reseat (it
, it
->current
.pos
, 1);
7861 it
->current_x
= it
->hpos
= 0;
7863 /* Above call may have moved too far if continuation lines
7864 are involved. Scan forward and see if it did. */
7866 it2
.vpos
= it2
.current_y
= 0;
7867 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7868 it
->vpos
-= it2
.vpos
;
7869 it
->current_y
-= it2
.current_y
;
7870 it
->current_x
= it
->hpos
= 0;
7872 /* If we moved too far back, move IT some lines forward. */
7873 if (it2
.vpos
> -dvpos
)
7875 int delta
= it2
.vpos
+ dvpos
;
7877 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7878 /* Move back again if we got too far ahead. */
7879 if (IT_CHARPOS (*it
) >= start_charpos
)
7885 /* Return 1 if IT points into the middle of a display vector. */
7888 in_display_vector_p (it
)
7891 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7892 && it
->current
.dpvec_index
> 0
7893 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7897 /***********************************************************************
7899 ***********************************************************************/
7902 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7906 add_to_log (format
, arg1
, arg2
)
7908 Lisp_Object arg1
, arg2
;
7910 Lisp_Object args
[3];
7911 Lisp_Object msg
, fmt
;
7914 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7917 /* Do nothing if called asynchronously. Inserting text into
7918 a buffer may call after-change-functions and alike and
7919 that would means running Lisp asynchronously. */
7920 if (handling_signal
)
7924 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7926 args
[0] = fmt
= build_string (format
);
7929 msg
= Fformat (3, args
);
7931 len
= SBYTES (msg
) + 1;
7932 SAFE_ALLOCA (buffer
, char *, len
);
7933 bcopy (SDATA (msg
), buffer
, len
);
7935 message_dolog (buffer
, len
- 1, 1, 0);
7942 /* Output a newline in the *Messages* buffer if "needs" one. */
7945 message_log_maybe_newline ()
7947 if (message_log_need_newline
)
7948 message_dolog ("", 0, 1, 0);
7952 /* Add a string M of length NBYTES to the message log, optionally
7953 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7954 nonzero, means interpret the contents of M as multibyte. This
7955 function calls low-level routines in order to bypass text property
7956 hooks, etc. which might not be safe to run.
7958 This may GC (insert may run before/after change hooks),
7959 so the buffer M must NOT point to a Lisp string. */
7962 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7964 int nbytes
, nlflag
, multibyte
;
7966 if (!NILP (Vmemory_full
))
7969 if (!NILP (Vmessage_log_max
))
7971 struct buffer
*oldbuf
;
7972 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7973 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7974 int point_at_end
= 0;
7976 Lisp_Object old_deactivate_mark
, tem
;
7977 struct gcpro gcpro1
;
7979 old_deactivate_mark
= Vdeactivate_mark
;
7980 oldbuf
= current_buffer
;
7981 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7982 current_buffer
->undo_list
= Qt
;
7984 oldpoint
= message_dolog_marker1
;
7985 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7986 oldbegv
= message_dolog_marker2
;
7987 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7988 oldzv
= message_dolog_marker3
;
7989 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7990 GCPRO1 (old_deactivate_mark
);
7998 BEGV_BYTE
= BEG_BYTE
;
8001 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8003 /* Insert the string--maybe converting multibyte to single byte
8004 or vice versa, so that all the text fits the buffer. */
8006 && NILP (current_buffer
->enable_multibyte_characters
))
8008 int i
, c
, char_bytes
;
8009 unsigned char work
[1];
8011 /* Convert a multibyte string to single-byte
8012 for the *Message* buffer. */
8013 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8015 c
= string_char_and_length (m
+ i
, &char_bytes
);
8016 work
[0] = (ASCII_CHAR_P (c
)
8018 : multibyte_char_to_unibyte (c
, Qnil
));
8019 insert_1_both (work
, 1, 1, 1, 0, 0);
8022 else if (! multibyte
8023 && ! NILP (current_buffer
->enable_multibyte_characters
))
8025 int i
, c
, char_bytes
;
8026 unsigned char *msg
= (unsigned char *) m
;
8027 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8028 /* Convert a single-byte string to multibyte
8029 for the *Message* buffer. */
8030 for (i
= 0; i
< nbytes
; i
++)
8033 MAKE_CHAR_MULTIBYTE (c
);
8034 char_bytes
= CHAR_STRING (c
, str
);
8035 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
8039 insert_1 (m
, nbytes
, 1, 0, 0);
8043 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
8044 insert_1 ("\n", 1, 1, 0, 0);
8046 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8048 this_bol_byte
= PT_BYTE
;
8050 /* See if this line duplicates the previous one.
8051 If so, combine duplicates. */
8054 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8056 prev_bol_byte
= PT_BYTE
;
8058 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
8059 this_bol
, this_bol_byte
);
8062 del_range_both (prev_bol
, prev_bol_byte
,
8063 this_bol
, this_bol_byte
, 0);
8069 /* If you change this format, don't forget to also
8070 change message_log_check_duplicate. */
8071 sprintf (dupstr
, " [%d times]", dup
);
8072 duplen
= strlen (dupstr
);
8073 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8074 insert_1 (dupstr
, duplen
, 1, 0, 1);
8079 /* If we have more than the desired maximum number of lines
8080 in the *Messages* buffer now, delete the oldest ones.
8081 This is safe because we don't have undo in this buffer. */
8083 if (NATNUMP (Vmessage_log_max
))
8085 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8086 -XFASTINT (Vmessage_log_max
) - 1, 0);
8087 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8090 BEGV
= XMARKER (oldbegv
)->charpos
;
8091 BEGV_BYTE
= marker_byte_position (oldbegv
);
8100 ZV
= XMARKER (oldzv
)->charpos
;
8101 ZV_BYTE
= marker_byte_position (oldzv
);
8105 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8107 /* We can't do Fgoto_char (oldpoint) because it will run some
8109 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8110 XMARKER (oldpoint
)->bytepos
);
8113 unchain_marker (XMARKER (oldpoint
));
8114 unchain_marker (XMARKER (oldbegv
));
8115 unchain_marker (XMARKER (oldzv
));
8117 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8118 set_buffer_internal (oldbuf
);
8120 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8121 message_log_need_newline
= !nlflag
;
8122 Vdeactivate_mark
= old_deactivate_mark
;
8127 /* We are at the end of the buffer after just having inserted a newline.
8128 (Note: We depend on the fact we won't be crossing the gap.)
8129 Check to see if the most recent message looks a lot like the previous one.
8130 Return 0 if different, 1 if the new one should just replace it, or a
8131 value N > 1 if we should also append " [N times]". */
8134 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
8135 int prev_bol
, this_bol
;
8136 int prev_bol_byte
, this_bol_byte
;
8139 int len
= Z_BYTE
- 1 - this_bol_byte
;
8141 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8142 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8144 for (i
= 0; i
< len
; i
++)
8146 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8154 if (*p1
++ == ' ' && *p1
++ == '[')
8157 while (*p1
>= '0' && *p1
<= '9')
8158 n
= n
* 10 + *p1
++ - '0';
8159 if (strncmp (p1
, " times]\n", 8) == 0)
8166 /* Display an echo area message M with a specified length of NBYTES
8167 bytes. The string may include null characters. If M is 0, clear
8168 out any existing message, and let the mini-buffer text show
8171 This may GC, so the buffer M must NOT point to a Lisp string. */
8174 message2 (m
, nbytes
, multibyte
)
8179 /* First flush out any partial line written with print. */
8180 message_log_maybe_newline ();
8182 message_dolog (m
, nbytes
, 1, multibyte
);
8183 message2_nolog (m
, nbytes
, multibyte
);
8187 /* The non-logging counterpart of message2. */
8190 message2_nolog (m
, nbytes
, multibyte
)
8192 int nbytes
, multibyte
;
8194 struct frame
*sf
= SELECTED_FRAME ();
8195 message_enable_multibyte
= multibyte
;
8197 if (FRAME_INITIAL_P (sf
))
8199 if (noninteractive_need_newline
)
8200 putc ('\n', stderr
);
8201 noninteractive_need_newline
= 0;
8203 fwrite (m
, nbytes
, 1, stderr
);
8204 if (cursor_in_echo_area
== 0)
8205 fprintf (stderr
, "\n");
8208 /* A null message buffer means that the frame hasn't really been
8209 initialized yet. Error messages get reported properly by
8210 cmd_error, so this must be just an informative message; toss it. */
8211 else if (INTERACTIVE
8212 && sf
->glyphs_initialized_p
8213 && FRAME_MESSAGE_BUF (sf
))
8215 Lisp_Object mini_window
;
8218 /* Get the frame containing the mini-buffer
8219 that the selected frame is using. */
8220 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8221 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8223 FRAME_SAMPLE_VISIBILITY (f
);
8224 if (FRAME_VISIBLE_P (sf
)
8225 && ! FRAME_VISIBLE_P (f
))
8226 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8230 set_message (m
, Qnil
, nbytes
, multibyte
);
8231 if (minibuffer_auto_raise
)
8232 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8235 clear_message (1, 1);
8237 do_pending_window_change (0);
8238 echo_area_display (1);
8239 do_pending_window_change (0);
8240 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8241 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8246 /* Display an echo area message M with a specified length of NBYTES
8247 bytes. The string may include null characters. If M is not a
8248 string, clear out any existing message, and let the mini-buffer
8251 This function cancels echoing. */
8254 message3 (m
, nbytes
, multibyte
)
8259 struct gcpro gcpro1
;
8262 clear_message (1,1);
8265 /* First flush out any partial line written with print. */
8266 message_log_maybe_newline ();
8272 SAFE_ALLOCA (buffer
, char *, nbytes
);
8273 bcopy (SDATA (m
), buffer
, nbytes
);
8274 message_dolog (buffer
, nbytes
, 1, multibyte
);
8277 message3_nolog (m
, nbytes
, multibyte
);
8283 /* The non-logging version of message3.
8284 This does not cancel echoing, because it is used for echoing.
8285 Perhaps we need to make a separate function for echoing
8286 and make this cancel echoing. */
8289 message3_nolog (m
, nbytes
, multibyte
)
8291 int nbytes
, multibyte
;
8293 struct frame
*sf
= SELECTED_FRAME ();
8294 message_enable_multibyte
= multibyte
;
8296 if (FRAME_INITIAL_P (sf
))
8298 if (noninteractive_need_newline
)
8299 putc ('\n', stderr
);
8300 noninteractive_need_newline
= 0;
8302 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8303 if (cursor_in_echo_area
== 0)
8304 fprintf (stderr
, "\n");
8307 /* A null message buffer means that the frame hasn't really been
8308 initialized yet. Error messages get reported properly by
8309 cmd_error, so this must be just an informative message; toss it. */
8310 else if (INTERACTIVE
8311 && sf
->glyphs_initialized_p
8312 && FRAME_MESSAGE_BUF (sf
))
8314 Lisp_Object mini_window
;
8318 /* Get the frame containing the mini-buffer
8319 that the selected frame is using. */
8320 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8321 frame
= XWINDOW (mini_window
)->frame
;
8324 FRAME_SAMPLE_VISIBILITY (f
);
8325 if (FRAME_VISIBLE_P (sf
)
8326 && !FRAME_VISIBLE_P (f
))
8327 Fmake_frame_visible (frame
);
8329 if (STRINGP (m
) && SCHARS (m
) > 0)
8331 set_message (NULL
, m
, nbytes
, multibyte
);
8332 if (minibuffer_auto_raise
)
8333 Fraise_frame (frame
);
8334 /* Assume we are not echoing.
8335 (If we are, echo_now will override this.) */
8336 echo_message_buffer
= Qnil
;
8339 clear_message (1, 1);
8341 do_pending_window_change (0);
8342 echo_area_display (1);
8343 do_pending_window_change (0);
8344 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8345 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8350 /* Display a null-terminated echo area message M. If M is 0, clear
8351 out any existing message, and let the mini-buffer text show through.
8353 The buffer M must continue to exist until after the echo area gets
8354 cleared or some other message gets displayed there. Do not pass
8355 text that is stored in a Lisp string. Do not pass text in a buffer
8356 that was alloca'd. */
8362 message2 (m
, (m
? strlen (m
) : 0), 0);
8366 /* The non-logging counterpart of message1. */
8372 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8375 /* Display a message M which contains a single %s
8376 which gets replaced with STRING. */
8379 message_with_string (m
, string
, log
)
8384 CHECK_STRING (string
);
8390 if (noninteractive_need_newline
)
8391 putc ('\n', stderr
);
8392 noninteractive_need_newline
= 0;
8393 fprintf (stderr
, m
, SDATA (string
));
8394 if (!cursor_in_echo_area
)
8395 fprintf (stderr
, "\n");
8399 else if (INTERACTIVE
)
8401 /* The frame whose minibuffer we're going to display the message on.
8402 It may be larger than the selected frame, so we need
8403 to use its buffer, not the selected frame's buffer. */
8404 Lisp_Object mini_window
;
8405 struct frame
*f
, *sf
= SELECTED_FRAME ();
8407 /* Get the frame containing the minibuffer
8408 that the selected frame is using. */
8409 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8410 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8412 /* A null message buffer means that the frame hasn't really been
8413 initialized yet. Error messages get reported properly by
8414 cmd_error, so this must be just an informative message; toss it. */
8415 if (FRAME_MESSAGE_BUF (f
))
8417 Lisp_Object args
[2], message
;
8418 struct gcpro gcpro1
, gcpro2
;
8420 args
[0] = build_string (m
);
8421 args
[1] = message
= string
;
8422 GCPRO2 (args
[0], message
);
8425 message
= Fformat (2, args
);
8428 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8430 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8434 /* Print should start at the beginning of the message
8435 buffer next time. */
8436 message_buf_print
= 0;
8442 /* Dump an informative message to the minibuf. If M is 0, clear out
8443 any existing message, and let the mini-buffer text show through. */
8447 message (m
, a1
, a2
, a3
)
8449 EMACS_INT a1
, a2
, a3
;
8455 if (noninteractive_need_newline
)
8456 putc ('\n', stderr
);
8457 noninteractive_need_newline
= 0;
8458 fprintf (stderr
, m
, a1
, a2
, a3
);
8459 if (cursor_in_echo_area
== 0)
8460 fprintf (stderr
, "\n");
8464 else if (INTERACTIVE
)
8466 /* The frame whose mini-buffer we're going to display the message
8467 on. It may be larger than the selected frame, so we need to
8468 use its buffer, not the selected frame's buffer. */
8469 Lisp_Object mini_window
;
8470 struct frame
*f
, *sf
= SELECTED_FRAME ();
8472 /* Get the frame containing the mini-buffer
8473 that the selected frame is using. */
8474 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8475 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8477 /* A null message buffer means that the frame hasn't really been
8478 initialized yet. Error messages get reported properly by
8479 cmd_error, so this must be just an informative message; toss
8481 if (FRAME_MESSAGE_BUF (f
))
8492 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8493 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8495 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8496 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8498 #endif /* NO_ARG_ARRAY */
8500 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8505 /* Print should start at the beginning of the message
8506 buffer next time. */
8507 message_buf_print
= 0;
8513 /* The non-logging version of message. */
8516 message_nolog (m
, a1
, a2
, a3
)
8518 EMACS_INT a1
, a2
, a3
;
8520 Lisp_Object old_log_max
;
8521 old_log_max
= Vmessage_log_max
;
8522 Vmessage_log_max
= Qnil
;
8523 message (m
, a1
, a2
, a3
);
8524 Vmessage_log_max
= old_log_max
;
8528 /* Display the current message in the current mini-buffer. This is
8529 only called from error handlers in process.c, and is not time
8535 if (!NILP (echo_area_buffer
[0]))
8538 string
= Fcurrent_message ();
8539 message3 (string
, SBYTES (string
),
8540 !NILP (current_buffer
->enable_multibyte_characters
));
8545 /* Make sure echo area buffers in `echo_buffers' are live.
8546 If they aren't, make new ones. */
8549 ensure_echo_area_buffers ()
8553 for (i
= 0; i
< 2; ++i
)
8554 if (!BUFFERP (echo_buffer
[i
])
8555 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8558 Lisp_Object old_buffer
;
8561 old_buffer
= echo_buffer
[i
];
8562 sprintf (name
, " *Echo Area %d*", i
);
8563 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8564 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8565 /* to force word wrap in echo area -
8566 it was decided to postpone this*/
8567 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8569 for (j
= 0; j
< 2; ++j
)
8570 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8571 echo_area_buffer
[j
] = echo_buffer
[i
];
8576 /* Call FN with args A1..A4 with either the current or last displayed
8577 echo_area_buffer as current buffer.
8579 WHICH zero means use the current message buffer
8580 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8581 from echo_buffer[] and clear it.
8583 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8584 suitable buffer from echo_buffer[] and clear it.
8586 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8587 that the current message becomes the last displayed one, make
8588 choose a suitable buffer for echo_area_buffer[0], and clear it.
8590 Value is what FN returns. */
8593 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8596 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8602 int this_one
, the_other
, clear_buffer_p
, rc
;
8603 int count
= SPECPDL_INDEX ();
8605 /* If buffers aren't live, make new ones. */
8606 ensure_echo_area_buffers ();
8611 this_one
= 0, the_other
= 1;
8613 this_one
= 1, the_other
= 0;
8616 this_one
= 0, the_other
= 1;
8619 /* We need a fresh one in case the current echo buffer equals
8620 the one containing the last displayed echo area message. */
8621 if (!NILP (echo_area_buffer
[this_one
])
8622 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8623 echo_area_buffer
[this_one
] = Qnil
;
8626 /* Choose a suitable buffer from echo_buffer[] is we don't
8628 if (NILP (echo_area_buffer
[this_one
]))
8630 echo_area_buffer
[this_one
]
8631 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8632 ? echo_buffer
[the_other
]
8633 : echo_buffer
[this_one
]);
8637 buffer
= echo_area_buffer
[this_one
];
8639 /* Don't get confused by reusing the buffer used for echoing
8640 for a different purpose. */
8641 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8644 record_unwind_protect (unwind_with_echo_area_buffer
,
8645 with_echo_area_buffer_unwind_data (w
));
8647 /* Make the echo area buffer current. Note that for display
8648 purposes, it is not necessary that the displayed window's buffer
8649 == current_buffer, except for text property lookup. So, let's
8650 only set that buffer temporarily here without doing a full
8651 Fset_window_buffer. We must also change w->pointm, though,
8652 because otherwise an assertions in unshow_buffer fails, and Emacs
8654 set_buffer_internal_1 (XBUFFER (buffer
));
8658 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8661 current_buffer
->undo_list
= Qt
;
8662 current_buffer
->read_only
= Qnil
;
8663 specbind (Qinhibit_read_only
, Qt
);
8664 specbind (Qinhibit_modification_hooks
, Qt
);
8666 if (clear_buffer_p
&& Z
> BEG
)
8669 xassert (BEGV
>= BEG
);
8670 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8672 rc
= fn (a1
, a2
, a3
, a4
);
8674 xassert (BEGV
>= BEG
);
8675 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8677 unbind_to (count
, Qnil
);
8682 /* Save state that should be preserved around the call to the function
8683 FN called in with_echo_area_buffer. */
8686 with_echo_area_buffer_unwind_data (w
)
8690 Lisp_Object vector
, tmp
;
8692 /* Reduce consing by keeping one vector in
8693 Vwith_echo_area_save_vector. */
8694 vector
= Vwith_echo_area_save_vector
;
8695 Vwith_echo_area_save_vector
= Qnil
;
8698 vector
= Fmake_vector (make_number (7), Qnil
);
8700 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8701 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8702 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8706 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8707 ASET (vector
, i
, w
->buffer
); ++i
;
8708 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8709 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8714 for (; i
< end
; ++i
)
8715 ASET (vector
, i
, Qnil
);
8718 xassert (i
== ASIZE (vector
));
8723 /* Restore global state from VECTOR which was created by
8724 with_echo_area_buffer_unwind_data. */
8727 unwind_with_echo_area_buffer (vector
)
8730 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8731 Vdeactivate_mark
= AREF (vector
, 1);
8732 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8734 if (WINDOWP (AREF (vector
, 3)))
8737 Lisp_Object buffer
, charpos
, bytepos
;
8739 w
= XWINDOW (AREF (vector
, 3));
8740 buffer
= AREF (vector
, 4);
8741 charpos
= AREF (vector
, 5);
8742 bytepos
= AREF (vector
, 6);
8745 set_marker_both (w
->pointm
, buffer
,
8746 XFASTINT (charpos
), XFASTINT (bytepos
));
8749 Vwith_echo_area_save_vector
= vector
;
8754 /* Set up the echo area for use by print functions. MULTIBYTE_P
8755 non-zero means we will print multibyte. */
8758 setup_echo_area_for_printing (multibyte_p
)
8761 /* If we can't find an echo area any more, exit. */
8762 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8765 ensure_echo_area_buffers ();
8767 if (!message_buf_print
)
8769 /* A message has been output since the last time we printed.
8770 Choose a fresh echo area buffer. */
8771 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8772 echo_area_buffer
[0] = echo_buffer
[1];
8774 echo_area_buffer
[0] = echo_buffer
[0];
8776 /* Switch to that buffer and clear it. */
8777 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8778 current_buffer
->truncate_lines
= Qnil
;
8782 int count
= SPECPDL_INDEX ();
8783 specbind (Qinhibit_read_only
, Qt
);
8784 /* Note that undo recording is always disabled. */
8786 unbind_to (count
, Qnil
);
8788 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8790 /* Set up the buffer for the multibyteness we need. */
8792 != !NILP (current_buffer
->enable_multibyte_characters
))
8793 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8795 /* Raise the frame containing the echo area. */
8796 if (minibuffer_auto_raise
)
8798 struct frame
*sf
= SELECTED_FRAME ();
8799 Lisp_Object mini_window
;
8800 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8801 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8804 message_log_maybe_newline ();
8805 message_buf_print
= 1;
8809 if (NILP (echo_area_buffer
[0]))
8811 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8812 echo_area_buffer
[0] = echo_buffer
[1];
8814 echo_area_buffer
[0] = echo_buffer
[0];
8817 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8819 /* Someone switched buffers between print requests. */
8820 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8821 current_buffer
->truncate_lines
= Qnil
;
8827 /* Display an echo area message in window W. Value is non-zero if W's
8828 height is changed. If display_last_displayed_message_p is
8829 non-zero, display the message that was last displayed, otherwise
8830 display the current message. */
8833 display_echo_area (w
)
8836 int i
, no_message_p
, window_height_changed_p
, count
;
8838 /* Temporarily disable garbage collections while displaying the echo
8839 area. This is done because a GC can print a message itself.
8840 That message would modify the echo area buffer's contents while a
8841 redisplay of the buffer is going on, and seriously confuse
8843 count
= inhibit_garbage_collection ();
8845 /* If there is no message, we must call display_echo_area_1
8846 nevertheless because it resizes the window. But we will have to
8847 reset the echo_area_buffer in question to nil at the end because
8848 with_echo_area_buffer will sets it to an empty buffer. */
8849 i
= display_last_displayed_message_p
? 1 : 0;
8850 no_message_p
= NILP (echo_area_buffer
[i
]);
8852 window_height_changed_p
8853 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8854 display_echo_area_1
,
8855 (EMACS_INT
) w
, Qnil
, 0, 0);
8858 echo_area_buffer
[i
] = Qnil
;
8860 unbind_to (count
, Qnil
);
8861 return window_height_changed_p
;
8865 /* Helper for display_echo_area. Display the current buffer which
8866 contains the current echo area message in window W, a mini-window,
8867 a pointer to which is passed in A1. A2..A4 are currently not used.
8868 Change the height of W so that all of the message is displayed.
8869 Value is non-zero if height of W was changed. */
8872 display_echo_area_1 (a1
, a2
, a3
, a4
)
8877 struct window
*w
= (struct window
*) a1
;
8879 struct text_pos start
;
8880 int window_height_changed_p
= 0;
8882 /* Do this before displaying, so that we have a large enough glyph
8883 matrix for the display. If we can't get enough space for the
8884 whole text, display the last N lines. That works by setting w->start. */
8885 window_height_changed_p
= resize_mini_window (w
, 0);
8887 /* Use the starting position chosen by resize_mini_window. */
8888 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8891 clear_glyph_matrix (w
->desired_matrix
);
8892 XSETWINDOW (window
, w
);
8893 try_window (window
, start
, 0);
8895 return window_height_changed_p
;
8899 /* Resize the echo area window to exactly the size needed for the
8900 currently displayed message, if there is one. If a mini-buffer
8901 is active, don't shrink it. */
8904 resize_echo_area_exactly ()
8906 if (BUFFERP (echo_area_buffer
[0])
8907 && WINDOWP (echo_area_window
))
8909 struct window
*w
= XWINDOW (echo_area_window
);
8911 Lisp_Object resize_exactly
;
8913 if (minibuf_level
== 0)
8914 resize_exactly
= Qt
;
8916 resize_exactly
= Qnil
;
8918 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8919 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8922 ++windows_or_buffers_changed
;
8923 ++update_mode_lines
;
8924 redisplay_internal (0);
8930 /* Callback function for with_echo_area_buffer, when used from
8931 resize_echo_area_exactly. A1 contains a pointer to the window to
8932 resize, EXACTLY non-nil means resize the mini-window exactly to the
8933 size of the text displayed. A3 and A4 are not used. Value is what
8934 resize_mini_window returns. */
8937 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8939 Lisp_Object exactly
;
8942 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8946 /* Resize mini-window W to fit the size of its contents. EXACT_P
8947 means size the window exactly to the size needed. Otherwise, it's
8948 only enlarged until W's buffer is empty.
8950 Set W->start to the right place to begin display. If the whole
8951 contents fit, start at the beginning. Otherwise, start so as
8952 to make the end of the contents appear. This is particularly
8953 important for y-or-n-p, but seems desirable generally.
8955 Value is non-zero if the window height has been changed. */
8958 resize_mini_window (w
, exact_p
)
8962 struct frame
*f
= XFRAME (w
->frame
);
8963 int window_height_changed_p
= 0;
8965 xassert (MINI_WINDOW_P (w
));
8967 /* By default, start display at the beginning. */
8968 set_marker_both (w
->start
, w
->buffer
,
8969 BUF_BEGV (XBUFFER (w
->buffer
)),
8970 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8972 /* Don't resize windows while redisplaying a window; it would
8973 confuse redisplay functions when the size of the window they are
8974 displaying changes from under them. Such a resizing can happen,
8975 for instance, when which-func prints a long message while
8976 we are running fontification-functions. We're running these
8977 functions with safe_call which binds inhibit-redisplay to t. */
8978 if (!NILP (Vinhibit_redisplay
))
8981 /* Nil means don't try to resize. */
8982 if (NILP (Vresize_mini_windows
)
8983 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8986 if (!FRAME_MINIBUF_ONLY_P (f
))
8989 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8990 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8991 int height
, max_height
;
8992 int unit
= FRAME_LINE_HEIGHT (f
);
8993 struct text_pos start
;
8994 struct buffer
*old_current_buffer
= NULL
;
8996 if (current_buffer
!= XBUFFER (w
->buffer
))
8998 old_current_buffer
= current_buffer
;
8999 set_buffer_internal (XBUFFER (w
->buffer
));
9002 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9004 /* Compute the max. number of lines specified by the user. */
9005 if (FLOATP (Vmax_mini_window_height
))
9006 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9007 else if (INTEGERP (Vmax_mini_window_height
))
9008 max_height
= XINT (Vmax_mini_window_height
);
9010 max_height
= total_height
/ 4;
9012 /* Correct that max. height if it's bogus. */
9013 max_height
= max (1, max_height
);
9014 max_height
= min (total_height
, max_height
);
9016 /* Find out the height of the text in the window. */
9017 if (it
.line_wrap
== TRUNCATE
)
9022 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9023 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9024 height
= it
.current_y
+ last_height
;
9026 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9027 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9028 height
= (height
+ unit
- 1) / unit
;
9031 /* Compute a suitable window start. */
9032 if (height
> max_height
)
9034 height
= max_height
;
9035 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9036 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9037 start
= it
.current
.pos
;
9040 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9041 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9043 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9045 /* Let it grow only, until we display an empty message, in which
9046 case the window shrinks again. */
9047 if (height
> WINDOW_TOTAL_LINES (w
))
9049 int old_height
= WINDOW_TOTAL_LINES (w
);
9050 freeze_window_starts (f
, 1);
9051 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9052 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9054 else if (height
< WINDOW_TOTAL_LINES (w
)
9055 && (exact_p
|| BEGV
== ZV
))
9057 int old_height
= WINDOW_TOTAL_LINES (w
);
9058 freeze_window_starts (f
, 0);
9059 shrink_mini_window (w
);
9060 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9065 /* Always resize to exact size needed. */
9066 if (height
> WINDOW_TOTAL_LINES (w
))
9068 int old_height
= WINDOW_TOTAL_LINES (w
);
9069 freeze_window_starts (f
, 1);
9070 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9071 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9073 else if (height
< WINDOW_TOTAL_LINES (w
))
9075 int old_height
= WINDOW_TOTAL_LINES (w
);
9076 freeze_window_starts (f
, 0);
9077 shrink_mini_window (w
);
9081 freeze_window_starts (f
, 1);
9082 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9085 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9089 if (old_current_buffer
)
9090 set_buffer_internal (old_current_buffer
);
9093 return window_height_changed_p
;
9097 /* Value is the current message, a string, or nil if there is no
9105 if (!BUFFERP (echo_area_buffer
[0]))
9109 with_echo_area_buffer (0, 0, current_message_1
,
9110 (EMACS_INT
) &msg
, Qnil
, 0, 0);
9112 echo_area_buffer
[0] = Qnil
;
9120 current_message_1 (a1
, a2
, a3
, a4
)
9125 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
9128 *msg
= make_buffer_string (BEG
, Z
, 1);
9135 /* Push the current message on Vmessage_stack for later restauration
9136 by restore_message. Value is non-zero if the current message isn't
9137 empty. This is a relatively infrequent operation, so it's not
9138 worth optimizing. */
9144 msg
= current_message ();
9145 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9146 return STRINGP (msg
);
9150 /* Restore message display from the top of Vmessage_stack. */
9157 xassert (CONSP (Vmessage_stack
));
9158 msg
= XCAR (Vmessage_stack
);
9160 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9162 message3_nolog (msg
, 0, 0);
9166 /* Handler for record_unwind_protect calling pop_message. */
9169 pop_message_unwind (dummy
)
9176 /* Pop the top-most entry off Vmessage_stack. */
9181 xassert (CONSP (Vmessage_stack
));
9182 Vmessage_stack
= XCDR (Vmessage_stack
);
9186 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9187 exits. If the stack is not empty, we have a missing pop_message
9191 check_message_stack ()
9193 if (!NILP (Vmessage_stack
))
9198 /* Truncate to NCHARS what will be displayed in the echo area the next
9199 time we display it---but don't redisplay it now. */
9202 truncate_echo_area (nchars
)
9206 echo_area_buffer
[0] = Qnil
;
9207 /* A null message buffer means that the frame hasn't really been
9208 initialized yet. Error messages get reported properly by
9209 cmd_error, so this must be just an informative message; toss it. */
9210 else if (!noninteractive
9212 && !NILP (echo_area_buffer
[0]))
9214 struct frame
*sf
= SELECTED_FRAME ();
9215 if (FRAME_MESSAGE_BUF (sf
))
9216 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9221 /* Helper function for truncate_echo_area. Truncate the current
9222 message to at most NCHARS characters. */
9225 truncate_message_1 (nchars
, a2
, a3
, a4
)
9230 if (BEG
+ nchars
< Z
)
9231 del_range (BEG
+ nchars
, Z
);
9233 echo_area_buffer
[0] = Qnil
;
9238 /* Set the current message to a substring of S or STRING.
9240 If STRING is a Lisp string, set the message to the first NBYTES
9241 bytes from STRING. NBYTES zero means use the whole string. If
9242 STRING is multibyte, the message will be displayed multibyte.
9244 If S is not null, set the message to the first LEN bytes of S. LEN
9245 zero means use the whole string. MULTIBYTE_P non-zero means S is
9246 multibyte. Display the message multibyte in that case.
9248 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9249 to t before calling set_message_1 (which calls insert).
9253 set_message (s
, string
, nbytes
, multibyte_p
)
9256 int nbytes
, multibyte_p
;
9258 message_enable_multibyte
9259 = ((s
&& multibyte_p
)
9260 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9262 with_echo_area_buffer (0, -1, set_message_1
,
9263 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9264 message_buf_print
= 0;
9265 help_echo_showing_p
= 0;
9269 /* Helper function for set_message. Arguments have the same meaning
9270 as there, with A1 corresponding to S and A2 corresponding to STRING
9271 This function is called with the echo area buffer being
9275 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9278 EMACS_INT nbytes
, multibyte_p
;
9280 const char *s
= (const char *) a1
;
9281 Lisp_Object string
= a2
;
9283 /* Change multibyteness of the echo buffer appropriately. */
9284 if (message_enable_multibyte
9285 != !NILP (current_buffer
->enable_multibyte_characters
))
9286 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9288 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9290 /* Insert new message at BEG. */
9291 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9293 if (STRINGP (string
))
9298 nbytes
= SBYTES (string
);
9299 nchars
= string_byte_to_char (string
, nbytes
);
9301 /* This function takes care of single/multibyte conversion. We
9302 just have to ensure that the echo area buffer has the right
9303 setting of enable_multibyte_characters. */
9304 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9309 nbytes
= strlen (s
);
9311 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9313 /* Convert from multi-byte to single-byte. */
9315 unsigned char work
[1];
9317 /* Convert a multibyte string to single-byte. */
9318 for (i
= 0; i
< nbytes
; i
+= n
)
9320 c
= string_char_and_length (s
+ i
, &n
);
9321 work
[0] = (ASCII_CHAR_P (c
)
9323 : multibyte_char_to_unibyte (c
, Qnil
));
9324 insert_1_both (work
, 1, 1, 1, 0, 0);
9327 else if (!multibyte_p
9328 && !NILP (current_buffer
->enable_multibyte_characters
))
9330 /* Convert from single-byte to multi-byte. */
9332 const unsigned char *msg
= (const unsigned char *) s
;
9333 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9335 /* Convert a single-byte string to multibyte. */
9336 for (i
= 0; i
< nbytes
; i
++)
9339 MAKE_CHAR_MULTIBYTE (c
);
9340 n
= CHAR_STRING (c
, str
);
9341 insert_1_both (str
, 1, n
, 1, 0, 0);
9345 insert_1 (s
, nbytes
, 1, 0, 0);
9352 /* Clear messages. CURRENT_P non-zero means clear the current
9353 message. LAST_DISPLAYED_P non-zero means clear the message
9357 clear_message (current_p
, last_displayed_p
)
9358 int current_p
, last_displayed_p
;
9362 echo_area_buffer
[0] = Qnil
;
9363 message_cleared_p
= 1;
9366 if (last_displayed_p
)
9367 echo_area_buffer
[1] = Qnil
;
9369 message_buf_print
= 0;
9372 /* Clear garbaged frames.
9374 This function is used where the old redisplay called
9375 redraw_garbaged_frames which in turn called redraw_frame which in
9376 turn called clear_frame. The call to clear_frame was a source of
9377 flickering. I believe a clear_frame is not necessary. It should
9378 suffice in the new redisplay to invalidate all current matrices,
9379 and ensure a complete redisplay of all windows. */
9382 clear_garbaged_frames ()
9386 Lisp_Object tail
, frame
;
9387 int changed_count
= 0;
9389 FOR_EACH_FRAME (tail
, frame
)
9391 struct frame
*f
= XFRAME (frame
);
9393 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9397 Fredraw_frame (frame
);
9398 f
->force_flush_display_p
= 1;
9400 clear_current_matrices (f
);
9409 ++windows_or_buffers_changed
;
9414 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9415 is non-zero update selected_frame. Value is non-zero if the
9416 mini-windows height has been changed. */
9419 echo_area_display (update_frame_p
)
9422 Lisp_Object mini_window
;
9425 int window_height_changed_p
= 0;
9426 struct frame
*sf
= SELECTED_FRAME ();
9428 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9429 w
= XWINDOW (mini_window
);
9430 f
= XFRAME (WINDOW_FRAME (w
));
9432 /* Don't display if frame is invisible or not yet initialized. */
9433 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9436 #ifdef HAVE_WINDOW_SYSTEM
9437 /* When Emacs starts, selected_frame may be the initial terminal
9438 frame. If we let this through, a message would be displayed on
9440 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9442 #endif /* HAVE_WINDOW_SYSTEM */
9444 /* Redraw garbaged frames. */
9446 clear_garbaged_frames ();
9448 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9450 echo_area_window
= mini_window
;
9451 window_height_changed_p
= display_echo_area (w
);
9452 w
->must_be_updated_p
= 1;
9454 /* Update the display, unless called from redisplay_internal.
9455 Also don't update the screen during redisplay itself. The
9456 update will happen at the end of redisplay, and an update
9457 here could cause confusion. */
9458 if (update_frame_p
&& !redisplaying_p
)
9462 /* If the display update has been interrupted by pending
9463 input, update mode lines in the frame. Due to the
9464 pending input, it might have been that redisplay hasn't
9465 been called, so that mode lines above the echo area are
9466 garbaged. This looks odd, so we prevent it here. */
9467 if (!display_completed
)
9468 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9470 if (window_height_changed_p
9471 /* Don't do this if Emacs is shutting down. Redisplay
9472 needs to run hooks. */
9473 && !NILP (Vrun_hooks
))
9475 /* Must update other windows. Likewise as in other
9476 cases, don't let this update be interrupted by
9478 int count
= SPECPDL_INDEX ();
9479 specbind (Qredisplay_dont_pause
, Qt
);
9480 windows_or_buffers_changed
= 1;
9481 redisplay_internal (0);
9482 unbind_to (count
, Qnil
);
9484 else if (FRAME_WINDOW_P (f
) && n
== 0)
9486 /* Window configuration is the same as before.
9487 Can do with a display update of the echo area,
9488 unless we displayed some mode lines. */
9489 update_single_window (w
, 1);
9490 FRAME_RIF (f
)->flush_display (f
);
9493 update_frame (f
, 1, 1);
9495 /* If cursor is in the echo area, make sure that the next
9496 redisplay displays the minibuffer, so that the cursor will
9497 be replaced with what the minibuffer wants. */
9498 if (cursor_in_echo_area
)
9499 ++windows_or_buffers_changed
;
9502 else if (!EQ (mini_window
, selected_window
))
9503 windows_or_buffers_changed
++;
9505 /* Last displayed message is now the current message. */
9506 echo_area_buffer
[1] = echo_area_buffer
[0];
9507 /* Inform read_char that we're not echoing. */
9508 echo_message_buffer
= Qnil
;
9510 /* Prevent redisplay optimization in redisplay_internal by resetting
9511 this_line_start_pos. This is done because the mini-buffer now
9512 displays the message instead of its buffer text. */
9513 if (EQ (mini_window
, selected_window
))
9514 CHARPOS (this_line_start_pos
) = 0;
9516 return window_height_changed_p
;
9521 /***********************************************************************
9522 Mode Lines and Frame Titles
9523 ***********************************************************************/
9525 /* A buffer for constructing non-propertized mode-line strings and
9526 frame titles in it; allocated from the heap in init_xdisp and
9527 resized as needed in store_mode_line_noprop_char. */
9529 static char *mode_line_noprop_buf
;
9531 /* The buffer's end, and a current output position in it. */
9533 static char *mode_line_noprop_buf_end
;
9534 static char *mode_line_noprop_ptr
;
9536 #define MODE_LINE_NOPROP_LEN(start) \
9537 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9540 MODE_LINE_DISPLAY
= 0,
9546 /* Alist that caches the results of :propertize.
9547 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9548 static Lisp_Object mode_line_proptrans_alist
;
9550 /* List of strings making up the mode-line. */
9551 static Lisp_Object mode_line_string_list
;
9553 /* Base face property when building propertized mode line string. */
9554 static Lisp_Object mode_line_string_face
;
9555 static Lisp_Object mode_line_string_face_prop
;
9558 /* Unwind data for mode line strings */
9560 static Lisp_Object Vmode_line_unwind_vector
;
9563 format_mode_line_unwind_data (struct buffer
*obuf
,
9567 Lisp_Object vector
, tmp
;
9569 /* Reduce consing by keeping one vector in
9570 Vwith_echo_area_save_vector. */
9571 vector
= Vmode_line_unwind_vector
;
9572 Vmode_line_unwind_vector
= Qnil
;
9575 vector
= Fmake_vector (make_number (8), Qnil
);
9577 ASET (vector
, 0, make_number (mode_line_target
));
9578 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9579 ASET (vector
, 2, mode_line_string_list
);
9580 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9581 ASET (vector
, 4, mode_line_string_face
);
9582 ASET (vector
, 5, mode_line_string_face_prop
);
9585 XSETBUFFER (tmp
, obuf
);
9588 ASET (vector
, 6, tmp
);
9589 ASET (vector
, 7, owin
);
9595 unwind_format_mode_line (vector
)
9598 mode_line_target
= XINT (AREF (vector
, 0));
9599 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9600 mode_line_string_list
= AREF (vector
, 2);
9601 if (! EQ (AREF (vector
, 3), Qt
))
9602 mode_line_proptrans_alist
= AREF (vector
, 3);
9603 mode_line_string_face
= AREF (vector
, 4);
9604 mode_line_string_face_prop
= AREF (vector
, 5);
9606 if (!NILP (AREF (vector
, 7)))
9607 /* Select window before buffer, since it may change the buffer. */
9608 Fselect_window (AREF (vector
, 7), Qt
);
9610 if (!NILP (AREF (vector
, 6)))
9612 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9613 ASET (vector
, 6, Qnil
);
9616 Vmode_line_unwind_vector
= vector
;
9621 /* Store a single character C for the frame title in mode_line_noprop_buf.
9622 Re-allocate mode_line_noprop_buf if necessary. */
9626 store_mode_line_noprop_char (char c
)
9628 store_mode_line_noprop_char (c
)
9632 /* If output position has reached the end of the allocated buffer,
9633 double the buffer's size. */
9634 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9636 int len
= MODE_LINE_NOPROP_LEN (0);
9637 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9638 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9639 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9640 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9643 *mode_line_noprop_ptr
++ = c
;
9647 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9648 mode_line_noprop_ptr. STR is the string to store. Do not copy
9649 characters that yield more columns than PRECISION; PRECISION <= 0
9650 means copy the whole string. Pad with spaces until FIELD_WIDTH
9651 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9652 pad. Called from display_mode_element when it is used to build a
9656 store_mode_line_noprop (str
, field_width
, precision
)
9657 const unsigned char *str
;
9658 int field_width
, precision
;
9663 /* Copy at most PRECISION chars from STR. */
9664 nbytes
= strlen (str
);
9665 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9667 store_mode_line_noprop_char (*str
++);
9669 /* Fill up with spaces until FIELD_WIDTH reached. */
9670 while (field_width
> 0
9673 store_mode_line_noprop_char (' ');
9680 /***********************************************************************
9682 ***********************************************************************/
9684 #ifdef HAVE_WINDOW_SYSTEM
9686 /* Set the title of FRAME, if it has changed. The title format is
9687 Vicon_title_format if FRAME is iconified, otherwise it is
9688 frame_title_format. */
9691 x_consider_frame_title (frame
)
9694 struct frame
*f
= XFRAME (frame
);
9696 if (FRAME_WINDOW_P (f
)
9697 || FRAME_MINIBUF_ONLY_P (f
)
9698 || f
->explicit_name
)
9700 /* Do we have more than one visible frame on this X display? */
9707 int count
= SPECPDL_INDEX ();
9709 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9711 Lisp_Object other_frame
= XCAR (tail
);
9712 struct frame
*tf
= XFRAME (other_frame
);
9715 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9716 && !FRAME_MINIBUF_ONLY_P (tf
)
9717 && !EQ (other_frame
, tip_frame
)
9718 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9722 /* Set global variable indicating that multiple frames exist. */
9723 multiple_frames
= CONSP (tail
);
9725 /* Switch to the buffer of selected window of the frame. Set up
9726 mode_line_target so that display_mode_element will output into
9727 mode_line_noprop_buf; then display the title. */
9728 record_unwind_protect (unwind_format_mode_line
,
9729 format_mode_line_unwind_data
9730 (current_buffer
, selected_window
, 0));
9732 Fselect_window (f
->selected_window
, Qt
);
9733 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9734 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9736 mode_line_target
= MODE_LINE_TITLE
;
9737 title_start
= MODE_LINE_NOPROP_LEN (0);
9738 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9739 NULL
, DEFAULT_FACE_ID
);
9740 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9741 len
= MODE_LINE_NOPROP_LEN (title_start
);
9742 title
= mode_line_noprop_buf
+ title_start
;
9743 unbind_to (count
, Qnil
);
9745 /* Set the title only if it's changed. This avoids consing in
9746 the common case where it hasn't. (If it turns out that we've
9747 already wasted too much time by walking through the list with
9748 display_mode_element, then we might need to optimize at a
9749 higher level than this.) */
9750 if (! STRINGP (f
->name
)
9751 || SBYTES (f
->name
) != len
9752 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9757 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9760 ns_set_name_as_filename (f
);
9762 x_implicitly_set_name (f
, make_string(title
, len
),
9768 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9773 /* do this also for frames with explicit names */
9774 ns_implicitly_set_icon_type(f
);
9775 ns_set_doc_edited(f
, Fbuffer_modified_p
9776 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9782 #endif /* not HAVE_WINDOW_SYSTEM */
9787 /***********************************************************************
9789 ***********************************************************************/
9792 /* Prepare for redisplay by updating menu-bar item lists when
9793 appropriate. This can call eval. */
9796 prepare_menu_bars ()
9799 struct gcpro gcpro1
, gcpro2
;
9801 Lisp_Object tooltip_frame
;
9803 #ifdef HAVE_WINDOW_SYSTEM
9804 tooltip_frame
= tip_frame
;
9806 tooltip_frame
= Qnil
;
9809 /* Update all frame titles based on their buffer names, etc. We do
9810 this before the menu bars so that the buffer-menu will show the
9811 up-to-date frame titles. */
9812 #ifdef HAVE_WINDOW_SYSTEM
9813 if (windows_or_buffers_changed
|| update_mode_lines
)
9815 Lisp_Object tail
, frame
;
9817 FOR_EACH_FRAME (tail
, frame
)
9820 if (!EQ (frame
, tooltip_frame
)
9821 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9822 x_consider_frame_title (frame
);
9825 #endif /* HAVE_WINDOW_SYSTEM */
9827 /* Update the menu bar item lists, if appropriate. This has to be
9828 done before any actual redisplay or generation of display lines. */
9829 all_windows
= (update_mode_lines
9830 || buffer_shared
> 1
9831 || windows_or_buffers_changed
);
9834 Lisp_Object tail
, frame
;
9835 int count
= SPECPDL_INDEX ();
9836 /* 1 means that update_menu_bar has run its hooks
9837 so any further calls to update_menu_bar shouldn't do so again. */
9838 int menu_bar_hooks_run
= 0;
9840 record_unwind_save_match_data ();
9842 FOR_EACH_FRAME (tail
, frame
)
9846 /* Ignore tooltip frame. */
9847 if (EQ (frame
, tooltip_frame
))
9850 /* If a window on this frame changed size, report that to
9851 the user and clear the size-change flag. */
9852 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9854 Lisp_Object functions
;
9856 /* Clear flag first in case we get an error below. */
9857 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9858 functions
= Vwindow_size_change_functions
;
9859 GCPRO2 (tail
, functions
);
9861 while (CONSP (functions
))
9863 if (!EQ (XCAR (functions
), Qt
))
9864 call1 (XCAR (functions
), frame
);
9865 functions
= XCDR (functions
);
9871 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9872 #ifdef HAVE_WINDOW_SYSTEM
9873 update_tool_bar (f
, 0);
9878 unbind_to (count
, Qnil
);
9882 struct frame
*sf
= SELECTED_FRAME ();
9883 update_menu_bar (sf
, 1, 0);
9884 #ifdef HAVE_WINDOW_SYSTEM
9885 update_tool_bar (sf
, 1);
9889 /* Motif needs this. See comment in xmenu.c. Turn it off when
9890 pending_menu_activation is not defined. */
9891 #ifdef USE_X_TOOLKIT
9892 pending_menu_activation
= 0;
9897 /* Update the menu bar item list for frame F. This has to be done
9898 before we start to fill in any display lines, because it can call
9901 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9903 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9904 already ran the menu bar hooks for this redisplay, so there
9905 is no need to run them again. The return value is the
9906 updated value of this flag, to pass to the next call. */
9909 update_menu_bar (f
, save_match_data
, hooks_run
)
9911 int save_match_data
;
9915 register struct window
*w
;
9917 /* If called recursively during a menu update, do nothing. This can
9918 happen when, for instance, an activate-menubar-hook causes a
9920 if (inhibit_menubar_update
)
9923 window
= FRAME_SELECTED_WINDOW (f
);
9924 w
= XWINDOW (window
);
9926 if (FRAME_WINDOW_P (f
)
9928 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9929 || defined (HAVE_NS) || defined (USE_GTK)
9930 FRAME_EXTERNAL_MENU_BAR (f
)
9932 FRAME_MENU_BAR_LINES (f
) > 0
9934 : FRAME_MENU_BAR_LINES (f
) > 0)
9936 /* If the user has switched buffers or windows, we need to
9937 recompute to reflect the new bindings. But we'll
9938 recompute when update_mode_lines is set too; that means
9939 that people can use force-mode-line-update to request
9940 that the menu bar be recomputed. The adverse effect on
9941 the rest of the redisplay algorithm is about the same as
9942 windows_or_buffers_changed anyway. */
9943 if (windows_or_buffers_changed
9944 /* This used to test w->update_mode_line, but we believe
9945 there is no need to recompute the menu in that case. */
9946 || update_mode_lines
9947 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9948 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9949 != !NILP (w
->last_had_star
))
9950 || ((!NILP (Vtransient_mark_mode
)
9951 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9952 != !NILP (w
->region_showing
)))
9954 struct buffer
*prev
= current_buffer
;
9955 int count
= SPECPDL_INDEX ();
9957 specbind (Qinhibit_menubar_update
, Qt
);
9959 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9960 if (save_match_data
)
9961 record_unwind_save_match_data ();
9962 if (NILP (Voverriding_local_map_menu_flag
))
9964 specbind (Qoverriding_terminal_local_map
, Qnil
);
9965 specbind (Qoverriding_local_map
, Qnil
);
9970 /* Run the Lucid hook. */
9971 safe_run_hooks (Qactivate_menubar_hook
);
9973 /* If it has changed current-menubar from previous value,
9974 really recompute the menu-bar from the value. */
9975 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9976 call0 (Qrecompute_lucid_menubar
);
9978 safe_run_hooks (Qmenu_bar_update_hook
);
9983 XSETFRAME (Vmenu_updating_frame
, f
);
9984 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9986 /* Redisplay the menu bar in case we changed it. */
9987 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9988 || defined (HAVE_NS) || defined (USE_GTK)
9989 if (FRAME_WINDOW_P (f
))
9991 #if defined (HAVE_NS)
9992 /* All frames on Mac OS share the same menubar. So only
9993 the selected frame should be allowed to set it. */
9994 if (f
== SELECTED_FRAME ())
9996 set_frame_menubar (f
, 0, 0);
9999 /* On a terminal screen, the menu bar is an ordinary screen
10000 line, and this makes it get updated. */
10001 w
->update_mode_line
= Qt
;
10002 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10003 /* In the non-toolkit version, the menu bar is an ordinary screen
10004 line, and this makes it get updated. */
10005 w
->update_mode_line
= Qt
;
10006 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10008 unbind_to (count
, Qnil
);
10009 set_buffer_internal_1 (prev
);
10018 /***********************************************************************
10020 ***********************************************************************/
10022 #ifdef HAVE_WINDOW_SYSTEM
10025 Nominal cursor position -- where to draw output.
10026 HPOS and VPOS are window relative glyph matrix coordinates.
10027 X and Y are window relative pixel coordinates. */
10029 struct cursor_pos output_cursor
;
10033 Set the global variable output_cursor to CURSOR. All cursor
10034 positions are relative to updated_window. */
10037 set_output_cursor (cursor
)
10038 struct cursor_pos
*cursor
;
10040 output_cursor
.hpos
= cursor
->hpos
;
10041 output_cursor
.vpos
= cursor
->vpos
;
10042 output_cursor
.x
= cursor
->x
;
10043 output_cursor
.y
= cursor
->y
;
10048 Set a nominal cursor position.
10050 HPOS and VPOS are column/row positions in a window glyph matrix. X
10051 and Y are window text area relative pixel positions.
10053 If this is done during an update, updated_window will contain the
10054 window that is being updated and the position is the future output
10055 cursor position for that window. If updated_window is null, use
10056 selected_window and display the cursor at the given position. */
10059 x_cursor_to (vpos
, hpos
, y
, x
)
10060 int vpos
, hpos
, y
, x
;
10064 /* If updated_window is not set, work on selected_window. */
10065 if (updated_window
)
10066 w
= updated_window
;
10068 w
= XWINDOW (selected_window
);
10070 /* Set the output cursor. */
10071 output_cursor
.hpos
= hpos
;
10072 output_cursor
.vpos
= vpos
;
10073 output_cursor
.x
= x
;
10074 output_cursor
.y
= y
;
10076 /* If not called as part of an update, really display the cursor.
10077 This will also set the cursor position of W. */
10078 if (updated_window
== NULL
)
10081 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10082 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10083 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10088 #endif /* HAVE_WINDOW_SYSTEM */
10091 /***********************************************************************
10093 ***********************************************************************/
10095 #ifdef HAVE_WINDOW_SYSTEM
10097 /* Where the mouse was last time we reported a mouse event. */
10099 FRAME_PTR last_mouse_frame
;
10101 /* Tool-bar item index of the item on which a mouse button was pressed
10104 int last_tool_bar_item
;
10108 update_tool_bar_unwind (frame
)
10111 selected_frame
= frame
;
10115 /* Update the tool-bar item list for frame F. This has to be done
10116 before we start to fill in any display lines. Called from
10117 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10118 and restore it here. */
10121 update_tool_bar (f
, save_match_data
)
10123 int save_match_data
;
10125 #if defined (USE_GTK) || defined (HAVE_NS)
10126 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10128 int do_update
= WINDOWP (f
->tool_bar_window
)
10129 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10134 Lisp_Object window
;
10137 window
= FRAME_SELECTED_WINDOW (f
);
10138 w
= XWINDOW (window
);
10140 /* If the user has switched buffers or windows, we need to
10141 recompute to reflect the new bindings. But we'll
10142 recompute when update_mode_lines is set too; that means
10143 that people can use force-mode-line-update to request
10144 that the menu bar be recomputed. The adverse effect on
10145 the rest of the redisplay algorithm is about the same as
10146 windows_or_buffers_changed anyway. */
10147 if (windows_or_buffers_changed
10148 || !NILP (w
->update_mode_line
)
10149 || update_mode_lines
10150 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10151 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10152 != !NILP (w
->last_had_star
))
10153 || ((!NILP (Vtransient_mark_mode
)
10154 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10155 != !NILP (w
->region_showing
)))
10157 struct buffer
*prev
= current_buffer
;
10158 int count
= SPECPDL_INDEX ();
10159 Lisp_Object frame
, new_tool_bar
;
10160 int new_n_tool_bar
;
10161 struct gcpro gcpro1
;
10163 /* Set current_buffer to the buffer of the selected
10164 window of the frame, so that we get the right local
10166 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10168 /* Save match data, if we must. */
10169 if (save_match_data
)
10170 record_unwind_save_match_data ();
10172 /* Make sure that we don't accidentally use bogus keymaps. */
10173 if (NILP (Voverriding_local_map_menu_flag
))
10175 specbind (Qoverriding_terminal_local_map
, Qnil
);
10176 specbind (Qoverriding_local_map
, Qnil
);
10179 GCPRO1 (new_tool_bar
);
10181 /* We must temporarily set the selected frame to this frame
10182 before calling tool_bar_items, because the calculation of
10183 the tool-bar keymap uses the selected frame (see
10184 `tool-bar-make-keymap' in tool-bar.el). */
10185 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10186 XSETFRAME (frame
, f
);
10187 selected_frame
= frame
;
10189 /* Build desired tool-bar items from keymaps. */
10190 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10193 /* Redisplay the tool-bar if we changed it. */
10194 if (new_n_tool_bar
!= f
->n_tool_bar_items
10195 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10197 /* Redisplay that happens asynchronously due to an expose event
10198 may access f->tool_bar_items. Make sure we update both
10199 variables within BLOCK_INPUT so no such event interrupts. */
10201 f
->tool_bar_items
= new_tool_bar
;
10202 f
->n_tool_bar_items
= new_n_tool_bar
;
10203 w
->update_mode_line
= Qt
;
10209 unbind_to (count
, Qnil
);
10210 set_buffer_internal_1 (prev
);
10216 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10217 F's desired tool-bar contents. F->tool_bar_items must have
10218 been set up previously by calling prepare_menu_bars. */
10221 build_desired_tool_bar_string (f
)
10224 int i
, size
, size_needed
;
10225 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10226 Lisp_Object image
, plist
, props
;
10228 image
= plist
= props
= Qnil
;
10229 GCPRO3 (image
, plist
, props
);
10231 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10232 Otherwise, make a new string. */
10234 /* The size of the string we might be able to reuse. */
10235 size
= (STRINGP (f
->desired_tool_bar_string
)
10236 ? SCHARS (f
->desired_tool_bar_string
)
10239 /* We need one space in the string for each image. */
10240 size_needed
= f
->n_tool_bar_items
;
10242 /* Reuse f->desired_tool_bar_string, if possible. */
10243 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10244 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10245 make_number (' '));
10248 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10249 Fremove_text_properties (make_number (0), make_number (size
),
10250 props
, f
->desired_tool_bar_string
);
10253 /* Put a `display' property on the string for the images to display,
10254 put a `menu_item' property on tool-bar items with a value that
10255 is the index of the item in F's tool-bar item vector. */
10256 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10258 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10260 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10261 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10262 int hmargin
, vmargin
, relief
, idx
, end
;
10263 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
10265 /* If image is a vector, choose the image according to the
10267 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10268 if (VECTORP (image
))
10272 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10273 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10276 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10277 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10279 xassert (ASIZE (image
) >= idx
);
10280 image
= AREF (image
, idx
);
10285 /* Ignore invalid image specifications. */
10286 if (!valid_image_p (image
))
10289 /* Display the tool-bar button pressed, or depressed. */
10290 plist
= Fcopy_sequence (XCDR (image
));
10292 /* Compute margin and relief to draw. */
10293 relief
= (tool_bar_button_relief
>= 0
10294 ? tool_bar_button_relief
10295 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10296 hmargin
= vmargin
= relief
;
10298 if (INTEGERP (Vtool_bar_button_margin
)
10299 && XINT (Vtool_bar_button_margin
) > 0)
10301 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10302 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10304 else if (CONSP (Vtool_bar_button_margin
))
10306 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10307 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10308 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10310 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10311 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10312 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10315 if (auto_raise_tool_bar_buttons_p
)
10317 /* Add a `:relief' property to the image spec if the item is
10321 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10328 /* If image is selected, display it pressed, i.e. with a
10329 negative relief. If it's not selected, display it with a
10331 plist
= Fplist_put (plist
, QCrelief
,
10333 ? make_number (-relief
)
10334 : make_number (relief
)));
10339 /* Put a margin around the image. */
10340 if (hmargin
|| vmargin
)
10342 if (hmargin
== vmargin
)
10343 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10345 plist
= Fplist_put (plist
, QCmargin
,
10346 Fcons (make_number (hmargin
),
10347 make_number (vmargin
)));
10350 /* If button is not enabled, and we don't have special images
10351 for the disabled state, make the image appear disabled by
10352 applying an appropriate algorithm to it. */
10353 if (!enabled_p
&& idx
< 0)
10354 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10356 /* Put a `display' text property on the string for the image to
10357 display. Put a `menu-item' property on the string that gives
10358 the start of this item's properties in the tool-bar items
10360 image
= Fcons (Qimage
, plist
);
10361 props
= list4 (Qdisplay
, image
,
10362 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10364 /* Let the last image hide all remaining spaces in the tool bar
10365 string. The string can be longer than needed when we reuse a
10366 previous string. */
10367 if (i
+ 1 == f
->n_tool_bar_items
)
10368 end
= SCHARS (f
->desired_tool_bar_string
);
10371 Fadd_text_properties (make_number (i
), make_number (end
),
10372 props
, f
->desired_tool_bar_string
);
10380 /* Display one line of the tool-bar of frame IT->f.
10382 HEIGHT specifies the desired height of the tool-bar line.
10383 If the actual height of the glyph row is less than HEIGHT, the
10384 row's height is increased to HEIGHT, and the icons are centered
10385 vertically in the new height.
10387 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10388 count a final empty row in case the tool-bar width exactly matches
10393 display_tool_bar_line (it
, height
)
10397 struct glyph_row
*row
= it
->glyph_row
;
10398 int max_x
= it
->last_visible_x
;
10399 struct glyph
*last
;
10401 prepare_desired_row (row
);
10402 row
->y
= it
->current_y
;
10404 /* Note that this isn't made use of if the face hasn't a box,
10405 so there's no need to check the face here. */
10406 it
->start_of_box_run_p
= 1;
10408 while (it
->current_x
< max_x
)
10410 int x
, n_glyphs_before
, i
, nglyphs
;
10411 struct it it_before
;
10413 /* Get the next display element. */
10414 if (!get_next_display_element (it
))
10416 /* Don't count empty row if we are counting needed tool-bar lines. */
10417 if (height
< 0 && !it
->hpos
)
10422 /* Produce glyphs. */
10423 n_glyphs_before
= row
->used
[TEXT_AREA
];
10426 PRODUCE_GLYPHS (it
);
10428 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10430 x
= it_before
.current_x
;
10431 while (i
< nglyphs
)
10433 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10435 if (x
+ glyph
->pixel_width
> max_x
)
10437 /* Glyph doesn't fit on line. Backtrack. */
10438 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10440 /* If this is the only glyph on this line, it will never fit on the
10441 toolbar, so skip it. But ensure there is at least one glyph,
10442 so we don't accidentally disable the tool-bar. */
10443 if (n_glyphs_before
== 0
10444 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10450 x
+= glyph
->pixel_width
;
10454 /* Stop at line ends. */
10455 if (ITERATOR_AT_END_OF_LINE_P (it
))
10458 set_iterator_to_next (it
, 1);
10463 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10465 /* Use default face for the border below the tool bar.
10467 FIXME: When auto-resize-tool-bars is grow-only, there is
10468 no additional border below the possibly empty tool-bar lines.
10469 So to make the extra empty lines look "normal", we have to
10470 use the tool-bar face for the border too. */
10471 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10472 it
->face_id
= DEFAULT_FACE_ID
;
10474 extend_face_to_end_of_line (it
);
10475 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10476 last
->right_box_line_p
= 1;
10477 if (last
== row
->glyphs
[TEXT_AREA
])
10478 last
->left_box_line_p
= 1;
10480 /* Make line the desired height and center it vertically. */
10481 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10483 /* Don't add more than one line height. */
10484 height
%= FRAME_LINE_HEIGHT (it
->f
);
10485 it
->max_ascent
+= height
/ 2;
10486 it
->max_descent
+= (height
+ 1) / 2;
10489 compute_line_metrics (it
);
10491 /* If line is empty, make it occupy the rest of the tool-bar. */
10492 if (!row
->displays_text_p
)
10494 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10495 row
->visible_height
= row
->height
;
10496 row
->ascent
= row
->phys_ascent
= 0;
10497 row
->extra_line_spacing
= 0;
10500 row
->full_width_p
= 1;
10501 row
->continued_p
= 0;
10502 row
->truncated_on_left_p
= 0;
10503 row
->truncated_on_right_p
= 0;
10505 it
->current_x
= it
->hpos
= 0;
10506 it
->current_y
+= row
->height
;
10512 /* Max tool-bar height. */
10514 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10515 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10517 /* Value is the number of screen lines needed to make all tool-bar
10518 items of frame F visible. The number of actual rows needed is
10519 returned in *N_ROWS if non-NULL. */
10522 tool_bar_lines_needed (f
, n_rows
)
10526 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10528 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10529 the desired matrix, so use (unused) mode-line row as temporary row to
10530 avoid destroying the first tool-bar row. */
10531 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10533 /* Initialize an iterator for iteration over
10534 F->desired_tool_bar_string in the tool-bar window of frame F. */
10535 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10536 it
.first_visible_x
= 0;
10537 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10538 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10540 while (!ITERATOR_AT_END_P (&it
))
10542 clear_glyph_row (temp_row
);
10543 it
.glyph_row
= temp_row
;
10544 display_tool_bar_line (&it
, -1);
10546 clear_glyph_row (temp_row
);
10548 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10550 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10552 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10556 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10558 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10567 frame
= selected_frame
;
10569 CHECK_FRAME (frame
);
10570 f
= XFRAME (frame
);
10572 if (WINDOWP (f
->tool_bar_window
)
10573 || (w
= XWINDOW (f
->tool_bar_window
),
10574 WINDOW_TOTAL_LINES (w
) > 0))
10576 update_tool_bar (f
, 1);
10577 if (f
->n_tool_bar_items
)
10579 build_desired_tool_bar_string (f
);
10580 nlines
= tool_bar_lines_needed (f
, NULL
);
10584 return make_number (nlines
);
10588 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10589 height should be changed. */
10592 redisplay_tool_bar (f
)
10597 struct glyph_row
*row
;
10599 #if defined (USE_GTK) || defined (HAVE_NS)
10600 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10601 update_frame_tool_bar (f
);
10605 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10606 do anything. This means you must start with tool-bar-lines
10607 non-zero to get the auto-sizing effect. Or in other words, you
10608 can turn off tool-bars by specifying tool-bar-lines zero. */
10609 if (!WINDOWP (f
->tool_bar_window
)
10610 || (w
= XWINDOW (f
->tool_bar_window
),
10611 WINDOW_TOTAL_LINES (w
) == 0))
10614 /* Set up an iterator for the tool-bar window. */
10615 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10616 it
.first_visible_x
= 0;
10617 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10618 row
= it
.glyph_row
;
10620 /* Build a string that represents the contents of the tool-bar. */
10621 build_desired_tool_bar_string (f
);
10622 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10624 if (f
->n_tool_bar_rows
== 0)
10628 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10629 nlines
!= WINDOW_TOTAL_LINES (w
)))
10631 extern Lisp_Object Qtool_bar_lines
;
10633 int old_height
= WINDOW_TOTAL_LINES (w
);
10635 XSETFRAME (frame
, f
);
10636 Fmodify_frame_parameters (frame
,
10637 Fcons (Fcons (Qtool_bar_lines
,
10638 make_number (nlines
)),
10640 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10642 clear_glyph_matrix (w
->desired_matrix
);
10643 fonts_changed_p
= 1;
10649 /* Display as many lines as needed to display all tool-bar items. */
10651 if (f
->n_tool_bar_rows
> 0)
10653 int border
, rows
, height
, extra
;
10655 if (INTEGERP (Vtool_bar_border
))
10656 border
= XINT (Vtool_bar_border
);
10657 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10658 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10659 else if (EQ (Vtool_bar_border
, Qborder_width
))
10660 border
= f
->border_width
;
10666 rows
= f
->n_tool_bar_rows
;
10667 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10668 extra
= it
.last_visible_y
- border
- height
* rows
;
10670 while (it
.current_y
< it
.last_visible_y
)
10673 if (extra
> 0 && rows
-- > 0)
10675 h
= (extra
+ rows
- 1) / rows
;
10678 display_tool_bar_line (&it
, height
+ h
);
10683 while (it
.current_y
< it
.last_visible_y
)
10684 display_tool_bar_line (&it
, 0);
10687 /* It doesn't make much sense to try scrolling in the tool-bar
10688 window, so don't do it. */
10689 w
->desired_matrix
->no_scrolling_p
= 1;
10690 w
->must_be_updated_p
= 1;
10692 if (!NILP (Vauto_resize_tool_bars
))
10694 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10695 int change_height_p
= 0;
10697 /* If we couldn't display everything, change the tool-bar's
10698 height if there is room for more. */
10699 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10700 && it
.current_y
< max_tool_bar_height
)
10701 change_height_p
= 1;
10703 row
= it
.glyph_row
- 1;
10705 /* If there are blank lines at the end, except for a partially
10706 visible blank line at the end that is smaller than
10707 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10708 if (!row
->displays_text_p
10709 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10710 change_height_p
= 1;
10712 /* If row displays tool-bar items, but is partially visible,
10713 change the tool-bar's height. */
10714 if (row
->displays_text_p
10715 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10716 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10717 change_height_p
= 1;
10719 /* Resize windows as needed by changing the `tool-bar-lines'
10720 frame parameter. */
10721 if (change_height_p
)
10723 extern Lisp_Object Qtool_bar_lines
;
10725 int old_height
= WINDOW_TOTAL_LINES (w
);
10727 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10729 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10730 && !f
->minimize_tool_bar_window_p
)
10731 ? (nlines
> old_height
)
10732 : (nlines
!= old_height
));
10733 f
->minimize_tool_bar_window_p
= 0;
10735 if (change_height_p
)
10737 XSETFRAME (frame
, f
);
10738 Fmodify_frame_parameters (frame
,
10739 Fcons (Fcons (Qtool_bar_lines
,
10740 make_number (nlines
)),
10742 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10744 clear_glyph_matrix (w
->desired_matrix
);
10745 f
->n_tool_bar_rows
= nrows
;
10746 fonts_changed_p
= 1;
10753 f
->minimize_tool_bar_window_p
= 0;
10758 /* Get information about the tool-bar item which is displayed in GLYPH
10759 on frame F. Return in *PROP_IDX the index where tool-bar item
10760 properties start in F->tool_bar_items. Value is zero if
10761 GLYPH doesn't display a tool-bar item. */
10764 tool_bar_item_info (f
, glyph
, prop_idx
)
10766 struct glyph
*glyph
;
10773 /* This function can be called asynchronously, which means we must
10774 exclude any possibility that Fget_text_property signals an
10776 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10777 charpos
= max (0, charpos
);
10779 /* Get the text property `menu-item' at pos. The value of that
10780 property is the start index of this item's properties in
10781 F->tool_bar_items. */
10782 prop
= Fget_text_property (make_number (charpos
),
10783 Qmenu_item
, f
->current_tool_bar_string
);
10784 if (INTEGERP (prop
))
10786 *prop_idx
= XINT (prop
);
10796 /* Get information about the tool-bar item at position X/Y on frame F.
10797 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10798 the current matrix of the tool-bar window of F, or NULL if not
10799 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10800 item in F->tool_bar_items. Value is
10802 -1 if X/Y is not on a tool-bar item
10803 0 if X/Y is on the same item that was highlighted before.
10807 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10810 struct glyph
**glyph
;
10811 int *hpos
, *vpos
, *prop_idx
;
10813 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10814 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10817 /* Find the glyph under X/Y. */
10818 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10819 if (*glyph
== NULL
)
10822 /* Get the start of this tool-bar item's properties in
10823 f->tool_bar_items. */
10824 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10827 /* Is mouse on the highlighted item? */
10828 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10829 && *vpos
>= dpyinfo
->mouse_face_beg_row
10830 && *vpos
<= dpyinfo
->mouse_face_end_row
10831 && (*vpos
> dpyinfo
->mouse_face_beg_row
10832 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10833 && (*vpos
< dpyinfo
->mouse_face_end_row
10834 || *hpos
< dpyinfo
->mouse_face_end_col
10835 || dpyinfo
->mouse_face_past_end
))
10843 Handle mouse button event on the tool-bar of frame F, at
10844 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10845 0 for button release. MODIFIERS is event modifiers for button
10849 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10852 unsigned int modifiers
;
10854 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10855 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10856 int hpos
, vpos
, prop_idx
;
10857 struct glyph
*glyph
;
10858 Lisp_Object enabled_p
;
10860 /* If not on the highlighted tool-bar item, return. */
10861 frame_to_window_pixel_xy (w
, &x
, &y
);
10862 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10865 /* If item is disabled, do nothing. */
10866 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10867 if (NILP (enabled_p
))
10872 /* Show item in pressed state. */
10873 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10874 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10875 last_tool_bar_item
= prop_idx
;
10879 Lisp_Object key
, frame
;
10880 struct input_event event
;
10881 EVENT_INIT (event
);
10883 /* Show item in released state. */
10884 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10885 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10887 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10889 XSETFRAME (frame
, f
);
10890 event
.kind
= TOOL_BAR_EVENT
;
10891 event
.frame_or_window
= frame
;
10893 kbd_buffer_store_event (&event
);
10895 event
.kind
= TOOL_BAR_EVENT
;
10896 event
.frame_or_window
= frame
;
10898 event
.modifiers
= modifiers
;
10899 kbd_buffer_store_event (&event
);
10900 last_tool_bar_item
= -1;
10905 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10906 tool-bar window-relative coordinates X/Y. Called from
10907 note_mouse_highlight. */
10910 note_tool_bar_highlight (f
, x
, y
)
10914 Lisp_Object window
= f
->tool_bar_window
;
10915 struct window
*w
= XWINDOW (window
);
10916 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10918 struct glyph
*glyph
;
10919 struct glyph_row
*row
;
10921 Lisp_Object enabled_p
;
10923 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10924 int mouse_down_p
, rc
;
10926 /* Function note_mouse_highlight is called with negative x(y
10927 values when mouse moves outside of the frame. */
10928 if (x
<= 0 || y
<= 0)
10930 clear_mouse_face (dpyinfo
);
10934 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10937 /* Not on tool-bar item. */
10938 clear_mouse_face (dpyinfo
);
10942 /* On same tool-bar item as before. */
10943 goto set_help_echo
;
10945 clear_mouse_face (dpyinfo
);
10947 /* Mouse is down, but on different tool-bar item? */
10948 mouse_down_p
= (dpyinfo
->grabbed
10949 && f
== last_mouse_frame
10950 && FRAME_LIVE_P (f
));
10952 && last_tool_bar_item
!= prop_idx
)
10955 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10956 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10958 /* If tool-bar item is not enabled, don't highlight it. */
10959 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10960 if (!NILP (enabled_p
))
10962 /* Compute the x-position of the glyph. In front and past the
10963 image is a space. We include this in the highlighted area. */
10964 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10965 for (i
= x
= 0; i
< hpos
; ++i
)
10966 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10968 /* Record this as the current active region. */
10969 dpyinfo
->mouse_face_beg_col
= hpos
;
10970 dpyinfo
->mouse_face_beg_row
= vpos
;
10971 dpyinfo
->mouse_face_beg_x
= x
;
10972 dpyinfo
->mouse_face_beg_y
= row
->y
;
10973 dpyinfo
->mouse_face_past_end
= 0;
10975 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10976 dpyinfo
->mouse_face_end_row
= vpos
;
10977 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10978 dpyinfo
->mouse_face_end_y
= row
->y
;
10979 dpyinfo
->mouse_face_window
= window
;
10980 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10982 /* Display it as active. */
10983 show_mouse_face (dpyinfo
, draw
);
10984 dpyinfo
->mouse_face_image_state
= draw
;
10989 /* Set help_echo_string to a help string to display for this tool-bar item.
10990 XTread_socket does the rest. */
10991 help_echo_object
= help_echo_window
= Qnil
;
10992 help_echo_pos
= -1;
10993 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10994 if (NILP (help_echo_string
))
10995 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10998 #endif /* HAVE_WINDOW_SYSTEM */
11002 /************************************************************************
11003 Horizontal scrolling
11004 ************************************************************************/
11006 static int hscroll_window_tree
P_ ((Lisp_Object
));
11007 static int hscroll_windows
P_ ((Lisp_Object
));
11009 /* For all leaf windows in the window tree rooted at WINDOW, set their
11010 hscroll value so that PT is (i) visible in the window, and (ii) so
11011 that it is not within a certain margin at the window's left and
11012 right border. Value is non-zero if any window's hscroll has been
11016 hscroll_window_tree (window
)
11017 Lisp_Object window
;
11019 int hscrolled_p
= 0;
11020 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11021 int hscroll_step_abs
= 0;
11022 double hscroll_step_rel
= 0;
11024 if (hscroll_relative_p
)
11026 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11027 if (hscroll_step_rel
< 0)
11029 hscroll_relative_p
= 0;
11030 hscroll_step_abs
= 0;
11033 else if (INTEGERP (Vhscroll_step
))
11035 hscroll_step_abs
= XINT (Vhscroll_step
);
11036 if (hscroll_step_abs
< 0)
11037 hscroll_step_abs
= 0;
11040 hscroll_step_abs
= 0;
11042 while (WINDOWP (window
))
11044 struct window
*w
= XWINDOW (window
);
11046 if (WINDOWP (w
->hchild
))
11047 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11048 else if (WINDOWP (w
->vchild
))
11049 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11050 else if (w
->cursor
.vpos
>= 0)
11053 int text_area_width
;
11054 struct glyph_row
*current_cursor_row
11055 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11056 struct glyph_row
*desired_cursor_row
11057 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11058 struct glyph_row
*cursor_row
11059 = (desired_cursor_row
->enabled_p
11060 ? desired_cursor_row
11061 : current_cursor_row
);
11063 text_area_width
= window_box_width (w
, TEXT_AREA
);
11065 /* Scroll when cursor is inside this scroll margin. */
11066 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11068 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11069 && ((XFASTINT (w
->hscroll
)
11070 && w
->cursor
.x
<= h_margin
)
11071 || (cursor_row
->enabled_p
11072 && cursor_row
->truncated_on_right_p
11073 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11077 struct buffer
*saved_current_buffer
;
11081 /* Find point in a display of infinite width. */
11082 saved_current_buffer
= current_buffer
;
11083 current_buffer
= XBUFFER (w
->buffer
);
11085 if (w
== XWINDOW (selected_window
))
11086 pt
= BUF_PT (current_buffer
);
11089 pt
= marker_position (w
->pointm
);
11090 pt
= max (BEGV
, pt
);
11094 /* Move iterator to pt starting at cursor_row->start in
11095 a line with infinite width. */
11096 init_to_row_start (&it
, w
, cursor_row
);
11097 it
.last_visible_x
= INFINITY
;
11098 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11099 current_buffer
= saved_current_buffer
;
11101 /* Position cursor in window. */
11102 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11103 hscroll
= max (0, (it
.current_x
11104 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11105 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11106 : (text_area_width
/ 2))))
11107 / FRAME_COLUMN_WIDTH (it
.f
);
11108 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11110 if (hscroll_relative_p
)
11111 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11114 wanted_x
= text_area_width
11115 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11118 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11122 if (hscroll_relative_p
)
11123 wanted_x
= text_area_width
* hscroll_step_rel
11126 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11129 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11131 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11133 /* Don't call Fset_window_hscroll if value hasn't
11134 changed because it will prevent redisplay
11136 if (XFASTINT (w
->hscroll
) != hscroll
)
11138 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11139 w
->hscroll
= make_number (hscroll
);
11148 /* Value is non-zero if hscroll of any leaf window has been changed. */
11149 return hscrolled_p
;
11153 /* Set hscroll so that cursor is visible and not inside horizontal
11154 scroll margins for all windows in the tree rooted at WINDOW. See
11155 also hscroll_window_tree above. Value is non-zero if any window's
11156 hscroll has been changed. If it has, desired matrices on the frame
11157 of WINDOW are cleared. */
11160 hscroll_windows (window
)
11161 Lisp_Object window
;
11163 int hscrolled_p
= hscroll_window_tree (window
);
11165 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11166 return hscrolled_p
;
11171 /************************************************************************
11173 ************************************************************************/
11175 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11176 to a non-zero value. This is sometimes handy to have in a debugger
11181 /* First and last unchanged row for try_window_id. */
11183 int debug_first_unchanged_at_end_vpos
;
11184 int debug_last_unchanged_at_beg_vpos
;
11186 /* Delta vpos and y. */
11188 int debug_dvpos
, debug_dy
;
11190 /* Delta in characters and bytes for try_window_id. */
11192 int debug_delta
, debug_delta_bytes
;
11194 /* Values of window_end_pos and window_end_vpos at the end of
11197 EMACS_INT debug_end_pos
, debug_end_vpos
;
11199 /* Append a string to W->desired_matrix->method. FMT is a printf
11200 format string. A1...A9 are a supplement for a variable-length
11201 argument list. If trace_redisplay_p is non-zero also printf the
11202 resulting string to stderr. */
11205 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11208 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11211 char *method
= w
->desired_matrix
->method
;
11212 int len
= strlen (method
);
11213 int size
= sizeof w
->desired_matrix
->method
;
11214 int remaining
= size
- len
- 1;
11216 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11217 if (len
&& remaining
)
11220 --remaining
, ++len
;
11223 strncpy (method
+ len
, buffer
, remaining
);
11225 if (trace_redisplay_p
)
11226 fprintf (stderr
, "%p (%s): %s\n",
11228 ((BUFFERP (w
->buffer
)
11229 && STRINGP (XBUFFER (w
->buffer
)->name
))
11230 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
11235 #endif /* GLYPH_DEBUG */
11238 /* Value is non-zero if all changes in window W, which displays
11239 current_buffer, are in the text between START and END. START is a
11240 buffer position, END is given as a distance from Z. Used in
11241 redisplay_internal for display optimization. */
11244 text_outside_line_unchanged_p (w
, start
, end
)
11248 int unchanged_p
= 1;
11250 /* If text or overlays have changed, see where. */
11251 if (XFASTINT (w
->last_modified
) < MODIFF
11252 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11254 /* Gap in the line? */
11255 if (GPT
< start
|| Z
- GPT
< end
)
11258 /* Changes start in front of the line, or end after it? */
11260 && (BEG_UNCHANGED
< start
- 1
11261 || END_UNCHANGED
< end
))
11264 /* If selective display, can't optimize if changes start at the
11265 beginning of the line. */
11267 && INTEGERP (current_buffer
->selective_display
)
11268 && XINT (current_buffer
->selective_display
) > 0
11269 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11272 /* If there are overlays at the start or end of the line, these
11273 may have overlay strings with newlines in them. A change at
11274 START, for instance, may actually concern the display of such
11275 overlay strings as well, and they are displayed on different
11276 lines. So, quickly rule out this case. (For the future, it
11277 might be desirable to implement something more telling than
11278 just BEG/END_UNCHANGED.) */
11281 if (BEG
+ BEG_UNCHANGED
== start
11282 && overlay_touches_p (start
))
11284 if (END_UNCHANGED
== end
11285 && overlay_touches_p (Z
- end
))
11289 /* Under bidi reordering, adding or deleting a character in the
11290 beginning of a paragraph, before the first strong directional
11291 character, can change the base direction of the paragraph (unless
11292 the buffer specifies a fixed paragraph direction), which will
11293 require to redisplay the whole paragraph. It might be worthwhile
11294 to find the paragraph limits and widen the range of redisplayed
11295 lines to that, but for now just give up this optimization. */
11296 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
11297 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
11301 return unchanged_p
;
11305 /* Do a frame update, taking possible shortcuts into account. This is
11306 the main external entry point for redisplay.
11308 If the last redisplay displayed an echo area message and that message
11309 is no longer requested, we clear the echo area or bring back the
11310 mini-buffer if that is in use. */
11315 redisplay_internal (0);
11320 overlay_arrow_string_or_property (var
)
11325 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11328 return Voverlay_arrow_string
;
11331 /* Return 1 if there are any overlay-arrows in current_buffer. */
11333 overlay_arrow_in_current_buffer_p ()
11337 for (vlist
= Voverlay_arrow_variable_list
;
11339 vlist
= XCDR (vlist
))
11341 Lisp_Object var
= XCAR (vlist
);
11344 if (!SYMBOLP (var
))
11346 val
= find_symbol_value (var
);
11348 && current_buffer
== XMARKER (val
)->buffer
)
11355 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11359 overlay_arrows_changed_p ()
11363 for (vlist
= Voverlay_arrow_variable_list
;
11365 vlist
= XCDR (vlist
))
11367 Lisp_Object var
= XCAR (vlist
);
11368 Lisp_Object val
, pstr
;
11370 if (!SYMBOLP (var
))
11372 val
= find_symbol_value (var
);
11373 if (!MARKERP (val
))
11375 if (! EQ (COERCE_MARKER (val
),
11376 Fget (var
, Qlast_arrow_position
))
11377 || ! (pstr
= overlay_arrow_string_or_property (var
),
11378 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11384 /* Mark overlay arrows to be updated on next redisplay. */
11387 update_overlay_arrows (up_to_date
)
11392 for (vlist
= Voverlay_arrow_variable_list
;
11394 vlist
= XCDR (vlist
))
11396 Lisp_Object var
= XCAR (vlist
);
11398 if (!SYMBOLP (var
))
11401 if (up_to_date
> 0)
11403 Lisp_Object val
= find_symbol_value (var
);
11404 Fput (var
, Qlast_arrow_position
,
11405 COERCE_MARKER (val
));
11406 Fput (var
, Qlast_arrow_string
,
11407 overlay_arrow_string_or_property (var
));
11409 else if (up_to_date
< 0
11410 || !NILP (Fget (var
, Qlast_arrow_position
)))
11412 Fput (var
, Qlast_arrow_position
, Qt
);
11413 Fput (var
, Qlast_arrow_string
, Qt
);
11419 /* Return overlay arrow string to display at row.
11420 Return integer (bitmap number) for arrow bitmap in left fringe.
11421 Return nil if no overlay arrow. */
11424 overlay_arrow_at_row (it
, row
)
11426 struct glyph_row
*row
;
11430 for (vlist
= Voverlay_arrow_variable_list
;
11432 vlist
= XCDR (vlist
))
11434 Lisp_Object var
= XCAR (vlist
);
11437 if (!SYMBOLP (var
))
11440 val
= find_symbol_value (var
);
11443 && current_buffer
== XMARKER (val
)->buffer
11444 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11446 if (FRAME_WINDOW_P (it
->f
)
11447 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11449 #ifdef HAVE_WINDOW_SYSTEM
11450 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11453 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11454 return make_number (fringe_bitmap
);
11457 return make_number (-1); /* Use default arrow bitmap */
11459 return overlay_arrow_string_or_property (var
);
11466 /* Return 1 if point moved out of or into a composition. Otherwise
11467 return 0. PREV_BUF and PREV_PT are the last point buffer and
11468 position. BUF and PT are the current point buffer and position. */
11471 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11472 struct buffer
*prev_buf
, *buf
;
11475 EMACS_INT start
, end
;
11477 Lisp_Object buffer
;
11479 XSETBUFFER (buffer
, buf
);
11480 /* Check a composition at the last point if point moved within the
11482 if (prev_buf
== buf
)
11485 /* Point didn't move. */
11488 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11489 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11490 && COMPOSITION_VALID_P (start
, end
, prop
)
11491 && start
< prev_pt
&& end
> prev_pt
)
11492 /* The last point was within the composition. Return 1 iff
11493 point moved out of the composition. */
11494 return (pt
<= start
|| pt
>= end
);
11497 /* Check a composition at the current point. */
11498 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11499 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11500 && COMPOSITION_VALID_P (start
, end
, prop
)
11501 && start
< pt
&& end
> pt
);
11505 /* Reconsider the setting of B->clip_changed which is displayed
11509 reconsider_clip_changes (w
, b
)
11513 if (b
->clip_changed
11514 && !NILP (w
->window_end_valid
)
11515 && w
->current_matrix
->buffer
== b
11516 && w
->current_matrix
->zv
== BUF_ZV (b
)
11517 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11518 b
->clip_changed
= 0;
11520 /* If display wasn't paused, and W is not a tool bar window, see if
11521 point has been moved into or out of a composition. In that case,
11522 we set b->clip_changed to 1 to force updating the screen. If
11523 b->clip_changed has already been set to 1, we can skip this
11525 if (!b
->clip_changed
11526 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11530 if (w
== XWINDOW (selected_window
))
11531 pt
= BUF_PT (current_buffer
);
11533 pt
= marker_position (w
->pointm
);
11535 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11536 || pt
!= XINT (w
->last_point
))
11537 && check_point_in_composition (w
->current_matrix
->buffer
,
11538 XINT (w
->last_point
),
11539 XBUFFER (w
->buffer
), pt
))
11540 b
->clip_changed
= 1;
11545 /* Select FRAME to forward the values of frame-local variables into C
11546 variables so that the redisplay routines can access those values
11550 select_frame_for_redisplay (frame
)
11553 Lisp_Object tail
, symbol
, val
;
11554 Lisp_Object old
= selected_frame
;
11555 struct Lisp_Symbol
*sym
;
11557 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11559 selected_frame
= frame
;
11563 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11564 if (CONSP (XCAR (tail
))
11565 && (symbol
= XCAR (XCAR (tail
)),
11567 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11569 (BUFFER_LOCAL_VALUEP (val
)))
11570 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11571 /* Use find_symbol_value rather than Fsymbol_value
11572 to avoid an error if it is void. */
11573 find_symbol_value (symbol
);
11574 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11578 #define STOP_POLLING \
11579 do { if (! polling_stopped_here) stop_polling (); \
11580 polling_stopped_here = 1; } while (0)
11582 #define RESUME_POLLING \
11583 do { if (polling_stopped_here) start_polling (); \
11584 polling_stopped_here = 0; } while (0)
11587 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11588 response to any user action; therefore, we should preserve the echo
11589 area. (Actually, our caller does that job.) Perhaps in the future
11590 avoid recentering windows if it is not necessary; currently that
11591 causes some problems. */
11594 redisplay_internal (preserve_echo_area
)
11595 int preserve_echo_area
;
11597 struct window
*w
= XWINDOW (selected_window
);
11600 int must_finish
= 0;
11601 struct text_pos tlbufpos
, tlendpos
;
11602 int number_of_visible_frames
;
11605 int polling_stopped_here
= 0;
11606 Lisp_Object old_frame
= selected_frame
;
11608 /* Non-zero means redisplay has to consider all windows on all
11609 frames. Zero means, only selected_window is considered. */
11610 int consider_all_windows_p
;
11612 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11614 /* No redisplay if running in batch mode or frame is not yet fully
11615 initialized, or redisplay is explicitly turned off by setting
11616 Vinhibit_redisplay. */
11617 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11618 || !NILP (Vinhibit_redisplay
))
11621 /* Don't examine these until after testing Vinhibit_redisplay.
11622 When Emacs is shutting down, perhaps because its connection to
11623 X has dropped, we should not look at them at all. */
11624 f
= XFRAME (w
->frame
);
11625 sf
= SELECTED_FRAME ();
11627 if (!f
->glyphs_initialized_p
)
11630 /* The flag redisplay_performed_directly_p is set by
11631 direct_output_for_insert when it already did the whole screen
11632 update necessary. */
11633 if (redisplay_performed_directly_p
)
11635 redisplay_performed_directly_p
= 0;
11636 if (!hscroll_windows (selected_window
))
11640 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11641 if (popup_activated ())
11645 /* I don't think this happens but let's be paranoid. */
11646 if (redisplaying_p
)
11649 /* Record a function that resets redisplaying_p to its old value
11650 when we leave this function. */
11651 count
= SPECPDL_INDEX ();
11652 record_unwind_protect (unwind_redisplay
,
11653 Fcons (make_number (redisplaying_p
), selected_frame
));
11655 specbind (Qinhibit_free_realized_faces
, Qnil
);
11658 Lisp_Object tail
, frame
;
11660 FOR_EACH_FRAME (tail
, frame
)
11662 struct frame
*f
= XFRAME (frame
);
11663 f
->already_hscrolled_p
= 0;
11668 if (!EQ (old_frame
, selected_frame
)
11669 && FRAME_LIVE_P (XFRAME (old_frame
)))
11670 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11671 selected_frame and selected_window to be temporarily out-of-sync so
11672 when we come back here via `goto retry', we need to resync because we
11673 may need to run Elisp code (via prepare_menu_bars). */
11674 select_frame_for_redisplay (old_frame
);
11677 reconsider_clip_changes (w
, current_buffer
);
11678 last_escape_glyph_frame
= NULL
;
11679 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11681 /* If new fonts have been loaded that make a glyph matrix adjustment
11682 necessary, do it. */
11683 if (fonts_changed_p
)
11685 adjust_glyphs (NULL
);
11686 ++windows_or_buffers_changed
;
11687 fonts_changed_p
= 0;
11690 /* If face_change_count is non-zero, init_iterator will free all
11691 realized faces, which includes the faces referenced from current
11692 matrices. So, we can't reuse current matrices in this case. */
11693 if (face_change_count
)
11694 ++windows_or_buffers_changed
;
11696 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11697 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11699 /* Since frames on a single ASCII terminal share the same
11700 display area, displaying a different frame means redisplay
11701 the whole thing. */
11702 windows_or_buffers_changed
++;
11703 SET_FRAME_GARBAGED (sf
);
11705 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11707 FRAME_TTY (sf
)->previous_frame
= sf
;
11710 /* Set the visible flags for all frames. Do this before checking
11711 for resized or garbaged frames; they want to know if their frames
11712 are visible. See the comment in frame.h for
11713 FRAME_SAMPLE_VISIBILITY. */
11715 Lisp_Object tail
, frame
;
11717 number_of_visible_frames
= 0;
11719 FOR_EACH_FRAME (tail
, frame
)
11721 struct frame
*f
= XFRAME (frame
);
11723 FRAME_SAMPLE_VISIBILITY (f
);
11724 if (FRAME_VISIBLE_P (f
))
11725 ++number_of_visible_frames
;
11726 clear_desired_matrices (f
);
11730 /* Notice any pending interrupt request to change frame size. */
11731 do_pending_window_change (1);
11733 /* Clear frames marked as garbaged. */
11734 if (frame_garbaged
)
11735 clear_garbaged_frames ();
11737 /* Build menubar and tool-bar items. */
11738 if (NILP (Vmemory_full
))
11739 prepare_menu_bars ();
11741 if (windows_or_buffers_changed
)
11742 update_mode_lines
++;
11744 /* Detect case that we need to write or remove a star in the mode line. */
11745 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11747 w
->update_mode_line
= Qt
;
11748 if (buffer_shared
> 1)
11749 update_mode_lines
++;
11752 /* Avoid invocation of point motion hooks by `current_column' below. */
11753 count1
= SPECPDL_INDEX ();
11754 specbind (Qinhibit_point_motion_hooks
, Qt
);
11756 /* If %c is in the mode line, update it if needed. */
11757 if (!NILP (w
->column_number_displayed
)
11758 /* This alternative quickly identifies a common case
11759 where no change is needed. */
11760 && !(PT
== XFASTINT (w
->last_point
)
11761 && XFASTINT (w
->last_modified
) >= MODIFF
11762 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11763 && (XFASTINT (w
->column_number_displayed
)
11764 != (int) current_column ())) /* iftc */
11765 w
->update_mode_line
= Qt
;
11767 unbind_to (count1
, Qnil
);
11769 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11771 /* The variable buffer_shared is set in redisplay_window and
11772 indicates that we redisplay a buffer in different windows. See
11774 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11775 || cursor_type_changed
);
11777 /* If specs for an arrow have changed, do thorough redisplay
11778 to ensure we remove any arrow that should no longer exist. */
11779 if (overlay_arrows_changed_p ())
11780 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11782 /* Normally the message* functions will have already displayed and
11783 updated the echo area, but the frame may have been trashed, or
11784 the update may have been preempted, so display the echo area
11785 again here. Checking message_cleared_p captures the case that
11786 the echo area should be cleared. */
11787 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11788 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11789 || (message_cleared_p
11790 && minibuf_level
== 0
11791 /* If the mini-window is currently selected, this means the
11792 echo-area doesn't show through. */
11793 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11795 int window_height_changed_p
= echo_area_display (0);
11798 /* If we don't display the current message, don't clear the
11799 message_cleared_p flag, because, if we did, we wouldn't clear
11800 the echo area in the next redisplay which doesn't preserve
11802 if (!display_last_displayed_message_p
)
11803 message_cleared_p
= 0;
11805 if (fonts_changed_p
)
11807 else if (window_height_changed_p
)
11809 consider_all_windows_p
= 1;
11810 ++update_mode_lines
;
11811 ++windows_or_buffers_changed
;
11813 /* If window configuration was changed, frames may have been
11814 marked garbaged. Clear them or we will experience
11815 surprises wrt scrolling. */
11816 if (frame_garbaged
)
11817 clear_garbaged_frames ();
11820 else if (EQ (selected_window
, minibuf_window
)
11821 && (current_buffer
->clip_changed
11822 || XFASTINT (w
->last_modified
) < MODIFF
11823 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11824 && resize_mini_window (w
, 0))
11826 /* Resized active mini-window to fit the size of what it is
11827 showing if its contents might have changed. */
11829 /* FIXME: this causes all frames to be updated, which seems unnecessary
11830 since only the current frame needs to be considered. This function needs
11831 to be rewritten with two variables, consider_all_windows and
11832 consider_all_frames. */
11833 consider_all_windows_p
= 1;
11834 ++windows_or_buffers_changed
;
11835 ++update_mode_lines
;
11837 /* If window configuration was changed, frames may have been
11838 marked garbaged. Clear them or we will experience
11839 surprises wrt scrolling. */
11840 if (frame_garbaged
)
11841 clear_garbaged_frames ();
11845 /* If showing the region, and mark has changed, we must redisplay
11846 the whole window. The assignment to this_line_start_pos prevents
11847 the optimization directly below this if-statement. */
11848 if (((!NILP (Vtransient_mark_mode
)
11849 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11850 != !NILP (w
->region_showing
))
11851 || (!NILP (w
->region_showing
)
11852 && !EQ (w
->region_showing
,
11853 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11854 CHARPOS (this_line_start_pos
) = 0;
11856 /* Optimize the case that only the line containing the cursor in the
11857 selected window has changed. Variables starting with this_ are
11858 set in display_line and record information about the line
11859 containing the cursor. */
11860 tlbufpos
= this_line_start_pos
;
11861 tlendpos
= this_line_end_pos
;
11862 if (!consider_all_windows_p
11863 && CHARPOS (tlbufpos
) > 0
11864 && NILP (w
->update_mode_line
)
11865 && !current_buffer
->clip_changed
11866 && !current_buffer
->prevent_redisplay_optimizations_p
11867 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11868 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11869 /* Make sure recorded data applies to current buffer, etc. */
11870 && this_line_buffer
== current_buffer
11871 && current_buffer
== XBUFFER (w
->buffer
)
11872 && NILP (w
->force_start
)
11873 && NILP (w
->optional_new_start
)
11874 /* Point must be on the line that we have info recorded about. */
11875 && PT
>= CHARPOS (tlbufpos
)
11876 && PT
<= Z
- CHARPOS (tlendpos
)
11877 /* All text outside that line, including its final newline,
11878 must be unchanged. */
11879 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11880 CHARPOS (tlendpos
)))
11882 if (CHARPOS (tlbufpos
) > BEGV
11883 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11884 && (CHARPOS (tlbufpos
) == ZV
11885 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11886 /* Former continuation line has disappeared by becoming empty. */
11888 else if (XFASTINT (w
->last_modified
) < MODIFF
11889 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11890 || MINI_WINDOW_P (w
))
11892 /* We have to handle the case of continuation around a
11893 wide-column character (see the comment in indent.c around
11896 For instance, in the following case:
11898 -------- Insert --------
11899 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11900 J_I_ ==> J_I_ `^^' are cursors.
11904 As we have to redraw the line above, we cannot use this
11908 int line_height_before
= this_line_pixel_height
;
11910 /* Note that start_display will handle the case that the
11911 line starting at tlbufpos is a continuation line. */
11912 start_display (&it
, w
, tlbufpos
);
11914 /* Implementation note: It this still necessary? */
11915 if (it
.current_x
!= this_line_start_x
)
11918 TRACE ((stderr
, "trying display optimization 1\n"));
11919 w
->cursor
.vpos
= -1;
11920 overlay_arrow_seen
= 0;
11921 it
.vpos
= this_line_vpos
;
11922 it
.current_y
= this_line_y
;
11923 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11924 display_line (&it
);
11926 /* If line contains point, is not continued,
11927 and ends at same distance from eob as before, we win. */
11928 if (w
->cursor
.vpos
>= 0
11929 /* Line is not continued, otherwise this_line_start_pos
11930 would have been set to 0 in display_line. */
11931 && CHARPOS (this_line_start_pos
)
11932 /* Line ends as before. */
11933 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11934 /* Line has same height as before. Otherwise other lines
11935 would have to be shifted up or down. */
11936 && this_line_pixel_height
== line_height_before
)
11938 /* If this is not the window's last line, we must adjust
11939 the charstarts of the lines below. */
11940 if (it
.current_y
< it
.last_visible_y
)
11942 struct glyph_row
*row
11943 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11944 int delta
, delta_bytes
;
11946 /* We used to distinguish between two cases here,
11947 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11948 when the line ends in a newline or the end of the
11949 buffer's accessible portion. But both cases did
11950 the same, so they were collapsed. */
11952 - CHARPOS (tlendpos
)
11953 - MATRIX_ROW_START_CHARPOS (row
));
11954 delta_bytes
= (Z_BYTE
11955 - BYTEPOS (tlendpos
)
11956 - MATRIX_ROW_START_BYTEPOS (row
));
11958 increment_matrix_positions (w
->current_matrix
,
11959 this_line_vpos
+ 1,
11960 w
->current_matrix
->nrows
,
11961 delta
, delta_bytes
);
11964 /* If this row displays text now but previously didn't,
11965 or vice versa, w->window_end_vpos may have to be
11967 if ((it
.glyph_row
- 1)->displays_text_p
)
11969 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11970 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11972 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11973 && this_line_vpos
> 0)
11974 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11975 w
->window_end_valid
= Qnil
;
11977 /* Update hint: No need to try to scroll in update_window. */
11978 w
->desired_matrix
->no_scrolling_p
= 1;
11981 *w
->desired_matrix
->method
= 0;
11982 debug_method_add (w
, "optimization 1");
11984 #ifdef HAVE_WINDOW_SYSTEM
11985 update_window_fringes (w
, 0);
11992 else if (/* Cursor position hasn't changed. */
11993 PT
== XFASTINT (w
->last_point
)
11994 /* Make sure the cursor was last displayed
11995 in this window. Otherwise we have to reposition it. */
11996 && 0 <= w
->cursor
.vpos
11997 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12001 do_pending_window_change (1);
12003 /* We used to always goto end_of_redisplay here, but this
12004 isn't enough if we have a blinking cursor. */
12005 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12006 goto end_of_redisplay
;
12010 /* If highlighting the region, or if the cursor is in the echo area,
12011 then we can't just move the cursor. */
12012 else if (! (!NILP (Vtransient_mark_mode
)
12013 && !NILP (current_buffer
->mark_active
))
12014 && (EQ (selected_window
, current_buffer
->last_selected_window
)
12015 || highlight_nonselected_windows
)
12016 && NILP (w
->region_showing
)
12017 && NILP (Vshow_trailing_whitespace
)
12018 && !cursor_in_echo_area
)
12021 struct glyph_row
*row
;
12023 /* Skip from tlbufpos to PT and see where it is. Note that
12024 PT may be in invisible text. If so, we will end at the
12025 next visible position. */
12026 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12027 NULL
, DEFAULT_FACE_ID
);
12028 it
.current_x
= this_line_start_x
;
12029 it
.current_y
= this_line_y
;
12030 it
.vpos
= this_line_vpos
;
12032 /* The call to move_it_to stops in front of PT, but
12033 moves over before-strings. */
12034 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12036 if (it
.vpos
== this_line_vpos
12037 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12040 xassert (this_line_vpos
== it
.vpos
);
12041 xassert (this_line_y
== it
.current_y
);
12042 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12044 *w
->desired_matrix
->method
= 0;
12045 debug_method_add (w
, "optimization 3");
12054 /* Text changed drastically or point moved off of line. */
12055 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12058 CHARPOS (this_line_start_pos
) = 0;
12059 consider_all_windows_p
|= buffer_shared
> 1;
12060 ++clear_face_cache_count
;
12061 #ifdef HAVE_WINDOW_SYSTEM
12062 ++clear_image_cache_count
;
12065 /* Build desired matrices, and update the display. If
12066 consider_all_windows_p is non-zero, do it for all windows on all
12067 frames. Otherwise do it for selected_window, only. */
12069 if (consider_all_windows_p
)
12071 Lisp_Object tail
, frame
;
12073 FOR_EACH_FRAME (tail
, frame
)
12074 XFRAME (frame
)->updated_p
= 0;
12076 /* Recompute # windows showing selected buffer. This will be
12077 incremented each time such a window is displayed. */
12080 FOR_EACH_FRAME (tail
, frame
)
12082 struct frame
*f
= XFRAME (frame
);
12084 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12086 if (! EQ (frame
, selected_frame
))
12087 /* Select the frame, for the sake of frame-local
12089 select_frame_for_redisplay (frame
);
12091 /* Mark all the scroll bars to be removed; we'll redeem
12092 the ones we want when we redisplay their windows. */
12093 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12094 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12096 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12097 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12099 /* The X error handler may have deleted that frame. */
12100 if (!FRAME_LIVE_P (f
))
12103 /* Any scroll bars which redisplay_windows should have
12104 nuked should now go away. */
12105 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12106 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12108 /* If fonts changed, display again. */
12109 /* ??? rms: I suspect it is a mistake to jump all the way
12110 back to retry here. It should just retry this frame. */
12111 if (fonts_changed_p
)
12114 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12116 /* See if we have to hscroll. */
12117 if (!f
->already_hscrolled_p
)
12119 f
->already_hscrolled_p
= 1;
12120 if (hscroll_windows (f
->root_window
))
12124 /* Prevent various kinds of signals during display
12125 update. stdio is not robust about handling
12126 signals, which can cause an apparent I/O
12128 if (interrupt_input
)
12129 unrequest_sigio ();
12132 /* Update the display. */
12133 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12134 pause
|= update_frame (f
, 0, 0);
12140 if (!EQ (old_frame
, selected_frame
)
12141 && FRAME_LIVE_P (XFRAME (old_frame
)))
12142 /* We played a bit fast-and-loose above and allowed selected_frame
12143 and selected_window to be temporarily out-of-sync but let's make
12144 sure this stays contained. */
12145 select_frame_for_redisplay (old_frame
);
12146 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12150 /* Do the mark_window_display_accurate after all windows have
12151 been redisplayed because this call resets flags in buffers
12152 which are needed for proper redisplay. */
12153 FOR_EACH_FRAME (tail
, frame
)
12155 struct frame
*f
= XFRAME (frame
);
12158 mark_window_display_accurate (f
->root_window
, 1);
12159 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12160 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12165 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12167 Lisp_Object mini_window
;
12168 struct frame
*mini_frame
;
12170 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12171 /* Use list_of_error, not Qerror, so that
12172 we catch only errors and don't run the debugger. */
12173 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12175 redisplay_window_error
);
12177 /* Compare desired and current matrices, perform output. */
12180 /* If fonts changed, display again. */
12181 if (fonts_changed_p
)
12184 /* Prevent various kinds of signals during display update.
12185 stdio is not robust about handling signals,
12186 which can cause an apparent I/O error. */
12187 if (interrupt_input
)
12188 unrequest_sigio ();
12191 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12193 if (hscroll_windows (selected_window
))
12196 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12197 pause
= update_frame (sf
, 0, 0);
12200 /* We may have called echo_area_display at the top of this
12201 function. If the echo area is on another frame, that may
12202 have put text on a frame other than the selected one, so the
12203 above call to update_frame would not have caught it. Catch
12205 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12206 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12208 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12210 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12211 pause
|= update_frame (mini_frame
, 0, 0);
12212 if (!pause
&& hscroll_windows (mini_window
))
12217 /* If display was paused because of pending input, make sure we do a
12218 thorough update the next time. */
12221 /* Prevent the optimization at the beginning of
12222 redisplay_internal that tries a single-line update of the
12223 line containing the cursor in the selected window. */
12224 CHARPOS (this_line_start_pos
) = 0;
12226 /* Let the overlay arrow be updated the next time. */
12227 update_overlay_arrows (0);
12229 /* If we pause after scrolling, some rows in the current
12230 matrices of some windows are not valid. */
12231 if (!WINDOW_FULL_WIDTH_P (w
)
12232 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12233 update_mode_lines
= 1;
12237 if (!consider_all_windows_p
)
12239 /* This has already been done above if
12240 consider_all_windows_p is set. */
12241 mark_window_display_accurate_1 (w
, 1);
12243 /* Say overlay arrows are up to date. */
12244 update_overlay_arrows (1);
12246 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12247 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12250 update_mode_lines
= 0;
12251 windows_or_buffers_changed
= 0;
12252 cursor_type_changed
= 0;
12255 /* Start SIGIO interrupts coming again. Having them off during the
12256 code above makes it less likely one will discard output, but not
12257 impossible, since there might be stuff in the system buffer here.
12258 But it is much hairier to try to do anything about that. */
12259 if (interrupt_input
)
12263 /* If a frame has become visible which was not before, redisplay
12264 again, so that we display it. Expose events for such a frame
12265 (which it gets when becoming visible) don't call the parts of
12266 redisplay constructing glyphs, so simply exposing a frame won't
12267 display anything in this case. So, we have to display these
12268 frames here explicitly. */
12271 Lisp_Object tail
, frame
;
12274 FOR_EACH_FRAME (tail
, frame
)
12276 int this_is_visible
= 0;
12278 if (XFRAME (frame
)->visible
)
12279 this_is_visible
= 1;
12280 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12281 if (XFRAME (frame
)->visible
)
12282 this_is_visible
= 1;
12284 if (this_is_visible
)
12288 if (new_count
!= number_of_visible_frames
)
12289 windows_or_buffers_changed
++;
12292 /* Change frame size now if a change is pending. */
12293 do_pending_window_change (1);
12295 /* If we just did a pending size change, or have additional
12296 visible frames, redisplay again. */
12297 if (windows_or_buffers_changed
&& !pause
)
12300 /* Clear the face cache eventually. */
12301 if (consider_all_windows_p
)
12303 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12305 clear_face_cache (0);
12306 clear_face_cache_count
= 0;
12308 #ifdef HAVE_WINDOW_SYSTEM
12309 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12311 clear_image_caches (Qnil
);
12312 clear_image_cache_count
= 0;
12314 #endif /* HAVE_WINDOW_SYSTEM */
12318 unbind_to (count
, Qnil
);
12323 /* Redisplay, but leave alone any recent echo area message unless
12324 another message has been requested in its place.
12326 This is useful in situations where you need to redisplay but no
12327 user action has occurred, making it inappropriate for the message
12328 area to be cleared. See tracking_off and
12329 wait_reading_process_output for examples of these situations.
12331 FROM_WHERE is an integer saying from where this function was
12332 called. This is useful for debugging. */
12335 redisplay_preserve_echo_area (from_where
)
12338 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12340 if (!NILP (echo_area_buffer
[1]))
12342 /* We have a previously displayed message, but no current
12343 message. Redisplay the previous message. */
12344 display_last_displayed_message_p
= 1;
12345 redisplay_internal (1);
12346 display_last_displayed_message_p
= 0;
12349 redisplay_internal (1);
12351 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12352 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12353 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12357 /* Function registered with record_unwind_protect in
12358 redisplay_internal. Reset redisplaying_p to the value it had
12359 before redisplay_internal was called, and clear
12360 prevent_freeing_realized_faces_p. It also selects the previously
12361 selected frame, unless it has been deleted (by an X connection
12362 failure during redisplay, for example). */
12365 unwind_redisplay (val
)
12368 Lisp_Object old_redisplaying_p
, old_frame
;
12370 old_redisplaying_p
= XCAR (val
);
12371 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12372 old_frame
= XCDR (val
);
12373 if (! EQ (old_frame
, selected_frame
)
12374 && FRAME_LIVE_P (XFRAME (old_frame
)))
12375 select_frame_for_redisplay (old_frame
);
12380 /* Mark the display of window W as accurate or inaccurate. If
12381 ACCURATE_P is non-zero mark display of W as accurate. If
12382 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12383 redisplay_internal is called. */
12386 mark_window_display_accurate_1 (w
, accurate_p
)
12390 if (BUFFERP (w
->buffer
))
12392 struct buffer
*b
= XBUFFER (w
->buffer
);
12395 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12396 w
->last_overlay_modified
12397 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12399 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12403 b
->clip_changed
= 0;
12404 b
->prevent_redisplay_optimizations_p
= 0;
12406 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12407 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12408 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12409 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12411 w
->current_matrix
->buffer
= b
;
12412 w
->current_matrix
->begv
= BUF_BEGV (b
);
12413 w
->current_matrix
->zv
= BUF_ZV (b
);
12415 w
->last_cursor
= w
->cursor
;
12416 w
->last_cursor_off_p
= w
->cursor_off_p
;
12418 if (w
== XWINDOW (selected_window
))
12419 w
->last_point
= make_number (BUF_PT (b
));
12421 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12427 w
->window_end_valid
= w
->buffer
;
12428 w
->update_mode_line
= Qnil
;
12433 /* Mark the display of windows in the window tree rooted at WINDOW as
12434 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12435 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12436 be redisplayed the next time redisplay_internal is called. */
12439 mark_window_display_accurate (window
, accurate_p
)
12440 Lisp_Object window
;
12445 for (; !NILP (window
); window
= w
->next
)
12447 w
= XWINDOW (window
);
12448 mark_window_display_accurate_1 (w
, accurate_p
);
12450 if (!NILP (w
->vchild
))
12451 mark_window_display_accurate (w
->vchild
, accurate_p
);
12452 if (!NILP (w
->hchild
))
12453 mark_window_display_accurate (w
->hchild
, accurate_p
);
12458 update_overlay_arrows (1);
12462 /* Force a thorough redisplay the next time by setting
12463 last_arrow_position and last_arrow_string to t, which is
12464 unequal to any useful value of Voverlay_arrow_... */
12465 update_overlay_arrows (-1);
12470 /* Return value in display table DP (Lisp_Char_Table *) for character
12471 C. Since a display table doesn't have any parent, we don't have to
12472 follow parent. Do not call this function directly but use the
12473 macro DISP_CHAR_VECTOR. */
12476 disp_char_vector (dp
, c
)
12477 struct Lisp_Char_Table
*dp
;
12482 if (ASCII_CHAR_P (c
))
12485 if (SUB_CHAR_TABLE_P (val
))
12486 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12492 XSETCHAR_TABLE (table
, dp
);
12493 val
= char_table_ref (table
, c
);
12502 /***********************************************************************
12504 ***********************************************************************/
12506 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12509 redisplay_windows (window
)
12510 Lisp_Object window
;
12512 while (!NILP (window
))
12514 struct window
*w
= XWINDOW (window
);
12516 if (!NILP (w
->hchild
))
12517 redisplay_windows (w
->hchild
);
12518 else if (!NILP (w
->vchild
))
12519 redisplay_windows (w
->vchild
);
12520 else if (!NILP (w
->buffer
))
12522 displayed_buffer
= XBUFFER (w
->buffer
);
12523 /* Use list_of_error, not Qerror, so that
12524 we catch only errors and don't run the debugger. */
12525 internal_condition_case_1 (redisplay_window_0
, window
,
12527 redisplay_window_error
);
12535 redisplay_window_error ()
12537 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12542 redisplay_window_0 (window
)
12543 Lisp_Object window
;
12545 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12546 redisplay_window (window
, 0);
12551 redisplay_window_1 (window
)
12552 Lisp_Object window
;
12554 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12555 redisplay_window (window
, 1);
12560 /* Increment GLYPH until it reaches END or CONDITION fails while
12561 adding (GLYPH)->pixel_width to X. */
12563 #define SKIP_GLYPHS(glyph, end, x, condition) \
12566 (x) += (glyph)->pixel_width; \
12569 while ((glyph) < (end) && (condition))
12572 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12573 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12574 which positions recorded in ROW differ from current buffer
12577 Return 0 if cursor is not on this row, 1 otherwise. */
12580 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12582 struct glyph_row
*row
;
12583 struct glyph_matrix
*matrix
;
12584 int delta
, delta_bytes
, dy
, dvpos
;
12586 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12587 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12588 struct glyph
*cursor
= NULL
;
12589 /* The last known character position in row. */
12590 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12593 EMACS_INT pt_old
= PT
- delta
;
12594 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12595 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12596 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12597 /* Non-zero means we've found a match for cursor position, but that
12598 glyph has the avoid_cursor_p flag set. */
12599 int match_with_avoid_cursor
= 0;
12600 /* Non-zero means we've seen at least one glyph that came from a
12602 int string_seen
= 0;
12603 /* Largest buffer position seen so far during scan of glyph row. */
12604 EMACS_INT bpos_max
= last_pos
;
12605 /* Last buffer position covered by an overlay string with an integer
12606 `cursor' property. */
12607 EMACS_INT bpos_covered
= 0;
12609 /* Skip over glyphs not having an object at the start and the end of
12610 the row. These are special glyphs like truncation marks on
12611 terminal frames. */
12612 if (row
->displays_text_p
)
12614 if (!row
->reversed_p
)
12617 && INTEGERP (glyph
->object
)
12618 && glyph
->charpos
< 0)
12620 x
+= glyph
->pixel_width
;
12624 && INTEGERP ((end
- 1)->object
)
12625 /* CHARPOS is zero for blanks inserted by
12626 extend_face_to_end_of_line. */
12627 && (end
- 1)->charpos
<= 0)
12629 glyph_before
= glyph
- 1;
12636 /* If the glyph row is reversed, we need to process it from back
12637 to front, so swap the edge pointers. */
12639 glyph
+= row
->used
[TEXT_AREA
] - 1;
12640 /* Reverse the known positions in the row. */
12641 last_pos
= pos_after
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12642 pos_before
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12644 while (glyph
> end
+ 1
12645 && INTEGERP (glyph
->object
)
12646 && glyph
->charpos
< 0)
12649 x
-= glyph
->pixel_width
;
12651 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12653 /* By default, put the cursor on the rightmost glyph. */
12654 for (g
= end
+ 1; g
< glyph
; g
++)
12655 x
+= g
->pixel_width
;
12658 && INTEGERP ((end
+ 1)->object
)
12659 && (end
+ 1)->charpos
<= 0)
12661 glyph_before
= glyph
+ 1;
12665 else if (row
->reversed_p
)
12667 /* In R2L rows that don't display text, put the cursor on the
12668 rightmost glyph. Case in point: an empty last line that is
12669 part of an R2L paragraph. */
12671 x
= -1; /* will be computed below, at lable compute_x */
12674 /* Step 1: Try to find the glyph whose character position
12675 corresponds to point. If that's not possible, find 2 glyphs
12676 whose character positions are the closest to point, one before
12677 point, the other after it. */
12678 if (!row
->reversed_p
)
12679 while (/* not marched to end of glyph row */
12681 /* glyph was not inserted by redisplay for internal purposes */
12682 && !INTEGERP (glyph
->object
))
12684 if (BUFFERP (glyph
->object
))
12686 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12688 if (glyph
->charpos
> bpos_max
)
12689 bpos_max
= glyph
->charpos
;
12690 if (!glyph
->avoid_cursor_p
)
12692 /* If we hit point, we've found the glyph on which to
12693 display the cursor. */
12696 match_with_avoid_cursor
= 0;
12699 /* See if we've found a better approximation to
12700 POS_BEFORE or to POS_AFTER. Note that we want the
12701 first (leftmost) glyph of all those that are the
12702 closest from below, and the last (rightmost) of all
12703 those from above. */
12704 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12706 pos_before
= glyph
->charpos
;
12707 glyph_before
= glyph
;
12709 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12711 pos_after
= glyph
->charpos
;
12712 glyph_after
= glyph
;
12715 else if (dpos
== 0)
12716 match_with_avoid_cursor
= 1;
12718 else if (STRINGP (glyph
->object
))
12720 Lisp_Object chprop
;
12721 int glyph_pos
= glyph
->charpos
;
12723 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12725 if (INTEGERP (chprop
))
12727 bpos_covered
= bpos_max
+ XINT (chprop
);
12728 /* If the `cursor' property covers buffer positions up
12729 to and including point, we should display cursor on
12731 /* Implementation note: bpos_max == pt_old when, e.g.,
12732 we are in an empty line, where bpos_max is set to
12733 MATRIX_ROW_START_CHARPOS, see above. */
12734 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12743 x
+= glyph
->pixel_width
;
12746 else if (glyph
> end
) /* row is reversed */
12747 while (!INTEGERP (glyph
->object
))
12749 if (BUFFERP (glyph
->object
))
12751 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12753 if (glyph
->charpos
> bpos_max
)
12754 bpos_max
= glyph
->charpos
;
12755 if (!glyph
->avoid_cursor_p
)
12759 match_with_avoid_cursor
= 0;
12762 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12764 pos_before
= glyph
->charpos
;
12765 glyph_before
= glyph
;
12767 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12769 pos_after
= glyph
->charpos
;
12770 glyph_after
= glyph
;
12773 else if (dpos
== 0)
12774 match_with_avoid_cursor
= 1;
12776 else if (STRINGP (glyph
->object
))
12778 Lisp_Object chprop
;
12779 int glyph_pos
= glyph
->charpos
;
12781 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12783 if (INTEGERP (chprop
))
12785 bpos_covered
= bpos_max
+ XINT (chprop
);
12786 /* If the `cursor' property covers buffer positions up
12787 to and including point, we should display cursor on
12789 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12800 x
-= glyph
->pixel_width
;
12803 /* Step 2: If we didn't find an exact match for point, we need to
12804 look for a proper place to put the cursor among glyphs between
12805 GLYPH_BEFORE and GLYPH_AFTER. */
12806 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12807 && bpos_covered
< pt_old
)
12809 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12811 EMACS_INT ellipsis_pos
;
12813 /* Scan back over the ellipsis glyphs. */
12814 if (!row
->reversed_p
)
12816 ellipsis_pos
= (glyph
- 1)->charpos
;
12817 while (glyph
> row
->glyphs
[TEXT_AREA
]
12818 && (glyph
- 1)->charpos
== ellipsis_pos
)
12819 glyph
--, x
-= glyph
->pixel_width
;
12820 /* That loop always goes one position too far, including
12821 the glyph before the ellipsis. So scan forward over
12823 x
+= glyph
->pixel_width
;
12826 else /* row is reversed */
12828 ellipsis_pos
= (glyph
+ 1)->charpos
;
12829 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12830 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12831 glyph
++, x
+= glyph
->pixel_width
;
12832 x
-= glyph
->pixel_width
;
12836 else if (match_with_avoid_cursor
12837 /* zero-width characters produce no glyphs */
12838 || eabs (glyph_after
- glyph_before
) == 1)
12840 cursor
= glyph_after
;
12843 else if (string_seen
)
12845 int incr
= row
->reversed_p
? -1 : +1;
12847 /* Need to find the glyph that came out of a string which is
12848 present at point. That glyph is somewhere between
12849 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12850 positioned between POS_BEFORE and POS_AFTER in the
12852 struct glyph
*stop
= glyph_after
;
12853 EMACS_INT pos
= pos_before
;
12856 for (glyph
= glyph_before
+ incr
;
12857 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12860 /* Any glyphs that come from the buffer are here because
12861 of bidi reordering. Skip them, and only pay
12862 attention to glyphs that came from some string. */
12863 if (STRINGP (glyph
->object
))
12868 str
= glyph
->object
;
12869 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12872 /* If the string from which this glyph came is
12873 found in the buffer at point, then we've
12874 found the glyph we've been looking for. */
12877 /* The glyphs from this string could have
12878 been reordered. Find the one with the
12879 smallest string position. Or there could
12880 be a character in the string with the
12881 `cursor' property, which means display
12882 cursor on that character's glyph. */
12883 int strpos
= glyph
->charpos
;
12886 for (glyph
+= incr
;
12887 EQ (glyph
->object
, str
);
12891 int gpos
= glyph
->charpos
;
12893 cprop
= Fget_char_property (make_number (gpos
),
12901 if (glyph
->charpos
< strpos
)
12903 strpos
= glyph
->charpos
;
12910 pos
= tem
+ 1; /* don't find previous instances */
12912 /* This string is not what we want; skip all of the
12913 glyphs that came from it. */
12916 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12917 && EQ (glyph
->object
, str
));
12923 /* If we reached the end of the line, and END was from a string,
12924 the cursor is not on this line. */
12926 && STRINGP ((glyph
- incr
)->object
)
12927 && row
->continued_p
)
12933 if (cursor
!= NULL
)
12939 /* Need to compute x that corresponds to GLYPH. */
12940 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12942 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12944 x
+= g
->pixel_width
;
12948 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12950 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12951 w
->cursor
.y
= row
->y
+ dy
;
12953 if (w
== XWINDOW (selected_window
))
12955 if (!row
->continued_p
12956 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12959 this_line_buffer
= XBUFFER (w
->buffer
);
12961 CHARPOS (this_line_start_pos
)
12962 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12963 BYTEPOS (this_line_start_pos
)
12964 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12966 CHARPOS (this_line_end_pos
)
12967 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12968 BYTEPOS (this_line_end_pos
)
12969 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12971 this_line_y
= w
->cursor
.y
;
12972 this_line_pixel_height
= row
->height
;
12973 this_line_vpos
= w
->cursor
.vpos
;
12974 this_line_start_x
= row
->x
;
12977 CHARPOS (this_line_start_pos
) = 0;
12984 /* Run window scroll functions, if any, for WINDOW with new window
12985 start STARTP. Sets the window start of WINDOW to that position.
12987 We assume that the window's buffer is really current. */
12989 static INLINE
struct text_pos
12990 run_window_scroll_functions (window
, startp
)
12991 Lisp_Object window
;
12992 struct text_pos startp
;
12994 struct window
*w
= XWINDOW (window
);
12995 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12997 if (current_buffer
!= XBUFFER (w
->buffer
))
13000 if (!NILP (Vwindow_scroll_functions
))
13002 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13003 make_number (CHARPOS (startp
)));
13004 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13005 /* In case the hook functions switch buffers. */
13006 if (current_buffer
!= XBUFFER (w
->buffer
))
13007 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13014 /* Make sure the line containing the cursor is fully visible.
13015 A value of 1 means there is nothing to be done.
13016 (Either the line is fully visible, or it cannot be made so,
13017 or we cannot tell.)
13019 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13020 is higher than window.
13022 A value of 0 means the caller should do scrolling
13023 as if point had gone off the screen. */
13026 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
13029 int current_matrix_p
;
13031 struct glyph_matrix
*matrix
;
13032 struct glyph_row
*row
;
13035 if (!make_cursor_line_fully_visible_p
)
13038 /* It's not always possible to find the cursor, e.g, when a window
13039 is full of overlay strings. Don't do anything in that case. */
13040 if (w
->cursor
.vpos
< 0)
13043 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13044 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13046 /* If the cursor row is not partially visible, there's nothing to do. */
13047 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13050 /* If the row the cursor is in is taller than the window's height,
13051 it's not clear what to do, so do nothing. */
13052 window_height
= window_box_height (w
);
13053 if (row
->height
>= window_height
)
13055 if (!force_p
|| MINI_WINDOW_P (w
)
13056 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13063 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13064 non-zero means only WINDOW is redisplayed in redisplay_internal.
13065 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13066 in redisplay_window to bring a partially visible line into view in
13067 the case that only the cursor has moved.
13069 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13070 last screen line's vertical height extends past the end of the screen.
13074 1 if scrolling succeeded
13076 0 if scrolling didn't find point.
13078 -1 if new fonts have been loaded so that we must interrupt
13079 redisplay, adjust glyph matrices, and try again. */
13085 SCROLLING_NEED_LARGER_MATRICES
13089 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
13090 scroll_step
, temp_scroll_step
, last_line_misfit
)
13091 Lisp_Object window
;
13092 int just_this_one_p
;
13093 EMACS_INT scroll_conservatively
, scroll_step
;
13094 int temp_scroll_step
;
13095 int last_line_misfit
;
13097 struct window
*w
= XWINDOW (window
);
13098 struct frame
*f
= XFRAME (w
->frame
);
13099 struct text_pos pos
, startp
;
13101 int this_scroll_margin
, scroll_max
, rc
, height
;
13102 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13103 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13104 Lisp_Object aggressive
;
13105 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13108 debug_method_add (w
, "try_scrolling");
13111 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13113 /* Compute scroll margin height in pixels. We scroll when point is
13114 within this distance from the top or bottom of the window. */
13115 if (scroll_margin
> 0)
13116 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13117 * FRAME_LINE_HEIGHT (f
);
13119 this_scroll_margin
= 0;
13121 /* Force scroll_conservatively to have a reasonable value, to avoid
13122 overflow while computing how much to scroll. Note that the user
13123 can supply scroll-conservatively equal to `most-positive-fixnum',
13124 which can be larger than INT_MAX. */
13125 if (scroll_conservatively
> scroll_limit
)
13127 scroll_conservatively
= scroll_limit
;
13128 scroll_max
= INT_MAX
;
13130 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13131 /* Compute how much we should try to scroll maximally to bring
13132 point into view. */
13133 scroll_max
= (max (scroll_step
,
13134 max (scroll_conservatively
, temp_scroll_step
))
13135 * FRAME_LINE_HEIGHT (f
));
13136 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13137 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13138 /* We're trying to scroll because of aggressive scrolling but no
13139 scroll_step is set. Choose an arbitrary one. */
13140 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13146 /* Decide whether to scroll down. */
13147 if (PT
> CHARPOS (startp
))
13149 int scroll_margin_y
;
13151 /* Compute the pixel ypos of the scroll margin, then move it to
13152 either that ypos or PT, whichever comes first. */
13153 start_display (&it
, w
, startp
);
13154 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13155 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13156 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13157 (MOVE_TO_POS
| MOVE_TO_Y
));
13159 if (PT
> CHARPOS (it
.current
.pos
))
13161 int y0
= line_bottom_y (&it
);
13163 /* Compute the distance from the scroll margin to PT
13164 (including the height of the cursor line). Moving the
13165 iterator unconditionally to PT can be slow if PT is far
13166 away, so stop 10 lines past the window bottom (is there a
13167 way to do the right thing quickly?). */
13168 move_it_to (&it
, PT
, -1,
13169 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
13170 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13171 dy
= line_bottom_y (&it
) - y0
;
13173 if (dy
> scroll_max
)
13174 return SCROLLING_FAILED
;
13182 /* Point is in or below the bottom scroll margin, so move the
13183 window start down. If scrolling conservatively, move it just
13184 enough down to make point visible. If scroll_step is set,
13185 move it down by scroll_step. */
13186 if (scroll_conservatively
)
13188 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13189 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13190 else if (scroll_step
|| temp_scroll_step
)
13191 amount_to_scroll
= scroll_max
;
13194 aggressive
= current_buffer
->scroll_up_aggressively
;
13195 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13196 if (NUMBERP (aggressive
))
13198 double float_amount
= XFLOATINT (aggressive
) * height
;
13199 amount_to_scroll
= float_amount
;
13200 if (amount_to_scroll
== 0 && float_amount
> 0)
13201 amount_to_scroll
= 1;
13205 if (amount_to_scroll
<= 0)
13206 return SCROLLING_FAILED
;
13208 start_display (&it
, w
, startp
);
13209 move_it_vertically (&it
, amount_to_scroll
);
13211 /* If STARTP is unchanged, move it down another screen line. */
13212 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13213 move_it_by_lines (&it
, 1, 1);
13214 startp
= it
.current
.pos
;
13218 struct text_pos scroll_margin_pos
= startp
;
13220 /* See if point is inside the scroll margin at the top of the
13222 if (this_scroll_margin
)
13224 start_display (&it
, w
, startp
);
13225 move_it_vertically (&it
, this_scroll_margin
);
13226 scroll_margin_pos
= it
.current
.pos
;
13229 if (PT
< CHARPOS (scroll_margin_pos
))
13231 /* Point is in the scroll margin at the top of the window or
13232 above what is displayed in the window. */
13235 /* Compute the vertical distance from PT to the scroll
13236 margin position. Give up if distance is greater than
13238 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13239 start_display (&it
, w
, pos
);
13241 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13242 it
.last_visible_y
, -1,
13243 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13244 dy
= it
.current_y
- y0
;
13245 if (dy
> scroll_max
)
13246 return SCROLLING_FAILED
;
13248 /* Compute new window start. */
13249 start_display (&it
, w
, startp
);
13251 if (scroll_conservatively
)
13253 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13254 else if (scroll_step
|| temp_scroll_step
)
13255 amount_to_scroll
= scroll_max
;
13258 aggressive
= current_buffer
->scroll_down_aggressively
;
13259 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13260 if (NUMBERP (aggressive
))
13262 double float_amount
= XFLOATINT (aggressive
) * height
;
13263 amount_to_scroll
= float_amount
;
13264 if (amount_to_scroll
== 0 && float_amount
> 0)
13265 amount_to_scroll
= 1;
13269 if (amount_to_scroll
<= 0)
13270 return SCROLLING_FAILED
;
13272 move_it_vertically_backward (&it
, amount_to_scroll
);
13273 startp
= it
.current
.pos
;
13277 /* Run window scroll functions. */
13278 startp
= run_window_scroll_functions (window
, startp
);
13280 /* Display the window. Give up if new fonts are loaded, or if point
13282 if (!try_window (window
, startp
, 0))
13283 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13284 else if (w
->cursor
.vpos
< 0)
13286 clear_glyph_matrix (w
->desired_matrix
);
13287 rc
= SCROLLING_FAILED
;
13291 /* Maybe forget recorded base line for line number display. */
13292 if (!just_this_one_p
13293 || current_buffer
->clip_changed
13294 || BEG_UNCHANGED
< CHARPOS (startp
))
13295 w
->base_line_number
= Qnil
;
13297 /* If cursor ends up on a partially visible line,
13298 treat that as being off the bottom of the screen. */
13299 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13301 clear_glyph_matrix (w
->desired_matrix
);
13302 ++extra_scroll_margin_lines
;
13305 rc
= SCROLLING_SUCCESS
;
13312 /* Compute a suitable window start for window W if display of W starts
13313 on a continuation line. Value is non-zero if a new window start
13316 The new window start will be computed, based on W's width, starting
13317 from the start of the continued line. It is the start of the
13318 screen line with the minimum distance from the old start W->start. */
13321 compute_window_start_on_continuation_line (w
)
13324 struct text_pos pos
, start_pos
;
13325 int window_start_changed_p
= 0;
13327 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13329 /* If window start is on a continuation line... Window start may be
13330 < BEGV in case there's invisible text at the start of the
13331 buffer (M-x rmail, for example). */
13332 if (CHARPOS (start_pos
) > BEGV
13333 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13336 struct glyph_row
*row
;
13338 /* Handle the case that the window start is out of range. */
13339 if (CHARPOS (start_pos
) < BEGV
)
13340 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13341 else if (CHARPOS (start_pos
) > ZV
)
13342 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13344 /* Find the start of the continued line. This should be fast
13345 because scan_buffer is fast (newline cache). */
13346 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13347 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13348 row
, DEFAULT_FACE_ID
);
13349 reseat_at_previous_visible_line_start (&it
);
13351 /* If the line start is "too far" away from the window start,
13352 say it takes too much time to compute a new window start. */
13353 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13354 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13356 int min_distance
, distance
;
13358 /* Move forward by display lines to find the new window
13359 start. If window width was enlarged, the new start can
13360 be expected to be > the old start. If window width was
13361 decreased, the new window start will be < the old start.
13362 So, we're looking for the display line start with the
13363 minimum distance from the old window start. */
13364 pos
= it
.current
.pos
;
13365 min_distance
= INFINITY
;
13366 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13367 distance
< min_distance
)
13369 min_distance
= distance
;
13370 pos
= it
.current
.pos
;
13371 move_it_by_lines (&it
, 1, 0);
13374 /* Set the window start there. */
13375 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13376 window_start_changed_p
= 1;
13380 return window_start_changed_p
;
13384 /* Try cursor movement in case text has not changed in window WINDOW,
13385 with window start STARTP. Value is
13387 CURSOR_MOVEMENT_SUCCESS if successful
13389 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13391 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13392 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13393 we want to scroll as if scroll-step were set to 1. See the code.
13395 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13396 which case we have to abort this redisplay, and adjust matrices
13401 CURSOR_MOVEMENT_SUCCESS
,
13402 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13403 CURSOR_MOVEMENT_MUST_SCROLL
,
13404 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13408 try_cursor_movement (window
, startp
, scroll_step
)
13409 Lisp_Object window
;
13410 struct text_pos startp
;
13413 struct window
*w
= XWINDOW (window
);
13414 struct frame
*f
= XFRAME (w
->frame
);
13415 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13418 if (inhibit_try_cursor_movement
)
13422 /* Handle case where text has not changed, only point, and it has
13423 not moved off the frame. */
13424 if (/* Point may be in this window. */
13425 PT
>= CHARPOS (startp
)
13426 /* Selective display hasn't changed. */
13427 && !current_buffer
->clip_changed
13428 /* Function force-mode-line-update is used to force a thorough
13429 redisplay. It sets either windows_or_buffers_changed or
13430 update_mode_lines. So don't take a shortcut here for these
13432 && !update_mode_lines
13433 && !windows_or_buffers_changed
13434 && !cursor_type_changed
13435 /* Can't use this case if highlighting a region. When a
13436 region exists, cursor movement has to do more than just
13438 && !(!NILP (Vtransient_mark_mode
)
13439 && !NILP (current_buffer
->mark_active
))
13440 && NILP (w
->region_showing
)
13441 && NILP (Vshow_trailing_whitespace
)
13442 /* Right after splitting windows, last_point may be nil. */
13443 && INTEGERP (w
->last_point
)
13444 /* This code is not used for mini-buffer for the sake of the case
13445 of redisplaying to replace an echo area message; since in
13446 that case the mini-buffer contents per se are usually
13447 unchanged. This code is of no real use in the mini-buffer
13448 since the handling of this_line_start_pos, etc., in redisplay
13449 handles the same cases. */
13450 && !EQ (window
, minibuf_window
)
13451 /* When splitting windows or for new windows, it happens that
13452 redisplay is called with a nil window_end_vpos or one being
13453 larger than the window. This should really be fixed in
13454 window.c. I don't have this on my list, now, so we do
13455 approximately the same as the old redisplay code. --gerd. */
13456 && INTEGERP (w
->window_end_vpos
)
13457 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13458 && (FRAME_WINDOW_P (f
)
13459 || !overlay_arrow_in_current_buffer_p ()))
13461 int this_scroll_margin
, top_scroll_margin
;
13462 struct glyph_row
*row
= NULL
;
13465 debug_method_add (w
, "cursor movement");
13468 /* Scroll if point within this distance from the top or bottom
13469 of the window. This is a pixel value. */
13470 if (scroll_margin
> 0)
13472 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13473 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13476 this_scroll_margin
= 0;
13478 top_scroll_margin
= this_scroll_margin
;
13479 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13480 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13482 /* Start with the row the cursor was displayed during the last
13483 not paused redisplay. Give up if that row is not valid. */
13484 if (w
->last_cursor
.vpos
< 0
13485 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13486 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13489 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13490 if (row
->mode_line_p
)
13492 if (!row
->enabled_p
)
13493 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13496 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13499 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13501 if (PT
> XFASTINT (w
->last_point
))
13503 /* Point has moved forward. */
13504 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13505 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13507 xassert (row
->enabled_p
);
13511 /* The end position of a row equals the start position
13512 of the next row. If PT is there, we would rather
13513 display it in the next line. */
13514 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13515 && MATRIX_ROW_END_CHARPOS (row
) == PT
13516 && !cursor_row_p (w
, row
))
13519 /* If within the scroll margin, scroll. Note that
13520 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13521 the next line would be drawn, and that
13522 this_scroll_margin can be zero. */
13523 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13524 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13525 /* Line is completely visible last line in window
13526 and PT is to be set in the next line. */
13527 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13528 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13529 && !row
->ends_at_zv_p
13530 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13533 else if (PT
< XFASTINT (w
->last_point
))
13535 /* Cursor has to be moved backward. Note that PT >=
13536 CHARPOS (startp) because of the outer if-statement. */
13537 while (!row
->mode_line_p
13538 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13539 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13540 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13541 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13542 row
> w
->current_matrix
->rows
13543 && (row
-1)->ends_in_newline_from_string_p
))))
13544 && (row
->y
> top_scroll_margin
13545 || CHARPOS (startp
) == BEGV
))
13547 xassert (row
->enabled_p
);
13551 /* Consider the following case: Window starts at BEGV,
13552 there is invisible, intangible text at BEGV, so that
13553 display starts at some point START > BEGV. It can
13554 happen that we are called with PT somewhere between
13555 BEGV and START. Try to handle that case. */
13556 if (row
< w
->current_matrix
->rows
13557 || row
->mode_line_p
)
13559 row
= w
->current_matrix
->rows
;
13560 if (row
->mode_line_p
)
13564 /* Due to newlines in overlay strings, we may have to
13565 skip forward over overlay strings. */
13566 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13567 && MATRIX_ROW_END_CHARPOS (row
) == PT
13568 && !cursor_row_p (w
, row
))
13571 /* If within the scroll margin, scroll. */
13572 if (row
->y
< top_scroll_margin
13573 && CHARPOS (startp
) != BEGV
)
13578 /* Cursor did not move. So don't scroll even if cursor line
13579 is partially visible, as it was so before. */
13580 rc
= CURSOR_MOVEMENT_SUCCESS
;
13583 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13584 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13586 /* if PT is not in the glyph row, give up. */
13587 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13589 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13590 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13591 && make_cursor_line_fully_visible_p
)
13593 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13594 && !row
->ends_at_zv_p
13595 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13596 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13597 else if (row
->height
> window_box_height (w
))
13599 /* If we end up in a partially visible line, let's
13600 make it fully visible, except when it's taller
13601 than the window, in which case we can't do much
13604 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13608 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13609 if (!cursor_row_fully_visible_p (w
, 0, 1))
13610 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13612 rc
= CURSOR_MOVEMENT_SUCCESS
;
13616 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13621 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13623 rc
= CURSOR_MOVEMENT_SUCCESS
;
13628 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13629 && MATRIX_ROW_START_CHARPOS (row
) == PT
13630 && cursor_row_p (w
, row
));
13639 set_vertical_scroll_bar (w
)
13642 int start
, end
, whole
;
13644 /* Calculate the start and end positions for the current window.
13645 At some point, it would be nice to choose between scrollbars
13646 which reflect the whole buffer size, with special markers
13647 indicating narrowing, and scrollbars which reflect only the
13650 Note that mini-buffers sometimes aren't displaying any text. */
13651 if (!MINI_WINDOW_P (w
)
13652 || (w
== XWINDOW (minibuf_window
)
13653 && NILP (echo_area_buffer
[0])))
13655 struct buffer
*buf
= XBUFFER (w
->buffer
);
13656 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13657 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13658 /* I don't think this is guaranteed to be right. For the
13659 moment, we'll pretend it is. */
13660 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13664 if (whole
< (end
- start
))
13665 whole
= end
- start
;
13668 start
= end
= whole
= 0;
13670 /* Indicate what this scroll bar ought to be displaying now. */
13671 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13672 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13673 (w
, end
- start
, whole
, start
);
13677 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13678 selected_window is redisplayed.
13680 We can return without actually redisplaying the window if
13681 fonts_changed_p is nonzero. In that case, redisplay_internal will
13685 redisplay_window (window
, just_this_one_p
)
13686 Lisp_Object window
;
13687 int just_this_one_p
;
13689 struct window
*w
= XWINDOW (window
);
13690 struct frame
*f
= XFRAME (w
->frame
);
13691 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13692 struct buffer
*old
= current_buffer
;
13693 struct text_pos lpoint
, opoint
, startp
;
13694 int update_mode_line
;
13697 /* Record it now because it's overwritten. */
13698 int current_matrix_up_to_date_p
= 0;
13699 int used_current_matrix_p
= 0;
13700 /* This is less strict than current_matrix_up_to_date_p.
13701 It indictes that the buffer contents and narrowing are unchanged. */
13702 int buffer_unchanged_p
= 0;
13703 int temp_scroll_step
= 0;
13704 int count
= SPECPDL_INDEX ();
13706 int centering_position
= -1;
13707 int last_line_misfit
= 0;
13708 int beg_unchanged
, end_unchanged
;
13710 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13713 /* W must be a leaf window here. */
13714 xassert (!NILP (w
->buffer
));
13716 *w
->desired_matrix
->method
= 0;
13720 reconsider_clip_changes (w
, buffer
);
13722 /* Has the mode line to be updated? */
13723 update_mode_line
= (!NILP (w
->update_mode_line
)
13724 || update_mode_lines
13725 || buffer
->clip_changed
13726 || buffer
->prevent_redisplay_optimizations_p
);
13728 if (MINI_WINDOW_P (w
))
13730 if (w
== XWINDOW (echo_area_window
)
13731 && !NILP (echo_area_buffer
[0]))
13733 if (update_mode_line
)
13734 /* We may have to update a tty frame's menu bar or a
13735 tool-bar. Example `M-x C-h C-h C-g'. */
13736 goto finish_menu_bars
;
13738 /* We've already displayed the echo area glyphs in this window. */
13739 goto finish_scroll_bars
;
13741 else if ((w
!= XWINDOW (minibuf_window
)
13742 || minibuf_level
== 0)
13743 /* When buffer is nonempty, redisplay window normally. */
13744 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13745 /* Quail displays non-mini buffers in minibuffer window.
13746 In that case, redisplay the window normally. */
13747 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13749 /* W is a mini-buffer window, but it's not active, so clear
13751 int yb
= window_text_bottom_y (w
);
13752 struct glyph_row
*row
;
13755 for (y
= 0, row
= w
->desired_matrix
->rows
;
13757 y
+= row
->height
, ++row
)
13758 blank_row (w
, row
, y
);
13759 goto finish_scroll_bars
;
13762 clear_glyph_matrix (w
->desired_matrix
);
13765 /* Otherwise set up data on this window; select its buffer and point
13767 /* Really select the buffer, for the sake of buffer-local
13769 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13771 current_matrix_up_to_date_p
13772 = (!NILP (w
->window_end_valid
)
13773 && !current_buffer
->clip_changed
13774 && !current_buffer
->prevent_redisplay_optimizations_p
13775 && XFASTINT (w
->last_modified
) >= MODIFF
13776 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13778 /* Run the window-bottom-change-functions
13779 if it is possible that the text on the screen has changed
13780 (either due to modification of the text, or any other reason). */
13781 if (!current_matrix_up_to_date_p
13782 && !NILP (Vwindow_text_change_functions
))
13784 safe_run_hooks (Qwindow_text_change_functions
);
13788 beg_unchanged
= BEG_UNCHANGED
;
13789 end_unchanged
= END_UNCHANGED
;
13791 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13793 specbind (Qinhibit_point_motion_hooks
, Qt
);
13796 = (!NILP (w
->window_end_valid
)
13797 && !current_buffer
->clip_changed
13798 && XFASTINT (w
->last_modified
) >= MODIFF
13799 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13801 /* When windows_or_buffers_changed is non-zero, we can't rely on
13802 the window end being valid, so set it to nil there. */
13803 if (windows_or_buffers_changed
)
13805 /* If window starts on a continuation line, maybe adjust the
13806 window start in case the window's width changed. */
13807 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13808 compute_window_start_on_continuation_line (w
);
13810 w
->window_end_valid
= Qnil
;
13813 /* Some sanity checks. */
13814 CHECK_WINDOW_END (w
);
13815 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13817 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13820 /* If %c is in mode line, update it if needed. */
13821 if (!NILP (w
->column_number_displayed
)
13822 /* This alternative quickly identifies a common case
13823 where no change is needed. */
13824 && !(PT
== XFASTINT (w
->last_point
)
13825 && XFASTINT (w
->last_modified
) >= MODIFF
13826 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13827 && (XFASTINT (w
->column_number_displayed
)
13828 != (int) current_column ())) /* iftc */
13829 update_mode_line
= 1;
13831 /* Count number of windows showing the selected buffer. An indirect
13832 buffer counts as its base buffer. */
13833 if (!just_this_one_p
)
13835 struct buffer
*current_base
, *window_base
;
13836 current_base
= current_buffer
;
13837 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13838 if (current_base
->base_buffer
)
13839 current_base
= current_base
->base_buffer
;
13840 if (window_base
->base_buffer
)
13841 window_base
= window_base
->base_buffer
;
13842 if (current_base
== window_base
)
13846 /* Point refers normally to the selected window. For any other
13847 window, set up appropriate value. */
13848 if (!EQ (window
, selected_window
))
13850 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13851 int new_pt_byte
= marker_byte_position (w
->pointm
);
13855 new_pt_byte
= BEGV_BYTE
;
13856 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13858 else if (new_pt
> (ZV
- 1))
13861 new_pt_byte
= ZV_BYTE
;
13862 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13865 /* We don't use SET_PT so that the point-motion hooks don't run. */
13866 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13869 /* If any of the character widths specified in the display table
13870 have changed, invalidate the width run cache. It's true that
13871 this may be a bit late to catch such changes, but the rest of
13872 redisplay goes (non-fatally) haywire when the display table is
13873 changed, so why should we worry about doing any better? */
13874 if (current_buffer
->width_run_cache
)
13876 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13878 if (! disptab_matches_widthtab (disptab
,
13879 XVECTOR (current_buffer
->width_table
)))
13881 invalidate_region_cache (current_buffer
,
13882 current_buffer
->width_run_cache
,
13884 recompute_width_table (current_buffer
, disptab
);
13888 /* If window-start is screwed up, choose a new one. */
13889 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13892 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13894 /* If someone specified a new starting point but did not insist,
13895 check whether it can be used. */
13896 if (!NILP (w
->optional_new_start
)
13897 && CHARPOS (startp
) >= BEGV
13898 && CHARPOS (startp
) <= ZV
)
13900 w
->optional_new_start
= Qnil
;
13901 start_display (&it
, w
, startp
);
13902 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13903 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13904 if (IT_CHARPOS (it
) == PT
)
13905 w
->force_start
= Qt
;
13906 /* IT may overshoot PT if text at PT is invisible. */
13907 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13908 w
->force_start
= Qt
;
13913 /* Handle case where place to start displaying has been specified,
13914 unless the specified location is outside the accessible range. */
13915 if (!NILP (w
->force_start
)
13916 || w
->frozen_window_start_p
)
13918 /* We set this later on if we have to adjust point. */
13921 w
->force_start
= Qnil
;
13923 w
->window_end_valid
= Qnil
;
13925 /* Forget any recorded base line for line number display. */
13926 if (!buffer_unchanged_p
)
13927 w
->base_line_number
= Qnil
;
13929 /* Redisplay the mode line. Select the buffer properly for that.
13930 Also, run the hook window-scroll-functions
13931 because we have scrolled. */
13932 /* Note, we do this after clearing force_start because
13933 if there's an error, it is better to forget about force_start
13934 than to get into an infinite loop calling the hook functions
13935 and having them get more errors. */
13936 if (!update_mode_line
13937 || ! NILP (Vwindow_scroll_functions
))
13939 update_mode_line
= 1;
13940 w
->update_mode_line
= Qt
;
13941 startp
= run_window_scroll_functions (window
, startp
);
13944 w
->last_modified
= make_number (0);
13945 w
->last_overlay_modified
= make_number (0);
13946 if (CHARPOS (startp
) < BEGV
)
13947 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13948 else if (CHARPOS (startp
) > ZV
)
13949 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13951 /* Redisplay, then check if cursor has been set during the
13952 redisplay. Give up if new fonts were loaded. */
13953 /* We used to issue a CHECK_MARGINS argument to try_window here,
13954 but this causes scrolling to fail when point begins inside
13955 the scroll margin (bug#148) -- cyd */
13956 if (!try_window (window
, startp
, 0))
13958 w
->force_start
= Qt
;
13959 clear_glyph_matrix (w
->desired_matrix
);
13960 goto need_larger_matrices
;
13963 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13965 /* If point does not appear, try to move point so it does
13966 appear. The desired matrix has been built above, so we
13967 can use it here. */
13968 new_vpos
= window_box_height (w
) / 2;
13971 if (!cursor_row_fully_visible_p (w
, 0, 0))
13973 /* Point does appear, but on a line partly visible at end of window.
13974 Move it back to a fully-visible line. */
13975 new_vpos
= window_box_height (w
);
13978 /* If we need to move point for either of the above reasons,
13979 now actually do it. */
13982 struct glyph_row
*row
;
13984 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13985 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13988 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13989 MATRIX_ROW_START_BYTEPOS (row
));
13991 if (w
!= XWINDOW (selected_window
))
13992 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13993 else if (current_buffer
== old
)
13994 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13996 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13998 /* If we are highlighting the region, then we just changed
13999 the region, so redisplay to show it. */
14000 if (!NILP (Vtransient_mark_mode
)
14001 && !NILP (current_buffer
->mark_active
))
14003 clear_glyph_matrix (w
->desired_matrix
);
14004 if (!try_window (window
, startp
, 0))
14005 goto need_larger_matrices
;
14010 debug_method_add (w
, "forced window start");
14015 /* Handle case where text has not changed, only point, and it has
14016 not moved off the frame, and we are not retrying after hscroll.
14017 (current_matrix_up_to_date_p is nonzero when retrying.) */
14018 if (current_matrix_up_to_date_p
14019 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14020 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14024 case CURSOR_MOVEMENT_SUCCESS
:
14025 used_current_matrix_p
= 1;
14028 case CURSOR_MOVEMENT_MUST_SCROLL
:
14029 goto try_to_scroll
;
14035 /* If current starting point was originally the beginning of a line
14036 but no longer is, find a new starting point. */
14037 else if (!NILP (w
->start_at_line_beg
)
14038 && !(CHARPOS (startp
) <= BEGV
14039 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14042 debug_method_add (w
, "recenter 1");
14047 /* Try scrolling with try_window_id. Value is > 0 if update has
14048 been done, it is -1 if we know that the same window start will
14049 not work. It is 0 if unsuccessful for some other reason. */
14050 else if ((tem
= try_window_id (w
)) != 0)
14053 debug_method_add (w
, "try_window_id %d", tem
);
14056 if (fonts_changed_p
)
14057 goto need_larger_matrices
;
14061 /* Otherwise try_window_id has returned -1 which means that we
14062 don't want the alternative below this comment to execute. */
14064 else if (CHARPOS (startp
) >= BEGV
14065 && CHARPOS (startp
) <= ZV
14066 && PT
>= CHARPOS (startp
)
14067 && (CHARPOS (startp
) < ZV
14068 /* Avoid starting at end of buffer. */
14069 || CHARPOS (startp
) == BEGV
14070 || (XFASTINT (w
->last_modified
) >= MODIFF
14071 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14074 /* If first window line is a continuation line, and window start
14075 is inside the modified region, but the first change is before
14076 current window start, we must select a new window start.
14078 However, if this is the result of a down-mouse event (e.g. by
14079 extending the mouse-drag-overlay), we don't want to select a
14080 new window start, since that would change the position under
14081 the mouse, resulting in an unwanted mouse-movement rather
14082 than a simple mouse-click. */
14083 if (NILP (w
->start_at_line_beg
)
14084 && NILP (do_mouse_tracking
)
14085 && CHARPOS (startp
) > BEGV
14086 && CHARPOS (startp
) > BEG
+ beg_unchanged
14087 && CHARPOS (startp
) <= Z
- end_unchanged
14088 /* Even if w->start_at_line_beg is nil, a new window may
14089 start at a line_beg, since that's how set_buffer_window
14090 sets it. So, we need to check the return value of
14091 compute_window_start_on_continuation_line. (See also
14093 && XMARKER (w
->start
)->buffer
== current_buffer
14094 && compute_window_start_on_continuation_line (w
))
14096 w
->force_start
= Qt
;
14097 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14102 debug_method_add (w
, "same window start");
14105 /* Try to redisplay starting at same place as before.
14106 If point has not moved off frame, accept the results. */
14107 if (!current_matrix_up_to_date_p
14108 /* Don't use try_window_reusing_current_matrix in this case
14109 because a window scroll function can have changed the
14111 || !NILP (Vwindow_scroll_functions
)
14112 || MINI_WINDOW_P (w
)
14113 || !(used_current_matrix_p
14114 = try_window_reusing_current_matrix (w
)))
14116 IF_DEBUG (debug_method_add (w
, "1"));
14117 if (try_window (window
, startp
, 1) < 0)
14118 /* -1 means we need to scroll.
14119 0 means we need new matrices, but fonts_changed_p
14120 is set in that case, so we will detect it below. */
14121 goto try_to_scroll
;
14124 if (fonts_changed_p
)
14125 goto need_larger_matrices
;
14127 if (w
->cursor
.vpos
>= 0)
14129 if (!just_this_one_p
14130 || current_buffer
->clip_changed
14131 || BEG_UNCHANGED
< CHARPOS (startp
))
14132 /* Forget any recorded base line for line number display. */
14133 w
->base_line_number
= Qnil
;
14135 if (!cursor_row_fully_visible_p (w
, 1, 0))
14137 clear_glyph_matrix (w
->desired_matrix
);
14138 last_line_misfit
= 1;
14140 /* Drop through and scroll. */
14145 clear_glyph_matrix (w
->desired_matrix
);
14150 w
->last_modified
= make_number (0);
14151 w
->last_overlay_modified
= make_number (0);
14153 /* Redisplay the mode line. Select the buffer properly for that. */
14154 if (!update_mode_line
)
14156 update_mode_line
= 1;
14157 w
->update_mode_line
= Qt
;
14160 /* Try to scroll by specified few lines. */
14161 if ((scroll_conservatively
14163 || temp_scroll_step
14164 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14165 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14166 && !current_buffer
->clip_changed
14167 && CHARPOS (startp
) >= BEGV
14168 && CHARPOS (startp
) <= ZV
)
14170 /* The function returns -1 if new fonts were loaded, 1 if
14171 successful, 0 if not successful. */
14172 int rc
= try_scrolling (window
, just_this_one_p
,
14173 scroll_conservatively
,
14175 temp_scroll_step
, last_line_misfit
);
14178 case SCROLLING_SUCCESS
:
14181 case SCROLLING_NEED_LARGER_MATRICES
:
14182 goto need_larger_matrices
;
14184 case SCROLLING_FAILED
:
14192 /* Finally, just choose place to start which centers point */
14195 if (centering_position
< 0)
14196 centering_position
= window_box_height (w
) / 2;
14199 debug_method_add (w
, "recenter");
14202 /* w->vscroll = 0; */
14204 /* Forget any previously recorded base line for line number display. */
14205 if (!buffer_unchanged_p
)
14206 w
->base_line_number
= Qnil
;
14208 /* Move backward half the height of the window. */
14209 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14210 it
.current_y
= it
.last_visible_y
;
14211 move_it_vertically_backward (&it
, centering_position
);
14212 xassert (IT_CHARPOS (it
) >= BEGV
);
14214 /* The function move_it_vertically_backward may move over more
14215 than the specified y-distance. If it->w is small, e.g. a
14216 mini-buffer window, we may end up in front of the window's
14217 display area. Start displaying at the start of the line
14218 containing PT in this case. */
14219 if (it
.current_y
<= 0)
14221 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14222 move_it_vertically_backward (&it
, 0);
14226 it
.current_x
= it
.hpos
= 0;
14228 /* Set startp here explicitly in case that helps avoid an infinite loop
14229 in case the window-scroll-functions functions get errors. */
14230 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14232 /* Run scroll hooks. */
14233 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14235 /* Redisplay the window. */
14236 if (!current_matrix_up_to_date_p
14237 || windows_or_buffers_changed
14238 || cursor_type_changed
14239 /* Don't use try_window_reusing_current_matrix in this case
14240 because it can have changed the buffer. */
14241 || !NILP (Vwindow_scroll_functions
)
14242 || !just_this_one_p
14243 || MINI_WINDOW_P (w
)
14244 || !(used_current_matrix_p
14245 = try_window_reusing_current_matrix (w
)))
14246 try_window (window
, startp
, 0);
14248 /* If new fonts have been loaded (due to fontsets), give up. We
14249 have to start a new redisplay since we need to re-adjust glyph
14251 if (fonts_changed_p
)
14252 goto need_larger_matrices
;
14254 /* If cursor did not appear assume that the middle of the window is
14255 in the first line of the window. Do it again with the next line.
14256 (Imagine a window of height 100, displaying two lines of height
14257 60. Moving back 50 from it->last_visible_y will end in the first
14259 if (w
->cursor
.vpos
< 0)
14261 if (!NILP (w
->window_end_valid
)
14262 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14264 clear_glyph_matrix (w
->desired_matrix
);
14265 move_it_by_lines (&it
, 1, 0);
14266 try_window (window
, it
.current
.pos
, 0);
14268 else if (PT
< IT_CHARPOS (it
))
14270 clear_glyph_matrix (w
->desired_matrix
);
14271 move_it_by_lines (&it
, -1, 0);
14272 try_window (window
, it
.current
.pos
, 0);
14276 /* Not much we can do about it. */
14280 /* Consider the following case: Window starts at BEGV, there is
14281 invisible, intangible text at BEGV, so that display starts at
14282 some point START > BEGV. It can happen that we are called with
14283 PT somewhere between BEGV and START. Try to handle that case. */
14284 if (w
->cursor
.vpos
< 0)
14286 struct glyph_row
*row
= w
->current_matrix
->rows
;
14287 if (row
->mode_line_p
)
14289 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14292 if (!cursor_row_fully_visible_p (w
, 0, 0))
14294 /* If vscroll is enabled, disable it and try again. */
14298 clear_glyph_matrix (w
->desired_matrix
);
14302 /* If centering point failed to make the whole line visible,
14303 put point at the top instead. That has to make the whole line
14304 visible, if it can be done. */
14305 if (centering_position
== 0)
14308 clear_glyph_matrix (w
->desired_matrix
);
14309 centering_position
= 0;
14315 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14316 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14317 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14320 /* Display the mode line, if we must. */
14321 if ((update_mode_line
14322 /* If window not full width, must redo its mode line
14323 if (a) the window to its side is being redone and
14324 (b) we do a frame-based redisplay. This is a consequence
14325 of how inverted lines are drawn in frame-based redisplay. */
14326 || (!just_this_one_p
14327 && !FRAME_WINDOW_P (f
)
14328 && !WINDOW_FULL_WIDTH_P (w
))
14329 /* Line number to display. */
14330 || INTEGERP (w
->base_line_pos
)
14331 /* Column number is displayed and different from the one displayed. */
14332 || (!NILP (w
->column_number_displayed
)
14333 && (XFASTINT (w
->column_number_displayed
)
14334 != (int) current_column ()))) /* iftc */
14335 /* This means that the window has a mode line. */
14336 && (WINDOW_WANTS_MODELINE_P (w
)
14337 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14339 display_mode_lines (w
);
14341 /* If mode line height has changed, arrange for a thorough
14342 immediate redisplay using the correct mode line height. */
14343 if (WINDOW_WANTS_MODELINE_P (w
)
14344 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14346 fonts_changed_p
= 1;
14347 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14348 = DESIRED_MODE_LINE_HEIGHT (w
);
14351 /* If header line height has changed, arrange for a thorough
14352 immediate redisplay using the correct header line height. */
14353 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14354 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14356 fonts_changed_p
= 1;
14357 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14358 = DESIRED_HEADER_LINE_HEIGHT (w
);
14361 if (fonts_changed_p
)
14362 goto need_larger_matrices
;
14365 if (!line_number_displayed
14366 && !BUFFERP (w
->base_line_pos
))
14368 w
->base_line_pos
= Qnil
;
14369 w
->base_line_number
= Qnil
;
14374 /* When we reach a frame's selected window, redo the frame's menu bar. */
14375 if (update_mode_line
14376 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14378 int redisplay_menu_p
= 0;
14379 int redisplay_tool_bar_p
= 0;
14381 if (FRAME_WINDOW_P (f
))
14383 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14384 || defined (HAVE_NS) || defined (USE_GTK)
14385 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14387 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14391 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14393 if (redisplay_menu_p
)
14394 display_menu_bar (w
);
14396 #ifdef HAVE_WINDOW_SYSTEM
14397 if (FRAME_WINDOW_P (f
))
14399 #if defined (USE_GTK) || defined (HAVE_NS)
14400 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14402 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14403 && (FRAME_TOOL_BAR_LINES (f
) > 0
14404 || !NILP (Vauto_resize_tool_bars
));
14407 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14409 extern int ignore_mouse_drag_p
;
14410 ignore_mouse_drag_p
= 1;
14416 #ifdef HAVE_WINDOW_SYSTEM
14417 if (FRAME_WINDOW_P (f
)
14418 && update_window_fringes (w
, (just_this_one_p
14419 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14420 || w
->pseudo_window_p
)))
14424 if (draw_window_fringes (w
, 1))
14425 x_draw_vertical_border (w
);
14429 #endif /* HAVE_WINDOW_SYSTEM */
14431 /* We go to this label, with fonts_changed_p nonzero,
14432 if it is necessary to try again using larger glyph matrices.
14433 We have to redeem the scroll bar even in this case,
14434 because the loop in redisplay_internal expects that. */
14435 need_larger_matrices
:
14437 finish_scroll_bars
:
14439 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14441 /* Set the thumb's position and size. */
14442 set_vertical_scroll_bar (w
);
14444 /* Note that we actually used the scroll bar attached to this
14445 window, so it shouldn't be deleted at the end of redisplay. */
14446 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14447 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14450 /* Restore current_buffer and value of point in it. */
14451 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14452 set_buffer_internal_1 (old
);
14453 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14454 shorter. This can be caused by log truncation in *Messages*. */
14455 if (CHARPOS (lpoint
) <= ZV
)
14456 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14458 unbind_to (count
, Qnil
);
14462 /* Build the complete desired matrix of WINDOW with a window start
14463 buffer position POS.
14465 Value is 1 if successful. It is zero if fonts were loaded during
14466 redisplay which makes re-adjusting glyph matrices necessary, and -1
14467 if point would appear in the scroll margins.
14468 (We check that only if CHECK_MARGINS is nonzero. */
14471 try_window (window
, pos
, check_margins
)
14472 Lisp_Object window
;
14473 struct text_pos pos
;
14476 struct window
*w
= XWINDOW (window
);
14478 struct glyph_row
*last_text_row
= NULL
;
14479 struct frame
*f
= XFRAME (w
->frame
);
14481 /* Make POS the new window start. */
14482 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14484 /* Mark cursor position as unknown. No overlay arrow seen. */
14485 w
->cursor
.vpos
= -1;
14486 overlay_arrow_seen
= 0;
14488 /* Initialize iterator and info to start at POS. */
14489 start_display (&it
, w
, pos
);
14491 /* Display all lines of W. */
14492 while (it
.current_y
< it
.last_visible_y
)
14494 if (display_line (&it
))
14495 last_text_row
= it
.glyph_row
- 1;
14496 if (fonts_changed_p
)
14500 /* Don't let the cursor end in the scroll margins. */
14502 && !MINI_WINDOW_P (w
))
14504 int this_scroll_margin
;
14506 if (scroll_margin
> 0)
14508 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14509 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14512 this_scroll_margin
= 0;
14514 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14515 && w
->cursor
.y
< this_scroll_margin
14516 && CHARPOS (pos
) > BEGV
14517 && IT_CHARPOS (it
) < ZV
)
14518 /* rms: considering make_cursor_line_fully_visible_p here
14519 seems to give wrong results. We don't want to recenter
14520 when the last line is partly visible, we want to allow
14521 that case to be handled in the usual way. */
14522 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14524 w
->cursor
.vpos
= -1;
14525 clear_glyph_matrix (w
->desired_matrix
);
14530 /* If bottom moved off end of frame, change mode line percentage. */
14531 if (XFASTINT (w
->window_end_pos
) <= 0
14532 && Z
!= IT_CHARPOS (it
))
14533 w
->update_mode_line
= Qt
;
14535 /* Set window_end_pos to the offset of the last character displayed
14536 on the window from the end of current_buffer. Set
14537 window_end_vpos to its row number. */
14540 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14541 w
->window_end_bytepos
14542 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14544 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14546 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14547 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14548 ->displays_text_p
);
14552 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14553 w
->window_end_pos
= make_number (Z
- ZV
);
14554 w
->window_end_vpos
= make_number (0);
14557 /* But that is not valid info until redisplay finishes. */
14558 w
->window_end_valid
= Qnil
;
14564 /************************************************************************
14565 Window redisplay reusing current matrix when buffer has not changed
14566 ************************************************************************/
14568 /* Try redisplay of window W showing an unchanged buffer with a
14569 different window start than the last time it was displayed by
14570 reusing its current matrix. Value is non-zero if successful.
14571 W->start is the new window start. */
14574 try_window_reusing_current_matrix (w
)
14577 struct frame
*f
= XFRAME (w
->frame
);
14578 struct glyph_row
*row
, *bottom_row
;
14581 struct text_pos start
, new_start
;
14582 int nrows_scrolled
, i
;
14583 struct glyph_row
*last_text_row
;
14584 struct glyph_row
*last_reused_text_row
;
14585 struct glyph_row
*start_row
;
14586 int start_vpos
, min_y
, max_y
;
14589 if (inhibit_try_window_reusing
)
14593 if (/* This function doesn't handle terminal frames. */
14594 !FRAME_WINDOW_P (f
)
14595 /* Don't try to reuse the display if windows have been split
14597 || windows_or_buffers_changed
14598 || cursor_type_changed
)
14601 /* Can't do this if region may have changed. */
14602 if ((!NILP (Vtransient_mark_mode
)
14603 && !NILP (current_buffer
->mark_active
))
14604 || !NILP (w
->region_showing
)
14605 || !NILP (Vshow_trailing_whitespace
))
14608 /* If top-line visibility has changed, give up. */
14609 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14610 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14613 /* Give up if old or new display is scrolled vertically. We could
14614 make this function handle this, but right now it doesn't. */
14615 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14616 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14619 /* The variable new_start now holds the new window start. The old
14620 start `start' can be determined from the current matrix. */
14621 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14622 start
= start_row
->start
.pos
;
14623 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14625 /* Clear the desired matrix for the display below. */
14626 clear_glyph_matrix (w
->desired_matrix
);
14628 if (CHARPOS (new_start
) <= CHARPOS (start
))
14632 /* Don't use this method if the display starts with an ellipsis
14633 displayed for invisible text. It's not easy to handle that case
14634 below, and it's certainly not worth the effort since this is
14635 not a frequent case. */
14636 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14639 IF_DEBUG (debug_method_add (w
, "twu1"));
14641 /* Display up to a row that can be reused. The variable
14642 last_text_row is set to the last row displayed that displays
14643 text. Note that it.vpos == 0 if or if not there is a
14644 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14645 start_display (&it
, w
, new_start
);
14646 first_row_y
= it
.current_y
;
14647 w
->cursor
.vpos
= -1;
14648 last_text_row
= last_reused_text_row
= NULL
;
14650 while (it
.current_y
< it
.last_visible_y
14651 && !fonts_changed_p
)
14653 /* If we have reached into the characters in the START row,
14654 that means the line boundaries have changed. So we
14655 can't start copying with the row START. Maybe it will
14656 work to start copying with the following row. */
14657 while (IT_CHARPOS (it
) > CHARPOS (start
))
14659 /* Advance to the next row as the "start". */
14661 start
= start_row
->start
.pos
;
14662 /* If there are no more rows to try, or just one, give up. */
14663 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14664 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14665 || CHARPOS (start
) == ZV
)
14667 clear_glyph_matrix (w
->desired_matrix
);
14671 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14673 /* If we have reached alignment,
14674 we can copy the rest of the rows. */
14675 if (IT_CHARPOS (it
) == CHARPOS (start
))
14678 if (display_line (&it
))
14679 last_text_row
= it
.glyph_row
- 1;
14682 /* A value of current_y < last_visible_y means that we stopped
14683 at the previous window start, which in turn means that we
14684 have at least one reusable row. */
14685 if (it
.current_y
< it
.last_visible_y
)
14687 /* IT.vpos always starts from 0; it counts text lines. */
14688 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14690 /* Find PT if not already found in the lines displayed. */
14691 if (w
->cursor
.vpos
< 0)
14693 int dy
= it
.current_y
- start_row
->y
;
14695 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14696 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14698 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14699 dy
, nrows_scrolled
);
14702 clear_glyph_matrix (w
->desired_matrix
);
14707 /* Scroll the display. Do it before the current matrix is
14708 changed. The problem here is that update has not yet
14709 run, i.e. part of the current matrix is not up to date.
14710 scroll_run_hook will clear the cursor, and use the
14711 current matrix to get the height of the row the cursor is
14713 run
.current_y
= start_row
->y
;
14714 run
.desired_y
= it
.current_y
;
14715 run
.height
= it
.last_visible_y
- it
.current_y
;
14717 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14720 FRAME_RIF (f
)->update_window_begin_hook (w
);
14721 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14722 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14723 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14727 /* Shift current matrix down by nrows_scrolled lines. */
14728 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14729 rotate_matrix (w
->current_matrix
,
14731 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14734 /* Disable lines that must be updated. */
14735 for (i
= 0; i
< nrows_scrolled
; ++i
)
14736 (start_row
+ i
)->enabled_p
= 0;
14738 /* Re-compute Y positions. */
14739 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14740 max_y
= it
.last_visible_y
;
14741 for (row
= start_row
+ nrows_scrolled
;
14745 row
->y
= it
.current_y
;
14746 row
->visible_height
= row
->height
;
14748 if (row
->y
< min_y
)
14749 row
->visible_height
-= min_y
- row
->y
;
14750 if (row
->y
+ row
->height
> max_y
)
14751 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14752 row
->redraw_fringe_bitmaps_p
= 1;
14754 it
.current_y
+= row
->height
;
14756 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14757 last_reused_text_row
= row
;
14758 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14762 /* Disable lines in the current matrix which are now
14763 below the window. */
14764 for (++row
; row
< bottom_row
; ++row
)
14765 row
->enabled_p
= row
->mode_line_p
= 0;
14768 /* Update window_end_pos etc.; last_reused_text_row is the last
14769 reused row from the current matrix containing text, if any.
14770 The value of last_text_row is the last displayed line
14771 containing text. */
14772 if (last_reused_text_row
)
14774 w
->window_end_bytepos
14775 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14777 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14779 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14780 w
->current_matrix
));
14782 else if (last_text_row
)
14784 w
->window_end_bytepos
14785 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14787 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14789 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14793 /* This window must be completely empty. */
14794 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14795 w
->window_end_pos
= make_number (Z
- ZV
);
14796 w
->window_end_vpos
= make_number (0);
14798 w
->window_end_valid
= Qnil
;
14800 /* Update hint: don't try scrolling again in update_window. */
14801 w
->desired_matrix
->no_scrolling_p
= 1;
14804 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14808 else if (CHARPOS (new_start
) > CHARPOS (start
))
14810 struct glyph_row
*pt_row
, *row
;
14811 struct glyph_row
*first_reusable_row
;
14812 struct glyph_row
*first_row_to_display
;
14814 int yb
= window_text_bottom_y (w
);
14816 /* Find the row starting at new_start, if there is one. Don't
14817 reuse a partially visible line at the end. */
14818 first_reusable_row
= start_row
;
14819 while (first_reusable_row
->enabled_p
14820 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14821 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14822 < CHARPOS (new_start
)))
14823 ++first_reusable_row
;
14825 /* Give up if there is no row to reuse. */
14826 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14827 || !first_reusable_row
->enabled_p
14828 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14829 != CHARPOS (new_start
)))
14832 /* We can reuse fully visible rows beginning with
14833 first_reusable_row to the end of the window. Set
14834 first_row_to_display to the first row that cannot be reused.
14835 Set pt_row to the row containing point, if there is any. */
14837 for (first_row_to_display
= first_reusable_row
;
14838 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14839 ++first_row_to_display
)
14841 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14842 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14843 pt_row
= first_row_to_display
;
14846 /* Start displaying at the start of first_row_to_display. */
14847 xassert (first_row_to_display
->y
< yb
);
14848 init_to_row_start (&it
, w
, first_row_to_display
);
14850 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14852 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14854 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14855 + WINDOW_HEADER_LINE_HEIGHT (w
));
14857 /* Display lines beginning with first_row_to_display in the
14858 desired matrix. Set last_text_row to the last row displayed
14859 that displays text. */
14860 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14861 if (pt_row
== NULL
)
14862 w
->cursor
.vpos
= -1;
14863 last_text_row
= NULL
;
14864 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14865 if (display_line (&it
))
14866 last_text_row
= it
.glyph_row
- 1;
14868 /* If point is in a reused row, adjust y and vpos of the cursor
14872 w
->cursor
.vpos
-= nrows_scrolled
;
14873 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14876 /* Give up if point isn't in a row displayed or reused. (This
14877 also handles the case where w->cursor.vpos < nrows_scrolled
14878 after the calls to display_line, which can happen with scroll
14879 margins. See bug#1295.) */
14880 if (w
->cursor
.vpos
< 0)
14882 clear_glyph_matrix (w
->desired_matrix
);
14886 /* Scroll the display. */
14887 run
.current_y
= first_reusable_row
->y
;
14888 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14889 run
.height
= it
.last_visible_y
- run
.current_y
;
14890 dy
= run
.current_y
- run
.desired_y
;
14895 FRAME_RIF (f
)->update_window_begin_hook (w
);
14896 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14897 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14898 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14902 /* Adjust Y positions of reused rows. */
14903 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14904 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14905 max_y
= it
.last_visible_y
;
14906 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14909 row
->visible_height
= row
->height
;
14910 if (row
->y
< min_y
)
14911 row
->visible_height
-= min_y
- row
->y
;
14912 if (row
->y
+ row
->height
> max_y
)
14913 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14914 row
->redraw_fringe_bitmaps_p
= 1;
14917 /* Scroll the current matrix. */
14918 xassert (nrows_scrolled
> 0);
14919 rotate_matrix (w
->current_matrix
,
14921 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14924 /* Disable rows not reused. */
14925 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14926 row
->enabled_p
= 0;
14928 /* Point may have moved to a different line, so we cannot assume that
14929 the previous cursor position is valid; locate the correct row. */
14932 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14933 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14937 w
->cursor
.y
= row
->y
;
14939 if (row
< bottom_row
)
14941 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14942 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14943 struct glyph
*orig_glyph
= glyph
;
14944 struct cursor_pos orig_cursor
= w
->cursor
;
14947 && (!BUFFERP (glyph
->object
)
14948 || glyph
->charpos
!= PT
);
14952 w
->cursor
.x
+= glyph
->pixel_width
;
14954 /* With bidi reordering, charpos changes non-linearly
14955 with hpos, so the right glyph could be to the
14957 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
14958 && (!BUFFERP (glyph
->object
) || glyph
->charpos
!= PT
))
14960 struct glyph
*start_glyph
= row
->glyphs
[TEXT_AREA
];
14962 glyph
= orig_glyph
- 1;
14963 orig_cursor
.hpos
--;
14964 orig_cursor
.x
-= glyph
->pixel_width
;
14965 for (; glyph
>= start_glyph
14966 && (!BUFFERP (glyph
->object
)
14967 || glyph
->charpos
!= PT
);
14971 w
->cursor
.x
-= glyph
->pixel_width
;
14973 if (BUFFERP (glyph
->object
) && glyph
->charpos
== PT
)
14974 w
->cursor
= orig_cursor
;
14979 /* Adjust window end. A null value of last_text_row means that
14980 the window end is in reused rows which in turn means that
14981 only its vpos can have changed. */
14984 w
->window_end_bytepos
14985 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14987 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14989 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14994 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14997 w
->window_end_valid
= Qnil
;
14998 w
->desired_matrix
->no_scrolling_p
= 1;
15001 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15011 /************************************************************************
15012 Window redisplay reusing current matrix when buffer has changed
15013 ************************************************************************/
15015 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
15016 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
15018 static struct glyph_row
*
15019 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
15020 struct glyph_row
*));
15023 /* Return the last row in MATRIX displaying text. If row START is
15024 non-null, start searching with that row. IT gives the dimensions
15025 of the display. Value is null if matrix is empty; otherwise it is
15026 a pointer to the row found. */
15028 static struct glyph_row
*
15029 find_last_row_displaying_text (matrix
, it
, start
)
15030 struct glyph_matrix
*matrix
;
15032 struct glyph_row
*start
;
15034 struct glyph_row
*row
, *row_found
;
15036 /* Set row_found to the last row in IT->w's current matrix
15037 displaying text. The loop looks funny but think of partially
15040 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15041 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15043 xassert (row
->enabled_p
);
15045 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15054 /* Return the last row in the current matrix of W that is not affected
15055 by changes at the start of current_buffer that occurred since W's
15056 current matrix was built. Value is null if no such row exists.
15058 BEG_UNCHANGED us the number of characters unchanged at the start of
15059 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15060 first changed character in current_buffer. Characters at positions <
15061 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15062 when the current matrix was built. */
15064 static struct glyph_row
*
15065 find_last_unchanged_at_beg_row (w
)
15068 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15069 struct glyph_row
*row
;
15070 struct glyph_row
*row_found
= NULL
;
15071 int yb
= window_text_bottom_y (w
);
15073 /* Find the last row displaying unchanged text. */
15074 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15075 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15076 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15079 if (/* If row ends before first_changed_pos, it is unchanged,
15080 except in some case. */
15081 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15082 /* When row ends in ZV and we write at ZV it is not
15084 && !row
->ends_at_zv_p
15085 /* When first_changed_pos is the end of a continued line,
15086 row is not unchanged because it may be no longer
15088 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15089 && (row
->continued_p
15090 || row
->exact_window_width_line_p
)))
15093 /* Stop if last visible row. */
15094 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15102 /* Find the first glyph row in the current matrix of W that is not
15103 affected by changes at the end of current_buffer since the
15104 time W's current matrix was built.
15106 Return in *DELTA the number of chars by which buffer positions in
15107 unchanged text at the end of current_buffer must be adjusted.
15109 Return in *DELTA_BYTES the corresponding number of bytes.
15111 Value is null if no such row exists, i.e. all rows are affected by
15114 static struct glyph_row
*
15115 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
15117 int *delta
, *delta_bytes
;
15119 struct glyph_row
*row
;
15120 struct glyph_row
*row_found
= NULL
;
15122 *delta
= *delta_bytes
= 0;
15124 /* Display must not have been paused, otherwise the current matrix
15125 is not up to date. */
15126 eassert (!NILP (w
->window_end_valid
));
15128 /* A value of window_end_pos >= END_UNCHANGED means that the window
15129 end is in the range of changed text. If so, there is no
15130 unchanged row at the end of W's current matrix. */
15131 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15134 /* Set row to the last row in W's current matrix displaying text. */
15135 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15137 /* If matrix is entirely empty, no unchanged row exists. */
15138 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15140 /* The value of row is the last glyph row in the matrix having a
15141 meaningful buffer position in it. The end position of row
15142 corresponds to window_end_pos. This allows us to translate
15143 buffer positions in the current matrix to current buffer
15144 positions for characters not in changed text. */
15145 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15146 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15147 int last_unchanged_pos
, last_unchanged_pos_old
;
15148 struct glyph_row
*first_text_row
15149 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15151 *delta
= Z
- Z_old
;
15152 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15154 /* Set last_unchanged_pos to the buffer position of the last
15155 character in the buffer that has not been changed. Z is the
15156 index + 1 of the last character in current_buffer, i.e. by
15157 subtracting END_UNCHANGED we get the index of the last
15158 unchanged character, and we have to add BEG to get its buffer
15160 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15161 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15163 /* Search backward from ROW for a row displaying a line that
15164 starts at a minimum position >= last_unchanged_pos_old. */
15165 for (; row
> first_text_row
; --row
)
15167 /* This used to abort, but it can happen.
15168 It is ok to just stop the search instead here. KFS. */
15169 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15172 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15177 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15183 /* Make sure that glyph rows in the current matrix of window W
15184 reference the same glyph memory as corresponding rows in the
15185 frame's frame matrix. This function is called after scrolling W's
15186 current matrix on a terminal frame in try_window_id and
15187 try_window_reusing_current_matrix. */
15190 sync_frame_with_window_matrix_rows (w
)
15193 struct frame
*f
= XFRAME (w
->frame
);
15194 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15196 /* Preconditions: W must be a leaf window and full-width. Its frame
15197 must have a frame matrix. */
15198 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15199 xassert (WINDOW_FULL_WIDTH_P (w
));
15200 xassert (!FRAME_WINDOW_P (f
));
15202 /* If W is a full-width window, glyph pointers in W's current matrix
15203 have, by definition, to be the same as glyph pointers in the
15204 corresponding frame matrix. Note that frame matrices have no
15205 marginal areas (see build_frame_matrix). */
15206 window_row
= w
->current_matrix
->rows
;
15207 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15208 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15209 while (window_row
< window_row_end
)
15211 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15212 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15214 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15215 frame_row
->glyphs
[TEXT_AREA
] = start
;
15216 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15217 frame_row
->glyphs
[LAST_AREA
] = end
;
15219 /* Disable frame rows whose corresponding window rows have
15220 been disabled in try_window_id. */
15221 if (!window_row
->enabled_p
)
15222 frame_row
->enabled_p
= 0;
15224 ++window_row
, ++frame_row
;
15229 /* Find the glyph row in window W containing CHARPOS. Consider all
15230 rows between START and END (not inclusive). END null means search
15231 all rows to the end of the display area of W. Value is the row
15232 containing CHARPOS or null. */
15235 row_containing_pos (w
, charpos
, start
, end
, dy
)
15238 struct glyph_row
*start
, *end
;
15241 struct glyph_row
*row
= start
;
15244 /* If we happen to start on a header-line, skip that. */
15245 if (row
->mode_line_p
)
15248 if ((end
&& row
>= end
) || !row
->enabled_p
)
15251 last_y
= window_text_bottom_y (w
) - dy
;
15255 /* Give up if we have gone too far. */
15256 if (end
&& row
>= end
)
15258 /* This formerly returned if they were equal.
15259 I think that both quantities are of a "last plus one" type;
15260 if so, when they are equal, the row is within the screen. -- rms. */
15261 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15264 /* If it is in this row, return this row. */
15265 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15266 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15267 /* The end position of a row equals the start
15268 position of the next row. If CHARPOS is there, we
15269 would rather display it in the next line, except
15270 when this line ends in ZV. */
15271 && !row
->ends_at_zv_p
15272 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15273 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15280 /* Try to redisplay window W by reusing its existing display. W's
15281 current matrix must be up to date when this function is called,
15282 i.e. window_end_valid must not be nil.
15286 1 if display has been updated
15287 0 if otherwise unsuccessful
15288 -1 if redisplay with same window start is known not to succeed
15290 The following steps are performed:
15292 1. Find the last row in the current matrix of W that is not
15293 affected by changes at the start of current_buffer. If no such row
15296 2. Find the first row in W's current matrix that is not affected by
15297 changes at the end of current_buffer. Maybe there is no such row.
15299 3. Display lines beginning with the row + 1 found in step 1 to the
15300 row found in step 2 or, if step 2 didn't find a row, to the end of
15303 4. If cursor is not known to appear on the window, give up.
15305 5. If display stopped at the row found in step 2, scroll the
15306 display and current matrix as needed.
15308 6. Maybe display some lines at the end of W, if we must. This can
15309 happen under various circumstances, like a partially visible line
15310 becoming fully visible, or because newly displayed lines are displayed
15311 in smaller font sizes.
15313 7. Update W's window end information. */
15319 struct frame
*f
= XFRAME (w
->frame
);
15320 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15321 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15322 struct glyph_row
*last_unchanged_at_beg_row
;
15323 struct glyph_row
*first_unchanged_at_end_row
;
15324 struct glyph_row
*row
;
15325 struct glyph_row
*bottom_row
;
15328 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
15329 struct text_pos start_pos
;
15331 int first_unchanged_at_end_vpos
= 0;
15332 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15333 struct text_pos start
;
15334 int first_changed_charpos
, last_changed_charpos
;
15337 if (inhibit_try_window_id
)
15341 /* This is handy for debugging. */
15343 #define GIVE_UP(X) \
15345 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15349 #define GIVE_UP(X) return 0
15352 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15354 /* Don't use this for mini-windows because these can show
15355 messages and mini-buffers, and we don't handle that here. */
15356 if (MINI_WINDOW_P (w
))
15359 /* This flag is used to prevent redisplay optimizations. */
15360 if (windows_or_buffers_changed
|| cursor_type_changed
)
15363 /* Verify that narrowing has not changed.
15364 Also verify that we were not told to prevent redisplay optimizations.
15365 It would be nice to further
15366 reduce the number of cases where this prevents try_window_id. */
15367 if (current_buffer
->clip_changed
15368 || current_buffer
->prevent_redisplay_optimizations_p
)
15371 /* Window must either use window-based redisplay or be full width. */
15372 if (!FRAME_WINDOW_P (f
)
15373 && (!FRAME_LINE_INS_DEL_OK (f
)
15374 || !WINDOW_FULL_WIDTH_P (w
)))
15377 /* Give up if point is known NOT to appear in W. */
15378 if (PT
< CHARPOS (start
))
15381 /* Another way to prevent redisplay optimizations. */
15382 if (XFASTINT (w
->last_modified
) == 0)
15385 /* Verify that window is not hscrolled. */
15386 if (XFASTINT (w
->hscroll
) != 0)
15389 /* Verify that display wasn't paused. */
15390 if (NILP (w
->window_end_valid
))
15393 /* Can't use this if highlighting a region because a cursor movement
15394 will do more than just set the cursor. */
15395 if (!NILP (Vtransient_mark_mode
)
15396 && !NILP (current_buffer
->mark_active
))
15399 /* Likewise if highlighting trailing whitespace. */
15400 if (!NILP (Vshow_trailing_whitespace
))
15403 /* Likewise if showing a region. */
15404 if (!NILP (w
->region_showing
))
15407 /* Can't use this if overlay arrow position and/or string have
15409 if (overlay_arrows_changed_p ())
15412 /* When word-wrap is on, adding a space to the first word of a
15413 wrapped line can change the wrap position, altering the line
15414 above it. It might be worthwhile to handle this more
15415 intelligently, but for now just redisplay from scratch. */
15416 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15419 /* Under bidi reordering, adding or deleting a character in the
15420 beginning of a paragraph, before the first strong directional
15421 character, can change the base direction of the paragraph (unless
15422 the buffer specifies a fixed paragraph direction), which will
15423 require to redisplay the whole paragraph. It might be worthwhile
15424 to find the paragraph limits and widen the range of redisplayed
15425 lines to that, but for now just give up this optimization and
15426 redisplay from scratch. */
15427 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15428 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15431 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15432 only if buffer has really changed. The reason is that the gap is
15433 initially at Z for freshly visited files. The code below would
15434 set end_unchanged to 0 in that case. */
15435 if (MODIFF
> SAVE_MODIFF
15436 /* This seems to happen sometimes after saving a buffer. */
15437 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15439 if (GPT
- BEG
< BEG_UNCHANGED
)
15440 BEG_UNCHANGED
= GPT
- BEG
;
15441 if (Z
- GPT
< END_UNCHANGED
)
15442 END_UNCHANGED
= Z
- GPT
;
15445 /* The position of the first and last character that has been changed. */
15446 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15447 last_changed_charpos
= Z
- END_UNCHANGED
;
15449 /* If window starts after a line end, and the last change is in
15450 front of that newline, then changes don't affect the display.
15451 This case happens with stealth-fontification. Note that although
15452 the display is unchanged, glyph positions in the matrix have to
15453 be adjusted, of course. */
15454 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15455 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15456 && ((last_changed_charpos
< CHARPOS (start
)
15457 && CHARPOS (start
) == BEGV
)
15458 || (last_changed_charpos
< CHARPOS (start
) - 1
15459 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15461 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15462 struct glyph_row
*r0
;
15464 /* Compute how many chars/bytes have been added to or removed
15465 from the buffer. */
15466 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15467 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15469 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15471 /* Give up if PT is not in the window. Note that it already has
15472 been checked at the start of try_window_id that PT is not in
15473 front of the window start. */
15474 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15477 /* If window start is unchanged, we can reuse the whole matrix
15478 as is, after adjusting glyph positions. No need to compute
15479 the window end again, since its offset from Z hasn't changed. */
15480 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15481 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15482 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15483 /* PT must not be in a partially visible line. */
15484 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15485 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15487 /* Adjust positions in the glyph matrix. */
15488 if (delta
|| delta_bytes
)
15490 struct glyph_row
*r1
15491 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15492 increment_matrix_positions (w
->current_matrix
,
15493 MATRIX_ROW_VPOS (r0
, current_matrix
),
15494 MATRIX_ROW_VPOS (r1
, current_matrix
),
15495 delta
, delta_bytes
);
15498 /* Set the cursor. */
15499 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15501 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15508 /* Handle the case that changes are all below what is displayed in
15509 the window, and that PT is in the window. This shortcut cannot
15510 be taken if ZV is visible in the window, and text has been added
15511 there that is visible in the window. */
15512 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15513 /* ZV is not visible in the window, or there are no
15514 changes at ZV, actually. */
15515 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15516 || first_changed_charpos
== last_changed_charpos
))
15518 struct glyph_row
*r0
;
15520 /* Give up if PT is not in the window. Note that it already has
15521 been checked at the start of try_window_id that PT is not in
15522 front of the window start. */
15523 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15526 /* If window start is unchanged, we can reuse the whole matrix
15527 as is, without changing glyph positions since no text has
15528 been added/removed in front of the window end. */
15529 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15530 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15531 /* PT must not be in a partially visible line. */
15532 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15533 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15535 /* We have to compute the window end anew since text
15536 can have been added/removed after it. */
15538 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15539 w
->window_end_bytepos
15540 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15542 /* Set the cursor. */
15543 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15545 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15552 /* Give up if window start is in the changed area.
15554 The condition used to read
15556 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15558 but why that was tested escapes me at the moment. */
15559 if (CHARPOS (start
) >= first_changed_charpos
15560 && CHARPOS (start
) <= last_changed_charpos
)
15563 /* Check that window start agrees with the start of the first glyph
15564 row in its current matrix. Check this after we know the window
15565 start is not in changed text, otherwise positions would not be
15567 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15568 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15571 /* Give up if the window ends in strings. Overlay strings
15572 at the end are difficult to handle, so don't try. */
15573 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15574 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15577 /* Compute the position at which we have to start displaying new
15578 lines. Some of the lines at the top of the window might be
15579 reusable because they are not displaying changed text. Find the
15580 last row in W's current matrix not affected by changes at the
15581 start of current_buffer. Value is null if changes start in the
15582 first line of window. */
15583 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15584 if (last_unchanged_at_beg_row
)
15586 /* Avoid starting to display in the moddle of a character, a TAB
15587 for instance. This is easier than to set up the iterator
15588 exactly, and it's not a frequent case, so the additional
15589 effort wouldn't really pay off. */
15590 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15591 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15592 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15593 --last_unchanged_at_beg_row
;
15595 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15598 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15600 start_pos
= it
.current
.pos
;
15602 /* Start displaying new lines in the desired matrix at the same
15603 vpos we would use in the current matrix, i.e. below
15604 last_unchanged_at_beg_row. */
15605 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15607 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15608 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15610 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15614 /* There are no reusable lines at the start of the window.
15615 Start displaying in the first text line. */
15616 start_display (&it
, w
, start
);
15617 it
.vpos
= it
.first_vpos
;
15618 start_pos
= it
.current
.pos
;
15621 /* Find the first row that is not affected by changes at the end of
15622 the buffer. Value will be null if there is no unchanged row, in
15623 which case we must redisplay to the end of the window. delta
15624 will be set to the value by which buffer positions beginning with
15625 first_unchanged_at_end_row have to be adjusted due to text
15627 first_unchanged_at_end_row
15628 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15629 IF_DEBUG (debug_delta
= delta
);
15630 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15632 /* Set stop_pos to the buffer position up to which we will have to
15633 display new lines. If first_unchanged_at_end_row != NULL, this
15634 is the buffer position of the start of the line displayed in that
15635 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15636 that we don't stop at a buffer position. */
15638 if (first_unchanged_at_end_row
)
15640 xassert (last_unchanged_at_beg_row
== NULL
15641 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15643 /* If this is a continuation line, move forward to the next one
15644 that isn't. Changes in lines above affect this line.
15645 Caution: this may move first_unchanged_at_end_row to a row
15646 not displaying text. */
15647 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15648 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15649 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15650 < it
.last_visible_y
))
15651 ++first_unchanged_at_end_row
;
15653 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15654 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15655 >= it
.last_visible_y
))
15656 first_unchanged_at_end_row
= NULL
;
15659 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15661 first_unchanged_at_end_vpos
15662 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15663 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15666 else if (last_unchanged_at_beg_row
== NULL
)
15672 /* Either there is no unchanged row at the end, or the one we have
15673 now displays text. This is a necessary condition for the window
15674 end pos calculation at the end of this function. */
15675 xassert (first_unchanged_at_end_row
== NULL
15676 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15678 debug_last_unchanged_at_beg_vpos
15679 = (last_unchanged_at_beg_row
15680 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15682 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15684 #endif /* GLYPH_DEBUG != 0 */
15687 /* Display new lines. Set last_text_row to the last new line
15688 displayed which has text on it, i.e. might end up as being the
15689 line where the window_end_vpos is. */
15690 w
->cursor
.vpos
= -1;
15691 last_text_row
= NULL
;
15692 overlay_arrow_seen
= 0;
15693 while (it
.current_y
< it
.last_visible_y
15694 && !fonts_changed_p
15695 && (first_unchanged_at_end_row
== NULL
15696 || IT_CHARPOS (it
) < stop_pos
))
15698 if (display_line (&it
))
15699 last_text_row
= it
.glyph_row
- 1;
15702 if (fonts_changed_p
)
15706 /* Compute differences in buffer positions, y-positions etc. for
15707 lines reused at the bottom of the window. Compute what we can
15709 if (first_unchanged_at_end_row
15710 /* No lines reused because we displayed everything up to the
15711 bottom of the window. */
15712 && it
.current_y
< it
.last_visible_y
)
15715 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15717 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15718 run
.current_y
= first_unchanged_at_end_row
->y
;
15719 run
.desired_y
= run
.current_y
+ dy
;
15720 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15724 delta
= delta_bytes
= dvpos
= dy
15725 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15726 first_unchanged_at_end_row
= NULL
;
15728 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15731 /* Find the cursor if not already found. We have to decide whether
15732 PT will appear on this window (it sometimes doesn't, but this is
15733 not a very frequent case.) This decision has to be made before
15734 the current matrix is altered. A value of cursor.vpos < 0 means
15735 that PT is either in one of the lines beginning at
15736 first_unchanged_at_end_row or below the window. Don't care for
15737 lines that might be displayed later at the window end; as
15738 mentioned, this is not a frequent case. */
15739 if (w
->cursor
.vpos
< 0)
15741 /* Cursor in unchanged rows at the top? */
15742 if (PT
< CHARPOS (start_pos
)
15743 && last_unchanged_at_beg_row
)
15745 row
= row_containing_pos (w
, PT
,
15746 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15747 last_unchanged_at_beg_row
+ 1, 0);
15749 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15752 /* Start from first_unchanged_at_end_row looking for PT. */
15753 else if (first_unchanged_at_end_row
)
15755 row
= row_containing_pos (w
, PT
- delta
,
15756 first_unchanged_at_end_row
, NULL
, 0);
15758 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15759 delta_bytes
, dy
, dvpos
);
15762 /* Give up if cursor was not found. */
15763 if (w
->cursor
.vpos
< 0)
15765 clear_glyph_matrix (w
->desired_matrix
);
15770 /* Don't let the cursor end in the scroll margins. */
15772 int this_scroll_margin
, cursor_height
;
15774 this_scroll_margin
= max (0, scroll_margin
);
15775 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15776 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15777 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15779 if ((w
->cursor
.y
< this_scroll_margin
15780 && CHARPOS (start
) > BEGV
)
15781 /* Old redisplay didn't take scroll margin into account at the bottom,
15782 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15783 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15784 ? cursor_height
+ this_scroll_margin
15785 : 1)) > it
.last_visible_y
)
15787 w
->cursor
.vpos
= -1;
15788 clear_glyph_matrix (w
->desired_matrix
);
15793 /* Scroll the display. Do it before changing the current matrix so
15794 that xterm.c doesn't get confused about where the cursor glyph is
15796 if (dy
&& run
.height
)
15800 if (FRAME_WINDOW_P (f
))
15802 FRAME_RIF (f
)->update_window_begin_hook (w
);
15803 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15804 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15805 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15809 /* Terminal frame. In this case, dvpos gives the number of
15810 lines to scroll by; dvpos < 0 means scroll up. */
15811 int first_unchanged_at_end_vpos
15812 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15813 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15814 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15815 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15816 + window_internal_height (w
));
15818 /* Perform the operation on the screen. */
15821 /* Scroll last_unchanged_at_beg_row to the end of the
15822 window down dvpos lines. */
15823 set_terminal_window (f
, end
);
15825 /* On dumb terminals delete dvpos lines at the end
15826 before inserting dvpos empty lines. */
15827 if (!FRAME_SCROLL_REGION_OK (f
))
15828 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15830 /* Insert dvpos empty lines in front of
15831 last_unchanged_at_beg_row. */
15832 ins_del_lines (f
, from
, dvpos
);
15834 else if (dvpos
< 0)
15836 /* Scroll up last_unchanged_at_beg_vpos to the end of
15837 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15838 set_terminal_window (f
, end
);
15840 /* Delete dvpos lines in front of
15841 last_unchanged_at_beg_vpos. ins_del_lines will set
15842 the cursor to the given vpos and emit |dvpos| delete
15844 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15846 /* On a dumb terminal insert dvpos empty lines at the
15848 if (!FRAME_SCROLL_REGION_OK (f
))
15849 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15852 set_terminal_window (f
, 0);
15858 /* Shift reused rows of the current matrix to the right position.
15859 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15861 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15862 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15865 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15866 bottom_vpos
, dvpos
);
15867 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15870 else if (dvpos
> 0)
15872 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15873 bottom_vpos
, dvpos
);
15874 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15875 first_unchanged_at_end_vpos
+ dvpos
, 0);
15878 /* For frame-based redisplay, make sure that current frame and window
15879 matrix are in sync with respect to glyph memory. */
15880 if (!FRAME_WINDOW_P (f
))
15881 sync_frame_with_window_matrix_rows (w
);
15883 /* Adjust buffer positions in reused rows. */
15884 if (delta
|| delta_bytes
)
15885 increment_matrix_positions (current_matrix
,
15886 first_unchanged_at_end_vpos
+ dvpos
,
15887 bottom_vpos
, delta
, delta_bytes
);
15889 /* Adjust Y positions. */
15891 shift_glyph_matrix (w
, current_matrix
,
15892 first_unchanged_at_end_vpos
+ dvpos
,
15895 if (first_unchanged_at_end_row
)
15897 first_unchanged_at_end_row
+= dvpos
;
15898 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15899 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15900 first_unchanged_at_end_row
= NULL
;
15903 /* If scrolling up, there may be some lines to display at the end of
15905 last_text_row_at_end
= NULL
;
15908 /* Scrolling up can leave for example a partially visible line
15909 at the end of the window to be redisplayed. */
15910 /* Set last_row to the glyph row in the current matrix where the
15911 window end line is found. It has been moved up or down in
15912 the matrix by dvpos. */
15913 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15914 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15916 /* If last_row is the window end line, it should display text. */
15917 xassert (last_row
->displays_text_p
);
15919 /* If window end line was partially visible before, begin
15920 displaying at that line. Otherwise begin displaying with the
15921 line following it. */
15922 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15924 init_to_row_start (&it
, w
, last_row
);
15925 it
.vpos
= last_vpos
;
15926 it
.current_y
= last_row
->y
;
15930 init_to_row_end (&it
, w
, last_row
);
15931 it
.vpos
= 1 + last_vpos
;
15932 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15936 /* We may start in a continuation line. If so, we have to
15937 get the right continuation_lines_width and current_x. */
15938 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15939 it
.hpos
= it
.current_x
= 0;
15941 /* Display the rest of the lines at the window end. */
15942 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15943 while (it
.current_y
< it
.last_visible_y
15944 && !fonts_changed_p
)
15946 /* Is it always sure that the display agrees with lines in
15947 the current matrix? I don't think so, so we mark rows
15948 displayed invalid in the current matrix by setting their
15949 enabled_p flag to zero. */
15950 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15951 if (display_line (&it
))
15952 last_text_row_at_end
= it
.glyph_row
- 1;
15956 /* Update window_end_pos and window_end_vpos. */
15957 if (first_unchanged_at_end_row
15958 && !last_text_row_at_end
)
15960 /* Window end line if one of the preserved rows from the current
15961 matrix. Set row to the last row displaying text in current
15962 matrix starting at first_unchanged_at_end_row, after
15964 xassert (first_unchanged_at_end_row
->displays_text_p
);
15965 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15966 first_unchanged_at_end_row
);
15967 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15969 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15970 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15972 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15973 xassert (w
->window_end_bytepos
>= 0);
15974 IF_DEBUG (debug_method_add (w
, "A"));
15976 else if (last_text_row_at_end
)
15979 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15980 w
->window_end_bytepos
15981 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15983 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15984 xassert (w
->window_end_bytepos
>= 0);
15985 IF_DEBUG (debug_method_add (w
, "B"));
15987 else if (last_text_row
)
15989 /* We have displayed either to the end of the window or at the
15990 end of the window, i.e. the last row with text is to be found
15991 in the desired matrix. */
15993 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15994 w
->window_end_bytepos
15995 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15997 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15998 xassert (w
->window_end_bytepos
>= 0);
16000 else if (first_unchanged_at_end_row
== NULL
16001 && last_text_row
== NULL
16002 && last_text_row_at_end
== NULL
)
16004 /* Displayed to end of window, but no line containing text was
16005 displayed. Lines were deleted at the end of the window. */
16006 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16007 int vpos
= XFASTINT (w
->window_end_vpos
);
16008 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16009 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16012 row
== NULL
&& vpos
>= first_vpos
;
16013 --vpos
, --current_row
, --desired_row
)
16015 if (desired_row
->enabled_p
)
16017 if (desired_row
->displays_text_p
)
16020 else if (current_row
->displays_text_p
)
16024 xassert (row
!= NULL
);
16025 w
->window_end_vpos
= make_number (vpos
+ 1);
16026 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16027 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16028 xassert (w
->window_end_bytepos
>= 0);
16029 IF_DEBUG (debug_method_add (w
, "C"));
16034 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16035 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16037 /* Record that display has not been completed. */
16038 w
->window_end_valid
= Qnil
;
16039 w
->desired_matrix
->no_scrolling_p
= 1;
16047 /***********************************************************************
16048 More debugging support
16049 ***********************************************************************/
16053 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
16054 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
16055 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
16058 /* Dump the contents of glyph matrix MATRIX on stderr.
16060 GLYPHS 0 means don't show glyph contents.
16061 GLYPHS 1 means show glyphs in short form
16062 GLYPHS > 1 means show glyphs in long form. */
16065 dump_glyph_matrix (matrix
, glyphs
)
16066 struct glyph_matrix
*matrix
;
16070 for (i
= 0; i
< matrix
->nrows
; ++i
)
16071 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16075 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16076 the glyph row and area where the glyph comes from. */
16079 dump_glyph (row
, glyph
, area
)
16080 struct glyph_row
*row
;
16081 struct glyph
*glyph
;
16084 if (glyph
->type
== CHAR_GLYPH
)
16087 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16088 glyph
- row
->glyphs
[TEXT_AREA
],
16091 (BUFFERP (glyph
->object
)
16093 : (STRINGP (glyph
->object
)
16096 glyph
->pixel_width
,
16098 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16102 glyph
->left_box_line_p
,
16103 glyph
->right_box_line_p
);
16105 else if (glyph
->type
== STRETCH_GLYPH
)
16108 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16109 glyph
- row
->glyphs
[TEXT_AREA
],
16112 (BUFFERP (glyph
->object
)
16114 : (STRINGP (glyph
->object
)
16117 glyph
->pixel_width
,
16121 glyph
->left_box_line_p
,
16122 glyph
->right_box_line_p
);
16124 else if (glyph
->type
== IMAGE_GLYPH
)
16127 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16128 glyph
- row
->glyphs
[TEXT_AREA
],
16131 (BUFFERP (glyph
->object
)
16133 : (STRINGP (glyph
->object
)
16136 glyph
->pixel_width
,
16140 glyph
->left_box_line_p
,
16141 glyph
->right_box_line_p
);
16143 else if (glyph
->type
== COMPOSITE_GLYPH
)
16146 " %5d %4c %6d %c %3d 0x%05x",
16147 glyph
- row
->glyphs
[TEXT_AREA
],
16150 (BUFFERP (glyph
->object
)
16152 : (STRINGP (glyph
->object
)
16155 glyph
->pixel_width
,
16157 if (glyph
->u
.cmp
.automatic
)
16160 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
16161 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16163 glyph
->left_box_line_p
,
16164 glyph
->right_box_line_p
);
16169 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16170 GLYPHS 0 means don't show glyph contents.
16171 GLYPHS 1 means show glyphs in short form
16172 GLYPHS > 1 means show glyphs in long form. */
16175 dump_glyph_row (row
, vpos
, glyphs
)
16176 struct glyph_row
*row
;
16181 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16182 fprintf (stderr
, "======================================================================\n");
16184 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16185 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16187 MATRIX_ROW_START_CHARPOS (row
),
16188 MATRIX_ROW_END_CHARPOS (row
),
16189 row
->used
[TEXT_AREA
],
16190 row
->contains_overlapping_glyphs_p
,
16192 row
->truncated_on_left_p
,
16193 row
->truncated_on_right_p
,
16195 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16196 row
->displays_text_p
,
16199 row
->ends_in_middle_of_char_p
,
16200 row
->starts_in_middle_of_char_p
,
16206 row
->visible_height
,
16209 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16210 row
->end
.overlay_string_index
,
16211 row
->continuation_lines_width
);
16212 fprintf (stderr
, "%9d %5d\n",
16213 CHARPOS (row
->start
.string_pos
),
16214 CHARPOS (row
->end
.string_pos
));
16215 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16216 row
->end
.dpvec_index
);
16223 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16225 struct glyph
*glyph
= row
->glyphs
[area
];
16226 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16228 /* Glyph for a line end in text. */
16229 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16232 if (glyph
< glyph_end
)
16233 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16235 for (; glyph
< glyph_end
; ++glyph
)
16236 dump_glyph (row
, glyph
, area
);
16239 else if (glyphs
== 1)
16243 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16245 char *s
= (char *) alloca (row
->used
[area
] + 1);
16248 for (i
= 0; i
< row
->used
[area
]; ++i
)
16250 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16251 if (glyph
->type
== CHAR_GLYPH
16252 && glyph
->u
.ch
< 0x80
16253 && glyph
->u
.ch
>= ' ')
16254 s
[i
] = glyph
->u
.ch
;
16260 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16266 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16267 Sdump_glyph_matrix
, 0, 1, "p",
16268 doc
: /* Dump the current matrix of the selected window to stderr.
16269 Shows contents of glyph row structures. With non-nil
16270 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16271 glyphs in short form, otherwise show glyphs in long form. */)
16273 Lisp_Object glyphs
;
16275 struct window
*w
= XWINDOW (selected_window
);
16276 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16278 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16279 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16280 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16281 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16282 fprintf (stderr
, "=============================================\n");
16283 dump_glyph_matrix (w
->current_matrix
,
16284 NILP (glyphs
) ? 0 : XINT (glyphs
));
16289 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16290 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16293 struct frame
*f
= XFRAME (selected_frame
);
16294 dump_glyph_matrix (f
->current_matrix
, 1);
16299 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16300 doc
: /* Dump glyph row ROW to stderr.
16301 GLYPH 0 means don't dump glyphs.
16302 GLYPH 1 means dump glyphs in short form.
16303 GLYPH > 1 or omitted means dump glyphs in long form. */)
16305 Lisp_Object row
, glyphs
;
16307 struct glyph_matrix
*matrix
;
16310 CHECK_NUMBER (row
);
16311 matrix
= XWINDOW (selected_window
)->current_matrix
;
16313 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16314 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16316 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16321 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16322 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16323 GLYPH 0 means don't dump glyphs.
16324 GLYPH 1 means dump glyphs in short form.
16325 GLYPH > 1 or omitted means dump glyphs in long form. */)
16327 Lisp_Object row
, glyphs
;
16329 struct frame
*sf
= SELECTED_FRAME ();
16330 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16333 CHECK_NUMBER (row
);
16335 if (vpos
>= 0 && vpos
< m
->nrows
)
16336 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16337 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16342 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16343 doc
: /* Toggle tracing of redisplay.
16344 With ARG, turn tracing on if and only if ARG is positive. */)
16349 trace_redisplay_p
= !trace_redisplay_p
;
16352 arg
= Fprefix_numeric_value (arg
);
16353 trace_redisplay_p
= XINT (arg
) > 0;
16360 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16361 doc
: /* Like `format', but print result to stderr.
16362 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16367 Lisp_Object s
= Fformat (nargs
, args
);
16368 fprintf (stderr
, "%s", SDATA (s
));
16372 #endif /* GLYPH_DEBUG */
16376 /***********************************************************************
16377 Building Desired Matrix Rows
16378 ***********************************************************************/
16380 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16381 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16383 static struct glyph_row
*
16384 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
16386 Lisp_Object overlay_arrow_string
;
16388 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16389 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16390 struct buffer
*old
= current_buffer
;
16391 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16392 int arrow_len
= SCHARS (overlay_arrow_string
);
16393 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16394 const unsigned char *p
;
16397 int n_glyphs_before
;
16399 set_buffer_temp (buffer
);
16400 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16401 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16402 SET_TEXT_POS (it
.position
, 0, 0);
16404 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16406 while (p
< arrow_end
)
16408 Lisp_Object face
, ilisp
;
16410 /* Get the next character. */
16412 it
.c
= string_char_and_length (p
, &it
.len
);
16414 it
.c
= *p
, it
.len
= 1;
16417 /* Get its face. */
16418 ilisp
= make_number (p
- arrow_string
);
16419 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16420 it
.face_id
= compute_char_face (f
, it
.c
, face
);
16422 /* Compute its width, get its glyphs. */
16423 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16424 SET_TEXT_POS (it
.position
, -1, -1);
16425 PRODUCE_GLYPHS (&it
);
16427 /* If this character doesn't fit any more in the line, we have
16428 to remove some glyphs. */
16429 if (it
.current_x
> it
.last_visible_x
)
16431 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16436 set_buffer_temp (old
);
16437 return it
.glyph_row
;
16441 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16442 glyphs are only inserted for terminal frames since we can't really
16443 win with truncation glyphs when partially visible glyphs are
16444 involved. Which glyphs to insert is determined by
16445 produce_special_glyphs. */
16448 insert_left_trunc_glyphs (it
)
16451 struct it truncate_it
;
16452 struct glyph
*from
, *end
, *to
, *toend
;
16454 xassert (!FRAME_WINDOW_P (it
->f
));
16456 /* Get the truncation glyphs. */
16458 truncate_it
.current_x
= 0;
16459 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16460 truncate_it
.glyph_row
= &scratch_glyph_row
;
16461 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16462 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16463 truncate_it
.object
= make_number (0);
16464 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16466 /* Overwrite glyphs from IT with truncation glyphs. */
16467 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16468 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16469 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16470 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16475 /* There may be padding glyphs left over. Overwrite them too. */
16476 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16478 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16484 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16488 /* Compute the pixel height and width of IT->glyph_row.
16490 Most of the time, ascent and height of a display line will be equal
16491 to the max_ascent and max_height values of the display iterator
16492 structure. This is not the case if
16494 1. We hit ZV without displaying anything. In this case, max_ascent
16495 and max_height will be zero.
16497 2. We have some glyphs that don't contribute to the line height.
16498 (The glyph row flag contributes_to_line_height_p is for future
16499 pixmap extensions).
16501 The first case is easily covered by using default values because in
16502 these cases, the line height does not really matter, except that it
16503 must not be zero. */
16506 compute_line_metrics (it
)
16509 struct glyph_row
*row
= it
->glyph_row
;
16512 if (FRAME_WINDOW_P (it
->f
))
16514 int i
, min_y
, max_y
;
16516 /* The line may consist of one space only, that was added to
16517 place the cursor on it. If so, the row's height hasn't been
16519 if (row
->height
== 0)
16521 if (it
->max_ascent
+ it
->max_descent
== 0)
16522 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16523 row
->ascent
= it
->max_ascent
;
16524 row
->height
= it
->max_ascent
+ it
->max_descent
;
16525 row
->phys_ascent
= it
->max_phys_ascent
;
16526 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16527 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16530 /* Compute the width of this line. */
16531 row
->pixel_width
= row
->x
;
16532 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16533 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16535 xassert (row
->pixel_width
>= 0);
16536 xassert (row
->ascent
>= 0 && row
->height
> 0);
16538 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16539 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16541 /* If first line's physical ascent is larger than its logical
16542 ascent, use the physical ascent, and make the row taller.
16543 This makes accented characters fully visible. */
16544 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16545 && row
->phys_ascent
> row
->ascent
)
16547 row
->height
+= row
->phys_ascent
- row
->ascent
;
16548 row
->ascent
= row
->phys_ascent
;
16551 /* Compute how much of the line is visible. */
16552 row
->visible_height
= row
->height
;
16554 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16555 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16557 if (row
->y
< min_y
)
16558 row
->visible_height
-= min_y
- row
->y
;
16559 if (row
->y
+ row
->height
> max_y
)
16560 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16564 row
->pixel_width
= row
->used
[TEXT_AREA
];
16565 if (row
->continued_p
)
16566 row
->pixel_width
-= it
->continuation_pixel_width
;
16567 else if (row
->truncated_on_right_p
)
16568 row
->pixel_width
-= it
->truncation_pixel_width
;
16569 row
->ascent
= row
->phys_ascent
= 0;
16570 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16571 row
->extra_line_spacing
= 0;
16574 /* Compute a hash code for this row. */
16576 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16577 for (i
= 0; i
< row
->used
[area
]; ++i
)
16578 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16579 + row
->glyphs
[area
][i
].u
.val
16580 + row
->glyphs
[area
][i
].face_id
16581 + row
->glyphs
[area
][i
].padding_p
16582 + (row
->glyphs
[area
][i
].type
<< 2));
16584 it
->max_ascent
= it
->max_descent
= 0;
16585 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16589 /* Append one space to the glyph row of iterator IT if doing a
16590 window-based redisplay. The space has the same face as
16591 IT->face_id. Value is non-zero if a space was added.
16593 This function is called to make sure that there is always one glyph
16594 at the end of a glyph row that the cursor can be set on under
16595 window-systems. (If there weren't such a glyph we would not know
16596 how wide and tall a box cursor should be displayed).
16598 At the same time this space let's a nicely handle clearing to the
16599 end of the line if the row ends in italic text. */
16602 append_space_for_newline (it
, default_face_p
)
16604 int default_face_p
;
16606 if (FRAME_WINDOW_P (it
->f
))
16608 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16610 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16611 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16613 /* Save some values that must not be changed.
16614 Must save IT->c and IT->len because otherwise
16615 ITERATOR_AT_END_P wouldn't work anymore after
16616 append_space_for_newline has been called. */
16617 enum display_element_type saved_what
= it
->what
;
16618 int saved_c
= it
->c
, saved_len
= it
->len
;
16619 int saved_x
= it
->current_x
;
16620 int saved_face_id
= it
->face_id
;
16621 struct text_pos saved_pos
;
16622 Lisp_Object saved_object
;
16625 saved_object
= it
->object
;
16626 saved_pos
= it
->position
;
16628 it
->what
= IT_CHARACTER
;
16629 bzero (&it
->position
, sizeof it
->position
);
16630 it
->object
= make_number (0);
16634 if (default_face_p
)
16635 it
->face_id
= DEFAULT_FACE_ID
;
16636 else if (it
->face_before_selective_p
)
16637 it
->face_id
= it
->saved_face_id
;
16638 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16639 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16641 PRODUCE_GLYPHS (it
);
16643 it
->override_ascent
= -1;
16644 it
->constrain_row_ascent_descent_p
= 0;
16645 it
->current_x
= saved_x
;
16646 it
->object
= saved_object
;
16647 it
->position
= saved_pos
;
16648 it
->what
= saved_what
;
16649 it
->face_id
= saved_face_id
;
16650 it
->len
= saved_len
;
16660 /* Extend the face of the last glyph in the text area of IT->glyph_row
16661 to the end of the display line. Called from display_line.
16662 If the glyph row is empty, add a space glyph to it so that we
16663 know the face to draw. Set the glyph row flag fill_line_p. */
16666 extend_face_to_end_of_line (it
)
16670 struct frame
*f
= it
->f
;
16672 /* If line is already filled, do nothing. */
16673 if (it
->current_x
>= it
->last_visible_x
)
16676 /* Face extension extends the background and box of IT->face_id
16677 to the end of the line. If the background equals the background
16678 of the frame, we don't have to do anything. */
16679 if (it
->face_before_selective_p
)
16680 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16682 face
= FACE_FROM_ID (f
, it
->face_id
);
16684 if (FRAME_WINDOW_P (f
)
16685 && it
->glyph_row
->displays_text_p
16686 && face
->box
== FACE_NO_BOX
16687 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16691 /* Set the glyph row flag indicating that the face of the last glyph
16692 in the text area has to be drawn to the end of the text area. */
16693 it
->glyph_row
->fill_line_p
= 1;
16695 /* If current character of IT is not ASCII, make sure we have the
16696 ASCII face. This will be automatically undone the next time
16697 get_next_display_element returns a multibyte character. Note
16698 that the character will always be single byte in unibyte
16700 if (!ASCII_CHAR_P (it
->c
))
16702 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16705 if (FRAME_WINDOW_P (f
))
16707 /* If the row is empty, add a space with the current face of IT,
16708 so that we know which face to draw. */
16709 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16711 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16712 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16713 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16718 /* Save some values that must not be changed. */
16719 int saved_x
= it
->current_x
;
16720 struct text_pos saved_pos
;
16721 Lisp_Object saved_object
;
16722 enum display_element_type saved_what
= it
->what
;
16723 int saved_face_id
= it
->face_id
;
16725 saved_object
= it
->object
;
16726 saved_pos
= it
->position
;
16728 it
->what
= IT_CHARACTER
;
16729 bzero (&it
->position
, sizeof it
->position
);
16730 it
->object
= make_number (0);
16733 it
->face_id
= face
->id
;
16735 PRODUCE_GLYPHS (it
);
16737 while (it
->current_x
<= it
->last_visible_x
)
16738 PRODUCE_GLYPHS (it
);
16740 /* Don't count these blanks really. It would let us insert a left
16741 truncation glyph below and make us set the cursor on them, maybe. */
16742 it
->current_x
= saved_x
;
16743 it
->object
= saved_object
;
16744 it
->position
= saved_pos
;
16745 it
->what
= saved_what
;
16746 it
->face_id
= saved_face_id
;
16751 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16752 trailing whitespace. */
16755 trailing_whitespace_p (charpos
)
16758 int bytepos
= CHAR_TO_BYTE (charpos
);
16761 while (bytepos
< ZV_BYTE
16762 && (c
= FETCH_CHAR (bytepos
),
16763 c
== ' ' || c
== '\t'))
16766 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16768 if (bytepos
!= PT_BYTE
)
16775 /* Highlight trailing whitespace, if any, in ROW. */
16778 highlight_trailing_whitespace (f
, row
)
16780 struct glyph_row
*row
;
16782 int used
= row
->used
[TEXT_AREA
];
16786 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16787 struct glyph
*glyph
= start
+ used
- 1;
16789 /* Skip over glyphs inserted to display the cursor at the
16790 end of a line, for extending the face of the last glyph
16791 to the end of the line on terminals, and for truncation
16792 and continuation glyphs. */
16793 while (glyph
>= start
16794 && glyph
->type
== CHAR_GLYPH
16795 && INTEGERP (glyph
->object
))
16798 /* If last glyph is a space or stretch, and it's trailing
16799 whitespace, set the face of all trailing whitespace glyphs in
16800 IT->glyph_row to `trailing-whitespace'. */
16802 && BUFFERP (glyph
->object
)
16803 && (glyph
->type
== STRETCH_GLYPH
16804 || (glyph
->type
== CHAR_GLYPH
16805 && glyph
->u
.ch
== ' '))
16806 && trailing_whitespace_p (glyph
->charpos
))
16808 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16812 while (glyph
>= start
16813 && BUFFERP (glyph
->object
)
16814 && (glyph
->type
== STRETCH_GLYPH
16815 || (glyph
->type
== CHAR_GLYPH
16816 && glyph
->u
.ch
== ' ')))
16817 (glyph
--)->face_id
= face_id
;
16823 /* Value is non-zero if glyph row ROW in window W should be
16824 used to hold the cursor. */
16827 cursor_row_p (w
, row
)
16829 struct glyph_row
*row
;
16831 int cursor_row_p
= 1;
16833 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16835 /* Suppose the row ends on a string.
16836 Unless the row is continued, that means it ends on a newline
16837 in the string. If it's anything other than a display string
16838 (e.g. a before-string from an overlay), we don't want the
16839 cursor there. (This heuristic seems to give the optimal
16840 behavior for the various types of multi-line strings.) */
16841 if (CHARPOS (row
->end
.string_pos
) >= 0)
16843 if (row
->continued_p
)
16847 /* Check for `display' property. */
16848 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16849 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16850 struct glyph
*glyph
;
16853 for (glyph
= end
; glyph
>= beg
; --glyph
)
16854 if (STRINGP (glyph
->object
))
16857 = Fget_char_property (make_number (PT
),
16861 && display_prop_string_p (prop
, glyph
->object
));
16866 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16868 /* If the row ends in middle of a real character,
16869 and the line is continued, we want the cursor here.
16870 That's because MATRIX_ROW_END_CHARPOS would equal
16871 PT if PT is before the character. */
16872 if (!row
->ends_in_ellipsis_p
)
16873 cursor_row_p
= row
->continued_p
;
16875 /* If the row ends in an ellipsis, then
16876 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16877 We want that position to be displayed after the ellipsis. */
16880 /* If the row ends at ZV, display the cursor at the end of that
16881 row instead of at the start of the row below. */
16882 else if (row
->ends_at_zv_p
)
16888 return cursor_row_p
;
16893 /* Push the display property PROP so that it will be rendered at the
16894 current position in IT. Return 1 if PROP was successfully pushed,
16898 push_display_prop (struct it
*it
, Lisp_Object prop
)
16902 if (STRINGP (prop
))
16904 if (SCHARS (prop
) == 0)
16911 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16912 it
->current
.overlay_string_index
= -1;
16913 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16914 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16915 it
->method
= GET_FROM_STRING
;
16916 it
->stop_charpos
= 0;
16918 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16920 it
->method
= GET_FROM_STRETCH
;
16923 #ifdef HAVE_WINDOW_SYSTEM
16924 else if (IMAGEP (prop
))
16926 it
->what
= IT_IMAGE
;
16927 it
->image_id
= lookup_image (it
->f
, prop
);
16928 it
->method
= GET_FROM_IMAGE
;
16930 #endif /* HAVE_WINDOW_SYSTEM */
16933 pop_it (it
); /* bogus display property, give up */
16940 /* Return the character-property PROP at the current position in IT. */
16943 get_it_property (it
, prop
)
16947 Lisp_Object position
;
16949 if (STRINGP (it
->object
))
16950 position
= make_number (IT_STRING_CHARPOS (*it
));
16951 else if (BUFFERP (it
->object
))
16952 position
= make_number (IT_CHARPOS (*it
));
16956 return Fget_char_property (position
, prop
, it
->object
);
16959 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16962 handle_line_prefix (struct it
*it
)
16964 Lisp_Object prefix
;
16965 if (it
->continuation_lines_width
> 0)
16967 prefix
= get_it_property (it
, Qwrap_prefix
);
16969 prefix
= Vwrap_prefix
;
16973 prefix
= get_it_property (it
, Qline_prefix
);
16975 prefix
= Vline_prefix
;
16977 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
16979 /* If the prefix is wider than the window, and we try to wrap
16980 it, it would acquire its own wrap prefix, and so on till the
16981 iterator stack overflows. So, don't wrap the prefix. */
16982 it
->line_wrap
= TRUNCATE
;
16983 it
->avoid_cursor_p
= 1;
16989 /* Construct the glyph row IT->glyph_row in the desired matrix of
16990 IT->w from text at the current position of IT. See dispextern.h
16991 for an overview of struct it. Value is non-zero if
16992 IT->glyph_row displays text, as opposed to a line displaying ZV
16999 struct glyph_row
*row
= it
->glyph_row
;
17000 Lisp_Object overlay_arrow_string
;
17002 int may_wrap
= 0, wrap_x
;
17003 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
17004 int wrap_row_phys_ascent
, wrap_row_phys_height
;
17005 int wrap_row_extra_line_spacing
;
17006 struct display_pos row_end
;
17008 /* We always start displaying at hpos zero even if hscrolled. */
17009 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17011 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17012 >= it
->w
->desired_matrix
->nrows
)
17014 it
->w
->nrows_scale_factor
++;
17015 fonts_changed_p
= 1;
17019 /* Is IT->w showing the region? */
17020 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17022 /* Clear the result glyph row and enable it. */
17023 prepare_desired_row (row
);
17025 row
->y
= it
->current_y
;
17026 row
->start
= it
->start
;
17027 row
->continuation_lines_width
= it
->continuation_lines_width
;
17028 row
->displays_text_p
= 1;
17029 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17030 it
->starts_in_middle_of_char_p
= 0;
17031 /* If the paragraph base direction is R2L, its glyphs should be
17033 if (it
->bidi_p
&& (it
->bidi_it
.level_stack
[0].level
& 1) != 0)
17034 row
->reversed_p
= 1;
17036 /* Arrange the overlays nicely for our purposes. Usually, we call
17037 display_line on only one line at a time, in which case this
17038 can't really hurt too much, or we call it on lines which appear
17039 one after another in the buffer, in which case all calls to
17040 recenter_overlay_lists but the first will be pretty cheap. */
17041 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17043 /* Move over display elements that are not visible because we are
17044 hscrolled. This may stop at an x-position < IT->first_visible_x
17045 if the first glyph is partially visible or if we hit a line end. */
17046 if (it
->current_x
< it
->first_visible_x
)
17048 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17049 MOVE_TO_POS
| MOVE_TO_X
);
17053 /* We only do this when not calling `move_it_in_display_line_to'
17054 above, because move_it_in_display_line_to calls
17055 handle_line_prefix itself. */
17056 handle_line_prefix (it
);
17059 /* Get the initial row height. This is either the height of the
17060 text hscrolled, if there is any, or zero. */
17061 row
->ascent
= it
->max_ascent
;
17062 row
->height
= it
->max_ascent
+ it
->max_descent
;
17063 row
->phys_ascent
= it
->max_phys_ascent
;
17064 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17065 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17067 /* Loop generating characters. The loop is left with IT on the next
17068 character to display. */
17071 int n_glyphs_before
, hpos_before
, x_before
;
17073 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17075 /* Retrieve the next thing to display. Value is zero if end of
17077 if (!get_next_display_element (it
))
17079 /* Maybe add a space at the end of this line that is used to
17080 display the cursor there under X. Set the charpos of the
17081 first glyph of blank lines not corresponding to any text
17083 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17084 row
->exact_window_width_line_p
= 1;
17085 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17086 || row
->used
[TEXT_AREA
] == 0)
17088 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17089 row
->displays_text_p
= 0;
17091 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17092 && (!MINI_WINDOW_P (it
->w
)
17093 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17094 row
->indicate_empty_line_p
= 1;
17097 it
->continuation_lines_width
= 0;
17098 row
->ends_at_zv_p
= 1;
17099 /* A row that displays right-to-left text must always have
17100 its last face extended all the way to the end of line,
17101 even if this row ends in ZV. */
17102 if (row
->reversed_p
)
17103 extend_face_to_end_of_line (it
);
17104 row_end
= it
->current
;
17108 /* Now, get the metrics of what we want to display. This also
17109 generates glyphs in `row' (which is IT->glyph_row). */
17110 n_glyphs_before
= row
->used
[TEXT_AREA
];
17113 /* Remember the line height so far in case the next element doesn't
17114 fit on the line. */
17115 if (it
->line_wrap
!= TRUNCATE
)
17117 ascent
= it
->max_ascent
;
17118 descent
= it
->max_descent
;
17119 phys_ascent
= it
->max_phys_ascent
;
17120 phys_descent
= it
->max_phys_descent
;
17122 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17124 if (IT_DISPLAYING_WHITESPACE (it
))
17130 wrap_row_used
= row
->used
[TEXT_AREA
];
17131 wrap_row_ascent
= row
->ascent
;
17132 wrap_row_height
= row
->height
;
17133 wrap_row_phys_ascent
= row
->phys_ascent
;
17134 wrap_row_phys_height
= row
->phys_height
;
17135 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17141 PRODUCE_GLYPHS (it
);
17143 /* If this display element was in marginal areas, continue with
17145 if (it
->area
!= TEXT_AREA
)
17147 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17148 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17149 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17150 row
->phys_height
= max (row
->phys_height
,
17151 it
->max_phys_ascent
+ it
->max_phys_descent
);
17152 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17153 it
->max_extra_line_spacing
);
17154 set_iterator_to_next (it
, 1);
17158 /* Does the display element fit on the line? If we truncate
17159 lines, we should draw past the right edge of the window. If
17160 we don't truncate, we want to stop so that we can display the
17161 continuation glyph before the right margin. If lines are
17162 continued, there are two possible strategies for characters
17163 resulting in more than 1 glyph (e.g. tabs): Display as many
17164 glyphs as possible in this line and leave the rest for the
17165 continuation line, or display the whole element in the next
17166 line. Original redisplay did the former, so we do it also. */
17167 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17168 hpos_before
= it
->hpos
;
17171 if (/* Not a newline. */
17173 /* Glyphs produced fit entirely in the line. */
17174 && it
->current_x
< it
->last_visible_x
)
17176 it
->hpos
+= nglyphs
;
17177 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17178 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17179 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17180 row
->phys_height
= max (row
->phys_height
,
17181 it
->max_phys_ascent
+ it
->max_phys_descent
);
17182 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17183 it
->max_extra_line_spacing
);
17184 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17185 row
->x
= x
- it
->first_visible_x
;
17190 struct glyph
*glyph
;
17192 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17194 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17195 new_x
= x
+ glyph
->pixel_width
;
17197 if (/* Lines are continued. */
17198 it
->line_wrap
!= TRUNCATE
17199 && (/* Glyph doesn't fit on the line. */
17200 new_x
> it
->last_visible_x
17201 /* Or it fits exactly on a window system frame. */
17202 || (new_x
== it
->last_visible_x
17203 && FRAME_WINDOW_P (it
->f
))))
17205 /* End of a continued line. */
17208 || (new_x
== it
->last_visible_x
17209 && FRAME_WINDOW_P (it
->f
)))
17211 /* Current glyph is the only one on the line or
17212 fits exactly on the line. We must continue
17213 the line because we can't draw the cursor
17214 after the glyph. */
17215 row
->continued_p
= 1;
17216 it
->current_x
= new_x
;
17217 it
->continuation_lines_width
+= new_x
;
17219 if (i
== nglyphs
- 1)
17221 /* If line-wrap is on, check if a previous
17222 wrap point was found. */
17223 if (wrap_row_used
> 0
17224 /* Even if there is a previous wrap
17225 point, continue the line here as
17226 usual, if (i) the previous character
17227 was a space or tab AND (ii) the
17228 current character is not. */
17230 || IT_DISPLAYING_WHITESPACE (it
)))
17233 set_iterator_to_next (it
, 1);
17234 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17236 if (!get_next_display_element (it
))
17238 row
->exact_window_width_line_p
= 1;
17239 it
->continuation_lines_width
= 0;
17240 row
->continued_p
= 0;
17241 row
->ends_at_zv_p
= 1;
17243 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17245 row
->continued_p
= 0;
17246 row
->exact_window_width_line_p
= 1;
17251 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17252 && !FRAME_WINDOW_P (it
->f
))
17254 /* A padding glyph that doesn't fit on this line.
17255 This means the whole character doesn't fit
17257 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17259 /* Fill the rest of the row with continuation
17260 glyphs like in 20.x. */
17261 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17262 < row
->glyphs
[1 + TEXT_AREA
])
17263 produce_special_glyphs (it
, IT_CONTINUATION
);
17265 row
->continued_p
= 1;
17266 it
->current_x
= x_before
;
17267 it
->continuation_lines_width
+= x_before
;
17269 /* Restore the height to what it was before the
17270 element not fitting on the line. */
17271 it
->max_ascent
= ascent
;
17272 it
->max_descent
= descent
;
17273 it
->max_phys_ascent
= phys_ascent
;
17274 it
->max_phys_descent
= phys_descent
;
17276 else if (wrap_row_used
> 0)
17280 it
->continuation_lines_width
+= wrap_x
;
17281 row
->used
[TEXT_AREA
] = wrap_row_used
;
17282 row
->ascent
= wrap_row_ascent
;
17283 row
->height
= wrap_row_height
;
17284 row
->phys_ascent
= wrap_row_phys_ascent
;
17285 row
->phys_height
= wrap_row_phys_height
;
17286 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17287 row
->continued_p
= 1;
17288 row
->ends_at_zv_p
= 0;
17289 row
->exact_window_width_line_p
= 0;
17290 it
->continuation_lines_width
+= x
;
17292 /* Make sure that a non-default face is extended
17293 up to the right margin of the window. */
17294 extend_face_to_end_of_line (it
);
17296 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17298 /* A TAB that extends past the right edge of the
17299 window. This produces a single glyph on
17300 window system frames. We leave the glyph in
17301 this row and let it fill the row, but don't
17302 consume the TAB. */
17303 it
->continuation_lines_width
+= it
->last_visible_x
;
17304 row
->ends_in_middle_of_char_p
= 1;
17305 row
->continued_p
= 1;
17306 glyph
->pixel_width
= it
->last_visible_x
- x
;
17307 it
->starts_in_middle_of_char_p
= 1;
17311 /* Something other than a TAB that draws past
17312 the right edge of the window. Restore
17313 positions to values before the element. */
17314 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17316 /* Display continuation glyphs. */
17317 if (!FRAME_WINDOW_P (it
->f
))
17318 produce_special_glyphs (it
, IT_CONTINUATION
);
17319 row
->continued_p
= 1;
17321 it
->current_x
= x_before
;
17322 it
->continuation_lines_width
+= x
;
17323 extend_face_to_end_of_line (it
);
17325 if (nglyphs
> 1 && i
> 0)
17327 row
->ends_in_middle_of_char_p
= 1;
17328 it
->starts_in_middle_of_char_p
= 1;
17331 /* Restore the height to what it was before the
17332 element not fitting on the line. */
17333 it
->max_ascent
= ascent
;
17334 it
->max_descent
= descent
;
17335 it
->max_phys_ascent
= phys_ascent
;
17336 it
->max_phys_descent
= phys_descent
;
17339 row_end
= it
->current
;
17342 else if (new_x
> it
->first_visible_x
)
17344 /* Increment number of glyphs actually displayed. */
17347 if (x
< it
->first_visible_x
)
17348 /* Glyph is partially visible, i.e. row starts at
17349 negative X position. */
17350 row
->x
= x
- it
->first_visible_x
;
17354 /* Glyph is completely off the left margin of the
17355 window. This should not happen because of the
17356 move_it_in_display_line at the start of this
17357 function, unless the text display area of the
17358 window is empty. */
17359 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17363 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17364 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17365 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17366 row
->phys_height
= max (row
->phys_height
,
17367 it
->max_phys_ascent
+ it
->max_phys_descent
);
17368 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17369 it
->max_extra_line_spacing
);
17371 /* End of this display line if row is continued. */
17372 if (row
->continued_p
|| row
->ends_at_zv_p
)
17374 row_end
= it
->current
;
17380 /* Is this a line end? If yes, we're also done, after making
17381 sure that a non-default face is extended up to the right
17382 margin of the window. */
17383 if (ITERATOR_AT_END_OF_LINE_P (it
))
17385 int used_before
= row
->used
[TEXT_AREA
];
17387 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17389 /* Add a space at the end of the line that is used to
17390 display the cursor there. */
17391 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17392 append_space_for_newline (it
, 0);
17394 /* Extend the face to the end of the line. */
17395 extend_face_to_end_of_line (it
);
17397 /* Make sure we have the position. */
17398 if (used_before
== 0)
17399 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17401 /* Consume the line end. This skips over invisible lines. */
17404 /* When we are reordering bidi text, we still need the
17405 next character in logical order, to set row->end
17406 correctly below. */
17409 set_iterator_to_next (it
, 1);
17410 row_end
= it
->current
;
17414 set_iterator_to_next (it
, 1);
17415 it
->continuation_lines_width
= 0;
17417 row_end
= it
->current
;
17421 /* Proceed with next display element. Note that this skips
17422 over lines invisible because of selective display. */
17423 set_iterator_to_next (it
, 1);
17425 /* If we truncate lines, we are done when the last displayed
17426 glyphs reach past the right margin of the window. */
17427 if (it
->line_wrap
== TRUNCATE
17428 && (FRAME_WINDOW_P (it
->f
)
17429 ? (it
->current_x
>= it
->last_visible_x
)
17430 : (it
->current_x
> it
->last_visible_x
)))
17432 /* Maybe add truncation glyphs. */
17433 if (!FRAME_WINDOW_P (it
->f
))
17437 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17438 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17441 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17443 row
->used
[TEXT_AREA
] = i
;
17444 produce_special_glyphs (it
, IT_TRUNCATION
);
17447 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17449 /* Don't truncate if we can overflow newline into fringe. */
17450 if (!get_next_display_element (it
))
17452 it
->continuation_lines_width
= 0;
17453 row
->ends_at_zv_p
= 1;
17454 row
->exact_window_width_line_p
= 1;
17455 row_end
= it
->current
;
17458 if (ITERATOR_AT_END_OF_LINE_P (it
))
17460 row
->exact_window_width_line_p
= 1;
17461 goto at_end_of_line
;
17465 row
->truncated_on_right_p
= 1;
17466 it
->continuation_lines_width
= 0;
17467 reseat_at_next_visible_line_start (it
, 0);
17468 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17469 it
->hpos
= hpos_before
;
17470 it
->current_x
= x_before
;
17471 row_end
= it
->current
;
17476 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17477 at the left window margin. */
17478 if (it
->first_visible_x
17479 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
17481 if (!FRAME_WINDOW_P (it
->f
))
17482 insert_left_trunc_glyphs (it
);
17483 row
->truncated_on_left_p
= 1;
17486 /* If the start of this line is the overlay arrow-position, then
17487 mark this glyph row as the one containing the overlay arrow.
17488 This is clearly a mess with variable size fonts. It would be
17489 better to let it be displayed like cursors under X. */
17490 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17491 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17492 !NILP (overlay_arrow_string
)))
17494 /* Overlay arrow in window redisplay is a fringe bitmap. */
17495 if (STRINGP (overlay_arrow_string
))
17497 struct glyph_row
*arrow_row
17498 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17499 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17500 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17501 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17502 struct glyph
*p2
, *end
;
17504 /* Copy the arrow glyphs. */
17505 while (glyph
< arrow_end
)
17508 /* Throw away padding glyphs. */
17510 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17511 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17517 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17522 xassert (INTEGERP (overlay_arrow_string
));
17523 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17525 overlay_arrow_seen
= 1;
17528 /* Compute pixel dimensions of this line. */
17529 compute_line_metrics (it
);
17531 /* Remember the position at which this line ends. */
17532 row
->end
= row_end
;
17534 /* Record whether this row ends inside an ellipsis. */
17535 row
->ends_in_ellipsis_p
17536 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17537 && it
->ellipsis_p
);
17539 /* Save fringe bitmaps in this row. */
17540 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17541 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17542 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17543 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17545 it
->left_user_fringe_bitmap
= 0;
17546 it
->left_user_fringe_face_id
= 0;
17547 it
->right_user_fringe_bitmap
= 0;
17548 it
->right_user_fringe_face_id
= 0;
17550 /* Maybe set the cursor. */
17551 if (it
->w
->cursor
.vpos
< 0
17552 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17553 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17554 && cursor_row_p (it
->w
, row
))
17555 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17557 /* Highlight trailing whitespace. */
17558 if (!NILP (Vshow_trailing_whitespace
))
17559 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17561 /* Prepare for the next line. This line starts horizontally at (X
17562 HPOS) = (0 0). Vertical positions are incremented. As a
17563 convenience for the caller, IT->glyph_row is set to the next
17565 it
->current_x
= it
->hpos
= 0;
17566 it
->current_y
+= row
->height
;
17569 it
->start
= row_end
;
17570 return row
->displays_text_p
;
17575 /***********************************************************************
17577 ***********************************************************************/
17579 /* Redisplay the menu bar in the frame for window W.
17581 The menu bar of X frames that don't have X toolkit support is
17582 displayed in a special window W->frame->menu_bar_window.
17584 The menu bar of terminal frames is treated specially as far as
17585 glyph matrices are concerned. Menu bar lines are not part of
17586 windows, so the update is done directly on the frame matrix rows
17587 for the menu bar. */
17590 display_menu_bar (w
)
17593 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17598 /* Don't do all this for graphical frames. */
17600 if (FRAME_W32_P (f
))
17603 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17609 if (FRAME_NS_P (f
))
17611 #endif /* HAVE_NS */
17613 #ifdef USE_X_TOOLKIT
17614 xassert (!FRAME_WINDOW_P (f
));
17615 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17616 it
.first_visible_x
= 0;
17617 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17618 #else /* not USE_X_TOOLKIT */
17619 if (FRAME_WINDOW_P (f
))
17621 /* Menu bar lines are displayed in the desired matrix of the
17622 dummy window menu_bar_window. */
17623 struct window
*menu_w
;
17624 xassert (WINDOWP (f
->menu_bar_window
));
17625 menu_w
= XWINDOW (f
->menu_bar_window
);
17626 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17628 it
.first_visible_x
= 0;
17629 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17633 /* This is a TTY frame, i.e. character hpos/vpos are used as
17635 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17637 it
.first_visible_x
= 0;
17638 it
.last_visible_x
= FRAME_COLS (f
);
17640 #endif /* not USE_X_TOOLKIT */
17642 if (! mode_line_inverse_video
)
17643 /* Force the menu-bar to be displayed in the default face. */
17644 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17646 /* Clear all rows of the menu bar. */
17647 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17649 struct glyph_row
*row
= it
.glyph_row
+ i
;
17650 clear_glyph_row (row
);
17651 row
->enabled_p
= 1;
17652 row
->full_width_p
= 1;
17655 /* Display all items of the menu bar. */
17656 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17657 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17659 Lisp_Object string
;
17661 /* Stop at nil string. */
17662 string
= AREF (items
, i
+ 1);
17666 /* Remember where item was displayed. */
17667 ASET (items
, i
+ 3, make_number (it
.hpos
));
17669 /* Display the item, pad with one space. */
17670 if (it
.current_x
< it
.last_visible_x
)
17671 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17672 SCHARS (string
) + 1, 0, 0, -1);
17675 /* Fill out the line with spaces. */
17676 if (it
.current_x
< it
.last_visible_x
)
17677 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17679 /* Compute the total height of the lines. */
17680 compute_line_metrics (&it
);
17685 /***********************************************************************
17687 ***********************************************************************/
17689 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17690 FORCE is non-zero, redisplay mode lines unconditionally.
17691 Otherwise, redisplay only mode lines that are garbaged. Value is
17692 the number of windows whose mode lines were redisplayed. */
17695 redisplay_mode_lines (window
, force
)
17696 Lisp_Object window
;
17701 while (!NILP (window
))
17703 struct window
*w
= XWINDOW (window
);
17705 if (WINDOWP (w
->hchild
))
17706 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17707 else if (WINDOWP (w
->vchild
))
17708 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17710 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17711 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17713 struct text_pos lpoint
;
17714 struct buffer
*old
= current_buffer
;
17716 /* Set the window's buffer for the mode line display. */
17717 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17718 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17720 /* Point refers normally to the selected window. For any
17721 other window, set up appropriate value. */
17722 if (!EQ (window
, selected_window
))
17724 struct text_pos pt
;
17726 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17727 if (CHARPOS (pt
) < BEGV
)
17728 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17729 else if (CHARPOS (pt
) > (ZV
- 1))
17730 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17732 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17735 /* Display mode lines. */
17736 clear_glyph_matrix (w
->desired_matrix
);
17737 if (display_mode_lines (w
))
17740 w
->must_be_updated_p
= 1;
17743 /* Restore old settings. */
17744 set_buffer_internal_1 (old
);
17745 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17755 /* Display the mode and/or header line of window W. Value is the
17756 sum number of mode lines and header lines displayed. */
17759 display_mode_lines (w
)
17762 Lisp_Object old_selected_window
, old_selected_frame
;
17765 old_selected_frame
= selected_frame
;
17766 selected_frame
= w
->frame
;
17767 old_selected_window
= selected_window
;
17768 XSETWINDOW (selected_window
, w
);
17770 /* These will be set while the mode line specs are processed. */
17771 line_number_displayed
= 0;
17772 w
->column_number_displayed
= Qnil
;
17774 if (WINDOW_WANTS_MODELINE_P (w
))
17776 struct window
*sel_w
= XWINDOW (old_selected_window
);
17778 /* Select mode line face based on the real selected window. */
17779 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17780 current_buffer
->mode_line_format
);
17784 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17786 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17787 current_buffer
->header_line_format
);
17791 selected_frame
= old_selected_frame
;
17792 selected_window
= old_selected_window
;
17797 /* Display mode or header line of window W. FACE_ID specifies which
17798 line to display; it is either MODE_LINE_FACE_ID or
17799 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
17800 display. Value is the pixel height of the mode/header line
17804 display_mode_line (w
, face_id
, format
)
17806 enum face_id face_id
;
17807 Lisp_Object format
;
17811 int count
= SPECPDL_INDEX ();
17813 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17814 /* Don't extend on a previously drawn mode-line.
17815 This may happen if called from pos_visible_p. */
17816 it
.glyph_row
->enabled_p
= 0;
17817 prepare_desired_row (it
.glyph_row
);
17819 it
.glyph_row
->mode_line_p
= 1;
17821 if (! mode_line_inverse_video
)
17822 /* Force the mode-line to be displayed in the default face. */
17823 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17825 record_unwind_protect (unwind_format_mode_line
,
17826 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17828 mode_line_target
= MODE_LINE_DISPLAY
;
17830 /* Temporarily make frame's keyboard the current kboard so that
17831 kboard-local variables in the mode_line_format will get the right
17833 push_kboard (FRAME_KBOARD (it
.f
));
17834 record_unwind_save_match_data ();
17835 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17838 unbind_to (count
, Qnil
);
17840 /* Fill up with spaces. */
17841 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17843 compute_line_metrics (&it
);
17844 it
.glyph_row
->full_width_p
= 1;
17845 it
.glyph_row
->continued_p
= 0;
17846 it
.glyph_row
->truncated_on_left_p
= 0;
17847 it
.glyph_row
->truncated_on_right_p
= 0;
17849 /* Make a 3D mode-line have a shadow at its right end. */
17850 face
= FACE_FROM_ID (it
.f
, face_id
);
17851 extend_face_to_end_of_line (&it
);
17852 if (face
->box
!= FACE_NO_BOX
)
17854 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17855 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17856 last
->right_box_line_p
= 1;
17859 return it
.glyph_row
->height
;
17862 /* Move element ELT in LIST to the front of LIST.
17863 Return the updated list. */
17866 move_elt_to_front (elt
, list
)
17867 Lisp_Object elt
, list
;
17869 register Lisp_Object tail
, prev
;
17870 register Lisp_Object tem
;
17874 while (CONSP (tail
))
17880 /* Splice out the link TAIL. */
17882 list
= XCDR (tail
);
17884 Fsetcdr (prev
, XCDR (tail
));
17886 /* Now make it the first. */
17887 Fsetcdr (tail
, list
);
17892 tail
= XCDR (tail
);
17896 /* Not found--return unchanged LIST. */
17900 /* Contribute ELT to the mode line for window IT->w. How it
17901 translates into text depends on its data type.
17903 IT describes the display environment in which we display, as usual.
17905 DEPTH is the depth in recursion. It is used to prevent
17906 infinite recursion here.
17908 FIELD_WIDTH is the number of characters the display of ELT should
17909 occupy in the mode line, and PRECISION is the maximum number of
17910 characters to display from ELT's representation. See
17911 display_string for details.
17913 Returns the hpos of the end of the text generated by ELT.
17915 PROPS is a property list to add to any string we encounter.
17917 If RISKY is nonzero, remove (disregard) any properties in any string
17918 we encounter, and ignore :eval and :propertize.
17920 The global variable `mode_line_target' determines whether the
17921 output is passed to `store_mode_line_noprop',
17922 `store_mode_line_string', or `display_string'. */
17925 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17928 int field_width
, precision
;
17929 Lisp_Object elt
, props
;
17932 int n
= 0, field
, prec
;
17937 elt
= build_string ("*too-deep*");
17941 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17945 /* A string: output it and check for %-constructs within it. */
17949 if (SCHARS (elt
) > 0
17950 && (!NILP (props
) || risky
))
17952 Lisp_Object oprops
, aelt
;
17953 oprops
= Ftext_properties_at (make_number (0), elt
);
17955 /* If the starting string's properties are not what
17956 we want, translate the string. Also, if the string
17957 is risky, do that anyway. */
17959 if (NILP (Fequal (props
, oprops
)) || risky
)
17961 /* If the starting string has properties,
17962 merge the specified ones onto the existing ones. */
17963 if (! NILP (oprops
) && !risky
)
17967 oprops
= Fcopy_sequence (oprops
);
17969 while (CONSP (tem
))
17971 oprops
= Fplist_put (oprops
, XCAR (tem
),
17972 XCAR (XCDR (tem
)));
17973 tem
= XCDR (XCDR (tem
));
17978 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17979 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17981 /* AELT is what we want. Move it to the front
17982 without consing. */
17984 mode_line_proptrans_alist
17985 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17991 /* If AELT has the wrong props, it is useless.
17992 so get rid of it. */
17994 mode_line_proptrans_alist
17995 = Fdelq (aelt
, mode_line_proptrans_alist
);
17997 elt
= Fcopy_sequence (elt
);
17998 Fset_text_properties (make_number (0), Flength (elt
),
18000 /* Add this item to mode_line_proptrans_alist. */
18001 mode_line_proptrans_alist
18002 = Fcons (Fcons (elt
, props
),
18003 mode_line_proptrans_alist
);
18004 /* Truncate mode_line_proptrans_alist
18005 to at most 50 elements. */
18006 tem
= Fnthcdr (make_number (50),
18007 mode_line_proptrans_alist
);
18009 XSETCDR (tem
, Qnil
);
18018 prec
= precision
- n
;
18019 switch (mode_line_target
)
18021 case MODE_LINE_NOPROP
:
18022 case MODE_LINE_TITLE
:
18023 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
18025 case MODE_LINE_STRING
:
18026 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18028 case MODE_LINE_DISPLAY
:
18029 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18030 0, prec
, 0, STRING_MULTIBYTE (elt
));
18037 /* Handle the non-literal case. */
18039 while ((precision
<= 0 || n
< precision
)
18040 && SREF (elt
, offset
) != 0
18041 && (mode_line_target
!= MODE_LINE_DISPLAY
18042 || it
->current_x
< it
->last_visible_x
))
18044 int last_offset
= offset
;
18046 /* Advance to end of string or next format specifier. */
18047 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18050 if (offset
- 1 != last_offset
)
18052 int nchars
, nbytes
;
18054 /* Output to end of string or up to '%'. Field width
18055 is length of string. Don't output more than
18056 PRECISION allows us. */
18059 prec
= c_string_width (SDATA (elt
) + last_offset
,
18060 offset
- last_offset
, precision
- n
,
18063 switch (mode_line_target
)
18065 case MODE_LINE_NOPROP
:
18066 case MODE_LINE_TITLE
:
18067 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18069 case MODE_LINE_STRING
:
18071 int bytepos
= last_offset
;
18072 int charpos
= string_byte_to_char (elt
, bytepos
);
18073 int endpos
= (precision
<= 0
18074 ? string_byte_to_char (elt
, offset
)
18075 : charpos
+ nchars
);
18077 n
+= store_mode_line_string (NULL
,
18078 Fsubstring (elt
, make_number (charpos
),
18079 make_number (endpos
)),
18083 case MODE_LINE_DISPLAY
:
18085 int bytepos
= last_offset
;
18086 int charpos
= string_byte_to_char (elt
, bytepos
);
18088 if (precision
<= 0)
18089 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18090 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18092 STRING_MULTIBYTE (elt
));
18097 else /* c == '%' */
18099 int percent_position
= offset
;
18101 /* Get the specified minimum width. Zero means
18104 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18105 field
= field
* 10 + c
- '0';
18107 /* Don't pad beyond the total padding allowed. */
18108 if (field_width
- n
> 0 && field
> field_width
- n
)
18109 field
= field_width
- n
;
18111 /* Note that either PRECISION <= 0 or N < PRECISION. */
18112 prec
= precision
- n
;
18115 n
+= display_mode_element (it
, depth
, field
, prec
,
18116 Vglobal_mode_string
, props
,
18121 int bytepos
, charpos
;
18122 unsigned char *spec
;
18123 Lisp_Object string
;
18125 bytepos
= percent_position
;
18126 charpos
= (STRING_MULTIBYTE (elt
)
18127 ? string_byte_to_char (elt
, bytepos
)
18129 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
18130 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18132 switch (mode_line_target
)
18134 case MODE_LINE_NOPROP
:
18135 case MODE_LINE_TITLE
:
18136 n
+= store_mode_line_noprop (spec
, field
, prec
);
18138 case MODE_LINE_STRING
:
18140 int len
= strlen (spec
);
18141 Lisp_Object tem
= make_string (spec
, len
);
18142 props
= Ftext_properties_at (make_number (charpos
), elt
);
18143 /* Should only keep face property in props */
18144 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18147 case MODE_LINE_DISPLAY
:
18149 int nglyphs_before
, nwritten
;
18151 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18152 nwritten
= display_string (spec
, string
, elt
,
18157 /* Assign to the glyphs written above the
18158 string where the `%x' came from, position
18162 struct glyph
*glyph
18163 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18167 for (i
= 0; i
< nwritten
; ++i
)
18169 glyph
[i
].object
= elt
;
18170 glyph
[i
].charpos
= charpos
;
18187 /* A symbol: process the value of the symbol recursively
18188 as if it appeared here directly. Avoid error if symbol void.
18189 Special case: if value of symbol is a string, output the string
18192 register Lisp_Object tem
;
18194 /* If the variable is not marked as risky to set
18195 then its contents are risky to use. */
18196 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18199 tem
= Fboundp (elt
);
18202 tem
= Fsymbol_value (elt
);
18203 /* If value is a string, output that string literally:
18204 don't check for % within it. */
18208 if (!EQ (tem
, elt
))
18210 /* Give up right away for nil or t. */
18220 register Lisp_Object car
, tem
;
18222 /* A cons cell: five distinct cases.
18223 If first element is :eval or :propertize, do something special.
18224 If first element is a string or a cons, process all the elements
18225 and effectively concatenate them.
18226 If first element is a negative number, truncate displaying cdr to
18227 at most that many characters. If positive, pad (with spaces)
18228 to at least that many characters.
18229 If first element is a symbol, process the cadr or caddr recursively
18230 according to whether the symbol's value is non-nil or nil. */
18232 if (EQ (car
, QCeval
))
18234 /* An element of the form (:eval FORM) means evaluate FORM
18235 and use the result as mode line elements. */
18240 if (CONSP (XCDR (elt
)))
18243 spec
= safe_eval (XCAR (XCDR (elt
)));
18244 n
+= display_mode_element (it
, depth
, field_width
- n
,
18245 precision
- n
, spec
, props
,
18249 else if (EQ (car
, QCpropertize
))
18251 /* An element of the form (:propertize ELT PROPS...)
18252 means display ELT but applying properties PROPS. */
18257 if (CONSP (XCDR (elt
)))
18258 n
+= display_mode_element (it
, depth
, field_width
- n
,
18259 precision
- n
, XCAR (XCDR (elt
)),
18260 XCDR (XCDR (elt
)), risky
);
18262 else if (SYMBOLP (car
))
18264 tem
= Fboundp (car
);
18268 /* elt is now the cdr, and we know it is a cons cell.
18269 Use its car if CAR has a non-nil value. */
18272 tem
= Fsymbol_value (car
);
18279 /* Symbol's value is nil (or symbol is unbound)
18280 Get the cddr of the original list
18281 and if possible find the caddr and use that. */
18285 else if (!CONSP (elt
))
18290 else if (INTEGERP (car
))
18292 register int lim
= XINT (car
);
18296 /* Negative int means reduce maximum width. */
18297 if (precision
<= 0)
18300 precision
= min (precision
, -lim
);
18304 /* Padding specified. Don't let it be more than
18305 current maximum. */
18307 lim
= min (precision
, lim
);
18309 /* If that's more padding than already wanted, queue it.
18310 But don't reduce padding already specified even if
18311 that is beyond the current truncation point. */
18312 field_width
= max (lim
, field_width
);
18316 else if (STRINGP (car
) || CONSP (car
))
18318 Lisp_Object halftail
= elt
;
18322 && (precision
<= 0 || n
< precision
))
18324 n
+= display_mode_element (it
, depth
,
18325 /* Do padding only after the last
18326 element in the list. */
18327 (! CONSP (XCDR (elt
))
18330 precision
- n
, XCAR (elt
),
18334 if ((len
& 1) == 0)
18335 halftail
= XCDR (halftail
);
18336 /* Check for cycle. */
18337 if (EQ (halftail
, elt
))
18346 elt
= build_string ("*invalid*");
18350 /* Pad to FIELD_WIDTH. */
18351 if (field_width
> 0 && n
< field_width
)
18353 switch (mode_line_target
)
18355 case MODE_LINE_NOPROP
:
18356 case MODE_LINE_TITLE
:
18357 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18359 case MODE_LINE_STRING
:
18360 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18362 case MODE_LINE_DISPLAY
:
18363 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18372 /* Store a mode-line string element in mode_line_string_list.
18374 If STRING is non-null, display that C string. Otherwise, the Lisp
18375 string LISP_STRING is displayed.
18377 FIELD_WIDTH is the minimum number of output glyphs to produce.
18378 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18379 with spaces. FIELD_WIDTH <= 0 means don't pad.
18381 PRECISION is the maximum number of characters to output from
18382 STRING. PRECISION <= 0 means don't truncate the string.
18384 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18385 properties to the string.
18387 PROPS are the properties to add to the string.
18388 The mode_line_string_face face property is always added to the string.
18392 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
18394 Lisp_Object lisp_string
;
18403 if (string
!= NULL
)
18405 len
= strlen (string
);
18406 if (precision
> 0 && len
> precision
)
18408 lisp_string
= make_string (string
, len
);
18410 props
= mode_line_string_face_prop
;
18411 else if (!NILP (mode_line_string_face
))
18413 Lisp_Object face
= Fplist_get (props
, Qface
);
18414 props
= Fcopy_sequence (props
);
18416 face
= mode_line_string_face
;
18418 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18419 props
= Fplist_put (props
, Qface
, face
);
18421 Fadd_text_properties (make_number (0), make_number (len
),
18422 props
, lisp_string
);
18426 len
= XFASTINT (Flength (lisp_string
));
18427 if (precision
> 0 && len
> precision
)
18430 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
18433 if (!NILP (mode_line_string_face
))
18437 props
= Ftext_properties_at (make_number (0), lisp_string
);
18438 face
= Fplist_get (props
, Qface
);
18440 face
= mode_line_string_face
;
18442 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18443 props
= Fcons (Qface
, Fcons (face
, Qnil
));
18445 lisp_string
= Fcopy_sequence (lisp_string
);
18448 Fadd_text_properties (make_number (0), make_number (len
),
18449 props
, lisp_string
);
18454 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18458 if (field_width
> len
)
18460 field_width
-= len
;
18461 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
18463 Fadd_text_properties (make_number (0), make_number (field_width
),
18464 props
, lisp_string
);
18465 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18473 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
18475 doc
: /* Format a string out of a mode line format specification.
18476 First arg FORMAT specifies the mode line format (see `mode-line-format'
18477 for details) to use.
18479 Optional second arg FACE specifies the face property to put
18480 on all characters for which no face is specified.
18481 The value t means whatever face the window's mode line currently uses
18482 \(either `mode-line' or `mode-line-inactive', depending).
18483 A value of nil means the default is no face property.
18484 If FACE is an integer, the value string has no text properties.
18486 Optional third and fourth args WINDOW and BUFFER specify the window
18487 and buffer to use as the context for the formatting (defaults
18488 are the selected window and the window's buffer). */)
18489 (format
, face
, window
, buffer
)
18490 Lisp_Object format
, face
, window
, buffer
;
18495 struct buffer
*old_buffer
= NULL
;
18497 int no_props
= INTEGERP (face
);
18498 int count
= SPECPDL_INDEX ();
18500 int string_start
= 0;
18503 window
= selected_window
;
18504 CHECK_WINDOW (window
);
18505 w
= XWINDOW (window
);
18508 buffer
= w
->buffer
;
18509 CHECK_BUFFER (buffer
);
18511 /* Make formatting the modeline a non-op when noninteractive, otherwise
18512 there will be problems later caused by a partially initialized frame. */
18513 if (NILP (format
) || noninteractive
)
18514 return empty_unibyte_string
;
18522 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
18523 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
18527 face_id
= DEFAULT_FACE_ID
;
18529 if (XBUFFER (buffer
) != current_buffer
)
18530 old_buffer
= current_buffer
;
18532 /* Save things including mode_line_proptrans_alist,
18533 and set that to nil so that we don't alter the outer value. */
18534 record_unwind_protect (unwind_format_mode_line
,
18535 format_mode_line_unwind_data
18536 (old_buffer
, selected_window
, 1));
18537 mode_line_proptrans_alist
= Qnil
;
18539 Fselect_window (window
, Qt
);
18541 set_buffer_internal_1 (XBUFFER (buffer
));
18543 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18547 mode_line_target
= MODE_LINE_NOPROP
;
18548 mode_line_string_face_prop
= Qnil
;
18549 mode_line_string_list
= Qnil
;
18550 string_start
= MODE_LINE_NOPROP_LEN (0);
18554 mode_line_target
= MODE_LINE_STRING
;
18555 mode_line_string_list
= Qnil
;
18556 mode_line_string_face
= face
;
18557 mode_line_string_face_prop
18558 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18561 push_kboard (FRAME_KBOARD (it
.f
));
18562 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18567 len
= MODE_LINE_NOPROP_LEN (string_start
);
18568 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18572 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18573 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18574 empty_unibyte_string
);
18577 unbind_to (count
, Qnil
);
18581 /* Write a null-terminated, right justified decimal representation of
18582 the positive integer D to BUF using a minimal field width WIDTH. */
18585 pint2str (buf
, width
, d
)
18586 register char *buf
;
18587 register int width
;
18590 register char *p
= buf
;
18598 *p
++ = d
% 10 + '0';
18603 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18614 /* Write a null-terminated, right justified decimal and "human
18615 readable" representation of the nonnegative integer D to BUF using
18616 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18618 static const char power_letter
[] =
18632 pint2hrstr (buf
, width
, d
)
18637 /* We aim to represent the nonnegative integer D as
18638 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18641 /* -1 means: do not use TENTHS. */
18645 /* Length of QUOTIENT.TENTHS as a string. */
18651 if (1000 <= quotient
)
18653 /* Scale to the appropriate EXPONENT. */
18656 remainder
= quotient
% 1000;
18660 while (1000 <= quotient
);
18662 /* Round to nearest and decide whether to use TENTHS or not. */
18665 tenths
= remainder
/ 100;
18666 if (50 <= remainder
% 100)
18673 if (quotient
== 10)
18681 if (500 <= remainder
)
18683 if (quotient
< 999)
18694 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18695 if (tenths
== -1 && quotient
<= 99)
18702 p
= psuffix
= buf
+ max (width
, length
);
18704 /* Print EXPONENT. */
18706 *psuffix
++ = power_letter
[exponent
];
18709 /* Print TENTHS. */
18712 *--p
= '0' + tenths
;
18716 /* Print QUOTIENT. */
18719 int digit
= quotient
% 10;
18720 *--p
= '0' + digit
;
18722 while ((quotient
/= 10) != 0);
18724 /* Print leading spaces. */
18729 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18730 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18731 type of CODING_SYSTEM. Return updated pointer into BUF. */
18733 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18736 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18737 Lisp_Object coding_system
;
18738 register char *buf
;
18742 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18743 const unsigned char *eol_str
;
18745 /* The EOL conversion we are using. */
18746 Lisp_Object eoltype
;
18748 val
= CODING_SYSTEM_SPEC (coding_system
);
18751 if (!VECTORP (val
)) /* Not yet decided. */
18756 eoltype
= eol_mnemonic_undecided
;
18757 /* Don't mention EOL conversion if it isn't decided. */
18762 Lisp_Object eolvalue
;
18764 attrs
= AREF (val
, 0);
18765 eolvalue
= AREF (val
, 2);
18768 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18772 /* The EOL conversion that is normal on this system. */
18774 if (NILP (eolvalue
)) /* Not yet decided. */
18775 eoltype
= eol_mnemonic_undecided
;
18776 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18777 eoltype
= eol_mnemonic_undecided
;
18778 else /* eolvalue is Qunix, Qdos, or Qmac. */
18779 eoltype
= (EQ (eolvalue
, Qunix
)
18780 ? eol_mnemonic_unix
18781 : (EQ (eolvalue
, Qdos
) == 1
18782 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18788 /* Mention the EOL conversion if it is not the usual one. */
18789 if (STRINGP (eoltype
))
18791 eol_str
= SDATA (eoltype
);
18792 eol_str_len
= SBYTES (eoltype
);
18794 else if (CHARACTERP (eoltype
))
18796 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18797 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18802 eol_str
= invalid_eol_type
;
18803 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18805 bcopy (eol_str
, buf
, eol_str_len
);
18806 buf
+= eol_str_len
;
18812 /* Return a string for the output of a mode line %-spec for window W,
18813 generated by character C. PRECISION >= 0 means don't return a
18814 string longer than that value. FIELD_WIDTH > 0 means pad the
18815 string returned with spaces to that value. Return a Lisp string in
18816 *STRING if the resulting string is taken from that Lisp string.
18818 Note we operate on the current buffer for most purposes,
18819 the exception being w->base_line_pos. */
18821 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18824 decode_mode_spec (w
, c
, field_width
, precision
, string
)
18827 int field_width
, precision
;
18828 Lisp_Object
*string
;
18831 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18832 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18833 struct buffer
*b
= current_buffer
;
18841 if (!NILP (b
->read_only
))
18843 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18848 /* This differs from %* only for a modified read-only buffer. */
18849 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18851 if (!NILP (b
->read_only
))
18856 /* This differs from %* in ignoring read-only-ness. */
18857 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18869 if (command_loop_level
> 5)
18871 p
= decode_mode_spec_buf
;
18872 for (i
= 0; i
< command_loop_level
; i
++)
18875 return decode_mode_spec_buf
;
18883 if (command_loop_level
> 5)
18885 p
= decode_mode_spec_buf
;
18886 for (i
= 0; i
< command_loop_level
; i
++)
18889 return decode_mode_spec_buf
;
18896 /* Let lots_of_dashes be a string of infinite length. */
18897 if (mode_line_target
== MODE_LINE_NOPROP
||
18898 mode_line_target
== MODE_LINE_STRING
)
18900 if (field_width
<= 0
18901 || field_width
> sizeof (lots_of_dashes
))
18903 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18904 decode_mode_spec_buf
[i
] = '-';
18905 decode_mode_spec_buf
[i
] = '\0';
18906 return decode_mode_spec_buf
;
18909 return lots_of_dashes
;
18917 /* %c and %l are ignored in `frame-title-format'.
18918 (In redisplay_internal, the frame title is drawn _before_ the
18919 windows are updated, so the stuff which depends on actual
18920 window contents (such as %l) may fail to render properly, or
18921 even crash emacs.) */
18922 if (mode_line_target
== MODE_LINE_TITLE
)
18926 int col
= (int) current_column (); /* iftc */
18927 w
->column_number_displayed
= make_number (col
);
18928 pint2str (decode_mode_spec_buf
, field_width
, col
);
18929 return decode_mode_spec_buf
;
18933 #ifndef SYSTEM_MALLOC
18935 if (NILP (Vmemory_full
))
18938 return "!MEM FULL! ";
18945 /* %F displays the frame name. */
18946 if (!NILP (f
->title
))
18947 return (char *) SDATA (f
->title
);
18948 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18949 return (char *) SDATA (f
->name
);
18958 int size
= ZV
- BEGV
;
18959 pint2str (decode_mode_spec_buf
, field_width
, size
);
18960 return decode_mode_spec_buf
;
18965 int size
= ZV
- BEGV
;
18966 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18967 return decode_mode_spec_buf
;
18972 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18973 int topline
, nlines
, junk
, height
;
18975 /* %c and %l are ignored in `frame-title-format'. */
18976 if (mode_line_target
== MODE_LINE_TITLE
)
18979 startpos
= XMARKER (w
->start
)->charpos
;
18980 startpos_byte
= marker_byte_position (w
->start
);
18981 height
= WINDOW_TOTAL_LINES (w
);
18983 /* If we decided that this buffer isn't suitable for line numbers,
18984 don't forget that too fast. */
18985 if (EQ (w
->base_line_pos
, w
->buffer
))
18987 /* But do forget it, if the window shows a different buffer now. */
18988 else if (BUFFERP (w
->base_line_pos
))
18989 w
->base_line_pos
= Qnil
;
18991 /* If the buffer is very big, don't waste time. */
18992 if (INTEGERP (Vline_number_display_limit
)
18993 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18995 w
->base_line_pos
= Qnil
;
18996 w
->base_line_number
= Qnil
;
19000 if (INTEGERP (w
->base_line_number
)
19001 && INTEGERP (w
->base_line_pos
)
19002 && XFASTINT (w
->base_line_pos
) <= startpos
)
19004 line
= XFASTINT (w
->base_line_number
);
19005 linepos
= XFASTINT (w
->base_line_pos
);
19006 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19011 linepos
= BUF_BEGV (b
);
19012 linepos_byte
= BUF_BEGV_BYTE (b
);
19015 /* Count lines from base line to window start position. */
19016 nlines
= display_count_lines (linepos
, linepos_byte
,
19020 topline
= nlines
+ line
;
19022 /* Determine a new base line, if the old one is too close
19023 or too far away, or if we did not have one.
19024 "Too close" means it's plausible a scroll-down would
19025 go back past it. */
19026 if (startpos
== BUF_BEGV (b
))
19028 w
->base_line_number
= make_number (topline
);
19029 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19031 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19032 || linepos
== BUF_BEGV (b
))
19034 int limit
= BUF_BEGV (b
);
19035 int limit_byte
= BUF_BEGV_BYTE (b
);
19037 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
19039 if (startpos
- distance
> limit
)
19041 limit
= startpos
- distance
;
19042 limit_byte
= CHAR_TO_BYTE (limit
);
19045 nlines
= display_count_lines (startpos
, startpos_byte
,
19047 - (height
* 2 + 30),
19049 /* If we couldn't find the lines we wanted within
19050 line_number_display_limit_width chars per line,
19051 give up on line numbers for this window. */
19052 if (position
== limit_byte
&& limit
== startpos
- distance
)
19054 w
->base_line_pos
= w
->buffer
;
19055 w
->base_line_number
= Qnil
;
19059 w
->base_line_number
= make_number (topline
- nlines
);
19060 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19063 /* Now count lines from the start pos to point. */
19064 nlines
= display_count_lines (startpos
, startpos_byte
,
19065 PT_BYTE
, PT
, &junk
);
19067 /* Record that we did display the line number. */
19068 line_number_displayed
= 1;
19070 /* Make the string to show. */
19071 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19072 return decode_mode_spec_buf
;
19075 char* p
= decode_mode_spec_buf
;
19076 int pad
= field_width
- 2;
19082 return decode_mode_spec_buf
;
19088 obj
= b
->mode_name
;
19092 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19098 int pos
= marker_position (w
->start
);
19099 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19101 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19103 if (pos
<= BUF_BEGV (b
))
19108 else if (pos
<= BUF_BEGV (b
))
19112 if (total
> 1000000)
19113 /* Do it differently for a large value, to avoid overflow. */
19114 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19116 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19117 /* We can't normally display a 3-digit number,
19118 so get us a 2-digit number that is close. */
19121 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19122 return decode_mode_spec_buf
;
19126 /* Display percentage of size above the bottom of the screen. */
19129 int toppos
= marker_position (w
->start
);
19130 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19131 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19133 if (botpos
>= BUF_ZV (b
))
19135 if (toppos
<= BUF_BEGV (b
))
19142 if (total
> 1000000)
19143 /* Do it differently for a large value, to avoid overflow. */
19144 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19146 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19147 /* We can't normally display a 3-digit number,
19148 so get us a 2-digit number that is close. */
19151 if (toppos
<= BUF_BEGV (b
))
19152 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
19154 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19155 return decode_mode_spec_buf
;
19160 /* status of process */
19161 obj
= Fget_buffer_process (Fcurrent_buffer ());
19163 return "no process";
19164 #ifdef subprocesses
19165 obj
= Fsymbol_name (Fprocess_status (obj
));
19171 int count
= inhibit_garbage_collection ();
19172 Lisp_Object val
= call1 (intern ("file-remote-p"),
19173 current_buffer
->directory
);
19174 unbind_to (count
, Qnil
);
19182 case 't': /* indicate TEXT or BINARY */
19183 #ifdef MODE_LINE_BINARY_TEXT
19184 return MODE_LINE_BINARY_TEXT (b
);
19190 /* coding-system (not including end-of-line format) */
19192 /* coding-system (including end-of-line type) */
19194 int eol_flag
= (c
== 'Z');
19195 char *p
= decode_mode_spec_buf
;
19197 if (! FRAME_WINDOW_P (f
))
19199 /* No need to mention EOL here--the terminal never needs
19200 to do EOL conversion. */
19201 p
= decode_mode_spec_coding (CODING_ID_NAME
19202 (FRAME_KEYBOARD_CODING (f
)->id
),
19204 p
= decode_mode_spec_coding (CODING_ID_NAME
19205 (FRAME_TERMINAL_CODING (f
)->id
),
19208 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19211 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19212 #ifdef subprocesses
19213 obj
= Fget_buffer_process (Fcurrent_buffer ());
19214 if (PROCESSP (obj
))
19216 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19218 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19221 #endif /* subprocesses */
19224 return decode_mode_spec_buf
;
19231 return (char *) SDATA (obj
);
19238 /* Count up to COUNT lines starting from START / START_BYTE.
19239 But don't go beyond LIMIT_BYTE.
19240 Return the number of lines thus found (always nonnegative).
19242 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19245 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
19246 int start
, start_byte
, limit_byte
, count
;
19249 register unsigned char *cursor
;
19250 unsigned char *base
;
19252 register int ceiling
;
19253 register unsigned char *ceiling_addr
;
19254 int orig_count
= count
;
19256 /* If we are not in selective display mode,
19257 check only for newlines. */
19258 int selective_display
= (!NILP (current_buffer
->selective_display
)
19259 && !INTEGERP (current_buffer
->selective_display
));
19263 while (start_byte
< limit_byte
)
19265 ceiling
= BUFFER_CEILING_OF (start_byte
);
19266 ceiling
= min (limit_byte
- 1, ceiling
);
19267 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19268 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19271 if (selective_display
)
19272 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19275 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19278 if (cursor
!= ceiling_addr
)
19282 start_byte
+= cursor
- base
+ 1;
19283 *byte_pos_ptr
= start_byte
;
19287 if (++cursor
== ceiling_addr
)
19293 start_byte
+= cursor
- base
;
19298 while (start_byte
> limit_byte
)
19300 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19301 ceiling
= max (limit_byte
, ceiling
);
19302 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19303 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19306 if (selective_display
)
19307 while (--cursor
!= ceiling_addr
19308 && *cursor
!= '\n' && *cursor
!= 015)
19311 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19314 if (cursor
!= ceiling_addr
)
19318 start_byte
+= cursor
- base
+ 1;
19319 *byte_pos_ptr
= start_byte
;
19320 /* When scanning backwards, we should
19321 not count the newline posterior to which we stop. */
19322 return - orig_count
- 1;
19328 /* Here we add 1 to compensate for the last decrement
19329 of CURSOR, which took it past the valid range. */
19330 start_byte
+= cursor
- base
+ 1;
19334 *byte_pos_ptr
= limit_byte
;
19337 return - orig_count
+ count
;
19338 return orig_count
- count
;
19344 /***********************************************************************
19346 ***********************************************************************/
19348 /* Display a NUL-terminated string, starting with index START.
19350 If STRING is non-null, display that C string. Otherwise, the Lisp
19351 string LISP_STRING is displayed. There's a case that STRING is
19352 non-null and LISP_STRING is not nil. It means STRING is a string
19353 data of LISP_STRING. In that case, we display LISP_STRING while
19354 ignoring its text properties.
19356 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19357 FACE_STRING. Display STRING or LISP_STRING with the face at
19358 FACE_STRING_POS in FACE_STRING:
19360 Display the string in the environment given by IT, but use the
19361 standard display table, temporarily.
19363 FIELD_WIDTH is the minimum number of output glyphs to produce.
19364 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19365 with spaces. If STRING has more characters, more than FIELD_WIDTH
19366 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19368 PRECISION is the maximum number of characters to output from
19369 STRING. PRECISION < 0 means don't truncate the string.
19371 This is roughly equivalent to printf format specifiers:
19373 FIELD_WIDTH PRECISION PRINTF
19374 ----------------------------------------
19380 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19381 display them, and < 0 means obey the current buffer's value of
19382 enable_multibyte_characters.
19384 Value is the number of columns displayed. */
19387 display_string (string
, lisp_string
, face_string
, face_string_pos
,
19388 start
, it
, field_width
, precision
, max_x
, multibyte
)
19389 unsigned char *string
;
19390 Lisp_Object lisp_string
;
19391 Lisp_Object face_string
;
19392 EMACS_INT face_string_pos
;
19395 int field_width
, precision
, max_x
;
19398 int hpos_at_start
= it
->hpos
;
19399 int saved_face_id
= it
->face_id
;
19400 struct glyph_row
*row
= it
->glyph_row
;
19402 /* Initialize the iterator IT for iteration over STRING beginning
19403 with index START. */
19404 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19405 precision
, field_width
, multibyte
);
19406 if (string
&& STRINGP (lisp_string
))
19407 /* LISP_STRING is the one returned by decode_mode_spec. We should
19408 ignore its text properties. */
19409 it
->stop_charpos
= -1;
19411 /* If displaying STRING, set up the face of the iterator
19412 from LISP_STRING, if that's given. */
19413 if (STRINGP (face_string
))
19419 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19420 0, it
->region_beg_charpos
,
19421 it
->region_end_charpos
,
19422 &endptr
, it
->base_face_id
, 0);
19423 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19424 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19427 /* Set max_x to the maximum allowed X position. Don't let it go
19428 beyond the right edge of the window. */
19430 max_x
= it
->last_visible_x
;
19432 max_x
= min (max_x
, it
->last_visible_x
);
19434 /* Skip over display elements that are not visible. because IT->w is
19436 if (it
->current_x
< it
->first_visible_x
)
19437 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
19438 MOVE_TO_POS
| MOVE_TO_X
);
19440 row
->ascent
= it
->max_ascent
;
19441 row
->height
= it
->max_ascent
+ it
->max_descent
;
19442 row
->phys_ascent
= it
->max_phys_ascent
;
19443 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19444 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19446 /* This condition is for the case that we are called with current_x
19447 past last_visible_x. */
19448 while (it
->current_x
< max_x
)
19450 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
19452 /* Get the next display element. */
19453 if (!get_next_display_element (it
))
19456 /* Produce glyphs. */
19457 x_before
= it
->current_x
;
19458 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19459 PRODUCE_GLYPHS (it
);
19461 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
19464 while (i
< nglyphs
)
19466 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19468 if (it
->line_wrap
!= TRUNCATE
19469 && x
+ glyph
->pixel_width
> max_x
)
19471 /* End of continued line or max_x reached. */
19472 if (CHAR_GLYPH_PADDING_P (*glyph
))
19474 /* A wide character is unbreakable. */
19475 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19476 it
->current_x
= x_before
;
19480 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19485 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
19487 /* Glyph is at least partially visible. */
19489 if (x
< it
->first_visible_x
)
19490 it
->glyph_row
->x
= x
- it
->first_visible_x
;
19494 /* Glyph is off the left margin of the display area.
19495 Should not happen. */
19499 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19500 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19501 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19502 row
->phys_height
= max (row
->phys_height
,
19503 it
->max_phys_ascent
+ it
->max_phys_descent
);
19504 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19505 it
->max_extra_line_spacing
);
19506 x
+= glyph
->pixel_width
;
19510 /* Stop if max_x reached. */
19514 /* Stop at line ends. */
19515 if (ITERATOR_AT_END_OF_LINE_P (it
))
19517 it
->continuation_lines_width
= 0;
19521 set_iterator_to_next (it
, 1);
19523 /* Stop if truncating at the right edge. */
19524 if (it
->line_wrap
== TRUNCATE
19525 && it
->current_x
>= it
->last_visible_x
)
19527 /* Add truncation mark, but don't do it if the line is
19528 truncated at a padding space. */
19529 if (IT_CHARPOS (*it
) < it
->string_nchars
)
19531 if (!FRAME_WINDOW_P (it
->f
))
19535 if (it
->current_x
> it
->last_visible_x
)
19537 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19538 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19540 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19542 row
->used
[TEXT_AREA
] = i
;
19543 produce_special_glyphs (it
, IT_TRUNCATION
);
19546 produce_special_glyphs (it
, IT_TRUNCATION
);
19548 it
->glyph_row
->truncated_on_right_p
= 1;
19554 /* Maybe insert a truncation at the left. */
19555 if (it
->first_visible_x
19556 && IT_CHARPOS (*it
) > 0)
19558 if (!FRAME_WINDOW_P (it
->f
))
19559 insert_left_trunc_glyphs (it
);
19560 it
->glyph_row
->truncated_on_left_p
= 1;
19563 it
->face_id
= saved_face_id
;
19565 /* Value is number of columns displayed. */
19566 return it
->hpos
- hpos_at_start
;
19571 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19572 appears as an element of LIST or as the car of an element of LIST.
19573 If PROPVAL is a list, compare each element against LIST in that
19574 way, and return 1/2 if any element of PROPVAL is found in LIST.
19575 Otherwise return 0. This function cannot quit.
19576 The return value is 2 if the text is invisible but with an ellipsis
19577 and 1 if it's invisible and without an ellipsis. */
19580 invisible_p (propval
, list
)
19581 register Lisp_Object propval
;
19584 register Lisp_Object tail
, proptail
;
19586 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19588 register Lisp_Object tem
;
19590 if (EQ (propval
, tem
))
19592 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19593 return NILP (XCDR (tem
)) ? 1 : 2;
19596 if (CONSP (propval
))
19598 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19600 Lisp_Object propelt
;
19601 propelt
= XCAR (proptail
);
19602 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19604 register Lisp_Object tem
;
19606 if (EQ (propelt
, tem
))
19608 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19609 return NILP (XCDR (tem
)) ? 1 : 2;
19617 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19618 doc
: /* Non-nil if the property makes the text invisible.
19619 POS-OR-PROP can be a marker or number, in which case it is taken to be
19620 a position in the current buffer and the value of the `invisible' property
19621 is checked; or it can be some other value, which is then presumed to be the
19622 value of the `invisible' property of the text of interest.
19623 The non-nil value returned can be t for truly invisible text or something
19624 else if the text is replaced by an ellipsis. */)
19626 Lisp_Object pos_or_prop
;
19629 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19630 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19632 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19633 return (invis
== 0 ? Qnil
19635 : make_number (invis
));
19638 /* Calculate a width or height in pixels from a specification using
19639 the following elements:
19642 NUM - a (fractional) multiple of the default font width/height
19643 (NUM) - specifies exactly NUM pixels
19644 UNIT - a fixed number of pixels, see below.
19645 ELEMENT - size of a display element in pixels, see below.
19646 (NUM . SPEC) - equals NUM * SPEC
19647 (+ SPEC SPEC ...) - add pixel values
19648 (- SPEC SPEC ...) - subtract pixel values
19649 (- SPEC) - negate pixel value
19652 INT or FLOAT - a number constant
19653 SYMBOL - use symbol's (buffer local) variable binding.
19656 in - pixels per inch *)
19657 mm - pixels per 1/1000 meter *)
19658 cm - pixels per 1/100 meter *)
19659 width - width of current font in pixels.
19660 height - height of current font in pixels.
19662 *) using the ratio(s) defined in display-pixels-per-inch.
19666 left-fringe - left fringe width in pixels
19667 right-fringe - right fringe width in pixels
19669 left-margin - left margin width in pixels
19670 right-margin - right margin width in pixels
19672 scroll-bar - scroll-bar area width in pixels
19676 Pixels corresponding to 5 inches:
19679 Total width of non-text areas on left side of window (if scroll-bar is on left):
19680 '(space :width (+ left-fringe left-margin scroll-bar))
19682 Align to first text column (in header line):
19683 '(space :align-to 0)
19685 Align to middle of text area minus half the width of variable `my-image'
19686 containing a loaded image:
19687 '(space :align-to (0.5 . (- text my-image)))
19689 Width of left margin minus width of 1 character in the default font:
19690 '(space :width (- left-margin 1))
19692 Width of left margin minus width of 2 characters in the current font:
19693 '(space :width (- left-margin (2 . width)))
19695 Center 1 character over left-margin (in header line):
19696 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19698 Different ways to express width of left fringe plus left margin minus one pixel:
19699 '(space :width (- (+ left-fringe left-margin) (1)))
19700 '(space :width (+ left-fringe left-margin (- (1))))
19701 '(space :width (+ left-fringe left-margin (-1)))
19705 #define NUMVAL(X) \
19706 ((INTEGERP (X) || FLOATP (X)) \
19711 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19716 int width_p
, *align_to
;
19720 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19721 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19724 return OK_PIXELS (0);
19726 xassert (FRAME_LIVE_P (it
->f
));
19728 if (SYMBOLP (prop
))
19730 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19732 char *unit
= SDATA (SYMBOL_NAME (prop
));
19734 if (unit
[0] == 'i' && unit
[1] == 'n')
19736 else if (unit
[0] == 'm' && unit
[1] == 'm')
19738 else if (unit
[0] == 'c' && unit
[1] == 'm')
19745 #ifdef HAVE_WINDOW_SYSTEM
19746 if (FRAME_WINDOW_P (it
->f
)
19748 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19749 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19751 return OK_PIXELS (ppi
/ pixels
);
19754 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19755 || (CONSP (Vdisplay_pixels_per_inch
)
19757 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19758 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19760 return OK_PIXELS (ppi
/ pixels
);
19766 #ifdef HAVE_WINDOW_SYSTEM
19767 if (EQ (prop
, Qheight
))
19768 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19769 if (EQ (prop
, Qwidth
))
19770 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19772 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19773 return OK_PIXELS (1);
19776 if (EQ (prop
, Qtext
))
19777 return OK_PIXELS (width_p
19778 ? window_box_width (it
->w
, TEXT_AREA
)
19779 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19781 if (align_to
&& *align_to
< 0)
19784 if (EQ (prop
, Qleft
))
19785 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19786 if (EQ (prop
, Qright
))
19787 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19788 if (EQ (prop
, Qcenter
))
19789 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19790 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19791 if (EQ (prop
, Qleft_fringe
))
19792 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19793 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19794 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19795 if (EQ (prop
, Qright_fringe
))
19796 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19797 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19798 : window_box_right_offset (it
->w
, TEXT_AREA
));
19799 if (EQ (prop
, Qleft_margin
))
19800 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19801 if (EQ (prop
, Qright_margin
))
19802 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19803 if (EQ (prop
, Qscroll_bar
))
19804 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19806 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19807 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19808 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19813 if (EQ (prop
, Qleft_fringe
))
19814 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19815 if (EQ (prop
, Qright_fringe
))
19816 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19817 if (EQ (prop
, Qleft_margin
))
19818 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19819 if (EQ (prop
, Qright_margin
))
19820 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19821 if (EQ (prop
, Qscroll_bar
))
19822 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19825 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19828 if (INTEGERP (prop
) || FLOATP (prop
))
19830 int base_unit
= (width_p
19831 ? FRAME_COLUMN_WIDTH (it
->f
)
19832 : FRAME_LINE_HEIGHT (it
->f
));
19833 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19838 Lisp_Object car
= XCAR (prop
);
19839 Lisp_Object cdr
= XCDR (prop
);
19843 #ifdef HAVE_WINDOW_SYSTEM
19844 if (FRAME_WINDOW_P (it
->f
)
19845 && valid_image_p (prop
))
19847 int id
= lookup_image (it
->f
, prop
);
19848 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19850 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19853 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19859 while (CONSP (cdr
))
19861 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19862 font
, width_p
, align_to
))
19865 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19870 if (EQ (car
, Qminus
))
19872 return OK_PIXELS (pixels
);
19875 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19878 if (INTEGERP (car
) || FLOATP (car
))
19881 pixels
= XFLOATINT (car
);
19883 return OK_PIXELS (pixels
);
19884 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19885 font
, width_p
, align_to
))
19886 return OK_PIXELS (pixels
* fact
);
19897 /***********************************************************************
19899 ***********************************************************************/
19901 #ifdef HAVE_WINDOW_SYSTEM
19906 dump_glyph_string (s
)
19907 struct glyph_string
*s
;
19909 fprintf (stderr
, "glyph string\n");
19910 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19911 s
->x
, s
->y
, s
->width
, s
->height
);
19912 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19913 fprintf (stderr
, " hl = %d\n", s
->hl
);
19914 fprintf (stderr
, " left overhang = %d, right = %d\n",
19915 s
->left_overhang
, s
->right_overhang
);
19916 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19917 fprintf (stderr
, " extends to end of line = %d\n",
19918 s
->extends_to_end_of_line_p
);
19919 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19920 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19923 #endif /* GLYPH_DEBUG */
19925 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19926 of XChar2b structures for S; it can't be allocated in
19927 init_glyph_string because it must be allocated via `alloca'. W
19928 is the window on which S is drawn. ROW and AREA are the glyph row
19929 and area within the row from which S is constructed. START is the
19930 index of the first glyph structure covered by S. HL is a
19931 face-override for drawing S. */
19934 #define OPTIONAL_HDC(hdc) hdc,
19935 #define DECLARE_HDC(hdc) HDC hdc;
19936 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19937 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19940 #ifndef OPTIONAL_HDC
19941 #define OPTIONAL_HDC(hdc)
19942 #define DECLARE_HDC(hdc)
19943 #define ALLOCATE_HDC(hdc, f)
19944 #define RELEASE_HDC(hdc, f)
19948 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19949 struct glyph_string
*s
;
19953 struct glyph_row
*row
;
19954 enum glyph_row_area area
;
19956 enum draw_glyphs_face hl
;
19958 bzero (s
, sizeof *s
);
19960 s
->f
= XFRAME (w
->frame
);
19964 s
->display
= FRAME_X_DISPLAY (s
->f
);
19965 s
->window
= FRAME_X_WINDOW (s
->f
);
19966 s
->char2b
= char2b
;
19970 s
->first_glyph
= row
->glyphs
[area
] + start
;
19971 s
->height
= row
->height
;
19972 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19973 s
->ybase
= s
->y
+ row
->ascent
;
19977 /* Append the list of glyph strings with head H and tail T to the list
19978 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19981 append_glyph_string_lists (head
, tail
, h
, t
)
19982 struct glyph_string
**head
, **tail
;
19983 struct glyph_string
*h
, *t
;
19997 /* Prepend the list of glyph strings with head H and tail T to the
19998 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20002 prepend_glyph_string_lists (head
, tail
, h
, t
)
20003 struct glyph_string
**head
, **tail
;
20004 struct glyph_string
*h
, *t
;
20018 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20019 Set *HEAD and *TAIL to the resulting list. */
20022 append_glyph_string (head
, tail
, s
)
20023 struct glyph_string
**head
, **tail
;
20024 struct glyph_string
*s
;
20026 s
->next
= s
->prev
= NULL
;
20027 append_glyph_string_lists (head
, tail
, s
, s
);
20031 /* Get face and two-byte form of character C in face FACE_ID on frame
20032 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
20033 means we want to display multibyte text. DISPLAY_P non-zero means
20034 make sure that X resources for the face returned are allocated.
20035 Value is a pointer to a realized face that is ready for display if
20036 DISPLAY_P is non-zero. */
20038 static INLINE
struct face
*
20039 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
20043 int multibyte_p
, display_p
;
20045 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20049 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20051 if (code
!= FONT_INVALID_CODE
)
20052 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20054 STORE_XCHAR2B (char2b
, 0, 0);
20057 /* Make sure X resources of the face are allocated. */
20058 #ifdef HAVE_X_WINDOWS
20062 xassert (face
!= NULL
);
20063 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20070 /* Get face and two-byte form of character glyph GLYPH on frame F.
20071 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20072 a pointer to a realized face that is ready for display. */
20074 static INLINE
struct face
*
20075 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
20077 struct glyph
*glyph
;
20083 xassert (glyph
->type
== CHAR_GLYPH
);
20084 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20091 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20093 if (code
!= FONT_INVALID_CODE
)
20094 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20096 STORE_XCHAR2B (char2b
, 0, 0);
20099 /* Make sure X resources of the face are allocated. */
20100 xassert (face
!= NULL
);
20101 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20106 /* Fill glyph string S with composition components specified by S->cmp.
20108 BASE_FACE is the base face of the composition.
20109 S->cmp_from is the index of the first component for S.
20111 OVERLAPS non-zero means S should draw the foreground only, and use
20112 its physical height for clipping. See also draw_glyphs.
20114 Value is the index of a component not in S. */
20117 fill_composite_glyph_string (s
, base_face
, overlaps
)
20118 struct glyph_string
*s
;
20119 struct face
*base_face
;
20123 /* For all glyphs of this composition, starting at the offset
20124 S->cmp_from, until we reach the end of the definition or encounter a
20125 glyph that requires the different face, add it to S. */
20130 s
->for_overlaps
= overlaps
;
20133 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20135 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20139 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20142 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20143 s
->char2b
+ i
, 1, 1);
20149 s
->font
= s
->face
->font
;
20151 else if (s
->face
!= face
)
20159 /* All glyph strings for the same composition has the same width,
20160 i.e. the width set for the first component of the composition. */
20161 s
->width
= s
->first_glyph
->pixel_width
;
20163 /* If the specified font could not be loaded, use the frame's
20164 default font, but record the fact that we couldn't load it in
20165 the glyph string so that we can draw rectangles for the
20166 characters of the glyph string. */
20167 if (s
->font
== NULL
)
20169 s
->font_not_found_p
= 1;
20170 s
->font
= FRAME_FONT (s
->f
);
20173 /* Adjust base line for subscript/superscript text. */
20174 s
->ybase
+= s
->first_glyph
->voffset
;
20176 /* This glyph string must always be drawn with 16-bit functions. */
20183 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
20184 struct glyph_string
*s
;
20186 int start
, end
, overlaps
;
20188 struct glyph
*glyph
, *last
;
20189 Lisp_Object lgstring
;
20192 s
->for_overlaps
= overlaps
;
20193 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20194 last
= s
->row
->glyphs
[s
->area
] + end
;
20195 s
->cmp_id
= glyph
->u
.cmp
.id
;
20196 s
->cmp_from
= glyph
->u
.cmp
.from
;
20197 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
20198 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20199 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20200 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20202 while (glyph
< last
20203 && glyph
->u
.cmp
.automatic
20204 && glyph
->u
.cmp
.id
== s
->cmp_id
20205 && s
->cmp_to
== glyph
->u
.cmp
.from
)
20206 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
20208 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20210 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20211 unsigned code
= LGLYPH_CODE (lglyph
);
20213 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20215 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20216 return glyph
- s
->row
->glyphs
[s
->area
];
20220 /* Fill glyph string S from a sequence of character glyphs.
20222 FACE_ID is the face id of the string. START is the index of the
20223 first glyph to consider, END is the index of the last + 1.
20224 OVERLAPS non-zero means S should draw the foreground only, and use
20225 its physical height for clipping. See also draw_glyphs.
20227 Value is the index of the first glyph not in S. */
20230 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
20231 struct glyph_string
*s
;
20233 int start
, end
, overlaps
;
20235 struct glyph
*glyph
, *last
;
20237 int glyph_not_available_p
;
20239 xassert (s
->f
== XFRAME (s
->w
->frame
));
20240 xassert (s
->nchars
== 0);
20241 xassert (start
>= 0 && end
> start
);
20243 s
->for_overlaps
= overlaps
;
20244 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20245 last
= s
->row
->glyphs
[s
->area
] + end
;
20246 voffset
= glyph
->voffset
;
20247 s
->padding_p
= glyph
->padding_p
;
20248 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20250 while (glyph
< last
20251 && glyph
->type
== CHAR_GLYPH
20252 && glyph
->voffset
== voffset
20253 /* Same face id implies same font, nowadays. */
20254 && glyph
->face_id
== face_id
20255 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20259 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20260 s
->char2b
+ s
->nchars
,
20262 s
->two_byte_p
= two_byte_p
;
20264 xassert (s
->nchars
<= end
- start
);
20265 s
->width
+= glyph
->pixel_width
;
20266 if (glyph
++->padding_p
!= s
->padding_p
)
20270 s
->font
= s
->face
->font
;
20272 /* If the specified font could not be loaded, use the frame's font,
20273 but record the fact that we couldn't load it in
20274 S->font_not_found_p so that we can draw rectangles for the
20275 characters of the glyph string. */
20276 if (s
->font
== NULL
|| glyph_not_available_p
)
20278 s
->font_not_found_p
= 1;
20279 s
->font
= FRAME_FONT (s
->f
);
20282 /* Adjust base line for subscript/superscript text. */
20283 s
->ybase
+= voffset
;
20285 xassert (s
->face
&& s
->face
->gc
);
20286 return glyph
- s
->row
->glyphs
[s
->area
];
20290 /* Fill glyph string S from image glyph S->first_glyph. */
20293 fill_image_glyph_string (s
)
20294 struct glyph_string
*s
;
20296 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20297 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20299 s
->slice
= s
->first_glyph
->slice
;
20300 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20301 s
->font
= s
->face
->font
;
20302 s
->width
= s
->first_glyph
->pixel_width
;
20304 /* Adjust base line for subscript/superscript text. */
20305 s
->ybase
+= s
->first_glyph
->voffset
;
20309 /* Fill glyph string S from a sequence of stretch glyphs.
20311 ROW is the glyph row in which the glyphs are found, AREA is the
20312 area within the row. START is the index of the first glyph to
20313 consider, END is the index of the last + 1.
20315 Value is the index of the first glyph not in S. */
20318 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
20319 struct glyph_string
*s
;
20320 struct glyph_row
*row
;
20321 enum glyph_row_area area
;
20324 struct glyph
*glyph
, *last
;
20325 int voffset
, face_id
;
20327 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20329 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20330 last
= s
->row
->glyphs
[s
->area
] + end
;
20331 face_id
= glyph
->face_id
;
20332 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20333 s
->font
= s
->face
->font
;
20334 s
->width
= glyph
->pixel_width
;
20336 voffset
= glyph
->voffset
;
20340 && glyph
->type
== STRETCH_GLYPH
20341 && glyph
->voffset
== voffset
20342 && glyph
->face_id
== face_id
);
20344 s
->width
+= glyph
->pixel_width
;
20346 /* Adjust base line for subscript/superscript text. */
20347 s
->ybase
+= voffset
;
20349 /* The case that face->gc == 0 is handled when drawing the glyph
20350 string by calling PREPARE_FACE_FOR_DISPLAY. */
20352 return glyph
- s
->row
->glyphs
[s
->area
];
20355 static struct font_metrics
*
20356 get_per_char_metric (f
, font
, char2b
)
20361 static struct font_metrics metrics
;
20362 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20364 if (! font
|| code
== FONT_INVALID_CODE
)
20366 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20371 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20372 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20373 assumed to be zero. */
20376 x_get_glyph_overhangs (glyph
, f
, left
, right
)
20377 struct glyph
*glyph
;
20381 *left
= *right
= 0;
20383 if (glyph
->type
== CHAR_GLYPH
)
20387 struct font_metrics
*pcm
;
20389 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20390 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20392 if (pcm
->rbearing
> pcm
->width
)
20393 *right
= pcm
->rbearing
- pcm
->width
;
20394 if (pcm
->lbearing
< 0)
20395 *left
= -pcm
->lbearing
;
20398 else if (glyph
->type
== COMPOSITE_GLYPH
)
20400 if (! glyph
->u
.cmp
.automatic
)
20402 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20404 if (cmp
->rbearing
> cmp
->pixel_width
)
20405 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20406 if (cmp
->lbearing
< 0)
20407 *left
= - cmp
->lbearing
;
20411 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
20412 struct font_metrics metrics
;
20414 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
20415 glyph
->u
.cmp
.to
+ 1, &metrics
);
20416 if (metrics
.rbearing
> metrics
.width
)
20417 *right
= metrics
.rbearing
- metrics
.width
;
20418 if (metrics
.lbearing
< 0)
20419 *left
= - metrics
.lbearing
;
20425 /* Return the index of the first glyph preceding glyph string S that
20426 is overwritten by S because of S's left overhang. Value is -1
20427 if no glyphs are overwritten. */
20430 left_overwritten (s
)
20431 struct glyph_string
*s
;
20435 if (s
->left_overhang
)
20438 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20439 int first
= s
->first_glyph
- glyphs
;
20441 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
20442 x
-= glyphs
[i
].pixel_width
;
20453 /* Return the index of the first glyph preceding glyph string S that
20454 is overwriting S because of its right overhang. Value is -1 if no
20455 glyph in front of S overwrites S. */
20458 left_overwriting (s
)
20459 struct glyph_string
*s
;
20462 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20463 int first
= s
->first_glyph
- glyphs
;
20467 for (i
= first
- 1; i
>= 0; --i
)
20470 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20473 x
-= glyphs
[i
].pixel_width
;
20480 /* Return the index of the last glyph following glyph string S that is
20481 overwritten by S because of S's right overhang. Value is -1 if
20482 no such glyph is found. */
20485 right_overwritten (s
)
20486 struct glyph_string
*s
;
20490 if (s
->right_overhang
)
20493 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20494 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20495 int end
= s
->row
->used
[s
->area
];
20497 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
20498 x
+= glyphs
[i
].pixel_width
;
20507 /* Return the index of the last glyph following glyph string S that
20508 overwrites S because of its left overhang. Value is negative
20509 if no such glyph is found. */
20512 right_overwriting (s
)
20513 struct glyph_string
*s
;
20516 int end
= s
->row
->used
[s
->area
];
20517 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20518 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20522 for (i
= first
; i
< end
; ++i
)
20525 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20528 x
+= glyphs
[i
].pixel_width
;
20535 /* Set background width of glyph string S. START is the index of the
20536 first glyph following S. LAST_X is the right-most x-position + 1
20537 in the drawing area. */
20540 set_glyph_string_background_width (s
, start
, last_x
)
20541 struct glyph_string
*s
;
20545 /* If the face of this glyph string has to be drawn to the end of
20546 the drawing area, set S->extends_to_end_of_line_p. */
20548 if (start
== s
->row
->used
[s
->area
]
20549 && s
->area
== TEXT_AREA
20550 && ((s
->row
->fill_line_p
20551 && (s
->hl
== DRAW_NORMAL_TEXT
20552 || s
->hl
== DRAW_IMAGE_RAISED
20553 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20554 || s
->hl
== DRAW_MOUSE_FACE
))
20555 s
->extends_to_end_of_line_p
= 1;
20557 /* If S extends its face to the end of the line, set its
20558 background_width to the distance to the right edge of the drawing
20560 if (s
->extends_to_end_of_line_p
)
20561 s
->background_width
= last_x
- s
->x
+ 1;
20563 s
->background_width
= s
->width
;
20567 /* Compute overhangs and x-positions for glyph string S and its
20568 predecessors, or successors. X is the starting x-position for S.
20569 BACKWARD_P non-zero means process predecessors. */
20572 compute_overhangs_and_x (s
, x
, backward_p
)
20573 struct glyph_string
*s
;
20581 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20582 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20592 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20593 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20603 /* The following macros are only called from draw_glyphs below.
20604 They reference the following parameters of that function directly:
20605 `w', `row', `area', and `overlap_p'
20606 as well as the following local variables:
20607 `s', `f', and `hdc' (in W32) */
20610 /* On W32, silently add local `hdc' variable to argument list of
20611 init_glyph_string. */
20612 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20613 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20615 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20616 init_glyph_string (s, char2b, w, row, area, start, hl)
20619 /* Add a glyph string for a stretch glyph to the list of strings
20620 between HEAD and TAIL. START is the index of the stretch glyph in
20621 row area AREA of glyph row ROW. END is the index of the last glyph
20622 in that glyph row area. X is the current output position assigned
20623 to the new glyph string constructed. HL overrides that face of the
20624 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20625 is the right-most x-position of the drawing area. */
20627 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20628 and below -- keep them on one line. */
20629 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20632 s = (struct glyph_string *) alloca (sizeof *s); \
20633 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20634 START = fill_stretch_glyph_string (s, row, area, START, END); \
20635 append_glyph_string (&HEAD, &TAIL, s); \
20641 /* Add a glyph string for an image glyph to the list of strings
20642 between HEAD and TAIL. START is the index of the image glyph in
20643 row area AREA of glyph row ROW. END is the index of the last glyph
20644 in that glyph row area. X is the current output position assigned
20645 to the new glyph string constructed. HL overrides that face of the
20646 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20647 is the right-most x-position of the drawing area. */
20649 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20652 s = (struct glyph_string *) alloca (sizeof *s); \
20653 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20654 fill_image_glyph_string (s); \
20655 append_glyph_string (&HEAD, &TAIL, s); \
20662 /* Add a glyph string for a sequence of character glyphs to the list
20663 of strings between HEAD and TAIL. START is the index of the first
20664 glyph in row area AREA of glyph row ROW that is part of the new
20665 glyph string. END is the index of the last glyph in that glyph row
20666 area. X is the current output position assigned to the new glyph
20667 string constructed. HL overrides that face of the glyph; e.g. it
20668 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20669 right-most x-position of the drawing area. */
20671 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20677 face_id = (row)->glyphs[area][START].face_id; \
20679 s = (struct glyph_string *) alloca (sizeof *s); \
20680 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20681 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20682 append_glyph_string (&HEAD, &TAIL, s); \
20684 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20689 /* Add a glyph string for a composite sequence to the list of strings
20690 between HEAD and TAIL. START is the index of the first glyph in
20691 row area AREA of glyph row ROW that is part of the new glyph
20692 string. END is the index of the last glyph in that glyph row area.
20693 X is the current output position assigned to the new glyph string
20694 constructed. HL overrides that face of the glyph; e.g. it is
20695 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20696 x-position of the drawing area. */
20698 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20700 int face_id = (row)->glyphs[area][START].face_id; \
20701 struct face *base_face = FACE_FROM_ID (f, face_id); \
20702 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20703 struct composition *cmp = composition_table[cmp_id]; \
20705 struct glyph_string *first_s; \
20708 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20710 /* Make glyph_strings for each glyph sequence that is drawable by \
20711 the same face, and append them to HEAD/TAIL. */ \
20712 for (n = 0; n < cmp->glyph_len;) \
20714 s = (struct glyph_string *) alloca (sizeof *s); \
20715 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20716 append_glyph_string (&(HEAD), &(TAIL), s); \
20722 n = fill_composite_glyph_string (s, base_face, overlaps); \
20730 /* Add a glyph string for a glyph-string sequence to the list of strings
20731 between HEAD and TAIL. */
20733 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20737 Lisp_Object gstring; \
20739 face_id = (row)->glyphs[area][START].face_id; \
20740 gstring = (composition_gstring_from_id \
20741 ((row)->glyphs[area][START].u.cmp.id)); \
20742 s = (struct glyph_string *) alloca (sizeof *s); \
20743 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20744 * LGSTRING_GLYPH_LEN (gstring)); \
20745 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20746 append_glyph_string (&(HEAD), &(TAIL), s); \
20748 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20752 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20753 of AREA of glyph row ROW on window W between indices START and END.
20754 HL overrides the face for drawing glyph strings, e.g. it is
20755 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20756 x-positions of the drawing area.
20758 This is an ugly monster macro construct because we must use alloca
20759 to allocate glyph strings (because draw_glyphs can be called
20760 asynchronously). */
20762 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20765 HEAD = TAIL = NULL; \
20766 while (START < END) \
20768 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20769 switch (first_glyph->type) \
20772 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20776 case COMPOSITE_GLYPH: \
20777 if (first_glyph->u.cmp.automatic) \
20778 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20781 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20785 case STRETCH_GLYPH: \
20786 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20790 case IMAGE_GLYPH: \
20791 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20801 set_glyph_string_background_width (s, START, LAST_X); \
20808 /* Draw glyphs between START and END in AREA of ROW on window W,
20809 starting at x-position X. X is relative to AREA in W. HL is a
20810 face-override with the following meaning:
20812 DRAW_NORMAL_TEXT draw normally
20813 DRAW_CURSOR draw in cursor face
20814 DRAW_MOUSE_FACE draw in mouse face.
20815 DRAW_INVERSE_VIDEO draw in mode line face
20816 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20817 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20819 If OVERLAPS is non-zero, draw only the foreground of characters and
20820 clip to the physical height of ROW. Non-zero value also defines
20821 the overlapping part to be drawn:
20823 OVERLAPS_PRED overlap with preceding rows
20824 OVERLAPS_SUCC overlap with succeeding rows
20825 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20826 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20828 Value is the x-position reached, relative to AREA of W. */
20831 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20834 struct glyph_row
*row
;
20835 enum glyph_row_area area
;
20836 EMACS_INT start
, end
;
20837 enum draw_glyphs_face hl
;
20840 struct glyph_string
*head
, *tail
;
20841 struct glyph_string
*s
;
20842 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20843 int i
, j
, x_reached
, last_x
, area_left
= 0;
20844 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20847 ALLOCATE_HDC (hdc
, f
);
20849 /* Let's rather be paranoid than getting a SEGV. */
20850 end
= min (end
, row
->used
[area
]);
20851 start
= max (0, start
);
20852 start
= min (end
, start
);
20854 /* Translate X to frame coordinates. Set last_x to the right
20855 end of the drawing area. */
20856 if (row
->full_width_p
)
20858 /* X is relative to the left edge of W, without scroll bars
20860 area_left
= WINDOW_LEFT_EDGE_X (w
);
20861 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20865 area_left
= window_box_left (w
, area
);
20866 last_x
= area_left
+ window_box_width (w
, area
);
20870 /* Build a doubly-linked list of glyph_string structures between
20871 head and tail from what we have to draw. Note that the macro
20872 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20873 the reason we use a separate variable `i'. */
20875 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20877 x_reached
= tail
->x
+ tail
->background_width
;
20881 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20882 the row, redraw some glyphs in front or following the glyph
20883 strings built above. */
20884 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20886 struct glyph_string
*h
, *t
;
20887 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20888 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20891 /* If mouse highlighting is on, we may need to draw adjacent
20892 glyphs using mouse-face highlighting. */
20893 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20895 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20897 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20898 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20900 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20902 check_mouse_face
= 1;
20903 mouse_beg_col
= (row
== mouse_beg_row
)
20904 ? dpyinfo
->mouse_face_beg_col
: 0;
20905 mouse_end_col
= (row
== mouse_end_row
)
20906 ? dpyinfo
->mouse_face_end_col
20907 : row
->used
[TEXT_AREA
];
20911 /* Compute overhangs for all glyph strings. */
20912 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20913 for (s
= head
; s
; s
= s
->next
)
20914 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20916 /* Prepend glyph strings for glyphs in front of the first glyph
20917 string that are overwritten because of the first glyph
20918 string's left overhang. The background of all strings
20919 prepended must be drawn because the first glyph string
20921 i
= left_overwritten (head
);
20924 enum draw_glyphs_face overlap_hl
;
20926 /* If this row contains mouse highlighting, attempt to draw
20927 the overlapped glyphs with the correct highlight. This
20928 code fails if the overlap encompasses more than one glyph
20929 and mouse-highlight spans only some of these glyphs.
20930 However, making it work perfectly involves a lot more
20931 code, and I don't know if the pathological case occurs in
20932 practice, so we'll stick to this for now. --- cyd */
20933 if (check_mouse_face
20934 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20935 overlap_hl
= DRAW_MOUSE_FACE
;
20937 overlap_hl
= DRAW_NORMAL_TEXT
;
20940 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20941 overlap_hl
, dummy_x
, last_x
);
20942 compute_overhangs_and_x (t
, head
->x
, 1);
20943 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20947 /* Prepend glyph strings for glyphs in front of the first glyph
20948 string that overwrite that glyph string because of their
20949 right overhang. For these strings, only the foreground must
20950 be drawn, because it draws over the glyph string at `head'.
20951 The background must not be drawn because this would overwrite
20952 right overhangs of preceding glyphs for which no glyph
20954 i
= left_overwriting (head
);
20957 enum draw_glyphs_face overlap_hl
;
20959 if (check_mouse_face
20960 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20961 overlap_hl
= DRAW_MOUSE_FACE
;
20963 overlap_hl
= DRAW_NORMAL_TEXT
;
20966 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20967 overlap_hl
, dummy_x
, last_x
);
20968 for (s
= h
; s
; s
= s
->next
)
20969 s
->background_filled_p
= 1;
20970 compute_overhangs_and_x (t
, head
->x
, 1);
20971 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20974 /* Append glyphs strings for glyphs following the last glyph
20975 string tail that are overwritten by tail. The background of
20976 these strings has to be drawn because tail's foreground draws
20978 i
= right_overwritten (tail
);
20981 enum draw_glyphs_face overlap_hl
;
20983 if (check_mouse_face
20984 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20985 overlap_hl
= DRAW_MOUSE_FACE
;
20987 overlap_hl
= DRAW_NORMAL_TEXT
;
20989 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20990 overlap_hl
, x
, last_x
);
20991 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20992 append_glyph_string_lists (&head
, &tail
, h
, t
);
20996 /* Append glyph strings for glyphs following the last glyph
20997 string tail that overwrite tail. The foreground of such
20998 glyphs has to be drawn because it writes into the background
20999 of tail. The background must not be drawn because it could
21000 paint over the foreground of following glyphs. */
21001 i
= right_overwriting (tail
);
21004 enum draw_glyphs_face overlap_hl
;
21005 if (check_mouse_face
21006 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21007 overlap_hl
= DRAW_MOUSE_FACE
;
21009 overlap_hl
= DRAW_NORMAL_TEXT
;
21012 i
++; /* We must include the Ith glyph. */
21013 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21014 overlap_hl
, x
, last_x
);
21015 for (s
= h
; s
; s
= s
->next
)
21016 s
->background_filled_p
= 1;
21017 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21018 append_glyph_string_lists (&head
, &tail
, h
, t
);
21020 if (clip_head
|| clip_tail
)
21021 for (s
= head
; s
; s
= s
->next
)
21023 s
->clip_head
= clip_head
;
21024 s
->clip_tail
= clip_tail
;
21028 /* Draw all strings. */
21029 for (s
= head
; s
; s
= s
->next
)
21030 FRAME_RIF (f
)->draw_glyph_string (s
);
21033 /* When focus a sole frame and move horizontally, this sets on_p to 0
21034 causing a failure to erase prev cursor position. */
21035 if (area
== TEXT_AREA
21036 && !row
->full_width_p
21037 /* When drawing overlapping rows, only the glyph strings'
21038 foreground is drawn, which doesn't erase a cursor
21042 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21043 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21044 : (tail
? tail
->x
+ tail
->background_width
: x
));
21048 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21049 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21053 /* Value is the x-position up to which drawn, relative to AREA of W.
21054 This doesn't include parts drawn because of overhangs. */
21055 if (row
->full_width_p
)
21056 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21058 x_reached
-= area_left
;
21060 RELEASE_HDC (hdc
, f
);
21065 /* Expand row matrix if too narrow. Don't expand if area
21068 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21070 if (!fonts_changed_p \
21071 && (it->glyph_row->glyphs[area] \
21072 < it->glyph_row->glyphs[area + 1])) \
21074 it->w->ncols_scale_factor++; \
21075 fonts_changed_p = 1; \
21079 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21080 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21086 struct glyph
*glyph
;
21087 enum glyph_row_area area
= it
->area
;
21089 xassert (it
->glyph_row
);
21090 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21092 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21093 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21095 glyph
->charpos
= CHARPOS (it
->position
);
21096 glyph
->object
= it
->object
;
21097 if (it
->pixel_width
> 0)
21099 glyph
->pixel_width
= it
->pixel_width
;
21100 glyph
->padding_p
= 0;
21104 /* Assure at least 1-pixel width. Otherwise, cursor can't
21105 be displayed correctly. */
21106 glyph
->pixel_width
= 1;
21107 glyph
->padding_p
= 1;
21109 glyph
->ascent
= it
->ascent
;
21110 glyph
->descent
= it
->descent
;
21111 glyph
->voffset
= it
->voffset
;
21112 glyph
->type
= CHAR_GLYPH
;
21113 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21114 glyph
->multibyte_p
= it
->multibyte_p
;
21115 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21116 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21117 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21118 || it
->phys_descent
> it
->descent
);
21119 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21120 glyph
->face_id
= it
->face_id
;
21121 glyph
->u
.ch
= it
->char_to_display
;
21122 glyph
->slice
= null_glyph_slice
;
21123 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21126 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21127 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21129 glyph
->bidi_type
= it
->bidi_it
.type
;
21131 ++it
->glyph_row
->used
[area
];
21134 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21137 /* Store one glyph for the composition IT->cmp_it.id in
21138 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21142 append_composite_glyph (it
)
21145 struct glyph
*glyph
;
21146 enum glyph_row_area area
= it
->area
;
21148 xassert (it
->glyph_row
);
21150 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21151 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21153 glyph
->charpos
= CHARPOS (it
->position
);
21154 glyph
->object
= it
->object
;
21155 glyph
->pixel_width
= it
->pixel_width
;
21156 glyph
->ascent
= it
->ascent
;
21157 glyph
->descent
= it
->descent
;
21158 glyph
->voffset
= it
->voffset
;
21159 glyph
->type
= COMPOSITE_GLYPH
;
21160 if (it
->cmp_it
.ch
< 0)
21162 glyph
->u
.cmp
.automatic
= 0;
21163 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21167 glyph
->u
.cmp
.automatic
= 1;
21168 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21169 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
21170 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
21172 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21173 glyph
->multibyte_p
= it
->multibyte_p
;
21174 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21175 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21176 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21177 || it
->phys_descent
> it
->descent
);
21178 glyph
->padding_p
= 0;
21179 glyph
->glyph_not_available_p
= 0;
21180 glyph
->face_id
= it
->face_id
;
21181 glyph
->slice
= null_glyph_slice
;
21182 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21185 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21186 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21188 glyph
->bidi_type
= it
->bidi_it
.type
;
21190 ++it
->glyph_row
->used
[area
];
21193 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21197 /* Change IT->ascent and IT->height according to the setting of
21201 take_vertical_position_into_account (it
)
21206 if (it
->voffset
< 0)
21207 /* Increase the ascent so that we can display the text higher
21209 it
->ascent
-= it
->voffset
;
21211 /* Increase the descent so that we can display the text lower
21213 it
->descent
+= it
->voffset
;
21218 /* Produce glyphs/get display metrics for the image IT is loaded with.
21219 See the description of struct display_iterator in dispextern.h for
21220 an overview of struct display_iterator. */
21223 produce_image_glyph (it
)
21228 int glyph_ascent
, crop
;
21229 struct glyph_slice slice
;
21231 xassert (it
->what
== IT_IMAGE
);
21233 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21235 /* Make sure X resources of the face is loaded. */
21236 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21238 if (it
->image_id
< 0)
21240 /* Fringe bitmap. */
21241 it
->ascent
= it
->phys_ascent
= 0;
21242 it
->descent
= it
->phys_descent
= 0;
21243 it
->pixel_width
= 0;
21248 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21250 /* Make sure X resources of the image is loaded. */
21251 prepare_image_for_display (it
->f
, img
);
21253 slice
.x
= slice
.y
= 0;
21254 slice
.width
= img
->width
;
21255 slice
.height
= img
->height
;
21257 if (INTEGERP (it
->slice
.x
))
21258 slice
.x
= XINT (it
->slice
.x
);
21259 else if (FLOATP (it
->slice
.x
))
21260 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21262 if (INTEGERP (it
->slice
.y
))
21263 slice
.y
= XINT (it
->slice
.y
);
21264 else if (FLOATP (it
->slice
.y
))
21265 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21267 if (INTEGERP (it
->slice
.width
))
21268 slice
.width
= XINT (it
->slice
.width
);
21269 else if (FLOATP (it
->slice
.width
))
21270 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21272 if (INTEGERP (it
->slice
.height
))
21273 slice
.height
= XINT (it
->slice
.height
);
21274 else if (FLOATP (it
->slice
.height
))
21275 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21277 if (slice
.x
>= img
->width
)
21278 slice
.x
= img
->width
;
21279 if (slice
.y
>= img
->height
)
21280 slice
.y
= img
->height
;
21281 if (slice
.x
+ slice
.width
>= img
->width
)
21282 slice
.width
= img
->width
- slice
.x
;
21283 if (slice
.y
+ slice
.height
> img
->height
)
21284 slice
.height
= img
->height
- slice
.y
;
21286 if (slice
.width
== 0 || slice
.height
== 0)
21289 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21291 it
->descent
= slice
.height
- glyph_ascent
;
21293 it
->descent
+= img
->vmargin
;
21294 if (slice
.y
+ slice
.height
== img
->height
)
21295 it
->descent
+= img
->vmargin
;
21296 it
->phys_descent
= it
->descent
;
21298 it
->pixel_width
= slice
.width
;
21300 it
->pixel_width
+= img
->hmargin
;
21301 if (slice
.x
+ slice
.width
== img
->width
)
21302 it
->pixel_width
+= img
->hmargin
;
21304 /* It's quite possible for images to have an ascent greater than
21305 their height, so don't get confused in that case. */
21306 if (it
->descent
< 0)
21311 if (face
->box
!= FACE_NO_BOX
)
21313 if (face
->box_line_width
> 0)
21316 it
->ascent
+= face
->box_line_width
;
21317 if (slice
.y
+ slice
.height
== img
->height
)
21318 it
->descent
+= face
->box_line_width
;
21321 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21322 it
->pixel_width
+= eabs (face
->box_line_width
);
21323 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21324 it
->pixel_width
+= eabs (face
->box_line_width
);
21327 take_vertical_position_into_account (it
);
21329 /* Automatically crop wide image glyphs at right edge so we can
21330 draw the cursor on same display row. */
21331 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21332 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21334 it
->pixel_width
-= crop
;
21335 slice
.width
-= crop
;
21340 struct glyph
*glyph
;
21341 enum glyph_row_area area
= it
->area
;
21343 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21344 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21346 glyph
->charpos
= CHARPOS (it
->position
);
21347 glyph
->object
= it
->object
;
21348 glyph
->pixel_width
= it
->pixel_width
;
21349 glyph
->ascent
= glyph_ascent
;
21350 glyph
->descent
= it
->descent
;
21351 glyph
->voffset
= it
->voffset
;
21352 glyph
->type
= IMAGE_GLYPH
;
21353 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21354 glyph
->multibyte_p
= it
->multibyte_p
;
21355 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21356 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21357 glyph
->overlaps_vertically_p
= 0;
21358 glyph
->padding_p
= 0;
21359 glyph
->glyph_not_available_p
= 0;
21360 glyph
->face_id
= it
->face_id
;
21361 glyph
->u
.img_id
= img
->id
;
21362 glyph
->slice
= slice
;
21363 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21366 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21367 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21369 glyph
->bidi_type
= it
->bidi_it
.type
;
21371 ++it
->glyph_row
->used
[area
];
21374 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21379 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
21380 of the glyph, WIDTH and HEIGHT are the width and height of the
21381 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
21384 append_stretch_glyph (it
, object
, width
, height
, ascent
)
21386 Lisp_Object object
;
21390 struct glyph
*glyph
;
21391 enum glyph_row_area area
= it
->area
;
21393 xassert (ascent
>= 0 && ascent
<= height
);
21395 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21396 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21398 glyph
->charpos
= CHARPOS (it
->position
);
21399 glyph
->object
= object
;
21400 glyph
->pixel_width
= width
;
21401 glyph
->ascent
= ascent
;
21402 glyph
->descent
= height
- ascent
;
21403 glyph
->voffset
= it
->voffset
;
21404 glyph
->type
= STRETCH_GLYPH
;
21405 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21406 glyph
->multibyte_p
= it
->multibyte_p
;
21407 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21408 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21409 glyph
->overlaps_vertically_p
= 0;
21410 glyph
->padding_p
= 0;
21411 glyph
->glyph_not_available_p
= 0;
21412 glyph
->face_id
= it
->face_id
;
21413 glyph
->u
.stretch
.ascent
= ascent
;
21414 glyph
->u
.stretch
.height
= height
;
21415 glyph
->slice
= null_glyph_slice
;
21416 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21419 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21420 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21422 glyph
->bidi_type
= it
->bidi_it
.type
;
21424 ++it
->glyph_row
->used
[area
];
21427 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21431 /* Produce a stretch glyph for iterator IT. IT->object is the value
21432 of the glyph property displayed. The value must be a list
21433 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
21436 1. `:width WIDTH' specifies that the space should be WIDTH *
21437 canonical char width wide. WIDTH may be an integer or floating
21440 2. `:relative-width FACTOR' specifies that the width of the stretch
21441 should be computed from the width of the first character having the
21442 `glyph' property, and should be FACTOR times that width.
21444 3. `:align-to HPOS' specifies that the space should be wide enough
21445 to reach HPOS, a value in canonical character units.
21447 Exactly one of the above pairs must be present.
21449 4. `:height HEIGHT' specifies that the height of the stretch produced
21450 should be HEIGHT, measured in canonical character units.
21452 5. `:relative-height FACTOR' specifies that the height of the
21453 stretch should be FACTOR times the height of the characters having
21454 the glyph property.
21456 Either none or exactly one of 4 or 5 must be present.
21458 6. `:ascent ASCENT' specifies that ASCENT percent of the height
21459 of the stretch should be used for the ascent of the stretch.
21460 ASCENT must be in the range 0 <= ASCENT <= 100. */
21463 produce_stretch_glyph (it
)
21466 /* (space :width WIDTH :height HEIGHT ...) */
21467 Lisp_Object prop
, plist
;
21468 int width
= 0, height
= 0, align_to
= -1;
21469 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
21472 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21473 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
21475 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21477 /* List should start with `space'. */
21478 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
21479 plist
= XCDR (it
->object
);
21481 /* Compute the width of the stretch. */
21482 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
21483 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
21485 /* Absolute width `:width WIDTH' specified and valid. */
21486 zero_width_ok_p
= 1;
21489 else if (prop
= Fplist_get (plist
, QCrelative_width
),
21492 /* Relative width `:relative-width FACTOR' specified and valid.
21493 Compute the width of the characters having the `glyph'
21496 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
21499 if (it
->multibyte_p
)
21501 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
21502 - IT_BYTEPOS (*it
));
21503 it2
.c
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
21506 it2
.c
= *p
, it2
.len
= 1;
21508 it2
.glyph_row
= NULL
;
21509 it2
.what
= IT_CHARACTER
;
21510 x_produce_glyphs (&it2
);
21511 width
= NUMVAL (prop
) * it2
.pixel_width
;
21513 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
21514 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
21516 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
21517 align_to
= (align_to
< 0
21519 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
21520 else if (align_to
< 0)
21521 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
21522 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
21523 zero_width_ok_p
= 1;
21526 /* Nothing specified -> width defaults to canonical char width. */
21527 width
= FRAME_COLUMN_WIDTH (it
->f
);
21529 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
21532 /* Compute height. */
21533 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
21534 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21537 zero_height_ok_p
= 1;
21539 else if (prop
= Fplist_get (plist
, QCrelative_height
),
21541 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
21543 height
= FONT_HEIGHT (font
);
21545 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
21548 /* Compute percentage of height used for ascent. If
21549 `:ascent ASCENT' is present and valid, use that. Otherwise,
21550 derive the ascent from the font in use. */
21551 if (prop
= Fplist_get (plist
, QCascent
),
21552 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
21553 ascent
= height
* NUMVAL (prop
) / 100.0;
21554 else if (!NILP (prop
)
21555 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21556 ascent
= min (max (0, (int)tem
), height
);
21558 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
21560 if (width
> 0 && it
->line_wrap
!= TRUNCATE
21561 && it
->current_x
+ width
> it
->last_visible_x
)
21562 width
= it
->last_visible_x
- it
->current_x
- 1;
21564 if (width
> 0 && height
> 0 && it
->glyph_row
)
21566 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
21567 if (!STRINGP (object
))
21568 object
= it
->w
->buffer
;
21569 append_stretch_glyph (it
, object
, width
, height
, ascent
);
21572 it
->pixel_width
= width
;
21573 it
->ascent
= it
->phys_ascent
= ascent
;
21574 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
21575 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21577 take_vertical_position_into_account (it
);
21580 /* Calculate line-height and line-spacing properties.
21581 An integer value specifies explicit pixel value.
21582 A float value specifies relative value to current face height.
21583 A cons (float . face-name) specifies relative value to
21584 height of specified face font.
21586 Returns height in pixels, or nil. */
21590 calc_line_height_property (it
, val
, font
, boff
, override
)
21594 int boff
, override
;
21596 Lisp_Object face_name
= Qnil
;
21597 int ascent
, descent
, height
;
21599 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21604 face_name
= XCAR (val
);
21606 if (!NUMBERP (val
))
21607 val
= make_number (1);
21608 if (NILP (face_name
))
21610 height
= it
->ascent
+ it
->descent
;
21615 if (NILP (face_name
))
21617 font
= FRAME_FONT (it
->f
);
21618 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21620 else if (EQ (face_name
, Qt
))
21629 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21631 return make_number (-1);
21633 face
= FACE_FROM_ID (it
->f
, face_id
);
21636 return make_number (-1);
21637 boff
= font
->baseline_offset
;
21638 if (font
->vertical_centering
)
21639 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21642 ascent
= FONT_BASE (font
) + boff
;
21643 descent
= FONT_DESCENT (font
) - boff
;
21647 it
->override_ascent
= ascent
;
21648 it
->override_descent
= descent
;
21649 it
->override_boff
= boff
;
21652 height
= ascent
+ descent
;
21656 height
= (int)(XFLOAT_DATA (val
) * height
);
21657 else if (INTEGERP (val
))
21658 height
*= XINT (val
);
21660 return make_number (height
);
21665 Produce glyphs/get display metrics for the display element IT is
21666 loaded with. See the description of struct it in dispextern.h
21667 for an overview of struct it. */
21670 x_produce_glyphs (it
)
21673 int extra_line_spacing
= it
->extra_line_spacing
;
21675 it
->glyph_not_available_p
= 0;
21677 if (it
->what
== IT_CHARACTER
)
21681 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21682 struct font_metrics
*pcm
;
21683 int font_not_found_p
;
21684 int boff
; /* baseline offset */
21685 /* We may change it->multibyte_p upon unibyte<->multibyte
21686 conversion. So, save the current value now and restore it
21689 Note: It seems that we don't have to record multibyte_p in
21690 struct glyph because the character code itself tells whether
21691 or not the character is multibyte. Thus, in the future, we
21692 must consider eliminating the field `multibyte_p' in the
21694 int saved_multibyte_p
= it
->multibyte_p
;
21696 /* Maybe translate single-byte characters to multibyte, or the
21698 it
->char_to_display
= it
->c
;
21699 if (!ASCII_BYTE_P (it
->c
)
21700 && ! it
->multibyte_p
)
21702 if (SINGLE_BYTE_CHAR_P (it
->c
)
21703 && unibyte_display_via_language_environment
)
21705 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
21707 /* get_next_display_element assures that this decoding
21709 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
21710 it
->multibyte_p
= 1;
21711 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21713 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21717 /* Get font to use. Encode IT->char_to_display. */
21718 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21719 &char2b
, it
->multibyte_p
, 0);
21722 font_not_found_p
= font
== NULL
;
21723 if (font_not_found_p
)
21725 /* When no suitable font found, display an empty box based
21726 on the metrics of the font of the default face (or what
21728 struct face
*no_font_face
21729 = FACE_FROM_ID (it
->f
,
21730 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
21731 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
21732 font
= no_font_face
->font
;
21733 boff
= font
->baseline_offset
;
21737 boff
= font
->baseline_offset
;
21738 if (font
->vertical_centering
)
21739 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21742 if (it
->char_to_display
>= ' '
21743 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21745 /* Either unibyte or ASCII. */
21750 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21752 if (it
->override_ascent
>= 0)
21754 it
->ascent
= it
->override_ascent
;
21755 it
->descent
= it
->override_descent
;
21756 boff
= it
->override_boff
;
21760 it
->ascent
= FONT_BASE (font
) + boff
;
21761 it
->descent
= FONT_DESCENT (font
) - boff
;
21766 it
->phys_ascent
= pcm
->ascent
+ boff
;
21767 it
->phys_descent
= pcm
->descent
- boff
;
21768 it
->pixel_width
= pcm
->width
;
21772 it
->glyph_not_available_p
= 1;
21773 it
->phys_ascent
= it
->ascent
;
21774 it
->phys_descent
= it
->descent
;
21775 it
->pixel_width
= FONT_WIDTH (font
);
21778 if (it
->constrain_row_ascent_descent_p
)
21780 if (it
->descent
> it
->max_descent
)
21782 it
->ascent
+= it
->descent
- it
->max_descent
;
21783 it
->descent
= it
->max_descent
;
21785 if (it
->ascent
> it
->max_ascent
)
21787 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21788 it
->ascent
= it
->max_ascent
;
21790 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21791 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21792 extra_line_spacing
= 0;
21795 /* If this is a space inside a region of text with
21796 `space-width' property, change its width. */
21797 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21799 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21801 /* If face has a box, add the box thickness to the character
21802 height. If character has a box line to the left and/or
21803 right, add the box line width to the character's width. */
21804 if (face
->box
!= FACE_NO_BOX
)
21806 int thick
= face
->box_line_width
;
21810 it
->ascent
+= thick
;
21811 it
->descent
+= thick
;
21816 if (it
->start_of_box_run_p
)
21817 it
->pixel_width
+= thick
;
21818 if (it
->end_of_box_run_p
)
21819 it
->pixel_width
+= thick
;
21822 /* If face has an overline, add the height of the overline
21823 (1 pixel) and a 1 pixel margin to the character height. */
21824 if (face
->overline_p
)
21825 it
->ascent
+= overline_margin
;
21827 if (it
->constrain_row_ascent_descent_p
)
21829 if (it
->ascent
> it
->max_ascent
)
21830 it
->ascent
= it
->max_ascent
;
21831 if (it
->descent
> it
->max_descent
)
21832 it
->descent
= it
->max_descent
;
21835 take_vertical_position_into_account (it
);
21837 /* If we have to actually produce glyphs, do it. */
21842 /* Translate a space with a `space-width' property
21843 into a stretch glyph. */
21844 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21845 / FONT_HEIGHT (font
));
21846 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21847 it
->ascent
+ it
->descent
, ascent
);
21852 /* If characters with lbearing or rbearing are displayed
21853 in this line, record that fact in a flag of the
21854 glyph row. This is used to optimize X output code. */
21855 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21856 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21858 if (! stretched_p
&& it
->pixel_width
== 0)
21859 /* We assure that all visible glyphs have at least 1-pixel
21861 it
->pixel_width
= 1;
21863 else if (it
->char_to_display
== '\n')
21865 /* A newline has no width, but we need the height of the
21866 line. But if previous part of the line sets a height,
21867 don't increase that height */
21869 Lisp_Object height
;
21870 Lisp_Object total_height
= Qnil
;
21872 it
->override_ascent
= -1;
21873 it
->pixel_width
= 0;
21876 height
= get_it_property(it
, Qline_height
);
21877 /* Split (line-height total-height) list */
21879 && CONSP (XCDR (height
))
21880 && NILP (XCDR (XCDR (height
))))
21882 total_height
= XCAR (XCDR (height
));
21883 height
= XCAR (height
);
21885 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21887 if (it
->override_ascent
>= 0)
21889 it
->ascent
= it
->override_ascent
;
21890 it
->descent
= it
->override_descent
;
21891 boff
= it
->override_boff
;
21895 it
->ascent
= FONT_BASE (font
) + boff
;
21896 it
->descent
= FONT_DESCENT (font
) - boff
;
21899 if (EQ (height
, Qt
))
21901 if (it
->descent
> it
->max_descent
)
21903 it
->ascent
+= it
->descent
- it
->max_descent
;
21904 it
->descent
= it
->max_descent
;
21906 if (it
->ascent
> it
->max_ascent
)
21908 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21909 it
->ascent
= it
->max_ascent
;
21911 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21912 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21913 it
->constrain_row_ascent_descent_p
= 1;
21914 extra_line_spacing
= 0;
21918 Lisp_Object spacing
;
21920 it
->phys_ascent
= it
->ascent
;
21921 it
->phys_descent
= it
->descent
;
21923 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21924 && face
->box
!= FACE_NO_BOX
21925 && face
->box_line_width
> 0)
21927 it
->ascent
+= face
->box_line_width
;
21928 it
->descent
+= face
->box_line_width
;
21931 && XINT (height
) > it
->ascent
+ it
->descent
)
21932 it
->ascent
= XINT (height
) - it
->descent
;
21934 if (!NILP (total_height
))
21935 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21938 spacing
= get_it_property(it
, Qline_spacing
);
21939 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21941 if (INTEGERP (spacing
))
21943 extra_line_spacing
= XINT (spacing
);
21944 if (!NILP (total_height
))
21945 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21949 else if (it
->char_to_display
== '\t')
21951 if (font
->space_width
> 0)
21953 int tab_width
= it
->tab_width
* font
->space_width
;
21954 int x
= it
->current_x
+ it
->continuation_lines_width
;
21955 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21957 /* If the distance from the current position to the next tab
21958 stop is less than a space character width, use the
21959 tab stop after that. */
21960 if (next_tab_x
- x
< font
->space_width
)
21961 next_tab_x
+= tab_width
;
21963 it
->pixel_width
= next_tab_x
- x
;
21965 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21966 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21970 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21971 it
->ascent
+ it
->descent
, it
->ascent
);
21976 it
->pixel_width
= 0;
21982 /* A multi-byte character. Assume that the display width of the
21983 character is the width of the character multiplied by the
21984 width of the font. */
21986 /* If we found a font, this font should give us the right
21987 metrics. If we didn't find a font, use the frame's
21988 default font and calculate the width of the character by
21989 multiplying the width of font by the width of the
21992 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21994 if (font_not_found_p
|| !pcm
)
21996 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21998 if (char_width
== 0)
21999 /* This is a non spacing character. But, as we are
22000 going to display an empty box, the box must occupy
22001 at least one column. */
22003 it
->glyph_not_available_p
= 1;
22004 it
->pixel_width
= font
->space_width
* char_width
;
22005 it
->phys_ascent
= FONT_BASE (font
) + boff
;
22006 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22010 it
->pixel_width
= pcm
->width
;
22011 it
->phys_ascent
= pcm
->ascent
+ boff
;
22012 it
->phys_descent
= pcm
->descent
- boff
;
22014 && (pcm
->lbearing
< 0
22015 || pcm
->rbearing
> pcm
->width
))
22016 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22019 it
->ascent
= FONT_BASE (font
) + boff
;
22020 it
->descent
= FONT_DESCENT (font
) - boff
;
22021 if (face
->box
!= FACE_NO_BOX
)
22023 int thick
= face
->box_line_width
;
22027 it
->ascent
+= thick
;
22028 it
->descent
+= thick
;
22033 if (it
->start_of_box_run_p
)
22034 it
->pixel_width
+= thick
;
22035 if (it
->end_of_box_run_p
)
22036 it
->pixel_width
+= thick
;
22039 /* If face has an overline, add the height of the overline
22040 (1 pixel) and a 1 pixel margin to the character height. */
22041 if (face
->overline_p
)
22042 it
->ascent
+= overline_margin
;
22044 take_vertical_position_into_account (it
);
22046 if (it
->ascent
< 0)
22048 if (it
->descent
< 0)
22053 if (it
->pixel_width
== 0)
22054 /* We assure that all visible glyphs have at least 1-pixel
22056 it
->pixel_width
= 1;
22058 it
->multibyte_p
= saved_multibyte_p
;
22060 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22062 /* A static composition.
22064 Note: A composition is represented as one glyph in the
22065 glyph matrix. There are no padding glyphs.
22067 Important note: pixel_width, ascent, and descent are the
22068 values of what is drawn by draw_glyphs (i.e. the values of
22069 the overall glyphs composed). */
22070 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22071 int boff
; /* baseline offset */
22072 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22073 int glyph_len
= cmp
->glyph_len
;
22074 struct font
*font
= face
->font
;
22078 /* If we have not yet calculated pixel size data of glyphs of
22079 the composition for the current face font, calculate them
22080 now. Theoretically, we have to check all fonts for the
22081 glyphs, but that requires much time and memory space. So,
22082 here we check only the font of the first glyph. This may
22083 lead to incorrect display, but it's very rare, and C-l
22084 (recenter-top-bottom) can correct the display anyway. */
22085 if (! cmp
->font
|| cmp
->font
!= font
)
22087 /* Ascent and descent of the font of the first character
22088 of this composition (adjusted by baseline offset).
22089 Ascent and descent of overall glyphs should not be less
22090 than these, respectively. */
22091 int font_ascent
, font_descent
, font_height
;
22092 /* Bounding box of the overall glyphs. */
22093 int leftmost
, rightmost
, lowest
, highest
;
22094 int lbearing
, rbearing
;
22095 int i
, width
, ascent
, descent
;
22096 int left_padded
= 0, right_padded
= 0;
22099 struct font_metrics
*pcm
;
22100 int font_not_found_p
;
22103 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22104 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22106 if (glyph_len
< cmp
->glyph_len
)
22108 for (i
= 0; i
< glyph_len
; i
++)
22110 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22112 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22117 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22118 : IT_CHARPOS (*it
));
22119 /* If no suitable font is found, use the default font. */
22120 font_not_found_p
= font
== NULL
;
22121 if (font_not_found_p
)
22123 face
= face
->ascii_face
;
22126 boff
= font
->baseline_offset
;
22127 if (font
->vertical_centering
)
22128 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22129 font_ascent
= FONT_BASE (font
) + boff
;
22130 font_descent
= FONT_DESCENT (font
) - boff
;
22131 font_height
= FONT_HEIGHT (font
);
22133 cmp
->font
= (void *) font
;
22136 if (! font_not_found_p
)
22138 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22139 &char2b
, it
->multibyte_p
, 0);
22140 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22143 /* Initialize the bounding box. */
22146 width
= pcm
->width
;
22147 ascent
= pcm
->ascent
;
22148 descent
= pcm
->descent
;
22149 lbearing
= pcm
->lbearing
;
22150 rbearing
= pcm
->rbearing
;
22154 width
= FONT_WIDTH (font
);
22155 ascent
= FONT_BASE (font
);
22156 descent
= FONT_DESCENT (font
);
22163 lowest
= - descent
+ boff
;
22164 highest
= ascent
+ boff
;
22166 if (! font_not_found_p
22167 && font
->default_ascent
22168 && CHAR_TABLE_P (Vuse_default_ascent
)
22169 && !NILP (Faref (Vuse_default_ascent
,
22170 make_number (it
->char_to_display
))))
22171 highest
= font
->default_ascent
+ boff
;
22173 /* Draw the first glyph at the normal position. It may be
22174 shifted to right later if some other glyphs are drawn
22176 cmp
->offsets
[i
* 2] = 0;
22177 cmp
->offsets
[i
* 2 + 1] = boff
;
22178 cmp
->lbearing
= lbearing
;
22179 cmp
->rbearing
= rbearing
;
22181 /* Set cmp->offsets for the remaining glyphs. */
22182 for (i
++; i
< glyph_len
; i
++)
22184 int left
, right
, btm
, top
;
22185 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22187 struct face
*this_face
;
22192 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22193 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22194 font
= this_face
->font
;
22200 this_boff
= font
->baseline_offset
;
22201 if (font
->vertical_centering
)
22202 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22203 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22204 &char2b
, it
->multibyte_p
, 0);
22205 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22208 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22211 width
= pcm
->width
;
22212 ascent
= pcm
->ascent
;
22213 descent
= pcm
->descent
;
22214 lbearing
= pcm
->lbearing
;
22215 rbearing
= pcm
->rbearing
;
22216 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22218 /* Relative composition with or without
22219 alternate chars. */
22220 left
= (leftmost
+ rightmost
- width
) / 2;
22221 btm
= - descent
+ boff
;
22222 if (font
->relative_compose
22223 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22224 || NILP (Faref (Vignore_relative_composition
,
22225 make_number (ch
)))))
22228 if (- descent
>= font
->relative_compose
)
22229 /* One extra pixel between two glyphs. */
22231 else if (ascent
<= 0)
22232 /* One extra pixel between two glyphs. */
22233 btm
= lowest
- 1 - ascent
- descent
;
22238 /* A composition rule is specified by an integer
22239 value that encodes global and new reference
22240 points (GREF and NREF). GREF and NREF are
22241 specified by numbers as below:
22243 0---1---2 -- ascent
22247 9--10--11 -- center
22249 ---3---4---5--- baseline
22251 6---7---8 -- descent
22253 int rule
= COMPOSITION_RULE (cmp
, i
);
22254 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
22256 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
22257 grefx
= gref
% 3, nrefx
= nref
% 3;
22258 grefy
= gref
/ 3, nrefy
= nref
/ 3;
22260 xoff
= font_height
* (xoff
- 128) / 256;
22262 yoff
= font_height
* (yoff
- 128) / 256;
22265 + grefx
* (rightmost
- leftmost
) / 2
22266 - nrefx
* width
/ 2
22269 btm
= ((grefy
== 0 ? highest
22271 : grefy
== 2 ? lowest
22272 : (highest
+ lowest
) / 2)
22273 - (nrefy
== 0 ? ascent
+ descent
22274 : nrefy
== 1 ? descent
- boff
22276 : (ascent
+ descent
) / 2)
22280 cmp
->offsets
[i
* 2] = left
;
22281 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
22283 /* Update the bounding box of the overall glyphs. */
22286 right
= left
+ width
;
22287 if (left
< leftmost
)
22289 if (right
> rightmost
)
22292 top
= btm
+ descent
+ ascent
;
22298 if (cmp
->lbearing
> left
+ lbearing
)
22299 cmp
->lbearing
= left
+ lbearing
;
22300 if (cmp
->rbearing
< left
+ rbearing
)
22301 cmp
->rbearing
= left
+ rbearing
;
22305 /* If there are glyphs whose x-offsets are negative,
22306 shift all glyphs to the right and make all x-offsets
22310 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22311 cmp
->offsets
[i
* 2] -= leftmost
;
22312 rightmost
-= leftmost
;
22313 cmp
->lbearing
-= leftmost
;
22314 cmp
->rbearing
-= leftmost
;
22317 if (left_padded
&& cmp
->lbearing
< 0)
22319 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22320 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
22321 rightmost
-= cmp
->lbearing
;
22322 cmp
->rbearing
-= cmp
->lbearing
;
22325 if (right_padded
&& rightmost
< cmp
->rbearing
)
22327 rightmost
= cmp
->rbearing
;
22330 cmp
->pixel_width
= rightmost
;
22331 cmp
->ascent
= highest
;
22332 cmp
->descent
= - lowest
;
22333 if (cmp
->ascent
< font_ascent
)
22334 cmp
->ascent
= font_ascent
;
22335 if (cmp
->descent
< font_descent
)
22336 cmp
->descent
= font_descent
;
22340 && (cmp
->lbearing
< 0
22341 || cmp
->rbearing
> cmp
->pixel_width
))
22342 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22344 it
->pixel_width
= cmp
->pixel_width
;
22345 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
22346 it
->descent
= it
->phys_descent
= cmp
->descent
;
22347 if (face
->box
!= FACE_NO_BOX
)
22349 int thick
= face
->box_line_width
;
22353 it
->ascent
+= thick
;
22354 it
->descent
+= thick
;
22359 if (it
->start_of_box_run_p
)
22360 it
->pixel_width
+= thick
;
22361 if (it
->end_of_box_run_p
)
22362 it
->pixel_width
+= thick
;
22365 /* If face has an overline, add the height of the overline
22366 (1 pixel) and a 1 pixel margin to the character height. */
22367 if (face
->overline_p
)
22368 it
->ascent
+= overline_margin
;
22370 take_vertical_position_into_account (it
);
22371 if (it
->ascent
< 0)
22373 if (it
->descent
< 0)
22377 append_composite_glyph (it
);
22379 else if (it
->what
== IT_COMPOSITION
)
22381 /* A dynamic (automatic) composition. */
22382 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22383 Lisp_Object gstring
;
22384 struct font_metrics metrics
;
22386 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
22388 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
22391 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
22392 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22393 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
22394 it
->descent
= it
->phys_descent
= metrics
.descent
;
22395 if (face
->box
!= FACE_NO_BOX
)
22397 int thick
= face
->box_line_width
;
22401 it
->ascent
+= thick
;
22402 it
->descent
+= thick
;
22407 if (it
->start_of_box_run_p
)
22408 it
->pixel_width
+= thick
;
22409 if (it
->end_of_box_run_p
)
22410 it
->pixel_width
+= thick
;
22412 /* If face has an overline, add the height of the overline
22413 (1 pixel) and a 1 pixel margin to the character height. */
22414 if (face
->overline_p
)
22415 it
->ascent
+= overline_margin
;
22416 take_vertical_position_into_account (it
);
22417 if (it
->ascent
< 0)
22419 if (it
->descent
< 0)
22423 append_composite_glyph (it
);
22425 else if (it
->what
== IT_IMAGE
)
22426 produce_image_glyph (it
);
22427 else if (it
->what
== IT_STRETCH
)
22428 produce_stretch_glyph (it
);
22430 /* Accumulate dimensions. Note: can't assume that it->descent > 0
22431 because this isn't true for images with `:ascent 100'. */
22432 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
22433 if (it
->area
== TEXT_AREA
)
22434 it
->current_x
+= it
->pixel_width
;
22436 if (extra_line_spacing
> 0)
22438 it
->descent
+= extra_line_spacing
;
22439 if (extra_line_spacing
> it
->max_extra_line_spacing
)
22440 it
->max_extra_line_spacing
= extra_line_spacing
;
22443 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
22444 it
->max_descent
= max (it
->max_descent
, it
->descent
);
22445 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
22446 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
22450 Output LEN glyphs starting at START at the nominal cursor position.
22451 Advance the nominal cursor over the text. The global variable
22452 updated_window contains the window being updated, updated_row is
22453 the glyph row being updated, and updated_area is the area of that
22454 row being updated. */
22457 x_write_glyphs (start
, len
)
22458 struct glyph
*start
;
22463 xassert (updated_window
&& updated_row
);
22466 /* Write glyphs. */
22468 hpos
= start
- updated_row
->glyphs
[updated_area
];
22469 x
= draw_glyphs (updated_window
, output_cursor
.x
,
22470 updated_row
, updated_area
,
22472 DRAW_NORMAL_TEXT
, 0);
22474 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
22475 if (updated_area
== TEXT_AREA
22476 && updated_window
->phys_cursor_on_p
22477 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
22478 && updated_window
->phys_cursor
.hpos
>= hpos
22479 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
22480 updated_window
->phys_cursor_on_p
= 0;
22484 /* Advance the output cursor. */
22485 output_cursor
.hpos
+= len
;
22486 output_cursor
.x
= x
;
22491 Insert LEN glyphs from START at the nominal cursor position. */
22494 x_insert_glyphs (start
, len
)
22495 struct glyph
*start
;
22500 int line_height
, shift_by_width
, shifted_region_width
;
22501 struct glyph_row
*row
;
22502 struct glyph
*glyph
;
22503 int frame_x
, frame_y
;
22506 xassert (updated_window
&& updated_row
);
22508 w
= updated_window
;
22509 f
= XFRAME (WINDOW_FRAME (w
));
22511 /* Get the height of the line we are in. */
22513 line_height
= row
->height
;
22515 /* Get the width of the glyphs to insert. */
22516 shift_by_width
= 0;
22517 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
22518 shift_by_width
+= glyph
->pixel_width
;
22520 /* Get the width of the region to shift right. */
22521 shifted_region_width
= (window_box_width (w
, updated_area
)
22526 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
22527 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
22529 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
22530 line_height
, shift_by_width
);
22532 /* Write the glyphs. */
22533 hpos
= start
- row
->glyphs
[updated_area
];
22534 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
22536 DRAW_NORMAL_TEXT
, 0);
22538 /* Advance the output cursor. */
22539 output_cursor
.hpos
+= len
;
22540 output_cursor
.x
+= shift_by_width
;
22546 Erase the current text line from the nominal cursor position
22547 (inclusive) to pixel column TO_X (exclusive). The idea is that
22548 everything from TO_X onward is already erased.
22550 TO_X is a pixel position relative to updated_area of
22551 updated_window. TO_X == -1 means clear to the end of this area. */
22554 x_clear_end_of_line (to_x
)
22558 struct window
*w
= updated_window
;
22559 int max_x
, min_y
, max_y
;
22560 int from_x
, from_y
, to_y
;
22562 xassert (updated_window
&& updated_row
);
22563 f
= XFRAME (w
->frame
);
22565 if (updated_row
->full_width_p
)
22566 max_x
= WINDOW_TOTAL_WIDTH (w
);
22568 max_x
= window_box_width (w
, updated_area
);
22569 max_y
= window_text_bottom_y (w
);
22571 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
22572 of window. For TO_X > 0, truncate to end of drawing area. */
22578 to_x
= min (to_x
, max_x
);
22580 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
22582 /* Notice if the cursor will be cleared by this operation. */
22583 if (!updated_row
->full_width_p
)
22584 notice_overwritten_cursor (w
, updated_area
,
22585 output_cursor
.x
, -1,
22587 MATRIX_ROW_BOTTOM_Y (updated_row
));
22589 from_x
= output_cursor
.x
;
22591 /* Translate to frame coordinates. */
22592 if (updated_row
->full_width_p
)
22594 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
22595 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
22599 int area_left
= window_box_left (w
, updated_area
);
22600 from_x
+= area_left
;
22604 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22605 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22606 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22608 /* Prevent inadvertently clearing to end of the X window. */
22609 if (to_x
> from_x
&& to_y
> from_y
)
22612 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22613 to_x
- from_x
, to_y
- from_y
);
22618 #endif /* HAVE_WINDOW_SYSTEM */
22622 /***********************************************************************
22624 ***********************************************************************/
22626 /* Value is the internal representation of the specified cursor type
22627 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22628 of the bar cursor. */
22630 static enum text_cursor_kinds
22631 get_specified_cursor_type (arg
, width
)
22635 enum text_cursor_kinds type
;
22640 if (EQ (arg
, Qbox
))
22641 return FILLED_BOX_CURSOR
;
22643 if (EQ (arg
, Qhollow
))
22644 return HOLLOW_BOX_CURSOR
;
22646 if (EQ (arg
, Qbar
))
22653 && EQ (XCAR (arg
), Qbar
)
22654 && INTEGERP (XCDR (arg
))
22655 && XINT (XCDR (arg
)) >= 0)
22657 *width
= XINT (XCDR (arg
));
22661 if (EQ (arg
, Qhbar
))
22664 return HBAR_CURSOR
;
22668 && EQ (XCAR (arg
), Qhbar
)
22669 && INTEGERP (XCDR (arg
))
22670 && XINT (XCDR (arg
)) >= 0)
22672 *width
= XINT (XCDR (arg
));
22673 return HBAR_CURSOR
;
22676 /* Treat anything unknown as "hollow box cursor".
22677 It was bad to signal an error; people have trouble fixing
22678 .Xdefaults with Emacs, when it has something bad in it. */
22679 type
= HOLLOW_BOX_CURSOR
;
22684 /* Set the default cursor types for specified frame. */
22686 set_frame_cursor_types (f
, arg
)
22693 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22694 FRAME_CURSOR_WIDTH (f
) = width
;
22696 /* By default, set up the blink-off state depending on the on-state. */
22698 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22701 FRAME_BLINK_OFF_CURSOR (f
)
22702 = get_specified_cursor_type (XCDR (tem
), &width
);
22703 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22706 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22710 /* Return the cursor we want to be displayed in window W. Return
22711 width of bar/hbar cursor through WIDTH arg. Return with
22712 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22713 (i.e. if the `system caret' should track this cursor).
22715 In a mini-buffer window, we want the cursor only to appear if we
22716 are reading input from this window. For the selected window, we
22717 want the cursor type given by the frame parameter or buffer local
22718 setting of cursor-type. If explicitly marked off, draw no cursor.
22719 In all other cases, we want a hollow box cursor. */
22721 static enum text_cursor_kinds
22722 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22724 struct glyph
*glyph
;
22726 int *active_cursor
;
22728 struct frame
*f
= XFRAME (w
->frame
);
22729 struct buffer
*b
= XBUFFER (w
->buffer
);
22730 int cursor_type
= DEFAULT_CURSOR
;
22731 Lisp_Object alt_cursor
;
22732 int non_selected
= 0;
22734 *active_cursor
= 1;
22737 if (cursor_in_echo_area
22738 && FRAME_HAS_MINIBUF_P (f
)
22739 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22741 if (w
== XWINDOW (echo_area_window
))
22743 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22745 *width
= FRAME_CURSOR_WIDTH (f
);
22746 return FRAME_DESIRED_CURSOR (f
);
22749 return get_specified_cursor_type (b
->cursor_type
, width
);
22752 *active_cursor
= 0;
22756 /* Detect a nonselected window or nonselected frame. */
22757 else if (w
!= XWINDOW (f
->selected_window
)
22758 #ifdef HAVE_WINDOW_SYSTEM
22759 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22763 *active_cursor
= 0;
22765 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22771 /* Never display a cursor in a window in which cursor-type is nil. */
22772 if (NILP (b
->cursor_type
))
22775 /* Get the normal cursor type for this window. */
22776 if (EQ (b
->cursor_type
, Qt
))
22778 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22779 *width
= FRAME_CURSOR_WIDTH (f
);
22782 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22784 /* Use cursor-in-non-selected-windows instead
22785 for non-selected window or frame. */
22788 alt_cursor
= b
->cursor_in_non_selected_windows
;
22789 if (!EQ (Qt
, alt_cursor
))
22790 return get_specified_cursor_type (alt_cursor
, width
);
22791 /* t means modify the normal cursor type. */
22792 if (cursor_type
== FILLED_BOX_CURSOR
)
22793 cursor_type
= HOLLOW_BOX_CURSOR
;
22794 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22796 return cursor_type
;
22799 /* Use normal cursor if not blinked off. */
22800 if (!w
->cursor_off_p
)
22802 #ifdef HAVE_WINDOW_SYSTEM
22803 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22805 if (cursor_type
== FILLED_BOX_CURSOR
)
22807 /* Using a block cursor on large images can be very annoying.
22808 So use a hollow cursor for "large" images.
22809 If image is not transparent (no mask), also use hollow cursor. */
22810 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22811 if (img
!= NULL
&& IMAGEP (img
->spec
))
22813 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22814 where N = size of default frame font size.
22815 This should cover most of the "tiny" icons people may use. */
22817 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22818 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22819 cursor_type
= HOLLOW_BOX_CURSOR
;
22822 else if (cursor_type
!= NO_CURSOR
)
22824 /* Display current only supports BOX and HOLLOW cursors for images.
22825 So for now, unconditionally use a HOLLOW cursor when cursor is
22826 not a solid box cursor. */
22827 cursor_type
= HOLLOW_BOX_CURSOR
;
22831 return cursor_type
;
22834 /* Cursor is blinked off, so determine how to "toggle" it. */
22836 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22837 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22838 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22840 /* Then see if frame has specified a specific blink off cursor type. */
22841 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22843 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22844 return FRAME_BLINK_OFF_CURSOR (f
);
22848 /* Some people liked having a permanently visible blinking cursor,
22849 while others had very strong opinions against it. So it was
22850 decided to remove it. KFS 2003-09-03 */
22852 /* Finally perform built-in cursor blinking:
22853 filled box <-> hollow box
22854 wide [h]bar <-> narrow [h]bar
22855 narrow [h]bar <-> no cursor
22856 other type <-> no cursor */
22858 if (cursor_type
== FILLED_BOX_CURSOR
)
22859 return HOLLOW_BOX_CURSOR
;
22861 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22864 return cursor_type
;
22872 #ifdef HAVE_WINDOW_SYSTEM
22874 /* Notice when the text cursor of window W has been completely
22875 overwritten by a drawing operation that outputs glyphs in AREA
22876 starting at X0 and ending at X1 in the line starting at Y0 and
22877 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22878 the rest of the line after X0 has been written. Y coordinates
22879 are window-relative. */
22882 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22884 enum glyph_row_area area
;
22885 int x0
, y0
, x1
, y1
;
22887 int cx0
, cx1
, cy0
, cy1
;
22888 struct glyph_row
*row
;
22890 if (!w
->phys_cursor_on_p
)
22892 if (area
!= TEXT_AREA
)
22895 if (w
->phys_cursor
.vpos
< 0
22896 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22897 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22898 !(row
->enabled_p
&& row
->displays_text_p
)))
22901 if (row
->cursor_in_fringe_p
)
22903 row
->cursor_in_fringe_p
= 0;
22904 draw_fringe_bitmap (w
, row
, 0);
22905 w
->phys_cursor_on_p
= 0;
22909 cx0
= w
->phys_cursor
.x
;
22910 cx1
= cx0
+ w
->phys_cursor_width
;
22911 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22914 /* The cursor image will be completely removed from the
22915 screen if the output area intersects the cursor area in
22916 y-direction. When we draw in [y0 y1[, and some part of
22917 the cursor is at y < y0, that part must have been drawn
22918 before. When scrolling, the cursor is erased before
22919 actually scrolling, so we don't come here. When not
22920 scrolling, the rows above the old cursor row must have
22921 changed, and in this case these rows must have written
22922 over the cursor image.
22924 Likewise if part of the cursor is below y1, with the
22925 exception of the cursor being in the first blank row at
22926 the buffer and window end because update_text_area
22927 doesn't draw that row. (Except when it does, but
22928 that's handled in update_text_area.) */
22930 cy0
= w
->phys_cursor
.y
;
22931 cy1
= cy0
+ w
->phys_cursor_height
;
22932 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22935 w
->phys_cursor_on_p
= 0;
22938 #endif /* HAVE_WINDOW_SYSTEM */
22941 /************************************************************************
22943 ************************************************************************/
22945 #ifdef HAVE_WINDOW_SYSTEM
22948 Fix the display of area AREA of overlapping row ROW in window W
22949 with respect to the overlapping part OVERLAPS. */
22952 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22954 struct glyph_row
*row
;
22955 enum glyph_row_area area
;
22963 for (i
= 0; i
< row
->used
[area
];)
22965 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22967 int start
= i
, start_x
= x
;
22971 x
+= row
->glyphs
[area
][i
].pixel_width
;
22974 while (i
< row
->used
[area
]
22975 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22977 draw_glyphs (w
, start_x
, row
, area
,
22979 DRAW_NORMAL_TEXT
, overlaps
);
22983 x
+= row
->glyphs
[area
][i
].pixel_width
;
22993 Draw the cursor glyph of window W in glyph row ROW. See the
22994 comment of draw_glyphs for the meaning of HL. */
22997 draw_phys_cursor_glyph (w
, row
, hl
)
22999 struct glyph_row
*row
;
23000 enum draw_glyphs_face hl
;
23002 /* If cursor hpos is out of bounds, don't draw garbage. This can
23003 happen in mini-buffer windows when switching between echo area
23004 glyphs and mini-buffer. */
23005 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
23007 int on_p
= w
->phys_cursor_on_p
;
23009 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23010 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23012 w
->phys_cursor_on_p
= on_p
;
23014 if (hl
== DRAW_CURSOR
)
23015 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23016 /* When we erase the cursor, and ROW is overlapped by other
23017 rows, make sure that these overlapping parts of other rows
23019 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23021 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23023 if (row
> w
->current_matrix
->rows
23024 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23025 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23026 OVERLAPS_ERASED_CURSOR
);
23028 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23029 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23030 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23031 OVERLAPS_ERASED_CURSOR
);
23038 Erase the image of a cursor of window W from the screen. */
23041 erase_phys_cursor (w
)
23044 struct frame
*f
= XFRAME (w
->frame
);
23045 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23046 int hpos
= w
->phys_cursor
.hpos
;
23047 int vpos
= w
->phys_cursor
.vpos
;
23048 int mouse_face_here_p
= 0;
23049 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23050 struct glyph_row
*cursor_row
;
23051 struct glyph
*cursor_glyph
;
23052 enum draw_glyphs_face hl
;
23054 /* No cursor displayed or row invalidated => nothing to do on the
23056 if (w
->phys_cursor_type
== NO_CURSOR
)
23057 goto mark_cursor_off
;
23059 /* VPOS >= active_glyphs->nrows means that window has been resized.
23060 Don't bother to erase the cursor. */
23061 if (vpos
>= active_glyphs
->nrows
)
23062 goto mark_cursor_off
;
23064 /* If row containing cursor is marked invalid, there is nothing we
23066 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23067 if (!cursor_row
->enabled_p
)
23068 goto mark_cursor_off
;
23070 /* If line spacing is > 0, old cursor may only be partially visible in
23071 window after split-window. So adjust visible height. */
23072 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23073 window_text_bottom_y (w
) - cursor_row
->y
);
23075 /* If row is completely invisible, don't attempt to delete a cursor which
23076 isn't there. This can happen if cursor is at top of a window, and
23077 we switch to a buffer with a header line in that window. */
23078 if (cursor_row
->visible_height
<= 0)
23079 goto mark_cursor_off
;
23081 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23082 if (cursor_row
->cursor_in_fringe_p
)
23084 cursor_row
->cursor_in_fringe_p
= 0;
23085 draw_fringe_bitmap (w
, cursor_row
, 0);
23086 goto mark_cursor_off
;
23089 /* This can happen when the new row is shorter than the old one.
23090 In this case, either draw_glyphs or clear_end_of_line
23091 should have cleared the cursor. Note that we wouldn't be
23092 able to erase the cursor in this case because we don't have a
23093 cursor glyph at hand. */
23094 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
23095 goto mark_cursor_off
;
23097 /* If the cursor is in the mouse face area, redisplay that when
23098 we clear the cursor. */
23099 if (! NILP (dpyinfo
->mouse_face_window
)
23100 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
23101 && (vpos
> dpyinfo
->mouse_face_beg_row
23102 || (vpos
== dpyinfo
->mouse_face_beg_row
23103 && hpos
>= dpyinfo
->mouse_face_beg_col
))
23104 && (vpos
< dpyinfo
->mouse_face_end_row
23105 || (vpos
== dpyinfo
->mouse_face_end_row
23106 && hpos
< dpyinfo
->mouse_face_end_col
))
23107 /* Don't redraw the cursor's spot in mouse face if it is at the
23108 end of a line (on a newline). The cursor appears there, but
23109 mouse highlighting does not. */
23110 && cursor_row
->used
[TEXT_AREA
] > hpos
)
23111 mouse_face_here_p
= 1;
23113 /* Maybe clear the display under the cursor. */
23114 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23117 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23120 cursor_glyph
= get_phys_cursor_glyph (w
);
23121 if (cursor_glyph
== NULL
)
23122 goto mark_cursor_off
;
23124 width
= cursor_glyph
->pixel_width
;
23125 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23126 x
= w
->phys_cursor
.x
;
23128 width
-= left_x
- x
;
23129 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23130 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23131 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23134 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23137 /* Erase the cursor by redrawing the character underneath it. */
23138 if (mouse_face_here_p
)
23139 hl
= DRAW_MOUSE_FACE
;
23141 hl
= DRAW_NORMAL_TEXT
;
23142 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23145 w
->phys_cursor_on_p
= 0;
23146 w
->phys_cursor_type
= NO_CURSOR
;
23151 Display or clear cursor of window W. If ON is zero, clear the
23152 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23153 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23156 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
23158 int on
, hpos
, vpos
, x
, y
;
23160 struct frame
*f
= XFRAME (w
->frame
);
23161 int new_cursor_type
;
23162 int new_cursor_width
;
23164 struct glyph_row
*glyph_row
;
23165 struct glyph
*glyph
;
23167 /* This is pointless on invisible frames, and dangerous on garbaged
23168 windows and frames; in the latter case, the frame or window may
23169 be in the midst of changing its size, and x and y may be off the
23171 if (! FRAME_VISIBLE_P (f
)
23172 || FRAME_GARBAGED_P (f
)
23173 || vpos
>= w
->current_matrix
->nrows
23174 || hpos
>= w
->current_matrix
->matrix_w
)
23177 /* If cursor is off and we want it off, return quickly. */
23178 if (!on
&& !w
->phys_cursor_on_p
)
23181 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23182 /* If cursor row is not enabled, we don't really know where to
23183 display the cursor. */
23184 if (!glyph_row
->enabled_p
)
23186 w
->phys_cursor_on_p
= 0;
23191 if (!glyph_row
->exact_window_width_line_p
23192 || hpos
< glyph_row
->used
[TEXT_AREA
])
23193 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23195 xassert (interrupt_input_blocked
);
23197 /* Set new_cursor_type to the cursor we want to be displayed. */
23198 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23199 &new_cursor_width
, &active_cursor
);
23201 /* If cursor is currently being shown and we don't want it to be or
23202 it is in the wrong place, or the cursor type is not what we want,
23204 if (w
->phys_cursor_on_p
23206 || w
->phys_cursor
.x
!= x
23207 || w
->phys_cursor
.y
!= y
23208 || new_cursor_type
!= w
->phys_cursor_type
23209 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23210 && new_cursor_width
!= w
->phys_cursor_width
)))
23211 erase_phys_cursor (w
);
23213 /* Don't check phys_cursor_on_p here because that flag is only set
23214 to zero in some cases where we know that the cursor has been
23215 completely erased, to avoid the extra work of erasing the cursor
23216 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23217 still not be visible, or it has only been partly erased. */
23220 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23221 w
->phys_cursor_height
= glyph_row
->height
;
23223 /* Set phys_cursor_.* before x_draw_.* is called because some
23224 of them may need the information. */
23225 w
->phys_cursor
.x
= x
;
23226 w
->phys_cursor
.y
= glyph_row
->y
;
23227 w
->phys_cursor
.hpos
= hpos
;
23228 w
->phys_cursor
.vpos
= vpos
;
23231 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23232 new_cursor_type
, new_cursor_width
,
23233 on
, active_cursor
);
23237 /* Switch the display of W's cursor on or off, according to the value
23244 update_window_cursor (w
, on
)
23248 /* Don't update cursor in windows whose frame is in the process
23249 of being deleted. */
23250 if (w
->current_matrix
)
23253 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23254 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23260 /* Call update_window_cursor with parameter ON_P on all leaf windows
23261 in the window tree rooted at W. */
23264 update_cursor_in_window_tree (w
, on_p
)
23270 if (!NILP (w
->hchild
))
23271 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23272 else if (!NILP (w
->vchild
))
23273 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23275 update_window_cursor (w
, on_p
);
23277 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23283 Display the cursor on window W, or clear it, according to ON_P.
23284 Don't change the cursor's position. */
23287 x_update_cursor (f
, on_p
)
23291 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
23296 Clear the cursor of window W to background color, and mark the
23297 cursor as not shown. This is used when the text where the cursor
23298 is about to be rewritten. */
23304 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
23305 update_window_cursor (w
, 0);
23310 Display the active region described by mouse_face_* according to DRAW. */
23313 show_mouse_face (dpyinfo
, draw
)
23314 Display_Info
*dpyinfo
;
23315 enum draw_glyphs_face draw
;
23317 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
23318 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23320 if (/* If window is in the process of being destroyed, don't bother
23322 w
->current_matrix
!= NULL
23323 /* Don't update mouse highlight if hidden */
23324 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
23325 /* Recognize when we are called to operate on rows that don't exist
23326 anymore. This can happen when a window is split. */
23327 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
23329 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
23330 struct glyph_row
*row
, *first
, *last
;
23332 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
23333 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
23335 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
23337 int start_hpos
, end_hpos
, start_x
;
23339 /* For all but the first row, the highlight starts at column 0. */
23342 start_hpos
= dpyinfo
->mouse_face_beg_col
;
23343 start_x
= dpyinfo
->mouse_face_beg_x
;
23352 end_hpos
= dpyinfo
->mouse_face_end_col
;
23355 end_hpos
= row
->used
[TEXT_AREA
];
23356 if (draw
== DRAW_NORMAL_TEXT
)
23357 row
->fill_line_p
= 1; /* Clear to end of line */
23360 if (end_hpos
> start_hpos
)
23362 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
23363 start_hpos
, end_hpos
,
23367 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
23371 /* When we've written over the cursor, arrange for it to
23372 be displayed again. */
23373 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
23376 display_and_set_cursor (w
, 1,
23377 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23378 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23383 /* Change the mouse cursor. */
23384 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
23385 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
23386 else if (draw
== DRAW_MOUSE_FACE
)
23387 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
23389 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
23393 Clear out the mouse-highlighted active region.
23394 Redraw it un-highlighted first. Value is non-zero if mouse
23395 face was actually drawn unhighlighted. */
23398 clear_mouse_face (dpyinfo
)
23399 Display_Info
*dpyinfo
;
23403 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
23405 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
23409 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23410 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23411 dpyinfo
->mouse_face_window
= Qnil
;
23412 dpyinfo
->mouse_face_overlay
= Qnil
;
23418 Non-zero if physical cursor of window W is within mouse face. */
23421 cursor_in_mouse_face_p (w
)
23424 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23425 int in_mouse_face
= 0;
23427 if (WINDOWP (dpyinfo
->mouse_face_window
)
23428 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
23430 int hpos
= w
->phys_cursor
.hpos
;
23431 int vpos
= w
->phys_cursor
.vpos
;
23433 if (vpos
>= dpyinfo
->mouse_face_beg_row
23434 && vpos
<= dpyinfo
->mouse_face_end_row
23435 && (vpos
> dpyinfo
->mouse_face_beg_row
23436 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23437 && (vpos
< dpyinfo
->mouse_face_end_row
23438 || hpos
< dpyinfo
->mouse_face_end_col
23439 || dpyinfo
->mouse_face_past_end
))
23443 return in_mouse_face
;
23449 /* This function sets the mouse_face_* elements of DPYINFO, assuming
23450 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
23451 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
23452 for the overlay or run of text properties specifying the mouse
23453 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
23454 before-string and after-string that must also be highlighted.
23455 DISPLAY_STRING, if non-nil, is a display string that may cover some
23456 or all of the highlighted text. */
23459 mouse_face_from_buffer_pos (Lisp_Object window
,
23460 Display_Info
*dpyinfo
,
23461 EMACS_INT mouse_charpos
,
23462 EMACS_INT start_charpos
,
23463 EMACS_INT end_charpos
,
23464 Lisp_Object before_string
,
23465 Lisp_Object after_string
,
23466 Lisp_Object display_string
)
23468 struct window
*w
= XWINDOW (window
);
23469 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23470 struct glyph_row
*row
;
23471 struct glyph
*glyph
, *end
;
23475 xassert (NILP (display_string
) || STRINGP (display_string
));
23476 xassert (NILP (before_string
) || STRINGP (before_string
));
23477 xassert (NILP (after_string
) || STRINGP (after_string
));
23479 /* Find the first highlighted glyph. */
23480 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
23482 dpyinfo
->mouse_face_beg_col
= 0;
23483 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
23484 dpyinfo
->mouse_face_beg_x
= first
->x
;
23485 dpyinfo
->mouse_face_beg_y
= first
->y
;
23489 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
23491 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23493 /* If the before-string or display-string contains newlines,
23494 row_containing_pos skips to its last row. Move back. */
23495 if (!NILP (before_string
) || !NILP (display_string
))
23497 struct glyph_row
*prev
;
23498 while ((prev
= row
- 1, prev
>= first
)
23499 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
23500 && prev
->used
[TEXT_AREA
] > 0)
23502 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
23503 glyph
= beg
+ prev
->used
[TEXT_AREA
];
23504 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
23506 || !(EQ (glyph
->object
, before_string
)
23507 || EQ (glyph
->object
, display_string
)))
23513 glyph
= row
->glyphs
[TEXT_AREA
];
23514 end
= glyph
+ row
->used
[TEXT_AREA
];
23516 dpyinfo
->mouse_face_beg_y
= row
->y
;
23517 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23519 /* Skip truncation glyphs at the start of the glyph row. */
23520 if (row
->displays_text_p
)
23522 && INTEGERP (glyph
->object
)
23523 && glyph
->charpos
< 0;
23525 x
+= glyph
->pixel_width
;
23527 /* Scan the glyph row, stopping before BEFORE_STRING or
23528 DISPLAY_STRING or START_CHARPOS. */
23530 && !INTEGERP (glyph
->object
)
23531 && !EQ (glyph
->object
, before_string
)
23532 && !EQ (glyph
->object
, display_string
)
23533 && !(BUFFERP (glyph
->object
)
23534 && glyph
->charpos
>= start_charpos
);
23536 x
+= glyph
->pixel_width
;
23538 dpyinfo
->mouse_face_beg_x
= x
;
23539 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23542 /* Find the last highlighted glyph. */
23543 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
23546 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23547 dpyinfo
->mouse_face_past_end
= 1;
23549 else if (!NILP (after_string
))
23551 /* If the after-string has newlines, advance to its last row. */
23552 struct glyph_row
*next
;
23553 struct glyph_row
*last
23554 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23556 for (next
= row
+ 1;
23558 && next
->used
[TEXT_AREA
] > 0
23559 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
23564 glyph
= row
->glyphs
[TEXT_AREA
];
23565 end
= glyph
+ row
->used
[TEXT_AREA
];
23567 dpyinfo
->mouse_face_end_y
= row
->y
;
23568 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23570 /* Skip truncation glyphs at the start of the row. */
23571 if (row
->displays_text_p
)
23573 && INTEGERP (glyph
->object
)
23574 && glyph
->charpos
< 0;
23576 x
+= glyph
->pixel_width
;
23578 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
23581 && !INTEGERP (glyph
->object
)
23582 && !EQ (glyph
->object
, after_string
)
23583 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
23585 x
+= glyph
->pixel_width
;
23587 /* If we found AFTER_STRING, consume it and stop. */
23588 if (EQ (glyph
->object
, after_string
))
23590 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
23591 x
+= glyph
->pixel_width
;
23595 /* If there's no after-string, we must check if we overshot,
23596 which might be the case if we stopped after a string glyph.
23597 That glyph may belong to a before-string or display-string
23598 associated with the end position, which must not be
23600 Lisp_Object prev_object
;
23603 while (glyph
> row
->glyphs
[TEXT_AREA
])
23605 prev_object
= (glyph
- 1)->object
;
23606 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23609 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23610 if (pos
&& pos
< end_charpos
)
23613 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23614 && EQ ((glyph
- 1)->object
, prev_object
);
23616 x
-= (glyph
- 1)->pixel_width
;
23620 dpyinfo
->mouse_face_end_x
= x
;
23621 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23622 dpyinfo
->mouse_face_window
= window
;
23623 dpyinfo
->mouse_face_face_id
23624 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23626 !dpyinfo
->mouse_face_hidden
, -1);
23627 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23631 /* Find the position of the glyph for position POS in OBJECT in
23632 window W's current matrix, and return in *X, *Y the pixel
23633 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23635 RIGHT_P non-zero means return the position of the right edge of the
23636 glyph, RIGHT_P zero means return the left edge position.
23638 If no glyph for POS exists in the matrix, return the position of
23639 the glyph with the next smaller position that is in the matrix, if
23640 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23641 exists in the matrix, return the position of the glyph with the
23642 next larger position in OBJECT.
23644 Value is non-zero if a glyph was found. */
23647 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23650 Lisp_Object object
;
23651 int *hpos
, *vpos
, *x
, *y
;
23654 int yb
= window_text_bottom_y (w
);
23655 struct glyph_row
*r
;
23656 struct glyph
*best_glyph
= NULL
;
23657 struct glyph_row
*best_row
= NULL
;
23660 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23661 r
->enabled_p
&& r
->y
< yb
;
23664 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23665 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23668 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23669 if (EQ (g
->object
, object
))
23671 if (g
->charpos
== pos
)
23678 else if (best_glyph
== NULL
23679 || ((eabs (g
->charpos
- pos
)
23680 < eabs (best_glyph
->charpos
- pos
))
23683 : g
->charpos
> pos
)))
23697 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23701 *x
+= best_glyph
->pixel_width
;
23706 *vpos
= best_row
- w
->current_matrix
->rows
;
23709 return best_glyph
!= NULL
;
23713 /* See if position X, Y is within a hot-spot of an image. */
23716 on_hot_spot_p (hot_spot
, x
, y
)
23717 Lisp_Object hot_spot
;
23720 if (!CONSP (hot_spot
))
23723 if (EQ (XCAR (hot_spot
), Qrect
))
23725 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23726 Lisp_Object rect
= XCDR (hot_spot
);
23730 if (!CONSP (XCAR (rect
)))
23732 if (!CONSP (XCDR (rect
)))
23734 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23736 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23738 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23740 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23744 else if (EQ (XCAR (hot_spot
), Qcircle
))
23746 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23747 Lisp_Object circ
= XCDR (hot_spot
);
23748 Lisp_Object lr
, lx0
, ly0
;
23750 && CONSP (XCAR (circ
))
23751 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23752 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23753 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23755 double r
= XFLOATINT (lr
);
23756 double dx
= XINT (lx0
) - x
;
23757 double dy
= XINT (ly0
) - y
;
23758 return (dx
* dx
+ dy
* dy
<= r
* r
);
23761 else if (EQ (XCAR (hot_spot
), Qpoly
))
23763 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23764 if (VECTORP (XCDR (hot_spot
)))
23766 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23767 Lisp_Object
*poly
= v
->contents
;
23771 Lisp_Object lx
, ly
;
23774 /* Need an even number of coordinates, and at least 3 edges. */
23775 if (n
< 6 || n
& 1)
23778 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23779 If count is odd, we are inside polygon. Pixels on edges
23780 may or may not be included depending on actual geometry of the
23782 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23783 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23785 x0
= XINT (lx
), y0
= XINT (ly
);
23786 for (i
= 0; i
< n
; i
+= 2)
23788 int x1
= x0
, y1
= y0
;
23789 if ((lx
= poly
[i
], !INTEGERP (lx
))
23790 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23792 x0
= XINT (lx
), y0
= XINT (ly
);
23794 /* Does this segment cross the X line? */
23802 if (y
> y0
&& y
> y1
)
23804 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23814 find_hot_spot (map
, x
, y
)
23818 while (CONSP (map
))
23820 if (CONSP (XCAR (map
))
23821 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23829 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23831 doc
: /* Lookup in image map MAP coordinates X and Y.
23832 An image map is an alist where each element has the format (AREA ID PLIST).
23833 An AREA is specified as either a rectangle, a circle, or a polygon:
23834 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23835 pixel coordinates of the upper left and bottom right corners.
23836 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23837 and the radius of the circle; r may be a float or integer.
23838 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23839 vector describes one corner in the polygon.
23840 Returns the alist element for the first matching AREA in MAP. */)
23851 return find_hot_spot (map
, XINT (x
), XINT (y
));
23855 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23857 define_frame_cursor1 (f
, cursor
, pointer
)
23860 Lisp_Object pointer
;
23862 /* Do not change cursor shape while dragging mouse. */
23863 if (!NILP (do_mouse_tracking
))
23866 if (!NILP (pointer
))
23868 if (EQ (pointer
, Qarrow
))
23869 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23870 else if (EQ (pointer
, Qhand
))
23871 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23872 else if (EQ (pointer
, Qtext
))
23873 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23874 else if (EQ (pointer
, intern ("hdrag")))
23875 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23876 #ifdef HAVE_X_WINDOWS
23877 else if (EQ (pointer
, intern ("vdrag")))
23878 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23880 else if (EQ (pointer
, intern ("hourglass")))
23881 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23882 else if (EQ (pointer
, Qmodeline
))
23883 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23885 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23888 if (cursor
!= No_Cursor
)
23889 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23892 /* Take proper action when mouse has moved to the mode or header line
23893 or marginal area AREA of window W, x-position X and y-position Y.
23894 X is relative to the start of the text display area of W, so the
23895 width of bitmap areas and scroll bars must be subtracted to get a
23896 position relative to the start of the mode line. */
23899 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23900 Lisp_Object window
;
23902 enum window_part area
;
23904 struct window
*w
= XWINDOW (window
);
23905 struct frame
*f
= XFRAME (w
->frame
);
23906 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23907 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23908 Lisp_Object pointer
= Qnil
;
23909 int charpos
, dx
, dy
, width
, height
;
23910 Lisp_Object string
, object
= Qnil
;
23911 Lisp_Object pos
, help
;
23913 Lisp_Object mouse_face
;
23914 int original_x_pixel
= x
;
23915 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23916 struct glyph_row
*row
;
23918 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23923 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23924 &object
, &dx
, &dy
, &width
, &height
);
23926 row
= (area
== ON_MODE_LINE
23927 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23928 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23931 if (row
->mode_line_p
&& row
->enabled_p
)
23933 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23934 end
= glyph
+ row
->used
[TEXT_AREA
];
23936 for (x0
= original_x_pixel
;
23937 glyph
< end
&& x0
>= glyph
->pixel_width
;
23939 x0
-= glyph
->pixel_width
;
23947 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23948 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23949 &object
, &dx
, &dy
, &width
, &height
);
23954 if (IMAGEP (object
))
23956 Lisp_Object image_map
, hotspot
;
23957 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23959 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23961 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23963 Lisp_Object area_id
, plist
;
23965 area_id
= XCAR (hotspot
);
23966 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23967 If so, we could look for mouse-enter, mouse-leave
23968 properties in PLIST (and do something...). */
23969 hotspot
= XCDR (hotspot
);
23970 if (CONSP (hotspot
)
23971 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23973 pointer
= Fplist_get (plist
, Qpointer
);
23974 if (NILP (pointer
))
23976 help
= Fplist_get (plist
, Qhelp_echo
);
23979 help_echo_string
= help
;
23980 /* Is this correct? ++kfs */
23981 XSETWINDOW (help_echo_window
, w
);
23982 help_echo_object
= w
->buffer
;
23983 help_echo_pos
= charpos
;
23987 if (NILP (pointer
))
23988 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23991 if (STRINGP (string
))
23993 pos
= make_number (charpos
);
23994 /* If we're on a string with `help-echo' text property, arrange
23995 for the help to be displayed. This is done by setting the
23996 global variable help_echo_string to the help string. */
23999 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
24002 help_echo_string
= help
;
24003 XSETWINDOW (help_echo_window
, w
);
24004 help_echo_object
= string
;
24005 help_echo_pos
= charpos
;
24009 if (NILP (pointer
))
24010 pointer
= Fget_text_property (pos
, Qpointer
, string
);
24012 /* Change the mouse pointer according to what is under X/Y. */
24013 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
24016 map
= Fget_text_property (pos
, Qlocal_map
, string
);
24017 if (!KEYMAPP (map
))
24018 map
= Fget_text_property (pos
, Qkeymap
, string
);
24019 if (!KEYMAPP (map
))
24020 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
24023 /* Change the mouse face according to what is under X/Y. */
24024 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
24025 if (!NILP (mouse_face
)
24026 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24031 struct glyph
* tmp_glyph
;
24035 int total_pixel_width
;
24040 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
24041 Qmouse_face
, string
, Qnil
);
24043 b
= make_number (0);
24045 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
24047 e
= make_number (SCHARS (string
));
24049 /* Calculate the position(glyph position: GPOS) of GLYPH in
24050 displayed string. GPOS is different from CHARPOS.
24052 CHARPOS is the position of glyph in internal string
24053 object. A mode line string format has structures which
24054 is converted to a flatten by emacs lisp interpreter.
24055 The internal string is an element of the structures.
24056 The displayed string is the flatten string. */
24058 if (glyph
> row_start_glyph
)
24060 tmp_glyph
= glyph
- 1;
24061 while (tmp_glyph
>= row_start_glyph
24062 && tmp_glyph
->charpos
>= XINT (b
)
24063 && EQ (tmp_glyph
->object
, glyph
->object
))
24070 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
24071 displayed string holding GLYPH.
24073 GSEQ_LENGTH is different from SCHARS (STRING).
24074 SCHARS (STRING) returns the length of the internal string. */
24075 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
24076 tmp_glyph
->charpos
< XINT (e
);
24077 tmp_glyph
++, gseq_length
++)
24079 if (!EQ (tmp_glyph
->object
, glyph
->object
))
24083 total_pixel_width
= 0;
24084 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
24085 total_pixel_width
+= tmp_glyph
->pixel_width
;
24087 /* Pre calculation of re-rendering position */
24089 hpos
= (area
== ON_MODE_LINE
24090 ? (w
->current_matrix
)->nrows
- 1
24093 /* If the re-rendering position is included in the last
24094 re-rendering area, we should do nothing. */
24095 if ( EQ (window
, dpyinfo
->mouse_face_window
)
24096 && dpyinfo
->mouse_face_beg_col
<= vpos
24097 && vpos
< dpyinfo
->mouse_face_end_col
24098 && dpyinfo
->mouse_face_beg_row
== hpos
)
24101 if (clear_mouse_face (dpyinfo
))
24102 cursor
= No_Cursor
;
24104 dpyinfo
->mouse_face_beg_col
= vpos
;
24105 dpyinfo
->mouse_face_beg_row
= hpos
;
24107 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
24108 dpyinfo
->mouse_face_beg_y
= 0;
24110 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
24111 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
24113 dpyinfo
->mouse_face_end_x
= 0;
24114 dpyinfo
->mouse_face_end_y
= 0;
24116 dpyinfo
->mouse_face_past_end
= 0;
24117 dpyinfo
->mouse_face_window
= window
;
24119 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
24122 glyph
->face_id
, 1);
24123 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24125 if (NILP (pointer
))
24128 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24129 clear_mouse_face (dpyinfo
);
24131 define_frame_cursor1 (f
, cursor
, pointer
);
24136 Take proper action when the mouse has moved to position X, Y on
24137 frame F as regards highlighting characters that have mouse-face
24138 properties. Also de-highlighting chars where the mouse was before.
24139 X and Y can be negative or out of range. */
24142 note_mouse_highlight (f
, x
, y
)
24146 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24147 enum window_part part
;
24148 Lisp_Object window
;
24150 Cursor cursor
= No_Cursor
;
24151 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
24154 /* When a menu is active, don't highlight because this looks odd. */
24155 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
24156 if (popup_activated ())
24160 if (NILP (Vmouse_highlight
)
24161 || !f
->glyphs_initialized_p
)
24164 dpyinfo
->mouse_face_mouse_x
= x
;
24165 dpyinfo
->mouse_face_mouse_y
= y
;
24166 dpyinfo
->mouse_face_mouse_frame
= f
;
24168 if (dpyinfo
->mouse_face_defer
)
24171 if (gc_in_progress
)
24173 dpyinfo
->mouse_face_deferred_gc
= 1;
24177 /* Which window is that in? */
24178 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
24180 /* If we were displaying active text in another window, clear that.
24181 Also clear if we move out of text area in same window. */
24182 if (! EQ (window
, dpyinfo
->mouse_face_window
)
24183 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
24184 && !NILP (dpyinfo
->mouse_face_window
)))
24185 clear_mouse_face (dpyinfo
);
24187 /* Not on a window -> return. */
24188 if (!WINDOWP (window
))
24191 /* Reset help_echo_string. It will get recomputed below. */
24192 help_echo_string
= Qnil
;
24194 /* Convert to window-relative pixel coordinates. */
24195 w
= XWINDOW (window
);
24196 frame_to_window_pixel_xy (w
, &x
, &y
);
24198 /* Handle tool-bar window differently since it doesn't display a
24200 if (EQ (window
, f
->tool_bar_window
))
24202 note_tool_bar_highlight (f
, x
, y
);
24206 /* Mouse is on the mode, header line or margin? */
24207 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
24208 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
24210 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
24214 if (part
== ON_VERTICAL_BORDER
)
24216 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24217 help_echo_string
= build_string ("drag-mouse-1: resize");
24219 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
24220 || part
== ON_SCROLL_BAR
)
24221 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24223 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24225 /* Are we in a window whose display is up to date?
24226 And verify the buffer's text has not changed. */
24227 b
= XBUFFER (w
->buffer
);
24228 if (part
== ON_TEXT
24229 && EQ (w
->window_end_valid
, w
->buffer
)
24230 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
24231 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
24233 int hpos
, vpos
, i
, dx
, dy
, area
;
24235 struct glyph
*glyph
;
24236 Lisp_Object object
;
24237 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
24238 Lisp_Object
*overlay_vec
= NULL
;
24240 struct buffer
*obuf
;
24241 int obegv
, ozv
, same_region
;
24243 /* Find the glyph under X/Y. */
24244 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
24246 /* Look for :pointer property on image. */
24247 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24249 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24250 if (img
!= NULL
&& IMAGEP (img
->spec
))
24252 Lisp_Object image_map
, hotspot
;
24253 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
24255 && (hotspot
= find_hot_spot (image_map
,
24256 glyph
->slice
.x
+ dx
,
24257 glyph
->slice
.y
+ dy
),
24259 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24261 Lisp_Object area_id
, plist
;
24263 area_id
= XCAR (hotspot
);
24264 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24265 If so, we could look for mouse-enter, mouse-leave
24266 properties in PLIST (and do something...). */
24267 hotspot
= XCDR (hotspot
);
24268 if (CONSP (hotspot
)
24269 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24271 pointer
= Fplist_get (plist
, Qpointer
);
24272 if (NILP (pointer
))
24274 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
24275 if (!NILP (help_echo_string
))
24277 help_echo_window
= window
;
24278 help_echo_object
= glyph
->object
;
24279 help_echo_pos
= glyph
->charpos
;
24283 if (NILP (pointer
))
24284 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
24288 /* Clear mouse face if X/Y not over text. */
24290 || area
!= TEXT_AREA
24291 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
24293 if (clear_mouse_face (dpyinfo
))
24294 cursor
= No_Cursor
;
24295 if (NILP (pointer
))
24297 if (area
!= TEXT_AREA
)
24298 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24300 pointer
= Vvoid_text_area_pointer
;
24305 pos
= glyph
->charpos
;
24306 object
= glyph
->object
;
24307 if (!STRINGP (object
) && !BUFFERP (object
))
24310 /* If we get an out-of-range value, return now; avoid an error. */
24311 if (BUFFERP (object
) && pos
> BUF_Z (b
))
24314 /* Make the window's buffer temporarily current for
24315 overlays_at and compute_char_face. */
24316 obuf
= current_buffer
;
24317 current_buffer
= b
;
24323 /* Is this char mouse-active or does it have help-echo? */
24324 position
= make_number (pos
);
24326 if (BUFFERP (object
))
24328 /* Put all the overlays we want in a vector in overlay_vec. */
24329 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
24330 /* Sort overlays into increasing priority order. */
24331 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
24336 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
24337 && vpos
>= dpyinfo
->mouse_face_beg_row
24338 && vpos
<= dpyinfo
->mouse_face_end_row
24339 && (vpos
> dpyinfo
->mouse_face_beg_row
24340 || hpos
>= dpyinfo
->mouse_face_beg_col
)
24341 && (vpos
< dpyinfo
->mouse_face_end_row
24342 || hpos
< dpyinfo
->mouse_face_end_col
24343 || dpyinfo
->mouse_face_past_end
));
24346 cursor
= No_Cursor
;
24348 /* Check mouse-face highlighting. */
24350 /* If there exists an overlay with mouse-face overlapping
24351 the one we are currently highlighting, we have to
24352 check if we enter the overlapping overlay, and then
24353 highlight only that. */
24354 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
24355 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
24357 /* Find the highest priority overlay with a mouse-face. */
24359 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
24361 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
24362 if (!NILP (mouse_face
))
24363 overlay
= overlay_vec
[i
];
24366 /* If we're highlighting the same overlay as before, there's
24367 no need to do that again. */
24368 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
24369 goto check_help_echo
;
24370 dpyinfo
->mouse_face_overlay
= overlay
;
24372 /* Clear the display of the old active region, if any. */
24373 if (clear_mouse_face (dpyinfo
))
24374 cursor
= No_Cursor
;
24376 /* If no overlay applies, get a text property. */
24377 if (NILP (overlay
))
24378 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
24380 /* Next, compute the bounds of the mouse highlighting and
24382 if (!NILP (mouse_face
) && STRINGP (object
))
24384 /* The mouse-highlighting comes from a display string
24385 with a mouse-face. */
24389 b
= Fprevious_single_property_change
24390 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
24391 e
= Fnext_single_property_change
24392 (position
, Qmouse_face
, object
, Qnil
);
24394 b
= make_number (0);
24396 e
= make_number (SCHARS (object
) - 1);
24398 fast_find_string_pos (w
, XINT (b
), object
,
24399 &dpyinfo
->mouse_face_beg_col
,
24400 &dpyinfo
->mouse_face_beg_row
,
24401 &dpyinfo
->mouse_face_beg_x
,
24402 &dpyinfo
->mouse_face_beg_y
, 0);
24403 fast_find_string_pos (w
, XINT (e
), object
,
24404 &dpyinfo
->mouse_face_end_col
,
24405 &dpyinfo
->mouse_face_end_row
,
24406 &dpyinfo
->mouse_face_end_x
,
24407 &dpyinfo
->mouse_face_end_y
, 1);
24408 dpyinfo
->mouse_face_past_end
= 0;
24409 dpyinfo
->mouse_face_window
= window
;
24410 dpyinfo
->mouse_face_face_id
24411 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
24412 glyph
->face_id
, 1);
24413 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24414 cursor
= No_Cursor
;
24418 /* The mouse-highlighting, if any, comes from an overlay
24419 or text property in the buffer. */
24420 Lisp_Object buffer
, display_string
;
24422 if (STRINGP (object
))
24424 /* If we are on a display string with no mouse-face,
24425 check if the text under it has one. */
24426 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
24427 int start
= MATRIX_ROW_START_CHARPOS (r
);
24428 pos
= string_buffer_position (w
, object
, start
);
24431 mouse_face
= get_char_property_and_overlay
24432 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
24433 buffer
= w
->buffer
;
24434 display_string
= object
;
24440 display_string
= Qnil
;
24443 if (!NILP (mouse_face
))
24445 Lisp_Object before
, after
;
24446 Lisp_Object before_string
, after_string
;
24448 if (NILP (overlay
))
24450 /* Handle the text property case. */
24451 before
= Fprevious_single_property_change
24452 (make_number (pos
+ 1), Qmouse_face
, buffer
,
24453 Fmarker_position (w
->start
));
24454 after
= Fnext_single_property_change
24455 (make_number (pos
), Qmouse_face
, buffer
,
24456 make_number (BUF_Z (XBUFFER (buffer
))
24457 - XFASTINT (w
->window_end_pos
)));
24458 before_string
= after_string
= Qnil
;
24462 /* Handle the overlay case. */
24463 before
= Foverlay_start (overlay
);
24464 after
= Foverlay_end (overlay
);
24465 before_string
= Foverlay_get (overlay
, Qbefore_string
);
24466 after_string
= Foverlay_get (overlay
, Qafter_string
);
24468 if (!STRINGP (before_string
)) before_string
= Qnil
;
24469 if (!STRINGP (after_string
)) after_string
= Qnil
;
24472 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
24475 before_string
, after_string
,
24477 cursor
= No_Cursor
;
24484 /* Look for a `help-echo' property. */
24485 if (NILP (help_echo_string
)) {
24486 Lisp_Object help
, overlay
;
24488 /* Check overlays first. */
24489 help
= overlay
= Qnil
;
24490 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
24492 overlay
= overlay_vec
[i
];
24493 help
= Foverlay_get (overlay
, Qhelp_echo
);
24498 help_echo_string
= help
;
24499 help_echo_window
= window
;
24500 help_echo_object
= overlay
;
24501 help_echo_pos
= pos
;
24505 Lisp_Object object
= glyph
->object
;
24506 int charpos
= glyph
->charpos
;
24508 /* Try text properties. */
24509 if (STRINGP (object
)
24511 && charpos
< SCHARS (object
))
24513 help
= Fget_text_property (make_number (charpos
),
24514 Qhelp_echo
, object
);
24517 /* If the string itself doesn't specify a help-echo,
24518 see if the buffer text ``under'' it does. */
24519 struct glyph_row
*r
24520 = MATRIX_ROW (w
->current_matrix
, vpos
);
24521 int start
= MATRIX_ROW_START_CHARPOS (r
);
24522 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
24525 help
= Fget_char_property (make_number (pos
),
24526 Qhelp_echo
, w
->buffer
);
24530 object
= w
->buffer
;
24535 else if (BUFFERP (object
)
24538 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
24543 help_echo_string
= help
;
24544 help_echo_window
= window
;
24545 help_echo_object
= object
;
24546 help_echo_pos
= charpos
;
24551 /* Look for a `pointer' property. */
24552 if (NILP (pointer
))
24554 /* Check overlays first. */
24555 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
24556 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
24558 if (NILP (pointer
))
24560 Lisp_Object object
= glyph
->object
;
24561 int charpos
= glyph
->charpos
;
24563 /* Try text properties. */
24564 if (STRINGP (object
)
24566 && charpos
< SCHARS (object
))
24568 pointer
= Fget_text_property (make_number (charpos
),
24570 if (NILP (pointer
))
24572 /* If the string itself doesn't specify a pointer,
24573 see if the buffer text ``under'' it does. */
24574 struct glyph_row
*r
24575 = MATRIX_ROW (w
->current_matrix
, vpos
);
24576 int start
= MATRIX_ROW_START_CHARPOS (r
);
24577 EMACS_INT pos
= string_buffer_position (w
, object
,
24580 pointer
= Fget_char_property (make_number (pos
),
24581 Qpointer
, w
->buffer
);
24584 else if (BUFFERP (object
)
24587 pointer
= Fget_text_property (make_number (charpos
),
24594 current_buffer
= obuf
;
24599 define_frame_cursor1 (f
, cursor
, pointer
);
24604 Clear any mouse-face on window W. This function is part of the
24605 redisplay interface, and is called from try_window_id and similar
24606 functions to ensure the mouse-highlight is off. */
24609 x_clear_window_mouse_face (w
)
24612 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24613 Lisp_Object window
;
24616 XSETWINDOW (window
, w
);
24617 if (EQ (window
, dpyinfo
->mouse_face_window
))
24618 clear_mouse_face (dpyinfo
);
24624 Just discard the mouse face information for frame F, if any.
24625 This is used when the size of F is changed. */
24628 cancel_mouse_face (f
)
24631 Lisp_Object window
;
24632 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24634 window
= dpyinfo
->mouse_face_window
;
24635 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24637 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24638 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24639 dpyinfo
->mouse_face_window
= Qnil
;
24644 #endif /* HAVE_WINDOW_SYSTEM */
24647 /***********************************************************************
24649 ***********************************************************************/
24651 #ifdef HAVE_WINDOW_SYSTEM
24653 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24654 which intersects rectangle R. R is in window-relative coordinates. */
24657 expose_area (w
, row
, r
, area
)
24659 struct glyph_row
*row
;
24661 enum glyph_row_area area
;
24663 struct glyph
*first
= row
->glyphs
[area
];
24664 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24665 struct glyph
*last
;
24666 int first_x
, start_x
, x
;
24668 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24669 /* If row extends face to end of line write the whole line. */
24670 draw_glyphs (w
, 0, row
, area
,
24671 0, row
->used
[area
],
24672 DRAW_NORMAL_TEXT
, 0);
24675 /* Set START_X to the window-relative start position for drawing glyphs of
24676 AREA. The first glyph of the text area can be partially visible.
24677 The first glyphs of other areas cannot. */
24678 start_x
= window_box_left_offset (w
, area
);
24680 if (area
== TEXT_AREA
)
24683 /* Find the first glyph that must be redrawn. */
24685 && x
+ first
->pixel_width
< r
->x
)
24687 x
+= first
->pixel_width
;
24691 /* Find the last one. */
24695 && x
< r
->x
+ r
->width
)
24697 x
+= last
->pixel_width
;
24703 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24704 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24705 DRAW_NORMAL_TEXT
, 0);
24710 /* Redraw the parts of the glyph row ROW on window W intersecting
24711 rectangle R. R is in window-relative coordinates. Value is
24712 non-zero if mouse-face was overwritten. */
24715 expose_line (w
, row
, r
)
24717 struct glyph_row
*row
;
24720 xassert (row
->enabled_p
);
24722 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24723 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24724 0, row
->used
[TEXT_AREA
],
24725 DRAW_NORMAL_TEXT
, 0);
24728 if (row
->used
[LEFT_MARGIN_AREA
])
24729 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24730 if (row
->used
[TEXT_AREA
])
24731 expose_area (w
, row
, r
, TEXT_AREA
);
24732 if (row
->used
[RIGHT_MARGIN_AREA
])
24733 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24734 draw_row_fringe_bitmaps (w
, row
);
24737 return row
->mouse_face_p
;
24741 /* Redraw those parts of glyphs rows during expose event handling that
24742 overlap other rows. Redrawing of an exposed line writes over parts
24743 of lines overlapping that exposed line; this function fixes that.
24745 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24746 row in W's current matrix that is exposed and overlaps other rows.
24747 LAST_OVERLAPPING_ROW is the last such row. */
24750 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24752 struct glyph_row
*first_overlapping_row
;
24753 struct glyph_row
*last_overlapping_row
;
24756 struct glyph_row
*row
;
24758 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24759 if (row
->overlapping_p
)
24761 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24764 if (row
->used
[LEFT_MARGIN_AREA
])
24765 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24767 if (row
->used
[TEXT_AREA
])
24768 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24770 if (row
->used
[RIGHT_MARGIN_AREA
])
24771 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24777 /* Return non-zero if W's cursor intersects rectangle R. */
24780 phys_cursor_in_rect_p (w
, r
)
24784 XRectangle cr
, result
;
24785 struct glyph
*cursor_glyph
;
24786 struct glyph_row
*row
;
24788 if (w
->phys_cursor
.vpos
>= 0
24789 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24790 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24792 && row
->cursor_in_fringe_p
)
24794 /* Cursor is in the fringe. */
24795 cr
.x
= window_box_right_offset (w
,
24796 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24797 ? RIGHT_MARGIN_AREA
24800 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24801 cr
.height
= row
->height
;
24802 return x_intersect_rectangles (&cr
, r
, &result
);
24805 cursor_glyph
= get_phys_cursor_glyph (w
);
24808 /* r is relative to W's box, but w->phys_cursor.x is relative
24809 to left edge of W's TEXT area. Adjust it. */
24810 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24811 cr
.y
= w
->phys_cursor
.y
;
24812 cr
.width
= cursor_glyph
->pixel_width
;
24813 cr
.height
= w
->phys_cursor_height
;
24814 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24815 I assume the effect is the same -- and this is portable. */
24816 return x_intersect_rectangles (&cr
, r
, &result
);
24818 /* If we don't understand the format, pretend we're not in the hot-spot. */
24824 Draw a vertical window border to the right of window W if W doesn't
24825 have vertical scroll bars. */
24828 x_draw_vertical_border (w
)
24831 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24833 /* We could do better, if we knew what type of scroll-bar the adjacent
24834 windows (on either side) have... But we don't :-(
24835 However, I think this works ok. ++KFS 2003-04-25 */
24837 /* Redraw borders between horizontally adjacent windows. Don't
24838 do it for frames with vertical scroll bars because either the
24839 right scroll bar of a window, or the left scroll bar of its
24840 neighbor will suffice as a border. */
24841 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24844 if (!WINDOW_RIGHTMOST_P (w
)
24845 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24847 int x0
, x1
, y0
, y1
;
24849 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24852 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24855 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24857 else if (!WINDOW_LEFTMOST_P (w
)
24858 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24860 int x0
, x1
, y0
, y1
;
24862 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24865 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24868 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24873 /* Redraw the part of window W intersection rectangle FR. Pixel
24874 coordinates in FR are frame-relative. Call this function with
24875 input blocked. Value is non-zero if the exposure overwrites
24879 expose_window (w
, fr
)
24883 struct frame
*f
= XFRAME (w
->frame
);
24885 int mouse_face_overwritten_p
= 0;
24887 /* If window is not yet fully initialized, do nothing. This can
24888 happen when toolkit scroll bars are used and a window is split.
24889 Reconfiguring the scroll bar will generate an expose for a newly
24891 if (w
->current_matrix
== NULL
)
24894 /* When we're currently updating the window, display and current
24895 matrix usually don't agree. Arrange for a thorough display
24897 if (w
== updated_window
)
24899 SET_FRAME_GARBAGED (f
);
24903 /* Frame-relative pixel rectangle of W. */
24904 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24905 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24906 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24907 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24909 if (x_intersect_rectangles (fr
, &wr
, &r
))
24911 int yb
= window_text_bottom_y (w
);
24912 struct glyph_row
*row
;
24913 int cursor_cleared_p
;
24914 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24916 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24917 r
.x
, r
.y
, r
.width
, r
.height
));
24919 /* Convert to window coordinates. */
24920 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24921 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24923 /* Turn off the cursor. */
24924 if (!w
->pseudo_window_p
24925 && phys_cursor_in_rect_p (w
, &r
))
24927 x_clear_cursor (w
);
24928 cursor_cleared_p
= 1;
24931 cursor_cleared_p
= 0;
24933 /* Update lines intersecting rectangle R. */
24934 first_overlapping_row
= last_overlapping_row
= NULL
;
24935 for (row
= w
->current_matrix
->rows
;
24940 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24942 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24943 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24944 || (r
.y
>= y0
&& r
.y
< y1
)
24945 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24947 /* A header line may be overlapping, but there is no need
24948 to fix overlapping areas for them. KFS 2005-02-12 */
24949 if (row
->overlapping_p
&& !row
->mode_line_p
)
24951 if (first_overlapping_row
== NULL
)
24952 first_overlapping_row
= row
;
24953 last_overlapping_row
= row
;
24957 if (expose_line (w
, row
, &r
))
24958 mouse_face_overwritten_p
= 1;
24961 else if (row
->overlapping_p
)
24963 /* We must redraw a row overlapping the exposed area. */
24965 ? y0
+ row
->phys_height
> r
.y
24966 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24968 if (first_overlapping_row
== NULL
)
24969 first_overlapping_row
= row
;
24970 last_overlapping_row
= row
;
24978 /* Display the mode line if there is one. */
24979 if (WINDOW_WANTS_MODELINE_P (w
)
24980 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24982 && row
->y
< r
.y
+ r
.height
)
24984 if (expose_line (w
, row
, &r
))
24985 mouse_face_overwritten_p
= 1;
24988 if (!w
->pseudo_window_p
)
24990 /* Fix the display of overlapping rows. */
24991 if (first_overlapping_row
)
24992 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24995 /* Draw border between windows. */
24996 x_draw_vertical_border (w
);
24998 /* Turn the cursor on again. */
24999 if (cursor_cleared_p
)
25000 update_window_cursor (w
, 1);
25004 return mouse_face_overwritten_p
;
25009 /* Redraw (parts) of all windows in the window tree rooted at W that
25010 intersect R. R contains frame pixel coordinates. Value is
25011 non-zero if the exposure overwrites mouse-face. */
25014 expose_window_tree (w
, r
)
25018 struct frame
*f
= XFRAME (w
->frame
);
25019 int mouse_face_overwritten_p
= 0;
25021 while (w
&& !FRAME_GARBAGED_P (f
))
25023 if (!NILP (w
->hchild
))
25024 mouse_face_overwritten_p
25025 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
25026 else if (!NILP (w
->vchild
))
25027 mouse_face_overwritten_p
25028 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
25030 mouse_face_overwritten_p
|= expose_window (w
, r
);
25032 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
25035 return mouse_face_overwritten_p
;
25040 Redisplay an exposed area of frame F. X and Y are the upper-left
25041 corner of the exposed rectangle. W and H are width and height of
25042 the exposed area. All are pixel values. W or H zero means redraw
25043 the entire frame. */
25046 expose_frame (f
, x
, y
, w
, h
)
25051 int mouse_face_overwritten_p
= 0;
25053 TRACE ((stderr
, "expose_frame "));
25055 /* No need to redraw if frame will be redrawn soon. */
25056 if (FRAME_GARBAGED_P (f
))
25058 TRACE ((stderr
, " garbaged\n"));
25062 /* If basic faces haven't been realized yet, there is no point in
25063 trying to redraw anything. This can happen when we get an expose
25064 event while Emacs is starting, e.g. by moving another window. */
25065 if (FRAME_FACE_CACHE (f
) == NULL
25066 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
25068 TRACE ((stderr
, " no faces\n"));
25072 if (w
== 0 || h
== 0)
25075 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
25076 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
25086 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
25087 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
25089 if (WINDOWP (f
->tool_bar_window
))
25090 mouse_face_overwritten_p
25091 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
25093 #ifdef HAVE_X_WINDOWS
25095 #ifndef USE_X_TOOLKIT
25096 if (WINDOWP (f
->menu_bar_window
))
25097 mouse_face_overwritten_p
25098 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
25099 #endif /* not USE_X_TOOLKIT */
25103 /* Some window managers support a focus-follows-mouse style with
25104 delayed raising of frames. Imagine a partially obscured frame,
25105 and moving the mouse into partially obscured mouse-face on that
25106 frame. The visible part of the mouse-face will be highlighted,
25107 then the WM raises the obscured frame. With at least one WM, KDE
25108 2.1, Emacs is not getting any event for the raising of the frame
25109 (even tried with SubstructureRedirectMask), only Expose events.
25110 These expose events will draw text normally, i.e. not
25111 highlighted. Which means we must redo the highlight here.
25112 Subsume it under ``we love X''. --gerd 2001-08-15 */
25113 /* Included in Windows version because Windows most likely does not
25114 do the right thing if any third party tool offers
25115 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
25116 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
25118 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25119 if (f
== dpyinfo
->mouse_face_mouse_frame
)
25121 int x
= dpyinfo
->mouse_face_mouse_x
;
25122 int y
= dpyinfo
->mouse_face_mouse_y
;
25123 clear_mouse_face (dpyinfo
);
25124 note_mouse_highlight (f
, x
, y
);
25131 Determine the intersection of two rectangles R1 and R2. Return
25132 the intersection in *RESULT. Value is non-zero if RESULT is not
25136 x_intersect_rectangles (r1
, r2
, result
)
25137 XRectangle
*r1
, *r2
, *result
;
25139 XRectangle
*left
, *right
;
25140 XRectangle
*upper
, *lower
;
25141 int intersection_p
= 0;
25143 /* Rearrange so that R1 is the left-most rectangle. */
25145 left
= r1
, right
= r2
;
25147 left
= r2
, right
= r1
;
25149 /* X0 of the intersection is right.x0, if this is inside R1,
25150 otherwise there is no intersection. */
25151 if (right
->x
<= left
->x
+ left
->width
)
25153 result
->x
= right
->x
;
25155 /* The right end of the intersection is the minimum of the
25156 the right ends of left and right. */
25157 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
25160 /* Same game for Y. */
25162 upper
= r1
, lower
= r2
;
25164 upper
= r2
, lower
= r1
;
25166 /* The upper end of the intersection is lower.y0, if this is inside
25167 of upper. Otherwise, there is no intersection. */
25168 if (lower
->y
<= upper
->y
+ upper
->height
)
25170 result
->y
= lower
->y
;
25172 /* The lower end of the intersection is the minimum of the lower
25173 ends of upper and lower. */
25174 result
->height
= (min (lower
->y
+ lower
->height
,
25175 upper
->y
+ upper
->height
)
25177 intersection_p
= 1;
25181 return intersection_p
;
25184 #endif /* HAVE_WINDOW_SYSTEM */
25187 /***********************************************************************
25189 ***********************************************************************/
25194 Vwith_echo_area_save_vector
= Qnil
;
25195 staticpro (&Vwith_echo_area_save_vector
);
25197 Vmessage_stack
= Qnil
;
25198 staticpro (&Vmessage_stack
);
25200 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
25201 staticpro (&Qinhibit_redisplay
);
25203 message_dolog_marker1
= Fmake_marker ();
25204 staticpro (&message_dolog_marker1
);
25205 message_dolog_marker2
= Fmake_marker ();
25206 staticpro (&message_dolog_marker2
);
25207 message_dolog_marker3
= Fmake_marker ();
25208 staticpro (&message_dolog_marker3
);
25211 defsubr (&Sdump_frame_glyph_matrix
);
25212 defsubr (&Sdump_glyph_matrix
);
25213 defsubr (&Sdump_glyph_row
);
25214 defsubr (&Sdump_tool_bar_row
);
25215 defsubr (&Strace_redisplay
);
25216 defsubr (&Strace_to_stderr
);
25218 #ifdef HAVE_WINDOW_SYSTEM
25219 defsubr (&Stool_bar_lines_needed
);
25220 defsubr (&Slookup_image_map
);
25222 defsubr (&Sformat_mode_line
);
25223 defsubr (&Sinvisible_p
);
25225 staticpro (&Qmenu_bar_update_hook
);
25226 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
25228 staticpro (&Qoverriding_terminal_local_map
);
25229 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
25231 staticpro (&Qoverriding_local_map
);
25232 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
25234 staticpro (&Qwindow_scroll_functions
);
25235 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
25237 staticpro (&Qwindow_text_change_functions
);
25238 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
25240 staticpro (&Qredisplay_end_trigger_functions
);
25241 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
25243 staticpro (&Qinhibit_point_motion_hooks
);
25244 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
25246 Qeval
= intern_c_string ("eval");
25247 staticpro (&Qeval
);
25249 QCdata
= intern_c_string (":data");
25250 staticpro (&QCdata
);
25251 Qdisplay
= intern_c_string ("display");
25252 staticpro (&Qdisplay
);
25253 Qspace_width
= intern_c_string ("space-width");
25254 staticpro (&Qspace_width
);
25255 Qraise
= intern_c_string ("raise");
25256 staticpro (&Qraise
);
25257 Qslice
= intern_c_string ("slice");
25258 staticpro (&Qslice
);
25259 Qspace
= intern_c_string ("space");
25260 staticpro (&Qspace
);
25261 Qmargin
= intern_c_string ("margin");
25262 staticpro (&Qmargin
);
25263 Qpointer
= intern_c_string ("pointer");
25264 staticpro (&Qpointer
);
25265 Qleft_margin
= intern_c_string ("left-margin");
25266 staticpro (&Qleft_margin
);
25267 Qright_margin
= intern_c_string ("right-margin");
25268 staticpro (&Qright_margin
);
25269 Qcenter
= intern_c_string ("center");
25270 staticpro (&Qcenter
);
25271 Qline_height
= intern_c_string ("line-height");
25272 staticpro (&Qline_height
);
25273 QCalign_to
= intern_c_string (":align-to");
25274 staticpro (&QCalign_to
);
25275 QCrelative_width
= intern_c_string (":relative-width");
25276 staticpro (&QCrelative_width
);
25277 QCrelative_height
= intern_c_string (":relative-height");
25278 staticpro (&QCrelative_height
);
25279 QCeval
= intern_c_string (":eval");
25280 staticpro (&QCeval
);
25281 QCpropertize
= intern_c_string (":propertize");
25282 staticpro (&QCpropertize
);
25283 QCfile
= intern_c_string (":file");
25284 staticpro (&QCfile
);
25285 Qfontified
= intern_c_string ("fontified");
25286 staticpro (&Qfontified
);
25287 Qfontification_functions
= intern_c_string ("fontification-functions");
25288 staticpro (&Qfontification_functions
);
25289 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
25290 staticpro (&Qtrailing_whitespace
);
25291 Qescape_glyph
= intern_c_string ("escape-glyph");
25292 staticpro (&Qescape_glyph
);
25293 Qnobreak_space
= intern_c_string ("nobreak-space");
25294 staticpro (&Qnobreak_space
);
25295 Qimage
= intern_c_string ("image");
25296 staticpro (&Qimage
);
25297 QCmap
= intern_c_string (":map");
25298 staticpro (&QCmap
);
25299 QCpointer
= intern_c_string (":pointer");
25300 staticpro (&QCpointer
);
25301 Qrect
= intern_c_string ("rect");
25302 staticpro (&Qrect
);
25303 Qcircle
= intern_c_string ("circle");
25304 staticpro (&Qcircle
);
25305 Qpoly
= intern_c_string ("poly");
25306 staticpro (&Qpoly
);
25307 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
25308 staticpro (&Qmessage_truncate_lines
);
25309 Qgrow_only
= intern_c_string ("grow-only");
25310 staticpro (&Qgrow_only
);
25311 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
25312 staticpro (&Qinhibit_menubar_update
);
25313 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
25314 staticpro (&Qinhibit_eval_during_redisplay
);
25315 Qposition
= intern_c_string ("position");
25316 staticpro (&Qposition
);
25317 Qbuffer_position
= intern_c_string ("buffer-position");
25318 staticpro (&Qbuffer_position
);
25319 Qobject
= intern_c_string ("object");
25320 staticpro (&Qobject
);
25321 Qbar
= intern_c_string ("bar");
25323 Qhbar
= intern_c_string ("hbar");
25324 staticpro (&Qhbar
);
25325 Qbox
= intern_c_string ("box");
25327 Qhollow
= intern_c_string ("hollow");
25328 staticpro (&Qhollow
);
25329 Qhand
= intern_c_string ("hand");
25330 staticpro (&Qhand
);
25331 Qarrow
= intern_c_string ("arrow");
25332 staticpro (&Qarrow
);
25333 Qtext
= intern_c_string ("text");
25334 staticpro (&Qtext
);
25335 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
25336 staticpro (&Qrisky_local_variable
);
25337 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
25338 staticpro (&Qinhibit_free_realized_faces
);
25340 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
25341 Fcons (intern_c_string ("void-variable"), Qnil
)),
25343 staticpro (&list_of_error
);
25345 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
25346 staticpro (&Qlast_arrow_position
);
25347 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
25348 staticpro (&Qlast_arrow_string
);
25350 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
25351 staticpro (&Qoverlay_arrow_string
);
25352 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
25353 staticpro (&Qoverlay_arrow_bitmap
);
25355 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
25356 staticpro (&echo_buffer
[0]);
25357 staticpro (&echo_buffer
[1]);
25359 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
25360 staticpro (&echo_area_buffer
[0]);
25361 staticpro (&echo_area_buffer
[1]);
25363 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
25364 staticpro (&Vmessages_buffer_name
);
25366 mode_line_proptrans_alist
= Qnil
;
25367 staticpro (&mode_line_proptrans_alist
);
25368 mode_line_string_list
= Qnil
;
25369 staticpro (&mode_line_string_list
);
25370 mode_line_string_face
= Qnil
;
25371 staticpro (&mode_line_string_face
);
25372 mode_line_string_face_prop
= Qnil
;
25373 staticpro (&mode_line_string_face_prop
);
25374 Vmode_line_unwind_vector
= Qnil
;
25375 staticpro (&Vmode_line_unwind_vector
);
25377 help_echo_string
= Qnil
;
25378 staticpro (&help_echo_string
);
25379 help_echo_object
= Qnil
;
25380 staticpro (&help_echo_object
);
25381 help_echo_window
= Qnil
;
25382 staticpro (&help_echo_window
);
25383 previous_help_echo_string
= Qnil
;
25384 staticpro (&previous_help_echo_string
);
25385 help_echo_pos
= -1;
25387 Qright_to_left
= intern ("right-to-left");
25388 staticpro (&Qright_to_left
);
25389 Qleft_to_right
= intern ("left-to-right");
25390 staticpro (&Qleft_to_right
);
25392 #ifdef HAVE_WINDOW_SYSTEM
25393 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
25394 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
25395 For example, if a block cursor is over a tab, it will be drawn as
25396 wide as that tab on the display. */);
25397 x_stretch_cursor_p
= 0;
25400 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
25401 doc
: /* *Non-nil means highlight trailing whitespace.
25402 The face used for trailing whitespace is `trailing-whitespace'. */);
25403 Vshow_trailing_whitespace
= Qnil
;
25405 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
25406 doc
: /* *Control highlighting of nobreak space and soft hyphen.
25407 A value of t means highlight the character itself (for nobreak space,
25408 use face `nobreak-space').
25409 A value of nil means no highlighting.
25410 Other values mean display the escape glyph followed by an ordinary
25411 space or ordinary hyphen. */);
25412 Vnobreak_char_display
= Qt
;
25414 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
25415 doc
: /* *The pointer shape to show in void text areas.
25416 A value of nil means to show the text pointer. Other options are `arrow',
25417 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
25418 Vvoid_text_area_pointer
= Qarrow
;
25420 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
25421 doc
: /* Non-nil means don't actually do any redisplay.
25422 This is used for internal purposes. */);
25423 Vinhibit_redisplay
= Qnil
;
25425 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
25426 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
25427 Vglobal_mode_string
= Qnil
;
25429 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
25430 doc
: /* Marker for where to display an arrow on top of the buffer text.
25431 This must be the beginning of a line in order to work.
25432 See also `overlay-arrow-string'. */);
25433 Voverlay_arrow_position
= Qnil
;
25435 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
25436 doc
: /* String to display as an arrow in non-window frames.
25437 See also `overlay-arrow-position'. */);
25438 Voverlay_arrow_string
= make_pure_c_string ("=>");
25440 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
25441 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
25442 The symbols on this list are examined during redisplay to determine
25443 where to display overlay arrows. */);
25444 Voverlay_arrow_variable_list
25445 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
25447 DEFVAR_INT ("scroll-step", &scroll_step
,
25448 doc
: /* *The number of lines to try scrolling a window by when point moves out.
25449 If that fails to bring point back on frame, point is centered instead.
25450 If this is zero, point is always centered after it moves off frame.
25451 If you want scrolling to always be a line at a time, you should set
25452 `scroll-conservatively' to a large value rather than set this to 1. */);
25454 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
25455 doc
: /* *Scroll up to this many lines, to bring point back on screen.
25456 If point moves off-screen, redisplay will scroll by up to
25457 `scroll-conservatively' lines in order to bring point just barely
25458 onto the screen again. If that cannot be done, then redisplay
25459 recenters point as usual.
25461 A value of zero means always recenter point if it moves off screen. */);
25462 scroll_conservatively
= 0;
25464 DEFVAR_INT ("scroll-margin", &scroll_margin
,
25465 doc
: /* *Number of lines of margin at the top and bottom of a window.
25466 Recenter the window whenever point gets within this many lines
25467 of the top or bottom of the window. */);
25470 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
25471 doc
: /* Pixels per inch value for non-window system displays.
25472 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
25473 Vdisplay_pixels_per_inch
= make_float (72.0);
25476 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
25479 DEFVAR_LISP ("truncate-partial-width-windows",
25480 &Vtruncate_partial_width_windows
,
25481 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
25482 For an integer value, truncate lines in each window narrower than the
25483 full frame width, provided the window width is less than that integer;
25484 otherwise, respect the value of `truncate-lines'.
25486 For any other non-nil value, truncate lines in all windows that do
25487 not span the full frame width.
25489 A value of nil means to respect the value of `truncate-lines'.
25491 If `word-wrap' is enabled, you might want to reduce this. */);
25492 Vtruncate_partial_width_windows
= make_number (50);
25494 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
25495 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
25496 Any other value means to use the appropriate face, `mode-line',
25497 `header-line', or `menu' respectively. */);
25498 mode_line_inverse_video
= 1;
25500 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
25501 doc
: /* *Maximum buffer size for which line number should be displayed.
25502 If the buffer is bigger than this, the line number does not appear
25503 in the mode line. A value of nil means no limit. */);
25504 Vline_number_display_limit
= Qnil
;
25506 DEFVAR_INT ("line-number-display-limit-width",
25507 &line_number_display_limit_width
,
25508 doc
: /* *Maximum line width (in characters) for line number display.
25509 If the average length of the lines near point is bigger than this, then the
25510 line number may be omitted from the mode line. */);
25511 line_number_display_limit_width
= 200;
25513 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
25514 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
25515 highlight_nonselected_windows
= 0;
25517 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
25518 doc
: /* Non-nil if more than one frame is visible on this display.
25519 Minibuffer-only frames don't count, but iconified frames do.
25520 This variable is not guaranteed to be accurate except while processing
25521 `frame-title-format' and `icon-title-format'. */);
25523 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
25524 doc
: /* Template for displaying the title bar of visible frames.
25525 \(Assuming the window manager supports this feature.)
25527 This variable has the same structure as `mode-line-format', except that
25528 the %c and %l constructs are ignored. It is used only on frames for
25529 which no explicit name has been set \(see `modify-frame-parameters'). */);
25531 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
25532 doc
: /* Template for displaying the title bar of an iconified frame.
25533 \(Assuming the window manager supports this feature.)
25534 This variable has the same structure as `mode-line-format' (which see),
25535 and is used only on frames for which no explicit name has been set
25536 \(see `modify-frame-parameters'). */);
25538 = Vframe_title_format
25539 = pure_cons (intern_c_string ("multiple-frames"),
25540 pure_cons (make_pure_c_string ("%b"),
25541 pure_cons (pure_cons (empty_unibyte_string
,
25542 pure_cons (intern_c_string ("invocation-name"),
25543 pure_cons (make_pure_c_string ("@"),
25544 pure_cons (intern_c_string ("system-name"),
25548 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
25549 doc
: /* Maximum number of lines to keep in the message log buffer.
25550 If nil, disable message logging. If t, log messages but don't truncate
25551 the buffer when it becomes large. */);
25552 Vmessage_log_max
= make_number (100);
25554 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
25555 doc
: /* Functions called before redisplay, if window sizes have changed.
25556 The value should be a list of functions that take one argument.
25557 Just before redisplay, for each frame, if any of its windows have changed
25558 size since the last redisplay, or have been split or deleted,
25559 all the functions in the list are called, with the frame as argument. */);
25560 Vwindow_size_change_functions
= Qnil
;
25562 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
25563 doc
: /* List of functions to call before redisplaying a window with scrolling.
25564 Each function is called with two arguments, the window and its new
25565 display-start position. Note that these functions are also called by
25566 `set-window-buffer'. Also note that the value of `window-end' is not
25567 valid when these functions are called. */);
25568 Vwindow_scroll_functions
= Qnil
;
25570 DEFVAR_LISP ("window-text-change-functions",
25571 &Vwindow_text_change_functions
,
25572 doc
: /* Functions to call in redisplay when text in the window might change. */);
25573 Vwindow_text_change_functions
= Qnil
;
25575 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
25576 doc
: /* Functions called when redisplay of a window reaches the end trigger.
25577 Each function is called with two arguments, the window and the end trigger value.
25578 See `set-window-redisplay-end-trigger'. */);
25579 Vredisplay_end_trigger_functions
= Qnil
;
25581 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25582 doc
: /* *Non-nil means autoselect window with mouse pointer.
25583 If nil, do not autoselect windows.
25584 A positive number means delay autoselection by that many seconds: a
25585 window is autoselected only after the mouse has remained in that
25586 window for the duration of the delay.
25587 A negative number has a similar effect, but causes windows to be
25588 autoselected only after the mouse has stopped moving. \(Because of
25589 the way Emacs compares mouse events, you will occasionally wait twice
25590 that time before the window gets selected.\)
25591 Any other value means to autoselect window instantaneously when the
25592 mouse pointer enters it.
25594 Autoselection selects the minibuffer only if it is active, and never
25595 unselects the minibuffer if it is active.
25597 When customizing this variable make sure that the actual value of
25598 `focus-follows-mouse' matches the behavior of your window manager. */);
25599 Vmouse_autoselect_window
= Qnil
;
25601 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25602 doc
: /* *Non-nil means automatically resize tool-bars.
25603 This dynamically changes the tool-bar's height to the minimum height
25604 that is needed to make all tool-bar items visible.
25605 If value is `grow-only', the tool-bar's height is only increased
25606 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25607 Vauto_resize_tool_bars
= Qt
;
25609 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25610 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25611 auto_raise_tool_bar_buttons_p
= 1;
25613 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25614 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25615 make_cursor_line_fully_visible_p
= 1;
25617 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25618 doc
: /* *Border below tool-bar in pixels.
25619 If an integer, use it as the height of the border.
25620 If it is one of `internal-border-width' or `border-width', use the
25621 value of the corresponding frame parameter.
25622 Otherwise, no border is added below the tool-bar. */);
25623 Vtool_bar_border
= Qinternal_border_width
;
25625 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25626 doc
: /* *Margin around tool-bar buttons in pixels.
25627 If an integer, use that for both horizontal and vertical margins.
25628 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25629 HORZ specifying the horizontal margin, and VERT specifying the
25630 vertical margin. */);
25631 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25633 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25634 doc
: /* *Relief thickness of tool-bar buttons. */);
25635 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25637 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25638 doc
: /* List of functions to call to fontify regions of text.
25639 Each function is called with one argument POS. Functions must
25640 fontify a region starting at POS in the current buffer, and give
25641 fontified regions the property `fontified'. */);
25642 Vfontification_functions
= Qnil
;
25643 Fmake_variable_buffer_local (Qfontification_functions
);
25645 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25646 &unibyte_display_via_language_environment
,
25647 doc
: /* *Non-nil means display unibyte text according to language environment.
25648 Specifically, this means that raw bytes in the range 160-255 decimal
25649 are displayed by converting them to the equivalent multibyte characters
25650 according to the current language environment. As a result, they are
25651 displayed according to the current fontset.
25653 Note that this variable affects only how these bytes are displayed,
25654 but does not change the fact they are interpreted as raw bytes. */);
25655 unibyte_display_via_language_environment
= 0;
25657 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25658 doc
: /* *Maximum height for resizing mini-windows.
25659 If a float, it specifies a fraction of the mini-window frame's height.
25660 If an integer, it specifies a number of lines. */);
25661 Vmax_mini_window_height
= make_float (0.25);
25663 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25664 doc
: /* *How to resize mini-windows.
25665 A value of nil means don't automatically resize mini-windows.
25666 A value of t means resize them to fit the text displayed in them.
25667 A value of `grow-only', the default, means let mini-windows grow
25668 only, until their display becomes empty, at which point the windows
25669 go back to their normal size. */);
25670 Vresize_mini_windows
= Qgrow_only
;
25672 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25673 doc
: /* Alist specifying how to blink the cursor off.
25674 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25675 `cursor-type' frame-parameter or variable equals ON-STATE,
25676 comparing using `equal', Emacs uses OFF-STATE to specify
25677 how to blink it off. ON-STATE and OFF-STATE are values for
25678 the `cursor-type' frame parameter.
25680 If a frame's ON-STATE has no entry in this list,
25681 the frame's other specifications determine how to blink the cursor off. */);
25682 Vblink_cursor_alist
= Qnil
;
25684 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25685 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25686 automatic_hscrolling_p
= 1;
25687 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
25688 staticpro (&Qauto_hscroll_mode
);
25690 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25691 doc
: /* *How many columns away from the window edge point is allowed to get
25692 before automatic hscrolling will horizontally scroll the window. */);
25693 hscroll_margin
= 5;
25695 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25696 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25697 When point is less than `hscroll-margin' columns from the window
25698 edge, automatic hscrolling will scroll the window by the amount of columns
25699 determined by this variable. If its value is a positive integer, scroll that
25700 many columns. If it's a positive floating-point number, it specifies the
25701 fraction of the window's width to scroll. If it's nil or zero, point will be
25702 centered horizontally after the scroll. Any other value, including negative
25703 numbers, are treated as if the value were zero.
25705 Automatic hscrolling always moves point outside the scroll margin, so if
25706 point was more than scroll step columns inside the margin, the window will
25707 scroll more than the value given by the scroll step.
25709 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25710 and `scroll-right' overrides this variable's effect. */);
25711 Vhscroll_step
= make_number (0);
25713 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25714 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25715 Bind this around calls to `message' to let it take effect. */);
25716 message_truncate_lines
= 0;
25718 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25719 doc
: /* Normal hook run to update the menu bar definitions.
25720 Redisplay runs this hook before it redisplays the menu bar.
25721 This is used to update submenus such as Buffers,
25722 whose contents depend on various data. */);
25723 Vmenu_bar_update_hook
= Qnil
;
25725 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25726 doc
: /* Frame for which we are updating a menu.
25727 The enable predicate for a menu binding should check this variable. */);
25728 Vmenu_updating_frame
= Qnil
;
25730 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25731 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25732 inhibit_menubar_update
= 0;
25734 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25735 doc
: /* Prefix prepended to all continuation lines at display time.
25736 The value may be a string, an image, or a stretch-glyph; it is
25737 interpreted in the same way as the value of a `display' text property.
25739 This variable is overridden by any `wrap-prefix' text or overlay
25742 To add a prefix to non-continuation lines, use `line-prefix'. */);
25743 Vwrap_prefix
= Qnil
;
25744 staticpro (&Qwrap_prefix
);
25745 Qwrap_prefix
= intern_c_string ("wrap-prefix");
25746 Fmake_variable_buffer_local (Qwrap_prefix
);
25748 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25749 doc
: /* Prefix prepended to all non-continuation lines at display time.
25750 The value may be a string, an image, or a stretch-glyph; it is
25751 interpreted in the same way as the value of a `display' text property.
25753 This variable is overridden by any `line-prefix' text or overlay
25756 To add a prefix to continuation lines, use `wrap-prefix'. */);
25757 Vline_prefix
= Qnil
;
25758 staticpro (&Qline_prefix
);
25759 Qline_prefix
= intern_c_string ("line-prefix");
25760 Fmake_variable_buffer_local (Qline_prefix
);
25762 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25763 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25764 inhibit_eval_during_redisplay
= 0;
25766 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25767 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25768 inhibit_free_realized_faces
= 0;
25771 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25772 doc
: /* Inhibit try_window_id display optimization. */);
25773 inhibit_try_window_id
= 0;
25775 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25776 doc
: /* Inhibit try_window_reusing display optimization. */);
25777 inhibit_try_window_reusing
= 0;
25779 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25780 doc
: /* Inhibit try_cursor_movement display optimization. */);
25781 inhibit_try_cursor_movement
= 0;
25782 #endif /* GLYPH_DEBUG */
25784 DEFVAR_INT ("overline-margin", &overline_margin
,
25785 doc
: /* *Space between overline and text, in pixels.
25786 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25787 margin to the caracter height. */);
25788 overline_margin
= 2;
25790 DEFVAR_INT ("underline-minimum-offset",
25791 &underline_minimum_offset
,
25792 doc
: /* Minimum distance between baseline and underline.
25793 This can improve legibility of underlined text at small font sizes,
25794 particularly when using variable `x-use-underline-position-properties'
25795 with fonts that specify an UNDERLINE_POSITION relatively close to the
25796 baseline. The default value is 1. */);
25797 underline_minimum_offset
= 1;
25799 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25800 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25801 display_hourglass_p
= 1;
25803 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25804 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25805 Value must be an integer or float. */);
25806 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25808 hourglass_atimer
= NULL
;
25809 hourglass_shown_p
= 0;
25813 /* Initialize this module when Emacs starts. */
25818 Lisp_Object root_window
;
25819 struct window
*mini_w
;
25821 current_header_line_height
= current_mode_line_height
= -1;
25823 CHARPOS (this_line_start_pos
) = 0;
25825 mini_w
= XWINDOW (minibuf_window
);
25826 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25828 if (!noninteractive
)
25830 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25833 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25834 set_window_height (root_window
,
25835 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25837 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25838 set_window_height (minibuf_window
, 1, 0);
25840 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25841 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25843 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25844 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25845 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25847 /* The default ellipsis glyphs `...'. */
25848 for (i
= 0; i
< 3; ++i
)
25849 default_invis_vector
[i
] = make_number ('.');
25853 /* Allocate the buffer for frame titles.
25854 Also used for `format-mode-line'. */
25856 mode_line_noprop_buf
= (char *) xmalloc (size
);
25857 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25858 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25859 mode_line_target
= MODE_LINE_DISPLAY
;
25862 help_echo_showing_p
= 0;
25865 /* Since w32 does not support atimers, it defines its own implementation of
25866 the following three functions in w32fns.c. */
25869 /* Platform-independent portion of hourglass implementation. */
25871 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25873 hourglass_started ()
25875 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25878 /* Cancel a currently active hourglass timer, and start a new one. */
25882 #if defined (HAVE_WINDOW_SYSTEM)
25884 int secs
, usecs
= 0;
25886 cancel_hourglass ();
25888 if (INTEGERP (Vhourglass_delay
)
25889 && XINT (Vhourglass_delay
) > 0)
25890 secs
= XFASTINT (Vhourglass_delay
);
25891 else if (FLOATP (Vhourglass_delay
)
25892 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25895 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25896 secs
= XFASTINT (tem
);
25897 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25900 secs
= DEFAULT_HOURGLASS_DELAY
;
25902 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25903 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25904 show_hourglass
, NULL
);
25909 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25912 cancel_hourglass ()
25914 #if defined (HAVE_WINDOW_SYSTEM)
25915 if (hourglass_atimer
)
25917 cancel_atimer (hourglass_atimer
);
25918 hourglass_atimer
= NULL
;
25921 if (hourglass_shown_p
)
25925 #endif /* ! WINDOWSNT */
25927 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25928 (do not change this comment) */