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 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code. (Or,
35 let's say almost---see the description of direct update
38 The following diagram shows how redisplay code is invoked. As you
39 can see, Lisp calls redisplay and vice versa. Under window systems
40 like X, some portions of the redisplay code are also called
41 asynchronously during mouse movement or expose events. It is very
42 important that these code parts do NOT use the C library (malloc,
43 free) because many C libraries under Unix are not reentrant. They
44 may also NOT call functions of the Lisp interpreter which could
45 change the interpreter's state. If you don't follow these rules,
46 you will encounter bugs which are very hard to explain.
48 (Direct functions, see below)
49 direct_output_for_insert,
50 direct_forward_char (dispnew.c)
51 +---------------------------------+
54 +--------------+ redisplay +----------------+
55 | Lisp machine |---------------->| Redisplay code |<--+
56 +--------------+ (xdisp.c) +----------------+ |
58 +----------------------------------+ |
59 Don't use this path when called |
62 expose_window (asynchronous) |
64 X expose events -----+
66 What does redisplay do? Obviously, it has to figure out somehow what
67 has been changed since the last time the display has been updated,
68 and to make these changes visible. Preferably it would do that in
69 a moderately intelligent way, i.e. fast.
71 Changes in buffer text can be deduced from window and buffer
72 structures, and from some global variables like `beg_unchanged' and
73 `end_unchanged'. The contents of the display are additionally
74 recorded in a `glyph matrix', a two-dimensional matrix of glyph
75 structures. Each row in such a matrix corresponds to a line on the
76 display, and each glyph in a row corresponds to a column displaying
77 a character, an image, or what else. This matrix is called the
78 `current glyph matrix' or `current matrix' in redisplay
81 For buffer parts that have been changed since the last update, a
82 second glyph matrix is constructed, the so called `desired glyph
83 matrix' or short `desired matrix'. Current and desired matrix are
84 then compared to find a cheap way to update the display, e.g. by
85 reusing part of the display by scrolling lines.
90 You will find a lot of redisplay optimizations when you start
91 looking at the innards of redisplay. The overall goal of all these
92 optimizations is to make redisplay fast because it is done
95 Two optimizations are not found in xdisp.c. These are the direct
96 operations mentioned above. As the name suggests they follow a
97 different principle than the rest of redisplay. Instead of
98 building a desired matrix and then comparing it with the current
99 display, they perform their actions directly on the display and on
102 One direct operation updates the display after one character has
103 been entered. The other one moves the cursor by one position
104 forward or backward. You find these functions under the names
105 `direct_output_for_insert' and `direct_output_forward_char' in
111 Desired matrices are always built per Emacs window. The function
112 `display_line' is the central function to look at if you are
113 interested. It constructs one row in a desired matrix given an
114 iterator structure containing both a buffer position and a
115 description of the environment in which the text is to be
116 displayed. But this is too early, read on.
118 Characters and pixmaps displayed for a range of buffer text depend
119 on various settings of buffers and windows, on overlays and text
120 properties, on display tables, on selective display. The good news
121 is that all this hairy stuff is hidden behind a small set of
122 interface functions taking an iterator structure (struct it)
125 Iteration over things to be displayed is then simple. It is
126 started by initializing an iterator with a call to init_iterator.
127 Calls to get_next_display_element fill the iterator structure with
128 relevant information about the next thing to display. Calls to
129 set_iterator_to_next move the iterator to the next thing.
131 Besides this, an iterator also contains information about the
132 display environment in which glyphs for display elements are to be
133 produced. It has fields for the width and height of the display,
134 the information whether long lines are truncated or continued, a
135 current X and Y position, and lots of other stuff you can better
138 Glyphs in a desired matrix are normally constructed in a loop
139 calling get_next_display_element and then produce_glyphs. The call
140 to produce_glyphs will fill the iterator structure with pixel
141 information about the element being displayed and at the same time
142 produce glyphs for it. If the display element fits on the line
143 being displayed, set_iterator_to_next is called next, otherwise the
144 glyphs produced are discarded.
149 That just couldn't be all, could it? What about terminal types not
150 supporting operations on sub-windows of the screen? To update the
151 display on such a terminal, window-based glyph matrices are not
152 well suited. To be able to reuse part of the display (scrolling
153 lines up and down), we must instead have a view of the whole
154 screen. This is what `frame matrices' are for. They are a trick.
156 Frames on terminals like above have a glyph pool. Windows on such
157 a frame sub-allocate their glyph memory from their frame's glyph
158 pool. The frame itself is given its own glyph matrices. By
159 coincidence---or maybe something else---rows in window glyph
160 matrices are slices of corresponding rows in frame matrices. Thus
161 writing to window matrices implicitly updates a frame matrix which
162 provides us with the view of the whole screen that we originally
163 wanted to have without having to move many bytes around. To be
164 honest, there is a little bit more done, but not much more. If you
165 plan to extend that code, take a look at dispnew.c. The function
166 build_frame_matrix is a good starting point. */
174 #include "keyboard.h"
177 #include "termchar.h"
178 #include "dispextern.h"
180 #include "character.h"
183 #include "commands.h"
187 #include "termhooks.h"
188 #include "intervals.h"
191 #include "region-cache.h"
194 #include "blockinput.h"
196 #ifdef HAVE_X_WINDOWS
211 #ifndef FRAME_X_OUTPUT
212 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
215 #define INFINITY 10000000
217 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
218 || defined(HAVE_NS) || defined (USE_GTK)
219 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
220 extern int pending_menu_activation
;
223 extern int interrupt_input
;
224 extern int command_loop_level
;
226 extern Lisp_Object do_mouse_tracking
;
228 extern int minibuffer_auto_raise
;
229 extern Lisp_Object Vminibuffer_list
;
231 extern Lisp_Object Qface
;
232 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
234 extern Lisp_Object Voverriding_local_map
;
235 extern Lisp_Object Voverriding_local_map_menu_flag
;
236 extern Lisp_Object Qmenu_item
;
237 extern Lisp_Object Qwhen
;
238 extern Lisp_Object Qhelp_echo
;
239 extern Lisp_Object Qbefore_string
, Qafter_string
;
241 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
242 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
243 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
244 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
245 Lisp_Object Qinhibit_point_motion_hooks
;
246 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
247 Lisp_Object Qfontified
;
248 Lisp_Object Qgrow_only
;
249 Lisp_Object Qinhibit_eval_during_redisplay
;
250 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
253 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
256 Lisp_Object Qarrow
, Qhand
, Qtext
;
258 Lisp_Object Qrisky_local_variable
;
260 /* Holds the list (error). */
261 Lisp_Object list_of_error
;
263 /* Functions called to fontify regions of text. */
265 Lisp_Object Vfontification_functions
;
266 Lisp_Object Qfontification_functions
;
268 /* Non-nil means automatically select any window when the mouse
269 cursor moves into it. */
270 Lisp_Object Vmouse_autoselect_window
;
272 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
273 Lisp_Object Vline_prefix
, Qline_prefix
;
275 /* Non-zero means draw tool bar buttons raised when the mouse moves
278 int auto_raise_tool_bar_buttons_p
;
280 /* Non-zero means to reposition window if cursor line is only partially visible. */
282 int make_cursor_line_fully_visible_p
;
284 /* Margin below tool bar in pixels. 0 or nil means no margin.
285 If value is `internal-border-width' or `border-width',
286 the corresponding frame parameter is used. */
288 Lisp_Object Vtool_bar_border
;
290 /* Margin around tool bar buttons in pixels. */
292 Lisp_Object Vtool_bar_button_margin
;
294 /* Thickness of shadow to draw around tool bar buttons. */
296 EMACS_INT tool_bar_button_relief
;
298 /* Non-nil means automatically resize tool-bars so that all tool-bar
299 items are visible, and no blank lines remain.
301 If value is `grow-only', only make tool-bar bigger. */
303 Lisp_Object Vauto_resize_tool_bars
;
305 /* Non-zero means draw block and hollow cursor as wide as the glyph
306 under it. For example, if a block cursor is over a tab, it will be
307 drawn as wide as that tab on the display. */
309 int x_stretch_cursor_p
;
311 /* Non-nil means don't actually do any redisplay. */
313 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
315 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
317 int inhibit_eval_during_redisplay
;
319 /* Names of text properties relevant for redisplay. */
321 Lisp_Object Qdisplay
;
322 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
324 /* Symbols used in text property values. */
326 Lisp_Object Vdisplay_pixels_per_inch
;
327 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
328 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
331 Lisp_Object Qmargin
, Qpointer
;
332 Lisp_Object Qline_height
;
333 extern Lisp_Object Qheight
;
334 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
335 extern Lisp_Object Qscroll_bar
;
336 extern Lisp_Object Qcursor
;
338 /* Non-nil means highlight trailing whitespace. */
340 Lisp_Object Vshow_trailing_whitespace
;
342 /* Non-nil means escape non-break space and hyphens. */
344 Lisp_Object Vnobreak_char_display
;
346 #ifdef HAVE_WINDOW_SYSTEM
347 extern Lisp_Object Voverflow_newline_into_fringe
;
349 /* Test if overflow newline into fringe. Called with iterator IT
350 at or past right window margin, and with IT->current_x set. */
352 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
353 (!NILP (Voverflow_newline_into_fringe) \
354 && FRAME_WINDOW_P (it->f) \
355 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
356 && it->current_x == it->last_visible_x \
357 && it->line_wrap != WORD_WRAP)
359 #else /* !HAVE_WINDOW_SYSTEM */
360 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
361 #endif /* HAVE_WINDOW_SYSTEM */
363 /* Test if the display element loaded in IT is a space or tab
364 character. This is used to determine word wrapping. */
366 #define IT_DISPLAYING_WHITESPACE(it) \
367 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
369 /* Non-nil means show the text cursor in void text areas
370 i.e. in blank areas after eol and eob. This used to be
371 the default in 21.3. */
373 Lisp_Object Vvoid_text_area_pointer
;
375 /* Name of the face used to highlight trailing whitespace. */
377 Lisp_Object Qtrailing_whitespace
;
379 /* Name and number of the face used to highlight escape glyphs. */
381 Lisp_Object Qescape_glyph
;
383 /* Name and number of the face used to highlight non-breaking spaces. */
385 Lisp_Object Qnobreak_space
;
387 /* The symbol `image' which is the car of the lists used to represent
392 /* The image map types. */
393 Lisp_Object QCmap
, QCpointer
;
394 Lisp_Object Qrect
, Qcircle
, Qpoly
;
396 /* Non-zero means print newline to stdout before next mini-buffer
399 int noninteractive_need_newline
;
401 /* Non-zero means print newline to message log before next message. */
403 static int message_log_need_newline
;
405 /* Three markers that message_dolog uses.
406 It could allocate them itself, but that causes trouble
407 in handling memory-full errors. */
408 static Lisp_Object message_dolog_marker1
;
409 static Lisp_Object message_dolog_marker2
;
410 static Lisp_Object message_dolog_marker3
;
412 /* The buffer position of the first character appearing entirely or
413 partially on the line of the selected window which contains the
414 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
415 redisplay optimization in redisplay_internal. */
417 static struct text_pos this_line_start_pos
;
419 /* Number of characters past the end of the line above, including the
420 terminating newline. */
422 static struct text_pos this_line_end_pos
;
424 /* The vertical positions and the height of this line. */
426 static int this_line_vpos
;
427 static int this_line_y
;
428 static int this_line_pixel_height
;
430 /* X position at which this display line starts. Usually zero;
431 negative if first character is partially visible. */
433 static int this_line_start_x
;
435 /* Buffer that this_line_.* variables are referring to. */
437 static struct buffer
*this_line_buffer
;
439 /* Nonzero means truncate lines in all windows less wide than the
442 Lisp_Object Vtruncate_partial_width_windows
;
444 /* A flag to control how to display unibyte 8-bit character. */
446 int unibyte_display_via_language_environment
;
448 /* Nonzero means we have more than one non-mini-buffer-only frame.
449 Not guaranteed to be accurate except while parsing
450 frame-title-format. */
454 Lisp_Object Vglobal_mode_string
;
457 /* List of variables (symbols) which hold markers for overlay arrows.
458 The symbols on this list are examined during redisplay to determine
459 where to display overlay arrows. */
461 Lisp_Object Voverlay_arrow_variable_list
;
463 /* Marker for where to display an arrow on top of the buffer text. */
465 Lisp_Object Voverlay_arrow_position
;
467 /* String to display for the arrow. Only used on terminal frames. */
469 Lisp_Object Voverlay_arrow_string
;
471 /* Values of those variables at last redisplay are stored as
472 properties on `overlay-arrow-position' symbol. However, if
473 Voverlay_arrow_position is a marker, last-arrow-position is its
474 numerical position. */
476 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
478 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
479 properties on a symbol in overlay-arrow-variable-list. */
481 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
483 /* Like mode-line-format, but for the title bar on a visible frame. */
485 Lisp_Object Vframe_title_format
;
487 /* Like mode-line-format, but for the title bar on an iconified frame. */
489 Lisp_Object Vicon_title_format
;
491 /* List of functions to call when a window's size changes. These
492 functions get one arg, a frame on which one or more windows' sizes
495 static Lisp_Object Vwindow_size_change_functions
;
497 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
499 /* Nonzero if an overlay arrow has been displayed in this window. */
501 static int overlay_arrow_seen
;
503 /* Nonzero means highlight the region even in nonselected windows. */
505 int highlight_nonselected_windows
;
507 /* If cursor motion alone moves point off frame, try scrolling this
508 many lines up or down if that will bring it back. */
510 static EMACS_INT scroll_step
;
512 /* Nonzero means scroll just far enough to bring point back on the
513 screen, when appropriate. */
515 static EMACS_INT scroll_conservatively
;
517 /* Recenter the window whenever point gets within this many lines of
518 the top or bottom of the window. This value is translated into a
519 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
520 that there is really a fixed pixel height scroll margin. */
522 EMACS_INT scroll_margin
;
524 /* Number of windows showing the buffer of the selected window (or
525 another buffer with the same base buffer). keyboard.c refers to
530 /* Vector containing glyphs for an ellipsis `...'. */
532 static Lisp_Object default_invis_vector
[3];
534 /* Zero means display the mode-line/header-line/menu-bar in the default face
535 (this slightly odd definition is for compatibility with previous versions
536 of emacs), non-zero means display them using their respective faces.
538 This variable is deprecated. */
540 int mode_line_inverse_video
;
542 /* Prompt to display in front of the mini-buffer contents. */
544 Lisp_Object minibuf_prompt
;
546 /* Width of current mini-buffer prompt. Only set after display_line
547 of the line that contains the prompt. */
549 int minibuf_prompt_width
;
551 /* This is the window where the echo area message was displayed. It
552 is always a mini-buffer window, but it may not be the same window
553 currently active as a mini-buffer. */
555 Lisp_Object echo_area_window
;
557 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
558 pushes the current message and the value of
559 message_enable_multibyte on the stack, the function restore_message
560 pops the stack and displays MESSAGE again. */
562 Lisp_Object Vmessage_stack
;
564 /* Nonzero means multibyte characters were enabled when the echo area
565 message was specified. */
567 int message_enable_multibyte
;
569 /* Nonzero if we should redraw the mode lines on the next redisplay. */
571 int update_mode_lines
;
573 /* Nonzero if window sizes or contents have changed since last
574 redisplay that finished. */
576 int windows_or_buffers_changed
;
578 /* Nonzero means a frame's cursor type has been changed. */
580 int cursor_type_changed
;
582 /* Nonzero after display_mode_line if %l was used and it displayed a
585 int line_number_displayed
;
587 /* Maximum buffer size for which to display line numbers. */
589 Lisp_Object Vline_number_display_limit
;
591 /* Line width to consider when repositioning for line number display. */
593 static EMACS_INT line_number_display_limit_width
;
595 /* Number of lines to keep in the message log buffer. t means
596 infinite. nil means don't log at all. */
598 Lisp_Object Vmessage_log_max
;
600 /* The name of the *Messages* buffer, a string. */
602 static Lisp_Object Vmessages_buffer_name
;
604 /* Current, index 0, and last displayed echo area message. Either
605 buffers from echo_buffers, or nil to indicate no message. */
607 Lisp_Object echo_area_buffer
[2];
609 /* The buffers referenced from echo_area_buffer. */
611 static Lisp_Object echo_buffer
[2];
613 /* A vector saved used in with_area_buffer to reduce consing. */
615 static Lisp_Object Vwith_echo_area_save_vector
;
617 /* Non-zero means display_echo_area should display the last echo area
618 message again. Set by redisplay_preserve_echo_area. */
620 static int display_last_displayed_message_p
;
622 /* Nonzero if echo area is being used by print; zero if being used by
625 int message_buf_print
;
627 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
629 Lisp_Object Qinhibit_menubar_update
;
630 int inhibit_menubar_update
;
632 /* When evaluating expressions from menu bar items (enable conditions,
633 for instance), this is the frame they are being processed for. */
635 Lisp_Object Vmenu_updating_frame
;
637 /* Maximum height for resizing mini-windows. Either a float
638 specifying a fraction of the available height, or an integer
639 specifying a number of lines. */
641 Lisp_Object Vmax_mini_window_height
;
643 /* Non-zero means messages should be displayed with truncated
644 lines instead of being continued. */
646 int message_truncate_lines
;
647 Lisp_Object Qmessage_truncate_lines
;
649 /* Set to 1 in clear_message to make redisplay_internal aware
650 of an emptied echo area. */
652 static int message_cleared_p
;
654 /* How to blink the default frame cursor off. */
655 Lisp_Object Vblink_cursor_alist
;
657 /* A scratch glyph row with contents used for generating truncation
658 glyphs. Also used in direct_output_for_insert. */
660 #define MAX_SCRATCH_GLYPHS 100
661 struct glyph_row scratch_glyph_row
;
662 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
664 /* Ascent and height of the last line processed by move_it_to. */
666 static int last_max_ascent
, last_height
;
668 /* Non-zero if there's a help-echo in the echo area. */
670 int help_echo_showing_p
;
672 /* If >= 0, computed, exact values of mode-line and header-line height
673 to use in the macros CURRENT_MODE_LINE_HEIGHT and
674 CURRENT_HEADER_LINE_HEIGHT. */
676 int current_mode_line_height
, current_header_line_height
;
678 /* The maximum distance to look ahead for text properties. Values
679 that are too small let us call compute_char_face and similar
680 functions too often which is expensive. Values that are too large
681 let us call compute_char_face and alike too often because we
682 might not be interested in text properties that far away. */
684 #define TEXT_PROP_DISTANCE_LIMIT 100
688 /* Variables to turn off display optimizations from Lisp. */
690 int inhibit_try_window_id
, inhibit_try_window_reusing
;
691 int inhibit_try_cursor_movement
;
693 /* Non-zero means print traces of redisplay if compiled with
696 int trace_redisplay_p
;
698 #endif /* GLYPH_DEBUG */
700 #ifdef DEBUG_TRACE_MOVE
701 /* Non-zero means trace with TRACE_MOVE to stderr. */
704 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
706 #define TRACE_MOVE(x) (void) 0
709 /* Non-zero means automatically scroll windows horizontally to make
712 int automatic_hscrolling_p
;
713 Lisp_Object Qauto_hscroll_mode
;
715 /* How close to the margin can point get before the window is scrolled
717 EMACS_INT hscroll_margin
;
719 /* How much to scroll horizontally when point is inside the above margin. */
720 Lisp_Object Vhscroll_step
;
722 /* The variable `resize-mini-windows'. If nil, don't resize
723 mini-windows. If t, always resize them to fit the text they
724 display. If `grow-only', let mini-windows grow only until they
727 Lisp_Object Vresize_mini_windows
;
729 /* Buffer being redisplayed -- for redisplay_window_error. */
731 struct buffer
*displayed_buffer
;
733 /* Space between overline and text. */
735 EMACS_INT overline_margin
;
737 /* Require underline to be at least this many screen pixels below baseline
738 This to avoid underline "merging" with the base of letters at small
739 font sizes, particularly when x_use_underline_position_properties is on. */
741 EMACS_INT underline_minimum_offset
;
743 /* Value returned from text property handlers (see below). */
748 HANDLED_RECOMPUTE_PROPS
,
749 HANDLED_OVERLAY_STRING_CONSUMED
,
753 /* A description of text properties that redisplay is interested
758 /* The name of the property. */
761 /* A unique index for the property. */
764 /* A handler function called to set up iterator IT from the property
765 at IT's current position. Value is used to steer handle_stop. */
766 enum prop_handled (*handler
) P_ ((struct it
*it
));
769 static enum prop_handled handle_face_prop
P_ ((struct it
*));
770 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
771 static enum prop_handled handle_display_prop
P_ ((struct it
*));
772 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
773 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
774 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
776 /* Properties handled by iterators. */
778 static struct props it_props
[] =
780 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
781 /* Handle `face' before `display' because some sub-properties of
782 `display' need to know the face. */
783 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
784 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
785 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
786 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
790 /* Value is the position described by X. If X is a marker, value is
791 the marker_position of X. Otherwise, value is X. */
793 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
795 /* Enumeration returned by some move_it_.* functions internally. */
799 /* Not used. Undefined value. */
802 /* Move ended at the requested buffer position or ZV. */
803 MOVE_POS_MATCH_OR_ZV
,
805 /* Move ended at the requested X pixel position. */
808 /* Move within a line ended at the end of a line that must be
812 /* Move within a line ended at the end of a line that would
813 be displayed truncated. */
816 /* Move within a line ended at a line end. */
820 /* This counter is used to clear the face cache every once in a while
821 in redisplay_internal. It is incremented for each redisplay.
822 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
825 #define CLEAR_FACE_CACHE_COUNT 500
826 static int clear_face_cache_count
;
828 /* Similarly for the image cache. */
830 #ifdef HAVE_WINDOW_SYSTEM
831 #define CLEAR_IMAGE_CACHE_COUNT 101
832 static int clear_image_cache_count
;
835 /* Non-zero while redisplay_internal is in progress. */
839 /* Non-zero means don't free realized faces. Bound while freeing
840 realized faces is dangerous because glyph matrices might still
843 int inhibit_free_realized_faces
;
844 Lisp_Object Qinhibit_free_realized_faces
;
846 /* If a string, XTread_socket generates an event to display that string.
847 (The display is done in read_char.) */
849 Lisp_Object help_echo_string
;
850 Lisp_Object help_echo_window
;
851 Lisp_Object help_echo_object
;
854 /* Temporary variable for XTread_socket. */
856 Lisp_Object previous_help_echo_string
;
858 /* Null glyph slice */
860 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
862 /* Platform-independent portion of hourglass implementation. */
864 /* Non-zero means we're allowed to display a hourglass pointer. */
865 int display_hourglass_p
;
867 /* Non-zero means an hourglass cursor is currently shown. */
868 int hourglass_shown_p
;
870 /* If non-null, an asynchronous timer that, when it expires, displays
871 an hourglass cursor on all frames. */
872 struct atimer
*hourglass_atimer
;
874 /* Number of seconds to wait before displaying an hourglass cursor. */
875 Lisp_Object Vhourglass_delay
;
877 /* Default number of seconds to wait before displaying an hourglass
879 #define DEFAULT_HOURGLASS_DELAY 1
882 /* Function prototypes. */
884 static void setup_for_ellipsis
P_ ((struct it
*, int));
885 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
886 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
887 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
888 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
889 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
890 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
892 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
894 static void handle_line_prefix
P_ ((struct it
*));
896 static void pint2str
P_ ((char *, int, int));
897 static void pint2hrstr
P_ ((char *, int, int));
898 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
900 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
901 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
902 static void store_mode_line_noprop_char
P_ ((char));
903 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
904 static void x_consider_frame_title
P_ ((Lisp_Object
));
905 static void handle_stop
P_ ((struct it
*));
906 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
907 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
908 static void ensure_echo_area_buffers
P_ ((void));
909 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
910 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
911 static int with_echo_area_buffer
P_ ((struct window
*, int,
912 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
913 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
914 static void clear_garbaged_frames
P_ ((void));
915 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
916 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
918 static int display_echo_area
P_ ((struct window
*));
919 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
920 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
921 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
922 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
923 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
925 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
926 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
927 static void insert_left_trunc_glyphs
P_ ((struct it
*));
928 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
930 static void extend_face_to_end_of_line
P_ ((struct it
*));
931 static int append_space_for_newline
P_ ((struct it
*, int));
932 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
933 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
934 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
935 static int trailing_whitespace_p
P_ ((int));
936 static int message_log_check_duplicate
P_ ((int, int, int, int));
937 static void push_it
P_ ((struct it
*));
938 static void pop_it
P_ ((struct it
*));
939 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
940 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
941 static void redisplay_internal
P_ ((int));
942 static int echo_area_display
P_ ((int));
943 static void redisplay_windows
P_ ((Lisp_Object
));
944 static void redisplay_window
P_ ((Lisp_Object
, int));
945 static Lisp_Object
redisplay_window_error ();
946 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
947 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
948 static int update_menu_bar
P_ ((struct frame
*, int, int));
949 static int try_window_reusing_current_matrix
P_ ((struct window
*));
950 static int try_window_id
P_ ((struct window
*));
951 static int display_line
P_ ((struct it
*));
952 static int display_mode_lines
P_ ((struct window
*));
953 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
954 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
955 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
956 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
957 static void display_menu_bar
P_ ((struct window
*));
958 static int display_count_lines
P_ ((int, int, int, int, int *));
959 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
960 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
961 static void compute_line_metrics
P_ ((struct it
*));
962 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
963 static int get_overlay_strings
P_ ((struct it
*, int));
964 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
965 static void next_overlay_string
P_ ((struct it
*));
966 static void reseat
P_ ((struct it
*, struct text_pos
, int));
967 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
968 static void back_to_previous_visible_line_start
P_ ((struct it
*));
969 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
970 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
971 static int next_element_from_ellipsis
P_ ((struct it
*));
972 static int next_element_from_display_vector
P_ ((struct it
*));
973 static int next_element_from_string
P_ ((struct it
*));
974 static int next_element_from_c_string
P_ ((struct it
*));
975 static int next_element_from_buffer
P_ ((struct it
*));
976 static int next_element_from_composition
P_ ((struct it
*));
977 static int next_element_from_image
P_ ((struct it
*));
978 static int next_element_from_stretch
P_ ((struct it
*));
979 static void load_overlay_strings
P_ ((struct it
*, int));
980 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
981 struct display_pos
*));
982 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
983 Lisp_Object
, int, int, int, int));
984 static enum move_it_result
985 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
986 enum move_operation_enum
);
987 void move_it_vertically_backward
P_ ((struct it
*, int));
988 static void init_to_row_start
P_ ((struct it
*, struct window
*,
989 struct glyph_row
*));
990 static int init_to_row_end
P_ ((struct it
*, struct window
*,
991 struct glyph_row
*));
992 static void back_to_previous_line_start
P_ ((struct it
*));
993 static int forward_to_next_line_start
P_ ((struct it
*, int *));
994 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
996 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
997 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
998 static int number_of_chars
P_ ((unsigned char *, int));
999 static void compute_stop_pos
P_ ((struct it
*));
1000 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1002 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1003 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1004 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1005 Lisp_Object
, Lisp_Object
,
1006 struct text_pos
*, int));
1007 static int underlying_face_id
P_ ((struct it
*));
1008 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1011 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1012 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1014 #ifdef HAVE_WINDOW_SYSTEM
1016 static void update_tool_bar
P_ ((struct frame
*, int));
1017 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1018 static int redisplay_tool_bar
P_ ((struct frame
*));
1019 static void display_tool_bar_line
P_ ((struct it
*, int));
1020 static void notice_overwritten_cursor
P_ ((struct window
*,
1021 enum glyph_row_area
,
1022 int, int, int, int));
1026 #endif /* HAVE_WINDOW_SYSTEM */
1029 /***********************************************************************
1030 Window display dimensions
1031 ***********************************************************************/
1033 /* Return the bottom boundary y-position for text lines in window W.
1034 This is the first y position at which a line cannot start.
1035 It is relative to the top of the window.
1037 This is the height of W minus the height of a mode line, if any. */
1040 window_text_bottom_y (w
)
1043 int height
= WINDOW_TOTAL_HEIGHT (w
);
1045 if (WINDOW_WANTS_MODELINE_P (w
))
1046 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1050 /* Return the pixel width of display area AREA of window W. AREA < 0
1051 means return the total width of W, not including fringes to
1052 the left and right of the window. */
1055 window_box_width (w
, area
)
1059 int cols
= XFASTINT (w
->total_cols
);
1062 if (!w
->pseudo_window_p
)
1064 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1066 if (area
== TEXT_AREA
)
1068 if (INTEGERP (w
->left_margin_cols
))
1069 cols
-= XFASTINT (w
->left_margin_cols
);
1070 if (INTEGERP (w
->right_margin_cols
))
1071 cols
-= XFASTINT (w
->right_margin_cols
);
1072 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1074 else if (area
== LEFT_MARGIN_AREA
)
1076 cols
= (INTEGERP (w
->left_margin_cols
)
1077 ? XFASTINT (w
->left_margin_cols
) : 0);
1080 else if (area
== RIGHT_MARGIN_AREA
)
1082 cols
= (INTEGERP (w
->right_margin_cols
)
1083 ? XFASTINT (w
->right_margin_cols
) : 0);
1088 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1092 /* Return the pixel height of the display area of window W, not
1093 including mode lines of W, if any. */
1096 window_box_height (w
)
1099 struct frame
*f
= XFRAME (w
->frame
);
1100 int height
= WINDOW_TOTAL_HEIGHT (w
);
1102 xassert (height
>= 0);
1104 /* Note: the code below that determines the mode-line/header-line
1105 height is essentially the same as that contained in the macro
1106 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1107 the appropriate glyph row has its `mode_line_p' flag set,
1108 and if it doesn't, uses estimate_mode_line_height instead. */
1110 if (WINDOW_WANTS_MODELINE_P (w
))
1112 struct glyph_row
*ml_row
1113 = (w
->current_matrix
&& w
->current_matrix
->rows
1114 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1116 if (ml_row
&& ml_row
->mode_line_p
)
1117 height
-= ml_row
->height
;
1119 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1122 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1124 struct glyph_row
*hl_row
1125 = (w
->current_matrix
&& w
->current_matrix
->rows
1126 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1128 if (hl_row
&& hl_row
->mode_line_p
)
1129 height
-= hl_row
->height
;
1131 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1134 /* With a very small font and a mode-line that's taller than
1135 default, we might end up with a negative height. */
1136 return max (0, height
);
1139 /* Return the window-relative coordinate of the left edge of display
1140 area AREA of window W. AREA < 0 means return the left edge of the
1141 whole window, to the right of the left fringe of W. */
1144 window_box_left_offset (w
, area
)
1150 if (w
->pseudo_window_p
)
1153 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1155 if (area
== TEXT_AREA
)
1156 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1157 + window_box_width (w
, LEFT_MARGIN_AREA
));
1158 else if (area
== RIGHT_MARGIN_AREA
)
1159 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1160 + window_box_width (w
, LEFT_MARGIN_AREA
)
1161 + window_box_width (w
, TEXT_AREA
)
1162 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1164 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1165 else if (area
== LEFT_MARGIN_AREA
1166 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1167 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1173 /* Return the window-relative coordinate of the right edge of display
1174 area AREA of window W. AREA < 0 means return the left edge of the
1175 whole window, to the left of the right fringe of W. */
1178 window_box_right_offset (w
, area
)
1182 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1185 /* Return the frame-relative coordinate of the left edge of display
1186 area AREA of window W. AREA < 0 means return the left edge of the
1187 whole window, to the right of the left fringe of W. */
1190 window_box_left (w
, area
)
1194 struct frame
*f
= XFRAME (w
->frame
);
1197 if (w
->pseudo_window_p
)
1198 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1200 x
= (WINDOW_LEFT_EDGE_X (w
)
1201 + window_box_left_offset (w
, area
));
1207 /* Return the frame-relative coordinate of the right edge of display
1208 area AREA of window W. AREA < 0 means return the left edge of the
1209 whole window, to the left of the right fringe of W. */
1212 window_box_right (w
, area
)
1216 return window_box_left (w
, area
) + window_box_width (w
, area
);
1219 /* Get the bounding box of the display area AREA of window W, without
1220 mode lines, in frame-relative coordinates. AREA < 0 means the
1221 whole window, not including the left and right fringes of
1222 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1223 coordinates of the upper-left corner of the box. Return in
1224 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1227 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1230 int *box_x
, *box_y
, *box_width
, *box_height
;
1233 *box_width
= window_box_width (w
, area
);
1235 *box_height
= window_box_height (w
);
1237 *box_x
= window_box_left (w
, area
);
1240 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1241 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1242 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1247 /* Get the bounding box of the display area AREA of window W, without
1248 mode lines. AREA < 0 means the whole window, not including the
1249 left and right fringe of the window. Return in *TOP_LEFT_X
1250 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1251 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1252 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1256 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1257 bottom_right_x
, bottom_right_y
)
1260 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1262 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1264 *bottom_right_x
+= *top_left_x
;
1265 *bottom_right_y
+= *top_left_y
;
1270 /***********************************************************************
1272 ***********************************************************************/
1274 /* Return the bottom y-position of the line the iterator IT is in.
1275 This can modify IT's settings. */
1281 int line_height
= it
->max_ascent
+ it
->max_descent
;
1282 int line_top_y
= it
->current_y
;
1284 if (line_height
== 0)
1287 line_height
= last_height
;
1288 else if (IT_CHARPOS (*it
) < ZV
)
1290 move_it_by_lines (it
, 1, 1);
1291 line_height
= (it
->max_ascent
|| it
->max_descent
1292 ? it
->max_ascent
+ it
->max_descent
1297 struct glyph_row
*row
= it
->glyph_row
;
1299 /* Use the default character height. */
1300 it
->glyph_row
= NULL
;
1301 it
->what
= IT_CHARACTER
;
1304 PRODUCE_GLYPHS (it
);
1305 line_height
= it
->ascent
+ it
->descent
;
1306 it
->glyph_row
= row
;
1310 return line_top_y
+ line_height
;
1314 /* Return 1 if position CHARPOS is visible in window W.
1315 CHARPOS < 0 means return info about WINDOW_END position.
1316 If visible, set *X and *Y to pixel coordinates of top left corner.
1317 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1318 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1321 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1323 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1326 struct text_pos top
;
1328 struct buffer
*old_buffer
= NULL
;
1330 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1333 if (XBUFFER (w
->buffer
) != current_buffer
)
1335 old_buffer
= current_buffer
;
1336 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1339 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1341 /* Compute exact mode line heights. */
1342 if (WINDOW_WANTS_MODELINE_P (w
))
1343 current_mode_line_height
1344 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1345 current_buffer
->mode_line_format
);
1347 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1348 current_header_line_height
1349 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1350 current_buffer
->header_line_format
);
1352 start_display (&it
, w
, top
);
1353 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1354 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1356 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1358 /* We have reached CHARPOS, or passed it. How the call to
1359 move_it_to can overshoot: (i) If CHARPOS is on invisible
1360 text, move_it_to stops at the end of the invisible text,
1361 after CHARPOS. (ii) If CHARPOS is in a display vector,
1362 move_it_to stops on its last glyph. */
1363 int top_x
= it
.current_x
;
1364 int top_y
= it
.current_y
;
1365 enum it_method it_method
= it
.method
;
1366 /* Calling line_bottom_y may change it.method. */
1367 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1368 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1370 if (top_y
< window_top_y
)
1371 visible_p
= bottom_y
> window_top_y
;
1372 else if (top_y
< it
.last_visible_y
)
1376 if (it_method
== GET_FROM_BUFFER
)
1378 Lisp_Object window
, prop
;
1380 XSETWINDOW (window
, w
);
1381 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1382 Qinvisible
, window
);
1384 /* If charpos coincides with invisible text covered with an
1385 ellipsis, use the first glyph of the ellipsis to compute
1386 the pixel positions. */
1387 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1389 struct glyph_row
*row
= it
.glyph_row
;
1390 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1391 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1395 && (!BUFFERP (glyph
->object
)
1396 || glyph
->charpos
< charpos
);
1398 x
+= glyph
->pixel_width
;
1402 else if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1404 /* We stopped on the last glyph of a display vector.
1405 Try and recompute. Hack alert! */
1406 if (charpos
< 2 || top
.charpos
>= charpos
)
1407 top_x
= it
.glyph_row
->x
;
1411 start_display (&it2
, w
, top
);
1412 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1413 get_next_display_element (&it2
);
1414 PRODUCE_GLYPHS (&it2
);
1415 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1416 || it2
.current_x
> it2
.last_visible_x
)
1417 top_x
= it
.glyph_row
->x
;
1420 top_x
= it2
.current_x
;
1421 top_y
= it2
.current_y
;
1427 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1428 *rtop
= max (0, window_top_y
- top_y
);
1429 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1430 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1431 - max (top_y
, window_top_y
)));
1440 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1441 move_it_by_lines (&it
, 1, 0);
1442 if (charpos
< IT_CHARPOS (it
)
1443 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1446 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1448 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1449 *rtop
= max (0, -it2
.current_y
);
1450 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1451 - it
.last_visible_y
));
1452 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1454 - max (it2
.current_y
,
1455 WINDOW_HEADER_LINE_HEIGHT (w
))));
1461 set_buffer_internal_1 (old_buffer
);
1463 current_header_line_height
= current_mode_line_height
= -1;
1465 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1466 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1469 /* Debugging code. */
1471 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1472 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1474 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1481 /* Return the next character from STR which is MAXLEN bytes long.
1482 Return in *LEN the length of the character. This is like
1483 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1484 we find one, we return a `?', but with the length of the invalid
1488 string_char_and_length (str
, maxlen
, len
)
1489 const unsigned char *str
;
1494 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1495 if (!CHAR_VALID_P (c
, 1))
1496 /* We may not change the length here because other places in Emacs
1497 don't use this function, i.e. they silently accept invalid
1506 /* Given a position POS containing a valid character and byte position
1507 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1509 static struct text_pos
1510 string_pos_nchars_ahead (pos
, string
, nchars
)
1511 struct text_pos pos
;
1515 xassert (STRINGP (string
) && nchars
>= 0);
1517 if (STRING_MULTIBYTE (string
))
1519 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1520 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1525 string_char_and_length (p
, rest
, &len
);
1526 p
+= len
, rest
-= len
;
1527 xassert (rest
>= 0);
1529 BYTEPOS (pos
) += len
;
1533 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1539 /* Value is the text position, i.e. character and byte position,
1540 for character position CHARPOS in STRING. */
1542 static INLINE
struct text_pos
1543 string_pos (charpos
, string
)
1547 struct text_pos pos
;
1548 xassert (STRINGP (string
));
1549 xassert (charpos
>= 0);
1550 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1555 /* Value is a text position, i.e. character and byte position, for
1556 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1557 means recognize multibyte characters. */
1559 static struct text_pos
1560 c_string_pos (charpos
, s
, multibyte_p
)
1565 struct text_pos pos
;
1567 xassert (s
!= NULL
);
1568 xassert (charpos
>= 0);
1572 int rest
= strlen (s
), len
;
1574 SET_TEXT_POS (pos
, 0, 0);
1577 string_char_and_length (s
, rest
, &len
);
1578 s
+= len
, rest
-= len
;
1579 xassert (rest
>= 0);
1581 BYTEPOS (pos
) += len
;
1585 SET_TEXT_POS (pos
, charpos
, charpos
);
1591 /* Value is the number of characters in C string S. MULTIBYTE_P
1592 non-zero means recognize multibyte characters. */
1595 number_of_chars (s
, multibyte_p
)
1603 int rest
= strlen (s
), len
;
1604 unsigned char *p
= (unsigned char *) s
;
1606 for (nchars
= 0; rest
> 0; ++nchars
)
1608 string_char_and_length (p
, rest
, &len
);
1609 rest
-= len
, p
+= len
;
1613 nchars
= strlen (s
);
1619 /* Compute byte position NEWPOS->bytepos corresponding to
1620 NEWPOS->charpos. POS is a known position in string STRING.
1621 NEWPOS->charpos must be >= POS.charpos. */
1624 compute_string_pos (newpos
, pos
, string
)
1625 struct text_pos
*newpos
, pos
;
1628 xassert (STRINGP (string
));
1629 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1631 if (STRING_MULTIBYTE (string
))
1632 *newpos
= string_pos_nchars_ahead (pos
, string
,
1633 CHARPOS (*newpos
) - CHARPOS (pos
));
1635 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1639 Return an estimation of the pixel height of mode or header lines on
1640 frame F. FACE_ID specifies what line's height to estimate. */
1643 estimate_mode_line_height (f
, face_id
)
1645 enum face_id face_id
;
1647 #ifdef HAVE_WINDOW_SYSTEM
1648 if (FRAME_WINDOW_P (f
))
1650 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1652 /* This function is called so early when Emacs starts that the face
1653 cache and mode line face are not yet initialized. */
1654 if (FRAME_FACE_CACHE (f
))
1656 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1660 height
= FONT_HEIGHT (face
->font
);
1661 if (face
->box_line_width
> 0)
1662 height
+= 2 * face
->box_line_width
;
1673 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1674 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1675 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1676 not force the value into range. */
1679 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1681 register int pix_x
, pix_y
;
1683 NativeRectangle
*bounds
;
1687 #ifdef HAVE_WINDOW_SYSTEM
1688 if (FRAME_WINDOW_P (f
))
1690 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1691 even for negative values. */
1693 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1695 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1697 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1698 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1701 STORE_NATIVE_RECT (*bounds
,
1702 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1703 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1704 FRAME_COLUMN_WIDTH (f
) - 1,
1705 FRAME_LINE_HEIGHT (f
) - 1);
1711 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1712 pix_x
= FRAME_TOTAL_COLS (f
);
1716 else if (pix_y
> FRAME_LINES (f
))
1717 pix_y
= FRAME_LINES (f
);
1727 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1728 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1729 can't tell the positions because W's display is not up to date,
1733 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1736 int *frame_x
, *frame_y
;
1738 #ifdef HAVE_WINDOW_SYSTEM
1739 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1743 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1744 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1746 if (display_completed
)
1748 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1749 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1750 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1756 hpos
+= glyph
->pixel_width
;
1760 /* If first glyph is partially visible, its first visible position is still 0. */
1772 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1773 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1784 #ifdef HAVE_WINDOW_SYSTEM
1786 /* Find the glyph under window-relative coordinates X/Y in window W.
1787 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1788 strings. Return in *HPOS and *VPOS the row and column number of
1789 the glyph found. Return in *AREA the glyph area containing X.
1790 Value is a pointer to the glyph found or null if X/Y is not on
1791 text, or we can't tell because W's current matrix is not up to
1796 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1799 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1801 struct glyph
*glyph
, *end
;
1802 struct glyph_row
*row
= NULL
;
1805 /* Find row containing Y. Give up if some row is not enabled. */
1806 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1808 row
= MATRIX_ROW (w
->current_matrix
, i
);
1809 if (!row
->enabled_p
)
1811 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1818 /* Give up if Y is not in the window. */
1819 if (i
== w
->current_matrix
->nrows
)
1822 /* Get the glyph area containing X. */
1823 if (w
->pseudo_window_p
)
1830 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1832 *area
= LEFT_MARGIN_AREA
;
1833 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1835 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1838 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1842 *area
= RIGHT_MARGIN_AREA
;
1843 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1847 /* Find glyph containing X. */
1848 glyph
= row
->glyphs
[*area
];
1849 end
= glyph
+ row
->used
[*area
];
1851 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1853 x
-= glyph
->pixel_width
;
1863 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1866 *hpos
= glyph
- row
->glyphs
[*area
];
1872 Convert frame-relative x/y to coordinates relative to window W.
1873 Takes pseudo-windows into account. */
1876 frame_to_window_pixel_xy (w
, x
, y
)
1880 if (w
->pseudo_window_p
)
1882 /* A pseudo-window is always full-width, and starts at the
1883 left edge of the frame, plus a frame border. */
1884 struct frame
*f
= XFRAME (w
->frame
);
1885 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1886 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1890 *x
-= WINDOW_LEFT_EDGE_X (w
);
1891 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1896 Return in RECTS[] at most N clipping rectangles for glyph string S.
1897 Return the number of stored rectangles. */
1900 get_glyph_string_clip_rects (s
, rects
, n
)
1901 struct glyph_string
*s
;
1902 NativeRectangle
*rects
;
1910 if (s
->row
->full_width_p
)
1912 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1913 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1914 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1916 /* Unless displaying a mode or menu bar line, which are always
1917 fully visible, clip to the visible part of the row. */
1918 if (s
->w
->pseudo_window_p
)
1919 r
.height
= s
->row
->visible_height
;
1921 r
.height
= s
->height
;
1925 /* This is a text line that may be partially visible. */
1926 r
.x
= window_box_left (s
->w
, s
->area
);
1927 r
.width
= window_box_width (s
->w
, s
->area
);
1928 r
.height
= s
->row
->visible_height
;
1932 if (r
.x
< s
->clip_head
->x
)
1934 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1935 r
.width
-= s
->clip_head
->x
- r
.x
;
1938 r
.x
= s
->clip_head
->x
;
1941 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1943 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1944 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1949 /* If S draws overlapping rows, it's sufficient to use the top and
1950 bottom of the window for clipping because this glyph string
1951 intentionally draws over other lines. */
1952 if (s
->for_overlaps
)
1954 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1955 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1957 /* Alas, the above simple strategy does not work for the
1958 environments with anti-aliased text: if the same text is
1959 drawn onto the same place multiple times, it gets thicker.
1960 If the overlap we are processing is for the erased cursor, we
1961 take the intersection with the rectagle of the cursor. */
1962 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1964 XRectangle rc
, r_save
= r
;
1966 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1967 rc
.y
= s
->w
->phys_cursor
.y
;
1968 rc
.width
= s
->w
->phys_cursor_width
;
1969 rc
.height
= s
->w
->phys_cursor_height
;
1971 x_intersect_rectangles (&r_save
, &rc
, &r
);
1976 /* Don't use S->y for clipping because it doesn't take partially
1977 visible lines into account. For example, it can be negative for
1978 partially visible lines at the top of a window. */
1979 if (!s
->row
->full_width_p
1980 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1981 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1983 r
.y
= max (0, s
->row
->y
);
1985 /* If drawing a tool-bar window, draw it over the internal border
1986 at the top of the window. */
1987 if (WINDOWP (s
->f
->tool_bar_window
)
1988 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1989 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1992 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1994 /* If drawing the cursor, don't let glyph draw outside its
1995 advertised boundaries. Cleartype does this under some circumstances. */
1996 if (s
->hl
== DRAW_CURSOR
)
1998 struct glyph
*glyph
= s
->first_glyph
;
2003 r
.width
-= s
->x
- r
.x
;
2006 r
.width
= min (r
.width
, glyph
->pixel_width
);
2008 /* If r.y is below window bottom, ensure that we still see a cursor. */
2009 height
= min (glyph
->ascent
+ glyph
->descent
,
2010 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2011 max_y
= window_text_bottom_y (s
->w
) - height
;
2012 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2013 if (s
->ybase
- glyph
->ascent
> max_y
)
2020 /* Don't draw cursor glyph taller than our actual glyph. */
2021 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2022 if (height
< r
.height
)
2024 max_y
= r
.y
+ r
.height
;
2025 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2026 r
.height
= min (max_y
- r
.y
, height
);
2033 XRectangle r_save
= r
;
2035 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2039 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2040 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2042 #ifdef CONVERT_FROM_XRECT
2043 CONVERT_FROM_XRECT (r
, *rects
);
2051 /* If we are processing overlapping and allowed to return
2052 multiple clipping rectangles, we exclude the row of the glyph
2053 string from the clipping rectangle. This is to avoid drawing
2054 the same text on the environment with anti-aliasing. */
2055 #ifdef CONVERT_FROM_XRECT
2058 XRectangle
*rs
= rects
;
2060 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2062 if (s
->for_overlaps
& OVERLAPS_PRED
)
2065 if (r
.y
+ r
.height
> row_y
)
2068 rs
[i
].height
= row_y
- r
.y
;
2074 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2077 if (r
.y
< row_y
+ s
->row
->visible_height
)
2079 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2081 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2082 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2091 #ifdef CONVERT_FROM_XRECT
2092 for (i
= 0; i
< n
; i
++)
2093 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2100 Return in *NR the clipping rectangle for glyph string S. */
2103 get_glyph_string_clip_rect (s
, nr
)
2104 struct glyph_string
*s
;
2105 NativeRectangle
*nr
;
2107 get_glyph_string_clip_rects (s
, nr
, 1);
2112 Return the position and height of the phys cursor in window W.
2113 Set w->phys_cursor_width to width of phys cursor.
2117 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2119 struct glyph_row
*row
;
2120 struct glyph
*glyph
;
2121 int *xp
, *yp
, *heightp
;
2123 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2124 int x
, y
, wd
, h
, h0
, y0
;
2126 /* Compute the width of the rectangle to draw. If on a stretch
2127 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2128 rectangle as wide as the glyph, but use a canonical character
2130 wd
= glyph
->pixel_width
- 1;
2131 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2135 x
= w
->phys_cursor
.x
;
2142 if (glyph
->type
== STRETCH_GLYPH
2143 && !x_stretch_cursor_p
)
2144 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2145 w
->phys_cursor_width
= wd
;
2147 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2149 /* If y is below window bottom, ensure that we still see a cursor. */
2150 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2152 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2153 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2155 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2158 h
= max (h
- (y0
- y
) + 1, h0
);
2163 y0
= window_text_bottom_y (w
) - h0
;
2171 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2172 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2177 * Remember which glyph the mouse is over.
2181 remember_mouse_glyph (f
, gx
, gy
, rect
)
2184 NativeRectangle
*rect
;
2188 struct glyph_row
*r
, *gr
, *end_row
;
2189 enum window_part part
;
2190 enum glyph_row_area area
;
2191 int x
, y
, width
, height
;
2193 /* Try to determine frame pixel position and size of the glyph under
2194 frame pixel coordinates X/Y on frame F. */
2196 if (!f
->glyphs_initialized_p
2197 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2200 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2201 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2205 w
= XWINDOW (window
);
2206 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2207 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2209 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2210 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2212 if (w
->pseudo_window_p
)
2215 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2221 case ON_LEFT_MARGIN
:
2222 area
= LEFT_MARGIN_AREA
;
2225 case ON_RIGHT_MARGIN
:
2226 area
= RIGHT_MARGIN_AREA
;
2229 case ON_HEADER_LINE
:
2231 gr
= (part
== ON_HEADER_LINE
2232 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2233 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2236 goto text_glyph_row_found
;
2243 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2244 if (r
->y
+ r
->height
> y
)
2250 text_glyph_row_found
:
2253 struct glyph
*g
= gr
->glyphs
[area
];
2254 struct glyph
*end
= g
+ gr
->used
[area
];
2256 height
= gr
->height
;
2257 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2258 if (gx
+ g
->pixel_width
> x
)
2263 if (g
->type
== IMAGE_GLYPH
)
2265 /* Don't remember when mouse is over image, as
2266 image may have hot-spots. */
2267 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2270 width
= g
->pixel_width
;
2274 /* Use nominal char spacing at end of line. */
2276 gx
+= (x
/ width
) * width
;
2279 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2280 gx
+= window_box_left_offset (w
, area
);
2284 /* Use nominal line height at end of window. */
2285 gx
= (x
/ width
) * width
;
2287 gy
+= (y
/ height
) * height
;
2291 case ON_LEFT_FRINGE
:
2292 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2293 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2294 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2295 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2298 case ON_RIGHT_FRINGE
:
2299 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2300 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2301 : window_box_right_offset (w
, TEXT_AREA
));
2302 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2306 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2308 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2309 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2310 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2312 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2316 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2317 if (r
->y
+ r
->height
> y
)
2324 height
= gr
->height
;
2327 /* Use nominal line height at end of window. */
2329 gy
+= (y
/ height
) * height
;
2336 /* If there is no glyph under the mouse, then we divide the screen
2337 into a grid of the smallest glyph in the frame, and use that
2340 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2341 round down even for negative values. */
2347 gx
= (gx
/ width
) * width
;
2348 gy
= (gy
/ height
) * height
;
2353 gx
+= WINDOW_LEFT_EDGE_X (w
);
2354 gy
+= WINDOW_TOP_EDGE_Y (w
);
2357 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2359 /* Visible feedback for debugging. */
2362 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2363 f
->output_data
.x
->normal_gc
,
2364 gx
, gy
, width
, height
);
2370 #endif /* HAVE_WINDOW_SYSTEM */
2373 /***********************************************************************
2374 Lisp form evaluation
2375 ***********************************************************************/
2377 /* Error handler for safe_eval and safe_call. */
2380 safe_eval_handler (arg
)
2383 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2388 /* Evaluate SEXPR and return the result, or nil if something went
2389 wrong. Prevent redisplay during the evaluation. */
2391 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2392 Return the result, or nil if something went wrong. Prevent
2393 redisplay during the evaluation. */
2396 safe_call (nargs
, args
)
2402 if (inhibit_eval_during_redisplay
)
2406 int count
= SPECPDL_INDEX ();
2407 struct gcpro gcpro1
;
2410 gcpro1
.nvars
= nargs
;
2411 specbind (Qinhibit_redisplay
, Qt
);
2412 /* Use Qt to ensure debugger does not run,
2413 so there is no possibility of wanting to redisplay. */
2414 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2417 val
= unbind_to (count
, val
);
2424 /* Call function FN with one argument ARG.
2425 Return the result, or nil if something went wrong. */
2428 safe_call1 (fn
, arg
)
2429 Lisp_Object fn
, arg
;
2431 Lisp_Object args
[2];
2434 return safe_call (2, args
);
2437 static Lisp_Object Qeval
;
2440 safe_eval (Lisp_Object sexpr
)
2442 return safe_call1 (Qeval
, sexpr
);
2445 /* Call function FN with one argument ARG.
2446 Return the result, or nil if something went wrong. */
2449 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2451 Lisp_Object args
[3];
2455 return safe_call (3, args
);
2460 /***********************************************************************
2462 ***********************************************************************/
2466 /* Define CHECK_IT to perform sanity checks on iterators.
2467 This is for debugging. It is too slow to do unconditionally. */
2473 if (it
->method
== GET_FROM_STRING
)
2475 xassert (STRINGP (it
->string
));
2476 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2480 xassert (IT_STRING_CHARPOS (*it
) < 0);
2481 if (it
->method
== GET_FROM_BUFFER
)
2483 /* Check that character and byte positions agree. */
2484 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2489 xassert (it
->current
.dpvec_index
>= 0);
2491 xassert (it
->current
.dpvec_index
< 0);
2494 #define CHECK_IT(IT) check_it ((IT))
2498 #define CHECK_IT(IT) (void) 0
2505 /* Check that the window end of window W is what we expect it
2506 to be---the last row in the current matrix displaying text. */
2509 check_window_end (w
)
2512 if (!MINI_WINDOW_P (w
)
2513 && !NILP (w
->window_end_valid
))
2515 struct glyph_row
*row
;
2516 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2517 XFASTINT (w
->window_end_vpos
)),
2519 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2520 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2524 #define CHECK_WINDOW_END(W) check_window_end ((W))
2526 #else /* not GLYPH_DEBUG */
2528 #define CHECK_WINDOW_END(W) (void) 0
2530 #endif /* not GLYPH_DEBUG */
2534 /***********************************************************************
2535 Iterator initialization
2536 ***********************************************************************/
2538 /* Initialize IT for displaying current_buffer in window W, starting
2539 at character position CHARPOS. CHARPOS < 0 means that no buffer
2540 position is specified which is useful when the iterator is assigned
2541 a position later. BYTEPOS is the byte position corresponding to
2542 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2544 If ROW is not null, calls to produce_glyphs with IT as parameter
2545 will produce glyphs in that row.
2547 BASE_FACE_ID is the id of a base face to use. It must be one of
2548 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2549 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2550 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2552 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2553 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2554 will be initialized to use the corresponding mode line glyph row of
2555 the desired matrix of W. */
2558 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2561 int charpos
, bytepos
;
2562 struct glyph_row
*row
;
2563 enum face_id base_face_id
;
2565 int highlight_region_p
;
2566 enum face_id remapped_base_face_id
= base_face_id
;
2568 /* Some precondition checks. */
2569 xassert (w
!= NULL
&& it
!= NULL
);
2570 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2573 /* If face attributes have been changed since the last redisplay,
2574 free realized faces now because they depend on face definitions
2575 that might have changed. Don't free faces while there might be
2576 desired matrices pending which reference these faces. */
2577 if (face_change_count
&& !inhibit_free_realized_faces
)
2579 face_change_count
= 0;
2580 free_all_realized_faces (Qnil
);
2583 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2584 if (! NILP (Vface_remapping_alist
))
2585 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2587 /* Use one of the mode line rows of W's desired matrix if
2591 if (base_face_id
== MODE_LINE_FACE_ID
2592 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2593 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2594 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2595 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2599 bzero (it
, sizeof *it
);
2600 it
->current
.overlay_string_index
= -1;
2601 it
->current
.dpvec_index
= -1;
2602 it
->base_face_id
= remapped_base_face_id
;
2604 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2606 /* The window in which we iterate over current_buffer: */
2607 XSETWINDOW (it
->window
, w
);
2609 it
->f
= XFRAME (w
->frame
);
2613 /* Extra space between lines (on window systems only). */
2614 if (base_face_id
== DEFAULT_FACE_ID
2615 && FRAME_WINDOW_P (it
->f
))
2617 if (NATNUMP (current_buffer
->extra_line_spacing
))
2618 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2619 else if (FLOATP (current_buffer
->extra_line_spacing
))
2620 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2621 * FRAME_LINE_HEIGHT (it
->f
));
2622 else if (it
->f
->extra_line_spacing
> 0)
2623 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2624 it
->max_extra_line_spacing
= 0;
2627 /* If realized faces have been removed, e.g. because of face
2628 attribute changes of named faces, recompute them. When running
2629 in batch mode, the face cache of the initial frame is null. If
2630 we happen to get called, make a dummy face cache. */
2631 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2632 init_frame_faces (it
->f
);
2633 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2634 recompute_basic_faces (it
->f
);
2636 /* Current value of the `slice', `space-width', and 'height' properties. */
2637 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2638 it
->space_width
= Qnil
;
2639 it
->font_height
= Qnil
;
2640 it
->override_ascent
= -1;
2642 /* Are control characters displayed as `^C'? */
2643 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2645 /* -1 means everything between a CR and the following line end
2646 is invisible. >0 means lines indented more than this value are
2648 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2649 ? XFASTINT (current_buffer
->selective_display
)
2650 : (!NILP (current_buffer
->selective_display
)
2652 it
->selective_display_ellipsis_p
2653 = !NILP (current_buffer
->selective_display_ellipses
);
2655 /* Display table to use. */
2656 it
->dp
= window_display_table (w
);
2658 /* Are multibyte characters enabled in current_buffer? */
2659 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2661 /* Non-zero if we should highlight the region. */
2663 = (!NILP (Vtransient_mark_mode
)
2664 && !NILP (current_buffer
->mark_active
)
2665 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2667 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2668 start and end of a visible region in window IT->w. Set both to
2669 -1 to indicate no region. */
2670 if (highlight_region_p
2671 /* Maybe highlight only in selected window. */
2672 && (/* Either show region everywhere. */
2673 highlight_nonselected_windows
2674 /* Or show region in the selected window. */
2675 || w
== XWINDOW (selected_window
)
2676 /* Or show the region if we are in the mini-buffer and W is
2677 the window the mini-buffer refers to. */
2678 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2679 && WINDOWP (minibuf_selected_window
)
2680 && w
== XWINDOW (minibuf_selected_window
))))
2682 int charpos
= marker_position (current_buffer
->mark
);
2683 it
->region_beg_charpos
= min (PT
, charpos
);
2684 it
->region_end_charpos
= max (PT
, charpos
);
2687 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2689 /* Get the position at which the redisplay_end_trigger hook should
2690 be run, if it is to be run at all. */
2691 if (MARKERP (w
->redisplay_end_trigger
)
2692 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2693 it
->redisplay_end_trigger_charpos
2694 = marker_position (w
->redisplay_end_trigger
);
2695 else if (INTEGERP (w
->redisplay_end_trigger
))
2696 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2698 /* Correct bogus values of tab_width. */
2699 it
->tab_width
= XINT (current_buffer
->tab_width
);
2700 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2703 /* Are lines in the display truncated? */
2704 if (base_face_id
!= DEFAULT_FACE_ID
2705 || XINT (it
->w
->hscroll
)
2706 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2707 && ((!NILP (Vtruncate_partial_width_windows
)
2708 && !INTEGERP (Vtruncate_partial_width_windows
))
2709 || (INTEGERP (Vtruncate_partial_width_windows
)
2710 && (WINDOW_TOTAL_COLS (it
->w
)
2711 < XINT (Vtruncate_partial_width_windows
))))))
2712 it
->line_wrap
= TRUNCATE
;
2713 else if (NILP (current_buffer
->truncate_lines
))
2714 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2715 ? WINDOW_WRAP
: WORD_WRAP
;
2717 it
->line_wrap
= TRUNCATE
;
2719 /* Get dimensions of truncation and continuation glyphs. These are
2720 displayed as fringe bitmaps under X, so we don't need them for such
2722 if (!FRAME_WINDOW_P (it
->f
))
2724 if (it
->line_wrap
== TRUNCATE
)
2726 /* We will need the truncation glyph. */
2727 xassert (it
->glyph_row
== NULL
);
2728 produce_special_glyphs (it
, IT_TRUNCATION
);
2729 it
->truncation_pixel_width
= it
->pixel_width
;
2733 /* We will need the continuation glyph. */
2734 xassert (it
->glyph_row
== NULL
);
2735 produce_special_glyphs (it
, IT_CONTINUATION
);
2736 it
->continuation_pixel_width
= it
->pixel_width
;
2739 /* Reset these values to zero because the produce_special_glyphs
2740 above has changed them. */
2741 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2742 it
->phys_ascent
= it
->phys_descent
= 0;
2745 /* Set this after getting the dimensions of truncation and
2746 continuation glyphs, so that we don't produce glyphs when calling
2747 produce_special_glyphs, above. */
2748 it
->glyph_row
= row
;
2749 it
->area
= TEXT_AREA
;
2751 /* Get the dimensions of the display area. The display area
2752 consists of the visible window area plus a horizontally scrolled
2753 part to the left of the window. All x-values are relative to the
2754 start of this total display area. */
2755 if (base_face_id
!= DEFAULT_FACE_ID
)
2757 /* Mode lines, menu bar in terminal frames. */
2758 it
->first_visible_x
= 0;
2759 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2764 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2765 it
->last_visible_x
= (it
->first_visible_x
2766 + window_box_width (w
, TEXT_AREA
));
2768 /* If we truncate lines, leave room for the truncator glyph(s) at
2769 the right margin. Otherwise, leave room for the continuation
2770 glyph(s). Truncation and continuation glyphs are not inserted
2771 for window-based redisplay. */
2772 if (!FRAME_WINDOW_P (it
->f
))
2774 if (it
->line_wrap
== TRUNCATE
)
2775 it
->last_visible_x
-= it
->truncation_pixel_width
;
2777 it
->last_visible_x
-= it
->continuation_pixel_width
;
2780 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2781 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2784 /* Leave room for a border glyph. */
2785 if (!FRAME_WINDOW_P (it
->f
)
2786 && !WINDOW_RIGHTMOST_P (it
->w
))
2787 it
->last_visible_x
-= 1;
2789 it
->last_visible_y
= window_text_bottom_y (w
);
2791 /* For mode lines and alike, arrange for the first glyph having a
2792 left box line if the face specifies a box. */
2793 if (base_face_id
!= DEFAULT_FACE_ID
)
2797 it
->face_id
= remapped_base_face_id
;
2799 /* If we have a boxed mode line, make the first character appear
2800 with a left box line. */
2801 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2802 if (face
->box
!= FACE_NO_BOX
)
2803 it
->start_of_box_run_p
= 1;
2806 /* If a buffer position was specified, set the iterator there,
2807 getting overlays and face properties from that position. */
2808 if (charpos
>= BUF_BEG (current_buffer
))
2810 it
->end_charpos
= ZV
;
2812 IT_CHARPOS (*it
) = charpos
;
2814 /* Compute byte position if not specified. */
2815 if (bytepos
< charpos
)
2816 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2818 IT_BYTEPOS (*it
) = bytepos
;
2820 it
->start
= it
->current
;
2822 /* Compute faces etc. */
2823 reseat (it
, it
->current
.pos
, 1);
2830 /* Initialize IT for the display of window W with window start POS. */
2833 start_display (it
, w
, pos
)
2836 struct text_pos pos
;
2838 struct glyph_row
*row
;
2839 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2841 row
= w
->desired_matrix
->rows
+ first_vpos
;
2842 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2843 it
->first_vpos
= first_vpos
;
2845 /* Don't reseat to previous visible line start if current start
2846 position is in a string or image. */
2847 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2849 int start_at_line_beg_p
;
2850 int first_y
= it
->current_y
;
2852 /* If window start is not at a line start, skip forward to POS to
2853 get the correct continuation lines width. */
2854 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2855 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2856 if (!start_at_line_beg_p
)
2860 reseat_at_previous_visible_line_start (it
);
2861 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2863 new_x
= it
->current_x
+ it
->pixel_width
;
2865 /* If lines are continued, this line may end in the middle
2866 of a multi-glyph character (e.g. a control character
2867 displayed as \003, or in the middle of an overlay
2868 string). In this case move_it_to above will not have
2869 taken us to the start of the continuation line but to the
2870 end of the continued line. */
2871 if (it
->current_x
> 0
2872 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2873 && (/* And glyph doesn't fit on the line. */
2874 new_x
> it
->last_visible_x
2875 /* Or it fits exactly and we're on a window
2877 || (new_x
== it
->last_visible_x
2878 && FRAME_WINDOW_P (it
->f
))))
2880 if (it
->current
.dpvec_index
>= 0
2881 || it
->current
.overlay_string_index
>= 0)
2883 set_iterator_to_next (it
, 1);
2884 move_it_in_display_line_to (it
, -1, -1, 0);
2887 it
->continuation_lines_width
+= it
->current_x
;
2890 /* We're starting a new display line, not affected by the
2891 height of the continued line, so clear the appropriate
2892 fields in the iterator structure. */
2893 it
->max_ascent
= it
->max_descent
= 0;
2894 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2896 it
->current_y
= first_y
;
2898 it
->current_x
= it
->hpos
= 0;
2904 /* Return 1 if POS is a position in ellipses displayed for invisible
2905 text. W is the window we display, for text property lookup. */
2908 in_ellipses_for_invisible_text_p (pos
, w
)
2909 struct display_pos
*pos
;
2912 Lisp_Object prop
, window
;
2914 int charpos
= CHARPOS (pos
->pos
);
2916 /* If POS specifies a position in a display vector, this might
2917 be for an ellipsis displayed for invisible text. We won't
2918 get the iterator set up for delivering that ellipsis unless
2919 we make sure that it gets aware of the invisible text. */
2920 if (pos
->dpvec_index
>= 0
2921 && pos
->overlay_string_index
< 0
2922 && CHARPOS (pos
->string_pos
) < 0
2924 && (XSETWINDOW (window
, w
),
2925 prop
= Fget_char_property (make_number (charpos
),
2926 Qinvisible
, window
),
2927 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2929 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2931 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2938 /* Initialize IT for stepping through current_buffer in window W,
2939 starting at position POS that includes overlay string and display
2940 vector/ control character translation position information. Value
2941 is zero if there are overlay strings with newlines at POS. */
2944 init_from_display_pos (it
, w
, pos
)
2947 struct display_pos
*pos
;
2949 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2950 int i
, overlay_strings_with_newlines
= 0;
2952 /* If POS specifies a position in a display vector, this might
2953 be for an ellipsis displayed for invisible text. We won't
2954 get the iterator set up for delivering that ellipsis unless
2955 we make sure that it gets aware of the invisible text. */
2956 if (in_ellipses_for_invisible_text_p (pos
, w
))
2962 /* Keep in mind: the call to reseat in init_iterator skips invisible
2963 text, so we might end up at a position different from POS. This
2964 is only a problem when POS is a row start after a newline and an
2965 overlay starts there with an after-string, and the overlay has an
2966 invisible property. Since we don't skip invisible text in
2967 display_line and elsewhere immediately after consuming the
2968 newline before the row start, such a POS will not be in a string,
2969 but the call to init_iterator below will move us to the
2971 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2973 /* This only scans the current chunk -- it should scan all chunks.
2974 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2975 to 16 in 22.1 to make this a lesser problem. */
2976 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2978 const char *s
= SDATA (it
->overlay_strings
[i
]);
2979 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2981 while (s
< e
&& *s
!= '\n')
2986 overlay_strings_with_newlines
= 1;
2991 /* If position is within an overlay string, set up IT to the right
2993 if (pos
->overlay_string_index
>= 0)
2997 /* If the first overlay string happens to have a `display'
2998 property for an image, the iterator will be set up for that
2999 image, and we have to undo that setup first before we can
3000 correct the overlay string index. */
3001 if (it
->method
== GET_FROM_IMAGE
)
3004 /* We already have the first chunk of overlay strings in
3005 IT->overlay_strings. Load more until the one for
3006 pos->overlay_string_index is in IT->overlay_strings. */
3007 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3009 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3010 it
->current
.overlay_string_index
= 0;
3013 load_overlay_strings (it
, 0);
3014 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3018 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3019 relative_index
= (it
->current
.overlay_string_index
3020 % OVERLAY_STRING_CHUNK_SIZE
);
3021 it
->string
= it
->overlay_strings
[relative_index
];
3022 xassert (STRINGP (it
->string
));
3023 it
->current
.string_pos
= pos
->string_pos
;
3024 it
->method
= GET_FROM_STRING
;
3027 if (CHARPOS (pos
->string_pos
) >= 0)
3029 /* Recorded position is not in an overlay string, but in another
3030 string. This can only be a string from a `display' property.
3031 IT should already be filled with that string. */
3032 it
->current
.string_pos
= pos
->string_pos
;
3033 xassert (STRINGP (it
->string
));
3036 /* Restore position in display vector translations, control
3037 character translations or ellipses. */
3038 if (pos
->dpvec_index
>= 0)
3040 if (it
->dpvec
== NULL
)
3041 get_next_display_element (it
);
3042 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3043 it
->current
.dpvec_index
= pos
->dpvec_index
;
3047 return !overlay_strings_with_newlines
;
3051 /* Initialize IT for stepping through current_buffer in window W
3052 starting at ROW->start. */
3055 init_to_row_start (it
, w
, row
)
3058 struct glyph_row
*row
;
3060 init_from_display_pos (it
, w
, &row
->start
);
3061 it
->start
= row
->start
;
3062 it
->continuation_lines_width
= row
->continuation_lines_width
;
3067 /* Initialize IT for stepping through current_buffer in window W
3068 starting in the line following ROW, i.e. starting at ROW->end.
3069 Value is zero if there are overlay strings with newlines at ROW's
3073 init_to_row_end (it
, w
, row
)
3076 struct glyph_row
*row
;
3080 if (init_from_display_pos (it
, w
, &row
->end
))
3082 if (row
->continued_p
)
3083 it
->continuation_lines_width
3084 = row
->continuation_lines_width
+ row
->pixel_width
;
3095 /***********************************************************************
3097 ***********************************************************************/
3099 /* Called when IT reaches IT->stop_charpos. Handle text property and
3100 overlay changes. Set IT->stop_charpos to the next position where
3107 enum prop_handled handled
;
3108 int handle_overlay_change_p
;
3112 it
->current
.dpvec_index
= -1;
3113 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3114 it
->ignore_overlay_strings_at_pos_p
= 0;
3117 /* Use face of preceding text for ellipsis (if invisible) */
3118 if (it
->selective_display_ellipsis_p
)
3119 it
->saved_face_id
= it
->face_id
;
3123 handled
= HANDLED_NORMALLY
;
3125 /* Call text property handlers. */
3126 for (p
= it_props
; p
->handler
; ++p
)
3128 handled
= p
->handler (it
);
3130 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3132 else if (handled
== HANDLED_RETURN
)
3134 /* We still want to show before and after strings from
3135 overlays even if the actual buffer text is replaced. */
3136 if (!handle_overlay_change_p
3138 || !get_overlay_strings_1 (it
, 0, 0))
3141 setup_for_ellipsis (it
, 0);
3142 /* When handling a display spec, we might load an
3143 empty string. In that case, discard it here. We
3144 used to discard it in handle_single_display_spec,
3145 but that causes get_overlay_strings_1, above, to
3146 ignore overlay strings that we must check. */
3147 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3151 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3155 it
->ignore_overlay_strings_at_pos_p
= 1;
3156 it
->string_from_display_prop_p
= 0;
3157 handle_overlay_change_p
= 0;
3159 handled
= HANDLED_RECOMPUTE_PROPS
;
3162 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3163 handle_overlay_change_p
= 0;
3166 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3168 /* Don't check for overlay strings below when set to deliver
3169 characters from a display vector. */
3170 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3171 handle_overlay_change_p
= 0;
3173 /* Handle overlay changes.
3174 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3175 if it finds overlays. */
3176 if (handle_overlay_change_p
)
3177 handled
= handle_overlay_change (it
);
3182 setup_for_ellipsis (it
, 0);
3186 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3188 /* Determine where to stop next. */
3189 if (handled
== HANDLED_NORMALLY
)
3190 compute_stop_pos (it
);
3194 /* Compute IT->stop_charpos from text property and overlay change
3195 information for IT's current position. */
3198 compute_stop_pos (it
)
3201 register INTERVAL iv
, next_iv
;
3202 Lisp_Object object
, limit
, position
;
3203 EMACS_INT charpos
, bytepos
;
3205 /* If nowhere else, stop at the end. */
3206 it
->stop_charpos
= it
->end_charpos
;
3208 if (STRINGP (it
->string
))
3210 /* Strings are usually short, so don't limit the search for
3212 object
= it
->string
;
3214 charpos
= IT_STRING_CHARPOS (*it
);
3215 bytepos
= IT_STRING_BYTEPOS (*it
);
3221 /* If next overlay change is in front of the current stop pos
3222 (which is IT->end_charpos), stop there. Note: value of
3223 next_overlay_change is point-max if no overlay change
3225 charpos
= IT_CHARPOS (*it
);
3226 bytepos
= IT_BYTEPOS (*it
);
3227 pos
= next_overlay_change (charpos
);
3228 if (pos
< it
->stop_charpos
)
3229 it
->stop_charpos
= pos
;
3231 /* If showing the region, we have to stop at the region
3232 start or end because the face might change there. */
3233 if (it
->region_beg_charpos
> 0)
3235 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3236 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3237 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3238 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3241 /* Set up variables for computing the stop position from text
3242 property changes. */
3243 XSETBUFFER (object
, current_buffer
);
3244 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3247 /* Get the interval containing IT's position. Value is a null
3248 interval if there isn't such an interval. */
3249 position
= make_number (charpos
);
3250 iv
= validate_interval_range (object
, &position
, &position
, 0);
3251 if (!NULL_INTERVAL_P (iv
))
3253 Lisp_Object values_here
[LAST_PROP_IDX
];
3256 /* Get properties here. */
3257 for (p
= it_props
; p
->handler
; ++p
)
3258 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3260 /* Look for an interval following iv that has different
3262 for (next_iv
= next_interval (iv
);
3263 (!NULL_INTERVAL_P (next_iv
)
3265 || XFASTINT (limit
) > next_iv
->position
));
3266 next_iv
= next_interval (next_iv
))
3268 for (p
= it_props
; p
->handler
; ++p
)
3270 Lisp_Object new_value
;
3272 new_value
= textget (next_iv
->plist
, *p
->name
);
3273 if (!EQ (values_here
[p
->idx
], new_value
))
3281 if (!NULL_INTERVAL_P (next_iv
))
3283 if (INTEGERP (limit
)
3284 && next_iv
->position
>= XFASTINT (limit
))
3285 /* No text property change up to limit. */
3286 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3288 /* Text properties change in next_iv. */
3289 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3293 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3294 it
->stop_charpos
, it
->string
);
3296 xassert (STRINGP (it
->string
)
3297 || (it
->stop_charpos
>= BEGV
3298 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3302 /* Return the position of the next overlay change after POS in
3303 current_buffer. Value is point-max if no overlay change
3304 follows. This is like `next-overlay-change' but doesn't use
3308 next_overlay_change (pos
)
3313 Lisp_Object
*overlays
;
3316 /* Get all overlays at the given position. */
3317 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3319 /* If any of these overlays ends before endpos,
3320 use its ending point instead. */
3321 for (i
= 0; i
< noverlays
; ++i
)
3326 oend
= OVERLAY_END (overlays
[i
]);
3327 oendpos
= OVERLAY_POSITION (oend
);
3328 endpos
= min (endpos
, oendpos
);
3336 /***********************************************************************
3338 ***********************************************************************/
3340 /* Handle changes in the `fontified' property of the current buffer by
3341 calling hook functions from Qfontification_functions to fontify
3344 static enum prop_handled
3345 handle_fontified_prop (it
)
3348 Lisp_Object prop
, pos
;
3349 enum prop_handled handled
= HANDLED_NORMALLY
;
3351 if (!NILP (Vmemory_full
))
3354 /* Get the value of the `fontified' property at IT's current buffer
3355 position. (The `fontified' property doesn't have a special
3356 meaning in strings.) If the value is nil, call functions from
3357 Qfontification_functions. */
3358 if (!STRINGP (it
->string
)
3360 && !NILP (Vfontification_functions
)
3361 && !NILP (Vrun_hooks
)
3362 && (pos
= make_number (IT_CHARPOS (*it
)),
3363 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3364 /* Ignore the special cased nil value always present at EOB since
3365 no amount of fontifying will be able to change it. */
3366 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3368 int count
= SPECPDL_INDEX ();
3371 val
= Vfontification_functions
;
3372 specbind (Qfontification_functions
, Qnil
);
3374 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3375 safe_call1 (val
, pos
);
3378 Lisp_Object globals
, fn
;
3379 struct gcpro gcpro1
, gcpro2
;
3382 GCPRO2 (val
, globals
);
3384 for (; CONSP (val
); val
= XCDR (val
))
3390 /* A value of t indicates this hook has a local
3391 binding; it means to run the global binding too.
3392 In a global value, t should not occur. If it
3393 does, we must ignore it to avoid an endless
3395 for (globals
= Fdefault_value (Qfontification_functions
);
3397 globals
= XCDR (globals
))
3399 fn
= XCAR (globals
);
3401 safe_call1 (fn
, pos
);
3405 safe_call1 (fn
, pos
);
3411 unbind_to (count
, Qnil
);
3413 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3414 something. This avoids an endless loop if they failed to
3415 fontify the text for which reason ever. */
3416 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3417 handled
= HANDLED_RECOMPUTE_PROPS
;
3425 /***********************************************************************
3427 ***********************************************************************/
3429 /* Set up iterator IT from face properties at its current position.
3430 Called from handle_stop. */
3432 static enum prop_handled
3433 handle_face_prop (it
)
3437 EMACS_INT next_stop
;
3439 if (!STRINGP (it
->string
))
3442 = face_at_buffer_position (it
->w
,
3444 it
->region_beg_charpos
,
3445 it
->region_end_charpos
,
3448 + TEXT_PROP_DISTANCE_LIMIT
),
3449 0, it
->base_face_id
);
3451 /* Is this a start of a run of characters with box face?
3452 Caveat: this can be called for a freshly initialized
3453 iterator; face_id is -1 in this case. We know that the new
3454 face will not change until limit, i.e. if the new face has a
3455 box, all characters up to limit will have one. But, as
3456 usual, we don't know whether limit is really the end. */
3457 if (new_face_id
!= it
->face_id
)
3459 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3461 /* If new face has a box but old face has not, this is
3462 the start of a run of characters with box, i.e. it has
3463 a shadow on the left side. The value of face_id of the
3464 iterator will be -1 if this is the initial call that gets
3465 the face. In this case, we have to look in front of IT's
3466 position and see whether there is a face != new_face_id. */
3467 it
->start_of_box_run_p
3468 = (new_face
->box
!= FACE_NO_BOX
3469 && (it
->face_id
>= 0
3470 || IT_CHARPOS (*it
) == BEG
3471 || new_face_id
!= face_before_it_pos (it
)));
3472 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3477 int base_face_id
, bufpos
;
3479 Lisp_Object from_overlay
3480 = (it
->current
.overlay_string_index
>= 0
3481 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3484 /* See if we got to this string directly or indirectly from
3485 an overlay property. That includes the before-string or
3486 after-string of an overlay, strings in display properties
3487 provided by an overlay, their text properties, etc.
3489 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3490 if (! NILP (from_overlay
))
3491 for (i
= it
->sp
- 1; i
>= 0; i
--)
3493 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3495 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3496 else if (! NILP (it
->stack
[i
].from_overlay
))
3497 from_overlay
= it
->stack
[i
].from_overlay
;
3499 if (!NILP (from_overlay
))
3503 if (! NILP (from_overlay
))
3505 bufpos
= IT_CHARPOS (*it
);
3506 /* For a string from an overlay, the base face depends
3507 only on text properties and ignores overlays. */
3509 = face_for_overlay_string (it
->w
,
3511 it
->region_beg_charpos
,
3512 it
->region_end_charpos
,
3515 + TEXT_PROP_DISTANCE_LIMIT
),
3523 /* For strings from a `display' property, use the face at
3524 IT's current buffer position as the base face to merge
3525 with, so that overlay strings appear in the same face as
3526 surrounding text, unless they specify their own
3528 base_face_id
= underlying_face_id (it
);
3531 new_face_id
= face_at_string_position (it
->w
,
3533 IT_STRING_CHARPOS (*it
),
3535 it
->region_beg_charpos
,
3536 it
->region_end_charpos
,
3540 /* Is this a start of a run of characters with box? Caveat:
3541 this can be called for a freshly allocated iterator; face_id
3542 is -1 is this case. We know that the new face will not
3543 change until the next check pos, i.e. if the new face has a
3544 box, all characters up to that position will have a
3545 box. But, as usual, we don't know whether that position
3546 is really the end. */
3547 if (new_face_id
!= it
->face_id
)
3549 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3550 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3552 /* If new face has a box but old face hasn't, this is the
3553 start of a run of characters with box, i.e. it has a
3554 shadow on the left side. */
3555 it
->start_of_box_run_p
3556 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3557 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3561 it
->face_id
= new_face_id
;
3562 return HANDLED_NORMALLY
;
3566 /* Return the ID of the face ``underlying'' IT's current position,
3567 which is in a string. If the iterator is associated with a
3568 buffer, return the face at IT's current buffer position.
3569 Otherwise, use the iterator's base_face_id. */
3572 underlying_face_id (it
)
3575 int face_id
= it
->base_face_id
, i
;
3577 xassert (STRINGP (it
->string
));
3579 for (i
= it
->sp
- 1; i
>= 0; --i
)
3580 if (NILP (it
->stack
[i
].string
))
3581 face_id
= it
->stack
[i
].face_id
;
3587 /* Compute the face one character before or after the current position
3588 of IT. BEFORE_P non-zero means get the face in front of IT's
3589 position. Value is the id of the face. */
3592 face_before_or_after_it_pos (it
, before_p
)
3597 EMACS_INT next_check_charpos
;
3598 struct text_pos pos
;
3600 xassert (it
->s
== NULL
);
3602 if (STRINGP (it
->string
))
3604 int bufpos
, base_face_id
;
3606 /* No face change past the end of the string (for the case
3607 we are padding with spaces). No face change before the
3609 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3610 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3613 /* Set pos to the position before or after IT's current position. */
3615 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3617 /* For composition, we must check the character after the
3619 pos
= (it
->what
== IT_COMPOSITION
3620 ? string_pos (IT_STRING_CHARPOS (*it
)
3621 + it
->cmp_it
.nchars
, it
->string
)
3622 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3624 if (it
->current
.overlay_string_index
>= 0)
3625 bufpos
= IT_CHARPOS (*it
);
3629 base_face_id
= underlying_face_id (it
);
3631 /* Get the face for ASCII, or unibyte. */
3632 face_id
= face_at_string_position (it
->w
,
3636 it
->region_beg_charpos
,
3637 it
->region_end_charpos
,
3638 &next_check_charpos
,
3641 /* Correct the face for charsets different from ASCII. Do it
3642 for the multibyte case only. The face returned above is
3643 suitable for unibyte text if IT->string is unibyte. */
3644 if (STRING_MULTIBYTE (it
->string
))
3646 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3647 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3649 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3651 c
= string_char_and_length (p
, rest
, &len
);
3652 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3657 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3658 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3661 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3662 pos
= it
->current
.pos
;
3665 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3668 if (it
->what
== IT_COMPOSITION
)
3669 /* For composition, we must check the position after the
3671 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3673 INC_TEXT_POS (pos
, it
->multibyte_p
);
3676 /* Determine face for CHARSET_ASCII, or unibyte. */
3677 face_id
= face_at_buffer_position (it
->w
,
3679 it
->region_beg_charpos
,
3680 it
->region_end_charpos
,
3681 &next_check_charpos
,
3684 /* Correct the face for charsets different from ASCII. Do it
3685 for the multibyte case only. The face returned above is
3686 suitable for unibyte text if current_buffer is unibyte. */
3687 if (it
->multibyte_p
)
3689 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3690 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3691 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3700 /***********************************************************************
3702 ***********************************************************************/
3704 /* Set up iterator IT from invisible properties at its current
3705 position. Called from handle_stop. */
3707 static enum prop_handled
3708 handle_invisible_prop (it
)
3711 enum prop_handled handled
= HANDLED_NORMALLY
;
3713 if (STRINGP (it
->string
))
3715 extern Lisp_Object Qinvisible
;
3716 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3718 /* Get the value of the invisible text property at the
3719 current position. Value will be nil if there is no such
3721 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3722 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3725 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3727 handled
= HANDLED_RECOMPUTE_PROPS
;
3729 /* Get the position at which the next change of the
3730 invisible text property can be found in IT->string.
3731 Value will be nil if the property value is the same for
3732 all the rest of IT->string. */
3733 XSETINT (limit
, SCHARS (it
->string
));
3734 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3737 /* Text at current position is invisible. The next
3738 change in the property is at position end_charpos.
3739 Move IT's current position to that position. */
3740 if (INTEGERP (end_charpos
)
3741 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3743 struct text_pos old
;
3744 old
= it
->current
.string_pos
;
3745 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3746 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3750 /* The rest of the string is invisible. If this is an
3751 overlay string, proceed with the next overlay string
3752 or whatever comes and return a character from there. */
3753 if (it
->current
.overlay_string_index
>= 0)
3755 next_overlay_string (it
);
3756 /* Don't check for overlay strings when we just
3757 finished processing them. */
3758 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3762 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3763 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3771 EMACS_INT newpos
, next_stop
, start_charpos
;
3772 Lisp_Object pos
, prop
, overlay
;
3774 /* First of all, is there invisible text at this position? */
3775 start_charpos
= IT_CHARPOS (*it
);
3776 pos
= make_number (IT_CHARPOS (*it
));
3777 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3779 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3781 /* If we are on invisible text, skip over it. */
3782 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3784 /* Record whether we have to display an ellipsis for the
3786 int display_ellipsis_p
= invis_p
== 2;
3788 handled
= HANDLED_RECOMPUTE_PROPS
;
3790 /* Loop skipping over invisible text. The loop is left at
3791 ZV or with IT on the first char being visible again. */
3794 /* Try to skip some invisible text. Return value is the
3795 position reached which can be equal to IT's position
3796 if there is nothing invisible here. This skips both
3797 over invisible text properties and overlays with
3798 invisible property. */
3799 newpos
= skip_invisible (IT_CHARPOS (*it
),
3800 &next_stop
, ZV
, it
->window
);
3802 /* If we skipped nothing at all we weren't at invisible
3803 text in the first place. If everything to the end of
3804 the buffer was skipped, end the loop. */
3805 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3809 /* We skipped some characters but not necessarily
3810 all there are. Check if we ended up on visible
3811 text. Fget_char_property returns the property of
3812 the char before the given position, i.e. if we
3813 get invis_p = 0, this means that the char at
3814 newpos is visible. */
3815 pos
= make_number (newpos
);
3816 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3817 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3820 /* If we ended up on invisible text, proceed to
3821 skip starting with next_stop. */
3823 IT_CHARPOS (*it
) = next_stop
;
3825 /* If there are adjacent invisible texts, don't lose the
3826 second one's ellipsis. */
3828 display_ellipsis_p
= 1;
3832 /* The position newpos is now either ZV or on visible text. */
3833 IT_CHARPOS (*it
) = newpos
;
3834 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3836 /* If there are before-strings at the start of invisible
3837 text, and the text is invisible because of a text
3838 property, arrange to show before-strings because 20.x did
3839 it that way. (If the text is invisible because of an
3840 overlay property instead of a text property, this is
3841 already handled in the overlay code.) */
3843 && get_overlay_strings (it
, start_charpos
))
3845 handled
= HANDLED_RECOMPUTE_PROPS
;
3846 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3848 else if (display_ellipsis_p
)
3850 /* Make sure that the glyphs of the ellipsis will get
3851 correct `charpos' values. If we would not update
3852 it->position here, the glyphs would belong to the
3853 last visible character _before_ the invisible
3854 text, which confuses `set_cursor_from_row'.
3856 We use the last invisible position instead of the
3857 first because this way the cursor is always drawn on
3858 the first "." of the ellipsis, whenever PT is inside
3859 the invisible text. Otherwise the cursor would be
3860 placed _after_ the ellipsis when the point is after the
3861 first invisible character. */
3862 if (!STRINGP (it
->object
))
3864 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3865 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3868 /* Let the ellipsis display before
3869 considering any properties of the following char.
3870 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3871 handled
= HANDLED_RETURN
;
3880 /* Make iterator IT return `...' next.
3881 Replaces LEN characters from buffer. */
3884 setup_for_ellipsis (it
, len
)
3888 /* Use the display table definition for `...'. Invalid glyphs
3889 will be handled by the method returning elements from dpvec. */
3890 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3892 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3893 it
->dpvec
= v
->contents
;
3894 it
->dpend
= v
->contents
+ v
->size
;
3898 /* Default `...'. */
3899 it
->dpvec
= default_invis_vector
;
3900 it
->dpend
= default_invis_vector
+ 3;
3903 it
->dpvec_char_len
= len
;
3904 it
->current
.dpvec_index
= 0;
3905 it
->dpvec_face_id
= -1;
3907 /* Remember the current face id in case glyphs specify faces.
3908 IT's face is restored in set_iterator_to_next.
3909 saved_face_id was set to preceding char's face in handle_stop. */
3910 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3911 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3913 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3919 /***********************************************************************
3921 ***********************************************************************/
3923 /* Set up iterator IT from `display' property at its current position.
3924 Called from handle_stop.
3925 We return HANDLED_RETURN if some part of the display property
3926 overrides the display of the buffer text itself.
3927 Otherwise we return HANDLED_NORMALLY. */
3929 static enum prop_handled
3930 handle_display_prop (it
)
3933 Lisp_Object prop
, object
, overlay
;
3934 struct text_pos
*position
;
3935 /* Nonzero if some property replaces the display of the text itself. */
3936 int display_replaced_p
= 0;
3938 if (STRINGP (it
->string
))
3940 object
= it
->string
;
3941 position
= &it
->current
.string_pos
;
3945 XSETWINDOW (object
, it
->w
);
3946 position
= &it
->current
.pos
;
3949 /* Reset those iterator values set from display property values. */
3950 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3951 it
->space_width
= Qnil
;
3952 it
->font_height
= Qnil
;
3955 /* We don't support recursive `display' properties, i.e. string
3956 values that have a string `display' property, that have a string
3957 `display' property etc. */
3958 if (!it
->string_from_display_prop_p
)
3959 it
->area
= TEXT_AREA
;
3961 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3962 Qdisplay
, object
, &overlay
);
3964 return HANDLED_NORMALLY
;
3965 /* Now OVERLAY is the overlay that gave us this property, or nil
3966 if it was a text property. */
3968 if (!STRINGP (it
->string
))
3969 object
= it
->w
->buffer
;
3972 /* Simple properties. */
3973 && !EQ (XCAR (prop
), Qimage
)
3974 && !EQ (XCAR (prop
), Qspace
)
3975 && !EQ (XCAR (prop
), Qwhen
)
3976 && !EQ (XCAR (prop
), Qslice
)
3977 && !EQ (XCAR (prop
), Qspace_width
)
3978 && !EQ (XCAR (prop
), Qheight
)
3979 && !EQ (XCAR (prop
), Qraise
)
3980 /* Marginal area specifications. */
3981 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3982 && !EQ (XCAR (prop
), Qleft_fringe
)
3983 && !EQ (XCAR (prop
), Qright_fringe
)
3984 && !NILP (XCAR (prop
)))
3986 for (; CONSP (prop
); prop
= XCDR (prop
))
3988 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3989 position
, display_replaced_p
))
3991 display_replaced_p
= 1;
3992 /* If some text in a string is replaced, `position' no
3993 longer points to the position of `object'. */
3994 if (STRINGP (object
))
3999 else if (VECTORP (prop
))
4002 for (i
= 0; i
< ASIZE (prop
); ++i
)
4003 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4004 position
, display_replaced_p
))
4006 display_replaced_p
= 1;
4007 /* If some text in a string is replaced, `position' no
4008 longer points to the position of `object'. */
4009 if (STRINGP (object
))
4015 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4017 display_replaced_p
= 1;
4020 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4024 /* Value is the position of the end of the `display' property starting
4025 at START_POS in OBJECT. */
4027 static struct text_pos
4028 display_prop_end (it
, object
, start_pos
)
4031 struct text_pos start_pos
;
4034 struct text_pos end_pos
;
4036 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4037 Qdisplay
, object
, Qnil
);
4038 CHARPOS (end_pos
) = XFASTINT (end
);
4039 if (STRINGP (object
))
4040 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4042 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4048 /* Set up IT from a single `display' specification PROP. OBJECT
4049 is the object in which the `display' property was found. *POSITION
4050 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4051 means that we previously saw a display specification which already
4052 replaced text display with something else, for example an image;
4053 we ignore such properties after the first one has been processed.
4055 OVERLAY is the overlay this `display' property came from,
4056 or nil if it was a text property.
4058 If PROP is a `space' or `image' specification, and in some other
4059 cases too, set *POSITION to the position where the `display'
4062 Value is non-zero if something was found which replaces the display
4063 of buffer or string text. */
4066 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4067 display_replaced_before_p
)
4071 Lisp_Object overlay
;
4072 struct text_pos
*position
;
4073 int display_replaced_before_p
;
4076 Lisp_Object location
, value
;
4077 struct text_pos start_pos
, save_pos
;
4080 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4081 If the result is non-nil, use VALUE instead of SPEC. */
4083 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4092 if (!NILP (form
) && !EQ (form
, Qt
))
4094 int count
= SPECPDL_INDEX ();
4095 struct gcpro gcpro1
;
4097 /* Bind `object' to the object having the `display' property, a
4098 buffer or string. Bind `position' to the position in the
4099 object where the property was found, and `buffer-position'
4100 to the current position in the buffer. */
4101 specbind (Qobject
, object
);
4102 specbind (Qposition
, make_number (CHARPOS (*position
)));
4103 specbind (Qbuffer_position
,
4104 make_number (STRINGP (object
)
4105 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4107 form
= safe_eval (form
);
4109 unbind_to (count
, Qnil
);
4115 /* Handle `(height HEIGHT)' specifications. */
4117 && EQ (XCAR (spec
), Qheight
)
4118 && CONSP (XCDR (spec
)))
4120 if (!FRAME_WINDOW_P (it
->f
))
4123 it
->font_height
= XCAR (XCDR (spec
));
4124 if (!NILP (it
->font_height
))
4126 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4127 int new_height
= -1;
4129 if (CONSP (it
->font_height
)
4130 && (EQ (XCAR (it
->font_height
), Qplus
)
4131 || EQ (XCAR (it
->font_height
), Qminus
))
4132 && CONSP (XCDR (it
->font_height
))
4133 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4135 /* `(+ N)' or `(- N)' where N is an integer. */
4136 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4137 if (EQ (XCAR (it
->font_height
), Qplus
))
4139 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4141 else if (FUNCTIONP (it
->font_height
))
4143 /* Call function with current height as argument.
4144 Value is the new height. */
4146 height
= safe_call1 (it
->font_height
,
4147 face
->lface
[LFACE_HEIGHT_INDEX
]);
4148 if (NUMBERP (height
))
4149 new_height
= XFLOATINT (height
);
4151 else if (NUMBERP (it
->font_height
))
4153 /* Value is a multiple of the canonical char height. */
4156 face
= FACE_FROM_ID (it
->f
,
4157 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4158 new_height
= (XFLOATINT (it
->font_height
)
4159 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4163 /* Evaluate IT->font_height with `height' bound to the
4164 current specified height to get the new height. */
4165 int count
= SPECPDL_INDEX ();
4167 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4168 value
= safe_eval (it
->font_height
);
4169 unbind_to (count
, Qnil
);
4171 if (NUMBERP (value
))
4172 new_height
= XFLOATINT (value
);
4176 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4182 /* Handle `(space-width WIDTH)'. */
4184 && EQ (XCAR (spec
), Qspace_width
)
4185 && CONSP (XCDR (spec
)))
4187 if (!FRAME_WINDOW_P (it
->f
))
4190 value
= XCAR (XCDR (spec
));
4191 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4192 it
->space_width
= value
;
4197 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4199 && EQ (XCAR (spec
), Qslice
))
4203 if (!FRAME_WINDOW_P (it
->f
))
4206 if (tem
= XCDR (spec
), CONSP (tem
))
4208 it
->slice
.x
= XCAR (tem
);
4209 if (tem
= XCDR (tem
), CONSP (tem
))
4211 it
->slice
.y
= XCAR (tem
);
4212 if (tem
= XCDR (tem
), CONSP (tem
))
4214 it
->slice
.width
= XCAR (tem
);
4215 if (tem
= XCDR (tem
), CONSP (tem
))
4216 it
->slice
.height
= XCAR (tem
);
4224 /* Handle `(raise FACTOR)'. */
4226 && EQ (XCAR (spec
), Qraise
)
4227 && CONSP (XCDR (spec
)))
4229 if (!FRAME_WINDOW_P (it
->f
))
4232 #ifdef HAVE_WINDOW_SYSTEM
4233 value
= XCAR (XCDR (spec
));
4234 if (NUMBERP (value
))
4236 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4237 it
->voffset
= - (XFLOATINT (value
)
4238 * (FONT_HEIGHT (face
->font
)));
4240 #endif /* HAVE_WINDOW_SYSTEM */
4245 /* Don't handle the other kinds of display specifications
4246 inside a string that we got from a `display' property. */
4247 if (it
->string_from_display_prop_p
)
4250 /* Characters having this form of property are not displayed, so
4251 we have to find the end of the property. */
4252 start_pos
= *position
;
4253 *position
= display_prop_end (it
, object
, start_pos
);
4256 /* Stop the scan at that end position--we assume that all
4257 text properties change there. */
4258 it
->stop_charpos
= position
->charpos
;
4260 /* Handle `(left-fringe BITMAP [FACE])'
4261 and `(right-fringe BITMAP [FACE])'. */
4263 && (EQ (XCAR (spec
), Qleft_fringe
)
4264 || EQ (XCAR (spec
), Qright_fringe
))
4265 && CONSP (XCDR (spec
)))
4267 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4270 if (!FRAME_WINDOW_P (it
->f
))
4271 /* If we return here, POSITION has been advanced
4272 across the text with this property. */
4275 #ifdef HAVE_WINDOW_SYSTEM
4276 value
= XCAR (XCDR (spec
));
4277 if (!SYMBOLP (value
)
4278 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4279 /* If we return here, POSITION has been advanced
4280 across the text with this property. */
4283 if (CONSP (XCDR (XCDR (spec
))))
4285 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4286 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4292 /* Save current settings of IT so that we can restore them
4293 when we are finished with the glyph property value. */
4295 save_pos
= it
->position
;
4296 it
->position
= *position
;
4298 it
->position
= save_pos
;
4300 it
->area
= TEXT_AREA
;
4301 it
->what
= IT_IMAGE
;
4302 it
->image_id
= -1; /* no image */
4303 it
->position
= start_pos
;
4304 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4305 it
->method
= GET_FROM_IMAGE
;
4306 it
->from_overlay
= Qnil
;
4307 it
->face_id
= face_id
;
4309 /* Say that we haven't consumed the characters with
4310 `display' property yet. The call to pop_it in
4311 set_iterator_to_next will clean this up. */
4312 *position
= start_pos
;
4314 if (EQ (XCAR (spec
), Qleft_fringe
))
4316 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4317 it
->left_user_fringe_face_id
= face_id
;
4321 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4322 it
->right_user_fringe_face_id
= face_id
;
4324 #endif /* HAVE_WINDOW_SYSTEM */
4328 /* Prepare to handle `((margin left-margin) ...)',
4329 `((margin right-margin) ...)' and `((margin nil) ...)'
4330 prefixes for display specifications. */
4331 location
= Qunbound
;
4332 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4336 value
= XCDR (spec
);
4338 value
= XCAR (value
);
4341 if (EQ (XCAR (tem
), Qmargin
)
4342 && (tem
= XCDR (tem
),
4343 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4345 || EQ (tem
, Qleft_margin
)
4346 || EQ (tem
, Qright_margin
))))
4350 if (EQ (location
, Qunbound
))
4356 /* After this point, VALUE is the property after any
4357 margin prefix has been stripped. It must be a string,
4358 an image specification, or `(space ...)'.
4360 LOCATION specifies where to display: `left-margin',
4361 `right-margin' or nil. */
4363 valid_p
= (STRINGP (value
)
4364 #ifdef HAVE_WINDOW_SYSTEM
4365 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4366 #endif /* not HAVE_WINDOW_SYSTEM */
4367 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4369 if (valid_p
&& !display_replaced_before_p
)
4371 /* Save current settings of IT so that we can restore them
4372 when we are finished with the glyph property value. */
4373 save_pos
= it
->position
;
4374 it
->position
= *position
;
4376 it
->position
= save_pos
;
4377 it
->from_overlay
= overlay
;
4379 if (NILP (location
))
4380 it
->area
= TEXT_AREA
;
4381 else if (EQ (location
, Qleft_margin
))
4382 it
->area
= LEFT_MARGIN_AREA
;
4384 it
->area
= RIGHT_MARGIN_AREA
;
4386 if (STRINGP (value
))
4389 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4390 it
->current
.overlay_string_index
= -1;
4391 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4392 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4393 it
->method
= GET_FROM_STRING
;
4394 it
->stop_charpos
= 0;
4395 it
->string_from_display_prop_p
= 1;
4396 /* Say that we haven't consumed the characters with
4397 `display' property yet. The call to pop_it in
4398 set_iterator_to_next will clean this up. */
4399 if (BUFFERP (object
))
4400 *position
= start_pos
;
4402 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4404 it
->method
= GET_FROM_STRETCH
;
4406 *position
= it
->position
= start_pos
;
4408 #ifdef HAVE_WINDOW_SYSTEM
4411 it
->what
= IT_IMAGE
;
4412 it
->image_id
= lookup_image (it
->f
, value
);
4413 it
->position
= start_pos
;
4414 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4415 it
->method
= GET_FROM_IMAGE
;
4417 /* Say that we haven't consumed the characters with
4418 `display' property yet. The call to pop_it in
4419 set_iterator_to_next will clean this up. */
4420 *position
= start_pos
;
4422 #endif /* HAVE_WINDOW_SYSTEM */
4427 /* Invalid property or property not supported. Restore
4428 POSITION to what it was before. */
4429 *position
= start_pos
;
4434 /* Check if SPEC is a display sub-property value whose text should be
4435 treated as intangible. */
4438 single_display_spec_intangible_p (prop
)
4441 /* Skip over `when FORM'. */
4442 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4456 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4457 we don't need to treat text as intangible. */
4458 if (EQ (XCAR (prop
), Qmargin
))
4466 || EQ (XCAR (prop
), Qleft_margin
)
4467 || EQ (XCAR (prop
), Qright_margin
))
4471 return (CONSP (prop
)
4472 && (EQ (XCAR (prop
), Qimage
)
4473 || EQ (XCAR (prop
), Qspace
)));
4477 /* Check if PROP is a display property value whose text should be
4478 treated as intangible. */
4481 display_prop_intangible_p (prop
)
4485 && CONSP (XCAR (prop
))
4486 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4488 /* A list of sub-properties. */
4489 while (CONSP (prop
))
4491 if (single_display_spec_intangible_p (XCAR (prop
)))
4496 else if (VECTORP (prop
))
4498 /* A vector of sub-properties. */
4500 for (i
= 0; i
< ASIZE (prop
); ++i
)
4501 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4505 return single_display_spec_intangible_p (prop
);
4511 /* Return 1 if PROP is a display sub-property value containing STRING. */
4514 single_display_spec_string_p (prop
, string
)
4515 Lisp_Object prop
, string
;
4517 if (EQ (string
, prop
))
4520 /* Skip over `when FORM'. */
4521 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4530 /* Skip over `margin LOCATION'. */
4531 if (EQ (XCAR (prop
), Qmargin
))
4542 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4546 /* Return 1 if STRING appears in the `display' property PROP. */
4549 display_prop_string_p (prop
, string
)
4550 Lisp_Object prop
, string
;
4553 && CONSP (XCAR (prop
))
4554 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4556 /* A list of sub-properties. */
4557 while (CONSP (prop
))
4559 if (single_display_spec_string_p (XCAR (prop
), string
))
4564 else if (VECTORP (prop
))
4566 /* A vector of sub-properties. */
4568 for (i
= 0; i
< ASIZE (prop
); ++i
)
4569 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4573 return single_display_spec_string_p (prop
, string
);
4579 /* Determine which buffer position in W's buffer STRING comes from.
4580 AROUND_CHARPOS is an approximate position where it could come from.
4581 Value is the buffer position or 0 if it couldn't be determined.
4583 W's buffer must be current.
4585 This function is necessary because we don't record buffer positions
4586 in glyphs generated from strings (to keep struct glyph small).
4587 This function may only use code that doesn't eval because it is
4588 called asynchronously from note_mouse_highlight. */
4591 string_buffer_position (w
, string
, around_charpos
)
4596 Lisp_Object limit
, prop
, pos
;
4597 const int MAX_DISTANCE
= 1000;
4600 pos
= make_number (around_charpos
);
4601 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4602 while (!found
&& !EQ (pos
, limit
))
4604 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4605 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4608 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4613 pos
= make_number (around_charpos
);
4614 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4615 while (!found
&& !EQ (pos
, limit
))
4617 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4618 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4621 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4626 return found
? XINT (pos
) : 0;
4631 /***********************************************************************
4632 `composition' property
4633 ***********************************************************************/
4635 /* Set up iterator IT from `composition' property at its current
4636 position. Called from handle_stop. */
4638 static enum prop_handled
4639 handle_composition_prop (it
)
4642 Lisp_Object prop
, string
;
4643 EMACS_INT pos
, pos_byte
, start
, end
;
4645 if (STRINGP (it
->string
))
4649 pos
= IT_STRING_CHARPOS (*it
);
4650 pos_byte
= IT_STRING_BYTEPOS (*it
);
4651 string
= it
->string
;
4652 s
= SDATA (string
) + pos_byte
;
4653 it
->c
= STRING_CHAR (s
, 0);
4657 pos
= IT_CHARPOS (*it
);
4658 pos_byte
= IT_BYTEPOS (*it
);
4660 it
->c
= FETCH_CHAR (pos_byte
);
4663 /* If there's a valid composition and point is not inside of the
4664 composition (in the case that the composition is from the current
4665 buffer), draw a glyph composed from the composition components. */
4666 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4667 && COMPOSITION_VALID_P (start
, end
, prop
)
4668 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4672 if (STRINGP (it
->string
))
4673 pos_byte
= string_char_to_byte (it
->string
, start
);
4675 pos_byte
= CHAR_TO_BYTE (start
);
4677 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4680 if (it
->cmp_it
.id
>= 0)
4683 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4684 it
->cmp_it
.nglyphs
= -1;
4688 return HANDLED_NORMALLY
;
4693 /***********************************************************************
4695 ***********************************************************************/
4697 /* The following structure is used to record overlay strings for
4698 later sorting in load_overlay_strings. */
4700 struct overlay_entry
4702 Lisp_Object overlay
;
4709 /* Set up iterator IT from overlay strings at its current position.
4710 Called from handle_stop. */
4712 static enum prop_handled
4713 handle_overlay_change (it
)
4716 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4717 return HANDLED_RECOMPUTE_PROPS
;
4719 return HANDLED_NORMALLY
;
4723 /* Set up the next overlay string for delivery by IT, if there is an
4724 overlay string to deliver. Called by set_iterator_to_next when the
4725 end of the current overlay string is reached. If there are more
4726 overlay strings to display, IT->string and
4727 IT->current.overlay_string_index are set appropriately here.
4728 Otherwise IT->string is set to nil. */
4731 next_overlay_string (it
)
4734 ++it
->current
.overlay_string_index
;
4735 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4737 /* No more overlay strings. Restore IT's settings to what
4738 they were before overlay strings were processed, and
4739 continue to deliver from current_buffer. */
4741 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4744 || (NILP (it
->string
)
4745 && it
->method
== GET_FROM_BUFFER
4746 && it
->stop_charpos
>= BEGV
4747 && it
->stop_charpos
<= it
->end_charpos
));
4748 it
->current
.overlay_string_index
= -1;
4749 it
->n_overlay_strings
= 0;
4751 /* If we're at the end of the buffer, record that we have
4752 processed the overlay strings there already, so that
4753 next_element_from_buffer doesn't try it again. */
4754 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4755 it
->overlay_strings_at_end_processed_p
= 1;
4759 /* There are more overlay strings to process. If
4760 IT->current.overlay_string_index has advanced to a position
4761 where we must load IT->overlay_strings with more strings, do
4763 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4765 if (it
->current
.overlay_string_index
&& i
== 0)
4766 load_overlay_strings (it
, 0);
4768 /* Initialize IT to deliver display elements from the overlay
4770 it
->string
= it
->overlay_strings
[i
];
4771 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4772 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4773 it
->method
= GET_FROM_STRING
;
4774 it
->stop_charpos
= 0;
4775 if (it
->cmp_it
.stop_pos
>= 0)
4776 it
->cmp_it
.stop_pos
= 0;
4783 /* Compare two overlay_entry structures E1 and E2. Used as a
4784 comparison function for qsort in load_overlay_strings. Overlay
4785 strings for the same position are sorted so that
4787 1. All after-strings come in front of before-strings, except
4788 when they come from the same overlay.
4790 2. Within after-strings, strings are sorted so that overlay strings
4791 from overlays with higher priorities come first.
4793 2. Within before-strings, strings are sorted so that overlay
4794 strings from overlays with higher priorities come last.
4796 Value is analogous to strcmp. */
4800 compare_overlay_entries (e1
, e2
)
4803 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4804 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4807 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4809 /* Let after-strings appear in front of before-strings if
4810 they come from different overlays. */
4811 if (EQ (entry1
->overlay
, entry2
->overlay
))
4812 result
= entry1
->after_string_p
? 1 : -1;
4814 result
= entry1
->after_string_p
? -1 : 1;
4816 else if (entry1
->after_string_p
)
4817 /* After-strings sorted in order of decreasing priority. */
4818 result
= entry2
->priority
- entry1
->priority
;
4820 /* Before-strings sorted in order of increasing priority. */
4821 result
= entry1
->priority
- entry2
->priority
;
4827 /* Load the vector IT->overlay_strings with overlay strings from IT's
4828 current buffer position, or from CHARPOS if that is > 0. Set
4829 IT->n_overlays to the total number of overlay strings found.
4831 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4832 a time. On entry into load_overlay_strings,
4833 IT->current.overlay_string_index gives the number of overlay
4834 strings that have already been loaded by previous calls to this
4837 IT->add_overlay_start contains an additional overlay start
4838 position to consider for taking overlay strings from, if non-zero.
4839 This position comes into play when the overlay has an `invisible'
4840 property, and both before and after-strings. When we've skipped to
4841 the end of the overlay, because of its `invisible' property, we
4842 nevertheless want its before-string to appear.
4843 IT->add_overlay_start will contain the overlay start position
4846 Overlay strings are sorted so that after-string strings come in
4847 front of before-string strings. Within before and after-strings,
4848 strings are sorted by overlay priority. See also function
4849 compare_overlay_entries. */
4852 load_overlay_strings (it
, charpos
)
4856 extern Lisp_Object Qwindow
, Qpriority
;
4857 Lisp_Object overlay
, window
, str
, invisible
;
4858 struct Lisp_Overlay
*ov
;
4861 int n
= 0, i
, j
, invis_p
;
4862 struct overlay_entry
*entries
4863 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4866 charpos
= IT_CHARPOS (*it
);
4868 /* Append the overlay string STRING of overlay OVERLAY to vector
4869 `entries' which has size `size' and currently contains `n'
4870 elements. AFTER_P non-zero means STRING is an after-string of
4872 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4875 Lisp_Object priority; \
4879 int new_size = 2 * size; \
4880 struct overlay_entry *old = entries; \
4882 (struct overlay_entry *) alloca (new_size \
4883 * sizeof *entries); \
4884 bcopy (old, entries, size * sizeof *entries); \
4888 entries[n].string = (STRING); \
4889 entries[n].overlay = (OVERLAY); \
4890 priority = Foverlay_get ((OVERLAY), Qpriority); \
4891 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4892 entries[n].after_string_p = (AFTER_P); \
4897 /* Process overlay before the overlay center. */
4898 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4900 XSETMISC (overlay
, ov
);
4901 xassert (OVERLAYP (overlay
));
4902 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4903 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4908 /* Skip this overlay if it doesn't start or end at IT's current
4910 if (end
!= charpos
&& start
!= charpos
)
4913 /* Skip this overlay if it doesn't apply to IT->w. */
4914 window
= Foverlay_get (overlay
, Qwindow
);
4915 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4918 /* If the text ``under'' the overlay is invisible, both before-
4919 and after-strings from this overlay are visible; start and
4920 end position are indistinguishable. */
4921 invisible
= Foverlay_get (overlay
, Qinvisible
);
4922 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4924 /* If overlay has a non-empty before-string, record it. */
4925 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4926 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4928 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4930 /* If overlay has a non-empty after-string, record it. */
4931 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4932 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4934 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4937 /* Process overlays after the overlay center. */
4938 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4940 XSETMISC (overlay
, ov
);
4941 xassert (OVERLAYP (overlay
));
4942 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4943 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4945 if (start
> charpos
)
4948 /* Skip this overlay if it doesn't start or end at IT's current
4950 if (end
!= charpos
&& start
!= charpos
)
4953 /* Skip this overlay if it doesn't apply to IT->w. */
4954 window
= Foverlay_get (overlay
, Qwindow
);
4955 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4958 /* If the text ``under'' the overlay is invisible, it has a zero
4959 dimension, and both before- and after-strings apply. */
4960 invisible
= Foverlay_get (overlay
, Qinvisible
);
4961 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4963 /* If overlay has a non-empty before-string, record it. */
4964 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4965 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4967 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4969 /* If overlay has a non-empty after-string, record it. */
4970 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4971 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4973 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4976 #undef RECORD_OVERLAY_STRING
4980 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
4982 /* Record the total number of strings to process. */
4983 it
->n_overlay_strings
= n
;
4985 /* IT->current.overlay_string_index is the number of overlay strings
4986 that have already been consumed by IT. Copy some of the
4987 remaining overlay strings to IT->overlay_strings. */
4989 j
= it
->current
.overlay_string_index
;
4990 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
4992 it
->overlay_strings
[i
] = entries
[j
].string
;
4993 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5000 /* Get the first chunk of overlay strings at IT's current buffer
5001 position, or at CHARPOS if that is > 0. Value is non-zero if at
5002 least one overlay string was found. */
5005 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5010 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5011 process. This fills IT->overlay_strings with strings, and sets
5012 IT->n_overlay_strings to the total number of strings to process.
5013 IT->pos.overlay_string_index has to be set temporarily to zero
5014 because load_overlay_strings needs this; it must be set to -1
5015 when no overlay strings are found because a zero value would
5016 indicate a position in the first overlay string. */
5017 it
->current
.overlay_string_index
= 0;
5018 load_overlay_strings (it
, charpos
);
5020 /* If we found overlay strings, set up IT to deliver display
5021 elements from the first one. Otherwise set up IT to deliver
5022 from current_buffer. */
5023 if (it
->n_overlay_strings
)
5025 /* Make sure we know settings in current_buffer, so that we can
5026 restore meaningful values when we're done with the overlay
5029 compute_stop_pos (it
);
5030 xassert (it
->face_id
>= 0);
5032 /* Save IT's settings. They are restored after all overlay
5033 strings have been processed. */
5034 xassert (!compute_stop_p
|| it
->sp
== 0);
5036 /* When called from handle_stop, there might be an empty display
5037 string loaded. In that case, don't bother saving it. */
5038 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5041 /* Set up IT to deliver display elements from the first overlay
5043 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5044 it
->string
= it
->overlay_strings
[0];
5045 it
->from_overlay
= Qnil
;
5046 it
->stop_charpos
= 0;
5047 xassert (STRINGP (it
->string
));
5048 it
->end_charpos
= SCHARS (it
->string
);
5049 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5050 it
->method
= GET_FROM_STRING
;
5054 it
->current
.overlay_string_index
= -1;
5059 get_overlay_strings (it
, charpos
)
5064 it
->method
= GET_FROM_BUFFER
;
5066 (void) get_overlay_strings_1 (it
, charpos
, 1);
5070 /* Value is non-zero if we found at least one overlay string. */
5071 return STRINGP (it
->string
);
5076 /***********************************************************************
5077 Saving and restoring state
5078 ***********************************************************************/
5080 /* Save current settings of IT on IT->stack. Called, for example,
5081 before setting up IT for an overlay string, to be able to restore
5082 IT's settings to what they were after the overlay string has been
5089 struct iterator_stack_entry
*p
;
5091 xassert (it
->sp
< IT_STACK_SIZE
);
5092 p
= it
->stack
+ it
->sp
;
5094 p
->stop_charpos
= it
->stop_charpos
;
5095 p
->cmp_it
= it
->cmp_it
;
5096 xassert (it
->face_id
>= 0);
5097 p
->face_id
= it
->face_id
;
5098 p
->string
= it
->string
;
5099 p
->method
= it
->method
;
5100 p
->from_overlay
= it
->from_overlay
;
5103 case GET_FROM_IMAGE
:
5104 p
->u
.image
.object
= it
->object
;
5105 p
->u
.image
.image_id
= it
->image_id
;
5106 p
->u
.image
.slice
= it
->slice
;
5108 case GET_FROM_STRETCH
:
5109 p
->u
.stretch
.object
= it
->object
;
5112 p
->position
= it
->position
;
5113 p
->current
= it
->current
;
5114 p
->end_charpos
= it
->end_charpos
;
5115 p
->string_nchars
= it
->string_nchars
;
5117 p
->multibyte_p
= it
->multibyte_p
;
5118 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5119 p
->space_width
= it
->space_width
;
5120 p
->font_height
= it
->font_height
;
5121 p
->voffset
= it
->voffset
;
5122 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5123 p
->display_ellipsis_p
= 0;
5124 p
->line_wrap
= it
->line_wrap
;
5129 /* Restore IT's settings from IT->stack. Called, for example, when no
5130 more overlay strings must be processed, and we return to delivering
5131 display elements from a buffer, or when the end of a string from a
5132 `display' property is reached and we return to delivering display
5133 elements from an overlay string, or from a buffer. */
5139 struct iterator_stack_entry
*p
;
5141 xassert (it
->sp
> 0);
5143 p
= it
->stack
+ it
->sp
;
5144 it
->stop_charpos
= p
->stop_charpos
;
5145 it
->cmp_it
= p
->cmp_it
;
5146 it
->face_id
= p
->face_id
;
5147 it
->current
= p
->current
;
5148 it
->position
= p
->position
;
5149 it
->string
= p
->string
;
5150 it
->from_overlay
= p
->from_overlay
;
5151 if (NILP (it
->string
))
5152 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5153 it
->method
= p
->method
;
5156 case GET_FROM_IMAGE
:
5157 it
->image_id
= p
->u
.image
.image_id
;
5158 it
->object
= p
->u
.image
.object
;
5159 it
->slice
= p
->u
.image
.slice
;
5161 case GET_FROM_STRETCH
:
5162 it
->object
= p
->u
.comp
.object
;
5164 case GET_FROM_BUFFER
:
5165 it
->object
= it
->w
->buffer
;
5167 case GET_FROM_STRING
:
5168 it
->object
= it
->string
;
5170 case GET_FROM_DISPLAY_VECTOR
:
5172 it
->method
= GET_FROM_C_STRING
;
5173 else if (STRINGP (it
->string
))
5174 it
->method
= GET_FROM_STRING
;
5177 it
->method
= GET_FROM_BUFFER
;
5178 it
->object
= it
->w
->buffer
;
5181 it
->end_charpos
= p
->end_charpos
;
5182 it
->string_nchars
= p
->string_nchars
;
5184 it
->multibyte_p
= p
->multibyte_p
;
5185 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5186 it
->space_width
= p
->space_width
;
5187 it
->font_height
= p
->font_height
;
5188 it
->voffset
= p
->voffset
;
5189 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5190 it
->line_wrap
= p
->line_wrap
;
5195 /***********************************************************************
5197 ***********************************************************************/
5199 /* Set IT's current position to the previous line start. */
5202 back_to_previous_line_start (it
)
5205 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5206 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5210 /* Move IT to the next line start.
5212 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5213 we skipped over part of the text (as opposed to moving the iterator
5214 continuously over the text). Otherwise, don't change the value
5217 Newlines may come from buffer text, overlay strings, or strings
5218 displayed via the `display' property. That's the reason we can't
5219 simply use find_next_newline_no_quit.
5221 Note that this function may not skip over invisible text that is so
5222 because of text properties and immediately follows a newline. If
5223 it would, function reseat_at_next_visible_line_start, when called
5224 from set_iterator_to_next, would effectively make invisible
5225 characters following a newline part of the wrong glyph row, which
5226 leads to wrong cursor motion. */
5229 forward_to_next_line_start (it
, skipped_p
)
5233 int old_selective
, newline_found_p
, n
;
5234 const int MAX_NEWLINE_DISTANCE
= 500;
5236 /* If already on a newline, just consume it to avoid unintended
5237 skipping over invisible text below. */
5238 if (it
->what
== IT_CHARACTER
5240 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5242 set_iterator_to_next (it
, 0);
5247 /* Don't handle selective display in the following. It's (a)
5248 unnecessary because it's done by the caller, and (b) leads to an
5249 infinite recursion because next_element_from_ellipsis indirectly
5250 calls this function. */
5251 old_selective
= it
->selective
;
5254 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5255 from buffer text. */
5256 for (n
= newline_found_p
= 0;
5257 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5258 n
+= STRINGP (it
->string
) ? 0 : 1)
5260 if (!get_next_display_element (it
))
5262 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5263 set_iterator_to_next (it
, 0);
5266 /* If we didn't find a newline near enough, see if we can use a
5268 if (!newline_found_p
)
5270 int start
= IT_CHARPOS (*it
);
5271 int limit
= find_next_newline_no_quit (start
, 1);
5274 xassert (!STRINGP (it
->string
));
5276 /* If there isn't any `display' property in sight, and no
5277 overlays, we can just use the position of the newline in
5279 if (it
->stop_charpos
>= limit
5280 || ((pos
= Fnext_single_property_change (make_number (start
),
5282 Qnil
, make_number (limit
)),
5284 && next_overlay_change (start
) == ZV
))
5286 IT_CHARPOS (*it
) = limit
;
5287 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5288 *skipped_p
= newline_found_p
= 1;
5292 while (get_next_display_element (it
)
5293 && !newline_found_p
)
5295 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5296 set_iterator_to_next (it
, 0);
5301 it
->selective
= old_selective
;
5302 return newline_found_p
;
5306 /* Set IT's current position to the previous visible line start. Skip
5307 invisible text that is so either due to text properties or due to
5308 selective display. Caution: this does not change IT->current_x and
5312 back_to_previous_visible_line_start (it
)
5315 while (IT_CHARPOS (*it
) > BEGV
)
5317 back_to_previous_line_start (it
);
5319 if (IT_CHARPOS (*it
) <= BEGV
)
5322 /* If selective > 0, then lines indented more than that values
5324 if (it
->selective
> 0
5325 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5326 (double) it
->selective
)) /* iftc */
5329 /* Check the newline before point for invisibility. */
5332 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5333 Qinvisible
, it
->window
);
5334 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5338 if (IT_CHARPOS (*it
) <= BEGV
)
5345 Lisp_Object val
, overlay
;
5347 /* If newline is part of a composition, continue from start of composition */
5348 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5349 && beg
< IT_CHARPOS (*it
))
5352 /* If newline is replaced by a display property, find start of overlay
5353 or interval and continue search from that point. */
5355 pos
= --IT_CHARPOS (it2
);
5358 it2
.string_from_display_prop_p
= 0;
5359 if (handle_display_prop (&it2
) == HANDLED_RETURN
5360 && !NILP (val
= get_char_property_and_overlay
5361 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5362 && (OVERLAYP (overlay
)
5363 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5364 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5367 /* Newline is not replaced by anything -- so we are done. */
5373 IT_CHARPOS (*it
) = beg
;
5374 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5378 it
->continuation_lines_width
= 0;
5380 xassert (IT_CHARPOS (*it
) >= BEGV
);
5381 xassert (IT_CHARPOS (*it
) == BEGV
5382 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5387 /* Reseat iterator IT at the previous visible line start. Skip
5388 invisible text that is so either due to text properties or due to
5389 selective display. At the end, update IT's overlay information,
5390 face information etc. */
5393 reseat_at_previous_visible_line_start (it
)
5396 back_to_previous_visible_line_start (it
);
5397 reseat (it
, it
->current
.pos
, 1);
5402 /* Reseat iterator IT on the next visible line start in the current
5403 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5404 preceding the line start. Skip over invisible text that is so
5405 because of selective display. Compute faces, overlays etc at the
5406 new position. Note that this function does not skip over text that
5407 is invisible because of text properties. */
5410 reseat_at_next_visible_line_start (it
, on_newline_p
)
5414 int newline_found_p
, skipped_p
= 0;
5416 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5418 /* Skip over lines that are invisible because they are indented
5419 more than the value of IT->selective. */
5420 if (it
->selective
> 0)
5421 while (IT_CHARPOS (*it
) < ZV
5422 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5423 (double) it
->selective
)) /* iftc */
5425 xassert (IT_BYTEPOS (*it
) == BEGV
5426 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5427 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5430 /* Position on the newline if that's what's requested. */
5431 if (on_newline_p
&& newline_found_p
)
5433 if (STRINGP (it
->string
))
5435 if (IT_STRING_CHARPOS (*it
) > 0)
5437 --IT_STRING_CHARPOS (*it
);
5438 --IT_STRING_BYTEPOS (*it
);
5441 else if (IT_CHARPOS (*it
) > BEGV
)
5445 reseat (it
, it
->current
.pos
, 0);
5449 reseat (it
, it
->current
.pos
, 0);
5456 /***********************************************************************
5457 Changing an iterator's position
5458 ***********************************************************************/
5460 /* Change IT's current position to POS in current_buffer. If FORCE_P
5461 is non-zero, always check for text properties at the new position.
5462 Otherwise, text properties are only looked up if POS >=
5463 IT->check_charpos of a property. */
5466 reseat (it
, pos
, force_p
)
5468 struct text_pos pos
;
5471 int original_pos
= IT_CHARPOS (*it
);
5473 reseat_1 (it
, pos
, 0);
5475 /* Determine where to check text properties. Avoid doing it
5476 where possible because text property lookup is very expensive. */
5478 || CHARPOS (pos
) > it
->stop_charpos
5479 || CHARPOS (pos
) < original_pos
)
5486 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5487 IT->stop_pos to POS, also. */
5490 reseat_1 (it
, pos
, set_stop_p
)
5492 struct text_pos pos
;
5495 /* Don't call this function when scanning a C string. */
5496 xassert (it
->s
== NULL
);
5498 /* POS must be a reasonable value. */
5499 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5501 it
->current
.pos
= it
->position
= pos
;
5502 it
->end_charpos
= ZV
;
5504 it
->current
.dpvec_index
= -1;
5505 it
->current
.overlay_string_index
= -1;
5506 IT_STRING_CHARPOS (*it
) = -1;
5507 IT_STRING_BYTEPOS (*it
) = -1;
5509 it
->string_from_display_prop_p
= 0;
5510 it
->method
= GET_FROM_BUFFER
;
5511 it
->object
= it
->w
->buffer
;
5512 it
->area
= TEXT_AREA
;
5513 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5515 it
->string_from_display_prop_p
= 0;
5516 it
->face_before_selective_p
= 0;
5519 it
->stop_charpos
= CHARPOS (pos
);
5523 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5524 If S is non-null, it is a C string to iterate over. Otherwise,
5525 STRING gives a Lisp string to iterate over.
5527 If PRECISION > 0, don't return more then PRECISION number of
5528 characters from the string.
5530 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5531 characters have been returned. FIELD_WIDTH < 0 means an infinite
5534 MULTIBYTE = 0 means disable processing of multibyte characters,
5535 MULTIBYTE > 0 means enable it,
5536 MULTIBYTE < 0 means use IT->multibyte_p.
5538 IT must be initialized via a prior call to init_iterator before
5539 calling this function. */
5542 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5547 int precision
, field_width
, multibyte
;
5549 /* No region in strings. */
5550 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5552 /* No text property checks performed by default, but see below. */
5553 it
->stop_charpos
= -1;
5555 /* Set iterator position and end position. */
5556 bzero (&it
->current
, sizeof it
->current
);
5557 it
->current
.overlay_string_index
= -1;
5558 it
->current
.dpvec_index
= -1;
5559 xassert (charpos
>= 0);
5561 /* If STRING is specified, use its multibyteness, otherwise use the
5562 setting of MULTIBYTE, if specified. */
5564 it
->multibyte_p
= multibyte
> 0;
5568 xassert (STRINGP (string
));
5569 it
->string
= string
;
5571 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5572 it
->method
= GET_FROM_STRING
;
5573 it
->current
.string_pos
= string_pos (charpos
, string
);
5580 /* Note that we use IT->current.pos, not it->current.string_pos,
5581 for displaying C strings. */
5582 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5583 if (it
->multibyte_p
)
5585 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5586 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5590 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5591 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5594 it
->method
= GET_FROM_C_STRING
;
5597 /* PRECISION > 0 means don't return more than PRECISION characters
5599 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5600 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5602 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5603 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5604 FIELD_WIDTH < 0 means infinite field width. This is useful for
5605 padding with `-' at the end of a mode line. */
5606 if (field_width
< 0)
5607 field_width
= INFINITY
;
5608 if (field_width
> it
->end_charpos
- charpos
)
5609 it
->end_charpos
= charpos
+ field_width
;
5611 /* Use the standard display table for displaying strings. */
5612 if (DISP_TABLE_P (Vstandard_display_table
))
5613 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5615 it
->stop_charpos
= charpos
;
5621 /***********************************************************************
5623 ***********************************************************************/
5625 /* Map enum it_method value to corresponding next_element_from_* function. */
5627 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5629 next_element_from_buffer
,
5630 next_element_from_display_vector
,
5631 next_element_from_string
,
5632 next_element_from_c_string
,
5633 next_element_from_image
,
5634 next_element_from_stretch
5637 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5640 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5641 (possibly with the following characters). */
5643 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS) \
5644 ((IT)->cmp_it.id >= 0 \
5645 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5646 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5647 (IT)->end_charpos, (IT)->w, \
5648 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5652 /* Load IT's display element fields with information about the next
5653 display element from the current position of IT. Value is zero if
5654 end of buffer (or C string) is reached. */
5656 static struct frame
*last_escape_glyph_frame
= NULL
;
5657 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5658 static int last_escape_glyph_merged_face_id
= 0;
5661 get_next_display_element (it
)
5664 /* Non-zero means that we found a display element. Zero means that
5665 we hit the end of what we iterate over. Performance note: the
5666 function pointer `method' used here turns out to be faster than
5667 using a sequence of if-statements. */
5671 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5673 if (it
->what
== IT_CHARACTER
)
5675 /* Map via display table or translate control characters.
5676 IT->c, IT->len etc. have been set to the next character by
5677 the function call above. If we have a display table, and it
5678 contains an entry for IT->c, translate it. Don't do this if
5679 IT->c itself comes from a display table, otherwise we could
5680 end up in an infinite recursion. (An alternative could be to
5681 count the recursion depth of this function and signal an
5682 error when a certain maximum depth is reached.) Is it worth
5684 if (success_p
&& it
->dpvec
== NULL
)
5687 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5688 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5689 nbsp_or_shy
= char_is_other
;
5690 int decoded
= it
->c
;
5693 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5696 struct Lisp_Vector
*v
= XVECTOR (dv
);
5698 /* Return the first character from the display table
5699 entry, if not empty. If empty, don't display the
5700 current character. */
5703 it
->dpvec_char_len
= it
->len
;
5704 it
->dpvec
= v
->contents
;
5705 it
->dpend
= v
->contents
+ v
->size
;
5706 it
->current
.dpvec_index
= 0;
5707 it
->dpvec_face_id
= -1;
5708 it
->saved_face_id
= it
->face_id
;
5709 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5714 set_iterator_to_next (it
, 0);
5719 if (unibyte_display_via_language_environment
5720 && !ASCII_CHAR_P (it
->c
))
5721 decoded
= DECODE_CHAR (unibyte
, it
->c
);
5723 if (it
->c
>= 0x80 && ! NILP (Vnobreak_char_display
))
5725 if (it
->multibyte_p
)
5726 nbsp_or_shy
= (it
->c
== 0xA0 ? char_is_nbsp
5727 : it
->c
== 0xAD ? char_is_soft_hyphen
5729 else if (unibyte_display_via_language_environment
)
5730 nbsp_or_shy
= (decoded
== 0xA0 ? char_is_nbsp
5731 : decoded
== 0xAD ? char_is_soft_hyphen
5735 /* Translate control characters into `\003' or `^C' form.
5736 Control characters coming from a display table entry are
5737 currently not translated because we use IT->dpvec to hold
5738 the translation. This could easily be changed but I
5739 don't believe that it is worth doing.
5741 If it->multibyte_p is nonzero, non-printable non-ASCII
5742 characters are also translated to octal form.
5744 If it->multibyte_p is zero, eight-bit characters that
5745 don't have corresponding multibyte char code are also
5746 translated to octal form. */
5748 ? (it
->area
!= TEXT_AREA
5749 /* In mode line, treat \n, \t like other crl chars. */
5752 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5753 || (it
->c
!= '\n' && it
->c
!= '\t'))
5756 ? ! CHAR_PRINTABLE_P (it
->c
)
5757 : (! unibyte_display_via_language_environment
5759 : (decoded
>= 0x80 && decoded
< 0xA0))))))
5761 /* IT->c is a control character which must be displayed
5762 either as '\003' or as `^C' where the '\\' and '^'
5763 can be defined in the display table. Fill
5764 IT->ctl_chars with glyphs for what we have to
5765 display. Then, set IT->dpvec to these glyphs. */
5768 int face_id
, lface_id
= 0 ;
5771 /* Handle control characters with ^. */
5773 if (it
->c
< 128 && it
->ctl_arrow_p
)
5777 g
= '^'; /* default glyph for Control */
5778 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5780 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5781 && GLYPH_CODE_CHAR_VALID_P (gc
))
5783 g
= GLYPH_CODE_CHAR (gc
);
5784 lface_id
= GLYPH_CODE_FACE (gc
);
5788 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5790 else if (it
->f
== last_escape_glyph_frame
5791 && it
->face_id
== last_escape_glyph_face_id
)
5793 face_id
= last_escape_glyph_merged_face_id
;
5797 /* Merge the escape-glyph face into the current face. */
5798 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5800 last_escape_glyph_frame
= it
->f
;
5801 last_escape_glyph_face_id
= it
->face_id
;
5802 last_escape_glyph_merged_face_id
= face_id
;
5805 XSETINT (it
->ctl_chars
[0], g
);
5806 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5808 goto display_control
;
5811 /* Handle non-break space in the mode where it only gets
5814 if (EQ (Vnobreak_char_display
, Qt
)
5815 && nbsp_or_shy
== char_is_nbsp
)
5817 /* Merge the no-break-space face into the current face. */
5818 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5822 XSETINT (it
->ctl_chars
[0], ' ');
5824 goto display_control
;
5827 /* Handle sequences that start with the "escape glyph". */
5829 /* the default escape glyph is \. */
5830 escape_glyph
= '\\';
5833 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5834 && GLYPH_CODE_CHAR_VALID_P (gc
))
5836 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5837 lface_id
= GLYPH_CODE_FACE (gc
);
5841 /* The display table specified a face.
5842 Merge it into face_id and also into escape_glyph. */
5843 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5846 else if (it
->f
== last_escape_glyph_frame
5847 && it
->face_id
== last_escape_glyph_face_id
)
5849 face_id
= last_escape_glyph_merged_face_id
;
5853 /* Merge the escape-glyph face into the current face. */
5854 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5856 last_escape_glyph_frame
= it
->f
;
5857 last_escape_glyph_face_id
= it
->face_id
;
5858 last_escape_glyph_merged_face_id
= face_id
;
5861 /* Handle soft hyphens in the mode where they only get
5864 if (EQ (Vnobreak_char_display
, Qt
)
5865 && nbsp_or_shy
== char_is_soft_hyphen
)
5868 XSETINT (it
->ctl_chars
[0], '-');
5870 goto display_control
;
5873 /* Handle non-break space and soft hyphen
5874 with the escape glyph. */
5878 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5879 it
->c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5880 XSETINT (it
->ctl_chars
[1], it
->c
);
5882 goto display_control
;
5886 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5890 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5891 if (CHAR_BYTE8_P (it
->c
))
5893 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5896 else if (it
->c
< 256)
5903 /* It's an invalid character, which shouldn't
5904 happen actually, but due to bugs it may
5905 happen. Let's print the char as is, there's
5906 not much meaningful we can do with it. */
5908 str
[1] = it
->c
>> 8;
5909 str
[2] = it
->c
>> 16;
5910 str
[3] = it
->c
>> 24;
5914 for (i
= 0; i
< len
; i
++)
5917 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
5918 /* Insert three more glyphs into IT->ctl_chars for
5919 the octal display of the character. */
5920 g
= ((str
[i
] >> 6) & 7) + '0';
5921 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
5922 g
= ((str
[i
] >> 3) & 7) + '0';
5923 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
5924 g
= (str
[i
] & 7) + '0';
5925 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
5931 /* Set up IT->dpvec and return first character from it. */
5932 it
->dpvec_char_len
= it
->len
;
5933 it
->dpvec
= it
->ctl_chars
;
5934 it
->dpend
= it
->dpvec
+ ctl_len
;
5935 it
->current
.dpvec_index
= 0;
5936 it
->dpvec_face_id
= face_id
;
5937 it
->saved_face_id
= it
->face_id
;
5938 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5945 #ifdef HAVE_WINDOW_SYSTEM
5946 /* Adjust face id for a multibyte character. There are no multibyte
5947 character in unibyte text. */
5948 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
5951 && FRAME_WINDOW_P (it
->f
))
5953 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
5955 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
5957 /* Automatic composition with glyph-string. */
5958 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
5960 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
5964 int pos
= (it
->s
? -1
5965 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
5966 : IT_CHARPOS (*it
));
5968 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
5973 /* Is this character the last one of a run of characters with
5974 box? If yes, set IT->end_of_box_run_p to 1. */
5978 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
5980 int face_id
= underlying_face_id (it
);
5981 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
5985 if (face
->box
== FACE_NO_BOX
)
5987 /* If the box comes from face properties in a
5988 display string, check faces in that string. */
5989 int string_face_id
= face_after_it_pos (it
);
5990 it
->end_of_box_run_p
5991 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
5994 /* Otherwise, the box comes from the underlying face.
5995 If this is the last string character displayed, check
5996 the next buffer location. */
5997 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
5998 && (it
->current
.overlay_string_index
5999 == it
->n_overlay_strings
- 1))
6003 struct text_pos pos
= it
->current
.pos
;
6004 INC_TEXT_POS (pos
, it
->multibyte_p
);
6006 next_face_id
= face_at_buffer_position
6007 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6008 it
->region_end_charpos
, &ignore
,
6009 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6011 it
->end_of_box_run_p
6012 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6019 int face_id
= face_after_it_pos (it
);
6020 it
->end_of_box_run_p
6021 = (face_id
!= it
->face_id
6022 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6026 /* Value is 0 if end of buffer or string reached. */
6031 /* Move IT to the next display element.
6033 RESEAT_P non-zero means if called on a newline in buffer text,
6034 skip to the next visible line start.
6036 Functions get_next_display_element and set_iterator_to_next are
6037 separate because I find this arrangement easier to handle than a
6038 get_next_display_element function that also increments IT's
6039 position. The way it is we can first look at an iterator's current
6040 display element, decide whether it fits on a line, and if it does,
6041 increment the iterator position. The other way around we probably
6042 would either need a flag indicating whether the iterator has to be
6043 incremented the next time, or we would have to implement a
6044 decrement position function which would not be easy to write. */
6047 set_iterator_to_next (it
, reseat_p
)
6051 /* Reset flags indicating start and end of a sequence of characters
6052 with box. Reset them at the start of this function because
6053 moving the iterator to a new position might set them. */
6054 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6058 case GET_FROM_BUFFER
:
6059 /* The current display element of IT is a character from
6060 current_buffer. Advance in the buffer, and maybe skip over
6061 invisible lines that are so because of selective display. */
6062 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6063 reseat_at_next_visible_line_start (it
, 0);
6064 else if (it
->cmp_it
.id
>= 0)
6066 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6067 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6068 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6069 it
->cmp_it
.from
= it
->cmp_it
.to
;
6073 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6074 IT_BYTEPOS (*it
), it
->stop_charpos
,
6080 xassert (it
->len
!= 0);
6081 IT_BYTEPOS (*it
) += it
->len
;
6082 IT_CHARPOS (*it
) += 1;
6083 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6087 case GET_FROM_C_STRING
:
6088 /* Current display element of IT is from a C string. */
6089 IT_BYTEPOS (*it
) += it
->len
;
6090 IT_CHARPOS (*it
) += 1;
6093 case GET_FROM_DISPLAY_VECTOR
:
6094 /* Current display element of IT is from a display table entry.
6095 Advance in the display table definition. Reset it to null if
6096 end reached, and continue with characters from buffers/
6098 ++it
->current
.dpvec_index
;
6100 /* Restore face of the iterator to what they were before the
6101 display vector entry (these entries may contain faces). */
6102 it
->face_id
= it
->saved_face_id
;
6104 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6106 int recheck_faces
= it
->ellipsis_p
;
6109 it
->method
= GET_FROM_C_STRING
;
6110 else if (STRINGP (it
->string
))
6111 it
->method
= GET_FROM_STRING
;
6114 it
->method
= GET_FROM_BUFFER
;
6115 it
->object
= it
->w
->buffer
;
6119 it
->current
.dpvec_index
= -1;
6121 /* Skip over characters which were displayed via IT->dpvec. */
6122 if (it
->dpvec_char_len
< 0)
6123 reseat_at_next_visible_line_start (it
, 1);
6124 else if (it
->dpvec_char_len
> 0)
6126 if (it
->method
== GET_FROM_STRING
6127 && it
->n_overlay_strings
> 0)
6128 it
->ignore_overlay_strings_at_pos_p
= 1;
6129 it
->len
= it
->dpvec_char_len
;
6130 set_iterator_to_next (it
, reseat_p
);
6133 /* Maybe recheck faces after display vector */
6135 it
->stop_charpos
= IT_CHARPOS (*it
);
6139 case GET_FROM_STRING
:
6140 /* Current display element is a character from a Lisp string. */
6141 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6142 if (it
->cmp_it
.id
>= 0)
6144 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6145 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6146 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6147 it
->cmp_it
.from
= it
->cmp_it
.to
;
6151 composition_compute_stop_pos (&it
->cmp_it
,
6152 IT_STRING_CHARPOS (*it
),
6153 IT_STRING_BYTEPOS (*it
),
6154 it
->stop_charpos
, it
->string
);
6159 IT_STRING_BYTEPOS (*it
) += it
->len
;
6160 IT_STRING_CHARPOS (*it
) += 1;
6163 consider_string_end
:
6165 if (it
->current
.overlay_string_index
>= 0)
6167 /* IT->string is an overlay string. Advance to the
6168 next, if there is one. */
6169 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6172 next_overlay_string (it
);
6174 setup_for_ellipsis (it
, 0);
6179 /* IT->string is not an overlay string. If we reached
6180 its end, and there is something on IT->stack, proceed
6181 with what is on the stack. This can be either another
6182 string, this time an overlay string, or a buffer. */
6183 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6187 if (it
->method
== GET_FROM_STRING
)
6188 goto consider_string_end
;
6193 case GET_FROM_IMAGE
:
6194 case GET_FROM_STRETCH
:
6195 /* The position etc with which we have to proceed are on
6196 the stack. The position may be at the end of a string,
6197 if the `display' property takes up the whole string. */
6198 xassert (it
->sp
> 0);
6200 if (it
->method
== GET_FROM_STRING
)
6201 goto consider_string_end
;
6205 /* There are no other methods defined, so this should be a bug. */
6209 xassert (it
->method
!= GET_FROM_STRING
6210 || (STRINGP (it
->string
)
6211 && IT_STRING_CHARPOS (*it
) >= 0));
6214 /* Load IT's display element fields with information about the next
6215 display element which comes from a display table entry or from the
6216 result of translating a control character to one of the forms `^C'
6219 IT->dpvec holds the glyphs to return as characters.
6220 IT->saved_face_id holds the face id before the display vector--
6221 it is restored into IT->face_idin set_iterator_to_next. */
6224 next_element_from_display_vector (it
)
6230 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6232 it
->face_id
= it
->saved_face_id
;
6234 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6235 That seemed totally bogus - so I changed it... */
6236 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6238 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6240 it
->c
= GLYPH_CODE_CHAR (gc
);
6241 it
->len
= CHAR_BYTES (it
->c
);
6243 /* The entry may contain a face id to use. Such a face id is
6244 the id of a Lisp face, not a realized face. A face id of
6245 zero means no face is specified. */
6246 if (it
->dpvec_face_id
>= 0)
6247 it
->face_id
= it
->dpvec_face_id
;
6250 int lface_id
= GLYPH_CODE_FACE (gc
);
6252 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6257 /* Display table entry is invalid. Return a space. */
6258 it
->c
= ' ', it
->len
= 1;
6260 /* Don't change position and object of the iterator here. They are
6261 still the values of the character that had this display table
6262 entry or was translated, and that's what we want. */
6263 it
->what
= IT_CHARACTER
;
6268 /* Load IT with the next display element from Lisp string IT->string.
6269 IT->current.string_pos is the current position within the string.
6270 If IT->current.overlay_string_index >= 0, the Lisp string is an
6274 next_element_from_string (it
)
6277 struct text_pos position
;
6279 xassert (STRINGP (it
->string
));
6280 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6281 position
= it
->current
.string_pos
;
6283 /* Time to check for invisible text? */
6284 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6285 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6289 /* Since a handler may have changed IT->method, we must
6291 return GET_NEXT_DISPLAY_ELEMENT (it
);
6294 if (it
->current
.overlay_string_index
>= 0)
6296 /* Get the next character from an overlay string. In overlay
6297 strings, There is no field width or padding with spaces to
6299 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6304 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6305 IT_STRING_BYTEPOS (*it
))
6306 && next_element_from_composition (it
))
6310 else if (STRING_MULTIBYTE (it
->string
))
6312 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6313 const unsigned char *s
= (SDATA (it
->string
)
6314 + IT_STRING_BYTEPOS (*it
));
6315 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6319 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6325 /* Get the next character from a Lisp string that is not an
6326 overlay string. Such strings come from the mode line, for
6327 example. We may have to pad with spaces, or truncate the
6328 string. See also next_element_from_c_string. */
6329 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6334 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6336 /* Pad with spaces. */
6337 it
->c
= ' ', it
->len
= 1;
6338 CHARPOS (position
) = BYTEPOS (position
) = -1;
6340 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6341 IT_STRING_BYTEPOS (*it
))
6342 && next_element_from_composition (it
))
6346 else if (STRING_MULTIBYTE (it
->string
))
6348 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6349 const unsigned char *s
= (SDATA (it
->string
)
6350 + IT_STRING_BYTEPOS (*it
));
6351 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6355 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6360 /* Record what we have and where it came from. */
6361 it
->what
= IT_CHARACTER
;
6362 it
->object
= it
->string
;
6363 it
->position
= position
;
6368 /* Load IT with next display element from C string IT->s.
6369 IT->string_nchars is the maximum number of characters to return
6370 from the string. IT->end_charpos may be greater than
6371 IT->string_nchars when this function is called, in which case we
6372 may have to return padding spaces. Value is zero if end of string
6373 reached, including padding spaces. */
6376 next_element_from_c_string (it
)
6382 it
->what
= IT_CHARACTER
;
6383 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6386 /* IT's position can be greater IT->string_nchars in case a field
6387 width or precision has been specified when the iterator was
6389 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6391 /* End of the game. */
6395 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6397 /* Pad with spaces. */
6398 it
->c
= ' ', it
->len
= 1;
6399 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6401 else if (it
->multibyte_p
)
6403 /* Implementation note: The calls to strlen apparently aren't a
6404 performance problem because there is no noticeable performance
6405 difference between Emacs running in unibyte or multibyte mode. */
6406 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6407 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6411 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6417 /* Set up IT to return characters from an ellipsis, if appropriate.
6418 The definition of the ellipsis glyphs may come from a display table
6419 entry. This function Fills IT with the first glyph from the
6420 ellipsis if an ellipsis is to be displayed. */
6423 next_element_from_ellipsis (it
)
6426 if (it
->selective_display_ellipsis_p
)
6427 setup_for_ellipsis (it
, it
->len
);
6430 /* The face at the current position may be different from the
6431 face we find after the invisible text. Remember what it
6432 was in IT->saved_face_id, and signal that it's there by
6433 setting face_before_selective_p. */
6434 it
->saved_face_id
= it
->face_id
;
6435 it
->method
= GET_FROM_BUFFER
;
6436 it
->object
= it
->w
->buffer
;
6437 reseat_at_next_visible_line_start (it
, 1);
6438 it
->face_before_selective_p
= 1;
6441 return GET_NEXT_DISPLAY_ELEMENT (it
);
6445 /* Deliver an image display element. The iterator IT is already
6446 filled with image information (done in handle_display_prop). Value
6451 next_element_from_image (it
)
6454 it
->what
= IT_IMAGE
;
6459 /* Fill iterator IT with next display element from a stretch glyph
6460 property. IT->object is the value of the text property. Value is
6464 next_element_from_stretch (it
)
6467 it
->what
= IT_STRETCH
;
6472 /* Load IT with the next display element from current_buffer. Value
6473 is zero if end of buffer reached. IT->stop_charpos is the next
6474 position at which to stop and check for text properties or buffer
6478 next_element_from_buffer (it
)
6483 xassert (IT_CHARPOS (*it
) >= BEGV
);
6485 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6487 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6489 int overlay_strings_follow_p
;
6491 /* End of the game, except when overlay strings follow that
6492 haven't been returned yet. */
6493 if (it
->overlay_strings_at_end_processed_p
)
6494 overlay_strings_follow_p
= 0;
6497 it
->overlay_strings_at_end_processed_p
= 1;
6498 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6501 if (overlay_strings_follow_p
)
6502 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6506 it
->position
= it
->current
.pos
;
6513 return GET_NEXT_DISPLAY_ELEMENT (it
);
6518 /* No face changes, overlays etc. in sight, so just return a
6519 character from current_buffer. */
6522 /* Maybe run the redisplay end trigger hook. Performance note:
6523 This doesn't seem to cost measurable time. */
6524 if (it
->redisplay_end_trigger_charpos
6526 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6527 run_redisplay_end_trigger_hook (it
);
6529 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
))
6530 && next_element_from_composition (it
))
6535 /* Get the next character, maybe multibyte. */
6536 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6537 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6538 it
->c
= STRING_CHAR_AND_LENGTH (p
, 0, it
->len
);
6540 it
->c
= *p
, it
->len
= 1;
6542 /* Record what we have and where it came from. */
6543 it
->what
= IT_CHARACTER
;
6544 it
->object
= it
->w
->buffer
;
6545 it
->position
= it
->current
.pos
;
6547 /* Normally we return the character found above, except when we
6548 really want to return an ellipsis for selective display. */
6553 /* A value of selective > 0 means hide lines indented more
6554 than that number of columns. */
6555 if (it
->selective
> 0
6556 && IT_CHARPOS (*it
) + 1 < ZV
6557 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6558 IT_BYTEPOS (*it
) + 1,
6559 (double) it
->selective
)) /* iftc */
6561 success_p
= next_element_from_ellipsis (it
);
6562 it
->dpvec_char_len
= -1;
6565 else if (it
->c
== '\r' && it
->selective
== -1)
6567 /* A value of selective == -1 means that everything from the
6568 CR to the end of the line is invisible, with maybe an
6569 ellipsis displayed for it. */
6570 success_p
= next_element_from_ellipsis (it
);
6571 it
->dpvec_char_len
= -1;
6576 /* Value is zero if end of buffer reached. */
6577 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6582 /* Run the redisplay end trigger hook for IT. */
6585 run_redisplay_end_trigger_hook (it
)
6588 Lisp_Object args
[3];
6590 /* IT->glyph_row should be non-null, i.e. we should be actually
6591 displaying something, or otherwise we should not run the hook. */
6592 xassert (it
->glyph_row
);
6594 /* Set up hook arguments. */
6595 args
[0] = Qredisplay_end_trigger_functions
;
6596 args
[1] = it
->window
;
6597 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6598 it
->redisplay_end_trigger_charpos
= 0;
6600 /* Since we are *trying* to run these functions, don't try to run
6601 them again, even if they get an error. */
6602 it
->w
->redisplay_end_trigger
= Qnil
;
6603 Frun_hook_with_args (3, args
);
6605 /* Notice if it changed the face of the character we are on. */
6606 handle_face_prop (it
);
6610 /* Deliver a composition display element. Unlike the other
6611 next_element_from_XXX, this function is not registered in the array
6612 get_next_element[]. It is called from next_element_from_buffer and
6613 next_element_from_string when necessary. */
6616 next_element_from_composition (it
)
6619 it
->what
= IT_COMPOSITION
;
6620 it
->len
= it
->cmp_it
.nbytes
;
6621 if (STRINGP (it
->string
))
6625 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6626 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6629 it
->position
= it
->current
.string_pos
;
6630 it
->object
= it
->string
;
6631 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6632 IT_STRING_BYTEPOS (*it
), it
->string
);
6638 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6639 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6642 it
->position
= it
->current
.pos
;
6643 it
->object
= it
->w
->buffer
;
6644 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6645 IT_BYTEPOS (*it
), Qnil
);
6652 /***********************************************************************
6653 Moving an iterator without producing glyphs
6654 ***********************************************************************/
6656 /* Check if iterator is at a position corresponding to a valid buffer
6657 position after some move_it_ call. */
6659 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6660 ((it)->method == GET_FROM_STRING \
6661 ? IT_STRING_CHARPOS (*it) == 0 \
6665 /* Move iterator IT to a specified buffer or X position within one
6666 line on the display without producing glyphs.
6668 OP should be a bit mask including some or all of these bits:
6669 MOVE_TO_X: Stop on reaching x-position TO_X.
6670 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6671 Regardless of OP's value, stop in reaching the end of the display line.
6673 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6674 This means, in particular, that TO_X includes window's horizontal
6677 The return value has several possible values that
6678 say what condition caused the scan to stop:
6680 MOVE_POS_MATCH_OR_ZV
6681 - when TO_POS or ZV was reached.
6684 -when TO_X was reached before TO_POS or ZV were reached.
6687 - when we reached the end of the display area and the line must
6691 - when we reached the end of the display area and the line is
6695 - when we stopped at a line end, i.e. a newline or a CR and selective
6698 static enum move_it_result
6699 move_it_in_display_line_to (struct it
*it
,
6700 EMACS_INT to_charpos
, int to_x
,
6701 enum move_operation_enum op
)
6703 enum move_it_result result
= MOVE_UNDEFINED
;
6704 struct glyph_row
*saved_glyph_row
;
6705 struct it wrap_it
, atpos_it
, atx_it
;
6708 /* Don't produce glyphs in produce_glyphs. */
6709 saved_glyph_row
= it
->glyph_row
;
6710 it
->glyph_row
= NULL
;
6712 /* Use wrap_it to save a copy of IT wherever a word wrap could
6713 occur. Use atpos_it to save a copy of IT at the desired buffer
6714 position, if found, so that we can scan ahead and check if the
6715 word later overshoots the window edge. Use atx_it similarly, for
6721 #define BUFFER_POS_REACHED_P() \
6722 ((op & MOVE_TO_POS) != 0 \
6723 && BUFFERP (it->object) \
6724 && IT_CHARPOS (*it) >= to_charpos \
6725 && (it->method == GET_FROM_BUFFER \
6726 || (it->method == GET_FROM_DISPLAY_VECTOR \
6727 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6729 /* If there's a line-/wrap-prefix, handle it. */
6730 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6731 && it
->current_y
< it
->last_visible_y
)
6732 handle_line_prefix (it
);
6736 int x
, i
, ascent
= 0, descent
= 0;
6738 /* Utility macro to reset an iterator with x, ascent, and descent. */
6739 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6740 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6741 (IT)->max_descent = descent)
6743 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6745 if ((op
& MOVE_TO_POS
) != 0
6746 && BUFFERP (it
->object
)
6747 && it
->method
== GET_FROM_BUFFER
6748 && IT_CHARPOS (*it
) > to_charpos
)
6750 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6752 result
= MOVE_POS_MATCH_OR_ZV
;
6755 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6756 /* If wrap_it is valid, the current position might be in a
6757 word that is wrapped. So, save the iterator in
6758 atpos_it and continue to see if wrapping happens. */
6762 /* Stop when ZV reached.
6763 We used to stop here when TO_CHARPOS reached as well, but that is
6764 too soon if this glyph does not fit on this line. So we handle it
6765 explicitly below. */
6766 if (!get_next_display_element (it
))
6768 result
= MOVE_POS_MATCH_OR_ZV
;
6772 if (it
->line_wrap
== TRUNCATE
)
6774 if (BUFFER_POS_REACHED_P ())
6776 result
= MOVE_POS_MATCH_OR_ZV
;
6782 if (it
->line_wrap
== WORD_WRAP
)
6784 if (IT_DISPLAYING_WHITESPACE (it
))
6788 /* We have reached a glyph that follows one or more
6789 whitespace characters. If the position is
6790 already found, we are done. */
6791 if (atpos_it
.sp
>= 0)
6794 result
= MOVE_POS_MATCH_OR_ZV
;
6800 result
= MOVE_X_REACHED
;
6803 /* Otherwise, we can wrap here. */
6810 /* Remember the line height for the current line, in case
6811 the next element doesn't fit on the line. */
6812 ascent
= it
->max_ascent
;
6813 descent
= it
->max_descent
;
6815 /* The call to produce_glyphs will get the metrics of the
6816 display element IT is loaded with. Record the x-position
6817 before this display element, in case it doesn't fit on the
6821 PRODUCE_GLYPHS (it
);
6823 if (it
->area
!= TEXT_AREA
)
6825 set_iterator_to_next (it
, 1);
6829 /* The number of glyphs we get back in IT->nglyphs will normally
6830 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6831 character on a terminal frame, or (iii) a line end. For the
6832 second case, IT->nglyphs - 1 padding glyphs will be present.
6833 (On X frames, there is only one glyph produced for a
6834 composite character.)
6836 The behavior implemented below means, for continuation lines,
6837 that as many spaces of a TAB as fit on the current line are
6838 displayed there. For terminal frames, as many glyphs of a
6839 multi-glyph character are displayed in the current line, too.
6840 This is what the old redisplay code did, and we keep it that
6841 way. Under X, the whole shape of a complex character must
6842 fit on the line or it will be completely displayed in the
6845 Note that both for tabs and padding glyphs, all glyphs have
6849 /* More than one glyph or glyph doesn't fit on line. All
6850 glyphs have the same width. */
6851 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6853 int x_before_this_char
= x
;
6854 int hpos_before_this_char
= it
->hpos
;
6856 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6858 new_x
= x
+ single_glyph_width
;
6860 /* We want to leave anything reaching TO_X to the caller. */
6861 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6863 if (BUFFER_POS_REACHED_P ())
6865 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6866 goto buffer_pos_reached
;
6867 if (atpos_it
.sp
< 0)
6870 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6875 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6878 result
= MOVE_X_REACHED
;
6884 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6889 if (/* Lines are continued. */
6890 it
->line_wrap
!= TRUNCATE
6891 && (/* And glyph doesn't fit on the line. */
6892 new_x
> it
->last_visible_x
6893 /* Or it fits exactly and we're on a window
6895 || (new_x
== it
->last_visible_x
6896 && FRAME_WINDOW_P (it
->f
))))
6898 if (/* IT->hpos == 0 means the very first glyph
6899 doesn't fit on the line, e.g. a wide image. */
6901 || (new_x
== it
->last_visible_x
6902 && FRAME_WINDOW_P (it
->f
)))
6905 it
->current_x
= new_x
;
6907 /* The character's last glyph just barely fits
6909 if (i
== it
->nglyphs
- 1)
6911 /* If this is the destination position,
6912 return a position *before* it in this row,
6913 now that we know it fits in this row. */
6914 if (BUFFER_POS_REACHED_P ())
6916 if (it
->line_wrap
!= WORD_WRAP
6919 it
->hpos
= hpos_before_this_char
;
6920 it
->current_x
= x_before_this_char
;
6921 result
= MOVE_POS_MATCH_OR_ZV
;
6924 if (it
->line_wrap
== WORD_WRAP
6928 atpos_it
.current_x
= x_before_this_char
;
6929 atpos_it
.hpos
= hpos_before_this_char
;
6933 set_iterator_to_next (it
, 1);
6934 /* On graphical terminals, newlines may
6935 "overflow" into the fringe if
6936 overflow-newline-into-fringe is non-nil.
6937 On text-only terminals, newlines may
6938 overflow into the last glyph on the
6940 if (!FRAME_WINDOW_P (it
->f
)
6941 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6943 if (!get_next_display_element (it
))
6945 result
= MOVE_POS_MATCH_OR_ZV
;
6948 if (BUFFER_POS_REACHED_P ())
6950 if (ITERATOR_AT_END_OF_LINE_P (it
))
6951 result
= MOVE_POS_MATCH_OR_ZV
;
6953 result
= MOVE_LINE_CONTINUED
;
6956 if (ITERATOR_AT_END_OF_LINE_P (it
))
6958 result
= MOVE_NEWLINE_OR_CR
;
6965 IT_RESET_X_ASCENT_DESCENT (it
);
6967 if (wrap_it
.sp
>= 0)
6974 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6976 result
= MOVE_LINE_CONTINUED
;
6980 if (BUFFER_POS_REACHED_P ())
6982 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6983 goto buffer_pos_reached
;
6984 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6987 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6991 if (new_x
> it
->first_visible_x
)
6993 /* Glyph is visible. Increment number of glyphs that
6994 would be displayed. */
6999 if (result
!= MOVE_UNDEFINED
)
7002 else if (BUFFER_POS_REACHED_P ())
7005 IT_RESET_X_ASCENT_DESCENT (it
);
7006 result
= MOVE_POS_MATCH_OR_ZV
;
7009 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7011 /* Stop when TO_X specified and reached. This check is
7012 necessary here because of lines consisting of a line end,
7013 only. The line end will not produce any glyphs and we
7014 would never get MOVE_X_REACHED. */
7015 xassert (it
->nglyphs
== 0);
7016 result
= MOVE_X_REACHED
;
7020 /* Is this a line end? If yes, we're done. */
7021 if (ITERATOR_AT_END_OF_LINE_P (it
))
7023 result
= MOVE_NEWLINE_OR_CR
;
7027 /* The current display element has been consumed. Advance
7029 set_iterator_to_next (it
, 1);
7031 /* Stop if lines are truncated and IT's current x-position is
7032 past the right edge of the window now. */
7033 if (it
->line_wrap
== TRUNCATE
7034 && it
->current_x
>= it
->last_visible_x
)
7036 if (!FRAME_WINDOW_P (it
->f
)
7037 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7039 if (!get_next_display_element (it
)
7040 || BUFFER_POS_REACHED_P ())
7042 result
= MOVE_POS_MATCH_OR_ZV
;
7045 if (ITERATOR_AT_END_OF_LINE_P (it
))
7047 result
= MOVE_NEWLINE_OR_CR
;
7051 result
= MOVE_LINE_TRUNCATED
;
7054 #undef IT_RESET_X_ASCENT_DESCENT
7057 #undef BUFFER_POS_REACHED_P
7059 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7060 restore the saved iterator. */
7061 if (atpos_it
.sp
>= 0)
7063 else if (atx_it
.sp
>= 0)
7068 /* Restore the iterator settings altered at the beginning of this
7070 it
->glyph_row
= saved_glyph_row
;
7074 /* For external use. */
7076 move_it_in_display_line (struct it
*it
,
7077 EMACS_INT to_charpos
, int to_x
,
7078 enum move_operation_enum op
)
7080 if (it
->line_wrap
== WORD_WRAP
7081 && (op
& MOVE_TO_X
))
7083 struct it save_it
= *it
;
7084 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7085 /* When word-wrap is on, TO_X may lie past the end
7086 of a wrapped line. Then it->current is the
7087 character on the next line, so backtrack to the
7088 space before the wrap point. */
7089 if (skip
== MOVE_LINE_CONTINUED
)
7091 int prev_x
= max (it
->current_x
- 1, 0);
7093 move_it_in_display_line_to
7094 (it
, -1, prev_x
, MOVE_TO_X
);
7098 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7102 /* Move IT forward until it satisfies one or more of the criteria in
7103 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7105 OP is a bit-mask that specifies where to stop, and in particular,
7106 which of those four position arguments makes a difference. See the
7107 description of enum move_operation_enum.
7109 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7110 screen line, this function will set IT to the next position >
7114 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7116 int to_charpos
, to_x
, to_y
, to_vpos
;
7119 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7120 int line_height
, line_start_x
= 0, reached
= 0;
7124 if (op
& MOVE_TO_VPOS
)
7126 /* If no TO_CHARPOS and no TO_X specified, stop at the
7127 start of the line TO_VPOS. */
7128 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7130 if (it
->vpos
== to_vpos
)
7136 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7140 /* TO_VPOS >= 0 means stop at TO_X in the line at
7141 TO_VPOS, or at TO_POS, whichever comes first. */
7142 if (it
->vpos
== to_vpos
)
7148 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7150 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7155 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7157 /* We have reached TO_X but not in the line we want. */
7158 skip
= move_it_in_display_line_to (it
, to_charpos
,
7160 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7168 else if (op
& MOVE_TO_Y
)
7170 struct it it_backup
;
7172 if (it
->line_wrap
== WORD_WRAP
)
7175 /* TO_Y specified means stop at TO_X in the line containing
7176 TO_Y---or at TO_CHARPOS if this is reached first. The
7177 problem is that we can't really tell whether the line
7178 contains TO_Y before we have completely scanned it, and
7179 this may skip past TO_X. What we do is to first scan to
7182 If TO_X is not specified, use a TO_X of zero. The reason
7183 is to make the outcome of this function more predictable.
7184 If we didn't use TO_X == 0, we would stop at the end of
7185 the line which is probably not what a caller would expect
7187 skip
= move_it_in_display_line_to
7188 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7189 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7191 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7192 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7194 else if (skip
== MOVE_X_REACHED
)
7196 /* If TO_X was reached, we want to know whether TO_Y is
7197 in the line. We know this is the case if the already
7198 scanned glyphs make the line tall enough. Otherwise,
7199 we must check by scanning the rest of the line. */
7200 line_height
= it
->max_ascent
+ it
->max_descent
;
7201 if (to_y
>= it
->current_y
7202 && to_y
< it
->current_y
+ line_height
)
7208 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7209 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7211 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7212 line_height
= it
->max_ascent
+ it
->max_descent
;
7213 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7215 if (to_y
>= it
->current_y
7216 && to_y
< it
->current_y
+ line_height
)
7218 /* If TO_Y is in this line and TO_X was reached
7219 above, we scanned too far. We have to restore
7220 IT's settings to the ones before skipping. */
7227 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7233 /* Check whether TO_Y is in this line. */
7234 line_height
= it
->max_ascent
+ it
->max_descent
;
7235 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7237 if (to_y
>= it
->current_y
7238 && to_y
< it
->current_y
+ line_height
)
7240 /* When word-wrap is on, TO_X may lie past the end
7241 of a wrapped line. Then it->current is the
7242 character on the next line, so backtrack to the
7243 space before the wrap point. */
7244 if (skip
== MOVE_LINE_CONTINUED
7245 && it
->line_wrap
== WORD_WRAP
)
7247 int prev_x
= max (it
->current_x
- 1, 0);
7249 skip
= move_it_in_display_line_to
7250 (it
, -1, prev_x
, MOVE_TO_X
);
7259 else if (BUFFERP (it
->object
)
7260 && (it
->method
== GET_FROM_BUFFER
7261 || it
->method
== GET_FROM_STRETCH
)
7262 && IT_CHARPOS (*it
) >= to_charpos
)
7263 skip
= MOVE_POS_MATCH_OR_ZV
;
7265 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7269 case MOVE_POS_MATCH_OR_ZV
:
7273 case MOVE_NEWLINE_OR_CR
:
7274 set_iterator_to_next (it
, 1);
7275 it
->continuation_lines_width
= 0;
7278 case MOVE_LINE_TRUNCATED
:
7279 it
->continuation_lines_width
= 0;
7280 reseat_at_next_visible_line_start (it
, 0);
7281 if ((op
& MOVE_TO_POS
) != 0
7282 && IT_CHARPOS (*it
) > to_charpos
)
7289 case MOVE_LINE_CONTINUED
:
7290 /* For continued lines ending in a tab, some of the glyphs
7291 associated with the tab are displayed on the current
7292 line. Since it->current_x does not include these glyphs,
7293 we use it->last_visible_x instead. */
7296 it
->continuation_lines_width
+= it
->last_visible_x
;
7297 /* When moving by vpos, ensure that the iterator really
7298 advances to the next line (bug#847, bug#969). Fixme:
7299 do we need to do this in other circumstances? */
7300 if (it
->current_x
!= it
->last_visible_x
7301 && (op
& MOVE_TO_VPOS
)
7302 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7304 line_start_x
= it
->current_x
+ it
->pixel_width
7305 - it
->last_visible_x
;
7306 set_iterator_to_next (it
, 0);
7310 it
->continuation_lines_width
+= it
->current_x
;
7317 /* Reset/increment for the next run. */
7318 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7319 it
->current_x
= line_start_x
;
7322 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7324 last_height
= it
->max_ascent
+ it
->max_descent
;
7325 last_max_ascent
= it
->max_ascent
;
7326 it
->max_ascent
= it
->max_descent
= 0;
7331 /* On text terminals, we may stop at the end of a line in the middle
7332 of a multi-character glyph. If the glyph itself is continued,
7333 i.e. it is actually displayed on the next line, don't treat this
7334 stopping point as valid; move to the next line instead (unless
7335 that brings us offscreen). */
7336 if (!FRAME_WINDOW_P (it
->f
)
7338 && IT_CHARPOS (*it
) == to_charpos
7339 && it
->what
== IT_CHARACTER
7341 && it
->line_wrap
== WINDOW_WRAP
7342 && it
->current_x
== it
->last_visible_x
- 1
7345 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7347 it
->continuation_lines_width
+= it
->current_x
;
7348 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7349 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7351 last_height
= it
->max_ascent
+ it
->max_descent
;
7352 last_max_ascent
= it
->max_ascent
;
7355 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7359 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7361 If DY > 0, move IT backward at least that many pixels. DY = 0
7362 means move IT backward to the preceding line start or BEGV. This
7363 function may move over more than DY pixels if IT->current_y - DY
7364 ends up in the middle of a line; in this case IT->current_y will be
7365 set to the top of the line moved to. */
7368 move_it_vertically_backward (it
, dy
)
7379 start_pos
= IT_CHARPOS (*it
);
7381 /* Estimate how many newlines we must move back. */
7382 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7384 /* Set the iterator's position that many lines back. */
7385 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7386 back_to_previous_visible_line_start (it
);
7388 /* Reseat the iterator here. When moving backward, we don't want
7389 reseat to skip forward over invisible text, set up the iterator
7390 to deliver from overlay strings at the new position etc. So,
7391 use reseat_1 here. */
7392 reseat_1 (it
, it
->current
.pos
, 1);
7394 /* We are now surely at a line start. */
7395 it
->current_x
= it
->hpos
= 0;
7396 it
->continuation_lines_width
= 0;
7398 /* Move forward and see what y-distance we moved. First move to the
7399 start of the next line so that we get its height. We need this
7400 height to be able to tell whether we reached the specified
7403 it2
.max_ascent
= it2
.max_descent
= 0;
7406 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7407 MOVE_TO_POS
| MOVE_TO_VPOS
);
7409 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7410 xassert (IT_CHARPOS (*it
) >= BEGV
);
7413 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7414 xassert (IT_CHARPOS (*it
) >= BEGV
);
7415 /* H is the actual vertical distance from the position in *IT
7416 and the starting position. */
7417 h
= it2
.current_y
- it
->current_y
;
7418 /* NLINES is the distance in number of lines. */
7419 nlines
= it2
.vpos
- it
->vpos
;
7421 /* Correct IT's y and vpos position
7422 so that they are relative to the starting point. */
7428 /* DY == 0 means move to the start of the screen line. The
7429 value of nlines is > 0 if continuation lines were involved. */
7431 move_it_by_lines (it
, nlines
, 1);
7435 /* The y-position we try to reach, relative to *IT.
7436 Note that H has been subtracted in front of the if-statement. */
7437 int target_y
= it
->current_y
+ h
- dy
;
7438 int y0
= it3
.current_y
;
7439 int y1
= line_bottom_y (&it3
);
7440 int line_height
= y1
- y0
;
7442 /* If we did not reach target_y, try to move further backward if
7443 we can. If we moved too far backward, try to move forward. */
7444 if (target_y
< it
->current_y
7445 /* This is heuristic. In a window that's 3 lines high, with
7446 a line height of 13 pixels each, recentering with point
7447 on the bottom line will try to move -39/2 = 19 pixels
7448 backward. Try to avoid moving into the first line. */
7449 && (it
->current_y
- target_y
7450 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7451 && IT_CHARPOS (*it
) > BEGV
)
7453 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7454 target_y
- it
->current_y
));
7455 dy
= it
->current_y
- target_y
;
7456 goto move_further_back
;
7458 else if (target_y
>= it
->current_y
+ line_height
7459 && IT_CHARPOS (*it
) < ZV
)
7461 /* Should move forward by at least one line, maybe more.
7463 Note: Calling move_it_by_lines can be expensive on
7464 terminal frames, where compute_motion is used (via
7465 vmotion) to do the job, when there are very long lines
7466 and truncate-lines is nil. That's the reason for
7467 treating terminal frames specially here. */
7469 if (!FRAME_WINDOW_P (it
->f
))
7470 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7475 move_it_by_lines (it
, 1, 1);
7477 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7484 /* Move IT by a specified amount of pixel lines DY. DY negative means
7485 move backwards. DY = 0 means move to start of screen line. At the
7486 end, IT will be on the start of a screen line. */
7489 move_it_vertically (it
, dy
)
7494 move_it_vertically_backward (it
, -dy
);
7497 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7498 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7499 MOVE_TO_POS
| MOVE_TO_Y
);
7500 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7502 /* If buffer ends in ZV without a newline, move to the start of
7503 the line to satisfy the post-condition. */
7504 if (IT_CHARPOS (*it
) == ZV
7506 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7507 move_it_by_lines (it
, 0, 0);
7512 /* Move iterator IT past the end of the text line it is in. */
7515 move_it_past_eol (it
)
7518 enum move_it_result rc
;
7520 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7521 if (rc
== MOVE_NEWLINE_OR_CR
)
7522 set_iterator_to_next (it
, 0);
7526 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7527 negative means move up. DVPOS == 0 means move to the start of the
7528 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7529 NEED_Y_P is zero, IT->current_y will be left unchanged.
7531 Further optimization ideas: If we would know that IT->f doesn't use
7532 a face with proportional font, we could be faster for
7533 truncate-lines nil. */
7536 move_it_by_lines (it
, dvpos
, need_y_p
)
7538 int dvpos
, need_y_p
;
7540 struct position pos
;
7542 /* The commented-out optimization uses vmotion on terminals. This
7543 gives bad results, because elements like it->what, on which
7544 callers such as pos_visible_p rely, aren't updated. */
7545 /* if (!FRAME_WINDOW_P (it->f))
7547 struct text_pos textpos;
7549 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7550 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7551 reseat (it, textpos, 1);
7552 it->vpos += pos.vpos;
7553 it->current_y += pos.vpos;
7559 /* DVPOS == 0 means move to the start of the screen line. */
7560 move_it_vertically_backward (it
, 0);
7561 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7562 /* Let next call to line_bottom_y calculate real line height */
7567 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7568 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7569 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7574 int start_charpos
, i
;
7576 /* Start at the beginning of the screen line containing IT's
7577 position. This may actually move vertically backwards,
7578 in case of overlays, so adjust dvpos accordingly. */
7580 move_it_vertically_backward (it
, 0);
7583 /* Go back -DVPOS visible lines and reseat the iterator there. */
7584 start_charpos
= IT_CHARPOS (*it
);
7585 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7586 back_to_previous_visible_line_start (it
);
7587 reseat (it
, it
->current
.pos
, 1);
7589 /* Move further back if we end up in a string or an image. */
7590 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7592 /* First try to move to start of display line. */
7594 move_it_vertically_backward (it
, 0);
7596 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7598 /* If start of line is still in string or image,
7599 move further back. */
7600 back_to_previous_visible_line_start (it
);
7601 reseat (it
, it
->current
.pos
, 1);
7605 it
->current_x
= it
->hpos
= 0;
7607 /* Above call may have moved too far if continuation lines
7608 are involved. Scan forward and see if it did. */
7610 it2
.vpos
= it2
.current_y
= 0;
7611 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7612 it
->vpos
-= it2
.vpos
;
7613 it
->current_y
-= it2
.current_y
;
7614 it
->current_x
= it
->hpos
= 0;
7616 /* If we moved too far back, move IT some lines forward. */
7617 if (it2
.vpos
> -dvpos
)
7619 int delta
= it2
.vpos
+ dvpos
;
7621 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7622 /* Move back again if we got too far ahead. */
7623 if (IT_CHARPOS (*it
) >= start_charpos
)
7629 /* Return 1 if IT points into the middle of a display vector. */
7632 in_display_vector_p (it
)
7635 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7636 && it
->current
.dpvec_index
> 0
7637 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7641 /***********************************************************************
7643 ***********************************************************************/
7646 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7650 add_to_log (format
, arg1
, arg2
)
7652 Lisp_Object arg1
, arg2
;
7654 Lisp_Object args
[3];
7655 Lisp_Object msg
, fmt
;
7658 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7661 /* Do nothing if called asynchronously. Inserting text into
7662 a buffer may call after-change-functions and alike and
7663 that would means running Lisp asynchronously. */
7664 if (handling_signal
)
7668 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7670 args
[0] = fmt
= build_string (format
);
7673 msg
= Fformat (3, args
);
7675 len
= SBYTES (msg
) + 1;
7676 SAFE_ALLOCA (buffer
, char *, len
);
7677 bcopy (SDATA (msg
), buffer
, len
);
7679 message_dolog (buffer
, len
- 1, 1, 0);
7686 /* Output a newline in the *Messages* buffer if "needs" one. */
7689 message_log_maybe_newline ()
7691 if (message_log_need_newline
)
7692 message_dolog ("", 0, 1, 0);
7696 /* Add a string M of length NBYTES to the message log, optionally
7697 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7698 nonzero, means interpret the contents of M as multibyte. This
7699 function calls low-level routines in order to bypass text property
7700 hooks, etc. which might not be safe to run.
7702 This may GC (insert may run before/after change hooks),
7703 so the buffer M must NOT point to a Lisp string. */
7706 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7708 int nbytes
, nlflag
, multibyte
;
7710 if (!NILP (Vmemory_full
))
7713 if (!NILP (Vmessage_log_max
))
7715 struct buffer
*oldbuf
;
7716 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7717 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7718 int point_at_end
= 0;
7720 Lisp_Object old_deactivate_mark
, tem
;
7721 struct gcpro gcpro1
;
7723 old_deactivate_mark
= Vdeactivate_mark
;
7724 oldbuf
= current_buffer
;
7725 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7726 current_buffer
->undo_list
= Qt
;
7728 oldpoint
= message_dolog_marker1
;
7729 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7730 oldbegv
= message_dolog_marker2
;
7731 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7732 oldzv
= message_dolog_marker3
;
7733 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7734 GCPRO1 (old_deactivate_mark
);
7742 BEGV_BYTE
= BEG_BYTE
;
7745 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7747 /* Insert the string--maybe converting multibyte to single byte
7748 or vice versa, so that all the text fits the buffer. */
7750 && NILP (current_buffer
->enable_multibyte_characters
))
7752 int i
, c
, char_bytes
;
7753 unsigned char work
[1];
7755 /* Convert a multibyte string to single-byte
7756 for the *Message* buffer. */
7757 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7759 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7760 work
[0] = (ASCII_CHAR_P (c
)
7762 : multibyte_char_to_unibyte (c
, Qnil
));
7763 insert_1_both (work
, 1, 1, 1, 0, 0);
7766 else if (! multibyte
7767 && ! NILP (current_buffer
->enable_multibyte_characters
))
7769 int i
, c
, char_bytes
;
7770 unsigned char *msg
= (unsigned char *) m
;
7771 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7772 /* Convert a single-byte string to multibyte
7773 for the *Message* buffer. */
7774 for (i
= 0; i
< nbytes
; i
++)
7777 MAKE_CHAR_MULTIBYTE (c
);
7778 char_bytes
= CHAR_STRING (c
, str
);
7779 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7783 insert_1 (m
, nbytes
, 1, 0, 0);
7787 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7788 insert_1 ("\n", 1, 1, 0, 0);
7790 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7792 this_bol_byte
= PT_BYTE
;
7794 /* See if this line duplicates the previous one.
7795 If so, combine duplicates. */
7798 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7800 prev_bol_byte
= PT_BYTE
;
7802 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7803 this_bol
, this_bol_byte
);
7806 del_range_both (prev_bol
, prev_bol_byte
,
7807 this_bol
, this_bol_byte
, 0);
7813 /* If you change this format, don't forget to also
7814 change message_log_check_duplicate. */
7815 sprintf (dupstr
, " [%d times]", dup
);
7816 duplen
= strlen (dupstr
);
7817 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7818 insert_1 (dupstr
, duplen
, 1, 0, 1);
7823 /* If we have more than the desired maximum number of lines
7824 in the *Messages* buffer now, delete the oldest ones.
7825 This is safe because we don't have undo in this buffer. */
7827 if (NATNUMP (Vmessage_log_max
))
7829 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7830 -XFASTINT (Vmessage_log_max
) - 1, 0);
7831 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7834 BEGV
= XMARKER (oldbegv
)->charpos
;
7835 BEGV_BYTE
= marker_byte_position (oldbegv
);
7844 ZV
= XMARKER (oldzv
)->charpos
;
7845 ZV_BYTE
= marker_byte_position (oldzv
);
7849 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7851 /* We can't do Fgoto_char (oldpoint) because it will run some
7853 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7854 XMARKER (oldpoint
)->bytepos
);
7857 unchain_marker (XMARKER (oldpoint
));
7858 unchain_marker (XMARKER (oldbegv
));
7859 unchain_marker (XMARKER (oldzv
));
7861 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7862 set_buffer_internal (oldbuf
);
7864 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7865 message_log_need_newline
= !nlflag
;
7866 Vdeactivate_mark
= old_deactivate_mark
;
7871 /* We are at the end of the buffer after just having inserted a newline.
7872 (Note: We depend on the fact we won't be crossing the gap.)
7873 Check to see if the most recent message looks a lot like the previous one.
7874 Return 0 if different, 1 if the new one should just replace it, or a
7875 value N > 1 if we should also append " [N times]". */
7878 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7879 int prev_bol
, this_bol
;
7880 int prev_bol_byte
, this_bol_byte
;
7883 int len
= Z_BYTE
- 1 - this_bol_byte
;
7885 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7886 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7888 for (i
= 0; i
< len
; i
++)
7890 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7898 if (*p1
++ == ' ' && *p1
++ == '[')
7901 while (*p1
>= '0' && *p1
<= '9')
7902 n
= n
* 10 + *p1
++ - '0';
7903 if (strncmp (p1
, " times]\n", 8) == 0)
7910 /* Display an echo area message M with a specified length of NBYTES
7911 bytes. The string may include null characters. If M is 0, clear
7912 out any existing message, and let the mini-buffer text show
7915 This may GC, so the buffer M must NOT point to a Lisp string. */
7918 message2 (m
, nbytes
, multibyte
)
7923 /* First flush out any partial line written with print. */
7924 message_log_maybe_newline ();
7926 message_dolog (m
, nbytes
, 1, multibyte
);
7927 message2_nolog (m
, nbytes
, multibyte
);
7931 /* The non-logging counterpart of message2. */
7934 message2_nolog (m
, nbytes
, multibyte
)
7936 int nbytes
, multibyte
;
7938 struct frame
*sf
= SELECTED_FRAME ();
7939 message_enable_multibyte
= multibyte
;
7941 if (FRAME_INITIAL_P (sf
))
7943 if (noninteractive_need_newline
)
7944 putc ('\n', stderr
);
7945 noninteractive_need_newline
= 0;
7947 fwrite (m
, nbytes
, 1, stderr
);
7948 if (cursor_in_echo_area
== 0)
7949 fprintf (stderr
, "\n");
7952 /* A null message buffer means that the frame hasn't really been
7953 initialized yet. Error messages get reported properly by
7954 cmd_error, so this must be just an informative message; toss it. */
7955 else if (INTERACTIVE
7956 && sf
->glyphs_initialized_p
7957 && FRAME_MESSAGE_BUF (sf
))
7959 Lisp_Object mini_window
;
7962 /* Get the frame containing the mini-buffer
7963 that the selected frame is using. */
7964 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7965 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7967 FRAME_SAMPLE_VISIBILITY (f
);
7968 if (FRAME_VISIBLE_P (sf
)
7969 && ! FRAME_VISIBLE_P (f
))
7970 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7974 set_message (m
, Qnil
, nbytes
, multibyte
);
7975 if (minibuffer_auto_raise
)
7976 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7979 clear_message (1, 1);
7981 do_pending_window_change (0);
7982 echo_area_display (1);
7983 do_pending_window_change (0);
7984 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7985 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7990 /* Display an echo area message M with a specified length of NBYTES
7991 bytes. The string may include null characters. If M is not a
7992 string, clear out any existing message, and let the mini-buffer
7995 This function cancels echoing. */
7998 message3 (m
, nbytes
, multibyte
)
8003 struct gcpro gcpro1
;
8006 clear_message (1,1);
8009 /* First flush out any partial line written with print. */
8010 message_log_maybe_newline ();
8016 SAFE_ALLOCA (buffer
, char *, nbytes
);
8017 bcopy (SDATA (m
), buffer
, nbytes
);
8018 message_dolog (buffer
, nbytes
, 1, multibyte
);
8021 message3_nolog (m
, nbytes
, multibyte
);
8027 /* The non-logging version of message3.
8028 This does not cancel echoing, because it is used for echoing.
8029 Perhaps we need to make a separate function for echoing
8030 and make this cancel echoing. */
8033 message3_nolog (m
, nbytes
, multibyte
)
8035 int nbytes
, multibyte
;
8037 struct frame
*sf
= SELECTED_FRAME ();
8038 message_enable_multibyte
= multibyte
;
8040 if (FRAME_INITIAL_P (sf
))
8042 if (noninteractive_need_newline
)
8043 putc ('\n', stderr
);
8044 noninteractive_need_newline
= 0;
8046 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8047 if (cursor_in_echo_area
== 0)
8048 fprintf (stderr
, "\n");
8051 /* A null message buffer means that the frame hasn't really been
8052 initialized yet. Error messages get reported properly by
8053 cmd_error, so this must be just an informative message; toss it. */
8054 else if (INTERACTIVE
8055 && sf
->glyphs_initialized_p
8056 && FRAME_MESSAGE_BUF (sf
))
8058 Lisp_Object mini_window
;
8062 /* Get the frame containing the mini-buffer
8063 that the selected frame is using. */
8064 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8065 frame
= XWINDOW (mini_window
)->frame
;
8068 FRAME_SAMPLE_VISIBILITY (f
);
8069 if (FRAME_VISIBLE_P (sf
)
8070 && !FRAME_VISIBLE_P (f
))
8071 Fmake_frame_visible (frame
);
8073 if (STRINGP (m
) && SCHARS (m
) > 0)
8075 set_message (NULL
, m
, nbytes
, multibyte
);
8076 if (minibuffer_auto_raise
)
8077 Fraise_frame (frame
);
8078 /* Assume we are not echoing.
8079 (If we are, echo_now will override this.) */
8080 echo_message_buffer
= Qnil
;
8083 clear_message (1, 1);
8085 do_pending_window_change (0);
8086 echo_area_display (1);
8087 do_pending_window_change (0);
8088 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8089 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8094 /* Display a null-terminated echo area message M. If M is 0, clear
8095 out any existing message, and let the mini-buffer text show through.
8097 The buffer M must continue to exist until after the echo area gets
8098 cleared or some other message gets displayed there. Do not pass
8099 text that is stored in a Lisp string. Do not pass text in a buffer
8100 that was alloca'd. */
8106 message2 (m
, (m
? strlen (m
) : 0), 0);
8110 /* The non-logging counterpart of message1. */
8116 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8119 /* Display a message M which contains a single %s
8120 which gets replaced with STRING. */
8123 message_with_string (m
, string
, log
)
8128 CHECK_STRING (string
);
8134 if (noninteractive_need_newline
)
8135 putc ('\n', stderr
);
8136 noninteractive_need_newline
= 0;
8137 fprintf (stderr
, m
, SDATA (string
));
8138 if (!cursor_in_echo_area
)
8139 fprintf (stderr
, "\n");
8143 else if (INTERACTIVE
)
8145 /* The frame whose minibuffer we're going to display the message on.
8146 It may be larger than the selected frame, so we need
8147 to use its buffer, not the selected frame's buffer. */
8148 Lisp_Object mini_window
;
8149 struct frame
*f
, *sf
= SELECTED_FRAME ();
8151 /* Get the frame containing the minibuffer
8152 that the selected frame is using. */
8153 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8154 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8156 /* A null message buffer means that the frame hasn't really been
8157 initialized yet. Error messages get reported properly by
8158 cmd_error, so this must be just an informative message; toss it. */
8159 if (FRAME_MESSAGE_BUF (f
))
8161 Lisp_Object args
[2], message
;
8162 struct gcpro gcpro1
, gcpro2
;
8164 args
[0] = build_string (m
);
8165 args
[1] = message
= string
;
8166 GCPRO2 (args
[0], message
);
8169 message
= Fformat (2, args
);
8172 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8174 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8178 /* Print should start at the beginning of the message
8179 buffer next time. */
8180 message_buf_print
= 0;
8186 /* Dump an informative message to the minibuf. If M is 0, clear out
8187 any existing message, and let the mini-buffer text show through. */
8191 message (m
, a1
, a2
, a3
)
8193 EMACS_INT a1
, a2
, a3
;
8199 if (noninteractive_need_newline
)
8200 putc ('\n', stderr
);
8201 noninteractive_need_newline
= 0;
8202 fprintf (stderr
, m
, a1
, a2
, a3
);
8203 if (cursor_in_echo_area
== 0)
8204 fprintf (stderr
, "\n");
8208 else if (INTERACTIVE
)
8210 /* The frame whose mini-buffer we're going to display the message
8211 on. It may be larger than the selected frame, so we need to
8212 use its buffer, not the selected frame's buffer. */
8213 Lisp_Object mini_window
;
8214 struct frame
*f
, *sf
= SELECTED_FRAME ();
8216 /* Get the frame containing the mini-buffer
8217 that the selected frame is using. */
8218 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8219 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8221 /* A null message buffer means that the frame hasn't really been
8222 initialized yet. Error messages get reported properly by
8223 cmd_error, so this must be just an informative message; toss
8225 if (FRAME_MESSAGE_BUF (f
))
8236 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8237 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8239 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8240 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8242 #endif /* NO_ARG_ARRAY */
8244 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8249 /* Print should start at the beginning of the message
8250 buffer next time. */
8251 message_buf_print
= 0;
8257 /* The non-logging version of message. */
8260 message_nolog (m
, a1
, a2
, a3
)
8262 EMACS_INT a1
, a2
, a3
;
8264 Lisp_Object old_log_max
;
8265 old_log_max
= Vmessage_log_max
;
8266 Vmessage_log_max
= Qnil
;
8267 message (m
, a1
, a2
, a3
);
8268 Vmessage_log_max
= old_log_max
;
8272 /* Display the current message in the current mini-buffer. This is
8273 only called from error handlers in process.c, and is not time
8279 if (!NILP (echo_area_buffer
[0]))
8282 string
= Fcurrent_message ();
8283 message3 (string
, SBYTES (string
),
8284 !NILP (current_buffer
->enable_multibyte_characters
));
8289 /* Make sure echo area buffers in `echo_buffers' are live.
8290 If they aren't, make new ones. */
8293 ensure_echo_area_buffers ()
8297 for (i
= 0; i
< 2; ++i
)
8298 if (!BUFFERP (echo_buffer
[i
])
8299 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8302 Lisp_Object old_buffer
;
8305 old_buffer
= echo_buffer
[i
];
8306 sprintf (name
, " *Echo Area %d*", i
);
8307 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8308 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8309 /* to force word wrap in echo area -
8310 it was decided to postpone this*/
8311 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8313 for (j
= 0; j
< 2; ++j
)
8314 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8315 echo_area_buffer
[j
] = echo_buffer
[i
];
8320 /* Call FN with args A1..A4 with either the current or last displayed
8321 echo_area_buffer as current buffer.
8323 WHICH zero means use the current message buffer
8324 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8325 from echo_buffer[] and clear it.
8327 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8328 suitable buffer from echo_buffer[] and clear it.
8330 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8331 that the current message becomes the last displayed one, make
8332 choose a suitable buffer for echo_area_buffer[0], and clear it.
8334 Value is what FN returns. */
8337 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8340 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8346 int this_one
, the_other
, clear_buffer_p
, rc
;
8347 int count
= SPECPDL_INDEX ();
8349 /* If buffers aren't live, make new ones. */
8350 ensure_echo_area_buffers ();
8355 this_one
= 0, the_other
= 1;
8357 this_one
= 1, the_other
= 0;
8360 this_one
= 0, the_other
= 1;
8363 /* We need a fresh one in case the current echo buffer equals
8364 the one containing the last displayed echo area message. */
8365 if (!NILP (echo_area_buffer
[this_one
])
8366 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8367 echo_area_buffer
[this_one
] = Qnil
;
8370 /* Choose a suitable buffer from echo_buffer[] is we don't
8372 if (NILP (echo_area_buffer
[this_one
]))
8374 echo_area_buffer
[this_one
]
8375 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8376 ? echo_buffer
[the_other
]
8377 : echo_buffer
[this_one
]);
8381 buffer
= echo_area_buffer
[this_one
];
8383 /* Don't get confused by reusing the buffer used for echoing
8384 for a different purpose. */
8385 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8388 record_unwind_protect (unwind_with_echo_area_buffer
,
8389 with_echo_area_buffer_unwind_data (w
));
8391 /* Make the echo area buffer current. Note that for display
8392 purposes, it is not necessary that the displayed window's buffer
8393 == current_buffer, except for text property lookup. So, let's
8394 only set that buffer temporarily here without doing a full
8395 Fset_window_buffer. We must also change w->pointm, though,
8396 because otherwise an assertions in unshow_buffer fails, and Emacs
8398 set_buffer_internal_1 (XBUFFER (buffer
));
8402 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8405 current_buffer
->undo_list
= Qt
;
8406 current_buffer
->read_only
= Qnil
;
8407 specbind (Qinhibit_read_only
, Qt
);
8408 specbind (Qinhibit_modification_hooks
, Qt
);
8410 if (clear_buffer_p
&& Z
> BEG
)
8413 xassert (BEGV
>= BEG
);
8414 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8416 rc
= fn (a1
, a2
, a3
, a4
);
8418 xassert (BEGV
>= BEG
);
8419 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8421 unbind_to (count
, Qnil
);
8426 /* Save state that should be preserved around the call to the function
8427 FN called in with_echo_area_buffer. */
8430 with_echo_area_buffer_unwind_data (w
)
8434 Lisp_Object vector
, tmp
;
8436 /* Reduce consing by keeping one vector in
8437 Vwith_echo_area_save_vector. */
8438 vector
= Vwith_echo_area_save_vector
;
8439 Vwith_echo_area_save_vector
= Qnil
;
8442 vector
= Fmake_vector (make_number (7), Qnil
);
8444 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8445 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8446 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8450 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8451 ASET (vector
, i
, w
->buffer
); ++i
;
8452 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8453 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8458 for (; i
< end
; ++i
)
8459 ASET (vector
, i
, Qnil
);
8462 xassert (i
== ASIZE (vector
));
8467 /* Restore global state from VECTOR which was created by
8468 with_echo_area_buffer_unwind_data. */
8471 unwind_with_echo_area_buffer (vector
)
8474 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8475 Vdeactivate_mark
= AREF (vector
, 1);
8476 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8478 if (WINDOWP (AREF (vector
, 3)))
8481 Lisp_Object buffer
, charpos
, bytepos
;
8483 w
= XWINDOW (AREF (vector
, 3));
8484 buffer
= AREF (vector
, 4);
8485 charpos
= AREF (vector
, 5);
8486 bytepos
= AREF (vector
, 6);
8489 set_marker_both (w
->pointm
, buffer
,
8490 XFASTINT (charpos
), XFASTINT (bytepos
));
8493 Vwith_echo_area_save_vector
= vector
;
8498 /* Set up the echo area for use by print functions. MULTIBYTE_P
8499 non-zero means we will print multibyte. */
8502 setup_echo_area_for_printing (multibyte_p
)
8505 /* If we can't find an echo area any more, exit. */
8506 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8509 ensure_echo_area_buffers ();
8511 if (!message_buf_print
)
8513 /* A message has been output since the last time we printed.
8514 Choose a fresh echo area buffer. */
8515 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8516 echo_area_buffer
[0] = echo_buffer
[1];
8518 echo_area_buffer
[0] = echo_buffer
[0];
8520 /* Switch to that buffer and clear it. */
8521 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8522 current_buffer
->truncate_lines
= Qnil
;
8526 int count
= SPECPDL_INDEX ();
8527 specbind (Qinhibit_read_only
, Qt
);
8528 /* Note that undo recording is always disabled. */
8530 unbind_to (count
, Qnil
);
8532 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8534 /* Set up the buffer for the multibyteness we need. */
8536 != !NILP (current_buffer
->enable_multibyte_characters
))
8537 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8539 /* Raise the frame containing the echo area. */
8540 if (minibuffer_auto_raise
)
8542 struct frame
*sf
= SELECTED_FRAME ();
8543 Lisp_Object mini_window
;
8544 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8545 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8548 message_log_maybe_newline ();
8549 message_buf_print
= 1;
8553 if (NILP (echo_area_buffer
[0]))
8555 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8556 echo_area_buffer
[0] = echo_buffer
[1];
8558 echo_area_buffer
[0] = echo_buffer
[0];
8561 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8563 /* Someone switched buffers between print requests. */
8564 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8565 current_buffer
->truncate_lines
= Qnil
;
8571 /* Display an echo area message in window W. Value is non-zero if W's
8572 height is changed. If display_last_displayed_message_p is
8573 non-zero, display the message that was last displayed, otherwise
8574 display the current message. */
8577 display_echo_area (w
)
8580 int i
, no_message_p
, window_height_changed_p
, count
;
8582 /* Temporarily disable garbage collections while displaying the echo
8583 area. This is done because a GC can print a message itself.
8584 That message would modify the echo area buffer's contents while a
8585 redisplay of the buffer is going on, and seriously confuse
8587 count
= inhibit_garbage_collection ();
8589 /* If there is no message, we must call display_echo_area_1
8590 nevertheless because it resizes the window. But we will have to
8591 reset the echo_area_buffer in question to nil at the end because
8592 with_echo_area_buffer will sets it to an empty buffer. */
8593 i
= display_last_displayed_message_p
? 1 : 0;
8594 no_message_p
= NILP (echo_area_buffer
[i
]);
8596 window_height_changed_p
8597 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8598 display_echo_area_1
,
8599 (EMACS_INT
) w
, Qnil
, 0, 0);
8602 echo_area_buffer
[i
] = Qnil
;
8604 unbind_to (count
, Qnil
);
8605 return window_height_changed_p
;
8609 /* Helper for display_echo_area. Display the current buffer which
8610 contains the current echo area message in window W, a mini-window,
8611 a pointer to which is passed in A1. A2..A4 are currently not used.
8612 Change the height of W so that all of the message is displayed.
8613 Value is non-zero if height of W was changed. */
8616 display_echo_area_1 (a1
, a2
, a3
, a4
)
8621 struct window
*w
= (struct window
*) a1
;
8623 struct text_pos start
;
8624 int window_height_changed_p
= 0;
8626 /* Do this before displaying, so that we have a large enough glyph
8627 matrix for the display. If we can't get enough space for the
8628 whole text, display the last N lines. That works by setting w->start. */
8629 window_height_changed_p
= resize_mini_window (w
, 0);
8631 /* Use the starting position chosen by resize_mini_window. */
8632 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8635 clear_glyph_matrix (w
->desired_matrix
);
8636 XSETWINDOW (window
, w
);
8637 try_window (window
, start
, 0);
8639 return window_height_changed_p
;
8643 /* Resize the echo area window to exactly the size needed for the
8644 currently displayed message, if there is one. If a mini-buffer
8645 is active, don't shrink it. */
8648 resize_echo_area_exactly ()
8650 if (BUFFERP (echo_area_buffer
[0])
8651 && WINDOWP (echo_area_window
))
8653 struct window
*w
= XWINDOW (echo_area_window
);
8655 Lisp_Object resize_exactly
;
8657 if (minibuf_level
== 0)
8658 resize_exactly
= Qt
;
8660 resize_exactly
= Qnil
;
8662 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8663 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8666 ++windows_or_buffers_changed
;
8667 ++update_mode_lines
;
8668 redisplay_internal (0);
8674 /* Callback function for with_echo_area_buffer, when used from
8675 resize_echo_area_exactly. A1 contains a pointer to the window to
8676 resize, EXACTLY non-nil means resize the mini-window exactly to the
8677 size of the text displayed. A3 and A4 are not used. Value is what
8678 resize_mini_window returns. */
8681 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8683 Lisp_Object exactly
;
8686 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8690 /* Resize mini-window W to fit the size of its contents. EXACT_P
8691 means size the window exactly to the size needed. Otherwise, it's
8692 only enlarged until W's buffer is empty.
8694 Set W->start to the right place to begin display. If the whole
8695 contents fit, start at the beginning. Otherwise, start so as
8696 to make the end of the contents appear. This is particularly
8697 important for y-or-n-p, but seems desirable generally.
8699 Value is non-zero if the window height has been changed. */
8702 resize_mini_window (w
, exact_p
)
8706 struct frame
*f
= XFRAME (w
->frame
);
8707 int window_height_changed_p
= 0;
8709 xassert (MINI_WINDOW_P (w
));
8711 /* By default, start display at the beginning. */
8712 set_marker_both (w
->start
, w
->buffer
,
8713 BUF_BEGV (XBUFFER (w
->buffer
)),
8714 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8716 /* Don't resize windows while redisplaying a window; it would
8717 confuse redisplay functions when the size of the window they are
8718 displaying changes from under them. Such a resizing can happen,
8719 for instance, when which-func prints a long message while
8720 we are running fontification-functions. We're running these
8721 functions with safe_call which binds inhibit-redisplay to t. */
8722 if (!NILP (Vinhibit_redisplay
))
8725 /* Nil means don't try to resize. */
8726 if (NILP (Vresize_mini_windows
)
8727 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8730 if (!FRAME_MINIBUF_ONLY_P (f
))
8733 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8734 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8735 int height
, max_height
;
8736 int unit
= FRAME_LINE_HEIGHT (f
);
8737 struct text_pos start
;
8738 struct buffer
*old_current_buffer
= NULL
;
8740 if (current_buffer
!= XBUFFER (w
->buffer
))
8742 old_current_buffer
= current_buffer
;
8743 set_buffer_internal (XBUFFER (w
->buffer
));
8746 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8748 /* Compute the max. number of lines specified by the user. */
8749 if (FLOATP (Vmax_mini_window_height
))
8750 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8751 else if (INTEGERP (Vmax_mini_window_height
))
8752 max_height
= XINT (Vmax_mini_window_height
);
8754 max_height
= total_height
/ 4;
8756 /* Correct that max. height if it's bogus. */
8757 max_height
= max (1, max_height
);
8758 max_height
= min (total_height
, max_height
);
8760 /* Find out the height of the text in the window. */
8761 if (it
.line_wrap
== TRUNCATE
)
8766 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8767 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8768 height
= it
.current_y
+ last_height
;
8770 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8771 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8772 height
= (height
+ unit
- 1) / unit
;
8775 /* Compute a suitable window start. */
8776 if (height
> max_height
)
8778 height
= max_height
;
8779 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8780 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8781 start
= it
.current
.pos
;
8784 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8785 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8787 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8789 /* Let it grow only, until we display an empty message, in which
8790 case the window shrinks again. */
8791 if (height
> WINDOW_TOTAL_LINES (w
))
8793 int old_height
= WINDOW_TOTAL_LINES (w
);
8794 freeze_window_starts (f
, 1);
8795 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8796 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8798 else if (height
< WINDOW_TOTAL_LINES (w
)
8799 && (exact_p
|| BEGV
== ZV
))
8801 int old_height
= WINDOW_TOTAL_LINES (w
);
8802 freeze_window_starts (f
, 0);
8803 shrink_mini_window (w
);
8804 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8809 /* Always resize to exact size needed. */
8810 if (height
> WINDOW_TOTAL_LINES (w
))
8812 int old_height
= WINDOW_TOTAL_LINES (w
);
8813 freeze_window_starts (f
, 1);
8814 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8815 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8817 else if (height
< WINDOW_TOTAL_LINES (w
))
8819 int old_height
= WINDOW_TOTAL_LINES (w
);
8820 freeze_window_starts (f
, 0);
8821 shrink_mini_window (w
);
8825 freeze_window_starts (f
, 1);
8826 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8829 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8833 if (old_current_buffer
)
8834 set_buffer_internal (old_current_buffer
);
8837 return window_height_changed_p
;
8841 /* Value is the current message, a string, or nil if there is no
8849 if (!BUFFERP (echo_area_buffer
[0]))
8853 with_echo_area_buffer (0, 0, current_message_1
,
8854 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8856 echo_area_buffer
[0] = Qnil
;
8864 current_message_1 (a1
, a2
, a3
, a4
)
8869 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8872 *msg
= make_buffer_string (BEG
, Z
, 1);
8879 /* Push the current message on Vmessage_stack for later restauration
8880 by restore_message. Value is non-zero if the current message isn't
8881 empty. This is a relatively infrequent operation, so it's not
8882 worth optimizing. */
8888 msg
= current_message ();
8889 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8890 return STRINGP (msg
);
8894 /* Restore message display from the top of Vmessage_stack. */
8901 xassert (CONSP (Vmessage_stack
));
8902 msg
= XCAR (Vmessage_stack
);
8904 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8906 message3_nolog (msg
, 0, 0);
8910 /* Handler for record_unwind_protect calling pop_message. */
8913 pop_message_unwind (dummy
)
8920 /* Pop the top-most entry off Vmessage_stack. */
8925 xassert (CONSP (Vmessage_stack
));
8926 Vmessage_stack
= XCDR (Vmessage_stack
);
8930 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8931 exits. If the stack is not empty, we have a missing pop_message
8935 check_message_stack ()
8937 if (!NILP (Vmessage_stack
))
8942 /* Truncate to NCHARS what will be displayed in the echo area the next
8943 time we display it---but don't redisplay it now. */
8946 truncate_echo_area (nchars
)
8950 echo_area_buffer
[0] = Qnil
;
8951 /* A null message buffer means that the frame hasn't really been
8952 initialized yet. Error messages get reported properly by
8953 cmd_error, so this must be just an informative message; toss it. */
8954 else if (!noninteractive
8956 && !NILP (echo_area_buffer
[0]))
8958 struct frame
*sf
= SELECTED_FRAME ();
8959 if (FRAME_MESSAGE_BUF (sf
))
8960 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8965 /* Helper function for truncate_echo_area. Truncate the current
8966 message to at most NCHARS characters. */
8969 truncate_message_1 (nchars
, a2
, a3
, a4
)
8974 if (BEG
+ nchars
< Z
)
8975 del_range (BEG
+ nchars
, Z
);
8977 echo_area_buffer
[0] = Qnil
;
8982 /* Set the current message to a substring of S or STRING.
8984 If STRING is a Lisp string, set the message to the first NBYTES
8985 bytes from STRING. NBYTES zero means use the whole string. If
8986 STRING is multibyte, the message will be displayed multibyte.
8988 If S is not null, set the message to the first LEN bytes of S. LEN
8989 zero means use the whole string. MULTIBYTE_P non-zero means S is
8990 multibyte. Display the message multibyte in that case.
8992 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8993 to t before calling set_message_1 (which calls insert).
8997 set_message (s
, string
, nbytes
, multibyte_p
)
9000 int nbytes
, multibyte_p
;
9002 message_enable_multibyte
9003 = ((s
&& multibyte_p
)
9004 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9006 with_echo_area_buffer (0, -1, set_message_1
,
9007 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9008 message_buf_print
= 0;
9009 help_echo_showing_p
= 0;
9013 /* Helper function for set_message. Arguments have the same meaning
9014 as there, with A1 corresponding to S and A2 corresponding to STRING
9015 This function is called with the echo area buffer being
9019 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9022 EMACS_INT nbytes
, multibyte_p
;
9024 const char *s
= (const char *) a1
;
9025 Lisp_Object string
= a2
;
9027 /* Change multibyteness of the echo buffer appropriately. */
9028 if (message_enable_multibyte
9029 != !NILP (current_buffer
->enable_multibyte_characters
))
9030 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9032 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9034 /* Insert new message at BEG. */
9035 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9037 if (STRINGP (string
))
9042 nbytes
= SBYTES (string
);
9043 nchars
= string_byte_to_char (string
, nbytes
);
9045 /* This function takes care of single/multibyte conversion. We
9046 just have to ensure that the echo area buffer has the right
9047 setting of enable_multibyte_characters. */
9048 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9053 nbytes
= strlen (s
);
9055 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9057 /* Convert from multi-byte to single-byte. */
9059 unsigned char work
[1];
9061 /* Convert a multibyte string to single-byte. */
9062 for (i
= 0; i
< nbytes
; i
+= n
)
9064 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
9065 work
[0] = (ASCII_CHAR_P (c
)
9067 : multibyte_char_to_unibyte (c
, Qnil
));
9068 insert_1_both (work
, 1, 1, 1, 0, 0);
9071 else if (!multibyte_p
9072 && !NILP (current_buffer
->enable_multibyte_characters
))
9074 /* Convert from single-byte to multi-byte. */
9076 const unsigned char *msg
= (const unsigned char *) s
;
9077 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9079 /* Convert a single-byte string to multibyte. */
9080 for (i
= 0; i
< nbytes
; i
++)
9083 MAKE_CHAR_MULTIBYTE (c
);
9084 n
= CHAR_STRING (c
, str
);
9085 insert_1_both (str
, 1, n
, 1, 0, 0);
9089 insert_1 (s
, nbytes
, 1, 0, 0);
9096 /* Clear messages. CURRENT_P non-zero means clear the current
9097 message. LAST_DISPLAYED_P non-zero means clear the message
9101 clear_message (current_p
, last_displayed_p
)
9102 int current_p
, last_displayed_p
;
9106 echo_area_buffer
[0] = Qnil
;
9107 message_cleared_p
= 1;
9110 if (last_displayed_p
)
9111 echo_area_buffer
[1] = Qnil
;
9113 message_buf_print
= 0;
9116 /* Clear garbaged frames.
9118 This function is used where the old redisplay called
9119 redraw_garbaged_frames which in turn called redraw_frame which in
9120 turn called clear_frame. The call to clear_frame was a source of
9121 flickering. I believe a clear_frame is not necessary. It should
9122 suffice in the new redisplay to invalidate all current matrices,
9123 and ensure a complete redisplay of all windows. */
9126 clear_garbaged_frames ()
9130 Lisp_Object tail
, frame
;
9131 int changed_count
= 0;
9133 FOR_EACH_FRAME (tail
, frame
)
9135 struct frame
*f
= XFRAME (frame
);
9137 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9141 Fredraw_frame (frame
);
9142 f
->force_flush_display_p
= 1;
9144 clear_current_matrices (f
);
9153 ++windows_or_buffers_changed
;
9158 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9159 is non-zero update selected_frame. Value is non-zero if the
9160 mini-windows height has been changed. */
9163 echo_area_display (update_frame_p
)
9166 Lisp_Object mini_window
;
9169 int window_height_changed_p
= 0;
9170 struct frame
*sf
= SELECTED_FRAME ();
9172 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9173 w
= XWINDOW (mini_window
);
9174 f
= XFRAME (WINDOW_FRAME (w
));
9176 /* Don't display if frame is invisible or not yet initialized. */
9177 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9180 #ifdef HAVE_WINDOW_SYSTEM
9181 /* When Emacs starts, selected_frame may be the initial terminal
9182 frame. If we let this through, a message would be displayed on
9184 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9186 #endif /* HAVE_WINDOW_SYSTEM */
9188 /* Redraw garbaged frames. */
9190 clear_garbaged_frames ();
9192 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9194 echo_area_window
= mini_window
;
9195 window_height_changed_p
= display_echo_area (w
);
9196 w
->must_be_updated_p
= 1;
9198 /* Update the display, unless called from redisplay_internal.
9199 Also don't update the screen during redisplay itself. The
9200 update will happen at the end of redisplay, and an update
9201 here could cause confusion. */
9202 if (update_frame_p
&& !redisplaying_p
)
9206 /* If the display update has been interrupted by pending
9207 input, update mode lines in the frame. Due to the
9208 pending input, it might have been that redisplay hasn't
9209 been called, so that mode lines above the echo area are
9210 garbaged. This looks odd, so we prevent it here. */
9211 if (!display_completed
)
9212 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9214 if (window_height_changed_p
9215 /* Don't do this if Emacs is shutting down. Redisplay
9216 needs to run hooks. */
9217 && !NILP (Vrun_hooks
))
9219 /* Must update other windows. Likewise as in other
9220 cases, don't let this update be interrupted by
9222 int count
= SPECPDL_INDEX ();
9223 specbind (Qredisplay_dont_pause
, Qt
);
9224 windows_or_buffers_changed
= 1;
9225 redisplay_internal (0);
9226 unbind_to (count
, Qnil
);
9228 else if (FRAME_WINDOW_P (f
) && n
== 0)
9230 /* Window configuration is the same as before.
9231 Can do with a display update of the echo area,
9232 unless we displayed some mode lines. */
9233 update_single_window (w
, 1);
9234 FRAME_RIF (f
)->flush_display (f
);
9237 update_frame (f
, 1, 1);
9239 /* If cursor is in the echo area, make sure that the next
9240 redisplay displays the minibuffer, so that the cursor will
9241 be replaced with what the minibuffer wants. */
9242 if (cursor_in_echo_area
)
9243 ++windows_or_buffers_changed
;
9246 else if (!EQ (mini_window
, selected_window
))
9247 windows_or_buffers_changed
++;
9249 /* Last displayed message is now the current message. */
9250 echo_area_buffer
[1] = echo_area_buffer
[0];
9251 /* Inform read_char that we're not echoing. */
9252 echo_message_buffer
= Qnil
;
9254 /* Prevent redisplay optimization in redisplay_internal by resetting
9255 this_line_start_pos. This is done because the mini-buffer now
9256 displays the message instead of its buffer text. */
9257 if (EQ (mini_window
, selected_window
))
9258 CHARPOS (this_line_start_pos
) = 0;
9260 return window_height_changed_p
;
9265 /***********************************************************************
9266 Mode Lines and Frame Titles
9267 ***********************************************************************/
9269 /* A buffer for constructing non-propertized mode-line strings and
9270 frame titles in it; allocated from the heap in init_xdisp and
9271 resized as needed in store_mode_line_noprop_char. */
9273 static char *mode_line_noprop_buf
;
9275 /* The buffer's end, and a current output position in it. */
9277 static char *mode_line_noprop_buf_end
;
9278 static char *mode_line_noprop_ptr
;
9280 #define MODE_LINE_NOPROP_LEN(start) \
9281 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9284 MODE_LINE_DISPLAY
= 0,
9290 /* Alist that caches the results of :propertize.
9291 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9292 static Lisp_Object mode_line_proptrans_alist
;
9294 /* List of strings making up the mode-line. */
9295 static Lisp_Object mode_line_string_list
;
9297 /* Base face property when building propertized mode line string. */
9298 static Lisp_Object mode_line_string_face
;
9299 static Lisp_Object mode_line_string_face_prop
;
9302 /* Unwind data for mode line strings */
9304 static Lisp_Object Vmode_line_unwind_vector
;
9307 format_mode_line_unwind_data (struct buffer
*obuf
,
9311 Lisp_Object vector
, tmp
;
9313 /* Reduce consing by keeping one vector in
9314 Vwith_echo_area_save_vector. */
9315 vector
= Vmode_line_unwind_vector
;
9316 Vmode_line_unwind_vector
= Qnil
;
9319 vector
= Fmake_vector (make_number (8), Qnil
);
9321 ASET (vector
, 0, make_number (mode_line_target
));
9322 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9323 ASET (vector
, 2, mode_line_string_list
);
9324 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9325 ASET (vector
, 4, mode_line_string_face
);
9326 ASET (vector
, 5, mode_line_string_face_prop
);
9329 XSETBUFFER (tmp
, obuf
);
9332 ASET (vector
, 6, tmp
);
9333 ASET (vector
, 7, owin
);
9339 unwind_format_mode_line (vector
)
9342 mode_line_target
= XINT (AREF (vector
, 0));
9343 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9344 mode_line_string_list
= AREF (vector
, 2);
9345 if (! EQ (AREF (vector
, 3), Qt
))
9346 mode_line_proptrans_alist
= AREF (vector
, 3);
9347 mode_line_string_face
= AREF (vector
, 4);
9348 mode_line_string_face_prop
= AREF (vector
, 5);
9350 if (!NILP (AREF (vector
, 7)))
9351 /* Select window before buffer, since it may change the buffer. */
9352 Fselect_window (AREF (vector
, 7), Qt
);
9354 if (!NILP (AREF (vector
, 6)))
9356 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9357 ASET (vector
, 6, Qnil
);
9360 Vmode_line_unwind_vector
= vector
;
9365 /* Store a single character C for the frame title in mode_line_noprop_buf.
9366 Re-allocate mode_line_noprop_buf if necessary. */
9370 store_mode_line_noprop_char (char c
)
9372 store_mode_line_noprop_char (c
)
9376 /* If output position has reached the end of the allocated buffer,
9377 double the buffer's size. */
9378 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9380 int len
= MODE_LINE_NOPROP_LEN (0);
9381 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9382 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9383 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9384 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9387 *mode_line_noprop_ptr
++ = c
;
9391 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9392 mode_line_noprop_ptr. STR is the string to store. Do not copy
9393 characters that yield more columns than PRECISION; PRECISION <= 0
9394 means copy the whole string. Pad with spaces until FIELD_WIDTH
9395 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9396 pad. Called from display_mode_element when it is used to build a
9400 store_mode_line_noprop (str
, field_width
, precision
)
9401 const unsigned char *str
;
9402 int field_width
, precision
;
9407 /* Copy at most PRECISION chars from STR. */
9408 nbytes
= strlen (str
);
9409 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9411 store_mode_line_noprop_char (*str
++);
9413 /* Fill up with spaces until FIELD_WIDTH reached. */
9414 while (field_width
> 0
9417 store_mode_line_noprop_char (' ');
9424 /***********************************************************************
9426 ***********************************************************************/
9428 #ifdef HAVE_WINDOW_SYSTEM
9430 /* Set the title of FRAME, if it has changed. The title format is
9431 Vicon_title_format if FRAME is iconified, otherwise it is
9432 frame_title_format. */
9435 x_consider_frame_title (frame
)
9438 struct frame
*f
= XFRAME (frame
);
9440 if (FRAME_WINDOW_P (f
)
9441 || FRAME_MINIBUF_ONLY_P (f
)
9442 || f
->explicit_name
)
9444 /* Do we have more than one visible frame on this X display? */
9451 int count
= SPECPDL_INDEX ();
9453 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9455 Lisp_Object other_frame
= XCAR (tail
);
9456 struct frame
*tf
= XFRAME (other_frame
);
9459 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9460 && !FRAME_MINIBUF_ONLY_P (tf
)
9461 && !EQ (other_frame
, tip_frame
)
9462 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9466 /* Set global variable indicating that multiple frames exist. */
9467 multiple_frames
= CONSP (tail
);
9469 /* Switch to the buffer of selected window of the frame. Set up
9470 mode_line_target so that display_mode_element will output into
9471 mode_line_noprop_buf; then display the title. */
9472 record_unwind_protect (unwind_format_mode_line
,
9473 format_mode_line_unwind_data
9474 (current_buffer
, selected_window
, 0));
9476 Fselect_window (f
->selected_window
, Qt
);
9477 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9478 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9480 mode_line_target
= MODE_LINE_TITLE
;
9481 title_start
= MODE_LINE_NOPROP_LEN (0);
9482 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9483 NULL
, DEFAULT_FACE_ID
);
9484 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9485 len
= MODE_LINE_NOPROP_LEN (title_start
);
9486 title
= mode_line_noprop_buf
+ title_start
;
9487 unbind_to (count
, Qnil
);
9489 /* Set the title only if it's changed. This avoids consing in
9490 the common case where it hasn't. (If it turns out that we've
9491 already wasted too much time by walking through the list with
9492 display_mode_element, then we might need to optimize at a
9493 higher level than this.) */
9494 if (! STRINGP (f
->name
)
9495 || SBYTES (f
->name
) != len
9496 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9501 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9504 ns_set_name_as_filename (f
);
9506 x_implicitly_set_name (f
, make_string(title
, len
),
9512 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9517 /* do this also for frames with explicit names */
9518 ns_implicitly_set_icon_type(f
);
9519 ns_set_doc_edited(f
, Fbuffer_modified_p
9520 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9526 #endif /* not HAVE_WINDOW_SYSTEM */
9531 /***********************************************************************
9533 ***********************************************************************/
9536 /* Prepare for redisplay by updating menu-bar item lists when
9537 appropriate. This can call eval. */
9540 prepare_menu_bars ()
9543 struct gcpro gcpro1
, gcpro2
;
9545 Lisp_Object tooltip_frame
;
9547 #ifdef HAVE_WINDOW_SYSTEM
9548 tooltip_frame
= tip_frame
;
9550 tooltip_frame
= Qnil
;
9553 /* Update all frame titles based on their buffer names, etc. We do
9554 this before the menu bars so that the buffer-menu will show the
9555 up-to-date frame titles. */
9556 #ifdef HAVE_WINDOW_SYSTEM
9557 if (windows_or_buffers_changed
|| update_mode_lines
)
9559 Lisp_Object tail
, frame
;
9561 FOR_EACH_FRAME (tail
, frame
)
9564 if (!EQ (frame
, tooltip_frame
)
9565 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9566 x_consider_frame_title (frame
);
9569 #endif /* HAVE_WINDOW_SYSTEM */
9571 /* Update the menu bar item lists, if appropriate. This has to be
9572 done before any actual redisplay or generation of display lines. */
9573 all_windows
= (update_mode_lines
9574 || buffer_shared
> 1
9575 || windows_or_buffers_changed
);
9578 Lisp_Object tail
, frame
;
9579 int count
= SPECPDL_INDEX ();
9580 /* 1 means that update_menu_bar has run its hooks
9581 so any further calls to update_menu_bar shouldn't do so again. */
9582 int menu_bar_hooks_run
= 0;
9584 record_unwind_save_match_data ();
9586 FOR_EACH_FRAME (tail
, frame
)
9590 /* Ignore tooltip frame. */
9591 if (EQ (frame
, tooltip_frame
))
9594 /* If a window on this frame changed size, report that to
9595 the user and clear the size-change flag. */
9596 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9598 Lisp_Object functions
;
9600 /* Clear flag first in case we get an error below. */
9601 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9602 functions
= Vwindow_size_change_functions
;
9603 GCPRO2 (tail
, functions
);
9605 while (CONSP (functions
))
9607 if (!EQ (XCAR (functions
), Qt
))
9608 call1 (XCAR (functions
), frame
);
9609 functions
= XCDR (functions
);
9615 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9616 #ifdef HAVE_WINDOW_SYSTEM
9617 update_tool_bar (f
, 0);
9622 unbind_to (count
, Qnil
);
9626 struct frame
*sf
= SELECTED_FRAME ();
9627 update_menu_bar (sf
, 1, 0);
9628 #ifdef HAVE_WINDOW_SYSTEM
9629 update_tool_bar (sf
, 1);
9633 /* Motif needs this. See comment in xmenu.c. Turn it off when
9634 pending_menu_activation is not defined. */
9635 #ifdef USE_X_TOOLKIT
9636 pending_menu_activation
= 0;
9641 /* Update the menu bar item list for frame F. This has to be done
9642 before we start to fill in any display lines, because it can call
9645 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9647 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9648 already ran the menu bar hooks for this redisplay, so there
9649 is no need to run them again. The return value is the
9650 updated value of this flag, to pass to the next call. */
9653 update_menu_bar (f
, save_match_data
, hooks_run
)
9655 int save_match_data
;
9659 register struct window
*w
;
9661 /* If called recursively during a menu update, do nothing. This can
9662 happen when, for instance, an activate-menubar-hook causes a
9664 if (inhibit_menubar_update
)
9667 window
= FRAME_SELECTED_WINDOW (f
);
9668 w
= XWINDOW (window
);
9670 if (FRAME_WINDOW_P (f
)
9672 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9673 || defined (HAVE_NS) || defined (USE_GTK)
9674 FRAME_EXTERNAL_MENU_BAR (f
)
9676 FRAME_MENU_BAR_LINES (f
) > 0
9678 : FRAME_MENU_BAR_LINES (f
) > 0)
9680 /* If the user has switched buffers or windows, we need to
9681 recompute to reflect the new bindings. But we'll
9682 recompute when update_mode_lines is set too; that means
9683 that people can use force-mode-line-update to request
9684 that the menu bar be recomputed. The adverse effect on
9685 the rest of the redisplay algorithm is about the same as
9686 windows_or_buffers_changed anyway. */
9687 if (windows_or_buffers_changed
9688 /* This used to test w->update_mode_line, but we believe
9689 there is no need to recompute the menu in that case. */
9690 || update_mode_lines
9691 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9692 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9693 != !NILP (w
->last_had_star
))
9694 || ((!NILP (Vtransient_mark_mode
)
9695 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9696 != !NILP (w
->region_showing
)))
9698 struct buffer
*prev
= current_buffer
;
9699 int count
= SPECPDL_INDEX ();
9701 specbind (Qinhibit_menubar_update
, Qt
);
9703 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9704 if (save_match_data
)
9705 record_unwind_save_match_data ();
9706 if (NILP (Voverriding_local_map_menu_flag
))
9708 specbind (Qoverriding_terminal_local_map
, Qnil
);
9709 specbind (Qoverriding_local_map
, Qnil
);
9714 /* Run the Lucid hook. */
9715 safe_run_hooks (Qactivate_menubar_hook
);
9717 /* If it has changed current-menubar from previous value,
9718 really recompute the menu-bar from the value. */
9719 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9720 call0 (Qrecompute_lucid_menubar
);
9722 safe_run_hooks (Qmenu_bar_update_hook
);
9727 XSETFRAME (Vmenu_updating_frame
, f
);
9728 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9730 /* Redisplay the menu bar in case we changed it. */
9731 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9732 || defined (HAVE_NS) || defined (USE_GTK)
9733 if (FRAME_WINDOW_P (f
))
9735 #if defined (HAVE_NS)
9736 /* All frames on Mac OS share the same menubar. So only
9737 the selected frame should be allowed to set it. */
9738 if (f
== SELECTED_FRAME ())
9740 set_frame_menubar (f
, 0, 0);
9743 /* On a terminal screen, the menu bar is an ordinary screen
9744 line, and this makes it get updated. */
9745 w
->update_mode_line
= Qt
;
9746 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9747 /* In the non-toolkit version, the menu bar is an ordinary screen
9748 line, and this makes it get updated. */
9749 w
->update_mode_line
= Qt
;
9750 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9752 unbind_to (count
, Qnil
);
9753 set_buffer_internal_1 (prev
);
9762 /***********************************************************************
9764 ***********************************************************************/
9766 #ifdef HAVE_WINDOW_SYSTEM
9769 Nominal cursor position -- where to draw output.
9770 HPOS and VPOS are window relative glyph matrix coordinates.
9771 X and Y are window relative pixel coordinates. */
9773 struct cursor_pos output_cursor
;
9777 Set the global variable output_cursor to CURSOR. All cursor
9778 positions are relative to updated_window. */
9781 set_output_cursor (cursor
)
9782 struct cursor_pos
*cursor
;
9784 output_cursor
.hpos
= cursor
->hpos
;
9785 output_cursor
.vpos
= cursor
->vpos
;
9786 output_cursor
.x
= cursor
->x
;
9787 output_cursor
.y
= cursor
->y
;
9792 Set a nominal cursor position.
9794 HPOS and VPOS are column/row positions in a window glyph matrix. X
9795 and Y are window text area relative pixel positions.
9797 If this is done during an update, updated_window will contain the
9798 window that is being updated and the position is the future output
9799 cursor position for that window. If updated_window is null, use
9800 selected_window and display the cursor at the given position. */
9803 x_cursor_to (vpos
, hpos
, y
, x
)
9804 int vpos
, hpos
, y
, x
;
9808 /* If updated_window is not set, work on selected_window. */
9812 w
= XWINDOW (selected_window
);
9814 /* Set the output cursor. */
9815 output_cursor
.hpos
= hpos
;
9816 output_cursor
.vpos
= vpos
;
9817 output_cursor
.x
= x
;
9818 output_cursor
.y
= y
;
9820 /* If not called as part of an update, really display the cursor.
9821 This will also set the cursor position of W. */
9822 if (updated_window
== NULL
)
9825 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9826 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9827 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9832 #endif /* HAVE_WINDOW_SYSTEM */
9835 /***********************************************************************
9837 ***********************************************************************/
9839 #ifdef HAVE_WINDOW_SYSTEM
9841 /* Where the mouse was last time we reported a mouse event. */
9843 FRAME_PTR last_mouse_frame
;
9845 /* Tool-bar item index of the item on which a mouse button was pressed
9848 int last_tool_bar_item
;
9852 update_tool_bar_unwind (frame
)
9855 selected_frame
= frame
;
9859 /* Update the tool-bar item list for frame F. This has to be done
9860 before we start to fill in any display lines. Called from
9861 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9862 and restore it here. */
9865 update_tool_bar (f
, save_match_data
)
9867 int save_match_data
;
9869 #if defined (USE_GTK) || defined (HAVE_NS)
9870 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9872 int do_update
= WINDOWP (f
->tool_bar_window
)
9873 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9881 window
= FRAME_SELECTED_WINDOW (f
);
9882 w
= XWINDOW (window
);
9884 /* If the user has switched buffers or windows, we need to
9885 recompute to reflect the new bindings. But we'll
9886 recompute when update_mode_lines is set too; that means
9887 that people can use force-mode-line-update to request
9888 that the menu bar be recomputed. The adverse effect on
9889 the rest of the redisplay algorithm is about the same as
9890 windows_or_buffers_changed anyway. */
9891 if (windows_or_buffers_changed
9892 || !NILP (w
->update_mode_line
)
9893 || update_mode_lines
9894 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9895 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9896 != !NILP (w
->last_had_star
))
9897 || ((!NILP (Vtransient_mark_mode
)
9898 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9899 != !NILP (w
->region_showing
)))
9901 struct buffer
*prev
= current_buffer
;
9902 int count
= SPECPDL_INDEX ();
9903 Lisp_Object frame
, new_tool_bar
;
9905 struct gcpro gcpro1
;
9907 /* Set current_buffer to the buffer of the selected
9908 window of the frame, so that we get the right local
9910 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9912 /* Save match data, if we must. */
9913 if (save_match_data
)
9914 record_unwind_save_match_data ();
9916 /* Make sure that we don't accidentally use bogus keymaps. */
9917 if (NILP (Voverriding_local_map_menu_flag
))
9919 specbind (Qoverriding_terminal_local_map
, Qnil
);
9920 specbind (Qoverriding_local_map
, Qnil
);
9923 GCPRO1 (new_tool_bar
);
9925 /* We must temporarily set the selected frame to this frame
9926 before calling tool_bar_items, because the calculation of
9927 the tool-bar keymap uses the selected frame (see
9928 `tool-bar-make-keymap' in tool-bar.el). */
9929 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
9930 XSETFRAME (frame
, f
);
9931 selected_frame
= frame
;
9933 /* Build desired tool-bar items from keymaps. */
9934 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9937 /* Redisplay the tool-bar if we changed it. */
9938 if (new_n_tool_bar
!= f
->n_tool_bar_items
9939 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9941 /* Redisplay that happens asynchronously due to an expose event
9942 may access f->tool_bar_items. Make sure we update both
9943 variables within BLOCK_INPUT so no such event interrupts. */
9945 f
->tool_bar_items
= new_tool_bar
;
9946 f
->n_tool_bar_items
= new_n_tool_bar
;
9947 w
->update_mode_line
= Qt
;
9953 unbind_to (count
, Qnil
);
9954 set_buffer_internal_1 (prev
);
9960 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9961 F's desired tool-bar contents. F->tool_bar_items must have
9962 been set up previously by calling prepare_menu_bars. */
9965 build_desired_tool_bar_string (f
)
9968 int i
, size
, size_needed
;
9969 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9970 Lisp_Object image
, plist
, props
;
9972 image
= plist
= props
= Qnil
;
9973 GCPRO3 (image
, plist
, props
);
9975 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9976 Otherwise, make a new string. */
9978 /* The size of the string we might be able to reuse. */
9979 size
= (STRINGP (f
->desired_tool_bar_string
)
9980 ? SCHARS (f
->desired_tool_bar_string
)
9983 /* We need one space in the string for each image. */
9984 size_needed
= f
->n_tool_bar_items
;
9986 /* Reuse f->desired_tool_bar_string, if possible. */
9987 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9988 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9992 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9993 Fremove_text_properties (make_number (0), make_number (size
),
9994 props
, f
->desired_tool_bar_string
);
9997 /* Put a `display' property on the string for the images to display,
9998 put a `menu_item' property on tool-bar items with a value that
9999 is the index of the item in F's tool-bar item vector. */
10000 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10002 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10004 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10005 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10006 int hmargin
, vmargin
, relief
, idx
, end
;
10007 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
10009 /* If image is a vector, choose the image according to the
10011 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10012 if (VECTORP (image
))
10016 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10017 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10020 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10021 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10023 xassert (ASIZE (image
) >= idx
);
10024 image
= AREF (image
, idx
);
10029 /* Ignore invalid image specifications. */
10030 if (!valid_image_p (image
))
10033 /* Display the tool-bar button pressed, or depressed. */
10034 plist
= Fcopy_sequence (XCDR (image
));
10036 /* Compute margin and relief to draw. */
10037 relief
= (tool_bar_button_relief
>= 0
10038 ? tool_bar_button_relief
10039 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10040 hmargin
= vmargin
= relief
;
10042 if (INTEGERP (Vtool_bar_button_margin
)
10043 && XINT (Vtool_bar_button_margin
) > 0)
10045 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10046 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10048 else if (CONSP (Vtool_bar_button_margin
))
10050 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10051 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10052 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10054 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10055 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10056 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10059 if (auto_raise_tool_bar_buttons_p
)
10061 /* Add a `:relief' property to the image spec if the item is
10065 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10072 /* If image is selected, display it pressed, i.e. with a
10073 negative relief. If it's not selected, display it with a
10075 plist
= Fplist_put (plist
, QCrelief
,
10077 ? make_number (-relief
)
10078 : make_number (relief
)));
10083 /* Put a margin around the image. */
10084 if (hmargin
|| vmargin
)
10086 if (hmargin
== vmargin
)
10087 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10089 plist
= Fplist_put (plist
, QCmargin
,
10090 Fcons (make_number (hmargin
),
10091 make_number (vmargin
)));
10094 /* If button is not enabled, and we don't have special images
10095 for the disabled state, make the image appear disabled by
10096 applying an appropriate algorithm to it. */
10097 if (!enabled_p
&& idx
< 0)
10098 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10100 /* Put a `display' text property on the string for the image to
10101 display. Put a `menu-item' property on the string that gives
10102 the start of this item's properties in the tool-bar items
10104 image
= Fcons (Qimage
, plist
);
10105 props
= list4 (Qdisplay
, image
,
10106 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10108 /* Let the last image hide all remaining spaces in the tool bar
10109 string. The string can be longer than needed when we reuse a
10110 previous string. */
10111 if (i
+ 1 == f
->n_tool_bar_items
)
10112 end
= SCHARS (f
->desired_tool_bar_string
);
10115 Fadd_text_properties (make_number (i
), make_number (end
),
10116 props
, f
->desired_tool_bar_string
);
10124 /* Display one line of the tool-bar of frame IT->f.
10126 HEIGHT specifies the desired height of the tool-bar line.
10127 If the actual height of the glyph row is less than HEIGHT, the
10128 row's height is increased to HEIGHT, and the icons are centered
10129 vertically in the new height.
10131 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10132 count a final empty row in case the tool-bar width exactly matches
10137 display_tool_bar_line (it
, height
)
10141 struct glyph_row
*row
= it
->glyph_row
;
10142 int max_x
= it
->last_visible_x
;
10143 struct glyph
*last
;
10145 prepare_desired_row (row
);
10146 row
->y
= it
->current_y
;
10148 /* Note that this isn't made use of if the face hasn't a box,
10149 so there's no need to check the face here. */
10150 it
->start_of_box_run_p
= 1;
10152 while (it
->current_x
< max_x
)
10154 int x
, n_glyphs_before
, i
, nglyphs
;
10155 struct it it_before
;
10157 /* Get the next display element. */
10158 if (!get_next_display_element (it
))
10160 /* Don't count empty row if we are counting needed tool-bar lines. */
10161 if (height
< 0 && !it
->hpos
)
10166 /* Produce glyphs. */
10167 n_glyphs_before
= row
->used
[TEXT_AREA
];
10170 PRODUCE_GLYPHS (it
);
10172 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10174 x
= it_before
.current_x
;
10175 while (i
< nglyphs
)
10177 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10179 if (x
+ glyph
->pixel_width
> max_x
)
10181 /* Glyph doesn't fit on line. Backtrack. */
10182 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10184 /* If this is the only glyph on this line, it will never fit on the
10185 toolbar, so skip it. But ensure there is at least one glyph,
10186 so we don't accidentally disable the tool-bar. */
10187 if (n_glyphs_before
== 0
10188 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10194 x
+= glyph
->pixel_width
;
10198 /* Stop at line ends. */
10199 if (ITERATOR_AT_END_OF_LINE_P (it
))
10202 set_iterator_to_next (it
, 1);
10207 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10209 /* Use default face for the border below the tool bar.
10211 FIXME: When auto-resize-tool-bars is grow-only, there is
10212 no additional border below the possibly empty tool-bar lines.
10213 So to make the extra empty lines look "normal", we have to
10214 use the tool-bar face for the border too. */
10215 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10216 it
->face_id
= DEFAULT_FACE_ID
;
10218 extend_face_to_end_of_line (it
);
10219 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10220 last
->right_box_line_p
= 1;
10221 if (last
== row
->glyphs
[TEXT_AREA
])
10222 last
->left_box_line_p
= 1;
10224 /* Make line the desired height and center it vertically. */
10225 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10227 /* Don't add more than one line height. */
10228 height
%= FRAME_LINE_HEIGHT (it
->f
);
10229 it
->max_ascent
+= height
/ 2;
10230 it
->max_descent
+= (height
+ 1) / 2;
10233 compute_line_metrics (it
);
10235 /* If line is empty, make it occupy the rest of the tool-bar. */
10236 if (!row
->displays_text_p
)
10238 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10239 row
->visible_height
= row
->height
;
10240 row
->ascent
= row
->phys_ascent
= 0;
10241 row
->extra_line_spacing
= 0;
10244 row
->full_width_p
= 1;
10245 row
->continued_p
= 0;
10246 row
->truncated_on_left_p
= 0;
10247 row
->truncated_on_right_p
= 0;
10249 it
->current_x
= it
->hpos
= 0;
10250 it
->current_y
+= row
->height
;
10256 /* Max tool-bar height. */
10258 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10259 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10261 /* Value is the number of screen lines needed to make all tool-bar
10262 items of frame F visible. The number of actual rows needed is
10263 returned in *N_ROWS if non-NULL. */
10266 tool_bar_lines_needed (f
, n_rows
)
10270 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10272 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10273 the desired matrix, so use (unused) mode-line row as temporary row to
10274 avoid destroying the first tool-bar row. */
10275 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10277 /* Initialize an iterator for iteration over
10278 F->desired_tool_bar_string in the tool-bar window of frame F. */
10279 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10280 it
.first_visible_x
= 0;
10281 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10282 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10284 while (!ITERATOR_AT_END_P (&it
))
10286 clear_glyph_row (temp_row
);
10287 it
.glyph_row
= temp_row
;
10288 display_tool_bar_line (&it
, -1);
10290 clear_glyph_row (temp_row
);
10292 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10294 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10296 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10300 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10302 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10311 frame
= selected_frame
;
10313 CHECK_FRAME (frame
);
10314 f
= XFRAME (frame
);
10316 if (WINDOWP (f
->tool_bar_window
)
10317 || (w
= XWINDOW (f
->tool_bar_window
),
10318 WINDOW_TOTAL_LINES (w
) > 0))
10320 update_tool_bar (f
, 1);
10321 if (f
->n_tool_bar_items
)
10323 build_desired_tool_bar_string (f
);
10324 nlines
= tool_bar_lines_needed (f
, NULL
);
10328 return make_number (nlines
);
10332 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10333 height should be changed. */
10336 redisplay_tool_bar (f
)
10341 struct glyph_row
*row
;
10343 #if defined (USE_GTK) || defined (HAVE_NS)
10344 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10345 update_frame_tool_bar (f
);
10349 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10350 do anything. This means you must start with tool-bar-lines
10351 non-zero to get the auto-sizing effect. Or in other words, you
10352 can turn off tool-bars by specifying tool-bar-lines zero. */
10353 if (!WINDOWP (f
->tool_bar_window
)
10354 || (w
= XWINDOW (f
->tool_bar_window
),
10355 WINDOW_TOTAL_LINES (w
) == 0))
10358 /* Set up an iterator for the tool-bar window. */
10359 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10360 it
.first_visible_x
= 0;
10361 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10362 row
= it
.glyph_row
;
10364 /* Build a string that represents the contents of the tool-bar. */
10365 build_desired_tool_bar_string (f
);
10366 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10368 if (f
->n_tool_bar_rows
== 0)
10372 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10373 nlines
!= WINDOW_TOTAL_LINES (w
)))
10375 extern Lisp_Object Qtool_bar_lines
;
10377 int old_height
= WINDOW_TOTAL_LINES (w
);
10379 XSETFRAME (frame
, f
);
10380 Fmodify_frame_parameters (frame
,
10381 Fcons (Fcons (Qtool_bar_lines
,
10382 make_number (nlines
)),
10384 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10386 clear_glyph_matrix (w
->desired_matrix
);
10387 fonts_changed_p
= 1;
10393 /* Display as many lines as needed to display all tool-bar items. */
10395 if (f
->n_tool_bar_rows
> 0)
10397 int border
, rows
, height
, extra
;
10399 if (INTEGERP (Vtool_bar_border
))
10400 border
= XINT (Vtool_bar_border
);
10401 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10402 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10403 else if (EQ (Vtool_bar_border
, Qborder_width
))
10404 border
= f
->border_width
;
10410 rows
= f
->n_tool_bar_rows
;
10411 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10412 extra
= it
.last_visible_y
- border
- height
* rows
;
10414 while (it
.current_y
< it
.last_visible_y
)
10417 if (extra
> 0 && rows
-- > 0)
10419 h
= (extra
+ rows
- 1) / rows
;
10422 display_tool_bar_line (&it
, height
+ h
);
10427 while (it
.current_y
< it
.last_visible_y
)
10428 display_tool_bar_line (&it
, 0);
10431 /* It doesn't make much sense to try scrolling in the tool-bar
10432 window, so don't do it. */
10433 w
->desired_matrix
->no_scrolling_p
= 1;
10434 w
->must_be_updated_p
= 1;
10436 if (!NILP (Vauto_resize_tool_bars
))
10438 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10439 int change_height_p
= 0;
10441 /* If we couldn't display everything, change the tool-bar's
10442 height if there is room for more. */
10443 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10444 && it
.current_y
< max_tool_bar_height
)
10445 change_height_p
= 1;
10447 row
= it
.glyph_row
- 1;
10449 /* If there are blank lines at the end, except for a partially
10450 visible blank line at the end that is smaller than
10451 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10452 if (!row
->displays_text_p
10453 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10454 change_height_p
= 1;
10456 /* If row displays tool-bar items, but is partially visible,
10457 change the tool-bar's height. */
10458 if (row
->displays_text_p
10459 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10460 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10461 change_height_p
= 1;
10463 /* Resize windows as needed by changing the `tool-bar-lines'
10464 frame parameter. */
10465 if (change_height_p
)
10467 extern Lisp_Object Qtool_bar_lines
;
10469 int old_height
= WINDOW_TOTAL_LINES (w
);
10471 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10473 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10474 && !f
->minimize_tool_bar_window_p
)
10475 ? (nlines
> old_height
)
10476 : (nlines
!= old_height
));
10477 f
->minimize_tool_bar_window_p
= 0;
10479 if (change_height_p
)
10481 XSETFRAME (frame
, f
);
10482 Fmodify_frame_parameters (frame
,
10483 Fcons (Fcons (Qtool_bar_lines
,
10484 make_number (nlines
)),
10486 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10488 clear_glyph_matrix (w
->desired_matrix
);
10489 f
->n_tool_bar_rows
= nrows
;
10490 fonts_changed_p
= 1;
10497 f
->minimize_tool_bar_window_p
= 0;
10502 /* Get information about the tool-bar item which is displayed in GLYPH
10503 on frame F. Return in *PROP_IDX the index where tool-bar item
10504 properties start in F->tool_bar_items. Value is zero if
10505 GLYPH doesn't display a tool-bar item. */
10508 tool_bar_item_info (f
, glyph
, prop_idx
)
10510 struct glyph
*glyph
;
10517 /* This function can be called asynchronously, which means we must
10518 exclude any possibility that Fget_text_property signals an
10520 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10521 charpos
= max (0, charpos
);
10523 /* Get the text property `menu-item' at pos. The value of that
10524 property is the start index of this item's properties in
10525 F->tool_bar_items. */
10526 prop
= Fget_text_property (make_number (charpos
),
10527 Qmenu_item
, f
->current_tool_bar_string
);
10528 if (INTEGERP (prop
))
10530 *prop_idx
= XINT (prop
);
10540 /* Get information about the tool-bar item at position X/Y on frame F.
10541 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10542 the current matrix of the tool-bar window of F, or NULL if not
10543 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10544 item in F->tool_bar_items. Value is
10546 -1 if X/Y is not on a tool-bar item
10547 0 if X/Y is on the same item that was highlighted before.
10551 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10554 struct glyph
**glyph
;
10555 int *hpos
, *vpos
, *prop_idx
;
10557 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10558 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10561 /* Find the glyph under X/Y. */
10562 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10563 if (*glyph
== NULL
)
10566 /* Get the start of this tool-bar item's properties in
10567 f->tool_bar_items. */
10568 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10571 /* Is mouse on the highlighted item? */
10572 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10573 && *vpos
>= dpyinfo
->mouse_face_beg_row
10574 && *vpos
<= dpyinfo
->mouse_face_end_row
10575 && (*vpos
> dpyinfo
->mouse_face_beg_row
10576 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10577 && (*vpos
< dpyinfo
->mouse_face_end_row
10578 || *hpos
< dpyinfo
->mouse_face_end_col
10579 || dpyinfo
->mouse_face_past_end
))
10587 Handle mouse button event on the tool-bar of frame F, at
10588 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10589 0 for button release. MODIFIERS is event modifiers for button
10593 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10596 unsigned int modifiers
;
10598 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10599 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10600 int hpos
, vpos
, prop_idx
;
10601 struct glyph
*glyph
;
10602 Lisp_Object enabled_p
;
10604 /* If not on the highlighted tool-bar item, return. */
10605 frame_to_window_pixel_xy (w
, &x
, &y
);
10606 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10609 /* If item is disabled, do nothing. */
10610 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10611 if (NILP (enabled_p
))
10616 /* Show item in pressed state. */
10617 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10618 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10619 last_tool_bar_item
= prop_idx
;
10623 Lisp_Object key
, frame
;
10624 struct input_event event
;
10625 EVENT_INIT (event
);
10627 /* Show item in released state. */
10628 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10629 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10631 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10633 XSETFRAME (frame
, f
);
10634 event
.kind
= TOOL_BAR_EVENT
;
10635 event
.frame_or_window
= frame
;
10637 kbd_buffer_store_event (&event
);
10639 event
.kind
= TOOL_BAR_EVENT
;
10640 event
.frame_or_window
= frame
;
10642 event
.modifiers
= modifiers
;
10643 kbd_buffer_store_event (&event
);
10644 last_tool_bar_item
= -1;
10649 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10650 tool-bar window-relative coordinates X/Y. Called from
10651 note_mouse_highlight. */
10654 note_tool_bar_highlight (f
, x
, y
)
10658 Lisp_Object window
= f
->tool_bar_window
;
10659 struct window
*w
= XWINDOW (window
);
10660 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10662 struct glyph
*glyph
;
10663 struct glyph_row
*row
;
10665 Lisp_Object enabled_p
;
10667 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10668 int mouse_down_p
, rc
;
10670 /* Function note_mouse_highlight is called with negative x(y
10671 values when mouse moves outside of the frame. */
10672 if (x
<= 0 || y
<= 0)
10674 clear_mouse_face (dpyinfo
);
10678 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10681 /* Not on tool-bar item. */
10682 clear_mouse_face (dpyinfo
);
10686 /* On same tool-bar item as before. */
10687 goto set_help_echo
;
10689 clear_mouse_face (dpyinfo
);
10691 /* Mouse is down, but on different tool-bar item? */
10692 mouse_down_p
= (dpyinfo
->grabbed
10693 && f
== last_mouse_frame
10694 && FRAME_LIVE_P (f
));
10696 && last_tool_bar_item
!= prop_idx
)
10699 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10700 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10702 /* If tool-bar item is not enabled, don't highlight it. */
10703 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10704 if (!NILP (enabled_p
))
10706 /* Compute the x-position of the glyph. In front and past the
10707 image is a space. We include this in the highlighted area. */
10708 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10709 for (i
= x
= 0; i
< hpos
; ++i
)
10710 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10712 /* Record this as the current active region. */
10713 dpyinfo
->mouse_face_beg_col
= hpos
;
10714 dpyinfo
->mouse_face_beg_row
= vpos
;
10715 dpyinfo
->mouse_face_beg_x
= x
;
10716 dpyinfo
->mouse_face_beg_y
= row
->y
;
10717 dpyinfo
->mouse_face_past_end
= 0;
10719 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10720 dpyinfo
->mouse_face_end_row
= vpos
;
10721 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10722 dpyinfo
->mouse_face_end_y
= row
->y
;
10723 dpyinfo
->mouse_face_window
= window
;
10724 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10726 /* Display it as active. */
10727 show_mouse_face (dpyinfo
, draw
);
10728 dpyinfo
->mouse_face_image_state
= draw
;
10733 /* Set help_echo_string to a help string to display for this tool-bar item.
10734 XTread_socket does the rest. */
10735 help_echo_object
= help_echo_window
= Qnil
;
10736 help_echo_pos
= -1;
10737 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10738 if (NILP (help_echo_string
))
10739 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10742 #endif /* HAVE_WINDOW_SYSTEM */
10746 /************************************************************************
10747 Horizontal scrolling
10748 ************************************************************************/
10750 static int hscroll_window_tree
P_ ((Lisp_Object
));
10751 static int hscroll_windows
P_ ((Lisp_Object
));
10753 /* For all leaf windows in the window tree rooted at WINDOW, set their
10754 hscroll value so that PT is (i) visible in the window, and (ii) so
10755 that it is not within a certain margin at the window's left and
10756 right border. Value is non-zero if any window's hscroll has been
10760 hscroll_window_tree (window
)
10761 Lisp_Object window
;
10763 int hscrolled_p
= 0;
10764 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10765 int hscroll_step_abs
= 0;
10766 double hscroll_step_rel
= 0;
10768 if (hscroll_relative_p
)
10770 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10771 if (hscroll_step_rel
< 0)
10773 hscroll_relative_p
= 0;
10774 hscroll_step_abs
= 0;
10777 else if (INTEGERP (Vhscroll_step
))
10779 hscroll_step_abs
= XINT (Vhscroll_step
);
10780 if (hscroll_step_abs
< 0)
10781 hscroll_step_abs
= 0;
10784 hscroll_step_abs
= 0;
10786 while (WINDOWP (window
))
10788 struct window
*w
= XWINDOW (window
);
10790 if (WINDOWP (w
->hchild
))
10791 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10792 else if (WINDOWP (w
->vchild
))
10793 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10794 else if (w
->cursor
.vpos
>= 0)
10797 int text_area_width
;
10798 struct glyph_row
*current_cursor_row
10799 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10800 struct glyph_row
*desired_cursor_row
10801 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10802 struct glyph_row
*cursor_row
10803 = (desired_cursor_row
->enabled_p
10804 ? desired_cursor_row
10805 : current_cursor_row
);
10807 text_area_width
= window_box_width (w
, TEXT_AREA
);
10809 /* Scroll when cursor is inside this scroll margin. */
10810 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10812 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10813 && ((XFASTINT (w
->hscroll
)
10814 && w
->cursor
.x
<= h_margin
)
10815 || (cursor_row
->enabled_p
10816 && cursor_row
->truncated_on_right_p
10817 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10821 struct buffer
*saved_current_buffer
;
10825 /* Find point in a display of infinite width. */
10826 saved_current_buffer
= current_buffer
;
10827 current_buffer
= XBUFFER (w
->buffer
);
10829 if (w
== XWINDOW (selected_window
))
10830 pt
= BUF_PT (current_buffer
);
10833 pt
= marker_position (w
->pointm
);
10834 pt
= max (BEGV
, pt
);
10838 /* Move iterator to pt starting at cursor_row->start in
10839 a line with infinite width. */
10840 init_to_row_start (&it
, w
, cursor_row
);
10841 it
.last_visible_x
= INFINITY
;
10842 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10843 current_buffer
= saved_current_buffer
;
10845 /* Position cursor in window. */
10846 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10847 hscroll
= max (0, (it
.current_x
10848 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10849 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10850 : (text_area_width
/ 2))))
10851 / FRAME_COLUMN_WIDTH (it
.f
);
10852 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10854 if (hscroll_relative_p
)
10855 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10858 wanted_x
= text_area_width
10859 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10862 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10866 if (hscroll_relative_p
)
10867 wanted_x
= text_area_width
* hscroll_step_rel
10870 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10873 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10875 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10877 /* Don't call Fset_window_hscroll if value hasn't
10878 changed because it will prevent redisplay
10880 if (XFASTINT (w
->hscroll
) != hscroll
)
10882 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10883 w
->hscroll
= make_number (hscroll
);
10892 /* Value is non-zero if hscroll of any leaf window has been changed. */
10893 return hscrolled_p
;
10897 /* Set hscroll so that cursor is visible and not inside horizontal
10898 scroll margins for all windows in the tree rooted at WINDOW. See
10899 also hscroll_window_tree above. Value is non-zero if any window's
10900 hscroll has been changed. If it has, desired matrices on the frame
10901 of WINDOW are cleared. */
10904 hscroll_windows (window
)
10905 Lisp_Object window
;
10907 int hscrolled_p
= hscroll_window_tree (window
);
10909 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10910 return hscrolled_p
;
10915 /************************************************************************
10917 ************************************************************************/
10919 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10920 to a non-zero value. This is sometimes handy to have in a debugger
10925 /* First and last unchanged row for try_window_id. */
10927 int debug_first_unchanged_at_end_vpos
;
10928 int debug_last_unchanged_at_beg_vpos
;
10930 /* Delta vpos and y. */
10932 int debug_dvpos
, debug_dy
;
10934 /* Delta in characters and bytes for try_window_id. */
10936 int debug_delta
, debug_delta_bytes
;
10938 /* Values of window_end_pos and window_end_vpos at the end of
10941 EMACS_INT debug_end_pos
, debug_end_vpos
;
10943 /* Append a string to W->desired_matrix->method. FMT is a printf
10944 format string. A1...A9 are a supplement for a variable-length
10945 argument list. If trace_redisplay_p is non-zero also printf the
10946 resulting string to stderr. */
10949 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10952 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10955 char *method
= w
->desired_matrix
->method
;
10956 int len
= strlen (method
);
10957 int size
= sizeof w
->desired_matrix
->method
;
10958 int remaining
= size
- len
- 1;
10960 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10961 if (len
&& remaining
)
10964 --remaining
, ++len
;
10967 strncpy (method
+ len
, buffer
, remaining
);
10969 if (trace_redisplay_p
)
10970 fprintf (stderr
, "%p (%s): %s\n",
10972 ((BUFFERP (w
->buffer
)
10973 && STRINGP (XBUFFER (w
->buffer
)->name
))
10974 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10979 #endif /* GLYPH_DEBUG */
10982 /* Value is non-zero if all changes in window W, which displays
10983 current_buffer, are in the text between START and END. START is a
10984 buffer position, END is given as a distance from Z. Used in
10985 redisplay_internal for display optimization. */
10988 text_outside_line_unchanged_p (w
, start
, end
)
10992 int unchanged_p
= 1;
10994 /* If text or overlays have changed, see where. */
10995 if (XFASTINT (w
->last_modified
) < MODIFF
10996 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10998 /* Gap in the line? */
10999 if (GPT
< start
|| Z
- GPT
< end
)
11002 /* Changes start in front of the line, or end after it? */
11004 && (BEG_UNCHANGED
< start
- 1
11005 || END_UNCHANGED
< end
))
11008 /* If selective display, can't optimize if changes start at the
11009 beginning of the line. */
11011 && INTEGERP (current_buffer
->selective_display
)
11012 && XINT (current_buffer
->selective_display
) > 0
11013 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11016 /* If there are overlays at the start or end of the line, these
11017 may have overlay strings with newlines in them. A change at
11018 START, for instance, may actually concern the display of such
11019 overlay strings as well, and they are displayed on different
11020 lines. So, quickly rule out this case. (For the future, it
11021 might be desirable to implement something more telling than
11022 just BEG/END_UNCHANGED.) */
11025 if (BEG
+ BEG_UNCHANGED
== start
11026 && overlay_touches_p (start
))
11028 if (END_UNCHANGED
== end
11029 && overlay_touches_p (Z
- end
))
11034 return unchanged_p
;
11038 /* Do a frame update, taking possible shortcuts into account. This is
11039 the main external entry point for redisplay.
11041 If the last redisplay displayed an echo area message and that message
11042 is no longer requested, we clear the echo area or bring back the
11043 mini-buffer if that is in use. */
11048 redisplay_internal (0);
11053 overlay_arrow_string_or_property (var
)
11058 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11061 return Voverlay_arrow_string
;
11064 /* Return 1 if there are any overlay-arrows in current_buffer. */
11066 overlay_arrow_in_current_buffer_p ()
11070 for (vlist
= Voverlay_arrow_variable_list
;
11072 vlist
= XCDR (vlist
))
11074 Lisp_Object var
= XCAR (vlist
);
11077 if (!SYMBOLP (var
))
11079 val
= find_symbol_value (var
);
11081 && current_buffer
== XMARKER (val
)->buffer
)
11088 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11092 overlay_arrows_changed_p ()
11096 for (vlist
= Voverlay_arrow_variable_list
;
11098 vlist
= XCDR (vlist
))
11100 Lisp_Object var
= XCAR (vlist
);
11101 Lisp_Object val
, pstr
;
11103 if (!SYMBOLP (var
))
11105 val
= find_symbol_value (var
);
11106 if (!MARKERP (val
))
11108 if (! EQ (COERCE_MARKER (val
),
11109 Fget (var
, Qlast_arrow_position
))
11110 || ! (pstr
= overlay_arrow_string_or_property (var
),
11111 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11117 /* Mark overlay arrows to be updated on next redisplay. */
11120 update_overlay_arrows (up_to_date
)
11125 for (vlist
= Voverlay_arrow_variable_list
;
11127 vlist
= XCDR (vlist
))
11129 Lisp_Object var
= XCAR (vlist
);
11131 if (!SYMBOLP (var
))
11134 if (up_to_date
> 0)
11136 Lisp_Object val
= find_symbol_value (var
);
11137 Fput (var
, Qlast_arrow_position
,
11138 COERCE_MARKER (val
));
11139 Fput (var
, Qlast_arrow_string
,
11140 overlay_arrow_string_or_property (var
));
11142 else if (up_to_date
< 0
11143 || !NILP (Fget (var
, Qlast_arrow_position
)))
11145 Fput (var
, Qlast_arrow_position
, Qt
);
11146 Fput (var
, Qlast_arrow_string
, Qt
);
11152 /* Return overlay arrow string to display at row.
11153 Return integer (bitmap number) for arrow bitmap in left fringe.
11154 Return nil if no overlay arrow. */
11157 overlay_arrow_at_row (it
, row
)
11159 struct glyph_row
*row
;
11163 for (vlist
= Voverlay_arrow_variable_list
;
11165 vlist
= XCDR (vlist
))
11167 Lisp_Object var
= XCAR (vlist
);
11170 if (!SYMBOLP (var
))
11173 val
= find_symbol_value (var
);
11176 && current_buffer
== XMARKER (val
)->buffer
11177 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11179 if (FRAME_WINDOW_P (it
->f
)
11180 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11182 #ifdef HAVE_WINDOW_SYSTEM
11183 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11186 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11187 return make_number (fringe_bitmap
);
11190 return make_number (-1); /* Use default arrow bitmap */
11192 return overlay_arrow_string_or_property (var
);
11199 /* Return 1 if point moved out of or into a composition. Otherwise
11200 return 0. PREV_BUF and PREV_PT are the last point buffer and
11201 position. BUF and PT are the current point buffer and position. */
11204 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11205 struct buffer
*prev_buf
, *buf
;
11208 EMACS_INT start
, end
;
11210 Lisp_Object buffer
;
11212 XSETBUFFER (buffer
, buf
);
11213 /* Check a composition at the last point if point moved within the
11215 if (prev_buf
== buf
)
11218 /* Point didn't move. */
11221 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11222 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11223 && COMPOSITION_VALID_P (start
, end
, prop
)
11224 && start
< prev_pt
&& end
> prev_pt
)
11225 /* The last point was within the composition. Return 1 iff
11226 point moved out of the composition. */
11227 return (pt
<= start
|| pt
>= end
);
11230 /* Check a composition at the current point. */
11231 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11232 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11233 && COMPOSITION_VALID_P (start
, end
, prop
)
11234 && start
< pt
&& end
> pt
);
11238 /* Reconsider the setting of B->clip_changed which is displayed
11242 reconsider_clip_changes (w
, b
)
11246 if (b
->clip_changed
11247 && !NILP (w
->window_end_valid
)
11248 && w
->current_matrix
->buffer
== b
11249 && w
->current_matrix
->zv
== BUF_ZV (b
)
11250 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11251 b
->clip_changed
= 0;
11253 /* If display wasn't paused, and W is not a tool bar window, see if
11254 point has been moved into or out of a composition. In that case,
11255 we set b->clip_changed to 1 to force updating the screen. If
11256 b->clip_changed has already been set to 1, we can skip this
11258 if (!b
->clip_changed
11259 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11263 if (w
== XWINDOW (selected_window
))
11264 pt
= BUF_PT (current_buffer
);
11266 pt
= marker_position (w
->pointm
);
11268 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11269 || pt
!= XINT (w
->last_point
))
11270 && check_point_in_composition (w
->current_matrix
->buffer
,
11271 XINT (w
->last_point
),
11272 XBUFFER (w
->buffer
), pt
))
11273 b
->clip_changed
= 1;
11278 /* Select FRAME to forward the values of frame-local variables into C
11279 variables so that the redisplay routines can access those values
11283 select_frame_for_redisplay (frame
)
11286 Lisp_Object tail
, symbol
, val
;
11287 Lisp_Object old
= selected_frame
;
11288 struct Lisp_Symbol
*sym
;
11290 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11292 selected_frame
= frame
;
11296 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11297 if (CONSP (XCAR (tail
))
11298 && (symbol
= XCAR (XCAR (tail
)),
11300 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11302 (BUFFER_LOCAL_VALUEP (val
)))
11303 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11304 /* Use find_symbol_value rather than Fsymbol_value
11305 to avoid an error if it is void. */
11306 find_symbol_value (symbol
);
11307 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11311 #define STOP_POLLING \
11312 do { if (! polling_stopped_here) stop_polling (); \
11313 polling_stopped_here = 1; } while (0)
11315 #define RESUME_POLLING \
11316 do { if (polling_stopped_here) start_polling (); \
11317 polling_stopped_here = 0; } while (0)
11320 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11321 response to any user action; therefore, we should preserve the echo
11322 area. (Actually, our caller does that job.) Perhaps in the future
11323 avoid recentering windows if it is not necessary; currently that
11324 causes some problems. */
11327 redisplay_internal (preserve_echo_area
)
11328 int preserve_echo_area
;
11330 struct window
*w
= XWINDOW (selected_window
);
11333 int must_finish
= 0;
11334 struct text_pos tlbufpos
, tlendpos
;
11335 int number_of_visible_frames
;
11338 int polling_stopped_here
= 0;
11339 Lisp_Object old_frame
= selected_frame
;
11341 /* Non-zero means redisplay has to consider all windows on all
11342 frames. Zero means, only selected_window is considered. */
11343 int consider_all_windows_p
;
11345 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11347 /* No redisplay if running in batch mode or frame is not yet fully
11348 initialized, or redisplay is explicitly turned off by setting
11349 Vinhibit_redisplay. */
11350 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11351 || !NILP (Vinhibit_redisplay
))
11354 /* Don't examine these until after testing Vinhibit_redisplay.
11355 When Emacs is shutting down, perhaps because its connection to
11356 X has dropped, we should not look at them at all. */
11357 f
= XFRAME (w
->frame
);
11358 sf
= SELECTED_FRAME ();
11360 if (!f
->glyphs_initialized_p
)
11363 /* The flag redisplay_performed_directly_p is set by
11364 direct_output_for_insert when it already did the whole screen
11365 update necessary. */
11366 if (redisplay_performed_directly_p
)
11368 redisplay_performed_directly_p
= 0;
11369 if (!hscroll_windows (selected_window
))
11373 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11374 if (popup_activated ())
11378 /* I don't think this happens but let's be paranoid. */
11379 if (redisplaying_p
)
11382 /* Record a function that resets redisplaying_p to its old value
11383 when we leave this function. */
11384 count
= SPECPDL_INDEX ();
11385 record_unwind_protect (unwind_redisplay
,
11386 Fcons (make_number (redisplaying_p
), selected_frame
));
11388 specbind (Qinhibit_free_realized_faces
, Qnil
);
11391 Lisp_Object tail
, frame
;
11393 FOR_EACH_FRAME (tail
, frame
)
11395 struct frame
*f
= XFRAME (frame
);
11396 f
->already_hscrolled_p
= 0;
11401 if (!EQ (old_frame
, selected_frame
)
11402 && FRAME_LIVE_P (XFRAME (old_frame
)))
11403 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11404 selected_frame and selected_window to be temporarily out-of-sync so
11405 when we come back here via `goto retry', we need to resync because we
11406 may need to run Elisp code (via prepare_menu_bars). */
11407 select_frame_for_redisplay (old_frame
);
11410 reconsider_clip_changes (w
, current_buffer
);
11411 last_escape_glyph_frame
= NULL
;
11412 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11414 /* If new fonts have been loaded that make a glyph matrix adjustment
11415 necessary, do it. */
11416 if (fonts_changed_p
)
11418 adjust_glyphs (NULL
);
11419 ++windows_or_buffers_changed
;
11420 fonts_changed_p
= 0;
11423 /* If face_change_count is non-zero, init_iterator will free all
11424 realized faces, which includes the faces referenced from current
11425 matrices. So, we can't reuse current matrices in this case. */
11426 if (face_change_count
)
11427 ++windows_or_buffers_changed
;
11429 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11430 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11432 /* Since frames on a single ASCII terminal share the same
11433 display area, displaying a different frame means redisplay
11434 the whole thing. */
11435 windows_or_buffers_changed
++;
11436 SET_FRAME_GARBAGED (sf
);
11438 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11440 FRAME_TTY (sf
)->previous_frame
= sf
;
11443 /* Set the visible flags for all frames. Do this before checking
11444 for resized or garbaged frames; they want to know if their frames
11445 are visible. See the comment in frame.h for
11446 FRAME_SAMPLE_VISIBILITY. */
11448 Lisp_Object tail
, frame
;
11450 number_of_visible_frames
= 0;
11452 FOR_EACH_FRAME (tail
, frame
)
11454 struct frame
*f
= XFRAME (frame
);
11456 FRAME_SAMPLE_VISIBILITY (f
);
11457 if (FRAME_VISIBLE_P (f
))
11458 ++number_of_visible_frames
;
11459 clear_desired_matrices (f
);
11463 /* Notice any pending interrupt request to change frame size. */
11464 do_pending_window_change (1);
11466 /* Clear frames marked as garbaged. */
11467 if (frame_garbaged
)
11468 clear_garbaged_frames ();
11470 /* Build menubar and tool-bar items. */
11471 if (NILP (Vmemory_full
))
11472 prepare_menu_bars ();
11474 if (windows_or_buffers_changed
)
11475 update_mode_lines
++;
11477 /* Detect case that we need to write or remove a star in the mode line. */
11478 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11480 w
->update_mode_line
= Qt
;
11481 if (buffer_shared
> 1)
11482 update_mode_lines
++;
11485 /* Avoid invocation of point motion hooks by `current_column' below. */
11486 count1
= SPECPDL_INDEX ();
11487 specbind (Qinhibit_point_motion_hooks
, Qt
);
11489 /* If %c is in the mode line, update it if needed. */
11490 if (!NILP (w
->column_number_displayed
)
11491 /* This alternative quickly identifies a common case
11492 where no change is needed. */
11493 && !(PT
== XFASTINT (w
->last_point
)
11494 && XFASTINT (w
->last_modified
) >= MODIFF
11495 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11496 && (XFASTINT (w
->column_number_displayed
)
11497 != (int) current_column ())) /* iftc */
11498 w
->update_mode_line
= Qt
;
11500 unbind_to (count1
, Qnil
);
11502 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11504 /* The variable buffer_shared is set in redisplay_window and
11505 indicates that we redisplay a buffer in different windows. See
11507 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11508 || cursor_type_changed
);
11510 /* If specs for an arrow have changed, do thorough redisplay
11511 to ensure we remove any arrow that should no longer exist. */
11512 if (overlay_arrows_changed_p ())
11513 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11515 /* Normally the message* functions will have already displayed and
11516 updated the echo area, but the frame may have been trashed, or
11517 the update may have been preempted, so display the echo area
11518 again here. Checking message_cleared_p captures the case that
11519 the echo area should be cleared. */
11520 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11521 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11522 || (message_cleared_p
11523 && minibuf_level
== 0
11524 /* If the mini-window is currently selected, this means the
11525 echo-area doesn't show through. */
11526 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11528 int window_height_changed_p
= echo_area_display (0);
11531 /* If we don't display the current message, don't clear the
11532 message_cleared_p flag, because, if we did, we wouldn't clear
11533 the echo area in the next redisplay which doesn't preserve
11535 if (!display_last_displayed_message_p
)
11536 message_cleared_p
= 0;
11538 if (fonts_changed_p
)
11540 else if (window_height_changed_p
)
11542 consider_all_windows_p
= 1;
11543 ++update_mode_lines
;
11544 ++windows_or_buffers_changed
;
11546 /* If window configuration was changed, frames may have been
11547 marked garbaged. Clear them or we will experience
11548 surprises wrt scrolling. */
11549 if (frame_garbaged
)
11550 clear_garbaged_frames ();
11553 else if (EQ (selected_window
, minibuf_window
)
11554 && (current_buffer
->clip_changed
11555 || XFASTINT (w
->last_modified
) < MODIFF
11556 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11557 && resize_mini_window (w
, 0))
11559 /* Resized active mini-window to fit the size of what it is
11560 showing if its contents might have changed. */
11562 /* FIXME: this causes all frames to be updated, which seems unnecessary
11563 since only the current frame needs to be considered. This function needs
11564 to be rewritten with two variables, consider_all_windows and
11565 consider_all_frames. */
11566 consider_all_windows_p
= 1;
11567 ++windows_or_buffers_changed
;
11568 ++update_mode_lines
;
11570 /* If window configuration was changed, frames may have been
11571 marked garbaged. Clear them or we will experience
11572 surprises wrt scrolling. */
11573 if (frame_garbaged
)
11574 clear_garbaged_frames ();
11578 /* If showing the region, and mark has changed, we must redisplay
11579 the whole window. The assignment to this_line_start_pos prevents
11580 the optimization directly below this if-statement. */
11581 if (((!NILP (Vtransient_mark_mode
)
11582 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11583 != !NILP (w
->region_showing
))
11584 || (!NILP (w
->region_showing
)
11585 && !EQ (w
->region_showing
,
11586 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11587 CHARPOS (this_line_start_pos
) = 0;
11589 /* Optimize the case that only the line containing the cursor in the
11590 selected window has changed. Variables starting with this_ are
11591 set in display_line and record information about the line
11592 containing the cursor. */
11593 tlbufpos
= this_line_start_pos
;
11594 tlendpos
= this_line_end_pos
;
11595 if (!consider_all_windows_p
11596 && CHARPOS (tlbufpos
) > 0
11597 && NILP (w
->update_mode_line
)
11598 && !current_buffer
->clip_changed
11599 && !current_buffer
->prevent_redisplay_optimizations_p
11600 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11601 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11602 /* Make sure recorded data applies to current buffer, etc. */
11603 && this_line_buffer
== current_buffer
11604 && current_buffer
== XBUFFER (w
->buffer
)
11605 && NILP (w
->force_start
)
11606 && NILP (w
->optional_new_start
)
11607 /* Point must be on the line that we have info recorded about. */
11608 && PT
>= CHARPOS (tlbufpos
)
11609 && PT
<= Z
- CHARPOS (tlendpos
)
11610 /* All text outside that line, including its final newline,
11611 must be unchanged. */
11612 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11613 CHARPOS (tlendpos
)))
11615 if (CHARPOS (tlbufpos
) > BEGV
11616 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11617 && (CHARPOS (tlbufpos
) == ZV
11618 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11619 /* Former continuation line has disappeared by becoming empty. */
11621 else if (XFASTINT (w
->last_modified
) < MODIFF
11622 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11623 || MINI_WINDOW_P (w
))
11625 /* We have to handle the case of continuation around a
11626 wide-column character (see the comment in indent.c around
11629 For instance, in the following case:
11631 -------- Insert --------
11632 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11633 J_I_ ==> J_I_ `^^' are cursors.
11637 As we have to redraw the line above, we cannot use this
11641 int line_height_before
= this_line_pixel_height
;
11643 /* Note that start_display will handle the case that the
11644 line starting at tlbufpos is a continuation line. */
11645 start_display (&it
, w
, tlbufpos
);
11647 /* Implementation note: It this still necessary? */
11648 if (it
.current_x
!= this_line_start_x
)
11651 TRACE ((stderr
, "trying display optimization 1\n"));
11652 w
->cursor
.vpos
= -1;
11653 overlay_arrow_seen
= 0;
11654 it
.vpos
= this_line_vpos
;
11655 it
.current_y
= this_line_y
;
11656 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11657 display_line (&it
);
11659 /* If line contains point, is not continued,
11660 and ends at same distance from eob as before, we win. */
11661 if (w
->cursor
.vpos
>= 0
11662 /* Line is not continued, otherwise this_line_start_pos
11663 would have been set to 0 in display_line. */
11664 && CHARPOS (this_line_start_pos
)
11665 /* Line ends as before. */
11666 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11667 /* Line has same height as before. Otherwise other lines
11668 would have to be shifted up or down. */
11669 && this_line_pixel_height
== line_height_before
)
11671 /* If this is not the window's last line, we must adjust
11672 the charstarts of the lines below. */
11673 if (it
.current_y
< it
.last_visible_y
)
11675 struct glyph_row
*row
11676 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11677 int delta
, delta_bytes
;
11679 /* We used to distinguish between two cases here,
11680 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11681 when the line ends in a newline or the end of the
11682 buffer's accessible portion. But both cases did
11683 the same, so they were collapsed. */
11685 - CHARPOS (tlendpos
)
11686 - MATRIX_ROW_START_CHARPOS (row
));
11687 delta_bytes
= (Z_BYTE
11688 - BYTEPOS (tlendpos
)
11689 - MATRIX_ROW_START_BYTEPOS (row
));
11691 increment_matrix_positions (w
->current_matrix
,
11692 this_line_vpos
+ 1,
11693 w
->current_matrix
->nrows
,
11694 delta
, delta_bytes
);
11697 /* If this row displays text now but previously didn't,
11698 or vice versa, w->window_end_vpos may have to be
11700 if ((it
.glyph_row
- 1)->displays_text_p
)
11702 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11703 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11705 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11706 && this_line_vpos
> 0)
11707 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11708 w
->window_end_valid
= Qnil
;
11710 /* Update hint: No need to try to scroll in update_window. */
11711 w
->desired_matrix
->no_scrolling_p
= 1;
11714 *w
->desired_matrix
->method
= 0;
11715 debug_method_add (w
, "optimization 1");
11717 #ifdef HAVE_WINDOW_SYSTEM
11718 update_window_fringes (w
, 0);
11725 else if (/* Cursor position hasn't changed. */
11726 PT
== XFASTINT (w
->last_point
)
11727 /* Make sure the cursor was last displayed
11728 in this window. Otherwise we have to reposition it. */
11729 && 0 <= w
->cursor
.vpos
11730 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11734 do_pending_window_change (1);
11736 /* We used to always goto end_of_redisplay here, but this
11737 isn't enough if we have a blinking cursor. */
11738 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11739 goto end_of_redisplay
;
11743 /* If highlighting the region, or if the cursor is in the echo area,
11744 then we can't just move the cursor. */
11745 else if (! (!NILP (Vtransient_mark_mode
)
11746 && !NILP (current_buffer
->mark_active
))
11747 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11748 || highlight_nonselected_windows
)
11749 && NILP (w
->region_showing
)
11750 && NILP (Vshow_trailing_whitespace
)
11751 && !cursor_in_echo_area
)
11754 struct glyph_row
*row
;
11756 /* Skip from tlbufpos to PT and see where it is. Note that
11757 PT may be in invisible text. If so, we will end at the
11758 next visible position. */
11759 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11760 NULL
, DEFAULT_FACE_ID
);
11761 it
.current_x
= this_line_start_x
;
11762 it
.current_y
= this_line_y
;
11763 it
.vpos
= this_line_vpos
;
11765 /* The call to move_it_to stops in front of PT, but
11766 moves over before-strings. */
11767 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11769 if (it
.vpos
== this_line_vpos
11770 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11773 xassert (this_line_vpos
== it
.vpos
);
11774 xassert (this_line_y
== it
.current_y
);
11775 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11777 *w
->desired_matrix
->method
= 0;
11778 debug_method_add (w
, "optimization 3");
11787 /* Text changed drastically or point moved off of line. */
11788 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11791 CHARPOS (this_line_start_pos
) = 0;
11792 consider_all_windows_p
|= buffer_shared
> 1;
11793 ++clear_face_cache_count
;
11794 #ifdef HAVE_WINDOW_SYSTEM
11795 ++clear_image_cache_count
;
11798 /* Build desired matrices, and update the display. If
11799 consider_all_windows_p is non-zero, do it for all windows on all
11800 frames. Otherwise do it for selected_window, only. */
11802 if (consider_all_windows_p
)
11804 Lisp_Object tail
, frame
;
11806 FOR_EACH_FRAME (tail
, frame
)
11807 XFRAME (frame
)->updated_p
= 0;
11809 /* Recompute # windows showing selected buffer. This will be
11810 incremented each time such a window is displayed. */
11813 FOR_EACH_FRAME (tail
, frame
)
11815 struct frame
*f
= XFRAME (frame
);
11817 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11819 if (! EQ (frame
, selected_frame
))
11820 /* Select the frame, for the sake of frame-local
11822 select_frame_for_redisplay (frame
);
11824 /* Mark all the scroll bars to be removed; we'll redeem
11825 the ones we want when we redisplay their windows. */
11826 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11827 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11829 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11830 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11832 /* The X error handler may have deleted that frame. */
11833 if (!FRAME_LIVE_P (f
))
11836 /* Any scroll bars which redisplay_windows should have
11837 nuked should now go away. */
11838 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11839 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11841 /* If fonts changed, display again. */
11842 /* ??? rms: I suspect it is a mistake to jump all the way
11843 back to retry here. It should just retry this frame. */
11844 if (fonts_changed_p
)
11847 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11849 /* See if we have to hscroll. */
11850 if (!f
->already_hscrolled_p
)
11852 f
->already_hscrolled_p
= 1;
11853 if (hscroll_windows (f
->root_window
))
11857 /* Prevent various kinds of signals during display
11858 update. stdio is not robust about handling
11859 signals, which can cause an apparent I/O
11861 if (interrupt_input
)
11862 unrequest_sigio ();
11865 /* Update the display. */
11866 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11867 pause
|= update_frame (f
, 0, 0);
11873 if (!EQ (old_frame
, selected_frame
)
11874 && FRAME_LIVE_P (XFRAME (old_frame
)))
11875 /* We played a bit fast-and-loose above and allowed selected_frame
11876 and selected_window to be temporarily out-of-sync but let's make
11877 sure this stays contained. */
11878 select_frame_for_redisplay (old_frame
);
11879 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11883 /* Do the mark_window_display_accurate after all windows have
11884 been redisplayed because this call resets flags in buffers
11885 which are needed for proper redisplay. */
11886 FOR_EACH_FRAME (tail
, frame
)
11888 struct frame
*f
= XFRAME (frame
);
11891 mark_window_display_accurate (f
->root_window
, 1);
11892 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11893 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11898 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11900 Lisp_Object mini_window
;
11901 struct frame
*mini_frame
;
11903 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11904 /* Use list_of_error, not Qerror, so that
11905 we catch only errors and don't run the debugger. */
11906 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11908 redisplay_window_error
);
11910 /* Compare desired and current matrices, perform output. */
11913 /* If fonts changed, display again. */
11914 if (fonts_changed_p
)
11917 /* Prevent various kinds of signals during display update.
11918 stdio is not robust about handling signals,
11919 which can cause an apparent I/O error. */
11920 if (interrupt_input
)
11921 unrequest_sigio ();
11924 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11926 if (hscroll_windows (selected_window
))
11929 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11930 pause
= update_frame (sf
, 0, 0);
11933 /* We may have called echo_area_display at the top of this
11934 function. If the echo area is on another frame, that may
11935 have put text on a frame other than the selected one, so the
11936 above call to update_frame would not have caught it. Catch
11938 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11939 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11941 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11943 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11944 pause
|= update_frame (mini_frame
, 0, 0);
11945 if (!pause
&& hscroll_windows (mini_window
))
11950 /* If display was paused because of pending input, make sure we do a
11951 thorough update the next time. */
11954 /* Prevent the optimization at the beginning of
11955 redisplay_internal that tries a single-line update of the
11956 line containing the cursor in the selected window. */
11957 CHARPOS (this_line_start_pos
) = 0;
11959 /* Let the overlay arrow be updated the next time. */
11960 update_overlay_arrows (0);
11962 /* If we pause after scrolling, some rows in the current
11963 matrices of some windows are not valid. */
11964 if (!WINDOW_FULL_WIDTH_P (w
)
11965 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11966 update_mode_lines
= 1;
11970 if (!consider_all_windows_p
)
11972 /* This has already been done above if
11973 consider_all_windows_p is set. */
11974 mark_window_display_accurate_1 (w
, 1);
11976 /* Say overlay arrows are up to date. */
11977 update_overlay_arrows (1);
11979 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11980 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11983 update_mode_lines
= 0;
11984 windows_or_buffers_changed
= 0;
11985 cursor_type_changed
= 0;
11988 /* Start SIGIO interrupts coming again. Having them off during the
11989 code above makes it less likely one will discard output, but not
11990 impossible, since there might be stuff in the system buffer here.
11991 But it is much hairier to try to do anything about that. */
11992 if (interrupt_input
)
11996 /* If a frame has become visible which was not before, redisplay
11997 again, so that we display it. Expose events for such a frame
11998 (which it gets when becoming visible) don't call the parts of
11999 redisplay constructing glyphs, so simply exposing a frame won't
12000 display anything in this case. So, we have to display these
12001 frames here explicitly. */
12004 Lisp_Object tail
, frame
;
12007 FOR_EACH_FRAME (tail
, frame
)
12009 int this_is_visible
= 0;
12011 if (XFRAME (frame
)->visible
)
12012 this_is_visible
= 1;
12013 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12014 if (XFRAME (frame
)->visible
)
12015 this_is_visible
= 1;
12017 if (this_is_visible
)
12021 if (new_count
!= number_of_visible_frames
)
12022 windows_or_buffers_changed
++;
12025 /* Change frame size now if a change is pending. */
12026 do_pending_window_change (1);
12028 /* If we just did a pending size change, or have additional
12029 visible frames, redisplay again. */
12030 if (windows_or_buffers_changed
&& !pause
)
12033 /* Clear the face cache eventually. */
12034 if (consider_all_windows_p
)
12036 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12038 clear_face_cache (0);
12039 clear_face_cache_count
= 0;
12041 #ifdef HAVE_WINDOW_SYSTEM
12042 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12044 clear_image_caches (Qnil
);
12045 clear_image_cache_count
= 0;
12047 #endif /* HAVE_WINDOW_SYSTEM */
12051 unbind_to (count
, Qnil
);
12056 /* Redisplay, but leave alone any recent echo area message unless
12057 another message has been requested in its place.
12059 This is useful in situations where you need to redisplay but no
12060 user action has occurred, making it inappropriate for the message
12061 area to be cleared. See tracking_off and
12062 wait_reading_process_output for examples of these situations.
12064 FROM_WHERE is an integer saying from where this function was
12065 called. This is useful for debugging. */
12068 redisplay_preserve_echo_area (from_where
)
12071 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12073 if (!NILP (echo_area_buffer
[1]))
12075 /* We have a previously displayed message, but no current
12076 message. Redisplay the previous message. */
12077 display_last_displayed_message_p
= 1;
12078 redisplay_internal (1);
12079 display_last_displayed_message_p
= 0;
12082 redisplay_internal (1);
12084 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12085 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12086 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12090 /* Function registered with record_unwind_protect in
12091 redisplay_internal. Reset redisplaying_p to the value it had
12092 before redisplay_internal was called, and clear
12093 prevent_freeing_realized_faces_p. It also selects the previously
12094 selected frame, unless it has been deleted (by an X connection
12095 failure during redisplay, for example). */
12098 unwind_redisplay (val
)
12101 Lisp_Object old_redisplaying_p
, old_frame
;
12103 old_redisplaying_p
= XCAR (val
);
12104 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12105 old_frame
= XCDR (val
);
12106 if (! EQ (old_frame
, selected_frame
)
12107 && FRAME_LIVE_P (XFRAME (old_frame
)))
12108 select_frame_for_redisplay (old_frame
);
12113 /* Mark the display of window W as accurate or inaccurate. If
12114 ACCURATE_P is non-zero mark display of W as accurate. If
12115 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12116 redisplay_internal is called. */
12119 mark_window_display_accurate_1 (w
, accurate_p
)
12123 if (BUFFERP (w
->buffer
))
12125 struct buffer
*b
= XBUFFER (w
->buffer
);
12128 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12129 w
->last_overlay_modified
12130 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12132 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12136 b
->clip_changed
= 0;
12137 b
->prevent_redisplay_optimizations_p
= 0;
12139 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12140 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12141 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12142 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12144 w
->current_matrix
->buffer
= b
;
12145 w
->current_matrix
->begv
= BUF_BEGV (b
);
12146 w
->current_matrix
->zv
= BUF_ZV (b
);
12148 w
->last_cursor
= w
->cursor
;
12149 w
->last_cursor_off_p
= w
->cursor_off_p
;
12151 if (w
== XWINDOW (selected_window
))
12152 w
->last_point
= make_number (BUF_PT (b
));
12154 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12160 w
->window_end_valid
= w
->buffer
;
12161 w
->update_mode_line
= Qnil
;
12166 /* Mark the display of windows in the window tree rooted at WINDOW as
12167 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12168 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12169 be redisplayed the next time redisplay_internal is called. */
12172 mark_window_display_accurate (window
, accurate_p
)
12173 Lisp_Object window
;
12178 for (; !NILP (window
); window
= w
->next
)
12180 w
= XWINDOW (window
);
12181 mark_window_display_accurate_1 (w
, accurate_p
);
12183 if (!NILP (w
->vchild
))
12184 mark_window_display_accurate (w
->vchild
, accurate_p
);
12185 if (!NILP (w
->hchild
))
12186 mark_window_display_accurate (w
->hchild
, accurate_p
);
12191 update_overlay_arrows (1);
12195 /* Force a thorough redisplay the next time by setting
12196 last_arrow_position and last_arrow_string to t, which is
12197 unequal to any useful value of Voverlay_arrow_... */
12198 update_overlay_arrows (-1);
12203 /* Return value in display table DP (Lisp_Char_Table *) for character
12204 C. Since a display table doesn't have any parent, we don't have to
12205 follow parent. Do not call this function directly but use the
12206 macro DISP_CHAR_VECTOR. */
12209 disp_char_vector (dp
, c
)
12210 struct Lisp_Char_Table
*dp
;
12215 if (ASCII_CHAR_P (c
))
12218 if (SUB_CHAR_TABLE_P (val
))
12219 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12225 XSETCHAR_TABLE (table
, dp
);
12226 val
= char_table_ref (table
, c
);
12235 /***********************************************************************
12237 ***********************************************************************/
12239 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12242 redisplay_windows (window
)
12243 Lisp_Object window
;
12245 while (!NILP (window
))
12247 struct window
*w
= XWINDOW (window
);
12249 if (!NILP (w
->hchild
))
12250 redisplay_windows (w
->hchild
);
12251 else if (!NILP (w
->vchild
))
12252 redisplay_windows (w
->vchild
);
12253 else if (!NILP (w
->buffer
))
12255 displayed_buffer
= XBUFFER (w
->buffer
);
12256 /* Use list_of_error, not Qerror, so that
12257 we catch only errors and don't run the debugger. */
12258 internal_condition_case_1 (redisplay_window_0
, window
,
12260 redisplay_window_error
);
12268 redisplay_window_error ()
12270 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12275 redisplay_window_0 (window
)
12276 Lisp_Object window
;
12278 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12279 redisplay_window (window
, 0);
12284 redisplay_window_1 (window
)
12285 Lisp_Object window
;
12287 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12288 redisplay_window (window
, 1);
12293 /* Increment GLYPH until it reaches END or CONDITION fails while
12294 adding (GLYPH)->pixel_width to X. */
12296 #define SKIP_GLYPHS(glyph, end, x, condition) \
12299 (x) += (glyph)->pixel_width; \
12302 while ((glyph) < (end) && (condition))
12305 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12306 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12307 which positions recorded in ROW differ from current buffer
12310 Return 0 if cursor is not on this row, 1 otherwise. */
12313 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12315 struct glyph_row
*row
;
12316 struct glyph_matrix
*matrix
;
12317 int delta
, delta_bytes
, dy
, dvpos
;
12319 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12320 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12321 struct glyph
*cursor
= NULL
;
12322 /* The first glyph that starts a sequence of glyphs from a string
12323 that is a value of a display property. */
12324 struct glyph
*string_start
;
12325 /* The X coordinate of string_start. */
12326 int string_start_x
;
12327 /* The last known character position in row. */
12328 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12329 /* The last known character position before string_start. */
12330 int string_before_pos
;
12333 /* Last buffer position covered by an overlay. */
12334 int cursor_from_overlay_pos
= 0;
12335 int pt_old
= PT
- delta
;
12337 /* Skip over glyphs not having an object at the start of the row.
12338 These are special glyphs like truncation marks on terminal
12340 if (row
->displays_text_p
)
12342 && INTEGERP (glyph
->object
)
12343 && glyph
->charpos
< 0)
12345 x
+= glyph
->pixel_width
;
12349 string_start
= NULL
;
12351 && !INTEGERP (glyph
->object
)
12352 && (!BUFFERP (glyph
->object
)
12353 || (last_pos
= glyph
->charpos
) < pt_old
12354 || glyph
->avoid_cursor_p
))
12356 if (! STRINGP (glyph
->object
))
12358 string_start
= NULL
;
12359 x
+= glyph
->pixel_width
;
12361 /* If we are beyond the cursor position computed from the
12362 last overlay seen, that overlay is not in effect for
12363 current cursor position. Reset the cursor information
12364 computed from that overlay. */
12365 if (cursor_from_overlay_pos
12366 && last_pos
>= cursor_from_overlay_pos
)
12368 cursor_from_overlay_pos
= 0;
12374 if (string_start
== NULL
)
12376 string_before_pos
= last_pos
;
12377 string_start
= glyph
;
12378 string_start_x
= x
;
12380 /* Skip all glyphs from a string. */
12385 if ((cursor
== NULL
|| glyph
> cursor
)
12386 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12387 Qcursor
, (glyph
)->object
),
12389 && (pos
= string_buffer_position (w
, glyph
->object
,
12390 string_before_pos
),
12391 (pos
== 0 /* from overlay */
12392 || pos
== pt_old
)))
12394 /* Compute the first buffer position after the overlay.
12395 If the `cursor' property tells us how many positions
12396 are associated with the overlay, use that. Otherwise,
12397 estimate from the buffer positions of the glyphs
12398 before and after the overlay. */
12399 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12400 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12404 x
+= glyph
->pixel_width
;
12407 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12411 if (cursor
!= NULL
)
12416 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12418 /* Scan back over the ellipsis glyphs, decrementing positions. */
12419 while (glyph
> row
->glyphs
[TEXT_AREA
]
12420 && (glyph
- 1)->charpos
== last_pos
)
12421 glyph
--, x
-= glyph
->pixel_width
;
12422 /* That loop always goes one position too far, including the
12423 glyph before the ellipsis. So scan forward over that one. */
12424 x
+= glyph
->pixel_width
;
12427 else if (string_start
12428 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12430 /* We may have skipped over point because the previous glyphs
12431 are from string. As there's no easy way to know the
12432 character position of the current glyph, find the correct
12433 glyph on point by scanning from string_start again. */
12435 Lisp_Object string
;
12436 struct glyph
*stop
= glyph
;
12439 limit
= make_number (pt_old
+ 1);
12440 glyph
= string_start
;
12441 x
= string_start_x
;
12442 string
= glyph
->object
;
12443 pos
= string_buffer_position (w
, string
, string_before_pos
);
12444 /* If POS == 0, STRING is from overlay. We skip such glyphs
12445 because we always put the cursor after overlay strings. */
12446 while (pos
== 0 && glyph
< stop
)
12448 string
= glyph
->object
;
12449 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12451 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12454 while (glyph
< stop
)
12456 pos
= XINT (Fnext_single_char_property_change
12457 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12460 /* Skip glyphs from the same string. */
12461 string
= glyph
->object
;
12462 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12463 /* Skip glyphs from an overlay. */
12464 while (glyph
< stop
12465 && ! string_buffer_position (w
, glyph
->object
, pos
))
12467 string
= glyph
->object
;
12468 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12472 /* If we reached the end of the line, and END was from a string,
12473 the cursor is not on this line. */
12474 if (glyph
== end
&& row
->continued_p
)
12478 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12480 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12481 w
->cursor
.y
= row
->y
+ dy
;
12483 if (w
== XWINDOW (selected_window
))
12485 if (!row
->continued_p
12486 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12489 this_line_buffer
= XBUFFER (w
->buffer
);
12491 CHARPOS (this_line_start_pos
)
12492 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12493 BYTEPOS (this_line_start_pos
)
12494 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12496 CHARPOS (this_line_end_pos
)
12497 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12498 BYTEPOS (this_line_end_pos
)
12499 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12501 this_line_y
= w
->cursor
.y
;
12502 this_line_pixel_height
= row
->height
;
12503 this_line_vpos
= w
->cursor
.vpos
;
12504 this_line_start_x
= row
->x
;
12507 CHARPOS (this_line_start_pos
) = 0;
12514 /* Run window scroll functions, if any, for WINDOW with new window
12515 start STARTP. Sets the window start of WINDOW to that position.
12517 We assume that the window's buffer is really current. */
12519 static INLINE
struct text_pos
12520 run_window_scroll_functions (window
, startp
)
12521 Lisp_Object window
;
12522 struct text_pos startp
;
12524 struct window
*w
= XWINDOW (window
);
12525 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12527 if (current_buffer
!= XBUFFER (w
->buffer
))
12530 if (!NILP (Vwindow_scroll_functions
))
12532 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12533 make_number (CHARPOS (startp
)));
12534 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12535 /* In case the hook functions switch buffers. */
12536 if (current_buffer
!= XBUFFER (w
->buffer
))
12537 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12544 /* Make sure the line containing the cursor is fully visible.
12545 A value of 1 means there is nothing to be done.
12546 (Either the line is fully visible, or it cannot be made so,
12547 or we cannot tell.)
12549 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12550 is higher than window.
12552 A value of 0 means the caller should do scrolling
12553 as if point had gone off the screen. */
12556 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12559 int current_matrix_p
;
12561 struct glyph_matrix
*matrix
;
12562 struct glyph_row
*row
;
12565 if (!make_cursor_line_fully_visible_p
)
12568 /* It's not always possible to find the cursor, e.g, when a window
12569 is full of overlay strings. Don't do anything in that case. */
12570 if (w
->cursor
.vpos
< 0)
12573 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12574 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12576 /* If the cursor row is not partially visible, there's nothing to do. */
12577 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12580 /* If the row the cursor is in is taller than the window's height,
12581 it's not clear what to do, so do nothing. */
12582 window_height
= window_box_height (w
);
12583 if (row
->height
>= window_height
)
12585 if (!force_p
|| MINI_WINDOW_P (w
)
12586 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12593 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12594 non-zero means only WINDOW is redisplayed in redisplay_internal.
12595 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12596 in redisplay_window to bring a partially visible line into view in
12597 the case that only the cursor has moved.
12599 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12600 last screen line's vertical height extends past the end of the screen.
12604 1 if scrolling succeeded
12606 0 if scrolling didn't find point.
12608 -1 if new fonts have been loaded so that we must interrupt
12609 redisplay, adjust glyph matrices, and try again. */
12615 SCROLLING_NEED_LARGER_MATRICES
12619 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12620 scroll_step
, temp_scroll_step
, last_line_misfit
)
12621 Lisp_Object window
;
12622 int just_this_one_p
;
12623 EMACS_INT scroll_conservatively
, scroll_step
;
12624 int temp_scroll_step
;
12625 int last_line_misfit
;
12627 struct window
*w
= XWINDOW (window
);
12628 struct frame
*f
= XFRAME (w
->frame
);
12629 struct text_pos pos
, startp
;
12631 int this_scroll_margin
, scroll_max
, rc
, height
;
12632 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
12633 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12634 Lisp_Object aggressive
;
12635 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
12638 debug_method_add (w
, "try_scrolling");
12641 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12643 /* Compute scroll margin height in pixels. We scroll when point is
12644 within this distance from the top or bottom of the window. */
12645 if (scroll_margin
> 0)
12646 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
12647 * FRAME_LINE_HEIGHT (f
);
12649 this_scroll_margin
= 0;
12651 /* Force scroll_conservatively to have a reasonable value, to avoid
12652 overflow while computing how much to scroll. Note that the user
12653 can supply scroll-conservatively equal to `most-positive-fixnum',
12654 which can be larger than INT_MAX. */
12655 if (scroll_conservatively
> scroll_limit
)
12657 scroll_conservatively
= scroll_limit
;
12658 scroll_max
= INT_MAX
;
12660 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12661 /* Compute how much we should try to scroll maximally to bring
12662 point into view. */
12663 scroll_max
= (max (scroll_step
,
12664 max (scroll_conservatively
, temp_scroll_step
))
12665 * FRAME_LINE_HEIGHT (f
));
12666 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12667 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12668 /* We're trying to scroll because of aggressive scrolling but no
12669 scroll_step is set. Choose an arbitrary one. */
12670 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
12676 /* Decide whether to scroll down. */
12677 if (PT
> CHARPOS (startp
))
12679 int scroll_margin_y
;
12681 /* Compute the pixel ypos of the scroll margin, then move it to
12682 either that ypos or PT, whichever comes first. */
12683 start_display (&it
, w
, startp
);
12684 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
12685 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
12686 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
12687 (MOVE_TO_POS
| MOVE_TO_Y
));
12689 if (PT
> CHARPOS (it
.current
.pos
))
12691 int y0
= line_bottom_y (&it
);
12693 /* Compute the distance from the scroll margin to PT
12694 (including the height of the cursor line). Moving the
12695 iterator unconditionally to PT can be slow if PT is far
12696 away, so stop 10 lines past the window bottom (is there a
12697 way to do the right thing quickly?). */
12698 move_it_to (&it
, PT
, -1,
12699 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
12700 -1, MOVE_TO_POS
| MOVE_TO_Y
);
12701 dy
= line_bottom_y (&it
) - y0
;
12703 if (dy
> scroll_max
)
12704 return SCROLLING_FAILED
;
12712 /* Point is in or below the bottom scroll margin, so move the
12713 window start down. If scrolling conservatively, move it just
12714 enough down to make point visible. If scroll_step is set,
12715 move it down by scroll_step. */
12716 if (scroll_conservatively
)
12718 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12719 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12720 else if (scroll_step
|| temp_scroll_step
)
12721 amount_to_scroll
= scroll_max
;
12724 aggressive
= current_buffer
->scroll_up_aggressively
;
12725 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12726 if (NUMBERP (aggressive
))
12728 double float_amount
= XFLOATINT (aggressive
) * height
;
12729 amount_to_scroll
= float_amount
;
12730 if (amount_to_scroll
== 0 && float_amount
> 0)
12731 amount_to_scroll
= 1;
12735 if (amount_to_scroll
<= 0)
12736 return SCROLLING_FAILED
;
12738 start_display (&it
, w
, startp
);
12739 move_it_vertically (&it
, amount_to_scroll
);
12741 /* If STARTP is unchanged, move it down another screen line. */
12742 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12743 move_it_by_lines (&it
, 1, 1);
12744 startp
= it
.current
.pos
;
12748 struct text_pos scroll_margin_pos
= startp
;
12750 /* See if point is inside the scroll margin at the top of the
12752 if (this_scroll_margin
)
12754 start_display (&it
, w
, startp
);
12755 move_it_vertically (&it
, this_scroll_margin
);
12756 scroll_margin_pos
= it
.current
.pos
;
12759 if (PT
< CHARPOS (scroll_margin_pos
))
12761 /* Point is in the scroll margin at the top of the window or
12762 above what is displayed in the window. */
12765 /* Compute the vertical distance from PT to the scroll
12766 margin position. Give up if distance is greater than
12768 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12769 start_display (&it
, w
, pos
);
12771 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12772 it
.last_visible_y
, -1,
12773 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12774 dy
= it
.current_y
- y0
;
12775 if (dy
> scroll_max
)
12776 return SCROLLING_FAILED
;
12778 /* Compute new window start. */
12779 start_display (&it
, w
, startp
);
12781 if (scroll_conservatively
)
12783 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12784 else if (scroll_step
|| temp_scroll_step
)
12785 amount_to_scroll
= scroll_max
;
12788 aggressive
= current_buffer
->scroll_down_aggressively
;
12789 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12790 if (NUMBERP (aggressive
))
12792 double float_amount
= XFLOATINT (aggressive
) * height
;
12793 amount_to_scroll
= float_amount
;
12794 if (amount_to_scroll
== 0 && float_amount
> 0)
12795 amount_to_scroll
= 1;
12799 if (amount_to_scroll
<= 0)
12800 return SCROLLING_FAILED
;
12802 move_it_vertically_backward (&it
, amount_to_scroll
);
12803 startp
= it
.current
.pos
;
12807 /* Run window scroll functions. */
12808 startp
= run_window_scroll_functions (window
, startp
);
12810 /* Display the window. Give up if new fonts are loaded, or if point
12812 if (!try_window (window
, startp
, 0))
12813 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12814 else if (w
->cursor
.vpos
< 0)
12816 clear_glyph_matrix (w
->desired_matrix
);
12817 rc
= SCROLLING_FAILED
;
12821 /* Maybe forget recorded base line for line number display. */
12822 if (!just_this_one_p
12823 || current_buffer
->clip_changed
12824 || BEG_UNCHANGED
< CHARPOS (startp
))
12825 w
->base_line_number
= Qnil
;
12827 /* If cursor ends up on a partially visible line,
12828 treat that as being off the bottom of the screen. */
12829 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12831 clear_glyph_matrix (w
->desired_matrix
);
12832 ++extra_scroll_margin_lines
;
12835 rc
= SCROLLING_SUCCESS
;
12842 /* Compute a suitable window start for window W if display of W starts
12843 on a continuation line. Value is non-zero if a new window start
12846 The new window start will be computed, based on W's width, starting
12847 from the start of the continued line. It is the start of the
12848 screen line with the minimum distance from the old start W->start. */
12851 compute_window_start_on_continuation_line (w
)
12854 struct text_pos pos
, start_pos
;
12855 int window_start_changed_p
= 0;
12857 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12859 /* If window start is on a continuation line... Window start may be
12860 < BEGV in case there's invisible text at the start of the
12861 buffer (M-x rmail, for example). */
12862 if (CHARPOS (start_pos
) > BEGV
12863 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12866 struct glyph_row
*row
;
12868 /* Handle the case that the window start is out of range. */
12869 if (CHARPOS (start_pos
) < BEGV
)
12870 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12871 else if (CHARPOS (start_pos
) > ZV
)
12872 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12874 /* Find the start of the continued line. This should be fast
12875 because scan_buffer is fast (newline cache). */
12876 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12877 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12878 row
, DEFAULT_FACE_ID
);
12879 reseat_at_previous_visible_line_start (&it
);
12881 /* If the line start is "too far" away from the window start,
12882 say it takes too much time to compute a new window start. */
12883 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12884 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12886 int min_distance
, distance
;
12888 /* Move forward by display lines to find the new window
12889 start. If window width was enlarged, the new start can
12890 be expected to be > the old start. If window width was
12891 decreased, the new window start will be < the old start.
12892 So, we're looking for the display line start with the
12893 minimum distance from the old window start. */
12894 pos
= it
.current
.pos
;
12895 min_distance
= INFINITY
;
12896 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12897 distance
< min_distance
)
12899 min_distance
= distance
;
12900 pos
= it
.current
.pos
;
12901 move_it_by_lines (&it
, 1, 0);
12904 /* Set the window start there. */
12905 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12906 window_start_changed_p
= 1;
12910 return window_start_changed_p
;
12914 /* Try cursor movement in case text has not changed in window WINDOW,
12915 with window start STARTP. Value is
12917 CURSOR_MOVEMENT_SUCCESS if successful
12919 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12921 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12922 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12923 we want to scroll as if scroll-step were set to 1. See the code.
12925 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12926 which case we have to abort this redisplay, and adjust matrices
12931 CURSOR_MOVEMENT_SUCCESS
,
12932 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12933 CURSOR_MOVEMENT_MUST_SCROLL
,
12934 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12938 try_cursor_movement (window
, startp
, scroll_step
)
12939 Lisp_Object window
;
12940 struct text_pos startp
;
12943 struct window
*w
= XWINDOW (window
);
12944 struct frame
*f
= XFRAME (w
->frame
);
12945 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12948 if (inhibit_try_cursor_movement
)
12952 /* Handle case where text has not changed, only point, and it has
12953 not moved off the frame. */
12954 if (/* Point may be in this window. */
12955 PT
>= CHARPOS (startp
)
12956 /* Selective display hasn't changed. */
12957 && !current_buffer
->clip_changed
12958 /* Function force-mode-line-update is used to force a thorough
12959 redisplay. It sets either windows_or_buffers_changed or
12960 update_mode_lines. So don't take a shortcut here for these
12962 && !update_mode_lines
12963 && !windows_or_buffers_changed
12964 && !cursor_type_changed
12965 /* Can't use this case if highlighting a region. When a
12966 region exists, cursor movement has to do more than just
12968 && !(!NILP (Vtransient_mark_mode
)
12969 && !NILP (current_buffer
->mark_active
))
12970 && NILP (w
->region_showing
)
12971 && NILP (Vshow_trailing_whitespace
)
12972 /* Right after splitting windows, last_point may be nil. */
12973 && INTEGERP (w
->last_point
)
12974 /* This code is not used for mini-buffer for the sake of the case
12975 of redisplaying to replace an echo area message; since in
12976 that case the mini-buffer contents per se are usually
12977 unchanged. This code is of no real use in the mini-buffer
12978 since the handling of this_line_start_pos, etc., in redisplay
12979 handles the same cases. */
12980 && !EQ (window
, minibuf_window
)
12981 /* When splitting windows or for new windows, it happens that
12982 redisplay is called with a nil window_end_vpos or one being
12983 larger than the window. This should really be fixed in
12984 window.c. I don't have this on my list, now, so we do
12985 approximately the same as the old redisplay code. --gerd. */
12986 && INTEGERP (w
->window_end_vpos
)
12987 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
12988 && (FRAME_WINDOW_P (f
)
12989 || !overlay_arrow_in_current_buffer_p ()))
12991 int this_scroll_margin
, top_scroll_margin
;
12992 struct glyph_row
*row
= NULL
;
12995 debug_method_add (w
, "cursor movement");
12998 /* Scroll if point within this distance from the top or bottom
12999 of the window. This is a pixel value. */
13000 if (scroll_margin
> 0)
13002 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13003 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13006 this_scroll_margin
= 0;
13008 top_scroll_margin
= this_scroll_margin
;
13009 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13010 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13012 /* Start with the row the cursor was displayed during the last
13013 not paused redisplay. Give up if that row is not valid. */
13014 if (w
->last_cursor
.vpos
< 0
13015 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13016 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13019 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13020 if (row
->mode_line_p
)
13022 if (!row
->enabled_p
)
13023 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13026 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13029 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13031 if (PT
> XFASTINT (w
->last_point
))
13033 /* Point has moved forward. */
13034 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13035 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13037 xassert (row
->enabled_p
);
13041 /* The end position of a row equals the start position
13042 of the next row. If PT is there, we would rather
13043 display it in the next line. */
13044 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13045 && MATRIX_ROW_END_CHARPOS (row
) == PT
13046 && !cursor_row_p (w
, row
))
13049 /* If within the scroll margin, scroll. Note that
13050 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13051 the next line would be drawn, and that
13052 this_scroll_margin can be zero. */
13053 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13054 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13055 /* Line is completely visible last line in window
13056 and PT is to be set in the next line. */
13057 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13058 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13059 && !row
->ends_at_zv_p
13060 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13063 else if (PT
< XFASTINT (w
->last_point
))
13065 /* Cursor has to be moved backward. Note that PT >=
13066 CHARPOS (startp) because of the outer if-statement. */
13067 while (!row
->mode_line_p
13068 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13069 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13070 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13071 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13072 row
> w
->current_matrix
->rows
13073 && (row
-1)->ends_in_newline_from_string_p
))))
13074 && (row
->y
> top_scroll_margin
13075 || CHARPOS (startp
) == BEGV
))
13077 xassert (row
->enabled_p
);
13081 /* Consider the following case: Window starts at BEGV,
13082 there is invisible, intangible text at BEGV, so that
13083 display starts at some point START > BEGV. It can
13084 happen that we are called with PT somewhere between
13085 BEGV and START. Try to handle that case. */
13086 if (row
< w
->current_matrix
->rows
13087 || row
->mode_line_p
)
13089 row
= w
->current_matrix
->rows
;
13090 if (row
->mode_line_p
)
13094 /* Due to newlines in overlay strings, we may have to
13095 skip forward over overlay strings. */
13096 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13097 && MATRIX_ROW_END_CHARPOS (row
) == PT
13098 && !cursor_row_p (w
, row
))
13101 /* If within the scroll margin, scroll. */
13102 if (row
->y
< top_scroll_margin
13103 && CHARPOS (startp
) != BEGV
)
13108 /* Cursor did not move. So don't scroll even if cursor line
13109 is partially visible, as it was so before. */
13110 rc
= CURSOR_MOVEMENT_SUCCESS
;
13113 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13114 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13116 /* if PT is not in the glyph row, give up. */
13117 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13119 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13120 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13121 && make_cursor_line_fully_visible_p
)
13123 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13124 && !row
->ends_at_zv_p
13125 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13126 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13127 else if (row
->height
> window_box_height (w
))
13129 /* If we end up in a partially visible line, let's
13130 make it fully visible, except when it's taller
13131 than the window, in which case we can't do much
13134 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13138 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13139 if (!cursor_row_fully_visible_p (w
, 0, 1))
13140 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13142 rc
= CURSOR_MOVEMENT_SUCCESS
;
13146 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13151 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13153 rc
= CURSOR_MOVEMENT_SUCCESS
;
13158 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13159 && MATRIX_ROW_START_CHARPOS (row
) == PT
13160 && cursor_row_p (w
, row
));
13169 set_vertical_scroll_bar (w
)
13172 int start
, end
, whole
;
13174 /* Calculate the start and end positions for the current window.
13175 At some point, it would be nice to choose between scrollbars
13176 which reflect the whole buffer size, with special markers
13177 indicating narrowing, and scrollbars which reflect only the
13180 Note that mini-buffers sometimes aren't displaying any text. */
13181 if (!MINI_WINDOW_P (w
)
13182 || (w
== XWINDOW (minibuf_window
)
13183 && NILP (echo_area_buffer
[0])))
13185 struct buffer
*buf
= XBUFFER (w
->buffer
);
13186 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13187 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13188 /* I don't think this is guaranteed to be right. For the
13189 moment, we'll pretend it is. */
13190 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13194 if (whole
< (end
- start
))
13195 whole
= end
- start
;
13198 start
= end
= whole
= 0;
13200 /* Indicate what this scroll bar ought to be displaying now. */
13201 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13202 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13203 (w
, end
- start
, whole
, start
);
13207 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13208 selected_window is redisplayed.
13210 We can return without actually redisplaying the window if
13211 fonts_changed_p is nonzero. In that case, redisplay_internal will
13215 redisplay_window (window
, just_this_one_p
)
13216 Lisp_Object window
;
13217 int just_this_one_p
;
13219 struct window
*w
= XWINDOW (window
);
13220 struct frame
*f
= XFRAME (w
->frame
);
13221 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13222 struct buffer
*old
= current_buffer
;
13223 struct text_pos lpoint
, opoint
, startp
;
13224 int update_mode_line
;
13227 /* Record it now because it's overwritten. */
13228 int current_matrix_up_to_date_p
= 0;
13229 int used_current_matrix_p
= 0;
13230 /* This is less strict than current_matrix_up_to_date_p.
13231 It indictes that the buffer contents and narrowing are unchanged. */
13232 int buffer_unchanged_p
= 0;
13233 int temp_scroll_step
= 0;
13234 int count
= SPECPDL_INDEX ();
13236 int centering_position
= -1;
13237 int last_line_misfit
= 0;
13238 int beg_unchanged
, end_unchanged
;
13240 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13243 /* W must be a leaf window here. */
13244 xassert (!NILP (w
->buffer
));
13246 *w
->desired_matrix
->method
= 0;
13250 reconsider_clip_changes (w
, buffer
);
13252 /* Has the mode line to be updated? */
13253 update_mode_line
= (!NILP (w
->update_mode_line
)
13254 || update_mode_lines
13255 || buffer
->clip_changed
13256 || buffer
->prevent_redisplay_optimizations_p
);
13258 if (MINI_WINDOW_P (w
))
13260 if (w
== XWINDOW (echo_area_window
)
13261 && !NILP (echo_area_buffer
[0]))
13263 if (update_mode_line
)
13264 /* We may have to update a tty frame's menu bar or a
13265 tool-bar. Example `M-x C-h C-h C-g'. */
13266 goto finish_menu_bars
;
13268 /* We've already displayed the echo area glyphs in this window. */
13269 goto finish_scroll_bars
;
13271 else if ((w
!= XWINDOW (minibuf_window
)
13272 || minibuf_level
== 0)
13273 /* When buffer is nonempty, redisplay window normally. */
13274 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13275 /* Quail displays non-mini buffers in minibuffer window.
13276 In that case, redisplay the window normally. */
13277 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13279 /* W is a mini-buffer window, but it's not active, so clear
13281 int yb
= window_text_bottom_y (w
);
13282 struct glyph_row
*row
;
13285 for (y
= 0, row
= w
->desired_matrix
->rows
;
13287 y
+= row
->height
, ++row
)
13288 blank_row (w
, row
, y
);
13289 goto finish_scroll_bars
;
13292 clear_glyph_matrix (w
->desired_matrix
);
13295 /* Otherwise set up data on this window; select its buffer and point
13297 /* Really select the buffer, for the sake of buffer-local
13299 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13301 current_matrix_up_to_date_p
13302 = (!NILP (w
->window_end_valid
)
13303 && !current_buffer
->clip_changed
13304 && !current_buffer
->prevent_redisplay_optimizations_p
13305 && XFASTINT (w
->last_modified
) >= MODIFF
13306 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13308 /* Run the window-bottom-change-functions
13309 if it is possible that the text on the screen has changed
13310 (either due to modification of the text, or any other reason). */
13311 if (!current_matrix_up_to_date_p
13312 && !NILP (Vwindow_text_change_functions
))
13314 safe_run_hooks (Qwindow_text_change_functions
);
13318 beg_unchanged
= BEG_UNCHANGED
;
13319 end_unchanged
= END_UNCHANGED
;
13321 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13323 specbind (Qinhibit_point_motion_hooks
, Qt
);
13326 = (!NILP (w
->window_end_valid
)
13327 && !current_buffer
->clip_changed
13328 && XFASTINT (w
->last_modified
) >= MODIFF
13329 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13331 /* When windows_or_buffers_changed is non-zero, we can't rely on
13332 the window end being valid, so set it to nil there. */
13333 if (windows_or_buffers_changed
)
13335 /* If window starts on a continuation line, maybe adjust the
13336 window start in case the window's width changed. */
13337 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13338 compute_window_start_on_continuation_line (w
);
13340 w
->window_end_valid
= Qnil
;
13343 /* Some sanity checks. */
13344 CHECK_WINDOW_END (w
);
13345 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13347 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13350 /* If %c is in mode line, update it if needed. */
13351 if (!NILP (w
->column_number_displayed
)
13352 /* This alternative quickly identifies a common case
13353 where no change is needed. */
13354 && !(PT
== XFASTINT (w
->last_point
)
13355 && XFASTINT (w
->last_modified
) >= MODIFF
13356 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13357 && (XFASTINT (w
->column_number_displayed
)
13358 != (int) current_column ())) /* iftc */
13359 update_mode_line
= 1;
13361 /* Count number of windows showing the selected buffer. An indirect
13362 buffer counts as its base buffer. */
13363 if (!just_this_one_p
)
13365 struct buffer
*current_base
, *window_base
;
13366 current_base
= current_buffer
;
13367 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13368 if (current_base
->base_buffer
)
13369 current_base
= current_base
->base_buffer
;
13370 if (window_base
->base_buffer
)
13371 window_base
= window_base
->base_buffer
;
13372 if (current_base
== window_base
)
13376 /* Point refers normally to the selected window. For any other
13377 window, set up appropriate value. */
13378 if (!EQ (window
, selected_window
))
13380 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13381 int new_pt_byte
= marker_byte_position (w
->pointm
);
13385 new_pt_byte
= BEGV_BYTE
;
13386 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13388 else if (new_pt
> (ZV
- 1))
13391 new_pt_byte
= ZV_BYTE
;
13392 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13395 /* We don't use SET_PT so that the point-motion hooks don't run. */
13396 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13399 /* If any of the character widths specified in the display table
13400 have changed, invalidate the width run cache. It's true that
13401 this may be a bit late to catch such changes, but the rest of
13402 redisplay goes (non-fatally) haywire when the display table is
13403 changed, so why should we worry about doing any better? */
13404 if (current_buffer
->width_run_cache
)
13406 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13408 if (! disptab_matches_widthtab (disptab
,
13409 XVECTOR (current_buffer
->width_table
)))
13411 invalidate_region_cache (current_buffer
,
13412 current_buffer
->width_run_cache
,
13414 recompute_width_table (current_buffer
, disptab
);
13418 /* If window-start is screwed up, choose a new one. */
13419 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13422 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13424 /* If someone specified a new starting point but did not insist,
13425 check whether it can be used. */
13426 if (!NILP (w
->optional_new_start
)
13427 && CHARPOS (startp
) >= BEGV
13428 && CHARPOS (startp
) <= ZV
)
13430 w
->optional_new_start
= Qnil
;
13431 start_display (&it
, w
, startp
);
13432 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13433 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13434 if (IT_CHARPOS (it
) == PT
)
13435 w
->force_start
= Qt
;
13436 /* IT may overshoot PT if text at PT is invisible. */
13437 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13438 w
->force_start
= Qt
;
13443 /* Handle case where place to start displaying has been specified,
13444 unless the specified location is outside the accessible range. */
13445 if (!NILP (w
->force_start
)
13446 || w
->frozen_window_start_p
)
13448 /* We set this later on if we have to adjust point. */
13451 w
->force_start
= Qnil
;
13453 w
->window_end_valid
= Qnil
;
13455 /* Forget any recorded base line for line number display. */
13456 if (!buffer_unchanged_p
)
13457 w
->base_line_number
= Qnil
;
13459 /* Redisplay the mode line. Select the buffer properly for that.
13460 Also, run the hook window-scroll-functions
13461 because we have scrolled. */
13462 /* Note, we do this after clearing force_start because
13463 if there's an error, it is better to forget about force_start
13464 than to get into an infinite loop calling the hook functions
13465 and having them get more errors. */
13466 if (!update_mode_line
13467 || ! NILP (Vwindow_scroll_functions
))
13469 update_mode_line
= 1;
13470 w
->update_mode_line
= Qt
;
13471 startp
= run_window_scroll_functions (window
, startp
);
13474 w
->last_modified
= make_number (0);
13475 w
->last_overlay_modified
= make_number (0);
13476 if (CHARPOS (startp
) < BEGV
)
13477 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13478 else if (CHARPOS (startp
) > ZV
)
13479 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13481 /* Redisplay, then check if cursor has been set during the
13482 redisplay. Give up if new fonts were loaded. */
13483 /* We used to issue a CHECK_MARGINS argument to try_window here,
13484 but this causes scrolling to fail when point begins inside
13485 the scroll margin (bug#148) -- cyd */
13486 if (!try_window (window
, startp
, 0))
13488 w
->force_start
= Qt
;
13489 clear_glyph_matrix (w
->desired_matrix
);
13490 goto need_larger_matrices
;
13493 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13495 /* If point does not appear, try to move point so it does
13496 appear. The desired matrix has been built above, so we
13497 can use it here. */
13498 new_vpos
= window_box_height (w
) / 2;
13501 if (!cursor_row_fully_visible_p (w
, 0, 0))
13503 /* Point does appear, but on a line partly visible at end of window.
13504 Move it back to a fully-visible line. */
13505 new_vpos
= window_box_height (w
);
13508 /* If we need to move point for either of the above reasons,
13509 now actually do it. */
13512 struct glyph_row
*row
;
13514 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13515 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13518 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13519 MATRIX_ROW_START_BYTEPOS (row
));
13521 if (w
!= XWINDOW (selected_window
))
13522 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13523 else if (current_buffer
== old
)
13524 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13526 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13528 /* If we are highlighting the region, then we just changed
13529 the region, so redisplay to show it. */
13530 if (!NILP (Vtransient_mark_mode
)
13531 && !NILP (current_buffer
->mark_active
))
13533 clear_glyph_matrix (w
->desired_matrix
);
13534 if (!try_window (window
, startp
, 0))
13535 goto need_larger_matrices
;
13540 debug_method_add (w
, "forced window start");
13545 /* Handle case where text has not changed, only point, and it has
13546 not moved off the frame, and we are not retrying after hscroll.
13547 (current_matrix_up_to_date_p is nonzero when retrying.) */
13548 if (current_matrix_up_to_date_p
13549 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13550 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13554 case CURSOR_MOVEMENT_SUCCESS
:
13555 used_current_matrix_p
= 1;
13558 case CURSOR_MOVEMENT_MUST_SCROLL
:
13559 goto try_to_scroll
;
13565 /* If current starting point was originally the beginning of a line
13566 but no longer is, find a new starting point. */
13567 else if (!NILP (w
->start_at_line_beg
)
13568 && !(CHARPOS (startp
) <= BEGV
13569 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13572 debug_method_add (w
, "recenter 1");
13577 /* Try scrolling with try_window_id. Value is > 0 if update has
13578 been done, it is -1 if we know that the same window start will
13579 not work. It is 0 if unsuccessful for some other reason. */
13580 else if ((tem
= try_window_id (w
)) != 0)
13583 debug_method_add (w
, "try_window_id %d", tem
);
13586 if (fonts_changed_p
)
13587 goto need_larger_matrices
;
13591 /* Otherwise try_window_id has returned -1 which means that we
13592 don't want the alternative below this comment to execute. */
13594 else if (CHARPOS (startp
) >= BEGV
13595 && CHARPOS (startp
) <= ZV
13596 && PT
>= CHARPOS (startp
)
13597 && (CHARPOS (startp
) < ZV
13598 /* Avoid starting at end of buffer. */
13599 || CHARPOS (startp
) == BEGV
13600 || (XFASTINT (w
->last_modified
) >= MODIFF
13601 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13604 /* If first window line is a continuation line, and window start
13605 is inside the modified region, but the first change is before
13606 current window start, we must select a new window start.
13608 However, if this is the result of a down-mouse event (e.g. by
13609 extending the mouse-drag-overlay), we don't want to select a
13610 new window start, since that would change the position under
13611 the mouse, resulting in an unwanted mouse-movement rather
13612 than a simple mouse-click. */
13613 if (NILP (w
->start_at_line_beg
)
13614 && NILP (do_mouse_tracking
)
13615 && CHARPOS (startp
) > BEGV
13616 && CHARPOS (startp
) > BEG
+ beg_unchanged
13617 && CHARPOS (startp
) <= Z
- end_unchanged
13618 /* Even if w->start_at_line_beg is nil, a new window may
13619 start at a line_beg, since that's how set_buffer_window
13620 sets it. So, we need to check the return value of
13621 compute_window_start_on_continuation_line. (See also
13623 && XMARKER (w
->start
)->buffer
== current_buffer
13624 && compute_window_start_on_continuation_line (w
))
13626 w
->force_start
= Qt
;
13627 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13632 debug_method_add (w
, "same window start");
13635 /* Try to redisplay starting at same place as before.
13636 If point has not moved off frame, accept the results. */
13637 if (!current_matrix_up_to_date_p
13638 /* Don't use try_window_reusing_current_matrix in this case
13639 because a window scroll function can have changed the
13641 || !NILP (Vwindow_scroll_functions
)
13642 || MINI_WINDOW_P (w
)
13643 || !(used_current_matrix_p
13644 = try_window_reusing_current_matrix (w
)))
13646 IF_DEBUG (debug_method_add (w
, "1"));
13647 if (try_window (window
, startp
, 1) < 0)
13648 /* -1 means we need to scroll.
13649 0 means we need new matrices, but fonts_changed_p
13650 is set in that case, so we will detect it below. */
13651 goto try_to_scroll
;
13654 if (fonts_changed_p
)
13655 goto need_larger_matrices
;
13657 if (w
->cursor
.vpos
>= 0)
13659 if (!just_this_one_p
13660 || current_buffer
->clip_changed
13661 || BEG_UNCHANGED
< CHARPOS (startp
))
13662 /* Forget any recorded base line for line number display. */
13663 w
->base_line_number
= Qnil
;
13665 if (!cursor_row_fully_visible_p (w
, 1, 0))
13667 clear_glyph_matrix (w
->desired_matrix
);
13668 last_line_misfit
= 1;
13670 /* Drop through and scroll. */
13675 clear_glyph_matrix (w
->desired_matrix
);
13680 w
->last_modified
= make_number (0);
13681 w
->last_overlay_modified
= make_number (0);
13683 /* Redisplay the mode line. Select the buffer properly for that. */
13684 if (!update_mode_line
)
13686 update_mode_line
= 1;
13687 w
->update_mode_line
= Qt
;
13690 /* Try to scroll by specified few lines. */
13691 if ((scroll_conservatively
13693 || temp_scroll_step
13694 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13695 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13696 && !current_buffer
->clip_changed
13697 && CHARPOS (startp
) >= BEGV
13698 && CHARPOS (startp
) <= ZV
)
13700 /* The function returns -1 if new fonts were loaded, 1 if
13701 successful, 0 if not successful. */
13702 int rc
= try_scrolling (window
, just_this_one_p
,
13703 scroll_conservatively
,
13705 temp_scroll_step
, last_line_misfit
);
13708 case SCROLLING_SUCCESS
:
13711 case SCROLLING_NEED_LARGER_MATRICES
:
13712 goto need_larger_matrices
;
13714 case SCROLLING_FAILED
:
13722 /* Finally, just choose place to start which centers point */
13725 if (centering_position
< 0)
13726 centering_position
= window_box_height (w
) / 2;
13729 debug_method_add (w
, "recenter");
13732 /* w->vscroll = 0; */
13734 /* Forget any previously recorded base line for line number display. */
13735 if (!buffer_unchanged_p
)
13736 w
->base_line_number
= Qnil
;
13738 /* Move backward half the height of the window. */
13739 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13740 it
.current_y
= it
.last_visible_y
;
13741 move_it_vertically_backward (&it
, centering_position
);
13742 xassert (IT_CHARPOS (it
) >= BEGV
);
13744 /* The function move_it_vertically_backward may move over more
13745 than the specified y-distance. If it->w is small, e.g. a
13746 mini-buffer window, we may end up in front of the window's
13747 display area. Start displaying at the start of the line
13748 containing PT in this case. */
13749 if (it
.current_y
<= 0)
13751 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13752 move_it_vertically_backward (&it
, 0);
13756 it
.current_x
= it
.hpos
= 0;
13758 /* Set startp here explicitly in case that helps avoid an infinite loop
13759 in case the window-scroll-functions functions get errors. */
13760 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13762 /* Run scroll hooks. */
13763 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13765 /* Redisplay the window. */
13766 if (!current_matrix_up_to_date_p
13767 || windows_or_buffers_changed
13768 || cursor_type_changed
13769 /* Don't use try_window_reusing_current_matrix in this case
13770 because it can have changed the buffer. */
13771 || !NILP (Vwindow_scroll_functions
)
13772 || !just_this_one_p
13773 || MINI_WINDOW_P (w
)
13774 || !(used_current_matrix_p
13775 = try_window_reusing_current_matrix (w
)))
13776 try_window (window
, startp
, 0);
13778 /* If new fonts have been loaded (due to fontsets), give up. We
13779 have to start a new redisplay since we need to re-adjust glyph
13781 if (fonts_changed_p
)
13782 goto need_larger_matrices
;
13784 /* If cursor did not appear assume that the middle of the window is
13785 in the first line of the window. Do it again with the next line.
13786 (Imagine a window of height 100, displaying two lines of height
13787 60. Moving back 50 from it->last_visible_y will end in the first
13789 if (w
->cursor
.vpos
< 0)
13791 if (!NILP (w
->window_end_valid
)
13792 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13794 clear_glyph_matrix (w
->desired_matrix
);
13795 move_it_by_lines (&it
, 1, 0);
13796 try_window (window
, it
.current
.pos
, 0);
13798 else if (PT
< IT_CHARPOS (it
))
13800 clear_glyph_matrix (w
->desired_matrix
);
13801 move_it_by_lines (&it
, -1, 0);
13802 try_window (window
, it
.current
.pos
, 0);
13806 /* Not much we can do about it. */
13810 /* Consider the following case: Window starts at BEGV, there is
13811 invisible, intangible text at BEGV, so that display starts at
13812 some point START > BEGV. It can happen that we are called with
13813 PT somewhere between BEGV and START. Try to handle that case. */
13814 if (w
->cursor
.vpos
< 0)
13816 struct glyph_row
*row
= w
->current_matrix
->rows
;
13817 if (row
->mode_line_p
)
13819 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13822 if (!cursor_row_fully_visible_p (w
, 0, 0))
13824 /* If vscroll is enabled, disable it and try again. */
13828 clear_glyph_matrix (w
->desired_matrix
);
13832 /* If centering point failed to make the whole line visible,
13833 put point at the top instead. That has to make the whole line
13834 visible, if it can be done. */
13835 if (centering_position
== 0)
13838 clear_glyph_matrix (w
->desired_matrix
);
13839 centering_position
= 0;
13845 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13846 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13847 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13850 /* Display the mode line, if we must. */
13851 if ((update_mode_line
13852 /* If window not full width, must redo its mode line
13853 if (a) the window to its side is being redone and
13854 (b) we do a frame-based redisplay. This is a consequence
13855 of how inverted lines are drawn in frame-based redisplay. */
13856 || (!just_this_one_p
13857 && !FRAME_WINDOW_P (f
)
13858 && !WINDOW_FULL_WIDTH_P (w
))
13859 /* Line number to display. */
13860 || INTEGERP (w
->base_line_pos
)
13861 /* Column number is displayed and different from the one displayed. */
13862 || (!NILP (w
->column_number_displayed
)
13863 && (XFASTINT (w
->column_number_displayed
)
13864 != (int) current_column ()))) /* iftc */
13865 /* This means that the window has a mode line. */
13866 && (WINDOW_WANTS_MODELINE_P (w
)
13867 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13869 display_mode_lines (w
);
13871 /* If mode line height has changed, arrange for a thorough
13872 immediate redisplay using the correct mode line height. */
13873 if (WINDOW_WANTS_MODELINE_P (w
)
13874 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13876 fonts_changed_p
= 1;
13877 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13878 = DESIRED_MODE_LINE_HEIGHT (w
);
13881 /* If header line height has changed, arrange for a thorough
13882 immediate redisplay using the correct header line height. */
13883 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13884 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13886 fonts_changed_p
= 1;
13887 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13888 = DESIRED_HEADER_LINE_HEIGHT (w
);
13891 if (fonts_changed_p
)
13892 goto need_larger_matrices
;
13895 if (!line_number_displayed
13896 && !BUFFERP (w
->base_line_pos
))
13898 w
->base_line_pos
= Qnil
;
13899 w
->base_line_number
= Qnil
;
13904 /* When we reach a frame's selected window, redo the frame's menu bar. */
13905 if (update_mode_line
13906 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13908 int redisplay_menu_p
= 0;
13909 int redisplay_tool_bar_p
= 0;
13911 if (FRAME_WINDOW_P (f
))
13913 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
13914 || defined (HAVE_NS) || defined (USE_GTK)
13915 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13917 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13921 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13923 if (redisplay_menu_p
)
13924 display_menu_bar (w
);
13926 #ifdef HAVE_WINDOW_SYSTEM
13927 if (FRAME_WINDOW_P (f
))
13929 #if defined (USE_GTK) || defined (HAVE_NS)
13930 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13932 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13933 && (FRAME_TOOL_BAR_LINES (f
) > 0
13934 || !NILP (Vauto_resize_tool_bars
));
13937 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13939 extern int ignore_mouse_drag_p
;
13940 ignore_mouse_drag_p
= 1;
13946 #ifdef HAVE_WINDOW_SYSTEM
13947 if (FRAME_WINDOW_P (f
)
13948 && update_window_fringes (w
, (just_this_one_p
13949 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13950 || w
->pseudo_window_p
)))
13954 if (draw_window_fringes (w
, 1))
13955 x_draw_vertical_border (w
);
13959 #endif /* HAVE_WINDOW_SYSTEM */
13961 /* We go to this label, with fonts_changed_p nonzero,
13962 if it is necessary to try again using larger glyph matrices.
13963 We have to redeem the scroll bar even in this case,
13964 because the loop in redisplay_internal expects that. */
13965 need_larger_matrices
:
13967 finish_scroll_bars
:
13969 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
13971 /* Set the thumb's position and size. */
13972 set_vertical_scroll_bar (w
);
13974 /* Note that we actually used the scroll bar attached to this
13975 window, so it shouldn't be deleted at the end of redisplay. */
13976 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
13977 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
13980 /* Restore current_buffer and value of point in it. */
13981 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
13982 set_buffer_internal_1 (old
);
13983 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
13984 shorter. This can be caused by log truncation in *Messages*. */
13985 if (CHARPOS (lpoint
) <= ZV
)
13986 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
13988 unbind_to (count
, Qnil
);
13992 /* Build the complete desired matrix of WINDOW with a window start
13993 buffer position POS.
13995 Value is 1 if successful. It is zero if fonts were loaded during
13996 redisplay which makes re-adjusting glyph matrices necessary, and -1
13997 if point would appear in the scroll margins.
13998 (We check that only if CHECK_MARGINS is nonzero. */
14001 try_window (window
, pos
, check_margins
)
14002 Lisp_Object window
;
14003 struct text_pos pos
;
14006 struct window
*w
= XWINDOW (window
);
14008 struct glyph_row
*last_text_row
= NULL
;
14009 struct frame
*f
= XFRAME (w
->frame
);
14011 /* Make POS the new window start. */
14012 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14014 /* Mark cursor position as unknown. No overlay arrow seen. */
14015 w
->cursor
.vpos
= -1;
14016 overlay_arrow_seen
= 0;
14018 /* Initialize iterator and info to start at POS. */
14019 start_display (&it
, w
, pos
);
14021 /* Display all lines of W. */
14022 while (it
.current_y
< it
.last_visible_y
)
14024 if (display_line (&it
))
14025 last_text_row
= it
.glyph_row
- 1;
14026 if (fonts_changed_p
)
14030 /* Don't let the cursor end in the scroll margins. */
14032 && !MINI_WINDOW_P (w
))
14034 int this_scroll_margin
;
14036 if (scroll_margin
> 0)
14038 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14039 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14042 this_scroll_margin
= 0;
14044 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14045 && w
->cursor
.y
< this_scroll_margin
14046 && CHARPOS (pos
) > BEGV
14047 && IT_CHARPOS (it
) < ZV
)
14048 /* rms: considering make_cursor_line_fully_visible_p here
14049 seems to give wrong results. We don't want to recenter
14050 when the last line is partly visible, we want to allow
14051 that case to be handled in the usual way. */
14052 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14054 w
->cursor
.vpos
= -1;
14055 clear_glyph_matrix (w
->desired_matrix
);
14060 /* If bottom moved off end of frame, change mode line percentage. */
14061 if (XFASTINT (w
->window_end_pos
) <= 0
14062 && Z
!= IT_CHARPOS (it
))
14063 w
->update_mode_line
= Qt
;
14065 /* Set window_end_pos to the offset of the last character displayed
14066 on the window from the end of current_buffer. Set
14067 window_end_vpos to its row number. */
14070 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14071 w
->window_end_bytepos
14072 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14074 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14076 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14077 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14078 ->displays_text_p
);
14082 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14083 w
->window_end_pos
= make_number (Z
- ZV
);
14084 w
->window_end_vpos
= make_number (0);
14087 /* But that is not valid info until redisplay finishes. */
14088 w
->window_end_valid
= Qnil
;
14094 /************************************************************************
14095 Window redisplay reusing current matrix when buffer has not changed
14096 ************************************************************************/
14098 /* Try redisplay of window W showing an unchanged buffer with a
14099 different window start than the last time it was displayed by
14100 reusing its current matrix. Value is non-zero if successful.
14101 W->start is the new window start. */
14104 try_window_reusing_current_matrix (w
)
14107 struct frame
*f
= XFRAME (w
->frame
);
14108 struct glyph_row
*row
, *bottom_row
;
14111 struct text_pos start
, new_start
;
14112 int nrows_scrolled
, i
;
14113 struct glyph_row
*last_text_row
;
14114 struct glyph_row
*last_reused_text_row
;
14115 struct glyph_row
*start_row
;
14116 int start_vpos
, min_y
, max_y
;
14119 if (inhibit_try_window_reusing
)
14123 if (/* This function doesn't handle terminal frames. */
14124 !FRAME_WINDOW_P (f
)
14125 /* Don't try to reuse the display if windows have been split
14127 || windows_or_buffers_changed
14128 || cursor_type_changed
)
14131 /* Can't do this if region may have changed. */
14132 if ((!NILP (Vtransient_mark_mode
)
14133 && !NILP (current_buffer
->mark_active
))
14134 || !NILP (w
->region_showing
)
14135 || !NILP (Vshow_trailing_whitespace
))
14138 /* If top-line visibility has changed, give up. */
14139 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14140 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14143 /* Give up if old or new display is scrolled vertically. We could
14144 make this function handle this, but right now it doesn't. */
14145 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14146 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14149 /* The variable new_start now holds the new window start. The old
14150 start `start' can be determined from the current matrix. */
14151 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14152 start
= start_row
->start
.pos
;
14153 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14155 /* Clear the desired matrix for the display below. */
14156 clear_glyph_matrix (w
->desired_matrix
);
14158 if (CHARPOS (new_start
) <= CHARPOS (start
))
14162 /* Don't use this method if the display starts with an ellipsis
14163 displayed for invisible text. It's not easy to handle that case
14164 below, and it's certainly not worth the effort since this is
14165 not a frequent case. */
14166 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14169 IF_DEBUG (debug_method_add (w
, "twu1"));
14171 /* Display up to a row that can be reused. The variable
14172 last_text_row is set to the last row displayed that displays
14173 text. Note that it.vpos == 0 if or if not there is a
14174 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14175 start_display (&it
, w
, new_start
);
14176 first_row_y
= it
.current_y
;
14177 w
->cursor
.vpos
= -1;
14178 last_text_row
= last_reused_text_row
= NULL
;
14180 while (it
.current_y
< it
.last_visible_y
14181 && !fonts_changed_p
)
14183 /* If we have reached into the characters in the START row,
14184 that means the line boundaries have changed. So we
14185 can't start copying with the row START. Maybe it will
14186 work to start copying with the following row. */
14187 while (IT_CHARPOS (it
) > CHARPOS (start
))
14189 /* Advance to the next row as the "start". */
14191 start
= start_row
->start
.pos
;
14192 /* If there are no more rows to try, or just one, give up. */
14193 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14194 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14195 || CHARPOS (start
) == ZV
)
14197 clear_glyph_matrix (w
->desired_matrix
);
14201 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14203 /* If we have reached alignment,
14204 we can copy the rest of the rows. */
14205 if (IT_CHARPOS (it
) == CHARPOS (start
))
14208 if (display_line (&it
))
14209 last_text_row
= it
.glyph_row
- 1;
14212 /* A value of current_y < last_visible_y means that we stopped
14213 at the previous window start, which in turn means that we
14214 have at least one reusable row. */
14215 if (it
.current_y
< it
.last_visible_y
)
14217 /* IT.vpos always starts from 0; it counts text lines. */
14218 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14220 /* Find PT if not already found in the lines displayed. */
14221 if (w
->cursor
.vpos
< 0)
14223 int dy
= it
.current_y
- start_row
->y
;
14225 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14226 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14228 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14229 dy
, nrows_scrolled
);
14232 clear_glyph_matrix (w
->desired_matrix
);
14237 /* Scroll the display. Do it before the current matrix is
14238 changed. The problem here is that update has not yet
14239 run, i.e. part of the current matrix is not up to date.
14240 scroll_run_hook will clear the cursor, and use the
14241 current matrix to get the height of the row the cursor is
14243 run
.current_y
= start_row
->y
;
14244 run
.desired_y
= it
.current_y
;
14245 run
.height
= it
.last_visible_y
- it
.current_y
;
14247 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14250 FRAME_RIF (f
)->update_window_begin_hook (w
);
14251 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14252 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14253 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14257 /* Shift current matrix down by nrows_scrolled lines. */
14258 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14259 rotate_matrix (w
->current_matrix
,
14261 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14264 /* Disable lines that must be updated. */
14265 for (i
= 0; i
< nrows_scrolled
; ++i
)
14266 (start_row
+ i
)->enabled_p
= 0;
14268 /* Re-compute Y positions. */
14269 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14270 max_y
= it
.last_visible_y
;
14271 for (row
= start_row
+ nrows_scrolled
;
14275 row
->y
= it
.current_y
;
14276 row
->visible_height
= row
->height
;
14278 if (row
->y
< min_y
)
14279 row
->visible_height
-= min_y
- row
->y
;
14280 if (row
->y
+ row
->height
> max_y
)
14281 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14282 row
->redraw_fringe_bitmaps_p
= 1;
14284 it
.current_y
+= row
->height
;
14286 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14287 last_reused_text_row
= row
;
14288 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14292 /* Disable lines in the current matrix which are now
14293 below the window. */
14294 for (++row
; row
< bottom_row
; ++row
)
14295 row
->enabled_p
= row
->mode_line_p
= 0;
14298 /* Update window_end_pos etc.; last_reused_text_row is the last
14299 reused row from the current matrix containing text, if any.
14300 The value of last_text_row is the last displayed line
14301 containing text. */
14302 if (last_reused_text_row
)
14304 w
->window_end_bytepos
14305 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14307 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14309 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14310 w
->current_matrix
));
14312 else if (last_text_row
)
14314 w
->window_end_bytepos
14315 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14317 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14319 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14323 /* This window must be completely empty. */
14324 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14325 w
->window_end_pos
= make_number (Z
- ZV
);
14326 w
->window_end_vpos
= make_number (0);
14328 w
->window_end_valid
= Qnil
;
14330 /* Update hint: don't try scrolling again in update_window. */
14331 w
->desired_matrix
->no_scrolling_p
= 1;
14334 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14338 else if (CHARPOS (new_start
) > CHARPOS (start
))
14340 struct glyph_row
*pt_row
, *row
;
14341 struct glyph_row
*first_reusable_row
;
14342 struct glyph_row
*first_row_to_display
;
14344 int yb
= window_text_bottom_y (w
);
14346 /* Find the row starting at new_start, if there is one. Don't
14347 reuse a partially visible line at the end. */
14348 first_reusable_row
= start_row
;
14349 while (first_reusable_row
->enabled_p
14350 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14351 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14352 < CHARPOS (new_start
)))
14353 ++first_reusable_row
;
14355 /* Give up if there is no row to reuse. */
14356 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14357 || !first_reusable_row
->enabled_p
14358 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14359 != CHARPOS (new_start
)))
14362 /* We can reuse fully visible rows beginning with
14363 first_reusable_row to the end of the window. Set
14364 first_row_to_display to the first row that cannot be reused.
14365 Set pt_row to the row containing point, if there is any. */
14367 for (first_row_to_display
= first_reusable_row
;
14368 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14369 ++first_row_to_display
)
14371 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14372 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14373 pt_row
= first_row_to_display
;
14376 /* Start displaying at the start of first_row_to_display. */
14377 xassert (first_row_to_display
->y
< yb
);
14378 init_to_row_start (&it
, w
, first_row_to_display
);
14380 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14382 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14384 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14385 + WINDOW_HEADER_LINE_HEIGHT (w
));
14387 /* Display lines beginning with first_row_to_display in the
14388 desired matrix. Set last_text_row to the last row displayed
14389 that displays text. */
14390 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14391 if (pt_row
== NULL
)
14392 w
->cursor
.vpos
= -1;
14393 last_text_row
= NULL
;
14394 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14395 if (display_line (&it
))
14396 last_text_row
= it
.glyph_row
- 1;
14398 /* If point is in a reused row, adjust y and vpos of the cursor
14402 w
->cursor
.vpos
-= nrows_scrolled
;
14403 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14406 /* Give up if point isn't in a row displayed or reused. (This
14407 also handles the case where w->cursor.vpos < nrows_scrolled
14408 after the calls to display_line, which can happen with scroll
14409 margins. See bug#1295.) */
14410 if (w
->cursor
.vpos
< 0)
14412 clear_glyph_matrix (w
->desired_matrix
);
14416 /* Scroll the display. */
14417 run
.current_y
= first_reusable_row
->y
;
14418 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14419 run
.height
= it
.last_visible_y
- run
.current_y
;
14420 dy
= run
.current_y
- run
.desired_y
;
14425 FRAME_RIF (f
)->update_window_begin_hook (w
);
14426 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14427 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14428 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14432 /* Adjust Y positions of reused rows. */
14433 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14434 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14435 max_y
= it
.last_visible_y
;
14436 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14439 row
->visible_height
= row
->height
;
14440 if (row
->y
< min_y
)
14441 row
->visible_height
-= min_y
- row
->y
;
14442 if (row
->y
+ row
->height
> max_y
)
14443 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14444 row
->redraw_fringe_bitmaps_p
= 1;
14447 /* Scroll the current matrix. */
14448 xassert (nrows_scrolled
> 0);
14449 rotate_matrix (w
->current_matrix
,
14451 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14454 /* Disable rows not reused. */
14455 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14456 row
->enabled_p
= 0;
14458 /* Point may have moved to a different line, so we cannot assume that
14459 the previous cursor position is valid; locate the correct row. */
14462 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14463 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14467 w
->cursor
.y
= row
->y
;
14469 if (row
< bottom_row
)
14471 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14472 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14475 && (!BUFFERP (glyph
->object
)
14476 || glyph
->charpos
< PT
);
14480 w
->cursor
.x
+= glyph
->pixel_width
;
14485 /* Adjust window end. A null value of last_text_row means that
14486 the window end is in reused rows which in turn means that
14487 only its vpos can have changed. */
14490 w
->window_end_bytepos
14491 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14493 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14495 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14500 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14503 w
->window_end_valid
= Qnil
;
14504 w
->desired_matrix
->no_scrolling_p
= 1;
14507 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14517 /************************************************************************
14518 Window redisplay reusing current matrix when buffer has changed
14519 ************************************************************************/
14521 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14522 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14524 static struct glyph_row
*
14525 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14526 struct glyph_row
*));
14529 /* Return the last row in MATRIX displaying text. If row START is
14530 non-null, start searching with that row. IT gives the dimensions
14531 of the display. Value is null if matrix is empty; otherwise it is
14532 a pointer to the row found. */
14534 static struct glyph_row
*
14535 find_last_row_displaying_text (matrix
, it
, start
)
14536 struct glyph_matrix
*matrix
;
14538 struct glyph_row
*start
;
14540 struct glyph_row
*row
, *row_found
;
14542 /* Set row_found to the last row in IT->w's current matrix
14543 displaying text. The loop looks funny but think of partially
14546 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14547 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14549 xassert (row
->enabled_p
);
14551 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14560 /* Return the last row in the current matrix of W that is not affected
14561 by changes at the start of current_buffer that occurred since W's
14562 current matrix was built. Value is null if no such row exists.
14564 BEG_UNCHANGED us the number of characters unchanged at the start of
14565 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14566 first changed character in current_buffer. Characters at positions <
14567 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14568 when the current matrix was built. */
14570 static struct glyph_row
*
14571 find_last_unchanged_at_beg_row (w
)
14574 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14575 struct glyph_row
*row
;
14576 struct glyph_row
*row_found
= NULL
;
14577 int yb
= window_text_bottom_y (w
);
14579 /* Find the last row displaying unchanged text. */
14580 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14581 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14582 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14585 if (/* If row ends before first_changed_pos, it is unchanged,
14586 except in some case. */
14587 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14588 /* When row ends in ZV and we write at ZV it is not
14590 && !row
->ends_at_zv_p
14591 /* When first_changed_pos is the end of a continued line,
14592 row is not unchanged because it may be no longer
14594 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14595 && (row
->continued_p
14596 || row
->exact_window_width_line_p
)))
14599 /* Stop if last visible row. */
14600 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14608 /* Find the first glyph row in the current matrix of W that is not
14609 affected by changes at the end of current_buffer since the
14610 time W's current matrix was built.
14612 Return in *DELTA the number of chars by which buffer positions in
14613 unchanged text at the end of current_buffer must be adjusted.
14615 Return in *DELTA_BYTES the corresponding number of bytes.
14617 Value is null if no such row exists, i.e. all rows are affected by
14620 static struct glyph_row
*
14621 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14623 int *delta
, *delta_bytes
;
14625 struct glyph_row
*row
;
14626 struct glyph_row
*row_found
= NULL
;
14628 *delta
= *delta_bytes
= 0;
14630 /* Display must not have been paused, otherwise the current matrix
14631 is not up to date. */
14632 eassert (!NILP (w
->window_end_valid
));
14634 /* A value of window_end_pos >= END_UNCHANGED means that the window
14635 end is in the range of changed text. If so, there is no
14636 unchanged row at the end of W's current matrix. */
14637 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14640 /* Set row to the last row in W's current matrix displaying text. */
14641 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14643 /* If matrix is entirely empty, no unchanged row exists. */
14644 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14646 /* The value of row is the last glyph row in the matrix having a
14647 meaningful buffer position in it. The end position of row
14648 corresponds to window_end_pos. This allows us to translate
14649 buffer positions in the current matrix to current buffer
14650 positions for characters not in changed text. */
14651 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14652 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14653 int last_unchanged_pos
, last_unchanged_pos_old
;
14654 struct glyph_row
*first_text_row
14655 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14657 *delta
= Z
- Z_old
;
14658 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14660 /* Set last_unchanged_pos to the buffer position of the last
14661 character in the buffer that has not been changed. Z is the
14662 index + 1 of the last character in current_buffer, i.e. by
14663 subtracting END_UNCHANGED we get the index of the last
14664 unchanged character, and we have to add BEG to get its buffer
14666 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14667 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14669 /* Search backward from ROW for a row displaying a line that
14670 starts at a minimum position >= last_unchanged_pos_old. */
14671 for (; row
> first_text_row
; --row
)
14673 /* This used to abort, but it can happen.
14674 It is ok to just stop the search instead here. KFS. */
14675 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14678 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14683 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14689 /* Make sure that glyph rows in the current matrix of window W
14690 reference the same glyph memory as corresponding rows in the
14691 frame's frame matrix. This function is called after scrolling W's
14692 current matrix on a terminal frame in try_window_id and
14693 try_window_reusing_current_matrix. */
14696 sync_frame_with_window_matrix_rows (w
)
14699 struct frame
*f
= XFRAME (w
->frame
);
14700 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14702 /* Preconditions: W must be a leaf window and full-width. Its frame
14703 must have a frame matrix. */
14704 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14705 xassert (WINDOW_FULL_WIDTH_P (w
));
14706 xassert (!FRAME_WINDOW_P (f
));
14708 /* If W is a full-width window, glyph pointers in W's current matrix
14709 have, by definition, to be the same as glyph pointers in the
14710 corresponding frame matrix. Note that frame matrices have no
14711 marginal areas (see build_frame_matrix). */
14712 window_row
= w
->current_matrix
->rows
;
14713 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14714 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14715 while (window_row
< window_row_end
)
14717 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14718 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14720 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14721 frame_row
->glyphs
[TEXT_AREA
] = start
;
14722 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14723 frame_row
->glyphs
[LAST_AREA
] = end
;
14725 /* Disable frame rows whose corresponding window rows have
14726 been disabled in try_window_id. */
14727 if (!window_row
->enabled_p
)
14728 frame_row
->enabled_p
= 0;
14730 ++window_row
, ++frame_row
;
14735 /* Find the glyph row in window W containing CHARPOS. Consider all
14736 rows between START and END (not inclusive). END null means search
14737 all rows to the end of the display area of W. Value is the row
14738 containing CHARPOS or null. */
14741 row_containing_pos (w
, charpos
, start
, end
, dy
)
14744 struct glyph_row
*start
, *end
;
14747 struct glyph_row
*row
= start
;
14750 /* If we happen to start on a header-line, skip that. */
14751 if (row
->mode_line_p
)
14754 if ((end
&& row
>= end
) || !row
->enabled_p
)
14757 last_y
= window_text_bottom_y (w
) - dy
;
14761 /* Give up if we have gone too far. */
14762 if (end
&& row
>= end
)
14764 /* This formerly returned if they were equal.
14765 I think that both quantities are of a "last plus one" type;
14766 if so, when they are equal, the row is within the screen. -- rms. */
14767 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14770 /* If it is in this row, return this row. */
14771 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14772 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14773 /* The end position of a row equals the start
14774 position of the next row. If CHARPOS is there, we
14775 would rather display it in the next line, except
14776 when this line ends in ZV. */
14777 && !row
->ends_at_zv_p
14778 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14779 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14786 /* Try to redisplay window W by reusing its existing display. W's
14787 current matrix must be up to date when this function is called,
14788 i.e. window_end_valid must not be nil.
14792 1 if display has been updated
14793 0 if otherwise unsuccessful
14794 -1 if redisplay with same window start is known not to succeed
14796 The following steps are performed:
14798 1. Find the last row in the current matrix of W that is not
14799 affected by changes at the start of current_buffer. If no such row
14802 2. Find the first row in W's current matrix that is not affected by
14803 changes at the end of current_buffer. Maybe there is no such row.
14805 3. Display lines beginning with the row + 1 found in step 1 to the
14806 row found in step 2 or, if step 2 didn't find a row, to the end of
14809 4. If cursor is not known to appear on the window, give up.
14811 5. If display stopped at the row found in step 2, scroll the
14812 display and current matrix as needed.
14814 6. Maybe display some lines at the end of W, if we must. This can
14815 happen under various circumstances, like a partially visible line
14816 becoming fully visible, or because newly displayed lines are displayed
14817 in smaller font sizes.
14819 7. Update W's window end information. */
14825 struct frame
*f
= XFRAME (w
->frame
);
14826 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14827 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14828 struct glyph_row
*last_unchanged_at_beg_row
;
14829 struct glyph_row
*first_unchanged_at_end_row
;
14830 struct glyph_row
*row
;
14831 struct glyph_row
*bottom_row
;
14834 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14835 struct text_pos start_pos
;
14837 int first_unchanged_at_end_vpos
= 0;
14838 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14839 struct text_pos start
;
14840 int first_changed_charpos
, last_changed_charpos
;
14843 if (inhibit_try_window_id
)
14847 /* This is handy for debugging. */
14849 #define GIVE_UP(X) \
14851 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14855 #define GIVE_UP(X) return 0
14858 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14860 /* Don't use this for mini-windows because these can show
14861 messages and mini-buffers, and we don't handle that here. */
14862 if (MINI_WINDOW_P (w
))
14865 /* This flag is used to prevent redisplay optimizations. */
14866 if (windows_or_buffers_changed
|| cursor_type_changed
)
14869 /* Verify that narrowing has not changed.
14870 Also verify that we were not told to prevent redisplay optimizations.
14871 It would be nice to further
14872 reduce the number of cases where this prevents try_window_id. */
14873 if (current_buffer
->clip_changed
14874 || current_buffer
->prevent_redisplay_optimizations_p
)
14877 /* Window must either use window-based redisplay or be full width. */
14878 if (!FRAME_WINDOW_P (f
)
14879 && (!FRAME_LINE_INS_DEL_OK (f
)
14880 || !WINDOW_FULL_WIDTH_P (w
)))
14883 /* Give up if point is known NOT to appear in W. */
14884 if (PT
< CHARPOS (start
))
14887 /* Another way to prevent redisplay optimizations. */
14888 if (XFASTINT (w
->last_modified
) == 0)
14891 /* Verify that window is not hscrolled. */
14892 if (XFASTINT (w
->hscroll
) != 0)
14895 /* Verify that display wasn't paused. */
14896 if (NILP (w
->window_end_valid
))
14899 /* Can't use this if highlighting a region because a cursor movement
14900 will do more than just set the cursor. */
14901 if (!NILP (Vtransient_mark_mode
)
14902 && !NILP (current_buffer
->mark_active
))
14905 /* Likewise if highlighting trailing whitespace. */
14906 if (!NILP (Vshow_trailing_whitespace
))
14909 /* Likewise if showing a region. */
14910 if (!NILP (w
->region_showing
))
14913 /* Can't use this if overlay arrow position and/or string have
14915 if (overlay_arrows_changed_p ())
14918 /* When word-wrap is on, adding a space to the first word of a
14919 wrapped line can change the wrap position, altering the line
14920 above it. It might be worthwhile to handle this more
14921 intelligently, but for now just redisplay from scratch. */
14922 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14925 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14926 only if buffer has really changed. The reason is that the gap is
14927 initially at Z for freshly visited files. The code below would
14928 set end_unchanged to 0 in that case. */
14929 if (MODIFF
> SAVE_MODIFF
14930 /* This seems to happen sometimes after saving a buffer. */
14931 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14933 if (GPT
- BEG
< BEG_UNCHANGED
)
14934 BEG_UNCHANGED
= GPT
- BEG
;
14935 if (Z
- GPT
< END_UNCHANGED
)
14936 END_UNCHANGED
= Z
- GPT
;
14939 /* The position of the first and last character that has been changed. */
14940 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14941 last_changed_charpos
= Z
- END_UNCHANGED
;
14943 /* If window starts after a line end, and the last change is in
14944 front of that newline, then changes don't affect the display.
14945 This case happens with stealth-fontification. Note that although
14946 the display is unchanged, glyph positions in the matrix have to
14947 be adjusted, of course. */
14948 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14949 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14950 && ((last_changed_charpos
< CHARPOS (start
)
14951 && CHARPOS (start
) == BEGV
)
14952 || (last_changed_charpos
< CHARPOS (start
) - 1
14953 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14955 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14956 struct glyph_row
*r0
;
14958 /* Compute how many chars/bytes have been added to or removed
14959 from the buffer. */
14960 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14961 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14963 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14965 /* Give up if PT is not in the window. Note that it already has
14966 been checked at the start of try_window_id that PT is not in
14967 front of the window start. */
14968 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
14971 /* If window start is unchanged, we can reuse the whole matrix
14972 as is, after adjusting glyph positions. No need to compute
14973 the window end again, since its offset from Z hasn't changed. */
14974 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
14975 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
14976 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
14977 /* PT must not be in a partially visible line. */
14978 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
14979 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
14981 /* Adjust positions in the glyph matrix. */
14982 if (delta
|| delta_bytes
)
14984 struct glyph_row
*r1
14985 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
14986 increment_matrix_positions (w
->current_matrix
,
14987 MATRIX_ROW_VPOS (r0
, current_matrix
),
14988 MATRIX_ROW_VPOS (r1
, current_matrix
),
14989 delta
, delta_bytes
);
14992 /* Set the cursor. */
14993 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
14995 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15002 /* Handle the case that changes are all below what is displayed in
15003 the window, and that PT is in the window. This shortcut cannot
15004 be taken if ZV is visible in the window, and text has been added
15005 there that is visible in the window. */
15006 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15007 /* ZV is not visible in the window, or there are no
15008 changes at ZV, actually. */
15009 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15010 || first_changed_charpos
== last_changed_charpos
))
15012 struct glyph_row
*r0
;
15014 /* Give up if PT is not in the window. Note that it already has
15015 been checked at the start of try_window_id that PT is not in
15016 front of the window start. */
15017 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15020 /* If window start is unchanged, we can reuse the whole matrix
15021 as is, without changing glyph positions since no text has
15022 been added/removed in front of the window end. */
15023 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15024 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15025 /* PT must not be in a partially visible line. */
15026 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15027 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15029 /* We have to compute the window end anew since text
15030 can have been added/removed after it. */
15032 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15033 w
->window_end_bytepos
15034 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15036 /* Set the cursor. */
15037 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15039 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15046 /* Give up if window start is in the changed area.
15048 The condition used to read
15050 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15052 but why that was tested escapes me at the moment. */
15053 if (CHARPOS (start
) >= first_changed_charpos
15054 && CHARPOS (start
) <= last_changed_charpos
)
15057 /* Check that window start agrees with the start of the first glyph
15058 row in its current matrix. Check this after we know the window
15059 start is not in changed text, otherwise positions would not be
15061 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15062 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15065 /* Give up if the window ends in strings. Overlay strings
15066 at the end are difficult to handle, so don't try. */
15067 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15068 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15071 /* Compute the position at which we have to start displaying new
15072 lines. Some of the lines at the top of the window might be
15073 reusable because they are not displaying changed text. Find the
15074 last row in W's current matrix not affected by changes at the
15075 start of current_buffer. Value is null if changes start in the
15076 first line of window. */
15077 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15078 if (last_unchanged_at_beg_row
)
15080 /* Avoid starting to display in the moddle of a character, a TAB
15081 for instance. This is easier than to set up the iterator
15082 exactly, and it's not a frequent case, so the additional
15083 effort wouldn't really pay off. */
15084 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15085 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15086 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15087 --last_unchanged_at_beg_row
;
15089 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15092 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15094 start_pos
= it
.current
.pos
;
15096 /* Start displaying new lines in the desired matrix at the same
15097 vpos we would use in the current matrix, i.e. below
15098 last_unchanged_at_beg_row. */
15099 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15101 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15102 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15104 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15108 /* There are no reusable lines at the start of the window.
15109 Start displaying in the first text line. */
15110 start_display (&it
, w
, start
);
15111 it
.vpos
= it
.first_vpos
;
15112 start_pos
= it
.current
.pos
;
15115 /* Find the first row that is not affected by changes at the end of
15116 the buffer. Value will be null if there is no unchanged row, in
15117 which case we must redisplay to the end of the window. delta
15118 will be set to the value by which buffer positions beginning with
15119 first_unchanged_at_end_row have to be adjusted due to text
15121 first_unchanged_at_end_row
15122 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15123 IF_DEBUG (debug_delta
= delta
);
15124 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15126 /* Set stop_pos to the buffer position up to which we will have to
15127 display new lines. If first_unchanged_at_end_row != NULL, this
15128 is the buffer position of the start of the line displayed in that
15129 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15130 that we don't stop at a buffer position. */
15132 if (first_unchanged_at_end_row
)
15134 xassert (last_unchanged_at_beg_row
== NULL
15135 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15137 /* If this is a continuation line, move forward to the next one
15138 that isn't. Changes in lines above affect this line.
15139 Caution: this may move first_unchanged_at_end_row to a row
15140 not displaying text. */
15141 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15142 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15143 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15144 < it
.last_visible_y
))
15145 ++first_unchanged_at_end_row
;
15147 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15148 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15149 >= it
.last_visible_y
))
15150 first_unchanged_at_end_row
= NULL
;
15153 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15155 first_unchanged_at_end_vpos
15156 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15157 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15160 else if (last_unchanged_at_beg_row
== NULL
)
15166 /* Either there is no unchanged row at the end, or the one we have
15167 now displays text. This is a necessary condition for the window
15168 end pos calculation at the end of this function. */
15169 xassert (first_unchanged_at_end_row
== NULL
15170 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15172 debug_last_unchanged_at_beg_vpos
15173 = (last_unchanged_at_beg_row
15174 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15176 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15178 #endif /* GLYPH_DEBUG != 0 */
15181 /* Display new lines. Set last_text_row to the last new line
15182 displayed which has text on it, i.e. might end up as being the
15183 line where the window_end_vpos is. */
15184 w
->cursor
.vpos
= -1;
15185 last_text_row
= NULL
;
15186 overlay_arrow_seen
= 0;
15187 while (it
.current_y
< it
.last_visible_y
15188 && !fonts_changed_p
15189 && (first_unchanged_at_end_row
== NULL
15190 || IT_CHARPOS (it
) < stop_pos
))
15192 if (display_line (&it
))
15193 last_text_row
= it
.glyph_row
- 1;
15196 if (fonts_changed_p
)
15200 /* Compute differences in buffer positions, y-positions etc. for
15201 lines reused at the bottom of the window. Compute what we can
15203 if (first_unchanged_at_end_row
15204 /* No lines reused because we displayed everything up to the
15205 bottom of the window. */
15206 && it
.current_y
< it
.last_visible_y
)
15209 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15211 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15212 run
.current_y
= first_unchanged_at_end_row
->y
;
15213 run
.desired_y
= run
.current_y
+ dy
;
15214 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15218 delta
= delta_bytes
= dvpos
= dy
15219 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15220 first_unchanged_at_end_row
= NULL
;
15222 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15225 /* Find the cursor if not already found. We have to decide whether
15226 PT will appear on this window (it sometimes doesn't, but this is
15227 not a very frequent case.) This decision has to be made before
15228 the current matrix is altered. A value of cursor.vpos < 0 means
15229 that PT is either in one of the lines beginning at
15230 first_unchanged_at_end_row or below the window. Don't care for
15231 lines that might be displayed later at the window end; as
15232 mentioned, this is not a frequent case. */
15233 if (w
->cursor
.vpos
< 0)
15235 /* Cursor in unchanged rows at the top? */
15236 if (PT
< CHARPOS (start_pos
)
15237 && last_unchanged_at_beg_row
)
15239 row
= row_containing_pos (w
, PT
,
15240 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15241 last_unchanged_at_beg_row
+ 1, 0);
15243 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15246 /* Start from first_unchanged_at_end_row looking for PT. */
15247 else if (first_unchanged_at_end_row
)
15249 row
= row_containing_pos (w
, PT
- delta
,
15250 first_unchanged_at_end_row
, NULL
, 0);
15252 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15253 delta_bytes
, dy
, dvpos
);
15256 /* Give up if cursor was not found. */
15257 if (w
->cursor
.vpos
< 0)
15259 clear_glyph_matrix (w
->desired_matrix
);
15264 /* Don't let the cursor end in the scroll margins. */
15266 int this_scroll_margin
, cursor_height
;
15268 this_scroll_margin
= max (0, scroll_margin
);
15269 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15270 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15271 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15273 if ((w
->cursor
.y
< this_scroll_margin
15274 && CHARPOS (start
) > BEGV
)
15275 /* Old redisplay didn't take scroll margin into account at the bottom,
15276 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15277 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15278 ? cursor_height
+ this_scroll_margin
15279 : 1)) > it
.last_visible_y
)
15281 w
->cursor
.vpos
= -1;
15282 clear_glyph_matrix (w
->desired_matrix
);
15287 /* Scroll the display. Do it before changing the current matrix so
15288 that xterm.c doesn't get confused about where the cursor glyph is
15290 if (dy
&& run
.height
)
15294 if (FRAME_WINDOW_P (f
))
15296 FRAME_RIF (f
)->update_window_begin_hook (w
);
15297 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15298 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15299 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15303 /* Terminal frame. In this case, dvpos gives the number of
15304 lines to scroll by; dvpos < 0 means scroll up. */
15305 int first_unchanged_at_end_vpos
15306 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15307 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15308 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15309 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15310 + window_internal_height (w
));
15312 /* Perform the operation on the screen. */
15315 /* Scroll last_unchanged_at_beg_row to the end of the
15316 window down dvpos lines. */
15317 set_terminal_window (f
, end
);
15319 /* On dumb terminals delete dvpos lines at the end
15320 before inserting dvpos empty lines. */
15321 if (!FRAME_SCROLL_REGION_OK (f
))
15322 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15324 /* Insert dvpos empty lines in front of
15325 last_unchanged_at_beg_row. */
15326 ins_del_lines (f
, from
, dvpos
);
15328 else if (dvpos
< 0)
15330 /* Scroll up last_unchanged_at_beg_vpos to the end of
15331 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15332 set_terminal_window (f
, end
);
15334 /* Delete dvpos lines in front of
15335 last_unchanged_at_beg_vpos. ins_del_lines will set
15336 the cursor to the given vpos and emit |dvpos| delete
15338 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15340 /* On a dumb terminal insert dvpos empty lines at the
15342 if (!FRAME_SCROLL_REGION_OK (f
))
15343 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15346 set_terminal_window (f
, 0);
15352 /* Shift reused rows of the current matrix to the right position.
15353 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15355 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15356 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15359 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15360 bottom_vpos
, dvpos
);
15361 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15364 else if (dvpos
> 0)
15366 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15367 bottom_vpos
, dvpos
);
15368 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15369 first_unchanged_at_end_vpos
+ dvpos
, 0);
15372 /* For frame-based redisplay, make sure that current frame and window
15373 matrix are in sync with respect to glyph memory. */
15374 if (!FRAME_WINDOW_P (f
))
15375 sync_frame_with_window_matrix_rows (w
);
15377 /* Adjust buffer positions in reused rows. */
15378 if (delta
|| delta_bytes
)
15379 increment_matrix_positions (current_matrix
,
15380 first_unchanged_at_end_vpos
+ dvpos
,
15381 bottom_vpos
, delta
, delta_bytes
);
15383 /* Adjust Y positions. */
15385 shift_glyph_matrix (w
, current_matrix
,
15386 first_unchanged_at_end_vpos
+ dvpos
,
15389 if (first_unchanged_at_end_row
)
15391 first_unchanged_at_end_row
+= dvpos
;
15392 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15393 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15394 first_unchanged_at_end_row
= NULL
;
15397 /* If scrolling up, there may be some lines to display at the end of
15399 last_text_row_at_end
= NULL
;
15402 /* Scrolling up can leave for example a partially visible line
15403 at the end of the window to be redisplayed. */
15404 /* Set last_row to the glyph row in the current matrix where the
15405 window end line is found. It has been moved up or down in
15406 the matrix by dvpos. */
15407 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15408 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15410 /* If last_row is the window end line, it should display text. */
15411 xassert (last_row
->displays_text_p
);
15413 /* If window end line was partially visible before, begin
15414 displaying at that line. Otherwise begin displaying with the
15415 line following it. */
15416 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15418 init_to_row_start (&it
, w
, last_row
);
15419 it
.vpos
= last_vpos
;
15420 it
.current_y
= last_row
->y
;
15424 init_to_row_end (&it
, w
, last_row
);
15425 it
.vpos
= 1 + last_vpos
;
15426 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15430 /* We may start in a continuation line. If so, we have to
15431 get the right continuation_lines_width and current_x. */
15432 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15433 it
.hpos
= it
.current_x
= 0;
15435 /* Display the rest of the lines at the window end. */
15436 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15437 while (it
.current_y
< it
.last_visible_y
15438 && !fonts_changed_p
)
15440 /* Is it always sure that the display agrees with lines in
15441 the current matrix? I don't think so, so we mark rows
15442 displayed invalid in the current matrix by setting their
15443 enabled_p flag to zero. */
15444 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15445 if (display_line (&it
))
15446 last_text_row_at_end
= it
.glyph_row
- 1;
15450 /* Update window_end_pos and window_end_vpos. */
15451 if (first_unchanged_at_end_row
15452 && !last_text_row_at_end
)
15454 /* Window end line if one of the preserved rows from the current
15455 matrix. Set row to the last row displaying text in current
15456 matrix starting at first_unchanged_at_end_row, after
15458 xassert (first_unchanged_at_end_row
->displays_text_p
);
15459 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15460 first_unchanged_at_end_row
);
15461 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15463 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15464 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15466 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15467 xassert (w
->window_end_bytepos
>= 0);
15468 IF_DEBUG (debug_method_add (w
, "A"));
15470 else if (last_text_row_at_end
)
15473 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15474 w
->window_end_bytepos
15475 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15477 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15478 xassert (w
->window_end_bytepos
>= 0);
15479 IF_DEBUG (debug_method_add (w
, "B"));
15481 else if (last_text_row
)
15483 /* We have displayed either to the end of the window or at the
15484 end of the window, i.e. the last row with text is to be found
15485 in the desired matrix. */
15487 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15488 w
->window_end_bytepos
15489 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15491 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15492 xassert (w
->window_end_bytepos
>= 0);
15494 else if (first_unchanged_at_end_row
== NULL
15495 && last_text_row
== NULL
15496 && last_text_row_at_end
== NULL
)
15498 /* Displayed to end of window, but no line containing text was
15499 displayed. Lines were deleted at the end of the window. */
15500 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15501 int vpos
= XFASTINT (w
->window_end_vpos
);
15502 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15503 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15506 row
== NULL
&& vpos
>= first_vpos
;
15507 --vpos
, --current_row
, --desired_row
)
15509 if (desired_row
->enabled_p
)
15511 if (desired_row
->displays_text_p
)
15514 else if (current_row
->displays_text_p
)
15518 xassert (row
!= NULL
);
15519 w
->window_end_vpos
= make_number (vpos
+ 1);
15520 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15521 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15522 xassert (w
->window_end_bytepos
>= 0);
15523 IF_DEBUG (debug_method_add (w
, "C"));
15528 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15529 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15531 /* Record that display has not been completed. */
15532 w
->window_end_valid
= Qnil
;
15533 w
->desired_matrix
->no_scrolling_p
= 1;
15541 /***********************************************************************
15542 More debugging support
15543 ***********************************************************************/
15547 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15548 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15549 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15552 /* Dump the contents of glyph matrix MATRIX on stderr.
15554 GLYPHS 0 means don't show glyph contents.
15555 GLYPHS 1 means show glyphs in short form
15556 GLYPHS > 1 means show glyphs in long form. */
15559 dump_glyph_matrix (matrix
, glyphs
)
15560 struct glyph_matrix
*matrix
;
15564 for (i
= 0; i
< matrix
->nrows
; ++i
)
15565 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15569 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15570 the glyph row and area where the glyph comes from. */
15573 dump_glyph (row
, glyph
, area
)
15574 struct glyph_row
*row
;
15575 struct glyph
*glyph
;
15578 if (glyph
->type
== CHAR_GLYPH
)
15581 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15582 glyph
- row
->glyphs
[TEXT_AREA
],
15585 (BUFFERP (glyph
->object
)
15587 : (STRINGP (glyph
->object
)
15590 glyph
->pixel_width
,
15592 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15596 glyph
->left_box_line_p
,
15597 glyph
->right_box_line_p
);
15599 else if (glyph
->type
== STRETCH_GLYPH
)
15602 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15603 glyph
- row
->glyphs
[TEXT_AREA
],
15606 (BUFFERP (glyph
->object
)
15608 : (STRINGP (glyph
->object
)
15611 glyph
->pixel_width
,
15615 glyph
->left_box_line_p
,
15616 glyph
->right_box_line_p
);
15618 else if (glyph
->type
== IMAGE_GLYPH
)
15621 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15622 glyph
- row
->glyphs
[TEXT_AREA
],
15625 (BUFFERP (glyph
->object
)
15627 : (STRINGP (glyph
->object
)
15630 glyph
->pixel_width
,
15634 glyph
->left_box_line_p
,
15635 glyph
->right_box_line_p
);
15637 else if (glyph
->type
== COMPOSITE_GLYPH
)
15640 " %5d %4c %6d %c %3d 0x%05x",
15641 glyph
- row
->glyphs
[TEXT_AREA
],
15644 (BUFFERP (glyph
->object
)
15646 : (STRINGP (glyph
->object
)
15649 glyph
->pixel_width
,
15651 if (glyph
->u
.cmp
.automatic
)
15654 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
15655 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
15657 glyph
->left_box_line_p
,
15658 glyph
->right_box_line_p
);
15663 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15664 GLYPHS 0 means don't show glyph contents.
15665 GLYPHS 1 means show glyphs in short form
15666 GLYPHS > 1 means show glyphs in long form. */
15669 dump_glyph_row (row
, vpos
, glyphs
)
15670 struct glyph_row
*row
;
15675 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15676 fprintf (stderr
, "======================================================================\n");
15678 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15679 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15681 MATRIX_ROW_START_CHARPOS (row
),
15682 MATRIX_ROW_END_CHARPOS (row
),
15683 row
->used
[TEXT_AREA
],
15684 row
->contains_overlapping_glyphs_p
,
15686 row
->truncated_on_left_p
,
15687 row
->truncated_on_right_p
,
15689 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15690 row
->displays_text_p
,
15693 row
->ends_in_middle_of_char_p
,
15694 row
->starts_in_middle_of_char_p
,
15700 row
->visible_height
,
15703 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15704 row
->end
.overlay_string_index
,
15705 row
->continuation_lines_width
);
15706 fprintf (stderr
, "%9d %5d\n",
15707 CHARPOS (row
->start
.string_pos
),
15708 CHARPOS (row
->end
.string_pos
));
15709 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15710 row
->end
.dpvec_index
);
15717 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15719 struct glyph
*glyph
= row
->glyphs
[area
];
15720 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15722 /* Glyph for a line end in text. */
15723 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15726 if (glyph
< glyph_end
)
15727 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15729 for (; glyph
< glyph_end
; ++glyph
)
15730 dump_glyph (row
, glyph
, area
);
15733 else if (glyphs
== 1)
15737 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15739 char *s
= (char *) alloca (row
->used
[area
] + 1);
15742 for (i
= 0; i
< row
->used
[area
]; ++i
)
15744 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15745 if (glyph
->type
== CHAR_GLYPH
15746 && glyph
->u
.ch
< 0x80
15747 && glyph
->u
.ch
>= ' ')
15748 s
[i
] = glyph
->u
.ch
;
15754 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15760 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15761 Sdump_glyph_matrix
, 0, 1, "p",
15762 doc
: /* Dump the current matrix of the selected window to stderr.
15763 Shows contents of glyph row structures. With non-nil
15764 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15765 glyphs in short form, otherwise show glyphs in long form. */)
15767 Lisp_Object glyphs
;
15769 struct window
*w
= XWINDOW (selected_window
);
15770 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15772 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15773 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15774 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15775 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15776 fprintf (stderr
, "=============================================\n");
15777 dump_glyph_matrix (w
->current_matrix
,
15778 NILP (glyphs
) ? 0 : XINT (glyphs
));
15783 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15784 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15787 struct frame
*f
= XFRAME (selected_frame
);
15788 dump_glyph_matrix (f
->current_matrix
, 1);
15793 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15794 doc
: /* Dump glyph row ROW to stderr.
15795 GLYPH 0 means don't dump glyphs.
15796 GLYPH 1 means dump glyphs in short form.
15797 GLYPH > 1 or omitted means dump glyphs in long form. */)
15799 Lisp_Object row
, glyphs
;
15801 struct glyph_matrix
*matrix
;
15804 CHECK_NUMBER (row
);
15805 matrix
= XWINDOW (selected_window
)->current_matrix
;
15807 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15808 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15810 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15815 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15816 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15817 GLYPH 0 means don't dump glyphs.
15818 GLYPH 1 means dump glyphs in short form.
15819 GLYPH > 1 or omitted means dump glyphs in long form. */)
15821 Lisp_Object row
, glyphs
;
15823 struct frame
*sf
= SELECTED_FRAME ();
15824 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15827 CHECK_NUMBER (row
);
15829 if (vpos
>= 0 && vpos
< m
->nrows
)
15830 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15831 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15836 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15837 doc
: /* Toggle tracing of redisplay.
15838 With ARG, turn tracing on if and only if ARG is positive. */)
15843 trace_redisplay_p
= !trace_redisplay_p
;
15846 arg
= Fprefix_numeric_value (arg
);
15847 trace_redisplay_p
= XINT (arg
) > 0;
15854 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15855 doc
: /* Like `format', but print result to stderr.
15856 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15861 Lisp_Object s
= Fformat (nargs
, args
);
15862 fprintf (stderr
, "%s", SDATA (s
));
15866 #endif /* GLYPH_DEBUG */
15870 /***********************************************************************
15871 Building Desired Matrix Rows
15872 ***********************************************************************/
15874 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15875 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15877 static struct glyph_row
*
15878 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15880 Lisp_Object overlay_arrow_string
;
15882 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15883 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15884 struct buffer
*old
= current_buffer
;
15885 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15886 int arrow_len
= SCHARS (overlay_arrow_string
);
15887 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15888 const unsigned char *p
;
15891 int n_glyphs_before
;
15893 set_buffer_temp (buffer
);
15894 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15895 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15896 SET_TEXT_POS (it
.position
, 0, 0);
15898 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15900 while (p
< arrow_end
)
15902 Lisp_Object face
, ilisp
;
15904 /* Get the next character. */
15906 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15908 it
.c
= *p
, it
.len
= 1;
15911 /* Get its face. */
15912 ilisp
= make_number (p
- arrow_string
);
15913 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15914 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15916 /* Compute its width, get its glyphs. */
15917 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15918 SET_TEXT_POS (it
.position
, -1, -1);
15919 PRODUCE_GLYPHS (&it
);
15921 /* If this character doesn't fit any more in the line, we have
15922 to remove some glyphs. */
15923 if (it
.current_x
> it
.last_visible_x
)
15925 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15930 set_buffer_temp (old
);
15931 return it
.glyph_row
;
15935 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15936 glyphs are only inserted for terminal frames since we can't really
15937 win with truncation glyphs when partially visible glyphs are
15938 involved. Which glyphs to insert is determined by
15939 produce_special_glyphs. */
15942 insert_left_trunc_glyphs (it
)
15945 struct it truncate_it
;
15946 struct glyph
*from
, *end
, *to
, *toend
;
15948 xassert (!FRAME_WINDOW_P (it
->f
));
15950 /* Get the truncation glyphs. */
15952 truncate_it
.current_x
= 0;
15953 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15954 truncate_it
.glyph_row
= &scratch_glyph_row
;
15955 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15956 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15957 truncate_it
.object
= make_number (0);
15958 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15960 /* Overwrite glyphs from IT with truncation glyphs. */
15961 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15962 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15963 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15964 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
15969 /* There may be padding glyphs left over. Overwrite them too. */
15970 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
15972 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15978 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
15982 /* Compute the pixel height and width of IT->glyph_row.
15984 Most of the time, ascent and height of a display line will be equal
15985 to the max_ascent and max_height values of the display iterator
15986 structure. This is not the case if
15988 1. We hit ZV without displaying anything. In this case, max_ascent
15989 and max_height will be zero.
15991 2. We have some glyphs that don't contribute to the line height.
15992 (The glyph row flag contributes_to_line_height_p is for future
15993 pixmap extensions).
15995 The first case is easily covered by using default values because in
15996 these cases, the line height does not really matter, except that it
15997 must not be zero. */
16000 compute_line_metrics (it
)
16003 struct glyph_row
*row
= it
->glyph_row
;
16006 if (FRAME_WINDOW_P (it
->f
))
16008 int i
, min_y
, max_y
;
16010 /* The line may consist of one space only, that was added to
16011 place the cursor on it. If so, the row's height hasn't been
16013 if (row
->height
== 0)
16015 if (it
->max_ascent
+ it
->max_descent
== 0)
16016 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16017 row
->ascent
= it
->max_ascent
;
16018 row
->height
= it
->max_ascent
+ it
->max_descent
;
16019 row
->phys_ascent
= it
->max_phys_ascent
;
16020 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16021 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16024 /* Compute the width of this line. */
16025 row
->pixel_width
= row
->x
;
16026 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16027 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16029 xassert (row
->pixel_width
>= 0);
16030 xassert (row
->ascent
>= 0 && row
->height
> 0);
16032 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16033 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16035 /* If first line's physical ascent is larger than its logical
16036 ascent, use the physical ascent, and make the row taller.
16037 This makes accented characters fully visible. */
16038 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16039 && row
->phys_ascent
> row
->ascent
)
16041 row
->height
+= row
->phys_ascent
- row
->ascent
;
16042 row
->ascent
= row
->phys_ascent
;
16045 /* Compute how much of the line is visible. */
16046 row
->visible_height
= row
->height
;
16048 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16049 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16051 if (row
->y
< min_y
)
16052 row
->visible_height
-= min_y
- row
->y
;
16053 if (row
->y
+ row
->height
> max_y
)
16054 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16058 row
->pixel_width
= row
->used
[TEXT_AREA
];
16059 if (row
->continued_p
)
16060 row
->pixel_width
-= it
->continuation_pixel_width
;
16061 else if (row
->truncated_on_right_p
)
16062 row
->pixel_width
-= it
->truncation_pixel_width
;
16063 row
->ascent
= row
->phys_ascent
= 0;
16064 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16065 row
->extra_line_spacing
= 0;
16068 /* Compute a hash code for this row. */
16070 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16071 for (i
= 0; i
< row
->used
[area
]; ++i
)
16072 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16073 + row
->glyphs
[area
][i
].u
.val
16074 + row
->glyphs
[area
][i
].face_id
16075 + row
->glyphs
[area
][i
].padding_p
16076 + (row
->glyphs
[area
][i
].type
<< 2));
16078 it
->max_ascent
= it
->max_descent
= 0;
16079 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16083 /* Append one space to the glyph row of iterator IT if doing a
16084 window-based redisplay. The space has the same face as
16085 IT->face_id. Value is non-zero if a space was added.
16087 This function is called to make sure that there is always one glyph
16088 at the end of a glyph row that the cursor can be set on under
16089 window-systems. (If there weren't such a glyph we would not know
16090 how wide and tall a box cursor should be displayed).
16092 At the same time this space let's a nicely handle clearing to the
16093 end of the line if the row ends in italic text. */
16096 append_space_for_newline (it
, default_face_p
)
16098 int default_face_p
;
16100 if (FRAME_WINDOW_P (it
->f
))
16102 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16104 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16105 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16107 /* Save some values that must not be changed.
16108 Must save IT->c and IT->len because otherwise
16109 ITERATOR_AT_END_P wouldn't work anymore after
16110 append_space_for_newline has been called. */
16111 enum display_element_type saved_what
= it
->what
;
16112 int saved_c
= it
->c
, saved_len
= it
->len
;
16113 int saved_x
= it
->current_x
;
16114 int saved_face_id
= it
->face_id
;
16115 struct text_pos saved_pos
;
16116 Lisp_Object saved_object
;
16119 saved_object
= it
->object
;
16120 saved_pos
= it
->position
;
16122 it
->what
= IT_CHARACTER
;
16123 bzero (&it
->position
, sizeof it
->position
);
16124 it
->object
= make_number (0);
16128 if (default_face_p
)
16129 it
->face_id
= DEFAULT_FACE_ID
;
16130 else if (it
->face_before_selective_p
)
16131 it
->face_id
= it
->saved_face_id
;
16132 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16133 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16135 PRODUCE_GLYPHS (it
);
16137 it
->override_ascent
= -1;
16138 it
->constrain_row_ascent_descent_p
= 0;
16139 it
->current_x
= saved_x
;
16140 it
->object
= saved_object
;
16141 it
->position
= saved_pos
;
16142 it
->what
= saved_what
;
16143 it
->face_id
= saved_face_id
;
16144 it
->len
= saved_len
;
16154 /* Extend the face of the last glyph in the text area of IT->glyph_row
16155 to the end of the display line. Called from display_line.
16156 If the glyph row is empty, add a space glyph to it so that we
16157 know the face to draw. Set the glyph row flag fill_line_p. */
16160 extend_face_to_end_of_line (it
)
16164 struct frame
*f
= it
->f
;
16166 /* If line is already filled, do nothing. */
16167 if (it
->current_x
>= it
->last_visible_x
)
16170 /* Face extension extends the background and box of IT->face_id
16171 to the end of the line. If the background equals the background
16172 of the frame, we don't have to do anything. */
16173 if (it
->face_before_selective_p
)
16174 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16176 face
= FACE_FROM_ID (f
, it
->face_id
);
16178 if (FRAME_WINDOW_P (f
)
16179 && it
->glyph_row
->displays_text_p
16180 && face
->box
== FACE_NO_BOX
16181 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16185 /* Set the glyph row flag indicating that the face of the last glyph
16186 in the text area has to be drawn to the end of the text area. */
16187 it
->glyph_row
->fill_line_p
= 1;
16189 /* If current character of IT is not ASCII, make sure we have the
16190 ASCII face. This will be automatically undone the next time
16191 get_next_display_element returns a multibyte character. Note
16192 that the character will always be single byte in unibyte
16194 if (!ASCII_CHAR_P (it
->c
))
16196 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16199 if (FRAME_WINDOW_P (f
))
16201 /* If the row is empty, add a space with the current face of IT,
16202 so that we know which face to draw. */
16203 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16205 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16206 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16207 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16212 /* Save some values that must not be changed. */
16213 int saved_x
= it
->current_x
;
16214 struct text_pos saved_pos
;
16215 Lisp_Object saved_object
;
16216 enum display_element_type saved_what
= it
->what
;
16217 int saved_face_id
= it
->face_id
;
16219 saved_object
= it
->object
;
16220 saved_pos
= it
->position
;
16222 it
->what
= IT_CHARACTER
;
16223 bzero (&it
->position
, sizeof it
->position
);
16224 it
->object
= make_number (0);
16227 it
->face_id
= face
->id
;
16229 PRODUCE_GLYPHS (it
);
16231 while (it
->current_x
<= it
->last_visible_x
)
16232 PRODUCE_GLYPHS (it
);
16234 /* Don't count these blanks really. It would let us insert a left
16235 truncation glyph below and make us set the cursor on them, maybe. */
16236 it
->current_x
= saved_x
;
16237 it
->object
= saved_object
;
16238 it
->position
= saved_pos
;
16239 it
->what
= saved_what
;
16240 it
->face_id
= saved_face_id
;
16245 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16246 trailing whitespace. */
16249 trailing_whitespace_p (charpos
)
16252 int bytepos
= CHAR_TO_BYTE (charpos
);
16255 while (bytepos
< ZV_BYTE
16256 && (c
= FETCH_CHAR (bytepos
),
16257 c
== ' ' || c
== '\t'))
16260 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16262 if (bytepos
!= PT_BYTE
)
16269 /* Highlight trailing whitespace, if any, in ROW. */
16272 highlight_trailing_whitespace (f
, row
)
16274 struct glyph_row
*row
;
16276 int used
= row
->used
[TEXT_AREA
];
16280 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16281 struct glyph
*glyph
= start
+ used
- 1;
16283 /* Skip over glyphs inserted to display the cursor at the
16284 end of a line, for extending the face of the last glyph
16285 to the end of the line on terminals, and for truncation
16286 and continuation glyphs. */
16287 while (glyph
>= start
16288 && glyph
->type
== CHAR_GLYPH
16289 && INTEGERP (glyph
->object
))
16292 /* If last glyph is a space or stretch, and it's trailing
16293 whitespace, set the face of all trailing whitespace glyphs in
16294 IT->glyph_row to `trailing-whitespace'. */
16296 && BUFFERP (glyph
->object
)
16297 && (glyph
->type
== STRETCH_GLYPH
16298 || (glyph
->type
== CHAR_GLYPH
16299 && glyph
->u
.ch
== ' '))
16300 && trailing_whitespace_p (glyph
->charpos
))
16302 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16306 while (glyph
>= start
16307 && BUFFERP (glyph
->object
)
16308 && (glyph
->type
== STRETCH_GLYPH
16309 || (glyph
->type
== CHAR_GLYPH
16310 && glyph
->u
.ch
== ' ')))
16311 (glyph
--)->face_id
= face_id
;
16317 /* Value is non-zero if glyph row ROW in window W should be
16318 used to hold the cursor. */
16321 cursor_row_p (w
, row
)
16323 struct glyph_row
*row
;
16325 int cursor_row_p
= 1;
16327 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16329 /* Suppose the row ends on a string.
16330 Unless the row is continued, that means it ends on a newline
16331 in the string. If it's anything other than a display string
16332 (e.g. a before-string from an overlay), we don't want the
16333 cursor there. (This heuristic seems to give the optimal
16334 behavior for the various types of multi-line strings.) */
16335 if (CHARPOS (row
->end
.string_pos
) >= 0)
16337 if (row
->continued_p
)
16341 /* Check for `display' property. */
16342 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16343 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16344 struct glyph
*glyph
;
16347 for (glyph
= end
; glyph
>= beg
; --glyph
)
16348 if (STRINGP (glyph
->object
))
16351 = Fget_char_property (make_number (PT
),
16355 && display_prop_string_p (prop
, glyph
->object
));
16360 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16362 /* If the row ends in middle of a real character,
16363 and the line is continued, we want the cursor here.
16364 That's because MATRIX_ROW_END_CHARPOS would equal
16365 PT if PT is before the character. */
16366 if (!row
->ends_in_ellipsis_p
)
16367 cursor_row_p
= row
->continued_p
;
16369 /* If the row ends in an ellipsis, then
16370 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16371 We want that position to be displayed after the ellipsis. */
16374 /* If the row ends at ZV, display the cursor at the end of that
16375 row instead of at the start of the row below. */
16376 else if (row
->ends_at_zv_p
)
16382 return cursor_row_p
;
16387 /* Push the display property PROP so that it will be rendered at the
16388 current position in IT. */
16391 push_display_prop (struct it
*it
, Lisp_Object prop
)
16395 /* Never display a cursor on the prefix. */
16396 it
->avoid_cursor_p
= 1;
16398 if (STRINGP (prop
))
16400 if (SCHARS (prop
) == 0)
16407 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16408 it
->current
.overlay_string_index
= -1;
16409 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16410 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16411 it
->method
= GET_FROM_STRING
;
16412 it
->stop_charpos
= 0;
16414 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16416 it
->method
= GET_FROM_STRETCH
;
16419 #ifdef HAVE_WINDOW_SYSTEM
16420 else if (IMAGEP (prop
))
16422 it
->what
= IT_IMAGE
;
16423 it
->image_id
= lookup_image (it
->f
, prop
);
16424 it
->method
= GET_FROM_IMAGE
;
16426 #endif /* HAVE_WINDOW_SYSTEM */
16429 pop_it (it
); /* bogus display property, give up */
16434 /* Return the character-property PROP at the current position in IT. */
16437 get_it_property (it
, prop
)
16441 Lisp_Object position
;
16443 if (STRINGP (it
->object
))
16444 position
= make_number (IT_STRING_CHARPOS (*it
));
16445 else if (BUFFERP (it
->object
))
16446 position
= make_number (IT_CHARPOS (*it
));
16450 return Fget_char_property (position
, prop
, it
->object
);
16453 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16456 handle_line_prefix (struct it
*it
)
16458 Lisp_Object prefix
;
16459 if (it
->continuation_lines_width
> 0)
16461 prefix
= get_it_property (it
, Qwrap_prefix
);
16463 prefix
= Vwrap_prefix
;
16467 prefix
= get_it_property (it
, Qline_prefix
);
16469 prefix
= Vline_prefix
;
16471 if (! NILP (prefix
))
16473 push_display_prop (it
, prefix
);
16474 /* If the prefix is wider than the window, and we try to wrap
16475 it, it would acquire its own wrap prefix, and so on till the
16476 iterator stack overflows. So, don't wrap the prefix. */
16477 it
->line_wrap
= TRUNCATE
;
16483 /* Construct the glyph row IT->glyph_row in the desired matrix of
16484 IT->w from text at the current position of IT. See dispextern.h
16485 for an overview of struct it. Value is non-zero if
16486 IT->glyph_row displays text, as opposed to a line displaying ZV
16493 struct glyph_row
*row
= it
->glyph_row
;
16494 Lisp_Object overlay_arrow_string
;
16496 int may_wrap
= 0, wrap_x
;
16497 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16498 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16499 int wrap_row_extra_line_spacing
;
16501 /* We always start displaying at hpos zero even if hscrolled. */
16502 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16504 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16505 >= it
->w
->desired_matrix
->nrows
)
16507 it
->w
->nrows_scale_factor
++;
16508 fonts_changed_p
= 1;
16512 /* Is IT->w showing the region? */
16513 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16515 /* Clear the result glyph row and enable it. */
16516 prepare_desired_row (row
);
16518 row
->y
= it
->current_y
;
16519 row
->start
= it
->start
;
16520 row
->continuation_lines_width
= it
->continuation_lines_width
;
16521 row
->displays_text_p
= 1;
16522 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16523 it
->starts_in_middle_of_char_p
= 0;
16525 /* Arrange the overlays nicely for our purposes. Usually, we call
16526 display_line on only one line at a time, in which case this
16527 can't really hurt too much, or we call it on lines which appear
16528 one after another in the buffer, in which case all calls to
16529 recenter_overlay_lists but the first will be pretty cheap. */
16530 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16532 /* Move over display elements that are not visible because we are
16533 hscrolled. This may stop at an x-position < IT->first_visible_x
16534 if the first glyph is partially visible or if we hit a line end. */
16535 if (it
->current_x
< it
->first_visible_x
)
16537 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16538 MOVE_TO_POS
| MOVE_TO_X
);
16542 /* We only do this when not calling `move_it_in_display_line_to'
16543 above, because move_it_in_display_line_to calls
16544 handle_line_prefix itself. */
16545 handle_line_prefix (it
);
16548 /* Get the initial row height. This is either the height of the
16549 text hscrolled, if there is any, or zero. */
16550 row
->ascent
= it
->max_ascent
;
16551 row
->height
= it
->max_ascent
+ it
->max_descent
;
16552 row
->phys_ascent
= it
->max_phys_ascent
;
16553 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16554 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16556 /* Loop generating characters. The loop is left with IT on the next
16557 character to display. */
16560 int n_glyphs_before
, hpos_before
, x_before
;
16562 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16564 /* Retrieve the next thing to display. Value is zero if end of
16566 if (!get_next_display_element (it
))
16568 /* Maybe add a space at the end of this line that is used to
16569 display the cursor there under X. Set the charpos of the
16570 first glyph of blank lines not corresponding to any text
16572 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16573 row
->exact_window_width_line_p
= 1;
16574 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16575 || row
->used
[TEXT_AREA
] == 0)
16577 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16578 row
->displays_text_p
= 0;
16580 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16581 && (!MINI_WINDOW_P (it
->w
)
16582 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16583 row
->indicate_empty_line_p
= 1;
16586 it
->continuation_lines_width
= 0;
16587 row
->ends_at_zv_p
= 1;
16591 /* Now, get the metrics of what we want to display. This also
16592 generates glyphs in `row' (which is IT->glyph_row). */
16593 n_glyphs_before
= row
->used
[TEXT_AREA
];
16596 /* Remember the line height so far in case the next element doesn't
16597 fit on the line. */
16598 if (it
->line_wrap
!= TRUNCATE
)
16600 ascent
= it
->max_ascent
;
16601 descent
= it
->max_descent
;
16602 phys_ascent
= it
->max_phys_ascent
;
16603 phys_descent
= it
->max_phys_descent
;
16605 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16607 if (IT_DISPLAYING_WHITESPACE (it
))
16613 wrap_row_used
= row
->used
[TEXT_AREA
];
16614 wrap_row_ascent
= row
->ascent
;
16615 wrap_row_height
= row
->height
;
16616 wrap_row_phys_ascent
= row
->phys_ascent
;
16617 wrap_row_phys_height
= row
->phys_height
;
16618 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16624 PRODUCE_GLYPHS (it
);
16626 /* If this display element was in marginal areas, continue with
16628 if (it
->area
!= TEXT_AREA
)
16630 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16631 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16632 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16633 row
->phys_height
= max (row
->phys_height
,
16634 it
->max_phys_ascent
+ it
->max_phys_descent
);
16635 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16636 it
->max_extra_line_spacing
);
16637 set_iterator_to_next (it
, 1);
16641 /* Does the display element fit on the line? If we truncate
16642 lines, we should draw past the right edge of the window. If
16643 we don't truncate, we want to stop so that we can display the
16644 continuation glyph before the right margin. If lines are
16645 continued, there are two possible strategies for characters
16646 resulting in more than 1 glyph (e.g. tabs): Display as many
16647 glyphs as possible in this line and leave the rest for the
16648 continuation line, or display the whole element in the next
16649 line. Original redisplay did the former, so we do it also. */
16650 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16651 hpos_before
= it
->hpos
;
16654 if (/* Not a newline. */
16656 /* Glyphs produced fit entirely in the line. */
16657 && it
->current_x
< it
->last_visible_x
)
16659 it
->hpos
+= nglyphs
;
16660 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16661 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16662 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16663 row
->phys_height
= max (row
->phys_height
,
16664 it
->max_phys_ascent
+ it
->max_phys_descent
);
16665 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16666 it
->max_extra_line_spacing
);
16667 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16668 row
->x
= x
- it
->first_visible_x
;
16673 struct glyph
*glyph
;
16675 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16677 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16678 new_x
= x
+ glyph
->pixel_width
;
16680 if (/* Lines are continued. */
16681 it
->line_wrap
!= TRUNCATE
16682 && (/* Glyph doesn't fit on the line. */
16683 new_x
> it
->last_visible_x
16684 /* Or it fits exactly on a window system frame. */
16685 || (new_x
== it
->last_visible_x
16686 && FRAME_WINDOW_P (it
->f
))))
16688 /* End of a continued line. */
16691 || (new_x
== it
->last_visible_x
16692 && FRAME_WINDOW_P (it
->f
)))
16694 /* Current glyph is the only one on the line or
16695 fits exactly on the line. We must continue
16696 the line because we can't draw the cursor
16697 after the glyph. */
16698 row
->continued_p
= 1;
16699 it
->current_x
= new_x
;
16700 it
->continuation_lines_width
+= new_x
;
16702 if (i
== nglyphs
- 1)
16704 /* If line-wrap is on, check if a previous
16705 wrap point was found. */
16706 if (wrap_row_used
> 0
16707 /* Even if there is a previous wrap
16708 point, continue the line here as
16709 usual, if (i) the previous character
16710 was a space or tab AND (ii) the
16711 current character is not. */
16713 || IT_DISPLAYING_WHITESPACE (it
)))
16716 set_iterator_to_next (it
, 1);
16717 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16719 if (!get_next_display_element (it
))
16721 row
->exact_window_width_line_p
= 1;
16722 it
->continuation_lines_width
= 0;
16723 row
->continued_p
= 0;
16724 row
->ends_at_zv_p
= 1;
16726 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16728 row
->continued_p
= 0;
16729 row
->exact_window_width_line_p
= 1;
16734 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16735 && !FRAME_WINDOW_P (it
->f
))
16737 /* A padding glyph that doesn't fit on this line.
16738 This means the whole character doesn't fit
16740 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16742 /* Fill the rest of the row with continuation
16743 glyphs like in 20.x. */
16744 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16745 < row
->glyphs
[1 + TEXT_AREA
])
16746 produce_special_glyphs (it
, IT_CONTINUATION
);
16748 row
->continued_p
= 1;
16749 it
->current_x
= x_before
;
16750 it
->continuation_lines_width
+= x_before
;
16752 /* Restore the height to what it was before the
16753 element not fitting on the line. */
16754 it
->max_ascent
= ascent
;
16755 it
->max_descent
= descent
;
16756 it
->max_phys_ascent
= phys_ascent
;
16757 it
->max_phys_descent
= phys_descent
;
16759 else if (wrap_row_used
> 0)
16763 it
->continuation_lines_width
+= wrap_x
;
16764 row
->used
[TEXT_AREA
] = wrap_row_used
;
16765 row
->ascent
= wrap_row_ascent
;
16766 row
->height
= wrap_row_height
;
16767 row
->phys_ascent
= wrap_row_phys_ascent
;
16768 row
->phys_height
= wrap_row_phys_height
;
16769 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16770 row
->continued_p
= 1;
16771 row
->ends_at_zv_p
= 0;
16772 row
->exact_window_width_line_p
= 0;
16773 it
->continuation_lines_width
+= x
;
16775 /* Make sure that a non-default face is extended
16776 up to the right margin of the window. */
16777 extend_face_to_end_of_line (it
);
16779 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16781 /* A TAB that extends past the right edge of the
16782 window. This produces a single glyph on
16783 window system frames. We leave the glyph in
16784 this row and let it fill the row, but don't
16785 consume the TAB. */
16786 it
->continuation_lines_width
+= it
->last_visible_x
;
16787 row
->ends_in_middle_of_char_p
= 1;
16788 row
->continued_p
= 1;
16789 glyph
->pixel_width
= it
->last_visible_x
- x
;
16790 it
->starts_in_middle_of_char_p
= 1;
16794 /* Something other than a TAB that draws past
16795 the right edge of the window. Restore
16796 positions to values before the element. */
16797 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16799 /* Display continuation glyphs. */
16800 if (!FRAME_WINDOW_P (it
->f
))
16801 produce_special_glyphs (it
, IT_CONTINUATION
);
16802 row
->continued_p
= 1;
16804 it
->current_x
= x_before
;
16805 it
->continuation_lines_width
+= x
;
16806 extend_face_to_end_of_line (it
);
16808 if (nglyphs
> 1 && i
> 0)
16810 row
->ends_in_middle_of_char_p
= 1;
16811 it
->starts_in_middle_of_char_p
= 1;
16814 /* Restore the height to what it was before the
16815 element not fitting on the line. */
16816 it
->max_ascent
= ascent
;
16817 it
->max_descent
= descent
;
16818 it
->max_phys_ascent
= phys_ascent
;
16819 it
->max_phys_descent
= phys_descent
;
16824 else if (new_x
> it
->first_visible_x
)
16826 /* Increment number of glyphs actually displayed. */
16829 if (x
< it
->first_visible_x
)
16830 /* Glyph is partially visible, i.e. row starts at
16831 negative X position. */
16832 row
->x
= x
- it
->first_visible_x
;
16836 /* Glyph is completely off the left margin of the
16837 window. This should not happen because of the
16838 move_it_in_display_line at the start of this
16839 function, unless the text display area of the
16840 window is empty. */
16841 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16845 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16846 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16847 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16848 row
->phys_height
= max (row
->phys_height
,
16849 it
->max_phys_ascent
+ it
->max_phys_descent
);
16850 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16851 it
->max_extra_line_spacing
);
16853 /* End of this display line if row is continued. */
16854 if (row
->continued_p
|| row
->ends_at_zv_p
)
16859 /* Is this a line end? If yes, we're also done, after making
16860 sure that a non-default face is extended up to the right
16861 margin of the window. */
16862 if (ITERATOR_AT_END_OF_LINE_P (it
))
16864 int used_before
= row
->used
[TEXT_AREA
];
16866 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16868 /* Add a space at the end of the line that is used to
16869 display the cursor there. */
16870 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16871 append_space_for_newline (it
, 0);
16873 /* Extend the face to the end of the line. */
16874 extend_face_to_end_of_line (it
);
16876 /* Make sure we have the position. */
16877 if (used_before
== 0)
16878 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16880 /* Consume the line end. This skips over invisible lines. */
16881 set_iterator_to_next (it
, 1);
16882 it
->continuation_lines_width
= 0;
16886 /* Proceed with next display element. Note that this skips
16887 over lines invisible because of selective display. */
16888 set_iterator_to_next (it
, 1);
16890 /* If we truncate lines, we are done when the last displayed
16891 glyphs reach past the right margin of the window. */
16892 if (it
->line_wrap
== TRUNCATE
16893 && (FRAME_WINDOW_P (it
->f
)
16894 ? (it
->current_x
>= it
->last_visible_x
)
16895 : (it
->current_x
> it
->last_visible_x
)))
16897 /* Maybe add truncation glyphs. */
16898 if (!FRAME_WINDOW_P (it
->f
))
16902 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16903 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16906 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16908 row
->used
[TEXT_AREA
] = i
;
16909 produce_special_glyphs (it
, IT_TRUNCATION
);
16912 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16914 /* Don't truncate if we can overflow newline into fringe. */
16915 if (!get_next_display_element (it
))
16917 it
->continuation_lines_width
= 0;
16918 row
->ends_at_zv_p
= 1;
16919 row
->exact_window_width_line_p
= 1;
16922 if (ITERATOR_AT_END_OF_LINE_P (it
))
16924 row
->exact_window_width_line_p
= 1;
16925 goto at_end_of_line
;
16929 row
->truncated_on_right_p
= 1;
16930 it
->continuation_lines_width
= 0;
16931 reseat_at_next_visible_line_start (it
, 0);
16932 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16933 it
->hpos
= hpos_before
;
16934 it
->current_x
= x_before
;
16939 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16940 at the left window margin. */
16941 if (it
->first_visible_x
16942 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16944 if (!FRAME_WINDOW_P (it
->f
))
16945 insert_left_trunc_glyphs (it
);
16946 row
->truncated_on_left_p
= 1;
16949 /* If the start of this line is the overlay arrow-position, then
16950 mark this glyph row as the one containing the overlay arrow.
16951 This is clearly a mess with variable size fonts. It would be
16952 better to let it be displayed like cursors under X. */
16953 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16954 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16955 !NILP (overlay_arrow_string
)))
16957 /* Overlay arrow in window redisplay is a fringe bitmap. */
16958 if (STRINGP (overlay_arrow_string
))
16960 struct glyph_row
*arrow_row
16961 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
16962 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
16963 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
16964 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
16965 struct glyph
*p2
, *end
;
16967 /* Copy the arrow glyphs. */
16968 while (glyph
< arrow_end
)
16971 /* Throw away padding glyphs. */
16973 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16974 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
16980 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
16985 xassert (INTEGERP (overlay_arrow_string
));
16986 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
16988 overlay_arrow_seen
= 1;
16991 /* Compute pixel dimensions of this line. */
16992 compute_line_metrics (it
);
16994 /* Remember the position at which this line ends. */
16995 row
->end
= it
->current
;
16997 /* Record whether this row ends inside an ellipsis. */
16998 row
->ends_in_ellipsis_p
16999 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17000 && it
->ellipsis_p
);
17002 /* Save fringe bitmaps in this row. */
17003 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17004 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17005 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17006 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17008 it
->left_user_fringe_bitmap
= 0;
17009 it
->left_user_fringe_face_id
= 0;
17010 it
->right_user_fringe_bitmap
= 0;
17011 it
->right_user_fringe_face_id
= 0;
17013 /* Maybe set the cursor. */
17014 if (it
->w
->cursor
.vpos
< 0
17015 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17016 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17017 && cursor_row_p (it
->w
, row
))
17018 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17020 /* Highlight trailing whitespace. */
17021 if (!NILP (Vshow_trailing_whitespace
))
17022 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17024 /* Prepare for the next line. This line starts horizontally at (X
17025 HPOS) = (0 0). Vertical positions are incremented. As a
17026 convenience for the caller, IT->glyph_row is set to the next
17028 it
->current_x
= it
->hpos
= 0;
17029 it
->current_y
+= row
->height
;
17032 it
->start
= it
->current
;
17033 return row
->displays_text_p
;
17038 /***********************************************************************
17040 ***********************************************************************/
17042 /* Redisplay the menu bar in the frame for window W.
17044 The menu bar of X frames that don't have X toolkit support is
17045 displayed in a special window W->frame->menu_bar_window.
17047 The menu bar of terminal frames is treated specially as far as
17048 glyph matrices are concerned. Menu bar lines are not part of
17049 windows, so the update is done directly on the frame matrix rows
17050 for the menu bar. */
17053 display_menu_bar (w
)
17056 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17061 /* Don't do all this for graphical frames. */
17063 if (FRAME_W32_P (f
))
17066 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17072 if (FRAME_NS_P (f
))
17074 #endif /* HAVE_NS */
17076 #ifdef USE_X_TOOLKIT
17077 xassert (!FRAME_WINDOW_P (f
));
17078 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17079 it
.first_visible_x
= 0;
17080 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17081 #else /* not USE_X_TOOLKIT */
17082 if (FRAME_WINDOW_P (f
))
17084 /* Menu bar lines are displayed in the desired matrix of the
17085 dummy window menu_bar_window. */
17086 struct window
*menu_w
;
17087 xassert (WINDOWP (f
->menu_bar_window
));
17088 menu_w
= XWINDOW (f
->menu_bar_window
);
17089 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17091 it
.first_visible_x
= 0;
17092 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17096 /* This is a TTY frame, i.e. character hpos/vpos are used as
17098 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17100 it
.first_visible_x
= 0;
17101 it
.last_visible_x
= FRAME_COLS (f
);
17103 #endif /* not USE_X_TOOLKIT */
17105 if (! mode_line_inverse_video
)
17106 /* Force the menu-bar to be displayed in the default face. */
17107 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17109 /* Clear all rows of the menu bar. */
17110 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17112 struct glyph_row
*row
= it
.glyph_row
+ i
;
17113 clear_glyph_row (row
);
17114 row
->enabled_p
= 1;
17115 row
->full_width_p
= 1;
17118 /* Display all items of the menu bar. */
17119 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17120 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17122 Lisp_Object string
;
17124 /* Stop at nil string. */
17125 string
= AREF (items
, i
+ 1);
17129 /* Remember where item was displayed. */
17130 ASET (items
, i
+ 3, make_number (it
.hpos
));
17132 /* Display the item, pad with one space. */
17133 if (it
.current_x
< it
.last_visible_x
)
17134 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17135 SCHARS (string
) + 1, 0, 0, -1);
17138 /* Fill out the line with spaces. */
17139 if (it
.current_x
< it
.last_visible_x
)
17140 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17142 /* Compute the total height of the lines. */
17143 compute_line_metrics (&it
);
17148 /***********************************************************************
17150 ***********************************************************************/
17152 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17153 FORCE is non-zero, redisplay mode lines unconditionally.
17154 Otherwise, redisplay only mode lines that are garbaged. Value is
17155 the number of windows whose mode lines were redisplayed. */
17158 redisplay_mode_lines (window
, force
)
17159 Lisp_Object window
;
17164 while (!NILP (window
))
17166 struct window
*w
= XWINDOW (window
);
17168 if (WINDOWP (w
->hchild
))
17169 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17170 else if (WINDOWP (w
->vchild
))
17171 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17173 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17174 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17176 struct text_pos lpoint
;
17177 struct buffer
*old
= current_buffer
;
17179 /* Set the window's buffer for the mode line display. */
17180 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17181 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17183 /* Point refers normally to the selected window. For any
17184 other window, set up appropriate value. */
17185 if (!EQ (window
, selected_window
))
17187 struct text_pos pt
;
17189 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17190 if (CHARPOS (pt
) < BEGV
)
17191 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17192 else if (CHARPOS (pt
) > (ZV
- 1))
17193 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17195 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17198 /* Display mode lines. */
17199 clear_glyph_matrix (w
->desired_matrix
);
17200 if (display_mode_lines (w
))
17203 w
->must_be_updated_p
= 1;
17206 /* Restore old settings. */
17207 set_buffer_internal_1 (old
);
17208 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17218 /* Display the mode and/or header line of window W. Value is the
17219 sum number of mode lines and header lines displayed. */
17222 display_mode_lines (w
)
17225 Lisp_Object old_selected_window
, old_selected_frame
;
17228 old_selected_frame
= selected_frame
;
17229 selected_frame
= w
->frame
;
17230 old_selected_window
= selected_window
;
17231 XSETWINDOW (selected_window
, w
);
17233 /* These will be set while the mode line specs are processed. */
17234 line_number_displayed
= 0;
17235 w
->column_number_displayed
= Qnil
;
17237 if (WINDOW_WANTS_MODELINE_P (w
))
17239 struct window
*sel_w
= XWINDOW (old_selected_window
);
17241 /* Select mode line face based on the real selected window. */
17242 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17243 current_buffer
->mode_line_format
);
17247 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17249 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17250 current_buffer
->header_line_format
);
17254 selected_frame
= old_selected_frame
;
17255 selected_window
= old_selected_window
;
17260 /* Display mode or header line of window W. FACE_ID specifies which
17261 line to display; it is either MODE_LINE_FACE_ID or
17262 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
17263 display. Value is the pixel height of the mode/header line
17267 display_mode_line (w
, face_id
, format
)
17269 enum face_id face_id
;
17270 Lisp_Object format
;
17274 int count
= SPECPDL_INDEX ();
17276 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17277 /* Don't extend on a previously drawn mode-line.
17278 This may happen if called from pos_visible_p. */
17279 it
.glyph_row
->enabled_p
= 0;
17280 prepare_desired_row (it
.glyph_row
);
17282 it
.glyph_row
->mode_line_p
= 1;
17284 if (! mode_line_inverse_video
)
17285 /* Force the mode-line to be displayed in the default face. */
17286 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17288 record_unwind_protect (unwind_format_mode_line
,
17289 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17291 mode_line_target
= MODE_LINE_DISPLAY
;
17293 /* Temporarily make frame's keyboard the current kboard so that
17294 kboard-local variables in the mode_line_format will get the right
17296 push_kboard (FRAME_KBOARD (it
.f
));
17297 record_unwind_save_match_data ();
17298 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17301 unbind_to (count
, Qnil
);
17303 /* Fill up with spaces. */
17304 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17306 compute_line_metrics (&it
);
17307 it
.glyph_row
->full_width_p
= 1;
17308 it
.glyph_row
->continued_p
= 0;
17309 it
.glyph_row
->truncated_on_left_p
= 0;
17310 it
.glyph_row
->truncated_on_right_p
= 0;
17312 /* Make a 3D mode-line have a shadow at its right end. */
17313 face
= FACE_FROM_ID (it
.f
, face_id
);
17314 extend_face_to_end_of_line (&it
);
17315 if (face
->box
!= FACE_NO_BOX
)
17317 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17318 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17319 last
->right_box_line_p
= 1;
17322 return it
.glyph_row
->height
;
17325 /* Move element ELT in LIST to the front of LIST.
17326 Return the updated list. */
17329 move_elt_to_front (elt
, list
)
17330 Lisp_Object elt
, list
;
17332 register Lisp_Object tail
, prev
;
17333 register Lisp_Object tem
;
17337 while (CONSP (tail
))
17343 /* Splice out the link TAIL. */
17345 list
= XCDR (tail
);
17347 Fsetcdr (prev
, XCDR (tail
));
17349 /* Now make it the first. */
17350 Fsetcdr (tail
, list
);
17355 tail
= XCDR (tail
);
17359 /* Not found--return unchanged LIST. */
17363 /* Contribute ELT to the mode line for window IT->w. How it
17364 translates into text depends on its data type.
17366 IT describes the display environment in which we display, as usual.
17368 DEPTH is the depth in recursion. It is used to prevent
17369 infinite recursion here.
17371 FIELD_WIDTH is the number of characters the display of ELT should
17372 occupy in the mode line, and PRECISION is the maximum number of
17373 characters to display from ELT's representation. See
17374 display_string for details.
17376 Returns the hpos of the end of the text generated by ELT.
17378 PROPS is a property list to add to any string we encounter.
17380 If RISKY is nonzero, remove (disregard) any properties in any string
17381 we encounter, and ignore :eval and :propertize.
17383 The global variable `mode_line_target' determines whether the
17384 output is passed to `store_mode_line_noprop',
17385 `store_mode_line_string', or `display_string'. */
17388 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17391 int field_width
, precision
;
17392 Lisp_Object elt
, props
;
17395 int n
= 0, field
, prec
;
17400 elt
= build_string ("*too-deep*");
17404 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17408 /* A string: output it and check for %-constructs within it. */
17412 if (SCHARS (elt
) > 0
17413 && (!NILP (props
) || risky
))
17415 Lisp_Object oprops
, aelt
;
17416 oprops
= Ftext_properties_at (make_number (0), elt
);
17418 /* If the starting string's properties are not what
17419 we want, translate the string. Also, if the string
17420 is risky, do that anyway. */
17422 if (NILP (Fequal (props
, oprops
)) || risky
)
17424 /* If the starting string has properties,
17425 merge the specified ones onto the existing ones. */
17426 if (! NILP (oprops
) && !risky
)
17430 oprops
= Fcopy_sequence (oprops
);
17432 while (CONSP (tem
))
17434 oprops
= Fplist_put (oprops
, XCAR (tem
),
17435 XCAR (XCDR (tem
)));
17436 tem
= XCDR (XCDR (tem
));
17441 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17442 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17444 /* AELT is what we want. Move it to the front
17445 without consing. */
17447 mode_line_proptrans_alist
17448 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17454 /* If AELT has the wrong props, it is useless.
17455 so get rid of it. */
17457 mode_line_proptrans_alist
17458 = Fdelq (aelt
, mode_line_proptrans_alist
);
17460 elt
= Fcopy_sequence (elt
);
17461 Fset_text_properties (make_number (0), Flength (elt
),
17463 /* Add this item to mode_line_proptrans_alist. */
17464 mode_line_proptrans_alist
17465 = Fcons (Fcons (elt
, props
),
17466 mode_line_proptrans_alist
);
17467 /* Truncate mode_line_proptrans_alist
17468 to at most 50 elements. */
17469 tem
= Fnthcdr (make_number (50),
17470 mode_line_proptrans_alist
);
17472 XSETCDR (tem
, Qnil
);
17481 prec
= precision
- n
;
17482 switch (mode_line_target
)
17484 case MODE_LINE_NOPROP
:
17485 case MODE_LINE_TITLE
:
17486 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17488 case MODE_LINE_STRING
:
17489 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17491 case MODE_LINE_DISPLAY
:
17492 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17493 0, prec
, 0, STRING_MULTIBYTE (elt
));
17500 /* Handle the non-literal case. */
17502 while ((precision
<= 0 || n
< precision
)
17503 && SREF (elt
, offset
) != 0
17504 && (mode_line_target
!= MODE_LINE_DISPLAY
17505 || it
->current_x
< it
->last_visible_x
))
17507 int last_offset
= offset
;
17509 /* Advance to end of string or next format specifier. */
17510 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17513 if (offset
- 1 != last_offset
)
17515 int nchars
, nbytes
;
17517 /* Output to end of string or up to '%'. Field width
17518 is length of string. Don't output more than
17519 PRECISION allows us. */
17522 prec
= c_string_width (SDATA (elt
) + last_offset
,
17523 offset
- last_offset
, precision
- n
,
17526 switch (mode_line_target
)
17528 case MODE_LINE_NOPROP
:
17529 case MODE_LINE_TITLE
:
17530 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17532 case MODE_LINE_STRING
:
17534 int bytepos
= last_offset
;
17535 int charpos
= string_byte_to_char (elt
, bytepos
);
17536 int endpos
= (precision
<= 0
17537 ? string_byte_to_char (elt
, offset
)
17538 : charpos
+ nchars
);
17540 n
+= store_mode_line_string (NULL
,
17541 Fsubstring (elt
, make_number (charpos
),
17542 make_number (endpos
)),
17546 case MODE_LINE_DISPLAY
:
17548 int bytepos
= last_offset
;
17549 int charpos
= string_byte_to_char (elt
, bytepos
);
17551 if (precision
<= 0)
17552 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17553 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17555 STRING_MULTIBYTE (elt
));
17560 else /* c == '%' */
17562 int percent_position
= offset
;
17564 /* Get the specified minimum width. Zero means
17567 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17568 field
= field
* 10 + c
- '0';
17570 /* Don't pad beyond the total padding allowed. */
17571 if (field_width
- n
> 0 && field
> field_width
- n
)
17572 field
= field_width
- n
;
17574 /* Note that either PRECISION <= 0 or N < PRECISION. */
17575 prec
= precision
- n
;
17578 n
+= display_mode_element (it
, depth
, field
, prec
,
17579 Vglobal_mode_string
, props
,
17584 int bytepos
, charpos
;
17585 unsigned char *spec
;
17587 bytepos
= percent_position
;
17588 charpos
= (STRING_MULTIBYTE (elt
)
17589 ? string_byte_to_char (elt
, bytepos
)
17592 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17594 switch (mode_line_target
)
17596 case MODE_LINE_NOPROP
:
17597 case MODE_LINE_TITLE
:
17598 n
+= store_mode_line_noprop (spec
, field
, prec
);
17600 case MODE_LINE_STRING
:
17602 int len
= strlen (spec
);
17603 Lisp_Object tem
= make_string (spec
, len
);
17604 props
= Ftext_properties_at (make_number (charpos
), elt
);
17605 /* Should only keep face property in props */
17606 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17609 case MODE_LINE_DISPLAY
:
17611 int nglyphs_before
, nwritten
;
17613 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17614 nwritten
= display_string (spec
, Qnil
, elt
,
17619 /* Assign to the glyphs written above the
17620 string where the `%x' came from, position
17624 struct glyph
*glyph
17625 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17629 for (i
= 0; i
< nwritten
; ++i
)
17631 glyph
[i
].object
= elt
;
17632 glyph
[i
].charpos
= charpos
;
17649 /* A symbol: process the value of the symbol recursively
17650 as if it appeared here directly. Avoid error if symbol void.
17651 Special case: if value of symbol is a string, output the string
17654 register Lisp_Object tem
;
17656 /* If the variable is not marked as risky to set
17657 then its contents are risky to use. */
17658 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17661 tem
= Fboundp (elt
);
17664 tem
= Fsymbol_value (elt
);
17665 /* If value is a string, output that string literally:
17666 don't check for % within it. */
17670 if (!EQ (tem
, elt
))
17672 /* Give up right away for nil or t. */
17682 register Lisp_Object car
, tem
;
17684 /* A cons cell: five distinct cases.
17685 If first element is :eval or :propertize, do something special.
17686 If first element is a string or a cons, process all the elements
17687 and effectively concatenate them.
17688 If first element is a negative number, truncate displaying cdr to
17689 at most that many characters. If positive, pad (with spaces)
17690 to at least that many characters.
17691 If first element is a symbol, process the cadr or caddr recursively
17692 according to whether the symbol's value is non-nil or nil. */
17694 if (EQ (car
, QCeval
))
17696 /* An element of the form (:eval FORM) means evaluate FORM
17697 and use the result as mode line elements. */
17702 if (CONSP (XCDR (elt
)))
17705 spec
= safe_eval (XCAR (XCDR (elt
)));
17706 n
+= display_mode_element (it
, depth
, field_width
- n
,
17707 precision
- n
, spec
, props
,
17711 else if (EQ (car
, QCpropertize
))
17713 /* An element of the form (:propertize ELT PROPS...)
17714 means display ELT but applying properties PROPS. */
17719 if (CONSP (XCDR (elt
)))
17720 n
+= display_mode_element (it
, depth
, field_width
- n
,
17721 precision
- n
, XCAR (XCDR (elt
)),
17722 XCDR (XCDR (elt
)), risky
);
17724 else if (SYMBOLP (car
))
17726 tem
= Fboundp (car
);
17730 /* elt is now the cdr, and we know it is a cons cell.
17731 Use its car if CAR has a non-nil value. */
17734 tem
= Fsymbol_value (car
);
17741 /* Symbol's value is nil (or symbol is unbound)
17742 Get the cddr of the original list
17743 and if possible find the caddr and use that. */
17747 else if (!CONSP (elt
))
17752 else if (INTEGERP (car
))
17754 register int lim
= XINT (car
);
17758 /* Negative int means reduce maximum width. */
17759 if (precision
<= 0)
17762 precision
= min (precision
, -lim
);
17766 /* Padding specified. Don't let it be more than
17767 current maximum. */
17769 lim
= min (precision
, lim
);
17771 /* If that's more padding than already wanted, queue it.
17772 But don't reduce padding already specified even if
17773 that is beyond the current truncation point. */
17774 field_width
= max (lim
, field_width
);
17778 else if (STRINGP (car
) || CONSP (car
))
17780 Lisp_Object halftail
= elt
;
17784 && (precision
<= 0 || n
< precision
))
17786 n
+= display_mode_element (it
, depth
,
17787 /* Do padding only after the last
17788 element in the list. */
17789 (! CONSP (XCDR (elt
))
17792 precision
- n
, XCAR (elt
),
17796 if ((len
& 1) == 0)
17797 halftail
= XCDR (halftail
);
17798 /* Check for cycle. */
17799 if (EQ (halftail
, elt
))
17808 elt
= build_string ("*invalid*");
17812 /* Pad to FIELD_WIDTH. */
17813 if (field_width
> 0 && n
< field_width
)
17815 switch (mode_line_target
)
17817 case MODE_LINE_NOPROP
:
17818 case MODE_LINE_TITLE
:
17819 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17821 case MODE_LINE_STRING
:
17822 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17824 case MODE_LINE_DISPLAY
:
17825 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17834 /* Store a mode-line string element in mode_line_string_list.
17836 If STRING is non-null, display that C string. Otherwise, the Lisp
17837 string LISP_STRING is displayed.
17839 FIELD_WIDTH is the minimum number of output glyphs to produce.
17840 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17841 with spaces. FIELD_WIDTH <= 0 means don't pad.
17843 PRECISION is the maximum number of characters to output from
17844 STRING. PRECISION <= 0 means don't truncate the string.
17846 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17847 properties to the string.
17849 PROPS are the properties to add to the string.
17850 The mode_line_string_face face property is always added to the string.
17854 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17856 Lisp_Object lisp_string
;
17865 if (string
!= NULL
)
17867 len
= strlen (string
);
17868 if (precision
> 0 && len
> precision
)
17870 lisp_string
= make_string (string
, len
);
17872 props
= mode_line_string_face_prop
;
17873 else if (!NILP (mode_line_string_face
))
17875 Lisp_Object face
= Fplist_get (props
, Qface
);
17876 props
= Fcopy_sequence (props
);
17878 face
= mode_line_string_face
;
17880 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17881 props
= Fplist_put (props
, Qface
, face
);
17883 Fadd_text_properties (make_number (0), make_number (len
),
17884 props
, lisp_string
);
17888 len
= XFASTINT (Flength (lisp_string
));
17889 if (precision
> 0 && len
> precision
)
17892 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17895 if (!NILP (mode_line_string_face
))
17899 props
= Ftext_properties_at (make_number (0), lisp_string
);
17900 face
= Fplist_get (props
, Qface
);
17902 face
= mode_line_string_face
;
17904 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17905 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17907 lisp_string
= Fcopy_sequence (lisp_string
);
17910 Fadd_text_properties (make_number (0), make_number (len
),
17911 props
, lisp_string
);
17916 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17920 if (field_width
> len
)
17922 field_width
-= len
;
17923 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17925 Fadd_text_properties (make_number (0), make_number (field_width
),
17926 props
, lisp_string
);
17927 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17935 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17937 doc
: /* Format a string out of a mode line format specification.
17938 First arg FORMAT specifies the mode line format (see `mode-line-format'
17939 for details) to use.
17941 Optional second arg FACE specifies the face property to put
17942 on all characters for which no face is specified.
17943 The value t means whatever face the window's mode line currently uses
17944 \(either `mode-line' or `mode-line-inactive', depending).
17945 A value of nil means the default is no face property.
17946 If FACE is an integer, the value string has no text properties.
17948 Optional third and fourth args WINDOW and BUFFER specify the window
17949 and buffer to use as the context for the formatting (defaults
17950 are the selected window and the window's buffer). */)
17951 (format
, face
, window
, buffer
)
17952 Lisp_Object format
, face
, window
, buffer
;
17957 struct buffer
*old_buffer
= NULL
;
17959 int no_props
= INTEGERP (face
);
17960 int count
= SPECPDL_INDEX ();
17962 int string_start
= 0;
17965 window
= selected_window
;
17966 CHECK_WINDOW (window
);
17967 w
= XWINDOW (window
);
17970 buffer
= w
->buffer
;
17971 CHECK_BUFFER (buffer
);
17973 /* Make formatting the modeline a non-op when noninteractive, otherwise
17974 there will be problems later caused by a partially initialized frame. */
17975 if (NILP (format
) || noninteractive
)
17976 return empty_unibyte_string
;
17984 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
17985 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
17989 face_id
= DEFAULT_FACE_ID
;
17991 if (XBUFFER (buffer
) != current_buffer
)
17992 old_buffer
= current_buffer
;
17994 /* Save things including mode_line_proptrans_alist,
17995 and set that to nil so that we don't alter the outer value. */
17996 record_unwind_protect (unwind_format_mode_line
,
17997 format_mode_line_unwind_data
17998 (old_buffer
, selected_window
, 1));
17999 mode_line_proptrans_alist
= Qnil
;
18001 Fselect_window (window
, Qt
);
18003 set_buffer_internal_1 (XBUFFER (buffer
));
18005 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18009 mode_line_target
= MODE_LINE_NOPROP
;
18010 mode_line_string_face_prop
= Qnil
;
18011 mode_line_string_list
= Qnil
;
18012 string_start
= MODE_LINE_NOPROP_LEN (0);
18016 mode_line_target
= MODE_LINE_STRING
;
18017 mode_line_string_list
= Qnil
;
18018 mode_line_string_face
= face
;
18019 mode_line_string_face_prop
18020 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18023 push_kboard (FRAME_KBOARD (it
.f
));
18024 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18029 len
= MODE_LINE_NOPROP_LEN (string_start
);
18030 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18034 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18035 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18036 empty_unibyte_string
);
18039 unbind_to (count
, Qnil
);
18043 /* Write a null-terminated, right justified decimal representation of
18044 the positive integer D to BUF using a minimal field width WIDTH. */
18047 pint2str (buf
, width
, d
)
18048 register char *buf
;
18049 register int width
;
18052 register char *p
= buf
;
18060 *p
++ = d
% 10 + '0';
18065 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18076 /* Write a null-terminated, right justified decimal and "human
18077 readable" representation of the nonnegative integer D to BUF using
18078 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18080 static const const char power_letter
[] =
18094 pint2hrstr (buf
, width
, d
)
18099 /* We aim to represent the nonnegative integer D as
18100 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18103 /* -1 means: do not use TENTHS. */
18107 /* Length of QUOTIENT.TENTHS as a string. */
18113 if (1000 <= quotient
)
18115 /* Scale to the appropriate EXPONENT. */
18118 remainder
= quotient
% 1000;
18122 while (1000 <= quotient
);
18124 /* Round to nearest and decide whether to use TENTHS or not. */
18127 tenths
= remainder
/ 100;
18128 if (50 <= remainder
% 100)
18135 if (quotient
== 10)
18143 if (500 <= remainder
)
18145 if (quotient
< 999)
18156 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18157 if (tenths
== -1 && quotient
<= 99)
18164 p
= psuffix
= buf
+ max (width
, length
);
18166 /* Print EXPONENT. */
18168 *psuffix
++ = power_letter
[exponent
];
18171 /* Print TENTHS. */
18174 *--p
= '0' + tenths
;
18178 /* Print QUOTIENT. */
18181 int digit
= quotient
% 10;
18182 *--p
= '0' + digit
;
18184 while ((quotient
/= 10) != 0);
18186 /* Print leading spaces. */
18191 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18192 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18193 type of CODING_SYSTEM. Return updated pointer into BUF. */
18195 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18198 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18199 Lisp_Object coding_system
;
18200 register char *buf
;
18204 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18205 const unsigned char *eol_str
;
18207 /* The EOL conversion we are using. */
18208 Lisp_Object eoltype
;
18210 val
= CODING_SYSTEM_SPEC (coding_system
);
18213 if (!VECTORP (val
)) /* Not yet decided. */
18218 eoltype
= eol_mnemonic_undecided
;
18219 /* Don't mention EOL conversion if it isn't decided. */
18224 Lisp_Object eolvalue
;
18226 attrs
= AREF (val
, 0);
18227 eolvalue
= AREF (val
, 2);
18230 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18234 /* The EOL conversion that is normal on this system. */
18236 if (NILP (eolvalue
)) /* Not yet decided. */
18237 eoltype
= eol_mnemonic_undecided
;
18238 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18239 eoltype
= eol_mnemonic_undecided
;
18240 else /* eolvalue is Qunix, Qdos, or Qmac. */
18241 eoltype
= (EQ (eolvalue
, Qunix
)
18242 ? eol_mnemonic_unix
18243 : (EQ (eolvalue
, Qdos
) == 1
18244 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18250 /* Mention the EOL conversion if it is not the usual one. */
18251 if (STRINGP (eoltype
))
18253 eol_str
= SDATA (eoltype
);
18254 eol_str_len
= SBYTES (eoltype
);
18256 else if (CHARACTERP (eoltype
))
18258 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18259 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18264 eol_str
= invalid_eol_type
;
18265 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18267 bcopy (eol_str
, buf
, eol_str_len
);
18268 buf
+= eol_str_len
;
18274 /* Return a string for the output of a mode line %-spec for window W,
18275 generated by character C. PRECISION >= 0 means don't return a
18276 string longer than that value. FIELD_WIDTH > 0 means pad the
18277 string returned with spaces to that value. Return 1 in *MULTIBYTE
18278 if the result is multibyte text.
18280 Note we operate on the current buffer for most purposes,
18281 the exception being w->base_line_pos. */
18283 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18286 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
18289 int field_width
, precision
;
18293 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18294 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18295 struct buffer
*b
= current_buffer
;
18303 if (!NILP (b
->read_only
))
18305 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18310 /* This differs from %* only for a modified read-only buffer. */
18311 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18313 if (!NILP (b
->read_only
))
18318 /* This differs from %* in ignoring read-only-ness. */
18319 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18331 if (command_loop_level
> 5)
18333 p
= decode_mode_spec_buf
;
18334 for (i
= 0; i
< command_loop_level
; i
++)
18337 return decode_mode_spec_buf
;
18345 if (command_loop_level
> 5)
18347 p
= decode_mode_spec_buf
;
18348 for (i
= 0; i
< command_loop_level
; i
++)
18351 return decode_mode_spec_buf
;
18358 /* Let lots_of_dashes be a string of infinite length. */
18359 if (mode_line_target
== MODE_LINE_NOPROP
||
18360 mode_line_target
== MODE_LINE_STRING
)
18362 if (field_width
<= 0
18363 || field_width
> sizeof (lots_of_dashes
))
18365 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18366 decode_mode_spec_buf
[i
] = '-';
18367 decode_mode_spec_buf
[i
] = '\0';
18368 return decode_mode_spec_buf
;
18371 return lots_of_dashes
;
18379 /* %c and %l are ignored in `frame-title-format'.
18380 (In redisplay_internal, the frame title is drawn _before_ the
18381 windows are updated, so the stuff which depends on actual
18382 window contents (such as %l) may fail to render properly, or
18383 even crash emacs.) */
18384 if (mode_line_target
== MODE_LINE_TITLE
)
18388 int col
= (int) current_column (); /* iftc */
18389 w
->column_number_displayed
= make_number (col
);
18390 pint2str (decode_mode_spec_buf
, field_width
, col
);
18391 return decode_mode_spec_buf
;
18395 #ifndef SYSTEM_MALLOC
18397 if (NILP (Vmemory_full
))
18400 return "!MEM FULL! ";
18407 /* %F displays the frame name. */
18408 if (!NILP (f
->title
))
18409 return (char *) SDATA (f
->title
);
18410 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18411 return (char *) SDATA (f
->name
);
18420 int size
= ZV
- BEGV
;
18421 pint2str (decode_mode_spec_buf
, field_width
, size
);
18422 return decode_mode_spec_buf
;
18427 int size
= ZV
- BEGV
;
18428 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18429 return decode_mode_spec_buf
;
18434 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18435 int topline
, nlines
, junk
, height
;
18437 /* %c and %l are ignored in `frame-title-format'. */
18438 if (mode_line_target
== MODE_LINE_TITLE
)
18441 startpos
= XMARKER (w
->start
)->charpos
;
18442 startpos_byte
= marker_byte_position (w
->start
);
18443 height
= WINDOW_TOTAL_LINES (w
);
18445 /* If we decided that this buffer isn't suitable for line numbers,
18446 don't forget that too fast. */
18447 if (EQ (w
->base_line_pos
, w
->buffer
))
18449 /* But do forget it, if the window shows a different buffer now. */
18450 else if (BUFFERP (w
->base_line_pos
))
18451 w
->base_line_pos
= Qnil
;
18453 /* If the buffer is very big, don't waste time. */
18454 if (INTEGERP (Vline_number_display_limit
)
18455 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18457 w
->base_line_pos
= Qnil
;
18458 w
->base_line_number
= Qnil
;
18462 if (INTEGERP (w
->base_line_number
)
18463 && INTEGERP (w
->base_line_pos
)
18464 && XFASTINT (w
->base_line_pos
) <= startpos
)
18466 line
= XFASTINT (w
->base_line_number
);
18467 linepos
= XFASTINT (w
->base_line_pos
);
18468 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18473 linepos
= BUF_BEGV (b
);
18474 linepos_byte
= BUF_BEGV_BYTE (b
);
18477 /* Count lines from base line to window start position. */
18478 nlines
= display_count_lines (linepos
, linepos_byte
,
18482 topline
= nlines
+ line
;
18484 /* Determine a new base line, if the old one is too close
18485 or too far away, or if we did not have one.
18486 "Too close" means it's plausible a scroll-down would
18487 go back past it. */
18488 if (startpos
== BUF_BEGV (b
))
18490 w
->base_line_number
= make_number (topline
);
18491 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18493 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18494 || linepos
== BUF_BEGV (b
))
18496 int limit
= BUF_BEGV (b
);
18497 int limit_byte
= BUF_BEGV_BYTE (b
);
18499 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18501 if (startpos
- distance
> limit
)
18503 limit
= startpos
- distance
;
18504 limit_byte
= CHAR_TO_BYTE (limit
);
18507 nlines
= display_count_lines (startpos
, startpos_byte
,
18509 - (height
* 2 + 30),
18511 /* If we couldn't find the lines we wanted within
18512 line_number_display_limit_width chars per line,
18513 give up on line numbers for this window. */
18514 if (position
== limit_byte
&& limit
== startpos
- distance
)
18516 w
->base_line_pos
= w
->buffer
;
18517 w
->base_line_number
= Qnil
;
18521 w
->base_line_number
= make_number (topline
- nlines
);
18522 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18525 /* Now count lines from the start pos to point. */
18526 nlines
= display_count_lines (startpos
, startpos_byte
,
18527 PT_BYTE
, PT
, &junk
);
18529 /* Record that we did display the line number. */
18530 line_number_displayed
= 1;
18532 /* Make the string to show. */
18533 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18534 return decode_mode_spec_buf
;
18537 char* p
= decode_mode_spec_buf
;
18538 int pad
= field_width
- 2;
18544 return decode_mode_spec_buf
;
18550 obj
= b
->mode_name
;
18554 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18560 int pos
= marker_position (w
->start
);
18561 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18563 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18565 if (pos
<= BUF_BEGV (b
))
18570 else if (pos
<= BUF_BEGV (b
))
18574 if (total
> 1000000)
18575 /* Do it differently for a large value, to avoid overflow. */
18576 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18578 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18579 /* We can't normally display a 3-digit number,
18580 so get us a 2-digit number that is close. */
18583 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18584 return decode_mode_spec_buf
;
18588 /* Display percentage of size above the bottom of the screen. */
18591 int toppos
= marker_position (w
->start
);
18592 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18593 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18595 if (botpos
>= BUF_ZV (b
))
18597 if (toppos
<= BUF_BEGV (b
))
18604 if (total
> 1000000)
18605 /* Do it differently for a large value, to avoid overflow. */
18606 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18608 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18609 /* We can't normally display a 3-digit number,
18610 so get us a 2-digit number that is close. */
18613 if (toppos
<= BUF_BEGV (b
))
18614 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18616 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18617 return decode_mode_spec_buf
;
18622 /* status of process */
18623 obj
= Fget_buffer_process (Fcurrent_buffer ());
18625 return "no process";
18626 #ifdef subprocesses
18627 obj
= Fsymbol_name (Fprocess_status (obj
));
18634 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18641 case 't': /* indicate TEXT or BINARY */
18642 #ifdef MODE_LINE_BINARY_TEXT
18643 return MODE_LINE_BINARY_TEXT (b
);
18649 /* coding-system (not including end-of-line format) */
18651 /* coding-system (including end-of-line type) */
18653 int eol_flag
= (c
== 'Z');
18654 char *p
= decode_mode_spec_buf
;
18656 if (! FRAME_WINDOW_P (f
))
18658 /* No need to mention EOL here--the terminal never needs
18659 to do EOL conversion. */
18660 p
= decode_mode_spec_coding (CODING_ID_NAME
18661 (FRAME_KEYBOARD_CODING (f
)->id
),
18663 p
= decode_mode_spec_coding (CODING_ID_NAME
18664 (FRAME_TERMINAL_CODING (f
)->id
),
18667 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18670 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18671 #ifdef subprocesses
18672 obj
= Fget_buffer_process (Fcurrent_buffer ());
18673 if (PROCESSP (obj
))
18675 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18677 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18680 #endif /* subprocesses */
18683 return decode_mode_spec_buf
;
18689 *multibyte
= STRING_MULTIBYTE (obj
);
18690 return (char *) SDATA (obj
);
18697 /* Count up to COUNT lines starting from START / START_BYTE.
18698 But don't go beyond LIMIT_BYTE.
18699 Return the number of lines thus found (always nonnegative).
18701 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18704 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18705 int start
, start_byte
, limit_byte
, count
;
18708 register unsigned char *cursor
;
18709 unsigned char *base
;
18711 register int ceiling
;
18712 register unsigned char *ceiling_addr
;
18713 int orig_count
= count
;
18715 /* If we are not in selective display mode,
18716 check only for newlines. */
18717 int selective_display
= (!NILP (current_buffer
->selective_display
)
18718 && !INTEGERP (current_buffer
->selective_display
));
18722 while (start_byte
< limit_byte
)
18724 ceiling
= BUFFER_CEILING_OF (start_byte
);
18725 ceiling
= min (limit_byte
- 1, ceiling
);
18726 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18727 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18730 if (selective_display
)
18731 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18734 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18737 if (cursor
!= ceiling_addr
)
18741 start_byte
+= cursor
- base
+ 1;
18742 *byte_pos_ptr
= start_byte
;
18746 if (++cursor
== ceiling_addr
)
18752 start_byte
+= cursor
- base
;
18757 while (start_byte
> limit_byte
)
18759 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18760 ceiling
= max (limit_byte
, ceiling
);
18761 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18762 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18765 if (selective_display
)
18766 while (--cursor
!= ceiling_addr
18767 && *cursor
!= '\n' && *cursor
!= 015)
18770 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18773 if (cursor
!= ceiling_addr
)
18777 start_byte
+= cursor
- base
+ 1;
18778 *byte_pos_ptr
= start_byte
;
18779 /* When scanning backwards, we should
18780 not count the newline posterior to which we stop. */
18781 return - orig_count
- 1;
18787 /* Here we add 1 to compensate for the last decrement
18788 of CURSOR, which took it past the valid range. */
18789 start_byte
+= cursor
- base
+ 1;
18793 *byte_pos_ptr
= limit_byte
;
18796 return - orig_count
+ count
;
18797 return orig_count
- count
;
18803 /***********************************************************************
18805 ***********************************************************************/
18807 /* Display a NUL-terminated string, starting with index START.
18809 If STRING is non-null, display that C string. Otherwise, the Lisp
18810 string LISP_STRING is displayed.
18812 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18813 FACE_STRING. Display STRING or LISP_STRING with the face at
18814 FACE_STRING_POS in FACE_STRING:
18816 Display the string in the environment given by IT, but use the
18817 standard display table, temporarily.
18819 FIELD_WIDTH is the minimum number of output glyphs to produce.
18820 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18821 with spaces. If STRING has more characters, more than FIELD_WIDTH
18822 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18824 PRECISION is the maximum number of characters to output from
18825 STRING. PRECISION < 0 means don't truncate the string.
18827 This is roughly equivalent to printf format specifiers:
18829 FIELD_WIDTH PRECISION PRINTF
18830 ----------------------------------------
18836 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18837 display them, and < 0 means obey the current buffer's value of
18838 enable_multibyte_characters.
18840 Value is the number of columns displayed. */
18843 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18844 start
, it
, field_width
, precision
, max_x
, multibyte
)
18845 unsigned char *string
;
18846 Lisp_Object lisp_string
;
18847 Lisp_Object face_string
;
18848 EMACS_INT face_string_pos
;
18851 int field_width
, precision
, max_x
;
18854 int hpos_at_start
= it
->hpos
;
18855 int saved_face_id
= it
->face_id
;
18856 struct glyph_row
*row
= it
->glyph_row
;
18858 /* Initialize the iterator IT for iteration over STRING beginning
18859 with index START. */
18860 reseat_to_string (it
, string
, lisp_string
, start
,
18861 precision
, field_width
, multibyte
);
18863 /* If displaying STRING, set up the face of the iterator
18864 from LISP_STRING, if that's given. */
18865 if (STRINGP (face_string
))
18871 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18872 0, it
->region_beg_charpos
,
18873 it
->region_end_charpos
,
18874 &endptr
, it
->base_face_id
, 0);
18875 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18876 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18879 /* Set max_x to the maximum allowed X position. Don't let it go
18880 beyond the right edge of the window. */
18882 max_x
= it
->last_visible_x
;
18884 max_x
= min (max_x
, it
->last_visible_x
);
18886 /* Skip over display elements that are not visible. because IT->w is
18888 if (it
->current_x
< it
->first_visible_x
)
18889 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18890 MOVE_TO_POS
| MOVE_TO_X
);
18892 row
->ascent
= it
->max_ascent
;
18893 row
->height
= it
->max_ascent
+ it
->max_descent
;
18894 row
->phys_ascent
= it
->max_phys_ascent
;
18895 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18896 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18898 /* This condition is for the case that we are called with current_x
18899 past last_visible_x. */
18900 while (it
->current_x
< max_x
)
18902 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18904 /* Get the next display element. */
18905 if (!get_next_display_element (it
))
18908 /* Produce glyphs. */
18909 x_before
= it
->current_x
;
18910 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18911 PRODUCE_GLYPHS (it
);
18913 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18916 while (i
< nglyphs
)
18918 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18920 if (it
->line_wrap
!= TRUNCATE
18921 && x
+ glyph
->pixel_width
> max_x
)
18923 /* End of continued line or max_x reached. */
18924 if (CHAR_GLYPH_PADDING_P (*glyph
))
18926 /* A wide character is unbreakable. */
18927 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18928 it
->current_x
= x_before
;
18932 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18937 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18939 /* Glyph is at least partially visible. */
18941 if (x
< it
->first_visible_x
)
18942 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18946 /* Glyph is off the left margin of the display area.
18947 Should not happen. */
18951 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18952 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18953 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18954 row
->phys_height
= max (row
->phys_height
,
18955 it
->max_phys_ascent
+ it
->max_phys_descent
);
18956 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18957 it
->max_extra_line_spacing
);
18958 x
+= glyph
->pixel_width
;
18962 /* Stop if max_x reached. */
18966 /* Stop at line ends. */
18967 if (ITERATOR_AT_END_OF_LINE_P (it
))
18969 it
->continuation_lines_width
= 0;
18973 set_iterator_to_next (it
, 1);
18975 /* Stop if truncating at the right edge. */
18976 if (it
->line_wrap
== TRUNCATE
18977 && it
->current_x
>= it
->last_visible_x
)
18979 /* Add truncation mark, but don't do it if the line is
18980 truncated at a padding space. */
18981 if (IT_CHARPOS (*it
) < it
->string_nchars
)
18983 if (!FRAME_WINDOW_P (it
->f
))
18987 if (it
->current_x
> it
->last_visible_x
)
18989 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
18990 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
18992 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
18994 row
->used
[TEXT_AREA
] = i
;
18995 produce_special_glyphs (it
, IT_TRUNCATION
);
18998 produce_special_glyphs (it
, IT_TRUNCATION
);
19000 it
->glyph_row
->truncated_on_right_p
= 1;
19006 /* Maybe insert a truncation at the left. */
19007 if (it
->first_visible_x
19008 && IT_CHARPOS (*it
) > 0)
19010 if (!FRAME_WINDOW_P (it
->f
))
19011 insert_left_trunc_glyphs (it
);
19012 it
->glyph_row
->truncated_on_left_p
= 1;
19015 it
->face_id
= saved_face_id
;
19017 /* Value is number of columns displayed. */
19018 return it
->hpos
- hpos_at_start
;
19023 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19024 appears as an element of LIST or as the car of an element of LIST.
19025 If PROPVAL is a list, compare each element against LIST in that
19026 way, and return 1/2 if any element of PROPVAL is found in LIST.
19027 Otherwise return 0. This function cannot quit.
19028 The return value is 2 if the text is invisible but with an ellipsis
19029 and 1 if it's invisible and without an ellipsis. */
19032 invisible_p (propval
, list
)
19033 register Lisp_Object propval
;
19036 register Lisp_Object tail
, proptail
;
19038 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19040 register Lisp_Object tem
;
19042 if (EQ (propval
, tem
))
19044 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19045 return NILP (XCDR (tem
)) ? 1 : 2;
19048 if (CONSP (propval
))
19050 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19052 Lisp_Object propelt
;
19053 propelt
= XCAR (proptail
);
19054 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19056 register Lisp_Object tem
;
19058 if (EQ (propelt
, tem
))
19060 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19061 return NILP (XCDR (tem
)) ? 1 : 2;
19069 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19070 doc
: /* Non-nil if the property makes the text invisible.
19071 POS-OR-PROP can be a marker or number, in which case it is taken to be
19072 a position in the current buffer and the value of the `invisible' property
19073 is checked; or it can be some other value, which is then presumed to be the
19074 value of the `invisible' property of the text of interest.
19075 The non-nil value returned can be t for truly invisible text or something
19076 else if the text is replaced by an ellipsis. */)
19078 Lisp_Object pos_or_prop
;
19081 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19082 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19084 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19085 return (invis
== 0 ? Qnil
19087 : make_number (invis
));
19090 /* Calculate a width or height in pixels from a specification using
19091 the following elements:
19094 NUM - a (fractional) multiple of the default font width/height
19095 (NUM) - specifies exactly NUM pixels
19096 UNIT - a fixed number of pixels, see below.
19097 ELEMENT - size of a display element in pixels, see below.
19098 (NUM . SPEC) - equals NUM * SPEC
19099 (+ SPEC SPEC ...) - add pixel values
19100 (- SPEC SPEC ...) - subtract pixel values
19101 (- SPEC) - negate pixel value
19104 INT or FLOAT - a number constant
19105 SYMBOL - use symbol's (buffer local) variable binding.
19108 in - pixels per inch *)
19109 mm - pixels per 1/1000 meter *)
19110 cm - pixels per 1/100 meter *)
19111 width - width of current font in pixels.
19112 height - height of current font in pixels.
19114 *) using the ratio(s) defined in display-pixels-per-inch.
19118 left-fringe - left fringe width in pixels
19119 right-fringe - right fringe width in pixels
19121 left-margin - left margin width in pixels
19122 right-margin - right margin width in pixels
19124 scroll-bar - scroll-bar area width in pixels
19128 Pixels corresponding to 5 inches:
19131 Total width of non-text areas on left side of window (if scroll-bar is on left):
19132 '(space :width (+ left-fringe left-margin scroll-bar))
19134 Align to first text column (in header line):
19135 '(space :align-to 0)
19137 Align to middle of text area minus half the width of variable `my-image'
19138 containing a loaded image:
19139 '(space :align-to (0.5 . (- text my-image)))
19141 Width of left margin minus width of 1 character in the default font:
19142 '(space :width (- left-margin 1))
19144 Width of left margin minus width of 2 characters in the current font:
19145 '(space :width (- left-margin (2 . width)))
19147 Center 1 character over left-margin (in header line):
19148 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19150 Different ways to express width of left fringe plus left margin minus one pixel:
19151 '(space :width (- (+ left-fringe left-margin) (1)))
19152 '(space :width (+ left-fringe left-margin (- (1))))
19153 '(space :width (+ left-fringe left-margin (-1)))
19157 #define NUMVAL(X) \
19158 ((INTEGERP (X) || FLOATP (X)) \
19163 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19168 int width_p
, *align_to
;
19172 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19173 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19176 return OK_PIXELS (0);
19178 xassert (FRAME_LIVE_P (it
->f
));
19180 if (SYMBOLP (prop
))
19182 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19184 char *unit
= SDATA (SYMBOL_NAME (prop
));
19186 if (unit
[0] == 'i' && unit
[1] == 'n')
19188 else if (unit
[0] == 'm' && unit
[1] == 'm')
19190 else if (unit
[0] == 'c' && unit
[1] == 'm')
19197 #ifdef HAVE_WINDOW_SYSTEM
19198 if (FRAME_WINDOW_P (it
->f
)
19200 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19201 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19203 return OK_PIXELS (ppi
/ pixels
);
19206 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19207 || (CONSP (Vdisplay_pixels_per_inch
)
19209 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19210 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19212 return OK_PIXELS (ppi
/ pixels
);
19218 #ifdef HAVE_WINDOW_SYSTEM
19219 if (EQ (prop
, Qheight
))
19220 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19221 if (EQ (prop
, Qwidth
))
19222 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19224 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19225 return OK_PIXELS (1);
19228 if (EQ (prop
, Qtext
))
19229 return OK_PIXELS (width_p
19230 ? window_box_width (it
->w
, TEXT_AREA
)
19231 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19233 if (align_to
&& *align_to
< 0)
19236 if (EQ (prop
, Qleft
))
19237 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19238 if (EQ (prop
, Qright
))
19239 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19240 if (EQ (prop
, Qcenter
))
19241 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19242 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19243 if (EQ (prop
, Qleft_fringe
))
19244 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19245 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19246 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19247 if (EQ (prop
, Qright_fringe
))
19248 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19249 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19250 : window_box_right_offset (it
->w
, TEXT_AREA
));
19251 if (EQ (prop
, Qleft_margin
))
19252 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19253 if (EQ (prop
, Qright_margin
))
19254 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19255 if (EQ (prop
, Qscroll_bar
))
19256 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19258 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19259 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19260 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19265 if (EQ (prop
, Qleft_fringe
))
19266 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19267 if (EQ (prop
, Qright_fringe
))
19268 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19269 if (EQ (prop
, Qleft_margin
))
19270 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19271 if (EQ (prop
, Qright_margin
))
19272 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19273 if (EQ (prop
, Qscroll_bar
))
19274 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19277 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19280 if (INTEGERP (prop
) || FLOATP (prop
))
19282 int base_unit
= (width_p
19283 ? FRAME_COLUMN_WIDTH (it
->f
)
19284 : FRAME_LINE_HEIGHT (it
->f
));
19285 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19290 Lisp_Object car
= XCAR (prop
);
19291 Lisp_Object cdr
= XCDR (prop
);
19295 #ifdef HAVE_WINDOW_SYSTEM
19296 if (FRAME_WINDOW_P (it
->f
)
19297 && valid_image_p (prop
))
19299 int id
= lookup_image (it
->f
, prop
);
19300 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19302 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19305 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19311 while (CONSP (cdr
))
19313 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19314 font
, width_p
, align_to
))
19317 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19322 if (EQ (car
, Qminus
))
19324 return OK_PIXELS (pixels
);
19327 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19330 if (INTEGERP (car
) || FLOATP (car
))
19333 pixels
= XFLOATINT (car
);
19335 return OK_PIXELS (pixels
);
19336 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19337 font
, width_p
, align_to
))
19338 return OK_PIXELS (pixels
* fact
);
19349 /***********************************************************************
19351 ***********************************************************************/
19353 #ifdef HAVE_WINDOW_SYSTEM
19358 dump_glyph_string (s
)
19359 struct glyph_string
*s
;
19361 fprintf (stderr
, "glyph string\n");
19362 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19363 s
->x
, s
->y
, s
->width
, s
->height
);
19364 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19365 fprintf (stderr
, " hl = %d\n", s
->hl
);
19366 fprintf (stderr
, " left overhang = %d, right = %d\n",
19367 s
->left_overhang
, s
->right_overhang
);
19368 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19369 fprintf (stderr
, " extends to end of line = %d\n",
19370 s
->extends_to_end_of_line_p
);
19371 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19372 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19375 #endif /* GLYPH_DEBUG */
19377 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19378 of XChar2b structures for S; it can't be allocated in
19379 init_glyph_string because it must be allocated via `alloca'. W
19380 is the window on which S is drawn. ROW and AREA are the glyph row
19381 and area within the row from which S is constructed. START is the
19382 index of the first glyph structure covered by S. HL is a
19383 face-override for drawing S. */
19386 #define OPTIONAL_HDC(hdc) hdc,
19387 #define DECLARE_HDC(hdc) HDC hdc;
19388 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19389 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19392 #ifndef OPTIONAL_HDC
19393 #define OPTIONAL_HDC(hdc)
19394 #define DECLARE_HDC(hdc)
19395 #define ALLOCATE_HDC(hdc, f)
19396 #define RELEASE_HDC(hdc, f)
19400 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19401 struct glyph_string
*s
;
19405 struct glyph_row
*row
;
19406 enum glyph_row_area area
;
19408 enum draw_glyphs_face hl
;
19410 bzero (s
, sizeof *s
);
19412 s
->f
= XFRAME (w
->frame
);
19416 s
->display
= FRAME_X_DISPLAY (s
->f
);
19417 s
->window
= FRAME_X_WINDOW (s
->f
);
19418 s
->char2b
= char2b
;
19422 s
->first_glyph
= row
->glyphs
[area
] + start
;
19423 s
->height
= row
->height
;
19424 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19426 /* Display the internal border below the tool-bar window. */
19427 if (WINDOWP (s
->f
->tool_bar_window
)
19428 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19429 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19431 s
->ybase
= s
->y
+ row
->ascent
;
19435 /* Append the list of glyph strings with head H and tail T to the list
19436 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19439 append_glyph_string_lists (head
, tail
, h
, t
)
19440 struct glyph_string
**head
, **tail
;
19441 struct glyph_string
*h
, *t
;
19455 /* Prepend the list of glyph strings with head H and tail T to the
19456 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19460 prepend_glyph_string_lists (head
, tail
, h
, t
)
19461 struct glyph_string
**head
, **tail
;
19462 struct glyph_string
*h
, *t
;
19476 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19477 Set *HEAD and *TAIL to the resulting list. */
19480 append_glyph_string (head
, tail
, s
)
19481 struct glyph_string
**head
, **tail
;
19482 struct glyph_string
*s
;
19484 s
->next
= s
->prev
= NULL
;
19485 append_glyph_string_lists (head
, tail
, s
, s
);
19489 /* Get face and two-byte form of character C in face FACE_ID on frame
19490 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19491 means we want to display multibyte text. DISPLAY_P non-zero means
19492 make sure that X resources for the face returned are allocated.
19493 Value is a pointer to a realized face that is ready for display if
19494 DISPLAY_P is non-zero. */
19496 static INLINE
struct face
*
19497 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19501 int multibyte_p
, display_p
;
19503 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19507 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19509 if (code
!= FONT_INVALID_CODE
)
19510 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19512 STORE_XCHAR2B (char2b
, 0, 0);
19515 /* Make sure X resources of the face are allocated. */
19516 #ifdef HAVE_X_WINDOWS
19520 xassert (face
!= NULL
);
19521 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19528 /* Get face and two-byte form of character glyph GLYPH on frame F.
19529 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19530 a pointer to a realized face that is ready for display. */
19532 static INLINE
struct face
*
19533 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19535 struct glyph
*glyph
;
19541 xassert (glyph
->type
== CHAR_GLYPH
);
19542 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19549 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19551 if (code
!= FONT_INVALID_CODE
)
19552 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19554 STORE_XCHAR2B (char2b
, 0, 0);
19557 /* Make sure X resources of the face are allocated. */
19558 xassert (face
!= NULL
);
19559 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19564 /* Fill glyph string S with composition components specified by S->cmp.
19566 BASE_FACE is the base face of the composition.
19567 S->cmp_from is the index of the first component for S.
19569 OVERLAPS non-zero means S should draw the foreground only, and use
19570 its physical height for clipping. See also draw_glyphs.
19572 Value is the index of a component not in S. */
19575 fill_composite_glyph_string (s
, base_face
, overlaps
)
19576 struct glyph_string
*s
;
19577 struct face
*base_face
;
19581 /* For all glyphs of this composition, starting at the offset
19582 S->cmp_from, until we reach the end of the definition or encounter a
19583 glyph that requires the different face, add it to S. */
19588 s
->for_overlaps
= overlaps
;
19591 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
19593 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19597 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19600 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19601 s
->char2b
+ i
, 1, 1);
19607 s
->font
= s
->face
->font
;
19609 else if (s
->face
!= face
)
19617 /* All glyph strings for the same composition has the same width,
19618 i.e. the width set for the first component of the composition. */
19619 s
->width
= s
->first_glyph
->pixel_width
;
19621 /* If the specified font could not be loaded, use the frame's
19622 default font, but record the fact that we couldn't load it in
19623 the glyph string so that we can draw rectangles for the
19624 characters of the glyph string. */
19625 if (s
->font
== NULL
)
19627 s
->font_not_found_p
= 1;
19628 s
->font
= FRAME_FONT (s
->f
);
19631 /* Adjust base line for subscript/superscript text. */
19632 s
->ybase
+= s
->first_glyph
->voffset
;
19634 /* This glyph string must always be drawn with 16-bit functions. */
19641 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
19642 struct glyph_string
*s
;
19644 int start
, end
, overlaps
;
19646 struct glyph
*glyph
, *last
;
19647 Lisp_Object lgstring
;
19650 s
->for_overlaps
= overlaps
;
19651 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19652 last
= s
->row
->glyphs
[s
->area
] + end
;
19653 s
->cmp_id
= glyph
->u
.cmp
.id
;
19654 s
->cmp_from
= glyph
->u
.cmp
.from
;
19655 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
19656 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19657 lgstring
= composition_gstring_from_id (s
->cmp_id
);
19658 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
19660 while (glyph
< last
19661 && glyph
->u
.cmp
.automatic
19662 && glyph
->u
.cmp
.id
== s
->cmp_id
19663 && s
->cmp_to
== glyph
->u
.cmp
.from
)
19664 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
19666 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
19668 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
19669 unsigned code
= LGLYPH_CODE (lglyph
);
19671 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
19673 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
19674 return glyph
- s
->row
->glyphs
[s
->area
];
19678 /* Fill glyph string S from a sequence of character glyphs.
19680 FACE_ID is the face id of the string. START is the index of the
19681 first glyph to consider, END is the index of the last + 1.
19682 OVERLAPS non-zero means S should draw the foreground only, and use
19683 its physical height for clipping. See also draw_glyphs.
19685 Value is the index of the first glyph not in S. */
19688 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19689 struct glyph_string
*s
;
19691 int start
, end
, overlaps
;
19693 struct glyph
*glyph
, *last
;
19695 int glyph_not_available_p
;
19697 xassert (s
->f
== XFRAME (s
->w
->frame
));
19698 xassert (s
->nchars
== 0);
19699 xassert (start
>= 0 && end
> start
);
19701 s
->for_overlaps
= overlaps
;
19702 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19703 last
= s
->row
->glyphs
[s
->area
] + end
;
19704 voffset
= glyph
->voffset
;
19705 s
->padding_p
= glyph
->padding_p
;
19706 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19708 while (glyph
< last
19709 && glyph
->type
== CHAR_GLYPH
19710 && glyph
->voffset
== voffset
19711 /* Same face id implies same font, nowadays. */
19712 && glyph
->face_id
== face_id
19713 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19717 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19718 s
->char2b
+ s
->nchars
,
19720 s
->two_byte_p
= two_byte_p
;
19722 xassert (s
->nchars
<= end
- start
);
19723 s
->width
+= glyph
->pixel_width
;
19724 if (glyph
++->padding_p
!= s
->padding_p
)
19728 s
->font
= s
->face
->font
;
19730 /* If the specified font could not be loaded, use the frame's font,
19731 but record the fact that we couldn't load it in
19732 S->font_not_found_p so that we can draw rectangles for the
19733 characters of the glyph string. */
19734 if (s
->font
== NULL
|| glyph_not_available_p
)
19736 s
->font_not_found_p
= 1;
19737 s
->font
= FRAME_FONT (s
->f
);
19740 /* Adjust base line for subscript/superscript text. */
19741 s
->ybase
+= voffset
;
19743 xassert (s
->face
&& s
->face
->gc
);
19744 return glyph
- s
->row
->glyphs
[s
->area
];
19748 /* Fill glyph string S from image glyph S->first_glyph. */
19751 fill_image_glyph_string (s
)
19752 struct glyph_string
*s
;
19754 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19755 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19757 s
->slice
= s
->first_glyph
->slice
;
19758 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19759 s
->font
= s
->face
->font
;
19760 s
->width
= s
->first_glyph
->pixel_width
;
19762 /* Adjust base line for subscript/superscript text. */
19763 s
->ybase
+= s
->first_glyph
->voffset
;
19767 /* Fill glyph string S from a sequence of stretch glyphs.
19769 ROW is the glyph row in which the glyphs are found, AREA is the
19770 area within the row. START is the index of the first glyph to
19771 consider, END is the index of the last + 1.
19773 Value is the index of the first glyph not in S. */
19776 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19777 struct glyph_string
*s
;
19778 struct glyph_row
*row
;
19779 enum glyph_row_area area
;
19782 struct glyph
*glyph
, *last
;
19783 int voffset
, face_id
;
19785 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19787 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19788 last
= s
->row
->glyphs
[s
->area
] + end
;
19789 face_id
= glyph
->face_id
;
19790 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19791 s
->font
= s
->face
->font
;
19792 s
->width
= glyph
->pixel_width
;
19794 voffset
= glyph
->voffset
;
19798 && glyph
->type
== STRETCH_GLYPH
19799 && glyph
->voffset
== voffset
19800 && glyph
->face_id
== face_id
);
19802 s
->width
+= glyph
->pixel_width
;
19804 /* Adjust base line for subscript/superscript text. */
19805 s
->ybase
+= voffset
;
19807 /* The case that face->gc == 0 is handled when drawing the glyph
19808 string by calling PREPARE_FACE_FOR_DISPLAY. */
19810 return glyph
- s
->row
->glyphs
[s
->area
];
19813 static struct font_metrics
*
19814 get_per_char_metric (f
, font
, char2b
)
19819 static struct font_metrics metrics
;
19820 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19822 if (! font
|| code
== FONT_INVALID_CODE
)
19824 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19829 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19830 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19831 assumed to be zero. */
19834 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19835 struct glyph
*glyph
;
19839 *left
= *right
= 0;
19841 if (glyph
->type
== CHAR_GLYPH
)
19845 struct font_metrics
*pcm
;
19847 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19848 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19850 if (pcm
->rbearing
> pcm
->width
)
19851 *right
= pcm
->rbearing
- pcm
->width
;
19852 if (pcm
->lbearing
< 0)
19853 *left
= -pcm
->lbearing
;
19856 else if (glyph
->type
== COMPOSITE_GLYPH
)
19858 if (! glyph
->u
.cmp
.automatic
)
19860 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
19862 if (cmp
->rbearing
> cmp
->pixel_width
)
19863 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19864 if (cmp
->lbearing
< 0)
19865 *left
= - cmp
->lbearing
;
19869 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
19870 struct font_metrics metrics
;
19872 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
19873 glyph
->u
.cmp
.to
+ 1, &metrics
);
19874 if (metrics
.rbearing
> metrics
.width
)
19875 *right
= metrics
.rbearing
- metrics
.width
;
19876 if (metrics
.lbearing
< 0)
19877 *left
= - metrics
.lbearing
;
19883 /* Return the index of the first glyph preceding glyph string S that
19884 is overwritten by S because of S's left overhang. Value is -1
19885 if no glyphs are overwritten. */
19888 left_overwritten (s
)
19889 struct glyph_string
*s
;
19893 if (s
->left_overhang
)
19896 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19897 int first
= s
->first_glyph
- glyphs
;
19899 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19900 x
-= glyphs
[i
].pixel_width
;
19911 /* Return the index of the first glyph preceding glyph string S that
19912 is overwriting S because of its right overhang. Value is -1 if no
19913 glyph in front of S overwrites S. */
19916 left_overwriting (s
)
19917 struct glyph_string
*s
;
19920 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19921 int first
= s
->first_glyph
- glyphs
;
19925 for (i
= first
- 1; i
>= 0; --i
)
19928 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19931 x
-= glyphs
[i
].pixel_width
;
19938 /* Return the index of the last glyph following glyph string S that is
19939 overwritten by S because of S's right overhang. Value is -1 if
19940 no such glyph is found. */
19943 right_overwritten (s
)
19944 struct glyph_string
*s
;
19948 if (s
->right_overhang
)
19951 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19952 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19953 int end
= s
->row
->used
[s
->area
];
19955 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19956 x
+= glyphs
[i
].pixel_width
;
19965 /* Return the index of the last glyph following glyph string S that
19966 overwrites S because of its left overhang. Value is negative
19967 if no such glyph is found. */
19970 right_overwriting (s
)
19971 struct glyph_string
*s
;
19974 int end
= s
->row
->used
[s
->area
];
19975 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19976 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19980 for (i
= first
; i
< end
; ++i
)
19983 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19986 x
+= glyphs
[i
].pixel_width
;
19993 /* Set background width of glyph string S. START is the index of the
19994 first glyph following S. LAST_X is the right-most x-position + 1
19995 in the drawing area. */
19998 set_glyph_string_background_width (s
, start
, last_x
)
19999 struct glyph_string
*s
;
20003 /* If the face of this glyph string has to be drawn to the end of
20004 the drawing area, set S->extends_to_end_of_line_p. */
20006 if (start
== s
->row
->used
[s
->area
]
20007 && s
->area
== TEXT_AREA
20008 && ((s
->row
->fill_line_p
20009 && (s
->hl
== DRAW_NORMAL_TEXT
20010 || s
->hl
== DRAW_IMAGE_RAISED
20011 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20012 || s
->hl
== DRAW_MOUSE_FACE
))
20013 s
->extends_to_end_of_line_p
= 1;
20015 /* If S extends its face to the end of the line, set its
20016 background_width to the distance to the right edge of the drawing
20018 if (s
->extends_to_end_of_line_p
)
20019 s
->background_width
= last_x
- s
->x
+ 1;
20021 s
->background_width
= s
->width
;
20025 /* Compute overhangs and x-positions for glyph string S and its
20026 predecessors, or successors. X is the starting x-position for S.
20027 BACKWARD_P non-zero means process predecessors. */
20030 compute_overhangs_and_x (s
, x
, backward_p
)
20031 struct glyph_string
*s
;
20039 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20040 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20050 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20051 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20061 /* The following macros are only called from draw_glyphs below.
20062 They reference the following parameters of that function directly:
20063 `w', `row', `area', and `overlap_p'
20064 as well as the following local variables:
20065 `s', `f', and `hdc' (in W32) */
20068 /* On W32, silently add local `hdc' variable to argument list of
20069 init_glyph_string. */
20070 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20071 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20073 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20074 init_glyph_string (s, char2b, w, row, area, start, hl)
20077 /* Add a glyph string for a stretch glyph to the list of strings
20078 between HEAD and TAIL. START is the index of the stretch glyph in
20079 row area AREA of glyph row ROW. END is the index of the last glyph
20080 in that glyph row area. X is the current output position assigned
20081 to the new glyph string constructed. HL overrides that face of the
20082 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20083 is the right-most x-position of the drawing area. */
20085 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20086 and below -- keep them on one line. */
20087 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20090 s = (struct glyph_string *) alloca (sizeof *s); \
20091 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20092 START = fill_stretch_glyph_string (s, row, area, START, END); \
20093 append_glyph_string (&HEAD, &TAIL, s); \
20099 /* Add a glyph string for an image glyph to the list of strings
20100 between HEAD and TAIL. START is the index of the image glyph in
20101 row area AREA of glyph row ROW. END is the index of the last glyph
20102 in that glyph row area. X is the current output position assigned
20103 to the new glyph string constructed. HL overrides that face of the
20104 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20105 is the right-most x-position of the drawing area. */
20107 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20110 s = (struct glyph_string *) alloca (sizeof *s); \
20111 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20112 fill_image_glyph_string (s); \
20113 append_glyph_string (&HEAD, &TAIL, s); \
20120 /* Add a glyph string for a sequence of character glyphs to the list
20121 of strings between HEAD and TAIL. START is the index of the first
20122 glyph in row area AREA of glyph row ROW that is part of the new
20123 glyph string. END is the index of the last glyph in that glyph row
20124 area. X is the current output position assigned to the new glyph
20125 string constructed. HL overrides that face of the glyph; e.g. it
20126 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20127 right-most x-position of the drawing area. */
20129 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20135 face_id = (row)->glyphs[area][START].face_id; \
20137 s = (struct glyph_string *) alloca (sizeof *s); \
20138 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20139 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20140 append_glyph_string (&HEAD, &TAIL, s); \
20142 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20147 /* Add a glyph string for a composite sequence to the list of strings
20148 between HEAD and TAIL. START is the index of the first glyph in
20149 row area AREA of glyph row ROW that is part of the new glyph
20150 string. END is the index of the last glyph in that glyph row area.
20151 X is the current output position assigned to the new glyph string
20152 constructed. HL overrides that face of the glyph; e.g. it is
20153 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20154 x-position of the drawing area. */
20156 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20158 int face_id = (row)->glyphs[area][START].face_id; \
20159 struct face *base_face = FACE_FROM_ID (f, face_id); \
20160 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20161 struct composition *cmp = composition_table[cmp_id]; \
20163 struct glyph_string *first_s; \
20166 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20168 /* Make glyph_strings for each glyph sequence that is drawable by \
20169 the same face, and append them to HEAD/TAIL. */ \
20170 for (n = 0; n < cmp->glyph_len;) \
20172 s = (struct glyph_string *) alloca (sizeof *s); \
20173 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20174 append_glyph_string (&(HEAD), &(TAIL), s); \
20180 n = fill_composite_glyph_string (s, base_face, overlaps); \
20188 /* Add a glyph string for a glyph-string sequence to the list of strings
20189 between HEAD and TAIL. */
20191 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20195 Lisp_Object gstring; \
20197 face_id = (row)->glyphs[area][START].face_id; \
20198 gstring = (composition_gstring_from_id \
20199 ((row)->glyphs[area][START].u.cmp.id)); \
20200 s = (struct glyph_string *) alloca (sizeof *s); \
20201 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20202 * LGSTRING_GLYPH_LEN (gstring)); \
20203 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20204 append_glyph_string (&(HEAD), &(TAIL), s); \
20206 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20210 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20211 of AREA of glyph row ROW on window W between indices START and END.
20212 HL overrides the face for drawing glyph strings, e.g. it is
20213 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20214 x-positions of the drawing area.
20216 This is an ugly monster macro construct because we must use alloca
20217 to allocate glyph strings (because draw_glyphs can be called
20218 asynchronously). */
20220 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20223 HEAD = TAIL = NULL; \
20224 while (START < END) \
20226 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20227 switch (first_glyph->type) \
20230 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20234 case COMPOSITE_GLYPH: \
20235 if (first_glyph->u.cmp.automatic) \
20236 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20239 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20243 case STRETCH_GLYPH: \
20244 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20248 case IMAGE_GLYPH: \
20249 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20259 set_glyph_string_background_width (s, START, LAST_X); \
20266 /* Draw glyphs between START and END in AREA of ROW on window W,
20267 starting at x-position X. X is relative to AREA in W. HL is a
20268 face-override with the following meaning:
20270 DRAW_NORMAL_TEXT draw normally
20271 DRAW_CURSOR draw in cursor face
20272 DRAW_MOUSE_FACE draw in mouse face.
20273 DRAW_INVERSE_VIDEO draw in mode line face
20274 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20275 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20277 If OVERLAPS is non-zero, draw only the foreground of characters and
20278 clip to the physical height of ROW. Non-zero value also defines
20279 the overlapping part to be drawn:
20281 OVERLAPS_PRED overlap with preceding rows
20282 OVERLAPS_SUCC overlap with succeeding rows
20283 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20284 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20286 Value is the x-position reached, relative to AREA of W. */
20289 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20292 struct glyph_row
*row
;
20293 enum glyph_row_area area
;
20294 EMACS_INT start
, end
;
20295 enum draw_glyphs_face hl
;
20298 struct glyph_string
*head
, *tail
;
20299 struct glyph_string
*s
;
20300 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20301 int i
, j
, x_reached
, last_x
, area_left
= 0;
20302 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20305 ALLOCATE_HDC (hdc
, f
);
20307 /* Let's rather be paranoid than getting a SEGV. */
20308 end
= min (end
, row
->used
[area
]);
20309 start
= max (0, start
);
20310 start
= min (end
, start
);
20312 /* Translate X to frame coordinates. Set last_x to the right
20313 end of the drawing area. */
20314 if (row
->full_width_p
)
20316 /* X is relative to the left edge of W, without scroll bars
20318 area_left
= WINDOW_LEFT_EDGE_X (w
);
20319 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20323 area_left
= window_box_left (w
, area
);
20324 last_x
= area_left
+ window_box_width (w
, area
);
20328 /* Build a doubly-linked list of glyph_string structures between
20329 head and tail from what we have to draw. Note that the macro
20330 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20331 the reason we use a separate variable `i'. */
20333 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20335 x_reached
= tail
->x
+ tail
->background_width
;
20339 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20340 the row, redraw some glyphs in front or following the glyph
20341 strings built above. */
20342 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20344 struct glyph_string
*h
, *t
;
20345 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20346 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20349 /* If mouse highlighting is on, we may need to draw adjacent
20350 glyphs using mouse-face highlighting. */
20351 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20353 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20355 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20356 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20358 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20360 check_mouse_face
= 1;
20361 mouse_beg_col
= (row
== mouse_beg_row
)
20362 ? dpyinfo
->mouse_face_beg_col
: 0;
20363 mouse_end_col
= (row
== mouse_end_row
)
20364 ? dpyinfo
->mouse_face_end_col
20365 : row
->used
[TEXT_AREA
];
20369 /* Compute overhangs for all glyph strings. */
20370 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20371 for (s
= head
; s
; s
= s
->next
)
20372 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20374 /* Prepend glyph strings for glyphs in front of the first glyph
20375 string that are overwritten because of the first glyph
20376 string's left overhang. The background of all strings
20377 prepended must be drawn because the first glyph string
20379 i
= left_overwritten (head
);
20382 enum draw_glyphs_face overlap_hl
;
20384 /* If this row contains mouse highlighting, attempt to draw
20385 the overlapped glyphs with the correct highlight. This
20386 code fails if the overlap encompasses more than one glyph
20387 and mouse-highlight spans only some of these glyphs.
20388 However, making it work perfectly involves a lot more
20389 code, and I don't know if the pathological case occurs in
20390 practice, so we'll stick to this for now. --- cyd */
20391 if (check_mouse_face
20392 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20393 overlap_hl
= DRAW_MOUSE_FACE
;
20395 overlap_hl
= DRAW_NORMAL_TEXT
;
20398 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20399 overlap_hl
, dummy_x
, last_x
);
20400 compute_overhangs_and_x (t
, head
->x
, 1);
20401 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20405 /* Prepend glyph strings for glyphs in front of the first glyph
20406 string that overwrite that glyph string because of their
20407 right overhang. For these strings, only the foreground must
20408 be drawn, because it draws over the glyph string at `head'.
20409 The background must not be drawn because this would overwrite
20410 right overhangs of preceding glyphs for which no glyph
20412 i
= left_overwriting (head
);
20415 enum draw_glyphs_face overlap_hl
;
20417 if (check_mouse_face
20418 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20419 overlap_hl
= DRAW_MOUSE_FACE
;
20421 overlap_hl
= DRAW_NORMAL_TEXT
;
20424 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20425 overlap_hl
, dummy_x
, last_x
);
20426 for (s
= h
; s
; s
= s
->next
)
20427 s
->background_filled_p
= 1;
20428 compute_overhangs_and_x (t
, head
->x
, 1);
20429 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20432 /* Append glyphs strings for glyphs following the last glyph
20433 string tail that are overwritten by tail. The background of
20434 these strings has to be drawn because tail's foreground draws
20436 i
= right_overwritten (tail
);
20439 enum draw_glyphs_face overlap_hl
;
20441 if (check_mouse_face
20442 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20443 overlap_hl
= DRAW_MOUSE_FACE
;
20445 overlap_hl
= DRAW_NORMAL_TEXT
;
20447 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20448 overlap_hl
, x
, last_x
);
20449 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20450 append_glyph_string_lists (&head
, &tail
, h
, t
);
20454 /* Append glyph strings for glyphs following the last glyph
20455 string tail that overwrite tail. The foreground of such
20456 glyphs has to be drawn because it writes into the background
20457 of tail. The background must not be drawn because it could
20458 paint over the foreground of following glyphs. */
20459 i
= right_overwriting (tail
);
20462 enum draw_glyphs_face overlap_hl
;
20463 if (check_mouse_face
20464 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20465 overlap_hl
= DRAW_MOUSE_FACE
;
20467 overlap_hl
= DRAW_NORMAL_TEXT
;
20470 i
++; /* We must include the Ith glyph. */
20471 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20472 overlap_hl
, x
, last_x
);
20473 for (s
= h
; s
; s
= s
->next
)
20474 s
->background_filled_p
= 1;
20475 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20476 append_glyph_string_lists (&head
, &tail
, h
, t
);
20478 if (clip_head
|| clip_tail
)
20479 for (s
= head
; s
; s
= s
->next
)
20481 s
->clip_head
= clip_head
;
20482 s
->clip_tail
= clip_tail
;
20486 /* Draw all strings. */
20487 for (s
= head
; s
; s
= s
->next
)
20488 FRAME_RIF (f
)->draw_glyph_string (s
);
20491 /* When focus a sole frame and move horizontally, this sets on_p to 0
20492 causing a failure to erase prev cursor position. */
20493 if (area
== TEXT_AREA
20494 && !row
->full_width_p
20495 /* When drawing overlapping rows, only the glyph strings'
20496 foreground is drawn, which doesn't erase a cursor
20500 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20501 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20502 : (tail
? tail
->x
+ tail
->background_width
: x
));
20506 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20507 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20511 /* Value is the x-position up to which drawn, relative to AREA of W.
20512 This doesn't include parts drawn because of overhangs. */
20513 if (row
->full_width_p
)
20514 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20516 x_reached
-= area_left
;
20518 RELEASE_HDC (hdc
, f
);
20523 /* Expand row matrix if too narrow. Don't expand if area
20526 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20528 if (!fonts_changed_p \
20529 && (it->glyph_row->glyphs[area] \
20530 < it->glyph_row->glyphs[area + 1])) \
20532 it->w->ncols_scale_factor++; \
20533 fonts_changed_p = 1; \
20537 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20538 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20544 struct glyph
*glyph
;
20545 enum glyph_row_area area
= it
->area
;
20547 xassert (it
->glyph_row
);
20548 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20550 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20551 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20553 glyph
->charpos
= CHARPOS (it
->position
);
20554 glyph
->object
= it
->object
;
20555 if (it
->pixel_width
> 0)
20557 glyph
->pixel_width
= it
->pixel_width
;
20558 glyph
->padding_p
= 0;
20562 /* Assure at least 1-pixel width. Otherwise, cursor can't
20563 be displayed correctly. */
20564 glyph
->pixel_width
= 1;
20565 glyph
->padding_p
= 1;
20567 glyph
->ascent
= it
->ascent
;
20568 glyph
->descent
= it
->descent
;
20569 glyph
->voffset
= it
->voffset
;
20570 glyph
->type
= CHAR_GLYPH
;
20571 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20572 glyph
->multibyte_p
= it
->multibyte_p
;
20573 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20574 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20575 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20576 || it
->phys_descent
> it
->descent
);
20577 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20578 glyph
->face_id
= it
->face_id
;
20579 glyph
->u
.ch
= it
->char_to_display
;
20580 glyph
->slice
= null_glyph_slice
;
20581 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20582 ++it
->glyph_row
->used
[area
];
20585 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20588 /* Store one glyph for the composition IT->cmp_it.id in
20589 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
20593 append_composite_glyph (it
)
20596 struct glyph
*glyph
;
20597 enum glyph_row_area area
= it
->area
;
20599 xassert (it
->glyph_row
);
20601 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20602 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20604 glyph
->charpos
= CHARPOS (it
->position
);
20605 glyph
->object
= it
->object
;
20606 glyph
->pixel_width
= it
->pixel_width
;
20607 glyph
->ascent
= it
->ascent
;
20608 glyph
->descent
= it
->descent
;
20609 glyph
->voffset
= it
->voffset
;
20610 glyph
->type
= COMPOSITE_GLYPH
;
20611 if (it
->cmp_it
.ch
< 0)
20613 glyph
->u
.cmp
.automatic
= 0;
20614 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20618 glyph
->u
.cmp
.automatic
= 1;
20619 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
20620 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
20621 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
20623 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20624 glyph
->multibyte_p
= it
->multibyte_p
;
20625 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20626 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20627 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20628 || it
->phys_descent
> it
->descent
);
20629 glyph
->padding_p
= 0;
20630 glyph
->glyph_not_available_p
= 0;
20631 glyph
->face_id
= it
->face_id
;
20632 glyph
->slice
= null_glyph_slice
;
20633 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20634 ++it
->glyph_row
->used
[area
];
20637 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20641 /* Change IT->ascent and IT->height according to the setting of
20645 take_vertical_position_into_account (it
)
20650 if (it
->voffset
< 0)
20651 /* Increase the ascent so that we can display the text higher
20653 it
->ascent
-= it
->voffset
;
20655 /* Increase the descent so that we can display the text lower
20657 it
->descent
+= it
->voffset
;
20662 /* Produce glyphs/get display metrics for the image IT is loaded with.
20663 See the description of struct display_iterator in dispextern.h for
20664 an overview of struct display_iterator. */
20667 produce_image_glyph (it
)
20672 int glyph_ascent
, crop
;
20673 struct glyph_slice slice
;
20675 xassert (it
->what
== IT_IMAGE
);
20677 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20679 /* Make sure X resources of the face is loaded. */
20680 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20682 if (it
->image_id
< 0)
20684 /* Fringe bitmap. */
20685 it
->ascent
= it
->phys_ascent
= 0;
20686 it
->descent
= it
->phys_descent
= 0;
20687 it
->pixel_width
= 0;
20692 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20694 /* Make sure X resources of the image is loaded. */
20695 prepare_image_for_display (it
->f
, img
);
20697 slice
.x
= slice
.y
= 0;
20698 slice
.width
= img
->width
;
20699 slice
.height
= img
->height
;
20701 if (INTEGERP (it
->slice
.x
))
20702 slice
.x
= XINT (it
->slice
.x
);
20703 else if (FLOATP (it
->slice
.x
))
20704 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20706 if (INTEGERP (it
->slice
.y
))
20707 slice
.y
= XINT (it
->slice
.y
);
20708 else if (FLOATP (it
->slice
.y
))
20709 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20711 if (INTEGERP (it
->slice
.width
))
20712 slice
.width
= XINT (it
->slice
.width
);
20713 else if (FLOATP (it
->slice
.width
))
20714 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20716 if (INTEGERP (it
->slice
.height
))
20717 slice
.height
= XINT (it
->slice
.height
);
20718 else if (FLOATP (it
->slice
.height
))
20719 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20721 if (slice
.x
>= img
->width
)
20722 slice
.x
= img
->width
;
20723 if (slice
.y
>= img
->height
)
20724 slice
.y
= img
->height
;
20725 if (slice
.x
+ slice
.width
>= img
->width
)
20726 slice
.width
= img
->width
- slice
.x
;
20727 if (slice
.y
+ slice
.height
> img
->height
)
20728 slice
.height
= img
->height
- slice
.y
;
20730 if (slice
.width
== 0 || slice
.height
== 0)
20733 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20735 it
->descent
= slice
.height
- glyph_ascent
;
20737 it
->descent
+= img
->vmargin
;
20738 if (slice
.y
+ slice
.height
== img
->height
)
20739 it
->descent
+= img
->vmargin
;
20740 it
->phys_descent
= it
->descent
;
20742 it
->pixel_width
= slice
.width
;
20744 it
->pixel_width
+= img
->hmargin
;
20745 if (slice
.x
+ slice
.width
== img
->width
)
20746 it
->pixel_width
+= img
->hmargin
;
20748 /* It's quite possible for images to have an ascent greater than
20749 their height, so don't get confused in that case. */
20750 if (it
->descent
< 0)
20755 if (face
->box
!= FACE_NO_BOX
)
20757 if (face
->box_line_width
> 0)
20760 it
->ascent
+= face
->box_line_width
;
20761 if (slice
.y
+ slice
.height
== img
->height
)
20762 it
->descent
+= face
->box_line_width
;
20765 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20766 it
->pixel_width
+= eabs (face
->box_line_width
);
20767 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20768 it
->pixel_width
+= eabs (face
->box_line_width
);
20771 take_vertical_position_into_account (it
);
20773 /* Automatically crop wide image glyphs at right edge so we can
20774 draw the cursor on same display row. */
20775 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20776 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20778 it
->pixel_width
-= crop
;
20779 slice
.width
-= crop
;
20784 struct glyph
*glyph
;
20785 enum glyph_row_area area
= it
->area
;
20787 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20788 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20790 glyph
->charpos
= CHARPOS (it
->position
);
20791 glyph
->object
= it
->object
;
20792 glyph
->pixel_width
= it
->pixel_width
;
20793 glyph
->ascent
= glyph_ascent
;
20794 glyph
->descent
= it
->descent
;
20795 glyph
->voffset
= it
->voffset
;
20796 glyph
->type
= IMAGE_GLYPH
;
20797 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20798 glyph
->multibyte_p
= it
->multibyte_p
;
20799 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20800 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20801 glyph
->overlaps_vertically_p
= 0;
20802 glyph
->padding_p
= 0;
20803 glyph
->glyph_not_available_p
= 0;
20804 glyph
->face_id
= it
->face_id
;
20805 glyph
->u
.img_id
= img
->id
;
20806 glyph
->slice
= slice
;
20807 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20808 ++it
->glyph_row
->used
[area
];
20811 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20816 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20817 of the glyph, WIDTH and HEIGHT are the width and height of the
20818 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20821 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20823 Lisp_Object object
;
20827 struct glyph
*glyph
;
20828 enum glyph_row_area area
= it
->area
;
20830 xassert (ascent
>= 0 && ascent
<= height
);
20832 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20833 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20835 glyph
->charpos
= CHARPOS (it
->position
);
20836 glyph
->object
= object
;
20837 glyph
->pixel_width
= width
;
20838 glyph
->ascent
= ascent
;
20839 glyph
->descent
= height
- ascent
;
20840 glyph
->voffset
= it
->voffset
;
20841 glyph
->type
= STRETCH_GLYPH
;
20842 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20843 glyph
->multibyte_p
= it
->multibyte_p
;
20844 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20845 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20846 glyph
->overlaps_vertically_p
= 0;
20847 glyph
->padding_p
= 0;
20848 glyph
->glyph_not_available_p
= 0;
20849 glyph
->face_id
= it
->face_id
;
20850 glyph
->u
.stretch
.ascent
= ascent
;
20851 glyph
->u
.stretch
.height
= height
;
20852 glyph
->slice
= null_glyph_slice
;
20853 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20854 ++it
->glyph_row
->used
[area
];
20857 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20861 /* Produce a stretch glyph for iterator IT. IT->object is the value
20862 of the glyph property displayed. The value must be a list
20863 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20866 1. `:width WIDTH' specifies that the space should be WIDTH *
20867 canonical char width wide. WIDTH may be an integer or floating
20870 2. `:relative-width FACTOR' specifies that the width of the stretch
20871 should be computed from the width of the first character having the
20872 `glyph' property, and should be FACTOR times that width.
20874 3. `:align-to HPOS' specifies that the space should be wide enough
20875 to reach HPOS, a value in canonical character units.
20877 Exactly one of the above pairs must be present.
20879 4. `:height HEIGHT' specifies that the height of the stretch produced
20880 should be HEIGHT, measured in canonical character units.
20882 5. `:relative-height FACTOR' specifies that the height of the
20883 stretch should be FACTOR times the height of the characters having
20884 the glyph property.
20886 Either none or exactly one of 4 or 5 must be present.
20888 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20889 of the stretch should be used for the ascent of the stretch.
20890 ASCENT must be in the range 0 <= ASCENT <= 100. */
20893 produce_stretch_glyph (it
)
20896 /* (space :width WIDTH :height HEIGHT ...) */
20897 Lisp_Object prop
, plist
;
20898 int width
= 0, height
= 0, align_to
= -1;
20899 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20902 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20903 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20905 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20907 /* List should start with `space'. */
20908 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20909 plist
= XCDR (it
->object
);
20911 /* Compute the width of the stretch. */
20912 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20913 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20915 /* Absolute width `:width WIDTH' specified and valid. */
20916 zero_width_ok_p
= 1;
20919 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20922 /* Relative width `:relative-width FACTOR' specified and valid.
20923 Compute the width of the characters having the `glyph'
20926 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20929 if (it
->multibyte_p
)
20931 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20932 - IT_BYTEPOS (*it
));
20933 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20936 it2
.c
= *p
, it2
.len
= 1;
20938 it2
.glyph_row
= NULL
;
20939 it2
.what
= IT_CHARACTER
;
20940 x_produce_glyphs (&it2
);
20941 width
= NUMVAL (prop
) * it2
.pixel_width
;
20943 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20944 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20946 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20947 align_to
= (align_to
< 0
20949 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20950 else if (align_to
< 0)
20951 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20952 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20953 zero_width_ok_p
= 1;
20956 /* Nothing specified -> width defaults to canonical char width. */
20957 width
= FRAME_COLUMN_WIDTH (it
->f
);
20959 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20962 /* Compute height. */
20963 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20964 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20967 zero_height_ok_p
= 1;
20969 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20971 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20973 height
= FONT_HEIGHT (font
);
20975 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20978 /* Compute percentage of height used for ascent. If
20979 `:ascent ASCENT' is present and valid, use that. Otherwise,
20980 derive the ascent from the font in use. */
20981 if (prop
= Fplist_get (plist
, QCascent
),
20982 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20983 ascent
= height
* NUMVAL (prop
) / 100.0;
20984 else if (!NILP (prop
)
20985 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20986 ascent
= min (max (0, (int)tem
), height
);
20988 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20990 if (width
> 0 && it
->line_wrap
!= TRUNCATE
20991 && it
->current_x
+ width
> it
->last_visible_x
)
20992 width
= it
->last_visible_x
- it
->current_x
- 1;
20994 if (width
> 0 && height
> 0 && it
->glyph_row
)
20996 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20997 if (!STRINGP (object
))
20998 object
= it
->w
->buffer
;
20999 append_stretch_glyph (it
, object
, width
, height
, ascent
);
21002 it
->pixel_width
= width
;
21003 it
->ascent
= it
->phys_ascent
= ascent
;
21004 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
21005 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21007 take_vertical_position_into_account (it
);
21010 /* Calculate line-height and line-spacing properties.
21011 An integer value specifies explicit pixel value.
21012 A float value specifies relative value to current face height.
21013 A cons (float . face-name) specifies relative value to
21014 height of specified face font.
21016 Returns height in pixels, or nil. */
21020 calc_line_height_property (it
, val
, font
, boff
, override
)
21024 int boff
, override
;
21026 Lisp_Object face_name
= Qnil
;
21027 int ascent
, descent
, height
;
21029 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21034 face_name
= XCAR (val
);
21036 if (!NUMBERP (val
))
21037 val
= make_number (1);
21038 if (NILP (face_name
))
21040 height
= it
->ascent
+ it
->descent
;
21045 if (NILP (face_name
))
21047 font
= FRAME_FONT (it
->f
);
21048 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21050 else if (EQ (face_name
, Qt
))
21059 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21061 return make_number (-1);
21063 face
= FACE_FROM_ID (it
->f
, face_id
);
21066 return make_number (-1);
21067 boff
= font
->baseline_offset
;
21068 if (font
->vertical_centering
)
21069 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21072 ascent
= FONT_BASE (font
) + boff
;
21073 descent
= FONT_DESCENT (font
) - boff
;
21077 it
->override_ascent
= ascent
;
21078 it
->override_descent
= descent
;
21079 it
->override_boff
= boff
;
21082 height
= ascent
+ descent
;
21086 height
= (int)(XFLOAT_DATA (val
) * height
);
21087 else if (INTEGERP (val
))
21088 height
*= XINT (val
);
21090 return make_number (height
);
21095 Produce glyphs/get display metrics for the display element IT is
21096 loaded with. See the description of struct it in dispextern.h
21097 for an overview of struct it. */
21100 x_produce_glyphs (it
)
21103 int extra_line_spacing
= it
->extra_line_spacing
;
21105 it
->glyph_not_available_p
= 0;
21107 if (it
->what
== IT_CHARACTER
)
21111 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21112 struct font_metrics
*pcm
;
21113 int font_not_found_p
;
21114 int boff
; /* baseline offset */
21115 /* We may change it->multibyte_p upon unibyte<->multibyte
21116 conversion. So, save the current value now and restore it
21119 Note: It seems that we don't have to record multibyte_p in
21120 struct glyph because the character code itself tells whether
21121 or not the character is multibyte. Thus, in the future, we
21122 must consider eliminating the field `multibyte_p' in the
21124 int saved_multibyte_p
= it
->multibyte_p
;
21126 /* Maybe translate single-byte characters to multibyte, or the
21128 it
->char_to_display
= it
->c
;
21129 if (!ASCII_BYTE_P (it
->c
)
21130 && ! it
->multibyte_p
)
21132 if (SINGLE_BYTE_CHAR_P (it
->c
)
21133 && unibyte_display_via_language_environment
)
21135 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
21137 /* get_next_display_element assures that this decoding
21139 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
21140 it
->multibyte_p
= 1;
21141 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21143 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21147 /* Get font to use. Encode IT->char_to_display. */
21148 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21149 &char2b
, it
->multibyte_p
, 0);
21152 font_not_found_p
= font
== NULL
;
21153 if (font_not_found_p
)
21155 /* When no suitable font found, display an empty box based
21156 on the metrics of the font of the default face (or what
21158 struct face
*no_font_face
21159 = FACE_FROM_ID (it
->f
,
21160 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
21161 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
21162 font
= no_font_face
->font
;
21163 boff
= font
->baseline_offset
;
21167 boff
= font
->baseline_offset
;
21168 if (font
->vertical_centering
)
21169 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21172 if (it
->char_to_display
>= ' '
21173 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21175 /* Either unibyte or ASCII. */
21180 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21182 if (it
->override_ascent
>= 0)
21184 it
->ascent
= it
->override_ascent
;
21185 it
->descent
= it
->override_descent
;
21186 boff
= it
->override_boff
;
21190 it
->ascent
= FONT_BASE (font
) + boff
;
21191 it
->descent
= FONT_DESCENT (font
) - boff
;
21196 it
->phys_ascent
= pcm
->ascent
+ boff
;
21197 it
->phys_descent
= pcm
->descent
- boff
;
21198 it
->pixel_width
= pcm
->width
;
21202 it
->glyph_not_available_p
= 1;
21203 it
->phys_ascent
= it
->ascent
;
21204 it
->phys_descent
= it
->descent
;
21205 it
->pixel_width
= FONT_WIDTH (font
);
21208 if (it
->constrain_row_ascent_descent_p
)
21210 if (it
->descent
> it
->max_descent
)
21212 it
->ascent
+= it
->descent
- it
->max_descent
;
21213 it
->descent
= it
->max_descent
;
21215 if (it
->ascent
> it
->max_ascent
)
21217 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21218 it
->ascent
= it
->max_ascent
;
21220 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21221 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21222 extra_line_spacing
= 0;
21225 /* If this is a space inside a region of text with
21226 `space-width' property, change its width. */
21227 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21229 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21231 /* If face has a box, add the box thickness to the character
21232 height. If character has a box line to the left and/or
21233 right, add the box line width to the character's width. */
21234 if (face
->box
!= FACE_NO_BOX
)
21236 int thick
= face
->box_line_width
;
21240 it
->ascent
+= thick
;
21241 it
->descent
+= thick
;
21246 if (it
->start_of_box_run_p
)
21247 it
->pixel_width
+= thick
;
21248 if (it
->end_of_box_run_p
)
21249 it
->pixel_width
+= thick
;
21252 /* If face has an overline, add the height of the overline
21253 (1 pixel) and a 1 pixel margin to the character height. */
21254 if (face
->overline_p
)
21255 it
->ascent
+= overline_margin
;
21257 if (it
->constrain_row_ascent_descent_p
)
21259 if (it
->ascent
> it
->max_ascent
)
21260 it
->ascent
= it
->max_ascent
;
21261 if (it
->descent
> it
->max_descent
)
21262 it
->descent
= it
->max_descent
;
21265 take_vertical_position_into_account (it
);
21267 /* If we have to actually produce glyphs, do it. */
21272 /* Translate a space with a `space-width' property
21273 into a stretch glyph. */
21274 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21275 / FONT_HEIGHT (font
));
21276 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21277 it
->ascent
+ it
->descent
, ascent
);
21282 /* If characters with lbearing or rbearing are displayed
21283 in this line, record that fact in a flag of the
21284 glyph row. This is used to optimize X output code. */
21285 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21286 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21288 if (! stretched_p
&& it
->pixel_width
== 0)
21289 /* We assure that all visible glyphs have at least 1-pixel
21291 it
->pixel_width
= 1;
21293 else if (it
->char_to_display
== '\n')
21295 /* A newline has no width, but we need the height of the
21296 line. But if previous part of the line sets a height,
21297 don't increase that height */
21299 Lisp_Object height
;
21300 Lisp_Object total_height
= Qnil
;
21302 it
->override_ascent
= -1;
21303 it
->pixel_width
= 0;
21306 height
= get_it_property(it
, Qline_height
);
21307 /* Split (line-height total-height) list */
21309 && CONSP (XCDR (height
))
21310 && NILP (XCDR (XCDR (height
))))
21312 total_height
= XCAR (XCDR (height
));
21313 height
= XCAR (height
);
21315 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21317 if (it
->override_ascent
>= 0)
21319 it
->ascent
= it
->override_ascent
;
21320 it
->descent
= it
->override_descent
;
21321 boff
= it
->override_boff
;
21325 it
->ascent
= FONT_BASE (font
) + boff
;
21326 it
->descent
= FONT_DESCENT (font
) - boff
;
21329 if (EQ (height
, Qt
))
21331 if (it
->descent
> it
->max_descent
)
21333 it
->ascent
+= it
->descent
- it
->max_descent
;
21334 it
->descent
= it
->max_descent
;
21336 if (it
->ascent
> it
->max_ascent
)
21338 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21339 it
->ascent
= it
->max_ascent
;
21341 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21342 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21343 it
->constrain_row_ascent_descent_p
= 1;
21344 extra_line_spacing
= 0;
21348 Lisp_Object spacing
;
21350 it
->phys_ascent
= it
->ascent
;
21351 it
->phys_descent
= it
->descent
;
21353 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21354 && face
->box
!= FACE_NO_BOX
21355 && face
->box_line_width
> 0)
21357 it
->ascent
+= face
->box_line_width
;
21358 it
->descent
+= face
->box_line_width
;
21361 && XINT (height
) > it
->ascent
+ it
->descent
)
21362 it
->ascent
= XINT (height
) - it
->descent
;
21364 if (!NILP (total_height
))
21365 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21368 spacing
= get_it_property(it
, Qline_spacing
);
21369 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21371 if (INTEGERP (spacing
))
21373 extra_line_spacing
= XINT (spacing
);
21374 if (!NILP (total_height
))
21375 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21379 else if (it
->char_to_display
== '\t')
21381 if (font
->space_width
> 0)
21383 int tab_width
= it
->tab_width
* font
->space_width
;
21384 int x
= it
->current_x
+ it
->continuation_lines_width
;
21385 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21387 /* If the distance from the current position to the next tab
21388 stop is less than a space character width, use the
21389 tab stop after that. */
21390 if (next_tab_x
- x
< font
->space_width
)
21391 next_tab_x
+= tab_width
;
21393 it
->pixel_width
= next_tab_x
- x
;
21395 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21396 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21400 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21401 it
->ascent
+ it
->descent
, it
->ascent
);
21406 it
->pixel_width
= 0;
21412 /* A multi-byte character. Assume that the display width of the
21413 character is the width of the character multiplied by the
21414 width of the font. */
21416 /* If we found a font, this font should give us the right
21417 metrics. If we didn't find a font, use the frame's
21418 default font and calculate the width of the character by
21419 multiplying the width of font by the width of the
21422 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21424 if (font_not_found_p
|| !pcm
)
21426 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21428 if (char_width
== 0)
21429 /* This is a non spacing character. But, as we are
21430 going to display an empty box, the box must occupy
21431 at least one column. */
21433 it
->glyph_not_available_p
= 1;
21434 it
->pixel_width
= font
->space_width
* char_width
;
21435 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21436 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21440 it
->pixel_width
= pcm
->width
;
21441 it
->phys_ascent
= pcm
->ascent
+ boff
;
21442 it
->phys_descent
= pcm
->descent
- boff
;
21444 && (pcm
->lbearing
< 0
21445 || pcm
->rbearing
> pcm
->width
))
21446 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21449 it
->ascent
= FONT_BASE (font
) + boff
;
21450 it
->descent
= FONT_DESCENT (font
) - boff
;
21451 if (face
->box
!= FACE_NO_BOX
)
21453 int thick
= face
->box_line_width
;
21457 it
->ascent
+= thick
;
21458 it
->descent
+= thick
;
21463 if (it
->start_of_box_run_p
)
21464 it
->pixel_width
+= thick
;
21465 if (it
->end_of_box_run_p
)
21466 it
->pixel_width
+= thick
;
21469 /* If face has an overline, add the height of the overline
21470 (1 pixel) and a 1 pixel margin to the character height. */
21471 if (face
->overline_p
)
21472 it
->ascent
+= overline_margin
;
21474 take_vertical_position_into_account (it
);
21476 if (it
->ascent
< 0)
21478 if (it
->descent
< 0)
21483 if (it
->pixel_width
== 0)
21484 /* We assure that all visible glyphs have at least 1-pixel
21486 it
->pixel_width
= 1;
21488 it
->multibyte_p
= saved_multibyte_p
;
21490 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
21492 /* A static composition.
21494 Note: A composition is represented as one glyph in the
21495 glyph matrix. There are no padding glyphs.
21497 Important note: pixel_width, ascent, and descent are the
21498 values of what is drawn by draw_glyphs (i.e. the values of
21499 the overall glyphs composed). */
21500 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21501 int boff
; /* baseline offset */
21502 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
21503 int glyph_len
= cmp
->glyph_len
;
21504 struct font
*font
= face
->font
;
21508 /* If we have not yet calculated pixel size data of glyphs of
21509 the composition for the current face font, calculate them
21510 now. Theoretically, we have to check all fonts for the
21511 glyphs, but that requires much time and memory space. So,
21512 here we check only the font of the first glyph. This may
21513 lead to incorrect display, but it's very rare, and C-l
21514 (recenter-top-bottom) can correct the display anyway. */
21515 if (! cmp
->font
|| cmp
->font
!= font
)
21517 /* Ascent and descent of the font of the first character
21518 of this composition (adjusted by baseline offset).
21519 Ascent and descent of overall glyphs should not be less
21520 than these, respectively. */
21521 int font_ascent
, font_descent
, font_height
;
21522 /* Bounding box of the overall glyphs. */
21523 int leftmost
, rightmost
, lowest
, highest
;
21524 int lbearing
, rbearing
;
21525 int i
, width
, ascent
, descent
;
21526 int left_padded
= 0, right_padded
= 0;
21529 struct font_metrics
*pcm
;
21530 int font_not_found_p
;
21533 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21534 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21536 if (glyph_len
< cmp
->glyph_len
)
21538 for (i
= 0; i
< glyph_len
; i
++)
21540 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21542 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21547 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21548 : IT_CHARPOS (*it
));
21549 /* If no suitable font is found, use the default font. */
21550 font_not_found_p
= font
== NULL
;
21551 if (font_not_found_p
)
21553 face
= face
->ascii_face
;
21556 boff
= font
->baseline_offset
;
21557 if (font
->vertical_centering
)
21558 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21559 font_ascent
= FONT_BASE (font
) + boff
;
21560 font_descent
= FONT_DESCENT (font
) - boff
;
21561 font_height
= FONT_HEIGHT (font
);
21563 cmp
->font
= (void *) font
;
21566 if (! font_not_found_p
)
21568 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21569 &char2b
, it
->multibyte_p
, 0);
21570 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21573 /* Initialize the bounding box. */
21576 width
= pcm
->width
;
21577 ascent
= pcm
->ascent
;
21578 descent
= pcm
->descent
;
21579 lbearing
= pcm
->lbearing
;
21580 rbearing
= pcm
->rbearing
;
21584 width
= FONT_WIDTH (font
);
21585 ascent
= FONT_BASE (font
);
21586 descent
= FONT_DESCENT (font
);
21593 lowest
= - descent
+ boff
;
21594 highest
= ascent
+ boff
;
21596 if (! font_not_found_p
21597 && font
->default_ascent
21598 && CHAR_TABLE_P (Vuse_default_ascent
)
21599 && !NILP (Faref (Vuse_default_ascent
,
21600 make_number (it
->char_to_display
))))
21601 highest
= font
->default_ascent
+ boff
;
21603 /* Draw the first glyph at the normal position. It may be
21604 shifted to right later if some other glyphs are drawn
21606 cmp
->offsets
[i
* 2] = 0;
21607 cmp
->offsets
[i
* 2 + 1] = boff
;
21608 cmp
->lbearing
= lbearing
;
21609 cmp
->rbearing
= rbearing
;
21611 /* Set cmp->offsets for the remaining glyphs. */
21612 for (i
++; i
< glyph_len
; i
++)
21614 int left
, right
, btm
, top
;
21615 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21617 struct face
*this_face
;
21622 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21623 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21624 font
= this_face
->font
;
21630 this_boff
= font
->baseline_offset
;
21631 if (font
->vertical_centering
)
21632 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21633 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21634 &char2b
, it
->multibyte_p
, 0);
21635 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21638 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21641 width
= pcm
->width
;
21642 ascent
= pcm
->ascent
;
21643 descent
= pcm
->descent
;
21644 lbearing
= pcm
->lbearing
;
21645 rbearing
= pcm
->rbearing
;
21646 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21648 /* Relative composition with or without
21649 alternate chars. */
21650 left
= (leftmost
+ rightmost
- width
) / 2;
21651 btm
= - descent
+ boff
;
21652 if (font
->relative_compose
21653 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21654 || NILP (Faref (Vignore_relative_composition
,
21655 make_number (ch
)))))
21658 if (- descent
>= font
->relative_compose
)
21659 /* One extra pixel between two glyphs. */
21661 else if (ascent
<= 0)
21662 /* One extra pixel between two glyphs. */
21663 btm
= lowest
- 1 - ascent
- descent
;
21668 /* A composition rule is specified by an integer
21669 value that encodes global and new reference
21670 points (GREF and NREF). GREF and NREF are
21671 specified by numbers as below:
21673 0---1---2 -- ascent
21677 9--10--11 -- center
21679 ---3---4---5--- baseline
21681 6---7---8 -- descent
21683 int rule
= COMPOSITION_RULE (cmp
, i
);
21684 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21686 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21687 grefx
= gref
% 3, nrefx
= nref
% 3;
21688 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21690 xoff
= font_height
* (xoff
- 128) / 256;
21692 yoff
= font_height
* (yoff
- 128) / 256;
21695 + grefx
* (rightmost
- leftmost
) / 2
21696 - nrefx
* width
/ 2
21699 btm
= ((grefy
== 0 ? highest
21701 : grefy
== 2 ? lowest
21702 : (highest
+ lowest
) / 2)
21703 - (nrefy
== 0 ? ascent
+ descent
21704 : nrefy
== 1 ? descent
- boff
21706 : (ascent
+ descent
) / 2)
21710 cmp
->offsets
[i
* 2] = left
;
21711 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21713 /* Update the bounding box of the overall glyphs. */
21716 right
= left
+ width
;
21717 if (left
< leftmost
)
21719 if (right
> rightmost
)
21722 top
= btm
+ descent
+ ascent
;
21728 if (cmp
->lbearing
> left
+ lbearing
)
21729 cmp
->lbearing
= left
+ lbearing
;
21730 if (cmp
->rbearing
< left
+ rbearing
)
21731 cmp
->rbearing
= left
+ rbearing
;
21735 /* If there are glyphs whose x-offsets are negative,
21736 shift all glyphs to the right and make all x-offsets
21740 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21741 cmp
->offsets
[i
* 2] -= leftmost
;
21742 rightmost
-= leftmost
;
21743 cmp
->lbearing
-= leftmost
;
21744 cmp
->rbearing
-= leftmost
;
21747 if (left_padded
&& cmp
->lbearing
< 0)
21749 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21750 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21751 rightmost
-= cmp
->lbearing
;
21752 cmp
->rbearing
-= cmp
->lbearing
;
21755 if (right_padded
&& rightmost
< cmp
->rbearing
)
21757 rightmost
= cmp
->rbearing
;
21760 cmp
->pixel_width
= rightmost
;
21761 cmp
->ascent
= highest
;
21762 cmp
->descent
= - lowest
;
21763 if (cmp
->ascent
< font_ascent
)
21764 cmp
->ascent
= font_ascent
;
21765 if (cmp
->descent
< font_descent
)
21766 cmp
->descent
= font_descent
;
21770 && (cmp
->lbearing
< 0
21771 || cmp
->rbearing
> cmp
->pixel_width
))
21772 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21774 it
->pixel_width
= cmp
->pixel_width
;
21775 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21776 it
->descent
= it
->phys_descent
= cmp
->descent
;
21777 if (face
->box
!= FACE_NO_BOX
)
21779 int thick
= face
->box_line_width
;
21783 it
->ascent
+= thick
;
21784 it
->descent
+= thick
;
21789 if (it
->start_of_box_run_p
)
21790 it
->pixel_width
+= thick
;
21791 if (it
->end_of_box_run_p
)
21792 it
->pixel_width
+= thick
;
21795 /* If face has an overline, add the height of the overline
21796 (1 pixel) and a 1 pixel margin to the character height. */
21797 if (face
->overline_p
)
21798 it
->ascent
+= overline_margin
;
21800 take_vertical_position_into_account (it
);
21801 if (it
->ascent
< 0)
21803 if (it
->descent
< 0)
21807 append_composite_glyph (it
);
21809 else if (it
->what
== IT_COMPOSITION
)
21811 /* A dynamic (automatic) composition. */
21812 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21813 Lisp_Object gstring
;
21814 struct font_metrics metrics
;
21816 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
21818 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
21821 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
21822 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21823 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
21824 it
->descent
= it
->phys_descent
= metrics
.descent
;
21825 if (face
->box
!= FACE_NO_BOX
)
21827 int thick
= face
->box_line_width
;
21831 it
->ascent
+= thick
;
21832 it
->descent
+= thick
;
21837 if (it
->start_of_box_run_p
)
21838 it
->pixel_width
+= thick
;
21839 if (it
->end_of_box_run_p
)
21840 it
->pixel_width
+= thick
;
21842 /* If face has an overline, add the height of the overline
21843 (1 pixel) and a 1 pixel margin to the character height. */
21844 if (face
->overline_p
)
21845 it
->ascent
+= overline_margin
;
21846 take_vertical_position_into_account (it
);
21847 if (it
->ascent
< 0)
21849 if (it
->descent
< 0)
21853 append_composite_glyph (it
);
21855 else if (it
->what
== IT_IMAGE
)
21856 produce_image_glyph (it
);
21857 else if (it
->what
== IT_STRETCH
)
21858 produce_stretch_glyph (it
);
21860 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21861 because this isn't true for images with `:ascent 100'. */
21862 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21863 if (it
->area
== TEXT_AREA
)
21864 it
->current_x
+= it
->pixel_width
;
21866 if (extra_line_spacing
> 0)
21868 it
->descent
+= extra_line_spacing
;
21869 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21870 it
->max_extra_line_spacing
= extra_line_spacing
;
21873 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21874 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21875 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21876 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21880 Output LEN glyphs starting at START at the nominal cursor position.
21881 Advance the nominal cursor over the text. The global variable
21882 updated_window contains the window being updated, updated_row is
21883 the glyph row being updated, and updated_area is the area of that
21884 row being updated. */
21887 x_write_glyphs (start
, len
)
21888 struct glyph
*start
;
21893 xassert (updated_window
&& updated_row
);
21896 /* Write glyphs. */
21898 hpos
= start
- updated_row
->glyphs
[updated_area
];
21899 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21900 updated_row
, updated_area
,
21902 DRAW_NORMAL_TEXT
, 0);
21904 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21905 if (updated_area
== TEXT_AREA
21906 && updated_window
->phys_cursor_on_p
21907 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21908 && updated_window
->phys_cursor
.hpos
>= hpos
21909 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21910 updated_window
->phys_cursor_on_p
= 0;
21914 /* Advance the output cursor. */
21915 output_cursor
.hpos
+= len
;
21916 output_cursor
.x
= x
;
21921 Insert LEN glyphs from START at the nominal cursor position. */
21924 x_insert_glyphs (start
, len
)
21925 struct glyph
*start
;
21930 int line_height
, shift_by_width
, shifted_region_width
;
21931 struct glyph_row
*row
;
21932 struct glyph
*glyph
;
21933 int frame_x
, frame_y
;
21936 xassert (updated_window
&& updated_row
);
21938 w
= updated_window
;
21939 f
= XFRAME (WINDOW_FRAME (w
));
21941 /* Get the height of the line we are in. */
21943 line_height
= row
->height
;
21945 /* Get the width of the glyphs to insert. */
21946 shift_by_width
= 0;
21947 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21948 shift_by_width
+= glyph
->pixel_width
;
21950 /* Get the width of the region to shift right. */
21951 shifted_region_width
= (window_box_width (w
, updated_area
)
21956 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21957 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21959 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21960 line_height
, shift_by_width
);
21962 /* Write the glyphs. */
21963 hpos
= start
- row
->glyphs
[updated_area
];
21964 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21966 DRAW_NORMAL_TEXT
, 0);
21968 /* Advance the output cursor. */
21969 output_cursor
.hpos
+= len
;
21970 output_cursor
.x
+= shift_by_width
;
21976 Erase the current text line from the nominal cursor position
21977 (inclusive) to pixel column TO_X (exclusive). The idea is that
21978 everything from TO_X onward is already erased.
21980 TO_X is a pixel position relative to updated_area of
21981 updated_window. TO_X == -1 means clear to the end of this area. */
21984 x_clear_end_of_line (to_x
)
21988 struct window
*w
= updated_window
;
21989 int max_x
, min_y
, max_y
;
21990 int from_x
, from_y
, to_y
;
21992 xassert (updated_window
&& updated_row
);
21993 f
= XFRAME (w
->frame
);
21995 if (updated_row
->full_width_p
)
21996 max_x
= WINDOW_TOTAL_WIDTH (w
);
21998 max_x
= window_box_width (w
, updated_area
);
21999 max_y
= window_text_bottom_y (w
);
22001 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
22002 of window. For TO_X > 0, truncate to end of drawing area. */
22008 to_x
= min (to_x
, max_x
);
22010 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
22012 /* Notice if the cursor will be cleared by this operation. */
22013 if (!updated_row
->full_width_p
)
22014 notice_overwritten_cursor (w
, updated_area
,
22015 output_cursor
.x
, -1,
22017 MATRIX_ROW_BOTTOM_Y (updated_row
));
22019 from_x
= output_cursor
.x
;
22021 /* Translate to frame coordinates. */
22022 if (updated_row
->full_width_p
)
22024 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
22025 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
22029 int area_left
= window_box_left (w
, updated_area
);
22030 from_x
+= area_left
;
22034 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22035 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22036 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22038 /* Prevent inadvertently clearing to end of the X window. */
22039 if (to_x
> from_x
&& to_y
> from_y
)
22042 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22043 to_x
- from_x
, to_y
- from_y
);
22048 #endif /* HAVE_WINDOW_SYSTEM */
22052 /***********************************************************************
22054 ***********************************************************************/
22056 /* Value is the internal representation of the specified cursor type
22057 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22058 of the bar cursor. */
22060 static enum text_cursor_kinds
22061 get_specified_cursor_type (arg
, width
)
22065 enum text_cursor_kinds type
;
22070 if (EQ (arg
, Qbox
))
22071 return FILLED_BOX_CURSOR
;
22073 if (EQ (arg
, Qhollow
))
22074 return HOLLOW_BOX_CURSOR
;
22076 if (EQ (arg
, Qbar
))
22083 && EQ (XCAR (arg
), Qbar
)
22084 && INTEGERP (XCDR (arg
))
22085 && XINT (XCDR (arg
)) >= 0)
22087 *width
= XINT (XCDR (arg
));
22091 if (EQ (arg
, Qhbar
))
22094 return HBAR_CURSOR
;
22098 && EQ (XCAR (arg
), Qhbar
)
22099 && INTEGERP (XCDR (arg
))
22100 && XINT (XCDR (arg
)) >= 0)
22102 *width
= XINT (XCDR (arg
));
22103 return HBAR_CURSOR
;
22106 /* Treat anything unknown as "hollow box cursor".
22107 It was bad to signal an error; people have trouble fixing
22108 .Xdefaults with Emacs, when it has something bad in it. */
22109 type
= HOLLOW_BOX_CURSOR
;
22114 /* Set the default cursor types for specified frame. */
22116 set_frame_cursor_types (f
, arg
)
22123 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22124 FRAME_CURSOR_WIDTH (f
) = width
;
22126 /* By default, set up the blink-off state depending on the on-state. */
22128 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22131 FRAME_BLINK_OFF_CURSOR (f
)
22132 = get_specified_cursor_type (XCDR (tem
), &width
);
22133 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22136 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22140 /* Return the cursor we want to be displayed in window W. Return
22141 width of bar/hbar cursor through WIDTH arg. Return with
22142 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22143 (i.e. if the `system caret' should track this cursor).
22145 In a mini-buffer window, we want the cursor only to appear if we
22146 are reading input from this window. For the selected window, we
22147 want the cursor type given by the frame parameter or buffer local
22148 setting of cursor-type. If explicitly marked off, draw no cursor.
22149 In all other cases, we want a hollow box cursor. */
22151 static enum text_cursor_kinds
22152 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22154 struct glyph
*glyph
;
22156 int *active_cursor
;
22158 struct frame
*f
= XFRAME (w
->frame
);
22159 struct buffer
*b
= XBUFFER (w
->buffer
);
22160 int cursor_type
= DEFAULT_CURSOR
;
22161 Lisp_Object alt_cursor
;
22162 int non_selected
= 0;
22164 *active_cursor
= 1;
22167 if (cursor_in_echo_area
22168 && FRAME_HAS_MINIBUF_P (f
)
22169 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22171 if (w
== XWINDOW (echo_area_window
))
22173 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22175 *width
= FRAME_CURSOR_WIDTH (f
);
22176 return FRAME_DESIRED_CURSOR (f
);
22179 return get_specified_cursor_type (b
->cursor_type
, width
);
22182 *active_cursor
= 0;
22186 /* Detect a nonselected window or nonselected frame. */
22187 else if (w
!= XWINDOW (f
->selected_window
)
22188 #ifdef HAVE_WINDOW_SYSTEM
22189 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22193 *active_cursor
= 0;
22195 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22201 /* Never display a cursor in a window in which cursor-type is nil. */
22202 if (NILP (b
->cursor_type
))
22205 /* Get the normal cursor type for this window. */
22206 if (EQ (b
->cursor_type
, Qt
))
22208 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22209 *width
= FRAME_CURSOR_WIDTH (f
);
22212 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22214 /* Use cursor-in-non-selected-windows instead
22215 for non-selected window or frame. */
22218 alt_cursor
= b
->cursor_in_non_selected_windows
;
22219 if (!EQ (Qt
, alt_cursor
))
22220 return get_specified_cursor_type (alt_cursor
, width
);
22221 /* t means modify the normal cursor type. */
22222 if (cursor_type
== FILLED_BOX_CURSOR
)
22223 cursor_type
= HOLLOW_BOX_CURSOR
;
22224 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22226 return cursor_type
;
22229 /* Use normal cursor if not blinked off. */
22230 if (!w
->cursor_off_p
)
22232 #ifdef HAVE_WINDOW_SYSTEM
22233 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22235 if (cursor_type
== FILLED_BOX_CURSOR
)
22237 /* Using a block cursor on large images can be very annoying.
22238 So use a hollow cursor for "large" images.
22239 If image is not transparent (no mask), also use hollow cursor. */
22240 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22241 if (img
!= NULL
&& IMAGEP (img
->spec
))
22243 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22244 where N = size of default frame font size.
22245 This should cover most of the "tiny" icons people may use. */
22247 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22248 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22249 cursor_type
= HOLLOW_BOX_CURSOR
;
22252 else if (cursor_type
!= NO_CURSOR
)
22254 /* Display current only supports BOX and HOLLOW cursors for images.
22255 So for now, unconditionally use a HOLLOW cursor when cursor is
22256 not a solid box cursor. */
22257 cursor_type
= HOLLOW_BOX_CURSOR
;
22261 return cursor_type
;
22264 /* Cursor is blinked off, so determine how to "toggle" it. */
22266 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22267 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22268 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22270 /* Then see if frame has specified a specific blink off cursor type. */
22271 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22273 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22274 return FRAME_BLINK_OFF_CURSOR (f
);
22278 /* Some people liked having a permanently visible blinking cursor,
22279 while others had very strong opinions against it. So it was
22280 decided to remove it. KFS 2003-09-03 */
22282 /* Finally perform built-in cursor blinking:
22283 filled box <-> hollow box
22284 wide [h]bar <-> narrow [h]bar
22285 narrow [h]bar <-> no cursor
22286 other type <-> no cursor */
22288 if (cursor_type
== FILLED_BOX_CURSOR
)
22289 return HOLLOW_BOX_CURSOR
;
22291 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22294 return cursor_type
;
22302 #ifdef HAVE_WINDOW_SYSTEM
22304 /* Notice when the text cursor of window W has been completely
22305 overwritten by a drawing operation that outputs glyphs in AREA
22306 starting at X0 and ending at X1 in the line starting at Y0 and
22307 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22308 the rest of the line after X0 has been written. Y coordinates
22309 are window-relative. */
22312 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22314 enum glyph_row_area area
;
22315 int x0
, y0
, x1
, y1
;
22317 int cx0
, cx1
, cy0
, cy1
;
22318 struct glyph_row
*row
;
22320 if (!w
->phys_cursor_on_p
)
22322 if (area
!= TEXT_AREA
)
22325 if (w
->phys_cursor
.vpos
< 0
22326 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22327 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22328 !(row
->enabled_p
&& row
->displays_text_p
)))
22331 if (row
->cursor_in_fringe_p
)
22333 row
->cursor_in_fringe_p
= 0;
22334 draw_fringe_bitmap (w
, row
, 0);
22335 w
->phys_cursor_on_p
= 0;
22339 cx0
= w
->phys_cursor
.x
;
22340 cx1
= cx0
+ w
->phys_cursor_width
;
22341 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22344 /* The cursor image will be completely removed from the
22345 screen if the output area intersects the cursor area in
22346 y-direction. When we draw in [y0 y1[, and some part of
22347 the cursor is at y < y0, that part must have been drawn
22348 before. When scrolling, the cursor is erased before
22349 actually scrolling, so we don't come here. When not
22350 scrolling, the rows above the old cursor row must have
22351 changed, and in this case these rows must have written
22352 over the cursor image.
22354 Likewise if part of the cursor is below y1, with the
22355 exception of the cursor being in the first blank row at
22356 the buffer and window end because update_text_area
22357 doesn't draw that row. (Except when it does, but
22358 that's handled in update_text_area.) */
22360 cy0
= w
->phys_cursor
.y
;
22361 cy1
= cy0
+ w
->phys_cursor_height
;
22362 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22365 w
->phys_cursor_on_p
= 0;
22368 #endif /* HAVE_WINDOW_SYSTEM */
22371 /************************************************************************
22373 ************************************************************************/
22375 #ifdef HAVE_WINDOW_SYSTEM
22378 Fix the display of area AREA of overlapping row ROW in window W
22379 with respect to the overlapping part OVERLAPS. */
22382 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22384 struct glyph_row
*row
;
22385 enum glyph_row_area area
;
22393 for (i
= 0; i
< row
->used
[area
];)
22395 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22397 int start
= i
, start_x
= x
;
22401 x
+= row
->glyphs
[area
][i
].pixel_width
;
22404 while (i
< row
->used
[area
]
22405 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22407 draw_glyphs (w
, start_x
, row
, area
,
22409 DRAW_NORMAL_TEXT
, overlaps
);
22413 x
+= row
->glyphs
[area
][i
].pixel_width
;
22423 Draw the cursor glyph of window W in glyph row ROW. See the
22424 comment of draw_glyphs for the meaning of HL. */
22427 draw_phys_cursor_glyph (w
, row
, hl
)
22429 struct glyph_row
*row
;
22430 enum draw_glyphs_face hl
;
22432 /* If cursor hpos is out of bounds, don't draw garbage. This can
22433 happen in mini-buffer windows when switching between echo area
22434 glyphs and mini-buffer. */
22435 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22437 int on_p
= w
->phys_cursor_on_p
;
22439 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22440 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22442 w
->phys_cursor_on_p
= on_p
;
22444 if (hl
== DRAW_CURSOR
)
22445 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22446 /* When we erase the cursor, and ROW is overlapped by other
22447 rows, make sure that these overlapping parts of other rows
22449 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22451 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22453 if (row
> w
->current_matrix
->rows
22454 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22455 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22456 OVERLAPS_ERASED_CURSOR
);
22458 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22459 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22460 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22461 OVERLAPS_ERASED_CURSOR
);
22468 Erase the image of a cursor of window W from the screen. */
22471 erase_phys_cursor (w
)
22474 struct frame
*f
= XFRAME (w
->frame
);
22475 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22476 int hpos
= w
->phys_cursor
.hpos
;
22477 int vpos
= w
->phys_cursor
.vpos
;
22478 int mouse_face_here_p
= 0;
22479 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22480 struct glyph_row
*cursor_row
;
22481 struct glyph
*cursor_glyph
;
22482 enum draw_glyphs_face hl
;
22484 /* No cursor displayed or row invalidated => nothing to do on the
22486 if (w
->phys_cursor_type
== NO_CURSOR
)
22487 goto mark_cursor_off
;
22489 /* VPOS >= active_glyphs->nrows means that window has been resized.
22490 Don't bother to erase the cursor. */
22491 if (vpos
>= active_glyphs
->nrows
)
22492 goto mark_cursor_off
;
22494 /* If row containing cursor is marked invalid, there is nothing we
22496 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22497 if (!cursor_row
->enabled_p
)
22498 goto mark_cursor_off
;
22500 /* If line spacing is > 0, old cursor may only be partially visible in
22501 window after split-window. So adjust visible height. */
22502 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22503 window_text_bottom_y (w
) - cursor_row
->y
);
22505 /* If row is completely invisible, don't attempt to delete a cursor which
22506 isn't there. This can happen if cursor is at top of a window, and
22507 we switch to a buffer with a header line in that window. */
22508 if (cursor_row
->visible_height
<= 0)
22509 goto mark_cursor_off
;
22511 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22512 if (cursor_row
->cursor_in_fringe_p
)
22514 cursor_row
->cursor_in_fringe_p
= 0;
22515 draw_fringe_bitmap (w
, cursor_row
, 0);
22516 goto mark_cursor_off
;
22519 /* This can happen when the new row is shorter than the old one.
22520 In this case, either draw_glyphs or clear_end_of_line
22521 should have cleared the cursor. Note that we wouldn't be
22522 able to erase the cursor in this case because we don't have a
22523 cursor glyph at hand. */
22524 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22525 goto mark_cursor_off
;
22527 /* If the cursor is in the mouse face area, redisplay that when
22528 we clear the cursor. */
22529 if (! NILP (dpyinfo
->mouse_face_window
)
22530 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22531 && (vpos
> dpyinfo
->mouse_face_beg_row
22532 || (vpos
== dpyinfo
->mouse_face_beg_row
22533 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22534 && (vpos
< dpyinfo
->mouse_face_end_row
22535 || (vpos
== dpyinfo
->mouse_face_end_row
22536 && hpos
< dpyinfo
->mouse_face_end_col
))
22537 /* Don't redraw the cursor's spot in mouse face if it is at the
22538 end of a line (on a newline). The cursor appears there, but
22539 mouse highlighting does not. */
22540 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22541 mouse_face_here_p
= 1;
22543 /* Maybe clear the display under the cursor. */
22544 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22547 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22550 cursor_glyph
= get_phys_cursor_glyph (w
);
22551 if (cursor_glyph
== NULL
)
22552 goto mark_cursor_off
;
22554 width
= cursor_glyph
->pixel_width
;
22555 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22556 x
= w
->phys_cursor
.x
;
22558 width
-= left_x
- x
;
22559 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22560 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22561 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22564 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22567 /* Erase the cursor by redrawing the character underneath it. */
22568 if (mouse_face_here_p
)
22569 hl
= DRAW_MOUSE_FACE
;
22571 hl
= DRAW_NORMAL_TEXT
;
22572 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22575 w
->phys_cursor_on_p
= 0;
22576 w
->phys_cursor_type
= NO_CURSOR
;
22581 Display or clear cursor of window W. If ON is zero, clear the
22582 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22583 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22586 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22588 int on
, hpos
, vpos
, x
, y
;
22590 struct frame
*f
= XFRAME (w
->frame
);
22591 int new_cursor_type
;
22592 int new_cursor_width
;
22594 struct glyph_row
*glyph_row
;
22595 struct glyph
*glyph
;
22597 /* This is pointless on invisible frames, and dangerous on garbaged
22598 windows and frames; in the latter case, the frame or window may
22599 be in the midst of changing its size, and x and y may be off the
22601 if (! FRAME_VISIBLE_P (f
)
22602 || FRAME_GARBAGED_P (f
)
22603 || vpos
>= w
->current_matrix
->nrows
22604 || hpos
>= w
->current_matrix
->matrix_w
)
22607 /* If cursor is off and we want it off, return quickly. */
22608 if (!on
&& !w
->phys_cursor_on_p
)
22611 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22612 /* If cursor row is not enabled, we don't really know where to
22613 display the cursor. */
22614 if (!glyph_row
->enabled_p
)
22616 w
->phys_cursor_on_p
= 0;
22621 if (!glyph_row
->exact_window_width_line_p
22622 || hpos
< glyph_row
->used
[TEXT_AREA
])
22623 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22625 xassert (interrupt_input_blocked
);
22627 /* Set new_cursor_type to the cursor we want to be displayed. */
22628 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22629 &new_cursor_width
, &active_cursor
);
22631 /* If cursor is currently being shown and we don't want it to be or
22632 it is in the wrong place, or the cursor type is not what we want,
22634 if (w
->phys_cursor_on_p
22636 || w
->phys_cursor
.x
!= x
22637 || w
->phys_cursor
.y
!= y
22638 || new_cursor_type
!= w
->phys_cursor_type
22639 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22640 && new_cursor_width
!= w
->phys_cursor_width
)))
22641 erase_phys_cursor (w
);
22643 /* Don't check phys_cursor_on_p here because that flag is only set
22644 to zero in some cases where we know that the cursor has been
22645 completely erased, to avoid the extra work of erasing the cursor
22646 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22647 still not be visible, or it has only been partly erased. */
22650 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22651 w
->phys_cursor_height
= glyph_row
->height
;
22653 /* Set phys_cursor_.* before x_draw_.* is called because some
22654 of them may need the information. */
22655 w
->phys_cursor
.x
= x
;
22656 w
->phys_cursor
.y
= glyph_row
->y
;
22657 w
->phys_cursor
.hpos
= hpos
;
22658 w
->phys_cursor
.vpos
= vpos
;
22661 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22662 new_cursor_type
, new_cursor_width
,
22663 on
, active_cursor
);
22667 /* Switch the display of W's cursor on or off, according to the value
22674 update_window_cursor (w
, on
)
22678 /* Don't update cursor in windows whose frame is in the process
22679 of being deleted. */
22680 if (w
->current_matrix
)
22683 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22684 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22690 /* Call update_window_cursor with parameter ON_P on all leaf windows
22691 in the window tree rooted at W. */
22694 update_cursor_in_window_tree (w
, on_p
)
22700 if (!NILP (w
->hchild
))
22701 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22702 else if (!NILP (w
->vchild
))
22703 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22705 update_window_cursor (w
, on_p
);
22707 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22713 Display the cursor on window W, or clear it, according to ON_P.
22714 Don't change the cursor's position. */
22717 x_update_cursor (f
, on_p
)
22721 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22726 Clear the cursor of window W to background color, and mark the
22727 cursor as not shown. This is used when the text where the cursor
22728 is about to be rewritten. */
22734 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22735 update_window_cursor (w
, 0);
22740 Display the active region described by mouse_face_* according to DRAW. */
22743 show_mouse_face (dpyinfo
, draw
)
22744 Display_Info
*dpyinfo
;
22745 enum draw_glyphs_face draw
;
22747 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22748 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22750 if (/* If window is in the process of being destroyed, don't bother
22752 w
->current_matrix
!= NULL
22753 /* Don't update mouse highlight if hidden */
22754 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22755 /* Recognize when we are called to operate on rows that don't exist
22756 anymore. This can happen when a window is split. */
22757 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22759 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22760 struct glyph_row
*row
, *first
, *last
;
22762 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22763 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22765 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22767 int start_hpos
, end_hpos
, start_x
;
22769 /* For all but the first row, the highlight starts at column 0. */
22772 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22773 start_x
= dpyinfo
->mouse_face_beg_x
;
22782 end_hpos
= dpyinfo
->mouse_face_end_col
;
22785 end_hpos
= row
->used
[TEXT_AREA
];
22786 if (draw
== DRAW_NORMAL_TEXT
)
22787 row
->fill_line_p
= 1; /* Clear to end of line */
22790 if (end_hpos
> start_hpos
)
22792 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22793 start_hpos
, end_hpos
,
22797 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22801 /* When we've written over the cursor, arrange for it to
22802 be displayed again. */
22803 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22806 display_and_set_cursor (w
, 1,
22807 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22808 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22813 /* Change the mouse cursor. */
22814 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22815 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22816 else if (draw
== DRAW_MOUSE_FACE
)
22817 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22819 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22823 Clear out the mouse-highlighted active region.
22824 Redraw it un-highlighted first. Value is non-zero if mouse
22825 face was actually drawn unhighlighted. */
22828 clear_mouse_face (dpyinfo
)
22829 Display_Info
*dpyinfo
;
22833 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22835 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22839 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22840 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22841 dpyinfo
->mouse_face_window
= Qnil
;
22842 dpyinfo
->mouse_face_overlay
= Qnil
;
22848 Non-zero if physical cursor of window W is within mouse face. */
22851 cursor_in_mouse_face_p (w
)
22854 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22855 int in_mouse_face
= 0;
22857 if (WINDOWP (dpyinfo
->mouse_face_window
)
22858 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22860 int hpos
= w
->phys_cursor
.hpos
;
22861 int vpos
= w
->phys_cursor
.vpos
;
22863 if (vpos
>= dpyinfo
->mouse_face_beg_row
22864 && vpos
<= dpyinfo
->mouse_face_end_row
22865 && (vpos
> dpyinfo
->mouse_face_beg_row
22866 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22867 && (vpos
< dpyinfo
->mouse_face_end_row
22868 || hpos
< dpyinfo
->mouse_face_end_col
22869 || dpyinfo
->mouse_face_past_end
))
22873 return in_mouse_face
;
22879 /* This function sets the mouse_face_* elements of DPYINFO, assuming
22880 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
22881 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
22882 for the overlay or run of text properties specifying the mouse
22883 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
22884 before-string and after-string that must also be highlighted.
22885 DISPLAY_STRING, if non-nil, is a display string that may cover some
22886 or all of the highlighted text. */
22889 mouse_face_from_buffer_pos (Lisp_Object window
,
22890 Display_Info
*dpyinfo
,
22891 EMACS_INT mouse_charpos
,
22892 EMACS_INT start_charpos
,
22893 EMACS_INT end_charpos
,
22894 Lisp_Object before_string
,
22895 Lisp_Object after_string
,
22896 Lisp_Object display_string
)
22898 struct window
*w
= XWINDOW (window
);
22899 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22900 struct glyph_row
*row
;
22901 struct glyph
*glyph
, *end
;
22905 xassert (NILP (display_string
) || STRINGP (display_string
));
22906 xassert (NILP (before_string
) || STRINGP (before_string
));
22907 xassert (NILP (after_string
) || STRINGP (after_string
));
22909 /* Find the first highlighted glyph. */
22910 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
22912 dpyinfo
->mouse_face_beg_col
= 0;
22913 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22914 dpyinfo
->mouse_face_beg_x
= first
->x
;
22915 dpyinfo
->mouse_face_beg_y
= first
->y
;
22919 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
22921 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22923 /* If the before-string or display-string contains newlines,
22924 row_containing_pos skips to its last row. Move back. */
22925 if (!NILP (before_string
) || !NILP (display_string
))
22927 struct glyph_row
*prev
;
22928 while ((prev
= row
- 1, prev
>= first
)
22929 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
22930 && prev
->used
[TEXT_AREA
] > 0)
22932 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22933 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22934 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
22936 || !(EQ (glyph
->object
, before_string
)
22937 || EQ (glyph
->object
, display_string
)))
22943 glyph
= row
->glyphs
[TEXT_AREA
];
22944 end
= glyph
+ row
->used
[TEXT_AREA
];
22946 dpyinfo
->mouse_face_beg_y
= row
->y
;
22947 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22949 /* Skip truncation glyphs at the start of the glyph row. */
22950 if (row
->displays_text_p
)
22952 && INTEGERP (glyph
->object
)
22953 && glyph
->charpos
< 0;
22955 x
+= glyph
->pixel_width
;
22957 /* Scan the glyph row, stopping before BEFORE_STRING or
22958 DISPLAY_STRING or START_CHARPOS. */
22960 && !INTEGERP (glyph
->object
)
22961 && !EQ (glyph
->object
, before_string
)
22962 && !EQ (glyph
->object
, display_string
)
22963 && !(BUFFERP (glyph
->object
)
22964 && glyph
->charpos
>= start_charpos
);
22966 x
+= glyph
->pixel_width
;
22968 dpyinfo
->mouse_face_beg_x
= x
;
22969 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
22972 /* Find the last highlighted glyph. */
22973 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
22976 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22977 dpyinfo
->mouse_face_past_end
= 1;
22979 else if (!NILP (after_string
))
22981 /* If the after-string has newlines, advance to its last row. */
22982 struct glyph_row
*next
;
22983 struct glyph_row
*last
22984 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22986 for (next
= row
+ 1;
22988 && next
->used
[TEXT_AREA
] > 0
22989 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
22994 glyph
= row
->glyphs
[TEXT_AREA
];
22995 end
= glyph
+ row
->used
[TEXT_AREA
];
22997 dpyinfo
->mouse_face_end_y
= row
->y
;
22998 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23000 /* Skip truncation glyphs at the start of the row. */
23001 if (row
->displays_text_p
)
23003 && INTEGERP (glyph
->object
)
23004 && glyph
->charpos
< 0;
23006 x
+= glyph
->pixel_width
;
23008 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
23011 && !INTEGERP (glyph
->object
)
23012 && !EQ (glyph
->object
, after_string
)
23013 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
23015 x
+= glyph
->pixel_width
;
23017 /* If we found AFTER_STRING, consume it and stop. */
23018 if (EQ (glyph
->object
, after_string
))
23020 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
23021 x
+= glyph
->pixel_width
;
23025 /* If there's no after-string, we must check if we overshot,
23026 which might be the case if we stopped after a string glyph.
23027 That glyph may belong to a before-string or display-string
23028 associated with the end position, which must not be
23030 Lisp_Object prev_object
;
23033 while (glyph
> row
->glyphs
[TEXT_AREA
])
23035 prev_object
= (glyph
- 1)->object
;
23036 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23039 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23040 if (pos
&& pos
< end_charpos
)
23043 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23044 && EQ ((glyph
- 1)->object
, prev_object
);
23046 x
-= (glyph
- 1)->pixel_width
;
23050 dpyinfo
->mouse_face_end_x
= x
;
23051 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23052 dpyinfo
->mouse_face_window
= window
;
23053 dpyinfo
->mouse_face_face_id
23054 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23056 !dpyinfo
->mouse_face_hidden
, -1);
23057 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23061 /* Find the position of the glyph for position POS in OBJECT in
23062 window W's current matrix, and return in *X, *Y the pixel
23063 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23065 RIGHT_P non-zero means return the position of the right edge of the
23066 glyph, RIGHT_P zero means return the left edge position.
23068 If no glyph for POS exists in the matrix, return the position of
23069 the glyph with the next smaller position that is in the matrix, if
23070 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23071 exists in the matrix, return the position of the glyph with the
23072 next larger position in OBJECT.
23074 Value is non-zero if a glyph was found. */
23077 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23080 Lisp_Object object
;
23081 int *hpos
, *vpos
, *x
, *y
;
23084 int yb
= window_text_bottom_y (w
);
23085 struct glyph_row
*r
;
23086 struct glyph
*best_glyph
= NULL
;
23087 struct glyph_row
*best_row
= NULL
;
23090 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23091 r
->enabled_p
&& r
->y
< yb
;
23094 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23095 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23098 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23099 if (EQ (g
->object
, object
))
23101 if (g
->charpos
== pos
)
23108 else if (best_glyph
== NULL
23109 || ((eabs (g
->charpos
- pos
)
23110 < eabs (best_glyph
->charpos
- pos
))
23113 : g
->charpos
> pos
)))
23127 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23131 *x
+= best_glyph
->pixel_width
;
23136 *vpos
= best_row
- w
->current_matrix
->rows
;
23139 return best_glyph
!= NULL
;
23143 /* See if position X, Y is within a hot-spot of an image. */
23146 on_hot_spot_p (hot_spot
, x
, y
)
23147 Lisp_Object hot_spot
;
23150 if (!CONSP (hot_spot
))
23153 if (EQ (XCAR (hot_spot
), Qrect
))
23155 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23156 Lisp_Object rect
= XCDR (hot_spot
);
23160 if (!CONSP (XCAR (rect
)))
23162 if (!CONSP (XCDR (rect
)))
23164 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23166 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23168 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23170 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23174 else if (EQ (XCAR (hot_spot
), Qcircle
))
23176 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23177 Lisp_Object circ
= XCDR (hot_spot
);
23178 Lisp_Object lr
, lx0
, ly0
;
23180 && CONSP (XCAR (circ
))
23181 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23182 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23183 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23185 double r
= XFLOATINT (lr
);
23186 double dx
= XINT (lx0
) - x
;
23187 double dy
= XINT (ly0
) - y
;
23188 return (dx
* dx
+ dy
* dy
<= r
* r
);
23191 else if (EQ (XCAR (hot_spot
), Qpoly
))
23193 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23194 if (VECTORP (XCDR (hot_spot
)))
23196 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23197 Lisp_Object
*poly
= v
->contents
;
23201 Lisp_Object lx
, ly
;
23204 /* Need an even number of coordinates, and at least 3 edges. */
23205 if (n
< 6 || n
& 1)
23208 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23209 If count is odd, we are inside polygon. Pixels on edges
23210 may or may not be included depending on actual geometry of the
23212 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23213 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23215 x0
= XINT (lx
), y0
= XINT (ly
);
23216 for (i
= 0; i
< n
; i
+= 2)
23218 int x1
= x0
, y1
= y0
;
23219 if ((lx
= poly
[i
], !INTEGERP (lx
))
23220 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23222 x0
= XINT (lx
), y0
= XINT (ly
);
23224 /* Does this segment cross the X line? */
23232 if (y
> y0
&& y
> y1
)
23234 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23244 find_hot_spot (map
, x
, y
)
23248 while (CONSP (map
))
23250 if (CONSP (XCAR (map
))
23251 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23259 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23261 doc
: /* Lookup in image map MAP coordinates X and Y.
23262 An image map is an alist where each element has the format (AREA ID PLIST).
23263 An AREA is specified as either a rectangle, a circle, or a polygon:
23264 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23265 pixel coordinates of the upper left and bottom right corners.
23266 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23267 and the radius of the circle; r may be a float or integer.
23268 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23269 vector describes one corner in the polygon.
23270 Returns the alist element for the first matching AREA in MAP. */)
23281 return find_hot_spot (map
, XINT (x
), XINT (y
));
23285 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23287 define_frame_cursor1 (f
, cursor
, pointer
)
23290 Lisp_Object pointer
;
23292 /* Do not change cursor shape while dragging mouse. */
23293 if (!NILP (do_mouse_tracking
))
23296 if (!NILP (pointer
))
23298 if (EQ (pointer
, Qarrow
))
23299 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23300 else if (EQ (pointer
, Qhand
))
23301 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23302 else if (EQ (pointer
, Qtext
))
23303 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23304 else if (EQ (pointer
, intern ("hdrag")))
23305 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23306 #ifdef HAVE_X_WINDOWS
23307 else if (EQ (pointer
, intern ("vdrag")))
23308 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23310 else if (EQ (pointer
, intern ("hourglass")))
23311 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23312 else if (EQ (pointer
, Qmodeline
))
23313 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23315 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23318 if (cursor
!= No_Cursor
)
23319 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23322 /* Take proper action when mouse has moved to the mode or header line
23323 or marginal area AREA of window W, x-position X and y-position Y.
23324 X is relative to the start of the text display area of W, so the
23325 width of bitmap areas and scroll bars must be subtracted to get a
23326 position relative to the start of the mode line. */
23329 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23330 Lisp_Object window
;
23332 enum window_part area
;
23334 struct window
*w
= XWINDOW (window
);
23335 struct frame
*f
= XFRAME (w
->frame
);
23336 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23337 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23338 Lisp_Object pointer
= Qnil
;
23339 int charpos
, dx
, dy
, width
, height
;
23340 Lisp_Object string
, object
= Qnil
;
23341 Lisp_Object pos
, help
;
23343 Lisp_Object mouse_face
;
23344 int original_x_pixel
= x
;
23345 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23346 struct glyph_row
*row
;
23348 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23353 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23354 &object
, &dx
, &dy
, &width
, &height
);
23356 row
= (area
== ON_MODE_LINE
23357 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23358 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23361 if (row
->mode_line_p
&& row
->enabled_p
)
23363 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23364 end
= glyph
+ row
->used
[TEXT_AREA
];
23366 for (x0
= original_x_pixel
;
23367 glyph
< end
&& x0
>= glyph
->pixel_width
;
23369 x0
-= glyph
->pixel_width
;
23377 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23378 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23379 &object
, &dx
, &dy
, &width
, &height
);
23384 if (IMAGEP (object
))
23386 Lisp_Object image_map
, hotspot
;
23387 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23389 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23391 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23393 Lisp_Object area_id
, plist
;
23395 area_id
= XCAR (hotspot
);
23396 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23397 If so, we could look for mouse-enter, mouse-leave
23398 properties in PLIST (and do something...). */
23399 hotspot
= XCDR (hotspot
);
23400 if (CONSP (hotspot
)
23401 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23403 pointer
= Fplist_get (plist
, Qpointer
);
23404 if (NILP (pointer
))
23406 help
= Fplist_get (plist
, Qhelp_echo
);
23409 help_echo_string
= help
;
23410 /* Is this correct? ++kfs */
23411 XSETWINDOW (help_echo_window
, w
);
23412 help_echo_object
= w
->buffer
;
23413 help_echo_pos
= charpos
;
23417 if (NILP (pointer
))
23418 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23421 if (STRINGP (string
))
23423 pos
= make_number (charpos
);
23424 /* If we're on a string with `help-echo' text property, arrange
23425 for the help to be displayed. This is done by setting the
23426 global variable help_echo_string to the help string. */
23429 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23432 help_echo_string
= help
;
23433 XSETWINDOW (help_echo_window
, w
);
23434 help_echo_object
= string
;
23435 help_echo_pos
= charpos
;
23439 if (NILP (pointer
))
23440 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23442 /* Change the mouse pointer according to what is under X/Y. */
23443 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23446 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23447 if (!KEYMAPP (map
))
23448 map
= Fget_text_property (pos
, Qkeymap
, string
);
23449 if (!KEYMAPP (map
))
23450 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23453 /* Change the mouse face according to what is under X/Y. */
23454 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23455 if (!NILP (mouse_face
)
23456 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23461 struct glyph
* tmp_glyph
;
23465 int total_pixel_width
;
23470 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23471 Qmouse_face
, string
, Qnil
);
23473 b
= make_number (0);
23475 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23477 e
= make_number (SCHARS (string
));
23479 /* Calculate the position(glyph position: GPOS) of GLYPH in
23480 displayed string. GPOS is different from CHARPOS.
23482 CHARPOS is the position of glyph in internal string
23483 object. A mode line string format has structures which
23484 is converted to a flatten by emacs lisp interpreter.
23485 The internal string is an element of the structures.
23486 The displayed string is the flatten string. */
23488 if (glyph
> row_start_glyph
)
23490 tmp_glyph
= glyph
- 1;
23491 while (tmp_glyph
>= row_start_glyph
23492 && tmp_glyph
->charpos
>= XINT (b
)
23493 && EQ (tmp_glyph
->object
, glyph
->object
))
23500 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23501 displayed string holding GLYPH.
23503 GSEQ_LENGTH is different from SCHARS (STRING).
23504 SCHARS (STRING) returns the length of the internal string. */
23505 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23506 tmp_glyph
->charpos
< XINT (e
);
23507 tmp_glyph
++, gseq_length
++)
23509 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23513 total_pixel_width
= 0;
23514 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23515 total_pixel_width
+= tmp_glyph
->pixel_width
;
23517 /* Pre calculation of re-rendering position */
23519 hpos
= (area
== ON_MODE_LINE
23520 ? (w
->current_matrix
)->nrows
- 1
23523 /* If the re-rendering position is included in the last
23524 re-rendering area, we should do nothing. */
23525 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23526 && dpyinfo
->mouse_face_beg_col
<= vpos
23527 && vpos
< dpyinfo
->mouse_face_end_col
23528 && dpyinfo
->mouse_face_beg_row
== hpos
)
23531 if (clear_mouse_face (dpyinfo
))
23532 cursor
= No_Cursor
;
23534 dpyinfo
->mouse_face_beg_col
= vpos
;
23535 dpyinfo
->mouse_face_beg_row
= hpos
;
23537 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23538 dpyinfo
->mouse_face_beg_y
= 0;
23540 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23541 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23543 dpyinfo
->mouse_face_end_x
= 0;
23544 dpyinfo
->mouse_face_end_y
= 0;
23546 dpyinfo
->mouse_face_past_end
= 0;
23547 dpyinfo
->mouse_face_window
= window
;
23549 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23552 glyph
->face_id
, 1);
23553 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23555 if (NILP (pointer
))
23558 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23559 clear_mouse_face (dpyinfo
);
23561 define_frame_cursor1 (f
, cursor
, pointer
);
23566 Take proper action when the mouse has moved to position X, Y on
23567 frame F as regards highlighting characters that have mouse-face
23568 properties. Also de-highlighting chars where the mouse was before.
23569 X and Y can be negative or out of range. */
23572 note_mouse_highlight (f
, x
, y
)
23576 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23577 enum window_part part
;
23578 Lisp_Object window
;
23580 Cursor cursor
= No_Cursor
;
23581 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23584 /* When a menu is active, don't highlight because this looks odd. */
23585 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
23586 if (popup_activated ())
23590 if (NILP (Vmouse_highlight
)
23591 || !f
->glyphs_initialized_p
)
23594 dpyinfo
->mouse_face_mouse_x
= x
;
23595 dpyinfo
->mouse_face_mouse_y
= y
;
23596 dpyinfo
->mouse_face_mouse_frame
= f
;
23598 if (dpyinfo
->mouse_face_defer
)
23601 if (gc_in_progress
)
23603 dpyinfo
->mouse_face_deferred_gc
= 1;
23607 /* Which window is that in? */
23608 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23610 /* If we were displaying active text in another window, clear that.
23611 Also clear if we move out of text area in same window. */
23612 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23613 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23614 && !NILP (dpyinfo
->mouse_face_window
)))
23615 clear_mouse_face (dpyinfo
);
23617 /* Not on a window -> return. */
23618 if (!WINDOWP (window
))
23621 /* Reset help_echo_string. It will get recomputed below. */
23622 help_echo_string
= Qnil
;
23624 /* Convert to window-relative pixel coordinates. */
23625 w
= XWINDOW (window
);
23626 frame_to_window_pixel_xy (w
, &x
, &y
);
23628 /* Handle tool-bar window differently since it doesn't display a
23630 if (EQ (window
, f
->tool_bar_window
))
23632 note_tool_bar_highlight (f
, x
, y
);
23636 /* Mouse is on the mode, header line or margin? */
23637 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23638 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23640 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23644 if (part
== ON_VERTICAL_BORDER
)
23646 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23647 help_echo_string
= build_string ("drag-mouse-1: resize");
23649 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23650 || part
== ON_SCROLL_BAR
)
23651 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23653 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23655 /* Are we in a window whose display is up to date?
23656 And verify the buffer's text has not changed. */
23657 b
= XBUFFER (w
->buffer
);
23658 if (part
== ON_TEXT
23659 && EQ (w
->window_end_valid
, w
->buffer
)
23660 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23661 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23663 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23664 struct glyph
*glyph
;
23665 Lisp_Object object
;
23666 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23667 Lisp_Object
*overlay_vec
= NULL
;
23669 struct buffer
*obuf
;
23670 int obegv
, ozv
, same_region
;
23672 /* Find the glyph under X/Y. */
23673 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23675 /* Look for :pointer property on image. */
23676 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23678 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23679 if (img
!= NULL
&& IMAGEP (img
->spec
))
23681 Lisp_Object image_map
, hotspot
;
23682 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23684 && (hotspot
= find_hot_spot (image_map
,
23685 glyph
->slice
.x
+ dx
,
23686 glyph
->slice
.y
+ dy
),
23688 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23690 Lisp_Object area_id
, plist
;
23692 area_id
= XCAR (hotspot
);
23693 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23694 If so, we could look for mouse-enter, mouse-leave
23695 properties in PLIST (and do something...). */
23696 hotspot
= XCDR (hotspot
);
23697 if (CONSP (hotspot
)
23698 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23700 pointer
= Fplist_get (plist
, Qpointer
);
23701 if (NILP (pointer
))
23703 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23704 if (!NILP (help_echo_string
))
23706 help_echo_window
= window
;
23707 help_echo_object
= glyph
->object
;
23708 help_echo_pos
= glyph
->charpos
;
23712 if (NILP (pointer
))
23713 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23717 /* Clear mouse face if X/Y not over text. */
23719 || area
!= TEXT_AREA
23720 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23722 if (clear_mouse_face (dpyinfo
))
23723 cursor
= No_Cursor
;
23724 if (NILP (pointer
))
23726 if (area
!= TEXT_AREA
)
23727 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23729 pointer
= Vvoid_text_area_pointer
;
23734 pos
= glyph
->charpos
;
23735 object
= glyph
->object
;
23736 if (!STRINGP (object
) && !BUFFERP (object
))
23739 /* If we get an out-of-range value, return now; avoid an error. */
23740 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23743 /* Make the window's buffer temporarily current for
23744 overlays_at and compute_char_face. */
23745 obuf
= current_buffer
;
23746 current_buffer
= b
;
23752 /* Is this char mouse-active or does it have help-echo? */
23753 position
= make_number (pos
);
23755 if (BUFFERP (object
))
23757 /* Put all the overlays we want in a vector in overlay_vec. */
23758 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23759 /* Sort overlays into increasing priority order. */
23760 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23765 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23766 && vpos
>= dpyinfo
->mouse_face_beg_row
23767 && vpos
<= dpyinfo
->mouse_face_end_row
23768 && (vpos
> dpyinfo
->mouse_face_beg_row
23769 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23770 && (vpos
< dpyinfo
->mouse_face_end_row
23771 || hpos
< dpyinfo
->mouse_face_end_col
23772 || dpyinfo
->mouse_face_past_end
));
23775 cursor
= No_Cursor
;
23777 /* Check mouse-face highlighting. */
23779 /* If there exists an overlay with mouse-face overlapping
23780 the one we are currently highlighting, we have to
23781 check if we enter the overlapping overlay, and then
23782 highlight only that. */
23783 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23784 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23786 /* Find the highest priority overlay with a mouse-face. */
23788 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23790 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23791 if (!NILP (mouse_face
))
23792 overlay
= overlay_vec
[i
];
23795 /* If we're highlighting the same overlay as before, there's
23796 no need to do that again. */
23797 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23798 goto check_help_echo
;
23799 dpyinfo
->mouse_face_overlay
= overlay
;
23801 /* Clear the display of the old active region, if any. */
23802 if (clear_mouse_face (dpyinfo
))
23803 cursor
= No_Cursor
;
23805 /* If no overlay applies, get a text property. */
23806 if (NILP (overlay
))
23807 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23809 /* Next, compute the bounds of the mouse highlighting and
23811 if (!NILP (mouse_face
) && STRINGP (object
))
23813 /* The mouse-highlighting comes from a display string
23814 with a mouse-face. */
23818 b
= Fprevious_single_property_change
23819 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
23820 e
= Fnext_single_property_change
23821 (position
, Qmouse_face
, object
, Qnil
);
23823 b
= make_number (0);
23825 e
= make_number (SCHARS (object
) - 1);
23827 fast_find_string_pos (w
, XINT (b
), object
,
23828 &dpyinfo
->mouse_face_beg_col
,
23829 &dpyinfo
->mouse_face_beg_row
,
23830 &dpyinfo
->mouse_face_beg_x
,
23831 &dpyinfo
->mouse_face_beg_y
, 0);
23832 fast_find_string_pos (w
, XINT (e
), object
,
23833 &dpyinfo
->mouse_face_end_col
,
23834 &dpyinfo
->mouse_face_end_row
,
23835 &dpyinfo
->mouse_face_end_x
,
23836 &dpyinfo
->mouse_face_end_y
, 1);
23837 dpyinfo
->mouse_face_past_end
= 0;
23838 dpyinfo
->mouse_face_window
= window
;
23839 dpyinfo
->mouse_face_face_id
23840 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23841 glyph
->face_id
, 1);
23842 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23843 cursor
= No_Cursor
;
23847 /* The mouse-highlighting, if any, comes from an overlay
23848 or text property in the buffer. */
23849 Lisp_Object buffer
, display_string
;
23851 if (STRINGP (object
))
23853 /* If we are on a display string with no mouse-face,
23854 check if the text under it has one. */
23855 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23856 int start
= MATRIX_ROW_START_CHARPOS (r
);
23857 pos
= string_buffer_position (w
, object
, start
);
23860 mouse_face
= get_char_property_and_overlay
23861 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
23862 buffer
= w
->buffer
;
23863 display_string
= object
;
23869 display_string
= Qnil
;
23872 if (!NILP (mouse_face
))
23874 Lisp_Object before
, after
;
23875 Lisp_Object before_string
, after_string
;
23877 if (NILP (overlay
))
23879 /* Handle the text property case. */
23880 before
= Fprevious_single_property_change
23881 (make_number (pos
+ 1), Qmouse_face
, buffer
,
23882 Fmarker_position (w
->start
));
23883 after
= Fnext_single_property_change
23884 (make_number (pos
), Qmouse_face
, buffer
,
23885 make_number (BUF_Z (XBUFFER (buffer
))
23886 - XFASTINT (w
->window_end_pos
)));
23887 before_string
= after_string
= Qnil
;
23891 /* Handle the overlay case. */
23892 before
= Foverlay_start (overlay
);
23893 after
= Foverlay_end (overlay
);
23894 before_string
= Foverlay_get (overlay
, Qbefore_string
);
23895 after_string
= Foverlay_get (overlay
, Qafter_string
);
23897 if (!STRINGP (before_string
)) before_string
= Qnil
;
23898 if (!STRINGP (after_string
)) after_string
= Qnil
;
23901 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
23904 before_string
, after_string
,
23906 cursor
= No_Cursor
;
23913 /* Look for a `help-echo' property. */
23914 if (NILP (help_echo_string
)) {
23915 Lisp_Object help
, overlay
;
23917 /* Check overlays first. */
23918 help
= overlay
= Qnil
;
23919 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23921 overlay
= overlay_vec
[i
];
23922 help
= Foverlay_get (overlay
, Qhelp_echo
);
23927 help_echo_string
= help
;
23928 help_echo_window
= window
;
23929 help_echo_object
= overlay
;
23930 help_echo_pos
= pos
;
23934 Lisp_Object object
= glyph
->object
;
23935 int charpos
= glyph
->charpos
;
23937 /* Try text properties. */
23938 if (STRINGP (object
)
23940 && charpos
< SCHARS (object
))
23942 help
= Fget_text_property (make_number (charpos
),
23943 Qhelp_echo
, object
);
23946 /* If the string itself doesn't specify a help-echo,
23947 see if the buffer text ``under'' it does. */
23948 struct glyph_row
*r
23949 = MATRIX_ROW (w
->current_matrix
, vpos
);
23950 int start
= MATRIX_ROW_START_CHARPOS (r
);
23951 int pos
= string_buffer_position (w
, object
, start
);
23954 help
= Fget_char_property (make_number (pos
),
23955 Qhelp_echo
, w
->buffer
);
23959 object
= w
->buffer
;
23964 else if (BUFFERP (object
)
23967 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23972 help_echo_string
= help
;
23973 help_echo_window
= window
;
23974 help_echo_object
= object
;
23975 help_echo_pos
= charpos
;
23980 /* Look for a `pointer' property. */
23981 if (NILP (pointer
))
23983 /* Check overlays first. */
23984 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23985 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23987 if (NILP (pointer
))
23989 Lisp_Object object
= glyph
->object
;
23990 int charpos
= glyph
->charpos
;
23992 /* Try text properties. */
23993 if (STRINGP (object
)
23995 && charpos
< SCHARS (object
))
23997 pointer
= Fget_text_property (make_number (charpos
),
23999 if (NILP (pointer
))
24001 /* If the string itself doesn't specify a pointer,
24002 see if the buffer text ``under'' it does. */
24003 struct glyph_row
*r
24004 = MATRIX_ROW (w
->current_matrix
, vpos
);
24005 int start
= MATRIX_ROW_START_CHARPOS (r
);
24006 int pos
= string_buffer_position (w
, object
, start
);
24008 pointer
= Fget_char_property (make_number (pos
),
24009 Qpointer
, w
->buffer
);
24012 else if (BUFFERP (object
)
24015 pointer
= Fget_text_property (make_number (charpos
),
24022 current_buffer
= obuf
;
24027 define_frame_cursor1 (f
, cursor
, pointer
);
24032 Clear any mouse-face on window W. This function is part of the
24033 redisplay interface, and is called from try_window_id and similar
24034 functions to ensure the mouse-highlight is off. */
24037 x_clear_window_mouse_face (w
)
24040 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24041 Lisp_Object window
;
24044 XSETWINDOW (window
, w
);
24045 if (EQ (window
, dpyinfo
->mouse_face_window
))
24046 clear_mouse_face (dpyinfo
);
24052 Just discard the mouse face information for frame F, if any.
24053 This is used when the size of F is changed. */
24056 cancel_mouse_face (f
)
24059 Lisp_Object window
;
24060 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24062 window
= dpyinfo
->mouse_face_window
;
24063 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24065 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24066 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24067 dpyinfo
->mouse_face_window
= Qnil
;
24072 #endif /* HAVE_WINDOW_SYSTEM */
24075 /***********************************************************************
24077 ***********************************************************************/
24079 #ifdef HAVE_WINDOW_SYSTEM
24081 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24082 which intersects rectangle R. R is in window-relative coordinates. */
24085 expose_area (w
, row
, r
, area
)
24087 struct glyph_row
*row
;
24089 enum glyph_row_area area
;
24091 struct glyph
*first
= row
->glyphs
[area
];
24092 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24093 struct glyph
*last
;
24094 int first_x
, start_x
, x
;
24096 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24097 /* If row extends face to end of line write the whole line. */
24098 draw_glyphs (w
, 0, row
, area
,
24099 0, row
->used
[area
],
24100 DRAW_NORMAL_TEXT
, 0);
24103 /* Set START_X to the window-relative start position for drawing glyphs of
24104 AREA. The first glyph of the text area can be partially visible.
24105 The first glyphs of other areas cannot. */
24106 start_x
= window_box_left_offset (w
, area
);
24108 if (area
== TEXT_AREA
)
24111 /* Find the first glyph that must be redrawn. */
24113 && x
+ first
->pixel_width
< r
->x
)
24115 x
+= first
->pixel_width
;
24119 /* Find the last one. */
24123 && x
< r
->x
+ r
->width
)
24125 x
+= last
->pixel_width
;
24131 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24132 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24133 DRAW_NORMAL_TEXT
, 0);
24138 /* Redraw the parts of the glyph row ROW on window W intersecting
24139 rectangle R. R is in window-relative coordinates. Value is
24140 non-zero if mouse-face was overwritten. */
24143 expose_line (w
, row
, r
)
24145 struct glyph_row
*row
;
24148 xassert (row
->enabled_p
);
24150 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24151 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24152 0, row
->used
[TEXT_AREA
],
24153 DRAW_NORMAL_TEXT
, 0);
24156 if (row
->used
[LEFT_MARGIN_AREA
])
24157 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24158 if (row
->used
[TEXT_AREA
])
24159 expose_area (w
, row
, r
, TEXT_AREA
);
24160 if (row
->used
[RIGHT_MARGIN_AREA
])
24161 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24162 draw_row_fringe_bitmaps (w
, row
);
24165 return row
->mouse_face_p
;
24169 /* Redraw those parts of glyphs rows during expose event handling that
24170 overlap other rows. Redrawing of an exposed line writes over parts
24171 of lines overlapping that exposed line; this function fixes that.
24173 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24174 row in W's current matrix that is exposed and overlaps other rows.
24175 LAST_OVERLAPPING_ROW is the last such row. */
24178 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24180 struct glyph_row
*first_overlapping_row
;
24181 struct glyph_row
*last_overlapping_row
;
24184 struct glyph_row
*row
;
24186 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24187 if (row
->overlapping_p
)
24189 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24192 if (row
->used
[LEFT_MARGIN_AREA
])
24193 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24195 if (row
->used
[TEXT_AREA
])
24196 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24198 if (row
->used
[RIGHT_MARGIN_AREA
])
24199 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24205 /* Return non-zero if W's cursor intersects rectangle R. */
24208 phys_cursor_in_rect_p (w
, r
)
24212 XRectangle cr
, result
;
24213 struct glyph
*cursor_glyph
;
24214 struct glyph_row
*row
;
24216 if (w
->phys_cursor
.vpos
>= 0
24217 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24218 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24220 && row
->cursor_in_fringe_p
)
24222 /* Cursor is in the fringe. */
24223 cr
.x
= window_box_right_offset (w
,
24224 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24225 ? RIGHT_MARGIN_AREA
24228 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24229 cr
.height
= row
->height
;
24230 return x_intersect_rectangles (&cr
, r
, &result
);
24233 cursor_glyph
= get_phys_cursor_glyph (w
);
24236 /* r is relative to W's box, but w->phys_cursor.x is relative
24237 to left edge of W's TEXT area. Adjust it. */
24238 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24239 cr
.y
= w
->phys_cursor
.y
;
24240 cr
.width
= cursor_glyph
->pixel_width
;
24241 cr
.height
= w
->phys_cursor_height
;
24242 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24243 I assume the effect is the same -- and this is portable. */
24244 return x_intersect_rectangles (&cr
, r
, &result
);
24246 /* If we don't understand the format, pretend we're not in the hot-spot. */
24252 Draw a vertical window border to the right of window W if W doesn't
24253 have vertical scroll bars. */
24256 x_draw_vertical_border (w
)
24259 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24261 /* We could do better, if we knew what type of scroll-bar the adjacent
24262 windows (on either side) have... But we don't :-(
24263 However, I think this works ok. ++KFS 2003-04-25 */
24265 /* Redraw borders between horizontally adjacent windows. Don't
24266 do it for frames with vertical scroll bars because either the
24267 right scroll bar of a window, or the left scroll bar of its
24268 neighbor will suffice as a border. */
24269 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24272 if (!WINDOW_RIGHTMOST_P (w
)
24273 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24275 int x0
, x1
, y0
, y1
;
24277 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24280 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24283 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24285 else if (!WINDOW_LEFTMOST_P (w
)
24286 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24288 int x0
, x1
, y0
, y1
;
24290 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24293 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24296 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24301 /* Redraw the part of window W intersection rectangle FR. Pixel
24302 coordinates in FR are frame-relative. Call this function with
24303 input blocked. Value is non-zero if the exposure overwrites
24307 expose_window (w
, fr
)
24311 struct frame
*f
= XFRAME (w
->frame
);
24313 int mouse_face_overwritten_p
= 0;
24315 /* If window is not yet fully initialized, do nothing. This can
24316 happen when toolkit scroll bars are used and a window is split.
24317 Reconfiguring the scroll bar will generate an expose for a newly
24319 if (w
->current_matrix
== NULL
)
24322 /* When we're currently updating the window, display and current
24323 matrix usually don't agree. Arrange for a thorough display
24325 if (w
== updated_window
)
24327 SET_FRAME_GARBAGED (f
);
24331 /* Frame-relative pixel rectangle of W. */
24332 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24333 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24334 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24335 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24337 if (x_intersect_rectangles (fr
, &wr
, &r
))
24339 int yb
= window_text_bottom_y (w
);
24340 struct glyph_row
*row
;
24341 int cursor_cleared_p
;
24342 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24344 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24345 r
.x
, r
.y
, r
.width
, r
.height
));
24347 /* Convert to window coordinates. */
24348 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24349 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24351 /* Turn off the cursor. */
24352 if (!w
->pseudo_window_p
24353 && phys_cursor_in_rect_p (w
, &r
))
24355 x_clear_cursor (w
);
24356 cursor_cleared_p
= 1;
24359 cursor_cleared_p
= 0;
24361 /* Update lines intersecting rectangle R. */
24362 first_overlapping_row
= last_overlapping_row
= NULL
;
24363 for (row
= w
->current_matrix
->rows
;
24368 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24370 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24371 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24372 || (r
.y
>= y0
&& r
.y
< y1
)
24373 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24375 /* A header line may be overlapping, but there is no need
24376 to fix overlapping areas for them. KFS 2005-02-12 */
24377 if (row
->overlapping_p
&& !row
->mode_line_p
)
24379 if (first_overlapping_row
== NULL
)
24380 first_overlapping_row
= row
;
24381 last_overlapping_row
= row
;
24385 if (expose_line (w
, row
, &r
))
24386 mouse_face_overwritten_p
= 1;
24389 else if (row
->overlapping_p
)
24391 /* We must redraw a row overlapping the exposed area. */
24393 ? y0
+ row
->phys_height
> r
.y
24394 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24396 if (first_overlapping_row
== NULL
)
24397 first_overlapping_row
= row
;
24398 last_overlapping_row
= row
;
24406 /* Display the mode line if there is one. */
24407 if (WINDOW_WANTS_MODELINE_P (w
)
24408 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24410 && row
->y
< r
.y
+ r
.height
)
24412 if (expose_line (w
, row
, &r
))
24413 mouse_face_overwritten_p
= 1;
24416 if (!w
->pseudo_window_p
)
24418 /* Fix the display of overlapping rows. */
24419 if (first_overlapping_row
)
24420 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24423 /* Draw border between windows. */
24424 x_draw_vertical_border (w
);
24426 /* Turn the cursor on again. */
24427 if (cursor_cleared_p
)
24428 update_window_cursor (w
, 1);
24432 return mouse_face_overwritten_p
;
24437 /* Redraw (parts) of all windows in the window tree rooted at W that
24438 intersect R. R contains frame pixel coordinates. Value is
24439 non-zero if the exposure overwrites mouse-face. */
24442 expose_window_tree (w
, r
)
24446 struct frame
*f
= XFRAME (w
->frame
);
24447 int mouse_face_overwritten_p
= 0;
24449 while (w
&& !FRAME_GARBAGED_P (f
))
24451 if (!NILP (w
->hchild
))
24452 mouse_face_overwritten_p
24453 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24454 else if (!NILP (w
->vchild
))
24455 mouse_face_overwritten_p
24456 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24458 mouse_face_overwritten_p
|= expose_window (w
, r
);
24460 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24463 return mouse_face_overwritten_p
;
24468 Redisplay an exposed area of frame F. X and Y are the upper-left
24469 corner of the exposed rectangle. W and H are width and height of
24470 the exposed area. All are pixel values. W or H zero means redraw
24471 the entire frame. */
24474 expose_frame (f
, x
, y
, w
, h
)
24479 int mouse_face_overwritten_p
= 0;
24481 TRACE ((stderr
, "expose_frame "));
24483 /* No need to redraw if frame will be redrawn soon. */
24484 if (FRAME_GARBAGED_P (f
))
24486 TRACE ((stderr
, " garbaged\n"));
24490 /* If basic faces haven't been realized yet, there is no point in
24491 trying to redraw anything. This can happen when we get an expose
24492 event while Emacs is starting, e.g. by moving another window. */
24493 if (FRAME_FACE_CACHE (f
) == NULL
24494 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24496 TRACE ((stderr
, " no faces\n"));
24500 if (w
== 0 || h
== 0)
24503 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24504 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24514 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24515 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24517 if (WINDOWP (f
->tool_bar_window
))
24518 mouse_face_overwritten_p
24519 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24521 #ifdef HAVE_X_WINDOWS
24523 #ifndef USE_X_TOOLKIT
24524 if (WINDOWP (f
->menu_bar_window
))
24525 mouse_face_overwritten_p
24526 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24527 #endif /* not USE_X_TOOLKIT */
24531 /* Some window managers support a focus-follows-mouse style with
24532 delayed raising of frames. Imagine a partially obscured frame,
24533 and moving the mouse into partially obscured mouse-face on that
24534 frame. The visible part of the mouse-face will be highlighted,
24535 then the WM raises the obscured frame. With at least one WM, KDE
24536 2.1, Emacs is not getting any event for the raising of the frame
24537 (even tried with SubstructureRedirectMask), only Expose events.
24538 These expose events will draw text normally, i.e. not
24539 highlighted. Which means we must redo the highlight here.
24540 Subsume it under ``we love X''. --gerd 2001-08-15 */
24541 /* Included in Windows version because Windows most likely does not
24542 do the right thing if any third party tool offers
24543 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24544 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24546 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24547 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24549 int x
= dpyinfo
->mouse_face_mouse_x
;
24550 int y
= dpyinfo
->mouse_face_mouse_y
;
24551 clear_mouse_face (dpyinfo
);
24552 note_mouse_highlight (f
, x
, y
);
24559 Determine the intersection of two rectangles R1 and R2. Return
24560 the intersection in *RESULT. Value is non-zero if RESULT is not
24564 x_intersect_rectangles (r1
, r2
, result
)
24565 XRectangle
*r1
, *r2
, *result
;
24567 XRectangle
*left
, *right
;
24568 XRectangle
*upper
, *lower
;
24569 int intersection_p
= 0;
24571 /* Rearrange so that R1 is the left-most rectangle. */
24573 left
= r1
, right
= r2
;
24575 left
= r2
, right
= r1
;
24577 /* X0 of the intersection is right.x0, if this is inside R1,
24578 otherwise there is no intersection. */
24579 if (right
->x
<= left
->x
+ left
->width
)
24581 result
->x
= right
->x
;
24583 /* The right end of the intersection is the minimum of the
24584 the right ends of left and right. */
24585 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24588 /* Same game for Y. */
24590 upper
= r1
, lower
= r2
;
24592 upper
= r2
, lower
= r1
;
24594 /* The upper end of the intersection is lower.y0, if this is inside
24595 of upper. Otherwise, there is no intersection. */
24596 if (lower
->y
<= upper
->y
+ upper
->height
)
24598 result
->y
= lower
->y
;
24600 /* The lower end of the intersection is the minimum of the lower
24601 ends of upper and lower. */
24602 result
->height
= (min (lower
->y
+ lower
->height
,
24603 upper
->y
+ upper
->height
)
24605 intersection_p
= 1;
24609 return intersection_p
;
24612 #endif /* HAVE_WINDOW_SYSTEM */
24615 /***********************************************************************
24617 ***********************************************************************/
24622 Vwith_echo_area_save_vector
= Qnil
;
24623 staticpro (&Vwith_echo_area_save_vector
);
24625 Vmessage_stack
= Qnil
;
24626 staticpro (&Vmessage_stack
);
24628 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
24629 staticpro (&Qinhibit_redisplay
);
24631 message_dolog_marker1
= Fmake_marker ();
24632 staticpro (&message_dolog_marker1
);
24633 message_dolog_marker2
= Fmake_marker ();
24634 staticpro (&message_dolog_marker2
);
24635 message_dolog_marker3
= Fmake_marker ();
24636 staticpro (&message_dolog_marker3
);
24639 defsubr (&Sdump_frame_glyph_matrix
);
24640 defsubr (&Sdump_glyph_matrix
);
24641 defsubr (&Sdump_glyph_row
);
24642 defsubr (&Sdump_tool_bar_row
);
24643 defsubr (&Strace_redisplay
);
24644 defsubr (&Strace_to_stderr
);
24646 #ifdef HAVE_WINDOW_SYSTEM
24647 defsubr (&Stool_bar_lines_needed
);
24648 defsubr (&Slookup_image_map
);
24650 defsubr (&Sformat_mode_line
);
24651 defsubr (&Sinvisible_p
);
24653 staticpro (&Qmenu_bar_update_hook
);
24654 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
24656 staticpro (&Qoverriding_terminal_local_map
);
24657 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
24659 staticpro (&Qoverriding_local_map
);
24660 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
24662 staticpro (&Qwindow_scroll_functions
);
24663 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
24665 staticpro (&Qwindow_text_change_functions
);
24666 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
24668 staticpro (&Qredisplay_end_trigger_functions
);
24669 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
24671 staticpro (&Qinhibit_point_motion_hooks
);
24672 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
24674 Qeval
= intern_c_string ("eval");
24675 staticpro (&Qeval
);
24677 QCdata
= intern_c_string (":data");
24678 staticpro (&QCdata
);
24679 Qdisplay
= intern_c_string ("display");
24680 staticpro (&Qdisplay
);
24681 Qspace_width
= intern_c_string ("space-width");
24682 staticpro (&Qspace_width
);
24683 Qraise
= intern_c_string ("raise");
24684 staticpro (&Qraise
);
24685 Qslice
= intern_c_string ("slice");
24686 staticpro (&Qslice
);
24687 Qspace
= intern_c_string ("space");
24688 staticpro (&Qspace
);
24689 Qmargin
= intern_c_string ("margin");
24690 staticpro (&Qmargin
);
24691 Qpointer
= intern_c_string ("pointer");
24692 staticpro (&Qpointer
);
24693 Qleft_margin
= intern_c_string ("left-margin");
24694 staticpro (&Qleft_margin
);
24695 Qright_margin
= intern_c_string ("right-margin");
24696 staticpro (&Qright_margin
);
24697 Qcenter
= intern_c_string ("center");
24698 staticpro (&Qcenter
);
24699 Qline_height
= intern_c_string ("line-height");
24700 staticpro (&Qline_height
);
24701 QCalign_to
= intern_c_string (":align-to");
24702 staticpro (&QCalign_to
);
24703 QCrelative_width
= intern_c_string (":relative-width");
24704 staticpro (&QCrelative_width
);
24705 QCrelative_height
= intern_c_string (":relative-height");
24706 staticpro (&QCrelative_height
);
24707 QCeval
= intern_c_string (":eval");
24708 staticpro (&QCeval
);
24709 QCpropertize
= intern_c_string (":propertize");
24710 staticpro (&QCpropertize
);
24711 QCfile
= intern_c_string (":file");
24712 staticpro (&QCfile
);
24713 Qfontified
= intern_c_string ("fontified");
24714 staticpro (&Qfontified
);
24715 Qfontification_functions
= intern_c_string ("fontification-functions");
24716 staticpro (&Qfontification_functions
);
24717 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
24718 staticpro (&Qtrailing_whitespace
);
24719 Qescape_glyph
= intern_c_string ("escape-glyph");
24720 staticpro (&Qescape_glyph
);
24721 Qnobreak_space
= intern_c_string ("nobreak-space");
24722 staticpro (&Qnobreak_space
);
24723 Qimage
= intern_c_string ("image");
24724 staticpro (&Qimage
);
24725 QCmap
= intern_c_string (":map");
24726 staticpro (&QCmap
);
24727 QCpointer
= intern_c_string (":pointer");
24728 staticpro (&QCpointer
);
24729 Qrect
= intern_c_string ("rect");
24730 staticpro (&Qrect
);
24731 Qcircle
= intern_c_string ("circle");
24732 staticpro (&Qcircle
);
24733 Qpoly
= intern_c_string ("poly");
24734 staticpro (&Qpoly
);
24735 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
24736 staticpro (&Qmessage_truncate_lines
);
24737 Qgrow_only
= intern_c_string ("grow-only");
24738 staticpro (&Qgrow_only
);
24739 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
24740 staticpro (&Qinhibit_menubar_update
);
24741 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
24742 staticpro (&Qinhibit_eval_during_redisplay
);
24743 Qposition
= intern_c_string ("position");
24744 staticpro (&Qposition
);
24745 Qbuffer_position
= intern_c_string ("buffer-position");
24746 staticpro (&Qbuffer_position
);
24747 Qobject
= intern_c_string ("object");
24748 staticpro (&Qobject
);
24749 Qbar
= intern_c_string ("bar");
24751 Qhbar
= intern_c_string ("hbar");
24752 staticpro (&Qhbar
);
24753 Qbox
= intern_c_string ("box");
24755 Qhollow
= intern_c_string ("hollow");
24756 staticpro (&Qhollow
);
24757 Qhand
= intern_c_string ("hand");
24758 staticpro (&Qhand
);
24759 Qarrow
= intern_c_string ("arrow");
24760 staticpro (&Qarrow
);
24761 Qtext
= intern_c_string ("text");
24762 staticpro (&Qtext
);
24763 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
24764 staticpro (&Qrisky_local_variable
);
24765 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
24766 staticpro (&Qinhibit_free_realized_faces
);
24768 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
24769 Fcons (intern_c_string ("void-variable"), Qnil
)),
24771 staticpro (&list_of_error
);
24773 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
24774 staticpro (&Qlast_arrow_position
);
24775 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
24776 staticpro (&Qlast_arrow_string
);
24778 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
24779 staticpro (&Qoverlay_arrow_string
);
24780 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
24781 staticpro (&Qoverlay_arrow_bitmap
);
24783 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24784 staticpro (&echo_buffer
[0]);
24785 staticpro (&echo_buffer
[1]);
24787 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24788 staticpro (&echo_area_buffer
[0]);
24789 staticpro (&echo_area_buffer
[1]);
24791 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
24792 staticpro (&Vmessages_buffer_name
);
24794 mode_line_proptrans_alist
= Qnil
;
24795 staticpro (&mode_line_proptrans_alist
);
24796 mode_line_string_list
= Qnil
;
24797 staticpro (&mode_line_string_list
);
24798 mode_line_string_face
= Qnil
;
24799 staticpro (&mode_line_string_face
);
24800 mode_line_string_face_prop
= Qnil
;
24801 staticpro (&mode_line_string_face_prop
);
24802 Vmode_line_unwind_vector
= Qnil
;
24803 staticpro (&Vmode_line_unwind_vector
);
24805 help_echo_string
= Qnil
;
24806 staticpro (&help_echo_string
);
24807 help_echo_object
= Qnil
;
24808 staticpro (&help_echo_object
);
24809 help_echo_window
= Qnil
;
24810 staticpro (&help_echo_window
);
24811 previous_help_echo_string
= Qnil
;
24812 staticpro (&previous_help_echo_string
);
24813 help_echo_pos
= -1;
24815 #ifdef HAVE_WINDOW_SYSTEM
24816 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24817 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24818 For example, if a block cursor is over a tab, it will be drawn as
24819 wide as that tab on the display. */);
24820 x_stretch_cursor_p
= 0;
24823 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24824 doc
: /* *Non-nil means highlight trailing whitespace.
24825 The face used for trailing whitespace is `trailing-whitespace'. */);
24826 Vshow_trailing_whitespace
= Qnil
;
24828 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24829 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24830 A value of t means highlight the character itself (for nobreak space,
24831 use face `nobreak-space').
24832 A value of nil means no highlighting.
24833 Other values mean display the escape glyph followed by an ordinary
24834 space or ordinary hyphen. */);
24835 Vnobreak_char_display
= Qt
;
24837 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24838 doc
: /* *The pointer shape to show in void text areas.
24839 A value of nil means to show the text pointer. Other options are `arrow',
24840 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24841 Vvoid_text_area_pointer
= Qarrow
;
24843 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24844 doc
: /* Non-nil means don't actually do any redisplay.
24845 This is used for internal purposes. */);
24846 Vinhibit_redisplay
= Qnil
;
24848 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24849 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24850 Vglobal_mode_string
= Qnil
;
24852 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24853 doc
: /* Marker for where to display an arrow on top of the buffer text.
24854 This must be the beginning of a line in order to work.
24855 See also `overlay-arrow-string'. */);
24856 Voverlay_arrow_position
= Qnil
;
24858 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24859 doc
: /* String to display as an arrow in non-window frames.
24860 See also `overlay-arrow-position'. */);
24861 Voverlay_arrow_string
= make_pure_c_string ("=>");
24863 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24864 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24865 The symbols on this list are examined during redisplay to determine
24866 where to display overlay arrows. */);
24867 Voverlay_arrow_variable_list
24868 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
24870 DEFVAR_INT ("scroll-step", &scroll_step
,
24871 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24872 If that fails to bring point back on frame, point is centered instead.
24873 If this is zero, point is always centered after it moves off frame.
24874 If you want scrolling to always be a line at a time, you should set
24875 `scroll-conservatively' to a large value rather than set this to 1. */);
24877 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24878 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24879 If point moves off-screen, redisplay will scroll by up to
24880 `scroll-conservatively' lines in order to bring point just barely
24881 onto the screen again. If that cannot be done, then redisplay
24882 recenters point as usual.
24884 A value of zero means always recenter point if it moves off screen. */);
24885 scroll_conservatively
= 0;
24887 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24888 doc
: /* *Number of lines of margin at the top and bottom of a window.
24889 Recenter the window whenever point gets within this many lines
24890 of the top or bottom of the window. */);
24893 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24894 doc
: /* Pixels per inch value for non-window system displays.
24895 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24896 Vdisplay_pixels_per_inch
= make_float (72.0);
24899 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24902 DEFVAR_LISP ("truncate-partial-width-windows",
24903 &Vtruncate_partial_width_windows
,
24904 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
24905 For an integer value, truncate lines in each window narrower than the
24906 full frame width, provided the window width is less than that integer;
24907 otherwise, respect the value of `truncate-lines'.
24909 For any other non-nil value, truncate lines in all windows that do
24910 not span the full frame width.
24912 A value of nil means to respect the value of `truncate-lines'.
24914 If `word-wrap' is enabled, you might want to reduce this. */);
24915 Vtruncate_partial_width_windows
= make_number (50);
24917 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24918 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24919 Any other value means to use the appropriate face, `mode-line',
24920 `header-line', or `menu' respectively. */);
24921 mode_line_inverse_video
= 1;
24923 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24924 doc
: /* *Maximum buffer size for which line number should be displayed.
24925 If the buffer is bigger than this, the line number does not appear
24926 in the mode line. A value of nil means no limit. */);
24927 Vline_number_display_limit
= Qnil
;
24929 DEFVAR_INT ("line-number-display-limit-width",
24930 &line_number_display_limit_width
,
24931 doc
: /* *Maximum line width (in characters) for line number display.
24932 If the average length of the lines near point is bigger than this, then the
24933 line number may be omitted from the mode line. */);
24934 line_number_display_limit_width
= 200;
24936 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24937 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24938 highlight_nonselected_windows
= 0;
24940 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24941 doc
: /* Non-nil if more than one frame is visible on this display.
24942 Minibuffer-only frames don't count, but iconified frames do.
24943 This variable is not guaranteed to be accurate except while processing
24944 `frame-title-format' and `icon-title-format'. */);
24946 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24947 doc
: /* Template for displaying the title bar of visible frames.
24948 \(Assuming the window manager supports this feature.)
24950 This variable has the same structure as `mode-line-format', except that
24951 the %c and %l constructs are ignored. It is used only on frames for
24952 which no explicit name has been set \(see `modify-frame-parameters'). */);
24954 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24955 doc
: /* Template for displaying the title bar of an iconified frame.
24956 \(Assuming the window manager supports this feature.)
24957 This variable has the same structure as `mode-line-format' (which see),
24958 and is used only on frames for which no explicit name has been set
24959 \(see `modify-frame-parameters'). */);
24961 = Vframe_title_format
24962 = pure_cons (intern_c_string ("multiple-frames"),
24963 pure_cons (make_pure_c_string ("%b"),
24964 pure_cons (pure_cons (empty_unibyte_string
,
24965 pure_cons (intern_c_string ("invocation-name"),
24966 pure_cons (make_pure_c_string ("@"),
24967 pure_cons (intern_c_string ("system-name"),
24971 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24972 doc
: /* Maximum number of lines to keep in the message log buffer.
24973 If nil, disable message logging. If t, log messages but don't truncate
24974 the buffer when it becomes large. */);
24975 Vmessage_log_max
= make_number (100);
24977 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24978 doc
: /* Functions called before redisplay, if window sizes have changed.
24979 The value should be a list of functions that take one argument.
24980 Just before redisplay, for each frame, if any of its windows have changed
24981 size since the last redisplay, or have been split or deleted,
24982 all the functions in the list are called, with the frame as argument. */);
24983 Vwindow_size_change_functions
= Qnil
;
24985 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24986 doc
: /* List of functions to call before redisplaying a window with scrolling.
24987 Each function is called with two arguments, the window and its new
24988 display-start position. Note that these functions are also called by
24989 `set-window-buffer'. Also note that the value of `window-end' is not
24990 valid when these functions are called. */);
24991 Vwindow_scroll_functions
= Qnil
;
24993 DEFVAR_LISP ("window-text-change-functions",
24994 &Vwindow_text_change_functions
,
24995 doc
: /* Functions to call in redisplay when text in the window might change. */);
24996 Vwindow_text_change_functions
= Qnil
;
24998 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24999 doc
: /* Functions called when redisplay of a window reaches the end trigger.
25000 Each function is called with two arguments, the window and the end trigger value.
25001 See `set-window-redisplay-end-trigger'. */);
25002 Vredisplay_end_trigger_functions
= Qnil
;
25004 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25005 doc
: /* *Non-nil means autoselect window with mouse pointer.
25006 If nil, do not autoselect windows.
25007 A positive number means delay autoselection by that many seconds: a
25008 window is autoselected only after the mouse has remained in that
25009 window for the duration of the delay.
25010 A negative number has a similar effect, but causes windows to be
25011 autoselected only after the mouse has stopped moving. \(Because of
25012 the way Emacs compares mouse events, you will occasionally wait twice
25013 that time before the window gets selected.\)
25014 Any other value means to autoselect window instantaneously when the
25015 mouse pointer enters it.
25017 Autoselection selects the minibuffer only if it is active, and never
25018 unselects the minibuffer if it is active.
25020 When customizing this variable make sure that the actual value of
25021 `focus-follows-mouse' matches the behavior of your window manager. */);
25022 Vmouse_autoselect_window
= Qnil
;
25024 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25025 doc
: /* *Non-nil means automatically resize tool-bars.
25026 This dynamically changes the tool-bar's height to the minimum height
25027 that is needed to make all tool-bar items visible.
25028 If value is `grow-only', the tool-bar's height is only increased
25029 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25030 Vauto_resize_tool_bars
= Qt
;
25032 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25033 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25034 auto_raise_tool_bar_buttons_p
= 1;
25036 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25037 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25038 make_cursor_line_fully_visible_p
= 1;
25040 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25041 doc
: /* *Border below tool-bar in pixels.
25042 If an integer, use it as the height of the border.
25043 If it is one of `internal-border-width' or `border-width', use the
25044 value of the corresponding frame parameter.
25045 Otherwise, no border is added below the tool-bar. */);
25046 Vtool_bar_border
= Qinternal_border_width
;
25048 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25049 doc
: /* *Margin around tool-bar buttons in pixels.
25050 If an integer, use that for both horizontal and vertical margins.
25051 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25052 HORZ specifying the horizontal margin, and VERT specifying the
25053 vertical margin. */);
25054 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25056 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25057 doc
: /* *Relief thickness of tool-bar buttons. */);
25058 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25060 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25061 doc
: /* List of functions to call to fontify regions of text.
25062 Each function is called with one argument POS. Functions must
25063 fontify a region starting at POS in the current buffer, and give
25064 fontified regions the property `fontified'. */);
25065 Vfontification_functions
= Qnil
;
25066 Fmake_variable_buffer_local (Qfontification_functions
);
25068 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25069 &unibyte_display_via_language_environment
,
25070 doc
: /* *Non-nil means display unibyte text according to language environment.
25071 Specifically, this means that raw bytes in the range 160-255 decimal
25072 are displayed by converting them to the equivalent multibyte characters
25073 according to the current language environment. As a result, they are
25074 displayed according to the current fontset.
25076 Note that this variable affects only how these bytes are displayed,
25077 but does not change the fact they are interpreted as raw bytes. */);
25078 unibyte_display_via_language_environment
= 0;
25080 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25081 doc
: /* *Maximum height for resizing mini-windows.
25082 If a float, it specifies a fraction of the mini-window frame's height.
25083 If an integer, it specifies a number of lines. */);
25084 Vmax_mini_window_height
= make_float (0.25);
25086 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25087 doc
: /* *How to resize mini-windows.
25088 A value of nil means don't automatically resize mini-windows.
25089 A value of t means resize them to fit the text displayed in them.
25090 A value of `grow-only', the default, means let mini-windows grow
25091 only, until their display becomes empty, at which point the windows
25092 go back to their normal size. */);
25093 Vresize_mini_windows
= Qgrow_only
;
25095 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25096 doc
: /* Alist specifying how to blink the cursor off.
25097 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25098 `cursor-type' frame-parameter or variable equals ON-STATE,
25099 comparing using `equal', Emacs uses OFF-STATE to specify
25100 how to blink it off. ON-STATE and OFF-STATE are values for
25101 the `cursor-type' frame parameter.
25103 If a frame's ON-STATE has no entry in this list,
25104 the frame's other specifications determine how to blink the cursor off. */);
25105 Vblink_cursor_alist
= Qnil
;
25107 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25108 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25109 automatic_hscrolling_p
= 1;
25110 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
25111 staticpro (&Qauto_hscroll_mode
);
25113 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25114 doc
: /* *How many columns away from the window edge point is allowed to get
25115 before automatic hscrolling will horizontally scroll the window. */);
25116 hscroll_margin
= 5;
25118 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25119 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25120 When point is less than `hscroll-margin' columns from the window
25121 edge, automatic hscrolling will scroll the window by the amount of columns
25122 determined by this variable. If its value is a positive integer, scroll that
25123 many columns. If it's a positive floating-point number, it specifies the
25124 fraction of the window's width to scroll. If it's nil or zero, point will be
25125 centered horizontally after the scroll. Any other value, including negative
25126 numbers, are treated as if the value were zero.
25128 Automatic hscrolling always moves point outside the scroll margin, so if
25129 point was more than scroll step columns inside the margin, the window will
25130 scroll more than the value given by the scroll step.
25132 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25133 and `scroll-right' overrides this variable's effect. */);
25134 Vhscroll_step
= make_number (0);
25136 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25137 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25138 Bind this around calls to `message' to let it take effect. */);
25139 message_truncate_lines
= 0;
25141 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25142 doc
: /* Normal hook run to update the menu bar definitions.
25143 Redisplay runs this hook before it redisplays the menu bar.
25144 This is used to update submenus such as Buffers,
25145 whose contents depend on various data. */);
25146 Vmenu_bar_update_hook
= Qnil
;
25148 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25149 doc
: /* Frame for which we are updating a menu.
25150 The enable predicate for a menu binding should check this variable. */);
25151 Vmenu_updating_frame
= Qnil
;
25153 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25154 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25155 inhibit_menubar_update
= 0;
25157 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25158 doc
: /* Prefix prepended to all continuation lines at display time.
25159 The value may be a string, an image, or a stretch-glyph; it is
25160 interpreted in the same way as the value of a `display' text property.
25162 This variable is overridden by any `wrap-prefix' text or overlay
25165 To add a prefix to non-continuation lines, use `line-prefix'. */);
25166 Vwrap_prefix
= Qnil
;
25167 staticpro (&Qwrap_prefix
);
25168 Qwrap_prefix
= intern_c_string ("wrap-prefix");
25169 Fmake_variable_buffer_local (Qwrap_prefix
);
25171 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25172 doc
: /* Prefix prepended to all non-continuation lines at display time.
25173 The value may be a string, an image, or a stretch-glyph; it is
25174 interpreted in the same way as the value of a `display' text property.
25176 This variable is overridden by any `line-prefix' text or overlay
25179 To add a prefix to continuation lines, use `wrap-prefix'. */);
25180 Vline_prefix
= Qnil
;
25181 staticpro (&Qline_prefix
);
25182 Qline_prefix
= intern_c_string ("line-prefix");
25183 Fmake_variable_buffer_local (Qline_prefix
);
25185 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25186 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25187 inhibit_eval_during_redisplay
= 0;
25189 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25190 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25191 inhibit_free_realized_faces
= 0;
25194 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25195 doc
: /* Inhibit try_window_id display optimization. */);
25196 inhibit_try_window_id
= 0;
25198 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25199 doc
: /* Inhibit try_window_reusing display optimization. */);
25200 inhibit_try_window_reusing
= 0;
25202 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25203 doc
: /* Inhibit try_cursor_movement display optimization. */);
25204 inhibit_try_cursor_movement
= 0;
25205 #endif /* GLYPH_DEBUG */
25207 DEFVAR_INT ("overline-margin", &overline_margin
,
25208 doc
: /* *Space between overline and text, in pixels.
25209 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25210 margin to the caracter height. */);
25211 overline_margin
= 2;
25213 DEFVAR_INT ("underline-minimum-offset",
25214 &underline_minimum_offset
,
25215 doc
: /* Minimum distance between baseline and underline.
25216 This can improve legibility of underlined text at small font sizes,
25217 particularly when using variable `x-use-underline-position-properties'
25218 with fonts that specify an UNDERLINE_POSITION relatively close to the
25219 baseline. The default value is 1. */);
25220 underline_minimum_offset
= 1;
25222 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25223 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25224 display_hourglass_p
= 1;
25226 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25227 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25228 Value must be an integer or float. */);
25229 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25231 hourglass_atimer
= NULL
;
25232 hourglass_shown_p
= 0;
25236 /* Initialize this module when Emacs starts. */
25241 Lisp_Object root_window
;
25242 struct window
*mini_w
;
25244 current_header_line_height
= current_mode_line_height
= -1;
25246 CHARPOS (this_line_start_pos
) = 0;
25248 mini_w
= XWINDOW (minibuf_window
);
25249 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25251 if (!noninteractive
)
25253 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25256 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25257 set_window_height (root_window
,
25258 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25260 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25261 set_window_height (minibuf_window
, 1, 0);
25263 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25264 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25266 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25267 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25268 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25270 /* The default ellipsis glyphs `...'. */
25271 for (i
= 0; i
< 3; ++i
)
25272 default_invis_vector
[i
] = make_number ('.');
25276 /* Allocate the buffer for frame titles.
25277 Also used for `format-mode-line'. */
25279 mode_line_noprop_buf
= (char *) xmalloc (size
);
25280 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25281 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25282 mode_line_target
= MODE_LINE_DISPLAY
;
25285 help_echo_showing_p
= 0;
25288 /* Since w32 does not support atimers, it defines its own implementation of
25289 the following three functions in w32fns.c. */
25292 /* Platform-independent portion of hourglass implementation. */
25294 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25296 hourglass_started ()
25298 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25301 /* Cancel a currently active hourglass timer, and start a new one. */
25305 #if defined (HAVE_WINDOW_SYSTEM)
25307 int secs
, usecs
= 0;
25309 cancel_hourglass ();
25311 if (INTEGERP (Vhourglass_delay
)
25312 && XINT (Vhourglass_delay
) > 0)
25313 secs
= XFASTINT (Vhourglass_delay
);
25314 else if (FLOATP (Vhourglass_delay
)
25315 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25318 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25319 secs
= XFASTINT (tem
);
25320 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25323 secs
= DEFAULT_HOURGLASS_DELAY
;
25325 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25326 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25327 show_hourglass
, NULL
);
25332 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25335 cancel_hourglass ()
25337 #if defined (HAVE_WINDOW_SYSTEM)
25338 if (hourglass_atimer
)
25340 cancel_atimer (hourglass_atimer
);
25341 hourglass_atimer
= NULL
;
25344 if (hourglass_shown_p
)
25348 #endif /* ! WINDOWSNT */
25350 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25351 (do not change this comment) */