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, int *));
960 static void display_menu_bar
P_ ((struct window
*));
961 static int display_count_lines
P_ ((int, int, int, int, int *));
962 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
963 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
964 static void compute_line_metrics
P_ ((struct it
*));
965 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
966 static int get_overlay_strings
P_ ((struct it
*, int));
967 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
968 static void next_overlay_string
P_ ((struct it
*));
969 static void reseat
P_ ((struct it
*, struct text_pos
, int));
970 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
971 static void back_to_previous_visible_line_start
P_ ((struct it
*));
972 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
973 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
974 static int next_element_from_ellipsis
P_ ((struct it
*));
975 static int next_element_from_display_vector
P_ ((struct it
*));
976 static int next_element_from_string
P_ ((struct it
*));
977 static int next_element_from_c_string
P_ ((struct it
*));
978 static int next_element_from_buffer
P_ ((struct it
*));
979 static int next_element_from_composition
P_ ((struct it
*));
980 static int next_element_from_image
P_ ((struct it
*));
981 static int next_element_from_stretch
P_ ((struct it
*));
982 static void load_overlay_strings
P_ ((struct it
*, int));
983 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
984 struct display_pos
*));
985 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
986 Lisp_Object
, int, int, int, int));
987 static enum move_it_result
988 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
989 enum move_operation_enum
);
990 void move_it_vertically_backward
P_ ((struct it
*, int));
991 static void init_to_row_start
P_ ((struct it
*, struct window
*,
992 struct glyph_row
*));
993 static int init_to_row_end
P_ ((struct it
*, struct window
*,
994 struct glyph_row
*));
995 static void back_to_previous_line_start
P_ ((struct it
*));
996 static int forward_to_next_line_start
P_ ((struct it
*, int *));
997 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
999 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
1000 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
1001 static int number_of_chars
P_ ((unsigned char *, int));
1002 static void compute_stop_pos
P_ ((struct it
*));
1003 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
1005 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1006 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1007 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1008 Lisp_Object
, Lisp_Object
,
1009 struct text_pos
*, int));
1010 static int underlying_face_id
P_ ((struct it
*));
1011 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1014 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1015 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1017 #ifdef HAVE_WINDOW_SYSTEM
1019 static void update_tool_bar
P_ ((struct frame
*, int));
1020 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1021 static int redisplay_tool_bar
P_ ((struct frame
*));
1022 static void display_tool_bar_line
P_ ((struct it
*, int));
1023 static void notice_overwritten_cursor
P_ ((struct window
*,
1024 enum glyph_row_area
,
1025 int, int, int, int));
1029 #endif /* HAVE_WINDOW_SYSTEM */
1032 /***********************************************************************
1033 Window display dimensions
1034 ***********************************************************************/
1036 /* Return the bottom boundary y-position for text lines in window W.
1037 This is the first y position at which a line cannot start.
1038 It is relative to the top of the window.
1040 This is the height of W minus the height of a mode line, if any. */
1043 window_text_bottom_y (w
)
1046 int height
= WINDOW_TOTAL_HEIGHT (w
);
1048 if (WINDOW_WANTS_MODELINE_P (w
))
1049 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1053 /* Return the pixel width of display area AREA of window W. AREA < 0
1054 means return the total width of W, not including fringes to
1055 the left and right of the window. */
1058 window_box_width (w
, area
)
1062 int cols
= XFASTINT (w
->total_cols
);
1065 if (!w
->pseudo_window_p
)
1067 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1069 if (area
== TEXT_AREA
)
1071 if (INTEGERP (w
->left_margin_cols
))
1072 cols
-= XFASTINT (w
->left_margin_cols
);
1073 if (INTEGERP (w
->right_margin_cols
))
1074 cols
-= XFASTINT (w
->right_margin_cols
);
1075 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1077 else if (area
== LEFT_MARGIN_AREA
)
1079 cols
= (INTEGERP (w
->left_margin_cols
)
1080 ? XFASTINT (w
->left_margin_cols
) : 0);
1083 else if (area
== RIGHT_MARGIN_AREA
)
1085 cols
= (INTEGERP (w
->right_margin_cols
)
1086 ? XFASTINT (w
->right_margin_cols
) : 0);
1091 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1095 /* Return the pixel height of the display area of window W, not
1096 including mode lines of W, if any. */
1099 window_box_height (w
)
1102 struct frame
*f
= XFRAME (w
->frame
);
1103 int height
= WINDOW_TOTAL_HEIGHT (w
);
1105 xassert (height
>= 0);
1107 /* Note: the code below that determines the mode-line/header-line
1108 height is essentially the same as that contained in the macro
1109 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1110 the appropriate glyph row has its `mode_line_p' flag set,
1111 and if it doesn't, uses estimate_mode_line_height instead. */
1113 if (WINDOW_WANTS_MODELINE_P (w
))
1115 struct glyph_row
*ml_row
1116 = (w
->current_matrix
&& w
->current_matrix
->rows
1117 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1119 if (ml_row
&& ml_row
->mode_line_p
)
1120 height
-= ml_row
->height
;
1122 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1125 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1127 struct glyph_row
*hl_row
1128 = (w
->current_matrix
&& w
->current_matrix
->rows
1129 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1131 if (hl_row
&& hl_row
->mode_line_p
)
1132 height
-= hl_row
->height
;
1134 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1137 /* With a very small font and a mode-line that's taller than
1138 default, we might end up with a negative height. */
1139 return max (0, height
);
1142 /* Return the window-relative coordinate of the left edge of display
1143 area AREA of window W. AREA < 0 means return the left edge of the
1144 whole window, to the right of the left fringe of W. */
1147 window_box_left_offset (w
, area
)
1153 if (w
->pseudo_window_p
)
1156 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1158 if (area
== TEXT_AREA
)
1159 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1160 + window_box_width (w
, LEFT_MARGIN_AREA
));
1161 else if (area
== RIGHT_MARGIN_AREA
)
1162 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1163 + window_box_width (w
, LEFT_MARGIN_AREA
)
1164 + window_box_width (w
, TEXT_AREA
)
1165 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1167 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1168 else if (area
== LEFT_MARGIN_AREA
1169 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1170 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1176 /* Return the window-relative coordinate of the right edge of display
1177 area AREA of window W. AREA < 0 means return the left edge of the
1178 whole window, to the left of the right fringe of W. */
1181 window_box_right_offset (w
, area
)
1185 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1188 /* Return the frame-relative coordinate of the left edge of display
1189 area AREA of window W. AREA < 0 means return the left edge of the
1190 whole window, to the right of the left fringe of W. */
1193 window_box_left (w
, area
)
1197 struct frame
*f
= XFRAME (w
->frame
);
1200 if (w
->pseudo_window_p
)
1201 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1203 x
= (WINDOW_LEFT_EDGE_X (w
)
1204 + window_box_left_offset (w
, area
));
1210 /* Return the frame-relative coordinate of the right edge of display
1211 area AREA of window W. AREA < 0 means return the left edge of the
1212 whole window, to the left of the right fringe of W. */
1215 window_box_right (w
, area
)
1219 return window_box_left (w
, area
) + window_box_width (w
, area
);
1222 /* Get the bounding box of the display area AREA of window W, without
1223 mode lines, in frame-relative coordinates. AREA < 0 means the
1224 whole window, not including the left and right fringes of
1225 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1226 coordinates of the upper-left corner of the box. Return in
1227 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1230 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1233 int *box_x
, *box_y
, *box_width
, *box_height
;
1236 *box_width
= window_box_width (w
, area
);
1238 *box_height
= window_box_height (w
);
1240 *box_x
= window_box_left (w
, area
);
1243 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1244 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1245 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1250 /* Get the bounding box of the display area AREA of window W, without
1251 mode lines. AREA < 0 means the whole window, not including the
1252 left and right fringe of the window. Return in *TOP_LEFT_X
1253 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1254 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1255 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1259 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1260 bottom_right_x
, bottom_right_y
)
1263 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1265 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1267 *bottom_right_x
+= *top_left_x
;
1268 *bottom_right_y
+= *top_left_y
;
1273 /***********************************************************************
1275 ***********************************************************************/
1277 /* Return the bottom y-position of the line the iterator IT is in.
1278 This can modify IT's settings. */
1284 int line_height
= it
->max_ascent
+ it
->max_descent
;
1285 int line_top_y
= it
->current_y
;
1287 if (line_height
== 0)
1290 line_height
= last_height
;
1291 else if (IT_CHARPOS (*it
) < ZV
)
1293 move_it_by_lines (it
, 1, 1);
1294 line_height
= (it
->max_ascent
|| it
->max_descent
1295 ? it
->max_ascent
+ it
->max_descent
1300 struct glyph_row
*row
= it
->glyph_row
;
1302 /* Use the default character height. */
1303 it
->glyph_row
= NULL
;
1304 it
->what
= IT_CHARACTER
;
1307 PRODUCE_GLYPHS (it
);
1308 line_height
= it
->ascent
+ it
->descent
;
1309 it
->glyph_row
= row
;
1313 return line_top_y
+ line_height
;
1317 /* Return 1 if position CHARPOS is visible in window W.
1318 CHARPOS < 0 means return info about WINDOW_END position.
1319 If visible, set *X and *Y to pixel coordinates of top left corner.
1320 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1321 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1324 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1326 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1329 struct text_pos top
;
1331 struct buffer
*old_buffer
= NULL
;
1333 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1336 if (XBUFFER (w
->buffer
) != current_buffer
)
1338 old_buffer
= current_buffer
;
1339 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1342 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1344 /* Compute exact mode line heights. */
1345 if (WINDOW_WANTS_MODELINE_P (w
))
1346 current_mode_line_height
1347 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1348 current_buffer
->mode_line_format
);
1350 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1351 current_header_line_height
1352 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1353 current_buffer
->header_line_format
);
1355 start_display (&it
, w
, top
);
1356 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1357 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1359 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1361 /* We have reached CHARPOS, or passed it. How the call to
1362 move_it_to can overshoot: (i) If CHARPOS is on invisible
1363 text, move_it_to stops at the end of the invisible text,
1364 after CHARPOS. (ii) If CHARPOS is in a display vector,
1365 move_it_to stops on its last glyph. */
1366 int top_x
= it
.current_x
;
1367 int top_y
= it
.current_y
;
1368 enum it_method it_method
= it
.method
;
1369 /* Calling line_bottom_y may change it.method. */
1370 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1371 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1373 if (top_y
< window_top_y
)
1374 visible_p
= bottom_y
> window_top_y
;
1375 else if (top_y
< it
.last_visible_y
)
1379 if (it_method
== GET_FROM_BUFFER
)
1381 Lisp_Object window
, prop
;
1383 XSETWINDOW (window
, w
);
1384 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1385 Qinvisible
, window
);
1387 /* If charpos coincides with invisible text covered with an
1388 ellipsis, use the first glyph of the ellipsis to compute
1389 the pixel positions. */
1390 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1392 struct glyph_row
*row
= it
.glyph_row
;
1393 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1394 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1398 && (!BUFFERP (glyph
->object
)
1399 || glyph
->charpos
< charpos
);
1401 x
+= glyph
->pixel_width
;
1405 else if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1407 /* We stopped on the last glyph of a display vector.
1408 Try and recompute. Hack alert! */
1409 if (charpos
< 2 || top
.charpos
>= charpos
)
1410 top_x
= it
.glyph_row
->x
;
1414 start_display (&it2
, w
, top
);
1415 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1416 get_next_display_element (&it2
);
1417 PRODUCE_GLYPHS (&it2
);
1418 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1419 || it2
.current_x
> it2
.last_visible_x
)
1420 top_x
= it
.glyph_row
->x
;
1423 top_x
= it2
.current_x
;
1424 top_y
= it2
.current_y
;
1430 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1431 *rtop
= max (0, window_top_y
- top_y
);
1432 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1433 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1434 - max (top_y
, window_top_y
)));
1443 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1444 move_it_by_lines (&it
, 1, 0);
1445 if (charpos
< IT_CHARPOS (it
)
1446 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1449 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1451 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1452 *rtop
= max (0, -it2
.current_y
);
1453 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1454 - it
.last_visible_y
));
1455 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1457 - max (it2
.current_y
,
1458 WINDOW_HEADER_LINE_HEIGHT (w
))));
1464 set_buffer_internal_1 (old_buffer
);
1466 current_header_line_height
= current_mode_line_height
= -1;
1468 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1469 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1472 /* Debugging code. */
1474 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1475 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1477 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1484 /* Return the next character from STR which is MAXLEN bytes long.
1485 Return in *LEN the length of the character. This is like
1486 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1487 we find one, we return a `?', but with the length of the invalid
1491 string_char_and_length (str
, len
)
1492 const unsigned char *str
;
1497 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1498 if (!CHAR_VALID_P (c
, 1))
1499 /* We may not change the length here because other places in Emacs
1500 don't use this function, i.e. they silently accept invalid
1509 /* Given a position POS containing a valid character and byte position
1510 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1512 static struct text_pos
1513 string_pos_nchars_ahead (pos
, string
, nchars
)
1514 struct text_pos pos
;
1518 xassert (STRINGP (string
) && nchars
>= 0);
1520 if (STRING_MULTIBYTE (string
))
1522 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1523 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1528 string_char_and_length (p
, &len
);
1529 p
+= len
, rest
-= len
;
1530 xassert (rest
>= 0);
1532 BYTEPOS (pos
) += len
;
1536 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1542 /* Value is the text position, i.e. character and byte position,
1543 for character position CHARPOS in STRING. */
1545 static INLINE
struct text_pos
1546 string_pos (charpos
, string
)
1550 struct text_pos pos
;
1551 xassert (STRINGP (string
));
1552 xassert (charpos
>= 0);
1553 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1558 /* Value is a text position, i.e. character and byte position, for
1559 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1560 means recognize multibyte characters. */
1562 static struct text_pos
1563 c_string_pos (charpos
, s
, multibyte_p
)
1568 struct text_pos pos
;
1570 xassert (s
!= NULL
);
1571 xassert (charpos
>= 0);
1575 int rest
= strlen (s
), len
;
1577 SET_TEXT_POS (pos
, 0, 0);
1580 string_char_and_length (s
, &len
);
1581 s
+= len
, rest
-= len
;
1582 xassert (rest
>= 0);
1584 BYTEPOS (pos
) += len
;
1588 SET_TEXT_POS (pos
, charpos
, charpos
);
1594 /* Value is the number of characters in C string S. MULTIBYTE_P
1595 non-zero means recognize multibyte characters. */
1598 number_of_chars (s
, multibyte_p
)
1606 int rest
= strlen (s
), len
;
1607 unsigned char *p
= (unsigned char *) s
;
1609 for (nchars
= 0; rest
> 0; ++nchars
)
1611 string_char_and_length (p
, &len
);
1612 rest
-= len
, p
+= len
;
1616 nchars
= strlen (s
);
1622 /* Compute byte position NEWPOS->bytepos corresponding to
1623 NEWPOS->charpos. POS is a known position in string STRING.
1624 NEWPOS->charpos must be >= POS.charpos. */
1627 compute_string_pos (newpos
, pos
, string
)
1628 struct text_pos
*newpos
, pos
;
1631 xassert (STRINGP (string
));
1632 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1634 if (STRING_MULTIBYTE (string
))
1635 *newpos
= string_pos_nchars_ahead (pos
, string
,
1636 CHARPOS (*newpos
) - CHARPOS (pos
));
1638 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1642 Return an estimation of the pixel height of mode or header lines on
1643 frame F. FACE_ID specifies what line's height to estimate. */
1646 estimate_mode_line_height (f
, face_id
)
1648 enum face_id face_id
;
1650 #ifdef HAVE_WINDOW_SYSTEM
1651 if (FRAME_WINDOW_P (f
))
1653 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1655 /* This function is called so early when Emacs starts that the face
1656 cache and mode line face are not yet initialized. */
1657 if (FRAME_FACE_CACHE (f
))
1659 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1663 height
= FONT_HEIGHT (face
->font
);
1664 if (face
->box_line_width
> 0)
1665 height
+= 2 * face
->box_line_width
;
1676 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1677 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1678 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1679 not force the value into range. */
1682 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1684 register int pix_x
, pix_y
;
1686 NativeRectangle
*bounds
;
1690 #ifdef HAVE_WINDOW_SYSTEM
1691 if (FRAME_WINDOW_P (f
))
1693 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1694 even for negative values. */
1696 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1698 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1700 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1701 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1704 STORE_NATIVE_RECT (*bounds
,
1705 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1706 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1707 FRAME_COLUMN_WIDTH (f
) - 1,
1708 FRAME_LINE_HEIGHT (f
) - 1);
1714 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1715 pix_x
= FRAME_TOTAL_COLS (f
);
1719 else if (pix_y
> FRAME_LINES (f
))
1720 pix_y
= FRAME_LINES (f
);
1730 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1731 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1732 can't tell the positions because W's display is not up to date,
1736 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1739 int *frame_x
, *frame_y
;
1741 #ifdef HAVE_WINDOW_SYSTEM
1742 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1746 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1747 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1749 if (display_completed
)
1751 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1752 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1753 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1759 hpos
+= glyph
->pixel_width
;
1763 /* If first glyph is partially visible, its first visible position is still 0. */
1775 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1776 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1787 #ifdef HAVE_WINDOW_SYSTEM
1789 /* Find the glyph under window-relative coordinates X/Y in window W.
1790 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1791 strings. Return in *HPOS and *VPOS the row and column number of
1792 the glyph found. Return in *AREA the glyph area containing X.
1793 Value is a pointer to the glyph found or null if X/Y is not on
1794 text, or we can't tell because W's current matrix is not up to
1799 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1802 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1804 struct glyph
*glyph
, *end
;
1805 struct glyph_row
*row
= NULL
;
1808 /* Find row containing Y. Give up if some row is not enabled. */
1809 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1811 row
= MATRIX_ROW (w
->current_matrix
, i
);
1812 if (!row
->enabled_p
)
1814 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1821 /* Give up if Y is not in the window. */
1822 if (i
== w
->current_matrix
->nrows
)
1825 /* Get the glyph area containing X. */
1826 if (w
->pseudo_window_p
)
1833 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1835 *area
= LEFT_MARGIN_AREA
;
1836 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1838 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1841 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1845 *area
= RIGHT_MARGIN_AREA
;
1846 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1850 /* Find glyph containing X. */
1851 glyph
= row
->glyphs
[*area
];
1852 end
= glyph
+ row
->used
[*area
];
1854 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1856 x
-= glyph
->pixel_width
;
1866 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1869 *hpos
= glyph
- row
->glyphs
[*area
];
1875 Convert frame-relative x/y to coordinates relative to window W.
1876 Takes pseudo-windows into account. */
1879 frame_to_window_pixel_xy (w
, x
, y
)
1883 if (w
->pseudo_window_p
)
1885 /* A pseudo-window is always full-width, and starts at the
1886 left edge of the frame, plus a frame border. */
1887 struct frame
*f
= XFRAME (w
->frame
);
1888 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1889 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1893 *x
-= WINDOW_LEFT_EDGE_X (w
);
1894 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1899 Return in RECTS[] at most N clipping rectangles for glyph string S.
1900 Return the number of stored rectangles. */
1903 get_glyph_string_clip_rects (s
, rects
, n
)
1904 struct glyph_string
*s
;
1905 NativeRectangle
*rects
;
1913 if (s
->row
->full_width_p
)
1915 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1916 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1917 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1919 /* Unless displaying a mode or menu bar line, which are always
1920 fully visible, clip to the visible part of the row. */
1921 if (s
->w
->pseudo_window_p
)
1922 r
.height
= s
->row
->visible_height
;
1924 r
.height
= s
->height
;
1928 /* This is a text line that may be partially visible. */
1929 r
.x
= window_box_left (s
->w
, s
->area
);
1930 r
.width
= window_box_width (s
->w
, s
->area
);
1931 r
.height
= s
->row
->visible_height
;
1935 if (r
.x
< s
->clip_head
->x
)
1937 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1938 r
.width
-= s
->clip_head
->x
- r
.x
;
1941 r
.x
= s
->clip_head
->x
;
1944 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1946 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1947 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1952 /* If S draws overlapping rows, it's sufficient to use the top and
1953 bottom of the window for clipping because this glyph string
1954 intentionally draws over other lines. */
1955 if (s
->for_overlaps
)
1957 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1958 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1960 /* Alas, the above simple strategy does not work for the
1961 environments with anti-aliased text: if the same text is
1962 drawn onto the same place multiple times, it gets thicker.
1963 If the overlap we are processing is for the erased cursor, we
1964 take the intersection with the rectagle of the cursor. */
1965 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1967 XRectangle rc
, r_save
= r
;
1969 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1970 rc
.y
= s
->w
->phys_cursor
.y
;
1971 rc
.width
= s
->w
->phys_cursor_width
;
1972 rc
.height
= s
->w
->phys_cursor_height
;
1974 x_intersect_rectangles (&r_save
, &rc
, &r
);
1979 /* Don't use S->y for clipping because it doesn't take partially
1980 visible lines into account. For example, it can be negative for
1981 partially visible lines at the top of a window. */
1982 if (!s
->row
->full_width_p
1983 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1984 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1986 r
.y
= max (0, s
->row
->y
);
1989 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1991 /* If drawing the cursor, don't let glyph draw outside its
1992 advertised boundaries. Cleartype does this under some circumstances. */
1993 if (s
->hl
== DRAW_CURSOR
)
1995 struct glyph
*glyph
= s
->first_glyph
;
2000 r
.width
-= s
->x
- r
.x
;
2003 r
.width
= min (r
.width
, glyph
->pixel_width
);
2005 /* If r.y is below window bottom, ensure that we still see a cursor. */
2006 height
= min (glyph
->ascent
+ glyph
->descent
,
2007 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2008 max_y
= window_text_bottom_y (s
->w
) - height
;
2009 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2010 if (s
->ybase
- glyph
->ascent
> max_y
)
2017 /* Don't draw cursor glyph taller than our actual glyph. */
2018 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2019 if (height
< r
.height
)
2021 max_y
= r
.y
+ r
.height
;
2022 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2023 r
.height
= min (max_y
- r
.y
, height
);
2030 XRectangle r_save
= r
;
2032 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2036 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2037 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2039 #ifdef CONVERT_FROM_XRECT
2040 CONVERT_FROM_XRECT (r
, *rects
);
2048 /* If we are processing overlapping and allowed to return
2049 multiple clipping rectangles, we exclude the row of the glyph
2050 string from the clipping rectangle. This is to avoid drawing
2051 the same text on the environment with anti-aliasing. */
2052 #ifdef CONVERT_FROM_XRECT
2055 XRectangle
*rs
= rects
;
2057 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2059 if (s
->for_overlaps
& OVERLAPS_PRED
)
2062 if (r
.y
+ r
.height
> row_y
)
2065 rs
[i
].height
= row_y
- r
.y
;
2071 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2074 if (r
.y
< row_y
+ s
->row
->visible_height
)
2076 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2078 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2079 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2088 #ifdef CONVERT_FROM_XRECT
2089 for (i
= 0; i
< n
; i
++)
2090 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2097 Return in *NR the clipping rectangle for glyph string S. */
2100 get_glyph_string_clip_rect (s
, nr
)
2101 struct glyph_string
*s
;
2102 NativeRectangle
*nr
;
2104 get_glyph_string_clip_rects (s
, nr
, 1);
2109 Return the position and height of the phys cursor in window W.
2110 Set w->phys_cursor_width to width of phys cursor.
2114 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2116 struct glyph_row
*row
;
2117 struct glyph
*glyph
;
2118 int *xp
, *yp
, *heightp
;
2120 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2121 int x
, y
, wd
, h
, h0
, y0
;
2123 /* Compute the width of the rectangle to draw. If on a stretch
2124 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2125 rectangle as wide as the glyph, but use a canonical character
2127 wd
= glyph
->pixel_width
- 1;
2128 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
2132 x
= w
->phys_cursor
.x
;
2139 if (glyph
->type
== STRETCH_GLYPH
2140 && !x_stretch_cursor_p
)
2141 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2142 w
->phys_cursor_width
= wd
;
2144 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2146 /* If y is below window bottom, ensure that we still see a cursor. */
2147 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2149 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2150 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2152 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2155 h
= max (h
- (y0
- y
) + 1, h0
);
2160 y0
= window_text_bottom_y (w
) - h0
;
2168 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2169 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2174 * Remember which glyph the mouse is over.
2178 remember_mouse_glyph (f
, gx
, gy
, rect
)
2181 NativeRectangle
*rect
;
2185 struct glyph_row
*r
, *gr
, *end_row
;
2186 enum window_part part
;
2187 enum glyph_row_area area
;
2188 int x
, y
, width
, height
;
2190 /* Try to determine frame pixel position and size of the glyph under
2191 frame pixel coordinates X/Y on frame F. */
2193 if (!f
->glyphs_initialized_p
2194 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2197 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2198 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2202 w
= XWINDOW (window
);
2203 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2204 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2206 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2207 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2209 if (w
->pseudo_window_p
)
2212 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2218 case ON_LEFT_MARGIN
:
2219 area
= LEFT_MARGIN_AREA
;
2222 case ON_RIGHT_MARGIN
:
2223 area
= RIGHT_MARGIN_AREA
;
2226 case ON_HEADER_LINE
:
2228 gr
= (part
== ON_HEADER_LINE
2229 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2230 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2233 goto text_glyph_row_found
;
2240 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2241 if (r
->y
+ r
->height
> y
)
2247 text_glyph_row_found
:
2250 struct glyph
*g
= gr
->glyphs
[area
];
2251 struct glyph
*end
= g
+ gr
->used
[area
];
2253 height
= gr
->height
;
2254 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2255 if (gx
+ g
->pixel_width
> x
)
2260 if (g
->type
== IMAGE_GLYPH
)
2262 /* Don't remember when mouse is over image, as
2263 image may have hot-spots. */
2264 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2267 width
= g
->pixel_width
;
2271 /* Use nominal char spacing at end of line. */
2273 gx
+= (x
/ width
) * width
;
2276 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2277 gx
+= window_box_left_offset (w
, area
);
2281 /* Use nominal line height at end of window. */
2282 gx
= (x
/ width
) * width
;
2284 gy
+= (y
/ height
) * height
;
2288 case ON_LEFT_FRINGE
:
2289 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2290 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2291 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2292 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2295 case ON_RIGHT_FRINGE
:
2296 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2297 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2298 : window_box_right_offset (w
, TEXT_AREA
));
2299 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2303 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2305 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2306 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2307 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2309 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2313 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2314 if (r
->y
+ r
->height
> y
)
2321 height
= gr
->height
;
2324 /* Use nominal line height at end of window. */
2326 gy
+= (y
/ height
) * height
;
2333 /* If there is no glyph under the mouse, then we divide the screen
2334 into a grid of the smallest glyph in the frame, and use that
2337 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2338 round down even for negative values. */
2344 gx
= (gx
/ width
) * width
;
2345 gy
= (gy
/ height
) * height
;
2350 gx
+= WINDOW_LEFT_EDGE_X (w
);
2351 gy
+= WINDOW_TOP_EDGE_Y (w
);
2354 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2356 /* Visible feedback for debugging. */
2359 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2360 f
->output_data
.x
->normal_gc
,
2361 gx
, gy
, width
, height
);
2367 #endif /* HAVE_WINDOW_SYSTEM */
2370 /***********************************************************************
2371 Lisp form evaluation
2372 ***********************************************************************/
2374 /* Error handler for safe_eval and safe_call. */
2377 safe_eval_handler (arg
)
2380 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2385 /* Evaluate SEXPR and return the result, or nil if something went
2386 wrong. Prevent redisplay during the evaluation. */
2388 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2389 Return the result, or nil if something went wrong. Prevent
2390 redisplay during the evaluation. */
2393 safe_call (nargs
, args
)
2399 if (inhibit_eval_during_redisplay
)
2403 int count
= SPECPDL_INDEX ();
2404 struct gcpro gcpro1
;
2407 gcpro1
.nvars
= nargs
;
2408 specbind (Qinhibit_redisplay
, Qt
);
2409 /* Use Qt to ensure debugger does not run,
2410 so there is no possibility of wanting to redisplay. */
2411 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2414 val
= unbind_to (count
, val
);
2421 /* Call function FN with one argument ARG.
2422 Return the result, or nil if something went wrong. */
2425 safe_call1 (fn
, arg
)
2426 Lisp_Object fn
, arg
;
2428 Lisp_Object args
[2];
2431 return safe_call (2, args
);
2434 static Lisp_Object Qeval
;
2437 safe_eval (Lisp_Object sexpr
)
2439 return safe_call1 (Qeval
, sexpr
);
2442 /* Call function FN with one argument ARG.
2443 Return the result, or nil if something went wrong. */
2446 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2448 Lisp_Object args
[3];
2452 return safe_call (3, args
);
2457 /***********************************************************************
2459 ***********************************************************************/
2463 /* Define CHECK_IT to perform sanity checks on iterators.
2464 This is for debugging. It is too slow to do unconditionally. */
2470 if (it
->method
== GET_FROM_STRING
)
2472 xassert (STRINGP (it
->string
));
2473 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2477 xassert (IT_STRING_CHARPOS (*it
) < 0);
2478 if (it
->method
== GET_FROM_BUFFER
)
2480 /* Check that character and byte positions agree. */
2481 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2486 xassert (it
->current
.dpvec_index
>= 0);
2488 xassert (it
->current
.dpvec_index
< 0);
2491 #define CHECK_IT(IT) check_it ((IT))
2495 #define CHECK_IT(IT) (void) 0
2502 /* Check that the window end of window W is what we expect it
2503 to be---the last row in the current matrix displaying text. */
2506 check_window_end (w
)
2509 if (!MINI_WINDOW_P (w
)
2510 && !NILP (w
->window_end_valid
))
2512 struct glyph_row
*row
;
2513 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2514 XFASTINT (w
->window_end_vpos
)),
2516 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2517 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2521 #define CHECK_WINDOW_END(W) check_window_end ((W))
2523 #else /* not GLYPH_DEBUG */
2525 #define CHECK_WINDOW_END(W) (void) 0
2527 #endif /* not GLYPH_DEBUG */
2531 /***********************************************************************
2532 Iterator initialization
2533 ***********************************************************************/
2535 /* Initialize IT for displaying current_buffer in window W, starting
2536 at character position CHARPOS. CHARPOS < 0 means that no buffer
2537 position is specified which is useful when the iterator is assigned
2538 a position later. BYTEPOS is the byte position corresponding to
2539 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2541 If ROW is not null, calls to produce_glyphs with IT as parameter
2542 will produce glyphs in that row.
2544 BASE_FACE_ID is the id of a base face to use. It must be one of
2545 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2546 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2547 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2549 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2550 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2551 will be initialized to use the corresponding mode line glyph row of
2552 the desired matrix of W. */
2555 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2558 int charpos
, bytepos
;
2559 struct glyph_row
*row
;
2560 enum face_id base_face_id
;
2562 int highlight_region_p
;
2563 enum face_id remapped_base_face_id
= base_face_id
;
2565 /* Some precondition checks. */
2566 xassert (w
!= NULL
&& it
!= NULL
);
2567 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2570 /* If face attributes have been changed since the last redisplay,
2571 free realized faces now because they depend on face definitions
2572 that might have changed. Don't free faces while there might be
2573 desired matrices pending which reference these faces. */
2574 if (face_change_count
&& !inhibit_free_realized_faces
)
2576 face_change_count
= 0;
2577 free_all_realized_faces (Qnil
);
2580 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2581 if (! NILP (Vface_remapping_alist
))
2582 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2584 /* Use one of the mode line rows of W's desired matrix if
2588 if (base_face_id
== MODE_LINE_FACE_ID
2589 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2590 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2591 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2592 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2596 bzero (it
, sizeof *it
);
2597 it
->current
.overlay_string_index
= -1;
2598 it
->current
.dpvec_index
= -1;
2599 it
->base_face_id
= remapped_base_face_id
;
2601 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2603 /* The window in which we iterate over current_buffer: */
2604 XSETWINDOW (it
->window
, w
);
2606 it
->f
= XFRAME (w
->frame
);
2610 /* Extra space between lines (on window systems only). */
2611 if (base_face_id
== DEFAULT_FACE_ID
2612 && FRAME_WINDOW_P (it
->f
))
2614 if (NATNUMP (current_buffer
->extra_line_spacing
))
2615 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2616 else if (FLOATP (current_buffer
->extra_line_spacing
))
2617 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2618 * FRAME_LINE_HEIGHT (it
->f
));
2619 else if (it
->f
->extra_line_spacing
> 0)
2620 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2621 it
->max_extra_line_spacing
= 0;
2624 /* If realized faces have been removed, e.g. because of face
2625 attribute changes of named faces, recompute them. When running
2626 in batch mode, the face cache of the initial frame is null. If
2627 we happen to get called, make a dummy face cache. */
2628 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2629 init_frame_faces (it
->f
);
2630 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2631 recompute_basic_faces (it
->f
);
2633 /* Current value of the `slice', `space-width', and 'height' properties. */
2634 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2635 it
->space_width
= Qnil
;
2636 it
->font_height
= Qnil
;
2637 it
->override_ascent
= -1;
2639 /* Are control characters displayed as `^C'? */
2640 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2642 /* -1 means everything between a CR and the following line end
2643 is invisible. >0 means lines indented more than this value are
2645 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2646 ? XFASTINT (current_buffer
->selective_display
)
2647 : (!NILP (current_buffer
->selective_display
)
2649 it
->selective_display_ellipsis_p
2650 = !NILP (current_buffer
->selective_display_ellipses
);
2652 /* Display table to use. */
2653 it
->dp
= window_display_table (w
);
2655 /* Are multibyte characters enabled in current_buffer? */
2656 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2658 /* Do we need to reorder bidirectional text? */
2659 it
->bidi_p
= !NILP (current_buffer
->bidi_display_reordering
);
2661 /* Non-zero if we should highlight the region. */
2663 = (!NILP (Vtransient_mark_mode
)
2664 && !NILP (current_buffer
->mark_active
)
2665 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2667 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2668 start and end of a visible region in window IT->w. Set both to
2669 -1 to indicate no region. */
2670 if (highlight_region_p
2671 /* Maybe highlight only in selected window. */
2672 && (/* Either show region everywhere. */
2673 highlight_nonselected_windows
2674 /* Or show region in the selected window. */
2675 || w
== XWINDOW (selected_window
)
2676 /* Or show the region if we are in the mini-buffer and W is
2677 the window the mini-buffer refers to. */
2678 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2679 && WINDOWP (minibuf_selected_window
)
2680 && w
== XWINDOW (minibuf_selected_window
))))
2682 int charpos
= marker_position (current_buffer
->mark
);
2683 it
->region_beg_charpos
= min (PT
, charpos
);
2684 it
->region_end_charpos
= max (PT
, charpos
);
2687 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2689 /* Get the position at which the redisplay_end_trigger hook should
2690 be run, if it is to be run at all. */
2691 if (MARKERP (w
->redisplay_end_trigger
)
2692 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2693 it
->redisplay_end_trigger_charpos
2694 = marker_position (w
->redisplay_end_trigger
);
2695 else if (INTEGERP (w
->redisplay_end_trigger
))
2696 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2698 /* Correct bogus values of tab_width. */
2699 it
->tab_width
= XINT (current_buffer
->tab_width
);
2700 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2703 /* Are lines in the display truncated? */
2704 if (base_face_id
!= DEFAULT_FACE_ID
2705 || XINT (it
->w
->hscroll
)
2706 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2707 && ((!NILP (Vtruncate_partial_width_windows
)
2708 && !INTEGERP (Vtruncate_partial_width_windows
))
2709 || (INTEGERP (Vtruncate_partial_width_windows
)
2710 && (WINDOW_TOTAL_COLS (it
->w
)
2711 < XINT (Vtruncate_partial_width_windows
))))))
2712 it
->line_wrap
= TRUNCATE
;
2713 else if (NILP (current_buffer
->truncate_lines
))
2714 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2715 ? WINDOW_WRAP
: WORD_WRAP
;
2717 it
->line_wrap
= TRUNCATE
;
2719 /* Get dimensions of truncation and continuation glyphs. These are
2720 displayed as fringe bitmaps under X, so we don't need them for such
2722 if (!FRAME_WINDOW_P (it
->f
))
2724 if (it
->line_wrap
== TRUNCATE
)
2726 /* We will need the truncation glyph. */
2727 xassert (it
->glyph_row
== NULL
);
2728 produce_special_glyphs (it
, IT_TRUNCATION
);
2729 it
->truncation_pixel_width
= it
->pixel_width
;
2733 /* We will need the continuation glyph. */
2734 xassert (it
->glyph_row
== NULL
);
2735 produce_special_glyphs (it
, IT_CONTINUATION
);
2736 it
->continuation_pixel_width
= it
->pixel_width
;
2739 /* Reset these values to zero because the produce_special_glyphs
2740 above has changed them. */
2741 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2742 it
->phys_ascent
= it
->phys_descent
= 0;
2745 /* Set this after getting the dimensions of truncation and
2746 continuation glyphs, so that we don't produce glyphs when calling
2747 produce_special_glyphs, above. */
2748 it
->glyph_row
= row
;
2749 it
->area
= TEXT_AREA
;
2751 /* Get the dimensions of the display area. The display area
2752 consists of the visible window area plus a horizontally scrolled
2753 part to the left of the window. All x-values are relative to the
2754 start of this total display area. */
2755 if (base_face_id
!= DEFAULT_FACE_ID
)
2757 /* Mode lines, menu bar in terminal frames. */
2758 it
->first_visible_x
= 0;
2759 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2764 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2765 it
->last_visible_x
= (it
->first_visible_x
2766 + window_box_width (w
, TEXT_AREA
));
2768 /* If we truncate lines, leave room for the truncator glyph(s) at
2769 the right margin. Otherwise, leave room for the continuation
2770 glyph(s). Truncation and continuation glyphs are not inserted
2771 for window-based redisplay. */
2772 if (!FRAME_WINDOW_P (it
->f
))
2774 if (it
->line_wrap
== TRUNCATE
)
2775 it
->last_visible_x
-= it
->truncation_pixel_width
;
2777 it
->last_visible_x
-= it
->continuation_pixel_width
;
2780 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2781 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2784 /* Leave room for a border glyph. */
2785 if (!FRAME_WINDOW_P (it
->f
)
2786 && !WINDOW_RIGHTMOST_P (it
->w
))
2787 it
->last_visible_x
-= 1;
2789 it
->last_visible_y
= window_text_bottom_y (w
);
2791 /* For mode lines and alike, arrange for the first glyph having a
2792 left box line if the face specifies a box. */
2793 if (base_face_id
!= DEFAULT_FACE_ID
)
2797 it
->face_id
= remapped_base_face_id
;
2799 /* If we have a boxed mode line, make the first character appear
2800 with a left box line. */
2801 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2802 if (face
->box
!= FACE_NO_BOX
)
2803 it
->start_of_box_run_p
= 1;
2806 /* If we are to reorder bidirectional text, init the bidi
2810 /* Note the paragraph direction that this buffer wants to
2812 if (EQ (current_buffer
->bidi_paragraph_direction
, Qleft_to_right
))
2813 it
->paragraph_embedding
= L2R
;
2814 else if (EQ (current_buffer
->bidi_paragraph_direction
, Qright_to_left
))
2815 it
->paragraph_embedding
= R2L
;
2817 it
->paragraph_embedding
= NEUTRAL_DIR
;
2818 bidi_init_it (charpos
, bytepos
, &it
->bidi_it
);
2821 /* If a buffer position was specified, set the iterator there,
2822 getting overlays and face properties from that position. */
2823 if (charpos
>= BUF_BEG (current_buffer
))
2825 it
->end_charpos
= ZV
;
2827 IT_CHARPOS (*it
) = charpos
;
2829 /* Compute byte position if not specified. */
2830 if (bytepos
< charpos
)
2831 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2833 IT_BYTEPOS (*it
) = bytepos
;
2835 it
->start
= it
->current
;
2837 /* Compute faces etc. */
2838 reseat (it
, it
->current
.pos
, 1);
2845 /* Initialize IT for the display of window W with window start POS. */
2848 start_display (it
, w
, pos
)
2851 struct text_pos pos
;
2853 struct glyph_row
*row
;
2854 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2856 row
= w
->desired_matrix
->rows
+ first_vpos
;
2857 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2858 it
->first_vpos
= first_vpos
;
2860 /* Don't reseat to previous visible line start if current start
2861 position is in a string or image. */
2862 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2864 int start_at_line_beg_p
;
2865 int first_y
= it
->current_y
;
2867 /* If window start is not at a line start, skip forward to POS to
2868 get the correct continuation lines width. */
2869 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2870 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2871 if (!start_at_line_beg_p
)
2875 reseat_at_previous_visible_line_start (it
);
2876 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2878 new_x
= it
->current_x
+ it
->pixel_width
;
2880 /* If lines are continued, this line may end in the middle
2881 of a multi-glyph character (e.g. a control character
2882 displayed as \003, or in the middle of an overlay
2883 string). In this case move_it_to above will not have
2884 taken us to the start of the continuation line but to the
2885 end of the continued line. */
2886 if (it
->current_x
> 0
2887 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2888 && (/* And glyph doesn't fit on the line. */
2889 new_x
> it
->last_visible_x
2890 /* Or it fits exactly and we're on a window
2892 || (new_x
== it
->last_visible_x
2893 && FRAME_WINDOW_P (it
->f
))))
2895 if (it
->current
.dpvec_index
>= 0
2896 || it
->current
.overlay_string_index
>= 0)
2898 set_iterator_to_next (it
, 1);
2899 move_it_in_display_line_to (it
, -1, -1, 0);
2902 it
->continuation_lines_width
+= it
->current_x
;
2905 /* We're starting a new display line, not affected by the
2906 height of the continued line, so clear the appropriate
2907 fields in the iterator structure. */
2908 it
->max_ascent
= it
->max_descent
= 0;
2909 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2911 it
->current_y
= first_y
;
2913 it
->current_x
= it
->hpos
= 0;
2919 /* Return 1 if POS is a position in ellipses displayed for invisible
2920 text. W is the window we display, for text property lookup. */
2923 in_ellipses_for_invisible_text_p (pos
, w
)
2924 struct display_pos
*pos
;
2927 Lisp_Object prop
, window
;
2929 int charpos
= CHARPOS (pos
->pos
);
2931 /* If POS specifies a position in a display vector, this might
2932 be for an ellipsis displayed for invisible text. We won't
2933 get the iterator set up for delivering that ellipsis unless
2934 we make sure that it gets aware of the invisible text. */
2935 if (pos
->dpvec_index
>= 0
2936 && pos
->overlay_string_index
< 0
2937 && CHARPOS (pos
->string_pos
) < 0
2939 && (XSETWINDOW (window
, w
),
2940 prop
= Fget_char_property (make_number (charpos
),
2941 Qinvisible
, window
),
2942 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2944 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2946 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2953 /* Initialize IT for stepping through current_buffer in window W,
2954 starting at position POS that includes overlay string and display
2955 vector/ control character translation position information. Value
2956 is zero if there are overlay strings with newlines at POS. */
2959 init_from_display_pos (it
, w
, pos
)
2962 struct display_pos
*pos
;
2964 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2965 int i
, overlay_strings_with_newlines
= 0;
2967 /* If POS specifies a position in a display vector, this might
2968 be for an ellipsis displayed for invisible text. We won't
2969 get the iterator set up for delivering that ellipsis unless
2970 we make sure that it gets aware of the invisible text. */
2971 if (in_ellipses_for_invisible_text_p (pos
, w
))
2977 /* Keep in mind: the call to reseat in init_iterator skips invisible
2978 text, so we might end up at a position different from POS. This
2979 is only a problem when POS is a row start after a newline and an
2980 overlay starts there with an after-string, and the overlay has an
2981 invisible property. Since we don't skip invisible text in
2982 display_line and elsewhere immediately after consuming the
2983 newline before the row start, such a POS will not be in a string,
2984 but the call to init_iterator below will move us to the
2986 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2988 /* This only scans the current chunk -- it should scan all chunks.
2989 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2990 to 16 in 22.1 to make this a lesser problem. */
2991 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2993 const char *s
= SDATA (it
->overlay_strings
[i
]);
2994 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2996 while (s
< e
&& *s
!= '\n')
3001 overlay_strings_with_newlines
= 1;
3006 /* If position is within an overlay string, set up IT to the right
3008 if (pos
->overlay_string_index
>= 0)
3012 /* If the first overlay string happens to have a `display'
3013 property for an image, the iterator will be set up for that
3014 image, and we have to undo that setup first before we can
3015 correct the overlay string index. */
3016 if (it
->method
== GET_FROM_IMAGE
)
3019 /* We already have the first chunk of overlay strings in
3020 IT->overlay_strings. Load more until the one for
3021 pos->overlay_string_index is in IT->overlay_strings. */
3022 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3024 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3025 it
->current
.overlay_string_index
= 0;
3028 load_overlay_strings (it
, 0);
3029 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3033 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3034 relative_index
= (it
->current
.overlay_string_index
3035 % OVERLAY_STRING_CHUNK_SIZE
);
3036 it
->string
= it
->overlay_strings
[relative_index
];
3037 xassert (STRINGP (it
->string
));
3038 it
->current
.string_pos
= pos
->string_pos
;
3039 it
->method
= GET_FROM_STRING
;
3042 if (CHARPOS (pos
->string_pos
) >= 0)
3044 /* Recorded position is not in an overlay string, but in another
3045 string. This can only be a string from a `display' property.
3046 IT should already be filled with that string. */
3047 it
->current
.string_pos
= pos
->string_pos
;
3048 xassert (STRINGP (it
->string
));
3051 /* Restore position in display vector translations, control
3052 character translations or ellipses. */
3053 if (pos
->dpvec_index
>= 0)
3055 if (it
->dpvec
== NULL
)
3056 get_next_display_element (it
);
3057 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3058 it
->current
.dpvec_index
= pos
->dpvec_index
;
3062 return !overlay_strings_with_newlines
;
3066 /* Initialize IT for stepping through current_buffer in window W
3067 starting at ROW->start. */
3070 init_to_row_start (it
, w
, row
)
3073 struct glyph_row
*row
;
3075 init_from_display_pos (it
, w
, &row
->start
);
3076 it
->start
= row
->start
;
3077 it
->continuation_lines_width
= row
->continuation_lines_width
;
3082 /* Initialize IT for stepping through current_buffer in window W
3083 starting in the line following ROW, i.e. starting at ROW->end.
3084 Value is zero if there are overlay strings with newlines at ROW's
3088 init_to_row_end (it
, w
, row
)
3091 struct glyph_row
*row
;
3095 if (init_from_display_pos (it
, w
, &row
->end
))
3097 if (row
->continued_p
)
3098 it
->continuation_lines_width
3099 = row
->continuation_lines_width
+ row
->pixel_width
;
3110 /***********************************************************************
3112 ***********************************************************************/
3114 /* Called when IT reaches IT->stop_charpos. Handle text property and
3115 overlay changes. Set IT->stop_charpos to the next position where
3122 enum prop_handled handled
;
3123 int handle_overlay_change_p
;
3127 it
->current
.dpvec_index
= -1;
3128 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3129 it
->ignore_overlay_strings_at_pos_p
= 0;
3132 /* Use face of preceding text for ellipsis (if invisible) */
3133 if (it
->selective_display_ellipsis_p
)
3134 it
->saved_face_id
= it
->face_id
;
3138 handled
= HANDLED_NORMALLY
;
3140 /* Call text property handlers. */
3141 for (p
= it_props
; p
->handler
; ++p
)
3143 handled
= p
->handler (it
);
3145 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3147 else if (handled
== HANDLED_RETURN
)
3149 /* We still want to show before and after strings from
3150 overlays even if the actual buffer text is replaced. */
3151 if (!handle_overlay_change_p
3153 || !get_overlay_strings_1 (it
, 0, 0))
3156 setup_for_ellipsis (it
, 0);
3157 /* When handling a display spec, we might load an
3158 empty string. In that case, discard it here. We
3159 used to discard it in handle_single_display_spec,
3160 but that causes get_overlay_strings_1, above, to
3161 ignore overlay strings that we must check. */
3162 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3166 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3170 it
->ignore_overlay_strings_at_pos_p
= 1;
3171 it
->string_from_display_prop_p
= 0;
3172 handle_overlay_change_p
= 0;
3174 handled
= HANDLED_RECOMPUTE_PROPS
;
3177 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3178 handle_overlay_change_p
= 0;
3181 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3183 /* Don't check for overlay strings below when set to deliver
3184 characters from a display vector. */
3185 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3186 handle_overlay_change_p
= 0;
3188 /* Handle overlay changes.
3189 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3190 if it finds overlays. */
3191 if (handle_overlay_change_p
)
3192 handled
= handle_overlay_change (it
);
3197 setup_for_ellipsis (it
, 0);
3201 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3203 /* Determine where to stop next. */
3204 if (handled
== HANDLED_NORMALLY
)
3205 compute_stop_pos (it
);
3209 /* Compute IT->stop_charpos from text property and overlay change
3210 information for IT's current position. */
3213 compute_stop_pos (it
)
3216 register INTERVAL iv
, next_iv
;
3217 Lisp_Object object
, limit
, position
;
3218 EMACS_INT charpos
, bytepos
;
3220 /* If nowhere else, stop at the end. */
3221 it
->stop_charpos
= it
->end_charpos
;
3223 if (STRINGP (it
->string
))
3225 /* Strings are usually short, so don't limit the search for
3227 object
= it
->string
;
3229 charpos
= IT_STRING_CHARPOS (*it
);
3230 bytepos
= IT_STRING_BYTEPOS (*it
);
3236 /* If next overlay change is in front of the current stop pos
3237 (which is IT->end_charpos), stop there. Note: value of
3238 next_overlay_change is point-max if no overlay change
3240 charpos
= IT_CHARPOS (*it
);
3241 bytepos
= IT_BYTEPOS (*it
);
3242 pos
= next_overlay_change (charpos
);
3243 if (pos
< it
->stop_charpos
)
3244 it
->stop_charpos
= pos
;
3246 /* If showing the region, we have to stop at the region
3247 start or end because the face might change there. */
3248 if (it
->region_beg_charpos
> 0)
3250 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3251 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3252 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3253 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3256 /* Set up variables for computing the stop position from text
3257 property changes. */
3258 XSETBUFFER (object
, current_buffer
);
3259 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3262 /* Get the interval containing IT's position. Value is a null
3263 interval if there isn't such an interval. */
3264 position
= make_number (charpos
);
3265 iv
= validate_interval_range (object
, &position
, &position
, 0);
3266 if (!NULL_INTERVAL_P (iv
))
3268 Lisp_Object values_here
[LAST_PROP_IDX
];
3271 /* Get properties here. */
3272 for (p
= it_props
; p
->handler
; ++p
)
3273 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3275 /* Look for an interval following iv that has different
3277 for (next_iv
= next_interval (iv
);
3278 (!NULL_INTERVAL_P (next_iv
)
3280 || XFASTINT (limit
) > next_iv
->position
));
3281 next_iv
= next_interval (next_iv
))
3283 for (p
= it_props
; p
->handler
; ++p
)
3285 Lisp_Object new_value
;
3287 new_value
= textget (next_iv
->plist
, *p
->name
);
3288 if (!EQ (values_here
[p
->idx
], new_value
))
3296 if (!NULL_INTERVAL_P (next_iv
))
3298 if (INTEGERP (limit
)
3299 && next_iv
->position
>= XFASTINT (limit
))
3300 /* No text property change up to limit. */
3301 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3303 /* Text properties change in next_iv. */
3304 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3308 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3309 it
->stop_charpos
, it
->string
);
3311 xassert (STRINGP (it
->string
)
3312 || (it
->stop_charpos
>= BEGV
3313 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3317 /* Return the position of the next overlay change after POS in
3318 current_buffer. Value is point-max if no overlay change
3319 follows. This is like `next-overlay-change' but doesn't use
3323 next_overlay_change (pos
)
3328 Lisp_Object
*overlays
;
3331 /* Get all overlays at the given position. */
3332 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3334 /* If any of these overlays ends before endpos,
3335 use its ending point instead. */
3336 for (i
= 0; i
< noverlays
; ++i
)
3341 oend
= OVERLAY_END (overlays
[i
]);
3342 oendpos
= OVERLAY_POSITION (oend
);
3343 endpos
= min (endpos
, oendpos
);
3351 /***********************************************************************
3353 ***********************************************************************/
3355 /* Handle changes in the `fontified' property of the current buffer by
3356 calling hook functions from Qfontification_functions to fontify
3359 static enum prop_handled
3360 handle_fontified_prop (it
)
3363 Lisp_Object prop
, pos
;
3364 enum prop_handled handled
= HANDLED_NORMALLY
;
3366 if (!NILP (Vmemory_full
))
3369 /* Get the value of the `fontified' property at IT's current buffer
3370 position. (The `fontified' property doesn't have a special
3371 meaning in strings.) If the value is nil, call functions from
3372 Qfontification_functions. */
3373 if (!STRINGP (it
->string
)
3375 && !NILP (Vfontification_functions
)
3376 && !NILP (Vrun_hooks
)
3377 && (pos
= make_number (IT_CHARPOS (*it
)),
3378 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3379 /* Ignore the special cased nil value always present at EOB since
3380 no amount of fontifying will be able to change it. */
3381 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3383 int count
= SPECPDL_INDEX ();
3386 val
= Vfontification_functions
;
3387 specbind (Qfontification_functions
, Qnil
);
3389 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3390 safe_call1 (val
, pos
);
3393 Lisp_Object globals
, fn
;
3394 struct gcpro gcpro1
, gcpro2
;
3397 GCPRO2 (val
, globals
);
3399 for (; CONSP (val
); val
= XCDR (val
))
3405 /* A value of t indicates this hook has a local
3406 binding; it means to run the global binding too.
3407 In a global value, t should not occur. If it
3408 does, we must ignore it to avoid an endless
3410 for (globals
= Fdefault_value (Qfontification_functions
);
3412 globals
= XCDR (globals
))
3414 fn
= XCAR (globals
);
3416 safe_call1 (fn
, pos
);
3420 safe_call1 (fn
, pos
);
3426 unbind_to (count
, Qnil
);
3428 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3429 something. This avoids an endless loop if they failed to
3430 fontify the text for which reason ever. */
3431 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3432 handled
= HANDLED_RECOMPUTE_PROPS
;
3440 /***********************************************************************
3442 ***********************************************************************/
3444 /* Set up iterator IT from face properties at its current position.
3445 Called from handle_stop. */
3447 static enum prop_handled
3448 handle_face_prop (it
)
3452 EMACS_INT next_stop
;
3454 if (!STRINGP (it
->string
))
3457 = face_at_buffer_position (it
->w
,
3459 it
->region_beg_charpos
,
3460 it
->region_end_charpos
,
3463 + TEXT_PROP_DISTANCE_LIMIT
),
3464 0, it
->base_face_id
);
3466 /* Is this a start of a run of characters with box face?
3467 Caveat: this can be called for a freshly initialized
3468 iterator; face_id is -1 in this case. We know that the new
3469 face will not change until limit, i.e. if the new face has a
3470 box, all characters up to limit will have one. But, as
3471 usual, we don't know whether limit is really the end. */
3472 if (new_face_id
!= it
->face_id
)
3474 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3476 /* If new face has a box but old face has not, this is
3477 the start of a run of characters with box, i.e. it has
3478 a shadow on the left side. The value of face_id of the
3479 iterator will be -1 if this is the initial call that gets
3480 the face. In this case, we have to look in front of IT's
3481 position and see whether there is a face != new_face_id. */
3482 it
->start_of_box_run_p
3483 = (new_face
->box
!= FACE_NO_BOX
3484 && (it
->face_id
>= 0
3485 || IT_CHARPOS (*it
) == BEG
3486 || new_face_id
!= face_before_it_pos (it
)));
3487 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3492 int base_face_id
, bufpos
;
3494 Lisp_Object from_overlay
3495 = (it
->current
.overlay_string_index
>= 0
3496 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3499 /* See if we got to this string directly or indirectly from
3500 an overlay property. That includes the before-string or
3501 after-string of an overlay, strings in display properties
3502 provided by an overlay, their text properties, etc.
3504 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3505 if (! NILP (from_overlay
))
3506 for (i
= it
->sp
- 1; i
>= 0; i
--)
3508 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3510 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3511 else if (! NILP (it
->stack
[i
].from_overlay
))
3512 from_overlay
= it
->stack
[i
].from_overlay
;
3514 if (!NILP (from_overlay
))
3518 if (! NILP (from_overlay
))
3520 bufpos
= IT_CHARPOS (*it
);
3521 /* For a string from an overlay, the base face depends
3522 only on text properties and ignores overlays. */
3524 = face_for_overlay_string (it
->w
,
3526 it
->region_beg_charpos
,
3527 it
->region_end_charpos
,
3530 + TEXT_PROP_DISTANCE_LIMIT
),
3538 /* For strings from a `display' property, use the face at
3539 IT's current buffer position as the base face to merge
3540 with, so that overlay strings appear in the same face as
3541 surrounding text, unless they specify their own
3543 base_face_id
= underlying_face_id (it
);
3546 new_face_id
= face_at_string_position (it
->w
,
3548 IT_STRING_CHARPOS (*it
),
3550 it
->region_beg_charpos
,
3551 it
->region_end_charpos
,
3555 /* Is this a start of a run of characters with box? Caveat:
3556 this can be called for a freshly allocated iterator; face_id
3557 is -1 is this case. We know that the new face will not
3558 change until the next check pos, i.e. if the new face has a
3559 box, all characters up to that position will have a
3560 box. But, as usual, we don't know whether that position
3561 is really the end. */
3562 if (new_face_id
!= it
->face_id
)
3564 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3565 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3567 /* If new face has a box but old face hasn't, this is the
3568 start of a run of characters with box, i.e. it has a
3569 shadow on the left side. */
3570 it
->start_of_box_run_p
3571 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3572 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3576 it
->face_id
= new_face_id
;
3577 return HANDLED_NORMALLY
;
3581 /* Return the ID of the face ``underlying'' IT's current position,
3582 which is in a string. If the iterator is associated with a
3583 buffer, return the face at IT's current buffer position.
3584 Otherwise, use the iterator's base_face_id. */
3587 underlying_face_id (it
)
3590 int face_id
= it
->base_face_id
, i
;
3592 xassert (STRINGP (it
->string
));
3594 for (i
= it
->sp
- 1; i
>= 0; --i
)
3595 if (NILP (it
->stack
[i
].string
))
3596 face_id
= it
->stack
[i
].face_id
;
3602 /* Compute the face one character before or after the current position
3603 of IT. BEFORE_P non-zero means get the face in front of IT's
3604 position. Value is the id of the face. */
3607 face_before_or_after_it_pos (it
, before_p
)
3612 EMACS_INT next_check_charpos
;
3613 struct text_pos pos
;
3615 xassert (it
->s
== NULL
);
3617 if (STRINGP (it
->string
))
3619 int bufpos
, base_face_id
;
3621 /* No face change past the end of the string (for the case
3622 we are padding with spaces). No face change before the
3624 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3625 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3628 /* Set pos to the position before or after IT's current position. */
3630 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3632 /* For composition, we must check the character after the
3634 pos
= (it
->what
== IT_COMPOSITION
3635 ? string_pos (IT_STRING_CHARPOS (*it
)
3636 + it
->cmp_it
.nchars
, it
->string
)
3637 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3639 if (it
->current
.overlay_string_index
>= 0)
3640 bufpos
= IT_CHARPOS (*it
);
3644 base_face_id
= underlying_face_id (it
);
3646 /* Get the face for ASCII, or unibyte. */
3647 face_id
= face_at_string_position (it
->w
,
3651 it
->region_beg_charpos
,
3652 it
->region_end_charpos
,
3653 &next_check_charpos
,
3656 /* Correct the face for charsets different from ASCII. Do it
3657 for the multibyte case only. The face returned above is
3658 suitable for unibyte text if IT->string is unibyte. */
3659 if (STRING_MULTIBYTE (it
->string
))
3661 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3662 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3664 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3666 c
= string_char_and_length (p
, &len
);
3667 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3672 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3673 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3676 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3677 pos
= it
->current
.pos
;
3680 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3683 if (it
->what
== IT_COMPOSITION
)
3684 /* For composition, we must check the position after the
3686 pos
.charpos
+= it
->cmp_it
.nchars
, pos
.bytepos
+= it
->len
;
3688 INC_TEXT_POS (pos
, it
->multibyte_p
);
3691 /* Determine face for CHARSET_ASCII, or unibyte. */
3692 face_id
= face_at_buffer_position (it
->w
,
3694 it
->region_beg_charpos
,
3695 it
->region_end_charpos
,
3696 &next_check_charpos
,
3699 /* Correct the face for charsets different from ASCII. Do it
3700 for the multibyte case only. The face returned above is
3701 suitable for unibyte text if current_buffer is unibyte. */
3702 if (it
->multibyte_p
)
3704 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3705 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3706 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3715 /***********************************************************************
3717 ***********************************************************************/
3719 /* Set up iterator IT from invisible properties at its current
3720 position. Called from handle_stop. */
3722 static enum prop_handled
3723 handle_invisible_prop (it
)
3726 enum prop_handled handled
= HANDLED_NORMALLY
;
3728 if (STRINGP (it
->string
))
3730 extern Lisp_Object Qinvisible
;
3731 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3733 /* Get the value of the invisible text property at the
3734 current position. Value will be nil if there is no such
3736 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3737 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3740 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3742 handled
= HANDLED_RECOMPUTE_PROPS
;
3744 /* Get the position at which the next change of the
3745 invisible text property can be found in IT->string.
3746 Value will be nil if the property value is the same for
3747 all the rest of IT->string. */
3748 XSETINT (limit
, SCHARS (it
->string
));
3749 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3752 /* Text at current position is invisible. The next
3753 change in the property is at position end_charpos.
3754 Move IT's current position to that position. */
3755 if (INTEGERP (end_charpos
)
3756 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3758 struct text_pos old
;
3759 old
= it
->current
.string_pos
;
3760 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3761 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3765 /* The rest of the string is invisible. If this is an
3766 overlay string, proceed with the next overlay string
3767 or whatever comes and return a character from there. */
3768 if (it
->current
.overlay_string_index
>= 0)
3770 next_overlay_string (it
);
3771 /* Don't check for overlay strings when we just
3772 finished processing them. */
3773 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3777 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3778 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3786 EMACS_INT newpos
, next_stop
, start_charpos
;
3787 Lisp_Object pos
, prop
, overlay
;
3789 /* First of all, is there invisible text at this position? */
3790 start_charpos
= IT_CHARPOS (*it
);
3791 pos
= make_number (IT_CHARPOS (*it
));
3792 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3794 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3796 /* If we are on invisible text, skip over it. */
3797 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3799 /* Record whether we have to display an ellipsis for the
3801 int display_ellipsis_p
= invis_p
== 2;
3803 handled
= HANDLED_RECOMPUTE_PROPS
;
3805 /* Loop skipping over invisible text. The loop is left at
3806 ZV or with IT on the first char being visible again. */
3809 /* Try to skip some invisible text. Return value is the
3810 position reached which can be equal to IT's position
3811 if there is nothing invisible here. This skips both
3812 over invisible text properties and overlays with
3813 invisible property. */
3814 newpos
= skip_invisible (IT_CHARPOS (*it
),
3815 &next_stop
, ZV
, it
->window
);
3817 /* If we skipped nothing at all we weren't at invisible
3818 text in the first place. If everything to the end of
3819 the buffer was skipped, end the loop. */
3820 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3824 /* We skipped some characters but not necessarily
3825 all there are. Check if we ended up on visible
3826 text. Fget_char_property returns the property of
3827 the char before the given position, i.e. if we
3828 get invis_p = 0, this means that the char at
3829 newpos is visible. */
3830 pos
= make_number (newpos
);
3831 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3832 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3835 /* If we ended up on invisible text, proceed to
3836 skip starting with next_stop. */
3838 IT_CHARPOS (*it
) = next_stop
;
3840 /* If there are adjacent invisible texts, don't lose the
3841 second one's ellipsis. */
3843 display_ellipsis_p
= 1;
3847 /* The position newpos is now either ZV or on visible text. */
3848 IT_CHARPOS (*it
) = newpos
;
3849 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3851 /* If there are before-strings at the start of invisible
3852 text, and the text is invisible because of a text
3853 property, arrange to show before-strings because 20.x did
3854 it that way. (If the text is invisible because of an
3855 overlay property instead of a text property, this is
3856 already handled in the overlay code.) */
3858 && get_overlay_strings (it
, start_charpos
))
3860 handled
= HANDLED_RECOMPUTE_PROPS
;
3861 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3863 else if (display_ellipsis_p
)
3865 /* Make sure that the glyphs of the ellipsis will get
3866 correct `charpos' values. If we would not update
3867 it->position here, the glyphs would belong to the
3868 last visible character _before_ the invisible
3869 text, which confuses `set_cursor_from_row'.
3871 We use the last invisible position instead of the
3872 first because this way the cursor is always drawn on
3873 the first "." of the ellipsis, whenever PT is inside
3874 the invisible text. Otherwise the cursor would be
3875 placed _after_ the ellipsis when the point is after the
3876 first invisible character. */
3877 if (!STRINGP (it
->object
))
3879 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3880 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3883 /* Let the ellipsis display before
3884 considering any properties of the following char.
3885 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3886 handled
= HANDLED_RETURN
;
3895 /* Make iterator IT return `...' next.
3896 Replaces LEN characters from buffer. */
3899 setup_for_ellipsis (it
, len
)
3903 /* Use the display table definition for `...'. Invalid glyphs
3904 will be handled by the method returning elements from dpvec. */
3905 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3907 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3908 it
->dpvec
= v
->contents
;
3909 it
->dpend
= v
->contents
+ v
->size
;
3913 /* Default `...'. */
3914 it
->dpvec
= default_invis_vector
;
3915 it
->dpend
= default_invis_vector
+ 3;
3918 it
->dpvec_char_len
= len
;
3919 it
->current
.dpvec_index
= 0;
3920 it
->dpvec_face_id
= -1;
3922 /* Remember the current face id in case glyphs specify faces.
3923 IT's face is restored in set_iterator_to_next.
3924 saved_face_id was set to preceding char's face in handle_stop. */
3925 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3926 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3928 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3934 /***********************************************************************
3936 ***********************************************************************/
3938 /* Set up iterator IT from `display' property at its current position.
3939 Called from handle_stop.
3940 We return HANDLED_RETURN if some part of the display property
3941 overrides the display of the buffer text itself.
3942 Otherwise we return HANDLED_NORMALLY. */
3944 static enum prop_handled
3945 handle_display_prop (it
)
3948 Lisp_Object prop
, object
, overlay
;
3949 struct text_pos
*position
;
3950 /* Nonzero if some property replaces the display of the text itself. */
3951 int display_replaced_p
= 0;
3953 if (STRINGP (it
->string
))
3955 object
= it
->string
;
3956 position
= &it
->current
.string_pos
;
3960 XSETWINDOW (object
, it
->w
);
3961 position
= &it
->current
.pos
;
3964 /* Reset those iterator values set from display property values. */
3965 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3966 it
->space_width
= Qnil
;
3967 it
->font_height
= Qnil
;
3970 /* We don't support recursive `display' properties, i.e. string
3971 values that have a string `display' property, that have a string
3972 `display' property etc. */
3973 if (!it
->string_from_display_prop_p
)
3974 it
->area
= TEXT_AREA
;
3976 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3977 Qdisplay
, object
, &overlay
);
3979 return HANDLED_NORMALLY
;
3980 /* Now OVERLAY is the overlay that gave us this property, or nil
3981 if it was a text property. */
3983 if (!STRINGP (it
->string
))
3984 object
= it
->w
->buffer
;
3987 /* Simple properties. */
3988 && !EQ (XCAR (prop
), Qimage
)
3989 && !EQ (XCAR (prop
), Qspace
)
3990 && !EQ (XCAR (prop
), Qwhen
)
3991 && !EQ (XCAR (prop
), Qslice
)
3992 && !EQ (XCAR (prop
), Qspace_width
)
3993 && !EQ (XCAR (prop
), Qheight
)
3994 && !EQ (XCAR (prop
), Qraise
)
3995 /* Marginal area specifications. */
3996 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3997 && !EQ (XCAR (prop
), Qleft_fringe
)
3998 && !EQ (XCAR (prop
), Qright_fringe
)
3999 && !NILP (XCAR (prop
)))
4001 for (; CONSP (prop
); prop
= XCDR (prop
))
4003 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
4004 position
, display_replaced_p
))
4006 display_replaced_p
= 1;
4007 /* If some text in a string is replaced, `position' no
4008 longer points to the position of `object'. */
4009 if (STRINGP (object
))
4014 else if (VECTORP (prop
))
4017 for (i
= 0; i
< ASIZE (prop
); ++i
)
4018 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
4019 position
, display_replaced_p
))
4021 display_replaced_p
= 1;
4022 /* If some text in a string is replaced, `position' no
4023 longer points to the position of `object'. */
4024 if (STRINGP (object
))
4030 if (handle_single_display_spec (it
, prop
, object
, overlay
,
4032 display_replaced_p
= 1;
4035 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4039 /* Value is the position of the end of the `display' property starting
4040 at START_POS in OBJECT. */
4042 static struct text_pos
4043 display_prop_end (it
, object
, start_pos
)
4046 struct text_pos start_pos
;
4049 struct text_pos end_pos
;
4051 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4052 Qdisplay
, object
, Qnil
);
4053 CHARPOS (end_pos
) = XFASTINT (end
);
4054 if (STRINGP (object
))
4055 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4057 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4063 /* Set up IT from a single `display' specification PROP. OBJECT
4064 is the object in which the `display' property was found. *POSITION
4065 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4066 means that we previously saw a display specification which already
4067 replaced text display with something else, for example an image;
4068 we ignore such properties after the first one has been processed.
4070 OVERLAY is the overlay this `display' property came from,
4071 or nil if it was a text property.
4073 If PROP is a `space' or `image' specification, and in some other
4074 cases too, set *POSITION to the position where the `display'
4077 Value is non-zero if something was found which replaces the display
4078 of buffer or string text. */
4081 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4082 display_replaced_before_p
)
4086 Lisp_Object overlay
;
4087 struct text_pos
*position
;
4088 int display_replaced_before_p
;
4091 Lisp_Object location
, value
;
4092 struct text_pos start_pos
, save_pos
;
4095 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4096 If the result is non-nil, use VALUE instead of SPEC. */
4098 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4107 if (!NILP (form
) && !EQ (form
, Qt
))
4109 int count
= SPECPDL_INDEX ();
4110 struct gcpro gcpro1
;
4112 /* Bind `object' to the object having the `display' property, a
4113 buffer or string. Bind `position' to the position in the
4114 object where the property was found, and `buffer-position'
4115 to the current position in the buffer. */
4116 specbind (Qobject
, object
);
4117 specbind (Qposition
, make_number (CHARPOS (*position
)));
4118 specbind (Qbuffer_position
,
4119 make_number (STRINGP (object
)
4120 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4122 form
= safe_eval (form
);
4124 unbind_to (count
, Qnil
);
4130 /* Handle `(height HEIGHT)' specifications. */
4132 && EQ (XCAR (spec
), Qheight
)
4133 && CONSP (XCDR (spec
)))
4135 if (!FRAME_WINDOW_P (it
->f
))
4138 it
->font_height
= XCAR (XCDR (spec
));
4139 if (!NILP (it
->font_height
))
4141 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4142 int new_height
= -1;
4144 if (CONSP (it
->font_height
)
4145 && (EQ (XCAR (it
->font_height
), Qplus
)
4146 || EQ (XCAR (it
->font_height
), Qminus
))
4147 && CONSP (XCDR (it
->font_height
))
4148 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4150 /* `(+ N)' or `(- N)' where N is an integer. */
4151 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4152 if (EQ (XCAR (it
->font_height
), Qplus
))
4154 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4156 else if (FUNCTIONP (it
->font_height
))
4158 /* Call function with current height as argument.
4159 Value is the new height. */
4161 height
= safe_call1 (it
->font_height
,
4162 face
->lface
[LFACE_HEIGHT_INDEX
]);
4163 if (NUMBERP (height
))
4164 new_height
= XFLOATINT (height
);
4166 else if (NUMBERP (it
->font_height
))
4168 /* Value is a multiple of the canonical char height. */
4171 face
= FACE_FROM_ID (it
->f
,
4172 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4173 new_height
= (XFLOATINT (it
->font_height
)
4174 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4178 /* Evaluate IT->font_height with `height' bound to the
4179 current specified height to get the new height. */
4180 int count
= SPECPDL_INDEX ();
4182 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4183 value
= safe_eval (it
->font_height
);
4184 unbind_to (count
, Qnil
);
4186 if (NUMBERP (value
))
4187 new_height
= XFLOATINT (value
);
4191 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4197 /* Handle `(space-width WIDTH)'. */
4199 && EQ (XCAR (spec
), Qspace_width
)
4200 && CONSP (XCDR (spec
)))
4202 if (!FRAME_WINDOW_P (it
->f
))
4205 value
= XCAR (XCDR (spec
));
4206 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4207 it
->space_width
= value
;
4212 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4214 && EQ (XCAR (spec
), Qslice
))
4218 if (!FRAME_WINDOW_P (it
->f
))
4221 if (tem
= XCDR (spec
), CONSP (tem
))
4223 it
->slice
.x
= XCAR (tem
);
4224 if (tem
= XCDR (tem
), CONSP (tem
))
4226 it
->slice
.y
= XCAR (tem
);
4227 if (tem
= XCDR (tem
), CONSP (tem
))
4229 it
->slice
.width
= XCAR (tem
);
4230 if (tem
= XCDR (tem
), CONSP (tem
))
4231 it
->slice
.height
= XCAR (tem
);
4239 /* Handle `(raise FACTOR)'. */
4241 && EQ (XCAR (spec
), Qraise
)
4242 && CONSP (XCDR (spec
)))
4244 if (!FRAME_WINDOW_P (it
->f
))
4247 #ifdef HAVE_WINDOW_SYSTEM
4248 value
= XCAR (XCDR (spec
));
4249 if (NUMBERP (value
))
4251 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4252 it
->voffset
= - (XFLOATINT (value
)
4253 * (FONT_HEIGHT (face
->font
)));
4255 #endif /* HAVE_WINDOW_SYSTEM */
4260 /* Don't handle the other kinds of display specifications
4261 inside a string that we got from a `display' property. */
4262 if (it
->string_from_display_prop_p
)
4265 /* Characters having this form of property are not displayed, so
4266 we have to find the end of the property. */
4267 start_pos
= *position
;
4268 *position
= display_prop_end (it
, object
, start_pos
);
4271 /* Stop the scan at that end position--we assume that all
4272 text properties change there. */
4273 it
->stop_charpos
= position
->charpos
;
4275 /* Handle `(left-fringe BITMAP [FACE])'
4276 and `(right-fringe BITMAP [FACE])'. */
4278 && (EQ (XCAR (spec
), Qleft_fringe
)
4279 || EQ (XCAR (spec
), Qright_fringe
))
4280 && CONSP (XCDR (spec
)))
4282 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4285 if (!FRAME_WINDOW_P (it
->f
))
4286 /* If we return here, POSITION has been advanced
4287 across the text with this property. */
4290 #ifdef HAVE_WINDOW_SYSTEM
4291 value
= XCAR (XCDR (spec
));
4292 if (!SYMBOLP (value
)
4293 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4294 /* If we return here, POSITION has been advanced
4295 across the text with this property. */
4298 if (CONSP (XCDR (XCDR (spec
))))
4300 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4301 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4307 /* Save current settings of IT so that we can restore them
4308 when we are finished with the glyph property value. */
4310 save_pos
= it
->position
;
4311 it
->position
= *position
;
4313 it
->position
= save_pos
;
4315 it
->area
= TEXT_AREA
;
4316 it
->what
= IT_IMAGE
;
4317 it
->image_id
= -1; /* no image */
4318 it
->position
= start_pos
;
4319 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4320 it
->method
= GET_FROM_IMAGE
;
4321 it
->from_overlay
= Qnil
;
4322 it
->face_id
= face_id
;
4324 /* Say that we haven't consumed the characters with
4325 `display' property yet. The call to pop_it in
4326 set_iterator_to_next will clean this up. */
4327 *position
= start_pos
;
4329 if (EQ (XCAR (spec
), Qleft_fringe
))
4331 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4332 it
->left_user_fringe_face_id
= face_id
;
4336 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4337 it
->right_user_fringe_face_id
= face_id
;
4339 #endif /* HAVE_WINDOW_SYSTEM */
4343 /* Prepare to handle `((margin left-margin) ...)',
4344 `((margin right-margin) ...)' and `((margin nil) ...)'
4345 prefixes for display specifications. */
4346 location
= Qunbound
;
4347 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4351 value
= XCDR (spec
);
4353 value
= XCAR (value
);
4356 if (EQ (XCAR (tem
), Qmargin
)
4357 && (tem
= XCDR (tem
),
4358 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4360 || EQ (tem
, Qleft_margin
)
4361 || EQ (tem
, Qright_margin
))))
4365 if (EQ (location
, Qunbound
))
4371 /* After this point, VALUE is the property after any
4372 margin prefix has been stripped. It must be a string,
4373 an image specification, or `(space ...)'.
4375 LOCATION specifies where to display: `left-margin',
4376 `right-margin' or nil. */
4378 valid_p
= (STRINGP (value
)
4379 #ifdef HAVE_WINDOW_SYSTEM
4380 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4381 #endif /* not HAVE_WINDOW_SYSTEM */
4382 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4384 if (valid_p
&& !display_replaced_before_p
)
4386 /* Save current settings of IT so that we can restore them
4387 when we are finished with the glyph property value. */
4388 save_pos
= it
->position
;
4389 it
->position
= *position
;
4391 it
->position
= save_pos
;
4392 it
->from_overlay
= overlay
;
4394 if (NILP (location
))
4395 it
->area
= TEXT_AREA
;
4396 else if (EQ (location
, Qleft_margin
))
4397 it
->area
= LEFT_MARGIN_AREA
;
4399 it
->area
= RIGHT_MARGIN_AREA
;
4401 if (STRINGP (value
))
4404 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4405 it
->current
.overlay_string_index
= -1;
4406 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4407 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4408 it
->method
= GET_FROM_STRING
;
4409 it
->stop_charpos
= 0;
4410 it
->string_from_display_prop_p
= 1;
4411 /* Say that we haven't consumed the characters with
4412 `display' property yet. The call to pop_it in
4413 set_iterator_to_next will clean this up. */
4414 if (BUFFERP (object
))
4415 *position
= start_pos
;
4417 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4419 it
->method
= GET_FROM_STRETCH
;
4421 *position
= it
->position
= start_pos
;
4423 #ifdef HAVE_WINDOW_SYSTEM
4426 it
->what
= IT_IMAGE
;
4427 it
->image_id
= lookup_image (it
->f
, value
);
4428 it
->position
= start_pos
;
4429 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4430 it
->method
= GET_FROM_IMAGE
;
4432 /* Say that we haven't consumed the characters with
4433 `display' property yet. The call to pop_it in
4434 set_iterator_to_next will clean this up. */
4435 *position
= start_pos
;
4437 #endif /* HAVE_WINDOW_SYSTEM */
4442 /* Invalid property or property not supported. Restore
4443 POSITION to what it was before. */
4444 *position
= start_pos
;
4449 /* Check if SPEC is a display sub-property value whose text should be
4450 treated as intangible. */
4453 single_display_spec_intangible_p (prop
)
4456 /* Skip over `when FORM'. */
4457 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4471 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4472 we don't need to treat text as intangible. */
4473 if (EQ (XCAR (prop
), Qmargin
))
4481 || EQ (XCAR (prop
), Qleft_margin
)
4482 || EQ (XCAR (prop
), Qright_margin
))
4486 return (CONSP (prop
)
4487 && (EQ (XCAR (prop
), Qimage
)
4488 || EQ (XCAR (prop
), Qspace
)));
4492 /* Check if PROP is a display property value whose text should be
4493 treated as intangible. */
4496 display_prop_intangible_p (prop
)
4500 && CONSP (XCAR (prop
))
4501 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4503 /* A list of sub-properties. */
4504 while (CONSP (prop
))
4506 if (single_display_spec_intangible_p (XCAR (prop
)))
4511 else if (VECTORP (prop
))
4513 /* A vector of sub-properties. */
4515 for (i
= 0; i
< ASIZE (prop
); ++i
)
4516 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4520 return single_display_spec_intangible_p (prop
);
4526 /* Return 1 if PROP is a display sub-property value containing STRING. */
4529 single_display_spec_string_p (prop
, string
)
4530 Lisp_Object prop
, string
;
4532 if (EQ (string
, prop
))
4535 /* Skip over `when FORM'. */
4536 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4545 /* Skip over `margin LOCATION'. */
4546 if (EQ (XCAR (prop
), Qmargin
))
4557 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4561 /* Return 1 if STRING appears in the `display' property PROP. */
4564 display_prop_string_p (prop
, string
)
4565 Lisp_Object prop
, string
;
4568 && CONSP (XCAR (prop
))
4569 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4571 /* A list of sub-properties. */
4572 while (CONSP (prop
))
4574 if (single_display_spec_string_p (XCAR (prop
), string
))
4579 else if (VECTORP (prop
))
4581 /* A vector of sub-properties. */
4583 for (i
= 0; i
< ASIZE (prop
); ++i
)
4584 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4588 return single_display_spec_string_p (prop
, string
);
4593 /* Look for STRING in overlays and text properties in W's buffer,
4594 between character positions FROM and TO (excluding TO).
4595 BACK_P non-zero means look back (in this case, TO is supposed to be
4597 Value is the first character position where STRING was found, or
4598 zero if it wasn't found before hitting TO.
4600 W's buffer must be current.
4602 This function may only use code that doesn't eval because it is
4603 called asynchronously from note_mouse_highlight. */
4606 string_buffer_position_lim (w
, string
, from
, to
, back_p
)
4612 Lisp_Object limit
, prop
, pos
;
4615 pos
= make_number (from
);
4617 if (!back_p
) /* looking forward */
4619 limit
= make_number (min (to
, ZV
));
4620 while (!found
&& !EQ (pos
, limit
))
4622 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4623 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4626 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
4630 else /* looking back */
4632 limit
= make_number (max (to
, BEGV
));
4633 while (!found
&& !EQ (pos
, limit
))
4635 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4636 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4639 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4644 return found
? XINT (pos
) : 0;
4647 /* Determine which buffer position in W's buffer STRING comes from.
4648 AROUND_CHARPOS is an approximate position where it could come from.
4649 Value is the buffer position or 0 if it couldn't be determined.
4651 W's buffer must be current.
4653 This function is necessary because we don't record buffer positions
4654 in glyphs generated from strings (to keep struct glyph small).
4655 This function may only use code that doesn't eval because it is
4656 called asynchronously from note_mouse_highlight. */
4659 string_buffer_position (w
, string
, around_charpos
)
4662 EMACS_INT around_charpos
;
4664 Lisp_Object limit
, prop
, pos
;
4665 const int MAX_DISTANCE
= 1000;
4666 EMACS_INT found
= string_buffer_position_lim (w
, string
, around_charpos
,
4667 around_charpos
+ MAX_DISTANCE
,
4671 found
= string_buffer_position_lim (w
, string
, around_charpos
,
4672 around_charpos
- MAX_DISTANCE
, 1);
4678 /***********************************************************************
4679 `composition' property
4680 ***********************************************************************/
4682 /* Set up iterator IT from `composition' property at its current
4683 position. Called from handle_stop. */
4685 static enum prop_handled
4686 handle_composition_prop (it
)
4689 Lisp_Object prop
, string
;
4690 EMACS_INT pos
, pos_byte
, start
, end
;
4692 if (STRINGP (it
->string
))
4696 pos
= IT_STRING_CHARPOS (*it
);
4697 pos_byte
= IT_STRING_BYTEPOS (*it
);
4698 string
= it
->string
;
4699 s
= SDATA (string
) + pos_byte
;
4700 it
->c
= STRING_CHAR (s
);
4704 pos
= IT_CHARPOS (*it
);
4705 pos_byte
= IT_BYTEPOS (*it
);
4707 it
->c
= FETCH_CHAR (pos_byte
);
4710 /* If there's a valid composition and point is not inside of the
4711 composition (in the case that the composition is from the current
4712 buffer), draw a glyph composed from the composition components. */
4713 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4714 && COMPOSITION_VALID_P (start
, end
, prop
)
4715 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4719 if (STRINGP (it
->string
))
4720 pos_byte
= string_char_to_byte (it
->string
, start
);
4722 pos_byte
= CHAR_TO_BYTE (start
);
4724 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
4727 if (it
->cmp_it
.id
>= 0)
4730 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
4731 it
->cmp_it
.nglyphs
= -1;
4735 return HANDLED_NORMALLY
;
4740 /***********************************************************************
4742 ***********************************************************************/
4744 /* The following structure is used to record overlay strings for
4745 later sorting in load_overlay_strings. */
4747 struct overlay_entry
4749 Lisp_Object overlay
;
4756 /* Set up iterator IT from overlay strings at its current position.
4757 Called from handle_stop. */
4759 static enum prop_handled
4760 handle_overlay_change (it
)
4763 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4764 return HANDLED_RECOMPUTE_PROPS
;
4766 return HANDLED_NORMALLY
;
4770 /* Set up the next overlay string for delivery by IT, if there is an
4771 overlay string to deliver. Called by set_iterator_to_next when the
4772 end of the current overlay string is reached. If there are more
4773 overlay strings to display, IT->string and
4774 IT->current.overlay_string_index are set appropriately here.
4775 Otherwise IT->string is set to nil. */
4778 next_overlay_string (it
)
4781 ++it
->current
.overlay_string_index
;
4782 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4784 /* No more overlay strings. Restore IT's settings to what
4785 they were before overlay strings were processed, and
4786 continue to deliver from current_buffer. */
4788 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
4791 || (NILP (it
->string
)
4792 && it
->method
== GET_FROM_BUFFER
4793 && it
->stop_charpos
>= BEGV
4794 && it
->stop_charpos
<= it
->end_charpos
));
4795 it
->current
.overlay_string_index
= -1;
4796 it
->n_overlay_strings
= 0;
4798 /* If we're at the end of the buffer, record that we have
4799 processed the overlay strings there already, so that
4800 next_element_from_buffer doesn't try it again. */
4801 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4802 it
->overlay_strings_at_end_processed_p
= 1;
4806 /* There are more overlay strings to process. If
4807 IT->current.overlay_string_index has advanced to a position
4808 where we must load IT->overlay_strings with more strings, do
4810 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4812 if (it
->current
.overlay_string_index
&& i
== 0)
4813 load_overlay_strings (it
, 0);
4815 /* Initialize IT to deliver display elements from the overlay
4817 it
->string
= it
->overlay_strings
[i
];
4818 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4819 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4820 it
->method
= GET_FROM_STRING
;
4821 it
->stop_charpos
= 0;
4822 if (it
->cmp_it
.stop_pos
>= 0)
4823 it
->cmp_it
.stop_pos
= 0;
4830 /* Compare two overlay_entry structures E1 and E2. Used as a
4831 comparison function for qsort in load_overlay_strings. Overlay
4832 strings for the same position are sorted so that
4834 1. All after-strings come in front of before-strings, except
4835 when they come from the same overlay.
4837 2. Within after-strings, strings are sorted so that overlay strings
4838 from overlays with higher priorities come first.
4840 2. Within before-strings, strings are sorted so that overlay
4841 strings from overlays with higher priorities come last.
4843 Value is analogous to strcmp. */
4847 compare_overlay_entries (e1
, e2
)
4850 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4851 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4854 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4856 /* Let after-strings appear in front of before-strings if
4857 they come from different overlays. */
4858 if (EQ (entry1
->overlay
, entry2
->overlay
))
4859 result
= entry1
->after_string_p
? 1 : -1;
4861 result
= entry1
->after_string_p
? -1 : 1;
4863 else if (entry1
->after_string_p
)
4864 /* After-strings sorted in order of decreasing priority. */
4865 result
= entry2
->priority
- entry1
->priority
;
4867 /* Before-strings sorted in order of increasing priority. */
4868 result
= entry1
->priority
- entry2
->priority
;
4874 /* Load the vector IT->overlay_strings with overlay strings from IT's
4875 current buffer position, or from CHARPOS if that is > 0. Set
4876 IT->n_overlays to the total number of overlay strings found.
4878 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4879 a time. On entry into load_overlay_strings,
4880 IT->current.overlay_string_index gives the number of overlay
4881 strings that have already been loaded by previous calls to this
4884 IT->add_overlay_start contains an additional overlay start
4885 position to consider for taking overlay strings from, if non-zero.
4886 This position comes into play when the overlay has an `invisible'
4887 property, and both before and after-strings. When we've skipped to
4888 the end of the overlay, because of its `invisible' property, we
4889 nevertheless want its before-string to appear.
4890 IT->add_overlay_start will contain the overlay start position
4893 Overlay strings are sorted so that after-string strings come in
4894 front of before-string strings. Within before and after-strings,
4895 strings are sorted by overlay priority. See also function
4896 compare_overlay_entries. */
4899 load_overlay_strings (it
, charpos
)
4903 extern Lisp_Object Qwindow
, Qpriority
;
4904 Lisp_Object overlay
, window
, str
, invisible
;
4905 struct Lisp_Overlay
*ov
;
4908 int n
= 0, i
, j
, invis_p
;
4909 struct overlay_entry
*entries
4910 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4913 charpos
= IT_CHARPOS (*it
);
4915 /* Append the overlay string STRING of overlay OVERLAY to vector
4916 `entries' which has size `size' and currently contains `n'
4917 elements. AFTER_P non-zero means STRING is an after-string of
4919 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4922 Lisp_Object priority; \
4926 int new_size = 2 * size; \
4927 struct overlay_entry *old = entries; \
4929 (struct overlay_entry *) alloca (new_size \
4930 * sizeof *entries); \
4931 bcopy (old, entries, size * sizeof *entries); \
4935 entries[n].string = (STRING); \
4936 entries[n].overlay = (OVERLAY); \
4937 priority = Foverlay_get ((OVERLAY), Qpriority); \
4938 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
4939 entries[n].after_string_p = (AFTER_P); \
4944 /* Process overlay before the overlay center. */
4945 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
4947 XSETMISC (overlay
, ov
);
4948 xassert (OVERLAYP (overlay
));
4949 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4950 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4955 /* Skip this overlay if it doesn't start or end at IT's current
4957 if (end
!= charpos
&& start
!= charpos
)
4960 /* Skip this overlay if it doesn't apply to IT->w. */
4961 window
= Foverlay_get (overlay
, Qwindow
);
4962 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
4965 /* If the text ``under'' the overlay is invisible, both before-
4966 and after-strings from this overlay are visible; start and
4967 end position are indistinguishable. */
4968 invisible
= Foverlay_get (overlay
, Qinvisible
);
4969 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
4971 /* If overlay has a non-empty before-string, record it. */
4972 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
4973 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
4975 RECORD_OVERLAY_STRING (overlay
, str
, 0);
4977 /* If overlay has a non-empty after-string, record it. */
4978 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
4979 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
4981 RECORD_OVERLAY_STRING (overlay
, str
, 1);
4984 /* Process overlays after the overlay center. */
4985 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
4987 XSETMISC (overlay
, ov
);
4988 xassert (OVERLAYP (overlay
));
4989 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
4990 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
4992 if (start
> charpos
)
4995 /* Skip this overlay if it doesn't start or end at IT's current
4997 if (end
!= charpos
&& start
!= charpos
)
5000 /* Skip this overlay if it doesn't apply to IT->w. */
5001 window
= Foverlay_get (overlay
, Qwindow
);
5002 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5005 /* If the text ``under'' the overlay is invisible, it has a zero
5006 dimension, and both before- and after-strings apply. */
5007 invisible
= Foverlay_get (overlay
, Qinvisible
);
5008 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5010 /* If overlay has a non-empty before-string, record it. */
5011 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5012 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5014 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5016 /* If overlay has a non-empty after-string, record it. */
5017 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5018 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5020 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5023 #undef RECORD_OVERLAY_STRING
5027 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5029 /* Record the total number of strings to process. */
5030 it
->n_overlay_strings
= n
;
5032 /* IT->current.overlay_string_index is the number of overlay strings
5033 that have already been consumed by IT. Copy some of the
5034 remaining overlay strings to IT->overlay_strings. */
5036 j
= it
->current
.overlay_string_index
;
5037 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5039 it
->overlay_strings
[i
] = entries
[j
].string
;
5040 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5047 /* Get the first chunk of overlay strings at IT's current buffer
5048 position, or at CHARPOS if that is > 0. Value is non-zero if at
5049 least one overlay string was found. */
5052 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5057 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5058 process. This fills IT->overlay_strings with strings, and sets
5059 IT->n_overlay_strings to the total number of strings to process.
5060 IT->pos.overlay_string_index has to be set temporarily to zero
5061 because load_overlay_strings needs this; it must be set to -1
5062 when no overlay strings are found because a zero value would
5063 indicate a position in the first overlay string. */
5064 it
->current
.overlay_string_index
= 0;
5065 load_overlay_strings (it
, charpos
);
5067 /* If we found overlay strings, set up IT to deliver display
5068 elements from the first one. Otherwise set up IT to deliver
5069 from current_buffer. */
5070 if (it
->n_overlay_strings
)
5072 /* Make sure we know settings in current_buffer, so that we can
5073 restore meaningful values when we're done with the overlay
5076 compute_stop_pos (it
);
5077 xassert (it
->face_id
>= 0);
5079 /* Save IT's settings. They are restored after all overlay
5080 strings have been processed. */
5081 xassert (!compute_stop_p
|| it
->sp
== 0);
5083 /* When called from handle_stop, there might be an empty display
5084 string loaded. In that case, don't bother saving it. */
5085 if (!STRINGP (it
->string
) || SCHARS (it
->string
))
5088 /* Set up IT to deliver display elements from the first overlay
5090 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5091 it
->string
= it
->overlay_strings
[0];
5092 it
->from_overlay
= Qnil
;
5093 it
->stop_charpos
= 0;
5094 xassert (STRINGP (it
->string
));
5095 it
->end_charpos
= SCHARS (it
->string
);
5096 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5097 it
->method
= GET_FROM_STRING
;
5101 it
->current
.overlay_string_index
= -1;
5106 get_overlay_strings (it
, charpos
)
5111 it
->method
= GET_FROM_BUFFER
;
5113 (void) get_overlay_strings_1 (it
, charpos
, 1);
5117 /* Value is non-zero if we found at least one overlay string. */
5118 return STRINGP (it
->string
);
5123 /***********************************************************************
5124 Saving and restoring state
5125 ***********************************************************************/
5127 /* Save current settings of IT on IT->stack. Called, for example,
5128 before setting up IT for an overlay string, to be able to restore
5129 IT's settings to what they were after the overlay string has been
5136 struct iterator_stack_entry
*p
;
5138 xassert (it
->sp
< IT_STACK_SIZE
);
5139 p
= it
->stack
+ it
->sp
;
5141 p
->stop_charpos
= it
->stop_charpos
;
5142 p
->prev_stop
= it
->prev_stop
;
5143 p
->base_level_stop
= it
->base_level_stop
;
5144 p
->cmp_it
= it
->cmp_it
;
5145 xassert (it
->face_id
>= 0);
5146 p
->face_id
= it
->face_id
;
5147 p
->string
= it
->string
;
5148 p
->method
= it
->method
;
5149 p
->from_overlay
= it
->from_overlay
;
5152 case GET_FROM_IMAGE
:
5153 p
->u
.image
.object
= it
->object
;
5154 p
->u
.image
.image_id
= it
->image_id
;
5155 p
->u
.image
.slice
= it
->slice
;
5157 case GET_FROM_STRETCH
:
5158 p
->u
.stretch
.object
= it
->object
;
5161 p
->position
= it
->position
;
5162 p
->current
= it
->current
;
5163 p
->end_charpos
= it
->end_charpos
;
5164 p
->string_nchars
= it
->string_nchars
;
5166 p
->multibyte_p
= it
->multibyte_p
;
5167 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5168 p
->space_width
= it
->space_width
;
5169 p
->font_height
= it
->font_height
;
5170 p
->voffset
= it
->voffset
;
5171 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5172 p
->display_ellipsis_p
= 0;
5173 p
->line_wrap
= it
->line_wrap
;
5178 /* Restore IT's settings from IT->stack. Called, for example, when no
5179 more overlay strings must be processed, and we return to delivering
5180 display elements from a buffer, or when the end of a string from a
5181 `display' property is reached and we return to delivering display
5182 elements from an overlay string, or from a buffer. */
5188 struct iterator_stack_entry
*p
;
5190 xassert (it
->sp
> 0);
5192 p
= it
->stack
+ it
->sp
;
5193 it
->stop_charpos
= p
->stop_charpos
;
5194 it
->prev_stop
= p
->prev_stop
;
5195 it
->base_level_stop
= p
->base_level_stop
;
5196 it
->cmp_it
= p
->cmp_it
;
5197 it
->face_id
= p
->face_id
;
5198 it
->current
= p
->current
;
5199 it
->position
= p
->position
;
5200 it
->string
= p
->string
;
5201 it
->from_overlay
= p
->from_overlay
;
5202 if (NILP (it
->string
))
5203 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5204 it
->method
= p
->method
;
5207 case GET_FROM_IMAGE
:
5208 it
->image_id
= p
->u
.image
.image_id
;
5209 it
->object
= p
->u
.image
.object
;
5210 it
->slice
= p
->u
.image
.slice
;
5212 case GET_FROM_STRETCH
:
5213 it
->object
= p
->u
.comp
.object
;
5215 case GET_FROM_BUFFER
:
5216 it
->object
= it
->w
->buffer
;
5218 case GET_FROM_STRING
:
5219 it
->object
= it
->string
;
5221 case GET_FROM_DISPLAY_VECTOR
:
5223 it
->method
= GET_FROM_C_STRING
;
5224 else if (STRINGP (it
->string
))
5225 it
->method
= GET_FROM_STRING
;
5228 it
->method
= GET_FROM_BUFFER
;
5229 it
->object
= it
->w
->buffer
;
5232 it
->end_charpos
= p
->end_charpos
;
5233 it
->string_nchars
= p
->string_nchars
;
5235 it
->multibyte_p
= p
->multibyte_p
;
5236 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5237 it
->space_width
= p
->space_width
;
5238 it
->font_height
= p
->font_height
;
5239 it
->voffset
= p
->voffset
;
5240 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5241 it
->line_wrap
= p
->line_wrap
;
5246 /***********************************************************************
5248 ***********************************************************************/
5250 /* Set IT's current position to the previous line start. */
5253 back_to_previous_line_start (it
)
5256 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5257 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5261 /* Move IT to the next line start.
5263 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5264 we skipped over part of the text (as opposed to moving the iterator
5265 continuously over the text). Otherwise, don't change the value
5268 Newlines may come from buffer text, overlay strings, or strings
5269 displayed via the `display' property. That's the reason we can't
5270 simply use find_next_newline_no_quit.
5272 Note that this function may not skip over invisible text that is so
5273 because of text properties and immediately follows a newline. If
5274 it would, function reseat_at_next_visible_line_start, when called
5275 from set_iterator_to_next, would effectively make invisible
5276 characters following a newline part of the wrong glyph row, which
5277 leads to wrong cursor motion. */
5280 forward_to_next_line_start (it
, skipped_p
)
5284 int old_selective
, newline_found_p
, n
;
5285 const int MAX_NEWLINE_DISTANCE
= 500;
5287 /* If already on a newline, just consume it to avoid unintended
5288 skipping over invisible text below. */
5289 if (it
->what
== IT_CHARACTER
5291 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5293 set_iterator_to_next (it
, 0);
5298 /* Don't handle selective display in the following. It's (a)
5299 unnecessary because it's done by the caller, and (b) leads to an
5300 infinite recursion because next_element_from_ellipsis indirectly
5301 calls this function. */
5302 old_selective
= it
->selective
;
5305 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5306 from buffer text. */
5307 for (n
= newline_found_p
= 0;
5308 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5309 n
+= STRINGP (it
->string
) ? 0 : 1)
5311 if (!get_next_display_element (it
))
5313 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5314 set_iterator_to_next (it
, 0);
5317 /* If we didn't find a newline near enough, see if we can use a
5319 if (!newline_found_p
)
5321 int start
= IT_CHARPOS (*it
);
5322 int limit
= find_next_newline_no_quit (start
, 1);
5325 xassert (!STRINGP (it
->string
));
5327 /* If there isn't any `display' property in sight, and no
5328 overlays, we can just use the position of the newline in
5330 if (it
->stop_charpos
>= limit
5331 || ((pos
= Fnext_single_property_change (make_number (start
),
5333 Qnil
, make_number (limit
)),
5335 && next_overlay_change (start
) == ZV
))
5337 IT_CHARPOS (*it
) = limit
;
5338 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5339 *skipped_p
= newline_found_p
= 1;
5343 while (get_next_display_element (it
)
5344 && !newline_found_p
)
5346 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5347 set_iterator_to_next (it
, 0);
5352 it
->selective
= old_selective
;
5353 return newline_found_p
;
5357 /* Set IT's current position to the previous visible line start. Skip
5358 invisible text that is so either due to text properties or due to
5359 selective display. Caution: this does not change IT->current_x and
5363 back_to_previous_visible_line_start (it
)
5366 while (IT_CHARPOS (*it
) > BEGV
)
5368 back_to_previous_line_start (it
);
5370 if (IT_CHARPOS (*it
) <= BEGV
)
5373 /* If selective > 0, then lines indented more than its value are
5375 if (it
->selective
> 0
5376 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5377 (double) it
->selective
)) /* iftc */
5380 /* Check the newline before point for invisibility. */
5383 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5384 Qinvisible
, it
->window
);
5385 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5389 if (IT_CHARPOS (*it
) <= BEGV
)
5396 Lisp_Object val
, overlay
;
5398 /* If newline is part of a composition, continue from start of composition */
5399 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5400 && beg
< IT_CHARPOS (*it
))
5403 /* If newline is replaced by a display property, find start of overlay
5404 or interval and continue search from that point. */
5406 pos
= --IT_CHARPOS (it2
);
5409 it2
.string_from_display_prop_p
= 0;
5410 if (handle_display_prop (&it2
) == HANDLED_RETURN
5411 && !NILP (val
= get_char_property_and_overlay
5412 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5413 && (OVERLAYP (overlay
)
5414 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5415 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5418 /* Newline is not replaced by anything -- so we are done. */
5424 IT_CHARPOS (*it
) = beg
;
5425 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5429 it
->continuation_lines_width
= 0;
5431 xassert (IT_CHARPOS (*it
) >= BEGV
);
5432 xassert (IT_CHARPOS (*it
) == BEGV
5433 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5438 /* Reseat iterator IT at the previous visible line start. Skip
5439 invisible text that is so either due to text properties or due to
5440 selective display. At the end, update IT's overlay information,
5441 face information etc. */
5444 reseat_at_previous_visible_line_start (it
)
5447 back_to_previous_visible_line_start (it
);
5448 reseat (it
, it
->current
.pos
, 1);
5453 /* Reseat iterator IT on the next visible line start in the current
5454 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5455 preceding the line start. Skip over invisible text that is so
5456 because of selective display. Compute faces, overlays etc at the
5457 new position. Note that this function does not skip over text that
5458 is invisible because of text properties. */
5461 reseat_at_next_visible_line_start (it
, on_newline_p
)
5465 int newline_found_p
, skipped_p
= 0;
5467 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5469 /* Skip over lines that are invisible because they are indented
5470 more than the value of IT->selective. */
5471 if (it
->selective
> 0)
5472 while (IT_CHARPOS (*it
) < ZV
5473 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5474 (double) it
->selective
)) /* iftc */
5476 xassert (IT_BYTEPOS (*it
) == BEGV
5477 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5478 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5481 /* Position on the newline if that's what's requested. */
5482 if (on_newline_p
&& newline_found_p
)
5484 if (STRINGP (it
->string
))
5486 if (IT_STRING_CHARPOS (*it
) > 0)
5488 --IT_STRING_CHARPOS (*it
);
5489 --IT_STRING_BYTEPOS (*it
);
5492 else if (IT_CHARPOS (*it
) > BEGV
)
5496 reseat (it
, it
->current
.pos
, 0);
5500 reseat (it
, it
->current
.pos
, 0);
5507 /***********************************************************************
5508 Changing an iterator's position
5509 ***********************************************************************/
5511 /* Change IT's current position to POS in current_buffer. If FORCE_P
5512 is non-zero, always check for text properties at the new position.
5513 Otherwise, text properties are only looked up if POS >=
5514 IT->check_charpos of a property. */
5517 reseat (it
, pos
, force_p
)
5519 struct text_pos pos
;
5522 int original_pos
= IT_CHARPOS (*it
);
5524 reseat_1 (it
, pos
, 0);
5526 /* Determine where to check text properties. Avoid doing it
5527 where possible because text property lookup is very expensive. */
5529 || CHARPOS (pos
) > it
->stop_charpos
5530 || CHARPOS (pos
) < original_pos
)
5534 /* For bidi iteration, we need to prime prev_stop and
5535 base_level_stop with our best estimations. */
5536 if (CHARPOS (pos
) < it
->prev_stop
)
5538 handle_stop_backwards (it
, BEGV
);
5539 if (CHARPOS (pos
) < it
->base_level_stop
)
5540 it
->base_level_stop
= 0;
5542 else if (CHARPOS (pos
) > it
->stop_charpos
5543 && it
->stop_charpos
>= BEGV
)
5544 handle_stop_backwards (it
, it
->stop_charpos
);
5551 it
->prev_stop
= it
->base_level_stop
= 0;
5560 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5561 IT->stop_pos to POS, also. */
5564 reseat_1 (it
, pos
, set_stop_p
)
5566 struct text_pos pos
;
5569 /* Don't call this function when scanning a C string. */
5570 xassert (it
->s
== NULL
);
5572 /* POS must be a reasonable value. */
5573 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5575 it
->current
.pos
= it
->position
= pos
;
5576 it
->end_charpos
= ZV
;
5578 it
->current
.dpvec_index
= -1;
5579 it
->current
.overlay_string_index
= -1;
5580 IT_STRING_CHARPOS (*it
) = -1;
5581 IT_STRING_BYTEPOS (*it
) = -1;
5583 it
->string_from_display_prop_p
= 0;
5584 it
->method
= GET_FROM_BUFFER
;
5585 it
->object
= it
->w
->buffer
;
5586 it
->area
= TEXT_AREA
;
5587 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5589 it
->string_from_display_prop_p
= 0;
5590 it
->face_before_selective_p
= 0;
5592 it
->bidi_it
.first_elt
= 1;
5596 it
->stop_charpos
= CHARPOS (pos
);
5597 it
->base_level_stop
= CHARPOS (pos
);
5602 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5603 If S is non-null, it is a C string to iterate over. Otherwise,
5604 STRING gives a Lisp string to iterate over.
5606 If PRECISION > 0, don't return more then PRECISION number of
5607 characters from the string.
5609 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5610 characters have been returned. FIELD_WIDTH < 0 means an infinite
5613 MULTIBYTE = 0 means disable processing of multibyte characters,
5614 MULTIBYTE > 0 means enable it,
5615 MULTIBYTE < 0 means use IT->multibyte_p.
5617 IT must be initialized via a prior call to init_iterator before
5618 calling this function. */
5621 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5626 int precision
, field_width
, multibyte
;
5628 /* No region in strings. */
5629 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5631 /* No text property checks performed by default, but see below. */
5632 it
->stop_charpos
= -1;
5634 /* Set iterator position and end position. */
5635 bzero (&it
->current
, sizeof it
->current
);
5636 it
->current
.overlay_string_index
= -1;
5637 it
->current
.dpvec_index
= -1;
5638 xassert (charpos
>= 0);
5640 /* If STRING is specified, use its multibyteness, otherwise use the
5641 setting of MULTIBYTE, if specified. */
5643 it
->multibyte_p
= multibyte
> 0;
5647 xassert (STRINGP (string
));
5648 it
->string
= string
;
5650 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5651 it
->method
= GET_FROM_STRING
;
5652 it
->current
.string_pos
= string_pos (charpos
, string
);
5659 /* Note that we use IT->current.pos, not it->current.string_pos,
5660 for displaying C strings. */
5661 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5662 if (it
->multibyte_p
)
5664 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5665 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5669 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5670 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5673 it
->method
= GET_FROM_C_STRING
;
5676 /* PRECISION > 0 means don't return more than PRECISION characters
5678 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5679 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5681 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5682 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5683 FIELD_WIDTH < 0 means infinite field width. This is useful for
5684 padding with `-' at the end of a mode line. */
5685 if (field_width
< 0)
5686 field_width
= INFINITY
;
5687 if (field_width
> it
->end_charpos
- charpos
)
5688 it
->end_charpos
= charpos
+ field_width
;
5690 /* Use the standard display table for displaying strings. */
5691 if (DISP_TABLE_P (Vstandard_display_table
))
5692 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5694 it
->stop_charpos
= charpos
;
5700 /***********************************************************************
5702 ***********************************************************************/
5704 /* Map enum it_method value to corresponding next_element_from_* function. */
5706 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5708 next_element_from_buffer
,
5709 next_element_from_display_vector
,
5710 next_element_from_string
,
5711 next_element_from_c_string
,
5712 next_element_from_image
,
5713 next_element_from_stretch
5716 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5719 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
5720 (possibly with the following characters). */
5722 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS) \
5723 ((IT)->cmp_it.id >= 0 \
5724 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
5725 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
5726 (IT)->end_charpos, (IT)->w, \
5727 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
5731 /* Load IT's display element fields with information about the next
5732 display element from the current position of IT. Value is zero if
5733 end of buffer (or C string) is reached. */
5735 static struct frame
*last_escape_glyph_frame
= NULL
;
5736 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5737 static int last_escape_glyph_merged_face_id
= 0;
5740 get_next_display_element (it
)
5743 /* Non-zero means that we found a display element. Zero means that
5744 we hit the end of what we iterate over. Performance note: the
5745 function pointer `method' used here turns out to be faster than
5746 using a sequence of if-statements. */
5750 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5752 if (it
->what
== IT_CHARACTER
)
5754 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
5755 and only if (a) the resolved directionality of that character
5757 /* FIXME: Do we need an exception for characters from display
5759 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
5760 it
->c
= bidi_mirror_char (it
->c
);
5761 /* Map via display table or translate control characters.
5762 IT->c, IT->len etc. have been set to the next character by
5763 the function call above. If we have a display table, and it
5764 contains an entry for IT->c, translate it. Don't do this if
5765 IT->c itself comes from a display table, otherwise we could
5766 end up in an infinite recursion. (An alternative could be to
5767 count the recursion depth of this function and signal an
5768 error when a certain maximum depth is reached.) Is it worth
5770 if (success_p
&& it
->dpvec
== NULL
)
5773 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
5774 enum { char_is_other
= 0, char_is_nbsp
, char_is_soft_hyphen
}
5775 nbsp_or_shy
= char_is_other
;
5776 int decoded
= it
->c
;
5779 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5782 struct Lisp_Vector
*v
= XVECTOR (dv
);
5784 /* Return the first character from the display table
5785 entry, if not empty. If empty, don't display the
5786 current character. */
5789 it
->dpvec_char_len
= it
->len
;
5790 it
->dpvec
= v
->contents
;
5791 it
->dpend
= v
->contents
+ v
->size
;
5792 it
->current
.dpvec_index
= 0;
5793 it
->dpvec_face_id
= -1;
5794 it
->saved_face_id
= it
->face_id
;
5795 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5800 set_iterator_to_next (it
, 0);
5805 if (unibyte_display_via_language_environment
5806 && !ASCII_CHAR_P (it
->c
))
5807 decoded
= DECODE_CHAR (unibyte
, it
->c
);
5809 if (it
->c
>= 0x80 && ! NILP (Vnobreak_char_display
))
5811 if (it
->multibyte_p
)
5812 nbsp_or_shy
= (it
->c
== 0xA0 ? char_is_nbsp
5813 : it
->c
== 0xAD ? char_is_soft_hyphen
5815 else if (unibyte_display_via_language_environment
)
5816 nbsp_or_shy
= (decoded
== 0xA0 ? char_is_nbsp
5817 : decoded
== 0xAD ? char_is_soft_hyphen
5821 /* Translate control characters into `\003' or `^C' form.
5822 Control characters coming from a display table entry are
5823 currently not translated because we use IT->dpvec to hold
5824 the translation. This could easily be changed but I
5825 don't believe that it is worth doing.
5827 If it->multibyte_p is nonzero, non-printable non-ASCII
5828 characters are also translated to octal form.
5830 If it->multibyte_p is zero, eight-bit characters that
5831 don't have corresponding multibyte char code are also
5832 translated to octal form. */
5834 ? (it
->area
!= TEXT_AREA
5835 /* In mode line, treat \n, \t like other crl chars. */
5838 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
5839 || (it
->c
!= '\n' && it
->c
!= '\t'))
5842 ? ! CHAR_PRINTABLE_P (it
->c
)
5843 : (! unibyte_display_via_language_environment
5845 : (decoded
>= 0x80 && decoded
< 0xA0))))))
5847 /* IT->c is a control character which must be displayed
5848 either as '\003' or as `^C' where the '\\' and '^'
5849 can be defined in the display table. Fill
5850 IT->ctl_chars with glyphs for what we have to
5851 display. Then, set IT->dpvec to these glyphs. */
5854 int face_id
, lface_id
= 0 ;
5857 /* Handle control characters with ^. */
5859 if (it
->c
< 128 && it
->ctl_arrow_p
)
5863 g
= '^'; /* default glyph for Control */
5864 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5866 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5867 && GLYPH_CODE_CHAR_VALID_P (gc
))
5869 g
= GLYPH_CODE_CHAR (gc
);
5870 lface_id
= GLYPH_CODE_FACE (gc
);
5874 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5876 else if (it
->f
== last_escape_glyph_frame
5877 && it
->face_id
== last_escape_glyph_face_id
)
5879 face_id
= last_escape_glyph_merged_face_id
;
5883 /* Merge the escape-glyph face into the current face. */
5884 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5886 last_escape_glyph_frame
= it
->f
;
5887 last_escape_glyph_face_id
= it
->face_id
;
5888 last_escape_glyph_merged_face_id
= face_id
;
5891 XSETINT (it
->ctl_chars
[0], g
);
5892 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5894 goto display_control
;
5897 /* Handle non-break space in the mode where it only gets
5900 if (EQ (Vnobreak_char_display
, Qt
)
5901 && nbsp_or_shy
== char_is_nbsp
)
5903 /* Merge the no-break-space face into the current face. */
5904 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5908 XSETINT (it
->ctl_chars
[0], ' ');
5910 goto display_control
;
5913 /* Handle sequences that start with the "escape glyph". */
5915 /* the default escape glyph is \. */
5916 escape_glyph
= '\\';
5919 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5920 && GLYPH_CODE_CHAR_VALID_P (gc
))
5922 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5923 lface_id
= GLYPH_CODE_FACE (gc
);
5927 /* The display table specified a face.
5928 Merge it into face_id and also into escape_glyph. */
5929 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5932 else if (it
->f
== last_escape_glyph_frame
5933 && it
->face_id
== last_escape_glyph_face_id
)
5935 face_id
= last_escape_glyph_merged_face_id
;
5939 /* Merge the escape-glyph face into the current face. */
5940 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5942 last_escape_glyph_frame
= it
->f
;
5943 last_escape_glyph_face_id
= it
->face_id
;
5944 last_escape_glyph_merged_face_id
= face_id
;
5947 /* Handle soft hyphens in the mode where they only get
5950 if (EQ (Vnobreak_char_display
, Qt
)
5951 && nbsp_or_shy
== char_is_soft_hyphen
)
5954 XSETINT (it
->ctl_chars
[0], '-');
5956 goto display_control
;
5959 /* Handle non-break space and soft hyphen
5960 with the escape glyph. */
5964 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5965 it
->c
= (nbsp_or_shy
== char_is_nbsp
? ' ' : '-');
5966 XSETINT (it
->ctl_chars
[1], it
->c
);
5968 goto display_control
;
5972 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5976 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5977 if (CHAR_BYTE8_P (it
->c
))
5979 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5982 else if (it
->c
< 256)
5989 /* It's an invalid character, which shouldn't
5990 happen actually, but due to bugs it may
5991 happen. Let's print the char as is, there's
5992 not much meaningful we can do with it. */
5994 str
[1] = it
->c
>> 8;
5995 str
[2] = it
->c
>> 16;
5996 str
[3] = it
->c
>> 24;
6000 for (i
= 0; i
< len
; i
++)
6003 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
6004 /* Insert three more glyphs into IT->ctl_chars for
6005 the octal display of the character. */
6006 g
= ((str
[i
] >> 6) & 7) + '0';
6007 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
6008 g
= ((str
[i
] >> 3) & 7) + '0';
6009 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
6010 g
= (str
[i
] & 7) + '0';
6011 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
6017 /* Set up IT->dpvec and return first character from it. */
6018 it
->dpvec_char_len
= it
->len
;
6019 it
->dpvec
= it
->ctl_chars
;
6020 it
->dpend
= it
->dpvec
+ ctl_len
;
6021 it
->current
.dpvec_index
= 0;
6022 it
->dpvec_face_id
= face_id
;
6023 it
->saved_face_id
= it
->face_id
;
6024 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6031 #ifdef HAVE_WINDOW_SYSTEM
6032 /* Adjust face id for a multibyte character. There are no multibyte
6033 character in unibyte text. */
6034 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6037 && FRAME_WINDOW_P (it
->f
))
6039 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6041 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6043 /* Automatic composition with glyph-string. */
6044 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6046 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6050 int pos
= (it
->s
? -1
6051 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6052 : IT_CHARPOS (*it
));
6054 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
6059 /* Is this character the last one of a run of characters with
6060 box? If yes, set IT->end_of_box_run_p to 1. */
6064 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6066 int face_id
= underlying_face_id (it
);
6067 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6071 if (face
->box
== FACE_NO_BOX
)
6073 /* If the box comes from face properties in a
6074 display string, check faces in that string. */
6075 int string_face_id
= face_after_it_pos (it
);
6076 it
->end_of_box_run_p
6077 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6080 /* Otherwise, the box comes from the underlying face.
6081 If this is the last string character displayed, check
6082 the next buffer location. */
6083 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6084 && (it
->current
.overlay_string_index
6085 == it
->n_overlay_strings
- 1))
6089 struct text_pos pos
= it
->current
.pos
;
6090 INC_TEXT_POS (pos
, it
->multibyte_p
);
6092 next_face_id
= face_at_buffer_position
6093 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6094 it
->region_end_charpos
, &ignore
,
6095 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6097 it
->end_of_box_run_p
6098 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6105 int face_id
= face_after_it_pos (it
);
6106 it
->end_of_box_run_p
6107 = (face_id
!= it
->face_id
6108 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6112 /* Value is 0 if end of buffer or string reached. */
6117 /* Move IT to the next display element.
6119 RESEAT_P non-zero means if called on a newline in buffer text,
6120 skip to the next visible line start.
6122 Functions get_next_display_element and set_iterator_to_next are
6123 separate because I find this arrangement easier to handle than a
6124 get_next_display_element function that also increments IT's
6125 position. The way it is we can first look at an iterator's current
6126 display element, decide whether it fits on a line, and if it does,
6127 increment the iterator position. The other way around we probably
6128 would either need a flag indicating whether the iterator has to be
6129 incremented the next time, or we would have to implement a
6130 decrement position function which would not be easy to write. */
6133 set_iterator_to_next (it
, reseat_p
)
6137 /* Reset flags indicating start and end of a sequence of characters
6138 with box. Reset them at the start of this function because
6139 moving the iterator to a new position might set them. */
6140 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6144 case GET_FROM_BUFFER
:
6145 /* The current display element of IT is a character from
6146 current_buffer. Advance in the buffer, and maybe skip over
6147 invisible lines that are so because of selective display. */
6148 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6149 reseat_at_next_visible_line_start (it
, 0);
6150 else if (it
->cmp_it
.id
>= 0)
6152 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6153 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6154 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6155 it
->cmp_it
.from
= it
->cmp_it
.to
;
6159 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
6160 IT_BYTEPOS (*it
), it
->stop_charpos
,
6166 xassert (it
->len
!= 0);
6170 IT_BYTEPOS (*it
) += it
->len
;
6171 IT_CHARPOS (*it
) += 1;
6175 /* If this is a new paragraph, determine its base
6176 direction (a.k.a. its base embedding level). */
6177 if (it
->bidi_it
.new_paragraph
)
6178 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6179 bidi_get_next_char_visually (&it
->bidi_it
);
6180 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6181 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6183 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6187 case GET_FROM_C_STRING
:
6188 /* Current display element of IT is from a C string. */
6189 IT_BYTEPOS (*it
) += it
->len
;
6190 IT_CHARPOS (*it
) += 1;
6193 case GET_FROM_DISPLAY_VECTOR
:
6194 /* Current display element of IT is from a display table entry.
6195 Advance in the display table definition. Reset it to null if
6196 end reached, and continue with characters from buffers/
6198 ++it
->current
.dpvec_index
;
6200 /* Restore face of the iterator to what they were before the
6201 display vector entry (these entries may contain faces). */
6202 it
->face_id
= it
->saved_face_id
;
6204 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6206 int recheck_faces
= it
->ellipsis_p
;
6209 it
->method
= GET_FROM_C_STRING
;
6210 else if (STRINGP (it
->string
))
6211 it
->method
= GET_FROM_STRING
;
6214 it
->method
= GET_FROM_BUFFER
;
6215 it
->object
= it
->w
->buffer
;
6219 it
->current
.dpvec_index
= -1;
6221 /* Skip over characters which were displayed via IT->dpvec. */
6222 if (it
->dpvec_char_len
< 0)
6223 reseat_at_next_visible_line_start (it
, 1);
6224 else if (it
->dpvec_char_len
> 0)
6226 if (it
->method
== GET_FROM_STRING
6227 && it
->n_overlay_strings
> 0)
6228 it
->ignore_overlay_strings_at_pos_p
= 1;
6229 it
->len
= it
->dpvec_char_len
;
6230 set_iterator_to_next (it
, reseat_p
);
6233 /* Maybe recheck faces after display vector */
6235 it
->stop_charpos
= IT_CHARPOS (*it
);
6239 case GET_FROM_STRING
:
6240 /* Current display element is a character from a Lisp string. */
6241 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6242 if (it
->cmp_it
.id
>= 0)
6244 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6245 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6246 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
6247 it
->cmp_it
.from
= it
->cmp_it
.to
;
6251 composition_compute_stop_pos (&it
->cmp_it
,
6252 IT_STRING_CHARPOS (*it
),
6253 IT_STRING_BYTEPOS (*it
),
6254 it
->stop_charpos
, it
->string
);
6259 IT_STRING_BYTEPOS (*it
) += it
->len
;
6260 IT_STRING_CHARPOS (*it
) += 1;
6263 consider_string_end
:
6265 if (it
->current
.overlay_string_index
>= 0)
6267 /* IT->string is an overlay string. Advance to the
6268 next, if there is one. */
6269 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6272 next_overlay_string (it
);
6274 setup_for_ellipsis (it
, 0);
6279 /* IT->string is not an overlay string. If we reached
6280 its end, and there is something on IT->stack, proceed
6281 with what is on the stack. This can be either another
6282 string, this time an overlay string, or a buffer. */
6283 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6287 if (it
->method
== GET_FROM_STRING
)
6288 goto consider_string_end
;
6293 case GET_FROM_IMAGE
:
6294 case GET_FROM_STRETCH
:
6295 /* The position etc with which we have to proceed are on
6296 the stack. The position may be at the end of a string,
6297 if the `display' property takes up the whole string. */
6298 xassert (it
->sp
> 0);
6300 if (it
->method
== GET_FROM_STRING
)
6301 goto consider_string_end
;
6305 /* There are no other methods defined, so this should be a bug. */
6309 xassert (it
->method
!= GET_FROM_STRING
6310 || (STRINGP (it
->string
)
6311 && IT_STRING_CHARPOS (*it
) >= 0));
6314 /* Load IT's display element fields with information about the next
6315 display element which comes from a display table entry or from the
6316 result of translating a control character to one of the forms `^C'
6319 IT->dpvec holds the glyphs to return as characters.
6320 IT->saved_face_id holds the face id before the display vector--it
6321 is restored into IT->face_id in set_iterator_to_next. */
6324 next_element_from_display_vector (it
)
6330 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6332 it
->face_id
= it
->saved_face_id
;
6334 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6335 That seemed totally bogus - so I changed it... */
6336 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6338 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6340 it
->c
= GLYPH_CODE_CHAR (gc
);
6341 it
->len
= CHAR_BYTES (it
->c
);
6343 /* The entry may contain a face id to use. Such a face id is
6344 the id of a Lisp face, not a realized face. A face id of
6345 zero means no face is specified. */
6346 if (it
->dpvec_face_id
>= 0)
6347 it
->face_id
= it
->dpvec_face_id
;
6350 int lface_id
= GLYPH_CODE_FACE (gc
);
6352 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6357 /* Display table entry is invalid. Return a space. */
6358 it
->c
= ' ', it
->len
= 1;
6360 /* Don't change position and object of the iterator here. They are
6361 still the values of the character that had this display table
6362 entry or was translated, and that's what we want. */
6363 it
->what
= IT_CHARACTER
;
6368 /* Load IT with the next display element from Lisp string IT->string.
6369 IT->current.string_pos is the current position within the string.
6370 If IT->current.overlay_string_index >= 0, the Lisp string is an
6374 next_element_from_string (it
)
6377 struct text_pos position
;
6379 xassert (STRINGP (it
->string
));
6380 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6381 position
= it
->current
.string_pos
;
6383 /* Time to check for invisible text? */
6384 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6385 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6389 /* Since a handler may have changed IT->method, we must
6391 return GET_NEXT_DISPLAY_ELEMENT (it
);
6394 if (it
->current
.overlay_string_index
>= 0)
6396 /* Get the next character from an overlay string. In overlay
6397 strings, There is no field width or padding with spaces to
6399 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6404 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6405 IT_STRING_BYTEPOS (*it
))
6406 && next_element_from_composition (it
))
6410 else if (STRING_MULTIBYTE (it
->string
))
6412 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6413 const unsigned char *s
= (SDATA (it
->string
)
6414 + IT_STRING_BYTEPOS (*it
));
6415 it
->c
= string_char_and_length (s
, &it
->len
);
6419 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6425 /* Get the next character from a Lisp string that is not an
6426 overlay string. Such strings come from the mode line, for
6427 example. We may have to pad with spaces, or truncate the
6428 string. See also next_element_from_c_string. */
6429 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6434 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6436 /* Pad with spaces. */
6437 it
->c
= ' ', it
->len
= 1;
6438 CHARPOS (position
) = BYTEPOS (position
) = -1;
6440 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
6441 IT_STRING_BYTEPOS (*it
))
6442 && next_element_from_composition (it
))
6446 else if (STRING_MULTIBYTE (it
->string
))
6448 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6449 const unsigned char *s
= (SDATA (it
->string
)
6450 + IT_STRING_BYTEPOS (*it
));
6451 it
->c
= string_char_and_length (s
, &it
->len
);
6455 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6460 /* Record what we have and where it came from. */
6461 it
->what
= IT_CHARACTER
;
6462 it
->object
= it
->string
;
6463 it
->position
= position
;
6468 /* Load IT with next display element from C string IT->s.
6469 IT->string_nchars is the maximum number of characters to return
6470 from the string. IT->end_charpos may be greater than
6471 IT->string_nchars when this function is called, in which case we
6472 may have to return padding spaces. Value is zero if end of string
6473 reached, including padding spaces. */
6476 next_element_from_c_string (it
)
6482 it
->what
= IT_CHARACTER
;
6483 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6486 /* IT's position can be greater IT->string_nchars in case a field
6487 width or precision has been specified when the iterator was
6489 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6491 /* End of the game. */
6495 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6497 /* Pad with spaces. */
6498 it
->c
= ' ', it
->len
= 1;
6499 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6501 else if (it
->multibyte_p
)
6503 /* Implementation note: The calls to strlen apparently aren't a
6504 performance problem because there is no noticeable performance
6505 difference between Emacs running in unibyte or multibyte mode. */
6506 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6507 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
6510 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6516 /* Set up IT to return characters from an ellipsis, if appropriate.
6517 The definition of the ellipsis glyphs may come from a display table
6518 entry. This function fills IT with the first glyph from the
6519 ellipsis if an ellipsis is to be displayed. */
6522 next_element_from_ellipsis (it
)
6525 if (it
->selective_display_ellipsis_p
)
6526 setup_for_ellipsis (it
, it
->len
);
6529 /* The face at the current position may be different from the
6530 face we find after the invisible text. Remember what it
6531 was in IT->saved_face_id, and signal that it's there by
6532 setting face_before_selective_p. */
6533 it
->saved_face_id
= it
->face_id
;
6534 it
->method
= GET_FROM_BUFFER
;
6535 it
->object
= it
->w
->buffer
;
6536 reseat_at_next_visible_line_start (it
, 1);
6537 it
->face_before_selective_p
= 1;
6540 return GET_NEXT_DISPLAY_ELEMENT (it
);
6544 /* Deliver an image display element. The iterator IT is already
6545 filled with image information (done in handle_display_prop). Value
6550 next_element_from_image (it
)
6553 it
->what
= IT_IMAGE
;
6558 /* Fill iterator IT with next display element from a stretch glyph
6559 property. IT->object is the value of the text property. Value is
6563 next_element_from_stretch (it
)
6566 it
->what
= IT_STRETCH
;
6570 /* Scan forward from CHARPOS in the current buffer, until we find a
6571 stop position > current IT's position. Then handle the stop
6572 position before that. This is called when we bump into a stop
6573 position while reordering bidirectional text. */
6576 handle_stop_backwards (it
, charpos
)
6580 EMACS_INT where_we_are
= IT_CHARPOS (*it
);
6581 struct display_pos save_current
= it
->current
;
6582 struct text_pos save_position
= it
->position
;
6583 struct text_pos pos1
;
6584 EMACS_INT next_stop
;
6586 /* Scan in strict logical order. */
6590 it
->prev_stop
= charpos
;
6591 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
6592 reseat_1 (it
, pos1
, 0);
6593 compute_stop_pos (it
);
6594 /* We must advance forward, right? */
6595 if (it
->stop_charpos
<= it
->prev_stop
)
6597 charpos
= it
->stop_charpos
;
6599 while (charpos
<= where_we_are
);
6601 next_stop
= it
->stop_charpos
;
6602 it
->stop_charpos
= it
->prev_stop
;
6604 it
->stop_charpos
= next_stop
;
6606 it
->current
= save_current
;
6607 it
->position
= save_position
;
6610 /* Load IT with the next display element from current_buffer. Value
6611 is zero if end of buffer reached. IT->stop_charpos is the next
6612 position at which to stop and check for text properties or buffer
6616 next_element_from_buffer (it
)
6621 xassert (IT_CHARPOS (*it
) >= BEGV
);
6623 /* With bidi reordering, the character to display might not be the
6624 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
6625 we were reseat()ed to a new buffer position, which is potentially
6626 a different paragraph. */
6627 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
6629 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6630 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6631 /* If we are at the beginning of a line, we can produce the next
6632 element right away. */
6633 if (it
->bidi_it
.bytepos
== BEGV_BYTE
6634 /* FIXME: Should support all Unicode line separators. */
6635 || FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
6636 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')
6638 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6639 /* If the paragraph base direction is R2L, its glyphs should
6641 if (it
->glyph_row
&& (it
->bidi_it
.level_stack
[0].level
& 1) != 0)
6642 it
->glyph_row
->reversed_p
= 1;
6643 bidi_get_next_char_visually (&it
->bidi_it
);
6647 int orig_bytepos
= IT_BYTEPOS (*it
);
6649 /* We need to prime the bidi iterator starting at the line's
6650 beginning, before we will be able to produce the next
6652 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), -1);
6653 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
6654 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
6655 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
6656 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
);
6657 if (it
->glyph_row
&& (it
->bidi_it
.level_stack
[0].level
& 1) != 0)
6658 it
->glyph_row
->reversed_p
= 1;
6660 /* Now return to buffer position where we were asked to
6661 get the next display element, and produce that. */
6662 bidi_get_next_char_visually (&it
->bidi_it
);
6663 } while (it
->bidi_it
.bytepos
!= orig_bytepos
6664 && it
->bidi_it
.bytepos
< ZV_BYTE
);
6667 it
->bidi_it
.first_elt
= 0; /* paranoia: bidi.c does this */
6668 /* Adjust IT's position information to where we ended up. */
6669 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6670 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6671 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
6674 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6676 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6678 int overlay_strings_follow_p
;
6680 /* End of the game, except when overlay strings follow that
6681 haven't been returned yet. */
6682 if (it
->overlay_strings_at_end_processed_p
)
6683 overlay_strings_follow_p
= 0;
6686 it
->overlay_strings_at_end_processed_p
= 1;
6687 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6690 if (overlay_strings_follow_p
)
6691 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6695 it
->position
= it
->current
.pos
;
6699 else if (!(!it
->bidi_p
6700 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6701 || IT_CHARPOS (*it
) == it
->stop_charpos
))
6703 /* With bidi non-linear iteration, we could find ourselves
6704 far beyond the last computed stop_charpos, with several
6705 other stop positions in between that we missed. Scan
6706 them all now, in buffer's logical order, until we find
6707 and handle the last stop_charpos that precedes our
6708 current position. */
6709 handle_stop_backwards (it
, it
->stop_charpos
);
6710 return GET_NEXT_DISPLAY_ELEMENT (it
);
6716 /* Take note of the stop position we just moved across,
6717 for when we will move back across it. */
6718 it
->prev_stop
= it
->stop_charpos
;
6719 /* If we are at base paragraph embedding level, take
6720 note of the last stop position seen at this
6722 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
6723 it
->base_level_stop
= it
->stop_charpos
;
6726 return GET_NEXT_DISPLAY_ELEMENT (it
);
6730 /* We can sometimes back up for reasons that have nothing
6731 to do with bidi reordering. E.g., compositions. The
6732 code below is only needed when we are above the base
6733 embedding level, so test for that explicitly. */
6734 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
)
6735 && IT_CHARPOS (*it
) < it
->prev_stop
)
6737 if (it
->base_level_stop
<= 0)
6738 it
->base_level_stop
= BEGV
;
6739 if (IT_CHARPOS (*it
) < it
->base_level_stop
)
6741 handle_stop_backwards (it
, it
->base_level_stop
);
6742 return GET_NEXT_DISPLAY_ELEMENT (it
);
6746 /* No face changes, overlays etc. in sight, so just return a
6747 character from current_buffer. */
6750 /* Maybe run the redisplay end trigger hook. Performance note:
6751 This doesn't seem to cost measurable time. */
6752 if (it
->redisplay_end_trigger_charpos
6754 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6755 run_redisplay_end_trigger_hook (it
);
6757 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
))
6758 && next_element_from_composition (it
))
6763 /* Get the next character, maybe multibyte. */
6764 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6765 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6766 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
6768 it
->c
= *p
, it
->len
= 1;
6770 /* Record what we have and where it came from. */
6771 it
->what
= IT_CHARACTER
;
6772 it
->object
= it
->w
->buffer
;
6773 it
->position
= it
->current
.pos
;
6775 /* Normally we return the character found above, except when we
6776 really want to return an ellipsis for selective display. */
6781 /* A value of selective > 0 means hide lines indented more
6782 than that number of columns. */
6783 if (it
->selective
> 0
6784 && IT_CHARPOS (*it
) + 1 < ZV
6785 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6786 IT_BYTEPOS (*it
) + 1,
6787 (double) it
->selective
)) /* iftc */
6789 success_p
= next_element_from_ellipsis (it
);
6790 it
->dpvec_char_len
= -1;
6793 else if (it
->c
== '\r' && it
->selective
== -1)
6795 /* A value of selective == -1 means that everything from the
6796 CR to the end of the line is invisible, with maybe an
6797 ellipsis displayed for it. */
6798 success_p
= next_element_from_ellipsis (it
);
6799 it
->dpvec_char_len
= -1;
6804 /* Value is zero if end of buffer reached. */
6805 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6810 /* Run the redisplay end trigger hook for IT. */
6813 run_redisplay_end_trigger_hook (it
)
6816 Lisp_Object args
[3];
6818 /* IT->glyph_row should be non-null, i.e. we should be actually
6819 displaying something, or otherwise we should not run the hook. */
6820 xassert (it
->glyph_row
);
6822 /* Set up hook arguments. */
6823 args
[0] = Qredisplay_end_trigger_functions
;
6824 args
[1] = it
->window
;
6825 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6826 it
->redisplay_end_trigger_charpos
= 0;
6828 /* Since we are *trying* to run these functions, don't try to run
6829 them again, even if they get an error. */
6830 it
->w
->redisplay_end_trigger
= Qnil
;
6831 Frun_hook_with_args (3, args
);
6833 /* Notice if it changed the face of the character we are on. */
6834 handle_face_prop (it
);
6838 /* Deliver a composition display element. Unlike the other
6839 next_element_from_XXX, this function is not registered in the array
6840 get_next_element[]. It is called from next_element_from_buffer and
6841 next_element_from_string when necessary. */
6844 next_element_from_composition (it
)
6847 it
->what
= IT_COMPOSITION
;
6848 it
->len
= it
->cmp_it
.nbytes
;
6849 if (STRINGP (it
->string
))
6853 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6854 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6857 it
->position
= it
->current
.string_pos
;
6858 it
->object
= it
->string
;
6859 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
6860 IT_STRING_BYTEPOS (*it
), it
->string
);
6866 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
6867 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
6870 it
->position
= it
->current
.pos
;
6871 it
->object
= it
->w
->buffer
;
6872 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
6873 IT_BYTEPOS (*it
), Qnil
);
6880 /***********************************************************************
6881 Moving an iterator without producing glyphs
6882 ***********************************************************************/
6884 /* Check if iterator is at a position corresponding to a valid buffer
6885 position after some move_it_ call. */
6887 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6888 ((it)->method == GET_FROM_STRING \
6889 ? IT_STRING_CHARPOS (*it) == 0 \
6893 /* Move iterator IT to a specified buffer or X position within one
6894 line on the display without producing glyphs.
6896 OP should be a bit mask including some or all of these bits:
6897 MOVE_TO_X: Stop upon reaching x-position TO_X.
6898 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
6899 Regardless of OP's value, stop upon reaching the end of the display line.
6901 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6902 This means, in particular, that TO_X includes window's horizontal
6905 The return value has several possible values that
6906 say what condition caused the scan to stop:
6908 MOVE_POS_MATCH_OR_ZV
6909 - when TO_POS or ZV was reached.
6912 -when TO_X was reached before TO_POS or ZV were reached.
6915 - when we reached the end of the display area and the line must
6919 - when we reached the end of the display area and the line is
6923 - when we stopped at a line end, i.e. a newline or a CR and selective
6926 static enum move_it_result
6927 move_it_in_display_line_to (struct it
*it
,
6928 EMACS_INT to_charpos
, int to_x
,
6929 enum move_operation_enum op
)
6931 enum move_it_result result
= MOVE_UNDEFINED
;
6932 struct glyph_row
*saved_glyph_row
;
6933 struct it wrap_it
, atpos_it
, atx_it
;
6936 /* Don't produce glyphs in produce_glyphs. */
6937 saved_glyph_row
= it
->glyph_row
;
6938 it
->glyph_row
= NULL
;
6940 /* Use wrap_it to save a copy of IT wherever a word wrap could
6941 occur. Use atpos_it to save a copy of IT at the desired buffer
6942 position, if found, so that we can scan ahead and check if the
6943 word later overshoots the window edge. Use atx_it similarly, for
6949 #define BUFFER_POS_REACHED_P() \
6950 ((op & MOVE_TO_POS) != 0 \
6951 && BUFFERP (it->object) \
6952 && IT_CHARPOS (*it) >= to_charpos \
6953 && (it->method == GET_FROM_BUFFER \
6954 || (it->method == GET_FROM_DISPLAY_VECTOR \
6955 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6957 /* If there's a line-/wrap-prefix, handle it. */
6958 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6959 && it
->current_y
< it
->last_visible_y
)
6960 handle_line_prefix (it
);
6964 int x
, i
, ascent
= 0, descent
= 0;
6966 /* Utility macro to reset an iterator with x, ascent, and descent. */
6967 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6968 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6969 (IT)->max_descent = descent)
6971 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6973 if ((op
& MOVE_TO_POS
) != 0
6974 && BUFFERP (it
->object
)
6975 && it
->method
== GET_FROM_BUFFER
6976 && IT_CHARPOS (*it
) > to_charpos
)
6978 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6980 result
= MOVE_POS_MATCH_OR_ZV
;
6983 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6984 /* If wrap_it is valid, the current position might be in a
6985 word that is wrapped. So, save the iterator in
6986 atpos_it and continue to see if wrapping happens. */
6990 /* Stop when ZV reached.
6991 We used to stop here when TO_CHARPOS reached as well, but that is
6992 too soon if this glyph does not fit on this line. So we handle it
6993 explicitly below. */
6994 if (!get_next_display_element (it
))
6996 result
= MOVE_POS_MATCH_OR_ZV
;
7000 if (it
->line_wrap
== TRUNCATE
)
7002 if (BUFFER_POS_REACHED_P ())
7004 result
= MOVE_POS_MATCH_OR_ZV
;
7010 if (it
->line_wrap
== WORD_WRAP
)
7012 if (IT_DISPLAYING_WHITESPACE (it
))
7016 /* We have reached a glyph that follows one or more
7017 whitespace characters. If the position is
7018 already found, we are done. */
7019 if (atpos_it
.sp
>= 0)
7022 result
= MOVE_POS_MATCH_OR_ZV
;
7028 result
= MOVE_X_REACHED
;
7031 /* Otherwise, we can wrap here. */
7038 /* Remember the line height for the current line, in case
7039 the next element doesn't fit on the line. */
7040 ascent
= it
->max_ascent
;
7041 descent
= it
->max_descent
;
7043 /* The call to produce_glyphs will get the metrics of the
7044 display element IT is loaded with. Record the x-position
7045 before this display element, in case it doesn't fit on the
7049 PRODUCE_GLYPHS (it
);
7051 if (it
->area
!= TEXT_AREA
)
7053 set_iterator_to_next (it
, 1);
7057 /* The number of glyphs we get back in IT->nglyphs will normally
7058 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
7059 character on a terminal frame, or (iii) a line end. For the
7060 second case, IT->nglyphs - 1 padding glyphs will be present.
7061 (On X frames, there is only one glyph produced for a
7062 composite character.)
7064 The behavior implemented below means, for continuation lines,
7065 that as many spaces of a TAB as fit on the current line are
7066 displayed there. For terminal frames, as many glyphs of a
7067 multi-glyph character are displayed in the current line, too.
7068 This is what the old redisplay code did, and we keep it that
7069 way. Under X, the whole shape of a complex character must
7070 fit on the line or it will be completely displayed in the
7073 Note that both for tabs and padding glyphs, all glyphs have
7077 /* More than one glyph or glyph doesn't fit on line. All
7078 glyphs have the same width. */
7079 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
7081 int x_before_this_char
= x
;
7082 int hpos_before_this_char
= it
->hpos
;
7084 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
7086 new_x
= x
+ single_glyph_width
;
7088 /* We want to leave anything reaching TO_X to the caller. */
7089 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
7091 if (BUFFER_POS_REACHED_P ())
7093 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7094 goto buffer_pos_reached
;
7095 if (atpos_it
.sp
< 0)
7098 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7103 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7106 result
= MOVE_X_REACHED
;
7112 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
7117 if (/* Lines are continued. */
7118 it
->line_wrap
!= TRUNCATE
7119 && (/* And glyph doesn't fit on the line. */
7120 new_x
> it
->last_visible_x
7121 /* Or it fits exactly and we're on a window
7123 || (new_x
== it
->last_visible_x
7124 && FRAME_WINDOW_P (it
->f
))))
7126 if (/* IT->hpos == 0 means the very first glyph
7127 doesn't fit on the line, e.g. a wide image. */
7129 || (new_x
== it
->last_visible_x
7130 && FRAME_WINDOW_P (it
->f
)))
7133 it
->current_x
= new_x
;
7135 /* The character's last glyph just barely fits
7137 if (i
== it
->nglyphs
- 1)
7139 /* If this is the destination position,
7140 return a position *before* it in this row,
7141 now that we know it fits in this row. */
7142 if (BUFFER_POS_REACHED_P ())
7144 if (it
->line_wrap
!= WORD_WRAP
7147 it
->hpos
= hpos_before_this_char
;
7148 it
->current_x
= x_before_this_char
;
7149 result
= MOVE_POS_MATCH_OR_ZV
;
7152 if (it
->line_wrap
== WORD_WRAP
7156 atpos_it
.current_x
= x_before_this_char
;
7157 atpos_it
.hpos
= hpos_before_this_char
;
7161 set_iterator_to_next (it
, 1);
7162 /* On graphical terminals, newlines may
7163 "overflow" into the fringe if
7164 overflow-newline-into-fringe is non-nil.
7165 On text-only terminals, newlines may
7166 overflow into the last glyph on the
7168 if (!FRAME_WINDOW_P (it
->f
)
7169 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7171 if (!get_next_display_element (it
))
7173 result
= MOVE_POS_MATCH_OR_ZV
;
7176 if (BUFFER_POS_REACHED_P ())
7178 if (ITERATOR_AT_END_OF_LINE_P (it
))
7179 result
= MOVE_POS_MATCH_OR_ZV
;
7181 result
= MOVE_LINE_CONTINUED
;
7184 if (ITERATOR_AT_END_OF_LINE_P (it
))
7186 result
= MOVE_NEWLINE_OR_CR
;
7193 IT_RESET_X_ASCENT_DESCENT (it
);
7195 if (wrap_it
.sp
>= 0)
7202 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
7204 result
= MOVE_LINE_CONTINUED
;
7208 if (BUFFER_POS_REACHED_P ())
7210 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
7211 goto buffer_pos_reached
;
7212 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
7215 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
7219 if (new_x
> it
->first_visible_x
)
7221 /* Glyph is visible. Increment number of glyphs that
7222 would be displayed. */
7227 if (result
!= MOVE_UNDEFINED
)
7230 else if (BUFFER_POS_REACHED_P ())
7233 IT_RESET_X_ASCENT_DESCENT (it
);
7234 result
= MOVE_POS_MATCH_OR_ZV
;
7237 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
7239 /* Stop when TO_X specified and reached. This check is
7240 necessary here because of lines consisting of a line end,
7241 only. The line end will not produce any glyphs and we
7242 would never get MOVE_X_REACHED. */
7243 xassert (it
->nglyphs
== 0);
7244 result
= MOVE_X_REACHED
;
7248 /* Is this a line end? If yes, we're done. */
7249 if (ITERATOR_AT_END_OF_LINE_P (it
))
7251 result
= MOVE_NEWLINE_OR_CR
;
7255 /* The current display element has been consumed. Advance
7257 set_iterator_to_next (it
, 1);
7259 /* Stop if lines are truncated and IT's current x-position is
7260 past the right edge of the window now. */
7261 if (it
->line_wrap
== TRUNCATE
7262 && it
->current_x
>= it
->last_visible_x
)
7264 if (!FRAME_WINDOW_P (it
->f
)
7265 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7267 if (!get_next_display_element (it
)
7268 || BUFFER_POS_REACHED_P ())
7270 result
= MOVE_POS_MATCH_OR_ZV
;
7273 if (ITERATOR_AT_END_OF_LINE_P (it
))
7275 result
= MOVE_NEWLINE_OR_CR
;
7279 result
= MOVE_LINE_TRUNCATED
;
7282 #undef IT_RESET_X_ASCENT_DESCENT
7285 #undef BUFFER_POS_REACHED_P
7287 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7288 restore the saved iterator. */
7289 if (atpos_it
.sp
>= 0)
7291 else if (atx_it
.sp
>= 0)
7296 /* Restore the iterator settings altered at the beginning of this
7298 it
->glyph_row
= saved_glyph_row
;
7302 /* For external use. */
7304 move_it_in_display_line (struct it
*it
,
7305 EMACS_INT to_charpos
, int to_x
,
7306 enum move_operation_enum op
)
7308 if (it
->line_wrap
== WORD_WRAP
7309 && (op
& MOVE_TO_X
))
7311 struct it save_it
= *it
;
7312 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7313 /* When word-wrap is on, TO_X may lie past the end
7314 of a wrapped line. Then it->current is the
7315 character on the next line, so backtrack to the
7316 space before the wrap point. */
7317 if (skip
== MOVE_LINE_CONTINUED
)
7319 int prev_x
= max (it
->current_x
- 1, 0);
7321 move_it_in_display_line_to
7322 (it
, -1, prev_x
, MOVE_TO_X
);
7326 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7330 /* Move IT forward until it satisfies one or more of the criteria in
7331 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7333 OP is a bit-mask that specifies where to stop, and in particular,
7334 which of those four position arguments makes a difference. See the
7335 description of enum move_operation_enum.
7337 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7338 screen line, this function will set IT to the next position >
7342 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7344 int to_charpos
, to_x
, to_y
, to_vpos
;
7347 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7348 int line_height
, line_start_x
= 0, reached
= 0;
7352 if (op
& MOVE_TO_VPOS
)
7354 /* If no TO_CHARPOS and no TO_X specified, stop at the
7355 start of the line TO_VPOS. */
7356 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7358 if (it
->vpos
== to_vpos
)
7364 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7368 /* TO_VPOS >= 0 means stop at TO_X in the line at
7369 TO_VPOS, or at TO_POS, whichever comes first. */
7370 if (it
->vpos
== to_vpos
)
7376 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7378 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7383 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7385 /* We have reached TO_X but not in the line we want. */
7386 skip
= move_it_in_display_line_to (it
, to_charpos
,
7388 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7396 else if (op
& MOVE_TO_Y
)
7398 struct it it_backup
;
7400 if (it
->line_wrap
== WORD_WRAP
)
7403 /* TO_Y specified means stop at TO_X in the line containing
7404 TO_Y---or at TO_CHARPOS if this is reached first. The
7405 problem is that we can't really tell whether the line
7406 contains TO_Y before we have completely scanned it, and
7407 this may skip past TO_X. What we do is to first scan to
7410 If TO_X is not specified, use a TO_X of zero. The reason
7411 is to make the outcome of this function more predictable.
7412 If we didn't use TO_X == 0, we would stop at the end of
7413 the line which is probably not what a caller would expect
7415 skip
= move_it_in_display_line_to
7416 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7417 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7419 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7420 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7422 else if (skip
== MOVE_X_REACHED
)
7424 /* If TO_X was reached, we want to know whether TO_Y is
7425 in the line. We know this is the case if the already
7426 scanned glyphs make the line tall enough. Otherwise,
7427 we must check by scanning the rest of the line. */
7428 line_height
= it
->max_ascent
+ it
->max_descent
;
7429 if (to_y
>= it
->current_y
7430 && to_y
< it
->current_y
+ line_height
)
7436 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7437 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7439 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7440 line_height
= it
->max_ascent
+ it
->max_descent
;
7441 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7443 if (to_y
>= it
->current_y
7444 && to_y
< it
->current_y
+ line_height
)
7446 /* If TO_Y is in this line and TO_X was reached
7447 above, we scanned too far. We have to restore
7448 IT's settings to the ones before skipping. */
7455 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7461 /* Check whether TO_Y is in this line. */
7462 line_height
= it
->max_ascent
+ it
->max_descent
;
7463 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7465 if (to_y
>= it
->current_y
7466 && to_y
< it
->current_y
+ line_height
)
7468 /* When word-wrap is on, TO_X may lie past the end
7469 of a wrapped line. Then it->current is the
7470 character on the next line, so backtrack to the
7471 space before the wrap point. */
7472 if (skip
== MOVE_LINE_CONTINUED
7473 && it
->line_wrap
== WORD_WRAP
)
7475 int prev_x
= max (it
->current_x
- 1, 0);
7477 skip
= move_it_in_display_line_to
7478 (it
, -1, prev_x
, MOVE_TO_X
);
7487 else if (BUFFERP (it
->object
)
7488 && (it
->method
== GET_FROM_BUFFER
7489 || it
->method
== GET_FROM_STRETCH
)
7490 && IT_CHARPOS (*it
) >= to_charpos
)
7491 skip
= MOVE_POS_MATCH_OR_ZV
;
7493 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7497 case MOVE_POS_MATCH_OR_ZV
:
7501 case MOVE_NEWLINE_OR_CR
:
7502 set_iterator_to_next (it
, 1);
7503 it
->continuation_lines_width
= 0;
7506 case MOVE_LINE_TRUNCATED
:
7507 it
->continuation_lines_width
= 0;
7508 reseat_at_next_visible_line_start (it
, 0);
7509 if ((op
& MOVE_TO_POS
) != 0
7510 && IT_CHARPOS (*it
) > to_charpos
)
7517 case MOVE_LINE_CONTINUED
:
7518 /* For continued lines ending in a tab, some of the glyphs
7519 associated with the tab are displayed on the current
7520 line. Since it->current_x does not include these glyphs,
7521 we use it->last_visible_x instead. */
7524 it
->continuation_lines_width
+= it
->last_visible_x
;
7525 /* When moving by vpos, ensure that the iterator really
7526 advances to the next line (bug#847, bug#969). Fixme:
7527 do we need to do this in other circumstances? */
7528 if (it
->current_x
!= it
->last_visible_x
7529 && (op
& MOVE_TO_VPOS
)
7530 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
7532 line_start_x
= it
->current_x
+ it
->pixel_width
7533 - it
->last_visible_x
;
7534 set_iterator_to_next (it
, 0);
7538 it
->continuation_lines_width
+= it
->current_x
;
7545 /* Reset/increment for the next run. */
7546 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7547 it
->current_x
= line_start_x
;
7550 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7552 last_height
= it
->max_ascent
+ it
->max_descent
;
7553 last_max_ascent
= it
->max_ascent
;
7554 it
->max_ascent
= it
->max_descent
= 0;
7559 /* On text terminals, we may stop at the end of a line in the middle
7560 of a multi-character glyph. If the glyph itself is continued,
7561 i.e. it is actually displayed on the next line, don't treat this
7562 stopping point as valid; move to the next line instead (unless
7563 that brings us offscreen). */
7564 if (!FRAME_WINDOW_P (it
->f
)
7566 && IT_CHARPOS (*it
) == to_charpos
7567 && it
->what
== IT_CHARACTER
7569 && it
->line_wrap
== WINDOW_WRAP
7570 && it
->current_x
== it
->last_visible_x
- 1
7573 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
7575 it
->continuation_lines_width
+= it
->current_x
;
7576 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
7577 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7579 last_height
= it
->max_ascent
+ it
->max_descent
;
7580 last_max_ascent
= it
->max_ascent
;
7583 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7587 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7589 If DY > 0, move IT backward at least that many pixels. DY = 0
7590 means move IT backward to the preceding line start or BEGV. This
7591 function may move over more than DY pixels if IT->current_y - DY
7592 ends up in the middle of a line; in this case IT->current_y will be
7593 set to the top of the line moved to. */
7596 move_it_vertically_backward (it
, dy
)
7607 start_pos
= IT_CHARPOS (*it
);
7609 /* Estimate how many newlines we must move back. */
7610 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7612 /* Set the iterator's position that many lines back. */
7613 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7614 back_to_previous_visible_line_start (it
);
7616 /* Reseat the iterator here. When moving backward, we don't want
7617 reseat to skip forward over invisible text, set up the iterator
7618 to deliver from overlay strings at the new position etc. So,
7619 use reseat_1 here. */
7620 reseat_1 (it
, it
->current
.pos
, 1);
7622 /* We are now surely at a line start. */
7623 it
->current_x
= it
->hpos
= 0;
7624 it
->continuation_lines_width
= 0;
7626 /* Move forward and see what y-distance we moved. First move to the
7627 start of the next line so that we get its height. We need this
7628 height to be able to tell whether we reached the specified
7631 it2
.max_ascent
= it2
.max_descent
= 0;
7634 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7635 MOVE_TO_POS
| MOVE_TO_VPOS
);
7637 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7638 xassert (IT_CHARPOS (*it
) >= BEGV
);
7641 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7642 xassert (IT_CHARPOS (*it
) >= BEGV
);
7643 /* H is the actual vertical distance from the position in *IT
7644 and the starting position. */
7645 h
= it2
.current_y
- it
->current_y
;
7646 /* NLINES is the distance in number of lines. */
7647 nlines
= it2
.vpos
- it
->vpos
;
7649 /* Correct IT's y and vpos position
7650 so that they are relative to the starting point. */
7656 /* DY == 0 means move to the start of the screen line. The
7657 value of nlines is > 0 if continuation lines were involved. */
7659 move_it_by_lines (it
, nlines
, 1);
7663 /* The y-position we try to reach, relative to *IT.
7664 Note that H has been subtracted in front of the if-statement. */
7665 int target_y
= it
->current_y
+ h
- dy
;
7666 int y0
= it3
.current_y
;
7667 int y1
= line_bottom_y (&it3
);
7668 int line_height
= y1
- y0
;
7670 /* If we did not reach target_y, try to move further backward if
7671 we can. If we moved too far backward, try to move forward. */
7672 if (target_y
< it
->current_y
7673 /* This is heuristic. In a window that's 3 lines high, with
7674 a line height of 13 pixels each, recentering with point
7675 on the bottom line will try to move -39/2 = 19 pixels
7676 backward. Try to avoid moving into the first line. */
7677 && (it
->current_y
- target_y
7678 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7679 && IT_CHARPOS (*it
) > BEGV
)
7681 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7682 target_y
- it
->current_y
));
7683 dy
= it
->current_y
- target_y
;
7684 goto move_further_back
;
7686 else if (target_y
>= it
->current_y
+ line_height
7687 && IT_CHARPOS (*it
) < ZV
)
7689 /* Should move forward by at least one line, maybe more.
7691 Note: Calling move_it_by_lines can be expensive on
7692 terminal frames, where compute_motion is used (via
7693 vmotion) to do the job, when there are very long lines
7694 and truncate-lines is nil. That's the reason for
7695 treating terminal frames specially here. */
7697 if (!FRAME_WINDOW_P (it
->f
))
7698 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7703 move_it_by_lines (it
, 1, 1);
7705 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7712 /* Move IT by a specified amount of pixel lines DY. DY negative means
7713 move backwards. DY = 0 means move to start of screen line. At the
7714 end, IT will be on the start of a screen line. */
7717 move_it_vertically (it
, dy
)
7722 move_it_vertically_backward (it
, -dy
);
7725 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7726 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7727 MOVE_TO_POS
| MOVE_TO_Y
);
7728 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7730 /* If buffer ends in ZV without a newline, move to the start of
7731 the line to satisfy the post-condition. */
7732 if (IT_CHARPOS (*it
) == ZV
7734 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7735 move_it_by_lines (it
, 0, 0);
7740 /* Move iterator IT past the end of the text line it is in. */
7743 move_it_past_eol (it
)
7746 enum move_it_result rc
;
7748 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7749 if (rc
== MOVE_NEWLINE_OR_CR
)
7750 set_iterator_to_next (it
, 0);
7754 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7755 negative means move up. DVPOS == 0 means move to the start of the
7756 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7757 NEED_Y_P is zero, IT->current_y will be left unchanged.
7759 Further optimization ideas: If we would know that IT->f doesn't use
7760 a face with proportional font, we could be faster for
7761 truncate-lines nil. */
7764 move_it_by_lines (it
, dvpos
, need_y_p
)
7766 int dvpos
, need_y_p
;
7768 struct position pos
;
7770 /* The commented-out optimization uses vmotion on terminals. This
7771 gives bad results, because elements like it->what, on which
7772 callers such as pos_visible_p rely, aren't updated. */
7773 /* if (!FRAME_WINDOW_P (it->f))
7775 struct text_pos textpos;
7777 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7778 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7779 reseat (it, textpos, 1);
7780 it->vpos += pos.vpos;
7781 it->current_y += pos.vpos;
7787 /* DVPOS == 0 means move to the start of the screen line. */
7788 move_it_vertically_backward (it
, 0);
7789 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7790 /* Let next call to line_bottom_y calculate real line height */
7795 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7796 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7797 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7802 int start_charpos
, i
;
7804 /* Start at the beginning of the screen line containing IT's
7805 position. This may actually move vertically backwards,
7806 in case of overlays, so adjust dvpos accordingly. */
7808 move_it_vertically_backward (it
, 0);
7811 /* Go back -DVPOS visible lines and reseat the iterator there. */
7812 start_charpos
= IT_CHARPOS (*it
);
7813 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7814 back_to_previous_visible_line_start (it
);
7815 reseat (it
, it
->current
.pos
, 1);
7817 /* Move further back if we end up in a string or an image. */
7818 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7820 /* First try to move to start of display line. */
7822 move_it_vertically_backward (it
, 0);
7824 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7826 /* If start of line is still in string or image,
7827 move further back. */
7828 back_to_previous_visible_line_start (it
);
7829 reseat (it
, it
->current
.pos
, 1);
7833 it
->current_x
= it
->hpos
= 0;
7835 /* Above call may have moved too far if continuation lines
7836 are involved. Scan forward and see if it did. */
7838 it2
.vpos
= it2
.current_y
= 0;
7839 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7840 it
->vpos
-= it2
.vpos
;
7841 it
->current_y
-= it2
.current_y
;
7842 it
->current_x
= it
->hpos
= 0;
7844 /* If we moved too far back, move IT some lines forward. */
7845 if (it2
.vpos
> -dvpos
)
7847 int delta
= it2
.vpos
+ dvpos
;
7849 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7850 /* Move back again if we got too far ahead. */
7851 if (IT_CHARPOS (*it
) >= start_charpos
)
7857 /* Return 1 if IT points into the middle of a display vector. */
7860 in_display_vector_p (it
)
7863 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7864 && it
->current
.dpvec_index
> 0
7865 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7869 /***********************************************************************
7871 ***********************************************************************/
7874 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7878 add_to_log (format
, arg1
, arg2
)
7880 Lisp_Object arg1
, arg2
;
7882 Lisp_Object args
[3];
7883 Lisp_Object msg
, fmt
;
7886 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7889 /* Do nothing if called asynchronously. Inserting text into
7890 a buffer may call after-change-functions and alike and
7891 that would means running Lisp asynchronously. */
7892 if (handling_signal
)
7896 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7898 args
[0] = fmt
= build_string (format
);
7901 msg
= Fformat (3, args
);
7903 len
= SBYTES (msg
) + 1;
7904 SAFE_ALLOCA (buffer
, char *, len
);
7905 bcopy (SDATA (msg
), buffer
, len
);
7907 message_dolog (buffer
, len
- 1, 1, 0);
7914 /* Output a newline in the *Messages* buffer if "needs" one. */
7917 message_log_maybe_newline ()
7919 if (message_log_need_newline
)
7920 message_dolog ("", 0, 1, 0);
7924 /* Add a string M of length NBYTES to the message log, optionally
7925 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7926 nonzero, means interpret the contents of M as multibyte. This
7927 function calls low-level routines in order to bypass text property
7928 hooks, etc. which might not be safe to run.
7930 This may GC (insert may run before/after change hooks),
7931 so the buffer M must NOT point to a Lisp string. */
7934 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7936 int nbytes
, nlflag
, multibyte
;
7938 if (!NILP (Vmemory_full
))
7941 if (!NILP (Vmessage_log_max
))
7943 struct buffer
*oldbuf
;
7944 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7945 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7946 int point_at_end
= 0;
7948 Lisp_Object old_deactivate_mark
, tem
;
7949 struct gcpro gcpro1
;
7951 old_deactivate_mark
= Vdeactivate_mark
;
7952 oldbuf
= current_buffer
;
7953 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7954 current_buffer
->undo_list
= Qt
;
7956 oldpoint
= message_dolog_marker1
;
7957 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7958 oldbegv
= message_dolog_marker2
;
7959 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7960 oldzv
= message_dolog_marker3
;
7961 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7962 GCPRO1 (old_deactivate_mark
);
7970 BEGV_BYTE
= BEG_BYTE
;
7973 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7975 /* Insert the string--maybe converting multibyte to single byte
7976 or vice versa, so that all the text fits the buffer. */
7978 && NILP (current_buffer
->enable_multibyte_characters
))
7980 int i
, c
, char_bytes
;
7981 unsigned char work
[1];
7983 /* Convert a multibyte string to single-byte
7984 for the *Message* buffer. */
7985 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7987 c
= string_char_and_length (m
+ i
, &char_bytes
);
7988 work
[0] = (ASCII_CHAR_P (c
)
7990 : multibyte_char_to_unibyte (c
, Qnil
));
7991 insert_1_both (work
, 1, 1, 1, 0, 0);
7994 else if (! multibyte
7995 && ! NILP (current_buffer
->enable_multibyte_characters
))
7997 int i
, c
, char_bytes
;
7998 unsigned char *msg
= (unsigned char *) m
;
7999 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
8000 /* Convert a single-byte string to multibyte
8001 for the *Message* buffer. */
8002 for (i
= 0; i
< nbytes
; i
++)
8005 MAKE_CHAR_MULTIBYTE (c
);
8006 char_bytes
= CHAR_STRING (c
, str
);
8007 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
8011 insert_1 (m
, nbytes
, 1, 0, 0);
8015 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
8016 insert_1 ("\n", 1, 1, 0, 0);
8018 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8020 this_bol_byte
= PT_BYTE
;
8022 /* See if this line duplicates the previous one.
8023 If so, combine duplicates. */
8026 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
8028 prev_bol_byte
= PT_BYTE
;
8030 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
8031 this_bol
, this_bol_byte
);
8034 del_range_both (prev_bol
, prev_bol_byte
,
8035 this_bol
, this_bol_byte
, 0);
8041 /* If you change this format, don't forget to also
8042 change message_log_check_duplicate. */
8043 sprintf (dupstr
, " [%d times]", dup
);
8044 duplen
= strlen (dupstr
);
8045 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
8046 insert_1 (dupstr
, duplen
, 1, 0, 1);
8051 /* If we have more than the desired maximum number of lines
8052 in the *Messages* buffer now, delete the oldest ones.
8053 This is safe because we don't have undo in this buffer. */
8055 if (NATNUMP (Vmessage_log_max
))
8057 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
8058 -XFASTINT (Vmessage_log_max
) - 1, 0);
8059 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
8062 BEGV
= XMARKER (oldbegv
)->charpos
;
8063 BEGV_BYTE
= marker_byte_position (oldbegv
);
8072 ZV
= XMARKER (oldzv
)->charpos
;
8073 ZV_BYTE
= marker_byte_position (oldzv
);
8077 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
8079 /* We can't do Fgoto_char (oldpoint) because it will run some
8081 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
8082 XMARKER (oldpoint
)->bytepos
);
8085 unchain_marker (XMARKER (oldpoint
));
8086 unchain_marker (XMARKER (oldbegv
));
8087 unchain_marker (XMARKER (oldzv
));
8089 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
8090 set_buffer_internal (oldbuf
);
8092 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
8093 message_log_need_newline
= !nlflag
;
8094 Vdeactivate_mark
= old_deactivate_mark
;
8099 /* We are at the end of the buffer after just having inserted a newline.
8100 (Note: We depend on the fact we won't be crossing the gap.)
8101 Check to see if the most recent message looks a lot like the previous one.
8102 Return 0 if different, 1 if the new one should just replace it, or a
8103 value N > 1 if we should also append " [N times]". */
8106 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
8107 int prev_bol
, this_bol
;
8108 int prev_bol_byte
, this_bol_byte
;
8111 int len
= Z_BYTE
- 1 - this_bol_byte
;
8113 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
8114 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
8116 for (i
= 0; i
< len
; i
++)
8118 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
8126 if (*p1
++ == ' ' && *p1
++ == '[')
8129 while (*p1
>= '0' && *p1
<= '9')
8130 n
= n
* 10 + *p1
++ - '0';
8131 if (strncmp (p1
, " times]\n", 8) == 0)
8138 /* Display an echo area message M with a specified length of NBYTES
8139 bytes. The string may include null characters. If M is 0, clear
8140 out any existing message, and let the mini-buffer text show
8143 This may GC, so the buffer M must NOT point to a Lisp string. */
8146 message2 (m
, nbytes
, multibyte
)
8151 /* First flush out any partial line written with print. */
8152 message_log_maybe_newline ();
8154 message_dolog (m
, nbytes
, 1, multibyte
);
8155 message2_nolog (m
, nbytes
, multibyte
);
8159 /* The non-logging counterpart of message2. */
8162 message2_nolog (m
, nbytes
, multibyte
)
8164 int nbytes
, multibyte
;
8166 struct frame
*sf
= SELECTED_FRAME ();
8167 message_enable_multibyte
= multibyte
;
8169 if (FRAME_INITIAL_P (sf
))
8171 if (noninteractive_need_newline
)
8172 putc ('\n', stderr
);
8173 noninteractive_need_newline
= 0;
8175 fwrite (m
, nbytes
, 1, stderr
);
8176 if (cursor_in_echo_area
== 0)
8177 fprintf (stderr
, "\n");
8180 /* A null message buffer means that the frame hasn't really been
8181 initialized yet. Error messages get reported properly by
8182 cmd_error, so this must be just an informative message; toss it. */
8183 else if (INTERACTIVE
8184 && sf
->glyphs_initialized_p
8185 && FRAME_MESSAGE_BUF (sf
))
8187 Lisp_Object mini_window
;
8190 /* Get the frame containing the mini-buffer
8191 that the selected frame is using. */
8192 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8193 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8195 FRAME_SAMPLE_VISIBILITY (f
);
8196 if (FRAME_VISIBLE_P (sf
)
8197 && ! FRAME_VISIBLE_P (f
))
8198 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
8202 set_message (m
, Qnil
, nbytes
, multibyte
);
8203 if (minibuffer_auto_raise
)
8204 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8207 clear_message (1, 1);
8209 do_pending_window_change (0);
8210 echo_area_display (1);
8211 do_pending_window_change (0);
8212 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8213 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8218 /* Display an echo area message M with a specified length of NBYTES
8219 bytes. The string may include null characters. If M is not a
8220 string, clear out any existing message, and let the mini-buffer
8223 This function cancels echoing. */
8226 message3 (m
, nbytes
, multibyte
)
8231 struct gcpro gcpro1
;
8234 clear_message (1,1);
8237 /* First flush out any partial line written with print. */
8238 message_log_maybe_newline ();
8244 SAFE_ALLOCA (buffer
, char *, nbytes
);
8245 bcopy (SDATA (m
), buffer
, nbytes
);
8246 message_dolog (buffer
, nbytes
, 1, multibyte
);
8249 message3_nolog (m
, nbytes
, multibyte
);
8255 /* The non-logging version of message3.
8256 This does not cancel echoing, because it is used for echoing.
8257 Perhaps we need to make a separate function for echoing
8258 and make this cancel echoing. */
8261 message3_nolog (m
, nbytes
, multibyte
)
8263 int nbytes
, multibyte
;
8265 struct frame
*sf
= SELECTED_FRAME ();
8266 message_enable_multibyte
= multibyte
;
8268 if (FRAME_INITIAL_P (sf
))
8270 if (noninteractive_need_newline
)
8271 putc ('\n', stderr
);
8272 noninteractive_need_newline
= 0;
8274 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8275 if (cursor_in_echo_area
== 0)
8276 fprintf (stderr
, "\n");
8279 /* A null message buffer means that the frame hasn't really been
8280 initialized yet. Error messages get reported properly by
8281 cmd_error, so this must be just an informative message; toss it. */
8282 else if (INTERACTIVE
8283 && sf
->glyphs_initialized_p
8284 && FRAME_MESSAGE_BUF (sf
))
8286 Lisp_Object mini_window
;
8290 /* Get the frame containing the mini-buffer
8291 that the selected frame is using. */
8292 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8293 frame
= XWINDOW (mini_window
)->frame
;
8296 FRAME_SAMPLE_VISIBILITY (f
);
8297 if (FRAME_VISIBLE_P (sf
)
8298 && !FRAME_VISIBLE_P (f
))
8299 Fmake_frame_visible (frame
);
8301 if (STRINGP (m
) && SCHARS (m
) > 0)
8303 set_message (NULL
, m
, nbytes
, multibyte
);
8304 if (minibuffer_auto_raise
)
8305 Fraise_frame (frame
);
8306 /* Assume we are not echoing.
8307 (If we are, echo_now will override this.) */
8308 echo_message_buffer
= Qnil
;
8311 clear_message (1, 1);
8313 do_pending_window_change (0);
8314 echo_area_display (1);
8315 do_pending_window_change (0);
8316 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8317 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8322 /* Display a null-terminated echo area message M. If M is 0, clear
8323 out any existing message, and let the mini-buffer text show through.
8325 The buffer M must continue to exist until after the echo area gets
8326 cleared or some other message gets displayed there. Do not pass
8327 text that is stored in a Lisp string. Do not pass text in a buffer
8328 that was alloca'd. */
8334 message2 (m
, (m
? strlen (m
) : 0), 0);
8338 /* The non-logging counterpart of message1. */
8344 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8347 /* Display a message M which contains a single %s
8348 which gets replaced with STRING. */
8351 message_with_string (m
, string
, log
)
8356 CHECK_STRING (string
);
8362 if (noninteractive_need_newline
)
8363 putc ('\n', stderr
);
8364 noninteractive_need_newline
= 0;
8365 fprintf (stderr
, m
, SDATA (string
));
8366 if (!cursor_in_echo_area
)
8367 fprintf (stderr
, "\n");
8371 else if (INTERACTIVE
)
8373 /* The frame whose minibuffer we're going to display the message on.
8374 It may be larger than the selected frame, so we need
8375 to use its buffer, not the selected frame's buffer. */
8376 Lisp_Object mini_window
;
8377 struct frame
*f
, *sf
= SELECTED_FRAME ();
8379 /* Get the frame containing the minibuffer
8380 that the selected frame is using. */
8381 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8382 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8384 /* A null message buffer means that the frame hasn't really been
8385 initialized yet. Error messages get reported properly by
8386 cmd_error, so this must be just an informative message; toss it. */
8387 if (FRAME_MESSAGE_BUF (f
))
8389 Lisp_Object args
[2], message
;
8390 struct gcpro gcpro1
, gcpro2
;
8392 args
[0] = build_string (m
);
8393 args
[1] = message
= string
;
8394 GCPRO2 (args
[0], message
);
8397 message
= Fformat (2, args
);
8400 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8402 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8406 /* Print should start at the beginning of the message
8407 buffer next time. */
8408 message_buf_print
= 0;
8414 /* Dump an informative message to the minibuf. If M is 0, clear out
8415 any existing message, and let the mini-buffer text show through. */
8419 message (m
, a1
, a2
, a3
)
8421 EMACS_INT a1
, a2
, a3
;
8427 if (noninteractive_need_newline
)
8428 putc ('\n', stderr
);
8429 noninteractive_need_newline
= 0;
8430 fprintf (stderr
, m
, a1
, a2
, a3
);
8431 if (cursor_in_echo_area
== 0)
8432 fprintf (stderr
, "\n");
8436 else if (INTERACTIVE
)
8438 /* The frame whose mini-buffer we're going to display the message
8439 on. It may be larger than the selected frame, so we need to
8440 use its buffer, not the selected frame's buffer. */
8441 Lisp_Object mini_window
;
8442 struct frame
*f
, *sf
= SELECTED_FRAME ();
8444 /* Get the frame containing the mini-buffer
8445 that the selected frame is using. */
8446 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8447 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8449 /* A null message buffer means that the frame hasn't really been
8450 initialized yet. Error messages get reported properly by
8451 cmd_error, so this must be just an informative message; toss
8453 if (FRAME_MESSAGE_BUF (f
))
8464 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8465 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8467 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8468 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8470 #endif /* NO_ARG_ARRAY */
8472 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8477 /* Print should start at the beginning of the message
8478 buffer next time. */
8479 message_buf_print
= 0;
8485 /* The non-logging version of message. */
8488 message_nolog (m
, a1
, a2
, a3
)
8490 EMACS_INT a1
, a2
, a3
;
8492 Lisp_Object old_log_max
;
8493 old_log_max
= Vmessage_log_max
;
8494 Vmessage_log_max
= Qnil
;
8495 message (m
, a1
, a2
, a3
);
8496 Vmessage_log_max
= old_log_max
;
8500 /* Display the current message in the current mini-buffer. This is
8501 only called from error handlers in process.c, and is not time
8507 if (!NILP (echo_area_buffer
[0]))
8510 string
= Fcurrent_message ();
8511 message3 (string
, SBYTES (string
),
8512 !NILP (current_buffer
->enable_multibyte_characters
));
8517 /* Make sure echo area buffers in `echo_buffers' are live.
8518 If they aren't, make new ones. */
8521 ensure_echo_area_buffers ()
8525 for (i
= 0; i
< 2; ++i
)
8526 if (!BUFFERP (echo_buffer
[i
])
8527 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8530 Lisp_Object old_buffer
;
8533 old_buffer
= echo_buffer
[i
];
8534 sprintf (name
, " *Echo Area %d*", i
);
8535 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8536 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8537 /* to force word wrap in echo area -
8538 it was decided to postpone this*/
8539 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
8541 for (j
= 0; j
< 2; ++j
)
8542 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8543 echo_area_buffer
[j
] = echo_buffer
[i
];
8548 /* Call FN with args A1..A4 with either the current or last displayed
8549 echo_area_buffer as current buffer.
8551 WHICH zero means use the current message buffer
8552 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8553 from echo_buffer[] and clear it.
8555 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8556 suitable buffer from echo_buffer[] and clear it.
8558 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8559 that the current message becomes the last displayed one, make
8560 choose a suitable buffer for echo_area_buffer[0], and clear it.
8562 Value is what FN returns. */
8565 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8568 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8574 int this_one
, the_other
, clear_buffer_p
, rc
;
8575 int count
= SPECPDL_INDEX ();
8577 /* If buffers aren't live, make new ones. */
8578 ensure_echo_area_buffers ();
8583 this_one
= 0, the_other
= 1;
8585 this_one
= 1, the_other
= 0;
8588 this_one
= 0, the_other
= 1;
8591 /* We need a fresh one in case the current echo buffer equals
8592 the one containing the last displayed echo area message. */
8593 if (!NILP (echo_area_buffer
[this_one
])
8594 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8595 echo_area_buffer
[this_one
] = Qnil
;
8598 /* Choose a suitable buffer from echo_buffer[] is we don't
8600 if (NILP (echo_area_buffer
[this_one
]))
8602 echo_area_buffer
[this_one
]
8603 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8604 ? echo_buffer
[the_other
]
8605 : echo_buffer
[this_one
]);
8609 buffer
= echo_area_buffer
[this_one
];
8611 /* Don't get confused by reusing the buffer used for echoing
8612 for a different purpose. */
8613 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8616 record_unwind_protect (unwind_with_echo_area_buffer
,
8617 with_echo_area_buffer_unwind_data (w
));
8619 /* Make the echo area buffer current. Note that for display
8620 purposes, it is not necessary that the displayed window's buffer
8621 == current_buffer, except for text property lookup. So, let's
8622 only set that buffer temporarily here without doing a full
8623 Fset_window_buffer. We must also change w->pointm, though,
8624 because otherwise an assertions in unshow_buffer fails, and Emacs
8626 set_buffer_internal_1 (XBUFFER (buffer
));
8630 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8633 current_buffer
->undo_list
= Qt
;
8634 current_buffer
->read_only
= Qnil
;
8635 specbind (Qinhibit_read_only
, Qt
);
8636 specbind (Qinhibit_modification_hooks
, Qt
);
8638 if (clear_buffer_p
&& Z
> BEG
)
8641 xassert (BEGV
>= BEG
);
8642 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8644 rc
= fn (a1
, a2
, a3
, a4
);
8646 xassert (BEGV
>= BEG
);
8647 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8649 unbind_to (count
, Qnil
);
8654 /* Save state that should be preserved around the call to the function
8655 FN called in with_echo_area_buffer. */
8658 with_echo_area_buffer_unwind_data (w
)
8662 Lisp_Object vector
, tmp
;
8664 /* Reduce consing by keeping one vector in
8665 Vwith_echo_area_save_vector. */
8666 vector
= Vwith_echo_area_save_vector
;
8667 Vwith_echo_area_save_vector
= Qnil
;
8670 vector
= Fmake_vector (make_number (7), Qnil
);
8672 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8673 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8674 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8678 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8679 ASET (vector
, i
, w
->buffer
); ++i
;
8680 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8681 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8686 for (; i
< end
; ++i
)
8687 ASET (vector
, i
, Qnil
);
8690 xassert (i
== ASIZE (vector
));
8695 /* Restore global state from VECTOR which was created by
8696 with_echo_area_buffer_unwind_data. */
8699 unwind_with_echo_area_buffer (vector
)
8702 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8703 Vdeactivate_mark
= AREF (vector
, 1);
8704 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8706 if (WINDOWP (AREF (vector
, 3)))
8709 Lisp_Object buffer
, charpos
, bytepos
;
8711 w
= XWINDOW (AREF (vector
, 3));
8712 buffer
= AREF (vector
, 4);
8713 charpos
= AREF (vector
, 5);
8714 bytepos
= AREF (vector
, 6);
8717 set_marker_both (w
->pointm
, buffer
,
8718 XFASTINT (charpos
), XFASTINT (bytepos
));
8721 Vwith_echo_area_save_vector
= vector
;
8726 /* Set up the echo area for use by print functions. MULTIBYTE_P
8727 non-zero means we will print multibyte. */
8730 setup_echo_area_for_printing (multibyte_p
)
8733 /* If we can't find an echo area any more, exit. */
8734 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8737 ensure_echo_area_buffers ();
8739 if (!message_buf_print
)
8741 /* A message has been output since the last time we printed.
8742 Choose a fresh echo area buffer. */
8743 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8744 echo_area_buffer
[0] = echo_buffer
[1];
8746 echo_area_buffer
[0] = echo_buffer
[0];
8748 /* Switch to that buffer and clear it. */
8749 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8750 current_buffer
->truncate_lines
= Qnil
;
8754 int count
= SPECPDL_INDEX ();
8755 specbind (Qinhibit_read_only
, Qt
);
8756 /* Note that undo recording is always disabled. */
8758 unbind_to (count
, Qnil
);
8760 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8762 /* Set up the buffer for the multibyteness we need. */
8764 != !NILP (current_buffer
->enable_multibyte_characters
))
8765 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8767 /* Raise the frame containing the echo area. */
8768 if (minibuffer_auto_raise
)
8770 struct frame
*sf
= SELECTED_FRAME ();
8771 Lisp_Object mini_window
;
8772 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8773 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8776 message_log_maybe_newline ();
8777 message_buf_print
= 1;
8781 if (NILP (echo_area_buffer
[0]))
8783 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8784 echo_area_buffer
[0] = echo_buffer
[1];
8786 echo_area_buffer
[0] = echo_buffer
[0];
8789 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8791 /* Someone switched buffers between print requests. */
8792 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8793 current_buffer
->truncate_lines
= Qnil
;
8799 /* Display an echo area message in window W. Value is non-zero if W's
8800 height is changed. If display_last_displayed_message_p is
8801 non-zero, display the message that was last displayed, otherwise
8802 display the current message. */
8805 display_echo_area (w
)
8808 int i
, no_message_p
, window_height_changed_p
, count
;
8810 /* Temporarily disable garbage collections while displaying the echo
8811 area. This is done because a GC can print a message itself.
8812 That message would modify the echo area buffer's contents while a
8813 redisplay of the buffer is going on, and seriously confuse
8815 count
= inhibit_garbage_collection ();
8817 /* If there is no message, we must call display_echo_area_1
8818 nevertheless because it resizes the window. But we will have to
8819 reset the echo_area_buffer in question to nil at the end because
8820 with_echo_area_buffer will sets it to an empty buffer. */
8821 i
= display_last_displayed_message_p
? 1 : 0;
8822 no_message_p
= NILP (echo_area_buffer
[i
]);
8824 window_height_changed_p
8825 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8826 display_echo_area_1
,
8827 (EMACS_INT
) w
, Qnil
, 0, 0);
8830 echo_area_buffer
[i
] = Qnil
;
8832 unbind_to (count
, Qnil
);
8833 return window_height_changed_p
;
8837 /* Helper for display_echo_area. Display the current buffer which
8838 contains the current echo area message in window W, a mini-window,
8839 a pointer to which is passed in A1. A2..A4 are currently not used.
8840 Change the height of W so that all of the message is displayed.
8841 Value is non-zero if height of W was changed. */
8844 display_echo_area_1 (a1
, a2
, a3
, a4
)
8849 struct window
*w
= (struct window
*) a1
;
8851 struct text_pos start
;
8852 int window_height_changed_p
= 0;
8854 /* Do this before displaying, so that we have a large enough glyph
8855 matrix for the display. If we can't get enough space for the
8856 whole text, display the last N lines. That works by setting w->start. */
8857 window_height_changed_p
= resize_mini_window (w
, 0);
8859 /* Use the starting position chosen by resize_mini_window. */
8860 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8863 clear_glyph_matrix (w
->desired_matrix
);
8864 XSETWINDOW (window
, w
);
8865 try_window (window
, start
, 0);
8867 return window_height_changed_p
;
8871 /* Resize the echo area window to exactly the size needed for the
8872 currently displayed message, if there is one. If a mini-buffer
8873 is active, don't shrink it. */
8876 resize_echo_area_exactly ()
8878 if (BUFFERP (echo_area_buffer
[0])
8879 && WINDOWP (echo_area_window
))
8881 struct window
*w
= XWINDOW (echo_area_window
);
8883 Lisp_Object resize_exactly
;
8885 if (minibuf_level
== 0)
8886 resize_exactly
= Qt
;
8888 resize_exactly
= Qnil
;
8890 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8891 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8894 ++windows_or_buffers_changed
;
8895 ++update_mode_lines
;
8896 redisplay_internal (0);
8902 /* Callback function for with_echo_area_buffer, when used from
8903 resize_echo_area_exactly. A1 contains a pointer to the window to
8904 resize, EXACTLY non-nil means resize the mini-window exactly to the
8905 size of the text displayed. A3 and A4 are not used. Value is what
8906 resize_mini_window returns. */
8909 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8911 Lisp_Object exactly
;
8914 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8918 /* Resize mini-window W to fit the size of its contents. EXACT_P
8919 means size the window exactly to the size needed. Otherwise, it's
8920 only enlarged until W's buffer is empty.
8922 Set W->start to the right place to begin display. If the whole
8923 contents fit, start at the beginning. Otherwise, start so as
8924 to make the end of the contents appear. This is particularly
8925 important for y-or-n-p, but seems desirable generally.
8927 Value is non-zero if the window height has been changed. */
8930 resize_mini_window (w
, exact_p
)
8934 struct frame
*f
= XFRAME (w
->frame
);
8935 int window_height_changed_p
= 0;
8937 xassert (MINI_WINDOW_P (w
));
8939 /* By default, start display at the beginning. */
8940 set_marker_both (w
->start
, w
->buffer
,
8941 BUF_BEGV (XBUFFER (w
->buffer
)),
8942 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8944 /* Don't resize windows while redisplaying a window; it would
8945 confuse redisplay functions when the size of the window they are
8946 displaying changes from under them. Such a resizing can happen,
8947 for instance, when which-func prints a long message while
8948 we are running fontification-functions. We're running these
8949 functions with safe_call which binds inhibit-redisplay to t. */
8950 if (!NILP (Vinhibit_redisplay
))
8953 /* Nil means don't try to resize. */
8954 if (NILP (Vresize_mini_windows
)
8955 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8958 if (!FRAME_MINIBUF_ONLY_P (f
))
8961 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8962 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8963 int height
, max_height
;
8964 int unit
= FRAME_LINE_HEIGHT (f
);
8965 struct text_pos start
;
8966 struct buffer
*old_current_buffer
= NULL
;
8968 if (current_buffer
!= XBUFFER (w
->buffer
))
8970 old_current_buffer
= current_buffer
;
8971 set_buffer_internal (XBUFFER (w
->buffer
));
8974 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8976 /* Compute the max. number of lines specified by the user. */
8977 if (FLOATP (Vmax_mini_window_height
))
8978 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8979 else if (INTEGERP (Vmax_mini_window_height
))
8980 max_height
= XINT (Vmax_mini_window_height
);
8982 max_height
= total_height
/ 4;
8984 /* Correct that max. height if it's bogus. */
8985 max_height
= max (1, max_height
);
8986 max_height
= min (total_height
, max_height
);
8988 /* Find out the height of the text in the window. */
8989 if (it
.line_wrap
== TRUNCATE
)
8994 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8995 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8996 height
= it
.current_y
+ last_height
;
8998 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8999 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
9000 height
= (height
+ unit
- 1) / unit
;
9003 /* Compute a suitable window start. */
9004 if (height
> max_height
)
9006 height
= max_height
;
9007 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
9008 move_it_vertically_backward (&it
, (height
- 1) * unit
);
9009 start
= it
.current
.pos
;
9012 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
9013 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
9015 if (EQ (Vresize_mini_windows
, Qgrow_only
))
9017 /* Let it grow only, until we display an empty message, in which
9018 case the window shrinks again. */
9019 if (height
> WINDOW_TOTAL_LINES (w
))
9021 int old_height
= WINDOW_TOTAL_LINES (w
);
9022 freeze_window_starts (f
, 1);
9023 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9024 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9026 else if (height
< WINDOW_TOTAL_LINES (w
)
9027 && (exact_p
|| BEGV
== ZV
))
9029 int old_height
= WINDOW_TOTAL_LINES (w
);
9030 freeze_window_starts (f
, 0);
9031 shrink_mini_window (w
);
9032 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9037 /* Always resize to exact size needed. */
9038 if (height
> WINDOW_TOTAL_LINES (w
))
9040 int old_height
= WINDOW_TOTAL_LINES (w
);
9041 freeze_window_starts (f
, 1);
9042 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9043 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9045 else if (height
< WINDOW_TOTAL_LINES (w
))
9047 int old_height
= WINDOW_TOTAL_LINES (w
);
9048 freeze_window_starts (f
, 0);
9049 shrink_mini_window (w
);
9053 freeze_window_starts (f
, 1);
9054 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
9057 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
9061 if (old_current_buffer
)
9062 set_buffer_internal (old_current_buffer
);
9065 return window_height_changed_p
;
9069 /* Value is the current message, a string, or nil if there is no
9077 if (!BUFFERP (echo_area_buffer
[0]))
9081 with_echo_area_buffer (0, 0, current_message_1
,
9082 (EMACS_INT
) &msg
, Qnil
, 0, 0);
9084 echo_area_buffer
[0] = Qnil
;
9092 current_message_1 (a1
, a2
, a3
, a4
)
9097 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
9100 *msg
= make_buffer_string (BEG
, Z
, 1);
9107 /* Push the current message on Vmessage_stack for later restauration
9108 by restore_message. Value is non-zero if the current message isn't
9109 empty. This is a relatively infrequent operation, so it's not
9110 worth optimizing. */
9116 msg
= current_message ();
9117 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
9118 return STRINGP (msg
);
9122 /* Restore message display from the top of Vmessage_stack. */
9129 xassert (CONSP (Vmessage_stack
));
9130 msg
= XCAR (Vmessage_stack
);
9132 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9134 message3_nolog (msg
, 0, 0);
9138 /* Handler for record_unwind_protect calling pop_message. */
9141 pop_message_unwind (dummy
)
9148 /* Pop the top-most entry off Vmessage_stack. */
9153 xassert (CONSP (Vmessage_stack
));
9154 Vmessage_stack
= XCDR (Vmessage_stack
);
9158 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
9159 exits. If the stack is not empty, we have a missing pop_message
9163 check_message_stack ()
9165 if (!NILP (Vmessage_stack
))
9170 /* Truncate to NCHARS what will be displayed in the echo area the next
9171 time we display it---but don't redisplay it now. */
9174 truncate_echo_area (nchars
)
9178 echo_area_buffer
[0] = Qnil
;
9179 /* A null message buffer means that the frame hasn't really been
9180 initialized yet. Error messages get reported properly by
9181 cmd_error, so this must be just an informative message; toss it. */
9182 else if (!noninteractive
9184 && !NILP (echo_area_buffer
[0]))
9186 struct frame
*sf
= SELECTED_FRAME ();
9187 if (FRAME_MESSAGE_BUF (sf
))
9188 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
9193 /* Helper function for truncate_echo_area. Truncate the current
9194 message to at most NCHARS characters. */
9197 truncate_message_1 (nchars
, a2
, a3
, a4
)
9202 if (BEG
+ nchars
< Z
)
9203 del_range (BEG
+ nchars
, Z
);
9205 echo_area_buffer
[0] = Qnil
;
9210 /* Set the current message to a substring of S or STRING.
9212 If STRING is a Lisp string, set the message to the first NBYTES
9213 bytes from STRING. NBYTES zero means use the whole string. If
9214 STRING is multibyte, the message will be displayed multibyte.
9216 If S is not null, set the message to the first LEN bytes of S. LEN
9217 zero means use the whole string. MULTIBYTE_P non-zero means S is
9218 multibyte. Display the message multibyte in that case.
9220 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
9221 to t before calling set_message_1 (which calls insert).
9225 set_message (s
, string
, nbytes
, multibyte_p
)
9228 int nbytes
, multibyte_p
;
9230 message_enable_multibyte
9231 = ((s
&& multibyte_p
)
9232 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
9234 with_echo_area_buffer (0, -1, set_message_1
,
9235 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
9236 message_buf_print
= 0;
9237 help_echo_showing_p
= 0;
9241 /* Helper function for set_message. Arguments have the same meaning
9242 as there, with A1 corresponding to S and A2 corresponding to STRING
9243 This function is called with the echo area buffer being
9247 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9250 EMACS_INT nbytes
, multibyte_p
;
9252 const char *s
= (const char *) a1
;
9253 Lisp_Object string
= a2
;
9255 /* Change multibyteness of the echo buffer appropriately. */
9256 if (message_enable_multibyte
9257 != !NILP (current_buffer
->enable_multibyte_characters
))
9258 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9260 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9262 /* Insert new message at BEG. */
9263 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9265 if (STRINGP (string
))
9270 nbytes
= SBYTES (string
);
9271 nchars
= string_byte_to_char (string
, nbytes
);
9273 /* This function takes care of single/multibyte conversion. We
9274 just have to ensure that the echo area buffer has the right
9275 setting of enable_multibyte_characters. */
9276 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9281 nbytes
= strlen (s
);
9283 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9285 /* Convert from multi-byte to single-byte. */
9287 unsigned char work
[1];
9289 /* Convert a multibyte string to single-byte. */
9290 for (i
= 0; i
< nbytes
; i
+= n
)
9292 c
= string_char_and_length (s
+ i
, &n
);
9293 work
[0] = (ASCII_CHAR_P (c
)
9295 : multibyte_char_to_unibyte (c
, Qnil
));
9296 insert_1_both (work
, 1, 1, 1, 0, 0);
9299 else if (!multibyte_p
9300 && !NILP (current_buffer
->enable_multibyte_characters
))
9302 /* Convert from single-byte to multi-byte. */
9304 const unsigned char *msg
= (const unsigned char *) s
;
9305 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9307 /* Convert a single-byte string to multibyte. */
9308 for (i
= 0; i
< nbytes
; i
++)
9311 MAKE_CHAR_MULTIBYTE (c
);
9312 n
= CHAR_STRING (c
, str
);
9313 insert_1_both (str
, 1, n
, 1, 0, 0);
9317 insert_1 (s
, nbytes
, 1, 0, 0);
9324 /* Clear messages. CURRENT_P non-zero means clear the current
9325 message. LAST_DISPLAYED_P non-zero means clear the message
9329 clear_message (current_p
, last_displayed_p
)
9330 int current_p
, last_displayed_p
;
9334 echo_area_buffer
[0] = Qnil
;
9335 message_cleared_p
= 1;
9338 if (last_displayed_p
)
9339 echo_area_buffer
[1] = Qnil
;
9341 message_buf_print
= 0;
9344 /* Clear garbaged frames.
9346 This function is used where the old redisplay called
9347 redraw_garbaged_frames which in turn called redraw_frame which in
9348 turn called clear_frame. The call to clear_frame was a source of
9349 flickering. I believe a clear_frame is not necessary. It should
9350 suffice in the new redisplay to invalidate all current matrices,
9351 and ensure a complete redisplay of all windows. */
9354 clear_garbaged_frames ()
9358 Lisp_Object tail
, frame
;
9359 int changed_count
= 0;
9361 FOR_EACH_FRAME (tail
, frame
)
9363 struct frame
*f
= XFRAME (frame
);
9365 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9369 Fredraw_frame (frame
);
9370 f
->force_flush_display_p
= 1;
9372 clear_current_matrices (f
);
9381 ++windows_or_buffers_changed
;
9386 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9387 is non-zero update selected_frame. Value is non-zero if the
9388 mini-windows height has been changed. */
9391 echo_area_display (update_frame_p
)
9394 Lisp_Object mini_window
;
9397 int window_height_changed_p
= 0;
9398 struct frame
*sf
= SELECTED_FRAME ();
9400 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9401 w
= XWINDOW (mini_window
);
9402 f
= XFRAME (WINDOW_FRAME (w
));
9404 /* Don't display if frame is invisible or not yet initialized. */
9405 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9408 #ifdef HAVE_WINDOW_SYSTEM
9409 /* When Emacs starts, selected_frame may be the initial terminal
9410 frame. If we let this through, a message would be displayed on
9412 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9414 #endif /* HAVE_WINDOW_SYSTEM */
9416 /* Redraw garbaged frames. */
9418 clear_garbaged_frames ();
9420 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9422 echo_area_window
= mini_window
;
9423 window_height_changed_p
= display_echo_area (w
);
9424 w
->must_be_updated_p
= 1;
9426 /* Update the display, unless called from redisplay_internal.
9427 Also don't update the screen during redisplay itself. The
9428 update will happen at the end of redisplay, and an update
9429 here could cause confusion. */
9430 if (update_frame_p
&& !redisplaying_p
)
9434 /* If the display update has been interrupted by pending
9435 input, update mode lines in the frame. Due to the
9436 pending input, it might have been that redisplay hasn't
9437 been called, so that mode lines above the echo area are
9438 garbaged. This looks odd, so we prevent it here. */
9439 if (!display_completed
)
9440 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9442 if (window_height_changed_p
9443 /* Don't do this if Emacs is shutting down. Redisplay
9444 needs to run hooks. */
9445 && !NILP (Vrun_hooks
))
9447 /* Must update other windows. Likewise as in other
9448 cases, don't let this update be interrupted by
9450 int count
= SPECPDL_INDEX ();
9451 specbind (Qredisplay_dont_pause
, Qt
);
9452 windows_or_buffers_changed
= 1;
9453 redisplay_internal (0);
9454 unbind_to (count
, Qnil
);
9456 else if (FRAME_WINDOW_P (f
) && n
== 0)
9458 /* Window configuration is the same as before.
9459 Can do with a display update of the echo area,
9460 unless we displayed some mode lines. */
9461 update_single_window (w
, 1);
9462 FRAME_RIF (f
)->flush_display (f
);
9465 update_frame (f
, 1, 1);
9467 /* If cursor is in the echo area, make sure that the next
9468 redisplay displays the minibuffer, so that the cursor will
9469 be replaced with what the minibuffer wants. */
9470 if (cursor_in_echo_area
)
9471 ++windows_or_buffers_changed
;
9474 else if (!EQ (mini_window
, selected_window
))
9475 windows_or_buffers_changed
++;
9477 /* Last displayed message is now the current message. */
9478 echo_area_buffer
[1] = echo_area_buffer
[0];
9479 /* Inform read_char that we're not echoing. */
9480 echo_message_buffer
= Qnil
;
9482 /* Prevent redisplay optimization in redisplay_internal by resetting
9483 this_line_start_pos. This is done because the mini-buffer now
9484 displays the message instead of its buffer text. */
9485 if (EQ (mini_window
, selected_window
))
9486 CHARPOS (this_line_start_pos
) = 0;
9488 return window_height_changed_p
;
9493 /***********************************************************************
9494 Mode Lines and Frame Titles
9495 ***********************************************************************/
9497 /* A buffer for constructing non-propertized mode-line strings and
9498 frame titles in it; allocated from the heap in init_xdisp and
9499 resized as needed in store_mode_line_noprop_char. */
9501 static char *mode_line_noprop_buf
;
9503 /* The buffer's end, and a current output position in it. */
9505 static char *mode_line_noprop_buf_end
;
9506 static char *mode_line_noprop_ptr
;
9508 #define MODE_LINE_NOPROP_LEN(start) \
9509 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9512 MODE_LINE_DISPLAY
= 0,
9518 /* Alist that caches the results of :propertize.
9519 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9520 static Lisp_Object mode_line_proptrans_alist
;
9522 /* List of strings making up the mode-line. */
9523 static Lisp_Object mode_line_string_list
;
9525 /* Base face property when building propertized mode line string. */
9526 static Lisp_Object mode_line_string_face
;
9527 static Lisp_Object mode_line_string_face_prop
;
9530 /* Unwind data for mode line strings */
9532 static Lisp_Object Vmode_line_unwind_vector
;
9535 format_mode_line_unwind_data (struct buffer
*obuf
,
9539 Lisp_Object vector
, tmp
;
9541 /* Reduce consing by keeping one vector in
9542 Vwith_echo_area_save_vector. */
9543 vector
= Vmode_line_unwind_vector
;
9544 Vmode_line_unwind_vector
= Qnil
;
9547 vector
= Fmake_vector (make_number (8), Qnil
);
9549 ASET (vector
, 0, make_number (mode_line_target
));
9550 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9551 ASET (vector
, 2, mode_line_string_list
);
9552 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9553 ASET (vector
, 4, mode_line_string_face
);
9554 ASET (vector
, 5, mode_line_string_face_prop
);
9557 XSETBUFFER (tmp
, obuf
);
9560 ASET (vector
, 6, tmp
);
9561 ASET (vector
, 7, owin
);
9567 unwind_format_mode_line (vector
)
9570 mode_line_target
= XINT (AREF (vector
, 0));
9571 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9572 mode_line_string_list
= AREF (vector
, 2);
9573 if (! EQ (AREF (vector
, 3), Qt
))
9574 mode_line_proptrans_alist
= AREF (vector
, 3);
9575 mode_line_string_face
= AREF (vector
, 4);
9576 mode_line_string_face_prop
= AREF (vector
, 5);
9578 if (!NILP (AREF (vector
, 7)))
9579 /* Select window before buffer, since it may change the buffer. */
9580 Fselect_window (AREF (vector
, 7), Qt
);
9582 if (!NILP (AREF (vector
, 6)))
9584 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9585 ASET (vector
, 6, Qnil
);
9588 Vmode_line_unwind_vector
= vector
;
9593 /* Store a single character C for the frame title in mode_line_noprop_buf.
9594 Re-allocate mode_line_noprop_buf if necessary. */
9598 store_mode_line_noprop_char (char c
)
9600 store_mode_line_noprop_char (c
)
9604 /* If output position has reached the end of the allocated buffer,
9605 double the buffer's size. */
9606 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9608 int len
= MODE_LINE_NOPROP_LEN (0);
9609 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9610 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9611 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9612 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9615 *mode_line_noprop_ptr
++ = c
;
9619 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9620 mode_line_noprop_ptr. STR is the string to store. Do not copy
9621 characters that yield more columns than PRECISION; PRECISION <= 0
9622 means copy the whole string. Pad with spaces until FIELD_WIDTH
9623 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9624 pad. Called from display_mode_element when it is used to build a
9628 store_mode_line_noprop (str
, field_width
, precision
)
9629 const unsigned char *str
;
9630 int field_width
, precision
;
9635 /* Copy at most PRECISION chars from STR. */
9636 nbytes
= strlen (str
);
9637 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9639 store_mode_line_noprop_char (*str
++);
9641 /* Fill up with spaces until FIELD_WIDTH reached. */
9642 while (field_width
> 0
9645 store_mode_line_noprop_char (' ');
9652 /***********************************************************************
9654 ***********************************************************************/
9656 #ifdef HAVE_WINDOW_SYSTEM
9658 /* Set the title of FRAME, if it has changed. The title format is
9659 Vicon_title_format if FRAME is iconified, otherwise it is
9660 frame_title_format. */
9663 x_consider_frame_title (frame
)
9666 struct frame
*f
= XFRAME (frame
);
9668 if (FRAME_WINDOW_P (f
)
9669 || FRAME_MINIBUF_ONLY_P (f
)
9670 || f
->explicit_name
)
9672 /* Do we have more than one visible frame on this X display? */
9679 int count
= SPECPDL_INDEX ();
9681 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9683 Lisp_Object other_frame
= XCAR (tail
);
9684 struct frame
*tf
= XFRAME (other_frame
);
9687 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9688 && !FRAME_MINIBUF_ONLY_P (tf
)
9689 && !EQ (other_frame
, tip_frame
)
9690 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9694 /* Set global variable indicating that multiple frames exist. */
9695 multiple_frames
= CONSP (tail
);
9697 /* Switch to the buffer of selected window of the frame. Set up
9698 mode_line_target so that display_mode_element will output into
9699 mode_line_noprop_buf; then display the title. */
9700 record_unwind_protect (unwind_format_mode_line
,
9701 format_mode_line_unwind_data
9702 (current_buffer
, selected_window
, 0));
9704 Fselect_window (f
->selected_window
, Qt
);
9705 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9706 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9708 mode_line_target
= MODE_LINE_TITLE
;
9709 title_start
= MODE_LINE_NOPROP_LEN (0);
9710 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9711 NULL
, DEFAULT_FACE_ID
);
9712 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9713 len
= MODE_LINE_NOPROP_LEN (title_start
);
9714 title
= mode_line_noprop_buf
+ title_start
;
9715 unbind_to (count
, Qnil
);
9717 /* Set the title only if it's changed. This avoids consing in
9718 the common case where it hasn't. (If it turns out that we've
9719 already wasted too much time by walking through the list with
9720 display_mode_element, then we might need to optimize at a
9721 higher level than this.) */
9722 if (! STRINGP (f
->name
)
9723 || SBYTES (f
->name
) != len
9724 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9729 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9732 ns_set_name_as_filename (f
);
9734 x_implicitly_set_name (f
, make_string(title
, len
),
9740 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9745 /* do this also for frames with explicit names */
9746 ns_implicitly_set_icon_type(f
);
9747 ns_set_doc_edited(f
, Fbuffer_modified_p
9748 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9754 #endif /* not HAVE_WINDOW_SYSTEM */
9759 /***********************************************************************
9761 ***********************************************************************/
9764 /* Prepare for redisplay by updating menu-bar item lists when
9765 appropriate. This can call eval. */
9768 prepare_menu_bars ()
9771 struct gcpro gcpro1
, gcpro2
;
9773 Lisp_Object tooltip_frame
;
9775 #ifdef HAVE_WINDOW_SYSTEM
9776 tooltip_frame
= tip_frame
;
9778 tooltip_frame
= Qnil
;
9781 /* Update all frame titles based on their buffer names, etc. We do
9782 this before the menu bars so that the buffer-menu will show the
9783 up-to-date frame titles. */
9784 #ifdef HAVE_WINDOW_SYSTEM
9785 if (windows_or_buffers_changed
|| update_mode_lines
)
9787 Lisp_Object tail
, frame
;
9789 FOR_EACH_FRAME (tail
, frame
)
9792 if (!EQ (frame
, tooltip_frame
)
9793 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9794 x_consider_frame_title (frame
);
9797 #endif /* HAVE_WINDOW_SYSTEM */
9799 /* Update the menu bar item lists, if appropriate. This has to be
9800 done before any actual redisplay or generation of display lines. */
9801 all_windows
= (update_mode_lines
9802 || buffer_shared
> 1
9803 || windows_or_buffers_changed
);
9806 Lisp_Object tail
, frame
;
9807 int count
= SPECPDL_INDEX ();
9808 /* 1 means that update_menu_bar has run its hooks
9809 so any further calls to update_menu_bar shouldn't do so again. */
9810 int menu_bar_hooks_run
= 0;
9812 record_unwind_save_match_data ();
9814 FOR_EACH_FRAME (tail
, frame
)
9818 /* Ignore tooltip frame. */
9819 if (EQ (frame
, tooltip_frame
))
9822 /* If a window on this frame changed size, report that to
9823 the user and clear the size-change flag. */
9824 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9826 Lisp_Object functions
;
9828 /* Clear flag first in case we get an error below. */
9829 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9830 functions
= Vwindow_size_change_functions
;
9831 GCPRO2 (tail
, functions
);
9833 while (CONSP (functions
))
9835 if (!EQ (XCAR (functions
), Qt
))
9836 call1 (XCAR (functions
), frame
);
9837 functions
= XCDR (functions
);
9843 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9844 #ifdef HAVE_WINDOW_SYSTEM
9845 update_tool_bar (f
, 0);
9850 unbind_to (count
, Qnil
);
9854 struct frame
*sf
= SELECTED_FRAME ();
9855 update_menu_bar (sf
, 1, 0);
9856 #ifdef HAVE_WINDOW_SYSTEM
9857 update_tool_bar (sf
, 1);
9861 /* Motif needs this. See comment in xmenu.c. Turn it off when
9862 pending_menu_activation is not defined. */
9863 #ifdef USE_X_TOOLKIT
9864 pending_menu_activation
= 0;
9869 /* Update the menu bar item list for frame F. This has to be done
9870 before we start to fill in any display lines, because it can call
9873 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9875 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9876 already ran the menu bar hooks for this redisplay, so there
9877 is no need to run them again. The return value is the
9878 updated value of this flag, to pass to the next call. */
9881 update_menu_bar (f
, save_match_data
, hooks_run
)
9883 int save_match_data
;
9887 register struct window
*w
;
9889 /* If called recursively during a menu update, do nothing. This can
9890 happen when, for instance, an activate-menubar-hook causes a
9892 if (inhibit_menubar_update
)
9895 window
= FRAME_SELECTED_WINDOW (f
);
9896 w
= XWINDOW (window
);
9898 if (FRAME_WINDOW_P (f
)
9900 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9901 || defined (HAVE_NS) || defined (USE_GTK)
9902 FRAME_EXTERNAL_MENU_BAR (f
)
9904 FRAME_MENU_BAR_LINES (f
) > 0
9906 : FRAME_MENU_BAR_LINES (f
) > 0)
9908 /* If the user has switched buffers or windows, we need to
9909 recompute to reflect the new bindings. But we'll
9910 recompute when update_mode_lines is set too; that means
9911 that people can use force-mode-line-update to request
9912 that the menu bar be recomputed. The adverse effect on
9913 the rest of the redisplay algorithm is about the same as
9914 windows_or_buffers_changed anyway. */
9915 if (windows_or_buffers_changed
9916 /* This used to test w->update_mode_line, but we believe
9917 there is no need to recompute the menu in that case. */
9918 || update_mode_lines
9919 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9920 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9921 != !NILP (w
->last_had_star
))
9922 || ((!NILP (Vtransient_mark_mode
)
9923 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9924 != !NILP (w
->region_showing
)))
9926 struct buffer
*prev
= current_buffer
;
9927 int count
= SPECPDL_INDEX ();
9929 specbind (Qinhibit_menubar_update
, Qt
);
9931 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9932 if (save_match_data
)
9933 record_unwind_save_match_data ();
9934 if (NILP (Voverriding_local_map_menu_flag
))
9936 specbind (Qoverriding_terminal_local_map
, Qnil
);
9937 specbind (Qoverriding_local_map
, Qnil
);
9942 /* Run the Lucid hook. */
9943 safe_run_hooks (Qactivate_menubar_hook
);
9945 /* If it has changed current-menubar from previous value,
9946 really recompute the menu-bar from the value. */
9947 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9948 call0 (Qrecompute_lucid_menubar
);
9950 safe_run_hooks (Qmenu_bar_update_hook
);
9955 XSETFRAME (Vmenu_updating_frame
, f
);
9956 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9958 /* Redisplay the menu bar in case we changed it. */
9959 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9960 || defined (HAVE_NS) || defined (USE_GTK)
9961 if (FRAME_WINDOW_P (f
))
9963 #if defined (HAVE_NS)
9964 /* All frames on Mac OS share the same menubar. So only
9965 the selected frame should be allowed to set it. */
9966 if (f
== SELECTED_FRAME ())
9968 set_frame_menubar (f
, 0, 0);
9971 /* On a terminal screen, the menu bar is an ordinary screen
9972 line, and this makes it get updated. */
9973 w
->update_mode_line
= Qt
;
9974 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9975 /* In the non-toolkit version, the menu bar is an ordinary screen
9976 line, and this makes it get updated. */
9977 w
->update_mode_line
= Qt
;
9978 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9980 unbind_to (count
, Qnil
);
9981 set_buffer_internal_1 (prev
);
9990 /***********************************************************************
9992 ***********************************************************************/
9994 #ifdef HAVE_WINDOW_SYSTEM
9997 Nominal cursor position -- where to draw output.
9998 HPOS and VPOS are window relative glyph matrix coordinates.
9999 X and Y are window relative pixel coordinates. */
10001 struct cursor_pos output_cursor
;
10005 Set the global variable output_cursor to CURSOR. All cursor
10006 positions are relative to updated_window. */
10009 set_output_cursor (cursor
)
10010 struct cursor_pos
*cursor
;
10012 output_cursor
.hpos
= cursor
->hpos
;
10013 output_cursor
.vpos
= cursor
->vpos
;
10014 output_cursor
.x
= cursor
->x
;
10015 output_cursor
.y
= cursor
->y
;
10020 Set a nominal cursor position.
10022 HPOS and VPOS are column/row positions in a window glyph matrix. X
10023 and Y are window text area relative pixel positions.
10025 If this is done during an update, updated_window will contain the
10026 window that is being updated and the position is the future output
10027 cursor position for that window. If updated_window is null, use
10028 selected_window and display the cursor at the given position. */
10031 x_cursor_to (vpos
, hpos
, y
, x
)
10032 int vpos
, hpos
, y
, x
;
10036 /* If updated_window is not set, work on selected_window. */
10037 if (updated_window
)
10038 w
= updated_window
;
10040 w
= XWINDOW (selected_window
);
10042 /* Set the output cursor. */
10043 output_cursor
.hpos
= hpos
;
10044 output_cursor
.vpos
= vpos
;
10045 output_cursor
.x
= x
;
10046 output_cursor
.y
= y
;
10048 /* If not called as part of an update, really display the cursor.
10049 This will also set the cursor position of W. */
10050 if (updated_window
== NULL
)
10053 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
10054 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
10055 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
10060 #endif /* HAVE_WINDOW_SYSTEM */
10063 /***********************************************************************
10065 ***********************************************************************/
10067 #ifdef HAVE_WINDOW_SYSTEM
10069 /* Where the mouse was last time we reported a mouse event. */
10071 FRAME_PTR last_mouse_frame
;
10073 /* Tool-bar item index of the item on which a mouse button was pressed
10076 int last_tool_bar_item
;
10080 update_tool_bar_unwind (frame
)
10083 selected_frame
= frame
;
10087 /* Update the tool-bar item list for frame F. This has to be done
10088 before we start to fill in any display lines. Called from
10089 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
10090 and restore it here. */
10093 update_tool_bar (f
, save_match_data
)
10095 int save_match_data
;
10097 #if defined (USE_GTK) || defined (HAVE_NS)
10098 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
10100 int do_update
= WINDOWP (f
->tool_bar_window
)
10101 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
10106 Lisp_Object window
;
10109 window
= FRAME_SELECTED_WINDOW (f
);
10110 w
= XWINDOW (window
);
10112 /* If the user has switched buffers or windows, we need to
10113 recompute to reflect the new bindings. But we'll
10114 recompute when update_mode_lines is set too; that means
10115 that people can use force-mode-line-update to request
10116 that the menu bar be recomputed. The adverse effect on
10117 the rest of the redisplay algorithm is about the same as
10118 windows_or_buffers_changed anyway. */
10119 if (windows_or_buffers_changed
10120 || !NILP (w
->update_mode_line
)
10121 || update_mode_lines
10122 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
10123 < BUF_MODIFF (XBUFFER (w
->buffer
)))
10124 != !NILP (w
->last_had_star
))
10125 || ((!NILP (Vtransient_mark_mode
)
10126 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
10127 != !NILP (w
->region_showing
)))
10129 struct buffer
*prev
= current_buffer
;
10130 int count
= SPECPDL_INDEX ();
10131 Lisp_Object frame
, new_tool_bar
;
10132 int new_n_tool_bar
;
10133 struct gcpro gcpro1
;
10135 /* Set current_buffer to the buffer of the selected
10136 window of the frame, so that we get the right local
10138 set_buffer_internal_1 (XBUFFER (w
->buffer
));
10140 /* Save match data, if we must. */
10141 if (save_match_data
)
10142 record_unwind_save_match_data ();
10144 /* Make sure that we don't accidentally use bogus keymaps. */
10145 if (NILP (Voverriding_local_map_menu_flag
))
10147 specbind (Qoverriding_terminal_local_map
, Qnil
);
10148 specbind (Qoverriding_local_map
, Qnil
);
10151 GCPRO1 (new_tool_bar
);
10153 /* We must temporarily set the selected frame to this frame
10154 before calling tool_bar_items, because the calculation of
10155 the tool-bar keymap uses the selected frame (see
10156 `tool-bar-make-keymap' in tool-bar.el). */
10157 record_unwind_protect (update_tool_bar_unwind
, selected_frame
);
10158 XSETFRAME (frame
, f
);
10159 selected_frame
= frame
;
10161 /* Build desired tool-bar items from keymaps. */
10162 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
10165 /* Redisplay the tool-bar if we changed it. */
10166 if (new_n_tool_bar
!= f
->n_tool_bar_items
10167 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
10169 /* Redisplay that happens asynchronously due to an expose event
10170 may access f->tool_bar_items. Make sure we update both
10171 variables within BLOCK_INPUT so no such event interrupts. */
10173 f
->tool_bar_items
= new_tool_bar
;
10174 f
->n_tool_bar_items
= new_n_tool_bar
;
10175 w
->update_mode_line
= Qt
;
10181 unbind_to (count
, Qnil
);
10182 set_buffer_internal_1 (prev
);
10188 /* Set F->desired_tool_bar_string to a Lisp string representing frame
10189 F's desired tool-bar contents. F->tool_bar_items must have
10190 been set up previously by calling prepare_menu_bars. */
10193 build_desired_tool_bar_string (f
)
10196 int i
, size
, size_needed
;
10197 struct gcpro gcpro1
, gcpro2
, gcpro3
;
10198 Lisp_Object image
, plist
, props
;
10200 image
= plist
= props
= Qnil
;
10201 GCPRO3 (image
, plist
, props
);
10203 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
10204 Otherwise, make a new string. */
10206 /* The size of the string we might be able to reuse. */
10207 size
= (STRINGP (f
->desired_tool_bar_string
)
10208 ? SCHARS (f
->desired_tool_bar_string
)
10211 /* We need one space in the string for each image. */
10212 size_needed
= f
->n_tool_bar_items
;
10214 /* Reuse f->desired_tool_bar_string, if possible. */
10215 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
10216 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
10217 make_number (' '));
10220 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
10221 Fremove_text_properties (make_number (0), make_number (size
),
10222 props
, f
->desired_tool_bar_string
);
10225 /* Put a `display' property on the string for the images to display,
10226 put a `menu_item' property on tool-bar items with a value that
10227 is the index of the item in F's tool-bar item vector. */
10228 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
10230 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
10232 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
10233 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
10234 int hmargin
, vmargin
, relief
, idx
, end
;
10235 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
10237 /* If image is a vector, choose the image according to the
10239 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
10240 if (VECTORP (image
))
10244 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
10245 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
10248 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
10249 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
10251 xassert (ASIZE (image
) >= idx
);
10252 image
= AREF (image
, idx
);
10257 /* Ignore invalid image specifications. */
10258 if (!valid_image_p (image
))
10261 /* Display the tool-bar button pressed, or depressed. */
10262 plist
= Fcopy_sequence (XCDR (image
));
10264 /* Compute margin and relief to draw. */
10265 relief
= (tool_bar_button_relief
>= 0
10266 ? tool_bar_button_relief
10267 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10268 hmargin
= vmargin
= relief
;
10270 if (INTEGERP (Vtool_bar_button_margin
)
10271 && XINT (Vtool_bar_button_margin
) > 0)
10273 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10274 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10276 else if (CONSP (Vtool_bar_button_margin
))
10278 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10279 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10280 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10282 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10283 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10284 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10287 if (auto_raise_tool_bar_buttons_p
)
10289 /* Add a `:relief' property to the image spec if the item is
10293 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10300 /* If image is selected, display it pressed, i.e. with a
10301 negative relief. If it's not selected, display it with a
10303 plist
= Fplist_put (plist
, QCrelief
,
10305 ? make_number (-relief
)
10306 : make_number (relief
)));
10311 /* Put a margin around the image. */
10312 if (hmargin
|| vmargin
)
10314 if (hmargin
== vmargin
)
10315 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10317 plist
= Fplist_put (plist
, QCmargin
,
10318 Fcons (make_number (hmargin
),
10319 make_number (vmargin
)));
10322 /* If button is not enabled, and we don't have special images
10323 for the disabled state, make the image appear disabled by
10324 applying an appropriate algorithm to it. */
10325 if (!enabled_p
&& idx
< 0)
10326 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10328 /* Put a `display' text property on the string for the image to
10329 display. Put a `menu-item' property on the string that gives
10330 the start of this item's properties in the tool-bar items
10332 image
= Fcons (Qimage
, plist
);
10333 props
= list4 (Qdisplay
, image
,
10334 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10336 /* Let the last image hide all remaining spaces in the tool bar
10337 string. The string can be longer than needed when we reuse a
10338 previous string. */
10339 if (i
+ 1 == f
->n_tool_bar_items
)
10340 end
= SCHARS (f
->desired_tool_bar_string
);
10343 Fadd_text_properties (make_number (i
), make_number (end
),
10344 props
, f
->desired_tool_bar_string
);
10352 /* Display one line of the tool-bar of frame IT->f.
10354 HEIGHT specifies the desired height of the tool-bar line.
10355 If the actual height of the glyph row is less than HEIGHT, the
10356 row's height is increased to HEIGHT, and the icons are centered
10357 vertically in the new height.
10359 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10360 count a final empty row in case the tool-bar width exactly matches
10365 display_tool_bar_line (it
, height
)
10369 struct glyph_row
*row
= it
->glyph_row
;
10370 int max_x
= it
->last_visible_x
;
10371 struct glyph
*last
;
10373 prepare_desired_row (row
);
10374 row
->y
= it
->current_y
;
10376 /* Note that this isn't made use of if the face hasn't a box,
10377 so there's no need to check the face here. */
10378 it
->start_of_box_run_p
= 1;
10380 while (it
->current_x
< max_x
)
10382 int x
, n_glyphs_before
, i
, nglyphs
;
10383 struct it it_before
;
10385 /* Get the next display element. */
10386 if (!get_next_display_element (it
))
10388 /* Don't count empty row if we are counting needed tool-bar lines. */
10389 if (height
< 0 && !it
->hpos
)
10394 /* Produce glyphs. */
10395 n_glyphs_before
= row
->used
[TEXT_AREA
];
10398 PRODUCE_GLYPHS (it
);
10400 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10402 x
= it_before
.current_x
;
10403 while (i
< nglyphs
)
10405 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10407 if (x
+ glyph
->pixel_width
> max_x
)
10409 /* Glyph doesn't fit on line. Backtrack. */
10410 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10412 /* If this is the only glyph on this line, it will never fit on the
10413 toolbar, so skip it. But ensure there is at least one glyph,
10414 so we don't accidentally disable the tool-bar. */
10415 if (n_glyphs_before
== 0
10416 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10422 x
+= glyph
->pixel_width
;
10426 /* Stop at line ends. */
10427 if (ITERATOR_AT_END_OF_LINE_P (it
))
10430 set_iterator_to_next (it
, 1);
10435 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10437 /* Use default face for the border below the tool bar.
10439 FIXME: When auto-resize-tool-bars is grow-only, there is
10440 no additional border below the possibly empty tool-bar lines.
10441 So to make the extra empty lines look "normal", we have to
10442 use the tool-bar face for the border too. */
10443 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10444 it
->face_id
= DEFAULT_FACE_ID
;
10446 extend_face_to_end_of_line (it
);
10447 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10448 last
->right_box_line_p
= 1;
10449 if (last
== row
->glyphs
[TEXT_AREA
])
10450 last
->left_box_line_p
= 1;
10452 /* Make line the desired height and center it vertically. */
10453 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10455 /* Don't add more than one line height. */
10456 height
%= FRAME_LINE_HEIGHT (it
->f
);
10457 it
->max_ascent
+= height
/ 2;
10458 it
->max_descent
+= (height
+ 1) / 2;
10461 compute_line_metrics (it
);
10463 /* If line is empty, make it occupy the rest of the tool-bar. */
10464 if (!row
->displays_text_p
)
10466 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10467 row
->visible_height
= row
->height
;
10468 row
->ascent
= row
->phys_ascent
= 0;
10469 row
->extra_line_spacing
= 0;
10472 row
->full_width_p
= 1;
10473 row
->continued_p
= 0;
10474 row
->truncated_on_left_p
= 0;
10475 row
->truncated_on_right_p
= 0;
10477 it
->current_x
= it
->hpos
= 0;
10478 it
->current_y
+= row
->height
;
10484 /* Max tool-bar height. */
10486 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10487 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10489 /* Value is the number of screen lines needed to make all tool-bar
10490 items of frame F visible. The number of actual rows needed is
10491 returned in *N_ROWS if non-NULL. */
10494 tool_bar_lines_needed (f
, n_rows
)
10498 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10500 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10501 the desired matrix, so use (unused) mode-line row as temporary row to
10502 avoid destroying the first tool-bar row. */
10503 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10505 /* Initialize an iterator for iteration over
10506 F->desired_tool_bar_string in the tool-bar window of frame F. */
10507 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10508 it
.first_visible_x
= 0;
10509 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10510 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10512 while (!ITERATOR_AT_END_P (&it
))
10514 clear_glyph_row (temp_row
);
10515 it
.glyph_row
= temp_row
;
10516 display_tool_bar_line (&it
, -1);
10518 clear_glyph_row (temp_row
);
10520 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10522 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10524 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10528 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10530 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10539 frame
= selected_frame
;
10541 CHECK_FRAME (frame
);
10542 f
= XFRAME (frame
);
10544 if (WINDOWP (f
->tool_bar_window
)
10545 || (w
= XWINDOW (f
->tool_bar_window
),
10546 WINDOW_TOTAL_LINES (w
) > 0))
10548 update_tool_bar (f
, 1);
10549 if (f
->n_tool_bar_items
)
10551 build_desired_tool_bar_string (f
);
10552 nlines
= tool_bar_lines_needed (f
, NULL
);
10556 return make_number (nlines
);
10560 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10561 height should be changed. */
10564 redisplay_tool_bar (f
)
10569 struct glyph_row
*row
;
10571 #if defined (USE_GTK) || defined (HAVE_NS)
10572 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10573 update_frame_tool_bar (f
);
10577 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10578 do anything. This means you must start with tool-bar-lines
10579 non-zero to get the auto-sizing effect. Or in other words, you
10580 can turn off tool-bars by specifying tool-bar-lines zero. */
10581 if (!WINDOWP (f
->tool_bar_window
)
10582 || (w
= XWINDOW (f
->tool_bar_window
),
10583 WINDOW_TOTAL_LINES (w
) == 0))
10586 /* Set up an iterator for the tool-bar window. */
10587 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10588 it
.first_visible_x
= 0;
10589 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10590 row
= it
.glyph_row
;
10592 /* Build a string that represents the contents of the tool-bar. */
10593 build_desired_tool_bar_string (f
);
10594 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10596 if (f
->n_tool_bar_rows
== 0)
10600 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10601 nlines
!= WINDOW_TOTAL_LINES (w
)))
10603 extern Lisp_Object Qtool_bar_lines
;
10605 int old_height
= WINDOW_TOTAL_LINES (w
);
10607 XSETFRAME (frame
, f
);
10608 Fmodify_frame_parameters (frame
,
10609 Fcons (Fcons (Qtool_bar_lines
,
10610 make_number (nlines
)),
10612 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10614 clear_glyph_matrix (w
->desired_matrix
);
10615 fonts_changed_p
= 1;
10621 /* Display as many lines as needed to display all tool-bar items. */
10623 if (f
->n_tool_bar_rows
> 0)
10625 int border
, rows
, height
, extra
;
10627 if (INTEGERP (Vtool_bar_border
))
10628 border
= XINT (Vtool_bar_border
);
10629 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10630 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10631 else if (EQ (Vtool_bar_border
, Qborder_width
))
10632 border
= f
->border_width
;
10638 rows
= f
->n_tool_bar_rows
;
10639 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10640 extra
= it
.last_visible_y
- border
- height
* rows
;
10642 while (it
.current_y
< it
.last_visible_y
)
10645 if (extra
> 0 && rows
-- > 0)
10647 h
= (extra
+ rows
- 1) / rows
;
10650 display_tool_bar_line (&it
, height
+ h
);
10655 while (it
.current_y
< it
.last_visible_y
)
10656 display_tool_bar_line (&it
, 0);
10659 /* It doesn't make much sense to try scrolling in the tool-bar
10660 window, so don't do it. */
10661 w
->desired_matrix
->no_scrolling_p
= 1;
10662 w
->must_be_updated_p
= 1;
10664 if (!NILP (Vauto_resize_tool_bars
))
10666 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10667 int change_height_p
= 0;
10669 /* If we couldn't display everything, change the tool-bar's
10670 height if there is room for more. */
10671 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10672 && it
.current_y
< max_tool_bar_height
)
10673 change_height_p
= 1;
10675 row
= it
.glyph_row
- 1;
10677 /* If there are blank lines at the end, except for a partially
10678 visible blank line at the end that is smaller than
10679 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10680 if (!row
->displays_text_p
10681 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10682 change_height_p
= 1;
10684 /* If row displays tool-bar items, but is partially visible,
10685 change the tool-bar's height. */
10686 if (row
->displays_text_p
10687 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10688 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10689 change_height_p
= 1;
10691 /* Resize windows as needed by changing the `tool-bar-lines'
10692 frame parameter. */
10693 if (change_height_p
)
10695 extern Lisp_Object Qtool_bar_lines
;
10697 int old_height
= WINDOW_TOTAL_LINES (w
);
10699 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10701 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10702 && !f
->minimize_tool_bar_window_p
)
10703 ? (nlines
> old_height
)
10704 : (nlines
!= old_height
));
10705 f
->minimize_tool_bar_window_p
= 0;
10707 if (change_height_p
)
10709 XSETFRAME (frame
, f
);
10710 Fmodify_frame_parameters (frame
,
10711 Fcons (Fcons (Qtool_bar_lines
,
10712 make_number (nlines
)),
10714 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10716 clear_glyph_matrix (w
->desired_matrix
);
10717 f
->n_tool_bar_rows
= nrows
;
10718 fonts_changed_p
= 1;
10725 f
->minimize_tool_bar_window_p
= 0;
10730 /* Get information about the tool-bar item which is displayed in GLYPH
10731 on frame F. Return in *PROP_IDX the index where tool-bar item
10732 properties start in F->tool_bar_items. Value is zero if
10733 GLYPH doesn't display a tool-bar item. */
10736 tool_bar_item_info (f
, glyph
, prop_idx
)
10738 struct glyph
*glyph
;
10745 /* This function can be called asynchronously, which means we must
10746 exclude any possibility that Fget_text_property signals an
10748 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10749 charpos
= max (0, charpos
);
10751 /* Get the text property `menu-item' at pos. The value of that
10752 property is the start index of this item's properties in
10753 F->tool_bar_items. */
10754 prop
= Fget_text_property (make_number (charpos
),
10755 Qmenu_item
, f
->current_tool_bar_string
);
10756 if (INTEGERP (prop
))
10758 *prop_idx
= XINT (prop
);
10768 /* Get information about the tool-bar item at position X/Y on frame F.
10769 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10770 the current matrix of the tool-bar window of F, or NULL if not
10771 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10772 item in F->tool_bar_items. Value is
10774 -1 if X/Y is not on a tool-bar item
10775 0 if X/Y is on the same item that was highlighted before.
10779 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10782 struct glyph
**glyph
;
10783 int *hpos
, *vpos
, *prop_idx
;
10785 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10786 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10789 /* Find the glyph under X/Y. */
10790 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10791 if (*glyph
== NULL
)
10794 /* Get the start of this tool-bar item's properties in
10795 f->tool_bar_items. */
10796 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10799 /* Is mouse on the highlighted item? */
10800 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10801 && *vpos
>= dpyinfo
->mouse_face_beg_row
10802 && *vpos
<= dpyinfo
->mouse_face_end_row
10803 && (*vpos
> dpyinfo
->mouse_face_beg_row
10804 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10805 && (*vpos
< dpyinfo
->mouse_face_end_row
10806 || *hpos
< dpyinfo
->mouse_face_end_col
10807 || dpyinfo
->mouse_face_past_end
))
10815 Handle mouse button event on the tool-bar of frame F, at
10816 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10817 0 for button release. MODIFIERS is event modifiers for button
10821 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10824 unsigned int modifiers
;
10826 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10827 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10828 int hpos
, vpos
, prop_idx
;
10829 struct glyph
*glyph
;
10830 Lisp_Object enabled_p
;
10832 /* If not on the highlighted tool-bar item, return. */
10833 frame_to_window_pixel_xy (w
, &x
, &y
);
10834 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10837 /* If item is disabled, do nothing. */
10838 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10839 if (NILP (enabled_p
))
10844 /* Show item in pressed state. */
10845 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10846 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10847 last_tool_bar_item
= prop_idx
;
10851 Lisp_Object key
, frame
;
10852 struct input_event event
;
10853 EVENT_INIT (event
);
10855 /* Show item in released state. */
10856 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10857 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10859 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10861 XSETFRAME (frame
, f
);
10862 event
.kind
= TOOL_BAR_EVENT
;
10863 event
.frame_or_window
= frame
;
10865 kbd_buffer_store_event (&event
);
10867 event
.kind
= TOOL_BAR_EVENT
;
10868 event
.frame_or_window
= frame
;
10870 event
.modifiers
= modifiers
;
10871 kbd_buffer_store_event (&event
);
10872 last_tool_bar_item
= -1;
10877 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10878 tool-bar window-relative coordinates X/Y. Called from
10879 note_mouse_highlight. */
10882 note_tool_bar_highlight (f
, x
, y
)
10886 Lisp_Object window
= f
->tool_bar_window
;
10887 struct window
*w
= XWINDOW (window
);
10888 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10890 struct glyph
*glyph
;
10891 struct glyph_row
*row
;
10893 Lisp_Object enabled_p
;
10895 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10896 int mouse_down_p
, rc
;
10898 /* Function note_mouse_highlight is called with negative x(y
10899 values when mouse moves outside of the frame. */
10900 if (x
<= 0 || y
<= 0)
10902 clear_mouse_face (dpyinfo
);
10906 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10909 /* Not on tool-bar item. */
10910 clear_mouse_face (dpyinfo
);
10914 /* On same tool-bar item as before. */
10915 goto set_help_echo
;
10917 clear_mouse_face (dpyinfo
);
10919 /* Mouse is down, but on different tool-bar item? */
10920 mouse_down_p
= (dpyinfo
->grabbed
10921 && f
== last_mouse_frame
10922 && FRAME_LIVE_P (f
));
10924 && last_tool_bar_item
!= prop_idx
)
10927 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10928 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10930 /* If tool-bar item is not enabled, don't highlight it. */
10931 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10932 if (!NILP (enabled_p
))
10934 /* Compute the x-position of the glyph. In front and past the
10935 image is a space. We include this in the highlighted area. */
10936 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10937 for (i
= x
= 0; i
< hpos
; ++i
)
10938 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10940 /* Record this as the current active region. */
10941 dpyinfo
->mouse_face_beg_col
= hpos
;
10942 dpyinfo
->mouse_face_beg_row
= vpos
;
10943 dpyinfo
->mouse_face_beg_x
= x
;
10944 dpyinfo
->mouse_face_beg_y
= row
->y
;
10945 dpyinfo
->mouse_face_past_end
= 0;
10947 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10948 dpyinfo
->mouse_face_end_row
= vpos
;
10949 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10950 dpyinfo
->mouse_face_end_y
= row
->y
;
10951 dpyinfo
->mouse_face_window
= window
;
10952 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10954 /* Display it as active. */
10955 show_mouse_face (dpyinfo
, draw
);
10956 dpyinfo
->mouse_face_image_state
= draw
;
10961 /* Set help_echo_string to a help string to display for this tool-bar item.
10962 XTread_socket does the rest. */
10963 help_echo_object
= help_echo_window
= Qnil
;
10964 help_echo_pos
= -1;
10965 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10966 if (NILP (help_echo_string
))
10967 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10970 #endif /* HAVE_WINDOW_SYSTEM */
10974 /************************************************************************
10975 Horizontal scrolling
10976 ************************************************************************/
10978 static int hscroll_window_tree
P_ ((Lisp_Object
));
10979 static int hscroll_windows
P_ ((Lisp_Object
));
10981 /* For all leaf windows in the window tree rooted at WINDOW, set their
10982 hscroll value so that PT is (i) visible in the window, and (ii) so
10983 that it is not within a certain margin at the window's left and
10984 right border. Value is non-zero if any window's hscroll has been
10988 hscroll_window_tree (window
)
10989 Lisp_Object window
;
10991 int hscrolled_p
= 0;
10992 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10993 int hscroll_step_abs
= 0;
10994 double hscroll_step_rel
= 0;
10996 if (hscroll_relative_p
)
10998 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10999 if (hscroll_step_rel
< 0)
11001 hscroll_relative_p
= 0;
11002 hscroll_step_abs
= 0;
11005 else if (INTEGERP (Vhscroll_step
))
11007 hscroll_step_abs
= XINT (Vhscroll_step
);
11008 if (hscroll_step_abs
< 0)
11009 hscroll_step_abs
= 0;
11012 hscroll_step_abs
= 0;
11014 while (WINDOWP (window
))
11016 struct window
*w
= XWINDOW (window
);
11018 if (WINDOWP (w
->hchild
))
11019 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
11020 else if (WINDOWP (w
->vchild
))
11021 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
11022 else if (w
->cursor
.vpos
>= 0)
11025 int text_area_width
;
11026 struct glyph_row
*current_cursor_row
11027 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
11028 struct glyph_row
*desired_cursor_row
11029 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
11030 struct glyph_row
*cursor_row
11031 = (desired_cursor_row
->enabled_p
11032 ? desired_cursor_row
11033 : current_cursor_row
);
11035 text_area_width
= window_box_width (w
, TEXT_AREA
);
11037 /* Scroll when cursor is inside this scroll margin. */
11038 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
11040 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
11041 && ((XFASTINT (w
->hscroll
)
11042 && w
->cursor
.x
<= h_margin
)
11043 || (cursor_row
->enabled_p
11044 && cursor_row
->truncated_on_right_p
11045 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
11049 struct buffer
*saved_current_buffer
;
11053 /* Find point in a display of infinite width. */
11054 saved_current_buffer
= current_buffer
;
11055 current_buffer
= XBUFFER (w
->buffer
);
11057 if (w
== XWINDOW (selected_window
))
11058 pt
= BUF_PT (current_buffer
);
11061 pt
= marker_position (w
->pointm
);
11062 pt
= max (BEGV
, pt
);
11066 /* Move iterator to pt starting at cursor_row->start in
11067 a line with infinite width. */
11068 init_to_row_start (&it
, w
, cursor_row
);
11069 it
.last_visible_x
= INFINITY
;
11070 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
11071 current_buffer
= saved_current_buffer
;
11073 /* Position cursor in window. */
11074 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
11075 hscroll
= max (0, (it
.current_x
11076 - (ITERATOR_AT_END_OF_LINE_P (&it
)
11077 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
11078 : (text_area_width
/ 2))))
11079 / FRAME_COLUMN_WIDTH (it
.f
);
11080 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
11082 if (hscroll_relative_p
)
11083 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
11086 wanted_x
= text_area_width
11087 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11090 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11094 if (hscroll_relative_p
)
11095 wanted_x
= text_area_width
* hscroll_step_rel
11098 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
11101 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
11103 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
11105 /* Don't call Fset_window_hscroll if value hasn't
11106 changed because it will prevent redisplay
11108 if (XFASTINT (w
->hscroll
) != hscroll
)
11110 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
11111 w
->hscroll
= make_number (hscroll
);
11120 /* Value is non-zero if hscroll of any leaf window has been changed. */
11121 return hscrolled_p
;
11125 /* Set hscroll so that cursor is visible and not inside horizontal
11126 scroll margins for all windows in the tree rooted at WINDOW. See
11127 also hscroll_window_tree above. Value is non-zero if any window's
11128 hscroll has been changed. If it has, desired matrices on the frame
11129 of WINDOW are cleared. */
11132 hscroll_windows (window
)
11133 Lisp_Object window
;
11135 int hscrolled_p
= hscroll_window_tree (window
);
11137 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
11138 return hscrolled_p
;
11143 /************************************************************************
11145 ************************************************************************/
11147 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
11148 to a non-zero value. This is sometimes handy to have in a debugger
11153 /* First and last unchanged row for try_window_id. */
11155 int debug_first_unchanged_at_end_vpos
;
11156 int debug_last_unchanged_at_beg_vpos
;
11158 /* Delta vpos and y. */
11160 int debug_dvpos
, debug_dy
;
11162 /* Delta in characters and bytes for try_window_id. */
11164 int debug_delta
, debug_delta_bytes
;
11166 /* Values of window_end_pos and window_end_vpos at the end of
11169 EMACS_INT debug_end_pos
, debug_end_vpos
;
11171 /* Append a string to W->desired_matrix->method. FMT is a printf
11172 format string. A1...A9 are a supplement for a variable-length
11173 argument list. If trace_redisplay_p is non-zero also printf the
11174 resulting string to stderr. */
11177 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
11180 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
11183 char *method
= w
->desired_matrix
->method
;
11184 int len
= strlen (method
);
11185 int size
= sizeof w
->desired_matrix
->method
;
11186 int remaining
= size
- len
- 1;
11188 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
11189 if (len
&& remaining
)
11192 --remaining
, ++len
;
11195 strncpy (method
+ len
, buffer
, remaining
);
11197 if (trace_redisplay_p
)
11198 fprintf (stderr
, "%p (%s): %s\n",
11200 ((BUFFERP (w
->buffer
)
11201 && STRINGP (XBUFFER (w
->buffer
)->name
))
11202 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
11207 #endif /* GLYPH_DEBUG */
11210 /* Value is non-zero if all changes in window W, which displays
11211 current_buffer, are in the text between START and END. START is a
11212 buffer position, END is given as a distance from Z. Used in
11213 redisplay_internal for display optimization. */
11216 text_outside_line_unchanged_p (w
, start
, end
)
11220 int unchanged_p
= 1;
11222 /* If text or overlays have changed, see where. */
11223 if (XFASTINT (w
->last_modified
) < MODIFF
11224 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11226 /* Gap in the line? */
11227 if (GPT
< start
|| Z
- GPT
< end
)
11230 /* Changes start in front of the line, or end after it? */
11232 && (BEG_UNCHANGED
< start
- 1
11233 || END_UNCHANGED
< end
))
11236 /* If selective display, can't optimize if changes start at the
11237 beginning of the line. */
11239 && INTEGERP (current_buffer
->selective_display
)
11240 && XINT (current_buffer
->selective_display
) > 0
11241 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
11244 /* If there are overlays at the start or end of the line, these
11245 may have overlay strings with newlines in them. A change at
11246 START, for instance, may actually concern the display of such
11247 overlay strings as well, and they are displayed on different
11248 lines. So, quickly rule out this case. (For the future, it
11249 might be desirable to implement something more telling than
11250 just BEG/END_UNCHANGED.) */
11253 if (BEG
+ BEG_UNCHANGED
== start
11254 && overlay_touches_p (start
))
11256 if (END_UNCHANGED
== end
11257 && overlay_touches_p (Z
- end
))
11261 /* Under bidi reordering, adding or deleting a character in the
11262 beginning of a paragraph, before the first strong directional
11263 character, can change the base direction of the paragraph (unless
11264 the buffer specifies a fixed paragraph direction), which will
11265 require to redisplay the whole paragraph. It might be worthwhile
11266 to find the paragraph limits and widen the range of redisplayed
11267 lines to that, but for now just give up this optimization. */
11268 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
11269 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
11273 return unchanged_p
;
11277 /* Do a frame update, taking possible shortcuts into account. This is
11278 the main external entry point for redisplay.
11280 If the last redisplay displayed an echo area message and that message
11281 is no longer requested, we clear the echo area or bring back the
11282 mini-buffer if that is in use. */
11287 redisplay_internal (0);
11292 overlay_arrow_string_or_property (var
)
11297 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11300 return Voverlay_arrow_string
;
11303 /* Return 1 if there are any overlay-arrows in current_buffer. */
11305 overlay_arrow_in_current_buffer_p ()
11309 for (vlist
= Voverlay_arrow_variable_list
;
11311 vlist
= XCDR (vlist
))
11313 Lisp_Object var
= XCAR (vlist
);
11316 if (!SYMBOLP (var
))
11318 val
= find_symbol_value (var
);
11320 && current_buffer
== XMARKER (val
)->buffer
)
11327 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11331 overlay_arrows_changed_p ()
11335 for (vlist
= Voverlay_arrow_variable_list
;
11337 vlist
= XCDR (vlist
))
11339 Lisp_Object var
= XCAR (vlist
);
11340 Lisp_Object val
, pstr
;
11342 if (!SYMBOLP (var
))
11344 val
= find_symbol_value (var
);
11345 if (!MARKERP (val
))
11347 if (! EQ (COERCE_MARKER (val
),
11348 Fget (var
, Qlast_arrow_position
))
11349 || ! (pstr
= overlay_arrow_string_or_property (var
),
11350 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11356 /* Mark overlay arrows to be updated on next redisplay. */
11359 update_overlay_arrows (up_to_date
)
11364 for (vlist
= Voverlay_arrow_variable_list
;
11366 vlist
= XCDR (vlist
))
11368 Lisp_Object var
= XCAR (vlist
);
11370 if (!SYMBOLP (var
))
11373 if (up_to_date
> 0)
11375 Lisp_Object val
= find_symbol_value (var
);
11376 Fput (var
, Qlast_arrow_position
,
11377 COERCE_MARKER (val
));
11378 Fput (var
, Qlast_arrow_string
,
11379 overlay_arrow_string_or_property (var
));
11381 else if (up_to_date
< 0
11382 || !NILP (Fget (var
, Qlast_arrow_position
)))
11384 Fput (var
, Qlast_arrow_position
, Qt
);
11385 Fput (var
, Qlast_arrow_string
, Qt
);
11391 /* Return overlay arrow string to display at row.
11392 Return integer (bitmap number) for arrow bitmap in left fringe.
11393 Return nil if no overlay arrow. */
11396 overlay_arrow_at_row (it
, row
)
11398 struct glyph_row
*row
;
11402 for (vlist
= Voverlay_arrow_variable_list
;
11404 vlist
= XCDR (vlist
))
11406 Lisp_Object var
= XCAR (vlist
);
11409 if (!SYMBOLP (var
))
11412 val
= find_symbol_value (var
);
11415 && current_buffer
== XMARKER (val
)->buffer
11416 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11418 if (FRAME_WINDOW_P (it
->f
)
11419 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11421 #ifdef HAVE_WINDOW_SYSTEM
11422 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11425 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11426 return make_number (fringe_bitmap
);
11429 return make_number (-1); /* Use default arrow bitmap */
11431 return overlay_arrow_string_or_property (var
);
11438 /* Return 1 if point moved out of or into a composition. Otherwise
11439 return 0. PREV_BUF and PREV_PT are the last point buffer and
11440 position. BUF and PT are the current point buffer and position. */
11443 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11444 struct buffer
*prev_buf
, *buf
;
11447 EMACS_INT start
, end
;
11449 Lisp_Object buffer
;
11451 XSETBUFFER (buffer
, buf
);
11452 /* Check a composition at the last point if point moved within the
11454 if (prev_buf
== buf
)
11457 /* Point didn't move. */
11460 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11461 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11462 && COMPOSITION_VALID_P (start
, end
, prop
)
11463 && start
< prev_pt
&& end
> prev_pt
)
11464 /* The last point was within the composition. Return 1 iff
11465 point moved out of the composition. */
11466 return (pt
<= start
|| pt
>= end
);
11469 /* Check a composition at the current point. */
11470 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11471 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11472 && COMPOSITION_VALID_P (start
, end
, prop
)
11473 && start
< pt
&& end
> pt
);
11477 /* Reconsider the setting of B->clip_changed which is displayed
11481 reconsider_clip_changes (w
, b
)
11485 if (b
->clip_changed
11486 && !NILP (w
->window_end_valid
)
11487 && w
->current_matrix
->buffer
== b
11488 && w
->current_matrix
->zv
== BUF_ZV (b
)
11489 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11490 b
->clip_changed
= 0;
11492 /* If display wasn't paused, and W is not a tool bar window, see if
11493 point has been moved into or out of a composition. In that case,
11494 we set b->clip_changed to 1 to force updating the screen. If
11495 b->clip_changed has already been set to 1, we can skip this
11497 if (!b
->clip_changed
11498 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11502 if (w
== XWINDOW (selected_window
))
11503 pt
= BUF_PT (current_buffer
);
11505 pt
= marker_position (w
->pointm
);
11507 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11508 || pt
!= XINT (w
->last_point
))
11509 && check_point_in_composition (w
->current_matrix
->buffer
,
11510 XINT (w
->last_point
),
11511 XBUFFER (w
->buffer
), pt
))
11512 b
->clip_changed
= 1;
11517 /* Select FRAME to forward the values of frame-local variables into C
11518 variables so that the redisplay routines can access those values
11522 select_frame_for_redisplay (frame
)
11525 Lisp_Object tail
, symbol
, val
;
11526 Lisp_Object old
= selected_frame
;
11527 struct Lisp_Symbol
*sym
;
11529 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11531 selected_frame
= frame
;
11535 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11536 if (CONSP (XCAR (tail
))
11537 && (symbol
= XCAR (XCAR (tail
)),
11539 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11541 (BUFFER_LOCAL_VALUEP (val
)))
11542 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11543 /* Use find_symbol_value rather than Fsymbol_value
11544 to avoid an error if it is void. */
11545 find_symbol_value (symbol
);
11546 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11550 #define STOP_POLLING \
11551 do { if (! polling_stopped_here) stop_polling (); \
11552 polling_stopped_here = 1; } while (0)
11554 #define RESUME_POLLING \
11555 do { if (polling_stopped_here) start_polling (); \
11556 polling_stopped_here = 0; } while (0)
11559 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11560 response to any user action; therefore, we should preserve the echo
11561 area. (Actually, our caller does that job.) Perhaps in the future
11562 avoid recentering windows if it is not necessary; currently that
11563 causes some problems. */
11566 redisplay_internal (preserve_echo_area
)
11567 int preserve_echo_area
;
11569 struct window
*w
= XWINDOW (selected_window
);
11572 int must_finish
= 0;
11573 struct text_pos tlbufpos
, tlendpos
;
11574 int number_of_visible_frames
;
11577 int polling_stopped_here
= 0;
11578 Lisp_Object old_frame
= selected_frame
;
11580 /* Non-zero means redisplay has to consider all windows on all
11581 frames. Zero means, only selected_window is considered. */
11582 int consider_all_windows_p
;
11584 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11586 /* No redisplay if running in batch mode or frame is not yet fully
11587 initialized, or redisplay is explicitly turned off by setting
11588 Vinhibit_redisplay. */
11589 if (FRAME_INITIAL_P (SELECTED_FRAME ())
11590 || !NILP (Vinhibit_redisplay
))
11593 /* Don't examine these until after testing Vinhibit_redisplay.
11594 When Emacs is shutting down, perhaps because its connection to
11595 X has dropped, we should not look at them at all. */
11596 f
= XFRAME (w
->frame
);
11597 sf
= SELECTED_FRAME ();
11599 if (!f
->glyphs_initialized_p
)
11602 /* The flag redisplay_performed_directly_p is set by
11603 direct_output_for_insert when it already did the whole screen
11604 update necessary. */
11605 if (redisplay_performed_directly_p
)
11607 redisplay_performed_directly_p
= 0;
11608 if (!hscroll_windows (selected_window
))
11612 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
11613 if (popup_activated ())
11617 /* I don't think this happens but let's be paranoid. */
11618 if (redisplaying_p
)
11621 /* Record a function that resets redisplaying_p to its old value
11622 when we leave this function. */
11623 count
= SPECPDL_INDEX ();
11624 record_unwind_protect (unwind_redisplay
,
11625 Fcons (make_number (redisplaying_p
), selected_frame
));
11627 specbind (Qinhibit_free_realized_faces
, Qnil
);
11630 Lisp_Object tail
, frame
;
11632 FOR_EACH_FRAME (tail
, frame
)
11634 struct frame
*f
= XFRAME (frame
);
11635 f
->already_hscrolled_p
= 0;
11640 if (!EQ (old_frame
, selected_frame
)
11641 && FRAME_LIVE_P (XFRAME (old_frame
)))
11642 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11643 selected_frame and selected_window to be temporarily out-of-sync so
11644 when we come back here via `goto retry', we need to resync because we
11645 may need to run Elisp code (via prepare_menu_bars). */
11646 select_frame_for_redisplay (old_frame
);
11649 reconsider_clip_changes (w
, current_buffer
);
11650 last_escape_glyph_frame
= NULL
;
11651 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11653 /* If new fonts have been loaded that make a glyph matrix adjustment
11654 necessary, do it. */
11655 if (fonts_changed_p
)
11657 adjust_glyphs (NULL
);
11658 ++windows_or_buffers_changed
;
11659 fonts_changed_p
= 0;
11662 /* If face_change_count is non-zero, init_iterator will free all
11663 realized faces, which includes the faces referenced from current
11664 matrices. So, we can't reuse current matrices in this case. */
11665 if (face_change_count
)
11666 ++windows_or_buffers_changed
;
11668 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
11669 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11671 /* Since frames on a single ASCII terminal share the same
11672 display area, displaying a different frame means redisplay
11673 the whole thing. */
11674 windows_or_buffers_changed
++;
11675 SET_FRAME_GARBAGED (sf
);
11677 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11679 FRAME_TTY (sf
)->previous_frame
= sf
;
11682 /* Set the visible flags for all frames. Do this before checking
11683 for resized or garbaged frames; they want to know if their frames
11684 are visible. See the comment in frame.h for
11685 FRAME_SAMPLE_VISIBILITY. */
11687 Lisp_Object tail
, frame
;
11689 number_of_visible_frames
= 0;
11691 FOR_EACH_FRAME (tail
, frame
)
11693 struct frame
*f
= XFRAME (frame
);
11695 FRAME_SAMPLE_VISIBILITY (f
);
11696 if (FRAME_VISIBLE_P (f
))
11697 ++number_of_visible_frames
;
11698 clear_desired_matrices (f
);
11702 /* Notice any pending interrupt request to change frame size. */
11703 do_pending_window_change (1);
11705 /* Clear frames marked as garbaged. */
11706 if (frame_garbaged
)
11707 clear_garbaged_frames ();
11709 /* Build menubar and tool-bar items. */
11710 if (NILP (Vmemory_full
))
11711 prepare_menu_bars ();
11713 if (windows_or_buffers_changed
)
11714 update_mode_lines
++;
11716 /* Detect case that we need to write or remove a star in the mode line. */
11717 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11719 w
->update_mode_line
= Qt
;
11720 if (buffer_shared
> 1)
11721 update_mode_lines
++;
11724 /* Avoid invocation of point motion hooks by `current_column' below. */
11725 count1
= SPECPDL_INDEX ();
11726 specbind (Qinhibit_point_motion_hooks
, Qt
);
11728 /* If %c is in the mode line, update it if needed. */
11729 if (!NILP (w
->column_number_displayed
)
11730 /* This alternative quickly identifies a common case
11731 where no change is needed. */
11732 && !(PT
== XFASTINT (w
->last_point
)
11733 && XFASTINT (w
->last_modified
) >= MODIFF
11734 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11735 && (XFASTINT (w
->column_number_displayed
)
11736 != (int) current_column ())) /* iftc */
11737 w
->update_mode_line
= Qt
;
11739 unbind_to (count1
, Qnil
);
11741 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11743 /* The variable buffer_shared is set in redisplay_window and
11744 indicates that we redisplay a buffer in different windows. See
11746 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11747 || cursor_type_changed
);
11749 /* If specs for an arrow have changed, do thorough redisplay
11750 to ensure we remove any arrow that should no longer exist. */
11751 if (overlay_arrows_changed_p ())
11752 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11754 /* Normally the message* functions will have already displayed and
11755 updated the echo area, but the frame may have been trashed, or
11756 the update may have been preempted, so display the echo area
11757 again here. Checking message_cleared_p captures the case that
11758 the echo area should be cleared. */
11759 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11760 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11761 || (message_cleared_p
11762 && minibuf_level
== 0
11763 /* If the mini-window is currently selected, this means the
11764 echo-area doesn't show through. */
11765 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11767 int window_height_changed_p
= echo_area_display (0);
11770 /* If we don't display the current message, don't clear the
11771 message_cleared_p flag, because, if we did, we wouldn't clear
11772 the echo area in the next redisplay which doesn't preserve
11774 if (!display_last_displayed_message_p
)
11775 message_cleared_p
= 0;
11777 if (fonts_changed_p
)
11779 else if (window_height_changed_p
)
11781 consider_all_windows_p
= 1;
11782 ++update_mode_lines
;
11783 ++windows_or_buffers_changed
;
11785 /* If window configuration was changed, frames may have been
11786 marked garbaged. Clear them or we will experience
11787 surprises wrt scrolling. */
11788 if (frame_garbaged
)
11789 clear_garbaged_frames ();
11792 else if (EQ (selected_window
, minibuf_window
)
11793 && (current_buffer
->clip_changed
11794 || XFASTINT (w
->last_modified
) < MODIFF
11795 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11796 && resize_mini_window (w
, 0))
11798 /* Resized active mini-window to fit the size of what it is
11799 showing if its contents might have changed. */
11801 /* FIXME: this causes all frames to be updated, which seems unnecessary
11802 since only the current frame needs to be considered. This function needs
11803 to be rewritten with two variables, consider_all_windows and
11804 consider_all_frames. */
11805 consider_all_windows_p
= 1;
11806 ++windows_or_buffers_changed
;
11807 ++update_mode_lines
;
11809 /* If window configuration was changed, frames may have been
11810 marked garbaged. Clear them or we will experience
11811 surprises wrt scrolling. */
11812 if (frame_garbaged
)
11813 clear_garbaged_frames ();
11817 /* If showing the region, and mark has changed, we must redisplay
11818 the whole window. The assignment to this_line_start_pos prevents
11819 the optimization directly below this if-statement. */
11820 if (((!NILP (Vtransient_mark_mode
)
11821 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11822 != !NILP (w
->region_showing
))
11823 || (!NILP (w
->region_showing
)
11824 && !EQ (w
->region_showing
,
11825 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11826 CHARPOS (this_line_start_pos
) = 0;
11828 /* Optimize the case that only the line containing the cursor in the
11829 selected window has changed. Variables starting with this_ are
11830 set in display_line and record information about the line
11831 containing the cursor. */
11832 tlbufpos
= this_line_start_pos
;
11833 tlendpos
= this_line_end_pos
;
11834 if (!consider_all_windows_p
11835 && CHARPOS (tlbufpos
) > 0
11836 && NILP (w
->update_mode_line
)
11837 && !current_buffer
->clip_changed
11838 && !current_buffer
->prevent_redisplay_optimizations_p
11839 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11840 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11841 /* Make sure recorded data applies to current buffer, etc. */
11842 && this_line_buffer
== current_buffer
11843 && current_buffer
== XBUFFER (w
->buffer
)
11844 && NILP (w
->force_start
)
11845 && NILP (w
->optional_new_start
)
11846 /* Point must be on the line that we have info recorded about. */
11847 && PT
>= CHARPOS (tlbufpos
)
11848 && PT
<= Z
- CHARPOS (tlendpos
)
11849 /* All text outside that line, including its final newline,
11850 must be unchanged. */
11851 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11852 CHARPOS (tlendpos
)))
11854 if (CHARPOS (tlbufpos
) > BEGV
11855 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11856 && (CHARPOS (tlbufpos
) == ZV
11857 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11858 /* Former continuation line has disappeared by becoming empty. */
11860 else if (XFASTINT (w
->last_modified
) < MODIFF
11861 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11862 || MINI_WINDOW_P (w
))
11864 /* We have to handle the case of continuation around a
11865 wide-column character (see the comment in indent.c around
11868 For instance, in the following case:
11870 -------- Insert --------
11871 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11872 J_I_ ==> J_I_ `^^' are cursors.
11876 As we have to redraw the line above, we cannot use this
11880 int line_height_before
= this_line_pixel_height
;
11882 /* Note that start_display will handle the case that the
11883 line starting at tlbufpos is a continuation line. */
11884 start_display (&it
, w
, tlbufpos
);
11886 /* Implementation note: It this still necessary? */
11887 if (it
.current_x
!= this_line_start_x
)
11890 TRACE ((stderr
, "trying display optimization 1\n"));
11891 w
->cursor
.vpos
= -1;
11892 overlay_arrow_seen
= 0;
11893 it
.vpos
= this_line_vpos
;
11894 it
.current_y
= this_line_y
;
11895 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11896 display_line (&it
);
11898 /* If line contains point, is not continued,
11899 and ends at same distance from eob as before, we win. */
11900 if (w
->cursor
.vpos
>= 0
11901 /* Line is not continued, otherwise this_line_start_pos
11902 would have been set to 0 in display_line. */
11903 && CHARPOS (this_line_start_pos
)
11904 /* Line ends as before. */
11905 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11906 /* Line has same height as before. Otherwise other lines
11907 would have to be shifted up or down. */
11908 && this_line_pixel_height
== line_height_before
)
11910 /* If this is not the window's last line, we must adjust
11911 the charstarts of the lines below. */
11912 if (it
.current_y
< it
.last_visible_y
)
11914 struct glyph_row
*row
11915 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11916 int delta
, delta_bytes
;
11918 /* We used to distinguish between two cases here,
11919 conditioned by Z - CHARPOS (tlendpos) == ZV, for
11920 when the line ends in a newline or the end of the
11921 buffer's accessible portion. But both cases did
11922 the same, so they were collapsed. */
11924 - CHARPOS (tlendpos
)
11925 - MATRIX_ROW_START_CHARPOS (row
));
11926 delta_bytes
= (Z_BYTE
11927 - BYTEPOS (tlendpos
)
11928 - MATRIX_ROW_START_BYTEPOS (row
));
11930 increment_matrix_positions (w
->current_matrix
,
11931 this_line_vpos
+ 1,
11932 w
->current_matrix
->nrows
,
11933 delta
, delta_bytes
);
11936 /* If this row displays text now but previously didn't,
11937 or vice versa, w->window_end_vpos may have to be
11939 if ((it
.glyph_row
- 1)->displays_text_p
)
11941 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11942 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11944 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11945 && this_line_vpos
> 0)
11946 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11947 w
->window_end_valid
= Qnil
;
11949 /* Update hint: No need to try to scroll in update_window. */
11950 w
->desired_matrix
->no_scrolling_p
= 1;
11953 *w
->desired_matrix
->method
= 0;
11954 debug_method_add (w
, "optimization 1");
11956 #ifdef HAVE_WINDOW_SYSTEM
11957 update_window_fringes (w
, 0);
11964 else if (/* Cursor position hasn't changed. */
11965 PT
== XFASTINT (w
->last_point
)
11966 /* Make sure the cursor was last displayed
11967 in this window. Otherwise we have to reposition it. */
11968 && 0 <= w
->cursor
.vpos
11969 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11973 do_pending_window_change (1);
11975 /* We used to always goto end_of_redisplay here, but this
11976 isn't enough if we have a blinking cursor. */
11977 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11978 goto end_of_redisplay
;
11982 /* If highlighting the region, or if the cursor is in the echo area,
11983 then we can't just move the cursor. */
11984 else if (! (!NILP (Vtransient_mark_mode
)
11985 && !NILP (current_buffer
->mark_active
))
11986 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11987 || highlight_nonselected_windows
)
11988 && NILP (w
->region_showing
)
11989 && NILP (Vshow_trailing_whitespace
)
11990 && !cursor_in_echo_area
)
11993 struct glyph_row
*row
;
11995 /* Skip from tlbufpos to PT and see where it is. Note that
11996 PT may be in invisible text. If so, we will end at the
11997 next visible position. */
11998 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11999 NULL
, DEFAULT_FACE_ID
);
12000 it
.current_x
= this_line_start_x
;
12001 it
.current_y
= this_line_y
;
12002 it
.vpos
= this_line_vpos
;
12004 /* The call to move_it_to stops in front of PT, but
12005 moves over before-strings. */
12006 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
12008 if (it
.vpos
== this_line_vpos
12009 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
12012 xassert (this_line_vpos
== it
.vpos
);
12013 xassert (this_line_y
== it
.current_y
);
12014 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
12016 *w
->desired_matrix
->method
= 0;
12017 debug_method_add (w
, "optimization 3");
12026 /* Text changed drastically or point moved off of line. */
12027 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
12030 CHARPOS (this_line_start_pos
) = 0;
12031 consider_all_windows_p
|= buffer_shared
> 1;
12032 ++clear_face_cache_count
;
12033 #ifdef HAVE_WINDOW_SYSTEM
12034 ++clear_image_cache_count
;
12037 /* Build desired matrices, and update the display. If
12038 consider_all_windows_p is non-zero, do it for all windows on all
12039 frames. Otherwise do it for selected_window, only. */
12041 if (consider_all_windows_p
)
12043 Lisp_Object tail
, frame
;
12045 FOR_EACH_FRAME (tail
, frame
)
12046 XFRAME (frame
)->updated_p
= 0;
12048 /* Recompute # windows showing selected buffer. This will be
12049 incremented each time such a window is displayed. */
12052 FOR_EACH_FRAME (tail
, frame
)
12054 struct frame
*f
= XFRAME (frame
);
12056 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
12058 if (! EQ (frame
, selected_frame
))
12059 /* Select the frame, for the sake of frame-local
12061 select_frame_for_redisplay (frame
);
12063 /* Mark all the scroll bars to be removed; we'll redeem
12064 the ones we want when we redisplay their windows. */
12065 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
12066 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
12068 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12069 redisplay_windows (FRAME_ROOT_WINDOW (f
));
12071 /* The X error handler may have deleted that frame. */
12072 if (!FRAME_LIVE_P (f
))
12075 /* Any scroll bars which redisplay_windows should have
12076 nuked should now go away. */
12077 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
12078 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
12080 /* If fonts changed, display again. */
12081 /* ??? rms: I suspect it is a mistake to jump all the way
12082 back to retry here. It should just retry this frame. */
12083 if (fonts_changed_p
)
12086 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
12088 /* See if we have to hscroll. */
12089 if (!f
->already_hscrolled_p
)
12091 f
->already_hscrolled_p
= 1;
12092 if (hscroll_windows (f
->root_window
))
12096 /* Prevent various kinds of signals during display
12097 update. stdio is not robust about handling
12098 signals, which can cause an apparent I/O
12100 if (interrupt_input
)
12101 unrequest_sigio ();
12104 /* Update the display. */
12105 set_window_update_flags (XWINDOW (f
->root_window
), 1);
12106 pause
|= update_frame (f
, 0, 0);
12112 if (!EQ (old_frame
, selected_frame
)
12113 && FRAME_LIVE_P (XFRAME (old_frame
)))
12114 /* We played a bit fast-and-loose above and allowed selected_frame
12115 and selected_window to be temporarily out-of-sync but let's make
12116 sure this stays contained. */
12117 select_frame_for_redisplay (old_frame
);
12118 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
12122 /* Do the mark_window_display_accurate after all windows have
12123 been redisplayed because this call resets flags in buffers
12124 which are needed for proper redisplay. */
12125 FOR_EACH_FRAME (tail
, frame
)
12127 struct frame
*f
= XFRAME (frame
);
12130 mark_window_display_accurate (f
->root_window
, 1);
12131 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
12132 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
12137 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12139 Lisp_Object mini_window
;
12140 struct frame
*mini_frame
;
12142 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
12143 /* Use list_of_error, not Qerror, so that
12144 we catch only errors and don't run the debugger. */
12145 internal_condition_case_1 (redisplay_window_1
, selected_window
,
12147 redisplay_window_error
);
12149 /* Compare desired and current matrices, perform output. */
12152 /* If fonts changed, display again. */
12153 if (fonts_changed_p
)
12156 /* Prevent various kinds of signals during display update.
12157 stdio is not robust about handling signals,
12158 which can cause an apparent I/O error. */
12159 if (interrupt_input
)
12160 unrequest_sigio ();
12163 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
12165 if (hscroll_windows (selected_window
))
12168 XWINDOW (selected_window
)->must_be_updated_p
= 1;
12169 pause
= update_frame (sf
, 0, 0);
12172 /* We may have called echo_area_display at the top of this
12173 function. If the echo area is on another frame, that may
12174 have put text on a frame other than the selected one, so the
12175 above call to update_frame would not have caught it. Catch
12177 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
12178 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
12180 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
12182 XWINDOW (mini_window
)->must_be_updated_p
= 1;
12183 pause
|= update_frame (mini_frame
, 0, 0);
12184 if (!pause
&& hscroll_windows (mini_window
))
12189 /* If display was paused because of pending input, make sure we do a
12190 thorough update the next time. */
12193 /* Prevent the optimization at the beginning of
12194 redisplay_internal that tries a single-line update of the
12195 line containing the cursor in the selected window. */
12196 CHARPOS (this_line_start_pos
) = 0;
12198 /* Let the overlay arrow be updated the next time. */
12199 update_overlay_arrows (0);
12201 /* If we pause after scrolling, some rows in the current
12202 matrices of some windows are not valid. */
12203 if (!WINDOW_FULL_WIDTH_P (w
)
12204 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
12205 update_mode_lines
= 1;
12209 if (!consider_all_windows_p
)
12211 /* This has already been done above if
12212 consider_all_windows_p is set. */
12213 mark_window_display_accurate_1 (w
, 1);
12215 /* Say overlay arrows are up to date. */
12216 update_overlay_arrows (1);
12218 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
12219 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
12222 update_mode_lines
= 0;
12223 windows_or_buffers_changed
= 0;
12224 cursor_type_changed
= 0;
12227 /* Start SIGIO interrupts coming again. Having them off during the
12228 code above makes it less likely one will discard output, but not
12229 impossible, since there might be stuff in the system buffer here.
12230 But it is much hairier to try to do anything about that. */
12231 if (interrupt_input
)
12235 /* If a frame has become visible which was not before, redisplay
12236 again, so that we display it. Expose events for such a frame
12237 (which it gets when becoming visible) don't call the parts of
12238 redisplay constructing glyphs, so simply exposing a frame won't
12239 display anything in this case. So, we have to display these
12240 frames here explicitly. */
12243 Lisp_Object tail
, frame
;
12246 FOR_EACH_FRAME (tail
, frame
)
12248 int this_is_visible
= 0;
12250 if (XFRAME (frame
)->visible
)
12251 this_is_visible
= 1;
12252 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12253 if (XFRAME (frame
)->visible
)
12254 this_is_visible
= 1;
12256 if (this_is_visible
)
12260 if (new_count
!= number_of_visible_frames
)
12261 windows_or_buffers_changed
++;
12264 /* Change frame size now if a change is pending. */
12265 do_pending_window_change (1);
12267 /* If we just did a pending size change, or have additional
12268 visible frames, redisplay again. */
12269 if (windows_or_buffers_changed
&& !pause
)
12272 /* Clear the face cache eventually. */
12273 if (consider_all_windows_p
)
12275 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12277 clear_face_cache (0);
12278 clear_face_cache_count
= 0;
12280 #ifdef HAVE_WINDOW_SYSTEM
12281 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12283 clear_image_caches (Qnil
);
12284 clear_image_cache_count
= 0;
12286 #endif /* HAVE_WINDOW_SYSTEM */
12290 unbind_to (count
, Qnil
);
12295 /* Redisplay, but leave alone any recent echo area message unless
12296 another message has been requested in its place.
12298 This is useful in situations where you need to redisplay but no
12299 user action has occurred, making it inappropriate for the message
12300 area to be cleared. See tracking_off and
12301 wait_reading_process_output for examples of these situations.
12303 FROM_WHERE is an integer saying from where this function was
12304 called. This is useful for debugging. */
12307 redisplay_preserve_echo_area (from_where
)
12310 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12312 if (!NILP (echo_area_buffer
[1]))
12314 /* We have a previously displayed message, but no current
12315 message. Redisplay the previous message. */
12316 display_last_displayed_message_p
= 1;
12317 redisplay_internal (1);
12318 display_last_displayed_message_p
= 0;
12321 redisplay_internal (1);
12323 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12324 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12325 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12329 /* Function registered with record_unwind_protect in
12330 redisplay_internal. Reset redisplaying_p to the value it had
12331 before redisplay_internal was called, and clear
12332 prevent_freeing_realized_faces_p. It also selects the previously
12333 selected frame, unless it has been deleted (by an X connection
12334 failure during redisplay, for example). */
12337 unwind_redisplay (val
)
12340 Lisp_Object old_redisplaying_p
, old_frame
;
12342 old_redisplaying_p
= XCAR (val
);
12343 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12344 old_frame
= XCDR (val
);
12345 if (! EQ (old_frame
, selected_frame
)
12346 && FRAME_LIVE_P (XFRAME (old_frame
)))
12347 select_frame_for_redisplay (old_frame
);
12352 /* Mark the display of window W as accurate or inaccurate. If
12353 ACCURATE_P is non-zero mark display of W as accurate. If
12354 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12355 redisplay_internal is called. */
12358 mark_window_display_accurate_1 (w
, accurate_p
)
12362 if (BUFFERP (w
->buffer
))
12364 struct buffer
*b
= XBUFFER (w
->buffer
);
12367 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12368 w
->last_overlay_modified
12369 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12371 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12375 b
->clip_changed
= 0;
12376 b
->prevent_redisplay_optimizations_p
= 0;
12378 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12379 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12380 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12381 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12383 w
->current_matrix
->buffer
= b
;
12384 w
->current_matrix
->begv
= BUF_BEGV (b
);
12385 w
->current_matrix
->zv
= BUF_ZV (b
);
12387 w
->last_cursor
= w
->cursor
;
12388 w
->last_cursor_off_p
= w
->cursor_off_p
;
12390 if (w
== XWINDOW (selected_window
))
12391 w
->last_point
= make_number (BUF_PT (b
));
12393 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12399 w
->window_end_valid
= w
->buffer
;
12400 w
->update_mode_line
= Qnil
;
12405 /* Mark the display of windows in the window tree rooted at WINDOW as
12406 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12407 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12408 be redisplayed the next time redisplay_internal is called. */
12411 mark_window_display_accurate (window
, accurate_p
)
12412 Lisp_Object window
;
12417 for (; !NILP (window
); window
= w
->next
)
12419 w
= XWINDOW (window
);
12420 mark_window_display_accurate_1 (w
, accurate_p
);
12422 if (!NILP (w
->vchild
))
12423 mark_window_display_accurate (w
->vchild
, accurate_p
);
12424 if (!NILP (w
->hchild
))
12425 mark_window_display_accurate (w
->hchild
, accurate_p
);
12430 update_overlay_arrows (1);
12434 /* Force a thorough redisplay the next time by setting
12435 last_arrow_position and last_arrow_string to t, which is
12436 unequal to any useful value of Voverlay_arrow_... */
12437 update_overlay_arrows (-1);
12442 /* Return value in display table DP (Lisp_Char_Table *) for character
12443 C. Since a display table doesn't have any parent, we don't have to
12444 follow parent. Do not call this function directly but use the
12445 macro DISP_CHAR_VECTOR. */
12448 disp_char_vector (dp
, c
)
12449 struct Lisp_Char_Table
*dp
;
12454 if (ASCII_CHAR_P (c
))
12457 if (SUB_CHAR_TABLE_P (val
))
12458 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12464 XSETCHAR_TABLE (table
, dp
);
12465 val
= char_table_ref (table
, c
);
12474 /***********************************************************************
12476 ***********************************************************************/
12478 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12481 redisplay_windows (window
)
12482 Lisp_Object window
;
12484 while (!NILP (window
))
12486 struct window
*w
= XWINDOW (window
);
12488 if (!NILP (w
->hchild
))
12489 redisplay_windows (w
->hchild
);
12490 else if (!NILP (w
->vchild
))
12491 redisplay_windows (w
->vchild
);
12492 else if (!NILP (w
->buffer
))
12494 displayed_buffer
= XBUFFER (w
->buffer
);
12495 /* Use list_of_error, not Qerror, so that
12496 we catch only errors and don't run the debugger. */
12497 internal_condition_case_1 (redisplay_window_0
, window
,
12499 redisplay_window_error
);
12507 redisplay_window_error ()
12509 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12514 redisplay_window_0 (window
)
12515 Lisp_Object window
;
12517 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12518 redisplay_window (window
, 0);
12523 redisplay_window_1 (window
)
12524 Lisp_Object window
;
12526 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12527 redisplay_window (window
, 1);
12532 /* Increment GLYPH until it reaches END or CONDITION fails while
12533 adding (GLYPH)->pixel_width to X. */
12535 #define SKIP_GLYPHS(glyph, end, x, condition) \
12538 (x) += (glyph)->pixel_width; \
12541 while ((glyph) < (end) && (condition))
12544 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12545 DELTA and DELTA_BYTES are the numbers of characters and bytes by
12546 which positions recorded in ROW differ from current buffer
12549 Return 0 if cursor is not on this row, 1 otherwise. */
12552 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12554 struct glyph_row
*row
;
12555 struct glyph_matrix
*matrix
;
12556 int delta
, delta_bytes
, dy
, dvpos
;
12558 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12559 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12560 struct glyph
*cursor
= NULL
;
12561 /* The last known character position in row. */
12562 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12565 EMACS_INT pt_old
= PT
- delta
;
12566 EMACS_INT pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12567 EMACS_INT pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12568 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
12569 /* Non-zero means we've found a match for cursor position, but that
12570 glyph has the avoid_cursor_p flag set. */
12571 int match_with_avoid_cursor
= 0;
12572 /* Non-zero means we've seen at least one glyph that came from a
12574 int string_seen
= 0;
12575 /* Largest buffer position seen so far during scan of glyph row. */
12576 EMACS_INT bpos_max
= last_pos
;
12577 /* Last buffer position covered by an overlay string with an integer
12578 `cursor' property. */
12579 EMACS_INT bpos_covered
= 0;
12581 /* Skip over glyphs not having an object at the start and the end of
12582 the row. These are special glyphs like truncation marks on
12583 terminal frames. */
12584 if (row
->displays_text_p
)
12586 if (!row
->reversed_p
)
12589 && INTEGERP (glyph
->object
)
12590 && glyph
->charpos
< 0)
12592 x
+= glyph
->pixel_width
;
12596 && INTEGERP ((end
- 1)->object
)
12597 /* CHARPOS is zero for blanks inserted by
12598 extend_face_to_end_of_line. */
12599 && (end
- 1)->charpos
<= 0)
12601 glyph_before
= glyph
- 1;
12608 /* If the glyph row is reversed, we need to process it from back
12609 to front, so swap the edge pointers. */
12611 glyph
+= row
->used
[TEXT_AREA
] - 1;
12612 /* Reverse the known positions in the row. */
12613 last_pos
= pos_after
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12614 pos_before
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
12616 while (glyph
> end
+ 1
12617 && INTEGERP (glyph
->object
)
12618 && glyph
->charpos
< 0)
12621 x
-= glyph
->pixel_width
;
12623 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
12625 /* By default, put the cursor on the rightmost glyph. */
12626 for (g
= end
+ 1; g
< glyph
; g
++)
12627 x
+= g
->pixel_width
;
12630 && INTEGERP ((end
+ 1)->object
)
12631 && (end
+ 1)->charpos
<= 0)
12633 glyph_before
= glyph
+ 1;
12637 else if (row
->reversed_p
)
12639 /* In R2L rows that don't display text, put the cursor on the
12640 rightmost glyph. Case in point: an empty last line that is
12641 part of an R2L paragraph. */
12643 x
= -1; /* will be computed below, at lable compute_x */
12646 /* Step 1: Try to find the glyph whose character position
12647 corresponds to point. If that's not possible, find 2 glyphs
12648 whose character positions are the closest to point, one before
12649 point, the other after it. */
12650 if (!row
->reversed_p
)
12651 while (/* not marched to end of glyph row */
12653 /* glyph was not inserted by redisplay for internal purposes */
12654 && !INTEGERP (glyph
->object
))
12656 if (BUFFERP (glyph
->object
))
12658 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12660 if (glyph
->charpos
> bpos_max
)
12661 bpos_max
= glyph
->charpos
;
12662 if (!glyph
->avoid_cursor_p
)
12664 /* If we hit point, we've found the glyph on which to
12665 display the cursor. */
12668 match_with_avoid_cursor
= 0;
12671 /* See if we've found a better approximation to
12672 POS_BEFORE or to POS_AFTER. Note that we want the
12673 first (leftmost) glyph of all those that are the
12674 closest from below, and the last (rightmost) of all
12675 those from above. */
12676 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12678 pos_before
= glyph
->charpos
;
12679 glyph_before
= glyph
;
12681 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12683 pos_after
= glyph
->charpos
;
12684 glyph_after
= glyph
;
12687 else if (dpos
== 0)
12688 match_with_avoid_cursor
= 1;
12690 else if (STRINGP (glyph
->object
))
12692 Lisp_Object chprop
;
12693 int glyph_pos
= glyph
->charpos
;
12695 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12697 if (INTEGERP (chprop
))
12699 bpos_covered
= bpos_max
+ XINT (chprop
);
12700 /* If the `cursor' property covers buffer positions up
12701 to and including point, we should display cursor on
12703 /* Implementation note: bpos_max == pt_old when, e.g.,
12704 we are in an empty line, where bpos_max is set to
12705 MATRIX_ROW_START_CHARPOS, see above. */
12706 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12715 x
+= glyph
->pixel_width
;
12718 else if (glyph
> end
) /* row is reversed */
12719 while (!INTEGERP (glyph
->object
))
12721 if (BUFFERP (glyph
->object
))
12723 EMACS_INT dpos
= glyph
->charpos
- pt_old
;
12725 if (glyph
->charpos
> bpos_max
)
12726 bpos_max
= glyph
->charpos
;
12727 if (!glyph
->avoid_cursor_p
)
12731 match_with_avoid_cursor
= 0;
12734 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
12736 pos_before
= glyph
->charpos
;
12737 glyph_before
= glyph
;
12739 else if (0 < dpos
&& dpos
<= pos_after
- pt_old
)
12741 pos_after
= glyph
->charpos
;
12742 glyph_after
= glyph
;
12745 else if (dpos
== 0)
12746 match_with_avoid_cursor
= 1;
12748 else if (STRINGP (glyph
->object
))
12750 Lisp_Object chprop
;
12751 int glyph_pos
= glyph
->charpos
;
12753 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
12755 if (INTEGERP (chprop
))
12757 bpos_covered
= bpos_max
+ XINT (chprop
);
12758 /* If the `cursor' property covers buffer positions up
12759 to and including point, we should display cursor on
12761 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
12772 x
-= glyph
->pixel_width
;
12775 /* Step 2: If we didn't find an exact match for point, we need to
12776 look for a proper place to put the cursor among glyphs between
12777 GLYPH_BEFORE and GLYPH_AFTER. */
12778 if (!(BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
12779 && bpos_covered
< pt_old
)
12781 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
12783 EMACS_INT ellipsis_pos
;
12785 /* Scan back over the ellipsis glyphs. */
12786 if (!row
->reversed_p
)
12788 ellipsis_pos
= (glyph
- 1)->charpos
;
12789 while (glyph
> row
->glyphs
[TEXT_AREA
]
12790 && (glyph
- 1)->charpos
== ellipsis_pos
)
12791 glyph
--, x
-= glyph
->pixel_width
;
12792 /* That loop always goes one position too far, including
12793 the glyph before the ellipsis. So scan forward over
12795 x
+= glyph
->pixel_width
;
12798 else /* row is reversed */
12800 ellipsis_pos
= (glyph
+ 1)->charpos
;
12801 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
12802 && (glyph
+ 1)->charpos
== ellipsis_pos
)
12803 glyph
++, x
+= glyph
->pixel_width
;
12804 x
-= glyph
->pixel_width
;
12808 else if (match_with_avoid_cursor
12809 /* zero-width characters produce no glyphs */
12810 || eabs (glyph_after
- glyph_before
) == 1)
12812 cursor
= glyph_after
;
12815 else if (string_seen
)
12817 int incr
= row
->reversed_p
? -1 : +1;
12819 /* Need to find the glyph that came out of a string which is
12820 present at point. That glyph is somewhere between
12821 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
12822 positioned between POS_BEFORE and POS_AFTER in the
12824 struct glyph
*stop
= glyph_after
;
12825 EMACS_INT pos
= pos_before
;
12828 for (glyph
= glyph_before
+ incr
;
12829 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
12832 /* Any glyphs that come from the buffer are here because
12833 of bidi reordering. Skip them, and only pay
12834 attention to glyphs that came from some string. */
12835 if (STRINGP (glyph
->object
))
12840 str
= glyph
->object
;
12841 tem
= string_buffer_position_lim (w
, str
, pos
, pos_after
, 0);
12844 /* If the string from which this glyph came is
12845 found in the buffer at point, then we've
12846 found the glyph we've been looking for. */
12849 /* The glyphs from this string could have
12850 been reordered. Find the one with the
12851 smallest string position. Or there could
12852 be a character in the string with the
12853 `cursor' property, which means display
12854 cursor on that character's glyph. */
12855 int strpos
= glyph
->charpos
;
12858 for (glyph
+= incr
;
12859 EQ (glyph
->object
, str
);
12863 int gpos
= glyph
->charpos
;
12865 cprop
= Fget_char_property (make_number (gpos
),
12873 if (glyph
->charpos
< strpos
)
12875 strpos
= glyph
->charpos
;
12882 pos
= tem
+ 1; /* don't find previous instances */
12884 /* This string is not what we want; skip all of the
12885 glyphs that came from it. */
12888 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
12889 && EQ (glyph
->object
, str
));
12895 /* If we reached the end of the line, and END was from a string,
12896 the cursor is not on this line. */
12898 && STRINGP ((glyph
- incr
)->object
)
12899 && row
->continued_p
)
12905 if (cursor
!= NULL
)
12911 /* Need to compute x that corresponds to GLYPH. */
12912 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
12914 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
12916 x
+= g
->pixel_width
;
12920 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12922 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12923 w
->cursor
.y
= row
->y
+ dy
;
12925 if (w
== XWINDOW (selected_window
))
12927 if (!row
->continued_p
12928 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12931 this_line_buffer
= XBUFFER (w
->buffer
);
12933 CHARPOS (this_line_start_pos
)
12934 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12935 BYTEPOS (this_line_start_pos
)
12936 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12938 CHARPOS (this_line_end_pos
)
12939 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12940 BYTEPOS (this_line_end_pos
)
12941 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12943 this_line_y
= w
->cursor
.y
;
12944 this_line_pixel_height
= row
->height
;
12945 this_line_vpos
= w
->cursor
.vpos
;
12946 this_line_start_x
= row
->x
;
12949 CHARPOS (this_line_start_pos
) = 0;
12956 /* Run window scroll functions, if any, for WINDOW with new window
12957 start STARTP. Sets the window start of WINDOW to that position.
12959 We assume that the window's buffer is really current. */
12961 static INLINE
struct text_pos
12962 run_window_scroll_functions (window
, startp
)
12963 Lisp_Object window
;
12964 struct text_pos startp
;
12966 struct window
*w
= XWINDOW (window
);
12967 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12969 if (current_buffer
!= XBUFFER (w
->buffer
))
12972 if (!NILP (Vwindow_scroll_functions
))
12974 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12975 make_number (CHARPOS (startp
)));
12976 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12977 /* In case the hook functions switch buffers. */
12978 if (current_buffer
!= XBUFFER (w
->buffer
))
12979 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12986 /* Make sure the line containing the cursor is fully visible.
12987 A value of 1 means there is nothing to be done.
12988 (Either the line is fully visible, or it cannot be made so,
12989 or we cannot tell.)
12991 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12992 is higher than window.
12994 A value of 0 means the caller should do scrolling
12995 as if point had gone off the screen. */
12998 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
13001 int current_matrix_p
;
13003 struct glyph_matrix
*matrix
;
13004 struct glyph_row
*row
;
13007 if (!make_cursor_line_fully_visible_p
)
13010 /* It's not always possible to find the cursor, e.g, when a window
13011 is full of overlay strings. Don't do anything in that case. */
13012 if (w
->cursor
.vpos
< 0)
13015 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
13016 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
13018 /* If the cursor row is not partially visible, there's nothing to do. */
13019 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
13022 /* If the row the cursor is in is taller than the window's height,
13023 it's not clear what to do, so do nothing. */
13024 window_height
= window_box_height (w
);
13025 if (row
->height
>= window_height
)
13027 if (!force_p
|| MINI_WINDOW_P (w
)
13028 || w
->vscroll
|| w
->cursor
.vpos
== 0)
13035 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
13036 non-zero means only WINDOW is redisplayed in redisplay_internal.
13037 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
13038 in redisplay_window to bring a partially visible line into view in
13039 the case that only the cursor has moved.
13041 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
13042 last screen line's vertical height extends past the end of the screen.
13046 1 if scrolling succeeded
13048 0 if scrolling didn't find point.
13050 -1 if new fonts have been loaded so that we must interrupt
13051 redisplay, adjust glyph matrices, and try again. */
13057 SCROLLING_NEED_LARGER_MATRICES
13061 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
13062 scroll_step
, temp_scroll_step
, last_line_misfit
)
13063 Lisp_Object window
;
13064 int just_this_one_p
;
13065 EMACS_INT scroll_conservatively
, scroll_step
;
13066 int temp_scroll_step
;
13067 int last_line_misfit
;
13069 struct window
*w
= XWINDOW (window
);
13070 struct frame
*f
= XFRAME (w
->frame
);
13071 struct text_pos pos
, startp
;
13073 int this_scroll_margin
, scroll_max
, rc
, height
;
13074 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
13075 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
13076 Lisp_Object aggressive
;
13077 int scroll_limit
= INT_MAX
/ FRAME_LINE_HEIGHT (f
);
13080 debug_method_add (w
, "try_scrolling");
13083 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13085 /* Compute scroll margin height in pixels. We scroll when point is
13086 within this distance from the top or bottom of the window. */
13087 if (scroll_margin
> 0)
13088 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
13089 * FRAME_LINE_HEIGHT (f
);
13091 this_scroll_margin
= 0;
13093 /* Force scroll_conservatively to have a reasonable value, to avoid
13094 overflow while computing how much to scroll. Note that the user
13095 can supply scroll-conservatively equal to `most-positive-fixnum',
13096 which can be larger than INT_MAX. */
13097 if (scroll_conservatively
> scroll_limit
)
13099 scroll_conservatively
= scroll_limit
;
13100 scroll_max
= INT_MAX
;
13102 else if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
13103 /* Compute how much we should try to scroll maximally to bring
13104 point into view. */
13105 scroll_max
= (max (scroll_step
,
13106 max (scroll_conservatively
, temp_scroll_step
))
13107 * FRAME_LINE_HEIGHT (f
));
13108 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
13109 || NUMBERP (current_buffer
->scroll_up_aggressively
))
13110 /* We're trying to scroll because of aggressive scrolling but no
13111 scroll_step is set. Choose an arbitrary one. */
13112 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
13118 /* Decide whether to scroll down. */
13119 if (PT
> CHARPOS (startp
))
13121 int scroll_margin_y
;
13123 /* Compute the pixel ypos of the scroll margin, then move it to
13124 either that ypos or PT, whichever comes first. */
13125 start_display (&it
, w
, startp
);
13126 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
13127 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
13128 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
13129 (MOVE_TO_POS
| MOVE_TO_Y
));
13131 if (PT
> CHARPOS (it
.current
.pos
))
13133 int y0
= line_bottom_y (&it
);
13135 /* Compute the distance from the scroll margin to PT
13136 (including the height of the cursor line). Moving the
13137 iterator unconditionally to PT can be slow if PT is far
13138 away, so stop 10 lines past the window bottom (is there a
13139 way to do the right thing quickly?). */
13140 move_it_to (&it
, PT
, -1,
13141 it
.last_visible_y
+ 10 * FRAME_LINE_HEIGHT (f
),
13142 -1, MOVE_TO_POS
| MOVE_TO_Y
);
13143 dy
= line_bottom_y (&it
) - y0
;
13145 if (dy
> scroll_max
)
13146 return SCROLLING_FAILED
;
13154 /* Point is in or below the bottom scroll margin, so move the
13155 window start down. If scrolling conservatively, move it just
13156 enough down to make point visible. If scroll_step is set,
13157 move it down by scroll_step. */
13158 if (scroll_conservatively
)
13160 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
13161 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
13162 else if (scroll_step
|| temp_scroll_step
)
13163 amount_to_scroll
= scroll_max
;
13166 aggressive
= current_buffer
->scroll_up_aggressively
;
13167 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13168 if (NUMBERP (aggressive
))
13170 double float_amount
= XFLOATINT (aggressive
) * height
;
13171 amount_to_scroll
= float_amount
;
13172 if (amount_to_scroll
== 0 && float_amount
> 0)
13173 amount_to_scroll
= 1;
13177 if (amount_to_scroll
<= 0)
13178 return SCROLLING_FAILED
;
13180 start_display (&it
, w
, startp
);
13181 move_it_vertically (&it
, amount_to_scroll
);
13183 /* If STARTP is unchanged, move it down another screen line. */
13184 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
13185 move_it_by_lines (&it
, 1, 1);
13186 startp
= it
.current
.pos
;
13190 struct text_pos scroll_margin_pos
= startp
;
13192 /* See if point is inside the scroll margin at the top of the
13194 if (this_scroll_margin
)
13196 start_display (&it
, w
, startp
);
13197 move_it_vertically (&it
, this_scroll_margin
);
13198 scroll_margin_pos
= it
.current
.pos
;
13201 if (PT
< CHARPOS (scroll_margin_pos
))
13203 /* Point is in the scroll margin at the top of the window or
13204 above what is displayed in the window. */
13207 /* Compute the vertical distance from PT to the scroll
13208 margin position. Give up if distance is greater than
13210 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
13211 start_display (&it
, w
, pos
);
13213 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
13214 it
.last_visible_y
, -1,
13215 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13216 dy
= it
.current_y
- y0
;
13217 if (dy
> scroll_max
)
13218 return SCROLLING_FAILED
;
13220 /* Compute new window start. */
13221 start_display (&it
, w
, startp
);
13223 if (scroll_conservatively
)
13225 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
13226 else if (scroll_step
|| temp_scroll_step
)
13227 amount_to_scroll
= scroll_max
;
13230 aggressive
= current_buffer
->scroll_down_aggressively
;
13231 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
13232 if (NUMBERP (aggressive
))
13234 double float_amount
= XFLOATINT (aggressive
) * height
;
13235 amount_to_scroll
= float_amount
;
13236 if (amount_to_scroll
== 0 && float_amount
> 0)
13237 amount_to_scroll
= 1;
13241 if (amount_to_scroll
<= 0)
13242 return SCROLLING_FAILED
;
13244 move_it_vertically_backward (&it
, amount_to_scroll
);
13245 startp
= it
.current
.pos
;
13249 /* Run window scroll functions. */
13250 startp
= run_window_scroll_functions (window
, startp
);
13252 /* Display the window. Give up if new fonts are loaded, or if point
13254 if (!try_window (window
, startp
, 0))
13255 rc
= SCROLLING_NEED_LARGER_MATRICES
;
13256 else if (w
->cursor
.vpos
< 0)
13258 clear_glyph_matrix (w
->desired_matrix
);
13259 rc
= SCROLLING_FAILED
;
13263 /* Maybe forget recorded base line for line number display. */
13264 if (!just_this_one_p
13265 || current_buffer
->clip_changed
13266 || BEG_UNCHANGED
< CHARPOS (startp
))
13267 w
->base_line_number
= Qnil
;
13269 /* If cursor ends up on a partially visible line,
13270 treat that as being off the bottom of the screen. */
13271 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
13273 clear_glyph_matrix (w
->desired_matrix
);
13274 ++extra_scroll_margin_lines
;
13277 rc
= SCROLLING_SUCCESS
;
13284 /* Compute a suitable window start for window W if display of W starts
13285 on a continuation line. Value is non-zero if a new window start
13288 The new window start will be computed, based on W's width, starting
13289 from the start of the continued line. It is the start of the
13290 screen line with the minimum distance from the old start W->start. */
13293 compute_window_start_on_continuation_line (w
)
13296 struct text_pos pos
, start_pos
;
13297 int window_start_changed_p
= 0;
13299 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
13301 /* If window start is on a continuation line... Window start may be
13302 < BEGV in case there's invisible text at the start of the
13303 buffer (M-x rmail, for example). */
13304 if (CHARPOS (start_pos
) > BEGV
13305 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
13308 struct glyph_row
*row
;
13310 /* Handle the case that the window start is out of range. */
13311 if (CHARPOS (start_pos
) < BEGV
)
13312 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
13313 else if (CHARPOS (start_pos
) > ZV
)
13314 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
13316 /* Find the start of the continued line. This should be fast
13317 because scan_buffer is fast (newline cache). */
13318 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
13319 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
13320 row
, DEFAULT_FACE_ID
);
13321 reseat_at_previous_visible_line_start (&it
);
13323 /* If the line start is "too far" away from the window start,
13324 say it takes too much time to compute a new window start. */
13325 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
13326 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
13328 int min_distance
, distance
;
13330 /* Move forward by display lines to find the new window
13331 start. If window width was enlarged, the new start can
13332 be expected to be > the old start. If window width was
13333 decreased, the new window start will be < the old start.
13334 So, we're looking for the display line start with the
13335 minimum distance from the old window start. */
13336 pos
= it
.current
.pos
;
13337 min_distance
= INFINITY
;
13338 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
13339 distance
< min_distance
)
13341 min_distance
= distance
;
13342 pos
= it
.current
.pos
;
13343 move_it_by_lines (&it
, 1, 0);
13346 /* Set the window start there. */
13347 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
13348 window_start_changed_p
= 1;
13352 return window_start_changed_p
;
13356 /* Try cursor movement in case text has not changed in window WINDOW,
13357 with window start STARTP. Value is
13359 CURSOR_MOVEMENT_SUCCESS if successful
13361 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
13363 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
13364 display. *SCROLL_STEP is set to 1, under certain circumstances, if
13365 we want to scroll as if scroll-step were set to 1. See the code.
13367 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
13368 which case we have to abort this redisplay, and adjust matrices
13373 CURSOR_MOVEMENT_SUCCESS
,
13374 CURSOR_MOVEMENT_CANNOT_BE_USED
,
13375 CURSOR_MOVEMENT_MUST_SCROLL
,
13376 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
13380 try_cursor_movement (window
, startp
, scroll_step
)
13381 Lisp_Object window
;
13382 struct text_pos startp
;
13385 struct window
*w
= XWINDOW (window
);
13386 struct frame
*f
= XFRAME (w
->frame
);
13387 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
13390 if (inhibit_try_cursor_movement
)
13394 /* Handle case where text has not changed, only point, and it has
13395 not moved off the frame. */
13396 if (/* Point may be in this window. */
13397 PT
>= CHARPOS (startp
)
13398 /* Selective display hasn't changed. */
13399 && !current_buffer
->clip_changed
13400 /* Function force-mode-line-update is used to force a thorough
13401 redisplay. It sets either windows_or_buffers_changed or
13402 update_mode_lines. So don't take a shortcut here for these
13404 && !update_mode_lines
13405 && !windows_or_buffers_changed
13406 && !cursor_type_changed
13407 /* Can't use this case if highlighting a region. When a
13408 region exists, cursor movement has to do more than just
13410 && !(!NILP (Vtransient_mark_mode
)
13411 && !NILP (current_buffer
->mark_active
))
13412 && NILP (w
->region_showing
)
13413 && NILP (Vshow_trailing_whitespace
)
13414 /* Right after splitting windows, last_point may be nil. */
13415 && INTEGERP (w
->last_point
)
13416 /* This code is not used for mini-buffer for the sake of the case
13417 of redisplaying to replace an echo area message; since in
13418 that case the mini-buffer contents per se are usually
13419 unchanged. This code is of no real use in the mini-buffer
13420 since the handling of this_line_start_pos, etc., in redisplay
13421 handles the same cases. */
13422 && !EQ (window
, minibuf_window
)
13423 /* When splitting windows or for new windows, it happens that
13424 redisplay is called with a nil window_end_vpos or one being
13425 larger than the window. This should really be fixed in
13426 window.c. I don't have this on my list, now, so we do
13427 approximately the same as the old redisplay code. --gerd. */
13428 && INTEGERP (w
->window_end_vpos
)
13429 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13430 && (FRAME_WINDOW_P (f
)
13431 || !overlay_arrow_in_current_buffer_p ()))
13433 int this_scroll_margin
, top_scroll_margin
;
13434 struct glyph_row
*row
= NULL
;
13437 debug_method_add (w
, "cursor movement");
13440 /* Scroll if point within this distance from the top or bottom
13441 of the window. This is a pixel value. */
13442 if (scroll_margin
> 0)
13444 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13445 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13448 this_scroll_margin
= 0;
13450 top_scroll_margin
= this_scroll_margin
;
13451 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13452 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13454 /* Start with the row the cursor was displayed during the last
13455 not paused redisplay. Give up if that row is not valid. */
13456 if (w
->last_cursor
.vpos
< 0
13457 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13458 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13461 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13462 if (row
->mode_line_p
)
13464 if (!row
->enabled_p
)
13465 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13468 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13471 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13473 if (PT
> XFASTINT (w
->last_point
))
13475 /* Point has moved forward. */
13476 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13477 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13479 xassert (row
->enabled_p
);
13483 /* The end position of a row equals the start position
13484 of the next row. If PT is there, we would rather
13485 display it in the next line. */
13486 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13487 && MATRIX_ROW_END_CHARPOS (row
) == PT
13488 && !cursor_row_p (w
, row
))
13491 /* If within the scroll margin, scroll. Note that
13492 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13493 the next line would be drawn, and that
13494 this_scroll_margin can be zero. */
13495 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13496 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13497 /* Line is completely visible last line in window
13498 and PT is to be set in the next line. */
13499 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13500 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13501 && !row
->ends_at_zv_p
13502 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13505 else if (PT
< XFASTINT (w
->last_point
))
13507 /* Cursor has to be moved backward. Note that PT >=
13508 CHARPOS (startp) because of the outer if-statement. */
13509 while (!row
->mode_line_p
13510 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13511 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13512 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13513 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13514 row
> w
->current_matrix
->rows
13515 && (row
-1)->ends_in_newline_from_string_p
))))
13516 && (row
->y
> top_scroll_margin
13517 || CHARPOS (startp
) == BEGV
))
13519 xassert (row
->enabled_p
);
13523 /* Consider the following case: Window starts at BEGV,
13524 there is invisible, intangible text at BEGV, so that
13525 display starts at some point START > BEGV. It can
13526 happen that we are called with PT somewhere between
13527 BEGV and START. Try to handle that case. */
13528 if (row
< w
->current_matrix
->rows
13529 || row
->mode_line_p
)
13531 row
= w
->current_matrix
->rows
;
13532 if (row
->mode_line_p
)
13536 /* Due to newlines in overlay strings, we may have to
13537 skip forward over overlay strings. */
13538 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13539 && MATRIX_ROW_END_CHARPOS (row
) == PT
13540 && !cursor_row_p (w
, row
))
13543 /* If within the scroll margin, scroll. */
13544 if (row
->y
< top_scroll_margin
13545 && CHARPOS (startp
) != BEGV
)
13550 /* Cursor did not move. So don't scroll even if cursor line
13551 is partially visible, as it was so before. */
13552 rc
= CURSOR_MOVEMENT_SUCCESS
;
13555 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13556 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13558 /* if PT is not in the glyph row, give up. */
13559 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13561 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13562 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13563 && make_cursor_line_fully_visible_p
)
13565 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13566 && !row
->ends_at_zv_p
13567 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13568 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13569 else if (row
->height
> window_box_height (w
))
13571 /* If we end up in a partially visible line, let's
13572 make it fully visible, except when it's taller
13573 than the window, in which case we can't do much
13576 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13580 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13581 if (!cursor_row_fully_visible_p (w
, 0, 1))
13582 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13584 rc
= CURSOR_MOVEMENT_SUCCESS
;
13588 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13593 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13595 rc
= CURSOR_MOVEMENT_SUCCESS
;
13600 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13601 && MATRIX_ROW_START_CHARPOS (row
) == PT
13602 && cursor_row_p (w
, row
));
13611 set_vertical_scroll_bar (w
)
13614 int start
, end
, whole
;
13616 /* Calculate the start and end positions for the current window.
13617 At some point, it would be nice to choose between scrollbars
13618 which reflect the whole buffer size, with special markers
13619 indicating narrowing, and scrollbars which reflect only the
13622 Note that mini-buffers sometimes aren't displaying any text. */
13623 if (!MINI_WINDOW_P (w
)
13624 || (w
== XWINDOW (minibuf_window
)
13625 && NILP (echo_area_buffer
[0])))
13627 struct buffer
*buf
= XBUFFER (w
->buffer
);
13628 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13629 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13630 /* I don't think this is guaranteed to be right. For the
13631 moment, we'll pretend it is. */
13632 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13636 if (whole
< (end
- start
))
13637 whole
= end
- start
;
13640 start
= end
= whole
= 0;
13642 /* Indicate what this scroll bar ought to be displaying now. */
13643 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13644 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13645 (w
, end
- start
, whole
, start
);
13649 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13650 selected_window is redisplayed.
13652 We can return without actually redisplaying the window if
13653 fonts_changed_p is nonzero. In that case, redisplay_internal will
13657 redisplay_window (window
, just_this_one_p
)
13658 Lisp_Object window
;
13659 int just_this_one_p
;
13661 struct window
*w
= XWINDOW (window
);
13662 struct frame
*f
= XFRAME (w
->frame
);
13663 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13664 struct buffer
*old
= current_buffer
;
13665 struct text_pos lpoint
, opoint
, startp
;
13666 int update_mode_line
;
13669 /* Record it now because it's overwritten. */
13670 int current_matrix_up_to_date_p
= 0;
13671 int used_current_matrix_p
= 0;
13672 /* This is less strict than current_matrix_up_to_date_p.
13673 It indictes that the buffer contents and narrowing are unchanged. */
13674 int buffer_unchanged_p
= 0;
13675 int temp_scroll_step
= 0;
13676 int count
= SPECPDL_INDEX ();
13678 int centering_position
= -1;
13679 int last_line_misfit
= 0;
13680 int beg_unchanged
, end_unchanged
;
13682 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13685 /* W must be a leaf window here. */
13686 xassert (!NILP (w
->buffer
));
13688 *w
->desired_matrix
->method
= 0;
13692 reconsider_clip_changes (w
, buffer
);
13694 /* Has the mode line to be updated? */
13695 update_mode_line
= (!NILP (w
->update_mode_line
)
13696 || update_mode_lines
13697 || buffer
->clip_changed
13698 || buffer
->prevent_redisplay_optimizations_p
);
13700 if (MINI_WINDOW_P (w
))
13702 if (w
== XWINDOW (echo_area_window
)
13703 && !NILP (echo_area_buffer
[0]))
13705 if (update_mode_line
)
13706 /* We may have to update a tty frame's menu bar or a
13707 tool-bar. Example `M-x C-h C-h C-g'. */
13708 goto finish_menu_bars
;
13710 /* We've already displayed the echo area glyphs in this window. */
13711 goto finish_scroll_bars
;
13713 else if ((w
!= XWINDOW (minibuf_window
)
13714 || minibuf_level
== 0)
13715 /* When buffer is nonempty, redisplay window normally. */
13716 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13717 /* Quail displays non-mini buffers in minibuffer window.
13718 In that case, redisplay the window normally. */
13719 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13721 /* W is a mini-buffer window, but it's not active, so clear
13723 int yb
= window_text_bottom_y (w
);
13724 struct glyph_row
*row
;
13727 for (y
= 0, row
= w
->desired_matrix
->rows
;
13729 y
+= row
->height
, ++row
)
13730 blank_row (w
, row
, y
);
13731 goto finish_scroll_bars
;
13734 clear_glyph_matrix (w
->desired_matrix
);
13737 /* Otherwise set up data on this window; select its buffer and point
13739 /* Really select the buffer, for the sake of buffer-local
13741 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13743 current_matrix_up_to_date_p
13744 = (!NILP (w
->window_end_valid
)
13745 && !current_buffer
->clip_changed
13746 && !current_buffer
->prevent_redisplay_optimizations_p
13747 && XFASTINT (w
->last_modified
) >= MODIFF
13748 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13750 /* Run the window-bottom-change-functions
13751 if it is possible that the text on the screen has changed
13752 (either due to modification of the text, or any other reason). */
13753 if (!current_matrix_up_to_date_p
13754 && !NILP (Vwindow_text_change_functions
))
13756 safe_run_hooks (Qwindow_text_change_functions
);
13760 beg_unchanged
= BEG_UNCHANGED
;
13761 end_unchanged
= END_UNCHANGED
;
13763 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13765 specbind (Qinhibit_point_motion_hooks
, Qt
);
13768 = (!NILP (w
->window_end_valid
)
13769 && !current_buffer
->clip_changed
13770 && XFASTINT (w
->last_modified
) >= MODIFF
13771 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13773 /* When windows_or_buffers_changed is non-zero, we can't rely on
13774 the window end being valid, so set it to nil there. */
13775 if (windows_or_buffers_changed
)
13777 /* If window starts on a continuation line, maybe adjust the
13778 window start in case the window's width changed. */
13779 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13780 compute_window_start_on_continuation_line (w
);
13782 w
->window_end_valid
= Qnil
;
13785 /* Some sanity checks. */
13786 CHECK_WINDOW_END (w
);
13787 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13789 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13792 /* If %c is in mode line, update it if needed. */
13793 if (!NILP (w
->column_number_displayed
)
13794 /* This alternative quickly identifies a common case
13795 where no change is needed. */
13796 && !(PT
== XFASTINT (w
->last_point
)
13797 && XFASTINT (w
->last_modified
) >= MODIFF
13798 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13799 && (XFASTINT (w
->column_number_displayed
)
13800 != (int) current_column ())) /* iftc */
13801 update_mode_line
= 1;
13803 /* Count number of windows showing the selected buffer. An indirect
13804 buffer counts as its base buffer. */
13805 if (!just_this_one_p
)
13807 struct buffer
*current_base
, *window_base
;
13808 current_base
= current_buffer
;
13809 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13810 if (current_base
->base_buffer
)
13811 current_base
= current_base
->base_buffer
;
13812 if (window_base
->base_buffer
)
13813 window_base
= window_base
->base_buffer
;
13814 if (current_base
== window_base
)
13818 /* Point refers normally to the selected window. For any other
13819 window, set up appropriate value. */
13820 if (!EQ (window
, selected_window
))
13822 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13823 int new_pt_byte
= marker_byte_position (w
->pointm
);
13827 new_pt_byte
= BEGV_BYTE
;
13828 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13830 else if (new_pt
> (ZV
- 1))
13833 new_pt_byte
= ZV_BYTE
;
13834 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13837 /* We don't use SET_PT so that the point-motion hooks don't run. */
13838 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13841 /* If any of the character widths specified in the display table
13842 have changed, invalidate the width run cache. It's true that
13843 this may be a bit late to catch such changes, but the rest of
13844 redisplay goes (non-fatally) haywire when the display table is
13845 changed, so why should we worry about doing any better? */
13846 if (current_buffer
->width_run_cache
)
13848 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13850 if (! disptab_matches_widthtab (disptab
,
13851 XVECTOR (current_buffer
->width_table
)))
13853 invalidate_region_cache (current_buffer
,
13854 current_buffer
->width_run_cache
,
13856 recompute_width_table (current_buffer
, disptab
);
13860 /* If window-start is screwed up, choose a new one. */
13861 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13864 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13866 /* If someone specified a new starting point but did not insist,
13867 check whether it can be used. */
13868 if (!NILP (w
->optional_new_start
)
13869 && CHARPOS (startp
) >= BEGV
13870 && CHARPOS (startp
) <= ZV
)
13872 w
->optional_new_start
= Qnil
;
13873 start_display (&it
, w
, startp
);
13874 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13875 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13876 if (IT_CHARPOS (it
) == PT
)
13877 w
->force_start
= Qt
;
13878 /* IT may overshoot PT if text at PT is invisible. */
13879 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13880 w
->force_start
= Qt
;
13885 /* Handle case where place to start displaying has been specified,
13886 unless the specified location is outside the accessible range. */
13887 if (!NILP (w
->force_start
)
13888 || w
->frozen_window_start_p
)
13890 /* We set this later on if we have to adjust point. */
13893 w
->force_start
= Qnil
;
13895 w
->window_end_valid
= Qnil
;
13897 /* Forget any recorded base line for line number display. */
13898 if (!buffer_unchanged_p
)
13899 w
->base_line_number
= Qnil
;
13901 /* Redisplay the mode line. Select the buffer properly for that.
13902 Also, run the hook window-scroll-functions
13903 because we have scrolled. */
13904 /* Note, we do this after clearing force_start because
13905 if there's an error, it is better to forget about force_start
13906 than to get into an infinite loop calling the hook functions
13907 and having them get more errors. */
13908 if (!update_mode_line
13909 || ! NILP (Vwindow_scroll_functions
))
13911 update_mode_line
= 1;
13912 w
->update_mode_line
= Qt
;
13913 startp
= run_window_scroll_functions (window
, startp
);
13916 w
->last_modified
= make_number (0);
13917 w
->last_overlay_modified
= make_number (0);
13918 if (CHARPOS (startp
) < BEGV
)
13919 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13920 else if (CHARPOS (startp
) > ZV
)
13921 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13923 /* Redisplay, then check if cursor has been set during the
13924 redisplay. Give up if new fonts were loaded. */
13925 /* We used to issue a CHECK_MARGINS argument to try_window here,
13926 but this causes scrolling to fail when point begins inside
13927 the scroll margin (bug#148) -- cyd */
13928 if (!try_window (window
, startp
, 0))
13930 w
->force_start
= Qt
;
13931 clear_glyph_matrix (w
->desired_matrix
);
13932 goto need_larger_matrices
;
13935 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13937 /* If point does not appear, try to move point so it does
13938 appear. The desired matrix has been built above, so we
13939 can use it here. */
13940 new_vpos
= window_box_height (w
) / 2;
13943 if (!cursor_row_fully_visible_p (w
, 0, 0))
13945 /* Point does appear, but on a line partly visible at end of window.
13946 Move it back to a fully-visible line. */
13947 new_vpos
= window_box_height (w
);
13950 /* If we need to move point for either of the above reasons,
13951 now actually do it. */
13954 struct glyph_row
*row
;
13956 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13957 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13960 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13961 MATRIX_ROW_START_BYTEPOS (row
));
13963 if (w
!= XWINDOW (selected_window
))
13964 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13965 else if (current_buffer
== old
)
13966 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13968 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13970 /* If we are highlighting the region, then we just changed
13971 the region, so redisplay to show it. */
13972 if (!NILP (Vtransient_mark_mode
)
13973 && !NILP (current_buffer
->mark_active
))
13975 clear_glyph_matrix (w
->desired_matrix
);
13976 if (!try_window (window
, startp
, 0))
13977 goto need_larger_matrices
;
13982 debug_method_add (w
, "forced window start");
13987 /* Handle case where text has not changed, only point, and it has
13988 not moved off the frame, and we are not retrying after hscroll.
13989 (current_matrix_up_to_date_p is nonzero when retrying.) */
13990 if (current_matrix_up_to_date_p
13991 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13992 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13996 case CURSOR_MOVEMENT_SUCCESS
:
13997 used_current_matrix_p
= 1;
14000 case CURSOR_MOVEMENT_MUST_SCROLL
:
14001 goto try_to_scroll
;
14007 /* If current starting point was originally the beginning of a line
14008 but no longer is, find a new starting point. */
14009 else if (!NILP (w
->start_at_line_beg
)
14010 && !(CHARPOS (startp
) <= BEGV
14011 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
14014 debug_method_add (w
, "recenter 1");
14019 /* Try scrolling with try_window_id. Value is > 0 if update has
14020 been done, it is -1 if we know that the same window start will
14021 not work. It is 0 if unsuccessful for some other reason. */
14022 else if ((tem
= try_window_id (w
)) != 0)
14025 debug_method_add (w
, "try_window_id %d", tem
);
14028 if (fonts_changed_p
)
14029 goto need_larger_matrices
;
14033 /* Otherwise try_window_id has returned -1 which means that we
14034 don't want the alternative below this comment to execute. */
14036 else if (CHARPOS (startp
) >= BEGV
14037 && CHARPOS (startp
) <= ZV
14038 && PT
>= CHARPOS (startp
)
14039 && (CHARPOS (startp
) < ZV
14040 /* Avoid starting at end of buffer. */
14041 || CHARPOS (startp
) == BEGV
14042 || (XFASTINT (w
->last_modified
) >= MODIFF
14043 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
14046 /* If first window line is a continuation line, and window start
14047 is inside the modified region, but the first change is before
14048 current window start, we must select a new window start.
14050 However, if this is the result of a down-mouse event (e.g. by
14051 extending the mouse-drag-overlay), we don't want to select a
14052 new window start, since that would change the position under
14053 the mouse, resulting in an unwanted mouse-movement rather
14054 than a simple mouse-click. */
14055 if (NILP (w
->start_at_line_beg
)
14056 && NILP (do_mouse_tracking
)
14057 && CHARPOS (startp
) > BEGV
14058 && CHARPOS (startp
) > BEG
+ beg_unchanged
14059 && CHARPOS (startp
) <= Z
- end_unchanged
14060 /* Even if w->start_at_line_beg is nil, a new window may
14061 start at a line_beg, since that's how set_buffer_window
14062 sets it. So, we need to check the return value of
14063 compute_window_start_on_continuation_line. (See also
14065 && XMARKER (w
->start
)->buffer
== current_buffer
14066 && compute_window_start_on_continuation_line (w
))
14068 w
->force_start
= Qt
;
14069 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14074 debug_method_add (w
, "same window start");
14077 /* Try to redisplay starting at same place as before.
14078 If point has not moved off frame, accept the results. */
14079 if (!current_matrix_up_to_date_p
14080 /* Don't use try_window_reusing_current_matrix in this case
14081 because a window scroll function can have changed the
14083 || !NILP (Vwindow_scroll_functions
)
14084 || MINI_WINDOW_P (w
)
14085 || !(used_current_matrix_p
14086 = try_window_reusing_current_matrix (w
)))
14088 IF_DEBUG (debug_method_add (w
, "1"));
14089 if (try_window (window
, startp
, 1) < 0)
14090 /* -1 means we need to scroll.
14091 0 means we need new matrices, but fonts_changed_p
14092 is set in that case, so we will detect it below. */
14093 goto try_to_scroll
;
14096 if (fonts_changed_p
)
14097 goto need_larger_matrices
;
14099 if (w
->cursor
.vpos
>= 0)
14101 if (!just_this_one_p
14102 || current_buffer
->clip_changed
14103 || BEG_UNCHANGED
< CHARPOS (startp
))
14104 /* Forget any recorded base line for line number display. */
14105 w
->base_line_number
= Qnil
;
14107 if (!cursor_row_fully_visible_p (w
, 1, 0))
14109 clear_glyph_matrix (w
->desired_matrix
);
14110 last_line_misfit
= 1;
14112 /* Drop through and scroll. */
14117 clear_glyph_matrix (w
->desired_matrix
);
14122 w
->last_modified
= make_number (0);
14123 w
->last_overlay_modified
= make_number (0);
14125 /* Redisplay the mode line. Select the buffer properly for that. */
14126 if (!update_mode_line
)
14128 update_mode_line
= 1;
14129 w
->update_mode_line
= Qt
;
14132 /* Try to scroll by specified few lines. */
14133 if ((scroll_conservatively
14135 || temp_scroll_step
14136 || NUMBERP (current_buffer
->scroll_up_aggressively
)
14137 || NUMBERP (current_buffer
->scroll_down_aggressively
))
14138 && !current_buffer
->clip_changed
14139 && CHARPOS (startp
) >= BEGV
14140 && CHARPOS (startp
) <= ZV
)
14142 /* The function returns -1 if new fonts were loaded, 1 if
14143 successful, 0 if not successful. */
14144 int rc
= try_scrolling (window
, just_this_one_p
,
14145 scroll_conservatively
,
14147 temp_scroll_step
, last_line_misfit
);
14150 case SCROLLING_SUCCESS
:
14153 case SCROLLING_NEED_LARGER_MATRICES
:
14154 goto need_larger_matrices
;
14156 case SCROLLING_FAILED
:
14164 /* Finally, just choose place to start which centers point */
14167 if (centering_position
< 0)
14168 centering_position
= window_box_height (w
) / 2;
14171 debug_method_add (w
, "recenter");
14174 /* w->vscroll = 0; */
14176 /* Forget any previously recorded base line for line number display. */
14177 if (!buffer_unchanged_p
)
14178 w
->base_line_number
= Qnil
;
14180 /* Move backward half the height of the window. */
14181 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14182 it
.current_y
= it
.last_visible_y
;
14183 move_it_vertically_backward (&it
, centering_position
);
14184 xassert (IT_CHARPOS (it
) >= BEGV
);
14186 /* The function move_it_vertically_backward may move over more
14187 than the specified y-distance. If it->w is small, e.g. a
14188 mini-buffer window, we may end up in front of the window's
14189 display area. Start displaying at the start of the line
14190 containing PT in this case. */
14191 if (it
.current_y
<= 0)
14193 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
14194 move_it_vertically_backward (&it
, 0);
14198 it
.current_x
= it
.hpos
= 0;
14200 /* Set startp here explicitly in case that helps avoid an infinite loop
14201 in case the window-scroll-functions functions get errors. */
14202 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
14204 /* Run scroll hooks. */
14205 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
14207 /* Redisplay the window. */
14208 if (!current_matrix_up_to_date_p
14209 || windows_or_buffers_changed
14210 || cursor_type_changed
14211 /* Don't use try_window_reusing_current_matrix in this case
14212 because it can have changed the buffer. */
14213 || !NILP (Vwindow_scroll_functions
)
14214 || !just_this_one_p
14215 || MINI_WINDOW_P (w
)
14216 || !(used_current_matrix_p
14217 = try_window_reusing_current_matrix (w
)))
14218 try_window (window
, startp
, 0);
14220 /* If new fonts have been loaded (due to fontsets), give up. We
14221 have to start a new redisplay since we need to re-adjust glyph
14223 if (fonts_changed_p
)
14224 goto need_larger_matrices
;
14226 /* If cursor did not appear assume that the middle of the window is
14227 in the first line of the window. Do it again with the next line.
14228 (Imagine a window of height 100, displaying two lines of height
14229 60. Moving back 50 from it->last_visible_y will end in the first
14231 if (w
->cursor
.vpos
< 0)
14233 if (!NILP (w
->window_end_valid
)
14234 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
14236 clear_glyph_matrix (w
->desired_matrix
);
14237 move_it_by_lines (&it
, 1, 0);
14238 try_window (window
, it
.current
.pos
, 0);
14240 else if (PT
< IT_CHARPOS (it
))
14242 clear_glyph_matrix (w
->desired_matrix
);
14243 move_it_by_lines (&it
, -1, 0);
14244 try_window (window
, it
.current
.pos
, 0);
14248 /* Not much we can do about it. */
14252 /* Consider the following case: Window starts at BEGV, there is
14253 invisible, intangible text at BEGV, so that display starts at
14254 some point START > BEGV. It can happen that we are called with
14255 PT somewhere between BEGV and START. Try to handle that case. */
14256 if (w
->cursor
.vpos
< 0)
14258 struct glyph_row
*row
= w
->current_matrix
->rows
;
14259 if (row
->mode_line_p
)
14261 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
14264 if (!cursor_row_fully_visible_p (w
, 0, 0))
14266 /* If vscroll is enabled, disable it and try again. */
14270 clear_glyph_matrix (w
->desired_matrix
);
14274 /* If centering point failed to make the whole line visible,
14275 put point at the top instead. That has to make the whole line
14276 visible, if it can be done. */
14277 if (centering_position
== 0)
14280 clear_glyph_matrix (w
->desired_matrix
);
14281 centering_position
= 0;
14287 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14288 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
14289 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
14292 /* Display the mode line, if we must. */
14293 if ((update_mode_line
14294 /* If window not full width, must redo its mode line
14295 if (a) the window to its side is being redone and
14296 (b) we do a frame-based redisplay. This is a consequence
14297 of how inverted lines are drawn in frame-based redisplay. */
14298 || (!just_this_one_p
14299 && !FRAME_WINDOW_P (f
)
14300 && !WINDOW_FULL_WIDTH_P (w
))
14301 /* Line number to display. */
14302 || INTEGERP (w
->base_line_pos
)
14303 /* Column number is displayed and different from the one displayed. */
14304 || (!NILP (w
->column_number_displayed
)
14305 && (XFASTINT (w
->column_number_displayed
)
14306 != (int) current_column ()))) /* iftc */
14307 /* This means that the window has a mode line. */
14308 && (WINDOW_WANTS_MODELINE_P (w
)
14309 || WINDOW_WANTS_HEADER_LINE_P (w
)))
14311 display_mode_lines (w
);
14313 /* If mode line height has changed, arrange for a thorough
14314 immediate redisplay using the correct mode line height. */
14315 if (WINDOW_WANTS_MODELINE_P (w
)
14316 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
14318 fonts_changed_p
= 1;
14319 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
14320 = DESIRED_MODE_LINE_HEIGHT (w
);
14323 /* If header line height has changed, arrange for a thorough
14324 immediate redisplay using the correct header line height. */
14325 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14326 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
14328 fonts_changed_p
= 1;
14329 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
14330 = DESIRED_HEADER_LINE_HEIGHT (w
);
14333 if (fonts_changed_p
)
14334 goto need_larger_matrices
;
14337 if (!line_number_displayed
14338 && !BUFFERP (w
->base_line_pos
))
14340 w
->base_line_pos
= Qnil
;
14341 w
->base_line_number
= Qnil
;
14346 /* When we reach a frame's selected window, redo the frame's menu bar. */
14347 if (update_mode_line
14348 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
14350 int redisplay_menu_p
= 0;
14351 int redisplay_tool_bar_p
= 0;
14353 if (FRAME_WINDOW_P (f
))
14355 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
14356 || defined (HAVE_NS) || defined (USE_GTK)
14357 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
14359 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14363 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
14365 if (redisplay_menu_p
)
14366 display_menu_bar (w
);
14368 #ifdef HAVE_WINDOW_SYSTEM
14369 if (FRAME_WINDOW_P (f
))
14371 #if defined (USE_GTK) || defined (HAVE_NS)
14372 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
14374 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
14375 && (FRAME_TOOL_BAR_LINES (f
) > 0
14376 || !NILP (Vauto_resize_tool_bars
));
14379 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
14381 extern int ignore_mouse_drag_p
;
14382 ignore_mouse_drag_p
= 1;
14388 #ifdef HAVE_WINDOW_SYSTEM
14389 if (FRAME_WINDOW_P (f
)
14390 && update_window_fringes (w
, (just_this_one_p
14391 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
14392 || w
->pseudo_window_p
)))
14396 if (draw_window_fringes (w
, 1))
14397 x_draw_vertical_border (w
);
14401 #endif /* HAVE_WINDOW_SYSTEM */
14403 /* We go to this label, with fonts_changed_p nonzero,
14404 if it is necessary to try again using larger glyph matrices.
14405 We have to redeem the scroll bar even in this case,
14406 because the loop in redisplay_internal expects that. */
14407 need_larger_matrices
:
14409 finish_scroll_bars
:
14411 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14413 /* Set the thumb's position and size. */
14414 set_vertical_scroll_bar (w
);
14416 /* Note that we actually used the scroll bar attached to this
14417 window, so it shouldn't be deleted at the end of redisplay. */
14418 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14419 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14422 /* Restore current_buffer and value of point in it. */
14423 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14424 set_buffer_internal_1 (old
);
14425 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14426 shorter. This can be caused by log truncation in *Messages*. */
14427 if (CHARPOS (lpoint
) <= ZV
)
14428 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14430 unbind_to (count
, Qnil
);
14434 /* Build the complete desired matrix of WINDOW with a window start
14435 buffer position POS.
14437 Value is 1 if successful. It is zero if fonts were loaded during
14438 redisplay which makes re-adjusting glyph matrices necessary, and -1
14439 if point would appear in the scroll margins.
14440 (We check that only if CHECK_MARGINS is nonzero. */
14443 try_window (window
, pos
, check_margins
)
14444 Lisp_Object window
;
14445 struct text_pos pos
;
14448 struct window
*w
= XWINDOW (window
);
14450 struct glyph_row
*last_text_row
= NULL
;
14451 struct frame
*f
= XFRAME (w
->frame
);
14453 /* Make POS the new window start. */
14454 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14456 /* Mark cursor position as unknown. No overlay arrow seen. */
14457 w
->cursor
.vpos
= -1;
14458 overlay_arrow_seen
= 0;
14460 /* Initialize iterator and info to start at POS. */
14461 start_display (&it
, w
, pos
);
14463 /* Display all lines of W. */
14464 while (it
.current_y
< it
.last_visible_y
)
14466 if (display_line (&it
))
14467 last_text_row
= it
.glyph_row
- 1;
14468 if (fonts_changed_p
)
14472 /* Don't let the cursor end in the scroll margins. */
14474 && !MINI_WINDOW_P (w
))
14476 int this_scroll_margin
;
14478 if (scroll_margin
> 0)
14480 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14481 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
14484 this_scroll_margin
= 0;
14486 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14487 && w
->cursor
.y
< this_scroll_margin
14488 && CHARPOS (pos
) > BEGV
14489 && IT_CHARPOS (it
) < ZV
)
14490 /* rms: considering make_cursor_line_fully_visible_p here
14491 seems to give wrong results. We don't want to recenter
14492 when the last line is partly visible, we want to allow
14493 that case to be handled in the usual way. */
14494 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
14496 w
->cursor
.vpos
= -1;
14497 clear_glyph_matrix (w
->desired_matrix
);
14502 /* If bottom moved off end of frame, change mode line percentage. */
14503 if (XFASTINT (w
->window_end_pos
) <= 0
14504 && Z
!= IT_CHARPOS (it
))
14505 w
->update_mode_line
= Qt
;
14507 /* Set window_end_pos to the offset of the last character displayed
14508 on the window from the end of current_buffer. Set
14509 window_end_vpos to its row number. */
14512 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14513 w
->window_end_bytepos
14514 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14516 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14518 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14519 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14520 ->displays_text_p
);
14524 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14525 w
->window_end_pos
= make_number (Z
- ZV
);
14526 w
->window_end_vpos
= make_number (0);
14529 /* But that is not valid info until redisplay finishes. */
14530 w
->window_end_valid
= Qnil
;
14536 /************************************************************************
14537 Window redisplay reusing current matrix when buffer has not changed
14538 ************************************************************************/
14540 /* Try redisplay of window W showing an unchanged buffer with a
14541 different window start than the last time it was displayed by
14542 reusing its current matrix. Value is non-zero if successful.
14543 W->start is the new window start. */
14546 try_window_reusing_current_matrix (w
)
14549 struct frame
*f
= XFRAME (w
->frame
);
14550 struct glyph_row
*row
, *bottom_row
;
14553 struct text_pos start
, new_start
;
14554 int nrows_scrolled
, i
;
14555 struct glyph_row
*last_text_row
;
14556 struct glyph_row
*last_reused_text_row
;
14557 struct glyph_row
*start_row
;
14558 int start_vpos
, min_y
, max_y
;
14561 if (inhibit_try_window_reusing
)
14565 if (/* This function doesn't handle terminal frames. */
14566 !FRAME_WINDOW_P (f
)
14567 /* Don't try to reuse the display if windows have been split
14569 || windows_or_buffers_changed
14570 || cursor_type_changed
)
14573 /* Can't do this if region may have changed. */
14574 if ((!NILP (Vtransient_mark_mode
)
14575 && !NILP (current_buffer
->mark_active
))
14576 || !NILP (w
->region_showing
)
14577 || !NILP (Vshow_trailing_whitespace
))
14580 /* If top-line visibility has changed, give up. */
14581 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14582 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14585 /* Give up if old or new display is scrolled vertically. We could
14586 make this function handle this, but right now it doesn't. */
14587 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14588 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14591 /* The variable new_start now holds the new window start. The old
14592 start `start' can be determined from the current matrix. */
14593 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14594 start
= start_row
->start
.pos
;
14595 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14597 /* Clear the desired matrix for the display below. */
14598 clear_glyph_matrix (w
->desired_matrix
);
14600 if (CHARPOS (new_start
) <= CHARPOS (start
))
14604 /* Don't use this method if the display starts with an ellipsis
14605 displayed for invisible text. It's not easy to handle that case
14606 below, and it's certainly not worth the effort since this is
14607 not a frequent case. */
14608 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14611 IF_DEBUG (debug_method_add (w
, "twu1"));
14613 /* Display up to a row that can be reused. The variable
14614 last_text_row is set to the last row displayed that displays
14615 text. Note that it.vpos == 0 if or if not there is a
14616 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14617 start_display (&it
, w
, new_start
);
14618 first_row_y
= it
.current_y
;
14619 w
->cursor
.vpos
= -1;
14620 last_text_row
= last_reused_text_row
= NULL
;
14622 while (it
.current_y
< it
.last_visible_y
14623 && !fonts_changed_p
)
14625 /* If we have reached into the characters in the START row,
14626 that means the line boundaries have changed. So we
14627 can't start copying with the row START. Maybe it will
14628 work to start copying with the following row. */
14629 while (IT_CHARPOS (it
) > CHARPOS (start
))
14631 /* Advance to the next row as the "start". */
14633 start
= start_row
->start
.pos
;
14634 /* If there are no more rows to try, or just one, give up. */
14635 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14636 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14637 || CHARPOS (start
) == ZV
)
14639 clear_glyph_matrix (w
->desired_matrix
);
14643 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14645 /* If we have reached alignment,
14646 we can copy the rest of the rows. */
14647 if (IT_CHARPOS (it
) == CHARPOS (start
))
14650 if (display_line (&it
))
14651 last_text_row
= it
.glyph_row
- 1;
14654 /* A value of current_y < last_visible_y means that we stopped
14655 at the previous window start, which in turn means that we
14656 have at least one reusable row. */
14657 if (it
.current_y
< it
.last_visible_y
)
14659 /* IT.vpos always starts from 0; it counts text lines. */
14660 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14662 /* Find PT if not already found in the lines displayed. */
14663 if (w
->cursor
.vpos
< 0)
14665 int dy
= it
.current_y
- start_row
->y
;
14667 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14668 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14670 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14671 dy
, nrows_scrolled
);
14674 clear_glyph_matrix (w
->desired_matrix
);
14679 /* Scroll the display. Do it before the current matrix is
14680 changed. The problem here is that update has not yet
14681 run, i.e. part of the current matrix is not up to date.
14682 scroll_run_hook will clear the cursor, and use the
14683 current matrix to get the height of the row the cursor is
14685 run
.current_y
= start_row
->y
;
14686 run
.desired_y
= it
.current_y
;
14687 run
.height
= it
.last_visible_y
- it
.current_y
;
14689 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14692 FRAME_RIF (f
)->update_window_begin_hook (w
);
14693 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14694 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14695 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14699 /* Shift current matrix down by nrows_scrolled lines. */
14700 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14701 rotate_matrix (w
->current_matrix
,
14703 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14706 /* Disable lines that must be updated. */
14707 for (i
= 0; i
< nrows_scrolled
; ++i
)
14708 (start_row
+ i
)->enabled_p
= 0;
14710 /* Re-compute Y positions. */
14711 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14712 max_y
= it
.last_visible_y
;
14713 for (row
= start_row
+ nrows_scrolled
;
14717 row
->y
= it
.current_y
;
14718 row
->visible_height
= row
->height
;
14720 if (row
->y
< min_y
)
14721 row
->visible_height
-= min_y
- row
->y
;
14722 if (row
->y
+ row
->height
> max_y
)
14723 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14724 row
->redraw_fringe_bitmaps_p
= 1;
14726 it
.current_y
+= row
->height
;
14728 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14729 last_reused_text_row
= row
;
14730 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14734 /* Disable lines in the current matrix which are now
14735 below the window. */
14736 for (++row
; row
< bottom_row
; ++row
)
14737 row
->enabled_p
= row
->mode_line_p
= 0;
14740 /* Update window_end_pos etc.; last_reused_text_row is the last
14741 reused row from the current matrix containing text, if any.
14742 The value of last_text_row is the last displayed line
14743 containing text. */
14744 if (last_reused_text_row
)
14746 w
->window_end_bytepos
14747 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14749 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14751 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14752 w
->current_matrix
));
14754 else if (last_text_row
)
14756 w
->window_end_bytepos
14757 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14759 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14761 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14765 /* This window must be completely empty. */
14766 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14767 w
->window_end_pos
= make_number (Z
- ZV
);
14768 w
->window_end_vpos
= make_number (0);
14770 w
->window_end_valid
= Qnil
;
14772 /* Update hint: don't try scrolling again in update_window. */
14773 w
->desired_matrix
->no_scrolling_p
= 1;
14776 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14780 else if (CHARPOS (new_start
) > CHARPOS (start
))
14782 struct glyph_row
*pt_row
, *row
;
14783 struct glyph_row
*first_reusable_row
;
14784 struct glyph_row
*first_row_to_display
;
14786 int yb
= window_text_bottom_y (w
);
14788 /* Find the row starting at new_start, if there is one. Don't
14789 reuse a partially visible line at the end. */
14790 first_reusable_row
= start_row
;
14791 while (first_reusable_row
->enabled_p
14792 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14793 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14794 < CHARPOS (new_start
)))
14795 ++first_reusable_row
;
14797 /* Give up if there is no row to reuse. */
14798 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14799 || !first_reusable_row
->enabled_p
14800 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14801 != CHARPOS (new_start
)))
14804 /* We can reuse fully visible rows beginning with
14805 first_reusable_row to the end of the window. Set
14806 first_row_to_display to the first row that cannot be reused.
14807 Set pt_row to the row containing point, if there is any. */
14809 for (first_row_to_display
= first_reusable_row
;
14810 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14811 ++first_row_to_display
)
14813 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14814 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14815 pt_row
= first_row_to_display
;
14818 /* Start displaying at the start of first_row_to_display. */
14819 xassert (first_row_to_display
->y
< yb
);
14820 init_to_row_start (&it
, w
, first_row_to_display
);
14822 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14824 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14826 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14827 + WINDOW_HEADER_LINE_HEIGHT (w
));
14829 /* Display lines beginning with first_row_to_display in the
14830 desired matrix. Set last_text_row to the last row displayed
14831 that displays text. */
14832 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14833 if (pt_row
== NULL
)
14834 w
->cursor
.vpos
= -1;
14835 last_text_row
= NULL
;
14836 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14837 if (display_line (&it
))
14838 last_text_row
= it
.glyph_row
- 1;
14840 /* If point is in a reused row, adjust y and vpos of the cursor
14844 w
->cursor
.vpos
-= nrows_scrolled
;
14845 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14848 /* Give up if point isn't in a row displayed or reused. (This
14849 also handles the case where w->cursor.vpos < nrows_scrolled
14850 after the calls to display_line, which can happen with scroll
14851 margins. See bug#1295.) */
14852 if (w
->cursor
.vpos
< 0)
14854 clear_glyph_matrix (w
->desired_matrix
);
14858 /* Scroll the display. */
14859 run
.current_y
= first_reusable_row
->y
;
14860 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14861 run
.height
= it
.last_visible_y
- run
.current_y
;
14862 dy
= run
.current_y
- run
.desired_y
;
14867 FRAME_RIF (f
)->update_window_begin_hook (w
);
14868 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14869 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14870 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14874 /* Adjust Y positions of reused rows. */
14875 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14876 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14877 max_y
= it
.last_visible_y
;
14878 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14881 row
->visible_height
= row
->height
;
14882 if (row
->y
< min_y
)
14883 row
->visible_height
-= min_y
- row
->y
;
14884 if (row
->y
+ row
->height
> max_y
)
14885 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14886 row
->redraw_fringe_bitmaps_p
= 1;
14889 /* Scroll the current matrix. */
14890 xassert (nrows_scrolled
> 0);
14891 rotate_matrix (w
->current_matrix
,
14893 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14896 /* Disable rows not reused. */
14897 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14898 row
->enabled_p
= 0;
14900 /* Point may have moved to a different line, so we cannot assume that
14901 the previous cursor position is valid; locate the correct row. */
14904 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14905 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14909 w
->cursor
.y
= row
->y
;
14911 if (row
< bottom_row
)
14913 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14914 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14915 struct glyph
*orig_glyph
= glyph
;
14916 struct cursor_pos orig_cursor
= w
->cursor
;
14919 && (!BUFFERP (glyph
->object
)
14920 || glyph
->charpos
!= PT
);
14924 w
->cursor
.x
+= glyph
->pixel_width
;
14926 /* With bidi reordering, charpos changes non-linearly
14927 with hpos, so the right glyph could be to the
14929 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
14930 && (!BUFFERP (glyph
->object
) || glyph
->charpos
!= PT
))
14932 struct glyph
*start_glyph
= row
->glyphs
[TEXT_AREA
];
14934 glyph
= orig_glyph
- 1;
14935 orig_cursor
.hpos
--;
14936 orig_cursor
.x
-= glyph
->pixel_width
;
14937 for (; glyph
>= start_glyph
14938 && (!BUFFERP (glyph
->object
)
14939 || glyph
->charpos
!= PT
);
14943 w
->cursor
.x
-= glyph
->pixel_width
;
14945 if (BUFFERP (glyph
->object
) && glyph
->charpos
== PT
)
14946 w
->cursor
= orig_cursor
;
14951 /* Adjust window end. A null value of last_text_row means that
14952 the window end is in reused rows which in turn means that
14953 only its vpos can have changed. */
14956 w
->window_end_bytepos
14957 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14959 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14961 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14966 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14969 w
->window_end_valid
= Qnil
;
14970 w
->desired_matrix
->no_scrolling_p
= 1;
14973 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14983 /************************************************************************
14984 Window redisplay reusing current matrix when buffer has changed
14985 ************************************************************************/
14987 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14988 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14990 static struct glyph_row
*
14991 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14992 struct glyph_row
*));
14995 /* Return the last row in MATRIX displaying text. If row START is
14996 non-null, start searching with that row. IT gives the dimensions
14997 of the display. Value is null if matrix is empty; otherwise it is
14998 a pointer to the row found. */
15000 static struct glyph_row
*
15001 find_last_row_displaying_text (matrix
, it
, start
)
15002 struct glyph_matrix
*matrix
;
15004 struct glyph_row
*start
;
15006 struct glyph_row
*row
, *row_found
;
15008 /* Set row_found to the last row in IT->w's current matrix
15009 displaying text. The loop looks funny but think of partially
15012 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
15013 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15015 xassert (row
->enabled_p
);
15017 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
15026 /* Return the last row in the current matrix of W that is not affected
15027 by changes at the start of current_buffer that occurred since W's
15028 current matrix was built. Value is null if no such row exists.
15030 BEG_UNCHANGED us the number of characters unchanged at the start of
15031 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
15032 first changed character in current_buffer. Characters at positions <
15033 BEG + BEG_UNCHANGED are at the same buffer positions as they were
15034 when the current matrix was built. */
15036 static struct glyph_row
*
15037 find_last_unchanged_at_beg_row (w
)
15040 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
15041 struct glyph_row
*row
;
15042 struct glyph_row
*row_found
= NULL
;
15043 int yb
= window_text_bottom_y (w
);
15045 /* Find the last row displaying unchanged text. */
15046 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15047 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15048 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
15051 if (/* If row ends before first_changed_pos, it is unchanged,
15052 except in some case. */
15053 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
15054 /* When row ends in ZV and we write at ZV it is not
15056 && !row
->ends_at_zv_p
15057 /* When first_changed_pos is the end of a continued line,
15058 row is not unchanged because it may be no longer
15060 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
15061 && (row
->continued_p
15062 || row
->exact_window_width_line_p
)))
15065 /* Stop if last visible row. */
15066 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
15074 /* Find the first glyph row in the current matrix of W that is not
15075 affected by changes at the end of current_buffer since the
15076 time W's current matrix was built.
15078 Return in *DELTA the number of chars by which buffer positions in
15079 unchanged text at the end of current_buffer must be adjusted.
15081 Return in *DELTA_BYTES the corresponding number of bytes.
15083 Value is null if no such row exists, i.e. all rows are affected by
15086 static struct glyph_row
*
15087 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
15089 int *delta
, *delta_bytes
;
15091 struct glyph_row
*row
;
15092 struct glyph_row
*row_found
= NULL
;
15094 *delta
= *delta_bytes
= 0;
15096 /* Display must not have been paused, otherwise the current matrix
15097 is not up to date. */
15098 eassert (!NILP (w
->window_end_valid
));
15100 /* A value of window_end_pos >= END_UNCHANGED means that the window
15101 end is in the range of changed text. If so, there is no
15102 unchanged row at the end of W's current matrix. */
15103 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
15106 /* Set row to the last row in W's current matrix displaying text. */
15107 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15109 /* If matrix is entirely empty, no unchanged row exists. */
15110 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15112 /* The value of row is the last glyph row in the matrix having a
15113 meaningful buffer position in it. The end position of row
15114 corresponds to window_end_pos. This allows us to translate
15115 buffer positions in the current matrix to current buffer
15116 positions for characters not in changed text. */
15117 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15118 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15119 int last_unchanged_pos
, last_unchanged_pos_old
;
15120 struct glyph_row
*first_text_row
15121 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15123 *delta
= Z
- Z_old
;
15124 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15126 /* Set last_unchanged_pos to the buffer position of the last
15127 character in the buffer that has not been changed. Z is the
15128 index + 1 of the last character in current_buffer, i.e. by
15129 subtracting END_UNCHANGED we get the index of the last
15130 unchanged character, and we have to add BEG to get its buffer
15132 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
15133 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
15135 /* Search backward from ROW for a row displaying a line that
15136 starts at a minimum position >= last_unchanged_pos_old. */
15137 for (; row
> first_text_row
; --row
)
15139 /* This used to abort, but it can happen.
15140 It is ok to just stop the search instead here. KFS. */
15141 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
15144 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
15149 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
15155 /* Make sure that glyph rows in the current matrix of window W
15156 reference the same glyph memory as corresponding rows in the
15157 frame's frame matrix. This function is called after scrolling W's
15158 current matrix on a terminal frame in try_window_id and
15159 try_window_reusing_current_matrix. */
15162 sync_frame_with_window_matrix_rows (w
)
15165 struct frame
*f
= XFRAME (w
->frame
);
15166 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
15168 /* Preconditions: W must be a leaf window and full-width. Its frame
15169 must have a frame matrix. */
15170 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
15171 xassert (WINDOW_FULL_WIDTH_P (w
));
15172 xassert (!FRAME_WINDOW_P (f
));
15174 /* If W is a full-width window, glyph pointers in W's current matrix
15175 have, by definition, to be the same as glyph pointers in the
15176 corresponding frame matrix. Note that frame matrices have no
15177 marginal areas (see build_frame_matrix). */
15178 window_row
= w
->current_matrix
->rows
;
15179 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
15180 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
15181 while (window_row
< window_row_end
)
15183 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
15184 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
15186 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
15187 frame_row
->glyphs
[TEXT_AREA
] = start
;
15188 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
15189 frame_row
->glyphs
[LAST_AREA
] = end
;
15191 /* Disable frame rows whose corresponding window rows have
15192 been disabled in try_window_id. */
15193 if (!window_row
->enabled_p
)
15194 frame_row
->enabled_p
= 0;
15196 ++window_row
, ++frame_row
;
15201 /* Find the glyph row in window W containing CHARPOS. Consider all
15202 rows between START and END (not inclusive). END null means search
15203 all rows to the end of the display area of W. Value is the row
15204 containing CHARPOS or null. */
15207 row_containing_pos (w
, charpos
, start
, end
, dy
)
15210 struct glyph_row
*start
, *end
;
15213 struct glyph_row
*row
= start
;
15216 /* If we happen to start on a header-line, skip that. */
15217 if (row
->mode_line_p
)
15220 if ((end
&& row
>= end
) || !row
->enabled_p
)
15223 last_y
= window_text_bottom_y (w
) - dy
;
15227 /* Give up if we have gone too far. */
15228 if (end
&& row
>= end
)
15230 /* This formerly returned if they were equal.
15231 I think that both quantities are of a "last plus one" type;
15232 if so, when they are equal, the row is within the screen. -- rms. */
15233 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
15236 /* If it is in this row, return this row. */
15237 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
15238 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
15239 /* The end position of a row equals the start
15240 position of the next row. If CHARPOS is there, we
15241 would rather display it in the next line, except
15242 when this line ends in ZV. */
15243 && !row
->ends_at_zv_p
15244 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15245 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
15252 /* Try to redisplay window W by reusing its existing display. W's
15253 current matrix must be up to date when this function is called,
15254 i.e. window_end_valid must not be nil.
15258 1 if display has been updated
15259 0 if otherwise unsuccessful
15260 -1 if redisplay with same window start is known not to succeed
15262 The following steps are performed:
15264 1. Find the last row in the current matrix of W that is not
15265 affected by changes at the start of current_buffer. If no such row
15268 2. Find the first row in W's current matrix that is not affected by
15269 changes at the end of current_buffer. Maybe there is no such row.
15271 3. Display lines beginning with the row + 1 found in step 1 to the
15272 row found in step 2 or, if step 2 didn't find a row, to the end of
15275 4. If cursor is not known to appear on the window, give up.
15277 5. If display stopped at the row found in step 2, scroll the
15278 display and current matrix as needed.
15280 6. Maybe display some lines at the end of W, if we must. This can
15281 happen under various circumstances, like a partially visible line
15282 becoming fully visible, or because newly displayed lines are displayed
15283 in smaller font sizes.
15285 7. Update W's window end information. */
15291 struct frame
*f
= XFRAME (w
->frame
);
15292 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
15293 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
15294 struct glyph_row
*last_unchanged_at_beg_row
;
15295 struct glyph_row
*first_unchanged_at_end_row
;
15296 struct glyph_row
*row
;
15297 struct glyph_row
*bottom_row
;
15300 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
15301 struct text_pos start_pos
;
15303 int first_unchanged_at_end_vpos
= 0;
15304 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
15305 struct text_pos start
;
15306 int first_changed_charpos
, last_changed_charpos
;
15309 if (inhibit_try_window_id
)
15313 /* This is handy for debugging. */
15315 #define GIVE_UP(X) \
15317 fprintf (stderr, "try_window_id give up %d\n", (X)); \
15321 #define GIVE_UP(X) return 0
15324 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
15326 /* Don't use this for mini-windows because these can show
15327 messages and mini-buffers, and we don't handle that here. */
15328 if (MINI_WINDOW_P (w
))
15331 /* This flag is used to prevent redisplay optimizations. */
15332 if (windows_or_buffers_changed
|| cursor_type_changed
)
15335 /* Verify that narrowing has not changed.
15336 Also verify that we were not told to prevent redisplay optimizations.
15337 It would be nice to further
15338 reduce the number of cases where this prevents try_window_id. */
15339 if (current_buffer
->clip_changed
15340 || current_buffer
->prevent_redisplay_optimizations_p
)
15343 /* Window must either use window-based redisplay or be full width. */
15344 if (!FRAME_WINDOW_P (f
)
15345 && (!FRAME_LINE_INS_DEL_OK (f
)
15346 || !WINDOW_FULL_WIDTH_P (w
)))
15349 /* Give up if point is known NOT to appear in W. */
15350 if (PT
< CHARPOS (start
))
15353 /* Another way to prevent redisplay optimizations. */
15354 if (XFASTINT (w
->last_modified
) == 0)
15357 /* Verify that window is not hscrolled. */
15358 if (XFASTINT (w
->hscroll
) != 0)
15361 /* Verify that display wasn't paused. */
15362 if (NILP (w
->window_end_valid
))
15365 /* Can't use this if highlighting a region because a cursor movement
15366 will do more than just set the cursor. */
15367 if (!NILP (Vtransient_mark_mode
)
15368 && !NILP (current_buffer
->mark_active
))
15371 /* Likewise if highlighting trailing whitespace. */
15372 if (!NILP (Vshow_trailing_whitespace
))
15375 /* Likewise if showing a region. */
15376 if (!NILP (w
->region_showing
))
15379 /* Can't use this if overlay arrow position and/or string have
15381 if (overlay_arrows_changed_p ())
15384 /* When word-wrap is on, adding a space to the first word of a
15385 wrapped line can change the wrap position, altering the line
15386 above it. It might be worthwhile to handle this more
15387 intelligently, but for now just redisplay from scratch. */
15388 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
15391 /* Under bidi reordering, adding or deleting a character in the
15392 beginning of a paragraph, before the first strong directional
15393 character, can change the base direction of the paragraph (unless
15394 the buffer specifies a fixed paragraph direction), which will
15395 require to redisplay the whole paragraph. It might be worthwhile
15396 to find the paragraph limits and widen the range of redisplayed
15397 lines to that, but for now just give up this optimization and
15398 redisplay from scratch. */
15399 if (!NILP (XBUFFER (w
->buffer
)->bidi_display_reordering
)
15400 && NILP (XBUFFER (w
->buffer
)->bidi_paragraph_direction
))
15403 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
15404 only if buffer has really changed. The reason is that the gap is
15405 initially at Z for freshly visited files. The code below would
15406 set end_unchanged to 0 in that case. */
15407 if (MODIFF
> SAVE_MODIFF
15408 /* This seems to happen sometimes after saving a buffer. */
15409 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
15411 if (GPT
- BEG
< BEG_UNCHANGED
)
15412 BEG_UNCHANGED
= GPT
- BEG
;
15413 if (Z
- GPT
< END_UNCHANGED
)
15414 END_UNCHANGED
= Z
- GPT
;
15417 /* The position of the first and last character that has been changed. */
15418 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
15419 last_changed_charpos
= Z
- END_UNCHANGED
;
15421 /* If window starts after a line end, and the last change is in
15422 front of that newline, then changes don't affect the display.
15423 This case happens with stealth-fontification. Note that although
15424 the display is unchanged, glyph positions in the matrix have to
15425 be adjusted, of course. */
15426 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
15427 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
15428 && ((last_changed_charpos
< CHARPOS (start
)
15429 && CHARPOS (start
) == BEGV
)
15430 || (last_changed_charpos
< CHARPOS (start
) - 1
15431 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
15433 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
15434 struct glyph_row
*r0
;
15436 /* Compute how many chars/bytes have been added to or removed
15437 from the buffer. */
15438 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
15439 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
15441 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
15443 /* Give up if PT is not in the window. Note that it already has
15444 been checked at the start of try_window_id that PT is not in
15445 front of the window start. */
15446 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15449 /* If window start is unchanged, we can reuse the whole matrix
15450 as is, after adjusting glyph positions. No need to compute
15451 the window end again, since its offset from Z hasn't changed. */
15452 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15453 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15454 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15455 /* PT must not be in a partially visible line. */
15456 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15457 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15459 /* Adjust positions in the glyph matrix. */
15460 if (delta
|| delta_bytes
)
15462 struct glyph_row
*r1
15463 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15464 increment_matrix_positions (w
->current_matrix
,
15465 MATRIX_ROW_VPOS (r0
, current_matrix
),
15466 MATRIX_ROW_VPOS (r1
, current_matrix
),
15467 delta
, delta_bytes
);
15470 /* Set the cursor. */
15471 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15473 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15480 /* Handle the case that changes are all below what is displayed in
15481 the window, and that PT is in the window. This shortcut cannot
15482 be taken if ZV is visible in the window, and text has been added
15483 there that is visible in the window. */
15484 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15485 /* ZV is not visible in the window, or there are no
15486 changes at ZV, actually. */
15487 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15488 || first_changed_charpos
== last_changed_charpos
))
15490 struct glyph_row
*r0
;
15492 /* Give up if PT is not in the window. Note that it already has
15493 been checked at the start of try_window_id that PT is not in
15494 front of the window start. */
15495 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15498 /* If window start is unchanged, we can reuse the whole matrix
15499 as is, without changing glyph positions since no text has
15500 been added/removed in front of the window end. */
15501 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15502 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15503 /* PT must not be in a partially visible line. */
15504 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15505 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15507 /* We have to compute the window end anew since text
15508 can have been added/removed after it. */
15510 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15511 w
->window_end_bytepos
15512 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15514 /* Set the cursor. */
15515 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15517 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15524 /* Give up if window start is in the changed area.
15526 The condition used to read
15528 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15530 but why that was tested escapes me at the moment. */
15531 if (CHARPOS (start
) >= first_changed_charpos
15532 && CHARPOS (start
) <= last_changed_charpos
)
15535 /* Check that window start agrees with the start of the first glyph
15536 row in its current matrix. Check this after we know the window
15537 start is not in changed text, otherwise positions would not be
15539 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15540 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15543 /* Give up if the window ends in strings. Overlay strings
15544 at the end are difficult to handle, so don't try. */
15545 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15546 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15549 /* Compute the position at which we have to start displaying new
15550 lines. Some of the lines at the top of the window might be
15551 reusable because they are not displaying changed text. Find the
15552 last row in W's current matrix not affected by changes at the
15553 start of current_buffer. Value is null if changes start in the
15554 first line of window. */
15555 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15556 if (last_unchanged_at_beg_row
)
15558 /* Avoid starting to display in the moddle of a character, a TAB
15559 for instance. This is easier than to set up the iterator
15560 exactly, and it's not a frequent case, so the additional
15561 effort wouldn't really pay off. */
15562 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15563 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15564 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15565 --last_unchanged_at_beg_row
;
15567 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15570 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15572 start_pos
= it
.current
.pos
;
15574 /* Start displaying new lines in the desired matrix at the same
15575 vpos we would use in the current matrix, i.e. below
15576 last_unchanged_at_beg_row. */
15577 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15579 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15580 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15582 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15586 /* There are no reusable lines at the start of the window.
15587 Start displaying in the first text line. */
15588 start_display (&it
, w
, start
);
15589 it
.vpos
= it
.first_vpos
;
15590 start_pos
= it
.current
.pos
;
15593 /* Find the first row that is not affected by changes at the end of
15594 the buffer. Value will be null if there is no unchanged row, in
15595 which case we must redisplay to the end of the window. delta
15596 will be set to the value by which buffer positions beginning with
15597 first_unchanged_at_end_row have to be adjusted due to text
15599 first_unchanged_at_end_row
15600 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15601 IF_DEBUG (debug_delta
= delta
);
15602 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15604 /* Set stop_pos to the buffer position up to which we will have to
15605 display new lines. If first_unchanged_at_end_row != NULL, this
15606 is the buffer position of the start of the line displayed in that
15607 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15608 that we don't stop at a buffer position. */
15610 if (first_unchanged_at_end_row
)
15612 xassert (last_unchanged_at_beg_row
== NULL
15613 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15615 /* If this is a continuation line, move forward to the next one
15616 that isn't. Changes in lines above affect this line.
15617 Caution: this may move first_unchanged_at_end_row to a row
15618 not displaying text. */
15619 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15620 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15621 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15622 < it
.last_visible_y
))
15623 ++first_unchanged_at_end_row
;
15625 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15626 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15627 >= it
.last_visible_y
))
15628 first_unchanged_at_end_row
= NULL
;
15631 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15633 first_unchanged_at_end_vpos
15634 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15635 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15638 else if (last_unchanged_at_beg_row
== NULL
)
15644 /* Either there is no unchanged row at the end, or the one we have
15645 now displays text. This is a necessary condition for the window
15646 end pos calculation at the end of this function. */
15647 xassert (first_unchanged_at_end_row
== NULL
15648 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15650 debug_last_unchanged_at_beg_vpos
15651 = (last_unchanged_at_beg_row
15652 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15654 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15656 #endif /* GLYPH_DEBUG != 0 */
15659 /* Display new lines. Set last_text_row to the last new line
15660 displayed which has text on it, i.e. might end up as being the
15661 line where the window_end_vpos is. */
15662 w
->cursor
.vpos
= -1;
15663 last_text_row
= NULL
;
15664 overlay_arrow_seen
= 0;
15665 while (it
.current_y
< it
.last_visible_y
15666 && !fonts_changed_p
15667 && (first_unchanged_at_end_row
== NULL
15668 || IT_CHARPOS (it
) < stop_pos
))
15670 if (display_line (&it
))
15671 last_text_row
= it
.glyph_row
- 1;
15674 if (fonts_changed_p
)
15678 /* Compute differences in buffer positions, y-positions etc. for
15679 lines reused at the bottom of the window. Compute what we can
15681 if (first_unchanged_at_end_row
15682 /* No lines reused because we displayed everything up to the
15683 bottom of the window. */
15684 && it
.current_y
< it
.last_visible_y
)
15687 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15689 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15690 run
.current_y
= first_unchanged_at_end_row
->y
;
15691 run
.desired_y
= run
.current_y
+ dy
;
15692 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15696 delta
= delta_bytes
= dvpos
= dy
15697 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15698 first_unchanged_at_end_row
= NULL
;
15700 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15703 /* Find the cursor if not already found. We have to decide whether
15704 PT will appear on this window (it sometimes doesn't, but this is
15705 not a very frequent case.) This decision has to be made before
15706 the current matrix is altered. A value of cursor.vpos < 0 means
15707 that PT is either in one of the lines beginning at
15708 first_unchanged_at_end_row or below the window. Don't care for
15709 lines that might be displayed later at the window end; as
15710 mentioned, this is not a frequent case. */
15711 if (w
->cursor
.vpos
< 0)
15713 /* Cursor in unchanged rows at the top? */
15714 if (PT
< CHARPOS (start_pos
)
15715 && last_unchanged_at_beg_row
)
15717 row
= row_containing_pos (w
, PT
,
15718 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15719 last_unchanged_at_beg_row
+ 1, 0);
15721 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15724 /* Start from first_unchanged_at_end_row looking for PT. */
15725 else if (first_unchanged_at_end_row
)
15727 row
= row_containing_pos (w
, PT
- delta
,
15728 first_unchanged_at_end_row
, NULL
, 0);
15730 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15731 delta_bytes
, dy
, dvpos
);
15734 /* Give up if cursor was not found. */
15735 if (w
->cursor
.vpos
< 0)
15737 clear_glyph_matrix (w
->desired_matrix
);
15742 /* Don't let the cursor end in the scroll margins. */
15744 int this_scroll_margin
, cursor_height
;
15746 this_scroll_margin
= max (0, scroll_margin
);
15747 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15748 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15749 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15751 if ((w
->cursor
.y
< this_scroll_margin
15752 && CHARPOS (start
) > BEGV
)
15753 /* Old redisplay didn't take scroll margin into account at the bottom,
15754 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15755 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15756 ? cursor_height
+ this_scroll_margin
15757 : 1)) > it
.last_visible_y
)
15759 w
->cursor
.vpos
= -1;
15760 clear_glyph_matrix (w
->desired_matrix
);
15765 /* Scroll the display. Do it before changing the current matrix so
15766 that xterm.c doesn't get confused about where the cursor glyph is
15768 if (dy
&& run
.height
)
15772 if (FRAME_WINDOW_P (f
))
15774 FRAME_RIF (f
)->update_window_begin_hook (w
);
15775 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15776 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15777 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15781 /* Terminal frame. In this case, dvpos gives the number of
15782 lines to scroll by; dvpos < 0 means scroll up. */
15783 int first_unchanged_at_end_vpos
15784 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15785 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15786 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15787 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15788 + window_internal_height (w
));
15790 /* Perform the operation on the screen. */
15793 /* Scroll last_unchanged_at_beg_row to the end of the
15794 window down dvpos lines. */
15795 set_terminal_window (f
, end
);
15797 /* On dumb terminals delete dvpos lines at the end
15798 before inserting dvpos empty lines. */
15799 if (!FRAME_SCROLL_REGION_OK (f
))
15800 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15802 /* Insert dvpos empty lines in front of
15803 last_unchanged_at_beg_row. */
15804 ins_del_lines (f
, from
, dvpos
);
15806 else if (dvpos
< 0)
15808 /* Scroll up last_unchanged_at_beg_vpos to the end of
15809 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15810 set_terminal_window (f
, end
);
15812 /* Delete dvpos lines in front of
15813 last_unchanged_at_beg_vpos. ins_del_lines will set
15814 the cursor to the given vpos and emit |dvpos| delete
15816 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15818 /* On a dumb terminal insert dvpos empty lines at the
15820 if (!FRAME_SCROLL_REGION_OK (f
))
15821 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15824 set_terminal_window (f
, 0);
15830 /* Shift reused rows of the current matrix to the right position.
15831 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15833 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15834 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15837 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15838 bottom_vpos
, dvpos
);
15839 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15842 else if (dvpos
> 0)
15844 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15845 bottom_vpos
, dvpos
);
15846 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15847 first_unchanged_at_end_vpos
+ dvpos
, 0);
15850 /* For frame-based redisplay, make sure that current frame and window
15851 matrix are in sync with respect to glyph memory. */
15852 if (!FRAME_WINDOW_P (f
))
15853 sync_frame_with_window_matrix_rows (w
);
15855 /* Adjust buffer positions in reused rows. */
15856 if (delta
|| delta_bytes
)
15857 increment_matrix_positions (current_matrix
,
15858 first_unchanged_at_end_vpos
+ dvpos
,
15859 bottom_vpos
, delta
, delta_bytes
);
15861 /* Adjust Y positions. */
15863 shift_glyph_matrix (w
, current_matrix
,
15864 first_unchanged_at_end_vpos
+ dvpos
,
15867 if (first_unchanged_at_end_row
)
15869 first_unchanged_at_end_row
+= dvpos
;
15870 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15871 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15872 first_unchanged_at_end_row
= NULL
;
15875 /* If scrolling up, there may be some lines to display at the end of
15877 last_text_row_at_end
= NULL
;
15880 /* Scrolling up can leave for example a partially visible line
15881 at the end of the window to be redisplayed. */
15882 /* Set last_row to the glyph row in the current matrix where the
15883 window end line is found. It has been moved up or down in
15884 the matrix by dvpos. */
15885 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15886 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15888 /* If last_row is the window end line, it should display text. */
15889 xassert (last_row
->displays_text_p
);
15891 /* If window end line was partially visible before, begin
15892 displaying at that line. Otherwise begin displaying with the
15893 line following it. */
15894 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15896 init_to_row_start (&it
, w
, last_row
);
15897 it
.vpos
= last_vpos
;
15898 it
.current_y
= last_row
->y
;
15902 init_to_row_end (&it
, w
, last_row
);
15903 it
.vpos
= 1 + last_vpos
;
15904 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15908 /* We may start in a continuation line. If so, we have to
15909 get the right continuation_lines_width and current_x. */
15910 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15911 it
.hpos
= it
.current_x
= 0;
15913 /* Display the rest of the lines at the window end. */
15914 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15915 while (it
.current_y
< it
.last_visible_y
15916 && !fonts_changed_p
)
15918 /* Is it always sure that the display agrees with lines in
15919 the current matrix? I don't think so, so we mark rows
15920 displayed invalid in the current matrix by setting their
15921 enabled_p flag to zero. */
15922 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15923 if (display_line (&it
))
15924 last_text_row_at_end
= it
.glyph_row
- 1;
15928 /* Update window_end_pos and window_end_vpos. */
15929 if (first_unchanged_at_end_row
15930 && !last_text_row_at_end
)
15932 /* Window end line if one of the preserved rows from the current
15933 matrix. Set row to the last row displaying text in current
15934 matrix starting at first_unchanged_at_end_row, after
15936 xassert (first_unchanged_at_end_row
->displays_text_p
);
15937 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15938 first_unchanged_at_end_row
);
15939 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15941 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15942 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15944 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15945 xassert (w
->window_end_bytepos
>= 0);
15946 IF_DEBUG (debug_method_add (w
, "A"));
15948 else if (last_text_row_at_end
)
15951 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15952 w
->window_end_bytepos
15953 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15955 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15956 xassert (w
->window_end_bytepos
>= 0);
15957 IF_DEBUG (debug_method_add (w
, "B"));
15959 else if (last_text_row
)
15961 /* We have displayed either to the end of the window or at the
15962 end of the window, i.e. the last row with text is to be found
15963 in the desired matrix. */
15965 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15966 w
->window_end_bytepos
15967 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15969 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15970 xassert (w
->window_end_bytepos
>= 0);
15972 else if (first_unchanged_at_end_row
== NULL
15973 && last_text_row
== NULL
15974 && last_text_row_at_end
== NULL
)
15976 /* Displayed to end of window, but no line containing text was
15977 displayed. Lines were deleted at the end of the window. */
15978 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15979 int vpos
= XFASTINT (w
->window_end_vpos
);
15980 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15981 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15984 row
== NULL
&& vpos
>= first_vpos
;
15985 --vpos
, --current_row
, --desired_row
)
15987 if (desired_row
->enabled_p
)
15989 if (desired_row
->displays_text_p
)
15992 else if (current_row
->displays_text_p
)
15996 xassert (row
!= NULL
);
15997 w
->window_end_vpos
= make_number (vpos
+ 1);
15998 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15999 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
16000 xassert (w
->window_end_bytepos
>= 0);
16001 IF_DEBUG (debug_method_add (w
, "C"));
16006 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
16007 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
16009 /* Record that display has not been completed. */
16010 w
->window_end_valid
= Qnil
;
16011 w
->desired_matrix
->no_scrolling_p
= 1;
16019 /***********************************************************************
16020 More debugging support
16021 ***********************************************************************/
16025 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
16026 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
16027 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
16030 /* Dump the contents of glyph matrix MATRIX on stderr.
16032 GLYPHS 0 means don't show glyph contents.
16033 GLYPHS 1 means show glyphs in short form
16034 GLYPHS > 1 means show glyphs in long form. */
16037 dump_glyph_matrix (matrix
, glyphs
)
16038 struct glyph_matrix
*matrix
;
16042 for (i
= 0; i
< matrix
->nrows
; ++i
)
16043 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
16047 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
16048 the glyph row and area where the glyph comes from. */
16051 dump_glyph (row
, glyph
, area
)
16052 struct glyph_row
*row
;
16053 struct glyph
*glyph
;
16056 if (glyph
->type
== CHAR_GLYPH
)
16059 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16060 glyph
- row
->glyphs
[TEXT_AREA
],
16063 (BUFFERP (glyph
->object
)
16065 : (STRINGP (glyph
->object
)
16068 glyph
->pixel_width
,
16070 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
16074 glyph
->left_box_line_p
,
16075 glyph
->right_box_line_p
);
16077 else if (glyph
->type
== STRETCH_GLYPH
)
16080 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16081 glyph
- row
->glyphs
[TEXT_AREA
],
16084 (BUFFERP (glyph
->object
)
16086 : (STRINGP (glyph
->object
)
16089 glyph
->pixel_width
,
16093 glyph
->left_box_line_p
,
16094 glyph
->right_box_line_p
);
16096 else if (glyph
->type
== IMAGE_GLYPH
)
16099 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
16100 glyph
- row
->glyphs
[TEXT_AREA
],
16103 (BUFFERP (glyph
->object
)
16105 : (STRINGP (glyph
->object
)
16108 glyph
->pixel_width
,
16112 glyph
->left_box_line_p
,
16113 glyph
->right_box_line_p
);
16115 else if (glyph
->type
== COMPOSITE_GLYPH
)
16118 " %5d %4c %6d %c %3d 0x%05x",
16119 glyph
- row
->glyphs
[TEXT_AREA
],
16122 (BUFFERP (glyph
->object
)
16124 : (STRINGP (glyph
->object
)
16127 glyph
->pixel_width
,
16129 if (glyph
->u
.cmp
.automatic
)
16132 glyph
->u
.cmp
.from
, glyph
->u
.cmp
.to
);
16133 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
16135 glyph
->left_box_line_p
,
16136 glyph
->right_box_line_p
);
16141 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
16142 GLYPHS 0 means don't show glyph contents.
16143 GLYPHS 1 means show glyphs in short form
16144 GLYPHS > 1 means show glyphs in long form. */
16147 dump_glyph_row (row
, vpos
, glyphs
)
16148 struct glyph_row
*row
;
16153 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
16154 fprintf (stderr
, "======================================================================\n");
16156 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
16157 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
16159 MATRIX_ROW_START_CHARPOS (row
),
16160 MATRIX_ROW_END_CHARPOS (row
),
16161 row
->used
[TEXT_AREA
],
16162 row
->contains_overlapping_glyphs_p
,
16164 row
->truncated_on_left_p
,
16165 row
->truncated_on_right_p
,
16167 MATRIX_ROW_CONTINUATION_LINE_P (row
),
16168 row
->displays_text_p
,
16171 row
->ends_in_middle_of_char_p
,
16172 row
->starts_in_middle_of_char_p
,
16178 row
->visible_height
,
16181 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
16182 row
->end
.overlay_string_index
,
16183 row
->continuation_lines_width
);
16184 fprintf (stderr
, "%9d %5d\n",
16185 CHARPOS (row
->start
.string_pos
),
16186 CHARPOS (row
->end
.string_pos
));
16187 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
16188 row
->end
.dpvec_index
);
16195 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16197 struct glyph
*glyph
= row
->glyphs
[area
];
16198 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
16200 /* Glyph for a line end in text. */
16201 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
16204 if (glyph
< glyph_end
)
16205 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
16207 for (; glyph
< glyph_end
; ++glyph
)
16208 dump_glyph (row
, glyph
, area
);
16211 else if (glyphs
== 1)
16215 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16217 char *s
= (char *) alloca (row
->used
[area
] + 1);
16220 for (i
= 0; i
< row
->used
[area
]; ++i
)
16222 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
16223 if (glyph
->type
== CHAR_GLYPH
16224 && glyph
->u
.ch
< 0x80
16225 && glyph
->u
.ch
>= ' ')
16226 s
[i
] = glyph
->u
.ch
;
16232 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
16238 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
16239 Sdump_glyph_matrix
, 0, 1, "p",
16240 doc
: /* Dump the current matrix of the selected window to stderr.
16241 Shows contents of glyph row structures. With non-nil
16242 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
16243 glyphs in short form, otherwise show glyphs in long form. */)
16245 Lisp_Object glyphs
;
16247 struct window
*w
= XWINDOW (selected_window
);
16248 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16250 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
16251 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
16252 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
16253 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
16254 fprintf (stderr
, "=============================================\n");
16255 dump_glyph_matrix (w
->current_matrix
,
16256 NILP (glyphs
) ? 0 : XINT (glyphs
));
16261 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
16262 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
16265 struct frame
*f
= XFRAME (selected_frame
);
16266 dump_glyph_matrix (f
->current_matrix
, 1);
16271 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
16272 doc
: /* Dump glyph row ROW to stderr.
16273 GLYPH 0 means don't dump glyphs.
16274 GLYPH 1 means dump glyphs in short form.
16275 GLYPH > 1 or omitted means dump glyphs in long form. */)
16277 Lisp_Object row
, glyphs
;
16279 struct glyph_matrix
*matrix
;
16282 CHECK_NUMBER (row
);
16283 matrix
= XWINDOW (selected_window
)->current_matrix
;
16285 if (vpos
>= 0 && vpos
< matrix
->nrows
)
16286 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
16288 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16293 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
16294 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
16295 GLYPH 0 means don't dump glyphs.
16296 GLYPH 1 means dump glyphs in short form.
16297 GLYPH > 1 or omitted means dump glyphs in long form. */)
16299 Lisp_Object row
, glyphs
;
16301 struct frame
*sf
= SELECTED_FRAME ();
16302 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
16305 CHECK_NUMBER (row
);
16307 if (vpos
>= 0 && vpos
< m
->nrows
)
16308 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
16309 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
16314 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
16315 doc
: /* Toggle tracing of redisplay.
16316 With ARG, turn tracing on if and only if ARG is positive. */)
16321 trace_redisplay_p
= !trace_redisplay_p
;
16324 arg
= Fprefix_numeric_value (arg
);
16325 trace_redisplay_p
= XINT (arg
) > 0;
16332 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
16333 doc
: /* Like `format', but print result to stderr.
16334 usage: (trace-to-stderr STRING &rest OBJECTS) */)
16339 Lisp_Object s
= Fformat (nargs
, args
);
16340 fprintf (stderr
, "%s", SDATA (s
));
16344 #endif /* GLYPH_DEBUG */
16348 /***********************************************************************
16349 Building Desired Matrix Rows
16350 ***********************************************************************/
16352 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
16353 Used for non-window-redisplay windows, and for windows w/o left fringe. */
16355 static struct glyph_row
*
16356 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
16358 Lisp_Object overlay_arrow_string
;
16360 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
16361 struct buffer
*buffer
= XBUFFER (w
->buffer
);
16362 struct buffer
*old
= current_buffer
;
16363 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
16364 int arrow_len
= SCHARS (overlay_arrow_string
);
16365 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
16366 const unsigned char *p
;
16369 int n_glyphs_before
;
16371 set_buffer_temp (buffer
);
16372 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
16373 it
.glyph_row
->used
[TEXT_AREA
] = 0;
16374 SET_TEXT_POS (it
.position
, 0, 0);
16376 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
16378 while (p
< arrow_end
)
16380 Lisp_Object face
, ilisp
;
16382 /* Get the next character. */
16384 it
.c
= string_char_and_length (p
, &it
.len
);
16386 it
.c
= *p
, it
.len
= 1;
16389 /* Get its face. */
16390 ilisp
= make_number (p
- arrow_string
);
16391 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
16392 it
.face_id
= compute_char_face (f
, it
.c
, face
);
16394 /* Compute its width, get its glyphs. */
16395 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
16396 SET_TEXT_POS (it
.position
, -1, -1);
16397 PRODUCE_GLYPHS (&it
);
16399 /* If this character doesn't fit any more in the line, we have
16400 to remove some glyphs. */
16401 if (it
.current_x
> it
.last_visible_x
)
16403 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
16408 set_buffer_temp (old
);
16409 return it
.glyph_row
;
16413 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
16414 glyphs are only inserted for terminal frames since we can't really
16415 win with truncation glyphs when partially visible glyphs are
16416 involved. Which glyphs to insert is determined by
16417 produce_special_glyphs. */
16420 insert_left_trunc_glyphs (it
)
16423 struct it truncate_it
;
16424 struct glyph
*from
, *end
, *to
, *toend
;
16426 xassert (!FRAME_WINDOW_P (it
->f
));
16428 /* Get the truncation glyphs. */
16430 truncate_it
.current_x
= 0;
16431 truncate_it
.face_id
= DEFAULT_FACE_ID
;
16432 truncate_it
.glyph_row
= &scratch_glyph_row
;
16433 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
16434 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
16435 truncate_it
.object
= make_number (0);
16436 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
16438 /* Overwrite glyphs from IT with truncation glyphs. */
16439 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16440 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
16441 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
16442 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16447 /* There may be padding glyphs left over. Overwrite them too. */
16448 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16450 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16456 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16460 /* Compute the pixel height and width of IT->glyph_row.
16462 Most of the time, ascent and height of a display line will be equal
16463 to the max_ascent and max_height values of the display iterator
16464 structure. This is not the case if
16466 1. We hit ZV without displaying anything. In this case, max_ascent
16467 and max_height will be zero.
16469 2. We have some glyphs that don't contribute to the line height.
16470 (The glyph row flag contributes_to_line_height_p is for future
16471 pixmap extensions).
16473 The first case is easily covered by using default values because in
16474 these cases, the line height does not really matter, except that it
16475 must not be zero. */
16478 compute_line_metrics (it
)
16481 struct glyph_row
*row
= it
->glyph_row
;
16484 if (FRAME_WINDOW_P (it
->f
))
16486 int i
, min_y
, max_y
;
16488 /* The line may consist of one space only, that was added to
16489 place the cursor on it. If so, the row's height hasn't been
16491 if (row
->height
== 0)
16493 if (it
->max_ascent
+ it
->max_descent
== 0)
16494 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16495 row
->ascent
= it
->max_ascent
;
16496 row
->height
= it
->max_ascent
+ it
->max_descent
;
16497 row
->phys_ascent
= it
->max_phys_ascent
;
16498 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16499 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16502 /* Compute the width of this line. */
16503 row
->pixel_width
= row
->x
;
16504 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16505 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16507 xassert (row
->pixel_width
>= 0);
16508 xassert (row
->ascent
>= 0 && row
->height
> 0);
16510 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16511 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16513 /* If first line's physical ascent is larger than its logical
16514 ascent, use the physical ascent, and make the row taller.
16515 This makes accented characters fully visible. */
16516 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16517 && row
->phys_ascent
> row
->ascent
)
16519 row
->height
+= row
->phys_ascent
- row
->ascent
;
16520 row
->ascent
= row
->phys_ascent
;
16523 /* Compute how much of the line is visible. */
16524 row
->visible_height
= row
->height
;
16526 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16527 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16529 if (row
->y
< min_y
)
16530 row
->visible_height
-= min_y
- row
->y
;
16531 if (row
->y
+ row
->height
> max_y
)
16532 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16536 row
->pixel_width
= row
->used
[TEXT_AREA
];
16537 if (row
->continued_p
)
16538 row
->pixel_width
-= it
->continuation_pixel_width
;
16539 else if (row
->truncated_on_right_p
)
16540 row
->pixel_width
-= it
->truncation_pixel_width
;
16541 row
->ascent
= row
->phys_ascent
= 0;
16542 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16543 row
->extra_line_spacing
= 0;
16546 /* Compute a hash code for this row. */
16548 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16549 for (i
= 0; i
< row
->used
[area
]; ++i
)
16550 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16551 + row
->glyphs
[area
][i
].u
.val
16552 + row
->glyphs
[area
][i
].face_id
16553 + row
->glyphs
[area
][i
].padding_p
16554 + (row
->glyphs
[area
][i
].type
<< 2));
16556 it
->max_ascent
= it
->max_descent
= 0;
16557 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16561 /* Append one space to the glyph row of iterator IT if doing a
16562 window-based redisplay. The space has the same face as
16563 IT->face_id. Value is non-zero if a space was added.
16565 This function is called to make sure that there is always one glyph
16566 at the end of a glyph row that the cursor can be set on under
16567 window-systems. (If there weren't such a glyph we would not know
16568 how wide and tall a box cursor should be displayed).
16570 At the same time this space let's a nicely handle clearing to the
16571 end of the line if the row ends in italic text. */
16574 append_space_for_newline (it
, default_face_p
)
16576 int default_face_p
;
16578 if (FRAME_WINDOW_P (it
->f
))
16580 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16582 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16583 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16585 /* Save some values that must not be changed.
16586 Must save IT->c and IT->len because otherwise
16587 ITERATOR_AT_END_P wouldn't work anymore after
16588 append_space_for_newline has been called. */
16589 enum display_element_type saved_what
= it
->what
;
16590 int saved_c
= it
->c
, saved_len
= it
->len
;
16591 int saved_x
= it
->current_x
;
16592 int saved_face_id
= it
->face_id
;
16593 struct text_pos saved_pos
;
16594 Lisp_Object saved_object
;
16597 saved_object
= it
->object
;
16598 saved_pos
= it
->position
;
16600 it
->what
= IT_CHARACTER
;
16601 bzero (&it
->position
, sizeof it
->position
);
16602 it
->object
= make_number (0);
16606 if (default_face_p
)
16607 it
->face_id
= DEFAULT_FACE_ID
;
16608 else if (it
->face_before_selective_p
)
16609 it
->face_id
= it
->saved_face_id
;
16610 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16611 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16613 PRODUCE_GLYPHS (it
);
16615 it
->override_ascent
= -1;
16616 it
->constrain_row_ascent_descent_p
= 0;
16617 it
->current_x
= saved_x
;
16618 it
->object
= saved_object
;
16619 it
->position
= saved_pos
;
16620 it
->what
= saved_what
;
16621 it
->face_id
= saved_face_id
;
16622 it
->len
= saved_len
;
16632 /* Extend the face of the last glyph in the text area of IT->glyph_row
16633 to the end of the display line. Called from display_line.
16634 If the glyph row is empty, add a space glyph to it so that we
16635 know the face to draw. Set the glyph row flag fill_line_p. */
16638 extend_face_to_end_of_line (it
)
16642 struct frame
*f
= it
->f
;
16644 /* If line is already filled, do nothing. */
16645 if (it
->current_x
>= it
->last_visible_x
)
16648 /* Face extension extends the background and box of IT->face_id
16649 to the end of the line. If the background equals the background
16650 of the frame, we don't have to do anything. */
16651 if (it
->face_before_selective_p
)
16652 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16654 face
= FACE_FROM_ID (f
, it
->face_id
);
16656 if (FRAME_WINDOW_P (f
)
16657 && it
->glyph_row
->displays_text_p
16658 && face
->box
== FACE_NO_BOX
16659 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16663 /* Set the glyph row flag indicating that the face of the last glyph
16664 in the text area has to be drawn to the end of the text area. */
16665 it
->glyph_row
->fill_line_p
= 1;
16667 /* If current character of IT is not ASCII, make sure we have the
16668 ASCII face. This will be automatically undone the next time
16669 get_next_display_element returns a multibyte character. Note
16670 that the character will always be single byte in unibyte
16672 if (!ASCII_CHAR_P (it
->c
))
16674 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16677 if (FRAME_WINDOW_P (f
))
16679 /* If the row is empty, add a space with the current face of IT,
16680 so that we know which face to draw. */
16681 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16683 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16684 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16685 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16690 /* Save some values that must not be changed. */
16691 int saved_x
= it
->current_x
;
16692 struct text_pos saved_pos
;
16693 Lisp_Object saved_object
;
16694 enum display_element_type saved_what
= it
->what
;
16695 int saved_face_id
= it
->face_id
;
16697 saved_object
= it
->object
;
16698 saved_pos
= it
->position
;
16700 it
->what
= IT_CHARACTER
;
16701 bzero (&it
->position
, sizeof it
->position
);
16702 it
->object
= make_number (0);
16705 it
->face_id
= face
->id
;
16707 PRODUCE_GLYPHS (it
);
16709 while (it
->current_x
<= it
->last_visible_x
)
16710 PRODUCE_GLYPHS (it
);
16712 /* Don't count these blanks really. It would let us insert a left
16713 truncation glyph below and make us set the cursor on them, maybe. */
16714 it
->current_x
= saved_x
;
16715 it
->object
= saved_object
;
16716 it
->position
= saved_pos
;
16717 it
->what
= saved_what
;
16718 it
->face_id
= saved_face_id
;
16723 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16724 trailing whitespace. */
16727 trailing_whitespace_p (charpos
)
16730 int bytepos
= CHAR_TO_BYTE (charpos
);
16733 while (bytepos
< ZV_BYTE
16734 && (c
= FETCH_CHAR (bytepos
),
16735 c
== ' ' || c
== '\t'))
16738 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16740 if (bytepos
!= PT_BYTE
)
16747 /* Highlight trailing whitespace, if any, in ROW. */
16750 highlight_trailing_whitespace (f
, row
)
16752 struct glyph_row
*row
;
16754 int used
= row
->used
[TEXT_AREA
];
16758 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16759 struct glyph
*glyph
= start
+ used
- 1;
16761 /* Skip over glyphs inserted to display the cursor at the
16762 end of a line, for extending the face of the last glyph
16763 to the end of the line on terminals, and for truncation
16764 and continuation glyphs. */
16765 while (glyph
>= start
16766 && glyph
->type
== CHAR_GLYPH
16767 && INTEGERP (glyph
->object
))
16770 /* If last glyph is a space or stretch, and it's trailing
16771 whitespace, set the face of all trailing whitespace glyphs in
16772 IT->glyph_row to `trailing-whitespace'. */
16774 && BUFFERP (glyph
->object
)
16775 && (glyph
->type
== STRETCH_GLYPH
16776 || (glyph
->type
== CHAR_GLYPH
16777 && glyph
->u
.ch
== ' '))
16778 && trailing_whitespace_p (glyph
->charpos
))
16780 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16784 while (glyph
>= start
16785 && BUFFERP (glyph
->object
)
16786 && (glyph
->type
== STRETCH_GLYPH
16787 || (glyph
->type
== CHAR_GLYPH
16788 && glyph
->u
.ch
== ' ')))
16789 (glyph
--)->face_id
= face_id
;
16795 /* Value is non-zero if glyph row ROW in window W should be
16796 used to hold the cursor. */
16799 cursor_row_p (w
, row
)
16801 struct glyph_row
*row
;
16803 int cursor_row_p
= 1;
16805 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16807 /* Suppose the row ends on a string.
16808 Unless the row is continued, that means it ends on a newline
16809 in the string. If it's anything other than a display string
16810 (e.g. a before-string from an overlay), we don't want the
16811 cursor there. (This heuristic seems to give the optimal
16812 behavior for the various types of multi-line strings.) */
16813 if (CHARPOS (row
->end
.string_pos
) >= 0)
16815 if (row
->continued_p
)
16819 /* Check for `display' property. */
16820 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16821 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16822 struct glyph
*glyph
;
16825 for (glyph
= end
; glyph
>= beg
; --glyph
)
16826 if (STRINGP (glyph
->object
))
16829 = Fget_char_property (make_number (PT
),
16833 && display_prop_string_p (prop
, glyph
->object
));
16838 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16840 /* If the row ends in middle of a real character,
16841 and the line is continued, we want the cursor here.
16842 That's because MATRIX_ROW_END_CHARPOS would equal
16843 PT if PT is before the character. */
16844 if (!row
->ends_in_ellipsis_p
)
16845 cursor_row_p
= row
->continued_p
;
16847 /* If the row ends in an ellipsis, then
16848 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16849 We want that position to be displayed after the ellipsis. */
16852 /* If the row ends at ZV, display the cursor at the end of that
16853 row instead of at the start of the row below. */
16854 else if (row
->ends_at_zv_p
)
16860 return cursor_row_p
;
16865 /* Push the display property PROP so that it will be rendered at the
16866 current position in IT. Return 1 if PROP was successfully pushed,
16870 push_display_prop (struct it
*it
, Lisp_Object prop
)
16874 if (STRINGP (prop
))
16876 if (SCHARS (prop
) == 0)
16883 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16884 it
->current
.overlay_string_index
= -1;
16885 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16886 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16887 it
->method
= GET_FROM_STRING
;
16888 it
->stop_charpos
= 0;
16890 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16892 it
->method
= GET_FROM_STRETCH
;
16895 #ifdef HAVE_WINDOW_SYSTEM
16896 else if (IMAGEP (prop
))
16898 it
->what
= IT_IMAGE
;
16899 it
->image_id
= lookup_image (it
->f
, prop
);
16900 it
->method
= GET_FROM_IMAGE
;
16902 #endif /* HAVE_WINDOW_SYSTEM */
16905 pop_it (it
); /* bogus display property, give up */
16912 /* Return the character-property PROP at the current position in IT. */
16915 get_it_property (it
, prop
)
16919 Lisp_Object position
;
16921 if (STRINGP (it
->object
))
16922 position
= make_number (IT_STRING_CHARPOS (*it
));
16923 else if (BUFFERP (it
->object
))
16924 position
= make_number (IT_CHARPOS (*it
));
16928 return Fget_char_property (position
, prop
, it
->object
);
16931 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16934 handle_line_prefix (struct it
*it
)
16936 Lisp_Object prefix
;
16937 if (it
->continuation_lines_width
> 0)
16939 prefix
= get_it_property (it
, Qwrap_prefix
);
16941 prefix
= Vwrap_prefix
;
16945 prefix
= get_it_property (it
, Qline_prefix
);
16947 prefix
= Vline_prefix
;
16949 if (! NILP (prefix
) && push_display_prop (it
, prefix
))
16951 /* If the prefix is wider than the window, and we try to wrap
16952 it, it would acquire its own wrap prefix, and so on till the
16953 iterator stack overflows. So, don't wrap the prefix. */
16954 it
->line_wrap
= TRUNCATE
;
16955 it
->avoid_cursor_p
= 1;
16961 /* Construct the glyph row IT->glyph_row in the desired matrix of
16962 IT->w from text at the current position of IT. See dispextern.h
16963 for an overview of struct it. Value is non-zero if
16964 IT->glyph_row displays text, as opposed to a line displaying ZV
16971 struct glyph_row
*row
= it
->glyph_row
;
16972 Lisp_Object overlay_arrow_string
;
16974 int may_wrap
= 0, wrap_x
;
16975 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16976 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16977 int wrap_row_extra_line_spacing
;
16978 struct display_pos row_end
;
16980 /* We always start displaying at hpos zero even if hscrolled. */
16981 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16983 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16984 >= it
->w
->desired_matrix
->nrows
)
16986 it
->w
->nrows_scale_factor
++;
16987 fonts_changed_p
= 1;
16991 /* Is IT->w showing the region? */
16992 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16994 /* Clear the result glyph row and enable it. */
16995 prepare_desired_row (row
);
16997 row
->y
= it
->current_y
;
16998 row
->start
= it
->start
;
16999 row
->continuation_lines_width
= it
->continuation_lines_width
;
17000 row
->displays_text_p
= 1;
17001 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
17002 it
->starts_in_middle_of_char_p
= 0;
17003 /* If the paragraph base direction is R2L, its glyphs should be
17005 if (it
->bidi_p
&& (it
->bidi_it
.level_stack
[0].level
& 1) != 0)
17006 row
->reversed_p
= 1;
17008 /* Arrange the overlays nicely for our purposes. Usually, we call
17009 display_line on only one line at a time, in which case this
17010 can't really hurt too much, or we call it on lines which appear
17011 one after another in the buffer, in which case all calls to
17012 recenter_overlay_lists but the first will be pretty cheap. */
17013 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
17015 /* Move over display elements that are not visible because we are
17016 hscrolled. This may stop at an x-position < IT->first_visible_x
17017 if the first glyph is partially visible or if we hit a line end. */
17018 if (it
->current_x
< it
->first_visible_x
)
17020 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
17021 MOVE_TO_POS
| MOVE_TO_X
);
17025 /* We only do this when not calling `move_it_in_display_line_to'
17026 above, because move_it_in_display_line_to calls
17027 handle_line_prefix itself. */
17028 handle_line_prefix (it
);
17031 /* Get the initial row height. This is either the height of the
17032 text hscrolled, if there is any, or zero. */
17033 row
->ascent
= it
->max_ascent
;
17034 row
->height
= it
->max_ascent
+ it
->max_descent
;
17035 row
->phys_ascent
= it
->max_phys_ascent
;
17036 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
17037 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
17039 /* Loop generating characters. The loop is left with IT on the next
17040 character to display. */
17043 int n_glyphs_before
, hpos_before
, x_before
;
17045 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
17047 /* Retrieve the next thing to display. Value is zero if end of
17049 if (!get_next_display_element (it
))
17051 /* Maybe add a space at the end of this line that is used to
17052 display the cursor there under X. Set the charpos of the
17053 first glyph of blank lines not corresponding to any text
17055 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17056 row
->exact_window_width_line_p
= 1;
17057 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
17058 || row
->used
[TEXT_AREA
] == 0)
17060 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
17061 row
->displays_text_p
= 0;
17063 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
17064 && (!MINI_WINDOW_P (it
->w
)
17065 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
17066 row
->indicate_empty_line_p
= 1;
17069 it
->continuation_lines_width
= 0;
17070 row
->ends_at_zv_p
= 1;
17071 /* A row that displays right-to-left text must always have
17072 its last face extended all the way to the end of line,
17073 even if this row ends in ZV. */
17074 if (row
->reversed_p
)
17075 extend_face_to_end_of_line (it
);
17076 row_end
= it
->current
;
17080 /* Now, get the metrics of what we want to display. This also
17081 generates glyphs in `row' (which is IT->glyph_row). */
17082 n_glyphs_before
= row
->used
[TEXT_AREA
];
17085 /* Remember the line height so far in case the next element doesn't
17086 fit on the line. */
17087 if (it
->line_wrap
!= TRUNCATE
)
17089 ascent
= it
->max_ascent
;
17090 descent
= it
->max_descent
;
17091 phys_ascent
= it
->max_phys_ascent
;
17092 phys_descent
= it
->max_phys_descent
;
17094 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
17096 if (IT_DISPLAYING_WHITESPACE (it
))
17102 wrap_row_used
= row
->used
[TEXT_AREA
];
17103 wrap_row_ascent
= row
->ascent
;
17104 wrap_row_height
= row
->height
;
17105 wrap_row_phys_ascent
= row
->phys_ascent
;
17106 wrap_row_phys_height
= row
->phys_height
;
17107 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
17113 PRODUCE_GLYPHS (it
);
17115 /* If this display element was in marginal areas, continue with
17117 if (it
->area
!= TEXT_AREA
)
17119 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17120 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17121 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17122 row
->phys_height
= max (row
->phys_height
,
17123 it
->max_phys_ascent
+ it
->max_phys_descent
);
17124 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17125 it
->max_extra_line_spacing
);
17126 set_iterator_to_next (it
, 1);
17130 /* Does the display element fit on the line? If we truncate
17131 lines, we should draw past the right edge of the window. If
17132 we don't truncate, we want to stop so that we can display the
17133 continuation glyph before the right margin. If lines are
17134 continued, there are two possible strategies for characters
17135 resulting in more than 1 glyph (e.g. tabs): Display as many
17136 glyphs as possible in this line and leave the rest for the
17137 continuation line, or display the whole element in the next
17138 line. Original redisplay did the former, so we do it also. */
17139 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
17140 hpos_before
= it
->hpos
;
17143 if (/* Not a newline. */
17145 /* Glyphs produced fit entirely in the line. */
17146 && it
->current_x
< it
->last_visible_x
)
17148 it
->hpos
+= nglyphs
;
17149 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17150 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17151 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17152 row
->phys_height
= max (row
->phys_height
,
17153 it
->max_phys_ascent
+ it
->max_phys_descent
);
17154 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17155 it
->max_extra_line_spacing
);
17156 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
17157 row
->x
= x
- it
->first_visible_x
;
17162 struct glyph
*glyph
;
17164 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
17166 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
17167 new_x
= x
+ glyph
->pixel_width
;
17169 if (/* Lines are continued. */
17170 it
->line_wrap
!= TRUNCATE
17171 && (/* Glyph doesn't fit on the line. */
17172 new_x
> it
->last_visible_x
17173 /* Or it fits exactly on a window system frame. */
17174 || (new_x
== it
->last_visible_x
17175 && FRAME_WINDOW_P (it
->f
))))
17177 /* End of a continued line. */
17180 || (new_x
== it
->last_visible_x
17181 && FRAME_WINDOW_P (it
->f
)))
17183 /* Current glyph is the only one on the line or
17184 fits exactly on the line. We must continue
17185 the line because we can't draw the cursor
17186 after the glyph. */
17187 row
->continued_p
= 1;
17188 it
->current_x
= new_x
;
17189 it
->continuation_lines_width
+= new_x
;
17191 if (i
== nglyphs
- 1)
17193 /* If line-wrap is on, check if a previous
17194 wrap point was found. */
17195 if (wrap_row_used
> 0
17196 /* Even if there is a previous wrap
17197 point, continue the line here as
17198 usual, if (i) the previous character
17199 was a space or tab AND (ii) the
17200 current character is not. */
17202 || IT_DISPLAYING_WHITESPACE (it
)))
17205 set_iterator_to_next (it
, 1);
17206 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17208 if (!get_next_display_element (it
))
17210 row
->exact_window_width_line_p
= 1;
17211 it
->continuation_lines_width
= 0;
17212 row
->continued_p
= 0;
17213 row
->ends_at_zv_p
= 1;
17215 else if (ITERATOR_AT_END_OF_LINE_P (it
))
17217 row
->continued_p
= 0;
17218 row
->exact_window_width_line_p
= 1;
17223 else if (CHAR_GLYPH_PADDING_P (*glyph
)
17224 && !FRAME_WINDOW_P (it
->f
))
17226 /* A padding glyph that doesn't fit on this line.
17227 This means the whole character doesn't fit
17229 row
->used
[TEXT_AREA
] = n_glyphs_before
;
17231 /* Fill the rest of the row with continuation
17232 glyphs like in 20.x. */
17233 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
17234 < row
->glyphs
[1 + TEXT_AREA
])
17235 produce_special_glyphs (it
, IT_CONTINUATION
);
17237 row
->continued_p
= 1;
17238 it
->current_x
= x_before
;
17239 it
->continuation_lines_width
+= x_before
;
17241 /* Restore the height to what it was before the
17242 element not fitting on the line. */
17243 it
->max_ascent
= ascent
;
17244 it
->max_descent
= descent
;
17245 it
->max_phys_ascent
= phys_ascent
;
17246 it
->max_phys_descent
= phys_descent
;
17248 else if (wrap_row_used
> 0)
17252 it
->continuation_lines_width
+= wrap_x
;
17253 row
->used
[TEXT_AREA
] = wrap_row_used
;
17254 row
->ascent
= wrap_row_ascent
;
17255 row
->height
= wrap_row_height
;
17256 row
->phys_ascent
= wrap_row_phys_ascent
;
17257 row
->phys_height
= wrap_row_phys_height
;
17258 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
17259 row
->continued_p
= 1;
17260 row
->ends_at_zv_p
= 0;
17261 row
->exact_window_width_line_p
= 0;
17262 it
->continuation_lines_width
+= x
;
17264 /* Make sure that a non-default face is extended
17265 up to the right margin of the window. */
17266 extend_face_to_end_of_line (it
);
17268 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
17270 /* A TAB that extends past the right edge of the
17271 window. This produces a single glyph on
17272 window system frames. We leave the glyph in
17273 this row and let it fill the row, but don't
17274 consume the TAB. */
17275 it
->continuation_lines_width
+= it
->last_visible_x
;
17276 row
->ends_in_middle_of_char_p
= 1;
17277 row
->continued_p
= 1;
17278 glyph
->pixel_width
= it
->last_visible_x
- x
;
17279 it
->starts_in_middle_of_char_p
= 1;
17283 /* Something other than a TAB that draws past
17284 the right edge of the window. Restore
17285 positions to values before the element. */
17286 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
17288 /* Display continuation glyphs. */
17289 if (!FRAME_WINDOW_P (it
->f
))
17290 produce_special_glyphs (it
, IT_CONTINUATION
);
17291 row
->continued_p
= 1;
17293 it
->current_x
= x_before
;
17294 it
->continuation_lines_width
+= x
;
17295 extend_face_to_end_of_line (it
);
17297 if (nglyphs
> 1 && i
> 0)
17299 row
->ends_in_middle_of_char_p
= 1;
17300 it
->starts_in_middle_of_char_p
= 1;
17303 /* Restore the height to what it was before the
17304 element not fitting on the line. */
17305 it
->max_ascent
= ascent
;
17306 it
->max_descent
= descent
;
17307 it
->max_phys_ascent
= phys_ascent
;
17308 it
->max_phys_descent
= phys_descent
;
17311 row_end
= it
->current
;
17314 else if (new_x
> it
->first_visible_x
)
17316 /* Increment number of glyphs actually displayed. */
17319 if (x
< it
->first_visible_x
)
17320 /* Glyph is partially visible, i.e. row starts at
17321 negative X position. */
17322 row
->x
= x
- it
->first_visible_x
;
17326 /* Glyph is completely off the left margin of the
17327 window. This should not happen because of the
17328 move_it_in_display_line at the start of this
17329 function, unless the text display area of the
17330 window is empty. */
17331 xassert (it
->first_visible_x
<= it
->last_visible_x
);
17335 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
17336 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
17337 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
17338 row
->phys_height
= max (row
->phys_height
,
17339 it
->max_phys_ascent
+ it
->max_phys_descent
);
17340 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
17341 it
->max_extra_line_spacing
);
17343 /* End of this display line if row is continued. */
17344 if (row
->continued_p
|| row
->ends_at_zv_p
)
17346 row_end
= it
->current
;
17352 /* Is this a line end? If yes, we're also done, after making
17353 sure that a non-default face is extended up to the right
17354 margin of the window. */
17355 if (ITERATOR_AT_END_OF_LINE_P (it
))
17357 int used_before
= row
->used
[TEXT_AREA
];
17359 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
17361 /* Add a space at the end of the line that is used to
17362 display the cursor there. */
17363 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17364 append_space_for_newline (it
, 0);
17366 /* Extend the face to the end of the line. */
17367 extend_face_to_end_of_line (it
);
17369 /* Make sure we have the position. */
17370 if (used_before
== 0)
17371 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
17373 /* Consume the line end. This skips over invisible lines. */
17376 /* When we are reordering bidi text, we still need the
17377 next character in logical order, to set row->end
17378 correctly below. */
17381 set_iterator_to_next (it
, 1);
17382 row_end
= it
->current
;
17386 set_iterator_to_next (it
, 1);
17387 it
->continuation_lines_width
= 0;
17389 row_end
= it
->current
;
17393 /* Proceed with next display element. Note that this skips
17394 over lines invisible because of selective display. */
17395 set_iterator_to_next (it
, 1);
17397 /* If we truncate lines, we are done when the last displayed
17398 glyphs reach past the right margin of the window. */
17399 if (it
->line_wrap
== TRUNCATE
17400 && (FRAME_WINDOW_P (it
->f
)
17401 ? (it
->current_x
>= it
->last_visible_x
)
17402 : (it
->current_x
> it
->last_visible_x
)))
17404 /* Maybe add truncation glyphs. */
17405 if (!FRAME_WINDOW_P (it
->f
))
17409 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
17410 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
17413 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
17415 row
->used
[TEXT_AREA
] = i
;
17416 produce_special_glyphs (it
, IT_TRUNCATION
);
17419 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
17421 /* Don't truncate if we can overflow newline into fringe. */
17422 if (!get_next_display_element (it
))
17424 it
->continuation_lines_width
= 0;
17425 row
->ends_at_zv_p
= 1;
17426 row
->exact_window_width_line_p
= 1;
17427 row_end
= it
->current
;
17430 if (ITERATOR_AT_END_OF_LINE_P (it
))
17432 row
->exact_window_width_line_p
= 1;
17433 goto at_end_of_line
;
17437 row
->truncated_on_right_p
= 1;
17438 it
->continuation_lines_width
= 0;
17439 reseat_at_next_visible_line_start (it
, 0);
17440 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
17441 it
->hpos
= hpos_before
;
17442 it
->current_x
= x_before
;
17443 row_end
= it
->current
;
17448 /* If line is not empty and hscrolled, maybe insert truncation glyphs
17449 at the left window margin. */
17450 if (it
->first_visible_x
17451 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
17453 if (!FRAME_WINDOW_P (it
->f
))
17454 insert_left_trunc_glyphs (it
);
17455 row
->truncated_on_left_p
= 1;
17458 /* If the start of this line is the overlay arrow-position, then
17459 mark this glyph row as the one containing the overlay arrow.
17460 This is clearly a mess with variable size fonts. It would be
17461 better to let it be displayed like cursors under X. */
17462 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
17463 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
17464 !NILP (overlay_arrow_string
)))
17466 /* Overlay arrow in window redisplay is a fringe bitmap. */
17467 if (STRINGP (overlay_arrow_string
))
17469 struct glyph_row
*arrow_row
17470 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17471 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17472 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17473 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17474 struct glyph
*p2
, *end
;
17476 /* Copy the arrow glyphs. */
17477 while (glyph
< arrow_end
)
17480 /* Throw away padding glyphs. */
17482 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17483 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17489 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17494 xassert (INTEGERP (overlay_arrow_string
));
17495 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17497 overlay_arrow_seen
= 1;
17500 /* Compute pixel dimensions of this line. */
17501 compute_line_metrics (it
);
17503 /* Remember the position at which this line ends. */
17504 row
->end
= row_end
;
17506 /* Record whether this row ends inside an ellipsis. */
17507 row
->ends_in_ellipsis_p
17508 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17509 && it
->ellipsis_p
);
17511 /* Save fringe bitmaps in this row. */
17512 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17513 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17514 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17515 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17517 it
->left_user_fringe_bitmap
= 0;
17518 it
->left_user_fringe_face_id
= 0;
17519 it
->right_user_fringe_bitmap
= 0;
17520 it
->right_user_fringe_face_id
= 0;
17522 /* Maybe set the cursor. */
17523 if (it
->w
->cursor
.vpos
< 0
17524 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17525 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17526 && cursor_row_p (it
->w
, row
))
17527 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17529 /* Highlight trailing whitespace. */
17530 if (!NILP (Vshow_trailing_whitespace
))
17531 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17533 /* Prepare for the next line. This line starts horizontally at (X
17534 HPOS) = (0 0). Vertical positions are incremented. As a
17535 convenience for the caller, IT->glyph_row is set to the next
17537 it
->current_x
= it
->hpos
= 0;
17538 it
->current_y
+= row
->height
;
17541 it
->start
= row_end
;
17542 return row
->displays_text_p
;
17547 /***********************************************************************
17549 ***********************************************************************/
17551 /* Redisplay the menu bar in the frame for window W.
17553 The menu bar of X frames that don't have X toolkit support is
17554 displayed in a special window W->frame->menu_bar_window.
17556 The menu bar of terminal frames is treated specially as far as
17557 glyph matrices are concerned. Menu bar lines are not part of
17558 windows, so the update is done directly on the frame matrix rows
17559 for the menu bar. */
17562 display_menu_bar (w
)
17565 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17570 /* Don't do all this for graphical frames. */
17572 if (FRAME_W32_P (f
))
17575 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17581 if (FRAME_NS_P (f
))
17583 #endif /* HAVE_NS */
17585 #ifdef USE_X_TOOLKIT
17586 xassert (!FRAME_WINDOW_P (f
));
17587 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17588 it
.first_visible_x
= 0;
17589 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17590 #else /* not USE_X_TOOLKIT */
17591 if (FRAME_WINDOW_P (f
))
17593 /* Menu bar lines are displayed in the desired matrix of the
17594 dummy window menu_bar_window. */
17595 struct window
*menu_w
;
17596 xassert (WINDOWP (f
->menu_bar_window
));
17597 menu_w
= XWINDOW (f
->menu_bar_window
);
17598 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17600 it
.first_visible_x
= 0;
17601 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17605 /* This is a TTY frame, i.e. character hpos/vpos are used as
17607 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17609 it
.first_visible_x
= 0;
17610 it
.last_visible_x
= FRAME_COLS (f
);
17612 #endif /* not USE_X_TOOLKIT */
17614 if (! mode_line_inverse_video
)
17615 /* Force the menu-bar to be displayed in the default face. */
17616 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17618 /* Clear all rows of the menu bar. */
17619 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17621 struct glyph_row
*row
= it
.glyph_row
+ i
;
17622 clear_glyph_row (row
);
17623 row
->enabled_p
= 1;
17624 row
->full_width_p
= 1;
17627 /* Display all items of the menu bar. */
17628 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17629 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17631 Lisp_Object string
;
17633 /* Stop at nil string. */
17634 string
= AREF (items
, i
+ 1);
17638 /* Remember where item was displayed. */
17639 ASET (items
, i
+ 3, make_number (it
.hpos
));
17641 /* Display the item, pad with one space. */
17642 if (it
.current_x
< it
.last_visible_x
)
17643 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17644 SCHARS (string
) + 1, 0, 0, -1);
17647 /* Fill out the line with spaces. */
17648 if (it
.current_x
< it
.last_visible_x
)
17649 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17651 /* Compute the total height of the lines. */
17652 compute_line_metrics (&it
);
17657 /***********************************************************************
17659 ***********************************************************************/
17661 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17662 FORCE is non-zero, redisplay mode lines unconditionally.
17663 Otherwise, redisplay only mode lines that are garbaged. Value is
17664 the number of windows whose mode lines were redisplayed. */
17667 redisplay_mode_lines (window
, force
)
17668 Lisp_Object window
;
17673 while (!NILP (window
))
17675 struct window
*w
= XWINDOW (window
);
17677 if (WINDOWP (w
->hchild
))
17678 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17679 else if (WINDOWP (w
->vchild
))
17680 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17682 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17683 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17685 struct text_pos lpoint
;
17686 struct buffer
*old
= current_buffer
;
17688 /* Set the window's buffer for the mode line display. */
17689 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17690 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17692 /* Point refers normally to the selected window. For any
17693 other window, set up appropriate value. */
17694 if (!EQ (window
, selected_window
))
17696 struct text_pos pt
;
17698 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17699 if (CHARPOS (pt
) < BEGV
)
17700 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17701 else if (CHARPOS (pt
) > (ZV
- 1))
17702 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17704 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17707 /* Display mode lines. */
17708 clear_glyph_matrix (w
->desired_matrix
);
17709 if (display_mode_lines (w
))
17712 w
->must_be_updated_p
= 1;
17715 /* Restore old settings. */
17716 set_buffer_internal_1 (old
);
17717 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17727 /* Display the mode and/or header line of window W. Value is the
17728 sum number of mode lines and header lines displayed. */
17731 display_mode_lines (w
)
17734 Lisp_Object old_selected_window
, old_selected_frame
;
17737 old_selected_frame
= selected_frame
;
17738 selected_frame
= w
->frame
;
17739 old_selected_window
= selected_window
;
17740 XSETWINDOW (selected_window
, w
);
17742 /* These will be set while the mode line specs are processed. */
17743 line_number_displayed
= 0;
17744 w
->column_number_displayed
= Qnil
;
17746 if (WINDOW_WANTS_MODELINE_P (w
))
17748 struct window
*sel_w
= XWINDOW (old_selected_window
);
17750 /* Select mode line face based on the real selected window. */
17751 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17752 current_buffer
->mode_line_format
);
17756 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17758 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17759 current_buffer
->header_line_format
);
17763 selected_frame
= old_selected_frame
;
17764 selected_window
= old_selected_window
;
17769 /* Display mode or header line of window W. FACE_ID specifies which
17770 line to display; it is either MODE_LINE_FACE_ID or
17771 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
17772 display. Value is the pixel height of the mode/header line
17776 display_mode_line (w
, face_id
, format
)
17778 enum face_id face_id
;
17779 Lisp_Object format
;
17783 int count
= SPECPDL_INDEX ();
17785 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17786 /* Don't extend on a previously drawn mode-line.
17787 This may happen if called from pos_visible_p. */
17788 it
.glyph_row
->enabled_p
= 0;
17789 prepare_desired_row (it
.glyph_row
);
17791 it
.glyph_row
->mode_line_p
= 1;
17793 if (! mode_line_inverse_video
)
17794 /* Force the mode-line to be displayed in the default face. */
17795 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17797 record_unwind_protect (unwind_format_mode_line
,
17798 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17800 mode_line_target
= MODE_LINE_DISPLAY
;
17802 /* Temporarily make frame's keyboard the current kboard so that
17803 kboard-local variables in the mode_line_format will get the right
17805 push_kboard (FRAME_KBOARD (it
.f
));
17806 record_unwind_save_match_data ();
17807 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17810 unbind_to (count
, Qnil
);
17812 /* Fill up with spaces. */
17813 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17815 compute_line_metrics (&it
);
17816 it
.glyph_row
->full_width_p
= 1;
17817 it
.glyph_row
->continued_p
= 0;
17818 it
.glyph_row
->truncated_on_left_p
= 0;
17819 it
.glyph_row
->truncated_on_right_p
= 0;
17821 /* Make a 3D mode-line have a shadow at its right end. */
17822 face
= FACE_FROM_ID (it
.f
, face_id
);
17823 extend_face_to_end_of_line (&it
);
17824 if (face
->box
!= FACE_NO_BOX
)
17826 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17827 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17828 last
->right_box_line_p
= 1;
17831 return it
.glyph_row
->height
;
17834 /* Move element ELT in LIST to the front of LIST.
17835 Return the updated list. */
17838 move_elt_to_front (elt
, list
)
17839 Lisp_Object elt
, list
;
17841 register Lisp_Object tail
, prev
;
17842 register Lisp_Object tem
;
17846 while (CONSP (tail
))
17852 /* Splice out the link TAIL. */
17854 list
= XCDR (tail
);
17856 Fsetcdr (prev
, XCDR (tail
));
17858 /* Now make it the first. */
17859 Fsetcdr (tail
, list
);
17864 tail
= XCDR (tail
);
17868 /* Not found--return unchanged LIST. */
17872 /* Contribute ELT to the mode line for window IT->w. How it
17873 translates into text depends on its data type.
17875 IT describes the display environment in which we display, as usual.
17877 DEPTH is the depth in recursion. It is used to prevent
17878 infinite recursion here.
17880 FIELD_WIDTH is the number of characters the display of ELT should
17881 occupy in the mode line, and PRECISION is the maximum number of
17882 characters to display from ELT's representation. See
17883 display_string for details.
17885 Returns the hpos of the end of the text generated by ELT.
17887 PROPS is a property list to add to any string we encounter.
17889 If RISKY is nonzero, remove (disregard) any properties in any string
17890 we encounter, and ignore :eval and :propertize.
17892 The global variable `mode_line_target' determines whether the
17893 output is passed to `store_mode_line_noprop',
17894 `store_mode_line_string', or `display_string'. */
17897 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17900 int field_width
, precision
;
17901 Lisp_Object elt
, props
;
17904 int n
= 0, field
, prec
;
17909 elt
= build_string ("*too-deep*");
17913 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17917 /* A string: output it and check for %-constructs within it. */
17921 if (SCHARS (elt
) > 0
17922 && (!NILP (props
) || risky
))
17924 Lisp_Object oprops
, aelt
;
17925 oprops
= Ftext_properties_at (make_number (0), elt
);
17927 /* If the starting string's properties are not what
17928 we want, translate the string. Also, if the string
17929 is risky, do that anyway. */
17931 if (NILP (Fequal (props
, oprops
)) || risky
)
17933 /* If the starting string has properties,
17934 merge the specified ones onto the existing ones. */
17935 if (! NILP (oprops
) && !risky
)
17939 oprops
= Fcopy_sequence (oprops
);
17941 while (CONSP (tem
))
17943 oprops
= Fplist_put (oprops
, XCAR (tem
),
17944 XCAR (XCDR (tem
)));
17945 tem
= XCDR (XCDR (tem
));
17950 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17951 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17953 /* AELT is what we want. Move it to the front
17954 without consing. */
17956 mode_line_proptrans_alist
17957 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17963 /* If AELT has the wrong props, it is useless.
17964 so get rid of it. */
17966 mode_line_proptrans_alist
17967 = Fdelq (aelt
, mode_line_proptrans_alist
);
17969 elt
= Fcopy_sequence (elt
);
17970 Fset_text_properties (make_number (0), Flength (elt
),
17972 /* Add this item to mode_line_proptrans_alist. */
17973 mode_line_proptrans_alist
17974 = Fcons (Fcons (elt
, props
),
17975 mode_line_proptrans_alist
);
17976 /* Truncate mode_line_proptrans_alist
17977 to at most 50 elements. */
17978 tem
= Fnthcdr (make_number (50),
17979 mode_line_proptrans_alist
);
17981 XSETCDR (tem
, Qnil
);
17990 prec
= precision
- n
;
17991 switch (mode_line_target
)
17993 case MODE_LINE_NOPROP
:
17994 case MODE_LINE_TITLE
:
17995 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17997 case MODE_LINE_STRING
:
17998 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
18000 case MODE_LINE_DISPLAY
:
18001 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
18002 0, prec
, 0, STRING_MULTIBYTE (elt
));
18009 /* Handle the non-literal case. */
18011 while ((precision
<= 0 || n
< precision
)
18012 && SREF (elt
, offset
) != 0
18013 && (mode_line_target
!= MODE_LINE_DISPLAY
18014 || it
->current_x
< it
->last_visible_x
))
18016 int last_offset
= offset
;
18018 /* Advance to end of string or next format specifier. */
18019 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
18022 if (offset
- 1 != last_offset
)
18024 int nchars
, nbytes
;
18026 /* Output to end of string or up to '%'. Field width
18027 is length of string. Don't output more than
18028 PRECISION allows us. */
18031 prec
= c_string_width (SDATA (elt
) + last_offset
,
18032 offset
- last_offset
, precision
- n
,
18035 switch (mode_line_target
)
18037 case MODE_LINE_NOPROP
:
18038 case MODE_LINE_TITLE
:
18039 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
18041 case MODE_LINE_STRING
:
18043 int bytepos
= last_offset
;
18044 int charpos
= string_byte_to_char (elt
, bytepos
);
18045 int endpos
= (precision
<= 0
18046 ? string_byte_to_char (elt
, offset
)
18047 : charpos
+ nchars
);
18049 n
+= store_mode_line_string (NULL
,
18050 Fsubstring (elt
, make_number (charpos
),
18051 make_number (endpos
)),
18055 case MODE_LINE_DISPLAY
:
18057 int bytepos
= last_offset
;
18058 int charpos
= string_byte_to_char (elt
, bytepos
);
18060 if (precision
<= 0)
18061 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
18062 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
18064 STRING_MULTIBYTE (elt
));
18069 else /* c == '%' */
18071 int percent_position
= offset
;
18073 /* Get the specified minimum width. Zero means
18076 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
18077 field
= field
* 10 + c
- '0';
18079 /* Don't pad beyond the total padding allowed. */
18080 if (field_width
- n
> 0 && field
> field_width
- n
)
18081 field
= field_width
- n
;
18083 /* Note that either PRECISION <= 0 or N < PRECISION. */
18084 prec
= precision
- n
;
18087 n
+= display_mode_element (it
, depth
, field
, prec
,
18088 Vglobal_mode_string
, props
,
18093 int bytepos
, charpos
;
18094 unsigned char *spec
;
18096 bytepos
= percent_position
;
18097 charpos
= (STRING_MULTIBYTE (elt
)
18098 ? string_byte_to_char (elt
, bytepos
)
18101 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
18103 switch (mode_line_target
)
18105 case MODE_LINE_NOPROP
:
18106 case MODE_LINE_TITLE
:
18107 n
+= store_mode_line_noprop (spec
, field
, prec
);
18109 case MODE_LINE_STRING
:
18111 int len
= strlen (spec
);
18112 Lisp_Object tem
= make_string (spec
, len
);
18113 props
= Ftext_properties_at (make_number (charpos
), elt
);
18114 /* Should only keep face property in props */
18115 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
18118 case MODE_LINE_DISPLAY
:
18120 int nglyphs_before
, nwritten
;
18122 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18123 nwritten
= display_string (spec
, Qnil
, elt
,
18128 /* Assign to the glyphs written above the
18129 string where the `%x' came from, position
18133 struct glyph
*glyph
18134 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
18138 for (i
= 0; i
< nwritten
; ++i
)
18140 glyph
[i
].object
= elt
;
18141 glyph
[i
].charpos
= charpos
;
18158 /* A symbol: process the value of the symbol recursively
18159 as if it appeared here directly. Avoid error if symbol void.
18160 Special case: if value of symbol is a string, output the string
18163 register Lisp_Object tem
;
18165 /* If the variable is not marked as risky to set
18166 then its contents are risky to use. */
18167 if (NILP (Fget (elt
, Qrisky_local_variable
)))
18170 tem
= Fboundp (elt
);
18173 tem
= Fsymbol_value (elt
);
18174 /* If value is a string, output that string literally:
18175 don't check for % within it. */
18179 if (!EQ (tem
, elt
))
18181 /* Give up right away for nil or t. */
18191 register Lisp_Object car
, tem
;
18193 /* A cons cell: five distinct cases.
18194 If first element is :eval or :propertize, do something special.
18195 If first element is a string or a cons, process all the elements
18196 and effectively concatenate them.
18197 If first element is a negative number, truncate displaying cdr to
18198 at most that many characters. If positive, pad (with spaces)
18199 to at least that many characters.
18200 If first element is a symbol, process the cadr or caddr recursively
18201 according to whether the symbol's value is non-nil or nil. */
18203 if (EQ (car
, QCeval
))
18205 /* An element of the form (:eval FORM) means evaluate FORM
18206 and use the result as mode line elements. */
18211 if (CONSP (XCDR (elt
)))
18214 spec
= safe_eval (XCAR (XCDR (elt
)));
18215 n
+= display_mode_element (it
, depth
, field_width
- n
,
18216 precision
- n
, spec
, props
,
18220 else if (EQ (car
, QCpropertize
))
18222 /* An element of the form (:propertize ELT PROPS...)
18223 means display ELT but applying properties PROPS. */
18228 if (CONSP (XCDR (elt
)))
18229 n
+= display_mode_element (it
, depth
, field_width
- n
,
18230 precision
- n
, XCAR (XCDR (elt
)),
18231 XCDR (XCDR (elt
)), risky
);
18233 else if (SYMBOLP (car
))
18235 tem
= Fboundp (car
);
18239 /* elt is now the cdr, and we know it is a cons cell.
18240 Use its car if CAR has a non-nil value. */
18243 tem
= Fsymbol_value (car
);
18250 /* Symbol's value is nil (or symbol is unbound)
18251 Get the cddr of the original list
18252 and if possible find the caddr and use that. */
18256 else if (!CONSP (elt
))
18261 else if (INTEGERP (car
))
18263 register int lim
= XINT (car
);
18267 /* Negative int means reduce maximum width. */
18268 if (precision
<= 0)
18271 precision
= min (precision
, -lim
);
18275 /* Padding specified. Don't let it be more than
18276 current maximum. */
18278 lim
= min (precision
, lim
);
18280 /* If that's more padding than already wanted, queue it.
18281 But don't reduce padding already specified even if
18282 that is beyond the current truncation point. */
18283 field_width
= max (lim
, field_width
);
18287 else if (STRINGP (car
) || CONSP (car
))
18289 Lisp_Object halftail
= elt
;
18293 && (precision
<= 0 || n
< precision
))
18295 n
+= display_mode_element (it
, depth
,
18296 /* Do padding only after the last
18297 element in the list. */
18298 (! CONSP (XCDR (elt
))
18301 precision
- n
, XCAR (elt
),
18305 if ((len
& 1) == 0)
18306 halftail
= XCDR (halftail
);
18307 /* Check for cycle. */
18308 if (EQ (halftail
, elt
))
18317 elt
= build_string ("*invalid*");
18321 /* Pad to FIELD_WIDTH. */
18322 if (field_width
> 0 && n
< field_width
)
18324 switch (mode_line_target
)
18326 case MODE_LINE_NOPROP
:
18327 case MODE_LINE_TITLE
:
18328 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
18330 case MODE_LINE_STRING
:
18331 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
18333 case MODE_LINE_DISPLAY
:
18334 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
18343 /* Store a mode-line string element in mode_line_string_list.
18345 If STRING is non-null, display that C string. Otherwise, the Lisp
18346 string LISP_STRING is displayed.
18348 FIELD_WIDTH is the minimum number of output glyphs to produce.
18349 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18350 with spaces. FIELD_WIDTH <= 0 means don't pad.
18352 PRECISION is the maximum number of characters to output from
18353 STRING. PRECISION <= 0 means don't truncate the string.
18355 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
18356 properties to the string.
18358 PROPS are the properties to add to the string.
18359 The mode_line_string_face face property is always added to the string.
18363 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
18365 Lisp_Object lisp_string
;
18374 if (string
!= NULL
)
18376 len
= strlen (string
);
18377 if (precision
> 0 && len
> precision
)
18379 lisp_string
= make_string (string
, len
);
18381 props
= mode_line_string_face_prop
;
18382 else if (!NILP (mode_line_string_face
))
18384 Lisp_Object face
= Fplist_get (props
, Qface
);
18385 props
= Fcopy_sequence (props
);
18387 face
= mode_line_string_face
;
18389 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18390 props
= Fplist_put (props
, Qface
, face
);
18392 Fadd_text_properties (make_number (0), make_number (len
),
18393 props
, lisp_string
);
18397 len
= XFASTINT (Flength (lisp_string
));
18398 if (precision
> 0 && len
> precision
)
18401 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
18404 if (!NILP (mode_line_string_face
))
18408 props
= Ftext_properties_at (make_number (0), lisp_string
);
18409 face
= Fplist_get (props
, Qface
);
18411 face
= mode_line_string_face
;
18413 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
18414 props
= Fcons (Qface
, Fcons (face
, Qnil
));
18416 lisp_string
= Fcopy_sequence (lisp_string
);
18419 Fadd_text_properties (make_number (0), make_number (len
),
18420 props
, lisp_string
);
18425 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18429 if (field_width
> len
)
18431 field_width
-= len
;
18432 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
18434 Fadd_text_properties (make_number (0), make_number (field_width
),
18435 props
, lisp_string
);
18436 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
18444 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
18446 doc
: /* Format a string out of a mode line format specification.
18447 First arg FORMAT specifies the mode line format (see `mode-line-format'
18448 for details) to use.
18450 Optional second arg FACE specifies the face property to put
18451 on all characters for which no face is specified.
18452 The value t means whatever face the window's mode line currently uses
18453 \(either `mode-line' or `mode-line-inactive', depending).
18454 A value of nil means the default is no face property.
18455 If FACE is an integer, the value string has no text properties.
18457 Optional third and fourth args WINDOW and BUFFER specify the window
18458 and buffer to use as the context for the formatting (defaults
18459 are the selected window and the window's buffer). */)
18460 (format
, face
, window
, buffer
)
18461 Lisp_Object format
, face
, window
, buffer
;
18466 struct buffer
*old_buffer
= NULL
;
18468 int no_props
= INTEGERP (face
);
18469 int count
= SPECPDL_INDEX ();
18471 int string_start
= 0;
18474 window
= selected_window
;
18475 CHECK_WINDOW (window
);
18476 w
= XWINDOW (window
);
18479 buffer
= w
->buffer
;
18480 CHECK_BUFFER (buffer
);
18482 /* Make formatting the modeline a non-op when noninteractive, otherwise
18483 there will be problems later caused by a partially initialized frame. */
18484 if (NILP (format
) || noninteractive
)
18485 return empty_unibyte_string
;
18493 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
18494 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
18498 face_id
= DEFAULT_FACE_ID
;
18500 if (XBUFFER (buffer
) != current_buffer
)
18501 old_buffer
= current_buffer
;
18503 /* Save things including mode_line_proptrans_alist,
18504 and set that to nil so that we don't alter the outer value. */
18505 record_unwind_protect (unwind_format_mode_line
,
18506 format_mode_line_unwind_data
18507 (old_buffer
, selected_window
, 1));
18508 mode_line_proptrans_alist
= Qnil
;
18510 Fselect_window (window
, Qt
);
18512 set_buffer_internal_1 (XBUFFER (buffer
));
18514 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18518 mode_line_target
= MODE_LINE_NOPROP
;
18519 mode_line_string_face_prop
= Qnil
;
18520 mode_line_string_list
= Qnil
;
18521 string_start
= MODE_LINE_NOPROP_LEN (0);
18525 mode_line_target
= MODE_LINE_STRING
;
18526 mode_line_string_list
= Qnil
;
18527 mode_line_string_face
= face
;
18528 mode_line_string_face_prop
18529 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18532 push_kboard (FRAME_KBOARD (it
.f
));
18533 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18538 len
= MODE_LINE_NOPROP_LEN (string_start
);
18539 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18543 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18544 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18545 empty_unibyte_string
);
18548 unbind_to (count
, Qnil
);
18552 /* Write a null-terminated, right justified decimal representation of
18553 the positive integer D to BUF using a minimal field width WIDTH. */
18556 pint2str (buf
, width
, d
)
18557 register char *buf
;
18558 register int width
;
18561 register char *p
= buf
;
18569 *p
++ = d
% 10 + '0';
18574 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18585 /* Write a null-terminated, right justified decimal and "human
18586 readable" representation of the nonnegative integer D to BUF using
18587 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18589 static const char power_letter
[] =
18603 pint2hrstr (buf
, width
, d
)
18608 /* We aim to represent the nonnegative integer D as
18609 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18612 /* -1 means: do not use TENTHS. */
18616 /* Length of QUOTIENT.TENTHS as a string. */
18622 if (1000 <= quotient
)
18624 /* Scale to the appropriate EXPONENT. */
18627 remainder
= quotient
% 1000;
18631 while (1000 <= quotient
);
18633 /* Round to nearest and decide whether to use TENTHS or not. */
18636 tenths
= remainder
/ 100;
18637 if (50 <= remainder
% 100)
18644 if (quotient
== 10)
18652 if (500 <= remainder
)
18654 if (quotient
< 999)
18665 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18666 if (tenths
== -1 && quotient
<= 99)
18673 p
= psuffix
= buf
+ max (width
, length
);
18675 /* Print EXPONENT. */
18677 *psuffix
++ = power_letter
[exponent
];
18680 /* Print TENTHS. */
18683 *--p
= '0' + tenths
;
18687 /* Print QUOTIENT. */
18690 int digit
= quotient
% 10;
18691 *--p
= '0' + digit
;
18693 while ((quotient
/= 10) != 0);
18695 /* Print leading spaces. */
18700 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18701 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18702 type of CODING_SYSTEM. Return updated pointer into BUF. */
18704 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18707 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18708 Lisp_Object coding_system
;
18709 register char *buf
;
18713 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18714 const unsigned char *eol_str
;
18716 /* The EOL conversion we are using. */
18717 Lisp_Object eoltype
;
18719 val
= CODING_SYSTEM_SPEC (coding_system
);
18722 if (!VECTORP (val
)) /* Not yet decided. */
18727 eoltype
= eol_mnemonic_undecided
;
18728 /* Don't mention EOL conversion if it isn't decided. */
18733 Lisp_Object eolvalue
;
18735 attrs
= AREF (val
, 0);
18736 eolvalue
= AREF (val
, 2);
18739 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18743 /* The EOL conversion that is normal on this system. */
18745 if (NILP (eolvalue
)) /* Not yet decided. */
18746 eoltype
= eol_mnemonic_undecided
;
18747 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18748 eoltype
= eol_mnemonic_undecided
;
18749 else /* eolvalue is Qunix, Qdos, or Qmac. */
18750 eoltype
= (EQ (eolvalue
, Qunix
)
18751 ? eol_mnemonic_unix
18752 : (EQ (eolvalue
, Qdos
) == 1
18753 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18759 /* Mention the EOL conversion if it is not the usual one. */
18760 if (STRINGP (eoltype
))
18762 eol_str
= SDATA (eoltype
);
18763 eol_str_len
= SBYTES (eoltype
);
18765 else if (CHARACTERP (eoltype
))
18767 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18768 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18773 eol_str
= invalid_eol_type
;
18774 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18776 bcopy (eol_str
, buf
, eol_str_len
);
18777 buf
+= eol_str_len
;
18783 /* Return a string for the output of a mode line %-spec for window W,
18784 generated by character C. PRECISION >= 0 means don't return a
18785 string longer than that value. FIELD_WIDTH > 0 means pad the
18786 string returned with spaces to that value. Return 1 in *MULTIBYTE
18787 if the result is multibyte text.
18789 Note we operate on the current buffer for most purposes,
18790 the exception being w->base_line_pos. */
18792 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18795 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
18798 int field_width
, precision
;
18802 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18803 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18804 struct buffer
*b
= current_buffer
;
18812 if (!NILP (b
->read_only
))
18814 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18819 /* This differs from %* only for a modified read-only buffer. */
18820 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18822 if (!NILP (b
->read_only
))
18827 /* This differs from %* in ignoring read-only-ness. */
18828 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18840 if (command_loop_level
> 5)
18842 p
= decode_mode_spec_buf
;
18843 for (i
= 0; i
< command_loop_level
; i
++)
18846 return decode_mode_spec_buf
;
18854 if (command_loop_level
> 5)
18856 p
= decode_mode_spec_buf
;
18857 for (i
= 0; i
< command_loop_level
; i
++)
18860 return decode_mode_spec_buf
;
18867 /* Let lots_of_dashes be a string of infinite length. */
18868 if (mode_line_target
== MODE_LINE_NOPROP
||
18869 mode_line_target
== MODE_LINE_STRING
)
18871 if (field_width
<= 0
18872 || field_width
> sizeof (lots_of_dashes
))
18874 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18875 decode_mode_spec_buf
[i
] = '-';
18876 decode_mode_spec_buf
[i
] = '\0';
18877 return decode_mode_spec_buf
;
18880 return lots_of_dashes
;
18888 /* %c and %l are ignored in `frame-title-format'.
18889 (In redisplay_internal, the frame title is drawn _before_ the
18890 windows are updated, so the stuff which depends on actual
18891 window contents (such as %l) may fail to render properly, or
18892 even crash emacs.) */
18893 if (mode_line_target
== MODE_LINE_TITLE
)
18897 int col
= (int) current_column (); /* iftc */
18898 w
->column_number_displayed
= make_number (col
);
18899 pint2str (decode_mode_spec_buf
, field_width
, col
);
18900 return decode_mode_spec_buf
;
18904 #ifndef SYSTEM_MALLOC
18906 if (NILP (Vmemory_full
))
18909 return "!MEM FULL! ";
18916 /* %F displays the frame name. */
18917 if (!NILP (f
->title
))
18918 return (char *) SDATA (f
->title
);
18919 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18920 return (char *) SDATA (f
->name
);
18929 int size
= ZV
- BEGV
;
18930 pint2str (decode_mode_spec_buf
, field_width
, size
);
18931 return decode_mode_spec_buf
;
18936 int size
= ZV
- BEGV
;
18937 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18938 return decode_mode_spec_buf
;
18943 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18944 int topline
, nlines
, junk
, height
;
18946 /* %c and %l are ignored in `frame-title-format'. */
18947 if (mode_line_target
== MODE_LINE_TITLE
)
18950 startpos
= XMARKER (w
->start
)->charpos
;
18951 startpos_byte
= marker_byte_position (w
->start
);
18952 height
= WINDOW_TOTAL_LINES (w
);
18954 /* If we decided that this buffer isn't suitable for line numbers,
18955 don't forget that too fast. */
18956 if (EQ (w
->base_line_pos
, w
->buffer
))
18958 /* But do forget it, if the window shows a different buffer now. */
18959 else if (BUFFERP (w
->base_line_pos
))
18960 w
->base_line_pos
= Qnil
;
18962 /* If the buffer is very big, don't waste time. */
18963 if (INTEGERP (Vline_number_display_limit
)
18964 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18966 w
->base_line_pos
= Qnil
;
18967 w
->base_line_number
= Qnil
;
18971 if (INTEGERP (w
->base_line_number
)
18972 && INTEGERP (w
->base_line_pos
)
18973 && XFASTINT (w
->base_line_pos
) <= startpos
)
18975 line
= XFASTINT (w
->base_line_number
);
18976 linepos
= XFASTINT (w
->base_line_pos
);
18977 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18982 linepos
= BUF_BEGV (b
);
18983 linepos_byte
= BUF_BEGV_BYTE (b
);
18986 /* Count lines from base line to window start position. */
18987 nlines
= display_count_lines (linepos
, linepos_byte
,
18991 topline
= nlines
+ line
;
18993 /* Determine a new base line, if the old one is too close
18994 or too far away, or if we did not have one.
18995 "Too close" means it's plausible a scroll-down would
18996 go back past it. */
18997 if (startpos
== BUF_BEGV (b
))
18999 w
->base_line_number
= make_number (topline
);
19000 w
->base_line_pos
= make_number (BUF_BEGV (b
));
19002 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
19003 || linepos
== BUF_BEGV (b
))
19005 int limit
= BUF_BEGV (b
);
19006 int limit_byte
= BUF_BEGV_BYTE (b
);
19008 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
19010 if (startpos
- distance
> limit
)
19012 limit
= startpos
- distance
;
19013 limit_byte
= CHAR_TO_BYTE (limit
);
19016 nlines
= display_count_lines (startpos
, startpos_byte
,
19018 - (height
* 2 + 30),
19020 /* If we couldn't find the lines we wanted within
19021 line_number_display_limit_width chars per line,
19022 give up on line numbers for this window. */
19023 if (position
== limit_byte
&& limit
== startpos
- distance
)
19025 w
->base_line_pos
= w
->buffer
;
19026 w
->base_line_number
= Qnil
;
19030 w
->base_line_number
= make_number (topline
- nlines
);
19031 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
19034 /* Now count lines from the start pos to point. */
19035 nlines
= display_count_lines (startpos
, startpos_byte
,
19036 PT_BYTE
, PT
, &junk
);
19038 /* Record that we did display the line number. */
19039 line_number_displayed
= 1;
19041 /* Make the string to show. */
19042 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
19043 return decode_mode_spec_buf
;
19046 char* p
= decode_mode_spec_buf
;
19047 int pad
= field_width
- 2;
19053 return decode_mode_spec_buf
;
19059 obj
= b
->mode_name
;
19063 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
19069 int pos
= marker_position (w
->start
);
19070 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19072 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
19074 if (pos
<= BUF_BEGV (b
))
19079 else if (pos
<= BUF_BEGV (b
))
19083 if (total
> 1000000)
19084 /* Do it differently for a large value, to avoid overflow. */
19085 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19087 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19088 /* We can't normally display a 3-digit number,
19089 so get us a 2-digit number that is close. */
19092 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19093 return decode_mode_spec_buf
;
19097 /* Display percentage of size above the bottom of the screen. */
19100 int toppos
= marker_position (w
->start
);
19101 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
19102 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
19104 if (botpos
>= BUF_ZV (b
))
19106 if (toppos
<= BUF_BEGV (b
))
19113 if (total
> 1000000)
19114 /* Do it differently for a large value, to avoid overflow. */
19115 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
19117 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
19118 /* We can't normally display a 3-digit number,
19119 so get us a 2-digit number that is close. */
19122 if (toppos
<= BUF_BEGV (b
))
19123 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
19125 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
19126 return decode_mode_spec_buf
;
19131 /* status of process */
19132 obj
= Fget_buffer_process (Fcurrent_buffer ());
19134 return "no process";
19135 #ifdef subprocesses
19136 obj
= Fsymbol_name (Fprocess_status (obj
));
19142 int count
= inhibit_garbage_collection ();
19143 Lisp_Object val
= call1 (intern ("file-remote-p"),
19144 current_buffer
->directory
);
19145 unbind_to (count
, Qnil
);
19153 case 't': /* indicate TEXT or BINARY */
19154 #ifdef MODE_LINE_BINARY_TEXT
19155 return MODE_LINE_BINARY_TEXT (b
);
19161 /* coding-system (not including end-of-line format) */
19163 /* coding-system (including end-of-line type) */
19165 int eol_flag
= (c
== 'Z');
19166 char *p
= decode_mode_spec_buf
;
19168 if (! FRAME_WINDOW_P (f
))
19170 /* No need to mention EOL here--the terminal never needs
19171 to do EOL conversion. */
19172 p
= decode_mode_spec_coding (CODING_ID_NAME
19173 (FRAME_KEYBOARD_CODING (f
)->id
),
19175 p
= decode_mode_spec_coding (CODING_ID_NAME
19176 (FRAME_TERMINAL_CODING (f
)->id
),
19179 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
19182 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
19183 #ifdef subprocesses
19184 obj
= Fget_buffer_process (Fcurrent_buffer ());
19185 if (PROCESSP (obj
))
19187 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
19189 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
19192 #endif /* subprocesses */
19195 return decode_mode_spec_buf
;
19201 *multibyte
= STRING_MULTIBYTE (obj
);
19202 return (char *) SDATA (obj
);
19209 /* Count up to COUNT lines starting from START / START_BYTE.
19210 But don't go beyond LIMIT_BYTE.
19211 Return the number of lines thus found (always nonnegative).
19213 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
19216 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
19217 int start
, start_byte
, limit_byte
, count
;
19220 register unsigned char *cursor
;
19221 unsigned char *base
;
19223 register int ceiling
;
19224 register unsigned char *ceiling_addr
;
19225 int orig_count
= count
;
19227 /* If we are not in selective display mode,
19228 check only for newlines. */
19229 int selective_display
= (!NILP (current_buffer
->selective_display
)
19230 && !INTEGERP (current_buffer
->selective_display
));
19234 while (start_byte
< limit_byte
)
19236 ceiling
= BUFFER_CEILING_OF (start_byte
);
19237 ceiling
= min (limit_byte
- 1, ceiling
);
19238 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
19239 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
19242 if (selective_display
)
19243 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
19246 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
19249 if (cursor
!= ceiling_addr
)
19253 start_byte
+= cursor
- base
+ 1;
19254 *byte_pos_ptr
= start_byte
;
19258 if (++cursor
== ceiling_addr
)
19264 start_byte
+= cursor
- base
;
19269 while (start_byte
> limit_byte
)
19271 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
19272 ceiling
= max (limit_byte
, ceiling
);
19273 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
19274 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
19277 if (selective_display
)
19278 while (--cursor
!= ceiling_addr
19279 && *cursor
!= '\n' && *cursor
!= 015)
19282 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
19285 if (cursor
!= ceiling_addr
)
19289 start_byte
+= cursor
- base
+ 1;
19290 *byte_pos_ptr
= start_byte
;
19291 /* When scanning backwards, we should
19292 not count the newline posterior to which we stop. */
19293 return - orig_count
- 1;
19299 /* Here we add 1 to compensate for the last decrement
19300 of CURSOR, which took it past the valid range. */
19301 start_byte
+= cursor
- base
+ 1;
19305 *byte_pos_ptr
= limit_byte
;
19308 return - orig_count
+ count
;
19309 return orig_count
- count
;
19315 /***********************************************************************
19317 ***********************************************************************/
19319 /* Display a NUL-terminated string, starting with index START.
19321 If STRING is non-null, display that C string. Otherwise, the Lisp
19322 string LISP_STRING is displayed.
19324 If FACE_STRING is not nil, FACE_STRING_POS is a position in
19325 FACE_STRING. Display STRING or LISP_STRING with the face at
19326 FACE_STRING_POS in FACE_STRING:
19328 Display the string in the environment given by IT, but use the
19329 standard display table, temporarily.
19331 FIELD_WIDTH is the minimum number of output glyphs to produce.
19332 If STRING has fewer characters than FIELD_WIDTH, pad to the right
19333 with spaces. If STRING has more characters, more than FIELD_WIDTH
19334 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
19336 PRECISION is the maximum number of characters to output from
19337 STRING. PRECISION < 0 means don't truncate the string.
19339 This is roughly equivalent to printf format specifiers:
19341 FIELD_WIDTH PRECISION PRINTF
19342 ----------------------------------------
19348 MULTIBYTE zero means do not display multibyte chars, > 0 means do
19349 display them, and < 0 means obey the current buffer's value of
19350 enable_multibyte_characters.
19352 Value is the number of columns displayed. */
19355 display_string (string
, lisp_string
, face_string
, face_string_pos
,
19356 start
, it
, field_width
, precision
, max_x
, multibyte
)
19357 unsigned char *string
;
19358 Lisp_Object lisp_string
;
19359 Lisp_Object face_string
;
19360 EMACS_INT face_string_pos
;
19363 int field_width
, precision
, max_x
;
19366 int hpos_at_start
= it
->hpos
;
19367 int saved_face_id
= it
->face_id
;
19368 struct glyph_row
*row
= it
->glyph_row
;
19370 /* Initialize the iterator IT for iteration over STRING beginning
19371 with index START. */
19372 reseat_to_string (it
, string
, lisp_string
, start
,
19373 precision
, field_width
, multibyte
);
19375 /* If displaying STRING, set up the face of the iterator
19376 from LISP_STRING, if that's given. */
19377 if (STRINGP (face_string
))
19383 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
19384 0, it
->region_beg_charpos
,
19385 it
->region_end_charpos
,
19386 &endptr
, it
->base_face_id
, 0);
19387 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19388 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
19391 /* Set max_x to the maximum allowed X position. Don't let it go
19392 beyond the right edge of the window. */
19394 max_x
= it
->last_visible_x
;
19396 max_x
= min (max_x
, it
->last_visible_x
);
19398 /* Skip over display elements that are not visible. because IT->w is
19400 if (it
->current_x
< it
->first_visible_x
)
19401 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
19402 MOVE_TO_POS
| MOVE_TO_X
);
19404 row
->ascent
= it
->max_ascent
;
19405 row
->height
= it
->max_ascent
+ it
->max_descent
;
19406 row
->phys_ascent
= it
->max_phys_ascent
;
19407 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19408 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19410 /* This condition is for the case that we are called with current_x
19411 past last_visible_x. */
19412 while (it
->current_x
< max_x
)
19414 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
19416 /* Get the next display element. */
19417 if (!get_next_display_element (it
))
19420 /* Produce glyphs. */
19421 x_before
= it
->current_x
;
19422 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
19423 PRODUCE_GLYPHS (it
);
19425 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
19428 while (i
< nglyphs
)
19430 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19432 if (it
->line_wrap
!= TRUNCATE
19433 && x
+ glyph
->pixel_width
> max_x
)
19435 /* End of continued line or max_x reached. */
19436 if (CHAR_GLYPH_PADDING_P (*glyph
))
19438 /* A wide character is unbreakable. */
19439 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19440 it
->current_x
= x_before
;
19444 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19449 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
19451 /* Glyph is at least partially visible. */
19453 if (x
< it
->first_visible_x
)
19454 it
->glyph_row
->x
= x
- it
->first_visible_x
;
19458 /* Glyph is off the left margin of the display area.
19459 Should not happen. */
19463 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19464 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19465 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19466 row
->phys_height
= max (row
->phys_height
,
19467 it
->max_phys_ascent
+ it
->max_phys_descent
);
19468 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19469 it
->max_extra_line_spacing
);
19470 x
+= glyph
->pixel_width
;
19474 /* Stop if max_x reached. */
19478 /* Stop at line ends. */
19479 if (ITERATOR_AT_END_OF_LINE_P (it
))
19481 it
->continuation_lines_width
= 0;
19485 set_iterator_to_next (it
, 1);
19487 /* Stop if truncating at the right edge. */
19488 if (it
->line_wrap
== TRUNCATE
19489 && it
->current_x
>= it
->last_visible_x
)
19491 /* Add truncation mark, but don't do it if the line is
19492 truncated at a padding space. */
19493 if (IT_CHARPOS (*it
) < it
->string_nchars
)
19495 if (!FRAME_WINDOW_P (it
->f
))
19499 if (it
->current_x
> it
->last_visible_x
)
19501 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19502 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19504 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19506 row
->used
[TEXT_AREA
] = i
;
19507 produce_special_glyphs (it
, IT_TRUNCATION
);
19510 produce_special_glyphs (it
, IT_TRUNCATION
);
19512 it
->glyph_row
->truncated_on_right_p
= 1;
19518 /* Maybe insert a truncation at the left. */
19519 if (it
->first_visible_x
19520 && IT_CHARPOS (*it
) > 0)
19522 if (!FRAME_WINDOW_P (it
->f
))
19523 insert_left_trunc_glyphs (it
);
19524 it
->glyph_row
->truncated_on_left_p
= 1;
19527 it
->face_id
= saved_face_id
;
19529 /* Value is number of columns displayed. */
19530 return it
->hpos
- hpos_at_start
;
19535 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19536 appears as an element of LIST or as the car of an element of LIST.
19537 If PROPVAL is a list, compare each element against LIST in that
19538 way, and return 1/2 if any element of PROPVAL is found in LIST.
19539 Otherwise return 0. This function cannot quit.
19540 The return value is 2 if the text is invisible but with an ellipsis
19541 and 1 if it's invisible and without an ellipsis. */
19544 invisible_p (propval
, list
)
19545 register Lisp_Object propval
;
19548 register Lisp_Object tail
, proptail
;
19550 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19552 register Lisp_Object tem
;
19554 if (EQ (propval
, tem
))
19556 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19557 return NILP (XCDR (tem
)) ? 1 : 2;
19560 if (CONSP (propval
))
19562 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19564 Lisp_Object propelt
;
19565 propelt
= XCAR (proptail
);
19566 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19568 register Lisp_Object tem
;
19570 if (EQ (propelt
, tem
))
19572 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19573 return NILP (XCDR (tem
)) ? 1 : 2;
19581 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19582 doc
: /* Non-nil if the property makes the text invisible.
19583 POS-OR-PROP can be a marker or number, in which case it is taken to be
19584 a position in the current buffer and the value of the `invisible' property
19585 is checked; or it can be some other value, which is then presumed to be the
19586 value of the `invisible' property of the text of interest.
19587 The non-nil value returned can be t for truly invisible text or something
19588 else if the text is replaced by an ellipsis. */)
19590 Lisp_Object pos_or_prop
;
19593 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19594 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19596 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19597 return (invis
== 0 ? Qnil
19599 : make_number (invis
));
19602 /* Calculate a width or height in pixels from a specification using
19603 the following elements:
19606 NUM - a (fractional) multiple of the default font width/height
19607 (NUM) - specifies exactly NUM pixels
19608 UNIT - a fixed number of pixels, see below.
19609 ELEMENT - size of a display element in pixels, see below.
19610 (NUM . SPEC) - equals NUM * SPEC
19611 (+ SPEC SPEC ...) - add pixel values
19612 (- SPEC SPEC ...) - subtract pixel values
19613 (- SPEC) - negate pixel value
19616 INT or FLOAT - a number constant
19617 SYMBOL - use symbol's (buffer local) variable binding.
19620 in - pixels per inch *)
19621 mm - pixels per 1/1000 meter *)
19622 cm - pixels per 1/100 meter *)
19623 width - width of current font in pixels.
19624 height - height of current font in pixels.
19626 *) using the ratio(s) defined in display-pixels-per-inch.
19630 left-fringe - left fringe width in pixels
19631 right-fringe - right fringe width in pixels
19633 left-margin - left margin width in pixels
19634 right-margin - right margin width in pixels
19636 scroll-bar - scroll-bar area width in pixels
19640 Pixels corresponding to 5 inches:
19643 Total width of non-text areas on left side of window (if scroll-bar is on left):
19644 '(space :width (+ left-fringe left-margin scroll-bar))
19646 Align to first text column (in header line):
19647 '(space :align-to 0)
19649 Align to middle of text area minus half the width of variable `my-image'
19650 containing a loaded image:
19651 '(space :align-to (0.5 . (- text my-image)))
19653 Width of left margin minus width of 1 character in the default font:
19654 '(space :width (- left-margin 1))
19656 Width of left margin minus width of 2 characters in the current font:
19657 '(space :width (- left-margin (2 . width)))
19659 Center 1 character over left-margin (in header line):
19660 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19662 Different ways to express width of left fringe plus left margin minus one pixel:
19663 '(space :width (- (+ left-fringe left-margin) (1)))
19664 '(space :width (+ left-fringe left-margin (- (1))))
19665 '(space :width (+ left-fringe left-margin (-1)))
19669 #define NUMVAL(X) \
19670 ((INTEGERP (X) || FLOATP (X)) \
19675 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19680 int width_p
, *align_to
;
19684 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19685 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19688 return OK_PIXELS (0);
19690 xassert (FRAME_LIVE_P (it
->f
));
19692 if (SYMBOLP (prop
))
19694 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19696 char *unit
= SDATA (SYMBOL_NAME (prop
));
19698 if (unit
[0] == 'i' && unit
[1] == 'n')
19700 else if (unit
[0] == 'm' && unit
[1] == 'm')
19702 else if (unit
[0] == 'c' && unit
[1] == 'm')
19709 #ifdef HAVE_WINDOW_SYSTEM
19710 if (FRAME_WINDOW_P (it
->f
)
19712 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19713 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19715 return OK_PIXELS (ppi
/ pixels
);
19718 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19719 || (CONSP (Vdisplay_pixels_per_inch
)
19721 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19722 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19724 return OK_PIXELS (ppi
/ pixels
);
19730 #ifdef HAVE_WINDOW_SYSTEM
19731 if (EQ (prop
, Qheight
))
19732 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19733 if (EQ (prop
, Qwidth
))
19734 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19736 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19737 return OK_PIXELS (1);
19740 if (EQ (prop
, Qtext
))
19741 return OK_PIXELS (width_p
19742 ? window_box_width (it
->w
, TEXT_AREA
)
19743 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19745 if (align_to
&& *align_to
< 0)
19748 if (EQ (prop
, Qleft
))
19749 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19750 if (EQ (prop
, Qright
))
19751 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19752 if (EQ (prop
, Qcenter
))
19753 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19754 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19755 if (EQ (prop
, Qleft_fringe
))
19756 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19757 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19758 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19759 if (EQ (prop
, Qright_fringe
))
19760 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19761 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19762 : window_box_right_offset (it
->w
, TEXT_AREA
));
19763 if (EQ (prop
, Qleft_margin
))
19764 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19765 if (EQ (prop
, Qright_margin
))
19766 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19767 if (EQ (prop
, Qscroll_bar
))
19768 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19770 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19771 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19772 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19777 if (EQ (prop
, Qleft_fringe
))
19778 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19779 if (EQ (prop
, Qright_fringe
))
19780 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19781 if (EQ (prop
, Qleft_margin
))
19782 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19783 if (EQ (prop
, Qright_margin
))
19784 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19785 if (EQ (prop
, Qscroll_bar
))
19786 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19789 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19792 if (INTEGERP (prop
) || FLOATP (prop
))
19794 int base_unit
= (width_p
19795 ? FRAME_COLUMN_WIDTH (it
->f
)
19796 : FRAME_LINE_HEIGHT (it
->f
));
19797 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19802 Lisp_Object car
= XCAR (prop
);
19803 Lisp_Object cdr
= XCDR (prop
);
19807 #ifdef HAVE_WINDOW_SYSTEM
19808 if (FRAME_WINDOW_P (it
->f
)
19809 && valid_image_p (prop
))
19811 int id
= lookup_image (it
->f
, prop
);
19812 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19814 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19817 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19823 while (CONSP (cdr
))
19825 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19826 font
, width_p
, align_to
))
19829 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19834 if (EQ (car
, Qminus
))
19836 return OK_PIXELS (pixels
);
19839 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19842 if (INTEGERP (car
) || FLOATP (car
))
19845 pixels
= XFLOATINT (car
);
19847 return OK_PIXELS (pixels
);
19848 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19849 font
, width_p
, align_to
))
19850 return OK_PIXELS (pixels
* fact
);
19861 /***********************************************************************
19863 ***********************************************************************/
19865 #ifdef HAVE_WINDOW_SYSTEM
19870 dump_glyph_string (s
)
19871 struct glyph_string
*s
;
19873 fprintf (stderr
, "glyph string\n");
19874 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19875 s
->x
, s
->y
, s
->width
, s
->height
);
19876 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19877 fprintf (stderr
, " hl = %d\n", s
->hl
);
19878 fprintf (stderr
, " left overhang = %d, right = %d\n",
19879 s
->left_overhang
, s
->right_overhang
);
19880 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19881 fprintf (stderr
, " extends to end of line = %d\n",
19882 s
->extends_to_end_of_line_p
);
19883 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19884 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19887 #endif /* GLYPH_DEBUG */
19889 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19890 of XChar2b structures for S; it can't be allocated in
19891 init_glyph_string because it must be allocated via `alloca'. W
19892 is the window on which S is drawn. ROW and AREA are the glyph row
19893 and area within the row from which S is constructed. START is the
19894 index of the first glyph structure covered by S. HL is a
19895 face-override for drawing S. */
19898 #define OPTIONAL_HDC(hdc) hdc,
19899 #define DECLARE_HDC(hdc) HDC hdc;
19900 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19901 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19904 #ifndef OPTIONAL_HDC
19905 #define OPTIONAL_HDC(hdc)
19906 #define DECLARE_HDC(hdc)
19907 #define ALLOCATE_HDC(hdc, f)
19908 #define RELEASE_HDC(hdc, f)
19912 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19913 struct glyph_string
*s
;
19917 struct glyph_row
*row
;
19918 enum glyph_row_area area
;
19920 enum draw_glyphs_face hl
;
19922 bzero (s
, sizeof *s
);
19924 s
->f
= XFRAME (w
->frame
);
19928 s
->display
= FRAME_X_DISPLAY (s
->f
);
19929 s
->window
= FRAME_X_WINDOW (s
->f
);
19930 s
->char2b
= char2b
;
19934 s
->first_glyph
= row
->glyphs
[area
] + start
;
19935 s
->height
= row
->height
;
19936 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19937 s
->ybase
= s
->y
+ row
->ascent
;
19941 /* Append the list of glyph strings with head H and tail T to the list
19942 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19945 append_glyph_string_lists (head
, tail
, h
, t
)
19946 struct glyph_string
**head
, **tail
;
19947 struct glyph_string
*h
, *t
;
19961 /* Prepend the list of glyph strings with head H and tail T to the
19962 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19966 prepend_glyph_string_lists (head
, tail
, h
, t
)
19967 struct glyph_string
**head
, **tail
;
19968 struct glyph_string
*h
, *t
;
19982 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19983 Set *HEAD and *TAIL to the resulting list. */
19986 append_glyph_string (head
, tail
, s
)
19987 struct glyph_string
**head
, **tail
;
19988 struct glyph_string
*s
;
19990 s
->next
= s
->prev
= NULL
;
19991 append_glyph_string_lists (head
, tail
, s
, s
);
19995 /* Get face and two-byte form of character C in face FACE_ID on frame
19996 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19997 means we want to display multibyte text. DISPLAY_P non-zero means
19998 make sure that X resources for the face returned are allocated.
19999 Value is a pointer to a realized face that is ready for display if
20000 DISPLAY_P is non-zero. */
20002 static INLINE
struct face
*
20003 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
20007 int multibyte_p
, display_p
;
20009 struct face
*face
= FACE_FROM_ID (f
, face_id
);
20013 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
20015 if (code
!= FONT_INVALID_CODE
)
20016 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20018 STORE_XCHAR2B (char2b
, 0, 0);
20021 /* Make sure X resources of the face are allocated. */
20022 #ifdef HAVE_X_WINDOWS
20026 xassert (face
!= NULL
);
20027 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20034 /* Get face and two-byte form of character glyph GLYPH on frame F.
20035 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
20036 a pointer to a realized face that is ready for display. */
20038 static INLINE
struct face
*
20039 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
20041 struct glyph
*glyph
;
20047 xassert (glyph
->type
== CHAR_GLYPH
);
20048 face
= FACE_FROM_ID (f
, glyph
->face_id
);
20055 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
20057 if (code
!= FONT_INVALID_CODE
)
20058 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
20060 STORE_XCHAR2B (char2b
, 0, 0);
20063 /* Make sure X resources of the face are allocated. */
20064 xassert (face
!= NULL
);
20065 PREPARE_FACE_FOR_DISPLAY (f
, face
);
20070 /* Fill glyph string S with composition components specified by S->cmp.
20072 BASE_FACE is the base face of the composition.
20073 S->cmp_from is the index of the first component for S.
20075 OVERLAPS non-zero means S should draw the foreground only, and use
20076 its physical height for clipping. See also draw_glyphs.
20078 Value is the index of a component not in S. */
20081 fill_composite_glyph_string (s
, base_face
, overlaps
)
20082 struct glyph_string
*s
;
20083 struct face
*base_face
;
20087 /* For all glyphs of this composition, starting at the offset
20088 S->cmp_from, until we reach the end of the definition or encounter a
20089 glyph that requires the different face, add it to S. */
20094 s
->for_overlaps
= overlaps
;
20097 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
20099 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
20103 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
20106 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
20107 s
->char2b
+ i
, 1, 1);
20113 s
->font
= s
->face
->font
;
20115 else if (s
->face
!= face
)
20123 /* All glyph strings for the same composition has the same width,
20124 i.e. the width set for the first component of the composition. */
20125 s
->width
= s
->first_glyph
->pixel_width
;
20127 /* If the specified font could not be loaded, use the frame's
20128 default font, but record the fact that we couldn't load it in
20129 the glyph string so that we can draw rectangles for the
20130 characters of the glyph string. */
20131 if (s
->font
== NULL
)
20133 s
->font_not_found_p
= 1;
20134 s
->font
= FRAME_FONT (s
->f
);
20137 /* Adjust base line for subscript/superscript text. */
20138 s
->ybase
+= s
->first_glyph
->voffset
;
20140 /* This glyph string must always be drawn with 16-bit functions. */
20147 fill_gstring_glyph_string (s
, face_id
, start
, end
, overlaps
)
20148 struct glyph_string
*s
;
20150 int start
, end
, overlaps
;
20152 struct glyph
*glyph
, *last
;
20153 Lisp_Object lgstring
;
20156 s
->for_overlaps
= overlaps
;
20157 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20158 last
= s
->row
->glyphs
[s
->area
] + end
;
20159 s
->cmp_id
= glyph
->u
.cmp
.id
;
20160 s
->cmp_from
= glyph
->u
.cmp
.from
;
20161 s
->cmp_to
= glyph
->u
.cmp
.to
+ 1;
20162 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20163 lgstring
= composition_gstring_from_id (s
->cmp_id
);
20164 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
20166 while (glyph
< last
20167 && glyph
->u
.cmp
.automatic
20168 && glyph
->u
.cmp
.id
== s
->cmp_id
20169 && s
->cmp_to
== glyph
->u
.cmp
.from
)
20170 s
->cmp_to
= (glyph
++)->u
.cmp
.to
+ 1;
20172 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
20174 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
20175 unsigned code
= LGLYPH_CODE (lglyph
);
20177 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
20179 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
20180 return glyph
- s
->row
->glyphs
[s
->area
];
20184 /* Fill glyph string S from a sequence of character glyphs.
20186 FACE_ID is the face id of the string. START is the index of the
20187 first glyph to consider, END is the index of the last + 1.
20188 OVERLAPS non-zero means S should draw the foreground only, and use
20189 its physical height for clipping. See also draw_glyphs.
20191 Value is the index of the first glyph not in S. */
20194 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
20195 struct glyph_string
*s
;
20197 int start
, end
, overlaps
;
20199 struct glyph
*glyph
, *last
;
20201 int glyph_not_available_p
;
20203 xassert (s
->f
== XFRAME (s
->w
->frame
));
20204 xassert (s
->nchars
== 0);
20205 xassert (start
>= 0 && end
> start
);
20207 s
->for_overlaps
= overlaps
;
20208 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20209 last
= s
->row
->glyphs
[s
->area
] + end
;
20210 voffset
= glyph
->voffset
;
20211 s
->padding_p
= glyph
->padding_p
;
20212 glyph_not_available_p
= glyph
->glyph_not_available_p
;
20214 while (glyph
< last
20215 && glyph
->type
== CHAR_GLYPH
20216 && glyph
->voffset
== voffset
20217 /* Same face id implies same font, nowadays. */
20218 && glyph
->face_id
== face_id
20219 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
20223 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
20224 s
->char2b
+ s
->nchars
,
20226 s
->two_byte_p
= two_byte_p
;
20228 xassert (s
->nchars
<= end
- start
);
20229 s
->width
+= glyph
->pixel_width
;
20230 if (glyph
++->padding_p
!= s
->padding_p
)
20234 s
->font
= s
->face
->font
;
20236 /* If the specified font could not be loaded, use the frame's font,
20237 but record the fact that we couldn't load it in
20238 S->font_not_found_p so that we can draw rectangles for the
20239 characters of the glyph string. */
20240 if (s
->font
== NULL
|| glyph_not_available_p
)
20242 s
->font_not_found_p
= 1;
20243 s
->font
= FRAME_FONT (s
->f
);
20246 /* Adjust base line for subscript/superscript text. */
20247 s
->ybase
+= voffset
;
20249 xassert (s
->face
&& s
->face
->gc
);
20250 return glyph
- s
->row
->glyphs
[s
->area
];
20254 /* Fill glyph string S from image glyph S->first_glyph. */
20257 fill_image_glyph_string (s
)
20258 struct glyph_string
*s
;
20260 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
20261 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
20263 s
->slice
= s
->first_glyph
->slice
;
20264 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
20265 s
->font
= s
->face
->font
;
20266 s
->width
= s
->first_glyph
->pixel_width
;
20268 /* Adjust base line for subscript/superscript text. */
20269 s
->ybase
+= s
->first_glyph
->voffset
;
20273 /* Fill glyph string S from a sequence of stretch glyphs.
20275 ROW is the glyph row in which the glyphs are found, AREA is the
20276 area within the row. START is the index of the first glyph to
20277 consider, END is the index of the last + 1.
20279 Value is the index of the first glyph not in S. */
20282 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
20283 struct glyph_string
*s
;
20284 struct glyph_row
*row
;
20285 enum glyph_row_area area
;
20288 struct glyph
*glyph
, *last
;
20289 int voffset
, face_id
;
20291 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
20293 glyph
= s
->row
->glyphs
[s
->area
] + start
;
20294 last
= s
->row
->glyphs
[s
->area
] + end
;
20295 face_id
= glyph
->face_id
;
20296 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
20297 s
->font
= s
->face
->font
;
20298 s
->width
= glyph
->pixel_width
;
20300 voffset
= glyph
->voffset
;
20304 && glyph
->type
== STRETCH_GLYPH
20305 && glyph
->voffset
== voffset
20306 && glyph
->face_id
== face_id
);
20308 s
->width
+= glyph
->pixel_width
;
20310 /* Adjust base line for subscript/superscript text. */
20311 s
->ybase
+= voffset
;
20313 /* The case that face->gc == 0 is handled when drawing the glyph
20314 string by calling PREPARE_FACE_FOR_DISPLAY. */
20316 return glyph
- s
->row
->glyphs
[s
->area
];
20319 static struct font_metrics
*
20320 get_per_char_metric (f
, font
, char2b
)
20325 static struct font_metrics metrics
;
20326 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
20328 if (! font
|| code
== FONT_INVALID_CODE
)
20330 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
20335 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
20336 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
20337 assumed to be zero. */
20340 x_get_glyph_overhangs (glyph
, f
, left
, right
)
20341 struct glyph
*glyph
;
20345 *left
= *right
= 0;
20347 if (glyph
->type
== CHAR_GLYPH
)
20351 struct font_metrics
*pcm
;
20353 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
20354 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
20356 if (pcm
->rbearing
> pcm
->width
)
20357 *right
= pcm
->rbearing
- pcm
->width
;
20358 if (pcm
->lbearing
< 0)
20359 *left
= -pcm
->lbearing
;
20362 else if (glyph
->type
== COMPOSITE_GLYPH
)
20364 if (! glyph
->u
.cmp
.automatic
)
20366 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
20368 if (cmp
->rbearing
> cmp
->pixel_width
)
20369 *right
= cmp
->rbearing
- cmp
->pixel_width
;
20370 if (cmp
->lbearing
< 0)
20371 *left
= - cmp
->lbearing
;
20375 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
20376 struct font_metrics metrics
;
20378 composition_gstring_width (gstring
, glyph
->u
.cmp
.from
,
20379 glyph
->u
.cmp
.to
+ 1, &metrics
);
20380 if (metrics
.rbearing
> metrics
.width
)
20381 *right
= metrics
.rbearing
- metrics
.width
;
20382 if (metrics
.lbearing
< 0)
20383 *left
= - metrics
.lbearing
;
20389 /* Return the index of the first glyph preceding glyph string S that
20390 is overwritten by S because of S's left overhang. Value is -1
20391 if no glyphs are overwritten. */
20394 left_overwritten (s
)
20395 struct glyph_string
*s
;
20399 if (s
->left_overhang
)
20402 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20403 int first
= s
->first_glyph
- glyphs
;
20405 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
20406 x
-= glyphs
[i
].pixel_width
;
20417 /* Return the index of the first glyph preceding glyph string S that
20418 is overwriting S because of its right overhang. Value is -1 if no
20419 glyph in front of S overwrites S. */
20422 left_overwriting (s
)
20423 struct glyph_string
*s
;
20426 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20427 int first
= s
->first_glyph
- glyphs
;
20431 for (i
= first
- 1; i
>= 0; --i
)
20434 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20437 x
-= glyphs
[i
].pixel_width
;
20444 /* Return the index of the last glyph following glyph string S that is
20445 overwritten by S because of S's right overhang. Value is -1 if
20446 no such glyph is found. */
20449 right_overwritten (s
)
20450 struct glyph_string
*s
;
20454 if (s
->right_overhang
)
20457 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20458 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20459 int end
= s
->row
->used
[s
->area
];
20461 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
20462 x
+= glyphs
[i
].pixel_width
;
20471 /* Return the index of the last glyph following glyph string S that
20472 overwrites S because of its left overhang. Value is negative
20473 if no such glyph is found. */
20476 right_overwriting (s
)
20477 struct glyph_string
*s
;
20480 int end
= s
->row
->used
[s
->area
];
20481 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
20482 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
20486 for (i
= first
; i
< end
; ++i
)
20489 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
20492 x
+= glyphs
[i
].pixel_width
;
20499 /* Set background width of glyph string S. START is the index of the
20500 first glyph following S. LAST_X is the right-most x-position + 1
20501 in the drawing area. */
20504 set_glyph_string_background_width (s
, start
, last_x
)
20505 struct glyph_string
*s
;
20509 /* If the face of this glyph string has to be drawn to the end of
20510 the drawing area, set S->extends_to_end_of_line_p. */
20512 if (start
== s
->row
->used
[s
->area
]
20513 && s
->area
== TEXT_AREA
20514 && ((s
->row
->fill_line_p
20515 && (s
->hl
== DRAW_NORMAL_TEXT
20516 || s
->hl
== DRAW_IMAGE_RAISED
20517 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20518 || s
->hl
== DRAW_MOUSE_FACE
))
20519 s
->extends_to_end_of_line_p
= 1;
20521 /* If S extends its face to the end of the line, set its
20522 background_width to the distance to the right edge of the drawing
20524 if (s
->extends_to_end_of_line_p
)
20525 s
->background_width
= last_x
- s
->x
+ 1;
20527 s
->background_width
= s
->width
;
20531 /* Compute overhangs and x-positions for glyph string S and its
20532 predecessors, or successors. X is the starting x-position for S.
20533 BACKWARD_P non-zero means process predecessors. */
20536 compute_overhangs_and_x (s
, x
, backward_p
)
20537 struct glyph_string
*s
;
20545 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20546 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20556 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20557 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20567 /* The following macros are only called from draw_glyphs below.
20568 They reference the following parameters of that function directly:
20569 `w', `row', `area', and `overlap_p'
20570 as well as the following local variables:
20571 `s', `f', and `hdc' (in W32) */
20574 /* On W32, silently add local `hdc' variable to argument list of
20575 init_glyph_string. */
20576 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20577 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20579 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20580 init_glyph_string (s, char2b, w, row, area, start, hl)
20583 /* Add a glyph string for a stretch glyph to the list of strings
20584 between HEAD and TAIL. START is the index of the stretch glyph in
20585 row area AREA of glyph row ROW. END is the index of the last glyph
20586 in that glyph row area. X is the current output position assigned
20587 to the new glyph string constructed. HL overrides that face of the
20588 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20589 is the right-most x-position of the drawing area. */
20591 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20592 and below -- keep them on one line. */
20593 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20596 s = (struct glyph_string *) alloca (sizeof *s); \
20597 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20598 START = fill_stretch_glyph_string (s, row, area, START, END); \
20599 append_glyph_string (&HEAD, &TAIL, s); \
20605 /* Add a glyph string for an image glyph to the list of strings
20606 between HEAD and TAIL. START is the index of the image glyph in
20607 row area AREA of glyph row ROW. END is the index of the last glyph
20608 in that glyph row area. X is the current output position assigned
20609 to the new glyph string constructed. HL overrides that face of the
20610 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20611 is the right-most x-position of the drawing area. */
20613 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20616 s = (struct glyph_string *) alloca (sizeof *s); \
20617 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20618 fill_image_glyph_string (s); \
20619 append_glyph_string (&HEAD, &TAIL, s); \
20626 /* Add a glyph string for a sequence of character glyphs to the list
20627 of strings between HEAD and TAIL. START is the index of the first
20628 glyph in row area AREA of glyph row ROW that is part of the new
20629 glyph string. END is the index of the last glyph in that glyph row
20630 area. X is the current output position assigned to the new glyph
20631 string constructed. HL overrides that face of the glyph; e.g. it
20632 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20633 right-most x-position of the drawing area. */
20635 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20641 face_id = (row)->glyphs[area][START].face_id; \
20643 s = (struct glyph_string *) alloca (sizeof *s); \
20644 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20645 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20646 append_glyph_string (&HEAD, &TAIL, s); \
20648 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20653 /* Add a glyph string for a composite sequence to the list of strings
20654 between HEAD and TAIL. START is the index of the first glyph in
20655 row area AREA of glyph row ROW that is part of the new glyph
20656 string. END is the index of the last glyph in that glyph row area.
20657 X is the current output position assigned to the new glyph string
20658 constructed. HL overrides that face of the glyph; e.g. it is
20659 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20660 x-position of the drawing area. */
20662 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20664 int face_id = (row)->glyphs[area][START].face_id; \
20665 struct face *base_face = FACE_FROM_ID (f, face_id); \
20666 int cmp_id = (row)->glyphs[area][START].u.cmp.id; \
20667 struct composition *cmp = composition_table[cmp_id]; \
20669 struct glyph_string *first_s; \
20672 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20674 /* Make glyph_strings for each glyph sequence that is drawable by \
20675 the same face, and append them to HEAD/TAIL. */ \
20676 for (n = 0; n < cmp->glyph_len;) \
20678 s = (struct glyph_string *) alloca (sizeof *s); \
20679 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20680 append_glyph_string (&(HEAD), &(TAIL), s); \
20686 n = fill_composite_glyph_string (s, base_face, overlaps); \
20694 /* Add a glyph string for a glyph-string sequence to the list of strings
20695 between HEAD and TAIL. */
20697 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20701 Lisp_Object gstring; \
20703 face_id = (row)->glyphs[area][START].face_id; \
20704 gstring = (composition_gstring_from_id \
20705 ((row)->glyphs[area][START].u.cmp.id)); \
20706 s = (struct glyph_string *) alloca (sizeof *s); \
20707 char2b = (XChar2b *) alloca ((sizeof *char2b) \
20708 * LGSTRING_GLYPH_LEN (gstring)); \
20709 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20710 append_glyph_string (&(HEAD), &(TAIL), s); \
20712 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
20716 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20717 of AREA of glyph row ROW on window W between indices START and END.
20718 HL overrides the face for drawing glyph strings, e.g. it is
20719 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20720 x-positions of the drawing area.
20722 This is an ugly monster macro construct because we must use alloca
20723 to allocate glyph strings (because draw_glyphs can be called
20724 asynchronously). */
20726 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20729 HEAD = TAIL = NULL; \
20730 while (START < END) \
20732 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20733 switch (first_glyph->type) \
20736 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20740 case COMPOSITE_GLYPH: \
20741 if (first_glyph->u.cmp.automatic) \
20742 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
20745 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20749 case STRETCH_GLYPH: \
20750 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20754 case IMAGE_GLYPH: \
20755 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20765 set_glyph_string_background_width (s, START, LAST_X); \
20772 /* Draw glyphs between START and END in AREA of ROW on window W,
20773 starting at x-position X. X is relative to AREA in W. HL is a
20774 face-override with the following meaning:
20776 DRAW_NORMAL_TEXT draw normally
20777 DRAW_CURSOR draw in cursor face
20778 DRAW_MOUSE_FACE draw in mouse face.
20779 DRAW_INVERSE_VIDEO draw in mode line face
20780 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20781 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20783 If OVERLAPS is non-zero, draw only the foreground of characters and
20784 clip to the physical height of ROW. Non-zero value also defines
20785 the overlapping part to be drawn:
20787 OVERLAPS_PRED overlap with preceding rows
20788 OVERLAPS_SUCC overlap with succeeding rows
20789 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20790 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20792 Value is the x-position reached, relative to AREA of W. */
20795 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20798 struct glyph_row
*row
;
20799 enum glyph_row_area area
;
20800 EMACS_INT start
, end
;
20801 enum draw_glyphs_face hl
;
20804 struct glyph_string
*head
, *tail
;
20805 struct glyph_string
*s
;
20806 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20807 int i
, j
, x_reached
, last_x
, area_left
= 0;
20808 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20811 ALLOCATE_HDC (hdc
, f
);
20813 /* Let's rather be paranoid than getting a SEGV. */
20814 end
= min (end
, row
->used
[area
]);
20815 start
= max (0, start
);
20816 start
= min (end
, start
);
20818 /* Translate X to frame coordinates. Set last_x to the right
20819 end of the drawing area. */
20820 if (row
->full_width_p
)
20822 /* X is relative to the left edge of W, without scroll bars
20824 area_left
= WINDOW_LEFT_EDGE_X (w
);
20825 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20829 area_left
= window_box_left (w
, area
);
20830 last_x
= area_left
+ window_box_width (w
, area
);
20834 /* Build a doubly-linked list of glyph_string structures between
20835 head and tail from what we have to draw. Note that the macro
20836 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20837 the reason we use a separate variable `i'. */
20839 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20841 x_reached
= tail
->x
+ tail
->background_width
;
20845 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20846 the row, redraw some glyphs in front or following the glyph
20847 strings built above. */
20848 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20850 struct glyph_string
*h
, *t
;
20851 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20852 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20855 /* If mouse highlighting is on, we may need to draw adjacent
20856 glyphs using mouse-face highlighting. */
20857 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20859 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20861 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20862 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20864 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20866 check_mouse_face
= 1;
20867 mouse_beg_col
= (row
== mouse_beg_row
)
20868 ? dpyinfo
->mouse_face_beg_col
: 0;
20869 mouse_end_col
= (row
== mouse_end_row
)
20870 ? dpyinfo
->mouse_face_end_col
20871 : row
->used
[TEXT_AREA
];
20875 /* Compute overhangs for all glyph strings. */
20876 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20877 for (s
= head
; s
; s
= s
->next
)
20878 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20880 /* Prepend glyph strings for glyphs in front of the first glyph
20881 string that are overwritten because of the first glyph
20882 string's left overhang. The background of all strings
20883 prepended must be drawn because the first glyph string
20885 i
= left_overwritten (head
);
20888 enum draw_glyphs_face overlap_hl
;
20890 /* If this row contains mouse highlighting, attempt to draw
20891 the overlapped glyphs with the correct highlight. This
20892 code fails if the overlap encompasses more than one glyph
20893 and mouse-highlight spans only some of these glyphs.
20894 However, making it work perfectly involves a lot more
20895 code, and I don't know if the pathological case occurs in
20896 practice, so we'll stick to this for now. --- cyd */
20897 if (check_mouse_face
20898 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20899 overlap_hl
= DRAW_MOUSE_FACE
;
20901 overlap_hl
= DRAW_NORMAL_TEXT
;
20904 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20905 overlap_hl
, dummy_x
, last_x
);
20906 compute_overhangs_and_x (t
, head
->x
, 1);
20907 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20911 /* Prepend glyph strings for glyphs in front of the first glyph
20912 string that overwrite that glyph string because of their
20913 right overhang. For these strings, only the foreground must
20914 be drawn, because it draws over the glyph string at `head'.
20915 The background must not be drawn because this would overwrite
20916 right overhangs of preceding glyphs for which no glyph
20918 i
= left_overwriting (head
);
20921 enum draw_glyphs_face overlap_hl
;
20923 if (check_mouse_face
20924 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20925 overlap_hl
= DRAW_MOUSE_FACE
;
20927 overlap_hl
= DRAW_NORMAL_TEXT
;
20930 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20931 overlap_hl
, dummy_x
, last_x
);
20932 for (s
= h
; s
; s
= s
->next
)
20933 s
->background_filled_p
= 1;
20934 compute_overhangs_and_x (t
, head
->x
, 1);
20935 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20938 /* Append glyphs strings for glyphs following the last glyph
20939 string tail that are overwritten by tail. The background of
20940 these strings has to be drawn because tail's foreground draws
20942 i
= right_overwritten (tail
);
20945 enum draw_glyphs_face overlap_hl
;
20947 if (check_mouse_face
20948 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20949 overlap_hl
= DRAW_MOUSE_FACE
;
20951 overlap_hl
= DRAW_NORMAL_TEXT
;
20953 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20954 overlap_hl
, x
, last_x
);
20955 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20956 append_glyph_string_lists (&head
, &tail
, h
, t
);
20960 /* Append glyph strings for glyphs following the last glyph
20961 string tail that overwrite tail. The foreground of such
20962 glyphs has to be drawn because it writes into the background
20963 of tail. The background must not be drawn because it could
20964 paint over the foreground of following glyphs. */
20965 i
= right_overwriting (tail
);
20968 enum draw_glyphs_face overlap_hl
;
20969 if (check_mouse_face
20970 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20971 overlap_hl
= DRAW_MOUSE_FACE
;
20973 overlap_hl
= DRAW_NORMAL_TEXT
;
20976 i
++; /* We must include the Ith glyph. */
20977 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20978 overlap_hl
, x
, last_x
);
20979 for (s
= h
; s
; s
= s
->next
)
20980 s
->background_filled_p
= 1;
20981 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20982 append_glyph_string_lists (&head
, &tail
, h
, t
);
20984 if (clip_head
|| clip_tail
)
20985 for (s
= head
; s
; s
= s
->next
)
20987 s
->clip_head
= clip_head
;
20988 s
->clip_tail
= clip_tail
;
20992 /* Draw all strings. */
20993 for (s
= head
; s
; s
= s
->next
)
20994 FRAME_RIF (f
)->draw_glyph_string (s
);
20997 /* When focus a sole frame and move horizontally, this sets on_p to 0
20998 causing a failure to erase prev cursor position. */
20999 if (area
== TEXT_AREA
21000 && !row
->full_width_p
21001 /* When drawing overlapping rows, only the glyph strings'
21002 foreground is drawn, which doesn't erase a cursor
21006 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
21007 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
21008 : (tail
? tail
->x
+ tail
->background_width
: x
));
21012 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
21013 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
21017 /* Value is the x-position up to which drawn, relative to AREA of W.
21018 This doesn't include parts drawn because of overhangs. */
21019 if (row
->full_width_p
)
21020 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
21022 x_reached
-= area_left
;
21024 RELEASE_HDC (hdc
, f
);
21029 /* Expand row matrix if too narrow. Don't expand if area
21032 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
21034 if (!fonts_changed_p \
21035 && (it->glyph_row->glyphs[area] \
21036 < it->glyph_row->glyphs[area + 1])) \
21038 it->w->ncols_scale_factor++; \
21039 fonts_changed_p = 1; \
21043 /* Store one glyph for IT->char_to_display in IT->glyph_row.
21044 Called from x_produce_glyphs when IT->glyph_row is non-null. */
21050 struct glyph
*glyph
;
21051 enum glyph_row_area area
= it
->area
;
21053 xassert (it
->glyph_row
);
21054 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
21056 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21057 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21059 glyph
->charpos
= CHARPOS (it
->position
);
21060 glyph
->object
= it
->object
;
21061 if (it
->pixel_width
> 0)
21063 glyph
->pixel_width
= it
->pixel_width
;
21064 glyph
->padding_p
= 0;
21068 /* Assure at least 1-pixel width. Otherwise, cursor can't
21069 be displayed correctly. */
21070 glyph
->pixel_width
= 1;
21071 glyph
->padding_p
= 1;
21073 glyph
->ascent
= it
->ascent
;
21074 glyph
->descent
= it
->descent
;
21075 glyph
->voffset
= it
->voffset
;
21076 glyph
->type
= CHAR_GLYPH
;
21077 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21078 glyph
->multibyte_p
= it
->multibyte_p
;
21079 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21080 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21081 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21082 || it
->phys_descent
> it
->descent
);
21083 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
21084 glyph
->face_id
= it
->face_id
;
21085 glyph
->u
.ch
= it
->char_to_display
;
21086 glyph
->slice
= null_glyph_slice
;
21087 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21090 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21091 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21093 glyph
->bidi_type
= it
->bidi_it
.type
;
21095 ++it
->glyph_row
->used
[area
];
21098 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21101 /* Store one glyph for the composition IT->cmp_it.id in
21102 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
21106 append_composite_glyph (it
)
21109 struct glyph
*glyph
;
21110 enum glyph_row_area area
= it
->area
;
21112 xassert (it
->glyph_row
);
21114 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21115 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21117 glyph
->charpos
= CHARPOS (it
->position
);
21118 glyph
->object
= it
->object
;
21119 glyph
->pixel_width
= it
->pixel_width
;
21120 glyph
->ascent
= it
->ascent
;
21121 glyph
->descent
= it
->descent
;
21122 glyph
->voffset
= it
->voffset
;
21123 glyph
->type
= COMPOSITE_GLYPH
;
21124 if (it
->cmp_it
.ch
< 0)
21126 glyph
->u
.cmp
.automatic
= 0;
21127 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21131 glyph
->u
.cmp
.automatic
= 1;
21132 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
21133 glyph
->u
.cmp
.from
= it
->cmp_it
.from
;
21134 glyph
->u
.cmp
.to
= it
->cmp_it
.to
- 1;
21136 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21137 glyph
->multibyte_p
= it
->multibyte_p
;
21138 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21139 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21140 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
21141 || it
->phys_descent
> it
->descent
);
21142 glyph
->padding_p
= 0;
21143 glyph
->glyph_not_available_p
= 0;
21144 glyph
->face_id
= it
->face_id
;
21145 glyph
->slice
= null_glyph_slice
;
21146 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21149 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21150 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21152 glyph
->bidi_type
= it
->bidi_it
.type
;
21154 ++it
->glyph_row
->used
[area
];
21157 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21161 /* Change IT->ascent and IT->height according to the setting of
21165 take_vertical_position_into_account (it
)
21170 if (it
->voffset
< 0)
21171 /* Increase the ascent so that we can display the text higher
21173 it
->ascent
-= it
->voffset
;
21175 /* Increase the descent so that we can display the text lower
21177 it
->descent
+= it
->voffset
;
21182 /* Produce glyphs/get display metrics for the image IT is loaded with.
21183 See the description of struct display_iterator in dispextern.h for
21184 an overview of struct display_iterator. */
21187 produce_image_glyph (it
)
21192 int glyph_ascent
, crop
;
21193 struct glyph_slice slice
;
21195 xassert (it
->what
== IT_IMAGE
);
21197 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21199 /* Make sure X resources of the face is loaded. */
21200 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21202 if (it
->image_id
< 0)
21204 /* Fringe bitmap. */
21205 it
->ascent
= it
->phys_ascent
= 0;
21206 it
->descent
= it
->phys_descent
= 0;
21207 it
->pixel_width
= 0;
21212 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
21214 /* Make sure X resources of the image is loaded. */
21215 prepare_image_for_display (it
->f
, img
);
21217 slice
.x
= slice
.y
= 0;
21218 slice
.width
= img
->width
;
21219 slice
.height
= img
->height
;
21221 if (INTEGERP (it
->slice
.x
))
21222 slice
.x
= XINT (it
->slice
.x
);
21223 else if (FLOATP (it
->slice
.x
))
21224 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
21226 if (INTEGERP (it
->slice
.y
))
21227 slice
.y
= XINT (it
->slice
.y
);
21228 else if (FLOATP (it
->slice
.y
))
21229 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
21231 if (INTEGERP (it
->slice
.width
))
21232 slice
.width
= XINT (it
->slice
.width
);
21233 else if (FLOATP (it
->slice
.width
))
21234 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
21236 if (INTEGERP (it
->slice
.height
))
21237 slice
.height
= XINT (it
->slice
.height
);
21238 else if (FLOATP (it
->slice
.height
))
21239 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
21241 if (slice
.x
>= img
->width
)
21242 slice
.x
= img
->width
;
21243 if (slice
.y
>= img
->height
)
21244 slice
.y
= img
->height
;
21245 if (slice
.x
+ slice
.width
>= img
->width
)
21246 slice
.width
= img
->width
- slice
.x
;
21247 if (slice
.y
+ slice
.height
> img
->height
)
21248 slice
.height
= img
->height
- slice
.y
;
21250 if (slice
.width
== 0 || slice
.height
== 0)
21253 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
21255 it
->descent
= slice
.height
- glyph_ascent
;
21257 it
->descent
+= img
->vmargin
;
21258 if (slice
.y
+ slice
.height
== img
->height
)
21259 it
->descent
+= img
->vmargin
;
21260 it
->phys_descent
= it
->descent
;
21262 it
->pixel_width
= slice
.width
;
21264 it
->pixel_width
+= img
->hmargin
;
21265 if (slice
.x
+ slice
.width
== img
->width
)
21266 it
->pixel_width
+= img
->hmargin
;
21268 /* It's quite possible for images to have an ascent greater than
21269 their height, so don't get confused in that case. */
21270 if (it
->descent
< 0)
21275 if (face
->box
!= FACE_NO_BOX
)
21277 if (face
->box_line_width
> 0)
21280 it
->ascent
+= face
->box_line_width
;
21281 if (slice
.y
+ slice
.height
== img
->height
)
21282 it
->descent
+= face
->box_line_width
;
21285 if (it
->start_of_box_run_p
&& slice
.x
== 0)
21286 it
->pixel_width
+= eabs (face
->box_line_width
);
21287 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
21288 it
->pixel_width
+= eabs (face
->box_line_width
);
21291 take_vertical_position_into_account (it
);
21293 /* Automatically crop wide image glyphs at right edge so we can
21294 draw the cursor on same display row. */
21295 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
21296 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
21298 it
->pixel_width
-= crop
;
21299 slice
.width
-= crop
;
21304 struct glyph
*glyph
;
21305 enum glyph_row_area area
= it
->area
;
21307 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21308 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21310 glyph
->charpos
= CHARPOS (it
->position
);
21311 glyph
->object
= it
->object
;
21312 glyph
->pixel_width
= it
->pixel_width
;
21313 glyph
->ascent
= glyph_ascent
;
21314 glyph
->descent
= it
->descent
;
21315 glyph
->voffset
= it
->voffset
;
21316 glyph
->type
= IMAGE_GLYPH
;
21317 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21318 glyph
->multibyte_p
= it
->multibyte_p
;
21319 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21320 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21321 glyph
->overlaps_vertically_p
= 0;
21322 glyph
->padding_p
= 0;
21323 glyph
->glyph_not_available_p
= 0;
21324 glyph
->face_id
= it
->face_id
;
21325 glyph
->u
.img_id
= img
->id
;
21326 glyph
->slice
= slice
;
21327 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21330 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21331 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21333 glyph
->bidi_type
= it
->bidi_it
.type
;
21335 ++it
->glyph_row
->used
[area
];
21338 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21343 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
21344 of the glyph, WIDTH and HEIGHT are the width and height of the
21345 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
21348 append_stretch_glyph (it
, object
, width
, height
, ascent
)
21350 Lisp_Object object
;
21354 struct glyph
*glyph
;
21355 enum glyph_row_area area
= it
->area
;
21357 xassert (ascent
>= 0 && ascent
<= height
);
21359 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
21360 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
21362 glyph
->charpos
= CHARPOS (it
->position
);
21363 glyph
->object
= object
;
21364 glyph
->pixel_width
= width
;
21365 glyph
->ascent
= ascent
;
21366 glyph
->descent
= height
- ascent
;
21367 glyph
->voffset
= it
->voffset
;
21368 glyph
->type
= STRETCH_GLYPH
;
21369 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
21370 glyph
->multibyte_p
= it
->multibyte_p
;
21371 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
21372 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
21373 glyph
->overlaps_vertically_p
= 0;
21374 glyph
->padding_p
= 0;
21375 glyph
->glyph_not_available_p
= 0;
21376 glyph
->face_id
= it
->face_id
;
21377 glyph
->u
.stretch
.ascent
= ascent
;
21378 glyph
->u
.stretch
.height
= height
;
21379 glyph
->slice
= null_glyph_slice
;
21380 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
21383 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
21384 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
21386 glyph
->bidi_type
= it
->bidi_it
.type
;
21388 ++it
->glyph_row
->used
[area
];
21391 IT_EXPAND_MATRIX_WIDTH (it
, area
);
21395 /* Produce a stretch glyph for iterator IT. IT->object is the value
21396 of the glyph property displayed. The value must be a list
21397 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
21400 1. `:width WIDTH' specifies that the space should be WIDTH *
21401 canonical char width wide. WIDTH may be an integer or floating
21404 2. `:relative-width FACTOR' specifies that the width of the stretch
21405 should be computed from the width of the first character having the
21406 `glyph' property, and should be FACTOR times that width.
21408 3. `:align-to HPOS' specifies that the space should be wide enough
21409 to reach HPOS, a value in canonical character units.
21411 Exactly one of the above pairs must be present.
21413 4. `:height HEIGHT' specifies that the height of the stretch produced
21414 should be HEIGHT, measured in canonical character units.
21416 5. `:relative-height FACTOR' specifies that the height of the
21417 stretch should be FACTOR times the height of the characters having
21418 the glyph property.
21420 Either none or exactly one of 4 or 5 must be present.
21422 6. `:ascent ASCENT' specifies that ASCENT percent of the height
21423 of the stretch should be used for the ascent of the stretch.
21424 ASCENT must be in the range 0 <= ASCENT <= 100. */
21427 produce_stretch_glyph (it
)
21430 /* (space :width WIDTH :height HEIGHT ...) */
21431 Lisp_Object prop
, plist
;
21432 int width
= 0, height
= 0, align_to
= -1;
21433 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
21436 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21437 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
21439 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21441 /* List should start with `space'. */
21442 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
21443 plist
= XCDR (it
->object
);
21445 /* Compute the width of the stretch. */
21446 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
21447 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
21449 /* Absolute width `:width WIDTH' specified and valid. */
21450 zero_width_ok_p
= 1;
21453 else if (prop
= Fplist_get (plist
, QCrelative_width
),
21456 /* Relative width `:relative-width FACTOR' specified and valid.
21457 Compute the width of the characters having the `glyph'
21460 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
21463 if (it
->multibyte_p
)
21465 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
21466 - IT_BYTEPOS (*it
));
21467 it2
.c
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
21470 it2
.c
= *p
, it2
.len
= 1;
21472 it2
.glyph_row
= NULL
;
21473 it2
.what
= IT_CHARACTER
;
21474 x_produce_glyphs (&it2
);
21475 width
= NUMVAL (prop
) * it2
.pixel_width
;
21477 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
21478 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
21480 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
21481 align_to
= (align_to
< 0
21483 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
21484 else if (align_to
< 0)
21485 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
21486 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
21487 zero_width_ok_p
= 1;
21490 /* Nothing specified -> width defaults to canonical char width. */
21491 width
= FRAME_COLUMN_WIDTH (it
->f
);
21493 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
21496 /* Compute height. */
21497 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
21498 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21501 zero_height_ok_p
= 1;
21503 else if (prop
= Fplist_get (plist
, QCrelative_height
),
21505 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
21507 height
= FONT_HEIGHT (font
);
21509 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
21512 /* Compute percentage of height used for ascent. If
21513 `:ascent ASCENT' is present and valid, use that. Otherwise,
21514 derive the ascent from the font in use. */
21515 if (prop
= Fplist_get (plist
, QCascent
),
21516 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
21517 ascent
= height
* NUMVAL (prop
) / 100.0;
21518 else if (!NILP (prop
)
21519 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
21520 ascent
= min (max (0, (int)tem
), height
);
21522 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
21524 if (width
> 0 && it
->line_wrap
!= TRUNCATE
21525 && it
->current_x
+ width
> it
->last_visible_x
)
21526 width
= it
->last_visible_x
- it
->current_x
- 1;
21528 if (width
> 0 && height
> 0 && it
->glyph_row
)
21530 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
21531 if (!STRINGP (object
))
21532 object
= it
->w
->buffer
;
21533 append_stretch_glyph (it
, object
, width
, height
, ascent
);
21536 it
->pixel_width
= width
;
21537 it
->ascent
= it
->phys_ascent
= ascent
;
21538 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
21539 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
21541 take_vertical_position_into_account (it
);
21544 /* Calculate line-height and line-spacing properties.
21545 An integer value specifies explicit pixel value.
21546 A float value specifies relative value to current face height.
21547 A cons (float . face-name) specifies relative value to
21548 height of specified face font.
21550 Returns height in pixels, or nil. */
21554 calc_line_height_property (it
, val
, font
, boff
, override
)
21558 int boff
, override
;
21560 Lisp_Object face_name
= Qnil
;
21561 int ascent
, descent
, height
;
21563 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21568 face_name
= XCAR (val
);
21570 if (!NUMBERP (val
))
21571 val
= make_number (1);
21572 if (NILP (face_name
))
21574 height
= it
->ascent
+ it
->descent
;
21579 if (NILP (face_name
))
21581 font
= FRAME_FONT (it
->f
);
21582 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21584 else if (EQ (face_name
, Qt
))
21593 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21595 return make_number (-1);
21597 face
= FACE_FROM_ID (it
->f
, face_id
);
21600 return make_number (-1);
21601 boff
= font
->baseline_offset
;
21602 if (font
->vertical_centering
)
21603 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21606 ascent
= FONT_BASE (font
) + boff
;
21607 descent
= FONT_DESCENT (font
) - boff
;
21611 it
->override_ascent
= ascent
;
21612 it
->override_descent
= descent
;
21613 it
->override_boff
= boff
;
21616 height
= ascent
+ descent
;
21620 height
= (int)(XFLOAT_DATA (val
) * height
);
21621 else if (INTEGERP (val
))
21622 height
*= XINT (val
);
21624 return make_number (height
);
21629 Produce glyphs/get display metrics for the display element IT is
21630 loaded with. See the description of struct it in dispextern.h
21631 for an overview of struct it. */
21634 x_produce_glyphs (it
)
21637 int extra_line_spacing
= it
->extra_line_spacing
;
21639 it
->glyph_not_available_p
= 0;
21641 if (it
->what
== IT_CHARACTER
)
21645 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21646 struct font_metrics
*pcm
;
21647 int font_not_found_p
;
21648 int boff
; /* baseline offset */
21649 /* We may change it->multibyte_p upon unibyte<->multibyte
21650 conversion. So, save the current value now and restore it
21653 Note: It seems that we don't have to record multibyte_p in
21654 struct glyph because the character code itself tells whether
21655 or not the character is multibyte. Thus, in the future, we
21656 must consider eliminating the field `multibyte_p' in the
21658 int saved_multibyte_p
= it
->multibyte_p
;
21660 /* Maybe translate single-byte characters to multibyte, or the
21662 it
->char_to_display
= it
->c
;
21663 if (!ASCII_BYTE_P (it
->c
)
21664 && ! it
->multibyte_p
)
21666 if (SINGLE_BYTE_CHAR_P (it
->c
)
21667 && unibyte_display_via_language_environment
)
21669 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
21671 /* get_next_display_element assures that this decoding
21673 it
->char_to_display
= DECODE_CHAR (unibyte
, it
->c
);
21674 it
->multibyte_p
= 1;
21675 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21677 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21681 /* Get font to use. Encode IT->char_to_display. */
21682 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21683 &char2b
, it
->multibyte_p
, 0);
21686 font_not_found_p
= font
== NULL
;
21687 if (font_not_found_p
)
21689 /* When no suitable font found, display an empty box based
21690 on the metrics of the font of the default face (or what
21692 struct face
*no_font_face
21693 = FACE_FROM_ID (it
->f
,
21694 NILP (Vface_remapping_alist
) ? DEFAULT_FACE_ID
21695 : lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
21696 font
= no_font_face
->font
;
21697 boff
= font
->baseline_offset
;
21701 boff
= font
->baseline_offset
;
21702 if (font
->vertical_centering
)
21703 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21706 if (it
->char_to_display
>= ' '
21707 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21709 /* Either unibyte or ASCII. */
21714 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21716 if (it
->override_ascent
>= 0)
21718 it
->ascent
= it
->override_ascent
;
21719 it
->descent
= it
->override_descent
;
21720 boff
= it
->override_boff
;
21724 it
->ascent
= FONT_BASE (font
) + boff
;
21725 it
->descent
= FONT_DESCENT (font
) - boff
;
21730 it
->phys_ascent
= pcm
->ascent
+ boff
;
21731 it
->phys_descent
= pcm
->descent
- boff
;
21732 it
->pixel_width
= pcm
->width
;
21736 it
->glyph_not_available_p
= 1;
21737 it
->phys_ascent
= it
->ascent
;
21738 it
->phys_descent
= it
->descent
;
21739 it
->pixel_width
= FONT_WIDTH (font
);
21742 if (it
->constrain_row_ascent_descent_p
)
21744 if (it
->descent
> it
->max_descent
)
21746 it
->ascent
+= it
->descent
- it
->max_descent
;
21747 it
->descent
= it
->max_descent
;
21749 if (it
->ascent
> it
->max_ascent
)
21751 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21752 it
->ascent
= it
->max_ascent
;
21754 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21755 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21756 extra_line_spacing
= 0;
21759 /* If this is a space inside a region of text with
21760 `space-width' property, change its width. */
21761 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21763 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21765 /* If face has a box, add the box thickness to the character
21766 height. If character has a box line to the left and/or
21767 right, add the box line width to the character's width. */
21768 if (face
->box
!= FACE_NO_BOX
)
21770 int thick
= face
->box_line_width
;
21774 it
->ascent
+= thick
;
21775 it
->descent
+= thick
;
21780 if (it
->start_of_box_run_p
)
21781 it
->pixel_width
+= thick
;
21782 if (it
->end_of_box_run_p
)
21783 it
->pixel_width
+= thick
;
21786 /* If face has an overline, add the height of the overline
21787 (1 pixel) and a 1 pixel margin to the character height. */
21788 if (face
->overline_p
)
21789 it
->ascent
+= overline_margin
;
21791 if (it
->constrain_row_ascent_descent_p
)
21793 if (it
->ascent
> it
->max_ascent
)
21794 it
->ascent
= it
->max_ascent
;
21795 if (it
->descent
> it
->max_descent
)
21796 it
->descent
= it
->max_descent
;
21799 take_vertical_position_into_account (it
);
21801 /* If we have to actually produce glyphs, do it. */
21806 /* Translate a space with a `space-width' property
21807 into a stretch glyph. */
21808 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21809 / FONT_HEIGHT (font
));
21810 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21811 it
->ascent
+ it
->descent
, ascent
);
21816 /* If characters with lbearing or rbearing are displayed
21817 in this line, record that fact in a flag of the
21818 glyph row. This is used to optimize X output code. */
21819 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21820 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21822 if (! stretched_p
&& it
->pixel_width
== 0)
21823 /* We assure that all visible glyphs have at least 1-pixel
21825 it
->pixel_width
= 1;
21827 else if (it
->char_to_display
== '\n')
21829 /* A newline has no width, but we need the height of the
21830 line. But if previous part of the line sets a height,
21831 don't increase that height */
21833 Lisp_Object height
;
21834 Lisp_Object total_height
= Qnil
;
21836 it
->override_ascent
= -1;
21837 it
->pixel_width
= 0;
21840 height
= get_it_property(it
, Qline_height
);
21841 /* Split (line-height total-height) list */
21843 && CONSP (XCDR (height
))
21844 && NILP (XCDR (XCDR (height
))))
21846 total_height
= XCAR (XCDR (height
));
21847 height
= XCAR (height
);
21849 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21851 if (it
->override_ascent
>= 0)
21853 it
->ascent
= it
->override_ascent
;
21854 it
->descent
= it
->override_descent
;
21855 boff
= it
->override_boff
;
21859 it
->ascent
= FONT_BASE (font
) + boff
;
21860 it
->descent
= FONT_DESCENT (font
) - boff
;
21863 if (EQ (height
, Qt
))
21865 if (it
->descent
> it
->max_descent
)
21867 it
->ascent
+= it
->descent
- it
->max_descent
;
21868 it
->descent
= it
->max_descent
;
21870 if (it
->ascent
> it
->max_ascent
)
21872 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21873 it
->ascent
= it
->max_ascent
;
21875 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21876 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21877 it
->constrain_row_ascent_descent_p
= 1;
21878 extra_line_spacing
= 0;
21882 Lisp_Object spacing
;
21884 it
->phys_ascent
= it
->ascent
;
21885 it
->phys_descent
= it
->descent
;
21887 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21888 && face
->box
!= FACE_NO_BOX
21889 && face
->box_line_width
> 0)
21891 it
->ascent
+= face
->box_line_width
;
21892 it
->descent
+= face
->box_line_width
;
21895 && XINT (height
) > it
->ascent
+ it
->descent
)
21896 it
->ascent
= XINT (height
) - it
->descent
;
21898 if (!NILP (total_height
))
21899 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21902 spacing
= get_it_property(it
, Qline_spacing
);
21903 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21905 if (INTEGERP (spacing
))
21907 extra_line_spacing
= XINT (spacing
);
21908 if (!NILP (total_height
))
21909 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21913 else if (it
->char_to_display
== '\t')
21915 if (font
->space_width
> 0)
21917 int tab_width
= it
->tab_width
* font
->space_width
;
21918 int x
= it
->current_x
+ it
->continuation_lines_width
;
21919 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21921 /* If the distance from the current position to the next tab
21922 stop is less than a space character width, use the
21923 tab stop after that. */
21924 if (next_tab_x
- x
< font
->space_width
)
21925 next_tab_x
+= tab_width
;
21927 it
->pixel_width
= next_tab_x
- x
;
21929 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21930 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21934 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21935 it
->ascent
+ it
->descent
, it
->ascent
);
21940 it
->pixel_width
= 0;
21946 /* A multi-byte character. Assume that the display width of the
21947 character is the width of the character multiplied by the
21948 width of the font. */
21950 /* If we found a font, this font should give us the right
21951 metrics. If we didn't find a font, use the frame's
21952 default font and calculate the width of the character by
21953 multiplying the width of font by the width of the
21956 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21958 if (font_not_found_p
|| !pcm
)
21960 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21962 if (char_width
== 0)
21963 /* This is a non spacing character. But, as we are
21964 going to display an empty box, the box must occupy
21965 at least one column. */
21967 it
->glyph_not_available_p
= 1;
21968 it
->pixel_width
= font
->space_width
* char_width
;
21969 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21970 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21974 it
->pixel_width
= pcm
->width
;
21975 it
->phys_ascent
= pcm
->ascent
+ boff
;
21976 it
->phys_descent
= pcm
->descent
- boff
;
21978 && (pcm
->lbearing
< 0
21979 || pcm
->rbearing
> pcm
->width
))
21980 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21983 it
->ascent
= FONT_BASE (font
) + boff
;
21984 it
->descent
= FONT_DESCENT (font
) - boff
;
21985 if (face
->box
!= FACE_NO_BOX
)
21987 int thick
= face
->box_line_width
;
21991 it
->ascent
+= thick
;
21992 it
->descent
+= thick
;
21997 if (it
->start_of_box_run_p
)
21998 it
->pixel_width
+= thick
;
21999 if (it
->end_of_box_run_p
)
22000 it
->pixel_width
+= thick
;
22003 /* If face has an overline, add the height of the overline
22004 (1 pixel) and a 1 pixel margin to the character height. */
22005 if (face
->overline_p
)
22006 it
->ascent
+= overline_margin
;
22008 take_vertical_position_into_account (it
);
22010 if (it
->ascent
< 0)
22012 if (it
->descent
< 0)
22017 if (it
->pixel_width
== 0)
22018 /* We assure that all visible glyphs have at least 1-pixel
22020 it
->pixel_width
= 1;
22022 it
->multibyte_p
= saved_multibyte_p
;
22024 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
22026 /* A static composition.
22028 Note: A composition is represented as one glyph in the
22029 glyph matrix. There are no padding glyphs.
22031 Important note: pixel_width, ascent, and descent are the
22032 values of what is drawn by draw_glyphs (i.e. the values of
22033 the overall glyphs composed). */
22034 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22035 int boff
; /* baseline offset */
22036 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
22037 int glyph_len
= cmp
->glyph_len
;
22038 struct font
*font
= face
->font
;
22042 /* If we have not yet calculated pixel size data of glyphs of
22043 the composition for the current face font, calculate them
22044 now. Theoretically, we have to check all fonts for the
22045 glyphs, but that requires much time and memory space. So,
22046 here we check only the font of the first glyph. This may
22047 lead to incorrect display, but it's very rare, and C-l
22048 (recenter-top-bottom) can correct the display anyway. */
22049 if (! cmp
->font
|| cmp
->font
!= font
)
22051 /* Ascent and descent of the font of the first character
22052 of this composition (adjusted by baseline offset).
22053 Ascent and descent of overall glyphs should not be less
22054 than these, respectively. */
22055 int font_ascent
, font_descent
, font_height
;
22056 /* Bounding box of the overall glyphs. */
22057 int leftmost
, rightmost
, lowest
, highest
;
22058 int lbearing
, rbearing
;
22059 int i
, width
, ascent
, descent
;
22060 int left_padded
= 0, right_padded
= 0;
22063 struct font_metrics
*pcm
;
22064 int font_not_found_p
;
22067 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
22068 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
22070 if (glyph_len
< cmp
->glyph_len
)
22072 for (i
= 0; i
< glyph_len
; i
++)
22074 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
22076 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22081 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
22082 : IT_CHARPOS (*it
));
22083 /* If no suitable font is found, use the default font. */
22084 font_not_found_p
= font
== NULL
;
22085 if (font_not_found_p
)
22087 face
= face
->ascii_face
;
22090 boff
= font
->baseline_offset
;
22091 if (font
->vertical_centering
)
22092 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22093 font_ascent
= FONT_BASE (font
) + boff
;
22094 font_descent
= FONT_DESCENT (font
) - boff
;
22095 font_height
= FONT_HEIGHT (font
);
22097 cmp
->font
= (void *) font
;
22100 if (! font_not_found_p
)
22102 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
22103 &char2b
, it
->multibyte_p
, 0);
22104 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22107 /* Initialize the bounding box. */
22110 width
= pcm
->width
;
22111 ascent
= pcm
->ascent
;
22112 descent
= pcm
->descent
;
22113 lbearing
= pcm
->lbearing
;
22114 rbearing
= pcm
->rbearing
;
22118 width
= FONT_WIDTH (font
);
22119 ascent
= FONT_BASE (font
);
22120 descent
= FONT_DESCENT (font
);
22127 lowest
= - descent
+ boff
;
22128 highest
= ascent
+ boff
;
22130 if (! font_not_found_p
22131 && font
->default_ascent
22132 && CHAR_TABLE_P (Vuse_default_ascent
)
22133 && !NILP (Faref (Vuse_default_ascent
,
22134 make_number (it
->char_to_display
))))
22135 highest
= font
->default_ascent
+ boff
;
22137 /* Draw the first glyph at the normal position. It may be
22138 shifted to right later if some other glyphs are drawn
22140 cmp
->offsets
[i
* 2] = 0;
22141 cmp
->offsets
[i
* 2 + 1] = boff
;
22142 cmp
->lbearing
= lbearing
;
22143 cmp
->rbearing
= rbearing
;
22145 /* Set cmp->offsets for the remaining glyphs. */
22146 for (i
++; i
< glyph_len
; i
++)
22148 int left
, right
, btm
, top
;
22149 int ch
= COMPOSITION_GLYPH (cmp
, i
);
22151 struct face
*this_face
;
22156 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
22157 this_face
= FACE_FROM_ID (it
->f
, face_id
);
22158 font
= this_face
->font
;
22164 this_boff
= font
->baseline_offset
;
22165 if (font
->vertical_centering
)
22166 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
22167 get_char_face_and_encoding (it
->f
, ch
, face_id
,
22168 &char2b
, it
->multibyte_p
, 0);
22169 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
22172 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
22175 width
= pcm
->width
;
22176 ascent
= pcm
->ascent
;
22177 descent
= pcm
->descent
;
22178 lbearing
= pcm
->lbearing
;
22179 rbearing
= pcm
->rbearing
;
22180 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
22182 /* Relative composition with or without
22183 alternate chars. */
22184 left
= (leftmost
+ rightmost
- width
) / 2;
22185 btm
= - descent
+ boff
;
22186 if (font
->relative_compose
22187 && (! CHAR_TABLE_P (Vignore_relative_composition
)
22188 || NILP (Faref (Vignore_relative_composition
,
22189 make_number (ch
)))))
22192 if (- descent
>= font
->relative_compose
)
22193 /* One extra pixel between two glyphs. */
22195 else if (ascent
<= 0)
22196 /* One extra pixel between two glyphs. */
22197 btm
= lowest
- 1 - ascent
- descent
;
22202 /* A composition rule is specified by an integer
22203 value that encodes global and new reference
22204 points (GREF and NREF). GREF and NREF are
22205 specified by numbers as below:
22207 0---1---2 -- ascent
22211 9--10--11 -- center
22213 ---3---4---5--- baseline
22215 6---7---8 -- descent
22217 int rule
= COMPOSITION_RULE (cmp
, i
);
22218 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
22220 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
22221 grefx
= gref
% 3, nrefx
= nref
% 3;
22222 grefy
= gref
/ 3, nrefy
= nref
/ 3;
22224 xoff
= font_height
* (xoff
- 128) / 256;
22226 yoff
= font_height
* (yoff
- 128) / 256;
22229 + grefx
* (rightmost
- leftmost
) / 2
22230 - nrefx
* width
/ 2
22233 btm
= ((grefy
== 0 ? highest
22235 : grefy
== 2 ? lowest
22236 : (highest
+ lowest
) / 2)
22237 - (nrefy
== 0 ? ascent
+ descent
22238 : nrefy
== 1 ? descent
- boff
22240 : (ascent
+ descent
) / 2)
22244 cmp
->offsets
[i
* 2] = left
;
22245 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
22247 /* Update the bounding box of the overall glyphs. */
22250 right
= left
+ width
;
22251 if (left
< leftmost
)
22253 if (right
> rightmost
)
22256 top
= btm
+ descent
+ ascent
;
22262 if (cmp
->lbearing
> left
+ lbearing
)
22263 cmp
->lbearing
= left
+ lbearing
;
22264 if (cmp
->rbearing
< left
+ rbearing
)
22265 cmp
->rbearing
= left
+ rbearing
;
22269 /* If there are glyphs whose x-offsets are negative,
22270 shift all glyphs to the right and make all x-offsets
22274 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22275 cmp
->offsets
[i
* 2] -= leftmost
;
22276 rightmost
-= leftmost
;
22277 cmp
->lbearing
-= leftmost
;
22278 cmp
->rbearing
-= leftmost
;
22281 if (left_padded
&& cmp
->lbearing
< 0)
22283 for (i
= 0; i
< cmp
->glyph_len
; i
++)
22284 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
22285 rightmost
-= cmp
->lbearing
;
22286 cmp
->rbearing
-= cmp
->lbearing
;
22289 if (right_padded
&& rightmost
< cmp
->rbearing
)
22291 rightmost
= cmp
->rbearing
;
22294 cmp
->pixel_width
= rightmost
;
22295 cmp
->ascent
= highest
;
22296 cmp
->descent
= - lowest
;
22297 if (cmp
->ascent
< font_ascent
)
22298 cmp
->ascent
= font_ascent
;
22299 if (cmp
->descent
< font_descent
)
22300 cmp
->descent
= font_descent
;
22304 && (cmp
->lbearing
< 0
22305 || cmp
->rbearing
> cmp
->pixel_width
))
22306 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22308 it
->pixel_width
= cmp
->pixel_width
;
22309 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
22310 it
->descent
= it
->phys_descent
= cmp
->descent
;
22311 if (face
->box
!= FACE_NO_BOX
)
22313 int thick
= face
->box_line_width
;
22317 it
->ascent
+= thick
;
22318 it
->descent
+= thick
;
22323 if (it
->start_of_box_run_p
)
22324 it
->pixel_width
+= thick
;
22325 if (it
->end_of_box_run_p
)
22326 it
->pixel_width
+= thick
;
22329 /* If face has an overline, add the height of the overline
22330 (1 pixel) and a 1 pixel margin to the character height. */
22331 if (face
->overline_p
)
22332 it
->ascent
+= overline_margin
;
22334 take_vertical_position_into_account (it
);
22335 if (it
->ascent
< 0)
22337 if (it
->descent
< 0)
22341 append_composite_glyph (it
);
22343 else if (it
->what
== IT_COMPOSITION
)
22345 /* A dynamic (automatic) composition. */
22346 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22347 Lisp_Object gstring
;
22348 struct font_metrics metrics
;
22350 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
22352 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
22355 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
22356 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
22357 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
22358 it
->descent
= it
->phys_descent
= metrics
.descent
;
22359 if (face
->box
!= FACE_NO_BOX
)
22361 int thick
= face
->box_line_width
;
22365 it
->ascent
+= thick
;
22366 it
->descent
+= thick
;
22371 if (it
->start_of_box_run_p
)
22372 it
->pixel_width
+= thick
;
22373 if (it
->end_of_box_run_p
)
22374 it
->pixel_width
+= thick
;
22376 /* If face has an overline, add the height of the overline
22377 (1 pixel) and a 1 pixel margin to the character height. */
22378 if (face
->overline_p
)
22379 it
->ascent
+= overline_margin
;
22380 take_vertical_position_into_account (it
);
22381 if (it
->ascent
< 0)
22383 if (it
->descent
< 0)
22387 append_composite_glyph (it
);
22389 else if (it
->what
== IT_IMAGE
)
22390 produce_image_glyph (it
);
22391 else if (it
->what
== IT_STRETCH
)
22392 produce_stretch_glyph (it
);
22394 /* Accumulate dimensions. Note: can't assume that it->descent > 0
22395 because this isn't true for images with `:ascent 100'. */
22396 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
22397 if (it
->area
== TEXT_AREA
)
22398 it
->current_x
+= it
->pixel_width
;
22400 if (extra_line_spacing
> 0)
22402 it
->descent
+= extra_line_spacing
;
22403 if (extra_line_spacing
> it
->max_extra_line_spacing
)
22404 it
->max_extra_line_spacing
= extra_line_spacing
;
22407 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
22408 it
->max_descent
= max (it
->max_descent
, it
->descent
);
22409 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
22410 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
22414 Output LEN glyphs starting at START at the nominal cursor position.
22415 Advance the nominal cursor over the text. The global variable
22416 updated_window contains the window being updated, updated_row is
22417 the glyph row being updated, and updated_area is the area of that
22418 row being updated. */
22421 x_write_glyphs (start
, len
)
22422 struct glyph
*start
;
22427 xassert (updated_window
&& updated_row
);
22430 /* Write glyphs. */
22432 hpos
= start
- updated_row
->glyphs
[updated_area
];
22433 x
= draw_glyphs (updated_window
, output_cursor
.x
,
22434 updated_row
, updated_area
,
22436 DRAW_NORMAL_TEXT
, 0);
22438 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
22439 if (updated_area
== TEXT_AREA
22440 && updated_window
->phys_cursor_on_p
22441 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
22442 && updated_window
->phys_cursor
.hpos
>= hpos
22443 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
22444 updated_window
->phys_cursor_on_p
= 0;
22448 /* Advance the output cursor. */
22449 output_cursor
.hpos
+= len
;
22450 output_cursor
.x
= x
;
22455 Insert LEN glyphs from START at the nominal cursor position. */
22458 x_insert_glyphs (start
, len
)
22459 struct glyph
*start
;
22464 int line_height
, shift_by_width
, shifted_region_width
;
22465 struct glyph_row
*row
;
22466 struct glyph
*glyph
;
22467 int frame_x
, frame_y
;
22470 xassert (updated_window
&& updated_row
);
22472 w
= updated_window
;
22473 f
= XFRAME (WINDOW_FRAME (w
));
22475 /* Get the height of the line we are in. */
22477 line_height
= row
->height
;
22479 /* Get the width of the glyphs to insert. */
22480 shift_by_width
= 0;
22481 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
22482 shift_by_width
+= glyph
->pixel_width
;
22484 /* Get the width of the region to shift right. */
22485 shifted_region_width
= (window_box_width (w
, updated_area
)
22490 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
22491 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
22493 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
22494 line_height
, shift_by_width
);
22496 /* Write the glyphs. */
22497 hpos
= start
- row
->glyphs
[updated_area
];
22498 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
22500 DRAW_NORMAL_TEXT
, 0);
22502 /* Advance the output cursor. */
22503 output_cursor
.hpos
+= len
;
22504 output_cursor
.x
+= shift_by_width
;
22510 Erase the current text line from the nominal cursor position
22511 (inclusive) to pixel column TO_X (exclusive). The idea is that
22512 everything from TO_X onward is already erased.
22514 TO_X is a pixel position relative to updated_area of
22515 updated_window. TO_X == -1 means clear to the end of this area. */
22518 x_clear_end_of_line (to_x
)
22522 struct window
*w
= updated_window
;
22523 int max_x
, min_y
, max_y
;
22524 int from_x
, from_y
, to_y
;
22526 xassert (updated_window
&& updated_row
);
22527 f
= XFRAME (w
->frame
);
22529 if (updated_row
->full_width_p
)
22530 max_x
= WINDOW_TOTAL_WIDTH (w
);
22532 max_x
= window_box_width (w
, updated_area
);
22533 max_y
= window_text_bottom_y (w
);
22535 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
22536 of window. For TO_X > 0, truncate to end of drawing area. */
22542 to_x
= min (to_x
, max_x
);
22544 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
22546 /* Notice if the cursor will be cleared by this operation. */
22547 if (!updated_row
->full_width_p
)
22548 notice_overwritten_cursor (w
, updated_area
,
22549 output_cursor
.x
, -1,
22551 MATRIX_ROW_BOTTOM_Y (updated_row
));
22553 from_x
= output_cursor
.x
;
22555 /* Translate to frame coordinates. */
22556 if (updated_row
->full_width_p
)
22558 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
22559 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
22563 int area_left
= window_box_left (w
, updated_area
);
22564 from_x
+= area_left
;
22568 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
22569 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
22570 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
22572 /* Prevent inadvertently clearing to end of the X window. */
22573 if (to_x
> from_x
&& to_y
> from_y
)
22576 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
22577 to_x
- from_x
, to_y
- from_y
);
22582 #endif /* HAVE_WINDOW_SYSTEM */
22586 /***********************************************************************
22588 ***********************************************************************/
22590 /* Value is the internal representation of the specified cursor type
22591 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
22592 of the bar cursor. */
22594 static enum text_cursor_kinds
22595 get_specified_cursor_type (arg
, width
)
22599 enum text_cursor_kinds type
;
22604 if (EQ (arg
, Qbox
))
22605 return FILLED_BOX_CURSOR
;
22607 if (EQ (arg
, Qhollow
))
22608 return HOLLOW_BOX_CURSOR
;
22610 if (EQ (arg
, Qbar
))
22617 && EQ (XCAR (arg
), Qbar
)
22618 && INTEGERP (XCDR (arg
))
22619 && XINT (XCDR (arg
)) >= 0)
22621 *width
= XINT (XCDR (arg
));
22625 if (EQ (arg
, Qhbar
))
22628 return HBAR_CURSOR
;
22632 && EQ (XCAR (arg
), Qhbar
)
22633 && INTEGERP (XCDR (arg
))
22634 && XINT (XCDR (arg
)) >= 0)
22636 *width
= XINT (XCDR (arg
));
22637 return HBAR_CURSOR
;
22640 /* Treat anything unknown as "hollow box cursor".
22641 It was bad to signal an error; people have trouble fixing
22642 .Xdefaults with Emacs, when it has something bad in it. */
22643 type
= HOLLOW_BOX_CURSOR
;
22648 /* Set the default cursor types for specified frame. */
22650 set_frame_cursor_types (f
, arg
)
22657 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22658 FRAME_CURSOR_WIDTH (f
) = width
;
22660 /* By default, set up the blink-off state depending on the on-state. */
22662 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22665 FRAME_BLINK_OFF_CURSOR (f
)
22666 = get_specified_cursor_type (XCDR (tem
), &width
);
22667 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22670 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22674 /* Return the cursor we want to be displayed in window W. Return
22675 width of bar/hbar cursor through WIDTH arg. Return with
22676 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22677 (i.e. if the `system caret' should track this cursor).
22679 In a mini-buffer window, we want the cursor only to appear if we
22680 are reading input from this window. For the selected window, we
22681 want the cursor type given by the frame parameter or buffer local
22682 setting of cursor-type. If explicitly marked off, draw no cursor.
22683 In all other cases, we want a hollow box cursor. */
22685 static enum text_cursor_kinds
22686 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22688 struct glyph
*glyph
;
22690 int *active_cursor
;
22692 struct frame
*f
= XFRAME (w
->frame
);
22693 struct buffer
*b
= XBUFFER (w
->buffer
);
22694 int cursor_type
= DEFAULT_CURSOR
;
22695 Lisp_Object alt_cursor
;
22696 int non_selected
= 0;
22698 *active_cursor
= 1;
22701 if (cursor_in_echo_area
22702 && FRAME_HAS_MINIBUF_P (f
)
22703 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22705 if (w
== XWINDOW (echo_area_window
))
22707 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22709 *width
= FRAME_CURSOR_WIDTH (f
);
22710 return FRAME_DESIRED_CURSOR (f
);
22713 return get_specified_cursor_type (b
->cursor_type
, width
);
22716 *active_cursor
= 0;
22720 /* Detect a nonselected window or nonselected frame. */
22721 else if (w
!= XWINDOW (f
->selected_window
)
22722 #ifdef HAVE_WINDOW_SYSTEM
22723 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22727 *active_cursor
= 0;
22729 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22735 /* Never display a cursor in a window in which cursor-type is nil. */
22736 if (NILP (b
->cursor_type
))
22739 /* Get the normal cursor type for this window. */
22740 if (EQ (b
->cursor_type
, Qt
))
22742 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22743 *width
= FRAME_CURSOR_WIDTH (f
);
22746 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22748 /* Use cursor-in-non-selected-windows instead
22749 for non-selected window or frame. */
22752 alt_cursor
= b
->cursor_in_non_selected_windows
;
22753 if (!EQ (Qt
, alt_cursor
))
22754 return get_specified_cursor_type (alt_cursor
, width
);
22755 /* t means modify the normal cursor type. */
22756 if (cursor_type
== FILLED_BOX_CURSOR
)
22757 cursor_type
= HOLLOW_BOX_CURSOR
;
22758 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22760 return cursor_type
;
22763 /* Use normal cursor if not blinked off. */
22764 if (!w
->cursor_off_p
)
22766 #ifdef HAVE_WINDOW_SYSTEM
22767 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22769 if (cursor_type
== FILLED_BOX_CURSOR
)
22771 /* Using a block cursor on large images can be very annoying.
22772 So use a hollow cursor for "large" images.
22773 If image is not transparent (no mask), also use hollow cursor. */
22774 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22775 if (img
!= NULL
&& IMAGEP (img
->spec
))
22777 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22778 where N = size of default frame font size.
22779 This should cover most of the "tiny" icons people may use. */
22781 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22782 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22783 cursor_type
= HOLLOW_BOX_CURSOR
;
22786 else if (cursor_type
!= NO_CURSOR
)
22788 /* Display current only supports BOX and HOLLOW cursors for images.
22789 So for now, unconditionally use a HOLLOW cursor when cursor is
22790 not a solid box cursor. */
22791 cursor_type
= HOLLOW_BOX_CURSOR
;
22795 return cursor_type
;
22798 /* Cursor is blinked off, so determine how to "toggle" it. */
22800 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22801 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22802 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22804 /* Then see if frame has specified a specific blink off cursor type. */
22805 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22807 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22808 return FRAME_BLINK_OFF_CURSOR (f
);
22812 /* Some people liked having a permanently visible blinking cursor,
22813 while others had very strong opinions against it. So it was
22814 decided to remove it. KFS 2003-09-03 */
22816 /* Finally perform built-in cursor blinking:
22817 filled box <-> hollow box
22818 wide [h]bar <-> narrow [h]bar
22819 narrow [h]bar <-> no cursor
22820 other type <-> no cursor */
22822 if (cursor_type
== FILLED_BOX_CURSOR
)
22823 return HOLLOW_BOX_CURSOR
;
22825 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22828 return cursor_type
;
22836 #ifdef HAVE_WINDOW_SYSTEM
22838 /* Notice when the text cursor of window W has been completely
22839 overwritten by a drawing operation that outputs glyphs in AREA
22840 starting at X0 and ending at X1 in the line starting at Y0 and
22841 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22842 the rest of the line after X0 has been written. Y coordinates
22843 are window-relative. */
22846 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22848 enum glyph_row_area area
;
22849 int x0
, y0
, x1
, y1
;
22851 int cx0
, cx1
, cy0
, cy1
;
22852 struct glyph_row
*row
;
22854 if (!w
->phys_cursor_on_p
)
22856 if (area
!= TEXT_AREA
)
22859 if (w
->phys_cursor
.vpos
< 0
22860 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22861 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22862 !(row
->enabled_p
&& row
->displays_text_p
)))
22865 if (row
->cursor_in_fringe_p
)
22867 row
->cursor_in_fringe_p
= 0;
22868 draw_fringe_bitmap (w
, row
, 0);
22869 w
->phys_cursor_on_p
= 0;
22873 cx0
= w
->phys_cursor
.x
;
22874 cx1
= cx0
+ w
->phys_cursor_width
;
22875 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22878 /* The cursor image will be completely removed from the
22879 screen if the output area intersects the cursor area in
22880 y-direction. When we draw in [y0 y1[, and some part of
22881 the cursor is at y < y0, that part must have been drawn
22882 before. When scrolling, the cursor is erased before
22883 actually scrolling, so we don't come here. When not
22884 scrolling, the rows above the old cursor row must have
22885 changed, and in this case these rows must have written
22886 over the cursor image.
22888 Likewise if part of the cursor is below y1, with the
22889 exception of the cursor being in the first blank row at
22890 the buffer and window end because update_text_area
22891 doesn't draw that row. (Except when it does, but
22892 that's handled in update_text_area.) */
22894 cy0
= w
->phys_cursor
.y
;
22895 cy1
= cy0
+ w
->phys_cursor_height
;
22896 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22899 w
->phys_cursor_on_p
= 0;
22902 #endif /* HAVE_WINDOW_SYSTEM */
22905 /************************************************************************
22907 ************************************************************************/
22909 #ifdef HAVE_WINDOW_SYSTEM
22912 Fix the display of area AREA of overlapping row ROW in window W
22913 with respect to the overlapping part OVERLAPS. */
22916 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22918 struct glyph_row
*row
;
22919 enum glyph_row_area area
;
22927 for (i
= 0; i
< row
->used
[area
];)
22929 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22931 int start
= i
, start_x
= x
;
22935 x
+= row
->glyphs
[area
][i
].pixel_width
;
22938 while (i
< row
->used
[area
]
22939 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22941 draw_glyphs (w
, start_x
, row
, area
,
22943 DRAW_NORMAL_TEXT
, overlaps
);
22947 x
+= row
->glyphs
[area
][i
].pixel_width
;
22957 Draw the cursor glyph of window W in glyph row ROW. See the
22958 comment of draw_glyphs for the meaning of HL. */
22961 draw_phys_cursor_glyph (w
, row
, hl
)
22963 struct glyph_row
*row
;
22964 enum draw_glyphs_face hl
;
22966 /* If cursor hpos is out of bounds, don't draw garbage. This can
22967 happen in mini-buffer windows when switching between echo area
22968 glyphs and mini-buffer. */
22969 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22971 int on_p
= w
->phys_cursor_on_p
;
22973 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22974 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22976 w
->phys_cursor_on_p
= on_p
;
22978 if (hl
== DRAW_CURSOR
)
22979 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22980 /* When we erase the cursor, and ROW is overlapped by other
22981 rows, make sure that these overlapping parts of other rows
22983 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22985 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22987 if (row
> w
->current_matrix
->rows
22988 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22989 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22990 OVERLAPS_ERASED_CURSOR
);
22992 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22993 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22994 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22995 OVERLAPS_ERASED_CURSOR
);
23002 Erase the image of a cursor of window W from the screen. */
23005 erase_phys_cursor (w
)
23008 struct frame
*f
= XFRAME (w
->frame
);
23009 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23010 int hpos
= w
->phys_cursor
.hpos
;
23011 int vpos
= w
->phys_cursor
.vpos
;
23012 int mouse_face_here_p
= 0;
23013 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
23014 struct glyph_row
*cursor_row
;
23015 struct glyph
*cursor_glyph
;
23016 enum draw_glyphs_face hl
;
23018 /* No cursor displayed or row invalidated => nothing to do on the
23020 if (w
->phys_cursor_type
== NO_CURSOR
)
23021 goto mark_cursor_off
;
23023 /* VPOS >= active_glyphs->nrows means that window has been resized.
23024 Don't bother to erase the cursor. */
23025 if (vpos
>= active_glyphs
->nrows
)
23026 goto mark_cursor_off
;
23028 /* If row containing cursor is marked invalid, there is nothing we
23030 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
23031 if (!cursor_row
->enabled_p
)
23032 goto mark_cursor_off
;
23034 /* If line spacing is > 0, old cursor may only be partially visible in
23035 window after split-window. So adjust visible height. */
23036 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
23037 window_text_bottom_y (w
) - cursor_row
->y
);
23039 /* If row is completely invisible, don't attempt to delete a cursor which
23040 isn't there. This can happen if cursor is at top of a window, and
23041 we switch to a buffer with a header line in that window. */
23042 if (cursor_row
->visible_height
<= 0)
23043 goto mark_cursor_off
;
23045 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
23046 if (cursor_row
->cursor_in_fringe_p
)
23048 cursor_row
->cursor_in_fringe_p
= 0;
23049 draw_fringe_bitmap (w
, cursor_row
, 0);
23050 goto mark_cursor_off
;
23053 /* This can happen when the new row is shorter than the old one.
23054 In this case, either draw_glyphs or clear_end_of_line
23055 should have cleared the cursor. Note that we wouldn't be
23056 able to erase the cursor in this case because we don't have a
23057 cursor glyph at hand. */
23058 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
23059 goto mark_cursor_off
;
23061 /* If the cursor is in the mouse face area, redisplay that when
23062 we clear the cursor. */
23063 if (! NILP (dpyinfo
->mouse_face_window
)
23064 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
23065 && (vpos
> dpyinfo
->mouse_face_beg_row
23066 || (vpos
== dpyinfo
->mouse_face_beg_row
23067 && hpos
>= dpyinfo
->mouse_face_beg_col
))
23068 && (vpos
< dpyinfo
->mouse_face_end_row
23069 || (vpos
== dpyinfo
->mouse_face_end_row
23070 && hpos
< dpyinfo
->mouse_face_end_col
))
23071 /* Don't redraw the cursor's spot in mouse face if it is at the
23072 end of a line (on a newline). The cursor appears there, but
23073 mouse highlighting does not. */
23074 && cursor_row
->used
[TEXT_AREA
] > hpos
)
23075 mouse_face_here_p
= 1;
23077 /* Maybe clear the display under the cursor. */
23078 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
23081 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
23084 cursor_glyph
= get_phys_cursor_glyph (w
);
23085 if (cursor_glyph
== NULL
)
23086 goto mark_cursor_off
;
23088 width
= cursor_glyph
->pixel_width
;
23089 left_x
= window_box_left_offset (w
, TEXT_AREA
);
23090 x
= w
->phys_cursor
.x
;
23092 width
-= left_x
- x
;
23093 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
23094 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
23095 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
23098 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
23101 /* Erase the cursor by redrawing the character underneath it. */
23102 if (mouse_face_here_p
)
23103 hl
= DRAW_MOUSE_FACE
;
23105 hl
= DRAW_NORMAL_TEXT
;
23106 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
23109 w
->phys_cursor_on_p
= 0;
23110 w
->phys_cursor_type
= NO_CURSOR
;
23115 Display or clear cursor of window W. If ON is zero, clear the
23116 cursor. If it is non-zero, display the cursor. If ON is nonzero,
23117 where to put the cursor is specified by HPOS, VPOS, X and Y. */
23120 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
23122 int on
, hpos
, vpos
, x
, y
;
23124 struct frame
*f
= XFRAME (w
->frame
);
23125 int new_cursor_type
;
23126 int new_cursor_width
;
23128 struct glyph_row
*glyph_row
;
23129 struct glyph
*glyph
;
23131 /* This is pointless on invisible frames, and dangerous on garbaged
23132 windows and frames; in the latter case, the frame or window may
23133 be in the midst of changing its size, and x and y may be off the
23135 if (! FRAME_VISIBLE_P (f
)
23136 || FRAME_GARBAGED_P (f
)
23137 || vpos
>= w
->current_matrix
->nrows
23138 || hpos
>= w
->current_matrix
->matrix_w
)
23141 /* If cursor is off and we want it off, return quickly. */
23142 if (!on
&& !w
->phys_cursor_on_p
)
23145 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
23146 /* If cursor row is not enabled, we don't really know where to
23147 display the cursor. */
23148 if (!glyph_row
->enabled_p
)
23150 w
->phys_cursor_on_p
= 0;
23155 if (!glyph_row
->exact_window_width_line_p
23156 || hpos
< glyph_row
->used
[TEXT_AREA
])
23157 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
23159 xassert (interrupt_input_blocked
);
23161 /* Set new_cursor_type to the cursor we want to be displayed. */
23162 new_cursor_type
= get_window_cursor_type (w
, glyph
,
23163 &new_cursor_width
, &active_cursor
);
23165 /* If cursor is currently being shown and we don't want it to be or
23166 it is in the wrong place, or the cursor type is not what we want,
23168 if (w
->phys_cursor_on_p
23170 || w
->phys_cursor
.x
!= x
23171 || w
->phys_cursor
.y
!= y
23172 || new_cursor_type
!= w
->phys_cursor_type
23173 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
23174 && new_cursor_width
!= w
->phys_cursor_width
)))
23175 erase_phys_cursor (w
);
23177 /* Don't check phys_cursor_on_p here because that flag is only set
23178 to zero in some cases where we know that the cursor has been
23179 completely erased, to avoid the extra work of erasing the cursor
23180 twice. In other words, phys_cursor_on_p can be 1 and the cursor
23181 still not be visible, or it has only been partly erased. */
23184 w
->phys_cursor_ascent
= glyph_row
->ascent
;
23185 w
->phys_cursor_height
= glyph_row
->height
;
23187 /* Set phys_cursor_.* before x_draw_.* is called because some
23188 of them may need the information. */
23189 w
->phys_cursor
.x
= x
;
23190 w
->phys_cursor
.y
= glyph_row
->y
;
23191 w
->phys_cursor
.hpos
= hpos
;
23192 w
->phys_cursor
.vpos
= vpos
;
23195 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
23196 new_cursor_type
, new_cursor_width
,
23197 on
, active_cursor
);
23201 /* Switch the display of W's cursor on or off, according to the value
23208 update_window_cursor (w
, on
)
23212 /* Don't update cursor in windows whose frame is in the process
23213 of being deleted. */
23214 if (w
->current_matrix
)
23217 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23218 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23224 /* Call update_window_cursor with parameter ON_P on all leaf windows
23225 in the window tree rooted at W. */
23228 update_cursor_in_window_tree (w
, on_p
)
23234 if (!NILP (w
->hchild
))
23235 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
23236 else if (!NILP (w
->vchild
))
23237 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
23239 update_window_cursor (w
, on_p
);
23241 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
23247 Display the cursor on window W, or clear it, according to ON_P.
23248 Don't change the cursor's position. */
23251 x_update_cursor (f
, on_p
)
23255 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
23260 Clear the cursor of window W to background color, and mark the
23261 cursor as not shown. This is used when the text where the cursor
23262 is about to be rewritten. */
23268 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
23269 update_window_cursor (w
, 0);
23274 Display the active region described by mouse_face_* according to DRAW. */
23277 show_mouse_face (dpyinfo
, draw
)
23278 Display_Info
*dpyinfo
;
23279 enum draw_glyphs_face draw
;
23281 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
23282 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23284 if (/* If window is in the process of being destroyed, don't bother
23286 w
->current_matrix
!= NULL
23287 /* Don't update mouse highlight if hidden */
23288 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
23289 /* Recognize when we are called to operate on rows that don't exist
23290 anymore. This can happen when a window is split. */
23291 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
23293 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
23294 struct glyph_row
*row
, *first
, *last
;
23296 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
23297 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
23299 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
23301 int start_hpos
, end_hpos
, start_x
;
23303 /* For all but the first row, the highlight starts at column 0. */
23306 start_hpos
= dpyinfo
->mouse_face_beg_col
;
23307 start_x
= dpyinfo
->mouse_face_beg_x
;
23316 end_hpos
= dpyinfo
->mouse_face_end_col
;
23319 end_hpos
= row
->used
[TEXT_AREA
];
23320 if (draw
== DRAW_NORMAL_TEXT
)
23321 row
->fill_line_p
= 1; /* Clear to end of line */
23324 if (end_hpos
> start_hpos
)
23326 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
23327 start_hpos
, end_hpos
,
23331 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
23335 /* When we've written over the cursor, arrange for it to
23336 be displayed again. */
23337 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
23340 display_and_set_cursor (w
, 1,
23341 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
23342 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
23347 /* Change the mouse cursor. */
23348 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
23349 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
23350 else if (draw
== DRAW_MOUSE_FACE
)
23351 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
23353 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
23357 Clear out the mouse-highlighted active region.
23358 Redraw it un-highlighted first. Value is non-zero if mouse
23359 face was actually drawn unhighlighted. */
23362 clear_mouse_face (dpyinfo
)
23363 Display_Info
*dpyinfo
;
23367 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
23369 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
23373 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
23374 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
23375 dpyinfo
->mouse_face_window
= Qnil
;
23376 dpyinfo
->mouse_face_overlay
= Qnil
;
23382 Non-zero if physical cursor of window W is within mouse face. */
23385 cursor_in_mouse_face_p (w
)
23388 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
23389 int in_mouse_face
= 0;
23391 if (WINDOWP (dpyinfo
->mouse_face_window
)
23392 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
23394 int hpos
= w
->phys_cursor
.hpos
;
23395 int vpos
= w
->phys_cursor
.vpos
;
23397 if (vpos
>= dpyinfo
->mouse_face_beg_row
23398 && vpos
<= dpyinfo
->mouse_face_end_row
23399 && (vpos
> dpyinfo
->mouse_face_beg_row
23400 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23401 && (vpos
< dpyinfo
->mouse_face_end_row
23402 || hpos
< dpyinfo
->mouse_face_end_col
23403 || dpyinfo
->mouse_face_past_end
))
23407 return in_mouse_face
;
23413 /* This function sets the mouse_face_* elements of DPYINFO, assuming
23414 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
23415 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
23416 for the overlay or run of text properties specifying the mouse
23417 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
23418 before-string and after-string that must also be highlighted.
23419 DISPLAY_STRING, if non-nil, is a display string that may cover some
23420 or all of the highlighted text. */
23423 mouse_face_from_buffer_pos (Lisp_Object window
,
23424 Display_Info
*dpyinfo
,
23425 EMACS_INT mouse_charpos
,
23426 EMACS_INT start_charpos
,
23427 EMACS_INT end_charpos
,
23428 Lisp_Object before_string
,
23429 Lisp_Object after_string
,
23430 Lisp_Object display_string
)
23432 struct window
*w
= XWINDOW (window
);
23433 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23434 struct glyph_row
*row
;
23435 struct glyph
*glyph
, *end
;
23439 xassert (NILP (display_string
) || STRINGP (display_string
));
23440 xassert (NILP (before_string
) || STRINGP (before_string
));
23441 xassert (NILP (after_string
) || STRINGP (after_string
));
23443 /* Find the first highlighted glyph. */
23444 if (start_charpos
< MATRIX_ROW_START_CHARPOS (first
))
23446 dpyinfo
->mouse_face_beg_col
= 0;
23447 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
23448 dpyinfo
->mouse_face_beg_x
= first
->x
;
23449 dpyinfo
->mouse_face_beg_y
= first
->y
;
23453 row
= row_containing_pos (w
, start_charpos
, first
, NULL
, 0);
23455 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23457 /* If the before-string or display-string contains newlines,
23458 row_containing_pos skips to its last row. Move back. */
23459 if (!NILP (before_string
) || !NILP (display_string
))
23461 struct glyph_row
*prev
;
23462 while ((prev
= row
- 1, prev
>= first
)
23463 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
23464 && prev
->used
[TEXT_AREA
] > 0)
23466 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
23467 glyph
= beg
+ prev
->used
[TEXT_AREA
];
23468 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
23470 || !(EQ (glyph
->object
, before_string
)
23471 || EQ (glyph
->object
, display_string
)))
23477 glyph
= row
->glyphs
[TEXT_AREA
];
23478 end
= glyph
+ row
->used
[TEXT_AREA
];
23480 dpyinfo
->mouse_face_beg_y
= row
->y
;
23481 dpyinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23483 /* Skip truncation glyphs at the start of the glyph row. */
23484 if (row
->displays_text_p
)
23486 && INTEGERP (glyph
->object
)
23487 && glyph
->charpos
< 0;
23489 x
+= glyph
->pixel_width
;
23491 /* Scan the glyph row, stopping before BEFORE_STRING or
23492 DISPLAY_STRING or START_CHARPOS. */
23494 && !INTEGERP (glyph
->object
)
23495 && !EQ (glyph
->object
, before_string
)
23496 && !EQ (glyph
->object
, display_string
)
23497 && !(BUFFERP (glyph
->object
)
23498 && glyph
->charpos
>= start_charpos
);
23500 x
+= glyph
->pixel_width
;
23502 dpyinfo
->mouse_face_beg_x
= x
;
23503 dpyinfo
->mouse_face_beg_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23506 /* Find the last highlighted glyph. */
23507 row
= row_containing_pos (w
, end_charpos
, first
, NULL
, 0);
23510 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23511 dpyinfo
->mouse_face_past_end
= 1;
23513 else if (!NILP (after_string
))
23515 /* If the after-string has newlines, advance to its last row. */
23516 struct glyph_row
*next
;
23517 struct glyph_row
*last
23518 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
23520 for (next
= row
+ 1;
23522 && next
->used
[TEXT_AREA
] > 0
23523 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
23528 glyph
= row
->glyphs
[TEXT_AREA
];
23529 end
= glyph
+ row
->used
[TEXT_AREA
];
23531 dpyinfo
->mouse_face_end_y
= row
->y
;
23532 dpyinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23534 /* Skip truncation glyphs at the start of the row. */
23535 if (row
->displays_text_p
)
23537 && INTEGERP (glyph
->object
)
23538 && glyph
->charpos
< 0;
23540 x
+= glyph
->pixel_width
;
23542 /* Scan the glyph row, stopping at END_CHARPOS or when we encounter
23545 && !INTEGERP (glyph
->object
)
23546 && !EQ (glyph
->object
, after_string
)
23547 && !(BUFFERP (glyph
->object
) && glyph
->charpos
>= end_charpos
);
23549 x
+= glyph
->pixel_width
;
23551 /* If we found AFTER_STRING, consume it and stop. */
23552 if (EQ (glyph
->object
, after_string
))
23554 for (; EQ (glyph
->object
, after_string
) && glyph
< end
; ++glyph
)
23555 x
+= glyph
->pixel_width
;
23559 /* If there's no after-string, we must check if we overshot,
23560 which might be the case if we stopped after a string glyph.
23561 That glyph may belong to a before-string or display-string
23562 associated with the end position, which must not be
23564 Lisp_Object prev_object
;
23567 while (glyph
> row
->glyphs
[TEXT_AREA
])
23569 prev_object
= (glyph
- 1)->object
;
23570 if (!STRINGP (prev_object
) || EQ (prev_object
, display_string
))
23573 pos
= string_buffer_position (w
, prev_object
, end_charpos
);
23574 if (pos
&& pos
< end_charpos
)
23577 for (; glyph
> row
->glyphs
[TEXT_AREA
]
23578 && EQ ((glyph
- 1)->object
, prev_object
);
23580 x
-= (glyph
- 1)->pixel_width
;
23584 dpyinfo
->mouse_face_end_x
= x
;
23585 dpyinfo
->mouse_face_end_col
= glyph
- row
->glyphs
[TEXT_AREA
];
23586 dpyinfo
->mouse_face_window
= window
;
23587 dpyinfo
->mouse_face_face_id
23588 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
23590 !dpyinfo
->mouse_face_hidden
, -1);
23591 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23595 /* Find the position of the glyph for position POS in OBJECT in
23596 window W's current matrix, and return in *X, *Y the pixel
23597 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
23599 RIGHT_P non-zero means return the position of the right edge of the
23600 glyph, RIGHT_P zero means return the left edge position.
23602 If no glyph for POS exists in the matrix, return the position of
23603 the glyph with the next smaller position that is in the matrix, if
23604 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23605 exists in the matrix, return the position of the glyph with the
23606 next larger position in OBJECT.
23608 Value is non-zero if a glyph was found. */
23611 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23614 Lisp_Object object
;
23615 int *hpos
, *vpos
, *x
, *y
;
23618 int yb
= window_text_bottom_y (w
);
23619 struct glyph_row
*r
;
23620 struct glyph
*best_glyph
= NULL
;
23621 struct glyph_row
*best_row
= NULL
;
23624 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23625 r
->enabled_p
&& r
->y
< yb
;
23628 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23629 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23632 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23633 if (EQ (g
->object
, object
))
23635 if (g
->charpos
== pos
)
23642 else if (best_glyph
== NULL
23643 || ((eabs (g
->charpos
- pos
)
23644 < eabs (best_glyph
->charpos
- pos
))
23647 : g
->charpos
> pos
)))
23661 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23665 *x
+= best_glyph
->pixel_width
;
23670 *vpos
= best_row
- w
->current_matrix
->rows
;
23673 return best_glyph
!= NULL
;
23677 /* See if position X, Y is within a hot-spot of an image. */
23680 on_hot_spot_p (hot_spot
, x
, y
)
23681 Lisp_Object hot_spot
;
23684 if (!CONSP (hot_spot
))
23687 if (EQ (XCAR (hot_spot
), Qrect
))
23689 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23690 Lisp_Object rect
= XCDR (hot_spot
);
23694 if (!CONSP (XCAR (rect
)))
23696 if (!CONSP (XCDR (rect
)))
23698 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23700 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23702 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23704 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23708 else if (EQ (XCAR (hot_spot
), Qcircle
))
23710 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23711 Lisp_Object circ
= XCDR (hot_spot
);
23712 Lisp_Object lr
, lx0
, ly0
;
23714 && CONSP (XCAR (circ
))
23715 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23716 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23717 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23719 double r
= XFLOATINT (lr
);
23720 double dx
= XINT (lx0
) - x
;
23721 double dy
= XINT (ly0
) - y
;
23722 return (dx
* dx
+ dy
* dy
<= r
* r
);
23725 else if (EQ (XCAR (hot_spot
), Qpoly
))
23727 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23728 if (VECTORP (XCDR (hot_spot
)))
23730 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23731 Lisp_Object
*poly
= v
->contents
;
23735 Lisp_Object lx
, ly
;
23738 /* Need an even number of coordinates, and at least 3 edges. */
23739 if (n
< 6 || n
& 1)
23742 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23743 If count is odd, we are inside polygon. Pixels on edges
23744 may or may not be included depending on actual geometry of the
23746 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23747 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23749 x0
= XINT (lx
), y0
= XINT (ly
);
23750 for (i
= 0; i
< n
; i
+= 2)
23752 int x1
= x0
, y1
= y0
;
23753 if ((lx
= poly
[i
], !INTEGERP (lx
))
23754 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23756 x0
= XINT (lx
), y0
= XINT (ly
);
23758 /* Does this segment cross the X line? */
23766 if (y
> y0
&& y
> y1
)
23768 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23778 find_hot_spot (map
, x
, y
)
23782 while (CONSP (map
))
23784 if (CONSP (XCAR (map
))
23785 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23793 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23795 doc
: /* Lookup in image map MAP coordinates X and Y.
23796 An image map is an alist where each element has the format (AREA ID PLIST).
23797 An AREA is specified as either a rectangle, a circle, or a polygon:
23798 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23799 pixel coordinates of the upper left and bottom right corners.
23800 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23801 and the radius of the circle; r may be a float or integer.
23802 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23803 vector describes one corner in the polygon.
23804 Returns the alist element for the first matching AREA in MAP. */)
23815 return find_hot_spot (map
, XINT (x
), XINT (y
));
23819 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23821 define_frame_cursor1 (f
, cursor
, pointer
)
23824 Lisp_Object pointer
;
23826 /* Do not change cursor shape while dragging mouse. */
23827 if (!NILP (do_mouse_tracking
))
23830 if (!NILP (pointer
))
23832 if (EQ (pointer
, Qarrow
))
23833 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23834 else if (EQ (pointer
, Qhand
))
23835 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23836 else if (EQ (pointer
, Qtext
))
23837 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23838 else if (EQ (pointer
, intern ("hdrag")))
23839 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23840 #ifdef HAVE_X_WINDOWS
23841 else if (EQ (pointer
, intern ("vdrag")))
23842 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23844 else if (EQ (pointer
, intern ("hourglass")))
23845 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23846 else if (EQ (pointer
, Qmodeline
))
23847 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23849 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23852 if (cursor
!= No_Cursor
)
23853 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23856 /* Take proper action when mouse has moved to the mode or header line
23857 or marginal area AREA of window W, x-position X and y-position Y.
23858 X is relative to the start of the text display area of W, so the
23859 width of bitmap areas and scroll bars must be subtracted to get a
23860 position relative to the start of the mode line. */
23863 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23864 Lisp_Object window
;
23866 enum window_part area
;
23868 struct window
*w
= XWINDOW (window
);
23869 struct frame
*f
= XFRAME (w
->frame
);
23870 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23871 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23872 Lisp_Object pointer
= Qnil
;
23873 int charpos
, dx
, dy
, width
, height
;
23874 Lisp_Object string
, object
= Qnil
;
23875 Lisp_Object pos
, help
;
23877 Lisp_Object mouse_face
;
23878 int original_x_pixel
= x
;
23879 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23880 struct glyph_row
*row
;
23882 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23887 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23888 &object
, &dx
, &dy
, &width
, &height
);
23890 row
= (area
== ON_MODE_LINE
23891 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23892 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23895 if (row
->mode_line_p
&& row
->enabled_p
)
23897 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23898 end
= glyph
+ row
->used
[TEXT_AREA
];
23900 for (x0
= original_x_pixel
;
23901 glyph
< end
&& x0
>= glyph
->pixel_width
;
23903 x0
-= glyph
->pixel_width
;
23911 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23912 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23913 &object
, &dx
, &dy
, &width
, &height
);
23918 if (IMAGEP (object
))
23920 Lisp_Object image_map
, hotspot
;
23921 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23923 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23925 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23927 Lisp_Object area_id
, plist
;
23929 area_id
= XCAR (hotspot
);
23930 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23931 If so, we could look for mouse-enter, mouse-leave
23932 properties in PLIST (and do something...). */
23933 hotspot
= XCDR (hotspot
);
23934 if (CONSP (hotspot
)
23935 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23937 pointer
= Fplist_get (plist
, Qpointer
);
23938 if (NILP (pointer
))
23940 help
= Fplist_get (plist
, Qhelp_echo
);
23943 help_echo_string
= help
;
23944 /* Is this correct? ++kfs */
23945 XSETWINDOW (help_echo_window
, w
);
23946 help_echo_object
= w
->buffer
;
23947 help_echo_pos
= charpos
;
23951 if (NILP (pointer
))
23952 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23955 if (STRINGP (string
))
23957 pos
= make_number (charpos
);
23958 /* If we're on a string with `help-echo' text property, arrange
23959 for the help to be displayed. This is done by setting the
23960 global variable help_echo_string to the help string. */
23963 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23966 help_echo_string
= help
;
23967 XSETWINDOW (help_echo_window
, w
);
23968 help_echo_object
= string
;
23969 help_echo_pos
= charpos
;
23973 if (NILP (pointer
))
23974 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23976 /* Change the mouse pointer according to what is under X/Y. */
23977 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23980 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23981 if (!KEYMAPP (map
))
23982 map
= Fget_text_property (pos
, Qkeymap
, string
);
23983 if (!KEYMAPP (map
))
23984 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23987 /* Change the mouse face according to what is under X/Y. */
23988 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23989 if (!NILP (mouse_face
)
23990 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23995 struct glyph
* tmp_glyph
;
23999 int total_pixel_width
;
24004 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
24005 Qmouse_face
, string
, Qnil
);
24007 b
= make_number (0);
24009 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
24011 e
= make_number (SCHARS (string
));
24013 /* Calculate the position(glyph position: GPOS) of GLYPH in
24014 displayed string. GPOS is different from CHARPOS.
24016 CHARPOS is the position of glyph in internal string
24017 object. A mode line string format has structures which
24018 is converted to a flatten by emacs lisp interpreter.
24019 The internal string is an element of the structures.
24020 The displayed string is the flatten string. */
24022 if (glyph
> row_start_glyph
)
24024 tmp_glyph
= glyph
- 1;
24025 while (tmp_glyph
>= row_start_glyph
24026 && tmp_glyph
->charpos
>= XINT (b
)
24027 && EQ (tmp_glyph
->object
, glyph
->object
))
24034 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
24035 displayed string holding GLYPH.
24037 GSEQ_LENGTH is different from SCHARS (STRING).
24038 SCHARS (STRING) returns the length of the internal string. */
24039 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
24040 tmp_glyph
->charpos
< XINT (e
);
24041 tmp_glyph
++, gseq_length
++)
24043 if (!EQ (tmp_glyph
->object
, glyph
->object
))
24047 total_pixel_width
= 0;
24048 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
24049 total_pixel_width
+= tmp_glyph
->pixel_width
;
24051 /* Pre calculation of re-rendering position */
24053 hpos
= (area
== ON_MODE_LINE
24054 ? (w
->current_matrix
)->nrows
- 1
24057 /* If the re-rendering position is included in the last
24058 re-rendering area, we should do nothing. */
24059 if ( EQ (window
, dpyinfo
->mouse_face_window
)
24060 && dpyinfo
->mouse_face_beg_col
<= vpos
24061 && vpos
< dpyinfo
->mouse_face_end_col
24062 && dpyinfo
->mouse_face_beg_row
== hpos
)
24065 if (clear_mouse_face (dpyinfo
))
24066 cursor
= No_Cursor
;
24068 dpyinfo
->mouse_face_beg_col
= vpos
;
24069 dpyinfo
->mouse_face_beg_row
= hpos
;
24071 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
24072 dpyinfo
->mouse_face_beg_y
= 0;
24074 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
24075 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
24077 dpyinfo
->mouse_face_end_x
= 0;
24078 dpyinfo
->mouse_face_end_y
= 0;
24080 dpyinfo
->mouse_face_past_end
= 0;
24081 dpyinfo
->mouse_face_window
= window
;
24083 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
24086 glyph
->face_id
, 1);
24087 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24089 if (NILP (pointer
))
24092 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
24093 clear_mouse_face (dpyinfo
);
24095 define_frame_cursor1 (f
, cursor
, pointer
);
24100 Take proper action when the mouse has moved to position X, Y on
24101 frame F as regards highlighting characters that have mouse-face
24102 properties. Also de-highlighting chars where the mouse was before.
24103 X and Y can be negative or out of range. */
24106 note_mouse_highlight (f
, x
, y
)
24110 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24111 enum window_part part
;
24112 Lisp_Object window
;
24114 Cursor cursor
= No_Cursor
;
24115 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
24118 /* When a menu is active, don't highlight because this looks odd. */
24119 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
24120 if (popup_activated ())
24124 if (NILP (Vmouse_highlight
)
24125 || !f
->glyphs_initialized_p
)
24128 dpyinfo
->mouse_face_mouse_x
= x
;
24129 dpyinfo
->mouse_face_mouse_y
= y
;
24130 dpyinfo
->mouse_face_mouse_frame
= f
;
24132 if (dpyinfo
->mouse_face_defer
)
24135 if (gc_in_progress
)
24137 dpyinfo
->mouse_face_deferred_gc
= 1;
24141 /* Which window is that in? */
24142 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
24144 /* If we were displaying active text in another window, clear that.
24145 Also clear if we move out of text area in same window. */
24146 if (! EQ (window
, dpyinfo
->mouse_face_window
)
24147 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
24148 && !NILP (dpyinfo
->mouse_face_window
)))
24149 clear_mouse_face (dpyinfo
);
24151 /* Not on a window -> return. */
24152 if (!WINDOWP (window
))
24155 /* Reset help_echo_string. It will get recomputed below. */
24156 help_echo_string
= Qnil
;
24158 /* Convert to window-relative pixel coordinates. */
24159 w
= XWINDOW (window
);
24160 frame_to_window_pixel_xy (w
, &x
, &y
);
24162 /* Handle tool-bar window differently since it doesn't display a
24164 if (EQ (window
, f
->tool_bar_window
))
24166 note_tool_bar_highlight (f
, x
, y
);
24170 /* Mouse is on the mode, header line or margin? */
24171 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
24172 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
24174 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
24178 if (part
== ON_VERTICAL_BORDER
)
24180 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
24181 help_echo_string
= build_string ("drag-mouse-1: resize");
24183 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
24184 || part
== ON_SCROLL_BAR
)
24185 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24187 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
24189 /* Are we in a window whose display is up to date?
24190 And verify the buffer's text has not changed. */
24191 b
= XBUFFER (w
->buffer
);
24192 if (part
== ON_TEXT
24193 && EQ (w
->window_end_valid
, w
->buffer
)
24194 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
24195 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
24197 int hpos
, vpos
, i
, dx
, dy
, area
;
24199 struct glyph
*glyph
;
24200 Lisp_Object object
;
24201 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
24202 Lisp_Object
*overlay_vec
= NULL
;
24204 struct buffer
*obuf
;
24205 int obegv
, ozv
, same_region
;
24207 /* Find the glyph under X/Y. */
24208 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
24210 /* Look for :pointer property on image. */
24211 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
24213 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
24214 if (img
!= NULL
&& IMAGEP (img
->spec
))
24216 Lisp_Object image_map
, hotspot
;
24217 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
24219 && (hotspot
= find_hot_spot (image_map
,
24220 glyph
->slice
.x
+ dx
,
24221 glyph
->slice
.y
+ dy
),
24223 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
24225 Lisp_Object area_id
, plist
;
24227 area_id
= XCAR (hotspot
);
24228 /* Could check AREA_ID to see if we enter/leave this hot-spot.
24229 If so, we could look for mouse-enter, mouse-leave
24230 properties in PLIST (and do something...). */
24231 hotspot
= XCDR (hotspot
);
24232 if (CONSP (hotspot
)
24233 && (plist
= XCAR (hotspot
), CONSP (plist
)))
24235 pointer
= Fplist_get (plist
, Qpointer
);
24236 if (NILP (pointer
))
24238 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
24239 if (!NILP (help_echo_string
))
24241 help_echo_window
= window
;
24242 help_echo_object
= glyph
->object
;
24243 help_echo_pos
= glyph
->charpos
;
24247 if (NILP (pointer
))
24248 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
24252 /* Clear mouse face if X/Y not over text. */
24254 || area
!= TEXT_AREA
24255 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
24257 if (clear_mouse_face (dpyinfo
))
24258 cursor
= No_Cursor
;
24259 if (NILP (pointer
))
24261 if (area
!= TEXT_AREA
)
24262 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
24264 pointer
= Vvoid_text_area_pointer
;
24269 pos
= glyph
->charpos
;
24270 object
= glyph
->object
;
24271 if (!STRINGP (object
) && !BUFFERP (object
))
24274 /* If we get an out-of-range value, return now; avoid an error. */
24275 if (BUFFERP (object
) && pos
> BUF_Z (b
))
24278 /* Make the window's buffer temporarily current for
24279 overlays_at and compute_char_face. */
24280 obuf
= current_buffer
;
24281 current_buffer
= b
;
24287 /* Is this char mouse-active or does it have help-echo? */
24288 position
= make_number (pos
);
24290 if (BUFFERP (object
))
24292 /* Put all the overlays we want in a vector in overlay_vec. */
24293 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
24294 /* Sort overlays into increasing priority order. */
24295 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
24300 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
24301 && vpos
>= dpyinfo
->mouse_face_beg_row
24302 && vpos
<= dpyinfo
->mouse_face_end_row
24303 && (vpos
> dpyinfo
->mouse_face_beg_row
24304 || hpos
>= dpyinfo
->mouse_face_beg_col
)
24305 && (vpos
< dpyinfo
->mouse_face_end_row
24306 || hpos
< dpyinfo
->mouse_face_end_col
24307 || dpyinfo
->mouse_face_past_end
));
24310 cursor
= No_Cursor
;
24312 /* Check mouse-face highlighting. */
24314 /* If there exists an overlay with mouse-face overlapping
24315 the one we are currently highlighting, we have to
24316 check if we enter the overlapping overlay, and then
24317 highlight only that. */
24318 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
24319 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
24321 /* Find the highest priority overlay with a mouse-face. */
24323 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
24325 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
24326 if (!NILP (mouse_face
))
24327 overlay
= overlay_vec
[i
];
24330 /* If we're highlighting the same overlay as before, there's
24331 no need to do that again. */
24332 if (!NILP (overlay
) && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
24333 goto check_help_echo
;
24334 dpyinfo
->mouse_face_overlay
= overlay
;
24336 /* Clear the display of the old active region, if any. */
24337 if (clear_mouse_face (dpyinfo
))
24338 cursor
= No_Cursor
;
24340 /* If no overlay applies, get a text property. */
24341 if (NILP (overlay
))
24342 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
24344 /* Next, compute the bounds of the mouse highlighting and
24346 if (!NILP (mouse_face
) && STRINGP (object
))
24348 /* The mouse-highlighting comes from a display string
24349 with a mouse-face. */
24353 b
= Fprevious_single_property_change
24354 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
24355 e
= Fnext_single_property_change
24356 (position
, Qmouse_face
, object
, Qnil
);
24358 b
= make_number (0);
24360 e
= make_number (SCHARS (object
) - 1);
24362 fast_find_string_pos (w
, XINT (b
), object
,
24363 &dpyinfo
->mouse_face_beg_col
,
24364 &dpyinfo
->mouse_face_beg_row
,
24365 &dpyinfo
->mouse_face_beg_x
,
24366 &dpyinfo
->mouse_face_beg_y
, 0);
24367 fast_find_string_pos (w
, XINT (e
), object
,
24368 &dpyinfo
->mouse_face_end_col
,
24369 &dpyinfo
->mouse_face_end_row
,
24370 &dpyinfo
->mouse_face_end_x
,
24371 &dpyinfo
->mouse_face_end_y
, 1);
24372 dpyinfo
->mouse_face_past_end
= 0;
24373 dpyinfo
->mouse_face_window
= window
;
24374 dpyinfo
->mouse_face_face_id
24375 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
24376 glyph
->face_id
, 1);
24377 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
24378 cursor
= No_Cursor
;
24382 /* The mouse-highlighting, if any, comes from an overlay
24383 or text property in the buffer. */
24384 Lisp_Object buffer
, display_string
;
24386 if (STRINGP (object
))
24388 /* If we are on a display string with no mouse-face,
24389 check if the text under it has one. */
24390 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
24391 int start
= MATRIX_ROW_START_CHARPOS (r
);
24392 pos
= string_buffer_position (w
, object
, start
);
24395 mouse_face
= get_char_property_and_overlay
24396 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
24397 buffer
= w
->buffer
;
24398 display_string
= object
;
24404 display_string
= Qnil
;
24407 if (!NILP (mouse_face
))
24409 Lisp_Object before
, after
;
24410 Lisp_Object before_string
, after_string
;
24412 if (NILP (overlay
))
24414 /* Handle the text property case. */
24415 before
= Fprevious_single_property_change
24416 (make_number (pos
+ 1), Qmouse_face
, buffer
,
24417 Fmarker_position (w
->start
));
24418 after
= Fnext_single_property_change
24419 (make_number (pos
), Qmouse_face
, buffer
,
24420 make_number (BUF_Z (XBUFFER (buffer
))
24421 - XFASTINT (w
->window_end_pos
)));
24422 before_string
= after_string
= Qnil
;
24426 /* Handle the overlay case. */
24427 before
= Foverlay_start (overlay
);
24428 after
= Foverlay_end (overlay
);
24429 before_string
= Foverlay_get (overlay
, Qbefore_string
);
24430 after_string
= Foverlay_get (overlay
, Qafter_string
);
24432 if (!STRINGP (before_string
)) before_string
= Qnil
;
24433 if (!STRINGP (after_string
)) after_string
= Qnil
;
24436 mouse_face_from_buffer_pos (window
, dpyinfo
, pos
,
24439 before_string
, after_string
,
24441 cursor
= No_Cursor
;
24448 /* Look for a `help-echo' property. */
24449 if (NILP (help_echo_string
)) {
24450 Lisp_Object help
, overlay
;
24452 /* Check overlays first. */
24453 help
= overlay
= Qnil
;
24454 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
24456 overlay
= overlay_vec
[i
];
24457 help
= Foverlay_get (overlay
, Qhelp_echo
);
24462 help_echo_string
= help
;
24463 help_echo_window
= window
;
24464 help_echo_object
= overlay
;
24465 help_echo_pos
= pos
;
24469 Lisp_Object object
= glyph
->object
;
24470 int charpos
= glyph
->charpos
;
24472 /* Try text properties. */
24473 if (STRINGP (object
)
24475 && charpos
< SCHARS (object
))
24477 help
= Fget_text_property (make_number (charpos
),
24478 Qhelp_echo
, object
);
24481 /* If the string itself doesn't specify a help-echo,
24482 see if the buffer text ``under'' it does. */
24483 struct glyph_row
*r
24484 = MATRIX_ROW (w
->current_matrix
, vpos
);
24485 int start
= MATRIX_ROW_START_CHARPOS (r
);
24486 EMACS_INT pos
= string_buffer_position (w
, object
, start
);
24489 help
= Fget_char_property (make_number (pos
),
24490 Qhelp_echo
, w
->buffer
);
24494 object
= w
->buffer
;
24499 else if (BUFFERP (object
)
24502 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
24507 help_echo_string
= help
;
24508 help_echo_window
= window
;
24509 help_echo_object
= object
;
24510 help_echo_pos
= charpos
;
24515 /* Look for a `pointer' property. */
24516 if (NILP (pointer
))
24518 /* Check overlays first. */
24519 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
24520 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
24522 if (NILP (pointer
))
24524 Lisp_Object object
= glyph
->object
;
24525 int charpos
= glyph
->charpos
;
24527 /* Try text properties. */
24528 if (STRINGP (object
)
24530 && charpos
< SCHARS (object
))
24532 pointer
= Fget_text_property (make_number (charpos
),
24534 if (NILP (pointer
))
24536 /* If the string itself doesn't specify a pointer,
24537 see if the buffer text ``under'' it does. */
24538 struct glyph_row
*r
24539 = MATRIX_ROW (w
->current_matrix
, vpos
);
24540 int start
= MATRIX_ROW_START_CHARPOS (r
);
24541 EMACS_INT pos
= string_buffer_position (w
, object
,
24544 pointer
= Fget_char_property (make_number (pos
),
24545 Qpointer
, w
->buffer
);
24548 else if (BUFFERP (object
)
24551 pointer
= Fget_text_property (make_number (charpos
),
24558 current_buffer
= obuf
;
24563 define_frame_cursor1 (f
, cursor
, pointer
);
24568 Clear any mouse-face on window W. This function is part of the
24569 redisplay interface, and is called from try_window_id and similar
24570 functions to ensure the mouse-highlight is off. */
24573 x_clear_window_mouse_face (w
)
24576 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24577 Lisp_Object window
;
24580 XSETWINDOW (window
, w
);
24581 if (EQ (window
, dpyinfo
->mouse_face_window
))
24582 clear_mouse_face (dpyinfo
);
24588 Just discard the mouse face information for frame F, if any.
24589 This is used when the size of F is changed. */
24592 cancel_mouse_face (f
)
24595 Lisp_Object window
;
24596 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24598 window
= dpyinfo
->mouse_face_window
;
24599 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24601 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24602 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24603 dpyinfo
->mouse_face_window
= Qnil
;
24608 #endif /* HAVE_WINDOW_SYSTEM */
24611 /***********************************************************************
24613 ***********************************************************************/
24615 #ifdef HAVE_WINDOW_SYSTEM
24617 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24618 which intersects rectangle R. R is in window-relative coordinates. */
24621 expose_area (w
, row
, r
, area
)
24623 struct glyph_row
*row
;
24625 enum glyph_row_area area
;
24627 struct glyph
*first
= row
->glyphs
[area
];
24628 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24629 struct glyph
*last
;
24630 int first_x
, start_x
, x
;
24632 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24633 /* If row extends face to end of line write the whole line. */
24634 draw_glyphs (w
, 0, row
, area
,
24635 0, row
->used
[area
],
24636 DRAW_NORMAL_TEXT
, 0);
24639 /* Set START_X to the window-relative start position for drawing glyphs of
24640 AREA. The first glyph of the text area can be partially visible.
24641 The first glyphs of other areas cannot. */
24642 start_x
= window_box_left_offset (w
, area
);
24644 if (area
== TEXT_AREA
)
24647 /* Find the first glyph that must be redrawn. */
24649 && x
+ first
->pixel_width
< r
->x
)
24651 x
+= first
->pixel_width
;
24655 /* Find the last one. */
24659 && x
< r
->x
+ r
->width
)
24661 x
+= last
->pixel_width
;
24667 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24668 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24669 DRAW_NORMAL_TEXT
, 0);
24674 /* Redraw the parts of the glyph row ROW on window W intersecting
24675 rectangle R. R is in window-relative coordinates. Value is
24676 non-zero if mouse-face was overwritten. */
24679 expose_line (w
, row
, r
)
24681 struct glyph_row
*row
;
24684 xassert (row
->enabled_p
);
24686 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24687 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24688 0, row
->used
[TEXT_AREA
],
24689 DRAW_NORMAL_TEXT
, 0);
24692 if (row
->used
[LEFT_MARGIN_AREA
])
24693 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24694 if (row
->used
[TEXT_AREA
])
24695 expose_area (w
, row
, r
, TEXT_AREA
);
24696 if (row
->used
[RIGHT_MARGIN_AREA
])
24697 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24698 draw_row_fringe_bitmaps (w
, row
);
24701 return row
->mouse_face_p
;
24705 /* Redraw those parts of glyphs rows during expose event handling that
24706 overlap other rows. Redrawing of an exposed line writes over parts
24707 of lines overlapping that exposed line; this function fixes that.
24709 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24710 row in W's current matrix that is exposed and overlaps other rows.
24711 LAST_OVERLAPPING_ROW is the last such row. */
24714 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24716 struct glyph_row
*first_overlapping_row
;
24717 struct glyph_row
*last_overlapping_row
;
24720 struct glyph_row
*row
;
24722 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24723 if (row
->overlapping_p
)
24725 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24728 if (row
->used
[LEFT_MARGIN_AREA
])
24729 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24731 if (row
->used
[TEXT_AREA
])
24732 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24734 if (row
->used
[RIGHT_MARGIN_AREA
])
24735 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24741 /* Return non-zero if W's cursor intersects rectangle R. */
24744 phys_cursor_in_rect_p (w
, r
)
24748 XRectangle cr
, result
;
24749 struct glyph
*cursor_glyph
;
24750 struct glyph_row
*row
;
24752 if (w
->phys_cursor
.vpos
>= 0
24753 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24754 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24756 && row
->cursor_in_fringe_p
)
24758 /* Cursor is in the fringe. */
24759 cr
.x
= window_box_right_offset (w
,
24760 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24761 ? RIGHT_MARGIN_AREA
24764 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24765 cr
.height
= row
->height
;
24766 return x_intersect_rectangles (&cr
, r
, &result
);
24769 cursor_glyph
= get_phys_cursor_glyph (w
);
24772 /* r is relative to W's box, but w->phys_cursor.x is relative
24773 to left edge of W's TEXT area. Adjust it. */
24774 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24775 cr
.y
= w
->phys_cursor
.y
;
24776 cr
.width
= cursor_glyph
->pixel_width
;
24777 cr
.height
= w
->phys_cursor_height
;
24778 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24779 I assume the effect is the same -- and this is portable. */
24780 return x_intersect_rectangles (&cr
, r
, &result
);
24782 /* If we don't understand the format, pretend we're not in the hot-spot. */
24788 Draw a vertical window border to the right of window W if W doesn't
24789 have vertical scroll bars. */
24792 x_draw_vertical_border (w
)
24795 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24797 /* We could do better, if we knew what type of scroll-bar the adjacent
24798 windows (on either side) have... But we don't :-(
24799 However, I think this works ok. ++KFS 2003-04-25 */
24801 /* Redraw borders between horizontally adjacent windows. Don't
24802 do it for frames with vertical scroll bars because either the
24803 right scroll bar of a window, or the left scroll bar of its
24804 neighbor will suffice as a border. */
24805 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24808 if (!WINDOW_RIGHTMOST_P (w
)
24809 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24811 int x0
, x1
, y0
, y1
;
24813 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24816 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24819 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24821 else if (!WINDOW_LEFTMOST_P (w
)
24822 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24824 int x0
, x1
, y0
, y1
;
24826 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24829 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24832 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24837 /* Redraw the part of window W intersection rectangle FR. Pixel
24838 coordinates in FR are frame-relative. Call this function with
24839 input blocked. Value is non-zero if the exposure overwrites
24843 expose_window (w
, fr
)
24847 struct frame
*f
= XFRAME (w
->frame
);
24849 int mouse_face_overwritten_p
= 0;
24851 /* If window is not yet fully initialized, do nothing. This can
24852 happen when toolkit scroll bars are used and a window is split.
24853 Reconfiguring the scroll bar will generate an expose for a newly
24855 if (w
->current_matrix
== NULL
)
24858 /* When we're currently updating the window, display and current
24859 matrix usually don't agree. Arrange for a thorough display
24861 if (w
== updated_window
)
24863 SET_FRAME_GARBAGED (f
);
24867 /* Frame-relative pixel rectangle of W. */
24868 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24869 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24870 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24871 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24873 if (x_intersect_rectangles (fr
, &wr
, &r
))
24875 int yb
= window_text_bottom_y (w
);
24876 struct glyph_row
*row
;
24877 int cursor_cleared_p
;
24878 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24880 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24881 r
.x
, r
.y
, r
.width
, r
.height
));
24883 /* Convert to window coordinates. */
24884 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24885 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24887 /* Turn off the cursor. */
24888 if (!w
->pseudo_window_p
24889 && phys_cursor_in_rect_p (w
, &r
))
24891 x_clear_cursor (w
);
24892 cursor_cleared_p
= 1;
24895 cursor_cleared_p
= 0;
24897 /* Update lines intersecting rectangle R. */
24898 first_overlapping_row
= last_overlapping_row
= NULL
;
24899 for (row
= w
->current_matrix
->rows
;
24904 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24906 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24907 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24908 || (r
.y
>= y0
&& r
.y
< y1
)
24909 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24911 /* A header line may be overlapping, but there is no need
24912 to fix overlapping areas for them. KFS 2005-02-12 */
24913 if (row
->overlapping_p
&& !row
->mode_line_p
)
24915 if (first_overlapping_row
== NULL
)
24916 first_overlapping_row
= row
;
24917 last_overlapping_row
= row
;
24921 if (expose_line (w
, row
, &r
))
24922 mouse_face_overwritten_p
= 1;
24925 else if (row
->overlapping_p
)
24927 /* We must redraw a row overlapping the exposed area. */
24929 ? y0
+ row
->phys_height
> r
.y
24930 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24932 if (first_overlapping_row
== NULL
)
24933 first_overlapping_row
= row
;
24934 last_overlapping_row
= row
;
24942 /* Display the mode line if there is one. */
24943 if (WINDOW_WANTS_MODELINE_P (w
)
24944 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24946 && row
->y
< r
.y
+ r
.height
)
24948 if (expose_line (w
, row
, &r
))
24949 mouse_face_overwritten_p
= 1;
24952 if (!w
->pseudo_window_p
)
24954 /* Fix the display of overlapping rows. */
24955 if (first_overlapping_row
)
24956 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24959 /* Draw border between windows. */
24960 x_draw_vertical_border (w
);
24962 /* Turn the cursor on again. */
24963 if (cursor_cleared_p
)
24964 update_window_cursor (w
, 1);
24968 return mouse_face_overwritten_p
;
24973 /* Redraw (parts) of all windows in the window tree rooted at W that
24974 intersect R. R contains frame pixel coordinates. Value is
24975 non-zero if the exposure overwrites mouse-face. */
24978 expose_window_tree (w
, r
)
24982 struct frame
*f
= XFRAME (w
->frame
);
24983 int mouse_face_overwritten_p
= 0;
24985 while (w
&& !FRAME_GARBAGED_P (f
))
24987 if (!NILP (w
->hchild
))
24988 mouse_face_overwritten_p
24989 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24990 else if (!NILP (w
->vchild
))
24991 mouse_face_overwritten_p
24992 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24994 mouse_face_overwritten_p
|= expose_window (w
, r
);
24996 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24999 return mouse_face_overwritten_p
;
25004 Redisplay an exposed area of frame F. X and Y are the upper-left
25005 corner of the exposed rectangle. W and H are width and height of
25006 the exposed area. All are pixel values. W or H zero means redraw
25007 the entire frame. */
25010 expose_frame (f
, x
, y
, w
, h
)
25015 int mouse_face_overwritten_p
= 0;
25017 TRACE ((stderr
, "expose_frame "));
25019 /* No need to redraw if frame will be redrawn soon. */
25020 if (FRAME_GARBAGED_P (f
))
25022 TRACE ((stderr
, " garbaged\n"));
25026 /* If basic faces haven't been realized yet, there is no point in
25027 trying to redraw anything. This can happen when we get an expose
25028 event while Emacs is starting, e.g. by moving another window. */
25029 if (FRAME_FACE_CACHE (f
) == NULL
25030 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
25032 TRACE ((stderr
, " no faces\n"));
25036 if (w
== 0 || h
== 0)
25039 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
25040 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
25050 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
25051 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
25053 if (WINDOWP (f
->tool_bar_window
))
25054 mouse_face_overwritten_p
25055 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
25057 #ifdef HAVE_X_WINDOWS
25059 #ifndef USE_X_TOOLKIT
25060 if (WINDOWP (f
->menu_bar_window
))
25061 mouse_face_overwritten_p
25062 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
25063 #endif /* not USE_X_TOOLKIT */
25067 /* Some window managers support a focus-follows-mouse style with
25068 delayed raising of frames. Imagine a partially obscured frame,
25069 and moving the mouse into partially obscured mouse-face on that
25070 frame. The visible part of the mouse-face will be highlighted,
25071 then the WM raises the obscured frame. With at least one WM, KDE
25072 2.1, Emacs is not getting any event for the raising of the frame
25073 (even tried with SubstructureRedirectMask), only Expose events.
25074 These expose events will draw text normally, i.e. not
25075 highlighted. Which means we must redo the highlight here.
25076 Subsume it under ``we love X''. --gerd 2001-08-15 */
25077 /* Included in Windows version because Windows most likely does not
25078 do the right thing if any third party tool offers
25079 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
25080 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
25082 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
25083 if (f
== dpyinfo
->mouse_face_mouse_frame
)
25085 int x
= dpyinfo
->mouse_face_mouse_x
;
25086 int y
= dpyinfo
->mouse_face_mouse_y
;
25087 clear_mouse_face (dpyinfo
);
25088 note_mouse_highlight (f
, x
, y
);
25095 Determine the intersection of two rectangles R1 and R2. Return
25096 the intersection in *RESULT. Value is non-zero if RESULT is not
25100 x_intersect_rectangles (r1
, r2
, result
)
25101 XRectangle
*r1
, *r2
, *result
;
25103 XRectangle
*left
, *right
;
25104 XRectangle
*upper
, *lower
;
25105 int intersection_p
= 0;
25107 /* Rearrange so that R1 is the left-most rectangle. */
25109 left
= r1
, right
= r2
;
25111 left
= r2
, right
= r1
;
25113 /* X0 of the intersection is right.x0, if this is inside R1,
25114 otherwise there is no intersection. */
25115 if (right
->x
<= left
->x
+ left
->width
)
25117 result
->x
= right
->x
;
25119 /* The right end of the intersection is the minimum of the
25120 the right ends of left and right. */
25121 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
25124 /* Same game for Y. */
25126 upper
= r1
, lower
= r2
;
25128 upper
= r2
, lower
= r1
;
25130 /* The upper end of the intersection is lower.y0, if this is inside
25131 of upper. Otherwise, there is no intersection. */
25132 if (lower
->y
<= upper
->y
+ upper
->height
)
25134 result
->y
= lower
->y
;
25136 /* The lower end of the intersection is the minimum of the lower
25137 ends of upper and lower. */
25138 result
->height
= (min (lower
->y
+ lower
->height
,
25139 upper
->y
+ upper
->height
)
25141 intersection_p
= 1;
25145 return intersection_p
;
25148 #endif /* HAVE_WINDOW_SYSTEM */
25151 /***********************************************************************
25153 ***********************************************************************/
25158 Vwith_echo_area_save_vector
= Qnil
;
25159 staticpro (&Vwith_echo_area_save_vector
);
25161 Vmessage_stack
= Qnil
;
25162 staticpro (&Vmessage_stack
);
25164 Qinhibit_redisplay
= intern_c_string ("inhibit-redisplay");
25165 staticpro (&Qinhibit_redisplay
);
25167 message_dolog_marker1
= Fmake_marker ();
25168 staticpro (&message_dolog_marker1
);
25169 message_dolog_marker2
= Fmake_marker ();
25170 staticpro (&message_dolog_marker2
);
25171 message_dolog_marker3
= Fmake_marker ();
25172 staticpro (&message_dolog_marker3
);
25175 defsubr (&Sdump_frame_glyph_matrix
);
25176 defsubr (&Sdump_glyph_matrix
);
25177 defsubr (&Sdump_glyph_row
);
25178 defsubr (&Sdump_tool_bar_row
);
25179 defsubr (&Strace_redisplay
);
25180 defsubr (&Strace_to_stderr
);
25182 #ifdef HAVE_WINDOW_SYSTEM
25183 defsubr (&Stool_bar_lines_needed
);
25184 defsubr (&Slookup_image_map
);
25186 defsubr (&Sformat_mode_line
);
25187 defsubr (&Sinvisible_p
);
25189 staticpro (&Qmenu_bar_update_hook
);
25190 Qmenu_bar_update_hook
= intern_c_string ("menu-bar-update-hook");
25192 staticpro (&Qoverriding_terminal_local_map
);
25193 Qoverriding_terminal_local_map
= intern_c_string ("overriding-terminal-local-map");
25195 staticpro (&Qoverriding_local_map
);
25196 Qoverriding_local_map
= intern_c_string ("overriding-local-map");
25198 staticpro (&Qwindow_scroll_functions
);
25199 Qwindow_scroll_functions
= intern_c_string ("window-scroll-functions");
25201 staticpro (&Qwindow_text_change_functions
);
25202 Qwindow_text_change_functions
= intern_c_string ("window-text-change-functions");
25204 staticpro (&Qredisplay_end_trigger_functions
);
25205 Qredisplay_end_trigger_functions
= intern_c_string ("redisplay-end-trigger-functions");
25207 staticpro (&Qinhibit_point_motion_hooks
);
25208 Qinhibit_point_motion_hooks
= intern_c_string ("inhibit-point-motion-hooks");
25210 Qeval
= intern_c_string ("eval");
25211 staticpro (&Qeval
);
25213 QCdata
= intern_c_string (":data");
25214 staticpro (&QCdata
);
25215 Qdisplay
= intern_c_string ("display");
25216 staticpro (&Qdisplay
);
25217 Qspace_width
= intern_c_string ("space-width");
25218 staticpro (&Qspace_width
);
25219 Qraise
= intern_c_string ("raise");
25220 staticpro (&Qraise
);
25221 Qslice
= intern_c_string ("slice");
25222 staticpro (&Qslice
);
25223 Qspace
= intern_c_string ("space");
25224 staticpro (&Qspace
);
25225 Qmargin
= intern_c_string ("margin");
25226 staticpro (&Qmargin
);
25227 Qpointer
= intern_c_string ("pointer");
25228 staticpro (&Qpointer
);
25229 Qleft_margin
= intern_c_string ("left-margin");
25230 staticpro (&Qleft_margin
);
25231 Qright_margin
= intern_c_string ("right-margin");
25232 staticpro (&Qright_margin
);
25233 Qcenter
= intern_c_string ("center");
25234 staticpro (&Qcenter
);
25235 Qline_height
= intern_c_string ("line-height");
25236 staticpro (&Qline_height
);
25237 QCalign_to
= intern_c_string (":align-to");
25238 staticpro (&QCalign_to
);
25239 QCrelative_width
= intern_c_string (":relative-width");
25240 staticpro (&QCrelative_width
);
25241 QCrelative_height
= intern_c_string (":relative-height");
25242 staticpro (&QCrelative_height
);
25243 QCeval
= intern_c_string (":eval");
25244 staticpro (&QCeval
);
25245 QCpropertize
= intern_c_string (":propertize");
25246 staticpro (&QCpropertize
);
25247 QCfile
= intern_c_string (":file");
25248 staticpro (&QCfile
);
25249 Qfontified
= intern_c_string ("fontified");
25250 staticpro (&Qfontified
);
25251 Qfontification_functions
= intern_c_string ("fontification-functions");
25252 staticpro (&Qfontification_functions
);
25253 Qtrailing_whitespace
= intern_c_string ("trailing-whitespace");
25254 staticpro (&Qtrailing_whitespace
);
25255 Qescape_glyph
= intern_c_string ("escape-glyph");
25256 staticpro (&Qescape_glyph
);
25257 Qnobreak_space
= intern_c_string ("nobreak-space");
25258 staticpro (&Qnobreak_space
);
25259 Qimage
= intern_c_string ("image");
25260 staticpro (&Qimage
);
25261 QCmap
= intern_c_string (":map");
25262 staticpro (&QCmap
);
25263 QCpointer
= intern_c_string (":pointer");
25264 staticpro (&QCpointer
);
25265 Qrect
= intern_c_string ("rect");
25266 staticpro (&Qrect
);
25267 Qcircle
= intern_c_string ("circle");
25268 staticpro (&Qcircle
);
25269 Qpoly
= intern_c_string ("poly");
25270 staticpro (&Qpoly
);
25271 Qmessage_truncate_lines
= intern_c_string ("message-truncate-lines");
25272 staticpro (&Qmessage_truncate_lines
);
25273 Qgrow_only
= intern_c_string ("grow-only");
25274 staticpro (&Qgrow_only
);
25275 Qinhibit_menubar_update
= intern_c_string ("inhibit-menubar-update");
25276 staticpro (&Qinhibit_menubar_update
);
25277 Qinhibit_eval_during_redisplay
= intern_c_string ("inhibit-eval-during-redisplay");
25278 staticpro (&Qinhibit_eval_during_redisplay
);
25279 Qposition
= intern_c_string ("position");
25280 staticpro (&Qposition
);
25281 Qbuffer_position
= intern_c_string ("buffer-position");
25282 staticpro (&Qbuffer_position
);
25283 Qobject
= intern_c_string ("object");
25284 staticpro (&Qobject
);
25285 Qbar
= intern_c_string ("bar");
25287 Qhbar
= intern_c_string ("hbar");
25288 staticpro (&Qhbar
);
25289 Qbox
= intern_c_string ("box");
25291 Qhollow
= intern_c_string ("hollow");
25292 staticpro (&Qhollow
);
25293 Qhand
= intern_c_string ("hand");
25294 staticpro (&Qhand
);
25295 Qarrow
= intern_c_string ("arrow");
25296 staticpro (&Qarrow
);
25297 Qtext
= intern_c_string ("text");
25298 staticpro (&Qtext
);
25299 Qrisky_local_variable
= intern_c_string ("risky-local-variable");
25300 staticpro (&Qrisky_local_variable
);
25301 Qinhibit_free_realized_faces
= intern_c_string ("inhibit-free-realized-faces");
25302 staticpro (&Qinhibit_free_realized_faces
);
25304 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
25305 Fcons (intern_c_string ("void-variable"), Qnil
)),
25307 staticpro (&list_of_error
);
25309 Qlast_arrow_position
= intern_c_string ("last-arrow-position");
25310 staticpro (&Qlast_arrow_position
);
25311 Qlast_arrow_string
= intern_c_string ("last-arrow-string");
25312 staticpro (&Qlast_arrow_string
);
25314 Qoverlay_arrow_string
= intern_c_string ("overlay-arrow-string");
25315 staticpro (&Qoverlay_arrow_string
);
25316 Qoverlay_arrow_bitmap
= intern_c_string ("overlay-arrow-bitmap");
25317 staticpro (&Qoverlay_arrow_bitmap
);
25319 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
25320 staticpro (&echo_buffer
[0]);
25321 staticpro (&echo_buffer
[1]);
25323 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
25324 staticpro (&echo_area_buffer
[0]);
25325 staticpro (&echo_area_buffer
[1]);
25327 Vmessages_buffer_name
= make_pure_c_string ("*Messages*");
25328 staticpro (&Vmessages_buffer_name
);
25330 mode_line_proptrans_alist
= Qnil
;
25331 staticpro (&mode_line_proptrans_alist
);
25332 mode_line_string_list
= Qnil
;
25333 staticpro (&mode_line_string_list
);
25334 mode_line_string_face
= Qnil
;
25335 staticpro (&mode_line_string_face
);
25336 mode_line_string_face_prop
= Qnil
;
25337 staticpro (&mode_line_string_face_prop
);
25338 Vmode_line_unwind_vector
= Qnil
;
25339 staticpro (&Vmode_line_unwind_vector
);
25341 help_echo_string
= Qnil
;
25342 staticpro (&help_echo_string
);
25343 help_echo_object
= Qnil
;
25344 staticpro (&help_echo_object
);
25345 help_echo_window
= Qnil
;
25346 staticpro (&help_echo_window
);
25347 previous_help_echo_string
= Qnil
;
25348 staticpro (&previous_help_echo_string
);
25349 help_echo_pos
= -1;
25351 Qright_to_left
= intern ("right-to-left");
25352 staticpro (&Qright_to_left
);
25353 Qleft_to_right
= intern ("left-to-right");
25354 staticpro (&Qleft_to_right
);
25356 #ifdef HAVE_WINDOW_SYSTEM
25357 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
25358 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
25359 For example, if a block cursor is over a tab, it will be drawn as
25360 wide as that tab on the display. */);
25361 x_stretch_cursor_p
= 0;
25364 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
25365 doc
: /* *Non-nil means highlight trailing whitespace.
25366 The face used for trailing whitespace is `trailing-whitespace'. */);
25367 Vshow_trailing_whitespace
= Qnil
;
25369 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
25370 doc
: /* *Control highlighting of nobreak space and soft hyphen.
25371 A value of t means highlight the character itself (for nobreak space,
25372 use face `nobreak-space').
25373 A value of nil means no highlighting.
25374 Other values mean display the escape glyph followed by an ordinary
25375 space or ordinary hyphen. */);
25376 Vnobreak_char_display
= Qt
;
25378 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
25379 doc
: /* *The pointer shape to show in void text areas.
25380 A value of nil means to show the text pointer. Other options are `arrow',
25381 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
25382 Vvoid_text_area_pointer
= Qarrow
;
25384 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
25385 doc
: /* Non-nil means don't actually do any redisplay.
25386 This is used for internal purposes. */);
25387 Vinhibit_redisplay
= Qnil
;
25389 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
25390 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
25391 Vglobal_mode_string
= Qnil
;
25393 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
25394 doc
: /* Marker for where to display an arrow on top of the buffer text.
25395 This must be the beginning of a line in order to work.
25396 See also `overlay-arrow-string'. */);
25397 Voverlay_arrow_position
= Qnil
;
25399 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
25400 doc
: /* String to display as an arrow in non-window frames.
25401 See also `overlay-arrow-position'. */);
25402 Voverlay_arrow_string
= make_pure_c_string ("=>");
25404 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
25405 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
25406 The symbols on this list are examined during redisplay to determine
25407 where to display overlay arrows. */);
25408 Voverlay_arrow_variable_list
25409 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
25411 DEFVAR_INT ("scroll-step", &scroll_step
,
25412 doc
: /* *The number of lines to try scrolling a window by when point moves out.
25413 If that fails to bring point back on frame, point is centered instead.
25414 If this is zero, point is always centered after it moves off frame.
25415 If you want scrolling to always be a line at a time, you should set
25416 `scroll-conservatively' to a large value rather than set this to 1. */);
25418 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
25419 doc
: /* *Scroll up to this many lines, to bring point back on screen.
25420 If point moves off-screen, redisplay will scroll by up to
25421 `scroll-conservatively' lines in order to bring point just barely
25422 onto the screen again. If that cannot be done, then redisplay
25423 recenters point as usual.
25425 A value of zero means always recenter point if it moves off screen. */);
25426 scroll_conservatively
= 0;
25428 DEFVAR_INT ("scroll-margin", &scroll_margin
,
25429 doc
: /* *Number of lines of margin at the top and bottom of a window.
25430 Recenter the window whenever point gets within this many lines
25431 of the top or bottom of the window. */);
25434 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
25435 doc
: /* Pixels per inch value for non-window system displays.
25436 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
25437 Vdisplay_pixels_per_inch
= make_float (72.0);
25440 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
25443 DEFVAR_LISP ("truncate-partial-width-windows",
25444 &Vtruncate_partial_width_windows
,
25445 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
25446 For an integer value, truncate lines in each window narrower than the
25447 full frame width, provided the window width is less than that integer;
25448 otherwise, respect the value of `truncate-lines'.
25450 For any other non-nil value, truncate lines in all windows that do
25451 not span the full frame width.
25453 A value of nil means to respect the value of `truncate-lines'.
25455 If `word-wrap' is enabled, you might want to reduce this. */);
25456 Vtruncate_partial_width_windows
= make_number (50);
25458 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
25459 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
25460 Any other value means to use the appropriate face, `mode-line',
25461 `header-line', or `menu' respectively. */);
25462 mode_line_inverse_video
= 1;
25464 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
25465 doc
: /* *Maximum buffer size for which line number should be displayed.
25466 If the buffer is bigger than this, the line number does not appear
25467 in the mode line. A value of nil means no limit. */);
25468 Vline_number_display_limit
= Qnil
;
25470 DEFVAR_INT ("line-number-display-limit-width",
25471 &line_number_display_limit_width
,
25472 doc
: /* *Maximum line width (in characters) for line number display.
25473 If the average length of the lines near point is bigger than this, then the
25474 line number may be omitted from the mode line. */);
25475 line_number_display_limit_width
= 200;
25477 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
25478 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
25479 highlight_nonselected_windows
= 0;
25481 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
25482 doc
: /* Non-nil if more than one frame is visible on this display.
25483 Minibuffer-only frames don't count, but iconified frames do.
25484 This variable is not guaranteed to be accurate except while processing
25485 `frame-title-format' and `icon-title-format'. */);
25487 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
25488 doc
: /* Template for displaying the title bar of visible frames.
25489 \(Assuming the window manager supports this feature.)
25491 This variable has the same structure as `mode-line-format', except that
25492 the %c and %l constructs are ignored. It is used only on frames for
25493 which no explicit name has been set \(see `modify-frame-parameters'). */);
25495 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
25496 doc
: /* Template for displaying the title bar of an iconified frame.
25497 \(Assuming the window manager supports this feature.)
25498 This variable has the same structure as `mode-line-format' (which see),
25499 and is used only on frames for which no explicit name has been set
25500 \(see `modify-frame-parameters'). */);
25502 = Vframe_title_format
25503 = pure_cons (intern_c_string ("multiple-frames"),
25504 pure_cons (make_pure_c_string ("%b"),
25505 pure_cons (pure_cons (empty_unibyte_string
,
25506 pure_cons (intern_c_string ("invocation-name"),
25507 pure_cons (make_pure_c_string ("@"),
25508 pure_cons (intern_c_string ("system-name"),
25512 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
25513 doc
: /* Maximum number of lines to keep in the message log buffer.
25514 If nil, disable message logging. If t, log messages but don't truncate
25515 the buffer when it becomes large. */);
25516 Vmessage_log_max
= make_number (100);
25518 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
25519 doc
: /* Functions called before redisplay, if window sizes have changed.
25520 The value should be a list of functions that take one argument.
25521 Just before redisplay, for each frame, if any of its windows have changed
25522 size since the last redisplay, or have been split or deleted,
25523 all the functions in the list are called, with the frame as argument. */);
25524 Vwindow_size_change_functions
= Qnil
;
25526 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
25527 doc
: /* List of functions to call before redisplaying a window with scrolling.
25528 Each function is called with two arguments, the window and its new
25529 display-start position. Note that these functions are also called by
25530 `set-window-buffer'. Also note that the value of `window-end' is not
25531 valid when these functions are called. */);
25532 Vwindow_scroll_functions
= Qnil
;
25534 DEFVAR_LISP ("window-text-change-functions",
25535 &Vwindow_text_change_functions
,
25536 doc
: /* Functions to call in redisplay when text in the window might change. */);
25537 Vwindow_text_change_functions
= Qnil
;
25539 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
25540 doc
: /* Functions called when redisplay of a window reaches the end trigger.
25541 Each function is called with two arguments, the window and the end trigger value.
25542 See `set-window-redisplay-end-trigger'. */);
25543 Vredisplay_end_trigger_functions
= Qnil
;
25545 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
25546 doc
: /* *Non-nil means autoselect window with mouse pointer.
25547 If nil, do not autoselect windows.
25548 A positive number means delay autoselection by that many seconds: a
25549 window is autoselected only after the mouse has remained in that
25550 window for the duration of the delay.
25551 A negative number has a similar effect, but causes windows to be
25552 autoselected only after the mouse has stopped moving. \(Because of
25553 the way Emacs compares mouse events, you will occasionally wait twice
25554 that time before the window gets selected.\)
25555 Any other value means to autoselect window instantaneously when the
25556 mouse pointer enters it.
25558 Autoselection selects the minibuffer only if it is active, and never
25559 unselects the minibuffer if it is active.
25561 When customizing this variable make sure that the actual value of
25562 `focus-follows-mouse' matches the behavior of your window manager. */);
25563 Vmouse_autoselect_window
= Qnil
;
25565 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25566 doc
: /* *Non-nil means automatically resize tool-bars.
25567 This dynamically changes the tool-bar's height to the minimum height
25568 that is needed to make all tool-bar items visible.
25569 If value is `grow-only', the tool-bar's height is only increased
25570 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25571 Vauto_resize_tool_bars
= Qt
;
25573 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25574 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25575 auto_raise_tool_bar_buttons_p
= 1;
25577 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25578 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25579 make_cursor_line_fully_visible_p
= 1;
25581 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25582 doc
: /* *Border below tool-bar in pixels.
25583 If an integer, use it as the height of the border.
25584 If it is one of `internal-border-width' or `border-width', use the
25585 value of the corresponding frame parameter.
25586 Otherwise, no border is added below the tool-bar. */);
25587 Vtool_bar_border
= Qinternal_border_width
;
25589 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25590 doc
: /* *Margin around tool-bar buttons in pixels.
25591 If an integer, use that for both horizontal and vertical margins.
25592 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25593 HORZ specifying the horizontal margin, and VERT specifying the
25594 vertical margin. */);
25595 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25597 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25598 doc
: /* *Relief thickness of tool-bar buttons. */);
25599 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25601 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25602 doc
: /* List of functions to call to fontify regions of text.
25603 Each function is called with one argument POS. Functions must
25604 fontify a region starting at POS in the current buffer, and give
25605 fontified regions the property `fontified'. */);
25606 Vfontification_functions
= Qnil
;
25607 Fmake_variable_buffer_local (Qfontification_functions
);
25609 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25610 &unibyte_display_via_language_environment
,
25611 doc
: /* *Non-nil means display unibyte text according to language environment.
25612 Specifically, this means that raw bytes in the range 160-255 decimal
25613 are displayed by converting them to the equivalent multibyte characters
25614 according to the current language environment. As a result, they are
25615 displayed according to the current fontset.
25617 Note that this variable affects only how these bytes are displayed,
25618 but does not change the fact they are interpreted as raw bytes. */);
25619 unibyte_display_via_language_environment
= 0;
25621 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25622 doc
: /* *Maximum height for resizing mini-windows.
25623 If a float, it specifies a fraction of the mini-window frame's height.
25624 If an integer, it specifies a number of lines. */);
25625 Vmax_mini_window_height
= make_float (0.25);
25627 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25628 doc
: /* *How to resize mini-windows.
25629 A value of nil means don't automatically resize mini-windows.
25630 A value of t means resize them to fit the text displayed in them.
25631 A value of `grow-only', the default, means let mini-windows grow
25632 only, until their display becomes empty, at which point the windows
25633 go back to their normal size. */);
25634 Vresize_mini_windows
= Qgrow_only
;
25636 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25637 doc
: /* Alist specifying how to blink the cursor off.
25638 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25639 `cursor-type' frame-parameter or variable equals ON-STATE,
25640 comparing using `equal', Emacs uses OFF-STATE to specify
25641 how to blink it off. ON-STATE and OFF-STATE are values for
25642 the `cursor-type' frame parameter.
25644 If a frame's ON-STATE has no entry in this list,
25645 the frame's other specifications determine how to blink the cursor off. */);
25646 Vblink_cursor_alist
= Qnil
;
25648 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25649 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25650 automatic_hscrolling_p
= 1;
25651 Qauto_hscroll_mode
= intern_c_string ("auto-hscroll-mode");
25652 staticpro (&Qauto_hscroll_mode
);
25654 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25655 doc
: /* *How many columns away from the window edge point is allowed to get
25656 before automatic hscrolling will horizontally scroll the window. */);
25657 hscroll_margin
= 5;
25659 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25660 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25661 When point is less than `hscroll-margin' columns from the window
25662 edge, automatic hscrolling will scroll the window by the amount of columns
25663 determined by this variable. If its value is a positive integer, scroll that
25664 many columns. If it's a positive floating-point number, it specifies the
25665 fraction of the window's width to scroll. If it's nil or zero, point will be
25666 centered horizontally after the scroll. Any other value, including negative
25667 numbers, are treated as if the value were zero.
25669 Automatic hscrolling always moves point outside the scroll margin, so if
25670 point was more than scroll step columns inside the margin, the window will
25671 scroll more than the value given by the scroll step.
25673 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25674 and `scroll-right' overrides this variable's effect. */);
25675 Vhscroll_step
= make_number (0);
25677 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25678 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25679 Bind this around calls to `message' to let it take effect. */);
25680 message_truncate_lines
= 0;
25682 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25683 doc
: /* Normal hook run to update the menu bar definitions.
25684 Redisplay runs this hook before it redisplays the menu bar.
25685 This is used to update submenus such as Buffers,
25686 whose contents depend on various data. */);
25687 Vmenu_bar_update_hook
= Qnil
;
25689 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25690 doc
: /* Frame for which we are updating a menu.
25691 The enable predicate for a menu binding should check this variable. */);
25692 Vmenu_updating_frame
= Qnil
;
25694 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25695 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25696 inhibit_menubar_update
= 0;
25698 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25699 doc
: /* Prefix prepended to all continuation lines at display time.
25700 The value may be a string, an image, or a stretch-glyph; it is
25701 interpreted in the same way as the value of a `display' text property.
25703 This variable is overridden by any `wrap-prefix' text or overlay
25706 To add a prefix to non-continuation lines, use `line-prefix'. */);
25707 Vwrap_prefix
= Qnil
;
25708 staticpro (&Qwrap_prefix
);
25709 Qwrap_prefix
= intern_c_string ("wrap-prefix");
25710 Fmake_variable_buffer_local (Qwrap_prefix
);
25712 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25713 doc
: /* Prefix prepended to all non-continuation lines at display time.
25714 The value may be a string, an image, or a stretch-glyph; it is
25715 interpreted in the same way as the value of a `display' text property.
25717 This variable is overridden by any `line-prefix' text or overlay
25720 To add a prefix to continuation lines, use `wrap-prefix'. */);
25721 Vline_prefix
= Qnil
;
25722 staticpro (&Qline_prefix
);
25723 Qline_prefix
= intern_c_string ("line-prefix");
25724 Fmake_variable_buffer_local (Qline_prefix
);
25726 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25727 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25728 inhibit_eval_during_redisplay
= 0;
25730 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25731 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25732 inhibit_free_realized_faces
= 0;
25735 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25736 doc
: /* Inhibit try_window_id display optimization. */);
25737 inhibit_try_window_id
= 0;
25739 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25740 doc
: /* Inhibit try_window_reusing display optimization. */);
25741 inhibit_try_window_reusing
= 0;
25743 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25744 doc
: /* Inhibit try_cursor_movement display optimization. */);
25745 inhibit_try_cursor_movement
= 0;
25746 #endif /* GLYPH_DEBUG */
25748 DEFVAR_INT ("overline-margin", &overline_margin
,
25749 doc
: /* *Space between overline and text, in pixels.
25750 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25751 margin to the caracter height. */);
25752 overline_margin
= 2;
25754 DEFVAR_INT ("underline-minimum-offset",
25755 &underline_minimum_offset
,
25756 doc
: /* Minimum distance between baseline and underline.
25757 This can improve legibility of underlined text at small font sizes,
25758 particularly when using variable `x-use-underline-position-properties'
25759 with fonts that specify an UNDERLINE_POSITION relatively close to the
25760 baseline. The default value is 1. */);
25761 underline_minimum_offset
= 1;
25763 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25764 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25765 display_hourglass_p
= 1;
25767 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25768 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25769 Value must be an integer or float. */);
25770 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25772 hourglass_atimer
= NULL
;
25773 hourglass_shown_p
= 0;
25777 /* Initialize this module when Emacs starts. */
25782 Lisp_Object root_window
;
25783 struct window
*mini_w
;
25785 current_header_line_height
= current_mode_line_height
= -1;
25787 CHARPOS (this_line_start_pos
) = 0;
25789 mini_w
= XWINDOW (minibuf_window
);
25790 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25792 if (!noninteractive
)
25794 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25797 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25798 set_window_height (root_window
,
25799 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25801 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25802 set_window_height (minibuf_window
, 1, 0);
25804 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25805 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25807 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25808 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25809 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25811 /* The default ellipsis glyphs `...'. */
25812 for (i
= 0; i
< 3; ++i
)
25813 default_invis_vector
[i
] = make_number ('.');
25817 /* Allocate the buffer for frame titles.
25818 Also used for `format-mode-line'. */
25820 mode_line_noprop_buf
= (char *) xmalloc (size
);
25821 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25822 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25823 mode_line_target
= MODE_LINE_DISPLAY
;
25826 help_echo_showing_p
= 0;
25829 /* Since w32 does not support atimers, it defines its own implementation of
25830 the following three functions in w32fns.c. */
25833 /* Platform-independent portion of hourglass implementation. */
25835 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25837 hourglass_started ()
25839 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25842 /* Cancel a currently active hourglass timer, and start a new one. */
25846 #if defined (HAVE_WINDOW_SYSTEM)
25848 int secs
, usecs
= 0;
25850 cancel_hourglass ();
25852 if (INTEGERP (Vhourglass_delay
)
25853 && XINT (Vhourglass_delay
) > 0)
25854 secs
= XFASTINT (Vhourglass_delay
);
25855 else if (FLOATP (Vhourglass_delay
)
25856 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25859 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25860 secs
= XFASTINT (tem
);
25861 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25864 secs
= DEFAULT_HOURGLASS_DELAY
;
25866 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25867 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25868 show_hourglass
, NULL
);
25873 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25876 cancel_hourglass ()
25878 #if defined (HAVE_WINDOW_SYSTEM)
25879 if (hourglass_atimer
)
25881 cancel_atimer (hourglass_atimer
);
25882 hourglass_atimer
= NULL
;
25885 if (hourglass_shown_p
)
25889 #endif /* ! WINDOWSNT */
25891 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25892 (do not change this comment) */