1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
175 #include "keyboard.h"
178 #include "termchar.h"
179 #include "dispextern.h"
181 #include "character.h"
184 #include "commands.h"
188 #include "termhooks.h"
189 #include "intervals.h"
192 #include "region-cache.h"
195 #include "blockinput.h"
197 #ifdef HAVE_X_WINDOWS
212 #ifndef FRAME_X_OUTPUT
213 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
216 #define INFINITY 10000000
218 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
219 || defined(HAVE_NS) || defined (USE_GTK)
220 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
221 extern int pending_menu_activation
;
224 extern int interrupt_input
;
225 extern int command_loop_level
;
227 extern Lisp_Object do_mouse_tracking
;
229 extern int minibuffer_auto_raise
;
230 extern Lisp_Object Vminibuffer_list
;
232 extern Lisp_Object Qface
;
233 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
235 extern Lisp_Object Voverriding_local_map
;
236 extern Lisp_Object Voverriding_local_map_menu_flag
;
237 extern Lisp_Object Qmenu_item
;
238 extern Lisp_Object Qwhen
;
239 extern Lisp_Object Qhelp_echo
;
240 extern Lisp_Object Qbefore_string
, Qafter_string
;
242 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
243 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
244 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
245 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
246 Lisp_Object Qinhibit_point_motion_hooks
;
247 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
248 Lisp_Object Qfontified
;
249 Lisp_Object Qgrow_only
;
250 Lisp_Object Qinhibit_eval_during_redisplay
;
251 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
252 Lisp_Object Qright_to_left
, Qleft_to_right
;
255 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
258 Lisp_Object Qarrow
, Qhand
, Qtext
;
260 Lisp_Object Qrisky_local_variable
;
262 /* Holds the list (error). */
263 Lisp_Object list_of_error
;
265 /* Functions called to fontify regions of text. */
267 Lisp_Object Vfontification_functions
;
268 Lisp_Object Qfontification_functions
;
270 /* Non-nil means automatically select any window when the mouse
271 cursor moves into it. */
272 Lisp_Object Vmouse_autoselect_window
;
274 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
275 Lisp_Object Vline_prefix
, Qline_prefix
;
277 /* Non-zero means draw tool bar buttons raised when the mouse moves
280 int auto_raise_tool_bar_buttons_p
;
282 /* Non-zero means to reposition window if cursor line is only partially visible. */
284 int make_cursor_line_fully_visible_p
;
286 /* Margin below tool bar in pixels. 0 or nil means no margin.
287 If value is `internal-border-width' or `border-width',
288 the corresponding frame parameter is used. */
290 Lisp_Object Vtool_bar_border
;
292 /* Margin around tool bar buttons in pixels. */
294 Lisp_Object Vtool_bar_button_margin
;
296 /* Thickness of shadow to draw around tool bar buttons. */
298 EMACS_INT tool_bar_button_relief
;
300 /* Non-nil means automatically resize tool-bars so that all tool-bar
301 items are visible, and no blank lines remain.
303 If value is `grow-only', only make tool-bar bigger. */
305 Lisp_Object Vauto_resize_tool_bars
;
307 /* Non-zero means draw block and hollow cursor as wide as the glyph
308 under it. For example, if a block cursor is over a tab, it will be
309 drawn as wide as that tab on the display. */
311 int x_stretch_cursor_p
;
313 /* Non-nil means don't actually do any redisplay. */
315 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
317 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
319 int inhibit_eval_during_redisplay
;
321 /* Names of text properties relevant for redisplay. */
323 Lisp_Object Qdisplay
;
324 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
326 /* Symbols used in text property values. */
328 Lisp_Object Vdisplay_pixels_per_inch
;
329 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
330 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
333 Lisp_Object Qmargin
, Qpointer
;
334 Lisp_Object Qline_height
;
335 extern Lisp_Object Qheight
;
336 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
337 extern Lisp_Object Qscroll_bar
;
338 extern Lisp_Object Qcursor
;
340 /* Non-nil means highlight trailing whitespace. */
342 Lisp_Object Vshow_trailing_whitespace
;
344 /* Non-nil means escape non-break space and hyphens. */
346 Lisp_Object Vnobreak_char_display
;
348 #ifdef HAVE_WINDOW_SYSTEM
349 extern Lisp_Object Voverflow_newline_into_fringe
;
351 /* Test if overflow newline into fringe. Called with iterator IT
352 at or past right window margin, and with IT->current_x set. */
354 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
355 (!NILP (Voverflow_newline_into_fringe) \
356 && FRAME_WINDOW_P (it->f) \
357 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
358 && it->current_x == it->last_visible_x \
359 && it->line_wrap != WORD_WRAP)
361 #else /* !HAVE_WINDOW_SYSTEM */
362 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
363 #endif /* HAVE_WINDOW_SYSTEM */
365 /* Test if the display element loaded in IT is a space or tab
366 character. This is used to determine word wrapping. */
368 #define IT_DISPLAYING_WHITESPACE(it) \
369 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
371 /* Non-nil means show the text cursor in void text areas
372 i.e. in blank areas after eol and eob. This used to be
373 the default in 21.3. */
375 Lisp_Object Vvoid_text_area_pointer
;
377 /* Name of the face used to highlight trailing whitespace. */
379 Lisp_Object Qtrailing_whitespace
;
381 /* Name and number of the face used to highlight escape glyphs. */
383 Lisp_Object Qescape_glyph
;
385 /* Name and number of the face used to highlight non-breaking spaces. */
387 Lisp_Object Qnobreak_space
;
389 /* The symbol `image' which is the car of the lists used to represent
394 /* The image map types. */
395 Lisp_Object QCmap
, QCpointer
;
396 Lisp_Object Qrect
, Qcircle
, Qpoly
;
398 /* Non-zero means print newline to stdout before next mini-buffer
401 int noninteractive_need_newline
;
403 /* Non-zero means print newline to message log before next message. */
405 static int message_log_need_newline
;
407 /* Three markers that message_dolog uses.
408 It could allocate them itself, but that causes trouble
409 in handling memory-full errors. */
410 static Lisp_Object message_dolog_marker1
;
411 static Lisp_Object message_dolog_marker2
;
412 static Lisp_Object message_dolog_marker3
;
414 /* The buffer position of the first character appearing entirely or
415 partially on the line of the selected window which contains the
416 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
417 redisplay optimization in redisplay_internal. */
419 static struct text_pos this_line_start_pos
;
421 /* Number of characters past the end of the line above, including the
422 terminating newline. */
424 static struct text_pos this_line_end_pos
;
426 /* The vertical positions and the height of this line. */
428 static int this_line_vpos
;
429 static int this_line_y
;
430 static int this_line_pixel_height
;
432 /* X position at which this display line starts. Usually zero;
433 negative if first character is partially visible. */
435 static int this_line_start_x
;
437 /* Buffer that this_line_.* variables are referring to. */
439 static struct buffer
*this_line_buffer
;
441 /* Nonzero means truncate lines in all windows less wide than the
444 Lisp_Object Vtruncate_partial_width_windows
;
446 /* A flag to control how to display unibyte 8-bit character. */
448 int unibyte_display_via_language_environment
;
450 /* Nonzero means we have more than one non-mini-buffer-only frame.
451 Not guaranteed to be accurate except while parsing
452 frame-title-format. */
456 Lisp_Object Vglobal_mode_string
;
459 /* List of variables (symbols) which hold markers for overlay arrows.
460 The symbols on this list are examined during redisplay to determine
461 where to display overlay arrows. */
463 Lisp_Object Voverlay_arrow_variable_list
;
465 /* Marker for where to display an arrow on top of the buffer text. */
467 Lisp_Object Voverlay_arrow_position
;
469 /* String to display for the arrow. Only used on terminal frames. */
471 Lisp_Object Voverlay_arrow_string
;
473 /* Values of those variables at last redisplay are stored as
474 properties on `overlay-arrow-position' symbol. However, if
475 Voverlay_arrow_position is a marker, last-arrow-position is its
476 numerical position. */
478 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
480 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
481 properties on a symbol in overlay-arrow-variable-list. */
483 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
485 /* Like mode-line-format, but for the title bar on a visible frame. */
487 Lisp_Object Vframe_title_format
;
489 /* Like mode-line-format, but for the title bar on an iconified frame. */
491 Lisp_Object Vicon_title_format
;
493 /* List of functions to call when a window's size changes. These
494 functions get one arg, a frame on which one or more windows' sizes
497 static Lisp_Object Vwindow_size_change_functions
;
499 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
501 /* Nonzero if an overlay arrow has been displayed in this window. */
503 static int overlay_arrow_seen
;
505 /* Nonzero means highlight the region even in nonselected windows. */
507 int highlight_nonselected_windows
;
509 /* If cursor motion alone moves point off frame, try scrolling this
510 many lines up or down if that will bring it back. */
512 static EMACS_INT scroll_step
;
514 /* Nonzero means scroll just far enough to bring point back on the
515 screen, when appropriate. */
517 static EMACS_INT scroll_conservatively
;
519 /* Recenter the window whenever point gets within this many lines of
520 the top or bottom of the window. This value is translated into a
521 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
522 that there is really a fixed pixel height scroll margin. */
524 EMACS_INT scroll_margin
;
526 /* Number of windows showing the buffer of the selected window (or
527 another buffer with the same base buffer). keyboard.c refers to
532 /* Vector containing glyphs for an ellipsis `...'. */
534 static Lisp_Object default_invis_vector
[3];
536 /* Zero means display the mode-line/header-line/menu-bar in the default face
537 (this slightly odd definition is for compatibility with previous versions
538 of emacs), non-zero means display them using their respective faces.
540 This variable is deprecated. */
542 int mode_line_inverse_video
;
544 /* Prompt to display in front of the mini-buffer contents. */
546 Lisp_Object minibuf_prompt
;
548 /* Width of current mini-buffer prompt. Only set after display_line
549 of the line that contains the prompt. */
551 int minibuf_prompt_width
;
553 /* This is the window where the echo area message was displayed. It
554 is always a mini-buffer window, but it may not be the same window
555 currently active as a mini-buffer. */
557 Lisp_Object echo_area_window
;
559 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
560 pushes the current message and the value of
561 message_enable_multibyte on the stack, the function restore_message
562 pops the stack and displays MESSAGE again. */
564 Lisp_Object Vmessage_stack
;
566 /* Nonzero means multibyte characters were enabled when the echo area
567 message was specified. */
569 int message_enable_multibyte
;
571 /* Nonzero if we should redraw the mode lines on the next redisplay. */
573 int update_mode_lines
;
575 /* Nonzero if window sizes or contents have changed since last
576 redisplay that finished. */
578 int windows_or_buffers_changed
;
580 /* Nonzero means a frame's cursor type has been changed. */
582 int cursor_type_changed
;
584 /* Nonzero after display_mode_line if %l was used and it displayed a
587 int line_number_displayed
;
589 /* Maximum buffer size for which to display line numbers. */
591 Lisp_Object Vline_number_display_limit
;
593 /* Line width to consider when repositioning for line number display. */
595 static EMACS_INT line_number_display_limit_width
;
597 /* Number of lines to keep in the message log buffer. t means
598 infinite. nil means don't log at all. */
600 Lisp_Object Vmessage_log_max
;
602 /* The name of the *Messages* buffer, a string. */
604 static Lisp_Object Vmessages_buffer_name
;
606 /* Current, index 0, and last displayed echo area message. Either
607 buffers from echo_buffers, or nil to indicate no message. */
609 Lisp_Object echo_area_buffer
[2];
611 /* The buffers referenced from echo_area_buffer. */
613 static Lisp_Object echo_buffer
[2];
615 /* A vector saved used in with_area_buffer to reduce consing. */
617 static Lisp_Object Vwith_echo_area_save_vector
;
619 /* Non-zero means display_echo_area should display the last echo area
620 message again. Set by redisplay_preserve_echo_area. */
622 static int display_last_displayed_message_p
;
624 /* Nonzero if echo area is being used by print; zero if being used by
627 int message_buf_print
;
629 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
631 Lisp_Object Qinhibit_menubar_update
;
632 int inhibit_menubar_update
;
634 /* When evaluating expressions from menu bar items (enable conditions,
635 for instance), this is the frame they are being processed for. */
637 Lisp_Object Vmenu_updating_frame
;
639 /* Maximum height for resizing mini-windows. Either a float
640 specifying a fraction of the available height, or an integer
641 specifying a number of lines. */
643 Lisp_Object Vmax_mini_window_height
;
645 /* Non-zero means messages should be displayed with truncated
646 lines instead of being continued. */
648 int message_truncate_lines
;
649 Lisp_Object Qmessage_truncate_lines
;
651 /* Set to 1 in clear_message to make redisplay_internal aware
652 of an emptied echo area. */
654 static int message_cleared_p
;
656 /* How to blink the default frame cursor off. */
657 Lisp_Object Vblink_cursor_alist
;
659 /* A scratch glyph row with contents used for generating truncation
660 glyphs. Also used in direct_output_for_insert. */
662 #define MAX_SCRATCH_GLYPHS 100
663 struct glyph_row scratch_glyph_row
;
664 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
666 /* Ascent and height of the last line processed by move_it_to. */
668 static int last_max_ascent
, last_height
;
670 /* Non-zero if there's a help-echo in the echo area. */
672 int help_echo_showing_p
;
674 /* If >= 0, computed, exact values of mode-line and header-line height
675 to use in the macros CURRENT_MODE_LINE_HEIGHT and
676 CURRENT_HEADER_LINE_HEIGHT. */
678 int current_mode_line_height
, current_header_line_height
;
680 /* The maximum distance to look ahead for text properties. Values
681 that are too small let us call compute_char_face and similar
682 functions too often which is expensive. Values that are too large
683 let us call compute_char_face and alike too often because we
684 might not be interested in text properties that far away. */
686 #define TEXT_PROP_DISTANCE_LIMIT 100
690 /* Variables to turn off display optimizations from Lisp. */
692 int inhibit_try_window_id
, inhibit_try_window_reusing
;
693 int inhibit_try_cursor_movement
;
695 /* Non-zero means print traces of redisplay if compiled with
698 int trace_redisplay_p
;
700 #endif /* GLYPH_DEBUG */
702 #ifdef DEBUG_TRACE_MOVE
703 /* Non-zero means trace with TRACE_MOVE to stderr. */
706 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
708 #define TRACE_MOVE(x) (void) 0
711 /* Non-zero means automatically scroll windows horizontally to make
714 int automatic_hscrolling_p
;
715 Lisp_Object Qauto_hscroll_mode
;
717 /* How close to the margin can point get before the window is scrolled
719 EMACS_INT hscroll_margin
;
721 /* How much to scroll horizontally when point is inside the above margin. */
722 Lisp_Object Vhscroll_step
;
724 /* The variable `resize-mini-windows'. If nil, don't resize
725 mini-windows. If t, always resize them to fit the text they
726 display. If `grow-only', let mini-windows grow only until they
729 Lisp_Object Vresize_mini_windows
;
731 /* Buffer being redisplayed -- for redisplay_window_error. */
733 struct buffer
*displayed_buffer
;
735 /* Space between overline and text. */
737 EMACS_INT overline_margin
;
739 /* Require underline to be at least this many screen pixels below baseline
740 This to avoid underline "merging" with the base of letters at small
741 font sizes, particularly when x_use_underline_position_properties is on. */
743 EMACS_INT underline_minimum_offset
;
745 /* Value returned from text property handlers (see below). */
750 HANDLED_RECOMPUTE_PROPS
,
751 HANDLED_OVERLAY_STRING_CONSUMED
,
755 /* A description of text properties that redisplay is interested
760 /* The name of the property. */
763 /* A unique index for the property. */
766 /* A handler function called to set up iterator IT from the property
767 at IT's current position. Value is used to steer handle_stop. */
768 enum prop_handled (*handler
) P_ ((struct it
*it
));
771 static enum prop_handled handle_face_prop
P_ ((struct it
*));
772 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
773 static enum prop_handled handle_display_prop
P_ ((struct it
*));
774 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
775 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
776 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
778 /* Properties handled by iterators. */
780 static struct props it_props
[] =
782 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
783 /* Handle `face' before `display' because some sub-properties of
784 `display' need to know the face. */
785 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
786 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
787 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
788 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
792 /* Value is the position described by X. If X is a marker, value is
793 the marker_position of X. Otherwise, value is X. */
795 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
797 /* Enumeration returned by some move_it_.* functions internally. */
801 /* Not used. Undefined value. */
804 /* Move ended at the requested buffer position or ZV. */
805 MOVE_POS_MATCH_OR_ZV
,
807 /* Move ended at the requested X pixel position. */
810 /* Move within a line ended at the end of a line that must be
814 /* Move within a line ended at the end of a line that would
815 be displayed truncated. */
818 /* Move within a line ended at a line end. */
822 /* This counter is used to clear the face cache every once in a while
823 in redisplay_internal. It is incremented for each redisplay.
824 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
827 #define CLEAR_FACE_CACHE_COUNT 500
828 static int clear_face_cache_count
;
830 /* Similarly for the image cache. */
832 #ifdef HAVE_WINDOW_SYSTEM
833 #define CLEAR_IMAGE_CACHE_COUNT 101
834 static int clear_image_cache_count
;
837 /* Non-zero while redisplay_internal is in progress. */
841 /* Non-zero means don't free realized faces. Bound while freeing
842 realized faces is dangerous because glyph matrices might still
845 int inhibit_free_realized_faces
;
846 Lisp_Object Qinhibit_free_realized_faces
;
848 /* If a string, XTread_socket generates an event to display that string.
849 (The display is done in read_char.) */
851 Lisp_Object help_echo_string
;
852 Lisp_Object help_echo_window
;
853 Lisp_Object help_echo_object
;
856 /* Temporary variable for XTread_socket. */
858 Lisp_Object previous_help_echo_string
;
860 /* Null glyph slice */
862 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
864 /* Platform-independent portion of hourglass implementation. */
866 /* Non-zero means we're allowed to display a hourglass pointer. */
867 int display_hourglass_p
;
869 /* Non-zero means an hourglass cursor is currently shown. */
870 int hourglass_shown_p
;
872 /* If non-null, an asynchronous timer that, when it expires, displays
873 an hourglass cursor on all frames. */
874 struct atimer
*hourglass_atimer
;
876 /* Number of seconds to wait before displaying an hourglass cursor. */
877 Lisp_Object Vhourglass_delay
;
879 /* Default number of seconds to wait before displaying an hourglass
881 #define DEFAULT_HOURGLASS_DELAY 1
884 /* Function prototypes. */
886 static void setup_for_ellipsis
P_ ((struct it
*, int));
887 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
888 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
889 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
890 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
891 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
892 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
894 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
896 static void handle_line_prefix
P_ ((struct it
*));
898 static void pint2str
P_ ((char *, int, int));
899 static void pint2hrstr
P_ ((char *, int, int));
900 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
902 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
903 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
904 static void store_mode_line_noprop_char
P_ ((char));
905 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
906 static void x_consider_frame_title
P_ ((Lisp_Object
));
907 static void handle_stop
P_ ((struct it
*));
908 static void handle_stop_backwards
P_ ((struct it
*, EMACS_INT
));
909 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
910 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
911 static void ensure_echo_area_buffers
P_ ((void));
912 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
913 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
914 static int with_echo_area_buffer
P_ ((struct window
*, int,
915 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
916 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static void clear_garbaged_frames
P_ ((void));
918 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
919 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
920 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
921 static int display_echo_area
P_ ((struct window
*));
922 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
923 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
924 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
925 static int string_char_and_length
P_ ((const unsigned char *, int *));
926 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
928 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
929 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
930 static void insert_left_trunc_glyphs
P_ ((struct it
*));
931 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
933 static void extend_face_to_end_of_line
P_ ((struct it
*));
934 static int append_space_for_newline
P_ ((struct it
*, int));
935 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
936 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
937 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
938 static int trailing_whitespace_p
P_ ((int));
939 static int message_log_check_duplicate
P_ ((int, int, int, int));
940 static void push_it
P_ ((struct it
*));
941 static void pop_it
P_ ((struct it
*));
942 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
943 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
944 static void redisplay_internal
P_ ((int));
945 static int echo_area_display
P_ ((int));
946 static void redisplay_windows
P_ ((Lisp_Object
));
947 static void redisplay_window
P_ ((Lisp_Object
, int));
948 static Lisp_Object
redisplay_window_error ();
949 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
950 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
951 static int update_menu_bar
P_ ((struct frame
*, int, int));
952 static int try_window_reusing_current_matrix
P_ ((struct window
*));
953 static int try_window_id
P_ ((struct window
*));
954 static int display_line
P_ ((struct it
*));
955 static int display_mode_lines
P_ ((struct window
*));
956 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
957 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
958 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
959 static char *decode_mode_spec
P_ ((struct window
*, int, int, int,
961 static void display_menu_bar
P_ ((struct window
*));
962 static int display_count_lines
P_ ((int, int, int, int, int *));
963 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
964 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
965 static void compute_line_metrics
P_ ((struct it
*));
966 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
967 static int get_overlay_strings
P_ ((struct it
*, int));
968 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
969 static void next_overlay_string
P_ ((struct it
*));
970 static void reseat
P_ ((struct it
*, struct text_pos
, int));
971 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
972 static void back_to_previous_visible_line_start
P_ ((struct it
*));
973 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
974 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
975 static int next_element_from_ellipsis
P_ ((struct it
*));
976 static int next_element_from_display_vector
P_ ((struct it
*));
977 static int next_element_from_string
P_ ((struct it
*));
978 static int next_element_from_c_string
P_ ((struct it
*));
979 static int next_element_from_buffer
P_ ((struct it
*));
980 static int next_element_from_composition
P_ ((struct it
*));
981 static int next_element_from_image
P_ ((struct it
*));
982 static int next_element_from_stretch
P_ ((struct it
*));
983 static void load_overlay_strings
P_ ((struct it
*, int));
984 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
985 struct display_pos
*));
986 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
987 Lisp_Object
, int, int, int, int));
988 static enum move_it_result
989 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
990 enum move_operation_enum
);
991 void move_it_vertically_backward
P_ ((struct it
*, int));
992 static void init_to_row_start
P_ ((struct it
*, struct window
*,
993 struct glyph_row
*));
994 static int init_to_row_end
P_ ((struct it
*, struct window
*,
995 struct glyph_row
*));
996 static void back_to_previous_line_start
P_ ((struct it
*));
997 static int forward_to_next_line_start
P_ ((struct it
*, int *));
998 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
1000 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
1001 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
1002 static int number_of_chars
P_ ((unsigned char *, int));
1003 static void compute_stop_pos
P_ ((struct it
*));
1004 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1006 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1007 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1008 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1009 Lisp_Object
, Lisp_Object
,
1010 struct text_pos
*, int));
1011 static int underlying_face_id
P_ ((struct it
*));
1012 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1015 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1016 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1018 #ifdef HAVE_WINDOW_SYSTEM
1020 static void update_tool_bar
P_ ((struct frame
*, int));
1021 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1022 static int redisplay_tool_bar
P_ ((struct frame
*));
1023 static void display_tool_bar_line
P_ ((struct it
*, int));
1024 static void notice_overwritten_cursor
P_ ((struct window
*,
1025 enum glyph_row_area
,
1026 int, int, int, int));
1030 #endif /* HAVE_WINDOW_SYSTEM */
1033 /***********************************************************************
1034 Window display dimensions
1035 ***********************************************************************/
1037 /* Return the bottom boundary y-position for text lines in window W.
1038 This is the first y position at which a line cannot start.
1039 It is relative to the top of the window.
1041 This is the height of W minus the height of a mode line, if any. */
1044 window_text_bottom_y (w
)
1047 int height
= WINDOW_TOTAL_HEIGHT (w
);
1049 if (WINDOW_WANTS_MODELINE_P (w
))
1050 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1054 /* Return the pixel width of display area AREA of window W. AREA < 0
1055 means return the total width of W, not including fringes to
1056 the left and right of the window. */
1059 window_box_width (w
, area
)
1063 int cols
= XFASTINT (w
->total_cols
);
1066 if (!w
->pseudo_window_p
)
1068 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1070 if (area
== TEXT_AREA
)
1072 if (INTEGERP (w
->left_margin_cols
))
1073 cols
-= XFASTINT (w
->left_margin_cols
);
1074 if (INTEGERP (w
->right_margin_cols
))
1075 cols
-= XFASTINT (w
->right_margin_cols
);
1076 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1078 else if (area
== LEFT_MARGIN_AREA
)
1080 cols
= (INTEGERP (w
->left_margin_cols
)
1081 ? XFASTINT (w
->left_margin_cols
) : 0);
1084 else if (area
== RIGHT_MARGIN_AREA
)
1086 cols
= (INTEGERP (w
->right_margin_cols
)
1087 ? XFASTINT (w
->right_margin_cols
) : 0);
1092 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1096 /* Return the pixel height of the display area of window W, not
1097 including mode lines of W, if any. */
1100 window_box_height (w
)
1103 struct frame
*f
= XFRAME (w
->frame
);
1104 int height
= WINDOW_TOTAL_HEIGHT (w
);
1106 xassert (height
>= 0);
1108 /* Note: the code below that determines the mode-line/header-line
1109 height is essentially the same as that contained in the macro
1110 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1111 the appropriate glyph row has its `mode_line_p' flag set,
1112 and if it doesn't, uses estimate_mode_line_height instead. */
1114 if (WINDOW_WANTS_MODELINE_P (w
))
1116 struct glyph_row
*ml_row
1117 = (w
->current_matrix
&& w
->current_matrix
->rows
1118 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1120 if (ml_row
&& ml_row
->mode_line_p
)
1121 height
-= ml_row
->height
;
1123 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1126 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1128 struct glyph_row
*hl_row
1129 = (w
->current_matrix
&& w
->current_matrix
->rows
1130 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1132 if (hl_row
&& hl_row
->mode_line_p
)
1133 height
-= hl_row
->height
;
1135 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1138 /* With a very small font and a mode-line that's taller than
1139 default, we might end up with a negative height. */
1140 return max (0, height
);
1143 /* Return the window-relative coordinate of the left edge of display
1144 area AREA of window W. AREA < 0 means return the left edge of the
1145 whole window, to the right of the left fringe of W. */
1148 window_box_left_offset (w
, area
)
1154 if (w
->pseudo_window_p
)
1157 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1159 if (area
== TEXT_AREA
)
1160 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1161 + window_box_width (w
, LEFT_MARGIN_AREA
));
1162 else if (area
== RIGHT_MARGIN_AREA
)
1163 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1164 + window_box_width (w
, LEFT_MARGIN_AREA
)
1165 + window_box_width (w
, TEXT_AREA
)
1166 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1168 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1169 else if (area
== LEFT_MARGIN_AREA
1170 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1171 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1177 /* Return the window-relative coordinate of the right edge of display
1178 area AREA of window W. AREA < 0 means return the left edge of the
1179 whole window, to the left of the right fringe of W. */
1182 window_box_right_offset (w
, area
)
1186 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1189 /* Return the frame-relative coordinate of the left edge of display
1190 area AREA of window W. AREA < 0 means return the left edge of the
1191 whole window, to the right of the left fringe of W. */
1194 window_box_left (w
, area
)
1198 struct frame
*f
= XFRAME (w
->frame
);
1201 if (w
->pseudo_window_p
)
1202 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1204 x
= (WINDOW_LEFT_EDGE_X (w
)
1205 + window_box_left_offset (w
, area
));
1211 /* Return the frame-relative coordinate of the right edge of display
1212 area AREA of window W. AREA < 0 means return the left edge of the
1213 whole window, to the left of the right fringe of W. */
1216 window_box_right (w
, area
)
1220 return window_box_left (w
, area
) + window_box_width (w
, area
);
1223 /* Get the bounding box of the display area AREA of window W, without
1224 mode lines, in frame-relative coordinates. AREA < 0 means the
1225 whole window, not including the left and right fringes of
1226 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1227 coordinates of the upper-left corner of the box. Return in
1228 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1231 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1234 int *box_x
, *box_y
, *box_width
, *box_height
;
1237 *box_width
= window_box_width (w
, area
);
1239 *box_height
= window_box_height (w
);
1241 *box_x
= window_box_left (w
, area
);
1244 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1245 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1246 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1251 /* Get the bounding box of the display area AREA of window W, without
1252 mode lines. AREA < 0 means the whole window, not including the
1253 left and right fringe of the window. Return in *TOP_LEFT_X
1254 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1255 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1256 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1260 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1261 bottom_right_x
, bottom_right_y
)
1264 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1266 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1268 *bottom_right_x
+= *top_left_x
;
1269 *bottom_right_y
+= *top_left_y
;
1274 /***********************************************************************
1276 ***********************************************************************/
1278 /* Return the bottom y-position of the line the iterator IT is in.
1279 This can modify IT's settings. */
1285 int line_height
= it
->max_ascent
+ it
->max_descent
;
1286 int line_top_y
= it
->current_y
;
1288 if (line_height
== 0)
1291 line_height
= last_height
;
1292 else if (IT_CHARPOS (*it
) < ZV
)
1294 move_it_by_lines (it
, 1, 1);
1295 line_height
= (it
->max_ascent
|| it
->max_descent
1296 ? it
->max_ascent
+ it
->max_descent
1301 struct glyph_row
*row
= it
->glyph_row
;
1303 /* Use the default character height. */
1304 it
->glyph_row
= NULL
;
1305 it
->what
= IT_CHARACTER
;
1308 PRODUCE_GLYPHS (it
);
1309 line_height
= it
->ascent
+ it
->descent
;
1310 it
->glyph_row
= row
;
1314 return line_top_y
+ line_height
;
1318 /* Return 1 if position CHARPOS is visible in window W.
1319 CHARPOS < 0 means return info about WINDOW_END position.
1320 If visible, set *X and *Y to pixel coordinates of top left corner.
1321 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1322 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1325 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1327 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1330 struct text_pos top
;
1332 struct buffer
*old_buffer
= NULL
;
1334 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1337 if (XBUFFER (w
->buffer
) != current_buffer
)
1339 old_buffer
= current_buffer
;
1340 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1343 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1345 /* Compute exact mode line heights. */
1346 if (WINDOW_WANTS_MODELINE_P (w
))
1347 current_mode_line_height
1348 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1349 current_buffer
->mode_line_format
);
1351 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1352 current_header_line_height
1353 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1354 current_buffer
->header_line_format
);
1356 start_display (&it
, w
, top
);
1357 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1358 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1360 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1362 /* We have reached CHARPOS, or passed it. How the call to
1363 move_it_to can overshoot: (i) If CHARPOS is on invisible
1364 text, move_it_to stops at the end of the invisible text,
1365 after CHARPOS. (ii) If CHARPOS is in a display vector,
1366 move_it_to stops on its last glyph. */
1367 int top_x
= it
.current_x
;
1368 int top_y
= it
.current_y
;
1369 enum it_method it_method
= it
.method
;
1370 /* Calling line_bottom_y may change it.method, it.position, etc. */
1371 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1372 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1374 if (top_y
< window_top_y
)
1375 visible_p
= bottom_y
> window_top_y
;
1376 else if (top_y
< it
.last_visible_y
)
1380 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1382 /* We stopped on the last glyph of a display vector.
1383 Try and recompute. Hack alert! */
1384 if (charpos
< 2 || top
.charpos
>= charpos
)
1385 top_x
= it
.glyph_row
->x
;
1389 start_display (&it2
, w
, top
);
1390 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1391 get_next_display_element (&it2
);
1392 PRODUCE_GLYPHS (&it2
);
1393 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1394 || it2
.current_x
> it2
.last_visible_x
)
1395 top_x
= it
.glyph_row
->x
;
1398 top_x
= it2
.current_x
;
1399 top_y
= it2
.current_y
;
1405 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1406 *rtop
= max (0, window_top_y
- top_y
);
1407 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1408 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1409 - max (top_y
, window_top_y
)));
1418 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1419 move_it_by_lines (&it
, 1, 0);
1420 if (charpos
< IT_CHARPOS (it
)
1421 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1424 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1426 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1427 *rtop
= max (0, -it2
.current_y
);
1428 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1429 - it
.last_visible_y
));
1430 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1432 - max (it2
.current_y
,
1433 WINDOW_HEADER_LINE_HEIGHT (w
))));
1439 set_buffer_internal_1 (old_buffer
);
1441 current_header_line_height
= current_mode_line_height
= -1;
1443 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1444 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1447 /* Debugging code. */
1449 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1450 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1452 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1459 /* Return the next character from STR which is MAXLEN bytes long.
1460 Return in *LEN the length of the character. This is like
1461 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1462 we find one, we return a `?', but with the length of the invalid
1466 string_char_and_length (str
, len
)
1467 const unsigned char *str
;
1472 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1473 if (!CHAR_VALID_P (c
, 1))
1474 /* We may not change the length here because other places in Emacs
1475 don't use this function, i.e. they silently accept invalid
1484 /* Given a position POS containing a valid character and byte position
1485 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1487 static struct text_pos
1488 string_pos_nchars_ahead (pos
, string
, nchars
)
1489 struct text_pos pos
;
1493 xassert (STRINGP (string
) && nchars
>= 0);
1495 if (STRING_MULTIBYTE (string
))
1497 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1498 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1503 string_char_and_length (p
, &len
);
1504 p
+= len
, rest
-= len
;
1505 xassert (rest
>= 0);
1507 BYTEPOS (pos
) += len
;
1511 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1517 /* Value is the text position, i.e. character and byte position,
1518 for character position CHARPOS in STRING. */
1520 static INLINE
struct text_pos
1521 string_pos (charpos
, string
)
1525 struct text_pos pos
;
1526 xassert (STRINGP (string
));
1527 xassert (charpos
>= 0);
1528 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1533 /* Value is a text position, i.e. character and byte position, for
1534 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1535 means recognize multibyte characters. */
1537 static struct text_pos
1538 c_string_pos (charpos
, s
, multibyte_p
)
1543 struct text_pos pos
;
1545 xassert (s
!= NULL
);
1546 xassert (charpos
>= 0);
1550 int rest
= strlen (s
), len
;
1552 SET_TEXT_POS (pos
, 0, 0);
1555 string_char_and_length (s
, &len
);
1556 s
+= len
, rest
-= len
;
1557 xassert (rest
>= 0);
1559 BYTEPOS (pos
) += len
;
1563 SET_TEXT_POS (pos
, charpos
, charpos
);
1569 /* Value is the number of characters in C string S. MULTIBYTE_P
1570 non-zero means recognize multibyte characters. */
1573 number_of_chars (s
, multibyte_p
)
1581 int rest
= strlen (s
), len
;
1582 unsigned char *p
= (unsigned char *) s
;
1584 for (nchars
= 0; rest
> 0; ++nchars
)
1586 string_char_and_length (p
, &len
);
1587 rest
-= len
, p
+= len
;
1591 nchars
= strlen (s
);
1597 /* Compute byte position NEWPOS->bytepos corresponding to
1598 NEWPOS->charpos. POS is a known position in string STRING.
1599 NEWPOS->charpos must be >= POS.charpos. */
1602 compute_string_pos (newpos
, pos
, string
)
1603 struct text_pos
*newpos
, pos
;
1606 xassert (STRINGP (string
));
1607 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1609 if (STRING_MULTIBYTE (string
))
1610 *newpos
= string_pos_nchars_ahead (pos
, string
,
1611 CHARPOS (*newpos
) - CHARPOS (pos
));
1613 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1617 Return an estimation of the pixel height of mode or header lines on
1618 frame F. FACE_ID specifies what line's height to estimate. */
1621 estimate_mode_line_height (f
, face_id
)
1623 enum face_id face_id
;
1625 #ifdef HAVE_WINDOW_SYSTEM
1626 if (FRAME_WINDOW_P (f
))
1628 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1630 /* This function is called so early when Emacs starts that the face
1631 cache and mode line face are not yet initialized. */
1632 if (FRAME_FACE_CACHE (f
))
1634 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1638 height
= FONT_HEIGHT (face
->font
);
1639 if (face
->box_line_width
> 0)
1640 height
+= 2 * face
->box_line_width
;
1651 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1652 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1653 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1654 not force the value into range. */
1657 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1659 register int pix_x
, pix_y
;
1661 NativeRectangle
*bounds
;
1665 #ifdef HAVE_WINDOW_SYSTEM
1666 if (FRAME_WINDOW_P (f
))
1668 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1669 even for negative values. */
1671 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1673 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1675 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1676 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1679 STORE_NATIVE_RECT (*bounds
,
1680 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1681 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1682 FRAME_COLUMN_WIDTH (f
) - 1,
1683 FRAME_LINE_HEIGHT (f
) - 1);
1689 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1690 pix_x
= FRAME_TOTAL_COLS (f
);
1694 else if (pix_y
> FRAME_LINES (f
))
1695 pix_y
= FRAME_LINES (f
);
1705 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1706 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1707 can't tell the positions because W's display is not up to date,
1711 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1714 int *frame_x
, *frame_y
;
1716 #ifdef HAVE_WINDOW_SYSTEM
1717 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1721 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1722 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1724 if (display_completed
)
1726 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1727 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1728 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1734 hpos
+= glyph
->pixel_width
;
1738 /* If first glyph is partially visible, its first visible position is still 0. */
1750 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1751 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1762 #ifdef HAVE_WINDOW_SYSTEM
1764 /* Find the glyph under window-relative coordinates X/Y in window W.
1765 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1766 strings. Return in *HPOS and *VPOS the row and column number of
1767 the glyph found. Return in *AREA the glyph area containing X.
1768 Value is a pointer to the glyph found or null if X/Y is not on
1769 text, or we can't tell because W's current matrix is not up to
1774 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1777 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1779 struct glyph
*glyph
, *end
;
1780 struct glyph_row
*row
= NULL
;
1783 /* Find row containing Y. Give up if some row is not enabled. */
1784 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1786 row
= MATRIX_ROW (w
->current_matrix
, i
);
1787 if (!row
->enabled_p
)
1789 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1796 /* Give up if Y is not in the window. */
1797 if (i
== w
->current_matrix
->nrows
)
1800 /* Get the glyph area containing X. */
1801 if (w
->pseudo_window_p
)
1808 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1810 *area
= LEFT_MARGIN_AREA
;
1811 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1813 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1816 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1820 *area
= RIGHT_MARGIN_AREA
;
1821 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1825 /* Find glyph containing X. */
1826 glyph
= row
->glyphs
[*area
];
1827 end
= glyph
+ row
->used
[*area
];
1829 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1831 x
-= glyph
->pixel_width
;
1841 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1844 *hpos
= glyph
- row
->glyphs
[*area
];
1850 Convert frame-relative x/y to coordinates relative to window W.
1851 Takes pseudo-windows into account. */
1854 frame_to_window_pixel_xy (w
, x
, y
)
1858 if (w
->pseudo_window_p
)
1860 /* A pseudo-window is always full-width, and starts at the
1861 left edge of the frame, plus a frame border. */
1862 struct frame
*f
= XFRAME (w
->frame
);
1863 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1864 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1868 *x
-= WINDOW_LEFT_EDGE_X (w
);
1869 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1874 Return in RECTS[] at most N clipping rectangles for glyph string S.
1875 Return the number of stored rectangles. */
1878 get_glyph_string_clip_rects (s
, rects
, n
)
1879 struct glyph_string
*s
;
1880 NativeRectangle
*rects
;
1888 if (s
->row
->full_width_p
)
1890 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1891 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1892 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1894 /* Unless displaying a mode or menu bar line, which are always
1895 fully visible, clip to the visible part of the row. */
1896 if (s
->w
->pseudo_window_p
)
1897 r
.height
= s
->row
->visible_height
;
1899 r
.height
= s
->height
;
1903 /* This is a text line that may be partially visible. */
1904 r
.x
= window_box_left (s
->w
, s
->area
);
1905 r
.width
= window_box_width (s
->w
, s
->area
);
1906 r
.height
= s
->row
->visible_height
;
1910 if (r
.x
< s
->clip_head
->x
)
1912 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1913 r
.width
-= s
->clip_head
->x
- r
.x
;
1916 r
.x
= s
->clip_head
->x
;
1919 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1921 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1922 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1927 /* If S draws overlapping rows, it's sufficient to use the top and
1928 bottom of the window for clipping because this glyph string
1929 intentionally draws over other lines. */
1930 if (s
->for_overlaps
)
1932 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1933 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1935 /* Alas, the above simple strategy does not work for the
1936 environments with anti-aliased text: if the same text is
1937 drawn onto the same place multiple times, it gets thicker.
1938 If the overlap we are processing is for the erased cursor, we
1939 take the intersection with the rectagle of the cursor. */
1940 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1942 XRectangle rc
, r_save
= r
;
1944 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1945 rc
.y
= s
->w
->phys_cursor
.y
;
1946 rc
.width
= s
->w
->phys_cursor_width
;
1947 rc
.height
= s
->w
->phys_cursor_height
;
1949 x_intersect_rectangles (&r_save
, &rc
, &r
);
1954 /* Don't use S->y for clipping because it doesn't take partially
1955 visible lines into account. For example, it can be negative for
1956 partially visible lines at the top of a window. */
1957 if (!s
->row
->full_width_p
1958 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1959 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1961 r
.y
= max (0, s
->row
->y
);
1964 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1966 /* If drawing the cursor, don't let glyph draw outside its
1967 advertised boundaries. Cleartype does this under some circumstances. */
1968 if (s
->hl
== DRAW_CURSOR
)
1970 struct glyph
*glyph
= s
->first_glyph
;
1975 r
.width
-= s
->x
- r
.x
;
1978 r
.width
= min (r
.width
, glyph
->pixel_width
);
1980 /* If r.y is below window bottom, ensure that we still see a cursor. */
1981 height
= min (glyph
->ascent
+ glyph
->descent
,
1982 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1983 max_y
= window_text_bottom_y (s
->w
) - height
;
1984 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1985 if (s
->ybase
- glyph
->ascent
> max_y
)
1992 /* Don't draw cursor glyph taller than our actual glyph. */
1993 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1994 if (height
< r
.height
)
1996 max_y
= r
.y
+ r
.height
;
1997 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1998 r
.height
= min (max_y
- r
.y
, height
);
2005 XRectangle r_save
= r
;
2007 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2011 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2012 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2014 #ifdef CONVERT_FROM_XRECT
2015 CONVERT_FROM_XRECT (r
, *rects
);
2023 /* If we are processing overlapping and allowed to return
2024 multiple clipping rectangles, we exclude the row of the glyph
2025 string from the clipping rectangle. This is to avoid drawing
2026 the same text on the environment with anti-aliasing. */
2027 #ifdef CONVERT_FROM_XRECT
2030 XRectangle
*rs
= rects
;
2032 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2034 if (s
->for_overlaps
& OVERLAPS_PRED
)
2037 if (r
.y
+ r
.height
> row_y
)
2040 rs
[i
].height
= row_y
- r
.y
;
2046 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2049 if (r
.y
< row_y
+ s
->row
->visible_height
)
2051 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2053 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2054 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2063 #ifdef CONVERT_FROM_XRECT
2064 for (i
= 0; i
< n
; i
++)
2065 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2072 Return in *NR the clipping rectangle for glyph string S. */
2075 get_glyph_string_clip_rect (s
, nr
)
2076 struct glyph_string
*s
;
2077 NativeRectangle
*nr
;
2079 get_glyph_string_clip_rects (s
, nr
, 1);
2084 Return the position and height of the phys cursor in window W.
2085 Set w->phys_cursor_width to width of phys cursor.
2089 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2091 struct glyph_row
*row
;
2092 struct glyph
*glyph
;
2093 int *xp
, *yp
, *heightp
;
2095 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2096 int x
, y
, wd
, h
, h0
, y0
;
2098 /* Compute the width of the rectangle to draw. If on a stretch
2099 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2100 rectangle as wide as the glyph, but use a canonical character
2102 wd
= glyph
->pixel_width
- 1;
2103 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2107 x
= w
->phys_cursor
.x
;
2114 if (glyph
->type
== STRETCH_GLYPH
2115 && !x_stretch_cursor_p
)
2116 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2117 w
->phys_cursor_width
= wd
;
2119 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2121 /* If y is below window bottom, ensure that we still see a cursor. */
2122 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2124 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2125 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2127 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2130 h
= max (h
- (y0
- y
) + 1, h0
);
2135 y0
= window_text_bottom_y (w
) - h0
;
2143 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2144 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2149 * Remember which glyph the mouse is over.
2153 remember_mouse_glyph (f
, gx
, gy
, rect
)
2156 NativeRectangle
*rect
;
2160 struct glyph_row
*r
, *gr
, *end_row
;
2161 enum window_part part
;
2162 enum glyph_row_area area
;
2163 int x
, y
, width
, height
;
2165 /* Try to determine frame pixel position and size of the glyph under
2166 frame pixel coordinates X/Y on frame F. */
2168 if (!f
->glyphs_initialized_p
2169 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2172 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2173 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2177 w
= XWINDOW (window
);
2178 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2179 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2181 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2182 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2184 if (w
->pseudo_window_p
)
2187 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2193 case ON_LEFT_MARGIN
:
2194 area
= LEFT_MARGIN_AREA
;
2197 case ON_RIGHT_MARGIN
:
2198 area
= RIGHT_MARGIN_AREA
;
2201 case ON_HEADER_LINE
:
2203 gr
= (part
== ON_HEADER_LINE
2204 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2205 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2208 goto text_glyph_row_found
;
2215 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2216 if (r
->y
+ r
->height
> y
)
2222 text_glyph_row_found
:
2225 struct glyph
*g
= gr
->glyphs
[area
];
2226 struct glyph
*end
= g
+ gr
->used
[area
];
2228 height
= gr
->height
;
2229 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2230 if (gx
+ g
->pixel_width
> x
)
2235 if (g
->type
== IMAGE_GLYPH
)
2237 /* Don't remember when mouse is over image, as
2238 image may have hot-spots. */
2239 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2242 width
= g
->pixel_width
;
2246 /* Use nominal char spacing at end of line. */
2248 gx
+= (x
/ width
) * width
;
2251 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2252 gx
+= window_box_left_offset (w
, area
);
2256 /* Use nominal line height at end of window. */
2257 gx
= (x
/ width
) * width
;
2259 gy
+= (y
/ height
) * height
;
2263 case ON_LEFT_FRINGE
:
2264 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2265 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2266 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2267 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2270 case ON_RIGHT_FRINGE
:
2271 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2272 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2273 : window_box_right_offset (w
, TEXT_AREA
));
2274 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2278 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2280 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2281 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2282 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2284 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2288 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2289 if (r
->y
+ r
->height
> y
)
2296 height
= gr
->height
;
2299 /* Use nominal line height at end of window. */
2301 gy
+= (y
/ height
) * height
;
2308 /* If there is no glyph under the mouse, then we divide the screen
2309 into a grid of the smallest glyph in the frame, and use that
2312 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2313 round down even for negative values. */
2319 gx
= (gx
/ width
) * width
;
2320 gy
= (gy
/ height
) * height
;
2325 gx
+= WINDOW_LEFT_EDGE_X (w
);
2326 gy
+= WINDOW_TOP_EDGE_Y (w
);
2329 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2331 /* Visible feedback for debugging. */
2334 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2335 f
->output_data
.x
->normal_gc
,
2336 gx
, gy
, width
, height
);
2342 #endif /* HAVE_WINDOW_SYSTEM */
2345 /***********************************************************************
2346 Lisp form evaluation
2347 ***********************************************************************/
2349 /* Error handler for safe_eval and safe_call. */
2352 safe_eval_handler (arg
)
2355 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2360 /* Evaluate SEXPR and return the result, or nil if something went
2361 wrong. Prevent redisplay during the evaluation. */
2363 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2364 Return the result, or nil if something went wrong. Prevent
2365 redisplay during the evaluation. */
2368 safe_call (nargs
, args
)
2374 if (inhibit_eval_during_redisplay
)
2378 int count
= SPECPDL_INDEX ();
2379 struct gcpro gcpro1
;
2382 gcpro1
.nvars
= nargs
;
2383 specbind (Qinhibit_redisplay
, Qt
);
2384 /* Use Qt to ensure debugger does not run,
2385 so there is no possibility of wanting to redisplay. */
2386 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2389 val
= unbind_to (count
, val
);
2396 /* Call function FN with one argument ARG.
2397 Return the result, or nil if something went wrong. */
2400 safe_call1 (fn
, arg
)
2401 Lisp_Object fn
, arg
;
2403 Lisp_Object args
[2];
2406 return safe_call (2, args
);
2409 static Lisp_Object Qeval
;
2412 safe_eval (Lisp_Object sexpr
)
2414 return safe_call1 (Qeval
, sexpr
);
2417 /* Call function FN with one argument ARG.
2418 Return the result, or nil if something went wrong. */
2421 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2423 Lisp_Object args
[3];
2427 return safe_call (3, args
);
2432 /***********************************************************************
2434 ***********************************************************************/
2438 /* Define CHECK_IT to perform sanity checks on iterators.
2439 This is for debugging. It is too slow to do unconditionally. */
2445 if (it
->method
== GET_FROM_STRING
)
2447 xassert (STRINGP (it
->string
));
2448 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2452 xassert (IT_STRING_CHARPOS (*it
) < 0);
2453 if (it
->method
== GET_FROM_BUFFER
)
2455 /* Check that character and byte positions agree. */
2456 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2461 xassert (it
->current
.dpvec_index
>= 0);
2463 xassert (it
->current
.dpvec_index
< 0);
2466 #define CHECK_IT(IT) check_it ((IT))
2470 #define CHECK_IT(IT) (void) 0
2477 /* Check that the window end of window W is what we expect it
2478 to be---the last row in the current matrix displaying text. */
2481 check_window_end (w
)
2484 if (!MINI_WINDOW_P (w
)
2485 && !NILP (w
->window_end_valid
))
2487 struct glyph_row
*row
;
2488 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2489 XFASTINT (w
->window_end_vpos
)),
2491 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2492 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2496 #define CHECK_WINDOW_END(W) check_window_end ((W))
2498 #else /* not GLYPH_DEBUG */
2500 #define CHECK_WINDOW_END(W) (void) 0
2502 #endif /* not GLYPH_DEBUG */
2506 /***********************************************************************
2507 Iterator initialization
2508 ***********************************************************************/
2510 /* Initialize IT for displaying current_buffer in window W, starting
2511 at character position CHARPOS. CHARPOS < 0 means that no buffer
2512 position is specified which is useful when the iterator is assigned
2513 a position later. BYTEPOS is the byte position corresponding to
2514 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2516 If ROW is not null, calls to produce_glyphs with IT as parameter
2517 will produce glyphs in that row.
2519 BASE_FACE_ID is the id of a base face to use. It must be one of
2520 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2521 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2522 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2524 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2525 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2526 will be initialized to use the corresponding mode line glyph row of
2527 the desired matrix of W. */
2530 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2533 int charpos
, bytepos
;
2534 struct glyph_row
*row
;
2535 enum face_id base_face_id
;
2537 int highlight_region_p
;
2538 enum face_id remapped_base_face_id
= base_face_id
;
2540 /* Some precondition checks. */
2541 xassert (w
!= NULL
&& it
!= NULL
);
2542 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2545 /* If face attributes have been changed since the last redisplay,
2546 free realized faces now because they depend on face definitions
2547 that might have changed. Don't free faces while there might be
2548 desired matrices pending which reference these faces. */
2549 if (face_change_count
&& !inhibit_free_realized_faces
)
2551 face_change_count
= 0;
2552 free_all_realized_faces (Qnil
);
2555 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2556 if (! NILP (Vface_remapping_alist
))
2557 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2559 /* Use one of the mode line rows of W's desired matrix if
2563 if (base_face_id
== MODE_LINE_FACE_ID
2564 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2565 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2566 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2567 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2571 bzero (it
, sizeof *it
);
2572 it
->current
.overlay_string_index
= -1;
2573 it
->current
.dpvec_index
= -1;
2574 it
->base_face_id
= remapped_base_face_id
;
2576 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2578 /* The window in which we iterate over current_buffer: */
2579 XSETWINDOW (it
->window
, w
);
2581 it
->f
= XFRAME (w
->frame
);
2585 /* Extra space between lines (on window systems only). */
2586 if (base_face_id
== DEFAULT_FACE_ID
2587 && FRAME_WINDOW_P (it
->f
))
2589 if (NATNUMP (current_buffer
->extra_line_spacing
))
2590 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2591 else if (FLOATP (current_buffer
->extra_line_spacing
))
2592 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2593 * FRAME_LINE_HEIGHT (it
->f
));
2594 else if (it
->f
->extra_line_spacing
> 0)
2595 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2596 it
->max_extra_line_spacing
= 0;
2599 /* If realized faces have been removed, e.g. because of face
2600 attribute changes of named faces, recompute them. When running
2601 in batch mode, the face cache of the initial frame is null. If
2602 we happen to get called, make a dummy face cache. */
2603 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2604 init_frame_faces (it
->f
);
2605 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2606 recompute_basic_faces (it
->f
);
2608 /* Current value of the `slice', `space-width', and 'height' properties. */
2609 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2610 it
->space_width
= Qnil
;
2611 it
->font_height
= Qnil
;
2612 it
->override_ascent
= -1;
2614 /* Are control characters displayed as `^C'? */
2615 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2617 /* -1 means everything between a CR and the following line end
2618 is invisible. >0 means lines indented more than this value are
2620 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2621 ? XFASTINT (current_buffer
->selective_display
)
2622 : (!NILP (current_buffer
->selective_display
)
2624 it
->selective_display_ellipsis_p
2625 = !NILP (current_buffer
->selective_display_ellipses
);
2627 /* Display table to use. */
2628 it
->dp
= window_display_table (w
);
2630 /* Are multibyte characters enabled in current_buffer? */
2631 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2633 /* Do we need to reorder bidirectional text? */
2634 it
->bidi_p
= !NILP (current_buffer
->bidi_display_reordering
);
2636 /* Non-zero if we should highlight the region. */
2638 = (!NILP (Vtransient_mark_mode
)
2639 && !NILP (current_buffer
->mark_active
)
2640 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2642 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2643 start and end of a visible region in window IT->w. Set both to
2644 -1 to indicate no region. */
2645 if (highlight_region_p
2646 /* Maybe highlight only in selected window. */
2647 && (/* Either show region everywhere. */
2648 highlight_nonselected_windows
2649 /* Or show region in the selected window. */
2650 || w
== XWINDOW (selected_window
)
2651 /* Or show the region if we are in the mini-buffer and W is
2652 the window the mini-buffer refers to. */
2653 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2654 && WINDOWP (minibuf_selected_window
)
2655 && w
== XWINDOW (minibuf_selected_window
))))
2657 int charpos
= marker_position (current_buffer
->mark
);
2658 it
->region_beg_charpos
= min (PT
, charpos
);
2659 it
->region_end_charpos
= max (PT
, charpos
);
2662 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2664 /* Get the position at which the redisplay_end_trigger hook should
2665 be run, if it is to be run at all. */
2666 if (MARKERP (w
->redisplay_end_trigger
)
2667 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2668 it
->redisplay_end_trigger_charpos
2669 = marker_position (w
->redisplay_end_trigger
);
2670 else if (INTEGERP (w
->redisplay_end_trigger
))
2671 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2673 /* Correct bogus values of tab_width. */
2674 it
->tab_width
= XINT (current_buffer
->tab_width
);
2675 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2678 /* Are lines in the display truncated? */
2679 if (base_face_id
!= DEFAULT_FACE_ID
2680 || XINT (it
->w
->hscroll
)
2681 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2682 && ((!NILP (Vtruncate_partial_width_windows
)
2683 && !INTEGERP (Vtruncate_partial_width_windows
))
2684 || (INTEGERP (Vtruncate_partial_width_windows
)
2685 && (WINDOW_TOTAL_COLS (it
->w
)
2686 < XINT (Vtruncate_partial_width_windows
))))))
2687 it
->line_wrap
= TRUNCATE
;
2688 else if (NILP (current_buffer
->truncate_lines
))
2689 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2690 ? WINDOW_WRAP
: WORD_WRAP
;
2692 it
->line_wrap
= TRUNCATE
;
2694 /* Get dimensions of truncation and continuation glyphs. These are
2695 displayed as fringe bitmaps under X, so we don't need them for such
2697 if (!FRAME_WINDOW_P (it
->f
))
2699 if (it
->line_wrap
== TRUNCATE
)
2701 /* We will need the truncation glyph. */
2702 xassert (it
->glyph_row
== NULL
);
2703 produce_special_glyphs (it
, IT_TRUNCATION
);
2704 it
->truncation_pixel_width
= it
->pixel_width
;
2708 /* We will need the continuation glyph. */
2709 xassert (it
->glyph_row
== NULL
);
2710 produce_special_glyphs (it
, IT_CONTINUATION
);
2711 it
->continuation_pixel_width
= it
->pixel_width
;
2714 /* Reset these values to zero because the produce_special_glyphs
2715 above has changed them. */
2716 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2717 it
->phys_ascent
= it
->phys_descent
= 0;
2720 /* Set this after getting the dimensions of truncation and
2721 continuation glyphs, so that we don't produce glyphs when calling
2722 produce_special_glyphs, above. */
2723 it
->glyph_row
= row
;
2724 it
->area
= TEXT_AREA
;
2726 /* Forget any previous info about this row being reversed. */
2728 it
->glyph_row
->reversed_p
= 0;
2730 /* Get the dimensions of the display area. The display area
2731 consists of the visible window area plus a horizontally scrolled
2732 part to the left of the window. All x-values are relative to the
2733 start of this total display area. */
2734 if (base_face_id
!= DEFAULT_FACE_ID
)
2736 /* Mode lines, menu bar in terminal frames. */
2737 it
->first_visible_x
= 0;
2738 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2743 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2744 it
->last_visible_x
= (it
->first_visible_x
2745 + window_box_width (w
, TEXT_AREA
));
2747 /* If we truncate lines, leave room for the truncator glyph(s) at
2748 the right margin. Otherwise, leave room for the continuation
2749 glyph(s). Truncation and continuation glyphs are not inserted
2750 for window-based redisplay. */
2751 if (!FRAME_WINDOW_P (it
->f
))
2753 if (it
->line_wrap
== TRUNCATE
)
2754 it
->last_visible_x
-= it
->truncation_pixel_width
;
2756 it
->last_visible_x
-= it
->continuation_pixel_width
;
2759 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2760 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2763 /* Leave room for a border glyph. */
2764 if (!FRAME_WINDOW_P (it
->f
)
2765 && !WINDOW_RIGHTMOST_P (it
->w
))
2766 it
->last_visible_x
-= 1;
2768 it
->last_visible_y
= window_text_bottom_y (w
);
2770 /* For mode lines and alike, arrange for the first glyph having a
2771 left box line if the face specifies a box. */
2772 if (base_face_id
!= DEFAULT_FACE_ID
)
2776 it
->face_id
= remapped_base_face_id
;
2778 /* If we have a boxed mode line, make the first character appear
2779 with a left box line. */
2780 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2781 if (face
->box
!= FACE_NO_BOX
)
2782 it
->start_of_box_run_p
= 1;
2785 /* If we are to reorder bidirectional text, init the bidi
2789 /* Note the paragraph direction that this buffer wants to
2791 if (EQ (current_buffer
->bidi_paragraph_direction
, Qleft_to_right
))
2792 it
->paragraph_embedding
= L2R
;
2793 else if (EQ (current_buffer
->bidi_paragraph_direction
, Qright_to_left
))
2794 it
->paragraph_embedding
= R2L
;
2796 it
->paragraph_embedding
= NEUTRAL_DIR
;
2797 bidi_init_it (charpos
, bytepos
, &it
->bidi_it
);
2800 /* If a buffer position was specified, set the iterator there,
2801 getting overlays and face properties from that position. */
2802 if (charpos
>= BUF_BEG (current_buffer
))
2804 it
->end_charpos
= ZV
;
2806 IT_CHARPOS (*it
) = charpos
;
2808 /* Compute byte position if not specified. */
2809 if (bytepos
< charpos
)
2810 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2812 IT_BYTEPOS (*it
) = bytepos
;
2814 it
->start
= it
->current
;
2816 /* Compute faces etc. */
2817 reseat (it
, it
->current
.pos
, 1);
2824 /* Initialize IT for the display of window W with window start POS. */
2827 start_display (it
, w
, pos
)
2830 struct text_pos pos
;
2832 struct glyph_row
*row
;
2833 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2835 row
= w
->desired_matrix
->rows
+ first_vpos
;
2836 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2837 it
->first_vpos
= first_vpos
;
2839 /* Don't reseat to previous visible line start if current start
2840 position is in a string or image. */
2841 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2843 int start_at_line_beg_p
;
2844 int first_y
= it
->current_y
;
2846 /* If window start is not at a line start, skip forward to POS to
2847 get the correct continuation lines width. */
2848 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2849 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2850 if (!start_at_line_beg_p
)
2854 reseat_at_previous_visible_line_start (it
);
2855 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2857 new_x
= it
->current_x
+ it
->pixel_width
;
2859 /* If lines are continued, this line may end in the middle
2860 of a multi-glyph character (e.g. a control character
2861 displayed as \003, or in the middle of an overlay
2862 string). In this case move_it_to above will not have
2863 taken us to the start of the continuation line but to the
2864 end of the continued line. */
2865 if (it
->current_x
> 0
2866 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2867 && (/* And glyph doesn't fit on the line. */
2868 new_x
> it
->last_visible_x
2869 /* Or it fits exactly and we're on a window
2871 || (new_x
== it
->last_visible_x
2872 && FRAME_WINDOW_P (it
->f
))))
2874 if (it
->current
.dpvec_index
>= 0
2875 || it
->current
.overlay_string_index
>= 0)
2877 set_iterator_to_next (it
, 1);
2878 move_it_in_display_line_to (it
, -1, -1, 0);
2881 it
->continuation_lines_width
+= it
->current_x
;
2884 /* We're starting a new display line, not affected by the
2885 height of the continued line, so clear the appropriate
2886 fields in the iterator structure. */
2887 it
->max_ascent
= it
->max_descent
= 0;
2888 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2890 it
->current_y
= first_y
;
2892 it
->current_x
= it
->hpos
= 0;
2898 /* Return 1 if POS is a position in ellipses displayed for invisible
2899 text. W is the window we display, for text property lookup. */
2902 in_ellipses_for_invisible_text_p (pos
, w
)
2903 struct display_pos
*pos
;
2906 Lisp_Object prop
, window
;
2908 int charpos
= CHARPOS (pos
->pos
);
2910 /* If POS specifies a position in a display vector, this might
2911 be for an ellipsis displayed for invisible text. We won't
2912 get the iterator set up for delivering that ellipsis unless
2913 we make sure that it gets aware of the invisible text. */
2914 if (pos
->dpvec_index
>= 0
2915 && pos
->overlay_string_index
< 0
2916 && CHARPOS (pos
->string_pos
) < 0
2918 && (XSETWINDOW (window
, w
),
2919 prop
= Fget_char_property (make_number (charpos
),
2920 Qinvisible
, window
),
2921 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2923 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2925 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2932 /* Initialize IT for stepping through current_buffer in window W,
2933 starting at position POS that includes overlay string and display
2934 vector/ control character translation position information. Value
2935 is zero if there are overlay strings with newlines at POS. */
2938 init_from_display_pos (it
, w
, pos
)
2941 struct display_pos
*pos
;
2943 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2944 int i
, overlay_strings_with_newlines
= 0;
2946 /* If POS specifies a position in a display vector, this might
2947 be for an ellipsis displayed for invisible text. We won't
2948 get the iterator set up for delivering that ellipsis unless
2949 we make sure that it gets aware of the invisible text. */
2950 if (in_ellipses_for_invisible_text_p (pos
, w
))
2956 /* Keep in mind: the call to reseat in init_iterator skips invisible
2957 text, so we might end up at a position different from POS. This
2958 is only a problem when POS is a row start after a newline and an
2959 overlay starts there with an after-string, and the overlay has an
2960 invisible property. Since we don't skip invisible text in
2961 display_line and elsewhere immediately after consuming the
2962 newline before the row start, such a POS will not be in a string,
2963 but the call to init_iterator below will move us to the
2965 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2967 /* This only scans the current chunk -- it should scan all chunks.
2968 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2969 to 16 in 22.1 to make this a lesser problem. */
2970 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2972 const char *s
= SDATA (it
->overlay_strings
[i
]);
2973 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2975 while (s
< e
&& *s
!= '\n')
2980 overlay_strings_with_newlines
= 1;
2985 /* If position is within an overlay string, set up IT to the right
2987 if (pos
->overlay_string_index
>= 0)
2991 /* If the first overlay string happens to have a `display'
2992 property for an image, the iterator will be set up for that
2993 image, and we have to undo that setup first before we can
2994 correct the overlay string index. */
2995 if (it
->method
== GET_FROM_IMAGE
)
2998 /* We already have the first chunk of overlay strings in
2999 IT->overlay_strings. Load more until the one for
3000 pos->overlay_string_index is in IT->overlay_strings. */
3001 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3003 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3004 it
->current
.overlay_string_index
= 0;
3007 load_overlay_strings (it
, 0);
3008 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3012 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3013 relative_index
= (it
->current
.overlay_string_index
3014 % OVERLAY_STRING_CHUNK_SIZE
);
3015 it
->string
= it
->overlay_strings
[relative_index
];
3016 xassert (STRINGP (it
->string
));
3017 it
->current
.string_pos
= pos
->string_pos
;
3018 it
->method
= GET_FROM_STRING
;
3021 if (CHARPOS (pos
->string_pos
) >= 0)
3023 /* Recorded position is not in an overlay string, but in another
3024 string. This can only be a string from a `display' property.
3025 IT should already be filled with that string. */
3026 it
->current
.string_pos
= pos
->string_pos
;
3027 xassert (STRINGP (it
->string
));
3030 /* Restore position in display vector translations, control
3031 character translations or ellipses. */
3032 if (pos
->dpvec_index
>= 0)
3034 if (it
->dpvec
== NULL
)
3035 get_next_display_element (it
);
3036 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3037 it
->current
.dpvec_index
= pos
->dpvec_index
;
3041 return !overlay_strings_with_newlines
;
3045 /* Initialize IT for stepping through current_buffer in window W
3046 starting at ROW->start. */
3049 init_to_row_start (it
, w
, row
)
3052 struct glyph_row
*row
;
3054 init_from_display_pos (it
, w
, &row
->start
);
3055 it
->start
= row
->start
;
3056 it
->continuation_lines_width
= row
->continuation_lines_width
;
3061 /* Initialize IT for stepping through current_buffer in window W
3062 starting in the line following ROW, i.e. starting at ROW->end.
3063 Value is zero if there are overlay strings with newlines at ROW's
3067 init_to_row_end (it
, w
, row
)
3070 struct glyph_row
*row
;
3074 if (init_from_display_pos (it
, w
, &row
->end
))
3076 if (row
->continued_p
)
3077 it
->continuation_lines_width
3078 = row
->continuation_lines_width
+ row
->pixel_width
;
3089 /***********************************************************************
3091 ***********************************************************************/
3093 /* Called when IT reaches IT->stop_charpos. Handle text property and
3094 overlay changes. Set IT->stop_charpos to the next position where
3101 enum prop_handled handled
;
3102 int handle_overlay_change_p
;
3106 it
->current
.dpvec_index
= -1;
3107 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3108 it
->ignore_overlay_strings_at_pos_p
= 0;
3111 /* Use face of preceding text for ellipsis (if invisible) */
3112 if (it
->selective_display_ellipsis_p
)
3113 it
->saved_face_id
= it
->face_id
;
3117 handled
= HANDLED_NORMALLY
;
3119 /* Call text property handlers. */
3120 for (p
= it_props
; p
->handler
; ++p
)
3122 handled
= p
->handler (it
);
3124 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3126 else if (handled
== HANDLED_RETURN
)
3128 /* We still want to show before and after strings from
3129 overlays even if the actual buffer text is replaced. */
3130 if (!handle_overlay_change_p
3132 || !get_overlay_strings_1 (it
, 0, 0))
3135 setup_for_ellipsis (it
, 0);
3136 /* When handling a display spec, we might load an
3137 empty string. In that case, discard it here. We
3138 used to discard it in handle_single_display_spec,
3139 but that causes get_overlay_strings_1, above, to
3140 ignore overlay strings that we must check. */
3141 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3145 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3149 it
->ignore_overlay_strings_at_pos_p
= 1;
3150 it
->string_from_display_prop_p
= 0;
3151 handle_overlay_change_p
= 0;
3153 handled
= HANDLED_RECOMPUTE_PROPS
;
3156 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3157 handle_overlay_change_p
= 0;
3160 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3162 /* Don't check for overlay strings below when set to deliver
3163 characters from a display vector. */
3164 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3165 handle_overlay_change_p
= 0;
3167 /* Handle overlay changes.
3168 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3169 if it finds overlays. */
3170 if (handle_overlay_change_p
)
3171 handled
= handle_overlay_change (it
);
3176 setup_for_ellipsis (it
, 0);
3180 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3182 /* Determine where to stop next. */
3183 if (handled
== HANDLED_NORMALLY
)
3184 compute_stop_pos (it
);
3188 /* Compute IT->stop_charpos from text property and overlay change
3189 information for IT's current position. */
3192 compute_stop_pos (it
)
3195 register INTERVAL iv
, next_iv
;
3196 Lisp_Object object
, limit
, position
;
3197 EMACS_INT charpos
, bytepos
;
3199 /* If nowhere else, stop at the end. */
3200 it
->stop_charpos
= it
->end_charpos
;
3202 if (STRINGP (it
->string
))
3204 /* Strings are usually short, so don't limit the search for
3206 object
= it
->string
;
3208 charpos
= IT_STRING_CHARPOS (*it
);
3209 bytepos
= IT_STRING_BYTEPOS (*it
);
3215 /* If next overlay change is in front of the current stop pos
3216 (which is IT->end_charpos), stop there. Note: value of
3217 next_overlay_change is point-max if no overlay change
3219 charpos
= IT_CHARPOS (*it
);
3220 bytepos
= IT_BYTEPOS (*it
);
3221 pos
= next_overlay_change (charpos
);
3222 if (pos
< it
->stop_charpos
)
3223 it
->stop_charpos
= pos
;
3225 /* If showing the region, we have to stop at the region
3226 start or end because the face might change there. */
3227 if (it
->region_beg_charpos
> 0)
3229 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3230 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3231 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3232 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3235 /* Set up variables for computing the stop position from text
3236 property changes. */
3237 XSETBUFFER (object
, current_buffer
);
3238 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3241 /* Get the interval containing IT's position. Value is a null
3242 interval if there isn't such an interval. */
3243 position
= make_number (charpos
);
3244 iv
= validate_interval_range (object
, &position
, &position
, 0);
3245 if (!NULL_INTERVAL_P (iv
))
3247 Lisp_Object values_here
[LAST_PROP_IDX
];
3250 /* Get properties here. */
3251 for (p
= it_props
; p
->handler
; ++p
)
3252 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3254 /* Look for an interval following iv that has different
3256 for (next_iv
= next_interval (iv
);
3257 (!NULL_INTERVAL_P (next_iv
)
3259 || XFASTINT (limit
) > next_iv
->position
));
3260 next_iv
= next_interval (next_iv
))
3262 for (p
= it_props
; p
->handler
; ++p
)
3264 Lisp_Object new_value
;
3266 new_value
= textget (next_iv
->plist
, *p
->name
);
3267 if (!EQ (values_here
[p
->idx
], new_value
))
3275 if (!NULL_INTERVAL_P (next_iv
))
3277 if (INTEGERP (limit
)
3278 && next_iv
->position
>= XFASTINT (limit
))
3279 /* No text property change up to limit. */
3280 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3282 /* Text properties change in next_iv. */
3283 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3287 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3288 it
->stop_charpos
, it
->string
);
3290 xassert (STRINGP (it
->string
)
3291 || (it
->stop_charpos
>= BEGV
3292 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3296 /* Return the position of the next overlay change after POS in
3297 current_buffer. Value is point-max if no overlay change
3298 follows. This is like `next-overlay-change' but doesn't use
3302 next_overlay_change (pos
)
3307 Lisp_Object
*overlays
;
3310 /* Get all overlays at the given position. */
3311 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3313 /* If any of these overlays ends before endpos,
3314 use its ending point instead. */
3315 for (i
= 0; i
< noverlays
; ++i
)
3320 oend
= OVERLAY_END (overlays
[i
]);
3321 oendpos
= OVERLAY_POSITION (oend
);
3322 endpos
= min (endpos
, oendpos
);
3330 /***********************************************************************
3332 ***********************************************************************/
3334 /* Handle changes in the `fontified' property of the current buffer by
3335 calling hook functions from Qfontification_functions to fontify
3338 static enum prop_handled
3339 handle_fontified_prop (it
)
3342 Lisp_Object prop
, pos
;
3343 enum prop_handled handled
= HANDLED_NORMALLY
;
3345 if (!NILP (Vmemory_full
))
3348 /* Get the value of the `fontified' property at IT's current buffer
3349 position. (The `fontified' property doesn't have a special
3350 meaning in strings.) If the value is nil, call functions from
3351 Qfontification_functions. */
3352 if (!STRINGP (it
->string
)
3354 && !NILP (Vfontification_functions
)
3355 && !NILP (Vrun_hooks
)
3356 && (pos
= make_number (IT_CHARPOS (*it
)),
3357 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3358 /* Ignore the special cased nil value always present at EOB since
3359 no amount of fontifying will be able to change it. */
3360 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3362 int count
= SPECPDL_INDEX ();
3365 val
= Vfontification_functions
;
3366 specbind (Qfontification_functions
, Qnil
);
3368 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3369 safe_call1 (val
, pos
);
3372 Lisp_Object globals
, fn
;
3373 struct gcpro gcpro1
, gcpro2
;
3376 GCPRO2 (val
, globals
);
3378 for (; CONSP (val
); val
= XCDR (val
))
3384 /* A value of t indicates this hook has a local
3385 binding; it means to run the global binding too.
3386 In a global value, t should not occur. If it
3387 does, we must ignore it to avoid an endless
3389 for (globals
= Fdefault_value (Qfontification_functions
);
3391 globals
= XCDR (globals
))
3393 fn
= XCAR (globals
);
3395 safe_call1 (fn
, pos
);
3399 safe_call1 (fn
, pos
);
3405 unbind_to (count
, Qnil
);
3407 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3408 something. This avoids an endless loop if they failed to
3409 fontify the text for which reason ever. */
3410 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3411 handled
= HANDLED_RECOMPUTE_PROPS
;
3419 /***********************************************************************
3421 ***********************************************************************/
3423 /* Set up iterator IT from face properties at its current position.
3424 Called from handle_stop. */
3426 static enum prop_handled
3427 handle_face_prop (it
)
3431 EMACS_INT next_stop
;
3433 if (!STRINGP (it
->string
))
3436 = face_at_buffer_position (it
->w
,
3438 it
->region_beg_charpos
,
3439 it
->region_end_charpos
,
3442 + TEXT_PROP_DISTANCE_LIMIT
),
3443 0, it
->base_face_id
);
3445 /* Is this a start of a run of characters with box face?
3446 Caveat: this can be called for a freshly initialized
3447 iterator; face_id is -1 in this case. We know that the new
3448 face will not change until limit, i.e. if the new face has a
3449 box, all characters up to limit will have one. But, as
3450 usual, we don't know whether limit is really the end. */
3451 if (new_face_id
!= it
->face_id
)
3453 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3455 /* If new face has a box but old face has not, this is
3456 the start of a run of characters with box, i.e. it has
3457 a shadow on the left side. The value of face_id of the
3458 iterator will be -1 if this is the initial call that gets
3459 the face. In this case, we have to look in front of IT's
3460 position and see whether there is a face != new_face_id. */
3461 it
->start_of_box_run_p
3462 = (new_face
->box
!= FACE_NO_BOX
3463 && (it
->face_id
>= 0
3464 || IT_CHARPOS (*it
) == BEG
3465 || new_face_id
!= face_before_it_pos (it
)));
3466 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3471 int base_face_id
, bufpos
;
3473 Lisp_Object from_overlay
3474 = (it
->current
.overlay_string_index
>= 0
3475 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3478 /* See if we got to this string directly or indirectly from
3479 an overlay property. That includes the before-string or
3480 after-string of an overlay, strings in display properties
3481 provided by an overlay, their text properties, etc.
3483 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3484 if (! NILP (from_overlay
))
3485 for (i
= it
->sp
- 1; i
>= 0; i
--)
3487 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3489 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3490 else if (! NILP (it
->stack
[i
].from_overlay
))
3491 from_overlay
= it
->stack
[i
].from_overlay
;
3493 if (!NILP (from_overlay
))
3497 if (! NILP (from_overlay
))
3499 bufpos
= IT_CHARPOS (*it
);
3500 /* For a string from an overlay, the base face depends
3501 only on text properties and ignores overlays. */
3503 = face_for_overlay_string (it
->w
,
3505 it
->region_beg_charpos
,
3506 it
->region_end_charpos
,
3509 + TEXT_PROP_DISTANCE_LIMIT
),
3517 /* For strings from a `display' property, use the face at
3518 IT's current buffer position as the base face to merge
3519 with, so that overlay strings appear in the same face as
3520 surrounding text, unless they specify their own
3522 base_face_id
= underlying_face_id (it
);
3525 new_face_id
= face_at_string_position (it
->w
,
3527 IT_STRING_CHARPOS (*it
),
3529 it
->region_beg_charpos
,
3530 it
->region_end_charpos
,
3534 /* Is this a start of a run of characters with box? Caveat:
3535 this can be called for a freshly allocated iterator; face_id
3536 is -1 is this case. We know that the new face will not
3537 change until the next check pos, i.e. if the new face has a
3538 box, all characters up to that position will have a
3539 box. But, as usual, we don't know whether that position
3540 is really the end. */
3541 if (new_face_id
!= it
->face_id
)
3543 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3544 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3546 /* If new face has a box but old face hasn't, this is the
3547 start of a run of characters with box, i.e. it has a
3548 shadow on the left side. */
3549 it
->start_of_box_run_p
3550 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3551 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3555 it
->face_id
= new_face_id
;
3556 return HANDLED_NORMALLY
;
3560 /* Return the ID of the face ``underlying'' IT's current position,
3561 which is in a string. If the iterator is associated with a
3562 buffer, return the face at IT's current buffer position.
3563 Otherwise, use the iterator's base_face_id. */
3566 underlying_face_id (it
)
3569 int face_id
= it
->base_face_id
, i
;
3571 xassert (STRINGP (it
->string
));
3573 for (i
= it
->sp
- 1; i
>= 0; --i
)
3574 if (NILP (it
->stack
[i
].string
))
3575 face_id
= it
->stack
[i
].face_id
;
3581 /* Compute the face one character before or after the current position
3582 of IT. BEFORE_P non-zero means get the face in front of IT's
3583 position. Value is the id of the face. */
3586 face_before_or_after_it_pos (it
, before_p
)
3591 EMACS_INT next_check_charpos
;
3592 struct text_pos pos
;
3594 xassert (it
->s
== NULL
);
3596 if (STRINGP (it
->string
))
3598 int bufpos
, base_face_id
;
3600 /* No face change past the end of the string (for the case
3601 we are padding with spaces). No face change before the
3603 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3604 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3607 /* Set pos to the position before or after IT's current position. */
3609 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3611 /* For composition, we must check the character after the
3613 pos
= (it
->what
== IT_COMPOSITION
3614 ? string_pos (IT_STRING_CHARPOS (*it
)
3615 + it
->cmp_it
.nchars
, it
->string
)
3616 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3618 if (it
->current
.overlay_string_index
>= 0)
3619 bufpos
= IT_CHARPOS (*it
);
3623 base_face_id
= underlying_face_id (it
);
3625 /* Get the face for ASCII, or unibyte. */
3626 face_id
= face_at_string_position (it
->w
,
3630 it
->region_beg_charpos
,
3631 it
->region_end_charpos
,
3632 &next_check_charpos
,
3635 /* Correct the face for charsets different from ASCII. Do it
3636 for the multibyte case only. The face returned above is
3637 suitable for unibyte text if IT->string is unibyte. */
3638 if (STRING_MULTIBYTE (it
->string
))
3640 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3641 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3643 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3645 c
= string_char_and_length (p
, &len
);
3646 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3651 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3652 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3655 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3656 pos
= it
->current
.pos
;
3659 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3662 if (it
->what
== IT_COMPOSITION
)
3663 /* For composition, we must check the position after the
3665 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3667 INC_TEXT_POS (pos
, it
->multibyte_p
);
3670 /* Determine face for CHARSET_ASCII, or unibyte. */
3671 face_id
= face_at_buffer_position (it
->w
,
3673 it
->region_beg_charpos
,
3674 it
->region_end_charpos
,
3675 &next_check_charpos
,
3678 /* Correct the face for charsets different from ASCII. Do it
3679 for the multibyte case only. The face returned above is
3680 suitable for unibyte text if current_buffer is unibyte. */
3681 if (it
->multibyte_p
)
3683 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3684 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3685 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3694 /***********************************************************************
3696 ***********************************************************************/
3698 /* Set up iterator IT from invisible properties at its current
3699 position. Called from handle_stop. */
3701 static enum prop_handled
3702 handle_invisible_prop (it
)
3705 enum prop_handled handled
= HANDLED_NORMALLY
;
3707 if (STRINGP (it
->string
))
3709 extern Lisp_Object Qinvisible
;
3710 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3712 /* Get the value of the invisible text property at the
3713 current position. Value will be nil if there is no such
3715 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3716 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3719 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3721 handled
= HANDLED_RECOMPUTE_PROPS
;
3723 /* Get the position at which the next change of the
3724 invisible text property can be found in IT->string.
3725 Value will be nil if the property value is the same for
3726 all the rest of IT->string. */
3727 XSETINT (limit
, SCHARS (it
->string
));
3728 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3731 /* Text at current position is invisible. The next
3732 change in the property is at position end_charpos.
3733 Move IT's current position to that position. */
3734 if (INTEGERP (end_charpos
)
3735 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3737 struct text_pos old
;
3738 old
= it
->current
.string_pos
;
3739 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3740 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3744 /* The rest of the string is invisible. If this is an
3745 overlay string, proceed with the next overlay string
3746 or whatever comes and return a character from there. */
3747 if (it
->current
.overlay_string_index
>= 0)
3749 next_overlay_string (it
);
3750 /* Don't check for overlay strings when we just
3751 finished processing them. */
3752 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3756 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3757 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3765 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3766 Lisp_Object pos
, prop
, overlay
;
3768 /* First of all, is there invisible text at this position? */
3769 tem
= start_charpos
= IT_CHARPOS (*it
);
3770 pos
= make_number (tem
);
3771 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3773 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3775 /* If we are on invisible text, skip over it. */
3776 if (invis_p
&& start_charpos
< it
->end_charpos
)
3778 /* Record whether we have to display an ellipsis for the
3780 int display_ellipsis_p
= invis_p
== 2;
3782 handled
= HANDLED_RECOMPUTE_PROPS
;
3784 /* Loop skipping over invisible text. The loop is left at
3785 ZV or with IT on the first char being visible again. */
3788 /* Try to skip some invisible text. Return value is the
3789 position reached which can be equal to where we start
3790 if there is nothing invisible there. This skips both
3791 over invisible text properties and overlays with
3792 invisible property. */
3793 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3795 /* If we skipped nothing at all we weren't at invisible
3796 text in the first place. If everything to the end of
3797 the buffer was skipped, end the loop. */
3798 if (newpos
== tem
|| newpos
>= ZV
)
3802 /* We skipped some characters but not necessarily
3803 all there are. Check if we ended up on visible
3804 text. Fget_char_property returns the property of
3805 the char before the given position, i.e. if we
3806 get invis_p = 0, this means that the char at
3807 newpos is visible. */
3808 pos
= make_number (newpos
);
3809 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3810 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3813 /* If we ended up on invisible text, proceed to
3814 skip starting with next_stop. */
3818 /* If there are adjacent invisible texts, don't lose the
3819 second one's ellipsis. */
3821 display_ellipsis_p
= 1;
3825 /* The position newpos is now either ZV or on visible text. */
3826 if (it
->bidi_p
&& newpos
< ZV
)
3828 /* With bidi iteration, the region of invisible text
3829 could start and/or end in the middle of a non-base
3830 embedding level. Therefore, we need to skip
3831 invisible text using the bidi iterator, starting at
3832 IT's current position, until we find ourselves
3833 outside the invisible text. Skipping invisible text
3834 _after_ bidi iteration avoids affecting the visual
3835 order of the displayed text when invisible properties
3836 are added or removed. */
3837 if (it
->bidi_it
.first_elt
)
3839 /* If we were `reseat'ed to a new paragraph,
3840 determine the paragraph base direction. We need
3841 to do it now because next_element_from_buffer may
3842 not have a chance to do it, if we are going to
3843 skip any text at the beginning, which resets the
3845 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
3849 bidi_get_next_char_visually (&it
->bidi_it
);
3851 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3852 && it
->bidi_it
.charpos
< newpos
);
3853 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3854 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3855 /* If we overstepped NEWPOS, record its position in the
3856 iterator, so that we skip invisible text if later the
3857 bidi iteration lands us in the invisible region
3859 if (IT_CHARPOS (*it
) >= newpos
)
3860 it
->prev_stop
= newpos
;
3864 IT_CHARPOS (*it
) = newpos
;
3865 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3868 /* If there are before-strings at the start of invisible
3869 text, and the text is invisible because of a text
3870 property, arrange to show before-strings because 20.x did
3871 it that way. (If the text is invisible because of an
3872 overlay property instead of a text property, this is
3873 already handled in the overlay code.) */
3875 && get_overlay_strings (it
, it
->stop_charpos
))
3877 handled
= HANDLED_RECOMPUTE_PROPS
;
3878 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3880 else if (display_ellipsis_p
)
3882 /* Make sure that the glyphs of the ellipsis will get
3883 correct `charpos' values. If we would not update
3884 it->position here, the glyphs would belong to the
3885 last visible character _before_ the invisible
3886 text, which confuses `set_cursor_from_row'.
3888 We use the last invisible position instead of the
3889 first because this way the cursor is always drawn on
3890 the first "." of the ellipsis, whenever PT is inside
3891 the invisible text. Otherwise the cursor would be
3892 placed _after_ the ellipsis when the point is after the
3893 first invisible character. */
3894 if (!STRINGP (it
->object
))
3896 it
->position
.charpos
= newpos
- 1;
3897 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3900 /* Let the ellipsis display before
3901 considering any properties of the following char.
3902 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3903 handled
= HANDLED_RETURN
;
3912 /* Make iterator IT return `...' next.
3913 Replaces LEN characters from buffer. */
3916 setup_for_ellipsis (it
, len
)
3920 /* Use the display table definition for `...'. Invalid glyphs
3921 will be handled by the method returning elements from dpvec. */
3922 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3924 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3925 it
->dpvec
= v
->contents
;
3926 it
->dpend
= v
->contents
+ v
->size
;
3930 /* Default `...'. */
3931 it
->dpvec
= default_invis_vector
;
3932 it
->dpend
= default_invis_vector
+ 3;
3935 it
->dpvec_char_len
= len
;
3936 it
->current
.dpvec_index
= 0;
3937 it
->dpvec_face_id
= -1;
3939 /* Remember the current face id in case glyphs specify faces.
3940 IT's face is restored in set_iterator_to_next.
3941 saved_face_id was set to preceding char's face in handle_stop. */
3942 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3943 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3945 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3951 /***********************************************************************
3953 ***********************************************************************/
3955 /* Set up iterator IT from `display' property at its current position.
3956 Called from handle_stop.
3957 We return HANDLED_RETURN if some part of the display property
3958 overrides the display of the buffer text itself.
3959 Otherwise we return HANDLED_NORMALLY. */
3961 static enum prop_handled
3962 handle_display_prop (it
)
3965 Lisp_Object prop
, object
, overlay
;
3966 struct text_pos
*position
;
3967 /* Nonzero if some property replaces the display of the text itself. */
3968 int display_replaced_p
= 0;
3970 if (STRINGP (it
->string
))
3972 object
= it
->string
;
3973 position
= &it
->current
.string_pos
;
3977 XSETWINDOW (object
, it
->w
);
3978 position
= &it
->current
.pos
;
3981 /* Reset those iterator values set from display property values. */
3982 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3983 it
->space_width
= Qnil
;
3984 it
->font_height
= Qnil
;
3987 /* We don't support recursive `display' properties, i.e. string
3988 values that have a string `display' property, that have a string
3989 `display' property etc. */
3990 if (!it
->string_from_display_prop_p
)
3991 it
->area
= TEXT_AREA
;
3993 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3994 Qdisplay
, object
, &overlay
);
3996 return HANDLED_NORMALLY
;
3997 /* Now OVERLAY is the overlay that gave us this property, or nil
3998 if it was a text property. */
4000 if (!STRINGP (it
->string
))
4001 object
= it
->w
->buffer
;
4004 /* Simple properties. */
4005 && !EQ (XCAR (prop
), Qimage
)
4006 && !EQ (XCAR (prop
), Qspace
)
4007 && !EQ (XCAR (prop
), Qwhen
)
4008 && !EQ (XCAR (prop
), Qslice
)
4009 && !EQ (XCAR (prop
), Qspace_width
)
4010 && !EQ (XCAR (prop
), Qheight
)
4011 && !EQ (XCAR (prop
), Qraise
)
4012 /* Marginal area specifications. */
4013 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
4014 && !EQ (XCAR (prop
), Qleft_fringe
)
4015 && !EQ (XCAR (prop
), Qright_fringe
)
4016 && !NILP (XCAR (prop
)))
4018 for (; CONSP (prop
); prop
= XCDR (prop
))
4020 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
4021 position
, display_replaced_p
))
4023 display_replaced_p
= 1;
4024 /* If some text in a string is replaced, `position' no
4025 longer points to the position of `object'. */
4026 if (STRINGP (object
))
4031 else if (VECTORP (prop
))
4034 for (i
= 0; i
< ASIZE (prop
); ++i
)
4035 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4036 position
, display_replaced_p
))
4038 display_replaced_p
= 1;
4039 /* If some text in a string is replaced, `position' no
4040 longer points to the position of `object'. */
4041 if (STRINGP (object
))
4047 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4049 display_replaced_p
= 1;
4052 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4056 /* Value is the position of the end of the `display' property starting
4057 at START_POS in OBJECT. */
4059 static struct text_pos
4060 display_prop_end (it
, object
, start_pos
)
4063 struct text_pos start_pos
;
4066 struct text_pos end_pos
;
4068 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4069 Qdisplay
, object
, Qnil
);
4070 CHARPOS (end_pos
) = XFASTINT (end
);
4071 if (STRINGP (object
))
4072 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4074 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4080 /* Set up IT from a single `display' specification PROP. OBJECT
4081 is the object in which the `display' property was found. *POSITION
4082 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4083 means that we previously saw a display specification which already
4084 replaced text display with something else, for example an image;
4085 we ignore such properties after the first one has been processed.
4087 OVERLAY is the overlay this `display' property came from,
4088 or nil if it was a text property.
4090 If PROP is a `space' or `image' specification, and in some other
4091 cases too, set *POSITION to the position where the `display'
4094 Value is non-zero if something was found which replaces the display
4095 of buffer or string text. */
4098 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4099 display_replaced_before_p
)
4103 Lisp_Object overlay
;
4104 struct text_pos
*position
;
4105 int display_replaced_before_p
;
4108 Lisp_Object location
, value
;
4109 struct text_pos start_pos
, save_pos
;
4112 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4113 If the result is non-nil, use VALUE instead of SPEC. */
4115 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4124 if (!NILP (form
) && !EQ (form
, Qt
))
4126 int count
= SPECPDL_INDEX ();
4127 struct gcpro gcpro1
;
4129 /* Bind `object' to the object having the `display' property, a
4130 buffer or string. Bind `position' to the position in the
4131 object where the property was found, and `buffer-position'
4132 to the current position in the buffer. */
4133 specbind (Qobject
, object
);
4134 specbind (Qposition
, make_number (CHARPOS (*position
)));
4135 specbind (Qbuffer_position
,
4136 make_number (STRINGP (object
)
4137 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4139 form
= safe_eval (form
);
4141 unbind_to (count
, Qnil
);
4147 /* Handle `(height HEIGHT)' specifications. */
4149 && EQ (XCAR (spec
), Qheight
)
4150 && CONSP (XCDR (spec
)))
4152 if (!FRAME_WINDOW_P (it
->f
))
4155 it
->font_height
= XCAR (XCDR (spec
));
4156 if (!NILP (it
->font_height
))
4158 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4159 int new_height
= -1;
4161 if (CONSP (it
->font_height
)
4162 && (EQ (XCAR (it
->font_height
), Qplus
)
4163 || EQ (XCAR (it
->font_height
), Qminus
))
4164 && CONSP (XCDR (it
->font_height
))
4165 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4167 /* `(+ N)' or `(- N)' where N is an integer. */
4168 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4169 if (EQ (XCAR (it
->font_height
), Qplus
))
4171 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4173 else if (FUNCTIONP (it
->font_height
))
4175 /* Call function with current height as argument.
4176 Value is the new height. */
4178 height
= safe_call1 (it
->font_height
,
4179 face
->lface
[LFACE_HEIGHT_INDEX
]);
4180 if (NUMBERP (height
))
4181 new_height
= XFLOATINT (height
);
4183 else if (NUMBERP (it
->font_height
))
4185 /* Value is a multiple of the canonical char height. */
4188 face
= FACE_FROM_ID (it
->f
,
4189 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4190 new_height
= (XFLOATINT (it
->font_height
)
4191 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4195 /* Evaluate IT->font_height with `height' bound to the
4196 current specified height to get the new height. */
4197 int count
= SPECPDL_INDEX ();
4199 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4200 value
= safe_eval (it
->font_height
);
4201 unbind_to (count
, Qnil
);
4203 if (NUMBERP (value
))
4204 new_height
= XFLOATINT (value
);
4208 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4214 /* Handle `(space-width WIDTH)'. */
4216 && EQ (XCAR (spec
), Qspace_width
)
4217 && CONSP (XCDR (spec
)))
4219 if (!FRAME_WINDOW_P (it
->f
))
4222 value
= XCAR (XCDR (spec
));
4223 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4224 it
->space_width
= value
;
4229 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4231 && EQ (XCAR (spec
), Qslice
))
4235 if (!FRAME_WINDOW_P (it
->f
))
4238 if (tem
= XCDR (spec
), CONSP (tem
))
4240 it
->slice
.x
= XCAR (tem
);
4241 if (tem
= XCDR (tem
), CONSP (tem
))
4243 it
->slice
.y
= XCAR (tem
);
4244 if (tem
= XCDR (tem
), CONSP (tem
))
4246 it
->slice
.width
= XCAR (tem
);
4247 if (tem
= XCDR (tem
), CONSP (tem
))
4248 it
->slice
.height
= XCAR (tem
);
4256 /* Handle `(raise FACTOR)'. */
4258 && EQ (XCAR (spec
), Qraise
)
4259 && CONSP (XCDR (spec
)))
4261 if (!FRAME_WINDOW_P (it
->f
))
4264 #ifdef HAVE_WINDOW_SYSTEM
4265 value
= XCAR (XCDR (spec
));
4266 if (NUMBERP (value
))
4268 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4269 it
->voffset
= - (XFLOATINT (value
)
4270 * (FONT_HEIGHT (face
->font
)));
4272 #endif /* HAVE_WINDOW_SYSTEM */
4277 /* Don't handle the other kinds of display specifications
4278 inside a string that we got from a `display' property. */
4279 if (it
->string_from_display_prop_p
)
4282 /* Characters having this form of property are not displayed, so
4283 we have to find the end of the property. */
4284 start_pos
= *position
;
4285 *position
= display_prop_end (it
, object
, start_pos
);
4288 /* Stop the scan at that end position--we assume that all
4289 text properties change there. */
4290 it
->stop_charpos
= position
->charpos
;
4292 /* Handle `(left-fringe BITMAP [FACE])'
4293 and `(right-fringe BITMAP [FACE])'. */
4295 && (EQ (XCAR (spec
), Qleft_fringe
)
4296 || EQ (XCAR (spec
), Qright_fringe
))
4297 && CONSP (XCDR (spec
)))
4299 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4302 if (!FRAME_WINDOW_P (it
->f
))
4303 /* If we return here, POSITION has been advanced
4304 across the text with this property. */
4307 #ifdef HAVE_WINDOW_SYSTEM
4308 value
= XCAR (XCDR (spec
));
4309 if (!SYMBOLP (value
)
4310 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4311 /* If we return here, POSITION has been advanced
4312 across the text with this property. */
4315 if (CONSP (XCDR (XCDR (spec
))))
4317 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4318 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4324 /* Save current settings of IT so that we can restore them
4325 when we are finished with the glyph property value. */
4327 save_pos
= it
->position
;
4328 it
->position
= *position
;
4330 it
->position
= save_pos
;
4332 it
->area
= TEXT_AREA
;
4333 it
->what
= IT_IMAGE
;
4334 it
->image_id
= -1; /* no image */
4335 it
->position
= start_pos
;
4336 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4337 it
->method
= GET_FROM_IMAGE
;
4338 it
->from_overlay
= Qnil
;
4339 it
->face_id
= face_id
;
4341 /* Say that we haven't consumed the characters with
4342 `display' property yet. The call to pop_it in
4343 set_iterator_to_next will clean this up. */
4344 *position
= start_pos
;
4346 if (EQ (XCAR (spec
), Qleft_fringe
))
4348 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4349 it
->left_user_fringe_face_id
= face_id
;
4353 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4354 it
->right_user_fringe_face_id
= face_id
;
4356 #endif /* HAVE_WINDOW_SYSTEM */
4360 /* Prepare to handle `((margin left-margin) ...)',
4361 `((margin right-margin) ...)' and `((margin nil) ...)'
4362 prefixes for display specifications. */
4363 location
= Qunbound
;
4364 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4368 value
= XCDR (spec
);
4370 value
= XCAR (value
);
4373 if (EQ (XCAR (tem
), Qmargin
)
4374 && (tem
= XCDR (tem
),
4375 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4377 || EQ (tem
, Qleft_margin
)
4378 || EQ (tem
, Qright_margin
))))
4382 if (EQ (location
, Qunbound
))
4388 /* After this point, VALUE is the property after any
4389 margin prefix has been stripped. It must be a string,
4390 an image specification, or `(space ...)'.
4392 LOCATION specifies where to display: `left-margin',
4393 `right-margin' or nil. */
4395 valid_p
= (STRINGP (value
)
4396 #ifdef HAVE_WINDOW_SYSTEM
4397 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4398 #endif /* not HAVE_WINDOW_SYSTEM */
4399 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4401 if (valid_p
&& !display_replaced_before_p
)
4403 /* Save current settings of IT so that we can restore them
4404 when we are finished with the glyph property value. */
4405 save_pos
= it
->position
;
4406 it
->position
= *position
;
4408 it
->position
= save_pos
;
4409 it
->from_overlay
= overlay
;
4411 if (NILP (location
))
4412 it
->area
= TEXT_AREA
;
4413 else if (EQ (location
, Qleft_margin
))
4414 it
->area
= LEFT_MARGIN_AREA
;
4416 it
->area
= RIGHT_MARGIN_AREA
;
4418 if (STRINGP (value
))
4421 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4422 it
->current
.overlay_string_index
= -1;
4423 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4424 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4425 it
->method
= GET_FROM_STRING
;
4426 it
->stop_charpos
= 0;
4427 it
->string_from_display_prop_p
= 1;
4428 /* Say that we haven't consumed the characters with
4429 `display' property yet. The call to pop_it in
4430 set_iterator_to_next will clean this up. */
4431 if (BUFFERP (object
))
4432 *position
= start_pos
;
4434 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4436 it
->method
= GET_FROM_STRETCH
;
4438 *position
= it
->position
= start_pos
;
4440 #ifdef HAVE_WINDOW_SYSTEM
4443 it
->what
= IT_IMAGE
;
4444 it
->image_id
= lookup_image (it
->f
, value
);
4445 it
->position
= start_pos
;
4446 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4447 it
->method
= GET_FROM_IMAGE
;
4449 /* Say that we haven't consumed the characters with
4450 `display' property yet. The call to pop_it in
4451 set_iterator_to_next will clean this up. */
4452 *position
= start_pos
;
4454 #endif /* HAVE_WINDOW_SYSTEM */
4459 /* Invalid property or property not supported. Restore
4460 POSITION to what it was before. */
4461 *position
= start_pos
;
4466 /* Check if SPEC is a display sub-property value whose text should be
4467 treated as intangible. */
4470 single_display_spec_intangible_p (prop
)
4473 /* Skip over `when FORM'. */
4474 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4488 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4489 we don't need to treat text as intangible. */
4490 if (EQ (XCAR (prop
), Qmargin
))
4498 || EQ (XCAR (prop
), Qleft_margin
)
4499 || EQ (XCAR (prop
), Qright_margin
))
4503 return (CONSP (prop
)
4504 && (EQ (XCAR (prop
), Qimage
)
4505 || EQ (XCAR (prop
), Qspace
)));
4509 /* Check if PROP is a display property value whose text should be
4510 treated as intangible. */
4513 display_prop_intangible_p (prop
)
4517 && CONSP (XCAR (prop
))
4518 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4520 /* A list of sub-properties. */
4521 while (CONSP (prop
))
4523 if (single_display_spec_intangible_p (XCAR (prop
)))
4528 else if (VECTORP (prop
))
4530 /* A vector of sub-properties. */
4532 for (i
= 0; i
< ASIZE (prop
); ++i
)
4533 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4537 return single_display_spec_intangible_p (prop
);
4543 /* Return 1 if PROP is a display sub-property value containing STRING. */
4546 single_display_spec_string_p (prop
, string
)
4547 Lisp_Object prop
, string
;
4549 if (EQ (string
, prop
))
4552 /* Skip over `when FORM'. */
4553 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4562 /* Skip over `margin LOCATION'. */
4563 if (EQ (XCAR (prop
), Qmargin
))
4574 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4578 /* Return 1 if STRING appears in the `display' property PROP. */
4581 display_prop_string_p (prop
, string
)
4582 Lisp_Object prop
, string
;
4585 && CONSP (XCAR (prop
))
4586 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4588 /* A list of sub-properties. */
4589 while (CONSP (prop
))
4591 if (single_display_spec_string_p (XCAR (prop
), string
))
4596 else if (VECTORP (prop
))
4598 /* A vector of sub-properties. */
4600 for (i
= 0; i
< ASIZE (prop
); ++i
)
4601 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4605 return single_display_spec_string_p (prop
, string
);
4610 /* Look for STRING in overlays and text properties in W's buffer,
4611 between character positions FROM and TO (excluding TO).
4612 BACK_P non-zero means look back (in this case, TO is supposed to be
4614 Value is the first character position where STRING was found, or
4615 zero if it wasn't found before hitting TO.
4617 W's buffer must be current.
4619 This function may only use code that doesn't eval because it is
4620 called asynchronously from note_mouse_highlight. */
4623 string_buffer_position_lim (w
, string
, from
, to
, back_p
)
4629 Lisp_Object limit
, prop
, pos
;
4632 pos
= make_number (from
);
4634 if (!back_p
) /* looking forward */
4636 limit
= make_number (min (to
, ZV
));
4637 while (!found
&& !EQ (pos
, limit
))
4639 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4640 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4643 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4647 else /* looking back */
4649 limit
= make_number (max (to
, BEGV
));
4650 while (!found
&& !EQ (pos
, limit
))
4652 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4653 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4656 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4661 return found
? XINT (pos
) : 0;
4664 /* Determine which buffer position in W's buffer STRING comes from.
4665 AROUND_CHARPOS is an approximate position where it could come from.
4666 Value is the buffer position or 0 if it couldn't be determined.
4668 W's buffer must be current.
4670 This function is necessary because we don't record buffer positions
4671 in glyphs generated from strings (to keep struct glyph small).
4672 This function may only use code that doesn't eval because it is
4673 called asynchronously from note_mouse_highlight. */
4676 string_buffer_position (w
, string
, around_charpos
)
4679 EMACS_INT around_charpos
;
4681 Lisp_Object limit
, prop
, pos
;
4682 const int MAX_DISTANCE
= 1000;
4683 EMACS_INT found
= string_buffer_position_lim (w
, string
, around_charpos
,
4684 around_charpos
+ MAX_DISTANCE
,
4688 found
= string_buffer_position_lim (w
, string
, around_charpos
,
4689 around_charpos
- MAX_DISTANCE
, 1);
4695 /***********************************************************************
4696 `composition' property
4697 ***********************************************************************/
4699 /* Set up iterator IT from `composition' property at its current
4700 position. Called from handle_stop. */
4702 static enum prop_handled
4703 handle_composition_prop (it
)
4706 Lisp_Object prop
, string
;
4707 EMACS_INT pos
, pos_byte
, start
, end
;
4709 if (STRINGP (it
->string
))
4713 pos
= IT_STRING_CHARPOS (*it
);
4714 pos_byte
= IT_STRING_BYTEPOS (*it
);
4715 string
= it
->string
;
4716 s
= SDATA (string
) + pos_byte
;
4717 it
->c
= STRING_CHAR (s
);
4721 pos
= IT_CHARPOS (*it
);
4722 pos_byte
= IT_BYTEPOS (*it
);
4724 it
->c
= FETCH_CHAR (pos_byte
);
4727 /* If there's a valid composition and point is not inside of the
4728 composition (in the case that the composition is from the current
4729 buffer), draw a glyph composed from the composition components. */
4730 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4731 && COMPOSITION_VALID_P (start
, end
, prop
)
4732 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4736 if (STRINGP (it
->string
))
4737 pos_byte
= string_char_to_byte (it
->string
, start
);
4739 pos_byte
= CHAR_TO_BYTE (start
);
4741 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4744 if (it
->cmp_it
.id
>= 0)
4747 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4748 it
->cmp_it
.nglyphs
= -1;
4752 return HANDLED_NORMALLY
;
4757 /***********************************************************************
4759 ***********************************************************************/
4761 /* The following structure is used to record overlay strings for
4762 later sorting in load_overlay_strings. */
4764 struct overlay_entry
4766 Lisp_Object overlay
;
4773 /* Set up iterator IT from overlay strings at its current position.
4774 Called from handle_stop. */
4776 static enum prop_handled
4777 handle_overlay_change (it
)
4780 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4781 return HANDLED_RECOMPUTE_PROPS
;
4783 return HANDLED_NORMALLY
;
4787 /* Set up the next overlay string for delivery by IT, if there is an
4788 overlay string to deliver. Called by set_iterator_to_next when the
4789 end of the current overlay string is reached. If there are more
4790 overlay strings to display, IT->string and
4791 IT->current.overlay_string_index are set appropriately here.
4792 Otherwise IT->string is set to nil. */
4795 next_overlay_string (it
)
4798 ++it
->current
.overlay_string_index
;
4799 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4801 /* No more overlay strings. Restore IT's settings to what
4802 they were before overlay strings were processed, and
4803 continue to deliver from current_buffer. */
4805 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4808 || (NILP (it
->string
)
4809 && it
->method
== GET_FROM_BUFFER
4810 && it
->stop_charpos
>= BEGV
4811 && it
->stop_charpos
<= it
->end_charpos
));
4812 it
->current
.overlay_string_index
= -1;
4813 it
->n_overlay_strings
= 0;
4815 /* If we're at the end of the buffer, record that we have
4816 processed the overlay strings there already, so that
4817 next_element_from_buffer doesn't try it again. */
4818 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4819 it
->overlay_strings_at_end_processed_p
= 1;
4823 /* There are more overlay strings to process. If
4824 IT->current.overlay_string_index has advanced to a position
4825 where we must load IT->overlay_strings with more strings, do
4827 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4829 if (it
->current
.overlay_string_index
&& i
== 0)
4830 load_overlay_strings (it
, 0);
4832 /* Initialize IT to deliver display elements from the overlay
4834 it
->string
= it
->overlay_strings
[i
];
4835 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4836 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4837 it
->method
= GET_FROM_STRING
;
4838 it
->stop_charpos
= 0;
4839 if (it
->cmp_it
.stop_pos
>= 0)
4840 it
->cmp_it
.stop_pos
= 0;
4847 /* Compare two overlay_entry structures E1 and E2. Used as a
4848 comparison function for qsort in load_overlay_strings. Overlay
4849 strings for the same position are sorted so that
4851 1. All after-strings come in front of before-strings, except
4852 when they come from the same overlay.
4854 2. Within after-strings, strings are sorted so that overlay strings
4855 from overlays with higher priorities come first.
4857 2. Within before-strings, strings are sorted so that overlay
4858 strings from overlays with higher priorities come last.
4860 Value is analogous to strcmp. */
4864 compare_overlay_entries (e1
, e2
)
4867 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4868 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4871 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4873 /* Let after-strings appear in front of before-strings if
4874 they come from different overlays. */
4875 if (EQ (entry1
->overlay
, entry2
->overlay
))
4876 result
= entry1
->after_string_p
? 1 : -1;
4878 result
= entry1
->after_string_p
? -1 : 1;
4880 else if (entry1
->after_string_p
)
4881 /* After-strings sorted in order of decreasing priority. */
4882 result
= entry2
->priority
- entry1
->priority
;
4884 /* Before-strings sorted in order of increasing priority. */
4885 result
= entry1
->priority
- entry2
->priority
;
4891 /* Load the vector IT->overlay_strings with overlay strings from IT's
4892 current buffer position, or from CHARPOS if that is > 0. Set
4893 IT->n_overlays to the total number of overlay strings found.
4895 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4896 a time. On entry into load_overlay_strings,
4897 IT->current.overlay_string_index gives the number of overlay
4898 strings that have already been loaded by previous calls to this
4901 IT->add_overlay_start contains an additional overlay start
4902 position to consider for taking overlay strings from, if non-zero.
4903 This position comes into play when the overlay has an `invisible'
4904 property, and both before and after-strings. When we've skipped to
4905 the end of the overlay, because of its `invisible' property, we
4906 nevertheless want its before-string to appear.
4907 IT->add_overlay_start will contain the overlay start position
4910 Overlay strings are sorted so that after-string strings come in
4911 front of before-string strings. Within before and after-strings,
4912 strings are sorted by overlay priority. See also function
4913 compare_overlay_entries. */
4916 load_overlay_strings (it
, charpos
)
4920 extern Lisp_Object Qwindow
, Qpriority
;
4921 Lisp_Object overlay
, window
, str
, invisible
;
4922 struct Lisp_Overlay
*ov
;
4925 int n
= 0, i
, j
, invis_p
;
4926 struct overlay_entry
*entries
4927 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4930 charpos
= IT_CHARPOS (*it
);
4932 /* Append the overlay string STRING of overlay OVERLAY to vector
4933 `entries' which has size `size' and currently contains `n'
4934 elements. AFTER_P non-zero means STRING is an after-string of
4936 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4939 Lisp_Object priority; \
4943 int new_size = 2 * size; \
4944 struct overlay_entry *old = entries; \
4946 (struct overlay_entry *) alloca (new_size \
4947 * sizeof *entries); \
4948 bcopy (old, entries, size * sizeof *entries); \
4952 entries[n].string = (STRING); \
4953 entries[n].overlay = (OVERLAY); \
4954 priority = Foverlay_get ((OVERLAY), Qpriority); \
4955 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4956 entries[n].after_string_p = (AFTER_P); \
4961 /* Process overlay before the overlay center. */
4962 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4964 XSETMISC (overlay
, ov
);
4965 xassert (OVERLAYP (overlay
));
4966 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4967 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4972 /* Skip this overlay if it doesn't start or end at IT's current
4974 if (end
!= charpos
&& start
!= charpos
)
4977 /* Skip this overlay if it doesn't apply to IT->w. */
4978 window
= Foverlay_get (overlay
, Qwindow
);
4979 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4982 /* If the text ``under'' the overlay is invisible, both before-
4983 and after-strings from this overlay are visible; start and
4984 end position are indistinguishable. */
4985 invisible
= Foverlay_get (overlay
, Qinvisible
);
4986 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4988 /* If overlay has a non-empty before-string, record it. */
4989 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4990 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4992 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4994 /* If overlay has a non-empty after-string, record it. */
4995 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4996 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4998 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5001 /* Process overlays after the overlay center. */
5002 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5004 XSETMISC (overlay
, ov
);
5005 xassert (OVERLAYP (overlay
));
5006 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5007 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5009 if (start
> charpos
)
5012 /* Skip this overlay if it doesn't start or end at IT's current
5014 if (end
!= charpos
&& start
!= charpos
)
5017 /* Skip this overlay if it doesn't apply to IT->w. */
5018 window
= Foverlay_get (overlay
, Qwindow
);
5019 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5022 /* If the text ``under'' the overlay is invisible, it has a zero
5023 dimension, and both before- and after-strings apply. */
5024 invisible
= Foverlay_get (overlay
, Qinvisible
);
5025 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5027 /* If overlay has a non-empty before-string, record it. */
5028 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5029 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5031 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5033 /* If overlay has a non-empty after-string, record it. */
5034 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5035 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5037 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5040 #undef RECORD_OVERLAY_STRING
5044 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5046 /* Record the total number of strings to process. */
5047 it
->n_overlay_strings
= n
;
5049 /* IT->current.overlay_string_index is the number of overlay strings
5050 that have already been consumed by IT. Copy some of the
5051 remaining overlay strings to IT->overlay_strings. */
5053 j
= it
->current
.overlay_string_index
;
5054 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5056 it
->overlay_strings
[i
] = entries
[j
].string
;
5057 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5064 /* Get the first chunk of overlay strings at IT's current buffer
5065 position, or at CHARPOS if that is > 0. Value is non-zero if at
5066 least one overlay string was found. */
5069 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5074 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5075 process. This fills IT->overlay_strings with strings, and sets
5076 IT->n_overlay_strings to the total number of strings to process.
5077 IT->pos.overlay_string_index has to be set temporarily to zero
5078 because load_overlay_strings needs this; it must be set to -1
5079 when no overlay strings are found because a zero value would
5080 indicate a position in the first overlay string. */
5081 it
->current
.overlay_string_index
= 0;
5082 load_overlay_strings (it
, charpos
);
5084 /* If we found overlay strings, set up IT to deliver display
5085 elements from the first one. Otherwise set up IT to deliver
5086 from current_buffer. */
5087 if (it
->n_overlay_strings
)
5089 /* Make sure we know settings in current_buffer, so that we can
5090 restore meaningful values when we're done with the overlay
5093 compute_stop_pos (it
);
5094 xassert (it
->face_id
>= 0);
5096 /* Save IT's settings. They are restored after all overlay
5097 strings have been processed. */
5098 xassert (!compute_stop_p
|| it
->sp
== 0);
5100 /* When called from handle_stop, there might be an empty display
5101 string loaded. In that case, don't bother saving it. */
5102 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5105 /* Set up IT to deliver display elements from the first overlay
5107 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5108 it
->string
= it
->overlay_strings
[0];
5109 it
->from_overlay
= Qnil
;
5110 it
->stop_charpos
= 0;
5111 xassert (STRINGP (it
->string
));
5112 it
->end_charpos
= SCHARS (it
->string
);
5113 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5114 it
->method
= GET_FROM_STRING
;
5118 it
->current
.overlay_string_index
= -1;
5123 get_overlay_strings (it
, charpos
)
5128 it
->method
= GET_FROM_BUFFER
;
5130 (void) get_overlay_strings_1 (it
, charpos
, 1);
5134 /* Value is non-zero if we found at least one overlay string. */
5135 return STRINGP (it
->string
);
5140 /***********************************************************************
5141 Saving and restoring state
5142 ***********************************************************************/
5144 /* Save current settings of IT on IT->stack. Called, for example,
5145 before setting up IT for an overlay string, to be able to restore
5146 IT's settings to what they were after the overlay string has been
5153 struct iterator_stack_entry
*p
;
5155 xassert (it
->sp
< IT_STACK_SIZE
);
5156 p
= it
->stack
+ it
->sp
;
5158 p
->stop_charpos
= it
->stop_charpos
;
5159 p
->prev_stop
= it
->prev_stop
;
5160 p
->base_level_stop
= it
->base_level_stop
;
5161 p
->cmp_it
= it
->cmp_it
;
5162 xassert (it
->face_id
>= 0);
5163 p
->face_id
= it
->face_id
;
5164 p
->string
= it
->string
;
5165 p
->method
= it
->method
;
5166 p
->from_overlay
= it
->from_overlay
;
5169 case GET_FROM_IMAGE
:
5170 p
->u
.image
.object
= it
->object
;
5171 p
->u
.image
.image_id
= it
->image_id
;
5172 p
->u
.image
.slice
= it
->slice
;
5174 case GET_FROM_STRETCH
:
5175 p
->u
.stretch
.object
= it
->object
;
5178 p
->position
= it
->position
;
5179 p
->current
= it
->current
;
5180 p
->end_charpos
= it
->end_charpos
;
5181 p
->string_nchars
= it
->string_nchars
;
5183 p
->multibyte_p
= it
->multibyte_p
;
5184 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5185 p
->space_width
= it
->space_width
;
5186 p
->font_height
= it
->font_height
;
5187 p
->voffset
= it
->voffset
;
5188 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5189 p
->display_ellipsis_p
= 0;
5190 p
->line_wrap
= it
->line_wrap
;
5195 /* Restore IT's settings from IT->stack. Called, for example, when no
5196 more overlay strings must be processed, and we return to delivering
5197 display elements from a buffer, or when the end of a string from a
5198 `display' property is reached and we return to delivering display
5199 elements from an overlay string, or from a buffer. */
5205 struct iterator_stack_entry
*p
;
5207 xassert (it
->sp
> 0);
5209 p
= it
->stack
+ it
->sp
;
5210 it
->stop_charpos
= p
->stop_charpos
;
5211 it
->prev_stop
= p
->prev_stop
;
5212 it
->base_level_stop
= p
->base_level_stop
;
5213 it
->cmp_it
= p
->cmp_it
;
5214 it
->face_id
= p
->face_id
;
5215 it
->current
= p
->current
;
5216 it
->position
= p
->position
;
5217 it
->string
= p
->string
;
5218 it
->from_overlay
= p
->from_overlay
;
5219 if (NILP (it
->string
))
5220 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5221 it
->method
= p
->method
;
5224 case GET_FROM_IMAGE
:
5225 it
->image_id
= p
->u
.image
.image_id
;
5226 it
->object
= p
->u
.image
.object
;
5227 it
->slice
= p
->u
.image
.slice
;
5229 case GET_FROM_STRETCH
:
5230 it
->object
= p
->u
.comp
.object
;
5232 case GET_FROM_BUFFER
:
5233 it
->object
= it
->w
->buffer
;
5235 case GET_FROM_STRING
:
5236 it
->object
= it
->string
;
5238 case GET_FROM_DISPLAY_VECTOR
:
5240 it
->method
= GET_FROM_C_STRING
;
5241 else if (STRINGP (it
->string
))
5242 it
->method
= GET_FROM_STRING
;
5245 it
->method
= GET_FROM_BUFFER
;
5246 it
->object
= it
->w
->buffer
;
5249 it
->end_charpos
= p
->end_charpos
;
5250 it
->string_nchars
= p
->string_nchars
;
5252 it
->multibyte_p
= p
->multibyte_p
;
5253 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5254 it
->space_width
= p
->space_width
;
5255 it
->font_height
= p
->font_height
;
5256 it
->voffset
= p
->voffset
;
5257 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5258 it
->line_wrap
= p
->line_wrap
;
5263 /***********************************************************************
5265 ***********************************************************************/
5267 /* Set IT's current position to the previous line start. */
5270 back_to_previous_line_start (it
)
5273 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5274 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5278 /* Move IT to the next line start.
5280 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5281 we skipped over part of the text (as opposed to moving the iterator
5282 continuously over the text). Otherwise, don't change the value
5285 Newlines may come from buffer text, overlay strings, or strings
5286 displayed via the `display' property. That's the reason we can't
5287 simply use find_next_newline_no_quit.
5289 Note that this function may not skip over invisible text that is so
5290 because of text properties and immediately follows a newline. If
5291 it would, function reseat_at_next_visible_line_start, when called
5292 from set_iterator_to_next, would effectively make invisible
5293 characters following a newline part of the wrong glyph row, which
5294 leads to wrong cursor motion. */
5297 forward_to_next_line_start (it
, skipped_p
)
5301 int old_selective
, newline_found_p
, n
;
5302 const int MAX_NEWLINE_DISTANCE
= 500;
5304 /* If already on a newline, just consume it to avoid unintended
5305 skipping over invisible text below. */
5306 if (it
->what
== IT_CHARACTER
5308 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5310 set_iterator_to_next (it
, 0);
5315 /* Don't handle selective display in the following. It's (a)
5316 unnecessary because it's done by the caller, and (b) leads to an
5317 infinite recursion because next_element_from_ellipsis indirectly
5318 calls this function. */
5319 old_selective
= it
->selective
;
5322 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5323 from buffer text. */
5324 for (n
= newline_found_p
= 0;
5325 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5326 n
+= STRINGP (it
->string
) ? 0 : 1)
5328 if (!get_next_display_element (it
))
5330 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5331 set_iterator_to_next (it
, 0);
5334 /* If we didn't find a newline near enough, see if we can use a
5336 if (!newline_found_p
)
5338 int start
= IT_CHARPOS (*it
);
5339 int limit
= find_next_newline_no_quit (start
, 1);
5342 xassert (!STRINGP (it
->string
));
5344 /* If there isn't any `display' property in sight, and no
5345 overlays, we can just use the position of the newline in
5347 if (it
->stop_charpos
>= limit
5348 || ((pos
= Fnext_single_property_change (make_number (start
),
5350 Qnil
, make_number (limit
)),
5352 && next_overlay_change (start
) == ZV
))
5354 IT_CHARPOS (*it
) = limit
;
5355 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5356 *skipped_p
= newline_found_p
= 1;
5360 while (get_next_display_element (it
)
5361 && !newline_found_p
)
5363 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5364 set_iterator_to_next (it
, 0);
5369 it
->selective
= old_selective
;
5370 return newline_found_p
;
5374 /* Set IT's current position to the previous visible line start. Skip
5375 invisible text that is so either due to text properties or due to
5376 selective display. Caution: this does not change IT->current_x and
5380 back_to_previous_visible_line_start (it
)
5383 while (IT_CHARPOS (*it
) > BEGV
)
5385 back_to_previous_line_start (it
);
5387 if (IT_CHARPOS (*it
) <= BEGV
)
5390 /* If selective > 0, then lines indented more than its value are
5392 if (it
->selective
> 0
5393 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5394 (double) it
->selective
)) /* iftc */
5397 /* Check the newline before point for invisibility. */
5400 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5401 Qinvisible
, it
->window
);
5402 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5406 if (IT_CHARPOS (*it
) <= BEGV
)
5413 Lisp_Object val
, overlay
;
5415 /* If newline is part of a composition, continue from start of composition */
5416 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5417 && beg
< IT_CHARPOS (*it
))
5420 /* If newline is replaced by a display property, find start of overlay
5421 or interval and continue search from that point. */
5423 pos
= --IT_CHARPOS (it2
);
5426 it2
.string_from_display_prop_p
= 0;
5427 if (handle_display_prop (&it2
) == HANDLED_RETURN
5428 && !NILP (val
= get_char_property_and_overlay
5429 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5430 && (OVERLAYP (overlay
)
5431 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5432 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5435 /* Newline is not replaced by anything -- so we are done. */
5441 IT_CHARPOS (*it
) = beg
;
5442 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5446 it
->continuation_lines_width
= 0;
5448 xassert (IT_CHARPOS (*it
) >= BEGV
);
5449 xassert (IT_CHARPOS (*it
) == BEGV
5450 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5455 /* Reseat iterator IT at the previous visible line start. Skip
5456 invisible text that is so either due to text properties or due to
5457 selective display. At the end, update IT's overlay information,
5458 face information etc. */
5461 reseat_at_previous_visible_line_start (it
)
5464 back_to_previous_visible_line_start (it
);
5465 reseat (it
, it
->current
.pos
, 1);
5470 /* Reseat iterator IT on the next visible line start in the current
5471 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5472 preceding the line start. Skip over invisible text that is so
5473 because of selective display. Compute faces, overlays etc at the
5474 new position. Note that this function does not skip over text that
5475 is invisible because of text properties. */
5478 reseat_at_next_visible_line_start (it
, on_newline_p
)
5482 int newline_found_p
, skipped_p
= 0;
5484 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5486 /* Skip over lines that are invisible because they are indented
5487 more than the value of IT->selective. */
5488 if (it
->selective
> 0)
5489 while (IT_CHARPOS (*it
) < ZV
5490 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5491 (double) it
->selective
)) /* iftc */
5493 xassert (IT_BYTEPOS (*it
) == BEGV
5494 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5495 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5498 /* Position on the newline if that's what's requested. */
5499 if (on_newline_p
&& newline_found_p
)
5501 if (STRINGP (it
->string
))
5503 if (IT_STRING_CHARPOS (*it
) > 0)
5505 --IT_STRING_CHARPOS (*it
);
5506 --IT_STRING_BYTEPOS (*it
);
5509 else if (IT_CHARPOS (*it
) > BEGV
)
5513 reseat (it
, it
->current
.pos
, 0);
5517 reseat (it
, it
->current
.pos
, 0);
5524 /***********************************************************************
5525 Changing an iterator's position
5526 ***********************************************************************/
5528 /* Change IT's current position to POS in current_buffer. If FORCE_P
5529 is non-zero, always check for text properties at the new position.
5530 Otherwise, text properties are only looked up if POS >=
5531 IT->check_charpos of a property. */
5534 reseat (it
, pos
, force_p
)
5536 struct text_pos pos
;
5539 int original_pos
= IT_CHARPOS (*it
);
5541 reseat_1 (it
, pos
, 0);
5543 /* Determine where to check text properties. Avoid doing it
5544 where possible because text property lookup is very expensive. */
5546 || CHARPOS (pos
) > it
->stop_charpos
5547 || CHARPOS (pos
) < original_pos
)
5551 /* For bidi iteration, we need to prime prev_stop and
5552 base_level_stop with our best estimations. */
5553 if (CHARPOS (pos
) < it
->prev_stop
)
5555 handle_stop_backwards (it
, BEGV
);
5556 if (CHARPOS (pos
) < it
->base_level_stop
)
5557 it
->base_level_stop
= 0;
5559 else if (CHARPOS (pos
) > it
->stop_charpos
5560 && it
->stop_charpos
>= BEGV
)
5561 handle_stop_backwards (it
, it
->stop_charpos
);
5568 it
->prev_stop
= it
->base_level_stop
= 0;
5577 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5578 IT->stop_pos to POS, also. */
5581 reseat_1 (it
, pos
, set_stop_p
)
5583 struct text_pos pos
;
5586 /* Don't call this function when scanning a C string. */
5587 xassert (it
->s
== NULL
);
5589 /* POS must be a reasonable value. */
5590 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5592 it
->current
.pos
= it
->position
= pos
;
5593 it
->end_charpos
= ZV
;
5595 it
->current
.dpvec_index
= -1;
5596 it
->current
.overlay_string_index
= -1;
5597 IT_STRING_CHARPOS (*it
) = -1;
5598 IT_STRING_BYTEPOS (*it
) = -1;
5600 it
->string_from_display_prop_p
= 0;
5601 it
->method
= GET_FROM_BUFFER
;
5602 it
->object
= it
->w
->buffer
;
5603 it
->area
= TEXT_AREA
;
5604 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5606 it
->string_from_display_prop_p
= 0;
5607 it
->face_before_selective_p
= 0;
5609 it
->bidi_it
.first_elt
= 1;
5613 it
->stop_charpos
= CHARPOS (pos
);
5614 it
->base_level_stop
= CHARPOS (pos
);
5619 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5620 If S is non-null, it is a C string to iterate over. Otherwise,
5621 STRING gives a Lisp string to iterate over.
5623 If PRECISION > 0, don't return more then PRECISION number of
5624 characters from the string.
5626 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5627 characters have been returned. FIELD_WIDTH < 0 means an infinite
5630 MULTIBYTE = 0 means disable processing of multibyte characters,
5631 MULTIBYTE > 0 means enable it,
5632 MULTIBYTE < 0 means use IT->multibyte_p.
5634 IT must be initialized via a prior call to init_iterator before
5635 calling this function. */
5638 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5643 int precision
, field_width
, multibyte
;
5645 /* No region in strings. */
5646 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5648 /* No text property checks performed by default, but see below. */
5649 it
->stop_charpos
= -1;
5651 /* Set iterator position and end position. */
5652 bzero (&it
->current
, sizeof it
->current
);
5653 it
->current
.overlay_string_index
= -1;
5654 it
->current
.dpvec_index
= -1;
5655 xassert (charpos
>= 0);
5657 /* If STRING is specified, use its multibyteness, otherwise use the
5658 setting of MULTIBYTE, if specified. */
5660 it
->multibyte_p
= multibyte
> 0;
5664 xassert (STRINGP (string
));
5665 it
->string
= string
;
5667 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5668 it
->method
= GET_FROM_STRING
;
5669 it
->current
.string_pos
= string_pos (charpos
, string
);
5676 /* Note that we use IT->current.pos, not it->current.string_pos,
5677 for displaying C strings. */
5678 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5679 if (it
->multibyte_p
)
5681 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5682 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5686 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5687 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5690 it
->method
= GET_FROM_C_STRING
;
5693 /* PRECISION > 0 means don't return more than PRECISION characters
5695 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5696 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5698 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5699 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5700 FIELD_WIDTH < 0 means infinite field width. This is useful for
5701 padding with `-' at the end of a mode line. */
5702 if (field_width
< 0)
5703 field_width
= INFINITY
;
5704 if (field_width
> it
->end_charpos
- charpos
)
5705 it
->end_charpos
= charpos
+ field_width
;
5707 /* Use the standard display table for displaying strings. */
5708 if (DISP_TABLE_P (Vstandard_display_table
))
5709 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5711 it
->stop_charpos
= charpos
;
5712 if (s
== NULL
&& it
->multibyte_p
)
5714 EMACS_INT endpos
= SCHARS (it
->string
);
5715 if (endpos
> it
->end_charpos
)
5716 endpos
= it
->end_charpos
;
5717 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5725 /***********************************************************************
5727 ***********************************************************************/
5729 /* Map enum it_method value to corresponding next_element_from_* function. */
5731 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5733 next_element_from_buffer
,
5734 next_element_from_display_vector
,
5735 next_element_from_string
,
5736 next_element_from_c_string
,
5737 next_element_from_image
,
5738 next_element_from_stretch
5741 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5744 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5745 (possibly with the following characters). */
5747 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5748 ((IT)->cmp_it.id >= 0 \
5749 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5750 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5751 END_CHARPOS, (IT)->w, \
5752 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5756 /* Load IT's display element fields with information about the next
5757 display element from the current position of IT. Value is zero if
5758 end of buffer (or C string) is reached. */
5760 static struct frame
*last_escape_glyph_frame
= NULL
;
5761 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5762 static int last_escape_glyph_merged_face_id
= 0;
5765 get_next_display_element (it
)
5768 /* Non-zero means that we found a display element. Zero means that
5769 we hit the end of what we iterate over. Performance note: the
5770 function pointer `method' used here turns out to be faster than
5771 using a sequence of if-statements. */
5775 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5777 if (it
->what
== IT_CHARACTER
)
5779 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5780 and only if (a) the resolved directionality of that character
5782 /* FIXME: Do we need an exception for characters from display
5784 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5785 it
->c
= bidi_mirror_char (it
->c
);
5786 /* Map via display table or translate control characters.
5787 IT->c, IT->len etc. have been set to the next character by
5788 the function call above. If we have a display table, and it
5789 contains an entry for IT->c, translate it. Don't do this if
5790 IT->c itself comes from a display table, otherwise we could
5791 end up in an infinite recursion. (An alternative could be to
5792 count the recursion depth of this function and signal an
5793 error when a certain maximum depth is reached.) Is it worth
5795 if (success_p
&& it
->dpvec
== NULL
)
5798 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5799 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5800 nbsp_or_shy
= char_is_other
;
5801 int decoded
= it
->c
;
5804 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5807 struct Lisp_Vector
*v
= XVECTOR (dv
);
5809 /* Return the first character from the display table
5810 entry, if not empty. If empty, don't display the
5811 current character. */
5814 it
->dpvec_char_len
= it
->len
;
5815 it
->dpvec
= v
->contents
;
5816 it
->dpend
= v
->contents
+ v
->size
;
5817 it
->current
.dpvec_index
= 0;
5818 it
->dpvec_face_id
= -1;
5819 it
->saved_face_id
= it
->face_id
;
5820 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5825 set_iterator_to_next (it
, 0);
5830 if (unibyte_display_via_language_environment
5831 && !ASCII_CHAR_P (it
->c
))
5832 decoded
= DECODE_CHAR (unibyte
, it
->c
);
5834 if (it
->c
>= 0x80 && ! NILP (Vnobreak_char_display
))
5836 if (it
->multibyte_p
)
5837 nbsp_or_shy
= (it
->c
== 0xA0 ? char_is_nbsp
5838 : it
->c
== 0xAD ? char_is_soft_hyphen
5840 else if (unibyte_display_via_language_environment
)
5841 nbsp_or_shy
= (decoded
== 0xA0 ? char_is_nbsp
5842 : decoded
== 0xAD ? char_is_soft_hyphen
5846 /* Translate control characters into `\003' or `^C' form.
5847 Control characters coming from a display table entry are
5848 currently not translated because we use IT->dpvec to hold
5849 the translation. This could easily be changed but I
5850 don't believe that it is worth doing.
5852 If it->multibyte_p is nonzero, non-printable non-ASCII
5853 characters are also translated to octal form.
5855 If it->multibyte_p is zero, eight-bit characters that
5856 don't have corresponding multibyte char code are also
5857 translated to octal form. */
5859 ? (it
->area
!= TEXT_AREA
5860 /* In mode line, treat \n, \t like other crl chars. */
5863 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5864 || (it
->c
!= '\n' && it
->c
!= '\t'))
5867 ? ! CHAR_PRINTABLE_P (it
->c
)
5868 : (! unibyte_display_via_language_environment
5870 : (decoded
>= 0x80 && decoded
< 0xA0))))))
5872 /* IT->c is a control character which must be displayed
5873 either as '\003' or as `^C' where the '\\' and '^'
5874 can be defined in the display table. Fill
5875 IT->ctl_chars with glyphs for what we have to
5876 display. Then, set IT->dpvec to these glyphs. */
5879 int face_id
, lface_id
= 0 ;
5882 /* Handle control characters with ^. */
5884 if (it
->c
< 128 && it
->ctl_arrow_p
)
5888 g
= '^'; /* default glyph for Control */
5889 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5891 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5892 && GLYPH_CODE_CHAR_VALID_P (gc
))
5894 g
= GLYPH_CODE_CHAR (gc
);
5895 lface_id
= GLYPH_CODE_FACE (gc
);
5899 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5901 else if (it
->f
== last_escape_glyph_frame
5902 && it
->face_id
== last_escape_glyph_face_id
)
5904 face_id
= last_escape_glyph_merged_face_id
;
5908 /* Merge the escape-glyph face into the current face. */
5909 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5911 last_escape_glyph_frame
= it
->f
;
5912 last_escape_glyph_face_id
= it
->face_id
;
5913 last_escape_glyph_merged_face_id
= face_id
;
5916 XSETINT (it
->ctl_chars
[0], g
);
5917 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5919 goto display_control
;
5922 /* Handle non-break space in the mode where it only gets
5925 if (EQ (Vnobreak_char_display
, Qt
)
5926 && nbsp_or_shy
== char_is_nbsp
)
5928 /* Merge the no-break-space face into the current face. */
5929 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5933 XSETINT (it
->ctl_chars
[0], ' ');
5935 goto display_control
;
5938 /* Handle sequences that start with the "escape glyph". */
5940 /* the default escape glyph is \. */
5941 escape_glyph
= '\\';
5944 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5945 && GLYPH_CODE_CHAR_VALID_P (gc
))
5947 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5948 lface_id
= GLYPH_CODE_FACE (gc
);
5952 /* The display table specified a face.
5953 Merge it into face_id and also into escape_glyph. */
5954 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5957 else if (it
->f
== last_escape_glyph_frame
5958 && it
->face_id
== last_escape_glyph_face_id
)
5960 face_id
= last_escape_glyph_merged_face_id
;
5964 /* Merge the escape-glyph face into the current face. */
5965 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5967 last_escape_glyph_frame
= it
->f
;
5968 last_escape_glyph_face_id
= it
->face_id
;
5969 last_escape_glyph_merged_face_id
= face_id
;
5972 /* Handle soft hyphens in the mode where they only get
5975 if (EQ (Vnobreak_char_display
, Qt
)
5976 && nbsp_or_shy
== char_is_soft_hyphen
)
5979 XSETINT (it
->ctl_chars
[0], '-');
5981 goto display_control
;
5984 /* Handle non-break space and soft hyphen
5985 with the escape glyph. */
5989 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5990 it
->c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5991 XSETINT (it
->ctl_chars
[1], it
->c
);
5993 goto display_control
;
5997 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6001 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
6002 if (CHAR_BYTE8_P (it
->c
))
6004 str
[0] = CHAR_TO_BYTE8 (it
->c
);
6007 else if (it
->c
< 256)
6014 /* It's an invalid character, which shouldn't
6015 happen actually, but due to bugs it may
6016 happen. Let's print the char as is, there's
6017 not much meaningful we can do with it. */
6019 str
[1] = it
->c
>> 8;
6020 str
[2] = it
->c
>> 16;
6021 str
[3] = it
->c
>> 24;
6025 for (i
= 0; i
< len
; i
++)
6028 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
6029 /* Insert three more glyphs into IT->ctl_chars for
6030 the octal display of the character. */
6031 g
= ((str
[i
] >> 6) & 7) + '0';
6032 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
6033 g
= ((str
[i
] >> 3) & 7) + '0';
6034 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
6035 g
= (str
[i
] & 7) + '0';
6036 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
6042 /* Set up IT->dpvec and return first character from it. */
6043 it
->dpvec_char_len
= it
->len
;
6044 it
->dpvec
= it
->ctl_chars
;
6045 it
->dpend
= it
->dpvec
+ ctl_len
;
6046 it
->current
.dpvec_index
= 0;
6047 it
->dpvec_face_id
= face_id
;
6048 it
->saved_face_id
= it
->face_id
;
6049 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6056 #ifdef HAVE_WINDOW_SYSTEM
6057 /* Adjust face id for a multibyte character. There are no multibyte
6058 character in unibyte text. */
6059 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6062 && FRAME_WINDOW_P (it
->f
))
6064 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6066 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6068 /* Automatic composition with glyph-string. */
6069 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6071 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6075 int pos
= (it
->s
? -1
6076 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6077 : IT_CHARPOS (*it
));
6079 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
6084 /* Is this character the last one of a run of characters with
6085 box? If yes, set IT->end_of_box_run_p to 1. */
6089 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6091 int face_id
= underlying_face_id (it
);
6092 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6096 if (face
->box
== FACE_NO_BOX
)
6098 /* If the box comes from face properties in a
6099 display string, check faces in that string. */
6100 int string_face_id
= face_after_it_pos (it
);
6101 it
->end_of_box_run_p
6102 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6105 /* Otherwise, the box comes from the underlying face.
6106 If this is the last string character displayed, check
6107 the next buffer location. */
6108 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6109 && (it
->current
.overlay_string_index
6110 == it
->n_overlay_strings
- 1))
6114 struct text_pos pos
= it
->current
.pos
;
6115 INC_TEXT_POS (pos
, it
->multibyte_p
);
6117 next_face_id
= face_at_buffer_position
6118 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6119 it
->region_end_charpos
, &ignore
,
6120 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6122 it
->end_of_box_run_p
6123 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6130 int face_id
= face_after_it_pos (it
);
6131 it
->end_of_box_run_p
6132 = (face_id
!= it
->face_id
6133 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6137 /* Value is 0 if end of buffer or string reached. */
6142 /* Move IT to the next display element.
6144 RESEAT_P non-zero means if called on a newline in buffer text,
6145 skip to the next visible line start.
6147 Functions get_next_display_element and set_iterator_to_next are
6148 separate because I find this arrangement easier to handle than a
6149 get_next_display_element function that also increments IT's
6150 position. The way it is we can first look at an iterator's current
6151 display element, decide whether it fits on a line, and if it does,
6152 increment the iterator position. The other way around we probably
6153 would either need a flag indicating whether the iterator has to be
6154 incremented the next time, or we would have to implement a
6155 decrement position function which would not be easy to write. */
6158 set_iterator_to_next (it
, reseat_p
)
6162 /* Reset flags indicating start and end of a sequence of characters
6163 with box. Reset them at the start of this function because
6164 moving the iterator to a new position might set them. */
6165 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6169 case GET_FROM_BUFFER
:
6170 /* The current display element of IT is a character from
6171 current_buffer. Advance in the buffer, and maybe skip over
6172 invisible lines that are so because of selective display. */
6173 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6174 reseat_at_next_visible_line_start (it
, 0);
6175 else if (it
->cmp_it
.id
>= 0)
6177 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6178 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6179 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6180 it
->cmp_it
.from
= it
->cmp_it
.to
;
6184 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6185 IT_BYTEPOS (*it
), it
->stop_charpos
,
6191 xassert (it
->len
!= 0);
6195 IT_BYTEPOS (*it
) += it
->len
;
6196 IT_CHARPOS (*it
) += 1;
6200 /* If this is a new paragraph, determine its base
6201 direction (a.k.a. its base embedding level). */
6202 if (it
->bidi_it
.new_paragraph
)
6203 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6204 bidi_get_next_char_visually (&it
->bidi_it
);
6205 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6206 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6208 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6212 case GET_FROM_C_STRING
:
6213 /* Current display element of IT is from a C string. */
6214 IT_BYTEPOS (*it
) += it
->len
;
6215 IT_CHARPOS (*it
) += 1;
6218 case GET_FROM_DISPLAY_VECTOR
:
6219 /* Current display element of IT is from a display table entry.
6220 Advance in the display table definition. Reset it to null if
6221 end reached, and continue with characters from buffers/
6223 ++it
->current
.dpvec_index
;
6225 /* Restore face of the iterator to what they were before the
6226 display vector entry (these entries may contain faces). */
6227 it
->face_id
= it
->saved_face_id
;
6229 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6231 int recheck_faces
= it
->ellipsis_p
;
6234 it
->method
= GET_FROM_C_STRING
;
6235 else if (STRINGP (it
->string
))
6236 it
->method
= GET_FROM_STRING
;
6239 it
->method
= GET_FROM_BUFFER
;
6240 it
->object
= it
->w
->buffer
;
6244 it
->current
.dpvec_index
= -1;
6246 /* Skip over characters which were displayed via IT->dpvec. */
6247 if (it
->dpvec_char_len
< 0)
6248 reseat_at_next_visible_line_start (it
, 1);
6249 else if (it
->dpvec_char_len
> 0)
6251 if (it
->method
== GET_FROM_STRING
6252 && it
->n_overlay_strings
> 0)
6253 it
->ignore_overlay_strings_at_pos_p
= 1;
6254 it
->len
= it
->dpvec_char_len
;
6255 set_iterator_to_next (it
, reseat_p
);
6258 /* Maybe recheck faces after display vector */
6260 it
->stop_charpos
= IT_CHARPOS (*it
);
6264 case GET_FROM_STRING
:
6265 /* Current display element is a character from a Lisp string. */
6266 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6267 if (it
->cmp_it
.id
>= 0)
6269 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6270 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6271 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6272 it
->cmp_it
.from
= it
->cmp_it
.to
;
6276 composition_compute_stop_pos (&it
->cmp_it
,
6277 IT_STRING_CHARPOS (*it
),
6278 IT_STRING_BYTEPOS (*it
),
6279 it
->stop_charpos
, it
->string
);
6284 IT_STRING_BYTEPOS (*it
) += it
->len
;
6285 IT_STRING_CHARPOS (*it
) += 1;
6288 consider_string_end
:
6290 if (it
->current
.overlay_string_index
>= 0)
6292 /* IT->string is an overlay string. Advance to the
6293 next, if there is one. */
6294 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6297 next_overlay_string (it
);
6299 setup_for_ellipsis (it
, 0);
6304 /* IT->string is not an overlay string. If we reached
6305 its end, and there is something on IT->stack, proceed
6306 with what is on the stack. This can be either another
6307 string, this time an overlay string, or a buffer. */
6308 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6312 if (it
->method
== GET_FROM_STRING
)
6313 goto consider_string_end
;
6318 case GET_FROM_IMAGE
:
6319 case GET_FROM_STRETCH
:
6320 /* The position etc with which we have to proceed are on
6321 the stack. The position may be at the end of a string,
6322 if the `display' property takes up the whole string. */
6323 xassert (it
->sp
> 0);
6325 if (it
->method
== GET_FROM_STRING
)
6326 goto consider_string_end
;
6330 /* There are no other methods defined, so this should be a bug. */
6334 xassert (it
->method
!= GET_FROM_STRING
6335 || (STRINGP (it
->string
)
6336 && IT_STRING_CHARPOS (*it
) >= 0));
6339 /* Load IT's display element fields with information about the next
6340 display element which comes from a display table entry or from the
6341 result of translating a control character to one of the forms `^C'
6344 IT->dpvec holds the glyphs to return as characters.
6345 IT->saved_face_id holds the face id before the display vector--it
6346 is restored into IT->face_id in set_iterator_to_next. */
6349 next_element_from_display_vector (it
)
6355 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6357 it
->face_id
= it
->saved_face_id
;
6359 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6360 That seemed totally bogus - so I changed it... */
6361 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6363 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6365 it
->c
= GLYPH_CODE_CHAR (gc
);
6366 it
->len
= CHAR_BYTES (it
->c
);
6368 /* The entry may contain a face id to use. Such a face id is
6369 the id of a Lisp face, not a realized face. A face id of
6370 zero means no face is specified. */
6371 if (it
->dpvec_face_id
>= 0)
6372 it
->face_id
= it
->dpvec_face_id
;
6375 int lface_id
= GLYPH_CODE_FACE (gc
);
6377 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6382 /* Display table entry is invalid. Return a space. */
6383 it
->c
= ' ', it
->len
= 1;
6385 /* Don't change position and object of the iterator here. They are
6386 still the values of the character that had this display table
6387 entry or was translated, and that's what we want. */
6388 it
->what
= IT_CHARACTER
;
6393 /* Load IT with the next display element from Lisp string IT->string.
6394 IT->current.string_pos is the current position within the string.
6395 If IT->current.overlay_string_index >= 0, the Lisp string is an
6399 next_element_from_string (it
)
6402 struct text_pos position
;
6404 xassert (STRINGP (it
->string
));
6405 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6406 position
= it
->current
.string_pos
;
6408 /* Time to check for invisible text? */
6409 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6410 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6414 /* Since a handler may have changed IT->method, we must
6416 return GET_NEXT_DISPLAY_ELEMENT (it
);
6419 if (it
->current
.overlay_string_index
>= 0)
6421 /* Get the next character from an overlay string. In overlay
6422 strings, There is no field width or padding with spaces to
6424 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6429 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6430 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6431 && next_element_from_composition (it
))
6435 else if (STRING_MULTIBYTE (it
->string
))
6437 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6438 const unsigned char *s
= (SDATA (it
->string
)
6439 + IT_STRING_BYTEPOS (*it
));
6440 it
->c
= string_char_and_length (s
, &it
->len
);
6444 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6450 /* Get the next character from a Lisp string that is not an
6451 overlay string. Such strings come from the mode line, for
6452 example. We may have to pad with spaces, or truncate the
6453 string. See also next_element_from_c_string. */
6454 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6459 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6461 /* Pad with spaces. */
6462 it
->c
= ' ', it
->len
= 1;
6463 CHARPOS (position
) = BYTEPOS (position
) = -1;
6465 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6466 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6467 && next_element_from_composition (it
))
6471 else if (STRING_MULTIBYTE (it
->string
))
6473 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6474 const unsigned char *s
= (SDATA (it
->string
)
6475 + IT_STRING_BYTEPOS (*it
));
6476 it
->c
= string_char_and_length (s
, &it
->len
);
6480 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6485 /* Record what we have and where it came from. */
6486 it
->what
= IT_CHARACTER
;
6487 it
->object
= it
->string
;
6488 it
->position
= position
;
6493 /* Load IT with next display element from C string IT->s.
6494 IT->string_nchars is the maximum number of characters to return
6495 from the string. IT->end_charpos may be greater than
6496 IT->string_nchars when this function is called, in which case we
6497 may have to return padding spaces. Value is zero if end of string
6498 reached, including padding spaces. */
6501 next_element_from_c_string (it
)
6507 it
->what
= IT_CHARACTER
;
6508 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6511 /* IT's position can be greater IT->string_nchars in case a field
6512 width or precision has been specified when the iterator was
6514 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6516 /* End of the game. */
6520 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6522 /* Pad with spaces. */
6523 it
->c
= ' ', it
->len
= 1;
6524 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6526 else if (it
->multibyte_p
)
6528 /* Implementation note: The calls to strlen apparently aren't a
6529 performance problem because there is no noticeable performance
6530 difference between Emacs running in unibyte or multibyte mode. */
6531 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6532 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6535 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6541 /* Set up IT to return characters from an ellipsis, if appropriate.
6542 The definition of the ellipsis glyphs may come from a display table
6543 entry. This function fills IT with the first glyph from the
6544 ellipsis if an ellipsis is to be displayed. */
6547 next_element_from_ellipsis (it
)
6550 if (it
->selective_display_ellipsis_p
)
6551 setup_for_ellipsis (it
, it
->len
);
6554 /* The face at the current position may be different from the
6555 face we find after the invisible text. Remember what it
6556 was in IT->saved_face_id, and signal that it's there by
6557 setting face_before_selective_p. */
6558 it
->saved_face_id
= it
->face_id
;
6559 it
->method
= GET_FROM_BUFFER
;
6560 it
->object
= it
->w
->buffer
;
6561 reseat_at_next_visible_line_start (it
, 1);
6562 it
->face_before_selective_p
= 1;
6565 return GET_NEXT_DISPLAY_ELEMENT (it
);
6569 /* Deliver an image display element. The iterator IT is already
6570 filled with image information (done in handle_display_prop). Value
6575 next_element_from_image (it
)
6578 it
->what
= IT_IMAGE
;
6583 /* Fill iterator IT with next display element from a stretch glyph
6584 property. IT->object is the value of the text property. Value is
6588 next_element_from_stretch (it
)
6591 it
->what
= IT_STRETCH
;
6595 /* Scan forward from CHARPOS in the current buffer, until we find a
6596 stop position > current IT's position. Then handle the stop
6597 position before that. This is called when we bump into a stop
6598 position while reordering bidirectional text. */
6601 handle_stop_backwards (it
, charpos
)
6605 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6606 struct display_pos save_current
= it
->current
;
6607 struct text_pos save_position
= it
->position
;
6608 struct text_pos pos1
;
6609 EMACS_INT next_stop
;
6611 /* Scan in strict logical order. */
6615 it
->prev_stop
= charpos
;
6616 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6617 reseat_1 (it
, pos1
, 0);
6618 compute_stop_pos (it
);
6619 /* We must advance forward, right? */
6620 if (it
->stop_charpos
<= it
->prev_stop
)
6622 charpos
= it
->stop_charpos
;
6624 while (charpos
<= where_we_are
);
6626 next_stop
= it
->stop_charpos
;
6627 it
->stop_charpos
= it
->prev_stop
;
6629 it
->current
= save_current
;
6630 it
->position
= save_position
;
6632 it
->stop_charpos
= next_stop
;
6635 /* Load IT with the next display element from current_buffer. Value
6636 is zero if end of buffer reached. IT->stop_charpos is the next
6637 position at which to stop and check for text properties or buffer
6641 next_element_from_buffer (it
)
6646 xassert (IT_CHARPOS (*it
) >= BEGV
);
6648 /* With bidi reordering, the character to display might not be the
6649 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6650 we were reseat()ed to a new buffer position, which is potentially
6651 a different paragraph. */
6652 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6654 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6655 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6656 /* If we are at the beginning of a line, we can produce the next
6657 element right away. */
6658 if (it
->bidi_it
.bytepos
== BEGV_BYTE
6659 /* FIXME: Should support all Unicode line separators. */
6660 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6661 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6663 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6664 bidi_get_next_char_visually (&it
->bidi_it
);
6668 int orig_bytepos
= IT_BYTEPOS (*it
);
6670 /* We need to prime the bidi iterator starting at the line's
6671 beginning, before we will be able to produce the next
6673 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6674 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6675 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6676 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6677 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6680 /* Now return to buffer position where we were asked to
6681 get the next display element, and produce that. */
6682 bidi_get_next_char_visually (&it
->bidi_it
);
6684 while (it
->bidi_it
.bytepos
!= orig_bytepos
6685 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6688 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6689 /* Adjust IT's position information to where we ended up. */
6690 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6691 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6692 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6695 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6697 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6699 int overlay_strings_follow_p
;
6701 /* End of the game, except when overlay strings follow that
6702 haven't been returned yet. */
6703 if (it
->overlay_strings_at_end_processed_p
)
6704 overlay_strings_follow_p
= 0;
6707 it
->overlay_strings_at_end_processed_p
= 1;
6708 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6711 if (overlay_strings_follow_p
)
6712 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6716 it
->position
= it
->current
.pos
;
6720 else if (!(!it
->bidi_p
6721 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6722 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6724 /* With bidi non-linear iteration, we could find ourselves
6725 far beyond the last computed stop_charpos, with several
6726 other stop positions in between that we missed. Scan
6727 them all now, in buffer's logical order, until we find
6728 and handle the last stop_charpos that precedes our
6729 current position. */
6730 handle_stop_backwards (it
, it
->stop_charpos
);
6731 return GET_NEXT_DISPLAY_ELEMENT (it
);
6737 /* Take note of the stop position we just moved across,
6738 for when we will move back across it. */
6739 it
->prev_stop
= it
->stop_charpos
;
6740 /* If we are at base paragraph embedding level, take
6741 note of the last stop position seen at this
6743 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6744 it
->base_level_stop
= it
->stop_charpos
;
6747 return GET_NEXT_DISPLAY_ELEMENT (it
);
6751 /* We can sometimes back up for reasons that have nothing
6752 to do with bidi reordering. E.g., compositions. The
6753 code below is only needed when we are above the base
6754 embedding level, so test for that explicitly. */
6755 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6756 && IT_CHARPOS (*it
) < it
->prev_stop
)
6758 if (it
->base_level_stop
<= 0)
6759 it
->base_level_stop
= BEGV
;
6760 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6762 handle_stop_backwards (it
, it
->base_level_stop
);
6763 return GET_NEXT_DISPLAY_ELEMENT (it
);
6767 /* No face changes, overlays etc. in sight, so just return a
6768 character from current_buffer. */
6771 /* Maybe run the redisplay end trigger hook. Performance note:
6772 This doesn't seem to cost measurable time. */
6773 if (it
->redisplay_end_trigger_charpos
6775 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6776 run_redisplay_end_trigger_hook (it
);
6778 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6780 && next_element_from_composition (it
))
6785 /* Get the next character, maybe multibyte. */
6786 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6787 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6788 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6790 it
->c
= *p
, it
->len
= 1;
6792 /* Record what we have and where it came from. */
6793 it
->what
= IT_CHARACTER
;
6794 it
->object
= it
->w
->buffer
;
6795 it
->position
= it
->current
.pos
;
6797 /* Normally we return the character found above, except when we
6798 really want to return an ellipsis for selective display. */
6803 /* A value of selective > 0 means hide lines indented more
6804 than that number of columns. */
6805 if (it
->selective
> 0
6806 && IT_CHARPOS (*it
) + 1 < ZV
6807 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6808 IT_BYTEPOS (*it
) + 1,
6809 (double) it
->selective
)) /* iftc */
6811 success_p
= next_element_from_ellipsis (it
);
6812 it
->dpvec_char_len
= -1;
6815 else if (it
->c
== '\r' && it
->selective
== -1)
6817 /* A value of selective == -1 means that everything from the
6818 CR to the end of the line is invisible, with maybe an
6819 ellipsis displayed for it. */
6820 success_p
= next_element_from_ellipsis (it
);
6821 it
->dpvec_char_len
= -1;
6826 /* Value is zero if end of buffer reached. */
6827 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6832 /* Run the redisplay end trigger hook for IT. */
6835 run_redisplay_end_trigger_hook (it
)
6838 Lisp_Object args
[3];
6840 /* IT->glyph_row should be non-null, i.e. we should be actually
6841 displaying something, or otherwise we should not run the hook. */
6842 xassert (it
->glyph_row
);
6844 /* Set up hook arguments. */
6845 args
[0] = Qredisplay_end_trigger_functions
;
6846 args
[1] = it
->window
;
6847 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6848 it
->redisplay_end_trigger_charpos
= 0;
6850 /* Since we are *trying* to run these functions, don't try to run
6851 them again, even if they get an error. */
6852 it
->w
->redisplay_end_trigger
= Qnil
;
6853 Frun_hook_with_args (3, args
);
6855 /* Notice if it changed the face of the character we are on. */
6856 handle_face_prop (it
);
6860 /* Deliver a composition display element. Unlike the other
6861 next_element_from_XXX, this function is not registered in the array
6862 get_next_element[]. It is called from next_element_from_buffer and
6863 next_element_from_string when necessary. */
6866 next_element_from_composition (it
)
6869 it
->what
= IT_COMPOSITION
;
6870 it
->len
= it
->cmp_it
.nbytes
;
6871 if (STRINGP (it
->string
))
6875 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6876 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6879 it
->position
= it
->current
.string_pos
;
6880 it
->object
= it
->string
;
6881 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6882 IT_STRING_BYTEPOS (*it
), it
->string
);
6888 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6889 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6892 it
->position
= it
->current
.pos
;
6893 it
->object
= it
->w
->buffer
;
6894 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6895 IT_BYTEPOS (*it
), Qnil
);
6902 /***********************************************************************
6903 Moving an iterator without producing glyphs
6904 ***********************************************************************/
6906 /* Check if iterator is at a position corresponding to a valid buffer
6907 position after some move_it_ call. */
6909 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6910 ((it)->method == GET_FROM_STRING \
6911 ? IT_STRING_CHARPOS (*it) == 0 \
6915 /* Move iterator IT to a specified buffer or X position within one
6916 line on the display without producing glyphs.
6918 OP should be a bit mask including some or all of these bits:
6919 MOVE_TO_X: Stop upon reaching x-position TO_X.
6920 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
6921 Regardless of OP's value, stop upon reaching the end of the display line.
6923 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6924 This means, in particular, that TO_X includes window's horizontal
6927 The return value has several possible values that
6928 say what condition caused the scan to stop:
6930 MOVE_POS_MATCH_OR_ZV
6931 - when TO_POS or ZV was reached.
6934 -when TO_X was reached before TO_POS or ZV were reached.
6937 - when we reached the end of the display area and the line must
6941 - when we reached the end of the display area and the line is
6945 - when we stopped at a line end, i.e. a newline or a CR and selective
6948 static enum move_it_result
6949 move_it_in_display_line_to (struct it
*it
,
6950 EMACS_INT to_charpos
, int to_x
,
6951 enum move_operation_enum op
)
6953 enum move_it_result result
= MOVE_UNDEFINED
;
6954 struct glyph_row
*saved_glyph_row
;
6955 struct it wrap_it
, atpos_it
, atx_it
;
6957 enum it_method prev_method
= it
->method
;
6958 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
6960 /* Don't produce glyphs in produce_glyphs. */
6961 saved_glyph_row
= it
->glyph_row
;
6962 it
->glyph_row
= NULL
;
6964 /* Use wrap_it to save a copy of IT wherever a word wrap could
6965 occur. Use atpos_it to save a copy of IT at the desired buffer
6966 position, if found, so that we can scan ahead and check if the
6967 word later overshoots the window edge. Use atx_it similarly, for
6973 #define BUFFER_POS_REACHED_P() \
6974 ((op & MOVE_TO_POS) != 0 \
6975 && BUFFERP (it->object) \
6976 && (IT_CHARPOS (*it) == to_charpos \
6977 || (!it->bidi_p && IT_CHARPOS (*it) > to_charpos)) \
6978 && (it->method == GET_FROM_BUFFER \
6979 || (it->method == GET_FROM_DISPLAY_VECTOR \
6980 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6982 /* If there's a line-/wrap-prefix, handle it. */
6983 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6984 && it
->current_y
< it
->last_visible_y
)
6985 handle_line_prefix (it
);
6989 int x
, i
, ascent
= 0, descent
= 0;
6991 /* Utility macro to reset an iterator with x, ascent, and descent. */
6992 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6993 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6994 (IT)->max_descent = descent)
6996 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6998 if ((op
& MOVE_TO_POS
) != 0
6999 && BUFFERP (it
->object
)
7000 && it
->method
== GET_FROM_BUFFER
7001 && ((!it
->bidi_p
&& IT_CHARPOS (*it
) > to_charpos
)
7003 && (prev_method
== GET_FROM_IMAGE
7004 || prev_method
== GET_FROM_STRETCH
)
7005 /* Passed TO_CHARPOS from left to right. */
7006 && ((prev_pos
< to_charpos
7007 && IT_CHARPOS (*it
) > to_charpos
)
7008 /* Passed TO_CHARPOS from right to left. */
7009 || (prev_pos
> to_charpos
7010 && IT_CHARPOS (*it
) < to_charpos
)))))
7012 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7014 result
= MOVE_POS_MATCH_OR_ZV
;
7017 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7018 /* If wrap_it is valid, the current position might be in a
7019 word that is wrapped. So, save the iterator in
7020 atpos_it and continue to see if wrapping happens. */
7024 prev_method
= it
->method
;
7025 if (it
->method
== GET_FROM_BUFFER
)
7026 prev_pos
= IT_CHARPOS (*it
);
7027 /* Stop when ZV reached.
7028 We used to stop here when TO_CHARPOS reached as well, but that is
7029 too soon if this glyph does not fit on this line. So we handle it
7030 explicitly below. */
7031 if (!get_next_display_element (it
))
7033 result
= MOVE_POS_MATCH_OR_ZV
;
7037 if (it
->line_wrap
== TRUNCATE
)
7039 if (BUFFER_POS_REACHED_P ())
7041 result
= MOVE_POS_MATCH_OR_ZV
;
7047 if (it
->line_wrap
== WORD_WRAP
)
7049 if (IT_DISPLAYING_WHITESPACE (it
))
7053 /* We have reached a glyph that follows one or more
7054 whitespace characters. If the position is
7055 already found, we are done. */
7056 if (atpos_it
.sp
>= 0)
7059 result
= MOVE_POS_MATCH_OR_ZV
;
7065 result
= MOVE_X_REACHED
;
7068 /* Otherwise, we can wrap here. */
7075 /* Remember the line height for the current line, in case
7076 the next element doesn't fit on the line. */
7077 ascent
= it
->max_ascent
;
7078 descent
= it
->max_descent
;
7080 /* The call to produce_glyphs will get the metrics of the
7081 display element IT is loaded with. Record the x-position
7082 before this display element, in case it doesn't fit on the
7086 PRODUCE_GLYPHS (it
);
7088 if (it
->area
!= TEXT_AREA
)
7090 set_iterator_to_next (it
, 1);
7094 /* The number of glyphs we get back in IT->nglyphs will normally
7095 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7096 character on a terminal frame, or (iii) a line end. For the
7097 second case, IT->nglyphs - 1 padding glyphs will be present.
7098 (On X frames, there is only one glyph produced for a
7099 composite character.)
7101 The behavior implemented below means, for continuation lines,
7102 that as many spaces of a TAB as fit on the current line are
7103 displayed there. For terminal frames, as many glyphs of a
7104 multi-glyph character are displayed in the current line, too.
7105 This is what the old redisplay code did, and we keep it that
7106 way. Under X, the whole shape of a complex character must
7107 fit on the line or it will be completely displayed in the
7110 Note that both for tabs and padding glyphs, all glyphs have
7114 /* More than one glyph or glyph doesn't fit on line. All
7115 glyphs have the same width. */
7116 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7118 int x_before_this_char
= x
;
7119 int hpos_before_this_char
= it
->hpos
;
7121 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7123 new_x
= x
+ single_glyph_width
;
7125 /* We want to leave anything reaching TO_X to the caller. */
7126 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7128 if (BUFFER_POS_REACHED_P ())
7130 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7131 goto buffer_pos_reached
;
7132 if (atpos_it
.sp
< 0)
7135 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7140 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7143 result
= MOVE_X_REACHED
;
7149 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7154 if (/* Lines are continued. */
7155 it
->line_wrap
!= TRUNCATE
7156 && (/* And glyph doesn't fit on the line. */
7157 new_x
> it
->last_visible_x
7158 /* Or it fits exactly and we're on a window
7160 || (new_x
== it
->last_visible_x
7161 && FRAME_WINDOW_P (it
->f
))))
7163 if (/* IT->hpos == 0 means the very first glyph
7164 doesn't fit on the line, e.g. a wide image. */
7166 || (new_x
== it
->last_visible_x
7167 && FRAME_WINDOW_P (it
->f
)))
7170 it
->current_x
= new_x
;
7172 /* The character's last glyph just barely fits
7174 if (i
== it
->nglyphs
- 1)
7176 /* If this is the destination position,
7177 return a position *before* it in this row,
7178 now that we know it fits in this row. */
7179 if (BUFFER_POS_REACHED_P ())
7181 if (it
->line_wrap
!= WORD_WRAP
7184 it
->hpos
= hpos_before_this_char
;
7185 it
->current_x
= x_before_this_char
;
7186 result
= MOVE_POS_MATCH_OR_ZV
;
7189 if (it
->line_wrap
== WORD_WRAP
7193 atpos_it
.current_x
= x_before_this_char
;
7194 atpos_it
.hpos
= hpos_before_this_char
;
7198 set_iterator_to_next (it
, 1);
7199 /* On graphical terminals, newlines may
7200 "overflow" into the fringe if
7201 overflow-newline-into-fringe is non-nil.
7202 On text-only terminals, newlines may
7203 overflow into the last glyph on the
7205 if (!FRAME_WINDOW_P (it
->f
)
7206 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7208 if (!get_next_display_element (it
))
7210 result
= MOVE_POS_MATCH_OR_ZV
;
7213 if (BUFFER_POS_REACHED_P ())
7215 if (ITERATOR_AT_END_OF_LINE_P (it
))
7216 result
= MOVE_POS_MATCH_OR_ZV
;
7218 result
= MOVE_LINE_CONTINUED
;
7221 if (ITERATOR_AT_END_OF_LINE_P (it
))
7223 result
= MOVE_NEWLINE_OR_CR
;
7230 IT_RESET_X_ASCENT_DESCENT (it
);
7232 if (wrap_it
.sp
>= 0)
7239 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7241 result
= MOVE_LINE_CONTINUED
;
7245 if (BUFFER_POS_REACHED_P ())
7247 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7248 goto buffer_pos_reached
;
7249 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7252 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7256 if (new_x
> it
->first_visible_x
)
7258 /* Glyph is visible. Increment number of glyphs that
7259 would be displayed. */
7264 if (result
!= MOVE_UNDEFINED
)
7267 else if (BUFFER_POS_REACHED_P ())
7270 IT_RESET_X_ASCENT_DESCENT (it
);
7271 result
= MOVE_POS_MATCH_OR_ZV
;
7274 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7276 /* Stop when TO_X specified and reached. This check is
7277 necessary here because of lines consisting of a line end,
7278 only. The line end will not produce any glyphs and we
7279 would never get MOVE_X_REACHED. */
7280 xassert (it
->nglyphs
== 0);
7281 result
= MOVE_X_REACHED
;
7285 /* Is this a line end? If yes, we're done. */
7286 if (ITERATOR_AT_END_OF_LINE_P (it
))
7288 result
= MOVE_NEWLINE_OR_CR
;
7292 if (it
->method
== GET_FROM_BUFFER
)
7293 prev_pos
= IT_CHARPOS (*it
);
7294 /* The current display element has been consumed. Advance
7296 set_iterator_to_next (it
, 1);
7298 /* Stop if lines are truncated and IT's current x-position is
7299 past the right edge of the window now. */
7300 if (it
->line_wrap
== TRUNCATE
7301 && it
->current_x
>= it
->last_visible_x
)
7303 if (!FRAME_WINDOW_P (it
->f
)
7304 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7306 if (!get_next_display_element (it
)
7307 || BUFFER_POS_REACHED_P ())
7309 result
= MOVE_POS_MATCH_OR_ZV
;
7312 if (ITERATOR_AT_END_OF_LINE_P (it
))
7314 result
= MOVE_NEWLINE_OR_CR
;
7318 result
= MOVE_LINE_TRUNCATED
;
7321 #undef IT_RESET_X_ASCENT_DESCENT
7324 #undef BUFFER_POS_REACHED_P
7326 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7327 restore the saved iterator. */
7328 if (atpos_it
.sp
>= 0)
7330 else if (atx_it
.sp
>= 0)
7335 /* Restore the iterator settings altered at the beginning of this
7337 it
->glyph_row
= saved_glyph_row
;
7341 /* For external use. */
7343 move_it_in_display_line (struct it
*it
,
7344 EMACS_INT to_charpos
, int to_x
,
7345 enum move_operation_enum op
)
7347 if (it
->line_wrap
== WORD_WRAP
7348 && (op
& MOVE_TO_X
))
7350 struct it save_it
= *it
;
7351 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7352 /* When word-wrap is on, TO_X may lie past the end
7353 of a wrapped line. Then it->current is the
7354 character on the next line, so backtrack to the
7355 space before the wrap point. */
7356 if (skip
== MOVE_LINE_CONTINUED
)
7358 int prev_x
= max (it
->current_x
- 1, 0);
7360 move_it_in_display_line_to
7361 (it
, -1, prev_x
, MOVE_TO_X
);
7365 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7369 /* Move IT forward until it satisfies one or more of the criteria in
7370 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7372 OP is a bit-mask that specifies where to stop, and in particular,
7373 which of those four position arguments makes a difference. See the
7374 description of enum move_operation_enum.
7376 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7377 screen line, this function will set IT to the next position >
7381 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7383 int to_charpos
, to_x
, to_y
, to_vpos
;
7386 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7387 int line_height
, line_start_x
= 0, reached
= 0;
7391 if (op
& MOVE_TO_VPOS
)
7393 /* If no TO_CHARPOS and no TO_X specified, stop at the
7394 start of the line TO_VPOS. */
7395 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7397 if (it
->vpos
== to_vpos
)
7403 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7407 /* TO_VPOS >= 0 means stop at TO_X in the line at
7408 TO_VPOS, or at TO_POS, whichever comes first. */
7409 if (it
->vpos
== to_vpos
)
7415 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7417 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7422 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7424 /* We have reached TO_X but not in the line we want. */
7425 skip
= move_it_in_display_line_to (it
, to_charpos
,
7427 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7435 else if (op
& MOVE_TO_Y
)
7437 struct it it_backup
;
7439 if (it
->line_wrap
== WORD_WRAP
)
7442 /* TO_Y specified means stop at TO_X in the line containing
7443 TO_Y---or at TO_CHARPOS if this is reached first. The
7444 problem is that we can't really tell whether the line
7445 contains TO_Y before we have completely scanned it, and
7446 this may skip past TO_X. What we do is to first scan to
7449 If TO_X is not specified, use a TO_X of zero. The reason
7450 is to make the outcome of this function more predictable.
7451 If we didn't use TO_X == 0, we would stop at the end of
7452 the line which is probably not what a caller would expect
7454 skip
= move_it_in_display_line_to
7455 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7456 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7458 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7459 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7461 else if (skip
== MOVE_X_REACHED
)
7463 /* If TO_X was reached, we want to know whether TO_Y is
7464 in the line. We know this is the case if the already
7465 scanned glyphs make the line tall enough. Otherwise,
7466 we must check by scanning the rest of the line. */
7467 line_height
= it
->max_ascent
+ it
->max_descent
;
7468 if (to_y
>= it
->current_y
7469 && to_y
< it
->current_y
+ line_height
)
7475 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7476 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7478 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7479 line_height
= it
->max_ascent
+ it
->max_descent
;
7480 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7482 if (to_y
>= it
->current_y
7483 && to_y
< it
->current_y
+ line_height
)
7485 /* If TO_Y is in this line and TO_X was reached
7486 above, we scanned too far. We have to restore
7487 IT's settings to the ones before skipping. */
7494 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7500 /* Check whether TO_Y is in this line. */
7501 line_height
= it
->max_ascent
+ it
->max_descent
;
7502 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7504 if (to_y
>= it
->current_y
7505 && to_y
< it
->current_y
+ line_height
)
7507 /* When word-wrap is on, TO_X may lie past the end
7508 of a wrapped line. Then it->current is the
7509 character on the next line, so backtrack to the
7510 space before the wrap point. */
7511 if (skip
== MOVE_LINE_CONTINUED
7512 && it
->line_wrap
== WORD_WRAP
)
7514 int prev_x
= max (it
->current_x
- 1, 0);
7516 skip
= move_it_in_display_line_to
7517 (it
, -1, prev_x
, MOVE_TO_X
);
7526 else if (BUFFERP (it
->object
)
7527 && (it
->method
== GET_FROM_BUFFER
7528 || it
->method
== GET_FROM_STRETCH
)
7529 && IT_CHARPOS (*it
) >= to_charpos
)
7530 skip
= MOVE_POS_MATCH_OR_ZV
;
7532 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7536 case MOVE_POS_MATCH_OR_ZV
:
7540 case MOVE_NEWLINE_OR_CR
:
7541 set_iterator_to_next (it
, 1);
7542 it
->continuation_lines_width
= 0;
7545 case MOVE_LINE_TRUNCATED
:
7546 it
->continuation_lines_width
= 0;
7547 reseat_at_next_visible_line_start (it
, 0);
7548 if ((op
& MOVE_TO_POS
) != 0
7549 && IT_CHARPOS (*it
) > to_charpos
)
7556 case MOVE_LINE_CONTINUED
:
7557 /* For continued lines ending in a tab, some of the glyphs
7558 associated with the tab are displayed on the current
7559 line. Since it->current_x does not include these glyphs,
7560 we use it->last_visible_x instead. */
7563 it
->continuation_lines_width
+= it
->last_visible_x
;
7564 /* When moving by vpos, ensure that the iterator really
7565 advances to the next line (bug#847, bug#969). Fixme:
7566 do we need to do this in other circumstances? */
7567 if (it
->current_x
!= it
->last_visible_x
7568 && (op
& MOVE_TO_VPOS
)
7569 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7571 line_start_x
= it
->current_x
+ it
->pixel_width
7572 - it
->last_visible_x
;
7573 set_iterator_to_next (it
, 0);
7577 it
->continuation_lines_width
+= it
->current_x
;
7584 /* Reset/increment for the next run. */
7585 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7586 it
->current_x
= line_start_x
;
7589 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7591 last_height
= it
->max_ascent
+ it
->max_descent
;
7592 last_max_ascent
= it
->max_ascent
;
7593 it
->max_ascent
= it
->max_descent
= 0;
7598 /* On text terminals, we may stop at the end of a line in the middle
7599 of a multi-character glyph. If the glyph itself is continued,
7600 i.e. it is actually displayed on the next line, don't treat this
7601 stopping point as valid; move to the next line instead (unless
7602 that brings us offscreen). */
7603 if (!FRAME_WINDOW_P (it
->f
)
7605 && IT_CHARPOS (*it
) == to_charpos
7606 && it
->what
== IT_CHARACTER
7608 && it
->line_wrap
== WINDOW_WRAP
7609 && it
->current_x
== it
->last_visible_x
- 1
7612 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7614 it
->continuation_lines_width
+= it
->current_x
;
7615 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7616 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7618 last_height
= it
->max_ascent
+ it
->max_descent
;
7619 last_max_ascent
= it
->max_ascent
;
7622 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7626 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7628 If DY > 0, move IT backward at least that many pixels. DY = 0
7629 means move IT backward to the preceding line start or BEGV. This
7630 function may move over more than DY pixels if IT->current_y - DY
7631 ends up in the middle of a line; in this case IT->current_y will be
7632 set to the top of the line moved to. */
7635 move_it_vertically_backward (it
, dy
)
7646 start_pos
= IT_CHARPOS (*it
);
7648 /* Estimate how many newlines we must move back. */
7649 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7651 /* Set the iterator's position that many lines back. */
7652 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7653 back_to_previous_visible_line_start (it
);
7655 /* Reseat the iterator here. When moving backward, we don't want
7656 reseat to skip forward over invisible text, set up the iterator
7657 to deliver from overlay strings at the new position etc. So,
7658 use reseat_1 here. */
7659 reseat_1 (it
, it
->current
.pos
, 1);
7661 /* We are now surely at a line start. */
7662 it
->current_x
= it
->hpos
= 0;
7663 it
->continuation_lines_width
= 0;
7665 /* Move forward and see what y-distance we moved. First move to the
7666 start of the next line so that we get its height. We need this
7667 height to be able to tell whether we reached the specified
7670 it2
.max_ascent
= it2
.max_descent
= 0;
7673 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7674 MOVE_TO_POS
| MOVE_TO_VPOS
);
7676 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7677 xassert (IT_CHARPOS (*it
) >= BEGV
);
7680 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7681 xassert (IT_CHARPOS (*it
) >= BEGV
);
7682 /* H is the actual vertical distance from the position in *IT
7683 and the starting position. */
7684 h
= it2
.current_y
- it
->current_y
;
7685 /* NLINES is the distance in number of lines. */
7686 nlines
= it2
.vpos
- it
->vpos
;
7688 /* Correct IT's y and vpos position
7689 so that they are relative to the starting point. */
7695 /* DY == 0 means move to the start of the screen line. The
7696 value of nlines is > 0 if continuation lines were involved. */
7698 move_it_by_lines (it
, nlines
, 1);
7702 /* The y-position we try to reach, relative to *IT.
7703 Note that H has been subtracted in front of the if-statement. */
7704 int target_y
= it
->current_y
+ h
- dy
;
7705 int y0
= it3
.current_y
;
7706 int y1
= line_bottom_y (&it3
);
7707 int line_height
= y1
- y0
;
7709 /* If we did not reach target_y, try to move further backward if
7710 we can. If we moved too far backward, try to move forward. */
7711 if (target_y
< it
->current_y
7712 /* This is heuristic. In a window that's 3 lines high, with
7713 a line height of 13 pixels each, recentering with point
7714 on the bottom line will try to move -39/2 = 19 pixels
7715 backward. Try to avoid moving into the first line. */
7716 && (it
->current_y
- target_y
7717 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7718 && IT_CHARPOS (*it
) > BEGV
)
7720 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7721 target_y
- it
->current_y
));
7722 dy
= it
->current_y
- target_y
;
7723 goto move_further_back
;
7725 else if (target_y
>= it
->current_y
+ line_height
7726 && IT_CHARPOS (*it
) < ZV
)
7728 /* Should move forward by at least one line, maybe more.
7730 Note: Calling move_it_by_lines can be expensive on
7731 terminal frames, where compute_motion is used (via
7732 vmotion) to do the job, when there are very long lines
7733 and truncate-lines is nil. That's the reason for
7734 treating terminal frames specially here. */
7736 if (!FRAME_WINDOW_P (it
->f
))
7737 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7742 move_it_by_lines (it
, 1, 1);
7744 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7751 /* Move IT by a specified amount of pixel lines DY. DY negative means
7752 move backwards. DY = 0 means move to start of screen line. At the
7753 end, IT will be on the start of a screen line. */
7756 move_it_vertically (it
, dy
)
7761 move_it_vertically_backward (it
, -dy
);
7764 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7765 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7766 MOVE_TO_POS
| MOVE_TO_Y
);
7767 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7769 /* If buffer ends in ZV without a newline, move to the start of
7770 the line to satisfy the post-condition. */
7771 if (IT_CHARPOS (*it
) == ZV
7773 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7774 move_it_by_lines (it
, 0, 0);
7779 /* Move iterator IT past the end of the text line it is in. */
7782 move_it_past_eol (it
)
7785 enum move_it_result rc
;
7787 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7788 if (rc
== MOVE_NEWLINE_OR_CR
)
7789 set_iterator_to_next (it
, 0);
7793 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7794 negative means move up. DVPOS == 0 means move to the start of the
7795 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7796 NEED_Y_P is zero, IT->current_y will be left unchanged.
7798 Further optimization ideas: If we would know that IT->f doesn't use
7799 a face with proportional font, we could be faster for
7800 truncate-lines nil. */
7803 move_it_by_lines (it
, dvpos
, need_y_p
)
7805 int dvpos
, need_y_p
;
7807 struct position pos
;
7809 /* The commented-out optimization uses vmotion on terminals. This
7810 gives bad results, because elements like it->what, on which
7811 callers such as pos_visible_p rely, aren't updated. */
7812 /* if (!FRAME_WINDOW_P (it->f))
7814 struct text_pos textpos;
7816 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7817 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7818 reseat (it, textpos, 1);
7819 it->vpos += pos.vpos;
7820 it->current_y += pos.vpos;
7826 /* DVPOS == 0 means move to the start of the screen line. */
7827 move_it_vertically_backward (it
, 0);
7828 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7829 /* Let next call to line_bottom_y calculate real line height */
7834 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7835 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7836 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7841 int start_charpos
, i
;
7843 /* Start at the beginning of the screen line containing IT's
7844 position. This may actually move vertically backwards,
7845 in case of overlays, so adjust dvpos accordingly. */
7847 move_it_vertically_backward (it
, 0);
7850 /* Go back -DVPOS visible lines and reseat the iterator there. */
7851 start_charpos
= IT_CHARPOS (*it
);
7852 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7853 back_to_previous_visible_line_start (it
);
7854 reseat (it
, it
->current
.pos
, 1);
7856 /* Move further back if we end up in a string or an image. */
7857 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7859 /* First try to move to start of display line. */
7861 move_it_vertically_backward (it
, 0);
7863 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7865 /* If start of line is still in string or image,
7866 move further back. */
7867 back_to_previous_visible_line_start (it
);
7868 reseat (it
, it
->current
.pos
, 1);
7872 it
->current_x
= it
->hpos
= 0;
7874 /* Above call may have moved too far if continuation lines
7875 are involved. Scan forward and see if it did. */
7877 it2
.vpos
= it2
.current_y
= 0;
7878 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7879 it
->vpos
-= it2
.vpos
;
7880 it
->current_y
-= it2
.current_y
;
7881 it
->current_x
= it
->hpos
= 0;
7883 /* If we moved too far back, move IT some lines forward. */
7884 if (it2
.vpos
> -dvpos
)
7886 int delta
= it2
.vpos
+ dvpos
;
7888 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7889 /* Move back again if we got too far ahead. */
7890 if (IT_CHARPOS (*it
) >= start_charpos
)
7896 /* Return 1 if IT points into the middle of a display vector. */
7899 in_display_vector_p (it
)
7902 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7903 && it
->current
.dpvec_index
> 0
7904 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7908 /***********************************************************************
7910 ***********************************************************************/
7913 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7917 add_to_log (format
, arg1
, arg2
)
7919 Lisp_Object arg1
, arg2
;
7921 Lisp_Object args
[3];
7922 Lisp_Object msg
, fmt
;
7925 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7928 /* Do nothing if called asynchronously. Inserting text into
7929 a buffer may call after-change-functions and alike and
7930 that would means running Lisp asynchronously. */
7931 if (handling_signal
)
7935 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7937 args
[0] = fmt
= build_string (format
);
7940 msg
= Fformat (3, args
);
7942 len
= SBYTES (msg
) + 1;
7943 SAFE_ALLOCA (buffer
, char *, len
);
7944 bcopy (SDATA (msg
), buffer
, len
);
7946 message_dolog (buffer
, len
- 1, 1, 0);
7953 /* Output a newline in the *Messages* buffer if "needs" one. */
7956 message_log_maybe_newline ()
7958 if (message_log_need_newline
)
7959 message_dolog ("", 0, 1, 0);
7963 /* Add a string M of length NBYTES to the message log, optionally
7964 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7965 nonzero, means interpret the contents of M as multibyte. This
7966 function calls low-level routines in order to bypass text property
7967 hooks, etc. which might not be safe to run.
7969 This may GC (insert may run before/after change hooks),
7970 so the buffer M must NOT point to a Lisp string. */
7973 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7975 int nbytes
, nlflag
, multibyte
;
7977 if (!NILP (Vmemory_full
))
7980 if (!NILP (Vmessage_log_max
))
7982 struct buffer
*oldbuf
;
7983 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7984 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7985 int point_at_end
= 0;
7987 Lisp_Object old_deactivate_mark
, tem
;
7988 struct gcpro gcpro1
;
7990 old_deactivate_mark
= Vdeactivate_mark
;
7991 oldbuf
= current_buffer
;
7992 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7993 current_buffer
->undo_list
= Qt
;
7995 oldpoint
= message_dolog_marker1
;
7996 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7997 oldbegv
= message_dolog_marker2
;
7998 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7999 oldzv
= message_dolog_marker3
;
8000 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8001 GCPRO1 (old_deactivate_mark
);
8009 BEGV_BYTE
= BEG_BYTE
;
8012 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8014 /* Insert the string--maybe converting multibyte to single byte
8015 or vice versa, so that all the text fits the buffer. */
8017 && NILP (current_buffer
->enable_multibyte_characters
))
8019 int i
, c
, char_bytes
;
8020 unsigned char work
[1];
8022 /* Convert a multibyte string to single-byte
8023 for the *Message* buffer. */
8024 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8026 c
= string_char_and_length (m
+ i
, &char_bytes
);
8027 work
[0] = (ASCII_CHAR_P (c
)
8029 : multibyte_char_to_unibyte (c
, Qnil
));
8030 insert_1_both (work
, 1, 1, 1, 0, 0);
8033 else if (! multibyte
8034 && ! NILP (current_buffer
->enable_multibyte_characters
))
8036 int i
, c
, char_bytes
;
8037 unsigned char *msg
= (unsigned char *) m
;
8038 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8039 /* Convert a single-byte string to multibyte
8040 for the *Message* buffer. */
8041 for (i
= 0; i
< nbytes
; i
++)
8044 MAKE_CHAR_MULTIBYTE (c
);
8045 char_bytes
= CHAR_STRING (c
, str
);
8046 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
8050 insert_1 (m
, nbytes
, 1, 0, 0);
8054 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
8055 insert_1 ("\n", 1, 1, 0, 0);
8057 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8059 this_bol_byte
= PT_BYTE
;
8061 /* See if this line duplicates the previous one.
8062 If so, combine duplicates. */
8065 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8067 prev_bol_byte
= PT_BYTE
;
8069 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
8070 this_bol
, this_bol_byte
);
8073 del_range_both (prev_bol
, prev_bol_byte
,
8074 this_bol
, this_bol_byte
, 0);
8080 /* If you change this format, don't forget to also
8081 change message_log_check_duplicate. */
8082 sprintf (dupstr
, " [%d times]", dup
);
8083 duplen
= strlen (dupstr
);
8084 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8085 insert_1 (dupstr
, duplen
, 1, 0, 1);
8090 /* If we have more than the desired maximum number of lines
8091 in the *Messages* buffer now, delete the oldest ones.
8092 This is safe because we don't have undo in this buffer. */
8094 if (NATNUMP (Vmessage_log_max
))
8096 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8097 -XFASTINT (Vmessage_log_max
) - 1, 0);
8098 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8101 BEGV
= XMARKER (oldbegv
)->charpos
;
8102 BEGV_BYTE
= marker_byte_position (oldbegv
);
8111 ZV
= XMARKER (oldzv
)->charpos
;
8112 ZV_BYTE
= marker_byte_position (oldzv
);
8116 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8118 /* We can't do Fgoto_char (oldpoint) because it will run some
8120 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8121 XMARKER (oldpoint
)->bytepos
);
8124 unchain_marker (XMARKER (oldpoint
));
8125 unchain_marker (XMARKER (oldbegv
));
8126 unchain_marker (XMARKER (oldzv
));
8128 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8129 set_buffer_internal (oldbuf
);
8131 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8132 message_log_need_newline
= !nlflag
;
8133 Vdeactivate_mark
= old_deactivate_mark
;
8138 /* We are at the end of the buffer after just having inserted a newline.
8139 (Note: We depend on the fact we won't be crossing the gap.)
8140 Check to see if the most recent message looks a lot like the previous one.
8141 Return 0 if different, 1 if the new one should just replace it, or a
8142 value N > 1 if we should also append " [N times]". */
8145 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
8146 int prev_bol
, this_bol
;
8147 int prev_bol_byte
, this_bol_byte
;
8150 int len
= Z_BYTE
- 1 - this_bol_byte
;
8152 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8153 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8155 for (i
= 0; i
< len
; i
++)
8157 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8165 if (*p1
++ == ' ' && *p1
++ == '[')
8168 while (*p1
>= '0' && *p1
<= '9')
8169 n
= n
* 10 + *p1
++ - '0';
8170 if (strncmp (p1
, " times]\n", 8) == 0)
8177 /* Display an echo area message M with a specified length of NBYTES
8178 bytes. The string may include null characters. If M is 0, clear
8179 out any existing message, and let the mini-buffer text show
8182 This may GC, so the buffer M must NOT point to a Lisp string. */
8185 message2 (m
, nbytes
, multibyte
)
8190 /* First flush out any partial line written with print. */
8191 message_log_maybe_newline ();
8193 message_dolog (m
, nbytes
, 1, multibyte
);
8194 message2_nolog (m
, nbytes
, multibyte
);
8198 /* The non-logging counterpart of message2. */
8201 message2_nolog (m
, nbytes
, multibyte
)
8203 int nbytes
, multibyte
;
8205 struct frame
*sf
= SELECTED_FRAME ();
8206 message_enable_multibyte
= multibyte
;
8208 if (FRAME_INITIAL_P (sf
))
8210 if (noninteractive_need_newline
)
8211 putc ('\n', stderr
);
8212 noninteractive_need_newline
= 0;
8214 fwrite (m
, nbytes
, 1, stderr
);
8215 if (cursor_in_echo_area
== 0)
8216 fprintf (stderr
, "\n");
8219 /* A null message buffer means that the frame hasn't really been
8220 initialized yet. Error messages get reported properly by
8221 cmd_error, so this must be just an informative message; toss it. */
8222 else if (INTERACTIVE
8223 && sf
->glyphs_initialized_p
8224 && FRAME_MESSAGE_BUF (sf
))
8226 Lisp_Object mini_window
;
8229 /* Get the frame containing the mini-buffer
8230 that the selected frame is using. */
8231 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8232 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8234 FRAME_SAMPLE_VISIBILITY (f
);
8235 if (FRAME_VISIBLE_P (sf
)
8236 && ! FRAME_VISIBLE_P (f
))
8237 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8241 set_message (m
, Qnil
, nbytes
, multibyte
);
8242 if (minibuffer_auto_raise
)
8243 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8246 clear_message (1, 1);
8248 do_pending_window_change (0);
8249 echo_area_display (1);
8250 do_pending_window_change (0);
8251 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8252 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8257 /* Display an echo area message M with a specified length of NBYTES
8258 bytes. The string may include null characters. If M is not a
8259 string, clear out any existing message, and let the mini-buffer
8262 This function cancels echoing. */
8265 message3 (m
, nbytes
, multibyte
)
8270 struct gcpro gcpro1
;
8273 clear_message (1,1);
8276 /* First flush out any partial line written with print. */
8277 message_log_maybe_newline ();
8283 SAFE_ALLOCA (buffer
, char *, nbytes
);
8284 bcopy (SDATA (m
), buffer
, nbytes
);
8285 message_dolog (buffer
, nbytes
, 1, multibyte
);
8288 message3_nolog (m
, nbytes
, multibyte
);
8294 /* The non-logging version of message3.
8295 This does not cancel echoing, because it is used for echoing.
8296 Perhaps we need to make a separate function for echoing
8297 and make this cancel echoing. */
8300 message3_nolog (m
, nbytes
, multibyte
)
8302 int nbytes
, multibyte
;
8304 struct frame
*sf
= SELECTED_FRAME ();
8305 message_enable_multibyte
= multibyte
;
8307 if (FRAME_INITIAL_P (sf
))
8309 if (noninteractive_need_newline
)
8310 putc ('\n', stderr
);
8311 noninteractive_need_newline
= 0;
8313 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8314 if (cursor_in_echo_area
== 0)
8315 fprintf (stderr
, "\n");
8318 /* A null message buffer means that the frame hasn't really been
8319 initialized yet. Error messages get reported properly by
8320 cmd_error, so this must be just an informative message; toss it. */
8321 else if (INTERACTIVE
8322 && sf
->glyphs_initialized_p
8323 && FRAME_MESSAGE_BUF (sf
))
8325 Lisp_Object mini_window
;
8329 /* Get the frame containing the mini-buffer
8330 that the selected frame is using. */
8331 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8332 frame
= XWINDOW (mini_window
)->frame
;
8335 FRAME_SAMPLE_VISIBILITY (f
);
8336 if (FRAME_VISIBLE_P (sf
)
8337 && !FRAME_VISIBLE_P (f
))
8338 Fmake_frame_visible (frame
);
8340 if (STRINGP (m
) && SCHARS (m
) > 0)
8342 set_message (NULL
, m
, nbytes
, multibyte
);
8343 if (minibuffer_auto_raise
)
8344 Fraise_frame (frame
);
8345 /* Assume we are not echoing.
8346 (If we are, echo_now will override this.) */
8347 echo_message_buffer
= Qnil
;
8350 clear_message (1, 1);
8352 do_pending_window_change (0);
8353 echo_area_display (1);
8354 do_pending_window_change (0);
8355 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8356 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8361 /* Display a null-terminated echo area message M. If M is 0, clear
8362 out any existing message, and let the mini-buffer text show through.
8364 The buffer M must continue to exist until after the echo area gets
8365 cleared or some other message gets displayed there. Do not pass
8366 text that is stored in a Lisp string. Do not pass text in a buffer
8367 that was alloca'd. */
8373 message2 (m
, (m
? strlen (m
) : 0), 0);
8377 /* The non-logging counterpart of message1. */
8383 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8386 /* Display a message M which contains a single %s
8387 which gets replaced with STRING. */
8390 message_with_string (m
, string
, log
)
8395 CHECK_STRING (string
);
8401 if (noninteractive_need_newline
)
8402 putc ('\n', stderr
);
8403 noninteractive_need_newline
= 0;
8404 fprintf (stderr
, m
, SDATA (string
));
8405 if (!cursor_in_echo_area
)
8406 fprintf (stderr
, "\n");
8410 else if (INTERACTIVE
)
8412 /* The frame whose minibuffer we're going to display the message on.
8413 It may be larger than the selected frame, so we need
8414 to use its buffer, not the selected frame's buffer. */
8415 Lisp_Object mini_window
;
8416 struct frame
*f
, *sf
= SELECTED_FRAME ();
8418 /* Get the frame containing the minibuffer
8419 that the selected frame is using. */
8420 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8421 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8423 /* A null message buffer means that the frame hasn't really been
8424 initialized yet. Error messages get reported properly by
8425 cmd_error, so this must be just an informative message; toss it. */
8426 if (FRAME_MESSAGE_BUF (f
))
8428 Lisp_Object args
[2], message
;
8429 struct gcpro gcpro1
, gcpro2
;
8431 args
[0] = build_string (m
);
8432 args
[1] = message
= string
;
8433 GCPRO2 (args
[0], message
);
8436 message
= Fformat (2, args
);
8439 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8441 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8445 /* Print should start at the beginning of the message
8446 buffer next time. */
8447 message_buf_print
= 0;
8453 /* Dump an informative message to the minibuf. If M is 0, clear out
8454 any existing message, and let the mini-buffer text show through. */
8458 message (m
, a1
, a2
, a3
)
8460 EMACS_INT a1
, a2
, a3
;
8466 if (noninteractive_need_newline
)
8467 putc ('\n', stderr
);
8468 noninteractive_need_newline
= 0;
8469 fprintf (stderr
, m
, a1
, a2
, a3
);
8470 if (cursor_in_echo_area
== 0)
8471 fprintf (stderr
, "\n");
8475 else if (INTERACTIVE
)
8477 /* The frame whose mini-buffer we're going to display the message
8478 on. It may be larger than the selected frame, so we need to
8479 use its buffer, not the selected frame's buffer. */
8480 Lisp_Object mini_window
;
8481 struct frame
*f
, *sf
= SELECTED_FRAME ();
8483 /* Get the frame containing the mini-buffer
8484 that the selected frame is using. */
8485 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8486 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8488 /* A null message buffer means that the frame hasn't really been
8489 initialized yet. Error messages get reported properly by
8490 cmd_error, so this must be just an informative message; toss
8492 if (FRAME_MESSAGE_BUF (f
))
8503 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8504 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8506 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8507 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8509 #endif /* NO_ARG_ARRAY */
8511 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8516 /* Print should start at the beginning of the message
8517 buffer next time. */
8518 message_buf_print
= 0;
8524 /* The non-logging version of message. */
8527 message_nolog (m
, a1
, a2
, a3
)
8529 EMACS_INT a1
, a2
, a3
;
8531 Lisp_Object old_log_max
;
8532 old_log_max
= Vmessage_log_max
;
8533 Vmessage_log_max
= Qnil
;
8534 message (m
, a1
, a2
, a3
);
8535 Vmessage_log_max
= old_log_max
;
8539 /* Display the current message in the current mini-buffer. This is
8540 only called from error handlers in process.c, and is not time
8546 if (!NILP (echo_area_buffer
[0]))
8549 string
= Fcurrent_message ();
8550 message3 (string
, SBYTES (string
),
8551 !NILP (current_buffer
->enable_multibyte_characters
));
8556 /* Make sure echo area buffers in `echo_buffers' are live.
8557 If they aren't, make new ones. */
8560 ensure_echo_area_buffers ()
8564 for (i
= 0; i
< 2; ++i
)
8565 if (!BUFFERP (echo_buffer
[i
])
8566 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8569 Lisp_Object old_buffer
;
8572 old_buffer
= echo_buffer
[i
];
8573 sprintf (name
, " *Echo Area %d*", i
);
8574 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8575 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8576 /* to force word wrap in echo area -
8577 it was decided to postpone this*/
8578 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8580 for (j
= 0; j
< 2; ++j
)
8581 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8582 echo_area_buffer
[j
] = echo_buffer
[i
];
8587 /* Call FN with args A1..A4 with either the current or last displayed
8588 echo_area_buffer as current buffer.
8590 WHICH zero means use the current message buffer
8591 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8592 from echo_buffer[] and clear it.
8594 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8595 suitable buffer from echo_buffer[] and clear it.
8597 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8598 that the current message becomes the last displayed one, make
8599 choose a suitable buffer for echo_area_buffer[0], and clear it.
8601 Value is what FN returns. */
8604 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8607 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8613 int this_one
, the_other
, clear_buffer_p
, rc
;
8614 int count
= SPECPDL_INDEX ();
8616 /* If buffers aren't live, make new ones. */
8617 ensure_echo_area_buffers ();
8622 this_one
= 0, the_other
= 1;
8624 this_one
= 1, the_other
= 0;
8627 this_one
= 0, the_other
= 1;
8630 /* We need a fresh one in case the current echo buffer equals
8631 the one containing the last displayed echo area message. */
8632 if (!NILP (echo_area_buffer
[this_one
])
8633 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8634 echo_area_buffer
[this_one
] = Qnil
;
8637 /* Choose a suitable buffer from echo_buffer[] is we don't
8639 if (NILP (echo_area_buffer
[this_one
]))
8641 echo_area_buffer
[this_one
]
8642 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8643 ? echo_buffer
[the_other
]
8644 : echo_buffer
[this_one
]);
8648 buffer
= echo_area_buffer
[this_one
];
8650 /* Don't get confused by reusing the buffer used for echoing
8651 for a different purpose. */
8652 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8655 record_unwind_protect (unwind_with_echo_area_buffer
,
8656 with_echo_area_buffer_unwind_data (w
));
8658 /* Make the echo area buffer current. Note that for display
8659 purposes, it is not necessary that the displayed window's buffer
8660 == current_buffer, except for text property lookup. So, let's
8661 only set that buffer temporarily here without doing a full
8662 Fset_window_buffer. We must also change w->pointm, though,
8663 because otherwise an assertions in unshow_buffer fails, and Emacs
8665 set_buffer_internal_1 (XBUFFER (buffer
));
8669 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8672 current_buffer
->undo_list
= Qt
;
8673 current_buffer
->read_only
= Qnil
;
8674 specbind (Qinhibit_read_only
, Qt
);
8675 specbind (Qinhibit_modification_hooks
, Qt
);
8677 if (clear_buffer_p
&& Z
> BEG
)
8680 xassert (BEGV
>= BEG
);
8681 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8683 rc
= fn (a1
, a2
, a3
, a4
);
8685 xassert (BEGV
>= BEG
);
8686 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8688 unbind_to (count
, Qnil
);
8693 /* Save state that should be preserved around the call to the function
8694 FN called in with_echo_area_buffer. */
8697 with_echo_area_buffer_unwind_data (w
)
8701 Lisp_Object vector
, tmp
;
8703 /* Reduce consing by keeping one vector in
8704 Vwith_echo_area_save_vector. */
8705 vector
= Vwith_echo_area_save_vector
;
8706 Vwith_echo_area_save_vector
= Qnil
;
8709 vector
= Fmake_vector (make_number (7), Qnil
);
8711 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8712 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8713 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8717 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8718 ASET (vector
, i
, w
->buffer
); ++i
;
8719 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8720 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8725 for (; i
< end
; ++i
)
8726 ASET (vector
, i
, Qnil
);
8729 xassert (i
== ASIZE (vector
));
8734 /* Restore global state from VECTOR which was created by
8735 with_echo_area_buffer_unwind_data. */
8738 unwind_with_echo_area_buffer (vector
)
8741 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8742 Vdeactivate_mark
= AREF (vector
, 1);
8743 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8745 if (WINDOWP (AREF (vector
, 3)))
8748 Lisp_Object buffer
, charpos
, bytepos
;
8750 w
= XWINDOW (AREF (vector
, 3));
8751 buffer
= AREF (vector
, 4);
8752 charpos
= AREF (vector
, 5);
8753 bytepos
= AREF (vector
, 6);
8756 set_marker_both (w
->pointm
, buffer
,
8757 XFASTINT (charpos
), XFASTINT (bytepos
));
8760 Vwith_echo_area_save_vector
= vector
;
8765 /* Set up the echo area for use by print functions. MULTIBYTE_P
8766 non-zero means we will print multibyte. */
8769 setup_echo_area_for_printing (multibyte_p
)
8772 /* If we can't find an echo area any more, exit. */
8773 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8776 ensure_echo_area_buffers ();
8778 if (!message_buf_print
)
8780 /* A message has been output since the last time we printed.
8781 Choose a fresh echo area buffer. */
8782 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8783 echo_area_buffer
[0] = echo_buffer
[1];
8785 echo_area_buffer
[0] = echo_buffer
[0];
8787 /* Switch to that buffer and clear it. */
8788 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8789 current_buffer
->truncate_lines
= Qnil
;
8793 int count
= SPECPDL_INDEX ();
8794 specbind (Qinhibit_read_only
, Qt
);
8795 /* Note that undo recording is always disabled. */
8797 unbind_to (count
, Qnil
);
8799 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8801 /* Set up the buffer for the multibyteness we need. */
8803 != !NILP (current_buffer
->enable_multibyte_characters
))
8804 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8806 /* Raise the frame containing the echo area. */
8807 if (minibuffer_auto_raise
)
8809 struct frame
*sf
= SELECTED_FRAME ();
8810 Lisp_Object mini_window
;
8811 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8812 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8815 message_log_maybe_newline ();
8816 message_buf_print
= 1;
8820 if (NILP (echo_area_buffer
[0]))
8822 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8823 echo_area_buffer
[0] = echo_buffer
[1];
8825 echo_area_buffer
[0] = echo_buffer
[0];
8828 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8830 /* Someone switched buffers between print requests. */
8831 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8832 current_buffer
->truncate_lines
= Qnil
;
8838 /* Display an echo area message in window W. Value is non-zero if W's
8839 height is changed. If display_last_displayed_message_p is
8840 non-zero, display the message that was last displayed, otherwise
8841 display the current message. */
8844 display_echo_area (w
)
8847 int i
, no_message_p
, window_height_changed_p
, count
;
8849 /* Temporarily disable garbage collections while displaying the echo
8850 area. This is done because a GC can print a message itself.
8851 That message would modify the echo area buffer's contents while a
8852 redisplay of the buffer is going on, and seriously confuse
8854 count
= inhibit_garbage_collection ();
8856 /* If there is no message, we must call display_echo_area_1
8857 nevertheless because it resizes the window. But we will have to
8858 reset the echo_area_buffer in question to nil at the end because
8859 with_echo_area_buffer will sets it to an empty buffer. */
8860 i
= display_last_displayed_message_p
? 1 : 0;
8861 no_message_p
= NILP (echo_area_buffer
[i
]);
8863 window_height_changed_p
8864 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8865 display_echo_area_1
,
8866 (EMACS_INT
) w
, Qnil
, 0, 0);
8869 echo_area_buffer
[i
] = Qnil
;
8871 unbind_to (count
, Qnil
);
8872 return window_height_changed_p
;
8876 /* Helper for display_echo_area. Display the current buffer which
8877 contains the current echo area message in window W, a mini-window,
8878 a pointer to which is passed in A1. A2..A4 are currently not used.
8879 Change the height of W so that all of the message is displayed.
8880 Value is non-zero if height of W was changed. */
8883 display_echo_area_1 (a1
, a2
, a3
, a4
)
8888 struct window
*w
= (struct window
*) a1
;
8890 struct text_pos start
;
8891 int window_height_changed_p
= 0;
8893 /* Do this before displaying, so that we have a large enough glyph
8894 matrix for the display. If we can't get enough space for the
8895 whole text, display the last N lines. That works by setting w->start. */
8896 window_height_changed_p
= resize_mini_window (w
, 0);
8898 /* Use the starting position chosen by resize_mini_window. */
8899 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8902 clear_glyph_matrix (w
->desired_matrix
);
8903 XSETWINDOW (window
, w
);
8904 try_window (window
, start
, 0);
8906 return window_height_changed_p
;
8910 /* Resize the echo area window to exactly the size needed for the
8911 currently displayed message, if there is one. If a mini-buffer
8912 is active, don't shrink it. */
8915 resize_echo_area_exactly ()
8917 if (BUFFERP (echo_area_buffer
[0])
8918 && WINDOWP (echo_area_window
))
8920 struct window
*w
= XWINDOW (echo_area_window
);
8922 Lisp_Object resize_exactly
;
8924 if (minibuf_level
== 0)
8925 resize_exactly
= Qt
;
8927 resize_exactly
= Qnil
;
8929 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8930 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8933 ++windows_or_buffers_changed
;
8934 ++update_mode_lines
;
8935 redisplay_internal (0);
8941 /* Callback function for with_echo_area_buffer, when used from
8942 resize_echo_area_exactly. A1 contains a pointer to the window to
8943 resize, EXACTLY non-nil means resize the mini-window exactly to the
8944 size of the text displayed. A3 and A4 are not used. Value is what
8945 resize_mini_window returns. */
8948 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8950 Lisp_Object exactly
;
8953 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8957 /* Resize mini-window W to fit the size of its contents. EXACT_P
8958 means size the window exactly to the size needed. Otherwise, it's
8959 only enlarged until W's buffer is empty.
8961 Set W->start to the right place to begin display. If the whole
8962 contents fit, start at the beginning. Otherwise, start so as
8963 to make the end of the contents appear. This is particularly
8964 important for y-or-n-p, but seems desirable generally.
8966 Value is non-zero if the window height has been changed. */
8969 resize_mini_window (w
, exact_p
)
8973 struct frame
*f
= XFRAME (w
->frame
);
8974 int window_height_changed_p
= 0;
8976 xassert (MINI_WINDOW_P (w
));
8978 /* By default, start display at the beginning. */
8979 set_marker_both (w
->start
, w
->buffer
,
8980 BUF_BEGV (XBUFFER (w
->buffer
)),
8981 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8983 /* Don't resize windows while redisplaying a window; it would
8984 confuse redisplay functions when the size of the window they are
8985 displaying changes from under them. Such a resizing can happen,
8986 for instance, when which-func prints a long message while
8987 we are running fontification-functions. We're running these
8988 functions with safe_call which binds inhibit-redisplay to t. */
8989 if (!NILP (Vinhibit_redisplay
))
8992 /* Nil means don't try to resize. */
8993 if (NILP (Vresize_mini_windows
)
8994 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8997 if (!FRAME_MINIBUF_ONLY_P (f
))
9000 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9001 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9002 int height
, max_height
;
9003 int unit
= FRAME_LINE_HEIGHT (f
);
9004 struct text_pos start
;
9005 struct buffer
*old_current_buffer
= NULL
;
9007 if (current_buffer
!= XBUFFER (w
->buffer
))
9009 old_current_buffer
= current_buffer
;
9010 set_buffer_internal (XBUFFER (w
->buffer
));
9013 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9015 /* Compute the max. number of lines specified by the user. */
9016 if (FLOATP (Vmax_mini_window_height
))
9017 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9018 else if (INTEGERP (Vmax_mini_window_height
))
9019 max_height
= XINT (Vmax_mini_window_height
);
9021 max_height
= total_height
/ 4;
9023 /* Correct that max. height if it's bogus. */
9024 max_height
= max (1, max_height
);
9025 max_height
= min (total_height
, max_height
);
9027 /* Find out the height of the text in the window. */
9028 if (it
.line_wrap
== TRUNCATE
)
9033 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9034 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9035 height
= it
.current_y
+ last_height
;
9037 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9038 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9039 height
= (height
+ unit
- 1) / unit
;
9042 /* Compute a suitable window start. */
9043 if (height
> max_height
)
9045 height
= max_height
;
9046 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9047 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9048 start
= it
.current
.pos
;
9051 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9052 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9054 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9056 /* Let it grow only, until we display an empty message, in which
9057 case the window shrinks again. */
9058 if (height
> WINDOW_TOTAL_LINES (w
))
9060 int old_height
= WINDOW_TOTAL_LINES (w
);
9061 freeze_window_starts (f
, 1);
9062 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9063 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9065 else if (height
< WINDOW_TOTAL_LINES (w
)
9066 && (exact_p
|| BEGV
== ZV
))
9068 int old_height
= WINDOW_TOTAL_LINES (w
);
9069 freeze_window_starts (f
, 0);
9070 shrink_mini_window (w
);
9071 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9076 /* Always resize to exact size needed. */
9077 if (height
> WINDOW_TOTAL_LINES (w
))
9079 int old_height
= WINDOW_TOTAL_LINES (w
);
9080 freeze_window_starts (f
, 1);
9081 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9082 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9084 else if (height
< WINDOW_TOTAL_LINES (w
))
9086 int old_height
= WINDOW_TOTAL_LINES (w
);
9087 freeze_window_starts (f
, 0);
9088 shrink_mini_window (w
);
9092 freeze_window_starts (f
, 1);
9093 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9096 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9100 if (old_current_buffer
)
9101 set_buffer_internal (old_current_buffer
);
9104 return window_height_changed_p
;
9108 /* Value is the current message, a string, or nil if there is no
9116 if (!BUFFERP (echo_area_buffer
[0]))
9120 with_echo_area_buffer (0, 0, current_message_1
,
9121 (EMACS_INT
) &msg
, Qnil
, 0, 0);
9123 echo_area_buffer
[0] = Qnil
;
9131 current_message_1 (a1
, a2
, a3
, a4
)
9136 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
9139 *msg
= make_buffer_string (BEG
, Z
, 1);
9146 /* Push the current message on Vmessage_stack for later restauration
9147 by restore_message. Value is non-zero if the current message isn't
9148 empty. This is a relatively infrequent operation, so it's not
9149 worth optimizing. */
9155 msg
= current_message ();
9156 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9157 return STRINGP (msg
);
9161 /* Restore message display from the top of Vmessage_stack. */
9168 xassert (CONSP (Vmessage_stack
));
9169 msg
= XCAR (Vmessage_stack
);
9171 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9173 message3_nolog (msg
, 0, 0);
9177 /* Handler for record_unwind_protect calling pop_message. */
9180 pop_message_unwind (dummy
)
9187 /* Pop the top-most entry off Vmessage_stack. */
9192 xassert (CONSP (Vmessage_stack
));
9193 Vmessage_stack
= XCDR (Vmessage_stack
);
9197 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9198 exits. If the stack is not empty, we have a missing pop_message
9202 check_message_stack ()
9204 if (!NILP (Vmessage_stack
))
9209 /* Truncate to NCHARS what will be displayed in the echo area the next
9210 time we display it---but don't redisplay it now. */
9213 truncate_echo_area (nchars
)
9217 echo_area_buffer
[0] = Qnil
;
9218 /* A null message buffer means that the frame hasn't really been
9219 initialized yet. Error messages get reported properly by
9220 cmd_error, so this must be just an informative message; toss it. */
9221 else if (!noninteractive
9223 && !NILP (echo_area_buffer
[0]))
9225 struct frame
*sf
= SELECTED_FRAME ();
9226 if (FRAME_MESSAGE_BUF (sf
))
9227 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9232 /* Helper function for truncate_echo_area. Truncate the current
9233 message to at most NCHARS characters. */
9236 truncate_message_1 (nchars
, a2
, a3
, a4
)
9241 if (BEG
+ nchars
< Z
)
9242 del_range (BEG
+ nchars
, Z
);
9244 echo_area_buffer
[0] = Qnil
;
9249 /* Set the current message to a substring of S or STRING.
9251 If STRING is a Lisp string, set the message to the first NBYTES
9252 bytes from STRING. NBYTES zero means use the whole string. If
9253 STRING is multibyte, the message will be displayed multibyte.
9255 If S is not null, set the message to the first LEN bytes of S. LEN
9256 zero means use the whole string. MULTIBYTE_P non-zero means S is
9257 multibyte. Display the message multibyte in that case.
9259 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9260 to t before calling set_message_1 (which calls insert).
9264 set_message (s
, string
, nbytes
, multibyte_p
)
9267 int nbytes
, multibyte_p
;
9269 message_enable_multibyte
9270 = ((s
&& multibyte_p
)
9271 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9273 with_echo_area_buffer (0, -1, set_message_1
,
9274 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9275 message_buf_print
= 0;
9276 help_echo_showing_p
= 0;
9280 /* Helper function for set_message. Arguments have the same meaning
9281 as there, with A1 corresponding to S and A2 corresponding to STRING
9282 This function is called with the echo area buffer being
9286 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9289 EMACS_INT nbytes
, multibyte_p
;
9291 const char *s
= (const char *) a1
;
9292 Lisp_Object string
= a2
;
9294 /* Change multibyteness of the echo buffer appropriately. */
9295 if (message_enable_multibyte
9296 != !NILP (current_buffer
->enable_multibyte_characters
))
9297 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9299 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9301 /* Insert new message at BEG. */
9302 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9304 if (STRINGP (string
))
9309 nbytes
= SBYTES (string
);
9310 nchars
= string_byte_to_char (string
, nbytes
);
9312 /* This function takes care of single/multibyte conversion. We
9313 just have to ensure that the echo area buffer has the right
9314 setting of enable_multibyte_characters. */
9315 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9320 nbytes
= strlen (s
);
9322 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9324 /* Convert from multi-byte to single-byte. */
9326 unsigned char work
[1];
9328 /* Convert a multibyte string to single-byte. */
9329 for (i
= 0; i
< nbytes
; i
+= n
)
9331 c
= string_char_and_length (s
+ i
, &n
);
9332 work
[0] = (ASCII_CHAR_P (c
)
9334 : multibyte_char_to_unibyte (c
, Qnil
));
9335 insert_1_both (work
, 1, 1, 1, 0, 0);
9338 else if (!multibyte_p
9339 && !NILP (current_buffer
->enable_multibyte_characters
))
9341 /* Convert from single-byte to multi-byte. */
9343 const unsigned char *msg
= (const unsigned char *) s
;
9344 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9346 /* Convert a single-byte string to multibyte. */
9347 for (i
= 0; i
< nbytes
; i
++)
9350 MAKE_CHAR_MULTIBYTE (c
);
9351 n
= CHAR_STRING (c
, str
);
9352 insert_1_both (str
, 1, n
, 1, 0, 0);
9356 insert_1 (s
, nbytes
, 1, 0, 0);
9363 /* Clear messages. CURRENT_P non-zero means clear the current
9364 message. LAST_DISPLAYED_P non-zero means clear the message
9368 clear_message (current_p
, last_displayed_p
)
9369 int current_p
, last_displayed_p
;
9373 echo_area_buffer
[0] = Qnil
;
9374 message_cleared_p
= 1;
9377 if (last_displayed_p
)
9378 echo_area_buffer
[1] = Qnil
;
9380 message_buf_print
= 0;
9383 /* Clear garbaged frames.
9385 This function is used where the old redisplay called
9386 redraw_garbaged_frames which in turn called redraw_frame which in
9387 turn called clear_frame. The call to clear_frame was a source of
9388 flickering. I believe a clear_frame is not necessary. It should
9389 suffice in the new redisplay to invalidate all current matrices,
9390 and ensure a complete redisplay of all windows. */
9393 clear_garbaged_frames ()
9397 Lisp_Object tail
, frame
;
9398 int changed_count
= 0;
9400 FOR_EACH_FRAME (tail
, frame
)
9402 struct frame
*f
= XFRAME (frame
);
9404 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9408 Fredraw_frame (frame
);
9409 f
->force_flush_display_p
= 1;
9411 clear_current_matrices (f
);
9420 ++windows_or_buffers_changed
;
9425 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9426 is non-zero update selected_frame. Value is non-zero if the
9427 mini-windows height has been changed. */
9430 echo_area_display (update_frame_p
)
9433 Lisp_Object mini_window
;
9436 int window_height_changed_p
= 0;
9437 struct frame
*sf
= SELECTED_FRAME ();
9439 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9440 w
= XWINDOW (mini_window
);
9441 f
= XFRAME (WINDOW_FRAME (w
));
9443 /* Don't display if frame is invisible or not yet initialized. */
9444 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9447 #ifdef HAVE_WINDOW_SYSTEM
9448 /* When Emacs starts, selected_frame may be the initial terminal
9449 frame. If we let this through, a message would be displayed on
9451 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9453 #endif /* HAVE_WINDOW_SYSTEM */
9455 /* Redraw garbaged frames. */
9457 clear_garbaged_frames ();
9459 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9461 echo_area_window
= mini_window
;
9462 window_height_changed_p
= display_echo_area (w
);
9463 w
->must_be_updated_p
= 1;
9465 /* Update the display, unless called from redisplay_internal.
9466 Also don't update the screen during redisplay itself. The
9467 update will happen at the end of redisplay, and an update
9468 here could cause confusion. */
9469 if (update_frame_p
&& !redisplaying_p
)
9473 /* If the display update has been interrupted by pending
9474 input, update mode lines in the frame. Due to the
9475 pending input, it might have been that redisplay hasn't
9476 been called, so that mode lines above the echo area are
9477 garbaged. This looks odd, so we prevent it here. */
9478 if (!display_completed
)
9479 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9481 if (window_height_changed_p
9482 /* Don't do this if Emacs is shutting down. Redisplay
9483 needs to run hooks. */
9484 && !NILP (Vrun_hooks
))
9486 /* Must update other windows. Likewise as in other
9487 cases, don't let this update be interrupted by
9489 int count
= SPECPDL_INDEX ();
9490 specbind (Qredisplay_dont_pause
, Qt
);
9491 windows_or_buffers_changed
= 1;
9492 redisplay_internal (0);
9493 unbind_to (count
, Qnil
);
9495 else if (FRAME_WINDOW_P (f
) && n
== 0)
9497 /* Window configuration is the same as before.
9498 Can do with a display update of the echo area,
9499 unless we displayed some mode lines. */
9500 update_single_window (w
, 1);
9501 FRAME_RIF (f
)->flush_display (f
);
9504 update_frame (f
, 1, 1);
9506 /* If cursor is in the echo area, make sure that the next
9507 redisplay displays the minibuffer, so that the cursor will
9508 be replaced with what the minibuffer wants. */
9509 if (cursor_in_echo_area
)
9510 ++windows_or_buffers_changed
;
9513 else if (!EQ (mini_window
, selected_window
))
9514 windows_or_buffers_changed
++;
9516 /* Last displayed message is now the current message. */
9517 echo_area_buffer
[1] = echo_area_buffer
[0];
9518 /* Inform read_char that we're not echoing. */
9519 echo_message_buffer
= Qnil
;
9521 /* Prevent redisplay optimization in redisplay_internal by resetting
9522 this_line_start_pos. This is done because the mini-buffer now
9523 displays the message instead of its buffer text. */
9524 if (EQ (mini_window
, selected_window
))
9525 CHARPOS (this_line_start_pos
) = 0;
9527 return window_height_changed_p
;
9532 /***********************************************************************
9533 Mode Lines and Frame Titles
9534 ***********************************************************************/
9536 /* A buffer for constructing non-propertized mode-line strings and
9537 frame titles in it; allocated from the heap in init_xdisp and
9538 resized as needed in store_mode_line_noprop_char. */
9540 static char *mode_line_noprop_buf
;
9542 /* The buffer's end, and a current output position in it. */
9544 static char *mode_line_noprop_buf_end
;
9545 static char *mode_line_noprop_ptr
;
9547 #define MODE_LINE_NOPROP_LEN(start) \
9548 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9551 MODE_LINE_DISPLAY
= 0,
9557 /* Alist that caches the results of :propertize.
9558 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9559 static Lisp_Object mode_line_proptrans_alist
;
9561 /* List of strings making up the mode-line. */
9562 static Lisp_Object mode_line_string_list
;
9564 /* Base face property when building propertized mode line string. */
9565 static Lisp_Object mode_line_string_face
;
9566 static Lisp_Object mode_line_string_face_prop
;
9569 /* Unwind data for mode line strings */
9571 static Lisp_Object Vmode_line_unwind_vector
;
9574 format_mode_line_unwind_data (struct buffer
*obuf
,
9578 Lisp_Object vector
, tmp
;
9580 /* Reduce consing by keeping one vector in
9581 Vwith_echo_area_save_vector. */
9582 vector
= Vmode_line_unwind_vector
;
9583 Vmode_line_unwind_vector
= Qnil
;
9586 vector
= Fmake_vector (make_number (8), Qnil
);
9588 ASET (vector
, 0, make_number (mode_line_target
));
9589 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9590 ASET (vector
, 2, mode_line_string_list
);
9591 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9592 ASET (vector
, 4, mode_line_string_face
);
9593 ASET (vector
, 5, mode_line_string_face_prop
);
9596 XSETBUFFER (tmp
, obuf
);
9599 ASET (vector
, 6, tmp
);
9600 ASET (vector
, 7, owin
);
9606 unwind_format_mode_line (vector
)
9609 mode_line_target
= XINT (AREF (vector
, 0));
9610 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9611 mode_line_string_list
= AREF (vector
, 2);
9612 if (! EQ (AREF (vector
, 3), Qt
))
9613 mode_line_proptrans_alist
= AREF (vector
, 3);
9614 mode_line_string_face
= AREF (vector
, 4);
9615 mode_line_string_face_prop
= AREF (vector
, 5);
9617 if (!NILP (AREF (vector
, 7)))
9618 /* Select window before buffer, since it may change the buffer. */
9619 Fselect_window (AREF (vector
, 7), Qt
);
9621 if (!NILP (AREF (vector
, 6)))
9623 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9624 ASET (vector
, 6, Qnil
);
9627 Vmode_line_unwind_vector
= vector
;
9632 /* Store a single character C for the frame title in mode_line_noprop_buf.
9633 Re-allocate mode_line_noprop_buf if necessary. */
9637 store_mode_line_noprop_char (char c
)
9639 store_mode_line_noprop_char (c
)
9643 /* If output position has reached the end of the allocated buffer,
9644 double the buffer's size. */
9645 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9647 int len
= MODE_LINE_NOPROP_LEN (0);
9648 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9649 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9650 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9651 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9654 *mode_line_noprop_ptr
++ = c
;
9658 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9659 mode_line_noprop_ptr. STR is the string to store. Do not copy
9660 characters that yield more columns than PRECISION; PRECISION <= 0
9661 means copy the whole string. Pad with spaces until FIELD_WIDTH
9662 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9663 pad. Called from display_mode_element when it is used to build a
9667 store_mode_line_noprop (str
, field_width
, precision
)
9668 const unsigned char *str
;
9669 int field_width
, precision
;
9674 /* Copy at most PRECISION chars from STR. */
9675 nbytes
= strlen (str
);
9676 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9678 store_mode_line_noprop_char (*str
++);
9680 /* Fill up with spaces until FIELD_WIDTH reached. */
9681 while (field_width
> 0
9684 store_mode_line_noprop_char (' ');
9691 /***********************************************************************
9693 ***********************************************************************/
9695 #ifdef HAVE_WINDOW_SYSTEM
9697 /* Set the title of FRAME, if it has changed. The title format is
9698 Vicon_title_format if FRAME is iconified, otherwise it is
9699 frame_title_format. */
9702 x_consider_frame_title (frame
)
9705 struct frame
*f
= XFRAME (frame
);
9707 if (FRAME_WINDOW_P (f
)
9708 || FRAME_MINIBUF_ONLY_P (f
)
9709 || f
->explicit_name
)
9711 /* Do we have more than one visible frame on this X display? */
9718 int count
= SPECPDL_INDEX ();
9720 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9722 Lisp_Object other_frame
= XCAR (tail
);
9723 struct frame
*tf
= XFRAME (other_frame
);
9726 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9727 && !FRAME_MINIBUF_ONLY_P (tf
)
9728 && !EQ (other_frame
, tip_frame
)
9729 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9733 /* Set global variable indicating that multiple frames exist. */
9734 multiple_frames
= CONSP (tail
);
9736 /* Switch to the buffer of selected window of the frame. Set up
9737 mode_line_target so that display_mode_element will output into
9738 mode_line_noprop_buf; then display the title. */
9739 record_unwind_protect (unwind_format_mode_line
,
9740 format_mode_line_unwind_data
9741 (current_buffer
, selected_window
, 0));
9743 Fselect_window (f
->selected_window
, Qt
);
9744 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9745 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9747 mode_line_target
= MODE_LINE_TITLE
;
9748 title_start
= MODE_LINE_NOPROP_LEN (0);
9749 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9750 NULL
, DEFAULT_FACE_ID
);
9751 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9752 len
= MODE_LINE_NOPROP_LEN (title_start
);
9753 title
= mode_line_noprop_buf
+ title_start
;
9754 unbind_to (count
, Qnil
);
9756 /* Set the title only if it's changed. This avoids consing in
9757 the common case where it hasn't. (If it turns out that we've
9758 already wasted too much time by walking through the list with
9759 display_mode_element, then we might need to optimize at a
9760 higher level than this.) */
9761 if (! STRINGP (f
->name
)
9762 || SBYTES (f
->name
) != len
9763 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9764 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9768 #endif /* not HAVE_WINDOW_SYSTEM */
9773 /***********************************************************************
9775 ***********************************************************************/
9778 /* Prepare for redisplay by updating menu-bar item lists when
9779 appropriate. This can call eval. */
9782 prepare_menu_bars ()
9785 struct gcpro gcpro1
, gcpro2
;
9787 Lisp_Object tooltip_frame
;
9789 #ifdef HAVE_WINDOW_SYSTEM
9790 tooltip_frame
= tip_frame
;
9792 tooltip_frame
= Qnil
;
9795 /* Update all frame titles based on their buffer names, etc. We do
9796 this before the menu bars so that the buffer-menu will show the
9797 up-to-date frame titles. */
9798 #ifdef HAVE_WINDOW_SYSTEM
9799 if (windows_or_buffers_changed
|| update_mode_lines
)
9801 Lisp_Object tail
, frame
;
9803 FOR_EACH_FRAME (tail
, frame
)
9806 if (!EQ (frame
, tooltip_frame
)
9807 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9808 x_consider_frame_title (frame
);
9811 #endif /* HAVE_WINDOW_SYSTEM */
9813 /* Update the menu bar item lists, if appropriate. This has to be
9814 done before any actual redisplay or generation of display lines. */
9815 all_windows
= (update_mode_lines
9816 || buffer_shared
> 1
9817 || windows_or_buffers_changed
);
9820 Lisp_Object tail
, frame
;
9821 int count
= SPECPDL_INDEX ();
9822 /* 1 means that update_menu_bar has run its hooks
9823 so any further calls to update_menu_bar shouldn't do so again. */
9824 int menu_bar_hooks_run
= 0;
9826 record_unwind_save_match_data ();
9828 FOR_EACH_FRAME (tail
, frame
)
9832 /* Ignore tooltip frame. */
9833 if (EQ (frame
, tooltip_frame
))
9836 /* If a window on this frame changed size, report that to
9837 the user and clear the size-change flag. */
9838 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9840 Lisp_Object functions
;
9842 /* Clear flag first in case we get an error below. */
9843 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9844 functions
= Vwindow_size_change_functions
;
9845 GCPRO2 (tail
, functions
);
9847 while (CONSP (functions
))
9849 if (!EQ (XCAR (functions
), Qt
))
9850 call1 (XCAR (functions
), frame
);
9851 functions
= XCDR (functions
);
9857 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9858 #ifdef HAVE_WINDOW_SYSTEM
9859 update_tool_bar (f
, 0);
9862 if (windows_or_buffers_changed
)
9863 ns_set_doc_edited (f
, Fbuffer_modified_p
9864 (XWINDOW (f
->selected_window
)->buffer
));
9869 unbind_to (count
, Qnil
);
9873 struct frame
*sf
= SELECTED_FRAME ();
9874 update_menu_bar (sf
, 1, 0);
9875 #ifdef HAVE_WINDOW_SYSTEM
9876 update_tool_bar (sf
, 1);
9880 /* Motif needs this. See comment in xmenu.c. Turn it off when
9881 pending_menu_activation is not defined. */
9882 #ifdef USE_X_TOOLKIT
9883 pending_menu_activation
= 0;
9888 /* Update the menu bar item list for frame F. This has to be done
9889 before we start to fill in any display lines, because it can call
9892 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9894 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9895 already ran the menu bar hooks for this redisplay, so there
9896 is no need to run them again. The return value is the
9897 updated value of this flag, to pass to the next call. */
9900 update_menu_bar (f
, save_match_data
, hooks_run
)
9902 int save_match_data
;
9906 register struct window
*w
;
9908 /* If called recursively during a menu update, do nothing. This can
9909 happen when, for instance, an activate-menubar-hook causes a
9911 if (inhibit_menubar_update
)
9914 window
= FRAME_SELECTED_WINDOW (f
);
9915 w
= XWINDOW (window
);
9917 if (FRAME_WINDOW_P (f
)
9919 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9920 || defined (HAVE_NS) || defined (USE_GTK)
9921 FRAME_EXTERNAL_MENU_BAR (f
)
9923 FRAME_MENU_BAR_LINES (f
) > 0
9925 : FRAME_MENU_BAR_LINES (f
) > 0)
9927 /* If the user has switched buffers or windows, we need to
9928 recompute to reflect the new bindings. But we'll
9929 recompute when update_mode_lines is set too; that means
9930 that people can use force-mode-line-update to request
9931 that the menu bar be recomputed. The adverse effect on
9932 the rest of the redisplay algorithm is about the same as
9933 windows_or_buffers_changed anyway. */
9934 if (windows_or_buffers_changed
9935 /* This used to test w->update_mode_line, but we believe
9936 there is no need to recompute the menu in that case. */
9937 || update_mode_lines
9938 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9939 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9940 != !NILP (w
->last_had_star
))
9941 || ((!NILP (Vtransient_mark_mode
)
9942 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9943 != !NILP (w
->region_showing
)))
9945 struct buffer
*prev
= current_buffer
;
9946 int count
= SPECPDL_INDEX ();
9948 specbind (Qinhibit_menubar_update
, Qt
);
9950 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9951 if (save_match_data
)
9952 record_unwind_save_match_data ();
9953 if (NILP (Voverriding_local_map_menu_flag
))
9955 specbind (Qoverriding_terminal_local_map
, Qnil
);
9956 specbind (Qoverriding_local_map
, Qnil
);
9961 /* Run the Lucid hook. */
9962 safe_run_hooks (Qactivate_menubar_hook
);
9964 /* If it has changed current-menubar from previous value,
9965 really recompute the menu-bar from the value. */
9966 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9967 call0 (Qrecompute_lucid_menubar
);
9969 safe_run_hooks (Qmenu_bar_update_hook
);
9974 XSETFRAME (Vmenu_updating_frame
, f
);
9975 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9977 /* Redisplay the menu bar in case we changed it. */
9978 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9979 || defined (HAVE_NS) || defined (USE_GTK)
9980 if (FRAME_WINDOW_P (f
))
9982 #if defined (HAVE_NS)
9983 /* All frames on Mac OS share the same menubar. So only
9984 the selected frame should be allowed to set it. */
9985 if (f
== SELECTED_FRAME ())
9987 set_frame_menubar (f
, 0, 0);
9990 /* On a terminal screen, the menu bar is an ordinary screen
9991 line, and this makes it get updated. */
9992 w
->update_mode_line
= Qt
;
9993 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9994 /* In the non-toolkit version, the menu bar is an ordinary screen
9995 line, and this makes it get updated. */
9996 w
->update_mode_line
= Qt
;
9997 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9999 unbind_to (count
, Qnil
);
10000 set_buffer_internal_1 (prev
);
10009 /***********************************************************************
10011 ***********************************************************************/
10013 #ifdef HAVE_WINDOW_SYSTEM
10016 Nominal cursor position -- where to draw output.
10017 HPOS and VPOS are window relative glyph matrix coordinates.
10018 X and Y are window relative pixel coordinates. */
10020 struct cursor_pos output_cursor
;
10024 Set the global variable output_cursor to CURSOR. All cursor
10025 positions are relative to updated_window. */
10028 set_output_cursor (cursor
)
10029 struct cursor_pos
*cursor
;
10031 output_cursor
.hpos
= cursor
->hpos
;
10032 output_cursor
.vpos
= cursor
->vpos
;
10033 output_cursor
.x
= cursor
->x
;
10034 output_cursor
.y
= cursor
->y
;
10039 Set a nominal cursor position.
10041 HPOS and VPOS are column/row positions in a window glyph matrix. X
10042 and Y are window text area relative pixel positions.
10044 If this is done during an update, updated_window will contain the
10045 window that is being updated and the position is the future output
10046 cursor position for that window. If updated_window is null, use
10047 selected_window and display the cursor at the given position. */
10050 x_cursor_to (vpos
, hpos
, y
, x
)
10051 int vpos
, hpos
, y
, x
;
10055 /* If updated_window is not set, work on selected_window. */
10056 if (updated_window
)
10057 w
= updated_window
;
10059 w
= XWINDOW (selected_window
);
10061 /* Set the output cursor. */
10062 output_cursor
.hpos
= hpos
;
10063 output_cursor
.vpos
= vpos
;
10064 output_cursor
.x
= x
;
10065 output_cursor
.y
= y
;
10067 /* If not called as part of an update, really display the cursor.
10068 This will also set the cursor position of W. */
10069 if (updated_window
== NULL
)
10072 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10073 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10074 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10079 #endif /* HAVE_WINDOW_SYSTEM */
10082 /***********************************************************************
10084 ***********************************************************************/
10086 #ifdef HAVE_WINDOW_SYSTEM
10088 /* Where the mouse was last time we reported a mouse event. */
10090 FRAME_PTR last_mouse_frame
;
10092 /* Tool-bar item index of the item on which a mouse button was pressed
10095 int last_tool_bar_item
;
10099 update_tool_bar_unwind (frame
)
10102 selected_frame
= frame
;
10106 /* Update the tool-bar item list for frame F. This has to be done
10107 before we start to fill in any display lines. Called from
10108 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10109 and restore it here. */
10112 update_tool_bar (f
, save_match_data
)
10114 int save_match_data
;
10116 #if defined (USE_GTK) || defined (HAVE_NS)
10117 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10119 int do_update
= WINDOWP (f
->tool_bar_window
)
10120 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10125 Lisp_Object window
;
10128 window
= FRAME_SELECTED_WINDOW (f
);
10129 w
= XWINDOW (window
);
10131 /* If the user has switched buffers or windows, we need to
10132 recompute to reflect the new bindings. But we'll
10133 recompute when update_mode_lines is set too; that means
10134 that people can use force-mode-line-update to request
10135 that the menu bar be recomputed. The adverse effect on
10136 the rest of the redisplay algorithm is about the same as
10137 windows_or_buffers_changed anyway. */
10138 if (windows_or_buffers_changed
10139 || !NILP (w
->update_mode_line
)
10140 || update_mode_lines
10141 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10142 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10143 != !NILP (w
->last_had_star
))
10144 || ((!NILP (Vtransient_mark_mode
)
10145 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10146 != !NILP (w
->region_showing
)))
10148 struct buffer
*prev
= current_buffer
;
10149 int count
= SPECPDL_INDEX ();
10150 Lisp_Object frame
, new_tool_bar
;
10151 int new_n_tool_bar
;
10152 struct gcpro gcpro1
;
10154 /* Set current_buffer to the buffer of the selected
10155 window of the frame, so that we get the right local
10157 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10159 /* Save match data, if we must. */
10160 if (save_match_data
)
10161 record_unwind_save_match_data ();
10163 /* Make sure that we don't accidentally use bogus keymaps. */
10164 if (NILP (Voverriding_local_map_menu_flag
))
10166 specbind (Qoverriding_terminal_local_map
, Qnil
);
10167 specbind (Qoverriding_local_map
, Qnil
);
10170 GCPRO1 (new_tool_bar
);
10172 /* We must temporarily set the selected frame to this frame
10173 before calling tool_bar_items, because the calculation of
10174 the tool-bar keymap uses the selected frame (see
10175 `tool-bar-make-keymap' in tool-bar.el). */
10176 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10177 XSETFRAME (frame
, f
);
10178 selected_frame
= frame
;
10180 /* Build desired tool-bar items from keymaps. */
10181 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10184 /* Redisplay the tool-bar if we changed it. */
10185 if (new_n_tool_bar
!= f
->n_tool_bar_items
10186 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10188 /* Redisplay that happens asynchronously due to an expose event
10189 may access f->tool_bar_items. Make sure we update both
10190 variables within BLOCK_INPUT so no such event interrupts. */
10192 f
->tool_bar_items
= new_tool_bar
;
10193 f
->n_tool_bar_items
= new_n_tool_bar
;
10194 w
->update_mode_line
= Qt
;
10200 unbind_to (count
, Qnil
);
10201 set_buffer_internal_1 (prev
);
10207 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10208 F's desired tool-bar contents. F->tool_bar_items must have
10209 been set up previously by calling prepare_menu_bars. */
10212 build_desired_tool_bar_string (f
)
10215 int i
, size
, size_needed
;
10216 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10217 Lisp_Object image
, plist
, props
;
10219 image
= plist
= props
= Qnil
;
10220 GCPRO3 (image
, plist
, props
);
10222 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10223 Otherwise, make a new string. */
10225 /* The size of the string we might be able to reuse. */
10226 size
= (STRINGP (f
->desired_tool_bar_string
)
10227 ? SCHARS (f
->desired_tool_bar_string
)
10230 /* We need one space in the string for each image. */
10231 size_needed
= f
->n_tool_bar_items
;
10233 /* Reuse f->desired_tool_bar_string, if possible. */
10234 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10235 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10236 make_number (' '));
10239 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10240 Fremove_text_properties (make_number (0), make_number (size
),
10241 props
, f
->desired_tool_bar_string
);
10244 /* Put a `display' property on the string for the images to display,
10245 put a `menu_item' property on tool-bar items with a value that
10246 is the index of the item in F's tool-bar item vector. */
10247 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10249 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10251 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10252 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10253 int hmargin
, vmargin
, relief
, idx
, end
;
10254 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
10256 /* If image is a vector, choose the image according to the
10258 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10259 if (VECTORP (image
))
10263 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10264 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10267 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10268 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10270 xassert (ASIZE (image
) >= idx
);
10271 image
= AREF (image
, idx
);
10276 /* Ignore invalid image specifications. */
10277 if (!valid_image_p (image
))
10280 /* Display the tool-bar button pressed, or depressed. */
10281 plist
= Fcopy_sequence (XCDR (image
));
10283 /* Compute margin and relief to draw. */
10284 relief
= (tool_bar_button_relief
>= 0
10285 ? tool_bar_button_relief
10286 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10287 hmargin
= vmargin
= relief
;
10289 if (INTEGERP (Vtool_bar_button_margin
)
10290 && XINT (Vtool_bar_button_margin
) > 0)
10292 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10293 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10295 else if (CONSP (Vtool_bar_button_margin
))
10297 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10298 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10299 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10301 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10302 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10303 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10306 if (auto_raise_tool_bar_buttons_p
)
10308 /* Add a `:relief' property to the image spec if the item is
10312 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10319 /* If image is selected, display it pressed, i.e. with a
10320 negative relief. If it's not selected, display it with a
10322 plist
= Fplist_put (plist
, QCrelief
,
10324 ? make_number (-relief
)
10325 : make_number (relief
)));
10330 /* Put a margin around the image. */
10331 if (hmargin
|| vmargin
)
10333 if (hmargin
== vmargin
)
10334 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10336 plist
= Fplist_put (plist
, QCmargin
,
10337 Fcons (make_number (hmargin
),
10338 make_number (vmargin
)));
10341 /* If button is not enabled, and we don't have special images
10342 for the disabled state, make the image appear disabled by
10343 applying an appropriate algorithm to it. */
10344 if (!enabled_p
&& idx
< 0)
10345 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10347 /* Put a `display' text property on the string for the image to
10348 display. Put a `menu-item' property on the string that gives
10349 the start of this item's properties in the tool-bar items
10351 image
= Fcons (Qimage
, plist
);
10352 props
= list4 (Qdisplay
, image
,
10353 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10355 /* Let the last image hide all remaining spaces in the tool bar
10356 string. The string can be longer than needed when we reuse a
10357 previous string. */
10358 if (i
+ 1 == f
->n_tool_bar_items
)
10359 end
= SCHARS (f
->desired_tool_bar_string
);
10362 Fadd_text_properties (make_number (i
), make_number (end
),
10363 props
, f
->desired_tool_bar_string
);
10371 /* Display one line of the tool-bar of frame IT->f.
10373 HEIGHT specifies the desired height of the tool-bar line.
10374 If the actual height of the glyph row is less than HEIGHT, the
10375 row's height is increased to HEIGHT, and the icons are centered
10376 vertically in the new height.
10378 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10379 count a final empty row in case the tool-bar width exactly matches
10384 display_tool_bar_line (it
, height
)
10388 struct glyph_row
*row
= it
->glyph_row
;
10389 int max_x
= it
->last_visible_x
;
10390 struct glyph
*last
;
10392 prepare_desired_row (row
);
10393 row
->y
= it
->current_y
;
10395 /* Note that this isn't made use of if the face hasn't a box,
10396 so there's no need to check the face here. */
10397 it
->start_of_box_run_p
= 1;
10399 while (it
->current_x
< max_x
)
10401 int x
, n_glyphs_before
, i
, nglyphs
;
10402 struct it it_before
;
10404 /* Get the next display element. */
10405 if (!get_next_display_element (it
))
10407 /* Don't count empty row if we are counting needed tool-bar lines. */
10408 if (height
< 0 && !it
->hpos
)
10413 /* Produce glyphs. */
10414 n_glyphs_before
= row
->used
[TEXT_AREA
];
10417 PRODUCE_GLYPHS (it
);
10419 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10421 x
= it_before
.current_x
;
10422 while (i
< nglyphs
)
10424 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10426 if (x
+ glyph
->pixel_width
> max_x
)
10428 /* Glyph doesn't fit on line. Backtrack. */
10429 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10431 /* If this is the only glyph on this line, it will never fit on the
10432 toolbar, so skip it. But ensure there is at least one glyph,
10433 so we don't accidentally disable the tool-bar. */
10434 if (n_glyphs_before
== 0
10435 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10441 x
+= glyph
->pixel_width
;
10445 /* Stop at line ends. */
10446 if (ITERATOR_AT_END_OF_LINE_P (it
))
10449 set_iterator_to_next (it
, 1);
10454 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10456 /* Use default face for the border below the tool bar.
10458 FIXME: When auto-resize-tool-bars is grow-only, there is
10459 no additional border below the possibly empty tool-bar lines.
10460 So to make the extra empty lines look "normal", we have to
10461 use the tool-bar face for the border too. */
10462 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10463 it
->face_id
= DEFAULT_FACE_ID
;
10465 extend_face_to_end_of_line (it
);
10466 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10467 last
->right_box_line_p
= 1;
10468 if (last
== row
->glyphs
[TEXT_AREA
])
10469 last
->left_box_line_p
= 1;
10471 /* Make line the desired height and center it vertically. */
10472 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10474 /* Don't add more than one line height. */
10475 height
%= FRAME_LINE_HEIGHT (it
->f
);
10476 it
->max_ascent
+= height
/ 2;
10477 it
->max_descent
+= (height
+ 1) / 2;
10480 compute_line_metrics (it
);
10482 /* If line is empty, make it occupy the rest of the tool-bar. */
10483 if (!row
->displays_text_p
)
10485 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10486 row
->visible_height
= row
->height
;
10487 row
->ascent
= row
->phys_ascent
= 0;
10488 row
->extra_line_spacing
= 0;
10491 row
->full_width_p
= 1;
10492 row
->continued_p
= 0;
10493 row
->truncated_on_left_p
= 0;
10494 row
->truncated_on_right_p
= 0;
10496 it
->current_x
= it
->hpos
= 0;
10497 it
->current_y
+= row
->height
;
10503 /* Max tool-bar height. */
10505 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10506 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10508 /* Value is the number of screen lines needed to make all tool-bar
10509 items of frame F visible. The number of actual rows needed is
10510 returned in *N_ROWS if non-NULL. */
10513 tool_bar_lines_needed (f
, n_rows
)
10517 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10519 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10520 the desired matrix, so use (unused) mode-line row as temporary row to
10521 avoid destroying the first tool-bar row. */
10522 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10524 /* Initialize an iterator for iteration over
10525 F->desired_tool_bar_string in the tool-bar window of frame F. */
10526 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10527 it
.first_visible_x
= 0;
10528 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10529 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10531 while (!ITERATOR_AT_END_P (&it
))
10533 clear_glyph_row (temp_row
);
10534 it
.glyph_row
= temp_row
;
10535 display_tool_bar_line (&it
, -1);
10537 clear_glyph_row (temp_row
);
10539 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10541 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10543 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10547 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10549 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10558 frame
= selected_frame
;
10560 CHECK_FRAME (frame
);
10561 f
= XFRAME (frame
);
10563 if (WINDOWP (f
->tool_bar_window
)
10564 || (w
= XWINDOW (f
->tool_bar_window
),
10565 WINDOW_TOTAL_LINES (w
) > 0))
10567 update_tool_bar (f
, 1);
10568 if (f
->n_tool_bar_items
)
10570 build_desired_tool_bar_string (f
);
10571 nlines
= tool_bar_lines_needed (f
, NULL
);
10575 return make_number (nlines
);
10579 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10580 height should be changed. */
10583 redisplay_tool_bar (f
)
10588 struct glyph_row
*row
;
10590 #if defined (USE_GTK) || defined (HAVE_NS)
10591 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10592 update_frame_tool_bar (f
);
10596 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10597 do anything. This means you must start with tool-bar-lines
10598 non-zero to get the auto-sizing effect. Or in other words, you
10599 can turn off tool-bars by specifying tool-bar-lines zero. */
10600 if (!WINDOWP (f
->tool_bar_window
)
10601 || (w
= XWINDOW (f
->tool_bar_window
),
10602 WINDOW_TOTAL_LINES (w
) == 0))
10605 /* Set up an iterator for the tool-bar window. */
10606 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10607 it
.first_visible_x
= 0;
10608 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10609 row
= it
.glyph_row
;
10611 /* Build a string that represents the contents of the tool-bar. */
10612 build_desired_tool_bar_string (f
);
10613 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10615 if (f
->n_tool_bar_rows
== 0)
10619 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10620 nlines
!= WINDOW_TOTAL_LINES (w
)))
10622 extern Lisp_Object Qtool_bar_lines
;
10624 int old_height
= WINDOW_TOTAL_LINES (w
);
10626 XSETFRAME (frame
, f
);
10627 Fmodify_frame_parameters (frame
,
10628 Fcons (Fcons (Qtool_bar_lines
,
10629 make_number (nlines
)),
10631 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10633 clear_glyph_matrix (w
->desired_matrix
);
10634 fonts_changed_p
= 1;
10640 /* Display as many lines as needed to display all tool-bar items. */
10642 if (f
->n_tool_bar_rows
> 0)
10644 int border
, rows
, height
, extra
;
10646 if (INTEGERP (Vtool_bar_border
))
10647 border
= XINT (Vtool_bar_border
);
10648 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10649 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10650 else if (EQ (Vtool_bar_border
, Qborder_width
))
10651 border
= f
->border_width
;
10657 rows
= f
->n_tool_bar_rows
;
10658 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10659 extra
= it
.last_visible_y
- border
- height
* rows
;
10661 while (it
.current_y
< it
.last_visible_y
)
10664 if (extra
> 0 && rows
-- > 0)
10666 h
= (extra
+ rows
- 1) / rows
;
10669 display_tool_bar_line (&it
, height
+ h
);
10674 while (it
.current_y
< it
.last_visible_y
)
10675 display_tool_bar_line (&it
, 0);
10678 /* It doesn't make much sense to try scrolling in the tool-bar
10679 window, so don't do it. */
10680 w
->desired_matrix
->no_scrolling_p
= 1;
10681 w
->must_be_updated_p
= 1;
10683 if (!NILP (Vauto_resize_tool_bars
))
10685 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10686 int change_height_p
= 0;
10688 /* If we couldn't display everything, change the tool-bar's
10689 height if there is room for more. */
10690 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10691 && it
.current_y
< max_tool_bar_height
)
10692 change_height_p
= 1;
10694 row
= it
.glyph_row
- 1;
10696 /* If there are blank lines at the end, except for a partially
10697 visible blank line at the end that is smaller than
10698 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10699 if (!row
->displays_text_p
10700 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10701 change_height_p
= 1;
10703 /* If row displays tool-bar items, but is partially visible,
10704 change the tool-bar's height. */
10705 if (row
->displays_text_p
10706 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10707 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10708 change_height_p
= 1;
10710 /* Resize windows as needed by changing the `tool-bar-lines'
10711 frame parameter. */
10712 if (change_height_p
)
10714 extern Lisp_Object Qtool_bar_lines
;
10716 int old_height
= WINDOW_TOTAL_LINES (w
);
10718 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10720 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10721 && !f
->minimize_tool_bar_window_p
)
10722 ? (nlines
> old_height
)
10723 : (nlines
!= old_height
));
10724 f
->minimize_tool_bar_window_p
= 0;
10726 if (change_height_p
)
10728 XSETFRAME (frame
, f
);
10729 Fmodify_frame_parameters (frame
,
10730 Fcons (Fcons (Qtool_bar_lines
,
10731 make_number (nlines
)),
10733 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10735 clear_glyph_matrix (w
->desired_matrix
);
10736 f
->n_tool_bar_rows
= nrows
;
10737 fonts_changed_p
= 1;
10744 f
->minimize_tool_bar_window_p
= 0;
10749 /* Get information about the tool-bar item which is displayed in GLYPH
10750 on frame F. Return in *PROP_IDX the index where tool-bar item
10751 properties start in F->tool_bar_items. Value is zero if
10752 GLYPH doesn't display a tool-bar item. */
10755 tool_bar_item_info (f
, glyph
, prop_idx
)
10757 struct glyph
*glyph
;
10764 /* This function can be called asynchronously, which means we must
10765 exclude any possibility that Fget_text_property signals an
10767 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10768 charpos
= max (0, charpos
);
10770 /* Get the text property `menu-item' at pos. The value of that
10771 property is the start index of this item's properties in
10772 F->tool_bar_items. */
10773 prop
= Fget_text_property (make_number (charpos
),
10774 Qmenu_item
, f
->current_tool_bar_string
);
10775 if (INTEGERP (prop
))
10777 *prop_idx
= XINT (prop
);
10787 /* Get information about the tool-bar item at position X/Y on frame F.
10788 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10789 the current matrix of the tool-bar window of F, or NULL if not
10790 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10791 item in F->tool_bar_items. Value is
10793 -1 if X/Y is not on a tool-bar item
10794 0 if X/Y is on the same item that was highlighted before.
10798 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10801 struct glyph
**glyph
;
10802 int *hpos
, *vpos
, *prop_idx
;
10804 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10805 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10808 /* Find the glyph under X/Y. */
10809 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10810 if (*glyph
== NULL
)
10813 /* Get the start of this tool-bar item's properties in
10814 f->tool_bar_items. */
10815 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10818 /* Is mouse on the highlighted item? */
10819 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10820 && *vpos
>= dpyinfo
->mouse_face_beg_row
10821 && *vpos
<= dpyinfo
->mouse_face_end_row
10822 && (*vpos
> dpyinfo
->mouse_face_beg_row
10823 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10824 && (*vpos
< dpyinfo
->mouse_face_end_row
10825 || *hpos
< dpyinfo
->mouse_face_end_col
10826 || dpyinfo
->mouse_face_past_end
))
10834 Handle mouse button event on the tool-bar of frame F, at
10835 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10836 0 for button release. MODIFIERS is event modifiers for button
10840 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10843 unsigned int modifiers
;
10845 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10846 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10847 int hpos
, vpos
, prop_idx
;
10848 struct glyph
*glyph
;
10849 Lisp_Object enabled_p
;
10851 /* If not on the highlighted tool-bar item, return. */
10852 frame_to_window_pixel_xy (w
, &x
, &y
);
10853 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10856 /* If item is disabled, do nothing. */
10857 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10858 if (NILP (enabled_p
))
10863 /* Show item in pressed state. */
10864 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10865 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10866 last_tool_bar_item
= prop_idx
;
10870 Lisp_Object key
, frame
;
10871 struct input_event event
;
10872 EVENT_INIT (event
);
10874 /* Show item in released state. */
10875 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10876 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10878 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10880 XSETFRAME (frame
, f
);
10881 event
.kind
= TOOL_BAR_EVENT
;
10882 event
.frame_or_window
= frame
;
10884 kbd_buffer_store_event (&event
);
10886 event
.kind
= TOOL_BAR_EVENT
;
10887 event
.frame_or_window
= frame
;
10889 event
.modifiers
= modifiers
;
10890 kbd_buffer_store_event (&event
);
10891 last_tool_bar_item
= -1;
10896 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10897 tool-bar window-relative coordinates X/Y. Called from
10898 note_mouse_highlight. */
10901 note_tool_bar_highlight (f
, x
, y
)
10905 Lisp_Object window
= f
->tool_bar_window
;
10906 struct window
*w
= XWINDOW (window
);
10907 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10909 struct glyph
*glyph
;
10910 struct glyph_row
*row
;
10912 Lisp_Object enabled_p
;
10914 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10915 int mouse_down_p
, rc
;
10917 /* Function note_mouse_highlight is called with negative x(y
10918 values when mouse moves outside of the frame. */
10919 if (x
<= 0 || y
<= 0)
10921 clear_mouse_face (dpyinfo
);
10925 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10928 /* Not on tool-bar item. */
10929 clear_mouse_face (dpyinfo
);
10933 /* On same tool-bar item as before. */
10934 goto set_help_echo
;
10936 clear_mouse_face (dpyinfo
);
10938 /* Mouse is down, but on different tool-bar item? */
10939 mouse_down_p
= (dpyinfo
->grabbed
10940 && f
== last_mouse_frame
10941 && FRAME_LIVE_P (f
));
10943 && last_tool_bar_item
!= prop_idx
)
10946 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10947 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10949 /* If tool-bar item is not enabled, don't highlight it. */
10950 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10951 if (!NILP (enabled_p
))
10953 /* Compute the x-position of the glyph. In front and past the
10954 image is a space. We include this in the highlighted area. */
10955 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10956 for (i
= x
= 0; i
< hpos
; ++i
)
10957 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10959 /* Record this as the current active region. */
10960 dpyinfo
->mouse_face_beg_col
= hpos
;
10961 dpyinfo
->mouse_face_beg_row
= vpos
;
10962 dpyinfo
->mouse_face_beg_x
= x
;
10963 dpyinfo
->mouse_face_beg_y
= row
->y
;
10964 dpyinfo
->mouse_face_past_end
= 0;
10966 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10967 dpyinfo
->mouse_face_end_row
= vpos
;
10968 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10969 dpyinfo
->mouse_face_end_y
= row
->y
;
10970 dpyinfo
->mouse_face_window
= window
;
10971 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10973 /* Display it as active. */
10974 show_mouse_face (dpyinfo
, draw
);
10975 dpyinfo
->mouse_face_image_state
= draw
;
10980 /* Set help_echo_string to a help string to display for this tool-bar item.
10981 XTread_socket does the rest. */
10982 help_echo_object
= help_echo_window
= Qnil
;
10983 help_echo_pos
= -1;
10984 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10985 if (NILP (help_echo_string
))
10986 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10989 #endif /* HAVE_WINDOW_SYSTEM */
10993 /************************************************************************
10994 Horizontal scrolling
10995 ************************************************************************/
10997 static int hscroll_window_tree
P_ ((Lisp_Object
));
10998 static int hscroll_windows
P_ ((Lisp_Object
));
11000 /* For all leaf windows in the window tree rooted at WINDOW, set their
11001 hscroll value so that PT is (i) visible in the window, and (ii) so
11002 that it is not within a certain margin at the window's left and
11003 right border. Value is non-zero if any window's hscroll has been
11007 hscroll_window_tree (window
)
11008 Lisp_Object window
;
11010 int hscrolled_p
= 0;
11011 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11012 int hscroll_step_abs
= 0;
11013 double hscroll_step_rel
= 0;
11015 if (hscroll_relative_p
)
11017 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11018 if (hscroll_step_rel
< 0)
11020 hscroll_relative_p
= 0;
11021 hscroll_step_abs
= 0;
11024 else if (INTEGERP (Vhscroll_step
))
11026 hscroll_step_abs
= XINT (Vhscroll_step
);
11027 if (hscroll_step_abs
< 0)
11028 hscroll_step_abs
= 0;
11031 hscroll_step_abs
= 0;
11033 while (WINDOWP (window
))
11035 struct window
*w
= XWINDOW (window
);
11037 if (WINDOWP (w
->hchild
))
11038 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11039 else if (WINDOWP (w
->vchild
))
11040 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11041 else if (w
->cursor
.vpos
>= 0)
11044 int text_area_width
;
11045 struct glyph_row
*current_cursor_row
11046 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11047 struct glyph_row
*desired_cursor_row
11048 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11049 struct glyph_row
*cursor_row
11050 = (desired_cursor_row
->enabled_p
11051 ? desired_cursor_row
11052 : current_cursor_row
);
11054 text_area_width
= window_box_width (w
, TEXT_AREA
);
11056 /* Scroll when cursor is inside this scroll margin. */
11057 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11059 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11060 && ((XFASTINT (w
->hscroll
)
11061 && w
->cursor
.x
<= h_margin
)
11062 || (cursor_row
->enabled_p
11063 && cursor_row
->truncated_on_right_p
11064 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11068 struct buffer
*saved_current_buffer
;
11072 /* Find point in a display of infinite width. */
11073 saved_current_buffer
= current_buffer
;
11074 current_buffer
= XBUFFER (w
->buffer
);
11076 if (w
== XWINDOW (selected_window
))
11077 pt
= BUF_PT (current_buffer
);
11080 pt
= marker_position (w
->pointm
);
11081 pt
= max (BEGV
, pt
);
11085 /* Move iterator to pt starting at cursor_row->start in
11086 a line with infinite width. */
11087 init_to_row_start (&it
, w
, cursor_row
);
11088 it
.last_visible_x
= INFINITY
;
11089 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11090 current_buffer
= saved_current_buffer
;
11092 /* Position cursor in window. */
11093 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11094 hscroll
= max (0, (it
.current_x
11095 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11096 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11097 : (text_area_width
/ 2))))
11098 / FRAME_COLUMN_WIDTH (it
.f
);
11099 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11101 if (hscroll_relative_p
)
11102 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11105 wanted_x
= text_area_width
11106 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11109 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11113 if (hscroll_relative_p
)
11114 wanted_x
= text_area_width
* hscroll_step_rel
11117 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11120 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11122 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11124 /* Don't call Fset_window_hscroll if value hasn't
11125 changed because it will prevent redisplay
11127 if (XFASTINT (w
->hscroll
) != hscroll
)
11129 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11130 w
->hscroll
= make_number (hscroll
);
11139 /* Value is non-zero if hscroll of any leaf window has been changed. */
11140 return hscrolled_p
;
11144 /* Set hscroll so that cursor is visible and not inside horizontal
11145 scroll margins for all windows in the tree rooted at WINDOW. See
11146 also hscroll_window_tree above. Value is non-zero if any window's
11147 hscroll has been changed. If it has, desired matrices on the frame
11148 of WINDOW are cleared. */
11151 hscroll_windows (window
)
11152 Lisp_Object window
;
11154 int hscrolled_p
= hscroll_window_tree (window
);
11156 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11157 return hscrolled_p
;
11162 /************************************************************************
11164 ************************************************************************/
11166 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11167 to a non-zero value. This is sometimes handy to have in a debugger
11172 /* First and last unchanged row for try_window_id. */
11174 int debug_first_unchanged_at_end_vpos
;
11175 int debug_last_unchanged_at_beg_vpos
;
11177 /* Delta vpos and y. */
11179 int debug_dvpos
, debug_dy
;
11181 /* Delta in characters and bytes for try_window_id. */
11183 int debug_delta
, debug_delta_bytes
;
11185 /* Values of window_end_pos and window_end_vpos at the end of
11188 EMACS_INT debug_end_pos
, debug_end_vpos
;
11190 /* Append a string to W->desired_matrix->method. FMT is a printf
11191 format string. A1...A9 are a supplement for a variable-length
11192 argument list. If trace_redisplay_p is non-zero also printf the
11193 resulting string to stderr. */
11196 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11199 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11202 char *method
= w
->desired_matrix
->method
;
11203 int len
= strlen (method
);
11204 int size
= sizeof w
->desired_matrix
->method
;
11205 int remaining
= size
- len
- 1;
11207 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11208 if (len
&& remaining
)
11211 --remaining
, ++len
;
11214 strncpy (method
+ len
, buffer
, remaining
);
11216 if (trace_redisplay_p
)
11217 fprintf (stderr
, "%p (%s): %s\n",
11219 ((BUFFERP (w
->buffer
)
11220 && STRINGP (XBUFFER (w
->buffer
)->name
))
11221 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
11226 #endif /* GLYPH_DEBUG */
11229 /* Value is non-zero if all changes in window W, which displays
11230 current_buffer, are in the text between START and END. START is a
11231 buffer position, END is given as a distance from Z. Used in
11232 redisplay_internal for display optimization. */
11235 text_outside_line_unchanged_p (w
, start
, end
)
11239 int unchanged_p
= 1;
11241 /* If text or overlays have changed, see where. */
11242 if (XFASTINT (w
->last_modified
) < MODIFF
11243 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11245 /* Gap in the line? */
11246 if (GPT
< start
|| Z
- GPT
< end
)
11249 /* Changes start in front of the line, or end after it? */
11251 && (BEG_UNCHANGED
< start
- 1
11252 || END_UNCHANGED
< end
))
11255 /* If selective display, can't optimize if changes start at the
11256 beginning of the line. */
11258 && INTEGERP (current_buffer
->selective_display
)
11259 && XINT (current_buffer
->selective_display
) > 0
11260 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11263 /* If there are overlays at the start or end of the line, these
11264 may have overlay strings with newlines in them. A change at
11265 START, for instance, may actually concern the display of such
11266 overlay strings as well, and they are displayed on different
11267 lines. So, quickly rule out this case. (For the future, it
11268 might be desirable to implement something more telling than
11269 just BEG/END_UNCHANGED.) */
11272 if (BEG
+ BEG_UNCHANGED
== start
11273 && overlay_touches_p (start
))
11275 if (END_UNCHANGED
== end
11276 && overlay_touches_p (Z
- end
))
11280 /* Under bidi reordering, adding or deleting a character in the
11281 beginning of a paragraph, before the first strong directional
11282 character, can change the base direction of the paragraph (unless
11283 the buffer specifies a fixed paragraph direction), which will
11284 require to redisplay the whole paragraph. It might be worthwhile
11285 to find the paragraph limits and widen the range of redisplayed
11286 lines to that, but for now just give up this optimization. */
11287 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
11288 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
11292 return unchanged_p
;
11296 /* Do a frame update, taking possible shortcuts into account. This is
11297 the main external entry point for redisplay.
11299 If the last redisplay displayed an echo area message and that message
11300 is no longer requested, we clear the echo area or bring back the
11301 mini-buffer if that is in use. */
11306 redisplay_internal (0);
11311 overlay_arrow_string_or_property (var
)
11316 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11319 return Voverlay_arrow_string
;
11322 /* Return 1 if there are any overlay-arrows in current_buffer. */
11324 overlay_arrow_in_current_buffer_p ()
11328 for (vlist
= Voverlay_arrow_variable_list
;
11330 vlist
= XCDR (vlist
))
11332 Lisp_Object var
= XCAR (vlist
);
11335 if (!SYMBOLP (var
))
11337 val
= find_symbol_value (var
);
11339 && current_buffer
== XMARKER (val
)->buffer
)
11346 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11350 overlay_arrows_changed_p ()
11354 for (vlist
= Voverlay_arrow_variable_list
;
11356 vlist
= XCDR (vlist
))
11358 Lisp_Object var
= XCAR (vlist
);
11359 Lisp_Object val
, pstr
;
11361 if (!SYMBOLP (var
))
11363 val
= find_symbol_value (var
);
11364 if (!MARKERP (val
))
11366 if (! EQ (COERCE_MARKER (val
),
11367 Fget (var
, Qlast_arrow_position
))
11368 || ! (pstr
= overlay_arrow_string_or_property (var
),
11369 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11375 /* Mark overlay arrows to be updated on next redisplay. */
11378 update_overlay_arrows (up_to_date
)
11383 for (vlist
= Voverlay_arrow_variable_list
;
11385 vlist
= XCDR (vlist
))
11387 Lisp_Object var
= XCAR (vlist
);
11389 if (!SYMBOLP (var
))
11392 if (up_to_date
> 0)
11394 Lisp_Object val
= find_symbol_value (var
);
11395 Fput (var
, Qlast_arrow_position
,
11396 COERCE_MARKER (val
));
11397 Fput (var
, Qlast_arrow_string
,
11398 overlay_arrow_string_or_property (var
));
11400 else if (up_to_date
< 0
11401 || !NILP (Fget (var
, Qlast_arrow_position
)))
11403 Fput (var
, Qlast_arrow_position
, Qt
);
11404 Fput (var
, Qlast_arrow_string
, Qt
);
11410 /* Return overlay arrow string to display at row.
11411 Return integer (bitmap number) for arrow bitmap in left fringe.
11412 Return nil if no overlay arrow. */
11415 overlay_arrow_at_row (it
, row
)
11417 struct glyph_row
*row
;
11421 for (vlist
= Voverlay_arrow_variable_list
;
11423 vlist
= XCDR (vlist
))
11425 Lisp_Object var
= XCAR (vlist
);
11428 if (!SYMBOLP (var
))
11431 val
= find_symbol_value (var
);
11434 && current_buffer
== XMARKER (val
)->buffer
11435 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11437 if (FRAME_WINDOW_P (it
->f
)
11438 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11440 #ifdef HAVE_WINDOW_SYSTEM
11441 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11444 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11445 return make_number (fringe_bitmap
);
11448 return make_number (-1); /* Use default arrow bitmap */
11450 return overlay_arrow_string_or_property (var
);
11457 /* Return 1 if point moved out of or into a composition. Otherwise
11458 return 0. PREV_BUF and PREV_PT are the last point buffer and
11459 position. BUF and PT are the current point buffer and position. */
11462 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11463 struct buffer
*prev_buf
, *buf
;
11466 EMACS_INT start
, end
;
11468 Lisp_Object buffer
;
11470 XSETBUFFER (buffer
, buf
);
11471 /* Check a composition at the last point if point moved within the
11473 if (prev_buf
== buf
)
11476 /* Point didn't move. */
11479 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11480 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11481 && COMPOSITION_VALID_P (start
, end
, prop
)
11482 && start
< prev_pt
&& end
> prev_pt
)
11483 /* The last point was within the composition. Return 1 iff
11484 point moved out of the composition. */
11485 return (pt
<= start
|| pt
>= end
);
11488 /* Check a composition at the current point. */
11489 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11490 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11491 && COMPOSITION_VALID_P (start
, end
, prop
)
11492 && start
< pt
&& end
> pt
);
11496 /* Reconsider the setting of B->clip_changed which is displayed
11500 reconsider_clip_changes (w
, b
)
11504 if (b
->clip_changed
11505 && !NILP (w
->window_end_valid
)
11506 && w
->current_matrix
->buffer
== b
11507 && w
->current_matrix
->zv
== BUF_ZV (b
)
11508 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11509 b
->clip_changed
= 0;
11511 /* If display wasn't paused, and W is not a tool bar window, see if
11512 point has been moved into or out of a composition. In that case,
11513 we set b->clip_changed to 1 to force updating the screen. If
11514 b->clip_changed has already been set to 1, we can skip this
11516 if (!b
->clip_changed
11517 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11521 if (w
== XWINDOW (selected_window
))
11522 pt
= BUF_PT (current_buffer
);
11524 pt
= marker_position (w
->pointm
);
11526 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11527 || pt
!= XINT (w
->last_point
))
11528 && check_point_in_composition (w
->current_matrix
->buffer
,
11529 XINT (w
->last_point
),
11530 XBUFFER (w
->buffer
), pt
))
11531 b
->clip_changed
= 1;
11536 /* Select FRAME to forward the values of frame-local variables into C
11537 variables so that the redisplay routines can access those values
11541 select_frame_for_redisplay (frame
)
11544 Lisp_Object tail
, symbol
, val
;
11545 Lisp_Object old
= selected_frame
;
11546 struct Lisp_Symbol
*sym
;
11548 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11550 selected_frame
= frame
;
11554 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11555 if (CONSP (XCAR (tail
))
11556 && (symbol
= XCAR (XCAR (tail
)),
11558 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11560 (BUFFER_LOCAL_VALUEP (val
)))
11561 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11562 /* Use find_symbol_value rather than Fsymbol_value
11563 to avoid an error if it is void. */
11564 find_symbol_value (symbol
);
11565 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11569 #define STOP_POLLING \
11570 do { if (! polling_stopped_here) stop_polling (); \
11571 polling_stopped_here = 1; } while (0)
11573 #define RESUME_POLLING \
11574 do { if (polling_stopped_here) start_polling (); \
11575 polling_stopped_here = 0; } while (0)
11578 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11579 response to any user action; therefore, we should preserve the echo
11580 area. (Actually, our caller does that job.) Perhaps in the future
11581 avoid recentering windows if it is not necessary; currently that
11582 causes some problems. */
11585 redisplay_internal (preserve_echo_area
)
11586 int preserve_echo_area
;
11588 struct window
*w
= XWINDOW (selected_window
);
11591 int must_finish
= 0;
11592 struct text_pos tlbufpos
, tlendpos
;
11593 int number_of_visible_frames
;
11596 int polling_stopped_here
= 0;
11597 Lisp_Object old_frame
= selected_frame
;
11599 /* Non-zero means redisplay has to consider all windows on all
11600 frames. Zero means, only selected_window is considered. */
11601 int consider_all_windows_p
;
11603 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11605 /* No redisplay if running in batch mode or frame is not yet fully
11606 initialized, or redisplay is explicitly turned off by setting
11607 Vinhibit_redisplay. */
11608 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11609 || !NILP (Vinhibit_redisplay
))
11612 /* Don't examine these until after testing Vinhibit_redisplay.
11613 When Emacs is shutting down, perhaps because its connection to
11614 X has dropped, we should not look at them at all. */
11615 f
= XFRAME (w
->frame
);
11616 sf
= SELECTED_FRAME ();
11618 if (!f
->glyphs_initialized_p
)
11621 /* The flag redisplay_performed_directly_p is set by
11622 direct_output_for_insert when it already did the whole screen
11623 update necessary. */
11624 if (redisplay_performed_directly_p
)
11626 redisplay_performed_directly_p
= 0;
11627 if (!hscroll_windows (selected_window
))
11631 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11632 if (popup_activated ())
11636 /* I don't think this happens but let's be paranoid. */
11637 if (redisplaying_p
)
11640 /* Record a function that resets redisplaying_p to its old value
11641 when we leave this function. */
11642 count
= SPECPDL_INDEX ();
11643 record_unwind_protect (unwind_redisplay
,
11644 Fcons (make_number (redisplaying_p
), selected_frame
));
11646 specbind (Qinhibit_free_realized_faces
, Qnil
);
11649 Lisp_Object tail
, frame
;
11651 FOR_EACH_FRAME (tail
, frame
)
11653 struct frame
*f
= XFRAME (frame
);
11654 f
->already_hscrolled_p
= 0;
11659 if (!EQ (old_frame
, selected_frame
)
11660 && FRAME_LIVE_P (XFRAME (old_frame
)))
11661 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11662 selected_frame and selected_window to be temporarily out-of-sync so
11663 when we come back here via `goto retry', we need to resync because we
11664 may need to run Elisp code (via prepare_menu_bars). */
11665 select_frame_for_redisplay (old_frame
);
11668 reconsider_clip_changes (w
, current_buffer
);
11669 last_escape_glyph_frame
= NULL
;
11670 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11672 /* If new fonts have been loaded that make a glyph matrix adjustment
11673 necessary, do it. */
11674 if (fonts_changed_p
)
11676 adjust_glyphs (NULL
);
11677 ++windows_or_buffers_changed
;
11678 fonts_changed_p
= 0;
11681 /* If face_change_count is non-zero, init_iterator will free all
11682 realized faces, which includes the faces referenced from current
11683 matrices. So, we can't reuse current matrices in this case. */
11684 if (face_change_count
)
11685 ++windows_or_buffers_changed
;
11687 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11688 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11690 /* Since frames on a single ASCII terminal share the same
11691 display area, displaying a different frame means redisplay
11692 the whole thing. */
11693 windows_or_buffers_changed
++;
11694 SET_FRAME_GARBAGED (sf
);
11696 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11698 FRAME_TTY (sf
)->previous_frame
= sf
;
11701 /* Set the visible flags for all frames. Do this before checking
11702 for resized or garbaged frames; they want to know if their frames
11703 are visible. See the comment in frame.h for
11704 FRAME_SAMPLE_VISIBILITY. */
11706 Lisp_Object tail
, frame
;
11708 number_of_visible_frames
= 0;
11710 FOR_EACH_FRAME (tail
, frame
)
11712 struct frame
*f
= XFRAME (frame
);
11714 FRAME_SAMPLE_VISIBILITY (f
);
11715 if (FRAME_VISIBLE_P (f
))
11716 ++number_of_visible_frames
;
11717 clear_desired_matrices (f
);
11721 /* Notice any pending interrupt request to change frame size. */
11722 do_pending_window_change (1);
11724 /* Clear frames marked as garbaged. */
11725 if (frame_garbaged
)
11726 clear_garbaged_frames ();
11728 /* Build menubar and tool-bar items. */
11729 if (NILP (Vmemory_full
))
11730 prepare_menu_bars ();
11732 if (windows_or_buffers_changed
)
11733 update_mode_lines
++;
11735 /* Detect case that we need to write or remove a star in the mode line. */
11736 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11738 w
->update_mode_line
= Qt
;
11739 if (buffer_shared
> 1)
11740 update_mode_lines
++;
11743 /* Avoid invocation of point motion hooks by `current_column' below. */
11744 count1
= SPECPDL_INDEX ();
11745 specbind (Qinhibit_point_motion_hooks
, Qt
);
11747 /* If %c is in the mode line, update it if needed. */
11748 if (!NILP (w
->column_number_displayed
)
11749 /* This alternative quickly identifies a common case
11750 where no change is needed. */
11751 && !(PT
== XFASTINT (w
->last_point
)
11752 && XFASTINT (w
->last_modified
) >= MODIFF
11753 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11754 && (XFASTINT (w
->column_number_displayed
)
11755 != (int) current_column ())) /* iftc */
11756 w
->update_mode_line
= Qt
;
11758 unbind_to (count1
, Qnil
);
11760 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11762 /* The variable buffer_shared is set in redisplay_window and
11763 indicates that we redisplay a buffer in different windows. See
11765 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11766 || cursor_type_changed
);
11768 /* If specs for an arrow have changed, do thorough redisplay
11769 to ensure we remove any arrow that should no longer exist. */
11770 if (overlay_arrows_changed_p ())
11771 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11773 /* Normally the message* functions will have already displayed and
11774 updated the echo area, but the frame may have been trashed, or
11775 the update may have been preempted, so display the echo area
11776 again here. Checking message_cleared_p captures the case that
11777 the echo area should be cleared. */
11778 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11779 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11780 || (message_cleared_p
11781 && minibuf_level
== 0
11782 /* If the mini-window is currently selected, this means the
11783 echo-area doesn't show through. */
11784 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11786 int window_height_changed_p
= echo_area_display (0);
11789 /* If we don't display the current message, don't clear the
11790 message_cleared_p flag, because, if we did, we wouldn't clear
11791 the echo area in the next redisplay which doesn't preserve
11793 if (!display_last_displayed_message_p
)
11794 message_cleared_p
= 0;
11796 if (fonts_changed_p
)
11798 else if (window_height_changed_p
)
11800 consider_all_windows_p
= 1;
11801 ++update_mode_lines
;
11802 ++windows_or_buffers_changed
;
11804 /* If window configuration was changed, frames may have been
11805 marked garbaged. Clear them or we will experience
11806 surprises wrt scrolling. */
11807 if (frame_garbaged
)
11808 clear_garbaged_frames ();
11811 else if (EQ (selected_window
, minibuf_window
)
11812 && (current_buffer
->clip_changed
11813 || XFASTINT (w
->last_modified
) < MODIFF
11814 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11815 && resize_mini_window (w
, 0))
11817 /* Resized active mini-window to fit the size of what it is
11818 showing if its contents might have changed. */
11820 /* FIXME: this causes all frames to be updated, which seems unnecessary
11821 since only the current frame needs to be considered. This function needs
11822 to be rewritten with two variables, consider_all_windows and
11823 consider_all_frames. */
11824 consider_all_windows_p
= 1;
11825 ++windows_or_buffers_changed
;
11826 ++update_mode_lines
;
11828 /* If window configuration was changed, frames may have been
11829 marked garbaged. Clear them or we will experience
11830 surprises wrt scrolling. */
11831 if (frame_garbaged
)
11832 clear_garbaged_frames ();
11836 /* If showing the region, and mark has changed, we must redisplay
11837 the whole window. The assignment to this_line_start_pos prevents
11838 the optimization directly below this if-statement. */
11839 if (((!NILP (Vtransient_mark_mode
)
11840 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11841 != !NILP (w
->region_showing
))
11842 || (!NILP (w
->region_showing
)
11843 && !EQ (w
->region_showing
,
11844 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11845 CHARPOS (this_line_start_pos
) = 0;
11847 /* Optimize the case that only the line containing the cursor in the
11848 selected window has changed. Variables starting with this_ are
11849 set in display_line and record information about the line
11850 containing the cursor. */
11851 tlbufpos
= this_line_start_pos
;
11852 tlendpos
= this_line_end_pos
;
11853 if (!consider_all_windows_p
11854 && CHARPOS (tlbufpos
) > 0
11855 && NILP (w
->update_mode_line
)
11856 && !current_buffer
->clip_changed
11857 && !current_buffer
->prevent_redisplay_optimizations_p
11858 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11859 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11860 /* Make sure recorded data applies to current buffer, etc. */
11861 && this_line_buffer
== current_buffer
11862 && current_buffer
== XBUFFER (w
->buffer
)
11863 && NILP (w
->force_start
)
11864 && NILP (w
->optional_new_start
)
11865 /* Point must be on the line that we have info recorded about. */
11866 && PT
>= CHARPOS (tlbufpos
)
11867 && PT
<= Z
- CHARPOS (tlendpos
)
11868 /* All text outside that line, including its final newline,
11869 must be unchanged. */
11870 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11871 CHARPOS (tlendpos
)))
11873 if (CHARPOS (tlbufpos
) > BEGV
11874 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11875 && (CHARPOS (tlbufpos
) == ZV
11876 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11877 /* Former continuation line has disappeared by becoming empty. */
11879 else if (XFASTINT (w
->last_modified
) < MODIFF
11880 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11881 || MINI_WINDOW_P (w
))
11883 /* We have to handle the case of continuation around a
11884 wide-column character (see the comment in indent.c around
11887 For instance, in the following case:
11889 -------- Insert --------
11890 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11891 J_I_ ==> J_I_ `^^' are cursors.
11895 As we have to redraw the line above, we cannot use this
11899 int line_height_before
= this_line_pixel_height
;
11901 /* Note that start_display will handle the case that the
11902 line starting at tlbufpos is a continuation line. */
11903 start_display (&it
, w
, tlbufpos
);
11905 /* Implementation note: It this still necessary? */
11906 if (it
.current_x
!= this_line_start_x
)
11909 TRACE ((stderr
, "trying display optimization 1\n"));
11910 w
->cursor
.vpos
= -1;
11911 overlay_arrow_seen
= 0;
11912 it
.vpos
= this_line_vpos
;
11913 it
.current_y
= this_line_y
;
11914 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11915 display_line (&it
);
11917 /* If line contains point, is not continued,
11918 and ends at same distance from eob as before, we win. */
11919 if (w
->cursor
.vpos
>= 0
11920 /* Line is not continued, otherwise this_line_start_pos
11921 would have been set to 0 in display_line. */
11922 && CHARPOS (this_line_start_pos
)
11923 /* Line ends as before. */
11924 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11925 /* Line has same height as before. Otherwise other lines
11926 would have to be shifted up or down. */
11927 && this_line_pixel_height
== line_height_before
)
11929 /* If this is not the window's last line, we must adjust
11930 the charstarts of the lines below. */
11931 if (it
.current_y
< it
.last_visible_y
)
11933 struct glyph_row
*row
11934 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11935 int delta
, delta_bytes
;
11937 /* We used to distinguish between two cases here,
11938 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11939 when the line ends in a newline or the end of the
11940 buffer's accessible portion. But both cases did
11941 the same, so they were collapsed. */
11943 - CHARPOS (tlendpos
)
11944 - MATRIX_ROW_START_CHARPOS (row
));
11945 delta_bytes
= (Z_BYTE
11946 - BYTEPOS (tlendpos
)
11947 - MATRIX_ROW_START_BYTEPOS (row
));
11949 increment_matrix_positions (w
->current_matrix
,
11950 this_line_vpos
+ 1,
11951 w
->current_matrix
->nrows
,
11952 delta
, delta_bytes
);
11955 /* If this row displays text now but previously didn't,
11956 or vice versa, w->window_end_vpos may have to be
11958 if ((it
.glyph_row
- 1)->displays_text_p
)
11960 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11961 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11963 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11964 && this_line_vpos
> 0)
11965 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11966 w
->window_end_valid
= Qnil
;
11968 /* Update hint: No need to try to scroll in update_window. */
11969 w
->desired_matrix
->no_scrolling_p
= 1;
11972 *w
->desired_matrix
->method
= 0;
11973 debug_method_add (w
, "optimization 1");
11975 #ifdef HAVE_WINDOW_SYSTEM
11976 update_window_fringes (w
, 0);
11983 else if (/* Cursor position hasn't changed. */
11984 PT
== XFASTINT (w
->last_point
)
11985 /* Make sure the cursor was last displayed
11986 in this window. Otherwise we have to reposition it. */
11987 && 0 <= w
->cursor
.vpos
11988 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11992 do_pending_window_change (1);
11994 /* We used to always goto end_of_redisplay here, but this
11995 isn't enough if we have a blinking cursor. */
11996 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11997 goto end_of_redisplay
;
12001 /* If highlighting the region, or if the cursor is in the echo area,
12002 then we can't just move the cursor. */
12003 else if (! (!NILP (Vtransient_mark_mode
)
12004 && !NILP (current_buffer
->mark_active
))
12005 && (EQ (selected_window
, current_buffer
->last_selected_window
)
12006 || highlight_nonselected_windows
)
12007 && NILP (w
->region_showing
)
12008 && NILP (Vshow_trailing_whitespace
)
12009 && !cursor_in_echo_area
)
12012 struct glyph_row
*row
;
12014 /* Skip from tlbufpos to PT and see where it is. Note that
12015 PT may be in invisible text. If so, we will end at the
12016 next visible position. */
12017 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12018 NULL
, DEFAULT_FACE_ID
);
12019 it
.current_x
= this_line_start_x
;
12020 it
.current_y
= this_line_y
;
12021 it
.vpos
= this_line_vpos
;
12023 /* The call to move_it_to stops in front of PT, but
12024 moves over before-strings. */
12025 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12027 if (it
.vpos
== this_line_vpos
12028 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12031 xassert (this_line_vpos
== it
.vpos
);
12032 xassert (this_line_y
== it
.current_y
);
12033 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12035 *w
->desired_matrix
->method
= 0;
12036 debug_method_add (w
, "optimization 3");
12045 /* Text changed drastically or point moved off of line. */
12046 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12049 CHARPOS (this_line_start_pos
) = 0;
12050 consider_all_windows_p
|= buffer_shared
> 1;
12051 ++clear_face_cache_count
;
12052 #ifdef HAVE_WINDOW_SYSTEM
12053 ++clear_image_cache_count
;
12056 /* Build desired matrices, and update the display. If
12057 consider_all_windows_p is non-zero, do it for all windows on all
12058 frames. Otherwise do it for selected_window, only. */
12060 if (consider_all_windows_p
)
12062 Lisp_Object tail
, frame
;
12064 FOR_EACH_FRAME (tail
, frame
)
12065 XFRAME (frame
)->updated_p
= 0;
12067 /* Recompute # windows showing selected buffer. This will be
12068 incremented each time such a window is displayed. */
12071 FOR_EACH_FRAME (tail
, frame
)
12073 struct frame
*f
= XFRAME (frame
);
12075 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12077 if (! EQ (frame
, selected_frame
))
12078 /* Select the frame, for the sake of frame-local
12080 select_frame_for_redisplay (frame
);
12082 /* Mark all the scroll bars to be removed; we'll redeem
12083 the ones we want when we redisplay their windows. */
12084 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12085 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12087 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12088 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12090 /* The X error handler may have deleted that frame. */
12091 if (!FRAME_LIVE_P (f
))
12094 /* Any scroll bars which redisplay_windows should have
12095 nuked should now go away. */
12096 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12097 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12099 /* If fonts changed, display again. */
12100 /* ??? rms: I suspect it is a mistake to jump all the way
12101 back to retry here. It should just retry this frame. */
12102 if (fonts_changed_p
)
12105 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12107 /* See if we have to hscroll. */
12108 if (!f
->already_hscrolled_p
)
12110 f
->already_hscrolled_p
= 1;
12111 if (hscroll_windows (f
->root_window
))
12115 /* Prevent various kinds of signals during display
12116 update. stdio is not robust about handling
12117 signals, which can cause an apparent I/O
12119 if (interrupt_input
)
12120 unrequest_sigio ();
12123 /* Update the display. */
12124 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12125 pause
|= update_frame (f
, 0, 0);
12131 if (!EQ (old_frame
, selected_frame
)
12132 && FRAME_LIVE_P (XFRAME (old_frame
)))
12133 /* We played a bit fast-and-loose above and allowed selected_frame
12134 and selected_window to be temporarily out-of-sync but let's make
12135 sure this stays contained. */
12136 select_frame_for_redisplay (old_frame
);
12137 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12141 /* Do the mark_window_display_accurate after all windows have
12142 been redisplayed because this call resets flags in buffers
12143 which are needed for proper redisplay. */
12144 FOR_EACH_FRAME (tail
, frame
)
12146 struct frame
*f
= XFRAME (frame
);
12149 mark_window_display_accurate (f
->root_window
, 1);
12150 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12151 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12156 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12158 Lisp_Object mini_window
;
12159 struct frame
*mini_frame
;
12161 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12162 /* Use list_of_error, not Qerror, so that
12163 we catch only errors and don't run the debugger. */
12164 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12166 redisplay_window_error
);
12168 /* Compare desired and current matrices, perform output. */
12171 /* If fonts changed, display again. */
12172 if (fonts_changed_p
)
12175 /* Prevent various kinds of signals during display update.
12176 stdio is not robust about handling signals,
12177 which can cause an apparent I/O error. */
12178 if (interrupt_input
)
12179 unrequest_sigio ();
12182 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12184 if (hscroll_windows (selected_window
))
12187 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12188 pause
= update_frame (sf
, 0, 0);
12191 /* We may have called echo_area_display at the top of this
12192 function. If the echo area is on another frame, that may
12193 have put text on a frame other than the selected one, so the
12194 above call to update_frame would not have caught it. Catch
12196 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12197 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12199 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12201 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12202 pause
|= update_frame (mini_frame
, 0, 0);
12203 if (!pause
&& hscroll_windows (mini_window
))
12208 /* If display was paused because of pending input, make sure we do a
12209 thorough update the next time. */
12212 /* Prevent the optimization at the beginning of
12213 redisplay_internal that tries a single-line update of the
12214 line containing the cursor in the selected window. */
12215 CHARPOS (this_line_start_pos
) = 0;
12217 /* Let the overlay arrow be updated the next time. */
12218 update_overlay_arrows (0);
12220 /* If we pause after scrolling, some rows in the current
12221 matrices of some windows are not valid. */
12222 if (!WINDOW_FULL_WIDTH_P (w
)
12223 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12224 update_mode_lines
= 1;
12228 if (!consider_all_windows_p
)
12230 /* This has already been done above if
12231 consider_all_windows_p is set. */
12232 mark_window_display_accurate_1 (w
, 1);
12234 /* Say overlay arrows are up to date. */
12235 update_overlay_arrows (1);
12237 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12238 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12241 update_mode_lines
= 0;
12242 windows_or_buffers_changed
= 0;
12243 cursor_type_changed
= 0;
12246 /* Start SIGIO interrupts coming again. Having them off during the
12247 code above makes it less likely one will discard output, but not
12248 impossible, since there might be stuff in the system buffer here.
12249 But it is much hairier to try to do anything about that. */
12250 if (interrupt_input
)
12254 /* If a frame has become visible which was not before, redisplay
12255 again, so that we display it. Expose events for such a frame
12256 (which it gets when becoming visible) don't call the parts of
12257 redisplay constructing glyphs, so simply exposing a frame won't
12258 display anything in this case. So, we have to display these
12259 frames here explicitly. */
12262 Lisp_Object tail
, frame
;
12265 FOR_EACH_FRAME (tail
, frame
)
12267 int this_is_visible
= 0;
12269 if (XFRAME (frame
)->visible
)
12270 this_is_visible
= 1;
12271 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12272 if (XFRAME (frame
)->visible
)
12273 this_is_visible
= 1;
12275 if (this_is_visible
)
12279 if (new_count
!= number_of_visible_frames
)
12280 windows_or_buffers_changed
++;
12283 /* Change frame size now if a change is pending. */
12284 do_pending_window_change (1);
12286 /* If we just did a pending size change, or have additional
12287 visible frames, redisplay again. */
12288 if (windows_or_buffers_changed
&& !pause
)
12291 /* Clear the face cache eventually. */
12292 if (consider_all_windows_p
)
12294 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12296 clear_face_cache (0);
12297 clear_face_cache_count
= 0;
12299 #ifdef HAVE_WINDOW_SYSTEM
12300 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12302 clear_image_caches (Qnil
);
12303 clear_image_cache_count
= 0;
12305 #endif /* HAVE_WINDOW_SYSTEM */
12309 unbind_to (count
, Qnil
);
12314 /* Redisplay, but leave alone any recent echo area message unless
12315 another message has been requested in its place.
12317 This is useful in situations where you need to redisplay but no
12318 user action has occurred, making it inappropriate for the message
12319 area to be cleared. See tracking_off and
12320 wait_reading_process_output for examples of these situations.
12322 FROM_WHERE is an integer saying from where this function was
12323 called. This is useful for debugging. */
12326 redisplay_preserve_echo_area (from_where
)
12329 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12331 if (!NILP (echo_area_buffer
[1]))
12333 /* We have a previously displayed message, but no current
12334 message. Redisplay the previous message. */
12335 display_last_displayed_message_p
= 1;
12336 redisplay_internal (1);
12337 display_last_displayed_message_p
= 0;
12340 redisplay_internal (1);
12342 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12343 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12344 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12348 /* Function registered with record_unwind_protect in
12349 redisplay_internal. Reset redisplaying_p to the value it had
12350 before redisplay_internal was called, and clear
12351 prevent_freeing_realized_faces_p. It also selects the previously
12352 selected frame, unless it has been deleted (by an X connection
12353 failure during redisplay, for example). */
12356 unwind_redisplay (val
)
12359 Lisp_Object old_redisplaying_p
, old_frame
;
12361 old_redisplaying_p
= XCAR (val
);
12362 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12363 old_frame
= XCDR (val
);
12364 if (! EQ (old_frame
, selected_frame
)
12365 && FRAME_LIVE_P (XFRAME (old_frame
)))
12366 select_frame_for_redisplay (old_frame
);
12371 /* Mark the display of window W as accurate or inaccurate. If
12372 ACCURATE_P is non-zero mark display of W as accurate. If
12373 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12374 redisplay_internal is called. */
12377 mark_window_display_accurate_1 (w
, accurate_p
)
12381 if (BUFFERP (w
->buffer
))
12383 struct buffer
*b
= XBUFFER (w
->buffer
);
12386 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12387 w
->last_overlay_modified
12388 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12390 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12394 b
->clip_changed
= 0;
12395 b
->prevent_redisplay_optimizations_p
= 0;
12397 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12398 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12399 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12400 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12402 w
->current_matrix
->buffer
= b
;
12403 w
->current_matrix
->begv
= BUF_BEGV (b
);
12404 w
->current_matrix
->zv
= BUF_ZV (b
);
12406 w
->last_cursor
= w
->cursor
;
12407 w
->last_cursor_off_p
= w
->cursor_off_p
;
12409 if (w
== XWINDOW (selected_window
))
12410 w
->last_point
= make_number (BUF_PT (b
));
12412 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12418 w
->window_end_valid
= w
->buffer
;
12419 w
->update_mode_line
= Qnil
;
12424 /* Mark the display of windows in the window tree rooted at WINDOW as
12425 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12426 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12427 be redisplayed the next time redisplay_internal is called. */
12430 mark_window_display_accurate (window
, accurate_p
)
12431 Lisp_Object window
;
12436 for (; !NILP (window
); window
= w
->next
)
12438 w
= XWINDOW (window
);
12439 mark_window_display_accurate_1 (w
, accurate_p
);
12441 if (!NILP (w
->vchild
))
12442 mark_window_display_accurate (w
->vchild
, accurate_p
);
12443 if (!NILP (w
->hchild
))
12444 mark_window_display_accurate (w
->hchild
, accurate_p
);
12449 update_overlay_arrows (1);
12453 /* Force a thorough redisplay the next time by setting
12454 last_arrow_position and last_arrow_string to t, which is
12455 unequal to any useful value of Voverlay_arrow_... */
12456 update_overlay_arrows (-1);
12461 /* Return value in display table DP (Lisp_Char_Table *) for character
12462 C. Since a display table doesn't have any parent, we don't have to
12463 follow parent. Do not call this function directly but use the
12464 macro DISP_CHAR_VECTOR. */
12467 disp_char_vector (dp
, c
)
12468 struct Lisp_Char_Table
*dp
;
12473 if (ASCII_CHAR_P (c
))
12476 if (SUB_CHAR_TABLE_P (val
))
12477 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12483 XSETCHAR_TABLE (table
, dp
);
12484 val
= char_table_ref (table
, c
);
12493 /***********************************************************************
12495 ***********************************************************************/
12497 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12500 redisplay_windows (window
)
12501 Lisp_Object window
;
12503 while (!NILP (window
))
12505 struct window
*w
= XWINDOW (window
);
12507 if (!NILP (w
->hchild
))
12508 redisplay_windows (w
->hchild
);
12509 else if (!NILP (w
->vchild
))
12510 redisplay_windows (w
->vchild
);
12511 else if (!NILP (w
->buffer
))
12513 displayed_buffer
= XBUFFER (w
->buffer
);
12514 /* Use list_of_error, not Qerror, so that
12515 we catch only errors and don't run the debugger. */
12516 internal_condition_case_1 (redisplay_window_0
, window
,
12518 redisplay_window_error
);
12526 redisplay_window_error ()
12528 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12533 redisplay_window_0 (window
)
12534 Lisp_Object window
;
12536 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12537 redisplay_window (window
, 0);
12542 redisplay_window_1 (window
)
12543 Lisp_Object window
;
12545 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12546 redisplay_window (window
, 1);
12551 /* Increment GLYPH until it reaches END or CONDITION fails while
12552 adding (GLYPH)->pixel_width to X. */
12554 #define SKIP_GLYPHS(glyph, end, x, condition) \
12557 (x) += (glyph)->pixel_width; \
12560 while ((glyph) < (end) && (condition))
12563 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12564 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12565 which positions recorded in ROW differ from current buffer
12568 Return 0 if cursor is not on this row, 1 otherwise. */
12571 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12573 struct glyph_row
*row
;
12574 struct glyph_matrix
*matrix
;
12575 int delta
, delta_bytes
, dy
, dvpos
;
12577 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12578 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12579 struct glyph
*cursor
= NULL
;
12580 /* The last known character position in row. */
12581 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12584 EMACS_INT pt_old
= PT
- delta
;
12585 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12586 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12587 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12588 /* Non-zero means we've found a match for cursor position, but that
12589 glyph has the avoid_cursor_p flag set. */
12590 int match_with_avoid_cursor
= 0;
12591 /* Non-zero means we've seen at least one glyph that came from a
12593 int string_seen
= 0;
12594 /* Largest buffer position seen so far during scan of glyph row. */
12595 EMACS_INT bpos_max
= last_pos
;
12596 /* Last buffer position covered by an overlay string with an integer
12597 `cursor' property. */
12598 EMACS_INT bpos_covered
= 0;
12600 /* Skip over glyphs not having an object at the start and the end of
12601 the row. These are special glyphs like truncation marks on
12602 terminal frames. */
12603 if (row
->displays_text_p
)
12605 if (!row
->reversed_p
)
12608 && INTEGERP (glyph
->object
)
12609 && glyph
->charpos
< 0)
12611 x
+= glyph
->pixel_width
;
12615 && INTEGERP ((end
- 1)->object
)
12616 /* CHARPOS is zero for blanks inserted by
12617 extend_face_to_end_of_line. */
12618 && (end
- 1)->charpos
<= 0)
12620 glyph_before
= glyph
- 1;
12627 /* If the glyph row is reversed, we need to process it from back
12628 to front, so swap the edge pointers. */
12630 glyph
+= row
->used
[TEXT_AREA
] - 1;
12631 /* Reverse the known positions in the row. */
12632 last_pos
= pos_after
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12633 pos_before
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12635 while (glyph
> end
+ 1
12636 && INTEGERP (glyph
->object
)
12637 && glyph
->charpos
< 0)
12640 x
-= glyph
->pixel_width
;
12642 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12644 /* By default, put the cursor on the rightmost glyph. */
12645 for (g
= end
+ 1; g
< glyph
; g
++)
12646 x
+= g
->pixel_width
;
12649 && INTEGERP ((end
+ 1)->object
)
12650 && (end
+ 1)->charpos
<= 0)
12652 glyph_before
= glyph
+ 1;
12656 else if (row
->reversed_p
)
12658 /* In R2L rows that don't display text, put the cursor on the
12659 rightmost glyph. Case in point: an empty last line that is
12660 part of an R2L paragraph. */
12662 x
= -1; /* will be computed below, at lable compute_x */
12665 /* Step 1: Try to find the glyph whose character position
12666 corresponds to point. If that's not possible, find 2 glyphs
12667 whose character positions are the closest to point, one before
12668 point, the other after it. */
12669 if (!row
->reversed_p
)
12670 while (/* not marched to end of glyph row */
12672 /* glyph was not inserted by redisplay for internal purposes */
12673 && !INTEGERP (glyph
->object
))
12675 if (BUFFERP (glyph
->object
))
12677 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12679 if (glyph
->charpos
> bpos_max
)
12680 bpos_max
= glyph
->charpos
;
12681 if (!glyph
->avoid_cursor_p
)
12683 /* If we hit point, we've found the glyph on which to
12684 display the cursor. */
12687 match_with_avoid_cursor
= 0;
12690 /* See if we've found a better approximation to
12691 POS_BEFORE or to POS_AFTER. Note that we want the
12692 first (leftmost) glyph of all those that are the
12693 closest from below, and the last (rightmost) of all
12694 those from above. */
12695 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12697 pos_before
= glyph
->charpos
;
12698 glyph_before
= glyph
;
12700 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12702 pos_after
= glyph
->charpos
;
12703 glyph_after
= glyph
;
12706 else if (dpos
== 0)
12707 match_with_avoid_cursor
= 1;
12709 else if (STRINGP (glyph
->object
))
12711 Lisp_Object chprop
;
12712 int glyph_pos
= glyph
->charpos
;
12714 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12716 if (INTEGERP (chprop
))
12718 bpos_covered
= bpos_max
+ XINT (chprop
);
12719 /* If the `cursor' property covers buffer positions up
12720 to and including point, we should display cursor on
12722 /* Implementation note: bpos_max == pt_old when, e.g.,
12723 we are in an empty line, where bpos_max is set to
12724 MATRIX_ROW_START_CHARPOS, see above. */
12725 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12734 x
+= glyph
->pixel_width
;
12737 else if (glyph
> end
) /* row is reversed */
12738 while (!INTEGERP (glyph
->object
))
12740 if (BUFFERP (glyph
->object
))
12742 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12744 if (glyph
->charpos
> bpos_max
)
12745 bpos_max
= glyph
->charpos
;
12746 if (!glyph
->avoid_cursor_p
)
12750 match_with_avoid_cursor
= 0;
12753 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12755 pos_before
= glyph
->charpos
;
12756 glyph_before
= glyph
;
12758 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12760 pos_after
= glyph
->charpos
;
12761 glyph_after
= glyph
;
12764 else if (dpos
== 0)
12765 match_with_avoid_cursor
= 1;
12767 else if (STRINGP (glyph
->object
))
12769 Lisp_Object chprop
;
12770 int glyph_pos
= glyph
->charpos
;
12772 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12774 if (INTEGERP (chprop
))
12776 bpos_covered
= bpos_max
+ XINT (chprop
);
12777 /* If the `cursor' property covers buffer positions up
12778 to and including point, we should display cursor on
12780 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12791 x
-= glyph
->pixel_width
;
12794 /* Step 2: If we didn't find an exact match for point, we need to
12795 look for a proper place to put the cursor among glyphs between
12796 GLYPH_BEFORE and GLYPH_AFTER. */
12797 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12798 && bpos_covered
< pt_old
)
12800 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12802 EMACS_INT ellipsis_pos
;
12804 /* Scan back over the ellipsis glyphs. */
12805 if (!row
->reversed_p
)
12807 ellipsis_pos
= (glyph
- 1)->charpos
;
12808 while (glyph
> row
->glyphs
[TEXT_AREA
]
12809 && (glyph
- 1)->charpos
== ellipsis_pos
)
12810 glyph
--, x
-= glyph
->pixel_width
;
12811 /* That loop always goes one position too far, including
12812 the glyph before the ellipsis. So scan forward over
12814 x
+= glyph
->pixel_width
;
12817 else /* row is reversed */
12819 ellipsis_pos
= (glyph
+ 1)->charpos
;
12820 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12821 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12822 glyph
++, x
+= glyph
->pixel_width
;
12823 x
-= glyph
->pixel_width
;
12827 else if (match_with_avoid_cursor
12828 /* zero-width characters produce no glyphs */
12829 || eabs (glyph_after
- glyph_before
) == 1)
12831 cursor
= glyph_after
;
12834 else if (string_seen
)
12836 int incr
= row
->reversed_p
? -1 : +1;
12838 /* Need to find the glyph that came out of a string which is
12839 present at point. That glyph is somewhere between
12840 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12841 positioned between POS_BEFORE and POS_AFTER in the
12843 struct glyph
*stop
= glyph_after
;
12844 EMACS_INT pos
= pos_before
;
12847 for (glyph
= glyph_before
+ incr
;
12848 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12851 /* Any glyphs that come from the buffer are here because
12852 of bidi reordering. Skip them, and only pay
12853 attention to glyphs that came from some string. */
12854 if (STRINGP (glyph
->object
))
12859 str
= glyph
->object
;
12860 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12863 /* If the string from which this glyph came is
12864 found in the buffer at point, then we've
12865 found the glyph we've been looking for. */
12868 /* The glyphs from this string could have
12869 been reordered. Find the one with the
12870 smallest string position. Or there could
12871 be a character in the string with the
12872 `cursor' property, which means display
12873 cursor on that character's glyph. */
12874 int strpos
= glyph
->charpos
;
12877 for (glyph
+= incr
;
12878 EQ (glyph
->object
, str
);
12882 int gpos
= glyph
->charpos
;
12884 cprop
= Fget_char_property (make_number (gpos
),
12892 if (glyph
->charpos
< strpos
)
12894 strpos
= glyph
->charpos
;
12901 pos
= tem
+ 1; /* don't find previous instances */
12903 /* This string is not what we want; skip all of the
12904 glyphs that came from it. */
12907 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12908 && EQ (glyph
->object
, str
));
12914 /* If we reached the end of the line, and END was from a string,
12915 the cursor is not on this line. */
12917 && STRINGP ((glyph
- incr
)->object
)
12918 && row
->continued_p
)
12924 if (cursor
!= NULL
)
12930 /* Need to compute x that corresponds to GLYPH. */
12931 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12933 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12935 x
+= g
->pixel_width
;
12939 /* ROW could be part of a continued line, which might have other
12940 rows whose start and end charpos occlude point. Only set
12941 w->cursor if we found a better approximation to the cursor
12942 position than we have from previously examined rows. */
12943 if (w
->cursor
.vpos
>= 0
12944 /* Make sure cursor.vpos specifies a row whose start and end
12945 charpos occlude point. This is because some callers of this
12946 function leave cursor.vpos at the row where the cursor was
12947 displayed during the last redisplay cycle. */
12948 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
12949 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
12952 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
12954 /* Keep the candidate whose buffer position is the closest to
12956 if (BUFFERP (g1
->object
)
12957 && (g1
->charpos
== pt_old
/* an exact match always wins */
12958 || (BUFFERP (glyph
->object
)
12959 && eabs (g1
->charpos
- pt_old
)
12960 < eabs (glyph
->charpos
- pt_old
))))
12962 /* If this candidate gives an exact match, use that. */
12963 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12964 /* Otherwise, keep the candidate that comes from a row
12965 spanning less buffer positions. This may win when one or
12966 both candidate positions are on glyphs that came from
12967 display strings, for which we cannot compare buffer
12969 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12970 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
12971 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
12974 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12976 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12977 w
->cursor
.y
= row
->y
+ dy
;
12979 if (w
== XWINDOW (selected_window
))
12981 if (!row
->continued_p
12982 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12985 this_line_buffer
= XBUFFER (w
->buffer
);
12987 CHARPOS (this_line_start_pos
)
12988 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12989 BYTEPOS (this_line_start_pos
)
12990 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12992 CHARPOS (this_line_end_pos
)
12993 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12994 BYTEPOS (this_line_end_pos
)
12995 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12997 this_line_y
= w
->cursor
.y
;
12998 this_line_pixel_height
= row
->height
;
12999 this_line_vpos
= w
->cursor
.vpos
;
13000 this_line_start_x
= row
->x
;
13003 CHARPOS (this_line_start_pos
) = 0;
13010 /* Run window scroll functions, if any, for WINDOW with new window
13011 start STARTP. Sets the window start of WINDOW to that position.
13013 We assume that the window's buffer is really current. */
13015 static INLINE
struct text_pos
13016 run_window_scroll_functions (window
, startp
)
13017 Lisp_Object window
;
13018 struct text_pos startp
;
13020 struct window
*w
= XWINDOW (window
);
13021 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13023 if (current_buffer
!= XBUFFER (w
->buffer
))
13026 if (!NILP (Vwindow_scroll_functions
))
13028 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13029 make_number (CHARPOS (startp
)));
13030 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13031 /* In case the hook functions switch buffers. */
13032 if (current_buffer
!= XBUFFER (w
->buffer
))
13033 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13040 /* Make sure the line containing the cursor is fully visible.
13041 A value of 1 means there is nothing to be done.
13042 (Either the line is fully visible, or it cannot be made so,
13043 or we cannot tell.)
13045 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13046 is higher than window.
13048 A value of 0 means the caller should do scrolling
13049 as if point had gone off the screen. */
13052 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
13055 int current_matrix_p
;
13057 struct glyph_matrix
*matrix
;
13058 struct glyph_row
*row
;
13061 if (!make_cursor_line_fully_visible_p
)
13064 /* It's not always possible to find the cursor, e.g, when a window
13065 is full of overlay strings. Don't do anything in that case. */
13066 if (w
->cursor
.vpos
< 0)
13069 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13070 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13072 /* If the cursor row is not partially visible, there's nothing to do. */
13073 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13076 /* If the row the cursor is in is taller than the window's height,
13077 it's not clear what to do, so do nothing. */
13078 window_height
= window_box_height (w
);
13079 if (row
->height
>= window_height
)
13081 if (!force_p
|| MINI_WINDOW_P (w
)
13082 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13089 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13090 non-zero means only WINDOW is redisplayed in redisplay_internal.
13091 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13092 in redisplay_window to bring a partially visible line into view in
13093 the case that only the cursor has moved.
13095 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13096 last screen line's vertical height extends past the end of the screen.
13100 1 if scrolling succeeded
13102 0 if scrolling didn't find point.
13104 -1 if new fonts have been loaded so that we must interrupt
13105 redisplay, adjust glyph matrices, and try again. */
13111 SCROLLING_NEED_LARGER_MATRICES
13115 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
13116 scroll_step
, temp_scroll_step
, last_line_misfit
)
13117 Lisp_Object window
;
13118 int just_this_one_p
;
13119 EMACS_INT scroll_conservatively
, scroll_step
;
13120 int temp_scroll_step
;
13121 int last_line_misfit
;
13123 struct window
*w
= XWINDOW (window
);
13124 struct frame
*f
= XFRAME (w
->frame
);
13125 struct text_pos pos
, startp
;
13127 int this_scroll_margin
, scroll_max
, rc
, height
;
13128 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13129 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13130 Lisp_Object aggressive
;
13131 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13134 debug_method_add (w
, "try_scrolling");
13137 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13139 /* Compute scroll margin height in pixels. We scroll when point is
13140 within this distance from the top or bottom of the window. */
13141 if (scroll_margin
> 0)
13142 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13143 * FRAME_LINE_HEIGHT (f
);
13145 this_scroll_margin
= 0;
13147 /* Force scroll_conservatively to have a reasonable value, to avoid
13148 overflow while computing how much to scroll. Note that the user
13149 can supply scroll-conservatively equal to `most-positive-fixnum',
13150 which can be larger than INT_MAX. */
13151 if (scroll_conservatively
> scroll_limit
)
13153 scroll_conservatively
= scroll_limit
;
13154 scroll_max
= INT_MAX
;
13156 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13157 /* Compute how much we should try to scroll maximally to bring
13158 point into view. */
13159 scroll_max
= (max (scroll_step
,
13160 max (scroll_conservatively
, temp_scroll_step
))
13161 * FRAME_LINE_HEIGHT (f
));
13162 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13163 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13164 /* We're trying to scroll because of aggressive scrolling but no
13165 scroll_step is set. Choose an arbitrary one. */
13166 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13172 /* Decide whether to scroll down. */
13173 if (PT
> CHARPOS (startp
))
13175 int scroll_margin_y
;
13177 /* Compute the pixel ypos of the scroll margin, then move it to
13178 either that ypos or PT, whichever comes first. */
13179 start_display (&it
, w
, startp
);
13180 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13181 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13182 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13183 (MOVE_TO_POS
| MOVE_TO_Y
));
13185 if (PT
> CHARPOS (it
.current
.pos
))
13187 int y0
= line_bottom_y (&it
);
13189 /* Compute the distance from the scroll margin to PT
13190 (including the height of the cursor line). Moving the
13191 iterator unconditionally to PT can be slow if PT is far
13192 away, so stop 10 lines past the window bottom (is there a
13193 way to do the right thing quickly?). */
13194 move_it_to (&it
, PT
, -1,
13195 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
13196 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13197 dy
= line_bottom_y (&it
) - y0
;
13199 if (dy
> scroll_max
)
13200 return SCROLLING_FAILED
;
13208 /* Point is in or below the bottom scroll margin, so move the
13209 window start down. If scrolling conservatively, move it just
13210 enough down to make point visible. If scroll_step is set,
13211 move it down by scroll_step. */
13212 if (scroll_conservatively
)
13214 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13215 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13216 else if (scroll_step
|| temp_scroll_step
)
13217 amount_to_scroll
= scroll_max
;
13220 aggressive
= current_buffer
->scroll_up_aggressively
;
13221 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13222 if (NUMBERP (aggressive
))
13224 double float_amount
= XFLOATINT (aggressive
) * height
;
13225 amount_to_scroll
= float_amount
;
13226 if (amount_to_scroll
== 0 && float_amount
> 0)
13227 amount_to_scroll
= 1;
13231 if (amount_to_scroll
<= 0)
13232 return SCROLLING_FAILED
;
13234 start_display (&it
, w
, startp
);
13235 move_it_vertically (&it
, amount_to_scroll
);
13237 /* If STARTP is unchanged, move it down another screen line. */
13238 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13239 move_it_by_lines (&it
, 1, 1);
13240 startp
= it
.current
.pos
;
13244 struct text_pos scroll_margin_pos
= startp
;
13246 /* See if point is inside the scroll margin at the top of the
13248 if (this_scroll_margin
)
13250 start_display (&it
, w
, startp
);
13251 move_it_vertically (&it
, this_scroll_margin
);
13252 scroll_margin_pos
= it
.current
.pos
;
13255 if (PT
< CHARPOS (scroll_margin_pos
))
13257 /* Point is in the scroll margin at the top of the window or
13258 above what is displayed in the window. */
13261 /* Compute the vertical distance from PT to the scroll
13262 margin position. Give up if distance is greater than
13264 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13265 start_display (&it
, w
, pos
);
13267 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13268 it
.last_visible_y
, -1,
13269 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13270 dy
= it
.current_y
- y0
;
13271 if (dy
> scroll_max
)
13272 return SCROLLING_FAILED
;
13274 /* Compute new window start. */
13275 start_display (&it
, w
, startp
);
13277 if (scroll_conservatively
)
13279 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13280 else if (scroll_step
|| temp_scroll_step
)
13281 amount_to_scroll
= scroll_max
;
13284 aggressive
= current_buffer
->scroll_down_aggressively
;
13285 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13286 if (NUMBERP (aggressive
))
13288 double float_amount
= XFLOATINT (aggressive
) * height
;
13289 amount_to_scroll
= float_amount
;
13290 if (amount_to_scroll
== 0 && float_amount
> 0)
13291 amount_to_scroll
= 1;
13295 if (amount_to_scroll
<= 0)
13296 return SCROLLING_FAILED
;
13298 move_it_vertically_backward (&it
, amount_to_scroll
);
13299 startp
= it
.current
.pos
;
13303 /* Run window scroll functions. */
13304 startp
= run_window_scroll_functions (window
, startp
);
13306 /* Display the window. Give up if new fonts are loaded, or if point
13308 if (!try_window (window
, startp
, 0))
13309 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13310 else if (w
->cursor
.vpos
< 0)
13312 clear_glyph_matrix (w
->desired_matrix
);
13313 rc
= SCROLLING_FAILED
;
13317 /* Maybe forget recorded base line for line number display. */
13318 if (!just_this_one_p
13319 || current_buffer
->clip_changed
13320 || BEG_UNCHANGED
< CHARPOS (startp
))
13321 w
->base_line_number
= Qnil
;
13323 /* If cursor ends up on a partially visible line,
13324 treat that as being off the bottom of the screen. */
13325 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13327 clear_glyph_matrix (w
->desired_matrix
);
13328 ++extra_scroll_margin_lines
;
13331 rc
= SCROLLING_SUCCESS
;
13338 /* Compute a suitable window start for window W if display of W starts
13339 on a continuation line. Value is non-zero if a new window start
13342 The new window start will be computed, based on W's width, starting
13343 from the start of the continued line. It is the start of the
13344 screen line with the minimum distance from the old start W->start. */
13347 compute_window_start_on_continuation_line (w
)
13350 struct text_pos pos
, start_pos
;
13351 int window_start_changed_p
= 0;
13353 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13355 /* If window start is on a continuation line... Window start may be
13356 < BEGV in case there's invisible text at the start of the
13357 buffer (M-x rmail, for example). */
13358 if (CHARPOS (start_pos
) > BEGV
13359 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13362 struct glyph_row
*row
;
13364 /* Handle the case that the window start is out of range. */
13365 if (CHARPOS (start_pos
) < BEGV
)
13366 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13367 else if (CHARPOS (start_pos
) > ZV
)
13368 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13370 /* Find the start of the continued line. This should be fast
13371 because scan_buffer is fast (newline cache). */
13372 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13373 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13374 row
, DEFAULT_FACE_ID
);
13375 reseat_at_previous_visible_line_start (&it
);
13377 /* If the line start is "too far" away from the window start,
13378 say it takes too much time to compute a new window start. */
13379 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13380 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13382 int min_distance
, distance
;
13384 /* Move forward by display lines to find the new window
13385 start. If window width was enlarged, the new start can
13386 be expected to be > the old start. If window width was
13387 decreased, the new window start will be < the old start.
13388 So, we're looking for the display line start with the
13389 minimum distance from the old window start. */
13390 pos
= it
.current
.pos
;
13391 min_distance
= INFINITY
;
13392 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13393 distance
< min_distance
)
13395 min_distance
= distance
;
13396 pos
= it
.current
.pos
;
13397 move_it_by_lines (&it
, 1, 0);
13400 /* Set the window start there. */
13401 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13402 window_start_changed_p
= 1;
13406 return window_start_changed_p
;
13410 /* Try cursor movement in case text has not changed in window WINDOW,
13411 with window start STARTP. Value is
13413 CURSOR_MOVEMENT_SUCCESS if successful
13415 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13417 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13418 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13419 we want to scroll as if scroll-step were set to 1. See the code.
13421 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13422 which case we have to abort this redisplay, and adjust matrices
13427 CURSOR_MOVEMENT_SUCCESS
,
13428 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13429 CURSOR_MOVEMENT_MUST_SCROLL
,
13430 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13434 try_cursor_movement (window
, startp
, scroll_step
)
13435 Lisp_Object window
;
13436 struct text_pos startp
;
13439 struct window
*w
= XWINDOW (window
);
13440 struct frame
*f
= XFRAME (w
->frame
);
13441 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13444 if (inhibit_try_cursor_movement
)
13448 /* Handle case where text has not changed, only point, and it has
13449 not moved off the frame. */
13450 if (/* Point may be in this window. */
13451 PT
>= CHARPOS (startp
)
13452 /* Selective display hasn't changed. */
13453 && !current_buffer
->clip_changed
13454 /* Function force-mode-line-update is used to force a thorough
13455 redisplay. It sets either windows_or_buffers_changed or
13456 update_mode_lines. So don't take a shortcut here for these
13458 && !update_mode_lines
13459 && !windows_or_buffers_changed
13460 && !cursor_type_changed
13461 /* Can't use this case if highlighting a region. When a
13462 region exists, cursor movement has to do more than just
13464 && !(!NILP (Vtransient_mark_mode
)
13465 && !NILP (current_buffer
->mark_active
))
13466 && NILP (w
->region_showing
)
13467 && NILP (Vshow_trailing_whitespace
)
13468 /* Right after splitting windows, last_point may be nil. */
13469 && INTEGERP (w
->last_point
)
13470 /* This code is not used for mini-buffer for the sake of the case
13471 of redisplaying to replace an echo area message; since in
13472 that case the mini-buffer contents per se are usually
13473 unchanged. This code is of no real use in the mini-buffer
13474 since the handling of this_line_start_pos, etc., in redisplay
13475 handles the same cases. */
13476 && !EQ (window
, minibuf_window
)
13477 /* When splitting windows or for new windows, it happens that
13478 redisplay is called with a nil window_end_vpos or one being
13479 larger than the window. This should really be fixed in
13480 window.c. I don't have this on my list, now, so we do
13481 approximately the same as the old redisplay code. --gerd. */
13482 && INTEGERP (w
->window_end_vpos
)
13483 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13484 && (FRAME_WINDOW_P (f
)
13485 || !overlay_arrow_in_current_buffer_p ()))
13487 int this_scroll_margin
, top_scroll_margin
;
13488 struct glyph_row
*row
= NULL
;
13491 debug_method_add (w
, "cursor movement");
13494 /* Scroll if point within this distance from the top or bottom
13495 of the window. This is a pixel value. */
13496 if (scroll_margin
> 0)
13498 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13499 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13502 this_scroll_margin
= 0;
13504 top_scroll_margin
= this_scroll_margin
;
13505 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13506 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13508 /* Start with the row the cursor was displayed during the last
13509 not paused redisplay. Give up if that row is not valid. */
13510 if (w
->last_cursor
.vpos
< 0
13511 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13512 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13515 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13516 if (row
->mode_line_p
)
13518 if (!row
->enabled_p
)
13519 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13520 /* If rows are bidi-reordered, back up until we find a row
13521 that does not belong to a continuation line. This is
13522 because we must consider all rows of a continued line as
13523 candidates for cursor positioning, since row start and
13524 end positions change non-linearly with vertical position
13526 /* FIXME: Revisit this when glyph ``spilling'' in
13527 continuation lines' rows is implemented for
13528 bidi-reordered rows. */
13529 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13531 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13533 xassert (row
->enabled_p
);
13535 /* If we hit the beginning of the displayed portion
13536 without finding the first row of a continued
13538 if (row
<= w
->current_matrix
->rows
)
13540 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13548 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13551 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13553 if (PT
> XFASTINT (w
->last_point
))
13555 /* Point has moved forward. */
13556 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13557 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13559 xassert (row
->enabled_p
);
13563 /* The end position of a row equals the start position
13564 of the next row. If PT is there, we would rather
13565 display it in the next line. */
13566 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13567 && MATRIX_ROW_END_CHARPOS (row
) == PT
13568 && !cursor_row_p (w
, row
))
13571 /* If within the scroll margin, scroll. Note that
13572 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13573 the next line would be drawn, and that
13574 this_scroll_margin can be zero. */
13575 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13576 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13577 /* Line is completely visible last line in window
13578 and PT is to be set in the next line. */
13579 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13580 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13581 && !row
->ends_at_zv_p
13582 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13585 else if (PT
< XFASTINT (w
->last_point
))
13587 /* Cursor has to be moved backward. Note that PT >=
13588 CHARPOS (startp) because of the outer if-statement. */
13589 while (!row
->mode_line_p
13590 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13591 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13592 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13593 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13594 row
> w
->current_matrix
->rows
13595 && (row
-1)->ends_in_newline_from_string_p
))))
13596 && (row
->y
> top_scroll_margin
13597 || CHARPOS (startp
) == BEGV
))
13599 xassert (row
->enabled_p
);
13603 /* Consider the following case: Window starts at BEGV,
13604 there is invisible, intangible text at BEGV, so that
13605 display starts at some point START > BEGV. It can
13606 happen that we are called with PT somewhere between
13607 BEGV and START. Try to handle that case. */
13608 if (row
< w
->current_matrix
->rows
13609 || row
->mode_line_p
)
13611 row
= w
->current_matrix
->rows
;
13612 if (row
->mode_line_p
)
13616 /* Due to newlines in overlay strings, we may have to
13617 skip forward over overlay strings. */
13618 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13619 && MATRIX_ROW_END_CHARPOS (row
) == PT
13620 && !cursor_row_p (w
, row
))
13623 /* If within the scroll margin, scroll. */
13624 if (row
->y
< top_scroll_margin
13625 && CHARPOS (startp
) != BEGV
)
13630 /* Cursor did not move. So don't scroll even if cursor line
13631 is partially visible, as it was so before. */
13632 rc
= CURSOR_MOVEMENT_SUCCESS
;
13635 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13636 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13638 /* if PT is not in the glyph row, give up. */
13639 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13641 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13642 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13643 && make_cursor_line_fully_visible_p
)
13645 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13646 && !row
->ends_at_zv_p
13647 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13648 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13649 else if (row
->height
> window_box_height (w
))
13651 /* If we end up in a partially visible line, let's
13652 make it fully visible, except when it's taller
13653 than the window, in which case we can't do much
13656 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13660 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13661 if (!cursor_row_fully_visible_p (w
, 0, 1))
13662 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13664 rc
= CURSOR_MOVEMENT_SUCCESS
;
13668 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13669 else if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13671 /* With bidi-reordered rows, there could be more than
13672 one candidate row whose start and end positions
13673 occlude point. We need to let set_cursor_from_row
13674 find the best candidate. */
13675 /* FIXME: Revisit this when glyph ``spilling'' in
13676 continuation lines' rows is implemented for
13677 bidi-reordered rows. */
13682 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13684 /* As soon as we've found the first suitable row
13685 whose ends_at_zv_p flag is set, we are done. */
13687 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13689 rc
= CURSOR_MOVEMENT_SUCCESS
;
13694 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13695 && MATRIX_ROW_START_CHARPOS (row
) <= PT
13696 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13697 && cursor_row_p (w
, row
));
13698 /* If we didn't find any candidate rows, or exited the
13699 loop before all the candidates were examined, signal
13700 to the caller that this method failed. */
13701 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13703 || (MATRIX_ROW_START_CHARPOS (row
) <= PT
13704 && PT
<= MATRIX_ROW_END_CHARPOS (row
))))
13705 rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13707 rc
= CURSOR_MOVEMENT_SUCCESS
;
13713 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13715 rc
= CURSOR_MOVEMENT_SUCCESS
;
13720 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13721 && MATRIX_ROW_START_CHARPOS (row
) == PT
13722 && cursor_row_p (w
, row
));
13731 set_vertical_scroll_bar (w
)
13734 int start
, end
, whole
;
13736 /* Calculate the start and end positions for the current window.
13737 At some point, it would be nice to choose between scrollbars
13738 which reflect the whole buffer size, with special markers
13739 indicating narrowing, and scrollbars which reflect only the
13742 Note that mini-buffers sometimes aren't displaying any text. */
13743 if (!MINI_WINDOW_P (w
)
13744 || (w
== XWINDOW (minibuf_window
)
13745 && NILP (echo_area_buffer
[0])))
13747 struct buffer
*buf
= XBUFFER (w
->buffer
);
13748 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13749 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13750 /* I don't think this is guaranteed to be right. For the
13751 moment, we'll pretend it is. */
13752 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13756 if (whole
< (end
- start
))
13757 whole
= end
- start
;
13760 start
= end
= whole
= 0;
13762 /* Indicate what this scroll bar ought to be displaying now. */
13763 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13764 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13765 (w
, end
- start
, whole
, start
);
13769 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13770 selected_window is redisplayed.
13772 We can return without actually redisplaying the window if
13773 fonts_changed_p is nonzero. In that case, redisplay_internal will
13777 redisplay_window (window
, just_this_one_p
)
13778 Lisp_Object window
;
13779 int just_this_one_p
;
13781 struct window
*w
= XWINDOW (window
);
13782 struct frame
*f
= XFRAME (w
->frame
);
13783 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13784 struct buffer
*old
= current_buffer
;
13785 struct text_pos lpoint
, opoint
, startp
;
13786 int update_mode_line
;
13789 /* Record it now because it's overwritten. */
13790 int current_matrix_up_to_date_p
= 0;
13791 int used_current_matrix_p
= 0;
13792 /* This is less strict than current_matrix_up_to_date_p.
13793 It indictes that the buffer contents and narrowing are unchanged. */
13794 int buffer_unchanged_p
= 0;
13795 int temp_scroll_step
= 0;
13796 int count
= SPECPDL_INDEX ();
13798 int centering_position
= -1;
13799 int last_line_misfit
= 0;
13800 int beg_unchanged
, end_unchanged
;
13802 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13805 /* W must be a leaf window here. */
13806 xassert (!NILP (w
->buffer
));
13808 *w
->desired_matrix
->method
= 0;
13812 reconsider_clip_changes (w
, buffer
);
13814 /* Has the mode line to be updated? */
13815 update_mode_line
= (!NILP (w
->update_mode_line
)
13816 || update_mode_lines
13817 || buffer
->clip_changed
13818 || buffer
->prevent_redisplay_optimizations_p
);
13820 if (MINI_WINDOW_P (w
))
13822 if (w
== XWINDOW (echo_area_window
)
13823 && !NILP (echo_area_buffer
[0]))
13825 if (update_mode_line
)
13826 /* We may have to update a tty frame's menu bar or a
13827 tool-bar. Example `M-x C-h C-h C-g'. */
13828 goto finish_menu_bars
;
13830 /* We've already displayed the echo area glyphs in this window. */
13831 goto finish_scroll_bars
;
13833 else if ((w
!= XWINDOW (minibuf_window
)
13834 || minibuf_level
== 0)
13835 /* When buffer is nonempty, redisplay window normally. */
13836 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13837 /* Quail displays non-mini buffers in minibuffer window.
13838 In that case, redisplay the window normally. */
13839 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13841 /* W is a mini-buffer window, but it's not active, so clear
13843 int yb
= window_text_bottom_y (w
);
13844 struct glyph_row
*row
;
13847 for (y
= 0, row
= w
->desired_matrix
->rows
;
13849 y
+= row
->height
, ++row
)
13850 blank_row (w
, row
, y
);
13851 goto finish_scroll_bars
;
13854 clear_glyph_matrix (w
->desired_matrix
);
13857 /* Otherwise set up data on this window; select its buffer and point
13859 /* Really select the buffer, for the sake of buffer-local
13861 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13863 current_matrix_up_to_date_p
13864 = (!NILP (w
->window_end_valid
)
13865 && !current_buffer
->clip_changed
13866 && !current_buffer
->prevent_redisplay_optimizations_p
13867 && XFASTINT (w
->last_modified
) >= MODIFF
13868 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13870 /* Run the window-bottom-change-functions
13871 if it is possible that the text on the screen has changed
13872 (either due to modification of the text, or any other reason). */
13873 if (!current_matrix_up_to_date_p
13874 && !NILP (Vwindow_text_change_functions
))
13876 safe_run_hooks (Qwindow_text_change_functions
);
13880 beg_unchanged
= BEG_UNCHANGED
;
13881 end_unchanged
= END_UNCHANGED
;
13883 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13885 specbind (Qinhibit_point_motion_hooks
, Qt
);
13888 = (!NILP (w
->window_end_valid
)
13889 && !current_buffer
->clip_changed
13890 && XFASTINT (w
->last_modified
) >= MODIFF
13891 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13893 /* When windows_or_buffers_changed is non-zero, we can't rely on
13894 the window end being valid, so set it to nil there. */
13895 if (windows_or_buffers_changed
)
13897 /* If window starts on a continuation line, maybe adjust the
13898 window start in case the window's width changed. */
13899 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13900 compute_window_start_on_continuation_line (w
);
13902 w
->window_end_valid
= Qnil
;
13905 /* Some sanity checks. */
13906 CHECK_WINDOW_END (w
);
13907 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13909 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13912 /* If %c is in mode line, update it if needed. */
13913 if (!NILP (w
->column_number_displayed
)
13914 /* This alternative quickly identifies a common case
13915 where no change is needed. */
13916 && !(PT
== XFASTINT (w
->last_point
)
13917 && XFASTINT (w
->last_modified
) >= MODIFF
13918 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13919 && (XFASTINT (w
->column_number_displayed
)
13920 != (int) current_column ())) /* iftc */
13921 update_mode_line
= 1;
13923 /* Count number of windows showing the selected buffer. An indirect
13924 buffer counts as its base buffer. */
13925 if (!just_this_one_p
)
13927 struct buffer
*current_base
, *window_base
;
13928 current_base
= current_buffer
;
13929 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13930 if (current_base
->base_buffer
)
13931 current_base
= current_base
->base_buffer
;
13932 if (window_base
->base_buffer
)
13933 window_base
= window_base
->base_buffer
;
13934 if (current_base
== window_base
)
13938 /* Point refers normally to the selected window. For any other
13939 window, set up appropriate value. */
13940 if (!EQ (window
, selected_window
))
13942 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13943 int new_pt_byte
= marker_byte_position (w
->pointm
);
13947 new_pt_byte
= BEGV_BYTE
;
13948 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13950 else if (new_pt
> (ZV
- 1))
13953 new_pt_byte
= ZV_BYTE
;
13954 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13957 /* We don't use SET_PT so that the point-motion hooks don't run. */
13958 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13961 /* If any of the character widths specified in the display table
13962 have changed, invalidate the width run cache. It's true that
13963 this may be a bit late to catch such changes, but the rest of
13964 redisplay goes (non-fatally) haywire when the display table is
13965 changed, so why should we worry about doing any better? */
13966 if (current_buffer
->width_run_cache
)
13968 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13970 if (! disptab_matches_widthtab (disptab
,
13971 XVECTOR (current_buffer
->width_table
)))
13973 invalidate_region_cache (current_buffer
,
13974 current_buffer
->width_run_cache
,
13976 recompute_width_table (current_buffer
, disptab
);
13980 /* If window-start is screwed up, choose a new one. */
13981 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13984 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13986 /* If someone specified a new starting point but did not insist,
13987 check whether it can be used. */
13988 if (!NILP (w
->optional_new_start
)
13989 && CHARPOS (startp
) >= BEGV
13990 && CHARPOS (startp
) <= ZV
)
13992 w
->optional_new_start
= Qnil
;
13993 start_display (&it
, w
, startp
);
13994 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13995 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13996 if (IT_CHARPOS (it
) == PT
)
13997 w
->force_start
= Qt
;
13998 /* IT may overshoot PT if text at PT is invisible. */
13999 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14000 w
->force_start
= Qt
;
14005 /* Handle case where place to start displaying has been specified,
14006 unless the specified location is outside the accessible range. */
14007 if (!NILP (w
->force_start
)
14008 || w
->frozen_window_start_p
)
14010 /* We set this later on if we have to adjust point. */
14013 w
->force_start
= Qnil
;
14015 w
->window_end_valid
= Qnil
;
14017 /* Forget any recorded base line for line number display. */
14018 if (!buffer_unchanged_p
)
14019 w
->base_line_number
= Qnil
;
14021 /* Redisplay the mode line. Select the buffer properly for that.
14022 Also, run the hook window-scroll-functions
14023 because we have scrolled. */
14024 /* Note, we do this after clearing force_start because
14025 if there's an error, it is better to forget about force_start
14026 than to get into an infinite loop calling the hook functions
14027 and having them get more errors. */
14028 if (!update_mode_line
14029 || ! NILP (Vwindow_scroll_functions
))
14031 update_mode_line
= 1;
14032 w
->update_mode_line
= Qt
;
14033 startp
= run_window_scroll_functions (window
, startp
);
14036 w
->last_modified
= make_number (0);
14037 w
->last_overlay_modified
= make_number (0);
14038 if (CHARPOS (startp
) < BEGV
)
14039 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14040 else if (CHARPOS (startp
) > ZV
)
14041 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14043 /* Redisplay, then check if cursor has been set during the
14044 redisplay. Give up if new fonts were loaded. */
14045 /* We used to issue a CHECK_MARGINS argument to try_window here,
14046 but this causes scrolling to fail when point begins inside
14047 the scroll margin (bug#148) -- cyd */
14048 if (!try_window (window
, startp
, 0))
14050 w
->force_start
= Qt
;
14051 clear_glyph_matrix (w
->desired_matrix
);
14052 goto need_larger_matrices
;
14055 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14057 /* If point does not appear, try to move point so it does
14058 appear. The desired matrix has been built above, so we
14059 can use it here. */
14060 new_vpos
= window_box_height (w
) / 2;
14063 if (!cursor_row_fully_visible_p (w
, 0, 0))
14065 /* Point does appear, but on a line partly visible at end of window.
14066 Move it back to a fully-visible line. */
14067 new_vpos
= window_box_height (w
);
14070 /* If we need to move point for either of the above reasons,
14071 now actually do it. */
14074 struct glyph_row
*row
;
14076 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14077 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14080 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14081 MATRIX_ROW_START_BYTEPOS (row
));
14083 if (w
!= XWINDOW (selected_window
))
14084 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14085 else if (current_buffer
== old
)
14086 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14088 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14090 /* If we are highlighting the region, then we just changed
14091 the region, so redisplay to show it. */
14092 if (!NILP (Vtransient_mark_mode
)
14093 && !NILP (current_buffer
->mark_active
))
14095 clear_glyph_matrix (w
->desired_matrix
);
14096 if (!try_window (window
, startp
, 0))
14097 goto need_larger_matrices
;
14102 debug_method_add (w
, "forced window start");
14107 /* Handle case where text has not changed, only point, and it has
14108 not moved off the frame, and we are not retrying after hscroll.
14109 (current_matrix_up_to_date_p is nonzero when retrying.) */
14110 if (current_matrix_up_to_date_p
14111 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14112 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14116 case CURSOR_MOVEMENT_SUCCESS
:
14117 used_current_matrix_p
= 1;
14120 case CURSOR_MOVEMENT_MUST_SCROLL
:
14121 goto try_to_scroll
;
14127 /* If current starting point was originally the beginning of a line
14128 but no longer is, find a new starting point. */
14129 else if (!NILP (w
->start_at_line_beg
)
14130 && !(CHARPOS (startp
) <= BEGV
14131 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14134 debug_method_add (w
, "recenter 1");
14139 /* Try scrolling with try_window_id. Value is > 0 if update has
14140 been done, it is -1 if we know that the same window start will
14141 not work. It is 0 if unsuccessful for some other reason. */
14142 else if ((tem
= try_window_id (w
)) != 0)
14145 debug_method_add (w
, "try_window_id %d", tem
);
14148 if (fonts_changed_p
)
14149 goto need_larger_matrices
;
14153 /* Otherwise try_window_id has returned -1 which means that we
14154 don't want the alternative below this comment to execute. */
14156 else if (CHARPOS (startp
) >= BEGV
14157 && CHARPOS (startp
) <= ZV
14158 && PT
>= CHARPOS (startp
)
14159 && (CHARPOS (startp
) < ZV
14160 /* Avoid starting at end of buffer. */
14161 || CHARPOS (startp
) == BEGV
14162 || (XFASTINT (w
->last_modified
) >= MODIFF
14163 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14166 /* If first window line is a continuation line, and window start
14167 is inside the modified region, but the first change is before
14168 current window start, we must select a new window start.
14170 However, if this is the result of a down-mouse event (e.g. by
14171 extending the mouse-drag-overlay), we don't want to select a
14172 new window start, since that would change the position under
14173 the mouse, resulting in an unwanted mouse-movement rather
14174 than a simple mouse-click. */
14175 if (NILP (w
->start_at_line_beg
)
14176 && NILP (do_mouse_tracking
)
14177 && CHARPOS (startp
) > BEGV
14178 && CHARPOS (startp
) > BEG
+ beg_unchanged
14179 && CHARPOS (startp
) <= Z
- end_unchanged
14180 /* Even if w->start_at_line_beg is nil, a new window may
14181 start at a line_beg, since that's how set_buffer_window
14182 sets it. So, we need to check the return value of
14183 compute_window_start_on_continuation_line. (See also
14185 && XMARKER (w
->start
)->buffer
== current_buffer
14186 && compute_window_start_on_continuation_line (w
))
14188 w
->force_start
= Qt
;
14189 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14194 debug_method_add (w
, "same window start");
14197 /* Try to redisplay starting at same place as before.
14198 If point has not moved off frame, accept the results. */
14199 if (!current_matrix_up_to_date_p
14200 /* Don't use try_window_reusing_current_matrix in this case
14201 because a window scroll function can have changed the
14203 || !NILP (Vwindow_scroll_functions
)
14204 || MINI_WINDOW_P (w
)
14205 || !(used_current_matrix_p
14206 = try_window_reusing_current_matrix (w
)))
14208 IF_DEBUG (debug_method_add (w
, "1"));
14209 if (try_window (window
, startp
, 1) < 0)
14210 /* -1 means we need to scroll.
14211 0 means we need new matrices, but fonts_changed_p
14212 is set in that case, so we will detect it below. */
14213 goto try_to_scroll
;
14216 if (fonts_changed_p
)
14217 goto need_larger_matrices
;
14219 if (w
->cursor
.vpos
>= 0)
14221 if (!just_this_one_p
14222 || current_buffer
->clip_changed
14223 || BEG_UNCHANGED
< CHARPOS (startp
))
14224 /* Forget any recorded base line for line number display. */
14225 w
->base_line_number
= Qnil
;
14227 if (!cursor_row_fully_visible_p (w
, 1, 0))
14229 clear_glyph_matrix (w
->desired_matrix
);
14230 last_line_misfit
= 1;
14232 /* Drop through and scroll. */
14237 clear_glyph_matrix (w
->desired_matrix
);
14242 w
->last_modified
= make_number (0);
14243 w
->last_overlay_modified
= make_number (0);
14245 /* Redisplay the mode line. Select the buffer properly for that. */
14246 if (!update_mode_line
)
14248 update_mode_line
= 1;
14249 w
->update_mode_line
= Qt
;
14252 /* Try to scroll by specified few lines. */
14253 if ((scroll_conservatively
14255 || temp_scroll_step
14256 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14257 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14258 && !current_buffer
->clip_changed
14259 && CHARPOS (startp
) >= BEGV
14260 && CHARPOS (startp
) <= ZV
)
14262 /* The function returns -1 if new fonts were loaded, 1 if
14263 successful, 0 if not successful. */
14264 int rc
= try_scrolling (window
, just_this_one_p
,
14265 scroll_conservatively
,
14267 temp_scroll_step
, last_line_misfit
);
14270 case SCROLLING_SUCCESS
:
14273 case SCROLLING_NEED_LARGER_MATRICES
:
14274 goto need_larger_matrices
;
14276 case SCROLLING_FAILED
:
14284 /* Finally, just choose place to start which centers point */
14287 if (centering_position
< 0)
14288 centering_position
= window_box_height (w
) / 2;
14291 debug_method_add (w
, "recenter");
14294 /* w->vscroll = 0; */
14296 /* Forget any previously recorded base line for line number display. */
14297 if (!buffer_unchanged_p
)
14298 w
->base_line_number
= Qnil
;
14300 /* Move backward half the height of the window. */
14301 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14302 it
.current_y
= it
.last_visible_y
;
14303 move_it_vertically_backward (&it
, centering_position
);
14304 xassert (IT_CHARPOS (it
) >= BEGV
);
14306 /* The function move_it_vertically_backward may move over more
14307 than the specified y-distance. If it->w is small, e.g. a
14308 mini-buffer window, we may end up in front of the window's
14309 display area. Start displaying at the start of the line
14310 containing PT in this case. */
14311 if (it
.current_y
<= 0)
14313 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14314 move_it_vertically_backward (&it
, 0);
14318 it
.current_x
= it
.hpos
= 0;
14320 /* Set startp here explicitly in case that helps avoid an infinite loop
14321 in case the window-scroll-functions functions get errors. */
14322 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14324 /* Run scroll hooks. */
14325 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14327 /* Redisplay the window. */
14328 if (!current_matrix_up_to_date_p
14329 || windows_or_buffers_changed
14330 || cursor_type_changed
14331 /* Don't use try_window_reusing_current_matrix in this case
14332 because it can have changed the buffer. */
14333 || !NILP (Vwindow_scroll_functions
)
14334 || !just_this_one_p
14335 || MINI_WINDOW_P (w
)
14336 || !(used_current_matrix_p
14337 = try_window_reusing_current_matrix (w
)))
14338 try_window (window
, startp
, 0);
14340 /* If new fonts have been loaded (due to fontsets), give up. We
14341 have to start a new redisplay since we need to re-adjust glyph
14343 if (fonts_changed_p
)
14344 goto need_larger_matrices
;
14346 /* If cursor did not appear assume that the middle of the window is
14347 in the first line of the window. Do it again with the next line.
14348 (Imagine a window of height 100, displaying two lines of height
14349 60. Moving back 50 from it->last_visible_y will end in the first
14351 if (w
->cursor
.vpos
< 0)
14353 if (!NILP (w
->window_end_valid
)
14354 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14356 clear_glyph_matrix (w
->desired_matrix
);
14357 move_it_by_lines (&it
, 1, 0);
14358 try_window (window
, it
.current
.pos
, 0);
14360 else if (PT
< IT_CHARPOS (it
))
14362 clear_glyph_matrix (w
->desired_matrix
);
14363 move_it_by_lines (&it
, -1, 0);
14364 try_window (window
, it
.current
.pos
, 0);
14368 /* Not much we can do about it. */
14372 /* Consider the following case: Window starts at BEGV, there is
14373 invisible, intangible text at BEGV, so that display starts at
14374 some point START > BEGV. It can happen that we are called with
14375 PT somewhere between BEGV and START. Try to handle that case. */
14376 if (w
->cursor
.vpos
< 0)
14378 struct glyph_row
*row
= w
->current_matrix
->rows
;
14379 if (row
->mode_line_p
)
14381 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14384 if (!cursor_row_fully_visible_p (w
, 0, 0))
14386 /* If vscroll is enabled, disable it and try again. */
14390 clear_glyph_matrix (w
->desired_matrix
);
14394 /* If centering point failed to make the whole line visible,
14395 put point at the top instead. That has to make the whole line
14396 visible, if it can be done. */
14397 if (centering_position
== 0)
14400 clear_glyph_matrix (w
->desired_matrix
);
14401 centering_position
= 0;
14407 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14408 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14409 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14412 /* Display the mode line, if we must. */
14413 if ((update_mode_line
14414 /* If window not full width, must redo its mode line
14415 if (a) the window to its side is being redone and
14416 (b) we do a frame-based redisplay. This is a consequence
14417 of how inverted lines are drawn in frame-based redisplay. */
14418 || (!just_this_one_p
14419 && !FRAME_WINDOW_P (f
)
14420 && !WINDOW_FULL_WIDTH_P (w
))
14421 /* Line number to display. */
14422 || INTEGERP (w
->base_line_pos
)
14423 /* Column number is displayed and different from the one displayed. */
14424 || (!NILP (w
->column_number_displayed
)
14425 && (XFASTINT (w
->column_number_displayed
)
14426 != (int) current_column ()))) /* iftc */
14427 /* This means that the window has a mode line. */
14428 && (WINDOW_WANTS_MODELINE_P (w
)
14429 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14431 display_mode_lines (w
);
14433 /* If mode line height has changed, arrange for a thorough
14434 immediate redisplay using the correct mode line height. */
14435 if (WINDOW_WANTS_MODELINE_P (w
)
14436 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14438 fonts_changed_p
= 1;
14439 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14440 = DESIRED_MODE_LINE_HEIGHT (w
);
14443 /* If header line height has changed, arrange for a thorough
14444 immediate redisplay using the correct header line height. */
14445 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14446 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14448 fonts_changed_p
= 1;
14449 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14450 = DESIRED_HEADER_LINE_HEIGHT (w
);
14453 if (fonts_changed_p
)
14454 goto need_larger_matrices
;
14457 if (!line_number_displayed
14458 && !BUFFERP (w
->base_line_pos
))
14460 w
->base_line_pos
= Qnil
;
14461 w
->base_line_number
= Qnil
;
14466 /* When we reach a frame's selected window, redo the frame's menu bar. */
14467 if (update_mode_line
14468 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14470 int redisplay_menu_p
= 0;
14471 int redisplay_tool_bar_p
= 0;
14473 if (FRAME_WINDOW_P (f
))
14475 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14476 || defined (HAVE_NS) || defined (USE_GTK)
14477 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14479 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14483 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14485 if (redisplay_menu_p
)
14486 display_menu_bar (w
);
14488 #ifdef HAVE_WINDOW_SYSTEM
14489 if (FRAME_WINDOW_P (f
))
14491 #if defined (USE_GTK) || defined (HAVE_NS)
14492 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14494 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14495 && (FRAME_TOOL_BAR_LINES (f
) > 0
14496 || !NILP (Vauto_resize_tool_bars
));
14499 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14501 extern int ignore_mouse_drag_p
;
14502 ignore_mouse_drag_p
= 1;
14508 #ifdef HAVE_WINDOW_SYSTEM
14509 if (FRAME_WINDOW_P (f
)
14510 && update_window_fringes (w
, (just_this_one_p
14511 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14512 || w
->pseudo_window_p
)))
14516 if (draw_window_fringes (w
, 1))
14517 x_draw_vertical_border (w
);
14521 #endif /* HAVE_WINDOW_SYSTEM */
14523 /* We go to this label, with fonts_changed_p nonzero,
14524 if it is necessary to try again using larger glyph matrices.
14525 We have to redeem the scroll bar even in this case,
14526 because the loop in redisplay_internal expects that. */
14527 need_larger_matrices
:
14529 finish_scroll_bars
:
14531 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14533 /* Set the thumb's position and size. */
14534 set_vertical_scroll_bar (w
);
14536 /* Note that we actually used the scroll bar attached to this
14537 window, so it shouldn't be deleted at the end of redisplay. */
14538 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14539 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14542 /* Restore current_buffer and value of point in it. */
14543 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14544 set_buffer_internal_1 (old
);
14545 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14546 shorter. This can be caused by log truncation in *Messages*. */
14547 if (CHARPOS (lpoint
) <= ZV
)
14548 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14550 unbind_to (count
, Qnil
);
14554 /* Build the complete desired matrix of WINDOW with a window start
14555 buffer position POS.
14557 Value is 1 if successful. It is zero if fonts were loaded during
14558 redisplay which makes re-adjusting glyph matrices necessary, and -1
14559 if point would appear in the scroll margins.
14560 (We check that only if CHECK_MARGINS is nonzero. */
14563 try_window (window
, pos
, check_margins
)
14564 Lisp_Object window
;
14565 struct text_pos pos
;
14568 struct window
*w
= XWINDOW (window
);
14570 struct glyph_row
*last_text_row
= NULL
;
14571 struct frame
*f
= XFRAME (w
->frame
);
14573 /* Make POS the new window start. */
14574 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14576 /* Mark cursor position as unknown. No overlay arrow seen. */
14577 w
->cursor
.vpos
= -1;
14578 overlay_arrow_seen
= 0;
14580 /* Initialize iterator and info to start at POS. */
14581 start_display (&it
, w
, pos
);
14583 /* Display all lines of W. */
14584 while (it
.current_y
< it
.last_visible_y
)
14586 if (display_line (&it
))
14587 last_text_row
= it
.glyph_row
- 1;
14588 if (fonts_changed_p
)
14592 /* Don't let the cursor end in the scroll margins. */
14594 && !MINI_WINDOW_P (w
))
14596 int this_scroll_margin
;
14598 if (scroll_margin
> 0)
14600 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14601 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14604 this_scroll_margin
= 0;
14606 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14607 && w
->cursor
.y
< this_scroll_margin
14608 && CHARPOS (pos
) > BEGV
14609 && IT_CHARPOS (it
) < ZV
)
14610 /* rms: considering make_cursor_line_fully_visible_p here
14611 seems to give wrong results. We don't want to recenter
14612 when the last line is partly visible, we want to allow
14613 that case to be handled in the usual way. */
14614 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14616 w
->cursor
.vpos
= -1;
14617 clear_glyph_matrix (w
->desired_matrix
);
14622 /* If bottom moved off end of frame, change mode line percentage. */
14623 if (XFASTINT (w
->window_end_pos
) <= 0
14624 && Z
!= IT_CHARPOS (it
))
14625 w
->update_mode_line
= Qt
;
14627 /* Set window_end_pos to the offset of the last character displayed
14628 on the window from the end of current_buffer. Set
14629 window_end_vpos to its row number. */
14632 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14633 w
->window_end_bytepos
14634 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14636 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14638 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14639 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14640 ->displays_text_p
);
14644 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14645 w
->window_end_pos
= make_number (Z
- ZV
);
14646 w
->window_end_vpos
= make_number (0);
14649 /* But that is not valid info until redisplay finishes. */
14650 w
->window_end_valid
= Qnil
;
14656 /************************************************************************
14657 Window redisplay reusing current matrix when buffer has not changed
14658 ************************************************************************/
14660 /* Try redisplay of window W showing an unchanged buffer with a
14661 different window start than the last time it was displayed by
14662 reusing its current matrix. Value is non-zero if successful.
14663 W->start is the new window start. */
14666 try_window_reusing_current_matrix (w
)
14669 struct frame
*f
= XFRAME (w
->frame
);
14670 struct glyph_row
*row
, *bottom_row
;
14673 struct text_pos start
, new_start
;
14674 int nrows_scrolled
, i
;
14675 struct glyph_row
*last_text_row
;
14676 struct glyph_row
*last_reused_text_row
;
14677 struct glyph_row
*start_row
;
14678 int start_vpos
, min_y
, max_y
;
14681 if (inhibit_try_window_reusing
)
14685 if (/* This function doesn't handle terminal frames. */
14686 !FRAME_WINDOW_P (f
)
14687 /* Don't try to reuse the display if windows have been split
14689 || windows_or_buffers_changed
14690 || cursor_type_changed
)
14693 /* Can't do this if region may have changed. */
14694 if ((!NILP (Vtransient_mark_mode
)
14695 && !NILP (current_buffer
->mark_active
))
14696 || !NILP (w
->region_showing
)
14697 || !NILP (Vshow_trailing_whitespace
))
14700 /* If top-line visibility has changed, give up. */
14701 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14702 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14705 /* Give up if old or new display is scrolled vertically. We could
14706 make this function handle this, but right now it doesn't. */
14707 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14708 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14711 /* The variable new_start now holds the new window start. The old
14712 start `start' can be determined from the current matrix. */
14713 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14714 start
= start_row
->start
.pos
;
14715 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14717 /* Clear the desired matrix for the display below. */
14718 clear_glyph_matrix (w
->desired_matrix
);
14720 if (CHARPOS (new_start
) <= CHARPOS (start
))
14724 /* Don't use this method if the display starts with an ellipsis
14725 displayed for invisible text. It's not easy to handle that case
14726 below, and it's certainly not worth the effort since this is
14727 not a frequent case. */
14728 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14731 IF_DEBUG (debug_method_add (w
, "twu1"));
14733 /* Display up to a row that can be reused. The variable
14734 last_text_row is set to the last row displayed that displays
14735 text. Note that it.vpos == 0 if or if not there is a
14736 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14737 start_display (&it
, w
, new_start
);
14738 first_row_y
= it
.current_y
;
14739 w
->cursor
.vpos
= -1;
14740 last_text_row
= last_reused_text_row
= NULL
;
14742 while (it
.current_y
< it
.last_visible_y
14743 && !fonts_changed_p
)
14745 /* If we have reached into the characters in the START row,
14746 that means the line boundaries have changed. So we
14747 can't start copying with the row START. Maybe it will
14748 work to start copying with the following row. */
14749 while (IT_CHARPOS (it
) > CHARPOS (start
))
14751 /* Advance to the next row as the "start". */
14753 start
= start_row
->start
.pos
;
14754 /* If there are no more rows to try, or just one, give up. */
14755 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14756 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14757 || CHARPOS (start
) == ZV
)
14759 clear_glyph_matrix (w
->desired_matrix
);
14763 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14765 /* If we have reached alignment,
14766 we can copy the rest of the rows. */
14767 if (IT_CHARPOS (it
) == CHARPOS (start
))
14770 if (display_line (&it
))
14771 last_text_row
= it
.glyph_row
- 1;
14774 /* A value of current_y < last_visible_y means that we stopped
14775 at the previous window start, which in turn means that we
14776 have at least one reusable row. */
14777 if (it
.current_y
< it
.last_visible_y
)
14779 /* IT.vpos always starts from 0; it counts text lines. */
14780 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14782 /* Find PT if not already found in the lines displayed. */
14783 if (w
->cursor
.vpos
< 0)
14785 int dy
= it
.current_y
- start_row
->y
;
14787 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14788 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14790 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14791 dy
, nrows_scrolled
);
14794 clear_glyph_matrix (w
->desired_matrix
);
14799 /* Scroll the display. Do it before the current matrix is
14800 changed. The problem here is that update has not yet
14801 run, i.e. part of the current matrix is not up to date.
14802 scroll_run_hook will clear the cursor, and use the
14803 current matrix to get the height of the row the cursor is
14805 run
.current_y
= start_row
->y
;
14806 run
.desired_y
= it
.current_y
;
14807 run
.height
= it
.last_visible_y
- it
.current_y
;
14809 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14812 FRAME_RIF (f
)->update_window_begin_hook (w
);
14813 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14814 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14815 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14819 /* Shift current matrix down by nrows_scrolled lines. */
14820 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14821 rotate_matrix (w
->current_matrix
,
14823 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14826 /* Disable lines that must be updated. */
14827 for (i
= 0; i
< nrows_scrolled
; ++i
)
14828 (start_row
+ i
)->enabled_p
= 0;
14830 /* Re-compute Y positions. */
14831 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14832 max_y
= it
.last_visible_y
;
14833 for (row
= start_row
+ nrows_scrolled
;
14837 row
->y
= it
.current_y
;
14838 row
->visible_height
= row
->height
;
14840 if (row
->y
< min_y
)
14841 row
->visible_height
-= min_y
- row
->y
;
14842 if (row
->y
+ row
->height
> max_y
)
14843 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14844 row
->redraw_fringe_bitmaps_p
= 1;
14846 it
.current_y
+= row
->height
;
14848 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14849 last_reused_text_row
= row
;
14850 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14854 /* Disable lines in the current matrix which are now
14855 below the window. */
14856 for (++row
; row
< bottom_row
; ++row
)
14857 row
->enabled_p
= row
->mode_line_p
= 0;
14860 /* Update window_end_pos etc.; last_reused_text_row is the last
14861 reused row from the current matrix containing text, if any.
14862 The value of last_text_row is the last displayed line
14863 containing text. */
14864 if (last_reused_text_row
)
14866 w
->window_end_bytepos
14867 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14869 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14871 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14872 w
->current_matrix
));
14874 else if (last_text_row
)
14876 w
->window_end_bytepos
14877 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14879 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14881 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14885 /* This window must be completely empty. */
14886 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14887 w
->window_end_pos
= make_number (Z
- ZV
);
14888 w
->window_end_vpos
= make_number (0);
14890 w
->window_end_valid
= Qnil
;
14892 /* Update hint: don't try scrolling again in update_window. */
14893 w
->desired_matrix
->no_scrolling_p
= 1;
14896 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14900 else if (CHARPOS (new_start
) > CHARPOS (start
))
14902 struct glyph_row
*pt_row
, *row
;
14903 struct glyph_row
*first_reusable_row
;
14904 struct glyph_row
*first_row_to_display
;
14906 int yb
= window_text_bottom_y (w
);
14908 /* Find the row starting at new_start, if there is one. Don't
14909 reuse a partially visible line at the end. */
14910 first_reusable_row
= start_row
;
14911 while (first_reusable_row
->enabled_p
14912 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14913 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14914 < CHARPOS (new_start
)))
14915 ++first_reusable_row
;
14917 /* Give up if there is no row to reuse. */
14918 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14919 || !first_reusable_row
->enabled_p
14920 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14921 != CHARPOS (new_start
)))
14924 /* We can reuse fully visible rows beginning with
14925 first_reusable_row to the end of the window. Set
14926 first_row_to_display to the first row that cannot be reused.
14927 Set pt_row to the row containing point, if there is any. */
14929 for (first_row_to_display
= first_reusable_row
;
14930 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14931 ++first_row_to_display
)
14933 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14934 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14935 pt_row
= first_row_to_display
;
14938 /* Start displaying at the start of first_row_to_display. */
14939 xassert (first_row_to_display
->y
< yb
);
14940 init_to_row_start (&it
, w
, first_row_to_display
);
14942 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14944 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14946 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14947 + WINDOW_HEADER_LINE_HEIGHT (w
));
14949 /* Display lines beginning with first_row_to_display in the
14950 desired matrix. Set last_text_row to the last row displayed
14951 that displays text. */
14952 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14953 if (pt_row
== NULL
)
14954 w
->cursor
.vpos
= -1;
14955 last_text_row
= NULL
;
14956 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14957 if (display_line (&it
))
14958 last_text_row
= it
.glyph_row
- 1;
14960 /* If point is in a reused row, adjust y and vpos of the cursor
14964 w
->cursor
.vpos
-= nrows_scrolled
;
14965 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14968 /* Give up if point isn't in a row displayed or reused. (This
14969 also handles the case where w->cursor.vpos < nrows_scrolled
14970 after the calls to display_line, which can happen with scroll
14971 margins. See bug#1295.) */
14972 if (w
->cursor
.vpos
< 0)
14974 clear_glyph_matrix (w
->desired_matrix
);
14978 /* Scroll the display. */
14979 run
.current_y
= first_reusable_row
->y
;
14980 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14981 run
.height
= it
.last_visible_y
- run
.current_y
;
14982 dy
= run
.current_y
- run
.desired_y
;
14987 FRAME_RIF (f
)->update_window_begin_hook (w
);
14988 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14989 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14990 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14994 /* Adjust Y positions of reused rows. */
14995 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14996 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14997 max_y
= it
.last_visible_y
;
14998 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15001 row
->visible_height
= row
->height
;
15002 if (row
->y
< min_y
)
15003 row
->visible_height
-= min_y
- row
->y
;
15004 if (row
->y
+ row
->height
> max_y
)
15005 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15006 row
->redraw_fringe_bitmaps_p
= 1;
15009 /* Scroll the current matrix. */
15010 xassert (nrows_scrolled
> 0);
15011 rotate_matrix (w
->current_matrix
,
15013 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15016 /* Disable rows not reused. */
15017 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15018 row
->enabled_p
= 0;
15020 /* Point may have moved to a different line, so we cannot assume that
15021 the previous cursor position is valid; locate the correct row. */
15024 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15025 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15029 w
->cursor
.y
= row
->y
;
15031 if (row
< bottom_row
)
15033 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15034 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15035 struct glyph
*orig_glyph
= glyph
;
15036 struct cursor_pos orig_cursor
= w
->cursor
;
15039 && (!BUFFERP (glyph
->object
)
15040 || glyph
->charpos
!= PT
);
15044 w
->cursor
.x
+= glyph
->pixel_width
;
15046 /* With bidi reordering, charpos changes non-linearly
15047 with hpos, so the right glyph could be to the
15049 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15050 && (!BUFFERP (glyph
->object
) || glyph
->charpos
!= PT
))
15052 struct glyph
*start_glyph
= row
->glyphs
[TEXT_AREA
];
15054 glyph
= orig_glyph
- 1;
15055 orig_cursor
.hpos
--;
15056 orig_cursor
.x
-= glyph
->pixel_width
;
15057 for (; glyph
>= start_glyph
15058 && (!BUFFERP (glyph
->object
)
15059 || glyph
->charpos
!= PT
);
15063 w
->cursor
.x
-= glyph
->pixel_width
;
15065 if (BUFFERP (glyph
->object
) && glyph
->charpos
== PT
)
15066 w
->cursor
= orig_cursor
;
15071 /* Adjust window end. A null value of last_text_row means that
15072 the window end is in reused rows which in turn means that
15073 only its vpos can have changed. */
15076 w
->window_end_bytepos
15077 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15079 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15081 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15086 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15089 w
->window_end_valid
= Qnil
;
15090 w
->desired_matrix
->no_scrolling_p
= 1;
15093 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15103 /************************************************************************
15104 Window redisplay reusing current matrix when buffer has changed
15105 ************************************************************************/
15107 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
15108 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
15110 static struct glyph_row
*
15111 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
15112 struct glyph_row
*));
15115 /* Return the last row in MATRIX displaying text. If row START is
15116 non-null, start searching with that row. IT gives the dimensions
15117 of the display. Value is null if matrix is empty; otherwise it is
15118 a pointer to the row found. */
15120 static struct glyph_row
*
15121 find_last_row_displaying_text (matrix
, it
, start
)
15122 struct glyph_matrix
*matrix
;
15124 struct glyph_row
*start
;
15126 struct glyph_row
*row
, *row_found
;
15128 /* Set row_found to the last row in IT->w's current matrix
15129 displaying text. The loop looks funny but think of partially
15132 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15133 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15135 xassert (row
->enabled_p
);
15137 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15146 /* Return the last row in the current matrix of W that is not affected
15147 by changes at the start of current_buffer that occurred since W's
15148 current matrix was built. Value is null if no such row exists.
15150 BEG_UNCHANGED us the number of characters unchanged at the start of
15151 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15152 first changed character in current_buffer. Characters at positions <
15153 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15154 when the current matrix was built. */
15156 static struct glyph_row
*
15157 find_last_unchanged_at_beg_row (w
)
15160 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15161 struct glyph_row
*row
;
15162 struct glyph_row
*row_found
= NULL
;
15163 int yb
= window_text_bottom_y (w
);
15165 /* Find the last row displaying unchanged text. */
15166 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15167 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15168 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15171 if (/* If row ends before first_changed_pos, it is unchanged,
15172 except in some case. */
15173 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15174 /* When row ends in ZV and we write at ZV it is not
15176 && !row
->ends_at_zv_p
15177 /* When first_changed_pos is the end of a continued line,
15178 row is not unchanged because it may be no longer
15180 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15181 && (row
->continued_p
15182 || row
->exact_window_width_line_p
)))
15185 /* Stop if last visible row. */
15186 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15194 /* Find the first glyph row in the current matrix of W that is not
15195 affected by changes at the end of current_buffer since the
15196 time W's current matrix was built.
15198 Return in *DELTA the number of chars by which buffer positions in
15199 unchanged text at the end of current_buffer must be adjusted.
15201 Return in *DELTA_BYTES the corresponding number of bytes.
15203 Value is null if no such row exists, i.e. all rows are affected by
15206 static struct glyph_row
*
15207 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
15209 int *delta
, *delta_bytes
;
15211 struct glyph_row
*row
;
15212 struct glyph_row
*row_found
= NULL
;
15214 *delta
= *delta_bytes
= 0;
15216 /* Display must not have been paused, otherwise the current matrix
15217 is not up to date. */
15218 eassert (!NILP (w
->window_end_valid
));
15220 /* A value of window_end_pos >= END_UNCHANGED means that the window
15221 end is in the range of changed text. If so, there is no
15222 unchanged row at the end of W's current matrix. */
15223 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15226 /* Set row to the last row in W's current matrix displaying text. */
15227 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15229 /* If matrix is entirely empty, no unchanged row exists. */
15230 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15232 /* The value of row is the last glyph row in the matrix having a
15233 meaningful buffer position in it. The end position of row
15234 corresponds to window_end_pos. This allows us to translate
15235 buffer positions in the current matrix to current buffer
15236 positions for characters not in changed text. */
15237 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15238 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15239 int last_unchanged_pos
, last_unchanged_pos_old
;
15240 struct glyph_row
*first_text_row
15241 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15243 *delta
= Z
- Z_old
;
15244 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15246 /* Set last_unchanged_pos to the buffer position of the last
15247 character in the buffer that has not been changed. Z is the
15248 index + 1 of the last character in current_buffer, i.e. by
15249 subtracting END_UNCHANGED we get the index of the last
15250 unchanged character, and we have to add BEG to get its buffer
15252 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15253 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15255 /* Search backward from ROW for a row displaying a line that
15256 starts at a minimum position >= last_unchanged_pos_old. */
15257 for (; row
> first_text_row
; --row
)
15259 /* This used to abort, but it can happen.
15260 It is ok to just stop the search instead here. KFS. */
15261 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15264 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15269 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15275 /* Make sure that glyph rows in the current matrix of window W
15276 reference the same glyph memory as corresponding rows in the
15277 frame's frame matrix. This function is called after scrolling W's
15278 current matrix on a terminal frame in try_window_id and
15279 try_window_reusing_current_matrix. */
15282 sync_frame_with_window_matrix_rows (w
)
15285 struct frame
*f
= XFRAME (w
->frame
);
15286 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15288 /* Preconditions: W must be a leaf window and full-width. Its frame
15289 must have a frame matrix. */
15290 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15291 xassert (WINDOW_FULL_WIDTH_P (w
));
15292 xassert (!FRAME_WINDOW_P (f
));
15294 /* If W is a full-width window, glyph pointers in W's current matrix
15295 have, by definition, to be the same as glyph pointers in the
15296 corresponding frame matrix. Note that frame matrices have no
15297 marginal areas (see build_frame_matrix). */
15298 window_row
= w
->current_matrix
->rows
;
15299 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15300 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15301 while (window_row
< window_row_end
)
15303 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15304 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15306 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15307 frame_row
->glyphs
[TEXT_AREA
] = start
;
15308 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15309 frame_row
->glyphs
[LAST_AREA
] = end
;
15311 /* Disable frame rows whose corresponding window rows have
15312 been disabled in try_window_id. */
15313 if (!window_row
->enabled_p
)
15314 frame_row
->enabled_p
= 0;
15316 ++window_row
, ++frame_row
;
15321 /* Find the glyph row in window W containing CHARPOS. Consider all
15322 rows between START and END (not inclusive). END null means search
15323 all rows to the end of the display area of W. Value is the row
15324 containing CHARPOS or null. */
15327 row_containing_pos (w
, charpos
, start
, end
, dy
)
15330 struct glyph_row
*start
, *end
;
15333 struct glyph_row
*row
= start
;
15334 struct glyph_row
*best_row
= NULL
;
15335 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15338 /* If we happen to start on a header-line, skip that. */
15339 if (row
->mode_line_p
)
15342 if ((end
&& row
>= end
) || !row
->enabled_p
)
15345 last_y
= window_text_bottom_y (w
) - dy
;
15349 /* Give up if we have gone too far. */
15350 if (end
&& row
>= end
)
15352 /* This formerly returned if they were equal.
15353 I think that both quantities are of a "last plus one" type;
15354 if so, when they are equal, the row is within the screen. -- rms. */
15355 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15358 /* If it is in this row, return this row. */
15359 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15360 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15361 /* The end position of a row equals the start
15362 position of the next row. If CHARPOS is there, we
15363 would rather display it in the next line, except
15364 when this line ends in ZV. */
15365 && !row
->ends_at_zv_p
15366 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15367 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15371 if (NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
15373 /* In bidi-reordered rows, there could be several rows
15374 occluding point. We need to find the one which fits
15375 CHARPOS the best. */
15376 for (g
= row
->glyphs
[TEXT_AREA
];
15377 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15380 if (!STRINGP (g
->object
))
15382 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15384 mindif
= eabs (g
->charpos
- charpos
);
15397 /* Try to redisplay window W by reusing its existing display. W's
15398 current matrix must be up to date when this function is called,
15399 i.e. window_end_valid must not be nil.
15403 1 if display has been updated
15404 0 if otherwise unsuccessful
15405 -1 if redisplay with same window start is known not to succeed
15407 The following steps are performed:
15409 1. Find the last row in the current matrix of W that is not
15410 affected by changes at the start of current_buffer. If no such row
15413 2. Find the first row in W's current matrix that is not affected by
15414 changes at the end of current_buffer. Maybe there is no such row.
15416 3. Display lines beginning with the row + 1 found in step 1 to the
15417 row found in step 2 or, if step 2 didn't find a row, to the end of
15420 4. If cursor is not known to appear on the window, give up.
15422 5. If display stopped at the row found in step 2, scroll the
15423 display and current matrix as needed.
15425 6. Maybe display some lines at the end of W, if we must. This can
15426 happen under various circumstances, like a partially visible line
15427 becoming fully visible, or because newly displayed lines are displayed
15428 in smaller font sizes.
15430 7. Update W's window end information. */
15436 struct frame
*f
= XFRAME (w
->frame
);
15437 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15438 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15439 struct glyph_row
*last_unchanged_at_beg_row
;
15440 struct glyph_row
*first_unchanged_at_end_row
;
15441 struct glyph_row
*row
;
15442 struct glyph_row
*bottom_row
;
15445 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
15446 struct text_pos start_pos
;
15448 int first_unchanged_at_end_vpos
= 0;
15449 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15450 struct text_pos start
;
15451 int first_changed_charpos
, last_changed_charpos
;
15454 if (inhibit_try_window_id
)
15458 /* This is handy for debugging. */
15460 #define GIVE_UP(X) \
15462 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15466 #define GIVE_UP(X) return 0
15469 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15471 /* Don't use this for mini-windows because these can show
15472 messages and mini-buffers, and we don't handle that here. */
15473 if (MINI_WINDOW_P (w
))
15476 /* This flag is used to prevent redisplay optimizations. */
15477 if (windows_or_buffers_changed
|| cursor_type_changed
)
15480 /* Verify that narrowing has not changed.
15481 Also verify that we were not told to prevent redisplay optimizations.
15482 It would be nice to further
15483 reduce the number of cases where this prevents try_window_id. */
15484 if (current_buffer
->clip_changed
15485 || current_buffer
->prevent_redisplay_optimizations_p
)
15488 /* Window must either use window-based redisplay or be full width. */
15489 if (!FRAME_WINDOW_P (f
)
15490 && (!FRAME_LINE_INS_DEL_OK (f
)
15491 || !WINDOW_FULL_WIDTH_P (w
)))
15494 /* Give up if point is known NOT to appear in W. */
15495 if (PT
< CHARPOS (start
))
15498 /* Another way to prevent redisplay optimizations. */
15499 if (XFASTINT (w
->last_modified
) == 0)
15502 /* Verify that window is not hscrolled. */
15503 if (XFASTINT (w
->hscroll
) != 0)
15506 /* Verify that display wasn't paused. */
15507 if (NILP (w
->window_end_valid
))
15510 /* Can't use this if highlighting a region because a cursor movement
15511 will do more than just set the cursor. */
15512 if (!NILP (Vtransient_mark_mode
)
15513 && !NILP (current_buffer
->mark_active
))
15516 /* Likewise if highlighting trailing whitespace. */
15517 if (!NILP (Vshow_trailing_whitespace
))
15520 /* Likewise if showing a region. */
15521 if (!NILP (w
->region_showing
))
15524 /* Can't use this if overlay arrow position and/or string have
15526 if (overlay_arrows_changed_p ())
15529 /* When word-wrap is on, adding a space to the first word of a
15530 wrapped line can change the wrap position, altering the line
15531 above it. It might be worthwhile to handle this more
15532 intelligently, but for now just redisplay from scratch. */
15533 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15536 /* Under bidi reordering, adding or deleting a character in the
15537 beginning of a paragraph, before the first strong directional
15538 character, can change the base direction of the paragraph (unless
15539 the buffer specifies a fixed paragraph direction), which will
15540 require to redisplay the whole paragraph. It might be worthwhile
15541 to find the paragraph limits and widen the range of redisplayed
15542 lines to that, but for now just give up this optimization and
15543 redisplay from scratch. */
15544 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15545 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15548 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15549 only if buffer has really changed. The reason is that the gap is
15550 initially at Z for freshly visited files. The code below would
15551 set end_unchanged to 0 in that case. */
15552 if (MODIFF
> SAVE_MODIFF
15553 /* This seems to happen sometimes after saving a buffer. */
15554 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15556 if (GPT
- BEG
< BEG_UNCHANGED
)
15557 BEG_UNCHANGED
= GPT
- BEG
;
15558 if (Z
- GPT
< END_UNCHANGED
)
15559 END_UNCHANGED
= Z
- GPT
;
15562 /* The position of the first and last character that has been changed. */
15563 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15564 last_changed_charpos
= Z
- END_UNCHANGED
;
15566 /* If window starts after a line end, and the last change is in
15567 front of that newline, then changes don't affect the display.
15568 This case happens with stealth-fontification. Note that although
15569 the display is unchanged, glyph positions in the matrix have to
15570 be adjusted, of course. */
15571 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15572 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15573 && ((last_changed_charpos
< CHARPOS (start
)
15574 && CHARPOS (start
) == BEGV
)
15575 || (last_changed_charpos
< CHARPOS (start
) - 1
15576 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15578 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15579 struct glyph_row
*r0
;
15581 /* Compute how many chars/bytes have been added to or removed
15582 from the buffer. */
15583 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15584 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15586 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15588 /* Give up if PT is not in the window. Note that it already has
15589 been checked at the start of try_window_id that PT is not in
15590 front of the window start. */
15591 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15594 /* If window start is unchanged, we can reuse the whole matrix
15595 as is, after adjusting glyph positions. No need to compute
15596 the window end again, since its offset from Z hasn't changed. */
15597 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15598 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15599 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15600 /* PT must not be in a partially visible line. */
15601 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15602 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15604 /* Adjust positions in the glyph matrix. */
15605 if (delta
|| delta_bytes
)
15607 struct glyph_row
*r1
15608 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15609 increment_matrix_positions (w
->current_matrix
,
15610 MATRIX_ROW_VPOS (r0
, current_matrix
),
15611 MATRIX_ROW_VPOS (r1
, current_matrix
),
15612 delta
, delta_bytes
);
15615 /* Set the cursor. */
15616 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15618 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15625 /* Handle the case that changes are all below what is displayed in
15626 the window, and that PT is in the window. This shortcut cannot
15627 be taken if ZV is visible in the window, and text has been added
15628 there that is visible in the window. */
15629 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15630 /* ZV is not visible in the window, or there are no
15631 changes at ZV, actually. */
15632 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15633 || first_changed_charpos
== last_changed_charpos
))
15635 struct glyph_row
*r0
;
15637 /* Give up if PT is not in the window. Note that it already has
15638 been checked at the start of try_window_id that PT is not in
15639 front of the window start. */
15640 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15643 /* If window start is unchanged, we can reuse the whole matrix
15644 as is, without changing glyph positions since no text has
15645 been added/removed in front of the window end. */
15646 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15647 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15648 /* PT must not be in a partially visible line. */
15649 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15650 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15652 /* We have to compute the window end anew since text
15653 can have been added/removed after it. */
15655 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15656 w
->window_end_bytepos
15657 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15659 /* Set the cursor. */
15660 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15662 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15669 /* Give up if window start is in the changed area.
15671 The condition used to read
15673 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15675 but why that was tested escapes me at the moment. */
15676 if (CHARPOS (start
) >= first_changed_charpos
15677 && CHARPOS (start
) <= last_changed_charpos
)
15680 /* Check that window start agrees with the start of the first glyph
15681 row in its current matrix. Check this after we know the window
15682 start is not in changed text, otherwise positions would not be
15684 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15685 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15688 /* Give up if the window ends in strings. Overlay strings
15689 at the end are difficult to handle, so don't try. */
15690 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15691 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15694 /* Compute the position at which we have to start displaying new
15695 lines. Some of the lines at the top of the window might be
15696 reusable because they are not displaying changed text. Find the
15697 last row in W's current matrix not affected by changes at the
15698 start of current_buffer. Value is null if changes start in the
15699 first line of window. */
15700 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15701 if (last_unchanged_at_beg_row
)
15703 /* Avoid starting to display in the moddle of a character, a TAB
15704 for instance. This is easier than to set up the iterator
15705 exactly, and it's not a frequent case, so the additional
15706 effort wouldn't really pay off. */
15707 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15708 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15709 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15710 --last_unchanged_at_beg_row
;
15712 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15715 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15717 start_pos
= it
.current
.pos
;
15719 /* Start displaying new lines in the desired matrix at the same
15720 vpos we would use in the current matrix, i.e. below
15721 last_unchanged_at_beg_row. */
15722 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15724 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15725 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15727 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15731 /* There are no reusable lines at the start of the window.
15732 Start displaying in the first text line. */
15733 start_display (&it
, w
, start
);
15734 it
.vpos
= it
.first_vpos
;
15735 start_pos
= it
.current
.pos
;
15738 /* Find the first row that is not affected by changes at the end of
15739 the buffer. Value will be null if there is no unchanged row, in
15740 which case we must redisplay to the end of the window. delta
15741 will be set to the value by which buffer positions beginning with
15742 first_unchanged_at_end_row have to be adjusted due to text
15744 first_unchanged_at_end_row
15745 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15746 IF_DEBUG (debug_delta
= delta
);
15747 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15749 /* Set stop_pos to the buffer position up to which we will have to
15750 display new lines. If first_unchanged_at_end_row != NULL, this
15751 is the buffer position of the start of the line displayed in that
15752 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15753 that we don't stop at a buffer position. */
15755 if (first_unchanged_at_end_row
)
15757 xassert (last_unchanged_at_beg_row
== NULL
15758 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15760 /* If this is a continuation line, move forward to the next one
15761 that isn't. Changes in lines above affect this line.
15762 Caution: this may move first_unchanged_at_end_row to a row
15763 not displaying text. */
15764 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15765 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15766 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15767 < it
.last_visible_y
))
15768 ++first_unchanged_at_end_row
;
15770 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15771 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15772 >= it
.last_visible_y
))
15773 first_unchanged_at_end_row
= NULL
;
15776 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15778 first_unchanged_at_end_vpos
15779 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15780 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15783 else if (last_unchanged_at_beg_row
== NULL
)
15789 /* Either there is no unchanged row at the end, or the one we have
15790 now displays text. This is a necessary condition for the window
15791 end pos calculation at the end of this function. */
15792 xassert (first_unchanged_at_end_row
== NULL
15793 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15795 debug_last_unchanged_at_beg_vpos
15796 = (last_unchanged_at_beg_row
15797 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15799 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15801 #endif /* GLYPH_DEBUG != 0 */
15804 /* Display new lines. Set last_text_row to the last new line
15805 displayed which has text on it, i.e. might end up as being the
15806 line where the window_end_vpos is. */
15807 w
->cursor
.vpos
= -1;
15808 last_text_row
= NULL
;
15809 overlay_arrow_seen
= 0;
15810 while (it
.current_y
< it
.last_visible_y
15811 && !fonts_changed_p
15812 && (first_unchanged_at_end_row
== NULL
15813 || IT_CHARPOS (it
) < stop_pos
))
15815 if (display_line (&it
))
15816 last_text_row
= it
.glyph_row
- 1;
15819 if (fonts_changed_p
)
15823 /* Compute differences in buffer positions, y-positions etc. for
15824 lines reused at the bottom of the window. Compute what we can
15826 if (first_unchanged_at_end_row
15827 /* No lines reused because we displayed everything up to the
15828 bottom of the window. */
15829 && it
.current_y
< it
.last_visible_y
)
15832 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15834 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15835 run
.current_y
= first_unchanged_at_end_row
->y
;
15836 run
.desired_y
= run
.current_y
+ dy
;
15837 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15841 delta
= delta_bytes
= dvpos
= dy
15842 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15843 first_unchanged_at_end_row
= NULL
;
15845 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15848 /* Find the cursor if not already found. We have to decide whether
15849 PT will appear on this window (it sometimes doesn't, but this is
15850 not a very frequent case.) This decision has to be made before
15851 the current matrix is altered. A value of cursor.vpos < 0 means
15852 that PT is either in one of the lines beginning at
15853 first_unchanged_at_end_row or below the window. Don't care for
15854 lines that might be displayed later at the window end; as
15855 mentioned, this is not a frequent case. */
15856 if (w
->cursor
.vpos
< 0)
15858 /* Cursor in unchanged rows at the top? */
15859 if (PT
< CHARPOS (start_pos
)
15860 && last_unchanged_at_beg_row
)
15862 row
= row_containing_pos (w
, PT
,
15863 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15864 last_unchanged_at_beg_row
+ 1, 0);
15866 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15869 /* Start from first_unchanged_at_end_row looking for PT. */
15870 else if (first_unchanged_at_end_row
)
15872 row
= row_containing_pos (w
, PT
- delta
,
15873 first_unchanged_at_end_row
, NULL
, 0);
15875 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15876 delta_bytes
, dy
, dvpos
);
15879 /* Give up if cursor was not found. */
15880 if (w
->cursor
.vpos
< 0)
15882 clear_glyph_matrix (w
->desired_matrix
);
15887 /* Don't let the cursor end in the scroll margins. */
15889 int this_scroll_margin
, cursor_height
;
15891 this_scroll_margin
= max (0, scroll_margin
);
15892 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15893 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15894 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15896 if ((w
->cursor
.y
< this_scroll_margin
15897 && CHARPOS (start
) > BEGV
)
15898 /* Old redisplay didn't take scroll margin into account at the bottom,
15899 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15900 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15901 ? cursor_height
+ this_scroll_margin
15902 : 1)) > it
.last_visible_y
)
15904 w
->cursor
.vpos
= -1;
15905 clear_glyph_matrix (w
->desired_matrix
);
15910 /* Scroll the display. Do it before changing the current matrix so
15911 that xterm.c doesn't get confused about where the cursor glyph is
15913 if (dy
&& run
.height
)
15917 if (FRAME_WINDOW_P (f
))
15919 FRAME_RIF (f
)->update_window_begin_hook (w
);
15920 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15921 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15922 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15926 /* Terminal frame. In this case, dvpos gives the number of
15927 lines to scroll by; dvpos < 0 means scroll up. */
15928 int first_unchanged_at_end_vpos
15929 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15930 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15931 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15932 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15933 + window_internal_height (w
));
15935 /* Perform the operation on the screen. */
15938 /* Scroll last_unchanged_at_beg_row to the end of the
15939 window down dvpos lines. */
15940 set_terminal_window (f
, end
);
15942 /* On dumb terminals delete dvpos lines at the end
15943 before inserting dvpos empty lines. */
15944 if (!FRAME_SCROLL_REGION_OK (f
))
15945 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15947 /* Insert dvpos empty lines in front of
15948 last_unchanged_at_beg_row. */
15949 ins_del_lines (f
, from
, dvpos
);
15951 else if (dvpos
< 0)
15953 /* Scroll up last_unchanged_at_beg_vpos to the end of
15954 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15955 set_terminal_window (f
, end
);
15957 /* Delete dvpos lines in front of
15958 last_unchanged_at_beg_vpos. ins_del_lines will set
15959 the cursor to the given vpos and emit |dvpos| delete
15961 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15963 /* On a dumb terminal insert dvpos empty lines at the
15965 if (!FRAME_SCROLL_REGION_OK (f
))
15966 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15969 set_terminal_window (f
, 0);
15975 /* Shift reused rows of the current matrix to the right position.
15976 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15978 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15979 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15982 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15983 bottom_vpos
, dvpos
);
15984 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15987 else if (dvpos
> 0)
15989 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15990 bottom_vpos
, dvpos
);
15991 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15992 first_unchanged_at_end_vpos
+ dvpos
, 0);
15995 /* For frame-based redisplay, make sure that current frame and window
15996 matrix are in sync with respect to glyph memory. */
15997 if (!FRAME_WINDOW_P (f
))
15998 sync_frame_with_window_matrix_rows (w
);
16000 /* Adjust buffer positions in reused rows. */
16001 if (delta
|| delta_bytes
)
16002 increment_matrix_positions (current_matrix
,
16003 first_unchanged_at_end_vpos
+ dvpos
,
16004 bottom_vpos
, delta
, delta_bytes
);
16006 /* Adjust Y positions. */
16008 shift_glyph_matrix (w
, current_matrix
,
16009 first_unchanged_at_end_vpos
+ dvpos
,
16012 if (first_unchanged_at_end_row
)
16014 first_unchanged_at_end_row
+= dvpos
;
16015 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16016 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16017 first_unchanged_at_end_row
= NULL
;
16020 /* If scrolling up, there may be some lines to display at the end of
16022 last_text_row_at_end
= NULL
;
16025 /* Scrolling up can leave for example a partially visible line
16026 at the end of the window to be redisplayed. */
16027 /* Set last_row to the glyph row in the current matrix where the
16028 window end line is found. It has been moved up or down in
16029 the matrix by dvpos. */
16030 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16031 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16033 /* If last_row is the window end line, it should display text. */
16034 xassert (last_row
->displays_text_p
);
16036 /* If window end line was partially visible before, begin
16037 displaying at that line. Otherwise begin displaying with the
16038 line following it. */
16039 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16041 init_to_row_start (&it
, w
, last_row
);
16042 it
.vpos
= last_vpos
;
16043 it
.current_y
= last_row
->y
;
16047 init_to_row_end (&it
, w
, last_row
);
16048 it
.vpos
= 1 + last_vpos
;
16049 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16053 /* We may start in a continuation line. If so, we have to
16054 get the right continuation_lines_width and current_x. */
16055 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16056 it
.hpos
= it
.current_x
= 0;
16058 /* Display the rest of the lines at the window end. */
16059 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16060 while (it
.current_y
< it
.last_visible_y
16061 && !fonts_changed_p
)
16063 /* Is it always sure that the display agrees with lines in
16064 the current matrix? I don't think so, so we mark rows
16065 displayed invalid in the current matrix by setting their
16066 enabled_p flag to zero. */
16067 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16068 if (display_line (&it
))
16069 last_text_row_at_end
= it
.glyph_row
- 1;
16073 /* Update window_end_pos and window_end_vpos. */
16074 if (first_unchanged_at_end_row
16075 && !last_text_row_at_end
)
16077 /* Window end line if one of the preserved rows from the current
16078 matrix. Set row to the last row displaying text in current
16079 matrix starting at first_unchanged_at_end_row, after
16081 xassert (first_unchanged_at_end_row
->displays_text_p
);
16082 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16083 first_unchanged_at_end_row
);
16084 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16086 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16087 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16089 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16090 xassert (w
->window_end_bytepos
>= 0);
16091 IF_DEBUG (debug_method_add (w
, "A"));
16093 else if (last_text_row_at_end
)
16096 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16097 w
->window_end_bytepos
16098 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16100 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16101 xassert (w
->window_end_bytepos
>= 0);
16102 IF_DEBUG (debug_method_add (w
, "B"));
16104 else if (last_text_row
)
16106 /* We have displayed either to the end of the window or at the
16107 end of the window, i.e. the last row with text is to be found
16108 in the desired matrix. */
16110 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16111 w
->window_end_bytepos
16112 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16114 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16115 xassert (w
->window_end_bytepos
>= 0);
16117 else if (first_unchanged_at_end_row
== NULL
16118 && last_text_row
== NULL
16119 && last_text_row_at_end
== NULL
)
16121 /* Displayed to end of window, but no line containing text was
16122 displayed. Lines were deleted at the end of the window. */
16123 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16124 int vpos
= XFASTINT (w
->window_end_vpos
);
16125 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16126 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16129 row
== NULL
&& vpos
>= first_vpos
;
16130 --vpos
, --current_row
, --desired_row
)
16132 if (desired_row
->enabled_p
)
16134 if (desired_row
->displays_text_p
)
16137 else if (current_row
->displays_text_p
)
16141 xassert (row
!= NULL
);
16142 w
->window_end_vpos
= make_number (vpos
+ 1);
16143 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16144 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16145 xassert (w
->window_end_bytepos
>= 0);
16146 IF_DEBUG (debug_method_add (w
, "C"));
16151 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16152 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16154 /* Record that display has not been completed. */
16155 w
->window_end_valid
= Qnil
;
16156 w
->desired_matrix
->no_scrolling_p
= 1;
16164 /***********************************************************************
16165 More debugging support
16166 ***********************************************************************/
16170 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
16171 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
16172 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
16175 /* Dump the contents of glyph matrix MATRIX on stderr.
16177 GLYPHS 0 means don't show glyph contents.
16178 GLYPHS 1 means show glyphs in short form
16179 GLYPHS > 1 means show glyphs in long form. */
16182 dump_glyph_matrix (matrix
, glyphs
)
16183 struct glyph_matrix
*matrix
;
16187 for (i
= 0; i
< matrix
->nrows
; ++i
)
16188 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16192 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16193 the glyph row and area where the glyph comes from. */
16196 dump_glyph (row
, glyph
, area
)
16197 struct glyph_row
*row
;
16198 struct glyph
*glyph
;
16201 if (glyph
->type
== CHAR_GLYPH
)
16204 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16205 glyph
- row
->glyphs
[TEXT_AREA
],
16208 (BUFFERP (glyph
->object
)
16210 : (STRINGP (glyph
->object
)
16213 glyph
->pixel_width
,
16215 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16219 glyph
->left_box_line_p
,
16220 glyph
->right_box_line_p
);
16222 else if (glyph
->type
== STRETCH_GLYPH
)
16225 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16226 glyph
- row
->glyphs
[TEXT_AREA
],
16229 (BUFFERP (glyph
->object
)
16231 : (STRINGP (glyph
->object
)
16234 glyph
->pixel_width
,
16238 glyph
->left_box_line_p
,
16239 glyph
->right_box_line_p
);
16241 else if (glyph
->type
== IMAGE_GLYPH
)
16244 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16245 glyph
- row
->glyphs
[TEXT_AREA
],
16248 (BUFFERP (glyph
->object
)
16250 : (STRINGP (glyph
->object
)
16253 glyph
->pixel_width
,
16257 glyph
->left_box_line_p
,
16258 glyph
->right_box_line_p
);
16260 else if (glyph
->type
== COMPOSITE_GLYPH
)
16263 " %5d %4c %6d %c %3d 0x%05x",
16264 glyph
- row
->glyphs
[TEXT_AREA
],
16267 (BUFFERP (glyph
->object
)
16269 : (STRINGP (glyph
->object
)
16272 glyph
->pixel_width
,
16274 if (glyph
->u
.cmp
.automatic
)
16277 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
16278 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16280 glyph
->left_box_line_p
,
16281 glyph
->right_box_line_p
);
16286 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16287 GLYPHS 0 means don't show glyph contents.
16288 GLYPHS 1 means show glyphs in short form
16289 GLYPHS > 1 means show glyphs in long form. */
16292 dump_glyph_row (row
, vpos
, glyphs
)
16293 struct glyph_row
*row
;
16298 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16299 fprintf (stderr
, "======================================================================\n");
16301 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16302 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16304 MATRIX_ROW_START_CHARPOS (row
),
16305 MATRIX_ROW_END_CHARPOS (row
),
16306 row
->used
[TEXT_AREA
],
16307 row
->contains_overlapping_glyphs_p
,
16309 row
->truncated_on_left_p
,
16310 row
->truncated_on_right_p
,
16312 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16313 row
->displays_text_p
,
16316 row
->ends_in_middle_of_char_p
,
16317 row
->starts_in_middle_of_char_p
,
16323 row
->visible_height
,
16326 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16327 row
->end
.overlay_string_index
,
16328 row
->continuation_lines_width
);
16329 fprintf (stderr
, "%9d %5d\n",
16330 CHARPOS (row
->start
.string_pos
),
16331 CHARPOS (row
->end
.string_pos
));
16332 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16333 row
->end
.dpvec_index
);
16340 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16342 struct glyph
*glyph
= row
->glyphs
[area
];
16343 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16345 /* Glyph for a line end in text. */
16346 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16349 if (glyph
< glyph_end
)
16350 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16352 for (; glyph
< glyph_end
; ++glyph
)
16353 dump_glyph (row
, glyph
, area
);
16356 else if (glyphs
== 1)
16360 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16362 char *s
= (char *) alloca (row
->used
[area
] + 1);
16365 for (i
= 0; i
< row
->used
[area
]; ++i
)
16367 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16368 if (glyph
->type
== CHAR_GLYPH
16369 && glyph
->u
.ch
< 0x80
16370 && glyph
->u
.ch
>= ' ')
16371 s
[i
] = glyph
->u
.ch
;
16377 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16383 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16384 Sdump_glyph_matrix
, 0, 1, "p",
16385 doc
: /* Dump the current matrix of the selected window to stderr.
16386 Shows contents of glyph row structures. With non-nil
16387 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16388 glyphs in short form, otherwise show glyphs in long form. */)
16390 Lisp_Object glyphs
;
16392 struct window
*w
= XWINDOW (selected_window
);
16393 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16395 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16396 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16397 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16398 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16399 fprintf (stderr
, "=============================================\n");
16400 dump_glyph_matrix (w
->current_matrix
,
16401 NILP (glyphs
) ? 0 : XINT (glyphs
));
16406 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16407 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16410 struct frame
*f
= XFRAME (selected_frame
);
16411 dump_glyph_matrix (f
->current_matrix
, 1);
16416 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16417 doc
: /* Dump glyph row ROW to stderr.
16418 GLYPH 0 means don't dump glyphs.
16419 GLYPH 1 means dump glyphs in short form.
16420 GLYPH > 1 or omitted means dump glyphs in long form. */)
16422 Lisp_Object row
, glyphs
;
16424 struct glyph_matrix
*matrix
;
16427 CHECK_NUMBER (row
);
16428 matrix
= XWINDOW (selected_window
)->current_matrix
;
16430 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16431 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16433 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16438 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16439 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16440 GLYPH 0 means don't dump glyphs.
16441 GLYPH 1 means dump glyphs in short form.
16442 GLYPH > 1 or omitted means dump glyphs in long form. */)
16444 Lisp_Object row
, glyphs
;
16446 struct frame
*sf
= SELECTED_FRAME ();
16447 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16450 CHECK_NUMBER (row
);
16452 if (vpos
>= 0 && vpos
< m
->nrows
)
16453 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16454 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16459 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16460 doc
: /* Toggle tracing of redisplay.
16461 With ARG, turn tracing on if and only if ARG is positive. */)
16466 trace_redisplay_p
= !trace_redisplay_p
;
16469 arg
= Fprefix_numeric_value (arg
);
16470 trace_redisplay_p
= XINT (arg
) > 0;
16477 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16478 doc
: /* Like `format', but print result to stderr.
16479 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16484 Lisp_Object s
= Fformat (nargs
, args
);
16485 fprintf (stderr
, "%s", SDATA (s
));
16489 #endif /* GLYPH_DEBUG */
16493 /***********************************************************************
16494 Building Desired Matrix Rows
16495 ***********************************************************************/
16497 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16498 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16500 static struct glyph_row
*
16501 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
16503 Lisp_Object overlay_arrow_string
;
16505 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16506 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16507 struct buffer
*old
= current_buffer
;
16508 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16509 int arrow_len
= SCHARS (overlay_arrow_string
);
16510 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16511 const unsigned char *p
;
16514 int n_glyphs_before
;
16516 set_buffer_temp (buffer
);
16517 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16518 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16519 SET_TEXT_POS (it
.position
, 0, 0);
16521 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16523 while (p
< arrow_end
)
16525 Lisp_Object face
, ilisp
;
16527 /* Get the next character. */
16529 it
.c
= string_char_and_length (p
, &it
.len
);
16531 it
.c
= *p
, it
.len
= 1;
16534 /* Get its face. */
16535 ilisp
= make_number (p
- arrow_string
);
16536 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16537 it
.face_id
= compute_char_face (f
, it
.c
, face
);
16539 /* Compute its width, get its glyphs. */
16540 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16541 SET_TEXT_POS (it
.position
, -1, -1);
16542 PRODUCE_GLYPHS (&it
);
16544 /* If this character doesn't fit any more in the line, we have
16545 to remove some glyphs. */
16546 if (it
.current_x
> it
.last_visible_x
)
16548 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16553 set_buffer_temp (old
);
16554 return it
.glyph_row
;
16558 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16559 glyphs are only inserted for terminal frames since we can't really
16560 win with truncation glyphs when partially visible glyphs are
16561 involved. Which glyphs to insert is determined by
16562 produce_special_glyphs. */
16565 insert_left_trunc_glyphs (it
)
16568 struct it truncate_it
;
16569 struct glyph
*from
, *end
, *to
, *toend
;
16571 xassert (!FRAME_WINDOW_P (it
->f
));
16573 /* Get the truncation glyphs. */
16575 truncate_it
.current_x
= 0;
16576 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16577 truncate_it
.glyph_row
= &scratch_glyph_row
;
16578 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16579 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16580 truncate_it
.object
= make_number (0);
16581 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16583 /* Overwrite glyphs from IT with truncation glyphs. */
16584 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16585 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16586 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16587 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16592 /* There may be padding glyphs left over. Overwrite them too. */
16593 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16595 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16601 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16605 /* Compute the pixel height and width of IT->glyph_row.
16607 Most of the time, ascent and height of a display line will be equal
16608 to the max_ascent and max_height values of the display iterator
16609 structure. This is not the case if
16611 1. We hit ZV without displaying anything. In this case, max_ascent
16612 and max_height will be zero.
16614 2. We have some glyphs that don't contribute to the line height.
16615 (The glyph row flag contributes_to_line_height_p is for future
16616 pixmap extensions).
16618 The first case is easily covered by using default values because in
16619 these cases, the line height does not really matter, except that it
16620 must not be zero. */
16623 compute_line_metrics (it
)
16626 struct glyph_row
*row
= it
->glyph_row
;
16629 if (FRAME_WINDOW_P (it
->f
))
16631 int i
, min_y
, max_y
;
16633 /* The line may consist of one space only, that was added to
16634 place the cursor on it. If so, the row's height hasn't been
16636 if (row
->height
== 0)
16638 if (it
->max_ascent
+ it
->max_descent
== 0)
16639 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16640 row
->ascent
= it
->max_ascent
;
16641 row
->height
= it
->max_ascent
+ it
->max_descent
;
16642 row
->phys_ascent
= it
->max_phys_ascent
;
16643 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16644 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16647 /* Compute the width of this line. */
16648 row
->pixel_width
= row
->x
;
16649 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16650 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16652 xassert (row
->pixel_width
>= 0);
16653 xassert (row
->ascent
>= 0 && row
->height
> 0);
16655 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16656 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16658 /* If first line's physical ascent is larger than its logical
16659 ascent, use the physical ascent, and make the row taller.
16660 This makes accented characters fully visible. */
16661 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16662 && row
->phys_ascent
> row
->ascent
)
16664 row
->height
+= row
->phys_ascent
- row
->ascent
;
16665 row
->ascent
= row
->phys_ascent
;
16668 /* Compute how much of the line is visible. */
16669 row
->visible_height
= row
->height
;
16671 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16672 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16674 if (row
->y
< min_y
)
16675 row
->visible_height
-= min_y
- row
->y
;
16676 if (row
->y
+ row
->height
> max_y
)
16677 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16681 row
->pixel_width
= row
->used
[TEXT_AREA
];
16682 if (row
->continued_p
)
16683 row
->pixel_width
-= it
->continuation_pixel_width
;
16684 else if (row
->truncated_on_right_p
)
16685 row
->pixel_width
-= it
->truncation_pixel_width
;
16686 row
->ascent
= row
->phys_ascent
= 0;
16687 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16688 row
->extra_line_spacing
= 0;
16691 /* Compute a hash code for this row. */
16693 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16694 for (i
= 0; i
< row
->used
[area
]; ++i
)
16695 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16696 + row
->glyphs
[area
][i
].u
.val
16697 + row
->glyphs
[area
][i
].face_id
16698 + row
->glyphs
[area
][i
].padding_p
16699 + (row
->glyphs
[area
][i
].type
<< 2));
16701 it
->max_ascent
= it
->max_descent
= 0;
16702 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16706 /* Append one space to the glyph row of iterator IT if doing a
16707 window-based redisplay. The space has the same face as
16708 IT->face_id. Value is non-zero if a space was added.
16710 This function is called to make sure that there is always one glyph
16711 at the end of a glyph row that the cursor can be set on under
16712 window-systems. (If there weren't such a glyph we would not know
16713 how wide and tall a box cursor should be displayed).
16715 At the same time this space let's a nicely handle clearing to the
16716 end of the line if the row ends in italic text. */
16719 append_space_for_newline (it
, default_face_p
)
16721 int default_face_p
;
16723 if (FRAME_WINDOW_P (it
->f
))
16725 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16727 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16728 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16730 /* Save some values that must not be changed.
16731 Must save IT->c and IT->len because otherwise
16732 ITERATOR_AT_END_P wouldn't work anymore after
16733 append_space_for_newline has been called. */
16734 enum display_element_type saved_what
= it
->what
;
16735 int saved_c
= it
->c
, saved_len
= it
->len
;
16736 int saved_x
= it
->current_x
;
16737 int saved_face_id
= it
->face_id
;
16738 struct text_pos saved_pos
;
16739 Lisp_Object saved_object
;
16742 saved_object
= it
->object
;
16743 saved_pos
= it
->position
;
16745 it
->what
= IT_CHARACTER
;
16746 bzero (&it
->position
, sizeof it
->position
);
16747 it
->object
= make_number (0);
16751 if (default_face_p
)
16752 it
->face_id
= DEFAULT_FACE_ID
;
16753 else if (it
->face_before_selective_p
)
16754 it
->face_id
= it
->saved_face_id
;
16755 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16756 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16758 PRODUCE_GLYPHS (it
);
16760 it
->override_ascent
= -1;
16761 it
->constrain_row_ascent_descent_p
= 0;
16762 it
->current_x
= saved_x
;
16763 it
->object
= saved_object
;
16764 it
->position
= saved_pos
;
16765 it
->what
= saved_what
;
16766 it
->face_id
= saved_face_id
;
16767 it
->len
= saved_len
;
16777 /* Extend the face of the last glyph in the text area of IT->glyph_row
16778 to the end of the display line. Called from display_line.
16779 If the glyph row is empty, add a space glyph to it so that we
16780 know the face to draw. Set the glyph row flag fill_line_p. */
16783 extend_face_to_end_of_line (it
)
16787 struct frame
*f
= it
->f
;
16789 /* If line is already filled, do nothing. */
16790 if (it
->current_x
>= it
->last_visible_x
)
16793 /* Face extension extends the background and box of IT->face_id
16794 to the end of the line. If the background equals the background
16795 of the frame, we don't have to do anything. */
16796 if (it
->face_before_selective_p
)
16797 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16799 face
= FACE_FROM_ID (f
, it
->face_id
);
16801 if (FRAME_WINDOW_P (f
)
16802 && it
->glyph_row
->displays_text_p
16803 && face
->box
== FACE_NO_BOX
16804 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16808 /* Set the glyph row flag indicating that the face of the last glyph
16809 in the text area has to be drawn to the end of the text area. */
16810 it
->glyph_row
->fill_line_p
= 1;
16812 /* If current character of IT is not ASCII, make sure we have the
16813 ASCII face. This will be automatically undone the next time
16814 get_next_display_element returns a multibyte character. Note
16815 that the character will always be single byte in unibyte
16817 if (!ASCII_CHAR_P (it
->c
))
16819 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16822 if (FRAME_WINDOW_P (f
))
16824 /* If the row is empty, add a space with the current face of IT,
16825 so that we know which face to draw. */
16826 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16828 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16829 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16830 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16835 /* Save some values that must not be changed. */
16836 int saved_x
= it
->current_x
;
16837 struct text_pos saved_pos
;
16838 Lisp_Object saved_object
;
16839 enum display_element_type saved_what
= it
->what
;
16840 int saved_face_id
= it
->face_id
;
16842 saved_object
= it
->object
;
16843 saved_pos
= it
->position
;
16845 it
->what
= IT_CHARACTER
;
16846 bzero (&it
->position
, sizeof it
->position
);
16847 it
->object
= make_number (0);
16850 it
->face_id
= face
->id
;
16852 PRODUCE_GLYPHS (it
);
16854 while (it
->current_x
<= it
->last_visible_x
)
16855 PRODUCE_GLYPHS (it
);
16857 /* Don't count these blanks really. It would let us insert a left
16858 truncation glyph below and make us set the cursor on them, maybe. */
16859 it
->current_x
= saved_x
;
16860 it
->object
= saved_object
;
16861 it
->position
= saved_pos
;
16862 it
->what
= saved_what
;
16863 it
->face_id
= saved_face_id
;
16868 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16869 trailing whitespace. */
16872 trailing_whitespace_p (charpos
)
16875 int bytepos
= CHAR_TO_BYTE (charpos
);
16878 while (bytepos
< ZV_BYTE
16879 && (c
= FETCH_CHAR (bytepos
),
16880 c
== ' ' || c
== '\t'))
16883 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16885 if (bytepos
!= PT_BYTE
)
16892 /* Highlight trailing whitespace, if any, in ROW. */
16895 highlight_trailing_whitespace (f
, row
)
16897 struct glyph_row
*row
;
16899 int used
= row
->used
[TEXT_AREA
];
16903 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16904 struct glyph
*glyph
= start
+ used
- 1;
16906 /* Skip over glyphs inserted to display the cursor at the
16907 end of a line, for extending the face of the last glyph
16908 to the end of the line on terminals, and for truncation
16909 and continuation glyphs. */
16910 while (glyph
>= start
16911 && glyph
->type
== CHAR_GLYPH
16912 && INTEGERP (glyph
->object
))
16915 /* If last glyph is a space or stretch, and it's trailing
16916 whitespace, set the face of all trailing whitespace glyphs in
16917 IT->glyph_row to `trailing-whitespace'. */
16919 && BUFFERP (glyph
->object
)
16920 && (glyph
->type
== STRETCH_GLYPH
16921 || (glyph
->type
== CHAR_GLYPH
16922 && glyph
->u
.ch
== ' '))
16923 && trailing_whitespace_p (glyph
->charpos
))
16925 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16929 while (glyph
>= start
16930 && BUFFERP (glyph
->object
)
16931 && (glyph
->type
== STRETCH_GLYPH
16932 || (glyph
->type
== CHAR_GLYPH
16933 && glyph
->u
.ch
== ' ')))
16934 (glyph
--)->face_id
= face_id
;
16940 /* Value is non-zero if glyph row ROW in window W should be
16941 used to hold the cursor. */
16944 cursor_row_p (w
, row
)
16946 struct glyph_row
*row
;
16948 int cursor_row_p
= 1;
16950 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16952 /* Suppose the row ends on a string.
16953 Unless the row is continued, that means it ends on a newline
16954 in the string. If it's anything other than a display string
16955 (e.g. a before-string from an overlay), we don't want the
16956 cursor there. (This heuristic seems to give the optimal
16957 behavior for the various types of multi-line strings.) */
16958 if (CHARPOS (row
->end
.string_pos
) >= 0)
16960 if (row
->continued_p
)
16964 /* Check for `display' property. */
16965 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16966 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16967 struct glyph
*glyph
;
16970 for (glyph
= end
; glyph
>= beg
; --glyph
)
16971 if (STRINGP (glyph
->object
))
16974 = Fget_char_property (make_number (PT
),
16978 && display_prop_string_p (prop
, glyph
->object
));
16983 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16985 /* If the row ends in middle of a real character,
16986 and the line is continued, we want the cursor here.
16987 That's because MATRIX_ROW_END_CHARPOS would equal
16988 PT if PT is before the character. */
16989 if (!row
->ends_in_ellipsis_p
)
16990 cursor_row_p
= row
->continued_p
;
16992 /* If the row ends in an ellipsis, then
16993 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16994 We want that position to be displayed after the ellipsis. */
16997 /* If the row ends at ZV, display the cursor at the end of that
16998 row instead of at the start of the row below. */
16999 else if (row
->ends_at_zv_p
)
17005 return cursor_row_p
;
17010 /* Push the display property PROP so that it will be rendered at the
17011 current position in IT. Return 1 if PROP was successfully pushed,
17015 push_display_prop (struct it
*it
, Lisp_Object prop
)
17019 if (STRINGP (prop
))
17021 if (SCHARS (prop
) == 0)
17028 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17029 it
->current
.overlay_string_index
= -1;
17030 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17031 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17032 it
->method
= GET_FROM_STRING
;
17033 it
->stop_charpos
= 0;
17035 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17037 it
->method
= GET_FROM_STRETCH
;
17040 #ifdef HAVE_WINDOW_SYSTEM
17041 else if (IMAGEP (prop
))
17043 it
->what
= IT_IMAGE
;
17044 it
->image_id
= lookup_image (it
->f
, prop
);
17045 it
->method
= GET_FROM_IMAGE
;
17047 #endif /* HAVE_WINDOW_SYSTEM */
17050 pop_it (it
); /* bogus display property, give up */
17057 /* Return the character-property PROP at the current position in IT. */
17060 get_it_property (it
, prop
)
17064 Lisp_Object position
;
17066 if (STRINGP (it
->object
))
17067 position
= make_number (IT_STRING_CHARPOS (*it
));
17068 else if (BUFFERP (it
->object
))
17069 position
= make_number (IT_CHARPOS (*it
));
17073 return Fget_char_property (position
, prop
, it
->object
);
17076 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17079 handle_line_prefix (struct it
*it
)
17081 Lisp_Object prefix
;
17082 if (it
->continuation_lines_width
> 0)
17084 prefix
= get_it_property (it
, Qwrap_prefix
);
17086 prefix
= Vwrap_prefix
;
17090 prefix
= get_it_property (it
, Qline_prefix
);
17092 prefix
= Vline_prefix
;
17094 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17096 /* If the prefix is wider than the window, and we try to wrap
17097 it, it would acquire its own wrap prefix, and so on till the
17098 iterator stack overflows. So, don't wrap the prefix. */
17099 it
->line_wrap
= TRUNCATE
;
17100 it
->avoid_cursor_p
= 1;
17106 /* Construct the glyph row IT->glyph_row in the desired matrix of
17107 IT->w from text at the current position of IT. See dispextern.h
17108 for an overview of struct it. Value is non-zero if
17109 IT->glyph_row displays text, as opposed to a line displaying ZV
17116 struct glyph_row
*row
= it
->glyph_row
;
17117 Lisp_Object overlay_arrow_string
;
17119 int may_wrap
= 0, wrap_x
;
17120 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
17121 int wrap_row_phys_ascent
, wrap_row_phys_height
;
17122 int wrap_row_extra_line_spacing
;
17123 struct display_pos row_end
;
17126 /* We always start displaying at hpos zero even if hscrolled. */
17127 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17129 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17130 >= it
->w
->desired_matrix
->nrows
)
17132 it
->w
->nrows_scale_factor
++;
17133 fonts_changed_p
= 1;
17137 /* Is IT->w showing the region? */
17138 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17140 /* Clear the result glyph row and enable it. */
17141 prepare_desired_row (row
);
17143 row
->y
= it
->current_y
;
17144 row
->start
= it
->start
;
17145 row
->continuation_lines_width
= it
->continuation_lines_width
;
17146 row
->displays_text_p
= 1;
17147 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17148 it
->starts_in_middle_of_char_p
= 0;
17150 /* Arrange the overlays nicely for our purposes. Usually, we call
17151 display_line on only one line at a time, in which case this
17152 can't really hurt too much, or we call it on lines which appear
17153 one after another in the buffer, in which case all calls to
17154 recenter_overlay_lists but the first will be pretty cheap. */
17155 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17157 /* Move over display elements that are not visible because we are
17158 hscrolled. This may stop at an x-position < IT->first_visible_x
17159 if the first glyph is partially visible or if we hit a line end. */
17160 if (it
->current_x
< it
->first_visible_x
)
17162 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17163 MOVE_TO_POS
| MOVE_TO_X
);
17167 /* We only do this when not calling `move_it_in_display_line_to'
17168 above, because move_it_in_display_line_to calls
17169 handle_line_prefix itself. */
17170 handle_line_prefix (it
);
17173 /* Get the initial row height. This is either the height of the
17174 text hscrolled, if there is any, or zero. */
17175 row
->ascent
= it
->max_ascent
;
17176 row
->height
= it
->max_ascent
+ it
->max_descent
;
17177 row
->phys_ascent
= it
->max_phys_ascent
;
17178 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17179 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17181 /* Loop generating characters. The loop is left with IT on the next
17182 character to display. */
17185 int n_glyphs_before
, hpos_before
, x_before
;
17187 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17189 /* Retrieve the next thing to display. Value is zero if end of
17191 if (!get_next_display_element (it
))
17193 /* Maybe add a space at the end of this line that is used to
17194 display the cursor there under X. Set the charpos of the
17195 first glyph of blank lines not corresponding to any text
17197 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17198 row
->exact_window_width_line_p
= 1;
17199 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17200 || row
->used
[TEXT_AREA
] == 0)
17202 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17203 row
->displays_text_p
= 0;
17205 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17206 && (!MINI_WINDOW_P (it
->w
)
17207 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17208 row
->indicate_empty_line_p
= 1;
17211 it
->continuation_lines_width
= 0;
17212 row
->ends_at_zv_p
= 1;
17213 /* A row that displays right-to-left text must always have
17214 its last face extended all the way to the end of line,
17215 even if this row ends in ZV. */
17216 if (row
->reversed_p
)
17217 extend_face_to_end_of_line (it
);
17221 /* Now, get the metrics of what we want to display. This also
17222 generates glyphs in `row' (which is IT->glyph_row). */
17223 n_glyphs_before
= row
->used
[TEXT_AREA
];
17226 /* Remember the line height so far in case the next element doesn't
17227 fit on the line. */
17228 if (it
->line_wrap
!= TRUNCATE
)
17230 ascent
= it
->max_ascent
;
17231 descent
= it
->max_descent
;
17232 phys_ascent
= it
->max_phys_ascent
;
17233 phys_descent
= it
->max_phys_descent
;
17235 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17237 if (IT_DISPLAYING_WHITESPACE (it
))
17243 wrap_row_used
= row
->used
[TEXT_AREA
];
17244 wrap_row_ascent
= row
->ascent
;
17245 wrap_row_height
= row
->height
;
17246 wrap_row_phys_ascent
= row
->phys_ascent
;
17247 wrap_row_phys_height
= row
->phys_height
;
17248 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17254 PRODUCE_GLYPHS (it
);
17256 /* If this display element was in marginal areas, continue with
17258 if (it
->area
!= TEXT_AREA
)
17260 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17261 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17262 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17263 row
->phys_height
= max (row
->phys_height
,
17264 it
->max_phys_ascent
+ it
->max_phys_descent
);
17265 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17266 it
->max_extra_line_spacing
);
17267 set_iterator_to_next (it
, 1);
17271 /* Does the display element fit on the line? If we truncate
17272 lines, we should draw past the right edge of the window. If
17273 we don't truncate, we want to stop so that we can display the
17274 continuation glyph before the right margin. If lines are
17275 continued, there are two possible strategies for characters
17276 resulting in more than 1 glyph (e.g. tabs): Display as many
17277 glyphs as possible in this line and leave the rest for the
17278 continuation line, or display the whole element in the next
17279 line. Original redisplay did the former, so we do it also. */
17280 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17281 hpos_before
= it
->hpos
;
17284 if (/* Not a newline. */
17286 /* Glyphs produced fit entirely in the line. */
17287 && it
->current_x
< it
->last_visible_x
)
17289 it
->hpos
+= nglyphs
;
17290 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17291 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17292 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17293 row
->phys_height
= max (row
->phys_height
,
17294 it
->max_phys_ascent
+ it
->max_phys_descent
);
17295 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17296 it
->max_extra_line_spacing
);
17297 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17298 row
->x
= x
- it
->first_visible_x
;
17303 struct glyph
*glyph
;
17305 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17307 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17308 new_x
= x
+ glyph
->pixel_width
;
17310 if (/* Lines are continued. */
17311 it
->line_wrap
!= TRUNCATE
17312 && (/* Glyph doesn't fit on the line. */
17313 new_x
> it
->last_visible_x
17314 /* Or it fits exactly on a window system frame. */
17315 || (new_x
== it
->last_visible_x
17316 && FRAME_WINDOW_P (it
->f
))))
17318 /* End of a continued line. */
17321 || (new_x
== it
->last_visible_x
17322 && FRAME_WINDOW_P (it
->f
)))
17324 /* Current glyph is the only one on the line or
17325 fits exactly on the line. We must continue
17326 the line because we can't draw the cursor
17327 after the glyph. */
17328 row
->continued_p
= 1;
17329 it
->current_x
= new_x
;
17330 it
->continuation_lines_width
+= new_x
;
17332 if (i
== nglyphs
- 1)
17334 /* If line-wrap is on, check if a previous
17335 wrap point was found. */
17336 if (wrap_row_used
> 0
17337 /* Even if there is a previous wrap
17338 point, continue the line here as
17339 usual, if (i) the previous character
17340 was a space or tab AND (ii) the
17341 current character is not. */
17343 || IT_DISPLAYING_WHITESPACE (it
)))
17346 set_iterator_to_next (it
, 1);
17347 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17349 if (!get_next_display_element (it
))
17351 row
->exact_window_width_line_p
= 1;
17352 it
->continuation_lines_width
= 0;
17353 row
->continued_p
= 0;
17354 row
->ends_at_zv_p
= 1;
17356 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17358 row
->continued_p
= 0;
17359 row
->exact_window_width_line_p
= 1;
17364 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17365 && !FRAME_WINDOW_P (it
->f
))
17367 /* A padding glyph that doesn't fit on this line.
17368 This means the whole character doesn't fit
17370 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17372 /* Fill the rest of the row with continuation
17373 glyphs like in 20.x. */
17374 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17375 < row
->glyphs
[1 + TEXT_AREA
])
17376 produce_special_glyphs (it
, IT_CONTINUATION
);
17378 row
->continued_p
= 1;
17379 it
->current_x
= x_before
;
17380 it
->continuation_lines_width
+= x_before
;
17382 /* Restore the height to what it was before the
17383 element not fitting on the line. */
17384 it
->max_ascent
= ascent
;
17385 it
->max_descent
= descent
;
17386 it
->max_phys_ascent
= phys_ascent
;
17387 it
->max_phys_descent
= phys_descent
;
17389 else if (wrap_row_used
> 0)
17393 it
->continuation_lines_width
+= wrap_x
;
17394 row
->used
[TEXT_AREA
] = wrap_row_used
;
17395 row
->ascent
= wrap_row_ascent
;
17396 row
->height
= wrap_row_height
;
17397 row
->phys_ascent
= wrap_row_phys_ascent
;
17398 row
->phys_height
= wrap_row_phys_height
;
17399 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17400 row
->continued_p
= 1;
17401 row
->ends_at_zv_p
= 0;
17402 row
->exact_window_width_line_p
= 0;
17403 it
->continuation_lines_width
+= x
;
17405 /* Make sure that a non-default face is extended
17406 up to the right margin of the window. */
17407 extend_face_to_end_of_line (it
);
17409 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17411 /* A TAB that extends past the right edge of the
17412 window. This produces a single glyph on
17413 window system frames. We leave the glyph in
17414 this row and let it fill the row, but don't
17415 consume the TAB. */
17416 it
->continuation_lines_width
+= it
->last_visible_x
;
17417 row
->ends_in_middle_of_char_p
= 1;
17418 row
->continued_p
= 1;
17419 glyph
->pixel_width
= it
->last_visible_x
- x
;
17420 it
->starts_in_middle_of_char_p
= 1;
17424 /* Something other than a TAB that draws past
17425 the right edge of the window. Restore
17426 positions to values before the element. */
17427 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17429 /* Display continuation glyphs. */
17430 if (!FRAME_WINDOW_P (it
->f
))
17431 produce_special_glyphs (it
, IT_CONTINUATION
);
17432 row
->continued_p
= 1;
17434 it
->current_x
= x_before
;
17435 it
->continuation_lines_width
+= x
;
17436 extend_face_to_end_of_line (it
);
17438 if (nglyphs
> 1 && i
> 0)
17440 row
->ends_in_middle_of_char_p
= 1;
17441 it
->starts_in_middle_of_char_p
= 1;
17444 /* Restore the height to what it was before the
17445 element not fitting on the line. */
17446 it
->max_ascent
= ascent
;
17447 it
->max_descent
= descent
;
17448 it
->max_phys_ascent
= phys_ascent
;
17449 it
->max_phys_descent
= phys_descent
;
17454 else if (new_x
> it
->first_visible_x
)
17456 /* Increment number of glyphs actually displayed. */
17459 if (x
< it
->first_visible_x
)
17460 /* Glyph is partially visible, i.e. row starts at
17461 negative X position. */
17462 row
->x
= x
- it
->first_visible_x
;
17466 /* Glyph is completely off the left margin of the
17467 window. This should not happen because of the
17468 move_it_in_display_line at the start of this
17469 function, unless the text display area of the
17470 window is empty. */
17471 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17475 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17476 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17477 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17478 row
->phys_height
= max (row
->phys_height
,
17479 it
->max_phys_ascent
+ it
->max_phys_descent
);
17480 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17481 it
->max_extra_line_spacing
);
17483 /* End of this display line if row is continued. */
17484 if (row
->continued_p
|| row
->ends_at_zv_p
)
17489 /* Is this a line end? If yes, we're also done, after making
17490 sure that a non-default face is extended up to the right
17491 margin of the window. */
17492 if (ITERATOR_AT_END_OF_LINE_P (it
))
17494 int used_before
= row
->used
[TEXT_AREA
];
17496 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17498 /* Add a space at the end of the line that is used to
17499 display the cursor there. */
17500 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17501 append_space_for_newline (it
, 0);
17503 /* Extend the face to the end of the line. */
17504 extend_face_to_end_of_line (it
);
17506 /* Make sure we have the position. */
17507 if (used_before
== 0)
17508 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17510 /* Consume the line end. This skips over invisible lines. */
17511 set_iterator_to_next (it
, 1);
17512 it
->continuation_lines_width
= 0;
17516 /* Proceed with next display element. Note that this skips
17517 over lines invisible because of selective display. */
17518 set_iterator_to_next (it
, 1);
17520 /* If we truncate lines, we are done when the last displayed
17521 glyphs reach past the right margin of the window. */
17522 if (it
->line_wrap
== TRUNCATE
17523 && (FRAME_WINDOW_P (it
->f
)
17524 ? (it
->current_x
>= it
->last_visible_x
)
17525 : (it
->current_x
> it
->last_visible_x
)))
17527 /* Maybe add truncation glyphs. */
17528 if (!FRAME_WINDOW_P (it
->f
))
17532 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17533 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17536 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17538 row
->used
[TEXT_AREA
] = i
;
17539 produce_special_glyphs (it
, IT_TRUNCATION
);
17542 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17544 /* Don't truncate if we can overflow newline into fringe. */
17545 if (!get_next_display_element (it
))
17547 it
->continuation_lines_width
= 0;
17548 row
->ends_at_zv_p
= 1;
17549 row
->exact_window_width_line_p
= 1;
17552 if (ITERATOR_AT_END_OF_LINE_P (it
))
17554 row
->exact_window_width_line_p
= 1;
17555 goto at_end_of_line
;
17559 row
->truncated_on_right_p
= 1;
17560 it
->continuation_lines_width
= 0;
17561 reseat_at_next_visible_line_start (it
, 0);
17562 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17563 it
->hpos
= hpos_before
;
17564 it
->current_x
= x_before
;
17569 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17570 at the left window margin. */
17571 if (it
->first_visible_x
17572 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
17574 if (!FRAME_WINDOW_P (it
->f
))
17575 insert_left_trunc_glyphs (it
);
17576 row
->truncated_on_left_p
= 1;
17579 /* If the start of this line is the overlay arrow-position, then
17580 mark this glyph row as the one containing the overlay arrow.
17581 This is clearly a mess with variable size fonts. It would be
17582 better to let it be displayed like cursors under X. */
17583 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17584 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17585 !NILP (overlay_arrow_string
)))
17587 /* Overlay arrow in window redisplay is a fringe bitmap. */
17588 if (STRINGP (overlay_arrow_string
))
17590 struct glyph_row
*arrow_row
17591 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17592 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17593 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17594 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17595 struct glyph
*p2
, *end
;
17597 /* Copy the arrow glyphs. */
17598 while (glyph
< arrow_end
)
17601 /* Throw away padding glyphs. */
17603 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17604 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17610 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17615 xassert (INTEGERP (overlay_arrow_string
));
17616 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17618 overlay_arrow_seen
= 1;
17621 /* Compute pixel dimensions of this line. */
17622 compute_line_metrics (it
);
17624 /* Remember the position at which this line ends. */
17625 row
->end
= row_end
= it
->current
;
17628 /* ROW->start and ROW->end must be the smallest and largest
17629 buffer positions in ROW. But if ROW was bidi-reordered,
17630 these two positions can be anywhere in the row, so we must
17631 rescan all of the ROW's glyphs to find them. */
17632 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17633 lines' rows is implemented for bidi-reordered rows. */
17634 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17637 struct text_pos tpos
;
17639 for (g
= row
->glyphs
[TEXT_AREA
];
17640 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17643 if (BUFFERP (g
->object
))
17645 if (g
->charpos
> 0 && g
->charpos
< min_pos
)
17646 min_pos
= g
->charpos
;
17647 if (g
->charpos
> max_pos
)
17648 max_pos
= g
->charpos
;
17651 /* Empty lines have a valid buffer position at their first
17652 glyph, but that glyph's OBJECT is zero, as if it didn't come
17653 from a buffer. If we didn't find any valid buffer positions
17654 in this row, maybe we have such an empty line. */
17655 if (min_pos
== ZV
+ 1 && row
->used
[TEXT_AREA
])
17657 for (g
= row
->glyphs
[TEXT_AREA
];
17658 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17661 if (INTEGERP (g
->object
))
17663 if (g
->charpos
> 0 && g
->charpos
< min_pos
)
17664 min_pos
= g
->charpos
;
17665 if (g
->charpos
> max_pos
)
17666 max_pos
= g
->charpos
;
17672 if (min_pos
!= row
->start
.pos
.charpos
)
17674 row
->start
.pos
.charpos
= min_pos
;
17675 row
->start
.pos
.bytepos
= CHAR_TO_BYTE (min_pos
);
17680 /* For ROW->end, we need the position that is _after_ max_pos,
17681 in the logical order, unless we are at ZV. */
17682 if (row
->ends_at_zv_p
)
17684 row_end
= row
->end
= it
->current
;
17685 if (!row
->used
[TEXT_AREA
])
17687 row
->start
.pos
.charpos
= row_end
.pos
.charpos
;
17688 row
->start
.pos
.bytepos
= row_end
.pos
.bytepos
;
17691 else if (row
->used
[TEXT_AREA
] && max_pos
)
17693 SET_TEXT_POS (tpos
, max_pos
+ 1, CHAR_TO_BYTE (max_pos
+ 1));
17694 row_end
= it
->current
;
17695 row_end
.pos
= tpos
;
17696 /* If the character at max_pos+1 is a newline, skip that as
17697 well. Note that this may skip some invisible text. */
17698 if (FETCH_CHAR (tpos
.bytepos
) == '\n'
17699 || (FETCH_CHAR (tpos
.bytepos
) == '\r' && it
->selective
))
17703 reseat_1 (it
, tpos
, 0);
17704 set_iterator_to_next (it
, 1);
17705 /* Record the position after the newline of a continued
17706 row. We will need that to set ROW->end of the last
17707 row produced for a continued line. */
17708 if (row
->continued_p
)
17710 save_it
.eol_pos
.charpos
= IT_CHARPOS (*it
);
17711 save_it
.eol_pos
.bytepos
= IT_BYTEPOS (*it
);
17715 row_end
= it
->current
;
17716 save_it
.eol_pos
.charpos
= save_it
.eol_pos
.bytepos
= 0;
17720 else if (!row
->continued_p
17721 && row
->continuation_lines_width
17722 && it
->eol_pos
.charpos
> 0)
17724 /* Last row of a continued line. Use the position
17725 recorded in ROW->eol_pos, to the effect that the
17726 newline belongs to this row, not to the row which
17727 displays the character with the largest buffer
17729 row_end
.pos
= it
->eol_pos
;
17730 it
->eol_pos
.charpos
= it
->eol_pos
.bytepos
= 0;
17732 row
->end
= row_end
;
17736 /* Record whether this row ends inside an ellipsis. */
17737 row
->ends_in_ellipsis_p
17738 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17739 && it
->ellipsis_p
);
17741 /* Save fringe bitmaps in this row. */
17742 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17743 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17744 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17745 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17747 it
->left_user_fringe_bitmap
= 0;
17748 it
->left_user_fringe_face_id
= 0;
17749 it
->right_user_fringe_bitmap
= 0;
17750 it
->right_user_fringe_face_id
= 0;
17752 /* Maybe set the cursor. */
17753 cvpos
= it
->w
->cursor
.vpos
;
17755 /* In bidi-reordered rows, keep checking for proper cursor
17756 position even if one has been found already, because buffer
17757 positions in such rows change non-linearly with ROW->VPOS,
17758 when a line is continued. One exception: when we are at ZV,
17759 display cursor on the first suitable glyph row, since all
17760 the empty rows after that also have their position set to ZV. */
17761 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17762 lines' rows is implemented for bidi-reordered rows. */
17764 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
17765 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17766 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17767 && cursor_row_p (it
->w
, row
))
17768 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17770 /* Highlight trailing whitespace. */
17771 if (!NILP (Vshow_trailing_whitespace
))
17772 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17774 /* Prepare for the next line. This line starts horizontally at (X
17775 HPOS) = (0 0). Vertical positions are incremented. As a
17776 convenience for the caller, IT->glyph_row is set to the next
17778 it
->current_x
= it
->hpos
= 0;
17779 it
->current_y
+= row
->height
;
17782 /* The next row should use same value of the reversed_p flag as this
17783 one. set_iterator_to_next decides when it's a new paragraph, and
17784 PRODUCE_GLYPHS recomputes the value of the flag accordingly. */
17785 it
->glyph_row
->reversed_p
= row
->reversed_p
;
17786 it
->start
= row_end
;
17787 return row
->displays_text_p
;
17792 /***********************************************************************
17794 ***********************************************************************/
17796 /* Redisplay the menu bar in the frame for window W.
17798 The menu bar of X frames that don't have X toolkit support is
17799 displayed in a special window W->frame->menu_bar_window.
17801 The menu bar of terminal frames is treated specially as far as
17802 glyph matrices are concerned. Menu bar lines are not part of
17803 windows, so the update is done directly on the frame matrix rows
17804 for the menu bar. */
17807 display_menu_bar (w
)
17810 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17815 /* Don't do all this for graphical frames. */
17817 if (FRAME_W32_P (f
))
17820 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17826 if (FRAME_NS_P (f
))
17828 #endif /* HAVE_NS */
17830 #ifdef USE_X_TOOLKIT
17831 xassert (!FRAME_WINDOW_P (f
));
17832 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17833 it
.first_visible_x
= 0;
17834 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17835 #else /* not USE_X_TOOLKIT */
17836 if (FRAME_WINDOW_P (f
))
17838 /* Menu bar lines are displayed in the desired matrix of the
17839 dummy window menu_bar_window. */
17840 struct window
*menu_w
;
17841 xassert (WINDOWP (f
->menu_bar_window
));
17842 menu_w
= XWINDOW (f
->menu_bar_window
);
17843 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17845 it
.first_visible_x
= 0;
17846 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17850 /* This is a TTY frame, i.e. character hpos/vpos are used as
17852 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17854 it
.first_visible_x
= 0;
17855 it
.last_visible_x
= FRAME_COLS (f
);
17857 #endif /* not USE_X_TOOLKIT */
17859 if (! mode_line_inverse_video
)
17860 /* Force the menu-bar to be displayed in the default face. */
17861 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17863 /* Clear all rows of the menu bar. */
17864 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17866 struct glyph_row
*row
= it
.glyph_row
+ i
;
17867 clear_glyph_row (row
);
17868 row
->enabled_p
= 1;
17869 row
->full_width_p
= 1;
17872 /* Display all items of the menu bar. */
17873 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17874 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17876 Lisp_Object string
;
17878 /* Stop at nil string. */
17879 string
= AREF (items
, i
+ 1);
17883 /* Remember where item was displayed. */
17884 ASET (items
, i
+ 3, make_number (it
.hpos
));
17886 /* Display the item, pad with one space. */
17887 if (it
.current_x
< it
.last_visible_x
)
17888 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17889 SCHARS (string
) + 1, 0, 0, -1);
17892 /* Fill out the line with spaces. */
17893 if (it
.current_x
< it
.last_visible_x
)
17894 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17896 /* Compute the total height of the lines. */
17897 compute_line_metrics (&it
);
17902 /***********************************************************************
17904 ***********************************************************************/
17906 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17907 FORCE is non-zero, redisplay mode lines unconditionally.
17908 Otherwise, redisplay only mode lines that are garbaged. Value is
17909 the number of windows whose mode lines were redisplayed. */
17912 redisplay_mode_lines (window
, force
)
17913 Lisp_Object window
;
17918 while (!NILP (window
))
17920 struct window
*w
= XWINDOW (window
);
17922 if (WINDOWP (w
->hchild
))
17923 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17924 else if (WINDOWP (w
->vchild
))
17925 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17927 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17928 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17930 struct text_pos lpoint
;
17931 struct buffer
*old
= current_buffer
;
17933 /* Set the window's buffer for the mode line display. */
17934 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17935 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17937 /* Point refers normally to the selected window. For any
17938 other window, set up appropriate value. */
17939 if (!EQ (window
, selected_window
))
17941 struct text_pos pt
;
17943 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17944 if (CHARPOS (pt
) < BEGV
)
17945 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17946 else if (CHARPOS (pt
) > (ZV
- 1))
17947 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17949 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17952 /* Display mode lines. */
17953 clear_glyph_matrix (w
->desired_matrix
);
17954 if (display_mode_lines (w
))
17957 w
->must_be_updated_p
= 1;
17960 /* Restore old settings. */
17961 set_buffer_internal_1 (old
);
17962 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17972 /* Display the mode and/or header line of window W. Value is the
17973 sum number of mode lines and header lines displayed. */
17976 display_mode_lines (w
)
17979 Lisp_Object old_selected_window
, old_selected_frame
;
17982 old_selected_frame
= selected_frame
;
17983 selected_frame
= w
->frame
;
17984 old_selected_window
= selected_window
;
17985 XSETWINDOW (selected_window
, w
);
17987 /* These will be set while the mode line specs are processed. */
17988 line_number_displayed
= 0;
17989 w
->column_number_displayed
= Qnil
;
17991 if (WINDOW_WANTS_MODELINE_P (w
))
17993 struct window
*sel_w
= XWINDOW (old_selected_window
);
17995 /* Select mode line face based on the real selected window. */
17996 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17997 current_buffer
->mode_line_format
);
18001 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18003 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18004 current_buffer
->header_line_format
);
18008 selected_frame
= old_selected_frame
;
18009 selected_window
= old_selected_window
;
18014 /* Display mode or header line of window W. FACE_ID specifies which
18015 line to display; it is either MODE_LINE_FACE_ID or
18016 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18017 display. Value is the pixel height of the mode/header line
18021 display_mode_line (w
, face_id
, format
)
18023 enum face_id face_id
;
18024 Lisp_Object format
;
18028 int count
= SPECPDL_INDEX ();
18030 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18031 /* Don't extend on a previously drawn mode-line.
18032 This may happen if called from pos_visible_p. */
18033 it
.glyph_row
->enabled_p
= 0;
18034 prepare_desired_row (it
.glyph_row
);
18036 it
.glyph_row
->mode_line_p
= 1;
18038 if (! mode_line_inverse_video
)
18039 /* Force the mode-line to be displayed in the default face. */
18040 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18042 record_unwind_protect (unwind_format_mode_line
,
18043 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18045 mode_line_target
= MODE_LINE_DISPLAY
;
18047 /* Temporarily make frame's keyboard the current kboard so that
18048 kboard-local variables in the mode_line_format will get the right
18050 push_kboard (FRAME_KBOARD (it
.f
));
18051 record_unwind_save_match_data ();
18052 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18055 unbind_to (count
, Qnil
);
18057 /* Fill up with spaces. */
18058 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18060 compute_line_metrics (&it
);
18061 it
.glyph_row
->full_width_p
= 1;
18062 it
.glyph_row
->continued_p
= 0;
18063 it
.glyph_row
->truncated_on_left_p
= 0;
18064 it
.glyph_row
->truncated_on_right_p
= 0;
18066 /* Make a 3D mode-line have a shadow at its right end. */
18067 face
= FACE_FROM_ID (it
.f
, face_id
);
18068 extend_face_to_end_of_line (&it
);
18069 if (face
->box
!= FACE_NO_BOX
)
18071 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18072 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18073 last
->right_box_line_p
= 1;
18076 return it
.glyph_row
->height
;
18079 /* Move element ELT in LIST to the front of LIST.
18080 Return the updated list. */
18083 move_elt_to_front (elt
, list
)
18084 Lisp_Object elt
, list
;
18086 register Lisp_Object tail
, prev
;
18087 register Lisp_Object tem
;
18091 while (CONSP (tail
))
18097 /* Splice out the link TAIL. */
18099 list
= XCDR (tail
);
18101 Fsetcdr (prev
, XCDR (tail
));
18103 /* Now make it the first. */
18104 Fsetcdr (tail
, list
);
18109 tail
= XCDR (tail
);
18113 /* Not found--return unchanged LIST. */
18117 /* Contribute ELT to the mode line for window IT->w. How it
18118 translates into text depends on its data type.
18120 IT describes the display environment in which we display, as usual.
18122 DEPTH is the depth in recursion. It is used to prevent
18123 infinite recursion here.
18125 FIELD_WIDTH is the number of characters the display of ELT should
18126 occupy in the mode line, and PRECISION is the maximum number of
18127 characters to display from ELT's representation. See
18128 display_string for details.
18130 Returns the hpos of the end of the text generated by ELT.
18132 PROPS is a property list to add to any string we encounter.
18134 If RISKY is nonzero, remove (disregard) any properties in any string
18135 we encounter, and ignore :eval and :propertize.
18137 The global variable `mode_line_target' determines whether the
18138 output is passed to `store_mode_line_noprop',
18139 `store_mode_line_string', or `display_string'. */
18142 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
18145 int field_width
, precision
;
18146 Lisp_Object elt
, props
;
18149 int n
= 0, field
, prec
;
18154 elt
= build_string ("*too-deep*");
18158 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18162 /* A string: output it and check for %-constructs within it. */
18166 if (SCHARS (elt
) > 0
18167 && (!NILP (props
) || risky
))
18169 Lisp_Object oprops
, aelt
;
18170 oprops
= Ftext_properties_at (make_number (0), elt
);
18172 /* If the starting string's properties are not what
18173 we want, translate the string. Also, if the string
18174 is risky, do that anyway. */
18176 if (NILP (Fequal (props
, oprops
)) || risky
)
18178 /* If the starting string has properties,
18179 merge the specified ones onto the existing ones. */
18180 if (! NILP (oprops
) && !risky
)
18184 oprops
= Fcopy_sequence (oprops
);
18186 while (CONSP (tem
))
18188 oprops
= Fplist_put (oprops
, XCAR (tem
),
18189 XCAR (XCDR (tem
)));
18190 tem
= XCDR (XCDR (tem
));
18195 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18196 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18198 /* AELT is what we want. Move it to the front
18199 without consing. */
18201 mode_line_proptrans_alist
18202 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18208 /* If AELT has the wrong props, it is useless.
18209 so get rid of it. */
18211 mode_line_proptrans_alist
18212 = Fdelq (aelt
, mode_line_proptrans_alist
);
18214 elt
= Fcopy_sequence (elt
);
18215 Fset_text_properties (make_number (0), Flength (elt
),
18217 /* Add this item to mode_line_proptrans_alist. */
18218 mode_line_proptrans_alist
18219 = Fcons (Fcons (elt
, props
),
18220 mode_line_proptrans_alist
);
18221 /* Truncate mode_line_proptrans_alist
18222 to at most 50 elements. */
18223 tem
= Fnthcdr (make_number (50),
18224 mode_line_proptrans_alist
);
18226 XSETCDR (tem
, Qnil
);
18235 prec
= precision
- n
;
18236 switch (mode_line_target
)
18238 case MODE_LINE_NOPROP
:
18239 case MODE_LINE_TITLE
:
18240 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
18242 case MODE_LINE_STRING
:
18243 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18245 case MODE_LINE_DISPLAY
:
18246 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18247 0, prec
, 0, STRING_MULTIBYTE (elt
));
18254 /* Handle the non-literal case. */
18256 while ((precision
<= 0 || n
< precision
)
18257 && SREF (elt
, offset
) != 0
18258 && (mode_line_target
!= MODE_LINE_DISPLAY
18259 || it
->current_x
< it
->last_visible_x
))
18261 int last_offset
= offset
;
18263 /* Advance to end of string or next format specifier. */
18264 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18267 if (offset
- 1 != last_offset
)
18269 int nchars
, nbytes
;
18271 /* Output to end of string or up to '%'. Field width
18272 is length of string. Don't output more than
18273 PRECISION allows us. */
18276 prec
= c_string_width (SDATA (elt
) + last_offset
,
18277 offset
- last_offset
, precision
- n
,
18280 switch (mode_line_target
)
18282 case MODE_LINE_NOPROP
:
18283 case MODE_LINE_TITLE
:
18284 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18286 case MODE_LINE_STRING
:
18288 int bytepos
= last_offset
;
18289 int charpos
= string_byte_to_char (elt
, bytepos
);
18290 int endpos
= (precision
<= 0
18291 ? string_byte_to_char (elt
, offset
)
18292 : charpos
+ nchars
);
18294 n
+= store_mode_line_string (NULL
,
18295 Fsubstring (elt
, make_number (charpos
),
18296 make_number (endpos
)),
18300 case MODE_LINE_DISPLAY
:
18302 int bytepos
= last_offset
;
18303 int charpos
= string_byte_to_char (elt
, bytepos
);
18305 if (precision
<= 0)
18306 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18307 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18309 STRING_MULTIBYTE (elt
));
18314 else /* c == '%' */
18316 int percent_position
= offset
;
18318 /* Get the specified minimum width. Zero means
18321 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18322 field
= field
* 10 + c
- '0';
18324 /* Don't pad beyond the total padding allowed. */
18325 if (field_width
- n
> 0 && field
> field_width
- n
)
18326 field
= field_width
- n
;
18328 /* Note that either PRECISION <= 0 or N < PRECISION. */
18329 prec
= precision
- n
;
18332 n
+= display_mode_element (it
, depth
, field
, prec
,
18333 Vglobal_mode_string
, props
,
18338 int bytepos
, charpos
;
18339 unsigned char *spec
;
18340 Lisp_Object string
;
18342 bytepos
= percent_position
;
18343 charpos
= (STRING_MULTIBYTE (elt
)
18344 ? string_byte_to_char (elt
, bytepos
)
18346 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
18347 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18349 switch (mode_line_target
)
18351 case MODE_LINE_NOPROP
:
18352 case MODE_LINE_TITLE
:
18353 n
+= store_mode_line_noprop (spec
, field
, prec
);
18355 case MODE_LINE_STRING
:
18357 int len
= strlen (spec
);
18358 Lisp_Object tem
= make_string (spec
, len
);
18359 props
= Ftext_properties_at (make_number (charpos
), elt
);
18360 /* Should only keep face property in props */
18361 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18364 case MODE_LINE_DISPLAY
:
18366 int nglyphs_before
, nwritten
;
18368 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18369 nwritten
= display_string (spec
, string
, elt
,
18374 /* Assign to the glyphs written above the
18375 string where the `%x' came from, position
18379 struct glyph
*glyph
18380 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18384 for (i
= 0; i
< nwritten
; ++i
)
18386 glyph
[i
].object
= elt
;
18387 glyph
[i
].charpos
= charpos
;
18404 /* A symbol: process the value of the symbol recursively
18405 as if it appeared here directly. Avoid error if symbol void.
18406 Special case: if value of symbol is a string, output the string
18409 register Lisp_Object tem
;
18411 /* If the variable is not marked as risky to set
18412 then its contents are risky to use. */
18413 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18416 tem
= Fboundp (elt
);
18419 tem
= Fsymbol_value (elt
);
18420 /* If value is a string, output that string literally:
18421 don't check for % within it. */
18425 if (!EQ (tem
, elt
))
18427 /* Give up right away for nil or t. */
18437 register Lisp_Object car
, tem
;
18439 /* A cons cell: five distinct cases.
18440 If first element is :eval or :propertize, do something special.
18441 If first element is a string or a cons, process all the elements
18442 and effectively concatenate them.
18443 If first element is a negative number, truncate displaying cdr to
18444 at most that many characters. If positive, pad (with spaces)
18445 to at least that many characters.
18446 If first element is a symbol, process the cadr or caddr recursively
18447 according to whether the symbol's value is non-nil or nil. */
18449 if (EQ (car
, QCeval
))
18451 /* An element of the form (:eval FORM) means evaluate FORM
18452 and use the result as mode line elements. */
18457 if (CONSP (XCDR (elt
)))
18460 spec
= safe_eval (XCAR (XCDR (elt
)));
18461 n
+= display_mode_element (it
, depth
, field_width
- n
,
18462 precision
- n
, spec
, props
,
18466 else if (EQ (car
, QCpropertize
))
18468 /* An element of the form (:propertize ELT PROPS...)
18469 means display ELT but applying properties PROPS. */
18474 if (CONSP (XCDR (elt
)))
18475 n
+= display_mode_element (it
, depth
, field_width
- n
,
18476 precision
- n
, XCAR (XCDR (elt
)),
18477 XCDR (XCDR (elt
)), risky
);
18479 else if (SYMBOLP (car
))
18481 tem
= Fboundp (car
);
18485 /* elt is now the cdr, and we know it is a cons cell.
18486 Use its car if CAR has a non-nil value. */
18489 tem
= Fsymbol_value (car
);
18496 /* Symbol's value is nil (or symbol is unbound)
18497 Get the cddr of the original list
18498 and if possible find the caddr and use that. */
18502 else if (!CONSP (elt
))
18507 else if (INTEGERP (car
))
18509 register int lim
= XINT (car
);
18513 /* Negative int means reduce maximum width. */
18514 if (precision
<= 0)
18517 precision
= min (precision
, -lim
);
18521 /* Padding specified. Don't let it be more than
18522 current maximum. */
18524 lim
= min (precision
, lim
);
18526 /* If that's more padding than already wanted, queue it.
18527 But don't reduce padding already specified even if
18528 that is beyond the current truncation point. */
18529 field_width
= max (lim
, field_width
);
18533 else if (STRINGP (car
) || CONSP (car
))
18535 Lisp_Object halftail
= elt
;
18539 && (precision
<= 0 || n
< precision
))
18541 n
+= display_mode_element (it
, depth
,
18542 /* Do padding only after the last
18543 element in the list. */
18544 (! CONSP (XCDR (elt
))
18547 precision
- n
, XCAR (elt
),
18551 if ((len
& 1) == 0)
18552 halftail
= XCDR (halftail
);
18553 /* Check for cycle. */
18554 if (EQ (halftail
, elt
))
18563 elt
= build_string ("*invalid*");
18567 /* Pad to FIELD_WIDTH. */
18568 if (field_width
> 0 && n
< field_width
)
18570 switch (mode_line_target
)
18572 case MODE_LINE_NOPROP
:
18573 case MODE_LINE_TITLE
:
18574 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18576 case MODE_LINE_STRING
:
18577 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18579 case MODE_LINE_DISPLAY
:
18580 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18589 /* Store a mode-line string element in mode_line_string_list.
18591 If STRING is non-null, display that C string. Otherwise, the Lisp
18592 string LISP_STRING is displayed.
18594 FIELD_WIDTH is the minimum number of output glyphs to produce.
18595 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18596 with spaces. FIELD_WIDTH <= 0 means don't pad.
18598 PRECISION is the maximum number of characters to output from
18599 STRING. PRECISION <= 0 means don't truncate the string.
18601 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18602 properties to the string.
18604 PROPS are the properties to add to the string.
18605 The mode_line_string_face face property is always added to the string.
18609 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
18611 Lisp_Object lisp_string
;
18620 if (string
!= NULL
)
18622 len
= strlen (string
);
18623 if (precision
> 0 && len
> precision
)
18625 lisp_string
= make_string (string
, len
);
18627 props
= mode_line_string_face_prop
;
18628 else if (!NILP (mode_line_string_face
))
18630 Lisp_Object face
= Fplist_get (props
, Qface
);
18631 props
= Fcopy_sequence (props
);
18633 face
= mode_line_string_face
;
18635 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18636 props
= Fplist_put (props
, Qface
, face
);
18638 Fadd_text_properties (make_number (0), make_number (len
),
18639 props
, lisp_string
);
18643 len
= XFASTINT (Flength (lisp_string
));
18644 if (precision
> 0 && len
> precision
)
18647 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
18650 if (!NILP (mode_line_string_face
))
18654 props
= Ftext_properties_at (make_number (0), lisp_string
);
18655 face
= Fplist_get (props
, Qface
);
18657 face
= mode_line_string_face
;
18659 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18660 props
= Fcons (Qface
, Fcons (face
, Qnil
));
18662 lisp_string
= Fcopy_sequence (lisp_string
);
18665 Fadd_text_properties (make_number (0), make_number (len
),
18666 props
, lisp_string
);
18671 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18675 if (field_width
> len
)
18677 field_width
-= len
;
18678 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
18680 Fadd_text_properties (make_number (0), make_number (field_width
),
18681 props
, lisp_string
);
18682 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18690 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
18692 doc
: /* Format a string out of a mode line format specification.
18693 First arg FORMAT specifies the mode line format (see `mode-line-format'
18694 for details) to use.
18696 Optional second arg FACE specifies the face property to put
18697 on all characters for which no face is specified.
18698 The value t means whatever face the window's mode line currently uses
18699 \(either `mode-line' or `mode-line-inactive', depending).
18700 A value of nil means the default is no face property.
18701 If FACE is an integer, the value string has no text properties.
18703 Optional third and fourth args WINDOW and BUFFER specify the window
18704 and buffer to use as the context for the formatting (defaults
18705 are the selected window and the window's buffer). */)
18706 (format
, face
, window
, buffer
)
18707 Lisp_Object format
, face
, window
, buffer
;
18712 struct buffer
*old_buffer
= NULL
;
18714 int no_props
= INTEGERP (face
);
18715 int count
= SPECPDL_INDEX ();
18717 int string_start
= 0;
18720 window
= selected_window
;
18721 CHECK_WINDOW (window
);
18722 w
= XWINDOW (window
);
18725 buffer
= w
->buffer
;
18726 CHECK_BUFFER (buffer
);
18728 /* Make formatting the modeline a non-op when noninteractive, otherwise
18729 there will be problems later caused by a partially initialized frame. */
18730 if (NILP (format
) || noninteractive
)
18731 return empty_unibyte_string
;
18739 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
18740 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
18744 face_id
= DEFAULT_FACE_ID
;
18746 if (XBUFFER (buffer
) != current_buffer
)
18747 old_buffer
= current_buffer
;
18749 /* Save things including mode_line_proptrans_alist,
18750 and set that to nil so that we don't alter the outer value. */
18751 record_unwind_protect (unwind_format_mode_line
,
18752 format_mode_line_unwind_data
18753 (old_buffer
, selected_window
, 1));
18754 mode_line_proptrans_alist
= Qnil
;
18756 Fselect_window (window
, Qt
);
18758 set_buffer_internal_1 (XBUFFER (buffer
));
18760 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18764 mode_line_target
= MODE_LINE_NOPROP
;
18765 mode_line_string_face_prop
= Qnil
;
18766 mode_line_string_list
= Qnil
;
18767 string_start
= MODE_LINE_NOPROP_LEN (0);
18771 mode_line_target
= MODE_LINE_STRING
;
18772 mode_line_string_list
= Qnil
;
18773 mode_line_string_face
= face
;
18774 mode_line_string_face_prop
18775 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18778 push_kboard (FRAME_KBOARD (it
.f
));
18779 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18784 len
= MODE_LINE_NOPROP_LEN (string_start
);
18785 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18789 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18790 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18791 empty_unibyte_string
);
18794 unbind_to (count
, Qnil
);
18798 /* Write a null-terminated, right justified decimal representation of
18799 the positive integer D to BUF using a minimal field width WIDTH. */
18802 pint2str (buf
, width
, d
)
18803 register char *buf
;
18804 register int width
;
18807 register char *p
= buf
;
18815 *p
++ = d
% 10 + '0';
18820 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18831 /* Write a null-terminated, right justified decimal and "human
18832 readable" representation of the nonnegative integer D to BUF using
18833 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18835 static const char power_letter
[] =
18849 pint2hrstr (buf
, width
, d
)
18854 /* We aim to represent the nonnegative integer D as
18855 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18858 /* -1 means: do not use TENTHS. */
18862 /* Length of QUOTIENT.TENTHS as a string. */
18868 if (1000 <= quotient
)
18870 /* Scale to the appropriate EXPONENT. */
18873 remainder
= quotient
% 1000;
18877 while (1000 <= quotient
);
18879 /* Round to nearest and decide whether to use TENTHS or not. */
18882 tenths
= remainder
/ 100;
18883 if (50 <= remainder
% 100)
18890 if (quotient
== 10)
18898 if (500 <= remainder
)
18900 if (quotient
< 999)
18911 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18912 if (tenths
== -1 && quotient
<= 99)
18919 p
= psuffix
= buf
+ max (width
, length
);
18921 /* Print EXPONENT. */
18923 *psuffix
++ = power_letter
[exponent
];
18926 /* Print TENTHS. */
18929 *--p
= '0' + tenths
;
18933 /* Print QUOTIENT. */
18936 int digit
= quotient
% 10;
18937 *--p
= '0' + digit
;
18939 while ((quotient
/= 10) != 0);
18941 /* Print leading spaces. */
18946 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18947 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18948 type of CODING_SYSTEM. Return updated pointer into BUF. */
18950 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18953 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18954 Lisp_Object coding_system
;
18955 register char *buf
;
18959 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18960 const unsigned char *eol_str
;
18962 /* The EOL conversion we are using. */
18963 Lisp_Object eoltype
;
18965 val
= CODING_SYSTEM_SPEC (coding_system
);
18968 if (!VECTORP (val
)) /* Not yet decided. */
18973 eoltype
= eol_mnemonic_undecided
;
18974 /* Don't mention EOL conversion if it isn't decided. */
18979 Lisp_Object eolvalue
;
18981 attrs
= AREF (val
, 0);
18982 eolvalue
= AREF (val
, 2);
18985 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18989 /* The EOL conversion that is normal on this system. */
18991 if (NILP (eolvalue
)) /* Not yet decided. */
18992 eoltype
= eol_mnemonic_undecided
;
18993 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18994 eoltype
= eol_mnemonic_undecided
;
18995 else /* eolvalue is Qunix, Qdos, or Qmac. */
18996 eoltype
= (EQ (eolvalue
, Qunix
)
18997 ? eol_mnemonic_unix
18998 : (EQ (eolvalue
, Qdos
) == 1
18999 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19005 /* Mention the EOL conversion if it is not the usual one. */
19006 if (STRINGP (eoltype
))
19008 eol_str
= SDATA (eoltype
);
19009 eol_str_len
= SBYTES (eoltype
);
19011 else if (CHARACTERP (eoltype
))
19013 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19014 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19019 eol_str
= invalid_eol_type
;
19020 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19022 bcopy (eol_str
, buf
, eol_str_len
);
19023 buf
+= eol_str_len
;
19029 /* Return a string for the output of a mode line %-spec for window W,
19030 generated by character C. PRECISION >= 0 means don't return a
19031 string longer than that value. FIELD_WIDTH > 0 means pad the
19032 string returned with spaces to that value. Return a Lisp string in
19033 *STRING if the resulting string is taken from that Lisp string.
19035 Note we operate on the current buffer for most purposes,
19036 the exception being w->base_line_pos. */
19038 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19041 decode_mode_spec (w
, c
, field_width
, precision
, string
)
19044 int field_width
, precision
;
19045 Lisp_Object
*string
;
19048 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19049 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19050 struct buffer
*b
= current_buffer
;
19058 if (!NILP (b
->read_only
))
19060 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19065 /* This differs from %* only for a modified read-only buffer. */
19066 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19068 if (!NILP (b
->read_only
))
19073 /* This differs from %* in ignoring read-only-ness. */
19074 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19086 if (command_loop_level
> 5)
19088 p
= decode_mode_spec_buf
;
19089 for (i
= 0; i
< command_loop_level
; i
++)
19092 return decode_mode_spec_buf
;
19100 if (command_loop_level
> 5)
19102 p
= decode_mode_spec_buf
;
19103 for (i
= 0; i
< command_loop_level
; i
++)
19106 return decode_mode_spec_buf
;
19113 /* Let lots_of_dashes be a string of infinite length. */
19114 if (mode_line_target
== MODE_LINE_NOPROP
||
19115 mode_line_target
== MODE_LINE_STRING
)
19117 if (field_width
<= 0
19118 || field_width
> sizeof (lots_of_dashes
))
19120 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19121 decode_mode_spec_buf
[i
] = '-';
19122 decode_mode_spec_buf
[i
] = '\0';
19123 return decode_mode_spec_buf
;
19126 return lots_of_dashes
;
19134 /* %c and %l are ignored in `frame-title-format'.
19135 (In redisplay_internal, the frame title is drawn _before_ the
19136 windows are updated, so the stuff which depends on actual
19137 window contents (such as %l) may fail to render properly, or
19138 even crash emacs.) */
19139 if (mode_line_target
== MODE_LINE_TITLE
)
19143 int col
= (int) current_column (); /* iftc */
19144 w
->column_number_displayed
= make_number (col
);
19145 pint2str (decode_mode_spec_buf
, field_width
, col
);
19146 return decode_mode_spec_buf
;
19150 #ifndef SYSTEM_MALLOC
19152 if (NILP (Vmemory_full
))
19155 return "!MEM FULL! ";
19162 /* %F displays the frame name. */
19163 if (!NILP (f
->title
))
19164 return (char *) SDATA (f
->title
);
19165 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19166 return (char *) SDATA (f
->name
);
19175 int size
= ZV
- BEGV
;
19176 pint2str (decode_mode_spec_buf
, field_width
, size
);
19177 return decode_mode_spec_buf
;
19182 int size
= ZV
- BEGV
;
19183 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19184 return decode_mode_spec_buf
;
19189 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19190 int topline
, nlines
, junk
, height
;
19192 /* %c and %l are ignored in `frame-title-format'. */
19193 if (mode_line_target
== MODE_LINE_TITLE
)
19196 startpos
= XMARKER (w
->start
)->charpos
;
19197 startpos_byte
= marker_byte_position (w
->start
);
19198 height
= WINDOW_TOTAL_LINES (w
);
19200 /* If we decided that this buffer isn't suitable for line numbers,
19201 don't forget that too fast. */
19202 if (EQ (w
->base_line_pos
, w
->buffer
))
19204 /* But do forget it, if the window shows a different buffer now. */
19205 else if (BUFFERP (w
->base_line_pos
))
19206 w
->base_line_pos
= Qnil
;
19208 /* If the buffer is very big, don't waste time. */
19209 if (INTEGERP (Vline_number_display_limit
)
19210 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19212 w
->base_line_pos
= Qnil
;
19213 w
->base_line_number
= Qnil
;
19217 if (INTEGERP (w
->base_line_number
)
19218 && INTEGERP (w
->base_line_pos
)
19219 && XFASTINT (w
->base_line_pos
) <= startpos
)
19221 line
= XFASTINT (w
->base_line_number
);
19222 linepos
= XFASTINT (w
->base_line_pos
);
19223 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19228 linepos
= BUF_BEGV (b
);
19229 linepos_byte
= BUF_BEGV_BYTE (b
);
19232 /* Count lines from base line to window start position. */
19233 nlines
= display_count_lines (linepos
, linepos_byte
,
19237 topline
= nlines
+ line
;
19239 /* Determine a new base line, if the old one is too close
19240 or too far away, or if we did not have one.
19241 "Too close" means it's plausible a scroll-down would
19242 go back past it. */
19243 if (startpos
== BUF_BEGV (b
))
19245 w
->base_line_number
= make_number (topline
);
19246 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19248 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19249 || linepos
== BUF_BEGV (b
))
19251 int limit
= BUF_BEGV (b
);
19252 int limit_byte
= BUF_BEGV_BYTE (b
);
19254 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
19256 if (startpos
- distance
> limit
)
19258 limit
= startpos
- distance
;
19259 limit_byte
= CHAR_TO_BYTE (limit
);
19262 nlines
= display_count_lines (startpos
, startpos_byte
,
19264 - (height
* 2 + 30),
19266 /* If we couldn't find the lines we wanted within
19267 line_number_display_limit_width chars per line,
19268 give up on line numbers for this window. */
19269 if (position
== limit_byte
&& limit
== startpos
- distance
)
19271 w
->base_line_pos
= w
->buffer
;
19272 w
->base_line_number
= Qnil
;
19276 w
->base_line_number
= make_number (topline
- nlines
);
19277 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19280 /* Now count lines from the start pos to point. */
19281 nlines
= display_count_lines (startpos
, startpos_byte
,
19282 PT_BYTE
, PT
, &junk
);
19284 /* Record that we did display the line number. */
19285 line_number_displayed
= 1;
19287 /* Make the string to show. */
19288 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19289 return decode_mode_spec_buf
;
19292 char* p
= decode_mode_spec_buf
;
19293 int pad
= field_width
- 2;
19299 return decode_mode_spec_buf
;
19305 obj
= b
->mode_name
;
19309 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19315 int pos
= marker_position (w
->start
);
19316 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19318 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19320 if (pos
<= BUF_BEGV (b
))
19325 else if (pos
<= BUF_BEGV (b
))
19329 if (total
> 1000000)
19330 /* Do it differently for a large value, to avoid overflow. */
19331 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19333 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19334 /* We can't normally display a 3-digit number,
19335 so get us a 2-digit number that is close. */
19338 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19339 return decode_mode_spec_buf
;
19343 /* Display percentage of size above the bottom of the screen. */
19346 int toppos
= marker_position (w
->start
);
19347 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19348 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19350 if (botpos
>= BUF_ZV (b
))
19352 if (toppos
<= BUF_BEGV (b
))
19359 if (total
> 1000000)
19360 /* Do it differently for a large value, to avoid overflow. */
19361 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19363 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19364 /* We can't normally display a 3-digit number,
19365 so get us a 2-digit number that is close. */
19368 if (toppos
<= BUF_BEGV (b
))
19369 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
19371 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19372 return decode_mode_spec_buf
;
19377 /* status of process */
19378 obj
= Fget_buffer_process (Fcurrent_buffer ());
19380 return "no process";
19381 #ifdef subprocesses
19382 obj
= Fsymbol_name (Fprocess_status (obj
));
19388 int count
= inhibit_garbage_collection ();
19389 Lisp_Object val
= call1 (intern ("file-remote-p"),
19390 current_buffer
->directory
);
19391 unbind_to (count
, Qnil
);
19399 case 't': /* indicate TEXT or BINARY */
19400 #ifdef MODE_LINE_BINARY_TEXT
19401 return MODE_LINE_BINARY_TEXT (b
);
19407 /* coding-system (not including end-of-line format) */
19409 /* coding-system (including end-of-line type) */
19411 int eol_flag
= (c
== 'Z');
19412 char *p
= decode_mode_spec_buf
;
19414 if (! FRAME_WINDOW_P (f
))
19416 /* No need to mention EOL here--the terminal never needs
19417 to do EOL conversion. */
19418 p
= decode_mode_spec_coding (CODING_ID_NAME
19419 (FRAME_KEYBOARD_CODING (f
)->id
),
19421 p
= decode_mode_spec_coding (CODING_ID_NAME
19422 (FRAME_TERMINAL_CODING (f
)->id
),
19425 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19428 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19429 #ifdef subprocesses
19430 obj
= Fget_buffer_process (Fcurrent_buffer ());
19431 if (PROCESSP (obj
))
19433 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19435 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19438 #endif /* subprocesses */
19441 return decode_mode_spec_buf
;
19448 return (char *) SDATA (obj
);
19455 /* Count up to COUNT lines starting from START / START_BYTE.
19456 But don't go beyond LIMIT_BYTE.
19457 Return the number of lines thus found (always nonnegative).
19459 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19462 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
19463 int start
, start_byte
, limit_byte
, count
;
19466 register unsigned char *cursor
;
19467 unsigned char *base
;
19469 register int ceiling
;
19470 register unsigned char *ceiling_addr
;
19471 int orig_count
= count
;
19473 /* If we are not in selective display mode,
19474 check only for newlines. */
19475 int selective_display
= (!NILP (current_buffer
->selective_display
)
19476 && !INTEGERP (current_buffer
->selective_display
));
19480 while (start_byte
< limit_byte
)
19482 ceiling
= BUFFER_CEILING_OF (start_byte
);
19483 ceiling
= min (limit_byte
- 1, ceiling
);
19484 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19485 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19488 if (selective_display
)
19489 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19492 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19495 if (cursor
!= ceiling_addr
)
19499 start_byte
+= cursor
- base
+ 1;
19500 *byte_pos_ptr
= start_byte
;
19504 if (++cursor
== ceiling_addr
)
19510 start_byte
+= cursor
- base
;
19515 while (start_byte
> limit_byte
)
19517 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19518 ceiling
= max (limit_byte
, ceiling
);
19519 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19520 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19523 if (selective_display
)
19524 while (--cursor
!= ceiling_addr
19525 && *cursor
!= '\n' && *cursor
!= 015)
19528 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19531 if (cursor
!= ceiling_addr
)
19535 start_byte
+= cursor
- base
+ 1;
19536 *byte_pos_ptr
= start_byte
;
19537 /* When scanning backwards, we should
19538 not count the newline posterior to which we stop. */
19539 return - orig_count
- 1;
19545 /* Here we add 1 to compensate for the last decrement
19546 of CURSOR, which took it past the valid range. */
19547 start_byte
+= cursor
- base
+ 1;
19551 *byte_pos_ptr
= limit_byte
;
19554 return - orig_count
+ count
;
19555 return orig_count
- count
;
19561 /***********************************************************************
19563 ***********************************************************************/
19565 /* Display a NUL-terminated string, starting with index START.
19567 If STRING is non-null, display that C string. Otherwise, the Lisp
19568 string LISP_STRING is displayed. There's a case that STRING is
19569 non-null and LISP_STRING is not nil. It means STRING is a string
19570 data of LISP_STRING. In that case, we display LISP_STRING while
19571 ignoring its text properties.
19573 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19574 FACE_STRING. Display STRING or LISP_STRING with the face at
19575 FACE_STRING_POS in FACE_STRING:
19577 Display the string in the environment given by IT, but use the
19578 standard display table, temporarily.
19580 FIELD_WIDTH is the minimum number of output glyphs to produce.
19581 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19582 with spaces. If STRING has more characters, more than FIELD_WIDTH
19583 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19585 PRECISION is the maximum number of characters to output from
19586 STRING. PRECISION < 0 means don't truncate the string.
19588 This is roughly equivalent to printf format specifiers:
19590 FIELD_WIDTH PRECISION PRINTF
19591 ----------------------------------------
19597 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19598 display them, and < 0 means obey the current buffer's value of
19599 enable_multibyte_characters.
19601 Value is the number of columns displayed. */
19604 display_string (string
, lisp_string
, face_string
, face_string_pos
,
19605 start
, it
, field_width
, precision
, max_x
, multibyte
)
19606 unsigned char *string
;
19607 Lisp_Object lisp_string
;
19608 Lisp_Object face_string
;
19609 EMACS_INT face_string_pos
;
19612 int field_width
, precision
, max_x
;
19615 int hpos_at_start
= it
->hpos
;
19616 int saved_face_id
= it
->face_id
;
19617 struct glyph_row
*row
= it
->glyph_row
;
19619 /* Initialize the iterator IT for iteration over STRING beginning
19620 with index START. */
19621 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19622 precision
, field_width
, multibyte
);
19623 if (string
&& STRINGP (lisp_string
))
19624 /* LISP_STRING is the one returned by decode_mode_spec. We should
19625 ignore its text properties. */
19626 it
->stop_charpos
= -1;
19628 /* If displaying STRING, set up the face of the iterator
19629 from LISP_STRING, if that's given. */
19630 if (STRINGP (face_string
))
19636 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19637 0, it
->region_beg_charpos
,
19638 it
->region_end_charpos
,
19639 &endptr
, it
->base_face_id
, 0);
19640 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19641 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19644 /* Set max_x to the maximum allowed X position. Don't let it go
19645 beyond the right edge of the window. */
19647 max_x
= it
->last_visible_x
;
19649 max_x
= min (max_x
, it
->last_visible_x
);
19651 /* Skip over display elements that are not visible. because IT->w is
19653 if (it
->current_x
< it
->first_visible_x
)
19654 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
19655 MOVE_TO_POS
| MOVE_TO_X
);
19657 row
->ascent
= it
->max_ascent
;
19658 row
->height
= it
->max_ascent
+ it
->max_descent
;
19659 row
->phys_ascent
= it
->max_phys_ascent
;
19660 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19661 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19663 /* This condition is for the case that we are called with current_x
19664 past last_visible_x. */
19665 while (it
->current_x
< max_x
)
19667 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
19669 /* Get the next display element. */
19670 if (!get_next_display_element (it
))
19673 /* Produce glyphs. */
19674 x_before
= it
->current_x
;
19675 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19676 PRODUCE_GLYPHS (it
);
19678 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
19681 while (i
< nglyphs
)
19683 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19685 if (it
->line_wrap
!= TRUNCATE
19686 && x
+ glyph
->pixel_width
> max_x
)
19688 /* End of continued line or max_x reached. */
19689 if (CHAR_GLYPH_PADDING_P (*glyph
))
19691 /* A wide character is unbreakable. */
19692 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19693 it
->current_x
= x_before
;
19697 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19702 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
19704 /* Glyph is at least partially visible. */
19706 if (x
< it
->first_visible_x
)
19707 it
->glyph_row
->x
= x
- it
->first_visible_x
;
19711 /* Glyph is off the left margin of the display area.
19712 Should not happen. */
19716 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19717 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19718 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19719 row
->phys_height
= max (row
->phys_height
,
19720 it
->max_phys_ascent
+ it
->max_phys_descent
);
19721 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19722 it
->max_extra_line_spacing
);
19723 x
+= glyph
->pixel_width
;
19727 /* Stop if max_x reached. */
19731 /* Stop at line ends. */
19732 if (ITERATOR_AT_END_OF_LINE_P (it
))
19734 it
->continuation_lines_width
= 0;
19738 set_iterator_to_next (it
, 1);
19740 /* Stop if truncating at the right edge. */
19741 if (it
->line_wrap
== TRUNCATE
19742 && it
->current_x
>= it
->last_visible_x
)
19744 /* Add truncation mark, but don't do it if the line is
19745 truncated at a padding space. */
19746 if (IT_CHARPOS (*it
) < it
->string_nchars
)
19748 if (!FRAME_WINDOW_P (it
->f
))
19752 if (it
->current_x
> it
->last_visible_x
)
19754 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19755 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19757 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19759 row
->used
[TEXT_AREA
] = i
;
19760 produce_special_glyphs (it
, IT_TRUNCATION
);
19763 produce_special_glyphs (it
, IT_TRUNCATION
);
19765 it
->glyph_row
->truncated_on_right_p
= 1;
19771 /* Maybe insert a truncation at the left. */
19772 if (it
->first_visible_x
19773 && IT_CHARPOS (*it
) > 0)
19775 if (!FRAME_WINDOW_P (it
->f
))
19776 insert_left_trunc_glyphs (it
);
19777 it
->glyph_row
->truncated_on_left_p
= 1;
19780 it
->face_id
= saved_face_id
;
19782 /* Value is number of columns displayed. */
19783 return it
->hpos
- hpos_at_start
;
19788 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19789 appears as an element of LIST or as the car of an element of LIST.
19790 If PROPVAL is a list, compare each element against LIST in that
19791 way, and return 1/2 if any element of PROPVAL is found in LIST.
19792 Otherwise return 0. This function cannot quit.
19793 The return value is 2 if the text is invisible but with an ellipsis
19794 and 1 if it's invisible and without an ellipsis. */
19797 invisible_p (propval
, list
)
19798 register Lisp_Object propval
;
19801 register Lisp_Object tail
, proptail
;
19803 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19805 register Lisp_Object tem
;
19807 if (EQ (propval
, tem
))
19809 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19810 return NILP (XCDR (tem
)) ? 1 : 2;
19813 if (CONSP (propval
))
19815 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19817 Lisp_Object propelt
;
19818 propelt
= XCAR (proptail
);
19819 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19821 register Lisp_Object tem
;
19823 if (EQ (propelt
, tem
))
19825 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19826 return NILP (XCDR (tem
)) ? 1 : 2;
19834 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19835 doc
: /* Non-nil if the property makes the text invisible.
19836 POS-OR-PROP can be a marker or number, in which case it is taken to be
19837 a position in the current buffer and the value of the `invisible' property
19838 is checked; or it can be some other value, which is then presumed to be the
19839 value of the `invisible' property of the text of interest.
19840 The non-nil value returned can be t for truly invisible text or something
19841 else if the text is replaced by an ellipsis. */)
19843 Lisp_Object pos_or_prop
;
19846 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19847 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19849 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19850 return (invis
== 0 ? Qnil
19852 : make_number (invis
));
19855 /* Calculate a width or height in pixels from a specification using
19856 the following elements:
19859 NUM - a (fractional) multiple of the default font width/height
19860 (NUM) - specifies exactly NUM pixels
19861 UNIT - a fixed number of pixels, see below.
19862 ELEMENT - size of a display element in pixels, see below.
19863 (NUM . SPEC) - equals NUM * SPEC
19864 (+ SPEC SPEC ...) - add pixel values
19865 (- SPEC SPEC ...) - subtract pixel values
19866 (- SPEC) - negate pixel value
19869 INT or FLOAT - a number constant
19870 SYMBOL - use symbol's (buffer local) variable binding.
19873 in - pixels per inch *)
19874 mm - pixels per 1/1000 meter *)
19875 cm - pixels per 1/100 meter *)
19876 width - width of current font in pixels.
19877 height - height of current font in pixels.
19879 *) using the ratio(s) defined in display-pixels-per-inch.
19883 left-fringe - left fringe width in pixels
19884 right-fringe - right fringe width in pixels
19886 left-margin - left margin width in pixels
19887 right-margin - right margin width in pixels
19889 scroll-bar - scroll-bar area width in pixels
19893 Pixels corresponding to 5 inches:
19896 Total width of non-text areas on left side of window (if scroll-bar is on left):
19897 '(space :width (+ left-fringe left-margin scroll-bar))
19899 Align to first text column (in header line):
19900 '(space :align-to 0)
19902 Align to middle of text area minus half the width of variable `my-image'
19903 containing a loaded image:
19904 '(space :align-to (0.5 . (- text my-image)))
19906 Width of left margin minus width of 1 character in the default font:
19907 '(space :width (- left-margin 1))
19909 Width of left margin minus width of 2 characters in the current font:
19910 '(space :width (- left-margin (2 . width)))
19912 Center 1 character over left-margin (in header line):
19913 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19915 Different ways to express width of left fringe plus left margin minus one pixel:
19916 '(space :width (- (+ left-fringe left-margin) (1)))
19917 '(space :width (+ left-fringe left-margin (- (1))))
19918 '(space :width (+ left-fringe left-margin (-1)))
19922 #define NUMVAL(X) \
19923 ((INTEGERP (X) || FLOATP (X)) \
19928 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19933 int width_p
, *align_to
;
19937 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19938 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19941 return OK_PIXELS (0);
19943 xassert (FRAME_LIVE_P (it
->f
));
19945 if (SYMBOLP (prop
))
19947 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19949 char *unit
= SDATA (SYMBOL_NAME (prop
));
19951 if (unit
[0] == 'i' && unit
[1] == 'n')
19953 else if (unit
[0] == 'm' && unit
[1] == 'm')
19955 else if (unit
[0] == 'c' && unit
[1] == 'm')
19962 #ifdef HAVE_WINDOW_SYSTEM
19963 if (FRAME_WINDOW_P (it
->f
)
19965 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19966 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19968 return OK_PIXELS (ppi
/ pixels
);
19971 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19972 || (CONSP (Vdisplay_pixels_per_inch
)
19974 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19975 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19977 return OK_PIXELS (ppi
/ pixels
);
19983 #ifdef HAVE_WINDOW_SYSTEM
19984 if (EQ (prop
, Qheight
))
19985 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19986 if (EQ (prop
, Qwidth
))
19987 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19989 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19990 return OK_PIXELS (1);
19993 if (EQ (prop
, Qtext
))
19994 return OK_PIXELS (width_p
19995 ? window_box_width (it
->w
, TEXT_AREA
)
19996 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19998 if (align_to
&& *align_to
< 0)
20001 if (EQ (prop
, Qleft
))
20002 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20003 if (EQ (prop
, Qright
))
20004 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20005 if (EQ (prop
, Qcenter
))
20006 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20007 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20008 if (EQ (prop
, Qleft_fringe
))
20009 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20010 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20011 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20012 if (EQ (prop
, Qright_fringe
))
20013 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20014 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20015 : window_box_right_offset (it
->w
, TEXT_AREA
));
20016 if (EQ (prop
, Qleft_margin
))
20017 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20018 if (EQ (prop
, Qright_margin
))
20019 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20020 if (EQ (prop
, Qscroll_bar
))
20021 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20023 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20024 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20025 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20030 if (EQ (prop
, Qleft_fringe
))
20031 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20032 if (EQ (prop
, Qright_fringe
))
20033 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20034 if (EQ (prop
, Qleft_margin
))
20035 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20036 if (EQ (prop
, Qright_margin
))
20037 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20038 if (EQ (prop
, Qscroll_bar
))
20039 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20042 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20045 if (INTEGERP (prop
) || FLOATP (prop
))
20047 int base_unit
= (width_p
20048 ? FRAME_COLUMN_WIDTH (it
->f
)
20049 : FRAME_LINE_HEIGHT (it
->f
));
20050 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20055 Lisp_Object car
= XCAR (prop
);
20056 Lisp_Object cdr
= XCDR (prop
);
20060 #ifdef HAVE_WINDOW_SYSTEM
20061 if (FRAME_WINDOW_P (it
->f
)
20062 && valid_image_p (prop
))
20064 int id
= lookup_image (it
->f
, prop
);
20065 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20067 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20070 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20076 while (CONSP (cdr
))
20078 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20079 font
, width_p
, align_to
))
20082 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20087 if (EQ (car
, Qminus
))
20089 return OK_PIXELS (pixels
);
20092 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20095 if (INTEGERP (car
) || FLOATP (car
))
20098 pixels
= XFLOATINT (car
);
20100 return OK_PIXELS (pixels
);
20101 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20102 font
, width_p
, align_to
))
20103 return OK_PIXELS (pixels
* fact
);
20114 /***********************************************************************
20116 ***********************************************************************/
20118 #ifdef HAVE_WINDOW_SYSTEM
20123 dump_glyph_string (s
)
20124 struct glyph_string
*s
;
20126 fprintf (stderr
, "glyph string\n");
20127 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20128 s
->x
, s
->y
, s
->width
, s
->height
);
20129 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20130 fprintf (stderr
, " hl = %d\n", s
->hl
);
20131 fprintf (stderr
, " left overhang = %d, right = %d\n",
20132 s
->left_overhang
, s
->right_overhang
);
20133 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20134 fprintf (stderr
, " extends to end of line = %d\n",
20135 s
->extends_to_end_of_line_p
);
20136 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20137 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20140 #endif /* GLYPH_DEBUG */
20142 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20143 of XChar2b structures for S; it can't be allocated in
20144 init_glyph_string because it must be allocated via `alloca'. W
20145 is the window on which S is drawn. ROW and AREA are the glyph row
20146 and area within the row from which S is constructed. START is the
20147 index of the first glyph structure covered by S. HL is a
20148 face-override for drawing S. */
20151 #define OPTIONAL_HDC(hdc) hdc,
20152 #define DECLARE_HDC(hdc) HDC hdc;
20153 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20154 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20157 #ifndef OPTIONAL_HDC
20158 #define OPTIONAL_HDC(hdc)
20159 #define DECLARE_HDC(hdc)
20160 #define ALLOCATE_HDC(hdc, f)
20161 #define RELEASE_HDC(hdc, f)
20165 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
20166 struct glyph_string
*s
;
20170 struct glyph_row
*row
;
20171 enum glyph_row_area area
;
20173 enum draw_glyphs_face hl
;
20175 bzero (s
, sizeof *s
);
20177 s
->f
= XFRAME (w
->frame
);
20181 s
->display
= FRAME_X_DISPLAY (s
->f
);
20182 s
->window
= FRAME_X_WINDOW (s
->f
);
20183 s
->char2b
= char2b
;
20187 s
->first_glyph
= row
->glyphs
[area
] + start
;
20188 s
->height
= row
->height
;
20189 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20190 s
->ybase
= s
->y
+ row
->ascent
;
20194 /* Append the list of glyph strings with head H and tail T to the list
20195 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20198 append_glyph_string_lists (head
, tail
, h
, t
)
20199 struct glyph_string
**head
, **tail
;
20200 struct glyph_string
*h
, *t
;
20214 /* Prepend the list of glyph strings with head H and tail T to the
20215 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20219 prepend_glyph_string_lists (head
, tail
, h
, t
)
20220 struct glyph_string
**head
, **tail
;
20221 struct glyph_string
*h
, *t
;
20235 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20236 Set *HEAD and *TAIL to the resulting list. */
20239 append_glyph_string (head
, tail
, s
)
20240 struct glyph_string
**head
, **tail
;
20241 struct glyph_string
*s
;
20243 s
->next
= s
->prev
= NULL
;
20244 append_glyph_string_lists (head
, tail
, s
, s
);
20248 /* Get face and two-byte form of character C in face FACE_ID on frame
20249 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
20250 means we want to display multibyte text. DISPLAY_P non-zero means
20251 make sure that X resources for the face returned are allocated.
20252 Value is a pointer to a realized face that is ready for display if
20253 DISPLAY_P is non-zero. */
20255 static INLINE
struct face
*
20256 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
20260 int multibyte_p
, display_p
;
20262 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20266 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20268 if (code
!= FONT_INVALID_CODE
)
20269 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20271 STORE_XCHAR2B (char2b
, 0, 0);
20274 /* Make sure X resources of the face are allocated. */
20275 #ifdef HAVE_X_WINDOWS
20279 xassert (face
!= NULL
);
20280 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20287 /* Get face and two-byte form of character glyph GLYPH on frame F.
20288 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20289 a pointer to a realized face that is ready for display. */
20291 static INLINE
struct face
*
20292 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
20294 struct glyph
*glyph
;
20300 xassert (glyph
->type
== CHAR_GLYPH
);
20301 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20308 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20310 if (code
!= FONT_INVALID_CODE
)
20311 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20313 STORE_XCHAR2B (char2b
, 0, 0);
20316 /* Make sure X resources of the face are allocated. */
20317 xassert (face
!= NULL
);
20318 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20323 /* Fill glyph string S with composition components specified by S->cmp.
20325 BASE_FACE is the base face of the composition.
20326 S->cmp_from is the index of the first component for S.
20328 OVERLAPS non-zero means S should draw the foreground only, and use
20329 its physical height for clipping. See also draw_glyphs.
20331 Value is the index of a component not in S. */
20334 fill_composite_glyph_string (s
, base_face
, overlaps
)
20335 struct glyph_string
*s
;
20336 struct face
*base_face
;
20340 /* For all glyphs of this composition, starting at the offset
20341 S->cmp_from, until we reach the end of the definition or encounter a
20342 glyph that requires the different face, add it to S. */
20347 s
->for_overlaps
= overlaps
;
20350 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20352 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20356 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20359 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20360 s
->char2b
+ i
, 1, 1);
20366 s
->font
= s
->face
->font
;
20368 else if (s
->face
!= face
)
20376 /* All glyph strings for the same composition has the same width,
20377 i.e. the width set for the first component of the composition. */
20378 s
->width
= s
->first_glyph
->pixel_width
;
20380 /* If the specified font could not be loaded, use the frame's
20381 default font, but record the fact that we couldn't load it in
20382 the glyph string so that we can draw rectangles for the
20383 characters of the glyph string. */
20384 if (s
->font
== NULL
)
20386 s
->font_not_found_p
= 1;
20387 s
->font
= FRAME_FONT (s
->f
);
20390 /* Adjust base line for subscript/superscript text. */
20391 s
->ybase
+= s
->first_glyph
->voffset
;
20393 /* This glyph string must always be drawn with 16-bit functions. */
20400 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
20401 struct glyph_string
*s
;
20403 int start
, end
, overlaps
;
20405 struct glyph
*glyph
, *last
;
20406 Lisp_Object lgstring
;
20409 s
->for_overlaps
= overlaps
;
20410 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20411 last
= s
->row
->glyphs
[s
->area
] + end
;
20412 s
->cmp_id
= glyph
->u
.cmp
.id
;
20413 s
->cmp_from
= glyph
->u
.cmp
.from
;
20414 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
20415 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20416 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20417 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20419 while (glyph
< last
20420 && glyph
->u
.cmp
.automatic
20421 && glyph
->u
.cmp
.id
== s
->cmp_id
20422 && s
->cmp_to
== glyph
->u
.cmp
.from
)
20423 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
20425 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20427 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20428 unsigned code
= LGLYPH_CODE (lglyph
);
20430 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20432 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20433 return glyph
- s
->row
->glyphs
[s
->area
];
20437 /* Fill glyph string S from a sequence of character glyphs.
20439 FACE_ID is the face id of the string. START is the index of the
20440 first glyph to consider, END is the index of the last + 1.
20441 OVERLAPS non-zero means S should draw the foreground only, and use
20442 its physical height for clipping. See also draw_glyphs.
20444 Value is the index of the first glyph not in S. */
20447 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
20448 struct glyph_string
*s
;
20450 int start
, end
, overlaps
;
20452 struct glyph
*glyph
, *last
;
20454 int glyph_not_available_p
;
20456 xassert (s
->f
== XFRAME (s
->w
->frame
));
20457 xassert (s
->nchars
== 0);
20458 xassert (start
>= 0 && end
> start
);
20460 s
->for_overlaps
= overlaps
;
20461 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20462 last
= s
->row
->glyphs
[s
->area
] + end
;
20463 voffset
= glyph
->voffset
;
20464 s
->padding_p
= glyph
->padding_p
;
20465 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20467 while (glyph
< last
20468 && glyph
->type
== CHAR_GLYPH
20469 && glyph
->voffset
== voffset
20470 /* Same face id implies same font, nowadays. */
20471 && glyph
->face_id
== face_id
20472 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20476 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20477 s
->char2b
+ s
->nchars
,
20479 s
->two_byte_p
= two_byte_p
;
20481 xassert (s
->nchars
<= end
- start
);
20482 s
->width
+= glyph
->pixel_width
;
20483 if (glyph
++->padding_p
!= s
->padding_p
)
20487 s
->font
= s
->face
->font
;
20489 /* If the specified font could not be loaded, use the frame's font,
20490 but record the fact that we couldn't load it in
20491 S->font_not_found_p so that we can draw rectangles for the
20492 characters of the glyph string. */
20493 if (s
->font
== NULL
|| glyph_not_available_p
)
20495 s
->font_not_found_p
= 1;
20496 s
->font
= FRAME_FONT (s
->f
);
20499 /* Adjust base line for subscript/superscript text. */
20500 s
->ybase
+= voffset
;
20502 xassert (s
->face
&& s
->face
->gc
);
20503 return glyph
- s
->row
->glyphs
[s
->area
];
20507 /* Fill glyph string S from image glyph S->first_glyph. */
20510 fill_image_glyph_string (s
)
20511 struct glyph_string
*s
;
20513 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20514 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20516 s
->slice
= s
->first_glyph
->slice
;
20517 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20518 s
->font
= s
->face
->font
;
20519 s
->width
= s
->first_glyph
->pixel_width
;
20521 /* Adjust base line for subscript/superscript text. */
20522 s
->ybase
+= s
->first_glyph
->voffset
;
20526 /* Fill glyph string S from a sequence of stretch glyphs.
20528 ROW is the glyph row in which the glyphs are found, AREA is the
20529 area within the row. START is the index of the first glyph to
20530 consider, END is the index of the last + 1.
20532 Value is the index of the first glyph not in S. */
20535 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
20536 struct glyph_string
*s
;
20537 struct glyph_row
*row
;
20538 enum glyph_row_area area
;
20541 struct glyph
*glyph
, *last
;
20542 int voffset
, face_id
;
20544 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20546 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20547 last
= s
->row
->glyphs
[s
->area
] + end
;
20548 face_id
= glyph
->face_id
;
20549 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20550 s
->font
= s
->face
->font
;
20551 s
->width
= glyph
->pixel_width
;
20553 voffset
= glyph
->voffset
;
20557 && glyph
->type
== STRETCH_GLYPH
20558 && glyph
->voffset
== voffset
20559 && glyph
->face_id
== face_id
);
20561 s
->width
+= glyph
->pixel_width
;
20563 /* Adjust base line for subscript/superscript text. */
20564 s
->ybase
+= voffset
;
20566 /* The case that face->gc == 0 is handled when drawing the glyph
20567 string by calling PREPARE_FACE_FOR_DISPLAY. */
20569 return glyph
- s
->row
->glyphs
[s
->area
];
20572 static struct font_metrics
*
20573 get_per_char_metric (f
, font
, char2b
)
20578 static struct font_metrics metrics
;
20579 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20581 if (! font
|| code
== FONT_INVALID_CODE
)
20583 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20588 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20589 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20590 assumed to be zero. */
20593 x_get_glyph_overhangs (glyph
, f
, left
, right
)
20594 struct glyph
*glyph
;
20598 *left
= *right
= 0;
20600 if (glyph
->type
== CHAR_GLYPH
)
20604 struct font_metrics
*pcm
;
20606 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20607 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20609 if (pcm
->rbearing
> pcm
->width
)
20610 *right
= pcm
->rbearing
- pcm
->width
;
20611 if (pcm
->lbearing
< 0)
20612 *left
= -pcm
->lbearing
;
20615 else if (glyph
->type
== COMPOSITE_GLYPH
)
20617 if (! glyph
->u
.cmp
.automatic
)
20619 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20621 if (cmp
->rbearing
> cmp
->pixel_width
)
20622 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20623 if (cmp
->lbearing
< 0)
20624 *left
= - cmp
->lbearing
;
20628 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
20629 struct font_metrics metrics
;
20631 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
20632 glyph
->u
.cmp
.to
+ 1, &metrics
);
20633 if (metrics
.rbearing
> metrics
.width
)
20634 *right
= metrics
.rbearing
- metrics
.width
;
20635 if (metrics
.lbearing
< 0)
20636 *left
= - metrics
.lbearing
;
20642 /* Return the index of the first glyph preceding glyph string S that
20643 is overwritten by S because of S's left overhang. Value is -1
20644 if no glyphs are overwritten. */
20647 left_overwritten (s
)
20648 struct glyph_string
*s
;
20652 if (s
->left_overhang
)
20655 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20656 int first
= s
->first_glyph
- glyphs
;
20658 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
20659 x
-= glyphs
[i
].pixel_width
;
20670 /* Return the index of the first glyph preceding glyph string S that
20671 is overwriting S because of its right overhang. Value is -1 if no
20672 glyph in front of S overwrites S. */
20675 left_overwriting (s
)
20676 struct glyph_string
*s
;
20679 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20680 int first
= s
->first_glyph
- glyphs
;
20684 for (i
= first
- 1; i
>= 0; --i
)
20687 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20690 x
-= glyphs
[i
].pixel_width
;
20697 /* Return the index of the last glyph following glyph string S that is
20698 overwritten by S because of S's right overhang. Value is -1 if
20699 no such glyph is found. */
20702 right_overwritten (s
)
20703 struct glyph_string
*s
;
20707 if (s
->right_overhang
)
20710 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20711 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20712 int end
= s
->row
->used
[s
->area
];
20714 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
20715 x
+= glyphs
[i
].pixel_width
;
20724 /* Return the index of the last glyph following glyph string S that
20725 overwrites S because of its left overhang. Value is negative
20726 if no such glyph is found. */
20729 right_overwriting (s
)
20730 struct glyph_string
*s
;
20733 int end
= s
->row
->used
[s
->area
];
20734 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20735 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20739 for (i
= first
; i
< end
; ++i
)
20742 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20745 x
+= glyphs
[i
].pixel_width
;
20752 /* Set background width of glyph string S. START is the index of the
20753 first glyph following S. LAST_X is the right-most x-position + 1
20754 in the drawing area. */
20757 set_glyph_string_background_width (s
, start
, last_x
)
20758 struct glyph_string
*s
;
20762 /* If the face of this glyph string has to be drawn to the end of
20763 the drawing area, set S->extends_to_end_of_line_p. */
20765 if (start
== s
->row
->used
[s
->area
]
20766 && s
->area
== TEXT_AREA
20767 && ((s
->row
->fill_line_p
20768 && (s
->hl
== DRAW_NORMAL_TEXT
20769 || s
->hl
== DRAW_IMAGE_RAISED
20770 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20771 || s
->hl
== DRAW_MOUSE_FACE
))
20772 s
->extends_to_end_of_line_p
= 1;
20774 /* If S extends its face to the end of the line, set its
20775 background_width to the distance to the right edge of the drawing
20777 if (s
->extends_to_end_of_line_p
)
20778 s
->background_width
= last_x
- s
->x
+ 1;
20780 s
->background_width
= s
->width
;
20784 /* Compute overhangs and x-positions for glyph string S and its
20785 predecessors, or successors. X is the starting x-position for S.
20786 BACKWARD_P non-zero means process predecessors. */
20789 compute_overhangs_and_x (s
, x
, backward_p
)
20790 struct glyph_string
*s
;
20798 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20799 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20809 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20810 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20820 /* The following macros are only called from draw_glyphs below.
20821 They reference the following parameters of that function directly:
20822 `w', `row', `area', and `overlap_p'
20823 as well as the following local variables:
20824 `s', `f', and `hdc' (in W32) */
20827 /* On W32, silently add local `hdc' variable to argument list of
20828 init_glyph_string. */
20829 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20830 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20832 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20833 init_glyph_string (s, char2b, w, row, area, start, hl)
20836 /* Add a glyph string for a stretch glyph to the list of strings
20837 between HEAD and TAIL. START is the index of the stretch glyph in
20838 row area AREA of glyph row ROW. END is the index of the last glyph
20839 in that glyph row area. X is the current output position assigned
20840 to the new glyph string constructed. HL overrides that face of the
20841 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20842 is the right-most x-position of the drawing area. */
20844 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20845 and below -- keep them on one line. */
20846 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20849 s = (struct glyph_string *) alloca (sizeof *s); \
20850 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20851 START = fill_stretch_glyph_string (s, row, area, START, END); \
20852 append_glyph_string (&HEAD, &TAIL, s); \
20858 /* Add a glyph string for an image glyph to the list of strings
20859 between HEAD and TAIL. START is the index of the image glyph in
20860 row area AREA of glyph row ROW. END is the index of the last glyph
20861 in that glyph row area. X is the current output position assigned
20862 to the new glyph string constructed. HL overrides that face of the
20863 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20864 is the right-most x-position of the drawing area. */
20866 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20869 s = (struct glyph_string *) alloca (sizeof *s); \
20870 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20871 fill_image_glyph_string (s); \
20872 append_glyph_string (&HEAD, &TAIL, s); \
20879 /* Add a glyph string for a sequence of character glyphs to the list
20880 of strings between HEAD and TAIL. START is the index of the first
20881 glyph in row area AREA of glyph row ROW that is part of the new
20882 glyph string. END is the index of the last glyph in that glyph row
20883 area. X is the current output position assigned to the new glyph
20884 string constructed. HL overrides that face of the glyph; e.g. it
20885 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20886 right-most x-position of the drawing area. */
20888 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20894 face_id = (row)->glyphs[area][START].face_id; \
20896 s = (struct glyph_string *) alloca (sizeof *s); \
20897 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20898 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20899 append_glyph_string (&HEAD, &TAIL, s); \
20901 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20906 /* Add a glyph string for a composite sequence to the list of strings
20907 between HEAD and TAIL. START is the index of the first glyph in
20908 row area AREA of glyph row ROW that is part of the new glyph
20909 string. END is the index of the last glyph in that glyph row area.
20910 X is the current output position assigned to the new glyph string
20911 constructed. HL overrides that face of the glyph; e.g. it is
20912 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20913 x-position of the drawing area. */
20915 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20917 int face_id = (row)->glyphs[area][START].face_id; \
20918 struct face *base_face = FACE_FROM_ID (f, face_id); \
20919 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20920 struct composition *cmp = composition_table[cmp_id]; \
20922 struct glyph_string *first_s; \
20925 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20927 /* Make glyph_strings for each glyph sequence that is drawable by \
20928 the same face, and append them to HEAD/TAIL. */ \
20929 for (n = 0; n < cmp->glyph_len;) \
20931 s = (struct glyph_string *) alloca (sizeof *s); \
20932 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20933 append_glyph_string (&(HEAD), &(TAIL), s); \
20939 n = fill_composite_glyph_string (s, base_face, overlaps); \
20947 /* Add a glyph string for a glyph-string sequence to the list of strings
20948 between HEAD and TAIL. */
20950 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20954 Lisp_Object gstring; \
20956 face_id = (row)->glyphs[area][START].face_id; \
20957 gstring = (composition_gstring_from_id \
20958 ((row)->glyphs[area][START].u.cmp.id)); \
20959 s = (struct glyph_string *) alloca (sizeof *s); \
20960 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20961 * LGSTRING_GLYPH_LEN (gstring)); \
20962 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20963 append_glyph_string (&(HEAD), &(TAIL), s); \
20965 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20969 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20970 of AREA of glyph row ROW on window W between indices START and END.
20971 HL overrides the face for drawing glyph strings, e.g. it is
20972 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20973 x-positions of the drawing area.
20975 This is an ugly monster macro construct because we must use alloca
20976 to allocate glyph strings (because draw_glyphs can be called
20977 asynchronously). */
20979 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20982 HEAD = TAIL = NULL; \
20983 while (START < END) \
20985 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20986 switch (first_glyph->type) \
20989 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20993 case COMPOSITE_GLYPH: \
20994 if (first_glyph->u.cmp.automatic) \
20995 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20998 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21002 case STRETCH_GLYPH: \
21003 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21007 case IMAGE_GLYPH: \
21008 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21018 set_glyph_string_background_width (s, START, LAST_X); \
21025 /* Draw glyphs between START and END in AREA of ROW on window W,
21026 starting at x-position X. X is relative to AREA in W. HL is a
21027 face-override with the following meaning:
21029 DRAW_NORMAL_TEXT draw normally
21030 DRAW_CURSOR draw in cursor face
21031 DRAW_MOUSE_FACE draw in mouse face.
21032 DRAW_INVERSE_VIDEO draw in mode line face
21033 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21034 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21036 If OVERLAPS is non-zero, draw only the foreground of characters and
21037 clip to the physical height of ROW. Non-zero value also defines
21038 the overlapping part to be drawn:
21040 OVERLAPS_PRED overlap with preceding rows
21041 OVERLAPS_SUCC overlap with succeeding rows
21042 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21043 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21045 Value is the x-position reached, relative to AREA of W. */
21048 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
21051 struct glyph_row
*row
;
21052 enum glyph_row_area area
;
21053 EMACS_INT start
, end
;
21054 enum draw_glyphs_face hl
;
21057 struct glyph_string
*head
, *tail
;
21058 struct glyph_string
*s
;
21059 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21060 int i
, j
, x_reached
, last_x
, area_left
= 0;
21061 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21064 ALLOCATE_HDC (hdc
, f
);
21066 /* Let's rather be paranoid than getting a SEGV. */
21067 end
= min (end
, row
->used
[area
]);
21068 start
= max (0, start
);
21069 start
= min (end
, start
);
21071 /* Translate X to frame coordinates. Set last_x to the right
21072 end of the drawing area. */
21073 if (row
->full_width_p
)
21075 /* X is relative to the left edge of W, without scroll bars
21077 area_left
= WINDOW_LEFT_EDGE_X (w
);
21078 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21082 area_left
= window_box_left (w
, area
);
21083 last_x
= area_left
+ window_box_width (w
, area
);
21087 /* Build a doubly-linked list of glyph_string structures between
21088 head and tail from what we have to draw. Note that the macro
21089 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21090 the reason we use a separate variable `i'. */
21092 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21094 x_reached
= tail
->x
+ tail
->background_width
;
21098 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21099 the row, redraw some glyphs in front or following the glyph
21100 strings built above. */
21101 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21103 struct glyph_string
*h
, *t
;
21104 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21105 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
21108 /* If mouse highlighting is on, we may need to draw adjacent
21109 glyphs using mouse-face highlighting. */
21110 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21112 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21114 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21115 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21117 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21119 check_mouse_face
= 1;
21120 mouse_beg_col
= (row
== mouse_beg_row
)
21121 ? dpyinfo
->mouse_face_beg_col
: 0;
21122 mouse_end_col
= (row
== mouse_end_row
)
21123 ? dpyinfo
->mouse_face_end_col
21124 : row
->used
[TEXT_AREA
];
21128 /* Compute overhangs for all glyph strings. */
21129 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21130 for (s
= head
; s
; s
= s
->next
)
21131 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21133 /* Prepend glyph strings for glyphs in front of the first glyph
21134 string that are overwritten because of the first glyph
21135 string's left overhang. The background of all strings
21136 prepended must be drawn because the first glyph string
21138 i
= left_overwritten (head
);
21141 enum draw_glyphs_face overlap_hl
;
21143 /* If this row contains mouse highlighting, attempt to draw
21144 the overlapped glyphs with the correct highlight. This
21145 code fails if the overlap encompasses more than one glyph
21146 and mouse-highlight spans only some of these glyphs.
21147 However, making it work perfectly involves a lot more
21148 code, and I don't know if the pathological case occurs in
21149 practice, so we'll stick to this for now. --- cyd */
21150 if (check_mouse_face
21151 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21152 overlap_hl
= DRAW_MOUSE_FACE
;
21154 overlap_hl
= DRAW_NORMAL_TEXT
;
21157 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21158 overlap_hl
, dummy_x
, last_x
);
21160 compute_overhangs_and_x (t
, head
->x
, 1);
21161 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21165 /* Prepend glyph strings for glyphs in front of the first glyph
21166 string that overwrite that glyph string because of their
21167 right overhang. For these strings, only the foreground must
21168 be drawn, because it draws over the glyph string at `head'.
21169 The background must not be drawn because this would overwrite
21170 right overhangs of preceding glyphs for which no glyph
21172 i
= left_overwriting (head
);
21175 enum draw_glyphs_face overlap_hl
;
21177 if (check_mouse_face
21178 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21179 overlap_hl
= DRAW_MOUSE_FACE
;
21181 overlap_hl
= DRAW_NORMAL_TEXT
;
21184 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21185 overlap_hl
, dummy_x
, last_x
);
21186 for (s
= h
; s
; s
= s
->next
)
21187 s
->background_filled_p
= 1;
21188 compute_overhangs_and_x (t
, head
->x
, 1);
21189 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21192 /* Append glyphs strings for glyphs following the last glyph
21193 string tail that are overwritten by tail. The background of
21194 these strings has to be drawn because tail's foreground draws
21196 i
= right_overwritten (tail
);
21199 enum draw_glyphs_face overlap_hl
;
21201 if (check_mouse_face
21202 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21203 overlap_hl
= DRAW_MOUSE_FACE
;
21205 overlap_hl
= DRAW_NORMAL_TEXT
;
21207 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21208 overlap_hl
, x
, last_x
);
21209 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21210 we don't have `end = i;' here. */
21211 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21212 append_glyph_string_lists (&head
, &tail
, h
, t
);
21216 /* Append glyph strings for glyphs following the last glyph
21217 string tail that overwrite tail. The foreground of such
21218 glyphs has to be drawn because it writes into the background
21219 of tail. The background must not be drawn because it could
21220 paint over the foreground of following glyphs. */
21221 i
= right_overwriting (tail
);
21224 enum draw_glyphs_face overlap_hl
;
21225 if (check_mouse_face
21226 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21227 overlap_hl
= DRAW_MOUSE_FACE
;
21229 overlap_hl
= DRAW_NORMAL_TEXT
;
21232 i
++; /* We must include the Ith glyph. */
21233 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21234 overlap_hl
, x
, last_x
);
21235 for (s
= h
; s
; s
= s
->next
)
21236 s
->background_filled_p
= 1;
21237 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21238 append_glyph_string_lists (&head
, &tail
, h
, t
);
21240 if (clip_head
|| clip_tail
)
21241 for (s
= head
; s
; s
= s
->next
)
21243 s
->clip_head
= clip_head
;
21244 s
->clip_tail
= clip_tail
;
21248 /* Draw all strings. */
21249 for (s
= head
; s
; s
= s
->next
)
21250 FRAME_RIF (f
)->draw_glyph_string (s
);
21253 /* When focus a sole frame and move horizontally, this sets on_p to 0
21254 causing a failure to erase prev cursor position. */
21255 if (area
== TEXT_AREA
21256 && !row
->full_width_p
21257 /* When drawing overlapping rows, only the glyph strings'
21258 foreground is drawn, which doesn't erase a cursor
21262 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21263 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21264 : (tail
? tail
->x
+ tail
->background_width
: x
));
21268 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21269 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21273 /* Value is the x-position up to which drawn, relative to AREA of W.
21274 This doesn't include parts drawn because of overhangs. */
21275 if (row
->full_width_p
)
21276 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21278 x_reached
-= area_left
;
21280 RELEASE_HDC (hdc
, f
);
21285 /* Expand row matrix if too narrow. Don't expand if area
21288 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21290 if (!fonts_changed_p \
21291 && (it->glyph_row->glyphs[area] \
21292 < it->glyph_row->glyphs[area + 1])) \
21294 it->w->ncols_scale_factor++; \
21295 fonts_changed_p = 1; \
21299 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21300 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21306 struct glyph
*glyph
;
21307 enum glyph_row_area area
= it
->area
;
21309 xassert (it
->glyph_row
);
21310 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21312 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21313 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21315 /* If the glyph row is reversed, we need to prepend the glyph
21316 rather than append it. */
21317 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
21321 /* Make room for the additional glyph. */
21322 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
21324 glyph
= it
->glyph_row
->glyphs
[area
];
21326 glyph
->charpos
= CHARPOS (it
->position
);
21327 glyph
->object
= it
->object
;
21328 if (it
->pixel_width
> 0)
21330 glyph
->pixel_width
= it
->pixel_width
;
21331 glyph
->padding_p
= 0;
21335 /* Assure at least 1-pixel width. Otherwise, cursor can't
21336 be displayed correctly. */
21337 glyph
->pixel_width
= 1;
21338 glyph
->padding_p
= 1;
21340 glyph
->ascent
= it
->ascent
;
21341 glyph
->descent
= it
->descent
;
21342 glyph
->voffset
= it
->voffset
;
21343 glyph
->type
= CHAR_GLYPH
;
21344 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21345 glyph
->multibyte_p
= it
->multibyte_p
;
21346 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21347 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21348 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21349 || it
->phys_descent
> it
->descent
);
21350 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21351 glyph
->face_id
= it
->face_id
;
21352 glyph
->u
.ch
= it
->char_to_display
;
21353 glyph
->slice
= null_glyph_slice
;
21354 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21357 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21358 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21360 glyph
->bidi_type
= it
->bidi_it
.type
;
21364 glyph
->resolved_level
= 0;
21365 glyph
->bidi_type
= UNKNOWN_BT
;
21367 ++it
->glyph_row
->used
[area
];
21370 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21373 /* Store one glyph for the composition IT->cmp_it.id in
21374 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21378 append_composite_glyph (it
)
21381 struct glyph
*glyph
;
21382 enum glyph_row_area area
= it
->area
;
21384 xassert (it
->glyph_row
);
21386 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21387 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21389 glyph
->charpos
= CHARPOS (it
->position
);
21390 glyph
->object
= it
->object
;
21391 glyph
->pixel_width
= it
->pixel_width
;
21392 glyph
->ascent
= it
->ascent
;
21393 glyph
->descent
= it
->descent
;
21394 glyph
->voffset
= it
->voffset
;
21395 glyph
->type
= COMPOSITE_GLYPH
;
21396 if (it
->cmp_it
.ch
< 0)
21398 glyph
->u
.cmp
.automatic
= 0;
21399 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21403 glyph
->u
.cmp
.automatic
= 1;
21404 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21405 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
21406 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
21408 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21409 glyph
->multibyte_p
= it
->multibyte_p
;
21410 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21411 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21412 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21413 || it
->phys_descent
> it
->descent
);
21414 glyph
->padding_p
= 0;
21415 glyph
->glyph_not_available_p
= 0;
21416 glyph
->face_id
= it
->face_id
;
21417 glyph
->slice
= null_glyph_slice
;
21418 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21421 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21422 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21424 glyph
->bidi_type
= it
->bidi_it
.type
;
21426 ++it
->glyph_row
->used
[area
];
21429 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21433 /* Change IT->ascent and IT->height according to the setting of
21437 take_vertical_position_into_account (it
)
21442 if (it
->voffset
< 0)
21443 /* Increase the ascent so that we can display the text higher
21445 it
->ascent
-= it
->voffset
;
21447 /* Increase the descent so that we can display the text lower
21449 it
->descent
+= it
->voffset
;
21454 /* Produce glyphs/get display metrics for the image IT is loaded with.
21455 See the description of struct display_iterator in dispextern.h for
21456 an overview of struct display_iterator. */
21459 produce_image_glyph (it
)
21464 int glyph_ascent
, crop
;
21465 struct glyph_slice slice
;
21467 xassert (it
->what
== IT_IMAGE
);
21469 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21471 /* Make sure X resources of the face is loaded. */
21472 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21474 if (it
->image_id
< 0)
21476 /* Fringe bitmap. */
21477 it
->ascent
= it
->phys_ascent
= 0;
21478 it
->descent
= it
->phys_descent
= 0;
21479 it
->pixel_width
= 0;
21484 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21486 /* Make sure X resources of the image is loaded. */
21487 prepare_image_for_display (it
->f
, img
);
21489 slice
.x
= slice
.y
= 0;
21490 slice
.width
= img
->width
;
21491 slice
.height
= img
->height
;
21493 if (INTEGERP (it
->slice
.x
))
21494 slice
.x
= XINT (it
->slice
.x
);
21495 else if (FLOATP (it
->slice
.x
))
21496 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21498 if (INTEGERP (it
->slice
.y
))
21499 slice
.y
= XINT (it
->slice
.y
);
21500 else if (FLOATP (it
->slice
.y
))
21501 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21503 if (INTEGERP (it
->slice
.width
))
21504 slice
.width
= XINT (it
->slice
.width
);
21505 else if (FLOATP (it
->slice
.width
))
21506 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21508 if (INTEGERP (it
->slice
.height
))
21509 slice
.height
= XINT (it
->slice
.height
);
21510 else if (FLOATP (it
->slice
.height
))
21511 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21513 if (slice
.x
>= img
->width
)
21514 slice
.x
= img
->width
;
21515 if (slice
.y
>= img
->height
)
21516 slice
.y
= img
->height
;
21517 if (slice
.x
+ slice
.width
>= img
->width
)
21518 slice
.width
= img
->width
- slice
.x
;
21519 if (slice
.y
+ slice
.height
> img
->height
)
21520 slice
.height
= img
->height
- slice
.y
;
21522 if (slice
.width
== 0 || slice
.height
== 0)
21525 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21527 it
->descent
= slice
.height
- glyph_ascent
;
21529 it
->descent
+= img
->vmargin
;
21530 if (slice
.y
+ slice
.height
== img
->height
)
21531 it
->descent
+= img
->vmargin
;
21532 it
->phys_descent
= it
->descent
;
21534 it
->pixel_width
= slice
.width
;
21536 it
->pixel_width
+= img
->hmargin
;
21537 if (slice
.x
+ slice
.width
== img
->width
)
21538 it
->pixel_width
+= img
->hmargin
;
21540 /* It's quite possible for images to have an ascent greater than
21541 their height, so don't get confused in that case. */
21542 if (it
->descent
< 0)
21547 if (face
->box
!= FACE_NO_BOX
)
21549 if (face
->box_line_width
> 0)
21552 it
->ascent
+= face
->box_line_width
;
21553 if (slice
.y
+ slice
.height
== img
->height
)
21554 it
->descent
+= face
->box_line_width
;
21557 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21558 it
->pixel_width
+= eabs (face
->box_line_width
);
21559 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21560 it
->pixel_width
+= eabs (face
->box_line_width
);
21563 take_vertical_position_into_account (it
);
21565 /* Automatically crop wide image glyphs at right edge so we can
21566 draw the cursor on same display row. */
21567 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21568 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21570 it
->pixel_width
-= crop
;
21571 slice
.width
-= crop
;
21576 struct glyph
*glyph
;
21577 enum glyph_row_area area
= it
->area
;
21579 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21580 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21582 glyph
->charpos
= CHARPOS (it
->position
);
21583 glyph
->object
= it
->object
;
21584 glyph
->pixel_width
= it
->pixel_width
;
21585 glyph
->ascent
= glyph_ascent
;
21586 glyph
->descent
= it
->descent
;
21587 glyph
->voffset
= it
->voffset
;
21588 glyph
->type
= IMAGE_GLYPH
;
21589 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21590 glyph
->multibyte_p
= it
->multibyte_p
;
21591 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21592 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21593 glyph
->overlaps_vertically_p
= 0;
21594 glyph
->padding_p
= 0;
21595 glyph
->glyph_not_available_p
= 0;
21596 glyph
->face_id
= it
->face_id
;
21597 glyph
->u
.img_id
= img
->id
;
21598 glyph
->slice
= slice
;
21599 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21602 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21603 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21605 glyph
->bidi_type
= it
->bidi_it
.type
;
21607 ++it
->glyph_row
->used
[area
];
21610 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21615 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
21616 of the glyph, WIDTH and HEIGHT are the width and height of the
21617 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
21620 append_stretch_glyph (it
, object
, width
, height
, ascent
)
21622 Lisp_Object object
;
21626 struct glyph
*glyph
;
21627 enum glyph_row_area area
= it
->area
;
21629 xassert (ascent
>= 0 && ascent
<= height
);
21631 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21632 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21634 glyph
->charpos
= CHARPOS (it
->position
);
21635 glyph
->object
= object
;
21636 glyph
->pixel_width
= width
;
21637 glyph
->ascent
= ascent
;
21638 glyph
->descent
= height
- ascent
;
21639 glyph
->voffset
= it
->voffset
;
21640 glyph
->type
= STRETCH_GLYPH
;
21641 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21642 glyph
->multibyte_p
= it
->multibyte_p
;
21643 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21644 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21645 glyph
->overlaps_vertically_p
= 0;
21646 glyph
->padding_p
= 0;
21647 glyph
->glyph_not_available_p
= 0;
21648 glyph
->face_id
= it
->face_id
;
21649 glyph
->u
.stretch
.ascent
= ascent
;
21650 glyph
->u
.stretch
.height
= height
;
21651 glyph
->slice
= null_glyph_slice
;
21652 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21655 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21656 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21658 glyph
->bidi_type
= it
->bidi_it
.type
;
21660 ++it
->glyph_row
->used
[area
];
21663 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21667 /* Produce a stretch glyph for iterator IT. IT->object is the value
21668 of the glyph property displayed. The value must be a list
21669 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
21672 1. `:width WIDTH' specifies that the space should be WIDTH *
21673 canonical char width wide. WIDTH may be an integer or floating
21676 2. `:relative-width FACTOR' specifies that the width of the stretch
21677 should be computed from the width of the first character having the
21678 `glyph' property, and should be FACTOR times that width.
21680 3. `:align-to HPOS' specifies that the space should be wide enough
21681 to reach HPOS, a value in canonical character units.
21683 Exactly one of the above pairs must be present.
21685 4. `:height HEIGHT' specifies that the height of the stretch produced
21686 should be HEIGHT, measured in canonical character units.
21688 5. `:relative-height FACTOR' specifies that the height of the
21689 stretch should be FACTOR times the height of the characters having
21690 the glyph property.
21692 Either none or exactly one of 4 or 5 must be present.
21694 6. `:ascent ASCENT' specifies that ASCENT percent of the height
21695 of the stretch should be used for the ascent of the stretch.
21696 ASCENT must be in the range 0 <= ASCENT <= 100. */
21699 produce_stretch_glyph (it
)
21702 /* (space :width WIDTH :height HEIGHT ...) */
21703 Lisp_Object prop
, plist
;
21704 int width
= 0, height
= 0, align_to
= -1;
21705 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
21708 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21709 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
21711 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21713 /* List should start with `space'. */
21714 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
21715 plist
= XCDR (it
->object
);
21717 /* Compute the width of the stretch. */
21718 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
21719 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
21721 /* Absolute width `:width WIDTH' specified and valid. */
21722 zero_width_ok_p
= 1;
21725 else if (prop
= Fplist_get (plist
, QCrelative_width
),
21728 /* Relative width `:relative-width FACTOR' specified and valid.
21729 Compute the width of the characters having the `glyph'
21732 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
21735 if (it
->multibyte_p
)
21737 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
21738 - IT_BYTEPOS (*it
));
21739 it2
.c
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
21742 it2
.c
= *p
, it2
.len
= 1;
21744 it2
.glyph_row
= NULL
;
21745 it2
.what
= IT_CHARACTER
;
21746 x_produce_glyphs (&it2
);
21747 width
= NUMVAL (prop
) * it2
.pixel_width
;
21749 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
21750 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
21752 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
21753 align_to
= (align_to
< 0
21755 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
21756 else if (align_to
< 0)
21757 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
21758 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
21759 zero_width_ok_p
= 1;
21762 /* Nothing specified -> width defaults to canonical char width. */
21763 width
= FRAME_COLUMN_WIDTH (it
->f
);
21765 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
21768 /* Compute height. */
21769 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
21770 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21773 zero_height_ok_p
= 1;
21775 else if (prop
= Fplist_get (plist
, QCrelative_height
),
21777 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
21779 height
= FONT_HEIGHT (font
);
21781 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
21784 /* Compute percentage of height used for ascent. If
21785 `:ascent ASCENT' is present and valid, use that. Otherwise,
21786 derive the ascent from the font in use. */
21787 if (prop
= Fplist_get (plist
, QCascent
),
21788 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
21789 ascent
= height
* NUMVAL (prop
) / 100.0;
21790 else if (!NILP (prop
)
21791 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21792 ascent
= min (max (0, (int)tem
), height
);
21794 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
21796 if (width
> 0 && it
->line_wrap
!= TRUNCATE
21797 && it
->current_x
+ width
> it
->last_visible_x
)
21798 width
= it
->last_visible_x
- it
->current_x
- 1;
21800 if (width
> 0 && height
> 0 && it
->glyph_row
)
21802 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
21803 if (!STRINGP (object
))
21804 object
= it
->w
->buffer
;
21805 append_stretch_glyph (it
, object
, width
, height
, ascent
);
21808 it
->pixel_width
= width
;
21809 it
->ascent
= it
->phys_ascent
= ascent
;
21810 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
21811 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21813 take_vertical_position_into_account (it
);
21816 /* Calculate line-height and line-spacing properties.
21817 An integer value specifies explicit pixel value.
21818 A float value specifies relative value to current face height.
21819 A cons (float . face-name) specifies relative value to
21820 height of specified face font.
21822 Returns height in pixels, or nil. */
21826 calc_line_height_property (it
, val
, font
, boff
, override
)
21830 int boff
, override
;
21832 Lisp_Object face_name
= Qnil
;
21833 int ascent
, descent
, height
;
21835 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21840 face_name
= XCAR (val
);
21842 if (!NUMBERP (val
))
21843 val
= make_number (1);
21844 if (NILP (face_name
))
21846 height
= it
->ascent
+ it
->descent
;
21851 if (NILP (face_name
))
21853 font
= FRAME_FONT (it
->f
);
21854 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21856 else if (EQ (face_name
, Qt
))
21865 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21867 return make_number (-1);
21869 face
= FACE_FROM_ID (it
->f
, face_id
);
21872 return make_number (-1);
21873 boff
= font
->baseline_offset
;
21874 if (font
->vertical_centering
)
21875 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21878 ascent
= FONT_BASE (font
) + boff
;
21879 descent
= FONT_DESCENT (font
) - boff
;
21883 it
->override_ascent
= ascent
;
21884 it
->override_descent
= descent
;
21885 it
->override_boff
= boff
;
21888 height
= ascent
+ descent
;
21892 height
= (int)(XFLOAT_DATA (val
) * height
);
21893 else if (INTEGERP (val
))
21894 height
*= XINT (val
);
21896 return make_number (height
);
21901 Produce glyphs/get display metrics for the display element IT is
21902 loaded with. See the description of struct it in dispextern.h
21903 for an overview of struct it. */
21906 x_produce_glyphs (it
)
21909 int extra_line_spacing
= it
->extra_line_spacing
;
21911 it
->glyph_not_available_p
= 0;
21913 if (it
->what
== IT_CHARACTER
)
21917 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21918 struct font_metrics
*pcm
;
21919 int font_not_found_p
;
21920 int boff
; /* baseline offset */
21921 /* We may change it->multibyte_p upon unibyte<->multibyte
21922 conversion. So, save the current value now and restore it
21925 Note: It seems that we don't have to record multibyte_p in
21926 struct glyph because the character code itself tells whether
21927 or not the character is multibyte. Thus, in the future, we
21928 must consider eliminating the field `multibyte_p' in the
21930 int saved_multibyte_p
= it
->multibyte_p
;
21932 /* Maybe translate single-byte characters to multibyte, or the
21934 it
->char_to_display
= it
->c
;
21935 if (!ASCII_BYTE_P (it
->c
)
21936 && ! it
->multibyte_p
)
21938 if (SINGLE_BYTE_CHAR_P (it
->c
)
21939 && unibyte_display_via_language_environment
)
21941 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
21943 /* get_next_display_element assures that this decoding
21945 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
21946 it
->multibyte_p
= 1;
21947 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21949 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21953 /* Get font to use. Encode IT->char_to_display. */
21954 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21955 &char2b
, it
->multibyte_p
, 0);
21958 font_not_found_p
= font
== NULL
;
21959 if (font_not_found_p
)
21961 /* When no suitable font found, display an empty box based
21962 on the metrics of the font of the default face (or what
21964 struct face
*no_font_face
21965 = FACE_FROM_ID (it
->f
,
21966 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
21967 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
21968 font
= no_font_face
->font
;
21969 boff
= font
->baseline_offset
;
21973 boff
= font
->baseline_offset
;
21974 if (font
->vertical_centering
)
21975 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21978 if (it
->char_to_display
>= ' '
21979 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21981 /* Either unibyte or ASCII. */
21986 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21988 if (it
->override_ascent
>= 0)
21990 it
->ascent
= it
->override_ascent
;
21991 it
->descent
= it
->override_descent
;
21992 boff
= it
->override_boff
;
21996 it
->ascent
= FONT_BASE (font
) + boff
;
21997 it
->descent
= FONT_DESCENT (font
) - boff
;
22002 it
->phys_ascent
= pcm
->ascent
+ boff
;
22003 it
->phys_descent
= pcm
->descent
- boff
;
22004 it
->pixel_width
= pcm
->width
;
22008 it
->glyph_not_available_p
= 1;
22009 it
->phys_ascent
= it
->ascent
;
22010 it
->phys_descent
= it
->descent
;
22011 it
->pixel_width
= FONT_WIDTH (font
);
22014 if (it
->constrain_row_ascent_descent_p
)
22016 if (it
->descent
> it
->max_descent
)
22018 it
->ascent
+= it
->descent
- it
->max_descent
;
22019 it
->descent
= it
->max_descent
;
22021 if (it
->ascent
> it
->max_ascent
)
22023 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22024 it
->ascent
= it
->max_ascent
;
22026 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22027 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22028 extra_line_spacing
= 0;
22031 /* If this is a space inside a region of text with
22032 `space-width' property, change its width. */
22033 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22035 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22037 /* If face has a box, add the box thickness to the character
22038 height. If character has a box line to the left and/or
22039 right, add the box line width to the character's width. */
22040 if (face
->box
!= FACE_NO_BOX
)
22042 int thick
= face
->box_line_width
;
22046 it
->ascent
+= thick
;
22047 it
->descent
+= thick
;
22052 if (it
->start_of_box_run_p
)
22053 it
->pixel_width
+= thick
;
22054 if (it
->end_of_box_run_p
)
22055 it
->pixel_width
+= thick
;
22058 /* If face has an overline, add the height of the overline
22059 (1 pixel) and a 1 pixel margin to the character height. */
22060 if (face
->overline_p
)
22061 it
->ascent
+= overline_margin
;
22063 if (it
->constrain_row_ascent_descent_p
)
22065 if (it
->ascent
> it
->max_ascent
)
22066 it
->ascent
= it
->max_ascent
;
22067 if (it
->descent
> it
->max_descent
)
22068 it
->descent
= it
->max_descent
;
22071 take_vertical_position_into_account (it
);
22073 /* If we have to actually produce glyphs, do it. */
22078 /* Translate a space with a `space-width' property
22079 into a stretch glyph. */
22080 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22081 / FONT_HEIGHT (font
));
22082 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22083 it
->ascent
+ it
->descent
, ascent
);
22088 /* If characters with lbearing or rbearing are displayed
22089 in this line, record that fact in a flag of the
22090 glyph row. This is used to optimize X output code. */
22091 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22092 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22094 if (! stretched_p
&& it
->pixel_width
== 0)
22095 /* We assure that all visible glyphs have at least 1-pixel
22097 it
->pixel_width
= 1;
22099 else if (it
->char_to_display
== '\n')
22101 /* A newline has no width, but we need the height of the
22102 line. But if previous part of the line sets a height,
22103 don't increase that height */
22105 Lisp_Object height
;
22106 Lisp_Object total_height
= Qnil
;
22108 it
->override_ascent
= -1;
22109 it
->pixel_width
= 0;
22112 height
= get_it_property(it
, Qline_height
);
22113 /* Split (line-height total-height) list */
22115 && CONSP (XCDR (height
))
22116 && NILP (XCDR (XCDR (height
))))
22118 total_height
= XCAR (XCDR (height
));
22119 height
= XCAR (height
);
22121 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
22123 if (it
->override_ascent
>= 0)
22125 it
->ascent
= it
->override_ascent
;
22126 it
->descent
= it
->override_descent
;
22127 boff
= it
->override_boff
;
22131 it
->ascent
= FONT_BASE (font
) + boff
;
22132 it
->descent
= FONT_DESCENT (font
) - boff
;
22135 if (EQ (height
, Qt
))
22137 if (it
->descent
> it
->max_descent
)
22139 it
->ascent
+= it
->descent
- it
->max_descent
;
22140 it
->descent
= it
->max_descent
;
22142 if (it
->ascent
> it
->max_ascent
)
22144 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22145 it
->ascent
= it
->max_ascent
;
22147 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22148 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22149 it
->constrain_row_ascent_descent_p
= 1;
22150 extra_line_spacing
= 0;
22154 Lisp_Object spacing
;
22156 it
->phys_ascent
= it
->ascent
;
22157 it
->phys_descent
= it
->descent
;
22159 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22160 && face
->box
!= FACE_NO_BOX
22161 && face
->box_line_width
> 0)
22163 it
->ascent
+= face
->box_line_width
;
22164 it
->descent
+= face
->box_line_width
;
22167 && XINT (height
) > it
->ascent
+ it
->descent
)
22168 it
->ascent
= XINT (height
) - it
->descent
;
22170 if (!NILP (total_height
))
22171 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
22174 spacing
= get_it_property(it
, Qline_spacing
);
22175 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
22177 if (INTEGERP (spacing
))
22179 extra_line_spacing
= XINT (spacing
);
22180 if (!NILP (total_height
))
22181 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22185 else if (it
->char_to_display
== '\t')
22187 if (font
->space_width
> 0)
22189 int tab_width
= it
->tab_width
* font
->space_width
;
22190 int x
= it
->current_x
+ it
->continuation_lines_width
;
22191 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22193 /* If the distance from the current position to the next tab
22194 stop is less than a space character width, use the
22195 tab stop after that. */
22196 if (next_tab_x
- x
< font
->space_width
)
22197 next_tab_x
+= tab_width
;
22199 it
->pixel_width
= next_tab_x
- x
;
22201 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22202 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22206 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22207 it
->ascent
+ it
->descent
, it
->ascent
);
22212 it
->pixel_width
= 0;
22218 /* A multi-byte character. Assume that the display width of the
22219 character is the width of the character multiplied by the
22220 width of the font. */
22222 /* If we found a font, this font should give us the right
22223 metrics. If we didn't find a font, use the frame's
22224 default font and calculate the width of the character by
22225 multiplying the width of font by the width of the
22228 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22230 if (font_not_found_p
|| !pcm
)
22232 int char_width
= CHAR_WIDTH (it
->char_to_display
);
22234 if (char_width
== 0)
22235 /* This is a non spacing character. But, as we are
22236 going to display an empty box, the box must occupy
22237 at least one column. */
22239 it
->glyph_not_available_p
= 1;
22240 it
->pixel_width
= font
->space_width
* char_width
;
22241 it
->phys_ascent
= FONT_BASE (font
) + boff
;
22242 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22246 it
->pixel_width
= pcm
->width
;
22247 it
->phys_ascent
= pcm
->ascent
+ boff
;
22248 it
->phys_descent
= pcm
->descent
- boff
;
22250 && (pcm
->lbearing
< 0
22251 || pcm
->rbearing
> pcm
->width
))
22252 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22255 it
->ascent
= FONT_BASE (font
) + boff
;
22256 it
->descent
= FONT_DESCENT (font
) - boff
;
22257 if (face
->box
!= FACE_NO_BOX
)
22259 int thick
= face
->box_line_width
;
22263 it
->ascent
+= thick
;
22264 it
->descent
+= thick
;
22269 if (it
->start_of_box_run_p
)
22270 it
->pixel_width
+= thick
;
22271 if (it
->end_of_box_run_p
)
22272 it
->pixel_width
+= thick
;
22275 /* If face has an overline, add the height of the overline
22276 (1 pixel) and a 1 pixel margin to the character height. */
22277 if (face
->overline_p
)
22278 it
->ascent
+= overline_margin
;
22280 take_vertical_position_into_account (it
);
22282 if (it
->ascent
< 0)
22284 if (it
->descent
< 0)
22289 if (it
->pixel_width
== 0)
22290 /* We assure that all visible glyphs have at least 1-pixel
22292 it
->pixel_width
= 1;
22294 it
->multibyte_p
= saved_multibyte_p
;
22296 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22298 /* A static composition.
22300 Note: A composition is represented as one glyph in the
22301 glyph matrix. There are no padding glyphs.
22303 Important note: pixel_width, ascent, and descent are the
22304 values of what is drawn by draw_glyphs (i.e. the values of
22305 the overall glyphs composed). */
22306 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22307 int boff
; /* baseline offset */
22308 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22309 int glyph_len
= cmp
->glyph_len
;
22310 struct font
*font
= face
->font
;
22314 /* If we have not yet calculated pixel size data of glyphs of
22315 the composition for the current face font, calculate them
22316 now. Theoretically, we have to check all fonts for the
22317 glyphs, but that requires much time and memory space. So,
22318 here we check only the font of the first glyph. This may
22319 lead to incorrect display, but it's very rare, and C-l
22320 (recenter-top-bottom) can correct the display anyway. */
22321 if (! cmp
->font
|| cmp
->font
!= font
)
22323 /* Ascent and descent of the font of the first character
22324 of this composition (adjusted by baseline offset).
22325 Ascent and descent of overall glyphs should not be less
22326 than these, respectively. */
22327 int font_ascent
, font_descent
, font_height
;
22328 /* Bounding box of the overall glyphs. */
22329 int leftmost
, rightmost
, lowest
, highest
;
22330 int lbearing
, rbearing
;
22331 int i
, width
, ascent
, descent
;
22332 int left_padded
= 0, right_padded
= 0;
22335 struct font_metrics
*pcm
;
22336 int font_not_found_p
;
22339 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22340 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22342 if (glyph_len
< cmp
->glyph_len
)
22344 for (i
= 0; i
< glyph_len
; i
++)
22346 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22348 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22353 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22354 : IT_CHARPOS (*it
));
22355 /* If no suitable font is found, use the default font. */
22356 font_not_found_p
= font
== NULL
;
22357 if (font_not_found_p
)
22359 face
= face
->ascii_face
;
22362 boff
= font
->baseline_offset
;
22363 if (font
->vertical_centering
)
22364 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22365 font_ascent
= FONT_BASE (font
) + boff
;
22366 font_descent
= FONT_DESCENT (font
) - boff
;
22367 font_height
= FONT_HEIGHT (font
);
22369 cmp
->font
= (void *) font
;
22372 if (! font_not_found_p
)
22374 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22375 &char2b
, it
->multibyte_p
, 0);
22376 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22379 /* Initialize the bounding box. */
22382 width
= pcm
->width
;
22383 ascent
= pcm
->ascent
;
22384 descent
= pcm
->descent
;
22385 lbearing
= pcm
->lbearing
;
22386 rbearing
= pcm
->rbearing
;
22390 width
= FONT_WIDTH (font
);
22391 ascent
= FONT_BASE (font
);
22392 descent
= FONT_DESCENT (font
);
22399 lowest
= - descent
+ boff
;
22400 highest
= ascent
+ boff
;
22402 if (! font_not_found_p
22403 && font
->default_ascent
22404 && CHAR_TABLE_P (Vuse_default_ascent
)
22405 && !NILP (Faref (Vuse_default_ascent
,
22406 make_number (it
->char_to_display
))))
22407 highest
= font
->default_ascent
+ boff
;
22409 /* Draw the first glyph at the normal position. It may be
22410 shifted to right later if some other glyphs are drawn
22412 cmp
->offsets
[i
* 2] = 0;
22413 cmp
->offsets
[i
* 2 + 1] = boff
;
22414 cmp
->lbearing
= lbearing
;
22415 cmp
->rbearing
= rbearing
;
22417 /* Set cmp->offsets for the remaining glyphs. */
22418 for (i
++; i
< glyph_len
; i
++)
22420 int left
, right
, btm
, top
;
22421 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22423 struct face
*this_face
;
22428 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22429 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22430 font
= this_face
->font
;
22436 this_boff
= font
->baseline_offset
;
22437 if (font
->vertical_centering
)
22438 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22439 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22440 &char2b
, it
->multibyte_p
, 0);
22441 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22444 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22447 width
= pcm
->width
;
22448 ascent
= pcm
->ascent
;
22449 descent
= pcm
->descent
;
22450 lbearing
= pcm
->lbearing
;
22451 rbearing
= pcm
->rbearing
;
22452 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22454 /* Relative composition with or without
22455 alternate chars. */
22456 left
= (leftmost
+ rightmost
- width
) / 2;
22457 btm
= - descent
+ boff
;
22458 if (font
->relative_compose
22459 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22460 || NILP (Faref (Vignore_relative_composition
,
22461 make_number (ch
)))))
22464 if (- descent
>= font
->relative_compose
)
22465 /* One extra pixel between two glyphs. */
22467 else if (ascent
<= 0)
22468 /* One extra pixel between two glyphs. */
22469 btm
= lowest
- 1 - ascent
- descent
;
22474 /* A composition rule is specified by an integer
22475 value that encodes global and new reference
22476 points (GREF and NREF). GREF and NREF are
22477 specified by numbers as below:
22479 0---1---2 -- ascent
22483 9--10--11 -- center
22485 ---3---4---5--- baseline
22487 6---7---8 -- descent
22489 int rule
= COMPOSITION_RULE (cmp
, i
);
22490 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
22492 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
22493 grefx
= gref
% 3, nrefx
= nref
% 3;
22494 grefy
= gref
/ 3, nrefy
= nref
/ 3;
22496 xoff
= font_height
* (xoff
- 128) / 256;
22498 yoff
= font_height
* (yoff
- 128) / 256;
22501 + grefx
* (rightmost
- leftmost
) / 2
22502 - nrefx
* width
/ 2
22505 btm
= ((grefy
== 0 ? highest
22507 : grefy
== 2 ? lowest
22508 : (highest
+ lowest
) / 2)
22509 - (nrefy
== 0 ? ascent
+ descent
22510 : nrefy
== 1 ? descent
- boff
22512 : (ascent
+ descent
) / 2)
22516 cmp
->offsets
[i
* 2] = left
;
22517 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
22519 /* Update the bounding box of the overall glyphs. */
22522 right
= left
+ width
;
22523 if (left
< leftmost
)
22525 if (right
> rightmost
)
22528 top
= btm
+ descent
+ ascent
;
22534 if (cmp
->lbearing
> left
+ lbearing
)
22535 cmp
->lbearing
= left
+ lbearing
;
22536 if (cmp
->rbearing
< left
+ rbearing
)
22537 cmp
->rbearing
= left
+ rbearing
;
22541 /* If there are glyphs whose x-offsets are negative,
22542 shift all glyphs to the right and make all x-offsets
22546 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22547 cmp
->offsets
[i
* 2] -= leftmost
;
22548 rightmost
-= leftmost
;
22549 cmp
->lbearing
-= leftmost
;
22550 cmp
->rbearing
-= leftmost
;
22553 if (left_padded
&& cmp
->lbearing
< 0)
22555 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22556 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
22557 rightmost
-= cmp
->lbearing
;
22558 cmp
->rbearing
-= cmp
->lbearing
;
22561 if (right_padded
&& rightmost
< cmp
->rbearing
)
22563 rightmost
= cmp
->rbearing
;
22566 cmp
->pixel_width
= rightmost
;
22567 cmp
->ascent
= highest
;
22568 cmp
->descent
= - lowest
;
22569 if (cmp
->ascent
< font_ascent
)
22570 cmp
->ascent
= font_ascent
;
22571 if (cmp
->descent
< font_descent
)
22572 cmp
->descent
= font_descent
;
22576 && (cmp
->lbearing
< 0
22577 || cmp
->rbearing
> cmp
->pixel_width
))
22578 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22580 it
->pixel_width
= cmp
->pixel_width
;
22581 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
22582 it
->descent
= it
->phys_descent
= cmp
->descent
;
22583 if (face
->box
!= FACE_NO_BOX
)
22585 int thick
= face
->box_line_width
;
22589 it
->ascent
+= thick
;
22590 it
->descent
+= thick
;
22595 if (it
->start_of_box_run_p
)
22596 it
->pixel_width
+= thick
;
22597 if (it
->end_of_box_run_p
)
22598 it
->pixel_width
+= thick
;
22601 /* If face has an overline, add the height of the overline
22602 (1 pixel) and a 1 pixel margin to the character height. */
22603 if (face
->overline_p
)
22604 it
->ascent
+= overline_margin
;
22606 take_vertical_position_into_account (it
);
22607 if (it
->ascent
< 0)
22609 if (it
->descent
< 0)
22613 append_composite_glyph (it
);
22615 else if (it
->what
== IT_COMPOSITION
)
22617 /* A dynamic (automatic) composition. */
22618 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22619 Lisp_Object gstring
;
22620 struct font_metrics metrics
;
22622 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
22624 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
22627 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
22628 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22629 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
22630 it
->descent
= it
->phys_descent
= metrics
.descent
;
22631 if (face
->box
!= FACE_NO_BOX
)
22633 int thick
= face
->box_line_width
;
22637 it
->ascent
+= thick
;
22638 it
->descent
+= thick
;
22643 if (it
->start_of_box_run_p
)
22644 it
->pixel_width
+= thick
;
22645 if (it
->end_of_box_run_p
)
22646 it
->pixel_width
+= thick
;
22648 /* If face has an overline, add the height of the overline
22649 (1 pixel) and a 1 pixel margin to the character height. */
22650 if (face
->overline_p
)
22651 it
->ascent
+= overline_margin
;
22652 take_vertical_position_into_account (it
);
22653 if (it
->ascent
< 0)
22655 if (it
->descent
< 0)
22659 append_composite_glyph (it
);
22661 else if (it
->what
== IT_IMAGE
)
22662 produce_image_glyph (it
);
22663 else if (it
->what
== IT_STRETCH
)
22664 produce_stretch_glyph (it
);
22666 /* Accumulate dimensions. Note: can't assume that it->descent > 0
22667 because this isn't true for images with `:ascent 100'. */
22668 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
22669 if (it
->area
== TEXT_AREA
)
22670 it
->current_x
+= it
->pixel_width
;
22672 if (extra_line_spacing
> 0)
22674 it
->descent
+= extra_line_spacing
;
22675 if (extra_line_spacing
> it
->max_extra_line_spacing
)
22676 it
->max_extra_line_spacing
= extra_line_spacing
;
22679 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
22680 it
->max_descent
= max (it
->max_descent
, it
->descent
);
22681 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
22682 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
22686 Output LEN glyphs starting at START at the nominal cursor position.
22687 Advance the nominal cursor over the text. The global variable
22688 updated_window contains the window being updated, updated_row is
22689 the glyph row being updated, and updated_area is the area of that
22690 row being updated. */
22693 x_write_glyphs (start
, len
)
22694 struct glyph
*start
;
22699 xassert (updated_window
&& updated_row
);
22702 /* Write glyphs. */
22704 hpos
= start
- updated_row
->glyphs
[updated_area
];
22705 x
= draw_glyphs (updated_window
, output_cursor
.x
,
22706 updated_row
, updated_area
,
22708 DRAW_NORMAL_TEXT
, 0);
22710 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
22711 if (updated_area
== TEXT_AREA
22712 && updated_window
->phys_cursor_on_p
22713 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
22714 && updated_window
->phys_cursor
.hpos
>= hpos
22715 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
22716 updated_window
->phys_cursor_on_p
= 0;
22720 /* Advance the output cursor. */
22721 output_cursor
.hpos
+= len
;
22722 output_cursor
.x
= x
;
22727 Insert LEN glyphs from START at the nominal cursor position. */
22730 x_insert_glyphs (start
, len
)
22731 struct glyph
*start
;
22736 int line_height
, shift_by_width
, shifted_region_width
;
22737 struct glyph_row
*row
;
22738 struct glyph
*glyph
;
22739 int frame_x
, frame_y
;
22742 xassert (updated_window
&& updated_row
);
22744 w
= updated_window
;
22745 f
= XFRAME (WINDOW_FRAME (w
));
22747 /* Get the height of the line we are in. */
22749 line_height
= row
->height
;
22751 /* Get the width of the glyphs to insert. */
22752 shift_by_width
= 0;
22753 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
22754 shift_by_width
+= glyph
->pixel_width
;
22756 /* Get the width of the region to shift right. */
22757 shifted_region_width
= (window_box_width (w
, updated_area
)
22762 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
22763 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
22765 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
22766 line_height
, shift_by_width
);
22768 /* Write the glyphs. */
22769 hpos
= start
- row
->glyphs
[updated_area
];
22770 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
22772 DRAW_NORMAL_TEXT
, 0);
22774 /* Advance the output cursor. */
22775 output_cursor
.hpos
+= len
;
22776 output_cursor
.x
+= shift_by_width
;
22782 Erase the current text line from the nominal cursor position
22783 (inclusive) to pixel column TO_X (exclusive). The idea is that
22784 everything from TO_X onward is already erased.
22786 TO_X is a pixel position relative to updated_area of
22787 updated_window. TO_X == -1 means clear to the end of this area. */
22790 x_clear_end_of_line (to_x
)
22794 struct window
*w
= updated_window
;
22795 int max_x
, min_y
, max_y
;
22796 int from_x
, from_y
, to_y
;
22798 xassert (updated_window
&& updated_row
);
22799 f
= XFRAME (w
->frame
);
22801 if (updated_row
->full_width_p
)
22802 max_x
= WINDOW_TOTAL_WIDTH (w
);
22804 max_x
= window_box_width (w
, updated_area
);
22805 max_y
= window_text_bottom_y (w
);
22807 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
22808 of window. For TO_X > 0, truncate to end of drawing area. */
22814 to_x
= min (to_x
, max_x
);
22816 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
22818 /* Notice if the cursor will be cleared by this operation. */
22819 if (!updated_row
->full_width_p
)
22820 notice_overwritten_cursor (w
, updated_area
,
22821 output_cursor
.x
, -1,
22823 MATRIX_ROW_BOTTOM_Y (updated_row
));
22825 from_x
= output_cursor
.x
;
22827 /* Translate to frame coordinates. */
22828 if (updated_row
->full_width_p
)
22830 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
22831 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
22835 int area_left
= window_box_left (w
, updated_area
);
22836 from_x
+= area_left
;
22840 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22841 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22842 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22844 /* Prevent inadvertently clearing to end of the X window. */
22845 if (to_x
> from_x
&& to_y
> from_y
)
22848 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22849 to_x
- from_x
, to_y
- from_y
);
22854 #endif /* HAVE_WINDOW_SYSTEM */
22858 /***********************************************************************
22860 ***********************************************************************/
22862 /* Value is the internal representation of the specified cursor type
22863 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22864 of the bar cursor. */
22866 static enum text_cursor_kinds
22867 get_specified_cursor_type (arg
, width
)
22871 enum text_cursor_kinds type
;
22876 if (EQ (arg
, Qbox
))
22877 return FILLED_BOX_CURSOR
;
22879 if (EQ (arg
, Qhollow
))
22880 return HOLLOW_BOX_CURSOR
;
22882 if (EQ (arg
, Qbar
))
22889 && EQ (XCAR (arg
), Qbar
)
22890 && INTEGERP (XCDR (arg
))
22891 && XINT (XCDR (arg
)) >= 0)
22893 *width
= XINT (XCDR (arg
));
22897 if (EQ (arg
, Qhbar
))
22900 return HBAR_CURSOR
;
22904 && EQ (XCAR (arg
), Qhbar
)
22905 && INTEGERP (XCDR (arg
))
22906 && XINT (XCDR (arg
)) >= 0)
22908 *width
= XINT (XCDR (arg
));
22909 return HBAR_CURSOR
;
22912 /* Treat anything unknown as "hollow box cursor".
22913 It was bad to signal an error; people have trouble fixing
22914 .Xdefaults with Emacs, when it has something bad in it. */
22915 type
= HOLLOW_BOX_CURSOR
;
22920 /* Set the default cursor types for specified frame. */
22922 set_frame_cursor_types (f
, arg
)
22929 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22930 FRAME_CURSOR_WIDTH (f
) = width
;
22932 /* By default, set up the blink-off state depending on the on-state. */
22934 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22937 FRAME_BLINK_OFF_CURSOR (f
)
22938 = get_specified_cursor_type (XCDR (tem
), &width
);
22939 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22942 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22946 /* Return the cursor we want to be displayed in window W. Return
22947 width of bar/hbar cursor through WIDTH arg. Return with
22948 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22949 (i.e. if the `system caret' should track this cursor).
22951 In a mini-buffer window, we want the cursor only to appear if we
22952 are reading input from this window. For the selected window, we
22953 want the cursor type given by the frame parameter or buffer local
22954 setting of cursor-type. If explicitly marked off, draw no cursor.
22955 In all other cases, we want a hollow box cursor. */
22957 static enum text_cursor_kinds
22958 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22960 struct glyph
*glyph
;
22962 int *active_cursor
;
22964 struct frame
*f
= XFRAME (w
->frame
);
22965 struct buffer
*b
= XBUFFER (w
->buffer
);
22966 int cursor_type
= DEFAULT_CURSOR
;
22967 Lisp_Object alt_cursor
;
22968 int non_selected
= 0;
22970 *active_cursor
= 1;
22973 if (cursor_in_echo_area
22974 && FRAME_HAS_MINIBUF_P (f
)
22975 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22977 if (w
== XWINDOW (echo_area_window
))
22979 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22981 *width
= FRAME_CURSOR_WIDTH (f
);
22982 return FRAME_DESIRED_CURSOR (f
);
22985 return get_specified_cursor_type (b
->cursor_type
, width
);
22988 *active_cursor
= 0;
22992 /* Detect a nonselected window or nonselected frame. */
22993 else if (w
!= XWINDOW (f
->selected_window
)
22994 #ifdef HAVE_WINDOW_SYSTEM
22995 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22999 *active_cursor
= 0;
23001 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23007 /* Never display a cursor in a window in which cursor-type is nil. */
23008 if (NILP (b
->cursor_type
))
23011 /* Get the normal cursor type for this window. */
23012 if (EQ (b
->cursor_type
, Qt
))
23014 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23015 *width
= FRAME_CURSOR_WIDTH (f
);
23018 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
23020 /* Use cursor-in-non-selected-windows instead
23021 for non-selected window or frame. */
23024 alt_cursor
= b
->cursor_in_non_selected_windows
;
23025 if (!EQ (Qt
, alt_cursor
))
23026 return get_specified_cursor_type (alt_cursor
, width
);
23027 /* t means modify the normal cursor type. */
23028 if (cursor_type
== FILLED_BOX_CURSOR
)
23029 cursor_type
= HOLLOW_BOX_CURSOR
;
23030 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23032 return cursor_type
;
23035 /* Use normal cursor if not blinked off. */
23036 if (!w
->cursor_off_p
)
23038 #ifdef HAVE_WINDOW_SYSTEM
23039 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23041 if (cursor_type
== FILLED_BOX_CURSOR
)
23043 /* Using a block cursor on large images can be very annoying.
23044 So use a hollow cursor for "large" images.
23045 If image is not transparent (no mask), also use hollow cursor. */
23046 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23047 if (img
!= NULL
&& IMAGEP (img
->spec
))
23049 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23050 where N = size of default frame font size.
23051 This should cover most of the "tiny" icons people may use. */
23053 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23054 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23055 cursor_type
= HOLLOW_BOX_CURSOR
;
23058 else if (cursor_type
!= NO_CURSOR
)
23060 /* Display current only supports BOX and HOLLOW cursors for images.
23061 So for now, unconditionally use a HOLLOW cursor when cursor is
23062 not a solid box cursor. */
23063 cursor_type
= HOLLOW_BOX_CURSOR
;
23067 return cursor_type
;
23070 /* Cursor is blinked off, so determine how to "toggle" it. */
23072 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23073 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
23074 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23076 /* Then see if frame has specified a specific blink off cursor type. */
23077 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23079 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23080 return FRAME_BLINK_OFF_CURSOR (f
);
23084 /* Some people liked having a permanently visible blinking cursor,
23085 while others had very strong opinions against it. So it was
23086 decided to remove it. KFS 2003-09-03 */
23088 /* Finally perform built-in cursor blinking:
23089 filled box <-> hollow box
23090 wide [h]bar <-> narrow [h]bar
23091 narrow [h]bar <-> no cursor
23092 other type <-> no cursor */
23094 if (cursor_type
== FILLED_BOX_CURSOR
)
23095 return HOLLOW_BOX_CURSOR
;
23097 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23100 return cursor_type
;
23108 #ifdef HAVE_WINDOW_SYSTEM
23110 /* Notice when the text cursor of window W has been completely
23111 overwritten by a drawing operation that outputs glyphs in AREA
23112 starting at X0 and ending at X1 in the line starting at Y0 and
23113 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23114 the rest of the line after X0 has been written. Y coordinates
23115 are window-relative. */
23118 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
23120 enum glyph_row_area area
;
23121 int x0
, y0
, x1
, y1
;
23123 int cx0
, cx1
, cy0
, cy1
;
23124 struct glyph_row
*row
;
23126 if (!w
->phys_cursor_on_p
)
23128 if (area
!= TEXT_AREA
)
23131 if (w
->phys_cursor
.vpos
< 0
23132 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23133 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23134 !(row
->enabled_p
&& row
->displays_text_p
)))
23137 if (row
->cursor_in_fringe_p
)
23139 row
->cursor_in_fringe_p
= 0;
23140 draw_fringe_bitmap (w
, row
, 0);
23141 w
->phys_cursor_on_p
= 0;
23145 cx0
= w
->phys_cursor
.x
;
23146 cx1
= cx0
+ w
->phys_cursor_width
;
23147 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23150 /* The cursor image will be completely removed from the
23151 screen if the output area intersects the cursor area in
23152 y-direction. When we draw in [y0 y1[, and some part of
23153 the cursor is at y < y0, that part must have been drawn
23154 before. When scrolling, the cursor is erased before
23155 actually scrolling, so we don't come here. When not
23156 scrolling, the rows above the old cursor row must have
23157 changed, and in this case these rows must have written
23158 over the cursor image.
23160 Likewise if part of the cursor is below y1, with the
23161 exception of the cursor being in the first blank row at
23162 the buffer and window end because update_text_area
23163 doesn't draw that row. (Except when it does, but
23164 that's handled in update_text_area.) */
23166 cy0
= w
->phys_cursor
.y
;
23167 cy1
= cy0
+ w
->phys_cursor_height
;
23168 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23171 w
->phys_cursor_on_p
= 0;
23174 #endif /* HAVE_WINDOW_SYSTEM */
23177 /************************************************************************
23179 ************************************************************************/
23181 #ifdef HAVE_WINDOW_SYSTEM
23184 Fix the display of area AREA of overlapping row ROW in window W
23185 with respect to the overlapping part OVERLAPS. */
23188 x_fix_overlapping_area (w
, row
, area
, overlaps
)
23190 struct glyph_row
*row
;
23191 enum glyph_row_area area
;
23199 for (i
= 0; i
< row
->used
[area
];)
23201 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23203 int start
= i
, start_x
= x
;
23207 x
+= row
->glyphs
[area
][i
].pixel_width
;
23210 while (i
< row
->used
[area
]
23211 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23213 draw_glyphs (w
, start_x
, row
, area
,
23215 DRAW_NORMAL_TEXT
, overlaps
);
23219 x
+= row
->glyphs
[area
][i
].pixel_width
;
23229 Draw the cursor glyph of window W in glyph row ROW. See the
23230 comment of draw_glyphs for the meaning of HL. */
23233 draw_phys_cursor_glyph (w
, row
, hl
)
23235 struct glyph_row
*row
;
23236 enum draw_glyphs_face hl
;
23238 /* If cursor hpos is out of bounds, don't draw garbage. This can
23239 happen in mini-buffer windows when switching between echo area
23240 glyphs and mini-buffer. */
23241 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
23243 int on_p
= w
->phys_cursor_on_p
;
23245 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23246 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23248 w
->phys_cursor_on_p
= on_p
;
23250 if (hl
== DRAW_CURSOR
)
23251 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23252 /* When we erase the cursor, and ROW is overlapped by other
23253 rows, make sure that these overlapping parts of other rows
23255 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23257 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23259 if (row
> w
->current_matrix
->rows
23260 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23261 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23262 OVERLAPS_ERASED_CURSOR
);
23264 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23265 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23266 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23267 OVERLAPS_ERASED_CURSOR
);
23274 Erase the image of a cursor of window W from the screen. */
23277 erase_phys_cursor (w
)
23280 struct frame
*f
= XFRAME (w
->frame
);
23281 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23282 int hpos
= w
->phys_cursor
.hpos
;
23283 int vpos
= w
->phys_cursor
.vpos
;
23284 int mouse_face_here_p
= 0;
23285 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23286 struct glyph_row
*cursor_row
;
23287 struct glyph
*cursor_glyph
;
23288 enum draw_glyphs_face hl
;
23290 /* No cursor displayed or row invalidated => nothing to do on the
23292 if (w
->phys_cursor_type
== NO_CURSOR
)
23293 goto mark_cursor_off
;
23295 /* VPOS >= active_glyphs->nrows means that window has been resized.
23296 Don't bother to erase the cursor. */
23297 if (vpos
>= active_glyphs
->nrows
)
23298 goto mark_cursor_off
;
23300 /* If row containing cursor is marked invalid, there is nothing we
23302 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23303 if (!cursor_row
->enabled_p
)
23304 goto mark_cursor_off
;
23306 /* If line spacing is > 0, old cursor may only be partially visible in
23307 window after split-window. So adjust visible height. */
23308 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23309 window_text_bottom_y (w
) - cursor_row
->y
);
23311 /* If row is completely invisible, don't attempt to delete a cursor which
23312 isn't there. This can happen if cursor is at top of a window, and
23313 we switch to a buffer with a header line in that window. */
23314 if (cursor_row
->visible_height
<= 0)
23315 goto mark_cursor_off
;
23317 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23318 if (cursor_row
->cursor_in_fringe_p
)
23320 cursor_row
->cursor_in_fringe_p
= 0;
23321 draw_fringe_bitmap (w
, cursor_row
, 0);
23322 goto mark_cursor_off
;
23325 /* This can happen when the new row is shorter than the old one.
23326 In this case, either draw_glyphs or clear_end_of_line
23327 should have cleared the cursor. Note that we wouldn't be
23328 able to erase the cursor in this case because we don't have a
23329 cursor glyph at hand. */
23330 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
23331 goto mark_cursor_off
;
23333 /* If the cursor is in the mouse face area, redisplay that when
23334 we clear the cursor. */
23335 if (! NILP (dpyinfo
->mouse_face_window
)
23336 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
23337 && (vpos
> dpyinfo
->mouse_face_beg_row
23338 || (vpos
== dpyinfo
->mouse_face_beg_row
23339 && hpos
>= dpyinfo
->mouse_face_beg_col
))
23340 && (vpos
< dpyinfo
->mouse_face_end_row
23341 || (vpos
== dpyinfo
->mouse_face_end_row
23342 && hpos
< dpyinfo
->mouse_face_end_col
))
23343 /* Don't redraw the cursor's spot in mouse face if it is at the
23344 end of a line (on a newline). The cursor appears there, but
23345 mouse highlighting does not. */
23346 && cursor_row
->used
[TEXT_AREA
] > hpos
)
23347 mouse_face_here_p
= 1;
23349 /* Maybe clear the display under the cursor. */
23350 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23353 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23356 cursor_glyph
= get_phys_cursor_glyph (w
);
23357 if (cursor_glyph
== NULL
)
23358 goto mark_cursor_off
;
23360 width
= cursor_glyph
->pixel_width
;
23361 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23362 x
= w
->phys_cursor
.x
;
23364 width
-= left_x
- x
;
23365 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23366 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23367 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23370 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23373 /* Erase the cursor by redrawing the character underneath it. */
23374 if (mouse_face_here_p
)
23375 hl
= DRAW_MOUSE_FACE
;
23377 hl
= DRAW_NORMAL_TEXT
;
23378 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23381 w
->phys_cursor_on_p
= 0;
23382 w
->phys_cursor_type
= NO_CURSOR
;
23387 Display or clear cursor of window W. If ON is zero, clear the
23388 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23389 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23392 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
23394 int on
, hpos
, vpos
, x
, y
;
23396 struct frame
*f
= XFRAME (w
->frame
);
23397 int new_cursor_type
;
23398 int new_cursor_width
;
23400 struct glyph_row
*glyph_row
;
23401 struct glyph
*glyph
;
23403 /* This is pointless on invisible frames, and dangerous on garbaged
23404 windows and frames; in the latter case, the frame or window may
23405 be in the midst of changing its size, and x and y may be off the
23407 if (! FRAME_VISIBLE_P (f
)
23408 || FRAME_GARBAGED_P (f
)
23409 || vpos
>= w
->current_matrix
->nrows
23410 || hpos
>= w
->current_matrix
->matrix_w
)
23413 /* If cursor is off and we want it off, return quickly. */
23414 if (!on
&& !w
->phys_cursor_on_p
)
23417 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23418 /* If cursor row is not enabled, we don't really know where to
23419 display the cursor. */
23420 if (!glyph_row
->enabled_p
)
23422 w
->phys_cursor_on_p
= 0;
23427 if (!glyph_row
->exact_window_width_line_p
23428 || hpos
< glyph_row
->used
[TEXT_AREA
])
23429 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23431 xassert (interrupt_input_blocked
);
23433 /* Set new_cursor_type to the cursor we want to be displayed. */
23434 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23435 &new_cursor_width
, &active_cursor
);
23437 /* If cursor is currently being shown and we don't want it to be or
23438 it is in the wrong place, or the cursor type is not what we want,
23440 if (w
->phys_cursor_on_p
23442 || w
->phys_cursor
.x
!= x
23443 || w
->phys_cursor
.y
!= y
23444 || new_cursor_type
!= w
->phys_cursor_type
23445 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23446 && new_cursor_width
!= w
->phys_cursor_width
)))
23447 erase_phys_cursor (w
);
23449 /* Don't check phys_cursor_on_p here because that flag is only set
23450 to zero in some cases where we know that the cursor has been
23451 completely erased, to avoid the extra work of erasing the cursor
23452 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23453 still not be visible, or it has only been partly erased. */
23456 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23457 w
->phys_cursor_height
= glyph_row
->height
;
23459 /* Set phys_cursor_.* before x_draw_.* is called because some
23460 of them may need the information. */
23461 w
->phys_cursor
.x
= x
;
23462 w
->phys_cursor
.y
= glyph_row
->y
;
23463 w
->phys_cursor
.hpos
= hpos
;
23464 w
->phys_cursor
.vpos
= vpos
;
23467 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23468 new_cursor_type
, new_cursor_width
,
23469 on
, active_cursor
);
23473 /* Switch the display of W's cursor on or off, according to the value
23477 update_window_cursor (w
, on
)
23481 /* Don't update cursor in windows whose frame is in the process
23482 of being deleted. */
23483 if (w
->current_matrix
)
23486 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23487 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23493 /* Call update_window_cursor with parameter ON_P on all leaf windows
23494 in the window tree rooted at W. */
23497 update_cursor_in_window_tree (w
, on_p
)
23503 if (!NILP (w
->hchild
))
23504 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23505 else if (!NILP (w
->vchild
))
23506 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23508 update_window_cursor (w
, on_p
);
23510 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23516 Display the cursor on window W, or clear it, according to ON_P.
23517 Don't change the cursor's position. */
23520 x_update_cursor (f
, on_p
)
23524 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
23529 Clear the cursor of window W to background color, and mark the
23530 cursor as not shown. This is used when the text where the cursor
23531 is about to be rewritten. */
23537 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
23538 update_window_cursor (w
, 0);
23543 Display the active region described by mouse_face_* according to DRAW. */
23546 show_mouse_face (dpyinfo
, draw
)
23547 Display_Info
*dpyinfo
;
23548 enum draw_glyphs_face draw
;
23550 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
23551 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23553 if (/* If window is in the process of being destroyed, don't bother
23555 w
->current_matrix
!= NULL
23556 /* Don't update mouse highlight if hidden */
23557 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
23558 /* Recognize when we are called to operate on rows that don't exist
23559 anymore. This can happen when a window is split. */
23560 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
23562 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
23563 struct glyph_row
*row
, *first
, *last
;
23565 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
23566 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
23568 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
23570 int start_hpos
, end_hpos
, start_x
;
23572 /* For all but the first row, the highlight starts at column 0. */
23575 start_hpos
= dpyinfo
->mouse_face_beg_col
;
23576 start_x
= dpyinfo
->mouse_face_beg_x
;
23585 end_hpos
= dpyinfo
->mouse_face_end_col
;
23588 end_hpos
= row
->used
[TEXT_AREA
];
23589 if (draw
== DRAW_NORMAL_TEXT
)
23590 row
->fill_line_p
= 1; /* Clear to end of line */
23593 if (end_hpos
> start_hpos
)
23595 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
23596 start_hpos
, end_hpos
,
23600 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
23604 /* When we've written over the cursor, arrange for it to
23605 be displayed again. */
23606 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
23609 display_and_set_cursor (w
, 1,
23610 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23611 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23616 /* Change the mouse cursor. */
23617 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
23618 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
23619 else if (draw
== DRAW_MOUSE_FACE
)
23620 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
23622 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
23626 Clear out the mouse-highlighted active region.
23627 Redraw it un-highlighted first. Value is non-zero if mouse
23628 face was actually drawn unhighlighted. */
23631 clear_mouse_face (dpyinfo
)
23632 Display_Info
*dpyinfo
;
23636 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
23638 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
23642 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23643 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23644 dpyinfo
->mouse_face_window
= Qnil
;
23645 dpyinfo
->mouse_face_overlay
= Qnil
;
23651 Non-zero if physical cursor of window W is within mouse face. */
23654 cursor_in_mouse_face_p (w
)
23657 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23658 int in_mouse_face
= 0;
23660 if (WINDOWP (dpyinfo
->mouse_face_window
)
23661 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
23663 int hpos
= w
->phys_cursor
.hpos
;
23664 int vpos
= w
->phys_cursor
.vpos
;
23666 if (vpos
>= dpyinfo
->mouse_face_beg_row
23667 && vpos
<= dpyinfo
->mouse_face_end_row
23668 && (vpos
> dpyinfo
->mouse_face_beg_row
23669 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23670 && (vpos
< dpyinfo
->mouse_face_end_row
23671 || hpos
< dpyinfo
->mouse_face_end_col
23672 || dpyinfo
->mouse_face_past_end
))
23676 return in_mouse_face
;
23682 /* This function sets the mouse_face_* elements of DPYINFO, assuming
23683 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
23684 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
23685 for the overlay or run of text properties specifying the mouse
23686 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
23687 before-string and after-string that must also be highlighted.
23688 DISPLAY_STRING, if non-nil, is a display string that may cover some
23689 or all of the highlighted text. */
23692 mouse_face_from_buffer_pos (Lisp_Object window
,
23693 Display_Info
*dpyinfo
,
23694 EMACS_INT mouse_charpos
,
23695 EMACS_INT start_charpos
,
23696 EMACS_INT end_charpos
,
23697 Lisp_Object before_string
,
23698 Lisp_Object after_string
,
23699 Lisp_Object display_string
)
23701 struct window
*w
= XWINDOW (window
);
23702 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23703 struct glyph_row
*row
;
23704 struct glyph
*glyph
, *end
;
23708 xassert (NILP (display_string
) || STRINGP (display_string
));
23709 xassert (NILP (before_string
) || STRINGP (before_string
));
23710 xassert (NILP (after_string
) || STRINGP (after_string
));
23712 /* Find the first highlighted glyph. */
23713 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
23715 dpyinfo
->mouse_face_beg_col
= 0;
23716 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
23717 dpyinfo
->mouse_face_beg_x
= first
->x
;
23718 dpyinfo
->mouse_face_beg_y
= first
->y
;
23722 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
23724 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23726 /* If the before-string or display-string contains newlines,
23727 row_containing_pos skips to its last row. Move back. */
23728 if (!NILP (before_string
) || !NILP (display_string
))
23730 struct glyph_row
*prev
;
23731 while ((prev
= row
- 1, prev
>= first
)
23732 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
23733 && prev
->used
[TEXT_AREA
] > 0)
23735 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
23736 glyph
= beg
+ prev
->used
[TEXT_AREA
];
23737 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
23739 || !(EQ (glyph
->object
, before_string
)
23740 || EQ (glyph
->object
, display_string
)))
23746 glyph
= row
->glyphs
[TEXT_AREA
];
23747 end
= glyph
+ row
->used
[TEXT_AREA
];
23749 dpyinfo
->mouse_face_beg_y
= row
->y
;
23750 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23752 /* Skip truncation glyphs at the start of the glyph row. */
23753 if (row
->displays_text_p
)
23755 && INTEGERP (glyph
->object
)
23756 && glyph
->charpos
< 0;
23758 x
+= glyph
->pixel_width
;
23760 /* Scan the glyph row, stopping before BEFORE_STRING or
23761 DISPLAY_STRING or START_CHARPOS. */
23763 && !INTEGERP (glyph
->object
)
23764 && !EQ (glyph
->object
, before_string
)
23765 && !EQ (glyph
->object
, display_string
)
23766 && !(BUFFERP (glyph
->object
)
23767 && glyph
->charpos
>= start_charpos
);
23769 x
+= glyph
->pixel_width
;
23771 dpyinfo
->mouse_face_beg_x
= x
;
23772 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23775 /* Find the last highlighted glyph. */
23776 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
23779 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23780 dpyinfo
->mouse_face_past_end
= 1;
23782 else if (!NILP (after_string
))
23784 /* If the after-string has newlines, advance to its last row. */
23785 struct glyph_row
*next
;
23786 struct glyph_row
*last
23787 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23789 for (next
= row
+ 1;
23791 && next
->used
[TEXT_AREA
] > 0
23792 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
23797 glyph
= row
->glyphs
[TEXT_AREA
];
23798 end
= glyph
+ row
->used
[TEXT_AREA
];
23800 dpyinfo
->mouse_face_end_y
= row
->y
;
23801 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23803 /* Skip truncation glyphs at the start of the row. */
23804 if (row
->displays_text_p
)
23806 && INTEGERP (glyph
->object
)
23807 && glyph
->charpos
< 0;
23809 x
+= glyph
->pixel_width
;
23811 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
23814 && !INTEGERP (glyph
->object
)
23815 && !EQ (glyph
->object
, after_string
)
23816 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
23818 x
+= glyph
->pixel_width
;
23820 /* If we found AFTER_STRING, consume it and stop. */
23821 if (EQ (glyph
->object
, after_string
))
23823 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
23824 x
+= glyph
->pixel_width
;
23828 /* If there's no after-string, we must check if we overshot,
23829 which might be the case if we stopped after a string glyph.
23830 That glyph may belong to a before-string or display-string
23831 associated with the end position, which must not be
23833 Lisp_Object prev_object
;
23836 while (glyph
> row
->glyphs
[TEXT_AREA
])
23838 prev_object
= (glyph
- 1)->object
;
23839 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23842 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23843 if (pos
&& pos
< end_charpos
)
23846 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23847 && EQ ((glyph
- 1)->object
, prev_object
);
23849 x
-= (glyph
- 1)->pixel_width
;
23853 dpyinfo
->mouse_face_end_x
= x
;
23854 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23855 dpyinfo
->mouse_face_window
= window
;
23856 dpyinfo
->mouse_face_face_id
23857 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23859 !dpyinfo
->mouse_face_hidden
, -1);
23860 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23864 /* Find the position of the glyph for position POS in OBJECT in
23865 window W's current matrix, and return in *X, *Y the pixel
23866 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23868 RIGHT_P non-zero means return the position of the right edge of the
23869 glyph, RIGHT_P zero means return the left edge position.
23871 If no glyph for POS exists in the matrix, return the position of
23872 the glyph with the next smaller position that is in the matrix, if
23873 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23874 exists in the matrix, return the position of the glyph with the
23875 next larger position in OBJECT.
23877 Value is non-zero if a glyph was found. */
23880 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23883 Lisp_Object object
;
23884 int *hpos
, *vpos
, *x
, *y
;
23887 int yb
= window_text_bottom_y (w
);
23888 struct glyph_row
*r
;
23889 struct glyph
*best_glyph
= NULL
;
23890 struct glyph_row
*best_row
= NULL
;
23893 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23894 r
->enabled_p
&& r
->y
< yb
;
23897 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23898 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23901 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23902 if (EQ (g
->object
, object
))
23904 if (g
->charpos
== pos
)
23911 else if (best_glyph
== NULL
23912 || ((eabs (g
->charpos
- pos
)
23913 < eabs (best_glyph
->charpos
- pos
))
23916 : g
->charpos
> pos
)))
23930 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23934 *x
+= best_glyph
->pixel_width
;
23939 *vpos
= best_row
- w
->current_matrix
->rows
;
23942 return best_glyph
!= NULL
;
23946 /* See if position X, Y is within a hot-spot of an image. */
23949 on_hot_spot_p (hot_spot
, x
, y
)
23950 Lisp_Object hot_spot
;
23953 if (!CONSP (hot_spot
))
23956 if (EQ (XCAR (hot_spot
), Qrect
))
23958 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23959 Lisp_Object rect
= XCDR (hot_spot
);
23963 if (!CONSP (XCAR (rect
)))
23965 if (!CONSP (XCDR (rect
)))
23967 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23969 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23971 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23973 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23977 else if (EQ (XCAR (hot_spot
), Qcircle
))
23979 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23980 Lisp_Object circ
= XCDR (hot_spot
);
23981 Lisp_Object lr
, lx0
, ly0
;
23983 && CONSP (XCAR (circ
))
23984 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23985 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23986 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23988 double r
= XFLOATINT (lr
);
23989 double dx
= XINT (lx0
) - x
;
23990 double dy
= XINT (ly0
) - y
;
23991 return (dx
* dx
+ dy
* dy
<= r
* r
);
23994 else if (EQ (XCAR (hot_spot
), Qpoly
))
23996 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23997 if (VECTORP (XCDR (hot_spot
)))
23999 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
24000 Lisp_Object
*poly
= v
->contents
;
24004 Lisp_Object lx
, ly
;
24007 /* Need an even number of coordinates, and at least 3 edges. */
24008 if (n
< 6 || n
& 1)
24011 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
24012 If count is odd, we are inside polygon. Pixels on edges
24013 may or may not be included depending on actual geometry of the
24015 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
24016 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
24018 x0
= XINT (lx
), y0
= XINT (ly
);
24019 for (i
= 0; i
< n
; i
+= 2)
24021 int x1
= x0
, y1
= y0
;
24022 if ((lx
= poly
[i
], !INTEGERP (lx
))
24023 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
24025 x0
= XINT (lx
), y0
= XINT (ly
);
24027 /* Does this segment cross the X line? */
24035 if (y
> y0
&& y
> y1
)
24037 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
24047 find_hot_spot (map
, x
, y
)
24051 while (CONSP (map
))
24053 if (CONSP (XCAR (map
))
24054 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
24062 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
24064 doc
: /* Lookup in image map MAP coordinates X and Y.
24065 An image map is an alist where each element has the format (AREA ID PLIST).
24066 An AREA is specified as either a rectangle, a circle, or a polygon:
24067 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
24068 pixel coordinates of the upper left and bottom right corners.
24069 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
24070 and the radius of the circle; r may be a float or integer.
24071 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
24072 vector describes one corner in the polygon.
24073 Returns the alist element for the first matching AREA in MAP. */)
24084 return find_hot_spot (map
, XINT (x
), XINT (y
));
24088 /* Display frame CURSOR, optionally using shape defined by POINTER. */
24090 define_frame_cursor1 (f
, cursor
, pointer
)
24093 Lisp_Object pointer
;
24095 /* Do not change cursor shape while dragging mouse. */
24096 if (!NILP (do_mouse_tracking
))
24099 if (!NILP (pointer
))
24101 if (EQ (pointer
, Qarrow
))
24102 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24103 else if (EQ (pointer
, Qhand
))
24104 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
24105 else if (EQ (pointer
, Qtext
))
24106 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24107 else if (EQ (pointer
, intern ("hdrag")))
24108 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24109 #ifdef HAVE_X_WINDOWS
24110 else if (EQ (pointer
, intern ("vdrag")))
24111 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
24113 else if (EQ (pointer
, intern ("hourglass")))
24114 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
24115 else if (EQ (pointer
, Qmodeline
))
24116 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
24118 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24121 if (cursor
!= No_Cursor
)
24122 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
24125 /* Take proper action when mouse has moved to the mode or header line
24126 or marginal area AREA of window W, x-position X and y-position Y.
24127 X is relative to the start of the text display area of W, so the
24128 width of bitmap areas and scroll bars must be subtracted to get a
24129 position relative to the start of the mode line. */
24132 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
24133 Lisp_Object window
;
24135 enum window_part area
;
24137 struct window
*w
= XWINDOW (window
);
24138 struct frame
*f
= XFRAME (w
->frame
);
24139 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24140 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24141 Lisp_Object pointer
= Qnil
;
24142 int charpos
, dx
, dy
, width
, height
;
24143 Lisp_Object string
, object
= Qnil
;
24144 Lisp_Object pos
, help
;
24146 Lisp_Object mouse_face
;
24147 int original_x_pixel
= x
;
24148 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
24149 struct glyph_row
*row
;
24151 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
24156 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
24157 &object
, &dx
, &dy
, &width
, &height
);
24159 row
= (area
== ON_MODE_LINE
24160 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
24161 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
24164 if (row
->mode_line_p
&& row
->enabled_p
)
24166 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
24167 end
= glyph
+ row
->used
[TEXT_AREA
];
24169 for (x0
= original_x_pixel
;
24170 glyph
< end
&& x0
>= glyph
->pixel_width
;
24172 x0
-= glyph
->pixel_width
;
24180 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
24181 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
24182 &object
, &dx
, &dy
, &width
, &height
);
24187 if (IMAGEP (object
))
24189 Lisp_Object image_map
, hotspot
;
24190 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
24192 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
24194 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24196 Lisp_Object area_id
, plist
;
24198 area_id
= XCAR (hotspot
);
24199 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24200 If so, we could look for mouse-enter, mouse-leave
24201 properties in PLIST (and do something...). */
24202 hotspot
= XCDR (hotspot
);
24203 if (CONSP (hotspot
)
24204 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24206 pointer
= Fplist_get (plist
, Qpointer
);
24207 if (NILP (pointer
))
24209 help
= Fplist_get (plist
, Qhelp_echo
);
24212 help_echo_string
= help
;
24213 /* Is this correct? ++kfs */
24214 XSETWINDOW (help_echo_window
, w
);
24215 help_echo_object
= w
->buffer
;
24216 help_echo_pos
= charpos
;
24220 if (NILP (pointer
))
24221 pointer
= Fplist_get (XCDR (object
), QCpointer
);
24224 if (STRINGP (string
))
24226 pos
= make_number (charpos
);
24227 /* If we're on a string with `help-echo' text property, arrange
24228 for the help to be displayed. This is done by setting the
24229 global variable help_echo_string to the help string. */
24232 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
24235 help_echo_string
= help
;
24236 XSETWINDOW (help_echo_window
, w
);
24237 help_echo_object
= string
;
24238 help_echo_pos
= charpos
;
24242 if (NILP (pointer
))
24243 pointer
= Fget_text_property (pos
, Qpointer
, string
);
24245 /* Change the mouse pointer according to what is under X/Y. */
24246 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
24249 map
= Fget_text_property (pos
, Qlocal_map
, string
);
24250 if (!KEYMAPP (map
))
24251 map
= Fget_text_property (pos
, Qkeymap
, string
);
24252 if (!KEYMAPP (map
))
24253 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
24256 /* Change the mouse face according to what is under X/Y. */
24257 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
24258 if (!NILP (mouse_face
)
24259 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24264 struct glyph
* tmp_glyph
;
24268 int total_pixel_width
;
24273 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
24274 Qmouse_face
, string
, Qnil
);
24276 b
= make_number (0);
24278 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
24280 e
= make_number (SCHARS (string
));
24282 /* Calculate the position(glyph position: GPOS) of GLYPH in
24283 displayed string. GPOS is different from CHARPOS.
24285 CHARPOS is the position of glyph in internal string
24286 object. A mode line string format has structures which
24287 is converted to a flatten by emacs lisp interpreter.
24288 The internal string is an element of the structures.
24289 The displayed string is the flatten string. */
24291 if (glyph
> row_start_glyph
)
24293 tmp_glyph
= glyph
- 1;
24294 while (tmp_glyph
>= row_start_glyph
24295 && tmp_glyph
->charpos
>= XINT (b
)
24296 && EQ (tmp_glyph
->object
, glyph
->object
))
24303 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
24304 displayed string holding GLYPH.
24306 GSEQ_LENGTH is different from SCHARS (STRING).
24307 SCHARS (STRING) returns the length of the internal string. */
24308 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
24309 tmp_glyph
->charpos
< XINT (e
);
24310 tmp_glyph
++, gseq_length
++)
24312 if (!EQ (tmp_glyph
->object
, glyph
->object
))
24316 total_pixel_width
= 0;
24317 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
24318 total_pixel_width
+= tmp_glyph
->pixel_width
;
24320 /* Pre calculation of re-rendering position */
24322 hpos
= (area
== ON_MODE_LINE
24323 ? (w
->current_matrix
)->nrows
- 1
24326 /* If the re-rendering position is included in the last
24327 re-rendering area, we should do nothing. */
24328 if ( EQ (window
, dpyinfo
->mouse_face_window
)
24329 && dpyinfo
->mouse_face_beg_col
<= vpos
24330 && vpos
< dpyinfo
->mouse_face_end_col
24331 && dpyinfo
->mouse_face_beg_row
== hpos
)
24334 if (clear_mouse_face (dpyinfo
))
24335 cursor
= No_Cursor
;
24337 dpyinfo
->mouse_face_beg_col
= vpos
;
24338 dpyinfo
->mouse_face_beg_row
= hpos
;
24340 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
24341 dpyinfo
->mouse_face_beg_y
= 0;
24343 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
24344 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
24346 dpyinfo
->mouse_face_end_x
= 0;
24347 dpyinfo
->mouse_face_end_y
= 0;
24349 dpyinfo
->mouse_face_past_end
= 0;
24350 dpyinfo
->mouse_face_window
= window
;
24352 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
24355 glyph
->face_id
, 1);
24356 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24358 if (NILP (pointer
))
24361 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24362 clear_mouse_face (dpyinfo
);
24364 define_frame_cursor1 (f
, cursor
, pointer
);
24369 Take proper action when the mouse has moved to position X, Y on
24370 frame F as regards highlighting characters that have mouse-face
24371 properties. Also de-highlighting chars where the mouse was before.
24372 X and Y can be negative or out of range. */
24375 note_mouse_highlight (f
, x
, y
)
24379 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24380 enum window_part part
;
24381 Lisp_Object window
;
24383 Cursor cursor
= No_Cursor
;
24384 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
24387 /* When a menu is active, don't highlight because this looks odd. */
24388 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
24389 if (popup_activated ())
24393 if (NILP (Vmouse_highlight
)
24394 || !f
->glyphs_initialized_p
24395 || f
->pointer_invisible
)
24398 dpyinfo
->mouse_face_mouse_x
= x
;
24399 dpyinfo
->mouse_face_mouse_y
= y
;
24400 dpyinfo
->mouse_face_mouse_frame
= f
;
24402 if (dpyinfo
->mouse_face_defer
)
24405 if (gc_in_progress
)
24407 dpyinfo
->mouse_face_deferred_gc
= 1;
24411 /* Which window is that in? */
24412 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
24414 /* If we were displaying active text in another window, clear that.
24415 Also clear if we move out of text area in same window. */
24416 if (! EQ (window
, dpyinfo
->mouse_face_window
)
24417 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
24418 && !NILP (dpyinfo
->mouse_face_window
)))
24419 clear_mouse_face (dpyinfo
);
24421 /* Not on a window -> return. */
24422 if (!WINDOWP (window
))
24425 /* Reset help_echo_string. It will get recomputed below. */
24426 help_echo_string
= Qnil
;
24428 /* Convert to window-relative pixel coordinates. */
24429 w
= XWINDOW (window
);
24430 frame_to_window_pixel_xy (w
, &x
, &y
);
24432 /* Handle tool-bar window differently since it doesn't display a
24434 if (EQ (window
, f
->tool_bar_window
))
24436 note_tool_bar_highlight (f
, x
, y
);
24440 /* Mouse is on the mode, header line or margin? */
24441 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
24442 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
24444 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
24448 if (part
== ON_VERTICAL_BORDER
)
24450 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24451 help_echo_string
= build_string ("drag-mouse-1: resize");
24453 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
24454 || part
== ON_SCROLL_BAR
)
24455 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24457 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24459 /* Are we in a window whose display is up to date?
24460 And verify the buffer's text has not changed. */
24461 b
= XBUFFER (w
->buffer
);
24462 if (part
== ON_TEXT
24463 && EQ (w
->window_end_valid
, w
->buffer
)
24464 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
24465 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
24467 int hpos
, vpos
, i
, dx
, dy
, area
;
24469 struct glyph
*glyph
;
24470 Lisp_Object object
;
24471 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
24472 Lisp_Object
*overlay_vec
= NULL
;
24474 struct buffer
*obuf
;
24475 int obegv
, ozv
, same_region
;
24477 /* Find the glyph under X/Y. */
24478 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
24480 /* Look for :pointer property on image. */
24481 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24483 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24484 if (img
!= NULL
&& IMAGEP (img
->spec
))
24486 Lisp_Object image_map
, hotspot
;
24487 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
24489 && (hotspot
= find_hot_spot (image_map
,
24490 glyph
->slice
.x
+ dx
,
24491 glyph
->slice
.y
+ dy
),
24493 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24495 Lisp_Object area_id
, plist
;
24497 area_id
= XCAR (hotspot
);
24498 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24499 If so, we could look for mouse-enter, mouse-leave
24500 properties in PLIST (and do something...). */
24501 hotspot
= XCDR (hotspot
);
24502 if (CONSP (hotspot
)
24503 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24505 pointer
= Fplist_get (plist
, Qpointer
);
24506 if (NILP (pointer
))
24508 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
24509 if (!NILP (help_echo_string
))
24511 help_echo_window
= window
;
24512 help_echo_object
= glyph
->object
;
24513 help_echo_pos
= glyph
->charpos
;
24517 if (NILP (pointer
))
24518 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
24522 /* Clear mouse face if X/Y not over text. */
24524 || area
!= TEXT_AREA
24525 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
24527 if (clear_mouse_face (dpyinfo
))
24528 cursor
= No_Cursor
;
24529 if (NILP (pointer
))
24531 if (area
!= TEXT_AREA
)
24532 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24534 pointer
= Vvoid_text_area_pointer
;
24539 pos
= glyph
->charpos
;
24540 object
= glyph
->object
;
24541 if (!STRINGP (object
) && !BUFFERP (object
))
24544 /* If we get an out-of-range value, return now; avoid an error. */
24545 if (BUFFERP (object
) && pos
> BUF_Z (b
))
24548 /* Make the window's buffer temporarily current for
24549 overlays_at and compute_char_face. */
24550 obuf
= current_buffer
;
24551 current_buffer
= b
;
24557 /* Is this char mouse-active or does it have help-echo? */
24558 position
= make_number (pos
);
24560 if (BUFFERP (object
))
24562 /* Put all the overlays we want in a vector in overlay_vec. */
24563 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
24564 /* Sort overlays into increasing priority order. */
24565 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
24570 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
24571 && vpos
>= dpyinfo
->mouse_face_beg_row
24572 && vpos
<= dpyinfo
->mouse_face_end_row
24573 && (vpos
> dpyinfo
->mouse_face_beg_row
24574 || hpos
>= dpyinfo
->mouse_face_beg_col
)
24575 && (vpos
< dpyinfo
->mouse_face_end_row
24576 || hpos
< dpyinfo
->mouse_face_end_col
24577 || dpyinfo
->mouse_face_past_end
));
24580 cursor
= No_Cursor
;
24582 /* Check mouse-face highlighting. */
24584 /* If there exists an overlay with mouse-face overlapping
24585 the one we are currently highlighting, we have to
24586 check if we enter the overlapping overlay, and then
24587 highlight only that. */
24588 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
24589 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
24591 /* Find the highest priority overlay with a mouse-face. */
24593 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
24595 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
24596 if (!NILP (mouse_face
))
24597 overlay
= overlay_vec
[i
];
24600 /* If we're highlighting the same overlay as before, there's
24601 no need to do that again. */
24602 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
24603 goto check_help_echo
;
24604 dpyinfo
->mouse_face_overlay
= overlay
;
24606 /* Clear the display of the old active region, if any. */
24607 if (clear_mouse_face (dpyinfo
))
24608 cursor
= No_Cursor
;
24610 /* If no overlay applies, get a text property. */
24611 if (NILP (overlay
))
24612 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
24614 /* Next, compute the bounds of the mouse highlighting and
24616 if (!NILP (mouse_face
) && STRINGP (object
))
24618 /* The mouse-highlighting comes from a display string
24619 with a mouse-face. */
24623 b
= Fprevious_single_property_change
24624 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
24625 e
= Fnext_single_property_change
24626 (position
, Qmouse_face
, object
, Qnil
);
24628 b
= make_number (0);
24630 e
= make_number (SCHARS (object
) - 1);
24632 fast_find_string_pos (w
, XINT (b
), object
,
24633 &dpyinfo
->mouse_face_beg_col
,
24634 &dpyinfo
->mouse_face_beg_row
,
24635 &dpyinfo
->mouse_face_beg_x
,
24636 &dpyinfo
->mouse_face_beg_y
, 0);
24637 fast_find_string_pos (w
, XINT (e
), object
,
24638 &dpyinfo
->mouse_face_end_col
,
24639 &dpyinfo
->mouse_face_end_row
,
24640 &dpyinfo
->mouse_face_end_x
,
24641 &dpyinfo
->mouse_face_end_y
, 1);
24642 dpyinfo
->mouse_face_past_end
= 0;
24643 dpyinfo
->mouse_face_window
= window
;
24644 dpyinfo
->mouse_face_face_id
24645 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
24646 glyph
->face_id
, 1);
24647 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24648 cursor
= No_Cursor
;
24652 /* The mouse-highlighting, if any, comes from an overlay
24653 or text property in the buffer. */
24654 Lisp_Object buffer
, display_string
;
24656 if (STRINGP (object
))
24658 /* If we are on a display string with no mouse-face,
24659 check if the text under it has one. */
24660 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
24661 int start
= MATRIX_ROW_START_CHARPOS (r
);
24662 pos
= string_buffer_position (w
, object
, start
);
24665 mouse_face
= get_char_property_and_overlay
24666 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
24667 buffer
= w
->buffer
;
24668 display_string
= object
;
24674 display_string
= Qnil
;
24677 if (!NILP (mouse_face
))
24679 Lisp_Object before
, after
;
24680 Lisp_Object before_string
, after_string
;
24682 if (NILP (overlay
))
24684 /* Handle the text property case. */
24685 before
= Fprevious_single_property_change
24686 (make_number (pos
+ 1), Qmouse_face
, buffer
,
24687 Fmarker_position (w
->start
));
24688 after
= Fnext_single_property_change
24689 (make_number (pos
), Qmouse_face
, buffer
,
24690 make_number (BUF_Z (XBUFFER (buffer
))
24691 - XFASTINT (w
->window_end_pos
)));
24692 before_string
= after_string
= Qnil
;
24696 /* Handle the overlay case. */
24697 before
= Foverlay_start (overlay
);
24698 after
= Foverlay_end (overlay
);
24699 before_string
= Foverlay_get (overlay
, Qbefore_string
);
24700 after_string
= Foverlay_get (overlay
, Qafter_string
);
24702 if (!STRINGP (before_string
)) before_string
= Qnil
;
24703 if (!STRINGP (after_string
)) after_string
= Qnil
;
24706 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
24709 before_string
, after_string
,
24711 cursor
= No_Cursor
;
24718 /* Look for a `help-echo' property. */
24719 if (NILP (help_echo_string
)) {
24720 Lisp_Object help
, overlay
;
24722 /* Check overlays first. */
24723 help
= overlay
= Qnil
;
24724 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
24726 overlay
= overlay_vec
[i
];
24727 help
= Foverlay_get (overlay
, Qhelp_echo
);
24732 help_echo_string
= help
;
24733 help_echo_window
= window
;
24734 help_echo_object
= overlay
;
24735 help_echo_pos
= pos
;
24739 Lisp_Object object
= glyph
->object
;
24740 int charpos
= glyph
->charpos
;
24742 /* Try text properties. */
24743 if (STRINGP (object
)
24745 && charpos
< SCHARS (object
))
24747 help
= Fget_text_property (make_number (charpos
),
24748 Qhelp_echo
, object
);
24751 /* If the string itself doesn't specify a help-echo,
24752 see if the buffer text ``under'' it does. */
24753 struct glyph_row
*r
24754 = MATRIX_ROW (w
->current_matrix
, vpos
);
24755 int start
= MATRIX_ROW_START_CHARPOS (r
);
24756 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
24759 help
= Fget_char_property (make_number (pos
),
24760 Qhelp_echo
, w
->buffer
);
24764 object
= w
->buffer
;
24769 else if (BUFFERP (object
)
24772 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
24777 help_echo_string
= help
;
24778 help_echo_window
= window
;
24779 help_echo_object
= object
;
24780 help_echo_pos
= charpos
;
24785 /* Look for a `pointer' property. */
24786 if (NILP (pointer
))
24788 /* Check overlays first. */
24789 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
24790 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
24792 if (NILP (pointer
))
24794 Lisp_Object object
= glyph
->object
;
24795 int charpos
= glyph
->charpos
;
24797 /* Try text properties. */
24798 if (STRINGP (object
)
24800 && charpos
< SCHARS (object
))
24802 pointer
= Fget_text_property (make_number (charpos
),
24804 if (NILP (pointer
))
24806 /* If the string itself doesn't specify a pointer,
24807 see if the buffer text ``under'' it does. */
24808 struct glyph_row
*r
24809 = MATRIX_ROW (w
->current_matrix
, vpos
);
24810 int start
= MATRIX_ROW_START_CHARPOS (r
);
24811 EMACS_INT pos
= string_buffer_position (w
, object
,
24814 pointer
= Fget_char_property (make_number (pos
),
24815 Qpointer
, w
->buffer
);
24818 else if (BUFFERP (object
)
24821 pointer
= Fget_text_property (make_number (charpos
),
24828 current_buffer
= obuf
;
24833 define_frame_cursor1 (f
, cursor
, pointer
);
24838 Clear any mouse-face on window W. This function is part of the
24839 redisplay interface, and is called from try_window_id and similar
24840 functions to ensure the mouse-highlight is off. */
24843 x_clear_window_mouse_face (w
)
24846 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24847 Lisp_Object window
;
24850 XSETWINDOW (window
, w
);
24851 if (EQ (window
, dpyinfo
->mouse_face_window
))
24852 clear_mouse_face (dpyinfo
);
24858 Just discard the mouse face information for frame F, if any.
24859 This is used when the size of F is changed. */
24862 cancel_mouse_face (f
)
24865 Lisp_Object window
;
24866 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24868 window
= dpyinfo
->mouse_face_window
;
24869 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24871 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24872 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24873 dpyinfo
->mouse_face_window
= Qnil
;
24878 #endif /* HAVE_WINDOW_SYSTEM */
24881 /***********************************************************************
24883 ***********************************************************************/
24885 #ifdef HAVE_WINDOW_SYSTEM
24887 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24888 which intersects rectangle R. R is in window-relative coordinates. */
24891 expose_area (w
, row
, r
, area
)
24893 struct glyph_row
*row
;
24895 enum glyph_row_area area
;
24897 struct glyph
*first
= row
->glyphs
[area
];
24898 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24899 struct glyph
*last
;
24900 int first_x
, start_x
, x
;
24902 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24903 /* If row extends face to end of line write the whole line. */
24904 draw_glyphs (w
, 0, row
, area
,
24905 0, row
->used
[area
],
24906 DRAW_NORMAL_TEXT
, 0);
24909 /* Set START_X to the window-relative start position for drawing glyphs of
24910 AREA. The first glyph of the text area can be partially visible.
24911 The first glyphs of other areas cannot. */
24912 start_x
= window_box_left_offset (w
, area
);
24914 if (area
== TEXT_AREA
)
24917 /* Find the first glyph that must be redrawn. */
24919 && x
+ first
->pixel_width
< r
->x
)
24921 x
+= first
->pixel_width
;
24925 /* Find the last one. */
24929 && x
< r
->x
+ r
->width
)
24931 x
+= last
->pixel_width
;
24937 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24938 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24939 DRAW_NORMAL_TEXT
, 0);
24944 /* Redraw the parts of the glyph row ROW on window W intersecting
24945 rectangle R. R is in window-relative coordinates. Value is
24946 non-zero if mouse-face was overwritten. */
24949 expose_line (w
, row
, r
)
24951 struct glyph_row
*row
;
24954 xassert (row
->enabled_p
);
24956 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24957 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24958 0, row
->used
[TEXT_AREA
],
24959 DRAW_NORMAL_TEXT
, 0);
24962 if (row
->used
[LEFT_MARGIN_AREA
])
24963 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24964 if (row
->used
[TEXT_AREA
])
24965 expose_area (w
, row
, r
, TEXT_AREA
);
24966 if (row
->used
[RIGHT_MARGIN_AREA
])
24967 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24968 draw_row_fringe_bitmaps (w
, row
);
24971 return row
->mouse_face_p
;
24975 /* Redraw those parts of glyphs rows during expose event handling that
24976 overlap other rows. Redrawing of an exposed line writes over parts
24977 of lines overlapping that exposed line; this function fixes that.
24979 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24980 row in W's current matrix that is exposed and overlaps other rows.
24981 LAST_OVERLAPPING_ROW is the last such row. */
24984 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24986 struct glyph_row
*first_overlapping_row
;
24987 struct glyph_row
*last_overlapping_row
;
24990 struct glyph_row
*row
;
24992 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24993 if (row
->overlapping_p
)
24995 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24998 if (row
->used
[LEFT_MARGIN_AREA
])
24999 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
25001 if (row
->used
[TEXT_AREA
])
25002 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
25004 if (row
->used
[RIGHT_MARGIN_AREA
])
25005 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
25011 /* Return non-zero if W's cursor intersects rectangle R. */
25014 phys_cursor_in_rect_p (w
, r
)
25018 XRectangle cr
, result
;
25019 struct glyph
*cursor_glyph
;
25020 struct glyph_row
*row
;
25022 if (w
->phys_cursor
.vpos
>= 0
25023 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
25024 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
25026 && row
->cursor_in_fringe_p
)
25028 /* Cursor is in the fringe. */
25029 cr
.x
= window_box_right_offset (w
,
25030 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
25031 ? RIGHT_MARGIN_AREA
25034 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
25035 cr
.height
= row
->height
;
25036 return x_intersect_rectangles (&cr
, r
, &result
);
25039 cursor_glyph
= get_phys_cursor_glyph (w
);
25042 /* r is relative to W's box, but w->phys_cursor.x is relative
25043 to left edge of W's TEXT area. Adjust it. */
25044 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
25045 cr
.y
= w
->phys_cursor
.y
;
25046 cr
.width
= cursor_glyph
->pixel_width
;
25047 cr
.height
= w
->phys_cursor_height
;
25048 /* ++KFS: W32 version used W32-specific IntersectRect here, but
25049 I assume the effect is the same -- and this is portable. */
25050 return x_intersect_rectangles (&cr
, r
, &result
);
25052 /* If we don't understand the format, pretend we're not in the hot-spot. */
25058 Draw a vertical window border to the right of window W if W doesn't
25059 have vertical scroll bars. */
25062 x_draw_vertical_border (w
)
25065 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25067 /* We could do better, if we knew what type of scroll-bar the adjacent
25068 windows (on either side) have... But we don't :-(
25069 However, I think this works ok. ++KFS 2003-04-25 */
25071 /* Redraw borders between horizontally adjacent windows. Don't
25072 do it for frames with vertical scroll bars because either the
25073 right scroll bar of a window, or the left scroll bar of its
25074 neighbor will suffice as a border. */
25075 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
25078 if (!WINDOW_RIGHTMOST_P (w
)
25079 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
25081 int x0
, x1
, y0
, y1
;
25083 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
25086 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
25089 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
25091 else if (!WINDOW_LEFTMOST_P (w
)
25092 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
25094 int x0
, x1
, y0
, y1
;
25096 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
25099 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
25102 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
25107 /* Redraw the part of window W intersection rectangle FR. Pixel
25108 coordinates in FR are frame-relative. Call this function with
25109 input blocked. Value is non-zero if the exposure overwrites
25113 expose_window (w
, fr
)
25117 struct frame
*f
= XFRAME (w
->frame
);
25119 int mouse_face_overwritten_p
= 0;
25121 /* If window is not yet fully initialized, do nothing. This can
25122 happen when toolkit scroll bars are used and a window is split.
25123 Reconfiguring the scroll bar will generate an expose for a newly
25125 if (w
->current_matrix
== NULL
)
25128 /* When we're currently updating the window, display and current
25129 matrix usually don't agree. Arrange for a thorough display
25131 if (w
== updated_window
)
25133 SET_FRAME_GARBAGED (f
);
25137 /* Frame-relative pixel rectangle of W. */
25138 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
25139 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
25140 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
25141 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
25143 if (x_intersect_rectangles (fr
, &wr
, &r
))
25145 int yb
= window_text_bottom_y (w
);
25146 struct glyph_row
*row
;
25147 int cursor_cleared_p
;
25148 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
25150 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
25151 r
.x
, r
.y
, r
.width
, r
.height
));
25153 /* Convert to window coordinates. */
25154 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
25155 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
25157 /* Turn off the cursor. */
25158 if (!w
->pseudo_window_p
25159 && phys_cursor_in_rect_p (w
, &r
))
25161 x_clear_cursor (w
);
25162 cursor_cleared_p
= 1;
25165 cursor_cleared_p
= 0;
25167 /* Update lines intersecting rectangle R. */
25168 first_overlapping_row
= last_overlapping_row
= NULL
;
25169 for (row
= w
->current_matrix
->rows
;
25174 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
25176 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
25177 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
25178 || (r
.y
>= y0
&& r
.y
< y1
)
25179 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
25181 /* A header line may be overlapping, but there is no need
25182 to fix overlapping areas for them. KFS 2005-02-12 */
25183 if (row
->overlapping_p
&& !row
->mode_line_p
)
25185 if (first_overlapping_row
== NULL
)
25186 first_overlapping_row
= row
;
25187 last_overlapping_row
= row
;
25191 if (expose_line (w
, row
, &r
))
25192 mouse_face_overwritten_p
= 1;
25195 else if (row
->overlapping_p
)
25197 /* We must redraw a row overlapping the exposed area. */
25199 ? y0
+ row
->phys_height
> r
.y
25200 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
25202 if (first_overlapping_row
== NULL
)
25203 first_overlapping_row
= row
;
25204 last_overlapping_row
= row
;
25212 /* Display the mode line if there is one. */
25213 if (WINDOW_WANTS_MODELINE_P (w
)
25214 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
25216 && row
->y
< r
.y
+ r
.height
)
25218 if (expose_line (w
, row
, &r
))
25219 mouse_face_overwritten_p
= 1;
25222 if (!w
->pseudo_window_p
)
25224 /* Fix the display of overlapping rows. */
25225 if (first_overlapping_row
)
25226 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
25229 /* Draw border between windows. */
25230 x_draw_vertical_border (w
);
25232 /* Turn the cursor on again. */
25233 if (cursor_cleared_p
)
25234 update_window_cursor (w
, 1);
25238 return mouse_face_overwritten_p
;
25243 /* Redraw (parts) of all windows in the window tree rooted at W that
25244 intersect R. R contains frame pixel coordinates. Value is
25245 non-zero if the exposure overwrites mouse-face. */
25248 expose_window_tree (w
, r
)
25252 struct frame
*f
= XFRAME (w
->frame
);
25253 int mouse_face_overwritten_p
= 0;
25255 while (w
&& !FRAME_GARBAGED_P (f
))
25257 if (!NILP (w
->hchild
))
25258 mouse_face_overwritten_p
25259 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
25260 else if (!NILP (w
->vchild
))
25261 mouse_face_overwritten_p
25262 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
25264 mouse_face_overwritten_p
|= expose_window (w
, r
);
25266 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
25269 return mouse_face_overwritten_p
;
25274 Redisplay an exposed area of frame F. X and Y are the upper-left
25275 corner of the exposed rectangle. W and H are width and height of
25276 the exposed area. All are pixel values. W or H zero means redraw
25277 the entire frame. */
25280 expose_frame (f
, x
, y
, w
, h
)
25285 int mouse_face_overwritten_p
= 0;
25287 TRACE ((stderr
, "expose_frame "));
25289 /* No need to redraw if frame will be redrawn soon. */
25290 if (FRAME_GARBAGED_P (f
))
25292 TRACE ((stderr
, " garbaged\n"));
25296 /* If basic faces haven't been realized yet, there is no point in
25297 trying to redraw anything. This can happen when we get an expose
25298 event while Emacs is starting, e.g. by moving another window. */
25299 if (FRAME_FACE_CACHE (f
) == NULL
25300 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
25302 TRACE ((stderr
, " no faces\n"));
25306 if (w
== 0 || h
== 0)
25309 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
25310 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
25320 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
25321 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
25323 if (WINDOWP (f
->tool_bar_window
))
25324 mouse_face_overwritten_p
25325 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
25327 #ifdef HAVE_X_WINDOWS
25329 #ifndef USE_X_TOOLKIT
25330 if (WINDOWP (f
->menu_bar_window
))
25331 mouse_face_overwritten_p
25332 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
25333 #endif /* not USE_X_TOOLKIT */
25337 /* Some window managers support a focus-follows-mouse style with
25338 delayed raising of frames. Imagine a partially obscured frame,
25339 and moving the mouse into partially obscured mouse-face on that
25340 frame. The visible part of the mouse-face will be highlighted,
25341 then the WM raises the obscured frame. With at least one WM, KDE
25342 2.1, Emacs is not getting any event for the raising of the frame
25343 (even tried with SubstructureRedirectMask), only Expose events.
25344 These expose events will draw text normally, i.e. not
25345 highlighted. Which means we must redo the highlight here.
25346 Subsume it under ``we love X''. --gerd 2001-08-15 */
25347 /* Included in Windows version because Windows most likely does not
25348 do the right thing if any third party tool offers
25349 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
25350 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
25352 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25353 if (f
== dpyinfo
->mouse_face_mouse_frame
)
25355 int x
= dpyinfo
->mouse_face_mouse_x
;
25356 int y
= dpyinfo
->mouse_face_mouse_y
;
25357 clear_mouse_face (dpyinfo
);
25358 note_mouse_highlight (f
, x
, y
);
25365 Determine the intersection of two rectangles R1 and R2. Return
25366 the intersection in *RESULT. Value is non-zero if RESULT is not
25370 x_intersect_rectangles (r1
, r2
, result
)
25371 XRectangle
*r1
, *r2
, *result
;
25373 XRectangle
*left
, *right
;
25374 XRectangle
*upper
, *lower
;
25375 int intersection_p
= 0;
25377 /* Rearrange so that R1 is the left-most rectangle. */
25379 left
= r1
, right
= r2
;
25381 left
= r2
, right
= r1
;
25383 /* X0 of the intersection is right.x0, if this is inside R1,
25384 otherwise there is no intersection. */
25385 if (right
->x
<= left
->x
+ left
->width
)
25387 result
->x
= right
->x
;
25389 /* The right end of the intersection is the minimum of the
25390 the right ends of left and right. */
25391 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
25394 /* Same game for Y. */
25396 upper
= r1
, lower
= r2
;
25398 upper
= r2
, lower
= r1
;
25400 /* The upper end of the intersection is lower.y0, if this is inside
25401 of upper. Otherwise, there is no intersection. */
25402 if (lower
->y
<= upper
->y
+ upper
->height
)
25404 result
->y
= lower
->y
;
25406 /* The lower end of the intersection is the minimum of the lower
25407 ends of upper and lower. */
25408 result
->height
= (min (lower
->y
+ lower
->height
,
25409 upper
->y
+ upper
->height
)
25411 intersection_p
= 1;
25415 return intersection_p
;
25418 #endif /* HAVE_WINDOW_SYSTEM */
25421 /***********************************************************************
25423 ***********************************************************************/
25428 Vwith_echo_area_save_vector
= Qnil
;
25429 staticpro (&Vwith_echo_area_save_vector
);
25431 Vmessage_stack
= Qnil
;
25432 staticpro (&Vmessage_stack
);
25434 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
25435 staticpro (&Qinhibit_redisplay
);
25437 message_dolog_marker1
= Fmake_marker ();
25438 staticpro (&message_dolog_marker1
);
25439 message_dolog_marker2
= Fmake_marker ();
25440 staticpro (&message_dolog_marker2
);
25441 message_dolog_marker3
= Fmake_marker ();
25442 staticpro (&message_dolog_marker3
);
25445 defsubr (&Sdump_frame_glyph_matrix
);
25446 defsubr (&Sdump_glyph_matrix
);
25447 defsubr (&Sdump_glyph_row
);
25448 defsubr (&Sdump_tool_bar_row
);
25449 defsubr (&Strace_redisplay
);
25450 defsubr (&Strace_to_stderr
);
25452 #ifdef HAVE_WINDOW_SYSTEM
25453 defsubr (&Stool_bar_lines_needed
);
25454 defsubr (&Slookup_image_map
);
25456 defsubr (&Sformat_mode_line
);
25457 defsubr (&Sinvisible_p
);
25459 staticpro (&Qmenu_bar_update_hook
);
25460 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
25462 staticpro (&Qoverriding_terminal_local_map
);
25463 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
25465 staticpro (&Qoverriding_local_map
);
25466 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
25468 staticpro (&Qwindow_scroll_functions
);
25469 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
25471 staticpro (&Qwindow_text_change_functions
);
25472 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
25474 staticpro (&Qredisplay_end_trigger_functions
);
25475 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
25477 staticpro (&Qinhibit_point_motion_hooks
);
25478 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
25480 Qeval
= intern_c_string ("eval");
25481 staticpro (&Qeval
);
25483 QCdata
= intern_c_string (":data");
25484 staticpro (&QCdata
);
25485 Qdisplay
= intern_c_string ("display");
25486 staticpro (&Qdisplay
);
25487 Qspace_width
= intern_c_string ("space-width");
25488 staticpro (&Qspace_width
);
25489 Qraise
= intern_c_string ("raise");
25490 staticpro (&Qraise
);
25491 Qslice
= intern_c_string ("slice");
25492 staticpro (&Qslice
);
25493 Qspace
= intern_c_string ("space");
25494 staticpro (&Qspace
);
25495 Qmargin
= intern_c_string ("margin");
25496 staticpro (&Qmargin
);
25497 Qpointer
= intern_c_string ("pointer");
25498 staticpro (&Qpointer
);
25499 Qleft_margin
= intern_c_string ("left-margin");
25500 staticpro (&Qleft_margin
);
25501 Qright_margin
= intern_c_string ("right-margin");
25502 staticpro (&Qright_margin
);
25503 Qcenter
= intern_c_string ("center");
25504 staticpro (&Qcenter
);
25505 Qline_height
= intern_c_string ("line-height");
25506 staticpro (&Qline_height
);
25507 QCalign_to
= intern_c_string (":align-to");
25508 staticpro (&QCalign_to
);
25509 QCrelative_width
= intern_c_string (":relative-width");
25510 staticpro (&QCrelative_width
);
25511 QCrelative_height
= intern_c_string (":relative-height");
25512 staticpro (&QCrelative_height
);
25513 QCeval
= intern_c_string (":eval");
25514 staticpro (&QCeval
);
25515 QCpropertize
= intern_c_string (":propertize");
25516 staticpro (&QCpropertize
);
25517 QCfile
= intern_c_string (":file");
25518 staticpro (&QCfile
);
25519 Qfontified
= intern_c_string ("fontified");
25520 staticpro (&Qfontified
);
25521 Qfontification_functions
= intern_c_string ("fontification-functions");
25522 staticpro (&Qfontification_functions
);
25523 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
25524 staticpro (&Qtrailing_whitespace
);
25525 Qescape_glyph
= intern_c_string ("escape-glyph");
25526 staticpro (&Qescape_glyph
);
25527 Qnobreak_space
= intern_c_string ("nobreak-space");
25528 staticpro (&Qnobreak_space
);
25529 Qimage
= intern_c_string ("image");
25530 staticpro (&Qimage
);
25531 QCmap
= intern_c_string (":map");
25532 staticpro (&QCmap
);
25533 QCpointer
= intern_c_string (":pointer");
25534 staticpro (&QCpointer
);
25535 Qrect
= intern_c_string ("rect");
25536 staticpro (&Qrect
);
25537 Qcircle
= intern_c_string ("circle");
25538 staticpro (&Qcircle
);
25539 Qpoly
= intern_c_string ("poly");
25540 staticpro (&Qpoly
);
25541 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
25542 staticpro (&Qmessage_truncate_lines
);
25543 Qgrow_only
= intern_c_string ("grow-only");
25544 staticpro (&Qgrow_only
);
25545 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
25546 staticpro (&Qinhibit_menubar_update
);
25547 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
25548 staticpro (&Qinhibit_eval_during_redisplay
);
25549 Qposition
= intern_c_string ("position");
25550 staticpro (&Qposition
);
25551 Qbuffer_position
= intern_c_string ("buffer-position");
25552 staticpro (&Qbuffer_position
);
25553 Qobject
= intern_c_string ("object");
25554 staticpro (&Qobject
);
25555 Qbar
= intern_c_string ("bar");
25557 Qhbar
= intern_c_string ("hbar");
25558 staticpro (&Qhbar
);
25559 Qbox
= intern_c_string ("box");
25561 Qhollow
= intern_c_string ("hollow");
25562 staticpro (&Qhollow
);
25563 Qhand
= intern_c_string ("hand");
25564 staticpro (&Qhand
);
25565 Qarrow
= intern_c_string ("arrow");
25566 staticpro (&Qarrow
);
25567 Qtext
= intern_c_string ("text");
25568 staticpro (&Qtext
);
25569 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
25570 staticpro (&Qrisky_local_variable
);
25571 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
25572 staticpro (&Qinhibit_free_realized_faces
);
25574 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
25575 Fcons (intern_c_string ("void-variable"), Qnil
)),
25577 staticpro (&list_of_error
);
25579 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
25580 staticpro (&Qlast_arrow_position
);
25581 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
25582 staticpro (&Qlast_arrow_string
);
25584 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
25585 staticpro (&Qoverlay_arrow_string
);
25586 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
25587 staticpro (&Qoverlay_arrow_bitmap
);
25589 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
25590 staticpro (&echo_buffer
[0]);
25591 staticpro (&echo_buffer
[1]);
25593 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
25594 staticpro (&echo_area_buffer
[0]);
25595 staticpro (&echo_area_buffer
[1]);
25597 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
25598 staticpro (&Vmessages_buffer_name
);
25600 mode_line_proptrans_alist
= Qnil
;
25601 staticpro (&mode_line_proptrans_alist
);
25602 mode_line_string_list
= Qnil
;
25603 staticpro (&mode_line_string_list
);
25604 mode_line_string_face
= Qnil
;
25605 staticpro (&mode_line_string_face
);
25606 mode_line_string_face_prop
= Qnil
;
25607 staticpro (&mode_line_string_face_prop
);
25608 Vmode_line_unwind_vector
= Qnil
;
25609 staticpro (&Vmode_line_unwind_vector
);
25611 help_echo_string
= Qnil
;
25612 staticpro (&help_echo_string
);
25613 help_echo_object
= Qnil
;
25614 staticpro (&help_echo_object
);
25615 help_echo_window
= Qnil
;
25616 staticpro (&help_echo_window
);
25617 previous_help_echo_string
= Qnil
;
25618 staticpro (&previous_help_echo_string
);
25619 help_echo_pos
= -1;
25621 Qright_to_left
= intern_c_string ("right-to-left");
25622 staticpro (&Qright_to_left
);
25623 Qleft_to_right
= intern_c_string ("left-to-right");
25624 staticpro (&Qleft_to_right
);
25626 #ifdef HAVE_WINDOW_SYSTEM
25627 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
25628 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
25629 For example, if a block cursor is over a tab, it will be drawn as
25630 wide as that tab on the display. */);
25631 x_stretch_cursor_p
= 0;
25634 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
25635 doc
: /* *Non-nil means highlight trailing whitespace.
25636 The face used for trailing whitespace is `trailing-whitespace'. */);
25637 Vshow_trailing_whitespace
= Qnil
;
25639 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
25640 doc
: /* *Control highlighting of nobreak space and soft hyphen.
25641 A value of t means highlight the character itself (for nobreak space,
25642 use face `nobreak-space').
25643 A value of nil means no highlighting.
25644 Other values mean display the escape glyph followed by an ordinary
25645 space or ordinary hyphen. */);
25646 Vnobreak_char_display
= Qt
;
25648 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
25649 doc
: /* *The pointer shape to show in void text areas.
25650 A value of nil means to show the text pointer. Other options are `arrow',
25651 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
25652 Vvoid_text_area_pointer
= Qarrow
;
25654 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
25655 doc
: /* Non-nil means don't actually do any redisplay.
25656 This is used for internal purposes. */);
25657 Vinhibit_redisplay
= Qnil
;
25659 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
25660 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
25661 Vglobal_mode_string
= Qnil
;
25663 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
25664 doc
: /* Marker for where to display an arrow on top of the buffer text.
25665 This must be the beginning of a line in order to work.
25666 See also `overlay-arrow-string'. */);
25667 Voverlay_arrow_position
= Qnil
;
25669 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
25670 doc
: /* String to display as an arrow in non-window frames.
25671 See also `overlay-arrow-position'. */);
25672 Voverlay_arrow_string
= make_pure_c_string ("=>");
25674 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
25675 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
25676 The symbols on this list are examined during redisplay to determine
25677 where to display overlay arrows. */);
25678 Voverlay_arrow_variable_list
25679 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
25681 DEFVAR_INT ("scroll-step", &scroll_step
,
25682 doc
: /* *The number of lines to try scrolling a window by when point moves out.
25683 If that fails to bring point back on frame, point is centered instead.
25684 If this is zero, point is always centered after it moves off frame.
25685 If you want scrolling to always be a line at a time, you should set
25686 `scroll-conservatively' to a large value rather than set this to 1. */);
25688 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
25689 doc
: /* *Scroll up to this many lines, to bring point back on screen.
25690 If point moves off-screen, redisplay will scroll by up to
25691 `scroll-conservatively' lines in order to bring point just barely
25692 onto the screen again. If that cannot be done, then redisplay
25693 recenters point as usual.
25695 A value of zero means always recenter point if it moves off screen. */);
25696 scroll_conservatively
= 0;
25698 DEFVAR_INT ("scroll-margin", &scroll_margin
,
25699 doc
: /* *Number of lines of margin at the top and bottom of a window.
25700 Recenter the window whenever point gets within this many lines
25701 of the top or bottom of the window. */);
25704 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
25705 doc
: /* Pixels per inch value for non-window system displays.
25706 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
25707 Vdisplay_pixels_per_inch
= make_float (72.0);
25710 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
25713 DEFVAR_LISP ("truncate-partial-width-windows",
25714 &Vtruncate_partial_width_windows
,
25715 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
25716 For an integer value, truncate lines in each window narrower than the
25717 full frame width, provided the window width is less than that integer;
25718 otherwise, respect the value of `truncate-lines'.
25720 For any other non-nil value, truncate lines in all windows that do
25721 not span the full frame width.
25723 A value of nil means to respect the value of `truncate-lines'.
25725 If `word-wrap' is enabled, you might want to reduce this. */);
25726 Vtruncate_partial_width_windows
= make_number (50);
25728 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
25729 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
25730 Any other value means to use the appropriate face, `mode-line',
25731 `header-line', or `menu' respectively. */);
25732 mode_line_inverse_video
= 1;
25734 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
25735 doc
: /* *Maximum buffer size for which line number should be displayed.
25736 If the buffer is bigger than this, the line number does not appear
25737 in the mode line. A value of nil means no limit. */);
25738 Vline_number_display_limit
= Qnil
;
25740 DEFVAR_INT ("line-number-display-limit-width",
25741 &line_number_display_limit_width
,
25742 doc
: /* *Maximum line width (in characters) for line number display.
25743 If the average length of the lines near point is bigger than this, then the
25744 line number may be omitted from the mode line. */);
25745 line_number_display_limit_width
= 200;
25747 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
25748 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
25749 highlight_nonselected_windows
= 0;
25751 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
25752 doc
: /* Non-nil if more than one frame is visible on this display.
25753 Minibuffer-only frames don't count, but iconified frames do.
25754 This variable is not guaranteed to be accurate except while processing
25755 `frame-title-format' and `icon-title-format'. */);
25757 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
25758 doc
: /* Template for displaying the title bar of visible frames.
25759 \(Assuming the window manager supports this feature.)
25761 This variable has the same structure as `mode-line-format', except that
25762 the %c and %l constructs are ignored. It is used only on frames for
25763 which no explicit name has been set \(see `modify-frame-parameters'). */);
25765 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
25766 doc
: /* Template for displaying the title bar of an iconified frame.
25767 \(Assuming the window manager supports this feature.)
25768 This variable has the same structure as `mode-line-format' (which see),
25769 and is used only on frames for which no explicit name has been set
25770 \(see `modify-frame-parameters'). */);
25772 = Vframe_title_format
25773 = pure_cons (intern_c_string ("multiple-frames"),
25774 pure_cons (make_pure_c_string ("%b"),
25775 pure_cons (pure_cons (empty_unibyte_string
,
25776 pure_cons (intern_c_string ("invocation-name"),
25777 pure_cons (make_pure_c_string ("@"),
25778 pure_cons (intern_c_string ("system-name"),
25782 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
25783 doc
: /* Maximum number of lines to keep in the message log buffer.
25784 If nil, disable message logging. If t, log messages but don't truncate
25785 the buffer when it becomes large. */);
25786 Vmessage_log_max
= make_number (100);
25788 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
25789 doc
: /* Functions called before redisplay, if window sizes have changed.
25790 The value should be a list of functions that take one argument.
25791 Just before redisplay, for each frame, if any of its windows have changed
25792 size since the last redisplay, or have been split or deleted,
25793 all the functions in the list are called, with the frame as argument. */);
25794 Vwindow_size_change_functions
= Qnil
;
25796 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
25797 doc
: /* List of functions to call before redisplaying a window with scrolling.
25798 Each function is called with two arguments, the window and its new
25799 display-start position. Note that these functions are also called by
25800 `set-window-buffer'. Also note that the value of `window-end' is not
25801 valid when these functions are called. */);
25802 Vwindow_scroll_functions
= Qnil
;
25804 DEFVAR_LISP ("window-text-change-functions",
25805 &Vwindow_text_change_functions
,
25806 doc
: /* Functions to call in redisplay when text in the window might change. */);
25807 Vwindow_text_change_functions
= Qnil
;
25809 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
25810 doc
: /* Functions called when redisplay of a window reaches the end trigger.
25811 Each function is called with two arguments, the window and the end trigger value.
25812 See `set-window-redisplay-end-trigger'. */);
25813 Vredisplay_end_trigger_functions
= Qnil
;
25815 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25816 doc
: /* *Non-nil means autoselect window with mouse pointer.
25817 If nil, do not autoselect windows.
25818 A positive number means delay autoselection by that many seconds: a
25819 window is autoselected only after the mouse has remained in that
25820 window for the duration of the delay.
25821 A negative number has a similar effect, but causes windows to be
25822 autoselected only after the mouse has stopped moving. \(Because of
25823 the way Emacs compares mouse events, you will occasionally wait twice
25824 that time before the window gets selected.\)
25825 Any other value means to autoselect window instantaneously when the
25826 mouse pointer enters it.
25828 Autoselection selects the minibuffer only if it is active, and never
25829 unselects the minibuffer if it is active.
25831 When customizing this variable make sure that the actual value of
25832 `focus-follows-mouse' matches the behavior of your window manager. */);
25833 Vmouse_autoselect_window
= Qnil
;
25835 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25836 doc
: /* *Non-nil means automatically resize tool-bars.
25837 This dynamically changes the tool-bar's height to the minimum height
25838 that is needed to make all tool-bar items visible.
25839 If value is `grow-only', the tool-bar's height is only increased
25840 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25841 Vauto_resize_tool_bars
= Qt
;
25843 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25844 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25845 auto_raise_tool_bar_buttons_p
= 1;
25847 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25848 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25849 make_cursor_line_fully_visible_p
= 1;
25851 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25852 doc
: /* *Border below tool-bar in pixels.
25853 If an integer, use it as the height of the border.
25854 If it is one of `internal-border-width' or `border-width', use the
25855 value of the corresponding frame parameter.
25856 Otherwise, no border is added below the tool-bar. */);
25857 Vtool_bar_border
= Qinternal_border_width
;
25859 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25860 doc
: /* *Margin around tool-bar buttons in pixels.
25861 If an integer, use that for both horizontal and vertical margins.
25862 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25863 HORZ specifying the horizontal margin, and VERT specifying the
25864 vertical margin. */);
25865 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25867 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25868 doc
: /* *Relief thickness of tool-bar buttons. */);
25869 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25871 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25872 doc
: /* List of functions to call to fontify regions of text.
25873 Each function is called with one argument POS. Functions must
25874 fontify a region starting at POS in the current buffer, and give
25875 fontified regions the property `fontified'. */);
25876 Vfontification_functions
= Qnil
;
25877 Fmake_variable_buffer_local (Qfontification_functions
);
25879 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25880 &unibyte_display_via_language_environment
,
25881 doc
: /* *Non-nil means display unibyte text according to language environment.
25882 Specifically, this means that raw bytes in the range 160-255 decimal
25883 are displayed by converting them to the equivalent multibyte characters
25884 according to the current language environment. As a result, they are
25885 displayed according to the current fontset.
25887 Note that this variable affects only how these bytes are displayed,
25888 but does not change the fact they are interpreted as raw bytes. */);
25889 unibyte_display_via_language_environment
= 0;
25891 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25892 doc
: /* *Maximum height for resizing mini-windows.
25893 If a float, it specifies a fraction of the mini-window frame's height.
25894 If an integer, it specifies a number of lines. */);
25895 Vmax_mini_window_height
= make_float (0.25);
25897 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25898 doc
: /* *How to resize mini-windows.
25899 A value of nil means don't automatically resize mini-windows.
25900 A value of t means resize them to fit the text displayed in them.
25901 A value of `grow-only', the default, means let mini-windows grow
25902 only, until their display becomes empty, at which point the windows
25903 go back to their normal size. */);
25904 Vresize_mini_windows
= Qgrow_only
;
25906 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25907 doc
: /* Alist specifying how to blink the cursor off.
25908 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25909 `cursor-type' frame-parameter or variable equals ON-STATE,
25910 comparing using `equal', Emacs uses OFF-STATE to specify
25911 how to blink it off. ON-STATE and OFF-STATE are values for
25912 the `cursor-type' frame parameter.
25914 If a frame's ON-STATE has no entry in this list,
25915 the frame's other specifications determine how to blink the cursor off. */);
25916 Vblink_cursor_alist
= Qnil
;
25918 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25919 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25920 automatic_hscrolling_p
= 1;
25921 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
25922 staticpro (&Qauto_hscroll_mode
);
25924 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25925 doc
: /* *How many columns away from the window edge point is allowed to get
25926 before automatic hscrolling will horizontally scroll the window. */);
25927 hscroll_margin
= 5;
25929 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25930 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25931 When point is less than `hscroll-margin' columns from the window
25932 edge, automatic hscrolling will scroll the window by the amount of columns
25933 determined by this variable. If its value is a positive integer, scroll that
25934 many columns. If it's a positive floating-point number, it specifies the
25935 fraction of the window's width to scroll. If it's nil or zero, point will be
25936 centered horizontally after the scroll. Any other value, including negative
25937 numbers, are treated as if the value were zero.
25939 Automatic hscrolling always moves point outside the scroll margin, so if
25940 point was more than scroll step columns inside the margin, the window will
25941 scroll more than the value given by the scroll step.
25943 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25944 and `scroll-right' overrides this variable's effect. */);
25945 Vhscroll_step
= make_number (0);
25947 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25948 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25949 Bind this around calls to `message' to let it take effect. */);
25950 message_truncate_lines
= 0;
25952 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25953 doc
: /* Normal hook run to update the menu bar definitions.
25954 Redisplay runs this hook before it redisplays the menu bar.
25955 This is used to update submenus such as Buffers,
25956 whose contents depend on various data. */);
25957 Vmenu_bar_update_hook
= Qnil
;
25959 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25960 doc
: /* Frame for which we are updating a menu.
25961 The enable predicate for a menu binding should check this variable. */);
25962 Vmenu_updating_frame
= Qnil
;
25964 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25965 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25966 inhibit_menubar_update
= 0;
25968 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25969 doc
: /* Prefix prepended to all continuation lines at display time.
25970 The value may be a string, an image, or a stretch-glyph; it is
25971 interpreted in the same way as the value of a `display' text property.
25973 This variable is overridden by any `wrap-prefix' text or overlay
25976 To add a prefix to non-continuation lines, use `line-prefix'. */);
25977 Vwrap_prefix
= Qnil
;
25978 staticpro (&Qwrap_prefix
);
25979 Qwrap_prefix
= intern_c_string ("wrap-prefix");
25980 Fmake_variable_buffer_local (Qwrap_prefix
);
25982 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25983 doc
: /* Prefix prepended to all non-continuation lines at display time.
25984 The value may be a string, an image, or a stretch-glyph; it is
25985 interpreted in the same way as the value of a `display' text property.
25987 This variable is overridden by any `line-prefix' text or overlay
25990 To add a prefix to continuation lines, use `wrap-prefix'. */);
25991 Vline_prefix
= Qnil
;
25992 staticpro (&Qline_prefix
);
25993 Qline_prefix
= intern_c_string ("line-prefix");
25994 Fmake_variable_buffer_local (Qline_prefix
);
25996 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25997 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25998 inhibit_eval_during_redisplay
= 0;
26000 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
26001 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
26002 inhibit_free_realized_faces
= 0;
26005 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
26006 doc
: /* Inhibit try_window_id display optimization. */);
26007 inhibit_try_window_id
= 0;
26009 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
26010 doc
: /* Inhibit try_window_reusing display optimization. */);
26011 inhibit_try_window_reusing
= 0;
26013 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
26014 doc
: /* Inhibit try_cursor_movement display optimization. */);
26015 inhibit_try_cursor_movement
= 0;
26016 #endif /* GLYPH_DEBUG */
26018 DEFVAR_INT ("overline-margin", &overline_margin
,
26019 doc
: /* *Space between overline and text, in pixels.
26020 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
26021 margin to the caracter height. */);
26022 overline_margin
= 2;
26024 DEFVAR_INT ("underline-minimum-offset",
26025 &underline_minimum_offset
,
26026 doc
: /* Minimum distance between baseline and underline.
26027 This can improve legibility of underlined text at small font sizes,
26028 particularly when using variable `x-use-underline-position-properties'
26029 with fonts that specify an UNDERLINE_POSITION relatively close to the
26030 baseline. The default value is 1. */);
26031 underline_minimum_offset
= 1;
26033 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
26034 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
26035 display_hourglass_p
= 1;
26037 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
26038 doc
: /* *Seconds to wait before displaying an hourglass pointer.
26039 Value must be an integer or float. */);
26040 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
26042 hourglass_atimer
= NULL
;
26043 hourglass_shown_p
= 0;
26047 /* Initialize this module when Emacs starts. */
26052 Lisp_Object root_window
;
26053 struct window
*mini_w
;
26055 current_header_line_height
= current_mode_line_height
= -1;
26057 CHARPOS (this_line_start_pos
) = 0;
26059 mini_w
= XWINDOW (minibuf_window
);
26060 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
26062 if (!noninteractive
)
26064 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
26067 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
26068 set_window_height (root_window
,
26069 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
26071 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
26072 set_window_height (minibuf_window
, 1, 0);
26074 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
26075 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
26077 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
26078 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
26079 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
26081 /* The default ellipsis glyphs `...'. */
26082 for (i
= 0; i
< 3; ++i
)
26083 default_invis_vector
[i
] = make_number ('.');
26087 /* Allocate the buffer for frame titles.
26088 Also used for `format-mode-line'. */
26090 mode_line_noprop_buf
= (char *) xmalloc (size
);
26091 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
26092 mode_line_noprop_ptr
= mode_line_noprop_buf
;
26093 mode_line_target
= MODE_LINE_DISPLAY
;
26096 help_echo_showing_p
= 0;
26099 /* Since w32 does not support atimers, it defines its own implementation of
26100 the following three functions in w32fns.c. */
26103 /* Platform-independent portion of hourglass implementation. */
26105 /* Return non-zero if houglass timer has been started or hourglass is shown. */
26107 hourglass_started ()
26109 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
26112 /* Cancel a currently active hourglass timer, and start a new one. */
26116 #if defined (HAVE_WINDOW_SYSTEM)
26118 int secs
, usecs
= 0;
26120 cancel_hourglass ();
26122 if (INTEGERP (Vhourglass_delay
)
26123 && XINT (Vhourglass_delay
) > 0)
26124 secs
= XFASTINT (Vhourglass_delay
);
26125 else if (FLOATP (Vhourglass_delay
)
26126 && XFLOAT_DATA (Vhourglass_delay
) > 0)
26129 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
26130 secs
= XFASTINT (tem
);
26131 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
26134 secs
= DEFAULT_HOURGLASS_DELAY
;
26136 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
26137 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
26138 show_hourglass
, NULL
);
26143 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
26146 cancel_hourglass ()
26148 #if defined (HAVE_WINDOW_SYSTEM)
26149 if (hourglass_atimer
)
26151 cancel_atimer (hourglass_atimer
);
26152 hourglass_atimer
= NULL
;
26155 if (hourglass_shown_p
)
26159 #endif /* ! WINDOWSNT */
26161 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
26162 (do not change this comment) */