1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
3 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay do? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking an iterator structure (struct it)
126 Iteration over things to be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator.
128 Calls to get_next_display_element fill the iterator structure with
129 relevant information about the next thing to display. Calls to
130 set_iterator_to_next move the iterator to the next thing.
132 Besides this, an iterator also contains information about the
133 display environment in which glyphs for display elements are to be
134 produced. It has fields for the width and height of the display,
135 the information whether long lines are truncated or continued, a
136 current X and Y position, and lots of other stuff you can better
139 Glyphs in a desired matrix are normally constructed in a loop
140 calling get_next_display_element and then produce_glyphs. The call
141 to produce_glyphs will fill the iterator structure with pixel
142 information about the element being displayed and at the same time
143 produce glyphs for it. If the display element fits on the line
144 being displayed, set_iterator_to_next is called next, otherwise the
145 glyphs produced are discarded.
150 That just couldn't be all, could it? What about terminal types not
151 supporting operations on sub-windows of the screen? To update the
152 display on such a terminal, window-based glyph matrices are not
153 well suited. To be able to reuse part of the display (scrolling
154 lines up and down), we must instead have a view of the whole
155 screen. This is what `frame matrices' are for. They are a trick.
157 Frames on terminals like above have a glyph pool. Windows on such
158 a frame sub-allocate their glyph memory from their frame's glyph
159 pool. The frame itself is given its own glyph matrices. By
160 coincidence---or maybe something else---rows in window glyph
161 matrices are slices of corresponding rows in frame matrices. Thus
162 writing to window matrices implicitly updates a frame matrix which
163 provides us with the view of the whole screen that we originally
164 wanted to have without having to move many bytes around. To be
165 honest, there is a little bit more done, but not much more. If you
166 plan to extend that code, take a look at dispnew.c. The function
167 build_frame_matrix is a good starting point. */
175 #include "keyboard.h"
178 #include "termchar.h"
179 #include "dispextern.h"
181 #include "character.h"
184 #include "commands.h"
188 #include "termhooks.h"
189 #include "intervals.h"
192 #include "region-cache.h"
195 #include "blockinput.h"
197 #ifdef HAVE_X_WINDOWS
212 #ifndef FRAME_X_OUTPUT
213 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
216 #define INFINITY 10000000
218 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
219 || defined(HAVE_NS) || defined (USE_GTK)
220 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
221 extern int pending_menu_activation
;
224 extern int interrupt_input
;
225 extern int command_loop_level
;
227 extern Lisp_Object do_mouse_tracking
;
229 extern int minibuffer_auto_raise
;
230 extern Lisp_Object Vminibuffer_list
;
232 extern Lisp_Object Qface
;
233 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
235 extern Lisp_Object Voverriding_local_map
;
236 extern Lisp_Object Voverriding_local_map_menu_flag
;
237 extern Lisp_Object Qmenu_item
;
238 extern Lisp_Object Qwhen
;
239 extern Lisp_Object Qhelp_echo
;
240 extern Lisp_Object Qbefore_string
, Qafter_string
;
242 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
243 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
244 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
245 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
246 Lisp_Object Qinhibit_point_motion_hooks
;
247 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
248 Lisp_Object Qfontified
;
249 Lisp_Object Qgrow_only
;
250 Lisp_Object Qinhibit_eval_during_redisplay
;
251 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
252 Lisp_Object Qright_to_left
, Qleft_to_right
;
255 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
258 Lisp_Object Qarrow
, Qhand
, Qtext
;
260 Lisp_Object Qrisky_local_variable
;
262 /* Holds the list (error). */
263 Lisp_Object list_of_error
;
265 /* Functions called to fontify regions of text. */
267 Lisp_Object Vfontification_functions
;
268 Lisp_Object Qfontification_functions
;
270 /* Non-nil means automatically select any window when the mouse
271 cursor moves into it. */
272 Lisp_Object Vmouse_autoselect_window
;
274 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
275 Lisp_Object Vline_prefix
, Qline_prefix
;
277 /* Non-zero means draw tool bar buttons raised when the mouse moves
280 int auto_raise_tool_bar_buttons_p
;
282 /* Non-zero means to reposition window if cursor line is only partially visible. */
284 int make_cursor_line_fully_visible_p
;
286 /* Margin below tool bar in pixels. 0 or nil means no margin.
287 If value is `internal-border-width' or `border-width',
288 the corresponding frame parameter is used. */
290 Lisp_Object Vtool_bar_border
;
292 /* Margin around tool bar buttons in pixels. */
294 Lisp_Object Vtool_bar_button_margin
;
296 /* Thickness of shadow to draw around tool bar buttons. */
298 EMACS_INT tool_bar_button_relief
;
300 /* Non-nil means automatically resize tool-bars so that all tool-bar
301 items are visible, and no blank lines remain.
303 If value is `grow-only', only make tool-bar bigger. */
305 Lisp_Object Vauto_resize_tool_bars
;
307 /* Non-zero means draw block and hollow cursor as wide as the glyph
308 under it. For example, if a block cursor is over a tab, it will be
309 drawn as wide as that tab on the display. */
311 int x_stretch_cursor_p
;
313 /* Non-nil means don't actually do any redisplay. */
315 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
317 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
319 int inhibit_eval_during_redisplay
;
321 /* Names of text properties relevant for redisplay. */
323 Lisp_Object Qdisplay
;
324 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
326 /* Symbols used in text property values. */
328 Lisp_Object Vdisplay_pixels_per_inch
;
329 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
330 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
333 Lisp_Object Qmargin
, Qpointer
;
334 Lisp_Object Qline_height
;
335 extern Lisp_Object Qheight
;
336 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
337 extern Lisp_Object Qscroll_bar
;
338 extern Lisp_Object Qcursor
;
340 /* Non-nil means highlight trailing whitespace. */
342 Lisp_Object Vshow_trailing_whitespace
;
344 /* Non-nil means escape non-break space and hyphens. */
346 Lisp_Object Vnobreak_char_display
;
348 #ifdef HAVE_WINDOW_SYSTEM
349 extern Lisp_Object Voverflow_newline_into_fringe
;
351 /* Test if overflow newline into fringe. Called with iterator IT
352 at or past right window margin, and with IT->current_x set. */
354 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
355 (!NILP (Voverflow_newline_into_fringe) \
356 && FRAME_WINDOW_P (it->f) \
357 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
358 && it->current_x == it->last_visible_x \
359 && it->line_wrap != WORD_WRAP)
361 #else /* !HAVE_WINDOW_SYSTEM */
362 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
363 #endif /* HAVE_WINDOW_SYSTEM */
365 /* Test if the display element loaded in IT is a space or tab
366 character. This is used to determine word wrapping. */
368 #define IT_DISPLAYING_WHITESPACE(it) \
369 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
371 /* Non-nil means show the text cursor in void text areas
372 i.e. in blank areas after eol and eob. This used to be
373 the default in 21.3. */
375 Lisp_Object Vvoid_text_area_pointer
;
377 /* Name of the face used to highlight trailing whitespace. */
379 Lisp_Object Qtrailing_whitespace
;
381 /* Name and number of the face used to highlight escape glyphs. */
383 Lisp_Object Qescape_glyph
;
385 /* Name and number of the face used to highlight non-breaking spaces. */
387 Lisp_Object Qnobreak_space
;
389 /* The symbol `image' which is the car of the lists used to represent
394 /* The image map types. */
395 Lisp_Object QCmap
, QCpointer
;
396 Lisp_Object Qrect
, Qcircle
, Qpoly
;
398 /* Non-zero means print newline to stdout before next mini-buffer
401 int noninteractive_need_newline
;
403 /* Non-zero means print newline to message log before next message. */
405 static int message_log_need_newline
;
407 /* Three markers that message_dolog uses.
408 It could allocate them itself, but that causes trouble
409 in handling memory-full errors. */
410 static Lisp_Object message_dolog_marker1
;
411 static Lisp_Object message_dolog_marker2
;
412 static Lisp_Object message_dolog_marker3
;
414 /* The buffer position of the first character appearing entirely or
415 partially on the line of the selected window which contains the
416 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
417 redisplay optimization in redisplay_internal. */
419 static struct text_pos this_line_start_pos
;
421 /* Number of characters past the end of the line above, including the
422 terminating newline. */
424 static struct text_pos this_line_end_pos
;
426 /* The vertical positions and the height of this line. */
428 static int this_line_vpos
;
429 static int this_line_y
;
430 static int this_line_pixel_height
;
432 /* X position at which this display line starts. Usually zero;
433 negative if first character is partially visible. */
435 static int this_line_start_x
;
437 /* Buffer that this_line_.* variables are referring to. */
439 static struct buffer
*this_line_buffer
;
441 /* Nonzero means truncate lines in all windows less wide than the
444 Lisp_Object Vtruncate_partial_width_windows
;
446 /* A flag to control how to display unibyte 8-bit character. */
448 int unibyte_display_via_language_environment
;
450 /* Nonzero means we have more than one non-mini-buffer-only frame.
451 Not guaranteed to be accurate except while parsing
452 frame-title-format. */
456 Lisp_Object Vglobal_mode_string
;
459 /* List of variables (symbols) which hold markers for overlay arrows.
460 The symbols on this list are examined during redisplay to determine
461 where to display overlay arrows. */
463 Lisp_Object Voverlay_arrow_variable_list
;
465 /* Marker for where to display an arrow on top of the buffer text. */
467 Lisp_Object Voverlay_arrow_position
;
469 /* String to display for the arrow. Only used on terminal frames. */
471 Lisp_Object Voverlay_arrow_string
;
473 /* Values of those variables at last redisplay are stored as
474 properties on `overlay-arrow-position' symbol. However, if
475 Voverlay_arrow_position is a marker, last-arrow-position is its
476 numerical position. */
478 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
480 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
481 properties on a symbol in overlay-arrow-variable-list. */
483 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
485 /* Like mode-line-format, but for the title bar on a visible frame. */
487 Lisp_Object Vframe_title_format
;
489 /* Like mode-line-format, but for the title bar on an iconified frame. */
491 Lisp_Object Vicon_title_format
;
493 /* List of functions to call when a window's size changes. These
494 functions get one arg, a frame on which one or more windows' sizes
497 static Lisp_Object Vwindow_size_change_functions
;
499 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
501 /* Nonzero if an overlay arrow has been displayed in this window. */
503 static int overlay_arrow_seen
;
505 /* Nonzero means highlight the region even in nonselected windows. */
507 int highlight_nonselected_windows
;
509 /* If cursor motion alone moves point off frame, try scrolling this
510 many lines up or down if that will bring it back. */
512 static EMACS_INT scroll_step
;
514 /* Nonzero means scroll just far enough to bring point back on the
515 screen, when appropriate. */
517 static EMACS_INT scroll_conservatively
;
519 /* Recenter the window whenever point gets within this many lines of
520 the top or bottom of the window. This value is translated into a
521 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
522 that there is really a fixed pixel height scroll margin. */
524 EMACS_INT scroll_margin
;
526 /* Number of windows showing the buffer of the selected window (or
527 another buffer with the same base buffer). keyboard.c refers to
532 /* Vector containing glyphs for an ellipsis `...'. */
534 static Lisp_Object default_invis_vector
[3];
536 /* Zero means display the mode-line/header-line/menu-bar in the default face
537 (this slightly odd definition is for compatibility with previous versions
538 of emacs), non-zero means display them using their respective faces.
540 This variable is deprecated. */
542 int mode_line_inverse_video
;
544 /* Prompt to display in front of the mini-buffer contents. */
546 Lisp_Object minibuf_prompt
;
548 /* Width of current mini-buffer prompt. Only set after display_line
549 of the line that contains the prompt. */
551 int minibuf_prompt_width
;
553 /* This is the window where the echo area message was displayed. It
554 is always a mini-buffer window, but it may not be the same window
555 currently active as a mini-buffer. */
557 Lisp_Object echo_area_window
;
559 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
560 pushes the current message and the value of
561 message_enable_multibyte on the stack, the function restore_message
562 pops the stack and displays MESSAGE again. */
564 Lisp_Object Vmessage_stack
;
566 /* Nonzero means multibyte characters were enabled when the echo area
567 message was specified. */
569 int message_enable_multibyte
;
571 /* Nonzero if we should redraw the mode lines on the next redisplay. */
573 int update_mode_lines
;
575 /* Nonzero if window sizes or contents have changed since last
576 redisplay that finished. */
578 int windows_or_buffers_changed
;
580 /* Nonzero means a frame's cursor type has been changed. */
582 int cursor_type_changed
;
584 /* Nonzero after display_mode_line if %l was used and it displayed a
587 int line_number_displayed
;
589 /* Maximum buffer size for which to display line numbers. */
591 Lisp_Object Vline_number_display_limit
;
593 /* Line width to consider when repositioning for line number display. */
595 static EMACS_INT line_number_display_limit_width
;
597 /* Number of lines to keep in the message log buffer. t means
598 infinite. nil means don't log at all. */
600 Lisp_Object Vmessage_log_max
;
602 /* The name of the *Messages* buffer, a string. */
604 static Lisp_Object Vmessages_buffer_name
;
606 /* Current, index 0, and last displayed echo area message. Either
607 buffers from echo_buffers, or nil to indicate no message. */
609 Lisp_Object echo_area_buffer
[2];
611 /* The buffers referenced from echo_area_buffer. */
613 static Lisp_Object echo_buffer
[2];
615 /* A vector saved used in with_area_buffer to reduce consing. */
617 static Lisp_Object Vwith_echo_area_save_vector
;
619 /* Non-zero means display_echo_area should display the last echo area
620 message again. Set by redisplay_preserve_echo_area. */
622 static int display_last_displayed_message_p
;
624 /* Nonzero if echo area is being used by print; zero if being used by
627 int message_buf_print
;
629 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
631 Lisp_Object Qinhibit_menubar_update
;
632 int inhibit_menubar_update
;
634 /* When evaluating expressions from menu bar items (enable conditions,
635 for instance), this is the frame they are being processed for. */
637 Lisp_Object Vmenu_updating_frame
;
639 /* Maximum height for resizing mini-windows. Either a float
640 specifying a fraction of the available height, or an integer
641 specifying a number of lines. */
643 Lisp_Object Vmax_mini_window_height
;
645 /* Non-zero means messages should be displayed with truncated
646 lines instead of being continued. */
648 int message_truncate_lines
;
649 Lisp_Object Qmessage_truncate_lines
;
651 /* Set to 1 in clear_message to make redisplay_internal aware
652 of an emptied echo area. */
654 static int message_cleared_p
;
656 /* How to blink the default frame cursor off. */
657 Lisp_Object Vblink_cursor_alist
;
659 /* A scratch glyph row with contents used for generating truncation
660 glyphs. Also used in direct_output_for_insert. */
662 #define MAX_SCRATCH_GLYPHS 100
663 struct glyph_row scratch_glyph_row
;
664 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
666 /* Ascent and height of the last line processed by move_it_to. */
668 static int last_max_ascent
, last_height
;
670 /* Non-zero if there's a help-echo in the echo area. */
672 int help_echo_showing_p
;
674 /* If >= 0, computed, exact values of mode-line and header-line height
675 to use in the macros CURRENT_MODE_LINE_HEIGHT and
676 CURRENT_HEADER_LINE_HEIGHT. */
678 int current_mode_line_height
, current_header_line_height
;
680 /* The maximum distance to look ahead for text properties. Values
681 that are too small let us call compute_char_face and similar
682 functions too often which is expensive. Values that are too large
683 let us call compute_char_face and alike too often because we
684 might not be interested in text properties that far away. */
686 #define TEXT_PROP_DISTANCE_LIMIT 100
690 /* Variables to turn off display optimizations from Lisp. */
692 int inhibit_try_window_id
, inhibit_try_window_reusing
;
693 int inhibit_try_cursor_movement
;
695 /* Non-zero means print traces of redisplay if compiled with
698 int trace_redisplay_p
;
700 #endif /* GLYPH_DEBUG */
702 #ifdef DEBUG_TRACE_MOVE
703 /* Non-zero means trace with TRACE_MOVE to stderr. */
706 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
708 #define TRACE_MOVE(x) (void) 0
711 /* Non-zero means automatically scroll windows horizontally to make
714 int automatic_hscrolling_p
;
715 Lisp_Object Qauto_hscroll_mode
;
717 /* How close to the margin can point get before the window is scrolled
719 EMACS_INT hscroll_margin
;
721 /* How much to scroll horizontally when point is inside the above margin. */
722 Lisp_Object Vhscroll_step
;
724 /* The variable `resize-mini-windows'. If nil, don't resize
725 mini-windows. If t, always resize them to fit the text they
726 display. If `grow-only', let mini-windows grow only until they
729 Lisp_Object Vresize_mini_windows
;
731 /* Buffer being redisplayed -- for redisplay_window_error. */
733 struct buffer
*displayed_buffer
;
735 /* Space between overline and text. */
737 EMACS_INT overline_margin
;
739 /* Require underline to be at least this many screen pixels below baseline
740 This to avoid underline "merging" with the base of letters at small
741 font sizes, particularly when x_use_underline_position_properties is on. */
743 EMACS_INT underline_minimum_offset
;
745 /* Value returned from text property handlers (see below). */
750 HANDLED_RECOMPUTE_PROPS
,
751 HANDLED_OVERLAY_STRING_CONSUMED
,
755 /* A description of text properties that redisplay is interested
760 /* The name of the property. */
763 /* A unique index for the property. */
766 /* A handler function called to set up iterator IT from the property
767 at IT's current position. Value is used to steer handle_stop. */
768 enum prop_handled (*handler
) P_ ((struct it
*it
));
771 static enum prop_handled handle_face_prop
P_ ((struct it
*));
772 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
773 static enum prop_handled handle_display_prop
P_ ((struct it
*));
774 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
775 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
776 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
778 /* Properties handled by iterators. */
780 static struct props it_props
[] =
782 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
783 /* Handle `face' before `display' because some sub-properties of
784 `display' need to know the face. */
785 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
786 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
787 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
788 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
792 /* Value is the position described by X. If X is a marker, value is
793 the marker_position of X. Otherwise, value is X. */
795 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
797 /* Enumeration returned by some move_it_.* functions internally. */
801 /* Not used. Undefined value. */
804 /* Move ended at the requested buffer position or ZV. */
805 MOVE_POS_MATCH_OR_ZV
,
807 /* Move ended at the requested X pixel position. */
810 /* Move within a line ended at the end of a line that must be
814 /* Move within a line ended at the end of a line that would
815 be displayed truncated. */
818 /* Move within a line ended at a line end. */
822 /* This counter is used to clear the face cache every once in a while
823 in redisplay_internal. It is incremented for each redisplay.
824 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
827 #define CLEAR_FACE_CACHE_COUNT 500
828 static int clear_face_cache_count
;
830 /* Similarly for the image cache. */
832 #ifdef HAVE_WINDOW_SYSTEM
833 #define CLEAR_IMAGE_CACHE_COUNT 101
834 static int clear_image_cache_count
;
837 /* Non-zero while redisplay_internal is in progress. */
841 /* Non-zero means don't free realized faces. Bound while freeing
842 realized faces is dangerous because glyph matrices might still
845 int inhibit_free_realized_faces
;
846 Lisp_Object Qinhibit_free_realized_faces
;
848 /* If a string, XTread_socket generates an event to display that string.
849 (The display is done in read_char.) */
851 Lisp_Object help_echo_string
;
852 Lisp_Object help_echo_window
;
853 Lisp_Object help_echo_object
;
856 /* Temporary variable for XTread_socket. */
858 Lisp_Object previous_help_echo_string
;
860 /* Null glyph slice */
862 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
864 /* Platform-independent portion of hourglass implementation. */
866 /* Non-zero means we're allowed to display a hourglass pointer. */
867 int display_hourglass_p
;
869 /* Non-zero means an hourglass cursor is currently shown. */
870 int hourglass_shown_p
;
872 /* If non-null, an asynchronous timer that, when it expires, displays
873 an hourglass cursor on all frames. */
874 struct atimer
*hourglass_atimer
;
876 /* Number of seconds to wait before displaying an hourglass cursor. */
877 Lisp_Object Vhourglass_delay
;
879 /* Default number of seconds to wait before displaying an hourglass
881 #define DEFAULT_HOURGLASS_DELAY 1
884 /* Function prototypes. */
886 static void setup_for_ellipsis
P_ ((struct it
*, int));
887 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
888 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
889 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
890 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
891 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
892 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
894 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
896 static void handle_line_prefix
P_ ((struct it
*));
898 static void pint2str
P_ ((char *, int, int));
899 static void pint2hrstr
P_ ((char *, int, int));
900 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
902 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
903 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
904 static void store_mode_line_noprop_char
P_ ((char));
905 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
906 static void x_consider_frame_title
P_ ((Lisp_Object
));
907 static void handle_stop
P_ ((struct it
*));
908 static void handle_stop_backwards
P_ ((struct it
*, EMACS_INT
));
909 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
910 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
911 static void ensure_echo_area_buffers
P_ ((void));
912 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
913 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
914 static int with_echo_area_buffer
P_ ((struct window
*, int,
915 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
916 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static void clear_garbaged_frames
P_ ((void));
918 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
919 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
920 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
921 static int display_echo_area
P_ ((struct window
*));
922 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
923 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
924 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
925 static int string_char_and_length
P_ ((const unsigned char *, int *));
926 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
928 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
929 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
930 static void insert_left_trunc_glyphs
P_ ((struct it
*));
931 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
933 static void extend_face_to_end_of_line
P_ ((struct it
*));
934 static int append_space_for_newline
P_ ((struct it
*, int));
935 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
936 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
937 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
938 static int trailing_whitespace_p
P_ ((int));
939 static int message_log_check_duplicate
P_ ((int, int, int, int));
940 static void push_it
P_ ((struct it
*));
941 static void pop_it
P_ ((struct it
*));
942 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
943 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
944 static void redisplay_internal
P_ ((int));
945 static int echo_area_display
P_ ((int));
946 static void redisplay_windows
P_ ((Lisp_Object
));
947 static void redisplay_window
P_ ((Lisp_Object
, int));
948 static Lisp_Object
redisplay_window_error ();
949 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
950 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
951 static int update_menu_bar
P_ ((struct frame
*, int, int));
952 static int try_window_reusing_current_matrix
P_ ((struct window
*));
953 static int try_window_id
P_ ((struct window
*));
954 static int display_line
P_ ((struct it
*));
955 static int display_mode_lines
P_ ((struct window
*));
956 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
957 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
958 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
959 static char *decode_mode_spec
P_ ((struct window
*, int, int, int,
961 static void display_menu_bar
P_ ((struct window
*));
962 static int display_count_lines
P_ ((int, int, int, int, int *));
963 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
964 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
965 static void compute_line_metrics
P_ ((struct it
*));
966 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
967 static int get_overlay_strings
P_ ((struct it
*, int));
968 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
969 static void next_overlay_string
P_ ((struct it
*));
970 static void reseat
P_ ((struct it
*, struct text_pos
, int));
971 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
972 static void back_to_previous_visible_line_start
P_ ((struct it
*));
973 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
974 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
975 static int next_element_from_ellipsis
P_ ((struct it
*));
976 static int next_element_from_display_vector
P_ ((struct it
*));
977 static int next_element_from_string
P_ ((struct it
*));
978 static int next_element_from_c_string
P_ ((struct it
*));
979 static int next_element_from_buffer
P_ ((struct it
*));
980 static int next_element_from_composition
P_ ((struct it
*));
981 static int next_element_from_image
P_ ((struct it
*));
982 static int next_element_from_stretch
P_ ((struct it
*));
983 static void load_overlay_strings
P_ ((struct it
*, int));
984 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
985 struct display_pos
*));
986 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
987 Lisp_Object
, int, int, int, int));
988 static enum move_it_result
989 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
990 enum move_operation_enum
);
991 void move_it_vertically_backward
P_ ((struct it
*, int));
992 static void init_to_row_start
P_ ((struct it
*, struct window
*,
993 struct glyph_row
*));
994 static int init_to_row_end
P_ ((struct it
*, struct window
*,
995 struct glyph_row
*));
996 static void back_to_previous_line_start
P_ ((struct it
*));
997 static int forward_to_next_line_start
P_ ((struct it
*, int *));
998 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
1000 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
1001 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
1002 static int number_of_chars
P_ ((unsigned char *, int));
1003 static void compute_stop_pos
P_ ((struct it
*));
1004 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1006 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1007 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1008 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1009 Lisp_Object
, Lisp_Object
,
1010 struct text_pos
*, int));
1011 static int underlying_face_id
P_ ((struct it
*));
1012 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1015 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1016 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1018 #ifdef HAVE_WINDOW_SYSTEM
1020 static void update_tool_bar
P_ ((struct frame
*, int));
1021 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1022 static int redisplay_tool_bar
P_ ((struct frame
*));
1023 static void display_tool_bar_line
P_ ((struct it
*, int));
1024 static void notice_overwritten_cursor
P_ ((struct window
*,
1025 enum glyph_row_area
,
1026 int, int, int, int));
1030 #endif /* HAVE_WINDOW_SYSTEM */
1033 /***********************************************************************
1034 Window display dimensions
1035 ***********************************************************************/
1037 /* Return the bottom boundary y-position for text lines in window W.
1038 This is the first y position at which a line cannot start.
1039 It is relative to the top of the window.
1041 This is the height of W minus the height of a mode line, if any. */
1044 window_text_bottom_y (w
)
1047 int height
= WINDOW_TOTAL_HEIGHT (w
);
1049 if (WINDOW_WANTS_MODELINE_P (w
))
1050 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1054 /* Return the pixel width of display area AREA of window W. AREA < 0
1055 means return the total width of W, not including fringes to
1056 the left and right of the window. */
1059 window_box_width (w
, area
)
1063 int cols
= XFASTINT (w
->total_cols
);
1066 if (!w
->pseudo_window_p
)
1068 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1070 if (area
== TEXT_AREA
)
1072 if (INTEGERP (w
->left_margin_cols
))
1073 cols
-= XFASTINT (w
->left_margin_cols
);
1074 if (INTEGERP (w
->right_margin_cols
))
1075 cols
-= XFASTINT (w
->right_margin_cols
);
1076 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1078 else if (area
== LEFT_MARGIN_AREA
)
1080 cols
= (INTEGERP (w
->left_margin_cols
)
1081 ? XFASTINT (w
->left_margin_cols
) : 0);
1084 else if (area
== RIGHT_MARGIN_AREA
)
1086 cols
= (INTEGERP (w
->right_margin_cols
)
1087 ? XFASTINT (w
->right_margin_cols
) : 0);
1092 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1096 /* Return the pixel height of the display area of window W, not
1097 including mode lines of W, if any. */
1100 window_box_height (w
)
1103 struct frame
*f
= XFRAME (w
->frame
);
1104 int height
= WINDOW_TOTAL_HEIGHT (w
);
1106 xassert (height
>= 0);
1108 /* Note: the code below that determines the mode-line/header-line
1109 height is essentially the same as that contained in the macro
1110 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1111 the appropriate glyph row has its `mode_line_p' flag set,
1112 and if it doesn't, uses estimate_mode_line_height instead. */
1114 if (WINDOW_WANTS_MODELINE_P (w
))
1116 struct glyph_row
*ml_row
1117 = (w
->current_matrix
&& w
->current_matrix
->rows
1118 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1120 if (ml_row
&& ml_row
->mode_line_p
)
1121 height
-= ml_row
->height
;
1123 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1126 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1128 struct glyph_row
*hl_row
1129 = (w
->current_matrix
&& w
->current_matrix
->rows
1130 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1132 if (hl_row
&& hl_row
->mode_line_p
)
1133 height
-= hl_row
->height
;
1135 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1138 /* With a very small font and a mode-line that's taller than
1139 default, we might end up with a negative height. */
1140 return max (0, height
);
1143 /* Return the window-relative coordinate of the left edge of display
1144 area AREA of window W. AREA < 0 means return the left edge of the
1145 whole window, to the right of the left fringe of W. */
1148 window_box_left_offset (w
, area
)
1154 if (w
->pseudo_window_p
)
1157 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1159 if (area
== TEXT_AREA
)
1160 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1161 + window_box_width (w
, LEFT_MARGIN_AREA
));
1162 else if (area
== RIGHT_MARGIN_AREA
)
1163 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1164 + window_box_width (w
, LEFT_MARGIN_AREA
)
1165 + window_box_width (w
, TEXT_AREA
)
1166 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1168 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1169 else if (area
== LEFT_MARGIN_AREA
1170 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1171 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1177 /* Return the window-relative coordinate of the right edge of display
1178 area AREA of window W. AREA < 0 means return the left edge of the
1179 whole window, to the left of the right fringe of W. */
1182 window_box_right_offset (w
, area
)
1186 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1189 /* Return the frame-relative coordinate of the left edge of display
1190 area AREA of window W. AREA < 0 means return the left edge of the
1191 whole window, to the right of the left fringe of W. */
1194 window_box_left (w
, area
)
1198 struct frame
*f
= XFRAME (w
->frame
);
1201 if (w
->pseudo_window_p
)
1202 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1204 x
= (WINDOW_LEFT_EDGE_X (w
)
1205 + window_box_left_offset (w
, area
));
1211 /* Return the frame-relative coordinate of the right edge of display
1212 area AREA of window W. AREA < 0 means return the left edge of the
1213 whole window, to the left of the right fringe of W. */
1216 window_box_right (w
, area
)
1220 return window_box_left (w
, area
) + window_box_width (w
, area
);
1223 /* Get the bounding box of the display area AREA of window W, without
1224 mode lines, in frame-relative coordinates. AREA < 0 means the
1225 whole window, not including the left and right fringes of
1226 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1227 coordinates of the upper-left corner of the box. Return in
1228 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1231 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1234 int *box_x
, *box_y
, *box_width
, *box_height
;
1237 *box_width
= window_box_width (w
, area
);
1239 *box_height
= window_box_height (w
);
1241 *box_x
= window_box_left (w
, area
);
1244 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1245 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1246 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1251 /* Get the bounding box of the display area AREA of window W, without
1252 mode lines. AREA < 0 means the whole window, not including the
1253 left and right fringe of the window. Return in *TOP_LEFT_X
1254 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1255 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1256 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1260 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1261 bottom_right_x
, bottom_right_y
)
1264 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1266 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1268 *bottom_right_x
+= *top_left_x
;
1269 *bottom_right_y
+= *top_left_y
;
1274 /***********************************************************************
1276 ***********************************************************************/
1278 /* Return the bottom y-position of the line the iterator IT is in.
1279 This can modify IT's settings. */
1285 int line_height
= it
->max_ascent
+ it
->max_descent
;
1286 int line_top_y
= it
->current_y
;
1288 if (line_height
== 0)
1291 line_height
= last_height
;
1292 else if (IT_CHARPOS (*it
) < ZV
)
1294 move_it_by_lines (it
, 1, 1);
1295 line_height
= (it
->max_ascent
|| it
->max_descent
1296 ? it
->max_ascent
+ it
->max_descent
1301 struct glyph_row
*row
= it
->glyph_row
;
1303 /* Use the default character height. */
1304 it
->glyph_row
= NULL
;
1305 it
->what
= IT_CHARACTER
;
1308 PRODUCE_GLYPHS (it
);
1309 line_height
= it
->ascent
+ it
->descent
;
1310 it
->glyph_row
= row
;
1314 return line_top_y
+ line_height
;
1318 /* Return 1 if position CHARPOS is visible in window W.
1319 CHARPOS < 0 means return info about WINDOW_END position.
1320 If visible, set *X and *Y to pixel coordinates of top left corner.
1321 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1322 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1325 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1327 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1330 struct text_pos top
;
1332 struct buffer
*old_buffer
= NULL
;
1334 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1337 if (XBUFFER (w
->buffer
) != current_buffer
)
1339 old_buffer
= current_buffer
;
1340 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1343 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1345 /* Compute exact mode line heights. */
1346 if (WINDOW_WANTS_MODELINE_P (w
))
1347 current_mode_line_height
1348 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1349 current_buffer
->mode_line_format
);
1351 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1352 current_header_line_height
1353 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1354 current_buffer
->header_line_format
);
1356 start_display (&it
, w
, top
);
1357 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1358 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1360 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1362 /* We have reached CHARPOS, or passed it. How the call to
1363 move_it_to can overshoot: (i) If CHARPOS is on invisible
1364 text, move_it_to stops at the end of the invisible text,
1365 after CHARPOS. (ii) If CHARPOS is in a display vector,
1366 move_it_to stops on its last glyph. */
1367 int top_x
= it
.current_x
;
1368 int top_y
= it
.current_y
;
1369 enum it_method it_method
= it
.method
;
1370 /* Calling line_bottom_y may change it.method, it.position, etc. */
1371 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1372 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1374 if (top_y
< window_top_y
)
1375 visible_p
= bottom_y
> window_top_y
;
1376 else if (top_y
< it
.last_visible_y
)
1380 if (it_method
== GET_FROM_BUFFER
)
1382 Lisp_Object window
, prop
;
1384 XSETWINDOW (window
, w
);
1385 prop
= Fget_char_property (make_number (charpos
),
1386 Qinvisible
, window
);
1388 /* If charpos coincides with invisible text covered with an
1389 ellipsis, use the first glyph of the ellipsis to compute
1390 the pixel positions. */
1391 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1393 struct glyph_row
*row
= it
.glyph_row
;
1394 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1395 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1399 && (!BUFFERP (glyph
->object
)
1400 || glyph
->charpos
< charpos
);
1402 x
+= glyph
->pixel_width
;
1406 else if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1408 /* We stopped on the last glyph of a display vector.
1409 Try and recompute. Hack alert! */
1410 if (charpos
< 2 || top
.charpos
>= charpos
)
1411 top_x
= it
.glyph_row
->x
;
1415 start_display (&it2
, w
, top
);
1416 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1417 get_next_display_element (&it2
);
1418 PRODUCE_GLYPHS (&it2
);
1419 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1420 || it2
.current_x
> it2
.last_visible_x
)
1421 top_x
= it
.glyph_row
->x
;
1424 top_x
= it2
.current_x
;
1425 top_y
= it2
.current_y
;
1431 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1432 *rtop
= max (0, window_top_y
- top_y
);
1433 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1434 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1435 - max (top_y
, window_top_y
)));
1444 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1445 move_it_by_lines (&it
, 1, 0);
1446 if (charpos
< IT_CHARPOS (it
)
1447 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1450 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1452 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1453 *rtop
= max (0, -it2
.current_y
);
1454 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1455 - it
.last_visible_y
));
1456 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1458 - max (it2
.current_y
,
1459 WINDOW_HEADER_LINE_HEIGHT (w
))));
1465 set_buffer_internal_1 (old_buffer
);
1467 current_header_line_height
= current_mode_line_height
= -1;
1469 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1470 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1473 /* Debugging code. */
1475 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1476 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1478 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1485 /* Return the next character from STR which is MAXLEN bytes long.
1486 Return in *LEN the length of the character. This is like
1487 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1488 we find one, we return a `?', but with the length of the invalid
1492 string_char_and_length (str
, len
)
1493 const unsigned char *str
;
1498 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1499 if (!CHAR_VALID_P (c
, 1))
1500 /* We may not change the length here because other places in Emacs
1501 don't use this function, i.e. they silently accept invalid
1510 /* Given a position POS containing a valid character and byte position
1511 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1513 static struct text_pos
1514 string_pos_nchars_ahead (pos
, string
, nchars
)
1515 struct text_pos pos
;
1519 xassert (STRINGP (string
) && nchars
>= 0);
1521 if (STRING_MULTIBYTE (string
))
1523 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1524 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1529 string_char_and_length (p
, &len
);
1530 p
+= len
, rest
-= len
;
1531 xassert (rest
>= 0);
1533 BYTEPOS (pos
) += len
;
1537 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1543 /* Value is the text position, i.e. character and byte position,
1544 for character position CHARPOS in STRING. */
1546 static INLINE
struct text_pos
1547 string_pos (charpos
, string
)
1551 struct text_pos pos
;
1552 xassert (STRINGP (string
));
1553 xassert (charpos
>= 0);
1554 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1559 /* Value is a text position, i.e. character and byte position, for
1560 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1561 means recognize multibyte characters. */
1563 static struct text_pos
1564 c_string_pos (charpos
, s
, multibyte_p
)
1569 struct text_pos pos
;
1571 xassert (s
!= NULL
);
1572 xassert (charpos
>= 0);
1576 int rest
= strlen (s
), len
;
1578 SET_TEXT_POS (pos
, 0, 0);
1581 string_char_and_length (s
, &len
);
1582 s
+= len
, rest
-= len
;
1583 xassert (rest
>= 0);
1585 BYTEPOS (pos
) += len
;
1589 SET_TEXT_POS (pos
, charpos
, charpos
);
1595 /* Value is the number of characters in C string S. MULTIBYTE_P
1596 non-zero means recognize multibyte characters. */
1599 number_of_chars (s
, multibyte_p
)
1607 int rest
= strlen (s
), len
;
1608 unsigned char *p
= (unsigned char *) s
;
1610 for (nchars
= 0; rest
> 0; ++nchars
)
1612 string_char_and_length (p
, &len
);
1613 rest
-= len
, p
+= len
;
1617 nchars
= strlen (s
);
1623 /* Compute byte position NEWPOS->bytepos corresponding to
1624 NEWPOS->charpos. POS is a known position in string STRING.
1625 NEWPOS->charpos must be >= POS.charpos. */
1628 compute_string_pos (newpos
, pos
, string
)
1629 struct text_pos
*newpos
, pos
;
1632 xassert (STRINGP (string
));
1633 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1635 if (STRING_MULTIBYTE (string
))
1636 *newpos
= string_pos_nchars_ahead (pos
, string
,
1637 CHARPOS (*newpos
) - CHARPOS (pos
));
1639 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1643 Return an estimation of the pixel height of mode or header lines on
1644 frame F. FACE_ID specifies what line's height to estimate. */
1647 estimate_mode_line_height (f
, face_id
)
1649 enum face_id face_id
;
1651 #ifdef HAVE_WINDOW_SYSTEM
1652 if (FRAME_WINDOW_P (f
))
1654 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1656 /* This function is called so early when Emacs starts that the face
1657 cache and mode line face are not yet initialized. */
1658 if (FRAME_FACE_CACHE (f
))
1660 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1664 height
= FONT_HEIGHT (face
->font
);
1665 if (face
->box_line_width
> 0)
1666 height
+= 2 * face
->box_line_width
;
1677 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1678 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1679 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1680 not force the value into range. */
1683 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1685 register int pix_x
, pix_y
;
1687 NativeRectangle
*bounds
;
1691 #ifdef HAVE_WINDOW_SYSTEM
1692 if (FRAME_WINDOW_P (f
))
1694 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1695 even for negative values. */
1697 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1699 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1701 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1702 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1705 STORE_NATIVE_RECT (*bounds
,
1706 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1707 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1708 FRAME_COLUMN_WIDTH (f
) - 1,
1709 FRAME_LINE_HEIGHT (f
) - 1);
1715 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1716 pix_x
= FRAME_TOTAL_COLS (f
);
1720 else if (pix_y
> FRAME_LINES (f
))
1721 pix_y
= FRAME_LINES (f
);
1731 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1732 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1733 can't tell the positions because W's display is not up to date,
1737 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1740 int *frame_x
, *frame_y
;
1742 #ifdef HAVE_WINDOW_SYSTEM
1743 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1747 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1748 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1750 if (display_completed
)
1752 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1753 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1754 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1760 hpos
+= glyph
->pixel_width
;
1764 /* If first glyph is partially visible, its first visible position is still 0. */
1776 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1777 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1788 #ifdef HAVE_WINDOW_SYSTEM
1790 /* Find the glyph under window-relative coordinates X/Y in window W.
1791 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1792 strings. Return in *HPOS and *VPOS the row and column number of
1793 the glyph found. Return in *AREA the glyph area containing X.
1794 Value is a pointer to the glyph found or null if X/Y is not on
1795 text, or we can't tell because W's current matrix is not up to
1800 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1803 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1805 struct glyph
*glyph
, *end
;
1806 struct glyph_row
*row
= NULL
;
1809 /* Find row containing Y. Give up if some row is not enabled. */
1810 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1812 row
= MATRIX_ROW (w
->current_matrix
, i
);
1813 if (!row
->enabled_p
)
1815 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1822 /* Give up if Y is not in the window. */
1823 if (i
== w
->current_matrix
->nrows
)
1826 /* Get the glyph area containing X. */
1827 if (w
->pseudo_window_p
)
1834 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1836 *area
= LEFT_MARGIN_AREA
;
1837 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1839 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1842 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1846 *area
= RIGHT_MARGIN_AREA
;
1847 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1851 /* Find glyph containing X. */
1852 glyph
= row
->glyphs
[*area
];
1853 end
= glyph
+ row
->used
[*area
];
1855 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1857 x
-= glyph
->pixel_width
;
1867 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1870 *hpos
= glyph
- row
->glyphs
[*area
];
1876 Convert frame-relative x/y to coordinates relative to window W.
1877 Takes pseudo-windows into account. */
1880 frame_to_window_pixel_xy (w
, x
, y
)
1884 if (w
->pseudo_window_p
)
1886 /* A pseudo-window is always full-width, and starts at the
1887 left edge of the frame, plus a frame border. */
1888 struct frame
*f
= XFRAME (w
->frame
);
1889 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1890 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1894 *x
-= WINDOW_LEFT_EDGE_X (w
);
1895 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1900 Return in RECTS[] at most N clipping rectangles for glyph string S.
1901 Return the number of stored rectangles. */
1904 get_glyph_string_clip_rects (s
, rects
, n
)
1905 struct glyph_string
*s
;
1906 NativeRectangle
*rects
;
1914 if (s
->row
->full_width_p
)
1916 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1917 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1918 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1920 /* Unless displaying a mode or menu bar line, which are always
1921 fully visible, clip to the visible part of the row. */
1922 if (s
->w
->pseudo_window_p
)
1923 r
.height
= s
->row
->visible_height
;
1925 r
.height
= s
->height
;
1929 /* This is a text line that may be partially visible. */
1930 r
.x
= window_box_left (s
->w
, s
->area
);
1931 r
.width
= window_box_width (s
->w
, s
->area
);
1932 r
.height
= s
->row
->visible_height
;
1936 if (r
.x
< s
->clip_head
->x
)
1938 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1939 r
.width
-= s
->clip_head
->x
- r
.x
;
1942 r
.x
= s
->clip_head
->x
;
1945 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1947 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1948 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1953 /* If S draws overlapping rows, it's sufficient to use the top and
1954 bottom of the window for clipping because this glyph string
1955 intentionally draws over other lines. */
1956 if (s
->for_overlaps
)
1958 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1959 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1961 /* Alas, the above simple strategy does not work for the
1962 environments with anti-aliased text: if the same text is
1963 drawn onto the same place multiple times, it gets thicker.
1964 If the overlap we are processing is for the erased cursor, we
1965 take the intersection with the rectagle of the cursor. */
1966 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1968 XRectangle rc
, r_save
= r
;
1970 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1971 rc
.y
= s
->w
->phys_cursor
.y
;
1972 rc
.width
= s
->w
->phys_cursor_width
;
1973 rc
.height
= s
->w
->phys_cursor_height
;
1975 x_intersect_rectangles (&r_save
, &rc
, &r
);
1980 /* Don't use S->y for clipping because it doesn't take partially
1981 visible lines into account. For example, it can be negative for
1982 partially visible lines at the top of a window. */
1983 if (!s
->row
->full_width_p
1984 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1985 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1987 r
.y
= max (0, s
->row
->y
);
1990 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1992 /* If drawing the cursor, don't let glyph draw outside its
1993 advertised boundaries. Cleartype does this under some circumstances. */
1994 if (s
->hl
== DRAW_CURSOR
)
1996 struct glyph
*glyph
= s
->first_glyph
;
2001 r
.width
-= s
->x
- r
.x
;
2004 r
.width
= min (r
.width
, glyph
->pixel_width
);
2006 /* If r.y is below window bottom, ensure that we still see a cursor. */
2007 height
= min (glyph
->ascent
+ glyph
->descent
,
2008 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2009 max_y
= window_text_bottom_y (s
->w
) - height
;
2010 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2011 if (s
->ybase
- glyph
->ascent
> max_y
)
2018 /* Don't draw cursor glyph taller than our actual glyph. */
2019 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2020 if (height
< r
.height
)
2022 max_y
= r
.y
+ r
.height
;
2023 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2024 r
.height
= min (max_y
- r
.y
, height
);
2031 XRectangle r_save
= r
;
2033 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2037 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2038 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2040 #ifdef CONVERT_FROM_XRECT
2041 CONVERT_FROM_XRECT (r
, *rects
);
2049 /* If we are processing overlapping and allowed to return
2050 multiple clipping rectangles, we exclude the row of the glyph
2051 string from the clipping rectangle. This is to avoid drawing
2052 the same text on the environment with anti-aliasing. */
2053 #ifdef CONVERT_FROM_XRECT
2056 XRectangle
*rs
= rects
;
2058 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2060 if (s
->for_overlaps
& OVERLAPS_PRED
)
2063 if (r
.y
+ r
.height
> row_y
)
2066 rs
[i
].height
= row_y
- r
.y
;
2072 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2075 if (r
.y
< row_y
+ s
->row
->visible_height
)
2077 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2079 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2080 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2089 #ifdef CONVERT_FROM_XRECT
2090 for (i
= 0; i
< n
; i
++)
2091 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2098 Return in *NR the clipping rectangle for glyph string S. */
2101 get_glyph_string_clip_rect (s
, nr
)
2102 struct glyph_string
*s
;
2103 NativeRectangle
*nr
;
2105 get_glyph_string_clip_rects (s
, nr
, 1);
2110 Return the position and height of the phys cursor in window W.
2111 Set w->phys_cursor_width to width of phys cursor.
2115 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2117 struct glyph_row
*row
;
2118 struct glyph
*glyph
;
2119 int *xp
, *yp
, *heightp
;
2121 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2122 int x
, y
, wd
, h
, h0
, y0
;
2124 /* Compute the width of the rectangle to draw. If on a stretch
2125 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2126 rectangle as wide as the glyph, but use a canonical character
2128 wd
= glyph
->pixel_width
- 1;
2129 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2133 x
= w
->phys_cursor
.x
;
2140 if (glyph
->type
== STRETCH_GLYPH
2141 && !x_stretch_cursor_p
)
2142 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2143 w
->phys_cursor_width
= wd
;
2145 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2147 /* If y is below window bottom, ensure that we still see a cursor. */
2148 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2150 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2151 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2153 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2156 h
= max (h
- (y0
- y
) + 1, h0
);
2161 y0
= window_text_bottom_y (w
) - h0
;
2169 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2170 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2175 * Remember which glyph the mouse is over.
2179 remember_mouse_glyph (f
, gx
, gy
, rect
)
2182 NativeRectangle
*rect
;
2186 struct glyph_row
*r
, *gr
, *end_row
;
2187 enum window_part part
;
2188 enum glyph_row_area area
;
2189 int x
, y
, width
, height
;
2191 /* Try to determine frame pixel position and size of the glyph under
2192 frame pixel coordinates X/Y on frame F. */
2194 if (!f
->glyphs_initialized_p
2195 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2198 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2199 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2203 w
= XWINDOW (window
);
2204 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2205 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2207 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2208 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2210 if (w
->pseudo_window_p
)
2213 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2219 case ON_LEFT_MARGIN
:
2220 area
= LEFT_MARGIN_AREA
;
2223 case ON_RIGHT_MARGIN
:
2224 area
= RIGHT_MARGIN_AREA
;
2227 case ON_HEADER_LINE
:
2229 gr
= (part
== ON_HEADER_LINE
2230 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2231 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2234 goto text_glyph_row_found
;
2241 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2242 if (r
->y
+ r
->height
> y
)
2248 text_glyph_row_found
:
2251 struct glyph
*g
= gr
->glyphs
[area
];
2252 struct glyph
*end
= g
+ gr
->used
[area
];
2254 height
= gr
->height
;
2255 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2256 if (gx
+ g
->pixel_width
> x
)
2261 if (g
->type
== IMAGE_GLYPH
)
2263 /* Don't remember when mouse is over image, as
2264 image may have hot-spots. */
2265 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2268 width
= g
->pixel_width
;
2272 /* Use nominal char spacing at end of line. */
2274 gx
+= (x
/ width
) * width
;
2277 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2278 gx
+= window_box_left_offset (w
, area
);
2282 /* Use nominal line height at end of window. */
2283 gx
= (x
/ width
) * width
;
2285 gy
+= (y
/ height
) * height
;
2289 case ON_LEFT_FRINGE
:
2290 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2291 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2292 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2293 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2296 case ON_RIGHT_FRINGE
:
2297 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2298 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2299 : window_box_right_offset (w
, TEXT_AREA
));
2300 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2304 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2306 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2307 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2308 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2310 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2314 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2315 if (r
->y
+ r
->height
> y
)
2322 height
= gr
->height
;
2325 /* Use nominal line height at end of window. */
2327 gy
+= (y
/ height
) * height
;
2334 /* If there is no glyph under the mouse, then we divide the screen
2335 into a grid of the smallest glyph in the frame, and use that
2338 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2339 round down even for negative values. */
2345 gx
= (gx
/ width
) * width
;
2346 gy
= (gy
/ height
) * height
;
2351 gx
+= WINDOW_LEFT_EDGE_X (w
);
2352 gy
+= WINDOW_TOP_EDGE_Y (w
);
2355 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2357 /* Visible feedback for debugging. */
2360 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2361 f
->output_data
.x
->normal_gc
,
2362 gx
, gy
, width
, height
);
2368 #endif /* HAVE_WINDOW_SYSTEM */
2371 /***********************************************************************
2372 Lisp form evaluation
2373 ***********************************************************************/
2375 /* Error handler for safe_eval and safe_call. */
2378 safe_eval_handler (arg
)
2381 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2386 /* Evaluate SEXPR and return the result, or nil if something went
2387 wrong. Prevent redisplay during the evaluation. */
2389 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2390 Return the result, or nil if something went wrong. Prevent
2391 redisplay during the evaluation. */
2394 safe_call (nargs
, args
)
2400 if (inhibit_eval_during_redisplay
)
2404 int count
= SPECPDL_INDEX ();
2405 struct gcpro gcpro1
;
2408 gcpro1
.nvars
= nargs
;
2409 specbind (Qinhibit_redisplay
, Qt
);
2410 /* Use Qt to ensure debugger does not run,
2411 so there is no possibility of wanting to redisplay. */
2412 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2415 val
= unbind_to (count
, val
);
2422 /* Call function FN with one argument ARG.
2423 Return the result, or nil if something went wrong. */
2426 safe_call1 (fn
, arg
)
2427 Lisp_Object fn
, arg
;
2429 Lisp_Object args
[2];
2432 return safe_call (2, args
);
2435 static Lisp_Object Qeval
;
2438 safe_eval (Lisp_Object sexpr
)
2440 return safe_call1 (Qeval
, sexpr
);
2443 /* Call function FN with one argument ARG.
2444 Return the result, or nil if something went wrong. */
2447 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2449 Lisp_Object args
[3];
2453 return safe_call (3, args
);
2458 /***********************************************************************
2460 ***********************************************************************/
2464 /* Define CHECK_IT to perform sanity checks on iterators.
2465 This is for debugging. It is too slow to do unconditionally. */
2471 if (it
->method
== GET_FROM_STRING
)
2473 xassert (STRINGP (it
->string
));
2474 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2478 xassert (IT_STRING_CHARPOS (*it
) < 0);
2479 if (it
->method
== GET_FROM_BUFFER
)
2481 /* Check that character and byte positions agree. */
2482 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2487 xassert (it
->current
.dpvec_index
>= 0);
2489 xassert (it
->current
.dpvec_index
< 0);
2492 #define CHECK_IT(IT) check_it ((IT))
2496 #define CHECK_IT(IT) (void) 0
2503 /* Check that the window end of window W is what we expect it
2504 to be---the last row in the current matrix displaying text. */
2507 check_window_end (w
)
2510 if (!MINI_WINDOW_P (w
)
2511 && !NILP (w
->window_end_valid
))
2513 struct glyph_row
*row
;
2514 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2515 XFASTINT (w
->window_end_vpos
)),
2517 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2518 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2522 #define CHECK_WINDOW_END(W) check_window_end ((W))
2524 #else /* not GLYPH_DEBUG */
2526 #define CHECK_WINDOW_END(W) (void) 0
2528 #endif /* not GLYPH_DEBUG */
2532 /***********************************************************************
2533 Iterator initialization
2534 ***********************************************************************/
2536 /* Initialize IT for displaying current_buffer in window W, starting
2537 at character position CHARPOS. CHARPOS < 0 means that no buffer
2538 position is specified which is useful when the iterator is assigned
2539 a position later. BYTEPOS is the byte position corresponding to
2540 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2542 If ROW is not null, calls to produce_glyphs with IT as parameter
2543 will produce glyphs in that row.
2545 BASE_FACE_ID is the id of a base face to use. It must be one of
2546 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2547 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2548 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2550 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2551 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2552 will be initialized to use the corresponding mode line glyph row of
2553 the desired matrix of W. */
2556 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2559 int charpos
, bytepos
;
2560 struct glyph_row
*row
;
2561 enum face_id base_face_id
;
2563 int highlight_region_p
;
2564 enum face_id remapped_base_face_id
= base_face_id
;
2566 /* Some precondition checks. */
2567 xassert (w
!= NULL
&& it
!= NULL
);
2568 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2571 /* If face attributes have been changed since the last redisplay,
2572 free realized faces now because they depend on face definitions
2573 that might have changed. Don't free faces while there might be
2574 desired matrices pending which reference these faces. */
2575 if (face_change_count
&& !inhibit_free_realized_faces
)
2577 face_change_count
= 0;
2578 free_all_realized_faces (Qnil
);
2581 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2582 if (! NILP (Vface_remapping_alist
))
2583 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2585 /* Use one of the mode line rows of W's desired matrix if
2589 if (base_face_id
== MODE_LINE_FACE_ID
2590 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2591 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2592 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2593 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2597 bzero (it
, sizeof *it
);
2598 it
->current
.overlay_string_index
= -1;
2599 it
->current
.dpvec_index
= -1;
2600 it
->base_face_id
= remapped_base_face_id
;
2602 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2604 /* The window in which we iterate over current_buffer: */
2605 XSETWINDOW (it
->window
, w
);
2607 it
->f
= XFRAME (w
->frame
);
2611 /* Extra space between lines (on window systems only). */
2612 if (base_face_id
== DEFAULT_FACE_ID
2613 && FRAME_WINDOW_P (it
->f
))
2615 if (NATNUMP (current_buffer
->extra_line_spacing
))
2616 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2617 else if (FLOATP (current_buffer
->extra_line_spacing
))
2618 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2619 * FRAME_LINE_HEIGHT (it
->f
));
2620 else if (it
->f
->extra_line_spacing
> 0)
2621 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2622 it
->max_extra_line_spacing
= 0;
2625 /* If realized faces have been removed, e.g. because of face
2626 attribute changes of named faces, recompute them. When running
2627 in batch mode, the face cache of the initial frame is null. If
2628 we happen to get called, make a dummy face cache. */
2629 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2630 init_frame_faces (it
->f
);
2631 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2632 recompute_basic_faces (it
->f
);
2634 /* Current value of the `slice', `space-width', and 'height' properties. */
2635 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2636 it
->space_width
= Qnil
;
2637 it
->font_height
= Qnil
;
2638 it
->override_ascent
= -1;
2640 /* Are control characters displayed as `^C'? */
2641 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2643 /* -1 means everything between a CR and the following line end
2644 is invisible. >0 means lines indented more than this value are
2646 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2647 ? XFASTINT (current_buffer
->selective_display
)
2648 : (!NILP (current_buffer
->selective_display
)
2650 it
->selective_display_ellipsis_p
2651 = !NILP (current_buffer
->selective_display_ellipses
);
2653 /* Display table to use. */
2654 it
->dp
= window_display_table (w
);
2656 /* Are multibyte characters enabled in current_buffer? */
2657 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2659 /* Do we need to reorder bidirectional text? */
2660 it
->bidi_p
= !NILP (current_buffer
->bidi_display_reordering
);
2662 /* Non-zero if we should highlight the region. */
2664 = (!NILP (Vtransient_mark_mode
)
2665 && !NILP (current_buffer
->mark_active
)
2666 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2668 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2669 start and end of a visible region in window IT->w. Set both to
2670 -1 to indicate no region. */
2671 if (highlight_region_p
2672 /* Maybe highlight only in selected window. */
2673 && (/* Either show region everywhere. */
2674 highlight_nonselected_windows
2675 /* Or show region in the selected window. */
2676 || w
== XWINDOW (selected_window
)
2677 /* Or show the region if we are in the mini-buffer and W is
2678 the window the mini-buffer refers to. */
2679 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2680 && WINDOWP (minibuf_selected_window
)
2681 && w
== XWINDOW (minibuf_selected_window
))))
2683 int charpos
= marker_position (current_buffer
->mark
);
2684 it
->region_beg_charpos
= min (PT
, charpos
);
2685 it
->region_end_charpos
= max (PT
, charpos
);
2688 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2690 /* Get the position at which the redisplay_end_trigger hook should
2691 be run, if it is to be run at all. */
2692 if (MARKERP (w
->redisplay_end_trigger
)
2693 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2694 it
->redisplay_end_trigger_charpos
2695 = marker_position (w
->redisplay_end_trigger
);
2696 else if (INTEGERP (w
->redisplay_end_trigger
))
2697 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2699 /* Correct bogus values of tab_width. */
2700 it
->tab_width
= XINT (current_buffer
->tab_width
);
2701 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2704 /* Are lines in the display truncated? */
2705 if (base_face_id
!= DEFAULT_FACE_ID
2706 || XINT (it
->w
->hscroll
)
2707 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2708 && ((!NILP (Vtruncate_partial_width_windows
)
2709 && !INTEGERP (Vtruncate_partial_width_windows
))
2710 || (INTEGERP (Vtruncate_partial_width_windows
)
2711 && (WINDOW_TOTAL_COLS (it
->w
)
2712 < XINT (Vtruncate_partial_width_windows
))))))
2713 it
->line_wrap
= TRUNCATE
;
2714 else if (NILP (current_buffer
->truncate_lines
))
2715 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2716 ? WINDOW_WRAP
: WORD_WRAP
;
2718 it
->line_wrap
= TRUNCATE
;
2720 /* Get dimensions of truncation and continuation glyphs. These are
2721 displayed as fringe bitmaps under X, so we don't need them for such
2723 if (!FRAME_WINDOW_P (it
->f
))
2725 if (it
->line_wrap
== TRUNCATE
)
2727 /* We will need the truncation glyph. */
2728 xassert (it
->glyph_row
== NULL
);
2729 produce_special_glyphs (it
, IT_TRUNCATION
);
2730 it
->truncation_pixel_width
= it
->pixel_width
;
2734 /* We will need the continuation glyph. */
2735 xassert (it
->glyph_row
== NULL
);
2736 produce_special_glyphs (it
, IT_CONTINUATION
);
2737 it
->continuation_pixel_width
= it
->pixel_width
;
2740 /* Reset these values to zero because the produce_special_glyphs
2741 above has changed them. */
2742 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2743 it
->phys_ascent
= it
->phys_descent
= 0;
2746 /* Set this after getting the dimensions of truncation and
2747 continuation glyphs, so that we don't produce glyphs when calling
2748 produce_special_glyphs, above. */
2749 it
->glyph_row
= row
;
2750 it
->area
= TEXT_AREA
;
2752 /* Forget any previous info about this row being reversed. */
2754 it
->glyph_row
->reversed_p
= 0;
2756 /* Get the dimensions of the display area. The display area
2757 consists of the visible window area plus a horizontally scrolled
2758 part to the left of the window. All x-values are relative to the
2759 start of this total display area. */
2760 if (base_face_id
!= DEFAULT_FACE_ID
)
2762 /* Mode lines, menu bar in terminal frames. */
2763 it
->first_visible_x
= 0;
2764 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2769 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2770 it
->last_visible_x
= (it
->first_visible_x
2771 + window_box_width (w
, TEXT_AREA
));
2773 /* If we truncate lines, leave room for the truncator glyph(s) at
2774 the right margin. Otherwise, leave room for the continuation
2775 glyph(s). Truncation and continuation glyphs are not inserted
2776 for window-based redisplay. */
2777 if (!FRAME_WINDOW_P (it
->f
))
2779 if (it
->line_wrap
== TRUNCATE
)
2780 it
->last_visible_x
-= it
->truncation_pixel_width
;
2782 it
->last_visible_x
-= it
->continuation_pixel_width
;
2785 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2786 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2789 /* Leave room for a border glyph. */
2790 if (!FRAME_WINDOW_P (it
->f
)
2791 && !WINDOW_RIGHTMOST_P (it
->w
))
2792 it
->last_visible_x
-= 1;
2794 it
->last_visible_y
= window_text_bottom_y (w
);
2796 /* For mode lines and alike, arrange for the first glyph having a
2797 left box line if the face specifies a box. */
2798 if (base_face_id
!= DEFAULT_FACE_ID
)
2802 it
->face_id
= remapped_base_face_id
;
2804 /* If we have a boxed mode line, make the first character appear
2805 with a left box line. */
2806 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2807 if (face
->box
!= FACE_NO_BOX
)
2808 it
->start_of_box_run_p
= 1;
2811 /* If we are to reorder bidirectional text, init the bidi
2815 /* Note the paragraph direction that this buffer wants to
2817 if (EQ (current_buffer
->bidi_paragraph_direction
, Qleft_to_right
))
2818 it
->paragraph_embedding
= L2R
;
2819 else if (EQ (current_buffer
->bidi_paragraph_direction
, Qright_to_left
))
2820 it
->paragraph_embedding
= R2L
;
2822 it
->paragraph_embedding
= NEUTRAL_DIR
;
2823 bidi_init_it (charpos
, bytepos
, &it
->bidi_it
);
2826 /* If a buffer position was specified, set the iterator there,
2827 getting overlays and face properties from that position. */
2828 if (charpos
>= BUF_BEG (current_buffer
))
2830 it
->end_charpos
= ZV
;
2832 IT_CHARPOS (*it
) = charpos
;
2834 /* Compute byte position if not specified. */
2835 if (bytepos
< charpos
)
2836 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2838 IT_BYTEPOS (*it
) = bytepos
;
2840 it
->start
= it
->current
;
2842 /* Compute faces etc. */
2843 reseat (it
, it
->current
.pos
, 1);
2850 /* Initialize IT for the display of window W with window start POS. */
2853 start_display (it
, w
, pos
)
2856 struct text_pos pos
;
2858 struct glyph_row
*row
;
2859 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2861 row
= w
->desired_matrix
->rows
+ first_vpos
;
2862 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2863 it
->first_vpos
= first_vpos
;
2865 /* Don't reseat to previous visible line start if current start
2866 position is in a string or image. */
2867 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2869 int start_at_line_beg_p
;
2870 int first_y
= it
->current_y
;
2872 /* If window start is not at a line start, skip forward to POS to
2873 get the correct continuation lines width. */
2874 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2875 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2876 if (!start_at_line_beg_p
)
2880 reseat_at_previous_visible_line_start (it
);
2881 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2883 new_x
= it
->current_x
+ it
->pixel_width
;
2885 /* If lines are continued, this line may end in the middle
2886 of a multi-glyph character (e.g. a control character
2887 displayed as \003, or in the middle of an overlay
2888 string). In this case move_it_to above will not have
2889 taken us to the start of the continuation line but to the
2890 end of the continued line. */
2891 if (it
->current_x
> 0
2892 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2893 && (/* And glyph doesn't fit on the line. */
2894 new_x
> it
->last_visible_x
2895 /* Or it fits exactly and we're on a window
2897 || (new_x
== it
->last_visible_x
2898 && FRAME_WINDOW_P (it
->f
))))
2900 if (it
->current
.dpvec_index
>= 0
2901 || it
->current
.overlay_string_index
>= 0)
2903 set_iterator_to_next (it
, 1);
2904 move_it_in_display_line_to (it
, -1, -1, 0);
2907 it
->continuation_lines_width
+= it
->current_x
;
2910 /* We're starting a new display line, not affected by the
2911 height of the continued line, so clear the appropriate
2912 fields in the iterator structure. */
2913 it
->max_ascent
= it
->max_descent
= 0;
2914 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2916 it
->current_y
= first_y
;
2918 it
->current_x
= it
->hpos
= 0;
2924 /* Return 1 if POS is a position in ellipses displayed for invisible
2925 text. W is the window we display, for text property lookup. */
2928 in_ellipses_for_invisible_text_p (pos
, w
)
2929 struct display_pos
*pos
;
2932 Lisp_Object prop
, window
;
2934 int charpos
= CHARPOS (pos
->pos
);
2936 /* If POS specifies a position in a display vector, this might
2937 be for an ellipsis displayed for invisible text. We won't
2938 get the iterator set up for delivering that ellipsis unless
2939 we make sure that it gets aware of the invisible text. */
2940 if (pos
->dpvec_index
>= 0
2941 && pos
->overlay_string_index
< 0
2942 && CHARPOS (pos
->string_pos
) < 0
2944 && (XSETWINDOW (window
, w
),
2945 prop
= Fget_char_property (make_number (charpos
),
2946 Qinvisible
, window
),
2947 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2949 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2951 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2958 /* Initialize IT for stepping through current_buffer in window W,
2959 starting at position POS that includes overlay string and display
2960 vector/ control character translation position information. Value
2961 is zero if there are overlay strings with newlines at POS. */
2964 init_from_display_pos (it
, w
, pos
)
2967 struct display_pos
*pos
;
2969 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2970 int i
, overlay_strings_with_newlines
= 0;
2972 /* If POS specifies a position in a display vector, this might
2973 be for an ellipsis displayed for invisible text. We won't
2974 get the iterator set up for delivering that ellipsis unless
2975 we make sure that it gets aware of the invisible text. */
2976 if (in_ellipses_for_invisible_text_p (pos
, w
))
2982 /* Keep in mind: the call to reseat in init_iterator skips invisible
2983 text, so we might end up at a position different from POS. This
2984 is only a problem when POS is a row start after a newline and an
2985 overlay starts there with an after-string, and the overlay has an
2986 invisible property. Since we don't skip invisible text in
2987 display_line and elsewhere immediately after consuming the
2988 newline before the row start, such a POS will not be in a string,
2989 but the call to init_iterator below will move us to the
2991 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2993 /* This only scans the current chunk -- it should scan all chunks.
2994 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2995 to 16 in 22.1 to make this a lesser problem. */
2996 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2998 const char *s
= SDATA (it
->overlay_strings
[i
]);
2999 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3001 while (s
< e
&& *s
!= '\n')
3006 overlay_strings_with_newlines
= 1;
3011 /* If position is within an overlay string, set up IT to the right
3013 if (pos
->overlay_string_index
>= 0)
3017 /* If the first overlay string happens to have a `display'
3018 property for an image, the iterator will be set up for that
3019 image, and we have to undo that setup first before we can
3020 correct the overlay string index. */
3021 if (it
->method
== GET_FROM_IMAGE
)
3024 /* We already have the first chunk of overlay strings in
3025 IT->overlay_strings. Load more until the one for
3026 pos->overlay_string_index is in IT->overlay_strings. */
3027 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3029 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3030 it
->current
.overlay_string_index
= 0;
3033 load_overlay_strings (it
, 0);
3034 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3038 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3039 relative_index
= (it
->current
.overlay_string_index
3040 % OVERLAY_STRING_CHUNK_SIZE
);
3041 it
->string
= it
->overlay_strings
[relative_index
];
3042 xassert (STRINGP (it
->string
));
3043 it
->current
.string_pos
= pos
->string_pos
;
3044 it
->method
= GET_FROM_STRING
;
3047 if (CHARPOS (pos
->string_pos
) >= 0)
3049 /* Recorded position is not in an overlay string, but in another
3050 string. This can only be a string from a `display' property.
3051 IT should already be filled with that string. */
3052 it
->current
.string_pos
= pos
->string_pos
;
3053 xassert (STRINGP (it
->string
));
3056 /* Restore position in display vector translations, control
3057 character translations or ellipses. */
3058 if (pos
->dpvec_index
>= 0)
3060 if (it
->dpvec
== NULL
)
3061 get_next_display_element (it
);
3062 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3063 it
->current
.dpvec_index
= pos
->dpvec_index
;
3067 return !overlay_strings_with_newlines
;
3071 /* Initialize IT for stepping through current_buffer in window W
3072 starting at ROW->start. */
3075 init_to_row_start (it
, w
, row
)
3078 struct glyph_row
*row
;
3080 init_from_display_pos (it
, w
, &row
->start
);
3081 it
->start
= row
->start
;
3082 it
->continuation_lines_width
= row
->continuation_lines_width
;
3087 /* Initialize IT for stepping through current_buffer in window W
3088 starting in the line following ROW, i.e. starting at ROW->end.
3089 Value is zero if there are overlay strings with newlines at ROW's
3093 init_to_row_end (it
, w
, row
)
3096 struct glyph_row
*row
;
3100 if (init_from_display_pos (it
, w
, &row
->end
))
3102 if (row
->continued_p
)
3103 it
->continuation_lines_width
3104 = row
->continuation_lines_width
+ row
->pixel_width
;
3115 /***********************************************************************
3117 ***********************************************************************/
3119 /* Called when IT reaches IT->stop_charpos. Handle text property and
3120 overlay changes. Set IT->stop_charpos to the next position where
3127 enum prop_handled handled
;
3128 int handle_overlay_change_p
;
3132 it
->current
.dpvec_index
= -1;
3133 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3134 it
->ignore_overlay_strings_at_pos_p
= 0;
3137 /* Use face of preceding text for ellipsis (if invisible) */
3138 if (it
->selective_display_ellipsis_p
)
3139 it
->saved_face_id
= it
->face_id
;
3143 handled
= HANDLED_NORMALLY
;
3145 /* Call text property handlers. */
3146 for (p
= it_props
; p
->handler
; ++p
)
3148 handled
= p
->handler (it
);
3150 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3152 else if (handled
== HANDLED_RETURN
)
3154 /* We still want to show before and after strings from
3155 overlays even if the actual buffer text is replaced. */
3156 if (!handle_overlay_change_p
3158 || !get_overlay_strings_1 (it
, 0, 0))
3161 setup_for_ellipsis (it
, 0);
3162 /* When handling a display spec, we might load an
3163 empty string. In that case, discard it here. We
3164 used to discard it in handle_single_display_spec,
3165 but that causes get_overlay_strings_1, above, to
3166 ignore overlay strings that we must check. */
3167 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3171 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3175 it
->ignore_overlay_strings_at_pos_p
= 1;
3176 it
->string_from_display_prop_p
= 0;
3177 handle_overlay_change_p
= 0;
3179 handled
= HANDLED_RECOMPUTE_PROPS
;
3182 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3183 handle_overlay_change_p
= 0;
3186 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3188 /* Don't check for overlay strings below when set to deliver
3189 characters from a display vector. */
3190 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3191 handle_overlay_change_p
= 0;
3193 /* Handle overlay changes.
3194 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3195 if it finds overlays. */
3196 if (handle_overlay_change_p
)
3197 handled
= handle_overlay_change (it
);
3202 setup_for_ellipsis (it
, 0);
3206 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3208 /* Determine where to stop next. */
3209 if (handled
== HANDLED_NORMALLY
)
3210 compute_stop_pos (it
);
3214 /* Compute IT->stop_charpos from text property and overlay change
3215 information for IT's current position. */
3218 compute_stop_pos (it
)
3221 register INTERVAL iv
, next_iv
;
3222 Lisp_Object object
, limit
, position
;
3223 EMACS_INT charpos
, bytepos
;
3225 /* If nowhere else, stop at the end. */
3226 it
->stop_charpos
= it
->end_charpos
;
3228 if (STRINGP (it
->string
))
3230 /* Strings are usually short, so don't limit the search for
3232 object
= it
->string
;
3234 charpos
= IT_STRING_CHARPOS (*it
);
3235 bytepos
= IT_STRING_BYTEPOS (*it
);
3241 /* If next overlay change is in front of the current stop pos
3242 (which is IT->end_charpos), stop there. Note: value of
3243 next_overlay_change is point-max if no overlay change
3245 charpos
= IT_CHARPOS (*it
);
3246 bytepos
= IT_BYTEPOS (*it
);
3247 pos
= next_overlay_change (charpos
);
3248 if (pos
< it
->stop_charpos
)
3249 it
->stop_charpos
= pos
;
3251 /* If showing the region, we have to stop at the region
3252 start or end because the face might change there. */
3253 if (it
->region_beg_charpos
> 0)
3255 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3256 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3257 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3258 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3261 /* Set up variables for computing the stop position from text
3262 property changes. */
3263 XSETBUFFER (object
, current_buffer
);
3264 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3267 /* Get the interval containing IT's position. Value is a null
3268 interval if there isn't such an interval. */
3269 position
= make_number (charpos
);
3270 iv
= validate_interval_range (object
, &position
, &position
, 0);
3271 if (!NULL_INTERVAL_P (iv
))
3273 Lisp_Object values_here
[LAST_PROP_IDX
];
3276 /* Get properties here. */
3277 for (p
= it_props
; p
->handler
; ++p
)
3278 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3280 /* Look for an interval following iv that has different
3282 for (next_iv
= next_interval (iv
);
3283 (!NULL_INTERVAL_P (next_iv
)
3285 || XFASTINT (limit
) > next_iv
->position
));
3286 next_iv
= next_interval (next_iv
))
3288 for (p
= it_props
; p
->handler
; ++p
)
3290 Lisp_Object new_value
;
3292 new_value
= textget (next_iv
->plist
, *p
->name
);
3293 if (!EQ (values_here
[p
->idx
], new_value
))
3301 if (!NULL_INTERVAL_P (next_iv
))
3303 if (INTEGERP (limit
)
3304 && next_iv
->position
>= XFASTINT (limit
))
3305 /* No text property change up to limit. */
3306 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3308 /* Text properties change in next_iv. */
3309 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3313 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3314 it
->stop_charpos
, it
->string
);
3316 xassert (STRINGP (it
->string
)
3317 || (it
->stop_charpos
>= BEGV
3318 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3322 /* Return the position of the next overlay change after POS in
3323 current_buffer. Value is point-max if no overlay change
3324 follows. This is like `next-overlay-change' but doesn't use
3328 next_overlay_change (pos
)
3333 Lisp_Object
*overlays
;
3336 /* Get all overlays at the given position. */
3337 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3339 /* If any of these overlays ends before endpos,
3340 use its ending point instead. */
3341 for (i
= 0; i
< noverlays
; ++i
)
3346 oend
= OVERLAY_END (overlays
[i
]);
3347 oendpos
= OVERLAY_POSITION (oend
);
3348 endpos
= min (endpos
, oendpos
);
3356 /***********************************************************************
3358 ***********************************************************************/
3360 /* Handle changes in the `fontified' property of the current buffer by
3361 calling hook functions from Qfontification_functions to fontify
3364 static enum prop_handled
3365 handle_fontified_prop (it
)
3368 Lisp_Object prop
, pos
;
3369 enum prop_handled handled
= HANDLED_NORMALLY
;
3371 if (!NILP (Vmemory_full
))
3374 /* Get the value of the `fontified' property at IT's current buffer
3375 position. (The `fontified' property doesn't have a special
3376 meaning in strings.) If the value is nil, call functions from
3377 Qfontification_functions. */
3378 if (!STRINGP (it
->string
)
3380 && !NILP (Vfontification_functions
)
3381 && !NILP (Vrun_hooks
)
3382 && (pos
= make_number (IT_CHARPOS (*it
)),
3383 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3384 /* Ignore the special cased nil value always present at EOB since
3385 no amount of fontifying will be able to change it. */
3386 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3388 int count
= SPECPDL_INDEX ();
3391 val
= Vfontification_functions
;
3392 specbind (Qfontification_functions
, Qnil
);
3394 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3395 safe_call1 (val
, pos
);
3398 Lisp_Object globals
, fn
;
3399 struct gcpro gcpro1
, gcpro2
;
3402 GCPRO2 (val
, globals
);
3404 for (; CONSP (val
); val
= XCDR (val
))
3410 /* A value of t indicates this hook has a local
3411 binding; it means to run the global binding too.
3412 In a global value, t should not occur. If it
3413 does, we must ignore it to avoid an endless
3415 for (globals
= Fdefault_value (Qfontification_functions
);
3417 globals
= XCDR (globals
))
3419 fn
= XCAR (globals
);
3421 safe_call1 (fn
, pos
);
3425 safe_call1 (fn
, pos
);
3431 unbind_to (count
, Qnil
);
3433 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3434 something. This avoids an endless loop if they failed to
3435 fontify the text for which reason ever. */
3436 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3437 handled
= HANDLED_RECOMPUTE_PROPS
;
3445 /***********************************************************************
3447 ***********************************************************************/
3449 /* Set up iterator IT from face properties at its current position.
3450 Called from handle_stop. */
3452 static enum prop_handled
3453 handle_face_prop (it
)
3457 EMACS_INT next_stop
;
3459 if (!STRINGP (it
->string
))
3462 = face_at_buffer_position (it
->w
,
3464 it
->region_beg_charpos
,
3465 it
->region_end_charpos
,
3468 + TEXT_PROP_DISTANCE_LIMIT
),
3469 0, it
->base_face_id
);
3471 /* Is this a start of a run of characters with box face?
3472 Caveat: this can be called for a freshly initialized
3473 iterator; face_id is -1 in this case. We know that the new
3474 face will not change until limit, i.e. if the new face has a
3475 box, all characters up to limit will have one. But, as
3476 usual, we don't know whether limit is really the end. */
3477 if (new_face_id
!= it
->face_id
)
3479 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3481 /* If new face has a box but old face has not, this is
3482 the start of a run of characters with box, i.e. it has
3483 a shadow on the left side. The value of face_id of the
3484 iterator will be -1 if this is the initial call that gets
3485 the face. In this case, we have to look in front of IT's
3486 position and see whether there is a face != new_face_id. */
3487 it
->start_of_box_run_p
3488 = (new_face
->box
!= FACE_NO_BOX
3489 && (it
->face_id
>= 0
3490 || IT_CHARPOS (*it
) == BEG
3491 || new_face_id
!= face_before_it_pos (it
)));
3492 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3497 int base_face_id
, bufpos
;
3499 Lisp_Object from_overlay
3500 = (it
->current
.overlay_string_index
>= 0
3501 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3504 /* See if we got to this string directly or indirectly from
3505 an overlay property. That includes the before-string or
3506 after-string of an overlay, strings in display properties
3507 provided by an overlay, their text properties, etc.
3509 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3510 if (! NILP (from_overlay
))
3511 for (i
= it
->sp
- 1; i
>= 0; i
--)
3513 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3515 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3516 else if (! NILP (it
->stack
[i
].from_overlay
))
3517 from_overlay
= it
->stack
[i
].from_overlay
;
3519 if (!NILP (from_overlay
))
3523 if (! NILP (from_overlay
))
3525 bufpos
= IT_CHARPOS (*it
);
3526 /* For a string from an overlay, the base face depends
3527 only on text properties and ignores overlays. */
3529 = face_for_overlay_string (it
->w
,
3531 it
->region_beg_charpos
,
3532 it
->region_end_charpos
,
3535 + TEXT_PROP_DISTANCE_LIMIT
),
3543 /* For strings from a `display' property, use the face at
3544 IT's current buffer position as the base face to merge
3545 with, so that overlay strings appear in the same face as
3546 surrounding text, unless they specify their own
3548 base_face_id
= underlying_face_id (it
);
3551 new_face_id
= face_at_string_position (it
->w
,
3553 IT_STRING_CHARPOS (*it
),
3555 it
->region_beg_charpos
,
3556 it
->region_end_charpos
,
3560 /* Is this a start of a run of characters with box? Caveat:
3561 this can be called for a freshly allocated iterator; face_id
3562 is -1 is this case. We know that the new face will not
3563 change until the next check pos, i.e. if the new face has a
3564 box, all characters up to that position will have a
3565 box. But, as usual, we don't know whether that position
3566 is really the end. */
3567 if (new_face_id
!= it
->face_id
)
3569 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3570 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3572 /* If new face has a box but old face hasn't, this is the
3573 start of a run of characters with box, i.e. it has a
3574 shadow on the left side. */
3575 it
->start_of_box_run_p
3576 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3577 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3581 it
->face_id
= new_face_id
;
3582 return HANDLED_NORMALLY
;
3586 /* Return the ID of the face ``underlying'' IT's current position,
3587 which is in a string. If the iterator is associated with a
3588 buffer, return the face at IT's current buffer position.
3589 Otherwise, use the iterator's base_face_id. */
3592 underlying_face_id (it
)
3595 int face_id
= it
->base_face_id
, i
;
3597 xassert (STRINGP (it
->string
));
3599 for (i
= it
->sp
- 1; i
>= 0; --i
)
3600 if (NILP (it
->stack
[i
].string
))
3601 face_id
= it
->stack
[i
].face_id
;
3607 /* Compute the face one character before or after the current position
3608 of IT. BEFORE_P non-zero means get the face in front of IT's
3609 position. Value is the id of the face. */
3612 face_before_or_after_it_pos (it
, before_p
)
3617 EMACS_INT next_check_charpos
;
3618 struct text_pos pos
;
3620 xassert (it
->s
== NULL
);
3622 if (STRINGP (it
->string
))
3624 int bufpos
, base_face_id
;
3626 /* No face change past the end of the string (for the case
3627 we are padding with spaces). No face change before the
3629 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3630 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3633 /* Set pos to the position before or after IT's current position. */
3635 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3637 /* For composition, we must check the character after the
3639 pos
= (it
->what
== IT_COMPOSITION
3640 ? string_pos (IT_STRING_CHARPOS (*it
)
3641 + it
->cmp_it
.nchars
, it
->string
)
3642 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3644 if (it
->current
.overlay_string_index
>= 0)
3645 bufpos
= IT_CHARPOS (*it
);
3649 base_face_id
= underlying_face_id (it
);
3651 /* Get the face for ASCII, or unibyte. */
3652 face_id
= face_at_string_position (it
->w
,
3656 it
->region_beg_charpos
,
3657 it
->region_end_charpos
,
3658 &next_check_charpos
,
3661 /* Correct the face for charsets different from ASCII. Do it
3662 for the multibyte case only. The face returned above is
3663 suitable for unibyte text if IT->string is unibyte. */
3664 if (STRING_MULTIBYTE (it
->string
))
3666 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3667 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3669 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3671 c
= string_char_and_length (p
, &len
);
3672 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3677 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3678 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3681 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3682 pos
= it
->current
.pos
;
3685 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3688 if (it
->what
== IT_COMPOSITION
)
3689 /* For composition, we must check the position after the
3691 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3693 INC_TEXT_POS (pos
, it
->multibyte_p
);
3696 /* Determine face for CHARSET_ASCII, or unibyte. */
3697 face_id
= face_at_buffer_position (it
->w
,
3699 it
->region_beg_charpos
,
3700 it
->region_end_charpos
,
3701 &next_check_charpos
,
3704 /* Correct the face for charsets different from ASCII. Do it
3705 for the multibyte case only. The face returned above is
3706 suitable for unibyte text if current_buffer is unibyte. */
3707 if (it
->multibyte_p
)
3709 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3710 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3711 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3720 /***********************************************************************
3722 ***********************************************************************/
3724 /* Set up iterator IT from invisible properties at its current
3725 position. Called from handle_stop. */
3727 static enum prop_handled
3728 handle_invisible_prop (it
)
3731 enum prop_handled handled
= HANDLED_NORMALLY
;
3733 if (STRINGP (it
->string
))
3735 extern Lisp_Object Qinvisible
;
3736 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3738 /* Get the value of the invisible text property at the
3739 current position. Value will be nil if there is no such
3741 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3742 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3745 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3747 handled
= HANDLED_RECOMPUTE_PROPS
;
3749 /* Get the position at which the next change of the
3750 invisible text property can be found in IT->string.
3751 Value will be nil if the property value is the same for
3752 all the rest of IT->string. */
3753 XSETINT (limit
, SCHARS (it
->string
));
3754 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3757 /* Text at current position is invisible. The next
3758 change in the property is at position end_charpos.
3759 Move IT's current position to that position. */
3760 if (INTEGERP (end_charpos
)
3761 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3763 struct text_pos old
;
3764 old
= it
->current
.string_pos
;
3765 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3766 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3770 /* The rest of the string is invisible. If this is an
3771 overlay string, proceed with the next overlay string
3772 or whatever comes and return a character from there. */
3773 if (it
->current
.overlay_string_index
>= 0)
3775 next_overlay_string (it
);
3776 /* Don't check for overlay strings when we just
3777 finished processing them. */
3778 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3782 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3783 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3791 EMACS_INT newpos
, next_stop
, start_charpos
, tem
;
3792 Lisp_Object pos
, prop
, overlay
;
3794 /* First of all, is there invisible text at this position? */
3795 tem
= start_charpos
= IT_CHARPOS (*it
);
3796 pos
= make_number (tem
);
3797 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3799 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3801 /* If we are on invisible text, skip over it. */
3802 if (invis_p
&& start_charpos
< it
->end_charpos
)
3804 /* Record whether we have to display an ellipsis for the
3806 int display_ellipsis_p
= invis_p
== 2;
3808 handled
= HANDLED_RECOMPUTE_PROPS
;
3810 /* Loop skipping over invisible text. The loop is left at
3811 ZV or with IT on the first char being visible again. */
3814 /* Try to skip some invisible text. Return value is the
3815 position reached which can be equal to where we start
3816 if there is nothing invisible there. This skips both
3817 over invisible text properties and overlays with
3818 invisible property. */
3819 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
3821 /* If we skipped nothing at all we weren't at invisible
3822 text in the first place. If everything to the end of
3823 the buffer was skipped, end the loop. */
3824 if (newpos
== tem
|| newpos
>= ZV
)
3828 /* We skipped some characters but not necessarily
3829 all there are. Check if we ended up on visible
3830 text. Fget_char_property returns the property of
3831 the char before the given position, i.e. if we
3832 get invis_p = 0, this means that the char at
3833 newpos is visible. */
3834 pos
= make_number (newpos
);
3835 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3836 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3839 /* If we ended up on invisible text, proceed to
3840 skip starting with next_stop. */
3844 /* If there are adjacent invisible texts, don't lose the
3845 second one's ellipsis. */
3847 display_ellipsis_p
= 1;
3851 /* The position newpos is now either ZV or on visible text. */
3852 if (it
->bidi_p
&& newpos
< ZV
)
3854 /* With bidi iteration, the region of invisible text
3855 could start and/or end in the middle of a non-base
3856 embedding level. Therefore, we need to skip
3857 invisible text using the bidi iterator, starting at
3858 IT's current position, until we find ourselves
3859 outside the invisible text. Skipping invisible text
3860 _after_ bidi iteration avoids affecting the visual
3861 order of the displayed text when invisible properties
3862 are added or removed. */
3863 if (it
->bidi_it
.first_elt
)
3865 /* If we were `reseat'ed to a new paragraph,
3866 determine the paragraph base direction. We need
3867 to do it now because next_element_from_buffer may
3868 not have a chance to do it, if we are going to
3869 skip any text at the beginning, which resets the
3871 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
3872 /* If the paragraph base direction is R2L, its
3873 glyphs should be reversed. */
3876 if (it
->bidi_it
.paragraph_dir
== R2L
)
3877 it
->glyph_row
->reversed_p
= 1;
3879 it
->glyph_row
->reversed_p
= 0;
3884 bidi_get_next_char_visually (&it
->bidi_it
);
3886 while (it
->stop_charpos
<= it
->bidi_it
.charpos
3887 && it
->bidi_it
.charpos
< newpos
);
3888 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
3889 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
3890 /* If we overstepped NEWPOS, record its position in the
3891 iterator, so that we skip invisible text if later the
3892 bidi iteration lands us in the invisible region
3894 if (IT_CHARPOS (*it
) >= newpos
)
3895 it
->prev_stop
= newpos
;
3899 IT_CHARPOS (*it
) = newpos
;
3900 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3903 /* If there are before-strings at the start of invisible
3904 text, and the text is invisible because of a text
3905 property, arrange to show before-strings because 20.x did
3906 it that way. (If the text is invisible because of an
3907 overlay property instead of a text property, this is
3908 already handled in the overlay code.) */
3910 && get_overlay_strings (it
, it
->stop_charpos
))
3912 handled
= HANDLED_RECOMPUTE_PROPS
;
3913 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3915 else if (display_ellipsis_p
)
3917 /* Make sure that the glyphs of the ellipsis will get
3918 correct `charpos' values. If we would not update
3919 it->position here, the glyphs would belong to the
3920 last visible character _before_ the invisible
3921 text, which confuses `set_cursor_from_row'.
3923 We use the last invisible position instead of the
3924 first because this way the cursor is always drawn on
3925 the first "." of the ellipsis, whenever PT is inside
3926 the invisible text. Otherwise the cursor would be
3927 placed _after_ the ellipsis when the point is after the
3928 first invisible character. */
3929 if (!STRINGP (it
->object
))
3931 it
->position
.charpos
= newpos
- 1;
3932 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3935 /* Let the ellipsis display before
3936 considering any properties of the following char.
3937 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3938 handled
= HANDLED_RETURN
;
3947 /* Make iterator IT return `...' next.
3948 Replaces LEN characters from buffer. */
3951 setup_for_ellipsis (it
, len
)
3955 /* Use the display table definition for `...'. Invalid glyphs
3956 will be handled by the method returning elements from dpvec. */
3957 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3959 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3960 it
->dpvec
= v
->contents
;
3961 it
->dpend
= v
->contents
+ v
->size
;
3965 /* Default `...'. */
3966 it
->dpvec
= default_invis_vector
;
3967 it
->dpend
= default_invis_vector
+ 3;
3970 it
->dpvec_char_len
= len
;
3971 it
->current
.dpvec_index
= 0;
3972 it
->dpvec_face_id
= -1;
3974 /* Remember the current face id in case glyphs specify faces.
3975 IT's face is restored in set_iterator_to_next.
3976 saved_face_id was set to preceding char's face in handle_stop. */
3977 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3978 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3980 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3986 /***********************************************************************
3988 ***********************************************************************/
3990 /* Set up iterator IT from `display' property at its current position.
3991 Called from handle_stop.
3992 We return HANDLED_RETURN if some part of the display property
3993 overrides the display of the buffer text itself.
3994 Otherwise we return HANDLED_NORMALLY. */
3996 static enum prop_handled
3997 handle_display_prop (it
)
4000 Lisp_Object prop
, object
, overlay
;
4001 struct text_pos
*position
;
4002 /* Nonzero if some property replaces the display of the text itself. */
4003 int display_replaced_p
= 0;
4005 if (STRINGP (it
->string
))
4007 object
= it
->string
;
4008 position
= &it
->current
.string_pos
;
4012 XSETWINDOW (object
, it
->w
);
4013 position
= &it
->current
.pos
;
4016 /* Reset those iterator values set from display property values. */
4017 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4018 it
->space_width
= Qnil
;
4019 it
->font_height
= Qnil
;
4022 /* We don't support recursive `display' properties, i.e. string
4023 values that have a string `display' property, that have a string
4024 `display' property etc. */
4025 if (!it
->string_from_display_prop_p
)
4026 it
->area
= TEXT_AREA
;
4028 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
4029 Qdisplay
, object
, &overlay
);
4031 return HANDLED_NORMALLY
;
4032 /* Now OVERLAY is the overlay that gave us this property, or nil
4033 if it was a text property. */
4035 if (!STRINGP (it
->string
))
4036 object
= it
->w
->buffer
;
4039 /* Simple properties. */
4040 && !EQ (XCAR (prop
), Qimage
)
4041 && !EQ (XCAR (prop
), Qspace
)
4042 && !EQ (XCAR (prop
), Qwhen
)
4043 && !EQ (XCAR (prop
), Qslice
)
4044 && !EQ (XCAR (prop
), Qspace_width
)
4045 && !EQ (XCAR (prop
), Qheight
)
4046 && !EQ (XCAR (prop
), Qraise
)
4047 /* Marginal area specifications. */
4048 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
4049 && !EQ (XCAR (prop
), Qleft_fringe
)
4050 && !EQ (XCAR (prop
), Qright_fringe
)
4051 && !NILP (XCAR (prop
)))
4053 for (; CONSP (prop
); prop
= XCDR (prop
))
4055 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
4056 position
, display_replaced_p
))
4058 display_replaced_p
= 1;
4059 /* If some text in a string is replaced, `position' no
4060 longer points to the position of `object'. */
4061 if (STRINGP (object
))
4066 else if (VECTORP (prop
))
4069 for (i
= 0; i
< ASIZE (prop
); ++i
)
4070 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4071 position
, display_replaced_p
))
4073 display_replaced_p
= 1;
4074 /* If some text in a string is replaced, `position' no
4075 longer points to the position of `object'. */
4076 if (STRINGP (object
))
4082 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4084 display_replaced_p
= 1;
4087 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4091 /* Value is the position of the end of the `display' property starting
4092 at START_POS in OBJECT. */
4094 static struct text_pos
4095 display_prop_end (it
, object
, start_pos
)
4098 struct text_pos start_pos
;
4101 struct text_pos end_pos
;
4103 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4104 Qdisplay
, object
, Qnil
);
4105 CHARPOS (end_pos
) = XFASTINT (end
);
4106 if (STRINGP (object
))
4107 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4109 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4115 /* Set up IT from a single `display' specification PROP. OBJECT
4116 is the object in which the `display' property was found. *POSITION
4117 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4118 means that we previously saw a display specification which already
4119 replaced text display with something else, for example an image;
4120 we ignore such properties after the first one has been processed.
4122 OVERLAY is the overlay this `display' property came from,
4123 or nil if it was a text property.
4125 If PROP is a `space' or `image' specification, and in some other
4126 cases too, set *POSITION to the position where the `display'
4129 Value is non-zero if something was found which replaces the display
4130 of buffer or string text. */
4133 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4134 display_replaced_before_p
)
4138 Lisp_Object overlay
;
4139 struct text_pos
*position
;
4140 int display_replaced_before_p
;
4143 Lisp_Object location
, value
;
4144 struct text_pos start_pos
, save_pos
;
4147 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4148 If the result is non-nil, use VALUE instead of SPEC. */
4150 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4159 if (!NILP (form
) && !EQ (form
, Qt
))
4161 int count
= SPECPDL_INDEX ();
4162 struct gcpro gcpro1
;
4164 /* Bind `object' to the object having the `display' property, a
4165 buffer or string. Bind `position' to the position in the
4166 object where the property was found, and `buffer-position'
4167 to the current position in the buffer. */
4168 specbind (Qobject
, object
);
4169 specbind (Qposition
, make_number (CHARPOS (*position
)));
4170 specbind (Qbuffer_position
,
4171 make_number (STRINGP (object
)
4172 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4174 form
= safe_eval (form
);
4176 unbind_to (count
, Qnil
);
4182 /* Handle `(height HEIGHT)' specifications. */
4184 && EQ (XCAR (spec
), Qheight
)
4185 && CONSP (XCDR (spec
)))
4187 if (!FRAME_WINDOW_P (it
->f
))
4190 it
->font_height
= XCAR (XCDR (spec
));
4191 if (!NILP (it
->font_height
))
4193 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4194 int new_height
= -1;
4196 if (CONSP (it
->font_height
)
4197 && (EQ (XCAR (it
->font_height
), Qplus
)
4198 || EQ (XCAR (it
->font_height
), Qminus
))
4199 && CONSP (XCDR (it
->font_height
))
4200 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4202 /* `(+ N)' or `(- N)' where N is an integer. */
4203 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4204 if (EQ (XCAR (it
->font_height
), Qplus
))
4206 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4208 else if (FUNCTIONP (it
->font_height
))
4210 /* Call function with current height as argument.
4211 Value is the new height. */
4213 height
= safe_call1 (it
->font_height
,
4214 face
->lface
[LFACE_HEIGHT_INDEX
]);
4215 if (NUMBERP (height
))
4216 new_height
= XFLOATINT (height
);
4218 else if (NUMBERP (it
->font_height
))
4220 /* Value is a multiple of the canonical char height. */
4223 face
= FACE_FROM_ID (it
->f
,
4224 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4225 new_height
= (XFLOATINT (it
->font_height
)
4226 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4230 /* Evaluate IT->font_height with `height' bound to the
4231 current specified height to get the new height. */
4232 int count
= SPECPDL_INDEX ();
4234 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4235 value
= safe_eval (it
->font_height
);
4236 unbind_to (count
, Qnil
);
4238 if (NUMBERP (value
))
4239 new_height
= XFLOATINT (value
);
4243 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4249 /* Handle `(space-width WIDTH)'. */
4251 && EQ (XCAR (spec
), Qspace_width
)
4252 && CONSP (XCDR (spec
)))
4254 if (!FRAME_WINDOW_P (it
->f
))
4257 value
= XCAR (XCDR (spec
));
4258 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4259 it
->space_width
= value
;
4264 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4266 && EQ (XCAR (spec
), Qslice
))
4270 if (!FRAME_WINDOW_P (it
->f
))
4273 if (tem
= XCDR (spec
), CONSP (tem
))
4275 it
->slice
.x
= XCAR (tem
);
4276 if (tem
= XCDR (tem
), CONSP (tem
))
4278 it
->slice
.y
= XCAR (tem
);
4279 if (tem
= XCDR (tem
), CONSP (tem
))
4281 it
->slice
.width
= XCAR (tem
);
4282 if (tem
= XCDR (tem
), CONSP (tem
))
4283 it
->slice
.height
= XCAR (tem
);
4291 /* Handle `(raise FACTOR)'. */
4293 && EQ (XCAR (spec
), Qraise
)
4294 && CONSP (XCDR (spec
)))
4296 if (!FRAME_WINDOW_P (it
->f
))
4299 #ifdef HAVE_WINDOW_SYSTEM
4300 value
= XCAR (XCDR (spec
));
4301 if (NUMBERP (value
))
4303 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4304 it
->voffset
= - (XFLOATINT (value
)
4305 * (FONT_HEIGHT (face
->font
)));
4307 #endif /* HAVE_WINDOW_SYSTEM */
4312 /* Don't handle the other kinds of display specifications
4313 inside a string that we got from a `display' property. */
4314 if (it
->string_from_display_prop_p
)
4317 /* Characters having this form of property are not displayed, so
4318 we have to find the end of the property. */
4319 start_pos
= *position
;
4320 *position
= display_prop_end (it
, object
, start_pos
);
4323 /* Stop the scan at that end position--we assume that all
4324 text properties change there. */
4325 it
->stop_charpos
= position
->charpos
;
4327 /* Handle `(left-fringe BITMAP [FACE])'
4328 and `(right-fringe BITMAP [FACE])'. */
4330 && (EQ (XCAR (spec
), Qleft_fringe
)
4331 || EQ (XCAR (spec
), Qright_fringe
))
4332 && CONSP (XCDR (spec
)))
4334 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4337 if (!FRAME_WINDOW_P (it
->f
))
4338 /* If we return here, POSITION has been advanced
4339 across the text with this property. */
4342 #ifdef HAVE_WINDOW_SYSTEM
4343 value
= XCAR (XCDR (spec
));
4344 if (!SYMBOLP (value
)
4345 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4346 /* If we return here, POSITION has been advanced
4347 across the text with this property. */
4350 if (CONSP (XCDR (XCDR (spec
))))
4352 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4353 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4359 /* Save current settings of IT so that we can restore them
4360 when we are finished with the glyph property value. */
4362 save_pos
= it
->position
;
4363 it
->position
= *position
;
4365 it
->position
= save_pos
;
4367 it
->area
= TEXT_AREA
;
4368 it
->what
= IT_IMAGE
;
4369 it
->image_id
= -1; /* no image */
4370 it
->position
= start_pos
;
4371 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4372 it
->method
= GET_FROM_IMAGE
;
4373 it
->from_overlay
= Qnil
;
4374 it
->face_id
= face_id
;
4376 /* Say that we haven't consumed the characters with
4377 `display' property yet. The call to pop_it in
4378 set_iterator_to_next will clean this up. */
4379 *position
= start_pos
;
4381 if (EQ (XCAR (spec
), Qleft_fringe
))
4383 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4384 it
->left_user_fringe_face_id
= face_id
;
4388 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4389 it
->right_user_fringe_face_id
= face_id
;
4391 #endif /* HAVE_WINDOW_SYSTEM */
4395 /* Prepare to handle `((margin left-margin) ...)',
4396 `((margin right-margin) ...)' and `((margin nil) ...)'
4397 prefixes for display specifications. */
4398 location
= Qunbound
;
4399 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4403 value
= XCDR (spec
);
4405 value
= XCAR (value
);
4408 if (EQ (XCAR (tem
), Qmargin
)
4409 && (tem
= XCDR (tem
),
4410 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4412 || EQ (tem
, Qleft_margin
)
4413 || EQ (tem
, Qright_margin
))))
4417 if (EQ (location
, Qunbound
))
4423 /* After this point, VALUE is the property after any
4424 margin prefix has been stripped. It must be a string,
4425 an image specification, or `(space ...)'.
4427 LOCATION specifies where to display: `left-margin',
4428 `right-margin' or nil. */
4430 valid_p
= (STRINGP (value
)
4431 #ifdef HAVE_WINDOW_SYSTEM
4432 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4433 #endif /* not HAVE_WINDOW_SYSTEM */
4434 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4436 if (valid_p
&& !display_replaced_before_p
)
4438 /* Save current settings of IT so that we can restore them
4439 when we are finished with the glyph property value. */
4440 save_pos
= it
->position
;
4441 it
->position
= *position
;
4443 it
->position
= save_pos
;
4444 it
->from_overlay
= overlay
;
4446 if (NILP (location
))
4447 it
->area
= TEXT_AREA
;
4448 else if (EQ (location
, Qleft_margin
))
4449 it
->area
= LEFT_MARGIN_AREA
;
4451 it
->area
= RIGHT_MARGIN_AREA
;
4453 if (STRINGP (value
))
4456 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4457 it
->current
.overlay_string_index
= -1;
4458 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4459 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4460 it
->method
= GET_FROM_STRING
;
4461 it
->stop_charpos
= 0;
4462 it
->string_from_display_prop_p
= 1;
4463 /* Say that we haven't consumed the characters with
4464 `display' property yet. The call to pop_it in
4465 set_iterator_to_next will clean this up. */
4466 if (BUFFERP (object
))
4467 *position
= start_pos
;
4469 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4471 it
->method
= GET_FROM_STRETCH
;
4473 *position
= it
->position
= start_pos
;
4475 #ifdef HAVE_WINDOW_SYSTEM
4478 it
->what
= IT_IMAGE
;
4479 it
->image_id
= lookup_image (it
->f
, value
);
4480 it
->position
= start_pos
;
4481 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4482 it
->method
= GET_FROM_IMAGE
;
4484 /* Say that we haven't consumed the characters with
4485 `display' property yet. The call to pop_it in
4486 set_iterator_to_next will clean this up. */
4487 *position
= start_pos
;
4489 #endif /* HAVE_WINDOW_SYSTEM */
4494 /* Invalid property or property not supported. Restore
4495 POSITION to what it was before. */
4496 *position
= start_pos
;
4501 /* Check if SPEC is a display sub-property value whose text should be
4502 treated as intangible. */
4505 single_display_spec_intangible_p (prop
)
4508 /* Skip over `when FORM'. */
4509 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4523 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4524 we don't need to treat text as intangible. */
4525 if (EQ (XCAR (prop
), Qmargin
))
4533 || EQ (XCAR (prop
), Qleft_margin
)
4534 || EQ (XCAR (prop
), Qright_margin
))
4538 return (CONSP (prop
)
4539 && (EQ (XCAR (prop
), Qimage
)
4540 || EQ (XCAR (prop
), Qspace
)));
4544 /* Check if PROP is a display property value whose text should be
4545 treated as intangible. */
4548 display_prop_intangible_p (prop
)
4552 && CONSP (XCAR (prop
))
4553 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4555 /* A list of sub-properties. */
4556 while (CONSP (prop
))
4558 if (single_display_spec_intangible_p (XCAR (prop
)))
4563 else if (VECTORP (prop
))
4565 /* A vector of sub-properties. */
4567 for (i
= 0; i
< ASIZE (prop
); ++i
)
4568 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4572 return single_display_spec_intangible_p (prop
);
4578 /* Return 1 if PROP is a display sub-property value containing STRING. */
4581 single_display_spec_string_p (prop
, string
)
4582 Lisp_Object prop
, string
;
4584 if (EQ (string
, prop
))
4587 /* Skip over `when FORM'. */
4588 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4597 /* Skip over `margin LOCATION'. */
4598 if (EQ (XCAR (prop
), Qmargin
))
4609 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4613 /* Return 1 if STRING appears in the `display' property PROP. */
4616 display_prop_string_p (prop
, string
)
4617 Lisp_Object prop
, string
;
4620 && CONSP (XCAR (prop
))
4621 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4623 /* A list of sub-properties. */
4624 while (CONSP (prop
))
4626 if (single_display_spec_string_p (XCAR (prop
), string
))
4631 else if (VECTORP (prop
))
4633 /* A vector of sub-properties. */
4635 for (i
= 0; i
< ASIZE (prop
); ++i
)
4636 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4640 return single_display_spec_string_p (prop
, string
);
4645 /* Look for STRING in overlays and text properties in W's buffer,
4646 between character positions FROM and TO (excluding TO).
4647 BACK_P non-zero means look back (in this case, TO is supposed to be
4649 Value is the first character position where STRING was found, or
4650 zero if it wasn't found before hitting TO.
4652 W's buffer must be current.
4654 This function may only use code that doesn't eval because it is
4655 called asynchronously from note_mouse_highlight. */
4658 string_buffer_position_lim (w
, string
, from
, to
, back_p
)
4664 Lisp_Object limit
, prop
, pos
;
4667 pos
= make_number (from
);
4669 if (!back_p
) /* looking forward */
4671 limit
= make_number (min (to
, ZV
));
4672 while (!found
&& !EQ (pos
, limit
))
4674 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4675 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4678 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4682 else /* looking back */
4684 limit
= make_number (max (to
, BEGV
));
4685 while (!found
&& !EQ (pos
, limit
))
4687 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4688 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4691 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4696 return found
? XINT (pos
) : 0;
4699 /* Determine which buffer position in W's buffer STRING comes from.
4700 AROUND_CHARPOS is an approximate position where it could come from.
4701 Value is the buffer position or 0 if it couldn't be determined.
4703 W's buffer must be current.
4705 This function is necessary because we don't record buffer positions
4706 in glyphs generated from strings (to keep struct glyph small).
4707 This function may only use code that doesn't eval because it is
4708 called asynchronously from note_mouse_highlight. */
4711 string_buffer_position (w
, string
, around_charpos
)
4714 EMACS_INT around_charpos
;
4716 Lisp_Object limit
, prop
, pos
;
4717 const int MAX_DISTANCE
= 1000;
4718 EMACS_INT found
= string_buffer_position_lim (w
, string
, around_charpos
,
4719 around_charpos
+ MAX_DISTANCE
,
4723 found
= string_buffer_position_lim (w
, string
, around_charpos
,
4724 around_charpos
- MAX_DISTANCE
, 1);
4730 /***********************************************************************
4731 `composition' property
4732 ***********************************************************************/
4734 /* Set up iterator IT from `composition' property at its current
4735 position. Called from handle_stop. */
4737 static enum prop_handled
4738 handle_composition_prop (it
)
4741 Lisp_Object prop
, string
;
4742 EMACS_INT pos
, pos_byte
, start
, end
;
4744 if (STRINGP (it
->string
))
4748 pos
= IT_STRING_CHARPOS (*it
);
4749 pos_byte
= IT_STRING_BYTEPOS (*it
);
4750 string
= it
->string
;
4751 s
= SDATA (string
) + pos_byte
;
4752 it
->c
= STRING_CHAR (s
);
4756 pos
= IT_CHARPOS (*it
);
4757 pos_byte
= IT_BYTEPOS (*it
);
4759 it
->c
= FETCH_CHAR (pos_byte
);
4762 /* If there's a valid composition and point is not inside of the
4763 composition (in the case that the composition is from the current
4764 buffer), draw a glyph composed from the composition components. */
4765 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4766 && COMPOSITION_VALID_P (start
, end
, prop
)
4767 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4771 if (STRINGP (it
->string
))
4772 pos_byte
= string_char_to_byte (it
->string
, start
);
4774 pos_byte
= CHAR_TO_BYTE (start
);
4776 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4779 if (it
->cmp_it
.id
>= 0)
4782 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4783 it
->cmp_it
.nglyphs
= -1;
4787 return HANDLED_NORMALLY
;
4792 /***********************************************************************
4794 ***********************************************************************/
4796 /* The following structure is used to record overlay strings for
4797 later sorting in load_overlay_strings. */
4799 struct overlay_entry
4801 Lisp_Object overlay
;
4808 /* Set up iterator IT from overlay strings at its current position.
4809 Called from handle_stop. */
4811 static enum prop_handled
4812 handle_overlay_change (it
)
4815 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4816 return HANDLED_RECOMPUTE_PROPS
;
4818 return HANDLED_NORMALLY
;
4822 /* Set up the next overlay string for delivery by IT, if there is an
4823 overlay string to deliver. Called by set_iterator_to_next when the
4824 end of the current overlay string is reached. If there are more
4825 overlay strings to display, IT->string and
4826 IT->current.overlay_string_index are set appropriately here.
4827 Otherwise IT->string is set to nil. */
4830 next_overlay_string (it
)
4833 ++it
->current
.overlay_string_index
;
4834 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4836 /* No more overlay strings. Restore IT's settings to what
4837 they were before overlay strings were processed, and
4838 continue to deliver from current_buffer. */
4840 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4843 || (NILP (it
->string
)
4844 && it
->method
== GET_FROM_BUFFER
4845 && it
->stop_charpos
>= BEGV
4846 && it
->stop_charpos
<= it
->end_charpos
));
4847 it
->current
.overlay_string_index
= -1;
4848 it
->n_overlay_strings
= 0;
4850 /* If we're at the end of the buffer, record that we have
4851 processed the overlay strings there already, so that
4852 next_element_from_buffer doesn't try it again. */
4853 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4854 it
->overlay_strings_at_end_processed_p
= 1;
4858 /* There are more overlay strings to process. If
4859 IT->current.overlay_string_index has advanced to a position
4860 where we must load IT->overlay_strings with more strings, do
4862 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4864 if (it
->current
.overlay_string_index
&& i
== 0)
4865 load_overlay_strings (it
, 0);
4867 /* Initialize IT to deliver display elements from the overlay
4869 it
->string
= it
->overlay_strings
[i
];
4870 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4871 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4872 it
->method
= GET_FROM_STRING
;
4873 it
->stop_charpos
= 0;
4874 if (it
->cmp_it
.stop_pos
>= 0)
4875 it
->cmp_it
.stop_pos
= 0;
4882 /* Compare two overlay_entry structures E1 and E2. Used as a
4883 comparison function for qsort in load_overlay_strings. Overlay
4884 strings for the same position are sorted so that
4886 1. All after-strings come in front of before-strings, except
4887 when they come from the same overlay.
4889 2. Within after-strings, strings are sorted so that overlay strings
4890 from overlays with higher priorities come first.
4892 2. Within before-strings, strings are sorted so that overlay
4893 strings from overlays with higher priorities come last.
4895 Value is analogous to strcmp. */
4899 compare_overlay_entries (e1
, e2
)
4902 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4903 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4906 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4908 /* Let after-strings appear in front of before-strings if
4909 they come from different overlays. */
4910 if (EQ (entry1
->overlay
, entry2
->overlay
))
4911 result
= entry1
->after_string_p
? 1 : -1;
4913 result
= entry1
->after_string_p
? -1 : 1;
4915 else if (entry1
->after_string_p
)
4916 /* After-strings sorted in order of decreasing priority. */
4917 result
= entry2
->priority
- entry1
->priority
;
4919 /* Before-strings sorted in order of increasing priority. */
4920 result
= entry1
->priority
- entry2
->priority
;
4926 /* Load the vector IT->overlay_strings with overlay strings from IT's
4927 current buffer position, or from CHARPOS if that is > 0. Set
4928 IT->n_overlays to the total number of overlay strings found.
4930 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4931 a time. On entry into load_overlay_strings,
4932 IT->current.overlay_string_index gives the number of overlay
4933 strings that have already been loaded by previous calls to this
4936 IT->add_overlay_start contains an additional overlay start
4937 position to consider for taking overlay strings from, if non-zero.
4938 This position comes into play when the overlay has an `invisible'
4939 property, and both before and after-strings. When we've skipped to
4940 the end of the overlay, because of its `invisible' property, we
4941 nevertheless want its before-string to appear.
4942 IT->add_overlay_start will contain the overlay start position
4945 Overlay strings are sorted so that after-string strings come in
4946 front of before-string strings. Within before and after-strings,
4947 strings are sorted by overlay priority. See also function
4948 compare_overlay_entries. */
4951 load_overlay_strings (it
, charpos
)
4955 extern Lisp_Object Qwindow
, Qpriority
;
4956 Lisp_Object overlay
, window
, str
, invisible
;
4957 struct Lisp_Overlay
*ov
;
4960 int n
= 0, i
, j
, invis_p
;
4961 struct overlay_entry
*entries
4962 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4965 charpos
= IT_CHARPOS (*it
);
4967 /* Append the overlay string STRING of overlay OVERLAY to vector
4968 `entries' which has size `size' and currently contains `n'
4969 elements. AFTER_P non-zero means STRING is an after-string of
4971 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4974 Lisp_Object priority; \
4978 int new_size = 2 * size; \
4979 struct overlay_entry *old = entries; \
4981 (struct overlay_entry *) alloca (new_size \
4982 * sizeof *entries); \
4983 bcopy (old, entries, size * sizeof *entries); \
4987 entries[n].string = (STRING); \
4988 entries[n].overlay = (OVERLAY); \
4989 priority = Foverlay_get ((OVERLAY), Qpriority); \
4990 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4991 entries[n].after_string_p = (AFTER_P); \
4996 /* Process overlay before the overlay center. */
4997 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4999 XSETMISC (overlay
, ov
);
5000 xassert (OVERLAYP (overlay
));
5001 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5002 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5007 /* Skip this overlay if it doesn't start or end at IT's current
5009 if (end
!= charpos
&& start
!= charpos
)
5012 /* Skip this overlay if it doesn't apply to IT->w. */
5013 window
= Foverlay_get (overlay
, Qwindow
);
5014 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5017 /* If the text ``under'' the overlay is invisible, both before-
5018 and after-strings from this overlay are visible; start and
5019 end position are indistinguishable. */
5020 invisible
= Foverlay_get (overlay
, Qinvisible
);
5021 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5023 /* If overlay has a non-empty before-string, record it. */
5024 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5025 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5027 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5029 /* If overlay has a non-empty after-string, record it. */
5030 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5031 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5033 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5036 /* Process overlays after the overlay center. */
5037 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5039 XSETMISC (overlay
, ov
);
5040 xassert (OVERLAYP (overlay
));
5041 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5042 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5044 if (start
> charpos
)
5047 /* Skip this overlay if it doesn't start or end at IT's current
5049 if (end
!= charpos
&& start
!= charpos
)
5052 /* Skip this overlay if it doesn't apply to IT->w. */
5053 window
= Foverlay_get (overlay
, Qwindow
);
5054 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5057 /* If the text ``under'' the overlay is invisible, it has a zero
5058 dimension, and both before- and after-strings apply. */
5059 invisible
= Foverlay_get (overlay
, Qinvisible
);
5060 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5062 /* If overlay has a non-empty before-string, record it. */
5063 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5064 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5066 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5068 /* If overlay has a non-empty after-string, record it. */
5069 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5070 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5072 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5075 #undef RECORD_OVERLAY_STRING
5079 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5081 /* Record the total number of strings to process. */
5082 it
->n_overlay_strings
= n
;
5084 /* IT->current.overlay_string_index is the number of overlay strings
5085 that have already been consumed by IT. Copy some of the
5086 remaining overlay strings to IT->overlay_strings. */
5088 j
= it
->current
.overlay_string_index
;
5089 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5091 it
->overlay_strings
[i
] = entries
[j
].string
;
5092 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5099 /* Get the first chunk of overlay strings at IT's current buffer
5100 position, or at CHARPOS if that is > 0. Value is non-zero if at
5101 least one overlay string was found. */
5104 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5109 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5110 process. This fills IT->overlay_strings with strings, and sets
5111 IT->n_overlay_strings to the total number of strings to process.
5112 IT->pos.overlay_string_index has to be set temporarily to zero
5113 because load_overlay_strings needs this; it must be set to -1
5114 when no overlay strings are found because a zero value would
5115 indicate a position in the first overlay string. */
5116 it
->current
.overlay_string_index
= 0;
5117 load_overlay_strings (it
, charpos
);
5119 /* If we found overlay strings, set up IT to deliver display
5120 elements from the first one. Otherwise set up IT to deliver
5121 from current_buffer. */
5122 if (it
->n_overlay_strings
)
5124 /* Make sure we know settings in current_buffer, so that we can
5125 restore meaningful values when we're done with the overlay
5128 compute_stop_pos (it
);
5129 xassert (it
->face_id
>= 0);
5131 /* Save IT's settings. They are restored after all overlay
5132 strings have been processed. */
5133 xassert (!compute_stop_p
|| it
->sp
== 0);
5135 /* When called from handle_stop, there might be an empty display
5136 string loaded. In that case, don't bother saving it. */
5137 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5140 /* Set up IT to deliver display elements from the first overlay
5142 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5143 it
->string
= it
->overlay_strings
[0];
5144 it
->from_overlay
= Qnil
;
5145 it
->stop_charpos
= 0;
5146 xassert (STRINGP (it
->string
));
5147 it
->end_charpos
= SCHARS (it
->string
);
5148 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5149 it
->method
= GET_FROM_STRING
;
5153 it
->current
.overlay_string_index
= -1;
5158 get_overlay_strings (it
, charpos
)
5163 it
->method
= GET_FROM_BUFFER
;
5165 (void) get_overlay_strings_1 (it
, charpos
, 1);
5169 /* Value is non-zero if we found at least one overlay string. */
5170 return STRINGP (it
->string
);
5175 /***********************************************************************
5176 Saving and restoring state
5177 ***********************************************************************/
5179 /* Save current settings of IT on IT->stack. Called, for example,
5180 before setting up IT for an overlay string, to be able to restore
5181 IT's settings to what they were after the overlay string has been
5188 struct iterator_stack_entry
*p
;
5190 xassert (it
->sp
< IT_STACK_SIZE
);
5191 p
= it
->stack
+ it
->sp
;
5193 p
->stop_charpos
= it
->stop_charpos
;
5194 p
->prev_stop
= it
->prev_stop
;
5195 p
->base_level_stop
= it
->base_level_stop
;
5196 p
->cmp_it
= it
->cmp_it
;
5197 xassert (it
->face_id
>= 0);
5198 p
->face_id
= it
->face_id
;
5199 p
->string
= it
->string
;
5200 p
->method
= it
->method
;
5201 p
->from_overlay
= it
->from_overlay
;
5204 case GET_FROM_IMAGE
:
5205 p
->u
.image
.object
= it
->object
;
5206 p
->u
.image
.image_id
= it
->image_id
;
5207 p
->u
.image
.slice
= it
->slice
;
5209 case GET_FROM_STRETCH
:
5210 p
->u
.stretch
.object
= it
->object
;
5213 p
->position
= it
->position
;
5214 p
->current
= it
->current
;
5215 p
->end_charpos
= it
->end_charpos
;
5216 p
->string_nchars
= it
->string_nchars
;
5218 p
->multibyte_p
= it
->multibyte_p
;
5219 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5220 p
->space_width
= it
->space_width
;
5221 p
->font_height
= it
->font_height
;
5222 p
->voffset
= it
->voffset
;
5223 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5224 p
->display_ellipsis_p
= 0;
5225 p
->line_wrap
= it
->line_wrap
;
5230 /* Restore IT's settings from IT->stack. Called, for example, when no
5231 more overlay strings must be processed, and we return to delivering
5232 display elements from a buffer, or when the end of a string from a
5233 `display' property is reached and we return to delivering display
5234 elements from an overlay string, or from a buffer. */
5240 struct iterator_stack_entry
*p
;
5242 xassert (it
->sp
> 0);
5244 p
= it
->stack
+ it
->sp
;
5245 it
->stop_charpos
= p
->stop_charpos
;
5246 it
->prev_stop
= p
->prev_stop
;
5247 it
->base_level_stop
= p
->base_level_stop
;
5248 it
->cmp_it
= p
->cmp_it
;
5249 it
->face_id
= p
->face_id
;
5250 it
->current
= p
->current
;
5251 it
->position
= p
->position
;
5252 it
->string
= p
->string
;
5253 it
->from_overlay
= p
->from_overlay
;
5254 if (NILP (it
->string
))
5255 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5256 it
->method
= p
->method
;
5259 case GET_FROM_IMAGE
:
5260 it
->image_id
= p
->u
.image
.image_id
;
5261 it
->object
= p
->u
.image
.object
;
5262 it
->slice
= p
->u
.image
.slice
;
5264 case GET_FROM_STRETCH
:
5265 it
->object
= p
->u
.comp
.object
;
5267 case GET_FROM_BUFFER
:
5268 it
->object
= it
->w
->buffer
;
5270 case GET_FROM_STRING
:
5271 it
->object
= it
->string
;
5273 case GET_FROM_DISPLAY_VECTOR
:
5275 it
->method
= GET_FROM_C_STRING
;
5276 else if (STRINGP (it
->string
))
5277 it
->method
= GET_FROM_STRING
;
5280 it
->method
= GET_FROM_BUFFER
;
5281 it
->object
= it
->w
->buffer
;
5284 it
->end_charpos
= p
->end_charpos
;
5285 it
->string_nchars
= p
->string_nchars
;
5287 it
->multibyte_p
= p
->multibyte_p
;
5288 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5289 it
->space_width
= p
->space_width
;
5290 it
->font_height
= p
->font_height
;
5291 it
->voffset
= p
->voffset
;
5292 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5293 it
->line_wrap
= p
->line_wrap
;
5298 /***********************************************************************
5300 ***********************************************************************/
5302 /* Set IT's current position to the previous line start. */
5305 back_to_previous_line_start (it
)
5308 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5309 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5313 /* Move IT to the next line start.
5315 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5316 we skipped over part of the text (as opposed to moving the iterator
5317 continuously over the text). Otherwise, don't change the value
5320 Newlines may come from buffer text, overlay strings, or strings
5321 displayed via the `display' property. That's the reason we can't
5322 simply use find_next_newline_no_quit.
5324 Note that this function may not skip over invisible text that is so
5325 because of text properties and immediately follows a newline. If
5326 it would, function reseat_at_next_visible_line_start, when called
5327 from set_iterator_to_next, would effectively make invisible
5328 characters following a newline part of the wrong glyph row, which
5329 leads to wrong cursor motion. */
5332 forward_to_next_line_start (it
, skipped_p
)
5336 int old_selective
, newline_found_p
, n
;
5337 const int MAX_NEWLINE_DISTANCE
= 500;
5339 /* If already on a newline, just consume it to avoid unintended
5340 skipping over invisible text below. */
5341 if (it
->what
== IT_CHARACTER
5343 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5345 set_iterator_to_next (it
, 0);
5350 /* Don't handle selective display in the following. It's (a)
5351 unnecessary because it's done by the caller, and (b) leads to an
5352 infinite recursion because next_element_from_ellipsis indirectly
5353 calls this function. */
5354 old_selective
= it
->selective
;
5357 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5358 from buffer text. */
5359 for (n
= newline_found_p
= 0;
5360 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5361 n
+= STRINGP (it
->string
) ? 0 : 1)
5363 if (!get_next_display_element (it
))
5365 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5366 set_iterator_to_next (it
, 0);
5369 /* If we didn't find a newline near enough, see if we can use a
5371 if (!newline_found_p
)
5373 int start
= IT_CHARPOS (*it
);
5374 int limit
= find_next_newline_no_quit (start
, 1);
5377 xassert (!STRINGP (it
->string
));
5379 /* If there isn't any `display' property in sight, and no
5380 overlays, we can just use the position of the newline in
5382 if (it
->stop_charpos
>= limit
5383 || ((pos
= Fnext_single_property_change (make_number (start
),
5385 Qnil
, make_number (limit
)),
5387 && next_overlay_change (start
) == ZV
))
5389 IT_CHARPOS (*it
) = limit
;
5390 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5391 *skipped_p
= newline_found_p
= 1;
5395 while (get_next_display_element (it
)
5396 && !newline_found_p
)
5398 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5399 set_iterator_to_next (it
, 0);
5404 it
->selective
= old_selective
;
5405 return newline_found_p
;
5409 /* Set IT's current position to the previous visible line start. Skip
5410 invisible text that is so either due to text properties or due to
5411 selective display. Caution: this does not change IT->current_x and
5415 back_to_previous_visible_line_start (it
)
5418 while (IT_CHARPOS (*it
) > BEGV
)
5420 back_to_previous_line_start (it
);
5422 if (IT_CHARPOS (*it
) <= BEGV
)
5425 /* If selective > 0, then lines indented more than its value are
5427 if (it
->selective
> 0
5428 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5429 (double) it
->selective
)) /* iftc */
5432 /* Check the newline before point for invisibility. */
5435 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5436 Qinvisible
, it
->window
);
5437 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5441 if (IT_CHARPOS (*it
) <= BEGV
)
5448 Lisp_Object val
, overlay
;
5450 /* If newline is part of a composition, continue from start of composition */
5451 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5452 && beg
< IT_CHARPOS (*it
))
5455 /* If newline is replaced by a display property, find start of overlay
5456 or interval and continue search from that point. */
5458 pos
= --IT_CHARPOS (it2
);
5461 it2
.string_from_display_prop_p
= 0;
5462 if (handle_display_prop (&it2
) == HANDLED_RETURN
5463 && !NILP (val
= get_char_property_and_overlay
5464 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5465 && (OVERLAYP (overlay
)
5466 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5467 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5470 /* Newline is not replaced by anything -- so we are done. */
5476 IT_CHARPOS (*it
) = beg
;
5477 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5481 it
->continuation_lines_width
= 0;
5483 xassert (IT_CHARPOS (*it
) >= BEGV
);
5484 xassert (IT_CHARPOS (*it
) == BEGV
5485 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5490 /* Reseat iterator IT at the previous visible line start. Skip
5491 invisible text that is so either due to text properties or due to
5492 selective display. At the end, update IT's overlay information,
5493 face information etc. */
5496 reseat_at_previous_visible_line_start (it
)
5499 back_to_previous_visible_line_start (it
);
5500 reseat (it
, it
->current
.pos
, 1);
5505 /* Reseat iterator IT on the next visible line start in the current
5506 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5507 preceding the line start. Skip over invisible text that is so
5508 because of selective display. Compute faces, overlays etc at the
5509 new position. Note that this function does not skip over text that
5510 is invisible because of text properties. */
5513 reseat_at_next_visible_line_start (it
, on_newline_p
)
5517 int newline_found_p
, skipped_p
= 0;
5519 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5521 /* Skip over lines that are invisible because they are indented
5522 more than the value of IT->selective. */
5523 if (it
->selective
> 0)
5524 while (IT_CHARPOS (*it
) < ZV
5525 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5526 (double) it
->selective
)) /* iftc */
5528 xassert (IT_BYTEPOS (*it
) == BEGV
5529 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5530 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5533 /* Position on the newline if that's what's requested. */
5534 if (on_newline_p
&& newline_found_p
)
5536 if (STRINGP (it
->string
))
5538 if (IT_STRING_CHARPOS (*it
) > 0)
5540 --IT_STRING_CHARPOS (*it
);
5541 --IT_STRING_BYTEPOS (*it
);
5544 else if (IT_CHARPOS (*it
) > BEGV
)
5548 reseat (it
, it
->current
.pos
, 0);
5552 reseat (it
, it
->current
.pos
, 0);
5559 /***********************************************************************
5560 Changing an iterator's position
5561 ***********************************************************************/
5563 /* Change IT's current position to POS in current_buffer. If FORCE_P
5564 is non-zero, always check for text properties at the new position.
5565 Otherwise, text properties are only looked up if POS >=
5566 IT->check_charpos of a property. */
5569 reseat (it
, pos
, force_p
)
5571 struct text_pos pos
;
5574 int original_pos
= IT_CHARPOS (*it
);
5576 reseat_1 (it
, pos
, 0);
5578 /* Determine where to check text properties. Avoid doing it
5579 where possible because text property lookup is very expensive. */
5581 || CHARPOS (pos
) > it
->stop_charpos
5582 || CHARPOS (pos
) < original_pos
)
5586 /* For bidi iteration, we need to prime prev_stop and
5587 base_level_stop with our best estimations. */
5588 if (CHARPOS (pos
) < it
->prev_stop
)
5590 handle_stop_backwards (it
, BEGV
);
5591 if (CHARPOS (pos
) < it
->base_level_stop
)
5592 it
->base_level_stop
= 0;
5594 else if (CHARPOS (pos
) > it
->stop_charpos
5595 && it
->stop_charpos
>= BEGV
)
5596 handle_stop_backwards (it
, it
->stop_charpos
);
5603 it
->prev_stop
= it
->base_level_stop
= 0;
5612 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5613 IT->stop_pos to POS, also. */
5616 reseat_1 (it
, pos
, set_stop_p
)
5618 struct text_pos pos
;
5621 /* Don't call this function when scanning a C string. */
5622 xassert (it
->s
== NULL
);
5624 /* POS must be a reasonable value. */
5625 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5627 it
->current
.pos
= it
->position
= pos
;
5628 it
->end_charpos
= ZV
;
5630 it
->current
.dpvec_index
= -1;
5631 it
->current
.overlay_string_index
= -1;
5632 IT_STRING_CHARPOS (*it
) = -1;
5633 IT_STRING_BYTEPOS (*it
) = -1;
5635 it
->string_from_display_prop_p
= 0;
5636 it
->method
= GET_FROM_BUFFER
;
5637 it
->object
= it
->w
->buffer
;
5638 it
->area
= TEXT_AREA
;
5639 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5641 it
->string_from_display_prop_p
= 0;
5642 it
->face_before_selective_p
= 0;
5644 it
->bidi_it
.first_elt
= 1;
5648 it
->stop_charpos
= CHARPOS (pos
);
5649 it
->base_level_stop
= CHARPOS (pos
);
5654 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5655 If S is non-null, it is a C string to iterate over. Otherwise,
5656 STRING gives a Lisp string to iterate over.
5658 If PRECISION > 0, don't return more then PRECISION number of
5659 characters from the string.
5661 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5662 characters have been returned. FIELD_WIDTH < 0 means an infinite
5665 MULTIBYTE = 0 means disable processing of multibyte characters,
5666 MULTIBYTE > 0 means enable it,
5667 MULTIBYTE < 0 means use IT->multibyte_p.
5669 IT must be initialized via a prior call to init_iterator before
5670 calling this function. */
5673 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5678 int precision
, field_width
, multibyte
;
5680 /* No region in strings. */
5681 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5683 /* No text property checks performed by default, but see below. */
5684 it
->stop_charpos
= -1;
5686 /* Set iterator position and end position. */
5687 bzero (&it
->current
, sizeof it
->current
);
5688 it
->current
.overlay_string_index
= -1;
5689 it
->current
.dpvec_index
= -1;
5690 xassert (charpos
>= 0);
5692 /* If STRING is specified, use its multibyteness, otherwise use the
5693 setting of MULTIBYTE, if specified. */
5695 it
->multibyte_p
= multibyte
> 0;
5699 xassert (STRINGP (string
));
5700 it
->string
= string
;
5702 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5703 it
->method
= GET_FROM_STRING
;
5704 it
->current
.string_pos
= string_pos (charpos
, string
);
5711 /* Note that we use IT->current.pos, not it->current.string_pos,
5712 for displaying C strings. */
5713 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5714 if (it
->multibyte_p
)
5716 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5717 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5721 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5722 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5725 it
->method
= GET_FROM_C_STRING
;
5728 /* PRECISION > 0 means don't return more than PRECISION characters
5730 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5731 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5733 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5734 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5735 FIELD_WIDTH < 0 means infinite field width. This is useful for
5736 padding with `-' at the end of a mode line. */
5737 if (field_width
< 0)
5738 field_width
= INFINITY
;
5739 if (field_width
> it
->end_charpos
- charpos
)
5740 it
->end_charpos
= charpos
+ field_width
;
5742 /* Use the standard display table for displaying strings. */
5743 if (DISP_TABLE_P (Vstandard_display_table
))
5744 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5746 it
->stop_charpos
= charpos
;
5747 if (s
== NULL
&& it
->multibyte_p
)
5749 EMACS_INT endpos
= SCHARS (it
->string
);
5750 if (endpos
> it
->end_charpos
)
5751 endpos
= it
->end_charpos
;
5752 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
5760 /***********************************************************************
5762 ***********************************************************************/
5764 /* Map enum it_method value to corresponding next_element_from_* function. */
5766 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5768 next_element_from_buffer
,
5769 next_element_from_display_vector
,
5770 next_element_from_string
,
5771 next_element_from_c_string
,
5772 next_element_from_image
,
5773 next_element_from_stretch
5776 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5779 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5780 (possibly with the following characters). */
5782 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
5783 ((IT)->cmp_it.id >= 0 \
5784 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5785 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5786 END_CHARPOS, (IT)->w, \
5787 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5791 /* Load IT's display element fields with information about the next
5792 display element from the current position of IT. Value is zero if
5793 end of buffer (or C string) is reached. */
5795 static struct frame
*last_escape_glyph_frame
= NULL
;
5796 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5797 static int last_escape_glyph_merged_face_id
= 0;
5800 get_next_display_element (it
)
5803 /* Non-zero means that we found a display element. Zero means that
5804 we hit the end of what we iterate over. Performance note: the
5805 function pointer `method' used here turns out to be faster than
5806 using a sequence of if-statements. */
5810 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5812 if (it
->what
== IT_CHARACTER
)
5814 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5815 and only if (a) the resolved directionality of that character
5817 /* FIXME: Do we need an exception for characters from display
5819 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5820 it
->c
= bidi_mirror_char (it
->c
);
5821 /* Map via display table or translate control characters.
5822 IT->c, IT->len etc. have been set to the next character by
5823 the function call above. If we have a display table, and it
5824 contains an entry for IT->c, translate it. Don't do this if
5825 IT->c itself comes from a display table, otherwise we could
5826 end up in an infinite recursion. (An alternative could be to
5827 count the recursion depth of this function and signal an
5828 error when a certain maximum depth is reached.) Is it worth
5830 if (success_p
&& it
->dpvec
== NULL
)
5833 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5834 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5835 nbsp_or_shy
= char_is_other
;
5836 int decoded
= it
->c
;
5839 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5842 struct Lisp_Vector
*v
= XVECTOR (dv
);
5844 /* Return the first character from the display table
5845 entry, if not empty. If empty, don't display the
5846 current character. */
5849 it
->dpvec_char_len
= it
->len
;
5850 it
->dpvec
= v
->contents
;
5851 it
->dpend
= v
->contents
+ v
->size
;
5852 it
->current
.dpvec_index
= 0;
5853 it
->dpvec_face_id
= -1;
5854 it
->saved_face_id
= it
->face_id
;
5855 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5860 set_iterator_to_next (it
, 0);
5865 if (unibyte_display_via_language_environment
5866 && !ASCII_CHAR_P (it
->c
))
5867 decoded
= DECODE_CHAR (unibyte
, it
->c
);
5869 if (it
->c
>= 0x80 && ! NILP (Vnobreak_char_display
))
5871 if (it
->multibyte_p
)
5872 nbsp_or_shy
= (it
->c
== 0xA0 ? char_is_nbsp
5873 : it
->c
== 0xAD ? char_is_soft_hyphen
5875 else if (unibyte_display_via_language_environment
)
5876 nbsp_or_shy
= (decoded
== 0xA0 ? char_is_nbsp
5877 : decoded
== 0xAD ? char_is_soft_hyphen
5881 /* Translate control characters into `\003' or `^C' form.
5882 Control characters coming from a display table entry are
5883 currently not translated because we use IT->dpvec to hold
5884 the translation. This could easily be changed but I
5885 don't believe that it is worth doing.
5887 If it->multibyte_p is nonzero, non-printable non-ASCII
5888 characters are also translated to octal form.
5890 If it->multibyte_p is zero, eight-bit characters that
5891 don't have corresponding multibyte char code are also
5892 translated to octal form. */
5894 ? (it
->area
!= TEXT_AREA
5895 /* In mode line, treat \n, \t like other crl chars. */
5898 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5899 || (it
->c
!= '\n' && it
->c
!= '\t'))
5902 ? ! CHAR_PRINTABLE_P (it
->c
)
5903 : (! unibyte_display_via_language_environment
5905 : (decoded
>= 0x80 && decoded
< 0xA0))))))
5907 /* IT->c is a control character which must be displayed
5908 either as '\003' or as `^C' where the '\\' and '^'
5909 can be defined in the display table. Fill
5910 IT->ctl_chars with glyphs for what we have to
5911 display. Then, set IT->dpvec to these glyphs. */
5914 int face_id
, lface_id
= 0 ;
5917 /* Handle control characters with ^. */
5919 if (it
->c
< 128 && it
->ctl_arrow_p
)
5923 g
= '^'; /* default glyph for Control */
5924 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5926 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5927 && GLYPH_CODE_CHAR_VALID_P (gc
))
5929 g
= GLYPH_CODE_CHAR (gc
);
5930 lface_id
= GLYPH_CODE_FACE (gc
);
5934 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5936 else if (it
->f
== last_escape_glyph_frame
5937 && it
->face_id
== last_escape_glyph_face_id
)
5939 face_id
= last_escape_glyph_merged_face_id
;
5943 /* Merge the escape-glyph face into the current face. */
5944 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5946 last_escape_glyph_frame
= it
->f
;
5947 last_escape_glyph_face_id
= it
->face_id
;
5948 last_escape_glyph_merged_face_id
= face_id
;
5951 XSETINT (it
->ctl_chars
[0], g
);
5952 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5954 goto display_control
;
5957 /* Handle non-break space in the mode where it only gets
5960 if (EQ (Vnobreak_char_display
, Qt
)
5961 && nbsp_or_shy
== char_is_nbsp
)
5963 /* Merge the no-break-space face into the current face. */
5964 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5968 XSETINT (it
->ctl_chars
[0], ' ');
5970 goto display_control
;
5973 /* Handle sequences that start with the "escape glyph". */
5975 /* the default escape glyph is \. */
5976 escape_glyph
= '\\';
5979 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5980 && GLYPH_CODE_CHAR_VALID_P (gc
))
5982 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5983 lface_id
= GLYPH_CODE_FACE (gc
);
5987 /* The display table specified a face.
5988 Merge it into face_id and also into escape_glyph. */
5989 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5992 else if (it
->f
== last_escape_glyph_frame
5993 && it
->face_id
== last_escape_glyph_face_id
)
5995 face_id
= last_escape_glyph_merged_face_id
;
5999 /* Merge the escape-glyph face into the current face. */
6000 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6002 last_escape_glyph_frame
= it
->f
;
6003 last_escape_glyph_face_id
= it
->face_id
;
6004 last_escape_glyph_merged_face_id
= face_id
;
6007 /* Handle soft hyphens in the mode where they only get
6010 if (EQ (Vnobreak_char_display
, Qt
)
6011 && nbsp_or_shy
== char_is_soft_hyphen
)
6014 XSETINT (it
->ctl_chars
[0], '-');
6016 goto display_control
;
6019 /* Handle non-break space and soft hyphen
6020 with the escape glyph. */
6024 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6025 it
->c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
6026 XSETINT (it
->ctl_chars
[1], it
->c
);
6028 goto display_control
;
6032 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
6036 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
6037 if (CHAR_BYTE8_P (it
->c
))
6039 str
[0] = CHAR_TO_BYTE8 (it
->c
);
6042 else if (it
->c
< 256)
6049 /* It's an invalid character, which shouldn't
6050 happen actually, but due to bugs it may
6051 happen. Let's print the char as is, there's
6052 not much meaningful we can do with it. */
6054 str
[1] = it
->c
>> 8;
6055 str
[2] = it
->c
>> 16;
6056 str
[3] = it
->c
>> 24;
6060 for (i
= 0; i
< len
; i
++)
6063 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
6064 /* Insert three more glyphs into IT->ctl_chars for
6065 the octal display of the character. */
6066 g
= ((str
[i
] >> 6) & 7) + '0';
6067 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
6068 g
= ((str
[i
] >> 3) & 7) + '0';
6069 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
6070 g
= (str
[i
] & 7) + '0';
6071 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
6077 /* Set up IT->dpvec and return first character from it. */
6078 it
->dpvec_char_len
= it
->len
;
6079 it
->dpvec
= it
->ctl_chars
;
6080 it
->dpend
= it
->dpvec
+ ctl_len
;
6081 it
->current
.dpvec_index
= 0;
6082 it
->dpvec_face_id
= face_id
;
6083 it
->saved_face_id
= it
->face_id
;
6084 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6091 #ifdef HAVE_WINDOW_SYSTEM
6092 /* Adjust face id for a multibyte character. There are no multibyte
6093 character in unibyte text. */
6094 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6097 && FRAME_WINDOW_P (it
->f
))
6099 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6101 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6103 /* Automatic composition with glyph-string. */
6104 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6106 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6110 int pos
= (it
->s
? -1
6111 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6112 : IT_CHARPOS (*it
));
6114 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
6119 /* Is this character the last one of a run of characters with
6120 box? If yes, set IT->end_of_box_run_p to 1. */
6124 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6126 int face_id
= underlying_face_id (it
);
6127 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6131 if (face
->box
== FACE_NO_BOX
)
6133 /* If the box comes from face properties in a
6134 display string, check faces in that string. */
6135 int string_face_id
= face_after_it_pos (it
);
6136 it
->end_of_box_run_p
6137 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6140 /* Otherwise, the box comes from the underlying face.
6141 If this is the last string character displayed, check
6142 the next buffer location. */
6143 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6144 && (it
->current
.overlay_string_index
6145 == it
->n_overlay_strings
- 1))
6149 struct text_pos pos
= it
->current
.pos
;
6150 INC_TEXT_POS (pos
, it
->multibyte_p
);
6152 next_face_id
= face_at_buffer_position
6153 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6154 it
->region_end_charpos
, &ignore
,
6155 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6157 it
->end_of_box_run_p
6158 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6165 int face_id
= face_after_it_pos (it
);
6166 it
->end_of_box_run_p
6167 = (face_id
!= it
->face_id
6168 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6172 /* Value is 0 if end of buffer or string reached. */
6177 /* Move IT to the next display element.
6179 RESEAT_P non-zero means if called on a newline in buffer text,
6180 skip to the next visible line start.
6182 Functions get_next_display_element and set_iterator_to_next are
6183 separate because I find this arrangement easier to handle than a
6184 get_next_display_element function that also increments IT's
6185 position. The way it is we can first look at an iterator's current
6186 display element, decide whether it fits on a line, and if it does,
6187 increment the iterator position. The other way around we probably
6188 would either need a flag indicating whether the iterator has to be
6189 incremented the next time, or we would have to implement a
6190 decrement position function which would not be easy to write. */
6193 set_iterator_to_next (it
, reseat_p
)
6197 /* Reset flags indicating start and end of a sequence of characters
6198 with box. Reset them at the start of this function because
6199 moving the iterator to a new position might set them. */
6200 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6204 case GET_FROM_BUFFER
:
6205 /* The current display element of IT is a character from
6206 current_buffer. Advance in the buffer, and maybe skip over
6207 invisible lines that are so because of selective display. */
6208 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6209 reseat_at_next_visible_line_start (it
, 0);
6210 else if (it
->cmp_it
.id
>= 0)
6212 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6213 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6214 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6215 it
->cmp_it
.from
= it
->cmp_it
.to
;
6219 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6220 IT_BYTEPOS (*it
), it
->stop_charpos
,
6226 xassert (it
->len
!= 0);
6230 IT_BYTEPOS (*it
) += it
->len
;
6231 IT_CHARPOS (*it
) += 1;
6235 /* If this is a new paragraph, determine its base
6236 direction (a.k.a. its base embedding level). */
6237 if (it
->bidi_it
.new_paragraph
)
6239 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6242 if (it
->bidi_it
.paragraph_dir
== R2L
)
6243 it
->glyph_row
->reversed_p
= 1;
6245 it
->glyph_row
->reversed_p
= 0;
6248 bidi_get_next_char_visually (&it
->bidi_it
);
6249 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6250 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6252 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6256 case GET_FROM_C_STRING
:
6257 /* Current display element of IT is from a C string. */
6258 IT_BYTEPOS (*it
) += it
->len
;
6259 IT_CHARPOS (*it
) += 1;
6262 case GET_FROM_DISPLAY_VECTOR
:
6263 /* Current display element of IT is from a display table entry.
6264 Advance in the display table definition. Reset it to null if
6265 end reached, and continue with characters from buffers/
6267 ++it
->current
.dpvec_index
;
6269 /* Restore face of the iterator to what they were before the
6270 display vector entry (these entries may contain faces). */
6271 it
->face_id
= it
->saved_face_id
;
6273 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6275 int recheck_faces
= it
->ellipsis_p
;
6278 it
->method
= GET_FROM_C_STRING
;
6279 else if (STRINGP (it
->string
))
6280 it
->method
= GET_FROM_STRING
;
6283 it
->method
= GET_FROM_BUFFER
;
6284 it
->object
= it
->w
->buffer
;
6288 it
->current
.dpvec_index
= -1;
6290 /* Skip over characters which were displayed via IT->dpvec. */
6291 if (it
->dpvec_char_len
< 0)
6292 reseat_at_next_visible_line_start (it
, 1);
6293 else if (it
->dpvec_char_len
> 0)
6295 if (it
->method
== GET_FROM_STRING
6296 && it
->n_overlay_strings
> 0)
6297 it
->ignore_overlay_strings_at_pos_p
= 1;
6298 it
->len
= it
->dpvec_char_len
;
6299 set_iterator_to_next (it
, reseat_p
);
6302 /* Maybe recheck faces after display vector */
6304 it
->stop_charpos
= IT_CHARPOS (*it
);
6308 case GET_FROM_STRING
:
6309 /* Current display element is a character from a Lisp string. */
6310 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6311 if (it
->cmp_it
.id
>= 0)
6313 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6314 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6315 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6316 it
->cmp_it
.from
= it
->cmp_it
.to
;
6320 composition_compute_stop_pos (&it
->cmp_it
,
6321 IT_STRING_CHARPOS (*it
),
6322 IT_STRING_BYTEPOS (*it
),
6323 it
->stop_charpos
, it
->string
);
6328 IT_STRING_BYTEPOS (*it
) += it
->len
;
6329 IT_STRING_CHARPOS (*it
) += 1;
6332 consider_string_end
:
6334 if (it
->current
.overlay_string_index
>= 0)
6336 /* IT->string is an overlay string. Advance to the
6337 next, if there is one. */
6338 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6341 next_overlay_string (it
);
6343 setup_for_ellipsis (it
, 0);
6348 /* IT->string is not an overlay string. If we reached
6349 its end, and there is something on IT->stack, proceed
6350 with what is on the stack. This can be either another
6351 string, this time an overlay string, or a buffer. */
6352 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6356 if (it
->method
== GET_FROM_STRING
)
6357 goto consider_string_end
;
6362 case GET_FROM_IMAGE
:
6363 case GET_FROM_STRETCH
:
6364 /* The position etc with which we have to proceed are on
6365 the stack. The position may be at the end of a string,
6366 if the `display' property takes up the whole string. */
6367 xassert (it
->sp
> 0);
6369 if (it
->method
== GET_FROM_STRING
)
6370 goto consider_string_end
;
6374 /* There are no other methods defined, so this should be a bug. */
6378 xassert (it
->method
!= GET_FROM_STRING
6379 || (STRINGP (it
->string
)
6380 && IT_STRING_CHARPOS (*it
) >= 0));
6383 /* Load IT's display element fields with information about the next
6384 display element which comes from a display table entry or from the
6385 result of translating a control character to one of the forms `^C'
6388 IT->dpvec holds the glyphs to return as characters.
6389 IT->saved_face_id holds the face id before the display vector--it
6390 is restored into IT->face_id in set_iterator_to_next. */
6393 next_element_from_display_vector (it
)
6399 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6401 it
->face_id
= it
->saved_face_id
;
6403 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6404 That seemed totally bogus - so I changed it... */
6405 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6407 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6409 it
->c
= GLYPH_CODE_CHAR (gc
);
6410 it
->len
= CHAR_BYTES (it
->c
);
6412 /* The entry may contain a face id to use. Such a face id is
6413 the id of a Lisp face, not a realized face. A face id of
6414 zero means no face is specified. */
6415 if (it
->dpvec_face_id
>= 0)
6416 it
->face_id
= it
->dpvec_face_id
;
6419 int lface_id
= GLYPH_CODE_FACE (gc
);
6421 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6426 /* Display table entry is invalid. Return a space. */
6427 it
->c
= ' ', it
->len
= 1;
6429 /* Don't change position and object of the iterator here. They are
6430 still the values of the character that had this display table
6431 entry or was translated, and that's what we want. */
6432 it
->what
= IT_CHARACTER
;
6437 /* Load IT with the next display element from Lisp string IT->string.
6438 IT->current.string_pos is the current position within the string.
6439 If IT->current.overlay_string_index >= 0, the Lisp string is an
6443 next_element_from_string (it
)
6446 struct text_pos position
;
6448 xassert (STRINGP (it
->string
));
6449 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6450 position
= it
->current
.string_pos
;
6452 /* Time to check for invisible text? */
6453 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6454 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6458 /* Since a handler may have changed IT->method, we must
6460 return GET_NEXT_DISPLAY_ELEMENT (it
);
6463 if (it
->current
.overlay_string_index
>= 0)
6465 /* Get the next character from an overlay string. In overlay
6466 strings, There is no field width or padding with spaces to
6468 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6473 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6474 IT_STRING_BYTEPOS (*it
), SCHARS (it
->string
))
6475 && next_element_from_composition (it
))
6479 else if (STRING_MULTIBYTE (it
->string
))
6481 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6482 const unsigned char *s
= (SDATA (it
->string
)
6483 + IT_STRING_BYTEPOS (*it
));
6484 it
->c
= string_char_and_length (s
, &it
->len
);
6488 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6494 /* Get the next character from a Lisp string that is not an
6495 overlay string. Such strings come from the mode line, for
6496 example. We may have to pad with spaces, or truncate the
6497 string. See also next_element_from_c_string. */
6498 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6503 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6505 /* Pad with spaces. */
6506 it
->c
= ' ', it
->len
= 1;
6507 CHARPOS (position
) = BYTEPOS (position
) = -1;
6509 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6510 IT_STRING_BYTEPOS (*it
), it
->string_nchars
)
6511 && next_element_from_composition (it
))
6515 else if (STRING_MULTIBYTE (it
->string
))
6517 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6518 const unsigned char *s
= (SDATA (it
->string
)
6519 + IT_STRING_BYTEPOS (*it
));
6520 it
->c
= string_char_and_length (s
, &it
->len
);
6524 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6529 /* Record what we have and where it came from. */
6530 it
->what
= IT_CHARACTER
;
6531 it
->object
= it
->string
;
6532 it
->position
= position
;
6537 /* Load IT with next display element from C string IT->s.
6538 IT->string_nchars is the maximum number of characters to return
6539 from the string. IT->end_charpos may be greater than
6540 IT->string_nchars when this function is called, in which case we
6541 may have to return padding spaces. Value is zero if end of string
6542 reached, including padding spaces. */
6545 next_element_from_c_string (it
)
6551 it
->what
= IT_CHARACTER
;
6552 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6555 /* IT's position can be greater IT->string_nchars in case a field
6556 width or precision has been specified when the iterator was
6558 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6560 /* End of the game. */
6564 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6566 /* Pad with spaces. */
6567 it
->c
= ' ', it
->len
= 1;
6568 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6570 else if (it
->multibyte_p
)
6572 /* Implementation note: The calls to strlen apparently aren't a
6573 performance problem because there is no noticeable performance
6574 difference between Emacs running in unibyte or multibyte mode. */
6575 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6576 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6579 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6585 /* Set up IT to return characters from an ellipsis, if appropriate.
6586 The definition of the ellipsis glyphs may come from a display table
6587 entry. This function fills IT with the first glyph from the
6588 ellipsis if an ellipsis is to be displayed. */
6591 next_element_from_ellipsis (it
)
6594 if (it
->selective_display_ellipsis_p
)
6595 setup_for_ellipsis (it
, it
->len
);
6598 /* The face at the current position may be different from the
6599 face we find after the invisible text. Remember what it
6600 was in IT->saved_face_id, and signal that it's there by
6601 setting face_before_selective_p. */
6602 it
->saved_face_id
= it
->face_id
;
6603 it
->method
= GET_FROM_BUFFER
;
6604 it
->object
= it
->w
->buffer
;
6605 reseat_at_next_visible_line_start (it
, 1);
6606 it
->face_before_selective_p
= 1;
6609 return GET_NEXT_DISPLAY_ELEMENT (it
);
6613 /* Deliver an image display element. The iterator IT is already
6614 filled with image information (done in handle_display_prop). Value
6619 next_element_from_image (it
)
6622 it
->what
= IT_IMAGE
;
6627 /* Fill iterator IT with next display element from a stretch glyph
6628 property. IT->object is the value of the text property. Value is
6632 next_element_from_stretch (it
)
6635 it
->what
= IT_STRETCH
;
6639 /* Scan forward from CHARPOS in the current buffer, until we find a
6640 stop position > current IT's position. Then handle the stop
6641 position before that. This is called when we bump into a stop
6642 position while reordering bidirectional text. */
6645 handle_stop_backwards (it
, charpos
)
6649 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6650 struct display_pos save_current
= it
->current
;
6651 struct text_pos save_position
= it
->position
;
6652 struct text_pos pos1
;
6653 EMACS_INT next_stop
;
6655 /* Scan in strict logical order. */
6659 it
->prev_stop
= charpos
;
6660 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6661 reseat_1 (it
, pos1
, 0);
6662 compute_stop_pos (it
);
6663 /* We must advance forward, right? */
6664 if (it
->stop_charpos
<= it
->prev_stop
)
6666 charpos
= it
->stop_charpos
;
6668 while (charpos
<= where_we_are
);
6670 next_stop
= it
->stop_charpos
;
6671 it
->stop_charpos
= it
->prev_stop
;
6673 it
->current
= save_current
;
6674 it
->position
= save_position
;
6676 it
->stop_charpos
= next_stop
;
6679 /* Load IT with the next display element from current_buffer. Value
6680 is zero if end of buffer reached. IT->stop_charpos is the next
6681 position at which to stop and check for text properties or buffer
6685 next_element_from_buffer (it
)
6690 xassert (IT_CHARPOS (*it
) >= BEGV
);
6692 /* With bidi reordering, the character to display might not be the
6693 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6694 we were reseat()ed to a new buffer position, which is potentially
6695 a different paragraph. */
6696 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6698 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6699 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6700 /* If we are at the beginning of a line, we can produce the next
6701 element right away. */
6702 if (it
->bidi_it
.bytepos
== BEGV_BYTE
6703 /* FIXME: Should support all Unicode line separators. */
6704 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6705 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6707 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6708 /* If the paragraph base direction is R2L, its glyphs should
6712 if (it
->bidi_it
.paragraph_dir
== R2L
)
6713 it
->glyph_row
->reversed_p
= 1;
6715 it
->glyph_row
->reversed_p
= 0;
6717 bidi_get_next_char_visually (&it
->bidi_it
);
6721 int orig_bytepos
= IT_BYTEPOS (*it
);
6723 /* We need to prime the bidi iterator starting at the line's
6724 beginning, before we will be able to produce the next
6726 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6727 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6728 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6729 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6730 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6733 if (it
->bidi_it
.paragraph_dir
== R2L
)
6734 it
->glyph_row
->reversed_p
= 1;
6736 it
->glyph_row
->reversed_p
= 0;
6740 /* Now return to buffer position where we were asked to
6741 get the next display element, and produce that. */
6742 bidi_get_next_char_visually (&it
->bidi_it
);
6744 while (it
->bidi_it
.bytepos
!= orig_bytepos
6745 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6748 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6749 /* Adjust IT's position information to where we ended up. */
6750 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6751 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6752 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6755 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6757 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6759 int overlay_strings_follow_p
;
6761 /* End of the game, except when overlay strings follow that
6762 haven't been returned yet. */
6763 if (it
->overlay_strings_at_end_processed_p
)
6764 overlay_strings_follow_p
= 0;
6767 it
->overlay_strings_at_end_processed_p
= 1;
6768 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6771 if (overlay_strings_follow_p
)
6772 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6776 it
->position
= it
->current
.pos
;
6780 else if (!(!it
->bidi_p
6781 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6782 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6784 /* With bidi non-linear iteration, we could find ourselves
6785 far beyond the last computed stop_charpos, with several
6786 other stop positions in between that we missed. Scan
6787 them all now, in buffer's logical order, until we find
6788 and handle the last stop_charpos that precedes our
6789 current position. */
6790 handle_stop_backwards (it
, it
->stop_charpos
);
6791 return GET_NEXT_DISPLAY_ELEMENT (it
);
6797 /* Take note of the stop position we just moved across,
6798 for when we will move back across it. */
6799 it
->prev_stop
= it
->stop_charpos
;
6800 /* If we are at base paragraph embedding level, take
6801 note of the last stop position seen at this
6803 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6804 it
->base_level_stop
= it
->stop_charpos
;
6807 return GET_NEXT_DISPLAY_ELEMENT (it
);
6811 /* We can sometimes back up for reasons that have nothing
6812 to do with bidi reordering. E.g., compositions. The
6813 code below is only needed when we are above the base
6814 embedding level, so test for that explicitly. */
6815 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6816 && IT_CHARPOS (*it
) < it
->prev_stop
)
6818 if (it
->base_level_stop
<= 0)
6819 it
->base_level_stop
= BEGV
;
6820 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6822 handle_stop_backwards (it
, it
->base_level_stop
);
6823 return GET_NEXT_DISPLAY_ELEMENT (it
);
6827 /* No face changes, overlays etc. in sight, so just return a
6828 character from current_buffer. */
6831 /* Maybe run the redisplay end trigger hook. Performance note:
6832 This doesn't seem to cost measurable time. */
6833 if (it
->redisplay_end_trigger_charpos
6835 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6836 run_redisplay_end_trigger_hook (it
);
6838 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6840 && next_element_from_composition (it
))
6845 /* Get the next character, maybe multibyte. */
6846 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6847 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6848 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6850 it
->c
= *p
, it
->len
= 1;
6852 /* Record what we have and where it came from. */
6853 it
->what
= IT_CHARACTER
;
6854 it
->object
= it
->w
->buffer
;
6855 it
->position
= it
->current
.pos
;
6857 /* Normally we return the character found above, except when we
6858 really want to return an ellipsis for selective display. */
6863 /* A value of selective > 0 means hide lines indented more
6864 than that number of columns. */
6865 if (it
->selective
> 0
6866 && IT_CHARPOS (*it
) + 1 < ZV
6867 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6868 IT_BYTEPOS (*it
) + 1,
6869 (double) it
->selective
)) /* iftc */
6871 success_p
= next_element_from_ellipsis (it
);
6872 it
->dpvec_char_len
= -1;
6875 else if (it
->c
== '\r' && it
->selective
== -1)
6877 /* A value of selective == -1 means that everything from the
6878 CR to the end of the line is invisible, with maybe an
6879 ellipsis displayed for it. */
6880 success_p
= next_element_from_ellipsis (it
);
6881 it
->dpvec_char_len
= -1;
6886 /* Value is zero if end of buffer reached. */
6887 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6892 /* Run the redisplay end trigger hook for IT. */
6895 run_redisplay_end_trigger_hook (it
)
6898 Lisp_Object args
[3];
6900 /* IT->glyph_row should be non-null, i.e. we should be actually
6901 displaying something, or otherwise we should not run the hook. */
6902 xassert (it
->glyph_row
);
6904 /* Set up hook arguments. */
6905 args
[0] = Qredisplay_end_trigger_functions
;
6906 args
[1] = it
->window
;
6907 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6908 it
->redisplay_end_trigger_charpos
= 0;
6910 /* Since we are *trying* to run these functions, don't try to run
6911 them again, even if they get an error. */
6912 it
->w
->redisplay_end_trigger
= Qnil
;
6913 Frun_hook_with_args (3, args
);
6915 /* Notice if it changed the face of the character we are on. */
6916 handle_face_prop (it
);
6920 /* Deliver a composition display element. Unlike the other
6921 next_element_from_XXX, this function is not registered in the array
6922 get_next_element[]. It is called from next_element_from_buffer and
6923 next_element_from_string when necessary. */
6926 next_element_from_composition (it
)
6929 it
->what
= IT_COMPOSITION
;
6930 it
->len
= it
->cmp_it
.nbytes
;
6931 if (STRINGP (it
->string
))
6935 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6936 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6939 it
->position
= it
->current
.string_pos
;
6940 it
->object
= it
->string
;
6941 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6942 IT_STRING_BYTEPOS (*it
), it
->string
);
6948 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6949 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6952 it
->position
= it
->current
.pos
;
6953 it
->object
= it
->w
->buffer
;
6954 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6955 IT_BYTEPOS (*it
), Qnil
);
6962 /***********************************************************************
6963 Moving an iterator without producing glyphs
6964 ***********************************************************************/
6966 /* Check if iterator is at a position corresponding to a valid buffer
6967 position after some move_it_ call. */
6969 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6970 ((it)->method == GET_FROM_STRING \
6971 ? IT_STRING_CHARPOS (*it) == 0 \
6975 /* Move iterator IT to a specified buffer or X position within one
6976 line on the display without producing glyphs.
6978 OP should be a bit mask including some or all of these bits:
6979 MOVE_TO_X: Stop upon reaching x-position TO_X.
6980 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
6981 Regardless of OP's value, stop upon reaching the end of the display line.
6983 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6984 This means, in particular, that TO_X includes window's horizontal
6987 The return value has several possible values that
6988 say what condition caused the scan to stop:
6990 MOVE_POS_MATCH_OR_ZV
6991 - when TO_POS or ZV was reached.
6994 -when TO_X was reached before TO_POS or ZV were reached.
6997 - when we reached the end of the display area and the line must
7001 - when we reached the end of the display area and the line is
7005 - when we stopped at a line end, i.e. a newline or a CR and selective
7008 static enum move_it_result
7009 move_it_in_display_line_to (struct it
*it
,
7010 EMACS_INT to_charpos
, int to_x
,
7011 enum move_operation_enum op
)
7013 enum move_it_result result
= MOVE_UNDEFINED
;
7014 struct glyph_row
*saved_glyph_row
;
7015 struct it wrap_it
, atpos_it
, atx_it
;
7017 enum it_method prev_method
= it
->method
;
7018 EMACS_INT prev_pos
= IT_CHARPOS (*it
);
7020 /* Don't produce glyphs in produce_glyphs. */
7021 saved_glyph_row
= it
->glyph_row
;
7022 it
->glyph_row
= NULL
;
7024 /* Use wrap_it to save a copy of IT wherever a word wrap could
7025 occur. Use atpos_it to save a copy of IT at the desired buffer
7026 position, if found, so that we can scan ahead and check if the
7027 word later overshoots the window edge. Use atx_it similarly, for
7033 #define BUFFER_POS_REACHED_P() \
7034 ((op & MOVE_TO_POS) != 0 \
7035 && BUFFERP (it->object) \
7036 && IT_CHARPOS (*it) == to_charpos \
7037 && (it->method == GET_FROM_BUFFER \
7038 || (it->method == GET_FROM_DISPLAY_VECTOR \
7039 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
7041 /* If there's a line-/wrap-prefix, handle it. */
7042 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
7043 && it
->current_y
< it
->last_visible_y
)
7044 handle_line_prefix (it
);
7048 int x
, i
, ascent
= 0, descent
= 0;
7050 /* Utility macro to reset an iterator with x, ascent, and descent. */
7051 #define IT_RESET_X_ASCENT_DESCENT(IT) \
7052 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
7053 (IT)->max_descent = descent)
7055 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
7057 if ((op
& MOVE_TO_POS
) != 0
7058 && BUFFERP (it
->object
)
7059 && it
->method
== GET_FROM_BUFFER
7060 && (prev_method
== GET_FROM_IMAGE
7061 || prev_method
== GET_FROM_STRETCH
)
7062 /* Passed TO_CHARPOS from left to right. */
7063 && ((prev_pos
< to_charpos
7064 && IT_CHARPOS (*it
) > to_charpos
)
7065 /* Passed TO_CHARPOS from right to left. */
7066 || (prev_pos
> to_charpos
)
7067 && IT_CHARPOS (*it
) < to_charpos
))
7069 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7071 result
= MOVE_POS_MATCH_OR_ZV
;
7074 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7075 /* If wrap_it is valid, the current position might be in a
7076 word that is wrapped. So, save the iterator in
7077 atpos_it and continue to see if wrapping happens. */
7081 prev_method
= it
->method
;
7082 if (it
->method
== GET_FROM_BUFFER
)
7083 prev_pos
= IT_CHARPOS (*it
);
7084 /* Stop when ZV reached.
7085 We used to stop here when TO_CHARPOS reached as well, but that is
7086 too soon if this glyph does not fit on this line. So we handle it
7087 explicitly below. */
7088 if (!get_next_display_element (it
))
7090 result
= MOVE_POS_MATCH_OR_ZV
;
7094 if (it
->line_wrap
== TRUNCATE
)
7096 if (BUFFER_POS_REACHED_P ())
7098 result
= MOVE_POS_MATCH_OR_ZV
;
7104 if (it
->line_wrap
== WORD_WRAP
)
7106 if (IT_DISPLAYING_WHITESPACE (it
))
7110 /* We have reached a glyph that follows one or more
7111 whitespace characters. If the position is
7112 already found, we are done. */
7113 if (atpos_it
.sp
>= 0)
7116 result
= MOVE_POS_MATCH_OR_ZV
;
7122 result
= MOVE_X_REACHED
;
7125 /* Otherwise, we can wrap here. */
7132 /* Remember the line height for the current line, in case
7133 the next element doesn't fit on the line. */
7134 ascent
= it
->max_ascent
;
7135 descent
= it
->max_descent
;
7137 /* The call to produce_glyphs will get the metrics of the
7138 display element IT is loaded with. Record the x-position
7139 before this display element, in case it doesn't fit on the
7143 PRODUCE_GLYPHS (it
);
7145 if (it
->area
!= TEXT_AREA
)
7147 set_iterator_to_next (it
, 1);
7151 /* The number of glyphs we get back in IT->nglyphs will normally
7152 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7153 character on a terminal frame, or (iii) a line end. For the
7154 second case, IT->nglyphs - 1 padding glyphs will be present.
7155 (On X frames, there is only one glyph produced for a
7156 composite character.)
7158 The behavior implemented below means, for continuation lines,
7159 that as many spaces of a TAB as fit on the current line are
7160 displayed there. For terminal frames, as many glyphs of a
7161 multi-glyph character are displayed in the current line, too.
7162 This is what the old redisplay code did, and we keep it that
7163 way. Under X, the whole shape of a complex character must
7164 fit on the line or it will be completely displayed in the
7167 Note that both for tabs and padding glyphs, all glyphs have
7171 /* More than one glyph or glyph doesn't fit on line. All
7172 glyphs have the same width. */
7173 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7175 int x_before_this_char
= x
;
7176 int hpos_before_this_char
= it
->hpos
;
7178 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7180 new_x
= x
+ single_glyph_width
;
7182 /* We want to leave anything reaching TO_X to the caller. */
7183 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7185 if (BUFFER_POS_REACHED_P ())
7187 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7188 goto buffer_pos_reached
;
7189 if (atpos_it
.sp
< 0)
7192 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7197 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7200 result
= MOVE_X_REACHED
;
7206 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7211 if (/* Lines are continued. */
7212 it
->line_wrap
!= TRUNCATE
7213 && (/* And glyph doesn't fit on the line. */
7214 new_x
> it
->last_visible_x
7215 /* Or it fits exactly and we're on a window
7217 || (new_x
== it
->last_visible_x
7218 && FRAME_WINDOW_P (it
->f
))))
7220 if (/* IT->hpos == 0 means the very first glyph
7221 doesn't fit on the line, e.g. a wide image. */
7223 || (new_x
== it
->last_visible_x
7224 && FRAME_WINDOW_P (it
->f
)))
7227 it
->current_x
= new_x
;
7229 /* The character's last glyph just barely fits
7231 if (i
== it
->nglyphs
- 1)
7233 /* If this is the destination position,
7234 return a position *before* it in this row,
7235 now that we know it fits in this row. */
7236 if (BUFFER_POS_REACHED_P ())
7238 if (it
->line_wrap
!= WORD_WRAP
7241 it
->hpos
= hpos_before_this_char
;
7242 it
->current_x
= x_before_this_char
;
7243 result
= MOVE_POS_MATCH_OR_ZV
;
7246 if (it
->line_wrap
== WORD_WRAP
7250 atpos_it
.current_x
= x_before_this_char
;
7251 atpos_it
.hpos
= hpos_before_this_char
;
7255 set_iterator_to_next (it
, 1);
7256 /* On graphical terminals, newlines may
7257 "overflow" into the fringe if
7258 overflow-newline-into-fringe is non-nil.
7259 On text-only terminals, newlines may
7260 overflow into the last glyph on the
7262 if (!FRAME_WINDOW_P (it
->f
)
7263 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7265 if (!get_next_display_element (it
))
7267 result
= MOVE_POS_MATCH_OR_ZV
;
7270 if (BUFFER_POS_REACHED_P ())
7272 if (ITERATOR_AT_END_OF_LINE_P (it
))
7273 result
= MOVE_POS_MATCH_OR_ZV
;
7275 result
= MOVE_LINE_CONTINUED
;
7278 if (ITERATOR_AT_END_OF_LINE_P (it
))
7280 result
= MOVE_NEWLINE_OR_CR
;
7287 IT_RESET_X_ASCENT_DESCENT (it
);
7289 if (wrap_it
.sp
>= 0)
7296 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7298 result
= MOVE_LINE_CONTINUED
;
7302 if (BUFFER_POS_REACHED_P ())
7304 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7305 goto buffer_pos_reached
;
7306 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7309 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7313 if (new_x
> it
->first_visible_x
)
7315 /* Glyph is visible. Increment number of glyphs that
7316 would be displayed. */
7321 if (result
!= MOVE_UNDEFINED
)
7324 else if (BUFFER_POS_REACHED_P ())
7327 IT_RESET_X_ASCENT_DESCENT (it
);
7328 result
= MOVE_POS_MATCH_OR_ZV
;
7331 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7333 /* Stop when TO_X specified and reached. This check is
7334 necessary here because of lines consisting of a line end,
7335 only. The line end will not produce any glyphs and we
7336 would never get MOVE_X_REACHED. */
7337 xassert (it
->nglyphs
== 0);
7338 result
= MOVE_X_REACHED
;
7342 /* Is this a line end? If yes, we're done. */
7343 if (ITERATOR_AT_END_OF_LINE_P (it
))
7345 result
= MOVE_NEWLINE_OR_CR
;
7349 if (it
->method
== GET_FROM_BUFFER
)
7350 prev_pos
= IT_CHARPOS (*it
);
7351 /* The current display element has been consumed. Advance
7353 set_iterator_to_next (it
, 1);
7355 /* Stop if lines are truncated and IT's current x-position is
7356 past the right edge of the window now. */
7357 if (it
->line_wrap
== TRUNCATE
7358 && it
->current_x
>= it
->last_visible_x
)
7360 if (!FRAME_WINDOW_P (it
->f
)
7361 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7363 if (!get_next_display_element (it
)
7364 || BUFFER_POS_REACHED_P ())
7366 result
= MOVE_POS_MATCH_OR_ZV
;
7369 if (ITERATOR_AT_END_OF_LINE_P (it
))
7371 result
= MOVE_NEWLINE_OR_CR
;
7375 result
= MOVE_LINE_TRUNCATED
;
7378 #undef IT_RESET_X_ASCENT_DESCENT
7381 #undef BUFFER_POS_REACHED_P
7383 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7384 restore the saved iterator. */
7385 if (atpos_it
.sp
>= 0)
7387 else if (atx_it
.sp
>= 0)
7392 /* Restore the iterator settings altered at the beginning of this
7394 it
->glyph_row
= saved_glyph_row
;
7398 /* For external use. */
7400 move_it_in_display_line (struct it
*it
,
7401 EMACS_INT to_charpos
, int to_x
,
7402 enum move_operation_enum op
)
7404 if (it
->line_wrap
== WORD_WRAP
7405 && (op
& MOVE_TO_X
))
7407 struct it save_it
= *it
;
7408 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7409 /* When word-wrap is on, TO_X may lie past the end
7410 of a wrapped line. Then it->current is the
7411 character on the next line, so backtrack to the
7412 space before the wrap point. */
7413 if (skip
== MOVE_LINE_CONTINUED
)
7415 int prev_x
= max (it
->current_x
- 1, 0);
7417 move_it_in_display_line_to
7418 (it
, -1, prev_x
, MOVE_TO_X
);
7422 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7426 /* Move IT forward until it satisfies one or more of the criteria in
7427 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7429 OP is a bit-mask that specifies where to stop, and in particular,
7430 which of those four position arguments makes a difference. See the
7431 description of enum move_operation_enum.
7433 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7434 screen line, this function will set IT to the next position >
7438 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7440 int to_charpos
, to_x
, to_y
, to_vpos
;
7443 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7444 int line_height
, line_start_x
= 0, reached
= 0;
7448 if (op
& MOVE_TO_VPOS
)
7450 /* If no TO_CHARPOS and no TO_X specified, stop at the
7451 start of the line TO_VPOS. */
7452 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7454 if (it
->vpos
== to_vpos
)
7460 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7464 /* TO_VPOS >= 0 means stop at TO_X in the line at
7465 TO_VPOS, or at TO_POS, whichever comes first. */
7466 if (it
->vpos
== to_vpos
)
7472 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7474 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7479 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7481 /* We have reached TO_X but not in the line we want. */
7482 skip
= move_it_in_display_line_to (it
, to_charpos
,
7484 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7492 else if (op
& MOVE_TO_Y
)
7494 struct it it_backup
;
7496 if (it
->line_wrap
== WORD_WRAP
)
7499 /* TO_Y specified means stop at TO_X in the line containing
7500 TO_Y---or at TO_CHARPOS if this is reached first. The
7501 problem is that we can't really tell whether the line
7502 contains TO_Y before we have completely scanned it, and
7503 this may skip past TO_X. What we do is to first scan to
7506 If TO_X is not specified, use a TO_X of zero. The reason
7507 is to make the outcome of this function more predictable.
7508 If we didn't use TO_X == 0, we would stop at the end of
7509 the line which is probably not what a caller would expect
7511 skip
= move_it_in_display_line_to
7512 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7513 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7515 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7516 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7518 else if (skip
== MOVE_X_REACHED
)
7520 /* If TO_X was reached, we want to know whether TO_Y is
7521 in the line. We know this is the case if the already
7522 scanned glyphs make the line tall enough. Otherwise,
7523 we must check by scanning the rest of the line. */
7524 line_height
= it
->max_ascent
+ it
->max_descent
;
7525 if (to_y
>= it
->current_y
7526 && to_y
< it
->current_y
+ line_height
)
7532 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7533 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7535 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7536 line_height
= it
->max_ascent
+ it
->max_descent
;
7537 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7539 if (to_y
>= it
->current_y
7540 && to_y
< it
->current_y
+ line_height
)
7542 /* If TO_Y is in this line and TO_X was reached
7543 above, we scanned too far. We have to restore
7544 IT's settings to the ones before skipping. */
7551 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7557 /* Check whether TO_Y is in this line. */
7558 line_height
= it
->max_ascent
+ it
->max_descent
;
7559 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7561 if (to_y
>= it
->current_y
7562 && to_y
< it
->current_y
+ line_height
)
7564 /* When word-wrap is on, TO_X may lie past the end
7565 of a wrapped line. Then it->current is the
7566 character on the next line, so backtrack to the
7567 space before the wrap point. */
7568 if (skip
== MOVE_LINE_CONTINUED
7569 && it
->line_wrap
== WORD_WRAP
)
7571 int prev_x
= max (it
->current_x
- 1, 0);
7573 skip
= move_it_in_display_line_to
7574 (it
, -1, prev_x
, MOVE_TO_X
);
7583 else if (BUFFERP (it
->object
)
7584 && (it
->method
== GET_FROM_BUFFER
7585 || it
->method
== GET_FROM_STRETCH
)
7586 && IT_CHARPOS (*it
) >= to_charpos
)
7587 skip
= MOVE_POS_MATCH_OR_ZV
;
7589 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7593 case MOVE_POS_MATCH_OR_ZV
:
7597 case MOVE_NEWLINE_OR_CR
:
7598 set_iterator_to_next (it
, 1);
7599 it
->continuation_lines_width
= 0;
7602 case MOVE_LINE_TRUNCATED
:
7603 it
->continuation_lines_width
= 0;
7604 reseat_at_next_visible_line_start (it
, 0);
7605 if ((op
& MOVE_TO_POS
) != 0
7606 && IT_CHARPOS (*it
) > to_charpos
)
7613 case MOVE_LINE_CONTINUED
:
7614 /* For continued lines ending in a tab, some of the glyphs
7615 associated with the tab are displayed on the current
7616 line. Since it->current_x does not include these glyphs,
7617 we use it->last_visible_x instead. */
7620 it
->continuation_lines_width
+= it
->last_visible_x
;
7621 /* When moving by vpos, ensure that the iterator really
7622 advances to the next line (bug#847, bug#969). Fixme:
7623 do we need to do this in other circumstances? */
7624 if (it
->current_x
!= it
->last_visible_x
7625 && (op
& MOVE_TO_VPOS
)
7626 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7628 line_start_x
= it
->current_x
+ it
->pixel_width
7629 - it
->last_visible_x
;
7630 set_iterator_to_next (it
, 0);
7634 it
->continuation_lines_width
+= it
->current_x
;
7641 /* Reset/increment for the next run. */
7642 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7643 it
->current_x
= line_start_x
;
7646 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7648 last_height
= it
->max_ascent
+ it
->max_descent
;
7649 last_max_ascent
= it
->max_ascent
;
7650 it
->max_ascent
= it
->max_descent
= 0;
7655 /* On text terminals, we may stop at the end of a line in the middle
7656 of a multi-character glyph. If the glyph itself is continued,
7657 i.e. it is actually displayed on the next line, don't treat this
7658 stopping point as valid; move to the next line instead (unless
7659 that brings us offscreen). */
7660 if (!FRAME_WINDOW_P (it
->f
)
7662 && IT_CHARPOS (*it
) == to_charpos
7663 && it
->what
== IT_CHARACTER
7665 && it
->line_wrap
== WINDOW_WRAP
7666 && it
->current_x
== it
->last_visible_x
- 1
7669 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7671 it
->continuation_lines_width
+= it
->current_x
;
7672 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7673 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7675 last_height
= it
->max_ascent
+ it
->max_descent
;
7676 last_max_ascent
= it
->max_ascent
;
7679 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7683 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7685 If DY > 0, move IT backward at least that many pixels. DY = 0
7686 means move IT backward to the preceding line start or BEGV. This
7687 function may move over more than DY pixels if IT->current_y - DY
7688 ends up in the middle of a line; in this case IT->current_y will be
7689 set to the top of the line moved to. */
7692 move_it_vertically_backward (it
, dy
)
7703 start_pos
= IT_CHARPOS (*it
);
7705 /* Estimate how many newlines we must move back. */
7706 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7708 /* Set the iterator's position that many lines back. */
7709 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7710 back_to_previous_visible_line_start (it
);
7712 /* Reseat the iterator here. When moving backward, we don't want
7713 reseat to skip forward over invisible text, set up the iterator
7714 to deliver from overlay strings at the new position etc. So,
7715 use reseat_1 here. */
7716 reseat_1 (it
, it
->current
.pos
, 1);
7718 /* We are now surely at a line start. */
7719 it
->current_x
= it
->hpos
= 0;
7720 it
->continuation_lines_width
= 0;
7722 /* Move forward and see what y-distance we moved. First move to the
7723 start of the next line so that we get its height. We need this
7724 height to be able to tell whether we reached the specified
7727 it2
.max_ascent
= it2
.max_descent
= 0;
7730 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7731 MOVE_TO_POS
| MOVE_TO_VPOS
);
7733 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7734 xassert (IT_CHARPOS (*it
) >= BEGV
);
7737 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7738 xassert (IT_CHARPOS (*it
) >= BEGV
);
7739 /* H is the actual vertical distance from the position in *IT
7740 and the starting position. */
7741 h
= it2
.current_y
- it
->current_y
;
7742 /* NLINES is the distance in number of lines. */
7743 nlines
= it2
.vpos
- it
->vpos
;
7745 /* Correct IT's y and vpos position
7746 so that they are relative to the starting point. */
7752 /* DY == 0 means move to the start of the screen line. The
7753 value of nlines is > 0 if continuation lines were involved. */
7755 move_it_by_lines (it
, nlines
, 1);
7759 /* The y-position we try to reach, relative to *IT.
7760 Note that H has been subtracted in front of the if-statement. */
7761 int target_y
= it
->current_y
+ h
- dy
;
7762 int y0
= it3
.current_y
;
7763 int y1
= line_bottom_y (&it3
);
7764 int line_height
= y1
- y0
;
7766 /* If we did not reach target_y, try to move further backward if
7767 we can. If we moved too far backward, try to move forward. */
7768 if (target_y
< it
->current_y
7769 /* This is heuristic. In a window that's 3 lines high, with
7770 a line height of 13 pixels each, recentering with point
7771 on the bottom line will try to move -39/2 = 19 pixels
7772 backward. Try to avoid moving into the first line. */
7773 && (it
->current_y
- target_y
7774 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7775 && IT_CHARPOS (*it
) > BEGV
)
7777 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7778 target_y
- it
->current_y
));
7779 dy
= it
->current_y
- target_y
;
7780 goto move_further_back
;
7782 else if (target_y
>= it
->current_y
+ line_height
7783 && IT_CHARPOS (*it
) < ZV
)
7785 /* Should move forward by at least one line, maybe more.
7787 Note: Calling move_it_by_lines can be expensive on
7788 terminal frames, where compute_motion is used (via
7789 vmotion) to do the job, when there are very long lines
7790 and truncate-lines is nil. That's the reason for
7791 treating terminal frames specially here. */
7793 if (!FRAME_WINDOW_P (it
->f
))
7794 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7799 move_it_by_lines (it
, 1, 1);
7801 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7808 /* Move IT by a specified amount of pixel lines DY. DY negative means
7809 move backwards. DY = 0 means move to start of screen line. At the
7810 end, IT will be on the start of a screen line. */
7813 move_it_vertically (it
, dy
)
7818 move_it_vertically_backward (it
, -dy
);
7821 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7822 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7823 MOVE_TO_POS
| MOVE_TO_Y
);
7824 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7826 /* If buffer ends in ZV without a newline, move to the start of
7827 the line to satisfy the post-condition. */
7828 if (IT_CHARPOS (*it
) == ZV
7830 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7831 move_it_by_lines (it
, 0, 0);
7836 /* Move iterator IT past the end of the text line it is in. */
7839 move_it_past_eol (it
)
7842 enum move_it_result rc
;
7844 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7845 if (rc
== MOVE_NEWLINE_OR_CR
)
7846 set_iterator_to_next (it
, 0);
7850 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7851 negative means move up. DVPOS == 0 means move to the start of the
7852 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7853 NEED_Y_P is zero, IT->current_y will be left unchanged.
7855 Further optimization ideas: If we would know that IT->f doesn't use
7856 a face with proportional font, we could be faster for
7857 truncate-lines nil. */
7860 move_it_by_lines (it
, dvpos
, need_y_p
)
7862 int dvpos
, need_y_p
;
7864 struct position pos
;
7866 /* The commented-out optimization uses vmotion on terminals. This
7867 gives bad results, because elements like it->what, on which
7868 callers such as pos_visible_p rely, aren't updated. */
7869 /* if (!FRAME_WINDOW_P (it->f))
7871 struct text_pos textpos;
7873 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7874 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7875 reseat (it, textpos, 1);
7876 it->vpos += pos.vpos;
7877 it->current_y += pos.vpos;
7883 /* DVPOS == 0 means move to the start of the screen line. */
7884 move_it_vertically_backward (it
, 0);
7885 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7886 /* Let next call to line_bottom_y calculate real line height */
7891 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7892 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7893 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7898 int start_charpos
, i
;
7900 /* Start at the beginning of the screen line containing IT's
7901 position. This may actually move vertically backwards,
7902 in case of overlays, so adjust dvpos accordingly. */
7904 move_it_vertically_backward (it
, 0);
7907 /* Go back -DVPOS visible lines and reseat the iterator there. */
7908 start_charpos
= IT_CHARPOS (*it
);
7909 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7910 back_to_previous_visible_line_start (it
);
7911 reseat (it
, it
->current
.pos
, 1);
7913 /* Move further back if we end up in a string or an image. */
7914 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7916 /* First try to move to start of display line. */
7918 move_it_vertically_backward (it
, 0);
7920 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7922 /* If start of line is still in string or image,
7923 move further back. */
7924 back_to_previous_visible_line_start (it
);
7925 reseat (it
, it
->current
.pos
, 1);
7929 it
->current_x
= it
->hpos
= 0;
7931 /* Above call may have moved too far if continuation lines
7932 are involved. Scan forward and see if it did. */
7934 it2
.vpos
= it2
.current_y
= 0;
7935 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7936 it
->vpos
-= it2
.vpos
;
7937 it
->current_y
-= it2
.current_y
;
7938 it
->current_x
= it
->hpos
= 0;
7940 /* If we moved too far back, move IT some lines forward. */
7941 if (it2
.vpos
> -dvpos
)
7943 int delta
= it2
.vpos
+ dvpos
;
7945 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7946 /* Move back again if we got too far ahead. */
7947 if (IT_CHARPOS (*it
) >= start_charpos
)
7953 /* Return 1 if IT points into the middle of a display vector. */
7956 in_display_vector_p (it
)
7959 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7960 && it
->current
.dpvec_index
> 0
7961 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7965 /***********************************************************************
7967 ***********************************************************************/
7970 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7974 add_to_log (format
, arg1
, arg2
)
7976 Lisp_Object arg1
, arg2
;
7978 Lisp_Object args
[3];
7979 Lisp_Object msg
, fmt
;
7982 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7985 /* Do nothing if called asynchronously. Inserting text into
7986 a buffer may call after-change-functions and alike and
7987 that would means running Lisp asynchronously. */
7988 if (handling_signal
)
7992 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7994 args
[0] = fmt
= build_string (format
);
7997 msg
= Fformat (3, args
);
7999 len
= SBYTES (msg
) + 1;
8000 SAFE_ALLOCA (buffer
, char *, len
);
8001 bcopy (SDATA (msg
), buffer
, len
);
8003 message_dolog (buffer
, len
- 1, 1, 0);
8010 /* Output a newline in the *Messages* buffer if "needs" one. */
8013 message_log_maybe_newline ()
8015 if (message_log_need_newline
)
8016 message_dolog ("", 0, 1, 0);
8020 /* Add a string M of length NBYTES to the message log, optionally
8021 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
8022 nonzero, means interpret the contents of M as multibyte. This
8023 function calls low-level routines in order to bypass text property
8024 hooks, etc. which might not be safe to run.
8026 This may GC (insert may run before/after change hooks),
8027 so the buffer M must NOT point to a Lisp string. */
8030 message_dolog (m
, nbytes
, nlflag
, multibyte
)
8032 int nbytes
, nlflag
, multibyte
;
8034 if (!NILP (Vmemory_full
))
8037 if (!NILP (Vmessage_log_max
))
8039 struct buffer
*oldbuf
;
8040 Lisp_Object oldpoint
, oldbegv
, oldzv
;
8041 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
8042 int point_at_end
= 0;
8044 Lisp_Object old_deactivate_mark
, tem
;
8045 struct gcpro gcpro1
;
8047 old_deactivate_mark
= Vdeactivate_mark
;
8048 oldbuf
= current_buffer
;
8049 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
8050 current_buffer
->undo_list
= Qt
;
8052 oldpoint
= message_dolog_marker1
;
8053 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
8054 oldbegv
= message_dolog_marker2
;
8055 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
8056 oldzv
= message_dolog_marker3
;
8057 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
8058 GCPRO1 (old_deactivate_mark
);
8066 BEGV_BYTE
= BEG_BYTE
;
8069 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8071 /* Insert the string--maybe converting multibyte to single byte
8072 or vice versa, so that all the text fits the buffer. */
8074 && NILP (current_buffer
->enable_multibyte_characters
))
8076 int i
, c
, char_bytes
;
8077 unsigned char work
[1];
8079 /* Convert a multibyte string to single-byte
8080 for the *Message* buffer. */
8081 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
8083 c
= string_char_and_length (m
+ i
, &char_bytes
);
8084 work
[0] = (ASCII_CHAR_P (c
)
8086 : multibyte_char_to_unibyte (c
, Qnil
));
8087 insert_1_both (work
, 1, 1, 1, 0, 0);
8090 else if (! multibyte
8091 && ! NILP (current_buffer
->enable_multibyte_characters
))
8093 int i
, c
, char_bytes
;
8094 unsigned char *msg
= (unsigned char *) m
;
8095 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8096 /* Convert a single-byte string to multibyte
8097 for the *Message* buffer. */
8098 for (i
= 0; i
< nbytes
; i
++)
8101 MAKE_CHAR_MULTIBYTE (c
);
8102 char_bytes
= CHAR_STRING (c
, str
);
8103 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
8107 insert_1 (m
, nbytes
, 1, 0, 0);
8111 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
8112 insert_1 ("\n", 1, 1, 0, 0);
8114 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8116 this_bol_byte
= PT_BYTE
;
8118 /* See if this line duplicates the previous one.
8119 If so, combine duplicates. */
8122 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8124 prev_bol_byte
= PT_BYTE
;
8126 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
8127 this_bol
, this_bol_byte
);
8130 del_range_both (prev_bol
, prev_bol_byte
,
8131 this_bol
, this_bol_byte
, 0);
8137 /* If you change this format, don't forget to also
8138 change message_log_check_duplicate. */
8139 sprintf (dupstr
, " [%d times]", dup
);
8140 duplen
= strlen (dupstr
);
8141 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8142 insert_1 (dupstr
, duplen
, 1, 0, 1);
8147 /* If we have more than the desired maximum number of lines
8148 in the *Messages* buffer now, delete the oldest ones.
8149 This is safe because we don't have undo in this buffer. */
8151 if (NATNUMP (Vmessage_log_max
))
8153 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8154 -XFASTINT (Vmessage_log_max
) - 1, 0);
8155 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8158 BEGV
= XMARKER (oldbegv
)->charpos
;
8159 BEGV_BYTE
= marker_byte_position (oldbegv
);
8168 ZV
= XMARKER (oldzv
)->charpos
;
8169 ZV_BYTE
= marker_byte_position (oldzv
);
8173 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8175 /* We can't do Fgoto_char (oldpoint) because it will run some
8177 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8178 XMARKER (oldpoint
)->bytepos
);
8181 unchain_marker (XMARKER (oldpoint
));
8182 unchain_marker (XMARKER (oldbegv
));
8183 unchain_marker (XMARKER (oldzv
));
8185 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8186 set_buffer_internal (oldbuf
);
8188 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8189 message_log_need_newline
= !nlflag
;
8190 Vdeactivate_mark
= old_deactivate_mark
;
8195 /* We are at the end of the buffer after just having inserted a newline.
8196 (Note: We depend on the fact we won't be crossing the gap.)
8197 Check to see if the most recent message looks a lot like the previous one.
8198 Return 0 if different, 1 if the new one should just replace it, or a
8199 value N > 1 if we should also append " [N times]". */
8202 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
8203 int prev_bol
, this_bol
;
8204 int prev_bol_byte
, this_bol_byte
;
8207 int len
= Z_BYTE
- 1 - this_bol_byte
;
8209 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8210 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8212 for (i
= 0; i
< len
; i
++)
8214 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8222 if (*p1
++ == ' ' && *p1
++ == '[')
8225 while (*p1
>= '0' && *p1
<= '9')
8226 n
= n
* 10 + *p1
++ - '0';
8227 if (strncmp (p1
, " times]\n", 8) == 0)
8234 /* Display an echo area message M with a specified length of NBYTES
8235 bytes. The string may include null characters. If M is 0, clear
8236 out any existing message, and let the mini-buffer text show
8239 This may GC, so the buffer M must NOT point to a Lisp string. */
8242 message2 (m
, nbytes
, multibyte
)
8247 /* First flush out any partial line written with print. */
8248 message_log_maybe_newline ();
8250 message_dolog (m
, nbytes
, 1, multibyte
);
8251 message2_nolog (m
, nbytes
, multibyte
);
8255 /* The non-logging counterpart of message2. */
8258 message2_nolog (m
, nbytes
, multibyte
)
8260 int nbytes
, multibyte
;
8262 struct frame
*sf
= SELECTED_FRAME ();
8263 message_enable_multibyte
= multibyte
;
8265 if (FRAME_INITIAL_P (sf
))
8267 if (noninteractive_need_newline
)
8268 putc ('\n', stderr
);
8269 noninteractive_need_newline
= 0;
8271 fwrite (m
, nbytes
, 1, stderr
);
8272 if (cursor_in_echo_area
== 0)
8273 fprintf (stderr
, "\n");
8276 /* A null message buffer means that the frame hasn't really been
8277 initialized yet. Error messages get reported properly by
8278 cmd_error, so this must be just an informative message; toss it. */
8279 else if (INTERACTIVE
8280 && sf
->glyphs_initialized_p
8281 && FRAME_MESSAGE_BUF (sf
))
8283 Lisp_Object mini_window
;
8286 /* Get the frame containing the mini-buffer
8287 that the selected frame is using. */
8288 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8289 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8291 FRAME_SAMPLE_VISIBILITY (f
);
8292 if (FRAME_VISIBLE_P (sf
)
8293 && ! FRAME_VISIBLE_P (f
))
8294 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8298 set_message (m
, Qnil
, nbytes
, multibyte
);
8299 if (minibuffer_auto_raise
)
8300 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8303 clear_message (1, 1);
8305 do_pending_window_change (0);
8306 echo_area_display (1);
8307 do_pending_window_change (0);
8308 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8309 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8314 /* Display an echo area message M with a specified length of NBYTES
8315 bytes. The string may include null characters. If M is not a
8316 string, clear out any existing message, and let the mini-buffer
8319 This function cancels echoing. */
8322 message3 (m
, nbytes
, multibyte
)
8327 struct gcpro gcpro1
;
8330 clear_message (1,1);
8333 /* First flush out any partial line written with print. */
8334 message_log_maybe_newline ();
8340 SAFE_ALLOCA (buffer
, char *, nbytes
);
8341 bcopy (SDATA (m
), buffer
, nbytes
);
8342 message_dolog (buffer
, nbytes
, 1, multibyte
);
8345 message3_nolog (m
, nbytes
, multibyte
);
8351 /* The non-logging version of message3.
8352 This does not cancel echoing, because it is used for echoing.
8353 Perhaps we need to make a separate function for echoing
8354 and make this cancel echoing. */
8357 message3_nolog (m
, nbytes
, multibyte
)
8359 int nbytes
, multibyte
;
8361 struct frame
*sf
= SELECTED_FRAME ();
8362 message_enable_multibyte
= multibyte
;
8364 if (FRAME_INITIAL_P (sf
))
8366 if (noninteractive_need_newline
)
8367 putc ('\n', stderr
);
8368 noninteractive_need_newline
= 0;
8370 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8371 if (cursor_in_echo_area
== 0)
8372 fprintf (stderr
, "\n");
8375 /* A null message buffer means that the frame hasn't really been
8376 initialized yet. Error messages get reported properly by
8377 cmd_error, so this must be just an informative message; toss it. */
8378 else if (INTERACTIVE
8379 && sf
->glyphs_initialized_p
8380 && FRAME_MESSAGE_BUF (sf
))
8382 Lisp_Object mini_window
;
8386 /* Get the frame containing the mini-buffer
8387 that the selected frame is using. */
8388 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8389 frame
= XWINDOW (mini_window
)->frame
;
8392 FRAME_SAMPLE_VISIBILITY (f
);
8393 if (FRAME_VISIBLE_P (sf
)
8394 && !FRAME_VISIBLE_P (f
))
8395 Fmake_frame_visible (frame
);
8397 if (STRINGP (m
) && SCHARS (m
) > 0)
8399 set_message (NULL
, m
, nbytes
, multibyte
);
8400 if (minibuffer_auto_raise
)
8401 Fraise_frame (frame
);
8402 /* Assume we are not echoing.
8403 (If we are, echo_now will override this.) */
8404 echo_message_buffer
= Qnil
;
8407 clear_message (1, 1);
8409 do_pending_window_change (0);
8410 echo_area_display (1);
8411 do_pending_window_change (0);
8412 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8413 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8418 /* Display a null-terminated echo area message M. If M is 0, clear
8419 out any existing message, and let the mini-buffer text show through.
8421 The buffer M must continue to exist until after the echo area gets
8422 cleared or some other message gets displayed there. Do not pass
8423 text that is stored in a Lisp string. Do not pass text in a buffer
8424 that was alloca'd. */
8430 message2 (m
, (m
? strlen (m
) : 0), 0);
8434 /* The non-logging counterpart of message1. */
8440 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8443 /* Display a message M which contains a single %s
8444 which gets replaced with STRING. */
8447 message_with_string (m
, string
, log
)
8452 CHECK_STRING (string
);
8458 if (noninteractive_need_newline
)
8459 putc ('\n', stderr
);
8460 noninteractive_need_newline
= 0;
8461 fprintf (stderr
, m
, SDATA (string
));
8462 if (!cursor_in_echo_area
)
8463 fprintf (stderr
, "\n");
8467 else if (INTERACTIVE
)
8469 /* The frame whose minibuffer we're going to display the message on.
8470 It may be larger than the selected frame, so we need
8471 to use its buffer, not the selected frame's buffer. */
8472 Lisp_Object mini_window
;
8473 struct frame
*f
, *sf
= SELECTED_FRAME ();
8475 /* Get the frame containing the minibuffer
8476 that the selected frame is using. */
8477 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8478 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8480 /* A null message buffer means that the frame hasn't really been
8481 initialized yet. Error messages get reported properly by
8482 cmd_error, so this must be just an informative message; toss it. */
8483 if (FRAME_MESSAGE_BUF (f
))
8485 Lisp_Object args
[2], message
;
8486 struct gcpro gcpro1
, gcpro2
;
8488 args
[0] = build_string (m
);
8489 args
[1] = message
= string
;
8490 GCPRO2 (args
[0], message
);
8493 message
= Fformat (2, args
);
8496 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8498 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8502 /* Print should start at the beginning of the message
8503 buffer next time. */
8504 message_buf_print
= 0;
8510 /* Dump an informative message to the minibuf. If M is 0, clear out
8511 any existing message, and let the mini-buffer text show through. */
8515 message (m
, a1
, a2
, a3
)
8517 EMACS_INT a1
, a2
, a3
;
8523 if (noninteractive_need_newline
)
8524 putc ('\n', stderr
);
8525 noninteractive_need_newline
= 0;
8526 fprintf (stderr
, m
, a1
, a2
, a3
);
8527 if (cursor_in_echo_area
== 0)
8528 fprintf (stderr
, "\n");
8532 else if (INTERACTIVE
)
8534 /* The frame whose mini-buffer we're going to display the message
8535 on. It may be larger than the selected frame, so we need to
8536 use its buffer, not the selected frame's buffer. */
8537 Lisp_Object mini_window
;
8538 struct frame
*f
, *sf
= SELECTED_FRAME ();
8540 /* Get the frame containing the mini-buffer
8541 that the selected frame is using. */
8542 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8543 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8545 /* A null message buffer means that the frame hasn't really been
8546 initialized yet. Error messages get reported properly by
8547 cmd_error, so this must be just an informative message; toss
8549 if (FRAME_MESSAGE_BUF (f
))
8560 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8561 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8563 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8564 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8566 #endif /* NO_ARG_ARRAY */
8568 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8573 /* Print should start at the beginning of the message
8574 buffer next time. */
8575 message_buf_print
= 0;
8581 /* The non-logging version of message. */
8584 message_nolog (m
, a1
, a2
, a3
)
8586 EMACS_INT a1
, a2
, a3
;
8588 Lisp_Object old_log_max
;
8589 old_log_max
= Vmessage_log_max
;
8590 Vmessage_log_max
= Qnil
;
8591 message (m
, a1
, a2
, a3
);
8592 Vmessage_log_max
= old_log_max
;
8596 /* Display the current message in the current mini-buffer. This is
8597 only called from error handlers in process.c, and is not time
8603 if (!NILP (echo_area_buffer
[0]))
8606 string
= Fcurrent_message ();
8607 message3 (string
, SBYTES (string
),
8608 !NILP (current_buffer
->enable_multibyte_characters
));
8613 /* Make sure echo area buffers in `echo_buffers' are live.
8614 If they aren't, make new ones. */
8617 ensure_echo_area_buffers ()
8621 for (i
= 0; i
< 2; ++i
)
8622 if (!BUFFERP (echo_buffer
[i
])
8623 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8626 Lisp_Object old_buffer
;
8629 old_buffer
= echo_buffer
[i
];
8630 sprintf (name
, " *Echo Area %d*", i
);
8631 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8632 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8633 /* to force word wrap in echo area -
8634 it was decided to postpone this*/
8635 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8637 for (j
= 0; j
< 2; ++j
)
8638 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8639 echo_area_buffer
[j
] = echo_buffer
[i
];
8644 /* Call FN with args A1..A4 with either the current or last displayed
8645 echo_area_buffer as current buffer.
8647 WHICH zero means use the current message buffer
8648 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8649 from echo_buffer[] and clear it.
8651 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8652 suitable buffer from echo_buffer[] and clear it.
8654 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8655 that the current message becomes the last displayed one, make
8656 choose a suitable buffer for echo_area_buffer[0], and clear it.
8658 Value is what FN returns. */
8661 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8664 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8670 int this_one
, the_other
, clear_buffer_p
, rc
;
8671 int count
= SPECPDL_INDEX ();
8673 /* If buffers aren't live, make new ones. */
8674 ensure_echo_area_buffers ();
8679 this_one
= 0, the_other
= 1;
8681 this_one
= 1, the_other
= 0;
8684 this_one
= 0, the_other
= 1;
8687 /* We need a fresh one in case the current echo buffer equals
8688 the one containing the last displayed echo area message. */
8689 if (!NILP (echo_area_buffer
[this_one
])
8690 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8691 echo_area_buffer
[this_one
] = Qnil
;
8694 /* Choose a suitable buffer from echo_buffer[] is we don't
8696 if (NILP (echo_area_buffer
[this_one
]))
8698 echo_area_buffer
[this_one
]
8699 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8700 ? echo_buffer
[the_other
]
8701 : echo_buffer
[this_one
]);
8705 buffer
= echo_area_buffer
[this_one
];
8707 /* Don't get confused by reusing the buffer used for echoing
8708 for a different purpose. */
8709 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8712 record_unwind_protect (unwind_with_echo_area_buffer
,
8713 with_echo_area_buffer_unwind_data (w
));
8715 /* Make the echo area buffer current. Note that for display
8716 purposes, it is not necessary that the displayed window's buffer
8717 == current_buffer, except for text property lookup. So, let's
8718 only set that buffer temporarily here without doing a full
8719 Fset_window_buffer. We must also change w->pointm, though,
8720 because otherwise an assertions in unshow_buffer fails, and Emacs
8722 set_buffer_internal_1 (XBUFFER (buffer
));
8726 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8729 current_buffer
->undo_list
= Qt
;
8730 current_buffer
->read_only
= Qnil
;
8731 specbind (Qinhibit_read_only
, Qt
);
8732 specbind (Qinhibit_modification_hooks
, Qt
);
8734 if (clear_buffer_p
&& Z
> BEG
)
8737 xassert (BEGV
>= BEG
);
8738 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8740 rc
= fn (a1
, a2
, a3
, a4
);
8742 xassert (BEGV
>= BEG
);
8743 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8745 unbind_to (count
, Qnil
);
8750 /* Save state that should be preserved around the call to the function
8751 FN called in with_echo_area_buffer. */
8754 with_echo_area_buffer_unwind_data (w
)
8758 Lisp_Object vector
, tmp
;
8760 /* Reduce consing by keeping one vector in
8761 Vwith_echo_area_save_vector. */
8762 vector
= Vwith_echo_area_save_vector
;
8763 Vwith_echo_area_save_vector
= Qnil
;
8766 vector
= Fmake_vector (make_number (7), Qnil
);
8768 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8769 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8770 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8774 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8775 ASET (vector
, i
, w
->buffer
); ++i
;
8776 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8777 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8782 for (; i
< end
; ++i
)
8783 ASET (vector
, i
, Qnil
);
8786 xassert (i
== ASIZE (vector
));
8791 /* Restore global state from VECTOR which was created by
8792 with_echo_area_buffer_unwind_data. */
8795 unwind_with_echo_area_buffer (vector
)
8798 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8799 Vdeactivate_mark
= AREF (vector
, 1);
8800 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8802 if (WINDOWP (AREF (vector
, 3)))
8805 Lisp_Object buffer
, charpos
, bytepos
;
8807 w
= XWINDOW (AREF (vector
, 3));
8808 buffer
= AREF (vector
, 4);
8809 charpos
= AREF (vector
, 5);
8810 bytepos
= AREF (vector
, 6);
8813 set_marker_both (w
->pointm
, buffer
,
8814 XFASTINT (charpos
), XFASTINT (bytepos
));
8817 Vwith_echo_area_save_vector
= vector
;
8822 /* Set up the echo area for use by print functions. MULTIBYTE_P
8823 non-zero means we will print multibyte. */
8826 setup_echo_area_for_printing (multibyte_p
)
8829 /* If we can't find an echo area any more, exit. */
8830 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8833 ensure_echo_area_buffers ();
8835 if (!message_buf_print
)
8837 /* A message has been output since the last time we printed.
8838 Choose a fresh echo area buffer. */
8839 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8840 echo_area_buffer
[0] = echo_buffer
[1];
8842 echo_area_buffer
[0] = echo_buffer
[0];
8844 /* Switch to that buffer and clear it. */
8845 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8846 current_buffer
->truncate_lines
= Qnil
;
8850 int count
= SPECPDL_INDEX ();
8851 specbind (Qinhibit_read_only
, Qt
);
8852 /* Note that undo recording is always disabled. */
8854 unbind_to (count
, Qnil
);
8856 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8858 /* Set up the buffer for the multibyteness we need. */
8860 != !NILP (current_buffer
->enable_multibyte_characters
))
8861 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8863 /* Raise the frame containing the echo area. */
8864 if (minibuffer_auto_raise
)
8866 struct frame
*sf
= SELECTED_FRAME ();
8867 Lisp_Object mini_window
;
8868 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8869 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8872 message_log_maybe_newline ();
8873 message_buf_print
= 1;
8877 if (NILP (echo_area_buffer
[0]))
8879 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8880 echo_area_buffer
[0] = echo_buffer
[1];
8882 echo_area_buffer
[0] = echo_buffer
[0];
8885 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8887 /* Someone switched buffers between print requests. */
8888 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8889 current_buffer
->truncate_lines
= Qnil
;
8895 /* Display an echo area message in window W. Value is non-zero if W's
8896 height is changed. If display_last_displayed_message_p is
8897 non-zero, display the message that was last displayed, otherwise
8898 display the current message. */
8901 display_echo_area (w
)
8904 int i
, no_message_p
, window_height_changed_p
, count
;
8906 /* Temporarily disable garbage collections while displaying the echo
8907 area. This is done because a GC can print a message itself.
8908 That message would modify the echo area buffer's contents while a
8909 redisplay of the buffer is going on, and seriously confuse
8911 count
= inhibit_garbage_collection ();
8913 /* If there is no message, we must call display_echo_area_1
8914 nevertheless because it resizes the window. But we will have to
8915 reset the echo_area_buffer in question to nil at the end because
8916 with_echo_area_buffer will sets it to an empty buffer. */
8917 i
= display_last_displayed_message_p
? 1 : 0;
8918 no_message_p
= NILP (echo_area_buffer
[i
]);
8920 window_height_changed_p
8921 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8922 display_echo_area_1
,
8923 (EMACS_INT
) w
, Qnil
, 0, 0);
8926 echo_area_buffer
[i
] = Qnil
;
8928 unbind_to (count
, Qnil
);
8929 return window_height_changed_p
;
8933 /* Helper for display_echo_area. Display the current buffer which
8934 contains the current echo area message in window W, a mini-window,
8935 a pointer to which is passed in A1. A2..A4 are currently not used.
8936 Change the height of W so that all of the message is displayed.
8937 Value is non-zero if height of W was changed. */
8940 display_echo_area_1 (a1
, a2
, a3
, a4
)
8945 struct window
*w
= (struct window
*) a1
;
8947 struct text_pos start
;
8948 int window_height_changed_p
= 0;
8950 /* Do this before displaying, so that we have a large enough glyph
8951 matrix for the display. If we can't get enough space for the
8952 whole text, display the last N lines. That works by setting w->start. */
8953 window_height_changed_p
= resize_mini_window (w
, 0);
8955 /* Use the starting position chosen by resize_mini_window. */
8956 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8959 clear_glyph_matrix (w
->desired_matrix
);
8960 XSETWINDOW (window
, w
);
8961 try_window (window
, start
, 0);
8963 return window_height_changed_p
;
8967 /* Resize the echo area window to exactly the size needed for the
8968 currently displayed message, if there is one. If a mini-buffer
8969 is active, don't shrink it. */
8972 resize_echo_area_exactly ()
8974 if (BUFFERP (echo_area_buffer
[0])
8975 && WINDOWP (echo_area_window
))
8977 struct window
*w
= XWINDOW (echo_area_window
);
8979 Lisp_Object resize_exactly
;
8981 if (minibuf_level
== 0)
8982 resize_exactly
= Qt
;
8984 resize_exactly
= Qnil
;
8986 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8987 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8990 ++windows_or_buffers_changed
;
8991 ++update_mode_lines
;
8992 redisplay_internal (0);
8998 /* Callback function for with_echo_area_buffer, when used from
8999 resize_echo_area_exactly. A1 contains a pointer to the window to
9000 resize, EXACTLY non-nil means resize the mini-window exactly to the
9001 size of the text displayed. A3 and A4 are not used. Value is what
9002 resize_mini_window returns. */
9005 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
9007 Lisp_Object exactly
;
9010 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
9014 /* Resize mini-window W to fit the size of its contents. EXACT_P
9015 means size the window exactly to the size needed. Otherwise, it's
9016 only enlarged until W's buffer is empty.
9018 Set W->start to the right place to begin display. If the whole
9019 contents fit, start at the beginning. Otherwise, start so as
9020 to make the end of the contents appear. This is particularly
9021 important for y-or-n-p, but seems desirable generally.
9023 Value is non-zero if the window height has been changed. */
9026 resize_mini_window (w
, exact_p
)
9030 struct frame
*f
= XFRAME (w
->frame
);
9031 int window_height_changed_p
= 0;
9033 xassert (MINI_WINDOW_P (w
));
9035 /* By default, start display at the beginning. */
9036 set_marker_both (w
->start
, w
->buffer
,
9037 BUF_BEGV (XBUFFER (w
->buffer
)),
9038 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
9040 /* Don't resize windows while redisplaying a window; it would
9041 confuse redisplay functions when the size of the window they are
9042 displaying changes from under them. Such a resizing can happen,
9043 for instance, when which-func prints a long message while
9044 we are running fontification-functions. We're running these
9045 functions with safe_call which binds inhibit-redisplay to t. */
9046 if (!NILP (Vinhibit_redisplay
))
9049 /* Nil means don't try to resize. */
9050 if (NILP (Vresize_mini_windows
)
9051 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
9054 if (!FRAME_MINIBUF_ONLY_P (f
))
9057 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
9058 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
9059 int height
, max_height
;
9060 int unit
= FRAME_LINE_HEIGHT (f
);
9061 struct text_pos start
;
9062 struct buffer
*old_current_buffer
= NULL
;
9064 if (current_buffer
!= XBUFFER (w
->buffer
))
9066 old_current_buffer
= current_buffer
;
9067 set_buffer_internal (XBUFFER (w
->buffer
));
9070 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9072 /* Compute the max. number of lines specified by the user. */
9073 if (FLOATP (Vmax_mini_window_height
))
9074 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
9075 else if (INTEGERP (Vmax_mini_window_height
))
9076 max_height
= XINT (Vmax_mini_window_height
);
9078 max_height
= total_height
/ 4;
9080 /* Correct that max. height if it's bogus. */
9081 max_height
= max (1, max_height
);
9082 max_height
= min (total_height
, max_height
);
9084 /* Find out the height of the text in the window. */
9085 if (it
.line_wrap
== TRUNCATE
)
9090 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
9091 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
9092 height
= it
.current_y
+ last_height
;
9094 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9095 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9096 height
= (height
+ unit
- 1) / unit
;
9099 /* Compute a suitable window start. */
9100 if (height
> max_height
)
9102 height
= max_height
;
9103 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9104 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9105 start
= it
.current
.pos
;
9108 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9109 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9111 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9113 /* Let it grow only, until we display an empty message, in which
9114 case the window shrinks again. */
9115 if (height
> WINDOW_TOTAL_LINES (w
))
9117 int old_height
= WINDOW_TOTAL_LINES (w
);
9118 freeze_window_starts (f
, 1);
9119 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9120 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9122 else if (height
< WINDOW_TOTAL_LINES (w
)
9123 && (exact_p
|| BEGV
== ZV
))
9125 int old_height
= WINDOW_TOTAL_LINES (w
);
9126 freeze_window_starts (f
, 0);
9127 shrink_mini_window (w
);
9128 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9133 /* Always resize to exact size needed. */
9134 if (height
> WINDOW_TOTAL_LINES (w
))
9136 int old_height
= WINDOW_TOTAL_LINES (w
);
9137 freeze_window_starts (f
, 1);
9138 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9139 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9141 else if (height
< WINDOW_TOTAL_LINES (w
))
9143 int old_height
= WINDOW_TOTAL_LINES (w
);
9144 freeze_window_starts (f
, 0);
9145 shrink_mini_window (w
);
9149 freeze_window_starts (f
, 1);
9150 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9153 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9157 if (old_current_buffer
)
9158 set_buffer_internal (old_current_buffer
);
9161 return window_height_changed_p
;
9165 /* Value is the current message, a string, or nil if there is no
9173 if (!BUFFERP (echo_area_buffer
[0]))
9177 with_echo_area_buffer (0, 0, current_message_1
,
9178 (EMACS_INT
) &msg
, Qnil
, 0, 0);
9180 echo_area_buffer
[0] = Qnil
;
9188 current_message_1 (a1
, a2
, a3
, a4
)
9193 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
9196 *msg
= make_buffer_string (BEG
, Z
, 1);
9203 /* Push the current message on Vmessage_stack for later restauration
9204 by restore_message. Value is non-zero if the current message isn't
9205 empty. This is a relatively infrequent operation, so it's not
9206 worth optimizing. */
9212 msg
= current_message ();
9213 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9214 return STRINGP (msg
);
9218 /* Restore message display from the top of Vmessage_stack. */
9225 xassert (CONSP (Vmessage_stack
));
9226 msg
= XCAR (Vmessage_stack
);
9228 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9230 message3_nolog (msg
, 0, 0);
9234 /* Handler for record_unwind_protect calling pop_message. */
9237 pop_message_unwind (dummy
)
9244 /* Pop the top-most entry off Vmessage_stack. */
9249 xassert (CONSP (Vmessage_stack
));
9250 Vmessage_stack
= XCDR (Vmessage_stack
);
9254 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9255 exits. If the stack is not empty, we have a missing pop_message
9259 check_message_stack ()
9261 if (!NILP (Vmessage_stack
))
9266 /* Truncate to NCHARS what will be displayed in the echo area the next
9267 time we display it---but don't redisplay it now. */
9270 truncate_echo_area (nchars
)
9274 echo_area_buffer
[0] = Qnil
;
9275 /* A null message buffer means that the frame hasn't really been
9276 initialized yet. Error messages get reported properly by
9277 cmd_error, so this must be just an informative message; toss it. */
9278 else if (!noninteractive
9280 && !NILP (echo_area_buffer
[0]))
9282 struct frame
*sf
= SELECTED_FRAME ();
9283 if (FRAME_MESSAGE_BUF (sf
))
9284 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9289 /* Helper function for truncate_echo_area. Truncate the current
9290 message to at most NCHARS characters. */
9293 truncate_message_1 (nchars
, a2
, a3
, a4
)
9298 if (BEG
+ nchars
< Z
)
9299 del_range (BEG
+ nchars
, Z
);
9301 echo_area_buffer
[0] = Qnil
;
9306 /* Set the current message to a substring of S or STRING.
9308 If STRING is a Lisp string, set the message to the first NBYTES
9309 bytes from STRING. NBYTES zero means use the whole string. If
9310 STRING is multibyte, the message will be displayed multibyte.
9312 If S is not null, set the message to the first LEN bytes of S. LEN
9313 zero means use the whole string. MULTIBYTE_P non-zero means S is
9314 multibyte. Display the message multibyte in that case.
9316 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9317 to t before calling set_message_1 (which calls insert).
9321 set_message (s
, string
, nbytes
, multibyte_p
)
9324 int nbytes
, multibyte_p
;
9326 message_enable_multibyte
9327 = ((s
&& multibyte_p
)
9328 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9330 with_echo_area_buffer (0, -1, set_message_1
,
9331 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9332 message_buf_print
= 0;
9333 help_echo_showing_p
= 0;
9337 /* Helper function for set_message. Arguments have the same meaning
9338 as there, with A1 corresponding to S and A2 corresponding to STRING
9339 This function is called with the echo area buffer being
9343 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9346 EMACS_INT nbytes
, multibyte_p
;
9348 const char *s
= (const char *) a1
;
9349 Lisp_Object string
= a2
;
9351 /* Change multibyteness of the echo buffer appropriately. */
9352 if (message_enable_multibyte
9353 != !NILP (current_buffer
->enable_multibyte_characters
))
9354 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9356 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9358 /* Insert new message at BEG. */
9359 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9361 if (STRINGP (string
))
9366 nbytes
= SBYTES (string
);
9367 nchars
= string_byte_to_char (string
, nbytes
);
9369 /* This function takes care of single/multibyte conversion. We
9370 just have to ensure that the echo area buffer has the right
9371 setting of enable_multibyte_characters. */
9372 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9377 nbytes
= strlen (s
);
9379 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9381 /* Convert from multi-byte to single-byte. */
9383 unsigned char work
[1];
9385 /* Convert a multibyte string to single-byte. */
9386 for (i
= 0; i
< nbytes
; i
+= n
)
9388 c
= string_char_and_length (s
+ i
, &n
);
9389 work
[0] = (ASCII_CHAR_P (c
)
9391 : multibyte_char_to_unibyte (c
, Qnil
));
9392 insert_1_both (work
, 1, 1, 1, 0, 0);
9395 else if (!multibyte_p
9396 && !NILP (current_buffer
->enable_multibyte_characters
))
9398 /* Convert from single-byte to multi-byte. */
9400 const unsigned char *msg
= (const unsigned char *) s
;
9401 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9403 /* Convert a single-byte string to multibyte. */
9404 for (i
= 0; i
< nbytes
; i
++)
9407 MAKE_CHAR_MULTIBYTE (c
);
9408 n
= CHAR_STRING (c
, str
);
9409 insert_1_both (str
, 1, n
, 1, 0, 0);
9413 insert_1 (s
, nbytes
, 1, 0, 0);
9420 /* Clear messages. CURRENT_P non-zero means clear the current
9421 message. LAST_DISPLAYED_P non-zero means clear the message
9425 clear_message (current_p
, last_displayed_p
)
9426 int current_p
, last_displayed_p
;
9430 echo_area_buffer
[0] = Qnil
;
9431 message_cleared_p
= 1;
9434 if (last_displayed_p
)
9435 echo_area_buffer
[1] = Qnil
;
9437 message_buf_print
= 0;
9440 /* Clear garbaged frames.
9442 This function is used where the old redisplay called
9443 redraw_garbaged_frames which in turn called redraw_frame which in
9444 turn called clear_frame. The call to clear_frame was a source of
9445 flickering. I believe a clear_frame is not necessary. It should
9446 suffice in the new redisplay to invalidate all current matrices,
9447 and ensure a complete redisplay of all windows. */
9450 clear_garbaged_frames ()
9454 Lisp_Object tail
, frame
;
9455 int changed_count
= 0;
9457 FOR_EACH_FRAME (tail
, frame
)
9459 struct frame
*f
= XFRAME (frame
);
9461 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9465 Fredraw_frame (frame
);
9466 f
->force_flush_display_p
= 1;
9468 clear_current_matrices (f
);
9477 ++windows_or_buffers_changed
;
9482 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9483 is non-zero update selected_frame. Value is non-zero if the
9484 mini-windows height has been changed. */
9487 echo_area_display (update_frame_p
)
9490 Lisp_Object mini_window
;
9493 int window_height_changed_p
= 0;
9494 struct frame
*sf
= SELECTED_FRAME ();
9496 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9497 w
= XWINDOW (mini_window
);
9498 f
= XFRAME (WINDOW_FRAME (w
));
9500 /* Don't display if frame is invisible or not yet initialized. */
9501 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9504 #ifdef HAVE_WINDOW_SYSTEM
9505 /* When Emacs starts, selected_frame may be the initial terminal
9506 frame. If we let this through, a message would be displayed on
9508 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9510 #endif /* HAVE_WINDOW_SYSTEM */
9512 /* Redraw garbaged frames. */
9514 clear_garbaged_frames ();
9516 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9518 echo_area_window
= mini_window
;
9519 window_height_changed_p
= display_echo_area (w
);
9520 w
->must_be_updated_p
= 1;
9522 /* Update the display, unless called from redisplay_internal.
9523 Also don't update the screen during redisplay itself. The
9524 update will happen at the end of redisplay, and an update
9525 here could cause confusion. */
9526 if (update_frame_p
&& !redisplaying_p
)
9530 /* If the display update has been interrupted by pending
9531 input, update mode lines in the frame. Due to the
9532 pending input, it might have been that redisplay hasn't
9533 been called, so that mode lines above the echo area are
9534 garbaged. This looks odd, so we prevent it here. */
9535 if (!display_completed
)
9536 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9538 if (window_height_changed_p
9539 /* Don't do this if Emacs is shutting down. Redisplay
9540 needs to run hooks. */
9541 && !NILP (Vrun_hooks
))
9543 /* Must update other windows. Likewise as in other
9544 cases, don't let this update be interrupted by
9546 int count
= SPECPDL_INDEX ();
9547 specbind (Qredisplay_dont_pause
, Qt
);
9548 windows_or_buffers_changed
= 1;
9549 redisplay_internal (0);
9550 unbind_to (count
, Qnil
);
9552 else if (FRAME_WINDOW_P (f
) && n
== 0)
9554 /* Window configuration is the same as before.
9555 Can do with a display update of the echo area,
9556 unless we displayed some mode lines. */
9557 update_single_window (w
, 1);
9558 FRAME_RIF (f
)->flush_display (f
);
9561 update_frame (f
, 1, 1);
9563 /* If cursor is in the echo area, make sure that the next
9564 redisplay displays the minibuffer, so that the cursor will
9565 be replaced with what the minibuffer wants. */
9566 if (cursor_in_echo_area
)
9567 ++windows_or_buffers_changed
;
9570 else if (!EQ (mini_window
, selected_window
))
9571 windows_or_buffers_changed
++;
9573 /* Last displayed message is now the current message. */
9574 echo_area_buffer
[1] = echo_area_buffer
[0];
9575 /* Inform read_char that we're not echoing. */
9576 echo_message_buffer
= Qnil
;
9578 /* Prevent redisplay optimization in redisplay_internal by resetting
9579 this_line_start_pos. This is done because the mini-buffer now
9580 displays the message instead of its buffer text. */
9581 if (EQ (mini_window
, selected_window
))
9582 CHARPOS (this_line_start_pos
) = 0;
9584 return window_height_changed_p
;
9589 /***********************************************************************
9590 Mode Lines and Frame Titles
9591 ***********************************************************************/
9593 /* A buffer for constructing non-propertized mode-line strings and
9594 frame titles in it; allocated from the heap in init_xdisp and
9595 resized as needed in store_mode_line_noprop_char. */
9597 static char *mode_line_noprop_buf
;
9599 /* The buffer's end, and a current output position in it. */
9601 static char *mode_line_noprop_buf_end
;
9602 static char *mode_line_noprop_ptr
;
9604 #define MODE_LINE_NOPROP_LEN(start) \
9605 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9608 MODE_LINE_DISPLAY
= 0,
9614 /* Alist that caches the results of :propertize.
9615 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9616 static Lisp_Object mode_line_proptrans_alist
;
9618 /* List of strings making up the mode-line. */
9619 static Lisp_Object mode_line_string_list
;
9621 /* Base face property when building propertized mode line string. */
9622 static Lisp_Object mode_line_string_face
;
9623 static Lisp_Object mode_line_string_face_prop
;
9626 /* Unwind data for mode line strings */
9628 static Lisp_Object Vmode_line_unwind_vector
;
9631 format_mode_line_unwind_data (struct buffer
*obuf
,
9635 Lisp_Object vector
, tmp
;
9637 /* Reduce consing by keeping one vector in
9638 Vwith_echo_area_save_vector. */
9639 vector
= Vmode_line_unwind_vector
;
9640 Vmode_line_unwind_vector
= Qnil
;
9643 vector
= Fmake_vector (make_number (8), Qnil
);
9645 ASET (vector
, 0, make_number (mode_line_target
));
9646 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9647 ASET (vector
, 2, mode_line_string_list
);
9648 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9649 ASET (vector
, 4, mode_line_string_face
);
9650 ASET (vector
, 5, mode_line_string_face_prop
);
9653 XSETBUFFER (tmp
, obuf
);
9656 ASET (vector
, 6, tmp
);
9657 ASET (vector
, 7, owin
);
9663 unwind_format_mode_line (vector
)
9666 mode_line_target
= XINT (AREF (vector
, 0));
9667 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9668 mode_line_string_list
= AREF (vector
, 2);
9669 if (! EQ (AREF (vector
, 3), Qt
))
9670 mode_line_proptrans_alist
= AREF (vector
, 3);
9671 mode_line_string_face
= AREF (vector
, 4);
9672 mode_line_string_face_prop
= AREF (vector
, 5);
9674 if (!NILP (AREF (vector
, 7)))
9675 /* Select window before buffer, since it may change the buffer. */
9676 Fselect_window (AREF (vector
, 7), Qt
);
9678 if (!NILP (AREF (vector
, 6)))
9680 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9681 ASET (vector
, 6, Qnil
);
9684 Vmode_line_unwind_vector
= vector
;
9689 /* Store a single character C for the frame title in mode_line_noprop_buf.
9690 Re-allocate mode_line_noprop_buf if necessary. */
9694 store_mode_line_noprop_char (char c
)
9696 store_mode_line_noprop_char (c
)
9700 /* If output position has reached the end of the allocated buffer,
9701 double the buffer's size. */
9702 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9704 int len
= MODE_LINE_NOPROP_LEN (0);
9705 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9706 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9707 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9708 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9711 *mode_line_noprop_ptr
++ = c
;
9715 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9716 mode_line_noprop_ptr. STR is the string to store. Do not copy
9717 characters that yield more columns than PRECISION; PRECISION <= 0
9718 means copy the whole string. Pad with spaces until FIELD_WIDTH
9719 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9720 pad. Called from display_mode_element when it is used to build a
9724 store_mode_line_noprop (str
, field_width
, precision
)
9725 const unsigned char *str
;
9726 int field_width
, precision
;
9731 /* Copy at most PRECISION chars from STR. */
9732 nbytes
= strlen (str
);
9733 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9735 store_mode_line_noprop_char (*str
++);
9737 /* Fill up with spaces until FIELD_WIDTH reached. */
9738 while (field_width
> 0
9741 store_mode_line_noprop_char (' ');
9748 /***********************************************************************
9750 ***********************************************************************/
9752 #ifdef HAVE_WINDOW_SYSTEM
9754 /* Set the title of FRAME, if it has changed. The title format is
9755 Vicon_title_format if FRAME is iconified, otherwise it is
9756 frame_title_format. */
9759 x_consider_frame_title (frame
)
9762 struct frame
*f
= XFRAME (frame
);
9764 if (FRAME_WINDOW_P (f
)
9765 || FRAME_MINIBUF_ONLY_P (f
)
9766 || f
->explicit_name
)
9768 /* Do we have more than one visible frame on this X display? */
9775 int count
= SPECPDL_INDEX ();
9777 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9779 Lisp_Object other_frame
= XCAR (tail
);
9780 struct frame
*tf
= XFRAME (other_frame
);
9783 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9784 && !FRAME_MINIBUF_ONLY_P (tf
)
9785 && !EQ (other_frame
, tip_frame
)
9786 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9790 /* Set global variable indicating that multiple frames exist. */
9791 multiple_frames
= CONSP (tail
);
9793 /* Switch to the buffer of selected window of the frame. Set up
9794 mode_line_target so that display_mode_element will output into
9795 mode_line_noprop_buf; then display the title. */
9796 record_unwind_protect (unwind_format_mode_line
,
9797 format_mode_line_unwind_data
9798 (current_buffer
, selected_window
, 0));
9800 Fselect_window (f
->selected_window
, Qt
);
9801 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9802 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9804 mode_line_target
= MODE_LINE_TITLE
;
9805 title_start
= MODE_LINE_NOPROP_LEN (0);
9806 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9807 NULL
, DEFAULT_FACE_ID
);
9808 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9809 len
= MODE_LINE_NOPROP_LEN (title_start
);
9810 title
= mode_line_noprop_buf
+ title_start
;
9811 unbind_to (count
, Qnil
);
9813 /* Set the title only if it's changed. This avoids consing in
9814 the common case where it hasn't. (If it turns out that we've
9815 already wasted too much time by walking through the list with
9816 display_mode_element, then we might need to optimize at a
9817 higher level than this.) */
9818 if (! STRINGP (f
->name
)
9819 || SBYTES (f
->name
) != len
9820 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9825 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9828 ns_set_name_as_filename (f
);
9830 x_implicitly_set_name (f
, make_string(title
, len
),
9836 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9841 /* do this also for frames with explicit names */
9842 ns_implicitly_set_icon_type(f
);
9843 ns_set_doc_edited(f
, Fbuffer_modified_p
9844 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9850 #endif /* not HAVE_WINDOW_SYSTEM */
9855 /***********************************************************************
9857 ***********************************************************************/
9860 /* Prepare for redisplay by updating menu-bar item lists when
9861 appropriate. This can call eval. */
9864 prepare_menu_bars ()
9867 struct gcpro gcpro1
, gcpro2
;
9869 Lisp_Object tooltip_frame
;
9871 #ifdef HAVE_WINDOW_SYSTEM
9872 tooltip_frame
= tip_frame
;
9874 tooltip_frame
= Qnil
;
9877 /* Update all frame titles based on their buffer names, etc. We do
9878 this before the menu bars so that the buffer-menu will show the
9879 up-to-date frame titles. */
9880 #ifdef HAVE_WINDOW_SYSTEM
9881 if (windows_or_buffers_changed
|| update_mode_lines
)
9883 Lisp_Object tail
, frame
;
9885 FOR_EACH_FRAME (tail
, frame
)
9888 if (!EQ (frame
, tooltip_frame
)
9889 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9890 x_consider_frame_title (frame
);
9893 #endif /* HAVE_WINDOW_SYSTEM */
9895 /* Update the menu bar item lists, if appropriate. This has to be
9896 done before any actual redisplay or generation of display lines. */
9897 all_windows
= (update_mode_lines
9898 || buffer_shared
> 1
9899 || windows_or_buffers_changed
);
9902 Lisp_Object tail
, frame
;
9903 int count
= SPECPDL_INDEX ();
9904 /* 1 means that update_menu_bar has run its hooks
9905 so any further calls to update_menu_bar shouldn't do so again. */
9906 int menu_bar_hooks_run
= 0;
9908 record_unwind_save_match_data ();
9910 FOR_EACH_FRAME (tail
, frame
)
9914 /* Ignore tooltip frame. */
9915 if (EQ (frame
, tooltip_frame
))
9918 /* If a window on this frame changed size, report that to
9919 the user and clear the size-change flag. */
9920 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9922 Lisp_Object functions
;
9924 /* Clear flag first in case we get an error below. */
9925 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9926 functions
= Vwindow_size_change_functions
;
9927 GCPRO2 (tail
, functions
);
9929 while (CONSP (functions
))
9931 if (!EQ (XCAR (functions
), Qt
))
9932 call1 (XCAR (functions
), frame
);
9933 functions
= XCDR (functions
);
9939 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9940 #ifdef HAVE_WINDOW_SYSTEM
9941 update_tool_bar (f
, 0);
9946 unbind_to (count
, Qnil
);
9950 struct frame
*sf
= SELECTED_FRAME ();
9951 update_menu_bar (sf
, 1, 0);
9952 #ifdef HAVE_WINDOW_SYSTEM
9953 update_tool_bar (sf
, 1);
9957 /* Motif needs this. See comment in xmenu.c. Turn it off when
9958 pending_menu_activation is not defined. */
9959 #ifdef USE_X_TOOLKIT
9960 pending_menu_activation
= 0;
9965 /* Update the menu bar item list for frame F. This has to be done
9966 before we start to fill in any display lines, because it can call
9969 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9971 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9972 already ran the menu bar hooks for this redisplay, so there
9973 is no need to run them again. The return value is the
9974 updated value of this flag, to pass to the next call. */
9977 update_menu_bar (f
, save_match_data
, hooks_run
)
9979 int save_match_data
;
9983 register struct window
*w
;
9985 /* If called recursively during a menu update, do nothing. This can
9986 happen when, for instance, an activate-menubar-hook causes a
9988 if (inhibit_menubar_update
)
9991 window
= FRAME_SELECTED_WINDOW (f
);
9992 w
= XWINDOW (window
);
9994 if (FRAME_WINDOW_P (f
)
9996 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9997 || defined (HAVE_NS) || defined (USE_GTK)
9998 FRAME_EXTERNAL_MENU_BAR (f
)
10000 FRAME_MENU_BAR_LINES (f
) > 0
10002 : FRAME_MENU_BAR_LINES (f
) > 0)
10004 /* If the user has switched buffers or windows, we need to
10005 recompute to reflect the new bindings. But we'll
10006 recompute when update_mode_lines is set too; that means
10007 that people can use force-mode-line-update to request
10008 that the menu bar be recomputed. The adverse effect on
10009 the rest of the redisplay algorithm is about the same as
10010 windows_or_buffers_changed anyway. */
10011 if (windows_or_buffers_changed
10012 /* This used to test w->update_mode_line, but we believe
10013 there is no need to recompute the menu in that case. */
10014 || update_mode_lines
10015 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10016 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10017 != !NILP (w
->last_had_star
))
10018 || ((!NILP (Vtransient_mark_mode
)
10019 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10020 != !NILP (w
->region_showing
)))
10022 struct buffer
*prev
= current_buffer
;
10023 int count
= SPECPDL_INDEX ();
10025 specbind (Qinhibit_menubar_update
, Qt
);
10027 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10028 if (save_match_data
)
10029 record_unwind_save_match_data ();
10030 if (NILP (Voverriding_local_map_menu_flag
))
10032 specbind (Qoverriding_terminal_local_map
, Qnil
);
10033 specbind (Qoverriding_local_map
, Qnil
);
10038 /* Run the Lucid hook. */
10039 safe_run_hooks (Qactivate_menubar_hook
);
10041 /* If it has changed current-menubar from previous value,
10042 really recompute the menu-bar from the value. */
10043 if (! NILP (Vlucid_menu_bar_dirty_flag
))
10044 call0 (Qrecompute_lucid_menubar
);
10046 safe_run_hooks (Qmenu_bar_update_hook
);
10051 XSETFRAME (Vmenu_updating_frame
, f
);
10052 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
10054 /* Redisplay the menu bar in case we changed it. */
10055 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
10056 || defined (HAVE_NS) || defined (USE_GTK)
10057 if (FRAME_WINDOW_P (f
))
10059 #if defined (HAVE_NS)
10060 /* All frames on Mac OS share the same menubar. So only
10061 the selected frame should be allowed to set it. */
10062 if (f
== SELECTED_FRAME ())
10064 set_frame_menubar (f
, 0, 0);
10067 /* On a terminal screen, the menu bar is an ordinary screen
10068 line, and this makes it get updated. */
10069 w
->update_mode_line
= Qt
;
10070 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10071 /* In the non-toolkit version, the menu bar is an ordinary screen
10072 line, and this makes it get updated. */
10073 w
->update_mode_line
= Qt
;
10074 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
10076 unbind_to (count
, Qnil
);
10077 set_buffer_internal_1 (prev
);
10086 /***********************************************************************
10088 ***********************************************************************/
10090 #ifdef HAVE_WINDOW_SYSTEM
10093 Nominal cursor position -- where to draw output.
10094 HPOS and VPOS are window relative glyph matrix coordinates.
10095 X and Y are window relative pixel coordinates. */
10097 struct cursor_pos output_cursor
;
10101 Set the global variable output_cursor to CURSOR. All cursor
10102 positions are relative to updated_window. */
10105 set_output_cursor (cursor
)
10106 struct cursor_pos
*cursor
;
10108 output_cursor
.hpos
= cursor
->hpos
;
10109 output_cursor
.vpos
= cursor
->vpos
;
10110 output_cursor
.x
= cursor
->x
;
10111 output_cursor
.y
= cursor
->y
;
10116 Set a nominal cursor position.
10118 HPOS and VPOS are column/row positions in a window glyph matrix. X
10119 and Y are window text area relative pixel positions.
10121 If this is done during an update, updated_window will contain the
10122 window that is being updated and the position is the future output
10123 cursor position for that window. If updated_window is null, use
10124 selected_window and display the cursor at the given position. */
10127 x_cursor_to (vpos
, hpos
, y
, x
)
10128 int vpos
, hpos
, y
, x
;
10132 /* If updated_window is not set, work on selected_window. */
10133 if (updated_window
)
10134 w
= updated_window
;
10136 w
= XWINDOW (selected_window
);
10138 /* Set the output cursor. */
10139 output_cursor
.hpos
= hpos
;
10140 output_cursor
.vpos
= vpos
;
10141 output_cursor
.x
= x
;
10142 output_cursor
.y
= y
;
10144 /* If not called as part of an update, really display the cursor.
10145 This will also set the cursor position of W. */
10146 if (updated_window
== NULL
)
10149 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10150 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10151 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10156 #endif /* HAVE_WINDOW_SYSTEM */
10159 /***********************************************************************
10161 ***********************************************************************/
10163 #ifdef HAVE_WINDOW_SYSTEM
10165 /* Where the mouse was last time we reported a mouse event. */
10167 FRAME_PTR last_mouse_frame
;
10169 /* Tool-bar item index of the item on which a mouse button was pressed
10172 int last_tool_bar_item
;
10176 update_tool_bar_unwind (frame
)
10179 selected_frame
= frame
;
10183 /* Update the tool-bar item list for frame F. This has to be done
10184 before we start to fill in any display lines. Called from
10185 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10186 and restore it here. */
10189 update_tool_bar (f
, save_match_data
)
10191 int save_match_data
;
10193 #if defined (USE_GTK) || defined (HAVE_NS)
10194 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10196 int do_update
= WINDOWP (f
->tool_bar_window
)
10197 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10202 Lisp_Object window
;
10205 window
= FRAME_SELECTED_WINDOW (f
);
10206 w
= XWINDOW (window
);
10208 /* If the user has switched buffers or windows, we need to
10209 recompute to reflect the new bindings. But we'll
10210 recompute when update_mode_lines is set too; that means
10211 that people can use force-mode-line-update to request
10212 that the menu bar be recomputed. The adverse effect on
10213 the rest of the redisplay algorithm is about the same as
10214 windows_or_buffers_changed anyway. */
10215 if (windows_or_buffers_changed
10216 || !NILP (w
->update_mode_line
)
10217 || update_mode_lines
10218 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10219 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10220 != !NILP (w
->last_had_star
))
10221 || ((!NILP (Vtransient_mark_mode
)
10222 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10223 != !NILP (w
->region_showing
)))
10225 struct buffer
*prev
= current_buffer
;
10226 int count
= SPECPDL_INDEX ();
10227 Lisp_Object frame
, new_tool_bar
;
10228 int new_n_tool_bar
;
10229 struct gcpro gcpro1
;
10231 /* Set current_buffer to the buffer of the selected
10232 window of the frame, so that we get the right local
10234 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10236 /* Save match data, if we must. */
10237 if (save_match_data
)
10238 record_unwind_save_match_data ();
10240 /* Make sure that we don't accidentally use bogus keymaps. */
10241 if (NILP (Voverriding_local_map_menu_flag
))
10243 specbind (Qoverriding_terminal_local_map
, Qnil
);
10244 specbind (Qoverriding_local_map
, Qnil
);
10247 GCPRO1 (new_tool_bar
);
10249 /* We must temporarily set the selected frame to this frame
10250 before calling tool_bar_items, because the calculation of
10251 the tool-bar keymap uses the selected frame (see
10252 `tool-bar-make-keymap' in tool-bar.el). */
10253 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10254 XSETFRAME (frame
, f
);
10255 selected_frame
= frame
;
10257 /* Build desired tool-bar items from keymaps. */
10258 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10261 /* Redisplay the tool-bar if we changed it. */
10262 if (new_n_tool_bar
!= f
->n_tool_bar_items
10263 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10265 /* Redisplay that happens asynchronously due to an expose event
10266 may access f->tool_bar_items. Make sure we update both
10267 variables within BLOCK_INPUT so no such event interrupts. */
10269 f
->tool_bar_items
= new_tool_bar
;
10270 f
->n_tool_bar_items
= new_n_tool_bar
;
10271 w
->update_mode_line
= Qt
;
10277 unbind_to (count
, Qnil
);
10278 set_buffer_internal_1 (prev
);
10284 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10285 F's desired tool-bar contents. F->tool_bar_items must have
10286 been set up previously by calling prepare_menu_bars. */
10289 build_desired_tool_bar_string (f
)
10292 int i
, size
, size_needed
;
10293 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10294 Lisp_Object image
, plist
, props
;
10296 image
= plist
= props
= Qnil
;
10297 GCPRO3 (image
, plist
, props
);
10299 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10300 Otherwise, make a new string. */
10302 /* The size of the string we might be able to reuse. */
10303 size
= (STRINGP (f
->desired_tool_bar_string
)
10304 ? SCHARS (f
->desired_tool_bar_string
)
10307 /* We need one space in the string for each image. */
10308 size_needed
= f
->n_tool_bar_items
;
10310 /* Reuse f->desired_tool_bar_string, if possible. */
10311 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10312 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10313 make_number (' '));
10316 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10317 Fremove_text_properties (make_number (0), make_number (size
),
10318 props
, f
->desired_tool_bar_string
);
10321 /* Put a `display' property on the string for the images to display,
10322 put a `menu_item' property on tool-bar items with a value that
10323 is the index of the item in F's tool-bar item vector. */
10324 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10326 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10328 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10329 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10330 int hmargin
, vmargin
, relief
, idx
, end
;
10331 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
10333 /* If image is a vector, choose the image according to the
10335 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10336 if (VECTORP (image
))
10340 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10341 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10344 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10345 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10347 xassert (ASIZE (image
) >= idx
);
10348 image
= AREF (image
, idx
);
10353 /* Ignore invalid image specifications. */
10354 if (!valid_image_p (image
))
10357 /* Display the tool-bar button pressed, or depressed. */
10358 plist
= Fcopy_sequence (XCDR (image
));
10360 /* Compute margin and relief to draw. */
10361 relief
= (tool_bar_button_relief
>= 0
10362 ? tool_bar_button_relief
10363 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10364 hmargin
= vmargin
= relief
;
10366 if (INTEGERP (Vtool_bar_button_margin
)
10367 && XINT (Vtool_bar_button_margin
) > 0)
10369 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10370 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10372 else if (CONSP (Vtool_bar_button_margin
))
10374 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10375 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10376 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10378 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10379 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10380 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10383 if (auto_raise_tool_bar_buttons_p
)
10385 /* Add a `:relief' property to the image spec if the item is
10389 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10396 /* If image is selected, display it pressed, i.e. with a
10397 negative relief. If it's not selected, display it with a
10399 plist
= Fplist_put (plist
, QCrelief
,
10401 ? make_number (-relief
)
10402 : make_number (relief
)));
10407 /* Put a margin around the image. */
10408 if (hmargin
|| vmargin
)
10410 if (hmargin
== vmargin
)
10411 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10413 plist
= Fplist_put (plist
, QCmargin
,
10414 Fcons (make_number (hmargin
),
10415 make_number (vmargin
)));
10418 /* If button is not enabled, and we don't have special images
10419 for the disabled state, make the image appear disabled by
10420 applying an appropriate algorithm to it. */
10421 if (!enabled_p
&& idx
< 0)
10422 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10424 /* Put a `display' text property on the string for the image to
10425 display. Put a `menu-item' property on the string that gives
10426 the start of this item's properties in the tool-bar items
10428 image
= Fcons (Qimage
, plist
);
10429 props
= list4 (Qdisplay
, image
,
10430 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10432 /* Let the last image hide all remaining spaces in the tool bar
10433 string. The string can be longer than needed when we reuse a
10434 previous string. */
10435 if (i
+ 1 == f
->n_tool_bar_items
)
10436 end
= SCHARS (f
->desired_tool_bar_string
);
10439 Fadd_text_properties (make_number (i
), make_number (end
),
10440 props
, f
->desired_tool_bar_string
);
10448 /* Display one line of the tool-bar of frame IT->f.
10450 HEIGHT specifies the desired height of the tool-bar line.
10451 If the actual height of the glyph row is less than HEIGHT, the
10452 row's height is increased to HEIGHT, and the icons are centered
10453 vertically in the new height.
10455 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10456 count a final empty row in case the tool-bar width exactly matches
10461 display_tool_bar_line (it
, height
)
10465 struct glyph_row
*row
= it
->glyph_row
;
10466 int max_x
= it
->last_visible_x
;
10467 struct glyph
*last
;
10469 prepare_desired_row (row
);
10470 row
->y
= it
->current_y
;
10472 /* Note that this isn't made use of if the face hasn't a box,
10473 so there's no need to check the face here. */
10474 it
->start_of_box_run_p
= 1;
10476 while (it
->current_x
< max_x
)
10478 int x
, n_glyphs_before
, i
, nglyphs
;
10479 struct it it_before
;
10481 /* Get the next display element. */
10482 if (!get_next_display_element (it
))
10484 /* Don't count empty row if we are counting needed tool-bar lines. */
10485 if (height
< 0 && !it
->hpos
)
10490 /* Produce glyphs. */
10491 n_glyphs_before
= row
->used
[TEXT_AREA
];
10494 PRODUCE_GLYPHS (it
);
10496 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10498 x
= it_before
.current_x
;
10499 while (i
< nglyphs
)
10501 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10503 if (x
+ glyph
->pixel_width
> max_x
)
10505 /* Glyph doesn't fit on line. Backtrack. */
10506 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10508 /* If this is the only glyph on this line, it will never fit on the
10509 toolbar, so skip it. But ensure there is at least one glyph,
10510 so we don't accidentally disable the tool-bar. */
10511 if (n_glyphs_before
== 0
10512 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10518 x
+= glyph
->pixel_width
;
10522 /* Stop at line ends. */
10523 if (ITERATOR_AT_END_OF_LINE_P (it
))
10526 set_iterator_to_next (it
, 1);
10531 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10533 /* Use default face for the border below the tool bar.
10535 FIXME: When auto-resize-tool-bars is grow-only, there is
10536 no additional border below the possibly empty tool-bar lines.
10537 So to make the extra empty lines look "normal", we have to
10538 use the tool-bar face for the border too. */
10539 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10540 it
->face_id
= DEFAULT_FACE_ID
;
10542 extend_face_to_end_of_line (it
);
10543 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10544 last
->right_box_line_p
= 1;
10545 if (last
== row
->glyphs
[TEXT_AREA
])
10546 last
->left_box_line_p
= 1;
10548 /* Make line the desired height and center it vertically. */
10549 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10551 /* Don't add more than one line height. */
10552 height
%= FRAME_LINE_HEIGHT (it
->f
);
10553 it
->max_ascent
+= height
/ 2;
10554 it
->max_descent
+= (height
+ 1) / 2;
10557 compute_line_metrics (it
);
10559 /* If line is empty, make it occupy the rest of the tool-bar. */
10560 if (!row
->displays_text_p
)
10562 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10563 row
->visible_height
= row
->height
;
10564 row
->ascent
= row
->phys_ascent
= 0;
10565 row
->extra_line_spacing
= 0;
10568 row
->full_width_p
= 1;
10569 row
->continued_p
= 0;
10570 row
->truncated_on_left_p
= 0;
10571 row
->truncated_on_right_p
= 0;
10573 it
->current_x
= it
->hpos
= 0;
10574 it
->current_y
+= row
->height
;
10580 /* Max tool-bar height. */
10582 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10583 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10585 /* Value is the number of screen lines needed to make all tool-bar
10586 items of frame F visible. The number of actual rows needed is
10587 returned in *N_ROWS if non-NULL. */
10590 tool_bar_lines_needed (f
, n_rows
)
10594 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10596 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10597 the desired matrix, so use (unused) mode-line row as temporary row to
10598 avoid destroying the first tool-bar row. */
10599 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10601 /* Initialize an iterator for iteration over
10602 F->desired_tool_bar_string in the tool-bar window of frame F. */
10603 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10604 it
.first_visible_x
= 0;
10605 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10606 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10608 while (!ITERATOR_AT_END_P (&it
))
10610 clear_glyph_row (temp_row
);
10611 it
.glyph_row
= temp_row
;
10612 display_tool_bar_line (&it
, -1);
10614 clear_glyph_row (temp_row
);
10616 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10618 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10620 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10624 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10626 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10635 frame
= selected_frame
;
10637 CHECK_FRAME (frame
);
10638 f
= XFRAME (frame
);
10640 if (WINDOWP (f
->tool_bar_window
)
10641 || (w
= XWINDOW (f
->tool_bar_window
),
10642 WINDOW_TOTAL_LINES (w
) > 0))
10644 update_tool_bar (f
, 1);
10645 if (f
->n_tool_bar_items
)
10647 build_desired_tool_bar_string (f
);
10648 nlines
= tool_bar_lines_needed (f
, NULL
);
10652 return make_number (nlines
);
10656 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10657 height should be changed. */
10660 redisplay_tool_bar (f
)
10665 struct glyph_row
*row
;
10667 #if defined (USE_GTK) || defined (HAVE_NS)
10668 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10669 update_frame_tool_bar (f
);
10673 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10674 do anything. This means you must start with tool-bar-lines
10675 non-zero to get the auto-sizing effect. Or in other words, you
10676 can turn off tool-bars by specifying tool-bar-lines zero. */
10677 if (!WINDOWP (f
->tool_bar_window
)
10678 || (w
= XWINDOW (f
->tool_bar_window
),
10679 WINDOW_TOTAL_LINES (w
) == 0))
10682 /* Set up an iterator for the tool-bar window. */
10683 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10684 it
.first_visible_x
= 0;
10685 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10686 row
= it
.glyph_row
;
10688 /* Build a string that represents the contents of the tool-bar. */
10689 build_desired_tool_bar_string (f
);
10690 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10692 if (f
->n_tool_bar_rows
== 0)
10696 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10697 nlines
!= WINDOW_TOTAL_LINES (w
)))
10699 extern Lisp_Object Qtool_bar_lines
;
10701 int old_height
= WINDOW_TOTAL_LINES (w
);
10703 XSETFRAME (frame
, f
);
10704 Fmodify_frame_parameters (frame
,
10705 Fcons (Fcons (Qtool_bar_lines
,
10706 make_number (nlines
)),
10708 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10710 clear_glyph_matrix (w
->desired_matrix
);
10711 fonts_changed_p
= 1;
10717 /* Display as many lines as needed to display all tool-bar items. */
10719 if (f
->n_tool_bar_rows
> 0)
10721 int border
, rows
, height
, extra
;
10723 if (INTEGERP (Vtool_bar_border
))
10724 border
= XINT (Vtool_bar_border
);
10725 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10726 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10727 else if (EQ (Vtool_bar_border
, Qborder_width
))
10728 border
= f
->border_width
;
10734 rows
= f
->n_tool_bar_rows
;
10735 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10736 extra
= it
.last_visible_y
- border
- height
* rows
;
10738 while (it
.current_y
< it
.last_visible_y
)
10741 if (extra
> 0 && rows
-- > 0)
10743 h
= (extra
+ rows
- 1) / rows
;
10746 display_tool_bar_line (&it
, height
+ h
);
10751 while (it
.current_y
< it
.last_visible_y
)
10752 display_tool_bar_line (&it
, 0);
10755 /* It doesn't make much sense to try scrolling in the tool-bar
10756 window, so don't do it. */
10757 w
->desired_matrix
->no_scrolling_p
= 1;
10758 w
->must_be_updated_p
= 1;
10760 if (!NILP (Vauto_resize_tool_bars
))
10762 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10763 int change_height_p
= 0;
10765 /* If we couldn't display everything, change the tool-bar's
10766 height if there is room for more. */
10767 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10768 && it
.current_y
< max_tool_bar_height
)
10769 change_height_p
= 1;
10771 row
= it
.glyph_row
- 1;
10773 /* If there are blank lines at the end, except for a partially
10774 visible blank line at the end that is smaller than
10775 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10776 if (!row
->displays_text_p
10777 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10778 change_height_p
= 1;
10780 /* If row displays tool-bar items, but is partially visible,
10781 change the tool-bar's height. */
10782 if (row
->displays_text_p
10783 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10784 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10785 change_height_p
= 1;
10787 /* Resize windows as needed by changing the `tool-bar-lines'
10788 frame parameter. */
10789 if (change_height_p
)
10791 extern Lisp_Object Qtool_bar_lines
;
10793 int old_height
= WINDOW_TOTAL_LINES (w
);
10795 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10797 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10798 && !f
->minimize_tool_bar_window_p
)
10799 ? (nlines
> old_height
)
10800 : (nlines
!= old_height
));
10801 f
->minimize_tool_bar_window_p
= 0;
10803 if (change_height_p
)
10805 XSETFRAME (frame
, f
);
10806 Fmodify_frame_parameters (frame
,
10807 Fcons (Fcons (Qtool_bar_lines
,
10808 make_number (nlines
)),
10810 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10812 clear_glyph_matrix (w
->desired_matrix
);
10813 f
->n_tool_bar_rows
= nrows
;
10814 fonts_changed_p
= 1;
10821 f
->minimize_tool_bar_window_p
= 0;
10826 /* Get information about the tool-bar item which is displayed in GLYPH
10827 on frame F. Return in *PROP_IDX the index where tool-bar item
10828 properties start in F->tool_bar_items. Value is zero if
10829 GLYPH doesn't display a tool-bar item. */
10832 tool_bar_item_info (f
, glyph
, prop_idx
)
10834 struct glyph
*glyph
;
10841 /* This function can be called asynchronously, which means we must
10842 exclude any possibility that Fget_text_property signals an
10844 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10845 charpos
= max (0, charpos
);
10847 /* Get the text property `menu-item' at pos. The value of that
10848 property is the start index of this item's properties in
10849 F->tool_bar_items. */
10850 prop
= Fget_text_property (make_number (charpos
),
10851 Qmenu_item
, f
->current_tool_bar_string
);
10852 if (INTEGERP (prop
))
10854 *prop_idx
= XINT (prop
);
10864 /* Get information about the tool-bar item at position X/Y on frame F.
10865 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10866 the current matrix of the tool-bar window of F, or NULL if not
10867 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10868 item in F->tool_bar_items. Value is
10870 -1 if X/Y is not on a tool-bar item
10871 0 if X/Y is on the same item that was highlighted before.
10875 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10878 struct glyph
**glyph
;
10879 int *hpos
, *vpos
, *prop_idx
;
10881 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10882 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10885 /* Find the glyph under X/Y. */
10886 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10887 if (*glyph
== NULL
)
10890 /* Get the start of this tool-bar item's properties in
10891 f->tool_bar_items. */
10892 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10895 /* Is mouse on the highlighted item? */
10896 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10897 && *vpos
>= dpyinfo
->mouse_face_beg_row
10898 && *vpos
<= dpyinfo
->mouse_face_end_row
10899 && (*vpos
> dpyinfo
->mouse_face_beg_row
10900 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10901 && (*vpos
< dpyinfo
->mouse_face_end_row
10902 || *hpos
< dpyinfo
->mouse_face_end_col
10903 || dpyinfo
->mouse_face_past_end
))
10911 Handle mouse button event on the tool-bar of frame F, at
10912 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10913 0 for button release. MODIFIERS is event modifiers for button
10917 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10920 unsigned int modifiers
;
10922 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10923 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10924 int hpos
, vpos
, prop_idx
;
10925 struct glyph
*glyph
;
10926 Lisp_Object enabled_p
;
10928 /* If not on the highlighted tool-bar item, return. */
10929 frame_to_window_pixel_xy (w
, &x
, &y
);
10930 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10933 /* If item is disabled, do nothing. */
10934 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10935 if (NILP (enabled_p
))
10940 /* Show item in pressed state. */
10941 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10942 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10943 last_tool_bar_item
= prop_idx
;
10947 Lisp_Object key
, frame
;
10948 struct input_event event
;
10949 EVENT_INIT (event
);
10951 /* Show item in released state. */
10952 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10953 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10955 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10957 XSETFRAME (frame
, f
);
10958 event
.kind
= TOOL_BAR_EVENT
;
10959 event
.frame_or_window
= frame
;
10961 kbd_buffer_store_event (&event
);
10963 event
.kind
= TOOL_BAR_EVENT
;
10964 event
.frame_or_window
= frame
;
10966 event
.modifiers
= modifiers
;
10967 kbd_buffer_store_event (&event
);
10968 last_tool_bar_item
= -1;
10973 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10974 tool-bar window-relative coordinates X/Y. Called from
10975 note_mouse_highlight. */
10978 note_tool_bar_highlight (f
, x
, y
)
10982 Lisp_Object window
= f
->tool_bar_window
;
10983 struct window
*w
= XWINDOW (window
);
10984 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10986 struct glyph
*glyph
;
10987 struct glyph_row
*row
;
10989 Lisp_Object enabled_p
;
10991 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10992 int mouse_down_p
, rc
;
10994 /* Function note_mouse_highlight is called with negative x(y
10995 values when mouse moves outside of the frame. */
10996 if (x
<= 0 || y
<= 0)
10998 clear_mouse_face (dpyinfo
);
11002 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
11005 /* Not on tool-bar item. */
11006 clear_mouse_face (dpyinfo
);
11010 /* On same tool-bar item as before. */
11011 goto set_help_echo
;
11013 clear_mouse_face (dpyinfo
);
11015 /* Mouse is down, but on different tool-bar item? */
11016 mouse_down_p
= (dpyinfo
->grabbed
11017 && f
== last_mouse_frame
11018 && FRAME_LIVE_P (f
));
11020 && last_tool_bar_item
!= prop_idx
)
11023 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
11024 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
11026 /* If tool-bar item is not enabled, don't highlight it. */
11027 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
11028 if (!NILP (enabled_p
))
11030 /* Compute the x-position of the glyph. In front and past the
11031 image is a space. We include this in the highlighted area. */
11032 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
11033 for (i
= x
= 0; i
< hpos
; ++i
)
11034 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
11036 /* Record this as the current active region. */
11037 dpyinfo
->mouse_face_beg_col
= hpos
;
11038 dpyinfo
->mouse_face_beg_row
= vpos
;
11039 dpyinfo
->mouse_face_beg_x
= x
;
11040 dpyinfo
->mouse_face_beg_y
= row
->y
;
11041 dpyinfo
->mouse_face_past_end
= 0;
11043 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
11044 dpyinfo
->mouse_face_end_row
= vpos
;
11045 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
11046 dpyinfo
->mouse_face_end_y
= row
->y
;
11047 dpyinfo
->mouse_face_window
= window
;
11048 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
11050 /* Display it as active. */
11051 show_mouse_face (dpyinfo
, draw
);
11052 dpyinfo
->mouse_face_image_state
= draw
;
11057 /* Set help_echo_string to a help string to display for this tool-bar item.
11058 XTread_socket does the rest. */
11059 help_echo_object
= help_echo_window
= Qnil
;
11060 help_echo_pos
= -1;
11061 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
11062 if (NILP (help_echo_string
))
11063 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
11066 #endif /* HAVE_WINDOW_SYSTEM */
11070 /************************************************************************
11071 Horizontal scrolling
11072 ************************************************************************/
11074 static int hscroll_window_tree
P_ ((Lisp_Object
));
11075 static int hscroll_windows
P_ ((Lisp_Object
));
11077 /* For all leaf windows in the window tree rooted at WINDOW, set their
11078 hscroll value so that PT is (i) visible in the window, and (ii) so
11079 that it is not within a certain margin at the window's left and
11080 right border. Value is non-zero if any window's hscroll has been
11084 hscroll_window_tree (window
)
11085 Lisp_Object window
;
11087 int hscrolled_p
= 0;
11088 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
11089 int hscroll_step_abs
= 0;
11090 double hscroll_step_rel
= 0;
11092 if (hscroll_relative_p
)
11094 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
11095 if (hscroll_step_rel
< 0)
11097 hscroll_relative_p
= 0;
11098 hscroll_step_abs
= 0;
11101 else if (INTEGERP (Vhscroll_step
))
11103 hscroll_step_abs
= XINT (Vhscroll_step
);
11104 if (hscroll_step_abs
< 0)
11105 hscroll_step_abs
= 0;
11108 hscroll_step_abs
= 0;
11110 while (WINDOWP (window
))
11112 struct window
*w
= XWINDOW (window
);
11114 if (WINDOWP (w
->hchild
))
11115 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11116 else if (WINDOWP (w
->vchild
))
11117 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11118 else if (w
->cursor
.vpos
>= 0)
11121 int text_area_width
;
11122 struct glyph_row
*current_cursor_row
11123 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11124 struct glyph_row
*desired_cursor_row
11125 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11126 struct glyph_row
*cursor_row
11127 = (desired_cursor_row
->enabled_p
11128 ? desired_cursor_row
11129 : current_cursor_row
);
11131 text_area_width
= window_box_width (w
, TEXT_AREA
);
11133 /* Scroll when cursor is inside this scroll margin. */
11134 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11136 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11137 && ((XFASTINT (w
->hscroll
)
11138 && w
->cursor
.x
<= h_margin
)
11139 || (cursor_row
->enabled_p
11140 && cursor_row
->truncated_on_right_p
11141 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11145 struct buffer
*saved_current_buffer
;
11149 /* Find point in a display of infinite width. */
11150 saved_current_buffer
= current_buffer
;
11151 current_buffer
= XBUFFER (w
->buffer
);
11153 if (w
== XWINDOW (selected_window
))
11154 pt
= BUF_PT (current_buffer
);
11157 pt
= marker_position (w
->pointm
);
11158 pt
= max (BEGV
, pt
);
11162 /* Move iterator to pt starting at cursor_row->start in
11163 a line with infinite width. */
11164 init_to_row_start (&it
, w
, cursor_row
);
11165 it
.last_visible_x
= INFINITY
;
11166 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11167 current_buffer
= saved_current_buffer
;
11169 /* Position cursor in window. */
11170 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11171 hscroll
= max (0, (it
.current_x
11172 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11173 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11174 : (text_area_width
/ 2))))
11175 / FRAME_COLUMN_WIDTH (it
.f
);
11176 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11178 if (hscroll_relative_p
)
11179 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11182 wanted_x
= text_area_width
11183 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11186 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11190 if (hscroll_relative_p
)
11191 wanted_x
= text_area_width
* hscroll_step_rel
11194 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11197 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11199 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11201 /* Don't call Fset_window_hscroll if value hasn't
11202 changed because it will prevent redisplay
11204 if (XFASTINT (w
->hscroll
) != hscroll
)
11206 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11207 w
->hscroll
= make_number (hscroll
);
11216 /* Value is non-zero if hscroll of any leaf window has been changed. */
11217 return hscrolled_p
;
11221 /* Set hscroll so that cursor is visible and not inside horizontal
11222 scroll margins for all windows in the tree rooted at WINDOW. See
11223 also hscroll_window_tree above. Value is non-zero if any window's
11224 hscroll has been changed. If it has, desired matrices on the frame
11225 of WINDOW are cleared. */
11228 hscroll_windows (window
)
11229 Lisp_Object window
;
11231 int hscrolled_p
= hscroll_window_tree (window
);
11233 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11234 return hscrolled_p
;
11239 /************************************************************************
11241 ************************************************************************/
11243 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11244 to a non-zero value. This is sometimes handy to have in a debugger
11249 /* First and last unchanged row for try_window_id. */
11251 int debug_first_unchanged_at_end_vpos
;
11252 int debug_last_unchanged_at_beg_vpos
;
11254 /* Delta vpos and y. */
11256 int debug_dvpos
, debug_dy
;
11258 /* Delta in characters and bytes for try_window_id. */
11260 int debug_delta
, debug_delta_bytes
;
11262 /* Values of window_end_pos and window_end_vpos at the end of
11265 EMACS_INT debug_end_pos
, debug_end_vpos
;
11267 /* Append a string to W->desired_matrix->method. FMT is a printf
11268 format string. A1...A9 are a supplement for a variable-length
11269 argument list. If trace_redisplay_p is non-zero also printf the
11270 resulting string to stderr. */
11273 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11276 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11279 char *method
= w
->desired_matrix
->method
;
11280 int len
= strlen (method
);
11281 int size
= sizeof w
->desired_matrix
->method
;
11282 int remaining
= size
- len
- 1;
11284 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11285 if (len
&& remaining
)
11288 --remaining
, ++len
;
11291 strncpy (method
+ len
, buffer
, remaining
);
11293 if (trace_redisplay_p
)
11294 fprintf (stderr
, "%p (%s): %s\n",
11296 ((BUFFERP (w
->buffer
)
11297 && STRINGP (XBUFFER (w
->buffer
)->name
))
11298 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
11303 #endif /* GLYPH_DEBUG */
11306 /* Value is non-zero if all changes in window W, which displays
11307 current_buffer, are in the text between START and END. START is a
11308 buffer position, END is given as a distance from Z. Used in
11309 redisplay_internal for display optimization. */
11312 text_outside_line_unchanged_p (w
, start
, end
)
11316 int unchanged_p
= 1;
11318 /* If text or overlays have changed, see where. */
11319 if (XFASTINT (w
->last_modified
) < MODIFF
11320 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11322 /* Gap in the line? */
11323 if (GPT
< start
|| Z
- GPT
< end
)
11326 /* Changes start in front of the line, or end after it? */
11328 && (BEG_UNCHANGED
< start
- 1
11329 || END_UNCHANGED
< end
))
11332 /* If selective display, can't optimize if changes start at the
11333 beginning of the line. */
11335 && INTEGERP (current_buffer
->selective_display
)
11336 && XINT (current_buffer
->selective_display
) > 0
11337 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11340 /* If there are overlays at the start or end of the line, these
11341 may have overlay strings with newlines in them. A change at
11342 START, for instance, may actually concern the display of such
11343 overlay strings as well, and they are displayed on different
11344 lines. So, quickly rule out this case. (For the future, it
11345 might be desirable to implement something more telling than
11346 just BEG/END_UNCHANGED.) */
11349 if (BEG
+ BEG_UNCHANGED
== start
11350 && overlay_touches_p (start
))
11352 if (END_UNCHANGED
== end
11353 && overlay_touches_p (Z
- end
))
11357 /* Under bidi reordering, adding or deleting a character in the
11358 beginning of a paragraph, before the first strong directional
11359 character, can change the base direction of the paragraph (unless
11360 the buffer specifies a fixed paragraph direction), which will
11361 require to redisplay the whole paragraph. It might be worthwhile
11362 to find the paragraph limits and widen the range of redisplayed
11363 lines to that, but for now just give up this optimization. */
11364 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
11365 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
11369 return unchanged_p
;
11373 /* Do a frame update, taking possible shortcuts into account. This is
11374 the main external entry point for redisplay.
11376 If the last redisplay displayed an echo area message and that message
11377 is no longer requested, we clear the echo area or bring back the
11378 mini-buffer if that is in use. */
11383 redisplay_internal (0);
11388 overlay_arrow_string_or_property (var
)
11393 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11396 return Voverlay_arrow_string
;
11399 /* Return 1 if there are any overlay-arrows in current_buffer. */
11401 overlay_arrow_in_current_buffer_p ()
11405 for (vlist
= Voverlay_arrow_variable_list
;
11407 vlist
= XCDR (vlist
))
11409 Lisp_Object var
= XCAR (vlist
);
11412 if (!SYMBOLP (var
))
11414 val
= find_symbol_value (var
);
11416 && current_buffer
== XMARKER (val
)->buffer
)
11423 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11427 overlay_arrows_changed_p ()
11431 for (vlist
= Voverlay_arrow_variable_list
;
11433 vlist
= XCDR (vlist
))
11435 Lisp_Object var
= XCAR (vlist
);
11436 Lisp_Object val
, pstr
;
11438 if (!SYMBOLP (var
))
11440 val
= find_symbol_value (var
);
11441 if (!MARKERP (val
))
11443 if (! EQ (COERCE_MARKER (val
),
11444 Fget (var
, Qlast_arrow_position
))
11445 || ! (pstr
= overlay_arrow_string_or_property (var
),
11446 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11452 /* Mark overlay arrows to be updated on next redisplay. */
11455 update_overlay_arrows (up_to_date
)
11460 for (vlist
= Voverlay_arrow_variable_list
;
11462 vlist
= XCDR (vlist
))
11464 Lisp_Object var
= XCAR (vlist
);
11466 if (!SYMBOLP (var
))
11469 if (up_to_date
> 0)
11471 Lisp_Object val
= find_symbol_value (var
);
11472 Fput (var
, Qlast_arrow_position
,
11473 COERCE_MARKER (val
));
11474 Fput (var
, Qlast_arrow_string
,
11475 overlay_arrow_string_or_property (var
));
11477 else if (up_to_date
< 0
11478 || !NILP (Fget (var
, Qlast_arrow_position
)))
11480 Fput (var
, Qlast_arrow_position
, Qt
);
11481 Fput (var
, Qlast_arrow_string
, Qt
);
11487 /* Return overlay arrow string to display at row.
11488 Return integer (bitmap number) for arrow bitmap in left fringe.
11489 Return nil if no overlay arrow. */
11492 overlay_arrow_at_row (it
, row
)
11494 struct glyph_row
*row
;
11498 for (vlist
= Voverlay_arrow_variable_list
;
11500 vlist
= XCDR (vlist
))
11502 Lisp_Object var
= XCAR (vlist
);
11505 if (!SYMBOLP (var
))
11508 val
= find_symbol_value (var
);
11511 && current_buffer
== XMARKER (val
)->buffer
11512 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11514 if (FRAME_WINDOW_P (it
->f
)
11515 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11517 #ifdef HAVE_WINDOW_SYSTEM
11518 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11521 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11522 return make_number (fringe_bitmap
);
11525 return make_number (-1); /* Use default arrow bitmap */
11527 return overlay_arrow_string_or_property (var
);
11534 /* Return 1 if point moved out of or into a composition. Otherwise
11535 return 0. PREV_BUF and PREV_PT are the last point buffer and
11536 position. BUF and PT are the current point buffer and position. */
11539 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11540 struct buffer
*prev_buf
, *buf
;
11543 EMACS_INT start
, end
;
11545 Lisp_Object buffer
;
11547 XSETBUFFER (buffer
, buf
);
11548 /* Check a composition at the last point if point moved within the
11550 if (prev_buf
== buf
)
11553 /* Point didn't move. */
11556 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11557 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11558 && COMPOSITION_VALID_P (start
, end
, prop
)
11559 && start
< prev_pt
&& end
> prev_pt
)
11560 /* The last point was within the composition. Return 1 iff
11561 point moved out of the composition. */
11562 return (pt
<= start
|| pt
>= end
);
11565 /* Check a composition at the current point. */
11566 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11567 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11568 && COMPOSITION_VALID_P (start
, end
, prop
)
11569 && start
< pt
&& end
> pt
);
11573 /* Reconsider the setting of B->clip_changed which is displayed
11577 reconsider_clip_changes (w
, b
)
11581 if (b
->clip_changed
11582 && !NILP (w
->window_end_valid
)
11583 && w
->current_matrix
->buffer
== b
11584 && w
->current_matrix
->zv
== BUF_ZV (b
)
11585 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11586 b
->clip_changed
= 0;
11588 /* If display wasn't paused, and W is not a tool bar window, see if
11589 point has been moved into or out of a composition. In that case,
11590 we set b->clip_changed to 1 to force updating the screen. If
11591 b->clip_changed has already been set to 1, we can skip this
11593 if (!b
->clip_changed
11594 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11598 if (w
== XWINDOW (selected_window
))
11599 pt
= BUF_PT (current_buffer
);
11601 pt
= marker_position (w
->pointm
);
11603 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11604 || pt
!= XINT (w
->last_point
))
11605 && check_point_in_composition (w
->current_matrix
->buffer
,
11606 XINT (w
->last_point
),
11607 XBUFFER (w
->buffer
), pt
))
11608 b
->clip_changed
= 1;
11613 /* Select FRAME to forward the values of frame-local variables into C
11614 variables so that the redisplay routines can access those values
11618 select_frame_for_redisplay (frame
)
11621 Lisp_Object tail
, symbol
, val
;
11622 Lisp_Object old
= selected_frame
;
11623 struct Lisp_Symbol
*sym
;
11625 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11627 selected_frame
= frame
;
11631 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11632 if (CONSP (XCAR (tail
))
11633 && (symbol
= XCAR (XCAR (tail
)),
11635 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11637 (BUFFER_LOCAL_VALUEP (val
)))
11638 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11639 /* Use find_symbol_value rather than Fsymbol_value
11640 to avoid an error if it is void. */
11641 find_symbol_value (symbol
);
11642 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11646 #define STOP_POLLING \
11647 do { if (! polling_stopped_here) stop_polling (); \
11648 polling_stopped_here = 1; } while (0)
11650 #define RESUME_POLLING \
11651 do { if (polling_stopped_here) start_polling (); \
11652 polling_stopped_here = 0; } while (0)
11655 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11656 response to any user action; therefore, we should preserve the echo
11657 area. (Actually, our caller does that job.) Perhaps in the future
11658 avoid recentering windows if it is not necessary; currently that
11659 causes some problems. */
11662 redisplay_internal (preserve_echo_area
)
11663 int preserve_echo_area
;
11665 struct window
*w
= XWINDOW (selected_window
);
11668 int must_finish
= 0;
11669 struct text_pos tlbufpos
, tlendpos
;
11670 int number_of_visible_frames
;
11673 int polling_stopped_here
= 0;
11674 Lisp_Object old_frame
= selected_frame
;
11676 /* Non-zero means redisplay has to consider all windows on all
11677 frames. Zero means, only selected_window is considered. */
11678 int consider_all_windows_p
;
11680 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11682 /* No redisplay if running in batch mode or frame is not yet fully
11683 initialized, or redisplay is explicitly turned off by setting
11684 Vinhibit_redisplay. */
11685 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11686 || !NILP (Vinhibit_redisplay
))
11689 /* Don't examine these until after testing Vinhibit_redisplay.
11690 When Emacs is shutting down, perhaps because its connection to
11691 X has dropped, we should not look at them at all. */
11692 f
= XFRAME (w
->frame
);
11693 sf
= SELECTED_FRAME ();
11695 if (!f
->glyphs_initialized_p
)
11698 /* The flag redisplay_performed_directly_p is set by
11699 direct_output_for_insert when it already did the whole screen
11700 update necessary. */
11701 if (redisplay_performed_directly_p
)
11703 redisplay_performed_directly_p
= 0;
11704 if (!hscroll_windows (selected_window
))
11708 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11709 if (popup_activated ())
11713 /* I don't think this happens but let's be paranoid. */
11714 if (redisplaying_p
)
11717 /* Record a function that resets redisplaying_p to its old value
11718 when we leave this function. */
11719 count
= SPECPDL_INDEX ();
11720 record_unwind_protect (unwind_redisplay
,
11721 Fcons (make_number (redisplaying_p
), selected_frame
));
11723 specbind (Qinhibit_free_realized_faces
, Qnil
);
11726 Lisp_Object tail
, frame
;
11728 FOR_EACH_FRAME (tail
, frame
)
11730 struct frame
*f
= XFRAME (frame
);
11731 f
->already_hscrolled_p
= 0;
11736 if (!EQ (old_frame
, selected_frame
)
11737 && FRAME_LIVE_P (XFRAME (old_frame
)))
11738 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11739 selected_frame and selected_window to be temporarily out-of-sync so
11740 when we come back here via `goto retry', we need to resync because we
11741 may need to run Elisp code (via prepare_menu_bars). */
11742 select_frame_for_redisplay (old_frame
);
11745 reconsider_clip_changes (w
, current_buffer
);
11746 last_escape_glyph_frame
= NULL
;
11747 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11749 /* If new fonts have been loaded that make a glyph matrix adjustment
11750 necessary, do it. */
11751 if (fonts_changed_p
)
11753 adjust_glyphs (NULL
);
11754 ++windows_or_buffers_changed
;
11755 fonts_changed_p
= 0;
11758 /* If face_change_count is non-zero, init_iterator will free all
11759 realized faces, which includes the faces referenced from current
11760 matrices. So, we can't reuse current matrices in this case. */
11761 if (face_change_count
)
11762 ++windows_or_buffers_changed
;
11764 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11765 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11767 /* Since frames on a single ASCII terminal share the same
11768 display area, displaying a different frame means redisplay
11769 the whole thing. */
11770 windows_or_buffers_changed
++;
11771 SET_FRAME_GARBAGED (sf
);
11773 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11775 FRAME_TTY (sf
)->previous_frame
= sf
;
11778 /* Set the visible flags for all frames. Do this before checking
11779 for resized or garbaged frames; they want to know if their frames
11780 are visible. See the comment in frame.h for
11781 FRAME_SAMPLE_VISIBILITY. */
11783 Lisp_Object tail
, frame
;
11785 number_of_visible_frames
= 0;
11787 FOR_EACH_FRAME (tail
, frame
)
11789 struct frame
*f
= XFRAME (frame
);
11791 FRAME_SAMPLE_VISIBILITY (f
);
11792 if (FRAME_VISIBLE_P (f
))
11793 ++number_of_visible_frames
;
11794 clear_desired_matrices (f
);
11798 /* Notice any pending interrupt request to change frame size. */
11799 do_pending_window_change (1);
11801 /* Clear frames marked as garbaged. */
11802 if (frame_garbaged
)
11803 clear_garbaged_frames ();
11805 /* Build menubar and tool-bar items. */
11806 if (NILP (Vmemory_full
))
11807 prepare_menu_bars ();
11809 if (windows_or_buffers_changed
)
11810 update_mode_lines
++;
11812 /* Detect case that we need to write or remove a star in the mode line. */
11813 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11815 w
->update_mode_line
= Qt
;
11816 if (buffer_shared
> 1)
11817 update_mode_lines
++;
11820 /* Avoid invocation of point motion hooks by `current_column' below. */
11821 count1
= SPECPDL_INDEX ();
11822 specbind (Qinhibit_point_motion_hooks
, Qt
);
11824 /* If %c is in the mode line, update it if needed. */
11825 if (!NILP (w
->column_number_displayed
)
11826 /* This alternative quickly identifies a common case
11827 where no change is needed. */
11828 && !(PT
== XFASTINT (w
->last_point
)
11829 && XFASTINT (w
->last_modified
) >= MODIFF
11830 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11831 && (XFASTINT (w
->column_number_displayed
)
11832 != (int) current_column ())) /* iftc */
11833 w
->update_mode_line
= Qt
;
11835 unbind_to (count1
, Qnil
);
11837 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11839 /* The variable buffer_shared is set in redisplay_window and
11840 indicates that we redisplay a buffer in different windows. See
11842 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11843 || cursor_type_changed
);
11845 /* If specs for an arrow have changed, do thorough redisplay
11846 to ensure we remove any arrow that should no longer exist. */
11847 if (overlay_arrows_changed_p ())
11848 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11850 /* Normally the message* functions will have already displayed and
11851 updated the echo area, but the frame may have been trashed, or
11852 the update may have been preempted, so display the echo area
11853 again here. Checking message_cleared_p captures the case that
11854 the echo area should be cleared. */
11855 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11856 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11857 || (message_cleared_p
11858 && minibuf_level
== 0
11859 /* If the mini-window is currently selected, this means the
11860 echo-area doesn't show through. */
11861 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11863 int window_height_changed_p
= echo_area_display (0);
11866 /* If we don't display the current message, don't clear the
11867 message_cleared_p flag, because, if we did, we wouldn't clear
11868 the echo area in the next redisplay which doesn't preserve
11870 if (!display_last_displayed_message_p
)
11871 message_cleared_p
= 0;
11873 if (fonts_changed_p
)
11875 else if (window_height_changed_p
)
11877 consider_all_windows_p
= 1;
11878 ++update_mode_lines
;
11879 ++windows_or_buffers_changed
;
11881 /* If window configuration was changed, frames may have been
11882 marked garbaged. Clear them or we will experience
11883 surprises wrt scrolling. */
11884 if (frame_garbaged
)
11885 clear_garbaged_frames ();
11888 else if (EQ (selected_window
, minibuf_window
)
11889 && (current_buffer
->clip_changed
11890 || XFASTINT (w
->last_modified
) < MODIFF
11891 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11892 && resize_mini_window (w
, 0))
11894 /* Resized active mini-window to fit the size of what it is
11895 showing if its contents might have changed. */
11897 /* FIXME: this causes all frames to be updated, which seems unnecessary
11898 since only the current frame needs to be considered. This function needs
11899 to be rewritten with two variables, consider_all_windows and
11900 consider_all_frames. */
11901 consider_all_windows_p
= 1;
11902 ++windows_or_buffers_changed
;
11903 ++update_mode_lines
;
11905 /* If window configuration was changed, frames may have been
11906 marked garbaged. Clear them or we will experience
11907 surprises wrt scrolling. */
11908 if (frame_garbaged
)
11909 clear_garbaged_frames ();
11913 /* If showing the region, and mark has changed, we must redisplay
11914 the whole window. The assignment to this_line_start_pos prevents
11915 the optimization directly below this if-statement. */
11916 if (((!NILP (Vtransient_mark_mode
)
11917 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11918 != !NILP (w
->region_showing
))
11919 || (!NILP (w
->region_showing
)
11920 && !EQ (w
->region_showing
,
11921 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11922 CHARPOS (this_line_start_pos
) = 0;
11924 /* Optimize the case that only the line containing the cursor in the
11925 selected window has changed. Variables starting with this_ are
11926 set in display_line and record information about the line
11927 containing the cursor. */
11928 tlbufpos
= this_line_start_pos
;
11929 tlendpos
= this_line_end_pos
;
11930 if (!consider_all_windows_p
11931 && CHARPOS (tlbufpos
) > 0
11932 && NILP (w
->update_mode_line
)
11933 && !current_buffer
->clip_changed
11934 && !current_buffer
->prevent_redisplay_optimizations_p
11935 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11936 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11937 /* Make sure recorded data applies to current buffer, etc. */
11938 && this_line_buffer
== current_buffer
11939 && current_buffer
== XBUFFER (w
->buffer
)
11940 && NILP (w
->force_start
)
11941 && NILP (w
->optional_new_start
)
11942 /* Point must be on the line that we have info recorded about. */
11943 && PT
>= CHARPOS (tlbufpos
)
11944 && PT
<= Z
- CHARPOS (tlendpos
)
11945 /* All text outside that line, including its final newline,
11946 must be unchanged. */
11947 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11948 CHARPOS (tlendpos
)))
11950 if (CHARPOS (tlbufpos
) > BEGV
11951 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11952 && (CHARPOS (tlbufpos
) == ZV
11953 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11954 /* Former continuation line has disappeared by becoming empty. */
11956 else if (XFASTINT (w
->last_modified
) < MODIFF
11957 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11958 || MINI_WINDOW_P (w
))
11960 /* We have to handle the case of continuation around a
11961 wide-column character (see the comment in indent.c around
11964 For instance, in the following case:
11966 -------- Insert --------
11967 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11968 J_I_ ==> J_I_ `^^' are cursors.
11972 As we have to redraw the line above, we cannot use this
11976 int line_height_before
= this_line_pixel_height
;
11978 /* Note that start_display will handle the case that the
11979 line starting at tlbufpos is a continuation line. */
11980 start_display (&it
, w
, tlbufpos
);
11982 /* Implementation note: It this still necessary? */
11983 if (it
.current_x
!= this_line_start_x
)
11986 TRACE ((stderr
, "trying display optimization 1\n"));
11987 w
->cursor
.vpos
= -1;
11988 overlay_arrow_seen
= 0;
11989 it
.vpos
= this_line_vpos
;
11990 it
.current_y
= this_line_y
;
11991 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11992 display_line (&it
);
11994 /* If line contains point, is not continued,
11995 and ends at same distance from eob as before, we win. */
11996 if (w
->cursor
.vpos
>= 0
11997 /* Line is not continued, otherwise this_line_start_pos
11998 would have been set to 0 in display_line. */
11999 && CHARPOS (this_line_start_pos
)
12000 /* Line ends as before. */
12001 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
12002 /* Line has same height as before. Otherwise other lines
12003 would have to be shifted up or down. */
12004 && this_line_pixel_height
== line_height_before
)
12006 /* If this is not the window's last line, we must adjust
12007 the charstarts of the lines below. */
12008 if (it
.current_y
< it
.last_visible_y
)
12010 struct glyph_row
*row
12011 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
12012 int delta
, delta_bytes
;
12014 /* We used to distinguish between two cases here,
12015 conditioned by Z - CHARPOS (tlendpos) == ZV, for
12016 when the line ends in a newline or the end of the
12017 buffer's accessible portion. But both cases did
12018 the same, so they were collapsed. */
12020 - CHARPOS (tlendpos
)
12021 - MATRIX_ROW_START_CHARPOS (row
));
12022 delta_bytes
= (Z_BYTE
12023 - BYTEPOS (tlendpos
)
12024 - MATRIX_ROW_START_BYTEPOS (row
));
12026 increment_matrix_positions (w
->current_matrix
,
12027 this_line_vpos
+ 1,
12028 w
->current_matrix
->nrows
,
12029 delta
, delta_bytes
);
12032 /* If this row displays text now but previously didn't,
12033 or vice versa, w->window_end_vpos may have to be
12035 if ((it
.glyph_row
- 1)->displays_text_p
)
12037 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
12038 XSETINT (w
->window_end_vpos
, this_line_vpos
);
12040 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
12041 && this_line_vpos
> 0)
12042 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
12043 w
->window_end_valid
= Qnil
;
12045 /* Update hint: No need to try to scroll in update_window. */
12046 w
->desired_matrix
->no_scrolling_p
= 1;
12049 *w
->desired_matrix
->method
= 0;
12050 debug_method_add (w
, "optimization 1");
12052 #ifdef HAVE_WINDOW_SYSTEM
12053 update_window_fringes (w
, 0);
12060 else if (/* Cursor position hasn't changed. */
12061 PT
== XFASTINT (w
->last_point
)
12062 /* Make sure the cursor was last displayed
12063 in this window. Otherwise we have to reposition it. */
12064 && 0 <= w
->cursor
.vpos
12065 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
12069 do_pending_window_change (1);
12071 /* We used to always goto end_of_redisplay here, but this
12072 isn't enough if we have a blinking cursor. */
12073 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
12074 goto end_of_redisplay
;
12078 /* If highlighting the region, or if the cursor is in the echo area,
12079 then we can't just move the cursor. */
12080 else if (! (!NILP (Vtransient_mark_mode
)
12081 && !NILP (current_buffer
->mark_active
))
12082 && (EQ (selected_window
, current_buffer
->last_selected_window
)
12083 || highlight_nonselected_windows
)
12084 && NILP (w
->region_showing
)
12085 && NILP (Vshow_trailing_whitespace
)
12086 && !cursor_in_echo_area
)
12089 struct glyph_row
*row
;
12091 /* Skip from tlbufpos to PT and see where it is. Note that
12092 PT may be in invisible text. If so, we will end at the
12093 next visible position. */
12094 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
12095 NULL
, DEFAULT_FACE_ID
);
12096 it
.current_x
= this_line_start_x
;
12097 it
.current_y
= this_line_y
;
12098 it
.vpos
= this_line_vpos
;
12100 /* The call to move_it_to stops in front of PT, but
12101 moves over before-strings. */
12102 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12104 if (it
.vpos
== this_line_vpos
12105 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12108 xassert (this_line_vpos
== it
.vpos
);
12109 xassert (this_line_y
== it
.current_y
);
12110 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12112 *w
->desired_matrix
->method
= 0;
12113 debug_method_add (w
, "optimization 3");
12122 /* Text changed drastically or point moved off of line. */
12123 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12126 CHARPOS (this_line_start_pos
) = 0;
12127 consider_all_windows_p
|= buffer_shared
> 1;
12128 ++clear_face_cache_count
;
12129 #ifdef HAVE_WINDOW_SYSTEM
12130 ++clear_image_cache_count
;
12133 /* Build desired matrices, and update the display. If
12134 consider_all_windows_p is non-zero, do it for all windows on all
12135 frames. Otherwise do it for selected_window, only. */
12137 if (consider_all_windows_p
)
12139 Lisp_Object tail
, frame
;
12141 FOR_EACH_FRAME (tail
, frame
)
12142 XFRAME (frame
)->updated_p
= 0;
12144 /* Recompute # windows showing selected buffer. This will be
12145 incremented each time such a window is displayed. */
12148 FOR_EACH_FRAME (tail
, frame
)
12150 struct frame
*f
= XFRAME (frame
);
12152 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12154 if (! EQ (frame
, selected_frame
))
12155 /* Select the frame, for the sake of frame-local
12157 select_frame_for_redisplay (frame
);
12159 /* Mark all the scroll bars to be removed; we'll redeem
12160 the ones we want when we redisplay their windows. */
12161 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12162 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12164 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12165 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12167 /* The X error handler may have deleted that frame. */
12168 if (!FRAME_LIVE_P (f
))
12171 /* Any scroll bars which redisplay_windows should have
12172 nuked should now go away. */
12173 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12174 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12176 /* If fonts changed, display again. */
12177 /* ??? rms: I suspect it is a mistake to jump all the way
12178 back to retry here. It should just retry this frame. */
12179 if (fonts_changed_p
)
12182 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12184 /* See if we have to hscroll. */
12185 if (!f
->already_hscrolled_p
)
12187 f
->already_hscrolled_p
= 1;
12188 if (hscroll_windows (f
->root_window
))
12192 /* Prevent various kinds of signals during display
12193 update. stdio is not robust about handling
12194 signals, which can cause an apparent I/O
12196 if (interrupt_input
)
12197 unrequest_sigio ();
12200 /* Update the display. */
12201 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12202 pause
|= update_frame (f
, 0, 0);
12208 if (!EQ (old_frame
, selected_frame
)
12209 && FRAME_LIVE_P (XFRAME (old_frame
)))
12210 /* We played a bit fast-and-loose above and allowed selected_frame
12211 and selected_window to be temporarily out-of-sync but let's make
12212 sure this stays contained. */
12213 select_frame_for_redisplay (old_frame
);
12214 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12218 /* Do the mark_window_display_accurate after all windows have
12219 been redisplayed because this call resets flags in buffers
12220 which are needed for proper redisplay. */
12221 FOR_EACH_FRAME (tail
, frame
)
12223 struct frame
*f
= XFRAME (frame
);
12226 mark_window_display_accurate (f
->root_window
, 1);
12227 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12228 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12233 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12235 Lisp_Object mini_window
;
12236 struct frame
*mini_frame
;
12238 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12239 /* Use list_of_error, not Qerror, so that
12240 we catch only errors and don't run the debugger. */
12241 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12243 redisplay_window_error
);
12245 /* Compare desired and current matrices, perform output. */
12248 /* If fonts changed, display again. */
12249 if (fonts_changed_p
)
12252 /* Prevent various kinds of signals during display update.
12253 stdio is not robust about handling signals,
12254 which can cause an apparent I/O error. */
12255 if (interrupt_input
)
12256 unrequest_sigio ();
12259 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12261 if (hscroll_windows (selected_window
))
12264 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12265 pause
= update_frame (sf
, 0, 0);
12268 /* We may have called echo_area_display at the top of this
12269 function. If the echo area is on another frame, that may
12270 have put text on a frame other than the selected one, so the
12271 above call to update_frame would not have caught it. Catch
12273 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12274 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12276 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12278 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12279 pause
|= update_frame (mini_frame
, 0, 0);
12280 if (!pause
&& hscroll_windows (mini_window
))
12285 /* If display was paused because of pending input, make sure we do a
12286 thorough update the next time. */
12289 /* Prevent the optimization at the beginning of
12290 redisplay_internal that tries a single-line update of the
12291 line containing the cursor in the selected window. */
12292 CHARPOS (this_line_start_pos
) = 0;
12294 /* Let the overlay arrow be updated the next time. */
12295 update_overlay_arrows (0);
12297 /* If we pause after scrolling, some rows in the current
12298 matrices of some windows are not valid. */
12299 if (!WINDOW_FULL_WIDTH_P (w
)
12300 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12301 update_mode_lines
= 1;
12305 if (!consider_all_windows_p
)
12307 /* This has already been done above if
12308 consider_all_windows_p is set. */
12309 mark_window_display_accurate_1 (w
, 1);
12311 /* Say overlay arrows are up to date. */
12312 update_overlay_arrows (1);
12314 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12315 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12318 update_mode_lines
= 0;
12319 windows_or_buffers_changed
= 0;
12320 cursor_type_changed
= 0;
12323 /* Start SIGIO interrupts coming again. Having them off during the
12324 code above makes it less likely one will discard output, but not
12325 impossible, since there might be stuff in the system buffer here.
12326 But it is much hairier to try to do anything about that. */
12327 if (interrupt_input
)
12331 /* If a frame has become visible which was not before, redisplay
12332 again, so that we display it. Expose events for such a frame
12333 (which it gets when becoming visible) don't call the parts of
12334 redisplay constructing glyphs, so simply exposing a frame won't
12335 display anything in this case. So, we have to display these
12336 frames here explicitly. */
12339 Lisp_Object tail
, frame
;
12342 FOR_EACH_FRAME (tail
, frame
)
12344 int this_is_visible
= 0;
12346 if (XFRAME (frame
)->visible
)
12347 this_is_visible
= 1;
12348 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12349 if (XFRAME (frame
)->visible
)
12350 this_is_visible
= 1;
12352 if (this_is_visible
)
12356 if (new_count
!= number_of_visible_frames
)
12357 windows_or_buffers_changed
++;
12360 /* Change frame size now if a change is pending. */
12361 do_pending_window_change (1);
12363 /* If we just did a pending size change, or have additional
12364 visible frames, redisplay again. */
12365 if (windows_or_buffers_changed
&& !pause
)
12368 /* Clear the face cache eventually. */
12369 if (consider_all_windows_p
)
12371 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12373 clear_face_cache (0);
12374 clear_face_cache_count
= 0;
12376 #ifdef HAVE_WINDOW_SYSTEM
12377 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12379 clear_image_caches (Qnil
);
12380 clear_image_cache_count
= 0;
12382 #endif /* HAVE_WINDOW_SYSTEM */
12386 unbind_to (count
, Qnil
);
12391 /* Redisplay, but leave alone any recent echo area message unless
12392 another message has been requested in its place.
12394 This is useful in situations where you need to redisplay but no
12395 user action has occurred, making it inappropriate for the message
12396 area to be cleared. See tracking_off and
12397 wait_reading_process_output for examples of these situations.
12399 FROM_WHERE is an integer saying from where this function was
12400 called. This is useful for debugging. */
12403 redisplay_preserve_echo_area (from_where
)
12406 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12408 if (!NILP (echo_area_buffer
[1]))
12410 /* We have a previously displayed message, but no current
12411 message. Redisplay the previous message. */
12412 display_last_displayed_message_p
= 1;
12413 redisplay_internal (1);
12414 display_last_displayed_message_p
= 0;
12417 redisplay_internal (1);
12419 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12420 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12421 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12425 /* Function registered with record_unwind_protect in
12426 redisplay_internal. Reset redisplaying_p to the value it had
12427 before redisplay_internal was called, and clear
12428 prevent_freeing_realized_faces_p. It also selects the previously
12429 selected frame, unless it has been deleted (by an X connection
12430 failure during redisplay, for example). */
12433 unwind_redisplay (val
)
12436 Lisp_Object old_redisplaying_p
, old_frame
;
12438 old_redisplaying_p
= XCAR (val
);
12439 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12440 old_frame
= XCDR (val
);
12441 if (! EQ (old_frame
, selected_frame
)
12442 && FRAME_LIVE_P (XFRAME (old_frame
)))
12443 select_frame_for_redisplay (old_frame
);
12448 /* Mark the display of window W as accurate or inaccurate. If
12449 ACCURATE_P is non-zero mark display of W as accurate. If
12450 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12451 redisplay_internal is called. */
12454 mark_window_display_accurate_1 (w
, accurate_p
)
12458 if (BUFFERP (w
->buffer
))
12460 struct buffer
*b
= XBUFFER (w
->buffer
);
12463 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12464 w
->last_overlay_modified
12465 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12467 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12471 b
->clip_changed
= 0;
12472 b
->prevent_redisplay_optimizations_p
= 0;
12474 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12475 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12476 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12477 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12479 w
->current_matrix
->buffer
= b
;
12480 w
->current_matrix
->begv
= BUF_BEGV (b
);
12481 w
->current_matrix
->zv
= BUF_ZV (b
);
12483 w
->last_cursor
= w
->cursor
;
12484 w
->last_cursor_off_p
= w
->cursor_off_p
;
12486 if (w
== XWINDOW (selected_window
))
12487 w
->last_point
= make_number (BUF_PT (b
));
12489 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12495 w
->window_end_valid
= w
->buffer
;
12496 w
->update_mode_line
= Qnil
;
12501 /* Mark the display of windows in the window tree rooted at WINDOW as
12502 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12503 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12504 be redisplayed the next time redisplay_internal is called. */
12507 mark_window_display_accurate (window
, accurate_p
)
12508 Lisp_Object window
;
12513 for (; !NILP (window
); window
= w
->next
)
12515 w
= XWINDOW (window
);
12516 mark_window_display_accurate_1 (w
, accurate_p
);
12518 if (!NILP (w
->vchild
))
12519 mark_window_display_accurate (w
->vchild
, accurate_p
);
12520 if (!NILP (w
->hchild
))
12521 mark_window_display_accurate (w
->hchild
, accurate_p
);
12526 update_overlay_arrows (1);
12530 /* Force a thorough redisplay the next time by setting
12531 last_arrow_position and last_arrow_string to t, which is
12532 unequal to any useful value of Voverlay_arrow_... */
12533 update_overlay_arrows (-1);
12538 /* Return value in display table DP (Lisp_Char_Table *) for character
12539 C. Since a display table doesn't have any parent, we don't have to
12540 follow parent. Do not call this function directly but use the
12541 macro DISP_CHAR_VECTOR. */
12544 disp_char_vector (dp
, c
)
12545 struct Lisp_Char_Table
*dp
;
12550 if (ASCII_CHAR_P (c
))
12553 if (SUB_CHAR_TABLE_P (val
))
12554 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12560 XSETCHAR_TABLE (table
, dp
);
12561 val
= char_table_ref (table
, c
);
12570 /***********************************************************************
12572 ***********************************************************************/
12574 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12577 redisplay_windows (window
)
12578 Lisp_Object window
;
12580 while (!NILP (window
))
12582 struct window
*w
= XWINDOW (window
);
12584 if (!NILP (w
->hchild
))
12585 redisplay_windows (w
->hchild
);
12586 else if (!NILP (w
->vchild
))
12587 redisplay_windows (w
->vchild
);
12588 else if (!NILP (w
->buffer
))
12590 displayed_buffer
= XBUFFER (w
->buffer
);
12591 /* Use list_of_error, not Qerror, so that
12592 we catch only errors and don't run the debugger. */
12593 internal_condition_case_1 (redisplay_window_0
, window
,
12595 redisplay_window_error
);
12603 redisplay_window_error ()
12605 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12610 redisplay_window_0 (window
)
12611 Lisp_Object window
;
12613 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12614 redisplay_window (window
, 0);
12619 redisplay_window_1 (window
)
12620 Lisp_Object window
;
12622 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12623 redisplay_window (window
, 1);
12628 /* Increment GLYPH until it reaches END or CONDITION fails while
12629 adding (GLYPH)->pixel_width to X. */
12631 #define SKIP_GLYPHS(glyph, end, x, condition) \
12634 (x) += (glyph)->pixel_width; \
12637 while ((glyph) < (end) && (condition))
12640 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12641 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12642 which positions recorded in ROW differ from current buffer
12645 Return 0 if cursor is not on this row, 1 otherwise. */
12648 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12650 struct glyph_row
*row
;
12651 struct glyph_matrix
*matrix
;
12652 int delta
, delta_bytes
, dy
, dvpos
;
12654 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12655 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12656 struct glyph
*cursor
= NULL
;
12657 /* The last known character position in row. */
12658 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12661 EMACS_INT pt_old
= PT
- delta
;
12662 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12663 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12664 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12665 /* Non-zero means we've found a match for cursor position, but that
12666 glyph has the avoid_cursor_p flag set. */
12667 int match_with_avoid_cursor
= 0;
12668 /* Non-zero means we've seen at least one glyph that came from a
12670 int string_seen
= 0;
12671 /* Largest buffer position seen so far during scan of glyph row. */
12672 EMACS_INT bpos_max
= last_pos
;
12673 /* Last buffer position covered by an overlay string with an integer
12674 `cursor' property. */
12675 EMACS_INT bpos_covered
= 0;
12677 /* Skip over glyphs not having an object at the start and the end of
12678 the row. These are special glyphs like truncation marks on
12679 terminal frames. */
12680 if (row
->displays_text_p
)
12682 if (!row
->reversed_p
)
12685 && INTEGERP (glyph
->object
)
12686 && glyph
->charpos
< 0)
12688 x
+= glyph
->pixel_width
;
12692 && INTEGERP ((end
- 1)->object
)
12693 /* CHARPOS is zero for blanks inserted by
12694 extend_face_to_end_of_line. */
12695 && (end
- 1)->charpos
<= 0)
12697 glyph_before
= glyph
- 1;
12704 /* If the glyph row is reversed, we need to process it from back
12705 to front, so swap the edge pointers. */
12707 glyph
+= row
->used
[TEXT_AREA
] - 1;
12708 /* Reverse the known positions in the row. */
12709 last_pos
= pos_after
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12710 pos_before
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12712 while (glyph
> end
+ 1
12713 && INTEGERP (glyph
->object
)
12714 && glyph
->charpos
< 0)
12717 x
-= glyph
->pixel_width
;
12719 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12721 /* By default, put the cursor on the rightmost glyph. */
12722 for (g
= end
+ 1; g
< glyph
; g
++)
12723 x
+= g
->pixel_width
;
12726 && INTEGERP ((end
+ 1)->object
)
12727 && (end
+ 1)->charpos
<= 0)
12729 glyph_before
= glyph
+ 1;
12733 else if (row
->reversed_p
)
12735 /* In R2L rows that don't display text, put the cursor on the
12736 rightmost glyph. Case in point: an empty last line that is
12737 part of an R2L paragraph. */
12739 x
= -1; /* will be computed below, at lable compute_x */
12742 /* Step 1: Try to find the glyph whose character position
12743 corresponds to point. If that's not possible, find 2 glyphs
12744 whose character positions are the closest to point, one before
12745 point, the other after it. */
12746 if (!row
->reversed_p
)
12747 while (/* not marched to end of glyph row */
12749 /* glyph was not inserted by redisplay for internal purposes */
12750 && !INTEGERP (glyph
->object
))
12752 if (BUFFERP (glyph
->object
))
12754 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12756 if (glyph
->charpos
> bpos_max
)
12757 bpos_max
= glyph
->charpos
;
12758 if (!glyph
->avoid_cursor_p
)
12760 /* If we hit point, we've found the glyph on which to
12761 display the cursor. */
12764 match_with_avoid_cursor
= 0;
12767 /* See if we've found a better approximation to
12768 POS_BEFORE or to POS_AFTER. Note that we want the
12769 first (leftmost) glyph of all those that are the
12770 closest from below, and the last (rightmost) of all
12771 those from above. */
12772 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12774 pos_before
= glyph
->charpos
;
12775 glyph_before
= glyph
;
12777 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12779 pos_after
= glyph
->charpos
;
12780 glyph_after
= glyph
;
12783 else if (dpos
== 0)
12784 match_with_avoid_cursor
= 1;
12786 else if (STRINGP (glyph
->object
))
12788 Lisp_Object chprop
;
12789 int glyph_pos
= glyph
->charpos
;
12791 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12793 if (INTEGERP (chprop
))
12795 bpos_covered
= bpos_max
+ XINT (chprop
);
12796 /* If the `cursor' property covers buffer positions up
12797 to and including point, we should display cursor on
12799 /* Implementation note: bpos_max == pt_old when, e.g.,
12800 we are in an empty line, where bpos_max is set to
12801 MATRIX_ROW_START_CHARPOS, see above. */
12802 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12811 x
+= glyph
->pixel_width
;
12814 else if (glyph
> end
) /* row is reversed */
12815 while (!INTEGERP (glyph
->object
))
12817 if (BUFFERP (glyph
->object
))
12819 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12821 if (glyph
->charpos
> bpos_max
)
12822 bpos_max
= glyph
->charpos
;
12823 if (!glyph
->avoid_cursor_p
)
12827 match_with_avoid_cursor
= 0;
12830 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12832 pos_before
= glyph
->charpos
;
12833 glyph_before
= glyph
;
12835 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12837 pos_after
= glyph
->charpos
;
12838 glyph_after
= glyph
;
12841 else if (dpos
== 0)
12842 match_with_avoid_cursor
= 1;
12844 else if (STRINGP (glyph
->object
))
12846 Lisp_Object chprop
;
12847 int glyph_pos
= glyph
->charpos
;
12849 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12851 if (INTEGERP (chprop
))
12853 bpos_covered
= bpos_max
+ XINT (chprop
);
12854 /* If the `cursor' property covers buffer positions up
12855 to and including point, we should display cursor on
12857 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12868 x
-= glyph
->pixel_width
;
12871 /* Step 2: If we didn't find an exact match for point, we need to
12872 look for a proper place to put the cursor among glyphs between
12873 GLYPH_BEFORE and GLYPH_AFTER. */
12874 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12875 && bpos_covered
< pt_old
)
12877 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12879 EMACS_INT ellipsis_pos
;
12881 /* Scan back over the ellipsis glyphs. */
12882 if (!row
->reversed_p
)
12884 ellipsis_pos
= (glyph
- 1)->charpos
;
12885 while (glyph
> row
->glyphs
[TEXT_AREA
]
12886 && (glyph
- 1)->charpos
== ellipsis_pos
)
12887 glyph
--, x
-= glyph
->pixel_width
;
12888 /* That loop always goes one position too far, including
12889 the glyph before the ellipsis. So scan forward over
12891 x
+= glyph
->pixel_width
;
12894 else /* row is reversed */
12896 ellipsis_pos
= (glyph
+ 1)->charpos
;
12897 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12898 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12899 glyph
++, x
+= glyph
->pixel_width
;
12900 x
-= glyph
->pixel_width
;
12904 else if (match_with_avoid_cursor
12905 /* zero-width characters produce no glyphs */
12906 || eabs (glyph_after
- glyph_before
) == 1)
12908 cursor
= glyph_after
;
12911 else if (string_seen
)
12913 int incr
= row
->reversed_p
? -1 : +1;
12915 /* Need to find the glyph that came out of a string which is
12916 present at point. That glyph is somewhere between
12917 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12918 positioned between POS_BEFORE and POS_AFTER in the
12920 struct glyph
*stop
= glyph_after
;
12921 EMACS_INT pos
= pos_before
;
12924 for (glyph
= glyph_before
+ incr
;
12925 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12928 /* Any glyphs that come from the buffer are here because
12929 of bidi reordering. Skip them, and only pay
12930 attention to glyphs that came from some string. */
12931 if (STRINGP (glyph
->object
))
12936 str
= glyph
->object
;
12937 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12940 /* If the string from which this glyph came is
12941 found in the buffer at point, then we've
12942 found the glyph we've been looking for. */
12945 /* The glyphs from this string could have
12946 been reordered. Find the one with the
12947 smallest string position. Or there could
12948 be a character in the string with the
12949 `cursor' property, which means display
12950 cursor on that character's glyph. */
12951 int strpos
= glyph
->charpos
;
12954 for (glyph
+= incr
;
12955 EQ (glyph
->object
, str
);
12959 int gpos
= glyph
->charpos
;
12961 cprop
= Fget_char_property (make_number (gpos
),
12969 if (glyph
->charpos
< strpos
)
12971 strpos
= glyph
->charpos
;
12978 pos
= tem
+ 1; /* don't find previous instances */
12980 /* This string is not what we want; skip all of the
12981 glyphs that came from it. */
12984 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12985 && EQ (glyph
->object
, str
));
12991 /* If we reached the end of the line, and END was from a string,
12992 the cursor is not on this line. */
12994 && STRINGP ((glyph
- incr
)->object
)
12995 && row
->continued_p
)
13001 if (cursor
!= NULL
)
13007 /* Need to compute x that corresponds to GLYPH. */
13008 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
13010 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
13012 x
+= g
->pixel_width
;
13016 /* ROW could be part of a continued line, which might have other
13017 rows whose start and end charpos occlude point. Only set
13018 w->cursor if we found a better approximation to the cursor
13019 position than we have from previously examined rows. */
13020 if (w
->cursor
.vpos
>= 0
13021 /* Make sure cursor.vpos specifies a row whose start and end
13022 charpos occlude point. This is because some callers of this
13023 function leave cursor.vpos at the row where the cursor was
13024 displayed during the last redisplay cycle. */
13025 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
13026 && pt_old
< MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
13029 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
13031 /* Keep the candidate whose buffer position is the closest to
13033 if (BUFFERP (g1
->object
)
13034 && (g1
->charpos
== pt_old
/* an exact match always wins */
13035 || (BUFFERP (glyph
->object
)
13036 && eabs (g1
->charpos
- pt_old
)
13037 < eabs (glyph
->charpos
- pt_old
))))
13039 /* If this candidate gives an exact match, use that. */
13040 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
13041 /* Otherwise, keep the candidate that comes from a row
13042 spanning less buffer positions. This may win when one or
13043 both candidate positions are on glyphs that came from
13044 display strings, for which we cannot compare buffer
13046 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13047 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
13048 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
13051 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
13053 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
13054 w
->cursor
.y
= row
->y
+ dy
;
13056 if (w
== XWINDOW (selected_window
))
13058 if (!row
->continued_p
13059 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
13062 this_line_buffer
= XBUFFER (w
->buffer
);
13064 CHARPOS (this_line_start_pos
)
13065 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
13066 BYTEPOS (this_line_start_pos
)
13067 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
13069 CHARPOS (this_line_end_pos
)
13070 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
13071 BYTEPOS (this_line_end_pos
)
13072 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
13074 this_line_y
= w
->cursor
.y
;
13075 this_line_pixel_height
= row
->height
;
13076 this_line_vpos
= w
->cursor
.vpos
;
13077 this_line_start_x
= row
->x
;
13080 CHARPOS (this_line_start_pos
) = 0;
13087 /* Run window scroll functions, if any, for WINDOW with new window
13088 start STARTP. Sets the window start of WINDOW to that position.
13090 We assume that the window's buffer is really current. */
13092 static INLINE
struct text_pos
13093 run_window_scroll_functions (window
, startp
)
13094 Lisp_Object window
;
13095 struct text_pos startp
;
13097 struct window
*w
= XWINDOW (window
);
13098 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
13100 if (current_buffer
!= XBUFFER (w
->buffer
))
13103 if (!NILP (Vwindow_scroll_functions
))
13105 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
13106 make_number (CHARPOS (startp
)));
13107 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13108 /* In case the hook functions switch buffers. */
13109 if (current_buffer
!= XBUFFER (w
->buffer
))
13110 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13117 /* Make sure the line containing the cursor is fully visible.
13118 A value of 1 means there is nothing to be done.
13119 (Either the line is fully visible, or it cannot be made so,
13120 or we cannot tell.)
13122 If FORCE_P is non-zero, return 0 even if partial visible cursor row
13123 is higher than window.
13125 A value of 0 means the caller should do scrolling
13126 as if point had gone off the screen. */
13129 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
13132 int current_matrix_p
;
13134 struct glyph_matrix
*matrix
;
13135 struct glyph_row
*row
;
13138 if (!make_cursor_line_fully_visible_p
)
13141 /* It's not always possible to find the cursor, e.g, when a window
13142 is full of overlay strings. Don't do anything in that case. */
13143 if (w
->cursor
.vpos
< 0)
13146 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13147 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13149 /* If the cursor row is not partially visible, there's nothing to do. */
13150 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13153 /* If the row the cursor is in is taller than the window's height,
13154 it's not clear what to do, so do nothing. */
13155 window_height
= window_box_height (w
);
13156 if (row
->height
>= window_height
)
13158 if (!force_p
|| MINI_WINDOW_P (w
)
13159 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13166 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13167 non-zero means only WINDOW is redisplayed in redisplay_internal.
13168 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13169 in redisplay_window to bring a partially visible line into view in
13170 the case that only the cursor has moved.
13172 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13173 last screen line's vertical height extends past the end of the screen.
13177 1 if scrolling succeeded
13179 0 if scrolling didn't find point.
13181 -1 if new fonts have been loaded so that we must interrupt
13182 redisplay, adjust glyph matrices, and try again. */
13188 SCROLLING_NEED_LARGER_MATRICES
13192 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
13193 scroll_step
, temp_scroll_step
, last_line_misfit
)
13194 Lisp_Object window
;
13195 int just_this_one_p
;
13196 EMACS_INT scroll_conservatively
, scroll_step
;
13197 int temp_scroll_step
;
13198 int last_line_misfit
;
13200 struct window
*w
= XWINDOW (window
);
13201 struct frame
*f
= XFRAME (w
->frame
);
13202 struct text_pos pos
, startp
;
13204 int this_scroll_margin
, scroll_max
, rc
, height
;
13205 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13206 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13207 Lisp_Object aggressive
;
13208 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13211 debug_method_add (w
, "try_scrolling");
13214 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13216 /* Compute scroll margin height in pixels. We scroll when point is
13217 within this distance from the top or bottom of the window. */
13218 if (scroll_margin
> 0)
13219 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13220 * FRAME_LINE_HEIGHT (f
);
13222 this_scroll_margin
= 0;
13224 /* Force scroll_conservatively to have a reasonable value, to avoid
13225 overflow while computing how much to scroll. Note that the user
13226 can supply scroll-conservatively equal to `most-positive-fixnum',
13227 which can be larger than INT_MAX. */
13228 if (scroll_conservatively
> scroll_limit
)
13230 scroll_conservatively
= scroll_limit
;
13231 scroll_max
= INT_MAX
;
13233 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13234 /* Compute how much we should try to scroll maximally to bring
13235 point into view. */
13236 scroll_max
= (max (scroll_step
,
13237 max (scroll_conservatively
, temp_scroll_step
))
13238 * FRAME_LINE_HEIGHT (f
));
13239 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13240 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13241 /* We're trying to scroll because of aggressive scrolling but no
13242 scroll_step is set. Choose an arbitrary one. */
13243 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13249 /* Decide whether to scroll down. */
13250 if (PT
> CHARPOS (startp
))
13252 int scroll_margin_y
;
13254 /* Compute the pixel ypos of the scroll margin, then move it to
13255 either that ypos or PT, whichever comes first. */
13256 start_display (&it
, w
, startp
);
13257 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13258 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13259 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13260 (MOVE_TO_POS
| MOVE_TO_Y
));
13262 if (PT
> CHARPOS (it
.current
.pos
))
13264 int y0
= line_bottom_y (&it
);
13266 /* Compute the distance from the scroll margin to PT
13267 (including the height of the cursor line). Moving the
13268 iterator unconditionally to PT can be slow if PT is far
13269 away, so stop 10 lines past the window bottom (is there a
13270 way to do the right thing quickly?). */
13271 move_it_to (&it
, PT
, -1,
13272 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
13273 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13274 dy
= line_bottom_y (&it
) - y0
;
13276 if (dy
> scroll_max
)
13277 return SCROLLING_FAILED
;
13285 /* Point is in or below the bottom scroll margin, so move the
13286 window start down. If scrolling conservatively, move it just
13287 enough down to make point visible. If scroll_step is set,
13288 move it down by scroll_step. */
13289 if (scroll_conservatively
)
13291 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13292 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13293 else if (scroll_step
|| temp_scroll_step
)
13294 amount_to_scroll
= scroll_max
;
13297 aggressive
= current_buffer
->scroll_up_aggressively
;
13298 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13299 if (NUMBERP (aggressive
))
13301 double float_amount
= XFLOATINT (aggressive
) * height
;
13302 amount_to_scroll
= float_amount
;
13303 if (amount_to_scroll
== 0 && float_amount
> 0)
13304 amount_to_scroll
= 1;
13308 if (amount_to_scroll
<= 0)
13309 return SCROLLING_FAILED
;
13311 start_display (&it
, w
, startp
);
13312 move_it_vertically (&it
, amount_to_scroll
);
13314 /* If STARTP is unchanged, move it down another screen line. */
13315 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13316 move_it_by_lines (&it
, 1, 1);
13317 startp
= it
.current
.pos
;
13321 struct text_pos scroll_margin_pos
= startp
;
13323 /* See if point is inside the scroll margin at the top of the
13325 if (this_scroll_margin
)
13327 start_display (&it
, w
, startp
);
13328 move_it_vertically (&it
, this_scroll_margin
);
13329 scroll_margin_pos
= it
.current
.pos
;
13332 if (PT
< CHARPOS (scroll_margin_pos
))
13334 /* Point is in the scroll margin at the top of the window or
13335 above what is displayed in the window. */
13338 /* Compute the vertical distance from PT to the scroll
13339 margin position. Give up if distance is greater than
13341 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13342 start_display (&it
, w
, pos
);
13344 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13345 it
.last_visible_y
, -1,
13346 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13347 dy
= it
.current_y
- y0
;
13348 if (dy
> scroll_max
)
13349 return SCROLLING_FAILED
;
13351 /* Compute new window start. */
13352 start_display (&it
, w
, startp
);
13354 if (scroll_conservatively
)
13356 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13357 else if (scroll_step
|| temp_scroll_step
)
13358 amount_to_scroll
= scroll_max
;
13361 aggressive
= current_buffer
->scroll_down_aggressively
;
13362 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13363 if (NUMBERP (aggressive
))
13365 double float_amount
= XFLOATINT (aggressive
) * height
;
13366 amount_to_scroll
= float_amount
;
13367 if (amount_to_scroll
== 0 && float_amount
> 0)
13368 amount_to_scroll
= 1;
13372 if (amount_to_scroll
<= 0)
13373 return SCROLLING_FAILED
;
13375 move_it_vertically_backward (&it
, amount_to_scroll
);
13376 startp
= it
.current
.pos
;
13380 /* Run window scroll functions. */
13381 startp
= run_window_scroll_functions (window
, startp
);
13383 /* Display the window. Give up if new fonts are loaded, or if point
13385 if (!try_window (window
, startp
, 0))
13386 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13387 else if (w
->cursor
.vpos
< 0)
13389 clear_glyph_matrix (w
->desired_matrix
);
13390 rc
= SCROLLING_FAILED
;
13394 /* Maybe forget recorded base line for line number display. */
13395 if (!just_this_one_p
13396 || current_buffer
->clip_changed
13397 || BEG_UNCHANGED
< CHARPOS (startp
))
13398 w
->base_line_number
= Qnil
;
13400 /* If cursor ends up on a partially visible line,
13401 treat that as being off the bottom of the screen. */
13402 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13404 clear_glyph_matrix (w
->desired_matrix
);
13405 ++extra_scroll_margin_lines
;
13408 rc
= SCROLLING_SUCCESS
;
13415 /* Compute a suitable window start for window W if display of W starts
13416 on a continuation line. Value is non-zero if a new window start
13419 The new window start will be computed, based on W's width, starting
13420 from the start of the continued line. It is the start of the
13421 screen line with the minimum distance from the old start W->start. */
13424 compute_window_start_on_continuation_line (w
)
13427 struct text_pos pos
, start_pos
;
13428 int window_start_changed_p
= 0;
13430 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13432 /* If window start is on a continuation line... Window start may be
13433 < BEGV in case there's invisible text at the start of the
13434 buffer (M-x rmail, for example). */
13435 if (CHARPOS (start_pos
) > BEGV
13436 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13439 struct glyph_row
*row
;
13441 /* Handle the case that the window start is out of range. */
13442 if (CHARPOS (start_pos
) < BEGV
)
13443 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13444 else if (CHARPOS (start_pos
) > ZV
)
13445 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13447 /* Find the start of the continued line. This should be fast
13448 because scan_buffer is fast (newline cache). */
13449 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13450 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13451 row
, DEFAULT_FACE_ID
);
13452 reseat_at_previous_visible_line_start (&it
);
13454 /* If the line start is "too far" away from the window start,
13455 say it takes too much time to compute a new window start. */
13456 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13457 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13459 int min_distance
, distance
;
13461 /* Move forward by display lines to find the new window
13462 start. If window width was enlarged, the new start can
13463 be expected to be > the old start. If window width was
13464 decreased, the new window start will be < the old start.
13465 So, we're looking for the display line start with the
13466 minimum distance from the old window start. */
13467 pos
= it
.current
.pos
;
13468 min_distance
= INFINITY
;
13469 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13470 distance
< min_distance
)
13472 min_distance
= distance
;
13473 pos
= it
.current
.pos
;
13474 move_it_by_lines (&it
, 1, 0);
13477 /* Set the window start there. */
13478 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13479 window_start_changed_p
= 1;
13483 return window_start_changed_p
;
13487 /* Try cursor movement in case text has not changed in window WINDOW,
13488 with window start STARTP. Value is
13490 CURSOR_MOVEMENT_SUCCESS if successful
13492 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13494 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13495 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13496 we want to scroll as if scroll-step were set to 1. See the code.
13498 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13499 which case we have to abort this redisplay, and adjust matrices
13504 CURSOR_MOVEMENT_SUCCESS
,
13505 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13506 CURSOR_MOVEMENT_MUST_SCROLL
,
13507 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13511 try_cursor_movement (window
, startp
, scroll_step
)
13512 Lisp_Object window
;
13513 struct text_pos startp
;
13516 struct window
*w
= XWINDOW (window
);
13517 struct frame
*f
= XFRAME (w
->frame
);
13518 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13521 if (inhibit_try_cursor_movement
)
13525 /* Handle case where text has not changed, only point, and it has
13526 not moved off the frame. */
13527 if (/* Point may be in this window. */
13528 PT
>= CHARPOS (startp
)
13529 /* Selective display hasn't changed. */
13530 && !current_buffer
->clip_changed
13531 /* Function force-mode-line-update is used to force a thorough
13532 redisplay. It sets either windows_or_buffers_changed or
13533 update_mode_lines. So don't take a shortcut here for these
13535 && !update_mode_lines
13536 && !windows_or_buffers_changed
13537 && !cursor_type_changed
13538 /* Can't use this case if highlighting a region. When a
13539 region exists, cursor movement has to do more than just
13541 && !(!NILP (Vtransient_mark_mode
)
13542 && !NILP (current_buffer
->mark_active
))
13543 && NILP (w
->region_showing
)
13544 && NILP (Vshow_trailing_whitespace
)
13545 /* Right after splitting windows, last_point may be nil. */
13546 && INTEGERP (w
->last_point
)
13547 /* This code is not used for mini-buffer for the sake of the case
13548 of redisplaying to replace an echo area message; since in
13549 that case the mini-buffer contents per se are usually
13550 unchanged. This code is of no real use in the mini-buffer
13551 since the handling of this_line_start_pos, etc., in redisplay
13552 handles the same cases. */
13553 && !EQ (window
, minibuf_window
)
13554 /* When splitting windows or for new windows, it happens that
13555 redisplay is called with a nil window_end_vpos or one being
13556 larger than the window. This should really be fixed in
13557 window.c. I don't have this on my list, now, so we do
13558 approximately the same as the old redisplay code. --gerd. */
13559 && INTEGERP (w
->window_end_vpos
)
13560 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13561 && (FRAME_WINDOW_P (f
)
13562 || !overlay_arrow_in_current_buffer_p ()))
13564 int this_scroll_margin
, top_scroll_margin
;
13565 struct glyph_row
*row
= NULL
;
13568 debug_method_add (w
, "cursor movement");
13571 /* Scroll if point within this distance from the top or bottom
13572 of the window. This is a pixel value. */
13573 if (scroll_margin
> 0)
13575 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13576 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13579 this_scroll_margin
= 0;
13581 top_scroll_margin
= this_scroll_margin
;
13582 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13583 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13585 /* Start with the row the cursor was displayed during the last
13586 not paused redisplay. Give up if that row is not valid. */
13587 if (w
->last_cursor
.vpos
< 0
13588 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13589 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13592 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13593 if (row
->mode_line_p
)
13595 if (!row
->enabled_p
)
13596 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13597 /* If rows are bidi-reordered, back up until we find a row
13598 that does not belong to a continuation line. This is
13599 because we must consider all rows of a continued line as
13600 candidates for cursor positioning, since row start and
13601 end positions change non-linearly with vertical position
13603 /* FIXME: Revisit this when glyph ``spilling'' in
13604 continuation lines' rows is implemented for
13605 bidi-reordered rows. */
13606 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13608 while (MATRIX_ROW_CONTINUATION_LINE_P (row
))
13610 xassert (row
->enabled_p
);
13612 /* If we hit the beginning of the displayed portion
13613 without finding the first row of a continued
13615 if (row
<= w
->current_matrix
->rows
)
13617 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13625 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13628 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13630 if (PT
> XFASTINT (w
->last_point
))
13632 /* Point has moved forward. */
13633 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13634 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13636 xassert (row
->enabled_p
);
13640 /* The end position of a row equals the start position
13641 of the next row. If PT is there, we would rather
13642 display it in the next line. */
13643 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13644 && MATRIX_ROW_END_CHARPOS (row
) == PT
13645 && !cursor_row_p (w
, row
))
13648 /* If within the scroll margin, scroll. Note that
13649 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13650 the next line would be drawn, and that
13651 this_scroll_margin can be zero. */
13652 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13653 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13654 /* Line is completely visible last line in window
13655 and PT is to be set in the next line. */
13656 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13657 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13658 && !row
->ends_at_zv_p
13659 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13662 else if (PT
< XFASTINT (w
->last_point
))
13664 /* Cursor has to be moved backward. Note that PT >=
13665 CHARPOS (startp) because of the outer if-statement. */
13666 while (!row
->mode_line_p
13667 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13668 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13669 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13670 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13671 row
> w
->current_matrix
->rows
13672 && (row
-1)->ends_in_newline_from_string_p
))))
13673 && (row
->y
> top_scroll_margin
13674 || CHARPOS (startp
) == BEGV
))
13676 xassert (row
->enabled_p
);
13680 /* Consider the following case: Window starts at BEGV,
13681 there is invisible, intangible text at BEGV, so that
13682 display starts at some point START > BEGV. It can
13683 happen that we are called with PT somewhere between
13684 BEGV and START. Try to handle that case. */
13685 if (row
< w
->current_matrix
->rows
13686 || row
->mode_line_p
)
13688 row
= w
->current_matrix
->rows
;
13689 if (row
->mode_line_p
)
13693 /* Due to newlines in overlay strings, we may have to
13694 skip forward over overlay strings. */
13695 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13696 && MATRIX_ROW_END_CHARPOS (row
) == PT
13697 && !cursor_row_p (w
, row
))
13700 /* If within the scroll margin, scroll. */
13701 if (row
->y
< top_scroll_margin
13702 && CHARPOS (startp
) != BEGV
)
13707 /* Cursor did not move. So don't scroll even if cursor line
13708 is partially visible, as it was so before. */
13709 rc
= CURSOR_MOVEMENT_SUCCESS
;
13712 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13713 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13715 /* if PT is not in the glyph row, give up. */
13716 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13718 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13719 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13720 && make_cursor_line_fully_visible_p
)
13722 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13723 && !row
->ends_at_zv_p
13724 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13725 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13726 else if (row
->height
> window_box_height (w
))
13728 /* If we end up in a partially visible line, let's
13729 make it fully visible, except when it's taller
13730 than the window, in which case we can't do much
13733 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13737 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13738 if (!cursor_row_fully_visible_p (w
, 0, 1))
13739 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13741 rc
= CURSOR_MOVEMENT_SUCCESS
;
13745 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13746 else if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
13748 /* With bidi-reordered rows, there could be more than
13749 one candidate row whose start and end positions
13750 occlude point. We need to let set_cursor_from_row
13751 find the best candidate. */
13752 /* FIXME: Revisit this when glyph ``spilling'' in
13753 continuation lines' rows is implemented for
13754 bidi-reordered rows. */
13759 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
13761 /* As soon as we've found the first suitable row
13762 whose ends_at_zv_p flag is set, we are done. */
13764 && MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
)
13766 rc
= CURSOR_MOVEMENT_SUCCESS
;
13771 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13772 && MATRIX_ROW_START_CHARPOS (row
) <= PT
13773 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
13774 && cursor_row_p (w
, row
));
13775 /* If we didn't find any candidate rows, or exited the
13776 loop before all the candidates were examined, signal
13777 to the caller that this method failed. */
13778 if (rc
!= CURSOR_MOVEMENT_SUCCESS
13780 || (MATRIX_ROW_START_CHARPOS (row
) <= PT
13781 && PT
<= MATRIX_ROW_END_CHARPOS (row
))))
13782 rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13784 rc
= CURSOR_MOVEMENT_SUCCESS
;
13790 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13792 rc
= CURSOR_MOVEMENT_SUCCESS
;
13797 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13798 && MATRIX_ROW_START_CHARPOS (row
) == PT
13799 && cursor_row_p (w
, row
));
13808 set_vertical_scroll_bar (w
)
13811 int start
, end
, whole
;
13813 /* Calculate the start and end positions for the current window.
13814 At some point, it would be nice to choose between scrollbars
13815 which reflect the whole buffer size, with special markers
13816 indicating narrowing, and scrollbars which reflect only the
13819 Note that mini-buffers sometimes aren't displaying any text. */
13820 if (!MINI_WINDOW_P (w
)
13821 || (w
== XWINDOW (minibuf_window
)
13822 && NILP (echo_area_buffer
[0])))
13824 struct buffer
*buf
= XBUFFER (w
->buffer
);
13825 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13826 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13827 /* I don't think this is guaranteed to be right. For the
13828 moment, we'll pretend it is. */
13829 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13833 if (whole
< (end
- start
))
13834 whole
= end
- start
;
13837 start
= end
= whole
= 0;
13839 /* Indicate what this scroll bar ought to be displaying now. */
13840 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13841 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13842 (w
, end
- start
, whole
, start
);
13846 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13847 selected_window is redisplayed.
13849 We can return without actually redisplaying the window if
13850 fonts_changed_p is nonzero. In that case, redisplay_internal will
13854 redisplay_window (window
, just_this_one_p
)
13855 Lisp_Object window
;
13856 int just_this_one_p
;
13858 struct window
*w
= XWINDOW (window
);
13859 struct frame
*f
= XFRAME (w
->frame
);
13860 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13861 struct buffer
*old
= current_buffer
;
13862 struct text_pos lpoint
, opoint
, startp
;
13863 int update_mode_line
;
13866 /* Record it now because it's overwritten. */
13867 int current_matrix_up_to_date_p
= 0;
13868 int used_current_matrix_p
= 0;
13869 /* This is less strict than current_matrix_up_to_date_p.
13870 It indictes that the buffer contents and narrowing are unchanged. */
13871 int buffer_unchanged_p
= 0;
13872 int temp_scroll_step
= 0;
13873 int count
= SPECPDL_INDEX ();
13875 int centering_position
= -1;
13876 int last_line_misfit
= 0;
13877 int beg_unchanged
, end_unchanged
;
13879 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13882 /* W must be a leaf window here. */
13883 xassert (!NILP (w
->buffer
));
13885 *w
->desired_matrix
->method
= 0;
13889 reconsider_clip_changes (w
, buffer
);
13891 /* Has the mode line to be updated? */
13892 update_mode_line
= (!NILP (w
->update_mode_line
)
13893 || update_mode_lines
13894 || buffer
->clip_changed
13895 || buffer
->prevent_redisplay_optimizations_p
);
13897 if (MINI_WINDOW_P (w
))
13899 if (w
== XWINDOW (echo_area_window
)
13900 && !NILP (echo_area_buffer
[0]))
13902 if (update_mode_line
)
13903 /* We may have to update a tty frame's menu bar or a
13904 tool-bar. Example `M-x C-h C-h C-g'. */
13905 goto finish_menu_bars
;
13907 /* We've already displayed the echo area glyphs in this window. */
13908 goto finish_scroll_bars
;
13910 else if ((w
!= XWINDOW (minibuf_window
)
13911 || minibuf_level
== 0)
13912 /* When buffer is nonempty, redisplay window normally. */
13913 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13914 /* Quail displays non-mini buffers in minibuffer window.
13915 In that case, redisplay the window normally. */
13916 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13918 /* W is a mini-buffer window, but it's not active, so clear
13920 int yb
= window_text_bottom_y (w
);
13921 struct glyph_row
*row
;
13924 for (y
= 0, row
= w
->desired_matrix
->rows
;
13926 y
+= row
->height
, ++row
)
13927 blank_row (w
, row
, y
);
13928 goto finish_scroll_bars
;
13931 clear_glyph_matrix (w
->desired_matrix
);
13934 /* Otherwise set up data on this window; select its buffer and point
13936 /* Really select the buffer, for the sake of buffer-local
13938 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13940 current_matrix_up_to_date_p
13941 = (!NILP (w
->window_end_valid
)
13942 && !current_buffer
->clip_changed
13943 && !current_buffer
->prevent_redisplay_optimizations_p
13944 && XFASTINT (w
->last_modified
) >= MODIFF
13945 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13947 /* Run the window-bottom-change-functions
13948 if it is possible that the text on the screen has changed
13949 (either due to modification of the text, or any other reason). */
13950 if (!current_matrix_up_to_date_p
13951 && !NILP (Vwindow_text_change_functions
))
13953 safe_run_hooks (Qwindow_text_change_functions
);
13957 beg_unchanged
= BEG_UNCHANGED
;
13958 end_unchanged
= END_UNCHANGED
;
13960 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13962 specbind (Qinhibit_point_motion_hooks
, Qt
);
13965 = (!NILP (w
->window_end_valid
)
13966 && !current_buffer
->clip_changed
13967 && XFASTINT (w
->last_modified
) >= MODIFF
13968 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13970 /* When windows_or_buffers_changed is non-zero, we can't rely on
13971 the window end being valid, so set it to nil there. */
13972 if (windows_or_buffers_changed
)
13974 /* If window starts on a continuation line, maybe adjust the
13975 window start in case the window's width changed. */
13976 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13977 compute_window_start_on_continuation_line (w
);
13979 w
->window_end_valid
= Qnil
;
13982 /* Some sanity checks. */
13983 CHECK_WINDOW_END (w
);
13984 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13986 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13989 /* If %c is in mode line, update it if needed. */
13990 if (!NILP (w
->column_number_displayed
)
13991 /* This alternative quickly identifies a common case
13992 where no change is needed. */
13993 && !(PT
== XFASTINT (w
->last_point
)
13994 && XFASTINT (w
->last_modified
) >= MODIFF
13995 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13996 && (XFASTINT (w
->column_number_displayed
)
13997 != (int) current_column ())) /* iftc */
13998 update_mode_line
= 1;
14000 /* Count number of windows showing the selected buffer. An indirect
14001 buffer counts as its base buffer. */
14002 if (!just_this_one_p
)
14004 struct buffer
*current_base
, *window_base
;
14005 current_base
= current_buffer
;
14006 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
14007 if (current_base
->base_buffer
)
14008 current_base
= current_base
->base_buffer
;
14009 if (window_base
->base_buffer
)
14010 window_base
= window_base
->base_buffer
;
14011 if (current_base
== window_base
)
14015 /* Point refers normally to the selected window. For any other
14016 window, set up appropriate value. */
14017 if (!EQ (window
, selected_window
))
14019 int new_pt
= XMARKER (w
->pointm
)->charpos
;
14020 int new_pt_byte
= marker_byte_position (w
->pointm
);
14024 new_pt_byte
= BEGV_BYTE
;
14025 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
14027 else if (new_pt
> (ZV
- 1))
14030 new_pt_byte
= ZV_BYTE
;
14031 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
14034 /* We don't use SET_PT so that the point-motion hooks don't run. */
14035 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
14038 /* If any of the character widths specified in the display table
14039 have changed, invalidate the width run cache. It's true that
14040 this may be a bit late to catch such changes, but the rest of
14041 redisplay goes (non-fatally) haywire when the display table is
14042 changed, so why should we worry about doing any better? */
14043 if (current_buffer
->width_run_cache
)
14045 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
14047 if (! disptab_matches_widthtab (disptab
,
14048 XVECTOR (current_buffer
->width_table
)))
14050 invalidate_region_cache (current_buffer
,
14051 current_buffer
->width_run_cache
,
14053 recompute_width_table (current_buffer
, disptab
);
14057 /* If window-start is screwed up, choose a new one. */
14058 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
14061 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14063 /* If someone specified a new starting point but did not insist,
14064 check whether it can be used. */
14065 if (!NILP (w
->optional_new_start
)
14066 && CHARPOS (startp
) >= BEGV
14067 && CHARPOS (startp
) <= ZV
)
14069 w
->optional_new_start
= Qnil
;
14070 start_display (&it
, w
, startp
);
14071 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
14072 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14073 if (IT_CHARPOS (it
) == PT
)
14074 w
->force_start
= Qt
;
14075 /* IT may overshoot PT if text at PT is invisible. */
14076 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
14077 w
->force_start
= Qt
;
14082 /* Handle case where place to start displaying has been specified,
14083 unless the specified location is outside the accessible range. */
14084 if (!NILP (w
->force_start
)
14085 || w
->frozen_window_start_p
)
14087 /* We set this later on if we have to adjust point. */
14090 w
->force_start
= Qnil
;
14092 w
->window_end_valid
= Qnil
;
14094 /* Forget any recorded base line for line number display. */
14095 if (!buffer_unchanged_p
)
14096 w
->base_line_number
= Qnil
;
14098 /* Redisplay the mode line. Select the buffer properly for that.
14099 Also, run the hook window-scroll-functions
14100 because we have scrolled. */
14101 /* Note, we do this after clearing force_start because
14102 if there's an error, it is better to forget about force_start
14103 than to get into an infinite loop calling the hook functions
14104 and having them get more errors. */
14105 if (!update_mode_line
14106 || ! NILP (Vwindow_scroll_functions
))
14108 update_mode_line
= 1;
14109 w
->update_mode_line
= Qt
;
14110 startp
= run_window_scroll_functions (window
, startp
);
14113 w
->last_modified
= make_number (0);
14114 w
->last_overlay_modified
= make_number (0);
14115 if (CHARPOS (startp
) < BEGV
)
14116 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
14117 else if (CHARPOS (startp
) > ZV
)
14118 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
14120 /* Redisplay, then check if cursor has been set during the
14121 redisplay. Give up if new fonts were loaded. */
14122 /* We used to issue a CHECK_MARGINS argument to try_window here,
14123 but this causes scrolling to fail when point begins inside
14124 the scroll margin (bug#148) -- cyd */
14125 if (!try_window (window
, startp
, 0))
14127 w
->force_start
= Qt
;
14128 clear_glyph_matrix (w
->desired_matrix
);
14129 goto need_larger_matrices
;
14132 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
14134 /* If point does not appear, try to move point so it does
14135 appear. The desired matrix has been built above, so we
14136 can use it here. */
14137 new_vpos
= window_box_height (w
) / 2;
14140 if (!cursor_row_fully_visible_p (w
, 0, 0))
14142 /* Point does appear, but on a line partly visible at end of window.
14143 Move it back to a fully-visible line. */
14144 new_vpos
= window_box_height (w
);
14147 /* If we need to move point for either of the above reasons,
14148 now actually do it. */
14151 struct glyph_row
*row
;
14153 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
14154 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
14157 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
14158 MATRIX_ROW_START_BYTEPOS (row
));
14160 if (w
!= XWINDOW (selected_window
))
14161 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
14162 else if (current_buffer
== old
)
14163 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
14165 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
14167 /* If we are highlighting the region, then we just changed
14168 the region, so redisplay to show it. */
14169 if (!NILP (Vtransient_mark_mode
)
14170 && !NILP (current_buffer
->mark_active
))
14172 clear_glyph_matrix (w
->desired_matrix
);
14173 if (!try_window (window
, startp
, 0))
14174 goto need_larger_matrices
;
14179 debug_method_add (w
, "forced window start");
14184 /* Handle case where text has not changed, only point, and it has
14185 not moved off the frame, and we are not retrying after hscroll.
14186 (current_matrix_up_to_date_p is nonzero when retrying.) */
14187 if (current_matrix_up_to_date_p
14188 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
14189 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
14193 case CURSOR_MOVEMENT_SUCCESS
:
14194 used_current_matrix_p
= 1;
14197 case CURSOR_MOVEMENT_MUST_SCROLL
:
14198 goto try_to_scroll
;
14204 /* If current starting point was originally the beginning of a line
14205 but no longer is, find a new starting point. */
14206 else if (!NILP (w
->start_at_line_beg
)
14207 && !(CHARPOS (startp
) <= BEGV
14208 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14211 debug_method_add (w
, "recenter 1");
14216 /* Try scrolling with try_window_id. Value is > 0 if update has
14217 been done, it is -1 if we know that the same window start will
14218 not work. It is 0 if unsuccessful for some other reason. */
14219 else if ((tem
= try_window_id (w
)) != 0)
14222 debug_method_add (w
, "try_window_id %d", tem
);
14225 if (fonts_changed_p
)
14226 goto need_larger_matrices
;
14230 /* Otherwise try_window_id has returned -1 which means that we
14231 don't want the alternative below this comment to execute. */
14233 else if (CHARPOS (startp
) >= BEGV
14234 && CHARPOS (startp
) <= ZV
14235 && PT
>= CHARPOS (startp
)
14236 && (CHARPOS (startp
) < ZV
14237 /* Avoid starting at end of buffer. */
14238 || CHARPOS (startp
) == BEGV
14239 || (XFASTINT (w
->last_modified
) >= MODIFF
14240 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14243 /* If first window line is a continuation line, and window start
14244 is inside the modified region, but the first change is before
14245 current window start, we must select a new window start.
14247 However, if this is the result of a down-mouse event (e.g. by
14248 extending the mouse-drag-overlay), we don't want to select a
14249 new window start, since that would change the position under
14250 the mouse, resulting in an unwanted mouse-movement rather
14251 than a simple mouse-click. */
14252 if (NILP (w
->start_at_line_beg
)
14253 && NILP (do_mouse_tracking
)
14254 && CHARPOS (startp
) > BEGV
14255 && CHARPOS (startp
) > BEG
+ beg_unchanged
14256 && CHARPOS (startp
) <= Z
- end_unchanged
14257 /* Even if w->start_at_line_beg is nil, a new window may
14258 start at a line_beg, since that's how set_buffer_window
14259 sets it. So, we need to check the return value of
14260 compute_window_start_on_continuation_line. (See also
14262 && XMARKER (w
->start
)->buffer
== current_buffer
14263 && compute_window_start_on_continuation_line (w
))
14265 w
->force_start
= Qt
;
14266 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14271 debug_method_add (w
, "same window start");
14274 /* Try to redisplay starting at same place as before.
14275 If point has not moved off frame, accept the results. */
14276 if (!current_matrix_up_to_date_p
14277 /* Don't use try_window_reusing_current_matrix in this case
14278 because a window scroll function can have changed the
14280 || !NILP (Vwindow_scroll_functions
)
14281 || MINI_WINDOW_P (w
)
14282 || !(used_current_matrix_p
14283 = try_window_reusing_current_matrix (w
)))
14285 IF_DEBUG (debug_method_add (w
, "1"));
14286 if (try_window (window
, startp
, 1) < 0)
14287 /* -1 means we need to scroll.
14288 0 means we need new matrices, but fonts_changed_p
14289 is set in that case, so we will detect it below. */
14290 goto try_to_scroll
;
14293 if (fonts_changed_p
)
14294 goto need_larger_matrices
;
14296 if (w
->cursor
.vpos
>= 0)
14298 if (!just_this_one_p
14299 || current_buffer
->clip_changed
14300 || BEG_UNCHANGED
< CHARPOS (startp
))
14301 /* Forget any recorded base line for line number display. */
14302 w
->base_line_number
= Qnil
;
14304 if (!cursor_row_fully_visible_p (w
, 1, 0))
14306 clear_glyph_matrix (w
->desired_matrix
);
14307 last_line_misfit
= 1;
14309 /* Drop through and scroll. */
14314 clear_glyph_matrix (w
->desired_matrix
);
14319 w
->last_modified
= make_number (0);
14320 w
->last_overlay_modified
= make_number (0);
14322 /* Redisplay the mode line. Select the buffer properly for that. */
14323 if (!update_mode_line
)
14325 update_mode_line
= 1;
14326 w
->update_mode_line
= Qt
;
14329 /* Try to scroll by specified few lines. */
14330 if ((scroll_conservatively
14332 || temp_scroll_step
14333 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14334 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14335 && !current_buffer
->clip_changed
14336 && CHARPOS (startp
) >= BEGV
14337 && CHARPOS (startp
) <= ZV
)
14339 /* The function returns -1 if new fonts were loaded, 1 if
14340 successful, 0 if not successful. */
14341 int rc
= try_scrolling (window
, just_this_one_p
,
14342 scroll_conservatively
,
14344 temp_scroll_step
, last_line_misfit
);
14347 case SCROLLING_SUCCESS
:
14350 case SCROLLING_NEED_LARGER_MATRICES
:
14351 goto need_larger_matrices
;
14353 case SCROLLING_FAILED
:
14361 /* Finally, just choose place to start which centers point */
14364 if (centering_position
< 0)
14365 centering_position
= window_box_height (w
) / 2;
14368 debug_method_add (w
, "recenter");
14371 /* w->vscroll = 0; */
14373 /* Forget any previously recorded base line for line number display. */
14374 if (!buffer_unchanged_p
)
14375 w
->base_line_number
= Qnil
;
14377 /* Move backward half the height of the window. */
14378 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14379 it
.current_y
= it
.last_visible_y
;
14380 move_it_vertically_backward (&it
, centering_position
);
14381 xassert (IT_CHARPOS (it
) >= BEGV
);
14383 /* The function move_it_vertically_backward may move over more
14384 than the specified y-distance. If it->w is small, e.g. a
14385 mini-buffer window, we may end up in front of the window's
14386 display area. Start displaying at the start of the line
14387 containing PT in this case. */
14388 if (it
.current_y
<= 0)
14390 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14391 move_it_vertically_backward (&it
, 0);
14395 it
.current_x
= it
.hpos
= 0;
14397 /* Set startp here explicitly in case that helps avoid an infinite loop
14398 in case the window-scroll-functions functions get errors. */
14399 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14401 /* Run scroll hooks. */
14402 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14404 /* Redisplay the window. */
14405 if (!current_matrix_up_to_date_p
14406 || windows_or_buffers_changed
14407 || cursor_type_changed
14408 /* Don't use try_window_reusing_current_matrix in this case
14409 because it can have changed the buffer. */
14410 || !NILP (Vwindow_scroll_functions
)
14411 || !just_this_one_p
14412 || MINI_WINDOW_P (w
)
14413 || !(used_current_matrix_p
14414 = try_window_reusing_current_matrix (w
)))
14415 try_window (window
, startp
, 0);
14417 /* If new fonts have been loaded (due to fontsets), give up. We
14418 have to start a new redisplay since we need to re-adjust glyph
14420 if (fonts_changed_p
)
14421 goto need_larger_matrices
;
14423 /* If cursor did not appear assume that the middle of the window is
14424 in the first line of the window. Do it again with the next line.
14425 (Imagine a window of height 100, displaying two lines of height
14426 60. Moving back 50 from it->last_visible_y will end in the first
14428 if (w
->cursor
.vpos
< 0)
14430 if (!NILP (w
->window_end_valid
)
14431 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14433 clear_glyph_matrix (w
->desired_matrix
);
14434 move_it_by_lines (&it
, 1, 0);
14435 try_window (window
, it
.current
.pos
, 0);
14437 else if (PT
< IT_CHARPOS (it
))
14439 clear_glyph_matrix (w
->desired_matrix
);
14440 move_it_by_lines (&it
, -1, 0);
14441 try_window (window
, it
.current
.pos
, 0);
14445 /* Not much we can do about it. */
14449 /* Consider the following case: Window starts at BEGV, there is
14450 invisible, intangible text at BEGV, so that display starts at
14451 some point START > BEGV. It can happen that we are called with
14452 PT somewhere between BEGV and START. Try to handle that case. */
14453 if (w
->cursor
.vpos
< 0)
14455 struct glyph_row
*row
= w
->current_matrix
->rows
;
14456 if (row
->mode_line_p
)
14458 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14461 if (!cursor_row_fully_visible_p (w
, 0, 0))
14463 /* If vscroll is enabled, disable it and try again. */
14467 clear_glyph_matrix (w
->desired_matrix
);
14471 /* If centering point failed to make the whole line visible,
14472 put point at the top instead. That has to make the whole line
14473 visible, if it can be done. */
14474 if (centering_position
== 0)
14477 clear_glyph_matrix (w
->desired_matrix
);
14478 centering_position
= 0;
14484 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14485 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14486 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14489 /* Display the mode line, if we must. */
14490 if ((update_mode_line
14491 /* If window not full width, must redo its mode line
14492 if (a) the window to its side is being redone and
14493 (b) we do a frame-based redisplay. This is a consequence
14494 of how inverted lines are drawn in frame-based redisplay. */
14495 || (!just_this_one_p
14496 && !FRAME_WINDOW_P (f
)
14497 && !WINDOW_FULL_WIDTH_P (w
))
14498 /* Line number to display. */
14499 || INTEGERP (w
->base_line_pos
)
14500 /* Column number is displayed and different from the one displayed. */
14501 || (!NILP (w
->column_number_displayed
)
14502 && (XFASTINT (w
->column_number_displayed
)
14503 != (int) current_column ()))) /* iftc */
14504 /* This means that the window has a mode line. */
14505 && (WINDOW_WANTS_MODELINE_P (w
)
14506 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14508 display_mode_lines (w
);
14510 /* If mode line height has changed, arrange for a thorough
14511 immediate redisplay using the correct mode line height. */
14512 if (WINDOW_WANTS_MODELINE_P (w
)
14513 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14515 fonts_changed_p
= 1;
14516 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14517 = DESIRED_MODE_LINE_HEIGHT (w
);
14520 /* If header line height has changed, arrange for a thorough
14521 immediate redisplay using the correct header line height. */
14522 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14523 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14525 fonts_changed_p
= 1;
14526 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14527 = DESIRED_HEADER_LINE_HEIGHT (w
);
14530 if (fonts_changed_p
)
14531 goto need_larger_matrices
;
14534 if (!line_number_displayed
14535 && !BUFFERP (w
->base_line_pos
))
14537 w
->base_line_pos
= Qnil
;
14538 w
->base_line_number
= Qnil
;
14543 /* When we reach a frame's selected window, redo the frame's menu bar. */
14544 if (update_mode_line
14545 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14547 int redisplay_menu_p
= 0;
14548 int redisplay_tool_bar_p
= 0;
14550 if (FRAME_WINDOW_P (f
))
14552 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14553 || defined (HAVE_NS) || defined (USE_GTK)
14554 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14556 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14560 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14562 if (redisplay_menu_p
)
14563 display_menu_bar (w
);
14565 #ifdef HAVE_WINDOW_SYSTEM
14566 if (FRAME_WINDOW_P (f
))
14568 #if defined (USE_GTK) || defined (HAVE_NS)
14569 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14571 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14572 && (FRAME_TOOL_BAR_LINES (f
) > 0
14573 || !NILP (Vauto_resize_tool_bars
));
14576 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14578 extern int ignore_mouse_drag_p
;
14579 ignore_mouse_drag_p
= 1;
14585 #ifdef HAVE_WINDOW_SYSTEM
14586 if (FRAME_WINDOW_P (f
)
14587 && update_window_fringes (w
, (just_this_one_p
14588 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14589 || w
->pseudo_window_p
)))
14593 if (draw_window_fringes (w
, 1))
14594 x_draw_vertical_border (w
);
14598 #endif /* HAVE_WINDOW_SYSTEM */
14600 /* We go to this label, with fonts_changed_p nonzero,
14601 if it is necessary to try again using larger glyph matrices.
14602 We have to redeem the scroll bar even in this case,
14603 because the loop in redisplay_internal expects that. */
14604 need_larger_matrices
:
14606 finish_scroll_bars
:
14608 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14610 /* Set the thumb's position and size. */
14611 set_vertical_scroll_bar (w
);
14613 /* Note that we actually used the scroll bar attached to this
14614 window, so it shouldn't be deleted at the end of redisplay. */
14615 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14616 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14619 /* Restore current_buffer and value of point in it. */
14620 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14621 set_buffer_internal_1 (old
);
14622 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14623 shorter. This can be caused by log truncation in *Messages*. */
14624 if (CHARPOS (lpoint
) <= ZV
)
14625 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14627 unbind_to (count
, Qnil
);
14631 /* Build the complete desired matrix of WINDOW with a window start
14632 buffer position POS.
14634 Value is 1 if successful. It is zero if fonts were loaded during
14635 redisplay which makes re-adjusting glyph matrices necessary, and -1
14636 if point would appear in the scroll margins.
14637 (We check that only if CHECK_MARGINS is nonzero. */
14640 try_window (window
, pos
, check_margins
)
14641 Lisp_Object window
;
14642 struct text_pos pos
;
14645 struct window
*w
= XWINDOW (window
);
14647 struct glyph_row
*last_text_row
= NULL
;
14648 struct frame
*f
= XFRAME (w
->frame
);
14650 /* Make POS the new window start. */
14651 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14653 /* Mark cursor position as unknown. No overlay arrow seen. */
14654 w
->cursor
.vpos
= -1;
14655 overlay_arrow_seen
= 0;
14657 /* Initialize iterator and info to start at POS. */
14658 start_display (&it
, w
, pos
);
14660 /* Display all lines of W. */
14661 while (it
.current_y
< it
.last_visible_y
)
14663 if (display_line (&it
))
14664 last_text_row
= it
.glyph_row
- 1;
14665 if (fonts_changed_p
)
14669 /* Don't let the cursor end in the scroll margins. */
14671 && !MINI_WINDOW_P (w
))
14673 int this_scroll_margin
;
14675 if (scroll_margin
> 0)
14677 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14678 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14681 this_scroll_margin
= 0;
14683 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14684 && w
->cursor
.y
< this_scroll_margin
14685 && CHARPOS (pos
) > BEGV
14686 && IT_CHARPOS (it
) < ZV
)
14687 /* rms: considering make_cursor_line_fully_visible_p here
14688 seems to give wrong results. We don't want to recenter
14689 when the last line is partly visible, we want to allow
14690 that case to be handled in the usual way. */
14691 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14693 w
->cursor
.vpos
= -1;
14694 clear_glyph_matrix (w
->desired_matrix
);
14699 /* If bottom moved off end of frame, change mode line percentage. */
14700 if (XFASTINT (w
->window_end_pos
) <= 0
14701 && Z
!= IT_CHARPOS (it
))
14702 w
->update_mode_line
= Qt
;
14704 /* Set window_end_pos to the offset of the last character displayed
14705 on the window from the end of current_buffer. Set
14706 window_end_vpos to its row number. */
14709 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14710 w
->window_end_bytepos
14711 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14713 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14715 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14716 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14717 ->displays_text_p
);
14721 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14722 w
->window_end_pos
= make_number (Z
- ZV
);
14723 w
->window_end_vpos
= make_number (0);
14726 /* But that is not valid info until redisplay finishes. */
14727 w
->window_end_valid
= Qnil
;
14733 /************************************************************************
14734 Window redisplay reusing current matrix when buffer has not changed
14735 ************************************************************************/
14737 /* Try redisplay of window W showing an unchanged buffer with a
14738 different window start than the last time it was displayed by
14739 reusing its current matrix. Value is non-zero if successful.
14740 W->start is the new window start. */
14743 try_window_reusing_current_matrix (w
)
14746 struct frame
*f
= XFRAME (w
->frame
);
14747 struct glyph_row
*row
, *bottom_row
;
14750 struct text_pos start
, new_start
;
14751 int nrows_scrolled
, i
;
14752 struct glyph_row
*last_text_row
;
14753 struct glyph_row
*last_reused_text_row
;
14754 struct glyph_row
*start_row
;
14755 int start_vpos
, min_y
, max_y
;
14758 if (inhibit_try_window_reusing
)
14762 if (/* This function doesn't handle terminal frames. */
14763 !FRAME_WINDOW_P (f
)
14764 /* Don't try to reuse the display if windows have been split
14766 || windows_or_buffers_changed
14767 || cursor_type_changed
)
14770 /* Can't do this if region may have changed. */
14771 if ((!NILP (Vtransient_mark_mode
)
14772 && !NILP (current_buffer
->mark_active
))
14773 || !NILP (w
->region_showing
)
14774 || !NILP (Vshow_trailing_whitespace
))
14777 /* If top-line visibility has changed, give up. */
14778 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14779 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14782 /* Give up if old or new display is scrolled vertically. We could
14783 make this function handle this, but right now it doesn't. */
14784 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14785 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14788 /* The variable new_start now holds the new window start. The old
14789 start `start' can be determined from the current matrix. */
14790 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14791 start
= start_row
->start
.pos
;
14792 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14794 /* Clear the desired matrix for the display below. */
14795 clear_glyph_matrix (w
->desired_matrix
);
14797 if (CHARPOS (new_start
) <= CHARPOS (start
))
14801 /* Don't use this method if the display starts with an ellipsis
14802 displayed for invisible text. It's not easy to handle that case
14803 below, and it's certainly not worth the effort since this is
14804 not a frequent case. */
14805 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14808 IF_DEBUG (debug_method_add (w
, "twu1"));
14810 /* Display up to a row that can be reused. The variable
14811 last_text_row is set to the last row displayed that displays
14812 text. Note that it.vpos == 0 if or if not there is a
14813 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14814 start_display (&it
, w
, new_start
);
14815 first_row_y
= it
.current_y
;
14816 w
->cursor
.vpos
= -1;
14817 last_text_row
= last_reused_text_row
= NULL
;
14819 while (it
.current_y
< it
.last_visible_y
14820 && !fonts_changed_p
)
14822 /* If we have reached into the characters in the START row,
14823 that means the line boundaries have changed. So we
14824 can't start copying with the row START. Maybe it will
14825 work to start copying with the following row. */
14826 while (IT_CHARPOS (it
) > CHARPOS (start
))
14828 /* Advance to the next row as the "start". */
14830 start
= start_row
->start
.pos
;
14831 /* If there are no more rows to try, or just one, give up. */
14832 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14833 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14834 || CHARPOS (start
) == ZV
)
14836 clear_glyph_matrix (w
->desired_matrix
);
14840 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14842 /* If we have reached alignment,
14843 we can copy the rest of the rows. */
14844 if (IT_CHARPOS (it
) == CHARPOS (start
))
14847 if (display_line (&it
))
14848 last_text_row
= it
.glyph_row
- 1;
14851 /* A value of current_y < last_visible_y means that we stopped
14852 at the previous window start, which in turn means that we
14853 have at least one reusable row. */
14854 if (it
.current_y
< it
.last_visible_y
)
14856 /* IT.vpos always starts from 0; it counts text lines. */
14857 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14859 /* Find PT if not already found in the lines displayed. */
14860 if (w
->cursor
.vpos
< 0)
14862 int dy
= it
.current_y
- start_row
->y
;
14864 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14865 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14867 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14868 dy
, nrows_scrolled
);
14871 clear_glyph_matrix (w
->desired_matrix
);
14876 /* Scroll the display. Do it before the current matrix is
14877 changed. The problem here is that update has not yet
14878 run, i.e. part of the current matrix is not up to date.
14879 scroll_run_hook will clear the cursor, and use the
14880 current matrix to get the height of the row the cursor is
14882 run
.current_y
= start_row
->y
;
14883 run
.desired_y
= it
.current_y
;
14884 run
.height
= it
.last_visible_y
- it
.current_y
;
14886 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14889 FRAME_RIF (f
)->update_window_begin_hook (w
);
14890 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14891 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14892 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14896 /* Shift current matrix down by nrows_scrolled lines. */
14897 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14898 rotate_matrix (w
->current_matrix
,
14900 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14903 /* Disable lines that must be updated. */
14904 for (i
= 0; i
< nrows_scrolled
; ++i
)
14905 (start_row
+ i
)->enabled_p
= 0;
14907 /* Re-compute Y positions. */
14908 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14909 max_y
= it
.last_visible_y
;
14910 for (row
= start_row
+ nrows_scrolled
;
14914 row
->y
= it
.current_y
;
14915 row
->visible_height
= row
->height
;
14917 if (row
->y
< min_y
)
14918 row
->visible_height
-= min_y
- row
->y
;
14919 if (row
->y
+ row
->height
> max_y
)
14920 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14921 row
->redraw_fringe_bitmaps_p
= 1;
14923 it
.current_y
+= row
->height
;
14925 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14926 last_reused_text_row
= row
;
14927 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14931 /* Disable lines in the current matrix which are now
14932 below the window. */
14933 for (++row
; row
< bottom_row
; ++row
)
14934 row
->enabled_p
= row
->mode_line_p
= 0;
14937 /* Update window_end_pos etc.; last_reused_text_row is the last
14938 reused row from the current matrix containing text, if any.
14939 The value of last_text_row is the last displayed line
14940 containing text. */
14941 if (last_reused_text_row
)
14943 w
->window_end_bytepos
14944 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14946 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14948 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14949 w
->current_matrix
));
14951 else if (last_text_row
)
14953 w
->window_end_bytepos
14954 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14956 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14958 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14962 /* This window must be completely empty. */
14963 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14964 w
->window_end_pos
= make_number (Z
- ZV
);
14965 w
->window_end_vpos
= make_number (0);
14967 w
->window_end_valid
= Qnil
;
14969 /* Update hint: don't try scrolling again in update_window. */
14970 w
->desired_matrix
->no_scrolling_p
= 1;
14973 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14977 else if (CHARPOS (new_start
) > CHARPOS (start
))
14979 struct glyph_row
*pt_row
, *row
;
14980 struct glyph_row
*first_reusable_row
;
14981 struct glyph_row
*first_row_to_display
;
14983 int yb
= window_text_bottom_y (w
);
14985 /* Find the row starting at new_start, if there is one. Don't
14986 reuse a partially visible line at the end. */
14987 first_reusable_row
= start_row
;
14988 while (first_reusable_row
->enabled_p
14989 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14990 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14991 < CHARPOS (new_start
)))
14992 ++first_reusable_row
;
14994 /* Give up if there is no row to reuse. */
14995 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14996 || !first_reusable_row
->enabled_p
14997 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14998 != CHARPOS (new_start
)))
15001 /* We can reuse fully visible rows beginning with
15002 first_reusable_row to the end of the window. Set
15003 first_row_to_display to the first row that cannot be reused.
15004 Set pt_row to the row containing point, if there is any. */
15006 for (first_row_to_display
= first_reusable_row
;
15007 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
15008 ++first_row_to_display
)
15010 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
15011 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
15012 pt_row
= first_row_to_display
;
15015 /* Start displaying at the start of first_row_to_display. */
15016 xassert (first_row_to_display
->y
< yb
);
15017 init_to_row_start (&it
, w
, first_row_to_display
);
15019 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
15021 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
15023 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
15024 + WINDOW_HEADER_LINE_HEIGHT (w
));
15026 /* Display lines beginning with first_row_to_display in the
15027 desired matrix. Set last_text_row to the last row displayed
15028 that displays text. */
15029 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
15030 if (pt_row
== NULL
)
15031 w
->cursor
.vpos
= -1;
15032 last_text_row
= NULL
;
15033 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
15034 if (display_line (&it
))
15035 last_text_row
= it
.glyph_row
- 1;
15037 /* If point is in a reused row, adjust y and vpos of the cursor
15041 w
->cursor
.vpos
-= nrows_scrolled
;
15042 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
15045 /* Give up if point isn't in a row displayed or reused. (This
15046 also handles the case where w->cursor.vpos < nrows_scrolled
15047 after the calls to display_line, which can happen with scroll
15048 margins. See bug#1295.) */
15049 if (w
->cursor
.vpos
< 0)
15051 clear_glyph_matrix (w
->desired_matrix
);
15055 /* Scroll the display. */
15056 run
.current_y
= first_reusable_row
->y
;
15057 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15058 run
.height
= it
.last_visible_y
- run
.current_y
;
15059 dy
= run
.current_y
- run
.desired_y
;
15064 FRAME_RIF (f
)->update_window_begin_hook (w
);
15065 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15066 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15067 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15071 /* Adjust Y positions of reused rows. */
15072 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
15073 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
15074 max_y
= it
.last_visible_y
;
15075 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
15078 row
->visible_height
= row
->height
;
15079 if (row
->y
< min_y
)
15080 row
->visible_height
-= min_y
- row
->y
;
15081 if (row
->y
+ row
->height
> max_y
)
15082 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
15083 row
->redraw_fringe_bitmaps_p
= 1;
15086 /* Scroll the current matrix. */
15087 xassert (nrows_scrolled
> 0);
15088 rotate_matrix (w
->current_matrix
,
15090 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
15093 /* Disable rows not reused. */
15094 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
15095 row
->enabled_p
= 0;
15097 /* Point may have moved to a different line, so we cannot assume that
15098 the previous cursor position is valid; locate the correct row. */
15101 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15102 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
15106 w
->cursor
.y
= row
->y
;
15108 if (row
< bottom_row
)
15110 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15111 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
15112 struct glyph
*orig_glyph
= glyph
;
15113 struct cursor_pos orig_cursor
= w
->cursor
;
15116 && (!BUFFERP (glyph
->object
)
15117 || glyph
->charpos
!= PT
);
15121 w
->cursor
.x
+= glyph
->pixel_width
;
15123 /* With bidi reordering, charpos changes non-linearly
15124 with hpos, so the right glyph could be to the
15126 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15127 && (!BUFFERP (glyph
->object
) || glyph
->charpos
!= PT
))
15129 struct glyph
*start_glyph
= row
->glyphs
[TEXT_AREA
];
15131 glyph
= orig_glyph
- 1;
15132 orig_cursor
.hpos
--;
15133 orig_cursor
.x
-= glyph
->pixel_width
;
15134 for (; glyph
>= start_glyph
15135 && (!BUFFERP (glyph
->object
)
15136 || glyph
->charpos
!= PT
);
15140 w
->cursor
.x
-= glyph
->pixel_width
;
15142 if (BUFFERP (glyph
->object
) && glyph
->charpos
== PT
)
15143 w
->cursor
= orig_cursor
;
15148 /* Adjust window end. A null value of last_text_row means that
15149 the window end is in reused rows which in turn means that
15150 only its vpos can have changed. */
15153 w
->window_end_bytepos
15154 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15156 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15158 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
15163 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
15166 w
->window_end_valid
= Qnil
;
15167 w
->desired_matrix
->no_scrolling_p
= 1;
15170 debug_method_add (w
, "try_window_reusing_current_matrix 2");
15180 /************************************************************************
15181 Window redisplay reusing current matrix when buffer has changed
15182 ************************************************************************/
15184 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
15185 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
15187 static struct glyph_row
*
15188 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
15189 struct glyph_row
*));
15192 /* Return the last row in MATRIX displaying text. If row START is
15193 non-null, start searching with that row. IT gives the dimensions
15194 of the display. Value is null if matrix is empty; otherwise it is
15195 a pointer to the row found. */
15197 static struct glyph_row
*
15198 find_last_row_displaying_text (matrix
, it
, start
)
15199 struct glyph_matrix
*matrix
;
15201 struct glyph_row
*start
;
15203 struct glyph_row
*row
, *row_found
;
15205 /* Set row_found to the last row in IT->w's current matrix
15206 displaying text. The loop looks funny but think of partially
15209 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15210 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15212 xassert (row
->enabled_p
);
15214 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15223 /* Return the last row in the current matrix of W that is not affected
15224 by changes at the start of current_buffer that occurred since W's
15225 current matrix was built. Value is null if no such row exists.
15227 BEG_UNCHANGED us the number of characters unchanged at the start of
15228 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15229 first changed character in current_buffer. Characters at positions <
15230 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15231 when the current matrix was built. */
15233 static struct glyph_row
*
15234 find_last_unchanged_at_beg_row (w
)
15237 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15238 struct glyph_row
*row
;
15239 struct glyph_row
*row_found
= NULL
;
15240 int yb
= window_text_bottom_y (w
);
15242 /* Find the last row displaying unchanged text. */
15243 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15244 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15245 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15248 if (/* If row ends before first_changed_pos, it is unchanged,
15249 except in some case. */
15250 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15251 /* When row ends in ZV and we write at ZV it is not
15253 && !row
->ends_at_zv_p
15254 /* When first_changed_pos is the end of a continued line,
15255 row is not unchanged because it may be no longer
15257 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15258 && (row
->continued_p
15259 || row
->exact_window_width_line_p
)))
15262 /* Stop if last visible row. */
15263 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15271 /* Find the first glyph row in the current matrix of W that is not
15272 affected by changes at the end of current_buffer since the
15273 time W's current matrix was built.
15275 Return in *DELTA the number of chars by which buffer positions in
15276 unchanged text at the end of current_buffer must be adjusted.
15278 Return in *DELTA_BYTES the corresponding number of bytes.
15280 Value is null if no such row exists, i.e. all rows are affected by
15283 static struct glyph_row
*
15284 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
15286 int *delta
, *delta_bytes
;
15288 struct glyph_row
*row
;
15289 struct glyph_row
*row_found
= NULL
;
15291 *delta
= *delta_bytes
= 0;
15293 /* Display must not have been paused, otherwise the current matrix
15294 is not up to date. */
15295 eassert (!NILP (w
->window_end_valid
));
15297 /* A value of window_end_pos >= END_UNCHANGED means that the window
15298 end is in the range of changed text. If so, there is no
15299 unchanged row at the end of W's current matrix. */
15300 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15303 /* Set row to the last row in W's current matrix displaying text. */
15304 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15306 /* If matrix is entirely empty, no unchanged row exists. */
15307 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15309 /* The value of row is the last glyph row in the matrix having a
15310 meaningful buffer position in it. The end position of row
15311 corresponds to window_end_pos. This allows us to translate
15312 buffer positions in the current matrix to current buffer
15313 positions for characters not in changed text. */
15314 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15315 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15316 int last_unchanged_pos
, last_unchanged_pos_old
;
15317 struct glyph_row
*first_text_row
15318 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15320 *delta
= Z
- Z_old
;
15321 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15323 /* Set last_unchanged_pos to the buffer position of the last
15324 character in the buffer that has not been changed. Z is the
15325 index + 1 of the last character in current_buffer, i.e. by
15326 subtracting END_UNCHANGED we get the index of the last
15327 unchanged character, and we have to add BEG to get its buffer
15329 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15330 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15332 /* Search backward from ROW for a row displaying a line that
15333 starts at a minimum position >= last_unchanged_pos_old. */
15334 for (; row
> first_text_row
; --row
)
15336 /* This used to abort, but it can happen.
15337 It is ok to just stop the search instead here. KFS. */
15338 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15341 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15346 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15352 /* Make sure that glyph rows in the current matrix of window W
15353 reference the same glyph memory as corresponding rows in the
15354 frame's frame matrix. This function is called after scrolling W's
15355 current matrix on a terminal frame in try_window_id and
15356 try_window_reusing_current_matrix. */
15359 sync_frame_with_window_matrix_rows (w
)
15362 struct frame
*f
= XFRAME (w
->frame
);
15363 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15365 /* Preconditions: W must be a leaf window and full-width. Its frame
15366 must have a frame matrix. */
15367 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15368 xassert (WINDOW_FULL_WIDTH_P (w
));
15369 xassert (!FRAME_WINDOW_P (f
));
15371 /* If W is a full-width window, glyph pointers in W's current matrix
15372 have, by definition, to be the same as glyph pointers in the
15373 corresponding frame matrix. Note that frame matrices have no
15374 marginal areas (see build_frame_matrix). */
15375 window_row
= w
->current_matrix
->rows
;
15376 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15377 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15378 while (window_row
< window_row_end
)
15380 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15381 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15383 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15384 frame_row
->glyphs
[TEXT_AREA
] = start
;
15385 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15386 frame_row
->glyphs
[LAST_AREA
] = end
;
15388 /* Disable frame rows whose corresponding window rows have
15389 been disabled in try_window_id. */
15390 if (!window_row
->enabled_p
)
15391 frame_row
->enabled_p
= 0;
15393 ++window_row
, ++frame_row
;
15398 /* Find the glyph row in window W containing CHARPOS. Consider all
15399 rows between START and END (not inclusive). END null means search
15400 all rows to the end of the display area of W. Value is the row
15401 containing CHARPOS or null. */
15404 row_containing_pos (w
, charpos
, start
, end
, dy
)
15407 struct glyph_row
*start
, *end
;
15410 struct glyph_row
*row
= start
;
15411 struct glyph_row
*best_row
= NULL
;
15412 EMACS_INT mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
15415 /* If we happen to start on a header-line, skip that. */
15416 if (row
->mode_line_p
)
15419 if ((end
&& row
>= end
) || !row
->enabled_p
)
15422 last_y
= window_text_bottom_y (w
) - dy
;
15426 /* Give up if we have gone too far. */
15427 if (end
&& row
>= end
)
15429 /* This formerly returned if they were equal.
15430 I think that both quantities are of a "last plus one" type;
15431 if so, when they are equal, the row is within the screen. -- rms. */
15432 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15435 /* If it is in this row, return this row. */
15436 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15437 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15438 /* The end position of a row equals the start
15439 position of the next row. If CHARPOS is there, we
15440 would rather display it in the next line, except
15441 when this line ends in ZV. */
15442 && !row
->ends_at_zv_p
15443 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15444 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15448 if (NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
))
15450 /* In bidi-reordered rows, there could be several rows
15451 occluding point. We need to find the one which fits
15452 CHARPOS the best. */
15453 for (g
= row
->glyphs
[TEXT_AREA
];
15454 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
15457 if (!STRINGP (g
->object
))
15459 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
15461 mindif
= eabs (g
->charpos
- charpos
);
15474 /* Try to redisplay window W by reusing its existing display. W's
15475 current matrix must be up to date when this function is called,
15476 i.e. window_end_valid must not be nil.
15480 1 if display has been updated
15481 0 if otherwise unsuccessful
15482 -1 if redisplay with same window start is known not to succeed
15484 The following steps are performed:
15486 1. Find the last row in the current matrix of W that is not
15487 affected by changes at the start of current_buffer. If no such row
15490 2. Find the first row in W's current matrix that is not affected by
15491 changes at the end of current_buffer. Maybe there is no such row.
15493 3. Display lines beginning with the row + 1 found in step 1 to the
15494 row found in step 2 or, if step 2 didn't find a row, to the end of
15497 4. If cursor is not known to appear on the window, give up.
15499 5. If display stopped at the row found in step 2, scroll the
15500 display and current matrix as needed.
15502 6. Maybe display some lines at the end of W, if we must. This can
15503 happen under various circumstances, like a partially visible line
15504 becoming fully visible, or because newly displayed lines are displayed
15505 in smaller font sizes.
15507 7. Update W's window end information. */
15513 struct frame
*f
= XFRAME (w
->frame
);
15514 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15515 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15516 struct glyph_row
*last_unchanged_at_beg_row
;
15517 struct glyph_row
*first_unchanged_at_end_row
;
15518 struct glyph_row
*row
;
15519 struct glyph_row
*bottom_row
;
15522 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
15523 struct text_pos start_pos
;
15525 int first_unchanged_at_end_vpos
= 0;
15526 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15527 struct text_pos start
;
15528 int first_changed_charpos
, last_changed_charpos
;
15531 if (inhibit_try_window_id
)
15535 /* This is handy for debugging. */
15537 #define GIVE_UP(X) \
15539 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15543 #define GIVE_UP(X) return 0
15546 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15548 /* Don't use this for mini-windows because these can show
15549 messages and mini-buffers, and we don't handle that here. */
15550 if (MINI_WINDOW_P (w
))
15553 /* This flag is used to prevent redisplay optimizations. */
15554 if (windows_or_buffers_changed
|| cursor_type_changed
)
15557 /* Verify that narrowing has not changed.
15558 Also verify that we were not told to prevent redisplay optimizations.
15559 It would be nice to further
15560 reduce the number of cases where this prevents try_window_id. */
15561 if (current_buffer
->clip_changed
15562 || current_buffer
->prevent_redisplay_optimizations_p
)
15565 /* Window must either use window-based redisplay or be full width. */
15566 if (!FRAME_WINDOW_P (f
)
15567 && (!FRAME_LINE_INS_DEL_OK (f
)
15568 || !WINDOW_FULL_WIDTH_P (w
)))
15571 /* Give up if point is known NOT to appear in W. */
15572 if (PT
< CHARPOS (start
))
15575 /* Another way to prevent redisplay optimizations. */
15576 if (XFASTINT (w
->last_modified
) == 0)
15579 /* Verify that window is not hscrolled. */
15580 if (XFASTINT (w
->hscroll
) != 0)
15583 /* Verify that display wasn't paused. */
15584 if (NILP (w
->window_end_valid
))
15587 /* Can't use this if highlighting a region because a cursor movement
15588 will do more than just set the cursor. */
15589 if (!NILP (Vtransient_mark_mode
)
15590 && !NILP (current_buffer
->mark_active
))
15593 /* Likewise if highlighting trailing whitespace. */
15594 if (!NILP (Vshow_trailing_whitespace
))
15597 /* Likewise if showing a region. */
15598 if (!NILP (w
->region_showing
))
15601 /* Can't use this if overlay arrow position and/or string have
15603 if (overlay_arrows_changed_p ())
15606 /* When word-wrap is on, adding a space to the first word of a
15607 wrapped line can change the wrap position, altering the line
15608 above it. It might be worthwhile to handle this more
15609 intelligently, but for now just redisplay from scratch. */
15610 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15613 /* Under bidi reordering, adding or deleting a character in the
15614 beginning of a paragraph, before the first strong directional
15615 character, can change the base direction of the paragraph (unless
15616 the buffer specifies a fixed paragraph direction), which will
15617 require to redisplay the whole paragraph. It might be worthwhile
15618 to find the paragraph limits and widen the range of redisplayed
15619 lines to that, but for now just give up this optimization and
15620 redisplay from scratch. */
15621 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15622 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15625 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15626 only if buffer has really changed. The reason is that the gap is
15627 initially at Z for freshly visited files. The code below would
15628 set end_unchanged to 0 in that case. */
15629 if (MODIFF
> SAVE_MODIFF
15630 /* This seems to happen sometimes after saving a buffer. */
15631 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15633 if (GPT
- BEG
< BEG_UNCHANGED
)
15634 BEG_UNCHANGED
= GPT
- BEG
;
15635 if (Z
- GPT
< END_UNCHANGED
)
15636 END_UNCHANGED
= Z
- GPT
;
15639 /* The position of the first and last character that has been changed. */
15640 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15641 last_changed_charpos
= Z
- END_UNCHANGED
;
15643 /* If window starts after a line end, and the last change is in
15644 front of that newline, then changes don't affect the display.
15645 This case happens with stealth-fontification. Note that although
15646 the display is unchanged, glyph positions in the matrix have to
15647 be adjusted, of course. */
15648 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15649 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15650 && ((last_changed_charpos
< CHARPOS (start
)
15651 && CHARPOS (start
) == BEGV
)
15652 || (last_changed_charpos
< CHARPOS (start
) - 1
15653 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15655 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15656 struct glyph_row
*r0
;
15658 /* Compute how many chars/bytes have been added to or removed
15659 from the buffer. */
15660 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15661 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15663 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15665 /* Give up if PT is not in the window. Note that it already has
15666 been checked at the start of try_window_id that PT is not in
15667 front of the window start. */
15668 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15671 /* If window start is unchanged, we can reuse the whole matrix
15672 as is, after adjusting glyph positions. No need to compute
15673 the window end again, since its offset from Z hasn't changed. */
15674 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15675 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15676 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15677 /* PT must not be in a partially visible line. */
15678 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15679 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15681 /* Adjust positions in the glyph matrix. */
15682 if (delta
|| delta_bytes
)
15684 struct glyph_row
*r1
15685 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15686 increment_matrix_positions (w
->current_matrix
,
15687 MATRIX_ROW_VPOS (r0
, current_matrix
),
15688 MATRIX_ROW_VPOS (r1
, current_matrix
),
15689 delta
, delta_bytes
);
15692 /* Set the cursor. */
15693 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15695 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15702 /* Handle the case that changes are all below what is displayed in
15703 the window, and that PT is in the window. This shortcut cannot
15704 be taken if ZV is visible in the window, and text has been added
15705 there that is visible in the window. */
15706 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15707 /* ZV is not visible in the window, or there are no
15708 changes at ZV, actually. */
15709 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15710 || first_changed_charpos
== last_changed_charpos
))
15712 struct glyph_row
*r0
;
15714 /* Give up if PT is not in the window. Note that it already has
15715 been checked at the start of try_window_id that PT is not in
15716 front of the window start. */
15717 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15720 /* If window start is unchanged, we can reuse the whole matrix
15721 as is, without changing glyph positions since no text has
15722 been added/removed in front of the window end. */
15723 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15724 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15725 /* PT must not be in a partially visible line. */
15726 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15727 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15729 /* We have to compute the window end anew since text
15730 can have been added/removed after it. */
15732 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15733 w
->window_end_bytepos
15734 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15736 /* Set the cursor. */
15737 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15739 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15746 /* Give up if window start is in the changed area.
15748 The condition used to read
15750 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15752 but why that was tested escapes me at the moment. */
15753 if (CHARPOS (start
) >= first_changed_charpos
15754 && CHARPOS (start
) <= last_changed_charpos
)
15757 /* Check that window start agrees with the start of the first glyph
15758 row in its current matrix. Check this after we know the window
15759 start is not in changed text, otherwise positions would not be
15761 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15762 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15765 /* Give up if the window ends in strings. Overlay strings
15766 at the end are difficult to handle, so don't try. */
15767 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15768 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15771 /* Compute the position at which we have to start displaying new
15772 lines. Some of the lines at the top of the window might be
15773 reusable because they are not displaying changed text. Find the
15774 last row in W's current matrix not affected by changes at the
15775 start of current_buffer. Value is null if changes start in the
15776 first line of window. */
15777 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15778 if (last_unchanged_at_beg_row
)
15780 /* Avoid starting to display in the moddle of a character, a TAB
15781 for instance. This is easier than to set up the iterator
15782 exactly, and it's not a frequent case, so the additional
15783 effort wouldn't really pay off. */
15784 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15785 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15786 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15787 --last_unchanged_at_beg_row
;
15789 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15792 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15794 start_pos
= it
.current
.pos
;
15796 /* Start displaying new lines in the desired matrix at the same
15797 vpos we would use in the current matrix, i.e. below
15798 last_unchanged_at_beg_row. */
15799 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15801 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15802 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15804 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15808 /* There are no reusable lines at the start of the window.
15809 Start displaying in the first text line. */
15810 start_display (&it
, w
, start
);
15811 it
.vpos
= it
.first_vpos
;
15812 start_pos
= it
.current
.pos
;
15815 /* Find the first row that is not affected by changes at the end of
15816 the buffer. Value will be null if there is no unchanged row, in
15817 which case we must redisplay to the end of the window. delta
15818 will be set to the value by which buffer positions beginning with
15819 first_unchanged_at_end_row have to be adjusted due to text
15821 first_unchanged_at_end_row
15822 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15823 IF_DEBUG (debug_delta
= delta
);
15824 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15826 /* Set stop_pos to the buffer position up to which we will have to
15827 display new lines. If first_unchanged_at_end_row != NULL, this
15828 is the buffer position of the start of the line displayed in that
15829 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15830 that we don't stop at a buffer position. */
15832 if (first_unchanged_at_end_row
)
15834 xassert (last_unchanged_at_beg_row
== NULL
15835 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15837 /* If this is a continuation line, move forward to the next one
15838 that isn't. Changes in lines above affect this line.
15839 Caution: this may move first_unchanged_at_end_row to a row
15840 not displaying text. */
15841 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15842 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15843 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15844 < it
.last_visible_y
))
15845 ++first_unchanged_at_end_row
;
15847 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15848 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15849 >= it
.last_visible_y
))
15850 first_unchanged_at_end_row
= NULL
;
15853 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15855 first_unchanged_at_end_vpos
15856 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15857 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15860 else if (last_unchanged_at_beg_row
== NULL
)
15866 /* Either there is no unchanged row at the end, or the one we have
15867 now displays text. This is a necessary condition for the window
15868 end pos calculation at the end of this function. */
15869 xassert (first_unchanged_at_end_row
== NULL
15870 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15872 debug_last_unchanged_at_beg_vpos
15873 = (last_unchanged_at_beg_row
15874 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15876 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15878 #endif /* GLYPH_DEBUG != 0 */
15881 /* Display new lines. Set last_text_row to the last new line
15882 displayed which has text on it, i.e. might end up as being the
15883 line where the window_end_vpos is. */
15884 w
->cursor
.vpos
= -1;
15885 last_text_row
= NULL
;
15886 overlay_arrow_seen
= 0;
15887 while (it
.current_y
< it
.last_visible_y
15888 && !fonts_changed_p
15889 && (first_unchanged_at_end_row
== NULL
15890 || IT_CHARPOS (it
) < stop_pos
))
15892 if (display_line (&it
))
15893 last_text_row
= it
.glyph_row
- 1;
15896 if (fonts_changed_p
)
15900 /* Compute differences in buffer positions, y-positions etc. for
15901 lines reused at the bottom of the window. Compute what we can
15903 if (first_unchanged_at_end_row
15904 /* No lines reused because we displayed everything up to the
15905 bottom of the window. */
15906 && it
.current_y
< it
.last_visible_y
)
15909 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15911 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15912 run
.current_y
= first_unchanged_at_end_row
->y
;
15913 run
.desired_y
= run
.current_y
+ dy
;
15914 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15918 delta
= delta_bytes
= dvpos
= dy
15919 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15920 first_unchanged_at_end_row
= NULL
;
15922 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15925 /* Find the cursor if not already found. We have to decide whether
15926 PT will appear on this window (it sometimes doesn't, but this is
15927 not a very frequent case.) This decision has to be made before
15928 the current matrix is altered. A value of cursor.vpos < 0 means
15929 that PT is either in one of the lines beginning at
15930 first_unchanged_at_end_row or below the window. Don't care for
15931 lines that might be displayed later at the window end; as
15932 mentioned, this is not a frequent case. */
15933 if (w
->cursor
.vpos
< 0)
15935 /* Cursor in unchanged rows at the top? */
15936 if (PT
< CHARPOS (start_pos
)
15937 && last_unchanged_at_beg_row
)
15939 row
= row_containing_pos (w
, PT
,
15940 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15941 last_unchanged_at_beg_row
+ 1, 0);
15943 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15946 /* Start from first_unchanged_at_end_row looking for PT. */
15947 else if (first_unchanged_at_end_row
)
15949 row
= row_containing_pos (w
, PT
- delta
,
15950 first_unchanged_at_end_row
, NULL
, 0);
15952 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15953 delta_bytes
, dy
, dvpos
);
15956 /* Give up if cursor was not found. */
15957 if (w
->cursor
.vpos
< 0)
15959 clear_glyph_matrix (w
->desired_matrix
);
15964 /* Don't let the cursor end in the scroll margins. */
15966 int this_scroll_margin
, cursor_height
;
15968 this_scroll_margin
= max (0, scroll_margin
);
15969 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15970 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15971 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15973 if ((w
->cursor
.y
< this_scroll_margin
15974 && CHARPOS (start
) > BEGV
)
15975 /* Old redisplay didn't take scroll margin into account at the bottom,
15976 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15977 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15978 ? cursor_height
+ this_scroll_margin
15979 : 1)) > it
.last_visible_y
)
15981 w
->cursor
.vpos
= -1;
15982 clear_glyph_matrix (w
->desired_matrix
);
15987 /* Scroll the display. Do it before changing the current matrix so
15988 that xterm.c doesn't get confused about where the cursor glyph is
15990 if (dy
&& run
.height
)
15994 if (FRAME_WINDOW_P (f
))
15996 FRAME_RIF (f
)->update_window_begin_hook (w
);
15997 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15998 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15999 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16003 /* Terminal frame. In this case, dvpos gives the number of
16004 lines to scroll by; dvpos < 0 means scroll up. */
16005 int first_unchanged_at_end_vpos
16006 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
16007 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
16008 int end
= (WINDOW_TOP_EDGE_LINE (w
)
16009 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
16010 + window_internal_height (w
));
16012 /* Perform the operation on the screen. */
16015 /* Scroll last_unchanged_at_beg_row to the end of the
16016 window down dvpos lines. */
16017 set_terminal_window (f
, end
);
16019 /* On dumb terminals delete dvpos lines at the end
16020 before inserting dvpos empty lines. */
16021 if (!FRAME_SCROLL_REGION_OK (f
))
16022 ins_del_lines (f
, end
- dvpos
, -dvpos
);
16024 /* Insert dvpos empty lines in front of
16025 last_unchanged_at_beg_row. */
16026 ins_del_lines (f
, from
, dvpos
);
16028 else if (dvpos
< 0)
16030 /* Scroll up last_unchanged_at_beg_vpos to the end of
16031 the window to last_unchanged_at_beg_vpos - |dvpos|. */
16032 set_terminal_window (f
, end
);
16034 /* Delete dvpos lines in front of
16035 last_unchanged_at_beg_vpos. ins_del_lines will set
16036 the cursor to the given vpos and emit |dvpos| delete
16038 ins_del_lines (f
, from
+ dvpos
, dvpos
);
16040 /* On a dumb terminal insert dvpos empty lines at the
16042 if (!FRAME_SCROLL_REGION_OK (f
))
16043 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
16046 set_terminal_window (f
, 0);
16052 /* Shift reused rows of the current matrix to the right position.
16053 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
16055 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
16056 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
16059 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
16060 bottom_vpos
, dvpos
);
16061 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
16064 else if (dvpos
> 0)
16066 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
16067 bottom_vpos
, dvpos
);
16068 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
16069 first_unchanged_at_end_vpos
+ dvpos
, 0);
16072 /* For frame-based redisplay, make sure that current frame and window
16073 matrix are in sync with respect to glyph memory. */
16074 if (!FRAME_WINDOW_P (f
))
16075 sync_frame_with_window_matrix_rows (w
);
16077 /* Adjust buffer positions in reused rows. */
16078 if (delta
|| delta_bytes
)
16079 increment_matrix_positions (current_matrix
,
16080 first_unchanged_at_end_vpos
+ dvpos
,
16081 bottom_vpos
, delta
, delta_bytes
);
16083 /* Adjust Y positions. */
16085 shift_glyph_matrix (w
, current_matrix
,
16086 first_unchanged_at_end_vpos
+ dvpos
,
16089 if (first_unchanged_at_end_row
)
16091 first_unchanged_at_end_row
+= dvpos
;
16092 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
16093 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
16094 first_unchanged_at_end_row
= NULL
;
16097 /* If scrolling up, there may be some lines to display at the end of
16099 last_text_row_at_end
= NULL
;
16102 /* Scrolling up can leave for example a partially visible line
16103 at the end of the window to be redisplayed. */
16104 /* Set last_row to the glyph row in the current matrix where the
16105 window end line is found. It has been moved up or down in
16106 the matrix by dvpos. */
16107 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
16108 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
16110 /* If last_row is the window end line, it should display text. */
16111 xassert (last_row
->displays_text_p
);
16113 /* If window end line was partially visible before, begin
16114 displaying at that line. Otherwise begin displaying with the
16115 line following it. */
16116 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
16118 init_to_row_start (&it
, w
, last_row
);
16119 it
.vpos
= last_vpos
;
16120 it
.current_y
= last_row
->y
;
16124 init_to_row_end (&it
, w
, last_row
);
16125 it
.vpos
= 1 + last_vpos
;
16126 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
16130 /* We may start in a continuation line. If so, we have to
16131 get the right continuation_lines_width and current_x. */
16132 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
16133 it
.hpos
= it
.current_x
= 0;
16135 /* Display the rest of the lines at the window end. */
16136 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
16137 while (it
.current_y
< it
.last_visible_y
16138 && !fonts_changed_p
)
16140 /* Is it always sure that the display agrees with lines in
16141 the current matrix? I don't think so, so we mark rows
16142 displayed invalid in the current matrix by setting their
16143 enabled_p flag to zero. */
16144 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
16145 if (display_line (&it
))
16146 last_text_row_at_end
= it
.glyph_row
- 1;
16150 /* Update window_end_pos and window_end_vpos. */
16151 if (first_unchanged_at_end_row
16152 && !last_text_row_at_end
)
16154 /* Window end line if one of the preserved rows from the current
16155 matrix. Set row to the last row displaying text in current
16156 matrix starting at first_unchanged_at_end_row, after
16158 xassert (first_unchanged_at_end_row
->displays_text_p
);
16159 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
16160 first_unchanged_at_end_row
);
16161 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
16163 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16164 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16166 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
16167 xassert (w
->window_end_bytepos
>= 0);
16168 IF_DEBUG (debug_method_add (w
, "A"));
16170 else if (last_text_row_at_end
)
16173 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
16174 w
->window_end_bytepos
16175 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
16177 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
16178 xassert (w
->window_end_bytepos
>= 0);
16179 IF_DEBUG (debug_method_add (w
, "B"));
16181 else if (last_text_row
)
16183 /* We have displayed either to the end of the window or at the
16184 end of the window, i.e. the last row with text is to be found
16185 in the desired matrix. */
16187 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
16188 w
->window_end_bytepos
16189 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16191 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
16192 xassert (w
->window_end_bytepos
>= 0);
16194 else if (first_unchanged_at_end_row
== NULL
16195 && last_text_row
== NULL
16196 && last_text_row_at_end
== NULL
)
16198 /* Displayed to end of window, but no line containing text was
16199 displayed. Lines were deleted at the end of the window. */
16200 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
16201 int vpos
= XFASTINT (w
->window_end_vpos
);
16202 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
16203 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
16206 row
== NULL
&& vpos
>= first_vpos
;
16207 --vpos
, --current_row
, --desired_row
)
16209 if (desired_row
->enabled_p
)
16211 if (desired_row
->displays_text_p
)
16214 else if (current_row
->displays_text_p
)
16218 xassert (row
!= NULL
);
16219 w
->window_end_vpos
= make_number (vpos
+ 1);
16220 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
16221 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16222 xassert (w
->window_end_bytepos
>= 0);
16223 IF_DEBUG (debug_method_add (w
, "C"));
16228 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16229 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16231 /* Record that display has not been completed. */
16232 w
->window_end_valid
= Qnil
;
16233 w
->desired_matrix
->no_scrolling_p
= 1;
16241 /***********************************************************************
16242 More debugging support
16243 ***********************************************************************/
16247 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
16248 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
16249 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
16252 /* Dump the contents of glyph matrix MATRIX on stderr.
16254 GLYPHS 0 means don't show glyph contents.
16255 GLYPHS 1 means show glyphs in short form
16256 GLYPHS > 1 means show glyphs in long form. */
16259 dump_glyph_matrix (matrix
, glyphs
)
16260 struct glyph_matrix
*matrix
;
16264 for (i
= 0; i
< matrix
->nrows
; ++i
)
16265 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16269 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16270 the glyph row and area where the glyph comes from. */
16273 dump_glyph (row
, glyph
, area
)
16274 struct glyph_row
*row
;
16275 struct glyph
*glyph
;
16278 if (glyph
->type
== CHAR_GLYPH
)
16281 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16282 glyph
- row
->glyphs
[TEXT_AREA
],
16285 (BUFFERP (glyph
->object
)
16287 : (STRINGP (glyph
->object
)
16290 glyph
->pixel_width
,
16292 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16296 glyph
->left_box_line_p
,
16297 glyph
->right_box_line_p
);
16299 else if (glyph
->type
== STRETCH_GLYPH
)
16302 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16303 glyph
- row
->glyphs
[TEXT_AREA
],
16306 (BUFFERP (glyph
->object
)
16308 : (STRINGP (glyph
->object
)
16311 glyph
->pixel_width
,
16315 glyph
->left_box_line_p
,
16316 glyph
->right_box_line_p
);
16318 else if (glyph
->type
== IMAGE_GLYPH
)
16321 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16322 glyph
- row
->glyphs
[TEXT_AREA
],
16325 (BUFFERP (glyph
->object
)
16327 : (STRINGP (glyph
->object
)
16330 glyph
->pixel_width
,
16334 glyph
->left_box_line_p
,
16335 glyph
->right_box_line_p
);
16337 else if (glyph
->type
== COMPOSITE_GLYPH
)
16340 " %5d %4c %6d %c %3d 0x%05x",
16341 glyph
- row
->glyphs
[TEXT_AREA
],
16344 (BUFFERP (glyph
->object
)
16346 : (STRINGP (glyph
->object
)
16349 glyph
->pixel_width
,
16351 if (glyph
->u
.cmp
.automatic
)
16354 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
16355 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16357 glyph
->left_box_line_p
,
16358 glyph
->right_box_line_p
);
16363 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16364 GLYPHS 0 means don't show glyph contents.
16365 GLYPHS 1 means show glyphs in short form
16366 GLYPHS > 1 means show glyphs in long form. */
16369 dump_glyph_row (row
, vpos
, glyphs
)
16370 struct glyph_row
*row
;
16375 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16376 fprintf (stderr
, "======================================================================\n");
16378 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16379 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16381 MATRIX_ROW_START_CHARPOS (row
),
16382 MATRIX_ROW_END_CHARPOS (row
),
16383 row
->used
[TEXT_AREA
],
16384 row
->contains_overlapping_glyphs_p
,
16386 row
->truncated_on_left_p
,
16387 row
->truncated_on_right_p
,
16389 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16390 row
->displays_text_p
,
16393 row
->ends_in_middle_of_char_p
,
16394 row
->starts_in_middle_of_char_p
,
16400 row
->visible_height
,
16403 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16404 row
->end
.overlay_string_index
,
16405 row
->continuation_lines_width
);
16406 fprintf (stderr
, "%9d %5d\n",
16407 CHARPOS (row
->start
.string_pos
),
16408 CHARPOS (row
->end
.string_pos
));
16409 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16410 row
->end
.dpvec_index
);
16417 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16419 struct glyph
*glyph
= row
->glyphs
[area
];
16420 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16422 /* Glyph for a line end in text. */
16423 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16426 if (glyph
< glyph_end
)
16427 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16429 for (; glyph
< glyph_end
; ++glyph
)
16430 dump_glyph (row
, glyph
, area
);
16433 else if (glyphs
== 1)
16437 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16439 char *s
= (char *) alloca (row
->used
[area
] + 1);
16442 for (i
= 0; i
< row
->used
[area
]; ++i
)
16444 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16445 if (glyph
->type
== CHAR_GLYPH
16446 && glyph
->u
.ch
< 0x80
16447 && glyph
->u
.ch
>= ' ')
16448 s
[i
] = glyph
->u
.ch
;
16454 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16460 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16461 Sdump_glyph_matrix
, 0, 1, "p",
16462 doc
: /* Dump the current matrix of the selected window to stderr.
16463 Shows contents of glyph row structures. With non-nil
16464 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16465 glyphs in short form, otherwise show glyphs in long form. */)
16467 Lisp_Object glyphs
;
16469 struct window
*w
= XWINDOW (selected_window
);
16470 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16472 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16473 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16474 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16475 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16476 fprintf (stderr
, "=============================================\n");
16477 dump_glyph_matrix (w
->current_matrix
,
16478 NILP (glyphs
) ? 0 : XINT (glyphs
));
16483 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16484 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16487 struct frame
*f
= XFRAME (selected_frame
);
16488 dump_glyph_matrix (f
->current_matrix
, 1);
16493 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16494 doc
: /* Dump glyph row ROW to stderr.
16495 GLYPH 0 means don't dump glyphs.
16496 GLYPH 1 means dump glyphs in short form.
16497 GLYPH > 1 or omitted means dump glyphs in long form. */)
16499 Lisp_Object row
, glyphs
;
16501 struct glyph_matrix
*matrix
;
16504 CHECK_NUMBER (row
);
16505 matrix
= XWINDOW (selected_window
)->current_matrix
;
16507 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16508 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16510 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16515 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16516 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16517 GLYPH 0 means don't dump glyphs.
16518 GLYPH 1 means dump glyphs in short form.
16519 GLYPH > 1 or omitted means dump glyphs in long form. */)
16521 Lisp_Object row
, glyphs
;
16523 struct frame
*sf
= SELECTED_FRAME ();
16524 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16527 CHECK_NUMBER (row
);
16529 if (vpos
>= 0 && vpos
< m
->nrows
)
16530 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16531 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16536 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16537 doc
: /* Toggle tracing of redisplay.
16538 With ARG, turn tracing on if and only if ARG is positive. */)
16543 trace_redisplay_p
= !trace_redisplay_p
;
16546 arg
= Fprefix_numeric_value (arg
);
16547 trace_redisplay_p
= XINT (arg
) > 0;
16554 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16555 doc
: /* Like `format', but print result to stderr.
16556 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16561 Lisp_Object s
= Fformat (nargs
, args
);
16562 fprintf (stderr
, "%s", SDATA (s
));
16566 #endif /* GLYPH_DEBUG */
16570 /***********************************************************************
16571 Building Desired Matrix Rows
16572 ***********************************************************************/
16574 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16575 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16577 static struct glyph_row
*
16578 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
16580 Lisp_Object overlay_arrow_string
;
16582 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16583 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16584 struct buffer
*old
= current_buffer
;
16585 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16586 int arrow_len
= SCHARS (overlay_arrow_string
);
16587 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16588 const unsigned char *p
;
16591 int n_glyphs_before
;
16593 set_buffer_temp (buffer
);
16594 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16595 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16596 SET_TEXT_POS (it
.position
, 0, 0);
16598 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16600 while (p
< arrow_end
)
16602 Lisp_Object face
, ilisp
;
16604 /* Get the next character. */
16606 it
.c
= string_char_and_length (p
, &it
.len
);
16608 it
.c
= *p
, it
.len
= 1;
16611 /* Get its face. */
16612 ilisp
= make_number (p
- arrow_string
);
16613 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16614 it
.face_id
= compute_char_face (f
, it
.c
, face
);
16616 /* Compute its width, get its glyphs. */
16617 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16618 SET_TEXT_POS (it
.position
, -1, -1);
16619 PRODUCE_GLYPHS (&it
);
16621 /* If this character doesn't fit any more in the line, we have
16622 to remove some glyphs. */
16623 if (it
.current_x
> it
.last_visible_x
)
16625 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16630 set_buffer_temp (old
);
16631 return it
.glyph_row
;
16635 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16636 glyphs are only inserted for terminal frames since we can't really
16637 win with truncation glyphs when partially visible glyphs are
16638 involved. Which glyphs to insert is determined by
16639 produce_special_glyphs. */
16642 insert_left_trunc_glyphs (it
)
16645 struct it truncate_it
;
16646 struct glyph
*from
, *end
, *to
, *toend
;
16648 xassert (!FRAME_WINDOW_P (it
->f
));
16650 /* Get the truncation glyphs. */
16652 truncate_it
.current_x
= 0;
16653 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16654 truncate_it
.glyph_row
= &scratch_glyph_row
;
16655 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16656 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16657 truncate_it
.object
= make_number (0);
16658 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16660 /* Overwrite glyphs from IT with truncation glyphs. */
16661 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16662 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16663 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16664 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16669 /* There may be padding glyphs left over. Overwrite them too. */
16670 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16672 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16678 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16682 /* Compute the pixel height and width of IT->glyph_row.
16684 Most of the time, ascent and height of a display line will be equal
16685 to the max_ascent and max_height values of the display iterator
16686 structure. This is not the case if
16688 1. We hit ZV without displaying anything. In this case, max_ascent
16689 and max_height will be zero.
16691 2. We have some glyphs that don't contribute to the line height.
16692 (The glyph row flag contributes_to_line_height_p is for future
16693 pixmap extensions).
16695 The first case is easily covered by using default values because in
16696 these cases, the line height does not really matter, except that it
16697 must not be zero. */
16700 compute_line_metrics (it
)
16703 struct glyph_row
*row
= it
->glyph_row
;
16706 if (FRAME_WINDOW_P (it
->f
))
16708 int i
, min_y
, max_y
;
16710 /* The line may consist of one space only, that was added to
16711 place the cursor on it. If so, the row's height hasn't been
16713 if (row
->height
== 0)
16715 if (it
->max_ascent
+ it
->max_descent
== 0)
16716 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16717 row
->ascent
= it
->max_ascent
;
16718 row
->height
= it
->max_ascent
+ it
->max_descent
;
16719 row
->phys_ascent
= it
->max_phys_ascent
;
16720 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16721 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16724 /* Compute the width of this line. */
16725 row
->pixel_width
= row
->x
;
16726 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16727 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16729 xassert (row
->pixel_width
>= 0);
16730 xassert (row
->ascent
>= 0 && row
->height
> 0);
16732 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16733 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16735 /* If first line's physical ascent is larger than its logical
16736 ascent, use the physical ascent, and make the row taller.
16737 This makes accented characters fully visible. */
16738 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16739 && row
->phys_ascent
> row
->ascent
)
16741 row
->height
+= row
->phys_ascent
- row
->ascent
;
16742 row
->ascent
= row
->phys_ascent
;
16745 /* Compute how much of the line is visible. */
16746 row
->visible_height
= row
->height
;
16748 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16749 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16751 if (row
->y
< min_y
)
16752 row
->visible_height
-= min_y
- row
->y
;
16753 if (row
->y
+ row
->height
> max_y
)
16754 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16758 row
->pixel_width
= row
->used
[TEXT_AREA
];
16759 if (row
->continued_p
)
16760 row
->pixel_width
-= it
->continuation_pixel_width
;
16761 else if (row
->truncated_on_right_p
)
16762 row
->pixel_width
-= it
->truncation_pixel_width
;
16763 row
->ascent
= row
->phys_ascent
= 0;
16764 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16765 row
->extra_line_spacing
= 0;
16768 /* Compute a hash code for this row. */
16770 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16771 for (i
= 0; i
< row
->used
[area
]; ++i
)
16772 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16773 + row
->glyphs
[area
][i
].u
.val
16774 + row
->glyphs
[area
][i
].face_id
16775 + row
->glyphs
[area
][i
].padding_p
16776 + (row
->glyphs
[area
][i
].type
<< 2));
16778 it
->max_ascent
= it
->max_descent
= 0;
16779 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16783 /* Append one space to the glyph row of iterator IT if doing a
16784 window-based redisplay. The space has the same face as
16785 IT->face_id. Value is non-zero if a space was added.
16787 This function is called to make sure that there is always one glyph
16788 at the end of a glyph row that the cursor can be set on under
16789 window-systems. (If there weren't such a glyph we would not know
16790 how wide and tall a box cursor should be displayed).
16792 At the same time this space let's a nicely handle clearing to the
16793 end of the line if the row ends in italic text. */
16796 append_space_for_newline (it
, default_face_p
)
16798 int default_face_p
;
16800 if (FRAME_WINDOW_P (it
->f
))
16802 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16804 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16805 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16807 /* Save some values that must not be changed.
16808 Must save IT->c and IT->len because otherwise
16809 ITERATOR_AT_END_P wouldn't work anymore after
16810 append_space_for_newline has been called. */
16811 enum display_element_type saved_what
= it
->what
;
16812 int saved_c
= it
->c
, saved_len
= it
->len
;
16813 int saved_x
= it
->current_x
;
16814 int saved_face_id
= it
->face_id
;
16815 struct text_pos saved_pos
;
16816 Lisp_Object saved_object
;
16819 saved_object
= it
->object
;
16820 saved_pos
= it
->position
;
16822 it
->what
= IT_CHARACTER
;
16823 bzero (&it
->position
, sizeof it
->position
);
16824 it
->object
= make_number (0);
16828 if (default_face_p
)
16829 it
->face_id
= DEFAULT_FACE_ID
;
16830 else if (it
->face_before_selective_p
)
16831 it
->face_id
= it
->saved_face_id
;
16832 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16833 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16835 PRODUCE_GLYPHS (it
);
16837 it
->override_ascent
= -1;
16838 it
->constrain_row_ascent_descent_p
= 0;
16839 it
->current_x
= saved_x
;
16840 it
->object
= saved_object
;
16841 it
->position
= saved_pos
;
16842 it
->what
= saved_what
;
16843 it
->face_id
= saved_face_id
;
16844 it
->len
= saved_len
;
16854 /* Extend the face of the last glyph in the text area of IT->glyph_row
16855 to the end of the display line. Called from display_line.
16856 If the glyph row is empty, add a space glyph to it so that we
16857 know the face to draw. Set the glyph row flag fill_line_p. */
16860 extend_face_to_end_of_line (it
)
16864 struct frame
*f
= it
->f
;
16866 /* If line is already filled, do nothing. */
16867 if (it
->current_x
>= it
->last_visible_x
)
16870 /* Face extension extends the background and box of IT->face_id
16871 to the end of the line. If the background equals the background
16872 of the frame, we don't have to do anything. */
16873 if (it
->face_before_selective_p
)
16874 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16876 face
= FACE_FROM_ID (f
, it
->face_id
);
16878 if (FRAME_WINDOW_P (f
)
16879 && it
->glyph_row
->displays_text_p
16880 && face
->box
== FACE_NO_BOX
16881 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16885 /* Set the glyph row flag indicating that the face of the last glyph
16886 in the text area has to be drawn to the end of the text area. */
16887 it
->glyph_row
->fill_line_p
= 1;
16889 /* If current character of IT is not ASCII, make sure we have the
16890 ASCII face. This will be automatically undone the next time
16891 get_next_display_element returns a multibyte character. Note
16892 that the character will always be single byte in unibyte
16894 if (!ASCII_CHAR_P (it
->c
))
16896 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16899 if (FRAME_WINDOW_P (f
))
16901 /* If the row is empty, add a space with the current face of IT,
16902 so that we know which face to draw. */
16903 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16905 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16906 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16907 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16912 /* Save some values that must not be changed. */
16913 int saved_x
= it
->current_x
;
16914 struct text_pos saved_pos
;
16915 Lisp_Object saved_object
;
16916 enum display_element_type saved_what
= it
->what
;
16917 int saved_face_id
= it
->face_id
;
16919 saved_object
= it
->object
;
16920 saved_pos
= it
->position
;
16922 it
->what
= IT_CHARACTER
;
16923 bzero (&it
->position
, sizeof it
->position
);
16924 it
->object
= make_number (0);
16927 it
->face_id
= face
->id
;
16929 PRODUCE_GLYPHS (it
);
16931 while (it
->current_x
<= it
->last_visible_x
)
16932 PRODUCE_GLYPHS (it
);
16934 /* Don't count these blanks really. It would let us insert a left
16935 truncation glyph below and make us set the cursor on them, maybe. */
16936 it
->current_x
= saved_x
;
16937 it
->object
= saved_object
;
16938 it
->position
= saved_pos
;
16939 it
->what
= saved_what
;
16940 it
->face_id
= saved_face_id
;
16945 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16946 trailing whitespace. */
16949 trailing_whitespace_p (charpos
)
16952 int bytepos
= CHAR_TO_BYTE (charpos
);
16955 while (bytepos
< ZV_BYTE
16956 && (c
= FETCH_CHAR (bytepos
),
16957 c
== ' ' || c
== '\t'))
16960 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16962 if (bytepos
!= PT_BYTE
)
16969 /* Highlight trailing whitespace, if any, in ROW. */
16972 highlight_trailing_whitespace (f
, row
)
16974 struct glyph_row
*row
;
16976 int used
= row
->used
[TEXT_AREA
];
16980 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16981 struct glyph
*glyph
= start
+ used
- 1;
16983 /* Skip over glyphs inserted to display the cursor at the
16984 end of a line, for extending the face of the last glyph
16985 to the end of the line on terminals, and for truncation
16986 and continuation glyphs. */
16987 while (glyph
>= start
16988 && glyph
->type
== CHAR_GLYPH
16989 && INTEGERP (glyph
->object
))
16992 /* If last glyph is a space or stretch, and it's trailing
16993 whitespace, set the face of all trailing whitespace glyphs in
16994 IT->glyph_row to `trailing-whitespace'. */
16996 && BUFFERP (glyph
->object
)
16997 && (glyph
->type
== STRETCH_GLYPH
16998 || (glyph
->type
== CHAR_GLYPH
16999 && glyph
->u
.ch
== ' '))
17000 && trailing_whitespace_p (glyph
->charpos
))
17002 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
17006 while (glyph
>= start
17007 && BUFFERP (glyph
->object
)
17008 && (glyph
->type
== STRETCH_GLYPH
17009 || (glyph
->type
== CHAR_GLYPH
17010 && glyph
->u
.ch
== ' ')))
17011 (glyph
--)->face_id
= face_id
;
17017 /* Value is non-zero if glyph row ROW in window W should be
17018 used to hold the cursor. */
17021 cursor_row_p (w
, row
)
17023 struct glyph_row
*row
;
17025 int cursor_row_p
= 1;
17027 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
17029 /* Suppose the row ends on a string.
17030 Unless the row is continued, that means it ends on a newline
17031 in the string. If it's anything other than a display string
17032 (e.g. a before-string from an overlay), we don't want the
17033 cursor there. (This heuristic seems to give the optimal
17034 behavior for the various types of multi-line strings.) */
17035 if (CHARPOS (row
->end
.string_pos
) >= 0)
17037 if (row
->continued_p
)
17041 /* Check for `display' property. */
17042 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
17043 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
17044 struct glyph
*glyph
;
17047 for (glyph
= end
; glyph
>= beg
; --glyph
)
17048 if (STRINGP (glyph
->object
))
17051 = Fget_char_property (make_number (PT
),
17055 && display_prop_string_p (prop
, glyph
->object
));
17060 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
17062 /* If the row ends in middle of a real character,
17063 and the line is continued, we want the cursor here.
17064 That's because MATRIX_ROW_END_CHARPOS would equal
17065 PT if PT is before the character. */
17066 if (!row
->ends_in_ellipsis_p
)
17067 cursor_row_p
= row
->continued_p
;
17069 /* If the row ends in an ellipsis, then
17070 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
17071 We want that position to be displayed after the ellipsis. */
17074 /* If the row ends at ZV, display the cursor at the end of that
17075 row instead of at the start of the row below. */
17076 else if (row
->ends_at_zv_p
)
17082 return cursor_row_p
;
17087 /* Push the display property PROP so that it will be rendered at the
17088 current position in IT. Return 1 if PROP was successfully pushed,
17092 push_display_prop (struct it
*it
, Lisp_Object prop
)
17096 if (STRINGP (prop
))
17098 if (SCHARS (prop
) == 0)
17105 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
17106 it
->current
.overlay_string_index
= -1;
17107 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
17108 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
17109 it
->method
= GET_FROM_STRING
;
17110 it
->stop_charpos
= 0;
17112 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
17114 it
->method
= GET_FROM_STRETCH
;
17117 #ifdef HAVE_WINDOW_SYSTEM
17118 else if (IMAGEP (prop
))
17120 it
->what
= IT_IMAGE
;
17121 it
->image_id
= lookup_image (it
->f
, prop
);
17122 it
->method
= GET_FROM_IMAGE
;
17124 #endif /* HAVE_WINDOW_SYSTEM */
17127 pop_it (it
); /* bogus display property, give up */
17134 /* Return the character-property PROP at the current position in IT. */
17137 get_it_property (it
, prop
)
17141 Lisp_Object position
;
17143 if (STRINGP (it
->object
))
17144 position
= make_number (IT_STRING_CHARPOS (*it
));
17145 else if (BUFFERP (it
->object
))
17146 position
= make_number (IT_CHARPOS (*it
));
17150 return Fget_char_property (position
, prop
, it
->object
);
17153 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
17156 handle_line_prefix (struct it
*it
)
17158 Lisp_Object prefix
;
17159 if (it
->continuation_lines_width
> 0)
17161 prefix
= get_it_property (it
, Qwrap_prefix
);
17163 prefix
= Vwrap_prefix
;
17167 prefix
= get_it_property (it
, Qline_prefix
);
17169 prefix
= Vline_prefix
;
17171 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
17173 /* If the prefix is wider than the window, and we try to wrap
17174 it, it would acquire its own wrap prefix, and so on till the
17175 iterator stack overflows. So, don't wrap the prefix. */
17176 it
->line_wrap
= TRUNCATE
;
17177 it
->avoid_cursor_p
= 1;
17183 /* Construct the glyph row IT->glyph_row in the desired matrix of
17184 IT->w from text at the current position of IT. See dispextern.h
17185 for an overview of struct it. Value is non-zero if
17186 IT->glyph_row displays text, as opposed to a line displaying ZV
17193 struct glyph_row
*row
= it
->glyph_row
;
17194 Lisp_Object overlay_arrow_string
;
17196 int may_wrap
= 0, wrap_x
;
17197 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
17198 int wrap_row_phys_ascent
, wrap_row_phys_height
;
17199 int wrap_row_extra_line_spacing
;
17200 struct display_pos row_end
;
17203 /* We always start displaying at hpos zero even if hscrolled. */
17204 xassert (it
->hpos
== 0 && it
->current_x
== 0);
17206 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
17207 >= it
->w
->desired_matrix
->nrows
)
17209 it
->w
->nrows_scale_factor
++;
17210 fonts_changed_p
= 1;
17214 /* Is IT->w showing the region? */
17215 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
17217 /* Clear the result glyph row and enable it. */
17218 prepare_desired_row (row
);
17220 row
->y
= it
->current_y
;
17221 row
->start
= it
->start
;
17222 row
->continuation_lines_width
= it
->continuation_lines_width
;
17223 row
->displays_text_p
= 1;
17224 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17225 it
->starts_in_middle_of_char_p
= 0;
17227 /* Arrange the overlays nicely for our purposes. Usually, we call
17228 display_line on only one line at a time, in which case this
17229 can't really hurt too much, or we call it on lines which appear
17230 one after another in the buffer, in which case all calls to
17231 recenter_overlay_lists but the first will be pretty cheap. */
17232 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17234 /* Move over display elements that are not visible because we are
17235 hscrolled. This may stop at an x-position < IT->first_visible_x
17236 if the first glyph is partially visible or if we hit a line end. */
17237 if (it
->current_x
< it
->first_visible_x
)
17239 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17240 MOVE_TO_POS
| MOVE_TO_X
);
17244 /* We only do this when not calling `move_it_in_display_line_to'
17245 above, because move_it_in_display_line_to calls
17246 handle_line_prefix itself. */
17247 handle_line_prefix (it
);
17250 /* Get the initial row height. This is either the height of the
17251 text hscrolled, if there is any, or zero. */
17252 row
->ascent
= it
->max_ascent
;
17253 row
->height
= it
->max_ascent
+ it
->max_descent
;
17254 row
->phys_ascent
= it
->max_phys_ascent
;
17255 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17256 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17258 /* Loop generating characters. The loop is left with IT on the next
17259 character to display. */
17262 int n_glyphs_before
, hpos_before
, x_before
;
17264 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17266 /* Retrieve the next thing to display. Value is zero if end of
17268 if (!get_next_display_element (it
))
17270 /* Maybe add a space at the end of this line that is used to
17271 display the cursor there under X. Set the charpos of the
17272 first glyph of blank lines not corresponding to any text
17274 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17275 row
->exact_window_width_line_p
= 1;
17276 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17277 || row
->used
[TEXT_AREA
] == 0)
17279 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17280 row
->displays_text_p
= 0;
17282 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17283 && (!MINI_WINDOW_P (it
->w
)
17284 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17285 row
->indicate_empty_line_p
= 1;
17288 it
->continuation_lines_width
= 0;
17289 row
->ends_at_zv_p
= 1;
17290 /* A row that displays right-to-left text must always have
17291 its last face extended all the way to the end of line,
17292 even if this row ends in ZV. */
17293 if (row
->reversed_p
)
17294 extend_face_to_end_of_line (it
);
17298 /* Now, get the metrics of what we want to display. This also
17299 generates glyphs in `row' (which is IT->glyph_row). */
17300 n_glyphs_before
= row
->used
[TEXT_AREA
];
17303 /* Remember the line height so far in case the next element doesn't
17304 fit on the line. */
17305 if (it
->line_wrap
!= TRUNCATE
)
17307 ascent
= it
->max_ascent
;
17308 descent
= it
->max_descent
;
17309 phys_ascent
= it
->max_phys_ascent
;
17310 phys_descent
= it
->max_phys_descent
;
17312 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17314 if (IT_DISPLAYING_WHITESPACE (it
))
17320 wrap_row_used
= row
->used
[TEXT_AREA
];
17321 wrap_row_ascent
= row
->ascent
;
17322 wrap_row_height
= row
->height
;
17323 wrap_row_phys_ascent
= row
->phys_ascent
;
17324 wrap_row_phys_height
= row
->phys_height
;
17325 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17331 PRODUCE_GLYPHS (it
);
17333 /* If this display element was in marginal areas, continue with
17335 if (it
->area
!= TEXT_AREA
)
17337 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17338 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17339 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17340 row
->phys_height
= max (row
->phys_height
,
17341 it
->max_phys_ascent
+ it
->max_phys_descent
);
17342 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17343 it
->max_extra_line_spacing
);
17344 set_iterator_to_next (it
, 1);
17348 /* Does the display element fit on the line? If we truncate
17349 lines, we should draw past the right edge of the window. If
17350 we don't truncate, we want to stop so that we can display the
17351 continuation glyph before the right margin. If lines are
17352 continued, there are two possible strategies for characters
17353 resulting in more than 1 glyph (e.g. tabs): Display as many
17354 glyphs as possible in this line and leave the rest for the
17355 continuation line, or display the whole element in the next
17356 line. Original redisplay did the former, so we do it also. */
17357 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17358 hpos_before
= it
->hpos
;
17361 if (/* Not a newline. */
17363 /* Glyphs produced fit entirely in the line. */
17364 && it
->current_x
< it
->last_visible_x
)
17366 it
->hpos
+= nglyphs
;
17367 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17368 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17369 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17370 row
->phys_height
= max (row
->phys_height
,
17371 it
->max_phys_ascent
+ it
->max_phys_descent
);
17372 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17373 it
->max_extra_line_spacing
);
17374 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17375 row
->x
= x
- it
->first_visible_x
;
17380 struct glyph
*glyph
;
17382 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17384 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17385 new_x
= x
+ glyph
->pixel_width
;
17387 if (/* Lines are continued. */
17388 it
->line_wrap
!= TRUNCATE
17389 && (/* Glyph doesn't fit on the line. */
17390 new_x
> it
->last_visible_x
17391 /* Or it fits exactly on a window system frame. */
17392 || (new_x
== it
->last_visible_x
17393 && FRAME_WINDOW_P (it
->f
))))
17395 /* End of a continued line. */
17398 || (new_x
== it
->last_visible_x
17399 && FRAME_WINDOW_P (it
->f
)))
17401 /* Current glyph is the only one on the line or
17402 fits exactly on the line. We must continue
17403 the line because we can't draw the cursor
17404 after the glyph. */
17405 row
->continued_p
= 1;
17406 it
->current_x
= new_x
;
17407 it
->continuation_lines_width
+= new_x
;
17409 if (i
== nglyphs
- 1)
17411 /* If line-wrap is on, check if a previous
17412 wrap point was found. */
17413 if (wrap_row_used
> 0
17414 /* Even if there is a previous wrap
17415 point, continue the line here as
17416 usual, if (i) the previous character
17417 was a space or tab AND (ii) the
17418 current character is not. */
17420 || IT_DISPLAYING_WHITESPACE (it
)))
17423 set_iterator_to_next (it
, 1);
17424 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17426 if (!get_next_display_element (it
))
17428 row
->exact_window_width_line_p
= 1;
17429 it
->continuation_lines_width
= 0;
17430 row
->continued_p
= 0;
17431 row
->ends_at_zv_p
= 1;
17433 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17435 row
->continued_p
= 0;
17436 row
->exact_window_width_line_p
= 1;
17441 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17442 && !FRAME_WINDOW_P (it
->f
))
17444 /* A padding glyph that doesn't fit on this line.
17445 This means the whole character doesn't fit
17447 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17449 /* Fill the rest of the row with continuation
17450 glyphs like in 20.x. */
17451 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17452 < row
->glyphs
[1 + TEXT_AREA
])
17453 produce_special_glyphs (it
, IT_CONTINUATION
);
17455 row
->continued_p
= 1;
17456 it
->current_x
= x_before
;
17457 it
->continuation_lines_width
+= x_before
;
17459 /* Restore the height to what it was before the
17460 element not fitting on the line. */
17461 it
->max_ascent
= ascent
;
17462 it
->max_descent
= descent
;
17463 it
->max_phys_ascent
= phys_ascent
;
17464 it
->max_phys_descent
= phys_descent
;
17466 else if (wrap_row_used
> 0)
17470 it
->continuation_lines_width
+= wrap_x
;
17471 row
->used
[TEXT_AREA
] = wrap_row_used
;
17472 row
->ascent
= wrap_row_ascent
;
17473 row
->height
= wrap_row_height
;
17474 row
->phys_ascent
= wrap_row_phys_ascent
;
17475 row
->phys_height
= wrap_row_phys_height
;
17476 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17477 row
->continued_p
= 1;
17478 row
->ends_at_zv_p
= 0;
17479 row
->exact_window_width_line_p
= 0;
17480 it
->continuation_lines_width
+= x
;
17482 /* Make sure that a non-default face is extended
17483 up to the right margin of the window. */
17484 extend_face_to_end_of_line (it
);
17486 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17488 /* A TAB that extends past the right edge of the
17489 window. This produces a single glyph on
17490 window system frames. We leave the glyph in
17491 this row and let it fill the row, but don't
17492 consume the TAB. */
17493 it
->continuation_lines_width
+= it
->last_visible_x
;
17494 row
->ends_in_middle_of_char_p
= 1;
17495 row
->continued_p
= 1;
17496 glyph
->pixel_width
= it
->last_visible_x
- x
;
17497 it
->starts_in_middle_of_char_p
= 1;
17501 /* Something other than a TAB that draws past
17502 the right edge of the window. Restore
17503 positions to values before the element. */
17504 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17506 /* Display continuation glyphs. */
17507 if (!FRAME_WINDOW_P (it
->f
))
17508 produce_special_glyphs (it
, IT_CONTINUATION
);
17509 row
->continued_p
= 1;
17511 it
->current_x
= x_before
;
17512 it
->continuation_lines_width
+= x
;
17513 extend_face_to_end_of_line (it
);
17515 if (nglyphs
> 1 && i
> 0)
17517 row
->ends_in_middle_of_char_p
= 1;
17518 it
->starts_in_middle_of_char_p
= 1;
17521 /* Restore the height to what it was before the
17522 element not fitting on the line. */
17523 it
->max_ascent
= ascent
;
17524 it
->max_descent
= descent
;
17525 it
->max_phys_ascent
= phys_ascent
;
17526 it
->max_phys_descent
= phys_descent
;
17531 else if (new_x
> it
->first_visible_x
)
17533 /* Increment number of glyphs actually displayed. */
17536 if (x
< it
->first_visible_x
)
17537 /* Glyph is partially visible, i.e. row starts at
17538 negative X position. */
17539 row
->x
= x
- it
->first_visible_x
;
17543 /* Glyph is completely off the left margin of the
17544 window. This should not happen because of the
17545 move_it_in_display_line at the start of this
17546 function, unless the text display area of the
17547 window is empty. */
17548 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17552 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17553 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17554 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17555 row
->phys_height
= max (row
->phys_height
,
17556 it
->max_phys_ascent
+ it
->max_phys_descent
);
17557 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17558 it
->max_extra_line_spacing
);
17560 /* End of this display line if row is continued. */
17561 if (row
->continued_p
|| row
->ends_at_zv_p
)
17566 /* Is this a line end? If yes, we're also done, after making
17567 sure that a non-default face is extended up to the right
17568 margin of the window. */
17569 if (ITERATOR_AT_END_OF_LINE_P (it
))
17571 int used_before
= row
->used
[TEXT_AREA
];
17573 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17575 /* Add a space at the end of the line that is used to
17576 display the cursor there. */
17577 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17578 append_space_for_newline (it
, 0);
17580 /* Extend the face to the end of the line. */
17581 extend_face_to_end_of_line (it
);
17583 /* Make sure we have the position. */
17584 if (used_before
== 0)
17585 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17587 /* Consume the line end. This skips over invisible lines. */
17588 set_iterator_to_next (it
, 1);
17589 it
->continuation_lines_width
= 0;
17593 /* Proceed with next display element. Note that this skips
17594 over lines invisible because of selective display. */
17595 set_iterator_to_next (it
, 1);
17597 /* If we truncate lines, we are done when the last displayed
17598 glyphs reach past the right margin of the window. */
17599 if (it
->line_wrap
== TRUNCATE
17600 && (FRAME_WINDOW_P (it
->f
)
17601 ? (it
->current_x
>= it
->last_visible_x
)
17602 : (it
->current_x
> it
->last_visible_x
)))
17604 /* Maybe add truncation glyphs. */
17605 if (!FRAME_WINDOW_P (it
->f
))
17609 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17610 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17613 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17615 row
->used
[TEXT_AREA
] = i
;
17616 produce_special_glyphs (it
, IT_TRUNCATION
);
17619 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17621 /* Don't truncate if we can overflow newline into fringe. */
17622 if (!get_next_display_element (it
))
17624 it
->continuation_lines_width
= 0;
17625 row
->ends_at_zv_p
= 1;
17626 row
->exact_window_width_line_p
= 1;
17629 if (ITERATOR_AT_END_OF_LINE_P (it
))
17631 row
->exact_window_width_line_p
= 1;
17632 goto at_end_of_line
;
17636 row
->truncated_on_right_p
= 1;
17637 it
->continuation_lines_width
= 0;
17638 reseat_at_next_visible_line_start (it
, 0);
17639 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17640 it
->hpos
= hpos_before
;
17641 it
->current_x
= x_before
;
17646 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17647 at the left window margin. */
17648 if (it
->first_visible_x
17649 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
17651 if (!FRAME_WINDOW_P (it
->f
))
17652 insert_left_trunc_glyphs (it
);
17653 row
->truncated_on_left_p
= 1;
17656 /* If the start of this line is the overlay arrow-position, then
17657 mark this glyph row as the one containing the overlay arrow.
17658 This is clearly a mess with variable size fonts. It would be
17659 better to let it be displayed like cursors under X. */
17660 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17661 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17662 !NILP (overlay_arrow_string
)))
17664 /* Overlay arrow in window redisplay is a fringe bitmap. */
17665 if (STRINGP (overlay_arrow_string
))
17667 struct glyph_row
*arrow_row
17668 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17669 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17670 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17671 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17672 struct glyph
*p2
, *end
;
17674 /* Copy the arrow glyphs. */
17675 while (glyph
< arrow_end
)
17678 /* Throw away padding glyphs. */
17680 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17681 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17687 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17692 xassert (INTEGERP (overlay_arrow_string
));
17693 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17695 overlay_arrow_seen
= 1;
17698 /* Compute pixel dimensions of this line. */
17699 compute_line_metrics (it
);
17701 /* Remember the position at which this line ends. */
17702 row
->end
= row_end
= it
->current
;
17705 /* ROW->start and ROW->end must be the smallest and largest
17706 buffer positions in ROW. But if ROW was bidi-reordered,
17707 these two positions can be anywhere in the row, so we must
17708 rescan all of the ROW's glyphs to find them. */
17709 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17710 lines' rows is implemented for bidi-reordered rows. */
17711 EMACS_INT min_pos
= ZV
+ 1, max_pos
= 0;
17714 struct text_pos tpos
;
17716 for (g
= row
->glyphs
[TEXT_AREA
];
17717 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17720 if (BUFFERP (g
->object
))
17722 if (g
->charpos
> 0 && g
->charpos
< min_pos
)
17723 min_pos
= g
->charpos
;
17724 if (g
->charpos
> max_pos
)
17725 max_pos
= g
->charpos
;
17728 /* Empty lines have a valid buffer position at their first
17729 glyph, but that glyph's OBJECT is zero, as if it didn't come
17730 from a buffer. If we didn't find any valid buffer positions
17731 in this row, maybe we have such an empty line. */
17732 if (min_pos
== ZV
+ 1 && row
->used
[TEXT_AREA
])
17734 for (g
= row
->glyphs
[TEXT_AREA
];
17735 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17738 if (INTEGERP (g
->object
))
17740 if (g
->charpos
> 0 && g
->charpos
< min_pos
)
17741 min_pos
= g
->charpos
;
17742 if (g
->charpos
> max_pos
)
17743 max_pos
= g
->charpos
;
17749 if (min_pos
!= row
->start
.pos
.charpos
)
17751 row
->start
.pos
.charpos
= min_pos
;
17752 row
->start
.pos
.bytepos
= CHAR_TO_BYTE (min_pos
);
17757 /* For ROW->end, we need the position that is _after_ max_pos,
17758 in the logical order, unless we are at ZV. */
17759 if (row
->ends_at_zv_p
)
17761 row_end
= row
->end
= it
->current
;
17762 if (!row
->used
[TEXT_AREA
])
17764 row
->start
.pos
.charpos
= row_end
.pos
.charpos
;
17765 row
->start
.pos
.bytepos
= row_end
.pos
.bytepos
;
17768 else if (row
->used
[TEXT_AREA
] && max_pos
)
17770 SET_TEXT_POS (tpos
, max_pos
+ 1, CHAR_TO_BYTE (max_pos
+ 1));
17771 row_end
= it
->current
;
17772 row_end
.pos
= tpos
;
17773 /* If the character at max_pos+1 is a newline, skip that as
17774 well. Note that this may skip some invisible text. */
17775 if (FETCH_CHAR (tpos
.bytepos
) == '\n'
17776 || (FETCH_CHAR (tpos
.bytepos
) == '\r' && it
->selective
))
17780 reseat_1 (it
, tpos
, 0);
17781 set_iterator_to_next (it
, 1);
17782 /* Record the position after the newline of a continued
17783 row. We will need that to set ROW->end of the last
17784 row produced for a continued line. */
17785 if (row
->continued_p
)
17787 save_it
.eol_pos
.charpos
= IT_CHARPOS (*it
);
17788 save_it
.eol_pos
.bytepos
= IT_BYTEPOS (*it
);
17792 row_end
= it
->current
;
17793 save_it
.eol_pos
.charpos
= save_it
.eol_pos
.bytepos
= 0;
17797 else if (!row
->continued_p
17798 && row
->continuation_lines_width
17799 && it
->eol_pos
.charpos
> 0)
17801 /* Last row of a continued line. Use the position
17802 recorded in ROW->eol_pos, to the effect that the
17803 newline belongs to this row, not to the row which
17804 displays the character with the largest buffer
17806 row_end
.pos
= it
->eol_pos
;
17807 it
->eol_pos
.charpos
= it
->eol_pos
.bytepos
= 0;
17809 row
->end
= row_end
;
17813 /* Record whether this row ends inside an ellipsis. */
17814 row
->ends_in_ellipsis_p
17815 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17816 && it
->ellipsis_p
);
17818 /* Save fringe bitmaps in this row. */
17819 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17820 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17821 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17822 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17824 it
->left_user_fringe_bitmap
= 0;
17825 it
->left_user_fringe_face_id
= 0;
17826 it
->right_user_fringe_bitmap
= 0;
17827 it
->right_user_fringe_face_id
= 0;
17829 /* Maybe set the cursor. */
17830 cvpos
= it
->w
->cursor
.vpos
;
17832 /* In bidi-reordered rows, keep checking for proper cursor
17833 position even if one has been found already, because buffer
17834 positions in such rows change non-linearly with ROW->VPOS,
17835 when a line is continued. One exception: when we are at ZV,
17836 display cursor on the first suitable glyph row, since all
17837 the empty rows after that also have their position set to ZV. */
17838 /* FIXME: Revisit this when glyph ``spilling'' in continuation
17839 lines' rows is implemented for bidi-reordered rows. */
17841 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
17842 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17843 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17844 && cursor_row_p (it
->w
, row
))
17845 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17847 /* Highlight trailing whitespace. */
17848 if (!NILP (Vshow_trailing_whitespace
))
17849 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17851 /* Prepare for the next line. This line starts horizontally at (X
17852 HPOS) = (0 0). Vertical positions are incremented. As a
17853 convenience for the caller, IT->glyph_row is set to the next
17855 it
->current_x
= it
->hpos
= 0;
17856 it
->current_y
+= row
->height
;
17859 /* The next row should use same value of the reversed_p flag as this
17860 one. set_iterator_to_next decides when it's a new paragraph and
17861 recomputes the value of the flag accordingly. */
17862 it
->glyph_row
->reversed_p
= row
->reversed_p
;
17863 it
->start
= row_end
;
17864 return row
->displays_text_p
;
17869 /***********************************************************************
17871 ***********************************************************************/
17873 /* Redisplay the menu bar in the frame for window W.
17875 The menu bar of X frames that don't have X toolkit support is
17876 displayed in a special window W->frame->menu_bar_window.
17878 The menu bar of terminal frames is treated specially as far as
17879 glyph matrices are concerned. Menu bar lines are not part of
17880 windows, so the update is done directly on the frame matrix rows
17881 for the menu bar. */
17884 display_menu_bar (w
)
17887 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17892 /* Don't do all this for graphical frames. */
17894 if (FRAME_W32_P (f
))
17897 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17903 if (FRAME_NS_P (f
))
17905 #endif /* HAVE_NS */
17907 #ifdef USE_X_TOOLKIT
17908 xassert (!FRAME_WINDOW_P (f
));
17909 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17910 it
.first_visible_x
= 0;
17911 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17912 #else /* not USE_X_TOOLKIT */
17913 if (FRAME_WINDOW_P (f
))
17915 /* Menu bar lines are displayed in the desired matrix of the
17916 dummy window menu_bar_window. */
17917 struct window
*menu_w
;
17918 xassert (WINDOWP (f
->menu_bar_window
));
17919 menu_w
= XWINDOW (f
->menu_bar_window
);
17920 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17922 it
.first_visible_x
= 0;
17923 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17927 /* This is a TTY frame, i.e. character hpos/vpos are used as
17929 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17931 it
.first_visible_x
= 0;
17932 it
.last_visible_x
= FRAME_COLS (f
);
17934 #endif /* not USE_X_TOOLKIT */
17936 if (! mode_line_inverse_video
)
17937 /* Force the menu-bar to be displayed in the default face. */
17938 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17940 /* Clear all rows of the menu bar. */
17941 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17943 struct glyph_row
*row
= it
.glyph_row
+ i
;
17944 clear_glyph_row (row
);
17945 row
->enabled_p
= 1;
17946 row
->full_width_p
= 1;
17949 /* Display all items of the menu bar. */
17950 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17951 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17953 Lisp_Object string
;
17955 /* Stop at nil string. */
17956 string
= AREF (items
, i
+ 1);
17960 /* Remember where item was displayed. */
17961 ASET (items
, i
+ 3, make_number (it
.hpos
));
17963 /* Display the item, pad with one space. */
17964 if (it
.current_x
< it
.last_visible_x
)
17965 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17966 SCHARS (string
) + 1, 0, 0, -1);
17969 /* Fill out the line with spaces. */
17970 if (it
.current_x
< it
.last_visible_x
)
17971 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17973 /* Compute the total height of the lines. */
17974 compute_line_metrics (&it
);
17979 /***********************************************************************
17981 ***********************************************************************/
17983 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17984 FORCE is non-zero, redisplay mode lines unconditionally.
17985 Otherwise, redisplay only mode lines that are garbaged. Value is
17986 the number of windows whose mode lines were redisplayed. */
17989 redisplay_mode_lines (window
, force
)
17990 Lisp_Object window
;
17995 while (!NILP (window
))
17997 struct window
*w
= XWINDOW (window
);
17999 if (WINDOWP (w
->hchild
))
18000 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
18001 else if (WINDOWP (w
->vchild
))
18002 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
18004 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
18005 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
18007 struct text_pos lpoint
;
18008 struct buffer
*old
= current_buffer
;
18010 /* Set the window's buffer for the mode line display. */
18011 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
18012 set_buffer_internal_1 (XBUFFER (w
->buffer
));
18014 /* Point refers normally to the selected window. For any
18015 other window, set up appropriate value. */
18016 if (!EQ (window
, selected_window
))
18018 struct text_pos pt
;
18020 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
18021 if (CHARPOS (pt
) < BEGV
)
18022 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
18023 else if (CHARPOS (pt
) > (ZV
- 1))
18024 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
18026 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
18029 /* Display mode lines. */
18030 clear_glyph_matrix (w
->desired_matrix
);
18031 if (display_mode_lines (w
))
18034 w
->must_be_updated_p
= 1;
18037 /* Restore old settings. */
18038 set_buffer_internal_1 (old
);
18039 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
18049 /* Display the mode and/or header line of window W. Value is the
18050 sum number of mode lines and header lines displayed. */
18053 display_mode_lines (w
)
18056 Lisp_Object old_selected_window
, old_selected_frame
;
18059 old_selected_frame
= selected_frame
;
18060 selected_frame
= w
->frame
;
18061 old_selected_window
= selected_window
;
18062 XSETWINDOW (selected_window
, w
);
18064 /* These will be set while the mode line specs are processed. */
18065 line_number_displayed
= 0;
18066 w
->column_number_displayed
= Qnil
;
18068 if (WINDOW_WANTS_MODELINE_P (w
))
18070 struct window
*sel_w
= XWINDOW (old_selected_window
);
18072 /* Select mode line face based on the real selected window. */
18073 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
18074 current_buffer
->mode_line_format
);
18078 if (WINDOW_WANTS_HEADER_LINE_P (w
))
18080 display_mode_line (w
, HEADER_LINE_FACE_ID
,
18081 current_buffer
->header_line_format
);
18085 selected_frame
= old_selected_frame
;
18086 selected_window
= old_selected_window
;
18091 /* Display mode or header line of window W. FACE_ID specifies which
18092 line to display; it is either MODE_LINE_FACE_ID or
18093 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
18094 display. Value is the pixel height of the mode/header line
18098 display_mode_line (w
, face_id
, format
)
18100 enum face_id face_id
;
18101 Lisp_Object format
;
18105 int count
= SPECPDL_INDEX ();
18107 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18108 /* Don't extend on a previously drawn mode-line.
18109 This may happen if called from pos_visible_p. */
18110 it
.glyph_row
->enabled_p
= 0;
18111 prepare_desired_row (it
.glyph_row
);
18113 it
.glyph_row
->mode_line_p
= 1;
18115 if (! mode_line_inverse_video
)
18116 /* Force the mode-line to be displayed in the default face. */
18117 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
18119 record_unwind_protect (unwind_format_mode_line
,
18120 format_mode_line_unwind_data (NULL
, Qnil
, 0));
18122 mode_line_target
= MODE_LINE_DISPLAY
;
18124 /* Temporarily make frame's keyboard the current kboard so that
18125 kboard-local variables in the mode_line_format will get the right
18127 push_kboard (FRAME_KBOARD (it
.f
));
18128 record_unwind_save_match_data ();
18129 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18132 unbind_to (count
, Qnil
);
18134 /* Fill up with spaces. */
18135 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
18137 compute_line_metrics (&it
);
18138 it
.glyph_row
->full_width_p
= 1;
18139 it
.glyph_row
->continued_p
= 0;
18140 it
.glyph_row
->truncated_on_left_p
= 0;
18141 it
.glyph_row
->truncated_on_right_p
= 0;
18143 /* Make a 3D mode-line have a shadow at its right end. */
18144 face
= FACE_FROM_ID (it
.f
, face_id
);
18145 extend_face_to_end_of_line (&it
);
18146 if (face
->box
!= FACE_NO_BOX
)
18148 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
18149 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
18150 last
->right_box_line_p
= 1;
18153 return it
.glyph_row
->height
;
18156 /* Move element ELT in LIST to the front of LIST.
18157 Return the updated list. */
18160 move_elt_to_front (elt
, list
)
18161 Lisp_Object elt
, list
;
18163 register Lisp_Object tail
, prev
;
18164 register Lisp_Object tem
;
18168 while (CONSP (tail
))
18174 /* Splice out the link TAIL. */
18176 list
= XCDR (tail
);
18178 Fsetcdr (prev
, XCDR (tail
));
18180 /* Now make it the first. */
18181 Fsetcdr (tail
, list
);
18186 tail
= XCDR (tail
);
18190 /* Not found--return unchanged LIST. */
18194 /* Contribute ELT to the mode line for window IT->w. How it
18195 translates into text depends on its data type.
18197 IT describes the display environment in which we display, as usual.
18199 DEPTH is the depth in recursion. It is used to prevent
18200 infinite recursion here.
18202 FIELD_WIDTH is the number of characters the display of ELT should
18203 occupy in the mode line, and PRECISION is the maximum number of
18204 characters to display from ELT's representation. See
18205 display_string for details.
18207 Returns the hpos of the end of the text generated by ELT.
18209 PROPS is a property list to add to any string we encounter.
18211 If RISKY is nonzero, remove (disregard) any properties in any string
18212 we encounter, and ignore :eval and :propertize.
18214 The global variable `mode_line_target' determines whether the
18215 output is passed to `store_mode_line_noprop',
18216 `store_mode_line_string', or `display_string'. */
18219 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
18222 int field_width
, precision
;
18223 Lisp_Object elt
, props
;
18226 int n
= 0, field
, prec
;
18231 elt
= build_string ("*too-deep*");
18235 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
18239 /* A string: output it and check for %-constructs within it. */
18243 if (SCHARS (elt
) > 0
18244 && (!NILP (props
) || risky
))
18246 Lisp_Object oprops
, aelt
;
18247 oprops
= Ftext_properties_at (make_number (0), elt
);
18249 /* If the starting string's properties are not what
18250 we want, translate the string. Also, if the string
18251 is risky, do that anyway. */
18253 if (NILP (Fequal (props
, oprops
)) || risky
)
18255 /* If the starting string has properties,
18256 merge the specified ones onto the existing ones. */
18257 if (! NILP (oprops
) && !risky
)
18261 oprops
= Fcopy_sequence (oprops
);
18263 while (CONSP (tem
))
18265 oprops
= Fplist_put (oprops
, XCAR (tem
),
18266 XCAR (XCDR (tem
)));
18267 tem
= XCDR (XCDR (tem
));
18272 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
18273 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
18275 /* AELT is what we want. Move it to the front
18276 without consing. */
18278 mode_line_proptrans_alist
18279 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
18285 /* If AELT has the wrong props, it is useless.
18286 so get rid of it. */
18288 mode_line_proptrans_alist
18289 = Fdelq (aelt
, mode_line_proptrans_alist
);
18291 elt
= Fcopy_sequence (elt
);
18292 Fset_text_properties (make_number (0), Flength (elt
),
18294 /* Add this item to mode_line_proptrans_alist. */
18295 mode_line_proptrans_alist
18296 = Fcons (Fcons (elt
, props
),
18297 mode_line_proptrans_alist
);
18298 /* Truncate mode_line_proptrans_alist
18299 to at most 50 elements. */
18300 tem
= Fnthcdr (make_number (50),
18301 mode_line_proptrans_alist
);
18303 XSETCDR (tem
, Qnil
);
18312 prec
= precision
- n
;
18313 switch (mode_line_target
)
18315 case MODE_LINE_NOPROP
:
18316 case MODE_LINE_TITLE
:
18317 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
18319 case MODE_LINE_STRING
:
18320 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18322 case MODE_LINE_DISPLAY
:
18323 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18324 0, prec
, 0, STRING_MULTIBYTE (elt
));
18331 /* Handle the non-literal case. */
18333 while ((precision
<= 0 || n
< precision
)
18334 && SREF (elt
, offset
) != 0
18335 && (mode_line_target
!= MODE_LINE_DISPLAY
18336 || it
->current_x
< it
->last_visible_x
))
18338 int last_offset
= offset
;
18340 /* Advance to end of string or next format specifier. */
18341 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18344 if (offset
- 1 != last_offset
)
18346 int nchars
, nbytes
;
18348 /* Output to end of string or up to '%'. Field width
18349 is length of string. Don't output more than
18350 PRECISION allows us. */
18353 prec
= c_string_width (SDATA (elt
) + last_offset
,
18354 offset
- last_offset
, precision
- n
,
18357 switch (mode_line_target
)
18359 case MODE_LINE_NOPROP
:
18360 case MODE_LINE_TITLE
:
18361 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18363 case MODE_LINE_STRING
:
18365 int bytepos
= last_offset
;
18366 int charpos
= string_byte_to_char (elt
, bytepos
);
18367 int endpos
= (precision
<= 0
18368 ? string_byte_to_char (elt
, offset
)
18369 : charpos
+ nchars
);
18371 n
+= store_mode_line_string (NULL
,
18372 Fsubstring (elt
, make_number (charpos
),
18373 make_number (endpos
)),
18377 case MODE_LINE_DISPLAY
:
18379 int bytepos
= last_offset
;
18380 int charpos
= string_byte_to_char (elt
, bytepos
);
18382 if (precision
<= 0)
18383 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18384 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18386 STRING_MULTIBYTE (elt
));
18391 else /* c == '%' */
18393 int percent_position
= offset
;
18395 /* Get the specified minimum width. Zero means
18398 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18399 field
= field
* 10 + c
- '0';
18401 /* Don't pad beyond the total padding allowed. */
18402 if (field_width
- n
> 0 && field
> field_width
- n
)
18403 field
= field_width
- n
;
18405 /* Note that either PRECISION <= 0 or N < PRECISION. */
18406 prec
= precision
- n
;
18409 n
+= display_mode_element (it
, depth
, field
, prec
,
18410 Vglobal_mode_string
, props
,
18415 int bytepos
, charpos
;
18416 unsigned char *spec
;
18417 Lisp_Object string
;
18419 bytepos
= percent_position
;
18420 charpos
= (STRING_MULTIBYTE (elt
)
18421 ? string_byte_to_char (elt
, bytepos
)
18423 spec
= decode_mode_spec (it
->w
, c
, field
, prec
, &string
);
18424 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
18426 switch (mode_line_target
)
18428 case MODE_LINE_NOPROP
:
18429 case MODE_LINE_TITLE
:
18430 n
+= store_mode_line_noprop (spec
, field
, prec
);
18432 case MODE_LINE_STRING
:
18434 int len
= strlen (spec
);
18435 Lisp_Object tem
= make_string (spec
, len
);
18436 props
= Ftext_properties_at (make_number (charpos
), elt
);
18437 /* Should only keep face property in props */
18438 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18441 case MODE_LINE_DISPLAY
:
18443 int nglyphs_before
, nwritten
;
18445 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18446 nwritten
= display_string (spec
, string
, elt
,
18451 /* Assign to the glyphs written above the
18452 string where the `%x' came from, position
18456 struct glyph
*glyph
18457 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18461 for (i
= 0; i
< nwritten
; ++i
)
18463 glyph
[i
].object
= elt
;
18464 glyph
[i
].charpos
= charpos
;
18481 /* A symbol: process the value of the symbol recursively
18482 as if it appeared here directly. Avoid error if symbol void.
18483 Special case: if value of symbol is a string, output the string
18486 register Lisp_Object tem
;
18488 /* If the variable is not marked as risky to set
18489 then its contents are risky to use. */
18490 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18493 tem
= Fboundp (elt
);
18496 tem
= Fsymbol_value (elt
);
18497 /* If value is a string, output that string literally:
18498 don't check for % within it. */
18502 if (!EQ (tem
, elt
))
18504 /* Give up right away for nil or t. */
18514 register Lisp_Object car
, tem
;
18516 /* A cons cell: five distinct cases.
18517 If first element is :eval or :propertize, do something special.
18518 If first element is a string or a cons, process all the elements
18519 and effectively concatenate them.
18520 If first element is a negative number, truncate displaying cdr to
18521 at most that many characters. If positive, pad (with spaces)
18522 to at least that many characters.
18523 If first element is a symbol, process the cadr or caddr recursively
18524 according to whether the symbol's value is non-nil or nil. */
18526 if (EQ (car
, QCeval
))
18528 /* An element of the form (:eval FORM) means evaluate FORM
18529 and use the result as mode line elements. */
18534 if (CONSP (XCDR (elt
)))
18537 spec
= safe_eval (XCAR (XCDR (elt
)));
18538 n
+= display_mode_element (it
, depth
, field_width
- n
,
18539 precision
- n
, spec
, props
,
18543 else if (EQ (car
, QCpropertize
))
18545 /* An element of the form (:propertize ELT PROPS...)
18546 means display ELT but applying properties PROPS. */
18551 if (CONSP (XCDR (elt
)))
18552 n
+= display_mode_element (it
, depth
, field_width
- n
,
18553 precision
- n
, XCAR (XCDR (elt
)),
18554 XCDR (XCDR (elt
)), risky
);
18556 else if (SYMBOLP (car
))
18558 tem
= Fboundp (car
);
18562 /* elt is now the cdr, and we know it is a cons cell.
18563 Use its car if CAR has a non-nil value. */
18566 tem
= Fsymbol_value (car
);
18573 /* Symbol's value is nil (or symbol is unbound)
18574 Get the cddr of the original list
18575 and if possible find the caddr and use that. */
18579 else if (!CONSP (elt
))
18584 else if (INTEGERP (car
))
18586 register int lim
= XINT (car
);
18590 /* Negative int means reduce maximum width. */
18591 if (precision
<= 0)
18594 precision
= min (precision
, -lim
);
18598 /* Padding specified. Don't let it be more than
18599 current maximum. */
18601 lim
= min (precision
, lim
);
18603 /* If that's more padding than already wanted, queue it.
18604 But don't reduce padding already specified even if
18605 that is beyond the current truncation point. */
18606 field_width
= max (lim
, field_width
);
18610 else if (STRINGP (car
) || CONSP (car
))
18612 Lisp_Object halftail
= elt
;
18616 && (precision
<= 0 || n
< precision
))
18618 n
+= display_mode_element (it
, depth
,
18619 /* Do padding only after the last
18620 element in the list. */
18621 (! CONSP (XCDR (elt
))
18624 precision
- n
, XCAR (elt
),
18628 if ((len
& 1) == 0)
18629 halftail
= XCDR (halftail
);
18630 /* Check for cycle. */
18631 if (EQ (halftail
, elt
))
18640 elt
= build_string ("*invalid*");
18644 /* Pad to FIELD_WIDTH. */
18645 if (field_width
> 0 && n
< field_width
)
18647 switch (mode_line_target
)
18649 case MODE_LINE_NOPROP
:
18650 case MODE_LINE_TITLE
:
18651 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18653 case MODE_LINE_STRING
:
18654 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18656 case MODE_LINE_DISPLAY
:
18657 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18666 /* Store a mode-line string element in mode_line_string_list.
18668 If STRING is non-null, display that C string. Otherwise, the Lisp
18669 string LISP_STRING is displayed.
18671 FIELD_WIDTH is the minimum number of output glyphs to produce.
18672 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18673 with spaces. FIELD_WIDTH <= 0 means don't pad.
18675 PRECISION is the maximum number of characters to output from
18676 STRING. PRECISION <= 0 means don't truncate the string.
18678 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18679 properties to the string.
18681 PROPS are the properties to add to the string.
18682 The mode_line_string_face face property is always added to the string.
18686 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
18688 Lisp_Object lisp_string
;
18697 if (string
!= NULL
)
18699 len
= strlen (string
);
18700 if (precision
> 0 && len
> precision
)
18702 lisp_string
= make_string (string
, len
);
18704 props
= mode_line_string_face_prop
;
18705 else if (!NILP (mode_line_string_face
))
18707 Lisp_Object face
= Fplist_get (props
, Qface
);
18708 props
= Fcopy_sequence (props
);
18710 face
= mode_line_string_face
;
18712 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18713 props
= Fplist_put (props
, Qface
, face
);
18715 Fadd_text_properties (make_number (0), make_number (len
),
18716 props
, lisp_string
);
18720 len
= XFASTINT (Flength (lisp_string
));
18721 if (precision
> 0 && len
> precision
)
18724 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
18727 if (!NILP (mode_line_string_face
))
18731 props
= Ftext_properties_at (make_number (0), lisp_string
);
18732 face
= Fplist_get (props
, Qface
);
18734 face
= mode_line_string_face
;
18736 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18737 props
= Fcons (Qface
, Fcons (face
, Qnil
));
18739 lisp_string
= Fcopy_sequence (lisp_string
);
18742 Fadd_text_properties (make_number (0), make_number (len
),
18743 props
, lisp_string
);
18748 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18752 if (field_width
> len
)
18754 field_width
-= len
;
18755 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
18757 Fadd_text_properties (make_number (0), make_number (field_width
),
18758 props
, lisp_string
);
18759 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18767 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
18769 doc
: /* Format a string out of a mode line format specification.
18770 First arg FORMAT specifies the mode line format (see `mode-line-format'
18771 for details) to use.
18773 Optional second arg FACE specifies the face property to put
18774 on all characters for which no face is specified.
18775 The value t means whatever face the window's mode line currently uses
18776 \(either `mode-line' or `mode-line-inactive', depending).
18777 A value of nil means the default is no face property.
18778 If FACE is an integer, the value string has no text properties.
18780 Optional third and fourth args WINDOW and BUFFER specify the window
18781 and buffer to use as the context for the formatting (defaults
18782 are the selected window and the window's buffer). */)
18783 (format
, face
, window
, buffer
)
18784 Lisp_Object format
, face
, window
, buffer
;
18789 struct buffer
*old_buffer
= NULL
;
18791 int no_props
= INTEGERP (face
);
18792 int count
= SPECPDL_INDEX ();
18794 int string_start
= 0;
18797 window
= selected_window
;
18798 CHECK_WINDOW (window
);
18799 w
= XWINDOW (window
);
18802 buffer
= w
->buffer
;
18803 CHECK_BUFFER (buffer
);
18805 /* Make formatting the modeline a non-op when noninteractive, otherwise
18806 there will be problems later caused by a partially initialized frame. */
18807 if (NILP (format
) || noninteractive
)
18808 return empty_unibyte_string
;
18816 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
18817 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
18821 face_id
= DEFAULT_FACE_ID
;
18823 if (XBUFFER (buffer
) != current_buffer
)
18824 old_buffer
= current_buffer
;
18826 /* Save things including mode_line_proptrans_alist,
18827 and set that to nil so that we don't alter the outer value. */
18828 record_unwind_protect (unwind_format_mode_line
,
18829 format_mode_line_unwind_data
18830 (old_buffer
, selected_window
, 1));
18831 mode_line_proptrans_alist
= Qnil
;
18833 Fselect_window (window
, Qt
);
18835 set_buffer_internal_1 (XBUFFER (buffer
));
18837 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18841 mode_line_target
= MODE_LINE_NOPROP
;
18842 mode_line_string_face_prop
= Qnil
;
18843 mode_line_string_list
= Qnil
;
18844 string_start
= MODE_LINE_NOPROP_LEN (0);
18848 mode_line_target
= MODE_LINE_STRING
;
18849 mode_line_string_list
= Qnil
;
18850 mode_line_string_face
= face
;
18851 mode_line_string_face_prop
18852 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18855 push_kboard (FRAME_KBOARD (it
.f
));
18856 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18861 len
= MODE_LINE_NOPROP_LEN (string_start
);
18862 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18866 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18867 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18868 empty_unibyte_string
);
18871 unbind_to (count
, Qnil
);
18875 /* Write a null-terminated, right justified decimal representation of
18876 the positive integer D to BUF using a minimal field width WIDTH. */
18879 pint2str (buf
, width
, d
)
18880 register char *buf
;
18881 register int width
;
18884 register char *p
= buf
;
18892 *p
++ = d
% 10 + '0';
18897 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18908 /* Write a null-terminated, right justified decimal and "human
18909 readable" representation of the nonnegative integer D to BUF using
18910 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18912 static const char power_letter
[] =
18926 pint2hrstr (buf
, width
, d
)
18931 /* We aim to represent the nonnegative integer D as
18932 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18935 /* -1 means: do not use TENTHS. */
18939 /* Length of QUOTIENT.TENTHS as a string. */
18945 if (1000 <= quotient
)
18947 /* Scale to the appropriate EXPONENT. */
18950 remainder
= quotient
% 1000;
18954 while (1000 <= quotient
);
18956 /* Round to nearest and decide whether to use TENTHS or not. */
18959 tenths
= remainder
/ 100;
18960 if (50 <= remainder
% 100)
18967 if (quotient
== 10)
18975 if (500 <= remainder
)
18977 if (quotient
< 999)
18988 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18989 if (tenths
== -1 && quotient
<= 99)
18996 p
= psuffix
= buf
+ max (width
, length
);
18998 /* Print EXPONENT. */
19000 *psuffix
++ = power_letter
[exponent
];
19003 /* Print TENTHS. */
19006 *--p
= '0' + tenths
;
19010 /* Print QUOTIENT. */
19013 int digit
= quotient
% 10;
19014 *--p
= '0' + digit
;
19016 while ((quotient
/= 10) != 0);
19018 /* Print leading spaces. */
19023 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
19024 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
19025 type of CODING_SYSTEM. Return updated pointer into BUF. */
19027 static unsigned char invalid_eol_type
[] = "(*invalid*)";
19030 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
19031 Lisp_Object coding_system
;
19032 register char *buf
;
19036 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
19037 const unsigned char *eol_str
;
19039 /* The EOL conversion we are using. */
19040 Lisp_Object eoltype
;
19042 val
= CODING_SYSTEM_SPEC (coding_system
);
19045 if (!VECTORP (val
)) /* Not yet decided. */
19050 eoltype
= eol_mnemonic_undecided
;
19051 /* Don't mention EOL conversion if it isn't decided. */
19056 Lisp_Object eolvalue
;
19058 attrs
= AREF (val
, 0);
19059 eolvalue
= AREF (val
, 2);
19062 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
19066 /* The EOL conversion that is normal on this system. */
19068 if (NILP (eolvalue
)) /* Not yet decided. */
19069 eoltype
= eol_mnemonic_undecided
;
19070 else if (VECTORP (eolvalue
)) /* Not yet decided. */
19071 eoltype
= eol_mnemonic_undecided
;
19072 else /* eolvalue is Qunix, Qdos, or Qmac. */
19073 eoltype
= (EQ (eolvalue
, Qunix
)
19074 ? eol_mnemonic_unix
19075 : (EQ (eolvalue
, Qdos
) == 1
19076 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
19082 /* Mention the EOL conversion if it is not the usual one. */
19083 if (STRINGP (eoltype
))
19085 eol_str
= SDATA (eoltype
);
19086 eol_str_len
= SBYTES (eoltype
);
19088 else if (CHARACTERP (eoltype
))
19090 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
19091 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
19096 eol_str
= invalid_eol_type
;
19097 eol_str_len
= sizeof (invalid_eol_type
) - 1;
19099 bcopy (eol_str
, buf
, eol_str_len
);
19100 buf
+= eol_str_len
;
19106 /* Return a string for the output of a mode line %-spec for window W,
19107 generated by character C. PRECISION >= 0 means don't return a
19108 string longer than that value. FIELD_WIDTH > 0 means pad the
19109 string returned with spaces to that value. Return a Lisp string in
19110 *STRING if the resulting string is taken from that Lisp string.
19112 Note we operate on the current buffer for most purposes,
19113 the exception being w->base_line_pos. */
19115 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
19118 decode_mode_spec (w
, c
, field_width
, precision
, string
)
19121 int field_width
, precision
;
19122 Lisp_Object
*string
;
19125 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19126 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
19127 struct buffer
*b
= current_buffer
;
19135 if (!NILP (b
->read_only
))
19137 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19142 /* This differs from %* only for a modified read-only buffer. */
19143 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19145 if (!NILP (b
->read_only
))
19150 /* This differs from %* in ignoring read-only-ness. */
19151 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
19163 if (command_loop_level
> 5)
19165 p
= decode_mode_spec_buf
;
19166 for (i
= 0; i
< command_loop_level
; i
++)
19169 return decode_mode_spec_buf
;
19177 if (command_loop_level
> 5)
19179 p
= decode_mode_spec_buf
;
19180 for (i
= 0; i
< command_loop_level
; i
++)
19183 return decode_mode_spec_buf
;
19190 /* Let lots_of_dashes be a string of infinite length. */
19191 if (mode_line_target
== MODE_LINE_NOPROP
||
19192 mode_line_target
== MODE_LINE_STRING
)
19194 if (field_width
<= 0
19195 || field_width
> sizeof (lots_of_dashes
))
19197 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
19198 decode_mode_spec_buf
[i
] = '-';
19199 decode_mode_spec_buf
[i
] = '\0';
19200 return decode_mode_spec_buf
;
19203 return lots_of_dashes
;
19211 /* %c and %l are ignored in `frame-title-format'.
19212 (In redisplay_internal, the frame title is drawn _before_ the
19213 windows are updated, so the stuff which depends on actual
19214 window contents (such as %l) may fail to render properly, or
19215 even crash emacs.) */
19216 if (mode_line_target
== MODE_LINE_TITLE
)
19220 int col
= (int) current_column (); /* iftc */
19221 w
->column_number_displayed
= make_number (col
);
19222 pint2str (decode_mode_spec_buf
, field_width
, col
);
19223 return decode_mode_spec_buf
;
19227 #ifndef SYSTEM_MALLOC
19229 if (NILP (Vmemory_full
))
19232 return "!MEM FULL! ";
19239 /* %F displays the frame name. */
19240 if (!NILP (f
->title
))
19241 return (char *) SDATA (f
->title
);
19242 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
19243 return (char *) SDATA (f
->name
);
19252 int size
= ZV
- BEGV
;
19253 pint2str (decode_mode_spec_buf
, field_width
, size
);
19254 return decode_mode_spec_buf
;
19259 int size
= ZV
- BEGV
;
19260 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
19261 return decode_mode_spec_buf
;
19266 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
19267 int topline
, nlines
, junk
, height
;
19269 /* %c and %l are ignored in `frame-title-format'. */
19270 if (mode_line_target
== MODE_LINE_TITLE
)
19273 startpos
= XMARKER (w
->start
)->charpos
;
19274 startpos_byte
= marker_byte_position (w
->start
);
19275 height
= WINDOW_TOTAL_LINES (w
);
19277 /* If we decided that this buffer isn't suitable for line numbers,
19278 don't forget that too fast. */
19279 if (EQ (w
->base_line_pos
, w
->buffer
))
19281 /* But do forget it, if the window shows a different buffer now. */
19282 else if (BUFFERP (w
->base_line_pos
))
19283 w
->base_line_pos
= Qnil
;
19285 /* If the buffer is very big, don't waste time. */
19286 if (INTEGERP (Vline_number_display_limit
)
19287 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
19289 w
->base_line_pos
= Qnil
;
19290 w
->base_line_number
= Qnil
;
19294 if (INTEGERP (w
->base_line_number
)
19295 && INTEGERP (w
->base_line_pos
)
19296 && XFASTINT (w
->base_line_pos
) <= startpos
)
19298 line
= XFASTINT (w
->base_line_number
);
19299 linepos
= XFASTINT (w
->base_line_pos
);
19300 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
19305 linepos
= BUF_BEGV (b
);
19306 linepos_byte
= BUF_BEGV_BYTE (b
);
19309 /* Count lines from base line to window start position. */
19310 nlines
= display_count_lines (linepos
, linepos_byte
,
19314 topline
= nlines
+ line
;
19316 /* Determine a new base line, if the old one is too close
19317 or too far away, or if we did not have one.
19318 "Too close" means it's plausible a scroll-down would
19319 go back past it. */
19320 if (startpos
== BUF_BEGV (b
))
19322 w
->base_line_number
= make_number (topline
);
19323 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19325 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19326 || linepos
== BUF_BEGV (b
))
19328 int limit
= BUF_BEGV (b
);
19329 int limit_byte
= BUF_BEGV_BYTE (b
);
19331 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
19333 if (startpos
- distance
> limit
)
19335 limit
= startpos
- distance
;
19336 limit_byte
= CHAR_TO_BYTE (limit
);
19339 nlines
= display_count_lines (startpos
, startpos_byte
,
19341 - (height
* 2 + 30),
19343 /* If we couldn't find the lines we wanted within
19344 line_number_display_limit_width chars per line,
19345 give up on line numbers for this window. */
19346 if (position
== limit_byte
&& limit
== startpos
- distance
)
19348 w
->base_line_pos
= w
->buffer
;
19349 w
->base_line_number
= Qnil
;
19353 w
->base_line_number
= make_number (topline
- nlines
);
19354 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19357 /* Now count lines from the start pos to point. */
19358 nlines
= display_count_lines (startpos
, startpos_byte
,
19359 PT_BYTE
, PT
, &junk
);
19361 /* Record that we did display the line number. */
19362 line_number_displayed
= 1;
19364 /* Make the string to show. */
19365 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19366 return decode_mode_spec_buf
;
19369 char* p
= decode_mode_spec_buf
;
19370 int pad
= field_width
- 2;
19376 return decode_mode_spec_buf
;
19382 obj
= b
->mode_name
;
19386 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19392 int pos
= marker_position (w
->start
);
19393 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19395 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19397 if (pos
<= BUF_BEGV (b
))
19402 else if (pos
<= BUF_BEGV (b
))
19406 if (total
> 1000000)
19407 /* Do it differently for a large value, to avoid overflow. */
19408 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19410 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19411 /* We can't normally display a 3-digit number,
19412 so get us a 2-digit number that is close. */
19415 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19416 return decode_mode_spec_buf
;
19420 /* Display percentage of size above the bottom of the screen. */
19423 int toppos
= marker_position (w
->start
);
19424 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19425 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19427 if (botpos
>= BUF_ZV (b
))
19429 if (toppos
<= BUF_BEGV (b
))
19436 if (total
> 1000000)
19437 /* Do it differently for a large value, to avoid overflow. */
19438 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19440 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19441 /* We can't normally display a 3-digit number,
19442 so get us a 2-digit number that is close. */
19445 if (toppos
<= BUF_BEGV (b
))
19446 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
19448 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19449 return decode_mode_spec_buf
;
19454 /* status of process */
19455 obj
= Fget_buffer_process (Fcurrent_buffer ());
19457 return "no process";
19458 #ifdef subprocesses
19459 obj
= Fsymbol_name (Fprocess_status (obj
));
19465 int count
= inhibit_garbage_collection ();
19466 Lisp_Object val
= call1 (intern ("file-remote-p"),
19467 current_buffer
->directory
);
19468 unbind_to (count
, Qnil
);
19476 case 't': /* indicate TEXT or BINARY */
19477 #ifdef MODE_LINE_BINARY_TEXT
19478 return MODE_LINE_BINARY_TEXT (b
);
19484 /* coding-system (not including end-of-line format) */
19486 /* coding-system (including end-of-line type) */
19488 int eol_flag
= (c
== 'Z');
19489 char *p
= decode_mode_spec_buf
;
19491 if (! FRAME_WINDOW_P (f
))
19493 /* No need to mention EOL here--the terminal never needs
19494 to do EOL conversion. */
19495 p
= decode_mode_spec_coding (CODING_ID_NAME
19496 (FRAME_KEYBOARD_CODING (f
)->id
),
19498 p
= decode_mode_spec_coding (CODING_ID_NAME
19499 (FRAME_TERMINAL_CODING (f
)->id
),
19502 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19505 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19506 #ifdef subprocesses
19507 obj
= Fget_buffer_process (Fcurrent_buffer ());
19508 if (PROCESSP (obj
))
19510 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19512 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19515 #endif /* subprocesses */
19518 return decode_mode_spec_buf
;
19525 return (char *) SDATA (obj
);
19532 /* Count up to COUNT lines starting from START / START_BYTE.
19533 But don't go beyond LIMIT_BYTE.
19534 Return the number of lines thus found (always nonnegative).
19536 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19539 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
19540 int start
, start_byte
, limit_byte
, count
;
19543 register unsigned char *cursor
;
19544 unsigned char *base
;
19546 register int ceiling
;
19547 register unsigned char *ceiling_addr
;
19548 int orig_count
= count
;
19550 /* If we are not in selective display mode,
19551 check only for newlines. */
19552 int selective_display
= (!NILP (current_buffer
->selective_display
)
19553 && !INTEGERP (current_buffer
->selective_display
));
19557 while (start_byte
< limit_byte
)
19559 ceiling
= BUFFER_CEILING_OF (start_byte
);
19560 ceiling
= min (limit_byte
- 1, ceiling
);
19561 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19562 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19565 if (selective_display
)
19566 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19569 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19572 if (cursor
!= ceiling_addr
)
19576 start_byte
+= cursor
- base
+ 1;
19577 *byte_pos_ptr
= start_byte
;
19581 if (++cursor
== ceiling_addr
)
19587 start_byte
+= cursor
- base
;
19592 while (start_byte
> limit_byte
)
19594 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19595 ceiling
= max (limit_byte
, ceiling
);
19596 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19597 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19600 if (selective_display
)
19601 while (--cursor
!= ceiling_addr
19602 && *cursor
!= '\n' && *cursor
!= 015)
19605 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19608 if (cursor
!= ceiling_addr
)
19612 start_byte
+= cursor
- base
+ 1;
19613 *byte_pos_ptr
= start_byte
;
19614 /* When scanning backwards, we should
19615 not count the newline posterior to which we stop. */
19616 return - orig_count
- 1;
19622 /* Here we add 1 to compensate for the last decrement
19623 of CURSOR, which took it past the valid range. */
19624 start_byte
+= cursor
- base
+ 1;
19628 *byte_pos_ptr
= limit_byte
;
19631 return - orig_count
+ count
;
19632 return orig_count
- count
;
19638 /***********************************************************************
19640 ***********************************************************************/
19642 /* Display a NUL-terminated string, starting with index START.
19644 If STRING is non-null, display that C string. Otherwise, the Lisp
19645 string LISP_STRING is displayed. There's a case that STRING is
19646 non-null and LISP_STRING is not nil. It means STRING is a string
19647 data of LISP_STRING. In that case, we display LISP_STRING while
19648 ignoring its text properties.
19650 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19651 FACE_STRING. Display STRING or LISP_STRING with the face at
19652 FACE_STRING_POS in FACE_STRING:
19654 Display the string in the environment given by IT, but use the
19655 standard display table, temporarily.
19657 FIELD_WIDTH is the minimum number of output glyphs to produce.
19658 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19659 with spaces. If STRING has more characters, more than FIELD_WIDTH
19660 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19662 PRECISION is the maximum number of characters to output from
19663 STRING. PRECISION < 0 means don't truncate the string.
19665 This is roughly equivalent to printf format specifiers:
19667 FIELD_WIDTH PRECISION PRINTF
19668 ----------------------------------------
19674 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19675 display them, and < 0 means obey the current buffer's value of
19676 enable_multibyte_characters.
19678 Value is the number of columns displayed. */
19681 display_string (string
, lisp_string
, face_string
, face_string_pos
,
19682 start
, it
, field_width
, precision
, max_x
, multibyte
)
19683 unsigned char *string
;
19684 Lisp_Object lisp_string
;
19685 Lisp_Object face_string
;
19686 EMACS_INT face_string_pos
;
19689 int field_width
, precision
, max_x
;
19692 int hpos_at_start
= it
->hpos
;
19693 int saved_face_id
= it
->face_id
;
19694 struct glyph_row
*row
= it
->glyph_row
;
19696 /* Initialize the iterator IT for iteration over STRING beginning
19697 with index START. */
19698 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
19699 precision
, field_width
, multibyte
);
19700 if (string
&& STRINGP (lisp_string
))
19701 /* LISP_STRING is the one returned by decode_mode_spec. We should
19702 ignore its text properties. */
19703 it
->stop_charpos
= -1;
19705 /* If displaying STRING, set up the face of the iterator
19706 from LISP_STRING, if that's given. */
19707 if (STRINGP (face_string
))
19713 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19714 0, it
->region_beg_charpos
,
19715 it
->region_end_charpos
,
19716 &endptr
, it
->base_face_id
, 0);
19717 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19718 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19721 /* Set max_x to the maximum allowed X position. Don't let it go
19722 beyond the right edge of the window. */
19724 max_x
= it
->last_visible_x
;
19726 max_x
= min (max_x
, it
->last_visible_x
);
19728 /* Skip over display elements that are not visible. because IT->w is
19730 if (it
->current_x
< it
->first_visible_x
)
19731 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
19732 MOVE_TO_POS
| MOVE_TO_X
);
19734 row
->ascent
= it
->max_ascent
;
19735 row
->height
= it
->max_ascent
+ it
->max_descent
;
19736 row
->phys_ascent
= it
->max_phys_ascent
;
19737 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19738 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19740 /* This condition is for the case that we are called with current_x
19741 past last_visible_x. */
19742 while (it
->current_x
< max_x
)
19744 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
19746 /* Get the next display element. */
19747 if (!get_next_display_element (it
))
19750 /* Produce glyphs. */
19751 x_before
= it
->current_x
;
19752 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19753 PRODUCE_GLYPHS (it
);
19755 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
19758 while (i
< nglyphs
)
19760 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19762 if (it
->line_wrap
!= TRUNCATE
19763 && x
+ glyph
->pixel_width
> max_x
)
19765 /* End of continued line or max_x reached. */
19766 if (CHAR_GLYPH_PADDING_P (*glyph
))
19768 /* A wide character is unbreakable. */
19769 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19770 it
->current_x
= x_before
;
19774 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19779 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
19781 /* Glyph is at least partially visible. */
19783 if (x
< it
->first_visible_x
)
19784 it
->glyph_row
->x
= x
- it
->first_visible_x
;
19788 /* Glyph is off the left margin of the display area.
19789 Should not happen. */
19793 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19794 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19795 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19796 row
->phys_height
= max (row
->phys_height
,
19797 it
->max_phys_ascent
+ it
->max_phys_descent
);
19798 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19799 it
->max_extra_line_spacing
);
19800 x
+= glyph
->pixel_width
;
19804 /* Stop if max_x reached. */
19808 /* Stop at line ends. */
19809 if (ITERATOR_AT_END_OF_LINE_P (it
))
19811 it
->continuation_lines_width
= 0;
19815 set_iterator_to_next (it
, 1);
19817 /* Stop if truncating at the right edge. */
19818 if (it
->line_wrap
== TRUNCATE
19819 && it
->current_x
>= it
->last_visible_x
)
19821 /* Add truncation mark, but don't do it if the line is
19822 truncated at a padding space. */
19823 if (IT_CHARPOS (*it
) < it
->string_nchars
)
19825 if (!FRAME_WINDOW_P (it
->f
))
19829 if (it
->current_x
> it
->last_visible_x
)
19831 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19832 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19834 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19836 row
->used
[TEXT_AREA
] = i
;
19837 produce_special_glyphs (it
, IT_TRUNCATION
);
19840 produce_special_glyphs (it
, IT_TRUNCATION
);
19842 it
->glyph_row
->truncated_on_right_p
= 1;
19848 /* Maybe insert a truncation at the left. */
19849 if (it
->first_visible_x
19850 && IT_CHARPOS (*it
) > 0)
19852 if (!FRAME_WINDOW_P (it
->f
))
19853 insert_left_trunc_glyphs (it
);
19854 it
->glyph_row
->truncated_on_left_p
= 1;
19857 it
->face_id
= saved_face_id
;
19859 /* Value is number of columns displayed. */
19860 return it
->hpos
- hpos_at_start
;
19865 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19866 appears as an element of LIST or as the car of an element of LIST.
19867 If PROPVAL is a list, compare each element against LIST in that
19868 way, and return 1/2 if any element of PROPVAL is found in LIST.
19869 Otherwise return 0. This function cannot quit.
19870 The return value is 2 if the text is invisible but with an ellipsis
19871 and 1 if it's invisible and without an ellipsis. */
19874 invisible_p (propval
, list
)
19875 register Lisp_Object propval
;
19878 register Lisp_Object tail
, proptail
;
19880 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19882 register Lisp_Object tem
;
19884 if (EQ (propval
, tem
))
19886 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19887 return NILP (XCDR (tem
)) ? 1 : 2;
19890 if (CONSP (propval
))
19892 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19894 Lisp_Object propelt
;
19895 propelt
= XCAR (proptail
);
19896 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19898 register Lisp_Object tem
;
19900 if (EQ (propelt
, tem
))
19902 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19903 return NILP (XCDR (tem
)) ? 1 : 2;
19911 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19912 doc
: /* Non-nil if the property makes the text invisible.
19913 POS-OR-PROP can be a marker or number, in which case it is taken to be
19914 a position in the current buffer and the value of the `invisible' property
19915 is checked; or it can be some other value, which is then presumed to be the
19916 value of the `invisible' property of the text of interest.
19917 The non-nil value returned can be t for truly invisible text or something
19918 else if the text is replaced by an ellipsis. */)
19920 Lisp_Object pos_or_prop
;
19923 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19924 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19926 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19927 return (invis
== 0 ? Qnil
19929 : make_number (invis
));
19932 /* Calculate a width or height in pixels from a specification using
19933 the following elements:
19936 NUM - a (fractional) multiple of the default font width/height
19937 (NUM) - specifies exactly NUM pixels
19938 UNIT - a fixed number of pixels, see below.
19939 ELEMENT - size of a display element in pixels, see below.
19940 (NUM . SPEC) - equals NUM * SPEC
19941 (+ SPEC SPEC ...) - add pixel values
19942 (- SPEC SPEC ...) - subtract pixel values
19943 (- SPEC) - negate pixel value
19946 INT or FLOAT - a number constant
19947 SYMBOL - use symbol's (buffer local) variable binding.
19950 in - pixels per inch *)
19951 mm - pixels per 1/1000 meter *)
19952 cm - pixels per 1/100 meter *)
19953 width - width of current font in pixels.
19954 height - height of current font in pixels.
19956 *) using the ratio(s) defined in display-pixels-per-inch.
19960 left-fringe - left fringe width in pixels
19961 right-fringe - right fringe width in pixels
19963 left-margin - left margin width in pixels
19964 right-margin - right margin width in pixels
19966 scroll-bar - scroll-bar area width in pixels
19970 Pixels corresponding to 5 inches:
19973 Total width of non-text areas on left side of window (if scroll-bar is on left):
19974 '(space :width (+ left-fringe left-margin scroll-bar))
19976 Align to first text column (in header line):
19977 '(space :align-to 0)
19979 Align to middle of text area minus half the width of variable `my-image'
19980 containing a loaded image:
19981 '(space :align-to (0.5 . (- text my-image)))
19983 Width of left margin minus width of 1 character in the default font:
19984 '(space :width (- left-margin 1))
19986 Width of left margin minus width of 2 characters in the current font:
19987 '(space :width (- left-margin (2 . width)))
19989 Center 1 character over left-margin (in header line):
19990 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19992 Different ways to express width of left fringe plus left margin minus one pixel:
19993 '(space :width (- (+ left-fringe left-margin) (1)))
19994 '(space :width (+ left-fringe left-margin (- (1))))
19995 '(space :width (+ left-fringe left-margin (-1)))
19999 #define NUMVAL(X) \
20000 ((INTEGERP (X) || FLOATP (X)) \
20005 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
20010 int width_p
, *align_to
;
20014 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
20015 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
20018 return OK_PIXELS (0);
20020 xassert (FRAME_LIVE_P (it
->f
));
20022 if (SYMBOLP (prop
))
20024 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
20026 char *unit
= SDATA (SYMBOL_NAME (prop
));
20028 if (unit
[0] == 'i' && unit
[1] == 'n')
20030 else if (unit
[0] == 'm' && unit
[1] == 'm')
20032 else if (unit
[0] == 'c' && unit
[1] == 'm')
20039 #ifdef HAVE_WINDOW_SYSTEM
20040 if (FRAME_WINDOW_P (it
->f
)
20042 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
20043 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
20045 return OK_PIXELS (ppi
/ pixels
);
20048 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
20049 || (CONSP (Vdisplay_pixels_per_inch
)
20051 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
20052 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
20054 return OK_PIXELS (ppi
/ pixels
);
20060 #ifdef HAVE_WINDOW_SYSTEM
20061 if (EQ (prop
, Qheight
))
20062 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
20063 if (EQ (prop
, Qwidth
))
20064 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
20066 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
20067 return OK_PIXELS (1);
20070 if (EQ (prop
, Qtext
))
20071 return OK_PIXELS (width_p
20072 ? window_box_width (it
->w
, TEXT_AREA
)
20073 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
20075 if (align_to
&& *align_to
< 0)
20078 if (EQ (prop
, Qleft
))
20079 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
20080 if (EQ (prop
, Qright
))
20081 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
20082 if (EQ (prop
, Qcenter
))
20083 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
20084 + window_box_width (it
->w
, TEXT_AREA
) / 2);
20085 if (EQ (prop
, Qleft_fringe
))
20086 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20087 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
20088 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
20089 if (EQ (prop
, Qright_fringe
))
20090 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20091 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20092 : window_box_right_offset (it
->w
, TEXT_AREA
));
20093 if (EQ (prop
, Qleft_margin
))
20094 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
20095 if (EQ (prop
, Qright_margin
))
20096 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
20097 if (EQ (prop
, Qscroll_bar
))
20098 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
20100 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
20101 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
20102 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20107 if (EQ (prop
, Qleft_fringe
))
20108 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
20109 if (EQ (prop
, Qright_fringe
))
20110 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
20111 if (EQ (prop
, Qleft_margin
))
20112 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
20113 if (EQ (prop
, Qright_margin
))
20114 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
20115 if (EQ (prop
, Qscroll_bar
))
20116 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
20119 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
20122 if (INTEGERP (prop
) || FLOATP (prop
))
20124 int base_unit
= (width_p
20125 ? FRAME_COLUMN_WIDTH (it
->f
)
20126 : FRAME_LINE_HEIGHT (it
->f
));
20127 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
20132 Lisp_Object car
= XCAR (prop
);
20133 Lisp_Object cdr
= XCDR (prop
);
20137 #ifdef HAVE_WINDOW_SYSTEM
20138 if (FRAME_WINDOW_P (it
->f
)
20139 && valid_image_p (prop
))
20141 int id
= lookup_image (it
->f
, prop
);
20142 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
20144 return OK_PIXELS (width_p
? img
->width
: img
->height
);
20147 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
20153 while (CONSP (cdr
))
20155 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
20156 font
, width_p
, align_to
))
20159 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
20164 if (EQ (car
, Qminus
))
20166 return OK_PIXELS (pixels
);
20169 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
20172 if (INTEGERP (car
) || FLOATP (car
))
20175 pixels
= XFLOATINT (car
);
20177 return OK_PIXELS (pixels
);
20178 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
20179 font
, width_p
, align_to
))
20180 return OK_PIXELS (pixels
* fact
);
20191 /***********************************************************************
20193 ***********************************************************************/
20195 #ifdef HAVE_WINDOW_SYSTEM
20200 dump_glyph_string (s
)
20201 struct glyph_string
*s
;
20203 fprintf (stderr
, "glyph string\n");
20204 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
20205 s
->x
, s
->y
, s
->width
, s
->height
);
20206 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
20207 fprintf (stderr
, " hl = %d\n", s
->hl
);
20208 fprintf (stderr
, " left overhang = %d, right = %d\n",
20209 s
->left_overhang
, s
->right_overhang
);
20210 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
20211 fprintf (stderr
, " extends to end of line = %d\n",
20212 s
->extends_to_end_of_line_p
);
20213 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
20214 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
20217 #endif /* GLYPH_DEBUG */
20219 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
20220 of XChar2b structures for S; it can't be allocated in
20221 init_glyph_string because it must be allocated via `alloca'. W
20222 is the window on which S is drawn. ROW and AREA are the glyph row
20223 and area within the row from which S is constructed. START is the
20224 index of the first glyph structure covered by S. HL is a
20225 face-override for drawing S. */
20228 #define OPTIONAL_HDC(hdc) hdc,
20229 #define DECLARE_HDC(hdc) HDC hdc;
20230 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
20231 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
20234 #ifndef OPTIONAL_HDC
20235 #define OPTIONAL_HDC(hdc)
20236 #define DECLARE_HDC(hdc)
20237 #define ALLOCATE_HDC(hdc, f)
20238 #define RELEASE_HDC(hdc, f)
20242 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
20243 struct glyph_string
*s
;
20247 struct glyph_row
*row
;
20248 enum glyph_row_area area
;
20250 enum draw_glyphs_face hl
;
20252 bzero (s
, sizeof *s
);
20254 s
->f
= XFRAME (w
->frame
);
20258 s
->display
= FRAME_X_DISPLAY (s
->f
);
20259 s
->window
= FRAME_X_WINDOW (s
->f
);
20260 s
->char2b
= char2b
;
20264 s
->first_glyph
= row
->glyphs
[area
] + start
;
20265 s
->height
= row
->height
;
20266 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
20267 s
->ybase
= s
->y
+ row
->ascent
;
20271 /* Append the list of glyph strings with head H and tail T to the list
20272 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
20275 append_glyph_string_lists (head
, tail
, h
, t
)
20276 struct glyph_string
**head
, **tail
;
20277 struct glyph_string
*h
, *t
;
20291 /* Prepend the list of glyph strings with head H and tail T to the
20292 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
20296 prepend_glyph_string_lists (head
, tail
, h
, t
)
20297 struct glyph_string
**head
, **tail
;
20298 struct glyph_string
*h
, *t
;
20312 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
20313 Set *HEAD and *TAIL to the resulting list. */
20316 append_glyph_string (head
, tail
, s
)
20317 struct glyph_string
**head
, **tail
;
20318 struct glyph_string
*s
;
20320 s
->next
= s
->prev
= NULL
;
20321 append_glyph_string_lists (head
, tail
, s
, s
);
20325 /* Get face and two-byte form of character C in face FACE_ID on frame
20326 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
20327 means we want to display multibyte text. DISPLAY_P non-zero means
20328 make sure that X resources for the face returned are allocated.
20329 Value is a pointer to a realized face that is ready for display if
20330 DISPLAY_P is non-zero. */
20332 static INLINE
struct face
*
20333 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
20337 int multibyte_p
, display_p
;
20339 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20343 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20345 if (code
!= FONT_INVALID_CODE
)
20346 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20348 STORE_XCHAR2B (char2b
, 0, 0);
20351 /* Make sure X resources of the face are allocated. */
20352 #ifdef HAVE_X_WINDOWS
20356 xassert (face
!= NULL
);
20357 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20364 /* Get face and two-byte form of character glyph GLYPH on frame F.
20365 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20366 a pointer to a realized face that is ready for display. */
20368 static INLINE
struct face
*
20369 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
20371 struct glyph
*glyph
;
20377 xassert (glyph
->type
== CHAR_GLYPH
);
20378 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20385 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20387 if (code
!= FONT_INVALID_CODE
)
20388 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20390 STORE_XCHAR2B (char2b
, 0, 0);
20393 /* Make sure X resources of the face are allocated. */
20394 xassert (face
!= NULL
);
20395 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20400 /* Fill glyph string S with composition components specified by S->cmp.
20402 BASE_FACE is the base face of the composition.
20403 S->cmp_from is the index of the first component for S.
20405 OVERLAPS non-zero means S should draw the foreground only, and use
20406 its physical height for clipping. See also draw_glyphs.
20408 Value is the index of a component not in S. */
20411 fill_composite_glyph_string (s
, base_face
, overlaps
)
20412 struct glyph_string
*s
;
20413 struct face
*base_face
;
20417 /* For all glyphs of this composition, starting at the offset
20418 S->cmp_from, until we reach the end of the definition or encounter a
20419 glyph that requires the different face, add it to S. */
20424 s
->for_overlaps
= overlaps
;
20427 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20429 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20433 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20436 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20437 s
->char2b
+ i
, 1, 1);
20443 s
->font
= s
->face
->font
;
20445 else if (s
->face
!= face
)
20453 /* All glyph strings for the same composition has the same width,
20454 i.e. the width set for the first component of the composition. */
20455 s
->width
= s
->first_glyph
->pixel_width
;
20457 /* If the specified font could not be loaded, use the frame's
20458 default font, but record the fact that we couldn't load it in
20459 the glyph string so that we can draw rectangles for the
20460 characters of the glyph string. */
20461 if (s
->font
== NULL
)
20463 s
->font_not_found_p
= 1;
20464 s
->font
= FRAME_FONT (s
->f
);
20467 /* Adjust base line for subscript/superscript text. */
20468 s
->ybase
+= s
->first_glyph
->voffset
;
20470 /* This glyph string must always be drawn with 16-bit functions. */
20477 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
20478 struct glyph_string
*s
;
20480 int start
, end
, overlaps
;
20482 struct glyph
*glyph
, *last
;
20483 Lisp_Object lgstring
;
20486 s
->for_overlaps
= overlaps
;
20487 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20488 last
= s
->row
->glyphs
[s
->area
] + end
;
20489 s
->cmp_id
= glyph
->u
.cmp
.id
;
20490 s
->cmp_from
= glyph
->u
.cmp
.from
;
20491 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
20492 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20493 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20494 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20496 while (glyph
< last
20497 && glyph
->u
.cmp
.automatic
20498 && glyph
->u
.cmp
.id
== s
->cmp_id
20499 && s
->cmp_to
== glyph
->u
.cmp
.from
)
20500 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
20502 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20504 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20505 unsigned code
= LGLYPH_CODE (lglyph
);
20507 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20509 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20510 return glyph
- s
->row
->glyphs
[s
->area
];
20514 /* Fill glyph string S from a sequence of character glyphs.
20516 FACE_ID is the face id of the string. START is the index of the
20517 first glyph to consider, END is the index of the last + 1.
20518 OVERLAPS non-zero means S should draw the foreground only, and use
20519 its physical height for clipping. See also draw_glyphs.
20521 Value is the index of the first glyph not in S. */
20524 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
20525 struct glyph_string
*s
;
20527 int start
, end
, overlaps
;
20529 struct glyph
*glyph
, *last
;
20531 int glyph_not_available_p
;
20533 xassert (s
->f
== XFRAME (s
->w
->frame
));
20534 xassert (s
->nchars
== 0);
20535 xassert (start
>= 0 && end
> start
);
20537 s
->for_overlaps
= overlaps
;
20538 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20539 last
= s
->row
->glyphs
[s
->area
] + end
;
20540 voffset
= glyph
->voffset
;
20541 s
->padding_p
= glyph
->padding_p
;
20542 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20544 while (glyph
< last
20545 && glyph
->type
== CHAR_GLYPH
20546 && glyph
->voffset
== voffset
20547 /* Same face id implies same font, nowadays. */
20548 && glyph
->face_id
== face_id
20549 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20553 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20554 s
->char2b
+ s
->nchars
,
20556 s
->two_byte_p
= two_byte_p
;
20558 xassert (s
->nchars
<= end
- start
);
20559 s
->width
+= glyph
->pixel_width
;
20560 if (glyph
++->padding_p
!= s
->padding_p
)
20564 s
->font
= s
->face
->font
;
20566 /* If the specified font could not be loaded, use the frame's font,
20567 but record the fact that we couldn't load it in
20568 S->font_not_found_p so that we can draw rectangles for the
20569 characters of the glyph string. */
20570 if (s
->font
== NULL
|| glyph_not_available_p
)
20572 s
->font_not_found_p
= 1;
20573 s
->font
= FRAME_FONT (s
->f
);
20576 /* Adjust base line for subscript/superscript text. */
20577 s
->ybase
+= voffset
;
20579 xassert (s
->face
&& s
->face
->gc
);
20580 return glyph
- s
->row
->glyphs
[s
->area
];
20584 /* Fill glyph string S from image glyph S->first_glyph. */
20587 fill_image_glyph_string (s
)
20588 struct glyph_string
*s
;
20590 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20591 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20593 s
->slice
= s
->first_glyph
->slice
;
20594 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20595 s
->font
= s
->face
->font
;
20596 s
->width
= s
->first_glyph
->pixel_width
;
20598 /* Adjust base line for subscript/superscript text. */
20599 s
->ybase
+= s
->first_glyph
->voffset
;
20603 /* Fill glyph string S from a sequence of stretch glyphs.
20605 ROW is the glyph row in which the glyphs are found, AREA is the
20606 area within the row. START is the index of the first glyph to
20607 consider, END is the index of the last + 1.
20609 Value is the index of the first glyph not in S. */
20612 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
20613 struct glyph_string
*s
;
20614 struct glyph_row
*row
;
20615 enum glyph_row_area area
;
20618 struct glyph
*glyph
, *last
;
20619 int voffset
, face_id
;
20621 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20623 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20624 last
= s
->row
->glyphs
[s
->area
] + end
;
20625 face_id
= glyph
->face_id
;
20626 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20627 s
->font
= s
->face
->font
;
20628 s
->width
= glyph
->pixel_width
;
20630 voffset
= glyph
->voffset
;
20634 && glyph
->type
== STRETCH_GLYPH
20635 && glyph
->voffset
== voffset
20636 && glyph
->face_id
== face_id
);
20638 s
->width
+= glyph
->pixel_width
;
20640 /* Adjust base line for subscript/superscript text. */
20641 s
->ybase
+= voffset
;
20643 /* The case that face->gc == 0 is handled when drawing the glyph
20644 string by calling PREPARE_FACE_FOR_DISPLAY. */
20646 return glyph
- s
->row
->glyphs
[s
->area
];
20649 static struct font_metrics
*
20650 get_per_char_metric (f
, font
, char2b
)
20655 static struct font_metrics metrics
;
20656 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20658 if (! font
|| code
== FONT_INVALID_CODE
)
20660 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20665 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20666 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20667 assumed to be zero. */
20670 x_get_glyph_overhangs (glyph
, f
, left
, right
)
20671 struct glyph
*glyph
;
20675 *left
= *right
= 0;
20677 if (glyph
->type
== CHAR_GLYPH
)
20681 struct font_metrics
*pcm
;
20683 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20684 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20686 if (pcm
->rbearing
> pcm
->width
)
20687 *right
= pcm
->rbearing
- pcm
->width
;
20688 if (pcm
->lbearing
< 0)
20689 *left
= -pcm
->lbearing
;
20692 else if (glyph
->type
== COMPOSITE_GLYPH
)
20694 if (! glyph
->u
.cmp
.automatic
)
20696 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20698 if (cmp
->rbearing
> cmp
->pixel_width
)
20699 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20700 if (cmp
->lbearing
< 0)
20701 *left
= - cmp
->lbearing
;
20705 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
20706 struct font_metrics metrics
;
20708 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
20709 glyph
->u
.cmp
.to
+ 1, &metrics
);
20710 if (metrics
.rbearing
> metrics
.width
)
20711 *right
= metrics
.rbearing
- metrics
.width
;
20712 if (metrics
.lbearing
< 0)
20713 *left
= - metrics
.lbearing
;
20719 /* Return the index of the first glyph preceding glyph string S that
20720 is overwritten by S because of S's left overhang. Value is -1
20721 if no glyphs are overwritten. */
20724 left_overwritten (s
)
20725 struct glyph_string
*s
;
20729 if (s
->left_overhang
)
20732 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20733 int first
= s
->first_glyph
- glyphs
;
20735 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
20736 x
-= glyphs
[i
].pixel_width
;
20747 /* Return the index of the first glyph preceding glyph string S that
20748 is overwriting S because of its right overhang. Value is -1 if no
20749 glyph in front of S overwrites S. */
20752 left_overwriting (s
)
20753 struct glyph_string
*s
;
20756 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20757 int first
= s
->first_glyph
- glyphs
;
20761 for (i
= first
- 1; i
>= 0; --i
)
20764 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20767 x
-= glyphs
[i
].pixel_width
;
20774 /* Return the index of the last glyph following glyph string S that is
20775 overwritten by S because of S's right overhang. Value is -1 if
20776 no such glyph is found. */
20779 right_overwritten (s
)
20780 struct glyph_string
*s
;
20784 if (s
->right_overhang
)
20787 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20788 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20789 int end
= s
->row
->used
[s
->area
];
20791 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
20792 x
+= glyphs
[i
].pixel_width
;
20801 /* Return the index of the last glyph following glyph string S that
20802 overwrites S because of its left overhang. Value is negative
20803 if no such glyph is found. */
20806 right_overwriting (s
)
20807 struct glyph_string
*s
;
20810 int end
= s
->row
->used
[s
->area
];
20811 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20812 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20816 for (i
= first
; i
< end
; ++i
)
20819 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20822 x
+= glyphs
[i
].pixel_width
;
20829 /* Set background width of glyph string S. START is the index of the
20830 first glyph following S. LAST_X is the right-most x-position + 1
20831 in the drawing area. */
20834 set_glyph_string_background_width (s
, start
, last_x
)
20835 struct glyph_string
*s
;
20839 /* If the face of this glyph string has to be drawn to the end of
20840 the drawing area, set S->extends_to_end_of_line_p. */
20842 if (start
== s
->row
->used
[s
->area
]
20843 && s
->area
== TEXT_AREA
20844 && ((s
->row
->fill_line_p
20845 && (s
->hl
== DRAW_NORMAL_TEXT
20846 || s
->hl
== DRAW_IMAGE_RAISED
20847 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20848 || s
->hl
== DRAW_MOUSE_FACE
))
20849 s
->extends_to_end_of_line_p
= 1;
20851 /* If S extends its face to the end of the line, set its
20852 background_width to the distance to the right edge of the drawing
20854 if (s
->extends_to_end_of_line_p
)
20855 s
->background_width
= last_x
- s
->x
+ 1;
20857 s
->background_width
= s
->width
;
20861 /* Compute overhangs and x-positions for glyph string S and its
20862 predecessors, or successors. X is the starting x-position for S.
20863 BACKWARD_P non-zero means process predecessors. */
20866 compute_overhangs_and_x (s
, x
, backward_p
)
20867 struct glyph_string
*s
;
20875 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20876 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20886 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20887 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20897 /* The following macros are only called from draw_glyphs below.
20898 They reference the following parameters of that function directly:
20899 `w', `row', `area', and `overlap_p'
20900 as well as the following local variables:
20901 `s', `f', and `hdc' (in W32) */
20904 /* On W32, silently add local `hdc' variable to argument list of
20905 init_glyph_string. */
20906 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20907 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20909 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20910 init_glyph_string (s, char2b, w, row, area, start, hl)
20913 /* Add a glyph string for a stretch glyph to the list of strings
20914 between HEAD and TAIL. START is the index of the stretch glyph in
20915 row area AREA of glyph row ROW. END is the index of the last glyph
20916 in that glyph row area. X is the current output position assigned
20917 to the new glyph string constructed. HL overrides that face of the
20918 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20919 is the right-most x-position of the drawing area. */
20921 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20922 and below -- keep them on one line. */
20923 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20926 s = (struct glyph_string *) alloca (sizeof *s); \
20927 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20928 START = fill_stretch_glyph_string (s, row, area, START, END); \
20929 append_glyph_string (&HEAD, &TAIL, s); \
20935 /* Add a glyph string for an image glyph to the list of strings
20936 between HEAD and TAIL. START is the index of the image glyph in
20937 row area AREA of glyph row ROW. END is the index of the last glyph
20938 in that glyph row area. X is the current output position assigned
20939 to the new glyph string constructed. HL overrides that face of the
20940 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20941 is the right-most x-position of the drawing area. */
20943 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20946 s = (struct glyph_string *) alloca (sizeof *s); \
20947 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20948 fill_image_glyph_string (s); \
20949 append_glyph_string (&HEAD, &TAIL, s); \
20956 /* Add a glyph string for a sequence of character glyphs to the list
20957 of strings between HEAD and TAIL. START is the index of the first
20958 glyph in row area AREA of glyph row ROW that is part of the new
20959 glyph string. END is the index of the last glyph in that glyph row
20960 area. X is the current output position assigned to the new glyph
20961 string constructed. HL overrides that face of the glyph; e.g. it
20962 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20963 right-most x-position of the drawing area. */
20965 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20971 face_id = (row)->glyphs[area][START].face_id; \
20973 s = (struct glyph_string *) alloca (sizeof *s); \
20974 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20975 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20976 append_glyph_string (&HEAD, &TAIL, s); \
20978 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20983 /* Add a glyph string for a composite sequence to the list of strings
20984 between HEAD and TAIL. START is the index of the first glyph in
20985 row area AREA of glyph row ROW that is part of the new glyph
20986 string. END is the index of the last glyph in that glyph row area.
20987 X is the current output position assigned to the new glyph string
20988 constructed. HL overrides that face of the glyph; e.g. it is
20989 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20990 x-position of the drawing area. */
20992 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20994 int face_id = (row)->glyphs[area][START].face_id; \
20995 struct face *base_face = FACE_FROM_ID (f, face_id); \
20996 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20997 struct composition *cmp = composition_table[cmp_id]; \
20999 struct glyph_string *first_s; \
21002 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
21004 /* Make glyph_strings for each glyph sequence that is drawable by \
21005 the same face, and append them to HEAD/TAIL. */ \
21006 for (n = 0; n < cmp->glyph_len;) \
21008 s = (struct glyph_string *) alloca (sizeof *s); \
21009 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21010 append_glyph_string (&(HEAD), &(TAIL), s); \
21016 n = fill_composite_glyph_string (s, base_face, overlaps); \
21024 /* Add a glyph string for a glyph-string sequence to the list of strings
21025 between HEAD and TAIL. */
21027 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
21031 Lisp_Object gstring; \
21033 face_id = (row)->glyphs[area][START].face_id; \
21034 gstring = (composition_gstring_from_id \
21035 ((row)->glyphs[area][START].u.cmp.id)); \
21036 s = (struct glyph_string *) alloca (sizeof *s); \
21037 char2b = (XChar2b *) alloca ((sizeof *char2b) \
21038 * LGSTRING_GLYPH_LEN (gstring)); \
21039 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
21040 append_glyph_string (&(HEAD), &(TAIL), s); \
21042 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
21046 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
21047 of AREA of glyph row ROW on window W between indices START and END.
21048 HL overrides the face for drawing glyph strings, e.g. it is
21049 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
21050 x-positions of the drawing area.
21052 This is an ugly monster macro construct because we must use alloca
21053 to allocate glyph strings (because draw_glyphs can be called
21054 asynchronously). */
21056 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
21059 HEAD = TAIL = NULL; \
21060 while (START < END) \
21062 struct glyph *first_glyph = (row)->glyphs[area] + START; \
21063 switch (first_glyph->type) \
21066 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
21070 case COMPOSITE_GLYPH: \
21071 if (first_glyph->u.cmp.automatic) \
21072 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
21075 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
21079 case STRETCH_GLYPH: \
21080 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
21084 case IMAGE_GLYPH: \
21085 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
21095 set_glyph_string_background_width (s, START, LAST_X); \
21102 /* Draw glyphs between START and END in AREA of ROW on window W,
21103 starting at x-position X. X is relative to AREA in W. HL is a
21104 face-override with the following meaning:
21106 DRAW_NORMAL_TEXT draw normally
21107 DRAW_CURSOR draw in cursor face
21108 DRAW_MOUSE_FACE draw in mouse face.
21109 DRAW_INVERSE_VIDEO draw in mode line face
21110 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
21111 DRAW_IMAGE_RAISED draw an image with a raised relief around it
21113 If OVERLAPS is non-zero, draw only the foreground of characters and
21114 clip to the physical height of ROW. Non-zero value also defines
21115 the overlapping part to be drawn:
21117 OVERLAPS_PRED overlap with preceding rows
21118 OVERLAPS_SUCC overlap with succeeding rows
21119 OVERLAPS_BOTH overlap with both preceding/succeeding rows
21120 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
21122 Value is the x-position reached, relative to AREA of W. */
21125 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
21128 struct glyph_row
*row
;
21129 enum glyph_row_area area
;
21130 EMACS_INT start
, end
;
21131 enum draw_glyphs_face hl
;
21134 struct glyph_string
*head
, *tail
;
21135 struct glyph_string
*s
;
21136 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
21137 int i
, j
, x_reached
, last_x
, area_left
= 0;
21138 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21141 ALLOCATE_HDC (hdc
, f
);
21143 /* Let's rather be paranoid than getting a SEGV. */
21144 end
= min (end
, row
->used
[area
]);
21145 start
= max (0, start
);
21146 start
= min (end
, start
);
21148 /* Translate X to frame coordinates. Set last_x to the right
21149 end of the drawing area. */
21150 if (row
->full_width_p
)
21152 /* X is relative to the left edge of W, without scroll bars
21154 area_left
= WINDOW_LEFT_EDGE_X (w
);
21155 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
21159 area_left
= window_box_left (w
, area
);
21160 last_x
= area_left
+ window_box_width (w
, area
);
21164 /* Build a doubly-linked list of glyph_string structures between
21165 head and tail from what we have to draw. Note that the macro
21166 BUILD_GLYPH_STRINGS will modify its start parameter. That's
21167 the reason we use a separate variable `i'. */
21169 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
21171 x_reached
= tail
->x
+ tail
->background_width
;
21175 /* If there are any glyphs with lbearing < 0 or rbearing > width in
21176 the row, redraw some glyphs in front or following the glyph
21177 strings built above. */
21178 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
21180 struct glyph_string
*h
, *t
;
21181 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
21182 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
21185 /* If mouse highlighting is on, we may need to draw adjacent
21186 glyphs using mouse-face highlighting. */
21187 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
21189 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
21191 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
21192 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
21194 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
21196 check_mouse_face
= 1;
21197 mouse_beg_col
= (row
== mouse_beg_row
)
21198 ? dpyinfo
->mouse_face_beg_col
: 0;
21199 mouse_end_col
= (row
== mouse_end_row
)
21200 ? dpyinfo
->mouse_face_end_col
21201 : row
->used
[TEXT_AREA
];
21205 /* Compute overhangs for all glyph strings. */
21206 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
21207 for (s
= head
; s
; s
= s
->next
)
21208 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
21210 /* Prepend glyph strings for glyphs in front of the first glyph
21211 string that are overwritten because of the first glyph
21212 string's left overhang. The background of all strings
21213 prepended must be drawn because the first glyph string
21215 i
= left_overwritten (head
);
21218 enum draw_glyphs_face overlap_hl
;
21220 /* If this row contains mouse highlighting, attempt to draw
21221 the overlapped glyphs with the correct highlight. This
21222 code fails if the overlap encompasses more than one glyph
21223 and mouse-highlight spans only some of these glyphs.
21224 However, making it work perfectly involves a lot more
21225 code, and I don't know if the pathological case occurs in
21226 practice, so we'll stick to this for now. --- cyd */
21227 if (check_mouse_face
21228 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21229 overlap_hl
= DRAW_MOUSE_FACE
;
21231 overlap_hl
= DRAW_NORMAL_TEXT
;
21234 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
21235 overlap_hl
, dummy_x
, last_x
);
21237 compute_overhangs_and_x (t
, head
->x
, 1);
21238 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21242 /* Prepend glyph strings for glyphs in front of the first glyph
21243 string that overwrite that glyph string because of their
21244 right overhang. For these strings, only the foreground must
21245 be drawn, because it draws over the glyph string at `head'.
21246 The background must not be drawn because this would overwrite
21247 right overhangs of preceding glyphs for which no glyph
21249 i
= left_overwriting (head
);
21252 enum draw_glyphs_face overlap_hl
;
21254 if (check_mouse_face
21255 && mouse_beg_col
< start
&& mouse_end_col
> i
)
21256 overlap_hl
= DRAW_MOUSE_FACE
;
21258 overlap_hl
= DRAW_NORMAL_TEXT
;
21261 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
21262 overlap_hl
, dummy_x
, last_x
);
21263 for (s
= h
; s
; s
= s
->next
)
21264 s
->background_filled_p
= 1;
21265 compute_overhangs_and_x (t
, head
->x
, 1);
21266 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
21269 /* Append glyphs strings for glyphs following the last glyph
21270 string tail that are overwritten by tail. The background of
21271 these strings has to be drawn because tail's foreground draws
21273 i
= right_overwritten (tail
);
21276 enum draw_glyphs_face overlap_hl
;
21278 if (check_mouse_face
21279 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21280 overlap_hl
= DRAW_MOUSE_FACE
;
21282 overlap_hl
= DRAW_NORMAL_TEXT
;
21284 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21285 overlap_hl
, x
, last_x
);
21286 /* Because BUILD_GLYPH_STRINGS updates the first argument,
21287 we don't have `end = i;' here. */
21288 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21289 append_glyph_string_lists (&head
, &tail
, h
, t
);
21293 /* Append glyph strings for glyphs following the last glyph
21294 string tail that overwrite tail. The foreground of such
21295 glyphs has to be drawn because it writes into the background
21296 of tail. The background must not be drawn because it could
21297 paint over the foreground of following glyphs. */
21298 i
= right_overwriting (tail
);
21301 enum draw_glyphs_face overlap_hl
;
21302 if (check_mouse_face
21303 && mouse_beg_col
< i
&& mouse_end_col
> end
)
21304 overlap_hl
= DRAW_MOUSE_FACE
;
21306 overlap_hl
= DRAW_NORMAL_TEXT
;
21309 i
++; /* We must include the Ith glyph. */
21310 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
21311 overlap_hl
, x
, last_x
);
21312 for (s
= h
; s
; s
= s
->next
)
21313 s
->background_filled_p
= 1;
21314 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
21315 append_glyph_string_lists (&head
, &tail
, h
, t
);
21317 if (clip_head
|| clip_tail
)
21318 for (s
= head
; s
; s
= s
->next
)
21320 s
->clip_head
= clip_head
;
21321 s
->clip_tail
= clip_tail
;
21325 /* Draw all strings. */
21326 for (s
= head
; s
; s
= s
->next
)
21327 FRAME_RIF (f
)->draw_glyph_string (s
);
21330 /* When focus a sole frame and move horizontally, this sets on_p to 0
21331 causing a failure to erase prev cursor position. */
21332 if (area
== TEXT_AREA
21333 && !row
->full_width_p
21334 /* When drawing overlapping rows, only the glyph strings'
21335 foreground is drawn, which doesn't erase a cursor
21339 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21340 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21341 : (tail
? tail
->x
+ tail
->background_width
: x
));
21345 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21346 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21350 /* Value is the x-position up to which drawn, relative to AREA of W.
21351 This doesn't include parts drawn because of overhangs. */
21352 if (row
->full_width_p
)
21353 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21355 x_reached
-= area_left
;
21357 RELEASE_HDC (hdc
, f
);
21362 /* Expand row matrix if too narrow. Don't expand if area
21365 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21367 if (!fonts_changed_p \
21368 && (it->glyph_row->glyphs[area] \
21369 < it->glyph_row->glyphs[area + 1])) \
21371 it->w->ncols_scale_factor++; \
21372 fonts_changed_p = 1; \
21376 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21377 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21383 struct glyph
*glyph
;
21384 enum glyph_row_area area
= it
->area
;
21386 xassert (it
->glyph_row
);
21387 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21389 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21390 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21392 glyph
->charpos
= CHARPOS (it
->position
);
21393 glyph
->object
= it
->object
;
21394 if (it
->pixel_width
> 0)
21396 glyph
->pixel_width
= it
->pixel_width
;
21397 glyph
->padding_p
= 0;
21401 /* Assure at least 1-pixel width. Otherwise, cursor can't
21402 be displayed correctly. */
21403 glyph
->pixel_width
= 1;
21404 glyph
->padding_p
= 1;
21406 glyph
->ascent
= it
->ascent
;
21407 glyph
->descent
= it
->descent
;
21408 glyph
->voffset
= it
->voffset
;
21409 glyph
->type
= CHAR_GLYPH
;
21410 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21411 glyph
->multibyte_p
= it
->multibyte_p
;
21412 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21413 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21414 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21415 || it
->phys_descent
> it
->descent
);
21416 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21417 glyph
->face_id
= it
->face_id
;
21418 glyph
->u
.ch
= it
->char_to_display
;
21419 glyph
->slice
= null_glyph_slice
;
21420 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21423 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21424 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21426 glyph
->bidi_type
= it
->bidi_it
.type
;
21428 ++it
->glyph_row
->used
[area
];
21431 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21434 /* Store one glyph for the composition IT->cmp_it.id in
21435 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21439 append_composite_glyph (it
)
21442 struct glyph
*glyph
;
21443 enum glyph_row_area area
= it
->area
;
21445 xassert (it
->glyph_row
);
21447 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21448 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21450 glyph
->charpos
= CHARPOS (it
->position
);
21451 glyph
->object
= it
->object
;
21452 glyph
->pixel_width
= it
->pixel_width
;
21453 glyph
->ascent
= it
->ascent
;
21454 glyph
->descent
= it
->descent
;
21455 glyph
->voffset
= it
->voffset
;
21456 glyph
->type
= COMPOSITE_GLYPH
;
21457 if (it
->cmp_it
.ch
< 0)
21459 glyph
->u
.cmp
.automatic
= 0;
21460 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21464 glyph
->u
.cmp
.automatic
= 1;
21465 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21466 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
21467 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
21469 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21470 glyph
->multibyte_p
= it
->multibyte_p
;
21471 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21472 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21473 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21474 || it
->phys_descent
> it
->descent
);
21475 glyph
->padding_p
= 0;
21476 glyph
->glyph_not_available_p
= 0;
21477 glyph
->face_id
= it
->face_id
;
21478 glyph
->slice
= null_glyph_slice
;
21479 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21482 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21483 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21485 glyph
->bidi_type
= it
->bidi_it
.type
;
21487 ++it
->glyph_row
->used
[area
];
21490 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21494 /* Change IT->ascent and IT->height according to the setting of
21498 take_vertical_position_into_account (it
)
21503 if (it
->voffset
< 0)
21504 /* Increase the ascent so that we can display the text higher
21506 it
->ascent
-= it
->voffset
;
21508 /* Increase the descent so that we can display the text lower
21510 it
->descent
+= it
->voffset
;
21515 /* Produce glyphs/get display metrics for the image IT is loaded with.
21516 See the description of struct display_iterator in dispextern.h for
21517 an overview of struct display_iterator. */
21520 produce_image_glyph (it
)
21525 int glyph_ascent
, crop
;
21526 struct glyph_slice slice
;
21528 xassert (it
->what
== IT_IMAGE
);
21530 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21532 /* Make sure X resources of the face is loaded. */
21533 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21535 if (it
->image_id
< 0)
21537 /* Fringe bitmap. */
21538 it
->ascent
= it
->phys_ascent
= 0;
21539 it
->descent
= it
->phys_descent
= 0;
21540 it
->pixel_width
= 0;
21545 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21547 /* Make sure X resources of the image is loaded. */
21548 prepare_image_for_display (it
->f
, img
);
21550 slice
.x
= slice
.y
= 0;
21551 slice
.width
= img
->width
;
21552 slice
.height
= img
->height
;
21554 if (INTEGERP (it
->slice
.x
))
21555 slice
.x
= XINT (it
->slice
.x
);
21556 else if (FLOATP (it
->slice
.x
))
21557 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21559 if (INTEGERP (it
->slice
.y
))
21560 slice
.y
= XINT (it
->slice
.y
);
21561 else if (FLOATP (it
->slice
.y
))
21562 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21564 if (INTEGERP (it
->slice
.width
))
21565 slice
.width
= XINT (it
->slice
.width
);
21566 else if (FLOATP (it
->slice
.width
))
21567 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21569 if (INTEGERP (it
->slice
.height
))
21570 slice
.height
= XINT (it
->slice
.height
);
21571 else if (FLOATP (it
->slice
.height
))
21572 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21574 if (slice
.x
>= img
->width
)
21575 slice
.x
= img
->width
;
21576 if (slice
.y
>= img
->height
)
21577 slice
.y
= img
->height
;
21578 if (slice
.x
+ slice
.width
>= img
->width
)
21579 slice
.width
= img
->width
- slice
.x
;
21580 if (slice
.y
+ slice
.height
> img
->height
)
21581 slice
.height
= img
->height
- slice
.y
;
21583 if (slice
.width
== 0 || slice
.height
== 0)
21586 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21588 it
->descent
= slice
.height
- glyph_ascent
;
21590 it
->descent
+= img
->vmargin
;
21591 if (slice
.y
+ slice
.height
== img
->height
)
21592 it
->descent
+= img
->vmargin
;
21593 it
->phys_descent
= it
->descent
;
21595 it
->pixel_width
= slice
.width
;
21597 it
->pixel_width
+= img
->hmargin
;
21598 if (slice
.x
+ slice
.width
== img
->width
)
21599 it
->pixel_width
+= img
->hmargin
;
21601 /* It's quite possible for images to have an ascent greater than
21602 their height, so don't get confused in that case. */
21603 if (it
->descent
< 0)
21608 if (face
->box
!= FACE_NO_BOX
)
21610 if (face
->box_line_width
> 0)
21613 it
->ascent
+= face
->box_line_width
;
21614 if (slice
.y
+ slice
.height
== img
->height
)
21615 it
->descent
+= face
->box_line_width
;
21618 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21619 it
->pixel_width
+= eabs (face
->box_line_width
);
21620 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21621 it
->pixel_width
+= eabs (face
->box_line_width
);
21624 take_vertical_position_into_account (it
);
21626 /* Automatically crop wide image glyphs at right edge so we can
21627 draw the cursor on same display row. */
21628 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21629 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21631 it
->pixel_width
-= crop
;
21632 slice
.width
-= crop
;
21637 struct glyph
*glyph
;
21638 enum glyph_row_area area
= it
->area
;
21640 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21641 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21643 glyph
->charpos
= CHARPOS (it
->position
);
21644 glyph
->object
= it
->object
;
21645 glyph
->pixel_width
= it
->pixel_width
;
21646 glyph
->ascent
= glyph_ascent
;
21647 glyph
->descent
= it
->descent
;
21648 glyph
->voffset
= it
->voffset
;
21649 glyph
->type
= IMAGE_GLYPH
;
21650 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21651 glyph
->multibyte_p
= it
->multibyte_p
;
21652 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21653 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21654 glyph
->overlaps_vertically_p
= 0;
21655 glyph
->padding_p
= 0;
21656 glyph
->glyph_not_available_p
= 0;
21657 glyph
->face_id
= it
->face_id
;
21658 glyph
->u
.img_id
= img
->id
;
21659 glyph
->slice
= slice
;
21660 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21663 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21664 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21666 glyph
->bidi_type
= it
->bidi_it
.type
;
21668 ++it
->glyph_row
->used
[area
];
21671 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21676 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
21677 of the glyph, WIDTH and HEIGHT are the width and height of the
21678 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
21681 append_stretch_glyph (it
, object
, width
, height
, ascent
)
21683 Lisp_Object object
;
21687 struct glyph
*glyph
;
21688 enum glyph_row_area area
= it
->area
;
21690 xassert (ascent
>= 0 && ascent
<= height
);
21692 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21693 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21695 glyph
->charpos
= CHARPOS (it
->position
);
21696 glyph
->object
= object
;
21697 glyph
->pixel_width
= width
;
21698 glyph
->ascent
= ascent
;
21699 glyph
->descent
= height
- ascent
;
21700 glyph
->voffset
= it
->voffset
;
21701 glyph
->type
= STRETCH_GLYPH
;
21702 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21703 glyph
->multibyte_p
= it
->multibyte_p
;
21704 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21705 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21706 glyph
->overlaps_vertically_p
= 0;
21707 glyph
->padding_p
= 0;
21708 glyph
->glyph_not_available_p
= 0;
21709 glyph
->face_id
= it
->face_id
;
21710 glyph
->u
.stretch
.ascent
= ascent
;
21711 glyph
->u
.stretch
.height
= height
;
21712 glyph
->slice
= null_glyph_slice
;
21713 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21716 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21717 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21719 glyph
->bidi_type
= it
->bidi_it
.type
;
21721 ++it
->glyph_row
->used
[area
];
21724 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21728 /* Produce a stretch glyph for iterator IT. IT->object is the value
21729 of the glyph property displayed. The value must be a list
21730 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
21733 1. `:width WIDTH' specifies that the space should be WIDTH *
21734 canonical char width wide. WIDTH may be an integer or floating
21737 2. `:relative-width FACTOR' specifies that the width of the stretch
21738 should be computed from the width of the first character having the
21739 `glyph' property, and should be FACTOR times that width.
21741 3. `:align-to HPOS' specifies that the space should be wide enough
21742 to reach HPOS, a value in canonical character units.
21744 Exactly one of the above pairs must be present.
21746 4. `:height HEIGHT' specifies that the height of the stretch produced
21747 should be HEIGHT, measured in canonical character units.
21749 5. `:relative-height FACTOR' specifies that the height of the
21750 stretch should be FACTOR times the height of the characters having
21751 the glyph property.
21753 Either none or exactly one of 4 or 5 must be present.
21755 6. `:ascent ASCENT' specifies that ASCENT percent of the height
21756 of the stretch should be used for the ascent of the stretch.
21757 ASCENT must be in the range 0 <= ASCENT <= 100. */
21760 produce_stretch_glyph (it
)
21763 /* (space :width WIDTH :height HEIGHT ...) */
21764 Lisp_Object prop
, plist
;
21765 int width
= 0, height
= 0, align_to
= -1;
21766 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
21769 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21770 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
21772 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21774 /* List should start with `space'. */
21775 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
21776 plist
= XCDR (it
->object
);
21778 /* Compute the width of the stretch. */
21779 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
21780 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
21782 /* Absolute width `:width WIDTH' specified and valid. */
21783 zero_width_ok_p
= 1;
21786 else if (prop
= Fplist_get (plist
, QCrelative_width
),
21789 /* Relative width `:relative-width FACTOR' specified and valid.
21790 Compute the width of the characters having the `glyph'
21793 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
21796 if (it
->multibyte_p
)
21798 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
21799 - IT_BYTEPOS (*it
));
21800 it2
.c
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
21803 it2
.c
= *p
, it2
.len
= 1;
21805 it2
.glyph_row
= NULL
;
21806 it2
.what
= IT_CHARACTER
;
21807 x_produce_glyphs (&it2
);
21808 width
= NUMVAL (prop
) * it2
.pixel_width
;
21810 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
21811 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
21813 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
21814 align_to
= (align_to
< 0
21816 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
21817 else if (align_to
< 0)
21818 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
21819 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
21820 zero_width_ok_p
= 1;
21823 /* Nothing specified -> width defaults to canonical char width. */
21824 width
= FRAME_COLUMN_WIDTH (it
->f
);
21826 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
21829 /* Compute height. */
21830 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
21831 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21834 zero_height_ok_p
= 1;
21836 else if (prop
= Fplist_get (plist
, QCrelative_height
),
21838 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
21840 height
= FONT_HEIGHT (font
);
21842 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
21845 /* Compute percentage of height used for ascent. If
21846 `:ascent ASCENT' is present and valid, use that. Otherwise,
21847 derive the ascent from the font in use. */
21848 if (prop
= Fplist_get (plist
, QCascent
),
21849 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
21850 ascent
= height
* NUMVAL (prop
) / 100.0;
21851 else if (!NILP (prop
)
21852 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21853 ascent
= min (max (0, (int)tem
), height
);
21855 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
21857 if (width
> 0 && it
->line_wrap
!= TRUNCATE
21858 && it
->current_x
+ width
> it
->last_visible_x
)
21859 width
= it
->last_visible_x
- it
->current_x
- 1;
21861 if (width
> 0 && height
> 0 && it
->glyph_row
)
21863 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
21864 if (!STRINGP (object
))
21865 object
= it
->w
->buffer
;
21866 append_stretch_glyph (it
, object
, width
, height
, ascent
);
21869 it
->pixel_width
= width
;
21870 it
->ascent
= it
->phys_ascent
= ascent
;
21871 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
21872 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21874 take_vertical_position_into_account (it
);
21877 /* Calculate line-height and line-spacing properties.
21878 An integer value specifies explicit pixel value.
21879 A float value specifies relative value to current face height.
21880 A cons (float . face-name) specifies relative value to
21881 height of specified face font.
21883 Returns height in pixels, or nil. */
21887 calc_line_height_property (it
, val
, font
, boff
, override
)
21891 int boff
, override
;
21893 Lisp_Object face_name
= Qnil
;
21894 int ascent
, descent
, height
;
21896 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21901 face_name
= XCAR (val
);
21903 if (!NUMBERP (val
))
21904 val
= make_number (1);
21905 if (NILP (face_name
))
21907 height
= it
->ascent
+ it
->descent
;
21912 if (NILP (face_name
))
21914 font
= FRAME_FONT (it
->f
);
21915 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21917 else if (EQ (face_name
, Qt
))
21926 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21928 return make_number (-1);
21930 face
= FACE_FROM_ID (it
->f
, face_id
);
21933 return make_number (-1);
21934 boff
= font
->baseline_offset
;
21935 if (font
->vertical_centering
)
21936 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21939 ascent
= FONT_BASE (font
) + boff
;
21940 descent
= FONT_DESCENT (font
) - boff
;
21944 it
->override_ascent
= ascent
;
21945 it
->override_descent
= descent
;
21946 it
->override_boff
= boff
;
21949 height
= ascent
+ descent
;
21953 height
= (int)(XFLOAT_DATA (val
) * height
);
21954 else if (INTEGERP (val
))
21955 height
*= XINT (val
);
21957 return make_number (height
);
21962 Produce glyphs/get display metrics for the display element IT is
21963 loaded with. See the description of struct it in dispextern.h
21964 for an overview of struct it. */
21967 x_produce_glyphs (it
)
21970 int extra_line_spacing
= it
->extra_line_spacing
;
21972 it
->glyph_not_available_p
= 0;
21974 if (it
->what
== IT_CHARACTER
)
21978 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21979 struct font_metrics
*pcm
;
21980 int font_not_found_p
;
21981 int boff
; /* baseline offset */
21982 /* We may change it->multibyte_p upon unibyte<->multibyte
21983 conversion. So, save the current value now and restore it
21986 Note: It seems that we don't have to record multibyte_p in
21987 struct glyph because the character code itself tells whether
21988 or not the character is multibyte. Thus, in the future, we
21989 must consider eliminating the field `multibyte_p' in the
21991 int saved_multibyte_p
= it
->multibyte_p
;
21993 /* Maybe translate single-byte characters to multibyte, or the
21995 it
->char_to_display
= it
->c
;
21996 if (!ASCII_BYTE_P (it
->c
)
21997 && ! it
->multibyte_p
)
21999 if (SINGLE_BYTE_CHAR_P (it
->c
)
22000 && unibyte_display_via_language_environment
)
22002 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
22004 /* get_next_display_element assures that this decoding
22006 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
22007 it
->multibyte_p
= 1;
22008 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
22010 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22014 /* Get font to use. Encode IT->char_to_display. */
22015 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
22016 &char2b
, it
->multibyte_p
, 0);
22019 font_not_found_p
= font
== NULL
;
22020 if (font_not_found_p
)
22022 /* When no suitable font found, display an empty box based
22023 on the metrics of the font of the default face (or what
22025 struct face
*no_font_face
22026 = FACE_FROM_ID (it
->f
,
22027 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
22028 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
22029 font
= no_font_face
->font
;
22030 boff
= font
->baseline_offset
;
22034 boff
= font
->baseline_offset
;
22035 if (font
->vertical_centering
)
22036 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22039 if (it
->char_to_display
>= ' '
22040 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
22042 /* Either unibyte or ASCII. */
22047 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22049 if (it
->override_ascent
>= 0)
22051 it
->ascent
= it
->override_ascent
;
22052 it
->descent
= it
->override_descent
;
22053 boff
= it
->override_boff
;
22057 it
->ascent
= FONT_BASE (font
) + boff
;
22058 it
->descent
= FONT_DESCENT (font
) - boff
;
22063 it
->phys_ascent
= pcm
->ascent
+ boff
;
22064 it
->phys_descent
= pcm
->descent
- boff
;
22065 it
->pixel_width
= pcm
->width
;
22069 it
->glyph_not_available_p
= 1;
22070 it
->phys_ascent
= it
->ascent
;
22071 it
->phys_descent
= it
->descent
;
22072 it
->pixel_width
= FONT_WIDTH (font
);
22075 if (it
->constrain_row_ascent_descent_p
)
22077 if (it
->descent
> it
->max_descent
)
22079 it
->ascent
+= it
->descent
- it
->max_descent
;
22080 it
->descent
= it
->max_descent
;
22082 if (it
->ascent
> it
->max_ascent
)
22084 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22085 it
->ascent
= it
->max_ascent
;
22087 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22088 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22089 extra_line_spacing
= 0;
22092 /* If this is a space inside a region of text with
22093 `space-width' property, change its width. */
22094 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
22096 it
->pixel_width
*= XFLOATINT (it
->space_width
);
22098 /* If face has a box, add the box thickness to the character
22099 height. If character has a box line to the left and/or
22100 right, add the box line width to the character's width. */
22101 if (face
->box
!= FACE_NO_BOX
)
22103 int thick
= face
->box_line_width
;
22107 it
->ascent
+= thick
;
22108 it
->descent
+= thick
;
22113 if (it
->start_of_box_run_p
)
22114 it
->pixel_width
+= thick
;
22115 if (it
->end_of_box_run_p
)
22116 it
->pixel_width
+= thick
;
22119 /* If face has an overline, add the height of the overline
22120 (1 pixel) and a 1 pixel margin to the character height. */
22121 if (face
->overline_p
)
22122 it
->ascent
+= overline_margin
;
22124 if (it
->constrain_row_ascent_descent_p
)
22126 if (it
->ascent
> it
->max_ascent
)
22127 it
->ascent
= it
->max_ascent
;
22128 if (it
->descent
> it
->max_descent
)
22129 it
->descent
= it
->max_descent
;
22132 take_vertical_position_into_account (it
);
22134 /* If we have to actually produce glyphs, do it. */
22139 /* Translate a space with a `space-width' property
22140 into a stretch glyph. */
22141 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
22142 / FONT_HEIGHT (font
));
22143 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22144 it
->ascent
+ it
->descent
, ascent
);
22149 /* If characters with lbearing or rbearing are displayed
22150 in this line, record that fact in a flag of the
22151 glyph row. This is used to optimize X output code. */
22152 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
22153 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22155 if (! stretched_p
&& it
->pixel_width
== 0)
22156 /* We assure that all visible glyphs have at least 1-pixel
22158 it
->pixel_width
= 1;
22160 else if (it
->char_to_display
== '\n')
22162 /* A newline has no width, but we need the height of the
22163 line. But if previous part of the line sets a height,
22164 don't increase that height */
22166 Lisp_Object height
;
22167 Lisp_Object total_height
= Qnil
;
22169 it
->override_ascent
= -1;
22170 it
->pixel_width
= 0;
22173 height
= get_it_property(it
, Qline_height
);
22174 /* Split (line-height total-height) list */
22176 && CONSP (XCDR (height
))
22177 && NILP (XCDR (XCDR (height
))))
22179 total_height
= XCAR (XCDR (height
));
22180 height
= XCAR (height
);
22182 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
22184 if (it
->override_ascent
>= 0)
22186 it
->ascent
= it
->override_ascent
;
22187 it
->descent
= it
->override_descent
;
22188 boff
= it
->override_boff
;
22192 it
->ascent
= FONT_BASE (font
) + boff
;
22193 it
->descent
= FONT_DESCENT (font
) - boff
;
22196 if (EQ (height
, Qt
))
22198 if (it
->descent
> it
->max_descent
)
22200 it
->ascent
+= it
->descent
- it
->max_descent
;
22201 it
->descent
= it
->max_descent
;
22203 if (it
->ascent
> it
->max_ascent
)
22205 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
22206 it
->ascent
= it
->max_ascent
;
22208 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
22209 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
22210 it
->constrain_row_ascent_descent_p
= 1;
22211 extra_line_spacing
= 0;
22215 Lisp_Object spacing
;
22217 it
->phys_ascent
= it
->ascent
;
22218 it
->phys_descent
= it
->descent
;
22220 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
22221 && face
->box
!= FACE_NO_BOX
22222 && face
->box_line_width
> 0)
22224 it
->ascent
+= face
->box_line_width
;
22225 it
->descent
+= face
->box_line_width
;
22228 && XINT (height
) > it
->ascent
+ it
->descent
)
22229 it
->ascent
= XINT (height
) - it
->descent
;
22231 if (!NILP (total_height
))
22232 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
22235 spacing
= get_it_property(it
, Qline_spacing
);
22236 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
22238 if (INTEGERP (spacing
))
22240 extra_line_spacing
= XINT (spacing
);
22241 if (!NILP (total_height
))
22242 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
22246 else if (it
->char_to_display
== '\t')
22248 if (font
->space_width
> 0)
22250 int tab_width
= it
->tab_width
* font
->space_width
;
22251 int x
= it
->current_x
+ it
->continuation_lines_width
;
22252 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
22254 /* If the distance from the current position to the next tab
22255 stop is less than a space character width, use the
22256 tab stop after that. */
22257 if (next_tab_x
- x
< font
->space_width
)
22258 next_tab_x
+= tab_width
;
22260 it
->pixel_width
= next_tab_x
- x
;
22262 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
22263 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22267 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
22268 it
->ascent
+ it
->descent
, it
->ascent
);
22273 it
->pixel_width
= 0;
22279 /* A multi-byte character. Assume that the display width of the
22280 character is the width of the character multiplied by the
22281 width of the font. */
22283 /* If we found a font, this font should give us the right
22284 metrics. If we didn't find a font, use the frame's
22285 default font and calculate the width of the character by
22286 multiplying the width of font by the width of the
22289 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22291 if (font_not_found_p
|| !pcm
)
22293 int char_width
= CHAR_WIDTH (it
->char_to_display
);
22295 if (char_width
== 0)
22296 /* This is a non spacing character. But, as we are
22297 going to display an empty box, the box must occupy
22298 at least one column. */
22300 it
->glyph_not_available_p
= 1;
22301 it
->pixel_width
= font
->space_width
* char_width
;
22302 it
->phys_ascent
= FONT_BASE (font
) + boff
;
22303 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
22307 it
->pixel_width
= pcm
->width
;
22308 it
->phys_ascent
= pcm
->ascent
+ boff
;
22309 it
->phys_descent
= pcm
->descent
- boff
;
22311 && (pcm
->lbearing
< 0
22312 || pcm
->rbearing
> pcm
->width
))
22313 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22316 it
->ascent
= FONT_BASE (font
) + boff
;
22317 it
->descent
= FONT_DESCENT (font
) - boff
;
22318 if (face
->box
!= FACE_NO_BOX
)
22320 int thick
= face
->box_line_width
;
22324 it
->ascent
+= thick
;
22325 it
->descent
+= thick
;
22330 if (it
->start_of_box_run_p
)
22331 it
->pixel_width
+= thick
;
22332 if (it
->end_of_box_run_p
)
22333 it
->pixel_width
+= thick
;
22336 /* If face has an overline, add the height of the overline
22337 (1 pixel) and a 1 pixel margin to the character height. */
22338 if (face
->overline_p
)
22339 it
->ascent
+= overline_margin
;
22341 take_vertical_position_into_account (it
);
22343 if (it
->ascent
< 0)
22345 if (it
->descent
< 0)
22350 if (it
->pixel_width
== 0)
22351 /* We assure that all visible glyphs have at least 1-pixel
22353 it
->pixel_width
= 1;
22355 it
->multibyte_p
= saved_multibyte_p
;
22357 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22359 /* A static composition.
22361 Note: A composition is represented as one glyph in the
22362 glyph matrix. There are no padding glyphs.
22364 Important note: pixel_width, ascent, and descent are the
22365 values of what is drawn by draw_glyphs (i.e. the values of
22366 the overall glyphs composed). */
22367 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22368 int boff
; /* baseline offset */
22369 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22370 int glyph_len
= cmp
->glyph_len
;
22371 struct font
*font
= face
->font
;
22375 /* If we have not yet calculated pixel size data of glyphs of
22376 the composition for the current face font, calculate them
22377 now. Theoretically, we have to check all fonts for the
22378 glyphs, but that requires much time and memory space. So,
22379 here we check only the font of the first glyph. This may
22380 lead to incorrect display, but it's very rare, and C-l
22381 (recenter-top-bottom) can correct the display anyway. */
22382 if (! cmp
->font
|| cmp
->font
!= font
)
22384 /* Ascent and descent of the font of the first character
22385 of this composition (adjusted by baseline offset).
22386 Ascent and descent of overall glyphs should not be less
22387 than these, respectively. */
22388 int font_ascent
, font_descent
, font_height
;
22389 /* Bounding box of the overall glyphs. */
22390 int leftmost
, rightmost
, lowest
, highest
;
22391 int lbearing
, rbearing
;
22392 int i
, width
, ascent
, descent
;
22393 int left_padded
= 0, right_padded
= 0;
22396 struct font_metrics
*pcm
;
22397 int font_not_found_p
;
22400 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22401 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22403 if (glyph_len
< cmp
->glyph_len
)
22405 for (i
= 0; i
< glyph_len
; i
++)
22407 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22409 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22414 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22415 : IT_CHARPOS (*it
));
22416 /* If no suitable font is found, use the default font. */
22417 font_not_found_p
= font
== NULL
;
22418 if (font_not_found_p
)
22420 face
= face
->ascii_face
;
22423 boff
= font
->baseline_offset
;
22424 if (font
->vertical_centering
)
22425 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22426 font_ascent
= FONT_BASE (font
) + boff
;
22427 font_descent
= FONT_DESCENT (font
) - boff
;
22428 font_height
= FONT_HEIGHT (font
);
22430 cmp
->font
= (void *) font
;
22433 if (! font_not_found_p
)
22435 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22436 &char2b
, it
->multibyte_p
, 0);
22437 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22440 /* Initialize the bounding box. */
22443 width
= pcm
->width
;
22444 ascent
= pcm
->ascent
;
22445 descent
= pcm
->descent
;
22446 lbearing
= pcm
->lbearing
;
22447 rbearing
= pcm
->rbearing
;
22451 width
= FONT_WIDTH (font
);
22452 ascent
= FONT_BASE (font
);
22453 descent
= FONT_DESCENT (font
);
22460 lowest
= - descent
+ boff
;
22461 highest
= ascent
+ boff
;
22463 if (! font_not_found_p
22464 && font
->default_ascent
22465 && CHAR_TABLE_P (Vuse_default_ascent
)
22466 && !NILP (Faref (Vuse_default_ascent
,
22467 make_number (it
->char_to_display
))))
22468 highest
= font
->default_ascent
+ boff
;
22470 /* Draw the first glyph at the normal position. It may be
22471 shifted to right later if some other glyphs are drawn
22473 cmp
->offsets
[i
* 2] = 0;
22474 cmp
->offsets
[i
* 2 + 1] = boff
;
22475 cmp
->lbearing
= lbearing
;
22476 cmp
->rbearing
= rbearing
;
22478 /* Set cmp->offsets for the remaining glyphs. */
22479 for (i
++; i
< glyph_len
; i
++)
22481 int left
, right
, btm
, top
;
22482 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22484 struct face
*this_face
;
22489 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22490 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22491 font
= this_face
->font
;
22497 this_boff
= font
->baseline_offset
;
22498 if (font
->vertical_centering
)
22499 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22500 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22501 &char2b
, it
->multibyte_p
, 0);
22502 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22505 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22508 width
= pcm
->width
;
22509 ascent
= pcm
->ascent
;
22510 descent
= pcm
->descent
;
22511 lbearing
= pcm
->lbearing
;
22512 rbearing
= pcm
->rbearing
;
22513 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22515 /* Relative composition with or without
22516 alternate chars. */
22517 left
= (leftmost
+ rightmost
- width
) / 2;
22518 btm
= - descent
+ boff
;
22519 if (font
->relative_compose
22520 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22521 || NILP (Faref (Vignore_relative_composition
,
22522 make_number (ch
)))))
22525 if (- descent
>= font
->relative_compose
)
22526 /* One extra pixel between two glyphs. */
22528 else if (ascent
<= 0)
22529 /* One extra pixel between two glyphs. */
22530 btm
= lowest
- 1 - ascent
- descent
;
22535 /* A composition rule is specified by an integer
22536 value that encodes global and new reference
22537 points (GREF and NREF). GREF and NREF are
22538 specified by numbers as below:
22540 0---1---2 -- ascent
22544 9--10--11 -- center
22546 ---3---4---5--- baseline
22548 6---7---8 -- descent
22550 int rule
= COMPOSITION_RULE (cmp
, i
);
22551 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
22553 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
22554 grefx
= gref
% 3, nrefx
= nref
% 3;
22555 grefy
= gref
/ 3, nrefy
= nref
/ 3;
22557 xoff
= font_height
* (xoff
- 128) / 256;
22559 yoff
= font_height
* (yoff
- 128) / 256;
22562 + grefx
* (rightmost
- leftmost
) / 2
22563 - nrefx
* width
/ 2
22566 btm
= ((grefy
== 0 ? highest
22568 : grefy
== 2 ? lowest
22569 : (highest
+ lowest
) / 2)
22570 - (nrefy
== 0 ? ascent
+ descent
22571 : nrefy
== 1 ? descent
- boff
22573 : (ascent
+ descent
) / 2)
22577 cmp
->offsets
[i
* 2] = left
;
22578 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
22580 /* Update the bounding box of the overall glyphs. */
22583 right
= left
+ width
;
22584 if (left
< leftmost
)
22586 if (right
> rightmost
)
22589 top
= btm
+ descent
+ ascent
;
22595 if (cmp
->lbearing
> left
+ lbearing
)
22596 cmp
->lbearing
= left
+ lbearing
;
22597 if (cmp
->rbearing
< left
+ rbearing
)
22598 cmp
->rbearing
= left
+ rbearing
;
22602 /* If there are glyphs whose x-offsets are negative,
22603 shift all glyphs to the right and make all x-offsets
22607 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22608 cmp
->offsets
[i
* 2] -= leftmost
;
22609 rightmost
-= leftmost
;
22610 cmp
->lbearing
-= leftmost
;
22611 cmp
->rbearing
-= leftmost
;
22614 if (left_padded
&& cmp
->lbearing
< 0)
22616 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22617 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
22618 rightmost
-= cmp
->lbearing
;
22619 cmp
->rbearing
-= cmp
->lbearing
;
22622 if (right_padded
&& rightmost
< cmp
->rbearing
)
22624 rightmost
= cmp
->rbearing
;
22627 cmp
->pixel_width
= rightmost
;
22628 cmp
->ascent
= highest
;
22629 cmp
->descent
= - lowest
;
22630 if (cmp
->ascent
< font_ascent
)
22631 cmp
->ascent
= font_ascent
;
22632 if (cmp
->descent
< font_descent
)
22633 cmp
->descent
= font_descent
;
22637 && (cmp
->lbearing
< 0
22638 || cmp
->rbearing
> cmp
->pixel_width
))
22639 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22641 it
->pixel_width
= cmp
->pixel_width
;
22642 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
22643 it
->descent
= it
->phys_descent
= cmp
->descent
;
22644 if (face
->box
!= FACE_NO_BOX
)
22646 int thick
= face
->box_line_width
;
22650 it
->ascent
+= thick
;
22651 it
->descent
+= thick
;
22656 if (it
->start_of_box_run_p
)
22657 it
->pixel_width
+= thick
;
22658 if (it
->end_of_box_run_p
)
22659 it
->pixel_width
+= thick
;
22662 /* If face has an overline, add the height of the overline
22663 (1 pixel) and a 1 pixel margin to the character height. */
22664 if (face
->overline_p
)
22665 it
->ascent
+= overline_margin
;
22667 take_vertical_position_into_account (it
);
22668 if (it
->ascent
< 0)
22670 if (it
->descent
< 0)
22674 append_composite_glyph (it
);
22676 else if (it
->what
== IT_COMPOSITION
)
22678 /* A dynamic (automatic) composition. */
22679 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22680 Lisp_Object gstring
;
22681 struct font_metrics metrics
;
22683 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
22685 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
22688 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
22689 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22690 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
22691 it
->descent
= it
->phys_descent
= metrics
.descent
;
22692 if (face
->box
!= FACE_NO_BOX
)
22694 int thick
= face
->box_line_width
;
22698 it
->ascent
+= thick
;
22699 it
->descent
+= thick
;
22704 if (it
->start_of_box_run_p
)
22705 it
->pixel_width
+= thick
;
22706 if (it
->end_of_box_run_p
)
22707 it
->pixel_width
+= thick
;
22709 /* If face has an overline, add the height of the overline
22710 (1 pixel) and a 1 pixel margin to the character height. */
22711 if (face
->overline_p
)
22712 it
->ascent
+= overline_margin
;
22713 take_vertical_position_into_account (it
);
22714 if (it
->ascent
< 0)
22716 if (it
->descent
< 0)
22720 append_composite_glyph (it
);
22722 else if (it
->what
== IT_IMAGE
)
22723 produce_image_glyph (it
);
22724 else if (it
->what
== IT_STRETCH
)
22725 produce_stretch_glyph (it
);
22727 /* Accumulate dimensions. Note: can't assume that it->descent > 0
22728 because this isn't true for images with `:ascent 100'. */
22729 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
22730 if (it
->area
== TEXT_AREA
)
22731 it
->current_x
+= it
->pixel_width
;
22733 if (extra_line_spacing
> 0)
22735 it
->descent
+= extra_line_spacing
;
22736 if (extra_line_spacing
> it
->max_extra_line_spacing
)
22737 it
->max_extra_line_spacing
= extra_line_spacing
;
22740 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
22741 it
->max_descent
= max (it
->max_descent
, it
->descent
);
22742 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
22743 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
22747 Output LEN glyphs starting at START at the nominal cursor position.
22748 Advance the nominal cursor over the text. The global variable
22749 updated_window contains the window being updated, updated_row is
22750 the glyph row being updated, and updated_area is the area of that
22751 row being updated. */
22754 x_write_glyphs (start
, len
)
22755 struct glyph
*start
;
22760 xassert (updated_window
&& updated_row
);
22763 /* Write glyphs. */
22765 hpos
= start
- updated_row
->glyphs
[updated_area
];
22766 x
= draw_glyphs (updated_window
, output_cursor
.x
,
22767 updated_row
, updated_area
,
22769 DRAW_NORMAL_TEXT
, 0);
22771 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
22772 if (updated_area
== TEXT_AREA
22773 && updated_window
->phys_cursor_on_p
22774 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
22775 && updated_window
->phys_cursor
.hpos
>= hpos
22776 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
22777 updated_window
->phys_cursor_on_p
= 0;
22781 /* Advance the output cursor. */
22782 output_cursor
.hpos
+= len
;
22783 output_cursor
.x
= x
;
22788 Insert LEN glyphs from START at the nominal cursor position. */
22791 x_insert_glyphs (start
, len
)
22792 struct glyph
*start
;
22797 int line_height
, shift_by_width
, shifted_region_width
;
22798 struct glyph_row
*row
;
22799 struct glyph
*glyph
;
22800 int frame_x
, frame_y
;
22803 xassert (updated_window
&& updated_row
);
22805 w
= updated_window
;
22806 f
= XFRAME (WINDOW_FRAME (w
));
22808 /* Get the height of the line we are in. */
22810 line_height
= row
->height
;
22812 /* Get the width of the glyphs to insert. */
22813 shift_by_width
= 0;
22814 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
22815 shift_by_width
+= glyph
->pixel_width
;
22817 /* Get the width of the region to shift right. */
22818 shifted_region_width
= (window_box_width (w
, updated_area
)
22823 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
22824 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
22826 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
22827 line_height
, shift_by_width
);
22829 /* Write the glyphs. */
22830 hpos
= start
- row
->glyphs
[updated_area
];
22831 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
22833 DRAW_NORMAL_TEXT
, 0);
22835 /* Advance the output cursor. */
22836 output_cursor
.hpos
+= len
;
22837 output_cursor
.x
+= shift_by_width
;
22843 Erase the current text line from the nominal cursor position
22844 (inclusive) to pixel column TO_X (exclusive). The idea is that
22845 everything from TO_X onward is already erased.
22847 TO_X is a pixel position relative to updated_area of
22848 updated_window. TO_X == -1 means clear to the end of this area. */
22851 x_clear_end_of_line (to_x
)
22855 struct window
*w
= updated_window
;
22856 int max_x
, min_y
, max_y
;
22857 int from_x
, from_y
, to_y
;
22859 xassert (updated_window
&& updated_row
);
22860 f
= XFRAME (w
->frame
);
22862 if (updated_row
->full_width_p
)
22863 max_x
= WINDOW_TOTAL_WIDTH (w
);
22865 max_x
= window_box_width (w
, updated_area
);
22866 max_y
= window_text_bottom_y (w
);
22868 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
22869 of window. For TO_X > 0, truncate to end of drawing area. */
22875 to_x
= min (to_x
, max_x
);
22877 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
22879 /* Notice if the cursor will be cleared by this operation. */
22880 if (!updated_row
->full_width_p
)
22881 notice_overwritten_cursor (w
, updated_area
,
22882 output_cursor
.x
, -1,
22884 MATRIX_ROW_BOTTOM_Y (updated_row
));
22886 from_x
= output_cursor
.x
;
22888 /* Translate to frame coordinates. */
22889 if (updated_row
->full_width_p
)
22891 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
22892 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
22896 int area_left
= window_box_left (w
, updated_area
);
22897 from_x
+= area_left
;
22901 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22902 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22903 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22905 /* Prevent inadvertently clearing to end of the X window. */
22906 if (to_x
> from_x
&& to_y
> from_y
)
22909 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22910 to_x
- from_x
, to_y
- from_y
);
22915 #endif /* HAVE_WINDOW_SYSTEM */
22919 /***********************************************************************
22921 ***********************************************************************/
22923 /* Value is the internal representation of the specified cursor type
22924 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22925 of the bar cursor. */
22927 static enum text_cursor_kinds
22928 get_specified_cursor_type (arg
, width
)
22932 enum text_cursor_kinds type
;
22937 if (EQ (arg
, Qbox
))
22938 return FILLED_BOX_CURSOR
;
22940 if (EQ (arg
, Qhollow
))
22941 return HOLLOW_BOX_CURSOR
;
22943 if (EQ (arg
, Qbar
))
22950 && EQ (XCAR (arg
), Qbar
)
22951 && INTEGERP (XCDR (arg
))
22952 && XINT (XCDR (arg
)) >= 0)
22954 *width
= XINT (XCDR (arg
));
22958 if (EQ (arg
, Qhbar
))
22961 return HBAR_CURSOR
;
22965 && EQ (XCAR (arg
), Qhbar
)
22966 && INTEGERP (XCDR (arg
))
22967 && XINT (XCDR (arg
)) >= 0)
22969 *width
= XINT (XCDR (arg
));
22970 return HBAR_CURSOR
;
22973 /* Treat anything unknown as "hollow box cursor".
22974 It was bad to signal an error; people have trouble fixing
22975 .Xdefaults with Emacs, when it has something bad in it. */
22976 type
= HOLLOW_BOX_CURSOR
;
22981 /* Set the default cursor types for specified frame. */
22983 set_frame_cursor_types (f
, arg
)
22990 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22991 FRAME_CURSOR_WIDTH (f
) = width
;
22993 /* By default, set up the blink-off state depending on the on-state. */
22995 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22998 FRAME_BLINK_OFF_CURSOR (f
)
22999 = get_specified_cursor_type (XCDR (tem
), &width
);
23000 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
23003 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
23007 /* Return the cursor we want to be displayed in window W. Return
23008 width of bar/hbar cursor through WIDTH arg. Return with
23009 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
23010 (i.e. if the `system caret' should track this cursor).
23012 In a mini-buffer window, we want the cursor only to appear if we
23013 are reading input from this window. For the selected window, we
23014 want the cursor type given by the frame parameter or buffer local
23015 setting of cursor-type. If explicitly marked off, draw no cursor.
23016 In all other cases, we want a hollow box cursor. */
23018 static enum text_cursor_kinds
23019 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
23021 struct glyph
*glyph
;
23023 int *active_cursor
;
23025 struct frame
*f
= XFRAME (w
->frame
);
23026 struct buffer
*b
= XBUFFER (w
->buffer
);
23027 int cursor_type
= DEFAULT_CURSOR
;
23028 Lisp_Object alt_cursor
;
23029 int non_selected
= 0;
23031 *active_cursor
= 1;
23034 if (cursor_in_echo_area
23035 && FRAME_HAS_MINIBUF_P (f
)
23036 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
23038 if (w
== XWINDOW (echo_area_window
))
23040 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
23042 *width
= FRAME_CURSOR_WIDTH (f
);
23043 return FRAME_DESIRED_CURSOR (f
);
23046 return get_specified_cursor_type (b
->cursor_type
, width
);
23049 *active_cursor
= 0;
23053 /* Detect a nonselected window or nonselected frame. */
23054 else if (w
!= XWINDOW (f
->selected_window
)
23055 #ifdef HAVE_WINDOW_SYSTEM
23056 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
23060 *active_cursor
= 0;
23062 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
23068 /* Never display a cursor in a window in which cursor-type is nil. */
23069 if (NILP (b
->cursor_type
))
23072 /* Get the normal cursor type for this window. */
23073 if (EQ (b
->cursor_type
, Qt
))
23075 cursor_type
= FRAME_DESIRED_CURSOR (f
);
23076 *width
= FRAME_CURSOR_WIDTH (f
);
23079 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
23081 /* Use cursor-in-non-selected-windows instead
23082 for non-selected window or frame. */
23085 alt_cursor
= b
->cursor_in_non_selected_windows
;
23086 if (!EQ (Qt
, alt_cursor
))
23087 return get_specified_cursor_type (alt_cursor
, width
);
23088 /* t means modify the normal cursor type. */
23089 if (cursor_type
== FILLED_BOX_CURSOR
)
23090 cursor_type
= HOLLOW_BOX_CURSOR
;
23091 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
23093 return cursor_type
;
23096 /* Use normal cursor if not blinked off. */
23097 if (!w
->cursor_off_p
)
23099 #ifdef HAVE_WINDOW_SYSTEM
23100 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23102 if (cursor_type
== FILLED_BOX_CURSOR
)
23104 /* Using a block cursor on large images can be very annoying.
23105 So use a hollow cursor for "large" images.
23106 If image is not transparent (no mask), also use hollow cursor. */
23107 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23108 if (img
!= NULL
&& IMAGEP (img
->spec
))
23110 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
23111 where N = size of default frame font size.
23112 This should cover most of the "tiny" icons people may use. */
23114 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
23115 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
23116 cursor_type
= HOLLOW_BOX_CURSOR
;
23119 else if (cursor_type
!= NO_CURSOR
)
23121 /* Display current only supports BOX and HOLLOW cursors for images.
23122 So for now, unconditionally use a HOLLOW cursor when cursor is
23123 not a solid box cursor. */
23124 cursor_type
= HOLLOW_BOX_CURSOR
;
23128 return cursor_type
;
23131 /* Cursor is blinked off, so determine how to "toggle" it. */
23133 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
23134 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
23135 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
23137 /* Then see if frame has specified a specific blink off cursor type. */
23138 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
23140 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
23141 return FRAME_BLINK_OFF_CURSOR (f
);
23145 /* Some people liked having a permanently visible blinking cursor,
23146 while others had very strong opinions against it. So it was
23147 decided to remove it. KFS 2003-09-03 */
23149 /* Finally perform built-in cursor blinking:
23150 filled box <-> hollow box
23151 wide [h]bar <-> narrow [h]bar
23152 narrow [h]bar <-> no cursor
23153 other type <-> no cursor */
23155 if (cursor_type
== FILLED_BOX_CURSOR
)
23156 return HOLLOW_BOX_CURSOR
;
23158 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
23161 return cursor_type
;
23169 #ifdef HAVE_WINDOW_SYSTEM
23171 /* Notice when the text cursor of window W has been completely
23172 overwritten by a drawing operation that outputs glyphs in AREA
23173 starting at X0 and ending at X1 in the line starting at Y0 and
23174 ending at Y1. X coordinates are area-relative. X1 < 0 means all
23175 the rest of the line after X0 has been written. Y coordinates
23176 are window-relative. */
23179 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
23181 enum glyph_row_area area
;
23182 int x0
, y0
, x1
, y1
;
23184 int cx0
, cx1
, cy0
, cy1
;
23185 struct glyph_row
*row
;
23187 if (!w
->phys_cursor_on_p
)
23189 if (area
!= TEXT_AREA
)
23192 if (w
->phys_cursor
.vpos
< 0
23193 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
23194 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
23195 !(row
->enabled_p
&& row
->displays_text_p
)))
23198 if (row
->cursor_in_fringe_p
)
23200 row
->cursor_in_fringe_p
= 0;
23201 draw_fringe_bitmap (w
, row
, 0);
23202 w
->phys_cursor_on_p
= 0;
23206 cx0
= w
->phys_cursor
.x
;
23207 cx1
= cx0
+ w
->phys_cursor_width
;
23208 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
23211 /* The cursor image will be completely removed from the
23212 screen if the output area intersects the cursor area in
23213 y-direction. When we draw in [y0 y1[, and some part of
23214 the cursor is at y < y0, that part must have been drawn
23215 before. When scrolling, the cursor is erased before
23216 actually scrolling, so we don't come here. When not
23217 scrolling, the rows above the old cursor row must have
23218 changed, and in this case these rows must have written
23219 over the cursor image.
23221 Likewise if part of the cursor is below y1, with the
23222 exception of the cursor being in the first blank row at
23223 the buffer and window end because update_text_area
23224 doesn't draw that row. (Except when it does, but
23225 that's handled in update_text_area.) */
23227 cy0
= w
->phys_cursor
.y
;
23228 cy1
= cy0
+ w
->phys_cursor_height
;
23229 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
23232 w
->phys_cursor_on_p
= 0;
23235 #endif /* HAVE_WINDOW_SYSTEM */
23238 /************************************************************************
23240 ************************************************************************/
23242 #ifdef HAVE_WINDOW_SYSTEM
23245 Fix the display of area AREA of overlapping row ROW in window W
23246 with respect to the overlapping part OVERLAPS. */
23249 x_fix_overlapping_area (w
, row
, area
, overlaps
)
23251 struct glyph_row
*row
;
23252 enum glyph_row_area area
;
23260 for (i
= 0; i
< row
->used
[area
];)
23262 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
23264 int start
= i
, start_x
= x
;
23268 x
+= row
->glyphs
[area
][i
].pixel_width
;
23271 while (i
< row
->used
[area
]
23272 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
23274 draw_glyphs (w
, start_x
, row
, area
,
23276 DRAW_NORMAL_TEXT
, overlaps
);
23280 x
+= row
->glyphs
[area
][i
].pixel_width
;
23290 Draw the cursor glyph of window W in glyph row ROW. See the
23291 comment of draw_glyphs for the meaning of HL. */
23294 draw_phys_cursor_glyph (w
, row
, hl
)
23296 struct glyph_row
*row
;
23297 enum draw_glyphs_face hl
;
23299 /* If cursor hpos is out of bounds, don't draw garbage. This can
23300 happen in mini-buffer windows when switching between echo area
23301 glyphs and mini-buffer. */
23302 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
23304 int on_p
= w
->phys_cursor_on_p
;
23306 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
23307 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
23309 w
->phys_cursor_on_p
= on_p
;
23311 if (hl
== DRAW_CURSOR
)
23312 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23313 /* When we erase the cursor, and ROW is overlapped by other
23314 rows, make sure that these overlapping parts of other rows
23316 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
23318 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
23320 if (row
> w
->current_matrix
->rows
23321 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
23322 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
23323 OVERLAPS_ERASED_CURSOR
);
23325 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
23326 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
23327 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
23328 OVERLAPS_ERASED_CURSOR
);
23335 Erase the image of a cursor of window W from the screen. */
23338 erase_phys_cursor (w
)
23341 struct frame
*f
= XFRAME (w
->frame
);
23342 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23343 int hpos
= w
->phys_cursor
.hpos
;
23344 int vpos
= w
->phys_cursor
.vpos
;
23345 int mouse_face_here_p
= 0;
23346 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23347 struct glyph_row
*cursor_row
;
23348 struct glyph
*cursor_glyph
;
23349 enum draw_glyphs_face hl
;
23351 /* No cursor displayed or row invalidated => nothing to do on the
23353 if (w
->phys_cursor_type
== NO_CURSOR
)
23354 goto mark_cursor_off
;
23356 /* VPOS >= active_glyphs->nrows means that window has been resized.
23357 Don't bother to erase the cursor. */
23358 if (vpos
>= active_glyphs
->nrows
)
23359 goto mark_cursor_off
;
23361 /* If row containing cursor is marked invalid, there is nothing we
23363 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23364 if (!cursor_row
->enabled_p
)
23365 goto mark_cursor_off
;
23367 /* If line spacing is > 0, old cursor may only be partially visible in
23368 window after split-window. So adjust visible height. */
23369 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23370 window_text_bottom_y (w
) - cursor_row
->y
);
23372 /* If row is completely invisible, don't attempt to delete a cursor which
23373 isn't there. This can happen if cursor is at top of a window, and
23374 we switch to a buffer with a header line in that window. */
23375 if (cursor_row
->visible_height
<= 0)
23376 goto mark_cursor_off
;
23378 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23379 if (cursor_row
->cursor_in_fringe_p
)
23381 cursor_row
->cursor_in_fringe_p
= 0;
23382 draw_fringe_bitmap (w
, cursor_row
, 0);
23383 goto mark_cursor_off
;
23386 /* This can happen when the new row is shorter than the old one.
23387 In this case, either draw_glyphs or clear_end_of_line
23388 should have cleared the cursor. Note that we wouldn't be
23389 able to erase the cursor in this case because we don't have a
23390 cursor glyph at hand. */
23391 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
23392 goto mark_cursor_off
;
23394 /* If the cursor is in the mouse face area, redisplay that when
23395 we clear the cursor. */
23396 if (! NILP (dpyinfo
->mouse_face_window
)
23397 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
23398 && (vpos
> dpyinfo
->mouse_face_beg_row
23399 || (vpos
== dpyinfo
->mouse_face_beg_row
23400 && hpos
>= dpyinfo
->mouse_face_beg_col
))
23401 && (vpos
< dpyinfo
->mouse_face_end_row
23402 || (vpos
== dpyinfo
->mouse_face_end_row
23403 && hpos
< dpyinfo
->mouse_face_end_col
))
23404 /* Don't redraw the cursor's spot in mouse face if it is at the
23405 end of a line (on a newline). The cursor appears there, but
23406 mouse highlighting does not. */
23407 && cursor_row
->used
[TEXT_AREA
] > hpos
)
23408 mouse_face_here_p
= 1;
23410 /* Maybe clear the display under the cursor. */
23411 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23414 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23417 cursor_glyph
= get_phys_cursor_glyph (w
);
23418 if (cursor_glyph
== NULL
)
23419 goto mark_cursor_off
;
23421 width
= cursor_glyph
->pixel_width
;
23422 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23423 x
= w
->phys_cursor
.x
;
23425 width
-= left_x
- x
;
23426 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23427 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23428 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23431 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23434 /* Erase the cursor by redrawing the character underneath it. */
23435 if (mouse_face_here_p
)
23436 hl
= DRAW_MOUSE_FACE
;
23438 hl
= DRAW_NORMAL_TEXT
;
23439 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23442 w
->phys_cursor_on_p
= 0;
23443 w
->phys_cursor_type
= NO_CURSOR
;
23448 Display or clear cursor of window W. If ON is zero, clear the
23449 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23450 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23453 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
23455 int on
, hpos
, vpos
, x
, y
;
23457 struct frame
*f
= XFRAME (w
->frame
);
23458 int new_cursor_type
;
23459 int new_cursor_width
;
23461 struct glyph_row
*glyph_row
;
23462 struct glyph
*glyph
;
23464 /* This is pointless on invisible frames, and dangerous on garbaged
23465 windows and frames; in the latter case, the frame or window may
23466 be in the midst of changing its size, and x and y may be off the
23468 if (! FRAME_VISIBLE_P (f
)
23469 || FRAME_GARBAGED_P (f
)
23470 || vpos
>= w
->current_matrix
->nrows
23471 || hpos
>= w
->current_matrix
->matrix_w
)
23474 /* If cursor is off and we want it off, return quickly. */
23475 if (!on
&& !w
->phys_cursor_on_p
)
23478 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23479 /* If cursor row is not enabled, we don't really know where to
23480 display the cursor. */
23481 if (!glyph_row
->enabled_p
)
23483 w
->phys_cursor_on_p
= 0;
23488 if (!glyph_row
->exact_window_width_line_p
23489 || hpos
< glyph_row
->used
[TEXT_AREA
])
23490 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23492 xassert (interrupt_input_blocked
);
23494 /* Set new_cursor_type to the cursor we want to be displayed. */
23495 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23496 &new_cursor_width
, &active_cursor
);
23498 /* If cursor is currently being shown and we don't want it to be or
23499 it is in the wrong place, or the cursor type is not what we want,
23501 if (w
->phys_cursor_on_p
23503 || w
->phys_cursor
.x
!= x
23504 || w
->phys_cursor
.y
!= y
23505 || new_cursor_type
!= w
->phys_cursor_type
23506 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23507 && new_cursor_width
!= w
->phys_cursor_width
)))
23508 erase_phys_cursor (w
);
23510 /* Don't check phys_cursor_on_p here because that flag is only set
23511 to zero in some cases where we know that the cursor has been
23512 completely erased, to avoid the extra work of erasing the cursor
23513 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23514 still not be visible, or it has only been partly erased. */
23517 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23518 w
->phys_cursor_height
= glyph_row
->height
;
23520 /* Set phys_cursor_.* before x_draw_.* is called because some
23521 of them may need the information. */
23522 w
->phys_cursor
.x
= x
;
23523 w
->phys_cursor
.y
= glyph_row
->y
;
23524 w
->phys_cursor
.hpos
= hpos
;
23525 w
->phys_cursor
.vpos
= vpos
;
23528 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23529 new_cursor_type
, new_cursor_width
,
23530 on
, active_cursor
);
23534 /* Switch the display of W's cursor on or off, according to the value
23541 update_window_cursor (w
, on
)
23545 /* Don't update cursor in windows whose frame is in the process
23546 of being deleted. */
23547 if (w
->current_matrix
)
23550 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23551 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23557 /* Call update_window_cursor with parameter ON_P on all leaf windows
23558 in the window tree rooted at W. */
23561 update_cursor_in_window_tree (w
, on_p
)
23567 if (!NILP (w
->hchild
))
23568 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23569 else if (!NILP (w
->vchild
))
23570 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23572 update_window_cursor (w
, on_p
);
23574 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23580 Display the cursor on window W, or clear it, according to ON_P.
23581 Don't change the cursor's position. */
23584 x_update_cursor (f
, on_p
)
23588 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
23593 Clear the cursor of window W to background color, and mark the
23594 cursor as not shown. This is used when the text where the cursor
23595 is about to be rewritten. */
23601 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
23602 update_window_cursor (w
, 0);
23607 Display the active region described by mouse_face_* according to DRAW. */
23610 show_mouse_face (dpyinfo
, draw
)
23611 Display_Info
*dpyinfo
;
23612 enum draw_glyphs_face draw
;
23614 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
23615 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23617 if (/* If window is in the process of being destroyed, don't bother
23619 w
->current_matrix
!= NULL
23620 /* Don't update mouse highlight if hidden */
23621 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
23622 /* Recognize when we are called to operate on rows that don't exist
23623 anymore. This can happen when a window is split. */
23624 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
23626 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
23627 struct glyph_row
*row
, *first
, *last
;
23629 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
23630 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
23632 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
23634 int start_hpos
, end_hpos
, start_x
;
23636 /* For all but the first row, the highlight starts at column 0. */
23639 start_hpos
= dpyinfo
->mouse_face_beg_col
;
23640 start_x
= dpyinfo
->mouse_face_beg_x
;
23649 end_hpos
= dpyinfo
->mouse_face_end_col
;
23652 end_hpos
= row
->used
[TEXT_AREA
];
23653 if (draw
== DRAW_NORMAL_TEXT
)
23654 row
->fill_line_p
= 1; /* Clear to end of line */
23657 if (end_hpos
> start_hpos
)
23659 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
23660 start_hpos
, end_hpos
,
23664 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
23668 /* When we've written over the cursor, arrange for it to
23669 be displayed again. */
23670 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
23673 display_and_set_cursor (w
, 1,
23674 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23675 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23680 /* Change the mouse cursor. */
23681 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
23682 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
23683 else if (draw
== DRAW_MOUSE_FACE
)
23684 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
23686 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
23690 Clear out the mouse-highlighted active region.
23691 Redraw it un-highlighted first. Value is non-zero if mouse
23692 face was actually drawn unhighlighted. */
23695 clear_mouse_face (dpyinfo
)
23696 Display_Info
*dpyinfo
;
23700 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
23702 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
23706 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23707 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23708 dpyinfo
->mouse_face_window
= Qnil
;
23709 dpyinfo
->mouse_face_overlay
= Qnil
;
23715 Non-zero if physical cursor of window W is within mouse face. */
23718 cursor_in_mouse_face_p (w
)
23721 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23722 int in_mouse_face
= 0;
23724 if (WINDOWP (dpyinfo
->mouse_face_window
)
23725 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
23727 int hpos
= w
->phys_cursor
.hpos
;
23728 int vpos
= w
->phys_cursor
.vpos
;
23730 if (vpos
>= dpyinfo
->mouse_face_beg_row
23731 && vpos
<= dpyinfo
->mouse_face_end_row
23732 && (vpos
> dpyinfo
->mouse_face_beg_row
23733 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23734 && (vpos
< dpyinfo
->mouse_face_end_row
23735 || hpos
< dpyinfo
->mouse_face_end_col
23736 || dpyinfo
->mouse_face_past_end
))
23740 return in_mouse_face
;
23746 /* This function sets the mouse_face_* elements of DPYINFO, assuming
23747 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
23748 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
23749 for the overlay or run of text properties specifying the mouse
23750 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
23751 before-string and after-string that must also be highlighted.
23752 DISPLAY_STRING, if non-nil, is a display string that may cover some
23753 or all of the highlighted text. */
23756 mouse_face_from_buffer_pos (Lisp_Object window
,
23757 Display_Info
*dpyinfo
,
23758 EMACS_INT mouse_charpos
,
23759 EMACS_INT start_charpos
,
23760 EMACS_INT end_charpos
,
23761 Lisp_Object before_string
,
23762 Lisp_Object after_string
,
23763 Lisp_Object display_string
)
23765 struct window
*w
= XWINDOW (window
);
23766 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23767 struct glyph_row
*row
;
23768 struct glyph
*glyph
, *end
;
23772 xassert (NILP (display_string
) || STRINGP (display_string
));
23773 xassert (NILP (before_string
) || STRINGP (before_string
));
23774 xassert (NILP (after_string
) || STRINGP (after_string
));
23776 /* Find the first highlighted glyph. */
23777 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
23779 dpyinfo
->mouse_face_beg_col
= 0;
23780 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
23781 dpyinfo
->mouse_face_beg_x
= first
->x
;
23782 dpyinfo
->mouse_face_beg_y
= first
->y
;
23786 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
23788 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23790 /* If the before-string or display-string contains newlines,
23791 row_containing_pos skips to its last row. Move back. */
23792 if (!NILP (before_string
) || !NILP (display_string
))
23794 struct glyph_row
*prev
;
23795 while ((prev
= row
- 1, prev
>= first
)
23796 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
23797 && prev
->used
[TEXT_AREA
] > 0)
23799 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
23800 glyph
= beg
+ prev
->used
[TEXT_AREA
];
23801 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
23803 || !(EQ (glyph
->object
, before_string
)
23804 || EQ (glyph
->object
, display_string
)))
23810 glyph
= row
->glyphs
[TEXT_AREA
];
23811 end
= glyph
+ row
->used
[TEXT_AREA
];
23813 dpyinfo
->mouse_face_beg_y
= row
->y
;
23814 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23816 /* Skip truncation glyphs at the start of the glyph row. */
23817 if (row
->displays_text_p
)
23819 && INTEGERP (glyph
->object
)
23820 && glyph
->charpos
< 0;
23822 x
+= glyph
->pixel_width
;
23824 /* Scan the glyph row, stopping before BEFORE_STRING or
23825 DISPLAY_STRING or START_CHARPOS. */
23827 && !INTEGERP (glyph
->object
)
23828 && !EQ (glyph
->object
, before_string
)
23829 && !EQ (glyph
->object
, display_string
)
23830 && !(BUFFERP (glyph
->object
)
23831 && glyph
->charpos
>= start_charpos
);
23833 x
+= glyph
->pixel_width
;
23835 dpyinfo
->mouse_face_beg_x
= x
;
23836 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23839 /* Find the last highlighted glyph. */
23840 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
23843 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23844 dpyinfo
->mouse_face_past_end
= 1;
23846 else if (!NILP (after_string
))
23848 /* If the after-string has newlines, advance to its last row. */
23849 struct glyph_row
*next
;
23850 struct glyph_row
*last
23851 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23853 for (next
= row
+ 1;
23855 && next
->used
[TEXT_AREA
] > 0
23856 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
23861 glyph
= row
->glyphs
[TEXT_AREA
];
23862 end
= glyph
+ row
->used
[TEXT_AREA
];
23864 dpyinfo
->mouse_face_end_y
= row
->y
;
23865 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23867 /* Skip truncation glyphs at the start of the row. */
23868 if (row
->displays_text_p
)
23870 && INTEGERP (glyph
->object
)
23871 && glyph
->charpos
< 0;
23873 x
+= glyph
->pixel_width
;
23875 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
23878 && !INTEGERP (glyph
->object
)
23879 && !EQ (glyph
->object
, after_string
)
23880 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
23882 x
+= glyph
->pixel_width
;
23884 /* If we found AFTER_STRING, consume it and stop. */
23885 if (EQ (glyph
->object
, after_string
))
23887 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
23888 x
+= glyph
->pixel_width
;
23892 /* If there's no after-string, we must check if we overshot,
23893 which might be the case if we stopped after a string glyph.
23894 That glyph may belong to a before-string or display-string
23895 associated with the end position, which must not be
23897 Lisp_Object prev_object
;
23900 while (glyph
> row
->glyphs
[TEXT_AREA
])
23902 prev_object
= (glyph
- 1)->object
;
23903 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23906 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23907 if (pos
&& pos
< end_charpos
)
23910 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23911 && EQ ((glyph
- 1)->object
, prev_object
);
23913 x
-= (glyph
- 1)->pixel_width
;
23917 dpyinfo
->mouse_face_end_x
= x
;
23918 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23919 dpyinfo
->mouse_face_window
= window
;
23920 dpyinfo
->mouse_face_face_id
23921 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23923 !dpyinfo
->mouse_face_hidden
, -1);
23924 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23928 /* Find the position of the glyph for position POS in OBJECT in
23929 window W's current matrix, and return in *X, *Y the pixel
23930 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23932 RIGHT_P non-zero means return the position of the right edge of the
23933 glyph, RIGHT_P zero means return the left edge position.
23935 If no glyph for POS exists in the matrix, return the position of
23936 the glyph with the next smaller position that is in the matrix, if
23937 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23938 exists in the matrix, return the position of the glyph with the
23939 next larger position in OBJECT.
23941 Value is non-zero if a glyph was found. */
23944 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23947 Lisp_Object object
;
23948 int *hpos
, *vpos
, *x
, *y
;
23951 int yb
= window_text_bottom_y (w
);
23952 struct glyph_row
*r
;
23953 struct glyph
*best_glyph
= NULL
;
23954 struct glyph_row
*best_row
= NULL
;
23957 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23958 r
->enabled_p
&& r
->y
< yb
;
23961 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23962 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23965 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23966 if (EQ (g
->object
, object
))
23968 if (g
->charpos
== pos
)
23975 else if (best_glyph
== NULL
23976 || ((eabs (g
->charpos
- pos
)
23977 < eabs (best_glyph
->charpos
- pos
))
23980 : g
->charpos
> pos
)))
23994 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23998 *x
+= best_glyph
->pixel_width
;
24003 *vpos
= best_row
- w
->current_matrix
->rows
;
24006 return best_glyph
!= NULL
;
24010 /* See if position X, Y is within a hot-spot of an image. */
24013 on_hot_spot_p (hot_spot
, x
, y
)
24014 Lisp_Object hot_spot
;
24017 if (!CONSP (hot_spot
))
24020 if (EQ (XCAR (hot_spot
), Qrect
))
24022 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
24023 Lisp_Object rect
= XCDR (hot_spot
);
24027 if (!CONSP (XCAR (rect
)))
24029 if (!CONSP (XCDR (rect
)))
24031 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
24033 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
24035 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
24037 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
24041 else if (EQ (XCAR (hot_spot
), Qcircle
))
24043 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
24044 Lisp_Object circ
= XCDR (hot_spot
);
24045 Lisp_Object lr
, lx0
, ly0
;
24047 && CONSP (XCAR (circ
))
24048 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
24049 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
24050 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
24052 double r
= XFLOATINT (lr
);
24053 double dx
= XINT (lx0
) - x
;
24054 double dy
= XINT (ly0
) - y
;
24055 return (dx
* dx
+ dy
* dy
<= r
* r
);
24058 else if (EQ (XCAR (hot_spot
), Qpoly
))
24060 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
24061 if (VECTORP (XCDR (hot_spot
)))
24063 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
24064 Lisp_Object
*poly
= v
->contents
;
24068 Lisp_Object lx
, ly
;
24071 /* Need an even number of coordinates, and at least 3 edges. */
24072 if (n
< 6 || n
& 1)
24075 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
24076 If count is odd, we are inside polygon. Pixels on edges
24077 may or may not be included depending on actual geometry of the
24079 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
24080 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
24082 x0
= XINT (lx
), y0
= XINT (ly
);
24083 for (i
= 0; i
< n
; i
+= 2)
24085 int x1
= x0
, y1
= y0
;
24086 if ((lx
= poly
[i
], !INTEGERP (lx
))
24087 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
24089 x0
= XINT (lx
), y0
= XINT (ly
);
24091 /* Does this segment cross the X line? */
24099 if (y
> y0
&& y
> y1
)
24101 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
24111 find_hot_spot (map
, x
, y
)
24115 while (CONSP (map
))
24117 if (CONSP (XCAR (map
))
24118 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
24126 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
24128 doc
: /* Lookup in image map MAP coordinates X and Y.
24129 An image map is an alist where each element has the format (AREA ID PLIST).
24130 An AREA is specified as either a rectangle, a circle, or a polygon:
24131 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
24132 pixel coordinates of the upper left and bottom right corners.
24133 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
24134 and the radius of the circle; r may be a float or integer.
24135 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
24136 vector describes one corner in the polygon.
24137 Returns the alist element for the first matching AREA in MAP. */)
24148 return find_hot_spot (map
, XINT (x
), XINT (y
));
24152 /* Display frame CURSOR, optionally using shape defined by POINTER. */
24154 define_frame_cursor1 (f
, cursor
, pointer
)
24157 Lisp_Object pointer
;
24159 /* Do not change cursor shape while dragging mouse. */
24160 if (!NILP (do_mouse_tracking
))
24163 if (!NILP (pointer
))
24165 if (EQ (pointer
, Qarrow
))
24166 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24167 else if (EQ (pointer
, Qhand
))
24168 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
24169 else if (EQ (pointer
, Qtext
))
24170 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24171 else if (EQ (pointer
, intern ("hdrag")))
24172 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24173 #ifdef HAVE_X_WINDOWS
24174 else if (EQ (pointer
, intern ("vdrag")))
24175 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
24177 else if (EQ (pointer
, intern ("hourglass")))
24178 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
24179 else if (EQ (pointer
, Qmodeline
))
24180 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
24182 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24185 if (cursor
!= No_Cursor
)
24186 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
24189 /* Take proper action when mouse has moved to the mode or header line
24190 or marginal area AREA of window W, x-position X and y-position Y.
24191 X is relative to the start of the text display area of W, so the
24192 width of bitmap areas and scroll bars must be subtracted to get a
24193 position relative to the start of the mode line. */
24196 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
24197 Lisp_Object window
;
24199 enum window_part area
;
24201 struct window
*w
= XWINDOW (window
);
24202 struct frame
*f
= XFRAME (w
->frame
);
24203 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24204 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24205 Lisp_Object pointer
= Qnil
;
24206 int charpos
, dx
, dy
, width
, height
;
24207 Lisp_Object string
, object
= Qnil
;
24208 Lisp_Object pos
, help
;
24210 Lisp_Object mouse_face
;
24211 int original_x_pixel
= x
;
24212 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
24213 struct glyph_row
*row
;
24215 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
24220 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
24221 &object
, &dx
, &dy
, &width
, &height
);
24223 row
= (area
== ON_MODE_LINE
24224 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
24225 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
24228 if (row
->mode_line_p
&& row
->enabled_p
)
24230 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
24231 end
= glyph
+ row
->used
[TEXT_AREA
];
24233 for (x0
= original_x_pixel
;
24234 glyph
< end
&& x0
>= glyph
->pixel_width
;
24236 x0
-= glyph
->pixel_width
;
24244 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
24245 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
24246 &object
, &dx
, &dy
, &width
, &height
);
24251 if (IMAGEP (object
))
24253 Lisp_Object image_map
, hotspot
;
24254 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
24256 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
24258 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24260 Lisp_Object area_id
, plist
;
24262 area_id
= XCAR (hotspot
);
24263 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24264 If so, we could look for mouse-enter, mouse-leave
24265 properties in PLIST (and do something...). */
24266 hotspot
= XCDR (hotspot
);
24267 if (CONSP (hotspot
)
24268 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24270 pointer
= Fplist_get (plist
, Qpointer
);
24271 if (NILP (pointer
))
24273 help
= Fplist_get (plist
, Qhelp_echo
);
24276 help_echo_string
= help
;
24277 /* Is this correct? ++kfs */
24278 XSETWINDOW (help_echo_window
, w
);
24279 help_echo_object
= w
->buffer
;
24280 help_echo_pos
= charpos
;
24284 if (NILP (pointer
))
24285 pointer
= Fplist_get (XCDR (object
), QCpointer
);
24288 if (STRINGP (string
))
24290 pos
= make_number (charpos
);
24291 /* If we're on a string with `help-echo' text property, arrange
24292 for the help to be displayed. This is done by setting the
24293 global variable help_echo_string to the help string. */
24296 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
24299 help_echo_string
= help
;
24300 XSETWINDOW (help_echo_window
, w
);
24301 help_echo_object
= string
;
24302 help_echo_pos
= charpos
;
24306 if (NILP (pointer
))
24307 pointer
= Fget_text_property (pos
, Qpointer
, string
);
24309 /* Change the mouse pointer according to what is under X/Y. */
24310 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
24313 map
= Fget_text_property (pos
, Qlocal_map
, string
);
24314 if (!KEYMAPP (map
))
24315 map
= Fget_text_property (pos
, Qkeymap
, string
);
24316 if (!KEYMAPP (map
))
24317 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
24320 /* Change the mouse face according to what is under X/Y. */
24321 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
24322 if (!NILP (mouse_face
)
24323 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24328 struct glyph
* tmp_glyph
;
24332 int total_pixel_width
;
24337 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
24338 Qmouse_face
, string
, Qnil
);
24340 b
= make_number (0);
24342 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
24344 e
= make_number (SCHARS (string
));
24346 /* Calculate the position(glyph position: GPOS) of GLYPH in
24347 displayed string. GPOS is different from CHARPOS.
24349 CHARPOS is the position of glyph in internal string
24350 object. A mode line string format has structures which
24351 is converted to a flatten by emacs lisp interpreter.
24352 The internal string is an element of the structures.
24353 The displayed string is the flatten string. */
24355 if (glyph
> row_start_glyph
)
24357 tmp_glyph
= glyph
- 1;
24358 while (tmp_glyph
>= row_start_glyph
24359 && tmp_glyph
->charpos
>= XINT (b
)
24360 && EQ (tmp_glyph
->object
, glyph
->object
))
24367 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
24368 displayed string holding GLYPH.
24370 GSEQ_LENGTH is different from SCHARS (STRING).
24371 SCHARS (STRING) returns the length of the internal string. */
24372 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
24373 tmp_glyph
->charpos
< XINT (e
);
24374 tmp_glyph
++, gseq_length
++)
24376 if (!EQ (tmp_glyph
->object
, glyph
->object
))
24380 total_pixel_width
= 0;
24381 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
24382 total_pixel_width
+= tmp_glyph
->pixel_width
;
24384 /* Pre calculation of re-rendering position */
24386 hpos
= (area
== ON_MODE_LINE
24387 ? (w
->current_matrix
)->nrows
- 1
24390 /* If the re-rendering position is included in the last
24391 re-rendering area, we should do nothing. */
24392 if ( EQ (window
, dpyinfo
->mouse_face_window
)
24393 && dpyinfo
->mouse_face_beg_col
<= vpos
24394 && vpos
< dpyinfo
->mouse_face_end_col
24395 && dpyinfo
->mouse_face_beg_row
== hpos
)
24398 if (clear_mouse_face (dpyinfo
))
24399 cursor
= No_Cursor
;
24401 dpyinfo
->mouse_face_beg_col
= vpos
;
24402 dpyinfo
->mouse_face_beg_row
= hpos
;
24404 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
24405 dpyinfo
->mouse_face_beg_y
= 0;
24407 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
24408 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
24410 dpyinfo
->mouse_face_end_x
= 0;
24411 dpyinfo
->mouse_face_end_y
= 0;
24413 dpyinfo
->mouse_face_past_end
= 0;
24414 dpyinfo
->mouse_face_window
= window
;
24416 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
24419 glyph
->face_id
, 1);
24420 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24422 if (NILP (pointer
))
24425 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24426 clear_mouse_face (dpyinfo
);
24428 define_frame_cursor1 (f
, cursor
, pointer
);
24433 Take proper action when the mouse has moved to position X, Y on
24434 frame F as regards highlighting characters that have mouse-face
24435 properties. Also de-highlighting chars where the mouse was before.
24436 X and Y can be negative or out of range. */
24439 note_mouse_highlight (f
, x
, y
)
24443 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24444 enum window_part part
;
24445 Lisp_Object window
;
24447 Cursor cursor
= No_Cursor
;
24448 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
24451 /* When a menu is active, don't highlight because this looks odd. */
24452 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
24453 if (popup_activated ())
24457 if (NILP (Vmouse_highlight
)
24458 || !f
->glyphs_initialized_p
)
24461 dpyinfo
->mouse_face_mouse_x
= x
;
24462 dpyinfo
->mouse_face_mouse_y
= y
;
24463 dpyinfo
->mouse_face_mouse_frame
= f
;
24465 if (dpyinfo
->mouse_face_defer
)
24468 if (gc_in_progress
)
24470 dpyinfo
->mouse_face_deferred_gc
= 1;
24474 /* Which window is that in? */
24475 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
24477 /* If we were displaying active text in another window, clear that.
24478 Also clear if we move out of text area in same window. */
24479 if (! EQ (window
, dpyinfo
->mouse_face_window
)
24480 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
24481 && !NILP (dpyinfo
->mouse_face_window
)))
24482 clear_mouse_face (dpyinfo
);
24484 /* Not on a window -> return. */
24485 if (!WINDOWP (window
))
24488 /* Reset help_echo_string. It will get recomputed below. */
24489 help_echo_string
= Qnil
;
24491 /* Convert to window-relative pixel coordinates. */
24492 w
= XWINDOW (window
);
24493 frame_to_window_pixel_xy (w
, &x
, &y
);
24495 /* Handle tool-bar window differently since it doesn't display a
24497 if (EQ (window
, f
->tool_bar_window
))
24499 note_tool_bar_highlight (f
, x
, y
);
24503 /* Mouse is on the mode, header line or margin? */
24504 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
24505 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
24507 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
24511 if (part
== ON_VERTICAL_BORDER
)
24513 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24514 help_echo_string
= build_string ("drag-mouse-1: resize");
24516 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
24517 || part
== ON_SCROLL_BAR
)
24518 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24520 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24522 /* Are we in a window whose display is up to date?
24523 And verify the buffer's text has not changed. */
24524 b
= XBUFFER (w
->buffer
);
24525 if (part
== ON_TEXT
24526 && EQ (w
->window_end_valid
, w
->buffer
)
24527 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
24528 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
24530 int hpos
, vpos
, i
, dx
, dy
, area
;
24532 struct glyph
*glyph
;
24533 Lisp_Object object
;
24534 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
24535 Lisp_Object
*overlay_vec
= NULL
;
24537 struct buffer
*obuf
;
24538 int obegv
, ozv
, same_region
;
24540 /* Find the glyph under X/Y. */
24541 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
24543 /* Look for :pointer property on image. */
24544 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24546 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24547 if (img
!= NULL
&& IMAGEP (img
->spec
))
24549 Lisp_Object image_map
, hotspot
;
24550 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
24552 && (hotspot
= find_hot_spot (image_map
,
24553 glyph
->slice
.x
+ dx
,
24554 glyph
->slice
.y
+ dy
),
24556 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24558 Lisp_Object area_id
, plist
;
24560 area_id
= XCAR (hotspot
);
24561 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24562 If so, we could look for mouse-enter, mouse-leave
24563 properties in PLIST (and do something...). */
24564 hotspot
= XCDR (hotspot
);
24565 if (CONSP (hotspot
)
24566 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24568 pointer
= Fplist_get (plist
, Qpointer
);
24569 if (NILP (pointer
))
24571 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
24572 if (!NILP (help_echo_string
))
24574 help_echo_window
= window
;
24575 help_echo_object
= glyph
->object
;
24576 help_echo_pos
= glyph
->charpos
;
24580 if (NILP (pointer
))
24581 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
24585 /* Clear mouse face if X/Y not over text. */
24587 || area
!= TEXT_AREA
24588 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
24590 if (clear_mouse_face (dpyinfo
))
24591 cursor
= No_Cursor
;
24592 if (NILP (pointer
))
24594 if (area
!= TEXT_AREA
)
24595 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24597 pointer
= Vvoid_text_area_pointer
;
24602 pos
= glyph
->charpos
;
24603 object
= glyph
->object
;
24604 if (!STRINGP (object
) && !BUFFERP (object
))
24607 /* If we get an out-of-range value, return now; avoid an error. */
24608 if (BUFFERP (object
) && pos
> BUF_Z (b
))
24611 /* Make the window's buffer temporarily current for
24612 overlays_at and compute_char_face. */
24613 obuf
= current_buffer
;
24614 current_buffer
= b
;
24620 /* Is this char mouse-active or does it have help-echo? */
24621 position
= make_number (pos
);
24623 if (BUFFERP (object
))
24625 /* Put all the overlays we want in a vector in overlay_vec. */
24626 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
24627 /* Sort overlays into increasing priority order. */
24628 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
24633 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
24634 && vpos
>= dpyinfo
->mouse_face_beg_row
24635 && vpos
<= dpyinfo
->mouse_face_end_row
24636 && (vpos
> dpyinfo
->mouse_face_beg_row
24637 || hpos
>= dpyinfo
->mouse_face_beg_col
)
24638 && (vpos
< dpyinfo
->mouse_face_end_row
24639 || hpos
< dpyinfo
->mouse_face_end_col
24640 || dpyinfo
->mouse_face_past_end
));
24643 cursor
= No_Cursor
;
24645 /* Check mouse-face highlighting. */
24647 /* If there exists an overlay with mouse-face overlapping
24648 the one we are currently highlighting, we have to
24649 check if we enter the overlapping overlay, and then
24650 highlight only that. */
24651 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
24652 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
24654 /* Find the highest priority overlay with a mouse-face. */
24656 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
24658 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
24659 if (!NILP (mouse_face
))
24660 overlay
= overlay_vec
[i
];
24663 /* If we're highlighting the same overlay as before, there's
24664 no need to do that again. */
24665 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
24666 goto check_help_echo
;
24667 dpyinfo
->mouse_face_overlay
= overlay
;
24669 /* Clear the display of the old active region, if any. */
24670 if (clear_mouse_face (dpyinfo
))
24671 cursor
= No_Cursor
;
24673 /* If no overlay applies, get a text property. */
24674 if (NILP (overlay
))
24675 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
24677 /* Next, compute the bounds of the mouse highlighting and
24679 if (!NILP (mouse_face
) && STRINGP (object
))
24681 /* The mouse-highlighting comes from a display string
24682 with a mouse-face. */
24686 b
= Fprevious_single_property_change
24687 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
24688 e
= Fnext_single_property_change
24689 (position
, Qmouse_face
, object
, Qnil
);
24691 b
= make_number (0);
24693 e
= make_number (SCHARS (object
) - 1);
24695 fast_find_string_pos (w
, XINT (b
), object
,
24696 &dpyinfo
->mouse_face_beg_col
,
24697 &dpyinfo
->mouse_face_beg_row
,
24698 &dpyinfo
->mouse_face_beg_x
,
24699 &dpyinfo
->mouse_face_beg_y
, 0);
24700 fast_find_string_pos (w
, XINT (e
), object
,
24701 &dpyinfo
->mouse_face_end_col
,
24702 &dpyinfo
->mouse_face_end_row
,
24703 &dpyinfo
->mouse_face_end_x
,
24704 &dpyinfo
->mouse_face_end_y
, 1);
24705 dpyinfo
->mouse_face_past_end
= 0;
24706 dpyinfo
->mouse_face_window
= window
;
24707 dpyinfo
->mouse_face_face_id
24708 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
24709 glyph
->face_id
, 1);
24710 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24711 cursor
= No_Cursor
;
24715 /* The mouse-highlighting, if any, comes from an overlay
24716 or text property in the buffer. */
24717 Lisp_Object buffer
, display_string
;
24719 if (STRINGP (object
))
24721 /* If we are on a display string with no mouse-face,
24722 check if the text under it has one. */
24723 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
24724 int start
= MATRIX_ROW_START_CHARPOS (r
);
24725 pos
= string_buffer_position (w
, object
, start
);
24728 mouse_face
= get_char_property_and_overlay
24729 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
24730 buffer
= w
->buffer
;
24731 display_string
= object
;
24737 display_string
= Qnil
;
24740 if (!NILP (mouse_face
))
24742 Lisp_Object before
, after
;
24743 Lisp_Object before_string
, after_string
;
24745 if (NILP (overlay
))
24747 /* Handle the text property case. */
24748 before
= Fprevious_single_property_change
24749 (make_number (pos
+ 1), Qmouse_face
, buffer
,
24750 Fmarker_position (w
->start
));
24751 after
= Fnext_single_property_change
24752 (make_number (pos
), Qmouse_face
, buffer
,
24753 make_number (BUF_Z (XBUFFER (buffer
))
24754 - XFASTINT (w
->window_end_pos
)));
24755 before_string
= after_string
= Qnil
;
24759 /* Handle the overlay case. */
24760 before
= Foverlay_start (overlay
);
24761 after
= Foverlay_end (overlay
);
24762 before_string
= Foverlay_get (overlay
, Qbefore_string
);
24763 after_string
= Foverlay_get (overlay
, Qafter_string
);
24765 if (!STRINGP (before_string
)) before_string
= Qnil
;
24766 if (!STRINGP (after_string
)) after_string
= Qnil
;
24769 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
24772 before_string
, after_string
,
24774 cursor
= No_Cursor
;
24781 /* Look for a `help-echo' property. */
24782 if (NILP (help_echo_string
)) {
24783 Lisp_Object help
, overlay
;
24785 /* Check overlays first. */
24786 help
= overlay
= Qnil
;
24787 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
24789 overlay
= overlay_vec
[i
];
24790 help
= Foverlay_get (overlay
, Qhelp_echo
);
24795 help_echo_string
= help
;
24796 help_echo_window
= window
;
24797 help_echo_object
= overlay
;
24798 help_echo_pos
= pos
;
24802 Lisp_Object object
= glyph
->object
;
24803 int charpos
= glyph
->charpos
;
24805 /* Try text properties. */
24806 if (STRINGP (object
)
24808 && charpos
< SCHARS (object
))
24810 help
= Fget_text_property (make_number (charpos
),
24811 Qhelp_echo
, object
);
24814 /* If the string itself doesn't specify a help-echo,
24815 see if the buffer text ``under'' it does. */
24816 struct glyph_row
*r
24817 = MATRIX_ROW (w
->current_matrix
, vpos
);
24818 int start
= MATRIX_ROW_START_CHARPOS (r
);
24819 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
24822 help
= Fget_char_property (make_number (pos
),
24823 Qhelp_echo
, w
->buffer
);
24827 object
= w
->buffer
;
24832 else if (BUFFERP (object
)
24835 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
24840 help_echo_string
= help
;
24841 help_echo_window
= window
;
24842 help_echo_object
= object
;
24843 help_echo_pos
= charpos
;
24848 /* Look for a `pointer' property. */
24849 if (NILP (pointer
))
24851 /* Check overlays first. */
24852 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
24853 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
24855 if (NILP (pointer
))
24857 Lisp_Object object
= glyph
->object
;
24858 int charpos
= glyph
->charpos
;
24860 /* Try text properties. */
24861 if (STRINGP (object
)
24863 && charpos
< SCHARS (object
))
24865 pointer
= Fget_text_property (make_number (charpos
),
24867 if (NILP (pointer
))
24869 /* If the string itself doesn't specify a pointer,
24870 see if the buffer text ``under'' it does. */
24871 struct glyph_row
*r
24872 = MATRIX_ROW (w
->current_matrix
, vpos
);
24873 int start
= MATRIX_ROW_START_CHARPOS (r
);
24874 EMACS_INT pos
= string_buffer_position (w
, object
,
24877 pointer
= Fget_char_property (make_number (pos
),
24878 Qpointer
, w
->buffer
);
24881 else if (BUFFERP (object
)
24884 pointer
= Fget_text_property (make_number (charpos
),
24891 current_buffer
= obuf
;
24896 define_frame_cursor1 (f
, cursor
, pointer
);
24901 Clear any mouse-face on window W. This function is part of the
24902 redisplay interface, and is called from try_window_id and similar
24903 functions to ensure the mouse-highlight is off. */
24906 x_clear_window_mouse_face (w
)
24909 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24910 Lisp_Object window
;
24913 XSETWINDOW (window
, w
);
24914 if (EQ (window
, dpyinfo
->mouse_face_window
))
24915 clear_mouse_face (dpyinfo
);
24921 Just discard the mouse face information for frame F, if any.
24922 This is used when the size of F is changed. */
24925 cancel_mouse_face (f
)
24928 Lisp_Object window
;
24929 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24931 window
= dpyinfo
->mouse_face_window
;
24932 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24934 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24935 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24936 dpyinfo
->mouse_face_window
= Qnil
;
24941 #endif /* HAVE_WINDOW_SYSTEM */
24944 /***********************************************************************
24946 ***********************************************************************/
24948 #ifdef HAVE_WINDOW_SYSTEM
24950 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24951 which intersects rectangle R. R is in window-relative coordinates. */
24954 expose_area (w
, row
, r
, area
)
24956 struct glyph_row
*row
;
24958 enum glyph_row_area area
;
24960 struct glyph
*first
= row
->glyphs
[area
];
24961 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24962 struct glyph
*last
;
24963 int first_x
, start_x
, x
;
24965 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24966 /* If row extends face to end of line write the whole line. */
24967 draw_glyphs (w
, 0, row
, area
,
24968 0, row
->used
[area
],
24969 DRAW_NORMAL_TEXT
, 0);
24972 /* Set START_X to the window-relative start position for drawing glyphs of
24973 AREA. The first glyph of the text area can be partially visible.
24974 The first glyphs of other areas cannot. */
24975 start_x
= window_box_left_offset (w
, area
);
24977 if (area
== TEXT_AREA
)
24980 /* Find the first glyph that must be redrawn. */
24982 && x
+ first
->pixel_width
< r
->x
)
24984 x
+= first
->pixel_width
;
24988 /* Find the last one. */
24992 && x
< r
->x
+ r
->width
)
24994 x
+= last
->pixel_width
;
25000 draw_glyphs (w
, first_x
- start_x
, row
, area
,
25001 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
25002 DRAW_NORMAL_TEXT
, 0);
25007 /* Redraw the parts of the glyph row ROW on window W intersecting
25008 rectangle R. R is in window-relative coordinates. Value is
25009 non-zero if mouse-face was overwritten. */
25012 expose_line (w
, row
, r
)
25014 struct glyph_row
*row
;
25017 xassert (row
->enabled_p
);
25019 if (row
->mode_line_p
|| w
->pseudo_window_p
)
25020 draw_glyphs (w
, 0, row
, TEXT_AREA
,
25021 0, row
->used
[TEXT_AREA
],
25022 DRAW_NORMAL_TEXT
, 0);
25025 if (row
->used
[LEFT_MARGIN_AREA
])
25026 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
25027 if (row
->used
[TEXT_AREA
])
25028 expose_area (w
, row
, r
, TEXT_AREA
);
25029 if (row
->used
[RIGHT_MARGIN_AREA
])
25030 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
25031 draw_row_fringe_bitmaps (w
, row
);
25034 return row
->mouse_face_p
;
25038 /* Redraw those parts of glyphs rows during expose event handling that
25039 overlap other rows. Redrawing of an exposed line writes over parts
25040 of lines overlapping that exposed line; this function fixes that.
25042 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
25043 row in W's current matrix that is exposed and overlaps other rows.
25044 LAST_OVERLAPPING_ROW is the last such row. */
25047 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
25049 struct glyph_row
*first_overlapping_row
;
25050 struct glyph_row
*last_overlapping_row
;
25053 struct glyph_row
*row
;
25055 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
25056 if (row
->overlapping_p
)
25058 xassert (row
->enabled_p
&& !row
->mode_line_p
);
25061 if (row
->used
[LEFT_MARGIN_AREA
])
25062 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
25064 if (row
->used
[TEXT_AREA
])
25065 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
25067 if (row
->used
[RIGHT_MARGIN_AREA
])
25068 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
25074 /* Return non-zero if W's cursor intersects rectangle R. */
25077 phys_cursor_in_rect_p (w
, r
)
25081 XRectangle cr
, result
;
25082 struct glyph
*cursor_glyph
;
25083 struct glyph_row
*row
;
25085 if (w
->phys_cursor
.vpos
>= 0
25086 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
25087 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
25089 && row
->cursor_in_fringe_p
)
25091 /* Cursor is in the fringe. */
25092 cr
.x
= window_box_right_offset (w
,
25093 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
25094 ? RIGHT_MARGIN_AREA
25097 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
25098 cr
.height
= row
->height
;
25099 return x_intersect_rectangles (&cr
, r
, &result
);
25102 cursor_glyph
= get_phys_cursor_glyph (w
);
25105 /* r is relative to W's box, but w->phys_cursor.x is relative
25106 to left edge of W's TEXT area. Adjust it. */
25107 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
25108 cr
.y
= w
->phys_cursor
.y
;
25109 cr
.width
= cursor_glyph
->pixel_width
;
25110 cr
.height
= w
->phys_cursor_height
;
25111 /* ++KFS: W32 version used W32-specific IntersectRect here, but
25112 I assume the effect is the same -- and this is portable. */
25113 return x_intersect_rectangles (&cr
, r
, &result
);
25115 /* If we don't understand the format, pretend we're not in the hot-spot. */
25121 Draw a vertical window border to the right of window W if W doesn't
25122 have vertical scroll bars. */
25125 x_draw_vertical_border (w
)
25128 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25130 /* We could do better, if we knew what type of scroll-bar the adjacent
25131 windows (on either side) have... But we don't :-(
25132 However, I think this works ok. ++KFS 2003-04-25 */
25134 /* Redraw borders between horizontally adjacent windows. Don't
25135 do it for frames with vertical scroll bars because either the
25136 right scroll bar of a window, or the left scroll bar of its
25137 neighbor will suffice as a border. */
25138 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
25141 if (!WINDOW_RIGHTMOST_P (w
)
25142 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
25144 int x0
, x1
, y0
, y1
;
25146 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
25149 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
25152 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
25154 else if (!WINDOW_LEFTMOST_P (w
)
25155 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
25157 int x0
, x1
, y0
, y1
;
25159 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
25162 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
25165 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
25170 /* Redraw the part of window W intersection rectangle FR. Pixel
25171 coordinates in FR are frame-relative. Call this function with
25172 input blocked. Value is non-zero if the exposure overwrites
25176 expose_window (w
, fr
)
25180 struct frame
*f
= XFRAME (w
->frame
);
25182 int mouse_face_overwritten_p
= 0;
25184 /* If window is not yet fully initialized, do nothing. This can
25185 happen when toolkit scroll bars are used and a window is split.
25186 Reconfiguring the scroll bar will generate an expose for a newly
25188 if (w
->current_matrix
== NULL
)
25191 /* When we're currently updating the window, display and current
25192 matrix usually don't agree. Arrange for a thorough display
25194 if (w
== updated_window
)
25196 SET_FRAME_GARBAGED (f
);
25200 /* Frame-relative pixel rectangle of W. */
25201 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
25202 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
25203 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
25204 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
25206 if (x_intersect_rectangles (fr
, &wr
, &r
))
25208 int yb
= window_text_bottom_y (w
);
25209 struct glyph_row
*row
;
25210 int cursor_cleared_p
;
25211 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
25213 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
25214 r
.x
, r
.y
, r
.width
, r
.height
));
25216 /* Convert to window coordinates. */
25217 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
25218 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
25220 /* Turn off the cursor. */
25221 if (!w
->pseudo_window_p
25222 && phys_cursor_in_rect_p (w
, &r
))
25224 x_clear_cursor (w
);
25225 cursor_cleared_p
= 1;
25228 cursor_cleared_p
= 0;
25230 /* Update lines intersecting rectangle R. */
25231 first_overlapping_row
= last_overlapping_row
= NULL
;
25232 for (row
= w
->current_matrix
->rows
;
25237 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
25239 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
25240 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
25241 || (r
.y
>= y0
&& r
.y
< y1
)
25242 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
25244 /* A header line may be overlapping, but there is no need
25245 to fix overlapping areas for them. KFS 2005-02-12 */
25246 if (row
->overlapping_p
&& !row
->mode_line_p
)
25248 if (first_overlapping_row
== NULL
)
25249 first_overlapping_row
= row
;
25250 last_overlapping_row
= row
;
25254 if (expose_line (w
, row
, &r
))
25255 mouse_face_overwritten_p
= 1;
25258 else if (row
->overlapping_p
)
25260 /* We must redraw a row overlapping the exposed area. */
25262 ? y0
+ row
->phys_height
> r
.y
25263 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
25265 if (first_overlapping_row
== NULL
)
25266 first_overlapping_row
= row
;
25267 last_overlapping_row
= row
;
25275 /* Display the mode line if there is one. */
25276 if (WINDOW_WANTS_MODELINE_P (w
)
25277 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
25279 && row
->y
< r
.y
+ r
.height
)
25281 if (expose_line (w
, row
, &r
))
25282 mouse_face_overwritten_p
= 1;
25285 if (!w
->pseudo_window_p
)
25287 /* Fix the display of overlapping rows. */
25288 if (first_overlapping_row
)
25289 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
25292 /* Draw border between windows. */
25293 x_draw_vertical_border (w
);
25295 /* Turn the cursor on again. */
25296 if (cursor_cleared_p
)
25297 update_window_cursor (w
, 1);
25301 return mouse_face_overwritten_p
;
25306 /* Redraw (parts) of all windows in the window tree rooted at W that
25307 intersect R. R contains frame pixel coordinates. Value is
25308 non-zero if the exposure overwrites mouse-face. */
25311 expose_window_tree (w
, r
)
25315 struct frame
*f
= XFRAME (w
->frame
);
25316 int mouse_face_overwritten_p
= 0;
25318 while (w
&& !FRAME_GARBAGED_P (f
))
25320 if (!NILP (w
->hchild
))
25321 mouse_face_overwritten_p
25322 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
25323 else if (!NILP (w
->vchild
))
25324 mouse_face_overwritten_p
25325 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
25327 mouse_face_overwritten_p
|= expose_window (w
, r
);
25329 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
25332 return mouse_face_overwritten_p
;
25337 Redisplay an exposed area of frame F. X and Y are the upper-left
25338 corner of the exposed rectangle. W and H are width and height of
25339 the exposed area. All are pixel values. W or H zero means redraw
25340 the entire frame. */
25343 expose_frame (f
, x
, y
, w
, h
)
25348 int mouse_face_overwritten_p
= 0;
25350 TRACE ((stderr
, "expose_frame "));
25352 /* No need to redraw if frame will be redrawn soon. */
25353 if (FRAME_GARBAGED_P (f
))
25355 TRACE ((stderr
, " garbaged\n"));
25359 /* If basic faces haven't been realized yet, there is no point in
25360 trying to redraw anything. This can happen when we get an expose
25361 event while Emacs is starting, e.g. by moving another window. */
25362 if (FRAME_FACE_CACHE (f
) == NULL
25363 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
25365 TRACE ((stderr
, " no faces\n"));
25369 if (w
== 0 || h
== 0)
25372 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
25373 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
25383 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
25384 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
25386 if (WINDOWP (f
->tool_bar_window
))
25387 mouse_face_overwritten_p
25388 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
25390 #ifdef HAVE_X_WINDOWS
25392 #ifndef USE_X_TOOLKIT
25393 if (WINDOWP (f
->menu_bar_window
))
25394 mouse_face_overwritten_p
25395 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
25396 #endif /* not USE_X_TOOLKIT */
25400 /* Some window managers support a focus-follows-mouse style with
25401 delayed raising of frames. Imagine a partially obscured frame,
25402 and moving the mouse into partially obscured mouse-face on that
25403 frame. The visible part of the mouse-face will be highlighted,
25404 then the WM raises the obscured frame. With at least one WM, KDE
25405 2.1, Emacs is not getting any event for the raising of the frame
25406 (even tried with SubstructureRedirectMask), only Expose events.
25407 These expose events will draw text normally, i.e. not
25408 highlighted. Which means we must redo the highlight here.
25409 Subsume it under ``we love X''. --gerd 2001-08-15 */
25410 /* Included in Windows version because Windows most likely does not
25411 do the right thing if any third party tool offers
25412 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
25413 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
25415 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25416 if (f
== dpyinfo
->mouse_face_mouse_frame
)
25418 int x
= dpyinfo
->mouse_face_mouse_x
;
25419 int y
= dpyinfo
->mouse_face_mouse_y
;
25420 clear_mouse_face (dpyinfo
);
25421 note_mouse_highlight (f
, x
, y
);
25428 Determine the intersection of two rectangles R1 and R2. Return
25429 the intersection in *RESULT. Value is non-zero if RESULT is not
25433 x_intersect_rectangles (r1
, r2
, result
)
25434 XRectangle
*r1
, *r2
, *result
;
25436 XRectangle
*left
, *right
;
25437 XRectangle
*upper
, *lower
;
25438 int intersection_p
= 0;
25440 /* Rearrange so that R1 is the left-most rectangle. */
25442 left
= r1
, right
= r2
;
25444 left
= r2
, right
= r1
;
25446 /* X0 of the intersection is right.x0, if this is inside R1,
25447 otherwise there is no intersection. */
25448 if (right
->x
<= left
->x
+ left
->width
)
25450 result
->x
= right
->x
;
25452 /* The right end of the intersection is the minimum of the
25453 the right ends of left and right. */
25454 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
25457 /* Same game for Y. */
25459 upper
= r1
, lower
= r2
;
25461 upper
= r2
, lower
= r1
;
25463 /* The upper end of the intersection is lower.y0, if this is inside
25464 of upper. Otherwise, there is no intersection. */
25465 if (lower
->y
<= upper
->y
+ upper
->height
)
25467 result
->y
= lower
->y
;
25469 /* The lower end of the intersection is the minimum of the lower
25470 ends of upper and lower. */
25471 result
->height
= (min (lower
->y
+ lower
->height
,
25472 upper
->y
+ upper
->height
)
25474 intersection_p
= 1;
25478 return intersection_p
;
25481 #endif /* HAVE_WINDOW_SYSTEM */
25484 /***********************************************************************
25486 ***********************************************************************/
25491 Vwith_echo_area_save_vector
= Qnil
;
25492 staticpro (&Vwith_echo_area_save_vector
);
25494 Vmessage_stack
= Qnil
;
25495 staticpro (&Vmessage_stack
);
25497 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
25498 staticpro (&Qinhibit_redisplay
);
25500 message_dolog_marker1
= Fmake_marker ();
25501 staticpro (&message_dolog_marker1
);
25502 message_dolog_marker2
= Fmake_marker ();
25503 staticpro (&message_dolog_marker2
);
25504 message_dolog_marker3
= Fmake_marker ();
25505 staticpro (&message_dolog_marker3
);
25508 defsubr (&Sdump_frame_glyph_matrix
);
25509 defsubr (&Sdump_glyph_matrix
);
25510 defsubr (&Sdump_glyph_row
);
25511 defsubr (&Sdump_tool_bar_row
);
25512 defsubr (&Strace_redisplay
);
25513 defsubr (&Strace_to_stderr
);
25515 #ifdef HAVE_WINDOW_SYSTEM
25516 defsubr (&Stool_bar_lines_needed
);
25517 defsubr (&Slookup_image_map
);
25519 defsubr (&Sformat_mode_line
);
25520 defsubr (&Sinvisible_p
);
25522 staticpro (&Qmenu_bar_update_hook
);
25523 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
25525 staticpro (&Qoverriding_terminal_local_map
);
25526 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
25528 staticpro (&Qoverriding_local_map
);
25529 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
25531 staticpro (&Qwindow_scroll_functions
);
25532 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
25534 staticpro (&Qwindow_text_change_functions
);
25535 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
25537 staticpro (&Qredisplay_end_trigger_functions
);
25538 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
25540 staticpro (&Qinhibit_point_motion_hooks
);
25541 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
25543 Qeval
= intern_c_string ("eval");
25544 staticpro (&Qeval
);
25546 QCdata
= intern_c_string (":data");
25547 staticpro (&QCdata
);
25548 Qdisplay
= intern_c_string ("display");
25549 staticpro (&Qdisplay
);
25550 Qspace_width
= intern_c_string ("space-width");
25551 staticpro (&Qspace_width
);
25552 Qraise
= intern_c_string ("raise");
25553 staticpro (&Qraise
);
25554 Qslice
= intern_c_string ("slice");
25555 staticpro (&Qslice
);
25556 Qspace
= intern_c_string ("space");
25557 staticpro (&Qspace
);
25558 Qmargin
= intern_c_string ("margin");
25559 staticpro (&Qmargin
);
25560 Qpointer
= intern_c_string ("pointer");
25561 staticpro (&Qpointer
);
25562 Qleft_margin
= intern_c_string ("left-margin");
25563 staticpro (&Qleft_margin
);
25564 Qright_margin
= intern_c_string ("right-margin");
25565 staticpro (&Qright_margin
);
25566 Qcenter
= intern_c_string ("center");
25567 staticpro (&Qcenter
);
25568 Qline_height
= intern_c_string ("line-height");
25569 staticpro (&Qline_height
);
25570 QCalign_to
= intern_c_string (":align-to");
25571 staticpro (&QCalign_to
);
25572 QCrelative_width
= intern_c_string (":relative-width");
25573 staticpro (&QCrelative_width
);
25574 QCrelative_height
= intern_c_string (":relative-height");
25575 staticpro (&QCrelative_height
);
25576 QCeval
= intern_c_string (":eval");
25577 staticpro (&QCeval
);
25578 QCpropertize
= intern_c_string (":propertize");
25579 staticpro (&QCpropertize
);
25580 QCfile
= intern_c_string (":file");
25581 staticpro (&QCfile
);
25582 Qfontified
= intern_c_string ("fontified");
25583 staticpro (&Qfontified
);
25584 Qfontification_functions
= intern_c_string ("fontification-functions");
25585 staticpro (&Qfontification_functions
);
25586 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
25587 staticpro (&Qtrailing_whitespace
);
25588 Qescape_glyph
= intern_c_string ("escape-glyph");
25589 staticpro (&Qescape_glyph
);
25590 Qnobreak_space
= intern_c_string ("nobreak-space");
25591 staticpro (&Qnobreak_space
);
25592 Qimage
= intern_c_string ("image");
25593 staticpro (&Qimage
);
25594 QCmap
= intern_c_string (":map");
25595 staticpro (&QCmap
);
25596 QCpointer
= intern_c_string (":pointer");
25597 staticpro (&QCpointer
);
25598 Qrect
= intern_c_string ("rect");
25599 staticpro (&Qrect
);
25600 Qcircle
= intern_c_string ("circle");
25601 staticpro (&Qcircle
);
25602 Qpoly
= intern_c_string ("poly");
25603 staticpro (&Qpoly
);
25604 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
25605 staticpro (&Qmessage_truncate_lines
);
25606 Qgrow_only
= intern_c_string ("grow-only");
25607 staticpro (&Qgrow_only
);
25608 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
25609 staticpro (&Qinhibit_menubar_update
);
25610 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
25611 staticpro (&Qinhibit_eval_during_redisplay
);
25612 Qposition
= intern_c_string ("position");
25613 staticpro (&Qposition
);
25614 Qbuffer_position
= intern_c_string ("buffer-position");
25615 staticpro (&Qbuffer_position
);
25616 Qobject
= intern_c_string ("object");
25617 staticpro (&Qobject
);
25618 Qbar
= intern_c_string ("bar");
25620 Qhbar
= intern_c_string ("hbar");
25621 staticpro (&Qhbar
);
25622 Qbox
= intern_c_string ("box");
25624 Qhollow
= intern_c_string ("hollow");
25625 staticpro (&Qhollow
);
25626 Qhand
= intern_c_string ("hand");
25627 staticpro (&Qhand
);
25628 Qarrow
= intern_c_string ("arrow");
25629 staticpro (&Qarrow
);
25630 Qtext
= intern_c_string ("text");
25631 staticpro (&Qtext
);
25632 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
25633 staticpro (&Qrisky_local_variable
);
25634 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
25635 staticpro (&Qinhibit_free_realized_faces
);
25637 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
25638 Fcons (intern_c_string ("void-variable"), Qnil
)),
25640 staticpro (&list_of_error
);
25642 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
25643 staticpro (&Qlast_arrow_position
);
25644 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
25645 staticpro (&Qlast_arrow_string
);
25647 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
25648 staticpro (&Qoverlay_arrow_string
);
25649 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
25650 staticpro (&Qoverlay_arrow_bitmap
);
25652 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
25653 staticpro (&echo_buffer
[0]);
25654 staticpro (&echo_buffer
[1]);
25656 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
25657 staticpro (&echo_area_buffer
[0]);
25658 staticpro (&echo_area_buffer
[1]);
25660 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
25661 staticpro (&Vmessages_buffer_name
);
25663 mode_line_proptrans_alist
= Qnil
;
25664 staticpro (&mode_line_proptrans_alist
);
25665 mode_line_string_list
= Qnil
;
25666 staticpro (&mode_line_string_list
);
25667 mode_line_string_face
= Qnil
;
25668 staticpro (&mode_line_string_face
);
25669 mode_line_string_face_prop
= Qnil
;
25670 staticpro (&mode_line_string_face_prop
);
25671 Vmode_line_unwind_vector
= Qnil
;
25672 staticpro (&Vmode_line_unwind_vector
);
25674 help_echo_string
= Qnil
;
25675 staticpro (&help_echo_string
);
25676 help_echo_object
= Qnil
;
25677 staticpro (&help_echo_object
);
25678 help_echo_window
= Qnil
;
25679 staticpro (&help_echo_window
);
25680 previous_help_echo_string
= Qnil
;
25681 staticpro (&previous_help_echo_string
);
25682 help_echo_pos
= -1;
25684 Qright_to_left
= intern ("right-to-left");
25685 staticpro (&Qright_to_left
);
25686 Qleft_to_right
= intern ("left-to-right");
25687 staticpro (&Qleft_to_right
);
25689 #ifdef HAVE_WINDOW_SYSTEM
25690 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
25691 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
25692 For example, if a block cursor is over a tab, it will be drawn as
25693 wide as that tab on the display. */);
25694 x_stretch_cursor_p
= 0;
25697 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
25698 doc
: /* *Non-nil means highlight trailing whitespace.
25699 The face used for trailing whitespace is `trailing-whitespace'. */);
25700 Vshow_trailing_whitespace
= Qnil
;
25702 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
25703 doc
: /* *Control highlighting of nobreak space and soft hyphen.
25704 A value of t means highlight the character itself (for nobreak space,
25705 use face `nobreak-space').
25706 A value of nil means no highlighting.
25707 Other values mean display the escape glyph followed by an ordinary
25708 space or ordinary hyphen. */);
25709 Vnobreak_char_display
= Qt
;
25711 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
25712 doc
: /* *The pointer shape to show in void text areas.
25713 A value of nil means to show the text pointer. Other options are `arrow',
25714 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
25715 Vvoid_text_area_pointer
= Qarrow
;
25717 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
25718 doc
: /* Non-nil means don't actually do any redisplay.
25719 This is used for internal purposes. */);
25720 Vinhibit_redisplay
= Qnil
;
25722 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
25723 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
25724 Vglobal_mode_string
= Qnil
;
25726 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
25727 doc
: /* Marker for where to display an arrow on top of the buffer text.
25728 This must be the beginning of a line in order to work.
25729 See also `overlay-arrow-string'. */);
25730 Voverlay_arrow_position
= Qnil
;
25732 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
25733 doc
: /* String to display as an arrow in non-window frames.
25734 See also `overlay-arrow-position'. */);
25735 Voverlay_arrow_string
= make_pure_c_string ("=>");
25737 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
25738 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
25739 The symbols on this list are examined during redisplay to determine
25740 where to display overlay arrows. */);
25741 Voverlay_arrow_variable_list
25742 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
25744 DEFVAR_INT ("scroll-step", &scroll_step
,
25745 doc
: /* *The number of lines to try scrolling a window by when point moves out.
25746 If that fails to bring point back on frame, point is centered instead.
25747 If this is zero, point is always centered after it moves off frame.
25748 If you want scrolling to always be a line at a time, you should set
25749 `scroll-conservatively' to a large value rather than set this to 1. */);
25751 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
25752 doc
: /* *Scroll up to this many lines, to bring point back on screen.
25753 If point moves off-screen, redisplay will scroll by up to
25754 `scroll-conservatively' lines in order to bring point just barely
25755 onto the screen again. If that cannot be done, then redisplay
25756 recenters point as usual.
25758 A value of zero means always recenter point if it moves off screen. */);
25759 scroll_conservatively
= 0;
25761 DEFVAR_INT ("scroll-margin", &scroll_margin
,
25762 doc
: /* *Number of lines of margin at the top and bottom of a window.
25763 Recenter the window whenever point gets within this many lines
25764 of the top or bottom of the window. */);
25767 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
25768 doc
: /* Pixels per inch value for non-window system displays.
25769 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
25770 Vdisplay_pixels_per_inch
= make_float (72.0);
25773 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
25776 DEFVAR_LISP ("truncate-partial-width-windows",
25777 &Vtruncate_partial_width_windows
,
25778 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
25779 For an integer value, truncate lines in each window narrower than the
25780 full frame width, provided the window width is less than that integer;
25781 otherwise, respect the value of `truncate-lines'.
25783 For any other non-nil value, truncate lines in all windows that do
25784 not span the full frame width.
25786 A value of nil means to respect the value of `truncate-lines'.
25788 If `word-wrap' is enabled, you might want to reduce this. */);
25789 Vtruncate_partial_width_windows
= make_number (50);
25791 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
25792 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
25793 Any other value means to use the appropriate face, `mode-line',
25794 `header-line', or `menu' respectively. */);
25795 mode_line_inverse_video
= 1;
25797 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
25798 doc
: /* *Maximum buffer size for which line number should be displayed.
25799 If the buffer is bigger than this, the line number does not appear
25800 in the mode line. A value of nil means no limit. */);
25801 Vline_number_display_limit
= Qnil
;
25803 DEFVAR_INT ("line-number-display-limit-width",
25804 &line_number_display_limit_width
,
25805 doc
: /* *Maximum line width (in characters) for line number display.
25806 If the average length of the lines near point is bigger than this, then the
25807 line number may be omitted from the mode line. */);
25808 line_number_display_limit_width
= 200;
25810 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
25811 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
25812 highlight_nonselected_windows
= 0;
25814 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
25815 doc
: /* Non-nil if more than one frame is visible on this display.
25816 Minibuffer-only frames don't count, but iconified frames do.
25817 This variable is not guaranteed to be accurate except while processing
25818 `frame-title-format' and `icon-title-format'. */);
25820 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
25821 doc
: /* Template for displaying the title bar of visible frames.
25822 \(Assuming the window manager supports this feature.)
25824 This variable has the same structure as `mode-line-format', except that
25825 the %c and %l constructs are ignored. It is used only on frames for
25826 which no explicit name has been set \(see `modify-frame-parameters'). */);
25828 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
25829 doc
: /* Template for displaying the title bar of an iconified frame.
25830 \(Assuming the window manager supports this feature.)
25831 This variable has the same structure as `mode-line-format' (which see),
25832 and is used only on frames for which no explicit name has been set
25833 \(see `modify-frame-parameters'). */);
25835 = Vframe_title_format
25836 = pure_cons (intern_c_string ("multiple-frames"),
25837 pure_cons (make_pure_c_string ("%b"),
25838 pure_cons (pure_cons (empty_unibyte_string
,
25839 pure_cons (intern_c_string ("invocation-name"),
25840 pure_cons (make_pure_c_string ("@"),
25841 pure_cons (intern_c_string ("system-name"),
25845 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
25846 doc
: /* Maximum number of lines to keep in the message log buffer.
25847 If nil, disable message logging. If t, log messages but don't truncate
25848 the buffer when it becomes large. */);
25849 Vmessage_log_max
= make_number (100);
25851 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
25852 doc
: /* Functions called before redisplay, if window sizes have changed.
25853 The value should be a list of functions that take one argument.
25854 Just before redisplay, for each frame, if any of its windows have changed
25855 size since the last redisplay, or have been split or deleted,
25856 all the functions in the list are called, with the frame as argument. */);
25857 Vwindow_size_change_functions
= Qnil
;
25859 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
25860 doc
: /* List of functions to call before redisplaying a window with scrolling.
25861 Each function is called with two arguments, the window and its new
25862 display-start position. Note that these functions are also called by
25863 `set-window-buffer'. Also note that the value of `window-end' is not
25864 valid when these functions are called. */);
25865 Vwindow_scroll_functions
= Qnil
;
25867 DEFVAR_LISP ("window-text-change-functions",
25868 &Vwindow_text_change_functions
,
25869 doc
: /* Functions to call in redisplay when text in the window might change. */);
25870 Vwindow_text_change_functions
= Qnil
;
25872 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
25873 doc
: /* Functions called when redisplay of a window reaches the end trigger.
25874 Each function is called with two arguments, the window and the end trigger value.
25875 See `set-window-redisplay-end-trigger'. */);
25876 Vredisplay_end_trigger_functions
= Qnil
;
25878 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25879 doc
: /* *Non-nil means autoselect window with mouse pointer.
25880 If nil, do not autoselect windows.
25881 A positive number means delay autoselection by that many seconds: a
25882 window is autoselected only after the mouse has remained in that
25883 window for the duration of the delay.
25884 A negative number has a similar effect, but causes windows to be
25885 autoselected only after the mouse has stopped moving. \(Because of
25886 the way Emacs compares mouse events, you will occasionally wait twice
25887 that time before the window gets selected.\)
25888 Any other value means to autoselect window instantaneously when the
25889 mouse pointer enters it.
25891 Autoselection selects the minibuffer only if it is active, and never
25892 unselects the minibuffer if it is active.
25894 When customizing this variable make sure that the actual value of
25895 `focus-follows-mouse' matches the behavior of your window manager. */);
25896 Vmouse_autoselect_window
= Qnil
;
25898 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25899 doc
: /* *Non-nil means automatically resize tool-bars.
25900 This dynamically changes the tool-bar's height to the minimum height
25901 that is needed to make all tool-bar items visible.
25902 If value is `grow-only', the tool-bar's height is only increased
25903 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25904 Vauto_resize_tool_bars
= Qt
;
25906 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25907 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25908 auto_raise_tool_bar_buttons_p
= 1;
25910 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25911 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25912 make_cursor_line_fully_visible_p
= 1;
25914 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25915 doc
: /* *Border below tool-bar in pixels.
25916 If an integer, use it as the height of the border.
25917 If it is one of `internal-border-width' or `border-width', use the
25918 value of the corresponding frame parameter.
25919 Otherwise, no border is added below the tool-bar. */);
25920 Vtool_bar_border
= Qinternal_border_width
;
25922 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25923 doc
: /* *Margin around tool-bar buttons in pixels.
25924 If an integer, use that for both horizontal and vertical margins.
25925 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25926 HORZ specifying the horizontal margin, and VERT specifying the
25927 vertical margin. */);
25928 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25930 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25931 doc
: /* *Relief thickness of tool-bar buttons. */);
25932 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25934 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25935 doc
: /* List of functions to call to fontify regions of text.
25936 Each function is called with one argument POS. Functions must
25937 fontify a region starting at POS in the current buffer, and give
25938 fontified regions the property `fontified'. */);
25939 Vfontification_functions
= Qnil
;
25940 Fmake_variable_buffer_local (Qfontification_functions
);
25942 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25943 &unibyte_display_via_language_environment
,
25944 doc
: /* *Non-nil means display unibyte text according to language environment.
25945 Specifically, this means that raw bytes in the range 160-255 decimal
25946 are displayed by converting them to the equivalent multibyte characters
25947 according to the current language environment. As a result, they are
25948 displayed according to the current fontset.
25950 Note that this variable affects only how these bytes are displayed,
25951 but does not change the fact they are interpreted as raw bytes. */);
25952 unibyte_display_via_language_environment
= 0;
25954 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25955 doc
: /* *Maximum height for resizing mini-windows.
25956 If a float, it specifies a fraction of the mini-window frame's height.
25957 If an integer, it specifies a number of lines. */);
25958 Vmax_mini_window_height
= make_float (0.25);
25960 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25961 doc
: /* *How to resize mini-windows.
25962 A value of nil means don't automatically resize mini-windows.
25963 A value of t means resize them to fit the text displayed in them.
25964 A value of `grow-only', the default, means let mini-windows grow
25965 only, until their display becomes empty, at which point the windows
25966 go back to their normal size. */);
25967 Vresize_mini_windows
= Qgrow_only
;
25969 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25970 doc
: /* Alist specifying how to blink the cursor off.
25971 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25972 `cursor-type' frame-parameter or variable equals ON-STATE,
25973 comparing using `equal', Emacs uses OFF-STATE to specify
25974 how to blink it off. ON-STATE and OFF-STATE are values for
25975 the `cursor-type' frame parameter.
25977 If a frame's ON-STATE has no entry in this list,
25978 the frame's other specifications determine how to blink the cursor off. */);
25979 Vblink_cursor_alist
= Qnil
;
25981 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25982 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25983 automatic_hscrolling_p
= 1;
25984 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
25985 staticpro (&Qauto_hscroll_mode
);
25987 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25988 doc
: /* *How many columns away from the window edge point is allowed to get
25989 before automatic hscrolling will horizontally scroll the window. */);
25990 hscroll_margin
= 5;
25992 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25993 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25994 When point is less than `hscroll-margin' columns from the window
25995 edge, automatic hscrolling will scroll the window by the amount of columns
25996 determined by this variable. If its value is a positive integer, scroll that
25997 many columns. If it's a positive floating-point number, it specifies the
25998 fraction of the window's width to scroll. If it's nil or zero, point will be
25999 centered horizontally after the scroll. Any other value, including negative
26000 numbers, are treated as if the value were zero.
26002 Automatic hscrolling always moves point outside the scroll margin, so if
26003 point was more than scroll step columns inside the margin, the window will
26004 scroll more than the value given by the scroll step.
26006 Note that the lower bound for automatic hscrolling specified by `scroll-left'
26007 and `scroll-right' overrides this variable's effect. */);
26008 Vhscroll_step
= make_number (0);
26010 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
26011 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
26012 Bind this around calls to `message' to let it take effect. */);
26013 message_truncate_lines
= 0;
26015 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
26016 doc
: /* Normal hook run to update the menu bar definitions.
26017 Redisplay runs this hook before it redisplays the menu bar.
26018 This is used to update submenus such as Buffers,
26019 whose contents depend on various data. */);
26020 Vmenu_bar_update_hook
= Qnil
;
26022 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
26023 doc
: /* Frame for which we are updating a menu.
26024 The enable predicate for a menu binding should check this variable. */);
26025 Vmenu_updating_frame
= Qnil
;
26027 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
26028 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
26029 inhibit_menubar_update
= 0;
26031 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
26032 doc
: /* Prefix prepended to all continuation lines at display time.
26033 The value may be a string, an image, or a stretch-glyph; it is
26034 interpreted in the same way as the value of a `display' text property.
26036 This variable is overridden by any `wrap-prefix' text or overlay
26039 To add a prefix to non-continuation lines, use `line-prefix'. */);
26040 Vwrap_prefix
= Qnil
;
26041 staticpro (&Qwrap_prefix
);
26042 Qwrap_prefix
= intern_c_string ("wrap-prefix");
26043 Fmake_variable_buffer_local (Qwrap_prefix
);
26045 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
26046 doc
: /* Prefix prepended to all non-continuation lines at display time.
26047 The value may be a string, an image, or a stretch-glyph; it is
26048 interpreted in the same way as the value of a `display' text property.
26050 This variable is overridden by any `line-prefix' text or overlay
26053 To add a prefix to continuation lines, use `wrap-prefix'. */);
26054 Vline_prefix
= Qnil
;
26055 staticpro (&Qline_prefix
);
26056 Qline_prefix
= intern_c_string ("line-prefix");
26057 Fmake_variable_buffer_local (Qline_prefix
);
26059 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
26060 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
26061 inhibit_eval_during_redisplay
= 0;
26063 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
26064 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
26065 inhibit_free_realized_faces
= 0;
26068 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
26069 doc
: /* Inhibit try_window_id display optimization. */);
26070 inhibit_try_window_id
= 0;
26072 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
26073 doc
: /* Inhibit try_window_reusing display optimization. */);
26074 inhibit_try_window_reusing
= 0;
26076 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
26077 doc
: /* Inhibit try_cursor_movement display optimization. */);
26078 inhibit_try_cursor_movement
= 0;
26079 #endif /* GLYPH_DEBUG */
26081 DEFVAR_INT ("overline-margin", &overline_margin
,
26082 doc
: /* *Space between overline and text, in pixels.
26083 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
26084 margin to the caracter height. */);
26085 overline_margin
= 2;
26087 DEFVAR_INT ("underline-minimum-offset",
26088 &underline_minimum_offset
,
26089 doc
: /* Minimum distance between baseline and underline.
26090 This can improve legibility of underlined text at small font sizes,
26091 particularly when using variable `x-use-underline-position-properties'
26092 with fonts that specify an UNDERLINE_POSITION relatively close to the
26093 baseline. The default value is 1. */);
26094 underline_minimum_offset
= 1;
26096 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
26097 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
26098 display_hourglass_p
= 1;
26100 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
26101 doc
: /* *Seconds to wait before displaying an hourglass pointer.
26102 Value must be an integer or float. */);
26103 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
26105 hourglass_atimer
= NULL
;
26106 hourglass_shown_p
= 0;
26110 /* Initialize this module when Emacs starts. */
26115 Lisp_Object root_window
;
26116 struct window
*mini_w
;
26118 current_header_line_height
= current_mode_line_height
= -1;
26120 CHARPOS (this_line_start_pos
) = 0;
26122 mini_w
= XWINDOW (minibuf_window
);
26123 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
26125 if (!noninteractive
)
26127 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
26130 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
26131 set_window_height (root_window
,
26132 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
26134 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
26135 set_window_height (minibuf_window
, 1, 0);
26137 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
26138 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
26140 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
26141 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
26142 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
26144 /* The default ellipsis glyphs `...'. */
26145 for (i
= 0; i
< 3; ++i
)
26146 default_invis_vector
[i
] = make_number ('.');
26150 /* Allocate the buffer for frame titles.
26151 Also used for `format-mode-line'. */
26153 mode_line_noprop_buf
= (char *) xmalloc (size
);
26154 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
26155 mode_line_noprop_ptr
= mode_line_noprop_buf
;
26156 mode_line_target
= MODE_LINE_DISPLAY
;
26159 help_echo_showing_p
= 0;
26162 /* Since w32 does not support atimers, it defines its own implementation of
26163 the following three functions in w32fns.c. */
26166 /* Platform-independent portion of hourglass implementation. */
26168 /* Return non-zero if houglass timer has been started or hourglass is shown. */
26170 hourglass_started ()
26172 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
26175 /* Cancel a currently active hourglass timer, and start a new one. */
26179 #if defined (HAVE_WINDOW_SYSTEM)
26181 int secs
, usecs
= 0;
26183 cancel_hourglass ();
26185 if (INTEGERP (Vhourglass_delay
)
26186 && XINT (Vhourglass_delay
) > 0)
26187 secs
= XFASTINT (Vhourglass_delay
);
26188 else if (FLOATP (Vhourglass_delay
)
26189 && XFLOAT_DATA (Vhourglass_delay
) > 0)
26192 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
26193 secs
= XFASTINT (tem
);
26194 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
26197 secs
= DEFAULT_HOURGLASS_DELAY
;
26199 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
26200 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
26201 show_hourglass
, NULL
);
26206 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
26209 cancel_hourglass ()
26211 #if defined (HAVE_WINDOW_SYSTEM)
26212 if (hourglass_atimer
)
26214 cancel_atimer (hourglass_atimer
);
26215 hourglass_atimer
= NULL
;
26218 if (hourglass_shown_p
)
26222 #endif /* ! WINDOWSNT */
26224 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
26225 (do not change this comment) */