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 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code. (Or,
35 let's say almost---see the description of direct update
38 The following diagram shows how redisplay code is invoked. As you
39 can see, Lisp calls redisplay and vice versa. Under window systems
40 like X, some portions of the redisplay code are also called
41 asynchronously during mouse movement or expose events. It is very
42 important that these code parts do NOT use the C library (malloc,
43 free) because many C libraries under Unix are not reentrant. They
44 may also NOT call functions of the Lisp interpreter which could
45 change the interpreter's state. If you don't follow these rules,
46 you will encounter bugs which are very hard to explain.
48 (Direct functions, see below)
49 direct_output_for_insert,
50 direct_forward_char (dispnew.c)
51 +---------------------------------+
54 +--------------+ redisplay +----------------+
55 | Lisp machine |---------------->| Redisplay code |<--+
56 +--------------+ (xdisp.c) +----------------+ |
58 +----------------------------------+ |
59 Don't use this path when called |
62 expose_window (asynchronous) |
64 X expose events -----+
66 What does redisplay do? Obviously, it has to figure out somehow what
67 has been changed since the last time the display has been updated,
68 and to make these changes visible. Preferably it would do that in
69 a moderately intelligent way, i.e. fast.
71 Changes in buffer text can be deduced from window and buffer
72 structures, and from some global variables like `beg_unchanged' and
73 `end_unchanged'. The contents of the display are additionally
74 recorded in a `glyph matrix', a two-dimensional matrix of glyph
75 structures. Each row in such a matrix corresponds to a line on the
76 display, and each glyph in a row corresponds to a column displaying
77 a character, an image, or what else. This matrix is called the
78 `current glyph matrix' or `current matrix' in redisplay
81 For buffer parts that have been changed since the last update, a
82 second glyph matrix is constructed, the so called `desired glyph
83 matrix' or short `desired matrix'. Current and desired matrix are
84 then compared to find a cheap way to update the display, e.g. by
85 reusing part of the display by scrolling lines.
90 You will find a lot of redisplay optimizations when you start
91 looking at the innards of redisplay. The overall goal of all these
92 optimizations is to make redisplay fast because it is done
95 Two optimizations are not found in xdisp.c. These are the direct
96 operations mentioned above. As the name suggests they follow a
97 different principle than the rest of redisplay. Instead of
98 building a desired matrix and then comparing it with the current
99 display, they perform their actions directly on the display and on
102 One direct operation updates the display after one character has
103 been entered. The other one moves the cursor by one position
104 forward or backward. You find these functions under the names
105 `direct_output_for_insert' and `direct_output_forward_char' in
111 Desired matrices are always built per Emacs window. The function
112 `display_line' is the central function to look at if you are
113 interested. It constructs one row in a desired matrix given an
114 iterator structure containing both a buffer position and a
115 description of the environment in which the text is to be
116 displayed. But this is too early, read on.
118 Characters and pixmaps displayed for a range of buffer text depend
119 on various settings of buffers and windows, on overlays and text
120 properties, on display tables, on selective display. The good news
121 is that all this hairy stuff is hidden behind a small set of
122 interface functions taking an iterator structure (struct it)
125 Iteration over things to be displayed is then simple. It is
126 started by initializing an iterator with a call to init_iterator.
127 Calls to get_next_display_element fill the iterator structure with
128 relevant information about the next thing to display. Calls to
129 set_iterator_to_next move the iterator to the next thing.
131 Besides this, an iterator also contains information about the
132 display environment in which glyphs for display elements are to be
133 produced. It has fields for the width and height of the display,
134 the information whether long lines are truncated or continued, a
135 current X and Y position, and lots of other stuff you can better
138 Glyphs in a desired matrix are normally constructed in a loop
139 calling get_next_display_element and then produce_glyphs. The call
140 to produce_glyphs will fill the iterator structure with pixel
141 information about the element being displayed and at the same time
142 produce glyphs for it. If the display element fits on the line
143 being displayed, set_iterator_to_next is called next, otherwise the
144 glyphs produced are discarded.
149 That just couldn't be all, could it? What about terminal types not
150 supporting operations on sub-windows of the screen? To update the
151 display on such a terminal, window-based glyph matrices are not
152 well suited. To be able to reuse part of the display (scrolling
153 lines up and down), we must instead have a view of the whole
154 screen. This is what `frame matrices' are for. They are a trick.
156 Frames on terminals like above have a glyph pool. Windows on such
157 a frame sub-allocate their glyph memory from their frame's glyph
158 pool. The frame itself is given its own glyph matrices. By
159 coincidence---or maybe something else---rows in window glyph
160 matrices are slices of corresponding rows in frame matrices. Thus
161 writing to window matrices implicitly updates a frame matrix which
162 provides us with the view of the whole screen that we originally
163 wanted to have without having to move many bytes around. To be
164 honest, there is a little bit more done, but not much more. If you
165 plan to extend that code, take a look at dispnew.c. The function
166 build_frame_matrix is a good starting point. */
172 #include "keyboard.h"
175 #include "termchar.h"
176 #include "dispextern.h"
178 #include "character.h"
181 #include "commands.h"
185 #include "termhooks.h"
186 #include "intervals.h"
189 #include "region-cache.h"
191 #include "blockinput.h"
193 #ifdef HAVE_X_WINDOWS
205 #ifndef FRAME_X_OUTPUT
206 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
209 #define INFINITY 10000000
211 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
212 || defined(HAVE_NS) || defined (USE_GTK)
213 extern void set_frame_menubar
P_ ((struct frame
*f
, int, int));
214 extern int pending_menu_activation
;
217 extern int interrupt_input
;
218 extern int command_loop_level
;
220 extern Lisp_Object do_mouse_tracking
;
222 extern int minibuffer_auto_raise
;
223 extern Lisp_Object Vminibuffer_list
;
225 extern Lisp_Object Qface
;
226 extern Lisp_Object Qmode_line
, Qmode_line_inactive
, Qheader_line
;
228 extern Lisp_Object Voverriding_local_map
;
229 extern Lisp_Object Voverriding_local_map_menu_flag
;
230 extern Lisp_Object Qmenu_item
;
231 extern Lisp_Object Qwhen
;
232 extern Lisp_Object Qhelp_echo
;
234 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
235 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
236 Lisp_Object Qwindow_text_change_functions
, Vwindow_text_change_functions
;
237 Lisp_Object Qredisplay_end_trigger_functions
, Vredisplay_end_trigger_functions
;
238 Lisp_Object Qinhibit_point_motion_hooks
;
239 Lisp_Object QCeval
, QCfile
, QCdata
, QCpropertize
;
240 Lisp_Object Qfontified
;
241 Lisp_Object Qgrow_only
;
242 Lisp_Object Qinhibit_eval_during_redisplay
;
243 Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
246 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
249 Lisp_Object Qarrow
, Qhand
, Qtext
;
251 Lisp_Object Qrisky_local_variable
;
253 /* Holds the list (error). */
254 Lisp_Object list_of_error
;
256 /* Functions called to fontify regions of text. */
258 Lisp_Object Vfontification_functions
;
259 Lisp_Object Qfontification_functions
;
261 /* Non-nil means automatically select any window when the mouse
262 cursor moves into it. */
263 Lisp_Object Vmouse_autoselect_window
;
265 Lisp_Object Vwrap_prefix
, Qwrap_prefix
;
266 Lisp_Object Vline_prefix
, Qline_prefix
;
268 /* Non-zero means draw tool bar buttons raised when the mouse moves
271 int auto_raise_tool_bar_buttons_p
;
273 /* Non-zero means to reposition window if cursor line is only partially visible. */
275 int make_cursor_line_fully_visible_p
;
277 /* Margin below tool bar in pixels. 0 or nil means no margin.
278 If value is `internal-border-width' or `border-width',
279 the corresponding frame parameter is used. */
281 Lisp_Object Vtool_bar_border
;
283 /* Margin around tool bar buttons in pixels. */
285 Lisp_Object Vtool_bar_button_margin
;
287 /* Thickness of shadow to draw around tool bar buttons. */
289 EMACS_INT tool_bar_button_relief
;
291 /* Non-nil means automatically resize tool-bars so that all tool-bar
292 items are visible, and no blank lines remain.
294 If value is `grow-only', only make tool-bar bigger. */
296 Lisp_Object Vauto_resize_tool_bars
;
298 /* Non-zero means draw block and hollow cursor as wide as the glyph
299 under it. For example, if a block cursor is over a tab, it will be
300 drawn as wide as that tab on the display. */
302 int x_stretch_cursor_p
;
304 /* Non-nil means don't actually do any redisplay. */
306 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
308 /* Non-zero means Lisp evaluation during redisplay is inhibited. */
310 int inhibit_eval_during_redisplay
;
312 /* Names of text properties relevant for redisplay. */
314 Lisp_Object Qdisplay
;
315 extern Lisp_Object Qface
, Qinvisible
, Qwidth
;
317 /* Symbols used in text property values. */
319 Lisp_Object Vdisplay_pixels_per_inch
;
320 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
321 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
324 Lisp_Object Qmargin
, Qpointer
;
325 Lisp_Object Qline_height
;
326 extern Lisp_Object Qheight
;
327 extern Lisp_Object QCwidth
, QCheight
, QCascent
;
328 extern Lisp_Object Qscroll_bar
;
329 extern Lisp_Object Qcursor
;
331 /* Non-nil means highlight trailing whitespace. */
333 Lisp_Object Vshow_trailing_whitespace
;
335 /* Non-nil means escape non-break space and hyphens. */
337 Lisp_Object Vnobreak_char_display
;
339 #ifdef HAVE_WINDOW_SYSTEM
340 extern Lisp_Object Voverflow_newline_into_fringe
;
342 /* Test if overflow newline into fringe. Called with iterator IT
343 at or past right window margin, and with IT->current_x set. */
345 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) \
346 (!NILP (Voverflow_newline_into_fringe) \
347 && FRAME_WINDOW_P (it->f) \
348 && WINDOW_RIGHT_FRINGE_WIDTH (it->w) > 0 \
349 && it->current_x == it->last_visible_x \
350 && it->line_wrap != WORD_WRAP)
352 #endif /* HAVE_WINDOW_SYSTEM */
354 /* Test if the display element loaded in IT is a space or tab
355 character. This is used to determine word wrapping. */
357 #define IT_DISPLAYING_WHITESPACE(it) \
358 (it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t'))
360 /* Non-nil means show the text cursor in void text areas
361 i.e. in blank areas after eol and eob. This used to be
362 the default in 21.3. */
364 Lisp_Object Vvoid_text_area_pointer
;
366 /* Name of the face used to highlight trailing whitespace. */
368 Lisp_Object Qtrailing_whitespace
;
370 /* Name and number of the face used to highlight escape glyphs. */
372 Lisp_Object Qescape_glyph
;
374 /* Name and number of the face used to highlight non-breaking spaces. */
376 Lisp_Object Qnobreak_space
;
378 /* The symbol `image' which is the car of the lists used to represent
383 /* The image map types. */
384 Lisp_Object QCmap
, QCpointer
;
385 Lisp_Object Qrect
, Qcircle
, Qpoly
;
387 /* Non-zero means print newline to stdout before next mini-buffer
390 int noninteractive_need_newline
;
392 /* Non-zero means print newline to message log before next message. */
394 static int message_log_need_newline
;
396 /* Three markers that message_dolog uses.
397 It could allocate them itself, but that causes trouble
398 in handling memory-full errors. */
399 static Lisp_Object message_dolog_marker1
;
400 static Lisp_Object message_dolog_marker2
;
401 static Lisp_Object message_dolog_marker3
;
403 /* The buffer position of the first character appearing entirely or
404 partially on the line of the selected window which contains the
405 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
406 redisplay optimization in redisplay_internal. */
408 static struct text_pos this_line_start_pos
;
410 /* Number of characters past the end of the line above, including the
411 terminating newline. */
413 static struct text_pos this_line_end_pos
;
415 /* The vertical positions and the height of this line. */
417 static int this_line_vpos
;
418 static int this_line_y
;
419 static int this_line_pixel_height
;
421 /* X position at which this display line starts. Usually zero;
422 negative if first character is partially visible. */
424 static int this_line_start_x
;
426 /* Buffer that this_line_.* variables are referring to. */
428 static struct buffer
*this_line_buffer
;
430 /* Nonzero means truncate lines in all windows less wide than the
433 Lisp_Object Vtruncate_partial_width_windows
;
435 /* A flag to control how to display unibyte 8-bit character. */
437 int unibyte_display_via_language_environment
;
439 /* Nonzero means we have more than one non-mini-buffer-only frame.
440 Not guaranteed to be accurate except while parsing
441 frame-title-format. */
445 Lisp_Object Vglobal_mode_string
;
448 /* List of variables (symbols) which hold markers for overlay arrows.
449 The symbols on this list are examined during redisplay to determine
450 where to display overlay arrows. */
452 Lisp_Object Voverlay_arrow_variable_list
;
454 /* Marker for where to display an arrow on top of the buffer text. */
456 Lisp_Object Voverlay_arrow_position
;
458 /* String to display for the arrow. Only used on terminal frames. */
460 Lisp_Object Voverlay_arrow_string
;
462 /* Values of those variables at last redisplay are stored as
463 properties on `overlay-arrow-position' symbol. However, if
464 Voverlay_arrow_position is a marker, last-arrow-position is its
465 numerical position. */
467 Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
469 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
470 properties on a symbol in overlay-arrow-variable-list. */
472 Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
474 /* Like mode-line-format, but for the title bar on a visible frame. */
476 Lisp_Object Vframe_title_format
;
478 /* Like mode-line-format, but for the title bar on an iconified frame. */
480 Lisp_Object Vicon_title_format
;
482 /* List of functions to call when a window's size changes. These
483 functions get one arg, a frame on which one or more windows' sizes
486 static Lisp_Object Vwindow_size_change_functions
;
488 Lisp_Object Qmenu_bar_update_hook
, Vmenu_bar_update_hook
;
490 /* Nonzero if an overlay arrow has been displayed in this window. */
492 static int overlay_arrow_seen
;
494 /* Nonzero means highlight the region even in nonselected windows. */
496 int highlight_nonselected_windows
;
498 /* If cursor motion alone moves point off frame, try scrolling this
499 many lines up or down if that will bring it back. */
501 static EMACS_INT scroll_step
;
503 /* Nonzero means scroll just far enough to bring point back on the
504 screen, when appropriate. */
506 static EMACS_INT scroll_conservatively
;
508 /* Recenter the window whenever point gets within this many lines of
509 the top or bottom of the window. This value is translated into a
510 pixel value by multiplying it with FRAME_LINE_HEIGHT, which means
511 that there is really a fixed pixel height scroll margin. */
513 EMACS_INT scroll_margin
;
515 /* Number of windows showing the buffer of the selected window (or
516 another buffer with the same base buffer). keyboard.c refers to
521 /* Vector containing glyphs for an ellipsis `...'. */
523 static Lisp_Object default_invis_vector
[3];
525 /* Zero means display the mode-line/header-line/menu-bar in the default face
526 (this slightly odd definition is for compatibility with previous versions
527 of emacs), non-zero means display them using their respective faces.
529 This variable is deprecated. */
531 int mode_line_inverse_video
;
533 /* Prompt to display in front of the mini-buffer contents. */
535 Lisp_Object minibuf_prompt
;
537 /* Width of current mini-buffer prompt. Only set after display_line
538 of the line that contains the prompt. */
540 int minibuf_prompt_width
;
542 /* This is the window where the echo area message was displayed. It
543 is always a mini-buffer window, but it may not be the same window
544 currently active as a mini-buffer. */
546 Lisp_Object echo_area_window
;
548 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
549 pushes the current message and the value of
550 message_enable_multibyte on the stack, the function restore_message
551 pops the stack and displays MESSAGE again. */
553 Lisp_Object Vmessage_stack
;
555 /* Nonzero means multibyte characters were enabled when the echo area
556 message was specified. */
558 int message_enable_multibyte
;
560 /* Nonzero if we should redraw the mode lines on the next redisplay. */
562 int update_mode_lines
;
564 /* Nonzero if window sizes or contents have changed since last
565 redisplay that finished. */
567 int windows_or_buffers_changed
;
569 /* Nonzero means a frame's cursor type has been changed. */
571 int cursor_type_changed
;
573 /* Nonzero after display_mode_line if %l was used and it displayed a
576 int line_number_displayed
;
578 /* Maximum buffer size for which to display line numbers. */
580 Lisp_Object Vline_number_display_limit
;
582 /* Line width to consider when repositioning for line number display. */
584 static EMACS_INT line_number_display_limit_width
;
586 /* Number of lines to keep in the message log buffer. t means
587 infinite. nil means don't log at all. */
589 Lisp_Object Vmessage_log_max
;
591 /* The name of the *Messages* buffer, a string. */
593 static Lisp_Object Vmessages_buffer_name
;
595 /* Current, index 0, and last displayed echo area message. Either
596 buffers from echo_buffers, or nil to indicate no message. */
598 Lisp_Object echo_area_buffer
[2];
600 /* The buffers referenced from echo_area_buffer. */
602 static Lisp_Object echo_buffer
[2];
604 /* A vector saved used in with_area_buffer to reduce consing. */
606 static Lisp_Object Vwith_echo_area_save_vector
;
608 /* Non-zero means display_echo_area should display the last echo area
609 message again. Set by redisplay_preserve_echo_area. */
611 static int display_last_displayed_message_p
;
613 /* Nonzero if echo area is being used by print; zero if being used by
616 int message_buf_print
;
618 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
620 Lisp_Object Qinhibit_menubar_update
;
621 int inhibit_menubar_update
;
623 /* When evaluating expressions from menu bar items (enable conditions,
624 for instance), this is the frame they are being processed for. */
626 Lisp_Object Vmenu_updating_frame
;
628 /* Maximum height for resizing mini-windows. Either a float
629 specifying a fraction of the available height, or an integer
630 specifying a number of lines. */
632 Lisp_Object Vmax_mini_window_height
;
634 /* Non-zero means messages should be displayed with truncated
635 lines instead of being continued. */
637 int message_truncate_lines
;
638 Lisp_Object Qmessage_truncate_lines
;
640 /* Set to 1 in clear_message to make redisplay_internal aware
641 of an emptied echo area. */
643 static int message_cleared_p
;
645 /* How to blink the default frame cursor off. */
646 Lisp_Object Vblink_cursor_alist
;
648 /* A scratch glyph row with contents used for generating truncation
649 glyphs. Also used in direct_output_for_insert. */
651 #define MAX_SCRATCH_GLYPHS 100
652 struct glyph_row scratch_glyph_row
;
653 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
655 /* Ascent and height of the last line processed by move_it_to. */
657 static int last_max_ascent
, last_height
;
659 /* Non-zero if there's a help-echo in the echo area. */
661 int help_echo_showing_p
;
663 /* If >= 0, computed, exact values of mode-line and header-line height
664 to use in the macros CURRENT_MODE_LINE_HEIGHT and
665 CURRENT_HEADER_LINE_HEIGHT. */
667 int current_mode_line_height
, current_header_line_height
;
669 /* The maximum distance to look ahead for text properties. Values
670 that are too small let us call compute_char_face and similar
671 functions too often which is expensive. Values that are too large
672 let us call compute_char_face and alike too often because we
673 might not be interested in text properties that far away. */
675 #define TEXT_PROP_DISTANCE_LIMIT 100
679 /* Variables to turn off display optimizations from Lisp. */
681 int inhibit_try_window_id
, inhibit_try_window_reusing
;
682 int inhibit_try_cursor_movement
;
684 /* Non-zero means print traces of redisplay if compiled with
687 int trace_redisplay_p
;
689 #endif /* GLYPH_DEBUG */
691 #ifdef DEBUG_TRACE_MOVE
692 /* Non-zero means trace with TRACE_MOVE to stderr. */
695 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
697 #define TRACE_MOVE(x) (void) 0
700 /* Non-zero means automatically scroll windows horizontally to make
703 int automatic_hscrolling_p
;
704 Lisp_Object Qauto_hscroll_mode
;
706 /* How close to the margin can point get before the window is scrolled
708 EMACS_INT hscroll_margin
;
710 /* How much to scroll horizontally when point is inside the above margin. */
711 Lisp_Object Vhscroll_step
;
713 /* The variable `resize-mini-windows'. If nil, don't resize
714 mini-windows. If t, always resize them to fit the text they
715 display. If `grow-only', let mini-windows grow only until they
718 Lisp_Object Vresize_mini_windows
;
720 /* Buffer being redisplayed -- for redisplay_window_error. */
722 struct buffer
*displayed_buffer
;
724 /* Space between overline and text. */
726 EMACS_INT overline_margin
;
728 /* Require underline to be at least this many screen pixels below baseline
729 This to avoid underline "merging" with the base of letters at small
730 font sizes, particularly when x_use_underline_position_properties is on. */
732 EMACS_INT underline_minimum_offset
;
734 /* Value returned from text property handlers (see below). */
739 HANDLED_RECOMPUTE_PROPS
,
740 HANDLED_OVERLAY_STRING_CONSUMED
,
744 /* A description of text properties that redisplay is interested
749 /* The name of the property. */
752 /* A unique index for the property. */
755 /* A handler function called to set up iterator IT from the property
756 at IT's current position. Value is used to steer handle_stop. */
757 enum prop_handled (*handler
) P_ ((struct it
*it
));
760 static enum prop_handled handle_face_prop
P_ ((struct it
*));
761 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
762 static enum prop_handled handle_display_prop
P_ ((struct it
*));
763 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
764 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
765 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
766 static enum prop_handled handle_auto_composed_prop
P_ ((struct it
*));
768 /* Properties handled by iterators. */
770 static struct props it_props
[] =
772 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
773 /* Handle `face' before `display' because some sub-properties of
774 `display' need to know the face. */
775 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
776 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
777 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
778 {&Qauto_composed
, AUTO_COMPOSED_PROP_IDX
, handle_auto_composed_prop
},
779 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
783 /* Value is the position described by X. If X is a marker, value is
784 the marker_position of X. Otherwise, value is X. */
786 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
788 /* Enumeration returned by some move_it_.* functions internally. */
792 /* Not used. Undefined value. */
795 /* Move ended at the requested buffer position or ZV. */
796 MOVE_POS_MATCH_OR_ZV
,
798 /* Move ended at the requested X pixel position. */
801 /* Move within a line ended at the end of a line that must be
805 /* Move within a line ended at the end of a line that would
806 be displayed truncated. */
809 /* Move within a line ended at a line end. */
813 /* This counter is used to clear the face cache every once in a while
814 in redisplay_internal. It is incremented for each redisplay.
815 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
818 #define CLEAR_FACE_CACHE_COUNT 500
819 static int clear_face_cache_count
;
821 /* Similarly for the image cache. */
823 #ifdef HAVE_WINDOW_SYSTEM
824 #define CLEAR_IMAGE_CACHE_COUNT 101
825 static int clear_image_cache_count
;
828 /* Non-zero while redisplay_internal is in progress. */
832 /* Non-zero means don't free realized faces. Bound while freeing
833 realized faces is dangerous because glyph matrices might still
836 int inhibit_free_realized_faces
;
837 Lisp_Object Qinhibit_free_realized_faces
;
839 /* If a string, XTread_socket generates an event to display that string.
840 (The display is done in read_char.) */
842 Lisp_Object help_echo_string
;
843 Lisp_Object help_echo_window
;
844 Lisp_Object help_echo_object
;
847 /* Temporary variable for XTread_socket. */
849 Lisp_Object previous_help_echo_string
;
851 /* Null glyph slice */
853 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
855 /* Platform-independent portion of hourglass implementation. */
857 /* Non-zero means we're allowed to display a hourglass pointer. */
858 int display_hourglass_p
;
860 /* Non-zero means an hourglass cursor is currently shown. */
861 int hourglass_shown_p
;
863 /* If non-null, an asynchronous timer that, when it expires, displays
864 an hourglass cursor on all frames. */
865 struct atimer
*hourglass_atimer
;
867 /* Number of seconds to wait before displaying an hourglass cursor. */
868 Lisp_Object Vhourglass_delay
;
870 /* Default number of seconds to wait before displaying an hourglass
872 #define DEFAULT_HOURGLASS_DELAY 1
875 /* Function prototypes. */
877 static void setup_for_ellipsis
P_ ((struct it
*, int));
878 static void mark_window_display_accurate_1
P_ ((struct window
*, int));
879 static int single_display_spec_string_p
P_ ((Lisp_Object
, Lisp_Object
));
880 static int display_prop_string_p
P_ ((Lisp_Object
, Lisp_Object
));
881 static int cursor_row_p
P_ ((struct window
*, struct glyph_row
*));
882 static int redisplay_mode_lines
P_ ((Lisp_Object
, int));
883 static char *decode_mode_spec_coding
P_ ((Lisp_Object
, char *, int));
885 static Lisp_Object get_it_property
P_ ((struct it
*it
, Lisp_Object prop
));
887 static void handle_line_prefix
P_ ((struct it
*));
890 static int invisible_text_between_p
P_ ((struct it
*, int, int));
893 static void pint2str
P_ ((char *, int, int));
894 static void pint2hrstr
P_ ((char *, int, int));
895 static struct text_pos run_window_scroll_functions
P_ ((Lisp_Object
,
897 static void reconsider_clip_changes
P_ ((struct window
*, struct buffer
*));
898 static int text_outside_line_unchanged_p
P_ ((struct window
*, int, int));
899 static void store_mode_line_noprop_char
P_ ((char));
900 static int store_mode_line_noprop
P_ ((const unsigned char *, int, int));
901 static void x_consider_frame_title
P_ ((Lisp_Object
));
902 static void handle_stop
P_ ((struct it
*));
903 static int tool_bar_lines_needed
P_ ((struct frame
*, int *));
904 static int single_display_spec_intangible_p
P_ ((Lisp_Object
));
905 static void ensure_echo_area_buffers
P_ ((void));
906 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
907 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
908 static int with_echo_area_buffer
P_ ((struct window
*, int,
909 int (*) (EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
),
910 EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
911 static void clear_garbaged_frames
P_ ((void));
912 static int current_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
913 static int truncate_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
914 static int set_message_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
915 static int display_echo_area
P_ ((struct window
*));
916 static int display_echo_area_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
917 static int resize_mini_window_1
P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
918 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
919 static int string_char_and_length
P_ ((const unsigned char *, int, int *));
920 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
922 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
923 static Lisp_Object safe_eval_handler
P_ ((Lisp_Object
));
924 static void insert_left_trunc_glyphs
P_ ((struct it
*));
925 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*,
927 static void extend_face_to_end_of_line
P_ ((struct it
*));
928 static int append_space_for_newline
P_ ((struct it
*, int));
929 static int cursor_row_fully_visible_p
P_ ((struct window
*, int, int));
930 static int try_scrolling
P_ ((Lisp_Object
, int, EMACS_INT
, EMACS_INT
, int, int));
931 static int try_cursor_movement
P_ ((Lisp_Object
, struct text_pos
, int *));
932 static int trailing_whitespace_p
P_ ((int));
933 static int message_log_check_duplicate
P_ ((int, int, int, int));
934 static void push_it
P_ ((struct it
*));
935 static void pop_it
P_ ((struct it
*));
936 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
937 static void select_frame_for_redisplay
P_ ((Lisp_Object
));
938 static void redisplay_internal
P_ ((int));
939 static int echo_area_display
P_ ((int));
940 static void redisplay_windows
P_ ((Lisp_Object
));
941 static void redisplay_window
P_ ((Lisp_Object
, int));
942 static Lisp_Object
redisplay_window_error ();
943 static Lisp_Object redisplay_window_0
P_ ((Lisp_Object
));
944 static Lisp_Object redisplay_window_1
P_ ((Lisp_Object
));
945 static int update_menu_bar
P_ ((struct frame
*, int, int));
946 static int try_window_reusing_current_matrix
P_ ((struct window
*));
947 static int try_window_id
P_ ((struct window
*));
948 static int display_line
P_ ((struct it
*));
949 static int display_mode_lines
P_ ((struct window
*));
950 static int display_mode_line
P_ ((struct window
*, enum face_id
, Lisp_Object
));
951 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int));
952 static int store_mode_line_string
P_ ((char *, Lisp_Object
, int, int, int, Lisp_Object
));
953 static char *decode_mode_spec
P_ ((struct window
*, int, int, int, int *));
954 static void display_menu_bar
P_ ((struct window
*));
955 static int display_count_lines
P_ ((int, int, int, int, int *));
956 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
957 EMACS_INT
, EMACS_INT
, struct it
*, int, int, int, int));
958 static void compute_line_metrics
P_ ((struct it
*));
959 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
960 static int get_overlay_strings
P_ ((struct it
*, int));
961 static int get_overlay_strings_1
P_ ((struct it
*, int, int));
962 static void next_overlay_string
P_ ((struct it
*));
963 static void reseat
P_ ((struct it
*, struct text_pos
, int));
964 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
965 static void back_to_previous_visible_line_start
P_ ((struct it
*));
966 void reseat_at_previous_visible_line_start
P_ ((struct it
*));
967 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
968 static int next_element_from_ellipsis
P_ ((struct it
*));
969 static int next_element_from_display_vector
P_ ((struct it
*));
970 static int next_element_from_string
P_ ((struct it
*));
971 static int next_element_from_c_string
P_ ((struct it
*));
972 static int next_element_from_buffer
P_ ((struct it
*));
973 static int next_element_from_composition
P_ ((struct it
*));
974 static int next_element_from_image
P_ ((struct it
*));
975 static int next_element_from_stretch
P_ ((struct it
*));
976 static void load_overlay_strings
P_ ((struct it
*, int));
977 static int init_from_display_pos
P_ ((struct it
*, struct window
*,
978 struct display_pos
*));
979 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
980 Lisp_Object
, int, int, int, int));
981 static enum move_it_result
982 move_it_in_display_line_to (struct it
*, EMACS_INT
, int,
983 enum move_operation_enum
);
984 void move_it_vertically_backward
P_ ((struct it
*, int));
985 static void init_to_row_start
P_ ((struct it
*, struct window
*,
986 struct glyph_row
*));
987 static int init_to_row_end
P_ ((struct it
*, struct window
*,
988 struct glyph_row
*));
989 static void back_to_previous_line_start
P_ ((struct it
*));
990 static int forward_to_next_line_start
P_ ((struct it
*, int *));
991 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
993 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
994 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
995 static int number_of_chars
P_ ((unsigned char *, int));
996 static void compute_stop_pos
P_ ((struct it
*));
997 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
999 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
1000 static EMACS_INT next_overlay_change
P_ ((EMACS_INT
));
1001 static int handle_single_display_spec
P_ ((struct it
*, Lisp_Object
,
1002 Lisp_Object
, Lisp_Object
,
1003 struct text_pos
*, int));
1004 static int underlying_face_id
P_ ((struct it
*));
1005 static int in_ellipses_for_invisible_text_p
P_ ((struct display_pos
*,
1008 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
1009 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
1011 #ifdef HAVE_WINDOW_SYSTEM
1013 static void update_tool_bar
P_ ((struct frame
*, int));
1014 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
1015 static int redisplay_tool_bar
P_ ((struct frame
*));
1016 static void display_tool_bar_line
P_ ((struct it
*, int));
1017 static void notice_overwritten_cursor
P_ ((struct window
*,
1018 enum glyph_row_area
,
1019 int, int, int, int));
1023 #endif /* HAVE_WINDOW_SYSTEM */
1026 /***********************************************************************
1027 Window display dimensions
1028 ***********************************************************************/
1030 /* Return the bottom boundary y-position for text lines in window W.
1031 This is the first y position at which a line cannot start.
1032 It is relative to the top of the window.
1034 This is the height of W minus the height of a mode line, if any. */
1037 window_text_bottom_y (w
)
1040 int height
= WINDOW_TOTAL_HEIGHT (w
);
1042 if (WINDOW_WANTS_MODELINE_P (w
))
1043 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1047 /* Return the pixel width of display area AREA of window W. AREA < 0
1048 means return the total width of W, not including fringes to
1049 the left and right of the window. */
1052 window_box_width (w
, area
)
1056 int cols
= XFASTINT (w
->total_cols
);
1059 if (!w
->pseudo_window_p
)
1061 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1063 if (area
== TEXT_AREA
)
1065 if (INTEGERP (w
->left_margin_cols
))
1066 cols
-= XFASTINT (w
->left_margin_cols
);
1067 if (INTEGERP (w
->right_margin_cols
))
1068 cols
-= XFASTINT (w
->right_margin_cols
);
1069 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1071 else if (area
== LEFT_MARGIN_AREA
)
1073 cols
= (INTEGERP (w
->left_margin_cols
)
1074 ? XFASTINT (w
->left_margin_cols
) : 0);
1077 else if (area
== RIGHT_MARGIN_AREA
)
1079 cols
= (INTEGERP (w
->right_margin_cols
)
1080 ? XFASTINT (w
->right_margin_cols
) : 0);
1085 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1089 /* Return the pixel height of the display area of window W, not
1090 including mode lines of W, if any. */
1093 window_box_height (w
)
1096 struct frame
*f
= XFRAME (w
->frame
);
1097 int height
= WINDOW_TOTAL_HEIGHT (w
);
1099 xassert (height
>= 0);
1101 /* Note: the code below that determines the mode-line/header-line
1102 height is essentially the same as that contained in the macro
1103 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1104 the appropriate glyph row has its `mode_line_p' flag set,
1105 and if it doesn't, uses estimate_mode_line_height instead. */
1107 if (WINDOW_WANTS_MODELINE_P (w
))
1109 struct glyph_row
*ml_row
1110 = (w
->current_matrix
&& w
->current_matrix
->rows
1111 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1113 if (ml_row
&& ml_row
->mode_line_p
)
1114 height
-= ml_row
->height
;
1116 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1119 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1121 struct glyph_row
*hl_row
1122 = (w
->current_matrix
&& w
->current_matrix
->rows
1123 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1125 if (hl_row
&& hl_row
->mode_line_p
)
1126 height
-= hl_row
->height
;
1128 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1131 /* With a very small font and a mode-line that's taller than
1132 default, we might end up with a negative height. */
1133 return max (0, height
);
1136 /* Return the window-relative coordinate of the left edge of display
1137 area AREA of window W. AREA < 0 means return the left edge of the
1138 whole window, to the right of the left fringe of W. */
1141 window_box_left_offset (w
, area
)
1147 if (w
->pseudo_window_p
)
1150 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1152 if (area
== TEXT_AREA
)
1153 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1154 + window_box_width (w
, LEFT_MARGIN_AREA
));
1155 else if (area
== RIGHT_MARGIN_AREA
)
1156 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1157 + window_box_width (w
, LEFT_MARGIN_AREA
)
1158 + window_box_width (w
, TEXT_AREA
)
1159 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1161 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1162 else if (area
== LEFT_MARGIN_AREA
1163 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1164 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1170 /* Return the window-relative coordinate of the right edge of display
1171 area AREA of window W. AREA < 0 means return the left edge of the
1172 whole window, to the left of the right fringe of W. */
1175 window_box_right_offset (w
, area
)
1179 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1182 /* Return the frame-relative coordinate of the left edge of display
1183 area AREA of window W. AREA < 0 means return the left edge of the
1184 whole window, to the right of the left fringe of W. */
1187 window_box_left (w
, area
)
1191 struct frame
*f
= XFRAME (w
->frame
);
1194 if (w
->pseudo_window_p
)
1195 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1197 x
= (WINDOW_LEFT_EDGE_X (w
)
1198 + window_box_left_offset (w
, area
));
1204 /* Return the frame-relative coordinate of the right edge of display
1205 area AREA of window W. AREA < 0 means return the left edge of the
1206 whole window, to the left of the right fringe of W. */
1209 window_box_right (w
, area
)
1213 return window_box_left (w
, area
) + window_box_width (w
, area
);
1216 /* Get the bounding box of the display area AREA of window W, without
1217 mode lines, in frame-relative coordinates. AREA < 0 means the
1218 whole window, not including the left and right fringes of
1219 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1220 coordinates of the upper-left corner of the box. Return in
1221 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1224 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
1227 int *box_x
, *box_y
, *box_width
, *box_height
;
1230 *box_width
= window_box_width (w
, area
);
1232 *box_height
= window_box_height (w
);
1234 *box_x
= window_box_left (w
, area
);
1237 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1238 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1239 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1244 /* Get the bounding box of the display area AREA of window W, without
1245 mode lines. AREA < 0 means the whole window, not including the
1246 left and right fringe of the window. Return in *TOP_LEFT_X
1247 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1248 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1249 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1253 window_box_edges (w
, area
, top_left_x
, top_left_y
,
1254 bottom_right_x
, bottom_right_y
)
1257 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
1259 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1261 *bottom_right_x
+= *top_left_x
;
1262 *bottom_right_y
+= *top_left_y
;
1267 /***********************************************************************
1269 ***********************************************************************/
1271 /* Return the bottom y-position of the line the iterator IT is in.
1272 This can modify IT's settings. */
1278 int line_height
= it
->max_ascent
+ it
->max_descent
;
1279 int line_top_y
= it
->current_y
;
1281 if (line_height
== 0)
1284 line_height
= last_height
;
1285 else if (IT_CHARPOS (*it
) < ZV
)
1287 move_it_by_lines (it
, 1, 1);
1288 line_height
= (it
->max_ascent
|| it
->max_descent
1289 ? it
->max_ascent
+ it
->max_descent
1294 struct glyph_row
*row
= it
->glyph_row
;
1296 /* Use the default character height. */
1297 it
->glyph_row
= NULL
;
1298 it
->what
= IT_CHARACTER
;
1301 PRODUCE_GLYPHS (it
);
1302 line_height
= it
->ascent
+ it
->descent
;
1303 it
->glyph_row
= row
;
1307 return line_top_y
+ line_height
;
1311 /* Return 1 if position CHARPOS is visible in window W.
1312 CHARPOS < 0 means return info about WINDOW_END position.
1313 If visible, set *X and *Y to pixel coordinates of top left corner.
1314 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1315 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1318 pos_visible_p (w
, charpos
, x
, y
, rtop
, rbot
, rowh
, vpos
)
1320 int charpos
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
;
1323 struct text_pos top
;
1325 struct buffer
*old_buffer
= NULL
;
1330 if (XBUFFER (w
->buffer
) != current_buffer
)
1332 old_buffer
= current_buffer
;
1333 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1336 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1338 /* Compute exact mode line heights. */
1339 if (WINDOW_WANTS_MODELINE_P (w
))
1340 current_mode_line_height
1341 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1342 current_buffer
->mode_line_format
);
1344 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1345 current_header_line_height
1346 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1347 current_buffer
->header_line_format
);
1349 start_display (&it
, w
, top
);
1350 move_it_to (&it
, charpos
, -1, it
.last_visible_y
-1, -1,
1351 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1353 /* Note that we may overshoot because of invisible text. */
1354 if (charpos
>= 0 && IT_CHARPOS (it
) >= charpos
)
1356 int top_x
= it
.current_x
;
1357 int top_y
= it
.current_y
;
1358 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1359 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1361 if (top_y
< window_top_y
)
1362 visible_p
= bottom_y
> window_top_y
;
1363 else if (top_y
< it
.last_visible_y
)
1367 if (it
.method
== GET_FROM_BUFFER
)
1369 Lisp_Object window
, prop
;
1371 XSETWINDOW (window
, w
);
1372 prop
= Fget_char_property (make_number (it
.position
.charpos
),
1373 Qinvisible
, window
);
1375 /* If charpos coincides with invisible text covered with an
1376 ellipsis, use the first glyph of the ellipsis to compute
1377 the pixel positions. */
1378 if (TEXT_PROP_MEANS_INVISIBLE (prop
) == 2)
1380 struct glyph_row
*row
= it
.glyph_row
;
1381 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1382 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
1385 for (; glyph
< end
&& glyph
->charpos
< charpos
; glyph
++)
1386 x
+= glyph
->pixel_width
;
1393 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1394 *rtop
= max (0, window_top_y
- top_y
);
1395 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1396 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1397 - max (top_y
, window_top_y
)));
1406 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1407 move_it_by_lines (&it
, 1, 0);
1408 if (charpos
< IT_CHARPOS (it
)
1409 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1412 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1414 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1415 *rtop
= max (0, -it2
.current_y
);
1416 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1417 - it
.last_visible_y
));
1418 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1420 - max (it2
.current_y
,
1421 WINDOW_HEADER_LINE_HEIGHT (w
))));
1427 set_buffer_internal_1 (old_buffer
);
1429 current_header_line_height
= current_mode_line_height
= -1;
1431 if (visible_p
&& XFASTINT (w
->hscroll
) > 0)
1432 *x
-= XFASTINT (w
->hscroll
) * WINDOW_FRAME_COLUMN_WIDTH (w
);
1435 /* Debugging code. */
1437 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1438 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1440 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1447 /* Return the next character from STR which is MAXLEN bytes long.
1448 Return in *LEN the length of the character. This is like
1449 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
1450 we find one, we return a `?', but with the length of the invalid
1454 string_char_and_length (str
, maxlen
, len
)
1455 const unsigned char *str
;
1460 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
1461 if (!CHAR_VALID_P (c
, 1))
1462 /* We may not change the length here because other places in Emacs
1463 don't use this function, i.e. they silently accept invalid
1472 /* Given a position POS containing a valid character and byte position
1473 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1475 static struct text_pos
1476 string_pos_nchars_ahead (pos
, string
, nchars
)
1477 struct text_pos pos
;
1481 xassert (STRINGP (string
) && nchars
>= 0);
1483 if (STRING_MULTIBYTE (string
))
1485 int rest
= SBYTES (string
) - BYTEPOS (pos
);
1486 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1491 string_char_and_length (p
, rest
, &len
);
1492 p
+= len
, rest
-= len
;
1493 xassert (rest
>= 0);
1495 BYTEPOS (pos
) += len
;
1499 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1505 /* Value is the text position, i.e. character and byte position,
1506 for character position CHARPOS in STRING. */
1508 static INLINE
struct text_pos
1509 string_pos (charpos
, string
)
1513 struct text_pos pos
;
1514 xassert (STRINGP (string
));
1515 xassert (charpos
>= 0);
1516 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1521 /* Value is a text position, i.e. character and byte position, for
1522 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1523 means recognize multibyte characters. */
1525 static struct text_pos
1526 c_string_pos (charpos
, s
, multibyte_p
)
1531 struct text_pos pos
;
1533 xassert (s
!= NULL
);
1534 xassert (charpos
>= 0);
1538 int rest
= strlen (s
), len
;
1540 SET_TEXT_POS (pos
, 0, 0);
1543 string_char_and_length (s
, rest
, &len
);
1544 s
+= len
, rest
-= len
;
1545 xassert (rest
>= 0);
1547 BYTEPOS (pos
) += len
;
1551 SET_TEXT_POS (pos
, charpos
, charpos
);
1557 /* Value is the number of characters in C string S. MULTIBYTE_P
1558 non-zero means recognize multibyte characters. */
1561 number_of_chars (s
, multibyte_p
)
1569 int rest
= strlen (s
), len
;
1570 unsigned char *p
= (unsigned char *) s
;
1572 for (nchars
= 0; rest
> 0; ++nchars
)
1574 string_char_and_length (p
, rest
, &len
);
1575 rest
-= len
, p
+= len
;
1579 nchars
= strlen (s
);
1585 /* Compute byte position NEWPOS->bytepos corresponding to
1586 NEWPOS->charpos. POS is a known position in string STRING.
1587 NEWPOS->charpos must be >= POS.charpos. */
1590 compute_string_pos (newpos
, pos
, string
)
1591 struct text_pos
*newpos
, pos
;
1594 xassert (STRINGP (string
));
1595 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1597 if (STRING_MULTIBYTE (string
))
1598 *newpos
= string_pos_nchars_ahead (pos
, string
,
1599 CHARPOS (*newpos
) - CHARPOS (pos
));
1601 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1605 Return an estimation of the pixel height of mode or top lines on
1606 frame F. FACE_ID specifies what line's height to estimate. */
1609 estimate_mode_line_height (f
, face_id
)
1611 enum face_id face_id
;
1613 #ifdef HAVE_WINDOW_SYSTEM
1614 if (FRAME_WINDOW_P (f
))
1616 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1618 /* This function is called so early when Emacs starts that the face
1619 cache and mode line face are not yet initialized. */
1620 if (FRAME_FACE_CACHE (f
))
1622 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1626 height
= FONT_HEIGHT (face
->font
);
1627 if (face
->box_line_width
> 0)
1628 height
+= 2 * face
->box_line_width
;
1639 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1640 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1641 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1642 not force the value into range. */
1645 pixel_to_glyph_coords (f
, pix_x
, pix_y
, x
, y
, bounds
, noclip
)
1647 register int pix_x
, pix_y
;
1649 NativeRectangle
*bounds
;
1653 #ifdef HAVE_WINDOW_SYSTEM
1654 if (FRAME_WINDOW_P (f
))
1656 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1657 even for negative values. */
1659 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1661 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1663 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1664 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1667 STORE_NATIVE_RECT (*bounds
,
1668 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1669 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1670 FRAME_COLUMN_WIDTH (f
) - 1,
1671 FRAME_LINE_HEIGHT (f
) - 1);
1677 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1678 pix_x
= FRAME_TOTAL_COLS (f
);
1682 else if (pix_y
> FRAME_LINES (f
))
1683 pix_y
= FRAME_LINES (f
);
1693 /* Given HPOS/VPOS in the current matrix of W, return corresponding
1694 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1695 can't tell the positions because W's display is not up to date,
1699 glyph_to_pixel_coords (w
, hpos
, vpos
, frame_x
, frame_y
)
1702 int *frame_x
, *frame_y
;
1704 #ifdef HAVE_WINDOW_SYSTEM
1705 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w
))))
1709 xassert (hpos
>= 0 && hpos
< w
->current_matrix
->matrix_w
);
1710 xassert (vpos
>= 0 && vpos
< w
->current_matrix
->matrix_h
);
1712 if (display_completed
)
1714 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
1715 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
1716 struct glyph
*end
= glyph
+ min (hpos
, row
->used
[TEXT_AREA
]);
1722 hpos
+= glyph
->pixel_width
;
1726 /* If first glyph is partially visible, its first visible position is still 0. */
1738 *frame_x
= WINDOW_TO_FRAME_PIXEL_X (w
, hpos
);
1739 *frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, vpos
);
1750 #ifdef HAVE_WINDOW_SYSTEM
1752 /* Find the glyph under window-relative coordinates X/Y in window W.
1753 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1754 strings. Return in *HPOS and *VPOS the row and column number of
1755 the glyph found. Return in *AREA the glyph area containing X.
1756 Value is a pointer to the glyph found or null if X/Y is not on
1757 text, or we can't tell because W's current matrix is not up to
1762 x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, dx
, dy
, area
)
1765 int *hpos
, *vpos
, *dx
, *dy
, *area
;
1767 struct glyph
*glyph
, *end
;
1768 struct glyph_row
*row
= NULL
;
1771 /* Find row containing Y. Give up if some row is not enabled. */
1772 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1774 row
= MATRIX_ROW (w
->current_matrix
, i
);
1775 if (!row
->enabled_p
)
1777 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1784 /* Give up if Y is not in the window. */
1785 if (i
== w
->current_matrix
->nrows
)
1788 /* Get the glyph area containing X. */
1789 if (w
->pseudo_window_p
)
1796 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1798 *area
= LEFT_MARGIN_AREA
;
1799 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1801 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1804 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1808 *area
= RIGHT_MARGIN_AREA
;
1809 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1813 /* Find glyph containing X. */
1814 glyph
= row
->glyphs
[*area
];
1815 end
= glyph
+ row
->used
[*area
];
1817 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1819 x
-= glyph
->pixel_width
;
1829 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1832 *hpos
= glyph
- row
->glyphs
[*area
];
1838 Convert frame-relative x/y to coordinates relative to window W.
1839 Takes pseudo-windows into account. */
1842 frame_to_window_pixel_xy (w
, x
, y
)
1846 if (w
->pseudo_window_p
)
1848 /* A pseudo-window is always full-width, and starts at the
1849 left edge of the frame, plus a frame border. */
1850 struct frame
*f
= XFRAME (w
->frame
);
1851 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1852 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1856 *x
-= WINDOW_LEFT_EDGE_X (w
);
1857 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1862 Return in RECTS[] at most N clipping rectangles for glyph string S.
1863 Return the number of stored rectangles. */
1866 get_glyph_string_clip_rects (s
, rects
, n
)
1867 struct glyph_string
*s
;
1868 NativeRectangle
*rects
;
1876 if (s
->row
->full_width_p
)
1878 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1879 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1880 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1882 /* Unless displaying a mode or menu bar line, which are always
1883 fully visible, clip to the visible part of the row. */
1884 if (s
->w
->pseudo_window_p
)
1885 r
.height
= s
->row
->visible_height
;
1887 r
.height
= s
->height
;
1891 /* This is a text line that may be partially visible. */
1892 r
.x
= window_box_left (s
->w
, s
->area
);
1893 r
.width
= window_box_width (s
->w
, s
->area
);
1894 r
.height
= s
->row
->visible_height
;
1898 if (r
.x
< s
->clip_head
->x
)
1900 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1901 r
.width
-= s
->clip_head
->x
- r
.x
;
1904 r
.x
= s
->clip_head
->x
;
1907 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1909 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1910 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1915 /* If S draws overlapping rows, it's sufficient to use the top and
1916 bottom of the window for clipping because this glyph string
1917 intentionally draws over other lines. */
1918 if (s
->for_overlaps
)
1920 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1921 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
1923 /* Alas, the above simple strategy does not work for the
1924 environments with anti-aliased text: if the same text is
1925 drawn onto the same place multiple times, it gets thicker.
1926 If the overlap we are processing is for the erased cursor, we
1927 take the intersection with the rectagle of the cursor. */
1928 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
1930 XRectangle rc
, r_save
= r
;
1932 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
1933 rc
.y
= s
->w
->phys_cursor
.y
;
1934 rc
.width
= s
->w
->phys_cursor_width
;
1935 rc
.height
= s
->w
->phys_cursor_height
;
1937 x_intersect_rectangles (&r_save
, &rc
, &r
);
1942 /* Don't use S->y for clipping because it doesn't take partially
1943 visible lines into account. For example, it can be negative for
1944 partially visible lines at the top of a window. */
1945 if (!s
->row
->full_width_p
1946 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
1947 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
1949 r
.y
= max (0, s
->row
->y
);
1951 /* If drawing a tool-bar window, draw it over the internal border
1952 at the top of the window. */
1953 if (WINDOWP (s
->f
->tool_bar_window
)
1954 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
1955 r
.y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
1958 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
1960 /* If drawing the cursor, don't let glyph draw outside its
1961 advertised boundaries. Cleartype does this under some circumstances. */
1962 if (s
->hl
== DRAW_CURSOR
)
1964 struct glyph
*glyph
= s
->first_glyph
;
1969 r
.width
-= s
->x
- r
.x
;
1972 r
.width
= min (r
.width
, glyph
->pixel_width
);
1974 /* If r.y is below window bottom, ensure that we still see a cursor. */
1975 height
= min (glyph
->ascent
+ glyph
->descent
,
1976 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
1977 max_y
= window_text_bottom_y (s
->w
) - height
;
1978 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
1979 if (s
->ybase
- glyph
->ascent
> max_y
)
1986 /* Don't draw cursor glyph taller than our actual glyph. */
1987 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
1988 if (height
< r
.height
)
1990 max_y
= r
.y
+ r
.height
;
1991 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
1992 r
.height
= min (max_y
- r
.y
, height
);
1999 XRectangle r_save
= r
;
2001 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2005 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2006 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2008 #ifdef CONVERT_FROM_XRECT
2009 CONVERT_FROM_XRECT (r
, *rects
);
2017 /* If we are processing overlapping and allowed to return
2018 multiple clipping rectangles, we exclude the row of the glyph
2019 string from the clipping rectangle. This is to avoid drawing
2020 the same text on the environment with anti-aliasing. */
2021 #ifdef CONVERT_FROM_XRECT
2024 XRectangle
*rs
= rects
;
2026 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2028 if (s
->for_overlaps
& OVERLAPS_PRED
)
2031 if (r
.y
+ r
.height
> row_y
)
2034 rs
[i
].height
= row_y
- r
.y
;
2040 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2043 if (r
.y
< row_y
+ s
->row
->visible_height
)
2045 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2047 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2048 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2057 #ifdef CONVERT_FROM_XRECT
2058 for (i
= 0; i
< n
; i
++)
2059 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2066 Return in *NR the clipping rectangle for glyph string S. */
2069 get_glyph_string_clip_rect (s
, nr
)
2070 struct glyph_string
*s
;
2071 NativeRectangle
*nr
;
2073 get_glyph_string_clip_rects (s
, nr
, 1);
2078 Return the position and height of the phys cursor in window W.
2079 Set w->phys_cursor_width to width of phys cursor.
2083 get_phys_cursor_geometry (w
, row
, glyph
, xp
, yp
, heightp
)
2085 struct glyph_row
*row
;
2086 struct glyph
*glyph
;
2087 int *xp
, *yp
, *heightp
;
2089 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2090 int x
, y
, wd
, h
, h0
, y0
;
2092 /* Compute the width of the rectangle to draw. If on a stretch
2093 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2094 rectangle as wide as the glyph, but use a canonical character
2096 wd
= glyph
->pixel_width
- 1;
2101 x
= w
->phys_cursor
.x
;
2108 if (glyph
->type
== STRETCH_GLYPH
2109 && !x_stretch_cursor_p
)
2110 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2111 w
->phys_cursor_width
= wd
;
2113 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2115 /* If y is below window bottom, ensure that we still see a cursor. */
2116 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2118 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2119 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2121 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2124 h
= max (h
- (y0
- y
) + 1, h0
);
2129 y0
= window_text_bottom_y (w
) - h0
;
2137 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2138 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2143 * Remember which glyph the mouse is over.
2147 remember_mouse_glyph (f
, gx
, gy
, rect
)
2150 NativeRectangle
*rect
;
2154 struct glyph_row
*r
, *gr
, *end_row
;
2155 enum window_part part
;
2156 enum glyph_row_area area
;
2157 int x
, y
, width
, height
;
2159 /* Try to determine frame pixel position and size of the glyph under
2160 frame pixel coordinates X/Y on frame F. */
2162 if (!f
->glyphs_initialized_p
2163 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, &x
, &y
, 0),
2166 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2167 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2171 w
= XWINDOW (window
);
2172 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2173 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2175 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2176 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2178 if (w
->pseudo_window_p
)
2181 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2187 case ON_LEFT_MARGIN
:
2188 area
= LEFT_MARGIN_AREA
;
2191 case ON_RIGHT_MARGIN
:
2192 area
= RIGHT_MARGIN_AREA
;
2195 case ON_HEADER_LINE
:
2197 gr
= (part
== ON_HEADER_LINE
2198 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2199 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2202 goto text_glyph_row_found
;
2209 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2210 if (r
->y
+ r
->height
> y
)
2216 text_glyph_row_found
:
2219 struct glyph
*g
= gr
->glyphs
[area
];
2220 struct glyph
*end
= g
+ gr
->used
[area
];
2222 height
= gr
->height
;
2223 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2224 if (gx
+ g
->pixel_width
> x
)
2229 if (g
->type
== IMAGE_GLYPH
)
2231 /* Don't remember when mouse is over image, as
2232 image may have hot-spots. */
2233 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2236 width
= g
->pixel_width
;
2240 /* Use nominal char spacing at end of line. */
2242 gx
+= (x
/ width
) * width
;
2245 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2246 gx
+= window_box_left_offset (w
, area
);
2250 /* Use nominal line height at end of window. */
2251 gx
= (x
/ width
) * width
;
2253 gy
+= (y
/ height
) * height
;
2257 case ON_LEFT_FRINGE
:
2258 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2259 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2260 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2261 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2264 case ON_RIGHT_FRINGE
:
2265 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2266 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2267 : window_box_right_offset (w
, TEXT_AREA
));
2268 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2272 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2274 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2275 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2276 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2278 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2282 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2283 if (r
->y
+ r
->height
> y
)
2290 height
= gr
->height
;
2293 /* Use nominal line height at end of window. */
2295 gy
+= (y
/ height
) * height
;
2302 /* If there is no glyph under the mouse, then we divide the screen
2303 into a grid of the smallest glyph in the frame, and use that
2306 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2307 round down even for negative values. */
2313 gx
= (gx
/ width
) * width
;
2314 gy
= (gy
/ height
) * height
;
2319 gx
+= WINDOW_LEFT_EDGE_X (w
);
2320 gy
+= WINDOW_TOP_EDGE_Y (w
);
2323 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2325 /* Visible feedback for debugging. */
2328 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2329 f
->output_data
.x
->normal_gc
,
2330 gx
, gy
, width
, height
);
2336 #endif /* HAVE_WINDOW_SYSTEM */
2339 /***********************************************************************
2340 Lisp form evaluation
2341 ***********************************************************************/
2343 /* Error handler for safe_eval and safe_call. */
2346 safe_eval_handler (arg
)
2349 add_to_log ("Error during redisplay: %s", arg
, Qnil
);
2354 /* Evaluate SEXPR and return the result, or nil if something went
2355 wrong. Prevent redisplay during the evaluation. */
2357 /* Call function ARGS[0] with arguments ARGS[1] to ARGS[NARGS - 1].
2358 Return the result, or nil if something went wrong. Prevent
2359 redisplay during the evaluation. */
2362 safe_call (nargs
, args
)
2368 if (inhibit_eval_during_redisplay
)
2372 int count
= SPECPDL_INDEX ();
2373 struct gcpro gcpro1
;
2376 gcpro1
.nvars
= nargs
;
2377 specbind (Qinhibit_redisplay
, Qt
);
2378 /* Use Qt to ensure debugger does not run,
2379 so there is no possibility of wanting to redisplay. */
2380 val
= internal_condition_case_2 (Ffuncall
, nargs
, args
, Qt
,
2383 val
= unbind_to (count
, val
);
2390 /* Call function FN with one argument ARG.
2391 Return the result, or nil if something went wrong. */
2394 safe_call1 (fn
, arg
)
2395 Lisp_Object fn
, arg
;
2397 Lisp_Object args
[2];
2400 return safe_call (2, args
);
2403 static Lisp_Object Qeval
;
2406 safe_eval (Lisp_Object sexpr
)
2408 return safe_call1 (Qeval
, sexpr
);
2411 /* Call function FN with one argument ARG.
2412 Return the result, or nil if something went wrong. */
2415 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2417 Lisp_Object args
[3];
2421 return safe_call (3, args
);
2426 /***********************************************************************
2428 ***********************************************************************/
2432 /* Define CHECK_IT to perform sanity checks on iterators.
2433 This is for debugging. It is too slow to do unconditionally. */
2439 if (it
->method
== GET_FROM_STRING
)
2441 xassert (STRINGP (it
->string
));
2442 xassert (IT_STRING_CHARPOS (*it
) >= 0);
2446 xassert (IT_STRING_CHARPOS (*it
) < 0);
2447 if (it
->method
== GET_FROM_BUFFER
)
2449 /* Check that character and byte positions agree. */
2450 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2455 xassert (it
->current
.dpvec_index
>= 0);
2457 xassert (it
->current
.dpvec_index
< 0);
2460 #define CHECK_IT(IT) check_it ((IT))
2464 #define CHECK_IT(IT) (void) 0
2471 /* Check that the window end of window W is what we expect it
2472 to be---the last row in the current matrix displaying text. */
2475 check_window_end (w
)
2478 if (!MINI_WINDOW_P (w
)
2479 && !NILP (w
->window_end_valid
))
2481 struct glyph_row
*row
;
2482 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
2483 XFASTINT (w
->window_end_vpos
)),
2485 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2486 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2490 #define CHECK_WINDOW_END(W) check_window_end ((W))
2492 #else /* not GLYPH_DEBUG */
2494 #define CHECK_WINDOW_END(W) (void) 0
2496 #endif /* not GLYPH_DEBUG */
2500 /***********************************************************************
2501 Iterator initialization
2502 ***********************************************************************/
2504 /* Initialize IT for displaying current_buffer in window W, starting
2505 at character position CHARPOS. CHARPOS < 0 means that no buffer
2506 position is specified which is useful when the iterator is assigned
2507 a position later. BYTEPOS is the byte position corresponding to
2508 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2510 If ROW is not null, calls to produce_glyphs with IT as parameter
2511 will produce glyphs in that row.
2513 BASE_FACE_ID is the id of a base face to use. It must be one of
2514 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2515 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2516 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2518 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2519 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2520 will be initialized to use the corresponding mode line glyph row of
2521 the desired matrix of W. */
2524 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
2527 int charpos
, bytepos
;
2528 struct glyph_row
*row
;
2529 enum face_id base_face_id
;
2531 int highlight_region_p
;
2532 enum face_id remapped_base_face_id
= base_face_id
;
2534 /* Some precondition checks. */
2535 xassert (w
!= NULL
&& it
!= NULL
);
2536 xassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2539 /* If face attributes have been changed since the last redisplay,
2540 free realized faces now because they depend on face definitions
2541 that might have changed. Don't free faces while there might be
2542 desired matrices pending which reference these faces. */
2543 if (face_change_count
&& !inhibit_free_realized_faces
)
2545 face_change_count
= 0;
2546 free_all_realized_faces (Qnil
);
2549 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2550 if (! NILP (Vface_remapping_alist
))
2551 remapped_base_face_id
= lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2553 /* Use one of the mode line rows of W's desired matrix if
2557 if (base_face_id
== MODE_LINE_FACE_ID
2558 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2559 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2560 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2561 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2565 bzero (it
, sizeof *it
);
2566 it
->current
.overlay_string_index
= -1;
2567 it
->current
.dpvec_index
= -1;
2568 it
->base_face_id
= remapped_base_face_id
;
2570 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2572 /* The window in which we iterate over current_buffer: */
2573 XSETWINDOW (it
->window
, w
);
2575 it
->f
= XFRAME (w
->frame
);
2577 /* Extra space between lines (on window systems only). */
2578 if (base_face_id
== DEFAULT_FACE_ID
2579 && FRAME_WINDOW_P (it
->f
))
2581 if (NATNUMP (current_buffer
->extra_line_spacing
))
2582 it
->extra_line_spacing
= XFASTINT (current_buffer
->extra_line_spacing
);
2583 else if (FLOATP (current_buffer
->extra_line_spacing
))
2584 it
->extra_line_spacing
= (XFLOAT_DATA (current_buffer
->extra_line_spacing
)
2585 * FRAME_LINE_HEIGHT (it
->f
));
2586 else if (it
->f
->extra_line_spacing
> 0)
2587 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2588 it
->max_extra_line_spacing
= 0;
2591 /* If realized faces have been removed, e.g. because of face
2592 attribute changes of named faces, recompute them. When running
2593 in batch mode, the face cache of the initial frame is null. If
2594 we happen to get called, make a dummy face cache. */
2595 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2596 init_frame_faces (it
->f
);
2597 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2598 recompute_basic_faces (it
->f
);
2600 /* Current value of the `slice', `space-width', and 'height' properties. */
2601 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2602 it
->space_width
= Qnil
;
2603 it
->font_height
= Qnil
;
2604 it
->override_ascent
= -1;
2606 /* Are control characters displayed as `^C'? */
2607 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
2609 /* -1 means everything between a CR and the following line end
2610 is invisible. >0 means lines indented more than this value are
2612 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
2613 ? XFASTINT (current_buffer
->selective_display
)
2614 : (!NILP (current_buffer
->selective_display
)
2616 it
->selective_display_ellipsis_p
2617 = !NILP (current_buffer
->selective_display_ellipses
);
2619 /* Display table to use. */
2620 it
->dp
= window_display_table (w
);
2622 /* Are multibyte characters enabled in current_buffer? */
2623 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2625 /* Non-zero if we should highlight the region. */
2627 = (!NILP (Vtransient_mark_mode
)
2628 && !NILP (current_buffer
->mark_active
)
2629 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
2631 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
2632 start and end of a visible region in window IT->w. Set both to
2633 -1 to indicate no region. */
2634 if (highlight_region_p
2635 /* Maybe highlight only in selected window. */
2636 && (/* Either show region everywhere. */
2637 highlight_nonselected_windows
2638 /* Or show region in the selected window. */
2639 || w
== XWINDOW (selected_window
)
2640 /* Or show the region if we are in the mini-buffer and W is
2641 the window the mini-buffer refers to. */
2642 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2643 && WINDOWP (minibuf_selected_window
)
2644 && w
== XWINDOW (minibuf_selected_window
))))
2646 int charpos
= marker_position (current_buffer
->mark
);
2647 it
->region_beg_charpos
= min (PT
, charpos
);
2648 it
->region_end_charpos
= max (PT
, charpos
);
2651 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2653 /* Get the position at which the redisplay_end_trigger hook should
2654 be run, if it is to be run at all. */
2655 if (MARKERP (w
->redisplay_end_trigger
)
2656 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2657 it
->redisplay_end_trigger_charpos
2658 = marker_position (w
->redisplay_end_trigger
);
2659 else if (INTEGERP (w
->redisplay_end_trigger
))
2660 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
2662 /* Correct bogus values of tab_width. */
2663 it
->tab_width
= XINT (current_buffer
->tab_width
);
2664 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
2667 /* Are lines in the display truncated? */
2668 if (base_face_id
!= DEFAULT_FACE_ID
2669 || XINT (it
->w
->hscroll
)
2670 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2671 && ((!NILP (Vtruncate_partial_width_windows
)
2672 && !INTEGERP (Vtruncate_partial_width_windows
))
2673 || (INTEGERP (Vtruncate_partial_width_windows
)
2674 && (WINDOW_TOTAL_COLS (it
->w
)
2675 < XINT (Vtruncate_partial_width_windows
))))))
2676 it
->line_wrap
= TRUNCATE
;
2677 else if (NILP (current_buffer
->truncate_lines
))
2678 it
->line_wrap
= NILP (current_buffer
->word_wrap
)
2679 ? WINDOW_WRAP
: WORD_WRAP
;
2681 it
->line_wrap
= TRUNCATE
;
2683 /* Get dimensions of truncation and continuation glyphs. These are
2684 displayed as fringe bitmaps under X, so we don't need them for such
2686 if (!FRAME_WINDOW_P (it
->f
))
2688 if (it
->line_wrap
== TRUNCATE
)
2690 /* We will need the truncation glyph. */
2691 xassert (it
->glyph_row
== NULL
);
2692 produce_special_glyphs (it
, IT_TRUNCATION
);
2693 it
->truncation_pixel_width
= it
->pixel_width
;
2697 /* We will need the continuation glyph. */
2698 xassert (it
->glyph_row
== NULL
);
2699 produce_special_glyphs (it
, IT_CONTINUATION
);
2700 it
->continuation_pixel_width
= it
->pixel_width
;
2703 /* Reset these values to zero because the produce_special_glyphs
2704 above has changed them. */
2705 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2706 it
->phys_ascent
= it
->phys_descent
= 0;
2709 /* Set this after getting the dimensions of truncation and
2710 continuation glyphs, so that we don't produce glyphs when calling
2711 produce_special_glyphs, above. */
2712 it
->glyph_row
= row
;
2713 it
->area
= TEXT_AREA
;
2715 /* Get the dimensions of the display area. The display area
2716 consists of the visible window area plus a horizontally scrolled
2717 part to the left of the window. All x-values are relative to the
2718 start of this total display area. */
2719 if (base_face_id
!= DEFAULT_FACE_ID
)
2721 /* Mode lines, menu bar in terminal frames. */
2722 it
->first_visible_x
= 0;
2723 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2728 = XFASTINT (it
->w
->hscroll
) * FRAME_COLUMN_WIDTH (it
->f
);
2729 it
->last_visible_x
= (it
->first_visible_x
2730 + window_box_width (w
, TEXT_AREA
));
2732 /* If we truncate lines, leave room for the truncator glyph(s) at
2733 the right margin. Otherwise, leave room for the continuation
2734 glyph(s). Truncation and continuation glyphs are not inserted
2735 for window-based redisplay. */
2736 if (!FRAME_WINDOW_P (it
->f
))
2738 if (it
->line_wrap
== TRUNCATE
)
2739 it
->last_visible_x
-= it
->truncation_pixel_width
;
2741 it
->last_visible_x
-= it
->continuation_pixel_width
;
2744 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2745 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2748 /* Leave room for a border glyph. */
2749 if (!FRAME_WINDOW_P (it
->f
)
2750 && !WINDOW_RIGHTMOST_P (it
->w
))
2751 it
->last_visible_x
-= 1;
2753 it
->last_visible_y
= window_text_bottom_y (w
);
2755 /* For mode lines and alike, arrange for the first glyph having a
2756 left box line if the face specifies a box. */
2757 if (base_face_id
!= DEFAULT_FACE_ID
)
2761 it
->face_id
= remapped_base_face_id
;
2763 /* If we have a boxed mode line, make the first character appear
2764 with a left box line. */
2765 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2766 if (face
->box
!= FACE_NO_BOX
)
2767 it
->start_of_box_run_p
= 1;
2770 /* If a buffer position was specified, set the iterator there,
2771 getting overlays and face properties from that position. */
2772 if (charpos
>= BUF_BEG (current_buffer
))
2774 it
->end_charpos
= ZV
;
2776 IT_CHARPOS (*it
) = charpos
;
2778 /* Compute byte position if not specified. */
2779 if (bytepos
< charpos
)
2780 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2782 IT_BYTEPOS (*it
) = bytepos
;
2784 it
->start
= it
->current
;
2786 /* Compute faces etc. */
2787 reseat (it
, it
->current
.pos
, 1);
2794 /* Initialize IT for the display of window W with window start POS. */
2797 start_display (it
, w
, pos
)
2800 struct text_pos pos
;
2802 struct glyph_row
*row
;
2803 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2805 row
= w
->desired_matrix
->rows
+ first_vpos
;
2806 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2807 it
->first_vpos
= first_vpos
;
2809 /* Don't reseat to previous visible line start if current start
2810 position is in a string or image. */
2811 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2813 int start_at_line_beg_p
;
2814 int first_y
= it
->current_y
;
2816 /* If window start is not at a line start, skip forward to POS to
2817 get the correct continuation lines width. */
2818 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2819 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2820 if (!start_at_line_beg_p
)
2824 reseat_at_previous_visible_line_start (it
);
2825 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2827 new_x
= it
->current_x
+ it
->pixel_width
;
2829 /* If lines are continued, this line may end in the middle
2830 of a multi-glyph character (e.g. a control character
2831 displayed as \003, or in the middle of an overlay
2832 string). In this case move_it_to above will not have
2833 taken us to the start of the continuation line but to the
2834 end of the continued line. */
2835 if (it
->current_x
> 0
2836 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2837 && (/* And glyph doesn't fit on the line. */
2838 new_x
> it
->last_visible_x
2839 /* Or it fits exactly and we're on a window
2841 || (new_x
== it
->last_visible_x
2842 && FRAME_WINDOW_P (it
->f
))))
2844 if (it
->current
.dpvec_index
>= 0
2845 || it
->current
.overlay_string_index
>= 0)
2847 set_iterator_to_next (it
, 1);
2848 move_it_in_display_line_to (it
, -1, -1, 0);
2851 it
->continuation_lines_width
+= it
->current_x
;
2854 /* We're starting a new display line, not affected by the
2855 height of the continued line, so clear the appropriate
2856 fields in the iterator structure. */
2857 it
->max_ascent
= it
->max_descent
= 0;
2858 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2860 it
->current_y
= first_y
;
2862 it
->current_x
= it
->hpos
= 0;
2866 #if 0 /* Don't assert the following because start_display is sometimes
2867 called intentionally with a window start that is not at a
2868 line start. Please leave this code in as a comment. */
2870 /* Window start should be on a line start, now. */
2871 xassert (it
->continuation_lines_width
2872 || IT_CHARPOS (it
) == BEGV
2873 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
2878 /* Return 1 if POS is a position in ellipses displayed for invisible
2879 text. W is the window we display, for text property lookup. */
2882 in_ellipses_for_invisible_text_p (pos
, w
)
2883 struct display_pos
*pos
;
2886 Lisp_Object prop
, window
;
2888 int charpos
= CHARPOS (pos
->pos
);
2890 /* If POS specifies a position in a display vector, this might
2891 be for an ellipsis displayed for invisible text. We won't
2892 get the iterator set up for delivering that ellipsis unless
2893 we make sure that it gets aware of the invisible text. */
2894 if (pos
->dpvec_index
>= 0
2895 && pos
->overlay_string_index
< 0
2896 && CHARPOS (pos
->string_pos
) < 0
2898 && (XSETWINDOW (window
, w
),
2899 prop
= Fget_char_property (make_number (charpos
),
2900 Qinvisible
, window
),
2901 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
2903 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
2905 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
2912 /* Initialize IT for stepping through current_buffer in window W,
2913 starting at position POS that includes overlay string and display
2914 vector/ control character translation position information. Value
2915 is zero if there are overlay strings with newlines at POS. */
2918 init_from_display_pos (it
, w
, pos
)
2921 struct display_pos
*pos
;
2923 int charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
2924 int i
, overlay_strings_with_newlines
= 0;
2926 /* If POS specifies a position in a display vector, this might
2927 be for an ellipsis displayed for invisible text. We won't
2928 get the iterator set up for delivering that ellipsis unless
2929 we make sure that it gets aware of the invisible text. */
2930 if (in_ellipses_for_invisible_text_p (pos
, w
))
2936 /* Keep in mind: the call to reseat in init_iterator skips invisible
2937 text, so we might end up at a position different from POS. This
2938 is only a problem when POS is a row start after a newline and an
2939 overlay starts there with an after-string, and the overlay has an
2940 invisible property. Since we don't skip invisible text in
2941 display_line and elsewhere immediately after consuming the
2942 newline before the row start, such a POS will not be in a string,
2943 but the call to init_iterator below will move us to the
2945 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
2947 /* This only scans the current chunk -- it should scan all chunks.
2948 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
2949 to 16 in 22.1 to make this a lesser problem. */
2950 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
2952 const char *s
= SDATA (it
->overlay_strings
[i
]);
2953 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
2955 while (s
< e
&& *s
!= '\n')
2960 overlay_strings_with_newlines
= 1;
2965 /* If position is within an overlay string, set up IT to the right
2967 if (pos
->overlay_string_index
>= 0)
2971 /* If the first overlay string happens to have a `display'
2972 property for an image, the iterator will be set up for that
2973 image, and we have to undo that setup first before we can
2974 correct the overlay string index. */
2975 if (it
->method
== GET_FROM_IMAGE
)
2978 /* We already have the first chunk of overlay strings in
2979 IT->overlay_strings. Load more until the one for
2980 pos->overlay_string_index is in IT->overlay_strings. */
2981 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
2983 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
2984 it
->current
.overlay_string_index
= 0;
2987 load_overlay_strings (it
, 0);
2988 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
2992 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
2993 relative_index
= (it
->current
.overlay_string_index
2994 % OVERLAY_STRING_CHUNK_SIZE
);
2995 it
->string
= it
->overlay_strings
[relative_index
];
2996 xassert (STRINGP (it
->string
));
2997 it
->current
.string_pos
= pos
->string_pos
;
2998 it
->method
= GET_FROM_STRING
;
3001 #if 0 /* This is bogus because POS not having an overlay string
3002 position does not mean it's after the string. Example: A
3003 line starting with a before-string and initialization of IT
3004 to the previous row's end position. */
3005 else if (it
->current
.overlay_string_index
>= 0)
3007 /* If POS says we're already after an overlay string ending at
3008 POS, make sure to pop the iterator because it will be in
3009 front of that overlay string. When POS is ZV, we've thereby
3010 also ``processed'' overlay strings at ZV. */
3013 xassert (it
->current
.overlay_string_index
== -1);
3014 xassert (it
->method
== GET_FROM_BUFFER
);
3015 if (CHARPOS (pos
->pos
) == ZV
)
3016 it
->overlay_strings_at_end_processed_p
= 1;
3020 if (CHARPOS (pos
->string_pos
) >= 0)
3022 /* Recorded position is not in an overlay string, but in another
3023 string. This can only be a string from a `display' property.
3024 IT should already be filled with that string. */
3025 it
->current
.string_pos
= pos
->string_pos
;
3026 xassert (STRINGP (it
->string
));
3029 /* Restore position in display vector translations, control
3030 character translations or ellipses. */
3031 if (pos
->dpvec_index
>= 0)
3033 if (it
->dpvec
== NULL
)
3034 get_next_display_element (it
);
3035 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3036 it
->current
.dpvec_index
= pos
->dpvec_index
;
3040 return !overlay_strings_with_newlines
;
3044 /* Initialize IT for stepping through current_buffer in window W
3045 starting at ROW->start. */
3048 init_to_row_start (it
, w
, row
)
3051 struct glyph_row
*row
;
3053 init_from_display_pos (it
, w
, &row
->start
);
3054 it
->start
= row
->start
;
3055 it
->continuation_lines_width
= row
->continuation_lines_width
;
3060 /* Initialize IT for stepping through current_buffer in window W
3061 starting in the line following ROW, i.e. starting at ROW->end.
3062 Value is zero if there are overlay strings with newlines at ROW's
3066 init_to_row_end (it
, w
, row
)
3069 struct glyph_row
*row
;
3073 if (init_from_display_pos (it
, w
, &row
->end
))
3075 if (row
->continued_p
)
3076 it
->continuation_lines_width
3077 = row
->continuation_lines_width
+ row
->pixel_width
;
3088 /***********************************************************************
3090 ***********************************************************************/
3092 /* Called when IT reaches IT->stop_charpos. Handle text property and
3093 overlay changes. Set IT->stop_charpos to the next position where
3100 enum prop_handled handled
;
3101 int handle_overlay_change_p
;
3105 it
->current
.dpvec_index
= -1;
3106 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3107 it
->ignore_overlay_strings_at_pos_p
= 0;
3109 /* Use face of preceding text for ellipsis (if invisible) */
3110 if (it
->selective_display_ellipsis_p
)
3111 it
->saved_face_id
= it
->face_id
;
3115 handled
= HANDLED_NORMALLY
;
3117 /* Call text property handlers. */
3118 for (p
= it_props
; p
->handler
; ++p
)
3120 handled
= p
->handler (it
);
3122 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3124 else if (handled
== HANDLED_RETURN
)
3126 /* We still want to show before and after strings from
3127 overlays even if the actual buffer text is replaced. */
3128 if (!handle_overlay_change_p
|| it
->sp
> 1)
3130 if (!get_overlay_strings_1 (it
, 0, 0))
3132 it
->ignore_overlay_strings_at_pos_p
= 1;
3133 it
->string_from_display_prop_p
= 0;
3134 handle_overlay_change_p
= 0;
3135 handled
= HANDLED_RECOMPUTE_PROPS
;
3138 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3139 handle_overlay_change_p
= 0;
3142 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3144 /* Don't check for overlay strings below when set to deliver
3145 characters from a display vector. */
3146 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3147 handle_overlay_change_p
= 0;
3149 /* Handle overlay changes.
3150 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3151 if it finds overlays. */
3152 if (handle_overlay_change_p
)
3153 handled
= handle_overlay_change (it
);
3156 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3158 /* Determine where to stop next. */
3159 if (handled
== HANDLED_NORMALLY
)
3160 compute_stop_pos (it
);
3164 /* Compute IT->stop_charpos from text property and overlay change
3165 information for IT's current position. */
3168 compute_stop_pos (it
)
3171 register INTERVAL iv
, next_iv
;
3172 Lisp_Object object
, limit
, position
;
3174 /* If nowhere else, stop at the end. */
3175 it
->stop_charpos
= it
->end_charpos
;
3177 if (STRINGP (it
->string
))
3179 /* Strings are usually short, so don't limit the search for
3181 object
= it
->string
;
3183 position
= make_number (IT_STRING_CHARPOS (*it
));
3189 /* If next overlay change is in front of the current stop pos
3190 (which is IT->end_charpos), stop there. Note: value of
3191 next_overlay_change is point-max if no overlay change
3193 charpos
= next_overlay_change (IT_CHARPOS (*it
));
3194 if (charpos
< it
->stop_charpos
)
3195 it
->stop_charpos
= charpos
;
3197 /* If showing the region, we have to stop at the region
3198 start or end because the face might change there. */
3199 if (it
->region_beg_charpos
> 0)
3201 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3202 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3203 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3204 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3207 /* Set up variables for computing the stop position from text
3208 property changes. */
3209 XSETBUFFER (object
, current_buffer
);
3210 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3211 position
= make_number (IT_CHARPOS (*it
));
3215 /* Get the interval containing IT's position. Value is a null
3216 interval if there isn't such an interval. */
3217 iv
= validate_interval_range (object
, &position
, &position
, 0);
3218 if (!NULL_INTERVAL_P (iv
))
3220 Lisp_Object values_here
[LAST_PROP_IDX
];
3223 /* Get properties here. */
3224 for (p
= it_props
; p
->handler
; ++p
)
3225 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3227 /* Look for an interval following iv that has different
3229 for (next_iv
= next_interval (iv
);
3230 (!NULL_INTERVAL_P (next_iv
)
3232 || XFASTINT (limit
) > next_iv
->position
));
3233 next_iv
= next_interval (next_iv
))
3235 for (p
= it_props
; p
->handler
; ++p
)
3237 Lisp_Object new_value
;
3239 new_value
= textget (next_iv
->plist
, *p
->name
);
3240 if (!EQ (values_here
[p
->idx
], new_value
))
3248 if (!NULL_INTERVAL_P (next_iv
))
3250 if (INTEGERP (limit
)
3251 && next_iv
->position
>= XFASTINT (limit
))
3252 /* No text property change up to limit. */
3253 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3255 /* Text properties change in next_iv. */
3256 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3260 xassert (STRINGP (it
->string
)
3261 || (it
->stop_charpos
>= BEGV
3262 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3266 /* Return the position of the next overlay change after POS in
3267 current_buffer. Value is point-max if no overlay change
3268 follows. This is like `next-overlay-change' but doesn't use
3272 next_overlay_change (pos
)
3277 Lisp_Object
*overlays
;
3280 /* Get all overlays at the given position. */
3281 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3283 /* If any of these overlays ends before endpos,
3284 use its ending point instead. */
3285 for (i
= 0; i
< noverlays
; ++i
)
3290 oend
= OVERLAY_END (overlays
[i
]);
3291 oendpos
= OVERLAY_POSITION (oend
);
3292 endpos
= min (endpos
, oendpos
);
3300 /***********************************************************************
3302 ***********************************************************************/
3304 /* Handle changes in the `fontified' property of the current buffer by
3305 calling hook functions from Qfontification_functions to fontify
3308 static enum prop_handled
3309 handle_fontified_prop (it
)
3312 Lisp_Object prop
, pos
;
3313 enum prop_handled handled
= HANDLED_NORMALLY
;
3315 if (!NILP (Vmemory_full
))
3318 /* Get the value of the `fontified' property at IT's current buffer
3319 position. (The `fontified' property doesn't have a special
3320 meaning in strings.) If the value is nil, call functions from
3321 Qfontification_functions. */
3322 if (!STRINGP (it
->string
)
3324 && !NILP (Vfontification_functions
)
3325 && !NILP (Vrun_hooks
)
3326 && (pos
= make_number (IT_CHARPOS (*it
)),
3327 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3328 /* Ignore the special cased nil value always present at EOB since
3329 no amount of fontifying will be able to change it. */
3330 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3332 int count
= SPECPDL_INDEX ();
3335 val
= Vfontification_functions
;
3336 specbind (Qfontification_functions
, Qnil
);
3338 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3339 safe_call1 (val
, pos
);
3342 Lisp_Object globals
, fn
;
3343 struct gcpro gcpro1
, gcpro2
;
3346 GCPRO2 (val
, globals
);
3348 for (; CONSP (val
); val
= XCDR (val
))
3354 /* A value of t indicates this hook has a local
3355 binding; it means to run the global binding too.
3356 In a global value, t should not occur. If it
3357 does, we must ignore it to avoid an endless
3359 for (globals
= Fdefault_value (Qfontification_functions
);
3361 globals
= XCDR (globals
))
3363 fn
= XCAR (globals
);
3365 safe_call1 (fn
, pos
);
3369 safe_call1 (fn
, pos
);
3375 unbind_to (count
, Qnil
);
3377 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3378 something. This avoids an endless loop if they failed to
3379 fontify the text for which reason ever. */
3380 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3381 handled
= HANDLED_RECOMPUTE_PROPS
;
3389 /***********************************************************************
3391 ***********************************************************************/
3393 /* Set up iterator IT from face properties at its current position.
3394 Called from handle_stop. */
3396 static enum prop_handled
3397 handle_face_prop (it
)
3401 EMACS_INT next_stop
;
3403 if (!STRINGP (it
->string
))
3406 = face_at_buffer_position (it
->w
,
3408 it
->region_beg_charpos
,
3409 it
->region_end_charpos
,
3412 + TEXT_PROP_DISTANCE_LIMIT
),
3415 /* Is this a start of a run of characters with box face?
3416 Caveat: this can be called for a freshly initialized
3417 iterator; face_id is -1 in this case. We know that the new
3418 face will not change until limit, i.e. if the new face has a
3419 box, all characters up to limit will have one. But, as
3420 usual, we don't know whether limit is really the end. */
3421 if (new_face_id
!= it
->face_id
)
3423 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3425 /* If new face has a box but old face has not, this is
3426 the start of a run of characters with box, i.e. it has
3427 a shadow on the left side. The value of face_id of the
3428 iterator will be -1 if this is the initial call that gets
3429 the face. In this case, we have to look in front of IT's
3430 position and see whether there is a face != new_face_id. */
3431 it
->start_of_box_run_p
3432 = (new_face
->box
!= FACE_NO_BOX
3433 && (it
->face_id
>= 0
3434 || IT_CHARPOS (*it
) == BEG
3435 || new_face_id
!= face_before_it_pos (it
)));
3436 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3441 int base_face_id
, bufpos
;
3443 Lisp_Object from_overlay
3444 = (it
->current
.overlay_string_index
>= 0
3445 ? it
->string_overlays
[it
->current
.overlay_string_index
]
3448 /* See if we got to this string directly or indirectly from
3449 an overlay property. That includes the before-string or
3450 after-string of an overlay, strings in display properties
3451 provided by an overlay, their text properties, etc.
3453 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3454 if (! NILP (from_overlay
))
3455 for (i
= it
->sp
- 1; i
>= 0; i
--)
3457 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3459 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
];
3460 else if (! NILP (it
->stack
[i
].from_overlay
))
3461 from_overlay
= it
->stack
[i
].from_overlay
;
3463 if (!NILP (from_overlay
))
3467 if (! NILP (from_overlay
))
3469 bufpos
= IT_CHARPOS (*it
);
3470 /* For a string from an overlay, the base face depends
3471 only on text properties and ignores overlays. */
3473 = face_for_overlay_string (it
->w
,
3475 it
->region_beg_charpos
,
3476 it
->region_end_charpos
,
3479 + TEXT_PROP_DISTANCE_LIMIT
),
3487 /* For strings from a `display' property, use the face at
3488 IT's current buffer position as the base face to merge
3489 with, so that overlay strings appear in the same face as
3490 surrounding text, unless they specify their own
3492 base_face_id
= underlying_face_id (it
);
3495 new_face_id
= face_at_string_position (it
->w
,
3497 IT_STRING_CHARPOS (*it
),
3499 it
->region_beg_charpos
,
3500 it
->region_end_charpos
,
3504 #if 0 /* This shouldn't be neccessary. Let's check it. */
3505 /* If IT is used to display a mode line we would really like to
3506 use the mode line face instead of the frame's default face. */
3507 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
3508 && new_face_id
== DEFAULT_FACE_ID
)
3509 new_face_id
= CURRENT_MODE_LINE_FACE_ID (it
->w
);
3512 /* Is this a start of a run of characters with box? Caveat:
3513 this can be called for a freshly allocated iterator; face_id
3514 is -1 is this case. We know that the new face will not
3515 change until the next check pos, i.e. if the new face has a
3516 box, all characters up to that position will have a
3517 box. But, as usual, we don't know whether that position
3518 is really the end. */
3519 if (new_face_id
!= it
->face_id
)
3521 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3522 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3524 /* If new face has a box but old face hasn't, this is the
3525 start of a run of characters with box, i.e. it has a
3526 shadow on the left side. */
3527 it
->start_of_box_run_p
3528 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3529 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3533 it
->face_id
= new_face_id
;
3534 return HANDLED_NORMALLY
;
3538 /* Return the ID of the face ``underlying'' IT's current position,
3539 which is in a string. If the iterator is associated with a
3540 buffer, return the face at IT's current buffer position.
3541 Otherwise, use the iterator's base_face_id. */
3544 underlying_face_id (it
)
3547 int face_id
= it
->base_face_id
, i
;
3549 xassert (STRINGP (it
->string
));
3551 for (i
= it
->sp
- 1; i
>= 0; --i
)
3552 if (NILP (it
->stack
[i
].string
))
3553 face_id
= it
->stack
[i
].face_id
;
3559 /* Compute the face one character before or after the current position
3560 of IT. BEFORE_P non-zero means get the face in front of IT's
3561 position. Value is the id of the face. */
3564 face_before_or_after_it_pos (it
, before_p
)
3569 EMACS_INT next_check_charpos
;
3570 struct text_pos pos
;
3572 xassert (it
->s
== NULL
);
3574 if (STRINGP (it
->string
))
3576 int bufpos
, base_face_id
;
3578 /* No face change past the end of the string (for the case
3579 we are padding with spaces). No face change before the
3581 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3582 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3585 /* Set pos to the position before or after IT's current position. */
3587 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
3589 /* For composition, we must check the character after the
3591 pos
= (it
->what
== IT_COMPOSITION
3592 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
3593 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
3595 if (it
->current
.overlay_string_index
>= 0)
3596 bufpos
= IT_CHARPOS (*it
);
3600 base_face_id
= underlying_face_id (it
);
3602 /* Get the face for ASCII, or unibyte. */
3603 face_id
= face_at_string_position (it
->w
,
3607 it
->region_beg_charpos
,
3608 it
->region_end_charpos
,
3609 &next_check_charpos
,
3612 /* Correct the face for charsets different from ASCII. Do it
3613 for the multibyte case only. The face returned above is
3614 suitable for unibyte text if IT->string is unibyte. */
3615 if (STRING_MULTIBYTE (it
->string
))
3617 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos
);
3618 int rest
= SBYTES (it
->string
) - BYTEPOS (pos
);
3620 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3622 c
= string_char_and_length (p
, rest
, &len
);
3623 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), it
->string
);
3628 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
3629 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
3632 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
3633 pos
= it
->current
.pos
;
3636 DEC_TEXT_POS (pos
, it
->multibyte_p
);
3639 if (it
->what
== IT_COMPOSITION
)
3640 /* For composition, we must check the position after the
3642 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
3644 INC_TEXT_POS (pos
, it
->multibyte_p
);
3647 /* Determine face for CHARSET_ASCII, or unibyte. */
3648 face_id
= face_at_buffer_position (it
->w
,
3650 it
->region_beg_charpos
,
3651 it
->region_end_charpos
,
3652 &next_check_charpos
,
3655 /* Correct the face for charsets different from ASCII. Do it
3656 for the multibyte case only. The face returned above is
3657 suitable for unibyte text if current_buffer is unibyte. */
3658 if (it
->multibyte_p
)
3660 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
3661 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
3662 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
3671 /***********************************************************************
3673 ***********************************************************************/
3675 /* Set up iterator IT from invisible properties at its current
3676 position. Called from handle_stop. */
3678 static enum prop_handled
3679 handle_invisible_prop (it
)
3682 enum prop_handled handled
= HANDLED_NORMALLY
;
3684 if (STRINGP (it
->string
))
3686 extern Lisp_Object Qinvisible
;
3687 Lisp_Object prop
, end_charpos
, limit
, charpos
;
3689 /* Get the value of the invisible text property at the
3690 current position. Value will be nil if there is no such
3692 charpos
= make_number (IT_STRING_CHARPOS (*it
));
3693 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
3696 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
3698 handled
= HANDLED_RECOMPUTE_PROPS
;
3700 /* Get the position at which the next change of the
3701 invisible text property can be found in IT->string.
3702 Value will be nil if the property value is the same for
3703 all the rest of IT->string. */
3704 XSETINT (limit
, SCHARS (it
->string
));
3705 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
3708 /* Text at current position is invisible. The next
3709 change in the property is at position end_charpos.
3710 Move IT's current position to that position. */
3711 if (INTEGERP (end_charpos
)
3712 && XFASTINT (end_charpos
) < XFASTINT (limit
))
3714 struct text_pos old
;
3715 old
= it
->current
.string_pos
;
3716 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
3717 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
3721 /* The rest of the string is invisible. If this is an
3722 overlay string, proceed with the next overlay string
3723 or whatever comes and return a character from there. */
3724 if (it
->current
.overlay_string_index
>= 0)
3726 next_overlay_string (it
);
3727 /* Don't check for overlay strings when we just
3728 finished processing them. */
3729 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
3733 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
3734 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
3742 EMACS_INT newpos
, next_stop
, start_charpos
;
3743 Lisp_Object pos
, prop
, overlay
;
3745 /* First of all, is there invisible text at this position? */
3746 start_charpos
= IT_CHARPOS (*it
);
3747 pos
= make_number (IT_CHARPOS (*it
));
3748 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
3750 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3752 /* If we are on invisible text, skip over it. */
3753 if (invis_p
&& IT_CHARPOS (*it
) < it
->end_charpos
)
3755 /* Record whether we have to display an ellipsis for the
3757 int display_ellipsis_p
= invis_p
== 2;
3759 handled
= HANDLED_RECOMPUTE_PROPS
;
3761 /* Loop skipping over invisible text. The loop is left at
3762 ZV or with IT on the first char being visible again. */
3765 /* Try to skip some invisible text. Return value is the
3766 position reached which can be equal to IT's position
3767 if there is nothing invisible here. This skips both
3768 over invisible text properties and overlays with
3769 invisible property. */
3770 newpos
= skip_invisible (IT_CHARPOS (*it
),
3771 &next_stop
, ZV
, it
->window
);
3773 /* If we skipped nothing at all we weren't at invisible
3774 text in the first place. If everything to the end of
3775 the buffer was skipped, end the loop. */
3776 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
3780 /* We skipped some characters but not necessarily
3781 all there are. Check if we ended up on visible
3782 text. Fget_char_property returns the property of
3783 the char before the given position, i.e. if we
3784 get invis_p = 0, this means that the char at
3785 newpos is visible. */
3786 pos
= make_number (newpos
);
3787 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
3788 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
3791 /* If we ended up on invisible text, proceed to
3792 skip starting with next_stop. */
3794 IT_CHARPOS (*it
) = next_stop
;
3796 /* If there are adjacent invisible texts, don't lose the
3797 second one's ellipsis. */
3799 display_ellipsis_p
= 1;
3803 /* The position newpos is now either ZV or on visible text. */
3804 IT_CHARPOS (*it
) = newpos
;
3805 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
3807 /* If there are before-strings at the start of invisible
3808 text, and the text is invisible because of a text
3809 property, arrange to show before-strings because 20.x did
3810 it that way. (If the text is invisible because of an
3811 overlay property instead of a text property, this is
3812 already handled in the overlay code.) */
3814 && get_overlay_strings (it
, start_charpos
))
3816 handled
= HANDLED_RECOMPUTE_PROPS
;
3817 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
3819 else if (display_ellipsis_p
)
3821 /* Make sure that the glyphs of the ellipsis will get
3822 correct `charpos' values. If we would not update
3823 it->position here, the glyphs would belong to the
3824 last visible character _before_ the invisible
3825 text, which confuses `set_cursor_from_row'.
3827 We use the last invisible position instead of the
3828 first because this way the cursor is always drawn on
3829 the first "." of the ellipsis, whenever PT is inside
3830 the invisible text. Otherwise the cursor would be
3831 placed _after_ the ellipsis when the point is after the
3832 first invisible character. */
3833 if (!STRINGP (it
->object
))
3835 it
->position
.charpos
= IT_CHARPOS (*it
) - 1;
3836 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
3838 setup_for_ellipsis (it
, 0);
3839 /* Let the ellipsis display before
3840 considering any properties of the following char.
3841 Fixes jasonr@gnu.org 01 Oct 07 bug. */
3842 handled
= HANDLED_RETURN
;
3851 /* Make iterator IT return `...' next.
3852 Replaces LEN characters from buffer. */
3855 setup_for_ellipsis (it
, len
)
3859 /* Use the display table definition for `...'. Invalid glyphs
3860 will be handled by the method returning elements from dpvec. */
3861 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3863 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3864 it
->dpvec
= v
->contents
;
3865 it
->dpend
= v
->contents
+ v
->size
;
3869 /* Default `...'. */
3870 it
->dpvec
= default_invis_vector
;
3871 it
->dpend
= default_invis_vector
+ 3;
3874 it
->dpvec_char_len
= len
;
3875 it
->current
.dpvec_index
= 0;
3876 it
->dpvec_face_id
= -1;
3878 /* Remember the current face id in case glyphs specify faces.
3879 IT's face is restored in set_iterator_to_next.
3880 saved_face_id was set to preceding char's face in handle_stop. */
3881 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
3882 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
3884 it
->method
= GET_FROM_DISPLAY_VECTOR
;
3890 /***********************************************************************
3892 ***********************************************************************/
3894 /* Set up iterator IT from `display' property at its current position.
3895 Called from handle_stop.
3896 We return HANDLED_RETURN if some part of the display property
3897 overrides the display of the buffer text itself.
3898 Otherwise we return HANDLED_NORMALLY. */
3900 static enum prop_handled
3901 handle_display_prop (it
)
3904 Lisp_Object prop
, object
, overlay
;
3905 struct text_pos
*position
;
3906 /* Nonzero if some property replaces the display of the text itself. */
3907 int display_replaced_p
= 0;
3909 if (STRINGP (it
->string
))
3911 object
= it
->string
;
3912 position
= &it
->current
.string_pos
;
3916 XSETWINDOW (object
, it
->w
);
3917 position
= &it
->current
.pos
;
3920 /* Reset those iterator values set from display property values. */
3921 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
3922 it
->space_width
= Qnil
;
3923 it
->font_height
= Qnil
;
3926 /* We don't support recursive `display' properties, i.e. string
3927 values that have a string `display' property, that have a string
3928 `display' property etc. */
3929 if (!it
->string_from_display_prop_p
)
3930 it
->area
= TEXT_AREA
;
3932 prop
= get_char_property_and_overlay (make_number (position
->charpos
),
3933 Qdisplay
, object
, &overlay
);
3935 return HANDLED_NORMALLY
;
3936 /* Now OVERLAY is the overlay that gave us this property, or nil
3937 if it was a text property. */
3939 if (!STRINGP (it
->string
))
3940 object
= it
->w
->buffer
;
3943 /* Simple properties. */
3944 && !EQ (XCAR (prop
), Qimage
)
3945 && !EQ (XCAR (prop
), Qspace
)
3946 && !EQ (XCAR (prop
), Qwhen
)
3947 && !EQ (XCAR (prop
), Qslice
)
3948 && !EQ (XCAR (prop
), Qspace_width
)
3949 && !EQ (XCAR (prop
), Qheight
)
3950 && !EQ (XCAR (prop
), Qraise
)
3951 /* Marginal area specifications. */
3952 && !(CONSP (XCAR (prop
)) && EQ (XCAR (XCAR (prop
)), Qmargin
))
3953 && !EQ (XCAR (prop
), Qleft_fringe
)
3954 && !EQ (XCAR (prop
), Qright_fringe
)
3955 && !NILP (XCAR (prop
)))
3957 for (; CONSP (prop
); prop
= XCDR (prop
))
3959 if (handle_single_display_spec (it
, XCAR (prop
), object
, overlay
,
3960 position
, display_replaced_p
))
3962 display_replaced_p
= 1;
3963 /* If some text in a string is replaced, `position' no
3964 longer points to the position of `object'. */
3965 if (STRINGP (object
))
3970 else if (VECTORP (prop
))
3973 for (i
= 0; i
< ASIZE (prop
); ++i
)
3974 if (handle_single_display_spec (it
, AREF (prop
, i
), object
, overlay
,
3975 position
, display_replaced_p
))
3977 display_replaced_p
= 1;
3978 /* If some text in a string is replaced, `position' no
3979 longer points to the position of `object'. */
3980 if (STRINGP (object
))
3986 int ret
= handle_single_display_spec (it
, prop
, object
, overlay
,
3988 if (ret
< 0) /* Replaced by "", i.e. nothing. */
3989 return HANDLED_RECOMPUTE_PROPS
;
3991 display_replaced_p
= 1;
3994 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
3998 /* Value is the position of the end of the `display' property starting
3999 at START_POS in OBJECT. */
4001 static struct text_pos
4002 display_prop_end (it
, object
, start_pos
)
4005 struct text_pos start_pos
;
4008 struct text_pos end_pos
;
4010 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4011 Qdisplay
, object
, Qnil
);
4012 CHARPOS (end_pos
) = XFASTINT (end
);
4013 if (STRINGP (object
))
4014 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4016 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4022 /* Set up IT from a single `display' specification PROP. OBJECT
4023 is the object in which the `display' property was found. *POSITION
4024 is the position at which it was found. DISPLAY_REPLACED_P non-zero
4025 means that we previously saw a display specification which already
4026 replaced text display with something else, for example an image;
4027 we ignore such properties after the first one has been processed.
4029 OVERLAY is the overlay this `display' property came from,
4030 or nil if it was a text property.
4032 If PROP is a `space' or `image' specification, and in some other
4033 cases too, set *POSITION to the position where the `display'
4036 Value is non-zero if something was found which replaces the display
4037 of buffer or string text. Specifically, the value is -1 if that
4038 "something" is "nothing". */
4041 handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4042 display_replaced_before_p
)
4046 Lisp_Object overlay
;
4047 struct text_pos
*position
;
4048 int display_replaced_before_p
;
4051 Lisp_Object location
, value
;
4052 struct text_pos start_pos
, save_pos
;
4055 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4056 If the result is non-nil, use VALUE instead of SPEC. */
4058 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4067 if (!NILP (form
) && !EQ (form
, Qt
))
4069 int count
= SPECPDL_INDEX ();
4070 struct gcpro gcpro1
;
4072 /* Bind `object' to the object having the `display' property, a
4073 buffer or string. Bind `position' to the position in the
4074 object where the property was found, and `buffer-position'
4075 to the current position in the buffer. */
4076 specbind (Qobject
, object
);
4077 specbind (Qposition
, make_number (CHARPOS (*position
)));
4078 specbind (Qbuffer_position
,
4079 make_number (STRINGP (object
)
4080 ? IT_CHARPOS (*it
) : CHARPOS (*position
)));
4082 form
= safe_eval (form
);
4084 unbind_to (count
, Qnil
);
4090 /* Handle `(height HEIGHT)' specifications. */
4092 && EQ (XCAR (spec
), Qheight
)
4093 && CONSP (XCDR (spec
)))
4095 if (!FRAME_WINDOW_P (it
->f
))
4098 it
->font_height
= XCAR (XCDR (spec
));
4099 if (!NILP (it
->font_height
))
4101 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4102 int new_height
= -1;
4104 if (CONSP (it
->font_height
)
4105 && (EQ (XCAR (it
->font_height
), Qplus
)
4106 || EQ (XCAR (it
->font_height
), Qminus
))
4107 && CONSP (XCDR (it
->font_height
))
4108 && INTEGERP (XCAR (XCDR (it
->font_height
))))
4110 /* `(+ N)' or `(- N)' where N is an integer. */
4111 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4112 if (EQ (XCAR (it
->font_height
), Qplus
))
4114 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4116 else if (FUNCTIONP (it
->font_height
))
4118 /* Call function with current height as argument.
4119 Value is the new height. */
4121 height
= safe_call1 (it
->font_height
,
4122 face
->lface
[LFACE_HEIGHT_INDEX
]);
4123 if (NUMBERP (height
))
4124 new_height
= XFLOATINT (height
);
4126 else if (NUMBERP (it
->font_height
))
4128 /* Value is a multiple of the canonical char height. */
4131 face
= FACE_FROM_ID (it
->f
,
4132 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4133 new_height
= (XFLOATINT (it
->font_height
)
4134 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
4138 /* Evaluate IT->font_height with `height' bound to the
4139 current specified height to get the new height. */
4140 int count
= SPECPDL_INDEX ();
4142 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4143 value
= safe_eval (it
->font_height
);
4144 unbind_to (count
, Qnil
);
4146 if (NUMBERP (value
))
4147 new_height
= XFLOATINT (value
);
4151 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4157 /* Handle `(space-width WIDTH)'. */
4159 && EQ (XCAR (spec
), Qspace_width
)
4160 && CONSP (XCDR (spec
)))
4162 if (!FRAME_WINDOW_P (it
->f
))
4165 value
= XCAR (XCDR (spec
));
4166 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4167 it
->space_width
= value
;
4172 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4174 && EQ (XCAR (spec
), Qslice
))
4178 if (!FRAME_WINDOW_P (it
->f
))
4181 if (tem
= XCDR (spec
), CONSP (tem
))
4183 it
->slice
.x
= XCAR (tem
);
4184 if (tem
= XCDR (tem
), CONSP (tem
))
4186 it
->slice
.y
= XCAR (tem
);
4187 if (tem
= XCDR (tem
), CONSP (tem
))
4189 it
->slice
.width
= XCAR (tem
);
4190 if (tem
= XCDR (tem
), CONSP (tem
))
4191 it
->slice
.height
= XCAR (tem
);
4199 /* Handle `(raise FACTOR)'. */
4201 && EQ (XCAR (spec
), Qraise
)
4202 && CONSP (XCDR (spec
)))
4204 if (!FRAME_WINDOW_P (it
->f
))
4207 #ifdef HAVE_WINDOW_SYSTEM
4208 value
= XCAR (XCDR (spec
));
4209 if (NUMBERP (value
))
4211 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4212 it
->voffset
= - (XFLOATINT (value
)
4213 * (FONT_HEIGHT (face
->font
)));
4215 #endif /* HAVE_WINDOW_SYSTEM */
4220 /* Don't handle the other kinds of display specifications
4221 inside a string that we got from a `display' property. */
4222 if (it
->string_from_display_prop_p
)
4225 /* Characters having this form of property are not displayed, so
4226 we have to find the end of the property. */
4227 start_pos
= *position
;
4228 *position
= display_prop_end (it
, object
, start_pos
);
4231 /* Stop the scan at that end position--we assume that all
4232 text properties change there. */
4233 it
->stop_charpos
= position
->charpos
;
4235 /* Handle `(left-fringe BITMAP [FACE])'
4236 and `(right-fringe BITMAP [FACE])'. */
4238 && (EQ (XCAR (spec
), Qleft_fringe
)
4239 || EQ (XCAR (spec
), Qright_fringe
))
4240 && CONSP (XCDR (spec
)))
4242 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
4245 if (!FRAME_WINDOW_P (it
->f
))
4246 /* If we return here, POSITION has been advanced
4247 across the text with this property. */
4250 #ifdef HAVE_WINDOW_SYSTEM
4251 value
= XCAR (XCDR (spec
));
4252 if (!SYMBOLP (value
)
4253 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4254 /* If we return here, POSITION has been advanced
4255 across the text with this property. */
4258 if (CONSP (XCDR (XCDR (spec
))))
4260 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4261 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4267 /* Save current settings of IT so that we can restore them
4268 when we are finished with the glyph property value. */
4270 save_pos
= it
->position
;
4271 it
->position
= *position
;
4273 it
->position
= save_pos
;
4275 it
->area
= TEXT_AREA
;
4276 it
->what
= IT_IMAGE
;
4277 it
->image_id
= -1; /* no image */
4278 it
->position
= start_pos
;
4279 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4280 it
->method
= GET_FROM_IMAGE
;
4281 it
->from_overlay
= Qnil
;
4282 it
->face_id
= face_id
;
4284 /* Say that we haven't consumed the characters with
4285 `display' property yet. The call to pop_it in
4286 set_iterator_to_next will clean this up. */
4287 *position
= start_pos
;
4289 if (EQ (XCAR (spec
), Qleft_fringe
))
4291 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4292 it
->left_user_fringe_face_id
= face_id
;
4296 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4297 it
->right_user_fringe_face_id
= face_id
;
4299 #endif /* HAVE_WINDOW_SYSTEM */
4303 /* Prepare to handle `((margin left-margin) ...)',
4304 `((margin right-margin) ...)' and `((margin nil) ...)'
4305 prefixes for display specifications. */
4306 location
= Qunbound
;
4307 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4311 value
= XCDR (spec
);
4313 value
= XCAR (value
);
4316 if (EQ (XCAR (tem
), Qmargin
)
4317 && (tem
= XCDR (tem
),
4318 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4320 || EQ (tem
, Qleft_margin
)
4321 || EQ (tem
, Qright_margin
))))
4325 if (EQ (location
, Qunbound
))
4331 /* After this point, VALUE is the property after any
4332 margin prefix has been stripped. It must be a string,
4333 an image specification, or `(space ...)'.
4335 LOCATION specifies where to display: `left-margin',
4336 `right-margin' or nil. */
4338 valid_p
= (STRINGP (value
)
4339 #ifdef HAVE_WINDOW_SYSTEM
4340 || (FRAME_WINDOW_P (it
->f
) && valid_image_p (value
))
4341 #endif /* not HAVE_WINDOW_SYSTEM */
4342 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4344 if (valid_p
&& !display_replaced_before_p
)
4346 /* Save current settings of IT so that we can restore them
4347 when we are finished with the glyph property value. */
4348 save_pos
= it
->position
;
4349 it
->position
= *position
;
4351 it
->position
= save_pos
;
4352 it
->from_overlay
= overlay
;
4354 if (NILP (location
))
4355 it
->area
= TEXT_AREA
;
4356 else if (EQ (location
, Qleft_margin
))
4357 it
->area
= LEFT_MARGIN_AREA
;
4359 it
->area
= RIGHT_MARGIN_AREA
;
4361 if (STRINGP (value
))
4363 if (SCHARS (value
) == 0)
4366 return -1; /* Replaced by "", i.e. nothing. */
4369 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4370 it
->current
.overlay_string_index
= -1;
4371 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
4372 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
4373 it
->method
= GET_FROM_STRING
;
4374 it
->stop_charpos
= 0;
4375 it
->string_from_display_prop_p
= 1;
4376 /* Say that we haven't consumed the characters with
4377 `display' property yet. The call to pop_it in
4378 set_iterator_to_next will clean this up. */
4379 if (BUFFERP (object
))
4380 *position
= start_pos
;
4382 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
4384 it
->method
= GET_FROM_STRETCH
;
4386 *position
= it
->position
= start_pos
;
4388 #ifdef HAVE_WINDOW_SYSTEM
4391 it
->what
= IT_IMAGE
;
4392 it
->image_id
= lookup_image (it
->f
, value
);
4393 it
->position
= start_pos
;
4394 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4395 it
->method
= GET_FROM_IMAGE
;
4397 /* Say that we haven't consumed the characters with
4398 `display' property yet. The call to pop_it in
4399 set_iterator_to_next will clean this up. */
4400 *position
= start_pos
;
4402 #endif /* HAVE_WINDOW_SYSTEM */
4407 /* Invalid property or property not supported. Restore
4408 POSITION to what it was before. */
4409 *position
= start_pos
;
4414 /* Check if SPEC is a display sub-property value whose text should be
4415 treated as intangible. */
4418 single_display_spec_intangible_p (prop
)
4421 /* Skip over `when FORM'. */
4422 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4436 /* Skip over `margin LOCATION'. If LOCATION is in the margins,
4437 we don't need to treat text as intangible. */
4438 if (EQ (XCAR (prop
), Qmargin
))
4446 || EQ (XCAR (prop
), Qleft_margin
)
4447 || EQ (XCAR (prop
), Qright_margin
))
4451 return (CONSP (prop
)
4452 && (EQ (XCAR (prop
), Qimage
)
4453 || EQ (XCAR (prop
), Qspace
)));
4457 /* Check if PROP is a display property value whose text should be
4458 treated as intangible. */
4461 display_prop_intangible_p (prop
)
4465 && CONSP (XCAR (prop
))
4466 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4468 /* A list of sub-properties. */
4469 while (CONSP (prop
))
4471 if (single_display_spec_intangible_p (XCAR (prop
)))
4476 else if (VECTORP (prop
))
4478 /* A vector of sub-properties. */
4480 for (i
= 0; i
< ASIZE (prop
); ++i
)
4481 if (single_display_spec_intangible_p (AREF (prop
, i
)))
4485 return single_display_spec_intangible_p (prop
);
4491 /* Return 1 if PROP is a display sub-property value containing STRING. */
4494 single_display_spec_string_p (prop
, string
)
4495 Lisp_Object prop
, string
;
4497 if (EQ (string
, prop
))
4500 /* Skip over `when FORM'. */
4501 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
4510 /* Skip over `margin LOCATION'. */
4511 if (EQ (XCAR (prop
), Qmargin
))
4522 return CONSP (prop
) && EQ (XCAR (prop
), string
);
4526 /* Return 1 if STRING appears in the `display' property PROP. */
4529 display_prop_string_p (prop
, string
)
4530 Lisp_Object prop
, string
;
4533 && CONSP (XCAR (prop
))
4534 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
4536 /* A list of sub-properties. */
4537 while (CONSP (prop
))
4539 if (single_display_spec_string_p (XCAR (prop
), string
))
4544 else if (VECTORP (prop
))
4546 /* A vector of sub-properties. */
4548 for (i
= 0; i
< ASIZE (prop
); ++i
)
4549 if (single_display_spec_string_p (AREF (prop
, i
), string
))
4553 return single_display_spec_string_p (prop
, string
);
4559 /* Determine from which buffer position in W's buffer STRING comes
4560 from. AROUND_CHARPOS is an approximate position where it could
4561 be from. Value is the buffer position or 0 if it couldn't be
4564 W's buffer must be current.
4566 This function is necessary because we don't record buffer positions
4567 in glyphs generated from strings (to keep struct glyph small).
4568 This function may only use code that doesn't eval because it is
4569 called asynchronously from note_mouse_highlight. */
4572 string_buffer_position (w
, string
, around_charpos
)
4577 Lisp_Object limit
, prop
, pos
;
4578 const int MAX_DISTANCE
= 1000;
4581 pos
= make_number (around_charpos
);
4582 limit
= make_number (min (XINT (pos
) + MAX_DISTANCE
, ZV
));
4583 while (!found
&& !EQ (pos
, limit
))
4585 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4586 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4589 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
, limit
);
4594 pos
= make_number (around_charpos
);
4595 limit
= make_number (max (XINT (pos
) - MAX_DISTANCE
, BEGV
));
4596 while (!found
&& !EQ (pos
, limit
))
4598 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
4599 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
4602 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
4607 return found
? XINT (pos
) : 0;
4612 /***********************************************************************
4613 `composition' property
4614 ***********************************************************************/
4616 static enum prop_handled
4617 handle_auto_composed_prop (it
)
4620 enum prop_handled handled
= HANDLED_NORMALLY
;
4622 if (FUNCTIONP (Vauto_composition_function
))
4624 Lisp_Object val
= Qnil
;
4625 EMACS_INT pos
, limit
= -1;
4627 if (STRINGP (it
->string
))
4628 pos
= IT_STRING_CHARPOS (*it
);
4630 pos
= IT_CHARPOS (*it
);
4632 val
= Fget_text_property (make_number (pos
), Qauto_composed
, it
->string
);
4635 Lisp_Object cmp_prop
;
4636 EMACS_INT cmp_start
, cmp_end
;
4638 if (get_property_and_range (pos
, Qcomposition
, &cmp_prop
,
4639 &cmp_start
, &cmp_end
, it
->string
)
4641 && COMPOSITION_METHOD (cmp_prop
) == COMPOSITION_WITH_GLYPH_STRING
)
4643 Lisp_Object gstring
= COMPOSITION_COMPONENTS (cmp_prop
);
4644 Lisp_Object font_object
= LGSTRING_FONT (gstring
);
4646 if (! EQ (font_object
,
4647 font_at (-1, pos
, FACE_FROM_ID (it
->f
, it
->face_id
),
4648 it
->w
, it
->string
)))
4649 /* We must re-compute the composition for the
4658 /* As Fnext_single_char_property_change is very slow, we
4659 limit the search to the current line. */
4660 if (STRINGP (it
->string
))
4661 limit
= SCHARS (it
->string
);
4663 limit
= find_next_newline_no_quit (pos
, 1);
4664 end
= Fnext_single_char_property_change (make_number (pos
),
4667 make_number (limit
));
4669 if (XINT (end
) < limit
)
4670 /* The current point is auto-composed, but there exist
4671 characters not yet composed beyond the
4672 auto-composed region. There's a possiblity that
4673 the last characters in the region may be newly
4678 if (NILP (val
) && ! STRINGP (it
->string
))
4681 limit
= (STRINGP (it
->string
) ? SCHARS (it
->string
)
4682 : find_next_newline_no_quit (pos
, 1));
4685 int count
= SPECPDL_INDEX ();
4686 Lisp_Object args
[5];
4688 if (FRAME_WINDOW_P (it
->f
))
4689 limit
= font_range (pos
, limit
,
4690 FACE_FROM_ID (it
->f
, it
->face_id
),
4692 args
[0] = Vauto_composition_function
;
4693 specbind (Qauto_composition_function
, Qnil
);
4694 args
[1] = make_number (pos
);
4695 args
[2] = make_number (limit
);
4696 args
[3] = it
->window
;
4697 args
[4] = it
->string
;
4698 safe_call (5, args
);
4699 unbind_to (count
, Qnil
);
4707 /* Set up iterator IT from `composition' property at its current
4708 position. Called from handle_stop. */
4710 static enum prop_handled
4711 handle_composition_prop (it
)
4714 Lisp_Object prop
, string
;
4715 EMACS_INT pos
, pos_byte
, start
, end
;
4716 enum prop_handled handled
= HANDLED_NORMALLY
;
4718 if (STRINGP (it
->string
))
4722 pos
= IT_STRING_CHARPOS (*it
);
4723 pos_byte
= IT_STRING_BYTEPOS (*it
);
4724 string
= it
->string
;
4725 s
= SDATA (string
) + pos_byte
;
4726 it
->c
= STRING_CHAR (s
, 0);
4730 pos
= IT_CHARPOS (*it
);
4731 pos_byte
= IT_BYTEPOS (*it
);
4733 it
->c
= FETCH_CHAR (pos_byte
);
4736 /* If there's a valid composition and point is not inside of the
4737 composition (in the case that the composition is from the current
4738 buffer), draw a glyph composed from the composition components. */
4739 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
4740 && COMPOSITION_VALID_P (start
, end
, prop
)
4741 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
4747 if (STRINGP (it
->string
))
4748 pos_byte
= string_char_to_byte (it
->string
, start
);
4750 pos_byte
= CHAR_TO_BYTE (start
);
4752 id
= get_composition_id (start
, pos_byte
, end
- start
, prop
, string
);
4756 struct composition
*cmp
= composition_table
[id
];
4758 if (cmp
->glyph_len
== 0)
4761 if (STRINGP (it
->string
))
4763 IT_STRING_CHARPOS (*it
) = end
;
4764 IT_STRING_BYTEPOS (*it
) = string_char_to_byte (it
->string
,
4769 IT_CHARPOS (*it
) = end
;
4770 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (end
);
4772 return HANDLED_RECOMPUTE_PROPS
;
4775 it
->stop_charpos
= end
;
4778 it
->method
= GET_FROM_COMPOSITION
;
4780 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
4781 /* For a terminal, draw only the first (non-TAB) character
4782 of the components. */
4783 if (composition_table
[id
]->method
== COMPOSITION_WITH_GLYPH_STRING
)
4785 /* FIXME: This doesn't do anything!?! */
4786 Lisp_Object lgstring
= AREF (XHASH_TABLE (composition_hash_table
)
4788 cmp
->hash_index
* 2);
4794 for (i
= 0; i
< cmp
->glyph_len
; i
++)
4795 if ((it
->c
= COMPOSITION_GLYPH (composition_table
[id
], i
))
4801 it
->len
= (STRINGP (it
->string
)
4802 ? string_char_to_byte (it
->string
, end
)
4803 : CHAR_TO_BYTE (end
)) - pos_byte
;
4804 handled
= HANDLED_RETURN
;
4813 /***********************************************************************
4815 ***********************************************************************/
4817 /* The following structure is used to record overlay strings for
4818 later sorting in load_overlay_strings. */
4820 struct overlay_entry
4822 Lisp_Object overlay
;
4829 /* Set up iterator IT from overlay strings at its current position.
4830 Called from handle_stop. */
4832 static enum prop_handled
4833 handle_overlay_change (it
)
4836 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
4837 return HANDLED_RECOMPUTE_PROPS
;
4839 return HANDLED_NORMALLY
;
4843 /* Set up the next overlay string for delivery by IT, if there is an
4844 overlay string to deliver. Called by set_iterator_to_next when the
4845 end of the current overlay string is reached. If there are more
4846 overlay strings to display, IT->string and
4847 IT->current.overlay_string_index are set appropriately here.
4848 Otherwise IT->string is set to nil. */
4851 next_overlay_string (it
)
4854 ++it
->current
.overlay_string_index
;
4855 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
4857 /* No more overlay strings. Restore IT's settings to what
4858 they were before overlay strings were processed, and
4859 continue to deliver from current_buffer. */
4860 int display_ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
4864 || it
->method
== GET_FROM_COMPOSITION
4865 || (NILP (it
->string
)
4866 && it
->method
== GET_FROM_BUFFER
4867 && it
->stop_charpos
>= BEGV
4868 && it
->stop_charpos
<= it
->end_charpos
));
4869 it
->current
.overlay_string_index
= -1;
4870 it
->n_overlay_strings
= 0;
4872 /* If we're at the end of the buffer, record that we have
4873 processed the overlay strings there already, so that
4874 next_element_from_buffer doesn't try it again. */
4875 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
4876 it
->overlay_strings_at_end_processed_p
= 1;
4878 /* If we have to display `...' for invisible text, set
4879 the iterator up for that. */
4880 if (display_ellipsis_p
)
4881 setup_for_ellipsis (it
, 0);
4885 /* There are more overlay strings to process. If
4886 IT->current.overlay_string_index has advanced to a position
4887 where we must load IT->overlay_strings with more strings, do
4889 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
4891 if (it
->current
.overlay_string_index
&& i
== 0)
4892 load_overlay_strings (it
, 0);
4894 /* Initialize IT to deliver display elements from the overlay
4896 it
->string
= it
->overlay_strings
[i
];
4897 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
4898 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
4899 it
->method
= GET_FROM_STRING
;
4900 it
->stop_charpos
= 0;
4907 /* Compare two overlay_entry structures E1 and E2. Used as a
4908 comparison function for qsort in load_overlay_strings. Overlay
4909 strings for the same position are sorted so that
4911 1. All after-strings come in front of before-strings, except
4912 when they come from the same overlay.
4914 2. Within after-strings, strings are sorted so that overlay strings
4915 from overlays with higher priorities come first.
4917 2. Within before-strings, strings are sorted so that overlay
4918 strings from overlays with higher priorities come last.
4920 Value is analogous to strcmp. */
4924 compare_overlay_entries (e1
, e2
)
4927 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
4928 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
4931 if (entry1
->after_string_p
!= entry2
->after_string_p
)
4933 /* Let after-strings appear in front of before-strings if
4934 they come from different overlays. */
4935 if (EQ (entry1
->overlay
, entry2
->overlay
))
4936 result
= entry1
->after_string_p
? 1 : -1;
4938 result
= entry1
->after_string_p
? -1 : 1;
4940 else if (entry1
->after_string_p
)
4941 /* After-strings sorted in order of decreasing priority. */
4942 result
= entry2
->priority
- entry1
->priority
;
4944 /* Before-strings sorted in order of increasing priority. */
4945 result
= entry1
->priority
- entry2
->priority
;
4951 /* Load the vector IT->overlay_strings with overlay strings from IT's
4952 current buffer position, or from CHARPOS if that is > 0. Set
4953 IT->n_overlays to the total number of overlay strings found.
4955 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
4956 a time. On entry into load_overlay_strings,
4957 IT->current.overlay_string_index gives the number of overlay
4958 strings that have already been loaded by previous calls to this
4961 IT->add_overlay_start contains an additional overlay start
4962 position to consider for taking overlay strings from, if non-zero.
4963 This position comes into play when the overlay has an `invisible'
4964 property, and both before and after-strings. When we've skipped to
4965 the end of the overlay, because of its `invisible' property, we
4966 nevertheless want its before-string to appear.
4967 IT->add_overlay_start will contain the overlay start position
4970 Overlay strings are sorted so that after-string strings come in
4971 front of before-string strings. Within before and after-strings,
4972 strings are sorted by overlay priority. See also function
4973 compare_overlay_entries. */
4976 load_overlay_strings (it
, charpos
)
4980 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
4981 Lisp_Object overlay
, window
, str
, invisible
;
4982 struct Lisp_Overlay
*ov
;
4985 int n
= 0, i
, j
, invis_p
;
4986 struct overlay_entry
*entries
4987 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
4990 charpos
= IT_CHARPOS (*it
);
4992 /* Append the overlay string STRING of overlay OVERLAY to vector
4993 `entries' which has size `size' and currently contains `n'
4994 elements. AFTER_P non-zero means STRING is an after-string of
4996 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
4999 Lisp_Object priority; \
5003 int new_size = 2 * size; \
5004 struct overlay_entry *old = entries; \
5006 (struct overlay_entry *) alloca (new_size \
5007 * sizeof *entries); \
5008 bcopy (old, entries, size * sizeof *entries); \
5012 entries[n].string = (STRING); \
5013 entries[n].overlay = (OVERLAY); \
5014 priority = Foverlay_get ((OVERLAY), Qpriority); \
5015 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5016 entries[n].after_string_p = (AFTER_P); \
5021 /* Process overlay before the overlay center. */
5022 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5024 XSETMISC (overlay
, ov
);
5025 xassert (OVERLAYP (overlay
));
5026 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5027 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5032 /* Skip this overlay if it doesn't start or end at IT's current
5034 if (end
!= charpos
&& start
!= charpos
)
5037 /* Skip this overlay if it doesn't apply to IT->w. */
5038 window
= Foverlay_get (overlay
, Qwindow
);
5039 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5042 /* If the text ``under'' the overlay is invisible, both before-
5043 and after-strings from this overlay are visible; start and
5044 end position are indistinguishable. */
5045 invisible
= Foverlay_get (overlay
, Qinvisible
);
5046 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5048 /* If overlay has a non-empty before-string, record it. */
5049 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5050 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5052 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5054 /* If overlay has a non-empty after-string, record it. */
5055 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5056 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5058 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5061 /* Process overlays after the overlay center. */
5062 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5064 XSETMISC (overlay
, ov
);
5065 xassert (OVERLAYP (overlay
));
5066 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5067 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5069 if (start
> charpos
)
5072 /* Skip this overlay if it doesn't start or end at IT's current
5074 if (end
!= charpos
&& start
!= charpos
)
5077 /* Skip this overlay if it doesn't apply to IT->w. */
5078 window
= Foverlay_get (overlay
, Qwindow
);
5079 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5082 /* If the text ``under'' the overlay is invisible, it has a zero
5083 dimension, and both before- and after-strings apply. */
5084 invisible
= Foverlay_get (overlay
, Qinvisible
);
5085 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5087 /* If overlay has a non-empty before-string, record it. */
5088 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5089 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5091 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5093 /* If overlay has a non-empty after-string, record it. */
5094 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5095 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5097 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5100 #undef RECORD_OVERLAY_STRING
5104 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5106 /* Record the total number of strings to process. */
5107 it
->n_overlay_strings
= n
;
5109 /* IT->current.overlay_string_index is the number of overlay strings
5110 that have already been consumed by IT. Copy some of the
5111 remaining overlay strings to IT->overlay_strings. */
5113 j
= it
->current
.overlay_string_index
;
5114 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5116 it
->overlay_strings
[i
] = entries
[j
].string
;
5117 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5124 /* Get the first chunk of overlay strings at IT's current buffer
5125 position, or at CHARPOS if that is > 0. Value is non-zero if at
5126 least one overlay string was found. */
5129 get_overlay_strings_1 (it
, charpos
, compute_stop_p
)
5134 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5135 process. This fills IT->overlay_strings with strings, and sets
5136 IT->n_overlay_strings to the total number of strings to process.
5137 IT->pos.overlay_string_index has to be set temporarily to zero
5138 because load_overlay_strings needs this; it must be set to -1
5139 when no overlay strings are found because a zero value would
5140 indicate a position in the first overlay string. */
5141 it
->current
.overlay_string_index
= 0;
5142 load_overlay_strings (it
, charpos
);
5144 /* If we found overlay strings, set up IT to deliver display
5145 elements from the first one. Otherwise set up IT to deliver
5146 from current_buffer. */
5147 if (it
->n_overlay_strings
)
5149 /* Make sure we know settings in current_buffer, so that we can
5150 restore meaningful values when we're done with the overlay
5153 compute_stop_pos (it
);
5154 xassert (it
->face_id
>= 0);
5156 /* Save IT's settings. They are restored after all overlay
5157 strings have been processed. */
5158 xassert (!compute_stop_p
|| it
->sp
== 0);
5161 /* Set up IT to deliver display elements from the first overlay
5163 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5164 it
->string
= it
->overlay_strings
[0];
5165 it
->from_overlay
= Qnil
;
5166 it
->stop_charpos
= 0;
5167 xassert (STRINGP (it
->string
));
5168 it
->end_charpos
= SCHARS (it
->string
);
5169 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5170 it
->method
= GET_FROM_STRING
;
5174 it
->current
.overlay_string_index
= -1;
5179 get_overlay_strings (it
, charpos
)
5184 it
->method
= GET_FROM_BUFFER
;
5186 (void) get_overlay_strings_1 (it
, charpos
, 1);
5190 /* Value is non-zero if we found at least one overlay string. */
5191 return STRINGP (it
->string
);
5196 /***********************************************************************
5197 Saving and restoring state
5198 ***********************************************************************/
5200 /* Save current settings of IT on IT->stack. Called, for example,
5201 before setting up IT for an overlay string, to be able to restore
5202 IT's settings to what they were after the overlay string has been
5209 struct iterator_stack_entry
*p
;
5211 xassert (it
->sp
< IT_STACK_SIZE
);
5212 p
= it
->stack
+ it
->sp
;
5214 p
->stop_charpos
= it
->stop_charpos
;
5215 xassert (it
->face_id
>= 0);
5216 p
->face_id
= it
->face_id
;
5217 p
->string
= it
->string
;
5218 p
->method
= it
->method
;
5219 p
->from_overlay
= it
->from_overlay
;
5222 case GET_FROM_IMAGE
:
5223 p
->u
.image
.object
= it
->object
;
5224 p
->u
.image
.image_id
= it
->image_id
;
5225 p
->u
.image
.slice
= it
->slice
;
5227 case GET_FROM_COMPOSITION
:
5228 p
->u
.comp
.object
= it
->object
;
5229 p
->u
.comp
.c
= it
->c
;
5230 p
->u
.comp
.len
= it
->len
;
5231 p
->u
.comp
.cmp_id
= it
->cmp_id
;
5232 p
->u
.comp
.cmp_len
= it
->cmp_len
;
5234 case GET_FROM_STRETCH
:
5235 p
->u
.stretch
.object
= it
->object
;
5238 p
->position
= it
->position
;
5239 p
->current
= it
->current
;
5240 p
->end_charpos
= it
->end_charpos
;
5241 p
->string_nchars
= it
->string_nchars
;
5243 p
->multibyte_p
= it
->multibyte_p
;
5244 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5245 p
->space_width
= it
->space_width
;
5246 p
->font_height
= it
->font_height
;
5247 p
->voffset
= it
->voffset
;
5248 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5249 p
->display_ellipsis_p
= 0;
5254 /* Restore IT's settings from IT->stack. Called, for example, when no
5255 more overlay strings must be processed, and we return to delivering
5256 display elements from a buffer, or when the end of a string from a
5257 `display' property is reached and we return to delivering display
5258 elements from an overlay string, or from a buffer. */
5264 struct iterator_stack_entry
*p
;
5266 xassert (it
->sp
> 0);
5268 p
= it
->stack
+ it
->sp
;
5269 it
->stop_charpos
= p
->stop_charpos
;
5270 it
->face_id
= p
->face_id
;
5271 it
->current
= p
->current
;
5272 it
->position
= p
->position
;
5273 it
->string
= p
->string
;
5274 it
->from_overlay
= p
->from_overlay
;
5275 if (NILP (it
->string
))
5276 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5277 it
->method
= p
->method
;
5280 case GET_FROM_IMAGE
:
5281 it
->image_id
= p
->u
.image
.image_id
;
5282 it
->object
= p
->u
.image
.object
;
5283 it
->slice
= p
->u
.image
.slice
;
5285 case GET_FROM_COMPOSITION
:
5286 it
->object
= p
->u
.comp
.object
;
5287 it
->c
= p
->u
.comp
.c
;
5288 it
->len
= p
->u
.comp
.len
;
5289 it
->cmp_id
= p
->u
.comp
.cmp_id
;
5290 it
->cmp_len
= p
->u
.comp
.cmp_len
;
5292 case GET_FROM_STRETCH
:
5293 it
->object
= p
->u
.comp
.object
;
5295 case GET_FROM_BUFFER
:
5296 it
->object
= it
->w
->buffer
;
5298 case GET_FROM_STRING
:
5299 it
->object
= it
->string
;
5302 it
->end_charpos
= p
->end_charpos
;
5303 it
->string_nchars
= p
->string_nchars
;
5305 it
->multibyte_p
= p
->multibyte_p
;
5306 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5307 it
->space_width
= p
->space_width
;
5308 it
->font_height
= p
->font_height
;
5309 it
->voffset
= p
->voffset
;
5310 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5315 /***********************************************************************
5317 ***********************************************************************/
5319 /* Set IT's current position to the previous line start. */
5322 back_to_previous_line_start (it
)
5325 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5326 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5330 /* Move IT to the next line start.
5332 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5333 we skipped over part of the text (as opposed to moving the iterator
5334 continuously over the text). Otherwise, don't change the value
5337 Newlines may come from buffer text, overlay strings, or strings
5338 displayed via the `display' property. That's the reason we can't
5339 simply use find_next_newline_no_quit.
5341 Note that this function may not skip over invisible text that is so
5342 because of text properties and immediately follows a newline. If
5343 it would, function reseat_at_next_visible_line_start, when called
5344 from set_iterator_to_next, would effectively make invisible
5345 characters following a newline part of the wrong glyph row, which
5346 leads to wrong cursor motion. */
5349 forward_to_next_line_start (it
, skipped_p
)
5353 int old_selective
, newline_found_p
, n
;
5354 const int MAX_NEWLINE_DISTANCE
= 500;
5356 /* If already on a newline, just consume it to avoid unintended
5357 skipping over invisible text below. */
5358 if (it
->what
== IT_CHARACTER
5360 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5362 set_iterator_to_next (it
, 0);
5367 /* Don't handle selective display in the following. It's (a)
5368 unnecessary because it's done by the caller, and (b) leads to an
5369 infinite recursion because next_element_from_ellipsis indirectly
5370 calls this function. */
5371 old_selective
= it
->selective
;
5374 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5375 from buffer text. */
5376 for (n
= newline_found_p
= 0;
5377 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
5378 n
+= STRINGP (it
->string
) ? 0 : 1)
5380 if (!get_next_display_element (it
))
5382 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
5383 set_iterator_to_next (it
, 0);
5386 /* If we didn't find a newline near enough, see if we can use a
5388 if (!newline_found_p
)
5390 int start
= IT_CHARPOS (*it
);
5391 int limit
= find_next_newline_no_quit (start
, 1);
5394 xassert (!STRINGP (it
->string
));
5396 /* If there isn't any `display' property in sight, and no
5397 overlays, we can just use the position of the newline in
5399 if (it
->stop_charpos
>= limit
5400 || ((pos
= Fnext_single_property_change (make_number (start
),
5402 Qnil
, make_number (limit
)),
5404 && next_overlay_change (start
) == ZV
))
5406 IT_CHARPOS (*it
) = limit
;
5407 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
5408 *skipped_p
= newline_found_p
= 1;
5412 while (get_next_display_element (it
)
5413 && !newline_found_p
)
5415 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
5416 set_iterator_to_next (it
, 0);
5421 it
->selective
= old_selective
;
5422 return newline_found_p
;
5426 /* Set IT's current position to the previous visible line start. Skip
5427 invisible text that is so either due to text properties or due to
5428 selective display. Caution: this does not change IT->current_x and
5432 back_to_previous_visible_line_start (it
)
5435 while (IT_CHARPOS (*it
) > BEGV
)
5437 back_to_previous_line_start (it
);
5439 if (IT_CHARPOS (*it
) <= BEGV
)
5442 /* If selective > 0, then lines indented more than that values
5444 if (it
->selective
> 0
5445 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5446 (double) it
->selective
)) /* iftc */
5449 /* Check the newline before point for invisibility. */
5452 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
5453 Qinvisible
, it
->window
);
5454 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
5458 if (IT_CHARPOS (*it
) <= BEGV
)
5465 Lisp_Object val
, overlay
;
5467 /* If newline is part of a composition, continue from start of composition */
5468 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
5469 && beg
< IT_CHARPOS (*it
))
5472 /* If newline is replaced by a display property, find start of overlay
5473 or interval and continue search from that point. */
5475 pos
= --IT_CHARPOS (it2
);
5478 it2
.string_from_display_prop_p
= 0;
5479 if (handle_display_prop (&it2
) == HANDLED_RETURN
5480 && !NILP (val
= get_char_property_and_overlay
5481 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
5482 && (OVERLAYP (overlay
)
5483 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
5484 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
5487 /* Newline is not replaced by anything -- so we are done. */
5493 IT_CHARPOS (*it
) = beg
;
5494 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
5498 it
->continuation_lines_width
= 0;
5500 xassert (IT_CHARPOS (*it
) >= BEGV
);
5501 xassert (IT_CHARPOS (*it
) == BEGV
5502 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5507 /* Reseat iterator IT at the previous visible line start. Skip
5508 invisible text that is so either due to text properties or due to
5509 selective display. At the end, update IT's overlay information,
5510 face information etc. */
5513 reseat_at_previous_visible_line_start (it
)
5516 back_to_previous_visible_line_start (it
);
5517 reseat (it
, it
->current
.pos
, 1);
5522 /* Reseat iterator IT on the next visible line start in the current
5523 buffer. ON_NEWLINE_P non-zero means position IT on the newline
5524 preceding the line start. Skip over invisible text that is so
5525 because of selective display. Compute faces, overlays etc at the
5526 new position. Note that this function does not skip over text that
5527 is invisible because of text properties. */
5530 reseat_at_next_visible_line_start (it
, on_newline_p
)
5534 int newline_found_p
, skipped_p
= 0;
5536 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5538 /* Skip over lines that are invisible because they are indented
5539 more than the value of IT->selective. */
5540 if (it
->selective
> 0)
5541 while (IT_CHARPOS (*it
) < ZV
5542 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
5543 (double) it
->selective
)) /* iftc */
5545 xassert (IT_BYTEPOS (*it
) == BEGV
5546 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
5547 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
);
5550 /* Position on the newline if that's what's requested. */
5551 if (on_newline_p
&& newline_found_p
)
5553 if (STRINGP (it
->string
))
5555 if (IT_STRING_CHARPOS (*it
) > 0)
5557 --IT_STRING_CHARPOS (*it
);
5558 --IT_STRING_BYTEPOS (*it
);
5561 else if (IT_CHARPOS (*it
) > BEGV
)
5565 reseat (it
, it
->current
.pos
, 0);
5569 reseat (it
, it
->current
.pos
, 0);
5576 /***********************************************************************
5577 Changing an iterator's position
5578 ***********************************************************************/
5580 /* Change IT's current position to POS in current_buffer. If FORCE_P
5581 is non-zero, always check for text properties at the new position.
5582 Otherwise, text properties are only looked up if POS >=
5583 IT->check_charpos of a property. */
5586 reseat (it
, pos
, force_p
)
5588 struct text_pos pos
;
5591 int original_pos
= IT_CHARPOS (*it
);
5593 reseat_1 (it
, pos
, 0);
5595 /* Determine where to check text properties. Avoid doing it
5596 where possible because text property lookup is very expensive. */
5598 || CHARPOS (pos
) > it
->stop_charpos
5599 || CHARPOS (pos
) < original_pos
)
5606 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
5607 IT->stop_pos to POS, also. */
5610 reseat_1 (it
, pos
, set_stop_p
)
5612 struct text_pos pos
;
5615 /* Don't call this function when scanning a C string. */
5616 xassert (it
->s
== NULL
);
5618 /* POS must be a reasonable value. */
5619 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
5621 it
->current
.pos
= it
->position
= pos
;
5622 it
->end_charpos
= ZV
;
5624 it
->current
.dpvec_index
= -1;
5625 it
->current
.overlay_string_index
= -1;
5626 IT_STRING_CHARPOS (*it
) = -1;
5627 IT_STRING_BYTEPOS (*it
) = -1;
5629 it
->string_from_display_prop_p
= 0;
5630 it
->method
= GET_FROM_BUFFER
;
5631 it
->object
= it
->w
->buffer
;
5632 it
->area
= TEXT_AREA
;
5633 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
5635 it
->string_from_display_prop_p
= 0;
5636 it
->face_before_selective_p
= 0;
5639 it
->stop_charpos
= CHARPOS (pos
);
5643 /* Set up IT for displaying a string, starting at CHARPOS in window W.
5644 If S is non-null, it is a C string to iterate over. Otherwise,
5645 STRING gives a Lisp string to iterate over.
5647 If PRECISION > 0, don't return more then PRECISION number of
5648 characters from the string.
5650 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
5651 characters have been returned. FIELD_WIDTH < 0 means an infinite
5654 MULTIBYTE = 0 means disable processing of multibyte characters,
5655 MULTIBYTE > 0 means enable it,
5656 MULTIBYTE < 0 means use IT->multibyte_p.
5658 IT must be initialized via a prior call to init_iterator before
5659 calling this function. */
5662 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
5667 int precision
, field_width
, multibyte
;
5669 /* No region in strings. */
5670 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
5672 /* No text property checks performed by default, but see below. */
5673 it
->stop_charpos
= -1;
5675 /* Set iterator position and end position. */
5676 bzero (&it
->current
, sizeof it
->current
);
5677 it
->current
.overlay_string_index
= -1;
5678 it
->current
.dpvec_index
= -1;
5679 xassert (charpos
>= 0);
5681 /* If STRING is specified, use its multibyteness, otherwise use the
5682 setting of MULTIBYTE, if specified. */
5684 it
->multibyte_p
= multibyte
> 0;
5688 xassert (STRINGP (string
));
5689 it
->string
= string
;
5691 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
5692 it
->method
= GET_FROM_STRING
;
5693 it
->current
.string_pos
= string_pos (charpos
, string
);
5700 /* Note that we use IT->current.pos, not it->current.string_pos,
5701 for displaying C strings. */
5702 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
5703 if (it
->multibyte_p
)
5705 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
5706 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
5710 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
5711 it
->end_charpos
= it
->string_nchars
= strlen (s
);
5714 it
->method
= GET_FROM_C_STRING
;
5717 /* PRECISION > 0 means don't return more than PRECISION characters
5719 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
5720 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
5722 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
5723 characters have been returned. FIELD_WIDTH == 0 means don't pad,
5724 FIELD_WIDTH < 0 means infinite field width. This is useful for
5725 padding with `-' at the end of a mode line. */
5726 if (field_width
< 0)
5727 field_width
= INFINITY
;
5728 if (field_width
> it
->end_charpos
- charpos
)
5729 it
->end_charpos
= charpos
+ field_width
;
5731 /* Use the standard display table for displaying strings. */
5732 if (DISP_TABLE_P (Vstandard_display_table
))
5733 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
5735 it
->stop_charpos
= charpos
;
5741 /***********************************************************************
5743 ***********************************************************************/
5745 /* Map enum it_method value to corresponding next_element_from_* function. */
5747 static int (* get_next_element
[NUM_IT_METHODS
]) P_ ((struct it
*it
)) =
5749 next_element_from_buffer
,
5750 next_element_from_display_vector
,
5751 next_element_from_composition
,
5752 next_element_from_string
,
5753 next_element_from_c_string
,
5754 next_element_from_image
,
5755 next_element_from_stretch
5758 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
5760 /* Load IT's display element fields with information about the next
5761 display element from the current position of IT. Value is zero if
5762 end of buffer (or C string) is reached. */
5764 static struct frame
*last_escape_glyph_frame
= NULL
;
5765 static unsigned last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
5766 static int last_escape_glyph_merged_face_id
= 0;
5769 get_next_display_element (it
)
5772 /* Non-zero means that we found a display element. Zero means that
5773 we hit the end of what we iterate over. Performance note: the
5774 function pointer `method' used here turns out to be faster than
5775 using a sequence of if-statements. */
5779 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
5781 if (it
->what
== IT_CHARACTER
)
5783 /* Map via display table or translate control characters.
5784 IT->c, IT->len etc. have been set to the next character by
5785 the function call above. If we have a display table, and it
5786 contains an entry for IT->c, translate it. Don't do this if
5787 IT->c itself comes from a display table, otherwise we could
5788 end up in an infinite recursion. (An alternative could be to
5789 count the recursion depth of this function and signal an
5790 error when a certain maximum depth is reached.) Is it worth
5792 if (success_p
&& it
->dpvec
== NULL
)
5797 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
5800 struct Lisp_Vector
*v
= XVECTOR (dv
);
5802 /* Return the first character from the display table
5803 entry, if not empty. If empty, don't display the
5804 current character. */
5807 it
->dpvec_char_len
= it
->len
;
5808 it
->dpvec
= v
->contents
;
5809 it
->dpend
= v
->contents
+ v
->size
;
5810 it
->current
.dpvec_index
= 0;
5811 it
->dpvec_face_id
= -1;
5812 it
->saved_face_id
= it
->face_id
;
5813 it
->method
= GET_FROM_DISPLAY_VECTOR
;
5818 set_iterator_to_next (it
, 0);
5823 /* Translate control characters into `\003' or `^C' form.
5824 Control characters coming from a display table entry are
5825 currently not translated because we use IT->dpvec to hold
5826 the translation. This could easily be changed but I
5827 don't believe that it is worth doing.
5829 If it->multibyte_p is nonzero, non-printable non-ASCII
5830 characters are also translated to octal form.
5832 If it->multibyte_p is zero, eight-bit characters that
5833 don't have corresponding multibyte char code are also
5834 translated to octal form. */
5835 else if ((it
->c
< ' '
5836 ? (it
->area
!= TEXT_AREA
5837 /* In mode line, treat \n, \t like other crl chars. */
5839 && it
->glyph_row
&& it
->glyph_row
->mode_line_p
)
5840 || (it
->c
!= '\n' && it
->c
!= '\t'))
5842 ? (!CHAR_PRINTABLE_P (it
->c
)
5843 || (!NILP (Vnobreak_char_display
)
5844 && (it
->c
== 0xA0 /* NO-BREAK SPACE */
5845 || it
->c
== 0xAD /* SOFT HYPHEN */)))
5847 && (! unibyte_display_via_language_environment
5848 || (UNIBYTE_CHAR_HAS_MULTIBYTE_P (it
->c
)))))))
5850 /* IT->c is a control character which must be displayed
5851 either as '\003' or as `^C' where the '\\' and '^'
5852 can be defined in the display table. Fill
5853 IT->ctl_chars with glyphs for what we have to
5854 display. Then, set IT->dpvec to these glyphs. */
5857 int face_id
, lface_id
= 0 ;
5860 /* Handle control characters with ^. */
5862 if (it
->c
< 128 && it
->ctl_arrow_p
)
5866 g
= '^'; /* default glyph for Control */
5867 /* Set IT->ctl_chars[0] to the glyph for `^'. */
5869 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5870 && GLYPH_CODE_CHAR_VALID_P (gc
))
5872 g
= GLYPH_CODE_CHAR (gc
);
5873 lface_id
= GLYPH_CODE_FACE (gc
);
5877 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
5879 else if (it
->f
== last_escape_glyph_frame
5880 && it
->face_id
== last_escape_glyph_face_id
)
5882 face_id
= last_escape_glyph_merged_face_id
;
5886 /* Merge the escape-glyph face into the current face. */
5887 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5889 last_escape_glyph_frame
= it
->f
;
5890 last_escape_glyph_face_id
= it
->face_id
;
5891 last_escape_glyph_merged_face_id
= face_id
;
5894 XSETINT (it
->ctl_chars
[0], g
);
5895 XSETINT (it
->ctl_chars
[1], it
->c
^ 0100);
5897 goto display_control
;
5900 /* Handle non-break space in the mode where it only gets
5903 if (EQ (Vnobreak_char_display
, Qt
)
5906 /* Merge the no-break-space face into the current face. */
5907 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
5911 XSETINT (it
->ctl_chars
[0], ' ');
5913 goto display_control
;
5916 /* Handle sequences that start with the "escape glyph". */
5918 /* the default escape glyph is \. */
5919 escape_glyph
= '\\';
5922 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
))
5923 && GLYPH_CODE_CHAR_VALID_P (gc
))
5925 escape_glyph
= GLYPH_CODE_CHAR (gc
);
5926 lface_id
= GLYPH_CODE_FACE (gc
);
5930 /* The display table specified a face.
5931 Merge it into face_id and also into escape_glyph. */
5932 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
5935 else if (it
->f
== last_escape_glyph_frame
5936 && it
->face_id
== last_escape_glyph_face_id
)
5938 face_id
= last_escape_glyph_merged_face_id
;
5942 /* Merge the escape-glyph face into the current face. */
5943 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
5945 last_escape_glyph_frame
= it
->f
;
5946 last_escape_glyph_face_id
= it
->face_id
;
5947 last_escape_glyph_merged_face_id
= face_id
;
5950 /* Handle soft hyphens in the mode where they only get
5953 if (EQ (Vnobreak_char_display
, Qt
)
5957 XSETINT (it
->ctl_chars
[0], '-');
5959 goto display_control
;
5962 /* Handle non-break space and soft hyphen
5963 with the escape glyph. */
5965 if (it
->c
== 0xA0 || it
->c
== 0xAD)
5967 XSETINT (it
->ctl_chars
[0], escape_glyph
);
5968 it
->c
= (it
->c
== 0xA0 ? ' ' : '-');
5969 XSETINT (it
->ctl_chars
[1], it
->c
);
5971 goto display_control
;
5975 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5979 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
5980 if (CHAR_BYTE8_P (it
->c
))
5982 str
[0] = CHAR_TO_BYTE8 (it
->c
);
5985 else if (it
->c
< 256)
5992 /* It's an invalid character, which shouldn't
5993 happen actually, but due to bugs it may
5994 happen. Let's print the char as is, there's
5995 not much meaningful we can do with it. */
5997 str
[1] = it
->c
>> 8;
5998 str
[2] = it
->c
>> 16;
5999 str
[3] = it
->c
>> 24;
6003 for (i
= 0; i
< len
; i
++)
6006 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
6007 /* Insert three more glyphs into IT->ctl_chars for
6008 the octal display of the character. */
6009 g
= ((str
[i
] >> 6) & 7) + '0';
6010 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
6011 g
= ((str
[i
] >> 3) & 7) + '0';
6012 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
6013 g
= (str
[i
] & 7) + '0';
6014 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
6020 /* Set up IT->dpvec and return first character from it. */
6021 it
->dpvec_char_len
= it
->len
;
6022 it
->dpvec
= it
->ctl_chars
;
6023 it
->dpend
= it
->dpvec
+ ctl_len
;
6024 it
->current
.dpvec_index
= 0;
6025 it
->dpvec_face_id
= face_id
;
6026 it
->saved_face_id
= it
->face_id
;
6027 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6034 /* Adjust face id for a multibyte character. There are no multibyte
6035 character in unibyte text. */
6036 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6039 && FRAME_WINDOW_P (it
->f
))
6041 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6042 int pos
= (it
->s
? -1
6043 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6044 : IT_CHARPOS (*it
));
6046 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
, pos
, it
->string
);
6049 /* Is this character the last one of a run of characters with
6050 box? If yes, set IT->end_of_box_run_p to 1. */
6057 it
->end_of_box_run_p
6058 = ((face_id
= face_after_it_pos (it
),
6059 face_id
!= it
->face_id
)
6060 && (face
= FACE_FROM_ID (it
->f
, face_id
),
6061 face
->box
== FACE_NO_BOX
));
6064 /* Value is 0 if end of buffer or string reached. */
6069 /* Move IT to the next display element.
6071 RESEAT_P non-zero means if called on a newline in buffer text,
6072 skip to the next visible line start.
6074 Functions get_next_display_element and set_iterator_to_next are
6075 separate because I find this arrangement easier to handle than a
6076 get_next_display_element function that also increments IT's
6077 position. The way it is we can first look at an iterator's current
6078 display element, decide whether it fits on a line, and if it does,
6079 increment the iterator position. The other way around we probably
6080 would either need a flag indicating whether the iterator has to be
6081 incremented the next time, or we would have to implement a
6082 decrement position function which would not be easy to write. */
6085 set_iterator_to_next (it
, reseat_p
)
6089 /* Reset flags indicating start and end of a sequence of characters
6090 with box. Reset them at the start of this function because
6091 moving the iterator to a new position might set them. */
6092 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
6096 case GET_FROM_BUFFER
:
6097 /* The current display element of IT is a character from
6098 current_buffer. Advance in the buffer, and maybe skip over
6099 invisible lines that are so because of selective display. */
6100 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
6101 reseat_at_next_visible_line_start (it
, 0);
6104 xassert (it
->len
!= 0);
6105 IT_BYTEPOS (*it
) += it
->len
;
6106 IT_CHARPOS (*it
) += 1;
6107 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
6111 case GET_FROM_COMPOSITION
:
6112 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
6113 xassert (it
->sp
> 0);
6115 if (it
->method
== GET_FROM_STRING
)
6117 IT_STRING_BYTEPOS (*it
) += it
->len
;
6118 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
6119 goto consider_string_end
;
6121 else if (it
->method
== GET_FROM_BUFFER
)
6123 IT_BYTEPOS (*it
) += it
->len
;
6124 IT_CHARPOS (*it
) += it
->cmp_len
;
6128 case GET_FROM_C_STRING
:
6129 /* Current display element of IT is from a C string. */
6130 IT_BYTEPOS (*it
) += it
->len
;
6131 IT_CHARPOS (*it
) += 1;
6134 case GET_FROM_DISPLAY_VECTOR
:
6135 /* Current display element of IT is from a display table entry.
6136 Advance in the display table definition. Reset it to null if
6137 end reached, and continue with characters from buffers/
6139 ++it
->current
.dpvec_index
;
6141 /* Restore face of the iterator to what they were before the
6142 display vector entry (these entries may contain faces). */
6143 it
->face_id
= it
->saved_face_id
;
6145 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
6147 int recheck_faces
= it
->ellipsis_p
;
6150 it
->method
= GET_FROM_C_STRING
;
6151 else if (STRINGP (it
->string
))
6152 it
->method
= GET_FROM_STRING
;
6155 it
->method
= GET_FROM_BUFFER
;
6156 it
->object
= it
->w
->buffer
;
6160 it
->current
.dpvec_index
= -1;
6162 /* Skip over characters which were displayed via IT->dpvec. */
6163 if (it
->dpvec_char_len
< 0)
6164 reseat_at_next_visible_line_start (it
, 1);
6165 else if (it
->dpvec_char_len
> 0)
6167 if (it
->method
== GET_FROM_STRING
6168 && it
->n_overlay_strings
> 0)
6169 it
->ignore_overlay_strings_at_pos_p
= 1;
6170 it
->len
= it
->dpvec_char_len
;
6171 set_iterator_to_next (it
, reseat_p
);
6174 /* Maybe recheck faces after display vector */
6176 it
->stop_charpos
= IT_CHARPOS (*it
);
6180 case GET_FROM_STRING
:
6181 /* Current display element is a character from a Lisp string. */
6182 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
6183 IT_STRING_BYTEPOS (*it
) += it
->len
;
6184 IT_STRING_CHARPOS (*it
) += 1;
6186 consider_string_end
:
6188 if (it
->current
.overlay_string_index
>= 0)
6190 /* IT->string is an overlay string. Advance to the
6191 next, if there is one. */
6192 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6193 next_overlay_string (it
);
6197 /* IT->string is not an overlay string. If we reached
6198 its end, and there is something on IT->stack, proceed
6199 with what is on the stack. This can be either another
6200 string, this time an overlay string, or a buffer. */
6201 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
6205 if (it
->method
== GET_FROM_STRING
)
6206 goto consider_string_end
;
6211 case GET_FROM_IMAGE
:
6212 case GET_FROM_STRETCH
:
6213 /* The position etc with which we have to proceed are on
6214 the stack. The position may be at the end of a string,
6215 if the `display' property takes up the whole string. */
6216 xassert (it
->sp
> 0);
6218 if (it
->method
== GET_FROM_STRING
)
6219 goto consider_string_end
;
6223 /* There are no other methods defined, so this should be a bug. */
6227 xassert (it
->method
!= GET_FROM_STRING
6228 || (STRINGP (it
->string
)
6229 && IT_STRING_CHARPOS (*it
) >= 0));
6232 /* Load IT's display element fields with information about the next
6233 display element which comes from a display table entry or from the
6234 result of translating a control character to one of the forms `^C'
6237 IT->dpvec holds the glyphs to return as characters.
6238 IT->saved_face_id holds the face id before the display vector--
6239 it is restored into IT->face_idin set_iterator_to_next. */
6242 next_element_from_display_vector (it
)
6248 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
6250 it
->face_id
= it
->saved_face_id
;
6252 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
6253 That seemed totally bogus - so I changed it... */
6254 gc
= it
->dpvec
[it
->current
.dpvec_index
];
6256 if (GLYPH_CODE_P (gc
) && GLYPH_CODE_CHAR_VALID_P (gc
))
6258 it
->c
= GLYPH_CODE_CHAR (gc
);
6259 it
->len
= CHAR_BYTES (it
->c
);
6261 /* The entry may contain a face id to use. Such a face id is
6262 the id of a Lisp face, not a realized face. A face id of
6263 zero means no face is specified. */
6264 if (it
->dpvec_face_id
>= 0)
6265 it
->face_id
= it
->dpvec_face_id
;
6268 int lface_id
= GLYPH_CODE_FACE (gc
);
6270 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6275 /* Display table entry is invalid. Return a space. */
6276 it
->c
= ' ', it
->len
= 1;
6278 /* Don't change position and object of the iterator here. They are
6279 still the values of the character that had this display table
6280 entry or was translated, and that's what we want. */
6281 it
->what
= IT_CHARACTER
;
6286 /* Load IT with the next display element from Lisp string IT->string.
6287 IT->current.string_pos is the current position within the string.
6288 If IT->current.overlay_string_index >= 0, the Lisp string is an
6292 next_element_from_string (it
)
6295 struct text_pos position
;
6297 xassert (STRINGP (it
->string
));
6298 xassert (IT_STRING_CHARPOS (*it
) >= 0);
6299 position
= it
->current
.string_pos
;
6301 /* Time to check for invisible text? */
6302 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
6303 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
6307 /* Since a handler may have changed IT->method, we must
6309 return GET_NEXT_DISPLAY_ELEMENT (it
);
6312 if (it
->current
.overlay_string_index
>= 0)
6314 /* Get the next character from an overlay string. In overlay
6315 strings, There is no field width or padding with spaces to
6317 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
6322 else if (STRING_MULTIBYTE (it
->string
))
6324 int remaining
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6325 const unsigned char *s
= (SDATA (it
->string
)
6326 + IT_STRING_BYTEPOS (*it
));
6327 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
6331 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6337 /* Get the next character from a Lisp string that is not an
6338 overlay string. Such strings come from the mode line, for
6339 example. We may have to pad with spaces, or truncate the
6340 string. See also next_element_from_c_string. */
6341 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
6346 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
6348 /* Pad with spaces. */
6349 it
->c
= ' ', it
->len
= 1;
6350 CHARPOS (position
) = BYTEPOS (position
) = -1;
6352 else if (STRING_MULTIBYTE (it
->string
))
6354 int maxlen
= SBYTES (it
->string
) - IT_STRING_BYTEPOS (*it
);
6355 const unsigned char *s
= (SDATA (it
->string
)
6356 + IT_STRING_BYTEPOS (*it
));
6357 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
6361 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
6366 /* Record what we have and where it came from. */
6367 it
->what
= IT_CHARACTER
;
6368 it
->object
= it
->string
;
6369 it
->position
= position
;
6374 /* Load IT with next display element from C string IT->s.
6375 IT->string_nchars is the maximum number of characters to return
6376 from the string. IT->end_charpos may be greater than
6377 IT->string_nchars when this function is called, in which case we
6378 may have to return padding spaces. Value is zero if end of string
6379 reached, including padding spaces. */
6382 next_element_from_c_string (it
)
6388 it
->what
= IT_CHARACTER
;
6389 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
6392 /* IT's position can be greater IT->string_nchars in case a field
6393 width or precision has been specified when the iterator was
6395 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6397 /* End of the game. */
6401 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
6403 /* Pad with spaces. */
6404 it
->c
= ' ', it
->len
= 1;
6405 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
6407 else if (it
->multibyte_p
)
6409 /* Implementation note: The calls to strlen apparently aren't a
6410 performance problem because there is no noticeable performance
6411 difference between Emacs running in unibyte or multibyte mode. */
6412 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
6413 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
6417 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
6423 /* Set up IT to return characters from an ellipsis, if appropriate.
6424 The definition of the ellipsis glyphs may come from a display table
6425 entry. This function Fills IT with the first glyph from the
6426 ellipsis if an ellipsis is to be displayed. */
6429 next_element_from_ellipsis (it
)
6432 if (it
->selective_display_ellipsis_p
)
6433 setup_for_ellipsis (it
, it
->len
);
6436 /* The face at the current position may be different from the
6437 face we find after the invisible text. Remember what it
6438 was in IT->saved_face_id, and signal that it's there by
6439 setting face_before_selective_p. */
6440 it
->saved_face_id
= it
->face_id
;
6441 it
->method
= GET_FROM_BUFFER
;
6442 it
->object
= it
->w
->buffer
;
6443 reseat_at_next_visible_line_start (it
, 1);
6444 it
->face_before_selective_p
= 1;
6447 return GET_NEXT_DISPLAY_ELEMENT (it
);
6451 /* Deliver an image display element. The iterator IT is already
6452 filled with image information (done in handle_display_prop). Value
6457 next_element_from_image (it
)
6460 it
->what
= IT_IMAGE
;
6465 /* Fill iterator IT with next display element from a stretch glyph
6466 property. IT->object is the value of the text property. Value is
6470 next_element_from_stretch (it
)
6473 it
->what
= IT_STRETCH
;
6478 /* Load IT with the next display element from current_buffer. Value
6479 is zero if end of buffer reached. IT->stop_charpos is the next
6480 position at which to stop and check for text properties or buffer
6484 next_element_from_buffer (it
)
6489 /* Check this assumption, otherwise, we would never enter the
6490 if-statement, below. */
6491 xassert (IT_CHARPOS (*it
) >= BEGV
6492 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
6494 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
6496 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
6498 int overlay_strings_follow_p
;
6500 /* End of the game, except when overlay strings follow that
6501 haven't been returned yet. */
6502 if (it
->overlay_strings_at_end_processed_p
)
6503 overlay_strings_follow_p
= 0;
6506 it
->overlay_strings_at_end_processed_p
= 1;
6507 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
6510 if (overlay_strings_follow_p
)
6511 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6515 it
->position
= it
->current
.pos
;
6522 return GET_NEXT_DISPLAY_ELEMENT (it
);
6527 /* No face changes, overlays etc. in sight, so just return a
6528 character from current_buffer. */
6531 /* Maybe run the redisplay end trigger hook. Performance note:
6532 This doesn't seem to cost measurable time. */
6533 if (it
->redisplay_end_trigger_charpos
6535 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
6536 run_redisplay_end_trigger_hook (it
);
6538 /* Get the next character, maybe multibyte. */
6539 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
6540 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
6542 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
6543 - IT_BYTEPOS (*it
));
6544 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
6547 it
->c
= *p
, it
->len
= 1;
6549 /* Record what we have and where it came from. */
6550 it
->what
= IT_CHARACTER
;
6551 it
->object
= it
->w
->buffer
;
6552 it
->position
= it
->current
.pos
;
6554 /* Normally we return the character found above, except when we
6555 really want to return an ellipsis for selective display. */
6560 /* A value of selective > 0 means hide lines indented more
6561 than that number of columns. */
6562 if (it
->selective
> 0
6563 && IT_CHARPOS (*it
) + 1 < ZV
6564 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
6565 IT_BYTEPOS (*it
) + 1,
6566 (double) it
->selective
)) /* iftc */
6568 success_p
= next_element_from_ellipsis (it
);
6569 it
->dpvec_char_len
= -1;
6572 else if (it
->c
== '\r' && it
->selective
== -1)
6574 /* A value of selective == -1 means that everything from the
6575 CR to the end of the line is invisible, with maybe an
6576 ellipsis displayed for it. */
6577 success_p
= next_element_from_ellipsis (it
);
6578 it
->dpvec_char_len
= -1;
6583 /* Value is zero if end of buffer reached. */
6584 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
6589 /* Run the redisplay end trigger hook for IT. */
6592 run_redisplay_end_trigger_hook (it
)
6595 Lisp_Object args
[3];
6597 /* IT->glyph_row should be non-null, i.e. we should be actually
6598 displaying something, or otherwise we should not run the hook. */
6599 xassert (it
->glyph_row
);
6601 /* Set up hook arguments. */
6602 args
[0] = Qredisplay_end_trigger_functions
;
6603 args
[1] = it
->window
;
6604 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
6605 it
->redisplay_end_trigger_charpos
= 0;
6607 /* Since we are *trying* to run these functions, don't try to run
6608 them again, even if they get an error. */
6609 it
->w
->redisplay_end_trigger
= Qnil
;
6610 Frun_hook_with_args (3, args
);
6612 /* Notice if it changed the face of the character we are on. */
6613 handle_face_prop (it
);
6617 /* Deliver a composition display element. The iterator IT is already
6618 filled with composition information (done in
6619 handle_composition_prop). Value is always 1. */
6622 next_element_from_composition (it
)
6625 it
->what
= IT_COMPOSITION
;
6626 it
->position
= (STRINGP (it
->string
)
6627 ? it
->current
.string_pos
6629 if (STRINGP (it
->string
))
6630 it
->object
= it
->string
;
6632 it
->object
= it
->w
->buffer
;
6638 /***********************************************************************
6639 Moving an iterator without producing glyphs
6640 ***********************************************************************/
6642 /* Check if iterator is at a position corresponding to a valid buffer
6643 position after some move_it_ call. */
6645 #define IT_POS_VALID_AFTER_MOVE_P(it) \
6646 ((it)->method == GET_FROM_STRING \
6647 ? IT_STRING_CHARPOS (*it) == 0 \
6651 /* Move iterator IT to a specified buffer or X position within one
6652 line on the display without producing glyphs.
6654 OP should be a bit mask including some or all of these bits:
6655 MOVE_TO_X: Stop on reaching x-position TO_X.
6656 MOVE_TO_POS: Stop on reaching buffer or string position TO_CHARPOS.
6657 Regardless of OP's value, stop in reaching the end of the display line.
6659 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
6660 This means, in particular, that TO_X includes window's horizontal
6663 The return value has several possible values that
6664 say what condition caused the scan to stop:
6666 MOVE_POS_MATCH_OR_ZV
6667 - when TO_POS or ZV was reached.
6670 -when TO_X was reached before TO_POS or ZV were reached.
6673 - when we reached the end of the display area and the line must
6677 - when we reached the end of the display area and the line is
6681 - when we stopped at a line end, i.e. a newline or a CR and selective
6684 static enum move_it_result
6685 move_it_in_display_line_to (struct it
*it
,
6686 EMACS_INT to_charpos
, int to_x
,
6687 enum move_operation_enum op
)
6689 enum move_it_result result
= MOVE_UNDEFINED
;
6690 struct glyph_row
*saved_glyph_row
;
6691 struct it wrap_it
, atpos_it
, atx_it
;
6694 /* Don't produce glyphs in produce_glyphs. */
6695 saved_glyph_row
= it
->glyph_row
;
6696 it
->glyph_row
= NULL
;
6698 /* Use wrap_it to save a copy of IT wherever a word wrap could
6699 occur. Use atpos_it to save a copy of IT at the desired buffer
6700 position, if found, so that we can scan ahead and check if the
6701 word later overshoots the window edge. Use atx_it similarly, for
6707 #define BUFFER_POS_REACHED_P() \
6708 ((op & MOVE_TO_POS) != 0 \
6709 && BUFFERP (it->object) \
6710 && IT_CHARPOS (*it) >= to_charpos \
6711 && (it->method == GET_FROM_BUFFER \
6712 || (it->method == GET_FROM_DISPLAY_VECTOR \
6713 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
6715 /* If there's a line-/wrap-prefix, handle it. */
6716 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
6717 && it
->current_y
< it
->last_visible_y
)
6718 handle_line_prefix (it
);
6722 int x
, i
, ascent
= 0, descent
= 0;
6724 /* Utility macro to reset an iterator with x, ascent, and descent. */
6725 #define IT_RESET_X_ASCENT_DESCENT(IT) \
6726 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
6727 (IT)->max_descent = descent)
6729 /* Stop if we move beyond TO_CHARPOS (after an image or stretch
6731 if ((op
& MOVE_TO_POS
) != 0
6732 && BUFFERP (it
->object
)
6733 && it
->method
== GET_FROM_BUFFER
6734 && IT_CHARPOS (*it
) > to_charpos
)
6736 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6738 result
= MOVE_POS_MATCH_OR_ZV
;
6741 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6742 /* If wrap_it is valid, the current position might be in a
6743 word that is wrapped. So, save the iterator in
6744 atpos_it and continue to see if wrapping happens. */
6748 /* Stop when ZV reached.
6749 We used to stop here when TO_CHARPOS reached as well, but that is
6750 too soon if this glyph does not fit on this line. So we handle it
6751 explicitly below. */
6752 if (!get_next_display_element (it
))
6754 result
= MOVE_POS_MATCH_OR_ZV
;
6758 if (it
->line_wrap
== TRUNCATE
)
6760 if (BUFFER_POS_REACHED_P ())
6762 result
= MOVE_POS_MATCH_OR_ZV
;
6768 if (it
->line_wrap
== WORD_WRAP
)
6770 if (IT_DISPLAYING_WHITESPACE (it
))
6774 /* We have reached a glyph that follows one or more
6775 whitespace characters. If the position is
6776 already found, we are done. */
6777 if (atpos_it
.sp
>= 0)
6780 result
= MOVE_POS_MATCH_OR_ZV
;
6786 result
= MOVE_X_REACHED
;
6789 /* Otherwise, we can wrap here. */
6796 /* Remember the line height for the current line, in case
6797 the next element doesn't fit on the line. */
6798 ascent
= it
->max_ascent
;
6799 descent
= it
->max_descent
;
6801 /* The call to produce_glyphs will get the metrics of the
6802 display element IT is loaded with. Record the x-position
6803 before this display element, in case it doesn't fit on the
6807 PRODUCE_GLYPHS (it
);
6809 if (it
->area
!= TEXT_AREA
)
6811 set_iterator_to_next (it
, 1);
6815 /* The number of glyphs we get back in IT->nglyphs will normally
6816 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
6817 character on a terminal frame, or (iii) a line end. For the
6818 second case, IT->nglyphs - 1 padding glyphs will be present
6819 (on X frames, there is only one glyph produced for a
6820 composite character.
6822 The behavior implemented below means, for continuation lines,
6823 that as many spaces of a TAB as fit on the current line are
6824 displayed there. For terminal frames, as many glyphs of a
6825 multi-glyph character are displayed in the current line, too.
6826 This is what the old redisplay code did, and we keep it that
6827 way. Under X, the whole shape of a complex character must
6828 fit on the line or it will be completely displayed in the
6831 Note that both for tabs and padding glyphs, all glyphs have
6835 /* More than one glyph or glyph doesn't fit on line. All
6836 glyphs have the same width. */
6837 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
6839 int x_before_this_char
= x
;
6840 int hpos_before_this_char
= it
->hpos
;
6842 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
6844 new_x
= x
+ single_glyph_width
;
6846 /* We want to leave anything reaching TO_X to the caller. */
6847 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
6849 if (BUFFER_POS_REACHED_P ())
6851 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6852 goto buffer_pos_reached
;
6853 if (atpos_it
.sp
< 0)
6856 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6861 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6864 result
= MOVE_X_REACHED
;
6870 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
6875 if (/* Lines are continued. */
6876 it
->line_wrap
!= TRUNCATE
6877 && (/* And glyph doesn't fit on the line. */
6878 new_x
> it
->last_visible_x
6879 /* Or it fits exactly and we're on a window
6881 || (new_x
== it
->last_visible_x
6882 && FRAME_WINDOW_P (it
->f
))))
6884 if (/* IT->hpos == 0 means the very first glyph
6885 doesn't fit on the line, e.g. a wide image. */
6887 || (new_x
== it
->last_visible_x
6888 && FRAME_WINDOW_P (it
->f
)))
6891 it
->current_x
= new_x
;
6893 /* The character's last glyph just barely fits
6895 if (i
== it
->nglyphs
- 1)
6897 /* If this is the destination position,
6898 return a position *before* it in this row,
6899 now that we know it fits in this row. */
6900 if (BUFFER_POS_REACHED_P ())
6902 if (it
->line_wrap
!= WORD_WRAP
6905 it
->hpos
= hpos_before_this_char
;
6906 it
->current_x
= x_before_this_char
;
6907 result
= MOVE_POS_MATCH_OR_ZV
;
6910 if (it
->line_wrap
== WORD_WRAP
6914 atpos_it
.current_x
= x_before_this_char
;
6915 atpos_it
.hpos
= hpos_before_this_char
;
6919 set_iterator_to_next (it
, 1);
6920 #ifdef HAVE_WINDOW_SYSTEM
6921 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
6923 if (!get_next_display_element (it
))
6925 result
= MOVE_POS_MATCH_OR_ZV
;
6928 if (BUFFER_POS_REACHED_P ())
6930 if (ITERATOR_AT_END_OF_LINE_P (it
))
6931 result
= MOVE_POS_MATCH_OR_ZV
;
6933 result
= MOVE_LINE_CONTINUED
;
6936 if (ITERATOR_AT_END_OF_LINE_P (it
))
6938 result
= MOVE_NEWLINE_OR_CR
;
6942 #endif /* HAVE_WINDOW_SYSTEM */
6946 IT_RESET_X_ASCENT_DESCENT (it
);
6948 if (wrap_it
.sp
>= 0)
6955 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
6957 result
= MOVE_LINE_CONTINUED
;
6961 if (BUFFER_POS_REACHED_P ())
6963 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
6964 goto buffer_pos_reached
;
6965 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
6968 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
6972 if (new_x
> it
->first_visible_x
)
6974 /* Glyph is visible. Increment number of glyphs that
6975 would be displayed. */
6980 if (result
!= MOVE_UNDEFINED
)
6983 else if (BUFFER_POS_REACHED_P ())
6986 IT_RESET_X_ASCENT_DESCENT (it
);
6987 result
= MOVE_POS_MATCH_OR_ZV
;
6990 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
6992 /* Stop when TO_X specified and reached. This check is
6993 necessary here because of lines consisting of a line end,
6994 only. The line end will not produce any glyphs and we
6995 would never get MOVE_X_REACHED. */
6996 xassert (it
->nglyphs
== 0);
6997 result
= MOVE_X_REACHED
;
7001 /* Is this a line end? If yes, we're done. */
7002 if (ITERATOR_AT_END_OF_LINE_P (it
))
7004 result
= MOVE_NEWLINE_OR_CR
;
7008 /* The current display element has been consumed. Advance
7010 set_iterator_to_next (it
, 1);
7012 /* Stop if lines are truncated and IT's current x-position is
7013 past the right edge of the window now. */
7014 if (it
->line_wrap
== TRUNCATE
7015 && it
->current_x
>= it
->last_visible_x
)
7017 #ifdef HAVE_WINDOW_SYSTEM
7018 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
7020 if (!get_next_display_element (it
)
7021 || BUFFER_POS_REACHED_P ())
7023 result
= MOVE_POS_MATCH_OR_ZV
;
7026 if (ITERATOR_AT_END_OF_LINE_P (it
))
7028 result
= MOVE_NEWLINE_OR_CR
;
7032 #endif /* HAVE_WINDOW_SYSTEM */
7033 result
= MOVE_LINE_TRUNCATED
;
7036 #undef IT_RESET_X_ASCENT_DESCENT
7039 #undef BUFFER_POS_REACHED_P
7041 /* If we scanned beyond to_pos and didn't find a point to wrap at,
7042 restore the saved iterator. */
7043 if (atpos_it
.sp
>= 0)
7045 else if (atx_it
.sp
>= 0)
7050 /* Restore the iterator settings altered at the beginning of this
7052 it
->glyph_row
= saved_glyph_row
;
7056 /* For external use. */
7058 move_it_in_display_line (struct it
*it
,
7059 EMACS_INT to_charpos
, int to_x
,
7060 enum move_operation_enum op
)
7062 if (it
->line_wrap
== WORD_WRAP
7063 && (op
& MOVE_TO_X
))
7065 struct it save_it
= *it
;
7066 int skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7067 /* When word-wrap is on, TO_X may lie past the end
7068 of a wrapped line. Then it->current is the
7069 character on the next line, so backtrack to the
7070 space before the wrap point. */
7071 if (skip
== MOVE_LINE_CONTINUED
)
7073 int prev_x
= max (it
->current_x
- 1, 0);
7075 move_it_in_display_line_to
7076 (it
, -1, prev_x
, MOVE_TO_X
);
7080 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7084 /* Move IT forward until it satisfies one or more of the criteria in
7085 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
7087 OP is a bit-mask that specifies where to stop, and in particular,
7088 which of those four position arguments makes a difference. See the
7089 description of enum move_operation_enum.
7091 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
7092 screen line, this function will set IT to the next position >
7096 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
7098 int to_charpos
, to_x
, to_y
, to_vpos
;
7101 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
7107 if (op
& MOVE_TO_VPOS
)
7109 /* If no TO_CHARPOS and no TO_X specified, stop at the
7110 start of the line TO_VPOS. */
7111 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
7113 if (it
->vpos
== to_vpos
)
7119 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
7123 /* TO_VPOS >= 0 means stop at TO_X in the line at
7124 TO_VPOS, or at TO_POS, whichever comes first. */
7125 if (it
->vpos
== to_vpos
)
7131 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
7133 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
7138 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
7140 /* We have reached TO_X but not in the line we want. */
7141 skip
= move_it_in_display_line_to (it
, to_charpos
,
7143 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7151 else if (op
& MOVE_TO_Y
)
7153 struct it it_backup
;
7155 if (it
->line_wrap
== WORD_WRAP
)
7158 /* TO_Y specified means stop at TO_X in the line containing
7159 TO_Y---or at TO_CHARPOS if this is reached first. The
7160 problem is that we can't really tell whether the line
7161 contains TO_Y before we have completely scanned it, and
7162 this may skip past TO_X. What we do is to first scan to
7165 If TO_X is not specified, use a TO_X of zero. The reason
7166 is to make the outcome of this function more predictable.
7167 If we didn't use TO_X == 0, we would stop at the end of
7168 the line which is probably not what a caller would expect
7170 skip
= move_it_in_display_line_to
7171 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
7172 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
7174 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
7175 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7177 else if (skip
== MOVE_X_REACHED
)
7179 /* If TO_X was reached, we want to know whether TO_Y is
7180 in the line. We know this is the case if the already
7181 scanned glyphs make the line tall enough. Otherwise,
7182 we must check by scanning the rest of the line. */
7183 line_height
= it
->max_ascent
+ it
->max_descent
;
7184 if (to_y
>= it
->current_y
7185 && to_y
< it
->current_y
+ line_height
)
7191 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
7192 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
7194 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
7195 line_height
= it
->max_ascent
+ it
->max_descent
;
7196 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7198 if (to_y
>= it
->current_y
7199 && to_y
< it
->current_y
+ line_height
)
7201 /* If TO_Y is in this line and TO_X was reached
7202 above, we scanned too far. We have to restore
7203 IT's settings to the ones before skipping. */
7210 if (skip
== MOVE_POS_MATCH_OR_ZV
)
7216 /* Check whether TO_Y is in this line. */
7217 line_height
= it
->max_ascent
+ it
->max_descent
;
7218 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
7220 if (to_y
>= it
->current_y
7221 && to_y
< it
->current_y
+ line_height
)
7223 /* When word-wrap is on, TO_X may lie past the end
7224 of a wrapped line. Then it->current is the
7225 character on the next line, so backtrack to the
7226 space before the wrap point. */
7227 if (skip
== MOVE_LINE_CONTINUED
7228 && it
->line_wrap
== WORD_WRAP
)
7230 int prev_x
= max (it
->current_x
- 1, 0);
7232 skip
= move_it_in_display_line_to
7233 (it
, -1, prev_x
, MOVE_TO_X
);
7242 else if (BUFFERP (it
->object
)
7243 && it
->method
== GET_FROM_BUFFER
7244 && IT_CHARPOS (*it
) >= to_charpos
)
7245 skip
= MOVE_POS_MATCH_OR_ZV
;
7247 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
7251 case MOVE_POS_MATCH_OR_ZV
:
7255 case MOVE_NEWLINE_OR_CR
:
7256 set_iterator_to_next (it
, 1);
7257 it
->continuation_lines_width
= 0;
7260 case MOVE_LINE_TRUNCATED
:
7261 it
->continuation_lines_width
= 0;
7262 reseat_at_next_visible_line_start (it
, 0);
7263 if ((op
& MOVE_TO_POS
) != 0
7264 && IT_CHARPOS (*it
) > to_charpos
)
7271 case MOVE_LINE_CONTINUED
:
7272 /* For continued lines ending in a tab, some of the glyphs
7273 associated with the tab are displayed on the current
7274 line. Since it->current_x does not include these glyphs,
7275 we use it->last_visible_x instead. */
7276 it
->continuation_lines_width
+=
7277 (it
->c
== '\t') ? it
->last_visible_x
: it
->current_x
;
7284 /* Reset/increment for the next run. */
7285 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
7286 it
->current_x
= it
->hpos
= 0;
7287 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
7289 last_height
= it
->max_ascent
+ it
->max_descent
;
7290 last_max_ascent
= it
->max_ascent
;
7291 it
->max_ascent
= it
->max_descent
= 0;
7296 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
7300 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
7302 If DY > 0, move IT backward at least that many pixels. DY = 0
7303 means move IT backward to the preceding line start or BEGV. This
7304 function may move over more than DY pixels if IT->current_y - DY
7305 ends up in the middle of a line; in this case IT->current_y will be
7306 set to the top of the line moved to. */
7309 move_it_vertically_backward (it
, dy
)
7320 start_pos
= IT_CHARPOS (*it
);
7322 /* Estimate how many newlines we must move back. */
7323 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
7325 /* Set the iterator's position that many lines back. */
7326 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
7327 back_to_previous_visible_line_start (it
);
7329 /* Reseat the iterator here. When moving backward, we don't want
7330 reseat to skip forward over invisible text, set up the iterator
7331 to deliver from overlay strings at the new position etc. So,
7332 use reseat_1 here. */
7333 reseat_1 (it
, it
->current
.pos
, 1);
7335 /* We are now surely at a line start. */
7336 it
->current_x
= it
->hpos
= 0;
7337 it
->continuation_lines_width
= 0;
7339 /* Move forward and see what y-distance we moved. First move to the
7340 start of the next line so that we get its height. We need this
7341 height to be able to tell whether we reached the specified
7344 it2
.max_ascent
= it2
.max_descent
= 0;
7347 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
7348 MOVE_TO_POS
| MOVE_TO_VPOS
);
7350 while (!IT_POS_VALID_AFTER_MOVE_P (&it2
));
7351 xassert (IT_CHARPOS (*it
) >= BEGV
);
7354 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
7355 xassert (IT_CHARPOS (*it
) >= BEGV
);
7356 /* H is the actual vertical distance from the position in *IT
7357 and the starting position. */
7358 h
= it2
.current_y
- it
->current_y
;
7359 /* NLINES is the distance in number of lines. */
7360 nlines
= it2
.vpos
- it
->vpos
;
7362 /* Correct IT's y and vpos position
7363 so that they are relative to the starting point. */
7369 /* DY == 0 means move to the start of the screen line. The
7370 value of nlines is > 0 if continuation lines were involved. */
7372 move_it_by_lines (it
, nlines
, 1);
7374 /* I think this assert is bogus if buffer contains
7375 invisible text or images. KFS. */
7376 xassert (IT_CHARPOS (*it
) <= start_pos
);
7381 /* The y-position we try to reach, relative to *IT.
7382 Note that H has been subtracted in front of the if-statement. */
7383 int target_y
= it
->current_y
+ h
- dy
;
7384 int y0
= it3
.current_y
;
7385 int y1
= line_bottom_y (&it3
);
7386 int line_height
= y1
- y0
;
7388 /* If we did not reach target_y, try to move further backward if
7389 we can. If we moved too far backward, try to move forward. */
7390 if (target_y
< it
->current_y
7391 /* This is heuristic. In a window that's 3 lines high, with
7392 a line height of 13 pixels each, recentering with point
7393 on the bottom line will try to move -39/2 = 19 pixels
7394 backward. Try to avoid moving into the first line. */
7395 && (it
->current_y
- target_y
7396 > min (window_box_height (it
->w
), line_height
* 2 / 3))
7397 && IT_CHARPOS (*it
) > BEGV
)
7399 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
7400 target_y
- it
->current_y
));
7401 dy
= it
->current_y
- target_y
;
7402 goto move_further_back
;
7404 else if (target_y
>= it
->current_y
+ line_height
7405 && IT_CHARPOS (*it
) < ZV
)
7407 /* Should move forward by at least one line, maybe more.
7409 Note: Calling move_it_by_lines can be expensive on
7410 terminal frames, where compute_motion is used (via
7411 vmotion) to do the job, when there are very long lines
7412 and truncate-lines is nil. That's the reason for
7413 treating terminal frames specially here. */
7415 if (!FRAME_WINDOW_P (it
->f
))
7416 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
7421 move_it_by_lines (it
, 1, 1);
7423 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
7427 /* I think this assert is bogus if buffer contains
7428 invisible text or images. KFS. */
7429 xassert (IT_CHARPOS (*it
) >= BEGV
);
7436 /* Move IT by a specified amount of pixel lines DY. DY negative means
7437 move backwards. DY = 0 means move to start of screen line. At the
7438 end, IT will be on the start of a screen line. */
7441 move_it_vertically (it
, dy
)
7446 move_it_vertically_backward (it
, -dy
);
7449 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
7450 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
7451 MOVE_TO_POS
| MOVE_TO_Y
);
7452 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
7454 /* If buffer ends in ZV without a newline, move to the start of
7455 the line to satisfy the post-condition. */
7456 if (IT_CHARPOS (*it
) == ZV
7458 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
7459 move_it_by_lines (it
, 0, 0);
7464 /* Move iterator IT past the end of the text line it is in. */
7467 move_it_past_eol (it
)
7470 enum move_it_result rc
;
7472 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
7473 if (rc
== MOVE_NEWLINE_OR_CR
)
7474 set_iterator_to_next (it
, 0);
7478 #if 0 /* Currently not used. */
7480 /* Return non-zero if some text between buffer positions START_CHARPOS
7481 and END_CHARPOS is invisible. IT->window is the window for text
7485 invisible_text_between_p (it
, start_charpos
, end_charpos
)
7487 int start_charpos
, end_charpos
;
7489 Lisp_Object prop
, limit
;
7490 int invisible_found_p
;
7492 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
7494 /* Is text at START invisible? */
7495 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
7497 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
7498 invisible_found_p
= 1;
7501 limit
= Fnext_single_char_property_change (make_number (start_charpos
),
7503 make_number (end_charpos
));
7504 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
7507 return invisible_found_p
;
7513 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
7514 negative means move up. DVPOS == 0 means move to the start of the
7515 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
7516 NEED_Y_P is zero, IT->current_y will be left unchanged.
7518 Further optimization ideas: If we would know that IT->f doesn't use
7519 a face with proportional font, we could be faster for
7520 truncate-lines nil. */
7523 move_it_by_lines (it
, dvpos
, need_y_p
)
7525 int dvpos
, need_y_p
;
7527 struct position pos
;
7529 /* The commented-out optimization uses vmotion on terminals. This
7530 gives bad results, because elements like it->what, on which
7531 callers such as pos_visible_p rely, aren't updated. */
7532 /* if (!FRAME_WINDOW_P (it->f))
7534 struct text_pos textpos;
7536 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
7537 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
7538 reseat (it, textpos, 1);
7539 it->vpos += pos.vpos;
7540 it->current_y += pos.vpos;
7546 /* DVPOS == 0 means move to the start of the screen line. */
7547 move_it_vertically_backward (it
, 0);
7548 xassert (it
->current_x
== 0 && it
->hpos
== 0);
7549 /* Let next call to line_bottom_y calculate real line height */
7554 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
7555 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
7556 move_it_to (it
, IT_CHARPOS (*it
) + 1, -1, -1, -1, MOVE_TO_POS
);
7561 int start_charpos
, i
;
7563 /* Start at the beginning of the screen line containing IT's
7564 position. This may actually move vertically backwards,
7565 in case of overlays, so adjust dvpos accordingly. */
7567 move_it_vertically_backward (it
, 0);
7570 /* Go back -DVPOS visible lines and reseat the iterator there. */
7571 start_charpos
= IT_CHARPOS (*it
);
7572 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
7573 back_to_previous_visible_line_start (it
);
7574 reseat (it
, it
->current
.pos
, 1);
7576 /* Move further back if we end up in a string or an image. */
7577 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
7579 /* First try to move to start of display line. */
7581 move_it_vertically_backward (it
, 0);
7583 if (IT_POS_VALID_AFTER_MOVE_P (it
))
7585 /* If start of line is still in string or image,
7586 move further back. */
7587 back_to_previous_visible_line_start (it
);
7588 reseat (it
, it
->current
.pos
, 1);
7592 it
->current_x
= it
->hpos
= 0;
7594 /* Above call may have moved too far if continuation lines
7595 are involved. Scan forward and see if it did. */
7597 it2
.vpos
= it2
.current_y
= 0;
7598 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
7599 it
->vpos
-= it2
.vpos
;
7600 it
->current_y
-= it2
.current_y
;
7601 it
->current_x
= it
->hpos
= 0;
7603 /* If we moved too far back, move IT some lines forward. */
7604 if (it2
.vpos
> -dvpos
)
7606 int delta
= it2
.vpos
+ dvpos
;
7608 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
7609 /* Move back again if we got too far ahead. */
7610 if (IT_CHARPOS (*it
) >= start_charpos
)
7616 /* Return 1 if IT points into the middle of a display vector. */
7619 in_display_vector_p (it
)
7622 return (it
->method
== GET_FROM_DISPLAY_VECTOR
7623 && it
->current
.dpvec_index
> 0
7624 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
7628 /***********************************************************************
7630 ***********************************************************************/
7633 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
7637 add_to_log (format
, arg1
, arg2
)
7639 Lisp_Object arg1
, arg2
;
7641 Lisp_Object args
[3];
7642 Lisp_Object msg
, fmt
;
7645 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
7648 /* Do nothing if called asynchronously. Inserting text into
7649 a buffer may call after-change-functions and alike and
7650 that would means running Lisp asynchronously. */
7651 if (handling_signal
)
7655 GCPRO4 (fmt
, msg
, arg1
, arg2
);
7657 args
[0] = fmt
= build_string (format
);
7660 msg
= Fformat (3, args
);
7662 len
= SBYTES (msg
) + 1;
7663 SAFE_ALLOCA (buffer
, char *, len
);
7664 bcopy (SDATA (msg
), buffer
, len
);
7666 message_dolog (buffer
, len
- 1, 1, 0);
7673 /* Output a newline in the *Messages* buffer if "needs" one. */
7676 message_log_maybe_newline ()
7678 if (message_log_need_newline
)
7679 message_dolog ("", 0, 1, 0);
7683 /* Add a string M of length NBYTES to the message log, optionally
7684 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
7685 nonzero, means interpret the contents of M as multibyte. This
7686 function calls low-level routines in order to bypass text property
7687 hooks, etc. which might not be safe to run.
7689 This may GC (insert may run before/after change hooks),
7690 so the buffer M must NOT point to a Lisp string. */
7693 message_dolog (m
, nbytes
, nlflag
, multibyte
)
7695 int nbytes
, nlflag
, multibyte
;
7697 if (!NILP (Vmemory_full
))
7700 if (!NILP (Vmessage_log_max
))
7702 struct buffer
*oldbuf
;
7703 Lisp_Object oldpoint
, oldbegv
, oldzv
;
7704 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
7705 int point_at_end
= 0;
7707 Lisp_Object old_deactivate_mark
, tem
;
7708 struct gcpro gcpro1
;
7710 old_deactivate_mark
= Vdeactivate_mark
;
7711 oldbuf
= current_buffer
;
7712 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
7713 current_buffer
->undo_list
= Qt
;
7715 oldpoint
= message_dolog_marker1
;
7716 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
7717 oldbegv
= message_dolog_marker2
;
7718 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
7719 oldzv
= message_dolog_marker3
;
7720 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
7721 GCPRO1 (old_deactivate_mark
);
7729 BEGV_BYTE
= BEG_BYTE
;
7732 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7734 /* Insert the string--maybe converting multibyte to single byte
7735 or vice versa, so that all the text fits the buffer. */
7737 && NILP (current_buffer
->enable_multibyte_characters
))
7739 int i
, c
, char_bytes
;
7740 unsigned char work
[1];
7742 /* Convert a multibyte string to single-byte
7743 for the *Message* buffer. */
7744 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
7746 c
= string_char_and_length (m
+ i
, nbytes
- i
, &char_bytes
);
7747 work
[0] = (ASCII_CHAR_P (c
)
7749 : multibyte_char_to_unibyte (c
, Qnil
));
7750 insert_1_both (work
, 1, 1, 1, 0, 0);
7753 else if (! multibyte
7754 && ! NILP (current_buffer
->enable_multibyte_characters
))
7756 int i
, c
, char_bytes
;
7757 unsigned char *msg
= (unsigned char *) m
;
7758 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
7759 /* Convert a single-byte string to multibyte
7760 for the *Message* buffer. */
7761 for (i
= 0; i
< nbytes
; i
++)
7764 c
= unibyte_char_to_multibyte (c
);
7765 char_bytes
= CHAR_STRING (c
, str
);
7766 insert_1_both (str
, 1, char_bytes
, 1, 0, 0);
7770 insert_1 (m
, nbytes
, 1, 0, 0);
7774 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
7775 insert_1 ("\n", 1, 1, 0, 0);
7777 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7779 this_bol_byte
= PT_BYTE
;
7781 /* See if this line duplicates the previous one.
7782 If so, combine duplicates. */
7785 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
7787 prev_bol_byte
= PT_BYTE
;
7789 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
7790 this_bol
, this_bol_byte
);
7793 del_range_both (prev_bol
, prev_bol_byte
,
7794 this_bol
, this_bol_byte
, 0);
7800 /* If you change this format, don't forget to also
7801 change message_log_check_duplicate. */
7802 sprintf (dupstr
, " [%d times]", dup
);
7803 duplen
= strlen (dupstr
);
7804 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
7805 insert_1 (dupstr
, duplen
, 1, 0, 1);
7810 /* If we have more than the desired maximum number of lines
7811 in the *Messages* buffer now, delete the oldest ones.
7812 This is safe because we don't have undo in this buffer. */
7814 if (NATNUMP (Vmessage_log_max
))
7816 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
7817 -XFASTINT (Vmessage_log_max
) - 1, 0);
7818 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
7821 BEGV
= XMARKER (oldbegv
)->charpos
;
7822 BEGV_BYTE
= marker_byte_position (oldbegv
);
7831 ZV
= XMARKER (oldzv
)->charpos
;
7832 ZV_BYTE
= marker_byte_position (oldzv
);
7836 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
7838 /* We can't do Fgoto_char (oldpoint) because it will run some
7840 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
7841 XMARKER (oldpoint
)->bytepos
);
7844 unchain_marker (XMARKER (oldpoint
));
7845 unchain_marker (XMARKER (oldbegv
));
7846 unchain_marker (XMARKER (oldzv
));
7848 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
7849 set_buffer_internal (oldbuf
);
7851 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
7852 message_log_need_newline
= !nlflag
;
7853 Vdeactivate_mark
= old_deactivate_mark
;
7858 /* We are at the end of the buffer after just having inserted a newline.
7859 (Note: We depend on the fact we won't be crossing the gap.)
7860 Check to see if the most recent message looks a lot like the previous one.
7861 Return 0 if different, 1 if the new one should just replace it, or a
7862 value N > 1 if we should also append " [N times]". */
7865 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
7866 int prev_bol
, this_bol
;
7867 int prev_bol_byte
, this_bol_byte
;
7870 int len
= Z_BYTE
- 1 - this_bol_byte
;
7872 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
7873 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
7875 for (i
= 0; i
< len
; i
++)
7877 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
7885 if (*p1
++ == ' ' && *p1
++ == '[')
7888 while (*p1
>= '0' && *p1
<= '9')
7889 n
= n
* 10 + *p1
++ - '0';
7890 if (strncmp (p1
, " times]\n", 8) == 0)
7897 /* Display an echo area message M with a specified length of NBYTES
7898 bytes. The string may include null characters. If M is 0, clear
7899 out any existing message, and let the mini-buffer text show
7902 This may GC, so the buffer M must NOT point to a Lisp string. */
7905 message2 (m
, nbytes
, multibyte
)
7910 /* First flush out any partial line written with print. */
7911 message_log_maybe_newline ();
7913 message_dolog (m
, nbytes
, 1, multibyte
);
7914 message2_nolog (m
, nbytes
, multibyte
);
7918 /* The non-logging counterpart of message2. */
7921 message2_nolog (m
, nbytes
, multibyte
)
7923 int nbytes
, multibyte
;
7925 struct frame
*sf
= SELECTED_FRAME ();
7926 message_enable_multibyte
= multibyte
;
7930 if (noninteractive_need_newline
)
7931 putc ('\n', stderr
);
7932 noninteractive_need_newline
= 0;
7934 fwrite (m
, nbytes
, 1, stderr
);
7935 if (cursor_in_echo_area
== 0)
7936 fprintf (stderr
, "\n");
7939 /* A null message buffer means that the frame hasn't really been
7940 initialized yet. Error messages get reported properly by
7941 cmd_error, so this must be just an informative message; toss it. */
7942 else if (INTERACTIVE
7943 && sf
->glyphs_initialized_p
7944 && FRAME_MESSAGE_BUF (sf
))
7946 Lisp_Object mini_window
;
7949 /* Get the frame containing the mini-buffer
7950 that the selected frame is using. */
7951 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7952 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7954 FRAME_SAMPLE_VISIBILITY (f
);
7955 if (FRAME_VISIBLE_P (sf
)
7956 && ! FRAME_VISIBLE_P (f
))
7957 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
7961 set_message (m
, Qnil
, nbytes
, multibyte
);
7962 if (minibuffer_auto_raise
)
7963 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
7966 clear_message (1, 1);
7968 do_pending_window_change (0);
7969 echo_area_display (1);
7970 do_pending_window_change (0);
7971 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
7972 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
7977 /* Display an echo area message M with a specified length of NBYTES
7978 bytes. The string may include null characters. If M is not a
7979 string, clear out any existing message, and let the mini-buffer
7982 This function cancels echoing. */
7985 message3 (m
, nbytes
, multibyte
)
7990 struct gcpro gcpro1
;
7993 clear_message (1,1);
7996 /* First flush out any partial line written with print. */
7997 message_log_maybe_newline ();
8003 SAFE_ALLOCA (buffer
, char *, nbytes
);
8004 bcopy (SDATA (m
), buffer
, nbytes
);
8005 message_dolog (buffer
, nbytes
, 1, multibyte
);
8008 message3_nolog (m
, nbytes
, multibyte
);
8014 /* The non-logging version of message3.
8015 This does not cancel echoing, because it is used for echoing.
8016 Perhaps we need to make a separate function for echoing
8017 and make this cancel echoing. */
8020 message3_nolog (m
, nbytes
, multibyte
)
8022 int nbytes
, multibyte
;
8024 struct frame
*sf
= SELECTED_FRAME ();
8025 message_enable_multibyte
= multibyte
;
8029 if (noninteractive_need_newline
)
8030 putc ('\n', stderr
);
8031 noninteractive_need_newline
= 0;
8033 fwrite (SDATA (m
), nbytes
, 1, stderr
);
8034 if (cursor_in_echo_area
== 0)
8035 fprintf (stderr
, "\n");
8038 /* A null message buffer means that the frame hasn't really been
8039 initialized yet. Error messages get reported properly by
8040 cmd_error, so this must be just an informative message; toss it. */
8041 else if (INTERACTIVE
8042 && sf
->glyphs_initialized_p
8043 && FRAME_MESSAGE_BUF (sf
))
8045 Lisp_Object mini_window
;
8049 /* Get the frame containing the mini-buffer
8050 that the selected frame is using. */
8051 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8052 frame
= XWINDOW (mini_window
)->frame
;
8055 FRAME_SAMPLE_VISIBILITY (f
);
8056 if (FRAME_VISIBLE_P (sf
)
8057 && !FRAME_VISIBLE_P (f
))
8058 Fmake_frame_visible (frame
);
8060 if (STRINGP (m
) && SCHARS (m
) > 0)
8062 set_message (NULL
, m
, nbytes
, multibyte
);
8063 if (minibuffer_auto_raise
)
8064 Fraise_frame (frame
);
8065 /* Assume we are not echoing.
8066 (If we are, echo_now will override this.) */
8067 echo_message_buffer
= Qnil
;
8070 clear_message (1, 1);
8072 do_pending_window_change (0);
8073 echo_area_display (1);
8074 do_pending_window_change (0);
8075 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
8076 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
8081 /* Display a null-terminated echo area message M. If M is 0, clear
8082 out any existing message, and let the mini-buffer text show through.
8084 The buffer M must continue to exist until after the echo area gets
8085 cleared or some other message gets displayed there. Do not pass
8086 text that is stored in a Lisp string. Do not pass text in a buffer
8087 that was alloca'd. */
8093 message2 (m
, (m
? strlen (m
) : 0), 0);
8097 /* The non-logging counterpart of message1. */
8103 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
8106 /* Display a message M which contains a single %s
8107 which gets replaced with STRING. */
8110 message_with_string (m
, string
, log
)
8115 CHECK_STRING (string
);
8121 if (noninteractive_need_newline
)
8122 putc ('\n', stderr
);
8123 noninteractive_need_newline
= 0;
8124 fprintf (stderr
, m
, SDATA (string
));
8125 if (cursor_in_echo_area
== 0)
8126 fprintf (stderr
, "\n");
8130 else if (INTERACTIVE
)
8132 /* The frame whose minibuffer we're going to display the message on.
8133 It may be larger than the selected frame, so we need
8134 to use its buffer, not the selected frame's buffer. */
8135 Lisp_Object mini_window
;
8136 struct frame
*f
, *sf
= SELECTED_FRAME ();
8138 /* Get the frame containing the minibuffer
8139 that the selected frame is using. */
8140 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8141 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8143 /* A null message buffer means that the frame hasn't really been
8144 initialized yet. Error messages get reported properly by
8145 cmd_error, so this must be just an informative message; toss it. */
8146 if (FRAME_MESSAGE_BUF (f
))
8148 Lisp_Object args
[2], message
;
8149 struct gcpro gcpro1
, gcpro2
;
8151 args
[0] = build_string (m
);
8152 args
[1] = message
= string
;
8153 GCPRO2 (args
[0], message
);
8156 message
= Fformat (2, args
);
8159 message3 (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8161 message3_nolog (message
, SBYTES (message
), STRING_MULTIBYTE (message
));
8165 /* Print should start at the beginning of the message
8166 buffer next time. */
8167 message_buf_print
= 0;
8173 /* Dump an informative message to the minibuf. If M is 0, clear out
8174 any existing message, and let the mini-buffer text show through. */
8178 message (m
, a1
, a2
, a3
)
8180 EMACS_INT a1
, a2
, a3
;
8186 if (noninteractive_need_newline
)
8187 putc ('\n', stderr
);
8188 noninteractive_need_newline
= 0;
8189 fprintf (stderr
, m
, a1
, a2
, a3
);
8190 if (cursor_in_echo_area
== 0)
8191 fprintf (stderr
, "\n");
8195 else if (INTERACTIVE
)
8197 /* The frame whose mini-buffer we're going to display the message
8198 on. It may be larger than the selected frame, so we need to
8199 use its buffer, not the selected frame's buffer. */
8200 Lisp_Object mini_window
;
8201 struct frame
*f
, *sf
= SELECTED_FRAME ();
8203 /* Get the frame containing the mini-buffer
8204 that the selected frame is using. */
8205 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8206 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
8208 /* A null message buffer means that the frame hasn't really been
8209 initialized yet. Error messages get reported properly by
8210 cmd_error, so this must be just an informative message; toss
8212 if (FRAME_MESSAGE_BUF (f
))
8223 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8224 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
8226 len
= doprnt (FRAME_MESSAGE_BUF (f
),
8227 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
8229 #endif /* NO_ARG_ARRAY */
8231 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
8236 /* Print should start at the beginning of the message
8237 buffer next time. */
8238 message_buf_print
= 0;
8244 /* The non-logging version of message. */
8247 message_nolog (m
, a1
, a2
, a3
)
8249 EMACS_INT a1
, a2
, a3
;
8251 Lisp_Object old_log_max
;
8252 old_log_max
= Vmessage_log_max
;
8253 Vmessage_log_max
= Qnil
;
8254 message (m
, a1
, a2
, a3
);
8255 Vmessage_log_max
= old_log_max
;
8259 /* Display the current message in the current mini-buffer. This is
8260 only called from error handlers in process.c, and is not time
8266 if (!NILP (echo_area_buffer
[0]))
8269 string
= Fcurrent_message ();
8270 message3 (string
, SBYTES (string
),
8271 !NILP (current_buffer
->enable_multibyte_characters
));
8276 /* Make sure echo area buffers in `echo_buffers' are live.
8277 If they aren't, make new ones. */
8280 ensure_echo_area_buffers ()
8284 for (i
= 0; i
< 2; ++i
)
8285 if (!BUFFERP (echo_buffer
[i
])
8286 || NILP (XBUFFER (echo_buffer
[i
])->name
))
8289 Lisp_Object old_buffer
;
8292 old_buffer
= echo_buffer
[i
];
8293 sprintf (name
, " *Echo Area %d*", i
);
8294 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
8295 XBUFFER (echo_buffer
[i
])->truncate_lines
= Qnil
;
8297 for (j
= 0; j
< 2; ++j
)
8298 if (EQ (old_buffer
, echo_area_buffer
[j
]))
8299 echo_area_buffer
[j
] = echo_buffer
[i
];
8304 /* Call FN with args A1..A4 with either the current or last displayed
8305 echo_area_buffer as current buffer.
8307 WHICH zero means use the current message buffer
8308 echo_area_buffer[0]. If that is nil, choose a suitable buffer
8309 from echo_buffer[] and clear it.
8311 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
8312 suitable buffer from echo_buffer[] and clear it.
8314 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
8315 that the current message becomes the last displayed one, make
8316 choose a suitable buffer for echo_area_buffer[0], and clear it.
8318 Value is what FN returns. */
8321 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
)
8324 int (*fn
) P_ ((EMACS_INT
, Lisp_Object
, EMACS_INT
, EMACS_INT
));
8330 int this_one
, the_other
, clear_buffer_p
, rc
;
8331 int count
= SPECPDL_INDEX ();
8333 /* If buffers aren't live, make new ones. */
8334 ensure_echo_area_buffers ();
8339 this_one
= 0, the_other
= 1;
8341 this_one
= 1, the_other
= 0;
8344 this_one
= 0, the_other
= 1;
8347 /* We need a fresh one in case the current echo buffer equals
8348 the one containing the last displayed echo area message. */
8349 if (!NILP (echo_area_buffer
[this_one
])
8350 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
8351 echo_area_buffer
[this_one
] = Qnil
;
8354 /* Choose a suitable buffer from echo_buffer[] is we don't
8356 if (NILP (echo_area_buffer
[this_one
]))
8358 echo_area_buffer
[this_one
]
8359 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
8360 ? echo_buffer
[the_other
]
8361 : echo_buffer
[this_one
]);
8365 buffer
= echo_area_buffer
[this_one
];
8367 /* Don't get confused by reusing the buffer used for echoing
8368 for a different purpose. */
8369 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
8372 record_unwind_protect (unwind_with_echo_area_buffer
,
8373 with_echo_area_buffer_unwind_data (w
));
8375 /* Make the echo area buffer current. Note that for display
8376 purposes, it is not necessary that the displayed window's buffer
8377 == current_buffer, except for text property lookup. So, let's
8378 only set that buffer temporarily here without doing a full
8379 Fset_window_buffer. We must also change w->pointm, though,
8380 because otherwise an assertions in unshow_buffer fails, and Emacs
8382 set_buffer_internal_1 (XBUFFER (buffer
));
8386 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
8389 current_buffer
->undo_list
= Qt
;
8390 current_buffer
->read_only
= Qnil
;
8391 specbind (Qinhibit_read_only
, Qt
);
8392 specbind (Qinhibit_modification_hooks
, Qt
);
8394 if (clear_buffer_p
&& Z
> BEG
)
8397 xassert (BEGV
>= BEG
);
8398 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8400 rc
= fn (a1
, a2
, a3
, a4
);
8402 xassert (BEGV
>= BEG
);
8403 xassert (ZV
<= Z
&& ZV
>= BEGV
);
8405 unbind_to (count
, Qnil
);
8410 /* Save state that should be preserved around the call to the function
8411 FN called in with_echo_area_buffer. */
8414 with_echo_area_buffer_unwind_data (w
)
8418 Lisp_Object vector
, tmp
;
8420 /* Reduce consing by keeping one vector in
8421 Vwith_echo_area_save_vector. */
8422 vector
= Vwith_echo_area_save_vector
;
8423 Vwith_echo_area_save_vector
= Qnil
;
8426 vector
= Fmake_vector (make_number (7), Qnil
);
8428 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
8429 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
8430 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
8434 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
8435 ASET (vector
, i
, w
->buffer
); ++i
;
8436 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->charpos
)); ++i
;
8437 ASET (vector
, i
, make_number (XMARKER (w
->pointm
)->bytepos
)); ++i
;
8442 for (; i
< end
; ++i
)
8443 ASET (vector
, i
, Qnil
);
8446 xassert (i
== ASIZE (vector
));
8451 /* Restore global state from VECTOR which was created by
8452 with_echo_area_buffer_unwind_data. */
8455 unwind_with_echo_area_buffer (vector
)
8458 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
8459 Vdeactivate_mark
= AREF (vector
, 1);
8460 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
8462 if (WINDOWP (AREF (vector
, 3)))
8465 Lisp_Object buffer
, charpos
, bytepos
;
8467 w
= XWINDOW (AREF (vector
, 3));
8468 buffer
= AREF (vector
, 4);
8469 charpos
= AREF (vector
, 5);
8470 bytepos
= AREF (vector
, 6);
8473 set_marker_both (w
->pointm
, buffer
,
8474 XFASTINT (charpos
), XFASTINT (bytepos
));
8477 Vwith_echo_area_save_vector
= vector
;
8482 /* Set up the echo area for use by print functions. MULTIBYTE_P
8483 non-zero means we will print multibyte. */
8486 setup_echo_area_for_printing (multibyte_p
)
8489 /* If we can't find an echo area any more, exit. */
8490 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
8493 ensure_echo_area_buffers ();
8495 if (!message_buf_print
)
8497 /* A message has been output since the last time we printed.
8498 Choose a fresh echo area buffer. */
8499 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8500 echo_area_buffer
[0] = echo_buffer
[1];
8502 echo_area_buffer
[0] = echo_buffer
[0];
8504 /* Switch to that buffer and clear it. */
8505 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8506 current_buffer
->truncate_lines
= Qnil
;
8510 int count
= SPECPDL_INDEX ();
8511 specbind (Qinhibit_read_only
, Qt
);
8512 /* Note that undo recording is always disabled. */
8514 unbind_to (count
, Qnil
);
8516 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
8518 /* Set up the buffer for the multibyteness we need. */
8520 != !NILP (current_buffer
->enable_multibyte_characters
))
8521 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
8523 /* Raise the frame containing the echo area. */
8524 if (minibuffer_auto_raise
)
8526 struct frame
*sf
= SELECTED_FRAME ();
8527 Lisp_Object mini_window
;
8528 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
8529 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
8532 message_log_maybe_newline ();
8533 message_buf_print
= 1;
8537 if (NILP (echo_area_buffer
[0]))
8539 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
8540 echo_area_buffer
[0] = echo_buffer
[1];
8542 echo_area_buffer
[0] = echo_buffer
[0];
8545 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
8547 /* Someone switched buffers between print requests. */
8548 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
8549 current_buffer
->truncate_lines
= Qnil
;
8555 /* Display an echo area message in window W. Value is non-zero if W's
8556 height is changed. If display_last_displayed_message_p is
8557 non-zero, display the message that was last displayed, otherwise
8558 display the current message. */
8561 display_echo_area (w
)
8564 int i
, no_message_p
, window_height_changed_p
, count
;
8566 /* Temporarily disable garbage collections while displaying the echo
8567 area. This is done because a GC can print a message itself.
8568 That message would modify the echo area buffer's contents while a
8569 redisplay of the buffer is going on, and seriously confuse
8571 count
= inhibit_garbage_collection ();
8573 /* If there is no message, we must call display_echo_area_1
8574 nevertheless because it resizes the window. But we will have to
8575 reset the echo_area_buffer in question to nil at the end because
8576 with_echo_area_buffer will sets it to an empty buffer. */
8577 i
= display_last_displayed_message_p
? 1 : 0;
8578 no_message_p
= NILP (echo_area_buffer
[i
]);
8580 window_height_changed_p
8581 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
8582 display_echo_area_1
,
8583 (EMACS_INT
) w
, Qnil
, 0, 0);
8586 echo_area_buffer
[i
] = Qnil
;
8588 unbind_to (count
, Qnil
);
8589 return window_height_changed_p
;
8593 /* Helper for display_echo_area. Display the current buffer which
8594 contains the current echo area message in window W, a mini-window,
8595 a pointer to which is passed in A1. A2..A4 are currently not used.
8596 Change the height of W so that all of the message is displayed.
8597 Value is non-zero if height of W was changed. */
8600 display_echo_area_1 (a1
, a2
, a3
, a4
)
8605 struct window
*w
= (struct window
*) a1
;
8607 struct text_pos start
;
8608 int window_height_changed_p
= 0;
8610 /* Do this before displaying, so that we have a large enough glyph
8611 matrix for the display. If we can't get enough space for the
8612 whole text, display the last N lines. That works by setting w->start. */
8613 window_height_changed_p
= resize_mini_window (w
, 0);
8615 /* Use the starting position chosen by resize_mini_window. */
8616 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
8619 clear_glyph_matrix (w
->desired_matrix
);
8620 XSETWINDOW (window
, w
);
8621 try_window (window
, start
, 0);
8623 return window_height_changed_p
;
8627 /* Resize the echo area window to exactly the size needed for the
8628 currently displayed message, if there is one. If a mini-buffer
8629 is active, don't shrink it. */
8632 resize_echo_area_exactly ()
8634 if (BUFFERP (echo_area_buffer
[0])
8635 && WINDOWP (echo_area_window
))
8637 struct window
*w
= XWINDOW (echo_area_window
);
8639 Lisp_Object resize_exactly
;
8641 if (minibuf_level
== 0)
8642 resize_exactly
= Qt
;
8644 resize_exactly
= Qnil
;
8646 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
8647 (EMACS_INT
) w
, resize_exactly
, 0, 0);
8650 ++windows_or_buffers_changed
;
8651 ++update_mode_lines
;
8652 redisplay_internal (0);
8658 /* Callback function for with_echo_area_buffer, when used from
8659 resize_echo_area_exactly. A1 contains a pointer to the window to
8660 resize, EXACTLY non-nil means resize the mini-window exactly to the
8661 size of the text displayed. A3 and A4 are not used. Value is what
8662 resize_mini_window returns. */
8665 resize_mini_window_1 (a1
, exactly
, a3
, a4
)
8667 Lisp_Object exactly
;
8670 return resize_mini_window ((struct window
*) a1
, !NILP (exactly
));
8674 /* Resize mini-window W to fit the size of its contents. EXACT_P
8675 means size the window exactly to the size needed. Otherwise, it's
8676 only enlarged until W's buffer is empty.
8678 Set W->start to the right place to begin display. If the whole
8679 contents fit, start at the beginning. Otherwise, start so as
8680 to make the end of the contents appear. This is particularly
8681 important for y-or-n-p, but seems desirable generally.
8683 Value is non-zero if the window height has been changed. */
8686 resize_mini_window (w
, exact_p
)
8690 struct frame
*f
= XFRAME (w
->frame
);
8691 int window_height_changed_p
= 0;
8693 xassert (MINI_WINDOW_P (w
));
8695 /* By default, start display at the beginning. */
8696 set_marker_both (w
->start
, w
->buffer
,
8697 BUF_BEGV (XBUFFER (w
->buffer
)),
8698 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
8700 /* Don't resize windows while redisplaying a window; it would
8701 confuse redisplay functions when the size of the window they are
8702 displaying changes from under them. Such a resizing can happen,
8703 for instance, when which-func prints a long message while
8704 we are running fontification-functions. We're running these
8705 functions with safe_call which binds inhibit-redisplay to t. */
8706 if (!NILP (Vinhibit_redisplay
))
8709 /* Nil means don't try to resize. */
8710 if (NILP (Vresize_mini_windows
)
8711 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
8714 if (!FRAME_MINIBUF_ONLY_P (f
))
8717 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
8718 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
8719 int height
, max_height
;
8720 int unit
= FRAME_LINE_HEIGHT (f
);
8721 struct text_pos start
;
8722 struct buffer
*old_current_buffer
= NULL
;
8724 if (current_buffer
!= XBUFFER (w
->buffer
))
8726 old_current_buffer
= current_buffer
;
8727 set_buffer_internal (XBUFFER (w
->buffer
));
8730 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8732 /* Compute the max. number of lines specified by the user. */
8733 if (FLOATP (Vmax_mini_window_height
))
8734 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
8735 else if (INTEGERP (Vmax_mini_window_height
))
8736 max_height
= XINT (Vmax_mini_window_height
);
8738 max_height
= total_height
/ 4;
8740 /* Correct that max. height if it's bogus. */
8741 max_height
= max (1, max_height
);
8742 max_height
= min (total_height
, max_height
);
8744 /* Find out the height of the text in the window. */
8745 if (it
.line_wrap
== TRUNCATE
)
8750 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
8751 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
8752 height
= it
.current_y
+ last_height
;
8754 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
8755 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
8756 height
= (height
+ unit
- 1) / unit
;
8759 /* Compute a suitable window start. */
8760 if (height
> max_height
)
8762 height
= max_height
;
8763 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
8764 move_it_vertically_backward (&it
, (height
- 1) * unit
);
8765 start
= it
.current
.pos
;
8768 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
8769 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
8771 if (EQ (Vresize_mini_windows
, Qgrow_only
))
8773 /* Let it grow only, until we display an empty message, in which
8774 case the window shrinks again. */
8775 if (height
> WINDOW_TOTAL_LINES (w
))
8777 int old_height
= WINDOW_TOTAL_LINES (w
);
8778 freeze_window_starts (f
, 1);
8779 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8780 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8782 else if (height
< WINDOW_TOTAL_LINES (w
)
8783 && (exact_p
|| BEGV
== ZV
))
8785 int old_height
= WINDOW_TOTAL_LINES (w
);
8786 freeze_window_starts (f
, 0);
8787 shrink_mini_window (w
);
8788 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8793 /* Always resize to exact size needed. */
8794 if (height
> WINDOW_TOTAL_LINES (w
))
8796 int old_height
= WINDOW_TOTAL_LINES (w
);
8797 freeze_window_starts (f
, 1);
8798 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8799 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8801 else if (height
< WINDOW_TOTAL_LINES (w
))
8803 int old_height
= WINDOW_TOTAL_LINES (w
);
8804 freeze_window_starts (f
, 0);
8805 shrink_mini_window (w
);
8809 freeze_window_starts (f
, 1);
8810 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
8813 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
8817 if (old_current_buffer
)
8818 set_buffer_internal (old_current_buffer
);
8821 return window_height_changed_p
;
8825 /* Value is the current message, a string, or nil if there is no
8833 if (!BUFFERP (echo_area_buffer
[0]))
8837 with_echo_area_buffer (0, 0, current_message_1
,
8838 (EMACS_INT
) &msg
, Qnil
, 0, 0);
8840 echo_area_buffer
[0] = Qnil
;
8848 current_message_1 (a1
, a2
, a3
, a4
)
8853 Lisp_Object
*msg
= (Lisp_Object
*) a1
;
8856 *msg
= make_buffer_string (BEG
, Z
, 1);
8863 /* Push the current message on Vmessage_stack for later restauration
8864 by restore_message. Value is non-zero if the current message isn't
8865 empty. This is a relatively infrequent operation, so it's not
8866 worth optimizing. */
8872 msg
= current_message ();
8873 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
8874 return STRINGP (msg
);
8878 /* Restore message display from the top of Vmessage_stack. */
8885 xassert (CONSP (Vmessage_stack
));
8886 msg
= XCAR (Vmessage_stack
);
8888 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
8890 message3_nolog (msg
, 0, 0);
8894 /* Handler for record_unwind_protect calling pop_message. */
8897 pop_message_unwind (dummy
)
8904 /* Pop the top-most entry off Vmessage_stack. */
8909 xassert (CONSP (Vmessage_stack
));
8910 Vmessage_stack
= XCDR (Vmessage_stack
);
8914 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
8915 exits. If the stack is not empty, we have a missing pop_message
8919 check_message_stack ()
8921 if (!NILP (Vmessage_stack
))
8926 /* Truncate to NCHARS what will be displayed in the echo area the next
8927 time we display it---but don't redisplay it now. */
8930 truncate_echo_area (nchars
)
8934 echo_area_buffer
[0] = Qnil
;
8935 /* A null message buffer means that the frame hasn't really been
8936 initialized yet. Error messages get reported properly by
8937 cmd_error, so this must be just an informative message; toss it. */
8938 else if (!noninteractive
8940 && !NILP (echo_area_buffer
[0]))
8942 struct frame
*sf
= SELECTED_FRAME ();
8943 if (FRAME_MESSAGE_BUF (sf
))
8944 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
8949 /* Helper function for truncate_echo_area. Truncate the current
8950 message to at most NCHARS characters. */
8953 truncate_message_1 (nchars
, a2
, a3
, a4
)
8958 if (BEG
+ nchars
< Z
)
8959 del_range (BEG
+ nchars
, Z
);
8961 echo_area_buffer
[0] = Qnil
;
8966 /* Set the current message to a substring of S or STRING.
8968 If STRING is a Lisp string, set the message to the first NBYTES
8969 bytes from STRING. NBYTES zero means use the whole string. If
8970 STRING is multibyte, the message will be displayed multibyte.
8972 If S is not null, set the message to the first LEN bytes of S. LEN
8973 zero means use the whole string. MULTIBYTE_P non-zero means S is
8974 multibyte. Display the message multibyte in that case.
8976 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
8977 to t before calling set_message_1 (which calls insert).
8981 set_message (s
, string
, nbytes
, multibyte_p
)
8984 int nbytes
, multibyte_p
;
8986 message_enable_multibyte
8987 = ((s
&& multibyte_p
)
8988 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
8990 with_echo_area_buffer (0, -1, set_message_1
,
8991 (EMACS_INT
) s
, string
, nbytes
, multibyte_p
);
8992 message_buf_print
= 0;
8993 help_echo_showing_p
= 0;
8997 /* Helper function for set_message. Arguments have the same meaning
8998 as there, with A1 corresponding to S and A2 corresponding to STRING
8999 This function is called with the echo area buffer being
9003 set_message_1 (a1
, a2
, nbytes
, multibyte_p
)
9006 EMACS_INT nbytes
, multibyte_p
;
9008 const char *s
= (const char *) a1
;
9009 Lisp_Object string
= a2
;
9011 /* Change multibyteness of the echo buffer appropriately. */
9012 if (message_enable_multibyte
9013 != !NILP (current_buffer
->enable_multibyte_characters
))
9014 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
9016 current_buffer
->truncate_lines
= message_truncate_lines
? Qt
: Qnil
;
9018 /* Insert new message at BEG. */
9019 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
9021 if (STRINGP (string
))
9026 nbytes
= SBYTES (string
);
9027 nchars
= string_byte_to_char (string
, nbytes
);
9029 /* This function takes care of single/multibyte conversion. We
9030 just have to ensure that the echo area buffer has the right
9031 setting of enable_multibyte_characters. */
9032 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
9037 nbytes
= strlen (s
);
9039 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
9041 /* Convert from multi-byte to single-byte. */
9043 unsigned char work
[1];
9045 /* Convert a multibyte string to single-byte. */
9046 for (i
= 0; i
< nbytes
; i
+= n
)
9048 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
9049 work
[0] = (ASCII_CHAR_P (c
)
9051 : multibyte_char_to_unibyte (c
, Qnil
));
9052 insert_1_both (work
, 1, 1, 1, 0, 0);
9055 else if (!multibyte_p
9056 && !NILP (current_buffer
->enable_multibyte_characters
))
9058 /* Convert from single-byte to multi-byte. */
9060 const unsigned char *msg
= (const unsigned char *) s
;
9061 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9063 /* Convert a single-byte string to multibyte. */
9064 for (i
= 0; i
< nbytes
; i
++)
9067 c
= unibyte_char_to_multibyte (c
);
9068 n
= CHAR_STRING (c
, str
);
9069 insert_1_both (str
, 1, n
, 1, 0, 0);
9073 insert_1 (s
, nbytes
, 1, 0, 0);
9080 /* Clear messages. CURRENT_P non-zero means clear the current
9081 message. LAST_DISPLAYED_P non-zero means clear the message
9085 clear_message (current_p
, last_displayed_p
)
9086 int current_p
, last_displayed_p
;
9090 echo_area_buffer
[0] = Qnil
;
9091 message_cleared_p
= 1;
9094 if (last_displayed_p
)
9095 echo_area_buffer
[1] = Qnil
;
9097 message_buf_print
= 0;
9100 /* Clear garbaged frames.
9102 This function is used where the old redisplay called
9103 redraw_garbaged_frames which in turn called redraw_frame which in
9104 turn called clear_frame. The call to clear_frame was a source of
9105 flickering. I believe a clear_frame is not necessary. It should
9106 suffice in the new redisplay to invalidate all current matrices,
9107 and ensure a complete redisplay of all windows. */
9110 clear_garbaged_frames ()
9114 Lisp_Object tail
, frame
;
9115 int changed_count
= 0;
9117 FOR_EACH_FRAME (tail
, frame
)
9119 struct frame
*f
= XFRAME (frame
);
9121 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
9125 Fredraw_frame (frame
);
9126 f
->force_flush_display_p
= 1;
9128 clear_current_matrices (f
);
9137 ++windows_or_buffers_changed
;
9142 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
9143 is non-zero update selected_frame. Value is non-zero if the
9144 mini-windows height has been changed. */
9147 echo_area_display (update_frame_p
)
9150 Lisp_Object mini_window
;
9153 int window_height_changed_p
= 0;
9154 struct frame
*sf
= SELECTED_FRAME ();
9156 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9157 w
= XWINDOW (mini_window
);
9158 f
= XFRAME (WINDOW_FRAME (w
));
9160 /* Don't display if frame is invisible or not yet initialized. */
9161 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
9164 #ifdef HAVE_WINDOW_SYSTEM
9165 /* When Emacs starts, selected_frame may be the initial terminal
9166 frame. If we let this through, a message would be displayed on
9168 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
9170 #endif /* HAVE_WINDOW_SYSTEM */
9172 /* Redraw garbaged frames. */
9174 clear_garbaged_frames ();
9176 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
9178 echo_area_window
= mini_window
;
9179 window_height_changed_p
= display_echo_area (w
);
9180 w
->must_be_updated_p
= 1;
9182 /* Update the display, unless called from redisplay_internal.
9183 Also don't update the screen during redisplay itself. The
9184 update will happen at the end of redisplay, and an update
9185 here could cause confusion. */
9186 if (update_frame_p
&& !redisplaying_p
)
9190 /* If the display update has been interrupted by pending
9191 input, update mode lines in the frame. Due to the
9192 pending input, it might have been that redisplay hasn't
9193 been called, so that mode lines above the echo area are
9194 garbaged. This looks odd, so we prevent it here. */
9195 if (!display_completed
)
9196 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
9198 if (window_height_changed_p
9199 /* Don't do this if Emacs is shutting down. Redisplay
9200 needs to run hooks. */
9201 && !NILP (Vrun_hooks
))
9203 /* Must update other windows. Likewise as in other
9204 cases, don't let this update be interrupted by
9206 int count
= SPECPDL_INDEX ();
9207 specbind (Qredisplay_dont_pause
, Qt
);
9208 windows_or_buffers_changed
= 1;
9209 redisplay_internal (0);
9210 unbind_to (count
, Qnil
);
9212 else if (FRAME_WINDOW_P (f
) && n
== 0)
9214 /* Window configuration is the same as before.
9215 Can do with a display update of the echo area,
9216 unless we displayed some mode lines. */
9217 update_single_window (w
, 1);
9218 FRAME_RIF (f
)->flush_display (f
);
9221 update_frame (f
, 1, 1);
9223 /* If cursor is in the echo area, make sure that the next
9224 redisplay displays the minibuffer, so that the cursor will
9225 be replaced with what the minibuffer wants. */
9226 if (cursor_in_echo_area
)
9227 ++windows_or_buffers_changed
;
9230 else if (!EQ (mini_window
, selected_window
))
9231 windows_or_buffers_changed
++;
9233 /* Last displayed message is now the current message. */
9234 echo_area_buffer
[1] = echo_area_buffer
[0];
9235 /* Inform read_char that we're not echoing. */
9236 echo_message_buffer
= Qnil
;
9238 /* Prevent redisplay optimization in redisplay_internal by resetting
9239 this_line_start_pos. This is done because the mini-buffer now
9240 displays the message instead of its buffer text. */
9241 if (EQ (mini_window
, selected_window
))
9242 CHARPOS (this_line_start_pos
) = 0;
9244 return window_height_changed_p
;
9249 /***********************************************************************
9250 Mode Lines and Frame Titles
9251 ***********************************************************************/
9253 /* A buffer for constructing non-propertized mode-line strings and
9254 frame titles in it; allocated from the heap in init_xdisp and
9255 resized as needed in store_mode_line_noprop_char. */
9257 static char *mode_line_noprop_buf
;
9259 /* The buffer's end, and a current output position in it. */
9261 static char *mode_line_noprop_buf_end
;
9262 static char *mode_line_noprop_ptr
;
9264 #define MODE_LINE_NOPROP_LEN(start) \
9265 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
9268 MODE_LINE_DISPLAY
= 0,
9274 /* Alist that caches the results of :propertize.
9275 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
9276 static Lisp_Object mode_line_proptrans_alist
;
9278 /* List of strings making up the mode-line. */
9279 static Lisp_Object mode_line_string_list
;
9281 /* Base face property when building propertized mode line string. */
9282 static Lisp_Object mode_line_string_face
;
9283 static Lisp_Object mode_line_string_face_prop
;
9286 /* Unwind data for mode line strings */
9288 static Lisp_Object Vmode_line_unwind_vector
;
9291 format_mode_line_unwind_data (struct buffer
*obuf
,
9295 Lisp_Object vector
, tmp
;
9297 /* Reduce consing by keeping one vector in
9298 Vwith_echo_area_save_vector. */
9299 vector
= Vmode_line_unwind_vector
;
9300 Vmode_line_unwind_vector
= Qnil
;
9303 vector
= Fmake_vector (make_number (8), Qnil
);
9305 ASET (vector
, 0, make_number (mode_line_target
));
9306 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
9307 ASET (vector
, 2, mode_line_string_list
);
9308 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
9309 ASET (vector
, 4, mode_line_string_face
);
9310 ASET (vector
, 5, mode_line_string_face_prop
);
9313 XSETBUFFER (tmp
, obuf
);
9316 ASET (vector
, 6, tmp
);
9317 ASET (vector
, 7, owin
);
9323 unwind_format_mode_line (vector
)
9326 mode_line_target
= XINT (AREF (vector
, 0));
9327 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
9328 mode_line_string_list
= AREF (vector
, 2);
9329 if (! EQ (AREF (vector
, 3), Qt
))
9330 mode_line_proptrans_alist
= AREF (vector
, 3);
9331 mode_line_string_face
= AREF (vector
, 4);
9332 mode_line_string_face_prop
= AREF (vector
, 5);
9334 if (!NILP (AREF (vector
, 7)))
9335 /* Select window before buffer, since it may change the buffer. */
9336 Fselect_window (AREF (vector
, 7), Qt
);
9338 if (!NILP (AREF (vector
, 6)))
9340 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
9341 ASET (vector
, 6, Qnil
);
9344 Vmode_line_unwind_vector
= vector
;
9349 /* Store a single character C for the frame title in mode_line_noprop_buf.
9350 Re-allocate mode_line_noprop_buf if necessary. */
9354 store_mode_line_noprop_char (char c
)
9356 store_mode_line_noprop_char (c
)
9360 /* If output position has reached the end of the allocated buffer,
9361 double the buffer's size. */
9362 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
9364 int len
= MODE_LINE_NOPROP_LEN (0);
9365 int new_size
= 2 * len
* sizeof *mode_line_noprop_buf
;
9366 mode_line_noprop_buf
= (char *) xrealloc (mode_line_noprop_buf
, new_size
);
9367 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ new_size
;
9368 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
9371 *mode_line_noprop_ptr
++ = c
;
9375 /* Store part of a frame title in mode_line_noprop_buf, beginning at
9376 mode_line_noprop_ptr. STR is the string to store. Do not copy
9377 characters that yield more columns than PRECISION; PRECISION <= 0
9378 means copy the whole string. Pad with spaces until FIELD_WIDTH
9379 number of characters have been copied; FIELD_WIDTH <= 0 means don't
9380 pad. Called from display_mode_element when it is used to build a
9384 store_mode_line_noprop (str
, field_width
, precision
)
9385 const unsigned char *str
;
9386 int field_width
, precision
;
9391 /* Copy at most PRECISION chars from STR. */
9392 nbytes
= strlen (str
);
9393 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
9395 store_mode_line_noprop_char (*str
++);
9397 /* Fill up with spaces until FIELD_WIDTH reached. */
9398 while (field_width
> 0
9401 store_mode_line_noprop_char (' ');
9408 /***********************************************************************
9410 ***********************************************************************/
9412 #ifdef HAVE_WINDOW_SYSTEM
9414 /* Set the title of FRAME, if it has changed. The title format is
9415 Vicon_title_format if FRAME is iconified, otherwise it is
9416 frame_title_format. */
9419 x_consider_frame_title (frame
)
9422 struct frame
*f
= XFRAME (frame
);
9424 if (FRAME_WINDOW_P (f
)
9425 || FRAME_MINIBUF_ONLY_P (f
)
9426 || f
->explicit_name
)
9428 /* Do we have more than one visible frame on this X display? */
9435 int count
= SPECPDL_INDEX ();
9437 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
9439 Lisp_Object other_frame
= XCAR (tail
);
9440 struct frame
*tf
= XFRAME (other_frame
);
9443 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
9444 && !FRAME_MINIBUF_ONLY_P (tf
)
9445 && !EQ (other_frame
, tip_frame
)
9446 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
9450 /* Set global variable indicating that multiple frames exist. */
9451 multiple_frames
= CONSP (tail
);
9453 /* Switch to the buffer of selected window of the frame. Set up
9454 mode_line_target so that display_mode_element will output into
9455 mode_line_noprop_buf; then display the title. */
9456 record_unwind_protect (unwind_format_mode_line
,
9457 format_mode_line_unwind_data
9458 (current_buffer
, selected_window
, 0));
9460 Fselect_window (f
->selected_window
, Qt
);
9461 set_buffer_internal_1 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
9462 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
9464 mode_line_target
= MODE_LINE_TITLE
;
9465 title_start
= MODE_LINE_NOPROP_LEN (0);
9466 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
9467 NULL
, DEFAULT_FACE_ID
);
9468 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
9469 len
= MODE_LINE_NOPROP_LEN (title_start
);
9470 title
= mode_line_noprop_buf
+ title_start
;
9471 unbind_to (count
, Qnil
);
9473 /* Set the title only if it's changed. This avoids consing in
9474 the common case where it hasn't. (If it turns out that we've
9475 already wasted too much time by walking through the list with
9476 display_mode_element, then we might need to optimize at a
9477 higher level than this.) */
9478 if (! STRINGP (f
->name
)
9479 || SBYTES (f
->name
) != len
9480 || bcmp (title
, SDATA (f
->name
), len
) != 0)
9485 if (!MINI_WINDOW_P(XWINDOW(f
->selected_window
)))
9488 ns_set_name_as_filename (f
);
9490 x_implicitly_set_name (f
, make_string(title
, len
),
9496 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
9501 /* do this also for frames with explicit names */
9502 ns_implicitly_set_icon_type(f
);
9503 ns_set_doc_edited(f
, Fbuffer_modified_p
9504 (XWINDOW (f
->selected_window
)->buffer
), Qnil
);
9510 #endif /* not HAVE_WINDOW_SYSTEM */
9515 /***********************************************************************
9517 ***********************************************************************/
9520 /* Prepare for redisplay by updating menu-bar item lists when
9521 appropriate. This can call eval. */
9524 prepare_menu_bars ()
9527 struct gcpro gcpro1
, gcpro2
;
9529 Lisp_Object tooltip_frame
;
9531 #ifdef HAVE_WINDOW_SYSTEM
9532 tooltip_frame
= tip_frame
;
9534 tooltip_frame
= Qnil
;
9537 /* Update all frame titles based on their buffer names, etc. We do
9538 this before the menu bars so that the buffer-menu will show the
9539 up-to-date frame titles. */
9540 #ifdef HAVE_WINDOW_SYSTEM
9541 if (windows_or_buffers_changed
|| update_mode_lines
)
9543 Lisp_Object tail
, frame
;
9545 FOR_EACH_FRAME (tail
, frame
)
9548 if (!EQ (frame
, tooltip_frame
)
9549 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
9550 x_consider_frame_title (frame
);
9553 #endif /* HAVE_WINDOW_SYSTEM */
9555 /* Update the menu bar item lists, if appropriate. This has to be
9556 done before any actual redisplay or generation of display lines. */
9557 all_windows
= (update_mode_lines
9558 || buffer_shared
> 1
9559 || windows_or_buffers_changed
);
9562 Lisp_Object tail
, frame
;
9563 int count
= SPECPDL_INDEX ();
9564 /* 1 means that update_menu_bar has run its hooks
9565 so any further calls to update_menu_bar shouldn't do so again. */
9566 int menu_bar_hooks_run
= 0;
9568 record_unwind_save_match_data ();
9570 FOR_EACH_FRAME (tail
, frame
)
9574 /* Ignore tooltip frame. */
9575 if (EQ (frame
, tooltip_frame
))
9578 /* If a window on this frame changed size, report that to
9579 the user and clear the size-change flag. */
9580 if (FRAME_WINDOW_SIZES_CHANGED (f
))
9582 Lisp_Object functions
;
9584 /* Clear flag first in case we get an error below. */
9585 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
9586 functions
= Vwindow_size_change_functions
;
9587 GCPRO2 (tail
, functions
);
9589 while (CONSP (functions
))
9591 call1 (XCAR (functions
), frame
);
9592 functions
= XCDR (functions
);
9598 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
9599 #ifdef HAVE_WINDOW_SYSTEM
9600 update_tool_bar (f
, 0);
9605 unbind_to (count
, Qnil
);
9609 struct frame
*sf
= SELECTED_FRAME ();
9610 update_menu_bar (sf
, 1, 0);
9611 #ifdef HAVE_WINDOW_SYSTEM
9612 update_tool_bar (sf
, 1);
9616 /* Motif needs this. See comment in xmenu.c. Turn it off when
9617 pending_menu_activation is not defined. */
9618 #ifdef USE_X_TOOLKIT
9619 pending_menu_activation
= 0;
9624 /* Update the menu bar item list for frame F. This has to be done
9625 before we start to fill in any display lines, because it can call
9628 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
9630 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
9631 already ran the menu bar hooks for this redisplay, so there
9632 is no need to run them again. The return value is the
9633 updated value of this flag, to pass to the next call. */
9636 update_menu_bar (f
, save_match_data
, hooks_run
)
9638 int save_match_data
;
9642 register struct window
*w
;
9644 /* If called recursively during a menu update, do nothing. This can
9645 happen when, for instance, an activate-menubar-hook causes a
9647 if (inhibit_menubar_update
)
9650 window
= FRAME_SELECTED_WINDOW (f
);
9651 w
= XWINDOW (window
);
9653 #if 0 /* The if statement below this if statement used to include the
9654 condition !NILP (w->update_mode_line), rather than using
9655 update_mode_lines directly, and this if statement may have
9656 been added to make that condition work. Now the if
9657 statement below matches its comment, this isn't needed. */
9658 if (update_mode_lines
)
9659 w
->update_mode_line
= Qt
;
9662 if (FRAME_WINDOW_P (f
)
9664 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9665 || defined (HAVE_NS) || defined (USE_GTK)
9666 FRAME_EXTERNAL_MENU_BAR (f
)
9668 FRAME_MENU_BAR_LINES (f
) > 0
9670 : FRAME_MENU_BAR_LINES (f
) > 0)
9672 /* If the user has switched buffers or windows, we need to
9673 recompute to reflect the new bindings. But we'll
9674 recompute when update_mode_lines is set too; that means
9675 that people can use force-mode-line-update to request
9676 that the menu bar be recomputed. The adverse effect on
9677 the rest of the redisplay algorithm is about the same as
9678 windows_or_buffers_changed anyway. */
9679 if (windows_or_buffers_changed
9680 /* This used to test w->update_mode_line, but we believe
9681 there is no need to recompute the menu in that case. */
9682 || update_mode_lines
9683 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9684 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9685 != !NILP (w
->last_had_star
))
9686 || ((!NILP (Vtransient_mark_mode
)
9687 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9688 != !NILP (w
->region_showing
)))
9690 struct buffer
*prev
= current_buffer
;
9691 int count
= SPECPDL_INDEX ();
9693 specbind (Qinhibit_menubar_update
, Qt
);
9695 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9696 if (save_match_data
)
9697 record_unwind_save_match_data ();
9698 if (NILP (Voverriding_local_map_menu_flag
))
9700 specbind (Qoverriding_terminal_local_map
, Qnil
);
9701 specbind (Qoverriding_local_map
, Qnil
);
9706 /* Run the Lucid hook. */
9707 safe_run_hooks (Qactivate_menubar_hook
);
9709 /* If it has changed current-menubar from previous value,
9710 really recompute the menu-bar from the value. */
9711 if (! NILP (Vlucid_menu_bar_dirty_flag
))
9712 call0 (Qrecompute_lucid_menubar
);
9714 safe_run_hooks (Qmenu_bar_update_hook
);
9719 XSETFRAME (Vmenu_updating_frame
, f
);
9720 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
9722 /* Redisplay the menu bar in case we changed it. */
9723 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
9724 || defined (HAVE_NS) || defined (USE_GTK)
9725 if (FRAME_WINDOW_P (f
))
9727 #if defined (HAVE_NS)
9728 /* All frames on Mac OS share the same menubar. So only
9729 the selected frame should be allowed to set it. */
9730 if (f
== SELECTED_FRAME ())
9732 set_frame_menubar (f
, 0, 0);
9735 /* On a terminal screen, the menu bar is an ordinary screen
9736 line, and this makes it get updated. */
9737 w
->update_mode_line
= Qt
;
9738 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9739 /* In the non-toolkit version, the menu bar is an ordinary screen
9740 line, and this makes it get updated. */
9741 w
->update_mode_line
= Qt
;
9742 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
9744 unbind_to (count
, Qnil
);
9745 set_buffer_internal_1 (prev
);
9754 /***********************************************************************
9756 ***********************************************************************/
9758 #ifdef HAVE_WINDOW_SYSTEM
9761 Nominal cursor position -- where to draw output.
9762 HPOS and VPOS are window relative glyph matrix coordinates.
9763 X and Y are window relative pixel coordinates. */
9765 struct cursor_pos output_cursor
;
9769 Set the global variable output_cursor to CURSOR. All cursor
9770 positions are relative to updated_window. */
9773 set_output_cursor (cursor
)
9774 struct cursor_pos
*cursor
;
9776 output_cursor
.hpos
= cursor
->hpos
;
9777 output_cursor
.vpos
= cursor
->vpos
;
9778 output_cursor
.x
= cursor
->x
;
9779 output_cursor
.y
= cursor
->y
;
9784 Set a nominal cursor position.
9786 HPOS and VPOS are column/row positions in a window glyph matrix. X
9787 and Y are window text area relative pixel positions.
9789 If this is done during an update, updated_window will contain the
9790 window that is being updated and the position is the future output
9791 cursor position for that window. If updated_window is null, use
9792 selected_window and display the cursor at the given position. */
9795 x_cursor_to (vpos
, hpos
, y
, x
)
9796 int vpos
, hpos
, y
, x
;
9800 /* If updated_window is not set, work on selected_window. */
9804 w
= XWINDOW (selected_window
);
9806 /* Set the output cursor. */
9807 output_cursor
.hpos
= hpos
;
9808 output_cursor
.vpos
= vpos
;
9809 output_cursor
.x
= x
;
9810 output_cursor
.y
= y
;
9812 /* If not called as part of an update, really display the cursor.
9813 This will also set the cursor position of W. */
9814 if (updated_window
== NULL
)
9817 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
9818 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
9819 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
9824 #endif /* HAVE_WINDOW_SYSTEM */
9827 /***********************************************************************
9829 ***********************************************************************/
9831 #ifdef HAVE_WINDOW_SYSTEM
9833 /* Where the mouse was last time we reported a mouse event. */
9835 FRAME_PTR last_mouse_frame
;
9837 /* Tool-bar item index of the item on which a mouse button was pressed
9840 int last_tool_bar_item
;
9843 /* Update the tool-bar item list for frame F. This has to be done
9844 before we start to fill in any display lines. Called from
9845 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
9846 and restore it here. */
9849 update_tool_bar (f
, save_match_data
)
9851 int save_match_data
;
9853 #if defined (USE_GTK) || defined (HAVE_NS) || USE_MAC_TOOLBAR
9854 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
9856 int do_update
= WINDOWP (f
->tool_bar_window
)
9857 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
9865 window
= FRAME_SELECTED_WINDOW (f
);
9866 w
= XWINDOW (window
);
9868 /* If the user has switched buffers or windows, we need to
9869 recompute to reflect the new bindings. But we'll
9870 recompute when update_mode_lines is set too; that means
9871 that people can use force-mode-line-update to request
9872 that the menu bar be recomputed. The adverse effect on
9873 the rest of the redisplay algorithm is about the same as
9874 windows_or_buffers_changed anyway. */
9875 if (windows_or_buffers_changed
9876 || !NILP (w
->update_mode_line
)
9877 || update_mode_lines
9878 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
9879 < BUF_MODIFF (XBUFFER (w
->buffer
)))
9880 != !NILP (w
->last_had_star
))
9881 || ((!NILP (Vtransient_mark_mode
)
9882 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
9883 != !NILP (w
->region_showing
)))
9885 struct buffer
*prev
= current_buffer
;
9886 int count
= SPECPDL_INDEX ();
9887 Lisp_Object new_tool_bar
;
9889 struct gcpro gcpro1
;
9891 /* Set current_buffer to the buffer of the selected
9892 window of the frame, so that we get the right local
9894 set_buffer_internal_1 (XBUFFER (w
->buffer
));
9896 /* Save match data, if we must. */
9897 if (save_match_data
)
9898 record_unwind_save_match_data ();
9900 /* Make sure that we don't accidentally use bogus keymaps. */
9901 if (NILP (Voverriding_local_map_menu_flag
))
9903 specbind (Qoverriding_terminal_local_map
, Qnil
);
9904 specbind (Qoverriding_local_map
, Qnil
);
9907 GCPRO1 (new_tool_bar
);
9909 /* Build desired tool-bar items from keymaps. */
9910 new_tool_bar
= tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
9913 /* Redisplay the tool-bar if we changed it. */
9914 if (new_n_tool_bar
!= f
->n_tool_bar_items
9915 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
9917 /* Redisplay that happens asynchronously due to an expose event
9918 may access f->tool_bar_items. Make sure we update both
9919 variables within BLOCK_INPUT so no such event interrupts. */
9921 f
->tool_bar_items
= new_tool_bar
;
9922 f
->n_tool_bar_items
= new_n_tool_bar
;
9923 w
->update_mode_line
= Qt
;
9929 unbind_to (count
, Qnil
);
9930 set_buffer_internal_1 (prev
);
9936 /* Set F->desired_tool_bar_string to a Lisp string representing frame
9937 F's desired tool-bar contents. F->tool_bar_items must have
9938 been set up previously by calling prepare_menu_bars. */
9941 build_desired_tool_bar_string (f
)
9944 int i
, size
, size_needed
;
9945 struct gcpro gcpro1
, gcpro2
, gcpro3
;
9946 Lisp_Object image
, plist
, props
;
9948 image
= plist
= props
= Qnil
;
9949 GCPRO3 (image
, plist
, props
);
9951 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
9952 Otherwise, make a new string. */
9954 /* The size of the string we might be able to reuse. */
9955 size
= (STRINGP (f
->desired_tool_bar_string
)
9956 ? SCHARS (f
->desired_tool_bar_string
)
9959 /* We need one space in the string for each image. */
9960 size_needed
= f
->n_tool_bar_items
;
9962 /* Reuse f->desired_tool_bar_string, if possible. */
9963 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
9964 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
9968 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
9969 Fremove_text_properties (make_number (0), make_number (size
),
9970 props
, f
->desired_tool_bar_string
);
9973 /* Put a `display' property on the string for the images to display,
9974 put a `menu_item' property on tool-bar items with a value that
9975 is the index of the item in F's tool-bar item vector. */
9976 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
9978 #define PROP(IDX) AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
9980 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
9981 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
9982 int hmargin
, vmargin
, relief
, idx
, end
;
9983 extern Lisp_Object QCrelief
, QCmargin
, QCconversion
;
9985 /* If image is a vector, choose the image according to the
9987 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
9988 if (VECTORP (image
))
9992 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
9993 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
9996 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
9997 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
9999 xassert (ASIZE (image
) >= idx
);
10000 image
= AREF (image
, idx
);
10005 /* Ignore invalid image specifications. */
10006 if (!valid_image_p (image
))
10009 /* Display the tool-bar button pressed, or depressed. */
10010 plist
= Fcopy_sequence (XCDR (image
));
10012 /* Compute margin and relief to draw. */
10013 relief
= (tool_bar_button_relief
>= 0
10014 ? tool_bar_button_relief
10015 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
10016 hmargin
= vmargin
= relief
;
10018 if (INTEGERP (Vtool_bar_button_margin
)
10019 && XINT (Vtool_bar_button_margin
) > 0)
10021 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
10022 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
10024 else if (CONSP (Vtool_bar_button_margin
))
10026 if (INTEGERP (XCAR (Vtool_bar_button_margin
))
10027 && XINT (XCAR (Vtool_bar_button_margin
)) > 0)
10028 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
10030 if (INTEGERP (XCDR (Vtool_bar_button_margin
))
10031 && XINT (XCDR (Vtool_bar_button_margin
)) > 0)
10032 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
10035 if (auto_raise_tool_bar_buttons_p
)
10037 /* Add a `:relief' property to the image spec if the item is
10041 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
10048 /* If image is selected, display it pressed, i.e. with a
10049 negative relief. If it's not selected, display it with a
10051 plist
= Fplist_put (plist
, QCrelief
,
10053 ? make_number (-relief
)
10054 : make_number (relief
)));
10059 /* Put a margin around the image. */
10060 if (hmargin
|| vmargin
)
10062 if (hmargin
== vmargin
)
10063 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
10065 plist
= Fplist_put (plist
, QCmargin
,
10066 Fcons (make_number (hmargin
),
10067 make_number (vmargin
)));
10070 /* If button is not enabled, and we don't have special images
10071 for the disabled state, make the image appear disabled by
10072 applying an appropriate algorithm to it. */
10073 if (!enabled_p
&& idx
< 0)
10074 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
10076 /* Put a `display' text property on the string for the image to
10077 display. Put a `menu-item' property on the string that gives
10078 the start of this item's properties in the tool-bar items
10080 image
= Fcons (Qimage
, plist
);
10081 props
= list4 (Qdisplay
, image
,
10082 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
10084 /* Let the last image hide all remaining spaces in the tool bar
10085 string. The string can be longer than needed when we reuse a
10086 previous string. */
10087 if (i
+ 1 == f
->n_tool_bar_items
)
10088 end
= SCHARS (f
->desired_tool_bar_string
);
10091 Fadd_text_properties (make_number (i
), make_number (end
),
10092 props
, f
->desired_tool_bar_string
);
10100 /* Display one line of the tool-bar of frame IT->f.
10102 HEIGHT specifies the desired height of the tool-bar line.
10103 If the actual height of the glyph row is less than HEIGHT, the
10104 row's height is increased to HEIGHT, and the icons are centered
10105 vertically in the new height.
10107 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
10108 count a final empty row in case the tool-bar width exactly matches
10113 display_tool_bar_line (it
, height
)
10117 struct glyph_row
*row
= it
->glyph_row
;
10118 int max_x
= it
->last_visible_x
;
10119 struct glyph
*last
;
10121 prepare_desired_row (row
);
10122 row
->y
= it
->current_y
;
10124 /* Note that this isn't made use of if the face hasn't a box,
10125 so there's no need to check the face here. */
10126 it
->start_of_box_run_p
= 1;
10128 while (it
->current_x
< max_x
)
10130 int x
, n_glyphs_before
, i
, nglyphs
;
10131 struct it it_before
;
10133 /* Get the next display element. */
10134 if (!get_next_display_element (it
))
10136 /* Don't count empty row if we are counting needed tool-bar lines. */
10137 if (height
< 0 && !it
->hpos
)
10142 /* Produce glyphs. */
10143 n_glyphs_before
= row
->used
[TEXT_AREA
];
10146 PRODUCE_GLYPHS (it
);
10148 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
10150 x
= it_before
.current_x
;
10151 while (i
< nglyphs
)
10153 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
10155 if (x
+ glyph
->pixel_width
> max_x
)
10157 /* Glyph doesn't fit on line. Backtrack. */
10158 row
->used
[TEXT_AREA
] = n_glyphs_before
;
10160 /* If this is the only glyph on this line, it will never fit on the
10161 toolbar, so skip it. But ensure there is at least one glyph,
10162 so we don't accidentally disable the tool-bar. */
10163 if (n_glyphs_before
== 0
10164 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
10170 x
+= glyph
->pixel_width
;
10174 /* Stop at line ends. */
10175 if (ITERATOR_AT_END_OF_LINE_P (it
))
10178 set_iterator_to_next (it
, 1);
10183 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
10185 /* Use default face for the border below the tool bar.
10187 FIXME: When auto-resize-tool-bars is grow-only, there is
10188 no additional border below the possibly empty tool-bar lines.
10189 So to make the extra empty lines look "normal", we have to
10190 use the tool-bar face for the border too. */
10191 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
10192 it
->face_id
= DEFAULT_FACE_ID
;
10194 extend_face_to_end_of_line (it
);
10195 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
10196 last
->right_box_line_p
= 1;
10197 if (last
== row
->glyphs
[TEXT_AREA
])
10198 last
->left_box_line_p
= 1;
10200 /* Make line the desired height and center it vertically. */
10201 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
10203 /* Don't add more than one line height. */
10204 height
%= FRAME_LINE_HEIGHT (it
->f
);
10205 it
->max_ascent
+= height
/ 2;
10206 it
->max_descent
+= (height
+ 1) / 2;
10209 compute_line_metrics (it
);
10211 /* If line is empty, make it occupy the rest of the tool-bar. */
10212 if (!row
->displays_text_p
)
10214 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
10215 row
->visible_height
= row
->height
;
10216 row
->ascent
= row
->phys_ascent
= 0;
10217 row
->extra_line_spacing
= 0;
10220 row
->full_width_p
= 1;
10221 row
->continued_p
= 0;
10222 row
->truncated_on_left_p
= 0;
10223 row
->truncated_on_right_p
= 0;
10225 it
->current_x
= it
->hpos
= 0;
10226 it
->current_y
+= row
->height
;
10232 /* Max tool-bar height. */
10234 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
10235 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
10237 /* Value is the number of screen lines needed to make all tool-bar
10238 items of frame F visible. The number of actual rows needed is
10239 returned in *N_ROWS if non-NULL. */
10242 tool_bar_lines_needed (f
, n_rows
)
10246 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10248 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
10249 the desired matrix, so use (unused) mode-line row as temporary row to
10250 avoid destroying the first tool-bar row. */
10251 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
10253 /* Initialize an iterator for iteration over
10254 F->desired_tool_bar_string in the tool-bar window of frame F. */
10255 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
10256 it
.first_visible_x
= 0;
10257 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10258 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10260 while (!ITERATOR_AT_END_P (&it
))
10262 clear_glyph_row (temp_row
);
10263 it
.glyph_row
= temp_row
;
10264 display_tool_bar_line (&it
, -1);
10266 clear_glyph_row (temp_row
);
10268 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
10270 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
10272 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
10276 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
10278 doc
: /* Return the number of lines occupied by the tool bar of FRAME. */)
10287 frame
= selected_frame
;
10289 CHECK_FRAME (frame
);
10290 f
= XFRAME (frame
);
10292 if (WINDOWP (f
->tool_bar_window
)
10293 || (w
= XWINDOW (f
->tool_bar_window
),
10294 WINDOW_TOTAL_LINES (w
) > 0))
10296 update_tool_bar (f
, 1);
10297 if (f
->n_tool_bar_items
)
10299 build_desired_tool_bar_string (f
);
10300 nlines
= tool_bar_lines_needed (f
, NULL
);
10304 return make_number (nlines
);
10308 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
10309 height should be changed. */
10312 redisplay_tool_bar (f
)
10317 struct glyph_row
*row
;
10319 #if defined (USE_GTK) || defined (HAVE_NS) || USE_MAC_TOOLBAR
10320 if (FRAME_EXTERNAL_TOOL_BAR (f
))
10321 update_frame_tool_bar (f
);
10325 /* If frame hasn't a tool-bar window or if it is zero-height, don't
10326 do anything. This means you must start with tool-bar-lines
10327 non-zero to get the auto-sizing effect. Or in other words, you
10328 can turn off tool-bars by specifying tool-bar-lines zero. */
10329 if (!WINDOWP (f
->tool_bar_window
)
10330 || (w
= XWINDOW (f
->tool_bar_window
),
10331 WINDOW_TOTAL_LINES (w
) == 0))
10334 /* Set up an iterator for the tool-bar window. */
10335 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
10336 it
.first_visible_x
= 0;
10337 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
10338 row
= it
.glyph_row
;
10340 /* Build a string that represents the contents of the tool-bar. */
10341 build_desired_tool_bar_string (f
);
10342 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
10344 if (f
->n_tool_bar_rows
== 0)
10348 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
10349 nlines
!= WINDOW_TOTAL_LINES (w
)))
10351 extern Lisp_Object Qtool_bar_lines
;
10353 int old_height
= WINDOW_TOTAL_LINES (w
);
10355 XSETFRAME (frame
, f
);
10356 Fmodify_frame_parameters (frame
,
10357 Fcons (Fcons (Qtool_bar_lines
,
10358 make_number (nlines
)),
10360 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10362 clear_glyph_matrix (w
->desired_matrix
);
10363 fonts_changed_p
= 1;
10369 /* Display as many lines as needed to display all tool-bar items. */
10371 if (f
->n_tool_bar_rows
> 0)
10373 int border
, rows
, height
, extra
;
10375 if (INTEGERP (Vtool_bar_border
))
10376 border
= XINT (Vtool_bar_border
);
10377 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
10378 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
10379 else if (EQ (Vtool_bar_border
, Qborder_width
))
10380 border
= f
->border_width
;
10386 rows
= f
->n_tool_bar_rows
;
10387 height
= max (1, (it
.last_visible_y
- border
) / rows
);
10388 extra
= it
.last_visible_y
- border
- height
* rows
;
10390 while (it
.current_y
< it
.last_visible_y
)
10393 if (extra
> 0 && rows
-- > 0)
10395 h
= (extra
+ rows
- 1) / rows
;
10398 display_tool_bar_line (&it
, height
+ h
);
10403 while (it
.current_y
< it
.last_visible_y
)
10404 display_tool_bar_line (&it
, 0);
10407 /* It doesn't make much sense to try scrolling in the tool-bar
10408 window, so don't do it. */
10409 w
->desired_matrix
->no_scrolling_p
= 1;
10410 w
->must_be_updated_p
= 1;
10412 if (!NILP (Vauto_resize_tool_bars
))
10414 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
10415 int change_height_p
= 0;
10417 /* If we couldn't display everything, change the tool-bar's
10418 height if there is room for more. */
10419 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
10420 && it
.current_y
< max_tool_bar_height
)
10421 change_height_p
= 1;
10423 row
= it
.glyph_row
- 1;
10425 /* If there are blank lines at the end, except for a partially
10426 visible blank line at the end that is smaller than
10427 FRAME_LINE_HEIGHT, change the tool-bar's height. */
10428 if (!row
->displays_text_p
10429 && row
->height
>= FRAME_LINE_HEIGHT (f
))
10430 change_height_p
= 1;
10432 /* If row displays tool-bar items, but is partially visible,
10433 change the tool-bar's height. */
10434 if (row
->displays_text_p
10435 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
10436 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
10437 change_height_p
= 1;
10439 /* Resize windows as needed by changing the `tool-bar-lines'
10440 frame parameter. */
10441 if (change_height_p
)
10443 extern Lisp_Object Qtool_bar_lines
;
10445 int old_height
= WINDOW_TOTAL_LINES (w
);
10447 int nlines
= tool_bar_lines_needed (f
, &nrows
);
10449 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
10450 && !f
->minimize_tool_bar_window_p
)
10451 ? (nlines
> old_height
)
10452 : (nlines
!= old_height
));
10453 f
->minimize_tool_bar_window_p
= 0;
10455 if (change_height_p
)
10457 XSETFRAME (frame
, f
);
10458 Fmodify_frame_parameters (frame
,
10459 Fcons (Fcons (Qtool_bar_lines
,
10460 make_number (nlines
)),
10462 if (WINDOW_TOTAL_LINES (w
) != old_height
)
10464 clear_glyph_matrix (w
->desired_matrix
);
10465 f
->n_tool_bar_rows
= nrows
;
10466 fonts_changed_p
= 1;
10473 f
->minimize_tool_bar_window_p
= 0;
10478 /* Get information about the tool-bar item which is displayed in GLYPH
10479 on frame F. Return in *PROP_IDX the index where tool-bar item
10480 properties start in F->tool_bar_items. Value is zero if
10481 GLYPH doesn't display a tool-bar item. */
10484 tool_bar_item_info (f
, glyph
, prop_idx
)
10486 struct glyph
*glyph
;
10493 /* This function can be called asynchronously, which means we must
10494 exclude any possibility that Fget_text_property signals an
10496 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
10497 charpos
= max (0, charpos
);
10499 /* Get the text property `menu-item' at pos. The value of that
10500 property is the start index of this item's properties in
10501 F->tool_bar_items. */
10502 prop
= Fget_text_property (make_number (charpos
),
10503 Qmenu_item
, f
->current_tool_bar_string
);
10504 if (INTEGERP (prop
))
10506 *prop_idx
= XINT (prop
);
10516 /* Get information about the tool-bar item at position X/Y on frame F.
10517 Return in *GLYPH a pointer to the glyph of the tool-bar item in
10518 the current matrix of the tool-bar window of F, or NULL if not
10519 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
10520 item in F->tool_bar_items. Value is
10522 -1 if X/Y is not on a tool-bar item
10523 0 if X/Y is on the same item that was highlighted before.
10527 get_tool_bar_item (f
, x
, y
, glyph
, hpos
, vpos
, prop_idx
)
10530 struct glyph
**glyph
;
10531 int *hpos
, *vpos
, *prop_idx
;
10533 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10534 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10537 /* Find the glyph under X/Y. */
10538 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
10539 if (*glyph
== NULL
)
10542 /* Get the start of this tool-bar item's properties in
10543 f->tool_bar_items. */
10544 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
10547 /* Is mouse on the highlighted item? */
10548 if (EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)
10549 && *vpos
>= dpyinfo
->mouse_face_beg_row
10550 && *vpos
<= dpyinfo
->mouse_face_end_row
10551 && (*vpos
> dpyinfo
->mouse_face_beg_row
10552 || *hpos
>= dpyinfo
->mouse_face_beg_col
)
10553 && (*vpos
< dpyinfo
->mouse_face_end_row
10554 || *hpos
< dpyinfo
->mouse_face_end_col
10555 || dpyinfo
->mouse_face_past_end
))
10563 Handle mouse button event on the tool-bar of frame F, at
10564 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
10565 0 for button release. MODIFIERS is event modifiers for button
10569 handle_tool_bar_click (f
, x
, y
, down_p
, modifiers
)
10572 unsigned int modifiers
;
10574 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10575 struct window
*w
= XWINDOW (f
->tool_bar_window
);
10576 int hpos
, vpos
, prop_idx
;
10577 struct glyph
*glyph
;
10578 Lisp_Object enabled_p
;
10580 /* If not on the highlighted tool-bar item, return. */
10581 frame_to_window_pixel_xy (w
, &x
, &y
);
10582 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
10585 /* If item is disabled, do nothing. */
10586 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10587 if (NILP (enabled_p
))
10592 /* Show item in pressed state. */
10593 show_mouse_face (dpyinfo
, DRAW_IMAGE_SUNKEN
);
10594 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_SUNKEN
;
10595 last_tool_bar_item
= prop_idx
;
10599 Lisp_Object key
, frame
;
10600 struct input_event event
;
10601 EVENT_INIT (event
);
10603 /* Show item in released state. */
10604 show_mouse_face (dpyinfo
, DRAW_IMAGE_RAISED
);
10605 dpyinfo
->mouse_face_image_state
= DRAW_IMAGE_RAISED
;
10607 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
10609 XSETFRAME (frame
, f
);
10610 event
.kind
= TOOL_BAR_EVENT
;
10611 event
.frame_or_window
= frame
;
10613 kbd_buffer_store_event (&event
);
10615 event
.kind
= TOOL_BAR_EVENT
;
10616 event
.frame_or_window
= frame
;
10618 event
.modifiers
= modifiers
;
10619 kbd_buffer_store_event (&event
);
10620 last_tool_bar_item
= -1;
10625 /* Possibly highlight a tool-bar item on frame F when mouse moves to
10626 tool-bar window-relative coordinates X/Y. Called from
10627 note_mouse_highlight. */
10630 note_tool_bar_highlight (f
, x
, y
)
10634 Lisp_Object window
= f
->tool_bar_window
;
10635 struct window
*w
= XWINDOW (window
);
10636 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
10638 struct glyph
*glyph
;
10639 struct glyph_row
*row
;
10641 Lisp_Object enabled_p
;
10643 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
10644 int mouse_down_p
, rc
;
10646 /* Function note_mouse_highlight is called with negative x(y
10647 values when mouse moves outside of the frame. */
10648 if (x
<= 0 || y
<= 0)
10650 clear_mouse_face (dpyinfo
);
10654 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
10657 /* Not on tool-bar item. */
10658 clear_mouse_face (dpyinfo
);
10662 /* On same tool-bar item as before. */
10663 goto set_help_echo
;
10665 clear_mouse_face (dpyinfo
);
10667 /* Mouse is down, but on different tool-bar item? */
10668 mouse_down_p
= (dpyinfo
->grabbed
10669 && f
== last_mouse_frame
10670 && FRAME_LIVE_P (f
));
10672 && last_tool_bar_item
!= prop_idx
)
10675 dpyinfo
->mouse_face_image_state
= DRAW_NORMAL_TEXT
;
10676 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
10678 /* If tool-bar item is not enabled, don't highlight it. */
10679 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
10680 if (!NILP (enabled_p
))
10682 /* Compute the x-position of the glyph. In front and past the
10683 image is a space. We include this in the highlighted area. */
10684 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
10685 for (i
= x
= 0; i
< hpos
; ++i
)
10686 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10688 /* Record this as the current active region. */
10689 dpyinfo
->mouse_face_beg_col
= hpos
;
10690 dpyinfo
->mouse_face_beg_row
= vpos
;
10691 dpyinfo
->mouse_face_beg_x
= x
;
10692 dpyinfo
->mouse_face_beg_y
= row
->y
;
10693 dpyinfo
->mouse_face_past_end
= 0;
10695 dpyinfo
->mouse_face_end_col
= hpos
+ 1;
10696 dpyinfo
->mouse_face_end_row
= vpos
;
10697 dpyinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
10698 dpyinfo
->mouse_face_end_y
= row
->y
;
10699 dpyinfo
->mouse_face_window
= window
;
10700 dpyinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
10702 /* Display it as active. */
10703 show_mouse_face (dpyinfo
, draw
);
10704 dpyinfo
->mouse_face_image_state
= draw
;
10709 /* Set help_echo_string to a help string to display for this tool-bar item.
10710 XTread_socket does the rest. */
10711 help_echo_object
= help_echo_window
= Qnil
;
10712 help_echo_pos
= -1;
10713 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
10714 if (NILP (help_echo_string
))
10715 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
10718 #endif /* HAVE_WINDOW_SYSTEM */
10722 /************************************************************************
10723 Horizontal scrolling
10724 ************************************************************************/
10726 static int hscroll_window_tree
P_ ((Lisp_Object
));
10727 static int hscroll_windows
P_ ((Lisp_Object
));
10729 /* For all leaf windows in the window tree rooted at WINDOW, set their
10730 hscroll value so that PT is (i) visible in the window, and (ii) so
10731 that it is not within a certain margin at the window's left and
10732 right border. Value is non-zero if any window's hscroll has been
10736 hscroll_window_tree (window
)
10737 Lisp_Object window
;
10739 int hscrolled_p
= 0;
10740 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
10741 int hscroll_step_abs
= 0;
10742 double hscroll_step_rel
= 0;
10744 if (hscroll_relative_p
)
10746 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
10747 if (hscroll_step_rel
< 0)
10749 hscroll_relative_p
= 0;
10750 hscroll_step_abs
= 0;
10753 else if (INTEGERP (Vhscroll_step
))
10755 hscroll_step_abs
= XINT (Vhscroll_step
);
10756 if (hscroll_step_abs
< 0)
10757 hscroll_step_abs
= 0;
10760 hscroll_step_abs
= 0;
10762 while (WINDOWP (window
))
10764 struct window
*w
= XWINDOW (window
);
10766 if (WINDOWP (w
->hchild
))
10767 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
10768 else if (WINDOWP (w
->vchild
))
10769 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
10770 else if (w
->cursor
.vpos
>= 0)
10773 int text_area_width
;
10774 struct glyph_row
*current_cursor_row
10775 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
10776 struct glyph_row
*desired_cursor_row
10777 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
10778 struct glyph_row
*cursor_row
10779 = (desired_cursor_row
->enabled_p
10780 ? desired_cursor_row
10781 : current_cursor_row
);
10783 text_area_width
= window_box_width (w
, TEXT_AREA
);
10785 /* Scroll when cursor is inside this scroll margin. */
10786 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
10788 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
10789 && ((XFASTINT (w
->hscroll
)
10790 && w
->cursor
.x
<= h_margin
)
10791 || (cursor_row
->enabled_p
10792 && cursor_row
->truncated_on_right_p
10793 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
10797 struct buffer
*saved_current_buffer
;
10801 /* Find point in a display of infinite width. */
10802 saved_current_buffer
= current_buffer
;
10803 current_buffer
= XBUFFER (w
->buffer
);
10805 if (w
== XWINDOW (selected_window
))
10806 pt
= BUF_PT (current_buffer
);
10809 pt
= marker_position (w
->pointm
);
10810 pt
= max (BEGV
, pt
);
10814 /* Move iterator to pt starting at cursor_row->start in
10815 a line with infinite width. */
10816 init_to_row_start (&it
, w
, cursor_row
);
10817 it
.last_visible_x
= INFINITY
;
10818 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
10819 current_buffer
= saved_current_buffer
;
10821 /* Position cursor in window. */
10822 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
10823 hscroll
= max (0, (it
.current_x
10824 - (ITERATOR_AT_END_OF_LINE_P (&it
)
10825 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
10826 : (text_area_width
/ 2))))
10827 / FRAME_COLUMN_WIDTH (it
.f
);
10828 else if (w
->cursor
.x
>= text_area_width
- h_margin
)
10830 if (hscroll_relative_p
)
10831 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
10834 wanted_x
= text_area_width
10835 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10838 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10842 if (hscroll_relative_p
)
10843 wanted_x
= text_area_width
* hscroll_step_rel
10846 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
10849 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
10851 hscroll
= max (hscroll
, XFASTINT (w
->min_hscroll
));
10853 /* Don't call Fset_window_hscroll if value hasn't
10854 changed because it will prevent redisplay
10856 if (XFASTINT (w
->hscroll
) != hscroll
)
10858 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
10859 w
->hscroll
= make_number (hscroll
);
10868 /* Value is non-zero if hscroll of any leaf window has been changed. */
10869 return hscrolled_p
;
10873 /* Set hscroll so that cursor is visible and not inside horizontal
10874 scroll margins for all windows in the tree rooted at WINDOW. See
10875 also hscroll_window_tree above. Value is non-zero if any window's
10876 hscroll has been changed. If it has, desired matrices on the frame
10877 of WINDOW are cleared. */
10880 hscroll_windows (window
)
10881 Lisp_Object window
;
10883 int hscrolled_p
= hscroll_window_tree (window
);
10885 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
10886 return hscrolled_p
;
10891 /************************************************************************
10893 ************************************************************************/
10895 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
10896 to a non-zero value. This is sometimes handy to have in a debugger
10901 /* First and last unchanged row for try_window_id. */
10903 int debug_first_unchanged_at_end_vpos
;
10904 int debug_last_unchanged_at_beg_vpos
;
10906 /* Delta vpos and y. */
10908 int debug_dvpos
, debug_dy
;
10910 /* Delta in characters and bytes for try_window_id. */
10912 int debug_delta
, debug_delta_bytes
;
10914 /* Values of window_end_pos and window_end_vpos at the end of
10917 EMACS_INT debug_end_pos
, debug_end_vpos
;
10919 /* Append a string to W->desired_matrix->method. FMT is a printf
10920 format string. A1...A9 are a supplement for a variable-length
10921 argument list. If trace_redisplay_p is non-zero also printf the
10922 resulting string to stderr. */
10925 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
10928 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
10931 char *method
= w
->desired_matrix
->method
;
10932 int len
= strlen (method
);
10933 int size
= sizeof w
->desired_matrix
->method
;
10934 int remaining
= size
- len
- 1;
10936 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
10937 if (len
&& remaining
)
10940 --remaining
, ++len
;
10943 strncpy (method
+ len
, buffer
, remaining
);
10945 if (trace_redisplay_p
)
10946 fprintf (stderr
, "%p (%s): %s\n",
10948 ((BUFFERP (w
->buffer
)
10949 && STRINGP (XBUFFER (w
->buffer
)->name
))
10950 ? (char *) SDATA (XBUFFER (w
->buffer
)->name
)
10955 #endif /* GLYPH_DEBUG */
10958 /* Value is non-zero if all changes in window W, which displays
10959 current_buffer, are in the text between START and END. START is a
10960 buffer position, END is given as a distance from Z. Used in
10961 redisplay_internal for display optimization. */
10964 text_outside_line_unchanged_p (w
, start
, end
)
10968 int unchanged_p
= 1;
10970 /* If text or overlays have changed, see where. */
10971 if (XFASTINT (w
->last_modified
) < MODIFF
10972 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
10974 /* Gap in the line? */
10975 if (GPT
< start
|| Z
- GPT
< end
)
10978 /* Changes start in front of the line, or end after it? */
10980 && (BEG_UNCHANGED
< start
- 1
10981 || END_UNCHANGED
< end
))
10984 /* If selective display, can't optimize if changes start at the
10985 beginning of the line. */
10987 && INTEGERP (current_buffer
->selective_display
)
10988 && XINT (current_buffer
->selective_display
) > 0
10989 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
10992 /* If there are overlays at the start or end of the line, these
10993 may have overlay strings with newlines in them. A change at
10994 START, for instance, may actually concern the display of such
10995 overlay strings as well, and they are displayed on different
10996 lines. So, quickly rule out this case. (For the future, it
10997 might be desirable to implement something more telling than
10998 just BEG/END_UNCHANGED.) */
11001 if (BEG
+ BEG_UNCHANGED
== start
11002 && overlay_touches_p (start
))
11004 if (END_UNCHANGED
== end
11005 && overlay_touches_p (Z
- end
))
11010 return unchanged_p
;
11014 /* Do a frame update, taking possible shortcuts into account. This is
11015 the main external entry point for redisplay.
11017 If the last redisplay displayed an echo area message and that message
11018 is no longer requested, we clear the echo area or bring back the
11019 mini-buffer if that is in use. */
11024 redisplay_internal (0);
11029 overlay_arrow_string_or_property (var
)
11034 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
11037 return Voverlay_arrow_string
;
11040 /* Return 1 if there are any overlay-arrows in current_buffer. */
11042 overlay_arrow_in_current_buffer_p ()
11046 for (vlist
= Voverlay_arrow_variable_list
;
11048 vlist
= XCDR (vlist
))
11050 Lisp_Object var
= XCAR (vlist
);
11053 if (!SYMBOLP (var
))
11055 val
= find_symbol_value (var
);
11057 && current_buffer
== XMARKER (val
)->buffer
)
11064 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
11068 overlay_arrows_changed_p ()
11072 for (vlist
= Voverlay_arrow_variable_list
;
11074 vlist
= XCDR (vlist
))
11076 Lisp_Object var
= XCAR (vlist
);
11077 Lisp_Object val
, pstr
;
11079 if (!SYMBOLP (var
))
11081 val
= find_symbol_value (var
);
11082 if (!MARKERP (val
))
11084 if (! EQ (COERCE_MARKER (val
),
11085 Fget (var
, Qlast_arrow_position
))
11086 || ! (pstr
= overlay_arrow_string_or_property (var
),
11087 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
11093 /* Mark overlay arrows to be updated on next redisplay. */
11096 update_overlay_arrows (up_to_date
)
11101 for (vlist
= Voverlay_arrow_variable_list
;
11103 vlist
= XCDR (vlist
))
11105 Lisp_Object var
= XCAR (vlist
);
11107 if (!SYMBOLP (var
))
11110 if (up_to_date
> 0)
11112 Lisp_Object val
= find_symbol_value (var
);
11113 Fput (var
, Qlast_arrow_position
,
11114 COERCE_MARKER (val
));
11115 Fput (var
, Qlast_arrow_string
,
11116 overlay_arrow_string_or_property (var
));
11118 else if (up_to_date
< 0
11119 || !NILP (Fget (var
, Qlast_arrow_position
)))
11121 Fput (var
, Qlast_arrow_position
, Qt
);
11122 Fput (var
, Qlast_arrow_string
, Qt
);
11128 /* Return overlay arrow string to display at row.
11129 Return integer (bitmap number) for arrow bitmap in left fringe.
11130 Return nil if no overlay arrow. */
11133 overlay_arrow_at_row (it
, row
)
11135 struct glyph_row
*row
;
11139 for (vlist
= Voverlay_arrow_variable_list
;
11141 vlist
= XCDR (vlist
))
11143 Lisp_Object var
= XCAR (vlist
);
11146 if (!SYMBOLP (var
))
11149 val
= find_symbol_value (var
);
11152 && current_buffer
== XMARKER (val
)->buffer
11153 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
11155 if (FRAME_WINDOW_P (it
->f
)
11156 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
11158 #ifdef HAVE_WINDOW_SYSTEM
11159 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
11162 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
11163 return make_number (fringe_bitmap
);
11166 return make_number (-1); /* Use default arrow bitmap */
11168 return overlay_arrow_string_or_property (var
);
11175 /* Return 1 if point moved out of or into a composition. Otherwise
11176 return 0. PREV_BUF and PREV_PT are the last point buffer and
11177 position. BUF and PT are the current point buffer and position. */
11180 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
11181 struct buffer
*prev_buf
, *buf
;
11184 EMACS_INT start
, end
;
11186 Lisp_Object buffer
;
11188 XSETBUFFER (buffer
, buf
);
11189 /* Check a composition at the last point if point moved within the
11191 if (prev_buf
== buf
)
11194 /* Point didn't move. */
11197 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
11198 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
11199 && COMPOSITION_VALID_P (start
, end
, prop
)
11200 && start
< prev_pt
&& end
> prev_pt
)
11201 /* The last point was within the composition. Return 1 iff
11202 point moved out of the composition. */
11203 return (pt
<= start
|| pt
>= end
);
11206 /* Check a composition at the current point. */
11207 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
11208 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
11209 && COMPOSITION_VALID_P (start
, end
, prop
)
11210 && start
< pt
&& end
> pt
);
11214 /* Reconsider the setting of B->clip_changed which is displayed
11218 reconsider_clip_changes (w
, b
)
11222 if (b
->clip_changed
11223 && !NILP (w
->window_end_valid
)
11224 && w
->current_matrix
->buffer
== b
11225 && w
->current_matrix
->zv
== BUF_ZV (b
)
11226 && w
->current_matrix
->begv
== BUF_BEGV (b
))
11227 b
->clip_changed
= 0;
11229 /* If display wasn't paused, and W is not a tool bar window, see if
11230 point has been moved into or out of a composition. In that case,
11231 we set b->clip_changed to 1 to force updating the screen. If
11232 b->clip_changed has already been set to 1, we can skip this
11234 if (!b
->clip_changed
11235 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
11239 if (w
== XWINDOW (selected_window
))
11240 pt
= BUF_PT (current_buffer
);
11242 pt
= marker_position (w
->pointm
);
11244 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
11245 || pt
!= XINT (w
->last_point
))
11246 && check_point_in_composition (w
->current_matrix
->buffer
,
11247 XINT (w
->last_point
),
11248 XBUFFER (w
->buffer
), pt
))
11249 b
->clip_changed
= 1;
11254 /* Select FRAME to forward the values of frame-local variables into C
11255 variables so that the redisplay routines can access those values
11259 select_frame_for_redisplay (frame
)
11262 Lisp_Object tail
, symbol
, val
;
11263 Lisp_Object old
= selected_frame
;
11264 struct Lisp_Symbol
*sym
;
11266 xassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
11268 selected_frame
= frame
;
11272 for (tail
= XFRAME (frame
)->param_alist
; CONSP (tail
); tail
= XCDR (tail
))
11273 if (CONSP (XCAR (tail
))
11274 && (symbol
= XCAR (XCAR (tail
)),
11276 && (sym
= indirect_variable (XSYMBOL (symbol
)),
11278 (BUFFER_LOCAL_VALUEP (val
)))
11279 && XBUFFER_LOCAL_VALUE (val
)->check_frame
)
11280 /* Use find_symbol_value rather than Fsymbol_value
11281 to avoid an error if it is void. */
11282 find_symbol_value (symbol
);
11283 } while (!EQ (frame
, old
) && (frame
= old
, 1));
11287 #define STOP_POLLING \
11288 do { if (! polling_stopped_here) stop_polling (); \
11289 polling_stopped_here = 1; } while (0)
11291 #define RESUME_POLLING \
11292 do { if (polling_stopped_here) start_polling (); \
11293 polling_stopped_here = 0; } while (0)
11296 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
11297 response to any user action; therefore, we should preserve the echo
11298 area. (Actually, our caller does that job.) Perhaps in the future
11299 avoid recentering windows if it is not necessary; currently that
11300 causes some problems. */
11303 redisplay_internal (preserve_echo_area
)
11304 int preserve_echo_area
;
11306 struct window
*w
= XWINDOW (selected_window
);
11309 int must_finish
= 0;
11310 struct text_pos tlbufpos
, tlendpos
;
11311 int number_of_visible_frames
;
11314 int polling_stopped_here
= 0;
11315 Lisp_Object old_frame
= selected_frame
;
11317 /* Non-zero means redisplay has to consider all windows on all
11318 frames. Zero means, only selected_window is considered. */
11319 int consider_all_windows_p
;
11321 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
11323 /* No redisplay if running in batch mode or frame is not yet fully
11324 initialized, or redisplay is explicitly turned off by setting
11325 Vinhibit_redisplay. */
11327 || !NILP (Vinhibit_redisplay
))
11330 /* Don't examine these until after testing Vinhibit_redisplay.
11331 When Emacs is shutting down, perhaps because its connection to
11332 X has dropped, we should not look at them at all. */
11333 f
= XFRAME (w
->frame
);
11334 sf
= SELECTED_FRAME ();
11336 if (!f
->glyphs_initialized_p
)
11339 /* The flag redisplay_performed_directly_p is set by
11340 direct_output_for_insert when it already did the whole screen
11341 update necessary. */
11342 if (redisplay_performed_directly_p
)
11344 redisplay_performed_directly_p
= 0;
11345 if (!hscroll_windows (selected_window
))
11349 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
11350 if (popup_activated ())
11354 /* I don't think this happens but let's be paranoid. */
11355 if (redisplaying_p
)
11358 /* Record a function that resets redisplaying_p to its old value
11359 when we leave this function. */
11360 count
= SPECPDL_INDEX ();
11361 record_unwind_protect (unwind_redisplay
,
11362 Fcons (make_number (redisplaying_p
), selected_frame
));
11364 specbind (Qinhibit_free_realized_faces
, Qnil
);
11367 Lisp_Object tail
, frame
;
11369 FOR_EACH_FRAME (tail
, frame
)
11371 struct frame
*f
= XFRAME (frame
);
11372 f
->already_hscrolled_p
= 0;
11377 if (!EQ (old_frame
, selected_frame
)
11378 && FRAME_LIVE_P (XFRAME (old_frame
)))
11379 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
11380 selected_frame and selected_window to be temporarily out-of-sync so
11381 when we come back here via `goto retry', we need to resync because we
11382 may need to run Elisp code (via prepare_menu_bars). */
11383 select_frame_for_redisplay (old_frame
);
11386 reconsider_clip_changes (w
, current_buffer
);
11387 last_escape_glyph_frame
= NULL
;
11388 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
11390 /* If new fonts have been loaded that make a glyph matrix adjustment
11391 necessary, do it. */
11392 if (fonts_changed_p
)
11394 adjust_glyphs (NULL
);
11395 ++windows_or_buffers_changed
;
11396 fonts_changed_p
= 0;
11399 /* If face_change_count is non-zero, init_iterator will free all
11400 realized faces, which includes the faces referenced from current
11401 matrices. So, we can't reuse current matrices in this case. */
11402 if (face_change_count
)
11403 ++windows_or_buffers_changed
;
11405 if (FRAME_TERMCAP_P (sf
)
11406 && FRAME_TTY (sf
)->previous_frame
!= sf
)
11408 /* Since frames on a single ASCII terminal share the same
11409 display area, displaying a different frame means redisplay
11410 the whole thing. */
11411 windows_or_buffers_changed
++;
11412 SET_FRAME_GARBAGED (sf
);
11414 set_tty_color_mode (FRAME_TTY (sf
), sf
);
11416 FRAME_TTY (sf
)->previous_frame
= sf
;
11419 /* Set the visible flags for all frames. Do this before checking
11420 for resized or garbaged frames; they want to know if their frames
11421 are visible. See the comment in frame.h for
11422 FRAME_SAMPLE_VISIBILITY. */
11424 Lisp_Object tail
, frame
;
11426 number_of_visible_frames
= 0;
11428 FOR_EACH_FRAME (tail
, frame
)
11430 struct frame
*f
= XFRAME (frame
);
11432 FRAME_SAMPLE_VISIBILITY (f
);
11433 if (FRAME_VISIBLE_P (f
))
11434 ++number_of_visible_frames
;
11435 clear_desired_matrices (f
);
11440 /* Notice any pending interrupt request to change frame size. */
11441 do_pending_window_change (1);
11443 /* Clear frames marked as garbaged. */
11444 if (frame_garbaged
)
11445 clear_garbaged_frames ();
11447 /* Build menubar and tool-bar items. */
11448 if (NILP (Vmemory_full
))
11449 prepare_menu_bars ();
11451 if (windows_or_buffers_changed
)
11452 update_mode_lines
++;
11454 /* Detect case that we need to write or remove a star in the mode line. */
11455 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
11457 w
->update_mode_line
= Qt
;
11458 if (buffer_shared
> 1)
11459 update_mode_lines
++;
11462 /* Avoid invocation of point motion hooks by `current_column' below. */
11463 count1
= SPECPDL_INDEX ();
11464 specbind (Qinhibit_point_motion_hooks
, Qt
);
11466 /* If %c is in the mode line, update it if needed. */
11467 if (!NILP (w
->column_number_displayed
)
11468 /* This alternative quickly identifies a common case
11469 where no change is needed. */
11470 && !(PT
== XFASTINT (w
->last_point
)
11471 && XFASTINT (w
->last_modified
) >= MODIFF
11472 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
11473 && (XFASTINT (w
->column_number_displayed
)
11474 != (int) current_column ())) /* iftc */
11475 w
->update_mode_line
= Qt
;
11477 unbind_to (count1
, Qnil
);
11479 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
11481 /* The variable buffer_shared is set in redisplay_window and
11482 indicates that we redisplay a buffer in different windows. See
11484 consider_all_windows_p
= (update_mode_lines
|| buffer_shared
> 1
11485 || cursor_type_changed
);
11487 /* If specs for an arrow have changed, do thorough redisplay
11488 to ensure we remove any arrow that should no longer exist. */
11489 if (overlay_arrows_changed_p ())
11490 consider_all_windows_p
= windows_or_buffers_changed
= 1;
11492 /* Normally the message* functions will have already displayed and
11493 updated the echo area, but the frame may have been trashed, or
11494 the update may have been preempted, so display the echo area
11495 again here. Checking message_cleared_p captures the case that
11496 the echo area should be cleared. */
11497 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
11498 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
11499 || (message_cleared_p
11500 && minibuf_level
== 0
11501 /* If the mini-window is currently selected, this means the
11502 echo-area doesn't show through. */
11503 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
11505 int window_height_changed_p
= echo_area_display (0);
11508 /* If we don't display the current message, don't clear the
11509 message_cleared_p flag, because, if we did, we wouldn't clear
11510 the echo area in the next redisplay which doesn't preserve
11512 if (!display_last_displayed_message_p
)
11513 message_cleared_p
= 0;
11515 if (fonts_changed_p
)
11517 else if (window_height_changed_p
)
11519 consider_all_windows_p
= 1;
11520 ++update_mode_lines
;
11521 ++windows_or_buffers_changed
;
11523 /* If window configuration was changed, frames may have been
11524 marked garbaged. Clear them or we will experience
11525 surprises wrt scrolling. */
11526 if (frame_garbaged
)
11527 clear_garbaged_frames ();
11530 else if (EQ (selected_window
, minibuf_window
)
11531 && (current_buffer
->clip_changed
11532 || XFASTINT (w
->last_modified
) < MODIFF
11533 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
11534 && resize_mini_window (w
, 0))
11536 /* Resized active mini-window to fit the size of what it is
11537 showing if its contents might have changed. */
11539 /* FIXME: this causes all frames to be updated, which seems unnecessary
11540 since only the current frame needs to be considered. This function needs
11541 to be rewritten with two variables, consider_all_windows and
11542 consider_all_frames. */
11543 consider_all_windows_p
= 1;
11544 ++windows_or_buffers_changed
;
11545 ++update_mode_lines
;
11547 /* If window configuration was changed, frames may have been
11548 marked garbaged. Clear them or we will experience
11549 surprises wrt scrolling. */
11550 if (frame_garbaged
)
11551 clear_garbaged_frames ();
11555 /* If showing the region, and mark has changed, we must redisplay
11556 the whole window. The assignment to this_line_start_pos prevents
11557 the optimization directly below this if-statement. */
11558 if (((!NILP (Vtransient_mark_mode
)
11559 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
11560 != !NILP (w
->region_showing
))
11561 || (!NILP (w
->region_showing
)
11562 && !EQ (w
->region_showing
,
11563 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
11564 CHARPOS (this_line_start_pos
) = 0;
11566 /* Optimize the case that only the line containing the cursor in the
11567 selected window has changed. Variables starting with this_ are
11568 set in display_line and record information about the line
11569 containing the cursor. */
11570 tlbufpos
= this_line_start_pos
;
11571 tlendpos
= this_line_end_pos
;
11572 if (!consider_all_windows_p
11573 && CHARPOS (tlbufpos
) > 0
11574 && NILP (w
->update_mode_line
)
11575 && !current_buffer
->clip_changed
11576 && !current_buffer
->prevent_redisplay_optimizations_p
11577 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
11578 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
11579 /* Make sure recorded data applies to current buffer, etc. */
11580 && this_line_buffer
== current_buffer
11581 && current_buffer
== XBUFFER (w
->buffer
)
11582 && NILP (w
->force_start
)
11583 && NILP (w
->optional_new_start
)
11584 /* Point must be on the line that we have info recorded about. */
11585 && PT
>= CHARPOS (tlbufpos
)
11586 && PT
<= Z
- CHARPOS (tlendpos
)
11587 /* All text outside that line, including its final newline,
11588 must be unchanged */
11589 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
11590 CHARPOS (tlendpos
)))
11592 if (CHARPOS (tlbufpos
) > BEGV
11593 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
11594 && (CHARPOS (tlbufpos
) == ZV
11595 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
11596 /* Former continuation line has disappeared by becoming empty */
11598 else if (XFASTINT (w
->last_modified
) < MODIFF
11599 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
11600 || MINI_WINDOW_P (w
))
11602 /* We have to handle the case of continuation around a
11603 wide-column character (See the comment in indent.c around
11606 For instance, in the following case:
11608 -------- Insert --------
11609 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
11610 J_I_ ==> J_I_ `^^' are cursors.
11614 As we have to redraw the line above, we should goto cancel. */
11617 int line_height_before
= this_line_pixel_height
;
11619 /* Note that start_display will handle the case that the
11620 line starting at tlbufpos is a continuation lines. */
11621 start_display (&it
, w
, tlbufpos
);
11623 /* Implementation note: It this still necessary? */
11624 if (it
.current_x
!= this_line_start_x
)
11627 TRACE ((stderr
, "trying display optimization 1\n"));
11628 w
->cursor
.vpos
= -1;
11629 overlay_arrow_seen
= 0;
11630 it
.vpos
= this_line_vpos
;
11631 it
.current_y
= this_line_y
;
11632 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
11633 display_line (&it
);
11635 /* If line contains point, is not continued,
11636 and ends at same distance from eob as before, we win */
11637 if (w
->cursor
.vpos
>= 0
11638 /* Line is not continued, otherwise this_line_start_pos
11639 would have been set to 0 in display_line. */
11640 && CHARPOS (this_line_start_pos
)
11641 /* Line ends as before. */
11642 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
11643 /* Line has same height as before. Otherwise other lines
11644 would have to be shifted up or down. */
11645 && this_line_pixel_height
== line_height_before
)
11647 /* If this is not the window's last line, we must adjust
11648 the charstarts of the lines below. */
11649 if (it
.current_y
< it
.last_visible_y
)
11651 struct glyph_row
*row
11652 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
11653 int delta
, delta_bytes
;
11655 if (Z
- CHARPOS (tlendpos
) == ZV
)
11657 /* This line ends at end of (accessible part of)
11658 buffer. There is no newline to count. */
11660 - CHARPOS (tlendpos
)
11661 - MATRIX_ROW_START_CHARPOS (row
));
11662 delta_bytes
= (Z_BYTE
11663 - BYTEPOS (tlendpos
)
11664 - MATRIX_ROW_START_BYTEPOS (row
));
11668 /* This line ends in a newline. Must take
11669 account of the newline and the rest of the
11670 text that follows. */
11672 - CHARPOS (tlendpos
)
11673 - MATRIX_ROW_START_CHARPOS (row
));
11674 delta_bytes
= (Z_BYTE
11675 - BYTEPOS (tlendpos
)
11676 - MATRIX_ROW_START_BYTEPOS (row
));
11679 increment_matrix_positions (w
->current_matrix
,
11680 this_line_vpos
+ 1,
11681 w
->current_matrix
->nrows
,
11682 delta
, delta_bytes
);
11685 /* If this row displays text now but previously didn't,
11686 or vice versa, w->window_end_vpos may have to be
11688 if ((it
.glyph_row
- 1)->displays_text_p
)
11690 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
11691 XSETINT (w
->window_end_vpos
, this_line_vpos
);
11693 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
11694 && this_line_vpos
> 0)
11695 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
11696 w
->window_end_valid
= Qnil
;
11698 /* Update hint: No need to try to scroll in update_window. */
11699 w
->desired_matrix
->no_scrolling_p
= 1;
11702 *w
->desired_matrix
->method
= 0;
11703 debug_method_add (w
, "optimization 1");
11705 #ifdef HAVE_WINDOW_SYSTEM
11706 update_window_fringes (w
, 0);
11713 else if (/* Cursor position hasn't changed. */
11714 PT
== XFASTINT (w
->last_point
)
11715 /* Make sure the cursor was last displayed
11716 in this window. Otherwise we have to reposition it. */
11717 && 0 <= w
->cursor
.vpos
11718 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
11722 do_pending_window_change (1);
11724 /* We used to always goto end_of_redisplay here, but this
11725 isn't enough if we have a blinking cursor. */
11726 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
11727 goto end_of_redisplay
;
11731 /* If highlighting the region, or if the cursor is in the echo area,
11732 then we can't just move the cursor. */
11733 else if (! (!NILP (Vtransient_mark_mode
)
11734 && !NILP (current_buffer
->mark_active
))
11735 && (EQ (selected_window
, current_buffer
->last_selected_window
)
11736 || highlight_nonselected_windows
)
11737 && NILP (w
->region_showing
)
11738 && NILP (Vshow_trailing_whitespace
)
11739 && !cursor_in_echo_area
)
11742 struct glyph_row
*row
;
11744 /* Skip from tlbufpos to PT and see where it is. Note that
11745 PT may be in invisible text. If so, we will end at the
11746 next visible position. */
11747 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
11748 NULL
, DEFAULT_FACE_ID
);
11749 it
.current_x
= this_line_start_x
;
11750 it
.current_y
= this_line_y
;
11751 it
.vpos
= this_line_vpos
;
11753 /* The call to move_it_to stops in front of PT, but
11754 moves over before-strings. */
11755 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
11757 if (it
.vpos
== this_line_vpos
11758 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
11761 xassert (this_line_vpos
== it
.vpos
);
11762 xassert (this_line_y
== it
.current_y
);
11763 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
11765 *w
->desired_matrix
->method
= 0;
11766 debug_method_add (w
, "optimization 3");
11775 /* Text changed drastically or point moved off of line. */
11776 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
11779 CHARPOS (this_line_start_pos
) = 0;
11780 consider_all_windows_p
|= buffer_shared
> 1;
11781 ++clear_face_cache_count
;
11782 #ifdef HAVE_WINDOW_SYSTEM
11783 ++clear_image_cache_count
;
11786 /* Build desired matrices, and update the display. If
11787 consider_all_windows_p is non-zero, do it for all windows on all
11788 frames. Otherwise do it for selected_window, only. */
11790 if (consider_all_windows_p
)
11792 Lisp_Object tail
, frame
;
11794 FOR_EACH_FRAME (tail
, frame
)
11795 XFRAME (frame
)->updated_p
= 0;
11797 /* Recompute # windows showing selected buffer. This will be
11798 incremented each time such a window is displayed. */
11801 FOR_EACH_FRAME (tail
, frame
)
11803 struct frame
*f
= XFRAME (frame
);
11805 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
11807 if (! EQ (frame
, selected_frame
))
11808 /* Select the frame, for the sake of frame-local
11810 select_frame_for_redisplay (frame
);
11812 /* Mark all the scroll bars to be removed; we'll redeem
11813 the ones we want when we redisplay their windows. */
11814 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
11815 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
11817 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11818 redisplay_windows (FRAME_ROOT_WINDOW (f
));
11820 /* Any scroll bars which redisplay_windows should have
11821 nuked should now go away. */
11822 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
11823 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
11825 /* If fonts changed, display again. */
11826 /* ??? rms: I suspect it is a mistake to jump all the way
11827 back to retry here. It should just retry this frame. */
11828 if (fonts_changed_p
)
11831 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
11833 /* See if we have to hscroll. */
11834 if (!f
->already_hscrolled_p
)
11836 f
->already_hscrolled_p
= 1;
11837 if (hscroll_windows (f
->root_window
))
11841 /* Prevent various kinds of signals during display
11842 update. stdio is not robust about handling
11843 signals, which can cause an apparent I/O
11845 if (interrupt_input
)
11846 unrequest_sigio ();
11849 /* Update the display. */
11850 set_window_update_flags (XWINDOW (f
->root_window
), 1);
11851 pause
|= update_frame (f
, 0, 0);
11852 #if 0 /* Exiting the loop can leave the wrong value for buffer_shared. */
11862 if (!EQ (old_frame
, selected_frame
)
11863 && FRAME_LIVE_P (XFRAME (old_frame
)))
11864 /* We played a bit fast-and-loose above and allowed selected_frame
11865 and selected_window to be temporarily out-of-sync but let's make
11866 sure this stays contained. */
11867 select_frame_for_redisplay (old_frame
);
11868 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
11872 /* Do the mark_window_display_accurate after all windows have
11873 been redisplayed because this call resets flags in buffers
11874 which are needed for proper redisplay. */
11875 FOR_EACH_FRAME (tail
, frame
)
11877 struct frame
*f
= XFRAME (frame
);
11880 mark_window_display_accurate (f
->root_window
, 1);
11881 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
11882 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
11887 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11889 Lisp_Object mini_window
;
11890 struct frame
*mini_frame
;
11892 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
11893 /* Use list_of_error, not Qerror, so that
11894 we catch only errors and don't run the debugger. */
11895 internal_condition_case_1 (redisplay_window_1
, selected_window
,
11897 redisplay_window_error
);
11899 /* Compare desired and current matrices, perform output. */
11902 /* If fonts changed, display again. */
11903 if (fonts_changed_p
)
11906 /* Prevent various kinds of signals during display update.
11907 stdio is not robust about handling signals,
11908 which can cause an apparent I/O error. */
11909 if (interrupt_input
)
11910 unrequest_sigio ();
11913 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
11915 if (hscroll_windows (selected_window
))
11918 XWINDOW (selected_window
)->must_be_updated_p
= 1;
11919 pause
= update_frame (sf
, 0, 0);
11922 /* We may have called echo_area_display at the top of this
11923 function. If the echo area is on another frame, that may
11924 have put text on a frame other than the selected one, so the
11925 above call to update_frame would not have caught it. Catch
11927 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11928 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
11930 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
11932 XWINDOW (mini_window
)->must_be_updated_p
= 1;
11933 pause
|= update_frame (mini_frame
, 0, 0);
11934 if (!pause
&& hscroll_windows (mini_window
))
11939 /* If display was paused because of pending input, make sure we do a
11940 thorough update the next time. */
11943 /* Prevent the optimization at the beginning of
11944 redisplay_internal that tries a single-line update of the
11945 line containing the cursor in the selected window. */
11946 CHARPOS (this_line_start_pos
) = 0;
11948 /* Let the overlay arrow be updated the next time. */
11949 update_overlay_arrows (0);
11951 /* If we pause after scrolling, some rows in the current
11952 matrices of some windows are not valid. */
11953 if (!WINDOW_FULL_WIDTH_P (w
)
11954 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
11955 update_mode_lines
= 1;
11959 if (!consider_all_windows_p
)
11961 /* This has already been done above if
11962 consider_all_windows_p is set. */
11963 mark_window_display_accurate_1 (w
, 1);
11965 /* Say overlay arrows are up to date. */
11966 update_overlay_arrows (1);
11968 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
11969 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
11972 update_mode_lines
= 0;
11973 windows_or_buffers_changed
= 0;
11974 cursor_type_changed
= 0;
11977 /* Start SIGIO interrupts coming again. Having them off during the
11978 code above makes it less likely one will discard output, but not
11979 impossible, since there might be stuff in the system buffer here.
11980 But it is much hairier to try to do anything about that. */
11981 if (interrupt_input
)
11985 /* If a frame has become visible which was not before, redisplay
11986 again, so that we display it. Expose events for such a frame
11987 (which it gets when becoming visible) don't call the parts of
11988 redisplay constructing glyphs, so simply exposing a frame won't
11989 display anything in this case. So, we have to display these
11990 frames here explicitly. */
11993 Lisp_Object tail
, frame
;
11996 FOR_EACH_FRAME (tail
, frame
)
11998 int this_is_visible
= 0;
12000 if (XFRAME (frame
)->visible
)
12001 this_is_visible
= 1;
12002 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
12003 if (XFRAME (frame
)->visible
)
12004 this_is_visible
= 1;
12006 if (this_is_visible
)
12010 if (new_count
!= number_of_visible_frames
)
12011 windows_or_buffers_changed
++;
12014 /* Change frame size now if a change is pending. */
12015 do_pending_window_change (1);
12017 /* If we just did a pending size change, or have additional
12018 visible frames, redisplay again. */
12019 if (windows_or_buffers_changed
&& !pause
)
12022 /* Clear the face cache eventually. */
12023 if (consider_all_windows_p
)
12025 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
12027 clear_face_cache (0);
12028 clear_face_cache_count
= 0;
12030 #ifdef HAVE_WINDOW_SYSTEM
12031 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
12033 clear_image_caches (Qnil
);
12034 clear_image_cache_count
= 0;
12036 #endif /* HAVE_WINDOW_SYSTEM */
12040 unbind_to (count
, Qnil
);
12045 /* Redisplay, but leave alone any recent echo area message unless
12046 another message has been requested in its place.
12048 This is useful in situations where you need to redisplay but no
12049 user action has occurred, making it inappropriate for the message
12050 area to be cleared. See tracking_off and
12051 wait_reading_process_output for examples of these situations.
12053 FROM_WHERE is an integer saying from where this function was
12054 called. This is useful for debugging. */
12057 redisplay_preserve_echo_area (from_where
)
12060 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
12062 if (!NILP (echo_area_buffer
[1]))
12064 /* We have a previously displayed message, but no current
12065 message. Redisplay the previous message. */
12066 display_last_displayed_message_p
= 1;
12067 redisplay_internal (1);
12068 display_last_displayed_message_p
= 0;
12071 redisplay_internal (1);
12073 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
12074 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
12075 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
12079 /* Function registered with record_unwind_protect in
12080 redisplay_internal. Reset redisplaying_p to the value it had
12081 before redisplay_internal was called, and clear
12082 prevent_freeing_realized_faces_p. It also selects the previously
12083 selected frame, unless it has been deleted (by an X connection
12084 failure during redisplay, for example). */
12087 unwind_redisplay (val
)
12090 Lisp_Object old_redisplaying_p
, old_frame
;
12092 old_redisplaying_p
= XCAR (val
);
12093 redisplaying_p
= XFASTINT (old_redisplaying_p
);
12094 old_frame
= XCDR (val
);
12095 if (! EQ (old_frame
, selected_frame
)
12096 && FRAME_LIVE_P (XFRAME (old_frame
)))
12097 select_frame_for_redisplay (old_frame
);
12102 /* Mark the display of window W as accurate or inaccurate. If
12103 ACCURATE_P is non-zero mark display of W as accurate. If
12104 ACCURATE_P is zero, arrange for W to be redisplayed the next time
12105 redisplay_internal is called. */
12108 mark_window_display_accurate_1 (w
, accurate_p
)
12112 if (BUFFERP (w
->buffer
))
12114 struct buffer
*b
= XBUFFER (w
->buffer
);
12117 = make_number (accurate_p
? BUF_MODIFF (b
) : 0);
12118 w
->last_overlay_modified
12119 = make_number (accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
12121 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
) ? Qt
: Qnil
;
12125 b
->clip_changed
= 0;
12126 b
->prevent_redisplay_optimizations_p
= 0;
12128 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
12129 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
12130 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
12131 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
12133 w
->current_matrix
->buffer
= b
;
12134 w
->current_matrix
->begv
= BUF_BEGV (b
);
12135 w
->current_matrix
->zv
= BUF_ZV (b
);
12137 w
->last_cursor
= w
->cursor
;
12138 w
->last_cursor_off_p
= w
->cursor_off_p
;
12140 if (w
== XWINDOW (selected_window
))
12141 w
->last_point
= make_number (BUF_PT (b
));
12143 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
12149 w
->window_end_valid
= w
->buffer
;
12150 #if 0 /* This is incorrect with variable-height lines. */
12151 xassert (XINT (w
->window_end_vpos
)
12152 < (WINDOW_TOTAL_LINES (w
)
12153 - (WINDOW_WANTS_MODELINE_P (w
) ? 1 : 0)));
12155 w
->update_mode_line
= Qnil
;
12160 /* Mark the display of windows in the window tree rooted at WINDOW as
12161 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
12162 windows as accurate. If ACCURATE_P is zero, arrange for windows to
12163 be redisplayed the next time redisplay_internal is called. */
12166 mark_window_display_accurate (window
, accurate_p
)
12167 Lisp_Object window
;
12172 for (; !NILP (window
); window
= w
->next
)
12174 w
= XWINDOW (window
);
12175 mark_window_display_accurate_1 (w
, accurate_p
);
12177 if (!NILP (w
->vchild
))
12178 mark_window_display_accurate (w
->vchild
, accurate_p
);
12179 if (!NILP (w
->hchild
))
12180 mark_window_display_accurate (w
->hchild
, accurate_p
);
12185 update_overlay_arrows (1);
12189 /* Force a thorough redisplay the next time by setting
12190 last_arrow_position and last_arrow_string to t, which is
12191 unequal to any useful value of Voverlay_arrow_... */
12192 update_overlay_arrows (-1);
12197 /* Return value in display table DP (Lisp_Char_Table *) for character
12198 C. Since a display table doesn't have any parent, we don't have to
12199 follow parent. Do not call this function directly but use the
12200 macro DISP_CHAR_VECTOR. */
12203 disp_char_vector (dp
, c
)
12204 struct Lisp_Char_Table
*dp
;
12209 if (ASCII_CHAR_P (c
))
12212 if (SUB_CHAR_TABLE_P (val
))
12213 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
12219 XSETCHAR_TABLE (table
, dp
);
12220 val
= char_table_ref (table
, c
);
12229 /***********************************************************************
12231 ***********************************************************************/
12233 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
12236 redisplay_windows (window
)
12237 Lisp_Object window
;
12239 while (!NILP (window
))
12241 struct window
*w
= XWINDOW (window
);
12243 if (!NILP (w
->hchild
))
12244 redisplay_windows (w
->hchild
);
12245 else if (!NILP (w
->vchild
))
12246 redisplay_windows (w
->vchild
);
12249 displayed_buffer
= XBUFFER (w
->buffer
);
12250 /* Use list_of_error, not Qerror, so that
12251 we catch only errors and don't run the debugger. */
12252 internal_condition_case_1 (redisplay_window_0
, window
,
12254 redisplay_window_error
);
12262 redisplay_window_error ()
12264 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
12269 redisplay_window_0 (window
)
12270 Lisp_Object window
;
12272 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12273 redisplay_window (window
, 0);
12278 redisplay_window_1 (window
)
12279 Lisp_Object window
;
12281 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
12282 redisplay_window (window
, 1);
12287 /* Increment GLYPH until it reaches END or CONDITION fails while
12288 adding (GLYPH)->pixel_width to X. */
12290 #define SKIP_GLYPHS(glyph, end, x, condition) \
12293 (x) += (glyph)->pixel_width; \
12296 while ((glyph) < (end) && (condition))
12299 /* Set cursor position of W. PT is assumed to be displayed in ROW.
12300 DELTA is the number of bytes by which positions recorded in ROW
12301 differ from current buffer positions.
12303 Return 0 if cursor is not on this row. 1 otherwise. */
12306 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
12308 struct glyph_row
*row
;
12309 struct glyph_matrix
*matrix
;
12310 int delta
, delta_bytes
, dy
, dvpos
;
12312 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
12313 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
12314 struct glyph
*cursor
= NULL
;
12315 /* The first glyph that starts a sequence of glyphs from string. */
12316 struct glyph
*string_start
;
12317 /* The X coordinate of string_start. */
12318 int string_start_x
;
12319 /* The last known character position. */
12320 int last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
12321 /* The last known character position before string_start. */
12322 int string_before_pos
;
12325 int cursor_from_overlay_pos
= 0;
12326 int pt_old
= PT
- delta
;
12328 /* Skip over glyphs not having an object at the start of the row.
12329 These are special glyphs like truncation marks on terminal
12331 if (row
->displays_text_p
)
12333 && INTEGERP (glyph
->object
)
12334 && glyph
->charpos
< 0)
12336 x
+= glyph
->pixel_width
;
12340 string_start
= NULL
;
12342 && !INTEGERP (glyph
->object
)
12343 && (!BUFFERP (glyph
->object
)
12344 || (last_pos
= glyph
->charpos
) < pt_old
12345 || glyph
->avoid_cursor_p
))
12347 if (! STRINGP (glyph
->object
))
12349 string_start
= NULL
;
12350 x
+= glyph
->pixel_width
;
12352 if (cursor_from_overlay_pos
12353 && last_pos
>= cursor_from_overlay_pos
)
12355 cursor_from_overlay_pos
= 0;
12361 if (string_start
== NULL
)
12363 string_before_pos
= last_pos
;
12364 string_start
= glyph
;
12365 string_start_x
= x
;
12367 /* Skip all glyphs from string. */
12372 if ((cursor
== NULL
|| glyph
> cursor
)
12373 && (cprop
= Fget_char_property (make_number ((glyph
)->charpos
),
12374 Qcursor
, (glyph
)->object
),
12376 && (pos
= string_buffer_position (w
, glyph
->object
,
12377 string_before_pos
),
12378 (pos
== 0 /* From overlay */
12379 || pos
== pt_old
)))
12381 /* Estimate overlay buffer position from the buffer
12382 positions of the glyphs before and after the overlay.
12383 Add 1 to last_pos so that if point corresponds to the
12384 glyph right after the overlay, we still use a 'cursor'
12385 property found in that overlay. */
12386 cursor_from_overlay_pos
= (pos
? 0 : last_pos
12387 + (INTEGERP (cprop
) ? XINT (cprop
) : 0));
12391 x
+= glyph
->pixel_width
;
12394 while (glyph
< end
&& EQ (glyph
->object
, string_start
->object
));
12398 if (cursor
!= NULL
)
12403 else if (row
->ends_in_ellipsis_p
&& glyph
== end
)
12405 /* Scan back over the ellipsis glyphs, decrementing positions. */
12406 while (glyph
> row
->glyphs
[TEXT_AREA
]
12407 && (glyph
- 1)->charpos
== last_pos
)
12408 glyph
--, x
-= glyph
->pixel_width
;
12409 /* That loop always goes one position too far,
12410 including the glyph before the ellipsis.
12411 So scan forward over that one. */
12412 x
+= glyph
->pixel_width
;
12415 else if (string_start
12416 && (glyph
== end
|| !BUFFERP (glyph
->object
) || last_pos
> pt_old
))
12418 /* We may have skipped over point because the previous glyphs
12419 are from string. As there's no easy way to know the
12420 character position of the current glyph, find the correct
12421 glyph on point by scanning from string_start again. */
12423 Lisp_Object string
;
12424 struct glyph
*stop
= glyph
;
12427 limit
= make_number (pt_old
+ 1);
12428 glyph
= string_start
;
12429 x
= string_start_x
;
12430 string
= glyph
->object
;
12431 pos
= string_buffer_position (w
, string
, string_before_pos
);
12432 /* If STRING is from overlay, LAST_POS == 0. We skip such glyphs
12433 because we always put cursor after overlay strings. */
12434 while (pos
== 0 && glyph
< stop
)
12436 string
= glyph
->object
;
12437 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12439 pos
= string_buffer_position (w
, glyph
->object
, string_before_pos
);
12442 while (glyph
< stop
)
12444 pos
= XINT (Fnext_single_char_property_change
12445 (make_number (pos
), Qdisplay
, Qnil
, limit
));
12448 /* Skip glyphs from the same string. */
12449 string
= glyph
->object
;
12450 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12451 /* Skip glyphs from an overlay. */
12452 while (glyph
< stop
12453 && ! string_buffer_position (w
, glyph
->object
, pos
))
12455 string
= glyph
->object
;
12456 SKIP_GLYPHS (glyph
, stop
, x
, EQ (glyph
->object
, string
));
12460 /* If we reached the end of the line, and end was from a string,
12461 cursor is not on this line. */
12462 if (glyph
== end
&& row
->continued_p
)
12466 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
12468 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
12469 w
->cursor
.y
= row
->y
+ dy
;
12471 if (w
== XWINDOW (selected_window
))
12473 if (!row
->continued_p
12474 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
12477 this_line_buffer
= XBUFFER (w
->buffer
);
12479 CHARPOS (this_line_start_pos
)
12480 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
12481 BYTEPOS (this_line_start_pos
)
12482 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
12484 CHARPOS (this_line_end_pos
)
12485 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
12486 BYTEPOS (this_line_end_pos
)
12487 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
12489 this_line_y
= w
->cursor
.y
;
12490 this_line_pixel_height
= row
->height
;
12491 this_line_vpos
= w
->cursor
.vpos
;
12492 this_line_start_x
= row
->x
;
12495 CHARPOS (this_line_start_pos
) = 0;
12502 /* Run window scroll functions, if any, for WINDOW with new window
12503 start STARTP. Sets the window start of WINDOW to that position.
12505 We assume that the window's buffer is really current. */
12507 static INLINE
struct text_pos
12508 run_window_scroll_functions (window
, startp
)
12509 Lisp_Object window
;
12510 struct text_pos startp
;
12512 struct window
*w
= XWINDOW (window
);
12513 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
12515 if (current_buffer
!= XBUFFER (w
->buffer
))
12518 if (!NILP (Vwindow_scroll_functions
))
12520 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
12521 make_number (CHARPOS (startp
)));
12522 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12523 /* In case the hook functions switch buffers. */
12524 if (current_buffer
!= XBUFFER (w
->buffer
))
12525 set_buffer_internal_1 (XBUFFER (w
->buffer
));
12532 /* Make sure the line containing the cursor is fully visible.
12533 A value of 1 means there is nothing to be done.
12534 (Either the line is fully visible, or it cannot be made so,
12535 or we cannot tell.)
12537 If FORCE_P is non-zero, return 0 even if partial visible cursor row
12538 is higher than window.
12540 A value of 0 means the caller should do scrolling
12541 as if point had gone off the screen. */
12544 cursor_row_fully_visible_p (w
, force_p
, current_matrix_p
)
12547 int current_matrix_p
;
12549 struct glyph_matrix
*matrix
;
12550 struct glyph_row
*row
;
12553 if (!make_cursor_line_fully_visible_p
)
12556 /* It's not always possible to find the cursor, e.g, when a window
12557 is full of overlay strings. Don't do anything in that case. */
12558 if (w
->cursor
.vpos
< 0)
12561 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
12562 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
12564 /* If the cursor row is not partially visible, there's nothing to do. */
12565 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
12568 /* If the row the cursor is in is taller than the window's height,
12569 it's not clear what to do, so do nothing. */
12570 window_height
= window_box_height (w
);
12571 if (row
->height
>= window_height
)
12573 if (!force_p
|| MINI_WINDOW_P (w
)
12574 || w
->vscroll
|| w
->cursor
.vpos
== 0)
12580 /* This code used to try to scroll the window just enough to make
12581 the line visible. It returned 0 to say that the caller should
12582 allocate larger glyph matrices. */
12584 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
12586 int dy
= row
->height
- row
->visible_height
;
12589 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12591 else /* MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row)) */
12593 int dy
= - (row
->height
- row
->visible_height
);
12596 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
12599 /* When we change the cursor y-position of the selected window,
12600 change this_line_y as well so that the display optimization for
12601 the cursor line of the selected window in redisplay_internal uses
12602 the correct y-position. */
12603 if (w
== XWINDOW (selected_window
))
12604 this_line_y
= w
->cursor
.y
;
12606 /* If vscrolling requires a larger glyph matrix, arrange for a fresh
12607 redisplay with larger matrices. */
12608 if (matrix
->nrows
< required_matrix_height (w
))
12610 fonts_changed_p
= 1;
12619 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
12620 non-zero means only WINDOW is redisplayed in redisplay_internal.
12621 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
12622 in redisplay_window to bring a partially visible line into view in
12623 the case that only the cursor has moved.
12625 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
12626 last screen line's vertical height extends past the end of the screen.
12630 1 if scrolling succeeded
12632 0 if scrolling didn't find point.
12634 -1 if new fonts have been loaded so that we must interrupt
12635 redisplay, adjust glyph matrices, and try again. */
12641 SCROLLING_NEED_LARGER_MATRICES
12645 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
12646 scroll_step
, temp_scroll_step
, last_line_misfit
)
12647 Lisp_Object window
;
12648 int just_this_one_p
;
12649 EMACS_INT scroll_conservatively
, scroll_step
;
12650 int temp_scroll_step
;
12651 int last_line_misfit
;
12653 struct window
*w
= XWINDOW (window
);
12654 struct frame
*f
= XFRAME (w
->frame
);
12655 struct text_pos scroll_margin_pos
;
12656 struct text_pos pos
;
12657 struct text_pos startp
;
12659 Lisp_Object window_end
;
12660 int this_scroll_margin
;
12664 int amount_to_scroll
= 0;
12665 Lisp_Object aggressive
;
12667 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
12670 debug_method_add (w
, "try_scrolling");
12673 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
12675 /* Compute scroll margin height in pixels. We scroll when point is
12676 within this distance from the top or bottom of the window. */
12677 if (scroll_margin
> 0)
12679 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
12680 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
12683 this_scroll_margin
= 0;
12685 /* Force scroll_conservatively to have a reasonable value so it doesn't
12686 cause an overflow while computing how much to scroll. */
12687 if (scroll_conservatively
)
12688 scroll_conservatively
= min (scroll_conservatively
,
12689 MOST_POSITIVE_FIXNUM
/ FRAME_LINE_HEIGHT (f
));
12691 /* Compute how much we should try to scroll maximally to bring point
12693 if (scroll_step
|| scroll_conservatively
|| temp_scroll_step
)
12694 scroll_max
= max (scroll_step
,
12695 max (scroll_conservatively
, temp_scroll_step
));
12696 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
12697 || NUMBERP (current_buffer
->scroll_up_aggressively
))
12698 /* We're trying to scroll because of aggressive scrolling
12699 but no scroll_step is set. Choose an arbitrary one. Maybe
12700 there should be a variable for this. */
12704 scroll_max
*= FRAME_LINE_HEIGHT (f
);
12706 /* Decide whether we have to scroll down. Start at the window end
12707 and move this_scroll_margin up to find the position of the scroll
12709 window_end
= Fwindow_end (window
, Qt
);
12713 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
12714 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
12716 if (this_scroll_margin
|| extra_scroll_margin_lines
)
12718 start_display (&it
, w
, scroll_margin_pos
);
12719 if (this_scroll_margin
)
12720 move_it_vertically_backward (&it
, this_scroll_margin
);
12721 if (extra_scroll_margin_lines
)
12722 move_it_by_lines (&it
, - extra_scroll_margin_lines
, 0);
12723 scroll_margin_pos
= it
.current
.pos
;
12726 if (PT
>= CHARPOS (scroll_margin_pos
))
12730 /* Point is in the scroll margin at the bottom of the window, or
12731 below. Compute a new window start that makes point visible. */
12733 /* Compute the distance from the scroll margin to PT.
12734 Give up if the distance is greater than scroll_max. */
12735 start_display (&it
, w
, scroll_margin_pos
);
12737 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
12738 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12740 /* To make point visible, we have to move the window start
12741 down so that the line the cursor is in is visible, which
12742 means we have to add in the height of the cursor line. */
12743 dy
= line_bottom_y (&it
) - y0
;
12745 if (dy
> scroll_max
)
12746 return SCROLLING_FAILED
;
12748 /* Move the window start down. If scrolling conservatively,
12749 move it just enough down to make point visible. If
12750 scroll_step is set, move it down by scroll_step. */
12751 start_display (&it
, w
, startp
);
12753 if (scroll_conservatively
)
12754 /* Set AMOUNT_TO_SCROLL to at least one line,
12755 and at most scroll_conservatively lines. */
12757 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
12758 FRAME_LINE_HEIGHT (f
) * scroll_conservatively
);
12759 else if (scroll_step
|| temp_scroll_step
)
12760 amount_to_scroll
= scroll_max
;
12763 aggressive
= current_buffer
->scroll_up_aggressively
;
12764 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12765 if (NUMBERP (aggressive
))
12767 double float_amount
= XFLOATINT (aggressive
) * height
;
12768 amount_to_scroll
= float_amount
;
12769 if (amount_to_scroll
== 0 && float_amount
> 0)
12770 amount_to_scroll
= 1;
12774 if (amount_to_scroll
<= 0)
12775 return SCROLLING_FAILED
;
12777 /* If moving by amount_to_scroll leaves STARTP unchanged,
12778 move it down one screen line. */
12780 move_it_vertically (&it
, amount_to_scroll
);
12781 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
12782 move_it_by_lines (&it
, 1, 1);
12783 startp
= it
.current
.pos
;
12787 /* See if point is inside the scroll margin at the top of the
12789 scroll_margin_pos
= startp
;
12790 if (this_scroll_margin
)
12792 start_display (&it
, w
, startp
);
12793 move_it_vertically (&it
, this_scroll_margin
);
12794 scroll_margin_pos
= it
.current
.pos
;
12797 if (PT
< CHARPOS (scroll_margin_pos
))
12799 /* Point is in the scroll margin at the top of the window or
12800 above what is displayed in the window. */
12803 /* Compute the vertical distance from PT to the scroll
12804 margin position. Give up if distance is greater than
12806 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
12807 start_display (&it
, w
, pos
);
12809 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
12810 it
.last_visible_y
, -1,
12811 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
12812 dy
= it
.current_y
- y0
;
12813 if (dy
> scroll_max
)
12814 return SCROLLING_FAILED
;
12816 /* Compute new window start. */
12817 start_display (&it
, w
, startp
);
12819 if (scroll_conservatively
)
12821 = max (dy
, FRAME_LINE_HEIGHT (f
) * max (scroll_step
, temp_scroll_step
));
12822 else if (scroll_step
|| temp_scroll_step
)
12823 amount_to_scroll
= scroll_max
;
12826 aggressive
= current_buffer
->scroll_down_aggressively
;
12827 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
12828 if (NUMBERP (aggressive
))
12830 double float_amount
= XFLOATINT (aggressive
) * height
;
12831 amount_to_scroll
= float_amount
;
12832 if (amount_to_scroll
== 0 && float_amount
> 0)
12833 amount_to_scroll
= 1;
12837 if (amount_to_scroll
<= 0)
12838 return SCROLLING_FAILED
;
12840 move_it_vertically_backward (&it
, amount_to_scroll
);
12841 startp
= it
.current
.pos
;
12845 /* Run window scroll functions. */
12846 startp
= run_window_scroll_functions (window
, startp
);
12848 /* Display the window. Give up if new fonts are loaded, or if point
12850 if (!try_window (window
, startp
, 0))
12851 rc
= SCROLLING_NEED_LARGER_MATRICES
;
12852 else if (w
->cursor
.vpos
< 0)
12854 clear_glyph_matrix (w
->desired_matrix
);
12855 rc
= SCROLLING_FAILED
;
12859 /* Maybe forget recorded base line for line number display. */
12860 if (!just_this_one_p
12861 || current_buffer
->clip_changed
12862 || BEG_UNCHANGED
< CHARPOS (startp
))
12863 w
->base_line_number
= Qnil
;
12865 /* If cursor ends up on a partially visible line,
12866 treat that as being off the bottom of the screen. */
12867 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0))
12869 clear_glyph_matrix (w
->desired_matrix
);
12870 ++extra_scroll_margin_lines
;
12873 rc
= SCROLLING_SUCCESS
;
12880 /* Compute a suitable window start for window W if display of W starts
12881 on a continuation line. Value is non-zero if a new window start
12884 The new window start will be computed, based on W's width, starting
12885 from the start of the continued line. It is the start of the
12886 screen line with the minimum distance from the old start W->start. */
12889 compute_window_start_on_continuation_line (w
)
12892 struct text_pos pos
, start_pos
;
12893 int window_start_changed_p
= 0;
12895 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
12897 /* If window start is on a continuation line... Window start may be
12898 < BEGV in case there's invisible text at the start of the
12899 buffer (M-x rmail, for example). */
12900 if (CHARPOS (start_pos
) > BEGV
12901 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
12904 struct glyph_row
*row
;
12906 /* Handle the case that the window start is out of range. */
12907 if (CHARPOS (start_pos
) < BEGV
)
12908 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
12909 else if (CHARPOS (start_pos
) > ZV
)
12910 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
12912 /* Find the start of the continued line. This should be fast
12913 because scan_buffer is fast (newline cache). */
12914 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
12915 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
12916 row
, DEFAULT_FACE_ID
);
12917 reseat_at_previous_visible_line_start (&it
);
12919 /* If the line start is "too far" away from the window start,
12920 say it takes too much time to compute a new window start. */
12921 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
12922 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
12924 int min_distance
, distance
;
12926 /* Move forward by display lines to find the new window
12927 start. If window width was enlarged, the new start can
12928 be expected to be > the old start. If window width was
12929 decreased, the new window start will be < the old start.
12930 So, we're looking for the display line start with the
12931 minimum distance from the old window start. */
12932 pos
= it
.current
.pos
;
12933 min_distance
= INFINITY
;
12934 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
12935 distance
< min_distance
)
12937 min_distance
= distance
;
12938 pos
= it
.current
.pos
;
12939 move_it_by_lines (&it
, 1, 0);
12942 /* Set the window start there. */
12943 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
12944 window_start_changed_p
= 1;
12948 return window_start_changed_p
;
12952 /* Try cursor movement in case text has not changed in window WINDOW,
12953 with window start STARTP. Value is
12955 CURSOR_MOVEMENT_SUCCESS if successful
12957 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
12959 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
12960 display. *SCROLL_STEP is set to 1, under certain circumstances, if
12961 we want to scroll as if scroll-step were set to 1. See the code.
12963 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
12964 which case we have to abort this redisplay, and adjust matrices
12969 CURSOR_MOVEMENT_SUCCESS
,
12970 CURSOR_MOVEMENT_CANNOT_BE_USED
,
12971 CURSOR_MOVEMENT_MUST_SCROLL
,
12972 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
12976 try_cursor_movement (window
, startp
, scroll_step
)
12977 Lisp_Object window
;
12978 struct text_pos startp
;
12981 struct window
*w
= XWINDOW (window
);
12982 struct frame
*f
= XFRAME (w
->frame
);
12983 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
12986 if (inhibit_try_cursor_movement
)
12990 /* Handle case where text has not changed, only point, and it has
12991 not moved off the frame. */
12992 if (/* Point may be in this window. */
12993 PT
>= CHARPOS (startp
)
12994 /* Selective display hasn't changed. */
12995 && !current_buffer
->clip_changed
12996 /* Function force-mode-line-update is used to force a thorough
12997 redisplay. It sets either windows_or_buffers_changed or
12998 update_mode_lines. So don't take a shortcut here for these
13000 && !update_mode_lines
13001 && !windows_or_buffers_changed
13002 && !cursor_type_changed
13003 /* Can't use this case if highlighting a region. When a
13004 region exists, cursor movement has to do more than just
13006 && !(!NILP (Vtransient_mark_mode
)
13007 && !NILP (current_buffer
->mark_active
))
13008 && NILP (w
->region_showing
)
13009 && NILP (Vshow_trailing_whitespace
)
13010 /* Right after splitting windows, last_point may be nil. */
13011 && INTEGERP (w
->last_point
)
13012 /* This code is not used for mini-buffer for the sake of the case
13013 of redisplaying to replace an echo area message; since in
13014 that case the mini-buffer contents per se are usually
13015 unchanged. This code is of no real use in the mini-buffer
13016 since the handling of this_line_start_pos, etc., in redisplay
13017 handles the same cases. */
13018 && !EQ (window
, minibuf_window
)
13019 /* When splitting windows or for new windows, it happens that
13020 redisplay is called with a nil window_end_vpos or one being
13021 larger than the window. This should really be fixed in
13022 window.c. I don't have this on my list, now, so we do
13023 approximately the same as the old redisplay code. --gerd. */
13024 && INTEGERP (w
->window_end_vpos
)
13025 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
13026 && (FRAME_WINDOW_P (f
)
13027 || !overlay_arrow_in_current_buffer_p ()))
13029 int this_scroll_margin
, top_scroll_margin
;
13030 struct glyph_row
*row
= NULL
;
13033 debug_method_add (w
, "cursor movement");
13036 /* Scroll if point within this distance from the top or bottom
13037 of the window. This is a pixel value. */
13038 this_scroll_margin
= max (0, scroll_margin
);
13039 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
13040 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
13042 top_scroll_margin
= this_scroll_margin
;
13043 if (WINDOW_WANTS_HEADER_LINE_P (w
))
13044 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
13046 /* Start with the row the cursor was displayed during the last
13047 not paused redisplay. Give up if that row is not valid. */
13048 if (w
->last_cursor
.vpos
< 0
13049 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
13050 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13053 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
13054 if (row
->mode_line_p
)
13056 if (!row
->enabled_p
)
13057 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13060 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
13063 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
13065 if (PT
> XFASTINT (w
->last_point
))
13067 /* Point has moved forward. */
13068 while (MATRIX_ROW_END_CHARPOS (row
) < PT
13069 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
13071 xassert (row
->enabled_p
);
13075 /* The end position of a row equals the start position
13076 of the next row. If PT is there, we would rather
13077 display it in the next line. */
13078 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13079 && MATRIX_ROW_END_CHARPOS (row
) == PT
13080 && !cursor_row_p (w
, row
))
13083 /* If within the scroll margin, scroll. Note that
13084 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
13085 the next line would be drawn, and that
13086 this_scroll_margin can be zero. */
13087 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
13088 || PT
> MATRIX_ROW_END_CHARPOS (row
)
13089 /* Line is completely visible last line in window
13090 and PT is to be set in the next line. */
13091 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
13092 && PT
== MATRIX_ROW_END_CHARPOS (row
)
13093 && !row
->ends_at_zv_p
13094 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
13097 else if (PT
< XFASTINT (w
->last_point
))
13099 /* Cursor has to be moved backward. Note that PT >=
13100 CHARPOS (startp) because of the outer if-statement. */
13101 while (!row
->mode_line_p
13102 && (MATRIX_ROW_START_CHARPOS (row
) > PT
13103 || (MATRIX_ROW_START_CHARPOS (row
) == PT
13104 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
13105 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
13106 row
> w
->current_matrix
->rows
13107 && (row
-1)->ends_in_newline_from_string_p
))))
13108 && (row
->y
> top_scroll_margin
13109 || CHARPOS (startp
) == BEGV
))
13111 xassert (row
->enabled_p
);
13115 /* Consider the following case: Window starts at BEGV,
13116 there is invisible, intangible text at BEGV, so that
13117 display starts at some point START > BEGV. It can
13118 happen that we are called with PT somewhere between
13119 BEGV and START. Try to handle that case. */
13120 if (row
< w
->current_matrix
->rows
13121 || row
->mode_line_p
)
13123 row
= w
->current_matrix
->rows
;
13124 if (row
->mode_line_p
)
13128 /* Due to newlines in overlay strings, we may have to
13129 skip forward over overlay strings. */
13130 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13131 && MATRIX_ROW_END_CHARPOS (row
) == PT
13132 && !cursor_row_p (w
, row
))
13135 /* If within the scroll margin, scroll. */
13136 if (row
->y
< top_scroll_margin
13137 && CHARPOS (startp
) != BEGV
)
13142 /* Cursor did not move. So don't scroll even if cursor line
13143 is partially visible, as it was so before. */
13144 rc
= CURSOR_MOVEMENT_SUCCESS
;
13147 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
13148 || PT
> MATRIX_ROW_END_CHARPOS (row
))
13150 /* if PT is not in the glyph row, give up. */
13151 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13153 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
13154 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
13155 && make_cursor_line_fully_visible_p
)
13157 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
13158 && !row
->ends_at_zv_p
13159 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
13160 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13161 else if (row
->height
> window_box_height (w
))
13163 /* If we end up in a partially visible line, let's
13164 make it fully visible, except when it's taller
13165 than the window, in which case we can't do much
13168 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13172 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13173 if (!cursor_row_fully_visible_p (w
, 0, 1))
13174 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13176 rc
= CURSOR_MOVEMENT_SUCCESS
;
13180 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
13185 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
13187 rc
= CURSOR_MOVEMENT_SUCCESS
;
13192 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
13193 && MATRIX_ROW_START_CHARPOS (row
) == PT
13194 && cursor_row_p (w
, row
));
13203 set_vertical_scroll_bar (w
)
13206 int start
, end
, whole
;
13208 /* Calculate the start and end positions for the current window.
13209 At some point, it would be nice to choose between scrollbars
13210 which reflect the whole buffer size, with special markers
13211 indicating narrowing, and scrollbars which reflect only the
13214 Note that mini-buffers sometimes aren't displaying any text. */
13215 if (!MINI_WINDOW_P (w
)
13216 || (w
== XWINDOW (minibuf_window
)
13217 && NILP (echo_area_buffer
[0])))
13219 struct buffer
*buf
= XBUFFER (w
->buffer
);
13220 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
13221 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
13222 /* I don't think this is guaranteed to be right. For the
13223 moment, we'll pretend it is. */
13224 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
13228 if (whole
< (end
- start
))
13229 whole
= end
- start
;
13232 start
= end
= whole
= 0;
13234 /* Indicate what this scroll bar ought to be displaying now. */
13235 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13236 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
13237 (w
, end
- start
, whole
, start
);
13241 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
13242 selected_window is redisplayed.
13244 We can return without actually redisplaying the window if
13245 fonts_changed_p is nonzero. In that case, redisplay_internal will
13249 redisplay_window (window
, just_this_one_p
)
13250 Lisp_Object window
;
13251 int just_this_one_p
;
13253 struct window
*w
= XWINDOW (window
);
13254 struct frame
*f
= XFRAME (w
->frame
);
13255 struct buffer
*buffer
= XBUFFER (w
->buffer
);
13256 struct buffer
*old
= current_buffer
;
13257 struct text_pos lpoint
, opoint
, startp
;
13258 int update_mode_line
;
13261 /* Record it now because it's overwritten. */
13262 int current_matrix_up_to_date_p
= 0;
13263 int used_current_matrix_p
= 0;
13264 /* This is less strict than current_matrix_up_to_date_p.
13265 It indictes that the buffer contents and narrowing are unchanged. */
13266 int buffer_unchanged_p
= 0;
13267 int temp_scroll_step
= 0;
13268 int count
= SPECPDL_INDEX ();
13270 int centering_position
= -1;
13271 int last_line_misfit
= 0;
13272 int beg_unchanged
, end_unchanged
;
13274 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13277 /* W must be a leaf window here. */
13278 xassert (!NILP (w
->buffer
));
13280 *w
->desired_matrix
->method
= 0;
13284 reconsider_clip_changes (w
, buffer
);
13286 /* Has the mode line to be updated? */
13287 update_mode_line
= (!NILP (w
->update_mode_line
)
13288 || update_mode_lines
13289 || buffer
->clip_changed
13290 || buffer
->prevent_redisplay_optimizations_p
);
13292 if (MINI_WINDOW_P (w
))
13294 if (w
== XWINDOW (echo_area_window
)
13295 && !NILP (echo_area_buffer
[0]))
13297 if (update_mode_line
)
13298 /* We may have to update a tty frame's menu bar or a
13299 tool-bar. Example `M-x C-h C-h C-g'. */
13300 goto finish_menu_bars
;
13302 /* We've already displayed the echo area glyphs in this window. */
13303 goto finish_scroll_bars
;
13305 else if ((w
!= XWINDOW (minibuf_window
)
13306 || minibuf_level
== 0)
13307 /* When buffer is nonempty, redisplay window normally. */
13308 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
13309 /* Quail displays non-mini buffers in minibuffer window.
13310 In that case, redisplay the window normally. */
13311 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
13313 /* W is a mini-buffer window, but it's not active, so clear
13315 int yb
= window_text_bottom_y (w
);
13316 struct glyph_row
*row
;
13319 for (y
= 0, row
= w
->desired_matrix
->rows
;
13321 y
+= row
->height
, ++row
)
13322 blank_row (w
, row
, y
);
13323 goto finish_scroll_bars
;
13326 clear_glyph_matrix (w
->desired_matrix
);
13329 /* Otherwise set up data on this window; select its buffer and point
13331 /* Really select the buffer, for the sake of buffer-local
13333 set_buffer_internal_1 (XBUFFER (w
->buffer
));
13335 current_matrix_up_to_date_p
13336 = (!NILP (w
->window_end_valid
)
13337 && !current_buffer
->clip_changed
13338 && !current_buffer
->prevent_redisplay_optimizations_p
13339 && XFASTINT (w
->last_modified
) >= MODIFF
13340 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13342 /* Run the window-bottom-change-functions
13343 if it is possible that the text on the screen has changed
13344 (either due to modification of the text, or any other reason). */
13345 if (!current_matrix_up_to_date_p
13346 && !NILP (Vwindow_text_change_functions
))
13348 safe_run_hooks (Qwindow_text_change_functions
);
13352 beg_unchanged
= BEG_UNCHANGED
;
13353 end_unchanged
= END_UNCHANGED
;
13355 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
13357 specbind (Qinhibit_point_motion_hooks
, Qt
);
13360 = (!NILP (w
->window_end_valid
)
13361 && !current_buffer
->clip_changed
13362 && XFASTINT (w
->last_modified
) >= MODIFF
13363 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
13365 /* When windows_or_buffers_changed is non-zero, we can't rely on
13366 the window end being valid, so set it to nil there. */
13367 if (windows_or_buffers_changed
)
13369 /* If window starts on a continuation line, maybe adjust the
13370 window start in case the window's width changed. */
13371 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13372 compute_window_start_on_continuation_line (w
);
13374 w
->window_end_valid
= Qnil
;
13377 /* Some sanity checks. */
13378 CHECK_WINDOW_END (w
);
13379 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
13381 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
13384 /* If %c is in mode line, update it if needed. */
13385 if (!NILP (w
->column_number_displayed
)
13386 /* This alternative quickly identifies a common case
13387 where no change is needed. */
13388 && !(PT
== XFASTINT (w
->last_point
)
13389 && XFASTINT (w
->last_modified
) >= MODIFF
13390 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
13391 && (XFASTINT (w
->column_number_displayed
)
13392 != (int) current_column ())) /* iftc */
13393 update_mode_line
= 1;
13395 /* Count number of windows showing the selected buffer. An indirect
13396 buffer counts as its base buffer. */
13397 if (!just_this_one_p
)
13399 struct buffer
*current_base
, *window_base
;
13400 current_base
= current_buffer
;
13401 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13402 if (current_base
->base_buffer
)
13403 current_base
= current_base
->base_buffer
;
13404 if (window_base
->base_buffer
)
13405 window_base
= window_base
->base_buffer
;
13406 if (current_base
== window_base
)
13410 /* Point refers normally to the selected window. For any other
13411 window, set up appropriate value. */
13412 if (!EQ (window
, selected_window
))
13414 int new_pt
= XMARKER (w
->pointm
)->charpos
;
13415 int new_pt_byte
= marker_byte_position (w
->pointm
);
13419 new_pt_byte
= BEGV_BYTE
;
13420 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
13422 else if (new_pt
> (ZV
- 1))
13425 new_pt_byte
= ZV_BYTE
;
13426 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
13429 /* We don't use SET_PT so that the point-motion hooks don't run. */
13430 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
13433 /* If any of the character widths specified in the display table
13434 have changed, invalidate the width run cache. It's true that
13435 this may be a bit late to catch such changes, but the rest of
13436 redisplay goes (non-fatally) haywire when the display table is
13437 changed, so why should we worry about doing any better? */
13438 if (current_buffer
->width_run_cache
)
13440 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
13442 if (! disptab_matches_widthtab (disptab
,
13443 XVECTOR (current_buffer
->width_table
)))
13445 invalidate_region_cache (current_buffer
,
13446 current_buffer
->width_run_cache
,
13448 recompute_width_table (current_buffer
, disptab
);
13452 /* If window-start is screwed up, choose a new one. */
13453 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
13456 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13458 /* If someone specified a new starting point but did not insist,
13459 check whether it can be used. */
13460 if (!NILP (w
->optional_new_start
)
13461 && CHARPOS (startp
) >= BEGV
13462 && CHARPOS (startp
) <= ZV
)
13464 w
->optional_new_start
= Qnil
;
13465 start_display (&it
, w
, startp
);
13466 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
13467 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
13468 if (IT_CHARPOS (it
) == PT
)
13469 w
->force_start
= Qt
;
13470 /* IT may overshoot PT if text at PT is invisible. */
13471 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
13472 w
->force_start
= Qt
;
13477 /* Handle case where place to start displaying has been specified,
13478 unless the specified location is outside the accessible range. */
13479 if (!NILP (w
->force_start
)
13480 || w
->frozen_window_start_p
)
13482 /* We set this later on if we have to adjust point. */
13486 w
->force_start
= Qnil
;
13488 w
->window_end_valid
= Qnil
;
13490 /* Forget any recorded base line for line number display. */
13491 if (!buffer_unchanged_p
)
13492 w
->base_line_number
= Qnil
;
13494 /* Redisplay the mode line. Select the buffer properly for that.
13495 Also, run the hook window-scroll-functions
13496 because we have scrolled. */
13497 /* Note, we do this after clearing force_start because
13498 if there's an error, it is better to forget about force_start
13499 than to get into an infinite loop calling the hook functions
13500 and having them get more errors. */
13501 if (!update_mode_line
13502 || ! NILP (Vwindow_scroll_functions
))
13504 update_mode_line
= 1;
13505 w
->update_mode_line
= Qt
;
13506 startp
= run_window_scroll_functions (window
, startp
);
13509 w
->last_modified
= make_number (0);
13510 w
->last_overlay_modified
= make_number (0);
13511 if (CHARPOS (startp
) < BEGV
)
13512 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
13513 else if (CHARPOS (startp
) > ZV
)
13514 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
13516 /* Redisplay, then check if cursor has been set during the
13517 redisplay. Give up if new fonts were loaded. */
13518 val
= try_window (window
, startp
, 1);
13521 w
->force_start
= Qt
;
13522 clear_glyph_matrix (w
->desired_matrix
);
13523 goto need_larger_matrices
;
13525 /* Point was outside the scroll margins. */
13527 new_vpos
= window_box_height (w
) / 2;
13529 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
13531 /* If point does not appear, try to move point so it does
13532 appear. The desired matrix has been built above, so we
13533 can use it here. */
13534 new_vpos
= window_box_height (w
) / 2;
13537 if (!cursor_row_fully_visible_p (w
, 0, 0))
13539 /* Point does appear, but on a line partly visible at end of window.
13540 Move it back to a fully-visible line. */
13541 new_vpos
= window_box_height (w
);
13544 /* If we need to move point for either of the above reasons,
13545 now actually do it. */
13548 struct glyph_row
*row
;
13550 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
13551 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
13554 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
13555 MATRIX_ROW_START_BYTEPOS (row
));
13557 if (w
!= XWINDOW (selected_window
))
13558 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
13559 else if (current_buffer
== old
)
13560 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
13562 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
13564 /* If we are highlighting the region, then we just changed
13565 the region, so redisplay to show it. */
13566 if (!NILP (Vtransient_mark_mode
)
13567 && !NILP (current_buffer
->mark_active
))
13569 clear_glyph_matrix (w
->desired_matrix
);
13570 if (!try_window (window
, startp
, 0))
13571 goto need_larger_matrices
;
13576 debug_method_add (w
, "forced window start");
13581 /* Handle case where text has not changed, only point, and it has
13582 not moved off the frame, and we are not retrying after hscroll.
13583 (current_matrix_up_to_date_p is nonzero when retrying.) */
13584 if (current_matrix_up_to_date_p
13585 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
13586 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
13590 case CURSOR_MOVEMENT_SUCCESS
:
13591 used_current_matrix_p
= 1;
13594 #if 0 /* try_cursor_movement never returns this value. */
13595 case CURSOR_MOVEMENT_NEED_LARGER_MATRICES
:
13596 goto need_larger_matrices
;
13599 case CURSOR_MOVEMENT_MUST_SCROLL
:
13600 goto try_to_scroll
;
13606 /* If current starting point was originally the beginning of a line
13607 but no longer is, find a new starting point. */
13608 else if (!NILP (w
->start_at_line_beg
)
13609 && !(CHARPOS (startp
) <= BEGV
13610 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
13613 debug_method_add (w
, "recenter 1");
13618 /* Try scrolling with try_window_id. Value is > 0 if update has
13619 been done, it is -1 if we know that the same window start will
13620 not work. It is 0 if unsuccessful for some other reason. */
13621 else if ((tem
= try_window_id (w
)) != 0)
13624 debug_method_add (w
, "try_window_id %d", tem
);
13627 if (fonts_changed_p
)
13628 goto need_larger_matrices
;
13632 /* Otherwise try_window_id has returned -1 which means that we
13633 don't want the alternative below this comment to execute. */
13635 else if (CHARPOS (startp
) >= BEGV
13636 && CHARPOS (startp
) <= ZV
13637 && PT
>= CHARPOS (startp
)
13638 && (CHARPOS (startp
) < ZV
13639 /* Avoid starting at end of buffer. */
13640 || CHARPOS (startp
) == BEGV
13641 || (XFASTINT (w
->last_modified
) >= MODIFF
13642 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
13645 /* If first window line is a continuation line, and window start
13646 is inside the modified region, but the first change is before
13647 current window start, we must select a new window start.
13649 However, if this is the result of a down-mouse event (e.g. by
13650 extending the mouse-drag-overlay), we don't want to select a
13651 new window start, since that would change the position under
13652 the mouse, resulting in an unwanted mouse-movement rather
13653 than a simple mouse-click. */
13654 if (NILP (w
->start_at_line_beg
)
13655 && NILP (do_mouse_tracking
)
13656 && CHARPOS (startp
) > BEGV
13657 && CHARPOS (startp
) > BEG
+ beg_unchanged
13658 && CHARPOS (startp
) <= Z
- end_unchanged
)
13660 w
->force_start
= Qt
;
13661 if (XMARKER (w
->start
)->buffer
== current_buffer
)
13662 compute_window_start_on_continuation_line (w
);
13663 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13668 debug_method_add (w
, "same window start");
13671 /* Try to redisplay starting at same place as before.
13672 If point has not moved off frame, accept the results. */
13673 if (!current_matrix_up_to_date_p
13674 /* Don't use try_window_reusing_current_matrix in this case
13675 because a window scroll function can have changed the
13677 || !NILP (Vwindow_scroll_functions
)
13678 || MINI_WINDOW_P (w
)
13679 || !(used_current_matrix_p
13680 = try_window_reusing_current_matrix (w
)))
13682 IF_DEBUG (debug_method_add (w
, "1"));
13683 if (try_window (window
, startp
, 1) < 0)
13684 /* -1 means we need to scroll.
13685 0 means we need new matrices, but fonts_changed_p
13686 is set in that case, so we will detect it below. */
13687 goto try_to_scroll
;
13690 if (fonts_changed_p
)
13691 goto need_larger_matrices
;
13693 if (w
->cursor
.vpos
>= 0)
13695 if (!just_this_one_p
13696 || current_buffer
->clip_changed
13697 || BEG_UNCHANGED
< CHARPOS (startp
))
13698 /* Forget any recorded base line for line number display. */
13699 w
->base_line_number
= Qnil
;
13701 if (!cursor_row_fully_visible_p (w
, 1, 0))
13703 clear_glyph_matrix (w
->desired_matrix
);
13704 last_line_misfit
= 1;
13706 /* Drop through and scroll. */
13711 clear_glyph_matrix (w
->desired_matrix
);
13716 w
->last_modified
= make_number (0);
13717 w
->last_overlay_modified
= make_number (0);
13719 /* Redisplay the mode line. Select the buffer properly for that. */
13720 if (!update_mode_line
)
13722 update_mode_line
= 1;
13723 w
->update_mode_line
= Qt
;
13726 /* Try to scroll by specified few lines. */
13727 if ((scroll_conservatively
13729 || temp_scroll_step
13730 || NUMBERP (current_buffer
->scroll_up_aggressively
)
13731 || NUMBERP (current_buffer
->scroll_down_aggressively
))
13732 && !current_buffer
->clip_changed
13733 && CHARPOS (startp
) >= BEGV
13734 && CHARPOS (startp
) <= ZV
)
13736 /* The function returns -1 if new fonts were loaded, 1 if
13737 successful, 0 if not successful. */
13738 int rc
= try_scrolling (window
, just_this_one_p
,
13739 scroll_conservatively
,
13741 temp_scroll_step
, last_line_misfit
);
13744 case SCROLLING_SUCCESS
:
13747 case SCROLLING_NEED_LARGER_MATRICES
:
13748 goto need_larger_matrices
;
13750 case SCROLLING_FAILED
:
13758 /* Finally, just choose place to start which centers point */
13761 if (centering_position
< 0)
13762 centering_position
= window_box_height (w
) / 2;
13765 debug_method_add (w
, "recenter");
13768 /* w->vscroll = 0; */
13770 /* Forget any previously recorded base line for line number display. */
13771 if (!buffer_unchanged_p
)
13772 w
->base_line_number
= Qnil
;
13774 /* Move backward half the height of the window. */
13775 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13776 it
.current_y
= it
.last_visible_y
;
13777 move_it_vertically_backward (&it
, centering_position
);
13778 xassert (IT_CHARPOS (it
) >= BEGV
);
13780 /* The function move_it_vertically_backward may move over more
13781 than the specified y-distance. If it->w is small, e.g. a
13782 mini-buffer window, we may end up in front of the window's
13783 display area. Start displaying at the start of the line
13784 containing PT in this case. */
13785 if (it
.current_y
<= 0)
13787 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
13788 move_it_vertically_backward (&it
, 0);
13790 /* I think this assert is bogus if buffer contains
13791 invisible text or images. KFS. */
13792 xassert (IT_CHARPOS (it
) <= PT
);
13797 it
.current_x
= it
.hpos
= 0;
13799 /* Set startp here explicitly in case that helps avoid an infinite loop
13800 in case the window-scroll-functions functions get errors. */
13801 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
13803 /* Run scroll hooks. */
13804 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
13806 /* Redisplay the window. */
13807 if (!current_matrix_up_to_date_p
13808 || windows_or_buffers_changed
13809 || cursor_type_changed
13810 /* Don't use try_window_reusing_current_matrix in this case
13811 because it can have changed the buffer. */
13812 || !NILP (Vwindow_scroll_functions
)
13813 || !just_this_one_p
13814 || MINI_WINDOW_P (w
)
13815 || !(used_current_matrix_p
13816 = try_window_reusing_current_matrix (w
)))
13817 try_window (window
, startp
, 0);
13819 /* If new fonts have been loaded (due to fontsets), give up. We
13820 have to start a new redisplay since we need to re-adjust glyph
13822 if (fonts_changed_p
)
13823 goto need_larger_matrices
;
13825 /* If cursor did not appear assume that the middle of the window is
13826 in the first line of the window. Do it again with the next line.
13827 (Imagine a window of height 100, displaying two lines of height
13828 60. Moving back 50 from it->last_visible_y will end in the first
13830 if (w
->cursor
.vpos
< 0)
13832 if (!NILP (w
->window_end_valid
)
13833 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
13835 clear_glyph_matrix (w
->desired_matrix
);
13836 move_it_by_lines (&it
, 1, 0);
13837 try_window (window
, it
.current
.pos
, 0);
13839 else if (PT
< IT_CHARPOS (it
))
13841 clear_glyph_matrix (w
->desired_matrix
);
13842 move_it_by_lines (&it
, -1, 0);
13843 try_window (window
, it
.current
.pos
, 0);
13847 /* Not much we can do about it. */
13851 /* Consider the following case: Window starts at BEGV, there is
13852 invisible, intangible text at BEGV, so that display starts at
13853 some point START > BEGV. It can happen that we are called with
13854 PT somewhere between BEGV and START. Try to handle that case. */
13855 if (w
->cursor
.vpos
< 0)
13857 struct glyph_row
*row
= w
->current_matrix
->rows
;
13858 if (row
->mode_line_p
)
13860 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13863 if (!cursor_row_fully_visible_p (w
, 0, 0))
13865 /* If vscroll is enabled, disable it and try again. */
13869 clear_glyph_matrix (w
->desired_matrix
);
13873 /* If centering point failed to make the whole line visible,
13874 put point at the top instead. That has to make the whole line
13875 visible, if it can be done. */
13876 if (centering_position
== 0)
13879 clear_glyph_matrix (w
->desired_matrix
);
13880 centering_position
= 0;
13886 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
13887 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
13888 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
13891 /* Display the mode line, if we must. */
13892 if ((update_mode_line
13893 /* If window not full width, must redo its mode line
13894 if (a) the window to its side is being redone and
13895 (b) we do a frame-based redisplay. This is a consequence
13896 of how inverted lines are drawn in frame-based redisplay. */
13897 || (!just_this_one_p
13898 && !FRAME_WINDOW_P (f
)
13899 && !WINDOW_FULL_WIDTH_P (w
))
13900 /* Line number to display. */
13901 || INTEGERP (w
->base_line_pos
)
13902 /* Column number is displayed and different from the one displayed. */
13903 || (!NILP (w
->column_number_displayed
)
13904 && (XFASTINT (w
->column_number_displayed
)
13905 != (int) current_column ()))) /* iftc */
13906 /* This means that the window has a mode line. */
13907 && (WINDOW_WANTS_MODELINE_P (w
)
13908 || WINDOW_WANTS_HEADER_LINE_P (w
)))
13910 display_mode_lines (w
);
13912 /* If mode line height has changed, arrange for a thorough
13913 immediate redisplay using the correct mode line height. */
13914 if (WINDOW_WANTS_MODELINE_P (w
)
13915 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
13917 fonts_changed_p
= 1;
13918 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
13919 = DESIRED_MODE_LINE_HEIGHT (w
);
13922 /* If top line height has changed, arrange for a thorough
13923 immediate redisplay using the correct mode line height. */
13924 if (WINDOW_WANTS_HEADER_LINE_P (w
)
13925 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
13927 fonts_changed_p
= 1;
13928 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
13929 = DESIRED_HEADER_LINE_HEIGHT (w
);
13932 if (fonts_changed_p
)
13933 goto need_larger_matrices
;
13936 if (!line_number_displayed
13937 && !BUFFERP (w
->base_line_pos
))
13939 w
->base_line_pos
= Qnil
;
13940 w
->base_line_number
= Qnil
;
13945 /* When we reach a frame's selected window, redo the frame's menu bar. */
13946 if (update_mode_line
13947 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
13949 int redisplay_menu_p
= 0;
13950 int redisplay_tool_bar_p
= 0;
13952 if (FRAME_WINDOW_P (f
))
13954 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
13955 || defined (HAVE_NS) || defined (USE_GTK)
13956 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
13958 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13962 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
13964 if (redisplay_menu_p
)
13965 display_menu_bar (w
);
13967 #ifdef HAVE_WINDOW_SYSTEM
13968 if (FRAME_WINDOW_P (f
))
13970 #if defined (USE_GTK) || defined (HAVE_NS) || USE_MAC_TOOLBAR
13971 redisplay_tool_bar_p
= FRAME_EXTERNAL_TOOL_BAR (f
);
13973 redisplay_tool_bar_p
= WINDOWP (f
->tool_bar_window
)
13974 && (FRAME_TOOL_BAR_LINES (f
) > 0
13975 || !NILP (Vauto_resize_tool_bars
));
13978 if (redisplay_tool_bar_p
&& redisplay_tool_bar (f
))
13980 extern int ignore_mouse_drag_p
;
13981 ignore_mouse_drag_p
= 1;
13987 #ifdef HAVE_WINDOW_SYSTEM
13988 if (FRAME_WINDOW_P (f
)
13989 && update_window_fringes (w
, (just_this_one_p
13990 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
13991 || w
->pseudo_window_p
)))
13995 if (draw_window_fringes (w
, 1))
13996 x_draw_vertical_border (w
);
14000 #endif /* HAVE_WINDOW_SYSTEM */
14002 /* We go to this label, with fonts_changed_p nonzero,
14003 if it is necessary to try again using larger glyph matrices.
14004 We have to redeem the scroll bar even in this case,
14005 because the loop in redisplay_internal expects that. */
14006 need_larger_matrices
:
14008 finish_scroll_bars
:
14010 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
14012 /* Set the thumb's position and size. */
14013 set_vertical_scroll_bar (w
);
14015 /* Note that we actually used the scroll bar attached to this
14016 window, so it shouldn't be deleted at the end of redisplay. */
14017 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
14018 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
14021 /* Restore current_buffer and value of point in it. */
14022 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
14023 set_buffer_internal_1 (old
);
14024 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
14025 shorter. This can be caused by log truncation in *Messages*. */
14026 if (CHARPOS (lpoint
) <= ZV
)
14027 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
14029 unbind_to (count
, Qnil
);
14033 /* Build the complete desired matrix of WINDOW with a window start
14034 buffer position POS.
14036 Value is 1 if successful. It is zero if fonts were loaded during
14037 redisplay which makes re-adjusting glyph matrices necessary, and -1
14038 if point would appear in the scroll margins.
14039 (We check that only if CHECK_MARGINS is nonzero. */
14042 try_window (window
, pos
, check_margins
)
14043 Lisp_Object window
;
14044 struct text_pos pos
;
14047 struct window
*w
= XWINDOW (window
);
14049 struct glyph_row
*last_text_row
= NULL
;
14050 struct frame
*f
= XFRAME (w
->frame
);
14052 /* Make POS the new window start. */
14053 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
14055 /* Mark cursor position as unknown. No overlay arrow seen. */
14056 w
->cursor
.vpos
= -1;
14057 overlay_arrow_seen
= 0;
14059 /* Initialize iterator and info to start at POS. */
14060 start_display (&it
, w
, pos
);
14062 /* Display all lines of W. */
14063 while (it
.current_y
< it
.last_visible_y
)
14065 if (display_line (&it
))
14066 last_text_row
= it
.glyph_row
- 1;
14067 if (fonts_changed_p
)
14071 /* Don't let the cursor end in the scroll margins. */
14073 && !MINI_WINDOW_P (w
))
14075 int this_scroll_margin
;
14077 this_scroll_margin
= max (0, scroll_margin
);
14078 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
14079 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
14081 if ((w
->cursor
.y
>= 0 /* not vscrolled */
14082 && w
->cursor
.y
< this_scroll_margin
14083 && CHARPOS (pos
) > BEGV
14084 && IT_CHARPOS (it
) < ZV
)
14085 /* rms: considering make_cursor_line_fully_visible_p here
14086 seems to give wrong results. We don't want to recenter
14087 when the last line is partly visible, we want to allow
14088 that case to be handled in the usual way. */
14089 || (w
->cursor
.y
+ 1) > it
.last_visible_y
)
14091 w
->cursor
.vpos
= -1;
14092 clear_glyph_matrix (w
->desired_matrix
);
14097 /* If bottom moved off end of frame, change mode line percentage. */
14098 if (XFASTINT (w
->window_end_pos
) <= 0
14099 && Z
!= IT_CHARPOS (it
))
14100 w
->update_mode_line
= Qt
;
14102 /* Set window_end_pos to the offset of the last character displayed
14103 on the window from the end of current_buffer. Set
14104 window_end_vpos to its row number. */
14107 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
14108 w
->window_end_bytepos
14109 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14111 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14113 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14114 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
14115 ->displays_text_p
);
14119 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14120 w
->window_end_pos
= make_number (Z
- ZV
);
14121 w
->window_end_vpos
= make_number (0);
14124 /* But that is not valid info until redisplay finishes. */
14125 w
->window_end_valid
= Qnil
;
14131 /************************************************************************
14132 Window redisplay reusing current matrix when buffer has not changed
14133 ************************************************************************/
14135 /* Try redisplay of window W showing an unchanged buffer with a
14136 different window start than the last time it was displayed by
14137 reusing its current matrix. Value is non-zero if successful.
14138 W->start is the new window start. */
14141 try_window_reusing_current_matrix (w
)
14144 struct frame
*f
= XFRAME (w
->frame
);
14145 struct glyph_row
*row
, *bottom_row
;
14148 struct text_pos start
, new_start
;
14149 int nrows_scrolled
, i
;
14150 struct glyph_row
*last_text_row
;
14151 struct glyph_row
*last_reused_text_row
;
14152 struct glyph_row
*start_row
;
14153 int start_vpos
, min_y
, max_y
;
14156 if (inhibit_try_window_reusing
)
14160 if (/* This function doesn't handle terminal frames. */
14161 !FRAME_WINDOW_P (f
)
14162 /* Don't try to reuse the display if windows have been split
14164 || windows_or_buffers_changed
14165 || cursor_type_changed
)
14168 /* Can't do this if region may have changed. */
14169 if ((!NILP (Vtransient_mark_mode
)
14170 && !NILP (current_buffer
->mark_active
))
14171 || !NILP (w
->region_showing
)
14172 || !NILP (Vshow_trailing_whitespace
))
14175 /* If top-line visibility has changed, give up. */
14176 if (WINDOW_WANTS_HEADER_LINE_P (w
)
14177 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
14180 /* Give up if old or new display is scrolled vertically. We could
14181 make this function handle this, but right now it doesn't. */
14182 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14183 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
14186 /* The variable new_start now holds the new window start. The old
14187 start `start' can be determined from the current matrix. */
14188 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
14189 start
= start_row
->start
.pos
;
14190 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14192 /* Clear the desired matrix for the display below. */
14193 clear_glyph_matrix (w
->desired_matrix
);
14195 if (CHARPOS (new_start
) <= CHARPOS (start
))
14199 /* Don't use this method if the display starts with an ellipsis
14200 displayed for invisible text. It's not easy to handle that case
14201 below, and it's certainly not worth the effort since this is
14202 not a frequent case. */
14203 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
14206 IF_DEBUG (debug_method_add (w
, "twu1"));
14208 /* Display up to a row that can be reused. The variable
14209 last_text_row is set to the last row displayed that displays
14210 text. Note that it.vpos == 0 if or if not there is a
14211 header-line; it's not the same as the MATRIX_ROW_VPOS! */
14212 start_display (&it
, w
, new_start
);
14213 first_row_y
= it
.current_y
;
14214 w
->cursor
.vpos
= -1;
14215 last_text_row
= last_reused_text_row
= NULL
;
14217 while (it
.current_y
< it
.last_visible_y
14218 && !fonts_changed_p
)
14220 /* If we have reached into the characters in the START row,
14221 that means the line boundaries have changed. So we
14222 can't start copying with the row START. Maybe it will
14223 work to start copying with the following row. */
14224 while (IT_CHARPOS (it
) > CHARPOS (start
))
14226 /* Advance to the next row as the "start". */
14228 start
= start_row
->start
.pos
;
14229 /* If there are no more rows to try, or just one, give up. */
14230 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
14231 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
14232 || CHARPOS (start
) == ZV
)
14234 clear_glyph_matrix (w
->desired_matrix
);
14238 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
14240 /* If we have reached alignment,
14241 we can copy the rest of the rows. */
14242 if (IT_CHARPOS (it
) == CHARPOS (start
))
14245 if (display_line (&it
))
14246 last_text_row
= it
.glyph_row
- 1;
14249 /* A value of current_y < last_visible_y means that we stopped
14250 at the previous window start, which in turn means that we
14251 have at least one reusable row. */
14252 if (it
.current_y
< it
.last_visible_y
)
14254 /* IT.vpos always starts from 0; it counts text lines. */
14255 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
14257 /* Find PT if not already found in the lines displayed. */
14258 if (w
->cursor
.vpos
< 0)
14260 int dy
= it
.current_y
- start_row
->y
;
14262 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14263 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
14265 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
14266 dy
, nrows_scrolled
);
14269 clear_glyph_matrix (w
->desired_matrix
);
14274 /* Scroll the display. Do it before the current matrix is
14275 changed. The problem here is that update has not yet
14276 run, i.e. part of the current matrix is not up to date.
14277 scroll_run_hook will clear the cursor, and use the
14278 current matrix to get the height of the row the cursor is
14280 run
.current_y
= start_row
->y
;
14281 run
.desired_y
= it
.current_y
;
14282 run
.height
= it
.last_visible_y
- it
.current_y
;
14284 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
14287 FRAME_RIF (f
)->update_window_begin_hook (w
);
14288 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14289 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14290 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14294 /* Shift current matrix down by nrows_scrolled lines. */
14295 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14296 rotate_matrix (w
->current_matrix
,
14298 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14301 /* Disable lines that must be updated. */
14302 for (i
= 0; i
< nrows_scrolled
; ++i
)
14303 (start_row
+ i
)->enabled_p
= 0;
14305 /* Re-compute Y positions. */
14306 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14307 max_y
= it
.last_visible_y
;
14308 for (row
= start_row
+ nrows_scrolled
;
14312 row
->y
= it
.current_y
;
14313 row
->visible_height
= row
->height
;
14315 if (row
->y
< min_y
)
14316 row
->visible_height
-= min_y
- row
->y
;
14317 if (row
->y
+ row
->height
> max_y
)
14318 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14319 row
->redraw_fringe_bitmaps_p
= 1;
14321 it
.current_y
+= row
->height
;
14323 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14324 last_reused_text_row
= row
;
14325 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
14329 /* Disable lines in the current matrix which are now
14330 below the window. */
14331 for (++row
; row
< bottom_row
; ++row
)
14332 row
->enabled_p
= row
->mode_line_p
= 0;
14335 /* Update window_end_pos etc.; last_reused_text_row is the last
14336 reused row from the current matrix containing text, if any.
14337 The value of last_text_row is the last displayed line
14338 containing text. */
14339 if (last_reused_text_row
)
14341 w
->window_end_bytepos
14342 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
14344 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
14346 = make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
14347 w
->current_matrix
));
14349 else if (last_text_row
)
14351 w
->window_end_bytepos
14352 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14354 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14356 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14360 /* This window must be completely empty. */
14361 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
14362 w
->window_end_pos
= make_number (Z
- ZV
);
14363 w
->window_end_vpos
= make_number (0);
14365 w
->window_end_valid
= Qnil
;
14367 /* Update hint: don't try scrolling again in update_window. */
14368 w
->desired_matrix
->no_scrolling_p
= 1;
14371 debug_method_add (w
, "try_window_reusing_current_matrix 1");
14375 else if (CHARPOS (new_start
) > CHARPOS (start
))
14377 struct glyph_row
*pt_row
, *row
;
14378 struct glyph_row
*first_reusable_row
;
14379 struct glyph_row
*first_row_to_display
;
14381 int yb
= window_text_bottom_y (w
);
14383 /* Find the row starting at new_start, if there is one. Don't
14384 reuse a partially visible line at the end. */
14385 first_reusable_row
= start_row
;
14386 while (first_reusable_row
->enabled_p
14387 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
14388 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14389 < CHARPOS (new_start
)))
14390 ++first_reusable_row
;
14392 /* Give up if there is no row to reuse. */
14393 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
14394 || !first_reusable_row
->enabled_p
14395 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
14396 != CHARPOS (new_start
)))
14399 /* We can reuse fully visible rows beginning with
14400 first_reusable_row to the end of the window. Set
14401 first_row_to_display to the first row that cannot be reused.
14402 Set pt_row to the row containing point, if there is any. */
14404 for (first_row_to_display
= first_reusable_row
;
14405 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
14406 ++first_row_to_display
)
14408 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
14409 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
14410 pt_row
= first_row_to_display
;
14413 /* Start displaying at the start of first_row_to_display. */
14414 xassert (first_row_to_display
->y
< yb
);
14415 init_to_row_start (&it
, w
, first_row_to_display
);
14417 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
14419 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
14421 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
14422 + WINDOW_HEADER_LINE_HEIGHT (w
));
14424 /* Display lines beginning with first_row_to_display in the
14425 desired matrix. Set last_text_row to the last row displayed
14426 that displays text. */
14427 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
14428 if (pt_row
== NULL
)
14429 w
->cursor
.vpos
= -1;
14430 last_text_row
= NULL
;
14431 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
14432 if (display_line (&it
))
14433 last_text_row
= it
.glyph_row
- 1;
14435 /* Give up If point isn't in a row displayed or reused. */
14436 if (w
->cursor
.vpos
< 0)
14438 clear_glyph_matrix (w
->desired_matrix
);
14442 /* If point is in a reused row, adjust y and vpos of the cursor
14446 w
->cursor
.vpos
-= nrows_scrolled
;
14447 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
14450 /* Scroll the display. */
14451 run
.current_y
= first_reusable_row
->y
;
14452 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14453 run
.height
= it
.last_visible_y
- run
.current_y
;
14454 dy
= run
.current_y
- run
.desired_y
;
14459 FRAME_RIF (f
)->update_window_begin_hook (w
);
14460 FRAME_RIF (f
)->clear_window_mouse_face (w
);
14461 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
14462 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
14466 /* Adjust Y positions of reused rows. */
14467 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
14468 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
14469 max_y
= it
.last_visible_y
;
14470 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
14473 row
->visible_height
= row
->height
;
14474 if (row
->y
< min_y
)
14475 row
->visible_height
-= min_y
- row
->y
;
14476 if (row
->y
+ row
->height
> max_y
)
14477 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
14478 row
->redraw_fringe_bitmaps_p
= 1;
14481 /* Scroll the current matrix. */
14482 xassert (nrows_scrolled
> 0);
14483 rotate_matrix (w
->current_matrix
,
14485 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
14488 /* Disable rows not reused. */
14489 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
14490 row
->enabled_p
= 0;
14492 /* Point may have moved to a different line, so we cannot assume that
14493 the previous cursor position is valid; locate the correct row. */
14496 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
14497 row
< bottom_row
&& PT
>= MATRIX_ROW_END_CHARPOS (row
);
14501 w
->cursor
.y
= row
->y
;
14503 if (row
< bottom_row
)
14505 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
14506 while (glyph
->charpos
< PT
)
14509 w
->cursor
.x
+= glyph
->pixel_width
;
14515 /* Adjust window end. A null value of last_text_row means that
14516 the window end is in reused rows which in turn means that
14517 only its vpos can have changed. */
14520 w
->window_end_bytepos
14521 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
14523 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
14525 = make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
14530 = make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
14533 w
->window_end_valid
= Qnil
;
14534 w
->desired_matrix
->no_scrolling_p
= 1;
14537 debug_method_add (w
, "try_window_reusing_current_matrix 2");
14547 /************************************************************************
14548 Window redisplay reusing current matrix when buffer has changed
14549 ************************************************************************/
14551 static struct glyph_row
*find_last_unchanged_at_beg_row
P_ ((struct window
*));
14552 static struct glyph_row
*find_first_unchanged_at_end_row
P_ ((struct window
*,
14554 static struct glyph_row
*
14555 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
14556 struct glyph_row
*));
14559 /* Return the last row in MATRIX displaying text. If row START is
14560 non-null, start searching with that row. IT gives the dimensions
14561 of the display. Value is null if matrix is empty; otherwise it is
14562 a pointer to the row found. */
14564 static struct glyph_row
*
14565 find_last_row_displaying_text (matrix
, it
, start
)
14566 struct glyph_matrix
*matrix
;
14568 struct glyph_row
*start
;
14570 struct glyph_row
*row
, *row_found
;
14572 /* Set row_found to the last row in IT->w's current matrix
14573 displaying text. The loop looks funny but think of partially
14576 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
14577 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14579 xassert (row
->enabled_p
);
14581 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
14590 /* Return the last row in the current matrix of W that is not affected
14591 by changes at the start of current_buffer that occurred since W's
14592 current matrix was built. Value is null if no such row exists.
14594 BEG_UNCHANGED us the number of characters unchanged at the start of
14595 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
14596 first changed character in current_buffer. Characters at positions <
14597 BEG + BEG_UNCHANGED are at the same buffer positions as they were
14598 when the current matrix was built. */
14600 static struct glyph_row
*
14601 find_last_unchanged_at_beg_row (w
)
14604 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
14605 struct glyph_row
*row
;
14606 struct glyph_row
*row_found
= NULL
;
14607 int yb
= window_text_bottom_y (w
);
14609 /* Find the last row displaying unchanged text. */
14610 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14611 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14612 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
14615 if (/* If row ends before first_changed_pos, it is unchanged,
14616 except in some case. */
14617 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
14618 /* When row ends in ZV and we write at ZV it is not
14620 && !row
->ends_at_zv_p
14621 /* When first_changed_pos is the end of a continued line,
14622 row is not unchanged because it may be no longer
14624 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
14625 && (row
->continued_p
14626 || row
->exact_window_width_line_p
)))
14629 /* Stop if last visible row. */
14630 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
14638 /* Find the first glyph row in the current matrix of W that is not
14639 affected by changes at the end of current_buffer since the
14640 time W's current matrix was built.
14642 Return in *DELTA the number of chars by which buffer positions in
14643 unchanged text at the end of current_buffer must be adjusted.
14645 Return in *DELTA_BYTES the corresponding number of bytes.
14647 Value is null if no such row exists, i.e. all rows are affected by
14650 static struct glyph_row
*
14651 find_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
14653 int *delta
, *delta_bytes
;
14655 struct glyph_row
*row
;
14656 struct glyph_row
*row_found
= NULL
;
14658 *delta
= *delta_bytes
= 0;
14660 /* Display must not have been paused, otherwise the current matrix
14661 is not up to date. */
14662 eassert (!NILP (w
->window_end_valid
));
14664 /* A value of window_end_pos >= END_UNCHANGED means that the window
14665 end is in the range of changed text. If so, there is no
14666 unchanged row at the end of W's current matrix. */
14667 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
14670 /* Set row to the last row in W's current matrix displaying text. */
14671 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14673 /* If matrix is entirely empty, no unchanged row exists. */
14674 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14676 /* The value of row is the last glyph row in the matrix having a
14677 meaningful buffer position in it. The end position of row
14678 corresponds to window_end_pos. This allows us to translate
14679 buffer positions in the current matrix to current buffer
14680 positions for characters not in changed text. */
14681 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14682 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14683 int last_unchanged_pos
, last_unchanged_pos_old
;
14684 struct glyph_row
*first_text_row
14685 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
14687 *delta
= Z
- Z_old
;
14688 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14690 /* Set last_unchanged_pos to the buffer position of the last
14691 character in the buffer that has not been changed. Z is the
14692 index + 1 of the last character in current_buffer, i.e. by
14693 subtracting END_UNCHANGED we get the index of the last
14694 unchanged character, and we have to add BEG to get its buffer
14696 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
14697 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
14699 /* Search backward from ROW for a row displaying a line that
14700 starts at a minimum position >= last_unchanged_pos_old. */
14701 for (; row
> first_text_row
; --row
)
14703 /* This used to abort, but it can happen.
14704 It is ok to just stop the search instead here. KFS. */
14705 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14708 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
14713 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
14719 /* Make sure that glyph rows in the current matrix of window W
14720 reference the same glyph memory as corresponding rows in the
14721 frame's frame matrix. This function is called after scrolling W's
14722 current matrix on a terminal frame in try_window_id and
14723 try_window_reusing_current_matrix. */
14726 sync_frame_with_window_matrix_rows (w
)
14729 struct frame
*f
= XFRAME (w
->frame
);
14730 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
14732 /* Preconditions: W must be a leaf window and full-width. Its frame
14733 must have a frame matrix. */
14734 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
14735 xassert (WINDOW_FULL_WIDTH_P (w
));
14736 xassert (!FRAME_WINDOW_P (f
));
14738 /* If W is a full-width window, glyph pointers in W's current matrix
14739 have, by definition, to be the same as glyph pointers in the
14740 corresponding frame matrix. Note that frame matrices have no
14741 marginal areas (see build_frame_matrix). */
14742 window_row
= w
->current_matrix
->rows
;
14743 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
14744 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
14745 while (window_row
< window_row_end
)
14747 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
14748 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
14750 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
14751 frame_row
->glyphs
[TEXT_AREA
] = start
;
14752 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
14753 frame_row
->glyphs
[LAST_AREA
] = end
;
14755 /* Disable frame rows whose corresponding window rows have
14756 been disabled in try_window_id. */
14757 if (!window_row
->enabled_p
)
14758 frame_row
->enabled_p
= 0;
14760 ++window_row
, ++frame_row
;
14765 /* Find the glyph row in window W containing CHARPOS. Consider all
14766 rows between START and END (not inclusive). END null means search
14767 all rows to the end of the display area of W. Value is the row
14768 containing CHARPOS or null. */
14771 row_containing_pos (w
, charpos
, start
, end
, dy
)
14774 struct glyph_row
*start
, *end
;
14777 struct glyph_row
*row
= start
;
14780 /* If we happen to start on a header-line, skip that. */
14781 if (row
->mode_line_p
)
14784 if ((end
&& row
>= end
) || !row
->enabled_p
)
14787 last_y
= window_text_bottom_y (w
) - dy
;
14791 /* Give up if we have gone too far. */
14792 if (end
&& row
>= end
)
14794 /* This formerly returned if they were equal.
14795 I think that both quantities are of a "last plus one" type;
14796 if so, when they are equal, the row is within the screen. -- rms. */
14797 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
14800 /* If it is in this row, return this row. */
14801 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
14802 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
14803 /* The end position of a row equals the start
14804 position of the next row. If CHARPOS is there, we
14805 would rather display it in the next line, except
14806 when this line ends in ZV. */
14807 && !row
->ends_at_zv_p
14808 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
14809 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
14816 /* Try to redisplay window W by reusing its existing display. W's
14817 current matrix must be up to date when this function is called,
14818 i.e. window_end_valid must not be nil.
14822 1 if display has been updated
14823 0 if otherwise unsuccessful
14824 -1 if redisplay with same window start is known not to succeed
14826 The following steps are performed:
14828 1. Find the last row in the current matrix of W that is not
14829 affected by changes at the start of current_buffer. If no such row
14832 2. Find the first row in W's current matrix that is not affected by
14833 changes at the end of current_buffer. Maybe there is no such row.
14835 3. Display lines beginning with the row + 1 found in step 1 to the
14836 row found in step 2 or, if step 2 didn't find a row, to the end of
14839 4. If cursor is not known to appear on the window, give up.
14841 5. If display stopped at the row found in step 2, scroll the
14842 display and current matrix as needed.
14844 6. Maybe display some lines at the end of W, if we must. This can
14845 happen under various circumstances, like a partially visible line
14846 becoming fully visible, or because newly displayed lines are displayed
14847 in smaller font sizes.
14849 7. Update W's window end information. */
14855 struct frame
*f
= XFRAME (w
->frame
);
14856 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
14857 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
14858 struct glyph_row
*last_unchanged_at_beg_row
;
14859 struct glyph_row
*first_unchanged_at_end_row
;
14860 struct glyph_row
*row
;
14861 struct glyph_row
*bottom_row
;
14864 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
14865 struct text_pos start_pos
;
14867 int first_unchanged_at_end_vpos
= 0;
14868 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
14869 struct text_pos start
;
14870 int first_changed_charpos
, last_changed_charpos
;
14873 if (inhibit_try_window_id
)
14877 /* This is handy for debugging. */
14879 #define GIVE_UP(X) \
14881 fprintf (stderr, "try_window_id give up %d\n", (X)); \
14885 #define GIVE_UP(X) return 0
14888 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
14890 /* Don't use this for mini-windows because these can show
14891 messages and mini-buffers, and we don't handle that here. */
14892 if (MINI_WINDOW_P (w
))
14895 /* This flag is used to prevent redisplay optimizations. */
14896 if (windows_or_buffers_changed
|| cursor_type_changed
)
14899 /* Verify that narrowing has not changed.
14900 Also verify that we were not told to prevent redisplay optimizations.
14901 It would be nice to further
14902 reduce the number of cases where this prevents try_window_id. */
14903 if (current_buffer
->clip_changed
14904 || current_buffer
->prevent_redisplay_optimizations_p
)
14907 /* Window must either use window-based redisplay or be full width. */
14908 if (!FRAME_WINDOW_P (f
)
14909 && (!FRAME_LINE_INS_DEL_OK (f
)
14910 || !WINDOW_FULL_WIDTH_P (w
)))
14913 /* Give up if point is not known NOT to appear in W. */
14914 if (PT
< CHARPOS (start
))
14917 /* Another way to prevent redisplay optimizations. */
14918 if (XFASTINT (w
->last_modified
) == 0)
14921 /* Verify that window is not hscrolled. */
14922 if (XFASTINT (w
->hscroll
) != 0)
14925 /* Verify that display wasn't paused. */
14926 if (NILP (w
->window_end_valid
))
14929 /* Can't use this if highlighting a region because a cursor movement
14930 will do more than just set the cursor. */
14931 if (!NILP (Vtransient_mark_mode
)
14932 && !NILP (current_buffer
->mark_active
))
14935 /* Likewise if highlighting trailing whitespace. */
14936 if (!NILP (Vshow_trailing_whitespace
))
14939 /* Likewise if showing a region. */
14940 if (!NILP (w
->region_showing
))
14943 /* Can use this if overlay arrow position and or string have changed. */
14944 if (overlay_arrows_changed_p ())
14947 /* When word-wrap is on, adding a space to the first word of a
14948 wrapped line can change the wrap position, altering the line
14949 above it. It might be worthwhile to handle this more
14950 intelligently, but for now just redisplay from scratch. */
14951 if (!NILP (XBUFFER (w
->buffer
)->word_wrap
))
14954 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
14955 only if buffer has really changed. The reason is that the gap is
14956 initially at Z for freshly visited files. The code below would
14957 set end_unchanged to 0 in that case. */
14958 if (MODIFF
> SAVE_MODIFF
14959 /* This seems to happen sometimes after saving a buffer. */
14960 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
14962 if (GPT
- BEG
< BEG_UNCHANGED
)
14963 BEG_UNCHANGED
= GPT
- BEG
;
14964 if (Z
- GPT
< END_UNCHANGED
)
14965 END_UNCHANGED
= Z
- GPT
;
14968 /* The position of the first and last character that has been changed. */
14969 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
14970 last_changed_charpos
= Z
- END_UNCHANGED
;
14972 /* If window starts after a line end, and the last change is in
14973 front of that newline, then changes don't affect the display.
14974 This case happens with stealth-fontification. Note that although
14975 the display is unchanged, glyph positions in the matrix have to
14976 be adjusted, of course. */
14977 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
14978 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
14979 && ((last_changed_charpos
< CHARPOS (start
)
14980 && CHARPOS (start
) == BEGV
)
14981 || (last_changed_charpos
< CHARPOS (start
) - 1
14982 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
14984 int Z_old
, delta
, Z_BYTE_old
, delta_bytes
;
14985 struct glyph_row
*r0
;
14987 /* Compute how many chars/bytes have been added to or removed
14988 from the buffer. */
14989 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
14990 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
14992 delta_bytes
= Z_BYTE
- Z_BYTE_old
;
14994 /* Give up if PT is not in the window. Note that it already has
14995 been checked at the start of try_window_id that PT is not in
14996 front of the window start. */
14997 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + delta
)
15000 /* If window start is unchanged, we can reuse the whole matrix
15001 as is, after adjusting glyph positions. No need to compute
15002 the window end again, since its offset from Z hasn't changed. */
15003 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15004 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + delta
15005 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + delta_bytes
15006 /* PT must not be in a partially visible line. */
15007 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + delta
15008 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15010 /* Adjust positions in the glyph matrix. */
15011 if (delta
|| delta_bytes
)
15013 struct glyph_row
*r1
15014 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15015 increment_matrix_positions (w
->current_matrix
,
15016 MATRIX_ROW_VPOS (r0
, current_matrix
),
15017 MATRIX_ROW_VPOS (r1
, current_matrix
),
15018 delta
, delta_bytes
);
15021 /* Set the cursor. */
15022 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15024 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15031 /* Handle the case that changes are all below what is displayed in
15032 the window, and that PT is in the window. This shortcut cannot
15033 be taken if ZV is visible in the window, and text has been added
15034 there that is visible in the window. */
15035 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
15036 /* ZV is not visible in the window, or there are no
15037 changes at ZV, actually. */
15038 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
15039 || first_changed_charpos
== last_changed_charpos
))
15041 struct glyph_row
*r0
;
15043 /* Give up if PT is not in the window. Note that it already has
15044 been checked at the start of try_window_id that PT is not in
15045 front of the window start. */
15046 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
15049 /* If window start is unchanged, we can reuse the whole matrix
15050 as is, without changing glyph positions since no text has
15051 been added/removed in front of the window end. */
15052 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15053 if (TEXT_POS_EQUAL_P (start
, r0
->start
.pos
)
15054 /* PT must not be in a partially visible line. */
15055 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
15056 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
15058 /* We have to compute the window end anew since text
15059 can have been added/removed after it. */
15061 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15062 w
->window_end_bytepos
15063 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15065 /* Set the cursor. */
15066 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
15068 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
15075 /* Give up if window start is in the changed area.
15077 The condition used to read
15079 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
15081 but why that was tested escapes me at the moment. */
15082 if (CHARPOS (start
) >= first_changed_charpos
15083 && CHARPOS (start
) <= last_changed_charpos
)
15086 /* Check that window start agrees with the start of the first glyph
15087 row in its current matrix. Check this after we know the window
15088 start is not in changed text, otherwise positions would not be
15090 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
15091 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
15094 /* Give up if the window ends in strings. Overlay strings
15095 at the end are difficult to handle, so don't try. */
15096 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
15097 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
15100 /* Compute the position at which we have to start displaying new
15101 lines. Some of the lines at the top of the window might be
15102 reusable because they are not displaying changed text. Find the
15103 last row in W's current matrix not affected by changes at the
15104 start of current_buffer. Value is null if changes start in the
15105 first line of window. */
15106 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
15107 if (last_unchanged_at_beg_row
)
15109 /* Avoid starting to display in the moddle of a character, a TAB
15110 for instance. This is easier than to set up the iterator
15111 exactly, and it's not a frequent case, so the additional
15112 effort wouldn't really pay off. */
15113 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
15114 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
15115 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
15116 --last_unchanged_at_beg_row
;
15118 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
15121 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
15123 start_pos
= it
.current
.pos
;
15125 /* Start displaying new lines in the desired matrix at the same
15126 vpos we would use in the current matrix, i.e. below
15127 last_unchanged_at_beg_row. */
15128 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
15130 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15131 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
15133 xassert (it
.hpos
== 0 && it
.current_x
== 0);
15137 /* There are no reusable lines at the start of the window.
15138 Start displaying in the first text line. */
15139 start_display (&it
, w
, start
);
15140 it
.vpos
= it
.first_vpos
;
15141 start_pos
= it
.current
.pos
;
15144 /* Find the first row that is not affected by changes at the end of
15145 the buffer. Value will be null if there is no unchanged row, in
15146 which case we must redisplay to the end of the window. delta
15147 will be set to the value by which buffer positions beginning with
15148 first_unchanged_at_end_row have to be adjusted due to text
15150 first_unchanged_at_end_row
15151 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
15152 IF_DEBUG (debug_delta
= delta
);
15153 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
15155 /* Set stop_pos to the buffer position up to which we will have to
15156 display new lines. If first_unchanged_at_end_row != NULL, this
15157 is the buffer position of the start of the line displayed in that
15158 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
15159 that we don't stop at a buffer position. */
15161 if (first_unchanged_at_end_row
)
15163 xassert (last_unchanged_at_beg_row
== NULL
15164 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
15166 /* If this is a continuation line, move forward to the next one
15167 that isn't. Changes in lines above affect this line.
15168 Caution: this may move first_unchanged_at_end_row to a row
15169 not displaying text. */
15170 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
15171 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15172 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15173 < it
.last_visible_y
))
15174 ++first_unchanged_at_end_row
;
15176 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
15177 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
15178 >= it
.last_visible_y
))
15179 first_unchanged_at_end_row
= NULL
;
15182 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
15184 first_unchanged_at_end_vpos
15185 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
15186 xassert (stop_pos
>= Z
- END_UNCHANGED
);
15189 else if (last_unchanged_at_beg_row
== NULL
)
15195 /* Either there is no unchanged row at the end, or the one we have
15196 now displays text. This is a necessary condition for the window
15197 end pos calculation at the end of this function. */
15198 xassert (first_unchanged_at_end_row
== NULL
15199 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
15201 debug_last_unchanged_at_beg_vpos
15202 = (last_unchanged_at_beg_row
15203 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
15205 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
15207 #endif /* GLYPH_DEBUG != 0 */
15210 /* Display new lines. Set last_text_row to the last new line
15211 displayed which has text on it, i.e. might end up as being the
15212 line where the window_end_vpos is. */
15213 w
->cursor
.vpos
= -1;
15214 last_text_row
= NULL
;
15215 overlay_arrow_seen
= 0;
15216 while (it
.current_y
< it
.last_visible_y
15217 && !fonts_changed_p
15218 && (first_unchanged_at_end_row
== NULL
15219 || IT_CHARPOS (it
) < stop_pos
))
15221 if (display_line (&it
))
15222 last_text_row
= it
.glyph_row
- 1;
15225 if (fonts_changed_p
)
15229 /* Compute differences in buffer positions, y-positions etc. for
15230 lines reused at the bottom of the window. Compute what we can
15232 if (first_unchanged_at_end_row
15233 /* No lines reused because we displayed everything up to the
15234 bottom of the window. */
15235 && it
.current_y
< it
.last_visible_y
)
15238 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
15240 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
15241 run
.current_y
= first_unchanged_at_end_row
->y
;
15242 run
.desired_y
= run
.current_y
+ dy
;
15243 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
15247 delta
= delta_bytes
= dvpos
= dy
15248 = run
.current_y
= run
.desired_y
= run
.height
= 0;
15249 first_unchanged_at_end_row
= NULL
;
15251 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
15254 /* Find the cursor if not already found. We have to decide whether
15255 PT will appear on this window (it sometimes doesn't, but this is
15256 not a very frequent case.) This decision has to be made before
15257 the current matrix is altered. A value of cursor.vpos < 0 means
15258 that PT is either in one of the lines beginning at
15259 first_unchanged_at_end_row or below the window. Don't care for
15260 lines that might be displayed later at the window end; as
15261 mentioned, this is not a frequent case. */
15262 if (w
->cursor
.vpos
< 0)
15264 /* Cursor in unchanged rows at the top? */
15265 if (PT
< CHARPOS (start_pos
)
15266 && last_unchanged_at_beg_row
)
15268 row
= row_containing_pos (w
, PT
,
15269 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
15270 last_unchanged_at_beg_row
+ 1, 0);
15272 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15275 /* Start from first_unchanged_at_end_row looking for PT. */
15276 else if (first_unchanged_at_end_row
)
15278 row
= row_containing_pos (w
, PT
- delta
,
15279 first_unchanged_at_end_row
, NULL
, 0);
15281 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
15282 delta_bytes
, dy
, dvpos
);
15285 /* Give up if cursor was not found. */
15286 if (w
->cursor
.vpos
< 0)
15288 clear_glyph_matrix (w
->desired_matrix
);
15293 /* Don't let the cursor end in the scroll margins. */
15295 int this_scroll_margin
, cursor_height
;
15297 this_scroll_margin
= max (0, scroll_margin
);
15298 this_scroll_margin
= min (this_scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15299 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
15300 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
15302 if ((w
->cursor
.y
< this_scroll_margin
15303 && CHARPOS (start
) > BEGV
)
15304 /* Old redisplay didn't take scroll margin into account at the bottom,
15305 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
15306 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
15307 ? cursor_height
+ this_scroll_margin
15308 : 1)) > it
.last_visible_y
)
15310 w
->cursor
.vpos
= -1;
15311 clear_glyph_matrix (w
->desired_matrix
);
15316 /* Scroll the display. Do it before changing the current matrix so
15317 that xterm.c doesn't get confused about where the cursor glyph is
15319 if (dy
&& run
.height
)
15323 if (FRAME_WINDOW_P (f
))
15325 FRAME_RIF (f
)->update_window_begin_hook (w
);
15326 FRAME_RIF (f
)->clear_window_mouse_face (w
);
15327 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
15328 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
15332 /* Terminal frame. In this case, dvpos gives the number of
15333 lines to scroll by; dvpos < 0 means scroll up. */
15334 int first_unchanged_at_end_vpos
15335 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
15336 int from
= WINDOW_TOP_EDGE_LINE (w
) + first_unchanged_at_end_vpos
;
15337 int end
= (WINDOW_TOP_EDGE_LINE (w
)
15338 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
15339 + window_internal_height (w
));
15341 /* Perform the operation on the screen. */
15344 /* Scroll last_unchanged_at_beg_row to the end of the
15345 window down dvpos lines. */
15346 set_terminal_window (f
, end
);
15348 /* On dumb terminals delete dvpos lines at the end
15349 before inserting dvpos empty lines. */
15350 if (!FRAME_SCROLL_REGION_OK (f
))
15351 ins_del_lines (f
, end
- dvpos
, -dvpos
);
15353 /* Insert dvpos empty lines in front of
15354 last_unchanged_at_beg_row. */
15355 ins_del_lines (f
, from
, dvpos
);
15357 else if (dvpos
< 0)
15359 /* Scroll up last_unchanged_at_beg_vpos to the end of
15360 the window to last_unchanged_at_beg_vpos - |dvpos|. */
15361 set_terminal_window (f
, end
);
15363 /* Delete dvpos lines in front of
15364 last_unchanged_at_beg_vpos. ins_del_lines will set
15365 the cursor to the given vpos and emit |dvpos| delete
15367 ins_del_lines (f
, from
+ dvpos
, dvpos
);
15369 /* On a dumb terminal insert dvpos empty lines at the
15371 if (!FRAME_SCROLL_REGION_OK (f
))
15372 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
15375 set_terminal_window (f
, 0);
15381 /* Shift reused rows of the current matrix to the right position.
15382 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
15384 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
15385 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
15388 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
15389 bottom_vpos
, dvpos
);
15390 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
15393 else if (dvpos
> 0)
15395 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
15396 bottom_vpos
, dvpos
);
15397 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
15398 first_unchanged_at_end_vpos
+ dvpos
, 0);
15401 /* For frame-based redisplay, make sure that current frame and window
15402 matrix are in sync with respect to glyph memory. */
15403 if (!FRAME_WINDOW_P (f
))
15404 sync_frame_with_window_matrix_rows (w
);
15406 /* Adjust buffer positions in reused rows. */
15407 if (delta
|| delta_bytes
)
15408 increment_matrix_positions (current_matrix
,
15409 first_unchanged_at_end_vpos
+ dvpos
,
15410 bottom_vpos
, delta
, delta_bytes
);
15412 /* Adjust Y positions. */
15414 shift_glyph_matrix (w
, current_matrix
,
15415 first_unchanged_at_end_vpos
+ dvpos
,
15418 if (first_unchanged_at_end_row
)
15420 first_unchanged_at_end_row
+= dvpos
;
15421 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
15422 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
15423 first_unchanged_at_end_row
= NULL
;
15426 /* If scrolling up, there may be some lines to display at the end of
15428 last_text_row_at_end
= NULL
;
15431 /* Scrolling up can leave for example a partially visible line
15432 at the end of the window to be redisplayed. */
15433 /* Set last_row to the glyph row in the current matrix where the
15434 window end line is found. It has been moved up or down in
15435 the matrix by dvpos. */
15436 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
15437 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
15439 /* If last_row is the window end line, it should display text. */
15440 xassert (last_row
->displays_text_p
);
15442 /* If window end line was partially visible before, begin
15443 displaying at that line. Otherwise begin displaying with the
15444 line following it. */
15445 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
15447 init_to_row_start (&it
, w
, last_row
);
15448 it
.vpos
= last_vpos
;
15449 it
.current_y
= last_row
->y
;
15453 init_to_row_end (&it
, w
, last_row
);
15454 it
.vpos
= 1 + last_vpos
;
15455 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
15459 /* We may start in a continuation line. If so, we have to
15460 get the right continuation_lines_width and current_x. */
15461 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
15462 it
.hpos
= it
.current_x
= 0;
15464 /* Display the rest of the lines at the window end. */
15465 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
15466 while (it
.current_y
< it
.last_visible_y
15467 && !fonts_changed_p
)
15469 /* Is it always sure that the display agrees with lines in
15470 the current matrix? I don't think so, so we mark rows
15471 displayed invalid in the current matrix by setting their
15472 enabled_p flag to zero. */
15473 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
15474 if (display_line (&it
))
15475 last_text_row_at_end
= it
.glyph_row
- 1;
15479 /* Update window_end_pos and window_end_vpos. */
15480 if (first_unchanged_at_end_row
15481 && !last_text_row_at_end
)
15483 /* Window end line if one of the preserved rows from the current
15484 matrix. Set row to the last row displaying text in current
15485 matrix starting at first_unchanged_at_end_row, after
15487 xassert (first_unchanged_at_end_row
->displays_text_p
);
15488 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
15489 first_unchanged_at_end_row
);
15490 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
15492 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15493 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15495 = make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
));
15496 xassert (w
->window_end_bytepos
>= 0);
15497 IF_DEBUG (debug_method_add (w
, "A"));
15499 else if (last_text_row_at_end
)
15502 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
15503 w
->window_end_bytepos
15504 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
15506 = make_number (MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
15507 xassert (w
->window_end_bytepos
>= 0);
15508 IF_DEBUG (debug_method_add (w
, "B"));
15510 else if (last_text_row
)
15512 /* We have displayed either to the end of the window or at the
15513 end of the window, i.e. the last row with text is to be found
15514 in the desired matrix. */
15516 = make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
15517 w
->window_end_bytepos
15518 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
15520 = make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
15521 xassert (w
->window_end_bytepos
>= 0);
15523 else if (first_unchanged_at_end_row
== NULL
15524 && last_text_row
== NULL
15525 && last_text_row_at_end
== NULL
)
15527 /* Displayed to end of window, but no line containing text was
15528 displayed. Lines were deleted at the end of the window. */
15529 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
15530 int vpos
= XFASTINT (w
->window_end_vpos
);
15531 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
15532 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
15535 row
== NULL
&& vpos
>= first_vpos
;
15536 --vpos
, --current_row
, --desired_row
)
15538 if (desired_row
->enabled_p
)
15540 if (desired_row
->displays_text_p
)
15543 else if (current_row
->displays_text_p
)
15547 xassert (row
!= NULL
);
15548 w
->window_end_vpos
= make_number (vpos
+ 1);
15549 w
->window_end_pos
= make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
15550 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
15551 xassert (w
->window_end_bytepos
>= 0);
15552 IF_DEBUG (debug_method_add (w
, "C"));
15557 #if 0 /* This leads to problems, for instance when the cursor is
15558 at ZV, and the cursor line displays no text. */
15559 /* Disable rows below what's displayed in the window. This makes
15560 debugging easier. */
15561 enable_glyph_matrix_rows (current_matrix
,
15562 XFASTINT (w
->window_end_vpos
) + 1,
15566 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
15567 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
15569 /* Record that display has not been completed. */
15570 w
->window_end_valid
= Qnil
;
15571 w
->desired_matrix
->no_scrolling_p
= 1;
15579 /***********************************************************************
15580 More debugging support
15581 ***********************************************************************/
15585 void dump_glyph_row
P_ ((struct glyph_row
*, int, int));
15586 void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
15587 void dump_glyph
P_ ((struct glyph_row
*, struct glyph
*, int));
15590 /* Dump the contents of glyph matrix MATRIX on stderr.
15592 GLYPHS 0 means don't show glyph contents.
15593 GLYPHS 1 means show glyphs in short form
15594 GLYPHS > 1 means show glyphs in long form. */
15597 dump_glyph_matrix (matrix
, glyphs
)
15598 struct glyph_matrix
*matrix
;
15602 for (i
= 0; i
< matrix
->nrows
; ++i
)
15603 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
15607 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
15608 the glyph row and area where the glyph comes from. */
15611 dump_glyph (row
, glyph
, area
)
15612 struct glyph_row
*row
;
15613 struct glyph
*glyph
;
15616 if (glyph
->type
== CHAR_GLYPH
)
15619 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15620 glyph
- row
->glyphs
[TEXT_AREA
],
15623 (BUFFERP (glyph
->object
)
15625 : (STRINGP (glyph
->object
)
15628 glyph
->pixel_width
,
15630 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
15634 glyph
->left_box_line_p
,
15635 glyph
->right_box_line_p
);
15637 else if (glyph
->type
== STRETCH_GLYPH
)
15640 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15641 glyph
- row
->glyphs
[TEXT_AREA
],
15644 (BUFFERP (glyph
->object
)
15646 : (STRINGP (glyph
->object
)
15649 glyph
->pixel_width
,
15653 glyph
->left_box_line_p
,
15654 glyph
->right_box_line_p
);
15656 else if (glyph
->type
== IMAGE_GLYPH
)
15659 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15660 glyph
- row
->glyphs
[TEXT_AREA
],
15663 (BUFFERP (glyph
->object
)
15665 : (STRINGP (glyph
->object
)
15668 glyph
->pixel_width
,
15672 glyph
->left_box_line_p
,
15673 glyph
->right_box_line_p
);
15675 else if (glyph
->type
== COMPOSITE_GLYPH
)
15678 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
15679 glyph
- row
->glyphs
[TEXT_AREA
],
15682 (BUFFERP (glyph
->object
)
15684 : (STRINGP (glyph
->object
)
15687 glyph
->pixel_width
,
15691 glyph
->left_box_line_p
,
15692 glyph
->right_box_line_p
);
15697 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
15698 GLYPHS 0 means don't show glyph contents.
15699 GLYPHS 1 means show glyphs in short form
15700 GLYPHS > 1 means show glyphs in long form. */
15703 dump_glyph_row (row
, vpos
, glyphs
)
15704 struct glyph_row
*row
;
15709 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
15710 fprintf (stderr
, "======================================================================\n");
15712 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d\
15713 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
15715 MATRIX_ROW_START_CHARPOS (row
),
15716 MATRIX_ROW_END_CHARPOS (row
),
15717 row
->used
[TEXT_AREA
],
15718 row
->contains_overlapping_glyphs_p
,
15720 row
->truncated_on_left_p
,
15721 row
->truncated_on_right_p
,
15723 MATRIX_ROW_CONTINUATION_LINE_P (row
),
15724 row
->displays_text_p
,
15727 row
->ends_in_middle_of_char_p
,
15728 row
->starts_in_middle_of_char_p
,
15734 row
->visible_height
,
15737 fprintf (stderr
, "%9d %5d\t%5d\n", row
->start
.overlay_string_index
,
15738 row
->end
.overlay_string_index
,
15739 row
->continuation_lines_width
);
15740 fprintf (stderr
, "%9d %5d\n",
15741 CHARPOS (row
->start
.string_pos
),
15742 CHARPOS (row
->end
.string_pos
));
15743 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
15744 row
->end
.dpvec_index
);
15751 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15753 struct glyph
*glyph
= row
->glyphs
[area
];
15754 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
15756 /* Glyph for a line end in text. */
15757 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
15760 if (glyph
< glyph_end
)
15761 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
15763 for (; glyph
< glyph_end
; ++glyph
)
15764 dump_glyph (row
, glyph
, area
);
15767 else if (glyphs
== 1)
15771 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
15773 char *s
= (char *) alloca (row
->used
[area
] + 1);
15776 for (i
= 0; i
< row
->used
[area
]; ++i
)
15778 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
15779 if (glyph
->type
== CHAR_GLYPH
15780 && glyph
->u
.ch
< 0x80
15781 && glyph
->u
.ch
>= ' ')
15782 s
[i
] = glyph
->u
.ch
;
15788 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
15794 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
15795 Sdump_glyph_matrix
, 0, 1, "p",
15796 doc
: /* Dump the current matrix of the selected window to stderr.
15797 Shows contents of glyph row structures. With non-nil
15798 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
15799 glyphs in short form, otherwise show glyphs in long form. */)
15801 Lisp_Object glyphs
;
15803 struct window
*w
= XWINDOW (selected_window
);
15804 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15806 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
15807 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
15808 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
15809 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
15810 fprintf (stderr
, "=============================================\n");
15811 dump_glyph_matrix (w
->current_matrix
,
15812 NILP (glyphs
) ? 0 : XINT (glyphs
));
15817 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
15818 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
15821 struct frame
*f
= XFRAME (selected_frame
);
15822 dump_glyph_matrix (f
->current_matrix
, 1);
15827 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
15828 doc
: /* Dump glyph row ROW to stderr.
15829 GLYPH 0 means don't dump glyphs.
15830 GLYPH 1 means dump glyphs in short form.
15831 GLYPH > 1 or omitted means dump glyphs in long form. */)
15833 Lisp_Object row
, glyphs
;
15835 struct glyph_matrix
*matrix
;
15838 CHECK_NUMBER (row
);
15839 matrix
= XWINDOW (selected_window
)->current_matrix
;
15841 if (vpos
>= 0 && vpos
< matrix
->nrows
)
15842 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
15844 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15849 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
15850 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
15851 GLYPH 0 means don't dump glyphs.
15852 GLYPH 1 means dump glyphs in short form.
15853 GLYPH > 1 or omitted means dump glyphs in long form. */)
15855 Lisp_Object row
, glyphs
;
15857 struct frame
*sf
= SELECTED_FRAME ();
15858 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
15861 CHECK_NUMBER (row
);
15863 if (vpos
>= 0 && vpos
< m
->nrows
)
15864 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
15865 INTEGERP (glyphs
) ? XINT (glyphs
) : 2);
15870 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
15871 doc
: /* Toggle tracing of redisplay.
15872 With ARG, turn tracing on if and only if ARG is positive. */)
15877 trace_redisplay_p
= !trace_redisplay_p
;
15880 arg
= Fprefix_numeric_value (arg
);
15881 trace_redisplay_p
= XINT (arg
) > 0;
15888 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
15889 doc
: /* Like `format', but print result to stderr.
15890 usage: (trace-to-stderr STRING &rest OBJECTS) */)
15895 Lisp_Object s
= Fformat (nargs
, args
);
15896 fprintf (stderr
, "%s", SDATA (s
));
15900 #endif /* GLYPH_DEBUG */
15904 /***********************************************************************
15905 Building Desired Matrix Rows
15906 ***********************************************************************/
15908 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
15909 Used for non-window-redisplay windows, and for windows w/o left fringe. */
15911 static struct glyph_row
*
15912 get_overlay_arrow_glyph_row (w
, overlay_arrow_string
)
15914 Lisp_Object overlay_arrow_string
;
15916 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
15917 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15918 struct buffer
*old
= current_buffer
;
15919 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
15920 int arrow_len
= SCHARS (overlay_arrow_string
);
15921 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
15922 const unsigned char *p
;
15925 int n_glyphs_before
;
15927 set_buffer_temp (buffer
);
15928 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
15929 it
.glyph_row
->used
[TEXT_AREA
] = 0;
15930 SET_TEXT_POS (it
.position
, 0, 0);
15932 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
15934 while (p
< arrow_end
)
15936 Lisp_Object face
, ilisp
;
15938 /* Get the next character. */
15940 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
15942 it
.c
= *p
, it
.len
= 1;
15945 /* Get its face. */
15946 ilisp
= make_number (p
- arrow_string
);
15947 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
15948 it
.face_id
= compute_char_face (f
, it
.c
, face
);
15950 /* Compute its width, get its glyphs. */
15951 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
15952 SET_TEXT_POS (it
.position
, -1, -1);
15953 PRODUCE_GLYPHS (&it
);
15955 /* If this character doesn't fit any more in the line, we have
15956 to remove some glyphs. */
15957 if (it
.current_x
> it
.last_visible_x
)
15959 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
15964 set_buffer_temp (old
);
15965 return it
.glyph_row
;
15969 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
15970 glyphs are only inserted for terminal frames since we can't really
15971 win with truncation glyphs when partially visible glyphs are
15972 involved. Which glyphs to insert is determined by
15973 produce_special_glyphs. */
15976 insert_left_trunc_glyphs (it
)
15979 struct it truncate_it
;
15980 struct glyph
*from
, *end
, *to
, *toend
;
15982 xassert (!FRAME_WINDOW_P (it
->f
));
15984 /* Get the truncation glyphs. */
15986 truncate_it
.current_x
= 0;
15987 truncate_it
.face_id
= DEFAULT_FACE_ID
;
15988 truncate_it
.glyph_row
= &scratch_glyph_row
;
15989 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
15990 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
15991 truncate_it
.object
= make_number (0);
15992 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
15994 /* Overwrite glyphs from IT with truncation glyphs. */
15995 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
15996 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
15997 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
15998 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
16003 /* There may be padding glyphs left over. Overwrite them too. */
16004 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
16006 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
16012 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
16016 /* Compute the pixel height and width of IT->glyph_row.
16018 Most of the time, ascent and height of a display line will be equal
16019 to the max_ascent and max_height values of the display iterator
16020 structure. This is not the case if
16022 1. We hit ZV without displaying anything. In this case, max_ascent
16023 and max_height will be zero.
16025 2. We have some glyphs that don't contribute to the line height.
16026 (The glyph row flag contributes_to_line_height_p is for future
16027 pixmap extensions).
16029 The first case is easily covered by using default values because in
16030 these cases, the line height does not really matter, except that it
16031 must not be zero. */
16034 compute_line_metrics (it
)
16037 struct glyph_row
*row
= it
->glyph_row
;
16040 if (FRAME_WINDOW_P (it
->f
))
16042 int i
, min_y
, max_y
;
16044 /* The line may consist of one space only, that was added to
16045 place the cursor on it. If so, the row's height hasn't been
16047 if (row
->height
== 0)
16049 if (it
->max_ascent
+ it
->max_descent
== 0)
16050 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
16051 row
->ascent
= it
->max_ascent
;
16052 row
->height
= it
->max_ascent
+ it
->max_descent
;
16053 row
->phys_ascent
= it
->max_phys_ascent
;
16054 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16055 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16058 /* Compute the width of this line. */
16059 row
->pixel_width
= row
->x
;
16060 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
16061 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
16063 xassert (row
->pixel_width
>= 0);
16064 xassert (row
->ascent
>= 0 && row
->height
> 0);
16066 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
16067 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
16069 /* If first line's physical ascent is larger than its logical
16070 ascent, use the physical ascent, and make the row taller.
16071 This makes accented characters fully visible. */
16072 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
16073 && row
->phys_ascent
> row
->ascent
)
16075 row
->height
+= row
->phys_ascent
- row
->ascent
;
16076 row
->ascent
= row
->phys_ascent
;
16079 /* Compute how much of the line is visible. */
16080 row
->visible_height
= row
->height
;
16082 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
16083 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
16085 if (row
->y
< min_y
)
16086 row
->visible_height
-= min_y
- row
->y
;
16087 if (row
->y
+ row
->height
> max_y
)
16088 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16092 row
->pixel_width
= row
->used
[TEXT_AREA
];
16093 if (row
->continued_p
)
16094 row
->pixel_width
-= it
->continuation_pixel_width
;
16095 else if (row
->truncated_on_right_p
)
16096 row
->pixel_width
-= it
->truncation_pixel_width
;
16097 row
->ascent
= row
->phys_ascent
= 0;
16098 row
->height
= row
->phys_height
= row
->visible_height
= 1;
16099 row
->extra_line_spacing
= 0;
16102 /* Compute a hash code for this row. */
16104 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
16105 for (i
= 0; i
< row
->used
[area
]; ++i
)
16106 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
16107 + row
->glyphs
[area
][i
].u
.val
16108 + row
->glyphs
[area
][i
].face_id
16109 + row
->glyphs
[area
][i
].padding_p
16110 + (row
->glyphs
[area
][i
].type
<< 2));
16112 it
->max_ascent
= it
->max_descent
= 0;
16113 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
16117 /* Append one space to the glyph row of iterator IT if doing a
16118 window-based redisplay. The space has the same face as
16119 IT->face_id. Value is non-zero if a space was added.
16121 This function is called to make sure that there is always one glyph
16122 at the end of a glyph row that the cursor can be set on under
16123 window-systems. (If there weren't such a glyph we would not know
16124 how wide and tall a box cursor should be displayed).
16126 At the same time this space let's a nicely handle clearing to the
16127 end of the line if the row ends in italic text. */
16130 append_space_for_newline (it
, default_face_p
)
16132 int default_face_p
;
16134 if (FRAME_WINDOW_P (it
->f
))
16136 int n
= it
->glyph_row
->used
[TEXT_AREA
];
16138 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
16139 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
16141 /* Save some values that must not be changed.
16142 Must save IT->c and IT->len because otherwise
16143 ITERATOR_AT_END_P wouldn't work anymore after
16144 append_space_for_newline has been called. */
16145 enum display_element_type saved_what
= it
->what
;
16146 int saved_c
= it
->c
, saved_len
= it
->len
;
16147 int saved_x
= it
->current_x
;
16148 int saved_face_id
= it
->face_id
;
16149 struct text_pos saved_pos
;
16150 Lisp_Object saved_object
;
16153 saved_object
= it
->object
;
16154 saved_pos
= it
->position
;
16156 it
->what
= IT_CHARACTER
;
16157 bzero (&it
->position
, sizeof it
->position
);
16158 it
->object
= make_number (0);
16162 if (default_face_p
)
16163 it
->face_id
= DEFAULT_FACE_ID
;
16164 else if (it
->face_before_selective_p
)
16165 it
->face_id
= it
->saved_face_id
;
16166 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
16167 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
16169 PRODUCE_GLYPHS (it
);
16171 it
->override_ascent
= -1;
16172 it
->constrain_row_ascent_descent_p
= 0;
16173 it
->current_x
= saved_x
;
16174 it
->object
= saved_object
;
16175 it
->position
= saved_pos
;
16176 it
->what
= saved_what
;
16177 it
->face_id
= saved_face_id
;
16178 it
->len
= saved_len
;
16188 /* Extend the face of the last glyph in the text area of IT->glyph_row
16189 to the end of the display line. Called from display_line.
16190 If the glyph row is empty, add a space glyph to it so that we
16191 know the face to draw. Set the glyph row flag fill_line_p. */
16194 extend_face_to_end_of_line (it
)
16198 struct frame
*f
= it
->f
;
16200 /* If line is already filled, do nothing. */
16201 if (it
->current_x
>= it
->last_visible_x
)
16204 /* Face extension extends the background and box of IT->face_id
16205 to the end of the line. If the background equals the background
16206 of the frame, we don't have to do anything. */
16207 if (it
->face_before_selective_p
)
16208 face
= FACE_FROM_ID (it
->f
, it
->saved_face_id
);
16210 face
= FACE_FROM_ID (f
, it
->face_id
);
16212 if (FRAME_WINDOW_P (f
)
16213 && it
->glyph_row
->displays_text_p
16214 && face
->box
== FACE_NO_BOX
16215 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
16219 /* Set the glyph row flag indicating that the face of the last glyph
16220 in the text area has to be drawn to the end of the text area. */
16221 it
->glyph_row
->fill_line_p
= 1;
16223 /* If current character of IT is not ASCII, make sure we have the
16224 ASCII face. This will be automatically undone the next time
16225 get_next_display_element returns a multibyte character. Note
16226 that the character will always be single byte in unibyte text. */
16227 if (!ASCII_CHAR_P (it
->c
))
16229 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
16232 if (FRAME_WINDOW_P (f
))
16234 /* If the row is empty, add a space with the current face of IT,
16235 so that we know which face to draw. */
16236 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
16238 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
16239 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
16240 it
->glyph_row
->used
[TEXT_AREA
] = 1;
16245 /* Save some values that must not be changed. */
16246 int saved_x
= it
->current_x
;
16247 struct text_pos saved_pos
;
16248 Lisp_Object saved_object
;
16249 enum display_element_type saved_what
= it
->what
;
16250 int saved_face_id
= it
->face_id
;
16252 saved_object
= it
->object
;
16253 saved_pos
= it
->position
;
16255 it
->what
= IT_CHARACTER
;
16256 bzero (&it
->position
, sizeof it
->position
);
16257 it
->object
= make_number (0);
16260 it
->face_id
= face
->id
;
16262 PRODUCE_GLYPHS (it
);
16264 while (it
->current_x
<= it
->last_visible_x
)
16265 PRODUCE_GLYPHS (it
);
16267 /* Don't count these blanks really. It would let us insert a left
16268 truncation glyph below and make us set the cursor on them, maybe. */
16269 it
->current_x
= saved_x
;
16270 it
->object
= saved_object
;
16271 it
->position
= saved_pos
;
16272 it
->what
= saved_what
;
16273 it
->face_id
= saved_face_id
;
16278 /* Value is non-zero if text starting at CHARPOS in current_buffer is
16279 trailing whitespace. */
16282 trailing_whitespace_p (charpos
)
16285 int bytepos
= CHAR_TO_BYTE (charpos
);
16288 while (bytepos
< ZV_BYTE
16289 && (c
= FETCH_CHAR (bytepos
),
16290 c
== ' ' || c
== '\t'))
16293 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
16295 if (bytepos
!= PT_BYTE
)
16302 /* Highlight trailing whitespace, if any, in ROW. */
16305 highlight_trailing_whitespace (f
, row
)
16307 struct glyph_row
*row
;
16309 int used
= row
->used
[TEXT_AREA
];
16313 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
16314 struct glyph
*glyph
= start
+ used
- 1;
16316 /* Skip over glyphs inserted to display the cursor at the
16317 end of a line, for extending the face of the last glyph
16318 to the end of the line on terminals, and for truncation
16319 and continuation glyphs. */
16320 while (glyph
>= start
16321 && glyph
->type
== CHAR_GLYPH
16322 && INTEGERP (glyph
->object
))
16325 /* If last glyph is a space or stretch, and it's trailing
16326 whitespace, set the face of all trailing whitespace glyphs in
16327 IT->glyph_row to `trailing-whitespace'. */
16329 && BUFFERP (glyph
->object
)
16330 && (glyph
->type
== STRETCH_GLYPH
16331 || (glyph
->type
== CHAR_GLYPH
16332 && glyph
->u
.ch
== ' '))
16333 && trailing_whitespace_p (glyph
->charpos
))
16335 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
16339 while (glyph
>= start
16340 && BUFFERP (glyph
->object
)
16341 && (glyph
->type
== STRETCH_GLYPH
16342 || (glyph
->type
== CHAR_GLYPH
16343 && glyph
->u
.ch
== ' ')))
16344 (glyph
--)->face_id
= face_id
;
16350 /* Value is non-zero if glyph row ROW in window W should be
16351 used to hold the cursor. */
16354 cursor_row_p (w
, row
)
16356 struct glyph_row
*row
;
16358 int cursor_row_p
= 1;
16360 if (PT
== MATRIX_ROW_END_CHARPOS (row
))
16362 /* Suppose the row ends on a string.
16363 Unless the row is continued, that means it ends on a newline
16364 in the string. If it's anything other than a display string
16365 (e.g. a before-string from an overlay), we don't want the
16366 cursor there. (This heuristic seems to give the optimal
16367 behavior for the various types of multi-line strings.) */
16368 if (CHARPOS (row
->end
.string_pos
) >= 0)
16370 if (row
->continued_p
)
16374 /* Check for `display' property. */
16375 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
16376 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
16377 struct glyph
*glyph
;
16380 for (glyph
= end
; glyph
>= beg
; --glyph
)
16381 if (STRINGP (glyph
->object
))
16384 = Fget_char_property (make_number (PT
),
16388 && display_prop_string_p (prop
, glyph
->object
));
16393 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
16395 /* If the row ends in middle of a real character,
16396 and the line is continued, we want the cursor here.
16397 That's because MATRIX_ROW_END_CHARPOS would equal
16398 PT if PT is before the character. */
16399 if (!row
->ends_in_ellipsis_p
)
16400 cursor_row_p
= row
->continued_p
;
16402 /* If the row ends in an ellipsis, then
16403 MATRIX_ROW_END_CHARPOS will equal point after the invisible text.
16404 We want that position to be displayed after the ellipsis. */
16407 /* If the row ends at ZV, display the cursor at the end of that
16408 row instead of at the start of the row below. */
16409 else if (row
->ends_at_zv_p
)
16415 return cursor_row_p
;
16420 /* Push the display property PROP so that it will be rendered at the
16421 current position in IT. */
16424 push_display_prop (struct it
*it
, Lisp_Object prop
)
16428 /* Never display a cursor on the prefix. */
16429 it
->avoid_cursor_p
= 1;
16431 if (STRINGP (prop
))
16433 if (SCHARS (prop
) == 0)
16440 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
16441 it
->current
.overlay_string_index
= -1;
16442 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
16443 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
16444 it
->method
= GET_FROM_STRING
;
16445 it
->stop_charpos
= 0;
16447 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
16449 it
->method
= GET_FROM_STRETCH
;
16452 #ifdef HAVE_WINDOW_SYSTEM
16453 else if (IMAGEP (prop
))
16455 it
->what
= IT_IMAGE
;
16456 it
->image_id
= lookup_image (it
->f
, prop
);
16457 it
->method
= GET_FROM_IMAGE
;
16459 #endif /* HAVE_WINDOW_SYSTEM */
16462 pop_it (it
); /* bogus display property, give up */
16467 /* Return the character-property PROP at the current position in IT. */
16470 get_it_property (it
, prop
)
16474 Lisp_Object position
;
16476 if (STRINGP (it
->object
))
16477 position
= make_number (IT_STRING_CHARPOS (*it
));
16478 else if (BUFFERP (it
->object
))
16479 position
= make_number (IT_CHARPOS (*it
));
16483 return Fget_char_property (position
, prop
, it
->object
);
16486 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
16489 handle_line_prefix (struct it
*it
)
16491 Lisp_Object prefix
;
16492 if (it
->continuation_lines_width
> 0)
16494 prefix
= get_it_property (it
, Qwrap_prefix
);
16496 prefix
= Vwrap_prefix
;
16500 prefix
= get_it_property (it
, Qline_prefix
);
16502 prefix
= Vline_prefix
;
16504 if (! NILP (prefix
))
16505 push_display_prop (it
, prefix
);
16510 /* Construct the glyph row IT->glyph_row in the desired matrix of
16511 IT->w from text at the current position of IT. See dispextern.h
16512 for an overview of struct it. Value is non-zero if
16513 IT->glyph_row displays text, as opposed to a line displaying ZV
16520 struct glyph_row
*row
= it
->glyph_row
;
16521 Lisp_Object overlay_arrow_string
;
16523 int may_wrap
= 0, wrap_x
;
16524 int wrap_row_used
= -1, wrap_row_ascent
, wrap_row_height
;
16525 int wrap_row_phys_ascent
, wrap_row_phys_height
;
16526 int wrap_row_extra_line_spacing
;
16528 /* We always start displaying at hpos zero even if hscrolled. */
16529 xassert (it
->hpos
== 0 && it
->current_x
== 0);
16531 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
16532 >= it
->w
->desired_matrix
->nrows
)
16534 it
->w
->nrows_scale_factor
++;
16535 fonts_changed_p
= 1;
16539 /* Is IT->w showing the region? */
16540 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
16542 /* Clear the result glyph row and enable it. */
16543 prepare_desired_row (row
);
16545 row
->y
= it
->current_y
;
16546 row
->start
= it
->start
;
16547 row
->continuation_lines_width
= it
->continuation_lines_width
;
16548 row
->displays_text_p
= 1;
16549 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
16550 it
->starts_in_middle_of_char_p
= 0;
16552 /* Arrange the overlays nicely for our purposes. Usually, we call
16553 display_line on only one line at a time, in which case this
16554 can't really hurt too much, or we call it on lines which appear
16555 one after another in the buffer, in which case all calls to
16556 recenter_overlay_lists but the first will be pretty cheap. */
16557 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
16559 /* Move over display elements that are not visible because we are
16560 hscrolled. This may stop at an x-position < IT->first_visible_x
16561 if the first glyph is partially visible or if we hit a line end. */
16562 if (it
->current_x
< it
->first_visible_x
)
16564 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
16565 MOVE_TO_POS
| MOVE_TO_X
);
16569 /* We only do this when not calling `move_it_in_display_line_to'
16570 above, because move_it_in_display_line_to calls
16571 handle_line_prefix itself. */
16572 handle_line_prefix (it
);
16575 /* Get the initial row height. This is either the height of the
16576 text hscrolled, if there is any, or zero. */
16577 row
->ascent
= it
->max_ascent
;
16578 row
->height
= it
->max_ascent
+ it
->max_descent
;
16579 row
->phys_ascent
= it
->max_phys_ascent
;
16580 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
16581 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
16583 /* Loop generating characters. The loop is left with IT on the next
16584 character to display. */
16587 int n_glyphs_before
, hpos_before
, x_before
;
16589 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
16591 /* Retrieve the next thing to display. Value is zero if end of
16593 if (!get_next_display_element (it
))
16595 /* Maybe add a space at the end of this line that is used to
16596 display the cursor there under X. Set the charpos of the
16597 first glyph of blank lines not corresponding to any text
16599 #ifdef HAVE_WINDOW_SYSTEM
16600 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16601 row
->exact_window_width_line_p
= 1;
16603 #endif /* HAVE_WINDOW_SYSTEM */
16604 if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
16605 || row
->used
[TEXT_AREA
] == 0)
16607 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
16608 row
->displays_text_p
= 0;
16610 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
)
16611 && (!MINI_WINDOW_P (it
->w
)
16612 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
16613 row
->indicate_empty_line_p
= 1;
16616 it
->continuation_lines_width
= 0;
16617 row
->ends_at_zv_p
= 1;
16621 /* Now, get the metrics of what we want to display. This also
16622 generates glyphs in `row' (which is IT->glyph_row). */
16623 n_glyphs_before
= row
->used
[TEXT_AREA
];
16626 /* Remember the line height so far in case the next element doesn't
16627 fit on the line. */
16628 if (it
->line_wrap
!= TRUNCATE
)
16630 ascent
= it
->max_ascent
;
16631 descent
= it
->max_descent
;
16632 phys_ascent
= it
->max_phys_ascent
;
16633 phys_descent
= it
->max_phys_descent
;
16635 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
16637 if (IT_DISPLAYING_WHITESPACE (it
))
16643 wrap_row_used
= row
->used
[TEXT_AREA
];
16644 wrap_row_ascent
= row
->ascent
;
16645 wrap_row_height
= row
->height
;
16646 wrap_row_phys_ascent
= row
->phys_ascent
;
16647 wrap_row_phys_height
= row
->phys_height
;
16648 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
16654 PRODUCE_GLYPHS (it
);
16656 /* If this display element was in marginal areas, continue with
16658 if (it
->area
!= TEXT_AREA
)
16660 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16661 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16662 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16663 row
->phys_height
= max (row
->phys_height
,
16664 it
->max_phys_ascent
+ it
->max_phys_descent
);
16665 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16666 it
->max_extra_line_spacing
);
16667 set_iterator_to_next (it
, 1);
16671 /* Does the display element fit on the line? If we truncate
16672 lines, we should draw past the right edge of the window. If
16673 we don't truncate, we want to stop so that we can display the
16674 continuation glyph before the right margin. If lines are
16675 continued, there are two possible strategies for characters
16676 resulting in more than 1 glyph (e.g. tabs): Display as many
16677 glyphs as possible in this line and leave the rest for the
16678 continuation line, or display the whole element in the next
16679 line. Original redisplay did the former, so we do it also. */
16680 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
16681 hpos_before
= it
->hpos
;
16684 if (/* Not a newline. */
16686 /* Glyphs produced fit entirely in the line. */
16687 && it
->current_x
< it
->last_visible_x
)
16689 it
->hpos
+= nglyphs
;
16690 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16691 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16692 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16693 row
->phys_height
= max (row
->phys_height
,
16694 it
->max_phys_ascent
+ it
->max_phys_descent
);
16695 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16696 it
->max_extra_line_spacing
);
16697 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
16698 row
->x
= x
- it
->first_visible_x
;
16703 struct glyph
*glyph
;
16705 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
16707 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
16708 new_x
= x
+ glyph
->pixel_width
;
16710 if (/* Lines are continued. */
16711 it
->line_wrap
!= TRUNCATE
16712 && (/* Glyph doesn't fit on the line. */
16713 new_x
> it
->last_visible_x
16714 /* Or it fits exactly on a window system frame. */
16715 || (new_x
== it
->last_visible_x
16716 && FRAME_WINDOW_P (it
->f
))))
16718 /* End of a continued line. */
16721 || (new_x
== it
->last_visible_x
16722 && FRAME_WINDOW_P (it
->f
)))
16724 /* Current glyph is the only one on the line or
16725 fits exactly on the line. We must continue
16726 the line because we can't draw the cursor
16727 after the glyph. */
16728 row
->continued_p
= 1;
16729 it
->current_x
= new_x
;
16730 it
->continuation_lines_width
+= new_x
;
16732 if (i
== nglyphs
- 1)
16734 /* If line-wrap is on, check if a previous
16735 wrap point was found. */
16736 if (wrap_row_used
> 0
16737 /* Even if there is a previous wrap
16738 point, continue the line here as
16739 usual, if (i) the previous character
16740 was a space or tab AND (ii) the
16741 current character is not. */
16743 || IT_DISPLAYING_WHITESPACE (it
)))
16746 set_iterator_to_next (it
, 1);
16747 #ifdef HAVE_WINDOW_SYSTEM
16748 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16750 if (!get_next_display_element (it
))
16752 row
->exact_window_width_line_p
= 1;
16753 it
->continuation_lines_width
= 0;
16754 row
->continued_p
= 0;
16755 row
->ends_at_zv_p
= 1;
16757 else if (ITERATOR_AT_END_OF_LINE_P (it
))
16759 row
->continued_p
= 0;
16760 row
->exact_window_width_line_p
= 1;
16763 #endif /* HAVE_WINDOW_SYSTEM */
16766 else if (CHAR_GLYPH_PADDING_P (*glyph
)
16767 && !FRAME_WINDOW_P (it
->f
))
16769 /* A padding glyph that doesn't fit on this line.
16770 This means the whole character doesn't fit
16772 row
->used
[TEXT_AREA
] = n_glyphs_before
;
16774 /* Fill the rest of the row with continuation
16775 glyphs like in 20.x. */
16776 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
16777 < row
->glyphs
[1 + TEXT_AREA
])
16778 produce_special_glyphs (it
, IT_CONTINUATION
);
16780 row
->continued_p
= 1;
16781 it
->current_x
= x_before
;
16782 it
->continuation_lines_width
+= x_before
;
16784 /* Restore the height to what it was before the
16785 element not fitting on the line. */
16786 it
->max_ascent
= ascent
;
16787 it
->max_descent
= descent
;
16788 it
->max_phys_ascent
= phys_ascent
;
16789 it
->max_phys_descent
= phys_descent
;
16791 else if (wrap_row_used
> 0)
16795 it
->continuation_lines_width
+= wrap_x
;
16796 row
->used
[TEXT_AREA
] = wrap_row_used
;
16797 row
->ascent
= wrap_row_ascent
;
16798 row
->height
= wrap_row_height
;
16799 row
->phys_ascent
= wrap_row_phys_ascent
;
16800 row
->phys_height
= wrap_row_phys_height
;
16801 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
16802 row
->continued_p
= 1;
16803 row
->ends_at_zv_p
= 0;
16804 row
->exact_window_width_line_p
= 0;
16805 it
->continuation_lines_width
+= x
;
16807 /* Make sure that a non-default face is extended
16808 up to the right margin of the window. */
16809 extend_face_to_end_of_line (it
);
16811 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
16813 /* A TAB that extends past the right edge of the
16814 window. This produces a single glyph on
16815 window system frames. We leave the glyph in
16816 this row and let it fill the row, but don't
16817 consume the TAB. */
16818 it
->continuation_lines_width
+= it
->last_visible_x
;
16819 row
->ends_in_middle_of_char_p
= 1;
16820 row
->continued_p
= 1;
16821 glyph
->pixel_width
= it
->last_visible_x
- x
;
16822 it
->starts_in_middle_of_char_p
= 1;
16826 /* Something other than a TAB that draws past
16827 the right edge of the window. Restore
16828 positions to values before the element. */
16829 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
16831 /* Display continuation glyphs. */
16832 if (!FRAME_WINDOW_P (it
->f
))
16833 produce_special_glyphs (it
, IT_CONTINUATION
);
16834 row
->continued_p
= 1;
16836 it
->current_x
= x_before
;
16837 it
->continuation_lines_width
+= x
;
16838 extend_face_to_end_of_line (it
);
16840 if (nglyphs
> 1 && i
> 0)
16842 row
->ends_in_middle_of_char_p
= 1;
16843 it
->starts_in_middle_of_char_p
= 1;
16846 /* Restore the height to what it was before the
16847 element not fitting on the line. */
16848 it
->max_ascent
= ascent
;
16849 it
->max_descent
= descent
;
16850 it
->max_phys_ascent
= phys_ascent
;
16851 it
->max_phys_descent
= phys_descent
;
16856 else if (new_x
> it
->first_visible_x
)
16858 /* Increment number of glyphs actually displayed. */
16861 if (x
< it
->first_visible_x
)
16862 /* Glyph is partially visible, i.e. row starts at
16863 negative X position. */
16864 row
->x
= x
- it
->first_visible_x
;
16868 /* Glyph is completely off the left margin of the
16869 window. This should not happen because of the
16870 move_it_in_display_line at the start of this
16871 function, unless the text display area of the
16872 window is empty. */
16873 xassert (it
->first_visible_x
<= it
->last_visible_x
);
16877 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
16878 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
16879 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
16880 row
->phys_height
= max (row
->phys_height
,
16881 it
->max_phys_ascent
+ it
->max_phys_descent
);
16882 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
16883 it
->max_extra_line_spacing
);
16885 /* End of this display line if row is continued. */
16886 if (row
->continued_p
|| row
->ends_at_zv_p
)
16891 /* Is this a line end? If yes, we're also done, after making
16892 sure that a non-default face is extended up to the right
16893 margin of the window. */
16894 if (ITERATOR_AT_END_OF_LINE_P (it
))
16896 int used_before
= row
->used
[TEXT_AREA
];
16898 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
16900 #ifdef HAVE_WINDOW_SYSTEM
16901 /* Add a space at the end of the line that is used to
16902 display the cursor there. */
16903 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16904 append_space_for_newline (it
, 0);
16905 #endif /* HAVE_WINDOW_SYSTEM */
16907 /* Extend the face to the end of the line. */
16908 extend_face_to_end_of_line (it
);
16910 /* Make sure we have the position. */
16911 if (used_before
== 0)
16912 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
16914 /* Consume the line end. This skips over invisible lines. */
16915 set_iterator_to_next (it
, 1);
16916 it
->continuation_lines_width
= 0;
16920 /* Proceed with next display element. Note that this skips
16921 over lines invisible because of selective display. */
16922 set_iterator_to_next (it
, 1);
16924 /* If we truncate lines, we are done when the last displayed
16925 glyphs reach past the right margin of the window. */
16926 if (it
->line_wrap
== TRUNCATE
16927 && (FRAME_WINDOW_P (it
->f
)
16928 ? (it
->current_x
>= it
->last_visible_x
)
16929 : (it
->current_x
> it
->last_visible_x
)))
16931 /* Maybe add truncation glyphs. */
16932 if (!FRAME_WINDOW_P (it
->f
))
16936 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
16937 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
16940 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
16942 row
->used
[TEXT_AREA
] = i
;
16943 produce_special_glyphs (it
, IT_TRUNCATION
);
16946 #ifdef HAVE_WINDOW_SYSTEM
16949 /* Don't truncate if we can overflow newline into fringe. */
16950 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
16952 if (!get_next_display_element (it
))
16954 it
->continuation_lines_width
= 0;
16955 row
->ends_at_zv_p
= 1;
16956 row
->exact_window_width_line_p
= 1;
16959 if (ITERATOR_AT_END_OF_LINE_P (it
))
16961 row
->exact_window_width_line_p
= 1;
16962 goto at_end_of_line
;
16966 #endif /* HAVE_WINDOW_SYSTEM */
16968 row
->truncated_on_right_p
= 1;
16969 it
->continuation_lines_width
= 0;
16970 reseat_at_next_visible_line_start (it
, 0);
16971 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
16972 it
->hpos
= hpos_before
;
16973 it
->current_x
= x_before
;
16978 /* If line is not empty and hscrolled, maybe insert truncation glyphs
16979 at the left window margin. */
16980 if (it
->first_visible_x
16981 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
16983 if (!FRAME_WINDOW_P (it
->f
))
16984 insert_left_trunc_glyphs (it
);
16985 row
->truncated_on_left_p
= 1;
16988 /* If the start of this line is the overlay arrow-position, then
16989 mark this glyph row as the one containing the overlay arrow.
16990 This is clearly a mess with variable size fonts. It would be
16991 better to let it be displayed like cursors under X. */
16992 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
16993 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
16994 !NILP (overlay_arrow_string
)))
16996 /* Overlay arrow in window redisplay is a fringe bitmap. */
16997 if (STRINGP (overlay_arrow_string
))
16999 struct glyph_row
*arrow_row
17000 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
17001 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
17002 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
17003 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
17004 struct glyph
*p2
, *end
;
17006 /* Copy the arrow glyphs. */
17007 while (glyph
< arrow_end
)
17010 /* Throw away padding glyphs. */
17012 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17013 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
17019 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
17024 xassert (INTEGERP (overlay_arrow_string
));
17025 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
17027 overlay_arrow_seen
= 1;
17030 /* Compute pixel dimensions of this line. */
17031 compute_line_metrics (it
);
17033 /* Remember the position at which this line ends. */
17034 row
->end
= it
->current
;
17036 /* Record whether this row ends inside an ellipsis. */
17037 row
->ends_in_ellipsis_p
17038 = (it
->method
== GET_FROM_DISPLAY_VECTOR
17039 && it
->ellipsis_p
);
17041 /* Save fringe bitmaps in this row. */
17042 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
17043 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
17044 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
17045 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
17047 it
->left_user_fringe_bitmap
= 0;
17048 it
->left_user_fringe_face_id
= 0;
17049 it
->right_user_fringe_bitmap
= 0;
17050 it
->right_user_fringe_face_id
= 0;
17052 /* Maybe set the cursor. */
17053 if (it
->w
->cursor
.vpos
< 0
17054 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
17055 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
17056 && cursor_row_p (it
->w
, row
))
17057 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
17059 /* Highlight trailing whitespace. */
17060 if (!NILP (Vshow_trailing_whitespace
))
17061 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
17063 /* Prepare for the next line. This line starts horizontally at (X
17064 HPOS) = (0 0). Vertical positions are incremented. As a
17065 convenience for the caller, IT->glyph_row is set to the next
17067 it
->current_x
= it
->hpos
= 0;
17068 it
->current_y
+= row
->height
;
17071 it
->start
= it
->current
;
17072 return row
->displays_text_p
;
17077 /***********************************************************************
17079 ***********************************************************************/
17081 /* Redisplay the menu bar in the frame for window W.
17083 The menu bar of X frames that don't have X toolkit support is
17084 displayed in a special window W->frame->menu_bar_window.
17086 The menu bar of terminal frames is treated specially as far as
17087 glyph matrices are concerned. Menu bar lines are not part of
17088 windows, so the update is done directly on the frame matrix rows
17089 for the menu bar. */
17092 display_menu_bar (w
)
17095 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
17100 /* Don't do all this for graphical frames. */
17102 if (FRAME_W32_P (f
))
17105 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
17111 if (FRAME_NS_P (f
))
17113 #endif /* HAVE_NS */
17115 #ifdef USE_X_TOOLKIT
17116 xassert (!FRAME_WINDOW_P (f
));
17117 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
17118 it
.first_visible_x
= 0;
17119 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17120 #else /* not USE_X_TOOLKIT */
17121 if (FRAME_WINDOW_P (f
))
17123 /* Menu bar lines are displayed in the desired matrix of the
17124 dummy window menu_bar_window. */
17125 struct window
*menu_w
;
17126 xassert (WINDOWP (f
->menu_bar_window
));
17127 menu_w
= XWINDOW (f
->menu_bar_window
);
17128 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
17130 it
.first_visible_x
= 0;
17131 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
17135 /* This is a TTY frame, i.e. character hpos/vpos are used as
17137 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
17139 it
.first_visible_x
= 0;
17140 it
.last_visible_x
= FRAME_COLS (f
);
17142 #endif /* not USE_X_TOOLKIT */
17144 if (! mode_line_inverse_video
)
17145 /* Force the menu-bar to be displayed in the default face. */
17146 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17148 /* Clear all rows of the menu bar. */
17149 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
17151 struct glyph_row
*row
= it
.glyph_row
+ i
;
17152 clear_glyph_row (row
);
17153 row
->enabled_p
= 1;
17154 row
->full_width_p
= 1;
17157 /* Display all items of the menu bar. */
17158 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
17159 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
17161 Lisp_Object string
;
17163 /* Stop at nil string. */
17164 string
= AREF (items
, i
+ 1);
17168 /* Remember where item was displayed. */
17169 ASET (items
, i
+ 3, make_number (it
.hpos
));
17171 /* Display the item, pad with one space. */
17172 if (it
.current_x
< it
.last_visible_x
)
17173 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
17174 SCHARS (string
) + 1, 0, 0, -1);
17177 /* Fill out the line with spaces. */
17178 if (it
.current_x
< it
.last_visible_x
)
17179 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
17181 /* Compute the total height of the lines. */
17182 compute_line_metrics (&it
);
17187 /***********************************************************************
17189 ***********************************************************************/
17191 /* Redisplay mode lines in the window tree whose root is WINDOW. If
17192 FORCE is non-zero, redisplay mode lines unconditionally.
17193 Otherwise, redisplay only mode lines that are garbaged. Value is
17194 the number of windows whose mode lines were redisplayed. */
17197 redisplay_mode_lines (window
, force
)
17198 Lisp_Object window
;
17203 while (!NILP (window
))
17205 struct window
*w
= XWINDOW (window
);
17207 if (WINDOWP (w
->hchild
))
17208 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
17209 else if (WINDOWP (w
->vchild
))
17210 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
17212 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
17213 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
17215 struct text_pos lpoint
;
17216 struct buffer
*old
= current_buffer
;
17218 /* Set the window's buffer for the mode line display. */
17219 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
17220 set_buffer_internal_1 (XBUFFER (w
->buffer
));
17222 /* Point refers normally to the selected window. For any
17223 other window, set up appropriate value. */
17224 if (!EQ (window
, selected_window
))
17226 struct text_pos pt
;
17228 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
17229 if (CHARPOS (pt
) < BEGV
)
17230 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17231 else if (CHARPOS (pt
) > (ZV
- 1))
17232 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
17234 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
17237 /* Display mode lines. */
17238 clear_glyph_matrix (w
->desired_matrix
);
17239 if (display_mode_lines (w
))
17242 w
->must_be_updated_p
= 1;
17245 /* Restore old settings. */
17246 set_buffer_internal_1 (old
);
17247 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17257 /* Display the mode and/or top line of window W. Value is the number
17258 of mode lines displayed. */
17261 display_mode_lines (w
)
17264 Lisp_Object old_selected_window
, old_selected_frame
;
17267 old_selected_frame
= selected_frame
;
17268 selected_frame
= w
->frame
;
17269 old_selected_window
= selected_window
;
17270 XSETWINDOW (selected_window
, w
);
17272 /* These will be set while the mode line specs are processed. */
17273 line_number_displayed
= 0;
17274 w
->column_number_displayed
= Qnil
;
17276 if (WINDOW_WANTS_MODELINE_P (w
))
17278 struct window
*sel_w
= XWINDOW (old_selected_window
);
17280 /* Select mode line face based on the real selected window. */
17281 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
17282 current_buffer
->mode_line_format
);
17286 if (WINDOW_WANTS_HEADER_LINE_P (w
))
17288 display_mode_line (w
, HEADER_LINE_FACE_ID
,
17289 current_buffer
->header_line_format
);
17293 selected_frame
= old_selected_frame
;
17294 selected_window
= old_selected_window
;
17299 /* Display mode or top line of window W. FACE_ID specifies which line
17300 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
17301 FORMAT is the mode line format to display. Value is the pixel
17302 height of the mode line displayed. */
17305 display_mode_line (w
, face_id
, format
)
17307 enum face_id face_id
;
17308 Lisp_Object format
;
17312 int count
= SPECPDL_INDEX ();
17314 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
17315 /* Don't extend on a previously drawn mode-line.
17316 This may happen if called from pos_visible_p. */
17317 it
.glyph_row
->enabled_p
= 0;
17318 prepare_desired_row (it
.glyph_row
);
17320 it
.glyph_row
->mode_line_p
= 1;
17322 if (! mode_line_inverse_video
)
17323 /* Force the mode-line to be displayed in the default face. */
17324 it
.base_face_id
= it
.face_id
= DEFAULT_FACE_ID
;
17326 record_unwind_protect (unwind_format_mode_line
,
17327 format_mode_line_unwind_data (NULL
, Qnil
, 0));
17329 mode_line_target
= MODE_LINE_DISPLAY
;
17331 /* Temporarily make frame's keyboard the current kboard so that
17332 kboard-local variables in the mode_line_format will get the right
17334 push_kboard (FRAME_KBOARD (it
.f
));
17335 record_unwind_save_match_data ();
17336 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
17339 unbind_to (count
, Qnil
);
17341 /* Fill up with spaces. */
17342 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
17344 compute_line_metrics (&it
);
17345 it
.glyph_row
->full_width_p
= 1;
17346 it
.glyph_row
->continued_p
= 0;
17347 it
.glyph_row
->truncated_on_left_p
= 0;
17348 it
.glyph_row
->truncated_on_right_p
= 0;
17350 /* Make a 3D mode-line have a shadow at its right end. */
17351 face
= FACE_FROM_ID (it
.f
, face_id
);
17352 extend_face_to_end_of_line (&it
);
17353 if (face
->box
!= FACE_NO_BOX
)
17355 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
17356 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
17357 last
->right_box_line_p
= 1;
17360 return it
.glyph_row
->height
;
17363 /* Move element ELT in LIST to the front of LIST.
17364 Return the updated list. */
17367 move_elt_to_front (elt
, list
)
17368 Lisp_Object elt
, list
;
17370 register Lisp_Object tail
, prev
;
17371 register Lisp_Object tem
;
17375 while (CONSP (tail
))
17381 /* Splice out the link TAIL. */
17383 list
= XCDR (tail
);
17385 Fsetcdr (prev
, XCDR (tail
));
17387 /* Now make it the first. */
17388 Fsetcdr (tail
, list
);
17393 tail
= XCDR (tail
);
17397 /* Not found--return unchanged LIST. */
17401 /* Contribute ELT to the mode line for window IT->w. How it
17402 translates into text depends on its data type.
17404 IT describes the display environment in which we display, as usual.
17406 DEPTH is the depth in recursion. It is used to prevent
17407 infinite recursion here.
17409 FIELD_WIDTH is the number of characters the display of ELT should
17410 occupy in the mode line, and PRECISION is the maximum number of
17411 characters to display from ELT's representation. See
17412 display_string for details.
17414 Returns the hpos of the end of the text generated by ELT.
17416 PROPS is a property list to add to any string we encounter.
17418 If RISKY is nonzero, remove (disregard) any properties in any string
17419 we encounter, and ignore :eval and :propertize.
17421 The global variable `mode_line_target' determines whether the
17422 output is passed to `store_mode_line_noprop',
17423 `store_mode_line_string', or `display_string'. */
17426 display_mode_element (it
, depth
, field_width
, precision
, elt
, props
, risky
)
17429 int field_width
, precision
;
17430 Lisp_Object elt
, props
;
17433 int n
= 0, field
, prec
;
17438 elt
= build_string ("*too-deep*");
17442 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
17446 /* A string: output it and check for %-constructs within it. */
17450 if (SCHARS (elt
) > 0
17451 && (!NILP (props
) || risky
))
17453 Lisp_Object oprops
, aelt
;
17454 oprops
= Ftext_properties_at (make_number (0), elt
);
17456 /* If the starting string's properties are not what
17457 we want, translate the string. Also, if the string
17458 is risky, do that anyway. */
17460 if (NILP (Fequal (props
, oprops
)) || risky
)
17462 /* If the starting string has properties,
17463 merge the specified ones onto the existing ones. */
17464 if (! NILP (oprops
) && !risky
)
17468 oprops
= Fcopy_sequence (oprops
);
17470 while (CONSP (tem
))
17472 oprops
= Fplist_put (oprops
, XCAR (tem
),
17473 XCAR (XCDR (tem
)));
17474 tem
= XCDR (XCDR (tem
));
17479 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
17480 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
17482 /* AELT is what we want. Move it to the front
17483 without consing. */
17485 mode_line_proptrans_alist
17486 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
17492 /* If AELT has the wrong props, it is useless.
17493 so get rid of it. */
17495 mode_line_proptrans_alist
17496 = Fdelq (aelt
, mode_line_proptrans_alist
);
17498 elt
= Fcopy_sequence (elt
);
17499 Fset_text_properties (make_number (0), Flength (elt
),
17501 /* Add this item to mode_line_proptrans_alist. */
17502 mode_line_proptrans_alist
17503 = Fcons (Fcons (elt
, props
),
17504 mode_line_proptrans_alist
);
17505 /* Truncate mode_line_proptrans_alist
17506 to at most 50 elements. */
17507 tem
= Fnthcdr (make_number (50),
17508 mode_line_proptrans_alist
);
17510 XSETCDR (tem
, Qnil
);
17519 prec
= precision
- n
;
17520 switch (mode_line_target
)
17522 case MODE_LINE_NOPROP
:
17523 case MODE_LINE_TITLE
:
17524 n
+= store_mode_line_noprop (SDATA (elt
), -1, prec
);
17526 case MODE_LINE_STRING
:
17527 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
17529 case MODE_LINE_DISPLAY
:
17530 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
17531 0, prec
, 0, STRING_MULTIBYTE (elt
));
17538 /* Handle the non-literal case. */
17540 while ((precision
<= 0 || n
< precision
)
17541 && SREF (elt
, offset
) != 0
17542 && (mode_line_target
!= MODE_LINE_DISPLAY
17543 || it
->current_x
< it
->last_visible_x
))
17545 int last_offset
= offset
;
17547 /* Advance to end of string or next format specifier. */
17548 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
17551 if (offset
- 1 != last_offset
)
17553 int nchars
, nbytes
;
17555 /* Output to end of string or up to '%'. Field width
17556 is length of string. Don't output more than
17557 PRECISION allows us. */
17560 prec
= c_string_width (SDATA (elt
) + last_offset
,
17561 offset
- last_offset
, precision
- n
,
17564 switch (mode_line_target
)
17566 case MODE_LINE_NOPROP
:
17567 case MODE_LINE_TITLE
:
17568 n
+= store_mode_line_noprop (SDATA (elt
) + last_offset
, 0, prec
);
17570 case MODE_LINE_STRING
:
17572 int bytepos
= last_offset
;
17573 int charpos
= string_byte_to_char (elt
, bytepos
);
17574 int endpos
= (precision
<= 0
17575 ? string_byte_to_char (elt
, offset
)
17576 : charpos
+ nchars
);
17578 n
+= store_mode_line_string (NULL
,
17579 Fsubstring (elt
, make_number (charpos
),
17580 make_number (endpos
)),
17584 case MODE_LINE_DISPLAY
:
17586 int bytepos
= last_offset
;
17587 int charpos
= string_byte_to_char (elt
, bytepos
);
17589 if (precision
<= 0)
17590 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
17591 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
17593 STRING_MULTIBYTE (elt
));
17598 else /* c == '%' */
17600 int percent_position
= offset
;
17602 /* Get the specified minimum width. Zero means
17605 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
17606 field
= field
* 10 + c
- '0';
17608 /* Don't pad beyond the total padding allowed. */
17609 if (field_width
- n
> 0 && field
> field_width
- n
)
17610 field
= field_width
- n
;
17612 /* Note that either PRECISION <= 0 or N < PRECISION. */
17613 prec
= precision
- n
;
17616 n
+= display_mode_element (it
, depth
, field
, prec
,
17617 Vglobal_mode_string
, props
,
17622 int bytepos
, charpos
;
17623 unsigned char *spec
;
17625 bytepos
= percent_position
;
17626 charpos
= (STRING_MULTIBYTE (elt
)
17627 ? string_byte_to_char (elt
, bytepos
)
17630 = decode_mode_spec (it
->w
, c
, field
, prec
, &multibyte
);
17632 switch (mode_line_target
)
17634 case MODE_LINE_NOPROP
:
17635 case MODE_LINE_TITLE
:
17636 n
+= store_mode_line_noprop (spec
, field
, prec
);
17638 case MODE_LINE_STRING
:
17640 int len
= strlen (spec
);
17641 Lisp_Object tem
= make_string (spec
, len
);
17642 props
= Ftext_properties_at (make_number (charpos
), elt
);
17643 /* Should only keep face property in props */
17644 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
17647 case MODE_LINE_DISPLAY
:
17649 int nglyphs_before
, nwritten
;
17651 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
17652 nwritten
= display_string (spec
, Qnil
, elt
,
17657 /* Assign to the glyphs written above the
17658 string where the `%x' came from, position
17662 struct glyph
*glyph
17663 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
17667 for (i
= 0; i
< nwritten
; ++i
)
17669 glyph
[i
].object
= elt
;
17670 glyph
[i
].charpos
= charpos
;
17687 /* A symbol: process the value of the symbol recursively
17688 as if it appeared here directly. Avoid error if symbol void.
17689 Special case: if value of symbol is a string, output the string
17692 register Lisp_Object tem
;
17694 /* If the variable is not marked as risky to set
17695 then its contents are risky to use. */
17696 if (NILP (Fget (elt
, Qrisky_local_variable
)))
17699 tem
= Fboundp (elt
);
17702 tem
= Fsymbol_value (elt
);
17703 /* If value is a string, output that string literally:
17704 don't check for % within it. */
17708 if (!EQ (tem
, elt
))
17710 /* Give up right away for nil or t. */
17720 register Lisp_Object car
, tem
;
17722 /* A cons cell: five distinct cases.
17723 If first element is :eval or :propertize, do something special.
17724 If first element is a string or a cons, process all the elements
17725 and effectively concatenate them.
17726 If first element is a negative number, truncate displaying cdr to
17727 at most that many characters. If positive, pad (with spaces)
17728 to at least that many characters.
17729 If first element is a symbol, process the cadr or caddr recursively
17730 according to whether the symbol's value is non-nil or nil. */
17732 if (EQ (car
, QCeval
))
17734 /* An element of the form (:eval FORM) means evaluate FORM
17735 and use the result as mode line elements. */
17740 if (CONSP (XCDR (elt
)))
17743 spec
= safe_eval (XCAR (XCDR (elt
)));
17744 n
+= display_mode_element (it
, depth
, field_width
- n
,
17745 precision
- n
, spec
, props
,
17749 else if (EQ (car
, QCpropertize
))
17751 /* An element of the form (:propertize ELT PROPS...)
17752 means display ELT but applying properties PROPS. */
17757 if (CONSP (XCDR (elt
)))
17758 n
+= display_mode_element (it
, depth
, field_width
- n
,
17759 precision
- n
, XCAR (XCDR (elt
)),
17760 XCDR (XCDR (elt
)), risky
);
17762 else if (SYMBOLP (car
))
17764 tem
= Fboundp (car
);
17768 /* elt is now the cdr, and we know it is a cons cell.
17769 Use its car if CAR has a non-nil value. */
17772 tem
= Fsymbol_value (car
);
17779 /* Symbol's value is nil (or symbol is unbound)
17780 Get the cddr of the original list
17781 and if possible find the caddr and use that. */
17785 else if (!CONSP (elt
))
17790 else if (INTEGERP (car
))
17792 register int lim
= XINT (car
);
17796 /* Negative int means reduce maximum width. */
17797 if (precision
<= 0)
17800 precision
= min (precision
, -lim
);
17804 /* Padding specified. Don't let it be more than
17805 current maximum. */
17807 lim
= min (precision
, lim
);
17809 /* If that's more padding than already wanted, queue it.
17810 But don't reduce padding already specified even if
17811 that is beyond the current truncation point. */
17812 field_width
= max (lim
, field_width
);
17816 else if (STRINGP (car
) || CONSP (car
))
17818 register int limit
= 50;
17819 /* Limit is to protect against circular lists. */
17822 && (precision
<= 0 || n
< precision
))
17824 n
+= display_mode_element (it
, depth
,
17825 /* Do padding only after the last
17826 element in the list. */
17827 (! CONSP (XCDR (elt
))
17830 precision
- n
, XCAR (elt
),
17840 elt
= build_string ("*invalid*");
17844 /* Pad to FIELD_WIDTH. */
17845 if (field_width
> 0 && n
< field_width
)
17847 switch (mode_line_target
)
17849 case MODE_LINE_NOPROP
:
17850 case MODE_LINE_TITLE
:
17851 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
17853 case MODE_LINE_STRING
:
17854 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
17856 case MODE_LINE_DISPLAY
:
17857 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
17866 /* Store a mode-line string element in mode_line_string_list.
17868 If STRING is non-null, display that C string. Otherwise, the Lisp
17869 string LISP_STRING is displayed.
17871 FIELD_WIDTH is the minimum number of output glyphs to produce.
17872 If STRING has fewer characters than FIELD_WIDTH, pad to the right
17873 with spaces. FIELD_WIDTH <= 0 means don't pad.
17875 PRECISION is the maximum number of characters to output from
17876 STRING. PRECISION <= 0 means don't truncate the string.
17878 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
17879 properties to the string.
17881 PROPS are the properties to add to the string.
17882 The mode_line_string_face face property is always added to the string.
17886 store_mode_line_string (string
, lisp_string
, copy_string
, field_width
, precision
, props
)
17888 Lisp_Object lisp_string
;
17897 if (string
!= NULL
)
17899 len
= strlen (string
);
17900 if (precision
> 0 && len
> precision
)
17902 lisp_string
= make_string (string
, len
);
17904 props
= mode_line_string_face_prop
;
17905 else if (!NILP (mode_line_string_face
))
17907 Lisp_Object face
= Fplist_get (props
, Qface
);
17908 props
= Fcopy_sequence (props
);
17910 face
= mode_line_string_face
;
17912 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17913 props
= Fplist_put (props
, Qface
, face
);
17915 Fadd_text_properties (make_number (0), make_number (len
),
17916 props
, lisp_string
);
17920 len
= XFASTINT (Flength (lisp_string
));
17921 if (precision
> 0 && len
> precision
)
17924 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
17927 if (!NILP (mode_line_string_face
))
17931 props
= Ftext_properties_at (make_number (0), lisp_string
);
17932 face
= Fplist_get (props
, Qface
);
17934 face
= mode_line_string_face
;
17936 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
17937 props
= Fcons (Qface
, Fcons (face
, Qnil
));
17939 lisp_string
= Fcopy_sequence (lisp_string
);
17942 Fadd_text_properties (make_number (0), make_number (len
),
17943 props
, lisp_string
);
17948 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17952 if (field_width
> len
)
17954 field_width
-= len
;
17955 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
17957 Fadd_text_properties (make_number (0), make_number (field_width
),
17958 props
, lisp_string
);
17959 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
17967 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
17969 doc
: /* Format a string out of a mode line format specification.
17970 First arg FORMAT specifies the mode line format (see `mode-line-format'
17971 for details) to use.
17973 Optional second arg FACE specifies the face property to put
17974 on all characters for which no face is specified.
17975 The value t means whatever face the window's mode line currently uses
17976 \(either `mode-line' or `mode-line-inactive', depending).
17977 A value of nil means the default is no face property.
17978 If FACE is an integer, the value string has no text properties.
17980 Optional third and fourth args WINDOW and BUFFER specify the window
17981 and buffer to use as the context for the formatting (defaults
17982 are the selected window and the window's buffer). */)
17983 (format
, face
, window
, buffer
)
17984 Lisp_Object format
, face
, window
, buffer
;
17989 struct buffer
*old_buffer
= NULL
;
17991 int no_props
= INTEGERP (face
);
17992 int count
= SPECPDL_INDEX ();
17994 int string_start
= 0;
17997 window
= selected_window
;
17998 CHECK_WINDOW (window
);
17999 w
= XWINDOW (window
);
18002 buffer
= w
->buffer
;
18003 CHECK_BUFFER (buffer
);
18005 /* Make formatting the modeline a non-op when noninteractive, otherwise
18006 there will be problems later caused by a partially initialized frame. */
18007 if (NILP (format
) || noninteractive
)
18008 return empty_unibyte_string
;
18016 face
= (EQ (window
, selected_window
) ? Qmode_line
: Qmode_line_inactive
);
18017 face_id
= lookup_named_face (XFRAME (WINDOW_FRAME (w
)), face
, 0);
18021 face_id
= DEFAULT_FACE_ID
;
18023 if (XBUFFER (buffer
) != current_buffer
)
18024 old_buffer
= current_buffer
;
18026 /* Save things including mode_line_proptrans_alist,
18027 and set that to nil so that we don't alter the outer value. */
18028 record_unwind_protect (unwind_format_mode_line
,
18029 format_mode_line_unwind_data
18030 (old_buffer
, selected_window
, 1));
18031 mode_line_proptrans_alist
= Qnil
;
18033 Fselect_window (window
, Qt
);
18035 set_buffer_internal_1 (XBUFFER (buffer
));
18037 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
18041 mode_line_target
= MODE_LINE_NOPROP
;
18042 mode_line_string_face_prop
= Qnil
;
18043 mode_line_string_list
= Qnil
;
18044 string_start
= MODE_LINE_NOPROP_LEN (0);
18048 mode_line_target
= MODE_LINE_STRING
;
18049 mode_line_string_list
= Qnil
;
18050 mode_line_string_face
= face
;
18051 mode_line_string_face_prop
18052 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
18055 push_kboard (FRAME_KBOARD (it
.f
));
18056 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
18061 len
= MODE_LINE_NOPROP_LEN (string_start
);
18062 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
18066 mode_line_string_list
= Fnreverse (mode_line_string_list
);
18067 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
18068 empty_unibyte_string
);
18071 unbind_to (count
, Qnil
);
18075 /* Write a null-terminated, right justified decimal representation of
18076 the positive integer D to BUF using a minimal field width WIDTH. */
18079 pint2str (buf
, width
, d
)
18080 register char *buf
;
18081 register int width
;
18084 register char *p
= buf
;
18092 *p
++ = d
% 10 + '0';
18097 for (width
-= (int) (p
- buf
); width
> 0; --width
)
18108 /* Write a null-terminated, right justified decimal and "human
18109 readable" representation of the nonnegative integer D to BUF using
18110 a minimal field width WIDTH. D should be smaller than 999.5e24. */
18112 static const char power_letter
[] =
18126 pint2hrstr (buf
, width
, d
)
18131 /* We aim to represent the nonnegative integer D as
18132 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
18135 /* -1 means: do not use TENTHS. */
18139 /* Length of QUOTIENT.TENTHS as a string. */
18145 if (1000 <= quotient
)
18147 /* Scale to the appropriate EXPONENT. */
18150 remainder
= quotient
% 1000;
18154 while (1000 <= quotient
);
18156 /* Round to nearest and decide whether to use TENTHS or not. */
18159 tenths
= remainder
/ 100;
18160 if (50 <= remainder
% 100)
18167 if (quotient
== 10)
18175 if (500 <= remainder
)
18177 if (quotient
< 999)
18188 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
18189 if (tenths
== -1 && quotient
<= 99)
18196 p
= psuffix
= buf
+ max (width
, length
);
18198 /* Print EXPONENT. */
18200 *psuffix
++ = power_letter
[exponent
];
18203 /* Print TENTHS. */
18206 *--p
= '0' + tenths
;
18210 /* Print QUOTIENT. */
18213 int digit
= quotient
% 10;
18214 *--p
= '0' + digit
;
18216 while ((quotient
/= 10) != 0);
18218 /* Print leading spaces. */
18223 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
18224 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
18225 type of CODING_SYSTEM. Return updated pointer into BUF. */
18227 static unsigned char invalid_eol_type
[] = "(*invalid*)";
18230 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
18231 Lisp_Object coding_system
;
18232 register char *buf
;
18236 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
18237 const unsigned char *eol_str
;
18239 /* The EOL conversion we are using. */
18240 Lisp_Object eoltype
;
18242 val
= CODING_SYSTEM_SPEC (coding_system
);
18245 if (!VECTORP (val
)) /* Not yet decided. */
18250 eoltype
= eol_mnemonic_undecided
;
18251 /* Don't mention EOL conversion if it isn't decided. */
18256 Lisp_Object eolvalue
;
18258 attrs
= AREF (val
, 0);
18259 eolvalue
= AREF (val
, 2);
18262 *buf
++ = XFASTINT (CODING_ATTR_MNEMONIC (attrs
));
18266 /* The EOL conversion that is normal on this system. */
18268 if (NILP (eolvalue
)) /* Not yet decided. */
18269 eoltype
= eol_mnemonic_undecided
;
18270 else if (VECTORP (eolvalue
)) /* Not yet decided. */
18271 eoltype
= eol_mnemonic_undecided
;
18272 else /* eolvalue is Qunix, Qdos, or Qmac. */
18273 eoltype
= (EQ (eolvalue
, Qunix
)
18274 ? eol_mnemonic_unix
18275 : (EQ (eolvalue
, Qdos
) == 1
18276 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
18282 /* Mention the EOL conversion if it is not the usual one. */
18283 if (STRINGP (eoltype
))
18285 eol_str
= SDATA (eoltype
);
18286 eol_str_len
= SBYTES (eoltype
);
18288 else if (CHARACTERP (eoltype
))
18290 unsigned char *tmp
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
18291 eol_str_len
= CHAR_STRING (XINT (eoltype
), tmp
);
18296 eol_str
= invalid_eol_type
;
18297 eol_str_len
= sizeof (invalid_eol_type
) - 1;
18299 bcopy (eol_str
, buf
, eol_str_len
);
18300 buf
+= eol_str_len
;
18306 /* Return a string for the output of a mode line %-spec for window W,
18307 generated by character C. PRECISION >= 0 means don't return a
18308 string longer than that value. FIELD_WIDTH > 0 means pad the
18309 string returned with spaces to that value. Return 1 in *MULTIBYTE
18310 if the result is multibyte text.
18312 Note we operate on the current buffer for most purposes,
18313 the exception being w->base_line_pos. */
18315 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
18318 decode_mode_spec (w
, c
, field_width
, precision
, multibyte
)
18321 int field_width
, precision
;
18325 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18326 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
18327 struct buffer
*b
= current_buffer
;
18335 if (!NILP (b
->read_only
))
18337 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18342 /* This differs from %* only for a modified read-only buffer. */
18343 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18345 if (!NILP (b
->read_only
))
18350 /* This differs from %* in ignoring read-only-ness. */
18351 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
18363 if (command_loop_level
> 5)
18365 p
= decode_mode_spec_buf
;
18366 for (i
= 0; i
< command_loop_level
; i
++)
18369 return decode_mode_spec_buf
;
18377 if (command_loop_level
> 5)
18379 p
= decode_mode_spec_buf
;
18380 for (i
= 0; i
< command_loop_level
; i
++)
18383 return decode_mode_spec_buf
;
18390 /* Let lots_of_dashes be a string of infinite length. */
18391 if (mode_line_target
== MODE_LINE_NOPROP
||
18392 mode_line_target
== MODE_LINE_STRING
)
18394 if (field_width
<= 0
18395 || field_width
> sizeof (lots_of_dashes
))
18397 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
18398 decode_mode_spec_buf
[i
] = '-';
18399 decode_mode_spec_buf
[i
] = '\0';
18400 return decode_mode_spec_buf
;
18403 return lots_of_dashes
;
18411 /* %c and %l are ignored in `frame-title-format'.
18412 (In redisplay_internal, the frame title is drawn _before_ the
18413 windows are updated, so the stuff which depends on actual
18414 window contents (such as %l) may fail to render properly, or
18415 even crash emacs.) */
18416 if (mode_line_target
== MODE_LINE_TITLE
)
18420 int col
= (int) current_column (); /* iftc */
18421 w
->column_number_displayed
= make_number (col
);
18422 pint2str (decode_mode_spec_buf
, field_width
, col
);
18423 return decode_mode_spec_buf
;
18427 #ifndef SYSTEM_MALLOC
18429 if (NILP (Vmemory_full
))
18432 return "!MEM FULL! ";
18439 /* %F displays the frame name. */
18440 if (!NILP (f
->title
))
18441 return (char *) SDATA (f
->title
);
18442 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
18443 return (char *) SDATA (f
->name
);
18452 int size
= ZV
- BEGV
;
18453 pint2str (decode_mode_spec_buf
, field_width
, size
);
18454 return decode_mode_spec_buf
;
18459 int size
= ZV
- BEGV
;
18460 pint2hrstr (decode_mode_spec_buf
, field_width
, size
);
18461 return decode_mode_spec_buf
;
18466 int startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
18467 int topline
, nlines
, junk
, height
;
18469 /* %c and %l are ignored in `frame-title-format'. */
18470 if (mode_line_target
== MODE_LINE_TITLE
)
18473 startpos
= XMARKER (w
->start
)->charpos
;
18474 startpos_byte
= marker_byte_position (w
->start
);
18475 height
= WINDOW_TOTAL_LINES (w
);
18477 /* If we decided that this buffer isn't suitable for line numbers,
18478 don't forget that too fast. */
18479 if (EQ (w
->base_line_pos
, w
->buffer
))
18481 /* But do forget it, if the window shows a different buffer now. */
18482 else if (BUFFERP (w
->base_line_pos
))
18483 w
->base_line_pos
= Qnil
;
18485 /* If the buffer is very big, don't waste time. */
18486 if (INTEGERP (Vline_number_display_limit
)
18487 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
18489 w
->base_line_pos
= Qnil
;
18490 w
->base_line_number
= Qnil
;
18494 if (INTEGERP (w
->base_line_number
)
18495 && INTEGERP (w
->base_line_pos
)
18496 && XFASTINT (w
->base_line_pos
) <= startpos
)
18498 line
= XFASTINT (w
->base_line_number
);
18499 linepos
= XFASTINT (w
->base_line_pos
);
18500 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
18505 linepos
= BUF_BEGV (b
);
18506 linepos_byte
= BUF_BEGV_BYTE (b
);
18509 /* Count lines from base line to window start position. */
18510 nlines
= display_count_lines (linepos
, linepos_byte
,
18514 topline
= nlines
+ line
;
18516 /* Determine a new base line, if the old one is too close
18517 or too far away, or if we did not have one.
18518 "Too close" means it's plausible a scroll-down would
18519 go back past it. */
18520 if (startpos
== BUF_BEGV (b
))
18522 w
->base_line_number
= make_number (topline
);
18523 w
->base_line_pos
= make_number (BUF_BEGV (b
));
18525 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
18526 || linepos
== BUF_BEGV (b
))
18528 int limit
= BUF_BEGV (b
);
18529 int limit_byte
= BUF_BEGV_BYTE (b
);
18531 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
18533 if (startpos
- distance
> limit
)
18535 limit
= startpos
- distance
;
18536 limit_byte
= CHAR_TO_BYTE (limit
);
18539 nlines
= display_count_lines (startpos
, startpos_byte
,
18541 - (height
* 2 + 30),
18543 /* If we couldn't find the lines we wanted within
18544 line_number_display_limit_width chars per line,
18545 give up on line numbers for this window. */
18546 if (position
== limit_byte
&& limit
== startpos
- distance
)
18548 w
->base_line_pos
= w
->buffer
;
18549 w
->base_line_number
= Qnil
;
18553 w
->base_line_number
= make_number (topline
- nlines
);
18554 w
->base_line_pos
= make_number (BYTE_TO_CHAR (position
));
18557 /* Now count lines from the start pos to point. */
18558 nlines
= display_count_lines (startpos
, startpos_byte
,
18559 PT_BYTE
, PT
, &junk
);
18561 /* Record that we did display the line number. */
18562 line_number_displayed
= 1;
18564 /* Make the string to show. */
18565 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
18566 return decode_mode_spec_buf
;
18569 char* p
= decode_mode_spec_buf
;
18570 int pad
= field_width
- 2;
18576 return decode_mode_spec_buf
;
18582 obj
= b
->mode_name
;
18586 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
18592 int pos
= marker_position (w
->start
);
18593 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18595 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
18597 if (pos
<= BUF_BEGV (b
))
18602 else if (pos
<= BUF_BEGV (b
))
18606 if (total
> 1000000)
18607 /* Do it differently for a large value, to avoid overflow. */
18608 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18610 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18611 /* We can't normally display a 3-digit number,
18612 so get us a 2-digit number that is close. */
18615 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18616 return decode_mode_spec_buf
;
18620 /* Display percentage of size above the bottom of the screen. */
18623 int toppos
= marker_position (w
->start
);
18624 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
18625 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
18627 if (botpos
>= BUF_ZV (b
))
18629 if (toppos
<= BUF_BEGV (b
))
18636 if (total
> 1000000)
18637 /* Do it differently for a large value, to avoid overflow. */
18638 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
18640 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
18641 /* We can't normally display a 3-digit number,
18642 so get us a 2-digit number that is close. */
18645 if (toppos
<= BUF_BEGV (b
))
18646 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
18648 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
18649 return decode_mode_spec_buf
;
18654 /* status of process */
18655 obj
= Fget_buffer_process (Fcurrent_buffer ());
18657 return "no process";
18658 #ifdef subprocesses
18659 obj
= Fsymbol_name (Fprocess_status (obj
));
18666 val
= call1 (intern ("file-remote-p"), current_buffer
->directory
);
18673 case 't': /* indicate TEXT or BINARY */
18674 #ifdef MODE_LINE_BINARY_TEXT
18675 return MODE_LINE_BINARY_TEXT (b
);
18681 /* coding-system (not including end-of-line format) */
18683 /* coding-system (including end-of-line type) */
18685 int eol_flag
= (c
== 'Z');
18686 char *p
= decode_mode_spec_buf
;
18688 if (! FRAME_WINDOW_P (f
))
18690 /* No need to mention EOL here--the terminal never needs
18691 to do EOL conversion. */
18692 p
= decode_mode_spec_coding (CODING_ID_NAME
18693 (FRAME_KEYBOARD_CODING (f
)->id
),
18695 p
= decode_mode_spec_coding (CODING_ID_NAME
18696 (FRAME_TERMINAL_CODING (f
)->id
),
18699 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
18702 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
18703 #ifdef subprocesses
18704 obj
= Fget_buffer_process (Fcurrent_buffer ());
18705 if (PROCESSP (obj
))
18707 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
18709 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
18712 #endif /* subprocesses */
18715 return decode_mode_spec_buf
;
18721 *multibyte
= STRING_MULTIBYTE (obj
);
18722 return (char *) SDATA (obj
);
18729 /* Count up to COUNT lines starting from START / START_BYTE.
18730 But don't go beyond LIMIT_BYTE.
18731 Return the number of lines thus found (always nonnegative).
18733 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
18736 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
18737 int start
, start_byte
, limit_byte
, count
;
18740 register unsigned char *cursor
;
18741 unsigned char *base
;
18743 register int ceiling
;
18744 register unsigned char *ceiling_addr
;
18745 int orig_count
= count
;
18747 /* If we are not in selective display mode,
18748 check only for newlines. */
18749 int selective_display
= (!NILP (current_buffer
->selective_display
)
18750 && !INTEGERP (current_buffer
->selective_display
));
18754 while (start_byte
< limit_byte
)
18756 ceiling
= BUFFER_CEILING_OF (start_byte
);
18757 ceiling
= min (limit_byte
- 1, ceiling
);
18758 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
18759 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
18762 if (selective_display
)
18763 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
18766 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
18769 if (cursor
!= ceiling_addr
)
18773 start_byte
+= cursor
- base
+ 1;
18774 *byte_pos_ptr
= start_byte
;
18778 if (++cursor
== ceiling_addr
)
18784 start_byte
+= cursor
- base
;
18789 while (start_byte
> limit_byte
)
18791 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
18792 ceiling
= max (limit_byte
, ceiling
);
18793 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
18794 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
18797 if (selective_display
)
18798 while (--cursor
!= ceiling_addr
18799 && *cursor
!= '\n' && *cursor
!= 015)
18802 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
18805 if (cursor
!= ceiling_addr
)
18809 start_byte
+= cursor
- base
+ 1;
18810 *byte_pos_ptr
= start_byte
;
18811 /* When scanning backwards, we should
18812 not count the newline posterior to which we stop. */
18813 return - orig_count
- 1;
18819 /* Here we add 1 to compensate for the last decrement
18820 of CURSOR, which took it past the valid range. */
18821 start_byte
+= cursor
- base
+ 1;
18825 *byte_pos_ptr
= limit_byte
;
18828 return - orig_count
+ count
;
18829 return orig_count
- count
;
18835 /***********************************************************************
18837 ***********************************************************************/
18839 /* Display a NUL-terminated string, starting with index START.
18841 If STRING is non-null, display that C string. Otherwise, the Lisp
18842 string LISP_STRING is displayed.
18844 If FACE_STRING is not nil, FACE_STRING_POS is a position in
18845 FACE_STRING. Display STRING or LISP_STRING with the face at
18846 FACE_STRING_POS in FACE_STRING:
18848 Display the string in the environment given by IT, but use the
18849 standard display table, temporarily.
18851 FIELD_WIDTH is the minimum number of output glyphs to produce.
18852 If STRING has fewer characters than FIELD_WIDTH, pad to the right
18853 with spaces. If STRING has more characters, more than FIELD_WIDTH
18854 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
18856 PRECISION is the maximum number of characters to output from
18857 STRING. PRECISION < 0 means don't truncate the string.
18859 This is roughly equivalent to printf format specifiers:
18861 FIELD_WIDTH PRECISION PRINTF
18862 ----------------------------------------
18868 MULTIBYTE zero means do not display multibyte chars, > 0 means do
18869 display them, and < 0 means obey the current buffer's value of
18870 enable_multibyte_characters.
18872 Value is the number of columns displayed. */
18875 display_string (string
, lisp_string
, face_string
, face_string_pos
,
18876 start
, it
, field_width
, precision
, max_x
, multibyte
)
18877 unsigned char *string
;
18878 Lisp_Object lisp_string
;
18879 Lisp_Object face_string
;
18880 EMACS_INT face_string_pos
;
18883 int field_width
, precision
, max_x
;
18886 int hpos_at_start
= it
->hpos
;
18887 int saved_face_id
= it
->face_id
;
18888 struct glyph_row
*row
= it
->glyph_row
;
18890 /* Initialize the iterator IT for iteration over STRING beginning
18891 with index START. */
18892 reseat_to_string (it
, string
, lisp_string
, start
,
18893 precision
, field_width
, multibyte
);
18895 /* If displaying STRING, set up the face of the iterator
18896 from LISP_STRING, if that's given. */
18897 if (STRINGP (face_string
))
18903 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
18904 0, it
->region_beg_charpos
,
18905 it
->region_end_charpos
,
18906 &endptr
, it
->base_face_id
, 0);
18907 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18908 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
18911 /* Set max_x to the maximum allowed X position. Don't let it go
18912 beyond the right edge of the window. */
18914 max_x
= it
->last_visible_x
;
18916 max_x
= min (max_x
, it
->last_visible_x
);
18918 /* Skip over display elements that are not visible. because IT->w is
18920 if (it
->current_x
< it
->first_visible_x
)
18921 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
18922 MOVE_TO_POS
| MOVE_TO_X
);
18924 row
->ascent
= it
->max_ascent
;
18925 row
->height
= it
->max_ascent
+ it
->max_descent
;
18926 row
->phys_ascent
= it
->max_phys_ascent
;
18927 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18928 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18930 /* This condition is for the case that we are called with current_x
18931 past last_visible_x. */
18932 while (it
->current_x
< max_x
)
18934 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
18936 /* Get the next display element. */
18937 if (!get_next_display_element (it
))
18940 /* Produce glyphs. */
18941 x_before
= it
->current_x
;
18942 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
18943 PRODUCE_GLYPHS (it
);
18945 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
18948 while (i
< nglyphs
)
18950 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
18952 if (it
->line_wrap
!= TRUNCATE
18953 && x
+ glyph
->pixel_width
> max_x
)
18955 /* End of continued line or max_x reached. */
18956 if (CHAR_GLYPH_PADDING_P (*glyph
))
18958 /* A wide character is unbreakable. */
18959 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18960 it
->current_x
= x_before
;
18964 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
18969 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
18971 /* Glyph is at least partially visible. */
18973 if (x
< it
->first_visible_x
)
18974 it
->glyph_row
->x
= x
- it
->first_visible_x
;
18978 /* Glyph is off the left margin of the display area.
18979 Should not happen. */
18983 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
18984 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
18985 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
18986 row
->phys_height
= max (row
->phys_height
,
18987 it
->max_phys_ascent
+ it
->max_phys_descent
);
18988 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
18989 it
->max_extra_line_spacing
);
18990 x
+= glyph
->pixel_width
;
18994 /* Stop if max_x reached. */
18998 /* Stop at line ends. */
18999 if (ITERATOR_AT_END_OF_LINE_P (it
))
19001 it
->continuation_lines_width
= 0;
19005 set_iterator_to_next (it
, 1);
19007 /* Stop if truncating at the right edge. */
19008 if (it
->line_wrap
== TRUNCATE
19009 && it
->current_x
>= it
->last_visible_x
)
19011 /* Add truncation mark, but don't do it if the line is
19012 truncated at a padding space. */
19013 if (IT_CHARPOS (*it
) < it
->string_nchars
)
19015 if (!FRAME_WINDOW_P (it
->f
))
19019 if (it
->current_x
> it
->last_visible_x
)
19021 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19022 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19024 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19026 row
->used
[TEXT_AREA
] = i
;
19027 produce_special_glyphs (it
, IT_TRUNCATION
);
19030 produce_special_glyphs (it
, IT_TRUNCATION
);
19032 it
->glyph_row
->truncated_on_right_p
= 1;
19038 /* Maybe insert a truncation at the left. */
19039 if (it
->first_visible_x
19040 && IT_CHARPOS (*it
) > 0)
19042 if (!FRAME_WINDOW_P (it
->f
))
19043 insert_left_trunc_glyphs (it
);
19044 it
->glyph_row
->truncated_on_left_p
= 1;
19047 it
->face_id
= saved_face_id
;
19049 /* Value is number of columns displayed. */
19050 return it
->hpos
- hpos_at_start
;
19055 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
19056 appears as an element of LIST or as the car of an element of LIST.
19057 If PROPVAL is a list, compare each element against LIST in that
19058 way, and return 1/2 if any element of PROPVAL is found in LIST.
19059 Otherwise return 0. This function cannot quit.
19060 The return value is 2 if the text is invisible but with an ellipsis
19061 and 1 if it's invisible and without an ellipsis. */
19064 invisible_p (propval
, list
)
19065 register Lisp_Object propval
;
19068 register Lisp_Object tail
, proptail
;
19070 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19072 register Lisp_Object tem
;
19074 if (EQ (propval
, tem
))
19076 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
19077 return NILP (XCDR (tem
)) ? 1 : 2;
19080 if (CONSP (propval
))
19082 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
19084 Lisp_Object propelt
;
19085 propelt
= XCAR (proptail
);
19086 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
19088 register Lisp_Object tem
;
19090 if (EQ (propelt
, tem
))
19092 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
19093 return NILP (XCDR (tem
)) ? 1 : 2;
19101 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
19102 doc
: /* Non-nil if the property makes the text invisible.
19103 POS-OR-PROP can be a marker or number, in which case it is taken to be
19104 a position in the current buffer and the value of the `invisible' property
19105 is checked; or it can be some other value, which is then presumed to be the
19106 value of the `invisible' property of the text of interest.
19107 The non-nil value returned can be t for truly invisible text or something
19108 else if the text is replaced by an ellipsis. */)
19110 Lisp_Object pos_or_prop
;
19113 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
19114 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
19116 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
19117 return (invis
== 0 ? Qnil
19119 : make_number (invis
));
19122 /* Calculate a width or height in pixels from a specification using
19123 the following elements:
19126 NUM - a (fractional) multiple of the default font width/height
19127 (NUM) - specifies exactly NUM pixels
19128 UNIT - a fixed number of pixels, see below.
19129 ELEMENT - size of a display element in pixels, see below.
19130 (NUM . SPEC) - equals NUM * SPEC
19131 (+ SPEC SPEC ...) - add pixel values
19132 (- SPEC SPEC ...) - subtract pixel values
19133 (- SPEC) - negate pixel value
19136 INT or FLOAT - a number constant
19137 SYMBOL - use symbol's (buffer local) variable binding.
19140 in - pixels per inch *)
19141 mm - pixels per 1/1000 meter *)
19142 cm - pixels per 1/100 meter *)
19143 width - width of current font in pixels.
19144 height - height of current font in pixels.
19146 *) using the ratio(s) defined in display-pixels-per-inch.
19150 left-fringe - left fringe width in pixels
19151 right-fringe - right fringe width in pixels
19153 left-margin - left margin width in pixels
19154 right-margin - right margin width in pixels
19156 scroll-bar - scroll-bar area width in pixels
19160 Pixels corresponding to 5 inches:
19163 Total width of non-text areas on left side of window (if scroll-bar is on left):
19164 '(space :width (+ left-fringe left-margin scroll-bar))
19166 Align to first text column (in header line):
19167 '(space :align-to 0)
19169 Align to middle of text area minus half the width of variable `my-image'
19170 containing a loaded image:
19171 '(space :align-to (0.5 . (- text my-image)))
19173 Width of left margin minus width of 1 character in the default font:
19174 '(space :width (- left-margin 1))
19176 Width of left margin minus width of 2 characters in the current font:
19177 '(space :width (- left-margin (2 . width)))
19179 Center 1 character over left-margin (in header line):
19180 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
19182 Different ways to express width of left fringe plus left margin minus one pixel:
19183 '(space :width (- (+ left-fringe left-margin) (1)))
19184 '(space :width (+ left-fringe left-margin (- (1))))
19185 '(space :width (+ left-fringe left-margin (-1)))
19189 #define NUMVAL(X) \
19190 ((INTEGERP (X) || FLOATP (X)) \
19195 calc_pixel_width_or_height (res
, it
, prop
, font
, width_p
, align_to
)
19200 int width_p
, *align_to
;
19204 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
19205 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
19208 return OK_PIXELS (0);
19210 xassert (FRAME_LIVE_P (it
->f
));
19212 if (SYMBOLP (prop
))
19214 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
19216 char *unit
= SDATA (SYMBOL_NAME (prop
));
19218 if (unit
[0] == 'i' && unit
[1] == 'n')
19220 else if (unit
[0] == 'm' && unit
[1] == 'm')
19222 else if (unit
[0] == 'c' && unit
[1] == 'm')
19229 #ifdef HAVE_WINDOW_SYSTEM
19230 if (FRAME_WINDOW_P (it
->f
)
19232 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
19233 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
19235 return OK_PIXELS (ppi
/ pixels
);
19238 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
19239 || (CONSP (Vdisplay_pixels_per_inch
)
19241 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
19242 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
19244 return OK_PIXELS (ppi
/ pixels
);
19250 #ifdef HAVE_WINDOW_SYSTEM
19251 if (EQ (prop
, Qheight
))
19252 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
19253 if (EQ (prop
, Qwidth
))
19254 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
19256 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
19257 return OK_PIXELS (1);
19260 if (EQ (prop
, Qtext
))
19261 return OK_PIXELS (width_p
19262 ? window_box_width (it
->w
, TEXT_AREA
)
19263 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
19265 if (align_to
&& *align_to
< 0)
19268 if (EQ (prop
, Qleft
))
19269 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
19270 if (EQ (prop
, Qright
))
19271 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
19272 if (EQ (prop
, Qcenter
))
19273 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
19274 + window_box_width (it
->w
, TEXT_AREA
) / 2);
19275 if (EQ (prop
, Qleft_fringe
))
19276 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19277 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
19278 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
19279 if (EQ (prop
, Qright_fringe
))
19280 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19281 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19282 : window_box_right_offset (it
->w
, TEXT_AREA
));
19283 if (EQ (prop
, Qleft_margin
))
19284 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
19285 if (EQ (prop
, Qright_margin
))
19286 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
19287 if (EQ (prop
, Qscroll_bar
))
19288 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
19290 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
19291 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
19292 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19297 if (EQ (prop
, Qleft_fringe
))
19298 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
19299 if (EQ (prop
, Qright_fringe
))
19300 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
19301 if (EQ (prop
, Qleft_margin
))
19302 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
19303 if (EQ (prop
, Qright_margin
))
19304 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
19305 if (EQ (prop
, Qscroll_bar
))
19306 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
19309 prop
= Fbuffer_local_value (prop
, it
->w
->buffer
);
19312 if (INTEGERP (prop
) || FLOATP (prop
))
19314 int base_unit
= (width_p
19315 ? FRAME_COLUMN_WIDTH (it
->f
)
19316 : FRAME_LINE_HEIGHT (it
->f
));
19317 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
19322 Lisp_Object car
= XCAR (prop
);
19323 Lisp_Object cdr
= XCDR (prop
);
19327 #ifdef HAVE_WINDOW_SYSTEM
19328 if (FRAME_WINDOW_P (it
->f
)
19329 && valid_image_p (prop
))
19331 int id
= lookup_image (it
->f
, prop
);
19332 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
19334 return OK_PIXELS (width_p
? img
->width
: img
->height
);
19337 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
19343 while (CONSP (cdr
))
19345 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
19346 font
, width_p
, align_to
))
19349 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
19354 if (EQ (car
, Qminus
))
19356 return OK_PIXELS (pixels
);
19359 car
= Fbuffer_local_value (car
, it
->w
->buffer
);
19362 if (INTEGERP (car
) || FLOATP (car
))
19365 pixels
= XFLOATINT (car
);
19367 return OK_PIXELS (pixels
);
19368 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
19369 font
, width_p
, align_to
))
19370 return OK_PIXELS (pixels
* fact
);
19381 /***********************************************************************
19383 ***********************************************************************/
19385 #ifdef HAVE_WINDOW_SYSTEM
19390 dump_glyph_string (s
)
19391 struct glyph_string
*s
;
19393 fprintf (stderr
, "glyph string\n");
19394 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
19395 s
->x
, s
->y
, s
->width
, s
->height
);
19396 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
19397 fprintf (stderr
, " hl = %d\n", s
->hl
);
19398 fprintf (stderr
, " left overhang = %d, right = %d\n",
19399 s
->left_overhang
, s
->right_overhang
);
19400 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
19401 fprintf (stderr
, " extends to end of line = %d\n",
19402 s
->extends_to_end_of_line_p
);
19403 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
19404 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
19407 #endif /* GLYPH_DEBUG */
19409 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
19410 of XChar2b structures for S; it can't be allocated in
19411 init_glyph_string because it must be allocated via `alloca'. W
19412 is the window on which S is drawn. ROW and AREA are the glyph row
19413 and area within the row from which S is constructed. START is the
19414 index of the first glyph structure covered by S. HL is a
19415 face-override for drawing S. */
19418 #define OPTIONAL_HDC(hdc) hdc,
19419 #define DECLARE_HDC(hdc) HDC hdc;
19420 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
19421 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
19424 #ifndef OPTIONAL_HDC
19425 #define OPTIONAL_HDC(hdc)
19426 #define DECLARE_HDC(hdc)
19427 #define ALLOCATE_HDC(hdc, f)
19428 #define RELEASE_HDC(hdc, f)
19432 init_glyph_string (s
, OPTIONAL_HDC (hdc
) char2b
, w
, row
, area
, start
, hl
)
19433 struct glyph_string
*s
;
19437 struct glyph_row
*row
;
19438 enum glyph_row_area area
;
19440 enum draw_glyphs_face hl
;
19442 bzero (s
, sizeof *s
);
19444 s
->f
= XFRAME (w
->frame
);
19448 s
->display
= FRAME_X_DISPLAY (s
->f
);
19449 s
->window
= FRAME_X_WINDOW (s
->f
);
19450 s
->char2b
= char2b
;
19454 s
->first_glyph
= row
->glyphs
[area
] + start
;
19455 s
->height
= row
->height
;
19456 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
19458 /* Display the internal border below the tool-bar window. */
19459 if (WINDOWP (s
->f
->tool_bar_window
)
19460 && s
->w
== XWINDOW (s
->f
->tool_bar_window
))
19461 s
->y
-= FRAME_INTERNAL_BORDER_WIDTH (s
->f
);
19463 s
->ybase
= s
->y
+ row
->ascent
;
19467 /* Append the list of glyph strings with head H and tail T to the list
19468 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
19471 append_glyph_string_lists (head
, tail
, h
, t
)
19472 struct glyph_string
**head
, **tail
;
19473 struct glyph_string
*h
, *t
;
19487 /* Prepend the list of glyph strings with head H and tail T to the
19488 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
19492 prepend_glyph_string_lists (head
, tail
, h
, t
)
19493 struct glyph_string
**head
, **tail
;
19494 struct glyph_string
*h
, *t
;
19508 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
19509 Set *HEAD and *TAIL to the resulting list. */
19512 append_glyph_string (head
, tail
, s
)
19513 struct glyph_string
**head
, **tail
;
19514 struct glyph_string
*s
;
19516 s
->next
= s
->prev
= NULL
;
19517 append_glyph_string_lists (head
, tail
, s
, s
);
19521 /* Get face and two-byte form of character C in face FACE_ID on frame
19522 F. The encoding of C is returned in *CHAR2B. MULTIBYTE_P non-zero
19523 means we want to display multibyte text. DISPLAY_P non-zero means
19524 make sure that X resources for the face returned are allocated.
19525 Value is a pointer to a realized face that is ready for display if
19526 DISPLAY_P is non-zero. */
19528 static INLINE
struct face
*
19529 get_char_face_and_encoding (f
, c
, face_id
, char2b
, multibyte_p
, display_p
)
19533 int multibyte_p
, display_p
;
19535 struct face
*face
= FACE_FROM_ID (f
, face_id
);
19539 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
19541 if (code
!= FONT_INVALID_CODE
)
19542 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19544 STORE_XCHAR2B (char2b
, 0, 0);
19547 /* Make sure X resources of the face are allocated. */
19548 #ifdef HAVE_X_WINDOWS
19552 xassert (face
!= NULL
);
19553 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19560 /* Get face and two-byte form of character glyph GLYPH on frame F.
19561 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
19562 a pointer to a realized face that is ready for display. */
19564 static INLINE
struct face
*
19565 get_glyph_face_and_encoding (f
, glyph
, char2b
, two_byte_p
)
19567 struct glyph
*glyph
;
19573 xassert (glyph
->type
== CHAR_GLYPH
);
19574 face
= FACE_FROM_ID (f
, glyph
->face_id
);
19581 unsigned code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
19583 if (code
!= FONT_INVALID_CODE
)
19584 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
19586 STORE_XCHAR2B (char2b
, 0, 0);
19589 /* Make sure X resources of the face are allocated. */
19590 xassert (face
!= NULL
);
19591 PREPARE_FACE_FOR_DISPLAY (f
, face
);
19596 /* Fill glyph string S with composition components specified by S->cmp.
19598 BASE_FACE is the base face of the composition.
19599 S->gidx is the index of the first component for S.
19601 OVERLAPS non-zero means S should draw the foreground only, and use
19602 its physical height for clipping. See also draw_glyphs.
19604 Value is the index of a component not in S. */
19607 fill_composite_glyph_string (s
, base_face
, overlaps
)
19608 struct glyph_string
*s
;
19609 struct face
*base_face
;
19616 s
->for_overlaps
= overlaps
;
19618 if (s
->cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
19620 Lisp_Object gstring
19621 = AREF (XHASH_TABLE (composition_hash_table
)->key_and_value
,
19622 s
->cmp
->hash_index
* 2);
19624 s
->face
= base_face
;
19625 s
->font
= base_face
->font
;
19626 for (i
= 0, s
->nchars
= 0; i
< s
->cmp
->glyph_len
; i
++, s
->nchars
++)
19628 Lisp_Object g
= LGSTRING_GLYPH (gstring
, i
);
19630 XChar2b
* store_pos
;
19633 code
= LGLYPH_CODE (g
);
19634 store_pos
= s
->char2b
+ i
;
19635 STORE_XCHAR2B (store_pos
, code
>> 8, code
& 0xFF);
19637 s
->width
= s
->cmp
->pixel_width
;
19641 /* For all glyphs of this composition, starting at the offset
19642 S->gidx, until we reach the end of the definition or encounter a
19643 glyph that requires the different face, add it to S. */
19648 for (i
= s
->gidx
; i
< s
->cmp
->glyph_len
; i
++)
19650 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
19654 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
19657 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
19658 s
->char2b
+ i
, 1, 1);
19664 s
->font
= s
->face
->font
;
19666 else if (s
->face
!= face
)
19673 /* All glyph strings for the same composition has the same width,
19674 i.e. the width set for the first component of the composition. */
19675 s
->width
= s
->first_glyph
->pixel_width
;
19678 /* If the specified font could not be loaded, use the frame's
19679 default font, but record the fact that we couldn't load it in
19680 the glyph string so that we can draw rectangles for the
19681 characters of the glyph string. */
19682 if (s
->font
== NULL
)
19684 s
->font_not_found_p
= 1;
19685 s
->font
= FRAME_FONT (s
->f
);
19688 /* Adjust base line for subscript/superscript text. */
19689 s
->ybase
+= s
->first_glyph
->voffset
;
19691 /* This glyph string must always be drawn with 16-bit functions. */
19694 return s
->gidx
+ s
->nchars
;
19698 /* Fill glyph string S from a sequence of character glyphs.
19700 FACE_ID is the face id of the string. START is the index of the
19701 first glyph to consider, END is the index of the last + 1.
19702 OVERLAPS non-zero means S should draw the foreground only, and use
19703 its physical height for clipping. See also draw_glyphs.
19705 Value is the index of the first glyph not in S. */
19708 fill_glyph_string (s
, face_id
, start
, end
, overlaps
)
19709 struct glyph_string
*s
;
19711 int start
, end
, overlaps
;
19713 struct glyph
*glyph
, *last
;
19715 int glyph_not_available_p
;
19717 xassert (s
->f
== XFRAME (s
->w
->frame
));
19718 xassert (s
->nchars
== 0);
19719 xassert (start
>= 0 && end
> start
);
19721 s
->for_overlaps
= overlaps
,
19722 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19723 last
= s
->row
->glyphs
[s
->area
] + end
;
19724 voffset
= glyph
->voffset
;
19725 s
->padding_p
= glyph
->padding_p
;
19726 glyph_not_available_p
= glyph
->glyph_not_available_p
;
19728 while (glyph
< last
19729 && glyph
->type
== CHAR_GLYPH
19730 && glyph
->voffset
== voffset
19731 /* Same face id implies same font, nowadays. */
19732 && glyph
->face_id
== face_id
19733 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
19737 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
19738 s
->char2b
+ s
->nchars
,
19740 s
->two_byte_p
= two_byte_p
;
19742 xassert (s
->nchars
<= end
- start
);
19743 s
->width
+= glyph
->pixel_width
;
19744 if (glyph
++->padding_p
!= s
->padding_p
)
19748 s
->font
= s
->face
->font
;
19750 /* If the specified font could not be loaded, use the frame's font,
19751 but record the fact that we couldn't load it in
19752 S->font_not_found_p so that we can draw rectangles for the
19753 characters of the glyph string. */
19754 if (s
->font
== NULL
|| glyph_not_available_p
)
19756 s
->font_not_found_p
= 1;
19757 s
->font
= FRAME_FONT (s
->f
);
19760 /* Adjust base line for subscript/superscript text. */
19761 s
->ybase
+= voffset
;
19763 xassert (s
->face
&& s
->face
->gc
);
19764 return glyph
- s
->row
->glyphs
[s
->area
];
19768 /* Fill glyph string S from image glyph S->first_glyph. */
19771 fill_image_glyph_string (s
)
19772 struct glyph_string
*s
;
19774 xassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
19775 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
19777 s
->slice
= s
->first_glyph
->slice
;
19778 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
19779 s
->font
= s
->face
->font
;
19780 s
->width
= s
->first_glyph
->pixel_width
;
19782 /* Adjust base line for subscript/superscript text. */
19783 s
->ybase
+= s
->first_glyph
->voffset
;
19787 /* Fill glyph string S from a sequence of stretch glyphs.
19789 ROW is the glyph row in which the glyphs are found, AREA is the
19790 area within the row. START is the index of the first glyph to
19791 consider, END is the index of the last + 1.
19793 Value is the index of the first glyph not in S. */
19796 fill_stretch_glyph_string (s
, row
, area
, start
, end
)
19797 struct glyph_string
*s
;
19798 struct glyph_row
*row
;
19799 enum glyph_row_area area
;
19802 struct glyph
*glyph
, *last
;
19803 int voffset
, face_id
;
19805 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
19807 glyph
= s
->row
->glyphs
[s
->area
] + start
;
19808 last
= s
->row
->glyphs
[s
->area
] + end
;
19809 face_id
= glyph
->face_id
;
19810 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
19811 s
->font
= s
->face
->font
;
19812 s
->width
= glyph
->pixel_width
;
19814 voffset
= glyph
->voffset
;
19818 && glyph
->type
== STRETCH_GLYPH
19819 && glyph
->voffset
== voffset
19820 && glyph
->face_id
== face_id
);
19822 s
->width
+= glyph
->pixel_width
;
19824 /* Adjust base line for subscript/superscript text. */
19825 s
->ybase
+= voffset
;
19827 /* The case that face->gc == 0 is handled when drawing the glyph
19828 string by calling PREPARE_FACE_FOR_DISPLAY. */
19830 return glyph
- s
->row
->glyphs
[s
->area
];
19833 static struct font_metrics
*
19834 get_per_char_metric (f
, font
, char2b
)
19839 static struct font_metrics metrics
;
19840 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
19841 struct font
*fontp
;
19843 if (! font
|| code
== FONT_INVALID_CODE
)
19845 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
19850 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
19851 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
19852 assumed to be zero. */
19855 x_get_glyph_overhangs (glyph
, f
, left
, right
)
19856 struct glyph
*glyph
;
19860 *left
= *right
= 0;
19862 if (glyph
->type
== CHAR_GLYPH
)
19866 struct font_metrics
*pcm
;
19868 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
19869 if (face
->font
&& (pcm
= get_per_char_metric (f
, face
->font
, &char2b
)))
19871 if (pcm
->rbearing
> pcm
->width
)
19872 *right
= pcm
->rbearing
- pcm
->width
;
19873 if (pcm
->lbearing
< 0)
19874 *left
= -pcm
->lbearing
;
19877 else if (glyph
->type
== COMPOSITE_GLYPH
)
19879 struct composition
*cmp
= composition_table
[glyph
->u
.cmp_id
];
19881 *right
= cmp
->rbearing
- cmp
->pixel_width
;
19882 *left
= - cmp
->lbearing
;
19887 /* Return the index of the first glyph preceding glyph string S that
19888 is overwritten by S because of S's left overhang. Value is -1
19889 if no glyphs are overwritten. */
19892 left_overwritten (s
)
19893 struct glyph_string
*s
;
19897 if (s
->left_overhang
)
19900 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19901 int first
= s
->first_glyph
- glyphs
;
19903 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
19904 x
-= glyphs
[i
].pixel_width
;
19915 /* Return the index of the first glyph preceding glyph string S that
19916 is overwriting S because of its right overhang. Value is -1 if no
19917 glyph in front of S overwrites S. */
19920 left_overwriting (s
)
19921 struct glyph_string
*s
;
19924 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19925 int first
= s
->first_glyph
- glyphs
;
19929 for (i
= first
- 1; i
>= 0; --i
)
19932 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19935 x
-= glyphs
[i
].pixel_width
;
19942 /* Return the index of the last glyph following glyph string S that is
19943 overwritten by S because of S's right overhang. Value is -1 if
19944 no such glyph is found. */
19947 right_overwritten (s
)
19948 struct glyph_string
*s
;
19952 if (s
->right_overhang
)
19955 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19956 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19957 int end
= s
->row
->used
[s
->area
];
19959 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
19960 x
+= glyphs
[i
].pixel_width
;
19969 /* Return the index of the last glyph following glyph string S that
19970 overwrites S because of its left overhang. Value is negative
19971 if no such glyph is found. */
19974 right_overwriting (s
)
19975 struct glyph_string
*s
;
19978 int end
= s
->row
->used
[s
->area
];
19979 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
19980 int first
= (s
->first_glyph
- glyphs
) + (s
->cmp
? 1 : s
->nchars
);
19984 for (i
= first
; i
< end
; ++i
)
19987 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
19990 x
+= glyphs
[i
].pixel_width
;
19997 /* Set background width of glyph string S. START is the index of the
19998 first glyph following S. LAST_X is the right-most x-position + 1
19999 in the drawing area. */
20002 set_glyph_string_background_width (s
, start
, last_x
)
20003 struct glyph_string
*s
;
20007 /* If the face of this glyph string has to be drawn to the end of
20008 the drawing area, set S->extends_to_end_of_line_p. */
20010 if (start
== s
->row
->used
[s
->area
]
20011 && s
->area
== TEXT_AREA
20012 && ((s
->row
->fill_line_p
20013 && (s
->hl
== DRAW_NORMAL_TEXT
20014 || s
->hl
== DRAW_IMAGE_RAISED
20015 || s
->hl
== DRAW_IMAGE_SUNKEN
))
20016 || s
->hl
== DRAW_MOUSE_FACE
))
20017 s
->extends_to_end_of_line_p
= 1;
20019 /* If S extends its face to the end of the line, set its
20020 background_width to the distance to the right edge of the drawing
20022 if (s
->extends_to_end_of_line_p
)
20023 s
->background_width
= last_x
- s
->x
+ 1;
20025 s
->background_width
= s
->width
;
20029 /* Compute overhangs and x-positions for glyph string S and its
20030 predecessors, or successors. X is the starting x-position for S.
20031 BACKWARD_P non-zero means process predecessors. */
20034 compute_overhangs_and_x (s
, x
, backward_p
)
20035 struct glyph_string
*s
;
20043 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20044 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20054 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
20055 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
20065 /* The following macros are only called from draw_glyphs below.
20066 They reference the following parameters of that function directly:
20067 `w', `row', `area', and `overlap_p'
20068 as well as the following local variables:
20069 `s', `f', and `hdc' (in W32) */
20072 /* On W32, silently add local `hdc' variable to argument list of
20073 init_glyph_string. */
20074 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20075 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
20077 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
20078 init_glyph_string (s, char2b, w, row, area, start, hl)
20081 /* Add a glyph string for a stretch glyph to the list of strings
20082 between HEAD and TAIL. START is the index of the stretch glyph in
20083 row area AREA of glyph row ROW. END is the index of the last glyph
20084 in that glyph row area. X is the current output position assigned
20085 to the new glyph string constructed. HL overrides that face of the
20086 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20087 is the right-most x-position of the drawing area. */
20089 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
20090 and below -- keep them on one line. */
20091 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20094 s = (struct glyph_string *) alloca (sizeof *s); \
20095 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20096 START = fill_stretch_glyph_string (s, row, area, START, END); \
20097 append_glyph_string (&HEAD, &TAIL, s); \
20103 /* Add a glyph string for an image glyph to the list of strings
20104 between HEAD and TAIL. START is the index of the image glyph in
20105 row area AREA of glyph row ROW. END is the index of the last glyph
20106 in that glyph row area. X is the current output position assigned
20107 to the new glyph string constructed. HL overrides that face of the
20108 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
20109 is the right-most x-position of the drawing area. */
20111 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20114 s = (struct glyph_string *) alloca (sizeof *s); \
20115 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
20116 fill_image_glyph_string (s); \
20117 append_glyph_string (&HEAD, &TAIL, s); \
20124 /* Add a glyph string for a sequence of character glyphs to the list
20125 of strings between HEAD and TAIL. START is the index of the first
20126 glyph in row area AREA of glyph row ROW that is part of the new
20127 glyph string. END is the index of the last glyph in that glyph row
20128 area. X is the current output position assigned to the new glyph
20129 string constructed. HL overrides that face of the glyph; e.g. it
20130 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
20131 right-most x-position of the drawing area. */
20133 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20139 face_id = (row)->glyphs[area][START].face_id; \
20141 s = (struct glyph_string *) alloca (sizeof *s); \
20142 char2b = (XChar2b *) alloca ((END - START) * sizeof *char2b); \
20143 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20144 append_glyph_string (&HEAD, &TAIL, s); \
20146 START = fill_glyph_string (s, face_id, START, END, overlaps); \
20151 /* Add a glyph string for a composite sequence to the list of strings
20152 between HEAD and TAIL. START is the index of the first glyph in
20153 row area AREA of glyph row ROW that is part of the new glyph
20154 string. END is the index of the last glyph in that glyph row area.
20155 X is the current output position assigned to the new glyph string
20156 constructed. HL overrides that face of the glyph; e.g. it is
20157 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
20158 x-position of the drawing area. */
20160 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
20162 int face_id = (row)->glyphs[area][START].face_id; \
20163 struct face *base_face = FACE_FROM_ID (f, face_id); \
20164 int cmp_id = (row)->glyphs[area][START].u.cmp_id; \
20165 struct composition *cmp = composition_table[cmp_id]; \
20167 struct glyph_string *first_s; \
20170 char2b = (XChar2b *) alloca ((sizeof *char2b) * cmp->glyph_len); \
20172 /* Make glyph_strings for each glyph sequence that is drawable by \
20173 the same face, and append them to HEAD/TAIL. */ \
20174 for (n = 0; n < cmp->glyph_len;) \
20176 s = (struct glyph_string *) alloca (sizeof *s); \
20177 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
20178 append_glyph_string (&(HEAD), &(TAIL), s); \
20184 n = fill_composite_glyph_string (s, base_face, overlaps); \
20192 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
20193 of AREA of glyph row ROW on window W between indices START and END.
20194 HL overrides the face for drawing glyph strings, e.g. it is
20195 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
20196 x-positions of the drawing area.
20198 This is an ugly monster macro construct because we must use alloca
20199 to allocate glyph strings (because draw_glyphs can be called
20200 asynchronously). */
20202 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
20205 HEAD = TAIL = NULL; \
20206 while (START < END) \
20208 struct glyph *first_glyph = (row)->glyphs[area] + START; \
20209 switch (first_glyph->type) \
20212 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
20216 case COMPOSITE_GLYPH: \
20217 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
20221 case STRETCH_GLYPH: \
20222 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
20226 case IMAGE_GLYPH: \
20227 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
20237 set_glyph_string_background_width (s, START, LAST_X); \
20245 /* Draw glyphs between START and END in AREA of ROW on window W,
20246 starting at x-position X. X is relative to AREA in W. HL is a
20247 face-override with the following meaning:
20249 DRAW_NORMAL_TEXT draw normally
20250 DRAW_CURSOR draw in cursor face
20251 DRAW_MOUSE_FACE draw in mouse face.
20252 DRAW_INVERSE_VIDEO draw in mode line face
20253 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
20254 DRAW_IMAGE_RAISED draw an image with a raised relief around it
20256 If OVERLAPS is non-zero, draw only the foreground of characters and
20257 clip to the physical height of ROW. Non-zero value also defines
20258 the overlapping part to be drawn:
20260 OVERLAPS_PRED overlap with preceding rows
20261 OVERLAPS_SUCC overlap with succeeding rows
20262 OVERLAPS_BOTH overlap with both preceding/succeeding rows
20263 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
20265 Value is the x-position reached, relative to AREA of W. */
20268 draw_glyphs (w
, x
, row
, area
, start
, end
, hl
, overlaps
)
20271 struct glyph_row
*row
;
20272 enum glyph_row_area area
;
20273 EMACS_INT start
, end
;
20274 enum draw_glyphs_face hl
;
20277 struct glyph_string
*head
, *tail
;
20278 struct glyph_string
*s
;
20279 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
20280 int i
, j
, x_reached
, last_x
, area_left
= 0;
20281 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20284 ALLOCATE_HDC (hdc
, f
);
20286 /* Let's rather be paranoid than getting a SEGV. */
20287 end
= min (end
, row
->used
[area
]);
20288 start
= max (0, start
);
20289 start
= min (end
, start
);
20291 /* Translate X to frame coordinates. Set last_x to the right
20292 end of the drawing area. */
20293 if (row
->full_width_p
)
20295 /* X is relative to the left edge of W, without scroll bars
20297 area_left
= WINDOW_LEFT_EDGE_X (w
);
20298 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
20302 area_left
= window_box_left (w
, area
);
20303 last_x
= area_left
+ window_box_width (w
, area
);
20307 /* Build a doubly-linked list of glyph_string structures between
20308 head and tail from what we have to draw. Note that the macro
20309 BUILD_GLYPH_STRINGS will modify its start parameter. That's
20310 the reason we use a separate variable `i'. */
20312 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
20314 x_reached
= tail
->x
+ tail
->background_width
;
20318 /* If there are any glyphs with lbearing < 0 or rbearing > width in
20319 the row, redraw some glyphs in front or following the glyph
20320 strings built above. */
20321 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
20323 struct glyph_string
*h
, *t
;
20324 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
20325 int mouse_beg_col
, mouse_end_col
, check_mouse_face
= 0;
20328 /* If mouse highlighting is on, we may need to draw adjacent
20329 glyphs using mouse-face highlighting. */
20330 if (area
== TEXT_AREA
&& row
->mouse_face_p
)
20332 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
20334 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
20335 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
20337 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
20339 check_mouse_face
= 1;
20340 mouse_beg_col
= (row
== mouse_beg_row
)
20341 ? dpyinfo
->mouse_face_beg_col
: 0;
20342 mouse_end_col
= (row
== mouse_end_row
)
20343 ? dpyinfo
->mouse_face_end_col
20344 : row
->used
[TEXT_AREA
];
20348 /* Compute overhangs for all glyph strings. */
20349 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
20350 for (s
= head
; s
; s
= s
->next
)
20351 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
20353 /* Prepend glyph strings for glyphs in front of the first glyph
20354 string that are overwritten because of the first glyph
20355 string's left overhang. The background of all strings
20356 prepended must be drawn because the first glyph string
20358 i
= left_overwritten (head
);
20361 enum draw_glyphs_face overlap_hl
;
20363 /* If this row contains mouse highlighting, attempt to draw
20364 the overlapped glyphs with the correct highlight. This
20365 code fails if the overlap encompasses more than one glyph
20366 and mouse-highlight spans only some of these glyphs.
20367 However, making it work perfectly involves a lot more
20368 code, and I don't know if the pathological case occurs in
20369 practice, so we'll stick to this for now. --- cyd */
20370 if (check_mouse_face
20371 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20372 overlap_hl
= DRAW_MOUSE_FACE
;
20374 overlap_hl
= DRAW_NORMAL_TEXT
;
20377 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
20378 overlap_hl
, dummy_x
, last_x
);
20379 compute_overhangs_and_x (t
, head
->x
, 1);
20380 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20384 /* Prepend glyph strings for glyphs in front of the first glyph
20385 string that overwrite that glyph string because of their
20386 right overhang. For these strings, only the foreground must
20387 be drawn, because it draws over the glyph string at `head'.
20388 The background must not be drawn because this would overwrite
20389 right overhangs of preceding glyphs for which no glyph
20391 i
= left_overwriting (head
);
20394 enum draw_glyphs_face overlap_hl
;
20396 if (check_mouse_face
20397 && mouse_beg_col
< start
&& mouse_end_col
> i
)
20398 overlap_hl
= DRAW_MOUSE_FACE
;
20400 overlap_hl
= DRAW_NORMAL_TEXT
;
20403 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
20404 overlap_hl
, dummy_x
, last_x
);
20405 for (s
= h
; s
; s
= s
->next
)
20406 s
->background_filled_p
= 1;
20407 compute_overhangs_and_x (t
, head
->x
, 1);
20408 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
20411 /* Append glyphs strings for glyphs following the last glyph
20412 string tail that are overwritten by tail. The background of
20413 these strings has to be drawn because tail's foreground draws
20415 i
= right_overwritten (tail
);
20418 enum draw_glyphs_face overlap_hl
;
20420 if (check_mouse_face
20421 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20422 overlap_hl
= DRAW_MOUSE_FACE
;
20424 overlap_hl
= DRAW_NORMAL_TEXT
;
20426 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20427 overlap_hl
, x
, last_x
);
20428 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20429 append_glyph_string_lists (&head
, &tail
, h
, t
);
20433 /* Append glyph strings for glyphs following the last glyph
20434 string tail that overwrite tail. The foreground of such
20435 glyphs has to be drawn because it writes into the background
20436 of tail. The background must not be drawn because it could
20437 paint over the foreground of following glyphs. */
20438 i
= right_overwriting (tail
);
20441 enum draw_glyphs_face overlap_hl
;
20442 if (check_mouse_face
20443 && mouse_beg_col
< i
&& mouse_end_col
> end
)
20444 overlap_hl
= DRAW_MOUSE_FACE
;
20446 overlap_hl
= DRAW_NORMAL_TEXT
;
20449 i
++; /* We must include the Ith glyph. */
20450 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
20451 overlap_hl
, x
, last_x
);
20452 for (s
= h
; s
; s
= s
->next
)
20453 s
->background_filled_p
= 1;
20454 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
20455 append_glyph_string_lists (&head
, &tail
, h
, t
);
20457 if (clip_head
|| clip_tail
)
20458 for (s
= head
; s
; s
= s
->next
)
20460 s
->clip_head
= clip_head
;
20461 s
->clip_tail
= clip_tail
;
20465 /* Draw all strings. */
20466 for (s
= head
; s
; s
= s
->next
)
20467 FRAME_RIF (f
)->draw_glyph_string (s
);
20469 if (area
== TEXT_AREA
20470 && !row
->full_width_p
20471 /* When drawing overlapping rows, only the glyph strings'
20472 foreground is drawn, which doesn't erase a cursor
20476 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
20477 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
20478 : (tail
? tail
->x
+ tail
->background_width
: x
));
20482 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
20483 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
20486 /* Value is the x-position up to which drawn, relative to AREA of W.
20487 This doesn't include parts drawn because of overhangs. */
20488 if (row
->full_width_p
)
20489 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
20491 x_reached
-= area_left
;
20493 RELEASE_HDC (hdc
, f
);
20498 /* Expand row matrix if too narrow. Don't expand if area
20501 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
20503 if (!fonts_changed_p \
20504 && (it->glyph_row->glyphs[area] \
20505 < it->glyph_row->glyphs[area + 1])) \
20507 it->w->ncols_scale_factor++; \
20508 fonts_changed_p = 1; \
20512 /* Store one glyph for IT->char_to_display in IT->glyph_row.
20513 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20519 struct glyph
*glyph
;
20520 enum glyph_row_area area
= it
->area
;
20522 xassert (it
->glyph_row
);
20523 xassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
20525 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20526 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20528 glyph
->charpos
= CHARPOS (it
->position
);
20529 glyph
->object
= it
->object
;
20530 if (it
->pixel_width
> 0)
20532 glyph
->pixel_width
= it
->pixel_width
;
20533 glyph
->padding_p
= 0;
20537 /* Assure at least 1-pixel width. Otherwise, cursor can't
20538 be displayed correctly. */
20539 glyph
->pixel_width
= 1;
20540 glyph
->padding_p
= 1;
20542 glyph
->ascent
= it
->ascent
;
20543 glyph
->descent
= it
->descent
;
20544 glyph
->voffset
= it
->voffset
;
20545 glyph
->type
= CHAR_GLYPH
;
20546 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20547 glyph
->multibyte_p
= it
->multibyte_p
;
20548 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20549 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20550 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20551 || it
->phys_descent
> it
->descent
);
20552 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
20553 glyph
->face_id
= it
->face_id
;
20554 glyph
->u
.ch
= it
->char_to_display
;
20555 glyph
->slice
= null_glyph_slice
;
20556 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20557 ++it
->glyph_row
->used
[area
];
20560 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20563 /* Store one glyph for the composition IT->cmp_id in IT->glyph_row.
20564 Called from x_produce_glyphs when IT->glyph_row is non-null. */
20567 append_composite_glyph (it
)
20570 struct glyph
*glyph
;
20571 enum glyph_row_area area
= it
->area
;
20573 xassert (it
->glyph_row
);
20575 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20576 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20578 glyph
->charpos
= CHARPOS (it
->position
);
20579 glyph
->object
= it
->object
;
20580 glyph
->pixel_width
= it
->pixel_width
;
20581 glyph
->ascent
= it
->ascent
;
20582 glyph
->descent
= it
->descent
;
20583 glyph
->voffset
= it
->voffset
;
20584 glyph
->type
= COMPOSITE_GLYPH
;
20585 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20586 glyph
->multibyte_p
= it
->multibyte_p
;
20587 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20588 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20589 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
20590 || it
->phys_descent
> it
->descent
);
20591 glyph
->padding_p
= 0;
20592 glyph
->glyph_not_available_p
= 0;
20593 glyph
->face_id
= it
->face_id
;
20594 glyph
->u
.cmp_id
= it
->cmp_id
;
20595 glyph
->slice
= null_glyph_slice
;
20596 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20597 ++it
->glyph_row
->used
[area
];
20600 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20604 /* Change IT->ascent and IT->height according to the setting of
20608 take_vertical_position_into_account (it
)
20613 if (it
->voffset
< 0)
20614 /* Increase the ascent so that we can display the text higher
20616 it
->ascent
-= it
->voffset
;
20618 /* Increase the descent so that we can display the text lower
20620 it
->descent
+= it
->voffset
;
20625 /* Produce glyphs/get display metrics for the image IT is loaded with.
20626 See the description of struct display_iterator in dispextern.h for
20627 an overview of struct display_iterator. */
20630 produce_image_glyph (it
)
20635 int glyph_ascent
, crop
;
20636 struct glyph_slice slice
;
20638 xassert (it
->what
== IT_IMAGE
);
20640 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20642 /* Make sure X resources of the face is loaded. */
20643 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20645 if (it
->image_id
< 0)
20647 /* Fringe bitmap. */
20648 it
->ascent
= it
->phys_ascent
= 0;
20649 it
->descent
= it
->phys_descent
= 0;
20650 it
->pixel_width
= 0;
20655 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
20657 /* Make sure X resources of the image is loaded. */
20658 prepare_image_for_display (it
->f
, img
);
20660 slice
.x
= slice
.y
= 0;
20661 slice
.width
= img
->width
;
20662 slice
.height
= img
->height
;
20664 if (INTEGERP (it
->slice
.x
))
20665 slice
.x
= XINT (it
->slice
.x
);
20666 else if (FLOATP (it
->slice
.x
))
20667 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
20669 if (INTEGERP (it
->slice
.y
))
20670 slice
.y
= XINT (it
->slice
.y
);
20671 else if (FLOATP (it
->slice
.y
))
20672 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
20674 if (INTEGERP (it
->slice
.width
))
20675 slice
.width
= XINT (it
->slice
.width
);
20676 else if (FLOATP (it
->slice
.width
))
20677 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
20679 if (INTEGERP (it
->slice
.height
))
20680 slice
.height
= XINT (it
->slice
.height
);
20681 else if (FLOATP (it
->slice
.height
))
20682 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
20684 if (slice
.x
>= img
->width
)
20685 slice
.x
= img
->width
;
20686 if (slice
.y
>= img
->height
)
20687 slice
.y
= img
->height
;
20688 if (slice
.x
+ slice
.width
>= img
->width
)
20689 slice
.width
= img
->width
- slice
.x
;
20690 if (slice
.y
+ slice
.height
> img
->height
)
20691 slice
.height
= img
->height
- slice
.y
;
20693 if (slice
.width
== 0 || slice
.height
== 0)
20696 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
20698 it
->descent
= slice
.height
- glyph_ascent
;
20700 it
->descent
+= img
->vmargin
;
20701 if (slice
.y
+ slice
.height
== img
->height
)
20702 it
->descent
+= img
->vmargin
;
20703 it
->phys_descent
= it
->descent
;
20705 it
->pixel_width
= slice
.width
;
20707 it
->pixel_width
+= img
->hmargin
;
20708 if (slice
.x
+ slice
.width
== img
->width
)
20709 it
->pixel_width
+= img
->hmargin
;
20711 /* It's quite possible for images to have an ascent greater than
20712 their height, so don't get confused in that case. */
20713 if (it
->descent
< 0)
20716 #if 0 /* this breaks image tiling */
20717 /* If this glyph is alone on the last line, adjust it.ascent to minimum row ascent. */
20718 int face_ascent
= face
->font
? FONT_BASE (face
->font
) : FRAME_BASELINE_OFFSET (it
->f
);
20719 if (face_ascent
> it
->ascent
)
20720 it
->ascent
= it
->phys_ascent
= face_ascent
;
20725 if (face
->box
!= FACE_NO_BOX
)
20727 if (face
->box_line_width
> 0)
20730 it
->ascent
+= face
->box_line_width
;
20731 if (slice
.y
+ slice
.height
== img
->height
)
20732 it
->descent
+= face
->box_line_width
;
20735 if (it
->start_of_box_run_p
&& slice
.x
== 0)
20736 it
->pixel_width
+= eabs (face
->box_line_width
);
20737 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
20738 it
->pixel_width
+= eabs (face
->box_line_width
);
20741 take_vertical_position_into_account (it
);
20743 /* Automatically crop wide image glyphs at right edge so we can
20744 draw the cursor on same display row. */
20745 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
20746 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
20748 it
->pixel_width
-= crop
;
20749 slice
.width
-= crop
;
20754 struct glyph
*glyph
;
20755 enum glyph_row_area area
= it
->area
;
20757 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20758 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20760 glyph
->charpos
= CHARPOS (it
->position
);
20761 glyph
->object
= it
->object
;
20762 glyph
->pixel_width
= it
->pixel_width
;
20763 glyph
->ascent
= glyph_ascent
;
20764 glyph
->descent
= it
->descent
;
20765 glyph
->voffset
= it
->voffset
;
20766 glyph
->type
= IMAGE_GLYPH
;
20767 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20768 glyph
->multibyte_p
= it
->multibyte_p
;
20769 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20770 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20771 glyph
->overlaps_vertically_p
= 0;
20772 glyph
->padding_p
= 0;
20773 glyph
->glyph_not_available_p
= 0;
20774 glyph
->face_id
= it
->face_id
;
20775 glyph
->u
.img_id
= img
->id
;
20776 glyph
->slice
= slice
;
20777 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20778 ++it
->glyph_row
->used
[area
];
20781 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20786 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
20787 of the glyph, WIDTH and HEIGHT are the width and height of the
20788 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
20791 append_stretch_glyph (it
, object
, width
, height
, ascent
)
20793 Lisp_Object object
;
20797 struct glyph
*glyph
;
20798 enum glyph_row_area area
= it
->area
;
20800 xassert (ascent
>= 0 && ascent
<= height
);
20802 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
20803 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
20805 glyph
->charpos
= CHARPOS (it
->position
);
20806 glyph
->object
= object
;
20807 glyph
->pixel_width
= width
;
20808 glyph
->ascent
= ascent
;
20809 glyph
->descent
= height
- ascent
;
20810 glyph
->voffset
= it
->voffset
;
20811 glyph
->type
= STRETCH_GLYPH
;
20812 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
20813 glyph
->multibyte_p
= it
->multibyte_p
;
20814 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
20815 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
20816 glyph
->overlaps_vertically_p
= 0;
20817 glyph
->padding_p
= 0;
20818 glyph
->glyph_not_available_p
= 0;
20819 glyph
->face_id
= it
->face_id
;
20820 glyph
->u
.stretch
.ascent
= ascent
;
20821 glyph
->u
.stretch
.height
= height
;
20822 glyph
->slice
= null_glyph_slice
;
20823 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
20824 ++it
->glyph_row
->used
[area
];
20827 IT_EXPAND_MATRIX_WIDTH (it
, area
);
20831 /* Produce a stretch glyph for iterator IT. IT->object is the value
20832 of the glyph property displayed. The value must be a list
20833 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
20836 1. `:width WIDTH' specifies that the space should be WIDTH *
20837 canonical char width wide. WIDTH may be an integer or floating
20840 2. `:relative-width FACTOR' specifies that the width of the stretch
20841 should be computed from the width of the first character having the
20842 `glyph' property, and should be FACTOR times that width.
20844 3. `:align-to HPOS' specifies that the space should be wide enough
20845 to reach HPOS, a value in canonical character units.
20847 Exactly one of the above pairs must be present.
20849 4. `:height HEIGHT' specifies that the height of the stretch produced
20850 should be HEIGHT, measured in canonical character units.
20852 5. `:relative-height FACTOR' specifies that the height of the
20853 stretch should be FACTOR times the height of the characters having
20854 the glyph property.
20856 Either none or exactly one of 4 or 5 must be present.
20858 6. `:ascent ASCENT' specifies that ASCENT percent of the height
20859 of the stretch should be used for the ascent of the stretch.
20860 ASCENT must be in the range 0 <= ASCENT <= 100. */
20863 produce_stretch_glyph (it
)
20866 /* (space :width WIDTH :height HEIGHT ...) */
20867 Lisp_Object prop
, plist
;
20868 int width
= 0, height
= 0, align_to
= -1;
20869 int zero_width_ok_p
= 0, zero_height_ok_p
= 0;
20872 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
20873 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
20875 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
20877 /* List should start with `space'. */
20878 xassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
20879 plist
= XCDR (it
->object
);
20881 /* Compute the width of the stretch. */
20882 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
20883 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
20885 /* Absolute width `:width WIDTH' specified and valid. */
20886 zero_width_ok_p
= 1;
20889 else if (prop
= Fplist_get (plist
, QCrelative_width
),
20892 /* Relative width `:relative-width FACTOR' specified and valid.
20893 Compute the width of the characters having the `glyph'
20896 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
20899 if (it
->multibyte_p
)
20901 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT
? ZV
: GPT
)
20902 - IT_BYTEPOS (*it
));
20903 it2
.c
= STRING_CHAR_AND_LENGTH (p
, maxlen
, it2
.len
);
20906 it2
.c
= *p
, it2
.len
= 1;
20908 it2
.glyph_row
= NULL
;
20909 it2
.what
= IT_CHARACTER
;
20910 x_produce_glyphs (&it2
);
20911 width
= NUMVAL (prop
) * it2
.pixel_width
;
20913 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
20914 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
20916 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
20917 align_to
= (align_to
< 0
20919 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
20920 else if (align_to
< 0)
20921 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
20922 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
20923 zero_width_ok_p
= 1;
20926 /* Nothing specified -> width defaults to canonical char width. */
20927 width
= FRAME_COLUMN_WIDTH (it
->f
);
20929 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
20932 /* Compute height. */
20933 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
20934 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20937 zero_height_ok_p
= 1;
20939 else if (prop
= Fplist_get (plist
, QCrelative_height
),
20941 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
20943 height
= FONT_HEIGHT (font
);
20945 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
20948 /* Compute percentage of height used for ascent. If
20949 `:ascent ASCENT' is present and valid, use that. Otherwise,
20950 derive the ascent from the font in use. */
20951 if (prop
= Fplist_get (plist
, QCascent
),
20952 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
20953 ascent
= height
* NUMVAL (prop
) / 100.0;
20954 else if (!NILP (prop
)
20955 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
20956 ascent
= min (max (0, (int)tem
), height
);
20958 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
20960 if (width
> 0 && it
->line_wrap
!= TRUNCATE
20961 && it
->current_x
+ width
> it
->last_visible_x
)
20962 width
= it
->last_visible_x
- it
->current_x
- 1;
20964 if (width
> 0 && height
> 0 && it
->glyph_row
)
20966 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
20967 if (!STRINGP (object
))
20968 object
= it
->w
->buffer
;
20969 append_stretch_glyph (it
, object
, width
, height
, ascent
);
20972 it
->pixel_width
= width
;
20973 it
->ascent
= it
->phys_ascent
= ascent
;
20974 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
20975 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
20977 take_vertical_position_into_account (it
);
20980 /* Calculate line-height and line-spacing properties.
20981 An integer value specifies explicit pixel value.
20982 A float value specifies relative value to current face height.
20983 A cons (float . face-name) specifies relative value to
20984 height of specified face font.
20986 Returns height in pixels, or nil. */
20990 calc_line_height_property (it
, val
, font
, boff
, override
)
20994 int boff
, override
;
20996 Lisp_Object face_name
= Qnil
;
20997 int ascent
, descent
, height
;
20999 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
21004 face_name
= XCAR (val
);
21006 if (!NUMBERP (val
))
21007 val
= make_number (1);
21008 if (NILP (face_name
))
21010 height
= it
->ascent
+ it
->descent
;
21015 if (NILP (face_name
))
21017 font
= FRAME_FONT (it
->f
);
21018 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21020 else if (EQ (face_name
, Qt
))
21029 face_id
= lookup_named_face (it
->f
, face_name
, 0);
21031 return make_number (-1);
21033 face
= FACE_FROM_ID (it
->f
, face_id
);
21036 return make_number (-1);
21037 boff
= font
->baseline_offset
;
21038 if (font
->vertical_centering
)
21039 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21042 ascent
= FONT_BASE (font
) + boff
;
21043 descent
= FONT_DESCENT (font
) - boff
;
21047 it
->override_ascent
= ascent
;
21048 it
->override_descent
= descent
;
21049 it
->override_boff
= boff
;
21052 height
= ascent
+ descent
;
21056 height
= (int)(XFLOAT_DATA (val
) * height
);
21057 else if (INTEGERP (val
))
21058 height
*= XINT (val
);
21060 return make_number (height
);
21065 Produce glyphs/get display metrics for the display element IT is
21066 loaded with. See the description of struct it in dispextern.h
21067 for an overview of struct it. */
21070 x_produce_glyphs (it
)
21073 int extra_line_spacing
= it
->extra_line_spacing
;
21075 it
->glyph_not_available_p
= 0;
21077 if (it
->what
== IT_CHARACTER
)
21081 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21082 struct font_metrics
*pcm
;
21083 int font_not_found_p
;
21084 int boff
; /* baseline offset */
21085 /* We may change it->multibyte_p upon unibyte<->multibyte
21086 conversion. So, save the current value now and restore it
21089 Note: It seems that we don't have to record multibyte_p in
21090 struct glyph because the character code itself tells if or
21091 not the character is multibyte. Thus, in the future, we must
21092 consider eliminating the field `multibyte_p' in the struct
21094 int saved_multibyte_p
= it
->multibyte_p
;
21096 /* Maybe translate single-byte characters to multibyte, or the
21098 it
->char_to_display
= it
->c
;
21099 if (!ASCII_BYTE_P (it
->c
)
21100 && ! it
->multibyte_p
)
21102 if (SINGLE_BYTE_CHAR_P (it
->c
)
21103 && unibyte_display_via_language_environment
)
21104 it
->char_to_display
= unibyte_char_to_multibyte (it
->c
);
21105 if (! SINGLE_BYTE_CHAR_P (it
->char_to_display
))
21107 it
->multibyte_p
= 1;
21108 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->char_to_display
,
21110 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21114 /* Get font to use. Encode IT->char_to_display. */
21115 get_char_face_and_encoding (it
->f
, it
->char_to_display
, it
->face_id
,
21116 &char2b
, it
->multibyte_p
, 0);
21119 /* When no suitable font found, use the default font. */
21120 font_not_found_p
= font
== NULL
;
21121 if (font_not_found_p
)
21123 font
= FRAME_FONT (it
->f
);
21124 boff
= FRAME_BASELINE_OFFSET (it
->f
);
21128 boff
= font
->baseline_offset
;
21129 if (font
->vertical_centering
)
21130 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21133 if (it
->char_to_display
>= ' '
21134 && (!it
->multibyte_p
|| it
->char_to_display
< 128))
21136 /* Either unibyte or ASCII. */
21141 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21143 if (it
->override_ascent
>= 0)
21145 it
->ascent
= it
->override_ascent
;
21146 it
->descent
= it
->override_descent
;
21147 boff
= it
->override_boff
;
21151 it
->ascent
= FONT_BASE (font
) + boff
;
21152 it
->descent
= FONT_DESCENT (font
) - boff
;
21157 it
->phys_ascent
= pcm
->ascent
+ boff
;
21158 it
->phys_descent
= pcm
->descent
- boff
;
21159 it
->pixel_width
= pcm
->width
;
21163 it
->glyph_not_available_p
= 1;
21164 it
->phys_ascent
= it
->ascent
;
21165 it
->phys_descent
= it
->descent
;
21166 it
->pixel_width
= FONT_WIDTH (font
);
21169 if (it
->constrain_row_ascent_descent_p
)
21171 if (it
->descent
> it
->max_descent
)
21173 it
->ascent
+= it
->descent
- it
->max_descent
;
21174 it
->descent
= it
->max_descent
;
21176 if (it
->ascent
> it
->max_ascent
)
21178 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21179 it
->ascent
= it
->max_ascent
;
21181 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21182 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21183 extra_line_spacing
= 0;
21186 /* If this is a space inside a region of text with
21187 `space-width' property, change its width. */
21188 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
21190 it
->pixel_width
*= XFLOATINT (it
->space_width
);
21192 /* If face has a box, add the box thickness to the character
21193 height. If character has a box line to the left and/or
21194 right, add the box line width to the character's width. */
21195 if (face
->box
!= FACE_NO_BOX
)
21197 int thick
= face
->box_line_width
;
21201 it
->ascent
+= thick
;
21202 it
->descent
+= thick
;
21207 if (it
->start_of_box_run_p
)
21208 it
->pixel_width
+= thick
;
21209 if (it
->end_of_box_run_p
)
21210 it
->pixel_width
+= thick
;
21213 /* If face has an overline, add the height of the overline
21214 (1 pixel) and a 1 pixel margin to the character height. */
21215 if (face
->overline_p
)
21216 it
->ascent
+= overline_margin
;
21218 if (it
->constrain_row_ascent_descent_p
)
21220 if (it
->ascent
> it
->max_ascent
)
21221 it
->ascent
= it
->max_ascent
;
21222 if (it
->descent
> it
->max_descent
)
21223 it
->descent
= it
->max_descent
;
21226 take_vertical_position_into_account (it
);
21228 /* If we have to actually produce glyphs, do it. */
21233 /* Translate a space with a `space-width' property
21234 into a stretch glyph. */
21235 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
21236 / FONT_HEIGHT (font
));
21237 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21238 it
->ascent
+ it
->descent
, ascent
);
21243 /* If characters with lbearing or rbearing are displayed
21244 in this line, record that fact in a flag of the
21245 glyph row. This is used to optimize X output code. */
21246 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
21247 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21249 if (! stretched_p
&& it
->pixel_width
== 0)
21250 /* We assure that all visible glyphs have at least 1-pixel
21252 it
->pixel_width
= 1;
21254 else if (it
->char_to_display
== '\n')
21256 /* A newline has no width but we need the height of the line.
21257 But if previous part of the line set a height, don't
21258 increase that height */
21260 Lisp_Object height
;
21261 Lisp_Object total_height
= Qnil
;
21263 it
->override_ascent
= -1;
21264 it
->pixel_width
= 0;
21267 height
= get_it_property(it
, Qline_height
);
21268 /* Split (line-height total-height) list */
21270 && CONSP (XCDR (height
))
21271 && NILP (XCDR (XCDR (height
))))
21273 total_height
= XCAR (XCDR (height
));
21274 height
= XCAR (height
);
21276 height
= calc_line_height_property(it
, height
, font
, boff
, 1);
21278 if (it
->override_ascent
>= 0)
21280 it
->ascent
= it
->override_ascent
;
21281 it
->descent
= it
->override_descent
;
21282 boff
= it
->override_boff
;
21286 it
->ascent
= FONT_BASE (font
) + boff
;
21287 it
->descent
= FONT_DESCENT (font
) - boff
;
21290 if (EQ (height
, Qt
))
21292 if (it
->descent
> it
->max_descent
)
21294 it
->ascent
+= it
->descent
- it
->max_descent
;
21295 it
->descent
= it
->max_descent
;
21297 if (it
->ascent
> it
->max_ascent
)
21299 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
21300 it
->ascent
= it
->max_ascent
;
21302 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
21303 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
21304 it
->constrain_row_ascent_descent_p
= 1;
21305 extra_line_spacing
= 0;
21309 Lisp_Object spacing
;
21311 it
->phys_ascent
= it
->ascent
;
21312 it
->phys_descent
= it
->descent
;
21314 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
21315 && face
->box
!= FACE_NO_BOX
21316 && face
->box_line_width
> 0)
21318 it
->ascent
+= face
->box_line_width
;
21319 it
->descent
+= face
->box_line_width
;
21322 && XINT (height
) > it
->ascent
+ it
->descent
)
21323 it
->ascent
= XINT (height
) - it
->descent
;
21325 if (!NILP (total_height
))
21326 spacing
= calc_line_height_property(it
, total_height
, font
, boff
, 0);
21329 spacing
= get_it_property(it
, Qline_spacing
);
21330 spacing
= calc_line_height_property(it
, spacing
, font
, boff
, 0);
21332 if (INTEGERP (spacing
))
21334 extra_line_spacing
= XINT (spacing
);
21335 if (!NILP (total_height
))
21336 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
21340 else if (it
->char_to_display
== '\t')
21342 int tab_width
= it
->tab_width
* font
->space_width
;
21343 int x
= it
->current_x
+ it
->continuation_lines_width
;
21344 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
21346 /* If the distance from the current position to the next tab
21347 stop is less than a space character width, use the
21348 tab stop after that. */
21349 if (next_tab_x
- x
< font
->space_width
)
21350 next_tab_x
+= tab_width
;
21352 it
->pixel_width
= next_tab_x
- x
;
21354 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
21355 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21359 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
21360 it
->ascent
+ it
->descent
, it
->ascent
);
21365 /* A multi-byte character. Assume that the display width of the
21366 character is the width of the character multiplied by the
21367 width of the font. */
21369 /* If we found a font, this font should give us the right
21370 metrics. If we didn't find a font, use the frame's
21371 default font and calculate the width of the character by
21372 multiplying the width of font by the width of the
21375 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21377 if (font_not_found_p
|| !pcm
)
21379 int char_width
= CHAR_WIDTH (it
->char_to_display
);
21381 if (char_width
== 0)
21382 /* This is a non spacing character. But, as we are
21383 going to display an empty box, the box must occupy
21384 at least one column. */
21386 it
->glyph_not_available_p
= 1;
21387 it
->pixel_width
= FRAME_COLUMN_WIDTH (it
->f
) * char_width
;
21388 it
->phys_ascent
= FONT_BASE (font
) + boff
;
21389 it
->phys_descent
= FONT_DESCENT (font
) - boff
;
21393 it
->pixel_width
= pcm
->width
;
21394 it
->phys_ascent
= pcm
->ascent
+ boff
;
21395 it
->phys_descent
= pcm
->descent
- boff
;
21397 && (pcm
->lbearing
< 0
21398 || pcm
->rbearing
> pcm
->width
))
21399 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21402 it
->ascent
= FONT_BASE (font
) + boff
;
21403 it
->descent
= FONT_DESCENT (font
) - boff
;
21404 if (face
->box
!= FACE_NO_BOX
)
21406 int thick
= face
->box_line_width
;
21410 it
->ascent
+= thick
;
21411 it
->descent
+= thick
;
21416 if (it
->start_of_box_run_p
)
21417 it
->pixel_width
+= thick
;
21418 if (it
->end_of_box_run_p
)
21419 it
->pixel_width
+= thick
;
21422 /* If face has an overline, add the height of the overline
21423 (1 pixel) and a 1 pixel margin to the character height. */
21424 if (face
->overline_p
)
21425 it
->ascent
+= overline_margin
;
21427 take_vertical_position_into_account (it
);
21429 if (it
->ascent
< 0)
21431 if (it
->descent
< 0)
21436 if (it
->pixel_width
== 0)
21437 /* We assure that all visible glyphs have at least 1-pixel
21439 it
->pixel_width
= 1;
21441 it
->multibyte_p
= saved_multibyte_p
;
21443 else if (it
->what
== IT_COMPOSITION
)
21445 /* Note: A composition is represented as one glyph in the
21446 glyph matrix. There are no padding glyphs.
21448 Important is that pixel_width, ascent, and descent are the
21449 values of what is drawn by draw_glyphs (i.e. the values of
21450 the overall glyphs composed). */
21451 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21452 int boff
; /* baseline offset */
21453 struct composition
*cmp
= composition_table
[it
->cmp_id
];
21454 int glyph_len
= cmp
->glyph_len
;
21455 struct font
*font
= face
->font
;
21459 if (cmp
->method
== COMPOSITION_WITH_GLYPH_STRING
)
21461 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
21462 font_prepare_composition (cmp
, it
->f
);
21465 /* If we have not yet calculated pixel size data of glyphs of
21466 the composition for the current face font, calculate them
21467 now. Theoretically, we have to check all fonts for the
21468 glyphs, but that requires much time and memory space. So,
21469 here we check only the font of the first glyph. This leads
21470 to incorrect display, but it's very rare, and C-l (recenter)
21471 can correct the display anyway. */
21472 if (! cmp
->font
|| cmp
->font
!= font
)
21474 /* Ascent and descent of the font of the first character
21475 of this composition (adjusted by baseline offset).
21476 Ascent and descent of overall glyphs should not be less
21477 than them respectively. */
21478 int font_ascent
, font_descent
, font_height
;
21479 /* Bounding box of the overall glyphs. */
21480 int leftmost
, rightmost
, lowest
, highest
;
21481 int lbearing
, rbearing
;
21482 int i
, width
, ascent
, descent
;
21483 int left_padded
= 0, right_padded
= 0;
21487 struct font_metrics
*pcm
;
21488 int font_not_found_p
;
21491 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
21492 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
21494 if (glyph_len
< cmp
->glyph_len
)
21496 for (i
= 0; i
< glyph_len
; i
++)
21498 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
21500 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21505 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
21506 : IT_CHARPOS (*it
));
21507 /* When no suitable font found, use the default font. */
21508 font_not_found_p
= font
== NULL
;
21509 if (font_not_found_p
)
21511 face
= face
->ascii_face
;
21514 boff
= font
->baseline_offset
;
21515 if (font
->vertical_centering
)
21516 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21517 font_ascent
= FONT_BASE (font
) + boff
;
21518 font_descent
= FONT_DESCENT (font
) - boff
;
21519 font_height
= FONT_HEIGHT (font
);
21521 cmp
->font
= (void *) font
;
21524 if (! font_not_found_p
)
21526 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
21527 &char2b
, it
->multibyte_p
, 0);
21528 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21531 /* Initialize the bounding box. */
21534 width
= pcm
->width
;
21535 ascent
= pcm
->ascent
;
21536 descent
= pcm
->descent
;
21537 lbearing
= pcm
->lbearing
;
21538 rbearing
= pcm
->rbearing
;
21542 width
= FONT_WIDTH (font
);
21543 ascent
= FONT_BASE (font
);
21544 descent
= FONT_DESCENT (font
);
21551 lowest
= - descent
+ boff
;
21552 highest
= ascent
+ boff
;
21554 if (! font_not_found_p
21555 && font
->default_ascent
21556 && CHAR_TABLE_P (Vuse_default_ascent
)
21557 && !NILP (Faref (Vuse_default_ascent
,
21558 make_number (it
->char_to_display
))))
21559 highest
= font
->default_ascent
+ boff
;
21561 /* Draw the first glyph at the normal position. It may be
21562 shifted to right later if some other glyphs are drawn
21564 cmp
->offsets
[i
* 2] = 0;
21565 cmp
->offsets
[i
* 2 + 1] = boff
;
21566 cmp
->lbearing
= lbearing
;
21567 cmp
->rbearing
= rbearing
;
21569 /* Set cmp->offsets for the remaining glyphs. */
21570 for (i
++; i
< glyph_len
; i
++)
21572 int left
, right
, btm
, top
;
21573 int ch
= COMPOSITION_GLYPH (cmp
, i
);
21575 struct face
*this_face
;
21580 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
21581 this_face
= FACE_FROM_ID (it
->f
, face_id
);
21582 font
= this_face
->font
;
21588 this_boff
= font
->baseline_offset
;
21589 if (font
->vertical_centering
)
21590 this_boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
21591 get_char_face_and_encoding (it
->f
, ch
, face_id
,
21592 &char2b
, it
->multibyte_p
, 0);
21593 pcm
= get_per_char_metric (it
->f
, font
, &char2b
);
21596 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
21599 width
= pcm
->width
;
21600 ascent
= pcm
->ascent
;
21601 descent
= pcm
->descent
;
21602 lbearing
= pcm
->lbearing
;
21603 rbearing
= pcm
->rbearing
;
21604 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
21606 /* Relative composition with or without
21607 alternate chars. */
21608 left
= (leftmost
+ rightmost
- width
) / 2;
21609 btm
= - descent
+ boff
;
21610 if (font
->relative_compose
21611 && (! CHAR_TABLE_P (Vignore_relative_composition
)
21612 || NILP (Faref (Vignore_relative_composition
,
21613 make_number (ch
)))))
21616 if (- descent
>= font
->relative_compose
)
21617 /* One extra pixel between two glyphs. */
21619 else if (ascent
<= 0)
21620 /* One extra pixel between two glyphs. */
21621 btm
= lowest
- 1 - ascent
- descent
;
21626 /* A composition rule is specified by an integer
21627 value that encodes global and new reference
21628 points (GREF and NREF). GREF and NREF are
21629 specified by numbers as below:
21631 0---1---2 -- ascent
21635 9--10--11 -- center
21637 ---3---4---5--- baseline
21639 6---7---8 -- descent
21641 int rule
= COMPOSITION_RULE (cmp
, i
);
21642 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
21644 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
21645 grefx
= gref
% 3, nrefx
= nref
% 3;
21646 grefy
= gref
/ 3, nrefy
= nref
/ 3;
21648 xoff
= font_height
* (xoff
- 128) / 256;
21650 yoff
= font_height
* (yoff
- 128) / 256;
21653 + grefx
* (rightmost
- leftmost
) / 2
21654 - nrefx
* width
/ 2
21657 btm
= ((grefy
== 0 ? highest
21659 : grefy
== 2 ? lowest
21660 : (highest
+ lowest
) / 2)
21661 - (nrefy
== 0 ? ascent
+ descent
21662 : nrefy
== 1 ? descent
- boff
21664 : (ascent
+ descent
) / 2)
21668 cmp
->offsets
[i
* 2] = left
;
21669 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
21671 /* Update the bounding box of the overall glyphs. */
21674 right
= left
+ width
;
21675 if (left
< leftmost
)
21677 if (right
> rightmost
)
21680 top
= btm
+ descent
+ ascent
;
21686 if (cmp
->lbearing
> left
+ lbearing
)
21687 cmp
->lbearing
= left
+ lbearing
;
21688 if (cmp
->rbearing
< left
+ rbearing
)
21689 cmp
->rbearing
= left
+ rbearing
;
21693 /* If there are glyphs whose x-offsets are negative,
21694 shift all glyphs to the right and make all x-offsets
21698 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21699 cmp
->offsets
[i
* 2] -= leftmost
;
21700 rightmost
-= leftmost
;
21701 cmp
->lbearing
-= leftmost
;
21702 cmp
->rbearing
-= leftmost
;
21705 if (left_padded
&& cmp
->lbearing
< 0)
21707 for (i
= 0; i
< cmp
->glyph_len
; i
++)
21708 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
21709 rightmost
-= cmp
->lbearing
;
21710 cmp
->rbearing
-= cmp
->lbearing
;
21713 if (right_padded
&& rightmost
< cmp
->rbearing
)
21715 rightmost
= cmp
->rbearing
;
21718 cmp
->pixel_width
= rightmost
;
21719 cmp
->ascent
= highest
;
21720 cmp
->descent
= - lowest
;
21721 if (cmp
->ascent
< font_ascent
)
21722 cmp
->ascent
= font_ascent
;
21723 if (cmp
->descent
< font_descent
)
21724 cmp
->descent
= font_descent
;
21728 && (cmp
->lbearing
< 0
21729 || cmp
->rbearing
> cmp
->pixel_width
))
21730 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
21732 it
->pixel_width
= cmp
->pixel_width
;
21733 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
21734 it
->descent
= it
->phys_descent
= cmp
->descent
;
21735 if (face
->box
!= FACE_NO_BOX
)
21737 int thick
= face
->box_line_width
;
21741 it
->ascent
+= thick
;
21742 it
->descent
+= thick
;
21747 if (it
->start_of_box_run_p
)
21748 it
->pixel_width
+= thick
;
21749 if (it
->end_of_box_run_p
)
21750 it
->pixel_width
+= thick
;
21753 /* If face has an overline, add the height of the overline
21754 (1 pixel) and a 1 pixel margin to the character height. */
21755 if (face
->overline_p
)
21756 it
->ascent
+= overline_margin
;
21758 take_vertical_position_into_account (it
);
21759 if (it
->ascent
< 0)
21761 if (it
->descent
< 0)
21765 append_composite_glyph (it
);
21767 else if (it
->what
== IT_IMAGE
)
21768 produce_image_glyph (it
);
21769 else if (it
->what
== IT_STRETCH
)
21770 produce_stretch_glyph (it
);
21772 /* Accumulate dimensions. Note: can't assume that it->descent > 0
21773 because this isn't true for images with `:ascent 100'. */
21774 xassert (it
->ascent
>= 0 && it
->descent
>= 0);
21775 if (it
->area
== TEXT_AREA
)
21776 it
->current_x
+= it
->pixel_width
;
21778 if (extra_line_spacing
> 0)
21780 it
->descent
+= extra_line_spacing
;
21781 if (extra_line_spacing
> it
->max_extra_line_spacing
)
21782 it
->max_extra_line_spacing
= extra_line_spacing
;
21785 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
21786 it
->max_descent
= max (it
->max_descent
, it
->descent
);
21787 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
21788 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
21792 Output LEN glyphs starting at START at the nominal cursor position.
21793 Advance the nominal cursor over the text. The global variable
21794 updated_window contains the window being updated, updated_row is
21795 the glyph row being updated, and updated_area is the area of that
21796 row being updated. */
21799 x_write_glyphs (start
, len
)
21800 struct glyph
*start
;
21805 xassert (updated_window
&& updated_row
);
21808 /* Write glyphs. */
21810 hpos
= start
- updated_row
->glyphs
[updated_area
];
21811 x
= draw_glyphs (updated_window
, output_cursor
.x
,
21812 updated_row
, updated_area
,
21814 DRAW_NORMAL_TEXT
, 0);
21816 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
21817 if (updated_area
== TEXT_AREA
21818 && updated_window
->phys_cursor_on_p
21819 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
21820 && updated_window
->phys_cursor
.hpos
>= hpos
21821 && updated_window
->phys_cursor
.hpos
< hpos
+ len
)
21822 updated_window
->phys_cursor_on_p
= 0;
21826 /* Advance the output cursor. */
21827 output_cursor
.hpos
+= len
;
21828 output_cursor
.x
= x
;
21833 Insert LEN glyphs from START at the nominal cursor position. */
21836 x_insert_glyphs (start
, len
)
21837 struct glyph
*start
;
21842 int line_height
, shift_by_width
, shifted_region_width
;
21843 struct glyph_row
*row
;
21844 struct glyph
*glyph
;
21845 int frame_x
, frame_y
;
21848 xassert (updated_window
&& updated_row
);
21850 w
= updated_window
;
21851 f
= XFRAME (WINDOW_FRAME (w
));
21853 /* Get the height of the line we are in. */
21855 line_height
= row
->height
;
21857 /* Get the width of the glyphs to insert. */
21858 shift_by_width
= 0;
21859 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
21860 shift_by_width
+= glyph
->pixel_width
;
21862 /* Get the width of the region to shift right. */
21863 shifted_region_width
= (window_box_width (w
, updated_area
)
21868 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
21869 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
21871 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
21872 line_height
, shift_by_width
);
21874 /* Write the glyphs. */
21875 hpos
= start
- row
->glyphs
[updated_area
];
21876 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
21878 DRAW_NORMAL_TEXT
, 0);
21880 /* Advance the output cursor. */
21881 output_cursor
.hpos
+= len
;
21882 output_cursor
.x
+= shift_by_width
;
21888 Erase the current text line from the nominal cursor position
21889 (inclusive) to pixel column TO_X (exclusive). The idea is that
21890 everything from TO_X onward is already erased.
21892 TO_X is a pixel position relative to updated_area of
21893 updated_window. TO_X == -1 means clear to the end of this area. */
21896 x_clear_end_of_line (to_x
)
21900 struct window
*w
= updated_window
;
21901 int max_x
, min_y
, max_y
;
21902 int from_x
, from_y
, to_y
;
21904 xassert (updated_window
&& updated_row
);
21905 f
= XFRAME (w
->frame
);
21907 if (updated_row
->full_width_p
)
21908 max_x
= WINDOW_TOTAL_WIDTH (w
);
21910 max_x
= window_box_width (w
, updated_area
);
21911 max_y
= window_text_bottom_y (w
);
21913 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
21914 of window. For TO_X > 0, truncate to end of drawing area. */
21920 to_x
= min (to_x
, max_x
);
21922 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
21924 /* Notice if the cursor will be cleared by this operation. */
21925 if (!updated_row
->full_width_p
)
21926 notice_overwritten_cursor (w
, updated_area
,
21927 output_cursor
.x
, -1,
21929 MATRIX_ROW_BOTTOM_Y (updated_row
));
21931 from_x
= output_cursor
.x
;
21933 /* Translate to frame coordinates. */
21934 if (updated_row
->full_width_p
)
21936 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
21937 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
21941 int area_left
= window_box_left (w
, updated_area
);
21942 from_x
+= area_left
;
21946 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
21947 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
21948 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
21950 /* Prevent inadvertently clearing to end of the X window. */
21951 if (to_x
> from_x
&& to_y
> from_y
)
21954 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
21955 to_x
- from_x
, to_y
- from_y
);
21960 #endif /* HAVE_WINDOW_SYSTEM */
21964 /***********************************************************************
21966 ***********************************************************************/
21968 /* Value is the internal representation of the specified cursor type
21969 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
21970 of the bar cursor. */
21972 static enum text_cursor_kinds
21973 get_specified_cursor_type (arg
, width
)
21977 enum text_cursor_kinds type
;
21982 if (EQ (arg
, Qbox
))
21983 return FILLED_BOX_CURSOR
;
21985 if (EQ (arg
, Qhollow
))
21986 return HOLLOW_BOX_CURSOR
;
21988 if (EQ (arg
, Qbar
))
21995 && EQ (XCAR (arg
), Qbar
)
21996 && INTEGERP (XCDR (arg
))
21997 && XINT (XCDR (arg
)) >= 0)
21999 *width
= XINT (XCDR (arg
));
22003 if (EQ (arg
, Qhbar
))
22006 return HBAR_CURSOR
;
22010 && EQ (XCAR (arg
), Qhbar
)
22011 && INTEGERP (XCDR (arg
))
22012 && XINT (XCDR (arg
)) >= 0)
22014 *width
= XINT (XCDR (arg
));
22015 return HBAR_CURSOR
;
22018 /* Treat anything unknown as "hollow box cursor".
22019 It was bad to signal an error; people have trouble fixing
22020 .Xdefaults with Emacs, when it has something bad in it. */
22021 type
= HOLLOW_BOX_CURSOR
;
22026 /* Set the default cursor types for specified frame. */
22028 set_frame_cursor_types (f
, arg
)
22035 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
22036 FRAME_CURSOR_WIDTH (f
) = width
;
22038 /* By default, set up the blink-off state depending on the on-state. */
22040 tem
= Fassoc (arg
, Vblink_cursor_alist
);
22043 FRAME_BLINK_OFF_CURSOR (f
)
22044 = get_specified_cursor_type (XCDR (tem
), &width
);
22045 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
22048 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
22052 /* Return the cursor we want to be displayed in window W. Return
22053 width of bar/hbar cursor through WIDTH arg. Return with
22054 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
22055 (i.e. if the `system caret' should track this cursor).
22057 In a mini-buffer window, we want the cursor only to appear if we
22058 are reading input from this window. For the selected window, we
22059 want the cursor type given by the frame parameter or buffer local
22060 setting of cursor-type. If explicitly marked off, draw no cursor.
22061 In all other cases, we want a hollow box cursor. */
22063 static enum text_cursor_kinds
22064 get_window_cursor_type (w
, glyph
, width
, active_cursor
)
22066 struct glyph
*glyph
;
22068 int *active_cursor
;
22070 struct frame
*f
= XFRAME (w
->frame
);
22071 struct buffer
*b
= XBUFFER (w
->buffer
);
22072 int cursor_type
= DEFAULT_CURSOR
;
22073 Lisp_Object alt_cursor
;
22074 int non_selected
= 0;
22076 *active_cursor
= 1;
22079 if (cursor_in_echo_area
22080 && FRAME_HAS_MINIBUF_P (f
)
22081 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
22083 if (w
== XWINDOW (echo_area_window
))
22085 if (EQ (b
->cursor_type
, Qt
) || NILP (b
->cursor_type
))
22087 *width
= FRAME_CURSOR_WIDTH (f
);
22088 return FRAME_DESIRED_CURSOR (f
);
22091 return get_specified_cursor_type (b
->cursor_type
, width
);
22094 *active_cursor
= 0;
22098 /* Detect a nonselected window or nonselected frame. */
22099 else if (w
!= XWINDOW (f
->selected_window
)
22100 #ifdef HAVE_WINDOW_SYSTEM
22101 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
22105 *active_cursor
= 0;
22107 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
22113 /* Never display a cursor in a window in which cursor-type is nil. */
22114 if (NILP (b
->cursor_type
))
22117 /* Get the normal cursor type for this window. */
22118 if (EQ (b
->cursor_type
, Qt
))
22120 cursor_type
= FRAME_DESIRED_CURSOR (f
);
22121 *width
= FRAME_CURSOR_WIDTH (f
);
22124 cursor_type
= get_specified_cursor_type (b
->cursor_type
, width
);
22126 /* Use cursor-in-non-selected-windows instead
22127 for non-selected window or frame. */
22130 alt_cursor
= b
->cursor_in_non_selected_windows
;
22131 if (!EQ (Qt
, alt_cursor
))
22132 return get_specified_cursor_type (alt_cursor
, width
);
22133 /* t means modify the normal cursor type. */
22134 if (cursor_type
== FILLED_BOX_CURSOR
)
22135 cursor_type
= HOLLOW_BOX_CURSOR
;
22136 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
22138 return cursor_type
;
22141 /* Use normal cursor if not blinked off. */
22142 if (!w
->cursor_off_p
)
22144 #ifdef HAVE_WINDOW_SYSTEM
22145 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
22147 if (cursor_type
== FILLED_BOX_CURSOR
)
22149 /* Using a block cursor on large images can be very annoying.
22150 So use a hollow cursor for "large" images.
22151 If image is not transparent (no mask), also use hollow cursor. */
22152 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
22153 if (img
!= NULL
&& IMAGEP (img
->spec
))
22155 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
22156 where N = size of default frame font size.
22157 This should cover most of the "tiny" icons people may use. */
22159 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
22160 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
22161 cursor_type
= HOLLOW_BOX_CURSOR
;
22164 else if (cursor_type
!= NO_CURSOR
)
22166 /* Display current only supports BOX and HOLLOW cursors for images.
22167 So for now, unconditionally use a HOLLOW cursor when cursor is
22168 not a solid box cursor. */
22169 cursor_type
= HOLLOW_BOX_CURSOR
;
22173 return cursor_type
;
22176 /* Cursor is blinked off, so determine how to "toggle" it. */
22178 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
22179 if ((alt_cursor
= Fassoc (b
->cursor_type
, Vblink_cursor_alist
), !NILP (alt_cursor
)))
22180 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
22182 /* Then see if frame has specified a specific blink off cursor type. */
22183 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
22185 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
22186 return FRAME_BLINK_OFF_CURSOR (f
);
22190 /* Some people liked having a permanently visible blinking cursor,
22191 while others had very strong opinions against it. So it was
22192 decided to remove it. KFS 2003-09-03 */
22194 /* Finally perform built-in cursor blinking:
22195 filled box <-> hollow box
22196 wide [h]bar <-> narrow [h]bar
22197 narrow [h]bar <-> no cursor
22198 other type <-> no cursor */
22200 if (cursor_type
== FILLED_BOX_CURSOR
)
22201 return HOLLOW_BOX_CURSOR
;
22203 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
22206 return cursor_type
;
22214 #ifdef HAVE_WINDOW_SYSTEM
22216 /* Notice when the text cursor of window W has been completely
22217 overwritten by a drawing operation that outputs glyphs in AREA
22218 starting at X0 and ending at X1 in the line starting at Y0 and
22219 ending at Y1. X coordinates are area-relative. X1 < 0 means all
22220 the rest of the line after X0 has been written. Y coordinates
22221 are window-relative. */
22224 notice_overwritten_cursor (w
, area
, x0
, x1
, y0
, y1
)
22226 enum glyph_row_area area
;
22227 int x0
, y0
, x1
, y1
;
22229 int cx0
, cx1
, cy0
, cy1
;
22230 struct glyph_row
*row
;
22232 if (!w
->phys_cursor_on_p
)
22234 if (area
!= TEXT_AREA
)
22237 if (w
->phys_cursor
.vpos
< 0
22238 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
22239 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
22240 !(row
->enabled_p
&& row
->displays_text_p
)))
22243 if (row
->cursor_in_fringe_p
)
22245 row
->cursor_in_fringe_p
= 0;
22246 draw_fringe_bitmap (w
, row
, 0);
22247 w
->phys_cursor_on_p
= 0;
22251 cx0
= w
->phys_cursor
.x
;
22252 cx1
= cx0
+ w
->phys_cursor_width
;
22253 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
22256 /* The cursor image will be completely removed from the
22257 screen if the output area intersects the cursor area in
22258 y-direction. When we draw in [y0 y1[, and some part of
22259 the cursor is at y < y0, that part must have been drawn
22260 before. When scrolling, the cursor is erased before
22261 actually scrolling, so we don't come here. When not
22262 scrolling, the rows above the old cursor row must have
22263 changed, and in this case these rows must have written
22264 over the cursor image.
22266 Likewise if part of the cursor is below y1, with the
22267 exception of the cursor being in the first blank row at
22268 the buffer and window end because update_text_area
22269 doesn't draw that row. (Except when it does, but
22270 that's handled in update_text_area.) */
22272 cy0
= w
->phys_cursor
.y
;
22273 cy1
= cy0
+ w
->phys_cursor_height
;
22274 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
22277 w
->phys_cursor_on_p
= 0;
22280 #endif /* HAVE_WINDOW_SYSTEM */
22283 /************************************************************************
22285 ************************************************************************/
22287 #ifdef HAVE_WINDOW_SYSTEM
22290 Fix the display of area AREA of overlapping row ROW in window W
22291 with respect to the overlapping part OVERLAPS. */
22294 x_fix_overlapping_area (w
, row
, area
, overlaps
)
22296 struct glyph_row
*row
;
22297 enum glyph_row_area area
;
22305 for (i
= 0; i
< row
->used
[area
];)
22307 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
22309 int start
= i
, start_x
= x
;
22313 x
+= row
->glyphs
[area
][i
].pixel_width
;
22316 while (i
< row
->used
[area
]
22317 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
22319 draw_glyphs (w
, start_x
, row
, area
,
22321 DRAW_NORMAL_TEXT
, overlaps
);
22325 x
+= row
->glyphs
[area
][i
].pixel_width
;
22335 Draw the cursor glyph of window W in glyph row ROW. See the
22336 comment of draw_glyphs for the meaning of HL. */
22339 draw_phys_cursor_glyph (w
, row
, hl
)
22341 struct glyph_row
*row
;
22342 enum draw_glyphs_face hl
;
22344 /* If cursor hpos is out of bounds, don't draw garbage. This can
22345 happen in mini-buffer windows when switching between echo area
22346 glyphs and mini-buffer. */
22347 if (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])
22349 int on_p
= w
->phys_cursor_on_p
;
22351 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
,
22352 w
->phys_cursor
.hpos
, w
->phys_cursor
.hpos
+ 1,
22354 w
->phys_cursor_on_p
= on_p
;
22356 if (hl
== DRAW_CURSOR
)
22357 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22358 /* When we erase the cursor, and ROW is overlapped by other
22359 rows, make sure that these overlapping parts of other rows
22361 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
22363 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
22365 if (row
> w
->current_matrix
->rows
22366 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
22367 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
22368 OVERLAPS_ERASED_CURSOR
);
22370 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
22371 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
22372 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
22373 OVERLAPS_ERASED_CURSOR
);
22380 Erase the image of a cursor of window W from the screen. */
22383 erase_phys_cursor (w
)
22386 struct frame
*f
= XFRAME (w
->frame
);
22387 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
22388 int hpos
= w
->phys_cursor
.hpos
;
22389 int vpos
= w
->phys_cursor
.vpos
;
22390 int mouse_face_here_p
= 0;
22391 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
22392 struct glyph_row
*cursor_row
;
22393 struct glyph
*cursor_glyph
;
22394 enum draw_glyphs_face hl
;
22396 /* No cursor displayed or row invalidated => nothing to do on the
22398 if (w
->phys_cursor_type
== NO_CURSOR
)
22399 goto mark_cursor_off
;
22401 /* VPOS >= active_glyphs->nrows means that window has been resized.
22402 Don't bother to erase the cursor. */
22403 if (vpos
>= active_glyphs
->nrows
)
22404 goto mark_cursor_off
;
22406 /* If row containing cursor is marked invalid, there is nothing we
22408 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
22409 if (!cursor_row
->enabled_p
)
22410 goto mark_cursor_off
;
22412 /* If line spacing is > 0, old cursor may only be partially visible in
22413 window after split-window. So adjust visible height. */
22414 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
22415 window_text_bottom_y (w
) - cursor_row
->y
);
22417 /* If row is completely invisible, don't attempt to delete a cursor which
22418 isn't there. This can happen if cursor is at top of a window, and
22419 we switch to a buffer with a header line in that window. */
22420 if (cursor_row
->visible_height
<= 0)
22421 goto mark_cursor_off
;
22423 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
22424 if (cursor_row
->cursor_in_fringe_p
)
22426 cursor_row
->cursor_in_fringe_p
= 0;
22427 draw_fringe_bitmap (w
, cursor_row
, 0);
22428 goto mark_cursor_off
;
22431 /* This can happen when the new row is shorter than the old one.
22432 In this case, either draw_glyphs or clear_end_of_line
22433 should have cleared the cursor. Note that we wouldn't be
22434 able to erase the cursor in this case because we don't have a
22435 cursor glyph at hand. */
22436 if (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])
22437 goto mark_cursor_off
;
22439 /* If the cursor is in the mouse face area, redisplay that when
22440 we clear the cursor. */
22441 if (! NILP (dpyinfo
->mouse_face_window
)
22442 && w
== XWINDOW (dpyinfo
->mouse_face_window
)
22443 && (vpos
> dpyinfo
->mouse_face_beg_row
22444 || (vpos
== dpyinfo
->mouse_face_beg_row
22445 && hpos
>= dpyinfo
->mouse_face_beg_col
))
22446 && (vpos
< dpyinfo
->mouse_face_end_row
22447 || (vpos
== dpyinfo
->mouse_face_end_row
22448 && hpos
< dpyinfo
->mouse_face_end_col
))
22449 /* Don't redraw the cursor's spot in mouse face if it is at the
22450 end of a line (on a newline). The cursor appears there, but
22451 mouse highlighting does not. */
22452 && cursor_row
->used
[TEXT_AREA
] > hpos
)
22453 mouse_face_here_p
= 1;
22455 /* Maybe clear the display under the cursor. */
22456 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
22459 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
22462 cursor_glyph
= get_phys_cursor_glyph (w
);
22463 if (cursor_glyph
== NULL
)
22464 goto mark_cursor_off
;
22466 width
= cursor_glyph
->pixel_width
;
22467 left_x
= window_box_left_offset (w
, TEXT_AREA
);
22468 x
= w
->phys_cursor
.x
;
22470 width
-= left_x
- x
;
22471 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
22472 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
22473 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
22476 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
22479 /* Erase the cursor by redrawing the character underneath it. */
22480 if (mouse_face_here_p
)
22481 hl
= DRAW_MOUSE_FACE
;
22483 hl
= DRAW_NORMAL_TEXT
;
22484 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
22487 w
->phys_cursor_on_p
= 0;
22488 w
->phys_cursor_type
= NO_CURSOR
;
22493 Display or clear cursor of window W. If ON is zero, clear the
22494 cursor. If it is non-zero, display the cursor. If ON is nonzero,
22495 where to put the cursor is specified by HPOS, VPOS, X and Y. */
22498 display_and_set_cursor (w
, on
, hpos
, vpos
, x
, y
)
22500 int on
, hpos
, vpos
, x
, y
;
22502 struct frame
*f
= XFRAME (w
->frame
);
22503 int new_cursor_type
;
22504 int new_cursor_width
;
22506 struct glyph_row
*glyph_row
;
22507 struct glyph
*glyph
;
22509 /* This is pointless on invisible frames, and dangerous on garbaged
22510 windows and frames; in the latter case, the frame or window may
22511 be in the midst of changing its size, and x and y may be off the
22513 if (! FRAME_VISIBLE_P (f
)
22514 || FRAME_GARBAGED_P (f
)
22515 || vpos
>= w
->current_matrix
->nrows
22516 || hpos
>= w
->current_matrix
->matrix_w
)
22519 /* If cursor is off and we want it off, return quickly. */
22520 if (!on
&& !w
->phys_cursor_on_p
)
22523 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
22524 /* If cursor row is not enabled, we don't really know where to
22525 display the cursor. */
22526 if (!glyph_row
->enabled_p
)
22528 w
->phys_cursor_on_p
= 0;
22533 if (!glyph_row
->exact_window_width_line_p
22534 || hpos
< glyph_row
->used
[TEXT_AREA
])
22535 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
22537 xassert (interrupt_input_blocked
);
22539 /* Set new_cursor_type to the cursor we want to be displayed. */
22540 new_cursor_type
= get_window_cursor_type (w
, glyph
,
22541 &new_cursor_width
, &active_cursor
);
22543 /* If cursor is currently being shown and we don't want it to be or
22544 it is in the wrong place, or the cursor type is not what we want,
22546 if (w
->phys_cursor_on_p
22548 || w
->phys_cursor
.x
!= x
22549 || w
->phys_cursor
.y
!= y
22550 || new_cursor_type
!= w
->phys_cursor_type
22551 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
22552 && new_cursor_width
!= w
->phys_cursor_width
)))
22553 erase_phys_cursor (w
);
22555 /* Don't check phys_cursor_on_p here because that flag is only set
22556 to zero in some cases where we know that the cursor has been
22557 completely erased, to avoid the extra work of erasing the cursor
22558 twice. In other words, phys_cursor_on_p can be 1 and the cursor
22559 still not be visible, or it has only been partly erased. */
22562 w
->phys_cursor_ascent
= glyph_row
->ascent
;
22563 w
->phys_cursor_height
= glyph_row
->height
;
22565 /* Set phys_cursor_.* before x_draw_.* is called because some
22566 of them may need the information. */
22567 w
->phys_cursor
.x
= x
;
22568 w
->phys_cursor
.y
= glyph_row
->y
;
22569 w
->phys_cursor
.hpos
= hpos
;
22570 w
->phys_cursor
.vpos
= vpos
;
22573 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
22574 new_cursor_type
, new_cursor_width
,
22575 on
, active_cursor
);
22579 /* Switch the display of W's cursor on or off, according to the value
22586 update_window_cursor (w
, on
)
22590 /* Don't update cursor in windows whose frame is in the process
22591 of being deleted. */
22592 if (w
->current_matrix
)
22595 display_and_set_cursor (w
, on
, w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22596 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22602 /* Call update_window_cursor with parameter ON_P on all leaf windows
22603 in the window tree rooted at W. */
22606 update_cursor_in_window_tree (w
, on_p
)
22612 if (!NILP (w
->hchild
))
22613 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
22614 else if (!NILP (w
->vchild
))
22615 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
22617 update_window_cursor (w
, on_p
);
22619 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
22625 Display the cursor on window W, or clear it, according to ON_P.
22626 Don't change the cursor's position. */
22629 x_update_cursor (f
, on_p
)
22633 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
22638 Clear the cursor of window W to background color, and mark the
22639 cursor as not shown. This is used when the text where the cursor
22640 is is about to be rewritten. */
22646 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
22647 update_window_cursor (w
, 0);
22652 Display the active region described by mouse_face_* according to DRAW. */
22655 show_mouse_face (dpyinfo
, draw
)
22656 Display_Info
*dpyinfo
;
22657 enum draw_glyphs_face draw
;
22659 struct window
*w
= XWINDOW (dpyinfo
->mouse_face_window
);
22660 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22662 if (/* If window is in the process of being destroyed, don't bother
22664 w
->current_matrix
!= NULL
22665 /* Don't update mouse highlight if hidden */
22666 && (draw
!= DRAW_MOUSE_FACE
|| !dpyinfo
->mouse_face_hidden
)
22667 /* Recognize when we are called to operate on rows that don't exist
22668 anymore. This can happen when a window is split. */
22669 && dpyinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
22671 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
22672 struct glyph_row
*row
, *first
, *last
;
22674 first
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_beg_row
);
22675 last
= MATRIX_ROW (w
->current_matrix
, dpyinfo
->mouse_face_end_row
);
22677 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
22679 int start_hpos
, end_hpos
, start_x
;
22681 /* For all but the first row, the highlight starts at column 0. */
22684 start_hpos
= dpyinfo
->mouse_face_beg_col
;
22685 start_x
= dpyinfo
->mouse_face_beg_x
;
22694 end_hpos
= dpyinfo
->mouse_face_end_col
;
22697 end_hpos
= row
->used
[TEXT_AREA
];
22698 if (draw
== DRAW_NORMAL_TEXT
)
22699 row
->fill_line_p
= 1; /* Clear to end of line */
22702 if (end_hpos
> start_hpos
)
22704 draw_glyphs (w
, start_x
, row
, TEXT_AREA
,
22705 start_hpos
, end_hpos
,
22709 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
22713 /* When we've written over the cursor, arrange for it to
22714 be displayed again. */
22715 if (phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
22718 display_and_set_cursor (w
, 1,
22719 w
->phys_cursor
.hpos
, w
->phys_cursor
.vpos
,
22720 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
22725 /* Change the mouse cursor. */
22726 if (draw
== DRAW_NORMAL_TEXT
&& !EQ (dpyinfo
->mouse_face_window
, f
->tool_bar_window
))
22727 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
22728 else if (draw
== DRAW_MOUSE_FACE
)
22729 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
22731 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
22735 Clear out the mouse-highlighted active region.
22736 Redraw it un-highlighted first. Value is non-zero if mouse
22737 face was actually drawn unhighlighted. */
22740 clear_mouse_face (dpyinfo
)
22741 Display_Info
*dpyinfo
;
22745 if (!dpyinfo
->mouse_face_hidden
&& !NILP (dpyinfo
->mouse_face_window
))
22747 show_mouse_face (dpyinfo
, DRAW_NORMAL_TEXT
);
22751 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
22752 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
22753 dpyinfo
->mouse_face_window
= Qnil
;
22754 dpyinfo
->mouse_face_overlay
= Qnil
;
22760 Non-zero if physical cursor of window W is within mouse face. */
22763 cursor_in_mouse_face_p (w
)
22766 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
22767 int in_mouse_face
= 0;
22769 if (WINDOWP (dpyinfo
->mouse_face_window
)
22770 && XWINDOW (dpyinfo
->mouse_face_window
) == w
)
22772 int hpos
= w
->phys_cursor
.hpos
;
22773 int vpos
= w
->phys_cursor
.vpos
;
22775 if (vpos
>= dpyinfo
->mouse_face_beg_row
22776 && vpos
<= dpyinfo
->mouse_face_end_row
22777 && (vpos
> dpyinfo
->mouse_face_beg_row
22778 || hpos
>= dpyinfo
->mouse_face_beg_col
)
22779 && (vpos
< dpyinfo
->mouse_face_end_row
22780 || hpos
< dpyinfo
->mouse_face_end_col
22781 || dpyinfo
->mouse_face_past_end
))
22785 return in_mouse_face
;
22791 /* Find the glyph matrix position of buffer position CHARPOS in window
22792 *W. HPOS, *VPOS, *X, and *Y are set to the positions found. W's
22793 current glyphs must be up to date. If CHARPOS is above window
22794 start return (0, 0, 0, 0). If CHARPOS is after end of W, return end
22795 of last line in W. In the row containing CHARPOS, stop before glyphs
22796 having STOP as object. */
22798 #if 1 /* This is a version of fast_find_position that's more correct
22799 in the presence of hscrolling, for example. I didn't install
22800 it right away because the problem fixed is minor, it failed
22801 in 20.x as well, and I think it's too risky to install
22802 so near the release of 21.1. 2001-09-25 gerd. */
22806 fast_find_position (w
, charpos
, hpos
, vpos
, x
, y
, stop
)
22809 int *hpos
, *vpos
, *x
, *y
;
22812 struct glyph_row
*row
, *first
;
22813 struct glyph
*glyph
, *end
;
22816 first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22817 if (charpos
< MATRIX_ROW_START_CHARPOS (first
))
22822 *vpos
= MATRIX_ROW_VPOS (first
, w
->current_matrix
);
22826 row
= row_containing_pos (w
, charpos
, first
, NULL
, 0);
22829 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
22833 /* If whole rows or last part of a row came from a display overlay,
22834 row_containing_pos will skip over such rows because their end pos
22835 equals the start pos of the overlay or interval.
22837 Move back if we have a STOP object and previous row's
22838 end glyph came from STOP. */
22841 struct glyph_row
*prev
;
22842 while ((prev
= row
- 1, prev
>= first
)
22843 && MATRIX_ROW_END_CHARPOS (prev
) == charpos
22844 && prev
->used
[TEXT_AREA
] > 0)
22846 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
22847 glyph
= beg
+ prev
->used
[TEXT_AREA
];
22848 while (--glyph
>= beg
22849 && INTEGERP (glyph
->object
));
22851 || !EQ (stop
, glyph
->object
))
22859 *vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22861 glyph
= row
->glyphs
[TEXT_AREA
];
22862 end
= glyph
+ row
->used
[TEXT_AREA
];
22864 /* Skip over glyphs not having an object at the start of the row.
22865 These are special glyphs like truncation marks on terminal
22867 if (row
->displays_text_p
)
22869 && INTEGERP (glyph
->object
)
22870 && !EQ (stop
, glyph
->object
)
22871 && glyph
->charpos
< 0)
22873 *x
+= glyph
->pixel_width
;
22878 && !INTEGERP (glyph
->object
)
22879 && !EQ (stop
, glyph
->object
)
22880 && (!BUFFERP (glyph
->object
)
22881 || glyph
->charpos
< charpos
))
22883 *x
+= glyph
->pixel_width
;
22887 *hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
22894 fast_find_position (w
, pos
, hpos
, vpos
, x
, y
, stop
)
22897 int *hpos
, *vpos
, *x
, *y
;
22902 int maybe_next_line_p
= 0;
22903 int line_start_position
;
22904 int yb
= window_text_bottom_y (w
);
22905 struct glyph_row
*row
, *best_row
;
22906 int row_vpos
, best_row_vpos
;
22909 row
= best_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
22910 row_vpos
= best_row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
22912 while (row
->y
< yb
)
22914 if (row
->used
[TEXT_AREA
])
22915 line_start_position
= row
->glyphs
[TEXT_AREA
]->charpos
;
22917 line_start_position
= 0;
22919 if (line_start_position
> pos
)
22921 /* If the position sought is the end of the buffer,
22922 don't include the blank lines at the bottom of the window. */
22923 else if (line_start_position
== pos
22924 && pos
== BUF_ZV (XBUFFER (w
->buffer
)))
22926 maybe_next_line_p
= 1;
22929 else if (line_start_position
> 0)
22932 best_row_vpos
= row_vpos
;
22935 if (row
->y
+ row
->height
>= yb
)
22942 /* Find the right column within BEST_ROW. */
22944 current_x
= best_row
->x
;
22945 for (i
= 0; i
< best_row
->used
[TEXT_AREA
]; i
++)
22947 struct glyph
*glyph
= best_row
->glyphs
[TEXT_AREA
] + i
;
22948 int charpos
= glyph
->charpos
;
22950 if (BUFFERP (glyph
->object
))
22952 if (charpos
== pos
)
22955 *vpos
= best_row_vpos
;
22960 else if (charpos
> pos
)
22963 else if (EQ (glyph
->object
, stop
))
22968 current_x
+= glyph
->pixel_width
;
22971 /* If we're looking for the end of the buffer,
22972 and we didn't find it in the line we scanned,
22973 use the start of the following line. */
22974 if (maybe_next_line_p
)
22979 current_x
= best_row
->x
;
22982 *vpos
= best_row_vpos
;
22983 *hpos
= lastcol
+ 1;
22992 /* Find the position of the glyph for position POS in OBJECT in
22993 window W's current matrix, and return in *X, *Y the pixel
22994 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
22996 RIGHT_P non-zero means return the position of the right edge of the
22997 glyph, RIGHT_P zero means return the left edge position.
22999 If no glyph for POS exists in the matrix, return the position of
23000 the glyph with the next smaller position that is in the matrix, if
23001 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
23002 exists in the matrix, return the position of the glyph with the
23003 next larger position in OBJECT.
23005 Value is non-zero if a glyph was found. */
23008 fast_find_string_pos (w
, pos
, object
, hpos
, vpos
, x
, y
, right_p
)
23011 Lisp_Object object
;
23012 int *hpos
, *vpos
, *x
, *y
;
23015 int yb
= window_text_bottom_y (w
);
23016 struct glyph_row
*r
;
23017 struct glyph
*best_glyph
= NULL
;
23018 struct glyph_row
*best_row
= NULL
;
23021 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
23022 r
->enabled_p
&& r
->y
< yb
;
23025 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
23026 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
23029 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
23030 if (EQ (g
->object
, object
))
23032 if (g
->charpos
== pos
)
23039 else if (best_glyph
== NULL
23040 || ((eabs (g
->charpos
- pos
)
23041 < eabs (best_glyph
->charpos
- pos
))
23044 : g
->charpos
> pos
)))
23058 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
23062 *x
+= best_glyph
->pixel_width
;
23067 *vpos
= best_row
- w
->current_matrix
->rows
;
23070 return best_glyph
!= NULL
;
23074 /* See if position X, Y is within a hot-spot of an image. */
23077 on_hot_spot_p (hot_spot
, x
, y
)
23078 Lisp_Object hot_spot
;
23081 if (!CONSP (hot_spot
))
23084 if (EQ (XCAR (hot_spot
), Qrect
))
23086 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
23087 Lisp_Object rect
= XCDR (hot_spot
);
23091 if (!CONSP (XCAR (rect
)))
23093 if (!CONSP (XCDR (rect
)))
23095 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
23097 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
23099 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
23101 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
23105 else if (EQ (XCAR (hot_spot
), Qcircle
))
23107 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
23108 Lisp_Object circ
= XCDR (hot_spot
);
23109 Lisp_Object lr
, lx0
, ly0
;
23111 && CONSP (XCAR (circ
))
23112 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
23113 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
23114 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
23116 double r
= XFLOATINT (lr
);
23117 double dx
= XINT (lx0
) - x
;
23118 double dy
= XINT (ly0
) - y
;
23119 return (dx
* dx
+ dy
* dy
<= r
* r
);
23122 else if (EQ (XCAR (hot_spot
), Qpoly
))
23124 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
23125 if (VECTORP (XCDR (hot_spot
)))
23127 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
23128 Lisp_Object
*poly
= v
->contents
;
23132 Lisp_Object lx
, ly
;
23135 /* Need an even number of coordinates, and at least 3 edges. */
23136 if (n
< 6 || n
& 1)
23139 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
23140 If count is odd, we are inside polygon. Pixels on edges
23141 may or may not be included depending on actual geometry of the
23143 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
23144 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
23146 x0
= XINT (lx
), y0
= XINT (ly
);
23147 for (i
= 0; i
< n
; i
+= 2)
23149 int x1
= x0
, y1
= y0
;
23150 if ((lx
= poly
[i
], !INTEGERP (lx
))
23151 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
23153 x0
= XINT (lx
), y0
= XINT (ly
);
23155 /* Does this segment cross the X line? */
23163 if (y
> y0
&& y
> y1
)
23165 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
23175 find_hot_spot (map
, x
, y
)
23179 while (CONSP (map
))
23181 if (CONSP (XCAR (map
))
23182 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
23190 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
23192 doc
: /* Lookup in image map MAP coordinates X and Y.
23193 An image map is an alist where each element has the format (AREA ID PLIST).
23194 An AREA is specified as either a rectangle, a circle, or a polygon:
23195 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
23196 pixel coordinates of the upper left and bottom right corners.
23197 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
23198 and the radius of the circle; r may be a float or integer.
23199 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
23200 vector describes one corner in the polygon.
23201 Returns the alist element for the first matching AREA in MAP. */)
23212 return find_hot_spot (map
, XINT (x
), XINT (y
));
23216 /* Display frame CURSOR, optionally using shape defined by POINTER. */
23218 define_frame_cursor1 (f
, cursor
, pointer
)
23221 Lisp_Object pointer
;
23223 /* Do not change cursor shape while dragging mouse. */
23224 if (!NILP (do_mouse_tracking
))
23227 if (!NILP (pointer
))
23229 if (EQ (pointer
, Qarrow
))
23230 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23231 else if (EQ (pointer
, Qhand
))
23232 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
23233 else if (EQ (pointer
, Qtext
))
23234 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23235 else if (EQ (pointer
, intern ("hdrag")))
23236 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23237 #ifdef HAVE_X_WINDOWS
23238 else if (EQ (pointer
, intern ("vdrag")))
23239 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
23241 else if (EQ (pointer
, intern ("hourglass")))
23242 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
23243 else if (EQ (pointer
, Qmodeline
))
23244 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
23246 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23249 if (cursor
!= No_Cursor
)
23250 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
23253 /* Take proper action when mouse has moved to the mode or header line
23254 or marginal area AREA of window W, x-position X and y-position Y.
23255 X is relative to the start of the text display area of W, so the
23256 width of bitmap areas and scroll bars must be subtracted to get a
23257 position relative to the start of the mode line. */
23260 note_mode_line_or_margin_highlight (window
, x
, y
, area
)
23261 Lisp_Object window
;
23263 enum window_part area
;
23265 struct window
*w
= XWINDOW (window
);
23266 struct frame
*f
= XFRAME (w
->frame
);
23267 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23268 Cursor cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23269 Lisp_Object pointer
= Qnil
;
23270 int charpos
, dx
, dy
, width
, height
;
23271 Lisp_Object string
, object
= Qnil
;
23272 Lisp_Object pos
, help
;
23274 Lisp_Object mouse_face
;
23275 int original_x_pixel
= x
;
23276 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
23277 struct glyph_row
*row
;
23279 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
23284 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
23285 &object
, &dx
, &dy
, &width
, &height
);
23287 row
= (area
== ON_MODE_LINE
23288 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
23289 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
23292 if (row
->mode_line_p
&& row
->enabled_p
)
23294 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
23295 end
= glyph
+ row
->used
[TEXT_AREA
];
23297 for (x0
= original_x_pixel
;
23298 glyph
< end
&& x0
>= glyph
->pixel_width
;
23300 x0
-= glyph
->pixel_width
;
23308 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
23309 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
23310 &object
, &dx
, &dy
, &width
, &height
);
23315 if (IMAGEP (object
))
23317 Lisp_Object image_map
, hotspot
;
23318 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
23320 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
23322 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23324 Lisp_Object area_id
, plist
;
23326 area_id
= XCAR (hotspot
);
23327 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23328 If so, we could look for mouse-enter, mouse-leave
23329 properties in PLIST (and do something...). */
23330 hotspot
= XCDR (hotspot
);
23331 if (CONSP (hotspot
)
23332 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23334 pointer
= Fplist_get (plist
, Qpointer
);
23335 if (NILP (pointer
))
23337 help
= Fplist_get (plist
, Qhelp_echo
);
23340 help_echo_string
= help
;
23341 /* Is this correct? ++kfs */
23342 XSETWINDOW (help_echo_window
, w
);
23343 help_echo_object
= w
->buffer
;
23344 help_echo_pos
= charpos
;
23348 if (NILP (pointer
))
23349 pointer
= Fplist_get (XCDR (object
), QCpointer
);
23352 if (STRINGP (string
))
23354 pos
= make_number (charpos
);
23355 /* If we're on a string with `help-echo' text property, arrange
23356 for the help to be displayed. This is done by setting the
23357 global variable help_echo_string to the help string. */
23360 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
23363 help_echo_string
= help
;
23364 XSETWINDOW (help_echo_window
, w
);
23365 help_echo_object
= string
;
23366 help_echo_pos
= charpos
;
23370 if (NILP (pointer
))
23371 pointer
= Fget_text_property (pos
, Qpointer
, string
);
23373 /* Change the mouse pointer according to what is under X/Y. */
23374 if (NILP (pointer
) && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
23377 map
= Fget_text_property (pos
, Qlocal_map
, string
);
23378 if (!KEYMAPP (map
))
23379 map
= Fget_text_property (pos
, Qkeymap
, string
);
23380 if (!KEYMAPP (map
))
23381 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
23384 /* Change the mouse face according to what is under X/Y. */
23385 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
23386 if (!NILP (mouse_face
)
23387 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23392 struct glyph
* tmp_glyph
;
23396 int total_pixel_width
;
23401 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
23402 Qmouse_face
, string
, Qnil
);
23404 b
= make_number (0);
23406 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
23408 e
= make_number (SCHARS (string
));
23410 /* Calculate the position(glyph position: GPOS) of GLYPH in
23411 displayed string. GPOS is different from CHARPOS.
23413 CHARPOS is the position of glyph in internal string
23414 object. A mode line string format has structures which
23415 is converted to a flatten by emacs lisp interpreter.
23416 The internal string is an element of the structures.
23417 The displayed string is the flatten string. */
23419 if (glyph
> row_start_glyph
)
23421 tmp_glyph
= glyph
- 1;
23422 while (tmp_glyph
>= row_start_glyph
23423 && tmp_glyph
->charpos
>= XINT (b
)
23424 && EQ (tmp_glyph
->object
, glyph
->object
))
23431 /* Calculate the lenght(glyph sequence length: GSEQ_LENGTH) of
23432 displayed string holding GLYPH.
23434 GSEQ_LENGTH is different from SCHARS (STRING).
23435 SCHARS (STRING) returns the length of the internal string. */
23436 for (tmp_glyph
= glyph
, gseq_length
= gpos
;
23437 tmp_glyph
->charpos
< XINT (e
);
23438 tmp_glyph
++, gseq_length
++)
23440 if (!EQ (tmp_glyph
->object
, glyph
->object
))
23444 total_pixel_width
= 0;
23445 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
23446 total_pixel_width
+= tmp_glyph
->pixel_width
;
23448 /* Pre calculation of re-rendering position */
23450 hpos
= (area
== ON_MODE_LINE
23451 ? (w
->current_matrix
)->nrows
- 1
23454 /* If the re-rendering position is included in the last
23455 re-rendering area, we should do nothing. */
23456 if ( EQ (window
, dpyinfo
->mouse_face_window
)
23457 && dpyinfo
->mouse_face_beg_col
<= vpos
23458 && vpos
< dpyinfo
->mouse_face_end_col
23459 && dpyinfo
->mouse_face_beg_row
== hpos
)
23462 if (clear_mouse_face (dpyinfo
))
23463 cursor
= No_Cursor
;
23465 dpyinfo
->mouse_face_beg_col
= vpos
;
23466 dpyinfo
->mouse_face_beg_row
= hpos
;
23468 dpyinfo
->mouse_face_beg_x
= original_x_pixel
- (total_pixel_width
+ dx
);
23469 dpyinfo
->mouse_face_beg_y
= 0;
23471 dpyinfo
->mouse_face_end_col
= vpos
+ gseq_length
;
23472 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_beg_row
;
23474 dpyinfo
->mouse_face_end_x
= 0;
23475 dpyinfo
->mouse_face_end_y
= 0;
23477 dpyinfo
->mouse_face_past_end
= 0;
23478 dpyinfo
->mouse_face_window
= window
;
23480 dpyinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
23483 glyph
->face_id
, 1);
23484 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23486 if (NILP (pointer
))
23489 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
23490 clear_mouse_face (dpyinfo
);
23492 define_frame_cursor1 (f
, cursor
, pointer
);
23497 Take proper action when the mouse has moved to position X, Y on
23498 frame F as regards highlighting characters that have mouse-face
23499 properties. Also de-highlighting chars where the mouse was before.
23500 X and Y can be negative or out of range. */
23503 note_mouse_highlight (f
, x
, y
)
23507 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
23508 enum window_part part
;
23509 Lisp_Object window
;
23511 Cursor cursor
= No_Cursor
;
23512 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
23515 /* When a menu is active, don't highlight because this looks odd. */
23516 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
23517 if (popup_activated ())
23521 if (NILP (Vmouse_highlight
)
23522 || !f
->glyphs_initialized_p
)
23525 dpyinfo
->mouse_face_mouse_x
= x
;
23526 dpyinfo
->mouse_face_mouse_y
= y
;
23527 dpyinfo
->mouse_face_mouse_frame
= f
;
23529 if (dpyinfo
->mouse_face_defer
)
23532 if (gc_in_progress
)
23534 dpyinfo
->mouse_face_deferred_gc
= 1;
23538 /* Which window is that in? */
23539 window
= window_from_coordinates (f
, x
, y
, &part
, 0, 0, 1);
23541 /* If we were displaying active text in another window, clear that.
23542 Also clear if we move out of text area in same window. */
23543 if (! EQ (window
, dpyinfo
->mouse_face_window
)
23544 || (part
!= ON_TEXT
&& part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
23545 && !NILP (dpyinfo
->mouse_face_window
)))
23546 clear_mouse_face (dpyinfo
);
23548 /* Not on a window -> return. */
23549 if (!WINDOWP (window
))
23552 /* Reset help_echo_string. It will get recomputed below. */
23553 help_echo_string
= Qnil
;
23555 /* Convert to window-relative pixel coordinates. */
23556 w
= XWINDOW (window
);
23557 frame_to_window_pixel_xy (w
, &x
, &y
);
23559 /* Handle tool-bar window differently since it doesn't display a
23561 if (EQ (window
, f
->tool_bar_window
))
23563 note_tool_bar_highlight (f
, x
, y
);
23567 /* Mouse is on the mode, header line or margin? */
23568 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
23569 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
23571 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
23575 if (part
== ON_VERTICAL_BORDER
)
23577 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
23578 help_echo_string
= build_string ("drag-mouse-1: resize");
23580 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
23581 || part
== ON_SCROLL_BAR
)
23582 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23584 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
23586 /* Are we in a window whose display is up to date?
23587 And verify the buffer's text has not changed. */
23588 b
= XBUFFER (w
->buffer
);
23589 if (part
== ON_TEXT
23590 && EQ (w
->window_end_valid
, w
->buffer
)
23591 && XFASTINT (w
->last_modified
) == BUF_MODIFF (b
)
23592 && XFASTINT (w
->last_overlay_modified
) == BUF_OVERLAY_MODIFF (b
))
23594 int hpos
, vpos
, pos
, i
, dx
, dy
, area
;
23595 struct glyph
*glyph
;
23596 Lisp_Object object
;
23597 Lisp_Object mouse_face
= Qnil
, overlay
= Qnil
, position
;
23598 Lisp_Object
*overlay_vec
= NULL
;
23600 struct buffer
*obuf
;
23601 int obegv
, ozv
, same_region
;
23603 /* Find the glyph under X/Y. */
23604 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
23606 /* Look for :pointer property on image. */
23607 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
23609 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
23610 if (img
!= NULL
&& IMAGEP (img
->spec
))
23612 Lisp_Object image_map
, hotspot
;
23613 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
23615 && (hotspot
= find_hot_spot (image_map
,
23616 glyph
->slice
.x
+ dx
,
23617 glyph
->slice
.y
+ dy
),
23619 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
23621 Lisp_Object area_id
, plist
;
23623 area_id
= XCAR (hotspot
);
23624 /* Could check AREA_ID to see if we enter/leave this hot-spot.
23625 If so, we could look for mouse-enter, mouse-leave
23626 properties in PLIST (and do something...). */
23627 hotspot
= XCDR (hotspot
);
23628 if (CONSP (hotspot
)
23629 && (plist
= XCAR (hotspot
), CONSP (plist
)))
23631 pointer
= Fplist_get (plist
, Qpointer
);
23632 if (NILP (pointer
))
23634 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
23635 if (!NILP (help_echo_string
))
23637 help_echo_window
= window
;
23638 help_echo_object
= glyph
->object
;
23639 help_echo_pos
= glyph
->charpos
;
23643 if (NILP (pointer
))
23644 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
23648 /* Clear mouse face if X/Y not over text. */
23650 || area
!= TEXT_AREA
23651 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
)
23653 if (clear_mouse_face (dpyinfo
))
23654 cursor
= No_Cursor
;
23655 if (NILP (pointer
))
23657 if (area
!= TEXT_AREA
)
23658 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
23660 pointer
= Vvoid_text_area_pointer
;
23665 pos
= glyph
->charpos
;
23666 object
= glyph
->object
;
23667 if (!STRINGP (object
) && !BUFFERP (object
))
23670 /* If we get an out-of-range value, return now; avoid an error. */
23671 if (BUFFERP (object
) && pos
> BUF_Z (b
))
23674 /* Make the window's buffer temporarily current for
23675 overlays_at and compute_char_face. */
23676 obuf
= current_buffer
;
23677 current_buffer
= b
;
23683 /* Is this char mouse-active or does it have help-echo? */
23684 position
= make_number (pos
);
23686 if (BUFFERP (object
))
23688 /* Put all the overlays we want in a vector in overlay_vec. */
23689 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
23690 /* Sort overlays into increasing priority order. */
23691 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
23696 same_region
= (EQ (window
, dpyinfo
->mouse_face_window
)
23697 && vpos
>= dpyinfo
->mouse_face_beg_row
23698 && vpos
<= dpyinfo
->mouse_face_end_row
23699 && (vpos
> dpyinfo
->mouse_face_beg_row
23700 || hpos
>= dpyinfo
->mouse_face_beg_col
)
23701 && (vpos
< dpyinfo
->mouse_face_end_row
23702 || hpos
< dpyinfo
->mouse_face_end_col
23703 || dpyinfo
->mouse_face_past_end
));
23706 cursor
= No_Cursor
;
23708 /* Check mouse-face highlighting. */
23710 /* If there exists an overlay with mouse-face overlapping
23711 the one we are currently highlighting, we have to
23712 check if we enter the overlapping overlay, and then
23713 highlight only that. */
23714 || (OVERLAYP (dpyinfo
->mouse_face_overlay
)
23715 && mouse_face_overlay_overlaps (dpyinfo
->mouse_face_overlay
)))
23717 /* Find the highest priority overlay that has a mouse-face
23720 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
23722 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
23723 if (!NILP (mouse_face
))
23724 overlay
= overlay_vec
[i
];
23727 /* If we're actually highlighting the same overlay as
23728 before, there's no need to do that again. */
23729 if (!NILP (overlay
)
23730 && EQ (overlay
, dpyinfo
->mouse_face_overlay
))
23731 goto check_help_echo
;
23733 dpyinfo
->mouse_face_overlay
= overlay
;
23735 /* Clear the display of the old active region, if any. */
23736 if (clear_mouse_face (dpyinfo
))
23737 cursor
= No_Cursor
;
23739 /* If no overlay applies, get a text property. */
23740 if (NILP (overlay
))
23741 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
23743 /* Handle the overlay case. */
23744 if (!NILP (overlay
))
23746 /* Find the range of text around this char that
23747 should be active. */
23748 Lisp_Object before
, after
;
23751 before
= Foverlay_start (overlay
);
23752 after
= Foverlay_end (overlay
);
23753 /* Record this as the current active region. */
23754 fast_find_position (w
, XFASTINT (before
),
23755 &dpyinfo
->mouse_face_beg_col
,
23756 &dpyinfo
->mouse_face_beg_row
,
23757 &dpyinfo
->mouse_face_beg_x
,
23758 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23760 dpyinfo
->mouse_face_past_end
23761 = !fast_find_position (w
, XFASTINT (after
),
23762 &dpyinfo
->mouse_face_end_col
,
23763 &dpyinfo
->mouse_face_end_row
,
23764 &dpyinfo
->mouse_face_end_x
,
23765 &dpyinfo
->mouse_face_end_y
, Qnil
);
23766 dpyinfo
->mouse_face_window
= window
;
23768 dpyinfo
->mouse_face_face_id
23769 = face_at_buffer_position (w
, pos
, 0, 0,
23771 !dpyinfo
->mouse_face_hidden
);
23773 /* Display it as active. */
23774 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23775 cursor
= No_Cursor
;
23777 /* Handle the text property case. */
23778 else if (!NILP (mouse_face
) && BUFFERP (object
))
23780 /* Find the range of text around this char that
23781 should be active. */
23782 Lisp_Object before
, after
, beginning
, end
;
23785 beginning
= Fmarker_position (w
->start
);
23786 end
= make_number (BUF_Z (XBUFFER (object
))
23787 - XFASTINT (w
->window_end_pos
));
23789 = Fprevious_single_property_change (make_number (pos
+ 1),
23791 object
, beginning
);
23793 = Fnext_single_property_change (position
, Qmouse_face
,
23796 /* Record this as the current active region. */
23797 fast_find_position (w
, XFASTINT (before
),
23798 &dpyinfo
->mouse_face_beg_col
,
23799 &dpyinfo
->mouse_face_beg_row
,
23800 &dpyinfo
->mouse_face_beg_x
,
23801 &dpyinfo
->mouse_face_beg_y
, Qnil
);
23802 dpyinfo
->mouse_face_past_end
23803 = !fast_find_position (w
, XFASTINT (after
),
23804 &dpyinfo
->mouse_face_end_col
,
23805 &dpyinfo
->mouse_face_end_row
,
23806 &dpyinfo
->mouse_face_end_x
,
23807 &dpyinfo
->mouse_face_end_y
, Qnil
);
23808 dpyinfo
->mouse_face_window
= window
;
23810 if (BUFFERP (object
))
23811 dpyinfo
->mouse_face_face_id
23812 = face_at_buffer_position (w
, pos
, 0, 0,
23814 !dpyinfo
->mouse_face_hidden
);
23816 /* Display it as active. */
23817 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23818 cursor
= No_Cursor
;
23820 else if (!NILP (mouse_face
) && STRINGP (object
))
23825 b
= Fprevious_single_property_change (make_number (pos
+ 1),
23828 e
= Fnext_single_property_change (position
, Qmouse_face
,
23831 b
= make_number (0);
23833 e
= make_number (SCHARS (object
) - 1);
23835 fast_find_string_pos (w
, XINT (b
), object
,
23836 &dpyinfo
->mouse_face_beg_col
,
23837 &dpyinfo
->mouse_face_beg_row
,
23838 &dpyinfo
->mouse_face_beg_x
,
23839 &dpyinfo
->mouse_face_beg_y
, 0);
23840 fast_find_string_pos (w
, XINT (e
), object
,
23841 &dpyinfo
->mouse_face_end_col
,
23842 &dpyinfo
->mouse_face_end_row
,
23843 &dpyinfo
->mouse_face_end_x
,
23844 &dpyinfo
->mouse_face_end_y
, 1);
23845 dpyinfo
->mouse_face_past_end
= 0;
23846 dpyinfo
->mouse_face_window
= window
;
23847 dpyinfo
->mouse_face_face_id
23848 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
23849 glyph
->face_id
, 1);
23850 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23851 cursor
= No_Cursor
;
23853 else if (STRINGP (object
) && NILP (mouse_face
))
23855 /* A string which doesn't have mouse-face, but
23856 the text ``under'' it might have. */
23857 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
23858 int start
= MATRIX_ROW_START_CHARPOS (r
);
23860 pos
= string_buffer_position (w
, object
, start
);
23862 mouse_face
= get_char_property_and_overlay (make_number (pos
),
23866 if (!NILP (mouse_face
) && !NILP (overlay
))
23868 Lisp_Object before
= Foverlay_start (overlay
);
23869 Lisp_Object after
= Foverlay_end (overlay
);
23872 /* Note that we might not be able to find position
23873 BEFORE in the glyph matrix if the overlay is
23874 entirely covered by a `display' property. In
23875 this case, we overshoot. So let's stop in
23876 the glyph matrix before glyphs for OBJECT. */
23877 fast_find_position (w
, XFASTINT (before
),
23878 &dpyinfo
->mouse_face_beg_col
,
23879 &dpyinfo
->mouse_face_beg_row
,
23880 &dpyinfo
->mouse_face_beg_x
,
23881 &dpyinfo
->mouse_face_beg_y
,
23884 dpyinfo
->mouse_face_past_end
23885 = !fast_find_position (w
, XFASTINT (after
),
23886 &dpyinfo
->mouse_face_end_col
,
23887 &dpyinfo
->mouse_face_end_row
,
23888 &dpyinfo
->mouse_face_end_x
,
23889 &dpyinfo
->mouse_face_end_y
,
23891 dpyinfo
->mouse_face_window
= window
;
23892 dpyinfo
->mouse_face_face_id
23893 = face_at_buffer_position (w
, pos
, 0, 0,
23895 !dpyinfo
->mouse_face_hidden
);
23897 /* Display it as active. */
23898 show_mouse_face (dpyinfo
, DRAW_MOUSE_FACE
);
23899 cursor
= No_Cursor
;
23906 /* Look for a `help-echo' property. */
23907 if (NILP (help_echo_string
)) {
23908 Lisp_Object help
, overlay
;
23910 /* Check overlays first. */
23911 help
= overlay
= Qnil
;
23912 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
23914 overlay
= overlay_vec
[i
];
23915 help
= Foverlay_get (overlay
, Qhelp_echo
);
23920 help_echo_string
= help
;
23921 help_echo_window
= window
;
23922 help_echo_object
= overlay
;
23923 help_echo_pos
= pos
;
23927 Lisp_Object object
= glyph
->object
;
23928 int charpos
= glyph
->charpos
;
23930 /* Try text properties. */
23931 if (STRINGP (object
)
23933 && charpos
< SCHARS (object
))
23935 help
= Fget_text_property (make_number (charpos
),
23936 Qhelp_echo
, object
);
23939 /* If the string itself doesn't specify a help-echo,
23940 see if the buffer text ``under'' it does. */
23941 struct glyph_row
*r
23942 = MATRIX_ROW (w
->current_matrix
, vpos
);
23943 int start
= MATRIX_ROW_START_CHARPOS (r
);
23944 int pos
= string_buffer_position (w
, object
, start
);
23947 help
= Fget_char_property (make_number (pos
),
23948 Qhelp_echo
, w
->buffer
);
23952 object
= w
->buffer
;
23957 else if (BUFFERP (object
)
23960 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
23965 help_echo_string
= help
;
23966 help_echo_window
= window
;
23967 help_echo_object
= object
;
23968 help_echo_pos
= charpos
;
23973 /* Look for a `pointer' property. */
23974 if (NILP (pointer
))
23976 /* Check overlays first. */
23977 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
23978 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
23980 if (NILP (pointer
))
23982 Lisp_Object object
= glyph
->object
;
23983 int charpos
= glyph
->charpos
;
23985 /* Try text properties. */
23986 if (STRINGP (object
)
23988 && charpos
< SCHARS (object
))
23990 pointer
= Fget_text_property (make_number (charpos
),
23992 if (NILP (pointer
))
23994 /* If the string itself doesn't specify a pointer,
23995 see if the buffer text ``under'' it does. */
23996 struct glyph_row
*r
23997 = MATRIX_ROW (w
->current_matrix
, vpos
);
23998 int start
= MATRIX_ROW_START_CHARPOS (r
);
23999 int pos
= string_buffer_position (w
, object
, start
);
24001 pointer
= Fget_char_property (make_number (pos
),
24002 Qpointer
, w
->buffer
);
24005 else if (BUFFERP (object
)
24008 pointer
= Fget_text_property (make_number (charpos
),
24015 current_buffer
= obuf
;
24020 define_frame_cursor1 (f
, cursor
, pointer
);
24025 Clear any mouse-face on window W. This function is part of the
24026 redisplay interface, and is called from try_window_id and similar
24027 functions to ensure the mouse-highlight is off. */
24030 x_clear_window_mouse_face (w
)
24033 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
24034 Lisp_Object window
;
24037 XSETWINDOW (window
, w
);
24038 if (EQ (window
, dpyinfo
->mouse_face_window
))
24039 clear_mouse_face (dpyinfo
);
24045 Just discard the mouse face information for frame F, if any.
24046 This is used when the size of F is changed. */
24049 cancel_mouse_face (f
)
24052 Lisp_Object window
;
24053 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24055 window
= dpyinfo
->mouse_face_window
;
24056 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
24058 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
24059 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
24060 dpyinfo
->mouse_face_window
= Qnil
;
24065 #endif /* HAVE_WINDOW_SYSTEM */
24068 /***********************************************************************
24070 ***********************************************************************/
24072 #ifdef HAVE_WINDOW_SYSTEM
24074 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
24075 which intersects rectangle R. R is in window-relative coordinates. */
24078 expose_area (w
, row
, r
, area
)
24080 struct glyph_row
*row
;
24082 enum glyph_row_area area
;
24084 struct glyph
*first
= row
->glyphs
[area
];
24085 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
24086 struct glyph
*last
;
24087 int first_x
, start_x
, x
;
24089 if (area
== TEXT_AREA
&& row
->fill_line_p
)
24090 /* If row extends face to end of line write the whole line. */
24091 draw_glyphs (w
, 0, row
, area
,
24092 0, row
->used
[area
],
24093 DRAW_NORMAL_TEXT
, 0);
24096 /* Set START_X to the window-relative start position for drawing glyphs of
24097 AREA. The first glyph of the text area can be partially visible.
24098 The first glyphs of other areas cannot. */
24099 start_x
= window_box_left_offset (w
, area
);
24101 if (area
== TEXT_AREA
)
24104 /* Find the first glyph that must be redrawn. */
24106 && x
+ first
->pixel_width
< r
->x
)
24108 x
+= first
->pixel_width
;
24112 /* Find the last one. */
24116 && x
< r
->x
+ r
->width
)
24118 x
+= last
->pixel_width
;
24124 draw_glyphs (w
, first_x
- start_x
, row
, area
,
24125 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
24126 DRAW_NORMAL_TEXT
, 0);
24131 /* Redraw the parts of the glyph row ROW on window W intersecting
24132 rectangle R. R is in window-relative coordinates. Value is
24133 non-zero if mouse-face was overwritten. */
24136 expose_line (w
, row
, r
)
24138 struct glyph_row
*row
;
24141 xassert (row
->enabled_p
);
24143 if (row
->mode_line_p
|| w
->pseudo_window_p
)
24144 draw_glyphs (w
, 0, row
, TEXT_AREA
,
24145 0, row
->used
[TEXT_AREA
],
24146 DRAW_NORMAL_TEXT
, 0);
24149 if (row
->used
[LEFT_MARGIN_AREA
])
24150 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
24151 if (row
->used
[TEXT_AREA
])
24152 expose_area (w
, row
, r
, TEXT_AREA
);
24153 if (row
->used
[RIGHT_MARGIN_AREA
])
24154 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
24155 draw_row_fringe_bitmaps (w
, row
);
24158 return row
->mouse_face_p
;
24162 /* Redraw those parts of glyphs rows during expose event handling that
24163 overlap other rows. Redrawing of an exposed line writes over parts
24164 of lines overlapping that exposed line; this function fixes that.
24166 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
24167 row in W's current matrix that is exposed and overlaps other rows.
24168 LAST_OVERLAPPING_ROW is the last such row. */
24171 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
, r
)
24173 struct glyph_row
*first_overlapping_row
;
24174 struct glyph_row
*last_overlapping_row
;
24177 struct glyph_row
*row
;
24179 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
24180 if (row
->overlapping_p
)
24182 xassert (row
->enabled_p
&& !row
->mode_line_p
);
24185 if (row
->used
[LEFT_MARGIN_AREA
])
24186 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
24188 if (row
->used
[TEXT_AREA
])
24189 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
24191 if (row
->used
[RIGHT_MARGIN_AREA
])
24192 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
24198 /* Return non-zero if W's cursor intersects rectangle R. */
24201 phys_cursor_in_rect_p (w
, r
)
24205 XRectangle cr
, result
;
24206 struct glyph
*cursor_glyph
;
24207 struct glyph_row
*row
;
24209 if (w
->phys_cursor
.vpos
>= 0
24210 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
24211 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
24213 && row
->cursor_in_fringe_p
)
24215 /* Cursor is in the fringe. */
24216 cr
.x
= window_box_right_offset (w
,
24217 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
24218 ? RIGHT_MARGIN_AREA
24221 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
24222 cr
.height
= row
->height
;
24223 return x_intersect_rectangles (&cr
, r
, &result
);
24226 cursor_glyph
= get_phys_cursor_glyph (w
);
24229 /* r is relative to W's box, but w->phys_cursor.x is relative
24230 to left edge of W's TEXT area. Adjust it. */
24231 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
24232 cr
.y
= w
->phys_cursor
.y
;
24233 cr
.width
= cursor_glyph
->pixel_width
;
24234 cr
.height
= w
->phys_cursor_height
;
24235 /* ++KFS: W32 version used W32-specific IntersectRect here, but
24236 I assume the effect is the same -- and this is portable. */
24237 return x_intersect_rectangles (&cr
, r
, &result
);
24239 /* If we don't understand the format, pretend we're not in the hot-spot. */
24245 Draw a vertical window border to the right of window W if W doesn't
24246 have vertical scroll bars. */
24249 x_draw_vertical_border (w
)
24252 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24254 /* We could do better, if we knew what type of scroll-bar the adjacent
24255 windows (on either side) have... But we don't :-(
24256 However, I think this works ok. ++KFS 2003-04-25 */
24258 /* Redraw borders between horizontally adjacent windows. Don't
24259 do it for frames with vertical scroll bars because either the
24260 right scroll bar of a window, or the left scroll bar of its
24261 neighbor will suffice as a border. */
24262 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
24265 if (!WINDOW_RIGHTMOST_P (w
)
24266 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
24268 int x0
, x1
, y0
, y1
;
24270 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24273 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24276 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
24278 else if (!WINDOW_LEFTMOST_P (w
)
24279 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
24281 int x0
, x1
, y0
, y1
;
24283 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
24286 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
24289 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
24294 /* Redraw the part of window W intersection rectangle FR. Pixel
24295 coordinates in FR are frame-relative. Call this function with
24296 input blocked. Value is non-zero if the exposure overwrites
24300 expose_window (w
, fr
)
24304 struct frame
*f
= XFRAME (w
->frame
);
24306 int mouse_face_overwritten_p
= 0;
24308 /* If window is not yet fully initialized, do nothing. This can
24309 happen when toolkit scroll bars are used and a window is split.
24310 Reconfiguring the scroll bar will generate an expose for a newly
24312 if (w
->current_matrix
== NULL
)
24315 /* When we're currently updating the window, display and current
24316 matrix usually don't agree. Arrange for a thorough display
24318 if (w
== updated_window
)
24320 SET_FRAME_GARBAGED (f
);
24324 /* Frame-relative pixel rectangle of W. */
24325 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
24326 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
24327 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
24328 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
24330 if (x_intersect_rectangles (fr
, &wr
, &r
))
24332 int yb
= window_text_bottom_y (w
);
24333 struct glyph_row
*row
;
24334 int cursor_cleared_p
;
24335 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
24337 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
24338 r
.x
, r
.y
, r
.width
, r
.height
));
24340 /* Convert to window coordinates. */
24341 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
24342 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
24344 /* Turn off the cursor. */
24345 if (!w
->pseudo_window_p
24346 && phys_cursor_in_rect_p (w
, &r
))
24348 x_clear_cursor (w
);
24349 cursor_cleared_p
= 1;
24352 cursor_cleared_p
= 0;
24354 /* Update lines intersecting rectangle R. */
24355 first_overlapping_row
= last_overlapping_row
= NULL
;
24356 for (row
= w
->current_matrix
->rows
;
24361 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
24363 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
24364 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
24365 || (r
.y
>= y0
&& r
.y
< y1
)
24366 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
24368 /* A header line may be overlapping, but there is no need
24369 to fix overlapping areas for them. KFS 2005-02-12 */
24370 if (row
->overlapping_p
&& !row
->mode_line_p
)
24372 if (first_overlapping_row
== NULL
)
24373 first_overlapping_row
= row
;
24374 last_overlapping_row
= row
;
24378 if (expose_line (w
, row
, &r
))
24379 mouse_face_overwritten_p
= 1;
24382 else if (row
->overlapping_p
)
24384 /* We must redraw a row overlapping the exposed area. */
24386 ? y0
+ row
->phys_height
> r
.y
24387 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
24389 if (first_overlapping_row
== NULL
)
24390 first_overlapping_row
= row
;
24391 last_overlapping_row
= row
;
24399 /* Display the mode line if there is one. */
24400 if (WINDOW_WANTS_MODELINE_P (w
)
24401 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
24403 && row
->y
< r
.y
+ r
.height
)
24405 if (expose_line (w
, row
, &r
))
24406 mouse_face_overwritten_p
= 1;
24409 if (!w
->pseudo_window_p
)
24411 /* Fix the display of overlapping rows. */
24412 if (first_overlapping_row
)
24413 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
24416 /* Draw border between windows. */
24417 x_draw_vertical_border (w
);
24419 /* Turn the cursor on again. */
24420 if (cursor_cleared_p
)
24421 update_window_cursor (w
, 1);
24425 return mouse_face_overwritten_p
;
24430 /* Redraw (parts) of all windows in the window tree rooted at W that
24431 intersect R. R contains frame pixel coordinates. Value is
24432 non-zero if the exposure overwrites mouse-face. */
24435 expose_window_tree (w
, r
)
24439 struct frame
*f
= XFRAME (w
->frame
);
24440 int mouse_face_overwritten_p
= 0;
24442 while (w
&& !FRAME_GARBAGED_P (f
))
24444 if (!NILP (w
->hchild
))
24445 mouse_face_overwritten_p
24446 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
24447 else if (!NILP (w
->vchild
))
24448 mouse_face_overwritten_p
24449 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
24451 mouse_face_overwritten_p
|= expose_window (w
, r
);
24453 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
24456 return mouse_face_overwritten_p
;
24461 Redisplay an exposed area of frame F. X and Y are the upper-left
24462 corner of the exposed rectangle. W and H are width and height of
24463 the exposed area. All are pixel values. W or H zero means redraw
24464 the entire frame. */
24467 expose_frame (f
, x
, y
, w
, h
)
24472 int mouse_face_overwritten_p
= 0;
24474 TRACE ((stderr
, "expose_frame "));
24476 /* No need to redraw if frame will be redrawn soon. */
24477 if (FRAME_GARBAGED_P (f
))
24479 TRACE ((stderr
, " garbaged\n"));
24483 /* If basic faces haven't been realized yet, there is no point in
24484 trying to redraw anything. This can happen when we get an expose
24485 event while Emacs is starting, e.g. by moving another window. */
24486 if (FRAME_FACE_CACHE (f
) == NULL
24487 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
24489 TRACE ((stderr
, " no faces\n"));
24493 if (w
== 0 || h
== 0)
24496 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
24497 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
24507 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
24508 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
24510 if (WINDOWP (f
->tool_bar_window
))
24511 mouse_face_overwritten_p
24512 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
24514 #ifdef HAVE_X_WINDOWS
24516 #ifndef USE_X_TOOLKIT
24517 if (WINDOWP (f
->menu_bar_window
))
24518 mouse_face_overwritten_p
24519 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
24520 #endif /* not USE_X_TOOLKIT */
24524 /* Some window managers support a focus-follows-mouse style with
24525 delayed raising of frames. Imagine a partially obscured frame,
24526 and moving the mouse into partially obscured mouse-face on that
24527 frame. The visible part of the mouse-face will be highlighted,
24528 then the WM raises the obscured frame. With at least one WM, KDE
24529 2.1, Emacs is not getting any event for the raising of the frame
24530 (even tried with SubstructureRedirectMask), only Expose events.
24531 These expose events will draw text normally, i.e. not
24532 highlighted. Which means we must redo the highlight here.
24533 Subsume it under ``we love X''. --gerd 2001-08-15 */
24534 /* Included in Windows version because Windows most likely does not
24535 do the right thing if any third party tool offers
24536 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
24537 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
24539 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
24540 if (f
== dpyinfo
->mouse_face_mouse_frame
)
24542 int x
= dpyinfo
->mouse_face_mouse_x
;
24543 int y
= dpyinfo
->mouse_face_mouse_y
;
24544 clear_mouse_face (dpyinfo
);
24545 note_mouse_highlight (f
, x
, y
);
24552 Determine the intersection of two rectangles R1 and R2. Return
24553 the intersection in *RESULT. Value is non-zero if RESULT is not
24557 x_intersect_rectangles (r1
, r2
, result
)
24558 XRectangle
*r1
, *r2
, *result
;
24560 XRectangle
*left
, *right
;
24561 XRectangle
*upper
, *lower
;
24562 int intersection_p
= 0;
24564 /* Rearrange so that R1 is the left-most rectangle. */
24566 left
= r1
, right
= r2
;
24568 left
= r2
, right
= r1
;
24570 /* X0 of the intersection is right.x0, if this is inside R1,
24571 otherwise there is no intersection. */
24572 if (right
->x
<= left
->x
+ left
->width
)
24574 result
->x
= right
->x
;
24576 /* The right end of the intersection is the minimum of the
24577 the right ends of left and right. */
24578 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
24581 /* Same game for Y. */
24583 upper
= r1
, lower
= r2
;
24585 upper
= r2
, lower
= r1
;
24587 /* The upper end of the intersection is lower.y0, if this is inside
24588 of upper. Otherwise, there is no intersection. */
24589 if (lower
->y
<= upper
->y
+ upper
->height
)
24591 result
->y
= lower
->y
;
24593 /* The lower end of the intersection is the minimum of the lower
24594 ends of upper and lower. */
24595 result
->height
= (min (lower
->y
+ lower
->height
,
24596 upper
->y
+ upper
->height
)
24598 intersection_p
= 1;
24602 return intersection_p
;
24605 #endif /* HAVE_WINDOW_SYSTEM */
24608 /***********************************************************************
24610 ***********************************************************************/
24615 Vwith_echo_area_save_vector
= Qnil
;
24616 staticpro (&Vwith_echo_area_save_vector
);
24618 Vmessage_stack
= Qnil
;
24619 staticpro (&Vmessage_stack
);
24621 Qinhibit_redisplay
= intern ("inhibit-redisplay");
24622 staticpro (&Qinhibit_redisplay
);
24624 message_dolog_marker1
= Fmake_marker ();
24625 staticpro (&message_dolog_marker1
);
24626 message_dolog_marker2
= Fmake_marker ();
24627 staticpro (&message_dolog_marker2
);
24628 message_dolog_marker3
= Fmake_marker ();
24629 staticpro (&message_dolog_marker3
);
24632 defsubr (&Sdump_frame_glyph_matrix
);
24633 defsubr (&Sdump_glyph_matrix
);
24634 defsubr (&Sdump_glyph_row
);
24635 defsubr (&Sdump_tool_bar_row
);
24636 defsubr (&Strace_redisplay
);
24637 defsubr (&Strace_to_stderr
);
24639 #ifdef HAVE_WINDOW_SYSTEM
24640 defsubr (&Stool_bar_lines_needed
);
24641 defsubr (&Slookup_image_map
);
24643 defsubr (&Sformat_mode_line
);
24644 defsubr (&Sinvisible_p
);
24646 staticpro (&Qmenu_bar_update_hook
);
24647 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
24649 staticpro (&Qoverriding_terminal_local_map
);
24650 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
24652 staticpro (&Qoverriding_local_map
);
24653 Qoverriding_local_map
= intern ("overriding-local-map");
24655 staticpro (&Qwindow_scroll_functions
);
24656 Qwindow_scroll_functions
= intern ("window-scroll-functions");
24658 staticpro (&Qwindow_text_change_functions
);
24659 Qwindow_text_change_functions
= intern ("window-text-change-functions");
24661 staticpro (&Qredisplay_end_trigger_functions
);
24662 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
24664 staticpro (&Qinhibit_point_motion_hooks
);
24665 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
24667 Qeval
= intern ("eval");
24668 staticpro (&Qeval
);
24670 QCdata
= intern (":data");
24671 staticpro (&QCdata
);
24672 Qdisplay
= intern ("display");
24673 staticpro (&Qdisplay
);
24674 Qspace_width
= intern ("space-width");
24675 staticpro (&Qspace_width
);
24676 Qraise
= intern ("raise");
24677 staticpro (&Qraise
);
24678 Qslice
= intern ("slice");
24679 staticpro (&Qslice
);
24680 Qspace
= intern ("space");
24681 staticpro (&Qspace
);
24682 Qmargin
= intern ("margin");
24683 staticpro (&Qmargin
);
24684 Qpointer
= intern ("pointer");
24685 staticpro (&Qpointer
);
24686 Qleft_margin
= intern ("left-margin");
24687 staticpro (&Qleft_margin
);
24688 Qright_margin
= intern ("right-margin");
24689 staticpro (&Qright_margin
);
24690 Qcenter
= intern ("center");
24691 staticpro (&Qcenter
);
24692 Qline_height
= intern ("line-height");
24693 staticpro (&Qline_height
);
24694 QCalign_to
= intern (":align-to");
24695 staticpro (&QCalign_to
);
24696 QCrelative_width
= intern (":relative-width");
24697 staticpro (&QCrelative_width
);
24698 QCrelative_height
= intern (":relative-height");
24699 staticpro (&QCrelative_height
);
24700 QCeval
= intern (":eval");
24701 staticpro (&QCeval
);
24702 QCpropertize
= intern (":propertize");
24703 staticpro (&QCpropertize
);
24704 QCfile
= intern (":file");
24705 staticpro (&QCfile
);
24706 Qfontified
= intern ("fontified");
24707 staticpro (&Qfontified
);
24708 Qfontification_functions
= intern ("fontification-functions");
24709 staticpro (&Qfontification_functions
);
24710 Qtrailing_whitespace
= intern ("trailing-whitespace");
24711 staticpro (&Qtrailing_whitespace
);
24712 Qescape_glyph
= intern ("escape-glyph");
24713 staticpro (&Qescape_glyph
);
24714 Qnobreak_space
= intern ("nobreak-space");
24715 staticpro (&Qnobreak_space
);
24716 Qimage
= intern ("image");
24717 staticpro (&Qimage
);
24718 QCmap
= intern (":map");
24719 staticpro (&QCmap
);
24720 QCpointer
= intern (":pointer");
24721 staticpro (&QCpointer
);
24722 Qrect
= intern ("rect");
24723 staticpro (&Qrect
);
24724 Qcircle
= intern ("circle");
24725 staticpro (&Qcircle
);
24726 Qpoly
= intern ("poly");
24727 staticpro (&Qpoly
);
24728 Qmessage_truncate_lines
= intern ("message-truncate-lines");
24729 staticpro (&Qmessage_truncate_lines
);
24730 Qgrow_only
= intern ("grow-only");
24731 staticpro (&Qgrow_only
);
24732 Qinhibit_menubar_update
= intern ("inhibit-menubar-update");
24733 staticpro (&Qinhibit_menubar_update
);
24734 Qinhibit_eval_during_redisplay
= intern ("inhibit-eval-during-redisplay");
24735 staticpro (&Qinhibit_eval_during_redisplay
);
24736 Qposition
= intern ("position");
24737 staticpro (&Qposition
);
24738 Qbuffer_position
= intern ("buffer-position");
24739 staticpro (&Qbuffer_position
);
24740 Qobject
= intern ("object");
24741 staticpro (&Qobject
);
24742 Qbar
= intern ("bar");
24744 Qhbar
= intern ("hbar");
24745 staticpro (&Qhbar
);
24746 Qbox
= intern ("box");
24748 Qhollow
= intern ("hollow");
24749 staticpro (&Qhollow
);
24750 Qhand
= intern ("hand");
24751 staticpro (&Qhand
);
24752 Qarrow
= intern ("arrow");
24753 staticpro (&Qarrow
);
24754 Qtext
= intern ("text");
24755 staticpro (&Qtext
);
24756 Qrisky_local_variable
= intern ("risky-local-variable");
24757 staticpro (&Qrisky_local_variable
);
24758 Qinhibit_free_realized_faces
= intern ("inhibit-free-realized-faces");
24759 staticpro (&Qinhibit_free_realized_faces
);
24761 list_of_error
= Fcons (Fcons (intern ("error"),
24762 Fcons (intern ("void-variable"), Qnil
)),
24764 staticpro (&list_of_error
);
24766 Qlast_arrow_position
= intern ("last-arrow-position");
24767 staticpro (&Qlast_arrow_position
);
24768 Qlast_arrow_string
= intern ("last-arrow-string");
24769 staticpro (&Qlast_arrow_string
);
24771 Qoverlay_arrow_string
= intern ("overlay-arrow-string");
24772 staticpro (&Qoverlay_arrow_string
);
24773 Qoverlay_arrow_bitmap
= intern ("overlay-arrow-bitmap");
24774 staticpro (&Qoverlay_arrow_bitmap
);
24776 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
24777 staticpro (&echo_buffer
[0]);
24778 staticpro (&echo_buffer
[1]);
24780 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
24781 staticpro (&echo_area_buffer
[0]);
24782 staticpro (&echo_area_buffer
[1]);
24784 Vmessages_buffer_name
= build_string ("*Messages*");
24785 staticpro (&Vmessages_buffer_name
);
24787 mode_line_proptrans_alist
= Qnil
;
24788 staticpro (&mode_line_proptrans_alist
);
24789 mode_line_string_list
= Qnil
;
24790 staticpro (&mode_line_string_list
);
24791 mode_line_string_face
= Qnil
;
24792 staticpro (&mode_line_string_face
);
24793 mode_line_string_face_prop
= Qnil
;
24794 staticpro (&mode_line_string_face_prop
);
24795 Vmode_line_unwind_vector
= Qnil
;
24796 staticpro (&Vmode_line_unwind_vector
);
24798 help_echo_string
= Qnil
;
24799 staticpro (&help_echo_string
);
24800 help_echo_object
= Qnil
;
24801 staticpro (&help_echo_object
);
24802 help_echo_window
= Qnil
;
24803 staticpro (&help_echo_window
);
24804 previous_help_echo_string
= Qnil
;
24805 staticpro (&previous_help_echo_string
);
24806 help_echo_pos
= -1;
24808 #ifdef HAVE_WINDOW_SYSTEM
24809 DEFVAR_BOOL ("x-stretch-cursor", &x_stretch_cursor_p
,
24810 doc
: /* *Non-nil means draw block cursor as wide as the glyph under it.
24811 For example, if a block cursor is over a tab, it will be drawn as
24812 wide as that tab on the display. */);
24813 x_stretch_cursor_p
= 0;
24816 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
24817 doc
: /* *Non-nil means highlight trailing whitespace.
24818 The face used for trailing whitespace is `trailing-whitespace'. */);
24819 Vshow_trailing_whitespace
= Qnil
;
24821 DEFVAR_LISP ("nobreak-char-display", &Vnobreak_char_display
,
24822 doc
: /* *Control highlighting of nobreak space and soft hyphen.
24823 A value of t means highlight the character itself (for nobreak space,
24824 use face `nobreak-space').
24825 A value of nil means no highlighting.
24826 Other values mean display the escape glyph followed by an ordinary
24827 space or ordinary hyphen. */);
24828 Vnobreak_char_display
= Qt
;
24830 DEFVAR_LISP ("void-text-area-pointer", &Vvoid_text_area_pointer
,
24831 doc
: /* *The pointer shape to show in void text areas.
24832 A value of nil means to show the text pointer. Other options are `arrow',
24833 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
24834 Vvoid_text_area_pointer
= Qarrow
;
24836 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
24837 doc
: /* Non-nil means don't actually do any redisplay.
24838 This is used for internal purposes. */);
24839 Vinhibit_redisplay
= Qnil
;
24841 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
24842 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
24843 Vglobal_mode_string
= Qnil
;
24845 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
24846 doc
: /* Marker for where to display an arrow on top of the buffer text.
24847 This must be the beginning of a line in order to work.
24848 See also `overlay-arrow-string'. */);
24849 Voverlay_arrow_position
= Qnil
;
24851 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
24852 doc
: /* String to display as an arrow in non-window frames.
24853 See also `overlay-arrow-position'. */);
24854 Voverlay_arrow_string
= build_string ("=>");
24856 DEFVAR_LISP ("overlay-arrow-variable-list", &Voverlay_arrow_variable_list
,
24857 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
24858 The symbols on this list are examined during redisplay to determine
24859 where to display overlay arrows. */);
24860 Voverlay_arrow_variable_list
24861 = Fcons (intern ("overlay-arrow-position"), Qnil
);
24863 DEFVAR_INT ("scroll-step", &scroll_step
,
24864 doc
: /* *The number of lines to try scrolling a window by when point moves out.
24865 If that fails to bring point back on frame, point is centered instead.
24866 If this is zero, point is always centered after it moves off frame.
24867 If you want scrolling to always be a line at a time, you should set
24868 `scroll-conservatively' to a large value rather than set this to 1. */);
24870 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
24871 doc
: /* *Scroll up to this many lines, to bring point back on screen.
24872 If point moves off-screen, redisplay will scroll by up to
24873 `scroll-conservatively' lines in order to bring point just barely
24874 onto the screen again. If that cannot be done, then redisplay
24875 recenters point as usual.
24877 A value of zero means always recenter point if it moves off screen. */);
24878 scroll_conservatively
= 0;
24880 DEFVAR_INT ("scroll-margin", &scroll_margin
,
24881 doc
: /* *Number of lines of margin at the top and bottom of a window.
24882 Recenter the window whenever point gets within this many lines
24883 of the top or bottom of the window. */);
24886 DEFVAR_LISP ("display-pixels-per-inch", &Vdisplay_pixels_per_inch
,
24887 doc
: /* Pixels per inch value for non-window system displays.
24888 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
24889 Vdisplay_pixels_per_inch
= make_float (72.0);
24892 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, doc
: /* Don't ask. */);
24895 DEFVAR_LISP ("truncate-partial-width-windows",
24896 &Vtruncate_partial_width_windows
,
24897 doc
: /* Non-nil means truncate lines in windows with less than the frame width.
24898 For an integer value, truncate lines in each window with less than the
24899 full frame width, provided the window width is less than that integer;
24900 otherwise, respect the value of `truncate-lines'.
24902 For any other non-nil value, truncate lines in all windows with
24903 less than the full frame width.
24905 A value of nil means to respect the value of `truncate-lines'. */);
24906 Vtruncate_partial_width_windows
= make_number (30);
24908 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
24909 doc
: /* When nil, display the mode-line/header-line/menu-bar in the default face.
24910 Any other value means to use the appropriate face, `mode-line',
24911 `header-line', or `menu' respectively. */);
24912 mode_line_inverse_video
= 1;
24914 DEFVAR_LISP ("line-number-display-limit", &Vline_number_display_limit
,
24915 doc
: /* *Maximum buffer size for which line number should be displayed.
24916 If the buffer is bigger than this, the line number does not appear
24917 in the mode line. A value of nil means no limit. */);
24918 Vline_number_display_limit
= Qnil
;
24920 DEFVAR_INT ("line-number-display-limit-width",
24921 &line_number_display_limit_width
,
24922 doc
: /* *Maximum line width (in characters) for line number display.
24923 If the average length of the lines near point is bigger than this, then the
24924 line number may be omitted from the mode line. */);
24925 line_number_display_limit_width
= 200;
24927 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
24928 doc
: /* *Non-nil means highlight region even in nonselected windows. */);
24929 highlight_nonselected_windows
= 0;
24931 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
24932 doc
: /* Non-nil if more than one frame is visible on this display.
24933 Minibuffer-only frames don't count, but iconified frames do.
24934 This variable is not guaranteed to be accurate except while processing
24935 `frame-title-format' and `icon-title-format'. */);
24937 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
24938 doc
: /* Template for displaying the title bar of visible frames.
24939 \(Assuming the window manager supports this feature.)
24941 This variable has the same structure as `mode-line-format', except that
24942 the %c and %l constructs are ignored. It is used only on frames for
24943 which no explicit name has been set \(see `modify-frame-parameters'). */);
24945 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
24946 doc
: /* Template for displaying the title bar of an iconified frame.
24947 \(Assuming the window manager supports this feature.)
24948 This variable has the same structure as `mode-line-format' (which see),
24949 and is used only on frames for which no explicit name has been set
24950 \(see `modify-frame-parameters'). */);
24952 = Vframe_title_format
24953 = Fcons (intern ("multiple-frames"),
24954 Fcons (build_string ("%b"),
24955 Fcons (Fcons (empty_unibyte_string
,
24956 Fcons (intern ("invocation-name"),
24957 Fcons (build_string ("@"),
24958 Fcons (intern ("system-name"),
24962 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
24963 doc
: /* Maximum number of lines to keep in the message log buffer.
24964 If nil, disable message logging. If t, log messages but don't truncate
24965 the buffer when it becomes large. */);
24966 Vmessage_log_max
= make_number (100);
24968 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
24969 doc
: /* Functions called before redisplay, if window sizes have changed.
24970 The value should be a list of functions that take one argument.
24971 Just before redisplay, for each frame, if any of its windows have changed
24972 size since the last redisplay, or have been split or deleted,
24973 all the functions in the list are called, with the frame as argument. */);
24974 Vwindow_size_change_functions
= Qnil
;
24976 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
24977 doc
: /* List of functions to call before redisplaying a window with scrolling.
24978 Each function is called with two arguments, the window
24979 and its new display-start position. Note that the value of `window-end'
24980 is not valid when these functions are called. */);
24981 Vwindow_scroll_functions
= Qnil
;
24983 DEFVAR_LISP ("window-text-change-functions",
24984 &Vwindow_text_change_functions
,
24985 doc
: /* Functions to call in redisplay when text in the window might change. */);
24986 Vwindow_text_change_functions
= Qnil
;
24988 DEFVAR_LISP ("redisplay-end-trigger-functions", &Vredisplay_end_trigger_functions
,
24989 doc
: /* Functions called when redisplay of a window reaches the end trigger.
24990 Each function is called with two arguments, the window and the end trigger value.
24991 See `set-window-redisplay-end-trigger'. */);
24992 Vredisplay_end_trigger_functions
= Qnil
;
24994 DEFVAR_LISP ("mouse-autoselect-window", &Vmouse_autoselect_window
,
24995 doc
: /* *Non-nil means autoselect window with mouse pointer.
24996 If nil, do not autoselect windows.
24997 A positive number means delay autoselection by that many seconds: a
24998 window is autoselected only after the mouse has remained in that
24999 window for the duration of the delay.
25000 A negative number has a similar effect, but causes windows to be
25001 autoselected only after the mouse has stopped moving. \(Because of
25002 the way Emacs compares mouse events, you will occasionally wait twice
25003 that time before the window gets selected.\)
25004 Any other value means to autoselect window instantaneously when the
25005 mouse pointer enters it.
25007 Autoselection selects the minibuffer only if it is active, and never
25008 unselects the minibuffer if it is active.
25010 When customizing this variable make sure that the actual value of
25011 `focus-follows-mouse' matches the behavior of your window manager. */);
25012 Vmouse_autoselect_window
= Qnil
;
25014 DEFVAR_LISP ("auto-resize-tool-bars", &Vauto_resize_tool_bars
,
25015 doc
: /* *Non-nil means automatically resize tool-bars.
25016 This dynamically changes the tool-bar's height to the minimum height
25017 that is needed to make all tool-bar items visible.
25018 If value is `grow-only', the tool-bar's height is only increased
25019 automatically; to decrease the tool-bar height, use \\[recenter]. */);
25020 Vauto_resize_tool_bars
= Qt
;
25022 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
25023 doc
: /* *Non-nil means raise tool-bar buttons when the mouse moves over them. */);
25024 auto_raise_tool_bar_buttons_p
= 1;
25026 DEFVAR_BOOL ("make-cursor-line-fully-visible", &make_cursor_line_fully_visible_p
,
25027 doc
: /* *Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
25028 make_cursor_line_fully_visible_p
= 1;
25030 DEFVAR_LISP ("tool-bar-border", &Vtool_bar_border
,
25031 doc
: /* *Border below tool-bar in pixels.
25032 If an integer, use it as the height of the border.
25033 If it is one of `internal-border-width' or `border-width', use the
25034 value of the corresponding frame parameter.
25035 Otherwise, no border is added below the tool-bar. */);
25036 Vtool_bar_border
= Qinternal_border_width
;
25038 DEFVAR_LISP ("tool-bar-button-margin", &Vtool_bar_button_margin
,
25039 doc
: /* *Margin around tool-bar buttons in pixels.
25040 If an integer, use that for both horizontal and vertical margins.
25041 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
25042 HORZ specifying the horizontal margin, and VERT specifying the
25043 vertical margin. */);
25044 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
25046 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
25047 doc
: /* *Relief thickness of tool-bar buttons. */);
25048 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
25050 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
25051 doc
: /* List of functions to call to fontify regions of text.
25052 Each function is called with one argument POS. Functions must
25053 fontify a region starting at POS in the current buffer, and give
25054 fontified regions the property `fontified'. */);
25055 Vfontification_functions
= Qnil
;
25056 Fmake_variable_buffer_local (Qfontification_functions
);
25058 DEFVAR_BOOL ("unibyte-display-via-language-environment",
25059 &unibyte_display_via_language_environment
,
25060 doc
: /* *Non-nil means display unibyte text according to language environment.
25061 Specifically this means that unibyte non-ASCII characters
25062 are displayed by converting them to the equivalent multibyte characters
25063 according to the current language environment. As a result, they are
25064 displayed according to the current fontset. */);
25065 unibyte_display_via_language_environment
= 0;
25067 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
25068 doc
: /* *Maximum height for resizing mini-windows.
25069 If a float, it specifies a fraction of the mini-window frame's height.
25070 If an integer, it specifies a number of lines. */);
25071 Vmax_mini_window_height
= make_float (0.25);
25073 DEFVAR_LISP ("resize-mini-windows", &Vresize_mini_windows
,
25074 doc
: /* *How to resize mini-windows.
25075 A value of nil means don't automatically resize mini-windows.
25076 A value of t means resize them to fit the text displayed in them.
25077 A value of `grow-only', the default, means let mini-windows grow
25078 only, until their display becomes empty, at which point the windows
25079 go back to their normal size. */);
25080 Vresize_mini_windows
= Qgrow_only
;
25082 DEFVAR_LISP ("blink-cursor-alist", &Vblink_cursor_alist
,
25083 doc
: /* Alist specifying how to blink the cursor off.
25084 Each element has the form (ON-STATE . OFF-STATE). Whenever the
25085 `cursor-type' frame-parameter or variable equals ON-STATE,
25086 comparing using `equal', Emacs uses OFF-STATE to specify
25087 how to blink it off. ON-STATE and OFF-STATE are values for
25088 the `cursor-type' frame parameter.
25090 If a frame's ON-STATE has no entry in this list,
25091 the frame's other specifications determine how to blink the cursor off. */);
25092 Vblink_cursor_alist
= Qnil
;
25094 DEFVAR_BOOL ("auto-hscroll-mode", &automatic_hscrolling_p
,
25095 doc
: /* *Non-nil means scroll the display automatically to make point visible. */);
25096 automatic_hscrolling_p
= 1;
25097 Qauto_hscroll_mode
= intern ("auto-hscroll-mode");
25098 staticpro (&Qauto_hscroll_mode
);
25100 DEFVAR_INT ("hscroll-margin", &hscroll_margin
,
25101 doc
: /* *How many columns away from the window edge point is allowed to get
25102 before automatic hscrolling will horizontally scroll the window. */);
25103 hscroll_margin
= 5;
25105 DEFVAR_LISP ("hscroll-step", &Vhscroll_step
,
25106 doc
: /* *How many columns to scroll the window when point gets too close to the edge.
25107 When point is less than `hscroll-margin' columns from the window
25108 edge, automatic hscrolling will scroll the window by the amount of columns
25109 determined by this variable. If its value is a positive integer, scroll that
25110 many columns. If it's a positive floating-point number, it specifies the
25111 fraction of the window's width to scroll. If it's nil or zero, point will be
25112 centered horizontally after the scroll. Any other value, including negative
25113 numbers, are treated as if the value were zero.
25115 Automatic hscrolling always moves point outside the scroll margin, so if
25116 point was more than scroll step columns inside the margin, the window will
25117 scroll more than the value given by the scroll step.
25119 Note that the lower bound for automatic hscrolling specified by `scroll-left'
25120 and `scroll-right' overrides this variable's effect. */);
25121 Vhscroll_step
= make_number (0);
25123 DEFVAR_BOOL ("message-truncate-lines", &message_truncate_lines
,
25124 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
25125 Bind this around calls to `message' to let it take effect. */);
25126 message_truncate_lines
= 0;
25128 DEFVAR_LISP ("menu-bar-update-hook", &Vmenu_bar_update_hook
,
25129 doc
: /* Normal hook run to update the menu bar definitions.
25130 Redisplay runs this hook before it redisplays the menu bar.
25131 This is used to update submenus such as Buffers,
25132 whose contents depend on various data. */);
25133 Vmenu_bar_update_hook
= Qnil
;
25135 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame
,
25136 doc
: /* Frame for which we are updating a menu.
25137 The enable predicate for a menu binding should check this variable. */);
25138 Vmenu_updating_frame
= Qnil
;
25140 DEFVAR_BOOL ("inhibit-menubar-update", &inhibit_menubar_update
,
25141 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
25142 inhibit_menubar_update
= 0;
25144 DEFVAR_LISP ("wrap-prefix", &Vwrap_prefix
,
25145 doc
: /* Prefix added to the beginning of all continuation lines at display-time.
25146 May be a string, an image, or a stretch-glyph such as used by the
25147 `display' text-property.
25149 This variable is overridden by any `wrap-prefix' text-property.
25151 To add a prefix to non-continuation lines, use the `line-prefix' variable. */);
25152 Vwrap_prefix
= Qnil
;
25153 staticpro (&Qwrap_prefix
);
25154 Qwrap_prefix
= intern ("wrap-prefix");
25155 Fmake_variable_buffer_local (Qwrap_prefix
);
25157 DEFVAR_LISP ("line-prefix", &Vline_prefix
,
25158 doc
: /* Prefix added to the beginning of all non-continuation lines at display-time.
25159 May be a string, an image, or a stretch-glyph such as used by the
25160 `display' text-property.
25162 This variable is overridden by any `line-prefix' text-property.
25164 To add a prefix to continuation lines, use the `wrap-prefix' variable. */);
25165 Vline_prefix
= Qnil
;
25166 staticpro (&Qline_prefix
);
25167 Qline_prefix
= intern ("line-prefix");
25168 Fmake_variable_buffer_local (Qline_prefix
);
25170 DEFVAR_BOOL ("inhibit-eval-during-redisplay", &inhibit_eval_during_redisplay
,
25171 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
25172 inhibit_eval_during_redisplay
= 0;
25174 DEFVAR_BOOL ("inhibit-free-realized-faces", &inhibit_free_realized_faces
,
25175 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
25176 inhibit_free_realized_faces
= 0;
25179 DEFVAR_BOOL ("inhibit-try-window-id", &inhibit_try_window_id
,
25180 doc
: /* Inhibit try_window_id display optimization. */);
25181 inhibit_try_window_id
= 0;
25183 DEFVAR_BOOL ("inhibit-try-window-reusing", &inhibit_try_window_reusing
,
25184 doc
: /* Inhibit try_window_reusing display optimization. */);
25185 inhibit_try_window_reusing
= 0;
25187 DEFVAR_BOOL ("inhibit-try-cursor-movement", &inhibit_try_cursor_movement
,
25188 doc
: /* Inhibit try_cursor_movement display optimization. */);
25189 inhibit_try_cursor_movement
= 0;
25190 #endif /* GLYPH_DEBUG */
25192 DEFVAR_INT ("overline-margin", &overline_margin
,
25193 doc
: /* *Space between overline and text, in pixels.
25194 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
25195 margin to the caracter height. */);
25196 overline_margin
= 2;
25198 DEFVAR_INT ("underline-minimum-offset",
25199 &underline_minimum_offset
,
25200 doc
: /* Minimum distance between baseline and underline.
25201 This can improve legibility of underlined text at small font sizes,
25202 particularly when using variable `x-use-underline-position-properties'
25203 with fonts that specify an UNDERLINE_POSITION relatively close to the
25204 baseline. The default value is 1. */);
25205 underline_minimum_offset
= 1;
25207 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
25208 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
25209 display_hourglass_p
= 1;
25211 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
25212 doc
: /* *Seconds to wait before displaying an hourglass pointer.
25213 Value must be an integer or float. */);
25214 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
25216 hourglass_atimer
= NULL
;
25217 hourglass_shown_p
= 0;
25221 /* Initialize this module when Emacs starts. */
25226 Lisp_Object root_window
;
25227 struct window
*mini_w
;
25229 current_header_line_height
= current_mode_line_height
= -1;
25231 CHARPOS (this_line_start_pos
) = 0;
25233 mini_w
= XWINDOW (minibuf_window
);
25234 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
25236 if (!noninteractive
)
25238 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
25241 XWINDOW (root_window
)->top_line
= make_number (FRAME_TOP_MARGIN (f
));
25242 set_window_height (root_window
,
25243 FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
),
25245 mini_w
->top_line
= make_number (FRAME_LINES (f
) - 1);
25246 set_window_height (minibuf_window
, 1, 0);
25248 XWINDOW (root_window
)->total_cols
= make_number (FRAME_COLS (f
));
25249 mini_w
->total_cols
= make_number (FRAME_COLS (f
));
25251 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
25252 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
25253 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
25255 /* The default ellipsis glyphs `...'. */
25256 for (i
= 0; i
< 3; ++i
)
25257 default_invis_vector
[i
] = make_number ('.');
25261 /* Allocate the buffer for frame titles.
25262 Also used for `format-mode-line'. */
25264 mode_line_noprop_buf
= (char *) xmalloc (size
);
25265 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
25266 mode_line_noprop_ptr
= mode_line_noprop_buf
;
25267 mode_line_target
= MODE_LINE_DISPLAY
;
25270 help_echo_showing_p
= 0;
25273 /* Since w32 does not support atimers, it defines its own implementation of
25274 the following three functions in w32fns.c. */
25277 /* Platform-independent portion of hourglass implementation. */
25279 /* Return non-zero if houglass timer has been started or hourglass is shown. */
25281 hourglass_started ()
25283 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
25286 /* Cancel a currently active hourglass timer, and start a new one. */
25290 #if defined (HAVE_WINDOW_SYSTEM)
25292 int secs
, usecs
= 0;
25294 cancel_hourglass ();
25296 if (INTEGERP (Vhourglass_delay
)
25297 && XINT (Vhourglass_delay
) > 0)
25298 secs
= XFASTINT (Vhourglass_delay
);
25299 else if (FLOATP (Vhourglass_delay
)
25300 && XFLOAT_DATA (Vhourglass_delay
) > 0)
25303 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
25304 secs
= XFASTINT (tem
);
25305 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
25308 secs
= DEFAULT_HOURGLASS_DELAY
;
25310 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
25311 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
25312 show_hourglass
, NULL
);
25317 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
25320 cancel_hourglass ()
25322 #if defined (HAVE_WINDOW_SYSTEM)
25323 if (hourglass_atimer
)
25325 cancel_atimer (hourglass_atimer
);
25326 hourglass_atimer
= NULL
;
25329 if (hourglass_shown_p
)
25333 #endif /* ! WINDOWSNT */
25335 /* arch-tag: eacc864d-bb6a-4b74-894a-1a4399a1358b
25336 (do not change this comment) */